@pie-lib/editable-html 9.5.13 → 10.0.0-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.
- package/CHANGELOG.md +0 -302
- package/lib/components.js +116 -0
- package/lib/components.js.map +1 -0
- package/lib/editor.js +418 -103
- package/lib/editor.js.map +1 -1
- package/lib/index.js +101 -155
- package/lib/index.js.map +1 -1
- package/lib/new-serialization.js +320 -0
- package/lib/new-serialization.js.map +1 -0
- package/lib/old-serialization.js +330 -0
- package/lib/parse-html.js +1 -1
- package/lib/parse-html.js.map +1 -1
- package/lib/plugins/characters/custom-popper.js +1 -1
- package/lib/plugins/characters/custom-popper.js.map +1 -1
- package/lib/plugins/characters/index.js +21 -19
- package/lib/plugins/characters/index.js.map +1 -1
- package/lib/plugins/characters/utils.js +1 -1
- package/lib/plugins/characters/utils.js.map +1 -1
- package/lib/plugins/hotKeys/index.js +67 -0
- package/lib/plugins/hotKeys/index.js.map +1 -0
- package/lib/plugins/image/alt-dialog.js +1 -6
- package/lib/plugins/image/alt-dialog.js.map +1 -1
- package/lib/plugins/image/component.js +70 -53
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js +7 -9
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js +83 -27
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/image/insert-image-handler.js +72 -33
- package/lib/plugins/image/insert-image-handler.js.map +1 -1
- package/lib/plugins/index.js +23 -41
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/list/index.js +64 -100
- package/lib/plugins/list/index.js.map +1 -1
- package/lib/plugins/math/index.js +86 -60
- package/lib/plugins/math/index.js.map +1 -1
- package/lib/plugins/media/index.js +202 -132
- package/lib/plugins/media/index.js.map +1 -1
- package/lib/plugins/media/media-dialog.js +17 -16
- package/lib/plugins/media/media-dialog.js.map +1 -1
- package/lib/plugins/media/media-toolbar.js +3 -3
- package/lib/plugins/media/media-toolbar.js.map +1 -1
- package/lib/plugins/media/media-wrapper.js +21 -58
- package/lib/plugins/media/media-wrapper.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/choice.js +3 -3
- package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/index.js +3 -2
- package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
- package/lib/plugins/respArea/explicit-constructed-response/index.js +3 -2
- package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
- package/lib/plugins/respArea/icons/index.js +13 -15
- package/lib/plugins/respArea/icons/index.js.map +1 -1
- package/lib/plugins/respArea/index.js +87 -53
- package/lib/plugins/respArea/index.js.map +1 -1
- package/lib/plugins/respArea/inline-dropdown/index.js +4 -3
- package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
- package/lib/plugins/respArea/utils.js +17 -20
- package/lib/plugins/respArea/utils.js.map +1 -1
- package/lib/plugins/table/icons/index.js +1 -1
- package/lib/plugins/table/icons/index.js.map +1 -1
- package/lib/plugins/table/index.js +381 -212
- package/lib/plugins/table/index.js.map +1 -1
- package/lib/plugins/table/table-toolbar.js +5 -6
- package/lib/plugins/table/table-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/default-toolbar.js +55 -11
- package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/done-button.js +1 -1
- package/lib/plugins/toolbar/done-button.js.map +1 -1
- package/lib/plugins/toolbar/editor-and-toolbar.js +186 -232
- package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/index.js +1 -2
- package/lib/plugins/toolbar/index.js.map +1 -1
- package/lib/plugins/toolbar/toolbar-buttons.js +1 -1
- package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
- package/lib/plugins/toolbar/toolbar.js +253 -239
- package/lib/plugins/toolbar/toolbar.js.map +1 -1
- package/lib/plugins/utils.js +27 -2
- package/lib/plugins/utils.js.map +1 -1
- package/lib/serialization.js +1 -1
- package/lib/serialization.js.map +1 -1
- package/lib/slate-editor.js +302 -0
- package/lib/test-serializer.js +189 -0
- package/lib/test-serializer.js.map +1 -0
- package/lib/theme.js +1 -1
- package/lib/theme.js.map +1 -1
- package/package.json +18 -14
- package/playground/image/data.js +20 -20
- package/playground/image/index.html +22 -20
- package/playground/image/index.jsx +12 -10
- package/playground/index.html +25 -23
- package/playground/mathquill/index.html +23 -20
- package/playground/mathquill/index.jsx +18 -22
- package/playground/prod-test/index.html +24 -20
- package/playground/prod-test/index.jsx +5 -3
- package/playground/schema-override/data.js +10 -10
- package/playground/schema-override/image-plugin.jsx +3 -4
- package/playground/schema-override/index.html +21 -19
- package/playground/schema-override/index.jsx +13 -14
- package/playground/serialization/data.js +10 -10
- package/playground/serialization/image-plugin.jsx +3 -4
- package/playground/serialization/index.html +22 -20
- package/playground/table-examples.html +5 -8
- package/playground/webpack.config.js +10 -10
- package/src/components.js +135 -0
- package/src/editor.jsx +478 -141
- package/src/index.jsx +71 -95
- package/src/new-serialization.jsx +291 -0
- package/src/parse-html.js +1 -1
- package/src/plugins/characters/custom-popper.js +7 -7
- package/src/plugins/characters/index.jsx +33 -34
- package/src/plugins/characters/utils.js +81 -81
- package/src/plugins/hotKeys/index.js +54 -0
- package/src/plugins/image/alt-dialog.jsx +4 -5
- package/src/plugins/image/component.jsx +106 -89
- package/src/plugins/image/image-toolbar.jsx +27 -19
- package/src/plugins/image/index.jsx +75 -43
- package/src/plugins/image/insert-image-handler.js +62 -27
- package/src/plugins/index.jsx +23 -41
- package/src/plugins/list/index.jsx +70 -95
- package/src/plugins/math/index.jsx +102 -82
- package/src/plugins/media/index.jsx +159 -124
- package/src/plugins/media/media-dialog.js +98 -71
- package/src/plugins/media/media-toolbar.jsx +8 -8
- package/src/plugins/media/media-wrapper.jsx +29 -30
- package/src/plugins/respArea/drag-in-the-blank/choice.jsx +21 -19
- package/src/plugins/respArea/drag-in-the-blank/index.jsx +14 -11
- package/src/plugins/respArea/explicit-constructed-response/index.jsx +7 -6
- package/src/plugins/respArea/icons/index.jsx +11 -14
- package/src/plugins/respArea/index.jsx +92 -52
- package/src/plugins/respArea/inline-dropdown/index.jsx +9 -8
- package/src/plugins/respArea/utils.jsx +26 -35
- package/src/plugins/table/icons/index.jsx +17 -11
- package/src/plugins/table/index.jsx +288 -231
- package/src/plugins/table/table-toolbar.jsx +15 -11
- package/src/plugins/toolbar/default-toolbar.jsx +65 -19
- package/src/plugins/toolbar/done-button.jsx +4 -4
- package/src/plugins/toolbar/editor-and-toolbar.jsx +150 -145
- package/src/plugins/toolbar/index.jsx +2 -3
- package/src/plugins/toolbar/toolbar-buttons.jsx +11 -11
- package/src/plugins/toolbar/toolbar.jsx +244 -221
- package/src/plugins/utils.js +21 -4
- package/src/serialization.jsx +32 -32
- package/src/test-serializer.js +139 -0
- package/src/test-serializer.js.rej +20 -0
|
@@ -8,24 +8,26 @@ import { PureToolbar } from '@pie-lib/math-toolbar';
|
|
|
8
8
|
import CustomPopper from './custom-popper';
|
|
9
9
|
import { insertSnackBar } from '../respArea/utils';
|
|
10
10
|
import { characterIcons, spanishConfig, specialConfig } from './utils';
|
|
11
|
+
import { ReactEditor } from 'slate-react';
|
|
12
|
+
import { Editor } from 'slate';
|
|
11
13
|
const log = debug('@pie-lib:editable-html:plugins:characters');
|
|
12
14
|
|
|
13
15
|
const removePopOvers = () => {
|
|
14
16
|
const prevPopOvers = document.querySelectorAll('#mouse-over-popover');
|
|
15
17
|
|
|
16
18
|
log('[characters:removePopOvers]');
|
|
17
|
-
prevPopOvers.forEach(
|
|
19
|
+
prevPopOvers.forEach(s => s.remove());
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
export const removeDialogs = () => {
|
|
21
23
|
const prevDialogs = document.querySelectorAll('.insert-character-dialog');
|
|
22
24
|
|
|
23
25
|
log('[characters:removeDialogs]');
|
|
24
|
-
prevDialogs.forEach(
|
|
26
|
+
prevDialogs.forEach(s => s.remove());
|
|
25
27
|
removePopOvers();
|
|
26
28
|
};
|
|
27
29
|
|
|
28
|
-
const insertDialog = ({
|
|
30
|
+
const insertDialog = ({ editor, callback, opts }) => {
|
|
29
31
|
const newEl = document.createElement('div');
|
|
30
32
|
|
|
31
33
|
log('[characters:insertDialog]');
|
|
@@ -60,7 +62,7 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
|
|
|
60
62
|
|
|
61
63
|
return obj;
|
|
62
64
|
},
|
|
63
|
-
{ rows: configToUse.characters.length, columns: 0 }
|
|
65
|
+
{ rows: configToUse.characters.length, columns: 0 }
|
|
64
66
|
);
|
|
65
67
|
|
|
66
68
|
let popoverEl;
|
|
@@ -91,7 +93,7 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
|
|
|
91
93
|
|
|
92
94
|
<div style={infoStyle}>{el.unicode}</div>
|
|
93
95
|
</CustomPopper>,
|
|
94
|
-
popoverEl
|
|
96
|
+
popoverEl
|
|
95
97
|
);
|
|
96
98
|
|
|
97
99
|
document.body.appendChild(newEl);
|
|
@@ -99,12 +101,14 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
|
|
|
99
101
|
|
|
100
102
|
let firstCallMade = false;
|
|
101
103
|
|
|
102
|
-
const listener =
|
|
104
|
+
const listener = e => {
|
|
103
105
|
// this will be triggered right after setting it because
|
|
104
106
|
// this toolbar is added on the mousedown event
|
|
105
107
|
// so right after mouseup, the click will be triggered
|
|
106
108
|
if (firstCallMade) {
|
|
107
|
-
const focusIsInModals =
|
|
109
|
+
const focusIsInModals =
|
|
110
|
+
newEl.contains(e.target) || (popoverEl && popoverEl.contains(e.target));
|
|
111
|
+
const editorDOM = ReactEditor.toDOMNode(editor, editor);
|
|
108
112
|
const focusIsInEditor = editorDOM.contains(e.target);
|
|
109
113
|
|
|
110
114
|
if (!(focusIsInModals || focusIsInEditor)) {
|
|
@@ -122,7 +126,7 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
|
|
|
122
126
|
document.body.removeEventListener('click', listener);
|
|
123
127
|
};
|
|
124
128
|
|
|
125
|
-
const handleChange =
|
|
129
|
+
const handleChange = val => {
|
|
126
130
|
if (typeof val === 'string') {
|
|
127
131
|
callback(val, true);
|
|
128
132
|
}
|
|
@@ -138,7 +142,7 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
|
|
|
138
142
|
additionalKeys={configToUse.characters.reduce((arr, n) => {
|
|
139
143
|
arr = [
|
|
140
144
|
...arr,
|
|
141
|
-
...n.map(
|
|
145
|
+
...n.map(k => ({
|
|
142
146
|
name: get(k, 'name') || k,
|
|
143
147
|
write: get(k, 'write') || k,
|
|
144
148
|
label: get(k, 'label') || k,
|
|
@@ -148,15 +152,15 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
|
|
|
148
152
|
...(k.extraProps || {}),
|
|
149
153
|
style: {
|
|
150
154
|
...(k.extraProps || {}).style,
|
|
151
|
-
border: '1px solid #000'
|
|
152
|
-
}
|
|
155
|
+
border: '1px solid #000'
|
|
156
|
+
}
|
|
153
157
|
},
|
|
154
158
|
...(configToUse.hasPreview
|
|
155
159
|
? {
|
|
156
|
-
actions: { onMouseEnter:
|
|
160
|
+
actions: { onMouseEnter: ev => renderPopOver(ev, k), onMouseLeave: closePopOver }
|
|
157
161
|
}
|
|
158
|
-
: {})
|
|
159
|
-
}))
|
|
162
|
+
: {})
|
|
163
|
+
}))
|
|
160
164
|
];
|
|
161
165
|
|
|
162
166
|
return arr;
|
|
@@ -168,7 +172,8 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
|
|
|
168
172
|
);
|
|
169
173
|
|
|
170
174
|
ReactDOM.render(el, newEl, () => {
|
|
171
|
-
const
|
|
175
|
+
const [nodeAtSelection] = Editor.node(editor, editor.selection);
|
|
176
|
+
const cursorItem = ReactEditor.toDOMNode(editor, nodeAtSelection);
|
|
172
177
|
|
|
173
178
|
if (cursorItem) {
|
|
174
179
|
const bodyRect = document.body.getBoundingClientRect();
|
|
@@ -179,7 +184,10 @@ const insertDialog = ({ editorDOM, value, callback, opts }) => {
|
|
|
179
184
|
newEl.style.top = `${boundRect.top + Math.abs(bodyRect.top) - newEl.offsetHeight - 10}px`;
|
|
180
185
|
newEl.style.zIndex = 99999;
|
|
181
186
|
|
|
182
|
-
const leftValue = `${boundRect.left +
|
|
187
|
+
const leftValue = `${boundRect.left +
|
|
188
|
+
Math.abs(bodyRect.left) +
|
|
189
|
+
cursorItem.offsetWidth +
|
|
190
|
+
10}px`;
|
|
183
191
|
|
|
184
192
|
const rightValue = `${boundRect.x}px`;
|
|
185
193
|
|
|
@@ -210,7 +218,7 @@ const CharacterIcon = ({ letter }) => (
|
|
|
210
218
|
<div
|
|
211
219
|
style={{
|
|
212
220
|
fontSize: '25px',
|
|
213
|
-
lineHeight: '15px'
|
|
221
|
+
lineHeight: '15px'
|
|
214
222
|
}}
|
|
215
223
|
>
|
|
216
224
|
{letter}
|
|
@@ -223,40 +231,31 @@ export default function CharactersPlugin(opts) {
|
|
|
223
231
|
name: 'characters',
|
|
224
232
|
toolbar: {
|
|
225
233
|
icon: <CharacterIcon letter={opts.characterIcon || characterIcons[opts.language] || 'ñ'} />,
|
|
226
|
-
onClick:
|
|
227
|
-
const editorDOM = document.querySelector(`[data-key="${value.document.key}"]`);
|
|
228
|
-
let valueToUse = value;
|
|
234
|
+
onClick: editor => {
|
|
229
235
|
const callback = (char, focus) => {
|
|
230
|
-
valueToUse = getFocusedValue();
|
|
231
|
-
|
|
232
236
|
if (char) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
valueToUse = change.value;
|
|
236
|
-
log('[characters:insert]: ', value);
|
|
237
|
-
onChange(change);
|
|
237
|
+
log('[characters:insert]: ', char);
|
|
238
|
+
editor.insertText(char);
|
|
238
239
|
}
|
|
239
240
|
|
|
240
241
|
log('[characters:click]');
|
|
241
242
|
|
|
242
243
|
if (focus) {
|
|
243
|
-
|
|
244
|
-
editorDOM.focus();
|
|
245
|
-
}
|
|
244
|
+
ReactEditor.focus(editor);
|
|
246
245
|
}
|
|
247
246
|
};
|
|
248
247
|
|
|
249
|
-
insertDialog({
|
|
250
|
-
}
|
|
248
|
+
insertDialog({ editor, callback, opts });
|
|
249
|
+
}
|
|
251
250
|
},
|
|
252
251
|
|
|
253
252
|
pluginStyles: (node, parentNode, p) => {
|
|
254
253
|
if (p) {
|
|
255
254
|
return {
|
|
256
255
|
position: 'absolute',
|
|
257
|
-
top: 'initial'
|
|
256
|
+
top: 'initial'
|
|
258
257
|
};
|
|
259
258
|
}
|
|
260
|
-
}
|
|
259
|
+
}
|
|
261
260
|
};
|
|
262
261
|
}
|