@astryxdesign/richtext 0.7.5 → 0.7.6-canary.0bd3b37

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 +19 -6
  2. package/src/CodeBlockHeaderPlugin.test.tsx +0 -100
  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
@@ -1,49 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- import {describe, it, expect} from 'vitest';
4
- import {render, waitFor} from '@testing-library/react';
5
- import {RichTextEditor} from './RichTextEditor';
6
- import {RichTextView} from './RichTextView';
7
- import {markdownToEditorStateJSON} from './markdownSerializers';
8
- import {tableColumnFloors} from './TableColumnFloorPlugin';
9
-
10
- describe('table column floors (spec:AST-061 FR4)', () => {
11
- it('lets the longest cell wrap to two lines, keeps a header on one line up to a cap, and stays bounded', () => {
12
- expect(
13
- tableColumnFloors([
14
- // Header lengths, then body rows.
15
- [4, 29, 2, 3],
16
- [22, 5, 1, 120],
17
- ]),
18
- ).toEqual([
19
- // 22 / 2 = 11
20
- 11,
21
- // header capped at 20, body 5/2 → 20
22
- 20,
23
- // the 4ch minimum
24
- 4,
25
- // 120 / 2 = 60, capped at 24
26
- 24,
27
- ]);
28
- expect(tableColumnFloors([])).toEqual([]);
29
- });
30
-
31
- it('sets the floors on the header cells in the editor and the view', async () => {
32
- const value = markdownToEditorStateJSON(
33
- '| Name | Notes |\n| --- | --- |\n| Ada | Wrote the first published program |\n',
34
- );
35
- const {container} = render(
36
- <>
37
- <RichTextEditor label="Notes" defaultValue={value} />
38
- <RichTextView value={value} />
39
- </>,
40
- );
41
- await waitFor(() => {
42
- const headers = [...container.querySelectorAll('th')];
43
- expect(headers).toHaveLength(4);
44
- expect(
45
- headers.map(header => (header as HTMLElement).style.minWidth),
46
- ).toEqual(['4ch', '17ch', '4ch', '17ch']);
47
- });
48
- });
49
- });
@@ -1,138 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file TableScrollRegionPlugin.test.tsx
5
- * @input Uses vitest, @testing-library/react, RichTextView, RichTextEditor and
6
- * the Markdown serializer, with a controllable ResizeObserver
7
- * @output Tests that a table's scroll wrapper in RichTextView is a named group
8
- * that takes a tab stop only while the table overflows it, and that the
9
- * editor's wrapper is left alone
10
- * @position Testing; validates TableScrollRegionPlugin.tsx through RichTextView
11
- */
12
-
13
- import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
14
- import {act, render, waitFor} from '@testing-library/react';
15
- import {RichTextEditor} from './RichTextEditor';
16
- import {RichTextView} from './RichTextView';
17
- import {markdownToEditorStateJSON} from './markdownSerializers';
18
-
19
- const TABLE = markdownToEditorStateJSON(
20
- '| Name | Role |\n| --- | --- |\n| Ada | Engineer |',
21
- );
22
-
23
- /** jsdom has no ResizeObserver; this one lets a test fire a resize. */
24
- const observers: Array<{callback: () => void; targets: Set<Element>}> = [];
25
-
26
- class TestResizeObserver {
27
- private readonly entry: {callback: () => void; targets: Set<Element>};
28
- constructor(callback: () => void) {
29
- this.entry = {callback, targets: new Set()};
30
- observers.push(this.entry);
31
- }
32
- observe(target: Element) {
33
- this.entry.targets.add(target);
34
- }
35
- unobserve(target: Element) {
36
- this.entry.targets.delete(target);
37
- }
38
- disconnect() {
39
- this.entry.targets.clear();
40
- }
41
- }
42
-
43
- function resize(element: Element) {
44
- act(() => {
45
- for (const observer of observers) {
46
- if (observer.targets.has(element)) {
47
- observer.callback();
48
- }
49
- }
50
- });
51
- }
52
-
53
- /** jsdom lays nothing out, so widths are set by hand. */
54
- function setWidths(element: Element, scrollWidth: number, clientWidth: number) {
55
- Object.defineProperty(element, 'scrollWidth', {
56
- configurable: true,
57
- value: scrollWidth,
58
- });
59
- Object.defineProperty(element, 'clientWidth', {
60
- configurable: true,
61
- value: clientWidth,
62
- });
63
- }
64
-
65
- async function scrollWrapper(container: HTMLElement): Promise<HTMLElement> {
66
- // TablePlugin re-renders existing tables into the wrapper after mount.
67
- let wrapper: HTMLElement | null = null;
68
- await waitFor(() => {
69
- wrapper = container.querySelector('table')?.parentElement ?? null;
70
- expect(wrapper?.tagName).toBe('DIV');
71
- expect(wrapper?.getAttribute('contenteditable')).toBeNull();
72
- });
73
- return wrapper as unknown as HTMLElement;
74
- }
75
-
76
- describe('table scroll regions', () => {
77
- beforeEach(() => {
78
- observers.length = 0;
79
- vi.stubGlobal('ResizeObserver', TestResizeObserver);
80
- });
81
-
82
- afterEach(() => {
83
- vi.unstubAllGlobals();
84
- });
85
-
86
- it('names the table scroll region in RichTextView like core Table', async () => {
87
- const {container} = render(<RichTextView value={TABLE} />);
88
- const wrapper = await scrollWrapper(container);
89
- await waitFor(() => {
90
- expect(wrapper.getAttribute('role')).toBe('group');
91
- });
92
- expect(wrapper.getAttribute('aria-label')).toBe('Table');
93
- });
94
-
95
- it('adds a tab stop only while the table overflows its region', async () => {
96
- const {container} = render(<RichTextView value={TABLE} />);
97
- const wrapper = await scrollWrapper(container);
98
- await waitFor(() => {
99
- expect(wrapper.getAttribute('role')).toBe('group');
100
- });
101
- // A table that fits adds no stop.
102
- expect(wrapper.hasAttribute('tabindex')).toBe(false);
103
-
104
- setWidths(wrapper, 900, 340);
105
- resize(wrapper);
106
- expect(wrapper.getAttribute('tabindex')).toBe('0');
107
-
108
- setWidths(wrapper, 340, 340);
109
- resize(wrapper);
110
- expect(wrapper.hasAttribute('tabindex')).toBe(false);
111
- });
112
-
113
- it('follows a table whose content grows', async () => {
114
- const {container} = render(<RichTextView value={TABLE} />);
115
- const wrapper = await scrollWrapper(container);
116
- await waitFor(() => {
117
- expect(wrapper.getAttribute('role')).toBe('group');
118
- });
119
- const table = wrapper.querySelector('table');
120
- expect(table).not.toBeNull();
121
-
122
- setWidths(wrapper, 900, 340);
123
- resize(table as HTMLTableElement);
124
- expect(wrapper.getAttribute('tabindex')).toBe('0');
125
- });
126
-
127
- it('leaves the editor’s table wrapper alone, so Escape then Tab still leaves the editor', async () => {
128
- const {container} = render(
129
- <RichTextEditor label="Notes" defaultValue={TABLE} />,
130
- );
131
- const wrapper = await scrollWrapper(container);
132
- setWidths(wrapper, 900, 340);
133
- resize(wrapper);
134
- expect(wrapper.hasAttribute('role')).toBe(false);
135
- expect(wrapper.hasAttribute('aria-label')).toBe(false);
136
- expect(wrapper.hasAttribute('tabindex')).toBe(false);
137
- });
138
- });