@agent-native/core 0.38.0 → 0.39.1

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.
Files changed (158) hide show
  1. package/dist/cli/create.d.ts.map +1 -1
  2. package/dist/cli/create.js +8 -1
  3. package/dist/cli/create.js.map +1 -1
  4. package/dist/cli/index.js +1 -1
  5. package/dist/cli/index.js.map +1 -1
  6. package/dist/cli/skills.d.ts +6 -4
  7. package/dist/cli/skills.d.ts.map +1 -1
  8. package/dist/cli/skills.js +587 -126
  9. package/dist/cli/skills.js.map +1 -1
  10. package/dist/client/blocks/BlockView.d.ts +13 -4
  11. package/dist/client/blocks/BlockView.d.ts.map +1 -1
  12. package/dist/client/blocks/BlockView.js +34 -13
  13. package/dist/client/blocks/BlockView.js.map +1 -1
  14. package/dist/client/blocks/SchemaBlockEditor.d.ts.map +1 -1
  15. package/dist/client/blocks/SchemaBlockEditor.js +96 -3
  16. package/dist/client/blocks/SchemaBlockEditor.js.map +1 -1
  17. package/dist/client/blocks/index.d.ts +18 -1
  18. package/dist/client/blocks/index.d.ts.map +1 -1
  19. package/dist/client/blocks/index.js +26 -1
  20. package/dist/client/blocks/index.js.map +1 -1
  21. package/dist/client/blocks/library/AnnotatedCodeBlock.d.ts +6 -0
  22. package/dist/client/blocks/library/AnnotatedCodeBlock.d.ts.map +1 -0
  23. package/dist/client/blocks/library/AnnotatedCodeBlock.js +135 -0
  24. package/dist/client/blocks/library/AnnotatedCodeBlock.js.map +1 -0
  25. package/dist/client/blocks/library/ApiEndpointBlock.d.ts +20 -0
  26. package/dist/client/blocks/library/ApiEndpointBlock.d.ts.map +1 -0
  27. package/dist/client/blocks/library/ApiEndpointBlock.js +131 -0
  28. package/dist/client/blocks/library/ApiEndpointBlock.js.map +1 -0
  29. package/dist/client/blocks/library/DataModelBlock.d.ts +28 -0
  30. package/dist/client/blocks/library/DataModelBlock.d.ts.map +1 -0
  31. package/dist/client/blocks/library/DataModelBlock.js +222 -0
  32. package/dist/client/blocks/library/DataModelBlock.js.map +1 -0
  33. package/dist/client/blocks/library/DiffBlock.d.ts +6 -0
  34. package/dist/client/blocks/library/DiffBlock.d.ts.map +1 -0
  35. package/dist/client/blocks/library/DiffBlock.js +293 -0
  36. package/dist/client/blocks/library/DiffBlock.js.map +1 -0
  37. package/dist/client/blocks/library/FileTreeBlock.d.ts +23 -0
  38. package/dist/client/blocks/library/FileTreeBlock.d.ts.map +1 -0
  39. package/dist/client/blocks/library/FileTreeBlock.js +225 -0
  40. package/dist/client/blocks/library/FileTreeBlock.js.map +1 -0
  41. package/dist/client/blocks/library/JsonExplorerBlock.d.ts +19 -0
  42. package/dist/client/blocks/library/JsonExplorerBlock.d.ts.map +1 -0
  43. package/dist/client/blocks/library/JsonExplorerBlock.js +171 -0
  44. package/dist/client/blocks/library/JsonExplorerBlock.js.map +1 -0
  45. package/dist/client/blocks/library/MermaidBlock.d.ts +17 -0
  46. package/dist/client/blocks/library/MermaidBlock.d.ts.map +1 -0
  47. package/dist/client/blocks/library/MermaidBlock.js +131 -0
  48. package/dist/client/blocks/library/MermaidBlock.js.map +1 -0
  49. package/dist/client/blocks/library/OpenApiSpecBlock.d.ts +19 -0
  50. package/dist/client/blocks/library/OpenApiSpecBlock.d.ts.map +1 -0
  51. package/dist/client/blocks/library/OpenApiSpecBlock.js +494 -0
  52. package/dist/client/blocks/library/OpenApiSpecBlock.js.map +1 -0
  53. package/dist/client/blocks/library/annotated-code.config.d.ts +58 -0
  54. package/dist/client/blocks/library/annotated-code.config.d.ts.map +1 -0
  55. package/dist/client/blocks/library/annotated-code.config.js +53 -0
  56. package/dist/client/blocks/library/annotated-code.config.js.map +1 -0
  57. package/dist/client/blocks/library/api-endpoint.config.d.ts +71 -0
  58. package/dist/client/blocks/library/api-endpoint.config.d.ts.map +1 -0
  59. package/dist/client/blocks/library/api-endpoint.config.js +91 -0
  60. package/dist/client/blocks/library/api-endpoint.config.js.map +1 -0
  61. package/dist/client/blocks/library/checklist.d.ts.map +1 -1
  62. package/dist/client/blocks/library/checklist.js +3 -1
  63. package/dist/client/blocks/library/checklist.js.map +1 -1
  64. package/dist/client/blocks/library/code-tabs.js +1 -1
  65. package/dist/client/blocks/library/code-tabs.js.map +1 -1
  66. package/dist/client/blocks/library/data-model.config.d.ts +72 -0
  67. package/dist/client/blocks/library/data-model.config.d.ts.map +1 -0
  68. package/dist/client/blocks/library/data-model.config.js +59 -0
  69. package/dist/client/blocks/library/data-model.config.js.map +1 -0
  70. package/dist/client/blocks/library/dev-doc-ui.d.ts +49 -0
  71. package/dist/client/blocks/library/dev-doc-ui.d.ts.map +1 -0
  72. package/dist/client/blocks/library/dev-doc-ui.js +50 -0
  73. package/dist/client/blocks/library/dev-doc-ui.js.map +1 -0
  74. package/dist/client/blocks/library/diff.config.d.ts +41 -0
  75. package/dist/client/blocks/library/diff.config.d.ts.map +1 -0
  76. package/dist/client/blocks/library/diff.config.js +34 -0
  77. package/dist/client/blocks/library/diff.config.js.map +1 -0
  78. package/dist/client/blocks/library/file-tree.config.d.ts +59 -0
  79. package/dist/client/blocks/library/file-tree.config.d.ts.map +1 -0
  80. package/dist/client/blocks/library/file-tree.config.js +45 -0
  81. package/dist/client/blocks/library/file-tree.config.js.map +1 -0
  82. package/dist/client/blocks/library/html.d.ts.map +1 -1
  83. package/dist/client/blocks/library/html.js +4 -1
  84. package/dist/client/blocks/library/html.js.map +1 -1
  85. package/dist/client/blocks/library/json-explorer.config.d.ts +46 -0
  86. package/dist/client/blocks/library/json-explorer.config.d.ts.map +1 -0
  87. package/dist/client/blocks/library/json-explorer.config.js +28 -0
  88. package/dist/client/blocks/library/json-explorer.config.js.map +1 -0
  89. package/dist/client/blocks/library/mermaid.config.d.ts +32 -0
  90. package/dist/client/blocks/library/mermaid.config.d.ts.map +1 -0
  91. package/dist/client/blocks/library/mermaid.config.js +24 -0
  92. package/dist/client/blocks/library/mermaid.config.js.map +1 -0
  93. package/dist/client/blocks/library/openapi-spec.config.d.ts +49 -0
  94. package/dist/client/blocks/library/openapi-spec.config.d.ts.map +1 -0
  95. package/dist/client/blocks/library/openapi-spec.config.js +24 -0
  96. package/dist/client/blocks/library/openapi-spec.config.js.map +1 -0
  97. package/dist/client/blocks/library/server-specs.d.ts +35 -0
  98. package/dist/client/blocks/library/server-specs.d.ts.map +1 -0
  99. package/dist/client/blocks/library/server-specs.js +171 -0
  100. package/dist/client/blocks/library/server-specs.js.map +1 -0
  101. package/dist/client/blocks/library/specs.d.ts +29 -0
  102. package/dist/client/blocks/library/specs.d.ts.map +1 -0
  103. package/dist/client/blocks/library/specs.js +229 -0
  104. package/dist/client/blocks/library/specs.js.map +1 -0
  105. package/dist/client/blocks/library/table.d.ts.map +1 -1
  106. package/dist/client/blocks/library/table.js +3 -1
  107. package/dist/client/blocks/library/table.js.map +1 -1
  108. package/dist/client/blocks/library/tabs.js +1 -1
  109. package/dist/client/blocks/library/tabs.js.map +1 -1
  110. package/dist/client/blocks/registry.d.ts +8 -0
  111. package/dist/client/blocks/registry.d.ts.map +1 -1
  112. package/dist/client/blocks/registry.js +15 -0
  113. package/dist/client/blocks/registry.js.map +1 -1
  114. package/dist/client/blocks/server.d.ts +9 -0
  115. package/dist/client/blocks/server.d.ts.map +1 -1
  116. package/dist/client/blocks/server.js +16 -0
  117. package/dist/client/blocks/server.js.map +1 -1
  118. package/dist/client/blocks/types.d.ts +40 -0
  119. package/dist/client/blocks/types.d.ts.map +1 -1
  120. package/dist/client/blocks/types.js.map +1 -1
  121. package/dist/client/index.d.ts +2 -1
  122. package/dist/client/index.d.ts.map +1 -1
  123. package/dist/client/index.js +10 -1
  124. package/dist/client/index.js.map +1 -1
  125. package/dist/client/rich-markdown-editor/DragHandle.d.ts +52 -0
  126. package/dist/client/rich-markdown-editor/DragHandle.d.ts.map +1 -0
  127. package/dist/client/rich-markdown-editor/DragHandle.js +403 -0
  128. package/dist/client/rich-markdown-editor/DragHandle.js.map +1 -0
  129. package/dist/client/rich-markdown-editor/RegistryBlockNode.d.ts +97 -0
  130. package/dist/client/rich-markdown-editor/RegistryBlockNode.d.ts.map +1 -0
  131. package/dist/client/rich-markdown-editor/RegistryBlockNode.js +214 -0
  132. package/dist/client/rich-markdown-editor/RegistryBlockNode.js.map +1 -0
  133. package/dist/client/rich-markdown-editor/RunId.d.ts +28 -0
  134. package/dist/client/rich-markdown-editor/RunId.d.ts.map +1 -0
  135. package/dist/client/rich-markdown-editor/RunId.js +60 -0
  136. package/dist/client/rich-markdown-editor/RunId.js.map +1 -0
  137. package/dist/client/rich-markdown-editor/SharedRichEditor.d.ts +25 -1
  138. package/dist/client/rich-markdown-editor/SharedRichEditor.d.ts.map +1 -1
  139. package/dist/client/rich-markdown-editor/SharedRichEditor.js +14 -5
  140. package/dist/client/rich-markdown-editor/SharedRichEditor.js.map +1 -1
  141. package/dist/client/rich-markdown-editor/gfmDoc.d.ts +24 -0
  142. package/dist/client/rich-markdown-editor/gfmDoc.d.ts.map +1 -0
  143. package/dist/client/rich-markdown-editor/gfmDoc.js +83 -0
  144. package/dist/client/rich-markdown-editor/gfmDoc.js.map +1 -0
  145. package/dist/client/rich-markdown-editor/index.d.ts +5 -0
  146. package/dist/client/rich-markdown-editor/index.d.ts.map +1 -1
  147. package/dist/client/rich-markdown-editor/index.js +5 -0
  148. package/dist/client/rich-markdown-editor/index.js.map +1 -1
  149. package/dist/client/rich-markdown-editor/registrySlashCommands.d.ts +46 -0
  150. package/dist/client/rich-markdown-editor/registrySlashCommands.d.ts.map +1 -0
  151. package/dist/client/rich-markdown-editor/registrySlashCommands.js +13 -0
  152. package/dist/client/rich-markdown-editor/registrySlashCommands.js.map +1 -0
  153. package/dist/client/rich-markdown-editor/useCollabReconcile.d.ts.map +1 -1
  154. package/dist/client/rich-markdown-editor/useCollabReconcile.js +33 -0
  155. package/dist/client/rich-markdown-editor/useCollabReconcile.js.map +1 -1
  156. package/docs/content/template-plan.md +19 -4
  157. package/docs/content/visual-plans.md +3 -1
  158. package/package.json +1 -1
