@sybilion/uilib 1.4.36 → 1.4.40

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 (126) hide show
  1. package/README.md +2 -0
  2. package/dist/agent-glossary/workspace.generated.ts +1 -0
  3. package/dist/agent-glossary/workspace.index.md +1 -0
  4. package/dist/agent-glossary/workspace.md +1 -0
  5. package/dist/esm/src/components/ui/AppHeader/AppHeader.styl.js +1 -1
  6. package/dist/esm/src/components/ui/Banner/Banner.styl.js +1 -1
  7. package/dist/esm/src/components/ui/Card/Card.styl.js +1 -1
  8. package/dist/esm/src/components/ui/Chart/Chart.js +1 -2
  9. package/dist/esm/src/components/ui/Chip/Chip.js +9 -2
  10. package/dist/esm/src/components/ui/Chip/Chip.styl.js +2 -2
  11. package/dist/esm/src/components/ui/Dialog/Dialog.styl.js +1 -1
  12. package/dist/esm/src/components/ui/Drawer/Drawer.styl.js +1 -1
  13. package/dist/esm/src/components/ui/DropdownMenu/DropdownMenu.styl.js +1 -1
  14. package/dist/esm/src/components/ui/Input/Input.styl.js +1 -1
  15. package/dist/esm/src/components/ui/Logo/Logo.styl.js +1 -1
  16. package/dist/esm/src/components/ui/MobileAdaptiveSelector/MobileAdaptiveSelector.styl.js +1 -1
  17. package/dist/esm/src/components/ui/Page/PageHeader/PageHeader.styl.js +1 -1
  18. package/dist/esm/src/components/ui/Page/PageTabs/PageTabs.styl.js +1 -1
  19. package/dist/esm/src/components/ui/Select/Select.js +314 -6
  20. package/dist/esm/src/components/ui/Select/Select.styl.js +2 -2
  21. package/dist/esm/src/components/ui/Sheet/Sheet.styl.js +1 -1
  22. package/dist/esm/src/components/ui/SupplyChainMap/SupplyChainMap.js +384 -0
  23. package/dist/esm/src/components/ui/SupplyChainMap/SupplyChainMap.styl.js +7 -0
  24. package/dist/esm/src/components/ui/SupplyChainMap/map-colors.js +44 -0
  25. package/dist/esm/src/components/ui/SupplyChainMap/map-disclosure.js +142 -0
  26. package/dist/esm/src/components/ui/SupplyChainMap/map-labels.js +55 -0
  27. package/dist/esm/src/components/ui/SupplyChainMap/map-projection.js +186 -0
  28. package/dist/esm/src/components/ui/SupplyChainMap/supply-chain-map-clusters.js +96 -0
  29. package/dist/esm/src/components/ui/SupplyChainMap/supply-chain-map-draw.js +66 -0
  30. package/dist/esm/src/components/ui/SupplyChainMap/supply-chain-map-scene.js +59 -0
  31. package/dist/esm/src/components/ui/SupplyChainMap/supply-chain-map-types.js +10 -0
  32. package/dist/esm/src/components/ui/SupplyChainMap/use-map-base-renderer.js +122 -0
  33. package/dist/esm/src/components/ui/Table/Table.styl.js +1 -1
  34. package/dist/esm/src/components/ui/Tabs/Tabs.styl.js +1 -1
  35. package/dist/esm/src/components/ui/Tooltip/Tooltip.styl.js +1 -1
  36. package/dist/esm/src/components/widgets/DriverCard/DriverPerformanceChart.js +1 -2
  37. package/dist/esm/src/components/widgets/SybilionAppHeader/SybilionAppHeader.styl.js +1 -1
  38. package/dist/esm/src/index.js +2 -0
  39. package/dist/esm/types/src/components/ui/Chip/Chip.d.ts +1 -1
  40. package/dist/esm/types/src/components/ui/Chip/Chip.types.d.ts +2 -0
  41. package/dist/esm/types/src/components/ui/Chip/index.d.ts +1 -1
  42. package/dist/esm/types/src/components/ui/Select/Select.d.ts +3 -3
  43. package/dist/esm/types/src/components/ui/Select/Select.types.d.ts +3 -1
  44. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.contract.test.d.ts +1 -0
  45. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.d.ts +2 -0
  46. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.example.d.ts +1 -0
  47. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.render.worker.d.ts +15 -0
  48. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.types.d.ts +10 -0
  49. package/dist/esm/types/src/components/ui/SupplyChainMap/index.d.ts +3 -0
  50. package/dist/esm/types/src/components/ui/SupplyChainMap/map-colors.d.ts +43 -0
  51. package/dist/esm/types/src/components/ui/SupplyChainMap/map-disclosure.d.ts +35 -0
  52. package/dist/esm/types/src/components/ui/SupplyChainMap/map-disclosure.test.d.ts +1 -0
  53. package/dist/esm/types/src/components/ui/SupplyChainMap/map-labels.d.ts +14 -0
  54. package/dist/esm/types/src/components/ui/SupplyChainMap/map-labels.test.d.ts +1 -0
  55. package/dist/esm/types/src/components/ui/SupplyChainMap/map-projection.d.ts +83 -0
  56. package/dist/esm/types/src/components/ui/SupplyChainMap/map-projection.test.d.ts +1 -0
  57. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-clusters.d.ts +25 -0
  58. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-clusters.test.d.ts +1 -0
  59. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-draw.d.ts +30 -0
  60. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-scene.d.ts +28 -0
  61. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-scene.test.d.ts +1 -0
  62. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-types.d.ts +31 -0
  63. package/dist/esm/types/src/components/ui/SupplyChainMap/use-map-base-renderer.d.ts +14 -0
  64. package/dist/esm/types/src/docs/pages/BannerPage.d.ts +1 -0
  65. package/dist/esm/types/src/docs/pages/SupplyChainMapPage.d.ts +1 -0
  66. package/dist/esm/types/src/index.d.ts +1 -0
  67. package/dist/esm/types/src/lib/logger.d.ts +1 -0
  68. package/package.json +7 -1
  69. package/src/components/ui/AppHeader/AppHeader.styl +2 -2
  70. package/src/components/ui/Banner/Banner.styl +1 -1
  71. package/src/components/ui/Card/Card.styl +3 -1
  72. package/src/components/ui/Chip/AGENT.md +1 -1
  73. package/src/components/ui/Chip/Chip.styl +66 -6
  74. package/src/components/ui/Chip/Chip.styl.d.ts +4 -0
  75. package/src/components/ui/Chip/Chip.tsx +15 -1
  76. package/src/components/ui/Chip/Chip.types.ts +3 -0
  77. package/src/components/ui/Chip/index.ts +1 -1
  78. package/src/components/ui/Dialog/Dialog.styl +2 -2
  79. package/src/components/ui/Drawer/Drawer.styl +2 -2
  80. package/src/components/ui/DropdownMenu/DropdownMenu.styl +2 -2
  81. package/src/components/ui/Input/Input.styl +9 -13
  82. package/src/components/ui/Logo/Logo.styl +1 -1
  83. package/src/components/ui/MobileAdaptiveSelector/MobileAdaptiveSelector.styl +1 -1
  84. package/src/components/ui/Page/PageHeader/PageHeader.styl +1 -1
  85. package/src/components/ui/Page/PageTabs/PageTabs.styl +3 -0
  86. package/src/components/ui/Select/AGENT.md +3 -1
  87. package/src/components/ui/Select/Select.styl +38 -6
  88. package/src/components/ui/Select/Select.styl.d.ts +28 -25
  89. package/src/components/ui/Select/Select.tsx +512 -5
  90. package/src/components/ui/Select/Select.types.ts +3 -1
  91. package/src/components/ui/Sheet/Sheet.styl +2 -2
  92. package/src/components/ui/SupplyChainMap/AGENT.md +45 -0
  93. package/src/components/ui/SupplyChainMap/SupplyChainMap.contract.test.ts +45 -0
  94. package/src/components/ui/SupplyChainMap/SupplyChainMap.example.tsx +176 -0
  95. package/src/components/ui/SupplyChainMap/SupplyChainMap.render.worker.ts +63 -0
  96. package/src/components/ui/SupplyChainMap/SupplyChainMap.styl +221 -0
  97. package/src/components/ui/SupplyChainMap/SupplyChainMap.styl.d.ts +25 -0
  98. package/src/components/ui/SupplyChainMap/SupplyChainMap.tsx +720 -0
  99. package/src/components/ui/SupplyChainMap/SupplyChainMap.types.ts +15 -0
  100. package/src/components/ui/SupplyChainMap/index.ts +11 -0
  101. package/src/components/ui/SupplyChainMap/map-colors.ts +66 -0
  102. package/src/components/ui/SupplyChainMap/map-disclosure.test.ts +237 -0
  103. package/src/components/ui/SupplyChainMap/map-disclosure.ts +226 -0
  104. package/src/components/ui/SupplyChainMap/map-labels.test.ts +102 -0
  105. package/src/components/ui/SupplyChainMap/map-labels.ts +85 -0
  106. package/src/components/ui/SupplyChainMap/map-projection.test.ts +172 -0
  107. package/src/components/ui/SupplyChainMap/map-projection.ts +281 -0
  108. package/src/components/ui/SupplyChainMap/supply-chain-map-clusters.test.ts +182 -0
  109. package/src/components/ui/SupplyChainMap/supply-chain-map-clusters.ts +127 -0
  110. package/src/components/ui/SupplyChainMap/supply-chain-map-draw.ts +114 -0
  111. package/src/components/ui/SupplyChainMap/supply-chain-map-scene.test.ts +196 -0
  112. package/src/components/ui/SupplyChainMap/supply-chain-map-scene.ts +118 -0
  113. package/src/components/ui/SupplyChainMap/supply-chain-map-types.ts +45 -0
  114. package/src/components/ui/SupplyChainMap/use-map-base-renderer.ts +145 -0
  115. package/src/components/ui/Table/Table.styl +4 -3
  116. package/src/components/ui/Tabs/Tabs.styl +4 -0
  117. package/src/components/ui/Tooltip/Tooltip.styl +7 -2
  118. package/src/components/widgets/SybilionAppHeader/SybilionAppHeader.styl +4 -4
  119. package/src/declarations.d.ts +4 -0
  120. package/src/docs/pages/BannerPage.tsx +83 -0
  121. package/src/docs/pages/ChipPage.tsx +20 -1
  122. package/src/docs/pages/FeedbackOverviewPage.tsx +7 -1
  123. package/src/docs/pages/SelectPage.tsx +30 -1
  124. package/src/docs/pages/SupplyChainMapPage.tsx +21 -0
  125. package/src/docs/registry.ts +12 -0
  126. package/src/index.ts +1 -0
