Skip to content

Commit 23143b9

Browse files
committed
Better dynamic import handling
1 parent d46d18b commit 23143b9

File tree

14 files changed

+90
-21
lines changed

14 files changed

+90
-21
lines changed

demo/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@
4040
"scripts": {
4141
"serve": "vite preview",
4242
"type-check": "tsc --noEmit",
43-
"start": "rimraf ./src/json-edit-react && mkdir ./src/json-edit-react && mkdir ./src/json-edit-react/src && concurrently --kill-others-on-fail \"vite\" \"nodemon watch.cjs\"",
44-
"build": "tsc && vite build",
43+
"prepareLaunch": "rimraf ./src/json-edit-react && mkdir ./src/json-edit-react && mkdir ./src/json-edit-react/src && node src/imports/swap_import.cjs",
44+
"launch": "concurrently --kill-others-on-fail \"vite\" \"nodemon watch.cjs\"",
45+
"start": "yarn prepareLaunch && yarn launch",
46+
"dev": "cross-env VITE_USE_LOCAL_SRC=true yarn prepareLaunch && VITE_USE_LOCAL_SRC=true yarn launch",
47+
"build": "node src/imports/swap_import.cjs && tsc && vite build",
4548
"prebuild": "node ./scripts/getVersion.cjs",
4649
"predeploy": "yarn build",
4750
"deploy": "gh-pages -d build"
@@ -74,6 +77,7 @@
7477
"devDependencies": {
7578
"@vitejs/plugin-react": "^4.3.4",
7679
"concurrently": "^8.2.2",
80+
"cross-env": "^7.0.3",
7781
"gh-pages": "^6.1.1",
7882
"node-fetch": "^3.3.2",
7983
"nodemon": "^3.0.3",

demo/src/App.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import {
1818
psychedelicTheme,
1919
// ExternalTriggers,
2020
// type CollapseState
21-
} from './_imports'
21+
} from './imports'
22+
import SourceIndicator from './SourceIndicator'
2223
import { FaNpm, FaExternalLinkAlt, FaGithub } from 'react-icons/fa'
2324
import { BiReset } from 'react-icons/bi'
2425
import { AiOutlineCloudUpload } from 'react-icons/ai'
@@ -58,6 +59,8 @@ import { timestamp, version } from './version'
5859

5960
const CodeEditor = lazy(() => import('./CodeEditor'))
6061

62+
const usingLocalImport = import.meta.env.VITE_USE_LOCAL_SRC === 'true'
63+
6164
interface AppState {
6265
rootName: string
6366
indent: number
@@ -289,6 +292,7 @@ function App() {
289292
minH="100%"
290293
>
291294
<HStack w="100%" justify="space-between" align="flex-start">
295+
{usingLocalImport && <SourceIndicator />}
292296
<VStack align="flex-start" gap={3}>
293297
<HStack align="flex-end" mt={2} gap={4} flexWrap="wrap">
294298
<Flex gap={4} align="center">

demo/src/CodeEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import CodeMirror from '@uiw/react-codemirror'
33
import { json } from '@codemirror/lang-json'
4-
import { TextEditorProps } from './_imports'
4+
import { TextEditorProps } from './imports'
55
import { githubLight, githubDark } from '@uiw/codemirror-theme-github'
66
import { consoleDark } from '@uiw/codemirror-theme-console/dark'
77
import { consoleLight } from '@uiw/codemirror-theme-console/light'

demo/src/SourceIndicator.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import React from 'react'
2+
13
const SourceIndicator = () => {
24
// Directly check if we're using the local source
35
if (import.meta.env.VITE_USE_LOCAL_SRC !== 'true') return null

demo/src/_imports.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

demo/src/customComponents/DateTimePicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import React from 'react'
1212
import DatePicker from 'react-datepicker'
1313
import { Button } from '@chakra-ui/react'
14-
import { CustomNodeProps, CustomNodeDefinition } from '../_imports'
14+
import { CustomNodeProps, CustomNodeDefinition } from '../imports'
1515

1616
// Styles
1717
import 'react-datepicker/dist/react-datepicker.css'

demo/src/demoData/dataDefinitions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
StringDisplay,
1313
StringEdit,
1414
toPathString,
15-
} from '../_imports'
15+
} from '../imports'
1616
import {
1717
DefaultValueFunction,
1818
ErrorString,

demo/src/imports/import.local.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '../json-edit-react/src'

demo/src/imports/import.package.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from 'json-edit-react'

demo/src/imports/import.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '../json-edit-react/src'

0 commit comments

Comments
 (0)