@sixb/app 0.2.4 → 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/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 +5 -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.map +1 -1
- package/dist/agent/conversation.d.ts +3 -6
- package/dist/agent/conversation.d.ts.map +1 -1
- package/dist/agent/delegation/interpret.d.ts +5 -0
- package/dist/agent/delegation/interpret.d.ts.map +1 -1
- package/dist/agent/delegation/use-children.d.ts.map +1 -1
- package/dist/agent/hooks/use-agent-conversation.d.ts +10 -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 +68 -0
- 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 +114 -0
- 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/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/artifacts/card-preview.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 +226 -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.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/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-kymx9y5e.js → chunk-4fex83k2.js} +10874 -4690
- package/dist/chunk-4fex83k2.js.map +239 -0
- package/dist/{chunk-yrcm1pbg.js → chunk-4wm09prf.js} +491 -2128
- package/dist/chunk-4wm09prf.js.map +27 -0
- package/dist/{chunk-pxd07kvx.js → chunk-5sgac68y.js} +1 -1
- package/dist/{chunk-970s5nkn.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 +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -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 +3 -0
- package/src/agent/agent-chat.tsx +56 -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/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 +69 -29
- package/src/agent/components/message-parts.tsx +367 -59
- 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 +63 -34
- package/src/agent/conversation.ts +203 -54
- package/src/agent/delegation/interpret.ts +31 -7
- package/src/agent/hooks/use-agent-conversation.ts +348 -100
- package/src/agent/hooks/use-thread-stream.ts +10 -0
- package/src/agent/i18n/en.ts +87 -11
- package/src/agent/i18n/fr.ts +83 -12
- package/src/agent/inbox-handoff.ts +47 -0
- package/src/agent/live-run.ts +23 -2
- package/src/agent/react-router.tsx +2 -2
- 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 +16 -0
- 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/artifacts/artifacts.css +398 -0
- package/src/artifacts/card-preview.tsx +6 -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 +11 -3
- 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 +138 -2
- package/src/artifacts/pdf.ts +50 -0
- package/src/artifacts/references/references.tsx +46 -11
- package/src/artifacts/renderers/canvas/board-editor.tsx +11 -144
- 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/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 +87 -41
- package/src/index.ts +6 -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-kymx9y5e.js.map +0 -211
- package/dist/chunk-yrcm1pbg.js.map +0 -34
- /package/dist/{chunk-pxd07kvx.js.map → chunk-5sgac68y.js.map} +0 -0
- /package/dist/{chunk-970s5nkn.js.map → chunk-69qgh20f.js.map} +0 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { type Editor, Extension } from "@tiptap/core"
|
|
2
|
+
import type { Node as ProseMirrorNode } from "@tiptap/pm/model"
|
|
3
|
+
import { NodeSelection, Selection, TextSelection } from "@tiptap/pm/state"
|
|
4
|
+
import {
|
|
5
|
+
duplicate,
|
|
6
|
+
LIST_TAGS,
|
|
7
|
+
liftOut,
|
|
8
|
+
move,
|
|
9
|
+
SINGLE_BLOCK_TAGS,
|
|
10
|
+
tagOf,
|
|
11
|
+
withoutId,
|
|
12
|
+
words,
|
|
13
|
+
wordsAt,
|
|
14
|
+
} from "./commands"
|
|
15
|
+
import type { PageMark } from "./protocol"
|
|
16
|
+
|
|
17
|
+
// The keys of a page, Notion's where a page allows them. Enter starts a new paragraph, or a new
|
|
18
|
+
// item in a list; Backspace at the start of a heading makes it a paragraph, and of a list's first
|
|
19
|
+
// item takes it out of the list. What would merge two boxes of the design, a section into the one
|
|
20
|
+
// before it or a cell into its neighbour, does nothing: the design's structure is changed by the
|
|
21
|
+
// block handle, never by a stray key.
|
|
22
|
+
|
|
23
|
+
/** After a block of these, Enter makes a paragraph; after any other, a block like it. */
|
|
24
|
+
const ENDS_IN_PARAGRAPH: ReadonlySet<string> = new Set([
|
|
25
|
+
"h1",
|
|
26
|
+
"h2",
|
|
27
|
+
"h3",
|
|
28
|
+
"h4",
|
|
29
|
+
"h5",
|
|
30
|
+
"h6",
|
|
31
|
+
"blockquote",
|
|
32
|
+
"address",
|
|
33
|
+
])
|
|
34
|
+
|
|
35
|
+
export interface PageKeysOptions {
|
|
36
|
+
readonly toggleMark: (editor: Editor, mark: PageMark) => void
|
|
37
|
+
readonly onLink: () => void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const PageKeys = Extension.create<PageKeysOptions>({
|
|
41
|
+
name: "pageKeys",
|
|
42
|
+
addOptions: () => ({ toggleMark: () => {}, onLink: () => {} }),
|
|
43
|
+
addKeyboardShortcuts() {
|
|
44
|
+
const editor = this.editor
|
|
45
|
+
const mark = (name: PageMark) => () => {
|
|
46
|
+
this.options.toggleMark(editor, name)
|
|
47
|
+
return true
|
|
48
|
+
}
|
|
49
|
+
const current = () => {
|
|
50
|
+
const at = wordsAt(editor.state.selection)
|
|
51
|
+
if (at) return at
|
|
52
|
+
const { selection } = editor.state
|
|
53
|
+
return selection instanceof NodeSelection
|
|
54
|
+
? { node: selection.node, pos: selection.from }
|
|
55
|
+
: null
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
Enter: () => enter(editor),
|
|
59
|
+
"Shift-Enter": () => lineBreak(editor),
|
|
60
|
+
Backspace: () => backspace(editor),
|
|
61
|
+
Delete: () => forwardDelete(editor),
|
|
62
|
+
// The body is the editor, so the browser would scroll the whole page to its end as well.
|
|
63
|
+
Home: () => toLineEdge(editor, "backward", false),
|
|
64
|
+
End: () => toLineEdge(editor, "forward", false),
|
|
65
|
+
"Shift-Home": () => toLineEdge(editor, "backward", true),
|
|
66
|
+
"Shift-End": () => toLineEdge(editor, "forward", true),
|
|
67
|
+
Tab: () => nextCell(editor, 1),
|
|
68
|
+
"Shift-Tab": () => nextCell(editor, -1),
|
|
69
|
+
"Mod-b": mark("bold"),
|
|
70
|
+
"Mod-i": mark("italic"),
|
|
71
|
+
"Mod-u": mark("underline"),
|
|
72
|
+
"Mod-Shift-s": mark("strike"),
|
|
73
|
+
"Mod-e": mark("code"),
|
|
74
|
+
"Mod-k": () => {
|
|
75
|
+
if (editor.state.selection.empty) return false
|
|
76
|
+
this.options.onLink()
|
|
77
|
+
return true
|
|
78
|
+
},
|
|
79
|
+
"Mod-d": () => {
|
|
80
|
+
const at = current()
|
|
81
|
+
return at ? duplicate(editor, at.pos) : false
|
|
82
|
+
},
|
|
83
|
+
"Alt-Shift-ArrowUp": () => {
|
|
84
|
+
const at = current()
|
|
85
|
+
if (at) move(editor, at.pos, -1)
|
|
86
|
+
return true
|
|
87
|
+
},
|
|
88
|
+
"Alt-Shift-ArrowDown": () => {
|
|
89
|
+
const at = current()
|
|
90
|
+
if (at) move(editor, at.pos, 1)
|
|
91
|
+
return true
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
/** Moves the caret, or extends the selection, to the start or end of the line it is on. */
|
|
98
|
+
function toLineEdge(editor: Editor, direction: "forward" | "backward", extend: boolean): boolean {
|
|
99
|
+
const selection = editor.view.dom.ownerDocument.getSelection()
|
|
100
|
+
if (!selection || typeof selection.modify !== "function") return false
|
|
101
|
+
selection.modify(extend ? "extend" : "move", direction, "lineboundary")
|
|
102
|
+
return true
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function lineBreak(editor: Editor): boolean {
|
|
106
|
+
const at = wordsAt(editor.state.selection)
|
|
107
|
+
if (!at) return false
|
|
108
|
+
if (tagOf(at.node) === "pre") return editor.commands.insertContent("\n")
|
|
109
|
+
return editor.commands.insertContent({ type: "hardBreak" })
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Enter: a new block after the one the caret is in, which takes the words after the caret. In
|
|
114
|
+
* `<pre>`, a new line; in a cell or a caption, a line break. An empty list item ends its list.
|
|
115
|
+
*/
|
|
116
|
+
function enter(editor: Editor): boolean {
|
|
117
|
+
if (!(editor.state.selection instanceof TextSelection)) return false
|
|
118
|
+
const first = wordsAt(editor.state.selection)
|
|
119
|
+
if (!first) return false
|
|
120
|
+
const tag = tagOf(first.node)
|
|
121
|
+
if (tag === "pre") return editor.commands.insertContent("\n")
|
|
122
|
+
if (SINGLE_BLOCK_TAGS.has(tag)) return lineBreak(editor)
|
|
123
|
+
|
|
124
|
+
const tr = editor.state.tr
|
|
125
|
+
if (!tr.selection.empty) tr.deleteSelection()
|
|
126
|
+
const at = wordsAt(tr.selection)
|
|
127
|
+
if (!at) return false
|
|
128
|
+
const { node, pos } = at
|
|
129
|
+
const $pos = tr.doc.resolve(pos)
|
|
130
|
+
const inList = tag === "li" && LIST_TAGS.has(tagOf($pos.parent))
|
|
131
|
+
|
|
132
|
+
if (node.content.size === 0) {
|
|
133
|
+
// An empty item ends its list, and an empty description its list of terms.
|
|
134
|
+
if (inList || ((tag === "dd" || tag === "dt") && tagOf($pos.parent) === "dl")) {
|
|
135
|
+
liftOut(tr, pos, words(editor.schema, "p"))
|
|
136
|
+
editor.view.dispatch(tr.scrollIntoView())
|
|
137
|
+
return true
|
|
138
|
+
}
|
|
139
|
+
// The last, empty, paragraph of an item that holds paragraphs: the next item, or, alone in
|
|
140
|
+
// its item, the end of the list.
|
|
141
|
+
const item = $pos.parent
|
|
142
|
+
const itemPos = $pos.depth > 0 ? $pos.before() : -1
|
|
143
|
+
const listOfItem = itemPos >= 0 ? tr.doc.resolve(itemPos).parent : null
|
|
144
|
+
if (
|
|
145
|
+
tagOf(item) === "li" &&
|
|
146
|
+
LIST_TAGS.has(tagOf(listOfItem)) &&
|
|
147
|
+
$pos.index() === item.childCount - 1
|
|
148
|
+
) {
|
|
149
|
+
if (item.childCount === 1) {
|
|
150
|
+
liftOut(tr, itemPos, words(editor.schema, "p"))
|
|
151
|
+
} else {
|
|
152
|
+
tr.delete(pos, pos + node.nodeSize)
|
|
153
|
+
const after = tr.mapping.map(itemPos + item.nodeSize)
|
|
154
|
+
const open = typeof item.attrs.open === "string" ? withoutId(item.attrs.open, "li") : "<li>"
|
|
155
|
+
tr.insert(
|
|
156
|
+
after,
|
|
157
|
+
item.type.create({ ...item.attrs, open, before: null, end: null }, [
|
|
158
|
+
words(editor.schema, "p"),
|
|
159
|
+
])
|
|
160
|
+
)
|
|
161
|
+
tr.setSelection(TextSelection.create(tr.doc, after + 2))
|
|
162
|
+
}
|
|
163
|
+
editor.view.dispatch(tr.scrollIntoView())
|
|
164
|
+
return true
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const offset = tr.selection.$from.parentOffset
|
|
169
|
+
const open = typeof node.attrs.open === "string" ? withoutId(node.attrs.open, tag) : `<${tag}>`
|
|
170
|
+
|
|
171
|
+
// Within the last paragraph of an item that holds paragraphs, past its start: the next item
|
|
172
|
+
// takes the words after the caret, as in a list of words alone.
|
|
173
|
+
const item = $pos.depth > 0 ? $pos.parent : null
|
|
174
|
+
if (
|
|
175
|
+
item &&
|
|
176
|
+
offset > 0 &&
|
|
177
|
+
tagOf(item) === "li" &&
|
|
178
|
+
LIST_TAGS.has(tagOf(tr.doc.resolve($pos.before()).parent)) &&
|
|
179
|
+
$pos.index() === item.childCount - 1
|
|
180
|
+
) {
|
|
181
|
+
const itemOpen = typeof item.attrs.open === "string" ? withoutId(item.attrs.open, "li") : "<li>"
|
|
182
|
+
tr.split(tr.selection.from, 2, [
|
|
183
|
+
{ type: item.type, attrs: { ...item.attrs, open: itemOpen, before: null, end: null } },
|
|
184
|
+
{ type: node.type, attrs: { ...node.attrs, open, before: null, inner: null } },
|
|
185
|
+
])
|
|
186
|
+
editor.view.dispatch(tr.scrollIntoView())
|
|
187
|
+
return true
|
|
188
|
+
}
|
|
189
|
+
const next =
|
|
190
|
+
ENDS_IN_PARAGRAPH.has(tag) || (!inList && tag !== "dt" && tag !== "dd")
|
|
191
|
+
? words(editor.schema, "p")
|
|
192
|
+
: words(editor.schema, tag, open)
|
|
193
|
+
|
|
194
|
+
if (offset === 0 && node.content.size > 0) {
|
|
195
|
+
// At the start of words: an empty block before them, which they keep their kind beside.
|
|
196
|
+
tr.insert(pos, ENDS_IN_PARAGRAPH.has(tag) ? words(editor.schema, "p") : copyOf(node, open))
|
|
197
|
+
} else if (offset === node.content.size) {
|
|
198
|
+
tr.insert(pos + node.nodeSize, next)
|
|
199
|
+
tr.setSelection(TextSelection.create(tr.doc, pos + node.nodeSize + 1))
|
|
200
|
+
} else {
|
|
201
|
+
// In the middle: the words after the caret go to a block like this one.
|
|
202
|
+
tr.split(tr.selection.from, 1, [
|
|
203
|
+
{ type: node.type, attrs: { ...node.attrs, open, before: null, inner: null } },
|
|
204
|
+
])
|
|
205
|
+
}
|
|
206
|
+
editor.view.dispatch(tr.scrollIntoView())
|
|
207
|
+
return true
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** An empty block of words like `node`, without its id. */
|
|
211
|
+
function copyOf(node: ProseMirrorNode, open: string): ProseMirrorNode {
|
|
212
|
+
return node.type.create({ ...node.attrs, open, before: null, inner: null })
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Backspace at the start of a block of words: a heading or a quote becomes a paragraph, a list's
|
|
217
|
+
* first item leaves the list, and what would merge across boxes of the design does nothing. An
|
|
218
|
+
* empty block after a picture or another block goes, and the caret with it.
|
|
219
|
+
*/
|
|
220
|
+
function backspace(editor: Editor): boolean {
|
|
221
|
+
const { selection } = editor.state
|
|
222
|
+
if (!(selection instanceof TextSelection) || !selection.empty) return false
|
|
223
|
+
const at = wordsAt(selection)
|
|
224
|
+
if (!at || selection.$from.parentOffset > 0) return false
|
|
225
|
+
const { node, pos } = at
|
|
226
|
+
const tag = tagOf(node)
|
|
227
|
+
const $pos = editor.state.doc.resolve(pos)
|
|
228
|
+
const index = $pos.index()
|
|
229
|
+
const tr = editor.state.tr
|
|
230
|
+
|
|
231
|
+
if (ENDS_IN_PARAGRAPH.has(tag) && node.content.size > 0) {
|
|
232
|
+
tr.setNodeMarkup(pos, undefined, { ...node.attrs, tag: "p", open: "<p>", close: "</p>" })
|
|
233
|
+
editor.view.dispatch(tr)
|
|
234
|
+
return true
|
|
235
|
+
}
|
|
236
|
+
if (tag === "li" && LIST_TAGS.has(tagOf($pos.parent))) {
|
|
237
|
+
if (index > 0) return false
|
|
238
|
+
liftOut(tr, pos, words(editor.schema, "p", undefined, node.content))
|
|
239
|
+
editor.view.dispatch(tr.scrollIntoView())
|
|
240
|
+
return true
|
|
241
|
+
}
|
|
242
|
+
if (SINGLE_BLOCK_TAGS.has(tag)) return true
|
|
243
|
+
|
|
244
|
+
const previous = index > 0 ? $pos.parent.child(index - 1) : null
|
|
245
|
+
if (!previous) {
|
|
246
|
+
// The first block in its box: leaving it would merge it into what comes before.
|
|
247
|
+
if (node.content.size > 0 || $pos.depth === 0 || $pos.parent.childCount === 1) return true
|
|
248
|
+
tr.delete(pos, pos + node.nodeSize)
|
|
249
|
+
tr.setSelection(Selection.near(tr.doc.resolve(pos), -1))
|
|
250
|
+
editor.view.dispatch(tr.scrollIntoView())
|
|
251
|
+
return true
|
|
252
|
+
}
|
|
253
|
+
if (previous.type.name === "textBlock") return false
|
|
254
|
+
|
|
255
|
+
const previousPos = pos - previous.nodeSize
|
|
256
|
+
if (node.content.size === 0) {
|
|
257
|
+
tr.delete(pos, pos + node.nodeSize)
|
|
258
|
+
tr.setSelection(
|
|
259
|
+
previous.isAtom
|
|
260
|
+
? NodeSelection.create(tr.doc, previousPos)
|
|
261
|
+
: Selection.near(tr.doc.resolve(pos), -1)
|
|
262
|
+
)
|
|
263
|
+
} else if (previous.isAtom) {
|
|
264
|
+
tr.setSelection(NodeSelection.create(tr.doc, previousPos))
|
|
265
|
+
} else {
|
|
266
|
+
tr.setSelection(Selection.near(tr.doc.resolve(pos), -1))
|
|
267
|
+
}
|
|
268
|
+
editor.view.dispatch(tr.scrollIntoView())
|
|
269
|
+
return true
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Delete at the end of a block of words, as Backspace at the start of the next. */
|
|
273
|
+
function forwardDelete(editor: Editor): boolean {
|
|
274
|
+
const { selection } = editor.state
|
|
275
|
+
if (!(selection instanceof TextSelection) || !selection.empty) return false
|
|
276
|
+
const at = wordsAt(selection)
|
|
277
|
+
if (!at || selection.$from.parentOffset < at.node.content.size) return false
|
|
278
|
+
if (SINGLE_BLOCK_TAGS.has(tagOf(at.node))) return true
|
|
279
|
+
const $pos = editor.state.doc.resolve(at.pos)
|
|
280
|
+
const next = $pos.parent.maybeChild($pos.index() + 1)
|
|
281
|
+
// The last block in its box, or before something that is not words: nothing merges.
|
|
282
|
+
if (!next) return true
|
|
283
|
+
if (next.type.name !== "textBlock") {
|
|
284
|
+
const after = at.pos + at.node.nodeSize
|
|
285
|
+
const tr = editor.state.tr
|
|
286
|
+
if (at.node.content.size === 0) tr.delete(at.pos, after)
|
|
287
|
+
else if (next.isAtom) tr.setSelection(NodeSelection.create(tr.doc, after))
|
|
288
|
+
editor.view.dispatch(tr.scrollIntoView())
|
|
289
|
+
return true
|
|
290
|
+
}
|
|
291
|
+
return false
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Tab in a table moves to the next cell, Shift-Tab to the one before; elsewhere it stays put. */
|
|
295
|
+
function nextCell(editor: Editor, by: -1 | 1): boolean {
|
|
296
|
+
const at = wordsAt(editor.state.selection)
|
|
297
|
+
const tag = tagOf(at?.node)
|
|
298
|
+
// Out of a table, Tab leaves the frame, as it leaves any field.
|
|
299
|
+
if (!at || (tag !== "td" && tag !== "th")) return false
|
|
300
|
+
const cells: number[] = []
|
|
301
|
+
const $pos = editor.state.doc.resolve(at.pos)
|
|
302
|
+
let tableDepth = 0
|
|
303
|
+
for (let depth = $pos.depth; depth > 0; depth -= 1) {
|
|
304
|
+
if (tagOf($pos.node(depth)) === "table") tableDepth = depth
|
|
305
|
+
}
|
|
306
|
+
if (tableDepth === 0) return true
|
|
307
|
+
const table = $pos.node(tableDepth)
|
|
308
|
+
const start = $pos.start(tableDepth)
|
|
309
|
+
table.descendants((node, offset) => {
|
|
310
|
+
if (node.type.name === "textBlock" && (tagOf(node) === "td" || tagOf(node) === "th")) {
|
|
311
|
+
cells.push(start + offset)
|
|
312
|
+
}
|
|
313
|
+
return node.type.name !== "textBlock"
|
|
314
|
+
})
|
|
315
|
+
const target = cells[cells.indexOf(at.pos) + by]
|
|
316
|
+
if (target === undefined) return true
|
|
317
|
+
const cell = editor.state.doc.nodeAt(target) as ProseMirrorNode
|
|
318
|
+
const tr = editor.state.tr.setSelection(
|
|
319
|
+
TextSelection.create(editor.state.doc, target + 1, target + 1 + cell.content.size)
|
|
320
|
+
)
|
|
321
|
+
editor.view.dispatch(tr.scrollIntoView())
|
|
322
|
+
return true
|
|
323
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// What the app and a designed document's editor in its frame say to each other, through the port
|
|
2
|
+
// the app hands the frame with the `editor` request, where the page's own scripts never post.
|
|
3
|
+
//
|
|
4
|
+
// app ── start ────▶ frame the live document's state, the page's path, the blocks it offers
|
|
5
|
+
// ── update ───▶ what changed in the live document, from others or the Agent
|
|
6
|
+
// ── awareness ▶ where everyone else's carets are
|
|
7
|
+
// ── run ──────▶ what the reader chose in the app's menus and toolbar
|
|
8
|
+
// ◀─ update ─── what the reader changed
|
|
9
|
+
// ◀─ cursor ─── where the reader's caret is, for everyone else
|
|
10
|
+
// ◀─ selection, slash, hover, drop what the app draws over the frame, in its coordinates
|
|
11
|
+
// ◀─ upload ─── pictures the reader pasted or dropped, for the app to store
|
|
12
|
+
//
|
|
13
|
+
// The frame keeps a copy of the live document and edits it with TipTap, as a Markdown document is
|
|
14
|
+
// edited, so the two stay in step by Yjs updates alone. Everything the reader sees around the
|
|
15
|
+
// page, menus and toolbars and the block handle, the app draws, in its own design.
|
|
16
|
+
|
|
17
|
+
/** The kinds of block the editor makes, as the `/` menu and "Turn into" offer them. */
|
|
18
|
+
export type PageBlockId =
|
|
19
|
+
| "paragraph"
|
|
20
|
+
| "heading1"
|
|
21
|
+
| "heading2"
|
|
22
|
+
| "heading3"
|
|
23
|
+
| "bulletList"
|
|
24
|
+
| "orderedList"
|
|
25
|
+
| "quote"
|
|
26
|
+
| "table"
|
|
27
|
+
| "image"
|
|
28
|
+
| "divider"
|
|
29
|
+
| "pageBreak"
|
|
30
|
+
|
|
31
|
+
/** A kind of block, as the frame finds it by what the reader types after `/`. */
|
|
32
|
+
export interface PageBlockChoice {
|
|
33
|
+
readonly id: PageBlockId
|
|
34
|
+
readonly label: string
|
|
35
|
+
readonly keywords: readonly string[]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A rectangle in the frame's viewport, which is where the app's overlay draws. */
|
|
39
|
+
export interface EditorRect {
|
|
40
|
+
readonly left: number
|
|
41
|
+
readonly top: number
|
|
42
|
+
readonly right: number
|
|
43
|
+
readonly bottom: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The marks of selected words the toolbar shows. */
|
|
47
|
+
export type PageMark = "bold" | "italic" | "underline" | "strike" | "code"
|
|
48
|
+
|
|
49
|
+
export type EditorCommand =
|
|
50
|
+
| { readonly name: "mark"; readonly mark: PageMark }
|
|
51
|
+
| { readonly name: "link"; readonly href: string | null }
|
|
52
|
+
| { readonly name: "turnInto"; readonly block: PageBlockId; readonly pos?: number }
|
|
53
|
+
/** Chooses the `/` menu's item at `index`, as Enter does. */
|
|
54
|
+
| { readonly name: "choose"; readonly index: number }
|
|
55
|
+
/** Points the `/` menu at its item at `index`, as the arrows do. */
|
|
56
|
+
| { readonly name: "point"; readonly index: number }
|
|
57
|
+
| { readonly name: "closeMenu" }
|
|
58
|
+
/** Adds a paragraph below the block at `pos` and opens the `/` menu in it. */
|
|
59
|
+
| { readonly name: "addBelow"; readonly pos: number }
|
|
60
|
+
| { readonly name: "duplicate"; readonly pos: number }
|
|
61
|
+
| { readonly name: "remove"; readonly pos: number }
|
|
62
|
+
| { readonly name: "move"; readonly pos: number; readonly by: -1 | 1 }
|
|
63
|
+
/** Picks the block at `pos` whole, as its handle's menu acts on it. */
|
|
64
|
+
| { readonly name: "pick"; readonly pos: number }
|
|
65
|
+
/** A drag of the block at `pos` by its handle, the pointer at `x`, `y`. */
|
|
66
|
+
| { readonly name: "drag"; readonly pos: number; readonly x: number; readonly y: number }
|
|
67
|
+
| { readonly name: "drop"; readonly pos: number; readonly x: number; readonly y: number }
|
|
68
|
+
| { readonly name: "endDrag" }
|
|
69
|
+
/**
|
|
70
|
+
* A picture the app stored for the reader, at the path its source names; `preview` shows it
|
|
71
|
+
* until a version of the document holds it.
|
|
72
|
+
*/
|
|
73
|
+
| {
|
|
74
|
+
readonly name: "image"
|
|
75
|
+
readonly src: string
|
|
76
|
+
readonly alt: string
|
|
77
|
+
readonly at?: number
|
|
78
|
+
readonly preview?: Blob
|
|
79
|
+
}
|
|
80
|
+
| { readonly name: "focus" }
|
|
81
|
+
|
|
82
|
+
export type AppToEditor =
|
|
83
|
+
| {
|
|
84
|
+
readonly type: "start"
|
|
85
|
+
/** The live document, as `Y.encodeStateAsUpdate` encodes it. */
|
|
86
|
+
readonly state: Uint8Array
|
|
87
|
+
readonly path: string
|
|
88
|
+
readonly editable: boolean
|
|
89
|
+
readonly blocks: readonly PageBlockChoice[]
|
|
90
|
+
/** Words the editor shows itself, in the reader's language. */
|
|
91
|
+
readonly words: EditorWords
|
|
92
|
+
}
|
|
93
|
+
| { readonly type: "update"; readonly update: Uint8Array }
|
|
94
|
+
| { readonly type: "awareness"; readonly update: Uint8Array }
|
|
95
|
+
| { readonly type: "editable"; readonly editable: boolean }
|
|
96
|
+
| { readonly type: "run"; readonly command: EditorCommand }
|
|
97
|
+
|
|
98
|
+
export interface EditorWords {
|
|
99
|
+
readonly placeholder: string
|
|
100
|
+
readonly listItem: string
|
|
101
|
+
/** An empty heading's placeholder, by level from 1. */
|
|
102
|
+
readonly headings: readonly string[]
|
|
103
|
+
readonly pageBreak: string
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** What the toolbar over selected words shows; null when no words are selected. */
|
|
107
|
+
export interface SelectionState {
|
|
108
|
+
readonly rect: EditorRect
|
|
109
|
+
readonly marks: Readonly<Record<PageMark, boolean>>
|
|
110
|
+
readonly link: string | null
|
|
111
|
+
readonly block: PageBlockId | null
|
|
112
|
+
/** Whether the words' block may be turned into another kind: not a cell or a caption. */
|
|
113
|
+
readonly turnable: boolean
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The `/` menu: where the `/` is, the kinds of block that match what follows it, the one pointed at. */
|
|
117
|
+
export interface SlashState {
|
|
118
|
+
readonly rect: EditorRect
|
|
119
|
+
readonly items: readonly PageBlockId[]
|
|
120
|
+
readonly index: number
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The block the pointer is over, which the handle sits beside. */
|
|
124
|
+
export interface HoverState {
|
|
125
|
+
readonly pos: number
|
|
126
|
+
readonly rect: EditorRect
|
|
127
|
+
/** Whether "Turn into" changes it: words that stand where any block may. */
|
|
128
|
+
readonly textual: boolean
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export type EditorToApp =
|
|
132
|
+
| { readonly type: "ready" }
|
|
133
|
+
/** The page is no longer one the editor holds: the live document holds it as text now. */
|
|
134
|
+
| { readonly type: "gone" }
|
|
135
|
+
| { readonly type: "update"; readonly update: Uint8Array }
|
|
136
|
+
| { readonly type: "cursor"; readonly cursor: unknown }
|
|
137
|
+
| { readonly type: "focus"; readonly focused: boolean }
|
|
138
|
+
| { readonly type: "selection"; readonly selection: SelectionState | null }
|
|
139
|
+
| { readonly type: "slash"; readonly slash: SlashState | null }
|
|
140
|
+
| { readonly type: "hover"; readonly hover: HoverState | null }
|
|
141
|
+
/** Where a block dragged by its handle would land: a line across the page. */
|
|
142
|
+
| { readonly type: "drop"; readonly line: EditorRect | null }
|
|
143
|
+
/** ⌘K over selected words: the app opens the toolbar's link field. */
|
|
144
|
+
| { readonly type: "linkRequest" }
|
|
145
|
+
/** Pictures the reader pasted or dropped, to add at the block at `at`. */
|
|
146
|
+
| { readonly type: "upload"; readonly files: readonly File[]; readonly at: number | null }
|
|
147
|
+
/** The reader chose a picture from the `/` menu: the app asks them for the file. */
|
|
148
|
+
| { readonly type: "pickImage"; readonly at: number | null }
|
|
149
|
+
|
|
150
|
+
/** The global the editor's script sets as it runs, which the frame's runtime takes at once. */
|
|
151
|
+
export const FRAME_EDITOR_GLOBAL = "__sixbFrameEditor"
|