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