@pie-lib/editable-html-tip-tap 3.1.2-next.20261020062838 → 3.1.2-next.20261021000713
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 +87 -84
- package/dist/extensions/extended-list-item.js +1 -1
- package/dist/extensions/extended-table-cell.js +1 -1
- package/dist/extensions/image-component.d.ts +0 -2
- package/dist/extensions/image-component.js +86 -69
- package/dist/extensions/image.js +17 -5
- package/dist/extensions/math.d.ts +12 -0
- package/dist/extensions/math.js +114 -58
- package/package.json +7 -7
|
@@ -6,11 +6,11 @@ import { ExtendedTableCell as i, ExtendedTableHeader as a } from "../extensions/
|
|
|
6
6
|
import { DivNode as o } from "../extensions/div-node.js";
|
|
7
7
|
import { EnsureEmptyRootIsDiv as ee } from "../extensions/ensure-empty-root-div.js";
|
|
8
8
|
import { EnsureListItemContentIsDiv as s } from "../extensions/ensure-list-item-content-is-div.js";
|
|
9
|
-
import { DragInTheBlankNode as c, ExplicitConstructedResponseNode as
|
|
10
|
-
import { MathNode as
|
|
11
|
-
import { ImageUploadNode as
|
|
12
|
-
import { Media as
|
|
13
|
-
import { CSSMark as
|
|
9
|
+
import { DragInTheBlankNode as c, ExplicitConstructedResponseNode as l, InlineDropdownNode as u, MathTemplatedNode as te, ResponseAreaExtension as ne } from "../extensions/responseArea.js";
|
|
10
|
+
import { MathNode as re } from "../extensions/math.js";
|
|
11
|
+
import { ImageUploadNode as ie, uploadPastedImage as ae } from "../extensions/image.js";
|
|
12
|
+
import { Media as oe } from "../extensions/media.js";
|
|
13
|
+
import { CSSMark as se } from "../extensions/css.js";
|
|
14
14
|
import { ExtendedListItem as ce } from "../extensions/extended-list-item.js";
|
|
15
15
|
import { HeadingParagraph as le } from "../extensions/heading-paragraph.js";
|
|
16
16
|
import { valueToSize as d } from "../utils/size.js";
|
|
@@ -26,22 +26,21 @@ import { CharacterCount as ge } from "@tiptap/extension-character-count";
|
|
|
26
26
|
import _e from "@tiptap/extension-superscript";
|
|
27
27
|
import ve from "@tiptap/extension-subscript";
|
|
28
28
|
import ye from "@tiptap/extension-text-align";
|
|
29
|
-
import be from "@tiptap/extension-
|
|
30
|
-
import xe from "@tiptap/extension-
|
|
31
|
-
import {
|
|
32
|
-
import { jsx as S } from "react/jsx-runtime";
|
|
29
|
+
import be from "@tiptap/extension-placeholder";
|
|
30
|
+
import { TableRow as xe } from "@tiptap/extension-table-row";
|
|
31
|
+
import { jsx as x } from "react/jsx-runtime";
|
|
33
32
|
//#region src/components/EditableHtml.tsx
|
|
34
|
-
var
|
|
33
|
+
var S = {
|
|
35
34
|
position: "bottom",
|
|
36
35
|
alignment: "left",
|
|
37
36
|
alwaysVisible: !1,
|
|
38
37
|
showDone: !0,
|
|
39
38
|
doneOn: "blur"
|
|
40
|
-
},
|
|
39
|
+
}, C = {
|
|
41
40
|
options: {},
|
|
42
41
|
respAreaToolbar: () => {},
|
|
43
42
|
onHandleAreaChange: () => {}
|
|
44
|
-
},
|
|
43
|
+
}, w = [
|
|
45
44
|
"bold",
|
|
46
45
|
"italic",
|
|
47
46
|
"underline",
|
|
@@ -63,7 +62,7 @@ var C = {
|
|
|
63
62
|
"h3",
|
|
64
63
|
"undo",
|
|
65
64
|
"redo"
|
|
66
|
-
],
|
|
65
|
+
], T = {
|
|
67
66
|
bold: "bold",
|
|
68
67
|
italic: "italic",
|
|
69
68
|
underline: "underline",
|
|
@@ -74,7 +73,7 @@ var C = {
|
|
|
74
73
|
"numbered-list": "orderedList",
|
|
75
74
|
table: "table",
|
|
76
75
|
image: "image"
|
|
77
|
-
},
|
|
76
|
+
}, E = {
|
|
78
77
|
"--white": "#fff",
|
|
79
78
|
"--black": "#2e2b29",
|
|
80
79
|
"--black-contrast": "#110f0e",
|
|
@@ -93,7 +92,7 @@ var C = {
|
|
|
93
92
|
"--red": "#ff5c33",
|
|
94
93
|
"--red-light": "#ffebe5",
|
|
95
94
|
"--shadow": "0px 12px 33px 0px rgba(0, 0, 0, .06),\n 0px 3.618px 9.949px 0px rgba(0, 0, 0, .04)"
|
|
96
|
-
},
|
|
95
|
+
}, D = (e, t, n) => ({
|
|
97
96
|
role: "textbox",
|
|
98
97
|
"data-pie-editor": "true",
|
|
99
98
|
class: "mathjax_ignore",
|
|
@@ -102,50 +101,50 @@ var C = {
|
|
|
102
101
|
autocapitalize: e ? "on" : "off",
|
|
103
102
|
...t && { "aria-label": t },
|
|
104
103
|
...n && { "aria-labelledby": n }
|
|
105
|
-
}),
|
|
106
|
-
let { showParagraphs: b, separateParagraphs:
|
|
107
|
-
|
|
104
|
+
}), O = ["aria-label", "aria-labelledby"], k = (e) => e._insertingImage || e._toolbarOpened || e.isActive("inline_dropdown") || e.isActive("explicit_constructed_response"), A = (y) => {
|
|
105
|
+
let { showParagraphs: b, separateParagraphs: A } = y.pluginProps || {}, [Se, M] = _([]), [Ce, we] = _(!1), { toolbarOpts: Te } = y, N = p((e) => {
|
|
106
|
+
M((t) => {
|
|
108
107
|
let n = t.filter((t) => t.pos !== e);
|
|
109
108
|
return n.length === 0 && we(!1), n;
|
|
110
109
|
});
|
|
111
|
-
}, [
|
|
112
|
-
...
|
|
110
|
+
}, [M]), P = {
|
|
111
|
+
...S,
|
|
113
112
|
...Te
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
let
|
|
113
|
+
}, F = g([]), I = (e) => {
|
|
114
|
+
F.current = [...F.current.slice(-4), e], y.onChange?.(e);
|
|
115
|
+
}, L = g(I);
|
|
116
|
+
L.current = I;
|
|
117
|
+
let R = p((e) => {
|
|
119
118
|
let t = e.getHTML();
|
|
120
|
-
y.markup !== t &&
|
|
119
|
+
y.markup !== t && L.current(t), P.doneOn === "blur" && y.onDone?.(t);
|
|
121
120
|
}, [
|
|
122
121
|
y.markup,
|
|
123
122
|
y.onChange,
|
|
124
123
|
y.onDone,
|
|
125
|
-
|
|
126
|
-
]),
|
|
127
|
-
|
|
128
|
-
let { idleSaveDelay:
|
|
129
|
-
e.isDestroyed || (!
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
let
|
|
133
|
-
|
|
124
|
+
P.doneOn
|
|
125
|
+
]), z = g(R);
|
|
126
|
+
z.current = R;
|
|
127
|
+
let { idleSaveDelay: B } = y, V = g(!1), H = h(() => B > 0 ? v((e) => {
|
|
128
|
+
e.isDestroyed || (!V.current && (e.view.composing || k(e)) ? U.current?.(e) : z.current(e));
|
|
129
|
+
}, B) : null, [B]), U = g(H);
|
|
130
|
+
U.current = H;
|
|
131
|
+
let W = p((e) => {
|
|
132
|
+
V.current = !0;
|
|
134
133
|
try {
|
|
135
134
|
e?.flush();
|
|
136
135
|
} finally {
|
|
137
|
-
|
|
136
|
+
V.current = !1;
|
|
138
137
|
}
|
|
139
138
|
}, []);
|
|
140
|
-
m(() => () =>
|
|
141
|
-
let
|
|
142
|
-
...
|
|
139
|
+
m(() => () => W(H), [H, W]);
|
|
140
|
+
let G = p(() => W(U.current), [W]), K = h(() => ({
|
|
141
|
+
...C,
|
|
143
142
|
...y.responseAreaProps,
|
|
144
|
-
onInlineDropdownToolbarClose:
|
|
145
|
-
}), [y.responseAreaProps,
|
|
143
|
+
onInlineDropdownToolbarClose: R
|
|
144
|
+
}), [y.responseAreaProps, R]), q = h(() => {
|
|
146
145
|
let { customPlugins: e, ...t } = y.pluginProps || {};
|
|
147
146
|
e ||= [];
|
|
148
|
-
let n = (y.activePlugins ||
|
|
147
|
+
let n = (y.activePlugins || w)?.filter((e) => {
|
|
149
148
|
let n = de[e] || e, r = t[n] || {};
|
|
150
149
|
return !r || !r.disabled;
|
|
151
150
|
});
|
|
@@ -166,9 +165,9 @@ var C = {
|
|
|
166
165
|
}, [y, K.type]), J = g(null);
|
|
167
166
|
J.current = {
|
|
168
167
|
plainText: y.pluginProps?.pasteFormatting?.disabled === !0,
|
|
169
|
-
formatting: q.map((e) =>
|
|
168
|
+
formatting: q.map((e) => T[e]).filter(Boolean)
|
|
170
169
|
};
|
|
171
|
-
let
|
|
170
|
+
let Ee = [
|
|
172
171
|
ye.configure({
|
|
173
172
|
types: [
|
|
174
173
|
"heading",
|
|
@@ -194,7 +193,7 @@ var C = {
|
|
|
194
193
|
he,
|
|
195
194
|
e.configure({
|
|
196
195
|
settings: () => J.current,
|
|
197
|
-
uploadImage: y.imageSupport &&
|
|
196
|
+
uploadImage: y.imageSupport && ae
|
|
198
197
|
}),
|
|
199
198
|
ge.configure({ limit: y.charactersLimit || 1e6 }),
|
|
200
199
|
me.configure({
|
|
@@ -212,47 +211,47 @@ var C = {
|
|
|
212
211
|
le,
|
|
213
212
|
ee,
|
|
214
213
|
s,
|
|
215
|
-
|
|
214
|
+
be.configure({
|
|
216
215
|
placeholder: y.placeholder,
|
|
217
216
|
showOnlyWhenEditable: !0,
|
|
218
217
|
showOnlyCurrent: !1,
|
|
219
218
|
includeChildren: !0
|
|
220
219
|
}),
|
|
221
220
|
r,
|
|
222
|
-
|
|
221
|
+
xe,
|
|
223
222
|
a,
|
|
224
223
|
i,
|
|
225
|
-
re.configure(K),
|
|
226
|
-
te.configure(K),
|
|
227
|
-
c.configure(K),
|
|
228
|
-
l.configure(K),
|
|
229
224
|
ne.configure(K),
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
225
|
+
l.configure(K),
|
|
226
|
+
c.configure(K),
|
|
227
|
+
u.configure(K),
|
|
228
|
+
te.configure(K),
|
|
229
|
+
re.configure({
|
|
230
|
+
toolbarOpts: P,
|
|
231
|
+
math: y.pluginProps?.math || {},
|
|
232
|
+
mathMlOptions: y.mathMlOptions || {}
|
|
233
233
|
}),
|
|
234
234
|
ve,
|
|
235
235
|
_e,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
toolbarOpts: F,
|
|
236
|
+
ie.configure({
|
|
237
|
+
toolbarOpts: P,
|
|
239
238
|
imageHandling: {
|
|
240
239
|
disableImageAlignmentButtons: y.disableImageAlignmentButtons,
|
|
241
240
|
onDone: (e) => y.onDone?.(e.getHTML()),
|
|
242
241
|
onDelete: y.imageSupport && y.imageSupport.delete && ((e) => {
|
|
243
242
|
let { src: t } = e.attrs;
|
|
244
243
|
y.imageSupport.delete(t, (t) => {
|
|
245
|
-
|
|
244
|
+
N(e.pos);
|
|
246
245
|
});
|
|
247
246
|
}),
|
|
248
247
|
insertImageRequested: y.imageSupport && ((e, t, n) => {
|
|
249
248
|
let [r, i] = t, a = (t) => {
|
|
250
249
|
let n;
|
|
251
|
-
Ce && t && (n =
|
|
250
|
+
Ce && t && (n = L.current), N(i), n?.(e.getHTML());
|
|
252
251
|
};
|
|
253
|
-
e._insertingImage = !0,
|
|
252
|
+
e._insertingImage = !0, M((e) => [...e, r]), (() => {
|
|
254
253
|
let t = n(a), r = v(() => {
|
|
255
|
-
e._insertingImage &&= (
|
|
254
|
+
e._insertingImage &&= (N(i), !1), window.removeEventListener("focus", r);
|
|
256
255
|
}, 500);
|
|
257
256
|
window.addEventListener("focus", r), y.imageSupport.add(t);
|
|
258
257
|
})();
|
|
@@ -262,13 +261,13 @@ var C = {
|
|
|
262
261
|
},
|
|
263
262
|
limit: 3
|
|
264
263
|
}),
|
|
265
|
-
|
|
266
|
-
|
|
264
|
+
oe.configure({ uploadSoundSupport: y.uploadSoundSupport }),
|
|
265
|
+
se.configure({ extraCSSRules: y.extraCSSRules })
|
|
267
266
|
], Y = y.spellCheck !== !1, { ariaLabel: X, ariaLabelledBy: Z } = y, Q = fe({
|
|
268
|
-
extensions:
|
|
267
|
+
extensions: Ee,
|
|
269
268
|
immediatelyRender: !1,
|
|
270
269
|
editorProps: {
|
|
271
|
-
attributes:
|
|
270
|
+
attributes: D(Y, X, Z),
|
|
272
271
|
handleKeyDown(e, t) {
|
|
273
272
|
return y.onKeyDown ? y.onKeyDown(t) : !1;
|
|
274
273
|
}
|
|
@@ -276,23 +275,27 @@ var C = {
|
|
|
276
275
|
editable: !y.disabled,
|
|
277
276
|
content: t(y.markup),
|
|
278
277
|
onUpdate: ({ editor: e, transaction: t }) => {
|
|
279
|
-
t.isDone &&
|
|
278
|
+
t.isDone && L.current(e.getHTML()), t.docChanged && U.current && (U.current(e), n(e.view.dom, G));
|
|
280
279
|
},
|
|
281
280
|
onBlur: ({ editor: e }) => {
|
|
282
|
-
!
|
|
281
|
+
!k(e) && e.schema && (U.current?.cancel(), R(e));
|
|
283
282
|
}
|
|
284
|
-
}, [
|
|
283
|
+
}, [
|
|
284
|
+
y.charactersLimit,
|
|
285
|
+
y.mathMlOptions?.mmlEditing,
|
|
286
|
+
y.mathMlOptions?.mmlOutput
|
|
287
|
+
]);
|
|
285
288
|
m(() => {
|
|
286
289
|
y.editorRef && y.editorRef(Q);
|
|
287
290
|
}, [y.editorRef, Q]), m(() => {
|
|
288
291
|
Q?.setEditable(!y.disabled);
|
|
289
292
|
}, [y.disabled, Q]), m(() => {
|
|
290
|
-
Q?.on("destroy", () =>
|
|
291
|
-
}, [Q,
|
|
293
|
+
Q?.on("destroy", () => W(U.current));
|
|
294
|
+
}, [Q, W]), m(() => {
|
|
292
295
|
if (!Q) return;
|
|
293
|
-
let e = Q.options?.editorProps, t = e?.attributes || {}, n =
|
|
294
|
-
if (["spellcheck", ...
|
|
295
|
-
let r = Object.fromEntries(Object.entries(t).filter(([e]) => !
|
|
296
|
+
let e = Q.options?.editorProps, t = e?.attributes || {}, n = D(Y, X, Z);
|
|
297
|
+
if (["spellcheck", ...O].every((e) => t[e] === n[e])) return;
|
|
298
|
+
let r = Object.fromEntries(Object.entries(t).filter(([e]) => !O.includes(e)));
|
|
296
299
|
Q.setOptions({ editorProps: {
|
|
297
300
|
...e,
|
|
298
301
|
attributes: {
|
|
@@ -306,16 +309,16 @@ var C = {
|
|
|
306
309
|
Z,
|
|
307
310
|
Q
|
|
308
311
|
]), m(() => {
|
|
309
|
-
if (!Q ||
|
|
310
|
-
|
|
312
|
+
if (!Q || F.current.includes(y.markup)) return;
|
|
313
|
+
F.current = [];
|
|
311
314
|
let e = t(y.markup);
|
|
312
315
|
e !== Q.getHTML() && Q.commands.setContent(e, { emitUpdate: !1 });
|
|
313
316
|
}, [y.markup, Q]), m(() => {
|
|
314
|
-
Object.entries(
|
|
317
|
+
Object.entries(E).forEach(([e, t]) => {
|
|
315
318
|
document.documentElement.style.setProperty(e, t);
|
|
316
319
|
});
|
|
317
320
|
}, []);
|
|
318
|
-
let
|
|
321
|
+
let De = pe({
|
|
319
322
|
editor: Q,
|
|
320
323
|
selector: (e) => ({ isFocused: e.editor?.isFocused })
|
|
321
324
|
}), $ = h(() => {
|
|
@@ -329,24 +332,24 @@ var C = {
|
|
|
329
332
|
maxHeight: d(a)
|
|
330
333
|
};
|
|
331
334
|
}, [y]);
|
|
332
|
-
return /* @__PURE__ */
|
|
335
|
+
return /* @__PURE__ */ x(ue, {
|
|
333
336
|
...y,
|
|
334
337
|
activePlugins: q,
|
|
335
|
-
toolbarOpts:
|
|
336
|
-
editorState:
|
|
338
|
+
toolbarOpts: P,
|
|
339
|
+
editorState: De,
|
|
337
340
|
editor: Q,
|
|
338
|
-
children: Q && /* @__PURE__ */
|
|
341
|
+
children: Q && /* @__PURE__ */ x(j, {
|
|
339
342
|
style: {
|
|
340
343
|
minHeight: $.minHeight,
|
|
341
344
|
height: $.height,
|
|
342
345
|
maxHeight: $.maxHeight
|
|
343
346
|
},
|
|
344
347
|
showParagraph: b && !b.disabled,
|
|
345
|
-
separateParagraph:
|
|
348
|
+
separateParagraph: A && !A.disabled,
|
|
346
349
|
editor: Q
|
|
347
350
|
})
|
|
348
351
|
});
|
|
349
|
-
},
|
|
352
|
+
}, j = b(y, { shouldForwardProp: (e) => !["showParagraph", "separateParagraph"].includes(e) })(({ showParagraph: e, separateParagraph: t }) => ({
|
|
350
353
|
display: "flex",
|
|
351
354
|
outline: "none !important",
|
|
352
355
|
"& .ProseMirror": {
|
|
@@ -376,4 +379,4 @@ var C = {
|
|
|
376
379
|
}
|
|
377
380
|
}));
|
|
378
381
|
//#endregion
|
|
379
|
-
export {
|
|
382
|
+
export { A as EditableHtml, A as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ListItem as e } from "@tiptap/extension-list-item";
|
|
2
2
|
//#region src/extensions/extended-list-item.tsx
|
|
3
|
-
var t = e.extend({ content: "(div | paragraph | heading | bulletList | orderedList | blockquote | codeBlock | horizontalRule |
|
|
3
|
+
var t = e.extend({ content: "(div | paragraph | heading | bulletList | orderedList | blockquote | codeBlock | horizontalRule | imageUploadNode)+" });
|
|
4
4
|
//#endregion
|
|
5
5
|
export { t as ExtendedListItem };
|
|
@@ -2,7 +2,7 @@ import { scopeAttribute as e } from "./table-semantics.js";
|
|
|
2
2
|
import { TableCell as t } from "@tiptap/extension-table-cell";
|
|
3
3
|
import { TableHeader as n } from "@tiptap/extension-table-header";
|
|
4
4
|
//#region src/extensions/extended-table-cell.ts
|
|
5
|
-
var r = "(div | paragraph | heading | bulletList | orderedList | blockquote | codeBlock | horizontalRule |
|
|
5
|
+
var r = "(div | paragraph | heading | bulletList | orderedList | blockquote | codeBlock | horizontalRule | imageUploadNode)+", i = t.extend({ content: r }), a = n.extend({
|
|
6
6
|
content: r,
|
|
7
7
|
addAttributes() {
|
|
8
8
|
return {
|
|
@@ -7,8 +7,6 @@ declare namespace ImageComponent {
|
|
|
7
7
|
editor: PropTypes.Validator<object>;
|
|
8
8
|
attributes: PropTypes.Requireable<object>;
|
|
9
9
|
onFocus: PropTypes.Requireable<(...args: any[]) => any>;
|
|
10
|
-
maxImageWidth: PropTypes.Requireable<number>;
|
|
11
|
-
maxImageHeight: PropTypes.Requireable<number>;
|
|
12
10
|
};
|
|
13
11
|
}
|
|
14
12
|
export default ImageComponent;
|
|
@@ -46,60 +46,74 @@ var y = f(v, { shouldForwardProp: (e) => e !== "hideProgress" })(({ hideProgress
|
|
|
46
46
|
marginLeft: "5px",
|
|
47
47
|
marginRight: "10px",
|
|
48
48
|
display: "none"
|
|
49
|
-
})), w = (e) => e ? `${e}px` : "calc(20px)"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
})), w = (e) => e ? `${e}px` : "calc(20px)", T = 700, E = 900, D = ({ width: e, height: t }, n, r) => {
|
|
50
|
+
let i = Math.min(1, n / e, r / t);
|
|
51
|
+
return i < 1 ? {
|
|
52
|
+
width: Math.round(e * i),
|
|
53
|
+
height: Math.round(t * i)
|
|
54
|
+
} : {
|
|
55
|
+
width: e,
|
|
56
|
+
height: t
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
function O(f) {
|
|
60
|
+
let { node: m, editor: _, attributes: v, onFocus: O, getPos: k, selected: A, options: j } = f;
|
|
61
|
+
console.log({ ...f.options });
|
|
62
|
+
let M = j?.imageHandling?.maxImageWidth || T, N = j?.imageHandling?.maxImageHeight || E, { alt: ee } = m.attrs, P = k(), F = _.state.selection.from, I = _.state.selection.to, L = s(() => F + m.nodeSize === I, [
|
|
63
|
+
F,
|
|
64
|
+
I,
|
|
54
65
|
m.nodeSize
|
|
55
|
-
]), [
|
|
56
|
-
let t = e /
|
|
66
|
+
]), [R, z] = l(!1), B = c(m), V = c(null), H = c(null), U = c(null), W = a((e) => {
|
|
67
|
+
let t = e / V.current.naturalWidth * 4;
|
|
57
68
|
return parseInt(t.toFixed(0) * 25, 10);
|
|
58
|
-
}, []),
|
|
59
|
-
let e = n(_,
|
|
69
|
+
}, []), G = a(() => {
|
|
70
|
+
let e = n(_, B.current.attrs.nodeKey);
|
|
60
71
|
return e ? e[1] : null;
|
|
61
|
-
}, [_]),
|
|
62
|
-
let t =
|
|
72
|
+
}, [_]), K = a((e) => {
|
|
73
|
+
let t = G();
|
|
63
74
|
if (t === null) return;
|
|
64
75
|
let n = _.state.doc.nodeAt(t);
|
|
65
76
|
n && _.view.dispatch(_.state.tr.setNodeMarkup(t, void 0, {
|
|
66
77
|
...n.attrs,
|
|
67
78
|
...e
|
|
68
79
|
}));
|
|
69
|
-
}, [_,
|
|
70
|
-
if (!m.attrs.width || !
|
|
71
|
-
let e =
|
|
72
|
-
m.attrs.resizePercent !== e &&
|
|
80
|
+
}, [_, G]), q = a(() => {
|
|
81
|
+
if (!m.attrs.width || !V.current || !V.current.naturalWidth) return;
|
|
82
|
+
let e = W(m.attrs.width);
|
|
83
|
+
m.attrs.resizePercent !== e && K({ resizePercent: e });
|
|
73
84
|
}, [
|
|
74
85
|
m.attrs.width,
|
|
75
86
|
m.attrs.resizePercent,
|
|
76
|
-
|
|
77
|
-
|
|
87
|
+
W,
|
|
88
|
+
K
|
|
78
89
|
]);
|
|
79
90
|
o(() => {
|
|
80
|
-
|
|
91
|
+
B.current = {
|
|
81
92
|
...m,
|
|
82
|
-
pos:
|
|
93
|
+
pos: P
|
|
83
94
|
};
|
|
84
|
-
}, [m,
|
|
85
|
-
|
|
95
|
+
}, [m, P]), o(() => {
|
|
96
|
+
A ? L && _.isEditable && (!String(m.attrs?.src ?? "").trim() && j.imageHandling?.insertImageRequested && j.imageHandling.insertImageRequested(_, [m, P], (e) => new r(_, [m, P], e)), z(A)) : z(A);
|
|
86
97
|
}, [
|
|
87
|
-
|
|
88
|
-
|
|
98
|
+
L,
|
|
99
|
+
A,
|
|
89
100
|
_.isEditable
|
|
90
101
|
]), o(() => {
|
|
91
|
-
|
|
92
|
-
let e =
|
|
93
|
-
return e && _.isEditable && e.addEventListener("mousedown",
|
|
94
|
-
e && e.removeEventListener("mousedown",
|
|
102
|
+
q();
|
|
103
|
+
let e = H?.current;
|
|
104
|
+
return e && _.isEditable && e.addEventListener("mousedown", $, !1), () => {
|
|
105
|
+
e && e.removeEventListener("mousedown", $, !1);
|
|
95
106
|
};
|
|
96
107
|
}, []), o(() => {
|
|
97
|
-
|
|
108
|
+
q();
|
|
98
109
|
});
|
|
99
|
-
let
|
|
100
|
-
let e =
|
|
110
|
+
let J = a(() => {
|
|
111
|
+
let e = V.current;
|
|
101
112
|
if (e && (!e.style.width || e.style.width === "calc(20px)")) {
|
|
102
|
-
let
|
|
113
|
+
let { width: t, height: n } = D({
|
|
114
|
+
width: e.naturalWidth,
|
|
115
|
+
height: e.naturalHeight
|
|
116
|
+
}, M, N);
|
|
103
117
|
e.style.width = `${t}px`, e.style.height = `${n}px`;
|
|
104
118
|
let r = {
|
|
105
119
|
width: t,
|
|
@@ -108,15 +122,15 @@ function T(f) {
|
|
|
108
122
|
u(r, {
|
|
109
123
|
width: m.attrs.width,
|
|
110
124
|
height: m.attrs.height
|
|
111
|
-
}) ||
|
|
125
|
+
}) || K(r);
|
|
112
126
|
}
|
|
113
127
|
}, [
|
|
114
128
|
m.attrs.width,
|
|
115
129
|
m.attrs.height,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
]),
|
|
130
|
+
M,
|
|
131
|
+
N,
|
|
132
|
+
K
|
|
133
|
+
]), Y = (e, t, n = !0, r) => {
|
|
120
134
|
if (n) {
|
|
121
135
|
let n = e.width / e.height;
|
|
122
136
|
return r === "height" ? {
|
|
@@ -128,40 +142,45 @@ function T(f) {
|
|
|
128
142
|
};
|
|
129
143
|
}
|
|
130
144
|
return t;
|
|
131
|
-
},
|
|
132
|
-
let t =
|
|
145
|
+
}, X = a((e) => {
|
|
146
|
+
let t = V.current;
|
|
133
147
|
if (!t) return;
|
|
134
148
|
let n = e.target.getBoundingClientRect(), r = {
|
|
135
149
|
width: t.naturalWidth,
|
|
136
150
|
height: t.naturalHeight
|
|
137
|
-
}, i =
|
|
151
|
+
}, i = D(Y(r, {
|
|
138
152
|
width: e.clientX - n.left,
|
|
139
153
|
height: e.clientY - n.top
|
|
140
|
-
});
|
|
141
|
-
i.width > 50 && i.height > 50 &&
|
|
154
|
+
}), M, N);
|
|
155
|
+
i.width > 50 && i.height > 50 && (t.style.width = `${i.width}px`, t.style.height = `${i.height}px`, K({
|
|
142
156
|
width: i.width,
|
|
143
157
|
height: i.height
|
|
144
158
|
}));
|
|
145
|
-
}, [
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
159
|
+
}, [
|
|
160
|
+
_,
|
|
161
|
+
K,
|
|
162
|
+
M,
|
|
163
|
+
N
|
|
164
|
+
]), Z = a((e) => {
|
|
165
|
+
K(e);
|
|
166
|
+
}, [_, K]), Q = a(() => {
|
|
167
|
+
window.removeEventListener("mousemove", X), window.removeEventListener("mouseup", Q);
|
|
168
|
+
}, [X]), $ = a(() => {
|
|
169
|
+
window.addEventListener("mousemove", X), window.addEventListener("mouseup", Q);
|
|
170
|
+
}, [X, Q]), te = {
|
|
152
171
|
width: w(m.attrs.width),
|
|
153
172
|
height: w(m.attrs.height),
|
|
154
173
|
objectFit: "contain"
|
|
155
|
-
},
|
|
174
|
+
}, ne = {
|
|
156
175
|
left: "flex-start",
|
|
157
176
|
center: "center",
|
|
158
177
|
right: "flex-end"
|
|
159
178
|
}[m.attrs.alignment] || "flex-start";
|
|
160
179
|
return /* @__PURE__ */ g(d, { children: [/* @__PURE__ */ g(b, {
|
|
161
|
-
onFocus:
|
|
180
|
+
onFocus: O,
|
|
162
181
|
loading: !m.attrs.loaded,
|
|
163
182
|
pendingDelete: m.attrs.deleteStatus === "pending",
|
|
164
|
-
style: { justifyContent:
|
|
183
|
+
style: { justifyContent: ne },
|
|
165
184
|
children: [/* @__PURE__ */ h(y, {
|
|
166
185
|
mode: "determinate",
|
|
167
186
|
value: m.attrs.percent || 0,
|
|
@@ -170,21 +189,21 @@ function T(f) {
|
|
|
170
189
|
onDragStart: (e) => e.preventDefault(),
|
|
171
190
|
children: [/* @__PURE__ */ h(S, {
|
|
172
191
|
...v,
|
|
173
|
-
active:
|
|
192
|
+
active: A && m.attrs.loaded,
|
|
174
193
|
draggable: !1,
|
|
175
|
-
ref:
|
|
194
|
+
ref: V,
|
|
176
195
|
src: m.attrs.src,
|
|
177
|
-
style:
|
|
178
|
-
onLoad:
|
|
196
|
+
style: te,
|
|
197
|
+
onLoad: J,
|
|
179
198
|
alt: m.attrs.alt
|
|
180
199
|
}), /* @__PURE__ */ h(C, {
|
|
181
|
-
ref:
|
|
200
|
+
ref: H,
|
|
182
201
|
className: "resize",
|
|
183
202
|
style: { display: _.isEditable ? void 0 : "none" }
|
|
184
203
|
})]
|
|
185
204
|
})]
|
|
186
|
-
}),
|
|
187
|
-
ref:
|
|
205
|
+
}), R && _._tiptapContainerEl && p.createPortal(/* @__PURE__ */ h("div", {
|
|
206
|
+
ref: U,
|
|
188
207
|
style: {
|
|
189
208
|
zIndex: 20,
|
|
190
209
|
background: e,
|
|
@@ -194,31 +213,29 @@ function T(f) {
|
|
|
194
213
|
children: /* @__PURE__ */ h(t, {
|
|
195
214
|
showDone: !0,
|
|
196
215
|
deletable: !0,
|
|
197
|
-
toolbarOpts:
|
|
216
|
+
toolbarOpts: j.toolbarOpts || {},
|
|
198
217
|
onDelete: () => {
|
|
199
|
-
let e =
|
|
200
|
-
e !== null && (
|
|
218
|
+
let e = G();
|
|
219
|
+
e !== null && (j.imageHandling?.onDelete?.(B.current), _.view.dispatch(_.state.tr.delete(e, e + _.state.doc.nodeAt(e).nodeSize)), z(!1), _.commands.focus());
|
|
201
220
|
},
|
|
202
221
|
onDone: () => {
|
|
203
|
-
|
|
222
|
+
z(!1), j.imageHandling?.onDone?.(_), _.commands.focus("end");
|
|
204
223
|
},
|
|
205
224
|
children: /* @__PURE__ */ h(i, {
|
|
206
|
-
disableImageAlignmentButtons:
|
|
225
|
+
disableImageAlignmentButtons: j.imageHandling?.disableImageAlignmentButtons,
|
|
207
226
|
alt: m.attrs.alt,
|
|
208
227
|
imageLoaded: m.attrs.loaded,
|
|
209
228
|
alignment: m.attrs.alignment || "left",
|
|
210
|
-
onChange:
|
|
229
|
+
onChange: Z
|
|
211
230
|
})
|
|
212
231
|
})
|
|
213
232
|
}), _._tiptapContainerEl)] });
|
|
214
233
|
}
|
|
215
|
-
|
|
234
|
+
O.propTypes = {
|
|
216
235
|
node: m.object.isRequired,
|
|
217
236
|
editor: m.object.isRequired,
|
|
218
237
|
attributes: m.object,
|
|
219
|
-
onFocus: m.func
|
|
220
|
-
maxImageWidth: m.number,
|
|
221
|
-
maxImageHeight: m.number
|
|
238
|
+
onFocus: m.func
|
|
222
239
|
};
|
|
223
240
|
//#endregion
|
|
224
|
-
export {
|
|
241
|
+
export { O as default };
|
package/dist/extensions/image.js
CHANGED
|
@@ -34,19 +34,31 @@ var f = a.create({
|
|
|
34
34
|
draggable: !0,
|
|
35
35
|
addAttributes() {
|
|
36
36
|
return {
|
|
37
|
-
nodeKey: {
|
|
38
|
-
|
|
37
|
+
nodeKey: {
|
|
38
|
+
default: null,
|
|
39
|
+
parseHTML: (e) => e.getAttribute("nodeKey") || t()
|
|
40
|
+
},
|
|
41
|
+
loaded: {
|
|
42
|
+
default: !1,
|
|
43
|
+
parseHTML: (e) => e.hasAttribute("loaded") ? e.getAttribute("loaded") !== "false" : !/^data:/i.test(e.getAttribute("src") ?? "")
|
|
44
|
+
},
|
|
39
45
|
deleteStatus: { default: null },
|
|
40
46
|
alignment: { default: null },
|
|
41
47
|
percent: { default: null },
|
|
42
|
-
width: {
|
|
43
|
-
|
|
48
|
+
width: {
|
|
49
|
+
default: null,
|
|
50
|
+
parseHTML: (e) => parseInt(e.getAttribute("width"), 10) || null
|
|
51
|
+
},
|
|
52
|
+
height: {
|
|
53
|
+
default: null,
|
|
54
|
+
parseHTML: (e) => parseInt(e.getAttribute("height"), 10) || null
|
|
55
|
+
},
|
|
44
56
|
src: { default: null },
|
|
45
57
|
alt: { default: null }
|
|
46
58
|
};
|
|
47
59
|
},
|
|
48
60
|
parseHTML() {
|
|
49
|
-
return [{ tag: "img[data-type=\"image-upload-node\"]" }];
|
|
61
|
+
return [{ tag: "img[data-type=\"image-upload-node\"]" }, { tag: "img[src]" }];
|
|
50
62
|
},
|
|
51
63
|
renderHTML({ HTMLAttributes: e }) {
|
|
52
64
|
return ["img", o(e, { "data-type": "image-upload-node" })];
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Node } from '@tiptap/core';
|
|
3
3
|
import { Plugin } from 'prosemirror-state';
|
|
4
|
+
/**
|
|
5
|
+
* LaTeX for a MathML string, or null when there is none to give. `mmlToLatex` answers an empty
|
|
6
|
+
* string for MathML it cannot read, and the input back when its converter throws; neither is LaTeX,
|
|
7
|
+
* and neither may become a math node.
|
|
8
|
+
*/
|
|
9
|
+
export declare const convertMathMlToLatex: (mathMl: any) => string | null;
|
|
10
|
+
/**
|
|
11
|
+
* MathML for LaTeX, or null when there is none to give: MathJax has not started, or cannot read the
|
|
12
|
+
* LaTeX. A caller keeps the LaTeX then. The MathML carries the LaTeX it was made from, so that
|
|
13
|
+
* editing it again reads that back exactly, where converting the MathML would lose some.
|
|
14
|
+
*/
|
|
15
|
+
export declare const convertLatexToMathMl: (latex: any, wrapper: any) => string | null;
|
|
4
16
|
export declare const EnsureTextAfterMathPlugin: (mathNodeName: any) => Plugin<any>;
|
|
5
17
|
export declare const ZeroWidthSpaceHandlingPlugin: Plugin<any>;
|
|
6
18
|
export declare const MathNode: Node<any, any>;
|
package/dist/extensions/math.js
CHANGED
|
@@ -6,16 +6,42 @@ import { Node as s } from "@tiptap/core";
|
|
|
6
6
|
import { NodeSelection as c, Plugin as l, PluginKey as u, TextSelection as d } from "prosemirror-state";
|
|
7
7
|
import f from "react-dom";
|
|
8
8
|
import { jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
9
|
-
import {
|
|
10
|
-
import { MathPreview as
|
|
9
|
+
import { latexToMml as h, mmlToLatex as g, unWrapMath as _, wrapMath as v } from "@pie-element/shared-math-rendering-mathjax";
|
|
10
|
+
import { MathPreview as y, MathToolbar as b } from "@pie-lib/math-toolbar";
|
|
11
11
|
//#region src/extensions/math.tsx
|
|
12
|
-
var
|
|
12
|
+
var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>⁡<\/mo>/g, C = {
|
|
13
|
+
open: "\\[",
|
|
14
|
+
close: "\\]"
|
|
15
|
+
}, w = "data-pie-latex", T = (e) => e.replaceAll("&", "&").replaceAll("\"", """).replaceAll("<", "<").replaceAll(">", ">"), E = (e) => typeof e == "string" ? e === "double_dollar" : ["$$", "\\["].includes(e?.open), D = (e) => {
|
|
16
|
+
let t = e.replaceAll(" ", " "), n = g(t);
|
|
17
|
+
return !n || n === t ? null : n.replace(x, "") || null;
|
|
18
|
+
}, O = (e, t) => {
|
|
19
|
+
let n = h(e, { display: E(t) });
|
|
20
|
+
return !n || !n.startsWith("<math") ? null : n.replace(S, "").replace("<math", () => `<math ${w}="${T(e)}"`);
|
|
21
|
+
}, k = (e, t, n) => {
|
|
22
|
+
if (!t?.mathMlOptions?.mmlEditing) return !1;
|
|
23
|
+
let r = n?.getAttribute("display") === "block" ? C : null, i = (n?.getAttribute(w) ?? n?.getAttribute("data-latex"))?.trim();
|
|
24
|
+
if (i) return {
|
|
25
|
+
latex: i,
|
|
26
|
+
wrapper: r
|
|
27
|
+
};
|
|
28
|
+
let a = D(e);
|
|
29
|
+
if (a === null) return !1;
|
|
30
|
+
let { unwrapped: o, wrapper: s } = _(a);
|
|
31
|
+
return {
|
|
32
|
+
latex: o,
|
|
33
|
+
wrapper: s || r
|
|
34
|
+
};
|
|
35
|
+
}, A = (e) => {
|
|
36
|
+
let t = document.implementation.createHTMLDocument("").createElement("span");
|
|
37
|
+
return t.setAttribute("data-type", "mathml"), t.innerHTML = e, t;
|
|
38
|
+
}, j = new u("ensureTextAfterMath"), M = (e = []) => e.map((e) => ({
|
|
13
39
|
name: e,
|
|
14
40
|
latex: e,
|
|
15
41
|
write: e,
|
|
16
42
|
label: e
|
|
17
|
-
})),
|
|
18
|
-
key:
|
|
43
|
+
})), N = (e) => new l({
|
|
44
|
+
key: j,
|
|
19
45
|
appendTransaction: (t, n, r) => {
|
|
20
46
|
if (!t.some((e) => e.docChanged)) return null;
|
|
21
47
|
let i = r.tr, a = !1;
|
|
@@ -26,7 +52,7 @@ var y = new u("ensureTextAfterMath"), b = (e = []) => e.map((e) => ({
|
|
|
26
52
|
}
|
|
27
53
|
}), a ? i : null;
|
|
28
54
|
}
|
|
29
|
-
}),
|
|
55
|
+
}), P = (e, t) => {
|
|
30
56
|
let n;
|
|
31
57
|
for (n = t; n > 0; n--) {
|
|
32
58
|
let t = e.nodeAt(n);
|
|
@@ -34,16 +60,16 @@ var y = new u("ensureTextAfterMath"), b = (e = []) => e.map((e) => ({
|
|
|
34
60
|
if (t && t?.type?.name !== "text") break;
|
|
35
61
|
}
|
|
36
62
|
return n;
|
|
37
|
-
},
|
|
63
|
+
}, F = new l({
|
|
38
64
|
key: new u("zeroWidthSpaceHandling"),
|
|
39
65
|
props: { handleKeyDown(e, t) {
|
|
40
66
|
let { state: n, dispatch: r } = e, { selection: i, doc: a } = n, { from: o, empty: s } = i;
|
|
41
67
|
if (s && t.key === "Backspace" && o > 0) {
|
|
42
|
-
let e =
|
|
68
|
+
let e = P(a, o);
|
|
43
69
|
return e !== -1 && (r(n.tr.delete(e, o)), !0);
|
|
44
70
|
}
|
|
45
71
|
if (s && t.key === "ArrowLeft" && o > 0) {
|
|
46
|
-
let e =
|
|
72
|
+
let e = P(a, o);
|
|
47
73
|
if (e === -1) return !1;
|
|
48
74
|
let t = n.doc.resolve(e);
|
|
49
75
|
if (t.nodeAfter || t.nodeBefore) {
|
|
@@ -54,7 +80,7 @@ var y = new u("ensureTextAfterMath"), b = (e = []) => e.map((e) => ({
|
|
|
54
80
|
}
|
|
55
81
|
return !1;
|
|
56
82
|
} }
|
|
57
|
-
}),
|
|
83
|
+
}), I = s.create({
|
|
58
84
|
name: "math",
|
|
59
85
|
group: "inline",
|
|
60
86
|
inline: !0,
|
|
@@ -67,16 +93,35 @@ var y = new u("ensureTextAfterMath"), b = (e = []) => e.map((e) => ({
|
|
|
67
93
|
};
|
|
68
94
|
},
|
|
69
95
|
addProseMirrorPlugins() {
|
|
70
|
-
return [
|
|
96
|
+
return [N(this.name), F];
|
|
71
97
|
},
|
|
72
98
|
parseHTML() {
|
|
73
|
-
return [
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
99
|
+
return [
|
|
100
|
+
{
|
|
101
|
+
tag: "span[data-latex]",
|
|
102
|
+
getAttrs: (e) => ({ latex: _(e.getAttribute("data-raw") || e.textContent).unwrapped })
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
tag: "span[data-type=\"mathml\"]",
|
|
106
|
+
priority: 60,
|
|
107
|
+
getAttrs: (e) => {
|
|
108
|
+
let t = e.querySelector("math");
|
|
109
|
+
return k(t?.outerHTML || e.innerHTML, this.options, t);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
tag: "math",
|
|
114
|
+
getAttrs: (e) => k(e.outerHTML, this.options, e)
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
tag: "span[data-type=\"mathml\"]",
|
|
118
|
+
getAttrs: (e) => ({ html: e.innerHTML })
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
tag: "math",
|
|
122
|
+
getAttrs: (e) => ({ html: e.outerHTML })
|
|
123
|
+
}
|
|
124
|
+
];
|
|
80
125
|
},
|
|
81
126
|
addCommands() {
|
|
82
127
|
return { insertMath: (e = "") => ({ tr: n, editor: r, dispatch: i }) => {
|
|
@@ -89,32 +134,34 @@ var y = new u("ensureTextAfterMath"), b = (e = []) => e.map((e) => ({
|
|
|
89
134
|
} };
|
|
90
135
|
},
|
|
91
136
|
renderHTML({ HTMLAttributes: e }) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
137
|
+
if (e.html) return A(e.html);
|
|
138
|
+
if (this.options.mathMlOptions?.mmlOutput) {
|
|
139
|
+
let t = O(e.latex, e.wrapper);
|
|
140
|
+
if (t) return A(t);
|
|
141
|
+
}
|
|
142
|
+
return [
|
|
96
143
|
"span",
|
|
97
144
|
{
|
|
98
145
|
"data-latex": "",
|
|
99
146
|
"data-raw": e.latex
|
|
100
147
|
},
|
|
101
|
-
|
|
148
|
+
v(e.latex, e.wrapper)
|
|
102
149
|
];
|
|
103
150
|
},
|
|
104
151
|
addNodeView() {
|
|
105
|
-
return o((e) => /* @__PURE__ */ p(
|
|
152
|
+
return o((e) => /* @__PURE__ */ p(L, {
|
|
106
153
|
...e,
|
|
107
154
|
options: this.options
|
|
108
155
|
}));
|
|
109
156
|
}
|
|
110
|
-
}),
|
|
111
|
-
let { node: s, updateAttributes: c, editor: l, selected: u, options: h, getPos: g } = o, [
|
|
157
|
+
}), L = (o) => {
|
|
158
|
+
let { node: s, updateAttributes: c, editor: l, selected: u, options: h, getPos: g } = o, [_, v] = i(u), x = r(null), S = r(null), C = r(Date.now()), [w, T] = i({
|
|
112
159
|
top: 0,
|
|
113
160
|
left: 0
|
|
114
|
-
}), { math:
|
|
161
|
+
}), { math: E = {} } = h || {}, { keypadMode: D, controlledKeypadMode: O = !0, customKeys: k = [], keyPadCharacterRef: A, setKeypadInteraction: j } = E, N = s.attrs.latex || "", P = (e) => {
|
|
115
162
|
c({ latex: e });
|
|
116
163
|
}, F = (e, { moveCursorAfterNode: t = !0 } = {}) => {
|
|
117
|
-
if (c({ latex: e }),
|
|
164
|
+
if (c({ latex: e }), v(!1), t && typeof g == "function") {
|
|
118
165
|
let e = g(), { doc: t } = l.state, n = d.create(t, e + s.nodeSize), r = l.state.tr.setSelection(n);
|
|
119
166
|
l.view.dispatch(r);
|
|
120
167
|
}
|
|
@@ -123,27 +170,27 @@ var y = new u("ensureTextAfterMath"), b = (e = []) => e.map((e) => ({
|
|
|
123
170
|
return n(() => {
|
|
124
171
|
if (!u) return;
|
|
125
172
|
let { selection: e } = l.state;
|
|
126
|
-
e.node?.type?.name === "math" &&
|
|
173
|
+
e.node?.type?.name === "math" && v(!0);
|
|
127
174
|
}, [u, l]), n(() => {
|
|
128
|
-
t(l, u ||
|
|
175
|
+
t(l, u || _);
|
|
129
176
|
}, [
|
|
130
177
|
l,
|
|
131
|
-
|
|
178
|
+
_,
|
|
132
179
|
u
|
|
133
180
|
]), n(() => {
|
|
134
|
-
if (!l || !
|
|
135
|
-
|
|
181
|
+
if (!l || !_) {
|
|
182
|
+
T({
|
|
136
183
|
top: 0,
|
|
137
184
|
left: 0
|
|
138
185
|
});
|
|
139
186
|
return;
|
|
140
187
|
}
|
|
141
188
|
let e = () => {
|
|
142
|
-
if (!
|
|
143
|
-
let { from: e } = l.state.selection, t = l.view.coordsAtPos(e), n =
|
|
189
|
+
if (!x.current) return;
|
|
190
|
+
let { from: e } = l.state.selection, t = l.view.coordsAtPos(e), n = S.current?.getBoundingClientRect?.(), r = n?.height ? n.top : t.top, i = n?.width ? n.left : t.left, a = n?.height ? n.bottom : t.bottom ?? t.top, o = x.current.offsetHeight, s = x.current.offsetWidth, c = window.innerHeight - (a + 0) >= o ? a + 0 : r - o - 0, u = i;
|
|
144
191
|
c = Math.max(8, Math.min(c, window.innerHeight - o - 8)), u = Math.max(8, Math.min(u, window.innerWidth - s - 8));
|
|
145
192
|
let d = (l._tiptapContainerEl || document.body).getBoundingClientRect();
|
|
146
|
-
|
|
193
|
+
T({
|
|
147
194
|
top: c - d.top,
|
|
148
195
|
left: u - d.left
|
|
149
196
|
});
|
|
@@ -159,23 +206,32 @@ var y = new u("ensureTextAfterMath"), b = (e = []) => e.map((e) => ({
|
|
|
159
206
|
}), window.addEventListener("scroll", n, !0), window.addEventListener("resize", n), () => {
|
|
160
207
|
t !== null && cancelAnimationFrame(t), window.removeEventListener("scroll", n, !0), window.removeEventListener("resize", n);
|
|
161
208
|
};
|
|
162
|
-
}, [l,
|
|
209
|
+
}, [l, _]), n(() => {
|
|
163
210
|
let e = performance.now(), t = (t) => {
|
|
164
211
|
if (t?.timeStamp < e) return;
|
|
165
|
-
let n = t?.target, r = (document.querySelectorAll?.("[id^=\"equation-editor-select\"][id*=\"listbox\"], [aria-labelledby=\"equation-editor-label\"][role=\"listbox\"]") || []).length > 0, i = !!(n?.id && n.id.includes("equation-editor-select")) || !!n?.closest?.("[id*=\"equation-editor-select\"]"), a = !!n?.closest?.(`.math-node-${
|
|
166
|
-
if (
|
|
167
|
-
|
|
212
|
+
let n = t?.target, r = (document.querySelectorAll?.("[id^=\"equation-editor-select\"][id*=\"listbox\"], [aria-labelledby=\"equation-editor-label\"][role=\"listbox\"]") || []).length > 0, i = !!(n?.id && n.id.includes("equation-editor-select")) || !!n?.closest?.("[id*=\"equation-editor-select\"]"), a = !!n?.closest?.(`.math-node-${C.current}`);
|
|
213
|
+
if (x.current && !x.current.contains(n) && !n?.closest?.("[data-inline-node]") && !r && !i && !a) {
|
|
214
|
+
v(!1);
|
|
168
215
|
let e = !!l?.view?.dom?.contains(n);
|
|
169
216
|
F(s.attrs.latex, { moveCursorAfterNode: !e });
|
|
170
217
|
}
|
|
171
218
|
};
|
|
172
|
-
return
|
|
219
|
+
return _ ? document.addEventListener("click", t) : document.removeEventListener("click", t), () => document.removeEventListener("click", t);
|
|
173
220
|
}, [
|
|
174
221
|
l,
|
|
175
|
-
|
|
222
|
+
_,
|
|
176
223
|
s
|
|
177
|
-
]), /* @__PURE__ */
|
|
178
|
-
|
|
224
|
+
]), s.attrs.html && !N ? /* @__PURE__ */ p(a, {
|
|
225
|
+
as: "span",
|
|
226
|
+
"data-type": "mathml",
|
|
227
|
+
style: {
|
|
228
|
+
display: "inline-block",
|
|
229
|
+
margin: "0 4px"
|
|
230
|
+
},
|
|
231
|
+
contentEditable: !1,
|
|
232
|
+
dangerouslySetInnerHTML: { __html: s.attrs.html }
|
|
233
|
+
}) : /* @__PURE__ */ m(a, {
|
|
234
|
+
className: `math-node-${C.current}`,
|
|
179
235
|
style: {
|
|
180
236
|
display: "inline-flex",
|
|
181
237
|
cursor: "pointer",
|
|
@@ -183,34 +239,34 @@ var y = new u("ensureTextAfterMath"), b = (e = []) => e.map((e) => ({
|
|
|
183
239
|
},
|
|
184
240
|
"data-selected": u,
|
|
185
241
|
children: [/* @__PURE__ */ p("div", {
|
|
186
|
-
ref: C,
|
|
187
|
-
onClick: () => x(!0),
|
|
188
|
-
contentEditable: !1,
|
|
189
|
-
children: /* @__PURE__ */ p(_, { latex: N })
|
|
190
|
-
}), y && f.createPortal(/* @__PURE__ */ p("div", {
|
|
191
242
|
ref: S,
|
|
243
|
+
onClick: () => v(!0),
|
|
244
|
+
contentEditable: !1,
|
|
245
|
+
children: /* @__PURE__ */ p(y, { latex: N })
|
|
246
|
+
}), _ && f.createPortal(/* @__PURE__ */ p("div", {
|
|
247
|
+
ref: x,
|
|
192
248
|
"data-toolbar-for": l.instanceId,
|
|
193
249
|
style: {
|
|
194
250
|
position: "absolute",
|
|
195
|
-
top: `${
|
|
196
|
-
left: `${
|
|
251
|
+
top: `${w.top}px`,
|
|
252
|
+
left: `${w.left}px`,
|
|
197
253
|
zIndex: 1e3,
|
|
198
254
|
background: e,
|
|
199
255
|
boxShadow: "0px 1px 5px 0px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)"
|
|
200
256
|
},
|
|
201
|
-
children: /* @__PURE__ */ p(
|
|
257
|
+
children: /* @__PURE__ */ p(b, {
|
|
202
258
|
latex: N,
|
|
203
259
|
autoFocus: !0,
|
|
204
260
|
onChange: P,
|
|
205
261
|
onDone: F,
|
|
206
|
-
keypadMode:
|
|
207
|
-
controlledKeypadMode:
|
|
208
|
-
additionalKeys:
|
|
209
|
-
keyPadCharacterRef:
|
|
210
|
-
setKeypadInteraction:
|
|
262
|
+
keypadMode: D,
|
|
263
|
+
controlledKeypadMode: O,
|
|
264
|
+
additionalKeys: M(k),
|
|
265
|
+
keyPadCharacterRef: A,
|
|
266
|
+
setKeypadInteraction: j
|
|
211
267
|
})
|
|
212
268
|
}), l?._tiptapContainerEl || document.body)]
|
|
213
269
|
});
|
|
214
270
|
};
|
|
215
271
|
//#endregion
|
|
216
|
-
export {
|
|
272
|
+
export { N as EnsureTextAfterMathPlugin, I as MathNode, L as MathNodeView, F as ZeroWidthSpaceHandlingPlugin, O as convertLatexToMathMl, D as convertMathMlToLatex };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/editable-html-tip-tap",
|
|
3
|
-
"version": "3.1.2-next.
|
|
3
|
+
"version": "3.1.2-next.20261021000713",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"@dnd-kit/utilities": "3.2.2",
|
|
14
14
|
"@mui/icons-material": "^7.3.4",
|
|
15
15
|
"@mui/material": "^7.3.4",
|
|
16
|
-
"@pie-lib/drag": "5.0.7-next.
|
|
17
|
-
"@pie-lib/math-input": "9.0.7-next.
|
|
18
|
-
"@pie-lib/math-toolbar": "4.0.7-next.
|
|
19
|
-
"@pie-lib/render-ui": "8.0.7-next.
|
|
16
|
+
"@pie-lib/drag": "5.0.7-next.20261021000713",
|
|
17
|
+
"@pie-lib/math-input": "9.0.7-next.20261021000713",
|
|
18
|
+
"@pie-lib/math-toolbar": "4.0.7-next.20261021000713",
|
|
19
|
+
"@pie-lib/render-ui": "8.0.7-next.20261021000713",
|
|
20
20
|
"@pie-lib/translator": "5.0.2-next.20261019155156",
|
|
21
21
|
"@tiptap/core": "3.32.0",
|
|
22
22
|
"@tiptap/extension-character-count": "3.32.0",
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"react-portal": "^4.2.0",
|
|
44
44
|
"tippy.js": "latest",
|
|
45
45
|
"to-style": "^1.3.3",
|
|
46
|
-
"@pie-element/shared-lodash": "0.1.3-next.
|
|
46
|
+
"@pie-element/shared-lodash": "0.1.3-next.20261020155912",
|
|
47
47
|
"clsx": "^2.1.1",
|
|
48
48
|
"prosemirror-state": "^1.4.4",
|
|
49
|
-
"@pie-element/shared-math-rendering-mathjax": "0.1.8-next.
|
|
49
|
+
"@pie-element/shared-math-rendering-mathjax": "0.1.8-next.20261021000713",
|
|
50
50
|
"@tiptap/extensions": "3.32.0",
|
|
51
51
|
"@tiptap/extension-list": "3.32.0",
|
|
52
52
|
"@tiptap/extension-bubble-menu": "3.32.0",
|