@@ -0,0 +1,214 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ import { Node, NodeViewWrapper, ReactNodeViewRenderer, mergeAttributes, } from "@tiptap/react";
4
+ import { Plugin, PluginKey } from "@tiptap/pm/state";
5
+ import { BlockView, useOptionalBlockRegistry } from "../blocks/index.js";
6
+ const RegistryBlockDataContext = createContext(null);
7
+ export function RegistryBlockDataProvider({ value, children, }) {
8
+ return (_jsx(RegistryBlockDataContext.Provider, { value: value, children: children }));
9
+ }
10
+ /** Read the registry block side-map. Returns `null` outside a provider. */
11
+ export function useRegistryBlockData() {
12
+ return useContext(RegistryBlockDataContext);
13
+ }
14
+ /* -------------------------------------------------------------------------- */
15
+ /* B. RegistryBlockNodeView (React) */
16
+ /* -------------------------------------------------------------------------- */
17
+ /**
18
+ * Renders one registry-block atom. The block is non-editable as far as
19
+ * ProseMirror is concerned (`contentEditable={false}`); all interaction happens
20
+ * inside the registry-driven `<BlockView>`. Read vs edit is toggled by
21
+ * `props.selected` (the node is "selected" in the editor) AND the document being
22
+ * editable. `data-plan-interactive` keeps existing host click-guards from
23
+ * treating clicks inside the block as document clicks.
24
+ */
25
+ export function RegistryBlockNodeView(props) {
26
+ const blockType = String(props.node.attrs.blockType ?? "");
27
+ const blockId = String(props.node.attrs.blockId ?? "");
28
+ const registryValue = useOptionalBlockRegistry();
29
+ const sideMap = useRegistryBlockData();
30
+ const block = sideMap?.getBlock(blockId);
31
+ const editable = sideMap?.editable ?? false;
32
+ const editing = editable && props.selected;
33
+ // In Notion-sync mode, flag blocks that have no Notion (NFM) analog so the
34
+ // author sees what won't push. Prose blocks aren't registry-block nodes, so
35
+ // this only ever covers structured blocks.
36
+ const incompatibleWithNotion = (sideMap?.notionSync ?? false) &&
37
+ (sideMap?.isNotionIncompatibleType?.(blockType) ?? false);
38
+ // The block data isn't in the side-map yet (e.g. a freshly inserted node whose
39
+ // store entry hasn't been seeded). Render a graceful placeholder.
40
+ if (!block) {
41
+ return (_jsx(NodeViewWrapper, { className: "plan-block-node", "data-block-id": blockId, children: _jsx("div", { contentEditable: false, "data-plan-interactive": true, className: "plan-block-node__placeholder rounded-md border border-dashed border-border px-3 py-2 text-sm text-muted-foreground", children: blockType ? `Loading ${blockType} block…` : "Loading block…" }) }));
42
+ }
43
+ const spec = registryValue?.registry.get(blockType);
44
+ // Choose how to render the block body:
45
+ // 1. Registered spec → the registry `BlockView` (Read, or the spec Edit /
46
+ // auto-form when selected). This is the common path (callout, table,
47
+ // code-tabs, wireframe, …).
48
+ // 2. No spec, but the side-map provides `renderLegacyBlock` → delegate to the
49
+ // host's dispatcher (decision, legacy visual-questions, image, and any
50
+ // other type rendered by a bespoke component rather than the registry), so
51
+ // EVERY block type renders in the document exactly as it does in the
52
+ // per-block reader — never a bare title fallback.
53
+ // 3. Neither → a small non-crashing fallback.
54
+ let body;
55
+ if (registryValue && spec) {
56
+ body = (_jsx(BlockView, { spec: spec, block: {
57
+ id: block.id,
58
+ title: block.title,
59
+ summary: block.summary,
60
+ data: block.data,
61
+ }, editing: editing, editable: editable, onChange: (nextData) => sideMap?.onBlockDataChange(blockId, nextData), ctx: registryValue.ctx }));
62
+ }
63
+ else if (sideMap?.renderLegacyBlock) {
64
+ body = sideMap.renderLegacyBlock(block, { editing });
65
+ }
66
+ else {
67
+ body = (_jsx("div", { className: "plan-block-node__fallback rounded-md border border-border px-3 py-2 text-sm text-muted-foreground", children: block.title || blockType || "Unsupported block" }));
68
+ }
69
+ return (_jsx(NodeViewWrapper, { className: "plan-block-node", "data-block-id": blockId, "data-notion-incompatible": incompatibleWithNotion ? "" : undefined, children: _jsxs("div", { contentEditable: false, "data-plan-interactive": true, children: [incompatibleWithNotion && (_jsx("span", { className: "plan-block-notion-badge", title: "This block type has no Notion equivalent and won't sync to Notion.", children: "Won't sync to Notion" })), body] }) }));
70
+ }
71
+ /**
72
+ * Build the generic registry-block Tiptap atom node. Returns a Tiptap `Node`
73
+ * that:
74
+ * - carries identity attrs `blockType` / `blockId` / `title` / `summary`, a
75
+ * `sourceBlockId` (set when a duplicate is re-minted, so the host can copy the
76
+ * original block's data), and an optional `__raw` verbatim-MDX attr for
77
+ * byte-stable source round-trips;
78
+ * - is an atom + isolating + draggable block that renders through
79
+ * {@link RegistryBlockNodeView} (via `ReactNodeViewRenderer`);
80
+ * - installs a dedupe `appendTransaction` plugin that re-mints any duplicate or
81
+ * empty `blockId` (the classic paste/duplicate case), preserving the original
82
+ * block's id + side-map data and tagging its own transaction so it never
83
+ * loops.
84
+ */
85
+ export function createRegistryBlockNode(options) {
86
+ const { nodeName, dataTag, mintId, group = "block" } = options;
87
+ const dedupeKey = new PluginKey(`${nodeName}DedupeIds`);
88
+ /**
89
+ * Collect every `blockId` currently present on this node type in a doc, with
90
+ * the position of each node, so duplicate ids (from paste/duplicate) can be
91
+ * detected and re-minted.
92
+ */
93
+ function collectEntries(state) {
94
+ const found = [];
95
+ state.doc.descendants((node, pos) => {
96
+ if (node.type.name === nodeName) {
97
+ found.push({
98
+ pos,
99
+ blockType: String(node.attrs.blockType ?? ""),
100
+ blockId: String(node.attrs.blockId ?? ""),
101
+ sourceBlockId: typeof node.attrs.sourceBlockId === "string"
102
+ ? node.attrs.sourceBlockId
103
+ : undefined,
104
+ });
105
+ }
106
+ return true;
107
+ });
108
+ return found;
109
+ }
110
+ /**
111
+ * Build a transaction that re-mints any duplicate / missing ids in `state`, or
112
+ * `null` when nothing needs changing. Only the *later* duplicate (and any node
113
+ * with an empty id) is re-minted, so the original keeps its id and side-map
114
+ * data.
115
+ */
116
+ function buildDedupeTransaction(state) {
117
+ const entries = collectEntries(state);
118
+ if (entries.length === 0)
119
+ return null;
120
+ const seen = new Set();
121
+ let tr = state.tr;
122
+ let changed = false;
123
+ for (const entry of entries) {
124
+ const needsNewId = !entry.blockId || seen.has(entry.blockId);
125
+ if (needsNewId) {
126
+ const freshId = mintId(entry.blockType || "block");
127
+ const node = state.doc.nodeAt(entry.pos);
128
+ if (node) {
129
+ tr = tr.setNodeMarkup(entry.pos, undefined, {
130
+ ...node.attrs,
131
+ blockId: freshId,
132
+ sourceBlockId: entry.sourceBlockId || entry.blockId || null,
133
+ });
134
+ changed = true;
135
+ }
136
+ seen.add(freshId);
137
+ }
138
+ else {
139
+ seen.add(entry.blockId);
140
+ }
141
+ }
142
+ return changed ? tr.setMeta(dedupeKey, true) : null;
143
+ }
144
+ return Node.create({
145
+ name: nodeName,
146
+ group,
147
+ atom: true,
148
+ draggable: true,
149
+ selectable: true,
150
+ isolating: true,
151
+ addAttributes() {
152
+ return {
153
+ blockType: { default: "" },
154
+ blockId: { default: "" },
155
+ title: { default: null },
156
+ summary: { default: null },
157
+ sourceBlockId: { default: null },
158
+ // Optional verbatim source for hosts that need byte-identical
159
+ // source-format round-trips without React (server pull, hashing). Plan
160
+ // never sets this.
161
+ __raw: { default: null, rendered: false },
162
+ };
163
+ },
164
+ parseHTML() {
165
+ return [
166
+ {
167
+ tag: `div[${dataTag}]`,
168
+ getAttrs: (element) => {
169
+ const node = element;
170
+ return {
171
+ blockType: node.getAttribute("data-block-type") || "",
172
+ blockId: node.getAttribute("data-block-id") || "",
173
+ title: node.getAttribute("data-title") || null,
174
+ summary: node.getAttribute("data-summary") || null,
175
+ sourceBlockId: node.getAttribute("data-source-block-id") || null,
176
+ };
177
+ },
178
+ },
179
+ ];
180
+ },
181
+ renderHTML({ HTMLAttributes }) {
182
+ return [
183
+ "div",
184
+ mergeAttributes(HTMLAttributes, {
185
+ [dataTag]: "",
186
+ "data-block-type": HTMLAttributes.blockType ?? "",
187
+ "data-block-id": HTMLAttributes.blockId ?? "",
188
+ "data-title": HTMLAttributes.title ?? undefined,
189
+ "data-summary": HTMLAttributes.summary ?? undefined,
190
+ "data-source-block-id": HTMLAttributes.sourceBlockId ?? undefined,
191
+ }),
192
+ ];
193
+ },
194
+ addNodeView() {
195
+ return ReactNodeViewRenderer(RegistryBlockNodeView);
196
+ },
197
+ addProseMirrorPlugins() {
198
+ return [
199
+ new Plugin({
200
+ key: dedupeKey,
201
+ appendTransaction(transactions, _oldState, newState) {
202
+ // Ignore our own re-mint, and skip when nothing changed the doc.
203
+ if (transactions.some((transaction) => transaction.getMeta(dedupeKey)) ||
204
+ !transactions.some((transaction) => transaction.docChanged)) {
205
+ return null;
206
+ }
207
+ return buildDedupeTransaction(newState);
208
+ },
209
+ }),
210
+ ];
211
+ },
212
+ });
213
+ }
214
+ //# sourceMappingURL=RegistryBlockNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegistryBlockNode.js","sourceRoot":"","sources":["../../../src/client/rich-markdown-editor/RegistryBlockNode.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAkB,MAAM,OAAO,CAAC;AAClE,OAAO,EACL,IAAI,EACJ,eAAe,EACf,qBAAqB,EACrB,eAAe,GAEhB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,SAAS,EAAoB,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAoEzE,MAAM,wBAAwB,GAC5B,aAAa,CAAqC,IAAI,CAAC,CAAC;AAE1D,MAAM,UAAU,yBAAyB,CAEvC,EACA,KAAK,EACL,QAAQ,GAIT;IACC,OAAO,CACL,KAAC,wBAAwB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAC5C,QAAQ,GACyB,CACrC,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,oBAAoB;IAGlC,OAAO,UAAU,CACf,wBAAwB,CACgB,CAAC;AAC7C,CAAC;AAED,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAEhF;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAoB;IACxD,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IAC3D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E,YAAY,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAChC,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,CAC/B;4BACD,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC,EAC3D,CAAC;4BACD,OAAO,IAAI,CAAC;wBACd,CAAC;wBACD,OAAO,sBAAsB,CAAC,QAAQ,CAAC,CAAC;oBAC1C,CAAC;iBACF,CAAC;aACH,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { createContext, useContext, type ReactNode } from \"react\";\nimport {\n Node,\n NodeViewWrapper,\n ReactNodeViewRenderer,\n mergeAttributes,\n type NodeViewProps,\n} from \"@tiptap/react\";\nimport { Plugin, PluginKey, type EditorState } from \"@tiptap/pm/state\";\nimport { BlockView, useOptionalBlockRegistry } from \"../blocks/index.js\";\n\n/* -------------------------------------------------------------------------- */\n/* The generic registry-block side-map + Tiptap NodeView, lifted into core. */\n/* */\n/* This is the app-agnostic NodeView that renders registered block specs */\n/* inside a `SharedRichEditor` document. Hosts mount the node produced by */\n/* {@link createRegistryBlockNode} as an extra extension and wrap the editor */\n/* in a {@link RegistryBlockDataProvider}, sourcing the typed block `data` */\n/* from their own authoritative store (for example, PlanContent.blocks). The */\n/* node itself carries only lightweight identity attrs (type/id/title/summary) */\n/* plus an optional `__raw` verbatim-MDX attr for byte-stable source */\n/* round-trips; the heavy typed `data` is threaded through the side-map */\n/* context, keeping the doc small and the block data the single source of */\n/* truth. */\n/* -------------------------------------------------------------------------- */\n\n/* -------------------------------------------------------------------------- */\n/* C. Block-data side-map context */\n/* -------------------------------------------------------------------------- */\n\n/** The minimal block shape the NodeView renders through `<BlockView>`. */\nexport interface RegistryBlockSideMapBlock {\n id: string;\n title?: string;\n summary?: string;\n data: unknown;\n}\n\n/**\n * The side-map an editor host supplies so the registry NodeView can resolve a\n * block's full typed `data` (and commit edits) by its stable id, without ever\n * storing that data in the ProseMirror doc.\n */\nexport interface RegistryBlockDataValue<\n TBlock extends RegistryBlockSideMapBlock = RegistryBlockSideMapBlock,\n> {\n /** Resolve a block's full record (incl. `data`) by its stable id. */\n getBlock: (blockId: string) => TBlock | undefined;\n /** Commit a new `data` value for a block (edit-mode only). */\n onBlockDataChange: (blockId: string, nextData: unknown) => void;\n /** Whether the document (and thus its blocks) is editable. */\n editable: boolean;\n /**\n * When true, blocks whose type has no Notion (NFM) analog are badged so the\n * author knows they won't sync. The host decides which types are incompatible\n * via {@link isNotionIncompatibleType}; this flag just toggles the badge on.\n */\n notionSync?: boolean;\n /**\n * Decide whether a block type is Notion-incompatible (no NFM analog). Only\n * consulted when {@link notionSync} is true. Injected by the host so the\n * single registry-level allowlist (plan's `isNotionCompatibleBlockType`, or\n * content's registry-derived gate) drives the badge — core stays policy-free.\n */\n isNotionIncompatibleType?: (blockType: string) => boolean;\n /**\n * Render a block whose type is NOT in the registry through the host's own\n * dispatcher (plan: `PlanBlockView` for decision / legacy visual-questions /\n * image; omitted in hosts with no legacy types), so every block type renders\n * in the document instead of a bare fallback.\n */\n renderLegacyBlock?: (\n block: TBlock,\n options: { editing: boolean },\n ) => ReactNode;\n}\n\nconst RegistryBlockDataContext =\n createContext<RegistryBlockDataValue<any> | null>(null);\n\nexport function RegistryBlockDataProvider<\n TBlock extends RegistryBlockSideMapBlock = RegistryBlockSideMapBlock,\n>({\n value,\n children,\n}: {\n value: RegistryBlockDataValue<TBlock>;\n children: ReactNode;\n}) {\n return (\n <RegistryBlockDataContext.Provider value={value}>\n {children}\n </RegistryBlockDataContext.Provider>\n );\n}\n\n/** Read the registry block side-map. Returns `null` outside a provider. */\nexport function useRegistryBlockData<\n TBlock extends RegistryBlockSideMapBlock = RegistryBlockSideMapBlock,\n>(): RegistryBlockDataValue<TBlock> | null {\n return useContext(\n RegistryBlockDataContext,\n ) as RegistryBlockDataValue<TBlock> | null;\n}\n\n/* -------------------------------------------------------------------------- */\n/* B. RegistryBlockNodeView (React) */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Renders one registry-block atom. The block is non-editable as far as\n * ProseMirror is concerned (`contentEditable={false}`); all interaction happens\n * inside the registry-driven `<BlockView>`. Read vs edit is toggled by\n * `props.selected` (the node is \"selected\" in the editor) AND the document being\n * editable. `data-plan-interactive` keeps existing host click-guards from\n * treating clicks inside the block as document clicks.\n */\nexport function RegistryBlockNodeView(props: NodeViewProps) {\n const blockType = String(props.node.attrs.blockType ?? \"\");\n const blockId = String(props.node.attrs.blockId ?? \"\");\n\n const registryValue = useOptionalBlockRegistry();\n const sideMap = useRegistryBlockData();\n\n const block = sideMap?.getBlock(blockId);\n const editable = sideMap?.editable ?? false;\n const editing = editable && props.selected;\n // In Notion-sync mode, flag blocks that have no Notion (NFM) analog so the\n // author sees what won't push. Prose blocks aren't registry-block nodes, so\n // this only ever covers structured blocks.\n const incompatibleWithNotion =\n (sideMap?.notionSync ?? false) &&\n (sideMap?.isNotionIncompatibleType?.(blockType) ?? false);\n\n // The block data isn't in the side-map yet (e.g. a freshly inserted node whose\n // store entry hasn't been seeded). Render a graceful placeholder.\n if (!block) {\n return (\n <NodeViewWrapper className=\"plan-block-node\" data-block-id={blockId}>\n <div\n contentEditable={false}\n data-plan-interactive\n className=\"plan-block-node__placeholder rounded-md border border-dashed border-border px-3 py-2 text-sm text-muted-foreground\"\n >\n {blockType ? `Loading ${blockType} block…` : \"Loading block…\"}\n </div>\n </NodeViewWrapper>\n );\n }\n\n const spec = registryValue?.registry.get(blockType);\n\n // Choose how to render the block body:\n // 1. Registered spec → the registry `BlockView` (Read, or the spec Edit /\n // auto-form when selected). This is the common path (callout, table,\n // code-tabs, wireframe, …).\n // 2. No spec, but the side-map provides `renderLegacyBlock` → delegate to the\n // host's dispatcher (decision, legacy visual-questions, image, and any\n // other type rendered by a bespoke component rather than the registry), so\n // EVERY block type renders in the document exactly as it does in the\n // per-block reader — never a bare title fallback.\n // 3. Neither → a small non-crashing fallback.\n let body: ReactNode;\n if (registryValue && spec) {\n body = (\n <BlockView\n spec={spec}\n block={{\n id: block.id,\n title: block.title,\n summary: block.summary,\n data: (block as { data: unknown }).data,\n }}\n editing={editing}\n editable={editable}\n onChange={(nextData) => sideMap?.onBlockDataChange(blockId, nextData)}\n ctx={registryValue.ctx}\n />\n );\n } else if (sideMap?.renderLegacyBlock) {\n body = sideMap.renderLegacyBlock(block, { editing });\n } else {\n body = (\n <div className=\"plan-block-node__fallback rounded-md border border-border px-3 py-2 text-sm text-muted-foreground\">\n {block.title || blockType || \"Unsupported block\"}\n </div>\n );\n }\n\n return (\n <NodeViewWrapper\n className=\"plan-block-node\"\n data-block-id={blockId}\n data-notion-incompatible={incompatibleWithNotion ? \"\" : undefined}\n >\n <div contentEditable={false} data-plan-interactive>\n {incompatibleWithNotion && (\n <span\n className=\"plan-block-notion-badge\"\n title=\"This block type has no Notion equivalent and won't sync to Notion.\"\n >\n Won't sync to Notion\n </span>\n )}\n {body}\n </div>\n </NodeViewWrapper>\n );\n}\n\n/* -------------------------------------------------------------------------- */\n/* A. registry-block Tiptap node factory */\n/* -------------------------------------------------------------------------- */\n\n/** Options for {@link createRegistryBlockNode}. */\nexport interface CreateRegistryBlockNodeOptions {\n /**\n * The Tiptap node name (e.g. `\"planBlock\"`). Hosts that serialize the doc by\n * node name (plan's `plan-doc.ts` keys off `\"planBlock\"`) must pass the exact\n * name their serializer expects.\n */\n nodeName: string;\n /**\n * The HTML data-attribute that marks a serialized registry block on copy/paste\n * round-trip (e.g. `\"data-plan-block\"`).\n */\n dataTag: string;\n /**\n * Mint a fresh, unique block id for a given block type. Used by the dedupe\n * plugin to re-mint duplicate / missing ids (paste/duplicate). Plan passes\n * `createPlanBlockId`.\n */\n mintId: (blockType: string) => string;\n /** Node group (default `\"block\"`). */\n group?: string;\n}\n\n/**\n * Build the generic registry-block Tiptap atom node. Returns a Tiptap `Node`\n * that:\n * - carries identity attrs `blockType` / `blockId` / `title` / `summary`, a\n * `sourceBlockId` (set when a duplicate is re-minted, so the host can copy the\n * original block's data), and an optional `__raw` verbatim-MDX attr for\n * byte-stable source round-trips;\n * - is an atom + isolating + draggable block that renders through\n * {@link RegistryBlockNodeView} (via `ReactNodeViewRenderer`);\n * - installs a dedupe `appendTransaction` plugin that re-mints any duplicate or\n * empty `blockId` (the classic paste/duplicate case), preserving the original\n * block's id + side-map data and tagging its own transaction so it never\n * loops.\n */\nexport function createRegistryBlockNode(\n options: CreateRegistryBlockNodeOptions,\n) {\n const { nodeName, dataTag, mintId, group = \"block\" } = options;\n const dedupeKey = new PluginKey(`${nodeName}DedupeIds`);\n\n /**\n * Collect every `blockId` currently present on this node type in a doc, with\n * the position of each node, so duplicate ids (from paste/duplicate) can be\n * detected and re-minted.\n */\n function collectEntries(state: EditorState): Array<{\n pos: number;\n blockType: string;\n blockId: string;\n sourceBlockId?: string;\n }> {\n const found: Array<{\n pos: number;\n blockType: string;\n blockId: string;\n sourceBlockId?: string;\n }> = [];\n state.doc.descendants((node, pos) => {\n if (node.type.name === nodeName) {\n found.push({\n pos,\n blockType: String(node.attrs.blockType ?? \"\"),\n blockId: String(node.attrs.blockId ?? \"\"),\n sourceBlockId:\n typeof node.attrs.sourceBlockId === \"string\"\n ? node.attrs.sourceBlockId\n : undefined,\n });\n }\n return true;\n });\n return found;\n }\n\n /**\n * Build a transaction that re-mints any duplicate / missing ids in `state`, or\n * `null` when nothing needs changing. Only the *later* duplicate (and any node\n * with an empty id) is re-minted, so the original keeps its id and side-map\n * data.\n */\n function buildDedupeTransaction(state: EditorState) {\n const entries = collectEntries(state);\n if (entries.length === 0) return null;\n\n const seen = new Set<string>();\n let tr = state.tr;\n let changed = false;\n\n for (const entry of entries) {\n const needsNewId = !entry.blockId || seen.has(entry.blockId);\n if (needsNewId) {\n const freshId = mintId(entry.blockType || \"block\");\n const node = state.doc.nodeAt(entry.pos);\n if (node) {\n tr = tr.setNodeMarkup(entry.pos, undefined, {\n ...node.attrs,\n blockId: freshId,\n sourceBlockId: entry.sourceBlockId || entry.blockId || null,\n });\n changed = true;\n }\n seen.add(freshId);\n } else {\n seen.add(entry.blockId);\n }\n }\n\n return changed ? tr.setMeta(dedupeKey, true) : null;\n }\n\n return Node.create({\n name: nodeName,\n group,\n atom: true,\n draggable: true,\n selectable: true,\n isolating: true,\n\n addAttributes() {\n return {\n blockType: { default: \"\" },\n blockId: { default: \"\" },\n title: { default: null },\n summary: { default: null },\n sourceBlockId: { default: null },\n // Optional verbatim source for hosts that need byte-identical\n // source-format round-trips without React (server pull, hashing). Plan\n // never sets this.\n __raw: { default: null, rendered: false },\n };\n },\n\n parseHTML() {\n return [\n {\n tag: `div[${dataTag}]`,\n getAttrs: (element) => {\n const node = element as HTMLElement;\n return {\n blockType: node.getAttribute(\"data-block-type\") || \"\",\n blockId: node.getAttribute(\"data-block-id\") || \"\",\n title: node.getAttribute(\"data-title\") || null,\n summary: node.getAttribute(\"data-summary\") || null,\n sourceBlockId: node.getAttribute(\"data-source-block-id\") || null,\n };\n },\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\n \"div\",\n mergeAttributes(HTMLAttributes, {\n [dataTag]: \"\",\n \"data-block-type\": HTMLAttributes.blockType ?? \"\",\n \"data-block-id\": HTMLAttributes.blockId ?? \"\",\n \"data-title\": HTMLAttributes.title ?? undefined,\n \"data-summary\": HTMLAttributes.summary ?? undefined,\n \"data-source-block-id\": HTMLAttributes.sourceBlockId ?? undefined,\n }),\n ];\n },\n\n addNodeView() {\n return ReactNodeViewRenderer(RegistryBlockNodeView);\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: dedupeKey,\n appendTransaction(transactions, _oldState, newState) {\n // Ignore our own re-mint, and skip when nothing changed the doc.\n if (\n transactions.some((transaction) =>\n transaction.getMeta(dedupeKey),\n ) ||\n !transactions.some((transaction) => transaction.docChanged)\n ) {\n return null;\n }\n return buildDedupeTransaction(newState);\n },\n }),\n ];\n },\n });\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import { Extension } from "@tiptap/core";
2
+ /**
3
+ * Node types that carry the optional `runId` attribute.
4
+ *
5
+ * These are exactly the top-level block nodes a plan's `rich-text` block can
6
+ * serialize to. The plan's `doc ↔ blocks[]` bridge stamps `runId` onto the
7
+ * FIRST node of each rich-text run so a re-parse can map the run back to its
8
+ * originating block id (stable ids across edits). Atom/structured blocks live
9
+ * in their own `planBlock` node and do not need this attribute.
10
+ */
11
+ export declare const RUN_ID_NODE_TYPES: readonly ["paragraph", "heading", "bulletList", "orderedList", "taskList", "blockquote", "codeBlock"];
12
+ /**
13
+ * Tiptap extension that adds a GLOBAL `runId` attribute (default `null`) to the
14
+ * block node types in {@link RUN_ID_NODE_TYPES}.
15
+ *
16
+ * - `renderHTML` emits `data-run-id` only when the attribute is set, so the
17
+ * live editor's DOM carries the id for the doc↔blocks bridge.
18
+ * - `parseHTML` reads `data-run-id` back so a paste / re-parse preserves it.
19
+ * - Markdown serialization deliberately IGNORES `runId`: GFM never emits it.
20
+ * `tiptap-markdown` drops attributes it has no serializer for, so we simply
21
+ * don't register a markdown serializer here — the attribute is invisible to
22
+ * the GFM round-trip and only lives in the ProseMirror JSON / DOM.
23
+ *
24
+ * Used by BOTH the headless `gfmDoc` editor and the live plan editor so the
25
+ * schema is identical on both sides of the bridge.
26
+ */
27
+ export declare const RunId: Extension<any, any>;
28
+ //# sourceMappingURL=RunId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RunId.d.ts","sourceRoot":"","sources":["../../../src/client/rich-markdown-editor/RunId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,uGAQpB,CAAC;AAEX;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,KAAK,qBAwBhB,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { Extension } from "@tiptap/core";
2
+ /**
3
+ * Node types that carry the optional `runId` attribute.
4
+ *
5
+ * These are exactly the top-level block nodes a plan's `rich-text` block can
6
+ * serialize to. The plan's `doc ↔ blocks[]` bridge stamps `runId` onto the
7
+ * FIRST node of each rich-text run so a re-parse can map the run back to its
8
+ * originating block id (stable ids across edits). Atom/structured blocks live
9
+ * in their own `planBlock` node and do not need this attribute.
10
+ */
11
+ export const RUN_ID_NODE_TYPES = [
12
+ "paragraph",
13
+ "heading",
14
+ "bulletList",
15
+ "orderedList",
16
+ "taskList",
17
+ "blockquote",
18
+ "codeBlock",
19
+ ];
20
+ /**
21
+ * Tiptap extension that adds a GLOBAL `runId` attribute (default `null`) to the
22
+ * block node types in {@link RUN_ID_NODE_TYPES}.
23
+ *
24
+ * - `renderHTML` emits `data-run-id` only when the attribute is set, so the
25
+ * live editor's DOM carries the id for the doc↔blocks bridge.
26
+ * - `parseHTML` reads `data-run-id` back so a paste / re-parse preserves it.
27
+ * - Markdown serialization deliberately IGNORES `runId`: GFM never emits it.
28
+ * `tiptap-markdown` drops attributes it has no serializer for, so we simply
29
+ * don't register a markdown serializer here — the attribute is invisible to
30
+ * the GFM round-trip and only lives in the ProseMirror JSON / DOM.
31
+ *
32
+ * Used by BOTH the headless `gfmDoc` editor and the live plan editor so the
33
+ * schema is identical on both sides of the bridge.
34
+ */
35
+ export const RunId = Extension.create({
36
+ name: "runId",
37
+ addGlobalAttributes() {
38
+ return [
39
+ {
40
+ types: [...RUN_ID_NODE_TYPES],
41
+ attributes: {
42
+ runId: {
43
+ default: null,
44
+ // Read the id off the rendered DOM so paste / re-parse round-trips.
45
+ parseHTML: (element) => element.getAttribute("data-run-id"),
46
+ // Only emit the attribute when set; an unset (null) runId adds
47
+ // nothing to the DOM so untouched nodes stay clean.
48
+ renderHTML: (attributes) => {
49
+ const runId = attributes.runId;
50
+ if (!runId)
51
+ return {};
52
+ return { "data-run-id": runId };
53
+ },
54
+ },
55
+ },
56
+ },
57
+ ];
58
+ },
59
+ });
60
+ //# sourceMappingURL=RunId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RunId.js","sourceRoot":"","sources":["../../../src/client/rich-markdown-editor/RunId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,WAAW;IACX,SAAS;IACT,YAAY;IACZ,aAAa;IACb,UAAU;IACV,YAAY;IACZ,WAAW;CACH,CAAC;AAEX;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC;IACpC,IAAI,EAAE,OAAO;IAEb,mBAAmB;QACjB,OAAO;YACL;gBACE,KAAK,EAAE,CAAC,GAAG,iBAAiB,CAAC;gBAC7B,UAAU,EAAE;oBACV,KAAK,EAAE;wBACL,OAAO,EAAE,IAAI;wBACb,oEAAoE;wBACpE,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC;wBAC3D,+DAA+D;wBAC/D,oDAAoD;wBACpD,UAAU,EAAE,CAAC,UAAU,EAAE,EAAE;4BACzB,MAAM,KAAK,GAAI,UAAwC,CAAC,KAAK,CAAC;4BAC9D,IAAI,CAAC,KAAK;gCAAE,OAAO,EAAE,CAAC;4BACtB,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;wBAClC,CAAC;qBACF;iBACF;aACF;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { Extension } from \"@tiptap/core\";\n\n/**\n * Node types that carry the optional `runId` attribute.\n *\n * These are exactly the top-level block nodes a plan's `rich-text` block can\n * serialize to. The plan's `doc ↔ blocks[]` bridge stamps `runId` onto the\n * FIRST node of each rich-text run so a re-parse can map the run back to its\n * originating block id (stable ids across edits). Atom/structured blocks live\n * in their own `planBlock` node and do not need this attribute.\n */\nexport const RUN_ID_NODE_TYPES = [\n \"paragraph\",\n \"heading\",\n \"bulletList\",\n \"orderedList\",\n \"taskList\",\n \"blockquote\",\n \"codeBlock\",\n] as const;\n\n/**\n * Tiptap extension that adds a GLOBAL `runId` attribute (default `null`) to the\n * block node types in {@link RUN_ID_NODE_TYPES}.\n *\n * - `renderHTML` emits `data-run-id` only when the attribute is set, so the\n * live editor's DOM carries the id for the doc↔blocks bridge.\n * - `parseHTML` reads `data-run-id` back so a paste / re-parse preserves it.\n * - Markdown serialization deliberately IGNORES `runId`: GFM never emits it.\n * `tiptap-markdown` drops attributes it has no serializer for, so we simply\n * don't register a markdown serializer here — the attribute is invisible to\n * the GFM round-trip and only lives in the ProseMirror JSON / DOM.\n *\n * Used by BOTH the headless `gfmDoc` editor and the live plan editor so the\n * schema is identical on both sides of the bridge.\n */\nexport const RunId = Extension.create({\n name: \"runId\",\n\n addGlobalAttributes() {\n return [\n {\n types: [...RUN_ID_NODE_TYPES],\n attributes: {\n runId: {\n default: null,\n // Read the id off the rendered DOM so paste / re-parse round-trips.\n parseHTML: (element) => element.getAttribute(\"data-run-id\"),\n // Only emit the attribute when set; an unset (null) runId adds\n // nothing to the DOM so untouched nodes stay clean.\n renderHTML: (attributes) => {\n const runId = (attributes as { runId?: string | null }).runId;\n if (!runId) return {};\n return { \"data-run-id\": runId };\n },\n },\n },\n },\n ];\n },\n});\n"]}
@@ -45,6 +45,30 @@ export interface SharedRichEditorProps {
45
45
  slashItems?: SlashCommandItem[];
46
46
  /** Override the bubble-toolbar item builder. */
47
47
  buildBubbleItems?: (editor: import("@tiptap/react").Editor, toggleLink: () => void) => BubbleToolbarItem[];
48
+ /**
49
+ * Override how the editor's content is read into the canonical `value`.
50
+ * Defaults to the tiptap-markdown storage reader. Apps with a custom on-disk
51
+ * format (Content's NFM, the plan's `blocks[]` JSON) pass their serializer so
52
+ * seed/reconcile/onChange all speak the same value space.
53
+ */
54
+ getMarkdown?: (editor: import("@tiptap/react").Editor) => string;
55
+ /** Override how the canonical `value` is applied into the editor (seed + reconcile). */
56
+ setContent?: (editor: import("@tiptap/react").Editor, value: string, options: {
57
+ emitUpdate?: boolean;
58
+ addToHistory?: boolean;
59
+ }) => void;
60
+ /** Canonicalize `value` for the echo / already-in-sync equality checks. */
61
+ normalizeValue?: (value: string) => string;
62
+ /** Override the empty-doc seed predicate (see {@link useCollabReconcile}). */
63
+ shouldSeed?: (info: {
64
+ value: string;
65
+ currentMarkdown: string;
66
+ fragmentLength: number;
67
+ }) => boolean;
68
+ /** Initial "applied" watermark (see {@link useCollabReconcile}). */
69
+ initialAppliedUpdatedAt?: string | null;
70
+ /** Extra class on the editor wrapper (e.g. a drag-handle `wrapperSelector` hook). */
71
+ wrapperClassName?: string;
48
72
  }
