@ifhover/leaf-ui 0.16.7 → 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.
Files changed (135) hide show
  1. package/dist/cjs/browser/modules/confirm/confirm.cjs +2 -2
  2. package/dist/cjs/browser/modules/confirm/confirm.cjs.map +1 -1
  3. package/dist/cjs/browser/modules/drawer/drawer.cjs +120 -61
  4. package/dist/cjs/browser/modules/drawer/drawer.cjs.map +1 -1
  5. package/dist/cjs/browser/modules/filelist/filelist.cjs +2 -2
  6. package/dist/cjs/browser/modules/filelist/filelist.cjs.map +1 -1
  7. package/dist/cjs/browser/modules/modal/base.cjs +287 -0
  8. package/dist/cjs/browser/modules/modal/base.cjs.map +1 -0
  9. package/dist/cjs/browser/modules/modal/modal.cjs +64 -209
  10. package/dist/cjs/browser/modules/modal/modal.cjs.map +1 -1
  11. package/dist/cjs/browser/modules/shared/presence.cjs +12 -6
  12. package/dist/cjs/browser/modules/shared/presence.cjs.map +1 -1
  13. package/dist/cjs/browser/modules/tabletanstack/tabletanstack.cjs +14 -2
  14. package/dist/cjs/browser/modules/tabletanstack/tabletanstack.cjs.map +1 -1
  15. package/dist/cjs/browser/modules/tabs/tabs.cjs +194 -175
  16. package/dist/cjs/browser/modules/tabs/tabs.cjs.map +1 -1
  17. package/dist/cjs/confirm/confirm.cjs +2 -2
  18. package/dist/cjs/confirm/confirm.cjs.map +1 -1
  19. package/dist/cjs/drawer/drawer.cjs +120 -61
  20. package/dist/cjs/drawer/drawer.cjs.map +1 -1
  21. package/dist/cjs/drawer/drawer.d.cts +6 -0
  22. package/dist/cjs/drawer/drawer.d.cts.map +1 -1
  23. package/dist/cjs/drawer/index.d.cts +1 -1
  24. package/dist/cjs/drawer/index.d.cts.map +1 -1
  25. package/dist/cjs/filelist/filelist.cjs +2 -2
  26. package/dist/cjs/filelist/filelist.cjs.map +1 -1
  27. package/dist/cjs/index.d.cts +2 -2
  28. package/dist/cjs/index.d.cts.map +1 -1
  29. package/dist/cjs/modal/base.cjs +285 -0
  30. package/dist/cjs/modal/base.cjs.map +1 -0
  31. package/dist/cjs/modal/base.d.cts +23 -0
  32. package/dist/cjs/modal/base.d.cts.map +1 -0
  33. package/dist/cjs/modal/index.d.cts +1 -1
  34. package/dist/cjs/modal/index.d.cts.map +1 -1
  35. package/dist/cjs/modal/modal.cjs +64 -209
  36. package/dist/cjs/modal/modal.cjs.map +1 -1
  37. package/dist/cjs/modal/modal.d.cts +8 -3
  38. package/dist/cjs/modal/modal.d.cts.map +1 -1
  39. package/dist/cjs/shared/presence.cjs +12 -6
  40. package/dist/cjs/shared/presence.cjs.map +1 -1
  41. package/dist/cjs/shared/presence.d.cts +1 -1
  42. package/dist/cjs/shared/presence.d.cts.map +1 -1
  43. package/dist/cjs/styles/card.css +1 -1
  44. package/dist/cjs/styles/colorpicker.css +1 -1
  45. package/dist/cjs/styles/components/card.css +1 -1
  46. package/dist/cjs/styles/components/drawer.css +1 -1
  47. package/dist/cjs/styles/components/modal.css +1 -1
  48. package/dist/cjs/styles/components/tabletanstack.css +1 -1
  49. package/dist/cjs/styles/components/tabs.css +1 -1
  50. package/dist/cjs/styles/config-provider.css +1 -1
  51. package/dist/cjs/styles/confirm.css +1 -1
  52. package/dist/cjs/styles/daterangepicker.css +1 -1
  53. package/dist/cjs/styles/drawer.css +1 -1
  54. package/dist/cjs/styles/filelist.css +1 -1
  55. package/dist/cjs/styles/index.css +75 -14
  56. package/dist/cjs/styles/index.css.map +1 -1
  57. package/dist/cjs/styles/modal.css +1 -1
  58. package/dist/cjs/styles/tabletanstack.css +1 -1
  59. package/dist/cjs/styles/tabs.css +1 -1
  60. package/dist/cjs/styles/upload.css +1 -1
  61. package/dist/cjs/tabletanstack/tabletanstack.cjs +14 -2
  62. package/dist/cjs/tabletanstack/tabletanstack.cjs.map +1 -1
  63. package/dist/cjs/tabletanstack/tabletanstack.d.cts.map +1 -1
  64. package/dist/cjs/tabs/tabs.cjs +194 -175
  65. package/dist/cjs/tabs/tabs.cjs.map +1 -1
  66. package/dist/cjs/tabs/tabs.d.cts +14 -1
  67. package/dist/cjs/tabs/tabs.d.cts.map +1 -1
  68. package/dist/esm/browser/modules/confirm/confirm.js +1 -1
  69. package/dist/esm/browser/modules/confirm/confirm.js.map +1 -1
  70. package/dist/esm/browser/modules/drawer/drawer.js +121 -62
  71. package/dist/esm/browser/modules/drawer/drawer.js.map +1 -1
  72. package/dist/esm/browser/modules/filelist/filelist.js +1 -1
  73. package/dist/esm/browser/modules/filelist/filelist.js.map +1 -1
  74. package/dist/esm/browser/modules/modal/base.js +249 -0
  75. package/dist/esm/browser/modules/modal/base.js.map +1 -0
  76. package/dist/esm/browser/modules/modal/modal.js +65 -207
  77. package/dist/esm/browser/modules/modal/modal.js.map +1 -1
  78. package/dist/esm/browser/modules/shared/presence.js +12 -6
  79. package/dist/esm/browser/modules/shared/presence.js.map +1 -1
  80. package/dist/esm/browser/modules/tabletanstack/tabletanstack.js +14 -2
  81. package/dist/esm/browser/modules/tabletanstack/tabletanstack.js.map +1 -1
  82. package/dist/esm/browser/modules/tabs/tabs.js +190 -174
  83. package/dist/esm/browser/modules/tabs/tabs.js.map +1 -1
  84. package/dist/esm/confirm/confirm.js +1 -1
  85. package/dist/esm/confirm/confirm.js.map +1 -1
  86. package/dist/esm/drawer/drawer.d.ts +6 -0
  87. package/dist/esm/drawer/drawer.d.ts.map +1 -1
  88. package/dist/esm/drawer/drawer.js +121 -62
  89. package/dist/esm/drawer/drawer.js.map +1 -1
  90. package/dist/esm/drawer/index.d.ts +1 -1
  91. package/dist/esm/drawer/index.d.ts.map +1 -1
  92. package/dist/esm/filelist/filelist.js +1 -1
  93. package/dist/esm/filelist/filelist.js.map +1 -1
  94. package/dist/esm/index.d.ts +2 -2
  95. package/dist/esm/index.d.ts.map +1 -1
  96. package/dist/esm/modal/base.d.ts +23 -0
  97. package/dist/esm/modal/base.d.ts.map +1 -0
  98. package/dist/esm/modal/base.js +247 -0
  99. package/dist/esm/modal/base.js.map +1 -0
  100. package/dist/esm/modal/index.d.ts +1 -1
  101. package/dist/esm/modal/index.d.ts.map +1 -1
  102. package/dist/esm/modal/modal.d.ts +8 -3
  103. package/dist/esm/modal/modal.d.ts.map +1 -1
  104. package/dist/esm/modal/modal.js +65 -207
  105. package/dist/esm/modal/modal.js.map +1 -1
  106. package/dist/esm/shared/presence.d.ts +1 -1
  107. package/dist/esm/shared/presence.d.ts.map +1 -1
  108. package/dist/esm/shared/presence.js +12 -6
  109. package/dist/esm/shared/presence.js.map +1 -1
  110. package/dist/esm/styles/card.css +1 -1
  111. package/dist/esm/styles/colorpicker.css +1 -1
  112. package/dist/esm/styles/components/card.css +1 -1
  113. package/dist/esm/styles/components/drawer.css +1 -1
  114. package/dist/esm/styles/components/modal.css +1 -1
  115. package/dist/esm/styles/components/tabletanstack.css +1 -1
  116. package/dist/esm/styles/components/tabs.css +1 -1
  117. package/dist/esm/styles/config-provider.css +1 -1
  118. package/dist/esm/styles/confirm.css +1 -1
  119. package/dist/esm/styles/daterangepicker.css +1 -1
  120. package/dist/esm/styles/drawer.css +1 -1
  121. package/dist/esm/styles/filelist.css +1 -1
  122. package/dist/esm/styles/index.css +75 -14
  123. package/dist/esm/styles/index.css.map +1 -1
  124. package/dist/esm/styles/modal.css +1 -1
  125. package/dist/esm/styles/tabletanstack.css +1 -1
  126. package/dist/esm/styles/tabs.css +1 -1
  127. package/dist/esm/styles/upload.css +1 -1
  128. package/dist/esm/tabletanstack/tabletanstack.d.ts.map +1 -1
  129. package/dist/esm/tabletanstack/tabletanstack.js +14 -2
  130. package/dist/esm/tabletanstack/tabletanstack.js.map +1 -1
  131. package/dist/esm/tabs/tabs.d.ts +14 -1
  132. package/dist/esm/tabs/tabs.d.ts.map +1 -1
  133. package/dist/esm/tabs/tabs.js +190 -174
  134. package/dist/esm/tabs/tabs.js.map +1 -1
  135. package/package.json +2 -2
