@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.
@@ -1,19 +1,20 @@
1
- import { useEffect as e, useRef as t, useState as n } from "react";
2
- import { NodeViewWrapper as r, ReactNodeViewRenderer as i } from "@tiptap/react";
3
- import { Node as a } from "@tiptap/core";
4
- import { NodeSelection as o, Plugin as s, PluginKey as c, TextSelection as l } from "prosemirror-state";
5
- import u from "react-dom";
6
- import { jsx as d, jsxs as f } from "react/jsx-runtime";
7
- import { wrapMath as p } from "@pie-element/shared-math-rendering-mathjax";
8
- import { MathPreview as m, MathToolbar as h } from "@pie-lib/math-toolbar";
1
+ import { setToolbarOpened as e } from "../utils/toolbar.js";
2
+ import { useEffect as t, useRef as n, useState as r } from "react";
3
+ import { NodeViewWrapper as i, ReactNodeViewRenderer as a } from "@tiptap/react";
4
+ import { Node as o } from "@tiptap/core";
5
+ import { NodeSelection as s, Plugin as c, PluginKey as l, TextSelection as u } from "prosemirror-state";
6
+ import d from "react-dom";
7
+ import { jsx as f, jsxs as p } from "react/jsx-runtime";
8
+ import { wrapMath as m } from "@pie-element/shared-math-rendering-mathjax";
9
+ import { MathPreview as h, MathToolbar as g } from "@pie-lib/math-toolbar";
9
10
  //#region src/extensions/math.tsx