49
73
  /**
50
74
  * The single shared rich markdown editor surface. Combines
@@ -57,5 +81,5 @@ export interface SharedRichEditorProps {
57
81
  * With a `ydoc` it binds the framework collaboration stack; markdown stays the
58
82
  * canonical saved representation while the Y.Doc is transient live state.
59
83
  */
60
- export declare function SharedRichEditor({ value, onChange, onBlur, contentUpdatedAt, editable, dialect, preset, features, onImageUpload, extraExtensions, placeholder, className, editorClassName, interactive, ydoc, awareness, user, slashItems, buildBubbleItems, }: SharedRichEditorProps): import("react/jsx-runtime").JSX.Element;
84
+ export declare function SharedRichEditor({ value, onChange, onBlur, contentUpdatedAt, editable, dialect, preset, features, onImageUpload, extraExtensions, placeholder, className, editorClassName, interactive, ydoc, awareness, user, slashItems, buildBubbleItems, getMarkdown, setContent, normalizeValue, shouldSeed, initialAppliedUpdatedAt, wrapperClassName, }: SharedRichEditorProps): import("react/jsx-runtime").JSX.Element;
61
85
  //# sourceMappingURL=SharedRichEditor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SharedRichEditor.d.ts","sourceRoot":"","sources":["../../../src/client/rich-markdown-editor/SharedRichEditor.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,EAAE,GAAG,IAAI,IAAI,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,sBAAsB,GAAG,IAAI,CAAC;IACrC,kDAAkD;IAClD,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAChC,gDAAgD;IAChD,gBAAgB,CAAC,EAAE,CACjB,MAAM,EAAE,OAAO,eAAe,EAAE,MAAM,EACtC,UAAU,EAAE,MAAM,IAAI,KACnB,iBAAiB,EAAE,CAAC;CAC1B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,KAAK,EACL,QAAQ,EACR,MAAM,EACN,gBAAgB,EAChB,QAAe,EACf,OAAe,EACf,MAAe,EACf,QAAQ,EACR,aAAoB,EACpB,eAAe,EACf,WAAwC,EACxC,SAAS,EACT,eAAe,EACf,WAAsB,EACtB,IAAW,EACX,SAAgB,EAChB,IAAW,EACX,UAAU,EACV,gBAAgB,GACjB,EAAE,qBAAqB,2CAqIvB"}
