@sixb/app 0.2.4 → 0.2.6
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/agent-threads.d.ts.map +1 -1
- package/dist/agent/components/composer-place.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/computer-place.d.ts +24 -6
- package/dist/agent/components/computer-place.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 +13 -3
- 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 +13 -0
- package/dist/agent/components/transcript.d.ts.map +1 -1
- package/dist/agent/conversation.d.ts +7 -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/format.d.ts +7 -0
- package/dist/agent/format.d.ts.map +1 -1
- package/dist/agent/hooks/thread-queries.d.ts +1548 -0
- package/dist/agent/hooks/thread-queries.d.ts.map +1 -0
- package/dist/agent/hooks/use-agent-conversation.d.ts +51 -6
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-lists.d.ts +80 -3
- package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-place.d.ts +49 -0
- package/dist/agent/hooks/use-thread-place.d.ts.map +1 -0
- package/dist/agent/hooks/use-thread-stream.d.ts.map +1 -1
- package/dist/agent/i18n/en.d.ts +107 -6
- 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 +180 -12
- 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/model-selection.d.ts +3 -2
- package/dist/agent/model-selection.d.ts.map +1 -1
- package/dist/agent/moves.d.ts +40 -0
- package/dist/agent/moves.d.ts.map +1 -0
- 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-reader-state.d.ts +30 -0
- package/dist/agent/thread-reader-state.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 +9 -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-pxd07kvx.js → chunk-096d52h2.js} +1 -1
- package/dist/{chunk-yrcm1pbg.js → chunk-94d7enwc.js} +491 -2128
- package/dist/chunk-94d7enwc.js.map +27 -0
- package/dist/{chunk-970s5nkn.js → chunk-ezntd3yy.js} +1 -1
- package/dist/{chunk-kymx9y5e.js → chunk-qjw5r2vk.js} +12729 -5044
- package/dist/chunk-qjw5r2vk.js.map +242 -0
- package/dist/chunk-y51c4tsz.js +11 -0
- package/dist/chunk-y51c4tsz.js.map +10 -0
- package/dist/createCustomApp.d.ts +8 -1
- package/dist/createCustomApp.d.ts.map +1 -1
- package/dist/index.d.ts +4 -2
- 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/accounts.d.ts +94 -0
- package/dist/pages/console/data/accounts.d.ts.map +1 -0
- package/dist/pages/console/data/connectors.d.ts.map +1 -1
- package/dist/pages/console/data/live-updates.d.ts.map +1 -1
- package/dist/pages/console/data/messages.d.ts +52 -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/console/data/sync-button.d.ts.map +1 -1
- package/dist/pages/console/data/syncs.d.ts.map +1 -1
- package/dist/pages/settings/usage/breakdown.d.ts.map +1 -1
- package/dist/pages/settings/usage/page.d.ts +4 -1
- package/dist/pages/settings/usage/page.d.ts.map +1 -1
- package/dist/pages/settings/usage/spend-model.d.ts +43 -19
- package/dist/pages/settings/usage/spend-model.d.ts.map +1 -1
- package/dist/pages.js +23044 -22570
- package/dist/pages.js.map +17 -16
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +40 -3
- package/dist/server.js.map +3 -3
- 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 +58 -39
- 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/agent-threads.tsx +42 -2
- package/src/agent/components/composer-place.tsx +2 -7
- package/src/agent/components/composer-settings.tsx +20 -10
- package/src/agent/components/composer.tsx +342 -104
- package/src/agent/components/computer-place.tsx +415 -70
- package/src/agent/components/context-meter.tsx +7 -3
- package/src/agent/components/conversation-panel.tsx +99 -54
- package/src/agent/components/message-parts.tsx +367 -59
- package/src/agent/components/message-view.tsx +428 -9
- package/src/agent/components/pending-messages.tsx +342 -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 +198 -38
- package/src/agent/conversation.ts +219 -55
- package/src/agent/delegation/interpret.ts +31 -7
- package/src/agent/format.ts +52 -0
- package/src/agent/hooks/thread-queries.ts +75 -0
- package/src/agent/hooks/use-agent-conversation.ts +801 -211
- package/src/agent/hooks/use-thread-lists.ts +72 -7
- package/src/agent/hooks/use-thread-place.ts +239 -0
- package/src/agent/hooks/use-thread-stream.ts +10 -0
- package/src/agent/i18n/en.ts +150 -27
- package/src/agent/i18n/fr.ts +148 -31
- package/src/agent/inbox-handoff.ts +47 -0
- package/src/agent/live-run.ts +61 -2
- package/src/agent/model-selection.ts +3 -2
- package/src/agent/moves.ts +174 -0
- 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-reader-state.ts +75 -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 +13 -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 +9 -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/createCustomApp.ts +57 -3
- package/src/index.ts +10 -0
- package/src/pages/console/data/accounts.tsx +509 -0
- package/src/pages/console/data/connectors.tsx +7 -15
- package/src/pages/console/data/live-updates.ts +2 -0
- package/src/pages/console/data/messages.ts +79 -0
- package/src/pages/console/data/projections.tsx +4 -0
- package/src/pages/console/data/shared.tsx +1 -0
- package/src/pages/console/data/sync-button.tsx +56 -16
- package/src/pages/console/data/syncs.tsx +66 -41
- package/src/pages/console/ontology/lineage/trail.tsx +3 -0
- package/src/pages/section-ui.tsx +1 -1
- package/src/pages/settings/usage/breakdown.tsx +5 -2
- package/src/pages/settings/usage/filter-menu.tsx +1 -1
- package/src/pages/settings/usage/page.tsx +32 -13
- package/src/pages/settings/usage/spend-chart.tsx +2 -2
- package/src/pages/settings/usage/spend-model.ts +118 -50
- package/src/server.ts +1 -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-096d52h2.js.map} +0 -0
- /package/dist/{chunk-970s5nkn.js.map → chunk-ezntd3yy.js.map} +0 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { type AnyExtension, mergeAttributes, Node } from "@tiptap/core"
|
|
2
|
+
import { CodeBlock } from "@tiptap/extension-code-block"
|
|
3
|
+
import { Image } from "@tiptap/extension-image"
|
|
4
|
+
import { TaskItem, TaskList } from "@tiptap/extension-list"
|
|
5
|
+
import { Table, TableCell, TableHeader, TableRow } from "@tiptap/extension-table"
|
|
6
|
+
import { StarterKit } from "@tiptap/starter-kit"
|
|
7
|
+
import { CALLOUT_KINDS } from "../renderers/document-tree"
|
|
8
|
+
|
|
9
|
+
// The blocks a Markdown document is made of, as the editor's schema: the nodes and marks core's
|
|
10
|
+
// `artifacts/live/blocks.ts` reads Markdown into, with the same names and attributes, so the
|
|
11
|
+
// live document's `Y.XmlFragment` is what both read and write. A node or attribute added here is
|
|
12
|
+
// added there too, or the server writes it back as nothing.
|
|
13
|
+
|
|
14
|
+
/** A `> [!NOTE]` quote: a block of blocks of one kind. */
|
|
15
|
+
export const CalloutNode = Node.create({
|
|
16
|
+
name: "callout",
|
|
17
|
+
group: "block",
|
|
18
|
+
content: "block+",
|
|
19
|
+
defining: true,
|
|
20
|
+
addAttributes() {
|
|
21
|
+
return {
|
|
22
|
+
kind: {
|
|
23
|
+
default: "note",
|
|
24
|
+
parseHTML: (element) => element.getAttribute("data-callout") ?? "note",
|
|
25
|
+
renderHTML: (attrs) => ({ "data-callout": attrs.kind }),
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
parseHTML() {
|
|
30
|
+
return [{ tag: "aside[data-callout]" }]
|
|
31
|
+
},
|
|
32
|
+
renderHTML({ HTMLAttributes }) {
|
|
33
|
+
return ["aside", mergeAttributes(HTMLAttributes, { class: "sixb-callout" }), 0]
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
/** Markdown the editor does not model, a footnote or raw HTML, kept as it was written. */
|
|
38
|
+
export const MarkdownBlock = Node.create({
|
|
39
|
+
name: "markdown",
|
|
40
|
+
group: "block",
|
|
41
|
+
atom: true,
|
|
42
|
+
selectable: true,
|
|
43
|
+
draggable: true,
|
|
44
|
+
addAttributes() {
|
|
45
|
+
return { source: { default: "" } }
|
|
46
|
+
},
|
|
47
|
+
parseHTML() {
|
|
48
|
+
return [{ tag: "pre[data-markdown]", getAttrs: (element) => ({ source: element.textContent }) }]
|
|
49
|
+
},
|
|
50
|
+
renderHTML({ node }) {
|
|
51
|
+
return ["pre", { "data-markdown": "", class: "sixb-editor-verbatim" }, node.attrs.source]
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
/** The same, within a line of text. */
|
|
56
|
+
export const MarkdownInline = Node.create({
|
|
57
|
+
name: "markdownInline",
|
|
58
|
+
group: "inline",
|
|
59
|
+
inline: true,
|
|
60
|
+
atom: true,
|
|
61
|
+
addAttributes() {
|
|
62
|
+
return { source: { default: "" } }
|
|
63
|
+
},
|
|
64
|
+
parseHTML() {
|
|
65
|
+
return [
|
|
66
|
+
{ tag: "code[data-markdown]", getAttrs: (element) => ({ source: element.textContent }) },
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
renderHTML({ node }) {
|
|
70
|
+
return ["code", { "data-markdown": "", class: "sixb-editor-verbatim" }, node.attrs.source]
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
/** A table cell's column alignment, which GFM keeps on its delimiter row. */
|
|
75
|
+
const align = {
|
|
76
|
+
align: {
|
|
77
|
+
default: null,
|
|
78
|
+
parseHTML: (element: HTMLElement) => element.style.textAlign || null,
|
|
79
|
+
renderHTML: (attrs: Record<string, unknown>) =>
|
|
80
|
+
attrs.align ? { style: `text-align: ${attrs.align}` } : {},
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A fenced code block: its language, and the rest of its info string. */
|
|
85
|
+
export const CodeBlockWithMeta = CodeBlock.extend({
|
|
86
|
+
addAttributes() {
|
|
87
|
+
return { ...this.parent?.(), meta: { default: null, rendered: false } }
|
|
88
|
+
},
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* A header cell, with its column's alignment. A Markdown cell holds one line of words: its
|
|
93
|
+
* paragraphs, each a line, and no other block.
|
|
94
|
+
*/
|
|
95
|
+
const AlignedHeader = TableHeader.extend({
|
|
96
|
+
content: "paragraph+",
|
|
97
|
+
addAttributes() {
|
|
98
|
+
return { ...this.parent?.(), ...align }
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
/** A body cell, with its column's alignment, and words alone. */
|
|
103
|
+
const AlignedCell = TableCell.extend({
|
|
104
|
+
content: "paragraph+",
|
|
105
|
+
addAttributes() {
|
|
106
|
+
return { ...this.parent?.(), ...align }
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
/** A figure: an image alone in its paragraph, its title its caption. */
|
|
111
|
+
export const Figure = Image.extend({
|
|
112
|
+
draggable: true,
|
|
113
|
+
addAttributes() {
|
|
114
|
+
return {
|
|
115
|
+
src: { default: null },
|
|
116
|
+
alt: { default: null },
|
|
117
|
+
title: { default: null },
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
}).configure({ inline: false, allowBase64: false })
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The document's schema. `codeBlock` keeps its info string's meta, a heading its level, an
|
|
124
|
+
* ordered list its start: what writing it back as Markdown needs.
|
|
125
|
+
*/
|
|
126
|
+
export function documentSchemaExtensions(
|
|
127
|
+
options: { readonly callout?: AnyExtension } = {}
|
|
128
|
+
): AnyExtension[] {
|
|
129
|
+
return [
|
|
130
|
+
StarterKit.configure({
|
|
131
|
+
// Undo is the live document's own, and nothing is added to a document because it opened.
|
|
132
|
+
undoRedo: false,
|
|
133
|
+
trailingNode: false,
|
|
134
|
+
underline: false,
|
|
135
|
+
// A document's link opens where its reader decides: no target, no rel, as Markdown has none.
|
|
136
|
+
link: {
|
|
137
|
+
openOnClick: false,
|
|
138
|
+
autolink: true,
|
|
139
|
+
defaultProtocol: "https",
|
|
140
|
+
HTMLAttributes: { target: null, rel: null },
|
|
141
|
+
},
|
|
142
|
+
codeBlock: false,
|
|
143
|
+
heading: { levels: [1, 2, 3, 4, 5, 6] },
|
|
144
|
+
}),
|
|
145
|
+
CodeBlockWithMeta,
|
|
146
|
+
options.callout ?? CalloutNode,
|
|
147
|
+
MarkdownBlock,
|
|
148
|
+
MarkdownInline,
|
|
149
|
+
Figure,
|
|
150
|
+
TaskList,
|
|
151
|
+
TaskItem.configure({ nested: true }),
|
|
152
|
+
Table.configure({ resizable: false }),
|
|
153
|
+
TableRow,
|
|
154
|
+
AlignedHeader,
|
|
155
|
+
AlignedCell,
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { CALLOUT_KINDS }
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { cn } from "@sixb/ui/lib/utils"
|
|
2
|
+
import type { Editor } from "@tiptap/core"
|
|
3
|
+
import { TextSelection, type Transaction } from "@tiptap/pm/state"
|
|
4
|
+
import { useEditorState } from "@tiptap/react"
|
|
5
|
+
import { BubbleMenu } from "@tiptap/react/menus"
|
|
6
|
+
import { ySyncPluginKey } from "@tiptap/y-tiptap"
|
|
7
|
+
import {
|
|
8
|
+
Bold,
|
|
9
|
+
Check,
|
|
10
|
+
ChevronDown,
|
|
11
|
+
Code,
|
|
12
|
+
ExternalLink,
|
|
13
|
+
Italic,
|
|
14
|
+
Link2,
|
|
15
|
+
Strikethrough,
|
|
16
|
+
Unlink,
|
|
17
|
+
} from "lucide-react"
|
|
18
|
+
import { type ReactNode, useEffect, useRef, useState } from "react"
|
|
19
|
+
import type { BlockChoice, BlockType } from "./blocks"
|
|
20
|
+
import type { EditorMessages } from "./messages"
|
|
21
|
+
|
|
22
|
+
// The toolbar over selected words: what block they are in, the marks they carry, and a link. It
|
|
23
|
+
// shows for a range of text, never for a block picked whole or for code, where marks do not
|
|
24
|
+
// apply; ⌘K opens its link field from the keyboard.
|
|
25
|
+
|
|
26
|
+
export function SelectionToolbar({
|
|
27
|
+
editor,
|
|
28
|
+
types,
|
|
29
|
+
messages,
|
|
30
|
+
linkRequest,
|
|
31
|
+
}: {
|
|
32
|
+
readonly editor: Editor
|
|
33
|
+
readonly types: readonly BlockType[]
|
|
34
|
+
readonly messages: EditorMessages
|
|
35
|
+
/** Bumped by ⌘K: opens the link field over the selection. */
|
|
36
|
+
readonly linkRequest: number
|
|
37
|
+
}) {
|
|
38
|
+
const [mode, setMode] = useState<ToolbarMode>("marks")
|
|
39
|
+
const marks = useEditorState({
|
|
40
|
+
editor,
|
|
41
|
+
selector: ({ editor }) => ({
|
|
42
|
+
bold: editor.isActive("bold"),
|
|
43
|
+
italic: editor.isActive("italic"),
|
|
44
|
+
strike: editor.isActive("strike"),
|
|
45
|
+
code: editor.isActive("code"),
|
|
46
|
+
link: editor.isActive("link") ? String(editor.getAttributes("link").href ?? "") : null,
|
|
47
|
+
block: types.find((type) => type.turnsInto && type.isActive(editor)) ?? types[0],
|
|
48
|
+
}),
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
// Each new selection this reader makes opens on its marks; another editor's typing, which
|
|
52
|
+
// moves it, leaves the link field open.
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const reset = ({ transaction }: { readonly transaction: Transaction }) => {
|
|
55
|
+
if (transaction.selectionSet && !transaction.getMeta(ySyncPluginKey)) setMode("marks")
|
|
56
|
+
}
|
|
57
|
+
editor.on("transaction", reset)
|
|
58
|
+
return () => {
|
|
59
|
+
editor.off("transaction", reset)
|
|
60
|
+
}
|
|
61
|
+
}, [editor])
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (linkRequest > 0) setMode("link")
|
|
64
|
+
}, [linkRequest])
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<BubbleMenu
|
|
68
|
+
editor={editor}
|
|
69
|
+
pluginKey="sixb-selection-toolbar"
|
|
70
|
+
updateDelay={80}
|
|
71
|
+
options={{ placement: "top", offset: 10, flip: true, shift: { padding: 12 } }}
|
|
72
|
+
shouldShow={({ editor, state, from, to }) => {
|
|
73
|
+
if (!editor.isEditable || from === to) return false
|
|
74
|
+
if (editor.isActive("codeBlock") || editor.isActive("image")) return false
|
|
75
|
+
// A block picked whole (a rule, a figure, a table's cells) has no words to mark.
|
|
76
|
+
return state.selection instanceof TextSelection || mode === "link"
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
79
|
+
<div
|
|
80
|
+
className="sixb-editor-popover flex items-center gap-0.5 p-1"
|
|
81
|
+
onMouseDown={(event) => {
|
|
82
|
+
// The selection stays as it is while its toolbar is used, but a field may take focus.
|
|
83
|
+
if (!(event.target instanceof HTMLInputElement)) event.preventDefault()
|
|
84
|
+
}}
|
|
85
|
+
>
|
|
86
|
+
<SelectionToolbarBody
|
|
87
|
+
mode={mode}
|
|
88
|
+
onMode={setMode}
|
|
89
|
+
marks={{
|
|
90
|
+
bold: !!marks?.bold,
|
|
91
|
+
italic: !!marks?.italic,
|
|
92
|
+
strike: !!marks?.strike,
|
|
93
|
+
code: !!marks?.code,
|
|
94
|
+
link: marks?.link ?? null,
|
|
95
|
+
block: marks?.block?.id ?? null,
|
|
96
|
+
}}
|
|
97
|
+
types={types}
|
|
98
|
+
messages={messages}
|
|
99
|
+
onMark={(mark) => {
|
|
100
|
+
const chain = editor.chain().focus()
|
|
101
|
+
if (mark === "bold") chain.toggleBold().run()
|
|
102
|
+
else if (mark === "italic") chain.toggleItalic().run()
|
|
103
|
+
else if (mark === "strike") chain.toggleStrike().run()
|
|
104
|
+
else chain.toggleCode().run()
|
|
105
|
+
}}
|
|
106
|
+
onTurnInto={(id) => types.find((type) => type.id === id)?.make(editor)}
|
|
107
|
+
onLink={(href) => {
|
|
108
|
+
const chain = editor.chain().focus().extendMarkRange("link")
|
|
109
|
+
if (href) chain.setLink({ href }).run()
|
|
110
|
+
else chain.unsetLink().run()
|
|
111
|
+
}}
|
|
112
|
+
onCancelLink={() => editor.commands.focus()}
|
|
113
|
+
/>
|
|
114
|
+
</div>
|
|
115
|
+
</BubbleMenu>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export type ToolbarMode = "marks" | "link" | "turnInto"
|
|
120
|
+
|
|
121
|
+
/** The marks over selected words the toolbar toggles. */
|
|
122
|
+
export type ToolbarMark = "bold" | "italic" | "strike" | "code"
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The toolbar's contents, whichever editor it is over: the block the words are in, their marks,
|
|
126
|
+
* and their link, or the field that edits it, or the kinds of block to turn theirs into.
|
|
127
|
+
*/
|
|
128
|
+
export function SelectionToolbarBody({
|
|
129
|
+
mode,
|
|
130
|
+
onMode,
|
|
131
|
+
marks,
|
|
132
|
+
types,
|
|
133
|
+
messages,
|
|
134
|
+
onMark,
|
|
135
|
+
onTurnInto,
|
|
136
|
+
onLink,
|
|
137
|
+
onCancelLink,
|
|
138
|
+
turnable = true,
|
|
139
|
+
}: {
|
|
140
|
+
readonly mode: ToolbarMode
|
|
141
|
+
readonly onMode: (mode: ToolbarMode) => void
|
|
142
|
+
readonly marks: Readonly<Record<ToolbarMark, boolean>> & {
|
|
143
|
+
readonly link: string | null
|
|
144
|
+
readonly block: string | null
|
|
145
|
+
}
|
|
146
|
+
readonly types: readonly BlockChoice[]
|
|
147
|
+
readonly messages: EditorMessages
|
|
148
|
+
readonly onMark: (mark: ToolbarMark) => void
|
|
149
|
+
readonly onTurnInto: (id: string) => void
|
|
150
|
+
/** Sets the words' link, or removes it with null. */
|
|
151
|
+
readonly onLink: (href: string | null) => void
|
|
152
|
+
readonly onCancelLink: () => void
|
|
153
|
+
/** Whether the words' block may be turned into another kind; a table's cell may not. */
|
|
154
|
+
readonly turnable?: boolean
|
|
155
|
+
}) {
|
|
156
|
+
const block = types.find((type) => type.id === marks.block) ?? types[0]
|
|
157
|
+
if (mode === "link") {
|
|
158
|
+
return (
|
|
159
|
+
<LinkField
|
|
160
|
+
href={marks.link ?? ""}
|
|
161
|
+
messages={messages.link}
|
|
162
|
+
onApply={(href) => {
|
|
163
|
+
onLink(href)
|
|
164
|
+
onMode("marks")
|
|
165
|
+
}}
|
|
166
|
+
onCancel={() => {
|
|
167
|
+
onCancelLink()
|
|
168
|
+
onMode("marks")
|
|
169
|
+
}}
|
|
170
|
+
/>
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
if (mode === "turnInto") {
|
|
174
|
+
return (
|
|
175
|
+
<div className="flex max-h-72 w-56 flex-col overflow-y-auto">
|
|
176
|
+
{types
|
|
177
|
+
.filter((type) => type.turnsInto)
|
|
178
|
+
.map((type) => {
|
|
179
|
+
const Icon = type.icon
|
|
180
|
+
return (
|
|
181
|
+
<button
|
|
182
|
+
key={type.id}
|
|
183
|
+
type="button"
|
|
184
|
+
className="flex items-center gap-2.5 rounded-md px-2 py-1.5 text-left text-sm hover:bg-accent"
|
|
185
|
+
onClick={() => {
|
|
186
|
+
onTurnInto(type.id)
|
|
187
|
+
onMode("marks")
|
|
188
|
+
}}
|
|
189
|
+
>
|
|
190
|
+
<Icon className="size-4 text-muted-foreground" strokeWidth={1.75} />
|
|
191
|
+
<span className="flex-1">{type.label}</span>
|
|
192
|
+
{marks.block === type.id ? (
|
|
193
|
+
<Check className="size-3.5 text-muted-foreground" />
|
|
194
|
+
) : null}
|
|
195
|
+
</button>
|
|
196
|
+
)
|
|
197
|
+
})}
|
|
198
|
+
</div>
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
return (
|
|
202
|
+
<>
|
|
203
|
+
{turnable ? (
|
|
204
|
+
<>
|
|
205
|
+
<button
|
|
206
|
+
type="button"
|
|
207
|
+
className="flex h-8 items-center gap-1 rounded-md px-2 text-sm font-medium hover:bg-accent"
|
|
208
|
+
onClick={() => onMode("turnInto")}
|
|
209
|
+
aria-label={messages.toolbar.turnInto}
|
|
210
|
+
>
|
|
211
|
+
{marks.block ? block?.label : messages.toolbar.turnInto}
|
|
212
|
+
<ChevronDown className="size-3.5 text-muted-foreground" />
|
|
213
|
+
</button>
|
|
214
|
+
<span className="mx-0.5 h-5 w-px bg-border" />
|
|
215
|
+
</>
|
|
216
|
+
) : null}
|
|
217
|
+
<MarkButton
|
|
218
|
+
label={messages.toolbar.bold}
|
|
219
|
+
keys="⌘B"
|
|
220
|
+
active={marks.bold}
|
|
221
|
+
onClick={() => onMark("bold")}
|
|
222
|
+
>
|
|
223
|
+
<Bold className="size-4" strokeWidth={2.25} />
|
|
224
|
+
</MarkButton>
|
|
225
|
+
<MarkButton
|
|
226
|
+
label={messages.toolbar.italic}
|
|
227
|
+
keys="⌘I"
|
|
228
|
+
active={marks.italic}
|
|
229
|
+
onClick={() => onMark("italic")}
|
|
230
|
+
>
|
|
231
|
+
<Italic className="size-4" strokeWidth={2.25} />
|
|
232
|
+
</MarkButton>
|
|
233
|
+
<MarkButton
|
|
234
|
+
label={messages.toolbar.strike}
|
|
235
|
+
keys="⌘⇧S"
|
|
236
|
+
active={marks.strike}
|
|
237
|
+
onClick={() => onMark("strike")}
|
|
238
|
+
>
|
|
239
|
+
<Strikethrough className="size-4" strokeWidth={2.25} />
|
|
240
|
+
</MarkButton>
|
|
241
|
+
<MarkButton
|
|
242
|
+
label={messages.toolbar.code}
|
|
243
|
+
keys="⌘E"
|
|
244
|
+
active={marks.code}
|
|
245
|
+
onClick={() => onMark("code")}
|
|
246
|
+
>
|
|
247
|
+
<Code className="size-4" strokeWidth={2.25} />
|
|
248
|
+
</MarkButton>
|
|
249
|
+
<span className="mx-0.5 h-5 w-px bg-border" />
|
|
250
|
+
<MarkButton
|
|
251
|
+
label={messages.toolbar.link}
|
|
252
|
+
keys="⌘K"
|
|
253
|
+
active={marks.link !== null}
|
|
254
|
+
onClick={() => onMode("link")}
|
|
255
|
+
>
|
|
256
|
+
<Link2 className="size-4" strokeWidth={2.25} />
|
|
257
|
+
</MarkButton>
|
|
258
|
+
</>
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function MarkButton({
|
|
263
|
+
label,
|
|
264
|
+
keys,
|
|
265
|
+
active,
|
|
266
|
+
onClick,
|
|
267
|
+
children,
|
|
268
|
+
}: {
|
|
269
|
+
readonly label: string
|
|
270
|
+
readonly keys: string
|
|
271
|
+
readonly active: boolean
|
|
272
|
+
readonly onClick: () => void
|
|
273
|
+
readonly children: ReactNode
|
|
274
|
+
}) {
|
|
275
|
+
return (
|
|
276
|
+
<button
|
|
277
|
+
type="button"
|
|
278
|
+
aria-label={label}
|
|
279
|
+
aria-pressed={active}
|
|
280
|
+
title={`${label} ${keys}`}
|
|
281
|
+
className={cn(
|
|
282
|
+
"flex size-8 items-center justify-center rounded-md transition-colors hover:bg-accent",
|
|
283
|
+
active ? "text-primary" : "text-foreground"
|
|
284
|
+
)}
|
|
285
|
+
onClick={onClick}
|
|
286
|
+
>
|
|
287
|
+
{children}
|
|
288
|
+
</button>
|
|
289
|
+
)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** The link of the selected words: typed or pasted, applied with Enter, removed in one click. */
|
|
293
|
+
function LinkField({
|
|
294
|
+
href,
|
|
295
|
+
messages,
|
|
296
|
+
onApply,
|
|
297
|
+
onCancel,
|
|
298
|
+
}: {
|
|
299
|
+
readonly href: string
|
|
300
|
+
readonly messages: EditorMessages["link"]
|
|
301
|
+
readonly onApply: (href: string | null) => void
|
|
302
|
+
readonly onCancel: () => void
|
|
303
|
+
}) {
|
|
304
|
+
const [value, setValue] = useState(href)
|
|
305
|
+
const input = useRef<HTMLInputElement | null>(null)
|
|
306
|
+
useEffect(() => {
|
|
307
|
+
input.current?.focus()
|
|
308
|
+
input.current?.select()
|
|
309
|
+
}, [])
|
|
310
|
+
|
|
311
|
+
return (
|
|
312
|
+
<form
|
|
313
|
+
className="flex w-80 items-center gap-1"
|
|
314
|
+
onSubmit={(event) => {
|
|
315
|
+
event.preventDefault()
|
|
316
|
+
onApply(value.trim() || null)
|
|
317
|
+
}}
|
|
318
|
+
>
|
|
319
|
+
<Link2 className="ml-1.5 size-4 shrink-0 text-muted-foreground" />
|
|
320
|
+
<input
|
|
321
|
+
ref={input}
|
|
322
|
+
value={value}
|
|
323
|
+
onChange={(event) => setValue(event.target.value)}
|
|
324
|
+
onKeyDown={(event) => {
|
|
325
|
+
if (event.key === "Escape") {
|
|
326
|
+
event.preventDefault()
|
|
327
|
+
onCancel()
|
|
328
|
+
}
|
|
329
|
+
}}
|
|
330
|
+
placeholder={messages.placeholder}
|
|
331
|
+
className="h-8 min-w-0 flex-1 bg-transparent px-1 text-sm outline-none placeholder:text-muted-foreground"
|
|
332
|
+
/>
|
|
333
|
+
{href ? (
|
|
334
|
+
<>
|
|
335
|
+
<a
|
|
336
|
+
href={href}
|
|
337
|
+
target="_blank"
|
|
338
|
+
rel="noreferrer"
|
|
339
|
+
aria-label={messages.open}
|
|
340
|
+
title={messages.open}
|
|
341
|
+
className="flex size-8 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground"
|
|
342
|
+
>
|
|
343
|
+
<ExternalLink className="size-4" />
|
|
344
|
+
</a>
|
|
345
|
+
<button
|
|
346
|
+
type="button"
|
|
347
|
+
aria-label={messages.remove}
|
|
348
|
+
title={messages.remove}
|
|
349
|
+
className="flex size-8 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground"
|
|
350
|
+
onClick={() => onApply(null)}
|
|
351
|
+
>
|
|
352
|
+
<Unlink className="size-4" />
|
|
353
|
+
</button>
|
|
354
|
+
</>
|
|
355
|
+
) : null}
|
|
356
|
+
<button
|
|
357
|
+
type="submit"
|
|
358
|
+
className="h-7 rounded-md bg-primary px-2.5 text-xs font-medium text-primary-foreground"
|
|
359
|
+
>
|
|
360
|
+
{messages.apply}
|
|
361
|
+
</button>
|
|
362
|
+
</form>
|
|
363
|
+
)
|
|
364
|
+
}
|