@torpor/ui 1.3.5 → 1.4.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 (129) hide show
  1. package/dist/Accordion/AccordionItem.torp +1 -1
  2. package/dist/Alert/Alert.torp +41 -0
  3. package/dist/Alert/index.d.ts +37 -0
  4. package/dist/Alert/index.js +1 -0
  5. package/dist/Charts/ChartScatter.torp +167 -0
  6. package/dist/Charts/ScatterChart.torp +49 -178
  7. package/dist/Charts/index.d.ts +38 -78
  8. package/dist/Charts/index.js +2 -4
  9. package/dist/ColorPicker/ColorPalette.torp +107 -29
  10. package/dist/ColorPicker/ColorPicker.torp +121 -10
  11. package/dist/ColorPicker/ColorPickerAlpha.torp +58 -0
  12. package/dist/ColorPicker/ColorPickerArea.torp +175 -0
  13. package/dist/ColorPicker/ColorPickerEyedropper.torp +77 -0
  14. package/dist/ColorPicker/ColorPickerHue.torp +59 -0
  15. package/dist/ColorPicker/ColorPickerInput.torp +7 -18
  16. package/dist/ColorPicker/ColorPickerTypes.ts +11 -1
  17. package/dist/ColorPicker/index.d.ts +139 -14
  18. package/dist/ColorPicker/index.js +5 -1
  19. package/dist/ComboBox/ComboBox.torp +40 -5
  20. package/dist/ComboBox/index.d.ts +5 -2
  21. package/dist/ComboBox/index.js +1 -2
  22. package/dist/Contextual/Contextual.torp +25 -77
  23. package/dist/Contextual/ContextualContent.torp +10 -51
  24. package/dist/Contextual/ContextualHover.torp +13 -85
  25. package/dist/Contextual/ContextualTrigger.torp +9 -16
  26. package/dist/Contextual/ContextualTypes.ts +6 -12
  27. package/dist/Contextual/index.d.ts +10 -13
  28. package/dist/DataGrid/DataGrid.torp +21 -3
  29. package/dist/DataGrid/index.d.ts +1 -1
  30. package/dist/DatePicker/DatePicker.torp +6 -4
  31. package/dist/DateRangePicker/DateRangePicker.torp +14 -13
  32. package/dist/DateTimePicker/DateTimePicker.torp +264 -0
  33. package/dist/DateTimePicker/index.d.ts +46 -0
  34. package/dist/DateTimePicker/index.js +1 -0
  35. package/dist/Dialog/Dialog.torp +0 -1
  36. package/dist/Dialog/index.d.ts +0 -1
  37. package/dist/Drawer/Drawer.torp +5 -23
  38. package/dist/Drawer/DrawerContent.torp +1 -0
  39. package/dist/Drawer/DrawerOverlay.torp +9 -16
  40. package/dist/Drawer/DrawerTrigger.torp +9 -24
  41. package/dist/Drawer/DrawerTypes.ts +3 -1
  42. package/dist/Form/CheckBox.torp +10 -18
  43. package/dist/Form/File.torp +10 -18
  44. package/dist/Form/FileDrop.torp +16 -22
  45. package/dist/Form/Input.torp +14 -20
  46. package/dist/Form/Radio.torp +71 -0
  47. package/dist/Form/RadioGroup.torp +221 -0
  48. package/dist/Form/RadioGroupTypes.ts +40 -0
  49. package/dist/Form/Select.torp +10 -18
  50. package/dist/Form/{Toggle.torp → Switch.torp} +17 -21
  51. package/dist/Form/TextArea.torp +10 -18
  52. package/dist/Form/ToggleButton.torp +94 -0
  53. package/dist/Form/ToggleGroup.torp +150 -0
  54. package/dist/Form/ToggleGroupTypes.ts +23 -0
  55. package/dist/Form/index.d.ts +173 -15
  56. package/dist/Form/index.js +6 -2
  57. package/dist/ListBox/ListBox.torp +27 -5
  58. package/dist/ListBox/ListBoxItem.torp +1 -1
  59. package/dist/ListBox/index.d.ts +6 -2
  60. package/dist/MaskedInput/MaskedInput.torp +1 -1
  61. package/dist/Menu/MenuPopoutTrigger.torp +1 -1
  62. package/dist/MenuBar/MenuBar.torp +5 -3
  63. package/dist/MenuBar/MenuBarItemTrigger.torp +2 -2
  64. package/dist/Meter/Meter.torp +126 -0
  65. package/dist/Meter/MeterIndicator.torp +41 -0
  66. package/dist/Meter/MeterTypes.ts +8 -0
  67. package/dist/Meter/index.d.ts +79 -0
  68. package/dist/Meter/index.js +3 -0
  69. package/dist/Modal/Modal.torp +4 -22
  70. package/dist/Modal/ModalOverlay.torp +9 -16
  71. package/dist/NavMenu/NavMenu.torp +5 -3
  72. package/dist/NumberInput/NumberInput.torp +1 -1
  73. package/dist/PinInput/PinInput.torp +220 -0
  74. package/dist/PinInput/index.d.ts +48 -0
  75. package/dist/PinInput/index.js +1 -0
  76. package/dist/Popover/Popover.torp +18 -24
  77. package/dist/Popover/PopoverContent.torp +8 -0
  78. package/dist/Popover/PopoverHover.torp +30 -3
  79. package/dist/Popover/PopoverTypes.ts +2 -0
  80. package/dist/Popover/index.d.ts +8 -1
  81. package/dist/Rating/Rating.torp +1 -1
  82. package/dist/SegmentedControl/SegmentedControl.torp +3 -3
  83. package/dist/SegmentedControl/SegmentedItem.torp +1 -1
  84. package/dist/SelectBox/SelectBox.torp +40 -5
  85. package/dist/SelectBox/index.d.ts +5 -2
  86. package/dist/SelectBox/index.js +1 -2
  87. package/dist/Slider/Slider.torp +1 -1
  88. package/dist/SortableList/SortableList.torp +132 -0
  89. package/dist/SortableList/SortableListItem.torp +117 -0
  90. package/dist/SortableList/SortableListTypes.ts +16 -0
  91. package/dist/SortableList/index.d.ts +81 -0
  92. package/dist/SortableList/index.js +3 -0
  93. package/dist/TabGroup/TabContent.torp +1 -1
  94. package/dist/TabGroup/TabGroup.torp +2 -2
  95. package/dist/TabGroup/TabHeader.torp +1 -1
  96. package/dist/TagInput/TagInput.torp +1 -1
  97. package/dist/TimePicker/TimePicker.torp +1 -1
  98. package/dist/ToolBar/ToolBar.torp +8 -4
  99. package/dist/ToolBar/ToolBarPopoutTrigger.torp +1 -1
  100. package/dist/Tooltip/Tooltip.torp +104 -0
  101. package/dist/Tooltip/TooltipContent.torp +81 -0
  102. package/dist/Tooltip/TooltipTrigger.torp +79 -0
  103. package/dist/Tooltip/TooltipTypes.ts +28 -0
  104. package/dist/Tooltip/index.d.ts +104 -0
  105. package/dist/Tooltip/index.js +4 -0
  106. package/dist/Tree/Tree.torp +1 -1
  107. package/dist/Tree/TreeItem.torp +1 -1
  108. package/dist/VirtualList/VirtualList.torp +149 -0
  109. package/dist/VirtualList/index.d.ts +46 -0
  110. package/dist/VirtualList/index.js +1 -0
  111. package/dist/dnd/index.d.ts +2 -0
  112. package/dist/dnd/index.js +212 -0
  113. package/dist/dnd/index.js.map +1 -0
  114. package/dist/loader/index.d.ts +2 -0
  115. package/dist/{loader-DEeG5vFY.js → loader/index.js} +10 -3
  116. package/dist/loader/index.js.map +1 -0
  117. package/dist/utils/PopoutClickTrigger.torp +1 -0
  118. package/dist/utils/PopoutOverlay.torp +39 -0
  119. package/dist/utils/PopoutTypes.ts +4 -0
  120. package/dist/utils/SubmenuPopoutTrigger.torp +5 -5
  121. package/dist/utils/colorUtils.ts +260 -75
  122. package/dist/utils/formField.ts +4 -3
  123. package/dist/utils/handlePopoutButton.ts +43 -0
  124. package/dist/utils/loader.ts +20 -3
  125. package/package.json +41 -5
  126. package/dist/Charts/GridLines.torp +0 -65
  127. package/dist/Charts/XAxis.torp +0 -69
  128. package/dist/Charts/YAxis.torp +0 -49
  129. package/dist/loader-DEeG5vFY.js.map +0 -1
