@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,394 @@
|
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
CSSProperties,
|
|
4
|
+
ComponentPropsWithRef,
|
|
5
|
+
DragEvent as ReactDragEvent,
|
|
6
|
+
KeyboardEvent as ReactKeyboardEvent,
|
|
7
|
+
MouseEvent as ReactMouseEvent,
|
|
8
|
+
PointerEvent as ReactPointerEvent,
|
|
9
|
+
ReactNode,
|
|
10
|
+
} from 'react';
|
|
11
|
+
import { cxCodicon } from '../utils/codicon';
|
|
12
|
+
import { cx } from '../utils/cx';
|
|
13
|
+
import { IconButton } from './IconButton';
|
|
14
|
+
|
|
15
|
+
export interface ButtonGroupProps extends ComponentPropsWithRef<'div'> {
|
|
16
|
+
ariaLabel?: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function ButtonGroup({ ariaLabel, className, role = 'group', ...props }: ButtonGroupProps) {
|
|
20
|
+
return (
|
|
21
|
+
<div
|
|
22
|
+
aria-label={ariaLabel ?? props['aria-label']}
|
|
23
|
+
className={cx('ui-button-group', className)}
|
|
24
|
+
role={role}
|
|
25
|
+
{...props}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface SegmentedControlOption<TValue extends string = string> {
|
|
31
|
+
label: ReactNode;
|
|
32
|
+
testId?: string | undefined;
|
|
33
|
+
value: TValue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface SegmentedControlProps<TValue extends string = string> {
|
|
37
|
+
ariaLabel?: string | undefined;
|
|
38
|
+
onChange: (value: TValue) => void;
|
|
39
|
+
options: readonly SegmentedControlOption<TValue>[];
|
|
40
|
+
value: TValue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function SegmentedControl<TValue extends string = string>({
|
|
44
|
+
ariaLabel,
|
|
45
|
+
onChange,
|
|
46
|
+
options,
|
|
47
|
+
value,
|
|
48
|
+
}: SegmentedControlProps<TValue>) {
|
|
49
|
+
return (
|
|
50
|
+
<ButtonGroup ariaLabel={ariaLabel}>
|
|
51
|
+
{options.map((option) => {
|
|
52
|
+
const selected = option.value === value;
|
|
53
|
+
return (
|
|
54
|
+
<button
|
|
55
|
+
key={option.value}
|
|
56
|
+
aria-pressed={selected}
|
|
57
|
+
className={cx(
|
|
58
|
+
'ui-segmented-control__item',
|
|
59
|
+
selected && 'ui-segmented-control__item--selected',
|
|
60
|
+
)}
|
|
61
|
+
data-testid={option.testId}
|
|
62
|
+
onClick={() => onChange(option.value)}
|
|
63
|
+
type="button"
|
|
64
|
+
>
|
|
65
|
+
{option.label}
|
|
66
|
+
</button>
|
|
67
|
+
);
|
|
68
|
+
})}
|
|
69
|
+
</ButtonGroup>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface EditorTab {
|
|
74
|
+
closable?: boolean | undefined;
|
|
75
|
+
dirty?: boolean | undefined;
|
|
76
|
+
dropPosition?: EditorTabDropPosition | undefined;
|
|
77
|
+
icon?: string | undefined;
|
|
78
|
+
id: string;
|
|
79
|
+
label: ReactNode;
|
|
80
|
+
pinned?: boolean | undefined;
|
|
81
|
+
preview?: boolean | undefined;
|
|
82
|
+
title?: string | undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type EditorTabDropPosition = 'after' | 'before';
|
|
86
|
+
|
|
87
|
+
export interface EditorTabsProps extends Omit<ComponentPropsWithRef<'div'>, 'onSelect'> {
|
|
88
|
+
activeId: string;
|
|
89
|
+
addons?: ReactNode | undefined;
|
|
90
|
+
draggableTabs?: boolean | undefined;
|
|
91
|
+
onClose?: ((id: string) => void) | undefined;
|
|
92
|
+
onNewTab?: (() => void) | undefined;
|
|
93
|
+
onPinToggle?: ((id: string) => void) | undefined;
|
|
94
|
+
onSelect: (id: string) => void;
|
|
95
|
+
onTabContextMenu?: ((id: string, event: ReactMouseEvent<HTMLElement>) => void) | undefined;
|
|
96
|
+
onTabDoubleClick?: ((id: string, event: ReactMouseEvent<HTMLElement>) => void) | undefined;
|
|
97
|
+
onTabDragEnd?: ((id: string, event: ReactDragEvent<HTMLElement>) => void) | undefined;
|
|
98
|
+
onTabDragLeave?: ((id: string, event: ReactDragEvent<HTMLElement>) => void) | undefined;
|
|
99
|
+
onTabDragOver?: ((id: string, event: ReactDragEvent<HTMLElement>) => void) | undefined;
|
|
100
|
+
onTabDragStart?: ((id: string, event: ReactDragEvent<HTMLElement>) => void) | undefined;
|
|
101
|
+
onTabDrop?: ((id: string, event: ReactDragEvent<HTMLElement>) => void) | undefined;
|
|
102
|
+
tabs: readonly EditorTab[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function EditorTabs({
|
|
106
|
+
activeId,
|
|
107
|
+
addons,
|
|
108
|
+
className,
|
|
109
|
+
draggableTabs,
|
|
110
|
+
onClose,
|
|
111
|
+
onNewTab,
|
|
112
|
+
onPinToggle,
|
|
113
|
+
onSelect,
|
|
114
|
+
onTabContextMenu,
|
|
115
|
+
onTabDoubleClick,
|
|
116
|
+
onTabDragEnd,
|
|
117
|
+
onTabDragLeave,
|
|
118
|
+
onTabDragOver,
|
|
119
|
+
onTabDragStart,
|
|
120
|
+
onTabDrop,
|
|
121
|
+
tabs,
|
|
122
|
+
...props
|
|
123
|
+
}: EditorTabsProps) {
|
|
124
|
+
return (
|
|
125
|
+
<div className={cx('ui-editor-tabs', className)} role="tablist" {...props}>
|
|
126
|
+
<div className="ui-editor-tabs__scroller ui-workbench-scrollbar--hidden">
|
|
127
|
+
{tabs.map((tab) => {
|
|
128
|
+
const active = tab.id === activeId;
|
|
129
|
+
return (
|
|
130
|
+
<div
|
|
131
|
+
key={tab.id}
|
|
132
|
+
aria-selected={active}
|
|
133
|
+
className={cx('ui-editor-tabs__tab', active && 'ui-editor-tabs__tab--active')}
|
|
134
|
+
data-drop-position={tab.dropPosition}
|
|
135
|
+
draggable={draggableTabs}
|
|
136
|
+
onClick={() => onSelect(tab.id)}
|
|
137
|
+
onContextMenu={(event) => {
|
|
138
|
+
onTabContextMenu?.(tab.id, event);
|
|
139
|
+
}}
|
|
140
|
+
onDoubleClick={(event) => {
|
|
141
|
+
onTabDoubleClick?.(tab.id, event);
|
|
142
|
+
}}
|
|
143
|
+
onDragEnd={(event) => {
|
|
144
|
+
onTabDragEnd?.(tab.id, event);
|
|
145
|
+
}}
|
|
146
|
+
onDragLeave={(event) => {
|
|
147
|
+
onTabDragLeave?.(tab.id, event);
|
|
148
|
+
}}
|
|
149
|
+
onDragOver={(event) => {
|
|
150
|
+
onTabDragOver?.(tab.id, event);
|
|
151
|
+
}}
|
|
152
|
+
onDragStart={(event) => {
|
|
153
|
+
onTabDragStart?.(tab.id, event);
|
|
154
|
+
}}
|
|
155
|
+
onDrop={(event) => {
|
|
156
|
+
onTabDrop?.(tab.id, event);
|
|
157
|
+
}}
|
|
158
|
+
onKeyDown={(event) => {
|
|
159
|
+
if (event.key !== 'Enter' && event.key !== ' ') return;
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
onSelect(tab.id);
|
|
162
|
+
}}
|
|
163
|
+
role="tab"
|
|
164
|
+
tabIndex={active ? 0 : -1}
|
|
165
|
+
title={tab.title}
|
|
166
|
+
>
|
|
167
|
+
{tab.icon ? (
|
|
168
|
+
<i aria-hidden className={cxCodicon(tab.icon, 'ui-editor-tabs__file-icon')} />
|
|
169
|
+
) : null}
|
|
170
|
+
<span className="ui-editor-tabs__label">{tab.label}</span>
|
|
171
|
+
{tab.preview ? (
|
|
172
|
+
<i
|
|
173
|
+
aria-hidden
|
|
174
|
+
className={cxCodicon(
|
|
175
|
+
'preview',
|
|
176
|
+
'ui-editor-tabs__status-icon',
|
|
177
|
+
'ui-editor-tabs__status-icon--preview',
|
|
178
|
+
)}
|
|
179
|
+
/>
|
|
180
|
+
) : null}
|
|
181
|
+
{tab.dirty ? (
|
|
182
|
+
<span aria-label="Unsaved changes" className="ui-editor-tabs__dirty">
|
|
183
|
+
•
|
|
184
|
+
</span>
|
|
185
|
+
) : null}
|
|
186
|
+
{tab.pinned ? (
|
|
187
|
+
onPinToggle ? (
|
|
188
|
+
<button
|
|
189
|
+
aria-label="Unpin tab"
|
|
190
|
+
className="ui-editor-tabs__status-button"
|
|
191
|
+
title="Unpin tab"
|
|
192
|
+
type="button"
|
|
193
|
+
onClick={(event) => {
|
|
194
|
+
event.stopPropagation();
|
|
195
|
+
onPinToggle(tab.id);
|
|
196
|
+
}}
|
|
197
|
+
>
|
|
198
|
+
<i
|
|
199
|
+
aria-hidden
|
|
200
|
+
className={cxCodicon(
|
|
201
|
+
'pinned',
|
|
202
|
+
'ui-editor-tabs__status-icon',
|
|
203
|
+
'ui-editor-tabs__status-icon--pinned',
|
|
204
|
+
)}
|
|
205
|
+
/>
|
|
206
|
+
</button>
|
|
207
|
+
) : (
|
|
208
|
+
<i
|
|
209
|
+
aria-hidden
|
|
210
|
+
className={cxCodicon(
|
|
211
|
+
'pinned',
|
|
212
|
+
'ui-editor-tabs__status-icon',
|
|
213
|
+
'ui-editor-tabs__status-icon--pinned',
|
|
214
|
+
)}
|
|
215
|
+
/>
|
|
216
|
+
)
|
|
217
|
+
) : null}
|
|
218
|
+
{(tab.closable ?? true) && onClose ? (
|
|
219
|
+
<IconButton
|
|
220
|
+
compact
|
|
221
|
+
className="ui-editor-tabs__close"
|
|
222
|
+
icon="codicon-close"
|
|
223
|
+
label="Close tab"
|
|
224
|
+
onClick={(event) => {
|
|
225
|
+
event.stopPropagation();
|
|
226
|
+
onClose(tab.id);
|
|
227
|
+
}}
|
|
228
|
+
/>
|
|
229
|
+
) : null}
|
|
230
|
+
</div>
|
|
231
|
+
);
|
|
232
|
+
})}
|
|
233
|
+
</div>
|
|
234
|
+
{onNewTab ? (
|
|
235
|
+
<IconButton
|
|
236
|
+
compact
|
|
237
|
+
className="ui-editor-tabs__new"
|
|
238
|
+
icon="codicon-add"
|
|
239
|
+
label="New tab"
|
|
240
|
+
onClick={onNewTab}
|
|
241
|
+
/>
|
|
242
|
+
) : null}
|
|
243
|
+
{addons ? <div className="ui-editor-tabs__addons">{addons}</div> : null}
|
|
244
|
+
</div>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export interface ResizablePanelsProps extends ComponentPropsWithRef<'div'> {
|
|
249
|
+
defaultFirstSize?: number | undefined;
|
|
250
|
+
defaultSize?: number | undefined;
|
|
251
|
+
direction?: 'horizontal' | 'vertical' | undefined;
|
|
252
|
+
first: ReactNode;
|
|
253
|
+
maxFirstSize?: number | undefined;
|
|
254
|
+
maxSize?: number | undefined;
|
|
255
|
+
minFirstSize?: number | undefined;
|
|
256
|
+
minSecondSize?: number | undefined;
|
|
257
|
+
minSize?: number | undefined;
|
|
258
|
+
second: ReactNode;
|
|
259
|
+
separatorLabel?: string | undefined;
|
|
260
|
+
sizedPanel?: 'first' | 'second' | undefined;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function clampPanelSize(
|
|
264
|
+
value: number,
|
|
265
|
+
containerSize: number,
|
|
266
|
+
minFirstSize: number,
|
|
267
|
+
minSecondSize: number,
|
|
268
|
+
maxFirstSize?: number,
|
|
269
|
+
) {
|
|
270
|
+
const upperBySecond = Math.max(minFirstSize, containerSize - minSecondSize);
|
|
271
|
+
const upper = maxFirstSize === undefined ? upperBySecond : Math.min(maxFirstSize, upperBySecond);
|
|
272
|
+
return Math.min(Math.max(value, minFirstSize), upper);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function ResizablePanels({
|
|
276
|
+
className,
|
|
277
|
+
defaultFirstSize = 240,
|
|
278
|
+
defaultSize,
|
|
279
|
+
direction = 'horizontal',
|
|
280
|
+
first,
|
|
281
|
+
maxFirstSize,
|
|
282
|
+
maxSize,
|
|
283
|
+
minFirstSize = 160,
|
|
284
|
+
minSecondSize = 220,
|
|
285
|
+
minSize,
|
|
286
|
+
second,
|
|
287
|
+
separatorLabel = 'Resize panel',
|
|
288
|
+
sizedPanel = 'first',
|
|
289
|
+
style,
|
|
290
|
+
...props
|
|
291
|
+
}: ResizablePanelsProps) {
|
|
292
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
293
|
+
const [panelSize, setPanelSize] = useState(defaultSize ?? defaultFirstSize);
|
|
294
|
+
const isHorizontal = direction === 'horizontal';
|
|
295
|
+
const resolvedMinSize = minSize ?? minFirstSize;
|
|
296
|
+
const resolvedMaxSize = maxSize ?? maxFirstSize;
|
|
297
|
+
|
|
298
|
+
const updateByDelta = (delta: number) => {
|
|
299
|
+
const rect = rootRef.current?.getBoundingClientRect();
|
|
300
|
+
if (!rect) return;
|
|
301
|
+
const containerSize = isHorizontal ? rect.width : rect.height;
|
|
302
|
+
const sizedDelta = sizedPanel === 'first' ? delta : -delta;
|
|
303
|
+
setPanelSize((current) =>
|
|
304
|
+
clampPanelSize(
|
|
305
|
+
current + sizedDelta,
|
|
306
|
+
containerSize,
|
|
307
|
+
resolvedMinSize,
|
|
308
|
+
minSecondSize,
|
|
309
|
+
resolvedMaxSize,
|
|
310
|
+
),
|
|
311
|
+
);
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
const handlePointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {
|
|
315
|
+
event.preventDefault();
|
|
316
|
+
|
|
317
|
+
const rect = rootRef.current?.getBoundingClientRect();
|
|
318
|
+
if (!rect) return;
|
|
319
|
+
|
|
320
|
+
const containerSize = isHorizontal ? rect.width : rect.height;
|
|
321
|
+
const origin = isHorizontal ? event.clientX : event.clientY;
|
|
322
|
+
const startSize = panelSize;
|
|
323
|
+
const pointerId = event.pointerId;
|
|
324
|
+
event.currentTarget.setPointerCapture(pointerId);
|
|
325
|
+
|
|
326
|
+
const handlePointerMove = (moveEvent: PointerEvent) => {
|
|
327
|
+
const position = isHorizontal ? moveEvent.clientX : moveEvent.clientY;
|
|
328
|
+
const delta = sizedPanel === 'first' ? position - origin : origin - position;
|
|
329
|
+
setPanelSize(
|
|
330
|
+
clampPanelSize(
|
|
331
|
+
startSize + delta,
|
|
332
|
+
containerSize,
|
|
333
|
+
resolvedMinSize,
|
|
334
|
+
minSecondSize,
|
|
335
|
+
resolvedMaxSize,
|
|
336
|
+
),
|
|
337
|
+
);
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const handlePointerUp = () => {
|
|
341
|
+
window.removeEventListener('pointermove', handlePointerMove);
|
|
342
|
+
window.removeEventListener('pointerup', handlePointerUp);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
window.addEventListener('pointermove', handlePointerMove);
|
|
346
|
+
window.addEventListener('pointerup', handlePointerUp, { once: true });
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const handleKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {
|
|
350
|
+
const largeStep = event.shiftKey ? 40 : 10;
|
|
351
|
+
const negativeKeys = isHorizontal ? ['ArrowLeft'] : ['ArrowUp'];
|
|
352
|
+
const positiveKeys = isHorizontal ? ['ArrowRight'] : ['ArrowDown'];
|
|
353
|
+
|
|
354
|
+
if (negativeKeys.includes(event.key)) {
|
|
355
|
+
event.preventDefault();
|
|
356
|
+
updateByDelta(-largeStep);
|
|
357
|
+
}
|
|
358
|
+
if (positiveKeys.includes(event.key)) {
|
|
359
|
+
event.preventDefault();
|
|
360
|
+
updateByDelta(largeStep);
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
return (
|
|
365
|
+
<div
|
|
366
|
+
{...props}
|
|
367
|
+
ref={rootRef}
|
|
368
|
+
className={cx(
|
|
369
|
+
'ui-resizable-panels',
|
|
370
|
+
!isHorizontal && 'ui-resizable-panels--vertical',
|
|
371
|
+
className,
|
|
372
|
+
)}
|
|
373
|
+
data-sized-panel={sizedPanel}
|
|
374
|
+
style={
|
|
375
|
+
{
|
|
376
|
+
'--ui-resizable-panels-size': `${panelSize}px`,
|
|
377
|
+
...style,
|
|
378
|
+
} as CSSProperties
|
|
379
|
+
}
|
|
380
|
+
>
|
|
381
|
+
<div className="ui-resizable-panels__pane">{first}</div>
|
|
382
|
+
<div
|
|
383
|
+
aria-label={separatorLabel}
|
|
384
|
+
aria-orientation={isHorizontal ? 'vertical' : 'horizontal'}
|
|
385
|
+
className="ui-resizable-panels__separator"
|
|
386
|
+
onKeyDown={handleKeyDown}
|
|
387
|
+
onPointerDown={handlePointerDown}
|
|
388
|
+
role="separator"
|
|
389
|
+
tabIndex={0}
|
|
390
|
+
/>
|
|
391
|
+
<div className="ui-resizable-panels__pane">{second}</div>
|
|
392
|
+
</div>
|
|
393
|
+
);
|
|
394
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export { AbsoluteBox } from './AbsoluteBox';
|
|
2
|
+
export type { AbsoluteBoxProps, WorkbenchRect } from './AbsoluteBox';
|
|
3
|
+
export { Badge } from './Badge';
|
|
4
|
+
export type { BadgeProps } from './Badge';
|
|
5
|
+
export { Button } from './Button';
|
|
6
|
+
export type { ButtonProps } from './Button';
|
|
7
|
+
export { Checkbox } from './Checkbox';
|
|
8
|
+
export type { CheckboxProps } from './Checkbox';
|
|
9
|
+
export { EmptyState } from './EmptyState';
|
|
10
|
+
export type { EmptyStateProps } from './EmptyState';
|
|
11
|
+
export { Field } from './Field';
|
|
12
|
+
export type { FieldProps } from './Field';
|
|
13
|
+
export { IconButton } from './IconButton';
|
|
14
|
+
export type { IconButtonProps } from './IconButton';
|
|
15
|
+
export { List, ListEmptyState, ListItem, ListItemActionButton } from './List';
|
|
16
|
+
export type {
|
|
17
|
+
ListEmptyStateProps,
|
|
18
|
+
ListItemActionButtonProps,
|
|
19
|
+
ListItemProps,
|
|
20
|
+
ListProps,
|
|
21
|
+
} from './List';
|
|
22
|
+
export { NumberInput } from './NumberInput';
|
|
23
|
+
export type { NumberInputProps } from './NumberInput';
|
|
24
|
+
export { Select } from './Select';
|
|
25
|
+
export type { SelectProps } from './Select';
|
|
26
|
+
export { ScrollArea } from './ScrollArea';
|
|
27
|
+
export type {
|
|
28
|
+
ScrollAreaGutter,
|
|
29
|
+
ScrollAreaOrientation,
|
|
30
|
+
ScrollAreaProps,
|
|
31
|
+
ScrollAreaScrollbarVisibility,
|
|
32
|
+
} from './ScrollArea';
|
|
33
|
+
export { StatusBar, StatusBarLabel, StatusBarSection } from './StatusBar';
|
|
34
|
+
export type {
|
|
35
|
+
StatusBarLabelProps,
|
|
36
|
+
StatusBarProps,
|
|
37
|
+
StatusBarSectionAlign,
|
|
38
|
+
StatusBarSectionProps,
|
|
39
|
+
StatusBarSeverity,
|
|
40
|
+
} from './StatusBar';
|
|
41
|
+
export { TextInput } from './TextInput';
|
|
42
|
+
export type { ControlWidth, TextInputProps } from './TextInput';
|
|
43
|
+
export { TextArea } from './TextArea';
|
|
44
|
+
export type { TextAreaProps } from './TextArea';
|
|
45
|
+
export { Toolbar } from './Toolbar';
|
|
46
|
+
export type { ToolbarProps } from './Toolbar';
|
|
47
|
+
export { ActivityBar, Collapsible, SideBar, TabbedPanels, WorkbenchShell } from './WorkbenchChrome';
|
|
48
|
+
export type {
|
|
49
|
+
ActivityBarProps,
|
|
50
|
+
ActivityItem,
|
|
51
|
+
CollapsibleProps,
|
|
52
|
+
SideBarProps,
|
|
53
|
+
TabbedPanelItem,
|
|
54
|
+
TabbedPanelsProps,
|
|
55
|
+
WorkbenchShellProps,
|
|
56
|
+
} from './WorkbenchChrome';
|
|
57
|
+
export { ButtonGroup, EditorTabs, ResizablePanels, SegmentedControl } from './WorkbenchEditor';
|
|
58
|
+
export type {
|
|
59
|
+
ButtonGroupProps,
|
|
60
|
+
EditorTab,
|
|
61
|
+
EditorTabDropPosition,
|
|
62
|
+
EditorTabsProps,
|
|
63
|
+
ResizablePanelsProps,
|
|
64
|
+
SegmentedControlOption,
|
|
65
|
+
SegmentedControlProps,
|
|
66
|
+
} from './WorkbenchEditor';
|
|
67
|
+
export {
|
|
68
|
+
FilterBar,
|
|
69
|
+
FilterBarActiveChips,
|
|
70
|
+
FilterChip,
|
|
71
|
+
HelpText,
|
|
72
|
+
Panel,
|
|
73
|
+
PanelBody,
|
|
74
|
+
PanelFooter,
|
|
75
|
+
PanelHeader,
|
|
76
|
+
} from '../layout/Panel';
|
|
77
|
+
export type {
|
|
78
|
+
FilterBarActiveChipsProps,
|
|
79
|
+
FilterBarProps,
|
|
80
|
+
FilterChipProps,
|
|
81
|
+
HelpTextProps,
|
|
82
|
+
PanelBodyProps,
|
|
83
|
+
PanelFooterProps,
|
|
84
|
+
PanelHeaderProps,
|
|
85
|
+
PanelProps,
|
|
86
|
+
} from '../layout/Panel';
|
|
87
|
+
export {
|
|
88
|
+
WorkbenchParseError,
|
|
89
|
+
WorkbenchPropertyHint,
|
|
90
|
+
WorkbenchPropertyNumberRow,
|
|
91
|
+
WorkbenchPropertyPanel,
|
|
92
|
+
WorkbenchPropertyRow,
|
|
93
|
+
WorkbenchPropertySection,
|
|
94
|
+
WorkbenchPropertyStack,
|
|
95
|
+
WorkbenchPropertyTextRow,
|
|
96
|
+
} from '../layout/WorkbenchPropertyPanel';
|
|
97
|
+
export type {
|
|
98
|
+
WorkbenchParseErrorProps,
|
|
99
|
+
WorkbenchPropertyNumberRowProps,
|
|
100
|
+
WorkbenchPropertyPanelProps,
|
|
101
|
+
WorkbenchPropertyRowProps,
|
|
102
|
+
WorkbenchPropertySectionProps,
|
|
103
|
+
WorkbenchPropertyStackProps,
|
|
104
|
+
WorkbenchPropertyTextRowProps,
|
|
105
|
+
} from '../layout/WorkbenchPropertyPanel';
|