@pie-lib/editable-html-tip-tap 3.0.1-next.20261004011201 → 3.0.1-next.20261004020741
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/EditableHtml.js +150 -141
- package/package.json +3 -3
|
@@ -3,44 +3,44 @@ import { normalizeInitialMarkup as t } from "../utils/helper.js";
|
|
|
3
3
|
import n from "../extensions/extended-table.js";
|
|
4
4
|
import { ExtendedTableCell as r, ExtendedTableHeader as i } from "../extensions/extended-table-cell.js";
|
|
5
5
|
import { DivNode as a } from "../extensions/div-node.js";
|
|
6
|
-
import { EnsureEmptyRootIsDiv as
|
|
7
|
-
import { EnsureListItemContentIsDiv as
|
|
8
|
-
import { DragInTheBlankNode as s, ExplicitConstructedResponseNode as
|
|
9
|
-
import { MathNode as
|
|
10
|
-
import { ImageUploadNode as
|
|
11
|
-
import { Media as
|
|
12
|
-
import { CSSMark as
|
|
13
|
-
import { ExtendedListItem as
|
|
14
|
-
import { HeadingParagraph as
|
|
15
|
-
import { valueToSize as
|
|
16
|
-
import
|
|
17
|
-
import { PLUGINS_MAP as
|
|
18
|
-
import { useCallback as
|
|
19
|
-
import { debounce as
|
|
20
|
-
import { EditorContent as
|
|
21
|
-
import { styled as
|
|
22
|
-
import
|
|
23
|
-
import { TextStyleKit as
|
|
24
|
-
import { CharacterCount as
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import
|
|
29
|
-
import
|
|
30
|
-
import { TableRow as
|
|
31
|
-
import { jsx as
|
|
6
|
+
import { EnsureEmptyRootIsDiv as o } from "../extensions/ensure-empty-root-div.js";
|
|
7
|
+
import { EnsureListItemContentIsDiv as ee } from "../extensions/ensure-list-item-content-is-div.js";
|
|
8
|
+
import { DragInTheBlankNode as s, ExplicitConstructedResponseNode as te, InlineDropdownNode as ne, MathTemplatedNode as re, ResponseAreaExtension as ie } from "../extensions/responseArea.js";
|
|
9
|
+
import { MathNode as c } from "../extensions/math.js";
|
|
10
|
+
import { ImageUploadNode as l } from "../extensions/image.js";
|
|
11
|
+
import { Media as u } from "../extensions/media.js";
|
|
12
|
+
import { CSSMark as d } from "../extensions/css.js";
|
|
13
|
+
import { ExtendedListItem as ae } from "../extensions/extended-list-item.js";
|
|
14
|
+
import { HeadingParagraph as oe } from "../extensions/heading-paragraph.js";
|
|
15
|
+
import { valueToSize as f } from "../utils/size.js";
|
|
16
|
+
import p from "./TiptapContainer.js";
|
|
17
|
+
import { PLUGINS_MAP as m, buildExtensions as h } from "../extensions/index.js";
|
|
18
|
+
import { useCallback as g, useEffect as _, useMemo as v, useState as y } from "react";
|
|
19
|
+
import { debounce as se } from "@pie-element/shared-lodash";
|
|
20
|
+
import { EditorContent as b, useEditor as x, useEditorState as S } from "@tiptap/react";
|
|
21
|
+
import { styled as C } from "@mui/material/styles";
|
|
22
|
+
import w from "@tiptap/starter-kit";
|
|
23
|
+
import { TextStyleKit as T } from "@tiptap/extension-text-style";
|
|
24
|
+
import { CharacterCount as E } from "@tiptap/extension-character-count";
|
|
25
|
+
import D from "@tiptap/extension-superscript";
|
|
26
|
+
import O from "@tiptap/extension-subscript";
|
|
27
|
+
import k from "@tiptap/extension-text-align";
|
|
28
|
+
import A from "@tiptap/extension-image";
|
|
29
|
+
import j from "@tiptap/extension-placeholder";
|
|
30
|
+
import { TableRow as M } from "@tiptap/extension-table-row";
|
|
31
|
+
import { jsx as N } from "react/jsx-runtime";
|
|
32
32
|
//#region src/components/EditableHtml.tsx
|
|
33
|
-
var
|
|
33
|
+
var P = {
|
|
34
34
|
position: "bottom",
|
|
35
35
|
alignment: "left",
|
|
36
36
|
alwaysVisible: !1,
|
|
37
37
|
showDone: !0,
|
|
38
38
|
doneOn: "blur"
|
|
39
|
-
},
|
|
39
|
+
}, F = {
|
|
40
40
|
options: {},
|
|
41
41
|
respAreaToolbar: () => {},
|
|
42
42
|
onHandleAreaChange: () => {}
|
|
43
|
-
},
|
|
43
|
+
}, ce = [
|
|
44
44
|
"bold",
|
|
45
45
|
"italic",
|
|
46
46
|
"underline",
|
|
@@ -62,7 +62,7 @@ var I = {
|
|
|
62
62
|
"h3",
|
|
63
63
|
"undo",
|
|
64
64
|
"redo"
|
|
65
|
-
],
|
|
65
|
+
], I = {
|
|
66
66
|
"--white": "#fff",
|
|
67
67
|
"--black": "#2e2b29",
|
|
68
68
|
"--black-contrast": "#110f0e",
|
|
@@ -81,57 +81,59 @@ var I = {
|
|
|
81
81
|
"--red": "#ff5c33",
|
|
82
82
|
"--red-light": "#ffebe5",
|
|
83
83
|
"--shadow": "0px 12px 33px 0px rgba(0, 0, 0, .06),\n 0px 3.618px 9.949px 0px rgba(0, 0, 0, .04)"
|
|
84
|
-
},
|
|
84
|
+
}, L = (e, t, n) => ({
|
|
85
85
|
role: "textbox",
|
|
86
86
|
"data-pie-editor": "true",
|
|
87
87
|
class: "mathjax_ignore",
|
|
88
88
|
spellcheck: e ? "true" : "false",
|
|
89
89
|
autocorrect: e ? "on" : "off",
|
|
90
|
-
autocapitalize: e ? "on" : "off"
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
autocapitalize: e ? "on" : "off",
|
|
91
|
+
...t && { "aria-label": t },
|
|
92
|
+
...n && { "aria-labelledby": n }
|
|
93
|
+
}), R = ["aria-label", "aria-labelledby"], z = (b) => {
|
|
94
|
+
let { showParagraphs: C, separateParagraphs: z } = b.pluginProps || {}, [le, V] = y([]), [H, U] = y(!1), { toolbarOpts: W } = b, G = g((e) => {
|
|
95
|
+
V((t) => {
|
|
94
96
|
let n = t.filter((t) => t.pos !== e);
|
|
95
|
-
return n.length === 0 &&
|
|
97
|
+
return n.length === 0 && U(!1), n;
|
|
96
98
|
});
|
|
97
|
-
}, [
|
|
98
|
-
...
|
|
99
|
-
...
|
|
100
|
-
},
|
|
99
|
+
}, [V]), K = {
|
|
100
|
+
...P,
|
|
101
|
+
...W
|
|
102
|
+
}, q = g((e) => {
|
|
101
103
|
let t = e.getHTML();
|
|
102
|
-
|
|
104
|
+
b.markup !== t && b.onChange?.(t), K.doneOn === "blur" && b.onDone?.(t);
|
|
103
105
|
}, [
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
]),
|
|
109
|
-
...
|
|
110
|
-
...
|
|
111
|
-
onInlineDropdownToolbarClose:
|
|
112
|
-
}), [
|
|
113
|
-
let { customPlugins: e, ...t } =
|
|
106
|
+
b.markup,
|
|
107
|
+
b.onChange,
|
|
108
|
+
b.onDone,
|
|
109
|
+
K.doneOn
|
|
110
|
+
]), J = v(() => ({
|
|
111
|
+
...F,
|
|
112
|
+
...b.responseAreaProps,
|
|
113
|
+
onInlineDropdownToolbarClose: q
|
|
114
|
+
}), [b.responseAreaProps, q]), ue = v(() => {
|
|
115
|
+
let { customPlugins: e, ...t } = b.pluginProps || {};
|
|
114
116
|
e ||= [];
|
|
115
|
-
let n = (
|
|
116
|
-
let n =
|
|
117
|
+
let n = (b.activePlugins || ce)?.filter((e) => {
|
|
118
|
+
let n = m[e] || e, r = t[n] || {};
|
|
117
119
|
return !r || !r.disabled;
|
|
118
120
|
});
|
|
119
|
-
return
|
|
121
|
+
return h(n, e, {
|
|
120
122
|
math: {},
|
|
121
|
-
textAlign:
|
|
123
|
+
textAlign: b.textAlign,
|
|
122
124
|
html: {},
|
|
123
|
-
extraCSSRules:
|
|
124
|
-
image: { ...
|
|
125
|
+
extraCSSRules: b.extraCSSRules || {},
|
|
126
|
+
image: { ...b.imageSupport },
|
|
125
127
|
toolbar: {},
|
|
126
128
|
table: {},
|
|
127
|
-
responseArea: { type:
|
|
128
|
-
languageCharacters:
|
|
129
|
+
responseArea: { type: J.type },
|
|
130
|
+
languageCharacters: b.languageCharactersProps,
|
|
129
131
|
keyPadCharacterRef: {},
|
|
130
132
|
setKeypadInteraction: {},
|
|
131
133
|
media: {}
|
|
132
134
|
});
|
|
133
|
-
}, [
|
|
134
|
-
|
|
135
|
+
}, [b, J.type]), de = [
|
|
136
|
+
k.configure({
|
|
135
137
|
types: [
|
|
136
138
|
"heading",
|
|
137
139
|
"paragraph",
|
|
@@ -153,10 +155,10 @@ var I = {
|
|
|
153
155
|
"justify"
|
|
154
156
|
]
|
|
155
157
|
}),
|
|
156
|
-
|
|
158
|
+
T,
|
|
157
159
|
e,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
+
E.configure({ limit: b.charactersLimit || 1e6 }),
|
|
161
|
+
w.configure({
|
|
160
162
|
trailingNode: {
|
|
161
163
|
node: "paragraph",
|
|
162
164
|
notAfter: ["paragraph", "div"]
|
|
@@ -166,141 +168,148 @@ var I = {
|
|
|
166
168
|
linkOnPaste: !1
|
|
167
169
|
}
|
|
168
170
|
}),
|
|
169
|
-
|
|
171
|
+
ae,
|
|
170
172
|
a,
|
|
171
|
-
|
|
172
|
-
ee,
|
|
173
|
+
oe,
|
|
173
174
|
o,
|
|
174
|
-
|
|
175
|
-
|
|
175
|
+
ee,
|
|
176
|
+
j.configure({
|
|
177
|
+
placeholder: b.placeholder,
|
|
176
178
|
showOnlyWhenEditable: !0,
|
|
177
179
|
showOnlyCurrent: !1,
|
|
178
180
|
includeChildren: !0
|
|
179
181
|
}),
|
|
180
182
|
n,
|
|
181
|
-
|
|
183
|
+
M,
|
|
182
184
|
i,
|
|
183
185
|
r,
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
s.configure(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
toolbarOpts:
|
|
191
|
-
math:
|
|
186
|
+
ie.configure(J),
|
|
187
|
+
te.configure(J),
|
|
188
|
+
s.configure(J),
|
|
189
|
+
ne.configure(J),
|
|
190
|
+
re.configure(J),
|
|
191
|
+
c.configure({
|
|
192
|
+
toolbarOpts: K,
|
|
193
|
+
math: b.pluginProps?.math || {}
|
|
192
194
|
}),
|
|
195
|
+
O,
|
|
196
|
+
D,
|
|
193
197
|
A,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
u.configure({
|
|
197
|
-
toolbarOpts: J,
|
|
198
|
+
l.configure({
|
|
199
|
+
toolbarOpts: K,
|
|
198
200
|
imageHandling: {
|
|
199
|
-
disableImageAlignmentButtons:
|
|
200
|
-
onDone: (e) =>
|
|
201
|
-
onDelete:
|
|
201
|
+
disableImageAlignmentButtons: b.disableImageAlignmentButtons,
|
|
202
|
+
onDone: (e) => b.onDone?.(e.getHTML()),
|
|
203
|
+
onDelete: b.imageSupport && b.imageSupport.delete && ((e) => {
|
|
202
204
|
let { src: t } = e.attrs;
|
|
203
|
-
|
|
204
|
-
|
|
205
|
+
b.imageSupport.delete(t, (t) => {
|
|
206
|
+
G(e.pos);
|
|
205
207
|
});
|
|
206
208
|
}),
|
|
207
|
-
insertImageRequested:
|
|
209
|
+
insertImageRequested: b.imageSupport && ((e, t, n) => {
|
|
208
210
|
let [r, i] = t, a = (t) => {
|
|
209
211
|
let n;
|
|
210
|
-
|
|
212
|
+
H && t && (n = b.onChange), G(i), n?.(e.getHTML());
|
|
211
213
|
};
|
|
212
|
-
e._insertingImage = !0,
|
|
213
|
-
let t = n(a), r =
|
|
214
|
+
e._insertingImage = !0, V((e) => [...e, r]), (() => {
|
|
215
|
+
let t = n(a), r = se(() => {
|
|
214
216
|
let t = () => window.removeEventListener("focus", r);
|
|
215
217
|
if (!e._insertingImage) {
|
|
216
218
|
t();
|
|
217
219
|
return;
|
|
218
220
|
}
|
|
219
|
-
|
|
221
|
+
G(i), e._insertingImage = !1, t();
|
|
220
222
|
}, 500);
|
|
221
|
-
window.addEventListener("focus", r),
|
|
223
|
+
window.addEventListener("focus", r), b.imageSupport.add(t);
|
|
222
224
|
})();
|
|
223
225
|
}),
|
|
224
|
-
maxImageWidth:
|
|
225
|
-
maxImageHeight:
|
|
226
|
+
maxImageWidth: b.maxImageWidth,
|
|
227
|
+
maxImageHeight: b.maxImageHeight
|
|
226
228
|
},
|
|
227
229
|
limit: 3
|
|
228
230
|
}),
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
],
|
|
232
|
-
extensions:
|
|
231
|
+
u.configure({ uploadSoundSupport: b.uploadSoundSupport }),
|
|
232
|
+
d.configure({ extraCSSRules: b.extraCSSRules })
|
|
233
|
+
], Y = b.spellCheck !== !1, { ariaLabel: X, ariaLabelledBy: Z } = b, Q = x({
|
|
234
|
+
extensions: de,
|
|
233
235
|
immediatelyRender: !1,
|
|
234
236
|
editorProps: {
|
|
235
|
-
attributes:
|
|
237
|
+
attributes: L(Y, X, Z),
|
|
236
238
|
handleKeyDown(e, t) {
|
|
237
|
-
return
|
|
239
|
+
return b.onKeyDown ? b.onKeyDown(t) : !1;
|
|
238
240
|
}
|
|
239
241
|
},
|
|
240
|
-
editable: !
|
|
241
|
-
content: t(
|
|
242
|
+
editable: !b.disabled,
|
|
243
|
+
content: t(b.markup),
|
|
242
244
|
onUpdate: ({ editor: e, transaction: t }) => {
|
|
243
|
-
t.isDone &&
|
|
245
|
+
t.isDone && b.onChange?.(e.getHTML());
|
|
244
246
|
},
|
|
245
247
|
onBlur: ({ editor: e }) => {
|
|
246
|
-
e._insertingImage || e._toolbarOpened || e.isActive("inline_dropdown") || e.isActive("explicit_constructed_response") || !e.schema ||
|
|
248
|
+
e._insertingImage || e._toolbarOpened || e.isActive("inline_dropdown") || e.isActive("explicit_constructed_response") || !e.schema || q(e);
|
|
247
249
|
}
|
|
248
|
-
}, [
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}, [
|
|
252
|
-
Q?.setEditable(!
|
|
253
|
-
}, [
|
|
250
|
+
}, [b.charactersLimit]);
|
|
251
|
+
_(() => {
|
|
252
|
+
b.editorRef && b.editorRef(Q);
|
|
253
|
+
}, [b.editorRef, Q]), _(() => {
|
|
254
|
+
Q?.setEditable(!b.disabled);
|
|
255
|
+
}, [b.disabled, Q]), _(() => {
|
|
254
256
|
if (!Q) return;
|
|
255
|
-
let e = Q.options?.editorProps, t = {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
e?.attributes?.spellcheck !== t.spellcheck && Q.setOptions({ editorProps: {
|
|
257
|
+
let e = Q.options?.editorProps, t = e?.attributes || {}, n = L(Y, X, Z);
|
|
258
|
+
if (["spellcheck", ...R].every((e) => t[e] === n[e])) return;
|
|
259
|
+
let r = Object.fromEntries(Object.entries(t).filter(([e]) => !R.includes(e)));
|
|
260
|
+
Q.setOptions({ editorProps: {
|
|
260
261
|
...e,
|
|
261
|
-
attributes:
|
|
262
|
+
attributes: {
|
|
263
|
+
...r,
|
|
264
|
+
...n
|
|
265
|
+
}
|
|
262
266
|
} });
|
|
263
|
-
}, [
|
|
267
|
+
}, [
|
|
268
|
+
Y,
|
|
269
|
+
X,
|
|
270
|
+
Z,
|
|
271
|
+
Q
|
|
272
|
+
]), _(() => {
|
|
264
273
|
if (!Q) return;
|
|
265
|
-
let e = t(
|
|
274
|
+
let e = t(b.markup);
|
|
266
275
|
e !== Q.getHTML() && Q.commands.setContent(e, { emitUpdate: !1 });
|
|
267
|
-
}, [
|
|
268
|
-
Object.entries(
|
|
276
|
+
}, [b.markup, Q]), _(() => {
|
|
277
|
+
Object.entries(I).forEach(([e, t]) => {
|
|
269
278
|
document.documentElement.style.setProperty(e, t);
|
|
270
279
|
});
|
|
271
280
|
}, []);
|
|
272
|
-
let
|
|
281
|
+
let fe = S({
|
|
273
282
|
editor: Q,
|
|
274
283
|
selector: (e) => ({ isFocused: e.editor?.isFocused })
|
|
275
|
-
}), $ =
|
|
276
|
-
let { minWidth: e, width: t, maxWidth: n, minHeight: r, height: i, maxHeight: a } =
|
|
284
|
+
}), $ = v(() => {
|
|
285
|
+
let { minWidth: e, width: t, maxWidth: n, minHeight: r, height: i, maxHeight: a } = b;
|
|
277
286
|
return {
|
|
278
|
-
width:
|
|
279
|
-
minWidth:
|
|
280
|
-
maxWidth:
|
|
281
|
-
height:
|
|
282
|
-
minHeight:
|
|
283
|
-
maxHeight:
|
|
287
|
+
width: f(t),
|
|
288
|
+
minWidth: f(e),
|
|
289
|
+
maxWidth: f(n),
|
|
290
|
+
height: f(i),
|
|
291
|
+
minHeight: f(r),
|
|
292
|
+
maxHeight: f(a)
|
|
284
293
|
};
|
|
285
|
-
}, [
|
|
286
|
-
return /* @__PURE__ */
|
|
287
|
-
...
|
|
288
|
-
activePlugins:
|
|
289
|
-
toolbarOpts:
|
|
290
|
-
editorState:
|
|
294
|
+
}, [b]);
|
|
295
|
+
return /* @__PURE__ */ N(p, {
|
|
296
|
+
...b,
|
|
297
|
+
activePlugins: ue,
|
|
298
|
+
toolbarOpts: K,
|
|
299
|
+
editorState: fe,
|
|
291
300
|
editor: Q,
|
|
292
|
-
children: Q && /* @__PURE__ */
|
|
301
|
+
children: Q && /* @__PURE__ */ N(B, {
|
|
293
302
|
style: {
|
|
294
303
|
minHeight: $.minHeight,
|
|
295
304
|
height: $.height,
|
|
296
305
|
maxHeight: $.maxHeight
|
|
297
306
|
},
|
|
298
|
-
showParagraph:
|
|
299
|
-
separateParagraph:
|
|
307
|
+
showParagraph: C && !C.disabled,
|
|
308
|
+
separateParagraph: z && !z.disabled,
|
|
300
309
|
editor: Q
|
|
301
310
|
})
|
|
302
311
|
});
|
|
303
|
-
},
|
|
312
|
+
}, B = C(b, { shouldForwardProp: (e) => !["showParagraph", "separateParagraph"].includes(e) })(({ showParagraph: e, separateParagraph: t }) => ({
|
|
304
313
|
display: "flex",
|
|
305
314
|
outline: "none !important",
|
|
306
315
|
"& .ProseMirror": {
|
|
@@ -330,4 +339,4 @@ var I = {
|
|
|
330
339
|
}
|
|
331
340
|
}));
|
|
332
341
|
//#endregion
|
|
333
|
-
export {
|
|
342
|
+
export { z as EditableHtml, z as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/editable-html-tip-tap",
|
|
3
|
-
"version": "3.0.1-next.
|
|
3
|
+
"version": "3.0.1-next.20261004020741",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"@mui/icons-material": "^7.3.4",
|
|
15
15
|
"@mui/material": "^7.3.4",
|
|
16
16
|
"@pie-lib/drag": "5.0.1-next.20261004003105",
|
|
17
|
-
"@pie-lib/math-input": "9.0.1-next.
|
|
18
|
-
"@pie-lib/math-toolbar": "4.0.1-next.
|
|
17
|
+
"@pie-lib/math-input": "9.0.1-next.20261004020741",
|
|
18
|
+
"@pie-lib/math-toolbar": "4.0.1-next.20261004020741",
|
|
19
19
|
"@pie-lib/render-ui": "8.0.1-next.20261003161149",
|
|
20
20
|
"@tiptap/core": "3.31.3",
|
|
21
21
|
"@tiptap/extension-character-count": "3.31.3",
|