@stll/workspace-ui 0.22.0 → 0.23.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/sorts-face.js +1 -1
- package/dist/view-strip.d.ts +17 -4
- package/dist/view-strip.js +14 -9
- package/dist/view-switcher.d.ts +3 -1
- package/dist/view-switcher.js +91 -8
- package/package.json +2 -2
package/dist/sorts-face.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SORT_CHIP_CLASS, SORT_CHIP_TOGGLE, SORT_DIRECTION_CLASS, SORT_ICON_BUTTON } from "./sort-chip-classes.js";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { ArrowUpDownIcon, XIcon } from "@stll/ui/icons";
|
|
4
3
|
import { ButtonFace, FaceLabelPending } from "@stll/ui/control-face";
|
|
4
|
+
import { ArrowUpDownIcon, XIcon } from "@stll/ui/icons";
|
|
5
5
|
// src/sorts-face.tsx
|
|
6
6
|
/**
|
|
7
7
|
* `SortChips` before the properties are read: one chip per sort, with bars
|
package/dist/view-strip.d.ts
CHANGED
|
@@ -11,18 +11,31 @@ export type WorkspaceViewStripProps = {
|
|
|
11
11
|
/** The strip's reading direction; the document's when left out. */
|
|
12
12
|
direction?: InlineDirection | undefined;
|
|
13
13
|
addControl?: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* Drawn right after the tabs, in the room they share: the menu that holds
|
|
16
|
+
* the views the strip has no room for, and the copy it measures them by.
|
|
17
|
+
*/
|
|
18
|
+
overflowControl?: ReactNode;
|
|
14
19
|
onViewChange?: (viewId: string) => void;
|
|
15
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* The row the tabs and the overflow control share: its width is the room
|
|
22
|
+
* the switcher fits tabs into, and it is the drop target around them.
|
|
23
|
+
*/
|
|
16
24
|
stripRef?: Ref<HTMLDivElement>;
|
|
17
25
|
children: ReactNode;
|
|
18
26
|
};
|
|
19
27
|
/**
|
|
20
|
-
* The saved-view strip without behaviour: one toolbar row of underline tabs
|
|
21
|
-
*
|
|
28
|
+
* The saved-view strip without behaviour: one toolbar row of underline tabs,
|
|
29
|
+
* the overflow menu right after them when some views have no room, and the
|
|
30
|
+
* add control at the row's end. `WorkspaceViewSwitcher` renders its tabs
|
|
22
31
|
* inside it; a loading view renders `WorkspaceViewSwitcherFace` in the same
|
|
23
32
|
* strip, so the row does not move when the switcher takes over.
|
|
33
|
+
*
|
|
34
|
+
* The tabs never scroll: the switcher moves the views that do not fit into
|
|
35
|
+
* the overflow menu, so no divider is needed to set the add control apart
|
|
36
|
+
* from a scrolling strip.
|
|
24
37
|
*/
|
|
25
|
-
export declare const WorkspaceViewStrip: ({ activeViewId, ariaLabel, direction, addControl, onViewChange, stripRef, children }: WorkspaceViewStripProps) => import("react").JSX.Element;
|
|
38
|
+
export declare const WorkspaceViewStrip: ({ activeViewId, ariaLabel, direction, addControl, overflowControl, onViewChange, stripRef, children }: WorkspaceViewStripProps) => import("react").JSX.Element;
|
|
26
39
|
export type WorkspaceViewTabFaceProps = Omit<ComponentProps<typeof TabsTab>, "className"> & {
|
|
27
40
|
/** Room at the end of each tab for the active tab's action menu. */
|
|
28
41
|
reserveActionSpace: boolean;
|
package/dist/view-strip.js
CHANGED
|
@@ -7,20 +7,25 @@ import { cn } from "@stll/ui/utils";
|
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
// src/view-strip.tsx
|
|
9
9
|
/**
|
|
10
|
-
* The saved-view strip without behaviour: one toolbar row of underline tabs
|
|
11
|
-
*
|
|
10
|
+
* The saved-view strip without behaviour: one toolbar row of underline tabs,
|
|
11
|
+
* the overflow menu right after them when some views have no room, and the
|
|
12
|
+
* add control at the row's end. `WorkspaceViewSwitcher` renders its tabs
|
|
12
13
|
* inside it; a loading view renders `WorkspaceViewSwitcherFace` in the same
|
|
13
14
|
* strip, so the row does not move when the switcher takes over.
|
|
15
|
+
*
|
|
16
|
+
* The tabs never scroll: the switcher moves the views that do not fit into
|
|
17
|
+
* the overflow menu, so no divider is needed to set the add control apart
|
|
18
|
+
* from a scrolling strip.
|
|
14
19
|
*/
|
|
15
|
-
const WorkspaceViewStrip = ({ activeViewId, ariaLabel, direction, addControl, onViewChange, stripRef, children }) => /* @__PURE__ */ jsxs("div", {
|
|
20
|
+
const WorkspaceViewStrip = ({ activeViewId, ariaLabel, direction, addControl, overflowControl, onViewChange, stripRef, children }) => /* @__PURE__ */ jsxs("div", {
|
|
16
21
|
className: cn("flex min-w-0 flex-1 items-center gap-1 px-2", TOOLBAR_ROW_HEIGHT),
|
|
17
22
|
"data-slot": "workspace-view-switcher",
|
|
18
23
|
dir: direction,
|
|
19
|
-
children: [/* @__PURE__ */
|
|
20
|
-
className: "h-full min-w-0 flex-1",
|
|
24
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
25
|
+
className: "relative flex h-full min-w-0 flex-1 items-center gap-0.5",
|
|
21
26
|
ref: stripRef,
|
|
22
|
-
children: /* @__PURE__ */ jsx(Tabs, {
|
|
23
|
-
className: "h-full gap-0",
|
|
27
|
+
children: [/* @__PURE__ */ jsx(Tabs, {
|
|
28
|
+
className: "h-full min-w-0 gap-0",
|
|
24
29
|
onValueChange: (value) => {
|
|
25
30
|
if (typeof value === "string") onViewChange?.(value);
|
|
26
31
|
},
|
|
@@ -31,9 +36,9 @@ const WorkspaceViewStrip = ({ activeViewId, ariaLabel, direction, addControl, on
|
|
|
31
36
|
variant: "underline",
|
|
32
37
|
children
|
|
33
38
|
})
|
|
34
|
-
})
|
|
39
|
+
}), overflowControl]
|
|
35
40
|
}), addControl === null || addControl === void 0 ? null : /* @__PURE__ */ jsx("div", {
|
|
36
|
-
className: "
|
|
41
|
+
className: "flex shrink-0 translate-y-1 items-center",
|
|
37
42
|
children: addControl
|
|
38
43
|
})]
|
|
39
44
|
});
|
package/dist/view-switcher.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export type WorkspaceViewSwitcherProps<View extends WorkspaceViewSwitcherItem> =
|
|
|
15
15
|
activeViewId: string;
|
|
16
16
|
ariaLabel: string;
|
|
17
17
|
direction: InlineDirection;
|
|
18
|
+
/** Accessible name of the menu that holds the views with no room. */
|
|
19
|
+
overflowLabel: string;
|
|
18
20
|
reorder: WorkspaceViewSwitcherReorder<View> | null;
|
|
19
21
|
views: readonly View[];
|
|
20
22
|
addControl?: React.ReactNode;
|
|
@@ -29,5 +31,5 @@ export type WorkspaceViewSwitcherProps<View extends WorkspaceViewSwitcherItem> =
|
|
|
29
31
|
};
|
|
30
32
|
renderIcon: (view: View) => React.ReactNode;
|
|
31
33
|
};
|
|
32
|
-
export declare const WorkspaceViewSwitcher: <View extends WorkspaceViewSwitcherItem>({ activeViewId, ariaLabel, direction, reorder, views, addControl, editing, onViewChange, onViewContextMenu, onViewDoubleClick, actionMenu, renderIcon }: WorkspaceViewSwitcherProps<View>) => import("react").JSX.Element;
|
|
34
|
+
export declare const WorkspaceViewSwitcher: <View extends WorkspaceViewSwitcherItem>({ activeViewId, ariaLabel, direction, overflowLabel, reorder, views, addControl, editing, onViewChange, onViewContextMenu, onViewDoubleClick, actionMenu, renderIcon }: WorkspaceViewSwitcherProps<View>) => import("react").JSX.Element;
|
|
33
35
|
export type { WorkspaceViewSwitcherItem };
|
package/dist/view-switcher.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { WorkspaceViewStrip, WorkspaceViewTabFace } from "./view-strip.js";
|
|
2
|
+
import { WorkspaceViewStrip, WorkspaceViewTabFace, WorkspaceViewTabNameFace } from "./view-strip.js";
|
|
3
3
|
import { WorkspaceViewTabName } from "./view-switcher-face.js";
|
|
4
|
-
import {
|
|
4
|
+
import { BidiText } from "@stll/ui/bidi-text";
|
|
5
|
+
import { Tabs, TabsList } from "@stll/ui/tabs";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
7
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
6
8
|
import { attachClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge/attach-closest-edge";
|
|
7
9
|
import { extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge/extract-closest-edge";
|
|
8
10
|
import { draggable, dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/adapter/element-adapter";
|
|
9
11
|
import { combine } from "@atlaskit/pragmatic-drag-and-drop/utils/combine";
|
|
10
12
|
import { Button } from "@stll/ui/button";
|
|
11
|
-
import {
|
|
13
|
+
import { buttonFaceClassName } from "@stll/ui/control-face";
|
|
14
|
+
import { ChevronDownIcon, EllipsisVerticalIcon } from "@stll/ui/icons";
|
|
12
15
|
import { InlineDropIndicator } from "@stll/ui/inline-drop-indicator";
|
|
16
|
+
import { splitInlineOverflow } from "@stll/ui/inline-overflow";
|
|
13
17
|
import { reorderInlineIds, toInlineDropPosition } from "@stll/ui/inline-reorder";
|
|
14
|
-
import { Menu, MenuPopup, MenuTrigger } from "@stll/ui/menu";
|
|
18
|
+
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "@stll/ui/menu";
|
|
19
|
+
import { INLINE_OVERFLOW_ITEM_ATTRIBUTE, INLINE_OVERFLOW_TRIGGER_ATTRIBUTE, useInlineOverflow } from "@stll/ui/use-inline-overflow";
|
|
15
20
|
// src/view-switcher.tsx
|
|
16
21
|
const VIEW_DRAG_TYPE = "@stll/workspace-ui/view-switcher/drag-type";
|
|
17
22
|
const VIEW_DRAG_ID = "@stll/workspace-ui/view-switcher/view-id";
|
|
@@ -23,7 +28,7 @@ const useLatestCallback = (callback) => {
|
|
|
23
28
|
}, [callback]);
|
|
24
29
|
return useCallback((...args) => latest.current(...args), []);
|
|
25
30
|
};
|
|
26
|
-
const WorkspaceViewSwitcher = ({ activeViewId, ariaLabel, direction, reorder, views, addControl, editing, onViewChange, onViewContextMenu, onViewDoubleClick, actionMenu, renderIcon }) => {
|
|
31
|
+
const WorkspaceViewSwitcher = ({ activeViewId, ariaLabel, direction, overflowLabel, reorder, views, addControl, editing, onViewChange, onViewContextMenu, onViewDoubleClick, actionMenu, renderIcon }) => {
|
|
27
32
|
const [openMenuId, setOpenMenuId] = useState(null);
|
|
28
33
|
const canReorder = reorder !== null;
|
|
29
34
|
const viewTabs = views.map((view) => {
|
|
@@ -52,7 +57,13 @@ const WorkspaceViewSwitcher = ({ activeViewId, ariaLabel, direction, reorder, vi
|
|
|
52
57
|
});
|
|
53
58
|
const reserveActionSpace = viewTabs.some(({ actions }) => actions !== null);
|
|
54
59
|
const [instanceId] = useState(Symbol);
|
|
55
|
-
const
|
|
60
|
+
const pinnedViewId = editing?.viewId ?? activeViewId;
|
|
61
|
+
const pinnedIndex = views.findIndex((view) => view.id === pinnedViewId);
|
|
62
|
+
const { container: stripContainer, containerRef, measured, measureRef, visibleCount } = useInlineOverflow({
|
|
63
|
+
activeIndex: pinnedIndex,
|
|
64
|
+
itemKeys: views.map((view) => view.id)
|
|
65
|
+
});
|
|
66
|
+
const { visible: visibleTabs, overflow: overflowTabs } = splitInlineOverflow(viewTabs, visibleCount, pinnedIndex);
|
|
56
67
|
useEffect(() => {
|
|
57
68
|
if (!stripContainer || !canReorder) return;
|
|
58
69
|
return dropTargetForElements({
|
|
@@ -79,8 +90,38 @@ const WorkspaceViewSwitcher = ({ activeViewId, ariaLabel, direction, reorder, vi
|
|
|
79
90
|
ariaLabel,
|
|
80
91
|
direction,
|
|
81
92
|
onViewChange,
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
overflowControl: /* @__PURE__ */ jsxs(Fragment, { children: [overflowTabs.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
94
|
+
className: "flex shrink-0 translate-y-1 items-center",
|
|
95
|
+
children: /* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(MenuTrigger, {
|
|
96
|
+
"aria-label": overflowLabel,
|
|
97
|
+
"data-slot": "workspace-view-overflow-trigger",
|
|
98
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
99
|
+
size: "icon-xs",
|
|
100
|
+
variant: "ghost"
|
|
101
|
+
}),
|
|
102
|
+
children: /* @__PURE__ */ jsx(ChevronDownIcon, {})
|
|
103
|
+
}), /* @__PURE__ */ jsx(MenuPopup, {
|
|
104
|
+
align: "end",
|
|
105
|
+
children: overflowTabs.map(({ view }) => /* @__PURE__ */ jsxs(MenuItem, {
|
|
106
|
+
"aria-current": view.id === activeViewId ? "page" : void 0,
|
|
107
|
+
"data-view-overflow-item": view.id,
|
|
108
|
+
onClick: () => onViewChange(view.id),
|
|
109
|
+
children: [renderIcon(view), /* @__PURE__ */ jsx(BidiText, {
|
|
110
|
+
as: "span",
|
|
111
|
+
children: view.name
|
|
112
|
+
})]
|
|
113
|
+
}, view.id))
|
|
114
|
+
})] })
|
|
115
|
+
}), /* @__PURE__ */ jsx(WorkspaceViewTabsMeasure, {
|
|
116
|
+
activeViewId,
|
|
117
|
+
measured,
|
|
118
|
+
measureRef,
|
|
119
|
+
renderIcon,
|
|
120
|
+
reserveActionSpace,
|
|
121
|
+
views
|
|
122
|
+
})] }),
|
|
123
|
+
stripRef: containerRef,
|
|
124
|
+
children: visibleTabs.map(({ view, actions }) => {
|
|
84
125
|
if (editing?.viewId === view.id) return /* @__PURE__ */ jsxs(WorkspaceViewTabFace, {
|
|
85
126
|
nativeButton: false,
|
|
86
127
|
render: /* @__PURE__ */ jsx("div", {}),
|
|
@@ -106,6 +147,48 @@ const WorkspaceViewSwitcher = ({ activeViewId, ariaLabel, direction, reorder, vi
|
|
|
106
147
|
})
|
|
107
148
|
});
|
|
108
149
|
};
|
|
150
|
+
/**
|
|
151
|
+
* Every view's tab at its natural width, plus the overflow trigger, drawn
|
|
152
|
+
* invisibly and out of reach for `useInlineOverflow` to measure. The tabs are
|
|
153
|
+
* the strip's own tab faces in a tab list of their own, so a copy is as wide
|
|
154
|
+
* as the tab it stands for. The clipping box keeps the copy from widening
|
|
155
|
+
* anything that scrolls around the strip.
|
|
156
|
+
*/
|
|
157
|
+
const WorkspaceViewTabsMeasure = ({ activeViewId, measured, measureRef, renderIcon, reserveActionSpace, views }) => /* @__PURE__ */ jsx("div", {
|
|
158
|
+
"aria-hidden": "true",
|
|
159
|
+
className: "pointer-events-none invisible absolute start-0 top-0 size-0 overflow-hidden",
|
|
160
|
+
"data-measured": measured ? "" : void 0,
|
|
161
|
+
"data-slot": "workspace-view-measure",
|
|
162
|
+
inert: true,
|
|
163
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
164
|
+
className: "flex w-max items-center gap-0.5",
|
|
165
|
+
ref: measureRef,
|
|
166
|
+
children: [/* @__PURE__ */ jsx(Tabs, {
|
|
167
|
+
className: "h-full gap-0",
|
|
168
|
+
value: activeViewId,
|
|
169
|
+
children: /* @__PURE__ */ jsx(TabsList, {
|
|
170
|
+
className: "h-full data-[orientation=horizontal]:py-0",
|
|
171
|
+
variant: "underline",
|
|
172
|
+
children: views.map((view) => /* @__PURE__ */ jsx("div", {
|
|
173
|
+
className: "relative flex h-full items-center",
|
|
174
|
+
[INLINE_OVERFLOW_ITEM_ATTRIBUTE]: view.id,
|
|
175
|
+
children: /* @__PURE__ */ jsxs(WorkspaceViewTabFace, {
|
|
176
|
+
reserveActionSpace,
|
|
177
|
+
value: view.id,
|
|
178
|
+
children: [renderIcon(view), /* @__PURE__ */ jsx(WorkspaceViewTabNameFace, { name: view.name })]
|
|
179
|
+
})
|
|
180
|
+
}, view.id))
|
|
181
|
+
})
|
|
182
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
183
|
+
className: buttonFaceClassName({
|
|
184
|
+
size: "icon-xs",
|
|
185
|
+
variant: "ghost"
|
|
186
|
+
}),
|
|
187
|
+
[INLINE_OVERFLOW_TRIGGER_ATTRIBUTE]: "",
|
|
188
|
+
children: /* @__PURE__ */ jsx(ChevronDownIcon, {})
|
|
189
|
+
})]
|
|
190
|
+
})
|
|
191
|
+
});
|
|
109
192
|
const WorkspaceViewTab = ({ actions, canReorder, direction, getDragData, getDropData, isDragBlocked, instanceId, onContextMenu, onDoubleClick, onReorder, renderIcon, reserveActionSpace, view }) => {
|
|
110
193
|
const [tabContainer, setTabContainer] = useState(null);
|
|
111
194
|
const [dropPosition, setDropPosition] = useState(null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stll/workspace-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Reusable workspace presentation components and view helpers for Stella.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"calculations",
|
|
@@ -142,7 +142,7 @@
|
|
|
142
142
|
"@stll/calculations": "^0.1.5",
|
|
143
143
|
"@stll/conditions": "^0.4.1",
|
|
144
144
|
"@stll/money": "^0.4.0",
|
|
145
|
-
"@stll/ui": "^0.
|
|
145
|
+
"@stll/ui": "^0.81.0",
|
|
146
146
|
"better-result": "3.0.1",
|
|
147
147
|
"temporal-polyfill": "1.0.8",
|
|
148
148
|
"use-intl": "4.15.1"
|