@code0-tech/pictor 0.0.0-mvp.29 → 0.0.0-mvp.30

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 (125) hide show
  1. package/dist/_virtual/_commonjsHelpers.js +6 -0
  2. package/dist/_virtual/index.js +4 -0
  3. package/dist/_virtual/index2.js +4 -0
  4. package/dist/_virtual/react-contenteditable.js +7 -0
  5. package/dist/_virtual/react-contenteditable2.js +4 -0
  6. package/dist/_virtual/react-dom-server-legacy.browser.development.js +4 -0
  7. package/dist/_virtual/react-dom-server-legacy.browser.production.js +4 -0
  8. package/dist/_virtual/react-dom-server.browser.development.js +4 -0
  9. package/dist/_virtual/react-dom-server.browser.production.js +4 -0
  10. package/dist/_virtual/react-is.development.js +4 -0
  11. package/dist/_virtual/react-is.production.min.js +4 -0
  12. package/dist/_virtual/server.browser.js +5 -0
  13. package/dist/_virtual/server.browser2.js +4 -0
  14. package/dist/assets/components/d-resizable/DResizable.style.css +1 -1
  15. package/dist/assets/components/form/Input.style.css +1 -1
  16. package/dist/components/breadcrumb/Breadcrumb.js +12 -12
  17. package/dist/components/button-group/ButtonGroup.js +12 -12
  18. package/dist/components/d-flow/DFlow.edges.hook.js +57 -54
  19. package/dist/components/d-flow/DFlow.js +304 -268
  20. package/dist/components/d-flow/DFlow.nodes.hook.js +60 -59
  21. package/dist/components/d-flow/DFlow.service.d.ts +3 -2
  22. package/dist/components/d-flow/DFlow.service.js +62 -47
  23. package/dist/components/d-flow/DFlow.util.d.ts +4 -0
  24. package/dist/components/d-flow/DFlow.util.js +63 -0
  25. package/dist/components/d-flow/DFlowEdge.js +34 -34
  26. package/dist/components/d-flow-data-type/DFlowDataType.service.js +17 -14
  27. package/dist/components/d-flow-data-type/DFlowDataType.view.d.ts +7 -4
  28. package/dist/components/d-flow-data-type/DFlowDataType.view.js +11 -6
  29. package/dist/components/d-flow-file/DFlowTabDefault.d.ts +0 -3
  30. package/dist/components/d-flow-file/DFlowTabDefault.js +77 -112
  31. package/dist/components/d-flow-file/DFlowTabTrigger.js +38 -49
  32. package/dist/components/d-flow-file/DFlowTabs.js +26 -27
  33. package/dist/components/d-flow-folder/DFlowFolder.js +170 -143
  34. package/dist/components/d-flow-folder/DFlowFolderContextMenu.js +18 -11
  35. package/dist/components/d-flow-folder/DFlowFolderItemPathInput.js +1 -0
  36. package/dist/components/d-flow-function/DFlowFunction.input.hook.js +4 -5
  37. package/dist/components/d-flow-function/DFlowFunction.return.hook.js +1 -1
  38. package/dist/components/d-flow-function/DFlowFunction.view.d.ts +14 -11
  39. package/dist/components/d-flow-function/DFlowFunction.view.js +19 -12
  40. package/dist/components/d-flow-function/DFlowFunctionDefaultCard.js +72 -75
  41. package/dist/components/d-flow-function/DFlowFunctionSuggestionCard.js +27 -32
  42. package/dist/components/d-flow-function/DFlowFunctionTriggerCard.js +17 -10
  43. package/dist/components/d-flow-input/DFlowInputDataType.js +38 -33
  44. package/dist/components/d-flow-input/DFlowInputDefault.d.ts +10 -0
  45. package/dist/components/d-flow-input/DFlowInputDefault.js +128 -0
  46. package/dist/components/d-flow-input/DFlowInputLiteralBadge.d.ts +7 -0
  47. package/dist/components/d-flow-input/DFlowInputLiteralBadge.js +24 -0
  48. package/dist/components/d-flow-input/DFlowInputNodeBadge.d.ts +11 -0
  49. package/dist/components/d-flow-input/DFlowInputNodeBadge.js +44 -0
  50. package/dist/components/d-flow-input/DFlowInputReferenceBadge.d.ts +11 -0
  51. package/dist/components/d-flow-input/DFlowInputReferenceBadge.js +33 -0
  52. package/dist/components/d-flow-panel/DFlowExport.js +1 -1
  53. package/dist/components/d-flow-panel/DFlowMiniMap.js +1 -1
  54. package/dist/components/d-flow-panel/DFlowPanelControl.js +34 -32
  55. package/dist/components/d-flow-suggestion/DFlowDataTypeSuggestions.hook.d.ts +3 -0
  56. package/dist/components/d-flow-suggestion/DFlowDataTypeSuggestions.hook.js +34 -0
  57. package/dist/components/d-flow-suggestion/DFlowFunctionSuggestions.hook.d.ts +3 -0
  58. package/dist/components/d-flow-suggestion/DFlowFunctionSuggestions.hook.js +50 -0
  59. package/dist/components/d-flow-suggestion/DFlowReferenceSuggestions.hook.d.ts +3 -0
  60. package/dist/components/d-flow-suggestion/DFlowReferenceSuggestions.hook.js +133 -0
  61. package/dist/components/d-flow-suggestion/DFlowSuggestion.hook.d.ts +3 -18
  62. package/dist/components/d-flow-suggestion/DFlowSuggestion.hook.js +19 -156
  63. package/dist/components/d-flow-suggestion/DFlowSuggestionMenu.js +47 -58
  64. package/dist/components/d-flow-suggestion/DFlowSuggestionMenu.util.js +5 -4
  65. package/dist/components/d-flow-suggestion/DFlowSuggestionSearchInput.js +6 -6
  66. package/dist/components/d-flow-suggestion/DFlowValueSuggestions.hook.d.ts +3 -0
  67. package/dist/components/d-flow-suggestion/DFlowValueSuggestions.hook.js +44 -0
  68. package/dist/components/d-flow-type/DFlowType.view.d.ts +5 -5
  69. package/dist/components/d-flow-type/DFlowType.view.js +22 -12
  70. package/dist/components/d-flow-validation/DFlowValidation.hook.js +1 -1
  71. package/dist/components/d-flow-validation/DNodeValidation.hook.js +39 -43
  72. package/dist/components/d-resizable/DResizable.d.ts +4 -4
  73. package/dist/components/d-resizable/DResizable.js +22 -21
  74. package/dist/components/d-user/DUserInput.js +23 -21
  75. package/dist/components/file-tabs/FileTabs.service.d.ts +0 -1
  76. package/dist/components/file-tabs/FileTabs.service.js +49 -53
  77. package/dist/components/form/EmailInput.js +9 -9
  78. package/dist/components/form/Input.d.ts +2 -1
  79. package/dist/components/form/Input.js +294 -397
  80. package/dist/components/form/Input.syntax.hook.d.ts +1 -18
  81. package/dist/components/form/Input.syntax.hook.js +7 -73
  82. package/dist/components/form/Input.utils.d.ts +1 -2
  83. package/dist/components/form/Input.utils.js +26 -21
  84. package/dist/components/form/InputContentEditable.hook.d.ts +40 -0
  85. package/dist/components/form/InputContentEditable.hook.js +471 -0
  86. package/dist/components/form/InputSuggestion.d.ts +2 -2
  87. package/dist/components/form/InputSuggestion.js +169 -107
  88. package/dist/components/form/PasswordInput.js +8 -8
  89. package/dist/components/form/TextInput.js +11 -11
  90. package/dist/components/form/useForm.d.ts +1 -0
  91. package/dist/components/form/useForm.js +45 -60
  92. package/dist/components/menu/Menu.js +4 -4
  93. package/dist/index.js +155 -154
  94. package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js +30 -30
  95. package/dist/node_modules/@radix-ui/react-portal/dist/index.js +8 -8
  96. package/dist/node_modules/@radix-ui/react-primitive/dist/index.js +8 -8
  97. package/dist/node_modules/fast-deep-equal/index.js +31 -0
  98. package/dist/node_modules/object-assign/index.js +49 -0
  99. package/dist/node_modules/prop-types/checkPropTypes.js +54 -0
  100. package/dist/node_modules/prop-types/factoryWithThrowingShims.js +52 -0
  101. package/dist/node_modules/prop-types/factoryWithTypeCheckers.js +329 -0
  102. package/dist/node_modules/prop-types/index.js +17 -0
  103. package/dist/node_modules/prop-types/lib/ReactPropTypesSecret.js +10 -0
  104. package/dist/node_modules/prop-types/lib/has.js +7 -0
  105. package/dist/node_modules/prop-types/node_modules/react-is/cjs/react-is.development.js +87 -0
  106. package/dist/node_modules/prop-types/node_modules/react-is/cjs/react-is.production.min.js +70 -0
  107. package/dist/node_modules/prop-types/node_modules/react-is/index.js +10 -0
  108. package/dist/node_modules/react-contenteditable/lib/react-contenteditable.js +132 -0
  109. package/dist/node_modules/react-dom/cjs/react-dom-server-legacy.browser.development.js +6235 -0
  110. package/dist/node_modules/react-dom/cjs/react-dom-server-legacy.browser.production.js +4096 -0
  111. package/dist/node_modules/react-dom/cjs/react-dom-server.browser.development.js +6753 -0
  112. package/dist/node_modules/react-dom/cjs/react-dom-server.browser.production.js +4645 -0
  113. package/dist/node_modules/react-dom/server.browser.js +15 -0
  114. package/dist/utils/generics.d.ts +2 -0
  115. package/dist/utils/generics.js +93 -80
  116. package/dist/utils/index.js +22 -21
  117. package/dist/utils/inspection.d.ts +4 -2
  118. package/dist/utils/inspection.js +27 -2
  119. package/package.json +10 -8
  120. package/dist/components/form/Input.selection.hook.d.ts +0 -17
  121. package/dist/components/form/Input.selection.hook.js +0 -78
  122. package/dist/components/form/InputSyntax.d.ts +0 -19
  123. package/dist/components/form/InputSyntax.js +0 -52
  124. package/dist/components/form/inputSyntaxMapping.d.ts +0 -3
  125. package/dist/components/form/inputSyntaxMapping.js +0 -42
