@astryxdesign/richtext 0.7.6-canary.7958bd2 → 0.7.6-canary.7ef23f2

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 (44) hide show
  1. package/package.json +18 -5
  2. package/src/CodeBlockHeaderPlugin.test.tsx +0 -97
  3. package/src/CodeSyntaxPlugin.test.tsx +0 -60
  4. package/src/MarkdownExtensionsPlugin.test.tsx +0 -279
  5. package/src/RichTextEditor.test.tsx +0 -2258
  6. package/src/TableColumnFloorPlugin.test.tsx +0 -49
  7. package/src/TableScrollRegionPlugin.test.tsx +0 -138
  8. package/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts +0 -2092
  9. package/src/__tests__/MarkdownPlugins.a11y.chromium.spec.ts +0 -483
  10. package/src/__tests__/MarkdownPluginsImportExport.a11y.chromium.spec.ts +0 -152
  11. package/src/__tests__/Playground.a11y.chromium.spec.ts +0 -755
  12. package/src/__tests__/RichTextCodeLanguages.a11y.chromium.spec.ts +0 -61
  13. package/src/__tests__/RichTextEditorToolbar.a11y.chromium.spec.ts +0 -113
  14. package/src/__tests__/RichTextView.a11y.chromium.spec.ts +0 -101
  15. package/src/__tests__/TableCellSelection.a11y.chromium.spec.ts +0 -380
  16. package/src/markdownAngleCodeSpans.test.ts +0 -92
  17. package/src/markdownAngleDestinations.test.ts +0 -332
  18. package/src/markdownCharacterReferences.test.ts +0 -202
  19. package/src/markdownCodeFence.test.ts +0 -195
  20. package/src/markdownCodeSpans.test.ts +0 -399
  21. package/src/markdownEscapes.test.ts +0 -234
  22. package/src/markdownExtensionSelection.test.ts +0 -102
  23. package/src/markdownExtensions.test.ts +0 -765
  24. package/src/markdownHeadingMarkers.test.ts +0 -132
  25. package/src/markdownIndentedFences.test.ts +0 -43
  26. package/src/markdownIndentedTables.test.ts +0 -43
  27. package/src/markdownListContinuation.test.ts +0 -34
  28. package/src/markdownListIndentation.test.ts +0 -235
  29. package/src/markdownListThematicBreak.test.ts +0 -31
  30. package/src/markdownListThematicBreakInside.test.ts +0 -64
  31. package/src/markdownOpenFence.test.ts +0 -35
  32. package/src/markdownOrderedList.test.ts +0 -62
  33. package/src/markdownQuoteMarkers.test.ts +0 -206
  34. package/src/markdownRefusedLinks.test.tsx +0 -193
  35. package/src/markdownSource.test.tsx +0 -750
  36. package/src/markdownSpaceRuns.test.ts +0 -204
  37. package/src/markdownSpacedBlockStarts.test.ts +0 -96
  38. package/src/markdownTabRuns.test.ts +0 -75
  39. package/src/markdownTable.test.tsx +0 -214
  40. package/src/markdownTableLinks.test.ts +0 -69
  41. package/src/markdownTaskList.test.tsx +0 -445
  42. package/src/markdownThematicBreak.test.tsx +0 -185
  43. package/src/publicSurface.test.ts +0 -42
  44. package/src/textSemantics.test.tsx +0 -368
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astryxdesign/richtext",
3
3
  "displayName": "Rich Text",
4
- "version": "0.7.6-canary.7958bd2",
4
+ "version": "0.7.6-canary.7ef23f2",
5
5
  "description": "Astryx rich text — a Lexical-based rich text editor and viewer, styled with Astryx design tokens.",
6
6
  "author": "Meta Open Source",
7
7
  "license": "MIT",
@@ -34,7 +34,20 @@
34
34
  "dist",
35
35
  "src",
36
36
  "README.md",
37
- "CHANGELOG.md"
37
+ "CHANGELOG.md",
38
+ "!**/*.test.*",
39
+ "!**/*.spec.js",
40
+ "!**/*.spec.jsx",
41
+ "!**/*.spec.mjs",
42
+ "!**/*.spec.cjs",
43
+ "!**/*.spec.ts",
44
+ "!**/*.spec.tsx",
45
+ "!**/*.spec.mts",
46
+ "!**/*.spec.cts",
47
+ "!**/*.spec.d.ts",
48
+ "!**/__tests__/**",
49
+ "!**/__mocks__/**",
50
+ "!**/*.bench.*"
38
51
  ],
