@seanyeh77/ui 0.29.0 → 0.30.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.
package/dist/index.d.ts CHANGED
@@ -1873,6 +1873,11 @@ interface WorkbenchProps {
1873
1873
  /** Accessible name of the whole layout. Default 「編輯器」. */
1874
1874
  label?: string;
1875
1875
  className?: string;
1876
+ /** Called with the layout on the first render and after every change (a tab picked or moved, a region opened or
1877
+ * closed, a size changed), for example to put the panel's current tab in the URL. */
1878
+ onLayoutChange?: (layout: WorkbenchLayout) => void;
1879
+ /** show, toggle, resetLayout and getLayout from outside, such as URL handling in the page around the Workbench. */
1880
+ ref?: React.Ref<WorkbenchHandle>;
1876
1881
  }
1877
1882
  interface WorkbenchApi {
1878
1883
  /** Back to defaultLayout: places, open regions and sizes. */
@@ -1884,10 +1889,20 @@ interface WorkbenchApi {
1884
1889
  explorerPicked: () => void;
1885
1890
  /** Phones (below 600 px). */
1886
1891
  phone: boolean;
1887
- }
1892
+ /** Opens a view where it is: makes it the current tab of its region and opens the region (laid over the main view
1893
+ * on narrow screens; the merged panel on phones). Does not move the view. Unknown ids are ignored. */
1894
+ show: (viewId: string) => void;
1895
+ /** The current layout: where each view sits, the current tab of each region, what is open, sizes. */
1896
+ layout: WorkbenchLayout;
1897
+ }
1898
+ /** The same calls from outside the Workbench, through `ref`. */
1899
+ type WorkbenchHandle = Omit<WorkbenchApi, 'layout'> & {
1900
+ /** The current layout at the time of the call. */
1901
+ getLayout: () => WorkbenchLayout;
1902
+ };
1888
1903
  /** For anything rendered inside a Workbench (actions, explorer, views). */
1889
1904
  export declare function useWorkbench(): WorkbenchApi;
1890
1905
  /** An editor layout like VS Code: top bar, file explorer, main view, side bar and bottom panel, with resizable borders,
1891
1906
  * views that move between the side bar and the panel, Ctrl B / Ctrl J / Ctrl Alt B, and a remembered layout. */
