@ifhover/leaf-ui 0.16.6 → 0.17.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/cjs/browser/modules/card/card.cjs +29 -14
- package/dist/cjs/browser/modules/card/card.cjs.map +1 -1
- package/dist/cjs/browser/modules/confirm/confirm.cjs +2 -2
- package/dist/cjs/browser/modules/confirm/confirm.cjs.map +1 -1
- package/dist/cjs/browser/modules/drawer/drawer.cjs +120 -61
- package/dist/cjs/browser/modules/drawer/drawer.cjs.map +1 -1
- package/dist/cjs/browser/modules/filelist/filelist.cjs +2 -2
- package/dist/cjs/browser/modules/filelist/filelist.cjs.map +1 -1
- package/dist/cjs/browser/modules/modal/base.cjs +287 -0
- package/dist/cjs/browser/modules/modal/base.cjs.map +1 -0
- package/dist/cjs/browser/modules/modal/modal.cjs +64 -209
- package/dist/cjs/browser/modules/modal/modal.cjs.map +1 -1
- package/dist/cjs/browser/modules/shared/presence.cjs +12 -6
- package/dist/cjs/browser/modules/shared/presence.cjs.map +1 -1
- package/dist/cjs/browser/modules/tabletanstack/tabletanstack.cjs +14 -2
- package/dist/cjs/browser/modules/tabletanstack/tabletanstack.cjs.map +1 -1
- package/dist/cjs/browser/modules/tabs/tabs.cjs +194 -174
- package/dist/cjs/browser/modules/tabs/tabs.cjs.map +1 -1
- package/dist/cjs/card/card.cjs +29 -14
- package/dist/cjs/card/card.cjs.map +1 -1
- package/dist/cjs/card/card.d.cts.map +1 -1
- package/dist/cjs/confirm/confirm.cjs +2 -2
- package/dist/cjs/confirm/confirm.cjs.map +1 -1
- package/dist/cjs/drawer/drawer.cjs +120 -61
- package/dist/cjs/drawer/drawer.cjs.map +1 -1
- package/dist/cjs/drawer/drawer.d.cts +6 -0
- package/dist/cjs/drawer/drawer.d.cts.map +1 -1
- package/dist/cjs/drawer/index.d.cts +1 -1
- package/dist/cjs/drawer/index.d.cts.map +1 -1
- package/dist/cjs/filelist/filelist.cjs +2 -2
- package/dist/cjs/filelist/filelist.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/index.d.cts.map +1 -1
- package/dist/cjs/modal/base.cjs +285 -0
- package/dist/cjs/modal/base.cjs.map +1 -0
- package/dist/cjs/modal/base.d.cts +23 -0
- package/dist/cjs/modal/base.d.cts.map +1 -0
- package/dist/cjs/modal/index.d.cts +1 -1
- package/dist/cjs/modal/index.d.cts.map +1 -1
- package/dist/cjs/modal/modal.cjs +64 -209
- package/dist/cjs/modal/modal.cjs.map +1 -1
- package/dist/cjs/modal/modal.d.cts +8 -3
- package/dist/cjs/modal/modal.d.cts.map +1 -1
- package/dist/cjs/shared/presence.cjs +12 -6
- package/dist/cjs/shared/presence.cjs.map +1 -1
- package/dist/cjs/shared/presence.d.cts +1 -1
- package/dist/cjs/shared/presence.d.cts.map +1 -1
- package/dist/cjs/styles/card.css +1 -1
- package/dist/cjs/styles/colorpicker.css +1 -1
- package/dist/cjs/styles/components/card.css +1 -1
- package/dist/cjs/styles/components/drawer.css +1 -1
- package/dist/cjs/styles/components/modal.css +1 -1
- package/dist/cjs/styles/components/tabletanstack.css +1 -1
- package/dist/cjs/styles/components/tabs.css +1 -1
- package/dist/cjs/styles/config-provider.css +1 -1
- package/dist/cjs/styles/confirm.css +1 -1
- package/dist/cjs/styles/daterangepicker.css +1 -1
- package/dist/cjs/styles/drawer.css +1 -1
- package/dist/cjs/styles/filelist.css +1 -1
- package/dist/cjs/styles/index.css +79 -22
- package/dist/cjs/styles/index.css.map +1 -1
- package/dist/cjs/styles/modal.css +1 -1
- package/dist/cjs/styles/tabletanstack.css +1 -1
- package/dist/cjs/styles/tabs.css +1 -1
- package/dist/cjs/styles/upload.css +1 -1
- package/dist/cjs/tabletanstack/tabletanstack.cjs +14 -2
- package/dist/cjs/tabletanstack/tabletanstack.cjs.map +1 -1
- package/dist/cjs/tabletanstack/tabletanstack.d.cts.map +1 -1
- package/dist/cjs/tabs/tabs.cjs +194 -174
- package/dist/cjs/tabs/tabs.cjs.map +1 -1
- package/dist/cjs/tabs/tabs.d.cts +14 -1
- package/dist/cjs/tabs/tabs.d.cts.map +1 -1
- package/dist/esm/browser/modules/card/card.js +30 -15
- package/dist/esm/browser/modules/card/card.js.map +1 -1
- package/dist/esm/browser/modules/confirm/confirm.js +1 -1
- package/dist/esm/browser/modules/confirm/confirm.js.map +1 -1
- package/dist/esm/browser/modules/drawer/drawer.js +121 -62
- package/dist/esm/browser/modules/drawer/drawer.js.map +1 -1
- package/dist/esm/browser/modules/filelist/filelist.js +1 -1
- package/dist/esm/browser/modules/filelist/filelist.js.map +1 -1
- package/dist/esm/browser/modules/modal/base.js +249 -0
- package/dist/esm/browser/modules/modal/base.js.map +1 -0
- package/dist/esm/browser/modules/modal/modal.js +65 -207
- package/dist/esm/browser/modules/modal/modal.js.map +1 -1
- package/dist/esm/browser/modules/shared/presence.js +12 -6
- package/dist/esm/browser/modules/shared/presence.js.map +1 -1
- package/dist/esm/browser/modules/tabletanstack/tabletanstack.js +14 -2
- package/dist/esm/browser/modules/tabletanstack/tabletanstack.js.map +1 -1
- package/dist/esm/browser/modules/tabs/tabs.js +190 -173
- package/dist/esm/browser/modules/tabs/tabs.js.map +1 -1
- package/dist/esm/card/card.d.ts.map +1 -1
- package/dist/esm/card/card.js +30 -15
- package/dist/esm/card/card.js.map +1 -1
- package/dist/esm/confirm/confirm.js +1 -1
- package/dist/esm/confirm/confirm.js.map +1 -1
- package/dist/esm/drawer/drawer.d.ts +6 -0
- package/dist/esm/drawer/drawer.d.ts.map +1 -1
- package/dist/esm/drawer/drawer.js +121 -62
- package/dist/esm/drawer/drawer.js.map +1 -1
- package/dist/esm/drawer/index.d.ts +1 -1
- package/dist/esm/drawer/index.d.ts.map +1 -1
- package/dist/esm/filelist/filelist.js +1 -1
- package/dist/esm/filelist/filelist.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/modal/base.d.ts +23 -0
- package/dist/esm/modal/base.d.ts.map +1 -0
- package/dist/esm/modal/base.js +247 -0
- package/dist/esm/modal/base.js.map +1 -0
- package/dist/esm/modal/index.d.ts +1 -1
- package/dist/esm/modal/index.d.ts.map +1 -1
- package/dist/esm/modal/modal.d.ts +8 -3
- package/dist/esm/modal/modal.d.ts.map +1 -1
- package/dist/esm/modal/modal.js +65 -207
- package/dist/esm/modal/modal.js.map +1 -1
- package/dist/esm/shared/presence.d.ts +1 -1
- package/dist/esm/shared/presence.d.ts.map +1 -1
- package/dist/esm/shared/presence.js +12 -6
- package/dist/esm/shared/presence.js.map +1 -1
- package/dist/esm/styles/card.css +1 -1
- package/dist/esm/styles/colorpicker.css +1 -1
- package/dist/esm/styles/components/card.css +1 -1
- package/dist/esm/styles/components/drawer.css +1 -1
- package/dist/esm/styles/components/modal.css +1 -1
- package/dist/esm/styles/components/tabletanstack.css +1 -1
- package/dist/esm/styles/components/tabs.css +1 -1
- package/dist/esm/styles/config-provider.css +1 -1
- package/dist/esm/styles/confirm.css +1 -1
- package/dist/esm/styles/daterangepicker.css +1 -1
- package/dist/esm/styles/drawer.css +1 -1
- package/dist/esm/styles/filelist.css +1 -1
- package/dist/esm/styles/index.css +79 -22
- package/dist/esm/styles/index.css.map +1 -1
- package/dist/esm/styles/modal.css +1 -1
- package/dist/esm/styles/tabletanstack.css +1 -1
- package/dist/esm/styles/tabs.css +1 -1
- package/dist/esm/styles/upload.css +1 -1
- package/dist/esm/tabletanstack/tabletanstack.d.ts.map +1 -1
- package/dist/esm/tabletanstack/tabletanstack.js +14 -2
- package/dist/esm/tabletanstack/tabletanstack.js.map +1 -1
- package/dist/esm/tabs/tabs.d.ts +14 -1
- package/dist/esm/tabs/tabs.d.ts.map +1 -1
- package/dist/esm/tabs/tabs.js +190 -173
- package/dist/esm/tabs/tabs.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,215 +1,67 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import '../../../styles/foundation.css';
|
|
3
3
|
import '../../../styles/components/modal.css';
|
|
4
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
import {
|
|
6
|
-
import { useEffect, useId, useRef, useState } from "react";
|
|
7
|
-
import { ButtonControl } from "../button/button.js";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
8
6
|
import { useComponentProps } from "../config-provider/component-defaults.js";
|
|
9
|
-
import { useLeafConfig } from "../config-provider/context.js";
|
|
10
7
|
import { ScrollbarControl } from "../scrollbar/scrollbar.js";
|
|
11
8
|
import { classes } from "../shared/classes.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const { messages, maskBlur } = useLeafConfig();
|
|
19
|
-
const [pending, setPending] = useState(false);
|
|
20
|
-
const [error, setError] = useState();
|
|
21
|
-
const mounted = useRef(true);
|
|
22
|
-
const accepting = useRef(false);
|
|
23
|
-
const generation = useRef(0);
|
|
24
|
-
useEffect(()=>{
|
|
25
|
-
mounted.current = true;
|
|
26
|
-
return ()=>{
|
|
27
|
-
mounted.current = false;
|
|
28
|
-
};
|
|
29
|
-
}, []);
|
|
30
|
-
useEffect(()=>{
|
|
31
|
-
generation.current++;
|
|
32
|
-
accepting.current = false;
|
|
33
|
-
setPending(false);
|
|
34
|
-
if (open) setError(void 0);
|
|
35
|
-
}, [
|
|
36
|
-
open
|
|
37
|
-
]);
|
|
38
|
-
const busy = pending || confirmLoading;
|
|
39
|
-
async function accept() {
|
|
40
|
-
if (accepting.current || busy) return;
|
|
41
|
-
if (!onConfirm) {
|
|
42
|
-
if (confirmButtonProps?.type !== 'submit') onClose?.();
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
accepting.current = true;
|
|
46
|
-
const request = generation.current;
|
|
47
|
-
setPending(true);
|
|
48
|
-
setError(void 0);
|
|
49
|
-
try {
|
|
50
|
-
await onConfirm();
|
|
51
|
-
} catch (reason) {
|
|
52
|
-
if (mounted.current && generation.current === request) setError(reason instanceof Error ? reason.message : String(reason));
|
|
53
|
-
} finally{
|
|
54
|
-
if (generation.current === request) {
|
|
55
|
-
accepting.current = false;
|
|
56
|
-
if (mounted.current) setPending(false);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const cancel = ()=>{
|
|
61
|
-
if (!busy) (onCancel ?? onClose)?.();
|
|
62
|
-
};
|
|
63
|
-
const actions = {
|
|
64
|
-
cancelButton: /*#__PURE__*/ jsx(ButtonControl, {
|
|
65
|
-
type: "button",
|
|
66
|
-
variant: "outline",
|
|
67
|
-
...cancelButtonProps,
|
|
68
|
-
disabled: busy || cancelButtonProps?.disabled,
|
|
69
|
-
onClick: (event)=>{
|
|
70
|
-
cancelButtonProps?.onClick?.(event);
|
|
71
|
-
if (!event.defaultPrevented) cancel();
|
|
72
|
-
},
|
|
73
|
-
children: cancelText ?? messages.common.cancel
|
|
74
|
-
}),
|
|
75
|
-
confirmButton: /*#__PURE__*/ jsx(ButtonControl, {
|
|
76
|
-
type: "button",
|
|
77
|
-
variant: "solid",
|
|
78
|
-
...confirmButtonProps,
|
|
79
|
-
loading: busy || confirmButtonProps?.loading,
|
|
80
|
-
onClick: (event)=>{
|
|
81
|
-
confirmButtonProps?.onClick?.(event);
|
|
82
|
-
if (!event.defaultPrevented) accept();
|
|
83
|
-
},
|
|
84
|
-
children: confirmText ?? messages.common.confirm
|
|
85
|
-
})
|
|
86
|
-
};
|
|
87
|
-
const renderedFooter = 'function' == typeof footer ? footer(actions) : void 0 === footer ? /*#__PURE__*/ jsxs("div", {
|
|
88
|
-
className: "leaf-modal__actions",
|
|
9
|
+
import { useTabsParts } from "../tabs/tabs.js";
|
|
10
|
+
import { ModalBase } from "./base.js";
|
|
11
|
+
const useBrowserLayoutEffect = "u" < typeof window ? useEffect : useLayoutEffect;
|
|
12
|
+
function ModalTabsLayout({ open, tabs, title, titleId, hasHeading, closeButton, contentRef, snapHeight, ariaLabel, ariaLabelledBy, scrollbarLabel, scrollbarLabelledBy, error, children }) {
|
|
13
|
+
const tabExtra = hasHeading || null == closeButton ? tabs.extra : /*#__PURE__*/ jsxs("div", {
|
|
14
|
+
className: "leaf-dialog-tab-extra leaf-modal__tab-extra",
|
|
89
15
|
children: [
|
|
90
|
-
|
|
91
|
-
|
|
16
|
+
tabs.extra,
|
|
17
|
+
closeButton
|
|
92
18
|
]
|
|
93
|
-
})
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
19
|
+
});
|
|
20
|
+
const tabLabel = tabs['aria-label'] ?? ('string' == typeof title ? title : ariaLabel);
|
|
21
|
+
const tabLabelledBy = tabs['aria-labelledby'] ?? (null == tabs['aria-label'] && null != title ? titleId : null == tabs['aria-label'] ? ariaLabelledBy : void 0);
|
|
22
|
+
const parts = useTabsParts({
|
|
23
|
+
...tabs,
|
|
24
|
+
type: 'line',
|
|
25
|
+
placement: 'top',
|
|
26
|
+
size: tabs.size ?? 'md',
|
|
27
|
+
'aria-label': tabLabel,
|
|
28
|
+
'aria-labelledby': tabLabelledBy,
|
|
29
|
+
extra: tabExtra,
|
|
30
|
+
className: classes('leaf-dialog-tabs', hasHeading && 'leaf-dialog-tabs--headed', 'leaf-modal__tabs', tabs.className),
|
|
31
|
+
panelsClassName: 'leaf-dialog-panels',
|
|
32
|
+
visibilityKey: open
|
|
33
|
+
});
|
|
34
|
+
const previousSelected = useRef(parts?.selected);
|
|
35
|
+
useBrowserLayoutEffect(()=>{
|
|
36
|
+
if (previousSelected.current === parts?.selected) return;
|
|
37
|
+
previousSelected.current = parts?.selected;
|
|
38
|
+
snapHeight();
|
|
108
39
|
}, [
|
|
109
|
-
|
|
110
|
-
|
|
40
|
+
parts?.selected,
|
|
41
|
+
snapHeight
|
|
111
42
|
]);
|
|
112
|
-
|
|
113
|
-
initialFocus,
|
|
114
|
-
returnFocus
|
|
115
|
-
});
|
|
116
|
-
const visited = useRef(false);
|
|
117
|
-
if (open) visited.current = true;
|
|
118
|
-
if (!present && !forceRender && ((void 0 === preserve ? destroyOnClose : !preserve) || !visited.current)) return null;
|
|
119
|
-
return /*#__PURE__*/ jsxs("div", {
|
|
120
|
-
hidden: !present,
|
|
121
|
-
className: "leaf-modal-mask",
|
|
122
|
-
"data-blur": maskBlur ? void 0 : 'off',
|
|
123
|
-
"data-state": open ? 'open' : 'closing',
|
|
124
|
-
"aria-hidden": !open || void 0,
|
|
125
|
-
...inertProps(!open),
|
|
43
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
126
44
|
children: [
|
|
127
|
-
/*#__PURE__*/ jsx("
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
className: "leaf-modal-backdrop",
|
|
131
|
-
tabIndex: -1,
|
|
132
|
-
"aria-label": messages.common.close,
|
|
133
|
-
onClick: ()=>{
|
|
134
|
-
if (maskClosable) close.current?.();
|
|
135
|
-
}
|
|
45
|
+
parts && /*#__PURE__*/ jsx("div", {
|
|
46
|
+
...parts.rootProps,
|
|
47
|
+
children: parts.header
|
|
136
48
|
}),
|
|
137
|
-
/*#__PURE__*/ jsx(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
"aria-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
null != description && descriptionId
|
|
147
|
-
].filter(Boolean).join(' ') || void 0,
|
|
148
|
-
tabIndex: -1,
|
|
149
|
-
className: classes('leaf-modal', divided && 'leaf-modal--divided', className),
|
|
150
|
-
style: {
|
|
151
|
-
width,
|
|
152
|
-
...style
|
|
153
|
-
},
|
|
154
|
-
children: /*#__PURE__*/ jsxs(OverlayOwner.Provider, {
|
|
155
|
-
value: modalId,
|
|
49
|
+
(parts?.hasPanels || null != children && false !== children || null != error) && /*#__PURE__*/ jsx(ScrollbarControl, {
|
|
50
|
+
className: "leaf-modal__body",
|
|
51
|
+
viewportClassName: "leaf-modal__viewport",
|
|
52
|
+
orientation: "vertical",
|
|
53
|
+
"aria-labelledby": scrollbarLabelledBy,
|
|
54
|
+
"aria-label": scrollbarLabel,
|
|
55
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
56
|
+
ref: contentRef,
|
|
57
|
+
className: "leaf-modal__content",
|
|
156
58
|
children: [
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
children: icon
|
|
164
|
-
}),
|
|
165
|
-
(null != title || null != description) && /*#__PURE__*/ jsxs("div", {
|
|
166
|
-
className: "leaf-modal__heading",
|
|
167
|
-
children: [
|
|
168
|
-
null != title && /*#__PURE__*/ jsx("h2", {
|
|
169
|
-
id: titleId,
|
|
170
|
-
children: title
|
|
171
|
-
}),
|
|
172
|
-
null != description && /*#__PURE__*/ jsx("div", {
|
|
173
|
-
id: descriptionId,
|
|
174
|
-
className: "leaf-modal__description",
|
|
175
|
-
children: description
|
|
176
|
-
})
|
|
177
|
-
]
|
|
178
|
-
}),
|
|
179
|
-
closable && /*#__PURE__*/ jsx("button", {
|
|
180
|
-
type: "button",
|
|
181
|
-
className: "leaf-modal__close",
|
|
182
|
-
"aria-label": messages.common.close,
|
|
183
|
-
onClick: ()=>close.current?.(),
|
|
184
|
-
children: /*#__PURE__*/ jsx(X, {
|
|
185
|
-
size: 18,
|
|
186
|
-
"aria-hidden": "true"
|
|
187
|
-
})
|
|
188
|
-
})
|
|
189
|
-
]
|
|
190
|
-
}),
|
|
191
|
-
(null != children && false !== children || null != error) && /*#__PURE__*/ jsx(ScrollbarControl, {
|
|
192
|
-
className: "leaf-modal__body",
|
|
193
|
-
viewportClassName: "leaf-modal__viewport",
|
|
194
|
-
orientation: "vertical",
|
|
195
|
-
"aria-labelledby": null != title ? titleId : void 0,
|
|
196
|
-
"aria-label": null == title ? props['aria-label'] ?? messages.common.confirm : void 0,
|
|
197
|
-
children: /*#__PURE__*/ jsxs("div", {
|
|
198
|
-
ref: content,
|
|
199
|
-
className: "leaf-modal__content",
|
|
200
|
-
children: [
|
|
201
|
-
children,
|
|
202
|
-
error && /*#__PURE__*/ jsx("p", {
|
|
203
|
-
role: "alert",
|
|
204
|
-
className: "leaf-confirm-error",
|
|
205
|
-
children: error
|
|
206
|
-
})
|
|
207
|
-
]
|
|
208
|
-
})
|
|
209
|
-
}),
|
|
210
|
-
null != renderedFooter && /*#__PURE__*/ jsx("div", {
|
|
211
|
-
className: "leaf-modal__footer",
|
|
212
|
-
children: renderedFooter
|
|
59
|
+
parts?.panels,
|
|
60
|
+
children,
|
|
61
|
+
error && /*#__PURE__*/ jsx("p", {
|
|
62
|
+
role: "alert",
|
|
63
|
+
className: "leaf-confirm-error",
|
|
64
|
+
children: error
|
|
213
65
|
})
|
|
214
66
|
]
|
|
215
67
|
})
|
|
@@ -217,20 +69,26 @@ function ModalSurface({ open, title, description, icon, divided = true, footer,
|
|
|
217
69
|
]
|
|
218
70
|
});
|
|
219
71
|
}
|
|
220
|
-
function
|
|
221
|
-
return /*#__PURE__*/ jsx(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
72
|
+
function ModalControl({ divided = true, confirmLoading = false, width = 480, closable = true, maskClosable = true, keyboard = true, forceRender = false, destroyOnClose = false, ...props }) {
|
|
73
|
+
return /*#__PURE__*/ jsx(ModalBase, {
|
|
74
|
+
...props,
|
|
75
|
+
divided: divided,
|
|
76
|
+
confirmLoading: confirmLoading,
|
|
77
|
+
width: width,
|
|
78
|
+
closable: closable,
|
|
79
|
+
maskClosable: maskClosable,
|
|
80
|
+
keyboard: keyboard,
|
|
81
|
+
forceRender: forceRender,
|
|
82
|
+
destroyOnClose: destroyOnClose,
|
|
83
|
+
renderTabsLayout: ModalTabsLayout
|
|
226
84
|
});
|
|
227
85
|
}
|
|
228
86
|
function Modal(rawProps) {
|
|
229
87
|
const props = useComponentProps('Modal', rawProps);
|
|
230
|
-
return /*#__PURE__*/ jsx(
|
|
88
|
+
return /*#__PURE__*/ jsx(ModalControl, {
|
|
231
89
|
...props
|
|
232
90
|
});
|
|
233
91
|
}
|
|
234
|
-
export { Modal
|
|
92
|
+
export { Modal };
|
|
235
93
|
|
|
236
94
|
//# sourceMappingURL=modal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal/modal.js","sources":["../../../../../src/modal/modal.tsx"],"sourcesContent":["import { X } from 'lucide-react';\nimport { type HTMLAttributes, type ReactNode, useEffect, useId, useRef, useState } from 'react';\nimport { ButtonControl, type ButtonProps } from '../button/button';\nimport { useComponentProps } from '../config-provider/component-defaults';\nimport { useLeafConfig } from '../config-provider/context';\nimport { ScrollbarControl as Scrollbar } from '../scrollbar/scrollbar';\nimport { classes } from '../shared/classes';\nimport { type DialogFocusOptions, useDialog } from '../shared/dialog';\nimport { inertProps } from '../shared/inert';\nimport { OverlayOwner } from '../shared/overlay-owner';\nimport { useNaturalHeightTransition, usePresence } from '../shared/presence';\nimport { ScopedPortal } from '../shared/scoped-portal';\n\nexport interface ModalFooterActions {\n confirmButton: ReactNode;\n cancelButton: ReactNode;\n}\nexport interface ModalProps\n extends Omit<HTMLAttributes<HTMLDivElement>, 'title'>,\n DialogFocusOptions {\n open: boolean;\n title?: ReactNode;\n /** Supporting text displayed below the title. */\n description?: ReactNode;\n /** Decorative header icon. */\n icon?: ReactNode;\n /** Separate the header and footer with subtle borders. */\n divided?: boolean;\n footer?: ReactNode | ((actions: ModalFooterActions) => ReactNode);\n confirmText?: ReactNode;\n cancelText?: ReactNode;\n confirmLoading?: boolean;\n confirmButtonProps?: ButtonProps;\n cancelButtonProps?: ButtonProps;\n onConfirm?: () => void | Promise<void>;\n onCancel?: () => void;\n width?: number | string;\n closable?: boolean;\n maskClosable?: boolean;\n keyboard?: boolean;\n onClose?: () => void;\n afterClose?: () => void;\n forceRender?: boolean;\n destroyOnClose?: boolean;\n preserve?: boolean;\n container?: Element | DocumentFragment | (() => Element | DocumentFragment);\n}\n\nfunction ModalSurface({\n open,\n title,\n description,\n icon,\n divided = true,\n footer,\n confirmText,\n cancelText,\n confirmLoading = false,\n confirmButtonProps,\n cancelButtonProps,\n onConfirm,\n onCancel,\n width = 480,\n closable = true,\n maskClosable = true,\n keyboard = true,\n onClose,\n afterClose,\n forceRender = false,\n destroyOnClose = false,\n preserve,\n initialFocus,\n returnFocus,\n container: _container,\n children,\n className,\n style,\n ...props\n}: ModalProps) {\n const { messages, maskBlur } = useLeafConfig();\n const [pending, setPending] = useState(false);\n const [error, setError] = useState<string>();\n const mounted = useRef(true);\n const accepting = useRef(false);\n const generation = useRef(0);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n useEffect(() => {\n generation.current++;\n accepting.current = false;\n setPending(false);\n if (open) setError(undefined);\n }, [open]);\n const busy = pending || confirmLoading;\n async function accept() {\n if (accepting.current || busy) return;\n if (!onConfirm) {\n if (confirmButtonProps?.type !== 'submit') onClose?.();\n return;\n }\n accepting.current = true;\n const request = generation.current;\n setPending(true);\n setError(undefined);\n try {\n await onConfirm();\n } catch (reason) {\n if (mounted.current && generation.current === request)\n setError(reason instanceof Error ? reason.message : String(reason));\n } finally {\n if (generation.current === request) {\n accepting.current = false;\n if (mounted.current) setPending(false);\n }\n }\n }\n const cancel = () => {\n if (!busy) (onCancel ?? onClose)?.();\n };\n const actions: ModalFooterActions = {\n cancelButton: (\n <ButtonControl\n type=\"button\"\n variant=\"outline\"\n {...cancelButtonProps}\n disabled={busy || cancelButtonProps?.disabled}\n onClick={(event) => {\n cancelButtonProps?.onClick?.(event);\n if (!event.defaultPrevented) cancel();\n }}\n >\n {cancelText ?? messages.common.cancel}\n </ButtonControl>\n ),\n confirmButton: (\n <ButtonControl\n type=\"button\"\n variant=\"solid\"\n {...confirmButtonProps}\n loading={busy || confirmButtonProps?.loading}\n onClick={(event) => {\n confirmButtonProps?.onClick?.(event);\n if (!event.defaultPrevented) void accept();\n }}\n >\n {confirmText ?? messages.common.confirm}\n </ButtonControl>\n ),\n };\n const renderedFooter =\n typeof footer === 'function' ? (\n footer(actions)\n ) : footer === undefined ? (\n <div className=\"leaf-modal__actions\">\n {actions.cancelButton}\n {actions.confirmButton}\n </div>\n ) : (\n footer\n );\n const panel = useRef<HTMLDivElement>(null);\n const content = useRef<HTMLDivElement>(null);\n const backdrop = useRef<HTMLButtonElement>(null);\n const present = usePresence(open, backdrop);\n useNaturalHeightTransition(panel, content, open);\n const titleId = `${useId()}-title`;\n const descriptionId = `${useId()}-description`;\n const modalId = `${useId()}-dialog`;\n const close = useRef(cancel);\n close.current = cancel;\n const wasPresent = useRef(false);\n useEffect(() => {\n if (wasPresent.current && !present) afterClose?.();\n wasPresent.current = present;\n }, [present, afterClose]);\n useDialog(open, panel, modalId, cancel, keyboard, { initialFocus, returnFocus });\n const visited = useRef(false);\n if (open) visited.current = true;\n if (\n !present &&\n !forceRender &&\n ((preserve === undefined ? destroyOnClose : !preserve) || !visited.current)\n )\n return null;\n return (\n <div\n hidden={!present}\n className=\"leaf-modal-mask\"\n data-blur={maskBlur ? undefined : 'off'}\n data-state={open ? 'open' : 'closing'}\n aria-hidden={!open || undefined}\n {...inertProps(!open)}\n >\n <button\n ref={backdrop}\n type=\"button\"\n className=\"leaf-modal-backdrop\"\n tabIndex={-1}\n aria-label={messages.common.close}\n onClick={() => {\n if (maskClosable) close.current?.();\n }}\n />\n {/* biome-ignore lint/a11y/useAriaPropsSupportedByRole: dialog and alertdialog both support aria-modal. */}\n <div\n {...props}\n ref={panel}\n id={props.id ?? modalId}\n role={props.role ?? 'dialog'}\n aria-modal=\"true\"\n aria-labelledby={title != null ? titleId : props['aria-labelledby']}\n aria-describedby={\n [props['aria-describedby'], description != null && descriptionId]\n .filter(Boolean)\n .join(' ') || undefined\n }\n tabIndex={-1}\n className={classes('leaf-modal', divided && 'leaf-modal--divided', className)}\n style={{ width, ...style }}\n >\n <OverlayOwner.Provider value={modalId}>\n {(title != null || description != null || icon != null || closable) && (\n <div\n className={classes(\n 'leaf-modal__header',\n description == null && 'leaf-modal__header--simple',\n icon != null && 'leaf-modal__header--icon',\n title == null &&\n description == null &&\n icon == null &&\n 'leaf-modal__header--compact',\n )}\n >\n {icon != null && (\n <span className=\"leaf-modal__icon\" aria-hidden=\"true\">\n {icon}\n </span>\n )}\n {(title != null || description != null) && (\n <div className=\"leaf-modal__heading\">\n {title != null && <h2 id={titleId}>{title}</h2>}\n {description != null && (\n <div id={descriptionId} className=\"leaf-modal__description\">\n {description}\n </div>\n )}\n </div>\n )}\n {closable && (\n <button\n type=\"button\"\n className=\"leaf-modal__close\"\n aria-label={messages.common.close}\n onClick={() => close.current?.()}\n >\n <X size={18} aria-hidden=\"true\" />\n </button>\n )}\n </div>\n )}\n {((children != null && children !== false) || error != null) && (\n <Scrollbar\n className=\"leaf-modal__body\"\n viewportClassName=\"leaf-modal__viewport\"\n orientation=\"vertical\"\n aria-labelledby={title != null ? titleId : undefined}\n aria-label={\n title == null ? (props['aria-label'] ?? messages.common.confirm) : undefined\n }\n >\n <div ref={content} className=\"leaf-modal__content\">\n {children}\n {error && (\n <p role=\"alert\" className=\"leaf-confirm-error\">\n {error}\n </p>\n )}\n </div>\n </Scrollbar>\n )}\n {renderedFooter != null && <div className=\"leaf-modal__footer\">{renderedFooter}</div>}\n </OverlayOwner.Provider>\n </div>\n </div>\n );\n}\n// Other components reuse the dialog mechanics without inheriting public Modal defaults.\nexport function ModalBase(props: ModalProps) {\n return (\n <ScopedPortal container={props.container}>\n <ModalSurface {...props} />\n </ScopedPortal>\n );\n}\nexport function Modal(rawProps: ModalProps) {\n const props = useComponentProps('Modal', rawProps);\n return <ModalBase {...props} />;\n}\n"],"names":["ModalSurface","open","title","description","icon","divided","footer","confirmText","cancelText","confirmLoading","confirmButtonProps","cancelButtonProps","onConfirm","onCancel","width","closable","maskClosable","keyboard","onClose","afterClose","forceRender","destroyOnClose","preserve","initialFocus","returnFocus","_container","children","className","style","props","messages","maskBlur","useLeafConfig","pending","setPending","useState","error","setError","mounted","useRef","accepting","generation","useEffect","undefined","busy","accept","request","reason","Error","String","cancel","actions","ButtonControl","event","renderedFooter","panel","content","backdrop","present","usePresence","useNaturalHeightTransition","titleId","useId","descriptionId","modalId","close","wasPresent","useDialog","visited","inertProps","Boolean","classes","OverlayOwner","X","Scrollbar","ModalBase","ScopedPortal","Modal","rawProps","useComponentProps"],"mappings":";;;;;;;;;;;;;;;;AAgDA,SAASA,aAAa,EACpBC,IAAI,EACJC,KAAK,EACLC,WAAW,EACXC,IAAI,EACJC,UAAU,IAAI,EACdC,MAAM,EACNC,WAAW,EACXC,UAAU,EACVC,iBAAiB,KAAK,EACtBC,kBAAkB,EAClBC,iBAAiB,EACjBC,SAAS,EACTC,QAAQ,EACRC,QAAQ,GAAG,EACXC,WAAW,IAAI,EACfC,eAAe,IAAI,EACnBC,WAAW,IAAI,EACfC,OAAO,EACPC,UAAU,EACVC,cAAc,KAAK,EACnBC,iBAAiB,KAAK,EACtBC,QAAQ,EACRC,YAAY,EACZC,WAAW,EACX,WAAWC,UAAU,EACrBC,QAAQ,EACRC,SAAS,EACTC,KAAK,EACL,GAAGC,OACQ;IACX,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGC;IAC/B,MAAM,CAACC,SAASC,WAAW,GAAGC,SAAS;IACvC,MAAM,CAACC,OAAOC,SAAS,GAAGF;IAC1B,MAAMG,UAAUC,OAAO;IACvB,MAAMC,YAAYD,OAAO;IACzB,MAAME,aAAaF,OAAO;IAC1BG,UAAU;QACRJ,QAAQ,OAAO,GAAG;QAClB,OAAO;YACLA,QAAQ,OAAO,GAAG;QACpB;IACF,GAAG,EAAE;IACLI,UAAU;QACRD,WAAW,OAAO;QAClBD,UAAU,OAAO,GAAG;QACpBN,WAAW;QACX,IAAIjC,M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YAAoBA,AAAa,UAAbA,YAAuBU,AAAS,QAATA,KAAY,mBACxD,IAACsC,kBAASA;4BACR,WAAU;4BACV,mBAAkB;4BAClB,aAAY;4BACZ,mBAAiBxE,AAAS,QAATA,QAAgB2D,UAAUlB;4BAC3C,cACEzC,AAAS,QAATA,QAAiB2B,KAAK,CAAC,aAAa,IAAIC,SAAS,MAAM,CAAC,OAAO,GAAIa;sCAGrE,mBAAC;gCAAI,KAAKa;gCAAS,WAAU;;oCAC1B9B;oCACAU,SAAS,WAATA,GACC,IAAC;wCAAE,MAAK;wCAAQ,WAAU;kDACvBA;;;;;wBAMQ,QAAlBkB,kBAA0B,WAAR,GAAQ,IAAC;4BAAI,WAAU;sCAAsBA;;;;;;;AAK1E;AAEO,SAASqB,UAAU9C,KAAiB;IACzC,OAAO,WAAP,GACE,IAAC+C,cAAYA;QAAC,WAAW/C,MAAM,SAAS;kBACtC,kBAAC7B,cAAYA;YAAE,GAAG6B,KAAK;;;AAG7B;AACO,SAASgD,MAAMC,QAAoB;IACxC,MAAMjD,QAAQkD,kBAAkB,SAASD;IACzC,OAAO,WAAP,GAAO,IAACH,WAASA;QAAE,GAAG9C,KAAK;;AAC7B"}
|
|
1
|
+
{"version":3,"file":"modal/modal.js","sources":["../../../../../src/modal/modal.tsx"],"sourcesContent":["import { type HTMLAttributes, type ReactNode, useEffect, useLayoutEffect, useRef } from 'react';\nimport type { ButtonProps } from '../button/button';\nimport { useComponentProps } from '../config-provider/component-defaults';\nimport { ScrollbarControl as Scrollbar } from '../scrollbar/scrollbar';\nimport { classes } from '../shared/classes';\nimport type { DialogFocusOptions } from '../shared/dialog';\nimport { type TabsProps, useTabsParts } from '../tabs/tabs';\nimport { ModalBase, type ModalTabsRenderProps } from './base';\n\nconst useBrowserLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\nexport interface ModalFooterActions {\n confirmButton: ReactNode;\n cancelButton: ReactNode;\n}\n/** Tabs controls integrated with the modal; Modal fixes the line type and top placement. */\nexport interface ModalTabsProps extends Omit<TabsProps, 'type' | 'placement' | 'children'> {}\n\nexport interface ModalProps\n extends Omit<HTMLAttributes<HTMLDivElement>, 'title'>,\n DialogFocusOptions {\n open: boolean;\n title?: ReactNode;\n /** Supporting text displayed below the title. */\n description?: ReactNode;\n /** Decorative header icon. */\n icon?: ReactNode;\n /** Separate the header and footer with subtle borders. */\n divided?: boolean;\n /** Embedded tabs placed below the heading, or replacing it when no title is supplied. */\n tabs?: ModalTabsProps;\n footer?: ReactNode | ((actions: ModalFooterActions) => ReactNode);\n confirmText?: ReactNode;\n cancelText?: ReactNode;\n confirmLoading?: boolean;\n confirmButtonProps?: ButtonProps;\n cancelButtonProps?: ButtonProps;\n onConfirm?: () => void | Promise<void>;\n onCancel?: () => void;\n width?: number | string;\n closable?: boolean;\n maskClosable?: boolean;\n keyboard?: boolean;\n onClose?: () => void;\n afterClose?: () => void;\n forceRender?: boolean;\n destroyOnClose?: boolean;\n preserve?: boolean;\n container?: Element | DocumentFragment | (() => Element | DocumentFragment);\n}\n\nfunction ModalTabsLayout({\n open,\n tabs,\n title,\n titleId,\n hasHeading,\n closeButton,\n contentRef,\n snapHeight,\n ariaLabel,\n ariaLabelledBy,\n scrollbarLabel,\n scrollbarLabelledBy,\n error,\n children,\n}: ModalTabsRenderProps) {\n const tabExtra =\n !hasHeading && closeButton != null ? (\n <div className=\"leaf-dialog-tab-extra leaf-modal__tab-extra\">\n {tabs.extra}\n {closeButton}\n </div>\n ) : (\n tabs.extra\n );\n const tabLabel = tabs['aria-label'] ?? (typeof title === 'string' ? title : ariaLabel);\n const tabLabelledBy =\n tabs['aria-labelledby'] ??\n (tabs['aria-label'] == null && title != null\n ? titleId\n : tabs['aria-label'] == null\n ? ariaLabelledBy\n : undefined);\n const parts = useTabsParts({\n ...tabs,\n type: 'line',\n placement: 'top',\n size: tabs.size ?? 'md',\n 'aria-label': tabLabel,\n 'aria-labelledby': tabLabelledBy,\n extra: tabExtra,\n className: classes(\n 'leaf-dialog-tabs',\n hasHeading && 'leaf-dialog-tabs--headed',\n 'leaf-modal__tabs',\n tabs.className,\n ),\n panelsClassName: 'leaf-dialog-panels',\n visibilityKey: open,\n });\n const previousSelected = useRef(parts?.selected);\n useBrowserLayoutEffect(() => {\n if (previousSelected.current === parts?.selected) return;\n previousSelected.current = parts?.selected;\n snapHeight();\n }, [parts?.selected, snapHeight]);\n\n return (\n <>\n {parts && <div {...parts.rootProps}>{parts.header}</div>}\n {(parts?.hasPanels || (children != null && children !== false) || error != null) && (\n <Scrollbar\n className=\"leaf-modal__body\"\n viewportClassName=\"leaf-modal__viewport\"\n orientation=\"vertical\"\n aria-labelledby={scrollbarLabelledBy}\n aria-label={scrollbarLabel}\n >\n <div ref={contentRef} className=\"leaf-modal__content\">\n {parts?.panels}\n {children}\n {error && (\n <p role=\"alert\" className=\"leaf-confirm-error\">\n {error}\n </p>\n )}\n </div>\n </Scrollbar>\n )}\n </>\n );\n}\n\ntype ModalControlProps = ModalProps;\n\nfunction ModalControl({\n divided = true,\n confirmLoading = false,\n width = 480,\n closable = true,\n maskClosable = true,\n keyboard = true,\n forceRender = false,\n destroyOnClose = false,\n ...props\n}: ModalControlProps) {\n return (\n <ModalBase\n {...props}\n divided={divided}\n confirmLoading={confirmLoading}\n width={width}\n closable={closable}\n maskClosable={maskClosable}\n keyboard={keyboard}\n forceRender={forceRender}\n destroyOnClose={destroyOnClose}\n renderTabsLayout={ModalTabsLayout}\n />\n );\n}\n\nexport function Modal(rawProps: ModalProps) {\n const props = useComponentProps('Modal', rawProps);\n return <ModalControl {...props} />;\n}\n"],"names":["useBrowserLayoutEffect","window","useEffect","useLayoutEffect","ModalTabsLayout","open","tabs","title","titleId","hasHeading","closeButton","contentRef","snapHeight","ariaLabel","ariaLabelledBy","scrollbarLabel","scrollbarLabelledBy","error","children","tabExtra","tabLabel","tabLabelledBy","undefined","parts","useTabsParts","classes","previousSelected","useRef","Scrollbar","ModalControl","divided","confirmLoading","width","closable","maskClosable","keyboard","forceRender","destroyOnClose","props","ModalBase","Modal","rawProps","useComponentProps"],"mappings":";;;;;;;;;;AASA,MAAMA,yBAAyB,AAAkB,MAAlB,OAAOC,SAAyBC,YAAYC;AA0C3E,SAASC,gBAAgB,EACvBC,IAAI,EACJC,IAAI,EACJC,KAAK,EACLC,OAAO,EACPC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,UAAU,EACVC,SAAS,EACTC,cAAc,EACdC,cAAc,EACdC,mBAAmB,EACnBC,KAAK,EACLC,QAAQ,EACa;IACrB,MAAMC,WACJ,AAACV,cAAcC,AAAe,QAAfA,cAMbJ,KAAK,KAAK,GANyB,WAAP,GAC5B,KAAC;QAAI,WAAU;;YACZA,KAAK,KAAK;YACVI;;;IAKP,MAAMU,WAAWd,IAAI,CAAC,aAAa,IAAK,CAAiB,YAAjB,OAAOC,QAAqBA,QAAQM,SAAQ;IACpF,MAAMQ,gBACJf,IAAI,CAAC,kBAAkB,IACtBA,CAAAA,AAAsB,QAAtBA,IAAI,CAAC,aAAa,IAAYC,AAAS,QAATA,QAC3BC,UACAF,AAAsB,QAAtBA,IAAI,CAAC,aAAa,GAChBQ,iBACAQ,MAAQ;IAChB,MAAMC,QAAQC,aAAa;QACzB,GAAGlB,IAAI;QACP,MAAM;QACN,WAAW;QACX,MAAMA,KAAK,IAAI,IAAI;QACnB,cAAcc;QACd,mBAAmBC;QACnB,OAAOF;QACP,WAAWM,QACT,oBACAhB,cAAc,4BACd,oBACAH,KAAK,SAAS;QAEhB,iBAAiB;QACjB,eAAeD;IACjB;IACA,MAAMqB,mBAAmBC,OAAOJ,OAAO;IACvCvB,uBAAuB;QACrB,IAAI0B,iBAAiB,OAAO,KAAKH,OAAO,UAAU;QAClDG,iBAAiB,OAAO,GAAGH,OAAO;QAClCX;IACF,GAAG;QAACW,OAAO;QAAUX;KAAW;IAEhC,OAAO,WAAP,GACE;;YACGW,SAAS,WAATA,GAAS,IAAC;gBAAK,GAAGA,MAAM,SAAS;0BAAGA,MAAM,MAAM;;YAC/CA,CAAAA,OAAO,aAAcL,AAAY,QAAZA,YAAoBA,AAAa,UAAbA,YAAuBD,AAAS,QAATA,KAAY,mBAC5E,IAACW,kBAASA;gBACR,WAAU;gBACV,mBAAkB;gBAClB,aAAY;gBACZ,mBAAiBZ;gBACjB,cAAYD;0BAEZ,mBAAC;oBAAI,KAAKJ;oBAAY,WAAU;;wBAC7BY,OAAO;wBACPL;wBACAD,SAAS,WAATA,GACC,IAAC;4BAAE,MAAK;4BAAQ,WAAU;sCACvBA;;;;;;;AAQjB;AAIA,SAASY,aAAa,EACpBC,UAAU,IAAI,EACdC,iBAAiB,KAAK,EACtBC,QAAQ,GAAG,EACXC,WAAW,IAAI,EACfC,eAAe,IAAI,EACnBC,WAAW,IAAI,EACfC,cAAc,KAAK,EACnBC,iBAAiB,KAAK,EACtB,GAAGC,OACe;IAClB,OAAO,WAAP,GACE,IAACC,WAASA;QACP,GAAGD,KAAK;QACT,SAASR;QACT,gBAAgBC;QAChB,OAAOC;QACP,UAAUC;QACV,cAAcC;QACd,UAAUC;QACV,aAAaC;QACb,gBAAgBC;QAChB,kBAAkBjC;;AAGxB;AAEO,SAASoC,MAAMC,QAAoB;IACxC,MAAMH,QAAQI,kBAAkB,SAASD;IACzC,OAAO,WAAP,GAAO,IAACZ,cAAYA;QAAE,GAAGS,KAAK;;AAChC"}
|
|
@@ -5,6 +5,7 @@ const useBrowserLayoutEffect = "u" < typeof window ? useEffect : useLayoutEffect
|
|
|
5
5
|
function useNaturalHeightTransition(surfaceRef, contentRef, open) {
|
|
6
6
|
const enabled = useMotionEnabled();
|
|
7
7
|
const sync = useRef(void 0);
|
|
8
|
+
const snap = useRef(()=>{});
|
|
8
9
|
useBrowserLayoutEffect(()=>{
|
|
9
10
|
const surface = surfaceRef.current;
|
|
10
11
|
const content = contentRef.current;
|
|
@@ -53,6 +54,14 @@ function useNaturalHeightTransition(surfaceRef, contentRef, open) {
|
|
|
53
54
|
});
|
|
54
55
|
};
|
|
55
56
|
sync.current = update;
|
|
57
|
+
snap.current = ()=>{
|
|
58
|
+
animation?.cancel();
|
|
59
|
+
reveal?.cancel();
|
|
60
|
+
animation = void 0;
|
|
61
|
+
reveal = void 0;
|
|
62
|
+
lastHeight = surface.offsetHeight;
|
|
63
|
+
lastLayout = layout();
|
|
64
|
+
};
|
|
56
65
|
let observer;
|
|
57
66
|
if ("u" > typeof ResizeObserver) {
|
|
58
67
|
observer = new ResizeObserver(update);
|
|
@@ -60,12 +69,7 @@ function useNaturalHeightTransition(surfaceRef, contentRef, open) {
|
|
|
60
69
|
for (const part of parts())observer.observe(part);
|
|
61
70
|
}
|
|
62
71
|
const resize = ()=>{
|
|
63
|
-
|
|
64
|
-
reveal?.cancel();
|
|
65
|
-
animation = void 0;
|
|
66
|
-
reveal = void 0;
|
|
67
|
-
lastHeight = surface.offsetHeight;
|
|
68
|
-
lastLayout = layout();
|
|
72
|
+
snap.current();
|
|
69
73
|
};
|
|
70
74
|
window.addEventListener('resize', resize);
|
|
71
75
|
window.visualViewport?.addEventListener('resize', resize);
|
|
@@ -76,6 +80,7 @@ function useNaturalHeightTransition(surfaceRef, contentRef, open) {
|
|
|
76
80
|
animation?.cancel();
|
|
77
81
|
reveal?.cancel();
|
|
78
82
|
sync.current = void 0;
|
|
83
|
+
snap.current = ()=>{};
|
|
79
84
|
};
|
|
80
85
|
}, [
|
|
81
86
|
open,
|
|
@@ -86,6 +91,7 @@ function useNaturalHeightTransition(surfaceRef, contentRef, open) {
|
|
|
86
91
|
useBrowserLayoutEffect(()=>{
|
|
87
92
|
sync.current?.();
|
|
88
93
|
});
|
|
94
|
+
return useRef(()=>snap.current()).current;
|
|
89
95
|
}
|
|
90
96
|
function useContentTransition(ref, view, direction = 0, layoutOnly = false) {
|
|
91
97
|
const enabled = useMotionEnabled();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared/presence.js","sources":["../../../../../src/shared/presence.ts"],"sourcesContent":["import { type RefObject, useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { animateMotion, useMotionEnabled } from './motion';\n\nconst useBrowserLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\n/** Interpolate natural dialog height, including state changes inside its children. */\nexport function useNaturalHeightTransition(\n surfaceRef: RefObject<HTMLElement | null>,\n contentRef: RefObject<HTMLElement | null>,\n open: boolean,\n) {\n const enabled = useMotionEnabled();\n const sync = useRef<(() => void) | undefined>(undefined);\n useBrowserLayoutEffect(() => {\n const surface = surfaceRef.current;\n const content = contentRef.current;\n if (!open || !enabled || !surface || !content) return;\n let animation: Animation | undefined;\n let reveal: Animation | undefined;\n let lastHeight = surface.offsetHeight;\n let lastLayout = '';\n const parts = () =>\n Array.from(surface.children).filter(\n (child): child is HTMLElement => child instanceof HTMLElement && !child.contains(content),\n );\n const layout = () =>\n [surface.offsetWidth, content.offsetHeight, ...parts().map((part) => part.offsetHeight)].join(\n ':',\n );\n lastLayout = layout();\n const update = () => {\n const nextLayout = layout();\n if (nextLayout === lastLayout || surface.closest('[data-state=\"closing\"]')) return;\n lastLayout = nextLayout;\n // CSS height is unaffected by the separate entrance scale on the surface.\n const before =\n animation?.playState === 'running'\n ? Number.parseFloat(getComputedStyle(surface).height) || lastHeight\n : lastHeight;\n const opacity = reveal?.playState === 'running' ? getComputedStyle(content).opacity : '0.72';\n animation?.cancel();\n reveal?.cancel();\n const height = surface.offsetHeight;\n lastHeight = height;\n if (!before || !height || Math.abs(before - height) < 1) return;\n animation = animateMotion(surface, [{ height: `${before}px` }, { height: `${height}px` }], {\n durationMultiplier: 1.6,\n });\n if (animation)\n reveal = animateMotion(content, [{ opacity }, { opacity: 1 }], {\n durationMultiplier: 1.25,\n });\n };\n sync.current = update;\n let observer: ResizeObserver | undefined;\n if (typeof ResizeObserver !== 'undefined') {\n observer = new ResizeObserver(update);\n observer.observe(content);\n for (const part of parts()) observer.observe(part);\n }\n // Viewport constraints change the visible height without changing content.\n // Resizing establishes a fresh baseline instead of animating stale geometry.\n const resize = () => {\n animation?.cancel();\n reveal?.cancel();\n animation = undefined;\n reveal = undefined;\n lastHeight = surface.offsetHeight;\n lastLayout = layout();\n };\n window.addEventListener('resize', resize);\n window.visualViewport?.addEventListener('resize', resize);\n return () => {\n window.removeEventListener('resize', resize);\n window.visualViewport?.removeEventListener('resize', resize);\n observer?.disconnect();\n animation?.cancel();\n reveal?.cancel();\n sync.current = undefined;\n };\n }, [open, enabled, surfaceRef, contentRef]);\n // React updates to the header/footer are measurable before the next paint.\n useBrowserLayoutEffect(() => {\n sync.current?.();\n });\n}\n\n/** Animate a panel's explicit view change without remounting its focused controls. */\nexport function useContentTransition(\n ref: RefObject<HTMLElement | null>,\n view: string | number,\n direction = 0,\n layoutOnly = false,\n) {\n const enabled = useMotionEnabled();\n const travel = useRef(direction);\n travel.current = direction;\n const previous = useRef<{ view: string | number; height: number } | undefined>(undefined);\n useBrowserLayoutEffect(() => {\n const node = ref.current;\n if (!node) {\n previous.current = undefined;\n return;\n }\n const height = Number.parseFloat(getComputedStyle(node).height) || node.offsetHeight;\n const last = previous.current;\n previous.current = { view, height };\n if (!enabled || !last || last.view === view || node.closest('[data-state=\"closing\"]')) return;\n const changesHeight = last.height > 0 && height > 0 && Math.abs(last.height - height) > 1;\n if (layoutOnly && !changesHeight) return;\n const animation = animateMotion(\n node,\n [\n {\n ...(layoutOnly ? {} : { opacity: 0.45, translate: `${travel.current * 12}px 4px` }),\n ...(changesHeight ? { height: `${last.height}px`, overflow: 'clip' } : {}),\n },\n {\n ...(layoutOnly ? {} : { opacity: 1, translate: '0 0' }),\n ...(changesHeight ? { height: `${height}px`, overflow: 'clip' } : {}),\n },\n ],\n { durationMultiplier: 1.25 },\n );\n return () => {\n if (animation && changesHeight && previous.current)\n previous.current.height =\n Number.parseFloat(getComputedStyle(node).height) || node.offsetHeight;\n animation?.cancel();\n };\n }, [enabled, ref, view, layoutOnly]);\n}\n\n/** Keep a closing overlay mounted until its CSS transition or animation finishes. */\nexport function usePresence(open: boolean, ref: RefObject<HTMLElement | null>) {\n const enabled = useMotionEnabled();\n const [present, setPresent] = useState(open);\n if (open && !present) setPresent(true);\n useEffect(() => {\n if (open || !present) return;\n const node = ref.current;\n if (!node || !enabled) {\n setPresent(false);\n return;\n }\n const computed = getComputedStyle(node);\n const durations = [computed.animationDuration, computed.transitionDuration];\n const delays = [computed.animationDelay, computed.transitionDelay];\n const milliseconds = (value: string) => {\n const numeric = Number.parseFloat(value) || 0;\n return value.trim().endsWith('ms') ? numeric : numeric * 1000;\n };\n const duration = Math.max(\n 0,\n ...durations.flatMap((list, index) => {\n const delay = (delays[index] || '0s').split(',').map(milliseconds);\n return (list || '0s')\n .split(',')\n .map((value, i) => milliseconds(value) + (delay[i % delay.length] ?? 0));\n }),\n );\n const finish = () => setPresent(false);\n const ended = (event: Event) => {\n if (event.target === node && (!('propertyName' in event) || event.propertyName === 'opacity'))\n finish();\n };\n const timer = setTimeout(finish, duration ? duration + 32 : 0);\n node.addEventListener('animationend', ended);\n node.addEventListener('transitionend', ended);\n return () => {\n clearTimeout(timer);\n node.removeEventListener('animationend', ended);\n node.removeEventListener('transitionend', ended);\n };\n }, [open, present, ref, enabled]);\n return present;\n}\n"],"names":["useBrowserLayoutEffect","window","useEffect","useLayoutEffect","useNaturalHeightTransition","surfaceRef","contentRef","open","enabled","useMotionEnabled","sync","useRef","undefined","surface","content","animation","reveal","lastHeight","lastLayout","parts","Array","child","HTMLElement","layout","part","update","nextLayout","before","Number","getComputedStyle","opacity","height","Math","animateMotion","observer","ResizeObserver","resize","useContentTransition","ref","view","direction","layoutOnly","travel","previous","node","last","changesHeight","usePresence","present","setPresent","useState","computed","durations","delays","milliseconds","value","numeric","duration","list","index","delay","i","finish","ended","event","timer","setTimeout","clearTimeout"],"mappings":";;;AAGA,MAAMA,yBAAyB,AAAkB,MAAlB,OAAOC,SAAyBC,YAAYC;AAGpE,SAASC,2BACdC,UAAyC,EACzCC,UAAyC,EACzCC,IAAa;IAEb,MAAMC,UAA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AkB;SAAC;QAC3E,MAAME,SAAS;YAACF,SAAS,cAAc;YAAEA,SAAS,eAAe;SAAC;QAClE,MAAMG,eAAe,CAACC;YACpB,MAAMC,UAAU5B,OAAO,UAAU,CAAC2B,UAAU;YAC5C,OAAOA,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQC,UAAUA,AAAU,OAAVA;QACjD;QACA,MAAMC,WAAWzB,KAAK,GAAG,CACvB,MACGoB,UAAU,OAAO,CAAC,CAACM,MAAMC;YAC1B,MAAMC,QAASP,AAAAA,CAAAA,MAAM,CAACM,MAAM,IAAI,IAAG,EAAG,KAAK,CAAC,KAAK,GAAG,CAACL;YACrD,OAAQI,AAAAA,CAAAA,QAAQ,IAAG,EAChB,KAAK,CAAC,KACN,GAAG,CAAC,CAACH,OAAOM,IAAMP,aAAaC,SAAUK,CAAAA,KAAK,CAACC,IAAID,MAAM,MAAM,CAAC,IAAI;QACzE;QAEF,MAAME,SAAS,IAAMb,WAAW;QAChC,MAAMc,QAAQ,CAACC;YACb,IAAIA,MAAM,MAAM,KAAKpB,QAAS,EAAE,mBAAkBoB,KAAI,KAAMA,AAAuB,cAAvBA,MAAM,YAAY,AAAa,GACzFF;QACJ;QACA,MAAMG,QAAQC,WAAWJ,QAAQL,WAAWA,WAAW,KAAK;QAC5Db,KAAK,gBAAgB,CAAC,gBAAgBmB;QACtCnB,KAAK,gBAAgB,CAAC,iBAAiBmB;QACvC,OAAO;YACLI,aAAaF;YACbrB,KAAK,mBAAmB,CAAC,gBAAgBmB;YACzCnB,KAAK,mBAAmB,CAAC,iBAAiBmB;QAC5C;IACF,GAAG;QAACxD;QAAMyC;QAASV;QAAK9B;KAAQ;IAChC,OAAOwC;AACT"}
|
|
1
|
+
{"version":3,"file":"shared/presence.js","sources":["../../../../../src/shared/presence.ts"],"sourcesContent":["import { type RefObject, useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { animateMotion, useMotionEnabled } from './motion';\n\nconst useBrowserLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\n/** Interpolate natural dialog height, including state changes inside its children. */\nexport function useNaturalHeightTransition(\n surfaceRef: RefObject<HTMLElement | null>,\n contentRef: RefObject<HTMLElement | null>,\n open: boolean,\n) {\n const enabled = useMotionEnabled();\n const sync = useRef<(() => void) | undefined>(undefined);\n const snap = useRef<() => void>(() => {});\n useBrowserLayoutEffect(() => {\n const surface = surfaceRef.current;\n const content = contentRef.current;\n if (!open || !enabled || !surface || !content) return;\n let animation: Animation | undefined;\n let reveal: Animation | undefined;\n let lastHeight = surface.offsetHeight;\n let lastLayout = '';\n const parts = () =>\n Array.from(surface.children).filter(\n (child): child is HTMLElement => child instanceof HTMLElement && !child.contains(content),\n );\n const layout = () =>\n [surface.offsetWidth, content.offsetHeight, ...parts().map((part) => part.offsetHeight)].join(\n ':',\n );\n lastLayout = layout();\n const update = () => {\n const nextLayout = layout();\n if (nextLayout === lastLayout || surface.closest('[data-state=\"closing\"]')) return;\n lastLayout = nextLayout;\n // CSS height is unaffected by the separate entrance scale on the surface.\n const before =\n animation?.playState === 'running'\n ? Number.parseFloat(getComputedStyle(surface).height) || lastHeight\n : lastHeight;\n const opacity = reveal?.playState === 'running' ? getComputedStyle(content).opacity : '0.72';\n animation?.cancel();\n reveal?.cancel();\n const height = surface.offsetHeight;\n lastHeight = height;\n if (!before || !height || Math.abs(before - height) < 1) return;\n animation = animateMotion(surface, [{ height: `${before}px` }, { height: `${height}px` }], {\n durationMultiplier: 1.6,\n });\n if (animation)\n reveal = animateMotion(content, [{ opacity }, { opacity: 1 }], {\n durationMultiplier: 1.25,\n });\n };\n sync.current = update;\n // 切换标签页时立即刷新高度基线,避免触发容器高度缓动。\n snap.current = () => {\n animation?.cancel();\n reveal?.cancel();\n animation = undefined;\n reveal = undefined;\n lastHeight = surface.offsetHeight;\n lastLayout = layout();\n };\n let observer: ResizeObserver | undefined;\n if (typeof ResizeObserver !== 'undefined') {\n observer = new ResizeObserver(update);\n observer.observe(content);\n for (const part of parts()) observer.observe(part);\n }\n // Viewport constraints change the visible height without changing content.\n // Resizing establishes a fresh baseline instead of animating stale geometry.\n const resize = () => {\n snap.current();\n };\n window.addEventListener('resize', resize);\n window.visualViewport?.addEventListener('resize', resize);\n return () => {\n window.removeEventListener('resize', resize);\n window.visualViewport?.removeEventListener('resize', resize);\n observer?.disconnect();\n animation?.cancel();\n reveal?.cancel();\n sync.current = undefined;\n snap.current = () => {};\n };\n }, [open, enabled, surfaceRef, contentRef]);\n // React updates to the header/footer are measurable before the next paint.\n useBrowserLayoutEffect(() => {\n sync.current?.();\n });\n return useRef(() => snap.current()).current;\n}\n\n/** Animate a panel's explicit view change without remounting its focused controls. */\nexport function useContentTransition(\n ref: RefObject<HTMLElement | null>,\n view: string | number,\n direction = 0,\n layoutOnly = false,\n) {\n const enabled = useMotionEnabled();\n const travel = useRef(direction);\n travel.current = direction;\n const previous = useRef<{ view: string | number; height: number } | undefined>(undefined);\n useBrowserLayoutEffect(() => {\n const node = ref.current;\n if (!node) {\n previous.current = undefined;\n return;\n }\n const height = Number.parseFloat(getComputedStyle(node).height) || node.offsetHeight;\n const last = previous.current;\n previous.current = { view, height };\n if (!enabled || !last || last.view === view || node.closest('[data-state=\"closing\"]')) return;\n const changesHeight = last.height > 0 && height > 0 && Math.abs(last.height - height) > 1;\n if (layoutOnly && !changesHeight) return;\n const animation = animateMotion(\n node,\n [\n {\n ...(layoutOnly ? {} : { opacity: 0.45, translate: `${travel.current * 12}px 4px` }),\n ...(changesHeight ? { height: `${last.height}px`, overflow: 'clip' } : {}),\n },\n {\n ...(layoutOnly ? {} : { opacity: 1, translate: '0 0' }),\n ...(changesHeight ? { height: `${height}px`, overflow: 'clip' } : {}),\n },\n ],\n { durationMultiplier: 1.25 },\n );\n return () => {\n if (animation && changesHeight && previous.current)\n previous.current.height =\n Number.parseFloat(getComputedStyle(node).height) || node.offsetHeight;\n animation?.cancel();\n };\n }, [enabled, ref, view, layoutOnly]);\n}\n\n/** Keep a closing overlay mounted until its CSS transition or animation finishes. */\nexport function usePresence(open: boolean, ref: RefObject<HTMLElement | null>) {\n const enabled = useMotionEnabled();\n const [present, setPresent] = useState(open);\n if (open && !present) setPresent(true);\n useEffect(() => {\n if (open || !present) return;\n const node = ref.current;\n if (!node || !enabled) {\n setPresent(false);\n return;\n }\n const computed = getComputedStyle(node);\n const durations = [computed.animationDuration, computed.transitionDuration];\n const delays = [computed.animationDelay, computed.transitionDelay];\n const milliseconds = (value: string) => {\n const numeric = Number.parseFloat(value) || 0;\n return value.trim().endsWith('ms') ? numeric : numeric * 1000;\n };\n const duration = Math.max(\n 0,\n ...durations.flatMap((list, index) => {\n const delay = (delays[index] || '0s').split(',').map(milliseconds);\n return (list || '0s')\n .split(',')\n .map((value, i) => milliseconds(value) + (delay[i % delay.length] ?? 0));\n }),\n );\n const finish = () => setPresent(false);\n const ended = (event: Event) => {\n if (event.target === node && (!('propertyName' in event) || event.propertyName === 'opacity'))\n finish();\n };\n const timer = setTimeout(finish, duration ? duration + 32 : 0);\n node.addEventListener('animationend', ended);\n node.addEventListener('transitionend', ended);\n return () => {\n clearTimeout(timer);\n node.removeEventListener('animationend', ended);\n node.removeEventListener('transitionend', ended);\n };\n }, [open, present, ref, enabled]);\n return present;\n}\n"],"names":["useBrowserLayoutEffect","window","useEffect","useLayoutEffect","useNaturalHeightTransition","surfaceRef","contentRef","open","enabled","useMotionEnabled","sync","useRef","undefined","snap","surface","content","animation","reveal","lastHeight","lastLayout","parts","Array","child","HTMLElement","layout","part","update","nextLayout","before","Number","getComputedStyle","opacity","height","Math","animateMotion","observer","ResizeObserver","resize","useContentTransition","ref","view","direction","layoutOnly","travel","previous","node","last","changesHeight","usePresence","present","setPresent","useState","computed","durations","delays","milliseconds","value","numeric","duration","list","index","delay","i","finish","ended","event","timer","setTimeout","clearTimeout"],"mappings":";;;AAGA,MAAMA,yBAAyB,AAAkB,MAAlB,OAAOC,SAAyBC,YAAYC;AAGpE,SAASC,2BACdC,UAAyC,EACzCC,UA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;IAChC,OAAOyC;AACT"}
|
|
@@ -28,6 +28,15 @@ function warnDevelopment(key, message) {
|
|
|
28
28
|
developmentWarnings.add(key);
|
|
29
29
|
console.warn(`Leaf UI: ${message}`);
|
|
30
30
|
}
|
|
31
|
+
const SELECTION_CONTENT_WIDTH = 34;
|
|
32
|
+
function resolvePx(value, fallback) {
|
|
33
|
+
if ('number' == typeof value) return Number.isFinite(value) && value >= 0 ? value : fallback;
|
|
34
|
+
if ('string' == typeof value) {
|
|
35
|
+
const match = /^\s*(?:0+(?:\.0+)?|(\d+(?:\.\d+)?)\s*px)\s*$/iu.exec(value);
|
|
36
|
+
if (match) return Number(match[1] ?? 0);
|
|
37
|
+
}
|
|
38
|
+
return fallback;
|
|
39
|
+
}
|
|
31
40
|
function hasSortingModel(table) {
|
|
32
41
|
return Boolean(table.options.getSortedRowModel || table.options.manualSorting);
|
|
33
42
|
}
|
|
@@ -515,6 +524,7 @@ function ordinaryRows(rows) {
|
|
|
515
524
|
function DataTableContentControl({ className, ...props }) {
|
|
516
525
|
const config = useDataTableContext();
|
|
517
526
|
const { table, tableRef, loading, error, emptyContent, onRetry, selection, resizable, virtual } = config;
|
|
527
|
+
const { theme } = useLeafConfig();
|
|
518
528
|
const t = useText();
|
|
519
529
|
const viewport = useRef(null);
|
|
520
530
|
const [availableWidth, setAvailableWidth] = useState(0);
|
|
@@ -546,10 +556,12 @@ function DataTableContentControl({ className, ...props }) {
|
|
|
546
556
|
const expandable = config.expandable && !config.renderRowHeader;
|
|
547
557
|
const utilityCount = Number(Boolean(selection)) + Number(expandable);
|
|
548
558
|
const colSpan = Math.max(1, columns.length + utilityCount);
|
|
559
|
+
const selectionBorderWidth = config.bordered ? resolvePx(theme.components?.Table?.borderWidth ?? theme.tokens?.borderWidth, 1) : 0;
|
|
560
|
+
const selectionWidth = SELECTION_CONTENT_WIDTH + selectionBorderWidth;
|
|
549
561
|
const layout = getColumnLayout(table, columns, {
|
|
550
562
|
forceFixed: Boolean(resizable || virtual || columns.some((column)=>column.getIsPinned())),
|
|
551
563
|
availableWidth,
|
|
552
|
-
utilityWidth: (selection ?
|
|
564
|
+
utilityWidth: (selection ? selectionWidth : 0) + (expandable ? 48 : 0)
|
|
553
565
|
});
|
|
554
566
|
const status = null != error && false !== error ? 'error' : rows.length && columns.length ? null : loading ? 'loading' : 'empty';
|
|
555
567
|
const expanded = table.getState().expanded;
|
|
@@ -613,7 +625,7 @@ function DataTableContentControl({ className, ...props }) {
|
|
|
613
625
|
children: [
|
|
614
626
|
selection && /*#__PURE__*/ jsx("col", {
|
|
615
627
|
style: {
|
|
616
|
-
width:
|
|
628
|
+
width: config.bordered ? `calc(${SELECTION_CONTENT_WIDTH}px + var(--leaf-table-border-width))` : SELECTION_CONTENT_WIDTH
|
|
617
629
|
}
|
|
618
630
|
}),
|
|
619
631
|
expandable && /*#__PURE__*/ jsx("col", {
|