wimui 0.66.0 → 0.68.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/components/_internal/ChoiceLabel.cjs +2 -0
- package/dist/components/_internal/ChoiceLabel.d.ts +31 -0
- package/dist/components/_internal/ChoiceLabel.js +22 -0
- package/dist/components/_internal/InlineDisclosure.cjs +2 -0
- package/dist/components/_internal/InlineDisclosure.d.ts +22 -0
- package/dist/components/_internal/InlineDisclosure.js +47 -0
- package/dist/components/_internal/choice-label.module.cjs +2 -0
- package/dist/components/_internal/choice-label.module.js +11 -0
- package/dist/components/_internal/inline-disclosure.module.cjs +2 -0
- package/dist/components/_internal/inline-disclosure.module.js +9 -0
- package/dist/components/_internal/rovingIndex.cjs +2 -0
- package/dist/components/_internal/rovingIndex.d.ts +38 -0
- package/dist/components/_internal/rovingIndex.js +16 -0
- package/dist/components/data-display/AvatarGroup/AvatarGroup.cjs +1 -1
- package/dist/components/data-display/AvatarGroup/AvatarGroup.d.ts +10 -3
- package/dist/components/data-display/AvatarGroup/AvatarGroup.js +55 -27
- package/dist/components/data-display/AvatarGroup/avatar-group.module.cjs +1 -1
- package/dist/components/data-display/AvatarGroup/avatar-group.module.js +8 -6
- package/dist/components/data-display/Card/Card.cjs +1 -1
- package/dist/components/data-display/Card/Card.d.ts +21 -0
- package/dist/components/data-display/Card/Card.js +7 -3
- package/dist/components/data-display/Card/card.module.cjs +1 -1
- package/dist/components/data-display/Card/card.module.js +17 -16
- package/dist/components/form/CheckboxGroup/CheckboxGroup.cjs +1 -1
- package/dist/components/form/CheckboxGroup/CheckboxGroup.d.ts +9 -0
- package/dist/components/form/CheckboxGroup/CheckboxGroup.js +42 -30
- package/dist/components/form/CheckboxGroup/checkbox-group.module.cjs +1 -1
- package/dist/components/form/CheckboxGroup/checkbox-group.module.js +4 -3
- package/dist/components/form/RadioGroup/RadioGroup.cjs +1 -1
- package/dist/components/form/RadioGroup/RadioGroup.d.ts +9 -0
- package/dist/components/form/RadioGroup/RadioGroup.js +46 -34
- package/dist/components/form/RadioGroup/radio-group.module.cjs +1 -1
- package/dist/components/form/RadioGroup/radio-group.module.js +4 -3
- package/dist/components/form/SegmentedControl/SegmentedControl.cjs +1 -1
- package/dist/components/form/SegmentedControl/SegmentedControl.js +56 -68
- package/dist/components/form/ToggleGroup/ToggleGroup.cjs +1 -1
- package/dist/components/form/ToggleGroup/ToggleGroup.js +80 -88
- package/dist/components/layout/OverflowList/OverflowList.cjs +2 -0
- package/dist/components/layout/OverflowList/OverflowList.d.ts +81 -0
- package/dist/components/layout/OverflowList/OverflowList.js +85 -0
- package/dist/components/layout/OverflowList/getVisibleCount.cjs +2 -0
- package/dist/components/layout/OverflowList/getVisibleCount.d.ts +30 -0
- package/dist/components/layout/OverflowList/getVisibleCount.js +26 -0
- package/dist/components/layout/OverflowList/overflow-list.module.cjs +2 -0
- package/dist/components/layout/OverflowList/overflow-list.module.js +10 -0
- package/dist/components/layout/Toolbar/Toolbar.cjs +1 -1
- package/dist/components/layout/Toolbar/Toolbar.js +52 -51
- package/dist/components/navigation/Breadcrumb/Breadcrumb.cjs +1 -1
- package/dist/components/navigation/Breadcrumb/Breadcrumb.d.ts +12 -0
- package/dist/components/navigation/Breadcrumb/Breadcrumb.js +88 -53
- package/dist/components/navigation/Stepper/Stepper.cjs +1 -1
- package/dist/components/navigation/Stepper/Stepper.js +51 -53
- package/dist/components/navigation/TabNavigation/TabNavigation.cjs +1 -1
- package/dist/components/navigation/TabNavigation/TabNavigation.js +47 -49
- package/dist/components/navigation/Tabs/Tabs.cjs +1 -1
- package/dist/components/navigation/Tabs/Tabs.js +80 -73
- package/dist/data-display.cjs +1 -1
- package/dist/data-display.js +40 -40
- package/dist/i18n/generated/components.d.ts +1 -1
- package/dist/i18n/generated/data-display.cjs +1 -1
- package/dist/i18n/generated/data-display.d.ts +1 -1
- package/dist/i18n/generated/data-display.js +12 -3
- package/dist/i18n/generated/keys.d.ts +2 -1
- package/dist/i18n/generated/navigation.cjs +2 -0
- package/dist/i18n/generated/navigation.d.ts +3 -0
- package/dist/i18n/generated/navigation.js +12 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +175 -174
- package/dist/layout.cjs +1 -1
- package/dist/layout.d.ts +1 -0
- package/dist/layout.js +2 -1
- package/dist/llms-full.txt +45 -3
- package/dist/llms.txt +2 -1
- package/dist/locales/en/components.json +2 -1
- package/dist/locales/en/data-display.json +3 -0
- package/dist/locales/ja/components.json +2 -1
- package/dist/locales/ja/data-display.json +3 -0
- package/dist/locales/pt/components.json +2 -1
- package/dist/locales/pt/data-display.json +3 -0
- package/dist/styles.css +1 -1
- package/dist/wimui.umd.css +1 -1
- package/dist/wimui.umd.js +5 -5
- package/package.json +30 -30
|
@@ -2,121 +2,113 @@
|
|
|
2
2
|
import { Root as e, Slottable as t } from "../../../node_modules/@radix-ui/react-slot/dist/index.js";
|
|
3
3
|
import { useMergedRef as n } from "../../../hooks/useMergedRef.js";
|
|
4
4
|
import { Icon as r } from "../../media/Icon/Icon.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import f from "
|
|
10
|
-
import
|
|
5
|
+
import { getRovingIndex as i, isRovingKey as a } from "../../_internal/rovingIndex.js";
|
|
6
|
+
import { FieldTemplate as o } from "../FieldTemplate/FieldTemplate.js";
|
|
7
|
+
import { useIndicator as s } from "../../_internal/useIndicator.js";
|
|
8
|
+
import c from "./toggle-group.module.js";
|
|
9
|
+
import l, { forwardRef as u, useEffect as d, useRef as f, useState as p } from "react";
|
|
10
|
+
import m from "classnames";
|
|
11
|
+
import { jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
11
12
|
//#region src/components/form/ToggleGroup/ToggleGroup.tsx
|
|
12
|
-
var
|
|
13
|
-
let
|
|
14
|
-
activeSelector: `.${
|
|
15
|
-
dependence:
|
|
16
|
-
}),
|
|
17
|
-
if (
|
|
18
|
-
let e =
|
|
13
|
+
var _ = u(({ options: u, value: _, defaultValue: v, onChange: y, selectionMode: b = "single", size: x = "md", fullWidth: S = !1, className: C, "aria-label": w, "aria-labelledby": T, "aria-describedby": E, disabled: D = !1, label: O, error: k, required: A, layout: j = "vertical", id: M, asChild: N = !1, children: P }, F) => {
|
|
14
|
+
let I = l.useId(), L = M || `wim-toggle-group-${I}`, R = `${L}-label`, z = `${L}-error`, B = _ !== void 0, [V, H] = p(v ?? (b === "multiple" ? [] : "")), U = B ? _ : V, { containerRef: W, sliderStyle: G, isReady: K } = s({
|
|
15
|
+
activeSelector: `.${c.active}`,
|
|
16
|
+
dependence: u.length
|
|
17
|
+
}), q = f([]), J = u.findIndex((e) => !e.disabled), [Y, X] = p(() => {
|
|
18
|
+
if (b === "single") {
|
|
19
|
+
let e = B ? _ : v;
|
|
19
20
|
if (typeof e == "string") {
|
|
20
|
-
let t =
|
|
21
|
+
let t = u.findIndex((t) => !t.disabled && t.value === e);
|
|
21
22
|
if (t >= 0) return t;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
return
|
|
25
|
+
return J >= 0 ? J : 0;
|
|
25
26
|
});
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
let e =
|
|
29
|
-
e >= 0 &&
|
|
27
|
+
d(() => {
|
|
28
|
+
if (b === "single" && B && typeof _ == "string") {
|
|
29
|
+
let e = u.findIndex((e) => !e.disabled && e.value === _);
|
|
30
|
+
e >= 0 && X(e);
|
|
30
31
|
}
|
|
31
32
|
}, [
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
_,
|
|
34
|
+
b,
|
|
35
|
+
B,
|
|
36
|
+
u
|
|
36
37
|
]);
|
|
37
|
-
let
|
|
38
|
+
let Z = (e) => {
|
|
38
39
|
let t;
|
|
39
|
-
if (
|
|
40
|
-
let n = Array.isArray(
|
|
40
|
+
if (b === "multiple") {
|
|
41
|
+
let n = Array.isArray(U) ? U : [];
|
|
41
42
|
t = n.includes(e) ? n.filter((t) => t !== e) : [...n, e];
|
|
42
|
-
} else t =
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
errorId: L,
|
|
72
|
-
className: x,
|
|
73
|
-
children: /* @__PURE__ */ m(j ? e : "div", {
|
|
74
|
-
ref: n(H, N),
|
|
75
|
-
id: F,
|
|
76
|
-
className: f("wim-toggle-group", o.root, o[y], o[v], b && o.fullWidth, W && o.ready, D && o.danger),
|
|
77
|
-
role: $,
|
|
78
|
-
"aria-label": S,
|
|
79
|
-
"aria-labelledby": E ? I : C,
|
|
43
|
+
} else t = U === e ? "" : e;
|
|
44
|
+
B || H(t), y?.(t);
|
|
45
|
+
}, Q = (e) => b === "multiple" ? (Array.isArray(U) ? U : []).includes(e) : U === e, $ = (e, t) => {
|
|
46
|
+
if (!a(t.key)) return;
|
|
47
|
+
t.preventDefault();
|
|
48
|
+
let n = i({
|
|
49
|
+
key: t.key,
|
|
50
|
+
current: e,
|
|
51
|
+
count: u.length,
|
|
52
|
+
isDisabled: (e) => !!u[e].disabled
|
|
53
|
+
});
|
|
54
|
+
n !== null && n !== e && (X(n), q.current[n]?.focus(), b === "single" && Z(u[n].value));
|
|
55
|
+
}, ee = b === "single" ? "radiogroup" : "toolbar", te = `${L}-item-0`;
|
|
56
|
+
return /* @__PURE__ */ h(o, {
|
|
57
|
+
label: O,
|
|
58
|
+
error: k,
|
|
59
|
+
required: A,
|
|
60
|
+
layout: j,
|
|
61
|
+
labelId: R,
|
|
62
|
+
htmlFor: te,
|
|
63
|
+
errorId: z,
|
|
64
|
+
className: C,
|
|
65
|
+
children: /* @__PURE__ */ g(N ? e : "div", {
|
|
66
|
+
ref: n(W, F),
|
|
67
|
+
id: L,
|
|
68
|
+
className: m("wim-toggle-group", c.root, c[x], c[b], S && c.fullWidth, K && c.ready, k && c.danger),
|
|
69
|
+
role: ee,
|
|
70
|
+
"aria-label": w,
|
|
71
|
+
"aria-labelledby": O ? R : T,
|
|
80
72
|
"aria-orientation": "horizontal",
|
|
81
|
-
"aria-invalid":
|
|
82
|
-
"aria-describedby": [
|
|
73
|
+
"aria-invalid": k ? !0 : void 0,
|
|
74
|
+
"aria-describedby": [E, k ? z : void 0].filter(Boolean).join(" ") || void 0,
|
|
83
75
|
children: [
|
|
84
|
-
/* @__PURE__ */
|
|
85
|
-
className:
|
|
86
|
-
style:
|
|
76
|
+
/* @__PURE__ */ h("div", {
|
|
77
|
+
className: m(c.slider, c[b], K && c.ready),
|
|
78
|
+
style: G,
|
|
87
79
|
"aria-hidden": "true"
|
|
88
80
|
}),
|
|
89
|
-
|
|
90
|
-
let n = `${
|
|
91
|
-
return /* @__PURE__ */
|
|
81
|
+
u.map((e, t) => {
|
|
82
|
+
let n = `${L}-item-${t}`;
|
|
83
|
+
return /* @__PURE__ */ g("button", {
|
|
92
84
|
id: n,
|
|
93
85
|
ref: (e) => {
|
|
94
|
-
|
|
86
|
+
q.current[t] = e;
|
|
95
87
|
},
|
|
96
88
|
type: "button",
|
|
97
|
-
className:
|
|
89
|
+
className: m(c.item, c[b], Q(e.value) && c.active, !e.label && e.iconName && c.iconOnly),
|
|
98
90
|
onClick: () => {
|
|
99
|
-
|
|
91
|
+
X(t), Z(e.value);
|
|
100
92
|
},
|
|
101
|
-
onKeyDown: (e) =>
|
|
102
|
-
disabled:
|
|
103
|
-
role:
|
|
104
|
-
"aria-checked":
|
|
105
|
-
"aria-pressed":
|
|
93
|
+
onKeyDown: (e) => $(t, e),
|
|
94
|
+
disabled: D || e.disabled,
|
|
95
|
+
role: b === "single" ? "radio" : "button",
|
|
96
|
+
"aria-checked": b === "single" ? Q(e.value) : void 0,
|
|
97
|
+
"aria-pressed": b === "multiple" ? Q(e.value) : void 0,
|
|
106
98
|
"aria-label": e.label ? void 0 : e.value,
|
|
107
|
-
tabIndex: !e.disabled && t ===
|
|
108
|
-
children: [e.iconName && /* @__PURE__ */
|
|
99
|
+
tabIndex: !e.disabled && t === Y ? 0 : -1,
|
|
100
|
+
children: [e.iconName && /* @__PURE__ */ h(r, {
|
|
109
101
|
name: e.iconName,
|
|
110
|
-
size:
|
|
111
|
-
className:
|
|
112
|
-
}), e.label && /* @__PURE__ */
|
|
102
|
+
size: x,
|
|
103
|
+
className: c.icon
|
|
104
|
+
}), e.label && /* @__PURE__ */ h("span", { children: e.label })]
|
|
113
105
|
}, e.value);
|
|
114
106
|
}),
|
|
115
|
-
/* @__PURE__ */
|
|
107
|
+
/* @__PURE__ */ h(t, { children: P })
|
|
116
108
|
]
|
|
117
109
|
})
|
|
118
110
|
});
|
|
119
111
|
});
|
|
120
|
-
|
|
112
|
+
_.displayName = "ToggleGroup";
|
|
121
113
|
//#endregion
|
|
122
|
-
export {
|
|
114
|
+
export { _ as ToggleGroup };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../../utilities/style-utils.cjs"),r=require("../../../hooks/useMergedRef.cjs"),i=require("./getVisibleCount.cjs"),a=require("./overflow-list.module.cjs");let o=require("react");o=e.__toESM(o,1);let s=require("classnames");s=e.__toESM(s,1);let c=require("react/jsx-runtime");var l=o.default.forwardRef(({items:e,renderItem:l,renderOverflow:u,collapseFrom:d=`end`,minVisibleItems:f=0,alwaysRenderOverflow:p=!1,onOverflow:m,gap:h=`sm`,listElement:g,asChild:_=!1,className:v,style:y,children:b,...x},S)=>{let C=(0,o.useRef)(null),w=(0,o.useRef)(null),T=r.useMergedRef(S,C),[E,D]=(0,o.useState)(e.length),O=(0,o.useCallback)(()=>{let t=C.current,n=w.current;if(!t||!n)return;let r=getComputedStyle(t),a=t.clientWidth-(parseFloat(r.paddingLeft)||0)-(parseFloat(r.paddingRight)||0),o=parseFloat(getComputedStyle(n).columnGap)||0,s=e=>{let t=getComputedStyle(e);return e.getBoundingClientRect().width+(parseFloat(t.marginLeft)||0)+(parseFloat(t.marginRight)||0)},c=Array.from(n.children),l=c.slice(0,e.length).map(s),u=c[e.length]?s(c[e.length]):0,m=i.pinnedCount(d,l.length),h=l.slice(0,m).reduce((e,t)=>e+t+o,0),g=l.slice(m),_=m+i.getVisibleCount({itemWidths:d===`end`?g:[...g].reverse(),overflowWidth:u,available:a-h,gap:o,minVisibleItems:Math.max(f-m,0),alwaysRenderOverflow:p});D(e=>e===_?e:_)},[e.length,d,f,p]);(0,o.useLayoutEffect)(O),(0,o.useEffect)(()=>{let e=C.current,t=w.current;if(!e||!t||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>O());return n.observe(e),n.observe(t),()=>n.disconnect()},[O]);let{visible:k,hidden:A,overflowAt:j}=i.splitItems(d,e.length,E),M=A.length,N=A.map(t=>e[t]),P=M>0||p,F=(0,o.useRef)(m);(0,o.useLayoutEffect)(()=>{F.current=m});let I=(0,o.useRef)(null);(0,o.useEffect)(()=>{let t=I.current;t&&t.items===e&&t.count===M&&t.from===d||(I.current={items:e,count:M,from:d},(t||M!==0)&&F.current?.(i.splitItems(d,e.length,e.length-M).hidden.map(t=>e[t])))},[e,M,d]);let L=P?(0,c.jsx)(o.default.Fragment,{children:u(N)},`overflow`):null,R=g??`div`,z=k.map(t=>(0,c.jsx)(o.default.Fragment,{children:l(e[t],t)},t)),B=k.filter(e=>e<j).length;z.splice(B,0,L);let V=(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(R,{className:a.default.row,children:z}),(0,c.jsx)(`div`,{className:a.default.measure,"aria-hidden":`true`,inert:!0,children:(0,c.jsxs)(R,{ref:w,className:a.default.measureRow,children:[e.map((e,t)=>(0,c.jsx)(o.default.Fragment,{children:l(e,t)},t)),u(e)]})})]});return(0,c.jsxs)(_?t.Root:`div`,{ref:T,className:(0,s.default)(`wim-overflow-list`,a.default.root,v),"data-collapse-from":d,"data-hidden-count":M,...x,style:{...y,"--wim-overflow-list-gap":n.getSpacingValue(h)},children:[V,_?(0,c.jsx)(t.Slottable,{children:b}):null]})});l.displayName=`OverflowList`,exports.OverflowList=l;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { WimSpacing } from '../../../types/tokens';
|
|
3
|
+
import { CollapseFrom } from './getVisibleCount';
|
|
4
|
+
export type OverflowListProps<T> = Omit<React.ComponentPropsWithoutRef<"div">, "children"> & {
|
|
5
|
+
/**
|
|
6
|
+
* Items to lay out in a single row, in reading order.
|
|
7
|
+
*/
|
|
8
|
+
items: T[];
|
|
9
|
+
/**
|
|
10
|
+
* Renders one item. Return a single element: each top-level element is measured as one item.
|
|
11
|
+
*/
|
|
12
|
+
renderItem: (item: T, index: number) => React.ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* Renders the overflow indicator from the items that did not fit (for example a "+N" button
|
|
15
|
+
* that opens a Popover listing them). Return a single element. Not rendered while every item
|
|
16
|
+
* fits, unless `alwaysRenderOverflow` is set. The hidden items are not in the DOM, so the
|
|
17
|
+
* indicator is how users — including keyboard and screen reader users — reach them.
|
|
18
|
+
*/
|
|
19
|
+
renderOverflow: (hiddenItems: T[]) => React.ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* The side items are collapsed from. `"end"` keeps the first items (tags, toolbars);
|
|
22
|
+
* `"start"` keeps the last ones (a path keeps the current folder); `"middle"` keeps the first
|
|
23
|
+
* item and collapses from the second one, with the indicator right after the first item
|
|
24
|
+
* (a breadcrumb keeps its root and the current page).
|
|
25
|
+
* @default "end"
|
|
26
|
+
*/
|
|
27
|
+
collapseFrom?: CollapseFrom;
|
|
28
|
+
/**
|
|
29
|
+
* Renders the row as a list. `renderItem` and `renderOverflow` must then return `<li>`
|
|
30
|
+
* elements. Without it, the row is a `div`, which a list may not contain.
|
|
31
|
+
*/
|
|
32
|
+
listElement?: "ul" | "ol";
|
|
33
|
+
/**
|
|
34
|
+
* Items that stay visible however narrow the row gets. They may then overflow the row.
|
|
35
|
+
* @default 0
|
|
36
|
+
*/
|
|
37
|
+
minVisibleItems?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Renders the overflow indicator even when every item fits (it receives an empty array).
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
alwaysRenderOverflow?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Called with the hidden items whenever the set of hidden items changes.
|
|
45
|
+
*/
|
|
46
|
+
onOverflow?: (hiddenItems: T[]) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Gap between items: a spacing token name (`"sm"`, `"md"`, …).
|
|
49
|
+
* @default "sm"
|
|
50
|
+
*/
|
|
51
|
+
gap?: WimSpacing;
|
|
52
|
+
/**
|
|
53
|
+
* If true, the list will be rendered as its child, merging its props onto that child.
|
|
54
|
+
*/
|
|
55
|
+
asChild?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The element that becomes the root (in place of `div`) when `asChild` is set. The items are
|
|
58
|
+
* rendered inside it. Ignored without `asChild`.
|
|
59
|
+
*/
|
|
60
|
+
children?: React.ReactNode;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Lays out items in a single row and collapses the ones that do not fit into an overflow
|
|
64
|
+
* indicator ("+N"), recomputed whenever the row or an item changes width. It measures and
|
|
65
|
+
* collapses; what the indicator shows (a count, a Popover, a Menu) is up to `renderOverflow`.
|
|
66
|
+
*
|
|
67
|
+
* The list fills its container. Its own minimum width is 0 and its preferred width is every item
|
|
68
|
+
* in one row, whatever is folded at the moment, so it also folds inside a table cell or an
|
|
69
|
+
* inline-block and grows back when there is room.
|
|
70
|
+
*
|
|
71
|
+
* Composition Contract:
|
|
72
|
+
* - Managed by: App consumption
|
|
73
|
+
* - Scroll lock: No
|
|
74
|
+
* - Does not own the hidden items' disclosure — compose Popover / Menu in `renderOverflow`
|
|
75
|
+
* - Renders each item twice: once visible, once in an invisible, inert measuring layer
|
|
76
|
+
*/
|
|
77
|
+
export declare const OverflowList: (<T>(props: OverflowListProps<T> & {
|
|
78
|
+
ref?: React.ForwardedRef<HTMLDivElement>;
|
|
79
|
+
}) => React.ReactElement) & {
|
|
80
|
+
displayName?: string;
|
|
81
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Root as e, Slottable as t } from "../../../node_modules/@radix-ui/react-slot/dist/index.js";
|
|
3
|
+
import { getSpacingValue as n } from "../../../utilities/style-utils.js";
|
|
4
|
+
import { useMergedRef as r } from "../../../hooks/useMergedRef.js";
|
|
5
|
+
import { getVisibleCount as i, pinnedCount as a, splitItems as o } from "./getVisibleCount.js";
|
|
6
|
+
import s from "./overflow-list.module.js";
|
|
7
|
+
import c, { useCallback as l, useEffect as u, useLayoutEffect as d, useRef as f, useState as p } from "react";
|
|
8
|
+
import m from "classnames";
|
|
9
|
+
import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
10
|
+
var v = c.forwardRef(({ items: v, renderItem: y, renderOverflow: b, collapseFrom: x = "end", minVisibleItems: S = 0, alwaysRenderOverflow: C = !1, onOverflow: w, gap: T = "sm", listElement: E, asChild: D = !1, className: O, style: k, children: A, ...j }, M) => {
|
|
11
|
+
let N = f(null), P = f(null), F = r(M, N), [I, L] = p(v.length), R = l(() => {
|
|
12
|
+
let e = N.current, t = P.current;
|
|
13
|
+
if (!e || !t) return;
|
|
14
|
+
let n = getComputedStyle(e), r = e.clientWidth - (parseFloat(n.paddingLeft) || 0) - (parseFloat(n.paddingRight) || 0), o = parseFloat(getComputedStyle(t).columnGap) || 0, s = (e) => {
|
|
15
|
+
let t = getComputedStyle(e);
|
|
16
|
+
return e.getBoundingClientRect().width + (parseFloat(t.marginLeft) || 0) + (parseFloat(t.marginRight) || 0);
|
|
17
|
+
}, c = Array.from(t.children), l = c.slice(0, v.length).map(s), u = c[v.length] ? s(c[v.length]) : 0, d = a(x, l.length), f = l.slice(0, d).reduce((e, t) => e + t + o, 0), p = l.slice(d), m = d + i({
|
|
18
|
+
itemWidths: x === "end" ? p : [...p].reverse(),
|
|
19
|
+
overflowWidth: u,
|
|
20
|
+
available: r - f,
|
|
21
|
+
gap: o,
|
|
22
|
+
minVisibleItems: Math.max(S - d, 0),
|
|
23
|
+
alwaysRenderOverflow: C
|
|
24
|
+
});
|
|
25
|
+
L((e) => e === m ? e : m);
|
|
26
|
+
}, [
|
|
27
|
+
v.length,
|
|
28
|
+
x,
|
|
29
|
+
S,
|
|
30
|
+
C
|
|
31
|
+
]);
|
|
32
|
+
d(R), u(() => {
|
|
33
|
+
let e = N.current, t = P.current;
|
|
34
|
+
if (!e || !t || typeof ResizeObserver > "u") return;
|
|
35
|
+
let n = new ResizeObserver(() => R());
|
|
36
|
+
return n.observe(e), n.observe(t), () => n.disconnect();
|
|
37
|
+
}, [R]);
|
|
38
|
+
let { visible: z, hidden: B, overflowAt: V } = o(x, v.length, I), H = B.length, U = B.map((e) => v[e]), W = H > 0 || C, G = f(w);
|
|
39
|
+
d(() => {
|
|
40
|
+
G.current = w;
|
|
41
|
+
});
|
|
42
|
+
let K = f(null);
|
|
43
|
+
u(() => {
|
|
44
|
+
let e = K.current;
|
|
45
|
+
e && e.items === v && e.count === H && e.from === x || (K.current = {
|
|
46
|
+
items: v,
|
|
47
|
+
count: H,
|
|
48
|
+
from: x
|
|
49
|
+
}, (e || H !== 0) && G.current?.(o(x, v.length, v.length - H).hidden.map((e) => v[e])));
|
|
50
|
+
}, [
|
|
51
|
+
v,
|
|
52
|
+
H,
|
|
53
|
+
x
|
|
54
|
+
]);
|
|
55
|
+
let q = W ? /* @__PURE__ */ g(c.Fragment, { children: b(U) }, "overflow") : null, J = E ?? "div", Y = z.map((e) => /* @__PURE__ */ g(c.Fragment, { children: y(v[e], e) }, e)), X = z.filter((e) => e < V).length;
|
|
56
|
+
Y.splice(X, 0, q);
|
|
57
|
+
let Z = /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g(J, {
|
|
58
|
+
className: s.row,
|
|
59
|
+
children: Y
|
|
60
|
+
}), /* @__PURE__ */ g("div", {
|
|
61
|
+
className: s.measure,
|
|
62
|
+
"aria-hidden": "true",
|
|
63
|
+
inert: !0,
|
|
64
|
+
children: /* @__PURE__ */ _(J, {
|
|
65
|
+
ref: P,
|
|
66
|
+
className: s.measureRow,
|
|
67
|
+
children: [v.map((e, t) => /* @__PURE__ */ g(c.Fragment, { children: y(e, t) }, t)), b(v)]
|
|
68
|
+
})
|
|
69
|
+
})] });
|
|
70
|
+
return /* @__PURE__ */ _(D ? e : "div", {
|
|
71
|
+
ref: F,
|
|
72
|
+
className: m("wim-overflow-list", s.root, O),
|
|
73
|
+
"data-collapse-from": x,
|
|
74
|
+
"data-hidden-count": H,
|
|
75
|
+
...j,
|
|
76
|
+
style: {
|
|
77
|
+
...k,
|
|
78
|
+
"--wim-overflow-list-gap": n(T)
|
|
79
|
+
},
|
|
80
|
+
children: [Z, D ? /* @__PURE__ */ g(t, { children: A }) : null]
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
v.displayName = "OverflowList";
|
|
84
|
+
//#endregion
|
|
85
|
+
export { v as OverflowList };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var e=.5,t=(e,t)=>e===`middle`?Math.min(1,t):0,n=(e,n,r)=>{let i=t(e,n),a=Math.min(Math.max(r,i),n),o=n-a,s=(e,t)=>Array.from({length:Math.max(t-e,0)},(t,n)=>e+n);return e===`end`?{visible:s(0,a),hidden:s(a,n),overflowAt:a}:{visible:[...s(0,i),...s(i+o,n)],hidden:s(i,i+o),overflowAt:i}},r=({itemWidths:t,overflowWidth:n,available:r,gap:i,minVisibleItems:a,alwaysRenderOverflow:o})=>{let s=t.length,c=Math.min(Math.max(a,0),s);if(!o&&(e=>e.reduce((e,t,n)=>e+t+(n>0?i:0),0))(t)<=r+e)return s;let l=n,u=0;for(let n of t){let t=l+i+n;if(t>r+e)break;l=t,u+=1}return Math.max(u,c)};exports.getVisibleCount=r,exports.pinnedCount=t,exports.splitItems=n;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type VisibleCountInput = {
|
|
2
|
+
/** 各項目の幅。残す側の端から並べる(`collapseFrom="end"` なら先頭から) */
|
|
3
|
+
itemWidths: number[];
|
|
4
|
+
/** 「+N」の幅 */
|
|
5
|
+
overflowWidth: number;
|
|
6
|
+
/** 並びに使える幅 */
|
|
7
|
+
available: number;
|
|
8
|
+
gap: number;
|
|
9
|
+
minVisibleItems: number;
|
|
10
|
+
alwaysRenderOverflow: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type CollapseFrom = "start" | "end" | "middle";
|
|
13
|
+
/** `"middle"` のとき、畳まずに残す先頭の項目の数 */
|
|
14
|
+
export declare const pinnedCount: (collapseFrom: CollapseFrom, total: number) => number;
|
|
15
|
+
/**
|
|
16
|
+
* 見えている項目の数(`shown`)から、並べる順(項目の添字と「+N」の位置)と、畳んだ項目の添字を出す。
|
|
17
|
+
* - `"end"`: 先頭から見せ、「+N」は末尾
|
|
18
|
+
* - `"start"`: 末尾から見せ、「+N」は先頭
|
|
19
|
+
* - `"middle"`: 先頭の 1 つを残し、2 つ目から畳む。「+N」は先頭のすぐ後ろ
|
|
20
|
+
*/
|
|
21
|
+
export declare const splitItems: (collapseFrom: CollapseFrom, total: number, shown: number) => {
|
|
22
|
+
visible: number[];
|
|
23
|
+
hidden: number[];
|
|
24
|
+
overflowAt: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* 収まる項目の数。バレルには載せない(OverflowList の中だけで使う計算)。
|
|
28
|
+
*/
|
|
29
|
+
export declare const getVisibleCount: ({ itemWidths, overflowWidth, available, gap, minVisibleItems, alwaysRenderOverflow, }: VisibleCountInput) => number;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region src/components/layout/OverflowList/getVisibleCount.ts
|
|
3
|
+
var e = .5, t = (e, t) => e === "middle" ? Math.min(1, t) : 0, n = (e, n, r) => {
|
|
4
|
+
let i = t(e, n), a = Math.min(Math.max(r, i), n), o = n - a, s = (e, t) => Array.from({ length: Math.max(t - e, 0) }, (t, n) => e + n);
|
|
5
|
+
return e === "end" ? {
|
|
6
|
+
visible: s(0, a),
|
|
7
|
+
hidden: s(a, n),
|
|
8
|
+
overflowAt: a
|
|
9
|
+
} : {
|
|
10
|
+
visible: [...s(0, i), ...s(i + o, n)],
|
|
11
|
+
hidden: s(i, i + o),
|
|
12
|
+
overflowAt: i
|
|
13
|
+
};
|
|
14
|
+
}, r = ({ itemWidths: t, overflowWidth: n, available: r, gap: i, minVisibleItems: a, alwaysRenderOverflow: o }) => {
|
|
15
|
+
let s = t.length, c = Math.min(Math.max(a, 0), s);
|
|
16
|
+
if (!o && ((e) => e.reduce((e, t, n) => e + t + (n > 0 ? i : 0), 0))(t) <= r + e) return s;
|
|
17
|
+
let l = n, u = 0;
|
|
18
|
+
for (let n of t) {
|
|
19
|
+
let t = l + i + n;
|
|
20
|
+
if (t > r + e) break;
|
|
21
|
+
l = t, u += 1;
|
|
22
|
+
}
|
|
23
|
+
return Math.max(u, c);
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { r as getVisibleCount, t as pinnedCount, n as splitItems };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region src/components/layout/OverflowList/overflow-list.module.scss
|
|
3
|
+
var e = "_root_sh3ee_2", t = "_row_sh3ee_10", n = "_measureRow_sh3ee_11", r = "_measure_sh3ee_11", i = {
|
|
4
|
+
root: e,
|
|
5
|
+
row: t,
|
|
6
|
+
measureRow: n,
|
|
7
|
+
measure: r
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { i as default, r as measure, n as measureRow, e as root, t as row };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../../hooks/useMergedRef.cjs"),r=require("./toolbar.module.cjs");let
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../../hooks/useMergedRef.cjs"),r=require("../../_internal/rovingIndex.cjs"),i=require("./toolbar.module.cjs");let a=require("react");a=e.__toESM(a,1);let o=require("classnames");o=e.__toESM(o,1);let s=require("react/jsx-runtime");var c=`button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]`,l=`data-wim-toolbar-roving`,u=/^(button|checkbox|radio|submit|reset|image|file|color)$/,d=e=>e.tagName===`TEXTAREA`||e.tagName===`SELECT`||e.isContentEditable||e.tagName===`INPUT`&&!u.test(e.type),f=e=>Array.from(e.querySelectorAll(c)).filter(e=>!d(e)&&!e.closest(`[aria-hidden="true"]`)&&(e.getAttribute(`tabindex`)!==`-1`||e.hasAttribute(l))),p=a.default.forwardRef(({asChild:e=!1,size:c=`md`,orientation:u=`horizontal`,className:d,children:p,onKeyDownCapture:m,onFocus:h,...g},_)=>{let v=(0,a.useRef)(null),y=n.useMergedRef(_,v),b=(0,a.useRef)(null),x=(0,a.useRef)(null),S=(0,a.useCallback)(()=>{let e=v.current;if(!e)return;let t=f(e),n=document.activeElement,r=n&&t.includes(n)?n:b.current&&t.includes(b.current)?b.current:t[0];b.current=r??null;for(let e of t)e===r?e.hasAttribute(l)&&(e.removeAttribute(l),e.setAttribute(`tabindex`,`0`)):e.getAttribute(`tabindex`)!==`-1`&&(e.setAttribute(`tabindex`,`-1`),e.setAttribute(l,``));x.current?.takeRecords()},[]);return(0,a.useLayoutEffect)(S),(0,a.useEffect)(()=>{let e=v.current;if(!e)return;let t=new MutationObserver(()=>S());return t.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`disabled`,`tabindex`,`aria-hidden`]}),x.current=t,()=>{t.disconnect(),x.current=null}},[S]),(0,s.jsx)(e?t.Root:`div`,{ref:y,role:`toolbar`,"aria-orientation":u,"data-size":c,"data-orientation":u,className:(0,o.default)(`wim-toolbar`,i.default.root,i.default[`size-${c}`],i.default[u],d),onKeyDownCapture:e=>{if(m?.(e),e.defaultPrevented)return;let t=v.current;if(!t)return;let n=f(t);if(n.length===0)return;let i=n.indexOf(document.activeElement);if(i<0)return;let a=r.getRovingIndex({key:e.key,current:i,count:n.length,orientation:u});a!==null&&(e.preventDefault(),e.stopPropagation(),n[a]?.focus())},onFocus:e=>{h?.(e);let t=v.current,n=e.target;t&&n!==b.current&&f(t).includes(n)&&(b.current=n,S())},...g,children:p})});p.displayName=`Toolbar`;var m=a.default.forwardRef(({asChild:e=!1,className:n,children:r,...a},c)=>(0,s.jsx)(e?t.Root:`div`,{ref:c,role:`group`,className:(0,o.default)(i.default.group,n),...a,children:r}));m.displayName=`Toolbar.Group`;var h=a.default.forwardRef(({className:e,...t},n)=>(0,s.jsx)(`div`,{ref:n,role:`separator`,"aria-hidden":`true`,className:(0,o.default)(i.default.separator,e),...t}));h.displayName=`Toolbar.Separator`;var g=p;g.Group=m,g.Separator=h,exports.Toolbar=g,exports.default=g,exports.ToolbarGroup=m,exports.ToolbarSeparator=h;
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Root as e } from "../../../node_modules/@radix-ui/react-slot/dist/index.js";
|
|
3
3
|
import { useMergedRef as t } from "../../../hooks/useMergedRef.js";
|
|
4
|
-
import n from "
|
|
5
|
-
import r
|
|
6
|
-
import c from "
|
|
7
|
-
import
|
|
4
|
+
import { getRovingIndex as n } from "../../_internal/rovingIndex.js";
|
|
5
|
+
import r from "./toolbar.module.js";
|
|
6
|
+
import i, { useCallback as a, useEffect as o, useLayoutEffect as s, useRef as c } from "react";
|
|
7
|
+
import l from "classnames";
|
|
8
|
+
import { jsx as u } from "react/jsx-runtime";
|
|
8
9
|
//#region src/components/layout/Toolbar/Toolbar.tsx
|
|
9
|
-
var
|
|
10
|
-
let
|
|
11
|
-
let e =
|
|
10
|
+
var d = "button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]", f = "data-wim-toolbar-roving", p = /^(button|checkbox|radio|submit|reset|image|file|color)$/, m = (e) => e.tagName === "TEXTAREA" || e.tagName === "SELECT" || e.isContentEditable || e.tagName === "INPUT" && !p.test(e.type), h = (e) => Array.from(e.querySelectorAll(d)).filter((e) => !m(e) && !e.closest("[aria-hidden=\"true\"]") && (e.getAttribute("tabindex") !== "-1" || e.hasAttribute(f))), g = i.forwardRef(({ asChild: i = !1, size: d = "md", orientation: p = "horizontal", className: m, children: g, onKeyDownCapture: _, onFocus: v, ...y }, b) => {
|
|
11
|
+
let x = c(null), S = t(b, x), C = c(null), w = c(null), T = a(() => {
|
|
12
|
+
let e = x.current;
|
|
12
13
|
if (!e) return;
|
|
13
|
-
let t =
|
|
14
|
-
|
|
15
|
-
for (let e of t) e === r ? e.hasAttribute(
|
|
16
|
-
|
|
14
|
+
let t = h(e), n = document.activeElement, r = n && t.includes(n) ? n : C.current && t.includes(C.current) ? C.current : t[0];
|
|
15
|
+
C.current = r ?? null;
|
|
16
|
+
for (let e of t) e === r ? e.hasAttribute(f) && (e.removeAttribute(f), e.setAttribute("tabindex", "0")) : e.getAttribute("tabindex") !== "-1" && (e.setAttribute("tabindex", "-1"), e.setAttribute(f, ""));
|
|
17
|
+
w.current?.takeRecords();
|
|
17
18
|
}, []);
|
|
18
|
-
return
|
|
19
|
-
let e =
|
|
19
|
+
return s(T), o(() => {
|
|
20
|
+
let e = x.current;
|
|
20
21
|
if (!e) return;
|
|
21
|
-
let t = new MutationObserver(() =>
|
|
22
|
+
let t = new MutationObserver(() => T());
|
|
22
23
|
return t.observe(e, {
|
|
23
24
|
subtree: !0,
|
|
24
25
|
childList: !0,
|
|
@@ -28,59 +29,59 @@ var u = "button:not([disabled]), [href], input:not([disabled]), select:not([disa
|
|
|
28
29
|
"tabindex",
|
|
29
30
|
"aria-hidden"
|
|
30
31
|
]
|
|
31
|
-
}),
|
|
32
|
-
t.disconnect(),
|
|
32
|
+
}), w.current = t, () => {
|
|
33
|
+
t.disconnect(), w.current = null;
|
|
33
34
|
};
|
|
34
|
-
}, [
|
|
35
|
-
ref:
|
|
35
|
+
}, [T]), /* @__PURE__ */ u(i ? e : "div", {
|
|
36
|
+
ref: S,
|
|
36
37
|
role: "toolbar",
|
|
37
|
-
"aria-orientation":
|
|
38
|
-
"data-size":
|
|
39
|
-
"data-orientation":
|
|
40
|
-
className:
|
|
38
|
+
"aria-orientation": p,
|
|
39
|
+
"data-size": d,
|
|
40
|
+
"data-orientation": p,
|
|
41
|
+
className: l("wim-toolbar", r.root, r[`size-${d}`], r[p], m),
|
|
41
42
|
onKeyDownCapture: (e) => {
|
|
42
|
-
if (
|
|
43
|
-
let t =
|
|
43
|
+
if (_?.(e), e.defaultPrevented) return;
|
|
44
|
+
let t = x.current;
|
|
44
45
|
if (!t) return;
|
|
45
|
-
let
|
|
46
|
-
if (
|
|
47
|
-
let
|
|
48
|
-
if (
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
e.stopPropagation(),
|
|
46
|
+
let r = h(t);
|
|
47
|
+
if (r.length === 0) return;
|
|
48
|
+
let i = r.indexOf(document.activeElement);
|
|
49
|
+
if (i < 0) return;
|
|
50
|
+
let a = n({
|
|
51
|
+
key: e.key,
|
|
52
|
+
current: i,
|
|
53
|
+
count: r.length,
|
|
54
|
+
orientation: p
|
|
55
|
+
});
|
|
56
|
+
a !== null && (e.preventDefault(), e.stopPropagation(), r[a]?.focus());
|
|
56
57
|
},
|
|
57
58
|
onFocus: (e) => {
|
|
58
|
-
|
|
59
|
-
let t =
|
|
60
|
-
t && n !==
|
|
59
|
+
v?.(e);
|
|
60
|
+
let t = x.current, n = e.target;
|
|
61
|
+
t && n !== C.current && h(t).includes(n) && (C.current = n, T());
|
|
61
62
|
},
|
|
62
|
-
...
|
|
63
|
-
children:
|
|
63
|
+
...y,
|
|
64
|
+
children: g
|
|
64
65
|
});
|
|
65
66
|
});
|
|
66
|
-
|
|
67
|
-
var
|
|
67
|
+
g.displayName = "Toolbar";
|
|
68
|
+
var _ = i.forwardRef(({ asChild: t = !1, className: n, children: i, ...a }, o) => /* @__PURE__ */ u(t ? e : "div", {
|
|
68
69
|
ref: o,
|
|
69
70
|
role: "group",
|
|
70
|
-
className:
|
|
71
|
+
className: l(r.group, n),
|
|
71
72
|
...a,
|
|
72
73
|
children: i
|
|
73
74
|
}));
|
|
74
|
-
|
|
75
|
-
var
|
|
76
|
-
ref:
|
|
75
|
+
_.displayName = "Toolbar.Group";
|
|
76
|
+
var v = i.forwardRef(({ className: e, ...t }, n) => /* @__PURE__ */ u("div", {
|
|
77
|
+
ref: n,
|
|
77
78
|
role: "separator",
|
|
78
79
|
"aria-hidden": "true",
|
|
79
|
-
className:
|
|
80
|
+
className: l(r.separator, e),
|
|
80
81
|
...t
|
|
81
82
|
}));
|
|
82
|
-
|
|
83
|
-
var
|
|
84
|
-
|
|
83
|
+
v.displayName = "Toolbar.Separator";
|
|
84
|
+
var y = g;
|
|
85
|
+
y.Group = _, y.Separator = v;
|
|
85
86
|
//#endregion
|
|
86
|
-
export {
|
|
87
|
+
export { y as Toolbar, y as default, _ as ToolbarGroup, v as ToolbarSeparator };
|