@code0-tech/pictor 0.0.0-mvp.22 → 0.0.0-mvp.24

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.
Files changed (100) hide show
  1. package/dist/assets/components/aurora/Aurora.style.css +1 -0
  2. package/dist/assets/components/badge/Badge.style.css +1 -1
  3. package/dist/assets/components/button/Button.style.css +1 -1
  4. package/dist/assets/components/button-group/ButtonGroup.style.css +1 -1
  5. package/dist/assets/components/card/Card.style.css +1 -1
  6. package/dist/assets/components/command/Command.style.css +1 -1
  7. package/dist/assets/components/d-flow/folder/DFlowFolder.style.css +1 -1
  8. package/dist/assets/components/d-flow/function/DFlowFunctionDefaultCard.style.css +1 -1
  9. package/dist/assets/components/dialog/Dialog.style.css +1 -1
  10. package/dist/assets/components/file-tabs/FileTabs.style.css +1 -1
  11. package/dist/assets/components/form/Input.style.css +1 -1
  12. package/dist/assets/components/menu/Menu.style.css +1 -1
  13. package/dist/assets/components/segmented-control/SegmentedControl.style.css +1 -1
  14. package/dist/assets/components/tab/Tab.style.css +1 -1
  15. package/dist/assets/components/text/Text.style.css +1 -1
  16. package/dist/assets/components/tooltip/Tooltip.style.css +1 -1
  17. package/dist/components/aurora/Aurora.d.ts +5 -0
  18. package/dist/components/aurora/Aurora.js +23 -0
  19. package/dist/components/badge/Badge.d.ts +1 -0
  20. package/dist/components/badge/Badge.js +12 -11
  21. package/dist/components/button/Button.d.ts +1 -1
  22. package/dist/components/d-flow/DFlow.view.d.ts +6 -2
  23. package/dist/components/d-flow/DFlow.view.js +52 -17
  24. package/dist/components/d-flow/control/DFlowControl.js +38 -38
  25. package/dist/components/d-flow/data-type/DFlowDataType.service.js +1 -1
  26. package/dist/components/d-flow/export/DFlowExport.d.ts +6 -0
  27. package/dist/components/d-flow/export/DFlowExport.js +24 -0
  28. package/dist/components/d-flow/input/DFlowInputDataType.js +32 -32
  29. package/dist/components/d-flow/suggestion/DFlowSuggestion.hook.js +1 -1
  30. package/dist/components/d-flow/suggestion/DFlowSuggestionMenu.js +22 -22
  31. package/dist/components/d-flow/suggestion/DFlowSuggestionMenu.util.js +11 -11
  32. package/dist/components/d-flow/suggestion/DFlowSuggestionSearchInput.d.ts +1 -1
  33. package/dist/components/d-flow/suggestion/DFlowSuggestionSearchInput.js +29 -16
  34. package/dist/components/d-flow/tab/DFlowTabDefault.js +59 -53
  35. package/dist/components/d-flow/type/DFlowType.view.d.ts +1 -1
  36. package/dist/components/d-member/DNamespaceMember.view.js +13 -11
  37. package/dist/components/d-member/DNamespaceMemberCard.d.ts +10 -0
  38. package/dist/components/d-member/DNamespaceMemberCard.js +16 -0
  39. package/dist/components/d-member/DNamespaceMemberContent.d.ts +10 -0
  40. package/dist/components/d-member/DNamespaceMemberContent.js +176 -0
  41. package/dist/components/d-member/DNamespaceMemberList.d.ts +12 -0
  42. package/dist/components/d-member/DNamespaceMemberList.js +23 -0
  43. package/dist/components/d-member/index.d.ts +2 -0
  44. package/dist/components/d-member/index.js +6 -2
  45. package/dist/components/d-organization/DOrganizatonContent.js +29 -14
  46. package/dist/components/d-organization/index.js +22 -7
  47. package/dist/components/d-project/DNamespaceProjectContent.js +36 -42
  48. package/dist/components/d-role/DNamespaceRole.view.d.ts +4 -1
  49. package/dist/components/d-role/DNamespaceRole.view.js +6 -3
  50. package/dist/components/d-role/DNamespaceRoleCard.d.ts +11 -0
  51. package/dist/components/d-role/DNamespaceRoleCard.js +17 -0
  52. package/dist/components/d-role/DNamespaceRoleContent.d.ts +10 -0
  53. package/dist/components/d-role/DNamespaceRoleContent.js +156 -0
  54. package/dist/components/d-role/DNamespaceRoleList.d.ts +12 -0
  55. package/dist/components/d-role/DNamespaceRoleList.js +24 -0
  56. package/dist/components/d-role/DNamespaceRolePermissions.d.ts +5 -0
  57. package/dist/components/d-role/DNamespaceRolePermissions.js +129 -0
  58. package/dist/components/d-role/index.d.ts +2 -0
  59. package/dist/components/d-role/index.js +6 -2
  60. package/dist/components/d-runtime/DRuntimeCard.d.ts +1 -0
  61. package/dist/components/d-runtime/DRuntimeCard.js +13 -12
  62. package/dist/components/d-runtime/DRuntimeContent.d.ts +1 -0
  63. package/dist/components/d-runtime/DRuntimeContent.js +25 -20
  64. package/dist/components/d-runtime/DRuntimeList.d.ts +2 -1
  65. package/dist/components/d-runtime/DRuntimeList.js +17 -14
  66. package/dist/components/d-user/DUser.service.d.ts +1 -0
  67. package/dist/components/d-user/DUser.service.js +5 -2
  68. package/dist/components/d-user/DUserContent.js +25 -25
  69. package/dist/components/d-user/DUserInput.d.ts +7 -0
  70. package/dist/components/d-user/DUserInput.js +98 -0
  71. package/dist/components/d-user/DUserMenu.js +7 -6
  72. package/dist/components/d-user/index.d.ts +1 -0
  73. package/dist/components/d-user/index.js +11 -9
  74. package/dist/components/dialog/Dialog.d.ts +2 -1
  75. package/dist/components/dialog/Dialog.js +67 -59
  76. package/dist/components/form/EmailInput.js +12 -11
  77. package/dist/components/form/Input.d.ts +17 -5
  78. package/dist/components/form/Input.js +420 -137
  79. package/dist/components/form/Input.selection.hook.d.ts +17 -0
  80. package/dist/components/form/Input.selection.hook.js +78 -0
  81. package/dist/components/form/Input.syntax.hook.d.ts +27 -0
  82. package/dist/components/form/Input.syntax.hook.js +80 -0
  83. package/dist/components/form/Input.utils.d.ts +11 -0
  84. package/dist/components/form/Input.utils.js +33 -0
  85. package/dist/components/form/InputSuggestion.d.ts +14 -6
  86. package/dist/components/form/InputSuggestion.js +126 -72
  87. package/dist/components/form/InputSyntax.d.ts +19 -0
  88. package/dist/components/form/InputSyntax.js +52 -0
  89. package/dist/components/form/PasswordInput.js +11 -10
  90. package/dist/components/form/TextInput.js +11 -10
  91. package/dist/components/form/index.js +26 -27
  92. package/dist/components/form/inputSyntaxMapping.d.ts +3 -0
  93. package/dist/components/form/inputSyntaxMapping.js +42 -0
  94. package/dist/components/menu/Menu.d.ts +7 -3
  95. package/dist/components/menu/Menu.js +22 -22
  96. package/dist/components/tooltip/Tooltip.js +33 -33
  97. package/dist/index.d.ts +1 -0
  98. package/dist/index.js +250 -239
  99. package/dist/utils/generics.js +1 -1
  100. package/package.json +17 -17