@@ -1,61 +1,136 @@
1
- import { jsx as y, jsxs as z, Fragment as lt } from "react/jsx-runtime";
2
- import d, { useRef as A, useState as L, useEffect as k, useMemo as Je } from "react";
1
+ import { jsx as f, jsxs as z } from "react/jsx-runtime";
2
+ import i, { useRef as y, useState as K, useMemo as L, useEffect as x } from "react";
3
+ import Qe from "../../_virtual/react-contenteditable.js";
3
4
  import "../../utils/contextStore.js";
4
- import { mergeCode0Props as ge } from "../../utils/utils.js";
5
+ import { mergeCode0Props as le } from "../../utils/utils.js";
5
6
  import '../../assets/components/form/Input.style.css';/* empty css */
6
- import { InputLabel as ut } from "./InputLabel.js";
7
- import { InputDescription as ct } from "./InputDescription.js";
8
- import { InputMessage as dt } from "./InputMessage.js";
9
- import { Menu as ft, MenuTrigger as gt, MenuPortal as mt } from "../menu/Menu.js";
10
- import { InputSuggestionMenuContent as pt, InputSuggestionMenuContentItems as ht } from "./InputSuggestion.js";
11
- import { InputSyntax as xt } from "./InputSyntax.js";
12
- import { useSyntaxModel as St } from "./Input.syntax.hook.js";
13
- import { useSelectionVisibility as vt, useSelectionNormalization as kt, useSelectionResolution as wt } from "./Input.selection.hook.js";
14
- import { setSelectionRangeSafe as T, getSelectionMetrics as U, setElementKey as Xe } from "./Input.utils.js";
15
- import { Card as yt } from "../card/Card.js";
16
- const It = d.forwardRef((te, Ye) => {
7
+ import { InputLabel as Xe } from "./InputLabel.js";
8
+ import { InputDescription as Ye } from "./InputDescription.js";
9
+ import { InputMessage as Ze } from "./InputMessage.js";
10
+ import { Menu as _e, MenuTrigger as et, MenuPortal as tt } from "../menu/Menu.js";
11
+ import { InputSuggestionMenuContent as nt, InputSuggestionMenuContentItems as rt } from "./InputSuggestion.js";
12
+ import { getSelectionMetrics as ot, setElementKey as st, setSelectionRangeSafe as at } from "./Input.utils.js";
13
+ import { Card as ut } from "../card/Card.js";
14
+ import { useContentEditableController as it } from "./InputContentEditable.hook.js";
15
+ const X = (u) => {
16
+ const k = u ?? "";
17
+ return typeof k == "string" ? k : String(k);
18
+ }, $e = (u) => {
19
+ if (u == null) return "";
20
+ if (typeof u == "string") return u;
21
+ try {
22
+ return JSON.stringify(u);
23
+ } catch {
24
+ return String(u ?? "");
25
+ }
26
+ }, Fe = (u) => {
27
+ if (!u) return null;
28
+ const k = u.value ?? "", Y = u.selectionStart ?? k.length, E = k.slice(0, Y).match(/\S+$/);
29
+ if (!E || E.index === void 0) return null;
30
+ const g = E[0], $ = E.index, N = $ + g.length;
31
+ return {
32
+ token: g,
33
+ start: $,
34
+ end: N
35
+ };
36
+ }, lt = i.forwardRef((u, k) => {
17
37
  const {
18
- wrapperComponent: Ge = {},
19
- title: me,
20
- description: pe,
21
- disabled: he = !1,
22
- left: xe,
23
- right: Se,
24
- leftType: Qe = "icon",
25
- rightType: Ze = "action",
26
- formValidation: I = {
38
+ wrapperComponent: Y = {},
39
+ title: Z,
40
+ description: E,
41
+ disabled: g = !1,
42
+ left: $,
43
+ right: N,
44
+ leftType: Be = "icon",
45
+ rightType: Ae = "action",
46
+ formValidation: V = {
27
47
  valid: !0,
28
48
  notValidMessage: null,
29
49
  setValue: null
30
50
  },
31
- suggestions: x,
32
- suggestionsHeader: ve,
33
- suggestionsFooter: ke,
34
- onSuggestionSelect: W,
35
- disableOnValue: we = () => !1,
36
- transformSyntax: ne,
37
- validationUsesSuggestions: j = !1,
38
- filterSuggestionsByLastToken: C = !1,
39
- enforceUniqueSuggestions: ye = !1,
40
- onLastTokenChange: re,
41
- suggestionsEmptyState: Ie,
42
- ...et
43
- } = te, {
44
- onFocus: be,
45
- onBlur: Me,
46
- onKeyDown: Ce,
47
- onKeyDownCapture: Ve,
48
- onChange: Ee,
49
- onInput: De,
50
- ...P
51
- } = et, a = Ye || A(null), N = A(null), _ = A(null), H = A(!0), V = A(null), tt = A(0), Re = A([]), Ae = A(null), [E, F] = L(!1), [m, nt] = L(te.defaultValue || te.initialValue), [J, Te] = L([]), [X, Fe] = L([]), [Le, O] = L(null), [se, $] = L(null), [Pe, Ne] = L(!1), Y = d.useMemo(() => we(m), [m, we]), ae = d.useMemo(() => ({
52
- ...P,
53
- onChange: Ee,
54
- onInput: De
55
- }), [P, Ee, De]), b = d.useCallback((e) => {
56
- const t = e ?? "";
57
- return typeof t == "string" ? t : String(t);
58
- }, []), Oe = d.useCallback((e, t, n) => {
51
+ suggestions: l,
52
+ suggestionsHeader: ce,
53
+ suggestionsFooter: fe,
54
+ onSuggestionSelect: de,
55
+ disableOnValue: pe = () => !1,
56
+ transformSyntax: P,
57
+ validationUsesSyntax: j = !1,
58
+ filterSuggestionsByLastToken: h = !1,
59
+ enforceUniqueSuggestions: ge = !1,
60
+ onLastTokenChange: he,
61
+ suggestionsEmptyState: me,
62
+ ...ze
63
+ } = u, {
64
+ onFocus: Se,
65
+ onBlur: _,
66
+ onKeyDown: q,
67
+ onKeyDownCapture: ee,
68
+ onChange: F,
69
+ onInput: B,
70
+ ...m
71
+ } = ze, W = y(null), d = y(null), H = y(null), M = y(null), te = y(null), D = y(!1), Ne = y(0), Ce = y(null), ne = m.value ?? u.initialValue ?? u.defaultValue, [ye, je] = K(!1), R = y(!1), a = i.useCallback((e) => {
72
+ R.current = e, je(e);
73
+ }, []), [w, re] = K(ne), [ve, be] = K([]), [ke, oe] = K([]), [we, qe] = K(null), [xe, Ee] = K(null), o = !!P, I = L(() => pe(w), [pe, w]), v = L(() => o ? H : d, [o]);
74
+ i.useImperativeHandle(k, () => v.current ?? null, [v]);
75
+ const We = L(() => ({
76
+ ...m,
77
+ onChange: F,
78
+ onInput: B
79
+ }), [m, F, B]), He = L(() => {
80
+ const {
81
+ value: e,
82
+ defaultValue: t,
83
+ ...n
84
+ } = m;
85
+ return le("input__control", n);
86
+ }, [m]), U = i.useCallback(() => {
87
+ const e = v.current;
88
+ !e || g || I || e.focus({
89
+ preventScroll: !0
90
+ });
91
+ }, [v, g, I]), T = i.useCallback(() => {
92
+ l && a(!0);
93
+ }, [l, a]), se = i.useCallback((e) => {
94
+ h && (qe(e), e && a(!0), he?.(e));
95
+ }, [h, he, a]), ae = i.useCallback((e, t) => {
96
+ if (!V?.setValue) return;
97
+ const n = m.type !== "checkbox" ? X(e) : e, r = j ? t : n;
98
+ Object.is(Ce.current, r) || (Ce.current = r, V.setValue(r));
99
+ }, [V?.setValue, m.type, j]), p = it({
100
+ editorRef: H,
101
+ transformSyntax: P,
102
+ filterSuggestionsByLastToken: h,
103
+ onLastTokenChange: se,
104
+ onStateChange: ({
105
+ value: e,
106
+ tokens: t,
107
+ segments: n
108
+ }) => {
109
+ re(e), oe(t), Ee(n ?? null), ae(e, n ?? null);
110
+ }
111
+ }), Ve = y(!1);
112
+ x(() => {
113
+ if (!o || !P || Ve.current) return;
114
+ const e = X(ne);
115
+ re(e), p.initializeFromExternalValue(e), j && P && Ee(P(e, [])), Ve.current = !0;
116
+ }, [o, P, ne, j, p]), x(() => {
117
+ o || m.value !== void 0 && re(m.value);
118
+ }, [m.value, o]), x(() => {
119
+ ae(w, xe);
120
+ }, [ae, xe, w]), x(() => {
121
+ if (!l) return;
122
+ const e = (t) => {
123
+ const n = t.target, r = !!H.current?.contains(n), s = !!d.current?.contains(n), c = !!te.current?.contains(n), S = !!W.current?.contains(n), C = r || s || c || S;
124
+ D.current = C, !C && R.current && a(!1);
125
+ };
126
+ return document.addEventListener("pointerdown", e, !0), () => document.removeEventListener("pointerdown", e, !0);
127
+ }, [l, a]), x(() => {
128
+ const e = W.current;
129
+ if (!e) return;
130
+ const t = () => T();
131
+ return e.addEventListener("focusin", t), () => e.removeEventListener("focusin", t);
132
+ }, [T]);
133
+ const De = i.useCallback((e, t, n) => {
59
134
  if (e.length === 0) return t <= n.length ? t : null;
60
135
  let r = n.indexOf(e);
61
136
  if (r === -1) return null;
@@ -63,388 +138,210 @@ const It = d.forwardRef((te, Ye) => {
63
138
  for (; s !== -1; )
64
139
  Math.abs(s - t) < Math.abs(r - t) && (r = s), s = n.indexOf(e, s + 1);
65
140
  return r;
66
- }, []), G = d.useCallback((e, t) => {
141
+ }, []), J = i.useCallback((e, t) => {
67
142
  const n = [];
68
143
  return e.forEach((r) => {
69
- const s = Oe(r.text, r.start, t);
144
+ const s = De(r.text, r.start, t);
70
145
  if (s === null) return;
71
- const i = s + r.text.length;
72
- t.slice(s, i) === r.text && n.push({
146
+ const c = s + r.text.length;
147
+ t.slice(s, c) === r.text && n.push({
73
148
  ...r,
74
149
  start: s,
75
- end: i
150
+ end: c
76
151
  });
77
152
  }), n;
78
- }, [Oe]);
79
- k(() => {
80
- Re.current = X;
81
- }, [X]), k(() => {
82
- const e = a.current;
83
- if (!e || !I?.setValue) return;
84
- const t = (n) => {
85
- const r = P.type !== "checkbox" ? n.target.value : n.target.checked, s = j ? Re.current : r;
86
- I.setValue?.(s);
87
- };
88
- return e.addEventListener("change", t), () => e.removeEventListener("change", t);
89
- }, [I?.setValue, P.type, a, j]), k(() => {
90
- if (!x) return;
91
- const e = (t) => {
92
- const n = t.target, r = !!a.current?.contains(n), s = !!_.current?.contains(n);
93
- H.current = r || s;
94
- };
95
- return document.addEventListener("pointerdown", e, !0), () => document.removeEventListener("pointerdown", e, !0);
96
- }, [a, x]), k(() => {
97
- const e = a.current;
98
- if (!e) return;
99
- const t = (n) => {
100
- Y || nt(n.target.value);
101
- };
102
- return e.addEventListener("change", t), e.addEventListener("input", t), () => {
103
- e.removeEventListener("change", t), e.removeEventListener("input", t);
104
- };
105
- }, [Y, a]), k(() => {
106
- const e = b(a.current?.value ?? m);
107
- Te((t) => {
108
- const n = G(t, e);
109
- return Fe(n.map((r) => r.suggestion)), n;
153
+ }, [De]);
154
+ x(() => {
155
+ if (o) return;
156
+ const e = X(d.current?.value ?? w);
157
+ be((t) => {
158
+ const n = J(t, e);
159
+ return oe(n.map((r) => r.suggestion)), n;
110
160
  });
111
- }, [b, G, m]);
112
- const $e = d.useCallback((e, t) => {
113
- const n = b(e), r = [...t].sort((l, o) => l.start - o.start), s = [];
114
- let i = 0;
115
- return r.forEach((l) => {
116
- if (l.start < i) return;
117
- const o = Math.min(l.end, n.length);
118
- i < l.start && s.push(n.slice(i, l.start));
119
- const c = l.suggestion?.value ?? l.text ?? "", g = c == null ? "" : String(c), u = Math.max(o - l.start, g.length);
120
- u > 0 ? (s.push(l.suggestion), i = l.start + u) : i = l.start;
121
- }), i < n.length && s.push(n.slice(i)), s.length ? s : [n];
122
- }, [b]);
123
- k(() => {
124
- if (!I?.setValue) return;
125
- const e = P.type !== "checkbox" ? b(a.current?.value ?? m) : m, t = j ? X : e;
126
- Object.is(Ae.current, t) || (Ae.current = t, I.setValue(t));
127
- }, [X, I?.setValue, P.type, a, b, j, m]);
128
- const Be = d.useCallback(() => {
129
- setTimeout(() => {
130
- const e = a.current;
131
- if (!e) return;
132
- e.focus({
133
- preventScroll: !0
134
- });
135
- const t = e.value.length;
136
- T(e, t, t), e.scrollLeft = e.scrollWidth;
137
- }, 0);
138
- }, [a]), oe = d.useMemo(() => $e(m, J), [J, $e, m]), f = d.useMemo(() => {
139
- if (ne)
140
- return (e, t = oe) => ne(e, t);
141
- }, [oe, ne]), {
142
- syntaxSegments: ie,
143
- visualizedSyntaxSegments: M,
144
- expandSelectionRangeToBlockBoundaries: B,
145
- mapVisualIndexToRawIndex: K,
146
- mapRawIndexToVisualIndex: D,
147
- totalVisualLength: le
148
- } = St(m, f, a, oe), w = d.useMemo(() => {
149
- const e = b(a.current?.value ?? m);
150
- if (!C || !ie?.length) return null;
151
- const t = [...ie].reverse().find((h) => h?.type === "text" && h?.end === e.length);
152
- if (!t) return null;
153
- const n = e.slice(t.start, t.end), r = n.trim();
154
- if (!r.length) return null;
155
- const s = r.split(/\s+/), i = s[s.length - 1]?.trim();
156
- if (!i) return null;
157
- const l = n.search(/\S/), o = l === -1 ? 0 : l, c = r.lastIndexOf(i), g = t.start + o + c, u = g + i.length;
158
- return {
159
- token: i,
160
- start: g,
161
- end: u
162
- };
163
- }, [C, a, b, ie, m]);
164
- k(() => {
165
- C && re && (w?.token && F(!0), re(w?.token ?? null));
166
- }, [C, re, w?.token]);
167
- const q = d.useMemo(() => {
168
- if (!C || !x) return x;
169
- const e = w?.token?.trim();
170
- return e?.length ? x.filter((t) => {
171
- const n = t?.value ?? "";
172
- return (n == null ? "" : String(n)).toLowerCase().startsWith(e.toLowerCase());
173
- }) : x;
174
- }, [C, w?.token, x]), Q = d.useMemo(() => {
175
- if (!ye || !q) return q;
176
- const e = new Set(J.map((t) => t.suggestion));
177
- return q.filter((t) => !e.has(t));
178
- }, [J, ye, q]), {
179
- ensureVisualIndexVisible: Z,
180
- syncSyntaxScroll: S
181
- } = vt(a, _), Ke = kt(f, B), p = d.useCallback(() => {
182
- if (!f) return;
183
- const e = a.current;
161
+ }, [o, J, w]), x(() => {
162
+ if (!h || o) return;
163
+ const e = d.current;
184
164
  if (!e) return;
185
- const {
186
- rawStart: t,
187
- rawEnd: n
188
- } = U(e), r = M.find((u) => u?.type !== "block" ? !1 : t > u?.start && t < u?.end);
189
- if (r && t === n) {
190
- const u = t - r.start, h = r.end - t, v = u <= h ? r.start : r.end;
191
- T(e, v, v);
192
- const R = v === r.start ? r.visualStart : r.visualEnd;
193
- O(null), $(R), requestAnimationFrame(() => {
194
- S(), Z(R);
195
- });
196
- return;
197
- }
198
- if (t === n) {
199
- const u = Math.round(D(t));
200
- O(null), $(Number.isFinite(u) ? u : null), requestAnimationFrame(() => {
201
- S(), Z(u);
202
- });
203
- return;
204
- }
205
- let s = D(t), i = D(n);
206
- M.forEach((u) => {
207
- u?.type !== "block" || !(t < u?.end && n > u?.start) || (s = Math.min(s, u?.visualStart), i = Math.max(i, u?.visualEnd));
208
- });
209
- const l = Math.min(s, i), o = Math.max(s, i);
210
- $(null), O({
211
- start: l,
212
- end: o
213
- });
214
- const g = (e.selectionDirection === "backward" ? "backward" : "forward") === "backward" ? l : o;
215
- requestAnimationFrame(() => {
216
- S(), Z(g);
217
- });
218
- }, [Z, a, D, S, f, M]), qe = wt(f, a, Le, M, D), ze = d.useCallback((e) => {
219
- if (!e) return null;
220
- const t = e.dataset.rawIndex, n = e.dataset.visualIndex || e.dataset.visualStart || e.dataset.visualEnd, r = t ? Number(t) : void 0, s = n ? Number(n) : void 0;
221
- return !Number.isNaN(r) && r !== void 0 ? r : s !== void 0 ? K(s) : null;
222
- }, [K]), ee = d.useCallback((e) => {
223
- const t = document.elementFromPoint(e.clientX, e.clientY);
224
- return ze(t ?? e.target);
225
- }, [ze]), Ue = d.useCallback((e) => {
226
- if (!a.current) return;
227
- const t = ee(e);
228
- if (t === null || Number.isNaN(t)) return;
229
- e.preventDefault(), H.current = !0;
230
- const n = Math.min(Math.max(t, 0), a.current.value.length), {
231
- selectionStart: r
232
- } = U(a.current), s = e.shiftKey && Number.isFinite(r) ? r : n;
233
- V.current = s, a.current.focus({
234
- preventScroll: !0
235
- }), T(a.current, s, n), _.current?.setPointerCapture(e.pointerId), p();
236
- }, [a, ee, p]), We = d.useCallback((e) => {
237
- if (!a.current || V.current === null) return;
238
- if (!(e.buttons & 1)) {
239
- V.current = null;
240
- return;
241
- }
242
- const t = ee(e);
243
- if (t === null || Number.isNaN(t)) return;
244
- e.preventDefault();
245
- const n = V.current, r = Math.min(Math.max(t, 0), a.current.value.length);
246
- a.current.focus({
247
- preventScroll: !0
248
- }), T(a.current, n, r), p();
249
- }, [a, ee, p]), je = d.useCallback(() => {
250
- V.current = null;
251
- }, []), _e = d.useCallback((e) => {
252
- if (!f) return !1;
253
- const t = e.target, {
254
- rawStart: n,
255
- rawEnd: r
256
- } = U(t), s = (o, c) => {
257
- if (o === c) return !1;
258
- e.preventDefault();
259
- const g = `${t.value.slice(0, o)}${t.value.slice(c)}`;
260
- return Xe(t, "value", g, "input"), requestAnimationFrame(() => {
261
- T(t, o, o), p();
262
- }), !0;
165
+ const t = () => se(Fe(e)?.token ?? null);
166
+ return e.addEventListener("input", t), e.addEventListener("keyup", t), e.addEventListener("mouseup", t), t(), () => {
167
+ e.removeEventListener("input", t), e.removeEventListener("keyup", t), e.removeEventListener("mouseup", t);
263
168
  };
264
- if (n !== r) {
265
- const {
266
- start: o,
267
- end: c,
268
- hasBlockOverlap: g
269
- } = B(n, r);
270
- return g ? s(o, c) : !1;
271
- }
272
- const i = M.find((o) => o?.type !== "block" ? !1 : n === o?.end || n > o?.start && n < o?.end);
273
- if (e.key === "Backspace" && i)
274
- return s(i.start, i.end);
275
- const l = M.find((o) => o?.type !== "block" ? !1 : n === o?.start || n > o?.start && n < o?.end);
276
- return e.key === "Delete" && l ? s(l.start, l.end) : !1;
277
- }, [B, f, p, M]), ue = d.useCallback((e) => {
278
- if (f && Ke(e.target), f && (e.key === "ArrowLeft" || e.key === "ArrowRight")) {
279
- const t = e.target, {
280
- selectionStart: n,
281
- selectionEnd: r,
282
- rawStart: s,
283
- rawEnd: i,
284
- direction: l
285
- } = U(t), o = e.key === "ArrowLeft" ? -1 : 1;
286
- if (e.shiftKey) {
287
- const c = V.current ?? (l === "backward" ? r : n);
288
- V.current = c;
289
- const u = Math.round(D(c === n ? r : n)), h = Math.max(0, Math.min(u + o, le)), v = K(h);
290
- if (!Number.isNaN(v)) {
291
- e.preventDefault();
292
- const R = Math.min(Math.max(Math.round(v), 0), t.value.length), at = R < c ? "backward" : "forward", ot = Math.min(c, R), it = Math.max(c, R);
293
- T(t, ot, it, at), requestAnimationFrame(() => {
294
- S(), p();
295
- });
296
- }
297
- } else {
298
- V.current = null;
299
- const c = e.key === "ArrowLeft" ? s : i, g = Math.round(D(c)), u = Math.max(0, Math.min(g + o, le)), h = K(u);
300
- if (!Number.isNaN(h)) {
301
- e.preventDefault();
302
- const v = Math.min(Math.max(Math.round(h), 0), t.value.length);
303
- T(t, v, v), requestAnimationFrame(() => {
304
- S(), p();
305
- });
306
- }
307
- }
308
- if (e.defaultPrevented) return;
309
- }
310
- if (!(f && (e.key === "Backspace" || e.key === "Delete") && _e(e)) && x) {
311
- if (e.key === "ArrowDown") {
312
- e.preventDefault();
313
- const t = E;
314
- F(!0), t ? N.current?.highlightNextItem() : setTimeout(() => N.current?.focusFirstItem(), 0);
315
- } else if (e.key === "ArrowUp") {
316
- e.preventDefault();
317
- const t = E;
318
- F(!0), t ? N.current?.highlightPreviousItem() : setTimeout(() => N.current?.focusLastItem(), 0);
319
- } else e.key === "Enter" && E && N.current?.selectActiveItem() && F(!1);
320
- Ce?.(e);
169
+ }, [h, o, se]);
170
+ const O = L(() => {
171
+ if (!h || !l) return l;
172
+ const e = we?.trim();
173
+ return e?.length ? l.filter((t) => String(t?.value ?? "").toLowerCase().startsWith(e.toLowerCase())) : l;
174
+ }, [h, we, l]), G = L(() => {
175
+ if (!ge || !O) return O;
176
+ if (o) {
177
+ const t = new Set((ke ?? []).map((n) => $e(n?.value ?? n)));
178
+ return O.filter((n) => !t.has($e(n?.value ?? n)));
321
179
  }
322
- }, [_e, D, K, Ke, E, x, S, le, f, p, Ce]), ce = d.useCallback((e) => {
323
- (e.key === " " || e.code === "Space") && (e.stopPropagation(), e.nativeEvent?.stopImmediatePropagation?.()), Ve?.(e);
324
- }, [Ve]), de = d.useCallback((e) => {
325
- Ne(!0), requestAnimationFrame(() => {
326
- p(), S();
327
- }), x && !E && F(!0), be?.(e);
328
- }, [E, x, S, p, be]), fe = d.useCallback((e) => {
329
- Ne(!1), $(null), O(null), Me?.(e);
330
- }, [Me]);
331
- k(() => {
332
- const e = a.current;
333
- if (!e || !f) return;
334
- const t = () => requestAnimationFrame(p);
335
- t();
336
- const n = ["select", "keyup", "mouseup", "input", "keydown"];
337
- return n.forEach((r) => e.addEventListener(r, t)), () => {
338
- n.forEach((r) => e.removeEventListener(r, t));
339
- };
340
- }, [a, f, p]), k(() => {
341
- if (!f) return;
342
- const e = () => {
343
- document.activeElement === a.current && p();
344
- };
345
- return document.addEventListener("selectionchange", e), () => document.removeEventListener("selectionchange", e);
346
- }, [a, f, p]), k(() => {
347
- const e = a.current;
348
- if (!e) return;
349
- const t = () => S();
350
- return t(), e.addEventListener("scroll", t), () => e.removeEventListener("scroll", t);
351
- }, [a, S]), k(() => {
352
- S();
353
- }, [S, m, se, Le]), k(() => {
354
- f || (O(null), $(null));
355
- }, [f]);
356
- const He = d.useCallback((e) => {
357
- if (!a.current) return;
358
- const t = typeof m == "object" ? JSON.stringify(e.value) : e.value, n = t == null ? "" : String(t), r = e.insertMode ?? "replace", s = a.current.value ?? "";
359
- let i = s, l = null, o = 0;
360
- if (C && w)
361
- i = `${s.slice(0, w.start)}${n}${s.slice(w.end)}`, l = w.start + n.length, o = w.start;
180
+ const e = new Set(ve.map((t) => t.suggestion));
181
+ return O.filter((t) => !e.has(t));
182
+ }, [ve, ke, ge, O, o]), Ie = i.useCallback((e) => {
183
+ if (!d.current) return;
184
+ const t = typeof w == "object" ? JSON.stringify(e.value) : e.value, n = t == null ? "" : String(t), r = e.insertMode ?? "replace", s = d.current.value ?? "";
185
+ let c = s, S = null, C = 0;
186
+ const A = h ? Fe(d.current) : null;
187
+ if (h && A)
188
+ c = `${s.slice(0, A.start)}${n}${s.slice(A.end)}`, S = A.start + n.length, C = A.start;
362
189
  else
363
190
  switch (r) {
364
- case "append": {
365
- i = `${s}${n}`, l = i.length, o = s.length;
191
+ case "append":
192
+ c = `${s}${n}`, S = c.length, C = s.length;
366
193
  break;
367
- }
368
- case "prepend": {
369
- i = `${n}${s}`, l = n.length, o = 0;
194
+ case "prepend":
195
+ c = `${n}${s}`, S = n.length, C = 0;
370
196
  break;
371
- }
372
197
  case "insert": {
373
198
  const {
374
- rawStart: c,
375
- rawEnd: g
376
- } = U(a.current), {
377
- start: u,
378
- end: h
379
- } = f ? B(c, g) : {
380
- start: c,
381
- end: g
382
- };
383
- i = `${s.slice(0, u)}${n}${s.slice(h)}`, l = u + n.length, o = u;
199
+ rawStart: b,
200
+ rawEnd: ie
201
+ } = ot(d.current);
202
+ c = `${s.slice(0, b)}${n}${s.slice(ie)}`, S = b + n.length, C = b;
384
203
  break;
385
204
  }
386
205
  case "replace":
387
- default: {
388
- i = n, l = n.length, o = 0;
206
+ default:
207
+ c = n, S = n.length, C = 0;
389
208
  break;
390
- }
391
209
  }
392
- Xe(a.current, "value", i, "change"), Te((c) => {
393
- const g = b(i), u = G(c, g), h = n.length ? {
394
- id: tt.current++,
210
+ st(d.current, "value", c, "change"), be((b) => {
211
+ const ie = X(c), Te = J(b, ie), Oe = n.length ? {
212
+ id: Ne.current++,
395
213
  suggestion: e,
396
214
  text: n,
397
- start: o,
398
- end: o + n.length
399
- } : null, v = h ? [...u, h] : u;
400
- return Fe(v.map((R) => R.suggestion)), v;
401
- }), l !== null && requestAnimationFrame(() => {
402
- const c = a.current;
403
- c && (c.focus({
215
+ start: C,
216
+ end: C + n.length
217
+ } : null, Ke = Oe ? [...Te, Oe] : Te;
218
+ return oe(Ke.map((Ge) => Ge.suggestion)), Ke;
219
+ }), S !== null && requestAnimationFrame(() => {
220
+ const b = d.current;
221
+ b && (b.focus({
404
222
  preventScroll: !0
405
- }), T(c, l, l));
223
+ }), at(b, S, S));
224
+ });
225
+ }, [h, J, w]), Le = i.useCallback((e) => {
226
+ if (o ? p.applySuggestionValueSyntax(e) : Ie(e), de?.(e), o) {
227
+ const t = v.current;
228
+ requestAnimationFrame(() => {
229
+ if (!t) return;
230
+ const n = {
231
+ type: "change",
232
+ target: t,
233
+ currentTarget: t
234
+ };
235
+ t.dispatchEvent(new Event("input", {
236
+ bubbles: !0
237
+ })), B?.(n), F?.(n);
238
+ });
239
+ }
240
+ a(!1), D.current = !1, requestAnimationFrame(() => {
241
+ U();
406
242
  });
407
- }, [B, C, a, b, G, w, f, m]), rt = Je(() => /* @__PURE__ */ y(xt, { transformSyntax: f, syntaxRef: _, visualizedSyntaxSegments: M, resolvedVisualSelectionRange: qe, visualCaretIndex: se, isFocused: Pe, onPointerDown: Ue, onPointerMove: We, onPointerUp: je }), [Ue, je, We, Pe, qe, f, se, M]), st = Je(() => /* @__PURE__ */ z(ft, { open: E, modal: !1, onOpenChange: (e) => {
408
- if (!e && H.current) {
409
- H.current = !1;
243
+ }, [v, Ie, p, U, o, de, a, F, B]), Pe = i.useCallback((e) => {
244
+ T(), Se?.(e);
245
+ }, [T, Se]), Q = i.useCallback((e) => {
246
+ if (D.current) {
247
+ _?.(e);
248
+ return;
249
+ }
250
+ a(!1), _?.(e);
251
+ }, [_, a]), Me = i.useCallback((e) => {
252
+ if (o) {
253
+ p.handleKeyDownCapture(e), ee?.(e);
254
+ return;
255
+ }
256
+ (e.key === " " || e.code === "Space") && (e.stopPropagation(), e.nativeEvent?.stopImmediatePropagation?.()), ee?.(e);
257
+ }, [p, o, ee]), Re = i.useCallback((e) => {
258
+ if (l) {
259
+ if (e.key === "ArrowDown") {
260
+ e.preventDefault(), e.stopPropagation(), R.current ? M.current?.highlightNextItem?.() : (a(!0), setTimeout(() => M.current?.focusFirstItem?.(), 0));
261
+ return;
262
+ }
263
+ if (e.key === "ArrowUp") {
264
+ e.preventDefault(), e.stopPropagation(), R.current ? M.current?.highlightPreviousItem?.() : (a(!0), setTimeout(() => M.current?.focusLastItem?.(), 0));
265
+ return;
266
+ }
267
+ if (e.key === "Enter" && R.current) {
268
+ e.preventDefault(), e.stopPropagation(), M.current?.selectActiveItem?.() && a(!1);
269
+ return;
270
+ }
271
+ if (e.key === "Escape" && R.current) {
272
+ e.preventDefault(), e.stopPropagation(), a(!1);
273
+ return;
274
+ }
275
+ }
276
+ if (o && p.handleKeyDown(e)) {
277
+ q?.(e);
278
+ return;
279
+ }
280
+ if (o && e.key === "Enter") {
281
+ e.preventDefault(), q?.(e);
410
282
  return;
411
283
  }
412
- F(e), e && setTimeout(() => a.current?.focus(), 0);
284
+ q?.(e);
285
+ }, [p, o, l, a, q]), ue = o ? /* @__PURE__ */ f(Qe, { innerRef: H, html: p.editorHtml, ...He, disabled: g || I, onChange: (e) => {
286
+ p.handleChange(e), F?.(e), B?.(e);
287
+ }, onPaste: p.handlePaste, onFocus: Pe, onBlur: Q, onKeyDownCapture: Me, onKeyDown: Re, spellCheck: !1, contentEditable: !g && !I }) : /* @__PURE__ */ f("input", { ref: d, ...le("input__control", We), onFocus: Pe, onBlur: Q, onKeyDownCapture: Me, onKeyDown: Re, spellCheck: !1, disabled: g || I }), Ue = i.useCallback((e) => {
288
+ if (g || I) return;
289
+ const t = e.target;
290
+ te.current?.contains(t) || (D.current = !0, U(), T());
291
+ }, [g, I, U, T]);
292
+ x(() => {
293
+ const e = W.current;
294
+ if (!e) return;
295
+ const t = (n) => {
296
+ const r = n.relatedTarget;
297
+ r && e.contains(r) || Q(n);
298
+ };
299
+ return e.addEventListener("focusout", t), () => e.removeEventListener("focusout", t);
300
+ }, [Q]);
301
+ const Je = L(() => /* @__PURE__ */ z(_e, { open: ye, modal: !1, onOpenChange: (e) => {
302
+ !e && D.current || a(e);
413
303
  }, children: [
414
- /* @__PURE__ */ y(gt, { asChild: !0, children: /* @__PURE__ */ y("input", { ref: a, ...ge(`input__control ${f ? "input__control--syntax" : ""}`, ae), onFocus: de, onBlur: fe, onKeyDownCapture: ce, onKeyDown: ue, spellCheck: !1, disabled: he || Y }) }),
415
- /* @__PURE__ */ y(mt, { children: /* @__PURE__ */ z(pt, { color: "secondary", inputRef: a, children: [
416
- ve,
417
- /* @__PURE__ */ z(yt, { paddingSize: "xxs", mt: -0.35, mx: -0.35, style: {
304
+ /* @__PURE__ */ f(et, { asChild: !0, children: /* @__PURE__ */ f("button", { type: "button", tabIndex: -1, "aria-hidden": !0, style: {
305
+ position: "absolute",
306
+ inset: 0,
307
+ opacity: 0,
308
+ pointerEvents: "none"
309
+ }, onMouseDown: (e) => e.preventDefault() }) }),
310
+ ue,
311
+ /* @__PURE__ */ f(tt, { children: /* @__PURE__ */ f("div", { ref: te, onPointerDownCapture: () => {
312
+ D.current = !0;
313
+ }, onMouseDownCapture: (e) => {
314
+ e.preventDefault(), D.current = !0;
315
+ }, children: /* @__PURE__ */ z(nt, { color: "secondary", inputRef: v, children: [
316
+ ce,
317
+ /* @__PURE__ */ z(ut, { paddingSize: "xxs", mt: -0.35, mx: -0.35, style: {
418
318
  borderWidth: "2px"
419
319
  }, children: [
420
- Q?.length === 0 && Ie,
421
- !!Q?.length && /* @__PURE__ */ y(
422
- ht,
320
+ G?.length === 0 && me,
321
+ !!G?.length && /* @__PURE__ */ f(
322
+ rt,
423
323
  {
424
- ref: N,
425
- inputRef: a,
426
- suggestions: Q,
427
- onSuggestionSelect: (e) => {
428
- W ? W?.(e) : He(e), F(!1), W && Be();
429
- }
324
+ ref: M,
325
+ inputRef: v,
326
+ suggestions: G,
327
+ onSuggestionSelect: Le
430
328
  }
431
329
  )
432
330
  ] }),
433
- ke
434
- ] }) })
435
- ] }), [He, Q, Y, Be, fe, de, ue, ce, a, ae, W, E, Ie, ke, ve, f]);
436
- return /* @__PURE__ */ z(lt, { children: [
437
- me && /* @__PURE__ */ y(ut, { children: me }),
438
- pe && /* @__PURE__ */ y(ct, { children: pe }),
439
- /* @__PURE__ */ z("div", { ...ge(`input ${I?.valid ? "" : "input--not-valid"}`, Ge), children: [
440
- xe && /* @__PURE__ */ y("div", { className: `input__left input__left--${Qe}`, children: xe }),
441
- x ? st : /* @__PURE__ */ y("input", { tabIndex: 2, ref: a, disabled: he, onFocus: de, onBlur: fe, onKeyDownCapture: ce, onKeyDown: ue, ...ge(`input__control ${f ? "input__control--syntax" : ""}`, ae) }),
442
- rt,
443
- Se && /* @__PURE__ */ y("div", { className: `input__right input__right--${Ze}`, children: Se })
331
+ fe
332
+ ] }) }) })
333
+ ] }), [ye, ue, o, G, ce, fe, me, Le, v, a]);
334
+ return /* @__PURE__ */ z("div", { children: [
335
+ Z && /* @__PURE__ */ f(Xe, { children: Z }),
336
+ E && /* @__PURE__ */ f(Ye, { children: E }),
337
+ /* @__PURE__ */ z("div", { ref: W, ...le(`input ${V?.valid ? "" : "input--not-valid"}`, Y), onPointerDown: Ue, children: [
338
+ $ && /* @__PURE__ */ f("div", { className: `input__left input__left--${Be}`, children: $ }),
339
+ l ? Je : ue,
340
+ N && /* @__PURE__ */ f("div", { className: `input__right input__right--${Ae}`, children: N })
444
341
  ] }),
445
- !I?.valid && I?.notValidMessage && /* @__PURE__ */ y(dt, { children: I.notValidMessage })
342
+ !V?.valid && V?.notValidMessage && /* @__PURE__ */ f(Ze, { children: V.notValidMessage })
446
343
  ] });
447
- }), Bt = It;
344
+ }), xt = lt;
448
345
  export {
449
- Bt as Input
346
+ xt as Input
450
347
  };