@dexhq/canvas 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/app/canvas/activity-parts.tsx +50 -6
- package/app/canvas/activity.tsx +2 -3
- package/app/canvas/agent-changes.ts +18 -8
- package/app/canvas/anchoring.ts +13 -3
- package/app/canvas/canvas-context.tsx +6 -2
- package/app/canvas/canvas-input.ts +35 -0
- package/app/canvas/canvas-model.ts +2 -2
- package/app/canvas/canvas-scene.ts +243 -24
- package/app/canvas/canvas-ui.ts +11 -2
- package/app/canvas/canvas.css +86 -3
- package/app/canvas/comments.tsx +66 -29
- package/app/canvas/element-link.ts +135 -0
- package/app/canvas/element-picker.ts +23 -0
- package/app/canvas/export-dialog.tsx +265 -0
- package/app/canvas/flow-canvas.tsx +65 -14
- package/app/canvas/frame-context-menu.tsx +61 -7
- package/app/canvas/frame-node.tsx +10 -11
- package/app/canvas/layout.ts +41 -22
- package/app/canvas/linked-element.tsx +196 -0
- package/app/canvas/live-page.ts +14 -0
- package/app/canvas/mentions.tsx +209 -0
- package/app/canvas/picked-box.tsx +21 -0
- package/app/canvas/removed-views-panel.tsx +4 -4
- package/app/canvas/request-node.tsx +151 -0
- package/app/canvas/review-panel.tsx +8 -3
- package/app/canvas/section-node.tsx +4 -133
- package/app/canvas/spec-margin.tsx +4 -1
- package/app/canvas/teammates-layer.tsx +205 -0
- package/app/canvas/text-layer.tsx +103 -17
- package/app/canvas/tool-cursors.ts +7 -6
- package/app/canvas/tool-icons.tsx +24 -56
- package/app/canvas/typing.ts +12 -0
- package/app/canvas/use-agent-changes.tsx +6 -2
- package/app/canvas/use-canvas-editor.ts +4 -2
- package/app/export/player-model.ts +159 -0
- package/app/export/player.tsx +198 -0
- package/app/export.html +31 -0
- package/app/export.tsx +9 -0
- package/app/frame/announce-refreshes.ts +21 -0
- package/app/frame/start-frame.tsx +50 -0
- package/app/frame/view-loads.ts +161 -0
- package/app/frame/views.ts +13 -49
- package/app/frame.tsx +2 -38
- package/app/i18n/locales/en/messages.po +145 -6
- package/app/i18n/locales/en/messages.ts +1 -1
- package/app/i18n/locales/pseudo/messages.po +144 -5
- package/app/i18n/locales/pseudo/messages.ts +1 -1
- package/app/icons/dex-glyphs.tsx +219 -0
- package/app/icons/glyphs.tsx +76 -80
- package/app/kit/use-flow.ts +2 -1
- package/app/live/canvas-teammates.ts +90 -0
- package/app/live/studio-api.ts +30 -20
- package/app/pages/canvas.tsx +18 -6
- package/app/pages/commands-settings.tsx +1 -1
- package/app/pages/render.tsx +39 -11
- package/app/shell/bell.tsx +15 -5
- package/app/shell/presence.tsx +123 -26
- package/app/shell/thread-list.tsx +25 -8
- package/app/shell/working-on.tsx +35 -3
- package/app/ui/prompt-editor.tsx +39 -11
- package/app/ui/reference.tsx +21 -8
- package/bin/sudio.mjs +1 -1
- package/dist/cli/commands/create.d.mts +5 -5
- package/dist/cli/commands/create.mjs +4 -4
- package/dist/cli/commands/export.d.mts +40 -0
- package/dist/cli/commands/export.mjs +66 -0
- package/dist/cli/commands/init.d.mts +2 -2
- package/dist/cli/commands/upgrade.mjs +1 -1
- package/dist/cli/help.d.mts +1 -1
- package/dist/cli/help.mjs +13 -7
- package/dist/cli/main.d.mts +42 -5
- package/dist/cli/main.mjs +1 -0
- package/dist/config/load.mjs +14 -2
- package/dist/config/project-files.d.mts +5 -0
- package/dist/config/project-files.mjs +10 -1
- package/dist/config/renamed.d.mts +7 -0
- package/dist/config/renamed.mjs +13 -1
- package/dist/content/commands.d.mts +11 -9
- package/dist/content/commands.mjs +22 -16
- package/dist/content/comments-log.mjs +2 -1
- package/dist/content/content.d.mts +11 -3
- package/dist/content/content.mjs +49 -15
- package/dist/content/element-words.d.mts +42 -0
- package/dist/content/element-words.mjs +112 -0
- package/dist/content/hosted-person.d.mts +31 -0
- package/dist/content/hosted-person.mjs +68 -0
- package/dist/content/merge-rules.d.mts +5 -0
- package/dist/content/merge-rules.mjs +17 -1
- package/dist/content/screenshot.mjs +9 -0
- package/dist/content/text-edit.d.mts +24 -14
- package/dist/content/text-edit.mjs +92 -81
- package/dist/content/text-replace.mjs +2 -26
- package/dist/content/thread-module.d.mts +2 -4
- package/dist/content/thread-module.mjs +4 -5
- package/dist/server/agents.d.mts +10 -0
- package/dist/server/agents.mjs +21 -6
- package/dist/server/canvas-presence.d.mts +22 -0
- package/dist/server/canvas-presence.mjs +160 -0
- package/dist/server/command-settings.mjs +1 -1
- package/dist/server/comments/actions.d.mts +0 -8
- package/dist/server/comments/actions.mjs +1 -9
- package/dist/server/comments/routes.mjs +10 -31
- package/dist/server/dev-server.mjs +35 -13
- package/dist/server/export/build.d.mts +15 -0
- package/dist/server/export/build.mjs +220 -0
- package/dist/server/export/page.d.mts +25 -0
- package/dist/server/export/page.mjs +40 -0
- package/dist/server/export/plugin.d.mts +31 -0
- package/dist/server/export/plugin.mjs +69 -0
- package/dist/server/export/run.d.mts +9 -0
- package/dist/server/export/run.mjs +61 -0
- package/dist/server/export/save.d.mts +7 -0
- package/dist/server/export/save.mjs +29 -0
- package/dist/server/hosted.d.mts +8 -0
- package/dist/server/hosted.mjs +78 -0
- package/dist/server/live-mirror.mjs +66 -10
- package/dist/server/live.mjs +28 -1
- package/dist/server/mcp.mjs +2 -0
- package/dist/server/me.d.mts +2 -0
- package/dist/server/me.mjs +8 -2
- package/dist/server/notices.d.mts +1 -1
- package/dist/server/notices.mjs +1 -1
- package/dist/server/own-copies.mjs +1 -1
- package/dist/server/people.d.mts +7 -2
- package/dist/server/people.mjs +6 -2
- package/dist/server/pictures.d.mts +1 -1
- package/dist/server/pictures.mjs +2 -2
- package/dist/server/prebundle.d.mts +32 -0
- package/dist/server/prebundle.mjs +115 -0
- package/dist/server/problems.d.mts +8 -0
- package/dist/server/problems.mjs +13 -0
- package/dist/server/requests.mjs +43 -30
- package/dist/server/source-stamp.d.mts +4 -3
- package/dist/server/source-stamp.mjs +60 -31
- package/dist/server/state.d.mts +19 -10
- package/dist/server/state.mjs +27 -18
- package/dist/server/thread-source.d.mts +8 -0
- package/dist/server/thread-source.mjs +24 -5
- package/dist/server/tools/export.d.mts +5 -0
- package/dist/server/tools/export.mjs +35 -0
- package/dist/server/tools/place-frame.mjs +16 -16
- package/dist/server/tools/thread-list.mjs +1 -1
- package/dist/server/vite.d.mts +9 -4
- package/dist/server/vite.mjs +63 -61
- package/dist/server/welcome.mjs +2 -1
- package/dist/setup/apply.d.mts +4 -0
- package/dist/setup/apply.mjs +5 -4
- package/dist/setup/create.mjs +5 -5
- package/dist/setup/design-system-checks.mjs +1 -6
- package/dist/setup/detect/workspace.d.mts +10 -10
- package/dist/setup/detect/workspace.mjs +10 -12
- package/dist/setup/doctor.d.mts +4 -1
- package/dist/setup/doctor.mjs +7 -5
- package/dist/setup/migrate/dex-folder.d.mts +61 -0
- package/dist/setup/migrate/dex-folder.mjs +544 -0
- package/dist/setup/migrate/files-folder.mjs +1 -1
- package/dist/setup/migrate/guides.mjs +1 -1
- package/dist/setup/migrate/migrations.mjs +4 -0
- package/dist/setup/migrate/setup-files.d.mts +5 -0
- package/dist/setup/migrate/setup-files.mjs +115 -0
- package/dist/setup/migrate/studio-state.d.mts +2 -2
- package/dist/setup/migrate/studio-state.mjs +4 -4
- package/dist/setup/placement.d.mts +1 -1
- package/dist/setup/placement.mjs +5 -4
- package/dist/setup/plan.d.mts +5 -5
- package/dist/setup/plan.mjs +8 -12
- package/dist/setup/project.mjs +1 -1
- package/dist/setup/prompts.d.mts +2 -1
- package/dist/setup/prompts.mjs +4 -3
- package/dist/setup/questions.mjs +3 -2
- package/dist/setup/starters.d.mts +1 -1
- package/dist/setup/starters.mjs +2 -2
- package/dist/setup/write.d.mts +15 -3
- package/dist/setup/write.mjs +23 -3
- package/dist/shared/canvas-core.d.mts +22 -7
- package/dist/shared/canvas-core.mjs +38 -10
- package/dist/shared/comments/routes.d.mts +3 -1
- package/dist/shared/comments/routes.mjs +4 -2
- package/dist/shared/export-core.d.mts +62 -0
- package/dist/shared/export-core.mjs +101 -0
- package/dist/shared/live-core.d.mts +2 -0
- package/dist/shared/live-core.mjs +6 -1
- package/dist/shared/live-presence.d.mts +57 -2
- package/dist/shared/live-presence.mjs +90 -4
- package/dist/shared/page-messages.d.mts +14 -1
- package/dist/shared/page-messages.mjs +30 -3
- package/dist/shared/people-core.d.mts +28 -0
- package/dist/shared/people-core.mjs +27 -1
- package/dist/shared/presence-core.d.mts +2 -0
- package/dist/shared/references-core.d.mts +4 -0
- package/dist/shared/references-core.mjs +12 -4
- package/dist/shared/studio-files.d.mts +9 -0
- package/dist/shared/studio-files.mjs +11 -2
- package/dist/shared/studio-routes.d.mts +13 -1
- package/dist/shared/threads-core.d.mts +27 -4
- package/dist/shared/threads-core.mjs +67 -12
- package/extension/dist/feedback.js +104 -294
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/picker.js +104 -294
- package/package.json +2 -2
- package/src/cli/commands/create.ts +4 -4
- package/src/cli/commands/export.ts +78 -0
- package/src/cli/commands/upgrade.ts +1 -1
- package/src/cli/help.ts +13 -7
- package/src/cli/main.ts +1 -0
- package/src/config/load.ts +26 -2
- package/src/config/project-files.ts +15 -0
- package/src/config/renamed.ts +19 -1
- package/src/content/commands.ts +30 -18
- package/src/content/comments-log.ts +4 -1
- package/src/content/content.ts +64 -16
- package/src/content/element-words.ts +175 -0
- package/src/content/hosted-person.ts +107 -0
- package/src/content/merge-rules.ts +29 -0
- package/src/content/screenshot.ts +14 -0
- package/src/content/text-edit.ts +172 -105
- package/src/content/text-replace.ts +3 -32
- package/src/content/thread-module.ts +2 -4
- package/src/content/trash.ts +1 -1
- package/src/server/agents.ts +48 -17
- package/src/server/canvas-presence.ts +237 -0
- package/src/server/channel.ts +1 -1
- package/src/server/command-settings.ts +1 -1
- package/src/server/comments/actions.ts +0 -19
- package/src/server/comments/routes.ts +9 -54
- package/src/server/dev-server.ts +66 -26
- package/src/server/export/build.ts +310 -0
- package/src/server/export/page.ts +85 -0
- package/src/server/export/plugin.ts +138 -0
- package/src/server/export/run.ts +79 -0
- package/src/server/export/save.ts +38 -0
- package/src/server/hosted.ts +113 -0
- package/src/server/live-mirror.ts +93 -8
- package/src/server/live.ts +46 -1
- package/src/server/machine-update.ts +3 -3
- package/src/server/mcp.ts +2 -0
- package/src/server/me.ts +10 -1
- package/src/server/notices.ts +2 -2
- package/src/server/people.ts +11 -2
- package/src/server/pictures.ts +2 -2
- package/src/server/prebundle.ts +230 -0
- package/src/server/presence.ts +1 -1
- package/src/server/problems.ts +11 -0
- package/src/server/requests.ts +55 -40
- package/src/server/roster.ts +1 -1
- package/src/server/saved.ts +1 -1
- package/src/server/source-stamp.ts +118 -37
- package/src/server/state.ts +53 -31
- package/src/server/thread-source.ts +35 -3
- package/src/server/tools/export.ts +56 -0
- package/src/server/tools/place-frame.ts +23 -15
- package/src/server/tools/thread-list.ts +1 -1
- package/src/server/updates.ts +2 -2
- package/src/server/vite.ts +106 -110
- package/src/server/welcome.ts +3 -1
- package/src/setup/apply.ts +8 -5
- package/src/setup/create.ts +10 -10
- package/src/setup/design-system-checks.ts +1 -6
- package/src/setup/detect/workspace.ts +20 -21
- package/src/setup/doctor.ts +13 -6
- package/src/setup/migrate/dex-folder.ts +842 -0
- package/src/setup/migrate/files-folder.ts +1 -1
- package/src/setup/migrate/guides.ts +3 -1
- package/src/setup/migrate/migrations.ts +8 -2
- package/src/setup/migrate/setup-files.ts +198 -0
- package/src/setup/migrate/studio-state.ts +12 -10
- package/src/setup/own-app.ts +1 -1
- package/src/setup/placement.ts +7 -6
- package/src/setup/plan.ts +13 -18
- package/src/setup/project.ts +2 -2
- package/src/setup/prompts.ts +5 -4
- package/src/setup/questions.ts +6 -3
- package/src/setup/starters.ts +3 -3
- package/src/setup/write.ts +34 -3
- package/src/shared/canvas-core.ts +48 -9
- package/src/shared/comments/routes.ts +3 -1
- package/src/shared/export-core.ts +198 -0
- package/src/shared/live-core.ts +8 -0
- package/src/shared/live-presence.ts +171 -2
- package/src/shared/page-messages.ts +38 -2
- package/src/shared/people-core.ts +44 -0
- package/src/shared/presence-core.ts +2 -0
- package/src/shared/references-core.ts +22 -3
- package/src/shared/studio-files.ts +15 -1
- package/src/shared/studio-routes.ts +11 -1
- package/src/shared/threads-core.ts +132 -10
- package/templates/methods/explore.md +1 -1
- package/templates/methods/handoff.md +1 -1
- package/templates/methods/review.md +2 -1
- package/templates/rules/canvas-frames.md +6 -3
- package/templates/rules/commands.md +1 -0
- package/templates/rules/prototypes.md +1 -1
- package/templates/rules/studio.md +17 -11
- package/templates/skills/comprehend/SKILL.md +56 -0
- package/templates/skills/distill/SKILL.md +172 -0
- package/templates/skills/export-prototype/SKILL.md +35 -0
- package/templates/skills/riff/SKILL.md +21 -0
- package/templates/skills/riff-deep/SKILL.md +40 -0
- package/templates/skills/riff-max/SKILL.md +46 -0
- package/templates/skills/riff-state/SKILL.md +45 -0
- package/templates/skills/riff-up/SKILL.md +38 -0
- package/templates/skills/riff-wide/SKILL.md +40 -0
- package/templates/starters/standalone/README.md +1 -1
- package/templates/starters/turborepo/README.md +2 -2
- package/templates/starters/turborepo/apps/web/src/app.tsx +2 -2
- package/templates/starters/vite/README.md +1 -1
package/src/server/dev-server.ts
CHANGED
|
@@ -9,14 +9,19 @@
|
|
|
9
9
|
// - a prototype's content appearing or disappearing updates the registry in
|
|
10
10
|
// place, once, so open pages render again without reloading;
|
|
11
11
|
// - saving a canvas, a comment or instructions never reloads the page, nor
|
|
12
|
-
// does a
|
|
12
|
+
// does a file no page has, such as a new file's docs/.gitkeep;
|
|
13
13
|
// - an SVG is served so that, opened on its own, it runs nothing;
|
|
14
14
|
// - the request module is mounted on Vite's server.
|
|
15
15
|
|
|
16
16
|
import { existsSync, realpathSync, type Stats } from "node:fs";
|
|
17
17
|
import { homedir } from "node:os";
|
|
18
18
|
import { basename, dirname, join, relative, sep } from "node:path";
|
|
19
|
-
import
|
|
19
|
+
import {
|
|
20
|
+
type EnvironmentModuleNode,
|
|
21
|
+
isCSSRequest,
|
|
22
|
+
type Plugin,
|
|
23
|
+
type ViteDevServer,
|
|
24
|
+
} from "vite";
|
|
20
25
|
import { findConfigFile } from "../config/load.ts";
|
|
21
26
|
import { prototypesDir } from "../content/prototypes.ts";
|
|
22
27
|
import { closeScreenshotBrowser } from "../content/screenshot.ts";
|
|
@@ -31,6 +36,7 @@ import {
|
|
|
31
36
|
revealInFinder,
|
|
32
37
|
servedApp,
|
|
33
38
|
} from "../setup/desktop-app.ts";
|
|
39
|
+
import { isInside } from "../setup/detect/workspace.ts";
|
|
34
40
|
import { AVATAR_FILES } from "../shared/avatar-file.ts";
|
|
35
41
|
import { PROTOTYPES_FOLDER } from "../shared/prototypes-core.ts";
|
|
36
42
|
import { eventsForFile, studioEvent } from "../shared/studio-events.ts";
|
|
@@ -80,6 +86,15 @@ const SVG_PATH_RE = /\.svgz?$/i;
|
|
|
80
86
|
const SVG_POLICY =
|
|
81
87
|
"default-src 'none'; style-src 'unsafe-inline'; img-src data:; sandbox";
|
|
82
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Whether a page imports a module. A stylesheet's import is only Tailwind's
|
|
91
|
+
* scan: Tailwind makes a stylesheet depend on every file in the folders it
|
|
92
|
+
* scans for classes (the frame's, the files folder; the interface's, Dex's
|
|
93
|
+
* own app), and Vite records each as a module the stylesheet imports.
|
|
94
|
+
*/
|
|
95
|
+
const importedByPage = (module: { importers: Set<{ url: string }> }): boolean =>
|
|
96
|
+
[...module.importers].some((importer) => !isCSSRequest(importer.url));
|
|
97
|
+
|
|
83
98
|
/**
|
|
84
99
|
* Whether a module is a file-only entry nothing imports any more. For each
|
|
85
100
|
* file a stylesheet depends on, such as each view's stylesheet Tailwind
|
|
@@ -88,11 +103,33 @@ const SVG_POLICY =
|
|
|
88
103
|
* file is deleted and Tailwind scans again, nothing imports the entry, but
|
|
89
104
|
* Vite keeps it; when a file is written at that path again (a review
|
|
90
105
|
* imported again, a file restored), Vite finds nothing that takes the
|
|
91
|
-
* update and reloads every page.
|
|
106
|
+
* update and reloads every page.
|
|
92
107
|
*/
|
|
93
108
|
const orphanedFileOnlyEntry = (module: EnvironmentModuleNode): boolean =>
|
|
94
109
|
module.id === null && module.importers.size === 0;
|
|
95
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Whether only the stylesheets that scan a module import it, outside Dex's
|
|
113
|
+
* own app: a file Tailwind scans that no page loads, such as a new file's
|
|
114
|
+
* docs/.gitkeep, scanned and then reported again. Vite takes a module only
|
|
115
|
+
* stylesheets import for a page itself (an HTML template Tailwind scans),
|
|
116
|
+
* and reloads every page when it changes. Only Dex's own app has pages
|
|
117
|
+
* (index.html and frame.html, and the scripts they load, which only
|
|
118
|
+
* stylesheets import), so there Vite is right.
|
|
119
|
+
*/
|
|
120
|
+
const onlyScanned = (module: EnvironmentModuleNode): boolean =>
|
|
121
|
+
module.file !== null &&
|
|
122
|
+
!isInside(APP_DIR, module.file) &&
|
|
123
|
+
module.importers.size > 0 &&
|
|
124
|
+
!importedByPage(module);
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Whether no page has a module, though Vite would reload every page for it
|
|
128
|
+
* (propagateUpdate's dead end).
|
|
129
|
+
*/
|
|
130
|
+
const pageless = (module: EnvironmentModuleNode): boolean =>
|
|
131
|
+
orphanedFileOnlyEntry(module) || onlyScanned(module);
|
|
132
|
+
|
|
96
133
|
/** Whether a request is for an SVG file, as Vite reads its path. */
|
|
97
134
|
const isSvgRequest = (url = ""): boolean => {
|
|
98
135
|
try {
|
|
@@ -183,7 +220,7 @@ export function studioDev(project: StudioDevProject): Plugin {
|
|
|
183
220
|
/**
|
|
184
221
|
* Whether `path` is a folder in the content folder the studio never reads,
|
|
185
222
|
* as the watcher may name it: any but its own, and every folder in
|
|
186
|
-
* .
|
|
223
|
+
* .local (pictures, the trash). A file never is, since Vite watches the
|
|
187
224
|
* files it imports wherever they are.
|
|
188
225
|
*/
|
|
189
226
|
const unread = (path: string, stats?: Stats): boolean => {
|
|
@@ -222,21 +259,21 @@ export function studioDev(project: StudioDevProject): Plugin {
|
|
|
222
259
|
// any file appears, and reloads the page for them, so a first pick
|
|
223
260
|
// (a new annotations.json) would.
|
|
224
261
|
// A person's picture as well: the registry takes it in place (below).
|
|
225
|
-
// Dex's merge rules
|
|
226
|
-
//
|
|
227
|
-
//
|
|
228
|
-
// (orphanedFileOnlyEntry): Vite would reload every page for it.
|
|
262
|
+
// And a file no page has (pageless), such as Dex's merge rules, which a
|
|
263
|
+
// first comment writes, or a new file's docs/.gitkeep: the stylesheets
|
|
264
|
+
// that scan it take it in place, for its classes.
|
|
229
265
|
hotUpdate({ file, modules }) {
|
|
230
|
-
if (
|
|
231
|
-
kindOf(file) !== "other" ||
|
|
232
|
-
isAvatar(file) ||
|
|
233
|
-
basename(file) === ".gitattributes"
|
|
234
|
-
) {
|
|
266
|
+
if (kindOf(file) !== "other" || isAvatar(file)) {
|
|
235
267
|
return [];
|
|
236
268
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
269
|
+
if (modules.some(pageless)) {
|
|
270
|
+
return [
|
|
271
|
+
...new Set(
|
|
272
|
+
modules.flatMap((module) =>
|
|
273
|
+
pageless(module) ? [...module.importers] : [module]
|
|
274
|
+
)
|
|
275
|
+
),
|
|
276
|
+
];
|
|
240
277
|
}
|
|
241
278
|
},
|
|
242
279
|
|
|
@@ -299,15 +336,21 @@ export function studioDev(project: StudioDevProject): Plugin {
|
|
|
299
336
|
// canvas, and each frame on it) render again without reloading, so
|
|
300
337
|
// nothing flashes. Vite reloads the page only if that fails.
|
|
301
338
|
let refresh: ReturnType<typeof setTimeout> | undefined;
|
|
339
|
+
// A glob is reloaded only where a page imports it. With no frame
|
|
340
|
+
// open, the frame page's (view-files.ts) is only in the interface's
|
|
341
|
+
// stylesheet, which scans Dex's own app, and Vite would reload every
|
|
342
|
+
// page for it.
|
|
343
|
+
const reloadGlob = (id: string) => {
|
|
344
|
+
const glob = server.moduleGraph.getModuleById(id);
|
|
345
|
+
if (glob && importedByPage(glob)) {
|
|
346
|
+
server.reloadModule(glob);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
302
349
|
// A person's own picture, added or taken away (from Settings → Profile,
|
|
303
350
|
// by hand or by a pull), changes only what the interface's glob finds.
|
|
304
351
|
const onPicture = (file: string) => {
|
|
305
|
-
if (
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
const files = server.moduleGraph.getModuleById(REGISTRY_FILES_MODULE);
|
|
309
|
-
if (files) {
|
|
310
|
-
server.reloadModule(files);
|
|
352
|
+
if (isAvatar(file)) {
|
|
353
|
+
reloadGlob(REGISTRY_FILES_MODULE);
|
|
311
354
|
}
|
|
312
355
|
};
|
|
313
356
|
server.watcher.on("add", onPicture);
|
|
@@ -325,10 +368,7 @@ export function studioDev(project: StudioDevProject): Plugin {
|
|
|
325
368
|
clearTimeout(refresh);
|
|
326
369
|
refresh = setTimeout(() => {
|
|
327
370
|
for (const id of CONTENT_GLOBS) {
|
|
328
|
-
|
|
329
|
-
if (files) {
|
|
330
|
-
server.reloadModule(files);
|
|
331
|
-
}
|
|
371
|
+
reloadGlob(id);
|
|
332
372
|
}
|
|
333
373
|
}, SETTLE_MS);
|
|
334
374
|
};
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import {
|
|
3
|
+
cp,
|
|
4
|
+
mkdir,
|
|
5
|
+
mkdtemp,
|
|
6
|
+
readdir,
|
|
7
|
+
readFile,
|
|
8
|
+
rm,
|
|
9
|
+
writeFile,
|
|
10
|
+
} from "node:fs/promises";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { dirname, join } from "node:path";
|
|
13
|
+
import type { InlineConfig, PluginOption } from "vite";
|
|
14
|
+
import { readCanvas } from "../../content/content.ts";
|
|
15
|
+
import { prototypeTitle, viewFiles } from "../../content/prototypes.ts";
|
|
16
|
+
import { APP_DIR } from "../../paths.ts";
|
|
17
|
+
import { frameTitle } from "../../shared/canvas-core.ts";
|
|
18
|
+
import {
|
|
19
|
+
type ExportChoice,
|
|
20
|
+
type ExportData,
|
|
21
|
+
type ExportedFrame,
|
|
22
|
+
exportedPath,
|
|
23
|
+
exportFileName,
|
|
24
|
+
exportSelection,
|
|
25
|
+
} from "../../shared/export-core.ts";
|
|
26
|
+
import { prototypeFiles, slugify } from "../../shared/prototypes-core.ts";
|
|
27
|
+
import { studioState } from "../state.ts";
|
|
28
|
+
import { frameStylesheet, type StudioProject, viteConfig } from "../vite.ts";
|
|
29
|
+
import { zipFolder } from "../zip.ts";
|
|
30
|
+
import {
|
|
31
|
+
APP_SCRIPT,
|
|
32
|
+
APP_STYLES,
|
|
33
|
+
CONTENT_SCRIPT,
|
|
34
|
+
contentScript,
|
|
35
|
+
exportPage,
|
|
36
|
+
} from "./page.ts";
|
|
37
|
+
import { type ExportFound, exportPlugin } from "./plugin.ts";
|
|
38
|
+
|
|
39
|
+
// Export prototype: the chosen frames of a file as a zip that opens by
|
|
40
|
+
// double-click, offline. The frame page (app/export.html, its player
|
|
41
|
+
// stepping as Play does) built as one classic script and one stylesheet,
|
|
42
|
+
// with only the exported views, none of Dex's interface, and none of the
|
|
43
|
+
// project's public folder: index.html, app.js and app.css, and per kind
|
|
44
|
+
// - pages: a page more for each frame, opening on it;
|
|
45
|
+
// - content: content.js, the words and data the views read from their
|
|
46
|
+
// content.json, to edit without building again, and the file's notes;
|
|
47
|
+
// - source: the prototype's files the bundle took, to build on.
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Dex's plugins an export leaves out: its web app's manifest and icons, and
|
|
51
|
+
* the project's public folder (copied whole).
|
|
52
|
+
*/
|
|
53
|
+
const LEFT_OUT = new Set(["studio-web-app", "dex:project-public"]);
|
|
54
|
+
|
|
55
|
+
const ENTRY = "export.html";
|
|
56
|
+
/** The frame page's stylesheet, as its entry imports it. */
|
|
57
|
+
const FRAME_CSS_RE = /^@studio-frame\.css$/;
|
|
58
|
+
/** What the build may write: the page, its script and its stylesheet. */
|
|
59
|
+
const BUILT = new Set([ENTRY, APP_SCRIPT, APP_STYLES]);
|
|
60
|
+
/** Dex's own files a build writes that an export has no use for. */
|
|
61
|
+
const DEX_FILES = new Set(["workspace-icon.svg", "workspace-icon.png"]);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Keep only what the page loads. Anything else the bundle needs, such as a
|
|
65
|
+
* worker or WebAssembly, can't load from a page opened by double-click: the
|
|
66
|
+
* export fails rather than open broken.
|
|
67
|
+
*/
|
|
68
|
+
async function keepBuilt(out: string) {
|
|
69
|
+
for (const file of await readdir(out)) {
|
|
70
|
+
if (DEX_FILES.has(file)) {
|
|
71
|
+
await rm(join(out, file));
|
|
72
|
+
} else if (!BUILT.has(file)) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`The prototype needs ${file}, which a page opened by double-click can't load (a worker or WebAssembly). Leave out the frames that use it, then export again.`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ExportResult {
|
|
81
|
+
/** The zip, as its file would hold it. */
|
|
82
|
+
bytes: Buffer;
|
|
83
|
+
/** What the zip is called: the file's title. */
|
|
84
|
+
name: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const flatten = (options: readonly unknown[]): unknown[] =>
|
|
88
|
+
options.flatMap((option) =>
|
|
89
|
+
Array.isArray(option) ? flatten(option) : [option]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const plugins = (options: PluginOption[] | undefined): PluginOption[] =>
|
|
93
|
+
flatten(options ?? []).filter((plugin) => {
|
|
94
|
+
const name =
|
|
95
|
+
plugin && typeof plugin === "object" && "name" in plugin
|
|
96
|
+
? plugin.name
|
|
97
|
+
: undefined;
|
|
98
|
+
return !(typeof name === "string" && LEFT_OUT.has(name));
|
|
99
|
+
}) as PluginOption[];
|
|
100
|
+
|
|
101
|
+
const exportedFrames = (data: ExportData): ExportedFrame[] =>
|
|
102
|
+
data.sections.flatMap((section) => section.rows.flatMap((row) => row.frames));
|
|
103
|
+
|
|
104
|
+
/** A page per frame, numbered in the canvas's order: "02-card-declined.html". */
|
|
105
|
+
const framePages = (data: ExportData) => {
|
|
106
|
+
const seen = new Set<string>();
|
|
107
|
+
return exportedFrames(data).flatMap((frame) => {
|
|
108
|
+
const start = exportedPath(data.slug, frame);
|
|
109
|
+
if (seen.has(start)) {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
seen.add(start);
|
|
113
|
+
const number = String(seen.size).padStart(2, "0");
|
|
114
|
+
const name = slugify(frameTitle(frame)) || frame.view;
|
|
115
|
+
return [{ file: `${number}-${name}.html`, start }];
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
async function markdownIn(folder: string): Promise<string[]> {
|
|
120
|
+
const entries = await readdir(folder, { recursive: true }).catch(() => []);
|
|
121
|
+
return entries.filter((entry) => entry.endsWith(".md")).sort();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Write what each kind adds beside the bundle. */
|
|
125
|
+
async function writeKind(
|
|
126
|
+
out: string,
|
|
127
|
+
choice: ExportChoice,
|
|
128
|
+
context: {
|
|
129
|
+
data: ExportData;
|
|
130
|
+
found: ExportFound;
|
|
131
|
+
html: string;
|
|
132
|
+
people: string[];
|
|
133
|
+
prototypeDir: string;
|
|
134
|
+
}
|
|
135
|
+
) {
|
|
136
|
+
const { data, found, html, people, prototypeDir } = context;
|
|
137
|
+
const content = choice.kind === "content";
|
|
138
|
+
await writeFile(join(out, "index.html"), exportPage(html, { content, data }));
|
|
139
|
+
if (choice.kind === "pages") {
|
|
140
|
+
for (const page of framePages(data)) {
|
|
141
|
+
await writeFile(
|
|
142
|
+
join(out, page.file),
|
|
143
|
+
exportPage(html, { content, data, start: page.start })
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (content) {
|
|
148
|
+
if (found.content.size === 0) {
|
|
149
|
+
throw new Error(
|
|
150
|
+
"None of these views reads its words from a content.json yet, so a content pack would have nothing to edit. Ask the agent to prepare one (/export-prototype content), then export again."
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
await writeFile(join(out, CONTENT_SCRIPT), contentScript(found.content));
|
|
154
|
+
// The file's notes and specs, as they are.
|
|
155
|
+
for (const person of people) {
|
|
156
|
+
const folder = join(prototypeDir, "people", person);
|
|
157
|
+
for (const file of await markdownIn(folder)) {
|
|
158
|
+
const to = join(out, "docs", file);
|
|
159
|
+
await mkdir(dirname(to), { recursive: true });
|
|
160
|
+
await cp(join(folder, file), to, { dereference: false });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (choice.kind === "source") {
|
|
165
|
+
for (const file of found.sources) {
|
|
166
|
+
const to = join(out, "source", file);
|
|
167
|
+
await mkdir(dirname(to), { recursive: true });
|
|
168
|
+
await cp(join(prototypeDir, file), to, { dereference: false });
|
|
169
|
+
}
|
|
170
|
+
await writeFile(
|
|
171
|
+
join(out, "source", "README.md"),
|
|
172
|
+
[
|
|
173
|
+
`# ${data.title}: source`,
|
|
174
|
+
"",
|
|
175
|
+
"The prototype's own files this export was built from: its views and",
|
|
176
|
+
"what they import. They render with the design system they were made",
|
|
177
|
+
"in, which is not included: build them where it is.",
|
|
178
|
+
"",
|
|
179
|
+
].join("\n")
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Run a build as production: React's JSX transform follows NODE_ENV, not
|
|
186
|
+
* Vite's mode, and in development (as under `dex dev`, or in tests) writes
|
|
187
|
+
* every element's file path into the bundle, people's names with them.
|
|
188
|
+
*/
|
|
189
|
+
async function productionBuild<T>(run: () => Promise<T>): Promise<T> {
|
|
190
|
+
const before = process.env.NODE_ENV;
|
|
191
|
+
process.env.NODE_ENV = "production";
|
|
192
|
+
try {
|
|
193
|
+
return await run();
|
|
194
|
+
} finally {
|
|
195
|
+
if (before === undefined) {
|
|
196
|
+
delete process.env.NODE_ENV;
|
|
197
|
+
} else {
|
|
198
|
+
process.env.NODE_ENV = before;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Export frames of a file, as `choice` says. Throws, saying why, when the
|
|
205
|
+
* choice names frames the file does not have or nothing that shows a view.
|
|
206
|
+
*/
|
|
207
|
+
export async function exportPrototype(
|
|
208
|
+
project: StudioProject,
|
|
209
|
+
slug: string,
|
|
210
|
+
choice: ExportChoice
|
|
211
|
+
): Promise<ExportResult> {
|
|
212
|
+
const files = prototypeFiles(slug);
|
|
213
|
+
if (!files) {
|
|
214
|
+
throw new Error(`"${slug}" is not a file's name.`);
|
|
215
|
+
}
|
|
216
|
+
const canvas = await readCanvas(slug, project.content);
|
|
217
|
+
const selection = exportSelection(canvas, choice);
|
|
218
|
+
const found = await viewFiles(project.content, slug);
|
|
219
|
+
const views = selection.views.map((name) => {
|
|
220
|
+
const view = found.get(name);
|
|
221
|
+
if (!view) {
|
|
222
|
+
throw new Error(`This file has no view "${name}".`);
|
|
223
|
+
}
|
|
224
|
+
return { name, file: view.file, person: view.person };
|
|
225
|
+
});
|
|
226
|
+
const people = [...new Set(views.map((view) => view.person))].sort();
|
|
227
|
+
const prototypeDir = join(project.content, files.folder);
|
|
228
|
+
const title = await prototypeTitle(project.content, slug);
|
|
229
|
+
const data: ExportData = {
|
|
230
|
+
flows: choice.flows ?? false,
|
|
231
|
+
slug,
|
|
232
|
+
sections: selection.sections,
|
|
233
|
+
title,
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const state = studioState(project.content);
|
|
237
|
+
const vite = await viteConfig(project, "production");
|
|
238
|
+
// Tailwind reads only the exported people's folders, not every file's.
|
|
239
|
+
const stylesheet = state.exportCss(randomUUID());
|
|
240
|
+
await writeFile(
|
|
241
|
+
stylesheet,
|
|
242
|
+
frameStylesheet(
|
|
243
|
+
project,
|
|
244
|
+
state.dir,
|
|
245
|
+
people.map((person) => join(prototypeDir, "people", person))
|
|
246
|
+
)
|
|
247
|
+
);
|
|
248
|
+
const out = await mkdtemp(join(tmpdir(), "dex-export-"));
|
|
249
|
+
const { found: bundled, plugin } = exportPlugin({
|
|
250
|
+
content: choice.kind === "content",
|
|
251
|
+
interfaceCss: state.entryCss,
|
|
252
|
+
people,
|
|
253
|
+
prototypeDir,
|
|
254
|
+
slug,
|
|
255
|
+
views,
|
|
256
|
+
});
|
|
257
|
+
try {
|
|
258
|
+
const config: InlineConfig = {
|
|
259
|
+
...vite,
|
|
260
|
+
base: "./",
|
|
261
|
+
logLevel: "warn",
|
|
262
|
+
publicDir: false,
|
|
263
|
+
plugins: [plugin, ...plugins(vite.plugins)],
|
|
264
|
+
resolve: {
|
|
265
|
+
...vite.resolve,
|
|
266
|
+
alias: [
|
|
267
|
+
{ find: FRAME_CSS_RE, replacement: stylesheet },
|
|
268
|
+
...((vite.resolve?.alias as { find: unknown }[] | undefined) ?? []),
|
|
269
|
+
] as never,
|
|
270
|
+
},
|
|
271
|
+
build: {
|
|
272
|
+
...vite.build,
|
|
273
|
+
outDir: out,
|
|
274
|
+
emptyOutDir: true,
|
|
275
|
+
copyPublicDir: false,
|
|
276
|
+
modulePreload: false,
|
|
277
|
+
cssCodeSplit: false,
|
|
278
|
+
// Fonts and images go inside app.css and app.js: a page opened by
|
|
279
|
+
// double-click can read nothing beside it but scripts and styles.
|
|
280
|
+
assetsInlineLimit: Number.MAX_SAFE_INTEGER,
|
|
281
|
+
chunkSizeWarningLimit: Number.MAX_SAFE_INTEGER,
|
|
282
|
+
rollupOptions: {
|
|
283
|
+
input: { export: join(APP_DIR, ENTRY) },
|
|
284
|
+
output: {
|
|
285
|
+
format: "iife",
|
|
286
|
+
inlineDynamicImports: true,
|
|
287
|
+
entryFileNames: APP_SCRIPT,
|
|
288
|
+
assetFileNames: APP_STYLES,
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
const { build } = await import("vite");
|
|
294
|
+
await productionBuild(() => build(config));
|
|
295
|
+
await keepBuilt(out);
|
|
296
|
+
const html = await readFile(join(out, ENTRY), "utf8");
|
|
297
|
+
await rm(join(out, ENTRY));
|
|
298
|
+
await writeKind(out, choice, {
|
|
299
|
+
data,
|
|
300
|
+
found: bundled,
|
|
301
|
+
html,
|
|
302
|
+
people,
|
|
303
|
+
prototypeDir,
|
|
304
|
+
});
|
|
305
|
+
return { bytes: await zipFolder(out), name: exportFileName(title) };
|
|
306
|
+
} finally {
|
|
307
|
+
await rm(out, { recursive: true, force: true });
|
|
308
|
+
await rm(stylesheet, { force: true });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CONTENT_GLOBAL,
|
|
3
|
+
EXPORT_GLOBAL,
|
|
4
|
+
type ExportData,
|
|
5
|
+
} from "../../shared/export-core.ts";
|
|
6
|
+
|
|
7
|
+
// An exported page's HTML, from the one Vite wrote: a page opened by
|
|
8
|
+
// double-click (file://) runs no module script and loads no stylesheet
|
|
9
|
+
// marked crossorigin, so its bundle becomes a classic script at the end of
|
|
10
|
+
// the body, after the export's data.
|
|
11
|
+
|
|
12
|
+
const MODULE_SCRIPT_RE =
|
|
13
|
+
/<script\b[^>]*\btype="module"[^>]*\bsrc="([^"]+)"[^>]*><\/script>\s*/g;
|
|
14
|
+
const CROSSORIGIN_RE = /\s+crossorigin(?:="[^"]*")?/g;
|
|
15
|
+
const TITLE_RE = /<title>[^<]*<\/title>/;
|
|
16
|
+
|
|
17
|
+
/** The JS the exported page runs, as the build names it. */
|
|
18
|
+
export const APP_SCRIPT = "app.js";
|
|
19
|
+
/** The stylesheet, as the build names it. */
|
|
20
|
+
export const APP_STYLES = "app.css";
|
|
21
|
+
/** A content pack's editable content. */
|
|
22
|
+
export const CONTENT_SCRIPT = "content.js";
|
|
23
|
+
|
|
24
|
+
/** JSON that can sit inside a <script>: no `</script>` or `<!--` in it. */
|
|
25
|
+
export const scriptJson = (value: unknown): string =>
|
|
26
|
+
JSON.stringify(value)
|
|
27
|
+
.replaceAll("<", "\\u003c")
|
|
28
|
+
.replaceAll("
", "\\u2028")
|
|
29
|
+
.replaceAll("
", "\\u2029");
|
|
30
|
+
|
|
31
|
+
const escapeHtml = (text: string) =>
|
|
32
|
+
text
|
|
33
|
+
.replaceAll("&", "&")
|
|
34
|
+
.replaceAll("<", "<")
|
|
35
|
+
.replaceAll(">", ">")
|
|
36
|
+
.replaceAll('"', """);
|
|
37
|
+
|
|
38
|
+
export interface PageOptions {
|
|
39
|
+
/** Load content.js before the bundle. */
|
|
40
|
+
content: boolean;
|
|
41
|
+
data: ExportData;
|
|
42
|
+
/** The frame the page opens on, when not the export's first. */
|
|
43
|
+
start?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* An exported page from Vite's HTML. Throws when the HTML is not what the
|
|
48
|
+
* build makes, rather than write a page that opens blank.
|
|
49
|
+
*/
|
|
50
|
+
export function exportPage(html: string, options: PageOptions): string {
|
|
51
|
+
const scripts = [...html.matchAll(MODULE_SCRIPT_RE)].map(([, src]) => src);
|
|
52
|
+
if (scripts.length !== 1 || scripts[0] !== `./${APP_SCRIPT}`) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`The export's page should load one script, ./${APP_SCRIPT}; it loads ${scripts.join(", ") || "none"}.`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
const tail = [
|
|
58
|
+
...(options.start
|
|
59
|
+
? [
|
|
60
|
+
`<script>if (!location.hash) location.hash = ${scriptJson(options.start)};</script>`,
|
|
61
|
+
]
|
|
62
|
+
: []),
|
|
63
|
+
`<script>window.${EXPORT_GLOBAL} = ${scriptJson(options.data)};</script>`,
|
|
64
|
+
...(options.content ? [`<script src="./${CONTENT_SCRIPT}"></script>`] : []),
|
|
65
|
+
`<script src="./${APP_SCRIPT}"></script>`,
|
|
66
|
+
];
|
|
67
|
+
const page = html
|
|
68
|
+
.replace(MODULE_SCRIPT_RE, "")
|
|
69
|
+
.replace(CROSSORIGIN_RE, "")
|
|
70
|
+
.replace(TITLE_RE, `<title>${escapeHtml(options.data.title)}</title>`)
|
|
71
|
+
.replace("</body>", `${tail.join("\n")}\n</body>`);
|
|
72
|
+
if (page.includes('type="module"')) {
|
|
73
|
+
throw new Error("The export's page still has a module script.");
|
|
74
|
+
}
|
|
75
|
+
return page;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** content.js: the content.json files a content pack's views read, to edit. */
|
|
79
|
+
export const contentScript = (content: Map<string, unknown>): string =>
|
|
80
|
+
[
|
|
81
|
+
"// The words and data this prototype shows, by the file they came from.",
|
|
82
|
+
"// Edit them here, save, and open index.html again.",
|
|
83
|
+
`window.${CONTENT_GLOBAL} = ${JSON.stringify(Object.fromEntries(content), null, 2)};`,
|
|
84
|
+
"",
|
|
85
|
+
].join("\n");
|