@pie-lib/editable-html-tip-tap 3.1.3-next.20261026212738 → 3.1.3-next.20261027193325

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,60 +1,61 @@
1
- import { spanishConfig as e, specialConfig as t } from "./characters/characterUtils.js";
2
- import n from "./characters/custom-popper.js";
3
- import { useEffect as r, useMemo as i, useRef as a, useState as o } from "react";
4
- import { get as s } from "@pie-element/shared-lodash";
5
- import c from "react-dom";
6
- import l from "prop-types";
7
- import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
8
- import { PureToolbar as p } from "@pie-lib/math-toolbar";
1
+ import { arabicConfig as e, spanishConfig as t, specialConfig as n } from "./characters/characterUtils.js";
2
+ import r from "./characters/custom-popper.js";
3
+ import { useEffect as i, useMemo as a, useRef as o, useState as s } from "react";
4
+ import { get as c } from "@pie-element/shared-lodash";
5
+ import l from "react-dom";
6
+ import u from "prop-types";
7
+ import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
8
+ import { PureToolbar as m } from "@pie-lib/math-toolbar";
9
9
  //#region src/components/CharacterPicker.tsx
10
- var m = ({ letter: e }) => /* @__PURE__ */ d("div", {
10
+ var h = ({ letter: e }) => /* @__PURE__ */ f("div", {
11
11
  style: {
12
12
  fontSize: "24px",
13
13
  lineHeight: "24px"
14
14
  },
15
15
  children: e
16
16
  });
17
- m.propTypes = { letter: l.string };
18
- var h = [
17
+ h.propTypes = { letter: u.string };
18
+ var g = [
19
19
  "ArrowLeft",
20
20
  "ArrowRight",
21
21
  "ArrowUp",
22
22
  "ArrowDown"
23
- ], g = "button, a[href], input, select, textarea, [contenteditable=\"true\"], [tabindex]", _ = (e) => {
23
+ ], _ = "button, a[href], input, select, textarea, [contenteditable=\"true\"], [tabindex]", v = (e) => {
24
24
  let t = e.tabIndex >= 0, n = !e.disabled, r = !!e.closest("[inert]"), i = e.getClientRects().length > 0;
25
25
  return t && n && !r && i;
26
- }, v = (e) => Array.from(e.querySelectorAll(g)).filter(_), y = (e, t) => (e + t) % t, b = (e, t, n, r) => e[y(t + {
26
+ }, y = (e) => Array.from(e.querySelectorAll(_)).filter(v), b = (e, t) => (e + t) % t, x = (e, t, n, r) => e[b(t + {
27
27
  ArrowLeft: -1,
28
28
  ArrowRight: 1,
29
29
  ArrowUp: -r,
30
30
  ArrowDown: r
31
31
  }[n], e.length)];
32
- function x({ editor: l, opts: m, onClose: g, triggerEl: _, focusOnOpen: y }) {
33
- if (!m?.characters?.length) return null;
34
- let x = a(null), S = a(g), [C, w] = o({
32
+ function S({ editor: u, opts: h, onClose: _, triggerEl: v, focusOnOpen: b }) {
33
+ if (!h?.characters?.length) return null;
34
+ let S = o(null), C = o(_), [w, T] = s({
35
35
  top: 0,
36
36
  left: 0
37
- }), [T, E] = o(null);
38
- S.current = g;
39
- let D = i(() => {
40
- if (!m) return e;
37
+ }), [E, D] = s(null);
38
+ C.current = _;
39
+ let O = a(() => {
40
+ if (!h) return t;
41
41
  switch (!0) {
42
- case m.language === "spanish": return e;
43
- case m.language === "special": return t;
44
- default: return m;
42
+ case h.language === "spanish": return t;
43
+ case h.language === "special": return n;
44
+ case h.language === "arabic": return e;
45
+ default: return h;
45
46
  }
46
- }, [m]), O = i(() => D.characters.reduce((e, t) => (t.length >= e.columns && (e.columns = t.length), e), {
47
- rows: D.characters.length,
47
+ }, [h]), k = a(() => O.characters.reduce((e, t) => (t.length >= e.columns && (e.columns = t.length), e), {
48
+ rows: O.characters.length,
48
49
  columns: 0
49
- }), [D]), k = () => E(null);
50
- r(() => () => {
51
- k();
52
- }, []), r(() => {
53
- if (!l) return;
54
- let e = l.options.element, t = l.view.dom, n = () => {
55
- if (!x.current) return;
56
- let t = e.getBoundingClientRect(), { from: n } = l.state.selection, r = l.view.coordsAtPos(n), i = x.current.offsetHeight, a = x.current.offsetWidth, o = window.innerHeight - (t.bottom + 60) >= i || t.top < i + 80 ? t.bottom + 60 : t.top - i - 20, s = r.left;
57
- o = Math.max(8, Math.min(o, window.innerHeight - i - 8)), s = Math.max(8, Math.min(s, window.innerWidth - a - 8)), w({
50
+ }), [O]), A = () => D(null);
51
+ i(() => () => {
52
+ A();
53
+ }, []), i(() => {
54
+ if (!u) return;
55
+ let e = u.options.element, t = u.view.dom, n = () => {
56
+ if (!S.current) return;
57
+ let t = e.getBoundingClientRect(), { from: n } = u.state.selection, r = u.view.coordsAtPos(n), i = S.current.offsetHeight, a = S.current.offsetWidth, o = window.innerHeight - (t.bottom + 60) >= i || t.top < i + 80 ? t.bottom + 60 : t.top - i - 20, s = r.left;
58
+ o = Math.max(8, Math.min(o, window.innerHeight - i - 8)), s = Math.max(8, Math.min(s, window.innerWidth - a - 8)), T({
58
59
  top: o,
59
60
  left: s
60
61
  });
@@ -67,81 +68,81 @@ function x({ editor: l, opts: m, onClose: g, triggerEl: _, focusOnOpen: y }) {
67
68
  };
68
69
  window.addEventListener("scroll", i, !0), window.addEventListener("resize", i);
69
70
  let a = (e) => {
70
- x.current && !x.current.contains(e.target) && !t.contains(e.target) && S.current();
71
+ S.current && !S.current.contains(e.target) && !t.contains(e.target) && C.current();
71
72
  }, o = setTimeout(() => {
72
73
  document.addEventListener("click", a);
73
74
  });
74
75
  return () => {
75
76
  clearTimeout(o), r !== null && cancelAnimationFrame(r), window.removeEventListener("scroll", i, !0), window.removeEventListener("resize", i), document.removeEventListener("click", a);
76
77
  };
77
- }, [l]);
78
- let A = C.top !== 0 || C.left !== 0, j = () => Array.from(x.current?.querySelectorAll("button:not([disabled])") ?? []), M = a(!1);
79
- r(() => {
80
- if (!y || !A || M.current) return;
81
- let e = j()[0];
82
- e && (e.focus(), M.current = !0);
83
- }, [y, A]), r(() => {
84
- if (!_) return;
78
+ }, [u]);
79
+ let j = w.top !== 0 || w.left !== 0, M = () => Array.from(S.current?.querySelectorAll("button:not([disabled])") ?? []), N = o(!1);
80
+ i(() => {
81
+ if (!b || !j || N.current) return;
82
+ let e = M()[0];
83
+ e && (e.focus(), N.current = !0);
84
+ }, [b, j]), i(() => {
85
+ if (!v) return;
85
86
  let e = () => {
86
- S.current(), _.focus();
87
+ C.current(), v.focus();
87
88
  }, t = (e, t, n) => {
88
- b(n, Math.max(0, n.indexOf(t.closest("button"))), e, O.columns || 1)?.focus();
89
+ x(n, Math.max(0, n.indexOf(t.closest("button"))), e, k.columns || 1)?.focus();
89
90
  }, n = () => {
90
- let e = v(document.body).filter((e) => !x.current.contains(e)), t = e.indexOf(_);
91
- ((t === -1 ? null : e[t + 1]) || _).focus();
91
+ let e = y(document.body).filter((e) => !S.current.contains(e)), t = e.indexOf(v);
92
+ ((t === -1 ? null : e[t + 1]) || v).focus();
92
93
  }, r = (r) => {
93
- if (!x.current) return;
94
- let i = j();
94
+ if (!S.current) return;
95
+ let i = M();
95
96
  if (!i.length) return;
96
- let a = r.target, o = x.current.contains(a), s = i[0], c = i[i.length - 1];
97
+ let a = r.target, o = S.current.contains(a), s = i[0], c = i[i.length - 1];
97
98
  if (o && r.key === "Escape") {
98
99
  r.preventDefault(), r.stopPropagation(), e();
99
100
  return;
100
101
  }
101
- if (o && h.includes(r.key)) {
102
+ if (o && g.includes(r.key)) {
102
103
  r.preventDefault(), r.stopPropagation(), t(r.key, a, i);
103
104
  return;
104
105
  }
105
106
  if (r.key !== "Tab") return;
106
- let l = a === _ && !r.shiftKey, u = a === s && r.shiftKey, d = a === c && !r.shiftKey;
107
- l ? (r.preventDefault(), s.focus()) : u ? (r.preventDefault(), _.focus()) : d && (r.preventDefault(), n());
107
+ let l = a === v && !r.shiftKey, u = a === s && r.shiftKey, d = a === c && !r.shiftKey;
108
+ l ? (r.preventDefault(), s.focus()) : u ? (r.preventDefault(), v.focus()) : d && (r.preventDefault(), n());
108
109
  };
109
110
  return document.addEventListener("keydown", r, !0), () => document.removeEventListener("keydown", r, !0);
110
- }, [_, O.columns]);
111
- let N = (e, t) => E({
111
+ }, [v, k.columns]);
112
+ let P = (e, t) => D({
112
113
  anchorEl: e.currentTarget,
113
114
  el: t
114
- }), P = a("keyboard");
115
- return /* @__PURE__ */ f(u, { children: [c.createPortal(/* @__PURE__ */ d("div", {
116
- ref: x,
115
+ }), F = o("keyboard");
116
+ return /* @__PURE__ */ p(d, { children: [l.createPortal(/* @__PURE__ */ f("div", {
117
+ ref: S,
117
118
  className: "insert-character-dialog",
118
- "data-toolbar-for": l.instanceId,
119
+ "data-toolbar-for": u.instanceId,
119
120
  onPointerDown: () => {
120
- P.current = "pointer";
121
+ F.current = "pointer";
121
122
  },
122
123
  onKeyDown: () => {
123
- P.current = "keyboard";
124
+ F.current = "keyboard";
124
125
  },
125
126
  style: {
126
- visibility: A ? "initial" : "hidden",
127
+ visibility: j ? "initial" : "hidden",
127
128
  position: "fixed",
128
- top: `${C.top}px`,
129
- left: `${C.left}px`,
129
+ top: `${w.top}px`,
130
+ left: `${w.left}px`,
130
131
  maxWidth: "500px",
131
132
  zIndex: 1e3
132
133
  },
133
- children: /* @__PURE__ */ d("div", { children: /* @__PURE__ */ d(p, {
134
- keyPadCharacterRef: m.keyPadCharacterRef,
135
- setKeypadInteraction: m.setKeypadInteraction,
134
+ children: /* @__PURE__ */ f("div", { children: /* @__PURE__ */ f(m, {
135
+ keyPadCharacterRef: h.keyPadCharacterRef,
136
+ setKeypadInteraction: h.setKeypadInteraction,
136
137
  noDecimal: !0,
137
138
  hideInput: !0,
138
139
  noLatexHandling: !0,
139
140
  hideDoneButtonBackground: !0,
140
- layoutForKeyPad: O,
141
- additionalKeys: D.characters.reduce((e, t) => (e = [...e, ...t.map((e) => ({
142
- name: s(e, "name") || e,
143
- write: s(e, "write") || e,
144
- label: s(e, "label") || e,
141
+ layoutForKeyPad: k,
142
+ additionalKeys: O.characters.reduce((e, t) => (e = [...e, ...t.map((e) => ({
143
+ name: c(e, "name") || c(e, "label") || e,
144
+ write: c(e, "write") || e,
145
+ label: c(e, "label") || e,
145
146
  category: "character",
146
147
  extraClass: "character",
147
148
  extraProps: {
@@ -151,47 +152,47 @@ function x({ editor: l, opts: m, onClose: g, triggerEl: _, focusOnOpen: y }) {
151
152
  border: "1px solid #000"
152
153
  }
153
154
  },
154
- ...D.hasPreview ? { actions: {
155
- onMouseEnter: (t) => N(t, e),
156
- onMouseLeave: k
155
+ ...O.hasPreview ? { actions: {
156
+ onMouseEnter: (t) => P(t, e),
157
+ onMouseLeave: A
157
158
  } } : {}
158
159
  }))], e), []),
159
160
  keypadMode: "language",
160
161
  onChange: (e) => {
161
- typeof e == "string" && (P.current === "pointer" ? l.chain().focus().insertContent(e).run() : l.chain().insertContent(e).run());
162
+ typeof e == "string" && (F.current === "pointer" ? u.chain().focus().insertContent(e).run() : u.chain().insertContent(e).run());
162
163
  },
163
164
  onDone: () => {
164
- g(), _?.focus();
165
+ _(), v?.focus();
165
166
  }
166
167
  }) })
167
- }), document.body), T && c.createPortal(/* @__PURE__ */ f(n, {
168
- onClose: k,
169
- anchorEl: T.anchorEl,
168
+ }), document.body), E && l.createPortal(/* @__PURE__ */ p(r, {
169
+ onClose: A,
170
+ anchorEl: E.anchorEl,
170
171
  children: [
171
- /* @__PURE__ */ d("div", { children: T.el.label }),
172
- /* @__PURE__ */ d("div", {
172
+ /* @__PURE__ */ f("div", { children: E.el.label }),
173
+ /* @__PURE__ */ f("div", {
173
174
  style: {
174
175
  fontSize: 20,
175
176
  lineHeight: "20px"
176
177
  },
177
- children: T.el.description
178
+ children: E.el.description
178
179
  }),
179
- /* @__PURE__ */ d("div", {
180
+ /* @__PURE__ */ f("div", {
180
181
  style: {
181
182
  fontSize: 20,
182
183
  lineHeight: "20px"
183
184
  },
184
- children: T.el.unicode
185
+ children: E.el.unicode
185
186
  })
186
187
  ]
187
188
  }), document.body)] });
188
189
  }
189
- x.propTypes = {
190
- editor: l.object,
191
- opts: l.object,
192
- onClose: l.func.isRequired,
193
- triggerEl: l.object,
194
- focusOnOpen: l.bool
190
+ S.propTypes = {
191
+ editor: u.object,
192
+ opts: u.object,
193
+ onClose: u.func.isRequired,
194
+ triggerEl: u.object,
195
+ focusOnOpen: u.bool
195
196
  };
196
197
  //#endregion
197
- export { m as CharacterIcon, x as CharacterPicker };
198
+ export { h as CharacterIcon, S as CharacterPicker };