@pie-lib/editable-html 13.0.12 → 13.0.14-beta.1

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 (29) hide show
  1. package/CHANGELOG.md +0 -46
  2. package/lib/editor.js +3 -3
  3. package/lib/editor.js.map +1 -1
  4. package/lib/plugins/respArea/math-templated/index.js +2 -2
  5. package/lib/plugins/respArea/math-templated/index.js.map +1 -1
  6. package/lib/shared/alert-dialog.js +68 -0
  7. package/package.json +7 -7
  8. package/src/editor.jsx +2 -2
  9. package/src/plugins/respArea/math-templated/index.jsx +1 -1
  10. package/LICENSE.md +0 -5
  11. package/src/__tests__/editor-utils.test.js +0 -162
  12. package/src/__tests__/serialization.test.js +0 -290
  13. package/src/__tests__/utils.js +0 -36
  14. package/src/plugins/image/__tests__/component.test.jsx +0 -73
  15. package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +0 -90
  16. package/src/plugins/image/__tests__/image-toolbar.test.jsx +0 -12
  17. package/src/plugins/image/__tests__/index.test.js +0 -92
  18. package/src/plugins/image/__tests__/insert-image-handler.test.js +0 -113
  19. package/src/plugins/image/__tests__/mock-change.js +0 -15
  20. package/src/plugins/list/__tests__/index.test.js +0 -52
  21. package/src/plugins/math/__tests__/index.test.jsx +0 -264
  22. package/src/plugins/media/__tests__/index.test.js +0 -75
  23. package/src/plugins/respArea/drag-in-the-blank/__tests__/choice.test.js +0 -71
  24. package/src/plugins/table/__tests__/index.test.jsx +0 -401
  25. package/src/plugins/table/__tests__/table-toolbar.test.jsx +0 -75
  26. package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +0 -123
  27. package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +0 -40
  28. package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +0 -97
  29. package/src/plugins/toolbar/__tests__/toolbar.test.jsx +0 -112
