viewkitjs 0.26.0 → 0.27.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.
Files changed (94) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/MIGRATION.md +84 -6
  3. package/package.json +1 -1
  4. package/views/dist/contract.d.ts +171 -1
  5. package/views/dist/contract.js +162 -0
  6. package/views/dist/controls/compound-editor/map-parts-body.js +2 -1
  7. package/views/dist/controls/compound-editor/name-parts.js +10 -2
  8. package/views/dist/controls/compound-editor/place.d.ts +2 -1
  9. package/views/dist/controls/compound-editor/place.js +2 -0
  10. package/views/dist/controls/controls.d.ts +8 -0
  11. package/views/dist/controls/controls.js +8 -0
  12. package/views/dist/controls/index.d.ts +16 -0
  13. package/views/dist/controls/index.js +16 -0
  14. package/views/dist/controls/internal/editor-parts.d.ts +40 -0
  15. package/views/dist/controls/internal/editor-parts.js +43 -0
  16. package/views/dist/controls/links-editor/links-editor.d.ts +78 -0
  17. package/views/dist/controls/links-editor/links-editor.js +308 -0
  18. package/views/dist/controls/links-editor/links.d.ts +62 -0
  19. package/views/dist/controls/links-editor/links.js +50 -0
  20. package/views/dist/controls/links-editor/map-links-body.d.ts +10 -0
  21. package/views/dist/controls/links-editor/map-links-body.js +71 -0
  22. package/views/dist/controls/links-editor/tokens.d.ts +71 -0
  23. package/views/dist/controls/links-editor/tokens.js +20 -0
  24. package/views/dist/controls/links-editor/words.d.ts +56 -0
  25. package/views/dist/controls/links-editor/words.js +33 -0
  26. package/views/dist/controls/links-editor.css +132 -0
  27. package/views/dist/controls/number-editor/format.d.ts +31 -0
  28. package/views/dist/controls/number-editor/format.js +79 -0
  29. package/views/dist/controls/number-editor/looks.d.ts +14 -0
  30. package/views/dist/controls/number-editor/looks.js +17 -0
  31. package/views/dist/controls/number-editor/map-number-body.d.ts +16 -0
  32. package/views/dist/controls/number-editor/map-number-body.js +57 -0
  33. package/views/dist/controls/number-editor/number-editor.d.ts +72 -0
  34. package/views/dist/controls/number-editor/number-editor.js +202 -0
  35. package/views/dist/controls/number-editor/tokens.d.ts +28 -0
  36. package/views/dist/controls/number-editor/tokens.js +9 -0
  37. package/views/dist/controls/number-editor/words.d.ts +23 -0
  38. package/views/dist/controls/number-editor/words.js +13 -0
  39. package/views/dist/controls/number-editor.css +37 -0
  40. package/views/dist/controls/number-field/number-field.js +57 -5
  41. package/views/dist/controls/radio/radio.d.ts +33 -0
  42. package/views/dist/controls/radio/radio.js +19 -0
  43. package/views/dist/controls/radio/tokens.d.ts +127 -0
  44. package/views/dist/controls/radio/tokens.js +34 -0
  45. package/views/dist/controls/radio.css +104 -0
  46. package/views/dist/controls/text-editor/phone-number.d.ts +4 -0
  47. package/views/dist/controls/text-editor/phone-number.js +20 -0
  48. package/views/dist/controls/text-editor/text-editor.js +2 -19
  49. package/views/dist/controls/tokens.js +10 -0
  50. package/views/dist/controls/values-editor/looks.d.ts +16 -0
  51. package/views/dist/controls/values-editor/looks.js +19 -0
  52. package/views/dist/controls/values-editor/map-values-body.d.ts +12 -0
  53. package/views/dist/controls/values-editor/map-values-body.js +71 -0
  54. package/views/dist/controls/values-editor/tokens.d.ts +132 -0
  55. package/views/dist/controls/values-editor/tokens.js +35 -0
  56. package/views/dist/controls/values-editor/values-editor.d.ts +62 -0
  57. package/views/dist/controls/values-editor/values-editor.js +435 -0
  58. package/views/dist/controls/values-editor/values.d.ts +71 -0
  59. package/views/dist/controls/values-editor/values.js +59 -0
  60. package/views/dist/controls/values-editor/words.d.ts +50 -0
  61. package/views/dist/controls/values-editor/words.js +29 -0
  62. package/views/dist/controls/values-editor.css +207 -0
  63. package/views/dist/controls/views-list/looks.d.ts +13 -0
  64. package/views/dist/controls/views-list/looks.js +12 -0
  65. package/views/dist/controls/views-list/map-views-list-body.d.ts +19 -0
  66. package/views/dist/controls/views-list/map-views-list-body.js +65 -0
  67. package/views/dist/controls/views-list/rules.d.ts +72 -0
  68. package/views/dist/controls/views-list/rules.js +4 -0
  69. package/views/dist/controls/views-list/tokens.d.ts +11 -0
  70. package/views/dist/controls/views-list/tokens.js +5 -0
  71. package/views/dist/controls/views-list/views-list.d.ts +44 -0
  72. package/views/dist/controls/views-list/views-list.js +57 -0
  73. package/views/dist/controls/views-list/words.d.ts +22 -0
  74. package/views/dist/controls/views-list/words.js +3 -0
  75. package/views/dist/controls/views-list.css +8 -0
  76. package/views/dist/editors/NumberEditor.js +3 -1
  77. package/views/dist/grid/chrome/GridCellEditors.js +1 -1
  78. package/views/dist/grid/chrome/GridDateEditor.d.ts +3 -1
  79. package/views/dist/grid/chrome/GridDateEditor.js +2 -1
  80. package/views/dist/looks/index.d.ts +3 -0
  81. package/views/dist/looks/index.js +3 -0
  82. package/views/dist/looks/pieces.js +6 -0
  83. package/views/dist/provider/components.d.ts +4 -0
  84. package/views/dist/styles.css +432 -2
  85. package/views/dist/styles.unlayered.css +432 -2
  86. package/views/docs/contract.md +10 -8
  87. package/views/docs/controls/links-editor.md +25 -0
  88. package/views/docs/controls/number-editor.md +12 -0
  89. package/views/docs/controls/radio.md +39 -0
  90. package/views/docs/controls/values-editor.md +40 -0
  91. package/views/docs/controls/views-list.md +8 -0
  92. package/views/docs/reference/controls.md +117 -5
  93. package/views/docs/reference/looks.md +9 -2
  94. package/views/docs/reference/react.md +2 -2
