@vertesia/rich-text 1.6.0-dev.20260918.115658Z → 1.6.0-dev.20261004.085740Z
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/lib/vertesia-rich-text.js +84 -82
- package/lib/vertesia-rich-text.js.map +1 -1
- package/package.json +14 -13
- package/src/markdown.test.ts +0 -323
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vertesia/rich-text",
|
|
3
|
-
"version": "1.6.0-dev.
|
|
3
|
+
"version": "1.6.0-dev.20261004.085740Z",
|
|
4
4
|
"description": "Markdown-first rich-text editing primitives for Vertesia",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
9
|
"lib",
|
|
10
|
-
"src"
|
|
10
|
+
"src",
|
|
11
|
+
"!src/**/*.test.*"
|
|
11
12
|
],
|
|
12
13
|
"license": "Apache-2.0",
|
|
13
14
|
"homepage": "https://docs.vertesiahq.com",
|
|
@@ -27,18 +28,18 @@
|
|
|
27
28
|
"@tiptap/pm": "^3.31.3",
|
|
28
29
|
"@tiptap/react": "^3.31.3",
|
|
29
30
|
"@tiptap/starter-kit": "^3.31.3",
|
|
30
|
-
"marked": "^18.0.
|
|
31
|
-
"react": "19.
|
|
32
|
-
"react-dom": "19.
|
|
31
|
+
"marked": "^18.0.14",
|
|
32
|
+
"react": "19.3.0",
|
|
33
|
+
"react-dom": "19.3.0"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"@types/node": "^24.13.
|
|
36
|
-
"@types/react": "19.
|
|
37
|
-
"@types/react-dom": "19.
|
|
36
|
+
"@types/node": "^24.13.6",
|
|
37
|
+
"@types/react": "19.3.0",
|
|
38
|
+
"@types/react-dom": "19.3.0",
|
|
38
39
|
"@vertesia/tsconfig": "0.1.0",
|
|
39
|
-
"rolldown": "1.2.
|
|
40
|
+
"rolldown": "1.2.9",
|
|
40
41
|
"typescript": "7.0.2",
|
|
41
|
-
"vitest": "5.0.
|
|
42
|
+
"vitest": "5.0.1"
|
|
42
43
|
},
|
|
43
44
|
"exports": {
|
|
44
45
|
".": {
|
|
@@ -51,14 +52,14 @@
|
|
|
51
52
|
"url": "https://github.com/vertesia/composableai.git",
|
|
52
53
|
"directory": "packages/rich-text"
|
|
53
54
|
},
|
|
54
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "b51b6dc9262f81f55e2424d1e57190060f6068d7",
|
|
55
56
|
"scripts": {
|
|
56
57
|
"clean:lib": "rimraf ./lib ./tsconfig.tsbuildinfo",
|
|
57
58
|
"clean": "rimraf ./node_modules ./lib ./tsconfig.tsbuildinfo",
|
|
58
|
-
"build": "pnpm run clean:lib && tsc -p tsconfig.json && pnpm exec rolldown -c rolldown.config.js",
|
|
59
|
+
"build": "pnpm run clean:lib && tsc --checkers 1 -p tsconfig.json && pnpm exec rolldown -c rolldown.config.js",
|
|
59
60
|
"lint": "biome lint src",
|
|
60
61
|
"lint:fix": "biome lint --write src",
|
|
61
62
|
"test": "vitest run",
|
|
62
|
-
"typecheck:test": "tsc -p tsconfig.test.json --noEmit"
|
|
63
|
+
"typecheck:test": "tsc --checkers 1 -p tsconfig.test.json --noEmit"
|
|
63
64
|
}
|
|
64
65
|
}
|
package/src/markdown.test.ts
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import type { Editor, JSONContent } from '@tiptap/core';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import {
|
|
4
|
-
createMarkdownEditor,
|
|
5
|
-
getMarkdownCompatibility,
|
|
6
|
-
isMarkdownSourcePreserving,
|
|
7
|
-
isVertesiaWidgetLanguage,
|
|
8
|
-
parseMarkdown,
|
|
9
|
-
roundTripMarkdown,
|
|
10
|
-
} from './markdown.js';
|
|
11
|
-
|
|
12
|
-
const REPRESENTATIVE_DOCUMENT = `# Aurora launch brief
|
|
13
|
-
|
|
14
|
-
The **Aurora** release includes [the canonical document](store:6a56458923f5c40964a069e5),
|
|
15
|
-
an [artifact with spaces](<artifact:files/review copy.pdf>), and inline \`code\`.
|
|
16
|
-
|
|
17
|
-

|
|
18
|
-
|
|
19
|
-
## Goals
|
|
20
|
-
|
|
21
|
-
- Cut review time by 60%.
|
|
22
|
-
- Preserve source-page provenance.
|
|
23
|
-
- Keep stable anchors for comments.
|
|
24
|
-
|
|
25
|
-
| Tier | Pages | Support |
|
|
26
|
-
| :--- | ---: | :---: |
|
|
27
|
-
| Starter | 1,000 | Community |
|
|
28
|
-
| Scale | Unlimited | Dedicated |
|
|
29
|
-
|
|
30
|
-
> Review changes before publishing.
|
|
31
|
-
|
|
32
|
-
\`\`\`chart
|
|
33
|
-
{"$schema":"https://vega.github.io/schema/vega-lite/v6.json","mark":"bar","encoding":{}}
|
|
34
|
-
\`\`\`
|
|
35
|
-
|
|
36
|
-
\`\`\`mermaid
|
|
37
|
-
flowchart LR
|
|
38
|
-
Draft --> Review --> Publish
|
|
39
|
-
\`\`\`
|
|
40
|
-
|
|
41
|
-
\`\`\`expand:table
|
|
42
|
-
files/pricing.csv
|
|
43
|
-
\`\`\`
|
|
44
|
-
`;
|
|
45
|
-
|
|
46
|
-
const OPAQUE_WIDGET_DOCUMENT = `# Layout and notation
|
|
47
|
-
|
|
48
|
-
:::columns
|
|
49
|
-
:::column{width=50%}
|
|
50
|
-
Left **column**.
|
|
51
|
-
:::
|
|
52
|
-
:::column{width=50%}
|
|
53
|
-
Right column.
|
|
54
|
-
:::
|
|
55
|
-
:::
|
|
56
|
-
|
|
57
|
-
$$
|
|
58
|
-
E = mc^2
|
|
59
|
-
$$
|
|
60
|
-
|
|
61
|
-
> [!NOTE]
|
|
62
|
-
> This alert must retain its Vertesia rendering semantics.
|
|
63
|
-
`;
|
|
64
|
-
|
|
65
|
-
const TASK_LIST_DOCUMENT = `# Release checklist
|
|
66
|
-
|
|
67
|
-
- [ ] Publish the migration guide
|
|
68
|
-
- [x] Verify the conformance suite
|
|
69
|
-
- [ ] Run the browser smoke test
|
|
70
|
-
`;
|
|
71
|
-
|
|
72
|
-
const FRONTMATTER_DOCUMENT = `---
|
|
73
|
-
title: Aurora launch brief
|
|
74
|
-
tags:
|
|
75
|
-
- launch
|
|
76
|
-
- aurora
|
|
77
|
-
---
|
|
78
|
-
|
|
79
|
-
# Overview
|
|
80
|
-
|
|
81
|
-
Keep the frontmatter exact.
|
|
82
|
-
`;
|
|
83
|
-
|
|
84
|
-
function collectNodes(content: JSONContent, type: string): JSONContent[] {
|
|
85
|
-
const matches: JSONContent[] = [];
|
|
86
|
-
if (content.type === type) matches.push(content);
|
|
87
|
-
for (const child of content.content || []) matches.push(...collectNodes(child, type));
|
|
88
|
-
return matches;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function findFirstTextPosition(editor: Editor, nodeType: string): number {
|
|
92
|
-
let textPosition: number | undefined;
|
|
93
|
-
editor.state.doc.descendants((node, position) => {
|
|
94
|
-
if (textPosition === undefined && node.type.name === nodeType) textPosition = position + 2;
|
|
95
|
-
});
|
|
96
|
-
if (textPosition === undefined) throw new Error(`Expected a ${nodeType} node`);
|
|
97
|
-
return textPosition;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
describe('Vertesia Markdown conformance', () => {
|
|
101
|
-
it('preserves the document structure through parse and serialize', () => {
|
|
102
|
-
const parsed = parseMarkdown(REPRESENTATIVE_DOCUMENT);
|
|
103
|
-
const serialized = roundTripMarkdown(REPRESENTATIVE_DOCUMENT);
|
|
104
|
-
|
|
105
|
-
expect(parseMarkdown(serialized)).toEqual(parsed);
|
|
106
|
-
expect(roundTripMarkdown(serialized)).toBe(serialized);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('preserves custom links, artifact images, tables, and widget code blocks', () => {
|
|
110
|
-
const parsed = parseMarkdown(REPRESENTATIVE_DOCUMENT);
|
|
111
|
-
const serialized = roundTripMarkdown(REPRESENTATIVE_DOCUMENT);
|
|
112
|
-
const codeBlocks = collectNodes(parsed, 'codeBlock');
|
|
113
|
-
const images = collectNodes(parsed, 'image');
|
|
114
|
-
const links = collectNodes(parsed, 'text').flatMap((node) => node.marks || []);
|
|
115
|
-
|
|
116
|
-
expect(codeBlocks.map((node) => node.attrs?.language)).toEqual(['chart', 'mermaid', 'expand:table']);
|
|
117
|
-
expect(images[0]?.attrs).toMatchObject({
|
|
118
|
-
src: 'artifact:files/architecture v2.png',
|
|
119
|
-
alt: 'Architecture',
|
|
120
|
-
title: 'Aurora architecture',
|
|
121
|
-
});
|
|
122
|
-
expect(links.some((mark) => mark.attrs?.href === 'store:6a56458923f5c40964a069e5')).toBe(true);
|
|
123
|
-
expect(links.some((mark) => mark.attrs?.href === 'artifact:files/review copy.pdf')).toBe(true);
|
|
124
|
-
expect(collectNodes(parsed, 'table')).toHaveLength(1);
|
|
125
|
-
expect(serialized).toContain('[artifact with spaces](<artifact:files/review copy.pdf>)');
|
|
126
|
-
expect(serialized).toContain('');
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('round-trips table row and column insertions without changing unrelated content', () => {
|
|
130
|
-
const source = `Before the table.
|
|
131
|
-
|
|
132
|
-
| Name | Value |
|
|
133
|
-
| --- | ---: |
|
|
134
|
-
| Aurora | 1 |
|
|
135
|
-
|
|
136
|
-
After the table.
|
|
137
|
-
`;
|
|
138
|
-
const editor = createMarkdownEditor({ content: source });
|
|
139
|
-
try {
|
|
140
|
-
editor.commands.setTextSelection(findFirstTextPosition(editor, 'tableCell'));
|
|
141
|
-
|
|
142
|
-
expect(editor.commands.addRowAfter()).toBe(true);
|
|
143
|
-
expect(editor.commands.addColumnAfter()).toBe(true);
|
|
144
|
-
|
|
145
|
-
const serialized = editor.getMarkdown();
|
|
146
|
-
const parsed = parseMarkdown(serialized);
|
|
147
|
-
const table = collectNodes(parsed, 'table')[0];
|
|
148
|
-
|
|
149
|
-
expect(table?.content).toHaveLength(3);
|
|
150
|
-
expect(table?.content?.every((row) => row.content?.length === 3)).toBe(true);
|
|
151
|
-
expect(serialized).toContain('Before the table.');
|
|
152
|
-
expect(serialized).toContain('After the table.');
|
|
153
|
-
expect(roundTripMarkdown(serialized)).toBe(serialized);
|
|
154
|
-
} finally {
|
|
155
|
-
editor.destroy();
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('preserves a valid table when deleting its last row or column is not possible', () => {
|
|
160
|
-
const editor = createMarkdownEditor({
|
|
161
|
-
content: `Before.
|
|
162
|
-
|
|
163
|
-
| Name | Value |
|
|
164
|
-
| --- | --- |
|
|
165
|
-
| Aurora | 1 |
|
|
166
|
-
|
|
167
|
-
After.
|
|
168
|
-
`,
|
|
169
|
-
});
|
|
170
|
-
try {
|
|
171
|
-
editor.commands.setTextSelection(findFirstTextPosition(editor, 'tableCell'));
|
|
172
|
-
expect(editor.commands.deleteColumn()).toBe(true);
|
|
173
|
-
expect(editor.commands.deleteColumn()).toBe(false);
|
|
174
|
-
expect(editor.commands.deleteRow()).toBe(true);
|
|
175
|
-
expect(editor.commands.deleteRow()).toBe(false);
|
|
176
|
-
|
|
177
|
-
const serialized = editor.getMarkdown();
|
|
178
|
-
const table = collectNodes(parseMarkdown(serialized), 'table')[0];
|
|
179
|
-
expect(table?.content).toHaveLength(1);
|
|
180
|
-
expect(table?.content?.[0]?.content).toHaveLength(1);
|
|
181
|
-
expect(serialized).toContain('Before.');
|
|
182
|
-
expect(serialized).toContain('After.');
|
|
183
|
-
expect(roundTripMarkdown(serialized)).toBe(serialized);
|
|
184
|
-
} finally {
|
|
185
|
-
editor.destroy();
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('deletes a table without disturbing an adjacent opaque block', () => {
|
|
190
|
-
const opaqueBlock = `:::columns
|
|
191
|
-
:::column{width=100%}
|
|
192
|
-
Keep this **opaque block** intact.
|
|
193
|
-
:::
|
|
194
|
-
:::`;
|
|
195
|
-
const editor = createMarkdownEditor({
|
|
196
|
-
content: `Before.
|
|
197
|
-
|
|
198
|
-
| Name | Value |
|
|
199
|
-
| --- | --- |
|
|
200
|
-
| Aurora | 1 |
|
|
201
|
-
|
|
202
|
-
${opaqueBlock}
|
|
203
|
-
|
|
204
|
-
After.
|
|
205
|
-
`,
|
|
206
|
-
});
|
|
207
|
-
try {
|
|
208
|
-
editor.commands.setTextSelection(findFirstTextPosition(editor, 'tableCell'));
|
|
209
|
-
expect(editor.commands.deleteTable()).toBe(true);
|
|
210
|
-
|
|
211
|
-
const serialized = editor.getMarkdown();
|
|
212
|
-
const parsed = parseMarkdown(serialized);
|
|
213
|
-
expect(collectNodes(parsed, 'table')).toHaveLength(0);
|
|
214
|
-
expect(collectNodes(parsed, 'opaqueMarkdownBlock')).toHaveLength(1);
|
|
215
|
-
expect(serialized).toContain(opaqueBlock);
|
|
216
|
-
expect(serialized).toContain('Before.');
|
|
217
|
-
expect(serialized).toContain('After.');
|
|
218
|
-
expect(roundTripMarkdown(serialized)).toBe(serialized);
|
|
219
|
-
} finally {
|
|
220
|
-
editor.destroy();
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('keeps unsupported block widgets as exact opaque Markdown nodes', () => {
|
|
225
|
-
const parsed = parseMarkdown(OPAQUE_WIDGET_DOCUMENT);
|
|
226
|
-
const opaqueNodes = collectNodes(parsed, 'opaqueMarkdownBlock');
|
|
227
|
-
const serialized = roundTripMarkdown(OPAQUE_WIDGET_DOCUMENT);
|
|
228
|
-
|
|
229
|
-
expect(opaqueNodes.map((node) => node.attrs?.kind)).toEqual(['directive', 'display-math', 'github-alert']);
|
|
230
|
-
for (const node of opaqueNodes) {
|
|
231
|
-
expect(serialized).toContain(node.attrs?.raw);
|
|
232
|
-
}
|
|
233
|
-
expect(parseMarkdown(serialized)).toEqual(parsed);
|
|
234
|
-
expect(roundTripMarkdown(serialized)).toBe(serialized);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it('preserves task lists as opaque Markdown until task editing is supported', () => {
|
|
238
|
-
const parsed = parseMarkdown(TASK_LIST_DOCUMENT);
|
|
239
|
-
const taskLists = collectNodes(parsed, 'opaqueMarkdownBlock').filter(
|
|
240
|
-
(node) => node.attrs?.kind === 'task-list',
|
|
241
|
-
);
|
|
242
|
-
const serialized = roundTripMarkdown(TASK_LIST_DOCUMENT);
|
|
243
|
-
|
|
244
|
-
expect(taskLists).toHaveLength(1);
|
|
245
|
-
expect(taskLists[0]?.attrs?.raw).toContain('- [ ] Publish the migration guide');
|
|
246
|
-
expect(serialized).toContain('- [x] Verify the conformance suite');
|
|
247
|
-
expect(parseMarkdown(serialized)).toEqual(parsed);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it('preserves YAML frontmatter as an exact opaque Markdown node', () => {
|
|
251
|
-
const parsed = parseMarkdown(FRONTMATTER_DOCUMENT);
|
|
252
|
-
const frontmatter = collectNodes(parsed, 'opaqueMarkdownBlock').find(
|
|
253
|
-
(node) => node.attrs?.kind === 'frontmatter',
|
|
254
|
-
);
|
|
255
|
-
const serialized = roundTripMarkdown(FRONTMATTER_DOCUMENT);
|
|
256
|
-
|
|
257
|
-
expect(frontmatter?.attrs?.raw).toBe(`---
|
|
258
|
-
title: Aurora launch brief
|
|
259
|
-
tags:
|
|
260
|
-
- launch
|
|
261
|
-
- aurora
|
|
262
|
-
---`);
|
|
263
|
-
expect(serialized).toContain(frontmatter?.attrs?.raw);
|
|
264
|
-
expect(serialized).not.toContain('## title: Aurora launch brief');
|
|
265
|
-
expect(parseMarkdown(serialized)).toEqual(parsed);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it('does not mistake horizontal rules inside a document for frontmatter', () => {
|
|
269
|
-
const parsed = parseMarkdown(`# Before
|
|
270
|
-
|
|
271
|
-
---
|
|
272
|
-
|
|
273
|
-
Content between horizontal rules.
|
|
274
|
-
|
|
275
|
-
---
|
|
276
|
-
|
|
277
|
-
# After`);
|
|
278
|
-
const frontmatter = collectNodes(parsed, 'opaqueMarkdownBlock').filter(
|
|
279
|
-
(node) => node.attrs?.kind === 'frontmatter',
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
expect(frontmatter).toHaveLength(0);
|
|
283
|
-
expect(collectNodes(parsed, 'horizontalRule')).toHaveLength(2);
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it('detects source syntax that rich-text serialization would normalize', () => {
|
|
287
|
-
expect(isMarkdownSourcePreserving('# Canonical heading')).toBe(true);
|
|
288
|
-
expect(isMarkdownSourcePreserving('Setext heading\n==============')).toBe(false);
|
|
289
|
-
expect(getMarkdownCompatibility('# Canonical heading')).toBe('exact');
|
|
290
|
-
expect(getMarkdownCompatibility('Setext heading\n==============')).toBe('normalized');
|
|
291
|
-
expect(getMarkdownCompatibility(REPRESENTATIVE_DOCUMENT)).toBe('normalized');
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it('registers node and mark views for every important Vertesia widget shape', () => {
|
|
295
|
-
const editor = createMarkdownEditor({ content: REPRESENTATIVE_DOCUMENT, editable: false });
|
|
296
|
-
try {
|
|
297
|
-
const extensions = new Map(
|
|
298
|
-
editor.extensionManager.extensions.map((extension) => [extension.name, extension]),
|
|
299
|
-
);
|
|
300
|
-
const hook = (extensionName: string, hookName: string): unknown => {
|
|
301
|
-
const config = extensions.get(extensionName)?.config as Record<string, unknown> | undefined;
|
|
302
|
-
return config?.[hookName];
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
expect(hook('codeBlock', 'addNodeView')).toBeTypeOf('function');
|
|
306
|
-
expect(hook('image', 'addNodeView')).toBeTypeOf('function');
|
|
307
|
-
expect(hook('link', 'addMarkView')).toBeTypeOf('function');
|
|
308
|
-
expect(hook('opaqueMarkdownBlock', 'addNodeView')).toBeTypeOf('function');
|
|
309
|
-
} finally {
|
|
310
|
-
editor.destroy();
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
it('classifies only renderable Vertesia code fences as widgets', () => {
|
|
315
|
-
expect(isVertesiaWidgetLanguage('chart')).toBe(true);
|
|
316
|
-
expect(isVertesiaWidgetLanguage('vega-lite')).toBe(true);
|
|
317
|
-
expect(isVertesiaWidgetLanguage('mermaid')).toBe(true);
|
|
318
|
-
expect(isVertesiaWidgetLanguage('mockup')).toBe(true);
|
|
319
|
-
expect(isVertesiaWidgetLanguage('expand:fusion-fragment')).toBe(true);
|
|
320
|
-
expect(isVertesiaWidgetLanguage('typescript')).toBe(false);
|
|
321
|
-
expect(isVertesiaWidgetLanguage(undefined)).toBe(false);
|
|
322
|
-
});
|
|
323
|
-
});
|