@@ -1,75 +0,0 @@
1
- import MediaPlugin from '../';
2
-
3
- describe('media plugin', () => {
4
- const imagePlugin = MediaPlugin('video');
5
-
6
- describe('normalizeNode', () => {
7
- it('should exit the function if the node is not of type document', () => {
8
- const returnValue = imagePlugin.normalizeNode({ object: 'image' });
9
-
10
- expect(returnValue).toEqual(undefined);
11
- });
12
-
13
- it('should exit there are no changes needed', () => {
14
- const nodes = [
15
- {
16
- object: 'text',
17
- text: 'Before Media',
18
- },
19
- {
20
- type: 'video',
21
- },
22
- {
23
- object: 'text',
24
- text: 'After Media',
25
- },
26
- ];
27
- const returnValue = imagePlugin.normalizeNode({
28
- object: 'document',
29
- findDescendant: jest.fn((callback) => {
30
- nodes.forEach((n) => callback(n));
31
- }),
32
- });
33
- expect(returnValue).toEqual(undefined);
34
- });
35
-
36
- it('should return a function if there is a node with an empty text before a media element', () => {
37
- const nodes = [
38
- {
39
- object: 'text',
40
- text: '',
41
- key: '1',
42
- },
43
- {
44
- type: 'video',
45
- key: '2',
46
- },
47
- {
48
- object: 'text',
49
- text: 'After Media',
50
- key: '3',
51
- },
52
- ];
53
- const findDescendant = jest.fn((callback) => {
54
- nodes.forEach((n) => callback(n));
55
- });
56
- const change = {
57
- withoutNormalization: jest.fn((callback) => {
58
- callback();
59
- }),
60
- insertTextByKey: jest.fn(),
61
- };
62
- const returnValue = imagePlugin.normalizeNode({
63
- object: 'document',
64
- findDescendant,
65
- });
66
-
67
- expect(returnValue).toEqual(expect.any(Function));
68
-
69
- returnValue(change);
70
-
71
- expect(change.withoutNormalization).toHaveBeenCalledWith(expect.any(Function));
72
- expect(change.insertTextByKey).toHaveBeenCalledWith('1', 0, ' ');
73
- });
74
- });
75
- });
@@ -1,71 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import DragDropChoice from '../choice';
4
-
5
- // Mock @dnd-kit hooks to avoid DndContext requirement
6
- jest.mock('@dnd-kit/core', () => ({
7
- useDraggable: jest.fn(() => ({
8
- attributes: {},
9
- listeners: {},
10
- setNodeRef: jest.fn(),
11
- isDragging: false,
12
- })),
13
- useDroppable: jest.fn(() => ({
14
- setNodeRef: jest.fn(),
15
- isOver: false,
16
- active: null,
17
- })),
18
- }));
19
-
20
- jest.mock('@pie-lib/math-rendering', () => ({
21
- renderMath: jest.fn(),
22
- }));
23
-
24
- // Collect the CSS rules emotion/MUI injected into the document (jsdom uses insertRule).
25
- const collectEmotionRules = () => {
26
- const rules = [];
27
- for (const sheet of Array.from(document.styleSheets)) {
28
- try {
29
- for (const rule of Array.from(sheet.cssRules)) {
30
- rules.push(rule.cssText);
31
- }
32
- } catch (e) {
33
- /* inaccessible stylesheet */
34
- }
35
- }
36
- return rules;
37
- };
38
-
39
- describe('drag-in-the-blank choice', () => {
40
- const defaultProps = {
41
- value: { id: '1', value: '<math>1/2</math>' },
42
- disabled: false,
43
- instanceId: 'test-instance',
44
- n: { key: 'key-0' },
45
- nodeProps: {},
46
- opts: { options: { duplicates: false } },
47
- };
48
-
49
- it('renders without crashing', () => {
50
- const { container } = render(<DragDropChoice {...defaultProps} />);
51
- expect(container.firstChild).toBeInTheDocument();
52
- });
53
-
54
- describe('fraction math styling', () => {
55
- it('enlarges numerator/denominator digits adjacent to a fraction to 120%', () => {
56
- render(<DragDropChoice {...defaultProps} />);
57
- const rule = collectEmotionRules().find((r) => r.includes('mjx-mn') && r.includes('mjx-mfrac'));
58
- expect(rule).toBeDefined();
59
- expect(rule).toMatch(/mjx-mn:has\(~\s*mjx-mfrac\)/);
60
- expect(rule).toMatch(/mjx-mfrac\s*~\s*mjx-mn/);
61
- expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
62
- });
63
-
64
- it('keeps the existing mjx-frac 120% rule', () => {
65
- render(<DragDropChoice {...defaultProps} />);
66
- const rule = collectEmotionRules().find((r) => /(^|[^-])mjx-frac/.test(r) && !r.includes('mjx-mfrac'));
67
- expect(rule).toBeDefined();
68
- expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
69
- });
70
- });
71
- });
@@ -1,401 +0,0 @@
1
- import EditTable from 'slate-edit-table';
2
- import TablePlugin, { parseStyleString, reactAttributes, serialization } from '../index';
3
- import { Block, Data, PathUtils } from 'slate';
4
- import React from 'react';
5
-
6
- jest.mock('slate-edit-table', () => {
7
- const mock = {
8
- default: jest.fn().mockReturnThis(),
9
- utils: {
10
- isSelectionInTable: jest.fn().mockReturnValue(true),
11
- createTable: jest.fn(function (c) {
12
- return {
13
- toJSON: jest.fn().mockReturnValue({ object: 'block', type: 'table' }),
14
- };
15
- }),
16
- },
17
- changes: {
18
- insertTable: jest.fn(function (c) {
19
- return c;
20
- }),
21
- },
22
- };
23
-
24
- return jest.fn().mockReturnValue(mock);
25
- });
26
-
27
- describe('table', () => {
28
- describe('toolbar', () => {
29
- describe('onClick', () => {
30
- let plugin;
31
- let onChange;
32
- let findDescendant;
33
- let insertBlock;
34
- let changeMock;
35
-
36
- beforeEach(() => {
37
- plugin = TablePlugin();
38
- onChange = jest.fn();
39
- insertBlock = jest.fn();
40
- findDescendant = jest.fn();
41
- changeMock = jest.fn().mockReturnValue({
42
- insertBlock,
43
- value: {
44
- document: {
45
- findDescendant,
46
- },
47
- },
48
- });
49
- });
50
-
51
- it('calls utils.createTable', () => {
52
- plugin.toolbar.onClick({ change: changeMock }, onChange);
53
-
54
- expect(EditTable().utils.createTable).toHaveBeenCalledWith(2, 2);
55
- });
56
-
57
- it('creates table with border: 1 as default', () => {
58
- plugin.toolbar.onClick({ change: changeMock }, onChange);
59
-
60
- expect(insertBlock).toHaveBeenCalledWith(
61
- Block.create({ key: '2', type: 'table', data: { border: '1', newTable: true } }),
62
- );
63
- });
64
-
65
- it('moves cursor to first cell of the table and removes the newTable property', () => {
66
- const dataRemoveFn = jest.fn().mockReturnValue({ border: '1' });
67
- const setNodeByKey = jest.fn();
68
- const newTableBlock = {
69
- key: '2',
70
- data: {
71
- remove: dataRemoveFn,
72
- },
73
- };
74
- const collapseToStartOf = jest.fn();
75
-
76
- changeMock = jest.fn().mockReturnValue({
77
- insertBlock,
78
- collapseToStartOf,
79
- setNodeByKey,
80
- value: {
81
- document: {
82
- findDescendant: jest.fn().mockReturnValue(newTableBlock),
83
- },
84
- },
85
- });
86
- plugin.toolbar.onClick({ change: changeMock }, onChange);
87
-
88
- expect(collapseToStartOf).toHaveBeenCalledWith(newTableBlock);
89
- expect(dataRemoveFn).toHaveBeenCalledWith('newTable');
90
- expect(setNodeByKey).toHaveBeenCalledWith('2', { data: { border: '1' } });
91
- });
92
- });
93
-
94
- describe('supports', () => {
95
- const assertSupports = (inTable, object, expected) => {
96
- it(`inTable: ${inTable}, type: ${object} => ${expected}`, () => {
97
- EditTable().utils.isSelectionInTable.mockReturnValue(inTable);
98
- const plugin = TablePlugin();
99
- const supports = plugin.toolbar.supports({ object });
100
- expect(supports).toEqual(expected);
101
- });
102
- };
103
-
104
- assertSupports(true, 'block', true);
105
- assertSupports(false, 'block', false);
106
- assertSupports(true, 'inline', false);
107
- assertSupports(false, 'inline', false);
108
- });
109
-
110
- describe('customToolbar', () => {
111
- describe('toggleBorder', () => {
112
- const assertToggle = (border, expectedBorder) => {
113
- describe(`with initial border of ${border}`, () => {
114
- let change;
115
- let done;
116
-
117
- beforeEach(() => {
118
- const plugin = TablePlugin();
119
- change = {
120
- setNodeByKey: jest.fn().mockReturnThis(),
121
- };
122
- plugin.utils.getTableBlock = jest.fn().mockReturnValue({
123
- key: 'tableKey',
124
- data: Data.create({ border }),
125
- });
126
- const node = { key: 'nodeKey' };
127
- const value = {
128
- change: jest.fn().mockReturnValue(change),
129
- };
130
- done = jest.fn();
131
- const Comp = plugin.toolbar.customToolbar(node, value, done);
132
- const c = Comp();
133
- c.props.onToggleBorder();
134
- });
135
-
136
- it(`calls setNodeByKey with ${expectedBorder}`, () => {
137
- expect(change.setNodeByKey).toHaveBeenCalledWith('tableKey', {
138
- data: Data.create({ border: expectedBorder }),
139
- });
140
- });
141
-
142
- it('calls onToolbarDone', () => {
143
- expect(done).toHaveBeenCalledWith(change, false);
144
- });
145
- });
146
- };
147
-
148
- assertToggle(null, '1');
149
- assertToggle(undefined, '1');
150
- assertToggle('0', '1');
151
- assertToggle('1', '0');
152
- assertToggle('2', '0');
153
- });
154
- });
155
-
156
- describe('normalizeNode', () => {
157
- it('should exit the function if the node is not of type document', () => {
158
- const tablePlugin = TablePlugin();
159
- const returnValue = tablePlugin.normalizeNode({ object: 'table' });
160
-
161
- expect(returnValue).toEqual(undefined);
162
- });
163
-
164
- it('should exit there are no changes needed', () => {
165
- const tablePlugin = TablePlugin();
166
- const nodes = {
167
- size: 3,
168
- findLastIndex: jest.fn().mockReturnValue(1),
169
- };
170
- const returnValue = tablePlugin.normalizeNode({
171
- object: 'document',
172
- nodes,
173
- findDescendant: jest.fn().mockReturnValue({ object: 'block', type: 'table' }),
174
- getParent: jest.fn().mockReturnValue(undefined),
175
- });
176
- expect(returnValue).toEqual(undefined);
177
- });
178
-
179
- it('should return a function if a table does not have a node before or after it', () => {
180
- const tablePlugin = TablePlugin();
181
- const nodes = [
182
- {
183
- object: 'block',
184
- type: 'table',
185
- key: '99',
186
- data: Data.create({
187
- newTable: true,
188
- }),
189
- },
190
- ];
191
- const findDescendant = jest.fn((callback) => {
192
- nodes.forEach((n) => callback(n));
193
- });
194
- const change = {
195
- insertNodeByPath: jest.fn(),
196
- value: {
197
- document: {
198
- getPath: jest.fn().mockReturnValue(PathUtils.create([0, 0])),
199
- },
200
- },
201
- };
202
-
203
- const returnValue = tablePlugin.normalizeNode({
204
- object: 'document',
205
- findDescendant,
206
- getPath: jest.fn().mockReturnValue(PathUtils.create([0, 0])),
207
- getPreviousNode: jest.fn().mockReturnValue(undefined),
208
- getNextNode: jest.fn().mockReturnValue(undefined),
209
- });
210
-
211
- expect(returnValue).toEqual(expect.any(Function));
212
-
213
- returnValue(change);
214
-
215
- expect(change.insertNodeByPath).toHaveBeenCalledWith([0], 0, {
216
- object: 'block',
217
- type: 'div',
218
- });
219
- });
220
- });
221
- });
222
- });
223
-
224
- describe('parseStyleString', () => {
225
- const parses = (s, expected) => {
226
- it(`parses ${s} -> ${JSON.stringify(expected)}`, () => {
227
- const result = parseStyleString(s);
228
- expect(result).toEqual(expected);
229
- });
230
- };
231
- parses(' width: 10px ', { width: '10px' });
232
- parses(' width: 10px; ', { width: '10px' });
233
- parses(' border-width: 10px; ', { 'border-width': '10px' });
234
- parses(' border: solid 1px red; height: 1px', {
235
- border: 'solid 1px red',
236
- height: '1px',
237
- });
238
- });
239
-
240
- describe('toStyleString', () => {
241
- const styleString = (o, expected) => {
242
- it(`${JSON.stringify(s)} -> ${expected}`, () => {
243
- const result = toStyleString(o);
244
- expect(result).toEqual(expected);
245
- });
246
- };
247
- });
248
-
249
- describe('reactAttributes', () => {
250
- const attributes = (o, expected) => {
251
- it(`${JSON.stringify(o)} -> ${JSON.stringify(expected)}`, () => {
252
- const result = reactAttributes(o);
253
- expect(result).toEqual(expected);
254
- });
255
- };
256
- attributes({ 'border-width': '10px', 'line-height': 1.56 }, { borderWidth: '10px', lineHeight: '1.56' });
257
- });
258
-
259
- describe('serialization', () => {
260
- describe('deserialize', () => {
261
- let next;
262
-
263
- beforeEach(() => {
264
- next = jest.fn().mockReturnValue([]);
265
- });
266
-
267
- describe('table', () => {
268
- let el;
269
- let out;
270
- beforeEach(() => {
271
- el = {
272
- tagName: 'table',
273
- children: [],
274
- getAttribute: jest.fn((name) => {
275
- switch (name) {
276
- case 'border':
277
- return '1';
278
- case 'cellspacing':
279
- return '2';
280
- case 'cellpadding':
281
- return '3';
282
- case 'class':
283
- return 'table-class';
284
- case 'style':
285
- return 'width: 10px';
286
- }
287
- }),
288
- };
289
- out = serialization.deserialize(el, next);
290
- });
291
-
292
- const assertData = (name, value) => {
293
- it(`data.${name} should eql ${value}`, () => {
294
- expect(out.data[name]).toEqual(value);
295
- });
296
- };
297
-
298
- assertData('border', '1');
299
- assertData('cellspacing', '2');
300
- assertData('cellpadding', '3');
301
- assertData('class', 'table-class');
302
- assertData('style', { width: '10px' });
303
- it('returns a table block', () => {
304
- expect(out).toMatchObject({
305
- object: 'block',
306
- type: 'table',
307
- nodes: [],
308
- });
309
- });
310
- });
311
-
312
- it('deserializes tr', () => {
313
- const el = {
314
- tagName: 'tr',
315
- children: [],
316
- };
317
-
318
- const out = serialization.deserialize(el, next);
319
-
320
- expect(out).toEqual({
321
- object: 'block',
322
- type: 'table_row',
323
- nodes: [],
324
- });
325
- });
326
-
327
- it('deserializes td', () => {
328
- const el = {
329
- tagName: 'td',
330
- childNodes: [],
331
- getAttribute: jest.fn(function (name) {
332
- const o = {
333
- class: 'class name',
334
- colspan: '1',
335
- rowspan: '1',
336
- };
337
- return o[name];
338
- }),
339
- };
340
-
341
- const out = serialization.deserialize(el, next);
342
-
343
- expect(out).toEqual({
344
- object: 'block',
345
- type: 'table_cell',
346
- nodes: [],
347
- data: {
348
- colspan: '1',
349
- rowspan: '1',
350
- class: 'class name',
351
- header: false,
352
- },
353
- });
354
- });
355
- });
356
-
357
- describe('serialize', () => {
358
- it('serializes table', () => {
359
- const el = serialization.serialize({
360
- object: 'block',
361
- type: 'table',
362
- nodes: [],
363
- data: Data.create({
364
- border: '1',
365
- cellpadding: '2',
366
- cellspacing: '3',
367
- }),
368
- });
369
-
370
- expect(el).toEqual(
371
- <table border="1" cellPadding="2" cellSpacing="3">
372
- <tbody />
373
- </table>,
374
- );
375
- });
376
-
377
- it('serializes table_row', () => {
378
- const el = serialization.serialize({
379
- object: 'block',
380
- type: 'table_row',
381
- nodes: [],
382
- });
383
-
384
- expect(el).toEqual(<tr />);
385
- });
386
- it('serializes table_cell', () => {
387
- const el = serialization.serialize({
388
- object: 'block',
389
- type: 'table_cell',
390
- nodes: [],
391
- data: Data.create({
392
- header: false,
393
- style: { width: '10px' },
394
- class: 'foo',
395
- }),
396
- });
397
-
398
- expect(el).toEqual(<td style={{ width: '10px' }} className={'foo'} />);
399
- });
400
- });
401
- });
@@ -1,75 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import { TableToolbar } from '../table-toolbar';
4
-
5
- describe('table-toolbar', () => {
6
- let onDone, onAddColumn, onAddRow, onRemoveColumn, onRemoveRow, onRemoveTable, onToggleBorder;
7
-
8
- beforeEach(() => {
9
- onAddColumn = jest.fn();
10
- onAddRow = jest.fn();
11
- onRemoveColumn = jest.fn();
12
- onRemoveRow = jest.fn();
13
- onRemoveTable = jest.fn();
14
- onDone = jest.fn();
15
- onToggleBorder = jest.fn();
16
- });
17
-
18
- const renderComponent = (extras = {}) => {
19
- const props = {
20
- onDone,
21
- onAddRow,
22
- onRemoveRow,
23
- onAddColumn,
24
- onRemoveColumn,
25
- onRemoveTable,
26
- hasBorder: true,
27
- onToggleBorder,
28
- classes: {
29
- tableToolbar: 'table-toolbar',
30
- },
31
- plugins: [],
32
- value: {},
33
- onChange: jest.fn(),
34
- ...extras,
35
- };
36
-
37
- return render(<TableToolbar {...props} />);
38
- };
39
-
40
- describe('rendering', () => {
41
- it('renders toolbar without crashing', () => {
42
- const { container } = renderComponent();
43
-
44
- // Check that the toolbar container is rendered
45
- expect(container.firstChild).toBeInTheDocument();
46
-
47
- // Check for Done button (only one with aria-label)
48
- expect(screen.getByLabelText('Done')).toBeInTheDocument();
49
-
50
- // Check that there are multiple buttons (table manipulation buttons)
51
- const buttons = container.querySelectorAll('button');
52
- expect(buttons.length).toBeGreaterThan(1);
53
- });
54
-
55
- it('renders with hasBorder prop', () => {
56
- const { container } = renderComponent({ hasBorder: false });
57
-
58
- expect(container.firstChild).toBeInTheDocument();
59
-
60
- // Verify hasBorder affects rendering - button with aria-pressed attribute
61
- const borderButton = container.querySelector('button[aria-pressed]');
62
- expect(borderButton).toBeInTheDocument();
63
- expect(borderButton).toHaveAttribute('aria-pressed', 'false');
64
- });
65
-
66
- it('renders with hasBorder true', () => {
67
- const { container } = renderComponent({ hasBorder: true });
68
-
69
- // Verify hasBorder affects rendering
70
- const borderButton = container.querySelector('button[aria-pressed]');
71
- expect(borderButton).toBeInTheDocument();
72
- expect(borderButton).toHaveAttribute('aria-pressed', 'true');
73
- });
74
- });
75
- });