@pie-lib/editable-html-tip-tap 2.1.2-next.31 → 2.1.2-next.32
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.js +22 -12
- package/dist/components/EditableHtml.js +121 -107
- package/dist/components/MenuBar.js +135 -75
- package/dist/components/TiptapContainer.js +16 -3
- package/dist/components/common/done-button.js +1 -1
- package/dist/components/common/toolbar-buttons.js +23 -18
- package/dist/components/icons/TableIcons.js +2 -0
- package/dist/components/icons/TextAlign.js +10 -1
- package/dist/components/image/AltDialog.js +1 -1
- package/dist/components/image/ImageToolbar.js +2 -2
- package/dist/components/media/MediaDialog.js +1 -1
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.js +1 -1
- package/dist/components/respArea/DragInTheBlank/choice.js +3 -2
- package/dist/components/respArea/ExplicitConstructedResponse.js +40 -39
- package/dist/components/respArea/InlineDropdown.js +58 -51
- package/dist/components/respArea/MathTemplated.js +15 -14
- package/dist/components/respArea/inlineDropdownUtils.js +1 -1
- package/dist/extensions/css.js +8 -3
- package/dist/extensions/extended-table.js +1 -1
- package/dist/extensions/image-component.js +17 -12
- package/dist/extensions/math.js +131 -76
- package/dist/extensions/media.js +2 -2
- package/dist/extensions/responseArea.js +1 -5
- package/dist/index.js +1 -1
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +1 -1
- package/dist/utils/toolbar.d.ts +10 -0
- package/dist/utils/toolbar.js +7 -0
- package/package.json +12 -7
|
@@ -37,18 +37,28 @@ function h({ editor: l, opts: m, onClose: h }) {
|
|
|
37
37
|
w();
|
|
38
38
|
}, []), r(() => {
|
|
39
39
|
if (!l) return;
|
|
40
|
-
let e = l.options.element
|
|
41
|
-
|
|
42
|
-
top: i,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
40
|
+
let e = l.options.element, t = l.view.dom, n = () => {
|
|
41
|
+
if (!g.current) return;
|
|
42
|
+
let t = e.getBoundingClientRect(), { from: n } = l.state.selection, r = l.view.coordsAtPos(n), i = g.current.offsetHeight, a = g.current.offsetWidth, o = window.innerHeight - (t.bottom + 60) >= i || t.top < i + 80 ? t.bottom + 60 : t.top - i - 20, s = r.left;
|
|
43
|
+
o = Math.max(8, Math.min(o, window.innerHeight - i - 8)), s = Math.max(8, Math.min(s, window.innerWidth - a - 8)), y({
|
|
44
|
+
top: o,
|
|
45
|
+
left: s
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
n();
|
|
49
|
+
let r = null, i = () => {
|
|
50
|
+
r === null && (r = requestAnimationFrame(() => {
|
|
51
|
+
r = null, n();
|
|
52
|
+
}));
|
|
53
|
+
};
|
|
54
|
+
window.addEventListener("scroll", i, !0), window.addEventListener("resize", i);
|
|
55
|
+
let a = (e) => {
|
|
56
|
+
g.current && !g.current.contains(e.target) && !t.contains(e.target) && _.current();
|
|
57
|
+
}, o = setTimeout(() => {
|
|
58
|
+
document.addEventListener("click", a);
|
|
49
59
|
});
|
|
50
60
|
return () => {
|
|
51
|
-
clearTimeout(
|
|
61
|
+
clearTimeout(o), r !== null && cancelAnimationFrame(r), window.removeEventListener("scroll", i, !0), window.removeEventListener("resize", i), document.removeEventListener("click", a);
|
|
52
62
|
};
|
|
53
63
|
}, [l]);
|
|
54
64
|
let T = (e, t) => x({
|
|
@@ -61,11 +71,11 @@ function h({ editor: l, opts: m, onClose: h }) {
|
|
|
61
71
|
"data-toolbar-for": l.instanceId,
|
|
62
72
|
style: {
|
|
63
73
|
visibility: v.top === 0 && v.left === 0 ? "hidden" : "initial",
|
|
64
|
-
position: "
|
|
74
|
+
position: "fixed",
|
|
65
75
|
top: `${v.top}px`,
|
|
66
76
|
left: `${v.left}px`,
|
|
67
77
|
maxWidth: "500px",
|
|
68
|
-
zIndex:
|
|
78
|
+
zIndex: 1e3
|
|
69
79
|
},
|
|
70
80
|
children: /* @__PURE__ */ d("div", { children: /* @__PURE__ */ d(p, {
|
|
71
81
|
keyPadCharacterRef: m.keyPadCharacterRef,
|
|
@@ -4,37 +4,41 @@ 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 y, buildExtensions 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
|
|
7
|
+
import { DragInTheBlankNode as ee, ExplicitConstructedResponseNode as s, InlineDropdownNode as c, MathTemplatedNode as l, ResponseAreaExtension as u } from "../extensions/responseArea.js";
|
|
8
|
+
import { MathNode as d } from "../extensions/math.js";
|
|
9
|
+
import { ImageUploadNode as f } from "../extensions/image.js";
|
|
10
|
+
import { Media as p } from "../extensions/media.js";
|
|
11
|
+
import { CSSMark as m } from "../extensions/css.js";
|
|
12
|
+
import { ExtendedListItem as h } from "../extensions/extended-list-item.js";
|
|
13
|
+
import { HeadingParagraph as g } from "../extensions/heading-paragraph.js";
|
|
14
|
+
import { valueToSize as _ } from "../utils/size.js";
|
|
15
|
+
import v from "./TiptapContainer.js";
|
|
16
|
+
import { PLUGINS_MAP as y, buildExtensions as te } from "../extensions/index.js";
|
|
17
|
+
import { useCallback as b, useEffect as x, useMemo as S, useState as C } from "react";
|
|
18
|
+
import { debounce as w } from "@pie-element/shared-lodash";
|
|
19
|
+
import { EditorContent as T, useEditor as E, useEditorState as D } from "@tiptap/react";
|
|
20
|
+
import { styled as O } from "@mui/material/styles";
|
|
21
|
+
import k from "@tiptap/starter-kit";
|
|
22
|
+
import { TextStyleKit as A } from "@tiptap/extension-text-style";
|
|
23
|
+
import { CharacterCount as j } from "@tiptap/extension-character-count";
|
|
24
|
+
import M from "@tiptap/extension-superscript";
|
|
25
|
+
import N from "@tiptap/extension-subscript";
|
|
26
|
+
import P from "@tiptap/extension-text-align";
|
|
27
27
|
import F from "@tiptap/extension-image";
|
|
28
28
|
import I from "@tiptap/extension-placeholder";
|
|
29
|
-
import { TableRow as
|
|
30
|
-
import { jsx as
|
|
29
|
+
import { TableRow as ne } from "@tiptap/extension-table-row";
|
|
30
|
+
import { jsx as L } from "react/jsx-runtime";
|
|
31
31
|
//#region src/components/EditableHtml.tsx
|
|
32
|
-
var
|
|
32
|
+
var R = {
|
|
33
33
|
position: "bottom",
|
|
34
34
|
alignment: "left",
|
|
35
35
|
alwaysVisible: !1,
|
|
36
36
|
showDone: !0,
|
|
37
37
|
doneOn: "blur"
|
|
38
|
+
}, z = {
|
|
39
|
+
options: {},
|
|
40
|
+
respAreaToolbar: () => {},
|
|
41
|
+
onHandleAreaChange: () => {}
|
|
38
42
|
}, B = [
|
|
39
43
|
"bold",
|
|
40
44
|
"italic",
|
|
@@ -76,39 +80,51 @@ var z = {
|
|
|
76
80
|
"--red": "#ff5c33",
|
|
77
81
|
"--red-light": "#ffebe5",
|
|
78
82
|
"--shadow": "0px 12px 33px 0px rgba(0, 0, 0, .06),\n 0px 3.618px 9.949px 0px rgba(0, 0, 0, .04)"
|
|
79
|
-
}, H = (
|
|
80
|
-
let { showParagraphs:
|
|
83
|
+
}, H = (T) => {
|
|
84
|
+
let { showParagraphs: O, separateParagraphs: H } = T.pluginProps || {}, [re, W] = C([]), [G, K] = C(!1), { toolbarOpts: q } = T, J = b((e) => {
|
|
81
85
|
W((t) => {
|
|
82
86
|
let n = t.filter((t) => t.pos !== e);
|
|
83
87
|
return n.length === 0 && K(!1), n;
|
|
84
88
|
});
|
|
85
89
|
}, [W]), Y = {
|
|
86
|
-
...
|
|
90
|
+
...R,
|
|
87
91
|
...q
|
|
88
|
-
}, X =
|
|
89
|
-
let
|
|
92
|
+
}, X = b((e) => {
|
|
93
|
+
let t = e.getHTML();
|
|
94
|
+
T.markup !== t && T.onChange?.(t), Y.doneOn === "blur" && T.onDone?.(t);
|
|
95
|
+
}, [
|
|
96
|
+
T.markup,
|
|
97
|
+
T.onChange,
|
|
98
|
+
T.onDone,
|
|
99
|
+
Y.doneOn
|
|
100
|
+
]), Z = S(() => ({
|
|
101
|
+
...z,
|
|
102
|
+
...T.responseAreaProps,
|
|
103
|
+
onInlineDropdownToolbarClose: X
|
|
104
|
+
}), [T.responseAreaProps, X]), ie = S(() => {
|
|
105
|
+
let { customPlugins: e, ...t } = T.pluginProps || {};
|
|
90
106
|
e ||= [];
|
|
91
|
-
let n = (
|
|
92
|
-
let n =
|
|
93
|
-
return !
|
|
107
|
+
let n = (T.activePlugins || B)?.filter((e) => {
|
|
108
|
+
let n = y[e] || e, r = t[n] || {};
|
|
109
|
+
return !r || !r.disabled;
|
|
94
110
|
});
|
|
95
|
-
return
|
|
111
|
+
return te(n, e, {
|
|
96
112
|
math: {},
|
|
97
|
-
textAlign:
|
|
113
|
+
textAlign: T.textAlign,
|
|
98
114
|
html: {},
|
|
99
|
-
extraCSSRules:
|
|
100
|
-
image: { ...
|
|
115
|
+
extraCSSRules: T.extraCSSRules || {},
|
|
116
|
+
image: { ...T.imageSupport },
|
|
101
117
|
toolbar: {},
|
|
102
118
|
table: {},
|
|
103
|
-
responseArea: { type:
|
|
104
|
-
languageCharacters:
|
|
119
|
+
responseArea: { type: Z.type },
|
|
120
|
+
languageCharacters: T.languageCharactersProps,
|
|
105
121
|
keyPadCharacterRef: {},
|
|
106
122
|
setKeypadInteraction: {},
|
|
107
123
|
media: {}
|
|
108
124
|
});
|
|
109
|
-
}, [
|
|
125
|
+
}, [T, Z.type]), Q = E({
|
|
110
126
|
extensions: [
|
|
111
|
-
|
|
127
|
+
P.configure({
|
|
112
128
|
types: [
|
|
113
129
|
"heading",
|
|
114
130
|
"paragraph",
|
|
@@ -130,57 +146,57 @@ var z = {
|
|
|
130
146
|
"justify"
|
|
131
147
|
]
|
|
132
148
|
}),
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
149
|
+
A,
|
|
150
|
+
j.configure({ limit: T.charactersLimit || 1e6 }),
|
|
151
|
+
k.configure({ trailingNode: {
|
|
136
152
|
node: "paragraph",
|
|
137
153
|
notAfter: ["paragraph", "div"]
|
|
138
154
|
} }),
|
|
139
|
-
|
|
155
|
+
h,
|
|
140
156
|
i,
|
|
141
|
-
|
|
157
|
+
g,
|
|
142
158
|
a,
|
|
143
159
|
o,
|
|
144
160
|
I.configure({
|
|
145
|
-
placeholder:
|
|
161
|
+
placeholder: T.placeholder,
|
|
146
162
|
showOnlyWhenEditable: !0,
|
|
147
163
|
showOnlyCurrent: !1,
|
|
148
164
|
includeChildren: !0
|
|
149
165
|
}),
|
|
150
166
|
t,
|
|
151
|
-
|
|
167
|
+
ne,
|
|
152
168
|
r,
|
|
153
169
|
n,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
170
|
+
u.configure(Z),
|
|
171
|
+
s.configure(Z),
|
|
172
|
+
ee.configure(Z),
|
|
173
|
+
c.configure(Z),
|
|
174
|
+
l.configure(Z),
|
|
175
|
+
d.configure({
|
|
160
176
|
toolbarOpts: Y,
|
|
161
|
-
math:
|
|
177
|
+
math: T.pluginProps?.math || {}
|
|
162
178
|
}),
|
|
163
|
-
P,
|
|
164
179
|
N,
|
|
180
|
+
M,
|
|
165
181
|
F,
|
|
166
|
-
|
|
182
|
+
f.configure({
|
|
167
183
|
toolbarOpts: Y,
|
|
168
184
|
imageHandling: {
|
|
169
|
-
disableImageAlignmentButtons:
|
|
170
|
-
onDone: (e) =>
|
|
171
|
-
onDelete:
|
|
185
|
+
disableImageAlignmentButtons: T.disableImageAlignmentButtons,
|
|
186
|
+
onDone: (e) => T.onDone?.(e.getHTML()),
|
|
187
|
+
onDelete: T.imageSupport && T.imageSupport.delete && ((e) => {
|
|
172
188
|
let { src: t } = e.attrs;
|
|
173
|
-
|
|
189
|
+
T.imageSupport.delete(t, (t) => {
|
|
174
190
|
J(e.pos);
|
|
175
191
|
});
|
|
176
192
|
}),
|
|
177
|
-
insertImageRequested:
|
|
193
|
+
insertImageRequested: T.imageSupport && ((e, t, n) => {
|
|
178
194
|
let [r, i] = t, a = (t) => {
|
|
179
195
|
let n;
|
|
180
|
-
G && t && (n =
|
|
196
|
+
G && t && (n = T.onChange), J(i), n?.(e.getHTML());
|
|
181
197
|
};
|
|
182
198
|
e._insertingImage = !0, W((e) => [...e, r]), (() => {
|
|
183
|
-
let t = n(a), r =
|
|
199
|
+
let t = n(a), r = w(() => {
|
|
184
200
|
let t = () => window.removeEventListener("focus", r);
|
|
185
201
|
if (!e._insertingImage) {
|
|
186
202
|
t();
|
|
@@ -188,77 +204,75 @@ var z = {
|
|
|
188
204
|
}
|
|
189
205
|
J(i), e._insertingImage = !1, t();
|
|
190
206
|
}, 500);
|
|
191
|
-
window.addEventListener("focus", r),
|
|
207
|
+
window.addEventListener("focus", r), T.imageSupport.add(t);
|
|
192
208
|
})();
|
|
193
209
|
}),
|
|
194
|
-
maxImageWidth:
|
|
195
|
-
maxImageHeight:
|
|
210
|
+
maxImageWidth: T.maxImageWidth,
|
|
211
|
+
maxImageHeight: T.maxImageHeight
|
|
196
212
|
},
|
|
197
213
|
limit: 3
|
|
198
214
|
}),
|
|
199
|
-
|
|
200
|
-
|
|
215
|
+
p.configure({ uploadSoundSupport: T.uploadSoundSupport }),
|
|
216
|
+
m.configure({ extraCSSRules: T.extraCSSRules })
|
|
201
217
|
],
|
|
202
218
|
immediatelyRender: !1,
|
|
203
219
|
editorProps: { handleKeyDown(e, t) {
|
|
204
|
-
return
|
|
220
|
+
return T.onKeyDown ? T.onKeyDown(t) : !1;
|
|
205
221
|
} },
|
|
206
|
-
editable: !
|
|
207
|
-
content: e(
|
|
222
|
+
editable: !T.disabled,
|
|
223
|
+
content: e(T.markup),
|
|
208
224
|
onUpdate: ({ editor: e, transaction: t }) => {
|
|
209
|
-
t.isDone &&
|
|
225
|
+
t.isDone && T.onChange?.(e.getHTML());
|
|
210
226
|
},
|
|
211
227
|
onBlur: ({ editor: e }) => {
|
|
212
|
-
|
|
213
|
-
let t = e.getHTML();
|
|
214
|
-
E.markup !== t && E.onChange?.(t), Y.doneOn === "blur" && E.onDone?.(t);
|
|
228
|
+
e._insertingImage || e._toolbarOpened || e.isActive("inline_dropdown") || e.isActive("explicit_constructed_response") || !e.schema || X(e);
|
|
215
229
|
}
|
|
216
|
-
}, [
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}, [
|
|
220
|
-
|
|
221
|
-
}, [
|
|
222
|
-
if (!
|
|
223
|
-
let t = e(
|
|
224
|
-
t !==
|
|
225
|
-
}, [
|
|
230
|
+
}, [T.charactersLimit]);
|
|
231
|
+
x(() => {
|
|
232
|
+
T.editorRef && T.editorRef(Q);
|
|
233
|
+
}, [T.editorRef, Q]), x(() => {
|
|
234
|
+
Q?.setEditable(!T.disabled);
|
|
235
|
+
}, [T.disabled, Q]), x(() => {
|
|
236
|
+
if (!Q) return;
|
|
237
|
+
let t = e(T.markup);
|
|
238
|
+
t !== Q.getHTML() && Q.commands.setContent(t, { emitUpdate: !1 });
|
|
239
|
+
}, [T.markup, Q]), x(() => {
|
|
226
240
|
Object.entries(V).forEach(([e, t]) => {
|
|
227
241
|
document.documentElement.style.setProperty(e, t);
|
|
228
242
|
});
|
|
229
243
|
}, []);
|
|
230
|
-
let
|
|
231
|
-
editor:
|
|
244
|
+
let ae = D({
|
|
245
|
+
editor: Q,
|
|
232
246
|
selector: (e) => ({ isFocused: e.editor?.isFocused })
|
|
233
|
-
}), $ =
|
|
234
|
-
let { minWidth: e, width: t, maxWidth: n, minHeight: r, height: i, maxHeight: a } =
|
|
247
|
+
}), $ = S(() => {
|
|
248
|
+
let { minWidth: e, width: t, maxWidth: n, minHeight: r, height: i, maxHeight: a } = T;
|
|
235
249
|
return {
|
|
236
|
-
width:
|
|
237
|
-
minWidth:
|
|
238
|
-
maxWidth:
|
|
239
|
-
height:
|
|
240
|
-
minHeight:
|
|
241
|
-
maxHeight:
|
|
250
|
+
width: _(t),
|
|
251
|
+
minWidth: _(e),
|
|
252
|
+
maxWidth: _(n),
|
|
253
|
+
height: _(i),
|
|
254
|
+
minHeight: _(r),
|
|
255
|
+
maxHeight: _(a)
|
|
242
256
|
};
|
|
243
|
-
}, [
|
|
244
|
-
return /* @__PURE__ */
|
|
245
|
-
...
|
|
246
|
-
activePlugins:
|
|
257
|
+
}, [T]);
|
|
258
|
+
return /* @__PURE__ */ L(v, {
|
|
259
|
+
...T,
|
|
260
|
+
activePlugins: ie,
|
|
247
261
|
toolbarOpts: Y,
|
|
248
|
-
editorState:
|
|
249
|
-
editor:
|
|
250
|
-
children:
|
|
262
|
+
editorState: ae,
|
|
263
|
+
editor: Q,
|
|
264
|
+
children: Q && /* @__PURE__ */ L(U, {
|
|
251
265
|
style: {
|
|
252
266
|
minHeight: $.minHeight,
|
|
253
267
|
height: $.height,
|
|
254
268
|
maxHeight: $.maxHeight
|
|
255
269
|
},
|
|
256
|
-
showParagraph:
|
|
270
|
+
showParagraph: O && !O.disabled,
|
|
257
271
|
separateParagraph: H && !H.disabled,
|
|
258
|
-
editor:
|
|
272
|
+
editor: Q
|
|
259
273
|
})
|
|
260
274
|
});
|
|
261
|
-
}, U =
|
|
275
|
+
}, U = O(T, { shouldForwardProp: (e) => !["showParagraph", "separateParagraph"].includes(e) })(({ showParagraph: e, separateParagraph: t }) => ({
|
|
262
276
|
display: "flex",
|
|
263
277
|
outline: "none !important",
|
|
264
278
|
"& .ProseMirror": {
|
|
@@ -268,8 +282,8 @@ var z = {
|
|
|
268
282
|
outline: "none !important",
|
|
269
283
|
position: "initial",
|
|
270
284
|
"& > p, & > div": { margin: "0" },
|
|
271
|
-
"& p.is-
|
|
272
|
-
"& p.is-
|
|
285
|
+
"& p[data-placeholder].is-empty:only-child, & div[data-placeholder].is-empty:only-child": { position: "relative" },
|
|
286
|
+
"& p[data-placeholder].is-empty:only-child::before, & div[data-placeholder].is-empty:only-child::before": {
|
|
273
287
|
content: "attr(data-placeholder)",
|
|
274
288
|
position: "absolute",
|
|
275
289
|
left: 0,
|
|
@@ -288,4 +302,4 @@ var z = {
|
|
|
288
302
|
}
|
|
289
303
|
}));
|
|
290
304
|
//#endregion
|
|
291
|
-
export { H as default };
|
|
305
|
+
export { H as EditableHtml, H as default };
|