viewkitjs 0.24.0 → 0.25.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 (82) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/fields/dist/creatable.d.ts +9 -5
  3. package/fields/dist/creatable.js +8 -1
  4. package/fields/dist/messages.d.ts +19 -1
  5. package/fields/dist/messages.js +75 -0
  6. package/fields/dist/registry.js +4 -7
  7. package/fields/dist/types.d.ts +4 -2
  8. package/fields/dist/zod.d.ts +58 -0
  9. package/fields/dist/zod.js +430 -2
  10. package/fields/docs/guides/checking-definitions.md +6 -1
  11. package/fields/docs/guides/field-types.md +5 -1
  12. package/fields/docs/reference/definitions.md +1 -2
  13. package/fields/docs/reference/types.md +2 -1
  14. package/fields/skills/viewkit/SKILL.md +2 -2
  15. package/package.json +1 -1
  16. package/views/dist/controls/avatar/avatar.d.ts +58 -0
  17. package/views/dist/controls/avatar/avatar.js +54 -0
  18. package/views/dist/controls/avatar/looks.d.ts +4 -0
  19. package/views/dist/controls/avatar/looks.js +5 -0
  20. package/views/dist/controls/avatar/tokens.d.ts +131 -0
  21. package/views/dist/controls/avatar/tokens.js +35 -0
  22. package/views/dist/controls/avatar.css +163 -0
  23. package/views/dist/controls/controls.d.ts +2 -0
  24. package/views/dist/controls/controls.js +2 -0
  25. package/views/dist/controls/index.d.ts +12 -0
  26. package/views/dist/controls/index.js +12 -0
  27. package/views/dist/controls/internal/phone.d.ts +9 -0
  28. package/views/dist/controls/internal/phone.js +15 -0
  29. package/views/dist/controls/internal/read-token.d.ts +2 -1
  30. package/views/dist/controls/internal/read-token.js +1 -1
  31. package/views/dist/controls/internal/scroll.d.ts +38 -0
  32. package/views/dist/controls/internal/scroll.js +126 -0
  33. package/views/dist/controls/list/looks.d.ts +4 -0
  34. package/views/dist/controls/list/looks.js +12 -0
  35. package/views/dist/controls/list.css +17 -13
  36. package/views/dist/controls/menu/map-menu.d.ts +11 -0
  37. package/views/dist/controls/menu/map-menu.js +47 -0
  38. package/views/dist/controls/menu/menu.d.ts +75 -0
  39. package/views/dist/controls/menu/menu.js +105 -0
  40. package/views/dist/controls/menu/tokens.d.ts +23 -0
  41. package/views/dist/controls/menu/tokens.js +8 -0
  42. package/views/dist/controls/menu-list/looks.d.ts +5 -1
  43. package/views/dist/controls/menu-list/looks.js +6 -4
  44. package/views/dist/controls/menu-list/menu-list.js +3 -1
  45. package/views/dist/controls/menu-list.css +39 -31
  46. package/views/dist/controls/menu.css +25 -0
  47. package/views/dist/controls/picker/looks.d.ts +19 -0
  48. package/views/dist/controls/picker/looks.js +32 -0
  49. package/views/dist/controls/picker/picker.d.ts +153 -0
  50. package/views/dist/controls/picker/picker.js +773 -0
  51. package/views/dist/controls/picker/rows.d.ts +129 -0
  52. package/views/dist/controls/picker/rows.js +90 -0
  53. package/views/dist/controls/picker/tokens.d.ts +147 -0
  54. package/views/dist/controls/picker/tokens.js +39 -0
  55. package/views/dist/controls/picker.css +237 -0
  56. package/views/dist/controls/popup-line/tokens.d.ts +23 -0
  57. package/views/dist/controls/popup-line/tokens.js +8 -0
  58. package/views/dist/controls/popup-line.css +44 -0
  59. package/views/dist/controls/select/filled.d.ts +7 -0
  60. package/views/dist/controls/select/filled.js +5 -0
  61. package/views/dist/controls/select/fit.d.ts +9 -0
  62. package/views/dist/controls/select/fit.js +11 -0
  63. package/views/dist/controls/select/select.d.ts +131 -0
  64. package/views/dist/controls/select/select.js +227 -0
  65. package/views/dist/controls/select/side.d.ts +3 -0
  66. package/views/dist/controls/select/side.js +4 -0
  67. package/views/dist/controls/select/tokens.d.ts +27 -0
  68. package/views/dist/controls/select/tokens.js +9 -0
  69. package/views/dist/controls/select.css +91 -0
  70. package/views/dist/controls/tokens.js +10 -0
  71. package/views/dist/looks/index.d.ts +4 -0
  72. package/views/dist/looks/index.js +4 -0
  73. package/views/dist/looks/pieces.js +6 -0
  74. package/views/dist/styles.css +586 -62
  75. package/views/dist/styles.unlayered.css +586 -62
  76. package/views/docs/controls/avatar.md +38 -0
  77. package/views/docs/controls/menu.md +11 -0
  78. package/views/docs/controls/picker.md +42 -0
  79. package/views/docs/controls/popup-line.md +11 -0
  80. package/views/docs/controls/select.md +12 -0
  81. package/views/docs/reference/controls.md +86 -0
  82. package/views/docs/reference/looks.md +8 -0
