@astryxdesign/richtext 0.7.5 → 0.7.6-canary.0135af4
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/dist/RichTextEditor.d.ts +1 -1
- package/dist/RichTextEditor.d.ts.map +1 -1
- package/package.json +20 -6
- package/src/RichTextEditor.tsx +1 -1
- package/src/CodeBlockHeaderPlugin.test.tsx +0 -100
- package/src/CodeSyntaxPlugin.test.tsx +0 -60
- package/src/MarkdownExtensionsPlugin.test.tsx +0 -279
- package/src/RichTextEditor.test.tsx +0 -2258
- package/src/TableColumnFloorPlugin.test.tsx +0 -49
- package/src/TableScrollRegionPlugin.test.tsx +0 -138
- package/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts +0 -2092
- package/src/__tests__/MarkdownPlugins.a11y.chromium.spec.ts +0 -483
- package/src/__tests__/MarkdownPluginsImportExport.a11y.chromium.spec.ts +0 -152
- package/src/__tests__/Playground.a11y.chromium.spec.ts +0 -755
- package/src/__tests__/RichTextCodeLanguages.a11y.chromium.spec.ts +0 -61
- package/src/__tests__/RichTextEditorToolbar.a11y.chromium.spec.ts +0 -113
- package/src/__tests__/RichTextView.a11y.chromium.spec.ts +0 -101
- package/src/__tests__/TableCellSelection.a11y.chromium.spec.ts +0 -380
- package/src/markdownAngleCodeSpans.test.ts +0 -92
- package/src/markdownAngleDestinations.test.ts +0 -332
- package/src/markdownCharacterReferences.test.ts +0 -202
- package/src/markdownCodeFence.test.ts +0 -195
- package/src/markdownCodeSpans.test.ts +0 -399
- package/src/markdownEscapes.test.ts +0 -234
- package/src/markdownExtensionSelection.test.ts +0 -102
- package/src/markdownExtensions.test.ts +0 -765
- package/src/markdownHeadingMarkers.test.ts +0 -132
- package/src/markdownIndentedFences.test.ts +0 -43
- package/src/markdownIndentedTables.test.ts +0 -43
- package/src/markdownListContinuation.test.ts +0 -34
- package/src/markdownListIndentation.test.ts +0 -235
- package/src/markdownListThematicBreak.test.ts +0 -31
- package/src/markdownListThematicBreakInside.test.ts +0 -64
- package/src/markdownOpenFence.test.ts +0 -35
- package/src/markdownOrderedList.test.ts +0 -62
- package/src/markdownQuoteMarkers.test.ts +0 -206
- package/src/markdownRefusedLinks.test.tsx +0 -193
- package/src/markdownSource.test.tsx +0 -750
- package/src/markdownSpaceRuns.test.ts +0 -204
- package/src/markdownSpacedBlockStarts.test.ts +0 -96
- package/src/markdownTabRuns.test.ts +0 -75
- package/src/markdownTable.test.tsx +0 -214
- package/src/markdownTableLinks.test.ts +0 -69
- package/src/markdownTaskList.test.tsx +0 -445
- package/src/markdownThematicBreak.test.tsx +0 -185
- package/src/publicSurface.test.ts +0 -42
- package/src/textSemantics.test.tsx +0 -368
package/dist/RichTextEditor.d.ts
CHANGED
|
@@ -141,7 +141,7 @@ export interface RichTextEditorProps extends Omit<BaseProps, 'onChange' | 'defau
|
|
|
141
141
|
* info-tip button that reveals the message
|
|
142
142
|
* @default 'attached'
|
|
143
143
|
*/
|
|
144
|
-
statusVariant?: FieldStatusVariant;
|
|
144
|
+
statusVariant?: FieldStatusVariant | 'tooltip';
|
|
145
145
|
/**
|
|
146
146
|
* Width of the field. Numbers are treated as pixels, strings are used as-is
|
|
147
147
|
* (e.g. `'100%'`).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../src/RichTextEditor.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAOL,KAAK,SAAS,EACd,KAAK,GAAG,EACT,MAAM,OAAO,CAAC;AASf,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAIlD,OAAO,EAAyB,KAAK,SAAS,EAAC,MAAM,0BAA0B,CAAC;AAqBhF,OAAO,KAAK,EAAC,yBAAyB,EAAC,MAAM,sBAAsB,CAAC;AACpE,OAAO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
|
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.
|
|
69
|
+
"@astryxdesign/core": "0.7.6-canary.0135af4",
|
|
57
70
|
"react": ">=19.0.0",
|
|
58
71
|
"react-dom": ">=19.0.0",
|
|
59
72
|
"lexical": "^0.52.0",
|
|
@@ -112,6 +125,8 @@
|
|
|
112
125
|
}
|
|
113
126
|
},
|
|
114
127
|
"devDependencies": {
|
|
128
|
+
"@astryxdesign/a11y-spec": "0.7.6-canary.0135af4",
|
|
129
|
+
"@astryxdesign/cli": "0.7.6-canary.0135af4",
|
|
115
130
|
"@babel/cli": "^7.29.7",
|
|
116
131
|
"@babel/core": "^7.29.7",
|
|
117
132
|
"@babel/preset-react": "^7.29.7",
|
|
@@ -130,11 +145,10 @@
|
|
|
130
145
|
"@lexical/utils": "^0.52.0",
|
|
131
146
|
"@stylexjs/babel-plugin": "^0.19.0",
|
|
132
147
|
"@testing-library/react": "^16.3.2",
|
|
133
|
-
"lexical": "^0.52.0"
|
|
134
|
-
"@astryxdesign/cli": "0.7.5",
|
|
135
|
-
"@astryxdesign/a11y-spec": "0.0.0"
|
|
148
|
+
"lexical": "^0.52.0"
|
|
136
149
|
},
|
|
137
150
|
"scripts": {
|
|
151
|
+
"api:report": "node ../../scripts/api-report/cli.mjs --package .",
|
|
138
152
|
"build": "node ../../scripts/clean-dist.mjs && pnpm build:esm && tsc --project tsconfig.build.json && node ../../scripts/add-declaration-extensions.mjs && pnpm build:css && node ../../scripts/check-no-dev-jsx.mjs && node ../../scripts/check-fully-specified.mjs",
|
|
139
153
|
"build:esm": "babel src --out-dir dist --extensions \".ts,.tsx\" --out-file-extension \".js\" --ignore \"**/*.test.ts,**/*.test.tsx,**/__tests__/**,**/*.perf.test.*,**/*.doc.mjs,**/*.d.ts,**/*.css,**/*.css.d.ts\" --config-file ./babel.config.cjs",
|
|
140
154
|
"build:css": "node ../../scripts/build-css.mjs --package richtext",
|
package/src/RichTextEditor.tsx
CHANGED
|
@@ -370,7 +370,7 @@ export interface RichTextEditorProps extends Omit<
|
|
|
370
370
|
* info-tip button that reveals the message
|
|
371
371
|
* @default 'attached'
|
|
372
372
|
*/
|
|
373
|
-
statusVariant?: FieldStatusVariant;
|
|
373
|
+
statusVariant?: FieldStatusVariant | 'tooltip';
|
|
374
374
|
/**
|
|
375
375
|
* Width of the field. Numbers are treated as pixels, strings are used as-is
|
|
376
376
|
* (e.g. `'100%'`).
|
|
@@ -1,100 +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
|
-
const header = await waitFor(() => {
|
|
42
|
-
const element = container.querySelector('[data-richtext-code-header]');
|
|
43
|
-
expect(element).not.toBeNull();
|
|
44
|
-
return element as HTMLElement;
|
|
45
|
-
});
|
|
46
|
-
// The button's accessible name is all the header holds.
|
|
47
|
-
expect(header.textContent).toBe('Copy code');
|
|
48
|
-
expect(screen.getByRole('button', {name: 'Copy code'})).toBeTruthy();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('names no language for a plaintext fence, as core CodeBlock does', async () => {
|
|
52
|
-
const {container} = render(
|
|
53
|
-
<RichTextView
|
|
54
|
-
value={markdownToEditorStateJSON(
|
|
55
|
-
'```plaintext\nas typed\n```\n\n```Plaintext\ncased\n```\n',
|
|
56
|
-
)}
|
|
57
|
-
/>,
|
|
58
|
-
);
|
|
59
|
-
await waitFor(() =>
|
|
60
|
-
expect(
|
|
61
|
-
container.querySelectorAll('[data-richtext-code-header]'),
|
|
62
|
-
).toHaveLength(2),
|
|
63
|
-
);
|
|
64
|
-
const headers = [
|
|
65
|
-
...container.querySelectorAll('[data-richtext-code-header]'),
|
|
66
|
-
];
|
|
67
|
-
// Exactly `plaintext` names nothing; core compares it case-sensitively.
|
|
68
|
-
expect(headers.map(header => header.textContent)).toEqual([
|
|
69
|
-
'Copy code',
|
|
70
|
-
'PlaintextCopy code',
|
|
71
|
-
]);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('draws one header per code block in the editor, outside the editable text', async () => {
|
|
75
|
-
const {container} = render(
|
|
76
|
-
<RichTextEditor
|
|
77
|
-
label="Notes"
|
|
78
|
-
defaultValue={markdownToEditorStateJSON(
|
|
79
|
-
'```ts\none\n```\n\nText\n\n```js\ntwo\n```\n',
|
|
80
|
-
)}
|
|
81
|
-
/>,
|
|
82
|
-
);
|
|
83
|
-
await waitFor(() =>
|
|
84
|
-
expect(
|
|
85
|
-
container.querySelectorAll('[data-richtext-code-header]'),
|
|
86
|
-
).toHaveLength(2),
|
|
87
|
-
);
|
|
88
|
-
const headers = [
|
|
89
|
-
...container.querySelectorAll('[data-richtext-code-header]'),
|
|
90
|
-
];
|
|
91
|
-
// Each header: its language label, then the copy button's name.
|
|
92
|
-
expect(headers.map(header => header.textContent)).toEqual([
|
|
93
|
-
'tsCopy code',
|
|
94
|
-
'jsCopy code',
|
|
95
|
-
]);
|
|
96
|
-
for (const header of headers) {
|
|
97
|
-
expect(header.closest('[contenteditable]')).toBeNull();
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
@@ -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
|
-
});
|