@pie-lib/editable-html-tip-tap 2.1.2-next.31 → 2.1.2-next.34
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/CHANGELOG.json +32 -0
- package/CHANGELOG.md +2532 -0
- package/LICENSE.md +5 -0
- package/lib/components/CharacterPicker.js +201 -0
- package/lib/components/CharacterPicker.js.map +1 -0
- package/lib/components/EditableHtml.js +376 -0
- package/lib/components/EditableHtml.js.map +1 -0
- package/lib/components/MenuBar.js +696 -0
- package/lib/components/MenuBar.js.map +1 -0
- package/lib/components/TiptapContainer.js +234 -0
- package/lib/components/TiptapContainer.js.map +1 -0
- package/lib/components/characters/characterUtils.js +378 -0
- package/lib/components/characters/characterUtils.js.map +1 -0
- package/lib/components/characters/custom-popper.js +44 -0
- package/lib/components/characters/custom-popper.js.map +1 -0
- package/lib/components/common/done-button.js +34 -0
- package/lib/components/common/done-button.js.map +1 -0
- package/lib/components/common/toolbar-buttons.js +144 -0
- package/lib/components/common/toolbar-buttons.js.map +1 -0
- package/lib/components/icons/CssIcon.js +25 -0
- package/lib/components/icons/CssIcon.js.map +1 -0
- package/lib/components/icons/RespArea.js +72 -0
- package/lib/components/icons/RespArea.js.map +1 -0
- package/lib/components/icons/TableIcons.js +53 -0
- package/lib/components/icons/TableIcons.js.map +1 -0
- package/lib/components/icons/TextAlign.js +157 -0
- package/lib/components/icons/TextAlign.js.map +1 -0
- package/lib/components/image/AltDialog.js +98 -0
- package/lib/components/image/AltDialog.js.map +1 -0
- package/lib/components/image/ImageToolbar.js +137 -0
- package/lib/components/image/ImageToolbar.js.map +1 -0
- package/lib/components/image/InsertImageHandler.js +135 -0
- package/lib/components/image/InsertImageHandler.js.map +1 -0
- package/lib/components/media/MediaDialog.js +594 -0
- package/lib/components/media/MediaDialog.js.map +1 -0
- package/lib/components/media/MediaToolbar.js +74 -0
- package/lib/components/media/MediaToolbar.js.map +1 -0
- package/lib/components/media/MediaWrapper.js +67 -0
- package/lib/components/media/MediaWrapper.js.map +1 -0
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +84 -0
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +1 -0
- package/lib/components/respArea/DragInTheBlank/choice.js +250 -0
- package/lib/components/respArea/DragInTheBlank/choice.js.map +1 -0
- package/lib/components/respArea/ExplicitConstructedResponse.js +136 -0
- package/lib/components/respArea/ExplicitConstructedResponse.js.map +1 -0
- package/lib/components/respArea/InlineDropdown.js +209 -0
- package/lib/components/respArea/InlineDropdown.js.map +1 -0
- package/lib/components/respArea/MathTemplated.js +130 -0
- package/lib/components/respArea/MathTemplated.js.map +1 -0
- package/lib/components/respArea/ToolbarIcon.js +81 -0
- package/lib/components/respArea/ToolbarIcon.js.map +1 -0
- package/lib/components/respArea/inlineDropdownUtils.js +67 -0
- package/lib/components/respArea/inlineDropdownUtils.js.map +1 -0
- package/lib/constants.js +11 -0
- package/lib/constants.js.map +1 -0
- package/lib/extensions/css.js +217 -0
- package/lib/extensions/css.js.map +1 -0
- package/lib/extensions/custom-toolbar-wrapper.js +92 -0
- package/lib/extensions/custom-toolbar-wrapper.js.map +1 -0
- package/lib/extensions/div-node.js +83 -0
- package/lib/extensions/div-node.js.map +1 -0
- package/lib/extensions/ensure-empty-root-div.js +48 -0
- package/lib/extensions/ensure-empty-root-div.js.map +1 -0
- package/lib/extensions/ensure-list-item-content-is-div.js +64 -0
- package/lib/extensions/ensure-list-item-content-is-div.js.map +1 -0
- package/lib/extensions/extended-list-item.js +15 -0
- package/lib/extensions/extended-list-item.js.map +1 -0
- package/lib/extensions/extended-table-cell.js +22 -0
- package/lib/extensions/extended-table-cell.js.map +1 -0
- package/lib/extensions/extended-table.js +75 -0
- package/lib/extensions/extended-table.js.map +1 -0
- package/lib/extensions/heading-paragraph.js +61 -0
- package/lib/extensions/heading-paragraph.js.map +1 -0
- package/lib/extensions/image-component.js +348 -0
- package/lib/extensions/image-component.js.map +1 -0
- package/lib/extensions/image.js +134 -0
- package/lib/extensions/image.js.map +1 -0
- package/lib/extensions/index.js +46 -0
- package/lib/extensions/index.js.map +1 -0
- package/lib/extensions/math.js +342 -0
- package/lib/extensions/math.js.map +1 -0
- package/lib/extensions/media.js +243 -0
- package/lib/extensions/media.js.map +1 -0
- package/lib/extensions/responseArea.js +446 -0
- package/lib/extensions/responseArea.js.map +1 -0
- package/lib/index.js +37 -0
- package/lib/index.js.map +1 -0
- package/lib/styles/editorContainerStyles.js +137 -0
- package/lib/styles/editorContainerStyles.js.map +1 -0
- package/lib/theme.js +8 -0
- package/lib/theme.js.map +1 -0
- package/lib/utils/helper.js +73 -0
- package/lib/utils/helper.js.map +1 -0
- package/lib/utils/size.js +26 -0
- package/lib/utils/size.js.map +1 -0
- package/package.json +24 -40
- package/src/__tests__/EditableHtml.test.jsx +554 -0
- package/src/__tests__/constants.test.js +19 -0
- package/src/__tests__/div-to-paragraph-conversion.test.jsx +125 -0
- package/src/__tests__/extensions.test.js +208 -0
- package/src/__tests__/index.test.jsx +154 -0
- package/src/__tests__/size-utils.test.js +64 -0
- package/src/__tests__/theme.test.js +17 -0
- package/src/components/CharacterPicker.jsx +207 -0
- package/src/components/EditableHtml.jsx +440 -0
- package/src/components/MenuBar.jsx +554 -0
- package/src/components/TiptapContainer.jsx +219 -0
- package/src/components/__tests__/AltDialog.test.jsx +147 -0
- package/src/components/__tests__/CharacterPicker.test.jsx +261 -0
- package/src/components/__tests__/CssIcon.test.jsx +46 -0
- package/src/components/__tests__/DragInTheBlank.test.jsx +255 -0
- package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +204 -0
- package/src/components/__tests__/ImageToolbar.test.jsx +128 -0
- package/src/components/__tests__/InlineDropdown.test.jsx +388 -0
- package/src/components/__tests__/InsertImageHandler.test.js +161 -0
- package/src/components/__tests__/MediaDialog.test.jsx +293 -0
- package/src/components/__tests__/MediaToolbar.test.jsx +74 -0
- package/src/components/__tests__/MediaWrapper.test.jsx +81 -0
- package/src/components/__tests__/MenuBar.test.jsx +250 -0
- package/src/components/__tests__/RespArea.test.jsx +122 -0
- package/src/components/__tests__/TableIcons.test.jsx +149 -0
- package/src/components/__tests__/TextAlign.test.jsx +167 -0
- package/src/components/__tests__/TiptapContainer.test.jsx +138 -0
- package/src/components/__tests__/characterUtils.test.js +166 -0
- package/src/components/__tests__/choice.test.jsx +171 -0
- package/src/components/__tests__/custom-popper.test.jsx +82 -0
- package/src/components/__tests__/done-button.test.jsx +54 -0
- package/src/components/__tests__/toolbar-buttons.test.jsx +234 -0
- package/src/components/characters/characterUtils.js +447 -0
- package/src/components/characters/custom-popper.js +38 -0
- package/src/components/common/done-button.jsx +27 -0
- package/src/components/common/toolbar-buttons.jsx +122 -0
- package/src/components/icons/CssIcon.jsx +15 -0
- package/src/components/icons/RespArea.jsx +71 -0
- package/src/components/icons/TableIcons.jsx +52 -0
- package/src/components/icons/TextAlign.jsx +114 -0
- package/src/components/image/AltDialog.jsx +82 -0
- package/src/components/image/ImageToolbar.jsx +99 -0
- package/src/components/image/InsertImageHandler.js +107 -0
- package/src/components/media/MediaDialog.jsx +596 -0
- package/src/components/media/MediaToolbar.jsx +49 -0
- package/src/components/media/MediaWrapper.jsx +39 -0
- package/src/components/respArea/DragInTheBlank/DragInTheBlank.jsx +76 -0
- package/src/components/respArea/DragInTheBlank/choice.jsx +256 -0
- package/src/components/respArea/ExplicitConstructedResponse.jsx +135 -0
- package/src/components/respArea/InlineDropdown.jsx +220 -0
- package/src/components/respArea/MathTemplated.jsx +124 -0
- package/src/components/respArea/ToolbarIcon.jsx +66 -0
- package/src/components/respArea/__tests__/MathTemplated.test.jsx +210 -0
- package/src/components/respArea/inlineDropdownUtils.js +79 -0
- package/src/constants.js +5 -0
- package/src/extensions/__tests__/css.test.js +196 -0
- package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +180 -0
- package/src/extensions/__tests__/divNode.test.js +87 -0
- package/src/extensions/__tests__/ensure-empty-root-div.test.js +57 -0
- package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +44 -0
- package/src/extensions/__tests__/extended-list-item.test.js +13 -0
- package/src/extensions/__tests__/extended-table-cell.test.js +22 -0
- package/src/extensions/__tests__/extended-table.test.js +183 -0
- package/src/extensions/__tests__/image-component.test.jsx +345 -0
- package/src/extensions/__tests__/image.test.js +237 -0
- package/src/extensions/__tests__/math.test.js +603 -0
- package/src/extensions/__tests__/media-node-view.test.jsx +298 -0
- package/src/extensions/__tests__/media.test.js +271 -0
- package/src/extensions/__tests__/responseArea.test.js +601 -0
- package/src/extensions/css.js +220 -0
- package/src/extensions/custom-toolbar-wrapper.jsx +78 -0
- package/src/extensions/div-node.js +86 -0
- package/src/extensions/ensure-empty-root-div.js +47 -0
- package/src/extensions/ensure-list-item-content-is-div.js +62 -0
- package/src/extensions/extended-list-item.js +10 -0
- package/src/extensions/extended-table-cell.js +19 -0
- package/src/extensions/extended-table.js +60 -0
- package/src/extensions/heading-paragraph.js +53 -0
- package/src/extensions/image-component.jsx +338 -0
- package/src/extensions/image.js +109 -0
- package/src/extensions/index.js +81 -0
- package/src/extensions/math.js +326 -0
- package/src/extensions/media.js +188 -0
- package/src/extensions/responseArea.js +401 -0
- package/src/index.jsx +5 -0
- package/src/styles/editorContainerStyles.js +145 -0
- package/src/theme.js +1 -0
- package/src/utils/__tests__/helper.test.js +126 -0
- package/src/utils/helper.js +69 -0
- package/src/utils/size.js +32 -0
- package/dist/components/CharacterPicker.d.ts +0 -31
- package/dist/components/CharacterPicker.js +0 -131
- package/dist/components/EditableHtml.d.ts +0 -11
- package/dist/components/EditableHtml.js +0 -291
- package/dist/components/MenuBar.d.ts +0 -11
- package/dist/components/MenuBar.js +0 -462
- package/dist/components/TiptapContainer.d.ts +0 -11
- package/dist/components/TiptapContainer.js +0 -154
- package/dist/components/characters/characterUtils.d.ts +0 -35
- package/dist/components/characters/characterUtils.js +0 -465
- package/dist/components/characters/custom-popper.d.ts +0 -14
- package/dist/components/characters/custom-popper.js +0 -32
- package/dist/components/common/done-button.d.ts +0 -30
- package/dist/components/common/done-button.js +0 -26
- package/dist/components/common/toolbar-buttons.d.ts +0 -38
- package/dist/components/common/toolbar-buttons.js +0 -91
- package/dist/components/icons/CssIcon.d.ts +0 -11
- package/dist/components/icons/CssIcon.js +0 -14
- package/dist/components/icons/RespArea.d.ts +0 -26
- package/dist/components/icons/RespArea.js +0 -42
- package/dist/components/icons/TableIcons.d.ts +0 -14
- package/dist/components/icons/TableIcons.js +0 -32
- package/dist/components/icons/TextAlign.d.ts +0 -18
- package/dist/components/icons/TextAlign.js +0 -134
- package/dist/components/image/AltDialog.d.ts +0 -22
- package/dist/components/image/AltDialog.js +0 -61
- package/dist/components/image/ImageToolbar.d.ts +0 -24
- package/dist/components/image/ImageToolbar.js +0 -80
- package/dist/components/image/InsertImageHandler.d.ts +0 -32
- package/dist/components/image/InsertImageHandler.js +0 -53
- package/dist/components/media/MediaDialog.d.ts +0 -43
- package/dist/components/media/MediaDialog.js +0 -389
- package/dist/components/media/MediaToolbar.d.ts +0 -19
- package/dist/components/media/MediaToolbar.js +0 -41
- package/dist/components/media/MediaWrapper.d.ts +0 -19
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts +0 -23
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.js +0 -58
- package/dist/components/respArea/DragInTheBlank/choice.d.ts +0 -56
- package/dist/components/respArea/DragInTheBlank/choice.js +0 -156
- package/dist/components/respArea/ExplicitConstructedResponse.d.ts +0 -20
- package/dist/components/respArea/ExplicitConstructedResponse.js +0 -83
- package/dist/components/respArea/InlineDropdown.d.ts +0 -18
- package/dist/components/respArea/InlineDropdown.js +0 -119
- package/dist/components/respArea/MathTemplated.d.ts +0 -19
- package/dist/components/respArea/MathTemplated.js +0 -97
- package/dist/components/respArea/ToolbarIcon.d.ts +0 -14
- package/dist/components/respArea/ToolbarIcon.js +0 -17
- package/dist/components/respArea/inlineDropdownUtils.d.ts +0 -15
- package/dist/components/respArea/inlineDropdownUtils.js +0 -15
- package/dist/constants.d.ts +0 -13
- package/dist/constants.js +0 -4
- package/dist/extensions/css.d.ts +0 -11
- package/dist/extensions/css.js +0 -115
- package/dist/extensions/custom-toolbar-wrapper.d.ts +0 -11
- package/dist/extensions/custom-toolbar-wrapper.js +0 -61
- package/dist/extensions/div-node.d.ts +0 -10
- package/dist/extensions/div-node.js +0 -42
- package/dist/extensions/ensure-empty-root-div.d.ts +0 -14
- package/dist/extensions/ensure-empty-root-div.js +0 -24
- package/dist/extensions/ensure-list-item-content-is-div.d.ts +0 -15
- package/dist/extensions/ensure-list-item-content-is-div.js +0 -31
- package/dist/extensions/extended-list-item.d.ts +0 -13
- package/dist/extensions/extended-list-item.js +0 -5
- package/dist/extensions/extended-table-cell.d.ts +0 -10
- package/dist/extensions/extended-table-cell.js +0 -6
- package/dist/extensions/extended-table.d.ts +0 -17
- package/dist/extensions/extended-table.js +0 -34
- package/dist/extensions/heading-paragraph.d.ts +0 -17
- package/dist/extensions/heading-paragraph.js +0 -30
- package/dist/extensions/image-component.d.ts +0 -22
- package/dist/extensions/image-component.js +0 -220
- package/dist/extensions/image.d.ts +0 -10
- package/dist/extensions/image.js +0 -68
- package/dist/extensions/index.d.ts +0 -16
- package/dist/extensions/index.js +0 -64
- package/dist/extensions/math.d.ts +0 -15
- package/dist/extensions/math.js +0 -158
- package/dist/extensions/media.d.ts +0 -19
- package/dist/extensions/media.js +0 -149
- package/dist/extensions/responseArea.d.ts +0 -27
- package/dist/extensions/responseArea.js +0 -259
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -7
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +0 -16
- package/dist/styles/editorContainerStyles.d.ts +0 -134
- package/dist/theme.d.ts +0 -9
- package/dist/utils/helper.d.ts +0 -9
- package/dist/utils/helper.js +0 -27
- package/dist/utils/size.d.ts +0 -9
- package/dist/utils/size.js +0 -14
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NodeSelection, Plugin, PluginKey, TextSelection } from 'prosemirror-state';
|
|
3
|
+
import { Extension } from '@tiptap/core';
|
|
4
|
+
import { Node, ReactNodeViewRenderer } from '@tiptap/react';
|
|
5
|
+
import ExplicitConstructedResponse from '../components/respArea/ExplicitConstructedResponse';
|
|
6
|
+
import DragInTheBlank from '../components/respArea/DragInTheBlank/DragInTheBlank';
|
|
7
|
+
import InlineDropdown from '../components/respArea/InlineDropdown';
|
|
8
|
+
import MathTemplated from '../components/respArea/MathTemplated';
|
|
9
|
+
|
|
10
|
+
const lastIndexMap = {};
|
|
11
|
+
|
|
12
|
+
const normalizeType = (type) => String(type || '').replace(/-/g, '_');
|
|
13
|
+
|
|
14
|
+
const getAttrIndex = (node) => (node && node.attrs && node.attrs.index != null ? String(node.attrs.index) : null);
|
|
15
|
+
|
|
16
|
+
const collectNodesOfType = (doc, typeName) => {
|
|
17
|
+
const results = [];
|
|
18
|
+
|
|
19
|
+
doc.descendants((node, pos) => {
|
|
20
|
+
if (node.type && node.type.name === typeName) {
|
|
21
|
+
const index = getAttrIndex(node);
|
|
22
|
+
if (index != null) results.push({ index, pos, node });
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return results;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const countNodesOfType = (doc, typeName) => {
|
|
31
|
+
let count = 0;
|
|
32
|
+
doc.descendants((node) => {
|
|
33
|
+
if (node.type && node.type.name === typeName) count += 1;
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
return count;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const getDefaultNode = ({ schema, typeName, index }) => {
|
|
40
|
+
const nodeType = schema.nodes[typeName];
|
|
41
|
+
if (!nodeType) return null;
|
|
42
|
+
|
|
43
|
+
// mirror your Slate "getDefaultElement(opts, newIndex)"
|
|
44
|
+
// customize attrs as needed:
|
|
45
|
+
return nodeType.create({
|
|
46
|
+
index: String(index),
|
|
47
|
+
id: String(index),
|
|
48
|
+
value: '',
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Find a good cursor position *after* an inserted node.
|
|
53
|
+
const selectionAfterPos = (doc, pos) => {
|
|
54
|
+
const $pos = doc.resolve(Math.min(pos, doc.content.size));
|
|
55
|
+
return TextSelection.near($pos, 1);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const ResponseAreaExtension = Extension.create({
|
|
59
|
+
name: 'responseArea',
|
|
60
|
+
|
|
61
|
+
addOptions() {
|
|
62
|
+
return {
|
|
63
|
+
maxResponseAreas: null,
|
|
64
|
+
error: null,
|
|
65
|
+
options: null,
|
|
66
|
+
respAreaToolbar: null,
|
|
67
|
+
onHandleAreaChange: null,
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
addProseMirrorPlugins() {
|
|
72
|
+
if (!this.options.type) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const typeName = normalizeType(this.options.type);
|
|
77
|
+
const key = new PluginKey(`response-area-watcher:${typeName}`);
|
|
78
|
+
|
|
79
|
+
return [
|
|
80
|
+
new Plugin({
|
|
81
|
+
key,
|
|
82
|
+
|
|
83
|
+
view: (view) => {
|
|
84
|
+
// Lazy init lastIndexMap[typeName]
|
|
85
|
+
if (lastIndexMap[typeName] === undefined) {
|
|
86
|
+
lastIndexMap[typeName] = 0;
|
|
87
|
+
|
|
88
|
+
view.state.doc.descendants((node) => {
|
|
89
|
+
if (node.type && node.type.name === typeName) {
|
|
90
|
+
const idx = getAttrIndex(node);
|
|
91
|
+
if (idx != null) {
|
|
92
|
+
const n = parseInt(idx, 10);
|
|
93
|
+
if (!Number.isNaN(n) && n > lastIndexMap[typeName]) {
|
|
94
|
+
lastIndexMap[typeName] = n;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
update: (view, prevState) => {
|
|
104
|
+
const state = view.state;
|
|
105
|
+
if (prevState.doc.eq(state.doc)) return;
|
|
106
|
+
|
|
107
|
+
const currentList = collectNodesOfType(state.doc, typeName);
|
|
108
|
+
const oldList = collectNodesOfType(prevState.doc, typeName);
|
|
109
|
+
|
|
110
|
+
if (this.options.toolbar) {
|
|
111
|
+
this.options.toolbar.disabled = currentList.length >= this.options.maxResponseAreas;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Removed elements (same logic as Slate)
|
|
115
|
+
if (oldList.length > currentList.length) {
|
|
116
|
+
const currentIndexSet = new Set(currentList.map((x) => x.index));
|
|
117
|
+
|
|
118
|
+
const removed = oldList.filter((x) => !currentIndexSet.has(x.index));
|
|
119
|
+
|
|
120
|
+
if (removed.length && typeof this.options.onHandleAreaChange === 'function') {
|
|
121
|
+
this.options.onHandleAreaChange(removed);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
}),
|
|
128
|
+
];
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
addCommands() {
|
|
132
|
+
return {
|
|
133
|
+
insertResponseArea:
|
|
134
|
+
(type) =>
|
|
135
|
+
({ tr, state, dispatch, commands }) => {
|
|
136
|
+
const typeName = normalizeType(type);
|
|
137
|
+
|
|
138
|
+
// --- Slate: currentRespAreaList + max check ---
|
|
139
|
+
const currentCount = countNodesOfType(state.doc, typeName);
|
|
140
|
+
if (currentCount >= this.options.maxResponseAreas) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// --- Slate: indexing logic (kept identical) ---
|
|
145
|
+
if (lastIndexMap[typeName] === undefined) {
|
|
146
|
+
lastIndexMap[typeName] = 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const prevIndex = lastIndexMap[typeName];
|
|
150
|
+
const newIndex = prevIndex + 1;
|
|
151
|
+
|
|
152
|
+
// Slate increments map even if newIndex === 0
|
|
153
|
+
lastIndexMap[typeName] += 1;
|
|
154
|
+
|
|
155
|
+
const newInline = getDefaultNode({
|
|
156
|
+
schema: state.schema,
|
|
157
|
+
typeName,
|
|
158
|
+
index: newIndex,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
if (!newInline) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// --- Insert logic ---
|
|
166
|
+
const { selection } = state;
|
|
167
|
+
let insertPos = selection.from;
|
|
168
|
+
|
|
169
|
+
// If we're in a NodeSelection, insert before/after is ambiguous;
|
|
170
|
+
// We'll insert at its "from" (like your current code).
|
|
171
|
+
// If insertion fails, we fallback to end of doc.
|
|
172
|
+
const tryInsertAt = (pos) => {
|
|
173
|
+
try {
|
|
174
|
+
tr.insert(pos, newInline);
|
|
175
|
+
return pos;
|
|
176
|
+
} catch (e) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
let usedPos = tryInsertAt(insertPos);
|
|
182
|
+
|
|
183
|
+
// Slate branch: "markup empty and there's no focus"
|
|
184
|
+
// ProseMirror doesn't expose "no focus" the same way, so the closest
|
|
185
|
+
// equivalent fallback is inserting at end of document.
|
|
186
|
+
if (usedPos == null) {
|
|
187
|
+
usedPos = tryInsertAt(tr.doc.content.size);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (usedPos == null) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Optionally select the node you just inserted (like your original command)
|
|
195
|
+
// tr.setSelection(NodeSelection.create(tr.doc, usedPos))
|
|
196
|
+
|
|
197
|
+
// --- Cursor move behavior for certain types (Slate: moveFocusTo next text) ---
|
|
198
|
+
if (['math_templated', 'inline_dropdown', 'explicit_constructed_response'].includes(typeName)) {
|
|
199
|
+
tr.setSelection(NodeSelection.create(tr.doc, usedPos));
|
|
200
|
+
} else {
|
|
201
|
+
const after = usedPos + newInline.nodeSize;
|
|
202
|
+
tr.setSelection(selectionAfterPos(tr.doc, after));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (dispatch) {
|
|
206
|
+
commands.focus();
|
|
207
|
+
dispatch(tr);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return true;
|
|
211
|
+
},
|
|
212
|
+
refreshResponseArea:
|
|
213
|
+
() =>
|
|
214
|
+
({ tr, state, commands, dispatch }) => {
|
|
215
|
+
const { selection } = state;
|
|
216
|
+
const node = selection.$from.nodeAfter;
|
|
217
|
+
const nodePos = selection.from;
|
|
218
|
+
|
|
219
|
+
tr.setNodeMarkup(nodePos, undefined, { ...node?.attrs, updated: `${Date.now()}` });
|
|
220
|
+
tr.setSelection(NodeSelection.create(tr.doc, nodePos));
|
|
221
|
+
|
|
222
|
+
if (dispatch) {
|
|
223
|
+
commands.focus();
|
|
224
|
+
dispatch(tr);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return true;
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* ExplicitConstructedResponse Node
|
|
235
|
+
*/
|
|
236
|
+
export const ExplicitConstructedResponseNode = Node.create({
|
|
237
|
+
name: 'explicit_constructed_response',
|
|
238
|
+
group: 'inline',
|
|
239
|
+
inline: true,
|
|
240
|
+
atom: true,
|
|
241
|
+
addAttributes() {
|
|
242
|
+
return {
|
|
243
|
+
index: { default: null },
|
|
244
|
+
value: { default: '' },
|
|
245
|
+
updated: { default: '' },
|
|
246
|
+
};
|
|
247
|
+
},
|
|
248
|
+
parseHTML() {
|
|
249
|
+
return [
|
|
250
|
+
{
|
|
251
|
+
tag: 'span[data-type="explicit_constructed_response"]',
|
|
252
|
+
getAttrs: (el) => ({
|
|
253
|
+
index: el.dataset.index,
|
|
254
|
+
value: el.dataset.value,
|
|
255
|
+
}),
|
|
256
|
+
},
|
|
257
|
+
];
|
|
258
|
+
},
|
|
259
|
+
renderHTML({ HTMLAttributes }) {
|
|
260
|
+
return [
|
|
261
|
+
'span',
|
|
262
|
+
{
|
|
263
|
+
'data-type': 'explicit_constructed_response',
|
|
264
|
+
'data-index': HTMLAttributes.index,
|
|
265
|
+
'data-value': HTMLAttributes.value,
|
|
266
|
+
},
|
|
267
|
+
];
|
|
268
|
+
},
|
|
269
|
+
addNodeView() {
|
|
270
|
+
return ReactNodeViewRenderer((props) => <ExplicitConstructedResponse {...{ ...props, options: this.options }} />);
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* MathTemplated Node
|
|
276
|
+
*/
|
|
277
|
+
export const MathTemplatedNode = Node.create({
|
|
278
|
+
name: 'math_templated',
|
|
279
|
+
group: 'inline',
|
|
280
|
+
inline: true,
|
|
281
|
+
atom: true,
|
|
282
|
+
addAttributes() {
|
|
283
|
+
return {
|
|
284
|
+
index: { default: null },
|
|
285
|
+
value: { default: '' },
|
|
286
|
+
updated: { default: '' },
|
|
287
|
+
};
|
|
288
|
+
},
|
|
289
|
+
parseHTML() {
|
|
290
|
+
return [
|
|
291
|
+
{
|
|
292
|
+
tag: 'span[data-type="math_templated"]',
|
|
293
|
+
getAttrs: (el) => ({
|
|
294
|
+
index: el.dataset.index,
|
|
295
|
+
value: el.dataset.value,
|
|
296
|
+
}),
|
|
297
|
+
},
|
|
298
|
+
];
|
|
299
|
+
},
|
|
300
|
+
renderHTML({ HTMLAttributes }) {
|
|
301
|
+
return [
|
|
302
|
+
'span',
|
|
303
|
+
{
|
|
304
|
+
'data-type': 'math_templated',
|
|
305
|
+
'data-index': HTMLAttributes.index,
|
|
306
|
+
'data-value': HTMLAttributes.value,
|
|
307
|
+
},
|
|
308
|
+
];
|
|
309
|
+
},
|
|
310
|
+
addNodeView() {
|
|
311
|
+
return ReactNodeViewRenderer((props) => <MathTemplated {...{ ...props, options: this.options }} />);
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* DragInTheBlank Node
|
|
317
|
+
*/
|
|
318
|
+
export const DragInTheBlankNode = Node.create({
|
|
319
|
+
name: 'drag_in_the_blank',
|
|
320
|
+
group: 'inline',
|
|
321
|
+
inline: true,
|
|
322
|
+
atom: true,
|
|
323
|
+
addAttributes() {
|
|
324
|
+
return {
|
|
325
|
+
index: { default: null },
|
|
326
|
+
id: { default: null },
|
|
327
|
+
value: { default: '' },
|
|
328
|
+
inTable: { default: null },
|
|
329
|
+
updated: { default: '' },
|
|
330
|
+
};
|
|
331
|
+
},
|
|
332
|
+
parseHTML() {
|
|
333
|
+
return [
|
|
334
|
+
{
|
|
335
|
+
tag: 'span[data-type="drag_in_the_blank"]',
|
|
336
|
+
getAttrs: (el) => ({
|
|
337
|
+
index: el.dataset.index,
|
|
338
|
+
id: el.dataset.id,
|
|
339
|
+
value: el.dataset.value,
|
|
340
|
+
inTable: el.dataset.inTable,
|
|
341
|
+
}),
|
|
342
|
+
},
|
|
343
|
+
];
|
|
344
|
+
},
|
|
345
|
+
renderHTML({ HTMLAttributes }) {
|
|
346
|
+
return [
|
|
347
|
+
'span',
|
|
348
|
+
{
|
|
349
|
+
'data-type': 'drag_in_the_blank',
|
|
350
|
+
'data-index': HTMLAttributes.index,
|
|
351
|
+
'data-id': HTMLAttributes.id,
|
|
352
|
+
'data-value': HTMLAttributes.value,
|
|
353
|
+
'data-in-table': HTMLAttributes.inTable,
|
|
354
|
+
},
|
|
355
|
+
];
|
|
356
|
+
},
|
|
357
|
+
addNodeView() {
|
|
358
|
+
return ReactNodeViewRenderer((props) => <DragInTheBlank {...{ ...props, options: this.options }} />);
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* InlineDropdown Node
|
|
364
|
+
*/
|
|
365
|
+
export const InlineDropdownNode = Node.create({
|
|
366
|
+
name: 'inline_dropdown',
|
|
367
|
+
group: 'inline',
|
|
368
|
+
inline: true,
|
|
369
|
+
atom: true,
|
|
370
|
+
addAttributes() {
|
|
371
|
+
return {
|
|
372
|
+
index: { default: null },
|
|
373
|
+
value: { default: '' },
|
|
374
|
+
updated: { default: '' },
|
|
375
|
+
};
|
|
376
|
+
},
|
|
377
|
+
parseHTML() {
|
|
378
|
+
return [
|
|
379
|
+
{
|
|
380
|
+
tag: 'span[data-type="inline_dropdown"]',
|
|
381
|
+
getAttrs: (el) => ({
|
|
382
|
+
index: el.dataset.index,
|
|
383
|
+
value: el.dataset.value,
|
|
384
|
+
}),
|
|
385
|
+
},
|
|
386
|
+
];
|
|
387
|
+
},
|
|
388
|
+
renderHTML({ HTMLAttributes }) {
|
|
389
|
+
return [
|
|
390
|
+
'span',
|
|
391
|
+
{
|
|
392
|
+
'data-type': 'inline_dropdown',
|
|
393
|
+
'data-index': HTMLAttributes.index,
|
|
394
|
+
'data-value': HTMLAttributes.value,
|
|
395
|
+
},
|
|
396
|
+
];
|
|
397
|
+
},
|
|
398
|
+
addNodeView() {
|
|
399
|
+
return ReactNodeViewRenderer((props) => <InlineDropdown {...{ ...props, options: this.options }} />);
|
|
400
|
+
},
|
|
401
|
+
});
|
package/src/index.jsx
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import StyledEditor, { EditableHtml } from './components/EditableHtml';
|
|
2
|
+
import { ALL_PLUGINS, DEFAULT_PLUGINS } from './extensions';
|
|
3
|
+
import { deleteInlineDropdownByIndex } from './components/respArea/inlineDropdownUtils';
|
|
4
|
+
export { EditableHtml, ALL_PLUGINS, DEFAULT_PLUGINS, deleteInlineDropdownByIndex };
|
|
5
|
+
export default StyledEditor;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { color } from '@pie-lib/render-ui';
|
|
2
|
+
|
|
3
|
+
const styles = (theme) => ({
|
|
4
|
+
root: {
|
|
5
|
+
position: 'relative',
|
|
6
|
+
padding: '0px',
|
|
7
|
+
border: '1px solid #ccc',
|
|
8
|
+
borderRadius: '4px',
|
|
9
|
+
cursor: 'text',
|
|
10
|
+
'& [data-slate-editor="true"]': {
|
|
11
|
+
wordBreak: 'break-word',
|
|
12
|
+
overflow: 'visible',
|
|
13
|
+
maxHeight: '500px',
|
|
14
|
+
// needed in order to be able to put the focus before a void element when it is the first one in the editor
|
|
15
|
+
padding: '5px',
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
'&:first-child': {
|
|
19
|
+
marginTop: 0,
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
'& ul, & ol': {
|
|
23
|
+
padding: '0 1rem',
|
|
24
|
+
margin: '1.25rem 1rem 1.25rem 0.4rem',
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
'& ul li p, & ol li p': {
|
|
28
|
+
marginTop: '0.25em',
|
|
29
|
+
marginBottom: '0.25em',
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
'& h1, & h2, & h3, & h4, & h5, & h6': {
|
|
33
|
+
lineHeight: 1.1,
|
|
34
|
+
marginTop: '2.5rem',
|
|
35
|
+
textWrap: 'pretty',
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
'& h1, & h2': {
|
|
39
|
+
marginTop: '3.5rem',
|
|
40
|
+
marginBottom: '1.5rem',
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
'& h1': {
|
|
44
|
+
fontSize: '1.4rem',
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
'& h2': {
|
|
48
|
+
fontSize: '1.2rem',
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
'& h3': {
|
|
52
|
+
fontSize: '1.1rem',
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
'& h4, & h5, & h6': {
|
|
56
|
+
fontSize: '1rem',
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
'& code': {
|
|
60
|
+
backgroundColor: 'var(--purple-light)',
|
|
61
|
+
borderRadius: '0.4rem',
|
|
62
|
+
color: 'var(--black)',
|
|
63
|
+
fontSize: '0.85rem',
|
|
64
|
+
padding: '0.25em 0.3em',
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
'& pre': {
|
|
68
|
+
background: 'var(--black)',
|
|
69
|
+
borderRadius: '0.5rem',
|
|
70
|
+
color: 'var(--white)',
|
|
71
|
+
fontFamily: '\'JetBrainsMono\', monospace',
|
|
72
|
+
margin: '1.5rem 0',
|
|
73
|
+
padding: '0.75rem 1rem',
|
|
74
|
+
|
|
75
|
+
'& code': {
|
|
76
|
+
background: 'none',
|
|
77
|
+
color: 'inherit',
|
|
78
|
+
fontSize: '0.8rem',
|
|
79
|
+
padding: 0,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
'& blockquote': {
|
|
84
|
+
background: '#f9f9f9',
|
|
85
|
+
borderLeft: '5px solid #ccc',
|
|
86
|
+
margin: '1.5em 10px',
|
|
87
|
+
padding: '.5em 10px',
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
'& hr': {
|
|
91
|
+
border: 'none',
|
|
92
|
+
borderTop: '1px solid var(--gray-2)',
|
|
93
|
+
margin: '2rem 0',
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
'& table': {
|
|
97
|
+
tableLayout: 'fixed',
|
|
98
|
+
width: '100%',
|
|
99
|
+
borderCollapse: 'collapse',
|
|
100
|
+
color: color.text(),
|
|
101
|
+
backgroundColor: color.background(),
|
|
102
|
+
},
|
|
103
|
+
'& table:not([border="1"]) tr': {
|
|
104
|
+
borderTop: '1px solid #dfe2e5',
|
|
105
|
+
},
|
|
106
|
+
'& td, th': {
|
|
107
|
+
padding: '.6em 1em',
|
|
108
|
+
textAlign: 'center',
|
|
109
|
+
},
|
|
110
|
+
'& table:not([border="1"]) td, th': {
|
|
111
|
+
border: '1px solid #dfe2e5',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
children: {
|
|
115
|
+
padding: '10px 16px',
|
|
116
|
+
},
|
|
117
|
+
editorHolder: {
|
|
118
|
+
position: 'relative',
|
|
119
|
+
padding: '0px',
|
|
120
|
+
overflowY: 'auto',
|
|
121
|
+
color: color.text(),
|
|
122
|
+
backgroundColor: color.background(),
|
|
123
|
+
},
|
|
124
|
+
disabledScrollbar: {
|
|
125
|
+
'&::-webkit-scrollbar': {
|
|
126
|
+
display: 'none',
|
|
127
|
+
},
|
|
128
|
+
scrollbarWidth: 'none',
|
|
129
|
+
'-ms-overflow-style': 'none',
|
|
130
|
+
},
|
|
131
|
+
error: {
|
|
132
|
+
border: `2px solid ${theme.palette.error.main} !important`,
|
|
133
|
+
},
|
|
134
|
+
noBorder: {
|
|
135
|
+
border: 'none',
|
|
136
|
+
},
|
|
137
|
+
noPadding: {
|
|
138
|
+
padding: 0,
|
|
139
|
+
},
|
|
140
|
+
toolbarOnTop: {
|
|
141
|
+
marginTop: '45px',
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
export default styles;
|
package/src/theme.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const primary = '#304ffe';
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { normalizeInitialMarkup } from '../helper';
|
|
2
|
+
|
|
3
|
+
describe('normalizeInitialMarkup', () => {
|
|
4
|
+
describe('basic normalization', () => {
|
|
5
|
+
it('returns empty div for empty string', () => {
|
|
6
|
+
expect(normalizeInitialMarkup('')).toBe('<div></div>');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('returns empty div for null', () => {
|
|
10
|
+
expect(normalizeInitialMarkup(null)).toBe('<div></div>');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('returns empty div for undefined', () => {
|
|
14
|
+
expect(normalizeInitialMarkup(undefined)).toBe('<div></div>');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('wraps plain text in div', () => {
|
|
18
|
+
expect(normalizeInitialMarkup('Hello')).toBe('<div>Hello</div>');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('returns HTML tags as-is when detected as HTML', () => {
|
|
22
|
+
// Since '<script>' matches the HTML pattern, it's returned as-is
|
|
23
|
+
// To be escaped, it would need to not match the HTML pattern
|
|
24
|
+
expect(normalizeInitialMarkup('<script>')).toBe('<script>');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('escapes HTML entities in plain text', () => {
|
|
28
|
+
// Plain text without angle brackets gets escaped
|
|
29
|
+
expect(normalizeInitialMarkup('Hello & World')).toBe('<div>Hello & World</div>');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('returns single div as-is', () => {
|
|
33
|
+
const html = '<div>Hello</div>';
|
|
34
|
+
expect(normalizeInitialMarkup(html)).toBe(html);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('returns paragraph as-is', () => {
|
|
38
|
+
const html = '<p>Hello</p>';
|
|
39
|
+
expect(normalizeInitialMarkup(html)).toBe(html);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('consecutive divs to paragraph conversion', () => {
|
|
44
|
+
it('converts two consecutive divs to paragraph with br', () => {
|
|
45
|
+
const input = '<div>A</div><div>B</div>';
|
|
46
|
+
const expected = '<p>A<br>B</p>';
|
|
47
|
+
expect(normalizeInitialMarkup(input)).toBe(expected);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('converts three consecutive divs to paragraph with br tags', () => {
|
|
51
|
+
const input = '<div>A</div><div>B</div><div>C</div>';
|
|
52
|
+
const expected = '<p>A<br>B<br>C</p>';
|
|
53
|
+
expect(normalizeInitialMarkup(input)).toBe(expected);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('handles divs with whitespace', () => {
|
|
57
|
+
const input = '<div> A </div><div> B </div>';
|
|
58
|
+
const expected = '<p> A <br> B </p>';
|
|
59
|
+
expect(normalizeInitialMarkup(input)).toBe(expected);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('handles divs with inline elements', () => {
|
|
63
|
+
const input = '<div><strong>A</strong></div><div><em>B</em></div>';
|
|
64
|
+
const expected = '<p><strong>A</strong><br><em>B</em></p>';
|
|
65
|
+
expect(normalizeInitialMarkup(input)).toBe(expected);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('handles empty divs', () => {
|
|
69
|
+
const input = '<div></div><div>B</div>';
|
|
70
|
+
const expected = '<p><br>B</p>';
|
|
71
|
+
expect(normalizeInitialMarkup(input)).toBe(expected);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('preserves existing br tags within divs', () => {
|
|
75
|
+
const input = '<div>A<br>A2</div><div>B</div>';
|
|
76
|
+
const expected = '<p>A<br>A2<br>B</p>';
|
|
77
|
+
expect(normalizeInitialMarkup(input)).toBe(expected);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('cases that should NOT convert', () => {
|
|
82
|
+
it('does not convert single div', () => {
|
|
83
|
+
const input = '<div>Hello</div>';
|
|
84
|
+
expect(normalizeInitialMarkup(input)).toBe(input);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('does not convert divs with nested block elements', () => {
|
|
88
|
+
const input = '<div><div>Nested</div></div><div>B</div>';
|
|
89
|
+
expect(normalizeInitialMarkup(input)).toBe(input);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('does not convert divs containing tables', () => {
|
|
93
|
+
const input = '<div><table><tr><td>A</td></tr></table></div><div>B</div>';
|
|
94
|
+
expect(normalizeInitialMarkup(input)).toBe(input);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('does not convert divs containing lists', () => {
|
|
98
|
+
const input = '<div><ul><li>Item</li></ul></div><div>B</div>';
|
|
99
|
+
expect(normalizeInitialMarkup(input)).toBe(input);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('does not convert mixed element types', () => {
|
|
103
|
+
const input = '<div>A</div><p>B</p>';
|
|
104
|
+
expect(normalizeInitialMarkup(input)).toBe(input);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('does not convert paragraphs', () => {
|
|
108
|
+
const input = '<p>A</p><p>B</p>';
|
|
109
|
+
expect(normalizeInitialMarkup(input)).toBe(input);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('edge cases', () => {
|
|
114
|
+
it('handles divs with attributes', () => {
|
|
115
|
+
const input = '<div class="test">A</div><div>B</div>';
|
|
116
|
+
// Should not convert since we only want simple divs
|
|
117
|
+
expect(normalizeInitialMarkup(input)).toBe(input);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('handles complex inline formatting', () => {
|
|
121
|
+
const input = '<div><strong><em>A</em></strong></div><div><u>B</u></div>';
|
|
122
|
+
const expected = '<p><strong><em>A</em></strong><br><u>B</u></p>';
|
|
123
|
+
expect(normalizeInitialMarkup(input)).toBe(expected);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
});
|