1892
- export declare function Workbench(p: WorkbenchProps): React.JSX.Element;
1893
- export { type AccentPickerProps, type ActionBarAction, type ActionBarProps, type AiMarkProps, type AlertProps, type AlertTone, type AppShellProps, type BadgeProps, type BadgeStatus, type BarChartProps, type BarDatum, type BreadcrumbItem, type BreadcrumbProps, type ButtonProps, type CalendarProps, type CardProps, type CheckboxProps, type CodeLanguage, type CodeLink, type CodeTextProps, type CodeViewHandle, type CodeViewProps, type CommandPaletteProps, type CountUnit, type CustomIcon, type DangerConfirm, type DangerZoneProps, type DataTableColumn, type DataTableFilter, type DataTableProps, type DataTableView, type DatePickerProps, type DateRange, type DateRangePickerProps, type DayState, type Decimals, type DetailListItem, type DetailListProps, type DialogProps, type DrawerProps, type EmptyStateProps, type ErrorPageProps, type FileUploadProps, type FilterOption, type FilterValue, type FormGridProps, type GraphLegendItem, type GraphLegendProps, type GridProps, type IconButtonHint, type IconButtonProps, type IconName, type IconProps, type IconSource, type InlineCodeProps, type KpiCardProps, type LayerGraphEdge, type LayerGraphNode, type LayerGraphProps, type LineChartProps, type LineSeries, type LoadingBarProps, type LoginCardProps, type MarkdownProps, type MenuItem, type MenuProps, type MobileTab, type MobileTabBarProps, type MultiSelectOption, type MultiSelectProps, type NavBrand, type NavItem, type NavSection, type NotificationBellProps, type NotificationItem, type OnRef, type PageProps, type PaletteItem, type PopoverProps, type ProgressBarProps, type ProgressRingProps, type ProjectOption, type ProjectStatus, type ProjectSwitcherProps, type RadioGroupProps, type RadioOption, type RangeValue, type RefHref, type Row, type RowKey, type SearchFieldProps, type SectionGroupProps, type SectionGroupToggleProps, type SectionProps, type SelectOption, type SelectProps, type SettingsCategory, type SettingsLayoutProps, type SettingsSectionProps, type SideNavProps, type SkeletonProps, type SplitPaneProps, type SuggestionProps, type SwitchProps, type TabItem, type TabsProps, type TagProps, type TermProps, type TextAreaProps, type TextFieldProps, type ThemePickerProps, type ThemeSetting, type ToastProps, type Token, type TokenClass, type Tokenizer, type TooltipProps, type TopBarProps, type Total, type TourProps, type TourStep, type TreeListProps, type TreeMark, type TreeNode, type UploadFile, type WorkbenchApi, type WorkbenchLayout, type WorkbenchProps, type WorkbenchRegion, type WorkbenchView, addMessages, format, setLocale, tr as t };
1907
+ export declare function Workbench({ ref, ...p }: WorkbenchProps): React.JSX.Element;
1908
+ export { type AccentPickerProps, type ActionBarAction, type ActionBarProps, type AiMarkProps, type AlertProps, type AlertTone, type AppShellProps, type BadgeProps, type BadgeStatus, type BarChartProps, type BarDatum, type BreadcrumbItem, type BreadcrumbProps, type ButtonProps, type CalendarProps, type CardProps, type CheckboxProps, type CodeLanguage, type CodeLink, type CodeTextProps, type CodeViewHandle, type CodeViewProps, type CommandPaletteProps, type CountUnit, type CustomIcon, type DangerConfirm, type DangerZoneProps, type DataTableColumn, type DataTableFilter, type DataTableProps, type DataTableView, type DatePickerProps, type DateRange, type DateRangePickerProps, type DayState, type Decimals, type DetailListItem, type DetailListProps, type DialogProps, type DrawerProps, type EmptyStateProps, type ErrorPageProps, type FileUploadProps, type FilterOption, type FilterValue, type FormGridProps, type GraphLegendItem, type GraphLegendProps, type GridProps, type IconButtonHint, type IconButtonProps, type IconName, type IconProps, type IconSource, type InlineCodeProps, type KpiCardProps, type LayerGraphEdge, type LayerGraphNode, type LayerGraphProps, type LineChartProps, type LineSeries, type LoadingBarProps, type LoginCardProps, type MarkdownProps, type MenuItem, type MenuProps, type MobileTab, type MobileTabBarProps, type MultiSelectOption, type MultiSelectProps, type NavBrand, type NavItem, type NavSection, type NotificationBellProps, type NotificationItem, type OnRef, type PageProps, type PaletteItem, type PopoverProps, type ProgressBarProps, type ProgressRingProps, type ProjectOption, type ProjectStatus, type ProjectSwitcherProps, type RadioGroupProps, type RadioOption, type RangeValue, type RefHref, type Row, type RowKey, type SearchFieldProps, type SectionGroupProps, type SectionGroupToggleProps, type SectionProps, type SelectOption, type SelectProps, type SettingsCategory, type SettingsLayoutProps, type SettingsSectionProps, type SideNavProps, type SkeletonProps, type SplitPaneProps, type SuggestionProps, type SwitchProps, type TabItem, type TabsProps, type TagProps, type TermProps, type TextAreaProps, type TextFieldProps, type ThemePickerProps, type ThemeSetting, type ToastProps, type Token, type TokenClass, type Tokenizer, type TooltipProps, type TopBarProps, type Total, type TourProps, type TourStep, type TreeListProps, type TreeMark, type TreeNode, type UploadFile, type WorkbenchApi, type WorkbenchHandle, type WorkbenchLayout, type WorkbenchProps, type WorkbenchRegion, type WorkbenchView, addMessages, format, setLocale, tr as t };
package/dist/index.js CHANGED
@@ -10876,7 +10876,7 @@ function Pane({ view, onSwipe }) {
10876
10876
  }
10877
10877
  /** An editor layout like VS Code: top bar, file explorer, main view, side bar and bottom panel, with resizable borders,
10878
10878
  * views that move between the side bar and the panel, Ctrl B / Ctrl J / Ctrl Alt B, and a remembered layout. */
