@astryxdesign/richtext 0.7.6-canary.ccb1a52 → 0.7.6-canary.cdab2e6

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 (50) hide show
  1. package/dist/RichTextEditor.d.ts +1 -1
  2. package/dist/RichTextEditor.d.ts.map +1 -1
  3. package/dist/RichTextEditor.js +2 -2
  4. package/dist/RichTextEditorToolbar.js +2 -2
  5. package/package.json +19 -5
  6. package/src/RichTextEditor.tsx +9 -3
  7. package/src/RichTextEditorToolbar.tsx +2 -2
  8. package/src/CodeBlockHeaderPlugin.test.tsx +0 -97
  9. package/src/CodeSyntaxPlugin.test.tsx +0 -60
  10. package/src/MarkdownExtensionsPlugin.test.tsx +0 -279
  11. package/src/RichTextEditor.test.tsx +0 -2258
  12. package/src/TableColumnFloorPlugin.test.tsx +0 -49
  13. package/src/TableScrollRegionPlugin.test.tsx +0 -138
  14. package/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts +0 -2092
  15. package/src/__tests__/MarkdownPlugins.a11y.chromium.spec.ts +0 -483
  16. package/src/__tests__/MarkdownPluginsImportExport.a11y.chromium.spec.ts +0 -152
  17. package/src/__tests__/Playground.a11y.chromium.spec.ts +0 -755
  18. package/src/__tests__/RichTextCodeLanguages.a11y.chromium.spec.ts +0 -61
  19. package/src/__tests__/RichTextEditorToolbar.a11y.chromium.spec.ts +0 -113
  20. package/src/__tests__/RichTextView.a11y.chromium.spec.ts +0 -101
  21. package/src/__tests__/TableCellSelection.a11y.chromium.spec.ts +0 -380
  22. package/src/markdownAngleCodeSpans.test.ts +0 -92
  23. package/src/markdownAngleDestinations.test.ts +0 -332
  24. package/src/markdownCharacterReferences.test.ts +0 -202
  25. package/src/markdownCodeFence.test.ts +0 -195
  26. package/src/markdownCodeSpans.test.ts +0 -399
  27. package/src/markdownEscapes.test.ts +0 -234
  28. package/src/markdownExtensionSelection.test.ts +0 -102
  29. package/src/markdownExtensions.test.ts +0 -765
  30. package/src/markdownHeadingMarkers.test.ts +0 -132
  31. package/src/markdownIndentedFences.test.ts +0 -43
  32. package/src/markdownIndentedTables.test.ts +0 -43
  33. package/src/markdownListContinuation.test.ts +0 -34
  34. package/src/markdownListIndentation.test.ts +0 -235
  35. package/src/markdownListThematicBreak.test.ts +0 -31
  36. package/src/markdownListThematicBreakInside.test.ts +0 -64
  37. package/src/markdownOpenFence.test.ts +0 -35
  38. package/src/markdownOrderedList.test.ts +0 -62
  39. package/src/markdownQuoteMarkers.test.ts +0 -206
  40. package/src/markdownRefusedLinks.test.tsx +0 -193
  41. package/src/markdownSource.test.tsx +0 -750
  42. package/src/markdownSpaceRuns.test.ts +0 -204
  43. package/src/markdownSpacedBlockStarts.test.ts +0 -96
  44. package/src/markdownTabRuns.test.ts +0 -75
  45. package/src/markdownTable.test.tsx +0 -214
  46. package/src/markdownTableLinks.test.ts +0 -69
  47. package/src/markdownTaskList.test.tsx +0 -445
  48. package/src/markdownThematicBreak.test.tsx +0 -185
  49. package/src/publicSurface.test.ts +0 -42
  50. package/src/textSemantics.test.tsx +0 -368
@@ -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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B;;;;OAIG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B;;;;OAIG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1C;;;;;OAKG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAC1C;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,aAAa,CAAC,yBAAyB,CAAC,CAAC;IAC9D;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IAC5C,yEAAyE;IACzE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,cAAc;2ZAiCxB,mBAAmB;;CAqPrB,CAAC"}
@@ -32,7 +32,7 @@ import { Field, inputWrapperStyles, inputStatusBorderStyles, inputStatusHoverSha
32
32
  import { useInputStatusIcon } from '@astryxdesign/core/hooks';
33
33
  import { VisuallyHidden } from '@astryxdesign/core/VisuallyHidden';
34
34
  import { useTranslator } from '@astryxdesign/core/i18n';
35
- import { mergeProps, themeProps } from '@astryxdesign/core/utils';
35
+ import { isRenderable, mergeProps, themeProps } from '@astryxdesign/core/utils';
36
36
  import { useSize } from '@astryxdesign/core/SizeContext';
37
37
  import { LexicalExtensionComposer } from '@lexical/react/LexicalExtensionComposer';
38
38
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
@@ -258,7 +258,7 @@ export const RichTextEditor = function RichTextEditor({
258
258
  });
259
259
  }
260
260
  const hasTabEscapeHint = editable && tabEscapeHint !== '';