@@ -0,0 +1,435 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Button } from "../button/button.js";
5
+ import { Picker, usePicker } from "../picker/picker.js";
6
+ import { Popover } from "../popover/popover.js";
7
+ import { SheetButton } from "../sheet/bottom-sheet.js";
8
+ import { Flag } from "../flag/flag.js";
9
+ import { phoneMark, usePhoneForm } from "../internal/phone.js";
10
+ import { midWord, TEXT_KEYS, kept, textRefusal } from "../text-editor/check.js";
11
+ import { DIALS, countryName, dialOf, firstCountry, patternOf, phoneHanded, phoneOf } from "../text-editor/phone-number.js";
12
+ import { VALUES_EDITOR_ATTRS, valuesEditorWornOf } from "./looks.js";
13
+ import { added, handedList, labelFor, labelsOf, listOf, openOf, charsThatFit, splitEmail } from "./values.js";
14
+ import { valuesWords } from "./words.js";
15
+ import { FieldRowsRow as FieldRow, FieldRows } from "../field/field.js";
16
+ import { Input, InputGroupAddon, InputGroupButton } from "../input/input.js";
17
+ import { InlineInputGroup } from "../inline-input/inline-input.js";
18
+ import { cx } from "../../internal/cx.js";
19
+ import { moved, useReorder } from "../internal/reorder.js";
20
+ import { useShellHand } from "../internal/shell-hand.js";
21
+ import { spacingPx } from "../internal/read-token.js";
22
+ import { EDITOR_INNER_ESCAPE } from "../../editors/inner-escape.js";
23
+ const ROW_28 = { "--inline-input-row": "calc(var(--vk-spacing) * 7)" };
24
+ const ROW_40 = { "--inline-input-row": "calc(var(--vk-spacing) * 10)" };
25
+ const glyph = (paths, className) => (_jsx("svg", { className: className, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: paths.map((d) => _jsx("path", { d: d }, d)) }));
26
+ const dots = (x, y) => `M${x} ${y}m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`;
27
+ const GRIP = [dots(9, 5), dots(9, 12), dots(9, 19), dots(15, 5), dots(15, 12), dots(15, 19)], LINES = ["M4 6h16", "M4 12h16", "M4 18h16"];
28
+ const X = ["M18 6l-12 12", "M6 6l12 12"], TICK = ["M5 12l5 5l10 -10"], DOWN = ["M6 9l6 6l6 -6"], LEFT = ["M15 6l-6 6l6 6"];
29
+ const TRASH = ["M4 7l16 0", "M10 11l0 6", "M14 11l0 6", "M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12", "M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"];
30
+ const COPY = ["M7 9.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667z", "M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1"];
31
+ const PLUS = ["M12 5l0 14", "M5 12l14 0"];
32
+ const CALL = ["M5 4h4l2 5l-2.5 1.5a11 11 0 0 0 5 5l1.5 -2.5l5 2v4a2 2 0 0 1 -2 2a16 16 0 0 1 -15 -15a2 2 0 0 1 2 -2"];
33
+ const OPEN = ["M12 6h-6a2 2 0 0 0 -2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-6", "M11 13l9 -9", "M15 4h5v5"];
34
+ const ATTIO_ROWS = { cards: "one", edge: "off", height: "48", label: "104", lines: "across" };
35
+ const MIHAI_CARDS = { cards: "each", edge: "on", height: "56", label: "104", lines: "none" };
36
+ const MAIL = ["M3 7a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-10z", "M3 7l9 6l9 -6"];
37
+ const WORLD = ["M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0", "M3.6 9h16.8", "M3.6 15h16.8", "M11.5 3a17 17 0 0 0 0 18", "M12.5 3a17 17 0 0 1 0 18"];
38
+ const LINK = ["M9 15l6 -6", "M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464", "M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463"];
39
+ const ICON = { email: MAIL, phone: LINES, link: LINK, domain: WORLD };
40
+ let ids = 0;
41
+ const rowsOf = (list) => listOf(list).map((v) => ({ id: ++ids, value: v.value, label: v.label }));
42
+ const same = (a, b) => JSON.stringify(listOf(a)) === JSON.stringify(listOf(b));
43
+ function firstOf(props) {
44
+ const held = rowsOf(props.value), m = props.moving != null && held[props.moving] ? props.moving : null;
45
+ const rows = m == null ? held : moved(held, m, 0);
46
+ const posed = m == null ? null : { id: held[m].id, mainId: held[0].id };
47
+ if (props.draft === "shell") {
48
+ const editing = props.typed != null && rows.length ? 0 : props.editing ?? null;
49
+ return { rows, posed, typed: "", tried: false, editing, editText: editing != null ? rows[editing]?.value ?? "" : "" };
50
+ }
51
+ return { rows, posed, typed: props.typed ?? "", tried: props.typed != null, editing: props.editing ?? null,
52
+ editText: props.editing != null ? rows[props.editing]?.value ?? "" : "" };
53
+ }
54
+ const ROOT = ":root-of-body";
55
+ export function useValuesEditorWorn(el) {
56
+ const [worn, setWorn] = React.useState(() => valuesEditorWornOf(null));
57
+ React.useLayoutEffect(() => {
58
+ if (!el)
59
+ return;
60
+ const read = () => setWorn((now) => { const next = valuesEditorWornOf(el); return Object.keys(next).every((k) => now[k] === next[k]) ? now : next; });
61
+ read();
62
+ const watch = new MutationObserver(read);
63
+ watch.observe(document.documentElement, { attributes: true, subtree: true, attributeFilter: VALUES_EDITOR_ATTRS });
64
+ return () => watch.disconnect();
65
+ }, [el]);
66
+ return worn;
67
+ }
68
+ const countries = new Map();
69
+ const countryItems = (language) => {
70
+ if (!countries.has(language))
71
+ countries.set(language, DIALS.map((d) => ({ value: d.country, label: `${countryName(d.country, language)} ${d.code}` })).sort((a, b) => a.label.localeCompare(b.label, language)));
72
+ return countries.get(language);
73
+ };
74
+ export function useValuesEditor(props) {
75
+ const { label, kind, value, onValueChange, onDone, dialCodes = [], autoFocus = true } = props;
76
+ const one = props.holds === "one", shell = props.draft === "shell";
77
+ const w = valuesWords(props.words), language = props.language ?? "en";
78
+ const labels = one ? [] : props.labels ?? (kind === "domain" ? [] : labelsOf(w.labels));
79
+ const phone = usePhoneForm(props.form), device = phoneMark(usePhoneForm());
80
+ const rule = React.useCallback((v) => (props.check ?? ((x) => textRefusal(kind, x)))(v), [props.check, kind]);
81
+ const [first] = React.useState(() => firstOf(props));
82
+ const [rows, setRows] = React.useState(first.rows), [posed, setPosed] = React.useState(first.posed);
83
+ const [typed, setTyped] = React.useState(first.typed), [tried, setTried] = React.useState(first.tried);
84
+ const [editing, setEditing] = React.useState(first.editing), [editText, setEditText] = React.useState(first.editText);
85
+ const [view, setView] = React.useState("rows"), [labelOf, setLabelOf] = React.useState(null);
86
+ const [checked, setChecked] = React.useState(false);
87
+ const [country, setCountry] = React.useState(props.dial ?? dialCodes[0]?.country);
88
+ const [rootEl, setRootEl] = React.useState(null);
89
+ const worn = useValuesEditorWorn(rootEl), attio = worn.line === "plus";
90
+ const edit = phone && worn.phone === "cards" ? null : editing;
91
+ const reading = country && dialOf(country) ? country : firstCountry();
92
+ const keepAs = (t) => kept(kind, t);
93
+ const lineRead = () => {
94
+ if (!(kind === "phone" && attio))
95
+ return added(kind, typed, rule, dial, keepAs);
96
+ if (!typed.trim())
97
+ return { error: "" };
98
+ const r = phoneOf(reading, typed);
99
+ if (!("value" in r))
100
+ return { ...r, typed: phoneHanded(reading, typed) };
101
+ if (!r.value)
102
+ return { error: "" };
103
+ const refused = props.check?.(r.value);
104
+ return refused ? { error: refused, typed: r.value } : r;
105
+ };
106
+ const dial = dialCodes.find((d) => d.country === country) ?? (country ? { country, code: "" } : undefined);
107
+ const settled = React.useRef(false), swapping = React.useRef(false), root = React.useRef(null);
108
+ const keys = TEXT_KEYS[kind];
109
+ const refusal = tried ? (() => { const r = lineRead(); return "error" in r && r.error ? r.error : null; })() : null;
110
+ const finishEdit = () => {
111
+ if (edit == null)
112
+ return true;
113
+ const v = editText.trim() ? keepAs(editText) : "";
114
+ if (v && rule(v))
115
+ return false;
116
+ setRows((rs) => (v ? rs.map((r, i) => (i === edit ? { ...r, value: v } : r)) : rs.filter((_, i) => i !== edit)));
117
+ setEditing(null);
118
+ return true;
119
+ };
120
+ const listNow = (line) => handedList(rows, edit == null ? null : { at: edit, text: editText }, line ? lineRead() : null, { check: rule, keep: keepAs, label: labels.length ? labelFor(kind, w.labels) : undefined, refused: shell });
121
+ const sameList = (a, b) => JSON.stringify(listOf(a).map((v) => [v.value, v.label ?? ""])) === JSON.stringify(listOf(b).map((v) => [v.value, v.label ?? ""]));
122
+ useShellHand(shell, shell ? listNow(true) : value, value, sameList, onValueChange, (v) => {
123
+ setRows(rowsOf(v));
124
+ setPosed(null);
125
+ setTyped("");
126
+ setTried(false);
127
+ setEditing(null);
128
+ setEditText("");
129
+ setView("rows");
130
+ setChecked(false);
131
+ setDrop(null);
132
+ });
133
+ const keep = (line = false) => {
134
+ settled.current = true;
135
+ if (shell) {
136
+ onDone?.();
137
+ return;
138
+ }
139
+ const next = listNow(line);
140
+ if (!same(next, value))
141
+ onValueChange(next);
142
+ onDone?.();
143
+ };
144
+ const asked = React.useRef(props);
145
+ asked.current = props;
146
+ const reset = () => {
147
+ const f = firstOf(asked.current);
148
+ setRows(f.rows);
149
+ setPosed(f.posed);
150
+ setTyped(f.typed);
151
+ setTried(f.tried);
152
+ setEditing(f.editing);
153
+ setEditText(f.editText);
154
+ setView("rows");
155
+ setChecked(false);
156
+ };
157
+ const leave = () => { settled.current = true; reset(); onDone?.(); };
158
+ React.useLayoutEffect(() => {
159
+ if (!rootEl)
160
+ return;
161
+ let frame = 0;
162
+ const cut = () => {
163
+ if (typeof Range === "undefined" || typeof Range.prototype.getBoundingClientRect !== "function")
164
+ return;
165
+ for (const name of rootEl.querySelectorAll(".o-values-editor-name[data-name]")) {
166
+ const text = name.firstChild, full = name.dataset.name;
167
+ if (!(text instanceof Text))
168
+ continue;
169
+ name.style.textOverflow = "clip";
170
+ if (text.nodeValue !== full)
171
+ text.nodeValue = full;
172
+ const room = name.getBoundingClientRect().width, range = document.createRange(), widths = [];
173
+ for (let i = 1; i <= full.length; i++) {
174
+ range.setStart(text, 0);
175
+ range.setEnd(text, i);
176
+ widths.push(range.getBoundingClientRect().width);
177
+ }
178
+ text.nodeValue = "…";
179
+ range.selectNodeContents(text);
180
+ const ellipsis = range.getBoundingClientRect().width;
181
+ const k = charsThatFit(widths, room + 0.5, ellipsis);
182
+ text.nodeValue = k === full.length ? full : full.slice(0, k) + "…";
183
+ name.style.textOverflow = "";
184
+ }
185
+ };
186
+ cut();
187
+ if (typeof ResizeObserver === "undefined")
188
+ return;
189
+ const watch = new ResizeObserver(() => { cancelAnimationFrame(frame); frame = requestAnimationFrame(cut); });
190
+ watch.observe(rootEl);
191
+ for (const pill of rootEl.querySelectorAll(".o-values-editor-pill")) {
192
+ watch.observe(pill, { box: "border-box" });
193
+ watch.observe(pill.querySelector(".o-values-editor-value"));
194
+ }
195
+ return () => { cancelAnimationFrame(frame); watch.disconnect(); };
196
+ }, [rootEl, worn.rows, rows, editing, view]);
197
+ const placeRoot = React.useCallback((el) => { root.current = el; setRootEl(el); if (!el) {
198
+ reset();
199
+ settled.current = false;
200
+ } }, []);
201
+ const add = () => {
202
+ const r = lineRead();
203
+ if ("value" in r) {
204
+ setRows((rs) => [...rs, { id: ++ids, value: r.value, label: labels.length ? labelFor(kind, w.labels) : undefined }]);
205
+ setTyped("");
206
+ setTried(false);
207
+ return "added";
208
+ }
209
+ if (!r.error)
210
+ return "empty";
211
+ setTried(true);
212
+ return "refused";
213
+ };
214
+ const remove = (i) => { setRows((rs) => rs.filter((_, j) => j !== i)); if (editing === i)
215
+ setEditing(null);
216
+ else if (editing != null && i < editing)
217
+ setEditing(editing - 1); };
218
+ const { gripProps, lift, dragging } = useReorder({ count: rows.length, onMove: (from, to) => setRows((rs) => moved(rs, from, to)), grip: ".o-values-editor-grip" });
219
+ const [mainHeld, setMainHeld] = React.useState();
220
+ const mainId = posed ? posed.mainId : dragging != null ? mainHeld : rows[0]?.id;
221
+ const lifted = (r, i) => (dragging === i || posed?.id === r.id ? "" : undefined);
222
+ const grip = (r, i, icon, size, look) => {
223
+ const g = gripProps(i);
224
+ return _jsx(Button, { kind: "quiet", shape: "icon", size: size, look: look, className: "o-values-editor-grip", "aria-label": w.move(r.value), icon: glyph(icon), ...g, onPointerDown: (e) => { setPosed(null); setMainHeld(rows[0]?.id); g.onPointerDown(e); } });
225
+ };
226
+ const [focusTo, setFocusTo] = React.useState(autoFocus && !phone ? (first.editing != null ? ".o-values-editor-edit input" : props.holds === "one" && first.rows.length ? ROOT : ".o-values-editor-line-input") : null);
227
+ React.useLayoutEffect(() => {
228
+ if (!focusTo || !root.current)
229
+ return;
230
+ const el = root.current, sel = focusTo;
231
+ setFocusTo(null);
232
+ requestAnimationFrame(() => {
233
+ const t = sel === ROOT ? el : el.querySelector(sel);
234
+ swapping.current = false;
235
+ t?.focus({ preventScroll: true });
236
+ if (shell && sel === ".o-values-editor-edit input" && t instanceof HTMLInputElement && /^(text|search|url|tel|password)$/.test(t.type))
237
+ t.setSelectionRange(t.value.length, t.value.length);
238
+ });
239
+ }, [focusTo, shell]);
240
+ const hold = () => { swapping.current = true; if (!phone)
241
+ root.current?.focus({ preventScroll: true }); };
242
+ const go = (to, row) => {
243
+ hold();
244
+ if (row != null)
245
+ setLabelOf(row);
246
+ setView(to);
247
+ setFocusTo(to === "rows" ? (editing != null ? ".o-values-editor-edit input" : ".o-values-editor-line-input") : ".o-picker-input, [role='option']");
248
+ };
249
+ const back = () => go("rows");
250
+ const labelItems = [...labels, ...(labelOf != null && rows[labelOf]?.label && !labels.includes(rows[labelOf].label) ? [rows[labelOf].label] : [])].map((l) => ({ value: l, label: l }));
251
+ const setLabel = (l) => { if (typeof l === "string" && labelOf != null)
252
+ setRows((rs) => rs.map((r, i) => (i === labelOf ? { ...r, label: l } : r))); };
253
+ const names = React.useMemo(() => { try {
254
+ return new Intl.DisplayNames([language], { type: "region" });
255
+ }
256
+ catch {
257
+ return null;
258
+ } }, [language]);
259
+ const dialItems = dialCodes.map((d) => ({ value: d.country, label: `${names?.of(d.country) ?? d.country} ${d.code}`, as: { mark: _jsx(Flag, { code: d.country, size: phone ? "lg" : undefined }) } }));
260
+ const labelList = usePicker({ label: w.label, items: labelItems, value: labelOf != null ? rows[labelOf]?.label ?? null : null, onValueChange: setLabel, onCreate: (t) => t.trim(), onDone: back, search: w.labelSearch, form: "phone", fromHeld: true, ...(w.picker ? { words: w.picker } : {}) });
261
+ const dialList = usePicker({ label: w.countryCode, items: attio ? countryItems(language) : dialItems, value: attio ? reading : country ?? null, onValueChange: (c) => { if (typeof c === "string")
262
+ setCountry(c); }, onDone: back, search: w.searchCountry, form: "phone", fromHeld: true, ...(w.picker ? { words: w.picker } : {}) });
263
+ const hint = kind === "phone" && dial?.hint ? dial.hint : w.add[kind];
264
+ const under = worn.lists === "under";
265
+ const [drop, setDrop] = React.useState(null);
266
+ const popup = React.useRef(null);
267
+ const dropBack = React.useRef(null);
268
+ const closeDrop = () => { dropBack.current = root.current?.querySelector(drop?.what === "label" ? ".o-values-editor-edit input" : ".o-values-editor-line-input") ?? null; setDrop(null); };
269
+ const open = (what, row) => (e) => {
270
+ if (!under) {
271
+ go(what, row);
272
+ return;
273
+ }
274
+ if (row != null)
275
+ setLabelOf(row);
276
+ setDrop(drop?.what === what ? null : { what, at: e.currentTarget, row });
277
+ };
278
+ const [copied, setCopied] = React.useState(null);
279
+ React.useEffect(() => { if (!under)
280
+ setDrop(null); }, [under]);
281
+ const copy = (r) => () => {
282
+ try {
283
+ navigator.clipboard.writeText(r.value).then(() => setCopied(r.id), () => { });
284
+ }
285
+ catch { }
286
+ };
287
+ if (phone) {
288
+ const bad = checked ? rows.map((r) => rule(r.value)) : [];
289
+ const lineKeys = (e) => {
290
+ if (e.key !== "Enter" || midWord(e.nativeEvent))
291
+ return;
292
+ e.preventDefault();
293
+ if (shell && one) {
294
+ const r = lineRead();
295
+ if ("error" in r && r.error)
296
+ setTried(true);
297
+ onDone?.();
298
+ return;
299
+ }
300
+ if (one)
301
+ save();
302
+ else if (add() === "refused" && shell)
303
+ onDone?.();
304
+ };
305
+ const cardsLook = worn.phone === "cards", showLine = !(one && rows.length > 0);
306
+ const editKeys = (e) => { if (e.key === "Enter" && !midWord(e.nativeEvent)) {
307
+ e.preventDefault();
308
+ if (!finishEdit() && shell)
309
+ onDone?.();
310
+ } };
311
+ const card = (_jsxs(_Fragment, { children: [_jsxs(FieldRows, { look: ATTIO_ROWS, className: "o-values-editor-card", role: "list", "aria-label": label, children: [rows.map((r, i) => {
312
+ const act = openOf(kind, r.value);
313
+ return (_jsxs(React.Fragment, { children: [_jsxs(FieldRow, { as: "div", role: "listitem", className: "o-values-editor-row", "data-row": r.id, "data-lifted": lifted(r, i), style: lift(i), children: [!one && grip(r, i, GRIP, "32x44", { radius: "md", corner: "round", edge: "none", words: "inherit", colour: "faint", cursor: "grab", hover: "none", icon: "16" }), editing === i ? (_jsxs(InlineInputGroup, { className: "o-values-editor-edit", style: ROW_40, children: [_jsx(Input, { "aria-label": w.change(r.value), value: editText, type: keys.type, inputMode: keys.inputMode, autofill: false, autoCapitalize: keys.autoCapitalize, enterKeyHint: "done", onChange: (e) => setEditText(e.target.value), onKeyDown: editKeys }), labels.length > 0 && _jsx(InputGroupAddon, { side: "end", children: _jsx(InputGroupButton, { className: "o-values-editor-edit-label", size: "line", look: { radius: "none", corner: "round", edge: "none", words: "sm", icon: "14", hover: "words" }, "aria-label": w.labelIs(r.label ?? w.noLabel), onClick: () => go("label", i), iconEnd: glyph(DOWN), children: r.label ?? w.label }) })] })) : _jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "o-values-editor-value", onClick: () => { if (!finishEdit())
314
+ return; setEditing(i); setEditText(r.value); setFocusTo(".o-values-editor-edit input"); }, children: r.value }), r.label && labels.length > 0 && _jsx("span", { className: "o-values-editor-label", children: r.label }), _jsxs("span", { className: "o-values-editor-acts", children: [_jsx(Button, { kind: "quiet", shape: "icon", size: "40x44", look: { radius: "md", corner: "round", edge: "none", words: "inherit", icon: "20", hover: "none", press: "card" }, className: "o-values-editor-open", nativeButton: false, render: _jsx("a", { href: act.href }), "aria-label": w.open[kind](r.value), icon: glyph(kind === "phone" ? CALL : kind === "email" ? MAIL : OPEN) }), _jsx(Button, { kind: "quiet", shape: "icon", size: "40x44", look: { radius: "md", corner: "round", edge: "none", words: "inherit", icon: "20", hover: "none", press: "card" }, className: "o-values-editor-remove", "aria-label": w.remove(r.value), onClick: () => remove(i), icon: glyph(TRASH) })] })] })] }), bad[i] && !shell && _jsx("p", { className: "o-values-editor-error", role: "alert", children: bad[i] })] }, r.id));
315
+ }), showLine && (_jsxs("div", { className: "o-values-editor-line", "data-bad": refusal ? "" : undefined, children: [kind === "phone"
316
+ ? _jsxs(_Fragment, { children: [_jsx(Button, { kind: "quiet", size: "sm", look: { radius: "md", corner: "round", edge: "none", words: "inherit", colour: "text", icon: "12", iconColour: "faint", pad: "8", gap: "4" }, className: "o-values-editor-code", "aria-label": w.countryIs(countryName(reading, language)), onClick: () => go("dial"), iconEnd: glyph(DOWN), children: reading }), _jsx("span", { className: "o-values-editor-prefix", children: dialOf(reading) })] })
317
+ : _jsx("span", { className: "o-values-editor-plus", children: glyph(PLUS) }), _jsx(Input, { chrome: "bare", numeric: true, className: "o-values-editor-line-input", "aria-label": w.add[kind], value: typed, placeholder: kind === "phone" ? patternOf(reading) : w.cardLine[kind], type: keys.type, inputMode: keys.inputMode, autofill: false, autoCapitalize: keys.autoCapitalize, enterKeyHint: "enter", onChange: (e) => setTyped(e.target.value), onKeyDown: lineKeys })] }))] }), refusal && !shell && _jsx("p", { className: "o-values-editor-error", role: "alert", children: refusal })] }));
318
+ const cards = (_jsxs(FieldRows, { look: MIHAI_CARDS, className: "o-values-editor-cards", role: "list", "aria-label": label, children: [rows.map((r, i) => (_jsxs("div", { role: "listitem", "data-row": r.id, "data-lifted": lifted(r, i), style: lift(i), children: [_jsxs(FieldRow, { as: "div", className: "o-values-editor-card", children: [!one && grip(r, i, LINES, "20x24", { radius: "md", corner: "round", edge: "none", words: "inherit", colour: "faint", cursor: "grab", hover: "none", icon: "20" }), _jsx(Input, { chrome: "bare", numeric: true, className: "o-values-editor-card-input", "aria-label": w.nth[kind](i + 1), value: r.value, type: keys.type, inputMode: keys.inputMode, autofill: false, autoCapitalize: keys.autoCapitalize, onChange: (e) => setRows((rs) => rs.map((x) => (x.id === r.id ? { ...x, value: e.target.value } : x))) }), labels.length > 0 && _jsx(Button, { kind: "quiet", size: "line", look: { radius: "none", corner: "round", edge: "none", words: "sm", hover: "none" }, className: "o-values-editor-label", "aria-label": w.labelIs(r.label ?? w.noLabel), onClick: () => go("label", i), children: r.label ?? w.label }), _jsx(Button, { kind: "danger", shape: "round", size: "2xs", look: { edge: "none", words: "inherit", colour: "inherit", hover: "none" }, className: "o-values-editor-minus", "aria-label": w.remove(r.value), onClick: () => remove(i), children: _jsx("span", {}) })] }), bad[i] && !shell && _jsx("p", { className: "o-values-editor-error", role: "alert", children: bad[i] })] }, r.id))), showLine && _jsxs("div", { className: "o-values-editor-adding", children: [_jsxs(FieldRow, { className: "o-values-editor-card o-values-editor-new", children: [kind === "phone" ? _jsxs(_Fragment, { children: [dial && _jsx(Button, { kind: "quiet", shape: "icon", size: "line", look: { radius: "md", corner: "round", edge: "none", words: "xs-medium", colour: "text", disabled: "plain" }, className: "o-values-editor-code", "aria-label": w.countryCodeIs(dial.country), disabled: dialCodes.length < 2, onClick: () => go("dial"), icon: _jsx(Flag, { code: dial.country, size: "lg" }) }), dial && _jsx("span", { className: "o-values-editor-prefix", children: dial.code })] }) : glyph(ICON[kind]), _jsx(Input, { chrome: "bare", numeric: true, className: "o-values-editor-card-input", value: typed, placeholder: w.add[kind], type: keys.type, inputMode: keys.inputMode, autofill: false, autoCapitalize: keys.autoCapitalize, enterKeyHint: "done", onChange: (e) => setTyped(e.target.value), onKeyDown: lineKeys })] }), _jsx(Button, { kind: "soft", size: "lg", onClick: add, children: w.addButton })] }), refusal && !shell && _jsx("p", { className: "o-values-editor-error", role: "alert", children: refusal })] }));
319
+ const body = (_jsx("div", { ref: placeRoot, className: "o-values-editor", "data-kit": "values-editor", ...device, "data-values-form": "phone", "data-values-view": view, "data-values-holds": one ? "one" : "several", "data-values-phone": worn.phone, children: view === "label" ? labelList.body : view === "dial" ? dialList.body : cardsLook ? cards : card }));
320
+ if (view !== "rows")
321
+ return { body, head: { onBack: back, close: false }, title: view === "label" ? w.label : w.countryCode };
322
+ const save = () => {
323
+ if (edit != null && !finishEdit())
324
+ return;
325
+ if (rows.some((r) => rule(r.value))) {
326
+ setChecked(true);
327
+ return;
328
+ }
329
+ const r = lineRead();
330
+ if ("error" in r && r.error) {
331
+ setTried(true);
332
+ return;
333
+ }
334
+ keep(true);
335
+ };
336
+ if (shell)
337
+ return { body, head: {} };
338
+ return { body, head: { left: _jsx(SheetButton, { "aria-label": w.close, icon: glyph(X), onClick: leave }), right: _jsx(SheetButton, { kind: "primary", "aria-label": w.save, icon: glyph(TICK), onClick: save }) } };
339
+ }
340
+ const onBlur = (e) => {
341
+ if (shell || settled.current || swapping.current || drop || !(e.target instanceof Node) || !e.currentTarget.contains(e.target))
342
+ return;
343
+ const to = e.relatedTarget;
344
+ if (to instanceof Node && (e.currentTarget.contains(to) || popup.current?.contains(to)))
345
+ return;
346
+ keep(true);
347
+ };
348
+ const onKeyDown = (e) => {
349
+ if (midWord(e.nativeEvent) || drop)
350
+ return;
351
+ if (shell) {
352
+ if (e.key === "Escape" && view !== "rows") {
353
+ e.preventDefault();
354
+ e.stopPropagation();
355
+ back();
356
+ }
357
+ return;
358
+ }
359
+ if (e.key === "Escape") {
360
+ e.preventDefault();
361
+ e.stopPropagation();
362
+ if (view !== "rows")
363
+ back();
364
+ else
365
+ keep(true);
366
+ }
367
+ };
368
+ const editKeys = (e) => {
369
+ if (e.key !== "Enter" || midWord(e.nativeEvent))
370
+ return;
371
+ e.preventDefault();
372
+ const v = editText.trim() ? keepAs(editText) : "";
373
+ if (v && rule(v)) {
374
+ if (shell)
375
+ onDone?.();
376
+ return;
377
+ }
378
+ if (one) {
379
+ keep();
380
+ return;
381
+ }
382
+ hold();
383
+ finishEdit();
384
+ setFocusTo(".o-values-editor-line-input");
385
+ };
386
+ const lineKeys = (e) => {
387
+ if (e.key !== "Enter" || midWord(e.nativeEvent))
388
+ return;
389
+ e.preventDefault();
390
+ if (one) {
391
+ const r = lineRead();
392
+ if ("error" in r && r.error)
393
+ setTried(true);
394
+ if ("value" in r || !r.error || shell)
395
+ keep(true);
396
+ return;
397
+ }
398
+ const a = add();
399
+ if (a === "empty" || (a === "refused" && shell))
400
+ keep();
401
+ };
402
+ const editRefusal = editing != null && editText.trim() ? rule(keepAs(editText)) : null;
403
+ const showLine = !(one && rows.length > 0);
404
+ const labelButton = (r, i) => labels.length > 0 && (_jsx(InputGroupAddon, { side: "end", children: _jsx(InputGroupButton, { className: "o-values-editor-edit-label", size: "line", look: under ? { radius: "xs", corner: "round", edge: "none", words: "sm", iconColour: "faint", pad: "4", hover: "words", open: "hovered" } : { radius: "none", corner: "round", edge: "none", words: "xs", hover: "words" }, "aria-label": w.labelIs(r.label ?? w.noLabel), "aria-haspopup": under ? "listbox" : undefined, "aria-expanded": under ? drop?.what === "label" : undefined, onClick: open("label", i), iconEnd: under ? glyph(DOWN) : undefined, children: r.label ?? w.label }) }));
405
+ const code = attio ? (_jsx(Button, { kind: "quiet", size: "2xs", look: { radius: "sm", corner: "round", edge: "none", words: "inherit", colour: "text", icon: "12", iconColour: "faint", pad: "6", open: "hovered" }, className: "o-values-editor-code", "aria-label": w.countryIs(countryName(reading, language)), "aria-haspopup": "listbox", "aria-expanded": drop?.what === "dial", onClick: open("dial"), iconEnd: glyph(DOWN), children: reading })) : dial && (_jsx(Button, { kind: "quiet", size: "26", look: { radius: "md", corner: "round", edge: "none", words: "xs-medium", colour: "text", disabled: "plain", icon: "12", iconColour: "faint" }, className: "o-values-editor-code", "aria-label": w.countryCodeIs(dial.country), disabled: dialCodes.length < 2, onClick: open("dial"), icon: _jsx(Flag, { code: dial.country }), iconEnd: dialCodes.length > 1 ? glyph(DOWN) : undefined, children: dial.country }));
406
+ const line = (_jsxs("div", { className: cx("o-values-editor-line", !attio && "o-popup-line"), "data-at": attio ? undefined : "foot", "data-bad": refusal ? "" : undefined, children: [kind === "phone"
407
+ ? _jsxs(_Fragment, { children: [code, attio ? _jsx("span", { className: "o-values-editor-prefix", children: dialOf(reading) }) : dial?.code && _jsx("span", { className: "o-values-editor-prefix", children: dial.code })] })
408
+ : attio ? _jsx("span", { className: "o-values-editor-plus", children: glyph(PLUS) }) : glyph(ICON[kind]), _jsx(Input, { chrome: "bare", numeric: true, className: "o-values-editor-line-input", "aria-label": w.add[kind], placeholder: kind === "phone" ? (attio ? patternOf(reading) : hint) : attio ? w.line[kind] : hint, value: typed, type: keys.type, inputMode: keys.inputMode, autofill: false, spellCheck: false, "aria-invalid": refusal ? true : undefined, onChange: (e) => setTyped(e.target.value), onKeyDown: lineKeys })] }));
409
+ const body = (_jsx("div", { ref: placeRoot, className: "o-values-editor", "data-kit": "values-editor", ...device, "data-values-form": "computer", "data-values-view": view, "data-values-holds": one ? "one" : "several", "data-values-rows": worn.rows, "data-values-main": worn.main, "data-values-line": worn.line, "data-values-lists": worn.lists, ...(view !== "rows" ? { [EDITOR_INNER_ESCAPE]: "" } : {}), role: "group", "aria-label": label, tabIndex: -1, onBlur: onBlur, onFocus: () => { settled.current = false; }, onKeyDown: onKeyDown, children: view === "rows" ? _jsxs(_Fragment, { children: [rows.length > 0 && (_jsx("div", { className: "o-values-editor-rows", role: "list", "aria-label": label, children: rows.map((r, i) => (_jsxs("div", { role: "listitem", className: "o-values-editor-row", "data-row": r.id, "data-lifted": lifted(r, i), style: lift(i), onPointerLeave: () => { if (copied === r.id)
410
+ setCopied(null); }, children: [!one && grip(r, i, GRIP, worn.rows === "copy" ? "2xs" : "20x24", { radius: worn.rows === "copy" ? "sm" : "md", corner: "round", edge: "none", words: "inherit", colour: "faint", cursor: "grab", hover: "none" }), editing === i ? (_jsxs(InlineInputGroup, { className: "o-values-editor-edit", style: ROW_28, "data-bad": editRefusal ? "" : undefined, children: [_jsx(Input, { numeric: true, "aria-label": w.change(r.value), value: editText, type: keys.type, inputMode: keys.inputMode, autofill: false, spellCheck: false, "aria-invalid": editRefusal ? true : undefined, onChange: (e) => setEditText(e.target.value), onKeyDown: editKeys, onBlur: (e) => { const to = e.relatedTarget; if (to && to !== root.current && root.current?.contains(to) && !e.currentTarget.parentElement?.contains(to) && !swapping.current)
411
+ finishEdit(); } }), labelButton(r, i)] })) : _jsxs(_Fragment, { children: [(() => {
412
+ const parts = kind === "email" ? splitEmail(r.value) : null;
413
+ const value = _jsx("button", { type: "button", className: "o-values-editor-value", "aria-label": r.value, onClick: () => { hold(); if (!finishEdit()) {
414
+ setFocusTo(".o-values-editor-edit input");
415
+ return;
416
+ } setEditing(i); setEditText(r.value); setFocusTo(".o-values-editor-edit input"); }, children: parts ? _jsxs(_Fragment, { children: [_jsx("span", { className: "o-values-editor-name", "data-name": parts[0], children: parts[0] }), _jsx("span", { className: "o-values-editor-domain", children: parts[1] })] }) : r.value });
417
+ return worn.rows === "copy" ? (_jsxs("span", { className: "o-values-editor-pill", children: [value, _jsx(Button, { kind: "quiet", shape: "icon", size: "20", look: { radius: "xs", corner: "round", edge: "none", words: "inherit", colour: "link", icon: "15", hover: "none" }, className: "o-values-editor-copy", "aria-label": w.copy(r.value), "data-copied": copied === r.id ? "" : undefined, onClick: copy(r), icon: glyph(copied === r.id ? TICK : COPY) })] })) : value;
418
+ })(), !one && worn.main === "pill" && r.id === mainId && _jsx("span", { className: "o-values-editor-main", children: w.main }), r.label && !one && _jsx("span", { className: "o-values-editor-label", children: r.label }), _jsx(Button, { kind: "quiet", shape: "icon", size: worn.rows === "copy" ? "2xs" : "22", look: worn.rows === "copy" ? { radius: "sm", corner: "round", edge: "none", words: "inherit", icon: "16" } : { radius: "md", corner: "round", edge: "none", words: "inherit" }, className: "o-values-editor-remove", "aria-label": w.remove(r.value), icon: glyph(worn.rows === "copy" ? TRASH : X), onClick: () => { hold(); remove(i); setFocusTo(editing != null ? ".o-values-editor-edit input" : ".o-values-editor-line-input"); } })] })] }, r.id))) })), editRefusal && !shell && _jsx("p", { className: "o-values-editor-error", role: "alert", children: editRefusal }), showLine && line, refusal && !shell && _jsx("p", { className: "o-values-editor-error", role: "alert", children: refusal }), under && (_jsx(Popover, { open: !!drop, popupData: props.popupData, anchor: drop?.at, side: "bottom", align: "start", sideOffset: spacingPx(1, drop?.at), finalFocus: dropBack, "aria-label": drop?.what === "label" ? w.label : w.country, style: { width: drop?.what === "label" ? "calc(var(--vk-spacing) * 48)" : "calc(var(--vk-spacing) * 60)" }, onOpenChange: (o, d) => {
419
+ if (o)
420
+ return;
421
+ closeDrop();
422
+ if (!shell && d.reason === "outside-press" && !(d.event?.target instanceof Node && root.current?.contains(d.event.target)))
423
+ keep(true);
424
+ }, onOutsidePress: (e) => (e.target instanceof Node && drop?.at.contains(e.target) ? false : undefined), children: _jsx("div", { ref: popup, children: drop?.what === "label"
425
+ ? _jsx(Picker, { label: w.label, items: labelItems, value: labelOf != null ? rows[labelOf]?.label ?? null : null, onValueChange: setLabel, onCreate: (t) => t.trim(), onDone: closeDrop, search: w.labelFind, form: "computer", fromHeld: true, ...(w.picker ? { words: w.picker } : {}) })
426
+ : drop && _jsx(Picker, { label: w.country, items: attio ? countryItems(language) : dialItems, value: attio ? reading : country ?? null, onValueChange: (c) => { if (typeof c === "string")
427
+ setCountry(c); }, onDone: closeDrop, search: w.searchCountry, form: "computer", fromHeld: true, ...(w.picker ? { words: w.picker } : {}) }) }) }))] }) : _jsxs(_Fragment, { children: [_jsxs("div", { className: "o-values-editor-back o-popup-line", children: [_jsx(Button, { kind: "quiet", shape: "icon", size: "xs", "aria-label": w.backTo(label.toLowerCase()), icon: glyph(LEFT), onClick: back }), _jsx("span", { children: view === "label" ? w.label : w.countryCode })] }), view === "label"
428
+ ? _jsx(Picker, { label: w.label, items: labelItems, value: labelOf != null ? rows[labelOf]?.label ?? null : null, onValueChange: setLabel, onCreate: (t) => t.trim(), onDone: back, search: w.labelFind, form: "computer", fromHeld: true, ...(w.picker ? { words: w.picker } : {}) })
429
+ : _jsx(Picker, { label: w.countryCode, items: attio ? countryItems(language) : dialItems, value: attio ? reading : country ?? null, onValueChange: (c) => { if (typeof c === "string")
430
+ setCountry(c); }, onDone: back, search: w.findCountry, form: "computer", fromHeld: true, ...(w.picker ? { words: w.picker } : {}) })] }) }));
431
+ return { body, head: {} };
432
+ }
433
+ export function ValuesEditor(props) {
434
+ return _jsx(_Fragment, { children: useValuesEditor(props).body });
435
+ }
@@ -0,0 +1,71 @@
1
+ /** What a field holds several of. */
2
+ export type ValuesKind = "email" | "phone" | "link" | "domain";
3
+ /** One value of the list: what it is, its label (Work, Mobile), and whether it is the main one. */
4
+ export interface ListedValue {
5
+ value: string;
6
+ label?: string;
7
+ main?: boolean;
8
+ }
9
+ /** A phone's country code, as the field hands it in: the country (RO), its code (+40), and how a number is written there. */
10
+ export interface DialCode {
11
+ country: string;
12
+ code: string;
13
+ hint?: string;
14
+ }
15
+ /** The four labels' words, in the app's language. */
16
+ export interface LabelWords {
17
+ work: string;
18
+ personal: string;
19
+ mobile: string;
20
+ other: string;
21
+ }
22
+ /** The labels a value is picked from, in the words handed; unhanded, LABELS. */
23
+ export declare const labelsOf: (words?: LabelWords) => string[];
24
+ /** The labels a value is picked from, in English; one may be typed too. */
25
+ export declare const LABELS: string[];
26
+ /** A new value's label: Work for an email, Mobile for a phone, Other for a link, in the words handed; a domain has none. */
27
+ export declare const labelFor: (kind: ValuesKind, words?: LabelWords) => string | undefined;
28
+ /** The list with its main one first and marked main alone; with none marked, the first is the main one. */
29
+ export declare function listOf(values: ListedValue[]): ListedValue[];
30
+ /** An email as its name and its domain, split at its last @ (the domain keeps its @): on a touch screen the name is cut and
31
+ * the domain stays whole (KIT-455). Null for a value with no name before an @. */
32
+ export declare function splitEmail(value: string): [string, string] | null;
33
+ /** How many of a name's characters stand before its ellipsis: all of them when the whole fits `room`, else the most whose
34
+ * width with the ellipsis's does. `widths` are the widths after 1, 2, … characters, as a Range reads them (KIT-455). */
35
+ export declare function charsThatFit(widths: number[], room: number, ellipsis: number): number;
36
+ /** What the line reads: the value it adds, or why not ("" for nothing typed), with what was typed, trimmed. */
37
+ export type LineRead = {
38
+ value: string;
39
+ } | {
40
+ error: string;
41
+ typed?: string;
42
+ };
43
+ /** What the line adds: the value as `keep` keeps it (the body hands in the Text editor's kept; left out, trimmed), a phone's
44
+ * country code before it unless one is typed; or why `check` refuses it, with what was typed. Nothing typed is refused with no
45
+ * words: there is nothing to add. */
46
+ export declare function added(kind: ValuesKind, typed: string, check: (value: string) => string | null, dial?: DialCode, keep?: (typed: string) => string): LineRead;
47
+ /** What the list keeps, and what it hands a shell that keeps the draft (KIT-744), as one rule: the rows, a value being edited put
48
+ * back in its row (kept as `keep` keeps it; emptied, the row gone), rows left empty dropped, then what the line reads where it
49
+ * reads a value (`line`, as the line reads it: `added`, or a phone read in its country), with `label`; the first the main one.
50
+ * A refused edit keeps its row as it was, and a refused line hands nothing; with `refused` (a shell that judges the list
51
+ * itself, Mihai, 27 Nov 2026), each is handed as typed, so the holder refuses it and says why. */
52
+ export declare function handedList(rows: readonly {
53
+ value: string;
54
+ label?: string;
55
+ }[], edit: {
56
+ at: number;
57
+ text: string;
58
+ } | null, line: LineRead | null, o: {
59
+ check: (v: string) => string | null;
60
+ keep: (t: string) => string;
61
+ label?: string;
62
+ refused?: boolean;
63
+ }): ListedValue[];
64
+ /** What a cell shows: the main one, and how many more ("+40 773 768 874 +1"). */
65
+ export declare function valuesText(values: ListedValue[]): string;
66
+ /** A value's open action: a call, an email written, the page; and its name to a screen reader, in English (the body names it in
67
+ * the app's words). */
68
+ export declare function openOf(kind: ValuesKind, value: string): {
69
+ href: string;
70
+ label: string;
71
+ };
@@ -0,0 +1,59 @@
1
+ const ENGLISH = { work: "Work", personal: "Personal", mobile: "Mobile", other: "Other" };
2
+ export const labelsOf = (words = ENGLISH) => [words.work, words.personal, words.mobile, words.other];
3
+ export const LABELS = labelsOf(ENGLISH);
4
+ const NEW_LABEL = { email: "work", phone: "mobile", link: "other", domain: undefined };
5
+ export const labelFor = (kind, words = ENGLISH) => {
6
+ const k = NEW_LABEL[kind];
7
+ return k ? words[k] : undefined;
8
+ };
9
+ export function listOf(values) {
10
+ const at = Math.max(0, values.findIndex((v) => v.main));
11
+ const ordered = values.length ? [values[at], ...values.filter((_, i) => i !== at)] : [];
12
+ return ordered.map((v, i) => ({ ...v, main: i === 0 }));
13
+ }
14
+ export function splitEmail(value) {
15
+ const at = value.lastIndexOf("@");
16
+ return at > 0 ? [value.slice(0, at), value.slice(at)] : null;
17
+ }
18
+ export function charsThatFit(widths, room, ellipsis) {
19
+ if (!widths.length || widths[widths.length - 1] <= room)
20
+ return widths.length;
21
+ let k = 0;
22
+ while (k < widths.length && widths[k] + ellipsis <= room)
23
+ k++;
24
+ return k;
25
+ }
26
+ export function added(kind, typed, check, dial, keep = (t) => t.trim()) {
27
+ const v = typed.trim() ? keep(typed) : "";
28
+ if (!v)
29
+ return { error: "" };
30
+ const value = kind === "phone" && dial && !v.startsWith("+") ? `${dial.code} ${v}` : v;
31
+ const refusal = check(value);
32
+ return refusal ? { error: refusal, typed: typed.trim() } : { value };
33
+ }
34
+ export function handedList(rows, edit, line, o) {
35
+ const now = rows.flatMap((r, i) => {
36
+ if (!edit || i !== edit.at)
37
+ return [r];
38
+ const v = edit.text.trim() ? o.keep(edit.text) : "";
39
+ if (!v)
40
+ return [];
41
+ if (o.check(v))
42
+ return o.refused ? [{ ...r, value: edit.text.trim() }] : [r];
43
+ return [{ ...r, value: v }];
44
+ }).filter((r) => r.value.trim());
45
+ const typed = line && "value" in line ? line.value : line && o.refused && line.error && line.typed?.trim() ? line.typed.trim() : null;
46
+ const all = typed != null ? [...now, { value: typed, ...(o.label ? { label: o.label } : {}) }] : now;
47
+ return all.map((r, i) => ({ value: r.value, ...(r.label ? { label: r.label } : {}), main: i === 0 }));
48
+ }
49
+ export function valuesText(values) {
50
+ const list = listOf(values);
51
+ return list.length ? `${list[0].value}${list.length > 1 ? ` +${list.length - 1}` : ""}` : "";
52
+ }
53
+ export function openOf(kind, value) {
54
+ if (kind === "phone")
55
+ return { href: `tel:${value.replace(/[^\d+]/g, "")}`, label: `Call ${value}` };
56
+ if (kind === "email")
57
+ return { href: `mailto:${value}`, label: `Write to ${value}` };
58
+ return { href: /^https?:\/\//i.test(value) ? value : `https://${value}`, label: `Open ${value}` };
59
+ }
@@ -0,0 +1,50 @@
1
+ import type { PickerWords } from "../picker/picker.js";
2
+ import type { LabelWords, ValuesKind } from "./values.js";
3
+ export interface ValuesEditorWords {
4
+ /** Attio's line: "Add email…", "Add link…", "Add domain…" (a phone shows its pattern). */
5
+ line: Record<Exclude<ValuesKind, "phone">, string>;
6
+ /** Attio's card's line on a phone: "Add email", "Add link", "Add domain". */
7
+ cardLine: Record<Exclude<ValuesKind, "phone">, string>;
8
+ /** The line's name, and Mihai's placeholder: "Add an email". */
9
+ add: Record<ValuesKind, string>;
10
+ /** A card's box on a phone, in Mihai's look: "email 2". */
11
+ nth: Record<ValuesKind, (n: number) => string>;
12
+ /** Mihai's Add, on a phone. */
13
+ addButton: string;
14
+ /** A value's buttons. */
15
+ change: (value: string) => string;
16
+ copy: (value: string) => string;
17
+ move: (value: string) => string;
18
+ remove: (value: string) => string;
19
+ /** A value's open action: a call, an email written, the page. */
20
+ open: Record<ValuesKind, (value: string) => string>;
21
+ /** The main value's mark, in Mihai's look. */
22
+ main: string;
23
+ /** An unlabelled value's label button, the label list's name and its step's title. */
24
+ label: string;
25
+ /** A label button's name: "Label: Work", and "none" for no label. */
26
+ labelIs: (label: string) => string;
27
+ noLabel: string;
28
+ /** The label list's search, on a phone and on a computer. */
29
+ labelSearch: string;
30
+ labelFind: string;
31
+ /** The labels a value is picked from. */
32
+ labels: LabelWords;
33
+ /** A phone's country: the list's name, its searches, its step's title, and its button's names. */
34
+ country: string;
35
+ searchCountry: string;
36
+ findCountry: string;
37
+ countryCode: string;
38
+ countryIs: (country: string) => string;
39
+ countryCodeIs: (country: string) => string;
40
+ /** Back from a list in the values' place: "Back to emails" (the field's name, lowercased). */
41
+ backTo: (label: string) => string;
42
+ /** On a phone, its own sheet head's ✕ and ✓ (where no holder draws them). */
43
+ close: string;
44
+ save: string;
45
+ /** The words of its lists. */
46
+ picker?: Partial<PickerWords>;
47
+ }
48
+ export declare const VALUES_EDITOR_WORDS: ValuesEditorWords;
49
+ /** The words handed over the English. */
50
+ export declare const valuesWords: (given?: Partial<ValuesEditorWords>) => ValuesEditorWords;