@pie-lib/editable-html-tip-tap 3.0.0-next.49 → 3.0.0
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/extensions/math.js
CHANGED
|
@@ -5,16 +5,16 @@ import { Node as o } from "@tiptap/core";
|
|
|
5
5
|
import { NodeSelection as s, Plugin as c, PluginKey as l, TextSelection as u } from "prosemirror-state";
|
|
6
6
|
import d from "react-dom";
|
|
7
7
|
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
8
|
-
import {
|
|
9
|
-
import { MathPreview as
|
|
8
|
+
import { unWrapMath as m, wrapMath as h } from "@pie-element/shared-math-rendering-mathjax";
|
|
9
|
+
import { MathPreview as g, MathToolbar as _ } from "@pie-lib/math-toolbar";
|
|
10
10
|
//#region src/extensions/math.tsx
|
|
11
|
-
var
|
|
11
|
+
var v = new l("ensureTextAfterMath"), y = (e = []) => e.map((e) => ({
|
|
12
12
|
name: e,
|
|
13
13
|
latex: e,
|
|
14
14
|
write: e,
|
|
15
15
|
label: e
|
|
16
|
-
})),
|
|
17
|
-
key:
|
|
16
|
+
})), b = (e) => new c({
|
|
17
|
+
key: v,
|
|
18
18
|
appendTransaction: (t, n, r) => {
|
|
19
19
|
if (!t.some((e) => e.docChanged)) return null;
|
|
20
20
|
let i = r.tr, a = !1;
|
|
@@ -25,7 +25,7 @@ var _ = new l("ensureTextAfterMath"), v = (e = []) => e.map((e) => ({
|
|
|
25
25
|
}
|
|
26
26
|
}), a ? i : null;
|
|
27
27
|
}
|
|
28
|
-
}),
|
|
28
|
+
}), x = (e, t) => {
|
|
29
29
|
let n;
|
|
30
30
|
for (n = t; n > 0; n--) {
|
|
31
31
|
let t = e.nodeAt(n);
|
|
@@ -33,16 +33,16 @@ var _ = new l("ensureTextAfterMath"), v = (e = []) => e.map((e) => ({
|
|
|
33
33
|
if (t && t?.type?.name !== "text") break;
|
|
34
34
|
}
|
|
35
35
|
return n;
|
|
36
|
-
},
|
|
36
|
+
}, S = new c({
|
|
37
37
|
key: new l("zeroWidthSpaceHandling"),
|
|
38
38
|
props: { handleKeyDown(e, t) {
|
|
39
39
|
let { state: n, dispatch: r } = e, { selection: i, doc: a } = n, { from: o, empty: c } = i;
|
|
40
40
|
if (c && t.key === "Backspace" && o > 0) {
|
|
41
|
-
let e =
|
|
41
|
+
let e = x(a, o);
|
|
42
42
|
return e === -1 ? !1 : (r(n.tr.delete(e, o)), !0);
|
|
43
43
|
}
|
|
44
44
|
if (c && t.key === "ArrowLeft" && o > 0) {
|
|
45
|
-
let e =
|
|
45
|
+
let e = x(a, o);
|
|
46
46
|
if (e === -1) return !1;
|
|
47
47
|
let t = n.doc.resolve(e);
|
|
48
48
|
if (t.nodeAfter || t.nodeBefore) {
|
|
@@ -52,7 +52,7 @@ var _ = new l("ensureTextAfterMath"), v = (e = []) => e.map((e) => ({
|
|
|
52
52
|
}
|
|
53
53
|
return !1;
|
|
54
54
|
} }
|
|
55
|
-
}),
|
|
55
|
+
}), C = o.create({
|
|
56
56
|
name: "math",
|
|
57
57
|
group: "inline",
|
|
58
58
|
inline: !0,
|
|
@@ -65,12 +65,12 @@ var _ = new l("ensureTextAfterMath"), v = (e = []) => e.map((e) => ({
|
|
|
65
65
|
};
|
|
66
66
|
},
|
|
67
67
|
addProseMirrorPlugins() {
|
|
68
|
-
return [
|
|
68
|
+
return [b(this.name), S];
|
|
69
69
|
},
|
|
70
70
|
parseHTML() {
|
|
71
71
|
return [{
|
|
72
72
|
tag: "span[data-latex]",
|
|
73
|
-
getAttrs: (e) => ({ latex: e.getAttribute("data-raw") || e.textContent })
|
|
73
|
+
getAttrs: (e) => ({ latex: m(e.getAttribute("data-raw") || e.textContent).unwrapped })
|
|
74
74
|
}, {
|
|
75
75
|
tag: "span[data-type=\"mathml\"]",
|
|
76
76
|
getAttrs: (e) => ({ html: e.innerHTML })
|
|
@@ -96,24 +96,24 @@ var _ = new l("ensureTextAfterMath"), v = (e = []) => e.map((e) => ({
|
|
|
96
96
|
"data-latex": "",
|
|
97
97
|
"data-raw": e.latex
|
|
98
98
|
},
|
|
99
|
-
|
|
99
|
+
h(e.latex, e.wrapper)
|
|
100
100
|
];
|
|
101
101
|
},
|
|
102
102
|
addNodeView() {
|
|
103
|
-
return a((e) => /* @__PURE__ */ f(
|
|
103
|
+
return a((e) => /* @__PURE__ */ f(w, {
|
|
104
104
|
...e,
|
|
105
105
|
options: this.options
|
|
106
106
|
}));
|
|
107
107
|
}
|
|
108
|
-
}),
|
|
109
|
-
let { node: o, updateAttributes: s, editor: c, selected: l, options: m, getPos:
|
|
108
|
+
}), w = (a) => {
|
|
109
|
+
let { node: o, updateAttributes: s, editor: c, selected: l, options: m, getPos: h } = a, [v, b] = r(l), x = n(null), S = n(null), C = n(Date.now()), [w, T] = r({
|
|
110
110
|
top: 0,
|
|
111
111
|
left: 0
|
|
112
112
|
}), { math: E = {} } = m || {}, { keypadMode: D, controlledKeypadMode: O = !0, customKeys: k = [], keyPadCharacterRef: A, setKeypadInteraction: j } = E, M = o.attrs.latex || "", N = (e) => {
|
|
113
113
|
s({ latex: e });
|
|
114
114
|
}, P = (e, { moveCursorAfterNode: t = !0 } = {}) => {
|
|
115
|
-
if (s({ latex: e }), b(!1), t && typeof
|
|
116
|
-
let e =
|
|
115
|
+
if (s({ latex: e }), b(!1), t && typeof h == "function") {
|
|
116
|
+
let e = h(), { doc: t } = c.state, n = u.create(t, e + o.nodeSize), r = c.state.tr.setSelection(n);
|
|
117
117
|
c.view.dispatch(r);
|
|
118
118
|
}
|
|
119
119
|
c.commands.focus();
|
|
@@ -123,13 +123,13 @@ var _ = new l("ensureTextAfterMath"), v = (e = []) => e.map((e) => ({
|
|
|
123
123
|
let { selection: e } = c.state;
|
|
124
124
|
e.node?.type?.name === "math" && b(!0);
|
|
125
125
|
}, [l, c]), t(() => {
|
|
126
|
-
e(c, l ||
|
|
126
|
+
e(c, l || v);
|
|
127
127
|
}, [
|
|
128
128
|
c,
|
|
129
|
-
|
|
129
|
+
v,
|
|
130
130
|
l
|
|
131
131
|
]), t(() => {
|
|
132
|
-
if (!c || !
|
|
132
|
+
if (!c || !v) {
|
|
133
133
|
T({
|
|
134
134
|
top: 0,
|
|
135
135
|
left: 0
|
|
@@ -157,7 +157,7 @@ var _ = new l("ensureTextAfterMath"), v = (e = []) => e.map((e) => ({
|
|
|
157
157
|
}), window.addEventListener("scroll", n, !0), window.addEventListener("resize", n), () => {
|
|
158
158
|
t !== null && cancelAnimationFrame(t), window.removeEventListener("scroll", n, !0), window.removeEventListener("resize", n);
|
|
159
159
|
};
|
|
160
|
-
}, [c,
|
|
160
|
+
}, [c, v]), t(() => {
|
|
161
161
|
let e = performance.now(), t = (t) => {
|
|
162
162
|
if (t?.timeStamp < e) return;
|
|
163
163
|
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}`);
|
|
@@ -167,10 +167,10 @@ var _ = new l("ensureTextAfterMath"), v = (e = []) => e.map((e) => ({
|
|
|
167
167
|
P(o.attrs.latex, { moveCursorAfterNode: !e });
|
|
168
168
|
}
|
|
169
169
|
};
|
|
170
|
-
return
|
|
170
|
+
return v ? document.addEventListener("click", t) : document.removeEventListener("click", t), () => document.removeEventListener("click", t);
|
|
171
171
|
}, [
|
|
172
172
|
c,
|
|
173
|
-
|
|
173
|
+
v,
|
|
174
174
|
o
|
|
175
175
|
]), /* @__PURE__ */ p(i, {
|
|
176
176
|
className: `math-node-${C.current}`,
|
|
@@ -184,8 +184,8 @@ var _ = new l("ensureTextAfterMath"), v = (e = []) => e.map((e) => ({
|
|
|
184
184
|
ref: S,
|
|
185
185
|
onClick: () => b(!0),
|
|
186
186
|
contentEditable: !1,
|
|
187
|
-
children: /* @__PURE__ */ f(
|
|
188
|
-
}),
|
|
187
|
+
children: /* @__PURE__ */ f(g, { latex: M })
|
|
188
|
+
}), v && d.createPortal(/* @__PURE__ */ f("div", {
|
|
189
189
|
ref: x,
|
|
190
190
|
"data-toolbar-for": c.instanceId,
|
|
191
191
|
style: {
|
|
@@ -196,14 +196,14 @@ var _ = new l("ensureTextAfterMath"), v = (e = []) => e.map((e) => ({
|
|
|
196
196
|
background: "var(--editable-html-toolbar-bg, #efefef)",
|
|
197
197
|
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)"
|
|
198
198
|
},
|
|
199
|
-
children: /* @__PURE__ */ f(
|
|
199
|
+
children: /* @__PURE__ */ f(_, {
|
|
200
200
|
latex: M,
|
|
201
201
|
autoFocus: !0,
|
|
202
202
|
onChange: N,
|
|
203
203
|
onDone: P,
|
|
204
204
|
keypadMode: D,
|
|
205
205
|
controlledKeypadMode: O,
|
|
206
|
-
additionalKeys:
|
|
206
|
+
additionalKeys: y(k),
|
|
207
207
|
keyPadCharacterRef: A,
|
|
208
208
|
setKeypadInteraction: j
|
|
209
209
|
})
|
|
@@ -211,4 +211,4 @@ var _ = new l("ensureTextAfterMath"), v = (e = []) => e.map((e) => ({
|
|
|
211
211
|
});
|
|
212
212
|
};
|
|
213
213
|
//#endregion
|
|
214
|
-
export {
|
|
214
|
+
export { b as EnsureTextAfterMathPlugin, C as MathNode, w as MathNodeView, S as ZeroWidthSpaceHandlingPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/editable-html-tip-tap",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
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": "
|
|
17
|
-
"@pie-lib/math-input": "9.0.0
|
|
18
|
-
"@pie-lib/math-toolbar": "4.0.0
|
|
19
|
-
"@pie-lib/render-ui": "
|
|
16
|
+
"@pie-lib/drag": "5.0.0",
|
|
17
|
+
"@pie-lib/math-input": "9.0.0",
|
|
18
|
+
"@pie-lib/math-toolbar": "4.0.0",
|
|
19
|
+
"@pie-lib/render-ui": "8.0.0",
|
|
20
20
|
"@tiptap/core": "3.31.3",
|
|
21
21
|
"@tiptap/extension-character-count": "3.31.3",
|
|
22
22
|
"@tiptap/extension-color": "3.31.3",
|
|
@@ -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.1
|
|
46
|
+
"@pie-element/shared-lodash": "0.1.1",
|
|
47
47
|
"clsx": "^2.1.1",
|
|
48
48
|
"prosemirror-state": "^1.4.4",
|
|
49
|
-
"@pie-element/shared-math-rendering-mathjax": "0.1.1
|
|
49
|
+
"@pie-element/shared-math-rendering-mathjax": "0.1.1",
|
|
50
50
|
"@tiptap/extensions": "3.31.3",
|
|
51
51
|
"@tiptap/extension-list": "3.31.3",
|
|
52
52
|
"@tiptap/extension-bubble-menu": "3.31.3",
|