10879
- function Workbench(p) {
10879
+ function Workbench({ ref, ...p }) {
10880
10880
  const views = React.useMemo(() => p.views ?? [], [p.views]);
10881
10881
  const byId = React.useMemo(() => Object.fromEntries(views.map((v) => [v.id, v])), [views]);
10882
10882
  const key = "ui-workbench:" + p.id;
@@ -10903,6 +10903,10 @@ function Workbench(p) {
10903
10903
  React.useEffect(() => {
10904
10904
  store(key, JSON.stringify(lay));
10905
10905
  }, [key, lay]);
10906
+ const onLayoutChange = p.onLayoutChange;
10907
+ React.useEffect(() => {
10908
+ onLayoutChange?.(lay);
10909
+ }, [lay]);
10906
10910
  const [ov, setOv] = React.useState({
10907
10911
  explorer: false,
10908
10912
  side: false
@@ -11055,6 +11059,31 @@ function Workbench(p) {
11055
11059
  setSheet({ open: false });
11056
11060
  setSheetH(null);
11057
11061
  };
11062
+ const show = (viewId) => {
11063
+ const r = lay.side.includes(viewId) ? "side" : lay.panel.includes(viewId) ? "panel" : null;
11064
+ devWarn(!r, "Workbench", `show('${viewId}'): no view has this id. Pass the id of one of the views.`);
11065
+ if (!r) return;
11066
+ const remember = !phone && !(r === "side" && sideOverlay);
11067
+ update((l) => ({
11068
+ ...l,
11069
+ active: {
11070
+ ...l.active,
11071
+ [r]: viewId
11072
+ },
11073
+ open: remember ? {
11074
+ ...l.open,
11075
+ [r]: true
11076
+ } : l.open
11077
+ }));
11078
+ if (phone) setSheet({
11079
+ open: true,
11080
+ act: viewId
11081
+ });
11082
+ else if (r === "side" && sideOverlay) setOv((o) => ({
11083
+ ...o,
11084
+ side: true
11085
+ }));
11086
+ };
11058
11087
  const api = {
11059
11088
  resetLayout,
11060
11089
  toggle,
@@ -11064,8 +11093,24 @@ function Workbench(p) {
11064
11093
  explorer: false
11065
11094
  }));
11066
11095
  },
11067
- phone
11096
+ phone,
11097
+ show,
11098
+ layout: lay
11068
11099
  };
11100
+ const latest = React.useRef(api);
11101
+ React.useLayoutEffect(() => {
11102
+ latest.current = api;
11103
+ });
11104
+ React.useImperativeHandle(ref, () => ({
11105
+ show: (id) => latest.current.show(id),
11106
+ toggle: (r) => latest.current.toggle(r),
11107
+ resetLayout: () => latest.current.resetLayout(),
11108
+ explorerPicked: () => latest.current.explorerPicked(),
11109
+ get phone() {
11110
+ return latest.current.phone;
11111
+ },
11112
+ getLayout: () => latest.current.layout
11113
+ }), []);
11069
11114
  const regionName = {
11070
11115
  explorer: tr("檔案總管"),
11071
11116
  side: tr("右側欄"),
@@ -11170,10 +11215,20 @@ function Workbench(p) {
11170
11215
  })] }) : null;
11171
11216
  const sheetAct = sheet.act && merged.includes(sheet.act) ? sheet.act : merged[0];
11172
11217
  const sheetIdx = merged.indexOf(sheetAct ?? "");
11173
- const pickSheet = (id) => setSheet((s) => ({
11174
- ...s,
11175
- act: id
11176
- }));
11218
+ const pickSheet = (id) => {
11219
+ setSheet((s) => ({
11220
+ ...s,
11221
+ act: id
11222
+ }));
11223
+ const r = lay.side.includes(id) ? "side" : "panel";
11224
+ update((l) => ({
11225
+ ...l,
11226
+ active: {
11227
+ ...l.active,
11228
+ [r]: id
11229
+ }
11230
+ }));
11231
+ };
11177
11232
  const reorderMerged = (next) => {
11178
11233
  const nSide = lay.side.length;
11179
11234
  update((l) => ({