@@ -1,14 +1,15 @@
1
1
  import cn from 'classnames';
2
+ import * as React from 'react';
3
+ import { createPortal } from 'react-dom';
2
4
 
3
5
  import * as SelectPrimitive from '@radix-ui/react-select';
4
- import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from 'lucide-react';
6
+ import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react';
5
7
 
6
8
  import S from './Select.styl';
7
9
  import type {
8
10
  SelectContentProps,
9
11
  SelectGroupProps,
10
12
  SelectItemProps,
11
- SelectLabelProps,
12
13
  SelectProps,
13
14
  SelectScrollDownButtonProps,
14
15
  SelectScrollUpButtonProps,
@@ -17,10 +18,203 @@ import type {
17
18
  SelectValueProps,
18
19
  } from './Select.types';
19
20
 
21
+ type SearchableContextValue = {
22
+ open: boolean;
23
+ setOpen: (open: boolean) => void;
24
+ query: string;
25
+ setQuery: (query: string) => void;
26
+ dirty: boolean;
27
+ setDirty: (dirty: boolean) => void;
28
+ value?: string;
29
+ commitValue: (value: string) => void;
30
+ disabled?: boolean;
31
+ placeholder: string;
32
+ setPlaceholder: (placeholder: string) => void;
33
+ selectedLabel: string;
34
+ registerItem: (value: string, text: string) => void;
35
+ unregisterItem: (value: string) => void;
36
+ highlighted: string | null;
37
+ setHighlighted: (value: string | null) => void;
38
+ visibleValues: string[];
39
+ triggerRef: React.RefObject<HTMLDivElement | null>;
40
+ contentRef: React.RefObject<HTMLDivElement | null>;
41
+ listId: string;
42
+ };
43
+
44
+ const SearchableContext = React.createContext<SearchableContextValue | null>(
45
+ null,
46
+ );
47
+
48
+ function extractText(node: React.ReactNode): string {
49
+ if (node == null || typeof node === 'boolean') return '';
50
+ if (typeof node === 'string' || typeof node === 'number') return String(node);
51
+ if (Array.isArray(node)) return node.map(extractText).join('');
52
+ if (React.isValidElement<{ children?: React.ReactNode }>(node)) {
53
+ return extractText(node.props.children);
54
+ }
55
+ return '';
56
+ }
57
+
58
+ function SearchableSelectRoot({
59
+ value: valueProp,
60
+ defaultValue,
61
+ onValueChange,
62
+ open: openProp,
63
+ onOpenChange,
64
+ disabled,
65
+ children,
66
+ }: Pick<
67
+ SelectProps,
68
+ | 'value'
69
+ | 'defaultValue'
70
+ | 'onValueChange'
71
+ | 'open'
72
+ | 'onOpenChange'
73
+ | 'disabled'
74
+ | 'children'
75
+ >) {
76
+ const listId = React.useId();
77
+ const triggerRef = React.useRef<HTMLDivElement>(null);
78
+ const contentRef = React.useRef<HTMLDivElement>(null);
79
+ const [items, setItems] = React.useState<Record<string, string>>({});
80
+ const [placeholder, setPlaceholder] = React.useState('');
81
+ const [dirty, setDirty] = React.useState(false);
82
+ const [highlighted, setHighlighted] = React.useState<string | null>(null);
83
+
84
+ const [uncontrolledValue, setUncontrolledValue] = React.useState(
85
+ defaultValue ?? '',
86
+ );
87
+ const isValueControlled = valueProp !== undefined;
88
+ const value = isValueControlled ? valueProp : uncontrolledValue;
89
+
90
+ const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false);
91
+ const isOpenControlled = openProp !== undefined;
92
+ const open = isOpenControlled ? Boolean(openProp) : uncontrolledOpen;
93
+
94
+ const setOpen = React.useCallback(
95
+ (next: boolean) => {
96
+ if (!isOpenControlled) setUncontrolledOpen(next);
97
+ onOpenChange?.(next);
98
+ },
99
+ [isOpenControlled, onOpenChange],
100
+ );
101
+
102
+ const commitValue = React.useCallback(
103
+ (next: string) => {
104
+ if (!isValueControlled) setUncontrolledValue(next);
105
+ onValueChange?.(next);
106
+ },
107
+ [isValueControlled, onValueChange],
108
+ );
109
+
110
+ const selectedLabel = (value && items[value]) || '';
111
+ const [query, setQuery] = React.useState(selectedLabel);
112
+
113
+ React.useEffect(() => {
114
+ if (!dirty) setQuery(selectedLabel);
115
+ }, [selectedLabel, dirty]);
116
+
117
+ const registerItem = React.useCallback((itemValue: string, text: string) => {
118
+ setItems(prev =>
119
+ prev[itemValue] === text ? prev : { ...prev, [itemValue]: text },
120
+ );
121
+ }, []);
122
+
123
+ const unregisterItem = React.useCallback((itemValue: string) => {
124
+ setItems(prev => {
125
+ if (!(itemValue in prev)) return prev;
126
+ const next = { ...prev };
127
+ delete next[itemValue];
128
+ return next;
129
+ });
130
+ }, []);
131
+
132
+ const filter = dirty ? query.trim().toLowerCase() : '';
133
+ const visibleValues = React.useMemo(() => {
134
+ const entries = Object.entries(items);
135
+ const matched = filter
136
+ ? entries.filter(([, text]) => text.toLowerCase().includes(filter))
137
+ : entries;
138
+ return matched.map(([itemValue]) => itemValue);
139
+ }, [items, filter]);
140
+
141
+ React.useEffect(() => {
142
+ if (!open) return;
143
+ setHighlighted(current =>
144
+ current && visibleValues.includes(current)
145
+ ? current
146
+ : (visibleValues[0] ?? null),
147
+ );
148
+ }, [open, visibleValues]);
149
+
150
+ const ctx = React.useMemo<SearchableContextValue>(
151
+ () => ({
152
+ open,
153
+ setOpen,
154
+ query,
155
+ setQuery,
156
+ dirty,
157
+ setDirty,
158
+ value,
159
+ commitValue,
160
+ disabled,
161
+ placeholder,
162
+ setPlaceholder,
163
+ selectedLabel,
164
+ registerItem,
165
+ unregisterItem,
166
+ highlighted,
167
+ setHighlighted,
168
+ visibleValues,
169
+ triggerRef,
170
+ contentRef,
171
+ listId,
172
+ }),
173
+ [
174
+ open,
175
+ setOpen,
176
+ query,
177
+ dirty,
178
+ value,
179
+ commitValue,
180
+ disabled,
181
+ placeholder,
182
+ selectedLabel,
183
+ registerItem,
184
+ unregisterItem,
185
+ highlighted,
186
+ visibleValues,
187
+ listId,
188
+ ],
189
+ );
190
+
191
+ return (
192
+ <SearchableContext.Provider value={ctx}>
193
+ {children}
194
+ </SearchableContext.Provider>
195
+ );
196
+ }
197
+
20
198
  function Select({
21
199
  variant = 'default',
200
+ searchable = false,
22
201
  ...props
23
202
  }: SelectProps & { variant?: 'default' | 'clear' }) {
203
+ if (searchable) {
204
+ return (
205
+ <SearchableSelectRoot
206
+ value={props.value}
207
+ defaultValue={props.defaultValue}
208
+ onValueChange={props.onValueChange}
209
+ open={props.open}
210
+ onOpenChange={props.onOpenChange}
211
+ disabled={props.disabled}
212
+ >
213
+ {props.children}
214
+ </SearchableSelectRoot>
215
+ );
216
+ }
217
+
24
218
  return (
25
219
  <SelectPrimitive.Root
26
220
  data-slot="select"
@@ -31,11 +225,164 @@ function Select({
31
225
  }
32
226
 
33
227
  function SelectGroup({ ...props }: SelectGroupProps) {
228
+ const searchable = React.useContext(SearchableContext);
229
+ if (searchable) {
230
+ return <div data-slot="select-group" {...props} />;
231
+ }
34
232
  return <SelectPrimitive.Group data-slot="select-group" {...props} />;
35
233
  }
36
234
 
37
- function SelectValue({ ...props }: SelectValueProps) {
38
- return <SelectPrimitive.Value data-slot="select-value" {...props} />;
235
+ function SelectValue({ placeholder, ...props }: SelectValueProps) {
236
+ const searchable = React.useContext(SearchableContext);
237
+ React.useEffect(() => {
238
+ if (!searchable) return;
239
+ searchable.setPlaceholder(
240
+ typeof placeholder === 'string' ? placeholder : extractText(placeholder),
241
+ );
242
+ }, [searchable, placeholder]);
243
+
244
+ if (searchable) return null;
245
+
246
+ return (
247
+ <SelectPrimitive.Value
248
+ data-slot="select-value"
249
+ placeholder={placeholder}
250
+ {...props}
251
+ />
252
+ );
253
+ }
254
+
255
+ function SearchableTrigger({
256
+ className,
257
+ size = 'md',
258
+ variant = 'default',
259
+ darker = false,
260
+ hideChevron = false,
261
+ disabled: disabledProp,
262
+ style,
263
+ id,
264
+ }: SelectTriggerProps) {
265
+ const ctx = React.useContext(SearchableContext);
266
+ const inputRef = React.useRef<HTMLInputElement>(null);
267
+ const selectAllOnFocus = React.useRef(false);
268
+ React.useLayoutEffect(() => {
269
+ if (!selectAllOnFocus.current) return;
270
+ inputRef.current?.select();
271
+ });
272
+ if (!ctx) return null;
273
+
274
+ const disabled = disabledProp ?? ctx.disabled;
275
+ const displayValue = ctx.open && ctx.dirty ? ctx.query : ctx.selectedLabel;
276
+
277
+ const closeAndReset = () => {
278
+ ctx.setOpen(false);
279
+ ctx.setDirty(false);
280
+ ctx.setQuery(ctx.selectedLabel);
281
+ };
282
+
283
+ const moveHighlight = (delta: number) => {
284
+ if (ctx.visibleValues.length === 0) return;
285
+ const current = ctx.highlighted
286
+ ? ctx.visibleValues.indexOf(ctx.highlighted)
287
+ : -1;
288
+ const nextIndex =
289
+ delta > 0
290
+ ? Math.min(ctx.visibleValues.length - 1, current + 1)
291
+ : Math.max(0, current < 0 ? ctx.visibleValues.length - 1 : current - 1);
292
+ ctx.setHighlighted(ctx.visibleValues[nextIndex] ?? null);
293
+ };
294
+
295
+ return (
296
+ <div
297
+ ref={ctx.triggerRef}
298
+ data-slot="select-trigger"
299
+ data-size={size}
300
+ data-variant={variant}
301
+ data-placeholder={!displayValue || undefined}
302
+ className={cn(
303
+ S.selectTrigger,
304
+ S.searchable,
305
+ darker && S.darker,
306
+ variant === 'clear' && S.clear,
307
+ className,
308
+ )}
309
+ style={style}
310
+ >
311
+ <input
312
+ ref={inputRef}
313
+ id={id}
314
+ className={S.selectTriggerInput}
315
+ role="combobox"
316
+ aria-expanded={ctx.open}
317
+ aria-controls={ctx.listId}
318
+ aria-autocomplete="list"
319
+ aria-activedescendant={
320
+ ctx.open && ctx.highlighted
321
+ ? `${ctx.listId}-${ctx.highlighted}`
322
+ : undefined
323
+ }
324
+ disabled={disabled}
325
+ placeholder={ctx.placeholder}
326
+ value={displayValue}
327
+ autoComplete="off"
328
+ onFocus={event => {
329
+ if (disabled) return;
330
+ ctx.setOpen(true);
331
+ selectAllOnFocus.current = true;
332
+ event.currentTarget.select();
333
+ window.setTimeout(() => {
334
+ selectAllOnFocus.current = false;
335
+ }, 0);
336
+ }}
337
+ onMouseUp={event => {
338
+ if (!selectAllOnFocus.current) return;
339
+ selectAllOnFocus.current = false;
340
+ event.currentTarget.select();
341
+ }}
342
+ onClick={() => {
343
+ if (disabled) return;
344
+ ctx.setOpen(true);
345
+ }}
346
+ onChange={event => {
347
+ selectAllOnFocus.current = false;
348
+ ctx.setDirty(true);
349
+ ctx.setQuery(event.target.value);
350
+ ctx.setOpen(true);
351
+ }}
352
+ onKeyDown={event => {
353
+ if (disabled) return;
354
+ if (event.key === 'ArrowDown') {
355
+ event.preventDefault();
356
+ if (!ctx.open) ctx.setOpen(true);
357
+ else moveHighlight(1);
358
+ } else if (event.key === 'ArrowUp') {
359
+ event.preventDefault();
360
+ if (!ctx.open) ctx.setOpen(true);
361
+ else moveHighlight(-1);
362
+ } else if (event.key === 'Enter') {
363
+ event.preventDefault();
364
+ if (ctx.highlighted) {
365
+ ctx.commitValue(ctx.highlighted);
366
+ ctx.setDirty(false);
367
+ ctx.setOpen(false);
368
+ }
369
+ } else if (event.key === 'Escape') {
370
+ event.preventDefault();
371
+ closeAndReset();
372
+ } else if (event.key === 'Home' && ctx.open) {
373
+ event.preventDefault();
374
+ ctx.setHighlighted(ctx.visibleValues[0] ?? null);
375
+ } else if (event.key === 'End' && ctx.open) {
376
+ event.preventDefault();
377
+ ctx.setHighlighted(
378
+ ctx.visibleValues[ctx.visibleValues.length - 1] ?? null,
379
+ );
380
+ }
381
+ }}
382
+ />
383
+ {!hideChevron && <ChevronDownIcon className={S.selectIcon} />}
384
+ </div>
385
+ );
39
386
  }
40
387
 
41
388
  function SelectTrigger({
@@ -48,12 +395,34 @@ function SelectTrigger({
48
395
  asChild = false,
49
396
  ...props
50
397
  }: SelectTriggerProps) {
398
+ const searchable = React.useContext(SearchableContext);
399
+ if (searchable) {
400
+ return (
401
+ <>
402
+ {children}
403
+ <SearchableTrigger
404
+ className={className}
405
+ size={size}
406
+ variant={variant}
407
+ darker={darker}
408
+ hideChevron={hideChevron}
409
+ {...props}
410
+ />
411
+ </>
412
+ );
413
+ }
414
+
51
415
  return (
52
416
  <SelectPrimitive.Trigger
53
417
  data-slot="select-trigger"
54
418
  data-size={size}
55
419
  data-variant={variant}
56
- className={cn(S.selectTrigger, darker && S.darker, className)}
420
+ className={cn(
421
+ !asChild && S.selectTrigger,
422
+ !asChild && darker && S.darker,
423
+ !asChild && variant === 'clear' && S.clear,
424
+ className,
425
+ )}
57
426
  asChild={asChild}
58
427
  {...props}
59
428
  >
@@ -73,12 +442,92 @@ function SelectTrigger({
73
442
  );
74
443
  }
75
444
 
445
+ function SearchableContent({ className, children }: SelectContentProps) {
446
+ const ctx = React.useContext(SearchableContext);
447
+ const [coords, setCoords] = React.useState({ top: 0, left: 0, width: 0 });
448
+
449
+ const updateCoords = React.useCallback(() => {
450
+ const el = ctx?.triggerRef.current;
451
+ if (!el) return;
452
+ const rect = el.getBoundingClientRect();
453
+ setCoords({ top: rect.bottom + 4, left: rect.left, width: rect.width });
454
+ }, [ctx]);
455
+
456
+ React.useLayoutEffect(() => {
457
+ if (!ctx?.open) return;
458
+ updateCoords();
459
+ window.addEventListener('resize', updateCoords);
460
+ window.addEventListener('scroll', updateCoords, true);
461
+ return () => {
462
+ window.removeEventListener('resize', updateCoords);
463
+ window.removeEventListener('scroll', updateCoords, true);
464
+ };
465
+ }, [ctx?.open, updateCoords]);
466
+
467
+ React.useEffect(() => {
468
+ if (!ctx?.open) return;
469
+ const onPointerDown = (event: PointerEvent) => {
470
+ const target = event.target as Node;
471
+ if (ctx.triggerRef.current?.contains(target)) return;
472
+ if (ctx.contentRef.current?.contains(target)) return;
473
+ ctx.setOpen(false);
474
+ ctx.setDirty(false);
475
+ ctx.setQuery(ctx.selectedLabel);
476
+ };
477
+ document.addEventListener('pointerdown', onPointerDown);
478
+ return () => document.removeEventListener('pointerdown', onPointerDown);
479
+ }, [ctx]);
480
+
481
+ if (!ctx) return null;
482
+
483
+ return createPortal(
484
+ <div
485
+ ref={ctx.contentRef}
486
+ id={ctx.listId}
487
+ role="listbox"
488
+ data-slot="select-content"
489
+ data-state={ctx.open ? 'open' : 'closed'}
490
+ hidden={!ctx.open}
491
+ aria-hidden={!ctx.open}
492
+ className={cn(S.selectContent, S.selectContentPopper, className)}
493
+ style={
494
+ ctx.open
495
+ ? {
496
+ position: 'fixed',
497
+ top: coords.top,
498
+ left: coords.left,
499
+ minWidth: coords.width,
500
+ zIndex: 1100,
501
+ }
502
+ : { display: 'none' }
503
+ }
504
+ >
505
+ <div className={S.selectViewport}>
506
+ {children}
507
+ {ctx.visibleValues.length === 0 && (
508
+ <div className={S.selectEmpty}>No results</div>
509
+ )}
510
+ </div>
511
+ </div>,
512
+ document.body,
513
+ );
514
+ }
515
+
76
516
  function SelectContent({
77
517
  className,
78
518
  children,
79
519
  position = 'popper',
80
520
  ...props
81
521
  }: SelectContentProps) {
522
+ const searchable = React.useContext(SearchableContext);
523
+ if (searchable) {
524
+ return (
525
+ <SearchableContent className={className} {...props}>
526
+ {children}
527
+ </SearchableContent>
528
+ );
529
+ }
530
+
82
531
  return (
83
532
  <SelectPrimitive.Portal>
84
533
  <SelectPrimitive.Content
@@ -111,12 +560,60 @@ function SelectItem({
111
560
  className,
112
561
  children,
113
562
  selected,
563
+ value,
564
+ disabled,
565
+ textValue,
114
566
  ...props
115
567
  }: SelectItemProps) {
568
+ const searchable = React.useContext(SearchableContext);
569
+ const text = textValue || extractText(children);
570
+ const registerItem = searchable?.registerItem;
571
+ const unregisterItem = searchable?.unregisterItem;
572
+
573
+ React.useEffect(() => {
574
+ if (!registerItem || !unregisterItem) return;
575
+ registerItem(value, text);
576
+ return () => unregisterItem(value);
577
+ }, [registerItem, unregisterItem, value, text]);
578
+
579
+ if (searchable) {
580
+ const visible = searchable.visibleValues.includes(value);
581
+ if (!visible) return null;
582
+ const isHighlighted = searchable.highlighted === value;
583
+ const isSelected = selected || searchable.value === value;
584
+ return (
585
+ <div
586
+ {...props}
587
+ id={`${searchable.listId}-${value}`}
588
+ role="option"
589
+ data-slot="select-item"
590
+ data-highlighted={isHighlighted || undefined}
591
+ aria-selected={isSelected}
592
+ aria-disabled={disabled || undefined}
593
+ className={cn(S.selectItem, className, isSelected && S.selected)}
594
+ onPointerDown={event => {
595
+ event.preventDefault();
596
+ if (disabled) return;
597
+ searchable.commitValue(value);
598
+ searchable.setDirty(false);
599
+ searchable.setOpen(false);
600
+ }}
601
+ onMouseEnter={() => {
602
+ if (!disabled) searchable.setHighlighted(value);
603
+ }}
604
+ >
605
+ {children}
606
+ </div>
607
+ );
608
+ }
609
+
116
610
  return (
117
611
  <SelectPrimitive.Item
118
612
  data-slot="select-item"
119
613
  className={cn(S.selectItem, className, selected && S.selected)}
614
+ value={value}
615
+ disabled={disabled}
616
+ textValue={textValue}
120
617
  {...props}
121
618
  >
122
619
  <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
@@ -125,6 +622,16 @@ function SelectItem({
125
622
  }
126
623
 
127
624
  function SelectSeparator({ className, ...props }: SelectSeparatorProps) {
625
+ const searchable = React.useContext(SearchableContext);
626
+ if (searchable) {
627
+ return (
628
+ <div
629
+ data-slot="select-separator"
630
+ className={cn(S.selectSeparator, className)}
631
+ {...props}
632
+ />
633
+ );
634
+ }
128
635
  return (
129
636
  <SelectPrimitive.Separator
130
637
  data-slot="select-separator"
@@ -12,7 +12,9 @@ export interface SelectTriggerProps extends React.ComponentProps<
12
12
  asChild?: boolean;
13
13
  }
14
14
 
15
- export type SelectProps = React.ComponentProps<typeof SelectPrimitive.Root>;
15
+ export type SelectProps = React.ComponentProps<typeof SelectPrimitive.Root> & {
16
+ searchable?: boolean;
17
+ };
16
18
  export type SelectGroupProps = React.ComponentProps<
17
19
  typeof SelectPrimitive.Group
18
20
  >;
@@ -5,7 +5,7 @@ $animationDuration = 200ms
5
5
  .overlay
6
6
  position fixed
7
7
  inset 0
8
- z-index 50
8
+ z-index 1100
9
9
  background-color rgba(0, 0, 0, 0.5)
10
10
  backface-visibility hidden
11
11
 
@@ -17,7 +17,7 @@ $animationDuration = 200ms
17
17
 
18
18
  .content
19
19
  position fixed
20
- z-index 50
20
+ z-index 1100
21
21
  display flex
22
22
  flex-direction column
23
23
  // gap var(--p-4)
@@ -0,0 +1,45 @@
1
+ ---
2
+ summary: Interactive Natural Earth supply-chain map with clustering, disclosure, and optional OffscreenCanvas worker paint
3
+ ---
4
+
5
+ Canvas world map for confirmed sites and routes. Hosts pass entities and edges; the map clusters nearby markers, discloses routes by zoom, and flies to a site at the current zoom.
6
+
7
+ ## When to use
8
+
9
+ - Geographic supply-chain or site networks with lat/lng on confirmed nodes.
10
+ - Demo or product surfaces that need pan, zoom, hover, and clickable labels without a tile map.
11
+
12
+ ## When not to use
13
+
14
+ - Decorative backdrop only — use WorldMap.
15
+ - Driver overlays on the static SVG — use DriverMap.
16
+ - Street-level tiles or Mercator web maps.
17
+
18
+ ## Do
19
+
20
+ - Pass only confirmed, placed nodes you want drawn; drafts stay off the map.
21
+ - Keep geo on the host (`geo.lat` / `geo.lng`); the map does not geocode.
22
+ - Treat click callbacks as host navigation; the inspector is local UI.
23
+
24
+ ## Don't
25
+
26
+ - Import onboarding or graph-workspace types into the map.
27
+ - Rely on the OffscreenCanvas worker in every bundler — main-thread paint is the fallback.
28
+
29
+ ## Host provides
30
+
31
+ - `entities` and `edges` (minimal map types; compatible with onboarding shapes).
32
+ - Optional `onNodeClick` / `onEdgeSelect` and cascade dimming overlay.
33
+
34
+ ## Requires
35
+
36
+ - `entities` — confirmed rows with valid `geo` appear as markers.
37
+ - `edges` — confirmed links between two placed nodes become arcs.
38
+
39
+ ## Empty/loading
40
+
41
+ - No confirmed locations: status empty state. Hosts that SSR should lazy-load this component (d3-geo + TopoJSON).
42
+
43
+ Worker entry (bundler-resolved): `src/components/ui/SupplyChainMap/SupplyChainMap.render.worker.ts`. If `new Worker(new URL(..., import.meta.url))` fails after publish, painting stays on the main thread.
44
+
45
+ See [SupplyChainMap.example.tsx](src/components/ui/SupplyChainMap/SupplyChainMap.example.tsx).
@@ -0,0 +1,45 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ const dir = path.join(process.cwd(), 'src/components/ui/SupplyChainMap');
5
+ const map = readFileSync(path.join(dir, 'SupplyChainMap.tsx'), 'utf8');
6
+ const draw = readFileSync(path.join(dir, 'supply-chain-map-draw.ts'), 'utf8');
7
+ const worker = readFileSync(
8
+ path.join(dir, 'SupplyChainMap.render.worker.ts'),
9
+ 'utf8',
10
+ );
11
+ const styl = readFileSync(path.join(dir, 'SupplyChainMap.styl'), 'utf8');
12
+
13
+ describe('SupplyChainMap contract', () => {
14
+ it('stays a self-contained map (no onboarding / globe / graph)', () => {
15
+ expect(map).toMatch(/buildConfirmedMapScene/);
16
+ expect(map).toMatch(/discloseMapScene/);
17
+ expect(map).toMatch(/clusterMapNodes/);
18
+ expect(map).toMatch(/useMapBaseRenderer/);
19
+ expect(map).toMatch(/role="application"/);
20
+ expect(map).not.toMatch(/from ['"]@\/lib\/onboarding['"]/);
21
+ expect(map).not.toMatch(/from ['"]@\/lib\/globe-/);
22
+ expect(map).not.toMatch(/from ['"]@\/components\/globe-/);
23
+ expect(map).not.toMatch(/from ['"]@\/components\/graph-/);
24
+ });
25
+
26
+ it('paints world-atlas land in a worker-safe module', () => {
27
+ expect(draw).toMatch(/world-atlas\/countries-110m\.json/);
28
+ expect(draw).toMatch(/paintSupplyChainMap/);
29
+ expect(worker).toMatch(/OffscreenCanvas/);
30
+ expect(worker).toMatch(/paintSupplyChainMap/);
31
+ });
32
+
33
+ it('ships map chrome styles with the component', () => {
34
+ expect(styl).toMatch(/^\.root/m);
35
+ expect(styl).toMatch(/^\.canvas/m);
36
+ expect(styl).toMatch(/^\.baseCanvas/m);
37
+ expect(styl).toMatch(/^\.overlay/m);
38
+ expect(styl).toMatch(/^\.marker/m);
39
+ expect(styl).toMatch(/^\.node/m);
40
+ expect(styl).toMatch(/^\.label/m);
41
+ expect(styl).toMatch(/\.marker:hover \.node/);
42
+ expect(styl).toMatch(/\.marker:hover \.label/);
43
+ expect(styl).toMatch(/:global\(\.dark\)/);
44
+ });
45
+ });