10
- var g = new c("ensureTextAfterMath"), _ = (e = []) => e.map((e) => ({
11
+ var _ = new l("ensureTextAfterMath"), v = (e = []) => e.map((e) => ({
11
12
  name: e,
12
13
  latex: e,
13
14
  write: e,
14
15
  label: e
15
- })), v = (e) => new s({
16
- key: g,
16
+ })), y = (e) => new c({
17
+ key: _,
17
18
  appendTransaction: (t, n, r) => {
18
19
  if (!t.some((e) => e.docChanged)) return null;
19
20
  let i = r.tr, a = !1;
@@ -24,21 +25,34 @@ var g = new c("ensureTextAfterMath"), _ = (e = []) => e.map((e) => ({
24
25
  }
25
26
  }), a ? i : null;
26
27
  }
27
- }), y = new s({
28
- key: new c("zeroWidthSpaceHandling"),
28
+ }), b = (e, t) => {
29
+ let n;
30
+ for (n = t; n > 0; n--) {
31
+ let t = e.nodeAt(n);
32
+ if (t?.type?.name === "text" && t.textContent !== "​") return -1;
33
+ if (t && t?.type?.name !== "text") break;
34
+ }
35
+ return n;
36
+ }, x = new c({
37
+ key: new l("zeroWidthSpaceHandling"),
29
38
  props: { handleKeyDown(e, t) {
30
- let { state: n, dispatch: r } = e, { selection: i, doc: a } = n, { from: s, empty: c } = i;
31
- if (c && t.key === "Backspace" && s > 0 && a.textBetween(s - 1, s, "", "") === "​") return r(n.tr.delete(s - 2, s)), !0;
32
- if (c && t.key === "ArrowLeft" && s > 0 && a.textBetween(s - 1, s, "", "") === "​") {
33
- let e = s - 1, t = n.doc.resolve(e - 1), i = t.nodeAfter || t.nodeBefore;
34
- if (i) {
35
- let t = e - i.nodeSize, a = n.doc.resolve(t);
36
- return r(n.tr.setSelection(o.create(n.doc, a.pos))), !0;
37
- } else return r(n.tr.setSelection(l.create(n.doc, s - 2))), !0;
39
+ let { state: n, dispatch: r } = e, { selection: i, doc: a } = n, { from: o, empty: c } = i;
40
+ if (c && t.key === "Backspace" && o > 0) {
41
+ let e = b(a, o);
42
+ return e === -1 ? !1 : (r(n.tr.delete(e, o)), !0);
43
+ }
44
+ if (c && t.key === "ArrowLeft" && o > 0) {
45
+ let e = b(a, o);
46
+ if (e === -1) return !1;
47
+ let t = n.doc.resolve(e);
48
+ if (t.nodeAfter || t.nodeBefore) {
49
+ let t = n.doc.resolve(e);
50
+ return r(n.tr.setSelection(s.create(n.doc, t.pos))), !0;
51
+ } else return r(n.tr.setSelection(u.create(n.doc, o - 2))), !0;
38
52
  }
39
53
  return !1;
40
54
  } }
41
- }), b = a.create({
55
+ }), S = o.create({
42
56
  name: "math",
43
57
  group: "inline",
44
58
  inline: !0,
@@ -51,7 +65,7 @@ var g = new c("ensureTextAfterMath"), _ = (e = []) => e.map((e) => ({
51
65
  };
52
66
  },
53
67
  addProseMirrorPlugins() {
54
- return [v(this.name), y];
68
+ return [y(this.name), x];
55
69
  },
56
70
  parseHTML() {
57
71
  return [{
@@ -63,13 +77,13 @@ var g = new c("ensureTextAfterMath"), _ = (e = []) => e.map((e) => ({
63
77
  }];
64
78
  },
65
79
  addCommands() {
66
- return { insertMath: (e = "") => ({ tr: t, editor: n, dispatch: r }) => {
67
- let { state: i } = n.view, a = i.schema.nodes.math.create({ latex: e }), { selection: s } = i, c = s.$from.pos;
68
- if (t.insert(c, a), a?.type?.name === this.name) {
69
- let e = o.create(t.doc, s.$from.pos);
70
- t.setSelection(e);
80
+ return { insertMath: (t = "") => ({ tr: n, editor: r, dispatch: i }) => {
81
+ let { state: a } = r.view, o = a.schema.nodes.math.create({ latex: t }), { selection: c } = a, l = c.$from.pos;
82
+ if (n.insert(l, o), o?.type?.name === this.name) {
83
+ let e = s.create(n.doc, c.$from.pos);
84
+ n.setSelection(e);
71
85
  }
72
- return r(t), !0;
86
+ return i(n), e(r, !0), !0;
73
87
  } };
74
88
  },
75
89
  renderHTML({ HTMLAttributes: e }) {
@@ -82,77 +96,118 @@ var g = new c("ensureTextAfterMath"), _ = (e = []) => e.map((e) => ({
82
96
  "data-latex": "",
83
97
  "data-raw": e.latex
84
98
  },
85
- p(e.latex, e.wrapper)
99
+ m(e.latex, e.wrapper)
86
100
  ];
87
101
  },
88
102
  addNodeView() {
89
- return i((e) => /* @__PURE__ */ d(x, {
103
+ return a((e) => /* @__PURE__ */ f(C, {
90
104
  ...e,
91
105
  options: this.options
92
106
  }));
93
107
  }
94
- }), x = (i) => {
95
- let { node: a, updateAttributes: o, editor: s, selected: c, options: p } = i, [g, v] = n(c), y = t(null), [b, x] = n({
108
+ }), C = (a) => {
109
+ let { node: o, updateAttributes: s, editor: c, selected: l, options: m, getPos: _ } = a, [y, b] = r(l), x = n(null), S = n(null), C = n(Date.now()), [w, T] = r({
96
110
  top: 0,
97
111
  left: 0
98
- }), { math: S = {} } = p || {}, { keypadMode: C, controlledKeypadMode: w = !0, customKeys: T = [], keyPadCharacterRef: E, setKeypadInteraction: D } = S, O = a.attrs.latex || "", k = (e) => {
99
- o({ latex: e });
100
- }, A = (e) => {
101
- o({ latex: e }), v(!1), s._toolbarOpened = !1;
102
- let { selection: t, tr: n, doc: r } = s.state, i = l.create(r, t.from + 1);
103
- n.setSelection(i), s.view.dispatch(n), s.commands.focus();
112
+ }), { math: E = {} } = m || {}, { keypadMode: D, controlledKeypadMode: O = !0, customKeys: k = [], keyPadCharacterRef: A, setKeypadInteraction: j } = E, M = o.attrs.latex || "", N = (e) => {
113
+ s({ latex: e });
114
+ }, P = (e, { moveCursorAfterNode: t = !0 } = {}) => {
115
+ if (s({ latex: e }), b(!1), t && typeof _ == "function") {
116
+ let e = _(), { doc: t } = c.state, n = u.create(t, e + o.nodeSize), r = c.state.tr.setSelection(n);
117
+ c.view.dispatch(r);
118
+ }
119
+ c.commands.focus();
104
120
  };
105
- return e(() => {
106
- c && v(!0);
107
- }, [c]), e(() => {
108
- s._toolbarOpened = !!g;
109
- }, [g]), e(() => {
110
- let { from: e } = s.state.selection;
111
- x({
112
- top: 40,
113
- left: s.view.coordsAtPos(e).left
114
- });
115
- let t = (e) => {
116
- let t = e?.target, n = (document.querySelectorAll?.("[id^=\"equation-editor-select\"][id*=\"listbox\"], [aria-labelledby=\"equation-editor-label\"][role=\"listbox\"]") || []).length > 0, r = !!(t?.id && t.id.includes("equation-editor-select")) || !!t?.closest?.("[id*=\"equation-editor-select\"]"), i = !!t?.closest?.(".math-node");
117
- y.current && !y.current.contains(t) && !t?.closest?.("[data-inline-node]") && !n && !r && !i && (v(!1), A(a.attrs.latex));
121
+ return t(() => {
122
+ if (!l) return;
123
+ let { selection: e } = c.state;
124
+ e.node?.type?.name === "math" && b(!0);
125
+ }, [l, c]), t(() => {
126
+ e(c, l || y);
127
+ }, [
128
+ c,
129
+ y,
130
+ l
131
+ ]), t(() => {
132
+ if (!c || !y) {
133
+ T({
134
+ top: 0,
135
+ left: 0
136
+ });
137
+ return;
138
+ }
139
+ let e = () => {
140
+ if (!x.current) return;
141
+ let { from: e } = c.state.selection, t = c.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, l = window.innerHeight - (a + 0) >= o ? a + 0 : r - o - 0, u = i;
142
+ l = Math.max(8, Math.min(l, window.innerHeight - o - 8)), u = Math.max(8, Math.min(u, window.innerWidth - s - 8));
143
+ let d = (c._tiptapContainerEl || document.body).getBoundingClientRect();
144
+ T({
145
+ top: l - d.top,
146
+ left: u - d.left
147
+ });
148
+ };
149
+ e();
150
+ let t = null, n = () => {
151
+ t === null && (t = requestAnimationFrame(() => {
152
+ t = null, e();
153
+ }));
154
+ };
155
+ return t = requestAnimationFrame(() => {
156
+ t = null, e();
157
+ }), window.addEventListener("scroll", n, !0), window.addEventListener("resize", n), () => {
158
+ t !== null && cancelAnimationFrame(t), window.removeEventListener("scroll", n, !0), window.removeEventListener("resize", n);
159
+ };
160
+ }, [c, y]), t(() => {
161
+ let e = (e) => {
162
+ let t = e?.target, n = (document.querySelectorAll?.("[id^=\"equation-editor-select\"][id*=\"listbox\"], [aria-labelledby=\"equation-editor-label\"][role=\"listbox\"]") || []).length > 0, r = !!(t?.id && t.id.includes("equation-editor-select")) || !!t?.closest?.("[id*=\"equation-editor-select\"]"), i = !!t?.closest?.(`.math-node-${C.current}`);
163
+ if (x.current && !x.current.contains(t) && !t?.closest?.("[data-inline-node]") && !n && !r && !i) {
164
+ b(!1);
165
+ let e = !!c?.view?.dom?.contains(t);
166
+ P(o.attrs.latex, { moveCursorAfterNode: !e });
167
+ }
118
168
  };
119
- return g ? document.addEventListener("click", t) : document.removeEventListener("click", t), () => document.removeEventListener("click", t);
120
- }, [s, g]), /* @__PURE__ */ f(r, {
121
- className: "math-node",
169
+ return y ? document.addEventListener("click", e) : document.removeEventListener("click", e), () => document.removeEventListener("click", e);
170
+ }, [
171
+ c,
172
+ y,
173
+ o
174
+ ]), /* @__PURE__ */ p(i, {
175
+ className: `math-node-${C.current}`,
122
176
  style: {
123
177
  display: "inline-flex",
124
178
  cursor: "pointer",
125
179
  margin: "0 4px"
126
180
  },
127
- "data-selected": c,
128
- children: [/* @__PURE__ */ d("div", {
129
- onClick: () => v(!0),
181
+ "data-selected": l,
182
+ children: [/* @__PURE__ */ f("div", {
183
+ ref: S,
184
+ onClick: () => b(!0),
130
185
  contentEditable: !1,
131
- children: /* @__PURE__ */ d(m, { latex: O })
132
- }), g && u.createPortal(/* @__PURE__ */ d("div", {
133
- ref: y,
134
- "data-toolbar-for": s.instanceId,
186
+ children: /* @__PURE__ */ f(h, { latex: M })
187
+ }), y && d.createPortal(/* @__PURE__ */ f("div", {
188
+ ref: x,
189
+ "data-toolbar-for": c.instanceId,
135
190
  style: {
136
191
  position: "absolute",
137
- top: `${b.top}px`,
138
- left: `${b.left}px`,
139
- zIndex: 20,
192
+ top: `${w.top}px`,
193
+ left: `${w.left}px`,
194
+ zIndex: 1e3,
140
195
  background: "var(--editable-html-toolbar-bg, #efefef)",
141
196
  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)"
142
197
  },
143
- children: /* @__PURE__ */ d(h, {
144
- latex: O,
198
+ children: /* @__PURE__ */ f(g, {
199
+ latex: M,
145
200
  autoFocus: !0,
146
- onChange: k,
147
- onDone: A,
148
- keypadMode: C,
149
- controlledKeypadMode: w,
150
- additionalKeys: _(T),
151
- keyPadCharacterRef: E,
152
- setKeypadInteraction: D
201
+ onChange: N,
202
+ onDone: P,
203
+ keypadMode: D,
204
+ controlledKeypadMode: O,
205
+ additionalKeys: v(k),
206
+ keyPadCharacterRef: A,
207
+ setKeypadInteraction: j
153
208
  })
154
- }), s?._tiptapContainerEl || document.body)]
209
+ }), c?._tiptapContainerEl || document.body)]
155
210
  });
156
211
  };
157
212
  //#endregion
158
- export { b as MathNode };
213
+ export { y as EnsureTextAfterMathPlugin, S as MathNode, C as MathNodeView, x as ZeroWidthSpaceHandlingPlugin };
@@ -1,4 +1,4 @@
1
- import e from "../components/media/MediaDialog.js";
1
+ import { MediaDialog as e } from "../components/media/MediaDialog.js";
2
2
  import t from "../components/media/MediaToolbar.js";
3
3
  import { useEffect as n } from "react";
4
4
  import { NodeViewWrapper as r, ReactNodeViewRenderer as i } from "@tiptap/react";
@@ -146,4 +146,4 @@ function p({ editor: e, node: i, updateAttributes: a, deleteNode: o, options: s
146
146
  });
147
147
  }
148
148
  //#endregion
149
- export { u as Media };
149
+ export { u as Media, p as default, f as insertDialog };
@@ -92,11 +92,7 @@ var f = {}, p = (e) => String(e || "").replace(/-/g, "_"), m = (e) => e && e.att
92
92
  }
93
93
  }, m = d(u);
94
94
  if (m ??= d(t.doc.content.size), m == null) return !1;
95
- if ([
96
- "math_templated",
97
- "inline_dropdown",
98
- "explicit_constructed_response"
99
- ].includes(a)) t.setSelection(s.create(t.doc, m));
95
+ if (["inline_dropdown", "explicit_constructed_response"].includes(a)) t.setSelection(s.create(t.doc, m));
100
96
  else {
101
97
  let e = m + c.nodeSize;
102
98
  t.setSelection(v(t.doc, e));
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ALL_PLUGINS as e, DEFAULT_PLUGINS as t } from "./extensions/index.js";
2
- import n from "./components/EditableHtml.js";
2
+ import { EditableHtml as n } from "./components/EditableHtml.js";
3
3
  import { deleteInlineDropdownByIndex as r } from "./components/respArea/inlineDropdownUtils.js";
4
4
  //#region src/index.tsx
5
5
  var i = n;
@@ -13,4 +13,4 @@ function t() {
13
13
  return i;
14
14
  }
15
15
  //#endregion
16
- export { t as default };
16
+ export { t as clsx, t as default };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/utils/toolbar.js
3
+ * @auto-generated
4
+ *
5
+ * This file is automatically synced from pie-elements and converted to TypeScript.
6
+ * Manual edits will be overwritten on next sync.
7
+ * To make changes, edit the upstream JavaScript file and run sync again.
8
+ */
9
+ export declare const TOOLBAR_OPENED_META_KEY = "toolbarOpenedChanged";
10
+ export declare const setToolbarOpened: (editor: any, opened: any) => void;
@@ -0,0 +1,7 @@
1
+ //#region src/utils/toolbar.ts
2
+ var e = "toolbarOpenedChanged", t = (t, n) => {
3
+ let r = !!n;
4
+ t._toolbarOpened !== r && (t._toolbarOpened = r, t?.view && t?.state?.tr && t.view.dispatch(t.state.tr.setMeta(e, !0)));
5
+ };
6
+ //#endregion
7
+ export { e as TOOLBAR_OPENED_META_KEY, t as setToolbarOpened };
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "@pie-lib/editable-html-tip-tap",
3
- "version": "2.1.2-next.31",
3
+ "version": "2.1.2-next.32",
4
4
  "description": "",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/pie-framework/pie-elements-ng.git",
8
+ "directory": "packages/lib-react/editable-html-tip-tap"
9
+ },
5
10
  "dependencies": {
6
11
  "@dnd-kit/core": "6.3.1",
7
12
  "@dnd-kit/modifiers": "9.0.0",
8
13
  "@dnd-kit/utilities": "3.2.2",
9
14
  "@mui/icons-material": "^7.3.4",
10
15
  "@mui/material": "^7.3.4",
11
- "@pie-lib/drag": "4.0.3-next.38",
12
- "@pie-lib/math-input": "8.1.1-next.3",
13
- "@pie-lib/math-toolbar": "3.0.3-next.38",
14
- "@pie-lib/render-ui": "6.1.1-next.38",
16
+ "@pie-lib/drag": "4.0.3-next.39",
17
+ "@pie-lib/math-input": "8.1.1-next.4",
18
+ "@pie-lib/math-toolbar": "3.0.3-next.39",
19
+ "@pie-lib/render-ui": "6.1.1-next.39",
15
20
  "@tiptap/core": "3.20.0",
16
21
  "@tiptap/extension-character-count": "3.20.0",
17
22
  "@tiptap/extension-color": "3.20.0",
@@ -23,10 +28,10 @@
23
28
  "@tiptap/extension-table": "3.20.0",
24
29
  "@tiptap/extension-table-cell": "3.20.0",
25
30
  "@tiptap/extension-table-header": "3.20.0",
26
- "@tiptap/extension-table-row": "3.20.0",
31
+ "@tiptap/extension-table-row": "3.30.1",
27
32
  "@tiptap/extension-text-align": "3.20.0",
28
33
  "@tiptap/extension-text-style": "3.20.0",
29
- "@tiptap/pm": "3.20.0",
34
+ "@tiptap/pm": "3.30.2",
30
35
  "@tiptap/react": "3.20.0",
31
36
  "@tiptap/starter-kit": "3.20.0",
32
37
  "change-case": "^3.0.2",