@pie-lib/editable-html-tip-tap 3.1.2-next.20261022130755 → 3.1.2-next.20261022203410

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.
@@ -3,7 +3,7 @@ import t from "debug";
3
3
  //#region src/components/image/InsertImageHandler.ts
4
4
  var n = t("@pie-lib:editable-html:image:insert-image-handler"), r = class {
5
5
  constructor(e, t, n, r = !1) {
6
- this.editor = e, this.nodeInfo = t, this.node = t[0], this.nodePos = t[1], this.onFinish = n, this.isPasted = r, this.chosenFile = null, this.nodeKey = this.node?.attrs?.nodeKey || null;
6
+ this.editor = e, this.nodeInfo = t, this.node = t[0], this.nodePos = t[1], this.onFinish = n, this.isPasted = r, this.chosenFile = null, this.settled = !1, this.nodeKey = this.node?.attrs?.nodeKey || null;
7
7
  }
8
8
  resolveNodePos() {
9
9
  let t = e(this.editor, this.nodeKey);
@@ -39,7 +39,7 @@ var n = t("@pie-lib:editable-html:image:insert-image-handler"), r = class {
39
39
  n.dispatch(a);
40
40
  }
41
41
  done(e, t) {
42
- n("done: err:", e), e ? (console.log(e), this.onFinish(!1)) : (this.updateNode({
42
+ n("done: err:", e), this.settled = !0, e ? (console.log(e), this.onFinish(!1)) : (this.updateNode({
43
43
  loaded: !0,
44
44
  src: t,
45
45
  percent: 100
@@ -51,7 +51,7 @@ var n = t("@pie-lib:editable-html:image:insert-image-handler"), r = class {
51
51
  let t = new FileReader();
52
52
  t.onload = () => {
53
53
  let e = t.result;
54
- this.updateNode({ src: e });
54
+ this.settled || this.updateNode({ src: e });
55
55
  }, t.readAsDataURL(e);
56
56
  }
57
57
  progress(e, t, r) {
@@ -57,9 +57,7 @@ var y = f(v, { shouldForwardProp: (e) => e !== "hideProgress" })(({ hideProgress
57
57
  };
58
58
  };
59
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, [
60
+ let { node: m, editor: _, attributes: v, onFocus: O, getPos: k, selected: A, options: j } = f, 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
61
  F,
64
62
  I,
65
63
  m.nodeSize
@@ -40,7 +40,7 @@ var f = a.create({
40
40
  },
41
41
  loaded: {
42
42
  default: !1,
43
- parseHTML: (e) => e.hasAttribute("loaded") ? e.getAttribute("loaded") !== "false" : !/^data:/i.test(e.getAttribute("src") ?? "")
43
+ parseHTML: () => !0
44
44
  },
45
45
  deleteStatus: { default: null },
46
46
  alignment: { default: null },
@@ -2,9 +2,12 @@ import React from 'react';
2
2
  import { Node } from '@tiptap/core';
3
3
  import { Plugin } from 'prosemirror-state';
4
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.
5
+ * LaTeX for a MathML string, or null when there is none to give. A converter the page installed,
6
+ * such as the legacy renderer's, answers first; `mmlToLatex` gives the input back when there is
7
+ * none, and then this converts, so the ESM page, which installs only `renderMath`, converts too.
8
+ * The converter belongs here, not in the math adapter: only authoring needs it, and every
9
+ * element's delivery bundle carries the adapter. It answers an empty string for MathML it cannot
10
+ * read and throws on some; neither is LaTeX, and neither may become a math node.
8
11
  */
9
12
  export declare const convertMathMlToLatex: (mathMl: any) => string | null;
10
13
  /**
@@ -13,6 +16,11 @@ export declare const convertMathMlToLatex: (mathMl: any) => string | null;
13
16
  * editing it again reads that back exactly, where converting the MathML would lose some.
14
17
  */
15
18
  export declare const convertLatexToMathMl: (latex: any, wrapper: any) => string | null;
19
+ /**
20
+ * MathML that is safe to put in the live page: only MathML presentation elements, with no event
21
+ * handlers and no script URLs. `mathMlSpan` parses in an inert document, but markup shown in the page runs.
22
+ */
23
+ export declare const sanitizeMathMl: (html: any) => string;
16
24
  export declare const EnsureTextAfterMathPlugin: (mathNodeName: any) => Plugin<any>;
17
25
  export declare const ZeroWidthSpaceHandlingPlugin: Plugin<any>;
18
26
  export declare const MathNode: Node<any, any>;
@@ -7,41 +7,56 @@ import { NodeSelection as c, Plugin as l, PluginKey as u, TextSelection as d } f
7
7
  import f from "react-dom";
8
8
  import { jsx as p, jsxs as m } from "react/jsx-runtime";
9
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";
10
+ import { MathMLToLaTeX as y } from "@pie-framework/mathml-to-latex";
11
+ import { MathPreview as b, MathToolbar as x } from "@pie-lib/math-toolbar";
11
12
  //#region src/extensions/math.tsx
12
- var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
13
+ var S = /\\left\.\s*|\\right\.\s*/g, C = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, w = {
13
14
  open: "\\[",
14
15
  close: "\\]"
15
- }, w = "data-pie-latex", T = (e) => e.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;"), E = (e) => typeof e == "string" ? e === "double_dollar" : ["$$", "\\["].includes(e?.open), D = (e) => {
16
+ }, T = "data-pie-latex", E = (e) => e.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;"), D = (e) => typeof e == "string" ? e === "double_dollar" : ["$$", "\\["].includes(e?.open), O = (e) => {
16
17
  let t = e.replaceAll("&nbsp;", " "), 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) => {
18
+ if (n === t) try {
19
+ n = y.convert(t);
20
+ } catch {
21
+ return null;
22
+ }
23
+ return !n || n === t ? null : n.replace(S, "") || null;
24
+ }, k = (e, t) => {
25
+ let n = h(e, { display: D(t) });
26
+ return !n || !n.startsWith("<math") ? null : n.replace(C, "").replace("<math", () => `<math ${T}="${E(e)}"`);
27
+ }, A = (e, t, n) => {
22
28
  if (!t?.mathMlOptions?.mmlEditing) return !1;
23
- let r = n?.getAttribute("display") === "block" ? C : null, i = (n?.getAttribute(w) ?? n?.getAttribute("data-latex"))?.trim();
29
+ let r = n?.getAttribute("display") === "block" ? w : null, i = (n?.getAttribute(T) ?? n?.getAttribute("data-latex"))?.trim();
24
30
  if (i) return {
25
31
  latex: i,
26
32
  wrapper: r
27
33
  };
28
- let a = D(e);
34
+ let a = O(e);
29
35
  if (a === null) return !1;
30
36
  let { unwrapped: o, wrapper: s } = _(a);
31
37
  return {
32
38
  latex: o,
33
39
  wrapper: s || r
34
40
  };
35
- }, A = (e) => {
41
+ }, j = (e) => {
36
42
  let t = document.implementation.createHTMLDocument("").createElement("span");
37
43
  return t.setAttribute("data-type", "mathml"), t.innerHTML = e, t;
38
- }, j = new u("ensureTextAfterMath"), M = (e = []) => e.map((e) => ({
44
+ }, M = new Set("math maction maligngroup malignmark menclose merror mfenced mfrac mglyph mi mlabeledtr mlongdiv mmultiscripts mn mo mover mpadded mphantom mprescripts mroot mrow ms mscarries mscarry msgroup msline mspace msqrt msrow mstack mstyle msub msubsup msup mtable mtd mtext mtr munder munderover semantics".split(" ")), N = (e) => {
45
+ let t = j(e), n = (e) => {
46
+ for (let t of Array.from(e.children)) if (!M.has(t.localName)) t.remove();
47
+ else {
48
+ for (let { name: e, value: n } of Array.from(t.attributes)) (/^on/i.test(e) || /^\s*javascript:/i.test(n)) && t.removeAttribute(e);
49
+ n(t);
50
+ }
51
+ };
52
+ return n(t), t.innerHTML;
53
+ }, P = new u("ensureTextAfterMath"), F = (e = []) => e.map((e) => ({
39
54
  name: e,
40
55
  latex: e,
41
56
  write: e,
42
57
  label: e
43
- })), N = (e) => new l({
44
- key: j,
58
+ })), I = (e) => new l({
59
+ key: P,
45
60
  appendTransaction: (t, n, r) => {
46
61
  if (!t.some((e) => e.docChanged)) return null;
47
62
  let i = r.tr, a = !1;
@@ -52,7 +67,7 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
52
67
  }
53
68
  }), a ? i : null;
54
69
  }
55
- }), P = (e, t) => {
70
+ }), L = (e, t) => {
56
71
  let n;
57
72
  for (n = t; n > 0; n--) {
58
73
  let t = e.nodeAt(n);
@@ -60,16 +75,16 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
60
75
  if (t && t?.type?.name !== "text") break;
61
76
  }
62
77
  return n;
63
- }, F = new l({
78
+ }, R = new l({
64
79
  key: new u("zeroWidthSpaceHandling"),
65
80
  props: { handleKeyDown(e, t) {
66
81
  let { state: n, dispatch: r } = e, { selection: i, doc: a } = n, { from: o, empty: s } = i;
67
82
  if (s && t.key === "Backspace" && o > 0) {
68
- let e = P(a, o);
83
+ let e = L(a, o);
69
84
  return e !== -1 && (r(n.tr.delete(e, o)), !0);
70
85
  }
71
86
  if (s && t.key === "ArrowLeft" && o > 0) {
72
- let e = P(a, o);
87
+ let e = L(a, o);
73
88
  if (e === -1) return !1;
74
89
  let t = n.doc.resolve(e);
75
90
  if (t.nodeAfter || t.nodeBefore) {
@@ -80,7 +95,7 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
80
95
  }
81
96
  return !1;
82
97
  } }
83
- }), I = s.create({
98
+ }), z = s.create({
84
99
  name: "math",
85
100
  group: "inline",
86
101
  inline: !0,
@@ -93,7 +108,7 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
93
108
  };
94
109
  },
95
110
  addProseMirrorPlugins() {
96
- return [N(this.name), F];
111
+ return [I(this.name), R];
97
112
  },
98
113
  parseHTML() {
99
114
  return [
@@ -106,12 +121,12 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
106
121
  priority: 60,
107
122
  getAttrs: (e) => {
108
123
  let t = e.querySelector("math");
109
- return k(t?.outerHTML || e.innerHTML, this.options, t);
124
+ return A(t?.outerHTML || e.innerHTML, this.options, t);
110
125
  }
111
126
  },
112
127
  {
113
128
  tag: "math",
114
- getAttrs: (e) => k(e.outerHTML, this.options, e)
129
+ getAttrs: (e) => A(e.outerHTML, this.options, e)
115
130
  },
116
131
  {
117
132
  tag: "span[data-type=\"mathml\"]",
@@ -134,10 +149,10 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
134
149
  } };
135
150
  },
136
151
  renderHTML({ HTMLAttributes: e }) {
137
- if (e.html) return A(e.html);
152
+ if (e.html) return j(e.html);
138
153
  if (this.options.mathMlOptions?.mmlOutput) {
139
- let t = O(e.latex, e.wrapper);
140
- if (t) return A(t);
154
+ let t = k(e.latex, e.wrapper);
155
+ if (t) return j(t);
141
156
  }
142
157
  return [
143
158
  "span",
@@ -149,18 +164,18 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
149
164
  ];
150
165
  },
151
166
  addNodeView() {
152
- return o((e) => /* @__PURE__ */ p(L, {
167
+ return o((e) => /* @__PURE__ */ p(B, {
153
168
  ...e,
154
169
  options: this.options
155
170
  }));
156
171
  }
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({
172
+ }), B = (o) => {
173
+ let { node: s, updateAttributes: c, editor: l, selected: u, options: h, getPos: g } = o, [_, v] = i(u), y = r(null), S = r(null), C = r(Date.now()), [w, T] = i({
159
174
  top: 0,
160
175
  left: 0
161
- }), { math: E = {} } = h || {}, { keypadMode: D, controlledKeypadMode: O = !0, customKeys: k = [], keyPadCharacterRef: A, setKeypadInteraction: j } = E, N = s.attrs.latex || "", P = (e) => {
176
+ }), { math: E = {} } = h || {}, { keypadMode: D, controlledKeypadMode: O = !0, customKeys: k = [], keyPadCharacterRef: A, setKeypadInteraction: j } = E, M = s.attrs.latex || "", P = (e) => {
162
177
  c({ latex: e });
163
- }, F = (e, { moveCursorAfterNode: t = !0 } = {}) => {
178
+ }, I = (e, { moveCursorAfterNode: t = !0 } = {}) => {
164
179
  if (c({ latex: e }), v(!1), t && typeof g == "function") {
165
180
  let e = g(), { doc: t } = l.state, n = d.create(t, e + s.nodeSize), r = l.state.tr.setSelection(n);
166
181
  l.view.dispatch(r);
@@ -186,8 +201,8 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
186
201
  return;
187
202
  }
188
203
  let e = () => {
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;
204
+ if (!y.current) return;
205
+ 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 = y.current.offsetHeight, s = y.current.offsetWidth, c = window.innerHeight - (a + 0) >= o ? a + 0 : r - o - 0, u = i;
191
206
  c = Math.max(8, Math.min(c, window.innerHeight - o - 8)), u = Math.max(8, Math.min(u, window.innerWidth - s - 8));
192
207
  let d = (l._tiptapContainerEl || document.body).getBoundingClientRect();
193
208
  T({
@@ -210,10 +225,10 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
210
225
  let e = performance.now(), t = (t) => {
211
226
  if (t?.timeStamp < e) return;
212
227
  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) {
228
+ if (y.current && !y.current.contains(n) && !n?.closest?.("[data-inline-node]") && !r && !i && !a) {
214
229
  v(!1);
215
230
  let e = !!l?.view?.dom?.contains(n);
216
- F(s.attrs.latex, { moveCursorAfterNode: !e });
231
+ I(s.attrs.latex, { moveCursorAfterNode: !e });
217
232
  }
218
233
  };
219
234
  return _ ? document.addEventListener("click", t) : document.removeEventListener("click", t), () => document.removeEventListener("click", t);
@@ -221,7 +236,7 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
221
236
  l,
222
237
  _,
223
238
  s
224
- ]), s.attrs.html && !N ? /* @__PURE__ */ p(a, {
239
+ ]), s.attrs.html && !M ? /* @__PURE__ */ p(a, {
225
240
  as: "span",
226
241
  "data-type": "mathml",
227
242
  style: {
@@ -229,7 +244,7 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
229
244
  margin: "0 4px"
230
245
  },
231
246
  contentEditable: !1,
232
- dangerouslySetInnerHTML: { __html: s.attrs.html }
247
+ dangerouslySetInnerHTML: { __html: N(s.attrs.html) }
233
248
  }) : /* @__PURE__ */ m(a, {
234
249
  className: `math-node-${C.current}`,
235
250
  style: {
@@ -242,9 +257,9 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
242
257
  ref: S,
243
258
  onClick: () => v(!0),
244
259
  contentEditable: !1,
245
- children: /* @__PURE__ */ p(y, { latex: N })
260
+ children: /* @__PURE__ */ p(b, { latex: M })
246
261
  }), _ && f.createPortal(/* @__PURE__ */ p("div", {
247
- ref: x,
262
+ ref: y,
248
263
  "data-toolbar-for": l.instanceId,
249
264
  style: {
250
265
  position: "absolute",
@@ -254,14 +269,14 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
254
269
  background: e,
255
270
  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)"
256
271
  },
257
- children: /* @__PURE__ */ p(b, {
258
- latex: N,
272
+ children: /* @__PURE__ */ p(x, {
273
+ latex: M,
259
274
  autoFocus: !0,
260
275
  onChange: P,
261
- onDone: F,
276
+ onDone: I,
262
277
  keypadMode: D,
263
278
  controlledKeypadMode: O,
264
- additionalKeys: M(k),
279
+ additionalKeys: F(k),
265
280
  keyPadCharacterRef: A,
266
281
  setKeypadInteraction: j
267
282
  })
@@ -269,4 +284,4 @@ var x = /\\left\.\s*|\\right\.\s*/g, S = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, C = {
269
284
  });
270
285
  };
271
286
  //#endregion
272
- export { N as EnsureTextAfterMathPlugin, I as MathNode, L as MathNodeView, F as ZeroWidthSpaceHandlingPlugin, O as convertLatexToMathMl, D as convertMathMlToLatex };
287
+ export { I as EnsureTextAfterMathPlugin, z as MathNode, B as MathNodeView, R as ZeroWidthSpaceHandlingPlugin, k as convertLatexToMathMl, O as convertMathMlToLatex, N as sanitizeMathMl };
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.20261022130755",
3
+ "version": "3.1.2-next.20261022203410",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,15 +13,15 @@
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.20261022130755",
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",
16
+ "@pie-framework/mathml-to-latex": "1.4.4",
17
+ "@pie-lib/drag": "5.0.7-next.20261022203410",
18
+ "@pie-lib/math-input": "9.0.7-next.20261022203410",
19
+ "@pie-lib/math-toolbar": "4.0.7-next.20261022203410",
20
+ "@pie-lib/render-ui": "8.0.7-next.20261022203410",
20
21
  "@pie-lib/translator": "5.0.2-next.20261019155156",
21
22
  "@tiptap/core": "3.32.0",
22
23
  "@tiptap/extension-character-count": "3.32.0",
23
24
  "@tiptap/extension-color": "3.32.0",
24
- "@tiptap/extension-image": "3.32.0",
25
25
  "@tiptap/extension-list-item": "3.32.0",
26
26
  "@tiptap/extension-placeholder": "3.32.0",
27
27
  "@tiptap/extension-subscript": "3.32.0",
@@ -46,7 +46,7 @@
46
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.20261021000713",
49
+ "@pie-element/shared-math-rendering-mathjax": "0.1.8-next.20261022133444",
50
50
  "@tiptap/extensions": "3.32.0",
51
51
  "@tiptap/extension-list": "3.32.0",
52
52
  "@tiptap/extension-bubble-menu": "3.32.0",