@stll/workspace-ui 0.21.2 → 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.
@@ -11,6 +11,8 @@ export type ConditionBuilderLabels = {
11
11
  addCondition: string;
12
12
  /** "+ Add group". */
13
13
  addGroup: string;
14
+ noFields: string;
15
+ groupFull: string;
14
16
  /** Leads the first row: "When". */
15
17
  when: string;
16
18
  /** Accessible name of the and/or select. */
@@ -45,7 +45,10 @@ const ConditionBuilderTree = ({ value, onChange, capabilities }) => {
45
45
  const { fields, allowNesting = false, maxChildren } = capabilities;
46
46
  const firstField = fields.at(0);
47
47
  const atChildCap = maxChildren !== void 0 && group.children.length >= maxChildren;
48
- const canAdd = firstField !== void 0 && !atChildCap;
48
+ const addDisabledReason = (() => {
49
+ if (firstField === void 0) return labels.noFields;
50
+ return atChildCap ? labels.groupFull : void 0;
51
+ })();
49
52
  return /* @__PURE__ */ jsxs("div", {
50
53
  className: "flex flex-col gap-2",
51
54
  children: [/* @__PURE__ */ jsx("div", {
@@ -80,7 +83,8 @@ const ConditionBuilderTree = ({ value, onChange, capabilities }) => {
80
83
  className: "ms-[5.375rem] flex flex-wrap gap-1",
81
84
  children: [/* @__PURE__ */ jsxs(Button, {
82
85
  className: "w-fit justify-start",
83
- disabled: !canAdd,
86
+ disabled: addDisabledReason !== void 0,
87
+ disabledReason: addDisabledReason,
84
88
  onClick: () => {
85
89
  if (firstField && !atChildCap) onChange(appendChild(group, leafFromField(firstField)));
86
90
  },
@@ -90,7 +94,8 @@ const ConditionBuilderTree = ({ value, onChange, capabilities }) => {
90
94
  children: [/* @__PURE__ */ jsx(PlusIcon, {}), labels.addCondition]
91
95
  }), allowNesting && /* @__PURE__ */ jsxs(Button, {
92
96
  className: "w-fit justify-start",
93
- disabled: !canAdd,
97
+ disabled: addDisabledReason !== void 0,
98
+ disabledReason: addDisabledReason,
94
99
  onClick: () => {
95
100
  if (firstField && !atChildCap) onChange(appendChild(group, {
96
101
  type: "group",
@@ -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
@@ -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
- /** The element that holds the tabs, for a drop target around them. */
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
- * and, after them, the add control. `WorkspaceViewSwitcher` renders its tabs
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;
@@ -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
- * and, after them, the add control. `WorkspaceViewSwitcher` renders its tabs
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__ */ jsx("div", {
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: "border-border flex shrink-0 translate-y-1 items-center border-s ps-1",
41
+ className: "flex shrink-0 translate-y-1 items-center",
37
42
  children: addControl
38
43
  })]
39
44
  });
@@ -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 };
@@ -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 { jsx, jsxs } from "react/jsx-runtime";
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 { EllipsisVerticalIcon } from "@stll/ui/icons";
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 [stripContainer, setStripContainer] = useState(null);
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
- stripRef: setStripContainer,
83
- children: viewTabs.map(({ view, actions }) => {
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.21.2",
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.79.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"