1
+ {"version":3,"file":"SharedRichEditor.d.ts","sourceRoot":"","sources":["../../../src/client/rich-markdown-editor/SharedRichEditor.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,EAAE,GAAG,IAAI,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMzD,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE3E,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,QAA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,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,KACtD,IAAI,CAAC;IACV,2EAA2E;IAC3E,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3C,8EAA8E;IAC9E,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,eAAe,EAAE,MAAM,CAAC;QACxB,cAAc,EAAE,MAAM,CAAC;KACxB,KAAK,OAAO,CAAC;IACd,oEAAoE;IACpE,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,KAAK,EACL,QAAQ,EACR,MAAM,EACN,gBAAgB,EAChB,QAAe,EACf,OAAe,EACf,MAAe,EACf,QAAQ,EACR,aAAoB,EACpB,eAAe,EACf,WAAwC,EACxC,SAAS,EACT,eAAe,EACf,WAAsB,EACtB,IAAW,EACX,SAAgB,EAChB,IAAW,EACX,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,cAAc,EACd,UAAU,EACV,uBAAuB,EACvB,gBAAgB,GACjB,EAAE,qBAAqB,2CA+IvB"}
@@ -17,7 +17,8 @@ import { BubbleToolbar } from "./BubbleToolbar.js";
17
17
  * With a `ydoc` it binds the framework collaboration stack; markdown stays the
18
18
  * canonical saved representation while the Y.Doc is transient live state.
19
19
  */
20
- export function SharedRichEditor({ value, onChange, onBlur, contentUpdatedAt, editable = true, dialect = "gfm", preset = "plan", features, onImageUpload = null, extraExtensions, placeholder = "Type '/' for commands...", className, editorClassName, interactive = editable, ydoc = null, awareness = null, user = null, slashItems, buildBubbleItems, }) {
20
+ export function SharedRichEditor({ value, onChange, onBlur, contentUpdatedAt, editable = true, dialect = "gfm", preset = "plan", features, onImageUpload = null, extraExtensions, placeholder = "Type '/' for commands...", className, editorClassName, interactive = editable, ydoc = null, awareness = null, user = null, slashItems, buildBubbleItems, getMarkdown, setContent, normalizeValue, shouldSeed, initialAppliedUpdatedAt, wrapperClassName, }) {
21
+ const readMarkdown = getMarkdown ?? getEditorMarkdown;
21
22
  const onChangeRef = useRef(onChange);
22
23
  const onBlurRef = useRef(onBlur);
23
24
  onChangeRef.current = onChange;
@@ -63,7 +64,11 @@ export function SharedRichEditor({ value, onChange, onBlur, contentUpdatedAt, ed
63
64
  // prop and the Y.Doc, firing a spurious initial update that could autosave a
64
65
  // stale value over newer SQL. The lead-client seed effect populates an empty
65
66
  // doc instead. Non-collab editors keep initializing from `value`.
66
- content: collab ? undefined : value,
67
+ // With Collaboration the Y.Doc owns the prose (seeded by the lead client).
68
+ // With a custom `setContent` the reconcile seeds the editor too (the raw
69
+ // `value` is not directly settable content — e.g. the plan's blocks JSON),
70
+ // so only the plain markdown path seeds from `value` here.
71
+ content: collab || setContent ? undefined : value,
67
72
  editable,
68
73
  editorProps: {
69
74
  attributes: {
@@ -75,7 +80,7 @@ export function SharedRichEditor({ value, onChange, onBlur, contentUpdatedAt, ed
75
80
  if (!guards || guards.shouldIgnoreUpdate(transaction))
76
81
  return;
77
82
  try {
78
- const markdown = getEditorMarkdown(editor);
83
+ const markdown = readMarkdown(editor);
79
84
  if (!guards.registerEmitted(markdown))
80
85
  return;
81
86
  queueMicrotask(() => onChangeRef.current(markdown));
@@ -95,7 +100,11 @@ export function SharedRichEditor({ value, onChange, onBlur, contentUpdatedAt, ed
95
100
  value,
96
101
  contentUpdatedAt,
97
102
  editable,
98
- getMarkdown: getEditorMarkdown,
103
+ getMarkdown: readMarkdown,
104
+ setContent,
105
+ normalizeValue,
106
+ shouldSeed,
107
+ initialAppliedUpdatedAt,
99
108
  });
100
109
  guardsRef.current = collabState;
101
110
  useEffect(() => {
@@ -116,6 +125,6 @@ export function SharedRichEditor({ value, onChange, onBlur, contentUpdatedAt, ed
116
125
  if (!editor) {
117
126
  return (_jsx("div", { className: cn("an-rich-md-wrapper an-rich-md-loading", className), "data-plan-interactive": interactive ? true : undefined }));
118
127
  }
119
- return (_jsxs("div", { className: cn("an-rich-md-wrapper an-rich-md-clickable", !editable && "an-rich-md-wrapper--readonly", className), onClick: handleWrapperClick, "data-plan-interactive": interactive ? true : undefined, children: [editable ? (_jsx(BubbleToolbar, { editor: editor, buildItems: buildBubbleItems })) : null, editable ? (_jsx(SlashCommandMenu, { editor: editor, items: slashItems })) : null, _jsx(EditorContent, { editor: editor })] }));
128
+ return (_jsxs("div", { className: cn("an-rich-md-wrapper an-rich-md-clickable", !editable && "an-rich-md-wrapper--readonly", wrapperClassName, className), onClick: handleWrapperClick, "data-plan-interactive": interactive ? true : undefined, children: [editable ? (_jsx(BubbleToolbar, { editor: editor, buildItems: buildBubbleItems })) : null, editable ? (_jsx(SlashCommandMenu, { editor: editor, items: slashItems })) : null, _jsx(EditorContent, { editor: editor })] }));
120
129
  }
121
130
  //# sourceMappingURL=SharedRichEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SharedRichEditor.js","sourceRoot":"","sources":["../../../src/client/rich-markdown-editor/SharedRichEditor.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAIzD,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EACL,4BAA4B,GAK7B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,kBAAkB,EAClB,iBAAiB,GAElB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAyB,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,aAAa,EAA0B,MAAM,oBAAoB,CAAC;AA+C3E;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,KAAK,EACL,QAAQ,E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AAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAI,CACxD,CAAC,CAAC,CAAC,IAAI,EACR,KAAC,aAAa,IAAC,MAAM,EAAE,MAAM,GAAI,IAC7B,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { useEffect, useMemo, useRef } from \"react\";\nimport { EditorContent, useEditor } from \"@tiptap/react\";\nimport type { Extension, Node, Mark } from \"@tiptap/core\";\nimport type { Doc as YDoc } from \"yjs\";\nimport type { Awareness } from \"y-protocols/awareness\";\nimport { cn } from \"../utils.js\";\nimport {\n createSharedEditorExtensions,\n type RichMarkdownDialect,\n type RichMarkdownEditorPreset,\n type RichMarkdownCollabUser,\n type SharedEditorFeatures,\n} from \"./extensions.js\";\nimport type { ImageUploadFn } from \"./ImageExtension.js\";\nimport {\n useCollabReconcile,\n getEditorMarkdown,\n type UseCollabReconcileResult,\n} from \"./useCollabReconcile.js\";\nimport { SlashCommandMenu, type SlashCommandItem } from \"./SlashCommandMenu.js\";\nimport { BubbleToolbar, type BubbleToolbarItem } from \"./BubbleToolbar.js\";\n\nexport interface SharedRichEditorProps {\n value: string;\n onChange: (markdown: string) => void;\n onBlur?: () => void;\n contentUpdatedAt?: string | null;\n editable?: boolean;\n dialect?: RichMarkdownDialect;\n preset?: RichMarkdownEditorPreset;\n /** Toggle individual base extensions (tables/tasks/link/codeBlock/image). */\n features?: SharedEditorFeatures;\n /**\n * Injectable image uploader for the shared image block. Used only when\n * `features.image` is on. Pass `uploadEditorImage` (the framework\n * `upload-image` action) for a real uploading image block.\n */\n onImageUpload?: ImageUploadFn | null;\n /**\n * App-specific extensions (Notion nodes, media, drag handles, comment\n * anchors, …) appended after the shared base schema.\n */\n extraExtensions?: Array<Extension | Node | Mark>;\n placeholder?: string;\n className?: string;\n editorClassName?: string;\n interactive?: boolean;\n /**\n * Yjs document for real-time multi-user editing. When provided, prose is\n * authored against the shared Y.Doc and mirrored back to `value` as markdown\n * (still the source of truth). When omitted, the editor is a plain controlled\n * `value`/`onChange` editor — the existing, non-collaborative behavior.\n */\n ydoc?: YDoc | null;\n /** Shared awareness instance for live cursors/presence. */\n awareness?: Awareness | null;\n /** Current user info for the collaborative cursor label. */\n user?: RichMarkdownCollabUser | null;\n /** Override the slash-menu block command list. */\n slashItems?: SlashCommandItem[];\n /** Override the bubble-toolbar item builder. */\n buildBubbleItems?: (\n editor: import(\"@tiptap/react\").Editor,\n toggleLink: () => void,\n ) => BubbleToolbarItem[];\n}\n\n/**\n * The single shared rich markdown editor surface. Combines\n * {@link createSharedEditorExtensions} (schema + dialect-keyed markdown +\n * optional collab + app extras), {@link useCollabReconcile} (seed / reconcile /\n * lead-client logic), and the shared {@link SlashCommandMenu} +\n * {@link BubbleToolbar}.\n *\n * With no `ydoc` it is a controlled `value`/`onChange` single-user editor.\n * With a `ydoc` it binds the framework collaboration stack; markdown stays the\n * canonical saved representation while the Y.Doc is transient live state.\n */\nexport function SharedRichEditor({\n value,\n onChange,\n onBlur,\n contentUpdatedAt,\n editable = true,\n dialect = \"gfm\",\n preset = \"plan\",\n features,\n onImageUpload = null,\n extraExtensions,\n placeholder = \"Type '/' for commands...\",\n className,\n editorClassName,\n interactive = editable,\n ydoc = null,\n awareness = null,\n user = null,\n slashItems,\n buildBubbleItems,\n}: SharedRichEditorProps) {\n const onChangeRef = useRef(onChange);\n const onBlurRef = useRef(onBlur);\n onChangeRef.current = onChange;\n onBlurRef.current = onBlur;\n\n const extensions = useMemo(\n () =>\n createSharedEditorExtensions({\n dialect,\n preset,\n placeholder,\n features,\n extraExtensions,\n onImageUpload,\n collab: ydoc ? { ydoc, awareness, user } : null,\n }),\n // `preset` is retained in the dependency list so future preset-specific\n // schema branches re-create the editor; it is currently schema-neutral. The\n // collab inputs are identity-stable per block (one Y.Doc per docId), so they\n // only change on a genuine doc switch — exactly when the editor must\n // re-create to rebind Collaboration.\n [\n dialect,\n placeholder,\n preset,\n features,\n extraExtensions,\n onImageUpload,\n ydoc,\n awareness,\n user?.name,\n user?.email,\n user?.color,\n ],\n );\n\n const collab = !!ydoc;\n\n // The collab hook needs the editor, but useEditor's `onUpdate` needs the\n // hook's guards. Break the cycle with a ref: `onUpdate` reads the guards\n // through `guardsRef`, which is populated right after the hook runs below.\n // `onUpdate` only ever fires after the editor exists, by which point the ref\n // holds the real guards.\n const guardsRef = useRef<UseCollabReconcileResult | null>(null);\n\n const editor = useEditor({\n extensions,\n // With Collaboration active the prose is owned by the shared Y.XmlFragment.\n // Seeding `content` here too would make the editor initialize from BOTH the\n // prop and the Y.Doc, firing a spurious initial update that could autosave a\n // stale value over newer SQL. The lead-client seed effect populates an empty\n // doc instead. Non-collab editors keep initializing from `value`.\n content: collab ? undefined : value,\n editable,\n editorProps: {\n attributes: {\n class: cn(\"an-rich-md-prose\", editorClassName),\n },\n },\n onUpdate: ({ editor, transaction }) => {\n const guards = guardsRef.current;\n if (!guards || guards.shouldIgnoreUpdate(transaction)) return;\n try {\n const markdown = getEditorMarkdown(editor);\n if (!guards.registerEmitted(markdown)) return;\n queueMicrotask(() => onChangeRef.current(markdown));\n } catch (error) {\n console.error(\"Markdown serialization error:\", error);\n }\n },\n onBlur: () => {\n onBlurRef.current?.();\n },\n });\n\n const collabState = useCollabReconcile({\n editor,\n ydoc,\n awareness,\n value,\n contentUpdatedAt,\n editable,\n getMarkdown: getEditorMarkdown,\n });\n guardsRef.current = collabState;\n\n useEffect(() => {\n if (!editor || editor.isDestroyed) return;\n editor.setEditable(editable);\n }, [editable, editor]);\n\n useEffect(() => () => editor?.destroy(), [editor]);\n\n const handleWrapperClick = (event: React.MouseEvent<HTMLDivElement>) => {\n if (!editable || !editor || editor.isDestroyed) return;\n const target = event.target as HTMLElement;\n if (\n target.classList.contains(\"an-rich-md-wrapper\") ||\n target.classList.contains(\"an-rich-md-clickable\")\n ) {\n editor.chain().focus(\"end\").run();\n }\n };\n\n if (!editor) {\n return (\n <div\n className={cn(\"an-rich-md-wrapper an-rich-md-loading\", className)}\n data-plan-interactive={interactive ? true : undefined}\n />\n );\n }\n\n return (\n <div\n className={cn(\n \"an-rich-md-wrapper an-rich-md-clickable\",\n !editable && \"an-rich-md-wrapper--readonly\",\n className,\n )}\n onClick={handleWrapperClick}\n data-plan-interactive={interactive ? true : undefined}\n >\n {editable ? (\n <BubbleToolbar editor={editor} buildItems={buildBubbleItems} />\n ) : null}\n {editable ? (\n <SlashCommandMenu editor={editor} items={slashItems} />\n ) : null}\n <EditorContent editor={editor} />\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"SharedRichEditor.js","sourceRoot":"","sources":["../../../src/client/rich-markdown-editor/SharedRichEditor.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAIzD,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EACL,4BAA4B,GAK7B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,kBAAkB,EAClB,iBAAiB,GAElB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAyB,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,aAAa,EAA0B,MAAM,oBAAoB,CAAC;AAwE3E;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,KAAK,EACL,QAAQ,EACR,MAAM,EACN,gBAAgB,EAChB,QAAQ,GAAG,IAAI,EACf,OAAO,GAAG,KAAK,EACf,MAAM,GAAG,MAAM,EACf,QAAQ,EACR,aAAa,GAAG,IAAI,EACpB,eAAe,EACf,WAAW,GAAG,0BAA0B,EACxC,SAAS,EACT,eAAe,EACf,WAAW,GAAG,QAAQ,EACtB,IAAI,GAAG,IAAI,EACX,SAAS,GAAG,IAAI,EAChB,IAAI,GAAG,IAAI,EACX,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,cAAc,EACd,UAAU,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AM,EAAE,MAAM,GAAI,IAC7B,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { useEffect, useMemo, useRef } from \"react\";\nimport { EditorContent, useEditor } from \"@tiptap/react\";\nimport type { Extension, Node, Mark } from \"@tiptap/core\";\nimport type { Doc as YDoc } from \"yjs\";\nimport type { Awareness } from \"y-protocols/awareness\";\nimport { cn } from \"../utils.js\";\nimport {\n createSharedEditorExtensions,\n type RichMarkdownDialect,\n type RichMarkdownEditorPreset,\n type RichMarkdownCollabUser,\n type SharedEditorFeatures,\n} from \"./extensions.js\";\nimport type { ImageUploadFn } from \"./ImageExtension.js\";\nimport {\n useCollabReconcile,\n getEditorMarkdown,\n type UseCollabReconcileResult,\n} from \"./useCollabReconcile.js\";\nimport { SlashCommandMenu, type SlashCommandItem } from \"./SlashCommandMenu.js\";\nimport { BubbleToolbar, type BubbleToolbarItem } from \"./BubbleToolbar.js\";\n\nexport interface SharedRichEditorProps {\n value: string;\n onChange: (markdown: string) => void;\n onBlur?: () => void;\n contentUpdatedAt?: string | null;\n editable?: boolean;\n dialect?: RichMarkdownDialect;\n preset?: RichMarkdownEditorPreset;\n /** Toggle individual base extensions (tables/tasks/link/codeBlock/image). */\n features?: SharedEditorFeatures;\n /**\n * Injectable image uploader for the shared image block. Used only when\n * `features.image` is on. Pass `uploadEditorImage` (the framework\n * `upload-image` action) for a real uploading image block.\n */\n onImageUpload?: ImageUploadFn | null;\n /**\n * App-specific extensions (Notion nodes, media, drag handles, comment\n * anchors, …) appended after the shared base schema.\n */\n extraExtensions?: Array<Extension | Node | Mark>;\n placeholder?: string;\n className?: string;\n editorClassName?: string;\n interactive?: boolean;\n /**\n * Yjs document for real-time multi-user editing. When provided, prose is\n * authored against the shared Y.Doc and mirrored back to `value` as markdown\n * (still the source of truth). When omitted, the editor is a plain controlled\n * `value`/`onChange` editor — the existing, non-collaborative behavior.\n */\n ydoc?: YDoc | null;\n /** Shared awareness instance for live cursors/presence. */\n awareness?: Awareness | null;\n /** Current user info for the collaborative cursor label. */\n user?: RichMarkdownCollabUser | null;\n /** Override the slash-menu block command list. */\n slashItems?: SlashCommandItem[];\n /** Override the bubble-toolbar item builder. */\n buildBubbleItems?: (\n editor: import(\"@tiptap/react\").Editor,\n toggleLink: () => void,\n ) => BubbleToolbarItem[];\n /**\n * Override how the editor's content is read into the canonical `value`.\n * Defaults to the tiptap-markdown storage reader. Apps with a custom on-disk\n * format (Content's NFM, the plan's `blocks[]` JSON) pass their serializer so\n * seed/reconcile/onChange all speak the same value space.\n */\n getMarkdown?: (editor: import(\"@tiptap/react\").Editor) => string;\n /** Override how the canonical `value` is applied into the editor (seed + reconcile). */\n setContent?: (\n editor: import(\"@tiptap/react\").Editor,\n value: string,\n options: { emitUpdate?: boolean; addToHistory?: boolean },\n ) => void;\n /** Canonicalize `value` for the echo / already-in-sync equality checks. */\n normalizeValue?: (value: string) => string;\n /** Override the empty-doc seed predicate (see {@link useCollabReconcile}). */\n shouldSeed?: (info: {\n value: string;\n currentMarkdown: string;\n fragmentLength: number;\n }) => boolean;\n /** Initial \"applied\" watermark (see {@link useCollabReconcile}). */\n initialAppliedUpdatedAt?: string | null;\n /** Extra class on the editor wrapper (e.g. a drag-handle `wrapperSelector` hook). */\n wrapperClassName?: string;\n}\n\n/**\n * The single shared rich markdown editor surface. Combines\n * {@link createSharedEditorExtensions} (schema + dialect-keyed markdown +\n * optional collab + app extras), {@link useCollabReconcile} (seed / reconcile /\n * lead-client logic), and the shared {@link SlashCommandMenu} +\n * {@link BubbleToolbar}.\n *\n * With no `ydoc` it is a controlled `value`/`onChange` single-user editor.\n * With a `ydoc` it binds the framework collaboration stack; markdown stays the\n * canonical saved representation while the Y.Doc is transient live state.\n */\nexport function SharedRichEditor({\n value,\n onChange,\n onBlur,\n contentUpdatedAt,\n editable = true,\n dialect = \"gfm\",\n preset = \"plan\",\n features,\n onImageUpload = null,\n extraExtensions,\n placeholder = \"Type '/' for commands...\",\n className,\n editorClassName,\n interactive = editable,\n ydoc = null,\n awareness = null,\n user = null,\n slashItems,\n buildBubbleItems,\n getMarkdown,\n setContent,\n normalizeValue,\n shouldSeed,\n initialAppliedUpdatedAt,\n wrapperClassName,\n}: SharedRichEditorProps) {\n const readMarkdown = getMarkdown ?? getEditorMarkdown;\n const onChangeRef = useRef(onChange);\n const onBlurRef = useRef(onBlur);\n onChangeRef.current = onChange;\n onBlurRef.current = onBlur;\n\n const extensions = useMemo(\n () =>\n createSharedEditorExtensions({\n dialect,\n preset,\n placeholder,\n features,\n extraExtensions,\n onImageUpload,\n collab: ydoc ? { ydoc, awareness, user } : null,\n }),\n // `preset` is retained in the dependency list so future preset-specific\n // schema branches re-create the editor; it is currently schema-neutral. The\n // collab inputs are identity-stable per block (one Y.Doc per docId), so they\n // only change on a genuine doc switch — exactly when the editor must\n // re-create to rebind Collaboration.\n [\n dialect,\n placeholder,\n preset,\n features,\n extraExtensions,\n onImageUpload,\n ydoc,\n awareness,\n user?.name,\n user?.email,\n user?.color,\n ],\n );\n\n const collab = !!ydoc;\n\n // The collab hook needs the editor, but useEditor's `onUpdate` needs the\n // hook's guards. Break the cycle with a ref: `onUpdate` reads the guards\n // through `guardsRef`, which is populated right after the hook runs below.\n // `onUpdate` only ever fires after the editor exists, by which point the ref\n // holds the real guards.\n const guardsRef = useRef<UseCollabReconcileResult | null>(null);\n\n const editor = useEditor({\n extensions,\n // With Collaboration active the prose is owned by the shared Y.XmlFragment.\n // Seeding `content` here too would make the editor initialize from BOTH the\n // prop and the Y.Doc, firing a spurious initial update that could autosave a\n // stale value over newer SQL. The lead-client seed effect populates an empty\n // doc instead. Non-collab editors keep initializing from `value`.\n // With Collaboration the Y.Doc owns the prose (seeded by the lead client).\n // With a custom `setContent` the reconcile seeds the editor too (the raw\n // `value` is not directly settable content — e.g. the plan's blocks JSON),\n // so only the plain markdown path seeds from `value` here.\n content: collab || setContent ? undefined : value,\n editable,\n editorProps: {\n attributes: {\n class: cn(\"an-rich-md-prose\", editorClassName),\n },\n },\n onUpdate: ({ editor, transaction }) => {\n const guards = guardsRef.current;\n if (!guards || guards.shouldIgnoreUpdate(transaction)) return;\n try {\n const markdown = readMarkdown(editor);\n if (!guards.registerEmitted(markdown)) return;\n queueMicrotask(() => onChangeRef.current(markdown));\n } catch (error) {\n console.error(\"Markdown serialization error:\", error);\n }\n },\n onBlur: () => {\n onBlurRef.current?.();\n },\n });\n\n const collabState = useCollabReconcile({\n editor,\n ydoc,\n awareness,\n value,\n contentUpdatedAt,\n editable,\n getMarkdown: readMarkdown,\n setContent,\n normalizeValue,\n shouldSeed,\n initialAppliedUpdatedAt,\n });\n guardsRef.current = collabState;\n\n useEffect(() => {\n if (!editor || editor.isDestroyed) return;\n editor.setEditable(editable);\n }, [editable, editor]);\n\n useEffect(() => () => editor?.destroy(), [editor]);\n\n const handleWrapperClick = (event: React.MouseEvent<HTMLDivElement>) => {\n if (!editable || !editor || editor.isDestroyed) return;\n const target = event.target as HTMLElement;\n if (\n target.classList.contains(\"an-rich-md-wrapper\") ||\n target.classList.contains(\"an-rich-md-clickable\")\n ) {\n editor.chain().focus(\"end\").run();\n }\n };\n\n if (!editor) {\n return (\n <div\n className={cn(\"an-rich-md-wrapper an-rich-md-loading\", className)}\n data-plan-interactive={interactive ? true : undefined}\n />\n );\n }\n\n return (\n <div\n className={cn(\n \"an-rich-md-wrapper an-rich-md-clickable\",\n !editable && \"an-rich-md-wrapper--readonly\",\n wrapperClassName,\n className,\n )}\n onClick={handleWrapperClick}\n data-plan-interactive={interactive ? true : undefined}\n >\n {editable ? (\n <BubbleToolbar editor={editor} buildItems={buildBubbleItems} />\n ) : null}\n {editable ? (\n <SlashCommandMenu editor={editor} items={slashItems} />\n ) : null}\n <EditorContent editor={editor} />\n </div>\n );\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import { type JSONContent } from "@tiptap/core";
2
+ /**
3
+ * Parse a GFM markdown string into an array of top-level ProseMirror node JSON
4
+ * (paragraph / heading / list / table / code block / etc.), matching the live
5
+ * plan editor schema (`createSharedEditorExtensions({ dialect: "gfm",
6
+ * features: { image: true } })`) plus the {@link RunId} attribute.
7
+ *
8
+ * `tiptap-markdown` registers the markdown parser, so handing the raw markdown
9
+ * string to `setContent` deserializes it (the same path the live editor uses
10
+ * when it seeds `content: markdown`). Returns the doc's child nodes; an empty
11
+ * string yields a single empty paragraph.
12
+ */
13
+ export declare function gfmToProseJSON(markdown: string): JSONContent[];
14
+ /**
15
+ * Serialize an array of top-level ProseMirror node JSON into GFM markdown. The
16
+ * `runId` attribute is omitted by GFM (the {@link RunId} extension registers no
17
+ * markdown serializer), so it never leaks into the saved markdown.
18
+ *
19
+ * The nodes are wrapped in a `doc` and set on the shared editor, then the GFM
20
+ * markdown is read from the tiptap-markdown storage — the exact serializer the
21
+ * live editor persists with, so output is byte-stable with the live save path.
22
+ */
23
+ export declare function proseJSONToGfm(nodes: JSONContent[]): string;
24
+ //# sourceMappingURL=gfmDoc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gfmDoc.d.ts","sourceRoot":"","sources":["../../../src/client/rich-markdown-editor/gfmDoc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAyDxD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,EAAE,CAM9D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,CAK3D"}