@code0-tech/pictor 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/components/alert/Alert.style.css +1 -1
- package/dist/assets/components/avatar/Avatar.style.css +1 -1
- package/dist/assets/components/badge/Badge.style.css +1 -1
- package/dist/assets/components/breadcrumb/Breadcrumb.style.css +1 -1
- package/dist/assets/components/button/Button.style.css +1 -1
- package/dist/assets/components/button-group/ButtonGroup.style.css +1 -1
- package/dist/assets/components/card/Card.style.css +1 -1
- package/dist/assets/components/chart/Chart.style.css +1 -1
- package/dist/assets/components/command/Command.style.css +1 -1
- package/dist/assets/components/context-menu/ContextMenu.style.css +1 -1
- package/dist/assets/components/data-table/DataTable.style.css +1 -1
- package/dist/assets/components/dialog/Dialog.style.css +1 -1
- package/dist/assets/components/editor/Editor.styles.css +1 -1
- package/dist/assets/components/file-tabs/FileTabs.style.css +1 -1
- package/dist/assets/components/form/ColorInput.style.css +1 -1
- package/dist/assets/components/form/DateInput.style.css +1 -1
- package/dist/assets/components/form/EditorInput.style.css +1 -1
- package/dist/assets/components/form/Input.style.css +1 -1
- package/dist/assets/components/form/InputWrapper.style.css +1 -1
- package/dist/assets/components/form/SelectInput.style.css +1 -1
- package/dist/assets/components/json-view/JsonView.style.css +1 -1
- package/dist/assets/components/menu/Menu.style.css +1 -1
- package/dist/assets/components/resizable/Resizable.style.css +1 -1
- package/dist/assets/components/segmented-control/SegmentedControl.style.css +1 -1
- package/dist/assets/components/spacing/Spacing.style.css +1 -1
- package/dist/assets/components/tab/Tab.style.css +1 -1
- package/dist/assets/components/text/Text.style.css +1 -1
- package/dist/assets/components/toast/Toast.style.css +1 -1
- package/dist/assets/components/tooltip/Tooltip.style.css +1 -1
- package/dist/components/command/Command.js +35 -38
- package/dist/components/form/DateInput.js +82 -86
- package/dist/components/form/EditorInput.d.ts +26 -10
- package/dist/components/form/EditorInput.js +520 -148
- package/dist/components/form/EmailInput.js +16 -15
- package/dist/components/form/Input.d.ts +0 -20
- package/dist/components/form/Input.js +47 -432
- package/dist/components/form/InputWrapper.d.ts +0 -1
- package/dist/components/form/InputWrapper.js +52 -48
- package/dist/components/form/NumberInput.js +17 -16
- package/dist/components/form/PasswordInput.js +23 -22
- package/dist/components/form/TagInput.d.ts +30 -0
- package/dist/components/form/TagInput.js +117 -0
- package/dist/components/form/TextInput.js +12 -11
- package/dist/components/form/index.d.ts +1 -2
- package/dist/components/form/index.js +77 -70
- package/dist/components/layout/Layout.js +37 -37
- package/dist/components/menu/Menu.d.ts +2 -2
- package/dist/components/menu/Menu.js +87 -87
- package/dist/components/scroll-area/ScrollArea.js +1 -1
- package/dist/index.js +220 -213
- package/dist/utils/index.js +11 -11
- package/dist/utils/size.d.ts +3 -3
- package/dist/utils/size.js +12 -6
- package/package.json +1 -1
- package/dist/components/form/Input.syntax.hook.d.ts +0 -10
- package/dist/components/form/Input.syntax.hook.js +0 -14
- package/dist/components/form/InputContentEditable.hook.d.ts +0 -52
- package/dist/components/form/InputContentEditable.hook.js +0 -449
- package/dist/components/form/InputSuggestion.d.ts +0 -27
- package/dist/components/form/InputSuggestion.js +0 -218
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
|
-
import { InputSuggestion } from './InputSuggestion';
|
|
3
|
-
import { InputSyntaxSegment } from './Input.syntax.hook';
|
|
4
|
-
/**
|
|
5
|
-
* =========================
|
|
6
|
-
* Types
|
|
7
|
-
* =========================
|
|
8
|
-
*/
|
|
9
|
-
type EditorPart = string | InputSuggestion | any;
|
|
10
|
-
export type UseContentEditableControllerProps = {
|
|
11
|
-
editorRef: React.RefObject<HTMLElement>;
|
|
12
|
-
transformSyntax?: ((value: any, appliedSyntaxParts?: (InputSuggestion | any)[]) => InputSyntaxSegment[]) | undefined;
|
|
13
|
-
filterSuggestionsByLastToken?: boolean;
|
|
14
|
-
onLastTokenChange?: (token: string | null) => void;
|
|
15
|
-
onStateChange?: (payload: {
|
|
16
|
-
value: string;
|
|
17
|
-
tokens: InputSuggestion[];
|
|
18
|
-
segments?: InputSyntaxSegment[] | null;
|
|
19
|
-
}) => void;
|
|
20
|
-
};
|
|
21
|
-
export type UseContentEditableControllerReturn = {
|
|
22
|
-
editorHtml: string;
|
|
23
|
-
setEditorHtml: React.Dispatch<React.SetStateAction<string>>;
|
|
24
|
-
initializeFromExternalValue: (externalValue: string) => string;
|
|
25
|
-
updateEditorState: (rootEl: HTMLElement | null) => void;
|
|
26
|
-
takePendingSelection: () => {
|
|
27
|
-
start: number;
|
|
28
|
-
end: number;
|
|
29
|
-
} | null;
|
|
30
|
-
applySuggestionValueSyntax: (suggestion: InputSuggestion) => void;
|
|
31
|
-
handlePaste: (event: React.ClipboardEvent<HTMLDivElement>) => void;
|
|
32
|
-
handleChange: (event: React.FormEvent<HTMLDivElement>) => void;
|
|
33
|
-
handleKeyDownCapture: (event: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
34
|
-
handleKeyDown: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;
|
|
35
|
-
};
|
|
36
|
-
export declare const serializeEditorParts: (rootEl: HTMLElement | null) => EditorPart[];
|
|
37
|
-
/**
|
|
38
|
-
* ✅ FIX (caret after deleting last token):
|
|
39
|
-
* Selection can have startContainer = ELEMENT_NODE with an offset (i.e. “between childNodes”).
|
|
40
|
-
*/
|
|
41
|
-
export declare const getSelectionOffsetsInValue: (rootEl: HTMLElement) => {
|
|
42
|
-
start: number;
|
|
43
|
-
end: number;
|
|
44
|
-
} | null;
|
|
45
|
-
export declare const setSelectionOffsetsInValue: (rootEl: HTMLElement, start: number, end: number) => void;
|
|
46
|
-
/**
|
|
47
|
-
* =========================
|
|
48
|
-
* Hook
|
|
49
|
-
* =========================
|
|
50
|
-
*/
|
|
51
|
-
export declare const useContentEditableController: (props: UseContentEditableControllerProps) => UseContentEditableControllerReturn;
|
|
52
|
-
export {};
|
|
@@ -1,449 +0,0 @@
|
|
|
1
|
-
import { c as Y } from "../../_virtual/compiler-runtime.js";
|
|
2
|
-
import Z from "react";
|
|
3
|
-
const F = "input__token", K = "input__token--selected", q = "aria-data", O = "", k = (t) => (t ?? "").split(O).join(""), D = (t) => !!t && t.nodeType === Node.TEXT_NODE && (t.textContent ?? "") === O, U = (t) => {
|
|
4
|
-
try {
|
|
5
|
-
return JSON.stringify(t);
|
|
6
|
-
} catch {
|
|
7
|
-
return JSON.stringify({
|
|
8
|
-
value: String(t ?? "")
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
}, ee = (t) => {
|
|
12
|
-
if (!t) return null;
|
|
13
|
-
try {
|
|
14
|
-
return JSON.parse(t);
|
|
15
|
-
} catch {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
}, te = (t) => t == null ? "" : typeof t == "string" ? t : U(t), j = (t) => {
|
|
19
|
-
const e = (t.innerHTML ?? "").trim().toLowerCase();
|
|
20
|
-
(e === "<br>" || e === "<br/>" || e === "<br />") && (t.innerHTML = ""), t.childNodes.length === 1 && t.childNodes[0]?.tagName === "BR" && (t.innerHTML = "");
|
|
21
|
-
}, C = (t) => t instanceof HTMLElement && t.classList.contains(F), ne = (t) => {
|
|
22
|
-
let e = t;
|
|
23
|
-
for (; e; ) {
|
|
24
|
-
if (C(e)) return !0;
|
|
25
|
-
e = e.parentNode;
|
|
26
|
-
}
|
|
27
|
-
return !1;
|
|
28
|
-
}, re = (t) => {
|
|
29
|
-
if (t && typeof t == "object") {
|
|
30
|
-
const {
|
|
31
|
-
children: e,
|
|
32
|
-
__contentHtml: r,
|
|
33
|
-
...n
|
|
34
|
-
} = t;
|
|
35
|
-
return n;
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
value: t
|
|
39
|
-
};
|
|
40
|
-
}, P = (t) => ee(t.getAttribute(q)) ?? {
|
|
41
|
-
value: t.textContent ?? ""
|
|
42
|
-
}, oe = (t) => {
|
|
43
|
-
const e = document.createElement("span");
|
|
44
|
-
e.setAttribute("contenteditable", "false"), e.className = F;
|
|
45
|
-
const r = re(t);
|
|
46
|
-
e.setAttribute(q, U(r));
|
|
47
|
-
const n = r?.label ?? r?.value ?? "";
|
|
48
|
-
return e.textContent = String(n ?? ""), e.style.display = "inline-flex", e.style.alignItems = "center", e.style.verticalAlign = "middle", e.style.userSelect = "text", e.style.webkitUserSelect = "text", e;
|
|
49
|
-
}, se = (t) => {
|
|
50
|
-
const e = window.getSelection();
|
|
51
|
-
if (e && e.rangeCount > 0) {
|
|
52
|
-
const o = e.getRangeAt(0);
|
|
53
|
-
if (t.contains(o.startContainer)) return o;
|
|
54
|
-
}
|
|
55
|
-
const r = document.createRange();
|
|
56
|
-
r.selectNodeContents(t), r.collapse(!1);
|
|
57
|
-
const n = window.getSelection();
|
|
58
|
-
return n?.removeAllRanges(), n?.addRange(r), r;
|
|
59
|
-
}, ae = (t, e) => {
|
|
60
|
-
if (!t) return;
|
|
61
|
-
const r = window.getSelection();
|
|
62
|
-
if (!r || r.rangeCount === 0) return;
|
|
63
|
-
const n = r.getRangeAt(0);
|
|
64
|
-
if (!t.contains(n.startContainer)) return;
|
|
65
|
-
n.deleteContents();
|
|
66
|
-
const o = document.createTextNode(e);
|
|
67
|
-
n.insertNode(o);
|
|
68
|
-
const l = document.createRange();
|
|
69
|
-
l.setStartAfter(o), l.collapse(!0), r.removeAllRanges(), r.addRange(l);
|
|
70
|
-
}, ce = (t) => {
|
|
71
|
-
if (!t) return [""];
|
|
72
|
-
const e = [], r = (n) => {
|
|
73
|
-
if (n.nodeType === Node.TEXT_NODE) {
|
|
74
|
-
const l = k(n.textContent ?? "");
|
|
75
|
-
l.length && e.push(l);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
if (n.nodeType !== Node.ELEMENT_NODE) return;
|
|
79
|
-
const o = n;
|
|
80
|
-
if (C(o)) {
|
|
81
|
-
e.push(P(o));
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
Array.from(n.childNodes).forEach(r);
|
|
85
|
-
};
|
|
86
|
-
return Array.from(t.childNodes).forEach(r), e.length ? e.reduce((n, o) => (typeof o == "string" && typeof n[n.length - 1] == "string" ? n[n.length - 1] = `${n[n.length - 1]}${o}` : n.push(o), n), []) : [""];
|
|
87
|
-
}, ie = (t) => t.map((e) => {
|
|
88
|
-
if (typeof e == "string") return e;
|
|
89
|
-
const r = e?.value ?? e;
|
|
90
|
-
return te(r);
|
|
91
|
-
}).join(""), le = (t) => {
|
|
92
|
-
const {
|
|
93
|
-
children: e,
|
|
94
|
-
__contentHtml: r,
|
|
95
|
-
...n
|
|
96
|
-
} = t;
|
|
97
|
-
return n;
|
|
98
|
-
}, z = (t) => {
|
|
99
|
-
if (!t) return null;
|
|
100
|
-
const e = window.getSelection();
|
|
101
|
-
if (!e || e.rangeCount === 0) return null;
|
|
102
|
-
const r = e.getRangeAt(0);
|
|
103
|
-
if (!t.contains(r.startContainer)) return null;
|
|
104
|
-
const n = r.startContainer, o = r.startOffset;
|
|
105
|
-
let l = null;
|
|
106
|
-
n.nodeType === Node.ELEMENT_NODE && (l = n.childNodes[o] ?? null);
|
|
107
|
-
const m = document.createTreeWalker(t, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, {
|
|
108
|
-
acceptNode: (c) => c.nodeType === Node.TEXT_NODE ? ne(c) || (c.textContent ?? "") === O ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT : c.nodeType === Node.ELEMENT_NODE && C(c) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
|
109
|
-
});
|
|
110
|
-
let f = null, d = m.nextNode();
|
|
111
|
-
for (; d && !(l && d === l); ) {
|
|
112
|
-
if (d === n && d.nodeType === Node.TEXT_NODE) {
|
|
113
|
-
const c = d.textContent?.slice(0, o) ?? "", a = [...k(c).matchAll(/\S+/g)], s = a[a.length - 1];
|
|
114
|
-
if (s && s.index !== void 0) {
|
|
115
|
-
const N = s.index, p = N + s[0].length, h = document.createRange();
|
|
116
|
-
h.setStart(d, Math.min(N, c.length)), h.setEnd(d, Math.min(p, c.length)), f = {
|
|
117
|
-
token: s[0],
|
|
118
|
-
range: h
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
if (C(d)) {
|
|
124
|
-
f = null, d = m.nextNode();
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
if (d.nodeType === Node.TEXT_NODE) {
|
|
128
|
-
const c = d.textContent ?? "", a = [...k(c).matchAll(/\S+/g)], s = a[a.length - 1];
|
|
129
|
-
if (s && s.index !== void 0) {
|
|
130
|
-
const N = s.index, p = N + s[0].length, h = document.createRange();
|
|
131
|
-
h.setStart(d, Math.min(N, c.length)), h.setEnd(d, Math.min(p, c.length)), f = {
|
|
132
|
-
token: s[0],
|
|
133
|
-
range: h
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
d = m.nextNode();
|
|
138
|
-
}
|
|
139
|
-
return f;
|
|
140
|
-
}, de = (t) => {
|
|
141
|
-
const e = window.getSelection();
|
|
142
|
-
if (!e || e.rangeCount === 0) return null;
|
|
143
|
-
const r = e.getRangeAt(0);
|
|
144
|
-
if (!t.contains(r.startContainer) || !t.contains(r.endContainer)) return null;
|
|
145
|
-
const n = (f) => {
|
|
146
|
-
if (f.nodeType === Node.TEXT_NODE) return k(f.textContent ?? "").length;
|
|
147
|
-
if (f.nodeType === Node.ELEMENT_NODE) {
|
|
148
|
-
const d = f;
|
|
149
|
-
if (C(d)) {
|
|
150
|
-
const u = P(d);
|
|
151
|
-
return String(u?.value ?? "").length;
|
|
152
|
-
}
|
|
153
|
-
let c = 0;
|
|
154
|
-
return Array.from(f.childNodes).forEach((u) => c += n(u)), c;
|
|
155
|
-
}
|
|
156
|
-
return 0;
|
|
157
|
-
}, o = (f, d) => {
|
|
158
|
-
let c = 0;
|
|
159
|
-
const u = (a) => {
|
|
160
|
-
if (a === f) {
|
|
161
|
-
if (a.nodeType === Node.TEXT_NODE)
|
|
162
|
-
return c += k(a.textContent ?? "").slice(0, d).length, !0;
|
|
163
|
-
if (a.nodeType === Node.ELEMENT_NODE) {
|
|
164
|
-
const s = Array.from(a.childNodes), N = Math.max(0, Math.min(d, s.length));
|
|
165
|
-
for (let p = 0; p < N; p++) c += n(s[p]);
|
|
166
|
-
return !0;
|
|
167
|
-
}
|
|
168
|
-
return !0;
|
|
169
|
-
}
|
|
170
|
-
if (a.nodeType === Node.TEXT_NODE)
|
|
171
|
-
return c += k(a.textContent ?? "").length, !1;
|
|
172
|
-
if (a.nodeType === Node.ELEMENT_NODE) {
|
|
173
|
-
const s = a;
|
|
174
|
-
if (C(s)) {
|
|
175
|
-
const N = P(s);
|
|
176
|
-
return c += String(N?.value ?? "").length, !1;
|
|
177
|
-
}
|
|
178
|
-
for (const N of Array.from(a.childNodes))
|
|
179
|
-
if (u(N)) return !0;
|
|
180
|
-
}
|
|
181
|
-
return !1;
|
|
182
|
-
};
|
|
183
|
-
return u(t), c;
|
|
184
|
-
}, l = o(r.startContainer, r.startOffset), m = o(r.endContainer, r.endOffset);
|
|
185
|
-
return {
|
|
186
|
-
start: Math.min(l, m),
|
|
187
|
-
end: Math.max(l, m)
|
|
188
|
-
};
|
|
189
|
-
}, ye = (t, e, r) => {
|
|
190
|
-
const n = (a) => Math.max(0, a), o = n(e), l = n(r), m = (a) => {
|
|
191
|
-
let s = a;
|
|
192
|
-
const N = (p) => {
|
|
193
|
-
if (p.nodeType === Node.TEXT_NODE) {
|
|
194
|
-
const h = p.textContent ?? "", y = k(h).length;
|
|
195
|
-
return s <= y ? {
|
|
196
|
-
node: p,
|
|
197
|
-
offset: Math.min(s, h.length)
|
|
198
|
-
} : (s -= y, null);
|
|
199
|
-
}
|
|
200
|
-
if (p.nodeType === Node.ELEMENT_NODE) {
|
|
201
|
-
const h = p;
|
|
202
|
-
if (C(h)) {
|
|
203
|
-
const y = P(h), x = String(y?.value ?? "").length, S = h.parentNode ?? t, w = Array.from(S.childNodes).indexOf(h);
|
|
204
|
-
return s <= 0 ? {
|
|
205
|
-
node: S,
|
|
206
|
-
offset: w
|
|
207
|
-
} : s < x ? {
|
|
208
|
-
node: S,
|
|
209
|
-
offset: w + 1
|
|
210
|
-
} : (s -= x, null);
|
|
211
|
-
}
|
|
212
|
-
for (const y of Array.from(p.childNodes)) {
|
|
213
|
-
const x = N(y);
|
|
214
|
-
if (x) return x;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return null;
|
|
218
|
-
};
|
|
219
|
-
return N(t) ?? {
|
|
220
|
-
node: t,
|
|
221
|
-
offset: t.childNodes.length
|
|
222
|
-
};
|
|
223
|
-
}, f = m(o), d = m(l), c = window.getSelection();
|
|
224
|
-
if (!c) return;
|
|
225
|
-
const u = document.createRange();
|
|
226
|
-
try {
|
|
227
|
-
u.setStart(f.node, f.offset), u.setEnd(d.node, d.offset);
|
|
228
|
-
} catch {
|
|
229
|
-
u.selectNodeContents(t), u.collapse(!1);
|
|
230
|
-
}
|
|
231
|
-
c.removeAllRanges(), c.addRange(u);
|
|
232
|
-
}, ue = (t, e, r) => {
|
|
233
|
-
const n = window.getSelection();
|
|
234
|
-
if (!n || typeof n.modify != "function" || !t.contains(n.focusNode) || !t.contains(n.anchorNode)) return !1;
|
|
235
|
-
const o = r === "right" ? "forward" : "backward";
|
|
236
|
-
try {
|
|
237
|
-
return n.modify(e, o, "character"), D(n.focusNode) && n.modify(e, o, "character"), !0;
|
|
238
|
-
} catch {
|
|
239
|
-
return !1;
|
|
240
|
-
}
|
|
241
|
-
}, fe = (t) => {
|
|
242
|
-
const e = window.getSelection();
|
|
243
|
-
if (!e || e.rangeCount === 0) return null;
|
|
244
|
-
const r = e.getRangeAt(0);
|
|
245
|
-
return !t.contains(r.startContainer) || !t.contains(r.endContainer) ? null : r;
|
|
246
|
-
}, ge = (t) => {
|
|
247
|
-
const e = t.parentNode;
|
|
248
|
-
return e ? Array.from(e.childNodes).indexOf(t) : -1;
|
|
249
|
-
}, he = (t) => {
|
|
250
|
-
const e = t.startContainer, r = t.startOffset;
|
|
251
|
-
if (e.nodeType === Node.ELEMENT_NODE) return {
|
|
252
|
-
parent: e,
|
|
253
|
-
index: r
|
|
254
|
-
};
|
|
255
|
-
if (e.nodeType === Node.TEXT_NODE) {
|
|
256
|
-
const n = e, o = n.textContent ?? "", l = ge(n);
|
|
257
|
-
return l < 0 || !n.parentNode ? null : o === O ? {
|
|
258
|
-
parent: n.parentNode,
|
|
259
|
-
index: l + (r > 0 ? 1 : 0)
|
|
260
|
-
} : r === 0 ? {
|
|
261
|
-
parent: n.parentNode,
|
|
262
|
-
index: l
|
|
263
|
-
} : r === o.length ? {
|
|
264
|
-
parent: n.parentNode,
|
|
265
|
-
index: l + 1
|
|
266
|
-
} : null;
|
|
267
|
-
}
|
|
268
|
-
return null;
|
|
269
|
-
}, J = (t, e) => {
|
|
270
|
-
const r = window.getSelection();
|
|
271
|
-
if (!r) return;
|
|
272
|
-
const n = document.createRange();
|
|
273
|
-
n.setStart(t, e), n.collapse(!0), r.removeAllRanges(), r.addRange(n);
|
|
274
|
-
}, W = (t, e) => {
|
|
275
|
-
const r = t.childNodes[e - 1];
|
|
276
|
-
r && D(r) && r.parentNode === t && t.removeChild(r);
|
|
277
|
-
const n = Math.max(0, Math.min(e, t.childNodes.length - 1)), o = t.childNodes[n + 1];
|
|
278
|
-
o && D(o) && o.parentNode === t && t.removeChild(o);
|
|
279
|
-
}, Ne = (t, e) => {
|
|
280
|
-
const r = fe(t);
|
|
281
|
-
if (!r || !r.collapsed) return !1;
|
|
282
|
-
const n = he(r);
|
|
283
|
-
if (!n) return !1;
|
|
284
|
-
const o = n.parent, l = o.childNodes, m = (u) => {
|
|
285
|
-
let a = u;
|
|
286
|
-
for (; a > 0 && D(l[a - 1]); ) a--;
|
|
287
|
-
return a;
|
|
288
|
-
}, f = (u) => {
|
|
289
|
-
let a = u;
|
|
290
|
-
for (; a < l.length && D(l[a]); ) a++;
|
|
291
|
-
return a;
|
|
292
|
-
};
|
|
293
|
-
if (e === "backspace") {
|
|
294
|
-
const u = m(n.index), a = u > 0 ? l[u - 1] : null;
|
|
295
|
-
if (a && C(a)) {
|
|
296
|
-
if (a.parentNode !== o) return !1;
|
|
297
|
-
const s = u - 1;
|
|
298
|
-
return o.removeChild(a), W(o, s), J(o, Math.max(0, Math.min(s, o.childNodes.length))), !0;
|
|
299
|
-
}
|
|
300
|
-
return !1;
|
|
301
|
-
}
|
|
302
|
-
const d = f(n.index), c = l[d] ?? null;
|
|
303
|
-
if (c && C(c)) {
|
|
304
|
-
if (c.parentNode !== o) return !1;
|
|
305
|
-
const u = d;
|
|
306
|
-
return o.removeChild(c), W(o, u), J(o, Math.max(0, Math.min(u, o.childNodes.length))), !0;
|
|
307
|
-
}
|
|
308
|
-
return !1;
|
|
309
|
-
}, $ = (t) => {
|
|
310
|
-
t.querySelectorAll(`.${F}`).forEach((n) => n.classList.remove(K));
|
|
311
|
-
const e = window.getSelection();
|
|
312
|
-
if (!e || e.rangeCount === 0) return;
|
|
313
|
-
const r = e.getRangeAt(0);
|
|
314
|
-
!t.contains(r.startContainer) || !t.contains(r.endContainer) || t.querySelectorAll(`.${F}`).forEach((n) => {
|
|
315
|
-
try {
|
|
316
|
-
r.intersectsNode(n) && n.classList.add(K);
|
|
317
|
-
} catch {
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
}, xe = (t) => {
|
|
321
|
-
const e = Y.c(30), {
|
|
322
|
-
editorRef: r,
|
|
323
|
-
transformSyntax: n,
|
|
324
|
-
filterSuggestionsByLastToken: o,
|
|
325
|
-
onLastTokenChange: l,
|
|
326
|
-
onStateChange: m
|
|
327
|
-
} = t, f = o === void 0 ? !1 : o, [d, c] = Z.useState(""), u = Z.useRef(null);
|
|
328
|
-
let a;
|
|
329
|
-
e[0] !== f || e[1] !== l || e[2] !== m || e[3] !== n ? (a = (i) => {
|
|
330
|
-
if (!i)
|
|
331
|
-
return;
|
|
332
|
-
j(i);
|
|
333
|
-
const g = de(i);
|
|
334
|
-
u.current = g;
|
|
335
|
-
const T = ce(i), R = ie(T), A = T.filter(pe);
|
|
336
|
-
f && l?.(z(i)?.token ?? null);
|
|
337
|
-
let b = null;
|
|
338
|
-
n && (b = n(R, T)), $(i), m?.({
|
|
339
|
-
value: R,
|
|
340
|
-
tokens: A,
|
|
341
|
-
segments: b
|
|
342
|
-
});
|
|
343
|
-
}, e[0] = f, e[1] = l, e[2] = m, e[3] = n, e[4] = a) : a = e[4];
|
|
344
|
-
const s = a;
|
|
345
|
-
let N;
|
|
346
|
-
e[5] !== m || e[6] !== n ? (N = (i) => {
|
|
347
|
-
const g = [], T = i ?? "", R = n ? n(T, g) : null;
|
|
348
|
-
return m?.({
|
|
349
|
-
value: T,
|
|
350
|
-
tokens: [],
|
|
351
|
-
segments: R
|
|
352
|
-
}), c(""), T;
|
|
353
|
-
}, e[5] = m, e[6] = n, e[7] = N) : N = e[7];
|
|
354
|
-
const p = N;
|
|
355
|
-
let h;
|
|
356
|
-
e[8] !== r || e[9] !== f || e[10] !== s ? (h = (i) => {
|
|
357
|
-
const g = r.current;
|
|
358
|
-
if (!g)
|
|
359
|
-
return;
|
|
360
|
-
j(g), g.focus({
|
|
361
|
-
preventScroll: !0
|
|
362
|
-
});
|
|
363
|
-
const T = i.insertMode ?? "replace", A = (() => {
|
|
364
|
-
const E = document.createRange();
|
|
365
|
-
switch (T) {
|
|
366
|
-
case "append":
|
|
367
|
-
return E.selectNodeContents(g), E.collapse(!1), E;
|
|
368
|
-
case "prepend":
|
|
369
|
-
return E.selectNodeContents(g), E.collapse(!0), E;
|
|
370
|
-
case "replace":
|
|
371
|
-
return E.selectNodeContents(g), E;
|
|
372
|
-
default:
|
|
373
|
-
return se(g);
|
|
374
|
-
}
|
|
375
|
-
})(), b = le(i);
|
|
376
|
-
if (f && T !== "replace") {
|
|
377
|
-
const E = z(g);
|
|
378
|
-
E ? E.range.deleteContents() : A.deleteContents();
|
|
379
|
-
} else
|
|
380
|
-
A.deleteContents();
|
|
381
|
-
const v = oe(b), Q = document.createTextNode(O), H = document.createTextNode(O);
|
|
382
|
-
A.insertNode(Q), A.insertNode(v), v.parentNode?.insertBefore(H, v.nextSibling ?? null);
|
|
383
|
-
const B = window.getSelection(), I = document.createRange();
|
|
384
|
-
try {
|
|
385
|
-
I.setStart(H, 1);
|
|
386
|
-
} catch {
|
|
387
|
-
I.setStartAfter(v);
|
|
388
|
-
}
|
|
389
|
-
I.collapse(!0), B?.removeAllRanges(), B?.addRange(I), s(g);
|
|
390
|
-
}, e[8] = r, e[9] = f, e[10] = s, e[11] = h) : h = e[11];
|
|
391
|
-
const y = h;
|
|
392
|
-
let x;
|
|
393
|
-
e[12] !== r || e[13] !== s ? (x = (i) => {
|
|
394
|
-
i.preventDefault();
|
|
395
|
-
const g = i.clipboardData.getData("text/plain");
|
|
396
|
-
ae(r.current, g), s(r.current);
|
|
397
|
-
}, e[12] = r, e[13] = s, e[14] = x) : x = e[14];
|
|
398
|
-
const S = x;
|
|
399
|
-
let w;
|
|
400
|
-
e[15] !== r || e[16] !== s ? (w = (i) => {
|
|
401
|
-
s(r.current);
|
|
402
|
-
}, e[15] = r, e[16] = s, e[17] = w) : w = e[17];
|
|
403
|
-
const V = w, G = me;
|
|
404
|
-
let _;
|
|
405
|
-
e[18] !== r || e[19] !== s ? (_ = (i) => {
|
|
406
|
-
const g = r.current;
|
|
407
|
-
if (!g || document.activeElement !== g)
|
|
408
|
-
return !1;
|
|
409
|
-
if ((i.key === "Backspace" || i.key === "Delete") && Ne(g, i.key === "Backspace" ? "backspace" : "delete"))
|
|
410
|
-
return i.preventDefault(), i.stopPropagation(), s(g), !0;
|
|
411
|
-
if (i.key === "ArrowLeft" || i.key === "ArrowRight") {
|
|
412
|
-
const T = i.key === "ArrowLeft" ? "left" : "right";
|
|
413
|
-
if (ue(g, i.shiftKey ? "extend" : "move", T))
|
|
414
|
-
return i.preventDefault(), i.stopPropagation(), $(g), !0;
|
|
415
|
-
}
|
|
416
|
-
return i.key === "Enter" ? (i.preventDefault(), !0) : !1;
|
|
417
|
-
}, e[18] = r, e[19] = s, e[20] = _) : _ = e[20];
|
|
418
|
-
const X = _;
|
|
419
|
-
let L;
|
|
420
|
-
e[21] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (L = () => {
|
|
421
|
-
const i = u.current;
|
|
422
|
-
return u.current = null, i;
|
|
423
|
-
}, e[21] = L) : L = e[21];
|
|
424
|
-
let M;
|
|
425
|
-
return e[22] !== y || e[23] !== d || e[24] !== V || e[25] !== X || e[26] !== S || e[27] !== p || e[28] !== s ? (M = {
|
|
426
|
-
editorHtml: d,
|
|
427
|
-
setEditorHtml: c,
|
|
428
|
-
initializeFromExternalValue: p,
|
|
429
|
-
updateEditorState: s,
|
|
430
|
-
takePendingSelection: L,
|
|
431
|
-
applySuggestionValueSyntax: y,
|
|
432
|
-
handlePaste: S,
|
|
433
|
-
handleChange: V,
|
|
434
|
-
handleKeyDownCapture: G,
|
|
435
|
-
handleKeyDown: X
|
|
436
|
-
}, e[22] = y, e[23] = d, e[24] = V, e[25] = X, e[26] = S, e[27] = p, e[28] = s, e[29] = M) : M = e[29], M;
|
|
437
|
-
};
|
|
438
|
-
function pe(t) {
|
|
439
|
-
return typeof t != "string";
|
|
440
|
-
}
|
|
441
|
-
function me(t) {
|
|
442
|
-
(t.key === " " || t.code === "Space") && (t.stopPropagation(), t.nativeEvent?.stopImmediatePropagation?.());
|
|
443
|
-
}
|
|
444
|
-
export {
|
|
445
|
-
de as getSelectionOffsetsInValue,
|
|
446
|
-
ce as serializeEditorParts,
|
|
447
|
-
ye as setSelectionOffsetsInValue,
|
|
448
|
-
xe as useContentEditableController
|
|
449
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { MenuContentProps } from '../menu/Menu';
|
|
2
|
-
import { default as React, RefObject } from 'react';
|
|
3
|
-
export interface InputSuggestion {
|
|
4
|
-
children: React.ReactNode;
|
|
5
|
-
value: any;
|
|
6
|
-
valueData?: any;
|
|
7
|
-
groupBy?: string;
|
|
8
|
-
insertMode?: "replace" | "append" | "prepend" | "insert";
|
|
9
|
-
}
|
|
10
|
-
export type InputSuggestionMenuContentProps = MenuContentProps & {
|
|
11
|
-
inputRef?: RefObject<HTMLInputElement>;
|
|
12
|
-
};
|
|
13
|
-
export interface InputSuggestionMenuContentItemsProps {
|
|
14
|
-
suggestions?: InputSuggestion[];
|
|
15
|
-
onSuggestionSelect?: (suggestion: InputSuggestion) => void;
|
|
16
|
-
inputRef?: RefObject<HTMLInputElement>;
|
|
17
|
-
}
|
|
18
|
-
export interface InputSuggestionMenuContentItemsHandle {
|
|
19
|
-
focusFirstItem: () => InputSuggestion | undefined;
|
|
20
|
-
focusLastItem: () => InputSuggestion | undefined;
|
|
21
|
-
highlightNextItem: () => InputSuggestion | undefined;
|
|
22
|
-
highlightPreviousItem: () => InputSuggestion | undefined;
|
|
23
|
-
selectActiveItem: () => InputSuggestion | undefined;
|
|
24
|
-
clearActiveItem: () => void;
|
|
25
|
-
}
|
|
26
|
-
export declare const InputSuggestionMenuContent: React.NamedExoticComponent<InputSuggestionMenuContentProps>;
|
|
27
|
-
export declare const InputSuggestionMenuContentItems: React.NamedExoticComponent<InputSuggestionMenuContentItemsProps & React.RefAttributes<InputSuggestionMenuContentItemsHandle>>;
|