@@ -1,213 +1,65 @@
1
1
  "use client";
2
- import { jsx, jsxs } from "react/jsx-runtime";
3
- import { X } from "lucide-react";
4
- import { useEffect, useId, useRef, useState } from "react";
5
- import { ButtonControl } from "../button/button.js";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useLayoutEffect, useRef } from "react";
6
4
  import { useComponentProps } from "../config-provider/component-defaults.js";
7
- import { useLeafConfig } from "../config-provider/context.js";
8
5
  import { ScrollbarControl } from "../scrollbar/scrollbar.js";
9
6
  import { classes } from "../shared/classes.js";
10
- import { useDialog } from "../shared/dialog.js";
11
- import { inertProps } from "../shared/inert.js";
12
- import { OverlayOwner } from "../shared/overlay-owner.js";
13
- import { useNaturalHeightTransition, usePresence } from "../shared/presence.js";
14
- import { ScopedPortal } from "../shared/scoped-portal.js";
15
- function ModalSurface({ open, title, description, icon, divided = true, footer, confirmText, cancelText, confirmLoading = false, confirmButtonProps, cancelButtonProps, onConfirm, onCancel, width = 480, closable = true, maskClosable = true, keyboard = true, onClose, afterClose, forceRender = false, destroyOnClose = false, preserve, initialFocus, returnFocus, container: _container, children, className, style, ...props }) {
16
- const { messages, maskBlur } = useLeafConfig();
17
- const [pending, setPending] = useState(false);
18
- const [error, setError] = useState();
19
- const mounted = useRef(true);
20
- const accepting = useRef(false);
21
- const generation = useRef(0);
22
- useEffect(()=>{
23
- mounted.current = true;
24
- return ()=>{
25
- mounted.current = false;
26
- };
27
- }, []);
28
- useEffect(()=>{
29
- generation.current++;
30
- accepting.current = false;
31
- setPending(false);
32
- if (open) setError(void 0);
33
- }, [
34
- open
35
- ]);
36
- const busy = pending || confirmLoading;
37
- async function accept() {
38
- if (accepting.current || busy) return;
39
- if (!onConfirm) {
40
- if (confirmButtonProps?.type !== 'submit') onClose?.();
41
- return;
42
- }
43
- accepting.current = true;
44
- const request = generation.current;
45
- setPending(true);
46
- setError(void 0);
47
- try {
48
- await onConfirm();
49
- } catch (reason) {
50
- if (mounted.current && generation.current === request) setError(reason instanceof Error ? reason.message : String(reason));
51
- } finally{
52
- if (generation.current === request) {
53
- accepting.current = false;
54
- if (mounted.current) setPending(false);
55
- }
56
- }
57
- }
58
- const cancel = ()=>{
59
- if (!busy) (onCancel ?? onClose)?.();
60
- };
61
- const actions = {
62
- cancelButton: /*#__PURE__*/ jsx(ButtonControl, {
63
- type: "button",
64
- variant: "outline",
65
- ...cancelButtonProps,
66
- disabled: busy || cancelButtonProps?.disabled,
67
- onClick: (event)=>{
68
- cancelButtonProps?.onClick?.(event);
69
- if (!event.defaultPrevented) cancel();
70
- },
71
- children: cancelText ?? messages.common.cancel
72
- }),
73
- confirmButton: /*#__PURE__*/ jsx(ButtonControl, {
74
- type: "button",
75
- variant: "solid",
76
- ...confirmButtonProps,
77
- loading: busy || confirmButtonProps?.loading,
78
- onClick: (event)=>{
79
- confirmButtonProps?.onClick?.(event);
80
- if (!event.defaultPrevented) accept();
81
- },
82
- children: confirmText ?? messages.common.confirm
83
- })
84
- };
85
- const renderedFooter = 'function' == typeof footer ? footer(actions) : void 0 === footer ? /*#__PURE__*/ jsxs("div", {
86
- className: "leaf-modal__actions",
7
+ import { useTabsParts } from "../tabs/tabs.js";
8
+ import { ModalBase } from "./base.js";
9
+ const useBrowserLayoutEffect = "u" < typeof window ? useEffect : useLayoutEffect;
10
+ function ModalTabsLayout({ open, tabs, title, titleId, hasHeading, closeButton, contentRef, snapHeight, ariaLabel, ariaLabelledBy, scrollbarLabel, scrollbarLabelledBy, error, children }) {
11
+ const tabExtra = hasHeading || null == closeButton ? tabs.extra : /*#__PURE__*/ jsxs("div", {
12
+ className: "leaf-dialog-tab-extra leaf-modal__tab-extra",
87
13
  children: [
88
- actions.cancelButton,
89
- actions.confirmButton
14
+ tabs.extra,
15
+ closeButton
90
16
  ]
91
- }) : footer;
92
- const panel = useRef(null);
93
- const content = useRef(null);
94
- const backdrop = useRef(null);
95
- const present = usePresence(open, backdrop);
96
- useNaturalHeightTransition(panel, content, open);
97
- const titleId = `${useId()}-title`;
98
- const descriptionId = `${useId()}-description`;
99
- const modalId = `${useId()}-dialog`;
100
- const close = useRef(cancel);
101
- close.current = cancel;
102
- const wasPresent = useRef(false);
103
- useEffect(()=>{
104
- if (wasPresent.current && !present) afterClose?.();
105
- wasPresent.current = present;
17
+ });
18
+ const tabLabel = tabs['aria-label'] ?? ('string' == typeof title ? title : ariaLabel);
19
+ const tabLabelledBy = tabs['aria-labelledby'] ?? (null == tabs['aria-label'] && null != title ? titleId : null == tabs['aria-label'] ? ariaLabelledBy : void 0);
20
+ const parts = useTabsParts({
21
+ ...tabs,
22
+ type: 'line',
23
+ placement: 'top',
24
+ size: tabs.size ?? 'md',
25
+ 'aria-label': tabLabel,
26
+ 'aria-labelledby': tabLabelledBy,
27
+ extra: tabExtra,
28
+ className: classes('leaf-dialog-tabs', hasHeading && 'leaf-dialog-tabs--headed', 'leaf-modal__tabs', tabs.className),
29
+ panelsClassName: 'leaf-dialog-panels',
30
+ visibilityKey: open
31
+ });
32
+ const previousSelected = useRef(parts?.selected);
33
+ useBrowserLayoutEffect(()=>{
34
+ if (previousSelected.current === parts?.selected) return;
35
+ previousSelected.current = parts?.selected;
36
+ snapHeight();
106
37
  }, [
107
- present,
108
- afterClose
38
+ parts?.selected,
39
+ snapHeight
109
40
  ]);
110
- useDialog(open, panel, modalId, cancel, keyboard, {
111
- initialFocus,
112
- returnFocus
113
- });
114
- const visited = useRef(false);
115
- if (open) visited.current = true;
116
- if (!present && !forceRender && ((void 0 === preserve ? destroyOnClose : !preserve) || !visited.current)) return null;
117
- return /*#__PURE__*/ jsxs("div", {
118
- hidden: !present,
119
- className: "leaf-modal-mask",
120
- "data-blur": maskBlur ? void 0 : 'off',
121
- "data-state": open ? 'open' : 'closing',
122
- "aria-hidden": !open || void 0,
123
- ...inertProps(!open),
41
+ return /*#__PURE__*/ jsxs(Fragment, {
124
42
  children: [
125
- /*#__PURE__*/ jsx("button", {
126
- ref: backdrop,
127
- type: "button",
128
- className: "leaf-modal-backdrop",
129
- tabIndex: -1,
130
- "aria-label": messages.common.close,
131
- onClick: ()=>{
132
- if (maskClosable) close.current?.();
133
- }
43
+ parts && /*#__PURE__*/ jsx("div", {
44
+ ...parts.rootProps,
45
+ children: parts.header
134
46
  }),
135
- /*#__PURE__*/ jsx("div", {
136
- ...props,
137
- ref: panel,
138
- id: props.id ?? modalId,
139
- role: props.role ?? 'dialog',
140
- "aria-modal": "true",
141
- "aria-labelledby": null != title ? titleId : props['aria-labelledby'],
142
- "aria-describedby": [
143
- props['aria-describedby'],
144
- null != description && descriptionId
145
- ].filter(Boolean).join(' ') || void 0,
146
- tabIndex: -1,
147
- className: classes('leaf-modal', divided && 'leaf-modal--divided', className),
148
- style: {
149
- width,
150
- ...style
151
- },
152
- children: /*#__PURE__*/ jsxs(OverlayOwner.Provider, {
153
- value: modalId,
47
+ (parts?.hasPanels || null != children && false !== children || null != error) && /*#__PURE__*/ jsx(ScrollbarControl, {
48
+ className: "leaf-modal__body",
49
+ viewportClassName: "leaf-modal__viewport",
50
+ orientation: "vertical",
51
+ "aria-labelledby": scrollbarLabelledBy,
52
+ "aria-label": scrollbarLabel,
53
+ children: /*#__PURE__*/ jsxs("div", {
54
+ ref: contentRef,
55
+ className: "leaf-modal__content",
154
56
  children: [
155
- (null != title || null != description || null != icon || closable) && /*#__PURE__*/ jsxs("div", {
156
- className: classes('leaf-modal__header', null == description && 'leaf-modal__header--simple', null != icon && 'leaf-modal__header--icon', null == title && null == description && null == icon && 'leaf-modal__header--compact'),
157
- children: [
158
- null != icon && /*#__PURE__*/ jsx("span", {
159
- className: "leaf-modal__icon",
160
- "aria-hidden": "true",
161
- children: icon
162
- }),
163
- (null != title || null != description) && /*#__PURE__*/ jsxs("div", {
164
- className: "leaf-modal__heading",
165
- children: [
166
- null != title && /*#__PURE__*/ jsx("h2", {
167
- id: titleId,
168
- children: title
169
- }),
170
- null != description && /*#__PURE__*/ jsx("div", {
171
- id: descriptionId,
172
- className: "leaf-modal__description",
173
- children: description
174
- })
175
- ]
176
- }),
177
- closable && /*#__PURE__*/ jsx("button", {
178
- type: "button",
179
- className: "leaf-modal__close",
180
- "aria-label": messages.common.close,
181
- onClick: ()=>close.current?.(),
182
- children: /*#__PURE__*/ jsx(X, {
183
- size: 18,
184
- "aria-hidden": "true"
185
- })
186
- })
187
- ]
188
- }),
189
- (null != children && false !== children || null != error) && /*#__PURE__*/ jsx(ScrollbarControl, {
190
- className: "leaf-modal__body",
191
- viewportClassName: "leaf-modal__viewport",
192
- orientation: "vertical",
193
- "aria-labelledby": null != title ? titleId : void 0,
194
- "aria-label": null == title ? props['aria-label'] ?? messages.common.confirm : void 0,
195
- children: /*#__PURE__*/ jsxs("div", {
196
- ref: content,
197
- className: "leaf-modal__content",
198
- children: [
199
- children,
200
- error && /*#__PURE__*/ jsx("p", {
201
- role: "alert",
202
- className: "leaf-confirm-error",
203
- children: error
204
- })
205
- ]
206
- })
207
- }),
208
- null != renderedFooter && /*#__PURE__*/ jsx("div", {
209
- className: "leaf-modal__footer",
210
- children: renderedFooter
57
+ parts?.panels,
58
+ children,
59
+ error && /*#__PURE__*/ jsx("p", {
60
+ role: "alert",
61
+ className: "leaf-confirm-error",
62
+ children: error
211
63
  })
212
64
  ]
213
65
  })
@@ -215,20 +67,26 @@ function ModalSurface({ open, title, description, icon, divided = true, footer,
215
67
  ]
216
68
  });
217
69
  }
218
- function ModalBase(props) {
219
- return /*#__PURE__*/ jsx(ScopedPortal, {
220
- container: props.container,
221
- children: /*#__PURE__*/ jsx(ModalSurface, {
222
- ...props
223
- })
70
+ function ModalControl({ divided = true, confirmLoading = false, width = 480, closable = true, maskClosable = true, keyboard = true, forceRender = false, destroyOnClose = false, ...props }) {
71
+ return /*#__PURE__*/ jsx(ModalBase, {
72
+ ...props,
73
+ divided: divided,
74
+ confirmLoading: confirmLoading,
75
+ width: width,
76
+ closable: closable,
77
+ maskClosable: maskClosable,
78
+ keyboard: keyboard,
79
+ forceRender: forceRender,
80
+ destroyOnClose: destroyOnClose,
81
+ renderTabsLayout: ModalTabsLayout
224
82
  });
225
83
  }
226
84
  function Modal(rawProps) {
227
85
  const props = useComponentProps('Modal', rawProps);
228
- return /*#__PURE__*/ jsx(ModalBase, {
86
+ return /*#__PURE__*/ jsx(ModalControl, {
229
87
  ...props
230
88
  });
231
89
  }
232
- export { Modal, ModalBase };
90
+ export { Modal };
233
91
 
234
92
  //# 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,MAAMoC,SAASM;IACrB,GAAG;QAAC1C;KAAK;IACT,MAAM2C,OAAOX,WAAWxB;IACxB,eAAeoC;QACb,IAAIL,UA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BAClB,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,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,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"}
@@ -1,6 +1,6 @@
1
1
  import { type RefObject } from 'react';
2
2
  /** Interpolate natural dialog height, including state changes inside its children. */
3
- export declare function useNaturalHeightTransition(surfaceRef: RefObject<HTMLElement | null>, contentRef: RefObject<HTMLElement | null>, open: boolean): void;
3
+ export declare function useNaturalHeightTransition(surfaceRef: RefObject<HTMLElement | null>, contentRef: RefObject<HTMLElement | null>, open: boolean): () => void;
4
4
  /** Animate a panel's explicit view change without remounting its focused controls. */
5
5
  export declare function useContentTransition(ref: RefObject<HTMLElement | null>, view: string | number, direction?: number, layoutOnly?: boolean): void;
6
6
  /** Keep a closing overlay mounted until its CSS transition or animation finishes. */
@@ -1 +1 @@
1
- {"version":3,"file":"presence.d.ts","sourceRoot":"","sources":["../../../src/shared/presence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAgD,MAAM,OAAO,CAAC;AAKrF,sFAAsF;AACtF,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EACzC,UAAU,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EACzC,IAAI,EAAE,OAAO,QA4Ed;AAED,sFAAsF;AACtF,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAClC,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,SAAS,SAAI,EACb,UAAU,UAAQ,QAuCnB;AAED,qFAAqF;AACrF,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,WA0C5E"}
1
+ {"version":3,"file":"presence.d.ts","sourceRoot":"","sources":["../../../src/shared/presence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAgD,MAAM,OAAO,CAAC;AAKrF,sFAAsF;AACtF,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EACzC,UAAU,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EACzC,IAAI,EAAE,OAAO,cAmFd;AAED,sFAAsF;AACtF,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAClC,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,SAAS,SAAI,EACb,UAAU,UAAQ,QAuCnB;AAED,qFAAqF;AACrF,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,WA0C5E"}
@@ -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
- animation?.cancel();
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,UAAUC;IAChB,MAAMC,OAAOC,OAAiCC;IAC9CZ,uBAAuB;QACrB,MAAMa,UAAUR,WAAW,OAAO;Q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G,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,UAAyC,EACzCC,IAAa;IAEb,MAAMC,UAAUC;IAChB,MAAMC,OAAOC,OAAiCC;IAC9C,MAAMC,OAAOF,OAAm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