@@ -1,153 +1,436 @@
1
- import { jsxs as f, jsx as r, Fragment as T } from "react/jsx-runtime";
2
- import h, { useRef as v, useState as x, useEffect as V, useMemo as k } from "react";
3
- import { mergeCode0Props as y } from "../../utils/utils.js";
1
+ import { jsx as y, jsxs as z, Fragment as et } from "react/jsx-runtime";
2
+ import f, { useRef as A, useState as N, useEffect as k, useMemo as Ke } from "react";
3
+ import "../../utils/contextStore.js";
4
+ import { mergeCode0Props as fe } from "../../utils/utils.js";
4
5
  import '../../assets/components/form/Input.style.css';/* empty css */
5
- import { InputLabel as A } from "./InputLabel.js";
6
- import { InputDescription as K } from "./InputDescription.js";
7
- import { InputMessage as H } from "./InputMessage.js";
8
- import { Menu as J, MenuTrigger as U, MenuPortal as q } from "../menu/Menu.js";
9
- import { InputSuggestionMenuContent as z, InputSuggestionMenuContentItems as B } from "./InputSuggestion.js";
10
- const G = (t, s, n, a) => {
11
- const o = Object.getOwnPropertyDescriptor(t, s)?.set, l = Object.getPrototypeOf(t), i = Object.getOwnPropertyDescriptor(l, s)?.set;
12
- o && o !== i ? i?.call(t, n) : o?.call(t, n), t.dispatchEvent(new Event(a, {
13
- bubbles: !0
14
- }));
15
- }, oe = h.forwardRef((t, s) => {
16
- const n = s || v(null), a = v(null), [o, l] = x(!1), i = v(!0), [c, _] = x(t.defaultValue || t.initialValue || t.placeholder), {
17
- wrapperComponent: P = {},
18
- // Default empty wrapper props
19
- title: b,
20
- // Optional input label
21
- description: M,
22
- // Optional description below label
23
- disabled: w = !1,
24
- // Input disabled state
25
- left: E,
26
- // Left element (icon/button)
27
- right: I,
28
- // Right element (icon/button)
29
- leftType: j = "icon",
30
- // Visual hint for left
31
- rightType: R = "action",
32
- // Visual hint for right
33
- formValidation: u = {
6
+ import { InputLabel as tt } from "./InputLabel.js";
7
+ import { InputDescription as nt } from "./InputDescription.js";
8
+ import { InputMessage as rt } from "./InputMessage.js";
9
+ import { Menu as at, MenuTrigger as st, MenuPortal as ot } from "../menu/Menu.js";
10
+ import { InputSuggestionMenuContent as it, InputSuggestionMenuContentItems as lt } from "./InputSuggestion.js";
11
+ import { InputSyntax as ut } from "./InputSyntax.js";
12
+ import { useSyntaxModel as ct } from "./Input.syntax.hook.js";
13
+ import { useSelectionVisibility as dt, useSelectionNormalization as ft, useSelectionResolution as gt } from "./Input.selection.hook.js";
14
+ import { setSelectionRangeSafe as T, getSelectionMetrics as U, setElementKey as ze } from "./Input.utils.js";
15
+ import { Card as mt } from "../card/Card.js";
16
+ const pt = f.forwardRef((te, Ue) => {
17
+ const {
18
+ wrapperComponent: We = {},
19
+ title: ge,
20
+ description: me,
21
+ disabled: pe = !1,
22
+ left: he,
23
+ right: xe,
24
+ leftType: je = "icon",
25
+ rightType: _e = "action",
26
+ formValidation: b = {
34
27
  valid: !0,
35
28
  notValidMessage: null,
36
29
  setValue: null
37
30
  },
38
- // Validation config
39
- suggestions: d,
40
- // Optional suggestions array
41
- suggestionsHeader: S,
42
- // Optional header above suggestion list
43
- suggestionsFooter: O,
44
- // Optional footer below suggestion list
45
- onSuggestionSelect: C = () => {
46
- },
47
- // Callback for suggestion selection,
48
- disableOnValue: D = () => !1,
49
- ...m
50
- // Remaining native input props
51
- } = t;
52
- V(() => {
53
- const e = n.current;
54
- if (!e || !u?.setValue) return;
55
- const g = (L) => {
56
- const N = m.type !== "checkbox" ? L.target.value : L.target.checked;
57
- u.setValue?.(N);
31
+ suggestions: x,
32
+ suggestionsHeader: Se,
33
+ suggestionsFooter: ve,
34
+ onSuggestionSelect: W,
35
+ disableOnValue: ke = () => !1,
36
+ transformSyntax: ne,
37
+ validationUsesSuggestions: j = !1,
38
+ filterSuggestionsByLastToken: V = !1,
39
+ enforceUniqueSuggestions: we = !1,
40
+ onLastTokenChange: re,
41
+ suggestionsEmptyState: ye,
42
+ ...L
43
+ } = te, s = Ue || A(null), P = A(null), _ = A(null), H = A(!0), E = A(null), He = A(0), be = A([]), Ie = A(null), [C, F] = N(!1), [m, Je] = N(te.defaultValue || te.initialValue), [J, Me] = N([]), [X, Ve] = N([]), [Ee, $] = N(null), [ae, B] = N(null), [Ce, Re] = N(!1), Y = f.useMemo(() => ke(m), [m, ke]), I = f.useCallback((e) => {
44
+ const t = e ?? "";
45
+ return typeof t == "string" ? t : String(t);
46
+ }, []), De = f.useCallback((e, t, n) => {
47
+ if (e.length === 0) return t <= n.length ? t : null;
48
+ let r = n.indexOf(e);
49
+ if (r === -1) return null;
50
+ let a = r;
51
+ for (; a !== -1; )
52
+ Math.abs(a - t) < Math.abs(r - t) && (r = a), a = n.indexOf(e, a + 1);
53
+ return r;
54
+ }, []), G = f.useCallback((e, t) => {
55
+ const n = [];
56
+ return e.forEach((r) => {
57
+ const a = De(r.text, r.start, t);
58
+ if (a === null) return;
59
+ const i = a + r.text.length;
60
+ t.slice(a, i) === r.text && n.push({
61
+ ...r,
62
+ start: a,
63
+ end: i
64
+ });
65
+ }), n;
66
+ }, [De]);
67
+ k(() => {
68
+ be.current = X;
69
+ }, [X]), k(() => {
70
+ const e = s.current;
71
+ if (!e || !b?.setValue) return;
72
+ const t = (n) => {
73
+ const r = L.type !== "checkbox" ? n.target.value : n.target.checked, a = j ? be.current : r;
74
+ b.setValue?.(a);
58
75
  };
59
- return e.addEventListener("change", g), () => e.removeEventListener("change", g);
60
- }, [u?.setValue]), V(() => {
61
- if (!d) return;
62
- const e = (g) => {
63
- i.current = !!n.current?.contains(g.target);
76
+ return e.addEventListener("change", t), () => e.removeEventListener("change", t);
77
+ }, [b?.setValue, s, L.type, j]), k(() => {
78
+ if (!x) return;
79
+ const e = (t) => {
80
+ const n = t.target, r = !!s.current?.contains(n), a = !!_.current?.contains(n);
81
+ H.current = r || a;
64
82
  };
65
83
  return document.addEventListener("pointerdown", e, !0), () => document.removeEventListener("pointerdown", e, !0);
84
+ }, [s, x]), k(() => {
85
+ const e = s.current;
86
+ if (!e) return;
87
+ const t = (n) => {
88
+ Y || Je(n.target.value);
89
+ };
90
+ return e.addEventListener("change", t), e.addEventListener("input", t), () => {
91
+ e.removeEventListener("change", t), e.removeEventListener("input", t);
92
+ };
93
+ }, [Y, s]), k(() => {
94
+ const e = I(s.current?.value ?? m);
95
+ Me((t) => {
96
+ const n = G(t, e);
97
+ return Ve(n.map((r) => r.suggestion)), n;
98
+ });
99
+ }, [I, G, m]);
100
+ const Ae = f.useCallback((e, t) => {
101
+ const n = I(e), r = [...t].sort((l, o) => l.start - o.start), a = [];
102
+ let i = 0;
103
+ return r.forEach((l) => {
104
+ if (l.start < i) return;
105
+ const o = Math.min(l.end, n.length);
106
+ i < l.start && a.push(n.slice(i, l.start));
107
+ const c = l.suggestion?.value ?? l.text ?? "", g = c == null ? "" : String(c), u = Math.max(o - l.start, g.length);
108
+ u > 0 ? (a.push(l.suggestion), i = l.start + u) : i = l.start;
109
+ }), i < n.length && a.push(n.slice(i)), a.length ? a : [n];
110
+ }, [I]);
111
+ k(() => {
112
+ if (!b?.setValue) return;
113
+ const e = L.type !== "checkbox" ? I(s.current?.value ?? m) : m, t = j ? X : e;
114
+ Object.is(Ie.current, t) || (Ie.current = t, b.setValue(t));
115
+ }, [X, b?.setValue, s, I, L.type, j, m]);
116
+ const Te = f.useCallback(() => {
117
+ setTimeout(() => {
118
+ const e = s.current;
119
+ if (!e) return;
120
+ e.focus({
121
+ preventScroll: !0
122
+ });
123
+ const t = e.value.length;
124
+ T(e, t, t), e.scrollLeft = e.scrollWidth;
125
+ }, 0);
126
+ }, [s]), se = f.useMemo(() => Ae(m, J), [J, Ae, m]), d = f.useMemo(() => {
127
+ if (ne)
128
+ return (e, t = se) => ne(e, t);
129
+ }, [se, ne]), {
130
+ syntaxSegments: oe,
131
+ visualizedSyntaxSegments: M,
132
+ expandSelectionRangeToBlockBoundaries: O,
133
+ mapVisualIndexToRawIndex: q,
134
+ mapRawIndexToVisualIndex: R,
135
+ totalVisualLength: ie
136
+ } = ct(m, d, s, se), w = f.useMemo(() => {
137
+ const e = I(s.current?.value ?? m);
138
+ if (!V || !oe?.length) return null;
139
+ const t = [...oe].reverse().find((h) => h?.type === "text" && h?.end === e.length);
140
+ if (!t) return null;
141
+ const n = e.slice(t.start, t.end), r = n.trim();
142
+ if (!r.length) return null;
143
+ const a = r.split(/\s+/), i = a[a.length - 1]?.trim();
144
+ if (!i) return null;
145
+ const l = n.search(/\S/), o = l === -1 ? 0 : l, c = r.lastIndexOf(i), g = t.start + o + c, u = g + i.length;
146
+ return {
147
+ token: i,
148
+ start: g,
149
+ end: u
150
+ };
151
+ }, [V, s, I, oe, m]);
152
+ k(() => {
153
+ V && re && (w?.token && F(!0), re(w?.token ?? null));
154
+ }, [V, re, w?.token]);
155
+ const K = f.useMemo(() => {
156
+ if (!V || !x) return x;
157
+ const e = w?.token?.trim();
158
+ return e?.length ? x.filter((t) => {
159
+ const n = t?.value ?? "";
160
+ return (n == null ? "" : String(n)).toLowerCase().startsWith(e.toLowerCase());
161
+ }) : x;
162
+ }, [V, w?.token, x]), Q = f.useMemo(() => {
163
+ if (!we || !K) return K;
164
+ const e = new Set(J.map((t) => t.suggestion));
165
+ return K.filter((t) => !e.has(t));
166
+ }, [J, we, K]), {
167
+ ensureVisualIndexVisible: Z,
168
+ syncSyntaxScroll: S
169
+ } = dt(s, _), Le = ft(d, O), p = f.useCallback(() => {
170
+ if (!d) return;
171
+ const e = s.current;
172
+ if (!e) return;
173
+ const {
174
+ rawStart: t,
175
+ rawEnd: n
176
+ } = U(e), r = M.find((u) => u?.type !== "block" ? !1 : t > u?.start && t < u?.end);
177
+ if (r && t === n) {
178
+ const u = t - r.start, h = r.end - t, v = u <= h ? r.start : r.end;
179
+ T(e, v, v);
180
+ const D = v === r.start ? r.visualStart : r.visualEnd;
181
+ $(null), B(D), requestAnimationFrame(() => {
182
+ S(), Z(D);
183
+ });
184
+ return;
185
+ }
186
+ if (t === n) {
187
+ const u = Math.round(R(t));
188
+ $(null), B(Number.isFinite(u) ? u : null), requestAnimationFrame(() => {
189
+ S(), Z(u);
190
+ });
191
+ return;
192
+ }
193
+ let a = R(t), i = R(n);
194
+ M.forEach((u) => {
195
+ u?.type !== "block" || !(t < u?.end && n > u?.start) || (a = Math.min(a, u?.visualStart), i = Math.max(i, u?.visualEnd));
196
+ });
197
+ const l = Math.min(a, i), o = Math.max(a, i);
198
+ B(null), $({
199
+ start: l,
200
+ end: o
201
+ });
202
+ const g = (e.selectionDirection === "backward" ? "backward" : "forward") === "backward" ? l : o;
203
+ requestAnimationFrame(() => {
204
+ S(), Z(g);
205
+ });
206
+ }, [Z, s, R, S, d, M]), Fe = gt(d, s, Ee, M, R), Ne = f.useCallback((e) => {
207
+ if (!e) return null;
208
+ const t = e.dataset.rawIndex, n = e.dataset.visualIndex || e.dataset.visualStart || e.dataset.visualEnd, r = t ? Number(t) : void 0, a = n ? Number(n) : void 0;
209
+ return !Number.isNaN(r) && r !== void 0 ? r : a !== void 0 ? q(a) : null;
210
+ }, [q]), ee = f.useCallback((e) => {
211
+ const t = document.elementFromPoint(e.clientX, e.clientY);
212
+ return Ne(t ?? e.target);
213
+ }, [Ne]), Pe = f.useCallback((e) => {
214
+ if (!s.current) return;
215
+ const t = ee(e);
216
+ if (t === null || Number.isNaN(t)) return;
217
+ e.preventDefault(), H.current = !0;
218
+ const n = Math.min(Math.max(t, 0), s.current.value.length), {
219
+ selectionStart: r
220
+ } = U(s.current), a = e.shiftKey && Number.isFinite(r) ? r : n;
221
+ E.current = a, s.current.focus({
222
+ preventScroll: !0
223
+ }), T(s.current, a, n), _.current?.setPointerCapture(e.pointerId), p();
224
+ }, [s, ee, p]), $e = f.useCallback((e) => {
225
+ if (!s.current || E.current === null) return;
226
+ if (!(e.buttons & 1)) {
227
+ E.current = null;
228
+ return;
229
+ }
230
+ const t = ee(e);
231
+ if (t === null || Number.isNaN(t)) return;
232
+ e.preventDefault();
233
+ const n = E.current, r = Math.min(Math.max(t, 0), s.current.value.length);
234
+ s.current.focus({
235
+ preventScroll: !0
236
+ }), T(s.current, n, r), p();
237
+ }, [s, ee, p]), Be = f.useCallback(() => {
238
+ E.current = null;
239
+ }, []), Oe = f.useCallback((e) => {
240
+ if (!d) return !1;
241
+ const t = e.target, {
242
+ rawStart: n,
243
+ rawEnd: r
244
+ } = U(t), a = (o, c) => {
245
+ if (o === c) return !1;
246
+ e.preventDefault();
247
+ const g = `${t.value.slice(0, o)}${t.value.slice(c)}`;
248
+ return ze(t, "value", g, "input"), requestAnimationFrame(() => {
249
+ T(t, o, o), p();
250
+ }), !0;
251
+ };
252
+ if (n !== r) {
253
+ const {
254
+ start: o,
255
+ end: c,
256
+ hasBlockOverlap: g
257
+ } = O(n, r);
258
+ return g ? a(o, c) : !1;
259
+ }
260
+ const i = M.find((o) => o?.type !== "block" ? !1 : n === o?.end || n > o?.start && n < o?.end);
261
+ if (e.key === "Backspace" && i)
262
+ return a(i.start, i.end);
263
+ const l = M.find((o) => o?.type !== "block" ? !1 : n === o?.start || n > o?.start && n < o?.end);
264
+ return e.key === "Delete" && l ? a(l.start, l.end) : !1;
265
+ }, [O, d, p, M]), le = f.useCallback((e) => {
266
+ if (d && Le(e.target), d && (e.key === "ArrowLeft" || e.key === "ArrowRight")) {
267
+ const t = e.target, {
268
+ selectionStart: n,
269
+ selectionEnd: r,
270
+ rawStart: a,
271
+ rawEnd: i,
272
+ direction: l
273
+ } = U(t), o = e.key === "ArrowLeft" ? -1 : 1;
274
+ if (e.shiftKey) {
275
+ const c = E.current ?? (l === "backward" ? r : n);
276
+ E.current = c;
277
+ const u = Math.round(R(c === n ? r : n)), h = Math.max(0, Math.min(u + o, ie)), v = q(h);
278
+ if (!Number.isNaN(v)) {
279
+ e.preventDefault();
280
+ const D = Math.min(Math.max(Math.round(v), 0), t.value.length), Ge = D < c ? "backward" : "forward", Qe = Math.min(c, D), Ze = Math.max(c, D);
281
+ T(t, Qe, Ze, Ge), requestAnimationFrame(() => {
282
+ S(), p();
283
+ });
284
+ }
285
+ } else {
286
+ E.current = null;
287
+ const c = e.key === "ArrowLeft" ? a : i, g = Math.round(R(c)), u = Math.max(0, Math.min(g + o, ie)), h = q(u);
288
+ if (!Number.isNaN(h)) {
289
+ e.preventDefault();
290
+ const v = Math.min(Math.max(Math.round(h), 0), t.value.length);
291
+ T(t, v, v), requestAnimationFrame(() => {
292
+ S(), p();
293
+ });
294
+ }
295
+ }
296
+ if (e.defaultPrevented) return;
297
+ }
298
+ if (!(d && (e.key === "Backspace" || e.key === "Delete") && Oe(e)) && x)
299
+ if (e.key === "ArrowDown") {
300
+ e.preventDefault();
301
+ const t = C;
302
+ F(!0), t ? P.current?.highlightNextItem() : setTimeout(() => P.current?.focusFirstItem(), 0);
303
+ } else if (e.key === "ArrowUp") {
304
+ e.preventDefault();
305
+ const t = C;
306
+ F(!0), t ? P.current?.highlightPreviousItem() : setTimeout(() => P.current?.focusLastItem(), 0);
307
+ } else e.key === "Enter" && C && P.current?.selectActiveItem() && F(!1);
308
+ }, [Oe, R, q, Le, C, x, S, ie, d, p]), ue = f.useCallback((e) => {
309
+ (e.key === " " || e.code === "Space") && (e.stopPropagation(), e.nativeEvent?.stopImmediatePropagation?.());
310
+ }, []), ce = f.useCallback(() => {
311
+ Re(!0), requestAnimationFrame(() => {
312
+ p(), S();
313
+ }), x && !C && F(!0);
314
+ }, [C, x, S, p]), de = f.useCallback(() => {
315
+ Re(!1), B(null), $(null);
316
+ }, []);
317
+ k(() => {
318
+ const e = s.current;
319
+ if (!e || !d) return;
320
+ const t = () => requestAnimationFrame(p);
321
+ t();
322
+ const n = ["select", "keyup", "mouseup", "input", "keydown"];
323
+ return n.forEach((r) => e.addEventListener(r, t)), () => {
324
+ n.forEach((r) => e.removeEventListener(r, t));
325
+ };
326
+ }, [s, d, p]), k(() => {
327
+ if (!d) return;
328
+ const e = () => {
329
+ document.activeElement === s.current && p();
330
+ };
331
+ return document.addEventListener("selectionchange", e), () => document.removeEventListener("selectionchange", e);
332
+ }, [s, d, p]), k(() => {
333
+ const e = s.current;
334
+ if (!e) return;
335
+ const t = () => S();
336
+ return t(), e.addEventListener("scroll", t), () => e.removeEventListener("scroll", t);
337
+ }, [s, S]), k(() => {
338
+ S();
339
+ }, [S, m, ae, Ee]), k(() => {
340
+ d || ($(null), B(null));
66
341
  }, [d]);
67
- const p = h.useMemo(() => D(c), [c, D]);
68
- V(() => {
69
- n.current && (n.current.addEventListener("change", (e) => {
70
- p || _(e.target.value);
71
- }), n.current.addEventListener("input", (e) => {
72
- p || _(e.target.value);
73
- }));
74
- }, [n, p]);
75
- const $ = h.useMemo(() => t.transformValue ? /* @__PURE__ */ f("div", { className: "input__syntax", children: [
76
- t.transformValue(c),
77
- " "
78
- ] }) : null, [t.transformValue, c]), F = k(() => /* @__PURE__ */ f(
79
- J,
80
- {
81
- open: o,
82
- modal: !1,
83
- onOpenChange: (e) => {
84
- if (!e && i.current) {
85
- i.current = !1;
86
- return;
342
+ const qe = f.useCallback((e) => {
343
+ if (!s.current) return;
344
+ const t = typeof m == "object" ? JSON.stringify(e.value) : e.value, n = t == null ? "" : String(t), r = e.insertMode ?? "replace", a = s.current.value ?? "";
345
+ let i = a, l = null, o = 0;
346
+ if (V && w)
347
+ i = `${a.slice(0, w.start)}${n}${a.slice(w.end)}`, l = w.start + n.length, o = w.start;
348
+ else
349
+ switch (r) {
350
+ case "append": {
351
+ i = `${a}${n}`, l = i.length, o = a.length;
352
+ break;
353
+ }
354
+ case "prepend": {
355
+ i = `${n}${a}`, l = n.length, o = 0;
356
+ break;
357
+ }
358
+ case "insert": {
359
+ const {
360
+ rawStart: c,
361
+ rawEnd: g
362
+ } = U(s.current), {
363
+ start: u,
364
+ end: h
365
+ } = d ? O(c, g) : {
366
+ start: c,
367
+ end: g
368
+ };
369
+ i = `${a.slice(0, u)}${n}${a.slice(h)}`, l = u + n.length, o = u;
370
+ break;
87
371
  }
88
- l(e), e && setTimeout(() => n.current?.focus(), 0);
89
- },
90
- children: [
91
- /* @__PURE__ */ r(U, { asChild: !0, children: /* @__PURE__ */ r(
92
- "input",
372
+ case "replace":
373
+ default: {
374
+ i = n, l = n.length, o = 0;
375
+ break;
376
+ }
377
+ }
378
+ ze(s.current, "value", i, "change"), Me((c) => {
379
+ const g = I(i), u = G(c, g), h = n.length ? {
380
+ id: He.current++,
381
+ suggestion: e,
382
+ text: n,
383
+ start: o,
384
+ end: o + n.length
385
+ } : null, v = h ? [...u, h] : u;
386
+ return Ve(v.map((D) => D.suggestion)), v;
387
+ }), l !== null && requestAnimationFrame(() => {
388
+ const c = s.current;
389
+ c && (c.focus({
390
+ preventScroll: !0
391
+ }), T(c, l, l));
392
+ });
393
+ }, [O, V, s, I, G, w, d, m]), Xe = Ke(() => /* @__PURE__ */ y(ut, { transformSyntax: d, syntaxRef: _, visualizedSyntaxSegments: M, resolvedVisualSelectionRange: Fe, visualCaretIndex: ae, isFocused: Ce, onPointerDown: Pe, onPointerMove: $e, onPointerUp: Be }), [Pe, Be, $e, Ce, Fe, d, ae, M]), Ye = Ke(() => /* @__PURE__ */ z(at, { open: C, modal: !1, onOpenChange: (e) => {
394
+ if (!e && H.current) {
395
+ H.current = !1;
396
+ return;
397
+ }
398
+ F(e), e && setTimeout(() => s.current?.focus(), 0);
399
+ }, children: [
400
+ /* @__PURE__ */ y(st, { asChild: !0, children: /* @__PURE__ */ y("input", { ref: s, ...fe(`input__control ${d ? "input__control--syntax" : ""}`, L), onFocus: ce, onBlur: de, onKeyDownCapture: ue, onKeyDown: le, spellCheck: !1, disabled: pe || Y }) }),
401
+ /* @__PURE__ */ y(ot, { children: /* @__PURE__ */ z(it, { color: "secondary", inputRef: s, children: [
402
+ Se,
403
+ /* @__PURE__ */ z(mt, { paddingSize: "xxs", mt: -0.35, mx: -0.35, style: {
404
+ borderWidth: "2px"
405
+ }, children: [
406
+ Q?.length === 0 && ye,
407
+ !!Q?.length && /* @__PURE__ */ y(
408
+ lt,
93
409
  {
94
- ref: n,
95
- ...y(`input__control ${t.transformValue ? "input__control--syntax" : ""}`, m),
96
- onFocus: () => !o && l(!0),
97
- onKeyDown: (e) => {
98
- e.key === "ArrowDown" ? (e.preventDefault(), a.current?.focusFirstItem()) : e.key === "ArrowUp" && (e.preventDefault(), a.current?.focusLastItem());
99
- },
100
- disabled: w || p
101
- }
102
- ) }),
103
- /* @__PURE__ */ r(q, { children: /* @__PURE__ */ f(z, { children: [
104
- S,
105
- " ",
106
- /* @__PURE__ */ r(
107
- B,
108
- {
109
- ref: a,
110
- suggestions: d,
111
- onSuggestionSelect: (e) => {
112
- C || G(s.current, "value", typeof c == "object" ? JSON.stringify(e.value) : e.value, "change"), C(e), l(!1);
113
- }
410
+ ref: P,
411
+ inputRef: s,
412
+ suggestions: Q,
413
+ onSuggestionSelect: (e) => {
414
+ W ? W?.(e) : qe(e), F(!1), W && Te();
114
415
  }
115
- ),
116
- O,
117
- " "
118
- ] }) })
119
- ]
120
- }
121
- ), [o, d, S, O]);
122
- return /* @__PURE__ */ f(T, { children: [
123
- b && /* @__PURE__ */ r(A, { children: b }),
124
- " ",
125
- M && /* @__PURE__ */ r(K, { children: M }),
126
- " ",
127
- /* @__PURE__ */ f("div", { ...y(
128
- `input ${u?.valid ? "" : "input--not-valid"}`,
129
- // Add error class if invalid
130
- P
131
- ), children: [
132
- E && /* @__PURE__ */ r("div", { className: `input__left input__left--${j}`, children: E }),
133
- " ",
134
- d ? F : /* @__PURE__ */ r(
135
- "input",
136
- {
137
- tabIndex: 2,
138
- ref: n,
139
- disabled: w,
140
- ...y(`input__control ${t.transformValue ? "input__control--syntax" : ""}`, m)
141
- }
142
- ),
143
- $,
144
- I && /* @__PURE__ */ r("div", { className: `input__right input__right--${R}`, children: I }),
145
- " "
416
+ }
417
+ )
418
+ ] }),
419
+ ve
420
+ ] }) })
421
+ ] }), [qe, Q, Y, Te, de, ce, le, ue, s, W, C, L, ye, ve, Se, d]);
422
+ return /* @__PURE__ */ z(et, { children: [
423
+ ge && /* @__PURE__ */ y(tt, { children: ge }),
424
+ me && /* @__PURE__ */ y(nt, { children: me }),
425
+ /* @__PURE__ */ z("div", { ...fe(`input ${b?.valid ? "" : "input--not-valid"}`, We), children: [
426
+ he && /* @__PURE__ */ y("div", { className: `input__left input__left--${je}`, children: he }),
427
+ x ? Ye : /* @__PURE__ */ y("input", { tabIndex: 2, ref: s, disabled: pe, onFocus: ce, onBlur: de, onKeyDownCapture: ue, onKeyDown: le, ...fe(`input__control ${d ? "input__control--syntax" : ""}`, L) }),
428
+ Xe,
429
+ xe && /* @__PURE__ */ y("div", { className: `input__right input__right--${_e}`, children: xe })
146
430
  ] }),
147
- !u?.valid && u?.notValidMessage && /* @__PURE__ */ r(H, { children: u.notValidMessage })
431
+ !b?.valid && b?.notValidMessage && /* @__PURE__ */ y(rt, { children: b.notValidMessage })
148
432
  ] });
149
- });
433
+ }), At = pt;
150
434
  export {
151
- oe as Input,
152
- G as setElementKey
435
+ At as Input
153
436
  };
@@ -0,0 +1,17 @@
1
+ import { RefObject } from 'react';
2
+ import { ResolvedVisualSelectionRange } from './InputSyntax';
3
+ import { VisualizedInputSyntaxSegment } from './Input.syntax.hook';
4
+ import { InputSuggestion } from './InputSuggestion';
5
+ export declare const useSelectionVisibility: (inputRef: RefObject<HTMLInputElement | null>, syntaxRef: RefObject<HTMLDivElement | null>) => {
6
+ ensureVisualIndexVisible: (visualIndex: number | null) => void;
7
+ syncSyntaxScroll: () => void;
8
+ };
9
+ export declare const useSelectionNormalization: (transformSyntax: ((value: any, appliedSyntaxParts?: (InputSuggestion | any)[]) => any) | undefined, expandSelectionRangeToBlockBoundaries: (rawStart: number, rawEnd: number) => {
10
+ start: number;
11
+ end: number;
12
+ hasBlockOverlap: boolean;
13
+ }) => (target: HTMLInputElement) => void;
14
+ export declare const useSelectionResolution: (transformSyntax: ((value: any, appliedSyntaxParts?: (InputSuggestion | any)[]) => any) | undefined, inputRef: RefObject<HTMLInputElement>, visualSelectionRange: {
15
+ start: number;
16
+ end: number;
17
+ } | null, visualizedSyntaxSegments: VisualizedInputSyntaxSegment[], mapRawIndexToVisualIndex: (rawIndex: number) => number) => ResolvedVisualSelectionRange;
@@ -0,0 +1,78 @@
1
+ import { c as M } from "../../_virtual/compiler-runtime.js";
2
+ import p from "react";
3
+ import { useSyncSyntaxScroll as $, getSelectionMetrics as L, setSelectionRangeSafe as g } from "./Input.utils.js";
4
+ const F = (r, n) => {
5
+ const t = M.c(6);
6
+ let s;
7
+ t[0] !== r || t[1] !== n ? (s = (u) => {
8
+ if (u === null || !r.current || !n.current)
9
+ return;
10
+ const e = n.current, c = Math.round(u), m = e.querySelector(`[data-visual-index="${c}"]`);
11
+ let f = null, i = null;
12
+ if (m)
13
+ f = m.offsetLeft, i = m.offsetLeft + m.offsetWidth;
14
+ else {
15
+ const E = Array.from(e.querySelectorAll("[data-visual-start][data-visual-end]")).find((d) => {
16
+ const v = Number(d.dataset.visualStart), b = Number(d.dataset.visualEnd);
17
+ return Number.isFinite(v) && Number.isFinite(b) && c >= v && c <= b;
18
+ });
19
+ if (E) {
20
+ const d = Number(E.dataset.visualStart) || 0, v = Number(E.dataset.visualEnd) || d, b = E.offsetWidth, W = v === d ? 0 : (c - d) / (v - d);
21
+ f = E.offsetLeft + b * W, i = f;
22
+ }
23
+ }
24
+ if (f === null || i === null)
25
+ return;
26
+ const S = e.scrollLeft, N = S + e.clientWidth;
27
+ let h = S;
28
+ f - 8 < S ? h = Math.max(f - 8, 0) : i + 8 > N && (h = Math.max(i + 8 - e.clientWidth, 0)), h !== S && (r.current.scrollLeft = h, e.scrollLeft = h);
29
+ }, t[0] = r, t[1] = n, t[2] = s) : s = t[2];
30
+ const o = s, a = $(r, n);
31
+ let l;
32
+ return t[3] !== o || t[4] !== a ? (l = {
33
+ ensureVisualIndexVisible: o,
34
+ syncSyntaxScroll: a
35
+ }, t[3] = o, t[4] = a, t[5] = l) : l = t[5], l;
36
+ }, _ = (r, n) => {
37
+ const t = M.c(3);
38
+ let s;
39
+ return t[0] !== n || t[1] !== r ? (s = (o) => {
40
+ if (!r)
41
+ return;
42
+ const {
43
+ selectionStart: a,
44
+ selectionEnd: l
45
+ } = L(o);
46
+ if (a === l)
47
+ return;
48
+ const {
49
+ start: u,
50
+ end: e,
51
+ hasBlockOverlap: c
52
+ } = n(a, l);
53
+ c && (u === a && e === l || g(o, u, e));
54
+ }, t[0] = n, t[1] = r, t[2] = s) : s = t[2], s;
55
+ }, O = (r, n, t, s, o) => p.useMemo(() => {
56
+ if (!r) return null;
57
+ const a = n.current;
58
+ if (!a) return t;
59
+ const {
60
+ rawStart: l,
61
+ rawEnd: u
62
+ } = L(a);
63
+ if (l === u) return null;
64
+ let e = o(l), c = o(u);
65
+ s.forEach((i) => {
66
+ i.type !== "block" || !(l < i.end && u > i.start) || (e = Math.min(e, i.visualStart), c = Math.max(c, i.visualEnd));
67
+ });
68
+ const m = Math.min(e, c), f = Math.max(e, c);
69
+ return {
70
+ start: m,
71
+ end: f
72
+ };
73
+ }, [n, o, r, t, s]);
74
+ export {
75
+ _ as useSelectionNormalization,
76
+ O as useSelectionResolution,
77
+ F as useSelectionVisibility
78
+ };