@agent-native/toolkit 0.4.9 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -6
- package/dist/collab-ui/agent-identity.d.ts +9 -0
- package/dist/collab-ui/agent-identity.d.ts.map +1 -0
- package/dist/collab-ui/agent-identity.js +9 -0
- package/dist/collab-ui/agent-identity.js.map +1 -0
- package/dist/collab-ui/index.d.ts +2 -0
- package/dist/collab-ui/index.d.ts.map +1 -1
- package/dist/collab-ui/index.js +2 -0
- package/dist/collab-ui/index.js.map +1 -1
- package/dist/collab-ui/lead-client.d.ts +3 -0
- package/dist/collab-ui/lead-client.d.ts.map +1 -0
- package/dist/collab-ui/lead-client.js +29 -0
- package/dist/collab-ui/lead-client.js.map +1 -0
- package/dist/collab-ui/types.d.ts.map +1 -1
- package/dist/collab-ui/types.js +11 -2
- package/dist/collab-ui/types.js.map +1 -1
- package/dist/collab-ui/types.spec.d.ts +2 -0
- package/dist/collab-ui/types.spec.d.ts.map +1 -0
- package/dist/collab-ui/types.spec.js +15 -0
- package/dist/collab-ui/types.spec.js.map +1 -0
- package/dist/context-ui/ContextMeter.d.ts +10 -0
- package/dist/context-ui/ContextMeter.d.ts.map +1 -0
- package/dist/context-ui/ContextMeter.js +20 -0
- package/dist/context-ui/ContextMeter.js.map +1 -0
- package/dist/context-ui/ContextSegmentRow.d.ts +14 -0
- package/dist/context-ui/ContextSegmentRow.d.ts.map +1 -0
- package/dist/context-ui/ContextSegmentRow.js +25 -0
- package/dist/context-ui/ContextSegmentRow.js.map +1 -0
- package/dist/context-ui/ContextTreemap.d.ts +7 -0
- package/dist/context-ui/ContextTreemap.d.ts.map +1 -0
- package/dist/context-ui/ContextTreemap.js +55 -0
- package/dist/context-ui/ContextTreemap.js.map +1 -0
- package/dist/context-ui/ContextXRayPanel.d.ts +13 -0
- package/dist/context-ui/ContextXRayPanel.d.ts.map +1 -0
- package/dist/context-ui/ContextXRayPanel.js +120 -0
- package/dist/context-ui/ContextXRayPanel.js.map +1 -0
- package/dist/context-ui/format.d.ts +6 -0
- package/dist/context-ui/format.d.ts.map +1 -0
- package/dist/context-ui/format.js +58 -0
- package/dist/context-ui/format.js.map +1 -0
- package/dist/context-ui/index.d.ts +7 -0
- package/dist/context-ui/index.d.ts.map +1 -0
- package/dist/context-ui/index.js +6 -0
- package/dist/context-ui/index.js.map +1 -0
- package/dist/context-ui/types.d.ts +39 -0
- package/dist/context-ui/types.d.ts.map +1 -0
- package/dist/context-ui/types.js +2 -0
- package/dist/context-ui/types.js.map +1 -0
- package/dist/design-tweaks/index.d.ts +2 -0
- package/dist/design-tweaks/index.d.ts.map +1 -0
- package/dist/design-tweaks/index.js +2 -0
- package/dist/design-tweaks/index.js.map +1 -0
- package/dist/design-tweaks/visual-style-controls.d.ts +90 -0
- package/dist/design-tweaks/visual-style-controls.d.ts.map +1 -0
- package/dist/design-tweaks/visual-style-controls.js +499 -0
- package/dist/design-tweaks/visual-style-controls.js.map +1 -0
- package/dist/editor/BubbleToolbar.d.ts +37 -0
- package/dist/editor/BubbleToolbar.d.ts.map +1 -0
- package/dist/editor/BubbleToolbar.js +171 -0
- package/dist/editor/BubbleToolbar.js.map +1 -0
- package/dist/editor/CodeBlockNode.d.ts +49 -0
- package/dist/editor/CodeBlockNode.d.ts.map +1 -0
- package/dist/editor/CodeBlockNode.js +127 -0
- package/dist/editor/CodeBlockNode.js.map +1 -0
- package/dist/editor/DragHandle.d.ts +97 -0
- package/dist/editor/DragHandle.d.ts.map +1 -0
- package/dist/editor/DragHandle.js +1066 -0
- package/dist/editor/DragHandle.js.map +1 -0
- package/dist/editor/DragHandle.spec.d.ts +2 -0
- package/dist/editor/DragHandle.spec.d.ts.map +1 -0
- package/dist/editor/DragHandle.spec.js +407 -0
- package/dist/editor/DragHandle.spec.js.map +1 -0
- package/dist/editor/ImageExtension.d.ts +63 -0
- package/dist/editor/ImageExtension.d.ts.map +1 -0
- package/dist/editor/ImageExtension.js +243 -0
- package/dist/editor/ImageExtension.js.map +1 -0
- package/dist/editor/ImageExtension.roundtrip.spec.d.ts +2 -0
- package/dist/editor/ImageExtension.roundtrip.spec.d.ts.map +1 -0
- package/dist/editor/ImageExtension.roundtrip.spec.js +103 -0
- package/dist/editor/ImageExtension.roundtrip.spec.js.map +1 -0
- package/dist/editor/RichMarkdownEditor.collab.spec.d.ts +2 -0
- package/dist/editor/RichMarkdownEditor.collab.spec.d.ts.map +1 -0
- package/dist/editor/RichMarkdownEditor.collab.spec.js +65 -0
- package/dist/editor/RichMarkdownEditor.collab.spec.js.map +1 -0
- package/dist/editor/RichMarkdownEditor.d.ts +52 -0
- package/dist/editor/RichMarkdownEditor.d.ts.map +1 -0
- package/dist/editor/RichMarkdownEditor.js +38 -0
- package/dist/editor/RichMarkdownEditor.js.map +1 -0
- package/dist/editor/RichMarkdownEditor.roundtrip.spec.d.ts +2 -0
- package/dist/editor/RichMarkdownEditor.roundtrip.spec.d.ts.map +1 -0
- package/dist/editor/RichMarkdownEditor.roundtrip.spec.js +186 -0
- package/dist/editor/RichMarkdownEditor.roundtrip.spec.js.map +1 -0
- package/dist/editor/RunId.d.ts +28 -0
- package/dist/editor/RunId.d.ts.map +1 -0
- package/dist/editor/RunId.js +60 -0
- package/dist/editor/RunId.js.map +1 -0
- package/dist/editor/SharedRichEditor.d.ts +110 -0
- package/dist/editor/SharedRichEditor.d.ts.map +1 -0
- package/dist/editor/SharedRichEditor.js +144 -0
- package/dist/editor/SharedRichEditor.js.map +1 -0
- package/dist/editor/SlashCommandMenu.d.ts +41 -0
- package/dist/editor/SlashCommandMenu.d.ts.map +1 -0
- package/dist/editor/SlashCommandMenu.js +221 -0
- package/dist/editor/SlashCommandMenu.js.map +1 -0
- package/dist/editor/disableHistory.spec.d.ts +2 -0
- package/dist/editor/disableHistory.spec.d.ts.map +1 -0
- package/dist/editor/disableHistory.spec.js +73 -0
- package/dist/editor/disableHistory.spec.js.map +1 -0
- package/dist/editor/extensions.d.ts +178 -0
- package/dist/editor/extensions.d.ts.map +1 -0
- package/dist/editor/extensions.js +224 -0
- package/dist/editor/extensions.js.map +1 -0
- package/dist/editor/gfmDoc.d.ts +24 -0
- package/dist/editor/gfmDoc.d.ts.map +1 -0
- package/dist/editor/gfmDoc.js +83 -0
- package/dist/editor/gfmDoc.js.map +1 -0
- package/dist/editor/gfmDoc.spec.d.ts +2 -0
- package/dist/editor/gfmDoc.spec.d.ts.map +1 -0
- package/dist/editor/gfmDoc.spec.js +194 -0
- package/dist/editor/gfmDoc.spec.js.map +1 -0
- package/dist/editor/index.d.ts +13 -0
- package/dist/editor/index.d.ts.map +1 -0
- package/dist/editor/index.js +13 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/editor/structuralReorderUndo.spec.d.ts +2 -0
- package/dist/editor/structuralReorderUndo.spec.d.ts.map +1 -0
- package/dist/editor/structuralReorderUndo.spec.js +120 -0
- package/dist/editor/structuralReorderUndo.spec.js.map +1 -0
- package/dist/editor/surgical-apply.d.ts +66 -0
- package/dist/editor/surgical-apply.d.ts.map +1 -0
- package/dist/editor/surgical-apply.js +147 -0
- package/dist/editor/surgical-apply.js.map +1 -0
- package/dist/editor/surgical-apply.spec.d.ts +2 -0
- package/dist/editor/surgical-apply.spec.d.ts.map +1 -0
- package/dist/editor/surgical-apply.spec.js +257 -0
- package/dist/editor/surgical-apply.spec.js.map +1 -0
- package/dist/editor/useCollabReconcile.concurrent.spec.d.ts +2 -0
- package/dist/editor/useCollabReconcile.concurrent.spec.d.ts.map +1 -0
- package/dist/editor/useCollabReconcile.concurrent.spec.js +329 -0
- package/dist/editor/useCollabReconcile.concurrent.spec.js.map +1 -0
- package/dist/editor/useCollabReconcile.d.ts +110 -0
- package/dist/editor/useCollabReconcile.d.ts.map +1 -0
- package/dist/editor/useCollabReconcile.idempotent.spec.d.ts +2 -0
- package/dist/editor/useCollabReconcile.idempotent.spec.d.ts.map +1 -0
- package/dist/editor/useCollabReconcile.idempotent.spec.js +248 -0
- package/dist/editor/useCollabReconcile.idempotent.spec.js.map +1 -0
- package/dist/editor/useCollabReconcile.js +440 -0
- package/dist/editor/useCollabReconcile.js.map +1 -0
- package/dist/editor.css +510 -0
- package/package.json +63 -9
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
|
|
3
|
+
import { cn } from "../utils.js";
|
|
4
|
+
import { pickAndInsertImage } from "./ImageExtension.js";
|
|
5
|
+
/**
|
|
6
|
+
* The default block commands — Plan's current set. Apps pass their own `items`
|
|
7
|
+
* (typically `[...DEFAULT_SLASH_COMMANDS, ...extra]`) to extend it.
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_SLASH_COMMANDS = [
|
|
10
|
+
{
|
|
11
|
+
title: "Text",
|
|
12
|
+
description: "Plain text block",
|
|
13
|
+
icon: "T",
|
|
14
|
+
action: (editor) => editor.chain().focus().setParagraph().run(),
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
title: "Heading 1",
|
|
18
|
+
description: "Large heading",
|
|
19
|
+
icon: "H1",
|
|
20
|
+
action: (editor) => editor.chain().focus().toggleHeading({ level: 1 }).run(),
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
title: "Heading 2",
|
|
24
|
+
description: "Section heading",
|
|
25
|
+
icon: "H2",
|
|
26
|
+
action: (editor) => editor.chain().focus().toggleHeading({ level: 2 }).run(),
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
title: "Heading 3",
|
|
30
|
+
description: "Subheading",
|
|
31
|
+
icon: "H3",
|
|
32
|
+
action: (editor) => editor.chain().focus().toggleHeading({ level: 3 }).run(),
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
title: "Bulleted list",
|
|
36
|
+
description: "Unordered list",
|
|
37
|
+
icon: "-",
|
|
38
|
+
action: (editor) => editor.chain().focus().toggleBulletList().run(),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
title: "Numbered list",
|
|
42
|
+
description: "Ordered list",
|
|
43
|
+
icon: "1.",
|
|
44
|
+
action: (editor) => editor.chain().focus().toggleOrderedList().run(),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
title: "To-do list",
|
|
48
|
+
description: "Checklist items",
|
|
49
|
+
icon: "[]",
|
|
50
|
+
action: (editor) => editor.chain().focus().toggleTaskList().run(),
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
title: "Quote",
|
|
54
|
+
description: "Block quote",
|
|
55
|
+
icon: '"',
|
|
56
|
+
action: (editor) => editor.chain().focus().toggleBlockquote().run(),
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
title: "Code block",
|
|
60
|
+
description: "Code snippet",
|
|
61
|
+
icon: "<>",
|
|
62
|
+
action: (editor) => editor.chain().focus().toggleCodeBlock().run(),
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
title: "Divider",
|
|
66
|
+
description: "Horizontal rule",
|
|
67
|
+
icon: "-",
|
|
68
|
+
action: (editor) => editor.chain().focus().setHorizontalRule().run(),
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
title: "Table",
|
|
72
|
+
description: "Three by three table",
|
|
73
|
+
icon: "tbl",
|
|
74
|
+
action: (editor) => editor
|
|
75
|
+
.chain()
|
|
76
|
+
.focus()
|
|
77
|
+
.insertTable({ rows: 3, cols: 3, withHeaderRow: true })
|
|
78
|
+
.run(),
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
/**
|
|
82
|
+
* Build the `/image` slash command for the shared image block. Requires the
|
|
83
|
+
* editor to mount the shared image extension (`features.image`) and an
|
|
84
|
+
* {@link ImageUploadFn}; the command opens a native file picker and uploads +
|
|
85
|
+
* inserts the chosen image(s). Add it to the list an app passes to
|
|
86
|
+
* {@link SlashCommandMenu} (e.g. `[...DEFAULT_SLASH_COMMANDS, createImageSlashCommand(upload)]`).
|
|
87
|
+
*/
|
|
88
|
+
export function createImageSlashCommand(upload) {
|
|
89
|
+
return {
|
|
90
|
+
title: "Image",
|
|
91
|
+
description: "Upload an image",
|
|
92
|
+
icon: "img",
|
|
93
|
+
action: (editor) => pickAndInsertImage(editor.view, upload),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The shared "/" block-insert menu. Detects a `/query` at the caret, filters the
|
|
98
|
+
* provided command list, and renders a fixed-position picker with keyboard
|
|
99
|
+
* navigation. Extracted from the inline plan menu so apps share one
|
|
100
|
+
* implementation and only swap the command list.
|
|
101
|
+
*/
|
|
102
|
+
export function SlashCommandMenu({ editor, items = DEFAULT_SLASH_COMMANDS, }) {
|
|
103
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
104
|
+
const [query, setQuery] = useState("");
|
|
105
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
106
|
+
const [position, setPosition] = useState(null);
|
|
107
|
+
const menuRef = useRef(null);
|
|
108
|
+
const selectedItemRef = useRef(null);
|
|
109
|
+
const slashPosRef = useRef(null);
|
|
110
|
+
const filteredCommands = useMemo(() => {
|
|
111
|
+
const normalizedQuery = query.toLowerCase();
|
|
112
|
+
return items.filter((cmd) => cmd.title.toLowerCase().includes(normalizedQuery) ||
|
|
113
|
+
cmd.description.toLowerCase().includes(normalizedQuery) ||
|
|
114
|
+
cmd.searchText?.toLowerCase().includes(normalizedQuery));
|
|
115
|
+
}, [items, query]);
|
|
116
|
+
const close = useCallback(() => {
|
|
117
|
+
setIsOpen(false);
|
|
118
|
+
setQuery("");
|
|
119
|
+
slashPosRef.current = null;
|
|
120
|
+
}, []);
|
|
121
|
+
const executeCommand = useCallback((command) => {
|
|
122
|
+
if (slashPosRef.current !== null) {
|
|
123
|
+
const { from } = editor.state.selection;
|
|
124
|
+
editor
|
|
125
|
+
.chain()
|
|
126
|
+
.focus()
|
|
127
|
+
.deleteRange({ from: slashPosRef.current, to: from })
|
|
128
|
+
.run();
|
|
129
|
+
}
|
|
130
|
+
command.action(editor);
|
|
131
|
+
close();
|
|
132
|
+
}, [close, editor]);
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
const handleKeyDown = (event) => {
|
|
135
|
+
if (!isOpen)
|
|
136
|
+
return;
|
|
137
|
+
if (event.key === "ArrowDown") {
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
if (filteredCommands.length === 0)
|
|
140
|
+
return;
|
|
141
|
+
setSelectedIndex((index) => (index + 1) % filteredCommands.length);
|
|
142
|
+
}
|
|
143
|
+
else if (event.key === "ArrowUp") {
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
if (filteredCommands.length === 0)
|
|
146
|
+
return;
|
|
147
|
+
setSelectedIndex((index) => (index - 1 + filteredCommands.length) % filteredCommands.length);
|
|
148
|
+
}
|
|
149
|
+
else if (event.key === "Enter") {
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
const command = filteredCommands[selectedIndex];
|
|
152
|
+
if (command)
|
|
153
|
+
executeCommand(command);
|
|
154
|
+
}
|
|
155
|
+
else if (event.key === "Escape") {
|
|
156
|
+
close();
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
document.addEventListener("keydown", handleKeyDown, true);
|
|
160
|
+
return () => document.removeEventListener("keydown", handleKeyDown, true);
|
|
161
|
+
}, [close, executeCommand, filteredCommands, isOpen, selectedIndex]);
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (!isOpen)
|
|
164
|
+
return;
|
|
165
|
+
const menu = menuRef.current;
|
|
166
|
+
const item = selectedItemRef.current;
|
|
167
|
+
if (!menu || !item)
|
|
168
|
+
return;
|
|
169
|
+
const itemTop = item.offsetTop;
|
|
170
|
+
const itemBottom = itemTop + item.offsetHeight;
|
|
171
|
+
const visibleTop = menu.scrollTop;
|
|
172
|
+
const visibleBottom = visibleTop + menu.clientHeight;
|
|
173
|
+
if (itemTop < visibleTop) {
|
|
174
|
+
menu.scrollTop = itemTop;
|
|
175
|
+
}
|
|
176
|
+
else if (itemBottom > visibleBottom) {
|
|
177
|
+
menu.scrollTop = itemBottom - menu.clientHeight;
|
|
178
|
+
}
|
|
179
|
+
}, [filteredCommands.length, isOpen, selectedIndex]);
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
const handleTransaction = () => {
|
|
182
|
+
const { state } = editor;
|
|
183
|
+
const { from } = state.selection;
|
|
184
|
+
const textBefore = state.doc.textBetween(Math.max(0, from - 32), from, "\n");
|
|
185
|
+
const slashMatch = textBefore.match(/\/([a-zA-Z0-9 ]*)$/);
|
|
186
|
+
if (!slashMatch) {
|
|
187
|
+
if (isOpen)
|
|
188
|
+
close();
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const slashStart = from - slashMatch[0].length;
|
|
192
|
+
slashPosRef.current = slashStart;
|
|
193
|
+
setQuery(slashMatch[1]);
|
|
194
|
+
setSelectedIndex(0);
|
|
195
|
+
const coords = editor.view.coordsAtPos(from);
|
|
196
|
+
const menuHeight = 320;
|
|
197
|
+
const spaceBelow = window.innerHeight - coords.bottom;
|
|
198
|
+
const flipUp = spaceBelow < menuHeight && coords.top > menuHeight;
|
|
199
|
+
setPosition({
|
|
200
|
+
top: flipUp ? coords.top : coords.bottom + 4,
|
|
201
|
+
left: Math.min(coords.left, window.innerWidth - 250),
|
|
202
|
+
flipUp,
|
|
203
|
+
});
|
|
204
|
+
setIsOpen(true);
|
|
205
|
+
};
|
|
206
|
+
editor.on("transaction", handleTransaction);
|
|
207
|
+
return () => {
|
|
208
|
+
editor.off("transaction", handleTransaction);
|
|
209
|
+
};
|
|
210
|
+
}, [close, editor, isOpen]);
|
|
211
|
+
if (!isOpen || !position || filteredCommands.length === 0)
|
|
212
|
+
return null;
|
|
213
|
+
return (_jsxs("div", { ref: menuRef, className: "an-rich-md-slash-menu", style: {
|
|
214
|
+
position: "fixed",
|
|
215
|
+
...(position.flipUp
|
|
216
|
+
? { bottom: window.innerHeight - position.top + 4 }
|
|
217
|
+
: { top: position.top }),
|
|
218
|
+
left: position.left,
|
|
219
|
+
}, "data-plan-interactive": true, children: [_jsx("div", { className: "an-rich-md-slash-heading", children: "Blocks" }), filteredCommands.map((command, index) => (_jsxs("button", { ref: index === selectedIndex ? selectedItemRef : undefined, type: "button", className: cn("an-rich-md-slash-item", index === selectedIndex && "an-rich-md-slash-item--active"), onMouseEnter: () => setSelectedIndex(index), onMouseDown: (event) => event.preventDefault(), onClick: () => executeCommand(command), children: [_jsx("span", { className: "an-rich-md-slash-icon", children: command.icon }), _jsxs("span", { className: "an-rich-md-slash-copy", children: [_jsx("span", { className: "an-rich-md-slash-title", children: command.title }), _jsx("span", { className: "an-rich-md-slash-description", children: command.description })] })] }, command.title)))] }));
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=SlashCommandMenu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SlashCommandMenu.js","sourceRoot":"","sources":["../../src/editor/SlashCommandMenu.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GAET,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAsB,MAAM,qBAAqB,CAAC;AAgB7E;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAuB;IACxD;QACE,KAAK,EAAE,MAAM;QACb,WAAW,EAAE,kBAAkB;QAC/B,IAAI,EAAE,GAAG;QACT,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE;KAChE;IACD;QACE,KAAK,EAAE,WAAW;QAClB,WAAW,EAAE,eAAe;QAC5B,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CACjB,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,C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C,KAAK,CAAC,cAAc,EAAE,EAC9C,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,aAEtC,eAAM,SAAS,EAAC,uBAAuB,YAAE,OAAO,CAAC,IAAI,GAAQ,EAC7D,gBAAM,SAAS,EAAC,uBAAuB,aACrC,eAAM,SAAS,EAAC,wBAAwB,YAAE,OAAO,CAAC,KAAK,GAAQ,EAC/D,eAAM,SAAS,EAAC,8BAA8B,YAC3C,OAAO,CAAC,WAAW,GACf,IACF,KAjBF,OAAO,CAAC,KAAK,CAkBX,CACV,CAAC,IACE,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disableHistory.spec.d.ts","sourceRoot":"","sources":["../../src/editor/disableHistory.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { Editor } from "@tiptap/core";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { createSharedEditorExtensions } from "./extensions.js";
|
|
5
|
+
/**
|
|
6
|
+
* The `disableHistory` lever turns OFF StarterKit's prosemirror-history for a
|
|
7
|
+
* controlled (non-collab) editor whose host owns its own undo authority — the
|
|
8
|
+
* plan editor, whose authoritative `blocks[]` tree holds block data the
|
|
9
|
+
* ProseMirror doc never stores, so PM history can't be the undo authority.
|
|
10
|
+
*
|
|
11
|
+
* Contract:
|
|
12
|
+
* - default (history ON): cmd+z reverts a text edit (every existing embedder).
|
|
13
|
+
* - disableHistory: true: the Mod-z keymap is not bound, so cmd+z is NOT
|
|
14
|
+
* handled and the edit is NOT reverted — leaving the host's own cmd+z
|
|
15
|
+
* handler (a capture-phase listener, in the plan editor) as the sole undo.
|
|
16
|
+
*/
|
|
17
|
+
function makeEditor(disableHistory) {
|
|
18
|
+
const element = document.createElement("div");
|
|
19
|
+
document.body.appendChild(element);
|
|
20
|
+
return new Editor({
|
|
21
|
+
element,
|
|
22
|
+
extensions: createSharedEditorExtensions({ disableHistory }),
|
|
23
|
+
// Seed via a PM JSON doc (not an HTML/markdown string) so the baseline is a
|
|
24
|
+
// real paragraph "hello" and the first undoable step is the edit below.
|
|
25
|
+
content: {
|
|
26
|
+
type: "doc",
|
|
27
|
+
content: [
|
|
28
|
+
{ type: "paragraph", content: [{ type: "text", text: "hello" }] },
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function typeAtEnd(editor, text) {
|
|
34
|
+
editor.chain().focus("end").insertContent(text).run();
|
|
35
|
+
}
|
|
36
|
+
function pressModZ(editor) {
|
|
37
|
+
const isMac = typeof navigator !== "undefined" &&
|
|
38
|
+
/Mac|iP(hone|ad|od)/.test(navigator.platform || "");
|
|
39
|
+
const event = new KeyboardEvent("keydown", {
|
|
40
|
+
key: "z",
|
|
41
|
+
code: "KeyZ",
|
|
42
|
+
keyCode: 90,
|
|
43
|
+
which: 90,
|
|
44
|
+
metaKey: isMac,
|
|
45
|
+
ctrlKey: !isMac,
|
|
46
|
+
bubbles: true,
|
|
47
|
+
cancelable: true,
|
|
48
|
+
});
|
|
49
|
+
return (editor.view.someProp("handleKeyDown", (f) => f(editor.view, event)) ?? false);
|
|
50
|
+
}
|
|
51
|
+
describe("disableHistory editor lever", () => {
|
|
52
|
+
it("default (history ON): cmd+z reverts a text edit", () => {
|
|
53
|
+
const editor = makeEditor(false);
|
|
54
|
+
typeAtEnd(editor, " world");
|
|
55
|
+
expect(editor.getText()).toBe("hello world");
|
|
56
|
+
const handled = pressModZ(editor);
|
|
57
|
+
expect(handled).toBe(true);
|
|
58
|
+
expect(editor.getText()).toBe("hello");
|
|
59
|
+
editor.destroy();
|
|
60
|
+
});
|
|
61
|
+
it("disableHistory: true — cmd+z is NOT handled and the edit is NOT reverted", () => {
|
|
62
|
+
const editor = makeEditor(true);
|
|
63
|
+
typeAtEnd(editor, " world");
|
|
64
|
+
expect(editor.getText()).toBe("hello world");
|
|
65
|
+
const handled = pressModZ(editor);
|
|
66
|
+
// No history plugin → no Mod-z binding → the keymap does not consume it,
|
|
67
|
+
// and the document is unchanged. The host's own undo authority handles cmd+z.
|
|
68
|
+
expect(handled).toBe(false);
|
|
69
|
+
expect(editor.getText()).toBe("hello world");
|
|
70
|
+
editor.destroy();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=disableHistory.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disableHistory.spec.js","sourceRoot":"","sources":["../../src/editor/disableHistory.spec.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAE/D;;;;;;;;;;;GAWG;AAEH,SAAS,UAAU,CAAC,cAAuB;IACzC,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC9C,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACnC,OAAO,IAAI,MAAM,CAAC;QAChB,OAAO;QACP,UAAU,EAAE,4BAA4B,CAAC,EAAE,cAAc,EAAE,CAAC;QAC5D,4EAA4E;QAC5E,wEAAwE;QACxE,OAAO,EAAE;YACP,IAAI,EAAE,KAAK;YACX,OAAO,EAAE;gBACP,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE;aAClE;SACF;KACF,CAAC,CAAC;AACL,CAAC;AAED,SAAS,SAAS,CAAC,MAAc,EAAE,IAAY;IAC7C,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,aAAa,C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E,GAAG,EAAE;QAClF,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QAChC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC5B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAE7C,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QAClC,yEAAyE;QACzE,8EAA8E;QAC9E,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC7C,MAAM,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { Extension, Node, Mark } from "@tiptap/core";
|
|
2
|
+
import type { StarterKitOptions } from "@tiptap/starter-kit";
|
|
3
|
+
import { Markdown } from "tiptap-markdown";
|
|
4
|
+
import type { Awareness } from "y-protocols/awareness";
|
|
5
|
+
import type { Doc as YDoc } from "yjs";
|
|
6
|
+
import { type ImageUploadFn } from "./ImageExtension.js";
|
|
7
|
+
/**
|
|
8
|
+
* Markdown dialect the editor parses/serializes.
|
|
9
|
+
*
|
|
10
|
+
* - `gfm` — GitHub-Flavored Markdown. No raw HTML passthrough. The byte-stable
|
|
11
|
+
* serialization used by Plans (see RichMarkdownEditor.roundtrip.spec.ts).
|
|
12
|
+
* - `nfm` — the Notion-Flavored Markdown superset used by the Content editor,
|
|
13
|
+
* which opts into inline HTML so Notion-specific blocks round-trip.
|
|
14
|
+
*/
|
|
15
|
+
export type RichMarkdownDialect = "gfm" | "nfm";
|
|
16
|
+
/**
|
|
17
|
+
* Editor preset. Schema-neutral today (both presets share the base schema),
|
|
18
|
+
* but threaded through so an app can branch schema/behavior per preset without
|
|
19
|
+
* a new factory. The collab/markdown wiring is preset-independent.
|
|
20
|
+
*/
|
|
21
|
+
export type RichMarkdownEditorPreset = "plan" | "content";
|
|
22
|
+
/** User info used to label this client's collaborative cursor. */
|
|
23
|
+
export interface RichMarkdownCollabUser {
|
|
24
|
+
name: string;
|
|
25
|
+
color: string;
|
|
26
|
+
email?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Optional collaborative-editing inputs for the shared editor. */
|
|
29
|
+
export interface SharedEditorCollab {
|
|
30
|
+
/**
|
|
31
|
+
* Yjs document for collaborative editing. When present the editor binds the
|
|
32
|
+
* shared {@link Collaboration} (+ {@link CollaborationCaret} when awareness
|
|
33
|
+
* is set) extensions and StarterKit's built-in undo/redo is disabled (Yjs
|
|
34
|
+
* owns history). When absent the editor is a controlled `value`/`onChange`
|
|
35
|
+
* editor.
|
|
36
|
+
*/
|
|
37
|
+
ydoc?: YDoc | null;
|
|
38
|
+
/** Shared awareness instance for live multi-user cursors. */
|
|
39
|
+
awareness?: Awareness | null;
|
|
40
|
+
/** Current user info for the collaborative cursor label. */
|
|
41
|
+
user?: RichMarkdownCollabUser | null;
|
|
42
|
+
}
|
|
43
|
+
/** Toggle the optional base extensions on/off per app. All default to `true`. */
|
|
44
|
+
export interface SharedEditorFeatures {
|
|
45
|
+
/** GFM pipe tables (Table + TableRow + TableHeader + TableCell). */
|
|
46
|
+
tables?: boolean;
|
|
47
|
+
/** Task / checklist lists (TaskList + TaskItem). */
|
|
48
|
+
tasks?: boolean;
|
|
49
|
+
/** Inline links (the `Link` mark). When off, links fall back to plain text. */
|
|
50
|
+
link?: boolean;
|
|
51
|
+
/** Fenced code blocks. Disabling lets an app inject its own code-block node. */
|
|
52
|
+
codeBlock?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* The built-in {@link Placeholder} extension. Default `true`. Apps that need a
|
|
55
|
+
* bespoke placeholder resolver (per-node-type labels, ancestor-aware text)
|
|
56
|
+
* disable this and supply their own Placeholder via `extraExtensions`.
|
|
57
|
+
*/
|
|
58
|
+
placeholder?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The built-in dialect-keyed {@link Markdown} serializer. Default `true`.
|
|
61
|
+
* Apps with a custom serializer (e.g. Content's NFM converter, which does NOT
|
|
62
|
+
* round-trip through tiptap-markdown's storage) disable this and own the
|
|
63
|
+
* serialize/parse pipeline themselves. The Markdown extension is still added
|
|
64
|
+
* so paste/clipboard transforms work — disable it only when supplying your own
|
|
65
|
+
* Markdown configuration via the {@link CreateSharedEditorExtensionsOptions.markdown}
|
|
66
|
+
* option instead.
|
|
67
|
+
*/
|
|
68
|
+
markdown?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* The shared block-level image node (`@tiptap/extension-image`). Default
|
|
71
|
+
* `false` so existing embedders are unchanged. When `true`, images
|
|
72
|
+
* serialize to GFM `` (source-syncable) and — when an
|
|
73
|
+
* {@link CreateSharedEditorExtensionsOptions.onImageUpload} function is
|
|
74
|
+
* supplied — paste / drop of local image files uploads through it. Content
|
|
75
|
+
* leaves this off and injects its own richer image node via
|
|
76
|
+
* `extraExtensions`, so the two never collide.
|
|
77
|
+
*/
|
|
78
|
+
image?: boolean;
|
|
79
|
+
}
|
|
80
|
+
export interface CreateSharedEditorExtensionsOptions {
|
|
81
|
+
/** Markdown dialect; selects the keyed {@link Markdown} config. */
|
|
82
|
+
dialect?: RichMarkdownDialect;
|
|
83
|
+
/** Preset hook (schema-neutral today). */
|
|
84
|
+
preset?: RichMarkdownEditorPreset;
|
|
85
|
+
/** Empty-block placeholder text (headings get their own labels). */
|
|
86
|
+
placeholder?: string;
|
|
87
|
+
/** Toggle individual base extensions. */
|
|
88
|
+
features?: SharedEditorFeatures;
|
|
89
|
+
/**
|
|
90
|
+
* Extra StarterKit options merged over the shared defaults. Lets an app turn
|
|
91
|
+
* off StarterKit nodes it replaces (Content swaps in its own paragraph /
|
|
92
|
+
* blockquote / code block) or pass a custom dropcursor, while still sharing
|
|
93
|
+
* the rest of the StarterKit base + the collab undo/redo gating. The shared
|
|
94
|
+
* defaults (`heading` levels 1-4, `link: false`, the default dropcursor, and
|
|
95
|
+
* `undoRedo: false` in collab mode) are applied first and can be overridden
|
|
96
|
+
* key-by-key here.
|
|
97
|
+
*/
|
|
98
|
+
starterKit?: Partial<StarterKitOptions>;
|
|
99
|
+
/**
|
|
100
|
+
* Custom {@link Markdown} configuration. Replaces the dialect-keyed config from
|
|
101
|
+
* {@link MARKDOWN_DIALECT_CONFIG} when provided. Only used when
|
|
102
|
+
* `features.markdown !== false`; apps that own the whole markdown pipeline (no
|
|
103
|
+
* tiptap-markdown serialization at all) should set `features.markdown: false`
|
|
104
|
+
* and add their own configured Markdown extension via `extraExtensions`.
|
|
105
|
+
*/
|
|
106
|
+
markdown?: Parameters<typeof Markdown.configure>[0];
|
|
107
|
+
/**
|
|
108
|
+
* App-specific extensions (Notion nodes, media, drag handles, comment
|
|
109
|
+
* anchors, etc.) appended LAST so they bind over the shared base schema and
|
|
110
|
+
* the optional Collaboration extensions still mount after them.
|
|
111
|
+
*/
|
|
112
|
+
extraExtensions?: Array<Extension | Node | Mark>;
|
|
113
|
+
/** Optional collaborative-editing wiring. */
|
|
114
|
+
collab?: SharedEditorCollab | null;
|
|
115
|
+
/**
|
|
116
|
+
* Disable StarterKit's built-in undo/redo (prosemirror-history) for a
|
|
117
|
+
* controlled (non-collab) editor whose host owns its own undo authority.
|
|
118
|
+
* Default `false`. When a `collab.ydoc` is present, undo/redo is ALWAYS
|
|
119
|
+
* disabled regardless of this flag (Yjs owns history); this flag is the
|
|
120
|
+
* non-collab equivalent. The plan editor sets it so a single app-level undo
|
|
121
|
+
* stack (over the authoritative `blocks[]` tree, which includes block data
|
|
122
|
+
* the ProseMirror doc never stores) is the sole cmd+z authority — otherwise
|
|
123
|
+
* PM history and the app stack would both fire, and PM history can't see
|
|
124
|
+
* block-option edits at all.
|
|
125
|
+
*/
|
|
126
|
+
disableHistory?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Injectable image uploader for the shared image block. Only used when
|
|
129
|
+
* `features.image` is on. Turns a picked / pasted / dropped image File into a
|
|
130
|
+
* hosted `{ src, alt? }`. Plans pass `uploadEditorImage` (the framework
|
|
131
|
+
* `upload-image` action). When omitted, the image block still renders and
|
|
132
|
+
* round-trips `` markdown but cannot ingest local files.
|
|
133
|
+
*/
|
|
134
|
+
onImageUpload?: ImageUploadFn | null;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* tiptap-markdown configuration, keyed by dialect. This is the single source of
|
|
138
|
+
* truth for how each dialect parses/serializes markdown so the editor component
|
|
139
|
+
* and the round-trip fidelity test can never drift apart.
|
|
140
|
+
*
|
|
141
|
+
* tiptap-markdown re-serializes the whole document on every edit, so the goal
|
|
142
|
+
* for GFM is `serialize(parse(markdown)) === markdown` for the markdown plans
|
|
143
|
+
* actually contain. We deliberately keep tiptap-markdown's own defaults
|
|
144
|
+
* (`bulletListMarker: "-"`, `tightLists: true`, `linkify: false`,
|
|
145
|
+
* `breaks: false`) because those produce the most byte-stable GFM. See
|
|
146
|
+
* RichMarkdownEditor.roundtrip.spec.ts for the pinned corpus.
|
|
147
|
+
*
|
|
148
|
+
* NFM (Content) opts into inline HTML passthrough (`html: true`) so
|
|
149
|
+
* Notion-specific blocks survive a markdown round-trip; the rest mirrors the
|
|
150
|
+
* Content editor's existing `Markdown.configure` call.
|
|
151
|
+
*/
|
|
152
|
+
export declare const MARKDOWN_DIALECT_CONFIG: Record<RichMarkdownDialect, Parameters<typeof Markdown.configure>[0]>;
|
|
153
|
+
/**
|
|
154
|
+
* The ONE editor extension factory shared by every embedder (Plans today,
|
|
155
|
+
* Content next). It assembles the base Tiptap schema (StarterKit + Placeholder
|
|
156
|
+
* + Link + tasks + tables + code block), the dialect-keyed {@link Markdown}
|
|
157
|
+
* serializer, the optional Collaboration stack, and finally any app-specific
|
|
158
|
+
* `extraExtensions`.
|
|
159
|
+
*
|
|
160
|
+
* Ordering matters:
|
|
161
|
+
* 1. Base schema (StarterKit first so its nodes/marks register; `starterKit`
|
|
162
|
+
* overrides let an app disable replaced nodes / swap the dropcursor).
|
|
163
|
+
* 2. dialect-keyed Markdown serializer (suppressible via `features.markdown`
|
|
164
|
+
* for apps that own the whole serialize/parse pipeline, e.g. Content's NFM).
|
|
165
|
+
* 3. `extraExtensions` (Notion/media/etc.) — appended before Collaboration so
|
|
166
|
+
* apps can extend the schema and Collaboration still binds over the full
|
|
167
|
+
* schema.
|
|
168
|
+
* 4. Collaboration (+ CollaborationCaret) LAST so they bind over everything.
|
|
169
|
+
*
|
|
170
|
+
* Content (the NFM editor) drives this factory with `features.placeholder` and
|
|
171
|
+
* `features.markdown` off, `features.tasks/tables/link` off where it ships its
|
|
172
|
+
* own, a `starterKit` override disabling paragraph/blockquote/codeBlock, and all
|
|
173
|
+
* Notion/media/fidelity nodes + its own Markdown(NFM)/Placeholder via
|
|
174
|
+
* `extraExtensions` — so it shares the StarterKit base + the collab wiring while
|
|
175
|
+
* owning its byte-identical NFM serializer.
|
|
176
|
+
*/
|
|
177
|
+
export declare function createSharedEditorExtensions({ dialect, preset: _preset, placeholder, features, starterKit, markdown, extraExtensions, collab, onImageUpload, disableHistory, }?: CreateSharedEditorExtensionsOptions): Array<Extension | Node | Mark>;
|
|
178
|
+
//# sourceMappingURL=extensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../../src/editor/extensions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAY1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAY7D,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAsB3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,GAAG,IAAI,IAAI,EAAE,MAAM,KAAK,CAAC;AAGv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