@agent-native/toolkit 0.6.0 → 0.7.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 -1
- package/dist/chat-history/ChatHistoryList.d.ts +103 -0
- package/dist/chat-history/ChatHistoryList.d.ts.map +1 -0
- package/dist/chat-history/ChatHistoryList.js +109 -0
- package/dist/chat-history/ChatHistoryList.js.map +1 -0
- package/dist/chat-history/ChatHistoryList.spec.d.ts +2 -0
- package/dist/chat-history/ChatHistoryList.spec.d.ts.map +1 -0
- package/dist/chat-history/ChatHistoryList.spec.js +283 -0
- package/dist/chat-history/ChatHistoryList.spec.js.map +1 -0
- package/dist/chat-history/index.d.ts +2 -0
- package/dist/chat-history/index.d.ts.map +1 -0
- package/dist/chat-history/index.js +2 -0
- package/dist/chat-history/index.js.map +1 -0
- package/dist/chat-history.css +314 -0
- package/package.json +17 -1
- package/src/app-shell/header-actions.tsx +84 -0
- package/src/app-shell/index.ts +1 -0
- package/src/chat-history/ChatHistoryList.spec.tsx +453 -0
- package/src/chat-history/ChatHistoryList.tsx +469 -0
- package/src/chat-history/index.ts +7 -0
- package/src/chat-history.css +314 -0
- package/src/collab-ui/AgentPresenceChip.tsx +69 -0
- package/src/collab-ui/LiveCursorOverlay.tsx +241 -0
- package/src/collab-ui/PresenceBar.tsx +346 -0
- package/src/collab-ui/RecentEditHighlights.tsx +225 -0
- package/src/collab-ui/RemoteSelectionRings.tsx +227 -0
- package/src/collab-ui/agent-identity.ts +16 -0
- package/src/collab-ui/index.ts +39 -0
- package/src/collab-ui/lead-client.ts +32 -0
- package/src/collab-ui/types.spec.ts +18 -0
- package/src/collab-ui/types.ts +96 -0
- package/src/composer/AgentComposerFrame.tsx +59 -0
- package/src/composer/ComposerPlusMenu.tsx +983 -0
- package/src/composer/MentionPopover.tsx +412 -0
- package/src/composer/PastedTextChip.tsx +150 -0
- package/src/composer/PromptComposer.spec.ts +73 -0
- package/src/composer/PromptComposer.tsx +718 -0
- package/src/composer/RealtimeVoiceMode.spec.tsx +771 -0
- package/src/composer/RealtimeVoiceMode.tsx +856 -0
- package/src/composer/TiptapComposer.spec.ts +390 -0
- package/src/composer/TiptapComposer.tsx +2936 -0
- package/src/composer/VoiceButton.spec.ts +33 -0
- package/src/composer/VoiceButton.tsx +255 -0
- package/src/composer/asset-picker-url.spec.ts +56 -0
- package/src/composer/asset-picker-url.ts +80 -0
- package/src/composer/attachment-accept.spec.ts +22 -0
- package/src/composer/attachment-accept.ts +71 -0
- package/src/composer/draft-key.spec.ts +19 -0
- package/src/composer/draft-key.ts +7 -0
- package/src/composer/extensions/FileReference.tsx +55 -0
- package/src/composer/extensions/MentionReference.tsx +93 -0
- package/src/composer/extensions/SkillReference.tsx +56 -0
- package/src/composer/index.ts +79 -0
- package/src/composer/pasted-text.spec.ts +162 -0
- package/src/composer/pasted-text.ts +160 -0
- package/src/composer/prompt-attachments.spec.ts +80 -0
- package/src/composer/prompt-attachments.ts +93 -0
- package/src/composer/realtime-voice-audio-level.spec.ts +32 -0
- package/src/composer/realtime-voice-audio-level.ts +64 -0
- package/src/composer/realtime-voice-transcript.spec.ts +95 -0
- package/src/composer/realtime-voice-transcript.ts +134 -0
- package/src/composer/runtime-adapters.tsx +343 -0
- package/src/composer/types.ts +66 -0
- package/src/composer/use-file-search.ts +64 -0
- package/src/composer/use-mention-search.ts +90 -0
- package/src/composer/use-skills.ts +45 -0
- package/src/composer/useRealtimeVoiceMode.spec.ts +818 -0
- package/src/composer/useRealtimeVoiceMode.tsx +2117 -0
- package/src/composer/useVoiceDictation.spec.ts +45 -0
- package/src/composer/useVoiceDictation.ts +1191 -0
- package/src/context-ui/ContextMeter.tsx +101 -0
- package/src/context-ui/ContextSegmentRow.tsx +184 -0
- package/src/context-ui/ContextTreemap.tsx +125 -0
- package/src/context-ui/ContextXRayPanel.tsx +377 -0
- package/src/context-ui/format.ts +42 -0
- package/src/context-ui/index.ts +15 -0
- package/src/context-ui/types.ts +43 -0
- package/src/design-tweaks/index.ts +1 -0
- package/src/design-tweaks/visual-style-controls.tsx +1084 -0
- package/src/editor/BubbleToolbar.tsx +253 -0
- package/src/editor/CodeBlockNode.tsx +254 -0
- package/src/editor/DragHandle.spec.ts +588 -0
- package/src/editor/DragHandle.ts +1437 -0
- package/src/editor/ImageExtension.roundtrip.spec.ts +117 -0
- package/src/editor/ImageExtension.ts +306 -0
- package/src/editor/RegistryBlockContext.tsx +107 -0
- package/src/editor/RegistryBlockNode.spec.ts +279 -0
- package/src/editor/RegistryBlockNode.tsx +652 -0
- package/src/editor/RichMarkdownEditor.collab.spec.ts +79 -0
- package/src/editor/RichMarkdownEditor.roundtrip.spec.ts +226 -0
- package/src/editor/RichMarkdownEditor.tsx +81 -0
- package/src/editor/RunId.ts +61 -0
- package/src/editor/SharedRichEditor.tsx +321 -0
- package/src/editor/SlashCommandMenu.tsx +310 -0
- package/src/editor/disableHistory.spec.ts +85 -0
- package/src/editor/extensions.ts +402 -0
- package/src/editor/gfmDoc.spec.ts +230 -0
- package/src/editor/gfmDoc.ts +92 -0
- package/src/editor/index.ts +93 -0
- package/src/editor/registrySlashCommands.ts +131 -0
- package/src/editor/structuralReorderUndo.spec.ts +144 -0
- package/src/editor/surgical-apply.spec.ts +279 -0
- package/src/editor/surgical-apply.ts +192 -0
- package/src/editor/useCollabReconcile.concurrent.spec.ts +422 -0
- package/src/editor/useCollabReconcile.idempotent.spec.ts +324 -0
- package/src/editor/useCollabReconcile.ts +589 -0
- package/src/editor.css +510 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/use-mobile.tsx +21 -0
- package/src/hooks/use-toast.ts +188 -0
- package/src/index.ts +8 -0
- package/src/onboarding/index.ts +1 -0
- package/src/provider.tsx +47 -0
- package/src/sharing/VisibilityBadge.spec.ts +96 -0
- package/src/sharing/VisibilityBadge.tsx +37 -0
- package/src/sharing/index.ts +4 -0
- package/src/styles.css +21 -0
- package/src/ui/accordion.tsx +56 -0
- package/src/ui/alert-dialog.tsx +141 -0
- package/src/ui/alert.tsx +59 -0
- package/src/ui/aspect-ratio.tsx +5 -0
- package/src/ui/avatar.tsx +48 -0
- package/src/ui/badge.tsx +37 -0
- package/src/ui/breadcrumb.tsx +115 -0
- package/src/ui/button.tsx +78 -0
- package/src/ui/calendar.tsx +214 -0
- package/src/ui/card.tsx +86 -0
- package/src/ui/carousel.tsx +260 -0
- package/src/ui/chart.tsx +375 -0
- package/src/ui/checkbox.tsx +28 -0
- package/src/ui/collapsible.tsx +9 -0
- package/src/ui/command.spec.tsx +51 -0
- package/src/ui/command.tsx +174 -0
- package/src/ui/context-menu.tsx +202 -0
- package/src/ui/date-picker.tsx +64 -0
- package/src/ui/dialog.spec.tsx +43 -0
- package/src/ui/dialog.tsx +146 -0
- package/src/ui/drawer.tsx +126 -0
- package/src/ui/dropdown-menu.tsx +218 -0
- package/src/ui/form.tsx +177 -0
- package/src/ui/hover-card.tsx +27 -0
- package/src/ui/index.ts +52 -0
- package/src/ui/input-otp.tsx +69 -0
- package/src/ui/input.tsx +22 -0
- package/src/ui/label.tsx +24 -0
- package/src/ui/logo.tsx +36 -0
- package/src/ui/menubar.tsx +235 -0
- package/src/ui/navigation-menu.tsx +128 -0
- package/src/ui/pagination.tsx +121 -0
- package/src/ui/popover.tsx +44 -0
- package/src/ui/progress.tsx +26 -0
- package/src/ui/radio-group.tsx +42 -0
- package/src/ui/resizable.tsx +43 -0
- package/src/ui/scroll-area.tsx +46 -0
- package/src/ui/select.tsx +158 -0
- package/src/ui/separator.tsx +29 -0
- package/src/ui/sheet.tsx +160 -0
- package/src/ui/sidebar.tsx +777 -0
- package/src/ui/skeleton.tsx +18 -0
- package/src/ui/slider.tsx +26 -0
- package/src/ui/sonner.tsx +58 -0
- package/src/ui/spinner.tsx +17 -0
- package/src/ui/switch.tsx +27 -0
- package/src/ui/table.tsx +117 -0
- package/src/ui/tabs.tsx +53 -0
- package/src/ui/textarea.tsx +23 -0
- package/src/ui/toast.tsx +127 -0
- package/src/ui/toaster.tsx +33 -0
- package/src/ui/toggle-group.tsx +59 -0
- package/src/ui/toggle.tsx +43 -0
- package/src/ui/tooltip.tsx +53 -0
- package/src/ui/use-toast.ts +3 -0
- package/src/utils.ts +8 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { Awareness } from "y-protocols/awareness";
|
|
5
|
+
import * as Y from "yjs";
|
|
6
|
+
|
|
7
|
+
import { createRichMarkdownExtensions } from "./RichMarkdownEditor.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The optional collaboration wiring on the shared rich-markdown editor must be
|
|
11
|
+
* strictly additive: with no `ydoc`, the editor behaves exactly as the existing
|
|
12
|
+
* controlled single-user editor (no Collaboration extensions, undo/redo on);
|
|
13
|
+
* with a `ydoc`, it binds Collaboration (+ a CollaborationCaret when awareness
|
|
14
|
+
* is present) and disables StarterKit's undo/redo so Yjs owns history.
|
|
15
|
+
*/
|
|
16
|
+
function extensionNames(
|
|
17
|
+
opts?: Parameters<typeof createRichMarkdownExtensions>[0],
|
|
18
|
+
): string[] {
|
|
19
|
+
return createRichMarkdownExtensions(opts).map((ext) => ext.name);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe("createRichMarkdownExtensions collaboration wiring", () => {
|
|
23
|
+
it("adds no collaboration extensions when ydoc is absent", () => {
|
|
24
|
+
const names = extensionNames();
|
|
25
|
+
expect(names).not.toContain("collaboration");
|
|
26
|
+
expect(names).not.toContain("collaborationCaret");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("adds Collaboration only when a ydoc is provided", () => {
|
|
30
|
+
const ydoc = new Y.Doc();
|
|
31
|
+
try {
|
|
32
|
+
const names = extensionNames({ ydoc });
|
|
33
|
+
expect(names).toContain("collaboration");
|
|
34
|
+
// No awareness → no caret extension, but core collab still binds.
|
|
35
|
+
expect(names).not.toContain("collaborationCaret");
|
|
36
|
+
} finally {
|
|
37
|
+
ydoc.destroy();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("adds CollaborationCaret when ydoc and awareness are both provided", () => {
|
|
42
|
+
const ydoc = new Y.Doc();
|
|
43
|
+
const awareness = new Awareness(ydoc);
|
|
44
|
+
try {
|
|
45
|
+
const names = extensionNames({
|
|
46
|
+
ydoc,
|
|
47
|
+
awareness,
|
|
48
|
+
user: { name: "Ada", color: "#60a5fa", email: "ada@example.com" },
|
|
49
|
+
});
|
|
50
|
+
expect(names).toContain("collaboration");
|
|
51
|
+
expect(names).toContain("collaborationCaret");
|
|
52
|
+
} finally {
|
|
53
|
+
awareness.destroy();
|
|
54
|
+
ydoc.destroy();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("disables StarterKit undo/redo only in collab mode", () => {
|
|
59
|
+
const findStarterKit = (
|
|
60
|
+
opts?: Parameters<typeof createRichMarkdownExtensions>[0],
|
|
61
|
+
) =>
|
|
62
|
+
createRichMarkdownExtensions(opts).find(
|
|
63
|
+
(ext) => ext.name === "starterKit",
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const standalone = findStarterKit();
|
|
67
|
+
expect((standalone?.options as { undoRedo?: unknown })?.undoRedo).toBe(
|
|
68
|
+
undefined,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const ydoc = new Y.Doc();
|
|
72
|
+
try {
|
|
73
|
+
const collab = findStarterKit({ ydoc });
|
|
74
|
+
expect((collab?.options as { undoRedo?: unknown })?.undoRedo).toBe(false);
|
|
75
|
+
} finally {
|
|
76
|
+
ydoc.destroy();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { Editor } from "@tiptap/core";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
import { createRichMarkdownExtensions } from "./RichMarkdownEditor.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Round-trip fidelity for the Plan rich-text editor.
|
|
10
|
+
*
|
|
11
|
+
* tiptap-markdown re-serializes the ENTIRE document on every edit. If
|
|
12
|
+
* `serialize(parse(markdown)) !== markdown` for the markdown that plans
|
|
13
|
+
* actually contain, then the FIRST edit of an existing block emits a fully
|
|
14
|
+
* normalized version of text the user never touched — a noisy one-time git
|
|
15
|
+
* diff plus an update-rich-text write that rewrites untouched prose.
|
|
16
|
+
*
|
|
17
|
+
* This suite mounts an `Editor` from the SAME extension factory the component
|
|
18
|
+
* uses ({@link createRichMarkdownExtensions}) so the test and the component can
|
|
19
|
+
* never disagree about the dialect, then pins the round-trip output for a
|
|
20
|
+
* representative plan corpus. Cases fall into two buckets:
|
|
21
|
+
*
|
|
22
|
+
* - byte-stable: `roundTrip(x) === x`. Asserted via `expectStable`.
|
|
23
|
+
* - pinned-lossy: tiptap-markdown 0.9.0 normalizes the input in a way that
|
|
24
|
+
* CANNOT be removed through the public `Markdown.configure` surface
|
|
25
|
+
* (the relevant internals — prosemirror-markdown's `em` serializer and the
|
|
26
|
+
* non-exported `MarkdownTightLists` extension — are not configurable). We
|
|
27
|
+
* are forbidden from reformatting/post-processing stored markdown to chase
|
|
28
|
+
* stability, so these are pinned to their ACTUAL normalized output via
|
|
29
|
+
* `expectNormalizesTo`. That keeps each normalization visible and
|
|
30
|
+
* regression-guarded instead of silently churning.
|
|
31
|
+
*
|
|
32
|
+
* The only lever we are allowed to pull is the tiptap-markdown
|
|
33
|
+
* `Markdown.configure` options in the shared factory. The current config
|
|
34
|
+
* (`bulletListMarker: "-"`, `tightLists: true`, `linkify: false`,
|
|
35
|
+
* `breaks: false`) already minimizes normalization for everything below; the
|
|
36
|
+
* remaining lossy cases are inherent to the library at this version.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
function roundTrip(markdown: string): string {
|
|
40
|
+
const editor = new Editor({
|
|
41
|
+
element: document.createElement("div"),
|
|
42
|
+
extensions: createRichMarkdownExtensions({ dialect: "gfm" }),
|
|
43
|
+
content: markdown,
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
const storage = editor.storage as unknown as {
|
|
47
|
+
markdown?: { getMarkdown?: () => string };
|
|
48
|
+
};
|
|
49
|
+
return storage.markdown?.getMarkdown?.() ?? "";
|
|
50
|
+
} finally {
|
|
51
|
+
editor.destroy();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Asserts the markdown survives parse→serialize unchanged (byte-stable). */
|
|
56
|
+
function expectStable(markdown: string): void {
|
|
57
|
+
expect(roundTrip(markdown)).toBe(markdown);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Asserts an inherently-lossy case serializes to a KNOWN normalized form.
|
|
62
|
+
* Pins the normalization so it stays visible and regression-guarded; also
|
|
63
|
+
* guards that the case is genuinely lossy (otherwise it belongs in the
|
|
64
|
+
* byte-stable bucket).
|
|
65
|
+
*/
|
|
66
|
+
function expectNormalizesTo(input: string, normalized: string): void {
|
|
67
|
+
expect(roundTrip(input)).toBe(normalized);
|
|
68
|
+
expect(normalized).not.toBe(input);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
describe("RichMarkdownEditor markdown round-trip", () => {
|
|
72
|
+
describe("byte-stable cases", () => {
|
|
73
|
+
it("headings H1-H4 (ATX)", () => {
|
|
74
|
+
expectStable("# Heading 1");
|
|
75
|
+
expectStable("## Heading 2");
|
|
76
|
+
expectStable("### Heading 3");
|
|
77
|
+
expectStable("#### Heading 4");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("paragraphs", () => {
|
|
81
|
+
expectStable("A single plain paragraph.");
|
|
82
|
+
expectStable("First paragraph.\n\nSecond paragraph.");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("bold and inline code marks", () => {
|
|
86
|
+
expectStable("Text with **bold** words.");
|
|
87
|
+
expectStable("Text with `inline code` words.");
|
|
88
|
+
expectStable("Mixed **bold** and `code` together.");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("bulleted list (tight)", () => {
|
|
92
|
+
expectStable("- One\n- Two\n- Three");
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("numbered list (tight)", () => {
|
|
96
|
+
expectStable("1. One\n2. Two\n3. Three");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("nested bulleted list", () => {
|
|
100
|
+
expectStable("- One\n - Nested A\n - Nested B\n- Two");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("a single task item", () => {
|
|
104
|
+
expectStable("- [ ] Todo item");
|
|
105
|
+
expectStable("- [x] Done item");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("blockquote", () => {
|
|
109
|
+
expectStable("> A quoted line.");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("fenced code block with a language", () => {
|
|
113
|
+
expectStable("```ts\nconst x: number = 1;\n```");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("links", () => {
|
|
117
|
+
expectStable("See [the docs](https://example.com/docs) for details.");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("horizontal rule", () => {
|
|
121
|
+
expectStable("Above.\n\n---\n\nBelow.");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("GFM pipe table when followed by more content", () => {
|
|
125
|
+
// A table in the middle of a body (the common case in a plan) is stable.
|
|
126
|
+
// The trailing-newline normalization only happens when a table is the
|
|
127
|
+
// very last block — see pinned-lossy cases below.
|
|
128
|
+
expectStable(
|
|
129
|
+
[
|
|
130
|
+
"Intro paragraph.",
|
|
131
|
+
"",
|
|
132
|
+
"| Name | Status |",
|
|
133
|
+
"| --- | --- |",
|
|
134
|
+
"| Alpha | Done |",
|
|
135
|
+
"| Beta | Open |",
|
|
136
|
+
"",
|
|
137
|
+
"Closing paragraph.",
|
|
138
|
+
].join("\n"),
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("a representative mixed plan body (no italics, table not last)", () => {
|
|
143
|
+
expectStable(
|
|
144
|
+
[
|
|
145
|
+
"# Project Plan",
|
|
146
|
+
"",
|
|
147
|
+
"## Overview",
|
|
148
|
+
"",
|
|
149
|
+
"This plan covers the **rollout** of the new flow.",
|
|
150
|
+
"",
|
|
151
|
+
"## Notes",
|
|
152
|
+
"",
|
|
153
|
+
"See [the brief](https://example.com/brief) and run `pnpm test`.",
|
|
154
|
+
"",
|
|
155
|
+
"```ts",
|
|
156
|
+
"const ready = true;",
|
|
157
|
+
"```",
|
|
158
|
+
].join("\n"),
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("pinned-lossy cases (inherent to tiptap-markdown 0.9.0)", () => {
|
|
164
|
+
it("italic: underscore markers normalize to asterisks", () => {
|
|
165
|
+
// tiptap-markdown serializes the italic mark via prosemirror-markdown's
|
|
166
|
+
// `defaultMarkdownSerializer.marks.em`, which hardcodes `*` open/close.
|
|
167
|
+
// There is NO `Markdown.configure` option for the emphasis marker
|
|
168
|
+
// (`bulletListMarker` only controls bullet lists), so `_x_` always
|
|
169
|
+
// re-emits as `*x*`. Asterisk-delimited italics are already stable.
|
|
170
|
+
expectNormalizesTo(
|
|
171
|
+
"Text with _italic_ words.",
|
|
172
|
+
"Text with *italic* words.",
|
|
173
|
+
);
|
|
174
|
+
expectStable("Text with *italic* words.");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("multi-item task lists serialize loose (blank line between items)", () => {
|
|
178
|
+
// tiptap-markdown's tight-list support (MarkdownTightLists) only
|
|
179
|
+
// registers the `tight` attribute for `bulletList`/`orderedList`, never
|
|
180
|
+
// `taskList`, and that extension is not exported for reconfiguration.
|
|
181
|
+
// So task lists with 2+ items always gain a blank line between items.
|
|
182
|
+
// A single task item (above) stays stable.
|
|
183
|
+
expectNormalizesTo(
|
|
184
|
+
"- [ ] Todo item\n- [x] Done item",
|
|
185
|
+
"- [ ] Todo item\n\n- [x] Done item",
|
|
186
|
+
);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("nested task list also serializes loose", () => {
|
|
190
|
+
expectNormalizesTo(
|
|
191
|
+
"- [ ] parent\n - [x] child",
|
|
192
|
+
"- [ ] parent\n\n - [x] child",
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("a table as the LAST block gains a trailing newline", () => {
|
|
197
|
+
// When a pipe table is the final block in the document the serializer
|
|
198
|
+
// appends a trailing "\n". (Mid-body tables — see byte-stable cases —
|
|
199
|
+
// do not.) Not removable via public config.
|
|
200
|
+
expectNormalizesTo(
|
|
201
|
+
[
|
|
202
|
+
"| Name | Status |",
|
|
203
|
+
"| --- | --- |",
|
|
204
|
+
"| Alpha | Done |",
|
|
205
|
+
"| Beta | Open |",
|
|
206
|
+
].join("\n"),
|
|
207
|
+
[
|
|
208
|
+
"| Name | Status |",
|
|
209
|
+
"| --- | --- |",
|
|
210
|
+
"| Alpha | Done |",
|
|
211
|
+
"| Beta | Open |",
|
|
212
|
+
"",
|
|
213
|
+
].join("\n"),
|
|
214
|
+
);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe("intentional normalizations (desired, GFM-canonical)", () => {
|
|
219
|
+
it("`*` bullet markers normalize to `-` per bulletListMarker config", () => {
|
|
220
|
+
// We deliberately keep bulletListMarker: "-" so all bullets converge on
|
|
221
|
+
// the GFM-canonical dash. `*`/`+` bullets becoming `-` is intended.
|
|
222
|
+
expectNormalizesTo("* One\n* Two", "- One\n- Two");
|
|
223
|
+
expectNormalizesTo("+ One\n+ Two", "- One\n- Two");
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Awareness } from "y-protocols/awareness";
|
|
2
|
+
import type { Doc as YDoc } from "yjs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Back-compat surface for the shared rich markdown editor.
|
|
6
|
+
*
|
|
7
|
+
* The editor core now lives in dedicated modules:
|
|
8
|
+
* - {@link createSharedEditorExtensions} — the ONE extension factory.
|
|
9
|
+
* - {@link useCollabReconcile} — seed / reconcile / lead-client logic.
|
|
10
|
+
* - {@link SlashCommandMenu} / {@link BubbleToolbar} — shared menus.
|
|
11
|
+
* - {@link SharedRichEditor} — the editor component.
|
|
12
|
+
*
|
|
13
|
+
* This file keeps the historical `RichMarkdownEditor` component name (aliased to
|
|
14
|
+
* {@link SharedRichEditor}) and the `createRichMarkdownExtensions` factory so
|
|
15
|
+
* existing embedders and the round-trip / collab specs keep working unchanged.
|
|
16
|
+
*/
|
|
17
|
+
import {
|
|
18
|
+
createSharedEditorExtensions,
|
|
19
|
+
type RichMarkdownDialect,
|
|
20
|
+
type RichMarkdownEditorPreset,
|
|
21
|
+
type RichMarkdownCollabUser,
|
|
22
|
+
} from "./extensions.js";
|
|
23
|
+
import {
|
|
24
|
+
SharedRichEditor,
|
|
25
|
+
type SharedRichEditorProps,
|
|
26
|
+
} from "./SharedRichEditor.js";
|
|
27
|
+
|
|
28
|
+
export type {
|
|
29
|
+
RichMarkdownDialect,
|
|
30
|
+
RichMarkdownEditorPreset,
|
|
31
|
+
RichMarkdownCollabUser,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** @deprecated Prefer {@link CreateSharedEditorExtensionsOptions}. */
|
|
35
|
+
export interface CreateRichMarkdownExtensionsOptions {
|
|
36
|
+
dialect?: RichMarkdownDialect;
|
|
37
|
+
placeholder?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Yjs document for collaborative editing. When present, the editor binds the
|
|
40
|
+
* shared Collaboration + CollaborationCaret extensions and StarterKit's
|
|
41
|
+
* built-in undo/redo is disabled (Yjs owns history).
|
|
42
|
+
*/
|
|
43
|
+
ydoc?: YDoc | null;
|
|
44
|
+
/** Shared awareness instance for live multi-user cursors. */
|
|
45
|
+
awareness?: Awareness | null;
|
|
46
|
+
/** Current user info for the collaborative cursor label. */
|
|
47
|
+
user?: RichMarkdownCollabUser | null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Back-compat factory preserving today's GFM/plan behavior EXACTLY. Implemented
|
|
52
|
+
* in terms of {@link createSharedEditorExtensions}: it maps the flat
|
|
53
|
+
* `{ ydoc, awareness, user }` collab options into the nested `collab` shape the
|
|
54
|
+
* shared factory expects. The round-trip and collab specs build their `Editor`
|
|
55
|
+
* from this, so its output must stay byte-stable.
|
|
56
|
+
*/
|
|
57
|
+
export function createRichMarkdownExtensions({
|
|
58
|
+
dialect = "gfm",
|
|
59
|
+
placeholder = "Type '/' for commands...",
|
|
60
|
+
ydoc = null,
|
|
61
|
+
awareness = null,
|
|
62
|
+
user = null,
|
|
63
|
+
}: CreateRichMarkdownExtensionsOptions = {}) {
|
|
64
|
+
return createSharedEditorExtensions({
|
|
65
|
+
dialect,
|
|
66
|
+
placeholder,
|
|
67
|
+
collab: ydoc ? { ydoc, awareness, user } : null,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @deprecated Prefer {@link SharedRichEditorProps}. */
|
|
72
|
+
export type RichMarkdownEditorProps = SharedRichEditorProps;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Historical name for {@link SharedRichEditor}. Kept so existing imports
|
|
76
|
+
* (`import { RichMarkdownEditor } from "@agent-native/core/client"`) and the
|
|
77
|
+
* plan editor tests (which assert the source mentions `RichMarkdownEditor`)
|
|
78
|
+
* keep working through the Core compatibility re-export. New code should import
|
|
79
|
+
* `SharedRichEditor` from `@agent-native/toolkit/editor`.
|
|
80
|
+
*/
|
|
81
|
+
export const RichMarkdownEditor = SharedRichEditor;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Node types that carry the optional `runId` attribute.
|
|
5
|
+
*
|
|
6
|
+
* These are exactly the top-level block nodes a plan's `rich-text` block can
|
|
7
|
+
* serialize to. The plan's `doc ↔ blocks[]` bridge stamps `runId` onto the
|
|
8
|
+
* FIRST node of each rich-text run so a re-parse can map the run back to its
|
|
9
|
+
* originating block id (stable ids across edits). Atom/structured blocks live
|
|
10
|
+
* in their own `planBlock` node and do not need this attribute.
|
|
11
|
+
*/
|
|
12
|
+
export const RUN_ID_NODE_TYPES = [
|
|
13
|
+
"paragraph",
|
|
14
|
+
"heading",
|
|
15
|
+
"bulletList",
|
|
16
|
+
"orderedList",
|
|
17
|
+
"taskList",
|
|
18
|
+
"blockquote",
|
|
19
|
+
"codeBlock",
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Tiptap extension that adds a GLOBAL `runId` attribute (default `null`) to the
|
|
24
|
+
* block node types in {@link RUN_ID_NODE_TYPES}.
|
|
25
|
+
*
|
|
26
|
+
* - `renderHTML` emits `data-run-id` only when the attribute is set, so the
|
|
27
|
+
* live editor's DOM carries the id for the doc↔blocks bridge.
|
|
28
|
+
* - `parseHTML` reads `data-run-id` back so a paste / re-parse preserves it.
|
|
29
|
+
* - Markdown serialization deliberately IGNORES `runId`: GFM never emits it.
|
|
30
|
+
* `tiptap-markdown` drops attributes it has no serializer for, so we simply
|
|
31
|
+
* don't register a markdown serializer here — the attribute is invisible to
|
|
32
|
+
* the GFM round-trip and only lives in the ProseMirror JSON / DOM.
|
|
33
|
+
*
|
|
34
|
+
* Used by BOTH the headless `gfmDoc` editor and the live plan editor so the
|
|
35
|
+
* schema is identical on both sides of the bridge.
|
|
36
|
+
*/
|
|
37
|
+
export const RunId = Extension.create({
|
|
38
|
+
name: "runId",
|
|
39
|
+
|
|
40
|
+
addGlobalAttributes() {
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
types: [...RUN_ID_NODE_TYPES],
|
|
44
|
+
attributes: {
|
|
45
|
+
runId: {
|
|
46
|
+
default: null,
|
|
47
|
+
// Read the id off the rendered DOM so paste / re-parse round-trips.
|
|
48
|
+
parseHTML: (element) => element.getAttribute("data-run-id"),
|
|
49
|
+
// Only emit the attribute when set; an unset (null) runId adds
|
|
50
|
+
// nothing to the DOM so untouched nodes stay clean.
|
|
51
|
+
renderHTML: (attributes) => {
|
|
52
|
+
const runId = (attributes as { runId?: string | null }).runId;
|
|
53
|
+
if (!runId) return {};
|
|
54
|
+
return { "data-run-id": runId };
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
},
|
|
61
|
+
});
|