@pie-lib/editable-html-tip-tap 3.1.3-next.20261026212738 → 3.1.3-next.20261027184745
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/CharacterPicker.js +93 -92
- package/dist/components/EditableHtml.js +196 -170
- package/dist/components/MenuBar.js +241 -149
- package/dist/components/ToolbarDisclosure.d.ts +18 -0
- package/dist/components/ToolbarDisclosure.js +63 -0
- package/dist/components/characters/characterUtils.d.ts +10 -0
- package/dist/components/characters/characterUtils.js +187 -1
- package/dist/components/icons/TextAlign.d.ts +9 -4
- package/dist/components/icons/TextAlign.js +35 -93
- package/dist/extensions/index.d.ts +1 -0
- package/dist/extensions/index.js +4 -1
- package/dist/extensions/text-direction.d.ts +35 -0
- package/dist/extensions/text-direction.js +157 -0
- package/dist/utils/content-languages.d.ts +14 -0
- package/dist/utils/content-languages.js +25 -0
- package/dist/utils/direction.d.ts +10 -0
- package/dist/utils/direction.js +11 -0
- package/package.json +5 -4
|
@@ -1,60 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { useEffect as
|
|
4
|
-
import { get as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { Fragment as
|
|
8
|
-
import { PureToolbar as
|
|
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
|
|
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
|
-
|
|
18
|
-
var
|
|
17
|
+
h.propTypes = { letter: u.string };
|
|
18
|
+
var g = [
|
|
19
19
|
"ArrowLeft",
|
|
20
20
|
"ArrowRight",
|
|
21
21
|
"ArrowUp",
|
|
22
22
|
"ArrowDown"
|
|
23
|
-
],
|
|
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
|
-
},
|
|
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
|
|
33
|
-
if (!
|
|
34
|
-
let
|
|
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
|
-
}), [
|
|
38
|
-
|
|
39
|
-
let
|
|
40
|
-
if (!
|
|
37
|
+
}), [E, D] = s(null);
|
|
38
|
+
C.current = _;
|
|
39
|
+
let O = a(() => {
|
|
40
|
+
if (!h) return t;
|
|
41
41
|
switch (!0) {
|
|
42
|
-
case
|
|
43
|
-
case
|
|
44
|
-
|
|
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
|
-
}, [
|
|
47
|
-
rows:
|
|
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
|
-
}), [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}, []),
|
|
53
|
-
if (!
|
|
54
|
-
let e =
|
|
55
|
-
if (!
|
|
56
|
-
let t = e.getBoundingClientRect(), { from: n } =
|
|
57
|
-
o = Math.max(8, Math.min(o, window.innerHeight - i - 8)), s = Math.max(8, Math.min(s, window.innerWidth - a - 8)),
|
|
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
|
-
|
|
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
|
-
}, [
|
|
78
|
-
let
|
|
79
|
-
|
|
80
|
-
if (!
|
|
81
|
-
let e =
|
|
82
|
-
e && (e.focus(),
|
|
83
|
-
}, [
|
|
84
|
-
if (!
|
|
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
|
-
|
|
87
|
+
C.current(), v.focus();
|
|
87
88
|
}, t = (e, t, n) => {
|
|
88
|
-
|
|
89
|
+
x(n, Math.max(0, n.indexOf(t.closest("button"))), e, k.columns || 1)?.focus();
|
|
89
90
|
}, n = () => {
|
|
90
|
-
let e =
|
|
91
|
-
((t === -1 ? null : e[t + 1]) ||
|
|
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 (!
|
|
94
|
-
let i =
|
|
94
|
+
if (!S.current) return;
|
|
95
|
+
let i = M();
|
|
95
96
|
if (!i.length) return;
|
|
96
|
-
let a = r.target, o =
|
|
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 &&
|
|
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 ===
|
|
107
|
-
l ? (r.preventDefault(), s.focus()) : u ? (r.preventDefault(),
|
|
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
|
-
}, [
|
|
111
|
-
let
|
|
111
|
+
}, [v, k.columns]);
|
|
112
|
+
let P = (e, t) => D({
|
|
112
113
|
anchorEl: e.currentTarget,
|
|
113
114
|
el: t
|
|
114
|
-
}),
|
|
115
|
-
return /* @__PURE__ */
|
|
116
|
-
ref:
|
|
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":
|
|
119
|
+
"data-toolbar-for": u.instanceId,
|
|
119
120
|
onPointerDown: () => {
|
|
120
|
-
|
|
121
|
+
F.current = "pointer";
|
|
121
122
|
},
|
|
122
123
|
onKeyDown: () => {
|
|
123
|
-
|
|
124
|
+
F.current = "keyboard";
|
|
124
125
|
},
|
|
125
126
|
style: {
|
|
126
|
-
visibility:
|
|
127
|
+
visibility: j ? "initial" : "hidden",
|
|
127
128
|
position: "fixed",
|
|
128
|
-
top: `${
|
|
129
|
-
left: `${
|
|
129
|
+
top: `${w.top}px`,
|
|
130
|
+
left: `${w.left}px`,
|
|
130
131
|
maxWidth: "500px",
|
|
131
132
|
zIndex: 1e3
|
|
132
133
|
},
|
|
133
|
-
children: /* @__PURE__ */
|
|
134
|
-
keyPadCharacterRef:
|
|
135
|
-
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:
|
|
141
|
-
additionalKeys:
|
|
142
|
-
name:
|
|
143
|
-
write:
|
|
144
|
-
label:
|
|
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
|
-
...
|
|
155
|
-
onMouseEnter: (t) =>
|
|
156
|
-
onMouseLeave:
|
|
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" && (
|
|
162
|
+
typeof e == "string" && (F.current === "pointer" ? u.chain().focus().insertContent(e).run() : u.chain().insertContent(e).run());
|
|
162
163
|
},
|
|
163
164
|
onDone: () => {
|
|
164
|
-
|
|
165
|
+
_(), v?.focus();
|
|
165
166
|
}
|
|
166
167
|
}) })
|
|
167
|
-
}), document.body),
|
|
168
|
-
onClose:
|
|
169
|
-
anchorEl:
|
|
168
|
+
}), document.body), E && l.createPortal(/* @__PURE__ */ p(r, {
|
|
169
|
+
onClose: A,
|
|
170
|
+
anchorEl: E.anchorEl,
|
|
170
171
|
children: [
|
|
171
|
-
/* @__PURE__ */
|
|
172
|
-
/* @__PURE__ */
|
|
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:
|
|
178
|
+
children: E.el.description
|
|
178
179
|
}),
|
|
179
|
-
/* @__PURE__ */
|
|
180
|
+
/* @__PURE__ */ f("div", {
|
|
180
181
|
style: {
|
|
181
182
|
fontSize: 20,
|
|
182
183
|
lineHeight: "20px"
|
|
183
184
|
},
|
|
184
|
-
children:
|
|
185
|
+
children: E.el.unicode
|
|
185
186
|
})
|
|
186
187
|
]
|
|
187
188
|
}), document.body)] });
|
|
188
189
|
}
|
|
189
|
-
|
|
190
|
-
editor:
|
|
191
|
-
opts:
|
|
192
|
-
onClose:
|
|
193
|
-
triggerEl:
|
|
194
|
-
focusOnOpen:
|
|
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 {
|
|
198
|
+
export { h as CharacterIcon, S as CharacterPicker };
|