@@ -1,103 +1,288 @@
1
1
  /** Converts between color representations used by the picker components */
2
2
 
3
+ /** A named color offered by the palette */
4
+ export interface ColorOption {
5
+ /** The color as "#rrggbb" (or "#rrggbbaa") */
6
+ value: string;
7
+ /** An accessible name, instead of reading the hex out character by character */
8
+ name: string;
9
+ }
10
+
11
+ /** A palette entry: either a raw hex string or a named color */
12
+ export type Color = string | ColorOption;
13
+
3
14
  export interface Rgb {
4
15
  r: number;
5
16
  g: number;
6
17
  b: number;
7
18
  }
8
19
 
9
- /** Parses "#rgb", "#rrggbb" or "rrggbb"; returns undefined when invalid */
20
+ export interface Rgba extends Rgb {
21
+ /** Alpha in [0..1] */
22
+ a: number;
23
+ }
24
+
25
+ /** Hue in [0..360], saturation and value in [0..1] */
26
+ export interface Hsv {
27
+ h: number;
28
+ s: number;
29
+ v: number;
30
+ }
31
+
32
+ /** The hex value of a palette entry */
33
+ export function colorValue(color: Color): string {
34
+ return typeof color === "string" ? color : color.value;
35
+ }
36
+
37
+ /** The accessible name of a palette entry */
38
+ export function colorName(color: Color): string {
39
+ return typeof color === "string" ? color : color.name;
40
+ }
41
+
42
+ function clamp(value: number, min: number, max: number): number {
43
+ return Math.min(max, Math.max(min, value));
44
+ }
45
+
46
+ /**
47
+ * Parses "#rgb", "#rgba", "#rrggbb", "#rrggbbaa" or the same without the
48
+ * leading "#". Returns a lowercase hex string, with an alpha channel only
49
+ * when it isn't fully opaque, or undefined when invalid.
50
+ */
10
51
  export function parseHex(text: string | undefined | null): string | undefined {
11
52
  if (!text) return undefined;
12
53
  let value = text.trim().replace(/^#/, "");
13
- if (value.length === 3) {
54
+ if (!/^[0-9a-fA-F]+$/.test(value)) return undefined;
55
+ if (value.length === 3 || value.length === 4) {
14
56
  value = value
15
57
  .split("")
16
58
  .map((c) => c + c)
17
59
  .join("");
18
60
  }
19
- if (!/^[0-9a-fA-F]{6}$/.test(value)) return undefined;
20
- return "#" + value.toLowerCase();
61
+ if (value.length !== 6 && value.length !== 8) return undefined;
62
+ value = value.toLowerCase();
63
+ if (value.length === 8 && value.endsWith("ff")) {
64
+ value = value.slice(0, 6);
65
+ }
66
+ return "#" + value;
67
+ }
68
+
69
+ function parseRgbComponent(text: string): number | undefined {
70
+ if (text.endsWith("%")) {
71
+ const pct = Number(text.slice(0, -1));
72
+ if (!Number.isFinite(pct)) return undefined;
73
+ return clamp(Math.round((pct / 100) * 255), 0, 255);
74
+ }
75
+ const n = Number(text);
76
+ if (!Number.isFinite(n)) return undefined;
77
+ return clamp(Math.round(n), 0, 255);
78
+ }
79
+
80
+ function parseAlphaComponent(text: string | undefined): number {
81
+ if (text === undefined) return 1;
82
+ if (text.endsWith("%")) {
83
+ const pct = Number(text.slice(0, -1));
84
+ return Number.isFinite(pct) ? clamp(pct / 100, 0, 1) : 1;
85
+ }
86
+ const n = Number(text);
87
+ return Number.isFinite(n) ? clamp(n, 0, 1) : 1;
21
88
  }
22
89
 
23
- export function hexToRgb(hex: string): Rgb {
90
+ function hslToRgb(h: number, s: number, l: number): Rgb {
91
+ const hue = ((h % 360) + 360) % 360;
92
+ const sat = clamp(s, 0, 1);
93
+ const light = clamp(l, 0, 1);
94
+ const c = (1 - Math.abs(2 * light - 1)) * sat;
95
+ const x = c * (1 - Math.abs(((hue / 60) % 2) - 1));
96
+ const m = light - c / 2;
97
+ let r = 0;
98
+ let g = 0;
99
+ let b = 0;
100
+ if (hue < 60) [r, g, b] = [c, x, 0];
101
+ else if (hue < 120) [r, g, b] = [x, c, 0];
102
+ else if (hue < 180) [r, g, b] = [0, c, x];
103
+ else if (hue < 240) [r, g, b] = [0, x, c];
104
+ else if (hue < 300) [r, g, b] = [x, 0, c];
105
+ else [r, g, b] = [c, 0, x];
106
+ return {
107
+ r: Math.round((r + m) * 255),
108
+ g: Math.round((g + m) * 255),
109
+ b: Math.round((b + m) * 255),
110
+ };
111
+ }
112
+
113
+ /**
114
+ * Parses a CSS color: a hex string, `rgb()` / `rgba()`, or `hsl()` /
115
+ * `hsla()`. Returns a normalized hex string with an alpha channel when the
116
+ * color isn't fully opaque.
117
+ */
118
+ export function parseColor(text: string | undefined | null): string | undefined {
119
+ if (!text) return undefined;
120
+ const value = text.trim().toLowerCase();
121
+ const hex = parseHex(value);
122
+ if (hex) return hex;
123
+
124
+ const rgbMatch = value.match(/^rgba?\(([^)]+)\)$/);
125
+ if (rgbMatch) {
126
+ const parts = rgbMatch[1].split(/[\s,/]+/).filter(Boolean);
127
+ if (parts.length < 3) return undefined;
128
+ const [r, g, b] = parts.slice(0, 3).map(parseRgbComponent);
129
+ if (r === undefined || g === undefined || b === undefined) return undefined;
130
+ return rgbaToHex({ r, g, b, a: parseAlphaComponent(parts[3]) });
131
+ }
132
+
133
+ const hslMatch = value.match(/^hsla?\(([^)]+)\)$/);
134
+ if (hslMatch) {
135
+ const parts = hslMatch[1].split(/[\s,/]+/).filter(Boolean);
136
+ if (parts.length < 3) return undefined;
137
+ const h = Number(parts[0].replace(/deg$/, ""));
138
+ const s = Number(parts[1].replace(/%$/, ""));
139
+ const l = Number(parts[2].replace(/%$/, ""));
140
+ if (!Number.isFinite(h) || !Number.isFinite(s) || !Number.isFinite(l)) return undefined;
141
+ const rgb = hslToRgb(h, s / 100, l / 100);
142
+ return rgbaToHex({ ...rgb, a: parseAlphaComponent(parts[3]) });
143
+ }
144
+
145
+ return undefined;
146
+ }
147
+
148
+ /** Splits a hex color into its channels; invalid values parse as black */
149
+ export function hexToRgba(hex: string): Rgba {
24
150
  const value = parseHex(hex) ?? "#000000";
25
151
  return {
26
152
  r: parseInt(value.slice(1, 3), 16),
27
153
  g: parseInt(value.slice(3, 5), 16),
28
154
  b: parseInt(value.slice(5, 7), 16),
155
+ a: value.length === 9 ? parseInt(value.slice(7, 9), 16) / 255 : 1,
29
156
  };
30
157
  }
31
158
 
159
+ /** The alpha of a color in [0..1] */
160
+ export function alphaOf(hex: string): number {
161
+ return hexToRgba(hex).a;
162
+ }
163
+
164
+ /** Sets a color's alpha, dropping the channel when it becomes fully opaque */
165
+ export function withAlpha(hex: string, alpha: number): string {
166
+ const { r, g, b } = hexToRgba(hex);
167
+ return rgbaToHex({ r, g, b, a: alpha });
168
+ }
169
+
32
170
  function toHexPart(n: number): string {
33
- const clamped = Math.min(255, Math.max(0, Math.round(n)));
34
- return clamped.toString(16).padStart(2, "0");
35
- }
36
-
37
- export function rgbToHex({ r, g, b }: Rgb): string {
38
- return `#${toHexPart(r)}${toHexPart(g)}${toHexPart(b)}`;
39
- }
40
-
41
- /** Blends two colors; amount 0 returns a, 1 returns b */
42
- export function mix(a: string, b: string, amount: number): string {
43
- const ca = hexToRgb(a);
44
- const cb = hexToRgb(b);
45
- const t = Math.min(1, Math.max(0, amount));
46
- return rgbToHex({
47
- r: ca.r + (cb.r - ca.r) * t,
48
- g: ca.g + (cb.g - ca.g) * t,
49
- b: ca.b + (cb.b - ca.b) * t,
50
- });
51
- }
52
-
53
- /** Perceptual lightness in [0..1], for choosing readable text on swatches */
54
- export function luminance(hex: string): number {
55
- const { r, g, b } = hexToRgb(hex);
56
- return (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255;
57
- }
58
-
59
- /** A default palette, roughly ordered light to dark */
60
- export const defaultPalette: string[] = [
61
- "#FFFFFF",
62
- "#F5F5F5",
63
- "#D9D9D9",
64
- "#BFBFBF",
65
- "#8C8C8C",
66
- "#595959",
67
- "#404040",
68
- "#262626",
69
- "#0F0F0F",
70
- "#000000",
71
- "#FFE4E1",
72
- "#FFC0CB",
73
- "#FF7F7F",
74
- "#FF4040",
75
- "#E60000",
76
- "#A61C00",
77
- "#FFEDCC",
78
- "#FFD59E",
79
- "#FFAA33",
80
- "#E67E00",
81
- "#B35900",
82
- "#FFF9C4",
83
- "#FFF176",
84
- "#FFEB3B",
85
- "#FBC02D",
86
- "#F9A825",
87
- "#827717",
88
- "#E8F5E9",
89
- "#A5D6A7",
90
- "#66BB6A",
91
- "#2E7D32",
92
- "#1B5E20",
93
- "#0D47A1",
94
- "#1565C0",
95
- "#1E88E5",
96
- "#42A5F5",
97
- "#90CAF9",
98
- "#E1BEE7",
99
- "#CE93D8",
100
- "#AB47BC",
101
- "#8E24AA",
102
- "#4A148C",
171
+ return clamp(Math.round(n), 0, 255).toString(16).padStart(2, "0");
172
+ }
173
+
174
+ /** Formats channels as a hex color, with alpha only when not fully opaque */
175
+ export function rgbToHex({ r, g, b, a = 1 }: Rgba | (Rgb & { a?: number })): string {
176
+ const rgb = `#${toHexPart(r)}${toHexPart(g)}${toHexPart(b)}`;
177
+ const alpha = Math.round(clamp(a, 0, 1) * 255);
178
+ return alpha === 255 ? rgb : `${rgb}${toHexPart(alpha)}`;
179
+ }
180
+
181
+ export function rgbaToHex(rgba: Rgba): string {
182
+ return rgbToHex(rgba);
183
+ }
184
+
185
+ /** Converts RGB to hue/saturation/value */
186
+ export function rgbToHsv({ r, g, b }: Rgb): Hsv {
187
+ const rn = r / 255;
188
+ const gn = g / 255;
189
+ const bn = b / 255;
190
+ const max = Math.max(rn, gn, bn);
191
+ const min = Math.min(rn, gn, bn);
192
+ const delta = max - min;
193
+ let h = 0;
194
+ if (delta !== 0) {
195
+ if (max === rn) h = ((gn - bn) / delta) % 6;
196
+ else if (max === gn) h = (bn - rn) / delta + 2;
197
+ else h = (rn - gn) / delta + 4;
198
+ h *= 60;
199
+ if (h < 0) h += 360;
200
+ }
201
+ return { h, s: max === 0 ? 0 : delta / max, v: max };
202
+ }
203
+
204
+ /** Converts hue/saturation/value to RGB */
205
+ export function hsvToRgb({ h, s, v }: Hsv): Rgb {
206
+ const hue = ((h % 360) + 360) % 360;
207
+ const sat = clamp(s, 0, 1);
208
+ const val = clamp(v, 0, 1);
209
+ const c = val * sat;
210
+ const x = c * (1 - Math.abs(((hue / 60) % 2) - 1));
211
+ const m = val - c;
212
+ let r = 0;
213
+ let g = 0;
214
+ let b = 0;
215
+ if (hue < 60) [r, g, b] = [c, x, 0];
216
+ else if (hue < 120) [r, g, b] = [x, c, 0];
217
+ else if (hue < 180) [r, g, b] = [0, c, x];
218
+ else if (hue < 240) [r, g, b] = [0, x, c];
219
+ else if (hue < 300) [r, g, b] = [x, 0, c];
220
+ else [r, g, b] = [c, 0, x];
221
+ return {
222
+ r: Math.round((r + m) * 255),
223
+ g: Math.round((g + m) * 255),
224
+ b: Math.round((b + m) * 255),
225
+ };
226
+ }
227
+
228
+ /** Converts a hex color to hue/saturation/value */
229
+ export function hexToHsv(hex: string): Hsv {
230
+ return rgbToHsv(hexToRgba(hex));
231
+ }
232
+
233
+ /** Converts hue/saturation/value (and alpha) to a normalized hex color */
234
+ export function hsvToHex(hsv: Hsv, alpha = 1): string {
235
+ return rgbaToHex({ ...hsvToRgb(hsv), a: alpha });
236
+ }
237
+
238
+ /** A default palette of 6-column rows, each ordered light to dark */
239
+ export const defaultPalette: Color[] = [
240
+ { value: "#ffffff", name: "White" },
241
+ { value: "#d9d9d9", name: "Light gray" },
242
+ { value: "#a6a6a6", name: "Gray" },
243
+ { value: "#737373", name: "Dark gray" },
244
+ { value: "#404040", name: "Charcoal" },
245
+ { value: "#000000", name: "Black" },
246
+
247
+ { value: "#ffe4e1", name: "Pale red" },
248
+ { value: "#ffb3b3", name: "Light red" },
249
+ { value: "#ff8080", name: "Red" },
250
+ { value: "#ff4d4d", name: "Bright red" },
251
+ { value: "#cc0000", name: "Dark red" },
252
+ { value: "#800000", name: "Maroon" },
253
+
254
+ { value: "#ffedcc", name: "Pale orange" },
255
+ { value: "#ffd59e", name: "Light orange" },
256
+ { value: "#ffb366", name: "Orange" },
257
+ { value: "#ff9900", name: "Amber" },
258
+ { value: "#cc7a00", name: "Dark orange" },
259
+ { value: "#804d00", name: "Brown" },
260
+
261
+ { value: "#fff9c4", name: "Pale yellow" },
262
+ { value: "#fff176", name: "Light yellow" },
263
+ { value: "#ffe94d", name: "Yellow" },
264
+ { value: "#ffd600", name: "Gold" },
265
+ { value: "#ccab00", name: "Dark yellow" },
266
+ { value: "#665900", name: "Olive" },
267
+
268
+ { value: "#e8f5e9", name: "Pale green" },
269
+ { value: "#a5d6a7", name: "Light green" },
270
+ { value: "#66bb6a", name: "Green" },
271
+ { value: "#2e7d32", name: "Dark green" },
272
+ { value: "#1b5e20", name: "Deep green" },
273
+ { value: "#0d3311", name: "Forest" },
274
+
275
+ { value: "#e3f2fd", name: "Pale blue" },
276
+ { value: "#90caf9", name: "Light blue" },
277
+ { value: "#42a5f5", name: "Blue" },
278
+ { value: "#1e88e5", name: "Bright blue" },
279
+ { value: "#1565c0", name: "Dark blue" },
280
+ { value: "#0d47a1", name: "Navy" },
281
+
282
+ { value: "#f3e5f5", name: "Pale purple" },
283
+ { value: "#ce93d8", name: "Light purple" },
284
+ { value: "#ab47bc", name: "Purple" },
285
+ { value: "#8e24aa", name: "Dark purple" },
286
+ { value: "#6a1b9a", name: "Deep purple" },
287
+ { value: "#4a148c", name: "Violet" },
103
288
  ];
@@ -25,22 +25,23 @@ export interface FormField {
25
25
  *
26
26
  * ```ts
27
27
  * const form = createFormField(
28
- * $props?.name,
28
+ * () => $props?.name,
29
29
  * $context[FormContextName] as FormContext | undefined,
30
30
  * $context[FieldContextName] as FieldContext | undefined,
31
31
  * );
32
32
  * ```
33
33
  */
34
34
  export default function createFormField(
35
- name: string | undefined,
35
+ name: string | undefined | (() => string | undefined),
36
36
  formContext: FormContext | undefined,
37
37
  fieldContext: FieldContext | undefined,
38
38
  ): FormField {
39
39
  let blurred = false;
40
+ const resolveName = typeof name === "function" ? name : () => name;
40
41
 
41
42
  return {
42
43
  get name() {
43
- return name ?? fieldContext?.name;
44
+ return resolveName() ?? fieldContext?.name;
44
45
  },
45
46
  get inField(): boolean {
46
47
  return fieldContext !== undefined;
@@ -0,0 +1,43 @@
1
+ /** Minimal state shared by popout roots */
2
+ interface PopoutStateLike {
3
+ visible: boolean;
4
+ }
5
+
6
+ /**
7
+ * The common button-result handling for popouts: confirm/cancel buttons
8
+ * resolve to true/false (or the value they supply), other buttons supply
9
+ * their value, and every button hides the popout.
10
+ *
11
+ * Components keep their own `visible` state so that bindings and callbacks
12
+ * stay on the component's reactive object.
13
+ */
14
+ export function createPopoutButtonHandler(state: PopoutStateLike): {
15
+ handleButton: (type: "confirm" | "cancel" | undefined, value?: any) => void;
16
+ getResult: () => any;
17
+ } {
18
+ let result: any;
19
+
20
+ function handleButton(type: "confirm" | "cancel" | undefined, value?: any) {
21
+ switch (type) {
22
+ case "confirm": {
23
+ result = value ?? true;
24
+ break;
25
+ }
26
+ case "cancel": {
27
+ result = value ?? false;
28
+ break;
29
+ }
30
+ default: {
31
+ result = value;
32
+ break;
33
+ }
34
+ }
35
+
36
+ state.visible = false;
37
+ }
38
+
39
+ return {
40
+ handleButton,
41
+ getResult: () => result,
42
+ };
43
+ }
@@ -91,12 +91,29 @@ export interface ItemLoaderState<T = any> {
91
91
  export function createItemLoader<T = any, TRequest extends LoadRequest = LoadRequest>(
92
92
  options: ItemLoaderOptions<T, TRequest>,
93
93
  ): ItemLoaderState<T> {
94
+ // The in-flight fetch's controller: a re-run (search text changed, item
95
+ // expanded) aborts it, so loaders that take the signal can cancel the
96
+ // wire request. The $async generation guard discards stale results
97
+ // application-side either way.
98
+ let abort: AbortController | null = null;
99
+
94
100
  return $watch({
95
101
  get result(): LoadResult<T> | undefined {
96
102
  return $async(() => {
97
- const promise = Promise.resolve(options.load(options.getRequest())).then(
98
- normalizeLoadResult,
99
- );
103
+ abort?.abort();
104
+ const controller = new AbortController();
105
+ abort = controller;
106
+ const promise = Promise.resolve(options.load(options.getRequest(), controller.signal))
107
+ .then(normalizeLoadResult)
108
+ .catch((error) => {
109
+ // Our own abort is not an error — the superseding fetch
110
+ // owns the UI, so this one never settles instead of
111
+ // rejecting into the await boundary
112
+ if (controller.signal.aborted) {
113
+ return new Promise<LoadResult<T>>(() => {});
114
+ }
115
+ throw error;
116
+ });
100
117
  // Report successful loads to the consumer; failures surface
101
118
  // through the component's error boundary, not this chain
102
119
  promise.then(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torpor/ui",
3
- "version": "1.3.5",
3
+ "version": "1.4.0",
4
4
  "description": "Accessible, unstyled components for use in your Torpor front-end",
5
5
  "type": "module",
6
6
  "torpor": true,
@@ -9,6 +9,10 @@
9
9
  "types": "./dist/Accordion/index.d.ts",
10
10
  "import": "./dist/Accordion/index.js"
11
11
  },
12
+ "./Alert": {
13
+ "types": "./dist/Alert/index.d.ts",
14
+ "import": "./dist/Alert/index.js"
15
+ },
12
16
  "./Breadcrumb": {
13
17
  "types": "./dist/Breadcrumb/index.d.ts",
14
18
  "import": "./dist/Breadcrumb/index.js"
@@ -53,10 +57,18 @@
53
57
  "types": "./dist/DateRangePicker/index.d.ts",
54
58
  "import": "./dist/DateRangePicker/index.js"
55
59
  },
60
+ "./DateTimePicker": {
61
+ "types": "./dist/DateTimePicker/index.d.ts",
62
+ "import": "./dist/DateTimePicker/index.js"
63
+ },
56
64
  "./Dialog": {
57
65
  "types": "./dist/Dialog/index.d.ts",
58
66
  "import": "./dist/Dialog/index.js"
59
67
  },
68
+ "./dnd": {
69
+ "types": "./dist/dnd/index.d.ts",
70
+ "import": "./dist/dnd/index.js"
71
+ },
60
72
  "./Disclosure": {
61
73
  "types": "./dist/Disclosure/index.d.ts",
62
74
  "import": "./dist/Disclosure/index.js"
@@ -93,6 +105,10 @@
93
105
  "types": "./dist/NumberInput/index.d.ts",
94
106
  "import": "./dist/NumberInput/index.js"
95
107
  },
108
+ "./Meter": {
109
+ "types": "./dist/Meter/index.d.ts",
110
+ "import": "./dist/Meter/index.js"
111
+ },
96
112
  "./NavMenu": {
97
113
  "types": "./dist/NavMenu/index.d.ts",
98
114
  "import": "./dist/NavMenu/index.js"
@@ -109,6 +125,10 @@
109
125
  "types": "./dist/Pagination/index.d.ts",
110
126
  "import": "./dist/Pagination/index.js"
111
127
  },
128
+ "./PinInput": {
129
+ "types": "./dist/PinInput/index.d.ts",
130
+ "import": "./dist/PinInput/index.js"
131
+ },
112
132
  "./Progress": {
113
133
  "types": "./dist/Progress/index.d.ts",
114
134
  "import": "./dist/Progress/index.js"
@@ -133,6 +153,10 @@
133
153
  "types": "./dist/Slider/index.d.ts",
134
154
  "import": "./dist/Slider/index.js"
135
155
  },
156
+ "./SortableList": {
157
+ "types": "./dist/SortableList/index.d.ts",
158
+ "import": "./dist/SortableList/index.js"
159
+ },
136
160
  "./Splitter": {
137
161
  "types": "./dist/Splitter/index.d.ts",
138
162
  "import": "./dist/Splitter/index.js"
@@ -157,14 +181,26 @@
157
181
  "types": "./dist/ToolBar/index.d.ts",
158
182
  "import": "./dist/ToolBar/index.js"
159
183
  },
184
+ "./Tooltip": {
185
+ "types": "./dist/Tooltip/index.d.ts",
186
+ "import": "./dist/Tooltip/index.js"
187
+ },
160
188
  "./TimePicker": {
161
189
  "types": "./dist/TimePicker/index.d.ts",
162
190
  "import": "./dist/TimePicker/index.js"
163
191
  },
192
+ "./VirtualList": {
193
+ "types": "./dist/VirtualList/index.d.ts",
194
+ "import": "./dist/VirtualList/index.js"
195
+ },
164
196
  "./icons": {
165
197
  "types": "./dist/icons/index.d.ts",
166
198
  "import": "./dist/icons/index.js"
167
199
  },
200
+ "./loader": {
201
+ "types": "./dist/loader/index.d.ts",
202
+ "import": "./dist/loader/index.js"
203
+ },
168
204
  "./motion": {
169
205
  "types": "./dist/motion/index.d.ts",
170
206
  "import": "./dist/motion/index.js"
@@ -181,15 +217,15 @@
181
217
  "author": "",
182
218
  "license": "ISC",
183
219
  "dependencies": {
184
- "@torpor/unplugin": "^1.2.10",
185
- "@torpor/view": "^1.3.0"
220
+ "@torpor/unplugin": "^1.2.12",
221
+ "@torpor/view": "^1.3.2"
186
222
  },
187
223
  "devDependencies": {
188
224
  "@testing-library/dom": "^10.4.2",
189
225
  "@testing-library/jest-dom": "^7.0.1",
190
226
  "@testing-library/user-event": "^14.6.8",
191
- "@torpor/check": "^1.0.15",
192
- "@torpor/prettier": "^1.0.15",
227
+ "@torpor/check": "^1.0.17",
228
+ "@torpor/prettier": "^1.0.17",
193
229
  "@types/jsdom": "^30.0.0",
194
230
  "@types/node": "^26.6.5",
195
231
  "@typescript/native-preview": "7.0.0-dev.20260707.2",
@@ -1,65 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
-
3
- interface GridLinesProps {
4
- /** An ID for the root element */
5
- id?: string;
6
- /** Classes for the root element */
7
- class?: ClassValue;
8
- /** Styles for the root element */
9
- style?: StyleValue;
10
- showHLines?: boolean;
11
- showVLines?: boolean;
12
- width: number;
13
- labels: string[];
14
- xStepValue: number;
15
- xStepLabels: number[];
16
- yStepValue: number;
17
- yStepLabels: number[];
18
- itemWidth: number;
19
- valueHeight: number;
20
- chartLeft: number;
21
- chartBottom: number;
22
- type: string;
23
- }
24
-
25
- export default function GridLines($props: GridLinesProps) {
26
- @render {
27
- <svg>
28
- @if ($props.showHLines && $props.yStepLabels) {
29
- @for (let [i, label] of $props.yStepLabels!.entries()) {
30
- <line
31
- x1={$props.chartLeft ?? 0}
32
- y1={$props.chartBottom - i * $props.yStepValue * $props.valueHeight}
33
- x2={$props.width ?? 0}
34
- y2={$props.chartBottom - i * $props.yStepValue * $props.valueHeight}
35
- stroke="currentcolor"
36
- />
37
- }
38
- }
39
-
40
- @if ($props.showVLines) {
41
- @if ($props.xStepLabels.length && $props.xStepValue) {
42
- @for (let [i, label] of $props.xStepLabels.entries()) {
43
- <line
44
- x1={$props.chartLeft + i * $props.xStepValue * $props.itemWidth}
45
- y1={$props.chartBottom}
46
- x2={$props.chartLeft + i * $props.xStepValue * $props.itemWidth}
47
- y2={0}
48
- stroke="currentcolor"
49
- />
50
- }
51
- } else {
52
- @for (let [i, label] of $props.labels.entries()) {
53
- <line
54
- x1={$props.chartLeft + i * $props.itemWidth + ($props.type === "bar" ? 0 : $props.itemWidth / 2)}
55
- y1={$props.chartBottom}
56
- x2={$props.chartLeft + i * $props.itemWidth + ($props.type === "bar" ? 0 : $props.itemWidth / 2)}
57
- y2={0}
58
- stroke="currentcolor"
59
- />
60
- }
61
- }
62
- }
63
- </svg>
64
- }
65
- }