@sixb/app 0.2.3 → 0.2.5
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/assets/connector-icons/README.md +1 -0
- package/assets/connector-icons/ctm.png +0 -0
- package/dist/agent/activity-label.d.ts.map +1 -1
- package/dist/agent/agent-chat.d.ts +3 -1
- package/dist/agent/agent-chat.d.ts.map +1 -1
- package/dist/agent/agent-panel.d.ts.map +1 -1
- package/dist/agent/artifact-panel.d.ts +3 -1
- package/dist/agent/artifact-panel.d.ts.map +1 -1
- package/dist/agent/background/background-tool-row.d.ts.map +1 -1
- package/dist/agent/background/interpret.d.ts +1 -1
- package/dist/agent/background/interpret.d.ts.map +1 -1
- package/dist/agent/components/composer-settings.d.ts +1 -1
- package/dist/agent/components/composer-settings.d.ts.map +1 -1
- package/dist/agent/components/composer.d.ts +22 -5
- package/dist/agent/components/composer.d.ts.map +1 -1
- package/dist/agent/components/context-meter.d.ts +1 -1
- package/dist/agent/components/context-meter.d.ts.map +1 -1
- package/dist/agent/components/conversation-panel.d.ts +8 -2
- package/dist/agent/components/conversation-panel.d.ts.map +1 -1
- package/dist/agent/components/message-parts.d.ts +2 -1
- package/dist/agent/components/message-parts.d.ts.map +1 -1
- package/dist/agent/components/message-view.d.ts.map +1 -1
- package/dist/agent/components/pending-messages.d.ts +20 -0
- package/dist/agent/components/pending-messages.d.ts.map +1 -0
- package/dist/agent/components/sandbox-recovery.d.ts +11 -2
- package/dist/agent/components/sandbox-recovery.d.ts.map +1 -1
- package/dist/agent/components/threads-button.d.ts +1 -1
- package/dist/agent/components/threads-button.d.ts.map +1 -1
- package/dist/agent/components/transcript.d.ts +5 -0
- package/dist/agent/components/transcript.d.ts.map +1 -1
- package/dist/agent/conversation.d.ts +3 -6
- package/dist/agent/conversation.d.ts.map +1 -1
- package/dist/agent/delegation/agent-exchange.d.ts +16 -0
- package/dist/agent/delegation/agent-exchange.d.ts.map +1 -0
- package/dist/agent/delegation/child-card.d.ts +3 -3
- package/dist/agent/delegation/child-card.d.ts.map +1 -1
- package/dist/agent/delegation/child-parts.d.ts +1 -10
- package/dist/agent/delegation/child-parts.d.ts.map +1 -1
- package/dist/agent/delegation/child-work.d.ts.map +1 -1
- package/dist/agent/delegation/interpret.d.ts +9 -10
- package/dist/agent/delegation/interpret.d.ts.map +1 -1
- package/dist/agent/delegation/use-children.d.ts.map +1 -1
- package/dist/agent/file-edits/file-edit-tool-view.d.ts +10 -0
- package/dist/agent/file-edits/file-edit-tool-view.d.ts.map +1 -0
- package/dist/agent/file-edits/interpret.d.ts +25 -0
- package/dist/agent/file-edits/interpret.d.ts.map +1 -0
- package/dist/agent/hooks/use-agent-conversation.d.ts +16 -4
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-stream.d.ts.map +1 -1
- package/dist/agent/i18n/en.d.ts +114 -5
- package/dist/agent/i18n/en.d.ts.map +1 -1
- package/dist/agent/i18n/fr.d.ts.map +1 -1
- package/dist/agent/i18n/index.d.ts +190 -8
- package/dist/agent/i18n/index.d.ts.map +1 -1
- package/dist/agent/inbox-handoff.d.ts +10 -0
- package/dist/agent/inbox-handoff.d.ts.map +1 -0
- package/dist/agent/live-run.d.ts +8 -1
- package/dist/agent/live-run.d.ts.map +1 -1
- package/dist/agent/message-agent/interpret.d.ts +2 -2
- package/dist/agent/message-agent/interpret.d.ts.map +1 -1
- package/dist/agent/publish-artifact/interpret.d.ts +1 -1
- package/dist/agent/publish-artifact/interpret.d.ts.map +1 -1
- package/dist/agent/questions/interpret.d.ts +31 -0
- package/dist/agent/questions/interpret.d.ts.map +1 -0
- package/dist/agent/questions/question-card.d.ts +16 -0
- package/dist/agent/questions/question-card.d.ts.map +1 -0
- package/dist/agent/questions/question-composer.d.ts +15 -0
- package/dist/agent/questions/question-composer.d.ts.map +1 -0
- package/dist/agent/read/interpret.d.ts +8 -1
- package/dist/agent/read/interpret.d.ts.map +1 -1
- package/dist/agent/read/read-tool-view.d.ts.map +1 -1
- package/dist/agent/search/interpret.d.ts +101 -0
- package/dist/agent/search/interpret.d.ts.map +1 -0
- package/dist/agent/search/search-tool-view.d.ts +10 -0
- package/dist/agent/search/search-tool-view.d.ts.map +1 -0
- package/dist/agent/thread-state.d.ts +26 -0
- package/dist/agent/thread-state.d.ts.map +1 -0
- package/dist/agent/tool-views/built-in.d.ts.map +1 -1
- package/dist/agent/tool-views/registry.d.ts +5 -6
- package/dist/agent/tool-views/registry.d.ts.map +1 -1
- package/dist/agent/types.d.ts +5 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/view-file/view-file-tool-view.d.ts +2 -1
- package/dist/agent/view-file/view-file-tool-view.d.ts.map +1 -1
- package/dist/agent/waits.d.ts +14 -0
- package/dist/agent/waits.d.ts.map +1 -0
- package/dist/artifacts/card-preview.d.ts.map +1 -1
- package/dist/artifacts/edit-session.d.ts +11 -1
- package/dist/artifacts/edit-session.d.ts.map +1 -1
- package/dist/artifacts/editor/block-handle.d.ts +20 -0
- package/dist/artifacts/editor/block-handle.d.ts.map +1 -0
- package/dist/artifacts/editor/blocks.d.ts +34 -0
- package/dist/artifacts/editor/blocks.d.ts.map +1 -0
- package/dist/artifacts/editor/callout-view.d.ts +7 -0
- package/dist/artifacts/editor/callout-view.d.ts.map +1 -0
- package/dist/artifacts/editor/document-editor.d.ts +30 -0
- package/dist/artifacts/editor/document-editor.d.ts.map +1 -0
- package/dist/artifacts/editor/figure-view.d.ts +12 -0
- package/dist/artifacts/editor/figure-view.d.ts.map +1 -0
- package/dist/artifacts/editor/find-blocks.d.ts +6 -0
- package/dist/artifacts/editor/find-blocks.d.ts.map +1 -0
- package/dist/artifacts/editor/markdown-document.d.ts +12 -0
- package/dist/artifacts/editor/markdown-document.d.ts.map +1 -0
- package/dist/artifacts/editor/messages.d.ts +4 -0
- package/dist/artifacts/editor/messages.d.ts.map +1 -0
- package/dist/artifacts/editor/schema.d.ts +21 -0
- package/dist/artifacts/editor/schema.d.ts.map +1 -0
- package/dist/artifacts/editor/selection-toolbar.d.ts +35 -0
- package/dist/artifacts/editor/selection-toolbar.d.ts.map +1 -0
- package/dist/artifacts/editor/slash-menu.d.ts +43 -0
- package/dist/artifacts/editor/slash-menu.d.ts.map +1 -0
- package/dist/artifacts/editor/upload.d.ts +12 -0
- package/dist/artifacts/editor/upload.d.ts.map +1 -0
- package/dist/artifacts/file-source.d.ts +5 -0
- package/dist/artifacts/file-source.d.ts.map +1 -1
- package/dist/artifacts/frame-editor/bundle.d.ts +7 -0
- package/dist/artifacts/frame-editor/bundle.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/commands.d.ts +93 -0
- package/dist/artifacts/frame-editor/commands.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/entry.d.ts +2 -0
- package/dist/artifacts/frame-editor/entry.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/frame.d.ts +5 -0
- package/dist/artifacts/frame-editor/frame.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/keys.d.ts +8 -0
- package/dist/artifacts/frame-editor/keys.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/protocol.d.ts +186 -0
- package/dist/artifacts/frame-editor/protocol.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/schema.d.ts +34 -0
- package/dist/artifacts/frame-editor/schema.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/style.d.ts +2 -0
- package/dist/artifacts/frame-editor/style.d.ts.map +1 -0
- package/dist/artifacts/frame.d.ts +2 -2
- package/dist/artifacts/frame.d.ts.map +1 -1
- package/dist/artifacts/live/boards.d.ts +2 -0
- package/dist/artifacts/live/boards.d.ts.map +1 -1
- package/dist/artifacts/live/document.d.ts +32 -0
- package/dist/artifacts/live/document.d.ts.map +1 -0
- package/dist/artifacts/live/header.d.ts +4 -4
- package/dist/artifacts/live/header.d.ts.map +1 -1
- package/dist/artifacts/live/presence.d.ts.map +1 -1
- package/dist/artifacts/live/session.d.ts +2 -0
- package/dist/artifacts/live/session.d.ts.map +1 -1
- package/dist/artifacts/live/view.d.ts +4 -3
- package/dist/artifacts/live/view.d.ts.map +1 -1
- package/dist/artifacts/messages.d.ts +278 -2
- package/dist/artifacts/messages.d.ts.map +1 -1
- package/dist/artifacts/pdf.d.ts +8 -0
- package/dist/artifacts/pdf.d.ts.map +1 -0
- package/dist/artifacts/queries.d.ts +80 -0
- package/dist/artifacts/queries.d.ts.map +1 -1
- package/dist/artifacts/references/references.d.ts +3 -3
- package/dist/artifacts/references/references.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/board-editor.d.ts +11 -4
- package/dist/artifacts/renderers/canvas/board-editor.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/board.d.ts +14 -2
- package/dist/artifacts/renderers/canvas/board.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/canvas.d.ts +4 -3
- package/dist/artifacts/renderers/canvas/canvas.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comment-pins.d.ts +4 -2
- package/dist/artifacts/renderers/canvas/comment-pins.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comments-panel.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comments.d.ts +2 -1
- package/dist/artifacts/renderers/canvas/comments.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/controls.d.ts +15 -4
- package/dist/artifacts/renderers/canvas/controls.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/focus.d.ts +19 -5
- package/dist/artifacts/renderers/canvas/focus.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/gestures.d.ts +46 -0
- package/dist/artifacts/renderers/canvas/gestures.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-resize.d.ts +21 -0
- package/dist/artifacts/renderers/canvas/page-resize.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-size-controls.d.ts +21 -0
- package/dist/artifacts/renderers/canvas/page-size-controls.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-size.d.ts +93 -0
- package/dist/artifacts/renderers/canvas/page-size.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-zoom.d.ts +64 -0
- package/dist/artifacts/renderers/canvas/page-zoom.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/shown-size.d.ts +26 -0
- package/dist/artifacts/renderers/canvas/shown-size.d.ts.map +1 -0
- package/dist/artifacts/renderers/designed-document.d.ts +28 -0
- package/dist/artifacts/renderers/designed-document.d.ts.map +1 -0
- package/dist/artifacts/renderers/document-tree.d.ts +2 -0
- package/dist/artifacts/renderers/document-tree.d.ts.map +1 -1
- package/dist/artifacts/renderers/document.d.ts +9 -1
- package/dist/artifacts/renderers/document.d.ts.map +1 -1
- package/dist/artifacts/renderers/live-frame.d.ts +145 -0
- package/dist/artifacts/renderers/live-frame.d.ts.map +1 -0
- package/dist/artifacts/renderers/page-editor.d.ts +16 -0
- package/dist/artifacts/renderers/page-editor.d.ts.map +1 -0
- package/dist/artifacts/renderers/page.d.ts +10 -1
- package/dist/artifacts/renderers/page.d.ts.map +1 -1
- package/dist/artifacts/viewer.d.ts.map +1 -1
- package/dist/{chunk-001c4gnk.js → chunk-4fex83k2.js} +19965 -13027
- package/dist/chunk-4fex83k2.js.map +239 -0
- package/dist/{chunk-5crvhjp2.js → chunk-4wm09prf.js} +1633 -1999
- package/dist/chunk-4wm09prf.js.map +27 -0
- package/dist/{chunk-fwb9mxwm.js → chunk-5sgac68y.js} +1 -1
- package/dist/{chunk-kes4ygmz.js → chunk-69qgh20f.js} +1 -1
- package/dist/chunk-y51c4tsz.js +11 -0
- package/dist/chunk-y51c4tsz.js.map +10 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -6
- package/dist/index.js.map +5 -5
- package/dist/pages/console/data/messages.d.ts +6 -0
- package/dist/pages/console/data/messages.d.ts.map +1 -1
- package/dist/pages/console/data/shared.d.ts.map +1 -1
- package/dist/pages.js +12 -5
- package/dist/pages.js.map +6 -6
- package/dist/shell/search-command.d.ts.map +1 -1
- package/package.json +22 -5
- package/src/agent/activity-label.ts +9 -1
- package/src/agent/agent-chat.tsx +57 -37
- package/src/agent/agent-execution-trace.tsx +2 -2
- package/src/agent/agent-panel.tsx +6 -4
- package/src/agent/agent.css +254 -0
- package/src/agent/artifact-panel.tsx +77 -22
- package/src/agent/background/background-tool-row.tsx +24 -10
- package/src/agent/background/interpret.ts +60 -51
- package/src/agent/components/composer-settings.tsx +20 -10
- package/src/agent/components/composer.tsx +342 -104
- package/src/agent/components/context-meter.tsx +7 -3
- package/src/agent/components/conversation-panel.tsx +96 -37
- package/src/agent/components/message-parts.tsx +390 -64
- package/src/agent/components/message-view.tsx +12 -2
- package/src/agent/components/pending-messages.tsx +338 -0
- package/src/agent/components/sandbox-recovery.tsx +36 -17
- package/src/agent/components/threads-button.tsx +3 -2
- package/src/agent/components/transcript.tsx +92 -45
- package/src/agent/conversation.ts +203 -54
- package/src/agent/delegation/agent-exchange.tsx +53 -0
- package/src/agent/delegation/child-card.tsx +6 -40
- package/src/agent/delegation/child-parts.tsx +1 -84
- package/src/agent/delegation/child-work.tsx +19 -5
- package/src/agent/delegation/interpret.ts +64 -61
- package/src/agent/delegation/model.ts +1 -1
- package/src/agent/file-edits/file-edit-tool-view.tsx +126 -0
- package/src/agent/file-edits/interpret.ts +120 -0
- package/src/agent/hooks/use-agent-conversation.ts +360 -92
- package/src/agent/hooks/use-thread-stream.ts +10 -0
- package/src/agent/i18n/en.ts +134 -16
- package/src/agent/i18n/fr.ts +122 -16
- package/src/agent/inbox-handoff.ts +47 -0
- package/src/agent/live-run.ts +23 -2
- package/src/agent/message-agent/interpret.ts +4 -3
- package/src/agent/publish-artifact/interpret.ts +14 -5
- package/src/agent/publish-artifact/publish-artifact-tool-view.tsx +2 -2
- package/src/agent/questions/interpret.ts +90 -0
- package/src/agent/questions/question-card.tsx +57 -0
- package/src/agent/questions/question-composer.tsx +257 -0
- package/src/agent/react-router.tsx +2 -2
- package/src/agent/read/interpret.ts +34 -1
- package/src/agent/read/read-tool-view.tsx +20 -4
- package/src/agent/search/interpret.ts +367 -0
- package/src/agent/search/search-tool-view.tsx +235 -0
- package/src/agent/thread-state.ts +114 -0
- package/src/agent/tool-views/built-in.tsx +33 -6
- package/src/agent/tool-views/registry.tsx +28 -2
- package/src/agent/types.ts +7 -0
- package/src/agent/view-file/view-file-tool-view.tsx +33 -19
- package/src/agent/waits.ts +50 -0
- package/src/artifacts/artifacts.css +434 -0
- package/src/artifacts/card-preview.tsx +6 -1
- package/src/artifacts/edit-session.tsx +15 -1
- package/src/artifacts/editor/block-handle.tsx +278 -0
- package/src/artifacts/editor/blocks.ts +216 -0
- package/src/artifacts/editor/callout-view.tsx +31 -0
- package/src/artifacts/editor/document-editor.tsx +484 -0
- package/src/artifacts/editor/figure-view.tsx +66 -0
- package/src/artifacts/editor/find-blocks.ts +19 -0
- package/src/artifacts/editor/markdown-document.tsx +72 -0
- package/src/artifacts/editor/messages.ts +4 -0
- package/src/artifacts/editor/schema.ts +159 -0
- package/src/artifacts/editor/selection-toolbar.tsx +364 -0
- package/src/artifacts/editor/slash-menu.tsx +251 -0
- package/src/artifacts/editor/upload.ts +40 -0
- package/src/artifacts/file-source.ts +11 -0
- package/src/artifacts/frame-editor/bundle.ts +8 -0
- package/src/artifacts/frame-editor/commands.ts +565 -0
- package/src/artifacts/frame-editor/entry.ts +6 -0
- package/src/artifacts/frame-editor/frame.ts +847 -0
- package/src/artifacts/frame-editor/generated/editor.txt +149 -0
- package/src/artifacts/frame-editor/generated.d.ts +5 -0
- package/src/artifacts/frame-editor/keys.ts +323 -0
- package/src/artifacts/frame-editor/protocol.ts +151 -0
- package/src/artifacts/frame-editor/schema.ts +293 -0
- package/src/artifacts/frame-editor/style.ts +58 -0
- package/src/artifacts/frame.tsx +14 -5
- package/src/artifacts/live/boards.ts +46 -3
- package/src/artifacts/live/document.ts +89 -0
- package/src/artifacts/live/header.tsx +9 -14
- package/src/artifacts/live/presence.ts +5 -1
- package/src/artifacts/live/session.ts +4 -2
- package/src/artifacts/live/view.ts +14 -8
- package/src/artifacts/messages.ts +192 -2
- package/src/artifacts/pdf.ts +50 -0
- package/src/artifacts/references/references.tsx +46 -11
- package/src/artifacts/renderers/canvas/board-editor.tsx +44 -155
- package/src/artifacts/renderers/canvas/board.tsx +70 -8
- package/src/artifacts/renderers/canvas/canvas.tsx +66 -15
- package/src/artifacts/renderers/canvas/comment-pins.tsx +5 -0
- package/src/artifacts/renderers/canvas/comments-panel.tsx +58 -1
- package/src/artifacts/renderers/canvas/comments.ts +8 -4
- package/src/artifacts/renderers/canvas/controls.tsx +64 -30
- package/src/artifacts/renderers/canvas/focus.tsx +200 -56
- package/src/artifacts/renderers/canvas/gestures.ts +265 -0
- package/src/artifacts/renderers/canvas/page-resize.tsx +542 -0
- package/src/artifacts/renderers/canvas/page-size-controls.tsx +193 -0
- package/src/artifacts/renderers/canvas/page-size.ts +218 -0
- package/src/artifacts/renderers/canvas/page-zoom.ts +280 -0
- package/src/artifacts/renderers/canvas/shown-size.ts +105 -0
- package/src/artifacts/renderers/designed-document.tsx +277 -0
- package/src/artifacts/renderers/document-tree.ts +9 -0
- package/src/artifacts/renderers/document.tsx +13 -102
- package/src/artifacts/renderers/live-frame.ts +163 -0
- package/src/artifacts/renderers/page-editor.tsx +613 -0
- package/src/artifacts/renderers/page.tsx +21 -4
- package/src/artifacts/viewer.tsx +101 -41
- package/src/index.ts +8 -0
- package/src/pages/console/data/messages.ts +6 -0
- package/src/pages/console/data/projections.tsx +4 -0
- package/src/pages/console/data/shared.tsx +1 -0
- package/src/pages/console/ontology/lineage/trail.tsx +3 -0
- package/src/shell/search-command.tsx +2 -0
- package/dist/chunk-001c4gnk.js.map +0 -204
- package/dist/chunk-5crvhjp2.js.map +0 -28
- /package/dist/{chunk-fwb9mxwm.js.map → chunk-5sgac68y.js.map} +0 -0
- /package/dist/{chunk-kes4ygmz.js.map → chunk-69qgh20f.js.map} +0 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { PAGE_MARK_TAGS, PAGE_TEXT_TAGS } from "@sixb/core/artifacts/live"
|
|
2
|
+
import { type AnyExtension, Mark, Node } from "@tiptap/core"
|
|
3
|
+
import type { Node as ProseMirrorNode } from "@tiptap/pm/model"
|
|
4
|
+
|
|
5
|
+
// A designed document's page as the editor's schema: the nodes and marks core's
|
|
6
|
+
// `artifacts/live/page.ts` reads the page's body into, with the same names and attributes, so the
|
|
7
|
+
// live document's `Y.XmlFragment` is what both read and write. Each element is drawn with its own
|
|
8
|
+
// tag and the attributes its source gave it, so the page's stylesheets style it as they style the
|
|
9
|
+
// page; what the editor does not model is drawn from its source, and takes no typing.
|
|
10
|
+
|
|
11
|
+
/** A node's attributes: none the editor gives a value the server did not, so none is rewritten. */
|
|
12
|
+
function attributes(names: readonly string[], defaults: Readonly<Record<string, string>> = {}) {
|
|
13
|
+
return Object.fromEntries(
|
|
14
|
+
names.map((name) => [name, { default: defaults[name] ?? null, rendered: false }])
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The attributes the source wrote in a start tag, read once for each tag written the same. */
|
|
19
|
+
const attributeCache = new Map<string, Record<string, string>>()
|
|
20
|
+
export function tagAttributes(open: string | null | undefined): Record<string, string> {
|
|
21
|
+
if (!open) return {}
|
|
22
|
+
const known = attributeCache.get(open)
|
|
23
|
+
if (known) return known
|
|
24
|
+
if (attributeCache.size > 2000) attributeCache.clear()
|
|
25
|
+
|
|
26
|
+
// A tag's attributes as the browser reads them, from a template, where nothing runs or loads.
|
|
27
|
+
const template = document.createElement("template")
|
|
28
|
+
const tag = /^<([a-zA-Z][\w-]*)/.exec(open)?.[1] ?? "span"
|
|
29
|
+
template.innerHTML = `${open}</${tag}>`
|
|
30
|
+
const element = template.content.firstElementChild
|
|
31
|
+
const read: Record<string, string> = {}
|
|
32
|
+
for (const attribute of Array.from(element?.attributes ?? [])) {
|
|
33
|
+
if (drawable(attribute.name, attribute.value)) read[attribute.name] = attribute.value
|
|
34
|
+
}
|
|
35
|
+
attributeCache.set(open, read)
|
|
36
|
+
return read
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Whether an attribute is drawn in the frame. The live document is anyone's who may edit it, and
|
|
41
|
+
* publishing's checks have not seen it: an event handler, or an address that runs script, would
|
|
42
|
+
* run in each reader's frame, beside the editor and its port. They are kept in the source.
|
|
43
|
+
*/
|
|
44
|
+
export function drawable(name: string, value: string): boolean {
|
|
45
|
+
if (/^on/i.test(name)) return false
|
|
46
|
+
if (/^(href|src|action|formaction|xlink:href|srcdoc|data)$/i.test(name)) {
|
|
47
|
+
// As browsers read an address: without the whitespace and control characters within it.
|
|
48
|
+
const address = value.replace(/[\u0000-\u0020\u007f]/g, "")
|
|
49
|
+
return !/^(javascript|vbscript):/i.test(address) && name.toLowerCase() !== "srcdoc"
|
|
50
|
+
}
|
|
51
|
+
return true
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Elements never drawn in the frame: they run script, load a page, or change the frame's own. */
|
|
55
|
+
const UNDRAWN =
|
|
56
|
+
/^(script|iframe|object|embed|base|meta|link|form|frame|frameset|portal|noscript|template|set|animate|animatemotion|animatetransform)$/i
|
|
57
|
+
|
|
58
|
+
/** The tag a node of the page is drawn as: its own, unless it is one never drawn. */
|
|
59
|
+
export function drawnTag(tag: unknown): string {
|
|
60
|
+
const name = String(tag ?? "")
|
|
61
|
+
return /^[a-z][a-z0-9-]*$/i.test(name) && !UNDRAWN.test(name) ? name : "div"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Removes from markup drawn in the frame whatever could run script: see `drawable`. */
|
|
65
|
+
export function sanitize(root: DocumentFragment | Element): void {
|
|
66
|
+
for (const element of Array.from(root.querySelectorAll("*"))) {
|
|
67
|
+
if (UNDRAWN.test(element.localName)) {
|
|
68
|
+
element.remove()
|
|
69
|
+
continue
|
|
70
|
+
}
|
|
71
|
+
for (const attribute of Array.from(element.attributes)) {
|
|
72
|
+
if (!drawable(attribute.name, attribute.value)) element.removeAttribute(attribute.name)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A start tag for `tag` with `attrs`, as an editor writes one. */
|
|
78
|
+
export function startTag(tag: string, attrs: Readonly<Record<string, string>> = {}): string {
|
|
79
|
+
const written = Object.entries(attrs)
|
|
80
|
+
.map(([name, value]) => ` ${name}="${value.replace(/&/g, "&").replace(/"/g, """)}"`)
|
|
81
|
+
.join("")
|
|
82
|
+
return `<${tag}${written}>`
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The tag an element's start tag names. */
|
|
86
|
+
function tagOf(element: HTMLElement): string {
|
|
87
|
+
return element.tagName.toLowerCase()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** An element's start tag as the source would write it, for what is pasted, without the editor's marks. */
|
|
91
|
+
function openOf(element: HTMLElement): string {
|
|
92
|
+
const copy = element.cloneNode(false) as HTMLElement
|
|
93
|
+
for (const name of copy.getAttributeNames()) {
|
|
94
|
+
if (
|
|
95
|
+
name === "data-pm-slice" ||
|
|
96
|
+
name.startsWith("data-sixb-raw") ||
|
|
97
|
+
name === "contenteditable"
|
|
98
|
+
) {
|
|
99
|
+
copy.removeAttribute(name)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const html = copy.outerHTML
|
|
103
|
+
return html.slice(0, html.indexOf(">") + 1)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Elements that hold blocks, read as boxes when pasted. */
|
|
107
|
+
const CONTAINER_TAGS: ReadonlySet<string> = new Set([
|
|
108
|
+
"div",
|
|
109
|
+
"section",
|
|
110
|
+
"article",
|
|
111
|
+
"aside",
|
|
112
|
+
"header",
|
|
113
|
+
"footer",
|
|
114
|
+
"main",
|
|
115
|
+
"nav",
|
|
116
|
+
"ul",
|
|
117
|
+
"ol",
|
|
118
|
+
"dl",
|
|
119
|
+
"table",
|
|
120
|
+
"thead",
|
|
121
|
+
"tbody",
|
|
122
|
+
"tfoot",
|
|
123
|
+
"tr",
|
|
124
|
+
"figure",
|
|
125
|
+
"details",
|
|
126
|
+
"fieldset",
|
|
127
|
+
"hgroup",
|
|
128
|
+
"search",
|
|
129
|
+
])
|
|
130
|
+
|
|
131
|
+
/** Whether a pasted element holds blocks: an element among its children that is not inline. */
|
|
132
|
+
function holdsBlocks(element: HTMLElement): boolean {
|
|
133
|
+
return Array.from(element.children).some((child) => {
|
|
134
|
+
const tag = child.localName
|
|
135
|
+
return CONTAINER_TAGS.has(tag) || PAGE_TEXT_TAGS.has(tag) || tag === "hr" || tag === "img"
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The page's body: its blocks. */
|
|
140
|
+
const PageDocument = Node.create({ name: "doc", topNode: true, content: "block+" })
|
|
141
|
+
|
|
142
|
+
const PageText = Node.create({ name: "text", group: "inline" })
|
|
143
|
+
|
|
144
|
+
/** An element holding blocks: a section, a list, a table and its rows. */
|
|
145
|
+
export const Box = Node.create({
|
|
146
|
+
name: "box",
|
|
147
|
+
group: "block",
|
|
148
|
+
content: "block+",
|
|
149
|
+
defining: true,
|
|
150
|
+
addAttributes: () => attributes(["tag", "open", "close", "before", "end"], { tag: "div" }),
|
|
151
|
+
parseHTML: () => [
|
|
152
|
+
{
|
|
153
|
+
// What is pasted: a container, or an element of words that holds blocks, a list item
|
|
154
|
+
// holding paragraphs. Anything else gives its content alone.
|
|
155
|
+
tag: "*",
|
|
156
|
+
priority: 10,
|
|
157
|
+
getAttrs: (element) => {
|
|
158
|
+
const tag = tagOf(element)
|
|
159
|
+
const box = CONTAINER_TAGS.has(tag) || (PAGE_TEXT_TAGS.has(tag) && holdsBlocks(element))
|
|
160
|
+
return box ? { tag, open: openOf(element) } : false
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
renderHTML: ({ node }) => [
|
|
165
|
+
drawnTag(node.attrs.tag),
|
|
166
|
+
{ ...tagAttributes(node.attrs.open as string | null) },
|
|
167
|
+
0,
|
|
168
|
+
],
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
/** An element holding words: a paragraph, a heading, a list item, a table's cell. */
|
|
172
|
+
export const TextBlock = Node.create({
|
|
173
|
+
name: "textBlock",
|
|
174
|
+
group: "block",
|
|
175
|
+
content: "inline*",
|
|
176
|
+
defining: true,
|
|
177
|
+
addAttributes: () => attributes(["tag", "open", "close", "before", "inner"], { tag: "p" }),
|
|
178
|
+
parseHTML: () => [
|
|
179
|
+
{
|
|
180
|
+
tag: [...PAGE_TEXT_TAGS].join(","),
|
|
181
|
+
getAttrs: (element) =>
|
|
182
|
+
holdsBlocks(element) ? false : { tag: tagOf(element), open: openOf(element) },
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
renderHTML: ({ node }) => [
|
|
186
|
+
drawnTag(node.attrs.tag),
|
|
187
|
+
{ ...tagAttributes(node.attrs.open as string | null) },
|
|
188
|
+
0,
|
|
189
|
+
],
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
/** A picture among blocks. */
|
|
193
|
+
export const PageImage = Node.create({
|
|
194
|
+
name: "image",
|
|
195
|
+
group: "block",
|
|
196
|
+
atom: true,
|
|
197
|
+
draggable: true,
|
|
198
|
+
selectable: true,
|
|
199
|
+
addAttributes: () => attributes(["source", "before"]),
|
|
200
|
+
parseHTML: () => [{ tag: "img[src]", getAttrs: (element) => ({ source: element.outerHTML }) }],
|
|
201
|
+
renderHTML: ({ node }) => ["img", { ...tagAttributes(node.attrs.source as string | null) }],
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
/** Anything else among blocks, kept as its source wrote it. */
|
|
205
|
+
export const RawBlock = Node.create({
|
|
206
|
+
name: "raw",
|
|
207
|
+
group: "block",
|
|
208
|
+
atom: true,
|
|
209
|
+
draggable: true,
|
|
210
|
+
selectable: true,
|
|
211
|
+
addAttributes: () => attributes(["source", "before"]),
|
|
212
|
+
parseHTML: () => [
|
|
213
|
+
// As the clipboard writes it: its source as words. Before the rules for the tags it is drawn as.
|
|
214
|
+
{
|
|
215
|
+
tag: "[data-sixb-raw]",
|
|
216
|
+
priority: 60,
|
|
217
|
+
getAttrs: (element) => ({ source: element.textContent ?? "" }),
|
|
218
|
+
},
|
|
219
|
+
// A rule pasted from elsewhere, as it was written.
|
|
220
|
+
{ tag: "hr", getAttrs: (element) => ({ source: openOf(element) }) },
|
|
221
|
+
],
|
|
222
|
+
renderHTML: ({ node }) => ["div", { "data-sixb-raw": "" }, String(node.attrs.source ?? "")],
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
/** Anything inline that is not words: a field of live data, an inline picture or icon. */
|
|
226
|
+
export const RawInline = Node.create({
|
|
227
|
+
name: "rawInline",
|
|
228
|
+
group: "inline",
|
|
229
|
+
inline: true,
|
|
230
|
+
atom: true,
|
|
231
|
+
selectable: true,
|
|
232
|
+
addAttributes: () => attributes(["source"]),
|
|
233
|
+
parseHTML: () => [
|
|
234
|
+
{
|
|
235
|
+
tag: "[data-sixb-raw-inline]",
|
|
236
|
+
priority: 60,
|
|
237
|
+
getAttrs: (element) => ({ source: element.textContent ?? "" }),
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
renderHTML: ({ node }) => [
|
|
241
|
+
"span",
|
|
242
|
+
{ "data-sixb-raw-inline": "" },
|
|
243
|
+
String(node.attrs.source ?? ""),
|
|
244
|
+
],
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
/** A line break among words. */
|
|
248
|
+
export const HardBreak = Node.create({
|
|
249
|
+
name: "hardBreak",
|
|
250
|
+
group: "inline",
|
|
251
|
+
inline: true,
|
|
252
|
+
selectable: false,
|
|
253
|
+
linebreakReplacement: true,
|
|
254
|
+
addAttributes: () => attributes(["source"]),
|
|
255
|
+
parseHTML: () => [{ tag: "br" }],
|
|
256
|
+
renderHTML: () => ["br"],
|
|
257
|
+
renderText: () => "\n",
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
/** A mark for each inline tag, drawn as that tag with its source's attributes. */
|
|
261
|
+
export const PAGE_MARKS = PAGE_MARK_TAGS.map((tag) =>
|
|
262
|
+
Mark.create({
|
|
263
|
+
name: tag,
|
|
264
|
+
// A link does not grow as the reader types after it.
|
|
265
|
+
inclusive: tag !== "a",
|
|
266
|
+
addAttributes: () => attributes(["open", "close"]),
|
|
267
|
+
parseHTML: () => [
|
|
268
|
+
{ tag, getAttrs: (element) => ({ open: openOf(element), close: `</${tag}>` }) },
|
|
269
|
+
],
|
|
270
|
+
renderHTML: ({ mark }) => [tag, { ...tagAttributes(mark.attrs.open as string | null) }, 0],
|
|
271
|
+
})
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
/** The page's schema: what core's page reads its body into. */
|
|
275
|
+
export function pageSchemaExtensions(): AnyExtension[] {
|
|
276
|
+
// A block of words first: what ProseMirror makes where a block is missing.
|
|
277
|
+
return [
|
|
278
|
+
PageDocument,
|
|
279
|
+
PageText,
|
|
280
|
+
TextBlock,
|
|
281
|
+
Box,
|
|
282
|
+
PageImage,
|
|
283
|
+
RawBlock,
|
|
284
|
+
RawInline,
|
|
285
|
+
HardBreak,
|
|
286
|
+
...PAGE_MARKS,
|
|
287
|
+
]
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Whether a node is a block of words that takes typing. */
|
|
291
|
+
export function isWords(node: ProseMirrorNode | null | undefined): boolean {
|
|
292
|
+
return node?.type.name === "textBlock"
|
|
293
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// What the editor adds to a page's own styles while it is edited: as little as typing needs, and
|
|
2
|
+
// nothing the page's stylesheets do not override, so the page looks as it reads.
|
|
3
|
+
|
|
4
|
+
export const PAGE_EDITOR_CSS = `
|
|
5
|
+
body.ProseMirror { outline: none; white-space: pre-wrap; word-wrap: break-word; }
|
|
6
|
+
body.ProseMirror :where([data-sixb-raw]) { white-space: normal; cursor: default; }
|
|
7
|
+
body.ProseMirror .ProseMirror-selectednode { outline: 2px solid #0a84ff; outline-offset: 2px; border-radius: 2px; }
|
|
8
|
+
body.ProseMirror ::selection { background: rgba(10, 132, 255, 0.22); }
|
|
9
|
+
body.ProseMirror .ProseMirror-selectednode::selection,
|
|
10
|
+
body.ProseMirror .ProseMirror-selectednode ::selection { background: transparent; }
|
|
11
|
+
body.ProseMirror :where([data-sixb-field]) {
|
|
12
|
+
border-radius: 3px;
|
|
13
|
+
background: rgba(10, 132, 255, 0.08);
|
|
14
|
+
box-shadow: 0 0 0 1px rgba(10, 132, 255, 0.28);
|
|
15
|
+
}
|
|
16
|
+
body.ProseMirror .is-empty[data-placeholder]::before {
|
|
17
|
+
content: attr(data-placeholder);
|
|
18
|
+
float: left;
|
|
19
|
+
height: 0;
|
|
20
|
+
color: currentColor;
|
|
21
|
+
opacity: 0.38;
|
|
22
|
+
pointer-events: none;
|
|
23
|
+
}
|
|
24
|
+
body.ProseMirror .sixb-page-break { position: relative; user-select: none; }
|
|
25
|
+
body.ProseMirror .sixb-page-break::after {
|
|
26
|
+
content: attr(data-label);
|
|
27
|
+
position: absolute;
|
|
28
|
+
inset: 0;
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
justify-content: center;
|
|
32
|
+
color: #71717a;
|
|
33
|
+
font: 500 10px/1 system-ui, -apple-system, sans-serif;
|
|
34
|
+
letter-spacing: 0.06em;
|
|
35
|
+
text-transform: uppercase;
|
|
36
|
+
}
|
|
37
|
+
.sixb-caret {
|
|
38
|
+
position: relative;
|
|
39
|
+
margin-inline: -1px;
|
|
40
|
+
border-left: 2px solid var(--caret);
|
|
41
|
+
word-break: normal;
|
|
42
|
+
pointer-events: none;
|
|
43
|
+
}
|
|
44
|
+
.sixb-caret-label {
|
|
45
|
+
position: absolute;
|
|
46
|
+
bottom: 100%;
|
|
47
|
+
left: -2px;
|
|
48
|
+
padding: 1px 6px;
|
|
49
|
+
border-radius: 6px 6px 6px 0;
|
|
50
|
+
background: var(--caret);
|
|
51
|
+
color: #fff;
|
|
52
|
+
font: 600 11px/1.5 system-ui, -apple-system, sans-serif;
|
|
53
|
+
font-style: normal;
|
|
54
|
+
white-space: nowrap;
|
|
55
|
+
user-select: none;
|
|
56
|
+
}
|
|
57
|
+
.sixb-caret-selection { background: color-mix(in oklab, var(--caret) 22%, transparent); }
|
|
58
|
+
`
|
package/src/artifacts/frame.tsx
CHANGED
|
@@ -55,8 +55,8 @@ const LOADED_READY_MS = 2_000
|
|
|
55
55
|
* events of the protocol's shape. The app's theme goes in as tokens, read where the frame is
|
|
56
56
|
* mounted, so an artifact's theme applies too.
|
|
57
57
|
*
|
|
58
|
-
* The frame stays hidden until its theme is applied, then
|
|
59
|
-
*
|
|
58
|
+
* The frame stays hidden until its theme is applied, then replaces `fallback`: until the tokens
|
|
59
|
+
* arrive, a deck paints in the kit's light defaults, which flash on a dark page.
|
|
60
60
|
*
|
|
61
61
|
* A page in it keeps data with `sixb.state`, and reads its version's queries with `sixb.query`: the
|
|
62
62
|
* frame's calls are answered here, for the artifact and the version it shows and the signed-in
|
|
@@ -308,11 +308,12 @@ export function ArtifactFrame({
|
|
|
308
308
|
}, [artifactTheme, isReady, sendTheme])
|
|
309
309
|
|
|
310
310
|
// A picture of the deck takes no focus, and neither does what it holds: `tabIndex` alone would
|
|
311
|
-
// leave its links in the page's tab order.
|
|
311
|
+
// leave its links in the page's tab order. A canvas's board becomes one, and stops being one,
|
|
312
|
+
// without loading again.
|
|
312
313
|
const attach = useCallback(
|
|
313
314
|
(element: HTMLIFrameElement | null) => {
|
|
314
315
|
iframe.current = element
|
|
315
|
-
if (element
|
|
316
|
+
if (element) element.inert = decorative
|
|
316
317
|
},
|
|
317
318
|
[decorative]
|
|
318
319
|
)
|
|
@@ -329,9 +330,17 @@ export function ArtifactFrame({
|
|
|
329
330
|
const failed =
|
|
330
331
|
reportsFailure && (source === undefined ? frame.isError : timedOut === source && !isReady)
|
|
331
332
|
|
|
333
|
+
// The frame is transparent: once it shows, nothing stays beneath it to show through where its
|
|
334
|
+
// page bounces past an end.
|
|
335
|
+
const beneath = failed ? (
|
|
336
|
+
<div className="absolute inset-0 flex">{failure}</div>
|
|
337
|
+
) : shown === source ? null : (
|
|
338
|
+
fallback
|
|
339
|
+
)
|
|
340
|
+
|
|
332
341
|
return (
|
|
333
342
|
<div className={cn("relative min-h-0 min-w-0", className)}>
|
|
334
|
-
{
|
|
343
|
+
{beneath}
|
|
335
344
|
{source ? (
|
|
336
345
|
<iframe
|
|
337
346
|
ref={attach}
|
|
@@ -1,16 +1,33 @@
|
|
|
1
|
-
import { LIVE_FILES } from "@sixb/core/artifacts/live"
|
|
1
|
+
import { isPageEntry, LIVE_FILES, pageEntryHtml } from "@sixb/core/artifacts/live"
|
|
2
2
|
import type { FileRef } from "@sixb/core/blob-storage"
|
|
3
3
|
import { useCallback, useMemo, useSyncExternalStore } from "react"
|
|
4
4
|
import * as Y from "yjs"
|
|
5
5
|
import type { LiveArtifact } from "./session"
|
|
6
6
|
|
|
7
7
|
// A board's page as the live document holds it, read as it changes: someone typing in it, the
|
|
8
|
-
// Agent writing it, or the whole file replaced.
|
|
8
|
+
// Agent writing it, or the whole file replaced. A designed document's page is held as its blocks
|
|
9
|
+
// (`pageEntry`), read as the source they write.
|
|
10
|
+
|
|
11
|
+
/** A page's source as its blocks write it, written again only once they change. */
|
|
12
|
+
const pageSources = new WeakMap<Y.Map<unknown>, string>()
|
|
13
|
+
const observed = new WeakSet<Y.Map<unknown>>()
|
|
14
|
+
function pageSource(entry: Y.Map<unknown>): string {
|
|
15
|
+
const known = pageSources.get(entry)
|
|
16
|
+
if (known !== undefined) return known
|
|
17
|
+
if (!observed.has(entry)) {
|
|
18
|
+
observed.add(entry)
|
|
19
|
+
entry.observeDeep(() => pageSources.delete(entry))
|
|
20
|
+
}
|
|
21
|
+
const source = pageEntryHtml(entry)
|
|
22
|
+
pageSources.set(entry, source)
|
|
23
|
+
return source
|
|
24
|
+
}
|
|
9
25
|
|
|
10
26
|
/** A board's page in the document now; null when the document holds none at that path as text. */
|
|
11
27
|
export function liveBoardSource(doc: Y.Doc, path: string): string | null {
|
|
12
28
|
const entry = doc.getMap<unknown>(LIVE_FILES).get(path)
|
|
13
|
-
|
|
29
|
+
if (entry instanceof Y.Text) return entry.toString()
|
|
30
|
+
return isPageEntry(entry) ? pageSource(entry) : null
|
|
14
31
|
}
|
|
15
32
|
|
|
16
33
|
/** The files the document holds as stored bytes, by path: the pictures a board may show. */
|
|
@@ -42,11 +59,15 @@ export function useLiveBoardSource(live: LiveArtifact | null, path: string): str
|
|
|
42
59
|
|
|
43
60
|
const files = live.doc.getMap<unknown>(LIVE_FILES)
|
|
44
61
|
let text: Y.Text | null = null
|
|
62
|
+
let page: Y.Map<unknown> | null = null
|
|
45
63
|
const follow = () => {
|
|
46
64
|
text?.unobserve(listener)
|
|
65
|
+
page?.unobserveDeep(listener)
|
|
47
66
|
const entry = files.get(path)
|
|
48
67
|
text = entry instanceof Y.Text ? entry : null
|
|
68
|
+
page = isPageEntry(entry) ? entry : null
|
|
49
69
|
text?.observe(listener)
|
|
70
|
+
page?.observeDeep(listener)
|
|
50
71
|
}
|
|
51
72
|
const onFiles = (event: Y.YMapEvent<unknown>) => {
|
|
52
73
|
if (!event.keysChanged.has(path)) return
|
|
@@ -59,6 +80,7 @@ export function useLiveBoardSource(live: LiveArtifact | null, path: string): str
|
|
|
59
80
|
return () => {
|
|
60
81
|
files.unobserve(onFiles)
|
|
61
82
|
text?.unobserve(listener)
|
|
83
|
+
page?.unobserveDeep(listener)
|
|
62
84
|
}
|
|
63
85
|
},
|
|
64
86
|
[live, path]
|
|
@@ -71,6 +93,27 @@ export function useLiveBoardSource(live: LiveArtifact | null, path: string): str
|
|
|
71
93
|
)
|
|
72
94
|
}
|
|
73
95
|
|
|
96
|
+
/** Whether a live artifact's document holds the page at `path` as blocks an editor edits. */
|
|
97
|
+
export function useLivePageHeld(live: LiveArtifact | null, path: string): boolean {
|
|
98
|
+
const subscribe = useCallback(
|
|
99
|
+
(listener: () => void) => {
|
|
100
|
+
if (!live) return () => {}
|
|
101
|
+
const files = live.doc.getMap<unknown>(LIVE_FILES)
|
|
102
|
+
const onFiles = (event: Y.YMapEvent<unknown>) => {
|
|
103
|
+
if (event.keysChanged.has(path)) listener()
|
|
104
|
+
}
|
|
105
|
+
files.observe(onFiles)
|
|
106
|
+
return () => files.unobserve(onFiles)
|
|
107
|
+
},
|
|
108
|
+
[live, path]
|
|
109
|
+
)
|
|
110
|
+
return useSyncExternalStore(
|
|
111
|
+
subscribe,
|
|
112
|
+
() => (live ? isPageEntry(live.doc.getMap<unknown>(LIVE_FILES).get(path)) : false),
|
|
113
|
+
() => false
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
74
117
|
/** Follows the files a live artifact's document holds as stored bytes, as they are added. */
|
|
75
118
|
export function useLiveStoredFiles(live: LiveArtifact | null): ReadonlyMap<string, FileRef> {
|
|
76
119
|
const subscribe = useCallback(
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { applyBoardEditToText, type BoardEdit, LIVE_FILES } from "@sixb/core/artifacts/live"
|
|
2
|
+
import * as Y from "yjs"
|
|
3
|
+
import type { LiveArtifact } from "./session"
|
|
4
|
+
|
|
5
|
+
// A designed document as its live document holds it: `document.html` as a `Y.Text`, which the
|
|
6
|
+
// reader types into element by element. Each change is made under this document's own origin,
|
|
7
|
+
// so undo takes back the reader's own words and never anyone else's.
|
|
8
|
+
|
|
9
|
+
/** How long changes made one after the other are one step for undo, as typing a word is. */
|
|
10
|
+
const UNDO_CAPTURE_MS = 400
|
|
11
|
+
|
|
12
|
+
const NO_HISTORY = { undo: false, redo: false }
|
|
13
|
+
|
|
14
|
+
export class LiveDocument {
|
|
15
|
+
private readonly undoManager: Y.UndoManager
|
|
16
|
+
private readonly listeners = new Set<() => void>()
|
|
17
|
+
private history: { readonly undo: boolean; readonly redo: boolean } = NO_HISTORY
|
|
18
|
+
/** The origin of this reader's own changes: the only ones its undo takes back. */
|
|
19
|
+
readonly origin = Symbol("sixb-live-document")
|
|
20
|
+
|
|
21
|
+
constructor(private readonly doc: Y.Doc) {
|
|
22
|
+
this.undoManager = new Y.UndoManager(doc.getMap<unknown>(LIVE_FILES), {
|
|
23
|
+
trackedOrigins: new Set([this.origin]),
|
|
24
|
+
captureTimeout: UNDO_CAPTURE_MS,
|
|
25
|
+
})
|
|
26
|
+
this.undoManager.on("stack-item-added", this.onHistory)
|
|
27
|
+
this.undoManager.on("stack-item-popped", this.onHistory)
|
|
28
|
+
this.undoManager.on("stack-cleared", this.onHistory)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getHistory = (): { readonly undo: boolean; readonly redo: boolean } => this.history
|
|
32
|
+
|
|
33
|
+
subscribe = (listener: () => void): (() => void) => {
|
|
34
|
+
this.listeners.add(listener)
|
|
35
|
+
return () => this.listeners.delete(listener)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Makes an edit to a file, worked out from what it holds now, as one step of this reader's
|
|
40
|
+
* undo. False when the document holds no such text; `make` throws when the edit no longer
|
|
41
|
+
* applies.
|
|
42
|
+
*/
|
|
43
|
+
editFile(path: string, make: (source: string) => BoardEdit): boolean {
|
|
44
|
+
const text = this.doc.getMap<unknown>(LIVE_FILES).get(path)
|
|
45
|
+
if (!(text instanceof Y.Text)) return false
|
|
46
|
+
applyBoardEditToText(text, make(text.toString()), this.origin)
|
|
47
|
+
return true
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
undo(): void {
|
|
51
|
+
this.undoManager.undo()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
redo(): void {
|
|
55
|
+
this.undoManager.redo()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Ends the undo step being made: typing in another element is a step of its own. */
|
|
59
|
+
stopCapturing(): void {
|
|
60
|
+
this.undoManager.stopCapturing()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
destroy(): void {
|
|
64
|
+
this.undoManager.destroy()
|
|
65
|
+
this.listeners.clear()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private onHistory = (): void => {
|
|
69
|
+
const next = {
|
|
70
|
+
undo: this.undoManager.undoStack.length > 0,
|
|
71
|
+
redo: this.undoManager.redoStack.length > 0,
|
|
72
|
+
}
|
|
73
|
+
if (next.undo === this.history.undo && next.redo === this.history.redo) return
|
|
74
|
+
this.history = next
|
|
75
|
+
for (const listener of this.listeners) listener()
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const documents = new WeakMap<LiveArtifact, LiveDocument>()
|
|
80
|
+
|
|
81
|
+
/** The document of a live artifact, one per artifact, so the frame and the header share its undo. */
|
|
82
|
+
export function liveDocumentOf(artifact: LiveArtifact): LiveDocument {
|
|
83
|
+
let document = documents.get(artifact)
|
|
84
|
+
if (!document) {
|
|
85
|
+
document = new LiveDocument(artifact.doc)
|
|
86
|
+
documents.set(artifact, document)
|
|
87
|
+
}
|
|
88
|
+
return document
|
|
89
|
+
}
|
|
@@ -62,15 +62,15 @@ export function LiveAvatars({ live }: { readonly live: LiveArtifact }) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/** What the header says of an edit's write-back, as a document editor does. */
|
|
65
|
-
export type LiveSaveLabel = "saved" | "saving" | "failed" | "offline"
|
|
65
|
+
export type LiveSaveLabel = "saved" | "saving" | "failed" | "refused" | "offline"
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
* Where what the reader changed is: saved, being saved, kept here while the socket is down,
|
|
69
|
-
* failed and tried again by the server.
|
|
68
|
+
* Where what the reader changed is: saved, being saved, kept here while the socket is down,
|
|
69
|
+
* failed and tried again by the server, or refused until someone changes it.
|
|
70
70
|
*/
|
|
71
71
|
export function liveSaveLabel(state: LiveArtifactState): LiveSaveLabel {
|
|
72
72
|
if (state.connection !== "online") return "offline"
|
|
73
|
-
if (state.save?.state === "failed") return "failed"
|
|
73
|
+
if (state.save?.state === "failed") return state.save.refused ? "refused" : "failed"
|
|
74
74
|
if (state.pending || state.save?.state === "unsaved" || state.save?.state === "saving") {
|
|
75
75
|
return "saving"
|
|
76
76
|
}
|
|
@@ -79,28 +79,23 @@ export function liveSaveLabel(state: LiveArtifactState): LiveSaveLabel {
|
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* The save state, discreet beside the title: its words fold into the icon on a narrow header.
|
|
82
|
-
* Only a failure is announced; offline with nothing kept, it says it is reconnecting.
|
|
82
|
+
* Only a failure or a refusal is announced; offline with nothing kept, it says it is reconnecting.
|
|
83
83
|
*/
|
|
84
84
|
export function LiveSaveStatus({ state }: { readonly state: LiveArtifactState }) {
|
|
85
85
|
const messages = useArtifactMessages().live
|
|
86
86
|
const label = liveSaveLabel(state)
|
|
87
87
|
const text = label === "offline" && !state.pending ? messages.reconnecting : messages[label]
|
|
88
|
+
const warns = label === "failed" || label === "refused"
|
|
88
89
|
const Icon =
|
|
89
|
-
label === "saved"
|
|
90
|
-
? Check
|
|
91
|
-
: label === "saving"
|
|
92
|
-
? LoaderCircle
|
|
93
|
-
: label === "failed"
|
|
94
|
-
? TriangleAlert
|
|
95
|
-
: CloudOff
|
|
90
|
+
label === "saved" ? Check : label === "saving" ? LoaderCircle : warns ? TriangleAlert : CloudOff
|
|
96
91
|
return (
|
|
97
92
|
<span
|
|
98
|
-
role={
|
|
93
|
+
role={warns ? "status" : undefined}
|
|
99
94
|
title={text}
|
|
100
95
|
data-save={label}
|
|
101
96
|
className={cn(
|
|
102
97
|
"flex h-5 shrink-0 items-center gap-1 text-xs whitespace-nowrap transition-colors",
|
|
103
|
-
|
|
98
|
+
warns ? "text-warning" : "text-muted-foreground"
|
|
104
99
|
)}
|
|
105
100
|
>
|
|
106
101
|
<Icon
|
|
@@ -44,8 +44,12 @@ function presenceOf(artifact: LiveArtifact) {
|
|
|
44
44
|
if (entry) return entry
|
|
45
45
|
|
|
46
46
|
const created = { value: readPresence(artifact), listeners: new Set<() => void>() }
|
|
47
|
+
// Awareness changes with every caret that moves, this reader's own included: only a change to
|
|
48
|
+
// who is here, or to what they selected, is told to the readers of it.
|
|
47
49
|
artifact.awareness.on("change", () => {
|
|
48
|
-
|
|
50
|
+
const next = readPresence(artifact)
|
|
51
|
+
if (JSON.stringify(next) === JSON.stringify(created.value)) return
|
|
52
|
+
created.value = next
|
|
49
53
|
for (const listener of created.listeners) listener()
|
|
50
54
|
})
|
|
51
55
|
entry = created
|
|
@@ -39,6 +39,8 @@ export interface LiveSave {
|
|
|
39
39
|
readonly state: ArtifactLiveSaveState
|
|
40
40
|
readonly revision: number
|
|
41
41
|
readonly error?: string
|
|
42
|
+
/** Publishing refused what the document holds: it is not tried again until it changes. */
|
|
43
|
+
readonly refused?: true
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export interface LiveArtifactState {
|
|
@@ -270,11 +272,11 @@ export class LiveArtifact {
|
|
|
270
272
|
return
|
|
271
273
|
}
|
|
272
274
|
case "status": {
|
|
273
|
-
const { state, revision, error } = message
|
|
275
|
+
const { state, revision, error, refused } = message
|
|
274
276
|
const written = message.snapshot ? readSnapshot(message.snapshot) : null
|
|
275
277
|
if (written) this.forget(written)
|
|
276
278
|
this.update({
|
|
277
|
-
save: { state, revision, ...(error ? { error } : {}) },
|
|
279
|
+
save: { state, revision, ...(error ? { error } : {}), ...(refused ? { refused } : {}) },
|
|
278
280
|
pending: state !== "saved",
|
|
279
281
|
})
|
|
280
282
|
return
|