Skip to content

Commit 21fb3b4

Browse files
committed
lazy load editor + static build + update lucide
1 parent 541674b commit 21fb3b4

File tree

9 files changed

+186
-181
lines changed

9 files changed

+186
-181
lines changed

app.config.ts

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
1-
import { fileURLToPath, URL } from "node:url";
21
import { defineConfig } from "@solidjs/start/config";
32
import UnoCSS from "unocss/vite";
43
import wasmpack from "vite-plugin-wasm-pack";
54

65
export default defineConfig({
76
server: {
7+
static: true,
88
preset: "cloudflare-pages",
99
rollupConfig: {
10-
external: ["node:async_hooks"]
11-
}
10+
external: ["node:async_hooks"],
11+
},
1212
},
13-
ssr: true,
13+
ssr: false,
1414
vite: {
1515
plugins: [UnoCSS(), wasmpack([], ["fuqr"]), blobRewriter()],
16-
resolve: {
17-
alias: {
18-
// https://christopher.engineering/en/blog/lucide-icons-with-vite-dev-server/
19-
"lucide-solid/icons": fileURLToPath(
20-
new URL(
21-
"./node_modules/lucide-solid/dist/source/icons",
22-
import.meta.url
23-
)
24-
),
25-
},
26-
},
2716
},
2817
});
2918

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@unocss/reset": "^0.59.4",
2525
"codemirror": "^6.0.1",
2626
"fuqr": "^1.0.0",
27-
"lucide-solid": "^0.378.0",
27+
"lucide-solid": "^0.474.0",
2828
"solid-js": "^1.9.2",
2929
"unocss": "^0.59.4",
3030
"vinxi": "^0.3.11"

pnpm-lock.yaml

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/@types/lucide.d.ts

-7
This file was deleted.

src/components/Switch.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function Switch(props: Props) {
1818
)}
1919
<KSwitch.Input class="peer" />
2020
<KSwitch.Control class="inline-flex items-center w-11 h-6 px-0.5 bg-back-distinct data-[checked]:bg-fore-base transition-colors border rounded-3 peer-focus:(ring-2 ring-fore-base ring-offset-2 ring-offset-back-base)">
21-
<KSwitch.Thumb class="h-5 w-5 rounded-2.5 bg-back-base data-[checked]:translate-x-[calc(100%-1px)] transition-transform" />
21+
<KSwitch.Thumb class="h-5 w-5 rounded-2.5 bg-back-base data-[checked]:translate-x-[calc(100%-.125rem)] transition-transform" />
2222
</KSwitch.Control>
2323
</KSwitch>
2424
);

src/components/editor/CodeEditor.tsx

+41-50
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createEffect, createSignal, onMount, Show, untrack } from "solid-js";
1+
import { createEffect, createSignal, onMount, untrack } from "solid-js";
22

33
import { basicSetup } from "codemirror";
44
import { historyKeymap, indentWithTab } from "@codemirror/commands";
@@ -14,7 +14,6 @@ import { vim } from "@replit/codemirror-vim";
1414

1515
import { Button } from "@kobalte/core/button";
1616
import { debounce } from "~/lib/util";
17-
import { Switch } from "../Switch";
1817
import { AllowPasteDialog } from "./AllowPasteDialog";
1918

