@workbench-kit/react 0.0.1-prototype.0 → 0.0.2-prototype.0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +33 -9
- package/src/index.ts +545 -43
- package/src/jdw/JdwPreview.tsx +38 -0
- package/src/jdw/JsonCodeEditorPane.tsx +274 -0
- package/src/jdw/builtins/renderBuiltinWidgetLeaf.tsx +29 -0
- package/src/jdw/builtins/renderBuiltinWidgetNode.tsx +126 -0
- package/src/jdw/createBuiltinJdwRegistry.ts +111 -0
- package/src/jdw/cssRenderBackend.tsx +134 -0
- package/src/jdw/document.ts +38 -0
- package/src/jdw/fixtures/jdw-fixtures.ts +52 -0
- package/src/jdw/fixtures/jdw-sample-screens.ts +522 -0
- package/src/jdw/index.ts +45 -0
- package/src/jdw/parse.ts +1 -0
- package/src/jdw/renderJdw.tsx +32 -0
- package/src/json-config/JsonConfigWorkbench.tsx +316 -0
- package/src/json-config/index.ts +6 -0
- package/src/json-config/json-config-editor-state.ts +42 -0
- package/src/layout/Panel.tsx +146 -1
- package/src/layout/SideBarViewFrame.tsx +367 -328
- package/src/layout/WorkbenchCanvas.tsx +849 -0
- package/src/layout/WorkbenchFullscreen.tsx +368 -0
- package/src/layout/WorkbenchLayout.tsx +5 -0
- package/src/layout/WorkbenchLayoutBase.tsx +294 -0
- package/src/layout/WorkbenchPropertyPanel.tsx +497 -0
- package/src/layout/WorkbenchSidebarActions.tsx +274 -0
- package/src/layout/WorkbenchTree.tsx +351 -0
- package/src/layout/layoutHelpers.ts +25 -0
- package/src/modal/ConfirmDialog.tsx +61 -53
- package/src/modal/Modal.tsx +295 -35
- package/src/overlay/ContextMenu.tsx +146 -145
- package/src/primitives/AbsoluteBox.tsx +46 -0
- package/src/primitives/Badge.tsx +12 -12
- package/src/primitives/Button.tsx +44 -14
- package/src/primitives/Checkbox.tsx +11 -5
- package/src/primitives/EmptyState.tsx +27 -26
- package/src/primitives/Field.tsx +38 -38
- package/src/primitives/IconButton.tsx +5 -2
- package/src/primitives/List.tsx +111 -0
- package/src/primitives/NumberInput.tsx +38 -0
- package/src/primitives/ScrollArea.tsx +42 -0
- package/src/primitives/Select.tsx +1 -12
- package/src/primitives/StatusBar.tsx +46 -0
- package/src/primitives/TextArea.tsx +36 -0
- package/src/primitives/TextInput.tsx +11 -2
- package/src/primitives/WorkbenchChrome.tsx +424 -0
- package/src/primitives/WorkbenchEditor.tsx +394 -0
- package/src/primitives/index.ts +105 -0
- package/src/primitives/select/Select.tsx +266 -0
- package/src/primitives/select/index.ts +2 -0
- package/src/primitives/select/options.ts +38 -0
- package/src/primitives/select/overlay.ts +63 -0
- package/src/primitives/select/select.app.css +9 -0
- package/src/primitives/select/select.css +140 -0
- package/src/primitives/select/types.ts +18 -0
- package/src/primitives/styles.css +955 -0
- package/src/scrollbars.css +69 -0
- package/src/styles.css +7738 -1762
- package/src/utils/codicon.ts +17 -0
- package/src/widget-asset/WidgetAssetEditor.tsx +140 -0
- package/src/widget-asset/WidgetAssetMetadataForm.tsx +82 -0
- package/src/widget-asset/WidgetAssetModeControls.tsx +42 -0
- package/src/widget-asset/WidgetAssetSourceEditor.tsx +50 -0
- package/src/widget-asset/WidgetAssetWorkbench.tsx +112 -0
- package/src/widget-asset/index.ts +17 -0
- package/src/widget-asset/widget-asset-document.ts +37 -0
- package/src/widget-asset/widget-asset-mode.ts +3 -0
- package/src/widget-studio/builtin-widget-asset-catalog.ts +12 -0
- package/src/widget-studio/create-widget-studio-workspace-editor.tsx +79 -0
- package/src/widget-studio/index.ts +7 -0
- package/src/widget-studio/resolve-widget-studio-asset-catalog.ts +26 -0
- package/src/widget-tree/WidgetAssetPalette.tsx +77 -0
- package/src/widget-tree/WidgetInspectorPanel.tsx +266 -0
- package/src/widget-tree/WidgetSourceEditor.tsx +56 -0
- package/src/widget-tree/WidgetTreeLab.tsx +272 -0
- package/src/widget-tree/WidgetTreeModeControls.tsx +44 -0
- package/src/widget-tree/WidgetTreeSidePanel.tsx +49 -0
- package/src/widget-tree/WidgetTreeView.tsx +97 -0
- package/src/widget-tree/WidgetTreeWorkbench.tsx +111 -0
- package/src/widget-tree/WidgetTreeWorkspaceShell.tsx +154 -0
- package/src/widget-tree/demo-registry.ts +32 -0
- package/src/widget-tree/demo-widget-assets.ts +4 -0
- package/src/widget-tree/index.ts +27 -0
- package/src/widget-tree/widget-tree-document.ts +20 -0
- package/src/widget-tree/widget-tree-layout.ts +31 -0
- package/src/widget-tree/widget-tree-mode.ts +7 -0
- package/src/widget-tree/widget-tree-play-helpers.ts +74 -0
- package/src/workbench/ActivityBar.tsx +52 -52
- package/src/workbench/ArtifactShell.tsx +397 -0
- package/src/workbench/CommandPalette.tsx +819 -0
- package/src/workbench/ConfirmationFlow.tsx +245 -0
- package/src/workbench/MarkdownPreview.tsx +151 -0
- package/src/workbench/ShortcutCommandBridge.tsx +368 -0
- package/src/workbench/SplitView.tsx +136 -136
- package/src/workbench/StatusBar.tsx +178 -123
- package/src/workbench/StructuredArtifactEditor.tsx +205 -0
- package/src/workbench/Timeline.tsx +302 -0
- package/src/workbench/WorkbenchCanvasShell.tsx +941 -0
- package/src/workbench/WorkbenchShell.tsx +74 -70
- package/src/workbench/WorkbenchStandaloneShell.tsx +318 -291
- package/src/workbench/auth/WorkbenchAuthGate.tsx +61 -0
- package/src/workbench/auth/WorkbenchLoginView.tsx +635 -0
- package/src/workbench/auth/index.ts +19 -0
- package/src/workbench/chat/ChatComposer.tsx +165 -148
- package/src/workbench/chat/ChatMessageItem.tsx +10 -1
- package/src/workbench/chat/index.ts +9 -0
- package/src/workbench/chat/slashCommand.ts +28 -0
- package/src/workbench/chat/useChatRuntimeState.ts +76 -0
- package/src/workbench/chat/useSlashCommandSuggest.ts +101 -0
- package/src/workbench/commands.ts +520 -490
- package/src/workbench/index.ts +443 -98
- package/src/workbench/keyboard.ts +53 -0
- package/src/workbench/schema/index.ts +48 -0
- package/src/workbench/schema/workbenchDocument.ts +31 -0
- package/src/workbench/schema/workbenchDocumentActions.ts +6 -0
- package/src/workbench/schema/workbenchDocumentAdapter.ts +9 -0
- package/src/workbench/schema/workbenchDocumentPatch.ts +13 -0
- package/src/workbench/schema/workbenchDocumentRenderer.tsx +702 -0
- package/src/workbench/settings/NavigationPanel.tsx +47 -0
- package/src/workbench/settings/SchemaForm.tsx +420 -0
- package/src/workbench/settings/SectionedPanel.tsx +415 -0
- package/src/workbench/settings/StructuredDataForm.tsx +539 -0
- package/src/workbench/settings/StructuredDataSchemaPanel.tsx +559 -0
- package/src/workbench/settings/StructuredDataSchemaPanelEmbed.tsx +21 -0
- package/src/workbench/settings/StructuredDataSchemaPanelFrame.tsx +76 -0
- package/src/workbench/settings/StructuredDataTableView.tsx +127 -0
- package/src/workbench/settings/WorkbenchPanelRegion.tsx +46 -0
- package/src/workbench/settings/WorkbenchSettingsModal.tsx +21 -12
- package/src/workbench/settings/WorkbenchSettingsNav.tsx +38 -22
- package/src/workbench/settings/index.ts +135 -0
- package/src/workbench/settings/panel-region.css +21 -0
- package/src/workbench/settings/sectionedPanelScrollSpy.ts +143 -0
- package/src/workbench/settings/structured-data-schema-panel.css +330 -0
- package/src/workbench/settings/structured-data-table-view.css +85 -0
- package/src/workbench/settings/structuredDataSchema.ts +886 -0
- package/src/workbench/shell.ts +15 -0
- package/src/workbench/shellState.ts +203 -203
- package/src/workbench/standalone.ts +101 -94
- package/src/workbench/status.ts +129 -0
- package/src/workbench/theme.ts +44 -0
- package/src/workbench/workspace/MultiProviderExplorer.tsx +625 -0
- package/src/workbench/workspace/WorkspaceDraftsContext.tsx +111 -0
- package/src/workbench/workspace/WorkspaceEditor.tsx +47 -12
- package/src/workbench/workspace/WorkspaceEditorPanel.tsx +334 -353
- package/src/workbench/workspace/WorkspaceExplorer.tsx +532 -524
- package/src/workbench/workspace/WorkspaceFileIcon.tsx +32 -2
- package/src/workbench/workspace/WorkspaceSearchPanel.tsx +113 -113
- package/src/workbench/workspace/WorkspaceSearchResults.tsx +47 -47
- package/src/workbench/workspace/index.ts +156 -98
- package/src/workbench/workspace/mimeType.ts +45 -0
- package/src/workbench/workspace/path.ts +10 -10
- package/src/workbench/workspace/search.ts +6 -6
- package/src/workbench/workspace/tree.ts +1 -1
- package/src/workbench/workspace/types.ts +10 -10
- package/src/workbench/workspace/useVirtualWorkspace.ts +111 -98
- package/src/workbench/workspace/workspaceJsonDiagnostics.ts +83 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useId,
|
|
5
|
+
useLayoutEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
type ChangeEvent,
|
|
9
|
+
type ComponentPropsWithRef,
|
|
10
|
+
type KeyboardEvent,
|
|
11
|
+
} from 'react';
|
|
12
|
+
import { createPortal } from 'react-dom';
|
|
13
|
+
import type { ControlWidth } from '../TextInput';
|
|
14
|
+
import { cxCodicon } from '../../utils/codicon';
|
|
15
|
+
import { cx } from '../../utils/cx';
|
|
16
|
+
import { getEnabledOptionIndex, parseOptions } from './options';
|
|
17
|
+
import { isTriggerVisible, measureOverlayPosition, overlayListboxStyle } from './overlay';
|
|
18
|
+
import type { OverlayPosition, ParsedOption } from './types';
|
|
19
|
+
|
|
20
|
+
export interface SelectProps extends ComponentPropsWithRef<'select'> {
|
|
21
|
+
controlWidth?: ControlWidth;
|
|
22
|
+
onValueChange?: (value: string, event: ChangeEvent<HTMLSelectElement>) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function Select({
|
|
26
|
+
className,
|
|
27
|
+
controlWidth = 'default',
|
|
28
|
+
defaultValue,
|
|
29
|
+
disabled = false,
|
|
30
|
+
id,
|
|
31
|
+
onChange,
|
|
32
|
+
onValueChange,
|
|
33
|
+
value,
|
|
34
|
+
children,
|
|
35
|
+
'aria-describedby': ariaDescribedBy,
|
|
36
|
+
'aria-label': ariaLabel,
|
|
37
|
+
'aria-labelledby': ariaLabelledBy,
|
|
38
|
+
...nativeSelectProps
|
|
39
|
+
}: SelectProps) {
|
|
40
|
+
const options = parseOptions(children);
|
|
41
|
+
const listboxId = useId();
|
|
42
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
43
|
+
const triggerRef = useRef<HTMLButtonElement>(null);
|
|
44
|
+
const listboxRef = useRef<HTMLUListElement>(null);
|
|
45
|
+
const nativeSelectRef = useRef<HTMLSelectElement>(null);
|
|
46
|
+
const [open, setOpen] = useState(false);
|
|
47
|
+
const [overlayPosition, setOverlayPosition] = useState<OverlayPosition | null>(null);
|
|
48
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(() =>
|
|
49
|
+
String(defaultValue ?? options.find((option) => !option.disabled)?.value ?? ''),
|
|
50
|
+
);
|
|
51
|
+
const [highlightedIndex, setHighlightedIndex] = useState(-1);
|
|
52
|
+
|
|
53
|
+
const isControlled = value !== undefined;
|
|
54
|
+
const currentValue = isControlled ? String(value) : uncontrolledValue;
|
|
55
|
+
const selectedIndex = options.findIndex((option) => option.value === currentValue);
|
|
56
|
+
const selectedOption =
|
|
57
|
+
selectedIndex >= 0 ? options[selectedIndex] : options.find((option) => !option.disabled);
|
|
58
|
+
|
|
59
|
+
const commitValue = (nextValue: string) => {
|
|
60
|
+
const nativeSelect = nativeSelectRef.current;
|
|
61
|
+
if (!nativeSelect) return;
|
|
62
|
+
|
|
63
|
+
nativeSelect.value = nextValue;
|
|
64
|
+
if (!isControlled) {
|
|
65
|
+
setUncontrolledValue(nextValue);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
nativeSelect.dispatchEvent(new Event('change', { bubbles: true }));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const handleNativeChange = (event: ChangeEvent<HTMLSelectElement>) => {
|
|
72
|
+
if (!isControlled) {
|
|
73
|
+
setUncontrolledValue(event.currentTarget.value);
|
|
74
|
+
}
|
|
75
|
+
onChange?.(event);
|
|
76
|
+
onValueChange?.(event.currentTarget.value, event);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const closeListbox = useCallback(() => {
|
|
80
|
+
setOpen(false);
|
|
81
|
+
setHighlightedIndex(-1);
|
|
82
|
+
}, []);
|
|
83
|
+
|
|
84
|
+
const openListbox = (preferredIndex = selectedIndex >= 0 ? selectedIndex : 0) => {
|
|
85
|
+
if (disabled) return;
|
|
86
|
+
setOpen(true);
|
|
87
|
+
setHighlightedIndex(getEnabledOptionIndex(options, preferredIndex, 1));
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const selectOption = (option: ParsedOption | undefined) => {
|
|
91
|
+
if (!option || option.disabled) return;
|
|
92
|
+
commitValue(option.value);
|
|
93
|
+
closeListbox();
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const updateOverlayPosition = useCallback(() => {
|
|
97
|
+
const trigger = triggerRef.current;
|
|
98
|
+
if (!trigger) return;
|
|
99
|
+
|
|
100
|
+
if (!isTriggerVisible(trigger)) {
|
|
101
|
+
closeListbox();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const position = measureOverlayPosition(trigger, options.length);
|
|
106
|
+
if (!position) {
|
|
107
|
+
closeListbox();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
setOverlayPosition(position);
|
|
112
|
+
}, [closeListbox, options.length]);
|
|
113
|
+
|
|
114
|
+
useLayoutEffect(() => {
|
|
115
|
+
if (!open) {
|
|
116
|
+
setOverlayPosition(null);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
updateOverlayPosition();
|
|
121
|
+
window.addEventListener('resize', updateOverlayPosition);
|
|
122
|
+
window.addEventListener('scroll', updateOverlayPosition, true);
|
|
123
|
+
return () => {
|
|
124
|
+
window.removeEventListener('resize', updateOverlayPosition);
|
|
125
|
+
window.removeEventListener('scroll', updateOverlayPosition, true);
|
|
126
|
+
};
|
|
127
|
+
}, [open, updateOverlayPosition]);
|
|
128
|
+
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (!open) return;
|
|
131
|
+
|
|
132
|
+
const handlePointerDown = (event: PointerEvent) => {
|
|
133
|
+
const target = event.target as Node;
|
|
134
|
+
if (containerRef.current?.contains(target)) return;
|
|
135
|
+
if (listboxRef.current?.contains(target)) return;
|
|
136
|
+
closeListbox();
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const handleKeyDown = (event: globalThis.KeyboardEvent) => {
|
|
140
|
+
if (event.key === 'Escape') closeListbox();
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
window.addEventListener('pointerdown', handlePointerDown, true);
|
|
144
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
145
|
+
return () => {
|
|
146
|
+
window.removeEventListener('pointerdown', handlePointerDown, true);
|
|
147
|
+
window.removeEventListener('keydown', handleKeyDown);
|
|
148
|
+
};
|
|
149
|
+
}, [closeListbox, open]);
|
|
150
|
+
|
|
151
|
+
const handleTriggerKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {
|
|
152
|
+
if (disabled) return;
|
|
153
|
+
|
|
154
|
+
switch (event.key) {
|
|
155
|
+
case 'ArrowDown':
|
|
156
|
+
case 'ArrowUp':
|
|
157
|
+
case 'Enter':
|
|
158
|
+
case ' ':
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
if (!open) {
|
|
161
|
+
openListbox();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
case 'Escape':
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
closeListbox();
|
|
168
|
+
return;
|
|
169
|
+
case 'Home':
|
|
170
|
+
event.preventDefault();
|
|
171
|
+
setHighlightedIndex(getEnabledOptionIndex(options, -1, 1));
|
|
172
|
+
return;
|
|
173
|
+
case 'End':
|
|
174
|
+
event.preventDefault();
|
|
175
|
+
setHighlightedIndex(getEnabledOptionIndex(options, 0, -1));
|
|
176
|
+
return;
|
|
177
|
+
default:
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
182
|
+
selectOption(options[highlightedIndex]);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const direction = event.key === 'ArrowDown' ? 1 : -1;
|
|
187
|
+
const baseIndex = highlightedIndex >= 0 ? highlightedIndex : Math.max(selectedIndex, 0);
|
|
188
|
+
setHighlightedIndex(getEnabledOptionIndex(options, baseIndex, direction));
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const listbox =
|
|
192
|
+
open && overlayPosition ? (
|
|
193
|
+
<ul
|
|
194
|
+
ref={listboxRef}
|
|
195
|
+
className="ui-select__listbox ui-workbench-scrollbar"
|
|
196
|
+
id={listboxId}
|
|
197
|
+
role="listbox"
|
|
198
|
+
style={overlayListboxStyle(overlayPosition)}
|
|
199
|
+
>
|
|
200
|
+
{options.map((option, index) => {
|
|
201
|
+
const isSelected = option.value === currentValue;
|
|
202
|
+
const isHighlighted = index === highlightedIndex;
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<li
|
|
206
|
+
key={option.value}
|
|
207
|
+
aria-disabled={option.disabled ? 'true' : undefined}
|
|
208
|
+
aria-selected={isSelected}
|
|
209
|
+
className={cx(
|
|
210
|
+
'ui-select__option',
|
|
211
|
+
isSelected && 'ui-select__option--selected',
|
|
212
|
+
isHighlighted && 'ui-select__option--highlighted',
|
|
213
|
+
)}
|
|
214
|
+
role="option"
|
|
215
|
+
onMouseEnter={() => !option.disabled && setHighlightedIndex(index)}
|
|
216
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
217
|
+
onClick={() => selectOption(option)}
|
|
218
|
+
>
|
|
219
|
+
{option.label}
|
|
220
|
+
</li>
|
|
221
|
+
);
|
|
222
|
+
})}
|
|
223
|
+
</ul>
|
|
224
|
+
) : null;
|
|
225
|
+
|
|
226
|
+
return (
|
|
227
|
+
<div ref={containerRef} className={cx('ui-select', className)} data-width={controlWidth}>
|
|
228
|
+
<button
|
|
229
|
+
ref={triggerRef}
|
|
230
|
+
aria-controls={listboxId}
|
|
231
|
+
aria-describedby={ariaDescribedBy}
|
|
232
|
+
aria-expanded={open}
|
|
233
|
+
aria-haspopup="listbox"
|
|
234
|
+
aria-label={ariaLabel}
|
|
235
|
+
aria-labelledby={ariaLabelledBy}
|
|
236
|
+
className="ui-select__trigger"
|
|
237
|
+
disabled={disabled}
|
|
238
|
+
id={id}
|
|
239
|
+
role="combobox"
|
|
240
|
+
type="button"
|
|
241
|
+
onClick={() => (open ? closeListbox() : openListbox())}
|
|
242
|
+
onKeyDown={handleTriggerKeyDown}
|
|
243
|
+
>
|
|
244
|
+
<span className="ui-select__value">{selectedOption?.label}</span>
|
|
245
|
+
<span aria-hidden="true" className="ui-select__chevron">
|
|
246
|
+
<i className={cxCodicon('chevron-down')} />
|
|
247
|
+
</span>
|
|
248
|
+
</button>
|
|
249
|
+
|
|
250
|
+
{listbox ? createPortal(listbox, document.body) : null}
|
|
251
|
+
|
|
252
|
+
<select
|
|
253
|
+
ref={nativeSelectRef}
|
|
254
|
+
aria-hidden="true"
|
|
255
|
+
className="ui-select__native"
|
|
256
|
+
disabled={disabled}
|
|
257
|
+
tabIndex={-1}
|
|
258
|
+
value={currentValue}
|
|
259
|
+
onChange={handleNativeChange}
|
|
260
|
+
{...nativeSelectProps}
|
|
261
|
+
>
|
|
262
|
+
{children}
|
|
263
|
+
</select>
|
|
264
|
+
</div>
|
|
265
|
+
);
|
|
266
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
isValidElement,
|
|
4
|
+
type ComponentPropsWithRef,
|
|
5
|
+
type ReactElement,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import type { ParsedOption } from './types';
|
|
9
|
+
|
|
10
|
+
function isOptionElement(child: ReactNode): child is ReactElement<ComponentPropsWithRef<'option'>> {
|
|
11
|
+
return isValidElement(child) && child.type === 'option';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function parseOptions(children: ReactNode): ParsedOption[] {
|
|
15
|
+
return Children.toArray(children)
|
|
16
|
+
.filter(isOptionElement)
|
|
17
|
+
.map((child) => ({
|
|
18
|
+
value: String(child.props.value ?? ''),
|
|
19
|
+
label: child.props.children ?? child.props.value ?? '',
|
|
20
|
+
disabled: Boolean(child.props.disabled),
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getEnabledOptionIndex(
|
|
25
|
+
options: ParsedOption[],
|
|
26
|
+
startIndex: number,
|
|
27
|
+
direction: 1 | -1,
|
|
28
|
+
) {
|
|
29
|
+
if (options.length === 0) return -1;
|
|
30
|
+
|
|
31
|
+
let index = startIndex;
|
|
32
|
+
for (let step = 0; step < options.length; step += 1) {
|
|
33
|
+
index = (index + direction + options.length) % options.length;
|
|
34
|
+
if (!options[index]?.disabled) return index;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return -1;
|
|
38
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
import type { ListboxPlacement, OverlayPosition } from './types';
|
|
3
|
+
|
|
4
|
+
const LISTBOX_MAX_HEIGHT = 240;
|
|
5
|
+
const LISTBOX_OPTION_HEIGHT = 28;
|
|
6
|
+
const VIEWPORT_PADDING = 8;
|
|
7
|
+
|
|
8
|
+
export function isTriggerVisible(trigger: HTMLElement) {
|
|
9
|
+
const rect = trigger.getBoundingClientRect();
|
|
10
|
+
if (rect.width <= 0 || rect.height <= 0) return false;
|
|
11
|
+
if (rect.bottom <= 0 || rect.top >= window.innerHeight) return false;
|
|
12
|
+
if (rect.right <= 0 || rect.left >= window.innerWidth) return false;
|
|
13
|
+
|
|
14
|
+
if (typeof trigger.checkVisibility === 'function') {
|
|
15
|
+
return trigger.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function measureOverlayPosition(
|
|
22
|
+
trigger: HTMLElement,
|
|
23
|
+
optionCount: number,
|
|
24
|
+
): OverlayPosition | null {
|
|
25
|
+
const rect = trigger.getBoundingClientRect();
|
|
26
|
+
if (rect.width <= 0 || rect.height <= 0) return null;
|
|
27
|
+
|
|
28
|
+
const idealHeight = Math.min(LISTBOX_MAX_HEIGHT, optionCount * LISTBOX_OPTION_HEIGHT + 8);
|
|
29
|
+
const spaceBelow = Math.max(0, window.innerHeight - rect.bottom - VIEWPORT_PADDING);
|
|
30
|
+
const spaceAbove = Math.max(0, rect.top - VIEWPORT_PADDING);
|
|
31
|
+
const placement: ListboxPlacement =
|
|
32
|
+
spaceBelow >= idealHeight || spaceBelow >= spaceAbove ? 'bottom' : 'top';
|
|
33
|
+
const available = placement === 'bottom' ? spaceBelow : spaceAbove;
|
|
34
|
+
const minHeight = LISTBOX_OPTION_HEIGHT + 8;
|
|
35
|
+
const maxHeight = Math.min(LISTBOX_MAX_HEIGHT, idealHeight, Math.max(minHeight, available));
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
placement,
|
|
39
|
+
left: rect.left,
|
|
40
|
+
width: rect.width,
|
|
41
|
+
maxHeight,
|
|
42
|
+
triggerTop: rect.top,
|
|
43
|
+
triggerBottom: rect.bottom,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function overlayListboxStyle(position: OverlayPosition): CSSProperties {
|
|
48
|
+
const base: CSSProperties = {
|
|
49
|
+
left: position.left,
|
|
50
|
+
width: position.width,
|
|
51
|
+
maxHeight: position.maxHeight,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
if (position.placement === 'bottom') {
|
|
55
|
+
return { ...base, top: position.triggerBottom };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
...base,
|
|
60
|
+
top: position.triggerTop,
|
|
61
|
+
transform: 'translateY(-100%)',
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--ui-select-width-default: 320px;
|
|
3
|
+
--ui-select-width-wide: 420px;
|
|
4
|
+
--ui-select-trigger-height: 28px;
|
|
5
|
+
--ui-select-trigger-radius: var(--radius-sm);
|
|
6
|
+
--ui-select-option-height: 28px;
|
|
7
|
+
--ui-select-option-padding: 5px 10px;
|
|
8
|
+
--ui-select-option-radius: calc(var(--radius-sm) - 2px);
|
|
9
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
.ui-select {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: inline-block;
|
|
4
|
+
box-sizing: border-box;
|
|
5
|
+
min-width: 0;
|
|
6
|
+
vertical-align: top;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.ui-select[data-width='default'] {
|
|
10
|
+
width: var(--ui-select-width-default, 180px);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.ui-select[data-width='wide'] {
|
|
14
|
+
width: var(--ui-select-width-wide, 260px);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.ui-select[data-width='full'] {
|
|
18
|
+
width: 100%;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.ui-select__trigger {
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
position: relative;
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
width: 100%;
|
|
27
|
+
height: var(--ui-select-trigger-height, 26px);
|
|
28
|
+
min-width: 0;
|
|
29
|
+
padding: 0 28px 0 8px;
|
|
30
|
+
color: var(--vscode-input-foreground, var(--color-text));
|
|
31
|
+
background: var(--vscode-input-background, var(--color-surface));
|
|
32
|
+
border: 1px solid var(--vscode-input-border, var(--color-border));
|
|
33
|
+
border-radius: var(--ui-select-trigger-radius, 0);
|
|
34
|
+
outline: none;
|
|
35
|
+
font: inherit;
|
|
36
|
+
font-size: var(--font-size-sm);
|
|
37
|
+
text-align: left;
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.ui-select__trigger:disabled {
|
|
42
|
+
color: var(--color-text-subtle);
|
|
43
|
+
cursor: default;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.ui-select__value {
|
|
47
|
+
flex: 1;
|
|
48
|
+
min-width: 0;
|
|
49
|
+
overflow: hidden;
|
|
50
|
+
text-overflow: ellipsis;
|
|
51
|
+
white-space: nowrap;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.ui-select__chevron {
|
|
55
|
+
position: absolute;
|
|
56
|
+
top: 50%;
|
|
57
|
+
right: 8px;
|
|
58
|
+
display: inline-flex;
|
|
59
|
+
align-items: center;
|
|
60
|
+
justify-content: center;
|
|
61
|
+
color: var(--color-text-muted);
|
|
62
|
+
transform: translateY(-50%);
|
|
63
|
+
pointer-events: none;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.ui-select__chevron .codicon {
|
|
67
|
+
font-size: 14px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.ui-select__listbox {
|
|
71
|
+
position: fixed;
|
|
72
|
+
z-index: 10000;
|
|
73
|
+
box-sizing: border-box;
|
|
74
|
+
margin: 0;
|
|
75
|
+
padding: 4px;
|
|
76
|
+
list-style: none;
|
|
77
|
+
color: var(--vscode-menu-foreground, var(--color-text));
|
|
78
|
+
background: var(--vscode-menu-background, var(--color-surface));
|
|
79
|
+
border: 1px solid var(--vscode-menu-border, var(--color-border));
|
|
80
|
+
border-radius: var(--radius-sm, 0);
|
|
81
|
+
max-height: 240px;
|
|
82
|
+
overflow-y: auto;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.ui-select__option {
|
|
86
|
+
min-height: var(--ui-select-option-height, 26px);
|
|
87
|
+
padding: var(--ui-select-option-padding, 4px 10px);
|
|
88
|
+
border-radius: var(--ui-select-option-radius, 0);
|
|
89
|
+
font-size: var(--font-size-sm);
|
|
90
|
+
line-height: 1.4;
|
|
91
|
+
cursor: pointer;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.ui-select__option[aria-disabled='true'] {
|
|
95
|
+
color: var(--color-text-subtle);
|
|
96
|
+
cursor: default;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.ui-select__option:hover,
|
|
100
|
+
.ui-select__option--highlighted {
|
|
101
|
+
color: var(--vscode-menu-selectionForeground, var(--color-text));
|
|
102
|
+
background: var(--vscode-menu-selectionBackground, var(--color-surface-hover));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.ui-select__option--selected {
|
|
106
|
+
color: var(--vscode-list-activeSelectionForeground, var(--color-text));
|
|
107
|
+
background: var(--vscode-list-activeSelectionBackground, var(--color-surface-hover));
|
|
108
|
+
font-weight: 600;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.ui-select__native {
|
|
112
|
+
position: absolute;
|
|
113
|
+
width: 0;
|
|
114
|
+
height: 0;
|
|
115
|
+
padding: 0;
|
|
116
|
+
margin: 0;
|
|
117
|
+
opacity: 0;
|
|
118
|
+
pointer-events: none;
|
|
119
|
+
overflow: hidden;
|
|
120
|
+
clip: rect(0, 0, 0, 0);
|
|
121
|
+
clip-path: inset(50%);
|
|
122
|
+
white-space: nowrap;
|
|
123
|
+
border: 0;
|
|
124
|
+
appearance: none;
|
|
125
|
+
-webkit-appearance: none;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.ui-select__trigger:focus {
|
|
129
|
+
border-color: var(--vscode-focusBorder, var(--color-accent, var(--color-focus-border)));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.ui-select__trigger:focus-visible {
|
|
133
|
+
outline: 1px solid var(--vscode-focusBorder, var(--color-focus-border));
|
|
134
|
+
outline-offset: -1px;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.ui-select__option:focus-visible {
|
|
138
|
+
outline: 1px solid var(--vscode-focusBorder, var(--color-focus-border));
|
|
139
|
+
outline-offset: -1px;
|
|
140
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface ParsedOption {
|
|
4
|
+
value: string;
|
|
5
|
+
label: ReactNode;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type ListboxPlacement = 'bottom' | 'top';
|
|
10
|
+
|
|
11
|
+
export interface OverlayPosition {
|
|
12
|
+
left: number;
|
|
13
|
+
maxHeight: number;
|
|
14
|
+
placement: ListboxPlacement;
|
|
15
|
+
triggerBottom: number;
|
|
16
|
+
triggerTop: number;
|
|
17
|
+
width: number;
|
|
18
|
+
}
|