wimui 0.40.0 → 0.42.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/data-display/TreeDiagram/TreeDiagram.cjs +2 -0
- package/dist/components/data-display/TreeDiagram/TreeDiagram.d.ts +107 -0
- package/dist/components/data-display/TreeDiagram/TreeDiagram.js +190 -0
- package/dist/components/data-display/TreeDiagram/layoutTree.cjs +2 -0
- package/dist/components/data-display/TreeDiagram/layoutTree.d.ts +62 -0
- package/dist/components/data-display/TreeDiagram/layoutTree.js +79 -0
- package/dist/components/data-display/TreeDiagram/tree-diagram.module.cjs +2 -0
- package/dist/components/data-display/TreeDiagram/tree-diagram.module.js +21 -0
- package/dist/components/form/ButtonGroup/ButtonGroup.cjs +1 -1
- package/dist/components/form/ButtonGroup/ButtonGroup.d.ts +3 -1
- package/dist/components/form/ButtonGroup/ButtonGroup.js +6 -5
- package/dist/components/form/ButtonGroup/button-group.module.cjs +1 -1
- package/dist/components/form/ButtonGroup/button-group.module.js +1 -1
- package/dist/components/overlay/Popover/Popover.cjs +1 -1
- package/dist/components/overlay/Popover/Popover.js +28 -19
- package/dist/data-display-core.d.ts +1 -0
- package/dist/data-display.cjs +1 -1
- package/dist/data-display.js +17 -16
- package/dist/i18n/generated/keys.d.ts +1 -1
- package/dist/i18n/generated/resources.cjs +1 -1
- package/dist/i18n/generated/resources.js +18 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +55 -54
- package/dist/llms-full.txt +17 -1
- package/dist/llms.txt +2 -1
- package/dist/locales/en/components.json +7 -1
- package/dist/locales/ja/components.json +7 -1
- package/dist/locales/pt/components.json +7 -1
- package/dist/styles.css +1 -1
- package/dist/wimui.umd.css +1 -1
- package/dist/wimui.umd.js +5 -5
- package/package.json +3 -3
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../../icon/minus.cjs"),r=require("../../media/Icon/Icon.cjs"),i=require("./layoutTree.cjs"),a=require("./tree-diagram.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=200,u=64,d=24,f=48,p=(e,t=[])=>{for(let n of e)n.children?.length&&(t.push(n.value),p(n.children,t));return t},m=(e,t=new Map)=>{for(let n of e)t.set(n.value,n),n.children&&m(n.children,t);return t},h=e=>typeof e.label==`string`?e.label:e.value,g=o.default.forwardRef(({nodes:e,orientation:g=`vertical`,expandedValues:_,defaultExpandedValues:v,onExpandedChange:y,selectedValue:b,onSelect:x,renderNode:S,nodeWidth:C=l,nodeHeight:w=u,labels:T,className:E,"aria-label":D,...O},k)=>{let{t:A}=t.useWimTranslation(`components`),j=o.default.useId(),M=T?.expand??(e=>A(`treediagram.expand`,{label:e})),N=T?.collapse??(e=>A(`treediagram.collapse`,{label:e})),[P,F]=(0,o.useState)(()=>v??p(e)),I=_??P,L=(0,o.useMemo)(()=>new Set(I),[I]),R=(0,o.useCallback)(e=>{_===void 0&&F(e),y?.(e)},[_,y]),z=(0,o.useCallback)(e=>R(L.has(e)?I.filter(t=>t!==e):[...I,e]),[I,L,R]),B=(0,o.useMemo)(()=>m(e),[e]),V=(0,o.useMemo)(()=>i.layoutTree(e,{nodeWidth:C,nodeHeight:w,siblingGap:d,levelGap:f,orientation:g,isExpanded:e=>L.has(e)}),[e,C,w,g,L]),H=(0,o.useMemo)(()=>new Map(V.nodes.map(e=>[e.value,e])),[V]),[U,W]=(0,o.useState)(null),G=U!==null&&H.has(U)?U:null,K=G??b??V.nodes[0]?.value??null,q=(0,o.useRef)(new Map),J=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(U===null||H.has(U))return;let e=U,t=e=>{for(let[t,n]of B)if(n.children?.some(t=>t.value===e))return t;return null};for(;e&&!H.has(e);)e=t(e);W(e??null),J.current=!0},[U,H,B]),(0,o.useEffect)(()=>{if(!J.current||G===null)return;J.current=!1;let e=q.current.get(G);e?.focus(),e?.scrollIntoView?.({block:`nearest`,inline:`nearest`})},[G]);let Y=e=>{e!==void 0&&(J.current=!0,W(e))},X=(e,t,n)=>{let r=V.nodes,i=L.has(t.value);switch(e.key){case`ArrowDown`:Y(r[n+1]?.value);break;case`ArrowUp`:Y(r[n-1]?.value);break;case`Home`:Y(r[0]?.value);break;case`End`:Y(r[r.length-1]?.value);break;case`ArrowRight`:t.hasChildren&&!i?z(t.value):t.hasChildren&&Y(r[n+1]?.value);break;case`ArrowLeft`:t.hasChildren&&i?z(t.value):t.parent!==null&&Y(t.parent);break;case`Enter`:case` `:if(!x)return;x(t.value);break;default:return}e.preventDefault()},Z=g===`vertical`,Q=(e,t)=>{if(Z){let n=e.x+C/2,r=e.y+w,i=t.x+C/2;return`M${n} ${r}V${r+f/2}H${i}V${t.y}`}let n=e.x+C,r=e.y+w/2,i=t.y+w/2;return`M${n} ${r}H${n+f/2}V${i}H${t.x}`};return(0,c.jsx)(`div`,{ref:k,role:`tree`,"aria-label":D??A(`treediagram.aria`),"aria-orientation":g,className:(0,s.default)(`wim-tree-diagram`,a.default.root,Z?a.default.vertical:a.default.horizontal,E),...O,children:(0,c.jsxs)(`div`,{className:a.default.canvas,style:{width:V.width,height:V.height},children:[(0,c.jsx)(`svg`,{className:a.default.edges,width:V.width,height:V.height,"aria-hidden":`true`,focusable:`false`,children:V.edges.map(e=>(0,c.jsx)(`path`,{d:Q(H.get(e.from),H.get(e.to))},`${e.from}>${e.to}`))}),V.nodes.map((e,t)=>{let i=B.get(e.value),o=L.has(e.value),l=b===e.value,u={depth:e.depth,expanded:o,selected:l,hiddenCount:e.hiddenCount},d=h(i);return(0,c.jsxs)(`div`,{ref:t=>{t?q.current.set(e.value,t):q.current.delete(e.value)},role:`treeitem`,"aria-level":e.depth+1,"aria-setsize":e.setSize,"aria-posinset":e.posInSet,"aria-expanded":e.hasChildren?o:void 0,"aria-selected":x?l:void 0,tabIndex:e.value===K?0:-1,"data-value":e.value,"aria-labelledby":S||!i.description?`${j}-${t}`:`${j}-${t} ${j}-${t}-d`,className:(0,s.default)(a.default.node,l&&a.default.selected,x&&a.default.selectable),style:{left:e.x,top:e.y,width:C,height:w},title:d,onKeyDown:n=>X(n,e,t),onFocus:()=>W(e.value),onClick:x?()=>x(e.value):void 0,children:[S?(0,c.jsx)(`span`,{id:`${j}-${t}`,className:a.default.custom,children:S(i,u)}):(0,c.jsxs)(`span`,{className:a.default.content,children:[i.avatar&&(0,c.jsx)(`span`,{className:a.default.avatar,children:i.avatar}),(0,c.jsxs)(`span`,{className:a.default.text,children:[(0,c.jsx)(`span`,{id:`${j}-${t}`,className:a.default.label,children:i.label}),i.description&&(0,c.jsx)(`span`,{id:`${j}-${t}-d`,className:a.default.description,children:i.description})]})]}),e.hasChildren&&(0,c.jsx)(`button`,{type:`button`,tabIndex:-1,className:a.default.toggle,"aria-label":o?N(d):M(d),onClick:t=>{t.stopPropagation(),z(e.value)},children:o?(0,c.jsx)(r.Icon,{component:n.default,size:`xs`}):`+${e.hiddenCount}`})]},e.value)})]})})});g.displayName=`TreeDiagram`,exports.TreeDiagram=g;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export type TreeDiagramNode = {
|
|
3
|
+
/** Unique across the whole diagram (used for expansion, selection and focus). */
|
|
4
|
+
value: string;
|
|
5
|
+
/** Main line of the card, e.g. a person's name. */
|
|
6
|
+
label: React.ReactNode;
|
|
7
|
+
/** Second line of the card, e.g. a job title. */
|
|
8
|
+
description?: React.ReactNode;
|
|
9
|
+
/** Leading visual, e.g. an `Avatar`. */
|
|
10
|
+
avatar?: React.ReactNode;
|
|
11
|
+
children?: TreeDiagramNode[];
|
|
12
|
+
};
|
|
13
|
+
export type TreeDiagramNodeState = {
|
|
14
|
+
depth: number;
|
|
15
|
+
expanded: boolean;
|
|
16
|
+
selected: boolean;
|
|
17
|
+
/** Descendants hidden because this node is collapsed (0 when expanded). */
|
|
18
|
+
hiddenCount: number;
|
|
19
|
+
};
|
|
20
|
+
export type TreeDiagramLabels = {
|
|
21
|
+
/** Accessible name of the collapse / expand button. */
|
|
22
|
+
expand?: (label: string) => string;
|
|
23
|
+
collapse?: (label: string) => string;
|
|
24
|
+
};
|
|
25
|
+
export type TreeDiagramProps = Omit<React.ComponentPropsWithoutRef<"div">, "children" | "onSelect"> & {
|
|
26
|
+
/** The roots of the tree. Several roots are laid out side by side. */
|
|
27
|
+
nodes: TreeDiagramNode[];
|
|
28
|
+
/**
|
|
29
|
+
* `vertical` grows from top to bottom (an org chart). `horizontal` grows from left to
|
|
30
|
+
* right, which suits deep trees and narrow containers.
|
|
31
|
+
*/
|
|
32
|
+
orientation?: "vertical" | "horizontal";
|
|
33
|
+
/** Expanded nodes (controlled). A node that is not listed shows only itself. */
|
|
34
|
+
expandedValues?: string[];
|
|
35
|
+
/** Expanded nodes on first render (uncontrolled). Defaults to every node that has children. */
|
|
36
|
+
defaultExpandedValues?: string[];
|
|
37
|
+
/** Called with the new list of expanded nodes when a node is expanded or collapsed. */
|
|
38
|
+
onExpandedChange?: (values: string[]) => void;
|
|
39
|
+
/** Selected node (controlled). Pass `null` for none. */
|
|
40
|
+
selectedValue?: string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Called when a node is chosen by click, Enter or Space. Nodes are only selectable when
|
|
43
|
+
* this is given; without it the diagram is read-only.
|
|
44
|
+
*/
|
|
45
|
+
onSelect?: (value: string) => void;
|
|
46
|
+
/** Replaces the default card (label, description, avatar). The card frame stays. */
|
|
47
|
+
renderNode?: (node: TreeDiagramNode, state: TreeDiagramNodeState) => React.ReactNode;
|
|
48
|
+
/**
|
|
49
|
+
* Card width in px. Every card has the same size so the layout is decided before
|
|
50
|
+
* anything is measured; long text is truncated and read in full by assistive technology.
|
|
51
|
+
*/
|
|
52
|
+
nodeWidth?: number;
|
|
53
|
+
/** Card height in px. */
|
|
54
|
+
nodeHeight?: number;
|
|
55
|
+
/** Accessible names of the collapse / expand button, for when the built-in translations do not fit. */
|
|
56
|
+
labels?: TreeDiagramLabels;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* TreeDiagram — lays out a tree (an org chart, a site map, a taxonomy) from the data alone:
|
|
60
|
+
* no coordinates are passed. Parents sit centred over their children and sibling subtrees
|
|
61
|
+
* never overlap. Subtrees can be collapsed.
|
|
62
|
+
*
|
|
63
|
+
* Keyboard follows the WAI-ARIA tree pattern, the same as `TreeView`: Up / Down move through
|
|
64
|
+
* the visible nodes in reading order, Right expands or moves to the first child, Left
|
|
65
|
+
* collapses or moves to the parent, Home / End jump to the first / last node, and Enter /
|
|
66
|
+
* Space select when `onSelect` is given.
|
|
67
|
+
*
|
|
68
|
+
* Only trees: every node has one parent. A family tree with two parents per person is a
|
|
69
|
+
* different layout problem and is out of scope.
|
|
70
|
+
*
|
|
71
|
+
* Composition Contract:
|
|
72
|
+
* - Managed by: App consumption
|
|
73
|
+
* - Scroll lock: No (the diagram scrolls inside its own box when it is wider than it)
|
|
74
|
+
*/
|
|
75
|
+
export declare const TreeDiagram: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "children" | "onSelect"> & {
|
|
76
|
+
/** The roots of the tree. Several roots are laid out side by side. */
|
|
77
|
+
nodes: TreeDiagramNode[];
|
|
78
|
+
/**
|
|
79
|
+
* `vertical` grows from top to bottom (an org chart). `horizontal` grows from left to
|
|
80
|
+
* right, which suits deep trees and narrow containers.
|
|
81
|
+
*/
|
|
82
|
+
orientation?: "vertical" | "horizontal";
|
|
83
|
+
/** Expanded nodes (controlled). A node that is not listed shows only itself. */
|
|
84
|
+
expandedValues?: string[];
|
|
85
|
+
/** Expanded nodes on first render (uncontrolled). Defaults to every node that has children. */
|
|
86
|
+
defaultExpandedValues?: string[];
|
|
87
|
+
/** Called with the new list of expanded nodes when a node is expanded or collapsed. */
|
|
88
|
+
onExpandedChange?: (values: string[]) => void;
|
|
89
|
+
/** Selected node (controlled). Pass `null` for none. */
|
|
90
|
+
selectedValue?: string | null;
|
|
91
|
+
/**
|
|
92
|
+
* Called when a node is chosen by click, Enter or Space. Nodes are only selectable when
|
|
93
|
+
* this is given; without it the diagram is read-only.
|
|
94
|
+
*/
|
|
95
|
+
onSelect?: (value: string) => void;
|
|
96
|
+
/** Replaces the default card (label, description, avatar). The card frame stays. */
|
|
97
|
+
renderNode?: (node: TreeDiagramNode, state: TreeDiagramNodeState) => React.ReactNode;
|
|
98
|
+
/**
|
|
99
|
+
* Card width in px. Every card has the same size so the layout is decided before
|
|
100
|
+
* anything is measured; long text is truncated and read in full by assistive technology.
|
|
101
|
+
*/
|
|
102
|
+
nodeWidth?: number;
|
|
103
|
+
/** Card height in px. */
|
|
104
|
+
nodeHeight?: number;
|
|
105
|
+
/** Accessible names of the collapse / expand button, for when the built-in translations do not fit. */
|
|
106
|
+
labels?: TreeDiagramLabels;
|
|
107
|
+
} & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useWimTranslation as e } from "../../../i18n/useWimTranslation.js";
|
|
3
|
+
import t from "../../../icon/minus.js";
|
|
4
|
+
import { Icon as n } from "../../media/Icon/Icon.js";
|
|
5
|
+
import { layoutTree as r } from "./layoutTree.js";
|
|
6
|
+
import i from "./tree-diagram.module.js";
|
|
7
|
+
import a, { useCallback as o, useEffect as s, useMemo as c, useRef as l, useState as u } from "react";
|
|
8
|
+
import d from "classnames";
|
|
9
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
10
|
+
//#region src/components/data-display/TreeDiagram/TreeDiagram.tsx
|
|
11
|
+
var m = 200, h = 64, g = 24, _ = 48, v = (e, t = []) => {
|
|
12
|
+
for (let n of e) n.children?.length && (t.push(n.value), v(n.children, t));
|
|
13
|
+
return t;
|
|
14
|
+
}, y = (e, t = /* @__PURE__ */ new Map()) => {
|
|
15
|
+
for (let n of e) t.set(n.value, n), n.children && y(n.children, t);
|
|
16
|
+
return t;
|
|
17
|
+
}, b = (e) => typeof e.label == "string" ? e.label : e.value, x = a.forwardRef(({ nodes: x, orientation: S = "vertical", expandedValues: C, defaultExpandedValues: w, onExpandedChange: T, selectedValue: E, onSelect: D, renderNode: O, nodeWidth: k = m, nodeHeight: A = h, labels: j, className: M, "aria-label": ee, ...te }, ne) => {
|
|
18
|
+
let { t: N } = e("components"), P = a.useId(), F = j?.expand ?? ((e) => N("treediagram.expand", { label: e })), I = j?.collapse ?? ((e) => N("treediagram.collapse", { label: e })), [L, R] = u(() => w ?? v(x)), z = C ?? L, B = c(() => new Set(z), [z]), V = o((e) => {
|
|
19
|
+
C === void 0 && R(e), T?.(e);
|
|
20
|
+
}, [C, T]), H = o((e) => V(B.has(e) ? z.filter((t) => t !== e) : [...z, e]), [
|
|
21
|
+
z,
|
|
22
|
+
B,
|
|
23
|
+
V
|
|
24
|
+
]), U = c(() => y(x), [x]), W = c(() => r(x, {
|
|
25
|
+
nodeWidth: k,
|
|
26
|
+
nodeHeight: A,
|
|
27
|
+
siblingGap: g,
|
|
28
|
+
levelGap: _,
|
|
29
|
+
orientation: S,
|
|
30
|
+
isExpanded: (e) => B.has(e)
|
|
31
|
+
}), [
|
|
32
|
+
x,
|
|
33
|
+
k,
|
|
34
|
+
A,
|
|
35
|
+
S,
|
|
36
|
+
B
|
|
37
|
+
]), G = c(() => new Map(W.nodes.map((e) => [e.value, e])), [W]), [K, q] = u(null), J = K !== null && G.has(K) ? K : null, Y = J ?? E ?? W.nodes[0]?.value ?? null, X = l(/* @__PURE__ */ new Map()), Z = l(!1);
|
|
38
|
+
s(() => {
|
|
39
|
+
if (K === null || G.has(K)) return;
|
|
40
|
+
let e = K, t = (e) => {
|
|
41
|
+
for (let [t, n] of U) if (n.children?.some((t) => t.value === e)) return t;
|
|
42
|
+
return null;
|
|
43
|
+
};
|
|
44
|
+
for (; e && !G.has(e);) e = t(e);
|
|
45
|
+
q(e ?? null), Z.current = !0;
|
|
46
|
+
}, [
|
|
47
|
+
K,
|
|
48
|
+
G,
|
|
49
|
+
U
|
|
50
|
+
]), s(() => {
|
|
51
|
+
if (!Z.current || J === null) return;
|
|
52
|
+
Z.current = !1;
|
|
53
|
+
let e = X.current.get(J);
|
|
54
|
+
e?.focus(), e?.scrollIntoView?.({
|
|
55
|
+
block: "nearest",
|
|
56
|
+
inline: "nearest"
|
|
57
|
+
});
|
|
58
|
+
}, [J]);
|
|
59
|
+
let Q = (e) => {
|
|
60
|
+
e !== void 0 && (Z.current = !0, q(e));
|
|
61
|
+
}, re = (e, t, n) => {
|
|
62
|
+
let r = W.nodes, i = B.has(t.value);
|
|
63
|
+
switch (e.key) {
|
|
64
|
+
case "ArrowDown":
|
|
65
|
+
Q(r[n + 1]?.value);
|
|
66
|
+
break;
|
|
67
|
+
case "ArrowUp":
|
|
68
|
+
Q(r[n - 1]?.value);
|
|
69
|
+
break;
|
|
70
|
+
case "Home":
|
|
71
|
+
Q(r[0]?.value);
|
|
72
|
+
break;
|
|
73
|
+
case "End":
|
|
74
|
+
Q(r[r.length - 1]?.value);
|
|
75
|
+
break;
|
|
76
|
+
case "ArrowRight":
|
|
77
|
+
t.hasChildren && !i ? H(t.value) : t.hasChildren && Q(r[n + 1]?.value);
|
|
78
|
+
break;
|
|
79
|
+
case "ArrowLeft":
|
|
80
|
+
t.hasChildren && i ? H(t.value) : t.parent !== null && Q(t.parent);
|
|
81
|
+
break;
|
|
82
|
+
case "Enter":
|
|
83
|
+
case " ":
|
|
84
|
+
if (!D) return;
|
|
85
|
+
D(t.value);
|
|
86
|
+
break;
|
|
87
|
+
default: return;
|
|
88
|
+
}
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
}, $ = S === "vertical", ie = (e, t) => {
|
|
91
|
+
if ($) {
|
|
92
|
+
let n = e.x + k / 2, r = e.y + A, i = t.x + k / 2;
|
|
93
|
+
return `M${n} ${r}V${r + _ / 2}H${i}V${t.y}`;
|
|
94
|
+
}
|
|
95
|
+
let n = e.x + k, r = e.y + A / 2, i = t.y + A / 2;
|
|
96
|
+
return `M${n} ${r}H${n + _ / 2}V${i}H${t.x}`;
|
|
97
|
+
};
|
|
98
|
+
return /* @__PURE__ */ f("div", {
|
|
99
|
+
ref: ne,
|
|
100
|
+
role: "tree",
|
|
101
|
+
"aria-label": ee ?? N("treediagram.aria"),
|
|
102
|
+
"aria-orientation": S,
|
|
103
|
+
className: d("wim-tree-diagram", i.root, $ ? i.vertical : i.horizontal, M),
|
|
104
|
+
...te,
|
|
105
|
+
children: /* @__PURE__ */ p("div", {
|
|
106
|
+
className: i.canvas,
|
|
107
|
+
style: {
|
|
108
|
+
width: W.width,
|
|
109
|
+
height: W.height
|
|
110
|
+
},
|
|
111
|
+
children: [/* @__PURE__ */ f("svg", {
|
|
112
|
+
className: i.edges,
|
|
113
|
+
width: W.width,
|
|
114
|
+
height: W.height,
|
|
115
|
+
"aria-hidden": "true",
|
|
116
|
+
focusable: "false",
|
|
117
|
+
children: W.edges.map((e) => /* @__PURE__ */ f("path", { d: ie(G.get(e.from), G.get(e.to)) }, `${e.from}>${e.to}`))
|
|
118
|
+
}), W.nodes.map((e, r) => {
|
|
119
|
+
let a = U.get(e.value), o = B.has(e.value), s = E === e.value, c = {
|
|
120
|
+
depth: e.depth,
|
|
121
|
+
expanded: o,
|
|
122
|
+
selected: s,
|
|
123
|
+
hiddenCount: e.hiddenCount
|
|
124
|
+
}, l = b(a);
|
|
125
|
+
return /* @__PURE__ */ p("div", {
|
|
126
|
+
ref: (t) => {
|
|
127
|
+
t ? X.current.set(e.value, t) : X.current.delete(e.value);
|
|
128
|
+
},
|
|
129
|
+
role: "treeitem",
|
|
130
|
+
"aria-level": e.depth + 1,
|
|
131
|
+
"aria-setsize": e.setSize,
|
|
132
|
+
"aria-posinset": e.posInSet,
|
|
133
|
+
"aria-expanded": e.hasChildren ? o : void 0,
|
|
134
|
+
"aria-selected": D ? s : void 0,
|
|
135
|
+
tabIndex: e.value === Y ? 0 : -1,
|
|
136
|
+
"data-value": e.value,
|
|
137
|
+
"aria-labelledby": O || !a.description ? `${P}-${r}` : `${P}-${r} ${P}-${r}-d`,
|
|
138
|
+
className: d(i.node, s && i.selected, D && i.selectable),
|
|
139
|
+
style: {
|
|
140
|
+
left: e.x,
|
|
141
|
+
top: e.y,
|
|
142
|
+
width: k,
|
|
143
|
+
height: A
|
|
144
|
+
},
|
|
145
|
+
title: l,
|
|
146
|
+
onKeyDown: (t) => re(t, e, r),
|
|
147
|
+
onFocus: () => q(e.value),
|
|
148
|
+
onClick: D ? () => D(e.value) : void 0,
|
|
149
|
+
children: [O ? /* @__PURE__ */ f("span", {
|
|
150
|
+
id: `${P}-${r}`,
|
|
151
|
+
className: i.custom,
|
|
152
|
+
children: O(a, c)
|
|
153
|
+
}) : /* @__PURE__ */ p("span", {
|
|
154
|
+
className: i.content,
|
|
155
|
+
children: [a.avatar && /* @__PURE__ */ f("span", {
|
|
156
|
+
className: i.avatar,
|
|
157
|
+
children: a.avatar
|
|
158
|
+
}), /* @__PURE__ */ p("span", {
|
|
159
|
+
className: i.text,
|
|
160
|
+
children: [/* @__PURE__ */ f("span", {
|
|
161
|
+
id: `${P}-${r}`,
|
|
162
|
+
className: i.label,
|
|
163
|
+
children: a.label
|
|
164
|
+
}), a.description && /* @__PURE__ */ f("span", {
|
|
165
|
+
id: `${P}-${r}-d`,
|
|
166
|
+
className: i.description,
|
|
167
|
+
children: a.description
|
|
168
|
+
})]
|
|
169
|
+
})]
|
|
170
|
+
}), e.hasChildren && /* @__PURE__ */ f("button", {
|
|
171
|
+
type: "button",
|
|
172
|
+
tabIndex: -1,
|
|
173
|
+
className: i.toggle,
|
|
174
|
+
"aria-label": o ? I(l) : F(l),
|
|
175
|
+
onClick: (t) => {
|
|
176
|
+
t.stopPropagation(), H(e.value);
|
|
177
|
+
},
|
|
178
|
+
children: o ? /* @__PURE__ */ f(n, {
|
|
179
|
+
component: t,
|
|
180
|
+
size: "xs"
|
|
181
|
+
}) : `+${e.hiddenCount}`
|
|
182
|
+
})]
|
|
183
|
+
}, e.value);
|
|
184
|
+
})]
|
|
185
|
+
})
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
x.displayName = "TreeDiagram";
|
|
189
|
+
//#endregion
|
|
190
|
+
export { x as TreeDiagram };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var e=t=>(t.children??[]).reduce((t,n)=>t+1+e(n),0);function t(t,n){let{nodeWidth:r,nodeHeight:i,siblingGap:a,levelGap:o,orientation:s,isExpanded:c}=n,l=s===`vertical`?r:i,u=s===`vertical`?i:r,d=l+a,f=e=>{let t=[],n=[];e.forEach((e,r)=>{let i=0;if(r>0){i=-1/0;let t=Math.min(n.length,e.left.length);for(let r=0;r<t;r++)i=Math.max(i,n[r]-e.left[r]+d)}e.offset=i,e.left.forEach((e,n)=>{(t[n]===void 0||e+i<t[n])&&(t[n]=e+i)}),e.right.forEach((e,t)=>{(n[t]===void 0||e+i>n[t])&&(n[t]=e+i)})});let r=e.length?(e[0].offset+e[e.length-1].offset)/2:0;return e.forEach(e=>e.offset-=r),{items:e,left:t.map(e=>e-r),right:n.map(e=>e-r)}},p=e=>{let t=c(e.value)?e.children??[]:[],n=f(t.map(p));return{source:e,offset:0,children:n.items,left:[0,...n.left],right:[0,...n.right]}},m=f(t.map(p)),h=[],g=[],_=[],v=0,y=(t,n,r,i,a,o)=>{let s=(t.source.children?.length??0)>0;h.push({value:t.source.value,x:0,y:0,depth:r,parent:i,hasChildren:s,hiddenCount:s&&t.children.length===0?e(t.source):0,posInSet:a,setSize:o}),g.push(n),v=Math.max(v,r),t.children.forEach((e,i)=>{_.push({from:t.source.value,to:e.source.value}),y(e,n+e.offset,r+1,t.source.value,i+1,t.children.length)})};if(m.items.forEach((e,t)=>y(e,e.offset,0,null,t+1,m.items.length)),h.length===0)return{nodes:h,edges:_,width:0,height:0};let b=Math.min(...g),x=Math.max(...g);h.forEach((e,t)=>{let n=g[t]-b,r=e.depth*(u+o);s===`vertical`?(e.x=n,e.y=r):(e.x=r,e.y=n)});let S=x-b+l,C=(v+1)*u+v*o;return s===`vertical`?{nodes:h,edges:_,width:S,height:C}:{nodes:h,edges:_,width:C,height:S}}exports.layoutTree=t;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 木の自動配置(tidy tree)。
|
|
3
|
+
*
|
|
4
|
+
* 描画から切り離した純粋な関数で、座標は「幅方向(breadth)× 深さ方向(depth)」で
|
|
5
|
+
* 計算してから、`orientation` に合わせて x / y に写す。縦(上から下)なら幅方向が x、
|
|
6
|
+
* 横(左から右)なら幅方向が y になる。
|
|
7
|
+
*
|
|
8
|
+
* 約束(`layoutTree.test.ts` が見る):
|
|
9
|
+
* 1. 兄弟の部分木は、どの深さでも `siblingGap` 以上離れて重ならない
|
|
10
|
+
* 2. 親は、見えている子の列の中央(最初の子と最後の子の中点)に置く
|
|
11
|
+
* 3. 同じ深さのノードは、深さ方向の同じ位置に並ぶ
|
|
12
|
+
* 4. 折りたたんだノードの子孫は配置しない
|
|
13
|
+
*
|
|
14
|
+
* 手法は Reingold–Tilford の考え方そのまま ── 部分木ごとに「深さごとの左端・右端」
|
|
15
|
+
* (輪郭)を持ち、次の兄弟を、左の兄弟たちの右の輪郭にぶつからない所まで右へずらす。
|
|
16
|
+
* 輪郭の比較は深さの数だけかかるので O(ノード数 × 深さ)。組織図の規模(数百)では
|
|
17
|
+
* 十分速く、Buchheim の線形時間版の複雑さ(スレッド・ancestor の付け替え)を持たない。
|
|
18
|
+
* 兄弟の間の余りを均す処理(Walker の apportion)はしない ── 狭い部分木どうしの間に
|
|
19
|
+
* 広い部分木があるときに間隔が左右で不揃いになりうるが、重なりは起きない。
|
|
20
|
+
*/
|
|
21
|
+
export type TreeLayoutInput = {
|
|
22
|
+
value: string;
|
|
23
|
+
children?: TreeLayoutInput[];
|
|
24
|
+
};
|
|
25
|
+
export type TreeLayoutNode = {
|
|
26
|
+
value: string;
|
|
27
|
+
/** 描画座標(ノードの左上)。 */
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
depth: number;
|
|
31
|
+
parent: string | null;
|
|
32
|
+
/** 子を持つか(折りたたみ中でも true)。 */
|
|
33
|
+
hasChildren: boolean;
|
|
34
|
+
/** 折りたたんで隠している子孫の数。開いていれば 0。 */
|
|
35
|
+
hiddenCount: number;
|
|
36
|
+
/** 兄弟の中での位置(1 始まり)と兄弟の数。`aria-posinset` / `aria-setsize` に使う。 */
|
|
37
|
+
posInSet: number;
|
|
38
|
+
setSize: number;
|
|
39
|
+
};
|
|
40
|
+
export type TreeLayoutEdge = {
|
|
41
|
+
from: string;
|
|
42
|
+
to: string;
|
|
43
|
+
};
|
|
44
|
+
export type TreeLayoutOptions = {
|
|
45
|
+
nodeWidth: number;
|
|
46
|
+
nodeHeight: number;
|
|
47
|
+
/** 兄弟(幅方向)の間隔。 */
|
|
48
|
+
siblingGap: number;
|
|
49
|
+
/** 親子(深さ方向)の間隔。 */
|
|
50
|
+
levelGap: number;
|
|
51
|
+
orientation: "vertical" | "horizontal";
|
|
52
|
+
/** 開いているか。false のノードは子孫を配置しない。 */
|
|
53
|
+
isExpanded: (value: string) => boolean;
|
|
54
|
+
};
|
|
55
|
+
export type TreeLayoutResult = {
|
|
56
|
+
/** 前順(親 → 子、兄弟は左から)。キーボードの「次に見えているノード」の順と同じ。 */
|
|
57
|
+
nodes: TreeLayoutNode[];
|
|
58
|
+
edges: TreeLayoutEdge[];
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
};
|
|
62
|
+
export declare function layoutTree(roots: TreeLayoutInput[], options: TreeLayoutOptions): TreeLayoutResult;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region src/components/data-display/TreeDiagram/layoutTree.ts
|
|
3
|
+
var e = (t) => (t.children ?? []).reduce((t, n) => t + 1 + e(n), 0);
|
|
4
|
+
function t(t, n) {
|
|
5
|
+
let { nodeWidth: r, nodeHeight: i, siblingGap: a, levelGap: o, orientation: s, isExpanded: c } = n, l = s === "vertical" ? r : i, u = s === "vertical" ? i : r, d = l + a, f = (e) => {
|
|
6
|
+
let t = [], n = [];
|
|
7
|
+
e.forEach((e, r) => {
|
|
8
|
+
let i = 0;
|
|
9
|
+
if (r > 0) {
|
|
10
|
+
i = -Infinity;
|
|
11
|
+
let t = Math.min(n.length, e.left.length);
|
|
12
|
+
for (let r = 0; r < t; r++) i = Math.max(i, n[r] - e.left[r] + d);
|
|
13
|
+
}
|
|
14
|
+
e.offset = i, e.left.forEach((e, n) => {
|
|
15
|
+
(t[n] === void 0 || e + i < t[n]) && (t[n] = e + i);
|
|
16
|
+
}), e.right.forEach((e, t) => {
|
|
17
|
+
(n[t] === void 0 || e + i > n[t]) && (n[t] = e + i);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
let r = e.length ? (e[0].offset + e[e.length - 1].offset) / 2 : 0;
|
|
21
|
+
return e.forEach((e) => e.offset -= r), {
|
|
22
|
+
items: e,
|
|
23
|
+
left: t.map((e) => e - r),
|
|
24
|
+
right: n.map((e) => e - r)
|
|
25
|
+
};
|
|
26
|
+
}, p = (e) => {
|
|
27
|
+
let t = c(e.value) ? e.children ?? [] : [], n = f(t.map(p));
|
|
28
|
+
return {
|
|
29
|
+
source: e,
|
|
30
|
+
offset: 0,
|
|
31
|
+
children: n.items,
|
|
32
|
+
left: [0, ...n.left],
|
|
33
|
+
right: [0, ...n.right]
|
|
34
|
+
};
|
|
35
|
+
}, m = f(t.map(p)), h = [], g = [], _ = [], v = 0, y = (t, n, r, i, a, o) => {
|
|
36
|
+
let s = (t.source.children?.length ?? 0) > 0;
|
|
37
|
+
h.push({
|
|
38
|
+
value: t.source.value,
|
|
39
|
+
x: 0,
|
|
40
|
+
y: 0,
|
|
41
|
+
depth: r,
|
|
42
|
+
parent: i,
|
|
43
|
+
hasChildren: s,
|
|
44
|
+
hiddenCount: s && t.children.length === 0 ? e(t.source) : 0,
|
|
45
|
+
posInSet: a,
|
|
46
|
+
setSize: o
|
|
47
|
+
}), g.push(n), v = Math.max(v, r), t.children.forEach((e, i) => {
|
|
48
|
+
_.push({
|
|
49
|
+
from: t.source.value,
|
|
50
|
+
to: e.source.value
|
|
51
|
+
}), y(e, n + e.offset, r + 1, t.source.value, i + 1, t.children.length);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
if (m.items.forEach((e, t) => y(e, e.offset, 0, null, t + 1, m.items.length)), h.length === 0) return {
|
|
55
|
+
nodes: h,
|
|
56
|
+
edges: _,
|
|
57
|
+
width: 0,
|
|
58
|
+
height: 0
|
|
59
|
+
};
|
|
60
|
+
let b = Math.min(...g), x = Math.max(...g);
|
|
61
|
+
h.forEach((e, t) => {
|
|
62
|
+
let n = g[t] - b, r = e.depth * (u + o);
|
|
63
|
+
s === "vertical" ? (e.x = n, e.y = r) : (e.x = r, e.y = n);
|
|
64
|
+
});
|
|
65
|
+
let S = x - b + l, C = (v + 1) * u + v * o;
|
|
66
|
+
return s === "vertical" ? {
|
|
67
|
+
nodes: h,
|
|
68
|
+
edges: _,
|
|
69
|
+
width: S,
|
|
70
|
+
height: C
|
|
71
|
+
} : {
|
|
72
|
+
nodes: h,
|
|
73
|
+
edges: _,
|
|
74
|
+
width: C,
|
|
75
|
+
height: S
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { t as layoutTree };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var e=`_root_smsot_4`,t=`_canvas_smsot_10`,n=`_edges_smsot_14`,r=`_node_smsot_25`,i=`_selectable_smsot_42`,a=`_selected_smsot_48`,o=`_content_smsot_52`,s=`_custom_smsot_53`,c=`_avatar_smsot_60`,l=`_text_smsot_64`,u=`_label_smsot_70`,d=`_description_smsot_71`,f=`_toggle_smsot_85`,p=`_vertical_smsot_106`,m=`_horizontal_smsot_111`,h={root:e,canvas:t,edges:n,node:r,selectable:i,selected:a,content:o,custom:s,avatar:c,text:l,label:u,description:d,toggle:f,vertical:p,horizontal:m};exports.avatar=c,exports.canvas=t,exports.content=o,exports.custom=s,exports.default=h,exports.description=d,exports.edges=n,exports.horizontal=m,exports.label=u,exports.node=r,exports.root=e,exports.selectable=i,exports.selected=a,exports.text=l,exports.toggle=f,exports.vertical=p;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region src/components/data-display/TreeDiagram/tree-diagram.module.scss
|
|
3
|
+
var e = "_root_smsot_4", t = "_canvas_smsot_10", n = "_edges_smsot_14", r = "_node_smsot_25", i = "_selectable_smsot_42", a = "_selected_smsot_48", o = "_content_smsot_52", s = "_custom_smsot_53", c = "_avatar_smsot_60", l = "_text_smsot_64", u = "_label_smsot_70", d = "_description_smsot_71", f = "_toggle_smsot_85", p = "_vertical_smsot_106", m = "_horizontal_smsot_111", h = {
|
|
4
|
+
root: e,
|
|
5
|
+
canvas: t,
|
|
6
|
+
edges: n,
|
|
7
|
+
node: r,
|
|
8
|
+
selectable: i,
|
|
9
|
+
selected: a,
|
|
10
|
+
content: o,
|
|
11
|
+
custom: s,
|
|
12
|
+
avatar: c,
|
|
13
|
+
text: l,
|
|
14
|
+
label: u,
|
|
15
|
+
description: d,
|
|
16
|
+
toggle: f,
|
|
17
|
+
vertical: p,
|
|
18
|
+
horizontal: m
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { c as avatar, t as canvas, o as content, s as custom, h as default, d as description, n as edges, m as horizontal, u as label, r as node, e as root, i as selectable, a as selected, l as text, f as toggle, p as vertical };
|
|
@@ -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("./button-group.module.cjs");let r=require("react");r=e.__toESM(r,1);let i=require("classnames");i=e.__toESM(i,1);let a=require("react/jsx-runtime");var o=({children:e,gap:o=`8px`,className:s,joined:c=!1,variant:l,asChild:
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("./button-group.module.cjs");let r=require("react");r=e.__toESM(r,1);let i=require("classnames");i=e.__toESM(i,1);let a=require("react/jsx-runtime");var o=({children:e,gap:o=`8px`,className:s,joined:c=!1,variant:l,justify:u=`start`,asChild:d=!1})=>{let f=c?{}:{gap:o},p=!d&&l?r.default.Children.map(e,e=>r.default.isValidElement(e)?r.default.cloneElement(e,{variant:l}):e):e;return(0,a.jsx)(d?t.Root:`div`,{className:(0,i.default)(`wim-button-group`,n.default.root,c&&n.default.joined,s),style:f,"data-justify":u,children:p})};exports.ButtonGroup=o;
|
|
@@ -11,8 +11,10 @@ type ButtonGroupProps = {
|
|
|
11
11
|
joined?: boolean;
|
|
12
12
|
/** Variant applied to all child buttons */
|
|
13
13
|
variant?: ButtonVariant;
|
|
14
|
+
/** Where the buttons sit on the row. `start` keeps the group as wide as its buttons, so it lines up with other content; `center` / `end` / `stretch` take the full row (`stretch` grows every button to share it). */
|
|
15
|
+
justify?: "start" | "center" | "end" | "stretch";
|
|
14
16
|
/** Whether to render as a child element. */
|
|
15
17
|
asChild?: boolean;
|
|
16
18
|
};
|
|
17
|
-
export declare const ButtonGroup: ({ children, gap, className, joined, variant, asChild, }: ButtonGroupProps) => React.JSX.Element;
|
|
19
|
+
export declare const ButtonGroup: ({ children, gap, className, joined, variant, justify, asChild, }: ButtonGroupProps) => React.JSX.Element;
|
|
18
20
|
export {};
|
|
@@ -5,12 +5,13 @@ import n from "react";
|
|
|
5
5
|
import r from "classnames";
|
|
6
6
|
import { jsx as i } from "react/jsx-runtime";
|
|
7
7
|
//#region src/components/form/ButtonGroup/ButtonGroup.tsx
|
|
8
|
-
var a = ({ children: a, gap: o = "8px", className: s, joined: c = !1, variant: l,
|
|
9
|
-
let
|
|
10
|
-
return /* @__PURE__ */ i(
|
|
8
|
+
var a = ({ children: a, gap: o = "8px", className: s, joined: c = !1, variant: l, justify: u = "start", asChild: d = !1 }) => {
|
|
9
|
+
let f = c ? {} : { gap: o }, p = !d && l ? n.Children.map(a, (e) => n.isValidElement(e) ? n.cloneElement(e, { variant: l }) : e) : a;
|
|
10
|
+
return /* @__PURE__ */ i(d ? e : "div", {
|
|
11
11
|
className: r("wim-button-group", t.root, c && t.joined, s),
|
|
12
|
-
style:
|
|
13
|
-
|
|
12
|
+
style: f,
|
|
13
|
+
"data-justify": u,
|
|
14
|
+
children: p
|
|
14
15
|
});
|
|
15
16
|
};
|
|
16
17
|
//#endregion
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var e=`
|
|
2
|
+
var e=`_root_13irk_4`,t=`_joined_13irk_23`,n={root:e,joined:t};exports.default=n,exports.joined=t,exports.root=e;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../layout/Transition/Transition.cjs"),r=require("../../../icon/close.cjs"),i=require("../../media/Icon/Icon.cjs"),a=require("./popover.module.cjs"),o=require("../../_internal/useFloatingElement.cjs");let s=require("react");s=e.__toESM(s,1);let c=require("classnames");c=e.__toESM(c,1);let l=require("react/jsx-runtime"),u=require("@floating-ui/react");var d=s.default.createContext(null),f=({children:e,className:t,defaultOpen:n=!1,open:r,onOpenChange:i,placement:
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../layout/Transition/Transition.cjs"),r=require("../../../icon/close.cjs"),i=require("../../media/Icon/Icon.cjs"),a=require("./popover.module.cjs"),o=require("../../_internal/useFloatingElement.cjs");let s=require("react");s=e.__toESM(s,1);let c=require("classnames");c=e.__toESM(c,1);let l=require("react/jsx-runtime"),u=require("@floating-ui/react");var d=s.default.createContext(null),f=({children:e,className:t,defaultOpen:n=!1,open:r,onOpenChange:i,placement:u=`bottom-start`,variant:f=`default`})=>{let{isOpen:p,setOpen:m,refs:h,floatingStyles:g,context:_,getReferenceProps:v,getFloatingProps:y}=o.useFloatingElement({placement:u,open:r,defaultOpen:n,onOpenChange:i,trigger:`click`}),b=()=>m(!1),x=s.default.useId(),[S,C]=s.default.useState(`wim-popover-trigger-${x}`);return(0,l.jsx)(d.Provider,{value:{open:p,onOpenChange:m,refs:h,floatingStyles:g,context:_,getReferenceProps:v,getFloatingProps:y,close:b,variant:f,triggerId:S,setTriggerId:C},children:(0,l.jsx)(`div`,{className:(0,c.default)(`wim-popover`,a.default.root,t),children:e})})},p=s.default.forwardRef(({children:e,className:t,asChild:n,...r},i)=>{let o=s.default.useContext(d);if(o==null)throw Error(`Popover components must be wrapped in <Popover />`);let f=e.ref,p=(0,u.useMergeRefs)([o.refs.setReference,i,f??null]),m=n&&s.default.isValidElement(e)?e.props.id:void 0,h=r.id??m??o.triggerId,{setTriggerId:g}=o;if(s.default.useLayoutEffect(()=>{g(h)},[h,g]),n&&s.default.isValidElement(e)){let n=e.props,i=o.getReferenceProps({ref:p,...r,...n,id:h,className:(0,c.default)(t,n.className)});return s.default.cloneElement(e,{...i,"data-state":o.open?`open`:`closed`})}return(0,l.jsx)(`button`,{ref:p,type:`button`,className:(0,c.default)(a.default.trigger,t),"data-state":o.open?`open`:`closed`,...o.getReferenceProps({...r,id:h}),children:e})});p.displayName=`PopoverTrigger`;var m=s.default.forwardRef(({children:e,className:t,align:r,side:i,style:o,modal:f=!1,...p},m)=>{let h=s.default.useContext(d);if(h==null)throw Error(`Popover components must be wrapped in <Popover />`);let{open:g,refs:_,floatingStyles:v,getFloatingProps:y,context:b,triggerId:x}=h,S=p[`aria-label`]!=null||p[`aria-labelledby`]!=null?p[`aria-labelledby`]:x,C=(0,u.useMergeRefs)([_.setFloating,m]);return(0,l.jsx)(u.FloatingPortal,{children:(0,l.jsx)(n.Transition,{show:g,preset:`fade`,children:(0,l.jsx)(u.FloatingFocusManager,{context:b,modal:f,children:(0,l.jsx)(`div`,{ref:C,style:{...v,...o},className:(0,c.default)(a.default.content,a.default[h.variant],t),role:`dialog`,...y(p),"aria-labelledby":S,children:e})})})})});m.displayName=`PopoverContent`;var h=({children:e,className:n,asChild:o,ariaLabel:u,...f})=>{let{t:p}=t.useWimTranslation(`common`),m=u??p(`a11y.close`),h=s.default.useContext(d);if(!h)return null;let{close:g}=h,_=e=>{g(),f.onClick?.(e)};return o&&s.default.isValidElement(e)?s.default.cloneElement(e,{onClick:t=>{e.props.onClick?.(t),_(t)},className:(0,c.default)(n,e.props.className)}):(0,l.jsx)(`button`,{type:`button`,className:(0,c.default)(a.default.close,n),onClick:_,"aria-label":m,...f,children:e||(0,l.jsx)(i.Icon,{component:r.default,size:`sm`})})};exports.Popover=f,exports.PopoverClose=h,exports.PopoverContent=m,exports.PopoverTrigger=p;
|
|
@@ -10,25 +10,27 @@ import s from "classnames";
|
|
|
10
10
|
import { jsx as c } from "react/jsx-runtime";
|
|
11
11
|
import { FloatingFocusManager as l, FloatingPortal as u, useMergeRefs as d } from "@floating-ui/react";
|
|
12
12
|
//#region src/components/overlay/Popover/Popover.tsx
|
|
13
|
-
var f = o.createContext(null), p = ({ children: e, className: t, defaultOpen: n = !1, open: r, onOpenChange:
|
|
14
|
-
let { isOpen:
|
|
15
|
-
placement:
|
|
13
|
+
var f = o.createContext(null), p = ({ children: e, className: t, defaultOpen: n = !1, open: r, onOpenChange: l, placement: u = "bottom-start", variant: d = "default" }) => {
|
|
14
|
+
let { isOpen: p, setOpen: m, refs: h, floatingStyles: g, context: _, getReferenceProps: v, getFloatingProps: y } = a({
|
|
15
|
+
placement: u,
|
|
16
16
|
open: r,
|
|
17
17
|
defaultOpen: n,
|
|
18
|
-
onOpenChange:
|
|
18
|
+
onOpenChange: l,
|
|
19
19
|
trigger: "click"
|
|
20
|
-
});
|
|
20
|
+
}), b = () => m(!1), x = o.useId(), [S, C] = o.useState(`wim-popover-trigger-${x}`);
|
|
21
21
|
return /* @__PURE__ */ c(f.Provider, {
|
|
22
22
|
value: {
|
|
23
|
-
open:
|
|
24
|
-
onOpenChange:
|
|
25
|
-
refs:
|
|
26
|
-
floatingStyles:
|
|
27
|
-
context:
|
|
28
|
-
getReferenceProps:
|
|
29
|
-
getFloatingProps:
|
|
30
|
-
close:
|
|
31
|
-
variant:
|
|
23
|
+
open: p,
|
|
24
|
+
onOpenChange: m,
|
|
25
|
+
refs: h,
|
|
26
|
+
floatingStyles: g,
|
|
27
|
+
context: _,
|
|
28
|
+
getReferenceProps: v,
|
|
29
|
+
getFloatingProps: y,
|
|
30
|
+
close: b,
|
|
31
|
+
variant: d,
|
|
32
|
+
triggerId: S,
|
|
33
|
+
setTriggerId: C
|
|
32
34
|
},
|
|
33
35
|
children: /* @__PURE__ */ c("div", {
|
|
34
36
|
className: s("wim-popover", i.root, t),
|
|
@@ -42,12 +44,15 @@ var f = o.createContext(null), p = ({ children: e, className: t, defaultOpen: n
|
|
|
42
44
|
l.refs.setReference,
|
|
43
45
|
a,
|
|
44
46
|
u ?? null
|
|
45
|
-
]);
|
|
46
|
-
if (
|
|
47
|
+
]), m = n && o.isValidElement(e) ? e.props.id : void 0, h = r.id ?? m ?? l.triggerId, { setTriggerId: g } = l;
|
|
48
|
+
if (o.useLayoutEffect(() => {
|
|
49
|
+
g(h);
|
|
50
|
+
}, [h, g]), n && o.isValidElement(e)) {
|
|
47
51
|
let n = e.props, i = l.getReferenceProps({
|
|
48
52
|
ref: p,
|
|
49
53
|
...r,
|
|
50
54
|
...n,
|
|
55
|
+
id: h,
|
|
51
56
|
className: s(t, n.className)
|
|
52
57
|
});
|
|
53
58
|
return o.cloneElement(e, {
|
|
@@ -60,7 +65,10 @@ var f = o.createContext(null), p = ({ children: e, className: t, defaultOpen: n
|
|
|
60
65
|
type: "button",
|
|
61
66
|
className: s(i.trigger, t),
|
|
62
67
|
"data-state": l.open ? "open" : "closed",
|
|
63
|
-
...l.getReferenceProps(
|
|
68
|
+
...l.getReferenceProps({
|
|
69
|
+
...r,
|
|
70
|
+
id: h
|
|
71
|
+
}),
|
|
64
72
|
children: e
|
|
65
73
|
});
|
|
66
74
|
});
|
|
@@ -68,7 +76,7 @@ m.displayName = "PopoverTrigger";
|
|
|
68
76
|
var h = o.forwardRef(({ children: e, className: n, align: r, side: a, style: p, modal: m = !1, ...h }, g) => {
|
|
69
77
|
let _ = o.useContext(f);
|
|
70
78
|
if (_ == null) throw Error("Popover components must be wrapped in <Popover />");
|
|
71
|
-
let { open: v, refs: y, floatingStyles: b, getFloatingProps: x, context: S } = _, C = d([y.setFloating, g]);
|
|
79
|
+
let { open: v, refs: y, floatingStyles: b, getFloatingProps: x, context: S, triggerId: C } = _, w = h["aria-label"] != null || h["aria-labelledby"] != null ? h["aria-labelledby"] : C, T = d([y.setFloating, g]);
|
|
72
80
|
return /* @__PURE__ */ c(u, { children: /* @__PURE__ */ c(t, {
|
|
73
81
|
show: v,
|
|
74
82
|
preset: "fade",
|
|
@@ -76,7 +84,7 @@ var h = o.forwardRef(({ children: e, className: n, align: r, side: a, style: p,
|
|
|
76
84
|
context: S,
|
|
77
85
|
modal: m,
|
|
78
86
|
children: /* @__PURE__ */ c("div", {
|
|
79
|
-
ref:
|
|
87
|
+
ref: T,
|
|
80
88
|
style: {
|
|
81
89
|
...b,
|
|
82
90
|
...p
|
|
@@ -84,6 +92,7 @@ var h = o.forwardRef(({ children: e, className: n, align: r, side: a, style: p,
|
|
|
84
92
|
className: s(i.content, i[_.variant], n),
|
|
85
93
|
role: "dialog",
|
|
86
94
|
...x(h),
|
|
95
|
+
"aria-labelledby": w,
|
|
87
96
|
children: e
|
|
88
97
|
})
|
|
89
98
|
})
|