2019
type Props = {
@@ -26,7 +25,7 @@ const VIM_MODE_KEY = "vimMode";
2625
const ALLOW_PASTE_KEY = "allowPaste";
2726

2827
export function CodeEditor(props: Props) {
29-
let parent: HTMLDivElement;
28+
let parent!: HTMLDivElement;
3029
let view: EditorView;
3130
let modeComp = new Compartment();
3231
let allowPaste;
@@ -140,58 +139,50 @@ export function CodeEditor(props: Props) {
140139
view.contentDOM.blur();
141140
});
142141

143-
const [showCode, setShowCode] = createSignal(false);
144142
const [showDialog, setShowDialog] = createSignal(false);
145143

146144
return (
147145
<>
148-
<div class="py-2">
149-
<Switch label="Code editor" value={showCode()} setValue={setShowCode} />
150-
</div>
151-
<div>
152-
<AllowPasteDialog
153-
open={showDialog()}
154-
setClosed={() => {
155-
setShowDialog(false);
156-
}}
157-
onAllow={() => {
158-
allowPaste = true;
159-
localStorage.setItem(ALLOW_PASTE_KEY, "true");
160-
}}
161-
/>
162-
<div class="flex justify-end gap-4 pb-2 h-11">
163-
<Show when={showCode()}>
164-
<label class="flex items-center gap-1 text-sm">
165-
Vim mode
166-
<input
167-
class="h-4 w-4"
168-
type="checkbox"
169-
checked={vimMode()}
170-
onChange={(e) => setVimMode(e.target.checked)}
171-
/>
172-
</label>
173-
<label class="flex items-center gap-1 text-sm">
174-
Update thumbnail
175-
<input
176-
class="h-4 w-4"
177-
type="checkbox"
178-
checked={updateThumbnail()}
179-
onChange={(e) => setUpdateThumbnail(e.target.checked)}
180-
/>
181-
</label>
182-
<Button
183-
disabled={!dirty()}
184-
onMouseDown={() =>
185-
props.onSave(view.state.doc.toString(), updateThumbnail())
186-
}
187-
class="bg-green-700 border rounded-md hover:bg-green-700/90 focus-visible:(outline-none ring-2 ring-fore-base ring-offset-2 ring-offset-back-base) disabled:(bg-transparent text-fore-base pointer-events-none opacity-50) transition-colors px-3 min-w-150px"
188-
>
189-
{dirty() ? "Save" : "No changes"}
190-
</Button>
191-
</Show>
192-
</div>
193-
<div ref={parent!} classList={{ hidden: !showCode() }}></div>
146+
<AllowPasteDialog
147+
open={showDialog()}
148+
setClosed={() => {
149+
setShowDialog(false);
150+
}}
151+
onAllow={() => {
152+
allowPaste = true;
153+
localStorage.setItem(ALLOW_PASTE_KEY, "true");
154+
}}
155+
/>
156+
<div class="flex justify-end gap-4 py-2">
157+
<label class="flex items-center gap-1 text-sm">
158+
Vim mode
159+
<input
160+
class="h-4 w-4"
161+
type="checkbox"
162+
checked={vimMode()}
163+
onChange={(e) => setVimMode(e.target.checked)}
164+
/>
165+
</label>
166+
<label class="flex items-center gap-1 text-sm">
167+
Update thumbnail
168+
<input
169+
class="h-4 w-4"
170+
type="checkbox"
171+
checked={updateThumbnail()}
172+
onChange={(e) => setUpdateThumbnail(e.target.checked)}
173+
/>
174+
</label>
175+
<Button
176+
disabled={!dirty()}
177+
onMouseDown={() =>
178+
props.onSave(view.state.doc.toString(), updateThumbnail())
179+
}
180+
class="bg-green-700 border rounded-md hover:bg-green-700/90 focus-visible:(outline-none ring-2 ring-fore-base ring-offset-2 ring-offset-back-base) disabled:(bg-transparent text-fore-base pointer-events-none opacity-50) transition-colors px-3 py-1 min-w-150px"
181+
>
182+
{dirty() ? "Save" : "No changes"}
183+
</Button>
194184
</div>
185+
<div ref={parent!}></div>
195186
</>
196187
);
197188
}

