@pie-lib/editable-html-tip-tap 2.2.0-beta.8 → 3.0.0-next.20261002094057
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/components/CharacterPicker.d.ts +31 -0
- package/dist/components/CharacterPicker.js +141 -0
- package/dist/components/EditableHtml.d.ts +11 -0
- package/dist/components/EditableHtml.js +331 -0
- package/dist/components/MenuBar.d.ts +11 -0
- package/dist/components/MenuBar.js +531 -0
- package/dist/components/TiptapContainer.d.ts +11 -0
- package/dist/components/TiptapContainer.js +167 -0
- package/dist/components/characters/characterUtils.d.ts +35 -0
- package/dist/components/characters/characterUtils.js +465 -0
- package/dist/components/characters/custom-popper.d.ts +14 -0
- package/dist/components/characters/custom-popper.js +32 -0
- package/dist/components/common/done-button.d.ts +30 -0
- package/dist/components/common/done-button.js +26 -0
- package/dist/components/common/toolbar-buttons.d.ts +38 -0
- package/dist/components/common/toolbar-buttons.js +96 -0
- package/dist/components/icons/CssIcon.d.ts +11 -0
- package/dist/components/icons/CssIcon.js +14 -0
- package/dist/components/icons/RespArea.d.ts +26 -0
- package/dist/components/icons/RespArea.js +42 -0
- package/dist/components/icons/TableIcons.d.ts +14 -0
- package/dist/components/icons/TableIcons.js +34 -0
- package/dist/components/icons/TextAlign.d.ts +18 -0
- package/dist/components/icons/TextAlign.js +143 -0
- package/dist/components/image/AltDialog.d.ts +22 -0
- package/dist/components/image/AltDialog.js +61 -0
- package/dist/components/image/ImageToolbar.d.ts +24 -0
- package/dist/components/image/ImageToolbar.js +80 -0
- package/dist/components/image/InsertImageHandler.d.ts +33 -0
- package/dist/components/image/InsertImageHandler.js +65 -0
- package/dist/components/image/findImageNode.d.ts +3 -0
- package/dist/components/image/findImageNode.js +11 -0
- package/dist/components/media/MediaDialog.d.ts +43 -0
- package/dist/components/media/MediaDialog.js +389 -0
- package/dist/components/media/MediaToolbar.d.ts +19 -0
- package/dist/components/media/MediaToolbar.js +41 -0
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts +23 -0
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.js +58 -0
- package/dist/components/respArea/DragInTheBlank/choice.d.ts +56 -0
- package/dist/components/respArea/DragInTheBlank/choice.js +157 -0
- package/dist/components/respArea/ExplicitConstructedResponse.d.ts +20 -0
- package/dist/components/respArea/ExplicitConstructedResponse.js +84 -0
- package/dist/components/respArea/InlineDropdown.d.ts +18 -0
- package/dist/components/respArea/InlineDropdown.js +126 -0
- package/dist/components/respArea/MathTemplated.d.ts +19 -0
- package/dist/components/respArea/MathTemplated.js +98 -0
- package/dist/components/respArea/ToolbarIcon.d.ts +14 -0
- package/dist/components/respArea/ToolbarIcon.js +17 -0
- package/dist/components/respArea/inlineDropdownUtils.d.ts +15 -0
- package/dist/components/respArea/inlineDropdownUtils.js +15 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.js +4 -0
- package/dist/extensions/css.d.ts +11 -0
- package/dist/extensions/css.js +120 -0
- package/dist/extensions/custom-toolbar-wrapper.d.ts +11 -0
- package/dist/extensions/custom-toolbar-wrapper.js +61 -0
- package/dist/extensions/div-node.d.ts +10 -0
- package/dist/extensions/div-node.js +42 -0
- package/dist/extensions/ensure-empty-root-div.d.ts +14 -0
- package/dist/extensions/ensure-empty-root-div.js +24 -0
- package/dist/extensions/ensure-list-item-content-is-div.d.ts +15 -0
- package/dist/extensions/ensure-list-item-content-is-div.js +31 -0
- package/dist/extensions/extended-list-item.d.ts +13 -0
- package/dist/extensions/extended-list-item.js +5 -0
- package/dist/extensions/extended-table-cell.d.ts +10 -0
- package/dist/extensions/extended-table-cell.js +6 -0
- package/dist/extensions/extended-table.d.ts +17 -0
- package/dist/extensions/extended-table.js +34 -0
- package/dist/extensions/heading-paragraph.d.ts +17 -0
- package/dist/extensions/heading-paragraph.js +30 -0
- package/dist/extensions/image-component.d.ts +22 -0
- package/dist/extensions/image-component.js +223 -0
- package/dist/extensions/image.d.ts +10 -0
- package/dist/extensions/image.js +77 -0
- package/dist/extensions/index.d.ts +16 -0
- package/dist/extensions/index.js +64 -0
- package/dist/extensions/math.d.ts +15 -0
- package/dist/extensions/math.js +214 -0
- package/dist/extensions/media.d.ts +19 -0
- package/dist/extensions/media.js +149 -0
- package/dist/extensions/responseArea.d.ts +27 -0
- package/dist/extensions/responseArea.js +255 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +7 -0
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
- package/dist/utils/helper.d.ts +9 -0
- package/dist/utils/helper.js +27 -0
- package/dist/utils/size.d.ts +9 -0
- package/dist/utils/size.js +14 -0
- package/dist/utils/toolbar.d.ts +10 -0
- package/dist/utils/toolbar.js +7 -0
- package/package.json +59 -43
- package/CHANGELOG.json +0 -32
- package/CHANGELOG.md +0 -2532
- package/lib/components/CharacterPicker.js +0 -226
- package/lib/components/CharacterPicker.js.map +0 -1
- package/lib/components/EditableHtml.js +0 -388
- package/lib/components/EditableHtml.js.map +0 -1
- package/lib/components/MenuBar.js +0 -702
- package/lib/components/MenuBar.js.map +0 -1
- package/lib/components/TiptapContainer.js +0 -242
- package/lib/components/TiptapContainer.js.map +0 -1
- package/lib/components/characters/characterUtils.js +0 -378
- package/lib/components/characters/characterUtils.js.map +0 -1
- package/lib/components/characters/custom-popper.js +0 -44
- package/lib/components/characters/custom-popper.js.map +0 -1
- package/lib/components/common/done-button.js +0 -34
- package/lib/components/common/done-button.js.map +0 -1
- package/lib/components/common/toolbar-buttons.js +0 -149
- package/lib/components/common/toolbar-buttons.js.map +0 -1
- package/lib/components/icons/CssIcon.js +0 -25
- package/lib/components/icons/CssIcon.js.map +0 -1
- package/lib/components/icons/RespArea.js +0 -72
- package/lib/components/icons/RespArea.js.map +0 -1
- package/lib/components/icons/TableIcons.js +0 -53
- package/lib/components/icons/TableIcons.js.map +0 -1
- package/lib/components/icons/TextAlign.js +0 -157
- package/lib/components/icons/TextAlign.js.map +0 -1
- package/lib/components/image/AltDialog.js +0 -98
- package/lib/components/image/AltDialog.js.map +0 -1
- package/lib/components/image/ImageToolbar.js +0 -137
- package/lib/components/image/ImageToolbar.js.map +0 -1
- package/lib/components/image/InsertImageHandler.js +0 -135
- package/lib/components/image/InsertImageHandler.js.map +0 -1
- package/lib/components/media/MediaDialog.js +0 -594
- package/lib/components/media/MediaDialog.js.map +0 -1
- package/lib/components/media/MediaToolbar.js +0 -74
- package/lib/components/media/MediaToolbar.js.map +0 -1
- package/lib/components/media/MediaWrapper.js +0 -67
- package/lib/components/media/MediaWrapper.js.map +0 -1
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +0 -84
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +0 -1
- package/lib/components/respArea/DragInTheBlank/choice.js +0 -253
- package/lib/components/respArea/DragInTheBlank/choice.js.map +0 -1
- package/lib/components/respArea/ExplicitConstructedResponse.js +0 -137
- package/lib/components/respArea/ExplicitConstructedResponse.js.map +0 -1
- package/lib/components/respArea/InlineDropdown.js +0 -223
- package/lib/components/respArea/InlineDropdown.js.map +0 -1
- package/lib/components/respArea/MathTemplated.js +0 -130
- package/lib/components/respArea/MathTemplated.js.map +0 -1
- package/lib/components/respArea/ToolbarIcon.js +0 -81
- package/lib/components/respArea/ToolbarIcon.js.map +0 -1
- package/lib/components/respArea/inlineDropdownUtils.js +0 -67
- package/lib/components/respArea/inlineDropdownUtils.js.map +0 -1
- package/lib/constants.js +0 -11
- package/lib/constants.js.map +0 -1
- package/lib/extensions/css.js +0 -227
- package/lib/extensions/css.js.map +0 -1
- package/lib/extensions/custom-toolbar-wrapper.js +0 -92
- package/lib/extensions/custom-toolbar-wrapper.js.map +0 -1
- package/lib/extensions/div-node.js +0 -83
- package/lib/extensions/div-node.js.map +0 -1
- package/lib/extensions/ensure-empty-root-div.js +0 -48
- package/lib/extensions/ensure-empty-root-div.js.map +0 -1
- package/lib/extensions/ensure-list-item-content-is-div.js +0 -64
- package/lib/extensions/ensure-list-item-content-is-div.js.map +0 -1
- package/lib/extensions/extended-list-item.js +0 -15
- package/lib/extensions/extended-list-item.js.map +0 -1
- package/lib/extensions/extended-table-cell.js +0 -22
- package/lib/extensions/extended-table-cell.js.map +0 -1
- package/lib/extensions/extended-table.js +0 -75
- package/lib/extensions/extended-table.js.map +0 -1
- package/lib/extensions/heading-paragraph.js +0 -61
- package/lib/extensions/heading-paragraph.js.map +0 -1
- package/lib/extensions/image-component.js +0 -351
- package/lib/extensions/image-component.js.map +0 -1
- package/lib/extensions/image.js +0 -134
- package/lib/extensions/image.js.map +0 -1
- package/lib/extensions/index.js +0 -46
- package/lib/extensions/index.js.map +0 -1
- package/lib/extensions/math.js +0 -469
- package/lib/extensions/math.js.map +0 -1
- package/lib/extensions/media.js +0 -243
- package/lib/extensions/media.js.map +0 -1
- package/lib/extensions/responseArea.js +0 -452
- package/lib/extensions/responseArea.js.map +0 -1
- package/lib/index.js +0 -37
- package/lib/index.js.map +0 -1
- package/lib/styles/editorContainerStyles.js +0 -137
- package/lib/styles/editorContainerStyles.js.map +0 -1
- package/lib/theme.js +0 -8
- package/lib/theme.js.map +0 -1
- package/lib/utils/helper.js +0 -73
- package/lib/utils/helper.js.map +0 -1
- package/lib/utils/size.js +0 -26
- package/lib/utils/size.js.map +0 -1
- package/lib/utils/toolbar.js +0 -19
- package/lib/utils/toolbar.js.map +0 -1
- package/src/__tests__/EditableHtml.test.jsx +0 -588
- package/src/__tests__/constants.test.js +0 -19
- package/src/__tests__/div-to-paragraph-conversion.test.jsx +0 -125
- package/src/__tests__/extensions.test.js +0 -208
- package/src/__tests__/index.test.jsx +0 -154
- package/src/__tests__/size-utils.test.js +0 -64
- package/src/__tests__/theme.test.js +0 -17
- package/src/components/CharacterPicker.jsx +0 -237
- package/src/components/EditableHtml.jsx +0 -458
- package/src/components/MenuBar.jsx +0 -561
- package/src/components/TiptapContainer.jsx +0 -235
- package/src/components/__tests__/AltDialog.test.jsx +0 -147
- package/src/components/__tests__/CharacterPicker.test.jsx +0 -270
- package/src/components/__tests__/CssIcon.test.jsx +0 -46
- package/src/components/__tests__/DragInTheBlank.test.jsx +0 -255
- package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +0 -209
- package/src/components/__tests__/ImageToolbar.test.jsx +0 -128
- package/src/components/__tests__/InlineDropdown.test.jsx +0 -557
- package/src/components/__tests__/InsertImageHandler.test.js +0 -161
- package/src/components/__tests__/MediaDialog.test.jsx +0 -293
- package/src/components/__tests__/MediaToolbar.test.jsx +0 -74
- package/src/components/__tests__/MediaWrapper.test.jsx +0 -81
- package/src/components/__tests__/MenuBar.test.jsx +0 -250
- package/src/components/__tests__/RespArea.test.jsx +0 -122
- package/src/components/__tests__/TableIcons.test.jsx +0 -149
- package/src/components/__tests__/TextAlign.test.jsx +0 -167
- package/src/components/__tests__/TiptapContainer.test.jsx +0 -138
- package/src/components/__tests__/characterUtils.test.js +0 -166
- package/src/components/__tests__/choice.test.jsx +0 -171
- package/src/components/__tests__/custom-popper.test.jsx +0 -82
- package/src/components/__tests__/done-button.test.jsx +0 -54
- package/src/components/__tests__/toolbar-buttons.test.jsx +0 -234
- package/src/components/characters/characterUtils.js +0 -447
- package/src/components/characters/custom-popper.js +0 -38
- package/src/components/common/done-button.jsx +0 -27
- package/src/components/common/toolbar-buttons.jsx +0 -127
- package/src/components/icons/CssIcon.jsx +0 -15
- package/src/components/icons/RespArea.jsx +0 -71
- package/src/components/icons/TableIcons.jsx +0 -52
- package/src/components/icons/TextAlign.jsx +0 -114
- package/src/components/image/AltDialog.jsx +0 -82
- package/src/components/image/ImageToolbar.jsx +0 -99
- package/src/components/image/InsertImageHandler.js +0 -107
- package/src/components/media/MediaDialog.jsx +0 -596
- package/src/components/media/MediaToolbar.jsx +0 -49
- package/src/components/media/MediaWrapper.jsx +0 -39
- package/src/components/respArea/DragInTheBlank/DragInTheBlank.jsx +0 -76
- package/src/components/respArea/DragInTheBlank/__tests__/choice.test.jsx +0 -72
- package/src/components/respArea/DragInTheBlank/choice.jsx +0 -259
- package/src/components/respArea/ExplicitConstructedResponse.jsx +0 -136
- package/src/components/respArea/InlineDropdown.jsx +0 -240
- package/src/components/respArea/MathTemplated.jsx +0 -124
- package/src/components/respArea/ToolbarIcon.jsx +0 -66
- package/src/components/respArea/__tests__/MathTemplated.test.jsx +0 -210
- package/src/components/respArea/inlineDropdownUtils.js +0 -79
- package/src/constants.js +0 -5
- package/src/extensions/__tests__/css.test.js +0 -196
- package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +0 -180
- package/src/extensions/__tests__/divNode.test.js +0 -87
- package/src/extensions/__tests__/ensure-empty-root-div.test.js +0 -57
- package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +0 -44
- package/src/extensions/__tests__/extended-list-item.test.js +0 -13
- package/src/extensions/__tests__/extended-table-cell.test.js +0 -22
- package/src/extensions/__tests__/extended-table.test.js +0 -183
- package/src/extensions/__tests__/image-component.test.jsx +0 -346
- package/src/extensions/__tests__/image.test.js +0 -237
- package/src/extensions/__tests__/math.test.js +0 -900
- package/src/extensions/__tests__/media-node-view.test.jsx +0 -298
- package/src/extensions/__tests__/media.test.js +0 -271
- package/src/extensions/__tests__/responseArea.test.js +0 -655
- package/src/extensions/css.js +0 -233
- package/src/extensions/custom-toolbar-wrapper.jsx +0 -78
- package/src/extensions/div-node.js +0 -86
- package/src/extensions/ensure-empty-root-div.js +0 -47
- package/src/extensions/ensure-list-item-content-is-div.js +0 -62
- package/src/extensions/extended-list-item.js +0 -10
- package/src/extensions/extended-table-cell.js +0 -19
- package/src/extensions/extended-table.js +0 -60
- package/src/extensions/heading-paragraph.js +0 -53
- package/src/extensions/image-component.jsx +0 -340
- package/src/extensions/image.js +0 -109
- package/src/extensions/index.js +0 -81
- package/src/extensions/math.js +0 -454
- package/src/extensions/media.js +0 -188
- package/src/extensions/responseArea.js +0 -407
- package/src/index.jsx +0 -5
- package/src/styles/editorContainerStyles.js +0 -145
- package/src/theme.js +0 -1
- package/src/utils/__tests__/helper.test.js +0 -126
- package/src/utils/__tests__/toolbar.test.js +0 -43
- package/src/utils/helper.js +0 -69
- package/src/utils/size.js +0 -32
- package/src/utils/toolbar.js +0 -15
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { NodeSelection } from 'prosemirror-state';
|
|
2
|
-
|
|
3
|
-
export const HOLD_INLINE_DROPDOWN_TOOLBAR_INDEX = '_holdInlineDropdownToolbarIndex';
|
|
4
|
-
|
|
5
|
-
export const findInlineDropdownPos = (editor, index) => {
|
|
6
|
-
let foundPos = null;
|
|
7
|
-
|
|
8
|
-
editor.state.doc.descendants((n, p) => {
|
|
9
|
-
if (n.type?.name === 'inline_dropdown' && String(n.attrs?.index) === String(index)) {
|
|
10
|
-
foundPos = p;
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return true;
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
return foundPos;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const holdInlineDropdownToolbar = (editor, index) => {
|
|
21
|
-
editor[HOLD_INLINE_DROPDOWN_TOOLBAR_INDEX] = index;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const releaseInlineDropdownToolbarHold = (editor) => {
|
|
25
|
-
delete editor[HOLD_INLINE_DROPDOWN_TOOLBAR_INDEX];
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const isInlineDropdownToolbarHeld = (editor, index) =>
|
|
29
|
-
editor[HOLD_INLINE_DROPDOWN_TOOLBAR_INDEX] != null &&
|
|
30
|
-
String(editor[HOLD_INLINE_DROPDOWN_TOOLBAR_INDEX]) === String(index);
|
|
31
|
-
|
|
32
|
-
export const selectInlineDropdownNode = (editor, index, fallbackPos) => {
|
|
33
|
-
const pos = findInlineDropdownPos(editor, index) ?? fallbackPos;
|
|
34
|
-
|
|
35
|
-
if (pos == null) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const { tr } = editor.state;
|
|
40
|
-
const nodeAtPos = tr.doc.nodeAt(pos);
|
|
41
|
-
|
|
42
|
-
if (!nodeAtPos) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const { selection } = tr;
|
|
47
|
-
|
|
48
|
-
if (selection.from === pos && selection.to === pos + nodeAtPos.nodeSize) {
|
|
49
|
-
return pos;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
tr.setSelection(NodeSelection.create(tr.doc, pos));
|
|
53
|
-
editor.view.dispatch(tr);
|
|
54
|
-
|
|
55
|
-
return pos;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const deleteInlineDropdownByIndex = (editor, index, fallbackPos) => {
|
|
59
|
-
const pos = findInlineDropdownPos(editor, index) ?? fallbackPos;
|
|
60
|
-
|
|
61
|
-
if (pos == null) {
|
|
62
|
-
releaseInlineDropdownToolbarHold(editor);
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const { tr } = editor.state;
|
|
67
|
-
const nodeAtPos = tr.doc.nodeAt(pos);
|
|
68
|
-
|
|
69
|
-
if (!nodeAtPos) {
|
|
70
|
-
releaseInlineDropdownToolbarHold(editor);
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
tr.delete(pos, pos + nodeAtPos.nodeSize);
|
|
75
|
-
editor.view.dispatch(tr);
|
|
76
|
-
releaseInlineDropdownToolbarHold(editor);
|
|
77
|
-
|
|
78
|
-
return true;
|
|
79
|
-
};
|
package/src/constants.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { CSSMark, removeDialogs } from '../css';
|
|
2
|
-
|
|
3
|
-
jest.mock('@tiptap/core', () => ({
|
|
4
|
-
Mark: { create: jest.fn((config) => config) },
|
|
5
|
-
mergeAttributes: jest.fn((...args) => Object.assign({}, ...args)),
|
|
6
|
-
}));
|
|
7
|
-
|
|
8
|
-
jest.mock('react-dom', () => ({
|
|
9
|
-
render: jest.fn(),
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
describe('CSSMark', () => {
|
|
13
|
-
describe('configuration', () => {
|
|
14
|
-
it('has correct name', () => {
|
|
15
|
-
expect(CSSMark.name).toBe('cssmark');
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('addOptions', () => {
|
|
20
|
-
it('returns default options with empty classes array', () => {
|
|
21
|
-
const options = CSSMark.addOptions();
|
|
22
|
-
|
|
23
|
-
expect(options).toHaveProperty('classes');
|
|
24
|
-
expect(Array.isArray(options.classes)).toBe(true);
|
|
25
|
-
expect(options.classes).toHaveLength(0);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('addAttributes', () => {
|
|
30
|
-
it('returns class attribute configuration', () => {
|
|
31
|
-
const attributes = CSSMark.addAttributes();
|
|
32
|
-
|
|
33
|
-
expect(attributes).toHaveProperty('class');
|
|
34
|
-
expect(attributes.class).toHaveProperty('default', null);
|
|
35
|
-
expect(attributes.class).toHaveProperty('parseHTML');
|
|
36
|
-
expect(attributes.class).toHaveProperty('renderHTML');
|
|
37
|
-
expect(typeof attributes.class.parseHTML).toBe('function');
|
|
38
|
-
expect(typeof attributes.class.renderHTML).toBe('function');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('parseHTML extracts class attribute', () => {
|
|
42
|
-
const attributes = CSSMark.addAttributes();
|
|
43
|
-
const mockEl = {
|
|
44
|
-
getAttribute: jest.fn((attr) => (attr === 'class' ? 'my-class' : null)),
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const result = attributes.class.parseHTML(mockEl);
|
|
48
|
-
|
|
49
|
-
expect(result).toBe('my-class');
|
|
50
|
-
expect(mockEl.getAttribute).toHaveBeenCalledWith('class');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('renderHTML returns empty object when no class', () => {
|
|
54
|
-
const attributes = CSSMark.addAttributes();
|
|
55
|
-
const result = attributes.class.renderHTML({ class: null });
|
|
56
|
-
|
|
57
|
-
expect(result).toEqual({});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('renderHTML returns class when present', () => {
|
|
61
|
-
const attributes = CSSMark.addAttributes();
|
|
62
|
-
const result = attributes.class.renderHTML({ class: 'my-class' });
|
|
63
|
-
|
|
64
|
-
expect(result).toEqual({ class: 'my-class' });
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('parseHTML', () => {
|
|
69
|
-
beforeEach(() => {
|
|
70
|
-
CSSMark.options = { classes: ['allowed-class', 'another-class'] };
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('returns array with span[class] selector', () => {
|
|
74
|
-
const rules = CSSMark.parseHTML();
|
|
75
|
-
|
|
76
|
-
expect(Array.isArray(rules)).toBe(true);
|
|
77
|
-
expect(rules).toHaveLength(1);
|
|
78
|
-
expect(rules[0]).toHaveProperty('tag', 'span[class]');
|
|
79
|
-
expect(rules[0]).toHaveProperty('getAttrs');
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('matches allowed classes', () => {
|
|
83
|
-
const rules = CSSMark.parseHTML();
|
|
84
|
-
const mockEl = {
|
|
85
|
-
getAttribute: jest.fn(() => 'allowed-class some-other'),
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const result = rules[0].getAttrs(mockEl);
|
|
89
|
-
|
|
90
|
-
expect(result).toEqual({ class: 'allowed-class' });
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('returns false for non-allowed classes', () => {
|
|
94
|
-
const rules = CSSMark.parseHTML();
|
|
95
|
-
const mockEl = {
|
|
96
|
-
getAttribute: jest.fn(() => 'not-allowed'),
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const result = rules[0].getAttrs(mockEl);
|
|
100
|
-
|
|
101
|
-
expect(result).toBe(false);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('handles empty class attribute', () => {
|
|
105
|
-
const rules = CSSMark.parseHTML();
|
|
106
|
-
const mockEl = {
|
|
107
|
-
getAttribute: jest.fn(() => ''),
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const result = rules[0].getAttrs(mockEl);
|
|
111
|
-
|
|
112
|
-
expect(result).toBe(false);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('renderHTML', () => {
|
|
117
|
-
it('returns span with merged attributes', () => {
|
|
118
|
-
const result = CSSMark.renderHTML({
|
|
119
|
-
HTMLAttributes: { class: 'my-class' },
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
expect(result[0]).toBe('span');
|
|
123
|
-
expect(result[1]).toEqual({ class: 'my-class' });
|
|
124
|
-
expect(result[2]).toBe(0);
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
describe('addCommands', () => {
|
|
129
|
-
it('returns setCSSClass command', () => {
|
|
130
|
-
const commands = CSSMark.addCommands();
|
|
131
|
-
|
|
132
|
-
expect(commands).toHaveProperty('setCSSClass');
|
|
133
|
-
expect(typeof commands.setCSSClass).toBe('function');
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('returns unsetCSSClass command', () => {
|
|
137
|
-
const commands = CSSMark.addCommands();
|
|
138
|
-
|
|
139
|
-
expect(commands).toHaveProperty('unsetCSSClass');
|
|
140
|
-
expect(typeof commands.unsetCSSClass).toBe('function');
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('returns openCSSClassDialog command', () => {
|
|
144
|
-
const commands = CSSMark.addCommands();
|
|
145
|
-
|
|
146
|
-
expect(commands).toHaveProperty('openCSSClassDialog');
|
|
147
|
-
expect(typeof commands.openCSSClassDialog).toBe('function');
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('setCSSClass sets mark with class name', () => {
|
|
151
|
-
const context = { name: 'cssmark' };
|
|
152
|
-
const commands = CSSMark.addCommands.call(context);
|
|
153
|
-
const mockCommands = {
|
|
154
|
-
setMark: jest.fn(() => true),
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const result = commands.setCSSClass('my-class')({ commands: mockCommands });
|
|
158
|
-
|
|
159
|
-
expect(mockCommands.setMark).toHaveBeenCalledWith('cssmark', { class: 'my-class' });
|
|
160
|
-
expect(result).toBe(true);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('unsetCSSClass unsets mark', () => {
|
|
164
|
-
const context = { name: 'cssmark' };
|
|
165
|
-
const commands = CSSMark.addCommands.call(context);
|
|
166
|
-
const mockCommands = {
|
|
167
|
-
unsetMark: jest.fn(() => true),
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
const result = commands.unsetCSSClass()({ commands: mockCommands });
|
|
171
|
-
|
|
172
|
-
expect(mockCommands.unsetMark).toHaveBeenCalledWith('cssmark');
|
|
173
|
-
expect(result).toBe(true);
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe('removeDialogs', () => {
|
|
179
|
-
it('removes all elements with insert-css-dialog class', () => {
|
|
180
|
-
const mockElements = [{ remove: jest.fn() }, { remove: jest.fn() }];
|
|
181
|
-
|
|
182
|
-
document.querySelectorAll = jest.fn(() => mockElements);
|
|
183
|
-
|
|
184
|
-
removeDialogs();
|
|
185
|
-
|
|
186
|
-
expect(document.querySelectorAll).toHaveBeenCalledWith('.insert-css-dialog');
|
|
187
|
-
expect(mockElements[0].remove).toHaveBeenCalled();
|
|
188
|
-
expect(mockElements[1].remove).toHaveBeenCalled();
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('handles no dialogs gracefully', () => {
|
|
192
|
-
document.querySelectorAll = jest.fn(() => []);
|
|
193
|
-
|
|
194
|
-
expect(() => removeDialogs()).not.toThrow();
|
|
195
|
-
});
|
|
196
|
-
});
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { fireEvent, render } from '@testing-library/react';
|
|
3
|
-
import CustomToolbarWrapper from '../custom-toolbar-wrapper';
|
|
4
|
-
|
|
5
|
-
jest.mock('../../components/common/done-button', () => ({
|
|
6
|
-
DoneButton: ({ onClick }) => (
|
|
7
|
-
<button data-testid="done-button" onClick={onClick}>
|
|
8
|
-
Done
|
|
9
|
-
</button>
|
|
10
|
-
),
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
jest.mock('@mui/icons-material/Delete', () => ({
|
|
14
|
-
__esModule: true,
|
|
15
|
-
default: () => <span data-testid="delete-icon">Delete</span>,
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
describe('CustomToolbarWrapper', () => {
|
|
19
|
-
const mockOnDone = jest.fn();
|
|
20
|
-
const mockOnDelete = jest.fn();
|
|
21
|
-
const defaultToolbarOpts = {
|
|
22
|
-
position: 'bottom',
|
|
23
|
-
alignment: 'left',
|
|
24
|
-
alwaysVisible: false,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
jest.clearAllMocks();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('renders without crashing', () => {
|
|
32
|
-
const { container } = render(
|
|
33
|
-
<CustomToolbarWrapper showDone={false} toolbarOpts={defaultToolbarOpts}>
|
|
34
|
-
<div>Test content</div>
|
|
35
|
-
</CustomToolbarWrapper>,
|
|
36
|
-
);
|
|
37
|
-
expect(container).toBeInTheDocument();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('renders children', () => {
|
|
41
|
-
const { getByText } = render(
|
|
42
|
-
<CustomToolbarWrapper showDone={false} toolbarOpts={defaultToolbarOpts}>
|
|
43
|
-
<div>Test content</div>
|
|
44
|
-
</CustomToolbarWrapper>,
|
|
45
|
-
);
|
|
46
|
-
expect(getByText('Test content')).toBeInTheDocument();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('does not show done button when showDone is false', () => {
|
|
50
|
-
const { queryByTestId } = render(
|
|
51
|
-
<CustomToolbarWrapper showDone={false} onDone={mockOnDone} toolbarOpts={defaultToolbarOpts}>
|
|
52
|
-
<div>Test content</div>
|
|
53
|
-
</CustomToolbarWrapper>,
|
|
54
|
-
);
|
|
55
|
-
expect(queryByTestId('done-button')).not.toBeInTheDocument();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('shows done button when showDone is true', () => {
|
|
59
|
-
const { getByTestId } = render(
|
|
60
|
-
<CustomToolbarWrapper showDone={true} onDone={mockOnDone} toolbarOpts={defaultToolbarOpts}>
|
|
61
|
-
<div>Test content</div>
|
|
62
|
-
</CustomToolbarWrapper>,
|
|
63
|
-
);
|
|
64
|
-
expect(getByTestId('done-button')).toBeInTheDocument();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('calls onDone when done button is clicked', () => {
|
|
68
|
-
const { getByTestId } = render(
|
|
69
|
-
<CustomToolbarWrapper showDone={true} onDone={mockOnDone} toolbarOpts={defaultToolbarOpts}>
|
|
70
|
-
<div>Test content</div>
|
|
71
|
-
</CustomToolbarWrapper>,
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const doneButton = getByTestId('done-button');
|
|
75
|
-
fireEvent.click(doneButton);
|
|
76
|
-
|
|
77
|
-
expect(mockOnDone).toHaveBeenCalledTimes(1);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('does not show delete button when deletable is false', () => {
|
|
81
|
-
const { queryByTestId } = render(
|
|
82
|
-
<CustomToolbarWrapper deletable={false} toolbarOpts={defaultToolbarOpts}>
|
|
83
|
-
<div>Test content</div>
|
|
84
|
-
</CustomToolbarWrapper>,
|
|
85
|
-
);
|
|
86
|
-
expect(queryByTestId('delete-icon')).not.toBeInTheDocument();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('shows delete button when deletable is true', () => {
|
|
90
|
-
const { getByTestId } = render(
|
|
91
|
-
<CustomToolbarWrapper deletable={true} onDelete={mockOnDelete} toolbarOpts={defaultToolbarOpts}>
|
|
92
|
-
<div>Test content</div>
|
|
93
|
-
</CustomToolbarWrapper>,
|
|
94
|
-
);
|
|
95
|
-
expect(getByTestId('delete-icon')).toBeInTheDocument();
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('calls onDelete when delete button is clicked', () => {
|
|
99
|
-
const { getByLabelText } = render(
|
|
100
|
-
<CustomToolbarWrapper deletable={true} onDelete={mockOnDelete} toolbarOpts={defaultToolbarOpts}>
|
|
101
|
-
<div>Test content</div>
|
|
102
|
-
</CustomToolbarWrapper>,
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const deleteButton = getByLabelText('Delete');
|
|
106
|
-
fireEvent.mouseDown(deleteButton);
|
|
107
|
-
|
|
108
|
-
expect(mockOnDelete).toHaveBeenCalledTimes(1);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('applies right alignment from toolbarOpts', () => {
|
|
112
|
-
const toolbarOpts = {
|
|
113
|
-
...defaultToolbarOpts,
|
|
114
|
-
alignment: 'right',
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const { container } = render(
|
|
118
|
-
<CustomToolbarWrapper toolbarOpts={toolbarOpts}>
|
|
119
|
-
<div>Test content</div>
|
|
120
|
-
</CustomToolbarWrapper>,
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
const toolbar = container.querySelector('.pie-toolbar');
|
|
124
|
-
expect(toolbar).toHaveStyle({ right: '0' });
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('applies autoWidth when specified', () => {
|
|
128
|
-
const { container } = render(
|
|
129
|
-
<CustomToolbarWrapper autoWidth={true} toolbarOpts={defaultToolbarOpts}>
|
|
130
|
-
<div>Test content</div>
|
|
131
|
-
</CustomToolbarWrapper>,
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
const toolbar = container.querySelector('.pie-toolbar');
|
|
135
|
-
expect(toolbar).toHaveStyle({ width: 'auto' });
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('applies minWidth from toolbarOpts', () => {
|
|
139
|
-
const toolbarOpts = {
|
|
140
|
-
...defaultToolbarOpts,
|
|
141
|
-
minWidth: '300px',
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const { container } = render(
|
|
145
|
-
<CustomToolbarWrapper toolbarOpts={toolbarOpts}>
|
|
146
|
-
<div>Test content</div>
|
|
147
|
-
</CustomToolbarWrapper>,
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
const toolbar = container.querySelector('.pie-toolbar');
|
|
151
|
-
expect(toolbar).toHaveStyle({ minWidth: '300px' });
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('hides toolbar when isHidden is true', () => {
|
|
155
|
-
const toolbarOpts = {
|
|
156
|
-
...defaultToolbarOpts,
|
|
157
|
-
isHidden: true,
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
const { container } = render(
|
|
161
|
-
<CustomToolbarWrapper toolbarOpts={toolbarOpts}>
|
|
162
|
-
<div>Test content</div>
|
|
163
|
-
</CustomToolbarWrapper>,
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
const toolbar = container.querySelector('.pie-toolbar');
|
|
167
|
-
expect(toolbar).toHaveStyle({ visibility: 'hidden' });
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('renders multiple children', () => {
|
|
171
|
-
const { getByText } = render(
|
|
172
|
-
<CustomToolbarWrapper showDone={false} toolbarOpts={defaultToolbarOpts}>
|
|
173
|
-
<div>First child</div>
|
|
174
|
-
<div>Second child</div>
|
|
175
|
-
</CustomToolbarWrapper>,
|
|
176
|
-
);
|
|
177
|
-
expect(getByText('First child')).toBeInTheDocument();
|
|
178
|
-
expect(getByText('Second child')).toBeInTheDocument();
|
|
179
|
-
});
|
|
180
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { DivNode } from '../div-node';
|
|
2
|
-
|
|
3
|
-
jest.mock('@tiptap/core', () => ({
|
|
4
|
-
Node: {
|
|
5
|
-
create: jest.fn((config) => config),
|
|
6
|
-
},
|
|
7
|
-
}));
|
|
8
|
-
|
|
9
|
-
describe('DivNode', () => {
|
|
10
|
-
describe('configuration', () => {
|
|
11
|
-
it('has correct name', () => {
|
|
12
|
-
expect(DivNode.name).toBe('div');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('is block level', () => {
|
|
16
|
-
expect(DivNode.group).toBe('block');
|
|
17
|
-
expect(DivNode.content).toBe('inline*');
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe('parseHTML', () => {
|
|
22
|
-
it('parses <div> tags', () => {
|
|
23
|
-
const rules = DivNode.parseHTML();
|
|
24
|
-
|
|
25
|
-
expect(Array.isArray(rules)).toBe(true);
|
|
26
|
-
expect(rules).toHaveLength(1);
|
|
27
|
-
expect(rules[0]).toHaveProperty('tag', 'div');
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('renderHTML', () => {
|
|
32
|
-
it('renders a <div> tag', () => {
|
|
33
|
-
const result = DivNode.renderHTML({ HTMLAttributes: { class: 'foo' } });
|
|
34
|
-
|
|
35
|
-
expect(result[0]).toBe('div');
|
|
36
|
-
expect(result[1]).toEqual({ class: 'foo' });
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('addKeyboardShortcuts', () => {
|
|
41
|
-
it('does nothing when current block is not div', () => {
|
|
42
|
-
const mockEditor = {
|
|
43
|
-
state: {
|
|
44
|
-
selection: {
|
|
45
|
-
$from: {
|
|
46
|
-
parent: { type: { name: 'paragraph' } },
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const shortcuts = DivNode.addKeyboardShortcuts.call({ editor: mockEditor });
|
|
53
|
-
const handled = shortcuts.Enter();
|
|
54
|
-
|
|
55
|
-
expect(handled).toBe(false);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('turns div into paragraph and splits when Enter is pressed in a div', () => {
|
|
59
|
-
const chain = {
|
|
60
|
-
focus: jest.fn(() => chain),
|
|
61
|
-
setNode: jest.fn(() => chain),
|
|
62
|
-
splitBlock: jest.fn(() => chain),
|
|
63
|
-
run: jest.fn(() => true),
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const mockEditor = {
|
|
67
|
-
state: {
|
|
68
|
-
selection: {
|
|
69
|
-
$from: {
|
|
70
|
-
parent: { type: { name: 'div' } },
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
chain: () => chain,
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const shortcuts = DivNode.addKeyboardShortcuts.call({ editor: mockEditor });
|
|
78
|
-
const handled = shortcuts.Enter();
|
|
79
|
-
|
|
80
|
-
expect(chain.focus).toHaveBeenCalled();
|
|
81
|
-
expect(chain.setNode).toHaveBeenCalledWith('paragraph');
|
|
82
|
-
expect(chain.splitBlock).toHaveBeenCalled();
|
|
83
|
-
expect(chain.run).toHaveBeenCalled();
|
|
84
|
-
expect(handled).toBe(true);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
});
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Editor } from '@tiptap/core';
|
|
2
|
-
import StarterKit from '@tiptap/starter-kit';
|
|
3
|
-
import { DivNode } from '../div-node';
|
|
4
|
-
import { EnsureEmptyRootIsDiv } from '../ensure-empty-root-div';
|
|
5
|
-
|
|
6
|
-
/** Match EditableHtml so TrailingNode does not add a second empty block next to an empty paragraph. */
|
|
7
|
-
const starterKitConfigured = StarterKit.configure({
|
|
8
|
-
trailingNode: {
|
|
9
|
-
node: 'paragraph',
|
|
10
|
-
notAfter: ['paragraph', 'div'],
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe('EnsureEmptyRootIsDiv', () => {
|
|
15
|
-
const extensions = [starterKitConfigured, DivNode, EnsureEmptyRootIsDiv];
|
|
16
|
-
|
|
17
|
-
let editor;
|
|
18
|
-
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
if (editor) {
|
|
21
|
-
editor.destroy();
|
|
22
|
-
editor = null;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('replaces a lone root paragraph with an empty div after select-all and delete (full delete flow)', () => {
|
|
27
|
-
editor = new Editor({
|
|
28
|
-
extensions,
|
|
29
|
-
content: '<p>hello</p>',
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
editor.chain().focus().selectAll().deleteSelection().run();
|
|
33
|
-
|
|
34
|
-
expect(editor.state.doc.childCount).toBe(1);
|
|
35
|
-
expect(editor.state.doc.firstChild.type.name).toBe('div');
|
|
36
|
-
expect(editor.state.doc.firstChild.textContent).toBe('');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('does not replace a root paragraph that still has text', () => {
|
|
40
|
-
editor = new Editor({
|
|
41
|
-
extensions,
|
|
42
|
-
content: '<p>x</p>',
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
expect(editor.state.doc.firstChild.type.name).toBe('paragraph');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('does not run when there is more than one top-level block', () => {
|
|
49
|
-
editor = new Editor({
|
|
50
|
-
extensions,
|
|
51
|
-
content: '<p>a</p><p>b</p>',
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
expect(editor.state.doc.childCount).toBe(2);
|
|
55
|
-
expect(editor.state.doc.firstChild.type.name).toBe('paragraph');
|
|
56
|
-
});
|
|
57
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { EnsureListItemContentIsDiv } from '../ensure-list-item-content-is-div';
|
|
2
|
-
|
|
3
|
-
describe('EnsureListItemContentIsDiv', () => {
|
|
4
|
-
it('registers a ProseMirror plugin that rewrites listItem paragraph children to div', () => {
|
|
5
|
-
const plugins = EnsureListItemContentIsDiv.config.addProseMirrorPlugins();
|
|
6
|
-
expect(Array.isArray(plugins)).toBe(true);
|
|
7
|
-
expect(plugins).toHaveLength(1);
|
|
8
|
-
|
|
9
|
-
const plugin = plugins[0];
|
|
10
|
-
const divType = { name: 'div' };
|
|
11
|
-
const tr = { setNodeMarkup: jest.fn() };
|
|
12
|
-
|
|
13
|
-
const paragraphChild = {
|
|
14
|
-
type: { name: 'paragraph' },
|
|
15
|
-
attrs: { class: 'x' },
|
|
16
|
-
nodeSize: 6,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const listItemNode = {
|
|
20
|
-
type: { name: 'listItem' },
|
|
21
|
-
forEach: (cb) => cb(paragraphChild),
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const newState = {
|
|
25
|
-
schema: { nodes: { div: divType } },
|
|
26
|
-
tr,
|
|
27
|
-
doc: {
|
|
28
|
-
descendants: (cb) => cb(listItemNode, 10),
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const result = plugin.spec.appendTransaction([{ docChanged: true }], {}, newState);
|
|
33
|
-
|
|
34
|
-
expect(tr.setNodeMarkup).toHaveBeenCalledWith(11, divType, paragraphChild.attrs);
|
|
35
|
-
expect(result).toBe(tr);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('returns null when there is no document change', () => {
|
|
39
|
-
const plugin = EnsureListItemContentIsDiv.config.addProseMirrorPlugins()[0];
|
|
40
|
-
|
|
41
|
-
const result = plugin.spec.appendTransaction([{ docChanged: false }], {}, {});
|
|
42
|
-
expect(result).toBeNull();
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ExtendedListItem } from '../extended-list-item';
|
|
2
|
-
|
|
3
|
-
describe('ExtendedListItem', () => {
|
|
4
|
-
it('extends listItem and prefers div over paragraph in content spec', () => {
|
|
5
|
-
expect(ExtendedListItem.name).toBe('listItem');
|
|
6
|
-
|
|
7
|
-
const content =
|
|
8
|
-
ExtendedListItem.options?.content ?? ExtendedListItem.config?.content ?? ExtendedListItem.extendOptions?.content;
|
|
9
|
-
|
|
10
|
-
expect(String(content)).toMatch(/^\(div \| paragraph/);
|
|
11
|
-
expect(String(content)).toContain('imageUploadNode');
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ExtendedTableCell, ExtendedTableHeader } from '../extended-table-cell';
|
|
2
|
-
|
|
3
|
-
describe('ExtendedTableCell / ExtendedTableHeader', () => {
|
|
4
|
-
it('exports cell and header extensions with div preferred over paragraph in content spec', () => {
|
|
5
|
-
expect(ExtendedTableCell.name).toBe('tableCell');
|
|
6
|
-
expect(ExtendedTableHeader.name).toBe('tableHeader');
|
|
7
|
-
|
|
8
|
-
const cellContent =
|
|
9
|
-
ExtendedTableCell.options?.content ??
|
|
10
|
-
ExtendedTableCell.config?.content ??
|
|
11
|
-
ExtendedTableCell.extendOptions?.content;
|
|
12
|
-
|
|
13
|
-
expect(String(cellContent)).toMatch(/^\(div \| paragraph/);
|
|
14
|
-
|
|
15
|
-
const headerContent =
|
|
16
|
-
ExtendedTableHeader.options?.content ??
|
|
17
|
-
ExtendedTableHeader.config?.content ??
|
|
18
|
-
ExtendedTableHeader.extendOptions?.content;
|
|
19
|
-
|
|
20
|
-
expect(headerContent).toBe(cellContent);
|
|
21
|
-
});
|
|
22
|
-
});
|