@code0-tech/pictor 0.17.0 → 0.17.1

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.
@@ -22,9 +22,18 @@ export interface EditorInputProps extends Omit<InputWrapperProps, "onChange" | "
22
22
  placeholder?: string;
23
23
  children?: React.ReactNode;
24
24
  }
25
+ export type EditorInputMenuOpenMode = "shortcut" | "focus";
25
26
  export type EditorInputValueProps = Component<HTMLDivElement>;
26
27
  export type EditorInputTriggerProps = Component<HTMLButtonElement>;
27
- export type EditorInputMenuProps = MenuContentProps;
28
+ export type EditorInputMenuProps = MenuContentProps & {
29
+ /**
30
+ * When the menu opens.
31
+ * - "shortcut" (default): opens only on Ctrl+Space.
32
+ * - "focus": opens as soon as the input is focused and stays open while focused.
33
+ * Positioning stays anchored to the caret in both modes.
34
+ */
35
+ openOn?: EditorInputMenuOpenMode;
36
+ };
28
37
  export type EditorInputMenuItemProps = MenuItemProps & {
29
38
  value: any;
30
39
  data?: any;
@@ -1,542 +1,557 @@
1
- import { jsx as x, jsxs as ke } from "react/jsx-runtime";
2
- import { c as le } from "../../_virtual/compiler-runtime.js";
3
- import Y, { useMemo as ae, useRef as G, useState as ie, useEffect as re, useCallback as T } from "react";
4
- import { createEditor as Oe, Editor as fe, Transforms as ne, Text as pe, Range as Te, Node as Pe } from "slate";
5
- import { withReact as Ne, ReactEditor as Q, Slate as Ve, Editable as Fe } from "slate-react";
6
- import { withHistory as Le } from "slate-history";
7
- import { InputWrapper as $e } from "./InputWrapper.js";
1
+ import { jsx as v, jsxs as Re } from "react/jsx-runtime";
2
+ import { c as ae } from "../../_virtual/compiler-runtime.js";
3
+ import ee, { useMemo as de, useRef as W, useState as le, useEffect as se, useCallback as O } from "react";
4
+ import { createEditor as Ve, Editor as he, Transforms as oe, Text as ge, Range as ke, Node as Fe } from "slate";
5
+ import { withReact as Le, ReactEditor as Y, Slate as $e, Editable as je } from "slate-react";
6
+ import { withHistory as Be } from "slate-history";
7
+ import { InputWrapper as Ke } from "./InputWrapper.js";
8
8
  import "../../utils/contextStore.js";
9
- import { mergeComponentProps as Re } from "../../utils/component.js";
9
+ import { mergeComponentProps as Ee } from "../../utils/component.js";
10
10
  import "js-md5";
11
- import { Menu as je, MenuPortal as Be, MenuContent as Ke, MenuItem as Ue, MenuSubContent as We, MenuTrigger as Ge, MenuSubTrigger as He, MenuSub as qe } from "../menu/Menu.js";
11
+ import { Menu as Ue, MenuPortal as We, MenuContent as Ge, MenuItem as He, MenuSubContent as qe, MenuTrigger as ze, MenuSubTrigger as Je, MenuSub as Qe } from "../menu/Menu.js";
12
12
  import '../../assets/components/form/EditorInput.style.css';/* empty css */
13
- const X = (n) => n?.type === "token", ze = (n, e) => {
14
- const l = [];
15
- e.forEach((a, d) => {
16
- if (!a.void) return;
17
- const p = new RegExp(a.pattern.source, a.pattern.flags.includes("g") ? a.pattern.flags : a.pattern.flags + "g");
18
- let u;
19
- for (; (u = p.exec(n)) !== null && u[0].length; )
20
- l.push({
21
- start: u.index,
22
- end: u.index + u[0].length,
13
+ const Z = (n) => n?.type === "token", Xe = (n, e) => {
14
+ const i = [];
15
+ e.forEach((u, d) => {
16
+ if (!u.void) return;
17
+ const h = new RegExp(u.pattern.source, u.pattern.flags.includes("g") ? u.pattern.flags : u.pattern.flags + "g");
18
+ let f;
19
+ for (; (f = h.exec(n)) !== null && f[0].length; )
20
+ i.push({
21
+ start: f.index,
22
+ end: f.index + f[0].length,
23
23
  ruleIndex: d,
24
- token: u[0],
25
- match: u
24
+ token: f[0],
25
+ match: f
26
26
  });
27
- }), l.sort((a, d) => a.start - d.start);
27
+ }), i.sort((u, d) => u.start - d.start);
28
28
  const r = [];
29
- let o = 0;
30
- return l.forEach((a) => {
31
- if (a.start < o) return;
32
- a.start > o ? r.push({
33
- text: n.slice(o, a.start)
34
- }) : r.length && X(r[r.length - 1]) && r.push({
29
+ let l = 0;
30
+ return i.forEach((u) => {
31
+ if (u.start < l) return;
32
+ u.start > l ? r.push({
33
+ text: n.slice(l, u.start)
34
+ }) : r.length && Z(r[r.length - 1]) && r.push({
35
35
  text: ""
36
36
  });
37
37
  const d = {
38
38
  type: "token",
39
- ruleIndex: a.ruleIndex,
40
- token: a.token,
41
- match: a.match,
39
+ ruleIndex: u.ruleIndex,
40
+ token: u.token,
41
+ match: u.match,
42
42
  children: [{
43
43
  text: ""
44
44
  }]
45
45
  };
46
- r.push(d), o = a.end;
47
- }), o < n.length && r.push({
48
- text: n.slice(o)
49
- }), (!r.length || X(r[0])) && r.unshift({
46
+ r.push(d), l = u.end;
47
+ }), l < n.length && r.push({
48
+ text: n.slice(l)
49
+ }), (!r.length || Z(r[0])) && r.unshift({
50
50
  text: ""
51
- }), X(r[r.length - 1]) && r.push({
51
+ }), Z(r[r.length - 1]) && r.push({
52
52
  text: ""
53
53
  }), r;
54
- }, De = (n, e) => (n || "").split(`
55
- `).map((l) => ({
54
+ }, Me = (n, e) => (n || "").split(`
55
+ `).map((i) => ({
56
56
  type: "paragraph",
57
- children: ze(l, e)
58
- })), Ee = (n) => pe.isText(n) ? n.text : X(n) ? n.token : n.children.map(Ee).join(""), Se = (n) => n.map(Ee).join(`
59
- `), Ae = Y.createContext(null), de = Y.createContext(null), oe = () => {
60
- const n = Y.useContext(Ae);
57
+ children: Xe(i, e)
58
+ })), Ae = (n) => ge.isText(n) ? n.text : Z(n) ? n.token : n.children.map(Ae).join(""), Oe = (n) => n.map(Ae).join(`
59
+ `), _e = ee.createContext(null), me = ee.createContext(null), ce = () => {
60
+ const n = ee.useContext(_e);
61
61
  if (!n)
62
62
  throw new Error("EditorInput.* components must be used inside <EditorInput>");
63
63
  return n;
64
- }, mt = (n) => {
64
+ }, It = (n) => {
65
65
  const {
66
66
  title: e,
67
- right: l,
67
+ right: i,
68
68
  left: r,
69
- rightType: o,
70
- leftType: a,
69
+ rightType: l,
70
+ leftType: u,
71
71
  description: d,
72
- wrapperComponent: p,
73
- tokenRules: u = [],
74
- onSelect: h,
75
- search: D,
76
- formValidation: b,
77
- onChange: c,
78
- disabled: N = !1,
79
- readonly: V = !1,
80
- singleLine: v = !1,
81
- placeholder: F,
82
- value: _,
83
- initialValue: j,
84
- defaultValue: k,
72
+ wrapperComponent: h,
73
+ tokenRules: f = [],
74
+ onSelect: p,
75
+ search: S,
76
+ formValidation: I,
77
+ onChange: o,
78
+ disabled: k = !1,
79
+ readonly: C = !1,
80
+ singleLine: g = !1,
81
+ placeholder: b,
82
+ value: y,
83
+ initialValue: F,
84
+ defaultValue: E,
85
85
  children: B
86
- } = n, M = String(_ ?? j ?? k ?? ""), m = v ? M.replace(/\n/g, " ") : M, i = ae(() => {
87
- const t = Le(Ne(Oe())), {
86
+ } = n, L = String(y ?? F ?? E ?? ""), x = g ? L.replace(/\n/g, " ") : L, c = de(() => {
87
+ const t = Be(Le(Ve())), {
88
88
  isInline: s,
89
- isVoid: y
89
+ isVoid: T
90
90
  } = t;
91
- return t.isInline = (C) => X(C) || s(C), t.isVoid = (C) => X(C) || y(C), t;
92
- }, []), K = ae(() => De(m, u), []), R = G(m), [$, U] = ie(m);
93
- re(() => {
94
- if (m === R.current || (R.current = m, U(m), Se(i.children) === m)) return;
95
- const t = De(m, u);
96
- fe.withoutNormalizing(i, () => {
97
- ne.deselect(i);
98
- const s = i.children.length;
99
- ne.insertNodes(i, t, {
91
+ return t.isInline = (D) => Z(D) || s(D), t.isVoid = (D) => Z(D) || T(D), t;
92
+ }, []), K = de(() => Me(x, f), []), P = W(x), [$, U] = le(x);
93
+ se(() => {
94
+ if (x === P.current || (P.current = x, U(x), Oe(c.children) === x)) return;
95
+ const t = Me(x, f);
96
+ he.withoutNormalizing(c, () => {
97
+ oe.deselect(c);
98
+ const s = c.children.length;
99
+ oe.insertNodes(c, t, {
100
100
  at: [0]
101
101
  });
102
- for (let y = 0; y < s; y++) ne.removeNodes(i, {
102
+ for (let T = 0; T < s; T++) oe.removeNodes(c, {
103
103
  at: [t.length]
104
104
  });
105
105
  });
106
106
  try {
107
- ne.select(i, fe.end(i, []));
107
+ oe.select(c, he.end(c, []));
108
108
  } catch {
109
109
  }
110
- }, [m, i, u]);
111
- const [g, W] = ie(!1), Z = G(null), z = G(null), L = G(void 0), O = T(() => {
112
- const t = z.current, s = Z.current, y = s?.parentElement;
113
- if (!t || !s || !y) return;
114
- let C = null;
110
+ }, [x, c, f]);
111
+ const [m, G] = le(!1), [H, ie] = le("shortcut"), q = W(H);
112
+ q.current = H;
113
+ const te = W(null), Q = W(null), j = W(void 0), N = O(() => {
114
+ const t = Q.current, s = te.current, T = s?.parentElement;
115
+ if (!t || !s || !T) return;
116
+ let D = null;
115
117
  try {
116
- i.selection && (C = Q.toDOMRange(i, i.selection).getBoundingClientRect());
118
+ c.selection && (D = Y.toDOMRange(c, c.selection).getBoundingClientRect());
117
119
  } catch {
118
- C = null;
120
+ D = null;
119
121
  }
120
- (!C || !C.width && !C.height && !C.left && !C.top) && (C = s.getBoundingClientRect());
121
- const we = y.getBoundingClientRect();
122
- t.style.left = `${C.left - we.left}px`, t.style.top = `${C.top - we.top}px`, t.style.width = "0px", t.style.height = `${C.height || parseFloat(getComputedStyle(s).lineHeight) || 16}px`;
123
- }, [i]), J = b?.setValue, f = T((t) => {
124
- g && O();
125
- const s = Se(t);
126
- s !== R.current && (R.current = s, U(s), J?.(s), c?.(s));
127
- }, [g, O, J, c]), P = T(() => {
128
- z.current && (L.current && clearTimeout(L.current), O(), W(!0));
129
- }, [O]);
130
- re(() => {
131
- g && O();
132
- }, [g, O]);
133
- const E = T(() => {
134
- L.current && clearTimeout(L.current), L.current = setTimeout(() => W(!1), 150);
135
- }, []), S = T(() => {
136
- L.current && clearTimeout(L.current);
137
- }, []), I = G(/* @__PURE__ */ new Map()), [A, ce] = ie(null), H = G(null), w = T((t) => {
138
- H.current = t, ce(t);
139
- }, []), [he, _e] = ie(null), ue = G(null), ee = T((t) => {
140
- ue.current = t, _e(t);
141
- }, []), ge = T((t, s) => (I.current.set(t, s), () => {
142
- I.current.delete(t), H.current === t && w(null);
143
- }), [w]), te = T(() => Array.from(I.current.entries()).filter(([, t]) => t.el.current && t.parentId === ue.current).sort((t, s) => t[1].el.current.compareDocumentPosition(s[1].el.current) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1).map(([t]) => t), []), q = T((t) => {
144
- w(t), t && I.current.get(t)?.el.current?.scrollIntoView({
122
+ (!D || !D.width && !D.height && !D.left && !D.top) && (D = s.getBoundingClientRect());
123
+ const Se = T.getBoundingClientRect();
124
+ t.style.left = `${D.left - Se.left}px`, t.style.top = `${D.top - Se.top}px`, t.style.width = "0px", t.style.height = `${D.height || parseFloat(getComputedStyle(s).lineHeight) || 16}px`;
125
+ }, [c]), X = I?.setValue, a = O((t) => {
126
+ m && N();
127
+ const s = Oe(t);
128
+ s !== P.current && (P.current = s, U(s), X?.(s), o?.(s));
129
+ }, [m, N, X, o]), V = O(() => {
130
+ Q.current && (j.current && clearTimeout(j.current), N(), G(!0));
131
+ }, [N]);
132
+ se(() => {
133
+ m && N();
134
+ }, [m, N]);
135
+ const A = O(() => {
136
+ j.current && clearTimeout(j.current), j.current = setTimeout(() => G(!1), 150);
137
+ }, []), R = O(() => {
138
+ j.current && clearTimeout(j.current);
139
+ }, []), w = W(/* @__PURE__ */ new Map()), [_, fe] = le(null), z = W(null), M = O((t) => {
140
+ z.current = t, fe(t);
141
+ }, []), [xe, Pe] = le(null), pe = W(null), ne = O((t) => {
142
+ pe.current = t, Pe(t);
143
+ }, []), ve = O((t, s) => (w.current.set(t, s), () => {
144
+ w.current.delete(t), z.current === t && M(null);
145
+ }), [M]), re = O(() => Array.from(w.current.entries()).filter(([, t]) => t.el.current && t.parentId === pe.current).sort((t, s) => t[1].el.current.compareDocumentPosition(s[1].el.current) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1).map(([t]) => t), []), J = O((t) => {
146
+ M(t), t && w.current.get(t)?.el.current?.scrollIntoView({
145
147
  block: "nearest"
146
148
  });
147
- }, [w]), me = T(() => {
148
- const t = te();
149
+ }, [M]), Ie = O(() => {
150
+ const t = re();
149
151
  if (!t.length) return;
150
- const s = H.current, y = s === null ? -1 : t.indexOf(s);
151
- q(t[Math.min(y + 1, t.length - 1)] ?? t[0]);
152
- }, [te, q]), xe = T(() => {
153
- const t = te();
152
+ const s = z.current, T = s === null ? -1 : t.indexOf(s);
153
+ J(t[Math.min(T + 1, t.length - 1)] ?? t[0]);
154
+ }, [re, J]), ye = O(() => {
155
+ const t = re();
154
156
  if (!t.length) return;
155
- const s = H.current, y = s === null ? t.length : t.indexOf(s);
156
- q(t[Math.max(y - 1, 0)] ?? t[t.length - 1]);
157
- }, [te, q]), ve = T(() => {
158
- const t = te();
159
- t.length && q(t[0]);
160
- }, [te, q]), se = T((t, s) => {
161
- h?.(t, s), W(!1);
162
- }, [h]), Ie = T(() => {
163
- const t = H.current;
157
+ const s = z.current, T = s === null ? t.length : t.indexOf(s);
158
+ J(t[Math.max(T - 1, 0)] ?? t[t.length - 1]);
159
+ }, [re, J]), Ce = O(() => {
160
+ const t = re();
161
+ t.length && J(t[0]);
162
+ }, [re, J]), ue = O((t, s) => {
163
+ p?.(t, s), q.current !== "focus" && G(!1);
164
+ }, [p]), be = O(() => {
165
+ const t = z.current;
164
166
  if (!t) return !1;
165
- const s = I.current.get(t);
166
- return s ? s.onActivate ? (s.onActivate(), !0) : (setTimeout(() => se(s.getValue(), s.getData()), 0), !0) : !1;
167
- }, [se]), ye = T((t) => {
168
- ee(t), setTimeout(() => {
169
- const s = Array.from(I.current.entries()).filter(([, y]) => y.el.current && y.parentId === t).sort((y, C) => y[1].el.current.compareDocumentPosition(C[1].el.current) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1).map(([y]) => y);
170
- s.length && q(s[0]);
167
+ const s = w.current.get(t);
168
+ return s ? s.onActivate ? (s.onActivate(), !0) : (setTimeout(() => ue(s.getValue(), s.getData()), 0), !0) : !1;
169
+ }, [ue]), we = O((t) => {
170
+ ne(t), setTimeout(() => {
171
+ const s = Array.from(w.current.entries()).filter(([, T]) => T.el.current && T.parentId === t).sort((T, D) => T[1].el.current.compareDocumentPosition(D[1].el.current) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1).map(([T]) => T);
172
+ s.length && J(s[0]);
171
173
  }, 20);
172
- }, [ee, q]), Ce = T(() => {
173
- const t = ue.current;
174
- t !== null && (ee(null), w(t));
175
- }, [ee, w]), be = T(() => {
176
- const t = H.current;
174
+ }, [ne, J]), Te = O(() => {
175
+ const t = pe.current;
176
+ t !== null && (ne(null), M(t));
177
+ }, [ne, M]), De = O(() => {
178
+ const t = z.current;
177
179
  if (!t) return !1;
178
- const s = I.current.get(t);
180
+ const s = w.current.get(t);
179
181
  return s?.onActivate ? (s.onActivate(), !0) : !1;
180
182
  }, []);
181
- re(() => {
182
- g || (w(null), ee(null));
183
- }, [g, w, ee]);
184
- const Me = ae(() => ({
185
- editor: i,
186
- tokenRules: u,
187
- singleLine: v,
188
- disabled: N,
189
- readonly: V,
190
- placeholder: F,
191
- search: D,
183
+ se(() => {
184
+ m || (M(null), ne(null));
185
+ }, [m, M, ne]);
186
+ const Ne = de(() => ({
187
+ editor: c,
188
+ tokenRules: f,
189
+ singleLine: g,
190
+ disabled: k,
191
+ readonly: C,
192
+ placeholder: b,
193
+ search: S,
192
194
  documentText: $,
193
- open: g,
194
- setOpen: W,
195
- openMenu: P,
196
- editorContainerRef: Z,
197
- triggerRef: z,
198
- updateTriggerPosition: O,
199
- scheduleClose: E,
200
- cancelClose: S,
201
- registerItem: ge,
202
- activeId: A,
203
- setActiveId: w,
204
- highlightNext: me,
205
- highlightPrevious: xe,
206
- focusFirst: ve,
207
- selectActive: Ie,
208
- select: se,
209
- openSubId: he,
210
- enterSub: ye,
211
- exitSub: Ce,
212
- openActiveSub: be
213
- }), [i, u, v, N, V, F, D, $, g, P, O, E, S, ge, A, w, me, xe, ve, Ie, se, he, ye, Ce, be]);
214
- return /* @__PURE__ */ x(Ve, { editor: i, initialValue: K, onChange: f, children: /* @__PURE__ */ x(Ae.Provider, { value: Me, children: /* @__PURE__ */ x(je, { open: g, modal: !1, onOpenChange: (t) => !t && W(!1), children: /* @__PURE__ */ x($e, { title: e, description: d, right: l, left: r, rightType: o, leftType: a, formValidation: b, ...p ?? {}, style: {
195
+ open: m,
196
+ setOpen: G,
197
+ openMenu: V,
198
+ menuOpenMode: H,
199
+ setMenuOpenMode: ie,
200
+ editorContainerRef: te,
201
+ triggerRef: Q,
202
+ updateTriggerPosition: N,
203
+ scheduleClose: A,
204
+ cancelClose: R,
205
+ registerItem: ve,
206
+ activeId: _,
207
+ setActiveId: M,
208
+ highlightNext: Ie,
209
+ highlightPrevious: ye,
210
+ focusFirst: Ce,
211
+ selectActive: be,
212
+ select: ue,
213
+ openSubId: xe,
214
+ enterSub: we,
215
+ exitSub: Te,
216
+ openActiveSub: De
217
+ }), [c, f, g, k, C, b, S, $, m, V, H, N, A, R, ve, _, M, Ie, ye, Ce, be, ue, xe, we, Te, De]);
218
+ return /* @__PURE__ */ v($e, { editor: c, initialValue: K, onChange: a, children: /* @__PURE__ */ v(_e.Provider, { value: Ne, children: /* @__PURE__ */ v(Ue, { open: m, modal: !1, onOpenChange: (t) => !t && G(!1), children: /* @__PURE__ */ v(Ke, { title: e, description: d, right: i, left: r, rightType: l, leftType: u, formValidation: I, ...h ?? {}, style: {
215
219
  position: "relative",
216
- ...p?.style
220
+ ...h?.style
217
221
  }, children: B }) }) }) });
218
- }, xt = (n) => {
219
- const e = le.c(40), {
220
- editor: l,
222
+ }, yt = (n) => {
223
+ const e = ae.c(44), {
224
+ editor: i,
221
225
  tokenRules: r,
222
- singleLine: o,
223
- disabled: a,
226
+ singleLine: l,
227
+ disabled: u,
224
228
  readonly: d,
225
- placeholder: p,
226
- open: u,
227
- openMenu: h,
228
- setOpen: D,
229
- editorContainerRef: b,
230
- scheduleClose: c,
231
- cancelClose: N,
232
- highlightNext: V,
233
- highlightPrevious: v,
234
- focusFirst: F,
235
- selectActive: _,
236
- openSubId: j,
237
- exitSub: k,
238
- openActiveSub: B
239
- } = oe();
240
- let M;
241
- e[0] !== r ? (M = (f) => {
242
- const [P, E] = f, S = [];
243
- if (!pe.isText(P) || !r.length)
244
- return S;
229
+ placeholder: h,
230
+ open: f,
231
+ openMenu: p,
232
+ setOpen: S,
233
+ menuOpenMode: I,
234
+ editorContainerRef: o,
235
+ scheduleClose: k,
236
+ cancelClose: C,
237
+ highlightNext: g,
238
+ highlightPrevious: b,
239
+ focusFirst: y,
240
+ selectActive: F,
241
+ openSubId: E,
242
+ exitSub: B,
243
+ openActiveSub: L
244
+ } = ce();
245
+ let x;
246
+ e[0] !== C || e[1] !== I || e[2] !== p ? (x = () => {
247
+ C(), I === "focus" && p();
248
+ }, e[0] = C, e[1] = I, e[2] = p, e[3] = x) : x = e[3];
249
+ const c = x;
250
+ let K;
251
+ e[4] !== r ? (K = (a) => {
252
+ const [V, A] = a, R = [];
253
+ if (!ge.isText(V) || !r.length)
254
+ return R;
245
255
  const {
246
- text: I
247
- } = P;
248
- return r.forEach((A, ce) => {
249
- if (A.void)
256
+ text: w
257
+ } = V;
258
+ return r.forEach((_, fe) => {
259
+ if (_.void)
250
260
  return;
251
- const H = new RegExp(A.pattern.source, A.pattern.flags.includes("g") ? A.pattern.flags : A.pattern.flags + "g");
252
- let w;
253
- for (; (w = H.exec(I)) !== null && w[0].length; )
254
- S.push({
261
+ const z = new RegExp(_.pattern.source, _.pattern.flags.includes("g") ? _.pattern.flags : _.pattern.flags + "g");
262
+ let M;
263
+ for (; (M = z.exec(w)) !== null && M[0].length; )
264
+ R.push({
255
265
  anchor: {
256
- path: E,
257
- offset: w.index
266
+ path: A,
267
+ offset: M.index
258
268
  },
259
269
  focus: {
260
- path: E,
261
- offset: w.index + w[0].length
270
+ path: A,
271
+ offset: M.index + M[0].length
262
272
  },
263
- tokenRuleIndex: ce,
264
- tokenText: w[0],
265
- tokenMatch: w
273
+ tokenRuleIndex: fe,
274
+ tokenText: M[0],
275
+ tokenMatch: M
266
276
  });
267
- }), S;
268
- }, e[0] = r, e[1] = M) : M = e[1];
269
- const m = M;
270
- let i;
271
- e[2] !== r ? (i = (f) => {
277
+ }), R;
278
+ }, e[4] = r, e[5] = K) : K = e[5];
279
+ const P = K;
280
+ let $;
281
+ e[6] !== r ? ($ = (a) => {
272
282
  const {
273
- attributes: P,
274
- children: E,
275
- leaf: S
276
- } = f, I = S;
277
- if (I.tokenRuleIndex !== void 0) {
278
- const A = r[I.tokenRuleIndex];
279
- if (A)
280
- return A.wrap ? /* @__PURE__ */ x("span", { ...P, children: A.wrap(I.tokenText ?? "", E, I.tokenMatch ?? []) }) : /* @__PURE__ */ x("span", { ...P, children: /* @__PURE__ */ x("span", { style: A.style, className: A.className, children: E }) });
283
+ attributes: V,
284
+ children: A,
285
+ leaf: R
286
+ } = a, w = R;
287
+ if (w.tokenRuleIndex !== void 0) {
288
+ const _ = r[w.tokenRuleIndex];
289
+ if (_)
290
+ return _.wrap ? /* @__PURE__ */ v("span", { ...V, children: _.wrap(w.tokenText ?? "", A, w.tokenMatch ?? []) }) : /* @__PURE__ */ v("span", { ...V, children: /* @__PURE__ */ v("span", { style: _.style, className: _.className, children: A }) });
281
291
  }
282
- return /* @__PURE__ */ x("span", { ...P, children: E });
283
- }, e[2] = r, e[3] = i) : i = e[3];
284
- const K = i;
285
- let R;
286
- e[4] !== r ? (R = (f) => {
292
+ return /* @__PURE__ */ v("span", { ...V, children: A });
293
+ }, e[6] = r, e[7] = $) : $ = e[7];
294
+ const U = $;
295
+ let m;
296
+ e[8] !== r ? (m = (a) => {
287
297
  const {
288
- attributes: P,
289
- children: E,
290
- element: S
291
- } = f;
292
- if (X(S)) {
293
- const I = r[S.ruleIndex], A = I?.wrap ? I.wrap(S.token, null, S.match ?? []) : /* @__PURE__ */ x("span", { style: I?.style, className: I?.className, children: S.token });
294
- return /* @__PURE__ */ ke("span", { ...P, children: [
295
- /* @__PURE__ */ x("span", { contentEditable: !1, className: "editor-input__token", style: {
298
+ attributes: V,
299
+ children: A,
300
+ element: R
301
+ } = a;
302
+ if (Z(R)) {
303
+ const w = r[R.ruleIndex], _ = w?.wrap ? w.wrap(R.token, null, R.match ?? []) : /* @__PURE__ */ v("span", { style: w?.style, className: w?.className, children: R.token });
304
+ return /* @__PURE__ */ Re("span", { ...V, children: [
305
+ /* @__PURE__ */ v("span", { contentEditable: !1, className: "editor-input__token", style: {
296
306
  userSelect: "none"
297
- }, children: A }),
298
- E
307
+ }, children: _ }),
308
+ A
299
309
  ] });
300
310
  }
301
- return /* @__PURE__ */ x("div", { ...P, style: {
311
+ return /* @__PURE__ */ v("div", { ...V, style: {
302
312
  position: "relative"
303
- }, children: E });
304
- }, e[4] = r, e[5] = R) : R = e[5];
305
- const $ = R;
306
- let U;
307
- e[6] !== l || e[7] !== k || e[8] !== F || e[9] !== V || e[10] !== v || e[11] !== u || e[12] !== B || e[13] !== h || e[14] !== j || e[15] !== _ || e[16] !== D || e[17] !== o || e[18] !== r ? (U = (f) => {
308
- if (o && f.key === "Enter" && f.preventDefault(), f.ctrlKey && f.code === "Space") {
309
- f.preventDefault(), u ? F() : h();
313
+ }, children: A });
314
+ }, e[8] = r, e[9] = m) : m = e[9];
315
+ const G = m;
316
+ let H;
317
+ e[10] !== i || e[11] !== B || e[12] !== y || e[13] !== g || e[14] !== b || e[15] !== f || e[16] !== L || e[17] !== p || e[18] !== E || e[19] !== F || e[20] !== S || e[21] !== l || e[22] !== r ? (H = (a) => {
318
+ if (l && a.key === "Enter" && a.preventDefault(), a.ctrlKey && a.code === "Space") {
319
+ a.preventDefault(), f ? y() : p();
310
320
  return;
311
321
  }
312
- if (u) {
313
- if (f.key === "ArrowDown") {
314
- f.preventDefault(), V();
322
+ if (f) {
323
+ if (a.key === "ArrowDown") {
324
+ a.preventDefault(), g();
315
325
  return;
316
326
  }
317
- if (f.key === "ArrowUp") {
318
- f.preventDefault(), v();
327
+ if (a.key === "ArrowUp") {
328
+ a.preventDefault(), b();
319
329
  return;
320
330
  }
321
- if (f.key === "ArrowRight" && B()) {
322
- f.preventDefault();
331
+ if (a.key === "ArrowRight" && L()) {
332
+ a.preventDefault();
323
333
  return;
324
334
  }
325
- if (f.key === "ArrowLeft" && j !== null) {
326
- f.preventDefault(), k();
335
+ if (a.key === "ArrowLeft" && E !== null) {
336
+ a.preventDefault(), B();
327
337
  return;
328
338
  }
329
- if (f.key === "Enter") {
330
- _() && f.preventDefault();
339
+ if (a.key === "Enter") {
340
+ F() && a.preventDefault();
331
341
  return;
332
342
  }
333
- if (f.key === "Escape") {
334
- f.preventDefault(), j !== null ? k() : D(!1);
343
+ if (a.key === "Escape") {
344
+ a.preventDefault(), E !== null ? B() : S(!1);
335
345
  return;
336
346
  }
337
347
  }
338
- if ((f.key === "ArrowLeft" || f.key === "ArrowRight") && !f.shiftKey && r.some(Je) && l.selection && Te.isCollapsed(l.selection)) {
339
- f.preventDefault();
340
- const P = f.key === "ArrowLeft";
341
- ne.move(l, {
348
+ if ((a.key === "ArrowLeft" || a.key === "ArrowRight") && !a.shiftKey && r.some(Ye) && i.selection && ke.isCollapsed(i.selection)) {
349
+ a.preventDefault();
350
+ const V = a.key === "ArrowLeft";
351
+ oe.move(i, {
342
352
  unit: "offset",
343
- reverse: P
353
+ reverse: V
344
354
  });
345
- const E = l.selection;
346
- if (E && Te.isCollapsed(E)) {
347
- const S = Pe.parent(l, E.anchor.path);
348
- !pe.isText(S) && fe.isVoid(l, S) && ne.move(l, {
355
+ const A = i.selection;
356
+ if (A && ke.isCollapsed(A)) {
357
+ const R = Fe.parent(i, A.anchor.path);
358
+ !ge.isText(R) && he.isVoid(i, R) && oe.move(i, {
349
359
  unit: "offset",
350
- reverse: P
360
+ reverse: V
351
361
  });
352
362
  }
353
363
  }
354
- }, e[6] = l, e[7] = k, e[8] = F, e[9] = V, e[10] = v, e[11] = u, e[12] = B, e[13] = h, e[14] = j, e[15] = _, e[16] = D, e[17] = o, e[18] = r, e[19] = U) : U = e[19];
355
- const g = U;
356
- let W;
357
- e[20] !== n ? (W = Re("editor-input", n), e[20] = n, e[21] = W) : W = e[21];
358
- const Z = o ? "input-wrapper__control input-wrapper__control--single-line" : "input-wrapper__control", z = a || d;
359
- let L;
360
- e[22] !== l || e[23] !== o ? (L = o ? (f) => {
361
- f.preventDefault(), l.insertText(f.clipboardData.getData("text/plain").replace(/\r?\n/g, " "));
362
- } : void 0, e[22] = l, e[23] = o, e[24] = L) : L = e[24];
363
- let O;
364
- e[25] !== N || e[26] !== m || e[27] !== g || e[28] !== p || e[29] !== $ || e[30] !== K || e[31] !== c || e[32] !== Z || e[33] !== z || e[34] !== L ? (O = /* @__PURE__ */ x(Fe, { className: Z, decorate: m, renderLeaf: K, renderElement: $, readOnly: z, spellCheck: !1, placeholder: p, onBlur: c, onFocus: N, onKeyDown: g, onPaste: L }), e[25] = N, e[26] = m, e[27] = g, e[28] = p, e[29] = $, e[30] = K, e[31] = c, e[32] = Z, e[33] = z, e[34] = L, e[35] = O) : O = e[35];
365
- let J;
366
- return e[36] !== b || e[37] !== W || e[38] !== O ? (J = /* @__PURE__ */ x("div", { ...W, ref: b, children: O }), e[36] = b, e[37] = W, e[38] = O, e[39] = J) : J = e[39], J;
367
- }, vt = (n) => {
368
- const e = le.c(5), {
369
- triggerRef: l
370
- } = oe();
364
+ }, e[10] = i, e[11] = B, e[12] = y, e[13] = g, e[14] = b, e[15] = f, e[16] = L, e[17] = p, e[18] = E, e[19] = F, e[20] = S, e[21] = l, e[22] = r, e[23] = H) : H = e[23];
365
+ const ie = H;
366
+ let q;
367
+ e[24] !== n ? (q = Ee("editor-input", n), e[24] = n, e[25] = q) : q = e[25];
368
+ const te = l ? "input-wrapper__control input-wrapper__control--single-line" : "input-wrapper__control", Q = u || d;
369
+ let j;
370
+ e[26] !== i || e[27] !== l ? (j = l ? (a) => {
371
+ a.preventDefault(), i.insertText(a.clipboardData.getData("text/plain").replace(/\r?\n/g, " "));
372
+ } : void 0, e[26] = i, e[27] = l, e[28] = j) : j = e[28];
373
+ let N;
374
+ e[29] !== P || e[30] !== c || e[31] !== ie || e[32] !== h || e[33] !== G || e[34] !== U || e[35] !== k || e[36] !== te || e[37] !== Q || e[38] !== j ? (N = /* @__PURE__ */ v(je, { className: te, decorate: P, renderLeaf: U, renderElement: G, readOnly: Q, spellCheck: !1, placeholder: h, onBlur: k, onFocus: c, onKeyDown: ie, onPaste: j }), e[29] = P, e[30] = c, e[31] = ie, e[32] = h, e[33] = G, e[34] = U, e[35] = k, e[36] = te, e[37] = Q, e[38] = j, e[39] = N) : N = e[39];
375
+ let X;
376
+ return e[40] !== o || e[41] !== q || e[42] !== N ? (X = /* @__PURE__ */ v("div", { ...q, ref: o, children: N }), e[40] = o, e[41] = q, e[42] = N, e[43] = X) : X = e[43], X;
377
+ }, Ct = (n) => {
378
+ const e = ae.c(5), {
379
+ triggerRef: i
380
+ } = ce();
371
381
  let r;
372
- e[0] !== n ? (r = Re("editor-input__menu-anchor", n), e[0] = n, e[1] = r) : r = e[1];
373
- let o;
374
- return e[2] !== r || e[3] !== l ? (o = /* @__PURE__ */ x(Ge, { asChild: !0, children: /* @__PURE__ */ x("button", { ref: l, type: "button", tabIndex: -1, "aria-hidden": !0, onMouseDown: Qe, ...r }) }), e[2] = r, e[3] = l, e[4] = o) : o = e[4], o;
375
- }, It = (n) => {
376
- const e = le.c(16), {
377
- editor: l,
378
- editorContainerRef: r
379
- } = oe();
380
- let o, a;
382
+ e[0] !== n ? (r = Ee("editor-input__menu-anchor", n), e[0] = n, e[1] = r) : r = e[1];
383
+ let l;
384
+ return e[2] !== r || e[3] !== i ? (l = /* @__PURE__ */ v(ze, { asChild: !0, children: /* @__PURE__ */ v("button", { ref: i, type: "button", tabIndex: -1, "aria-hidden": !0, onMouseDown: Ze, ...r }) }), e[2] = r, e[3] = i, e[4] = l) : l = e[4], l;
385
+ }, bt = (n) => {
386
+ const e = ae.c(21), {
387
+ editor: i,
388
+ editorContainerRef: r,
389
+ setMenuOpenMode: l
390
+ } = ce();
391
+ let u, d, h;
381
392
  e[0] !== n ? ({
382
- children: o,
383
- ...a
384
- } = n, e[0] = n, e[1] = o, e[2] = a) : (o = e[1], a = e[2]);
385
- let d, p;
386
- e[3] !== l ? (d = (c) => {
387
- c.preventDefault(), Q.focus(l);
388
- }, p = () => Q.focus(l), e[3] = l, e[4] = d, e[5] = p) : (d = e[4], p = e[5]);
389
- let u;
390
- e[6] !== r ? (u = (c) => {
391
- const N = c.target;
392
- N && r.current?.contains(N) && c.preventDefault();
393
- }, e[6] = r, e[7] = u) : u = e[7];
394
- let h;
395
- e[8] !== a || e[9] !== d || e[10] !== p || e[11] !== u ? (h = {
393
+ children: u,
394
+ openOn: h,
395
+ ...d
396
+ } = n, e[0] = n, e[1] = u, e[2] = d, e[3] = h) : (u = e[1], d = e[2], h = e[3]);
397
+ const f = h === void 0 ? "shortcut" : h;
398
+ let p, S;
399
+ e[4] !== f || e[5] !== l ? (p = () => l(f), S = [f, l], e[4] = f, e[5] = l, e[6] = p, e[7] = S) : (p = e[6], S = e[7]), se(p, S);
400
+ let I, o;
401
+ e[8] !== i ? (I = (y) => {
402
+ y.preventDefault(), Y.focus(i);
403
+ }, o = () => Y.focus(i), e[8] = i, e[9] = I, e[10] = o) : (I = e[9], o = e[10]);
404
+ let k;
405
+ e[11] !== r ? (k = (y) => {
406
+ const F = y.target;
407
+ F && r.current?.contains(F) && y.preventDefault();
408
+ }, e[11] = r, e[12] = k) : k = e[12];
409
+ let C;
410
+ e[13] !== d || e[14] !== I || e[15] !== o || e[16] !== k ? (C = {
396
411
  color: "primary",
397
412
  align: "start",
398
413
  sideOffset: 8,
399
- onContextMenuCapture: Xe,
400
- onCloseAutoFocus: Ye,
401
- onOpenAutoFocus: d,
402
- onFocusCapture: p,
403
- onInteractOutside: u,
404
- ...a
405
- }, e[8] = a, e[9] = d, e[10] = p, e[11] = u, e[12] = h) : h = e[12];
406
- const D = h;
414
+ onContextMenuCapture: et,
415
+ onCloseAutoFocus: tt,
416
+ onOpenAutoFocus: I,
417
+ onFocusCapture: o,
418
+ onInteractOutside: k,
419
+ ...d
420
+ }, e[13] = d, e[14] = I, e[15] = o, e[16] = k, e[17] = C) : C = e[17];
421
+ const g = C;
407
422
  let b;
408
- return e[13] !== o || e[14] !== D ? (b = /* @__PURE__ */ x(Be, { children: /* @__PURE__ */ x(Ke, { ...D, children: o }) }), e[13] = o, e[14] = D, e[15] = b) : b = e[15], b;
409
- }, yt = (n) => {
423
+ return e[18] !== u || e[19] !== g ? (b = /* @__PURE__ */ v(We, { children: /* @__PURE__ */ v(Ge, { ...g, children: u }) }), e[18] = u, e[19] = g, e[20] = b) : b = e[20], b;
424
+ }, wt = (n) => {
410
425
  const {
411
426
  value: e,
412
- data: l,
427
+ data: i,
413
428
  children: r,
414
- onlyOnce: o,
415
- aliases: a,
429
+ onlyOnce: l,
430
+ aliases: u,
416
431
  ...d
417
432
  } = n, {
418
- editor: p,
419
- registerItem: u,
420
- activeId: h,
421
- setActiveId: D,
422
- select: b,
423
- search: c,
424
- documentText: N
425
- } = oe(), V = Y.useContext(de), v = Y.useId(), F = G(null), _ = G({
433
+ editor: h,
434
+ registerItem: f,
435
+ activeId: p,
436
+ setActiveId: S,
437
+ select: I,
438
+ search: o,
439
+ documentText: k
440
+ } = ce(), C = ee.useContext(me), g = ee.useId(), b = W(null), y = W({
426
441
  value: e,
427
- data: l
442
+ data: i
428
443
  });
429
- _.current = {
444
+ y.current = {
430
445
  value: e,
431
- data: l
446
+ data: i
432
447
  };
433
- const j = !!o && N.includes(String(e)), k = c?.trim().toLowerCase() ?? "", B = !k || [typeof r == "string" ? r : String(e), ...a ?? []].some((i) => i.toLowerCase().includes(k)), M = j || !B;
434
- return re(() => {
435
- if (!M)
436
- return u(v, {
437
- getValue: () => _.current.value,
438
- getData: () => _.current.data,
439
- el: F,
440
- parentId: V
448
+ const F = !!l && k.includes(String(e)), E = o?.trim().toLowerCase() ?? "", B = !E || [typeof r == "string" ? r : String(e), ...u ?? []].some((c) => c.toLowerCase().includes(E)), L = F || !B;
449
+ return se(() => {
450
+ if (!L)
451
+ return f(g, {
452
+ getValue: () => y.current.value,
453
+ getData: () => y.current.data,
454
+ el: b,
455
+ parentId: C
441
456
  });
442
- }, [v, u, V, M]), M ? null : /* @__PURE__ */ x(Ue, { ...d, ref: (i) => {
443
- F.current = i;
444
- }, textValue: "", "data-focus": h === v || void 0, onPointerDown: (i) => {
445
- i.preventDefault(), D(v), Q.focus(p);
446
- }, onPointerMove: (i) => {
447
- i.preventDefault(), i.stopPropagation(), h !== v && D(v);
448
- }, onSelect: () => setTimeout(() => b(_.current.value, _.current.data), 0), children: r });
449
- }, Ct = (n) => {
450
- const e = le.c(38), {
451
- label: l,
457
+ }, [g, f, C, L]), L ? null : /* @__PURE__ */ v(He, { ...d, ref: (c) => {
458
+ b.current = c;
459
+ }, textValue: "", "data-focus": p === g || void 0, onPointerDown: (c) => {
460
+ c.preventDefault(), S(g), Y.focus(h);
461
+ }, onPointerMove: (c) => {
462
+ c.preventDefault(), c.stopPropagation(), p !== g && S(g);
463
+ }, onSelect: () => setTimeout(() => I(y.current.value, y.current.data), 0), children: r });
464
+ }, Tt = (n) => {
465
+ const e = ae.c(38), {
466
+ label: i,
452
467
  children: r
453
468
  } = n, {
454
- editor: o,
455
- registerItem: a,
469
+ editor: l,
470
+ registerItem: u,
456
471
  activeId: d,
457
- setActiveId: p,
458
- openSubId: u,
459
- enterSub: h,
460
- exitSub: D
461
- } = oe(), b = Y.useContext(de), c = Y.useId(), N = G(null);
462
- let V, v;
463
- e[0] !== h || e[1] !== c || e[2] !== b || e[3] !== a ? (V = () => a(c, {
464
- getValue: Ze,
465
- getData: et,
466
- el: N,
467
- parentId: b,
468
- onActivate: () => h(c)
469
- }), v = [c, a, b, h], e[0] = h, e[1] = c, e[2] = b, e[3] = a, e[4] = V, e[5] = v) : (V = e[4], v = e[5]), re(V, v);
470
- let F;
471
- e[6] !== o ? (F = {
472
- onOpenAutoFocus: (g) => {
473
- g.preventDefault(), Q.focus(o);
472
+ setActiveId: h,
473
+ openSubId: f,
474
+ enterSub: p,
475
+ exitSub: S
476
+ } = ce(), I = ee.useContext(me), o = ee.useId(), k = W(null);
477
+ let C, g;
478
+ e[0] !== p || e[1] !== o || e[2] !== I || e[3] !== u ? (C = () => u(o, {
479
+ getValue: nt,
480
+ getData: rt,
481
+ el: k,
482
+ parentId: I,
483
+ onActivate: () => p(o)
484
+ }), g = [o, u, I, p], e[0] = p, e[1] = o, e[2] = I, e[3] = u, e[4] = C, e[5] = g) : (C = e[4], g = e[5]), se(C, g);
485
+ let b;
486
+ e[6] !== l ? (b = {
487
+ onOpenAutoFocus: (m) => {
488
+ m.preventDefault(), Y.focus(l);
474
489
  },
475
- onFocusCapture: () => Q.focus(o),
476
- onCloseAutoFocus: tt,
477
- onFocusOutside: nt,
478
- onInteractOutside: rt
479
- }, e[6] = o, e[7] = F) : F = e[7];
480
- const _ = F, j = u === c;
481
- let k;
482
- e[8] !== h || e[9] !== D || e[10] !== c || e[11] !== u ? (k = (g) => {
483
- g && u !== c ? h(c) : !g && u === c && D();
484
- }, e[8] = h, e[9] = D, e[10] = c, e[11] = u, e[12] = k) : k = e[12];
490
+ onFocusCapture: () => Y.focus(l),
491
+ onCloseAutoFocus: ot,
492
+ onFocusOutside: st,
493
+ onInteractOutside: it
494
+ }, e[6] = l, e[7] = b) : b = e[7];
495
+ const y = b, F = f === o;
496
+ let E;
497
+ e[8] !== p || e[9] !== S || e[10] !== o || e[11] !== f ? (E = (m) => {
498
+ m && f !== o ? p(o) : !m && f === o && S();
499
+ }, e[8] = p, e[9] = S, e[10] = o, e[11] = f, e[12] = E) : E = e[12];
485
500
  let B;
486
- e[13] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (B = (g) => {
487
- N.current = g;
501
+ e[13] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (B = (m) => {
502
+ k.current = m;
488
503
  }, e[13] = B) : B = e[13];
489
- const M = d === c || void 0;
490
- let m;
491
- e[14] !== o || e[15] !== c || e[16] !== p ? (m = (g) => {
492
- g.preventDefault(), p(c), Q.focus(o);
493
- }, e[14] = o, e[15] = c, e[16] = p, e[17] = m) : m = e[17];
494
- let i;
495
- e[18] !== d || e[19] !== c || e[20] !== p ? (i = () => {
496
- d !== c && p(c);
497
- }, e[18] = d, e[19] = c, e[20] = p, e[21] = i) : i = e[21];
504
+ const L = d === o || void 0;
505
+ let x;
506
+ e[14] !== l || e[15] !== o || e[16] !== h ? (x = (m) => {
507
+ m.preventDefault(), h(o), Y.focus(l);
508
+ }, e[14] = l, e[15] = o, e[16] = h, e[17] = x) : x = e[17];
509
+ let c;
510
+ e[18] !== d || e[19] !== o || e[20] !== h ? (c = () => {
511
+ d !== o && h(o);
512
+ }, e[18] = d, e[19] = o, e[20] = h, e[21] = c) : c = e[21];
498
513
  let K;
499
- e[22] !== l || e[23] !== M || e[24] !== m || e[25] !== i ? (K = /* @__PURE__ */ x(He, { ref: B, "data-focus": M, onPointerDown: m, onPointerMove: i, children: l }), e[22] = l, e[23] = M, e[24] = m, e[25] = i, e[26] = K) : K = e[26];
500
- let R;
501
- e[27] !== r || e[28] !== c ? (R = /* @__PURE__ */ x(de.Provider, { value: c, children: r }), e[27] = r, e[28] = c, e[29] = R) : R = e[29];
514
+ e[22] !== i || e[23] !== L || e[24] !== x || e[25] !== c ? (K = /* @__PURE__ */ v(Je, { ref: B, "data-focus": L, onPointerDown: x, onPointerMove: c, children: i }), e[22] = i, e[23] = L, e[24] = x, e[25] = c, e[26] = K) : K = e[26];
515
+ let P;
516
+ e[27] !== r || e[28] !== o ? (P = /* @__PURE__ */ v(me.Provider, { value: o, children: r }), e[27] = r, e[28] = o, e[29] = P) : P = e[29];
502
517
  let $;
503
- e[30] !== _ || e[31] !== R ? ($ = /* @__PURE__ */ x(We, { color: "primary", ..._, children: R }), e[30] = _, e[31] = R, e[32] = $) : $ = e[32];
518
+ e[30] !== y || e[31] !== P ? ($ = /* @__PURE__ */ v(qe, { color: "primary", ...y, children: P }), e[30] = y, e[31] = P, e[32] = $) : $ = e[32];
504
519
  let U;
505
- return e[33] !== K || e[34] !== $ || e[35] !== j || e[36] !== k ? (U = /* @__PURE__ */ ke(qe, { open: j, onOpenChange: k, children: [
520
+ return e[33] !== K || e[34] !== $ || e[35] !== F || e[36] !== E ? (U = /* @__PURE__ */ Re(Qe, { open: F, onOpenChange: E, children: [
506
521
  K,
507
522
  $
508
- ] }), e[33] = K, e[34] = $, e[35] = j, e[36] = k, e[37] = U) : U = e[37], U;
523
+ ] }), e[33] = K, e[34] = $, e[35] = F, e[36] = E, e[37] = U) : U = e[37], U;
509
524
  };
510
- function Je(n) {
525
+ function Ye(n) {
511
526
  return n.void;
512
527
  }
513
- function Qe(n) {
528
+ function Ze(n) {
514
529
  return n.preventDefault();
515
530
  }
516
- function Xe(n) {
531
+ function et(n) {
517
532
  return n.stopPropagation();
518
533
  }
519
- function Ye(n) {
534
+ function tt(n) {
520
535
  return n.preventDefault();
521
536
  }
522
- function Ze() {
537
+ function nt() {
523
538
  }
524
- function et() {
539
+ function rt() {
525
540
  }
526
- function tt(n) {
541
+ function ot(n) {
527
542
  return n.preventDefault();
528
543
  }
529
- function nt(n) {
544
+ function st(n) {
530
545
  return n.preventDefault();
531
546
  }
532
- function rt(n) {
547
+ function it(n) {
533
548
  return n.preventDefault();
534
549
  }
535
550
  export {
536
- mt as EditorInput,
537
- It as EditorInputMenu,
538
- yt as EditorInputMenuItem,
539
- Ct as EditorInputSubMenu,
540
- vt as EditorInputTrigger,
541
- xt as EditorInputValue
551
+ It as EditorInput,
552
+ bt as EditorInputMenu,
553
+ wt as EditorInputMenuItem,
554
+ Tt as EditorInputSubMenu,
555
+ Ct as EditorInputTrigger,
556
+ yt as EditorInputValue
542
557
  };
@@ -1,5 +1,5 @@
1
1
  import { default as React } from 'react';
2
- import { EditorInputMenuProps, EditorInputSubMenuProps, EditorInputTriggerProps, EditorInputValueProps, EditorInputMenuItemProps } from './EditorInput';
2
+ import { EditorInputMenuProps, EditorInputSubMenuProps, EditorInputTriggerProps, EditorInputValueProps, EditorTokenRule, EditorInputMenuItemProps } from './EditorInput';
3
3
  import { InputWrapperProps } from './InputWrapper';
4
4
  import { ValidationProps } from './useForm';
5
5
  export interface TagValue {
@@ -14,7 +14,14 @@ export interface TagSuggestion {
14
14
  export interface TagInputProps extends Omit<InputWrapperProps, "onChange">, ValidationProps<any> {
15
15
  allowCustomValues?: boolean;
16
16
  onChange?: (tags: TagValue[]) => void;
17
- tagColor?: string;
17
+ /**
18
+ * Defines how a tag is rendered as a chip inside the input. Each rule's
19
+ * `pattern` is matched against the tag's value; the first match decides the
20
+ * chip via its `wrap`/`style`/`className`. Tags with no matching rule fall
21
+ * back to a plain badge. The chip rendering is token-defined only — a menu
22
+ * item's `children` is never reused here.
23
+ */
24
+ tokenRules?: EditorTokenRule[];
18
25
  children?: React.ReactNode;
19
26
  }
20
27
  export type TagInputTriggerProps = EditorInputTriggerProps;
@@ -1,117 +1,124 @@
1
- import { jsx as l, Fragment as b } from "react/jsx-runtime";
1
+ import { jsx as l } from "react/jsx-runtime";
2
2
  import { c as I } from "../../_virtual/compiler-runtime.js";
3
- import K, { useState as N, useRef as V, useReducer as j, useCallback as A, useEffect as _, useMemo as B, useContext as F } from "react";
4
- import { EditorInput as L, EditorInputMenu as U, EditorInputMenuItem as q, EditorInputSubMenu as z, EditorInputTrigger as G, EditorInputValue as H } from "./EditorInput.js";
3
+ import b, { useState as K, useRef as k, useReducer as j, useCallback as A, useEffect as v, useMemo as B, useContext as L } from "react";
4
+ import { EditorInput as U, EditorInputMenu as q, EditorInputMenuItem as z, EditorInputSubMenu as F, EditorInputTrigger as G, EditorInputValue as H } from "./EditorInput.js";
5
5
  import { Badge as J } from "../badge/Badge.js";
6
- import { Text as Q } from "../text/Text.js";
7
- const h = "⟦", d = "⟧", k = new RegExp(`${h}([^${d}]+)${d}`, "g"), W = new RegExp(`(${h}[^${d}]+${d})|([^${h}${d}]+)`, "g"), w = (e) => `${h}${String(e)}${d}`, X = (e) => e.slice(h.length, -d.length), R = (e) => e.map((t) => w(t.value)).join(""), Y = (e) => e.replace(k, "").trim(), Z = (e, t) => {
6
+ import { Text as $ } from "../text/Text.js";
7
+ const E = "⟦", d = "⟧", R = new RegExp(`${E}([^${d}]+)${d}`, "g"), Q = new RegExp(`(${E}[^${d}]+${d})|([^${E}${d}]+)`, "g"), V = (t) => `${E}${String(t)}${d}`, W = (t) => t.slice(E.length, -d.length), y = (t) => t.map((e) => V(e.value)).join(""), X = (t) => t.replace(R, "").trim(), Y = (t, e) => {
8
8
  let n = !1;
9
- const r = e.replace(W, (s, o, c) => o || (!n && c.trim() ? (n = !0, t) : ""));
10
- return n ? r : r + t;
11
- }, v = K.createContext(null), y = () => {
12
- const e = F(v);
13
- if (!e)
9
+ const r = t.replace(Q, (a, o, c) => o || (!n && c.trim() ? (n = !0, e) : ""));
10
+ return n ? r : r + e;
11
+ }, _ = b.createContext(null), D = () => {
12
+ const t = L(_);
13
+ if (!t)
14
14
  throw new Error("TagInput.* components must be used inside <TagInput>");
15
- return e;
16
- }, ct = (e) => {
15
+ return t;
16
+ }, se = (t) => {
17
17
  const {
18
- allowCustomValues: t = !1,
18
+ allowCustomValues: e = !1,
19
19
  onChange: n,
20
20
  formValidation: r,
21
- tagColor: s = "primary",
21
+ tokenRules: a,
22
22
  value: o,
23
23
  initialValue: c,
24
- defaultValue: f,
25
- children: p,
26
- ...g
27
- } = e, u = o ?? c ?? f, [i, M] = N(() => R(u ?? [])), E = V(/* @__PURE__ */ new Map()), [, D] = j((a) => a + 1, 0), O = A((a, m) => {
28
- E.current.set(a, m), D();
29
- }, []), $ = V(u), S = (a) => {
30
- const m = [...a.matchAll(k)].map(([, T]) => {
31
- const C = E.current.get(T);
24
+ defaultValue: T,
25
+ children: h,
26
+ ...p
27
+ } = t, i = o ?? c ?? T, [g, C] = K(() => y(i ?? [])), M = k(/* @__PURE__ */ new Map()), [, N] = j((u) => u + 1, 0), O = A((u, s) => {
28
+ M.current.set(u, s), N();
29
+ }, []), x = k(i), S = (u) => {
30
+ const s = [...u.matchAll(R)].map(([, m]) => {
31
+ const f = M.current.get(m);
32
32
  return {
33
- value: C ? C.value : T,
34
- valueData: C?.data
33
+ value: f ? f.value : m,
34
+ valueData: f?.data
35
35
  };
36
36
  });
37
- $.current = m, M(a), r?.setValue?.(m), n?.(m);
37
+ x.current = s, C(u), r?.setValue?.(s), n?.(s);
38
38
  };
39
- _(() => {
40
- u !== $.current && ($.current = u, M(R(u ?? [])));
41
- }, [u]);
39
+ v(() => {
40
+ i !== x.current && (x.current = i, C(y(i ?? [])));
41
+ }, [i]);
42
42
  const P = B(() => [{
43
- pattern: k,
43
+ pattern: R,
44
44
  void: !0,
45
- wrap: (a) => {
46
- const m = X(a), T = E.current.get(m);
47
- return T ? /* @__PURE__ */ l(b, { children: T.children }) : /* @__PURE__ */ l(J, { m: 0.01, color: s, children: /* @__PURE__ */ l(Q, { children: m }) });
45
+ // The chip (input rendering) is defined by the token alone — the menu
46
+ // item's `children` is menu-only and must NOT be reused here. The tag's
47
+ // value is matched against the consumer's `tokenRules` to pick the chip.
48
+ wrap: (u) => {
49
+ const s = W(u), m = a?.find((f) => new RegExp(f.pattern.source, f.pattern.flags.replace("g", "")).test(s));
50
+ if (m?.wrap) {
51
+ const f = new RegExp(m.pattern.source, m.pattern.flags.replace("g", "")).exec(s);
52
+ return m.wrap(s, /* @__PURE__ */ l($, { children: s }), f ?? [s]);
53
+ }
54
+ return m ? /* @__PURE__ */ l("span", { style: m.style, className: m.className, children: /* @__PURE__ */ l($, { children: s }) }) : /* @__PURE__ */ l(J, { m: 0.01, children: /* @__PURE__ */ l($, { children: s }) });
48
55
  }
49
- }], [s]), x = {
50
- search: Y(i),
51
- allowCustomValues: t,
52
- insertToken: (a) => S(Z(i, a)),
56
+ }], [a]), w = {
57
+ search: X(g),
58
+ allowCustomValues: e,
59
+ insertToken: (u) => S(Y(g, u)),
53
60
  registerTag: O
54
61
  };
55
- return /* @__PURE__ */ l(v.Provider, { value: x, children: /* @__PURE__ */ l(L, { ...g, value: i, search: x.search, tokenRules: P, formValidation: r && {
62
+ return /* @__PURE__ */ l(_.Provider, { value: w, children: /* @__PURE__ */ l(U, { ...p, value: g, search: w.search, tokenRules: P, formValidation: r && {
56
63
  valid: r.valid,
57
64
  notValidMessage: r.notValidMessage
58
- }, onChange: S, onSelect: (a) => x.insertToken(String(a)), children: p }) });
59
- }, at = (e) => {
60
- const t = I.c(2);
65
+ }, onChange: S, onSelect: (u) => w.insertToken(String(u)), children: h }) });
66
+ }, ae = (t) => {
67
+ const e = I.c(2);
61
68
  let n;
62
- return t[0] !== e ? (n = /* @__PURE__ */ l(U, { ...e }), t[0] = e, t[1] = n) : n = t[1], n;
63
- }, ut = (e) => {
64
- const t = I.c(2);
69
+ return e[0] !== t ? (n = /* @__PURE__ */ l(q, { ...t }), e[0] = t, e[1] = n) : n = e[1], n;
70
+ }, ce = (t) => {
71
+ const e = I.c(2);
65
72
  let n;
66
- return t[0] !== e ? (n = /* @__PURE__ */ l(z, { ...e }), t[0] = e, t[1] = n) : n = t[1], n;
67
- }, it = ({
68
- value: e,
69
- data: t,
73
+ return e[0] !== t ? (n = /* @__PURE__ */ l(F, { ...t }), e[0] = t, e[1] = n) : n = e[1], n;
74
+ }, ue = ({
75
+ value: t,
76
+ data: e,
70
77
  onlyOnce: n,
71
78
  aliases: r,
72
- children: s
79
+ children: a
73
80
  }) => {
74
81
  const {
75
82
  registerTag: o
76
- } = y(), c = V({
77
- value: e,
78
- data: t,
79
- children: s
83
+ } = D(), c = k({
84
+ value: t,
85
+ data: e,
86
+ children: a
80
87
  });
81
- return c.current.value = e, c.current.data = t, c.current.children = s, _(() => o(String(e), c.current), [e, o]), /* @__PURE__ */ l(q, { value: w(e), data: t, onlyOnce: n, aliases: [String(e), ...r ?? []], children: s });
82
- }, lt = (e) => {
83
- const t = I.c(14);
88
+ return c.current.value = t, c.current.data = e, c.current.children = a, v(() => o(String(t), c.current), [t, o]), /* @__PURE__ */ l(z, { value: V(t), data: e, onlyOnce: n, aliases: [String(t), ...r ?? []], children: a });
89
+ }, le = (t) => {
90
+ const e = I.c(14);
84
91
  let n, r;
85
- t[0] !== e ? ({
92
+ e[0] !== t ? ({
86
93
  onKeyDown: n,
87
94
  ...r
88
- } = e, t[0] = e, t[1] = n, t[2] = r) : (n = t[1], r = t[2]);
95
+ } = t, e[0] = t, e[1] = n, e[2] = r) : (n = e[1], r = e[2]);
89
96
  const {
90
- search: s,
97
+ search: a,
91
98
  allowCustomValues: o,
92
99
  insertToken: c
93
- } = y();
94
- let f;
95
- t[3] !== o || t[4] !== c || t[5] !== s ? (f = () => {
96
- o && s && c(w(s));
97
- }, t[3] = o, t[4] = c, t[5] = s, t[6] = f) : f = t[6];
98
- const p = f;
99
- let g;
100
- t[7] !== o || t[8] !== p || t[9] !== n ? (g = (i) => {
101
- (i.key === "Enter" && !i.defaultPrevented || i.key === "," && o) && (i.preventDefault(), p()), n?.(i);
102
- }, t[7] = o, t[8] = p, t[9] = n, t[10] = g) : g = t[10];
103
- let u;
104
- return t[11] !== r || t[12] !== g ? (u = /* @__PURE__ */ l(H, { ...r, onKeyDown: g }), t[11] = r, t[12] = g, t[13] = u) : u = t[13], u;
105
- }, gt = (e) => {
106
- const t = I.c(2);
100
+ } = D();
101
+ let T;
102
+ e[3] !== o || e[4] !== c || e[5] !== a ? (T = () => {
103
+ o && a && c(V(a));
104
+ }, e[3] = o, e[4] = c, e[5] = a, e[6] = T) : T = e[6];
105
+ const h = T;
106
+ let p;
107
+ e[7] !== o || e[8] !== h || e[9] !== n ? (p = (g) => {
108
+ (g.key === "Enter" && !g.defaultPrevented || g.key === "," && o) && (g.preventDefault(), h()), n?.(g);
109
+ }, e[7] = o, e[8] = h, e[9] = n, e[10] = p) : p = e[10];
110
+ let i;
111
+ return e[11] !== r || e[12] !== p ? (i = /* @__PURE__ */ l(H, { ...r, onKeyDown: p }), e[11] = r, e[12] = p, e[13] = i) : i = e[13], i;
112
+ }, ie = (t) => {
113
+ const e = I.c(2);
107
114
  let n;
108
- return t[0] !== e ? (n = /* @__PURE__ */ l(G, { ...e }), t[0] = e, t[1] = n) : n = t[1], n;
115
+ return e[0] !== t ? (n = /* @__PURE__ */ l(G, { ...t }), e[0] = t, e[1] = n) : n = e[1], n;
109
116
  };
110
117
  export {
111
- ct as TagInput,
112
- at as TagInputMenu,
113
- it as TagInputMenuItem,
114
- ut as TagInputSubMenu,
115
- gt as TagInputTrigger,
116
- lt as TagInputValue
118
+ se as TagInput,
119
+ ae as TagInputMenu,
120
+ ue as TagInputMenuItem,
121
+ ce as TagInputSubMenu,
122
+ ie as TagInputTrigger,
123
+ le as TagInputValue
117
124
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code0-tech/pictor",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "type": "module",
5
5
  "description": "A simple template for a custom React component library",
6
6
  "scripts": {