39
52
  "exports": {
40
53
  ".": {
@@ -53,7 +66,7 @@
53
66
  },
54
67
  "peerDependencies": {
55
68
  "@stylexjs/stylex": ">=0.10.0",
56
- "@astryxdesign/core": "0.7.6-canary.7958bd2",
69
+ "@astryxdesign/core": "0.7.6-canary.7ef23f2",
57
70
  "react": ">=19.0.0",
58
71
  "react-dom": ">=19.0.0",
59
72
  "lexical": "^0.52.0",
@@ -112,8 +125,8 @@
112
125
  }
113
126
  },
114
127
  "devDependencies": {
115
- "@astryxdesign/a11y-spec": "0.7.6-canary.7958bd2",
116
- "@astryxdesign/cli": "0.7.6-canary.7958bd2",
128
+ "@astryxdesign/a11y-spec": "0.7.6-canary.7ef23f2",
129
+ "@astryxdesign/cli": "0.7.6-canary.7ef23f2",
117
130
  "@babel/cli": "^7.29.7",
118
131
  "@babel/core": "^7.29.7",
119
132
  "@babel/preset-react": "^7.29.7",
@@ -1,97 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- import {afterEach, describe, it, expect, vi} from 'vitest';
4
- import {fireEvent, render, screen, waitFor} from '@testing-library/react';
5
- import {RichTextEditor} from './RichTextEditor';
6
- import {RichTextView} from './RichTextView';
7
- import {markdownToEditorStateJSON} from './markdownSerializers';
8
-
9
- describe('code block headers (spec:AST-061 FR8)', () => {
10
- afterEach(() => {
11
- vi.restoreAllMocks();
12
- });
13
-
14
- it('labels a fenced block with its language and copies its code, outside the editable text', async () => {
15
- const writeText = vi.fn(async () => {});
16
- Object.defineProperty(navigator, 'clipboard', {
17
- configurable: true,
18
- value: {writeText},
19
- });
20
- const value = markdownToEditorStateJSON(
21
- 'Before\n\n```ts\nconst a = 1;\nconst b = 2;\n```\n',
22
- );
23
- const {container} = render(<RichTextView value={value} />);
24
- const header = await waitFor(() => {
25
- const element = container.querySelector('[data-richtext-code-header]');
26
- expect(element).not.toBeNull();
27
- return element as HTMLElement;
28
- });
29
- expect(header.textContent).toContain('ts');
30
- expect(header.closest('[contenteditable]')).toBeNull();
31
- fireEvent.click(screen.getByRole('button', {name: 'Copy code'}));
32
- await waitFor(() =>
33
- expect(writeText).toHaveBeenCalledWith('const a = 1;\nconst b = 2;'),
34
- );
35
- });
36
-
37
- it('shows only the copy button when the block names no language', async () => {
38
- const {container} = render(
39
- <RichTextView value={markdownToEditorStateJSON('```\nplain\n```\n')} />,
40
- );
41
- // The header's text ends with the copy button's tooltip, which its layer
42
- // draws in a later render than the header itself: wait for the text, not
43
- // only for the header.
44
- await waitFor(() =>
45
- expect(
46
- container.querySelector('[data-richtext-code-header]')?.textContent,
47
- ).toBe('Copy code'),
48
- );
49
- expect(screen.getByRole('button', {name: 'Copy code'})).toBeTruthy();
50
- });
51
-
52
- it('names no language for a plaintext fence, as core CodeBlock does', async () => {
53
- const {container} = render(
54
- <RichTextView
55
- value={markdownToEditorStateJSON(
56
- '```plaintext\nas typed\n```\n\n```Plaintext\ncased\n```\n',
57
- )}
58
- />,
59
- );
60
- // Exactly `plaintext` names nothing; core compares it case-sensitively.
61
- // Each header's text ends with its copy button's tooltip, drawn in a later
62
- // render than the header: wait for the text.
63
- await waitFor(() =>
64
- expect(
65
- [...container.querySelectorAll('[data-richtext-code-header]')].map(
66
- header => header.textContent,
67
- ),
68
- ).toEqual(['Copy code', 'PlaintextCopy code']),
69
- );
70
- });
71
-
72
- it('draws one header per code block in the editor, outside the editable text', async () => {
73
- const {container} = render(
74
- <RichTextEditor
75
- label="Notes"
76
- defaultValue={markdownToEditorStateJSON(
77
- '```ts\none\n```\n\nText\n\n```js\ntwo\n```\n',
78
- )}
79
- />,
80
- );
81
- // Each header: its language label, then the copy button's tooltip, which
82
- // its layer draws in a later render than the header: wait for the text.
83
- await waitFor(() =>
84
- expect(
85
- [...container.querySelectorAll('[data-richtext-code-header]')].map(
86
- header => header.textContent,
87
- ),
88
- ).toEqual(['tsCopy code', 'jsCopy code']),
89
- );
90
- const headers = [
91
- ...container.querySelectorAll('[data-richtext-code-header]'),
92
- ];
93
- for (const header of headers) {
94
- expect(header.closest('[contenteditable]')).toBeNull();
95
- }
96
- });
97
- });
@@ -1,60 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- import {describe, it, expect} from 'vitest';
4
- import {render, screen} from '@testing-library/react';
5
- import {tokenize} from '@astryxdesign/core/CodeBlock';
6
- import {thrift} from '@astryxdesign/core/CodeBlock/languages/thrift';
7
- import {listedLanguage, sameLanguages} from './codeLanguages';
8
- import {renderedTokens} from './CodeSyntaxPlugin';
9
- import {RichTextView} from './RichTextView';
10
- import {markdownToEditorStateJSON} from './markdownSerializers';
11
-
12
- describe('code block syntax colors (spec:AST-061 FR1)', () => {
13
- const code = 'let a = 1;\nreturn a;';
14
-
15
- it("uses core CodeBlock's tokens line by line when the text keeps its line breaks", () => {
16
- expect(renderedTokens(code, 'ts', code)).toEqual(tokenize(code, 'ts'));
17
- });
18
-
19
- it('paints a listed language value, as Markdown does (CodeBlock FR13)', () => {
20
- const idl = 'struct User {}';
21
- expect(renderedTokens(idl, 'thrift', idl)?.flat()).toEqual([]);
22
- expect(
23
- renderedTokens(idl, listedLanguage([thrift], 'thrift') ?? 'thrift', idl)
24
- ?.flat()
25
- .map(t => t.type),
26
- ).toContain('keyword');
27
- expect(listedLanguage([thrift], 'graphql')).toBeUndefined();
28
- });
29
-
30
- it('treats lists naming the same values as the same', () => {
31
- expect(sameLanguages([thrift], [thrift])).toBe(true);
32
- expect(sameLanguages(undefined, undefined)).toBe(true);
33
- expect(sameLanguages([thrift], [])).toBe(false);
34
- expect(sameLanguages([thrift], undefined)).toBe(false);
35
- });
36
-
37
- it('lays the tokens over the text as one line when line breaks render without text', () => {
38
- const rendered = code.replace('\n', '');
39
- const [line] = renderedTokens(code, 'ts', rendered) ?? [];
40
- const texts = (line ?? []).map(
41
- token => `${token.type}:${rendered.slice(token.start, token.end)}`,
42
- );
43
- expect(texts).toContain('keyword:let');
44
- expect(texts).toContain('keyword:return');
45
- });
46
-
47
- it('colors nothing while the rendered text is not the code, or for a language core does not know', () => {
48
- expect(renderedTokens(code, 'ts', 'let a')).toBeNull();
49
- expect(renderedTokens(code, 'notalanguage', code)).toEqual([]);
50
- });
51
-
52
- it('renders code blocks where the Highlight API is missing', async () => {
53
- render(
54
- <RichTextView
55
- value={markdownToEditorStateJSON('```ts\nlet plain = 1;\n```\n')}
56
- />,
57
- );
58
- expect(await screen.findByText('let plain = 1;')).toBeInTheDocument();
59
- });
60
- });
@@ -1,279 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- import {describe, expect, it, vi} from 'vitest';
4
- import {createRef} from 'react';
5
- import {render, waitFor} from '@testing-library/react';
6
- import {Markdown} from '@astryxdesign/core/Markdown';
7
- import {
8
- createMarkdownPlugin,
9
- type MarkdownExtensionNode,
10
- } from '@astryxdesign/core/Markdown/plugins';
11
- import {RichTextEditor, type RichTextEditorRef} from './RichTextEditor';
12
- import {RichTextView} from './RichTextView';
13
- import {
14
- createRichTextExtension,
15
- markdownToEditorStateJSON,
16
- RichTextExtensionError,
17
- } from './markdown';
18
-
19
- type MentionNode = MarkdownExtensionNode<
20
- 'demo-mentions',
21
- 'mention',
22
- {readonly label: string},
23
- 'inline'
24
- >;
25
- type NoteNode = MarkdownExtensionNode<
26
- 'demo-notes',
27
- 'note',
28
- {readonly body: string},
29
- 'block'
30
- >;
31
-
32
- const mentions = createMarkdownPlugin<'demo-mentions', MentionNode>({
33
- name: 'demo-mentions',
34
- apiVersion: 1,
35
- parseKey: 'v1',
36
- syntax: {
37
- inline: [
38
- {
39
- startsWith: ['@{'],
40
- maxSpan: 80,
41
- tokenize({source, offset, end}) {
42
- const close = source.indexOf('}', offset + 2);
43
- if (close < 0 || close >= end) {
44
- return {status: 'no-match'};
45
- }
46
- return {
47
- status: 'match',
48
- end: close + 1,
49
- node: {
50
- type: 'extension',
51
- plugin: 'demo-mentions',
52
- name: 'mention',
53
- display: 'inline',
54
- data: {label: source.slice(offset + 2, close)},
55
- },
56
- };
57
- },
58
- },
59
- ],
60
- },
61
- renderers: {
62
- mention: {
63
- render: ({node}) => {
64
- if (node.data.label === 'broken') {
65
- throw new Error('broken mention');
66
- }
67
- return <mark data-mention={node.data.label}>@{node.data.label}</mark>;
68
- },
69
- toText: node => `@${node.data.label}`,
70
- },
71
- },
72
- });
73
-
74
- const notes = createMarkdownPlugin<'demo-notes', NoteNode>({
75
- name: 'demo-notes',
76
- apiVersion: 1,
77
- parseKey: 'v1',
78
- syntax: {
79
- block: [
80
- {
81
- startsWith: [':::note'],
82
- maxSpan: 500,
83
- tokenize({source, offset, end}) {
84
- const close = source.indexOf('\n:::', offset);
85
- if (close < 0 || close + 4 > end) {
86
- return {status: 'no-match'};
87
- }
88
- return {
89
- status: 'match',
90
- end: close + 4,
91
- node: {
92
- type: 'extension',
93
- plugin: 'demo-notes',
94
- name: 'note',
95
- display: 'block',
96
- data: {body: source.slice(offset + 8, close)},
97
- },
98
- };
99
- },
100
- },
101
- ],
102
- },
103
- renderers: {
104
- note: {
105
- render: ({node}) => <aside data-note="">{node.data.body}</aside>,
106
- toText: node => node.data.body,
107
- },
108
- },
109
- });
110
-
111
- const EXTENSIONS = [
112
- createRichTextExtension(mentions),
113
- createRichTextExtension(notes),
114
- ];
115
-
116
- const SOURCE = 'Hi @{ada} and @{broken}.\n\n:::note\nRemember this\n:::\n';
117
-
118
- /** The HTML each plugin node renders inside its RichText element. */
119
- function richTextNodes(root: Element): Array<string> {
120
- return [...root.querySelectorAll('[data-lexical-decorator="true"]')].map(
121
- element => element.innerHTML,
122
- );
123
- }
124
-
125
- describe('Markdown plugin nodes in RichText (spec:AST-064 FR8, FR11)', () => {
126
- it('renders each node exactly as core Markdown does, fallback included, in the view and the editor', async () => {
127
- const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
128
- const error = vi.spyOn(console, 'error').mockImplementation(() => {});
129
- try {
130
- const core = render(
131
- <Markdown plugins={[mentions, notes]}>{SOURCE}</Markdown>,
132
- );
133
- const expected = [
134
- core.container.querySelector('[data-mention="ada"]')?.outerHTML,
135
- '@{broken}',
136
- core.container.querySelector('[data-note]')?.outerHTML,
137
- ];
138
- expect(core.container.textContent).toContain('@{broken}');
139
- core.unmount();
140
- const value = markdownToEditorStateJSON(SOURCE, {extensions: EXTENSIONS});
141
- for (const surface of [
142
- <RichTextView
143
- key="view"
144
- value={value}
145
- markdownExtensions={EXTENSIONS}
146
- />,
147
- <RichTextEditor
148
- key="editor"
149
- label="Notes"
150
- defaultValue={value}
151
- markdownExtensions={EXTENSIONS}
152
- />,
153
- ]) {
154
- const {container, unmount} = render(surface);
155
- await waitFor(() => expect(richTextNodes(container)).toEqual(expected));
156
- // A block node is spaced as a paragraph; an inline one sits in text.
157
- const block = container.querySelector(
158
- '[data-lexical-decorator="true"] > aside',
159
- )?.parentElement;
160
- expect(block?.tagName).toBe('DIV');
161
- expect(block?.className).not.toBe('');
162
- unmount();
163
- }
164
- } finally {
165
- warn.mockRestore();
166
- error.mockRestore();
167
- }
168
- });
169
-
170
- it('draws a node inside the marks around it, as core Markdown does', async () => {
171
- const source = 'See *thanks to @{ada}* and **ask @{ada}**.\n';
172
- const core = render(<Markdown plugins={[mentions]}>{source}</Markdown>);
173
- expect(
174
- core.container.querySelector('em [data-mention="ada"]'),
175
- ).not.toBeNull();
176
- expect(
177
- core.container.querySelector('strong [data-mention="ada"]'),
178
- ).not.toBeNull();
179
- core.unmount();
180
- const {container} = render(
181
- <RichTextView
182
- value={markdownToEditorStateJSON(source, {extensions: EXTENSIONS})}
183
- markdownExtensions={EXTENSIONS}
184
- />,
185
- );
186
- await waitFor(() =>
187
- expect(richTextNodes(container)).toEqual([
188
- '<em><mark data-mention="ada">@ada</mark></em>',
189
- '<strong><mark data-mention="ada">@ada</mark></strong>',
190
- ]),
191
- );
192
- });
193
-
194
- it('shows the source of a node whose plugin the surface was not given', async () => {
195
- const value = markdownToEditorStateJSON(SOURCE, {extensions: EXTENSIONS});
196
- const {container} = render(
197
- <RichTextView
198
- value={value}
199
- markdownExtensions={[createRichTextExtension(notes)]}
200
- />,
201
- );
202
- await waitFor(() =>
203
- expect(richTextNodes(container)).toEqual([
204
- '@{ada}',
205
- '@{broken}',
206
- expect.stringContaining('data-note'),
207
- ]),
208
- );
209
- });
210
-
211
- it('derives each node again from its source and never draws stored data', async () => {
212
- const stored = JSON.parse(
213
- markdownToEditorStateJSON('Hi @{ada}.\n', {extensions: EXTENSIONS}),
214
- ) as {root: {children: Array<{children: Array<Record<string, unknown>>}>}};
215
- const node = stored.root.children[0]?.children.find(
216
- child => child.type === 'astryx-markdown-extension',
217
- );
218
- if (node == null) {
219
- throw new Error('No extension node');
220
- }
221
- node.data = {label: 'stale'};
222
- const tampered = JSON.stringify(stored);
223
- const {container, unmount} = render(
224
- <RichTextView value={tampered} markdownExtensions={EXTENSIONS} />,
225
- );
226
- await waitFor(() =>
227
- expect(richTextNodes(container)).toEqual([
228
- '<mark data-mention="ada">@ada</mark>',
229
- ]),
230
- );
231
- unmount();
232
- // A node stored under another protocol version shows its source.
233
- node.data = {label: 'ada'};
234
- node.apiVersion = 2;
235
- const other = render(
236
- <RichTextView
237
- value={JSON.stringify(stored)}
238
- markdownExtensions={EXTENSIONS}
239
- />,
240
- );
241
- await waitFor(() =>
242
- expect(richTextNodes(other.container)).toEqual(['@{ada}']),
243
- );
244
- });
245
-
246
- it('keeps every node source in getMarkdown()', async () => {
247
- const ref = createRef<RichTextEditorRef>();
248
- render(
249
- <RichTextEditor
250
- label="Notes"
251
- ref={ref}
252
- defaultValue={markdownToEditorStateJSON(SOURCE, {
253
- extensions: EXTENSIONS,
254
- })}
255
- markdownExtensions={EXTENSIONS}
256
- />,
257
- );
258
- await waitFor(() => expect(ref.current?.getMarkdown()).toBe(SOURCE));
259
- });
260
-
261
- it('refuses a configuration that adopts one plugin twice', () => {
262
- const error = vi.spyOn(console, 'error').mockImplementation(() => {});
263
- try {
264
- expect(() =>
265
- render(
266
- <RichTextView
267
- value={markdownToEditorStateJSON('x')}
268
- markdownExtensions={[
269
- createRichTextExtension(mentions),
270
- createRichTextExtension(mentions),
271
- ]}
272
- />,
273
- ),
274
- ).toThrow(RichTextExtensionError);
275
- } finally {
276
- error.mockRestore();
277
- }
278
- });
279
- });