261
- const hasToolbar = toolbar != null && typeof toolbar !== 'boolean';
261
+ const hasToolbar = isRenderable(toolbar);
262
262
  const {
263
263
  statusIcon,
264
264
  describedBy: statusTooltipDescribedBy
@@ -56,7 +56,7 @@ import { Stack } from '@astryxdesign/core/Stack';
56
56
  import { HStack, Layout, LayoutContent, LayoutFooter } from '@astryxdesign/core/Layout';
57
57
  import { getExtendedIcon } from '@astryxdesign/core/Icon';
58
58
  import { useThemeName } from '@astryxdesign/core/theme';
59
- import { rtlStyles } from '@astryxdesign/core/utils';
59
+ import { isRenderable, rtlStyles } from '@astryxdesign/core/utils';
60
60
  import '@astryxdesign/core/theme/tokens.stylex';
61
61
  import { fontWeightVars, spacingVars, typeScaleVars } from '@astryxdesign/core/theme/tokens.stylex';
62
62
  import { useTranslator } from '@astryxdesign/core/i18n';
@@ -770,7 +770,7 @@ export function RichTextEditorToolbar({
770
770
  "aria-expanded": isLinkDialogOpen,
771
771
  onMouseDown: event => event.preventDefault(),
772
772
  onPressedChange: toggleLink
773
- }, "link"), endContent != null && /*#__PURE__*/_jsxs(_Fragment, {
773
+ }, "link"), isRenderable(endContent) && /*#__PURE__*/_jsxs(_Fragment, {
774
774
  children: [/*#__PURE__*/_jsx(Divider, {
775
775
  orientation: "vertical"
776
776
  }), endContent]
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.ccb1a52",
4
+ "version": "0.7.6-canary.cdab2e6",
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.ccb1a52",
69
+ "@astryxdesign/core": "0.7.6-canary.cdab2e6",
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.ccb1a52",
116
- "@astryxdesign/cli": "0.7.6-canary.ccb1a52",
128
+ "@astryxdesign/a11y-spec": "0.7.6-canary.cdab2e6",
129
+ "@astryxdesign/cli": "0.7.6-canary.cdab2e6",
117
130
  "@babel/cli": "^7.29.7",
118
131
  "@babel/core": "^7.29.7",
119
132
  "@babel/preset-react": "^7.29.7",
@@ -135,6 +148,7 @@
135
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",
@@ -54,7 +54,12 @@ import type {BaseProps} from '@astryxdesign/core';
54
54
  import {useInputStatusIcon} from '@astryxdesign/core/hooks';
55
55
  import {VisuallyHidden} from '@astryxdesign/core/VisuallyHidden';
56
56
  import {useTranslator} from '@astryxdesign/core/i18n';
57
- import {mergeProps, themeProps, type SizeValue} from '@astryxdesign/core/utils';
57
+ import {
58
+ isRenderable,
59
+ mergeProps,
60
+ themeProps,
61
+ type SizeValue,
62
+ } from '@astryxdesign/core/utils';
58
63
  import {useSize} from '@astryxdesign/core/SizeContext';
59
64
 
60
65
  import {LexicalExtensionComposer} from '@lexical/react/LexicalExtensionComposer';
@@ -370,7 +375,7 @@ export interface RichTextEditorProps extends Omit<
370
375
  * info-tip button that reveals the message
371
376
  * @default 'attached'
372
377
  */
373
- statusVariant?: FieldStatusVariant;
378
+ statusVariant?: FieldStatusVariant | 'tooltip';
374
379
  /**
375
380
  * Width of the field. Numbers are treated as pixels, strings are used as-is
376
381
  * (e.g. `'100%'`).
@@ -599,7 +604,7 @@ export const RichTextEditor = function RichTextEditor({
599
604
  }
600
605
 
601
606
  const hasTabEscapeHint = editable && tabEscapeHint !== '';
602
- const hasToolbar = toolbar != null && typeof toolbar !== 'boolean';
607
+ const hasToolbar = isRenderable(toolbar);
603
608
 
604
609
  const {statusIcon, describedBy: statusTooltipDescribedBy} =
605
610
  useInputStatusIcon({
@@ -755,6 +760,7 @@ export const RichTextEditor = function RichTextEditor({
755
760
  <VisuallyHidden id={tabEscapeHintID}>{tabEscapeHint}</VisuallyHidden>
756
761
  )}
757
762
  </div>
763
+ {/* eslint-disable-next-line @astryx/no-nullish-jsx-guard -- `maxLength` is a number; 0 still shows its counter */}
758
764
  {maxLength != null && (
759
765
  <div
760
766
  id={counterID}
@@ -82,7 +82,7 @@ import {
82
82
  } from '@astryxdesign/core/Layout';
83
83
  import {getExtendedIcon} from '@astryxdesign/core/Icon';
84
84
  import {useThemeName} from '@astryxdesign/core/theme';
85
- import {rtlStyles} from '@astryxdesign/core/utils';
85
+ import {isRenderable, rtlStyles} from '@astryxdesign/core/utils';
86
86
  import {
87
87
  fontWeightVars,
88
88
  spacingVars,
@@ -988,7 +988,7 @@ export function RichTextEditorToolbar({
988
988
  onPressedChange={toggleLink}
989
989
  />
990
990
  )}
991
- {endContent != null && (
991
+ {isRenderable(endContent) && (
992
992
  <>
993
993
  <Divider orientation="vertical" />
994
994
  {endContent}
@@ -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
- });