src/components/editor/ParamsEditor.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import {
2-
closestCenter, createSortable, DragDropProvider,
2+
closestCenter,
3+
createSortable,
4+
DragDropProvider,
35
DragDropSensors,
46
DragOverlay,
5-
SortableProvider, transformStyle, useDragDropContext
7+
SortableProvider,
8+
transformStyle,
9+
useDragDropContext,
610
} from "@thisbeyond/solid-dnd";
711
import GripVertical from "lucide-solid/icons/grip-vertical";
812
import Minus from "lucide-solid/icons/minus";
@@ -16,7 +20,7 @@ import { FlatButton } from "../Button";
1620
export function ParamsEditor() {
1721
const { paramsSchema, params, setParams } = useRenderContext();
1822
return (
19-
<div class="flex flex-col gap-2 mb-4">
23+
<div class="flex flex-col gap-2">
2024
<For each={Object.entries(paramsSchema())}>
2125
{([label, { type, ...other }]) => {
2226
if (type === "array") {
@@ -125,7 +129,10 @@ function ArrayParam({ label, other }) {
125129
value={v()}
126130
setValue={(v: any) => setParams(label, i, v)}
127131
/>
128-
<div class="px-1 cursor-move touch-none" {...sortable.dragActivators}>
132+
<div
133+
class="px-1 cursor-move touch-none"
134+
{...sortable.dragActivators}
135+
>
129136
<GripVertical />
130137
</div>
131138
</div>

src/components/editor/QrEditor.tsx

+45-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import Pencil from "lucide-solid/icons/pencil";
22
import Trash2 from "lucide-solid/icons/trash-2";
3-
import { For, Show, batch, createSignal, onMount, type JSX } from "solid-js";
3+
import {
4+
For,
5+
Show,
6+
Suspense,
7+
batch,
8+
createSignal,
9+
lazy,
10+
onMount,
11+
type JSX,
12+
} from "solid-js";
413
import { createStore } from "solid-js/store";
514
import {
615
deepEqualObj,
@@ -17,9 +26,15 @@ import { Collapsible } from "../Collapsible";
1726
import { ContentMenuTrigger, ContextMenuProvider } from "../ContextMenu";
1827
import { ControlledDialog, DialogButton } from "../Dialog";
1928
import { TextInput, TextareaInput } from "../TextInput";
20-
import { CodeEditor } from "./CodeEditor";
2129
import { ParamsEditor } from "./ParamsEditor";
2230
import { Settings } from "./Settings";
31+
import { Switch } from "../Switch";
32+
33+
const CodeEditor = lazy(() => {
34+
return import("./CodeEditor").then((module) => ({
35+
default: module.CodeEditor,
36+
}));
37+
});
2338

2439
import "virtual:blob-rewriter";
2540

@@ -286,6 +301,8 @@ export function Editor(props: Props) {
286301
saveAndRun(code, true, true);
287302
};
288303

304+
const [showCode, setShowCode] = createSignal(false);
305+
289306
return (
290307
<div class={props.class}>
291308
<TextareaInput
@@ -310,7 +327,7 @@ export function Editor(props: Props) {
310327
const [rename, setRename] = createSignal(key);
311328
const [duplicate, setDuplicate] = createSignal(false);
312329

313-
let ref: HTMLInputElement;
330+
let ref!: HTMLInputElement;
314331
onMount(() => ref.focus());
315332

316333
const onSubmit = () => {
@@ -340,7 +357,7 @@ export function Editor(props: Props) {
340357
<>
341358
<TextInput
342359
class="mt-2"
343-
ref={ref!}
360+
ref={ref}
344361
defaultValue={rename()}
345362
onInput={(s) => {
346363
if (duplicate()) setDuplicate(false);
@@ -397,8 +414,8 @@ export function Editor(props: Props) {
397414
);
398415
}}
399416
</ControlledDialog>
400-
<div class="py-4">
401-
<div class="mb-4 h-[180px] md:(h-unset)">
417+
<div class="py-4 flex flex-col gap-4">
418+
<div class="h-[180px] md:(h-unset)">
402419
<div class="flex justify-between">
403420
<div class="text-sm py-2 border border-transparent">Presets</div>
404421
<div class="flex gap-2">
@@ -429,7 +446,7 @@ export function Editor(props: Props) {
429446
</Show>
430447
</div>
431448
</div>
432-
<div class="flex gap-3 pt-2 pb-4 md:(flex-wrap static ml-0 px-0 overflow-x-visible) absolute max-w-full overflow-x-auto -ml-6 px-6">
449+
<div class="flex gap-3 py-2 md:(flex-wrap static ml-0 px-0 overflow-x-visible) absolute max-w-full overflow-x-auto -ml-6 px-6">
433450
<ContextMenuProvider
434451
disabled={isPreset(dialogKey())}
435452
onRename={() => setRenameOpen(true)}
@@ -466,16 +483,27 @@ export function Editor(props: Props) {
466483
</div>
467484
</div>
468485
<ParamsEditor />
469-
<CodeEditor
470-
initialValue={code()}
471-
onSave={(code, updateThumbnail) => {
472-
if (presetKeys.includes(renderKey())) {
473-
createAndSelectFunc(renderKey(), code);
474-
} else {
475-
saveAndRun(code, true, updateThumbnail);
476-
}
477-
}}
478-
/>
486+
<div>
487+
<Switch
488+
label="Code editor"
489+
value={showCode()}
490+
setValue={setShowCode}
491+
/>
492+
<Show when={showCode()}>
493+
<Suspense fallback={<p>Loading...</p>}>
494+
<CodeEditor
495+
initialValue={code()}
496+
onSave={(code, updateThumbnail) => {
497+
if (presetKeys.includes(renderKey())) {
498+
createAndSelectFunc(renderKey(), code);
499+
} else {
500+
saveAndRun(code, true, updateThumbnail);
501+
}
502+
}}
503+
/>
504+
</Suspense>
505+
</Show>
506+
</div>
479507
</div>
480508
</Collapsible>
481509
</div>

0 commit comments

Comments
 (0)