@stll/ui 0.81.0 → 0.81.1

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.
@@ -18,8 +18,10 @@ type UseInlineOverflowOptions = {
18
18
  * Measures a single-line row and decides how many of its items fit, by
19
19
  * `resolveInlineOverflow`. The caller renders two things:
20
20
  *
21
- * - the row (`containerRef`), whose content box is the room the items and
22
- * the overflow trigger share, independent of how many items it shows;
21
+ * - the row (`containerRef`), whose box is the room the items and the
22
+ * overflow trigger share, independent of how many items it shows. It
23
+ * carries no inline padding or border of its own (an inset belongs on a
24
+ * wrapper), so its client rect is that room, in the copies' own units;
23
25
  * - an invisible, inert copy of every item at its natural width plus the
24
26
  * trigger (`measureRef`), each marked with `INLINE_OVERFLOW_ITEM_ATTRIBUTE`
25
27
  * (set to the item's key) or `INLINE_OVERFLOW_TRIGGER_ATTRIBUTE`, inside
@@ -31,9 +33,12 @@ type UseInlineOverflowOptions = {
31
33
  * and the count is recomputed whenever either element resizes (a docked
32
34
  * pane narrows the row, an added view or a rename widens the copy), the
33
35
  * active item changes, or the items change order: swapping two items keeps
34
- * the measuring row's size, which no observer reports. The first count
35
- * arrives with the observer's first report, before the row paints; until
36
- * then every item shows.
36
+ * the measuring row's size, which no observer reports.
37
+ *
38
+ * The first count is taken in a layout effect, in the same task that commits
39
+ * the row: a `ResizeObserver` reports only at the browser's next rendering
40
+ * update, and until that count lands the row would hold every item, the last
41
+ * ones clipped, for a paint or any script that reads the layout to see.
37
42
  */
38
43
  export declare const useInlineOverflow: ({ activeIndex, itemKeys }: UseInlineOverflowOptions) => {
39
44
  /** The measured row, once mounted. */
@@ -1,5 +1,5 @@
1
1
  import { resolveInlineOverflow } from "../lib/inline-overflow.js";
2
- import { useEffect, useState } from "react";
2
+ import { useLayoutEffect, useState } from "react";
3
3
  // src/hooks/use-inline-overflow.ts
4
4
  /**
5
5
  * Marks one item's natural-width copy inside the measuring row; its value is
@@ -23,8 +23,10 @@ const itemGap = (items) => {
23
23
  * Measures a single-line row and decides how many of its items fit, by
24
24
  * `resolveInlineOverflow`. The caller renders two things:
25
25
  *
26
- * - the row (`containerRef`), whose content box is the room the items and
27
- * the overflow trigger share, independent of how many items it shows;
26
+ * - the row (`containerRef`), whose box is the room the items and the
27
+ * overflow trigger share, independent of how many items it shows. It
28
+ * carries no inline padding or border of its own (an inset belongs on a
29
+ * wrapper), so its client rect is that room, in the copies' own units;
28
30
  * - an invisible, inert copy of every item at its natural width plus the
29
31
  * trigger (`measureRef`), each marked with `INLINE_OVERFLOW_ITEM_ATTRIBUTE`
30
32
  * (set to the item's key) or `INLINE_OVERFLOW_TRIGGER_ATTRIBUTE`, inside
@@ -36,9 +38,12 @@ const itemGap = (items) => {
36
38
  * and the count is recomputed whenever either element resizes (a docked
37
39
  * pane narrows the row, an added view or a rename widens the copy), the
38
40
  * active item changes, or the items change order: swapping two items keeps
39
- * the measuring row's size, which no observer reports. The first count
40
- * arrives with the observer's first report, before the row paints; until
41
- * then every item shows.
41
+ * the measuring row's size, which no observer reports.
42
+ *
43
+ * The first count is taken in a layout effect, in the same task that commits
44
+ * the row: a `ResizeObserver` reports only at the browser's next rendering
45
+ * update, and until that count lands the row would hold every item, the last
46
+ * ones clipped, for a paint or any script that reads the layout to see.
42
47
  */
43
48
  const useInlineOverflow = ({ activeIndex, itemKeys }) => {
44
49
  const itemCount = itemKeys.length;
@@ -47,10 +52,9 @@ const useInlineOverflow = ({ activeIndex, itemKeys }) => {
47
52
  const [measure, setMeasure] = useState(null);
48
53
  const [visibleCount, setVisibleCount] = useState(itemCount);
49
54
  const [measured, setMeasured] = useState(false);
50
- useEffect(() => {
55
+ useLayoutEffect(() => {
51
56
  if (!container || !measure) return;
52
57
  const keys = order === "" ? [] : order.split(KEY_SEPARATOR);
53
- let availableWidth = 0;
54
58
  const recompute = () => {
55
59
  const copies = Array.from(measure.querySelectorAll(`[${INLINE_OVERFLOW_ITEM_ATTRIBUTE}]`), (copy) => ({
56
60
  key: copy.getAttribute(INLINE_OVERFLOW_ITEM_ATTRIBUTE),
@@ -60,17 +64,15 @@ const useInlineOverflow = ({ activeIndex, itemKeys }) => {
60
64
  const trigger = measure.querySelector(`[${INLINE_OVERFLOW_TRIGGER_ATTRIBUTE}]`);
61
65
  setVisibleCount(resolveInlineOverflow({
62
66
  activeIndex,
63
- availableWidth,
67
+ availableWidth: container.getBoundingClientRect().width,
64
68
  gap: itemGap(copies.map(({ box }) => box)),
65
69
  itemWidths: keys.map((key) => boxByKey.get(key)?.width ?? 0),
66
70
  triggerWidth: trigger?.getBoundingClientRect().width ?? 0
67
71
  }).visibleCount);
68
72
  setMeasured(true);
69
73
  };
70
- const observer = new ResizeObserver((entries) => {
71
- for (const entry of entries) if (entry.target === container) availableWidth = entry.contentRect.width;
72
- recompute();
73
- });
74
+ recompute();
75
+ const observer = new ResizeObserver(recompute);
74
76
  observer.observe(container);
75
77
  observer.observe(measure);
76
78
  return () => observer.disconnect();
@@ -38,60 +38,64 @@ const InspectorFacetBar = ({ facet, facets, labels, disabledFacets, pulseSeq, ac
38
38
  const activeChip = container?.querySelector("[data-facet-chip-active]");
39
39
  if (activeChip instanceof HTMLElement) flashFacetChip(activeChip);
40
40
  }, [container, pulseSeq]);
41
- return /* @__PURE__ */ jsxs("div", {
42
- className: cn("bg-background/85 supports-[backdrop-filter]:bg-background/65 sticky top-0 z-10 flex shrink-0 items-center gap-0.5 overflow-hidden border-b px-1.5 backdrop-blur", TOOLBAR_ROW_HEIGHT),
41
+ return /* @__PURE__ */ jsx("div", {
42
+ className: cn("bg-background/85 supports-[backdrop-filter]:bg-background/65 sticky top-0 z-10 flex shrink-0 items-center overflow-hidden border-b px-1.5 backdrop-blur", TOOLBAR_ROW_HEIGHT),
43
43
  "data-active-facet": facet,
44
44
  "data-slot": "inspector-facet-bar",
45
- ref: containerRef,
46
- children: [
47
- /* @__PURE__ */ jsx("div", {
48
- className: "contents",
49
- role: "tablist",
50
- children: visibleFacets.map((value) => /* @__PURE__ */ jsx(FacetChip, {
51
- activeBadge,
52
- disabled: disabledFacets?.has(value) ?? false,
53
- isActive: value === facet,
54
- label: labels[value],
55
- onSelect: () => onChange(value),
56
- value
57
- }, value))
58
- }),
59
- overflowing && /* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(MenuTrigger, {
60
- "aria-label": overflowMenuLabel,
61
- className: "ms-auto",
62
- "data-slot": "inspector-facet-overflow-trigger",
63
- render: /* @__PURE__ */ jsx(Button, {
64
- size: "icon-sm",
65
- type: "button",
66
- variant: "outline"
45
+ children: /* @__PURE__ */ jsxs("div", {
46
+ className: "relative flex h-full min-w-0 flex-1 items-center gap-0.5",
47
+ "data-slot": "inspector-facet-row",
48
+ ref: containerRef,
49
+ children: [
50
+ /* @__PURE__ */ jsx("div", {
51
+ className: "contents",
52
+ role: "tablist",
53
+ children: visibleFacets.map((value) => /* @__PURE__ */ jsx(FacetChip, {
54
+ activeBadge,
55
+ disabled: disabledFacets?.has(value) ?? false,
56
+ isActive: value === facet,
57
+ label: labels[value],
58
+ onSelect: () => onChange(value),
59
+ value
60
+ }, value))
67
61
  }),
68
- children: /* @__PURE__ */ jsx(ChevronDownIcon, {})
69
- }), /* @__PURE__ */ jsx(MenuPopup, {
70
- align: "end",
71
- side: "bottom",
72
- children: overflowFacets.map((value) => /* @__PURE__ */ jsx(MenuItem, {
73
- "data-facet-overflow-value": value,
74
- disabled: disabledFacets?.has(value) ?? false,
75
- onClick: () => onChange(value),
76
- children: labels[value]
77
- }, value))
78
- })] }),
79
- /* @__PURE__ */ jsxs("div", {
80
- "aria-hidden": "true",
81
- className: "pointer-events-none invisible absolute flex w-max items-center gap-0.5",
82
- ref: measureRef,
83
- children: [facets.map((value) => /* @__PURE__ */ jsx("span", {
84
- className: cn(CHIP_CLASS, INACTIVE_CHIP_CLASS),
85
- "data-facet-option": value,
86
- "data-facet-option-disabled": disabledFacets?.has(value) ? "" : void 0,
87
- [INLINE_OVERFLOW_ITEM_ATTRIBUTE]: value,
88
- children: labels[value]
89
- }, value)), /* @__PURE__ */ jsx("span", {
90
- className: "size-8 shrink-0 rounded-lg border sm:size-7",
91
- [INLINE_OVERFLOW_TRIGGER_ATTRIBUTE]: ""
92
- })]
93
- })
94
- ]
62
+ overflowing && /* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(MenuTrigger, {
63
+ "aria-label": overflowMenuLabel,
64
+ className: "ms-auto",
65
+ "data-slot": "inspector-facet-overflow-trigger",
66
+ render: /* @__PURE__ */ jsx(Button, {
67
+ size: "icon-sm",
68
+ type: "button",
69
+ variant: "outline"
70
+ }),
71
+ children: /* @__PURE__ */ jsx(ChevronDownIcon, {})
72
+ }), /* @__PURE__ */ jsx(MenuPopup, {
73
+ align: "end",
74
+ side: "bottom",
75
+ children: overflowFacets.map((value) => /* @__PURE__ */ jsx(MenuItem, {
76
+ "data-facet-overflow-value": value,
77
+ disabled: disabledFacets?.has(value) ?? false,
78
+ onClick: () => onChange(value),
79
+ children: labels[value]
80
+ }, value))
81
+ })] }),
82
+ /* @__PURE__ */ jsxs("div", {
83
+ "aria-hidden": "true",
84
+ className: "pointer-events-none invisible absolute flex w-max items-center gap-0.5",
85
+ ref: measureRef,
86
+ children: [facets.map((value) => /* @__PURE__ */ jsx("span", {
87
+ className: cn(CHIP_CLASS, INACTIVE_CHIP_CLASS),
88
+ "data-facet-option": value,
89
+ "data-facet-option-disabled": disabledFacets?.has(value) ? "" : void 0,
90
+ [INLINE_OVERFLOW_ITEM_ATTRIBUTE]: value,
91
+ children: labels[value]
92
+ }, value)), /* @__PURE__ */ jsx("span", {
93
+ className: "size-8 shrink-0 rounded-lg border sm:size-7",
94
+ [INLINE_OVERFLOW_TRIGGER_ATTRIBUTE]: ""
95
+ })]
96
+ })
97
+ ]
98
+ })
95
99
  });
96
100
  };
97
101
  /** One-shot attention flash: a ring that appears with a couple of opacity
@@ -8,9 +8,13 @@ type NumberFormatter = {
8
8
  maximumFractionDigits: number;
9
9
  style: "unit";
10
10
  unit: string;
11
- unitDisplay: "short";
11
+ unitDisplay: "long" | "short";
12
12
  }) => string;
13
13
  };
14
- /** A file size in the reader's locale, at most one decimal ("1.2 MB"). */
14
+ /**
15
+ * A file size in the reader's locale, at most one decimal ("1.2 MB"). Bytes
16
+ * use the long, plural-aware unit ("333 bytes", "333 bajtů"): the short
17
+ * English unit has no plural ("333 byte").
18
+ */
15
19
  export declare const formatFileSize: (sizeBytes: number, format: NumberFormatter) => string;
16
20
  export {};
@@ -17,14 +17,18 @@ const getFileSizeDisplay = (sizeBytes) => {
17
17
  value: sizeBytes / 1e9
18
18
  };
19
19
  };
20
- /** A file size in the reader's locale, at most one decimal ("1.2 MB"). */
20
+ /**
21
+ * A file size in the reader's locale, at most one decimal ("1.2 MB"). Bytes
22
+ * use the long, plural-aware unit ("333 bytes", "333 bajtů"): the short
23
+ * English unit has no plural ("333 byte").
24
+ */
21
25
  const formatFileSize = (sizeBytes, format) => {
22
26
  const size = getFileSizeDisplay(sizeBytes);
23
27
  return format.number(size.value, {
24
28
  maximumFractionDigits: 1,
25
29
  style: "unit",
26
30
  unit: size.unit,
27
- unitDisplay: "short"
31
+ unitDisplay: size.unit === "byte" ? "long" : "short"
28
32
  });
29
33
  };
30
34
  export { formatFileSize, getFileSizeDisplay };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/ui",
3
- "version": "0.81.0",
3
+ "version": "0.81.1",
4
4
  "description": "Stella's design system: bidi-aware React primitives built on Base UI, the dockable inspector pane, and the Tailwind v4 theme they are styled with.",
5
5
  "keywords": [
6
6
  "base-ui",