@@ -0,0 +1,129 @@
1
+ import type { ReactNode } from "react";
2
+ import type { StatusPlace } from "../status/status.js";
3
+ import type { MenuEntry } from "../menu-list/menu-list.js";
4
+ /** How a row draws its name: an Option chip (a select's value), a step with its Status glyph, an Avatar before it, a sign
5
+ * before it (a currency's €), a mark before it (a country's flag), or, left out, plain words. */
6
+ export type PickerAs = {
7
+ option: true;
8
+ } | {
9
+ status: StatusPlace;
10
+ quarters?: 1 | 2 | 3;
11
+ } | {
12
+ avatar: "person" | "company";
13
+ id?: string;
14
+ src?: string;
15
+ } | {
16
+ sign: string;
17
+ } | {
18
+ mark: ReactNode;
19
+ };
20
+ /** One value the field can hold: its value and its name, how it draws its name, a quieter second line, "you" after the person
21
+ * themself, the group it stands under, whether it can be picked, the kind's word when the field links to several, and a line
22
+ * above it, setting it apart from the rows before (the Select's Lost, off for now; on a computer only); and its level, the
23
+ * rows it leads one level in (a deal's Company, its Name, Industry and Region), which it opens and never picks; and its
24
+ * own menu, what can be done to that one row (a view's Rename…, Delete view…), ⋮ at its end opening it, never picking; and its
25
+ * count, how many records hold it (a quick filter's value), at its end, right before what says it is held.
26
+ * A row that leads one level in keeps its level's count and ›. And a mark after its name (a private view's lock), quieter.
27
+ */
28
+ export interface PickerItem {
29
+ value: string;
30
+ label: string;
31
+ as?: PickerAs;
32
+ line?: string;
33
+ you?: boolean;
34
+ group?: string;
35
+ disabled?: boolean;
36
+ kind?: string;
37
+ divider?: boolean;
38
+ level?: PickerItem[];
39
+ menu?: MenuEntry[];
40
+ count?: number;
41
+ after?: ReactNode;
42
+ }
43
+ export type PickerRow = {
44
+ kind: "empty";
45
+ label: string;
46
+ } | {
47
+ kind: "heading";
48
+ label: string;
49
+ }
50
+ /** A value's row: whether the field holds it, whether it stands in an open level (indented under its row), and, where it leads one
51
+ * level in, that it opens and how many rows it holds. */
52
+ | {
53
+ kind: "item";
54
+ item: PickerItem;
55
+ picked: boolean;
56
+ indent?: true;
57
+ opens?: true;
58
+ count?: number;
59
+ }
60
+ /** The open level's own row, on top: what its rows stand under. */
61
+ | {
62
+ kind: "parent";
63
+ item: PickerItem;
64
+ } | {
65
+ kind: "create";
66
+ typed: string;
67
+ } | {
68
+ kind: "more";
69
+ }
70
+ /** The line under the values listed first. */
71
+ | {
72
+ kind: "line";
73
+ };
74
+ export interface RowsInput {
75
+ /** What the list shows (less what stands as chips). */
76
+ items: PickerItem[];
77
+ /** Every value the field knows, for Create's exact match; left out, `items`. */
78
+ known?: PickerItem[];
79
+ /** What is typed in the search. */
80
+ query: string;
81
+ /** The values the field holds. */
82
+ picked: string[];
83
+ /** The empty row's words; left out, the field can't be empty. */
84
+ empty?: string;
85
+ /** The field takes new values. */
86
+ create: boolean;
87
+ /** The values come from a server search: its answer is shown as it is. */
88
+ server: boolean;
89
+ /** More rows are to come. */
90
+ more: boolean;
91
+ /** The values listed first, above a line, while nothing is typed (Attio's several). */
92
+ first?: string[];
93
+ /** The levels opened, outermost first: the list shows the last one's rows, under its own row. */
94
+ open?: PickerItem[];
95
+ /** Whether an open level's own row stands on top, its rows indented under it (the default); false where the Picker's holder names
96
+ * the level itself: the level's rows stand alone, as a list of their own. */
97
+ levelRow?: boolean;
98
+ }
99
+ /** The levels open, by their rows' values, outermost first, as far as the items still hold them. */
100
+ export declare function openLevels(items: PickerItem[], values: string[]): PickerItem[];
101
+ export declare const fold: (s: string) => string;
102
+ /** The item whose name is what was typed, whatever its case and the spaces round it. */
103
+ export declare function exactMatch(items: PickerItem[], query: string): PickerItem | undefined;
104
+ export declare function pickerRows({ items, known, query, picked, empty, create, server, more, first, open, levelRow }: RowsInput): PickerRow[];
105
+ /** Every item's value in its order after `value` moved to where `target` stands: before it, moving up; after it, moving
106
+ * down, by their places in `items`. An unknown value or target, or the same, leaves the order as it is. */
107
+ export declare function orderMoved(items: PickerItem[], value: string, target: string): string[];
108
+ /** Anything that leads one level in as a Picker's item does: the Picker's own, and the Select's items it is handed. */
109
+ type Leading<T> = {
110
+ value: string;
111
+ label: string;
112
+ level?: T[];
113
+ };
114
+ /** The item holding `value`, at the top or any level in, and the path to it: the levels it stands in, outermost first. */
115
+ export declare function findItem<T extends Leading<T> = PickerItem>(items: T[], value: string): {
116
+ item: T;
117
+ path: T[];
118
+ } | undefined;
119
+ /** An item's name by its path, each level's name before it ("Company › Region"); one at the top, its own name; one not found, its value. */
120
+ export declare function itemLabel<T extends Leading<T> = PickerItem>(items: T[], value: string): string;
121
+ /** Whether the search shows, unless what holds the Picker says: past 8 values, on a field that takes new values, with a server
122
+ * search, or once something is typed on what opened it (a cell's letter). With none shown, a letter jumps to its row. */
123
+ export declare function searchShown({ count, create, server, query }: {
124
+ count: number;
125
+ create: boolean;
126
+ server: boolean;
127
+ query: string;
128
+ }): boolean;
129
+ export {};
@@ -0,0 +1,90 @@
1
+ export function openLevels(items, values) {
2
+ const out = [];
3
+ for (let list = items, k = 0; k < values.length; k++) {
4
+ const it = list.find((i) => i.value === values[k]);
5
+ if (!it?.level)
6
+ break;
7
+ out.push(it);
8
+ list = it.level;
9
+ }
10
+ return out;
11
+ }
12
+ export const fold = (s) => s.normalize("NFD").replace(/\p{M}/gu, "").trim().toLowerCase();
13
+ export function exactMatch(items, query) {
14
+ const q = fold(query);
15
+ return q ? items.find((i) => fold(i.label) === q) : undefined;
16
+ }
17
+ const itemRow = (item, held) => (item.level ? { kind: "item", item, picked: held.has(item.value), opens: true, count: item.level.length } : { kind: "item", item, picked: held.has(item.value) });
18
+ export function pickerRows({ items, known = items, query, picked, empty, create, server, more, first = [], open = [], levelRow = true }) {
19
+ const level = open[open.length - 1];
20
+ if (level) {
21
+ const inner = level.level ?? [];
22
+ const rows = pickerRows({ items: inner, known: inner, query, picked, create, server: false, more: false, first });
23
+ if (!levelRow)
24
+ return rows;
25
+ return [{ kind: "parent", item: level }, ...rows.map((r) => (r.kind === "item" ? { ...r, indent: true } : r))];
26
+ }
27
+ const q = fold(query), held = new Set(picked);
28
+ const matching = server || !q ? items : items.filter((i) => fold(i.label).includes(q));
29
+ const exact = q ? exactMatch(matching, query) : undefined;
30
+ const ahead = new Set(q ? [] : first), top = matching.filter((i) => ahead.has(i.value));
31
+ const shown = (exact ? matching.filter((i) => i !== exact) : matching).filter((i) => !ahead.has(i.value));
32
+ const ranked = (list) => (server || !q ? list
33
+ : [...list.filter((i) => fold(i.label).startsWith(q)), ...list.filter((i) => !fold(i.label).startsWith(q))]);
34
+ const rows = [];
35
+ if (empty !== undefined && !q && held.size)
36
+ rows.push({ kind: "empty", label: empty });
37
+ if (exact)
38
+ rows.push(itemRow(exact, held));
39
+ for (const item of top)
40
+ rows.push(itemRow(item, held));
41
+ if (top.length && shown.length)
42
+ rows.push({ kind: "line" });
43
+ const groups = [];
44
+ for (const i of shown) {
45
+ const name = i.group ?? "";
46
+ let g = groups.find((x) => x.name === name);
47
+ if (!g)
48
+ groups.push((g = { name, items: [] }));
49
+ g.items.push(i);
50
+ }
51
+ for (const g of groups) {
52
+ if (g.name)
53
+ rows.push({ kind: "heading", label: g.name });
54
+ for (const item of ranked(g.items)) {
55
+ if (item.divider && !q && rows.length)
56
+ rows.push({ kind: "line" });
57
+ rows.push(itemRow(item, held));
58
+ }
59
+ }
60
+ if (create && q && !exactMatch(known, query))
61
+ rows.push({ kind: "create", typed: query.trim() });
62
+ if (more)
63
+ rows.push({ kind: "more" });
64
+ return rows;
65
+ }
66
+ export function orderMoved(items, value, target) {
67
+ const values = items.map((i) => i.value), from = values.indexOf(value), to = values.indexOf(target);
68
+ if (from < 0 || to < 0 || from === to)
69
+ return values;
70
+ const out = values.filter((v) => v !== value);
71
+ out.splice(out.indexOf(target) + (from < to ? 1 : 0), 0, value);
72
+ return out;
73
+ }
74
+ export function findItem(items, value) {
75
+ for (const item of items) {
76
+ if (item.value === value)
77
+ return { item, path: [] };
78
+ const inner = item.level && findItem(item.level, value);
79
+ if (inner)
80
+ return { item: inner.item, path: [item, ...inner.path] };
81
+ }
82
+ return undefined;
83
+ }
84
+ export function itemLabel(items, value) {
85
+ const found = findItem(items, value);
86
+ return found ? [...found.path, found.item].map((i) => i.label).join(" › ") : value;
87
+ }
88
+ export function searchShown({ count, create, server, query }) {
89
+ return count > 8 || create || server || query !== "";
90
+ }
@@ -0,0 +1,147 @@
1
+ export declare const PICKER_TOKENS: readonly [{
2
+ readonly name: "--vk-border";
3
+ readonly kind: "colour";
4
+ readonly outright: "--border";
5
+ }, {
6
+ readonly name: "--vk-border-bold";
7
+ readonly kind: "colour";
8
+ readonly outright: "--border-bold";
9
+ }, {
10
+ readonly name: "--vk-border-subtle";
11
+ readonly kind: "colour";
12
+ readonly outright: "--border-subtle";
13
+ }, {
14
+ readonly name: "--vk-brand";
15
+ readonly kind: "colour";
16
+ readonly outright: "--background-brand-bold";
17
+ }, {
18
+ readonly name: "--vk-fg";
19
+ readonly kind: "colour";
20
+ readonly outright: "--text";
21
+ }, {
22
+ readonly name: "--vk-fg-disabled";
23
+ readonly kind: "colour";
24
+ readonly outright: "--text-disabled";
25
+ }, {
26
+ readonly name: "--vk-fg-inverse";
27
+ readonly kind: "colour";
28
+ readonly outright: "--text-inverse";
29
+ }, {
30
+ readonly name: "--vk-fg-on-brand";
31
+ readonly kind: "colour";
32
+ readonly outright: "--text-brand-inverse";
33
+ }, {
34
+ readonly name: "--vk-fg-subtle";
35
+ readonly kind: "colour";
36
+ readonly outright: "--text-subtle";
37
+ }, {
38
+ readonly name: "--vk-fg-subtlest";
39
+ readonly kind: "colour";
40
+ readonly outright: "--text-subtlest";
41
+ }, {
42
+ readonly name: "--vk-label-amber";
43
+ readonly kind: "colour";
44
+ readonly outright: "--label-amber";
45
+ }, {
46
+ readonly name: "--vk-label-blue";
47
+ readonly kind: "colour";
48
+ readonly outright: "--label-blue";
49
+ }, {
50
+ readonly name: "--vk-neutral";
51
+ readonly kind: "colour";
52
+ readonly outright: "--background-neutral";
53
+ }, {
54
+ readonly name: "--vk-overlay";
55
+ readonly kind: "colour";
56
+ readonly outright: "--surface-overlay";
57
+ }, {
58
+ readonly name: "--vk-overlay-card";
59
+ readonly kind: "colour";
60
+ readonly outright: "--surface-overlay-card";
61
+ }, {
62
+ readonly name: "--vk-overlay-card-pressed";
63
+ readonly kind: "colour";
64
+ readonly outright: "--surface-overlay-card-pressed";
65
+ }, {
66
+ readonly name: "--vk-overlay-pressed";
67
+ readonly kind: "colour";
68
+ readonly outright: "--surface-overlay-pressed";
69
+ }, {
70
+ readonly name: "--vk-shadow-lg";
71
+ readonly kind: "shadow";
72
+ readonly outright: "--shadow-lg";
73
+ }, {
74
+ readonly name: "--vk-shadow-xl";
75
+ readonly kind: "shadow";
76
+ readonly outright: "--shadow-xl";
77
+ }, {
78
+ readonly name: "--vk-border-width";
79
+ readonly kind: "size";
80
+ readonly outright: "--border-width";
81
+ }, {
82
+ readonly name: "--vk-font-size-base";
83
+ readonly kind: "size";
84
+ readonly outright: "--text-base";
85
+ }, {
86
+ readonly name: "--vk-font-size-sm";
87
+ readonly kind: "size";
88
+ readonly outright: "--text-sm";
89
+ }, {
90
+ readonly name: "--vk-font-size-xs";
91
+ readonly kind: "size";
92
+ readonly outright: "--text-xs";
93
+ }, {
94
+ readonly name: "--vk-font-weight-semibold";
95
+ readonly kind: "size";
96
+ readonly outright: "--font-weight-semibold";
97
+ }, {
98
+ readonly name: "--vk-layer-popup";
99
+ readonly kind: "size";
100
+ readonly outright: "--layer-popup";
101
+ }, {
102
+ readonly name: "--vk-line-height-base";
103
+ readonly kind: "size";
104
+ readonly outright: "--text-base--line-height";
105
+ }, {
106
+ readonly name: "--vk-line-height-sm";
107
+ readonly kind: "size";
108
+ readonly outright: "--text-sm--line-height";
109
+ }, {
110
+ readonly name: "--vk-line-height-xs";
111
+ readonly kind: "size";
112
+ readonly outright: "--text-xs--line-height";
113
+ }, {
114
+ readonly name: "--vk-radius-2xl";
115
+ readonly kind: "size";
116
+ readonly outright: "--radius-2xl";
117
+ }, {
118
+ readonly name: "--vk-radius-full";
119
+ readonly kind: "size";
120
+ readonly outright: "--radius-full";
121
+ }, {
122
+ readonly name: "--vk-radius-lg";
123
+ readonly kind: "size";
124
+ readonly outright: "--radius-lg";
125
+ }, {
126
+ readonly name: "--vk-radius-md";
127
+ readonly kind: "size";
128
+ readonly outright: "--radius-md";
129
+ }, {
130
+ readonly name: "--vk-radius-sm";
131
+ readonly kind: "size";
132
+ readonly outright: "--radius-sm";
133
+ }, {
134
+ readonly name: "--vk-radius-xl";
135
+ readonly kind: "size";
136
+ readonly outright: "--radius-xl";
137
+ }, {
138
+ readonly name: "--vk-spacing";
139
+ readonly kind: "size";
140
+ readonly outright: "--spacing";
141
+ }, {
142
+ readonly name: "--vk-hold-delay";
143
+ readonly kind: "motion";
144
+ readonly outright: "--hold-delay";
145
+ }];
146
+ /** The Picker's own machinery: its room, its level's padding, its place under a box, a held row's time and its panel's curve. */
147
+ export declare const PICKER_PRIVATE: readonly ["--picker-"];
@@ -0,0 +1,39 @@
1
+ export const PICKER_TOKENS = [
2
+ { name: "--vk-border", kind: "colour", outright: "--border" },
3
+ { name: "--vk-border-bold", kind: "colour", outright: "--border-bold" },
4
+ { name: "--vk-border-subtle", kind: "colour", outright: "--border-subtle" },
5
+ { name: "--vk-brand", kind: "colour", outright: "--background-brand-bold" },
6
+ { name: "--vk-fg", kind: "colour", outright: "--text" },
7
+ { name: "--vk-fg-disabled", kind: "colour", outright: "--text-disabled" },
8
+ { name: "--vk-fg-inverse", kind: "colour", outright: "--text-inverse" },
9
+ { name: "--vk-fg-on-brand", kind: "colour", outright: "--text-brand-inverse" },
10
+ { name: "--vk-fg-subtle", kind: "colour", outright: "--text-subtle" },
11
+ { name: "--vk-fg-subtlest", kind: "colour", outright: "--text-subtlest" },
12
+ { name: "--vk-label-amber", kind: "colour", outright: "--label-amber" },
13
+ { name: "--vk-label-blue", kind: "colour", outright: "--label-blue" },
14
+ { name: "--vk-neutral", kind: "colour", outright: "--background-neutral" },
15
+ { name: "--vk-overlay", kind: "colour", outright: "--surface-overlay" },
16
+ { name: "--vk-overlay-card", kind: "colour", outright: "--surface-overlay-card" },
17
+ { name: "--vk-overlay-card-pressed", kind: "colour", outright: "--surface-overlay-card-pressed" },
18
+ { name: "--vk-overlay-pressed", kind: "colour", outright: "--surface-overlay-pressed" },
19
+ { name: "--vk-shadow-lg", kind: "shadow", outright: "--shadow-lg" },
20
+ { name: "--vk-shadow-xl", kind: "shadow", outright: "--shadow-xl" },
21
+ { name: "--vk-border-width", kind: "size", outright: "--border-width" },
22
+ { name: "--vk-font-size-base", kind: "size", outright: "--text-base" },
23
+ { name: "--vk-font-size-sm", kind: "size", outright: "--text-sm" },
24
+ { name: "--vk-font-size-xs", kind: "size", outright: "--text-xs" },
25
+ { name: "--vk-font-weight-semibold", kind: "size", outright: "--font-weight-semibold" },
26
+ { name: "--vk-layer-popup", kind: "size", outright: "--layer-popup" },
27
+ { name: "--vk-line-height-base", kind: "size", outright: "--text-base--line-height" },
28
+ { name: "--vk-line-height-sm", kind: "size", outright: "--text-sm--line-height" },
29
+ { name: "--vk-line-height-xs", kind: "size", outright: "--text-xs--line-height" },
30
+ { name: "--vk-radius-2xl", kind: "size", outright: "--radius-2xl" },
31
+ { name: "--vk-radius-full", kind: "size", outright: "--radius-full" },
32
+ { name: "--vk-radius-lg", kind: "size", outright: "--radius-lg" },
33
+ { name: "--vk-radius-md", kind: "size", outright: "--radius-md" },
34
+ { name: "--vk-radius-sm", kind: "size", outright: "--radius-sm" },
35
+ { name: "--vk-radius-xl", kind: "size", outright: "--radius-xl" },
36
+ { name: "--vk-spacing", kind: "size", outright: "--spacing" },
37
+ { name: "--vk-hold-delay", kind: "motion", outright: "--hold-delay" },
38
+ ];
39
+ export const PICKER_PRIVATE = ["--picker-"];