@ifhover/leaf-ui 0.17.1 → 0.17.2
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/drawer/drawer.cjs +8 -0
- package/dist/cjs/browser/modules/drawer/drawer.cjs.map +1 -1
- package/dist/cjs/browser/modules/image/viewer.cjs +2 -0
- package/dist/cjs/browser/modules/image/viewer.cjs.map +1 -1
- package/dist/cjs/browser/modules/modal/base.cjs +8 -0
- package/dist/cjs/browser/modules/modal/base.cjs.map +1 -1
- package/dist/cjs/browser/modules/shared/dialog.cjs +74 -2
- package/dist/cjs/browser/modules/shared/dialog.cjs.map +1 -1
- package/dist/cjs/browser/modules/tour/tour.cjs +75 -64
- package/dist/cjs/browser/modules/tour/tour.cjs.map +1 -1
- package/dist/cjs/drawer/drawer.cjs +8 -0
- package/dist/cjs/drawer/drawer.cjs.map +1 -1
- package/dist/cjs/drawer/drawer.d.cts.map +1 -1
- package/dist/cjs/image/viewer.cjs +2 -0
- package/dist/cjs/image/viewer.cjs.map +1 -1
- package/dist/cjs/modal/base.cjs +8 -0
- package/dist/cjs/modal/base.cjs.map +1 -1
- package/dist/cjs/modal/base.d.cts.map +1 -1
- package/dist/cjs/shared/dialog.cjs +74 -2
- package/dist/cjs/shared/dialog.cjs.map +1 -1
- package/dist/cjs/shared/dialog.d.cts +10 -1
- package/dist/cjs/shared/dialog.d.cts.map +1 -1
- package/dist/cjs/styles/components/tour.css +1 -1
- package/dist/cjs/styles/index.css +2 -2
- package/dist/cjs/styles/index.css.map +1 -1
- package/dist/cjs/styles/tour.css +1 -1
- package/dist/cjs/tour/tour.cjs +75 -64
- package/dist/cjs/tour/tour.cjs.map +1 -1
- package/dist/cjs/tour/tour.d.cts.map +1 -1
- package/dist/esm/browser/modules/drawer/drawer.js +9 -1
- package/dist/esm/browser/modules/drawer/drawer.js.map +1 -1
- package/dist/esm/browser/modules/image/viewer.js +3 -1
- package/dist/esm/browser/modules/image/viewer.js.map +1 -1
- package/dist/esm/browser/modules/modal/base.js +9 -1
- package/dist/esm/browser/modules/modal/base.js.map +1 -1
- package/dist/esm/browser/modules/shared/dialog.js +71 -2
- package/dist/esm/browser/modules/shared/dialog.js.map +1 -1
- package/dist/esm/browser/modules/tour/tour.js +76 -65
- package/dist/esm/browser/modules/tour/tour.js.map +1 -1
- package/dist/esm/drawer/drawer.d.ts.map +1 -1
- package/dist/esm/drawer/drawer.js +9 -1
- package/dist/esm/drawer/drawer.js.map +1 -1
- package/dist/esm/image/viewer.js +3 -1
- package/dist/esm/image/viewer.js.map +1 -1
- package/dist/esm/modal/base.d.ts.map +1 -1
- package/dist/esm/modal/base.js +9 -1
- package/dist/esm/modal/base.js.map +1 -1
- package/dist/esm/shared/dialog.d.ts +10 -1
- package/dist/esm/shared/dialog.d.ts.map +1 -1
- package/dist/esm/shared/dialog.js +71 -2
- package/dist/esm/shared/dialog.js.map +1 -1
- package/dist/esm/styles/components/tour.css +1 -1
- package/dist/esm/styles/index.css +2 -2
- package/dist/esm/styles/index.css.map +1 -1
- package/dist/esm/styles/tour.css +1 -1
- package/dist/esm/tour/tour.d.ts.map +1 -1
- package/dist/esm/tour/tour.js +76 -65
- package/dist/esm/tour/tour.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared/dialog.js","sources":["../../../../../src/shared/dialog.ts"],"sourcesContent":["import { type RefObject, useEffect, useRef } from 'react';\nimport { tabbable } from 'tabbable';\nimport { composedEventTarget, deepActiveElement } from './dom';\n\nconst stack: HTMLElement[] = [];\nexport type FocusTarget = RefObject<HTMLElement | null> | (() => HTMLElement | null);\nexport interface DialogFocusOptions {\n initialFocus?: FocusTarget;\n returnFocus?: boolean | FocusTarget;\n}\nlet savedOverflow = '';\nlet scrollLocks = 0;\n\n/** Share focus, Escape and scroll ownership between nested dialogs and drawers. */\nexport function useDialog(\n open: boolean,\n panel: RefObject<HTMLDivElement | null>,\n owner: string,\n onClose: () => void,\n keyboard: boolean,\n options: DialogFocusOptions = {},\n ready = true,\n modal = true,\n) {\n const focusOptions = useRef(options);\n focusOptions.current = options;\n const close = useRef(onClose);\n close.current = onClose;\n const keyboardRef = useRef(keyboard);\n keyboardRef.current = keyboard;\n useEffect(() => {\n const node = panel.current;\n if (!open || !node || !ready) return;\n const active = deepActiveElement();\n const previous = active instanceof HTMLElement ? active : null;\n const focusable = () =>\n tabbable(node, { getShadowRoot: (element) => element.shadowRoot ?? undefined });\n if (modal && scrollLocks++ === 0) {\n savedOverflow = document.body.style.overflow;\n document.body.style.overflow = 'hidden';\n }\n stack.push(node);\n const resolve = (target?: FocusTarget) =>\n typeof target === 'function' ? target() : target?.current;\n (resolve(focusOptions.current.initialFocus) ?? focusable()[0] ?? node).focus();\n const key = (event: KeyboardEvent) => {\n if (stack.at(-1) !== node || event.defaultPrevented) return;\n if (event.key === 'Escape' && keyboardRef.current) {\n event.preventDefault();\n event.stopPropagation();\n close.current();\n }\n if (event.key === 'Tab') {\n if (!modal) return;\n const items = focusable();\n if (!items.length) {\n event.preventDefault();\n node.focus();\n return;\n }\n const index = items.indexOf(deepActiveElement() as HTMLElement);\n if (event.shiftKey && index <= 0) {\n event.preventDefault();\n items.at(-1)?.focus();\n } else if (!event.shiftKey && (index < 0 || index === items.length - 1)) {\n event.preventDefault();\n items[0]?.focus();\n }\n }\n };\n const focus = (event: FocusEvent) => {\n const target = composedEventTarget(event);\n if (\n stack.at(-1) === node &&\n modal &&\n target instanceof HTMLElement &&\n !event.composedPath().includes(node) &&\n target.closest('[data-leaf-owner]')?.getAttribute('data-leaf-owner') !== owner\n )\n (focusable()[0] ?? node).focus();\n };\n document.addEventListener('keydown', key);\n document.addEventListener('focusin', focus);\n return () => {\n document.removeEventListener('keydown', key);\n document.removeEventListener('focusin', focus);\n const wasTop = stack.at(-1) === node;\n const index = stack.indexOf(node);\n if (index >= 0) stack.splice(index, 1);\n if (modal && --scrollLocks === 0) document.body.style.overflow = savedOverflow;\n if (wasTop && focusOptions.current.returnFocus !== false) {\n const destination =\n typeof focusOptions.current.returnFocus === 'object' ||\n typeof focusOptions.current.returnFocus === 'function'\n ? resolve(focusOptions.current.returnFocus)\n : previous;\n if (destination?.isConnected) destination.focus();\n }\n };\n }, [open, panel, owner, ready, modal]);\n}\n"],"names":["stack","savedOverflow","scrollLocks","useDialog","open","panel","owner","onClose","keyboard","options","ready","modal","focusOptions","useRef","close","keyboardRef","useEffect","node","active","deepActiveElement","previous","HTMLElement","focusable","tabbable","element","undefined","document","resolve","target","key","event","items","index","focus","composedEventTarget","wasTop","destination"],"mappings":";;;;AAIA,MAAMA,QAAuB,EAAE;AAM/B,IAAIC,gBAAgB;AACpB,IAAIC,cAAc;AAGX,SAASC,UACdC,IAAa,EACbC,KAAuC,EACvCC,KAAa,EACbC,OAAmB,EACnBC,QAAiB,EACjBC,UAA8B,CAAC,CAAC,EAChCC,QAAQ,IAAI,EACZC,QAAQ,IAAI;IAEZ,MAAMC,eAAeC,OAAOJ;IAC5BG,aAAa,OAAO,GAAGH;IACvB,MAAMK,QAAQD,OAAON;IACrBO,MAAM,OAAO,GAAGP;IAChB,MAAMQ,cAAcF,OAAOL;IAC3BO,YAAY,OAAO,GAAGP;IACtBQ,UAAU;QACR,MAAMC,OAAOZ,MAAM,OAAO;QAC1B,IAAI,CAACD,QAAQ,CAACa,QAAQ,CAACP,OAAO;QAC9B,MAAMQ,SAASC;QACf,MAAMC,WAAWF,kBAAkBG,cAAcH,SAAS;QAC1D,MAAMI,YAAY,IAChBC,SAASN,MAAM;gBAAE,eAAe,CAACO,UAAYA,QAAQ,UAAU,IAAIC;YAAU;QAC/E,IAAId,SAAST,AAAkB,MAAlBA,eAAqB;YAChCD,gBAAgByB,SAAS,IAAI,CAAC,KAAK,CAAC,QAAQ;YAC5CA,SAAS,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG;QACjC;QACA1B,MAAM,IAAI,CAACiB;QACX,MAAMU,UAAU,CAACC,SACf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AS,mBAAmB,CAAC,WAAWG;YACxCH,SAAS,mBAAmB,CAAC,WAAWO;YACxC,MAAME,SAASnC,MAAM,EAAE,CAAC,QAAQiB;YAChC,MAAMe,QAAQhC,MAAM,OAAO,CAACiB;YAC5B,IAAIe,SAAS,GAAGhC,MAAM,MAAM,CAACgC,OAAO;YACpC,IAAIrB,SAAS,AAAkB,MAAlB,EAAET,aAAmBwB,SAAS,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAGzB;YACjE,IAAIkC,UAAUvB,AAAqC,UAArCA,aAAa,OAAO,CAAC,WAAW,EAAY;gBACxD,MAAMwB,cACJ,AAA4C,YAA5C,OAAOxB,aAAa,OAAO,CAAC,WAAW,IACvC,AAA4C,cAA5C,OAAOA,aAAa,OAAO,CAAC,WAAW,GACnCe,QAAQf,aAAa,OAAO,CAAC,WAAW,IACxCQ;gBACN,IAAIgB,aAAa,aAAaA,YAAY,KAAK;YACjD;QACF;IACF,GAAG;QAAChC;QAAMC;QAAOC;QAAOI;QAAOC;KAAM;AACvC"}
|
|
1
|
+
{"version":3,"file":"shared/dialog.js","sources":["../../../../../src/shared/dialog.ts"],"sourcesContent":["import {\n type CSSProperties,\n type RefObject,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { tabbable } from 'tabbable';\nimport { composedEventTarget, deepActiveElement } from './dom';\n\nconst stack: HTMLElement[] = [];\nconst layers: { id: symbol; level: number }[] = [];\nconst OVERLAY_Z_STEP = 2;\nconst useBrowserLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\nconst overlayZIndex = (addend: number) => `calc(var(--leaf-z-index-modal, 1100) + ${addend})`;\n\nfunction releaseLayer(current: { id: symbol; level: number } | null) {\n if (current) {\n const index = layers.indexOf(current);\n if (index >= 0) layers.splice(index, 1);\n }\n return null;\n}\n\nexport interface OverlayLayer {\n level: number | null;\n offset: number;\n maskStyle: CSSProperties | undefined;\n popupStyle: CSSProperties | undefined;\n floatingStyle: CSSProperties | undefined;\n}\n\n/** 按浮层实际激活生命周期分配递增叠层,退场期间保留原层级直至完全卸载/隐藏。 */\nexport function useOverlayLayer(present: boolean, open = present): OverlayLayer {\n const [level, setLevel] = useState<number | null>(null);\n const entry = useRef<{ id: symbol; level: number } | null>(null);\n const wasOpen = useRef(false);\n\n useBrowserLayoutEffect(() => {\n const opened = open && !wasOpen.current;\n wasOpen.current = open;\n if (!present) {\n entry.current = releaseLayer(entry.current);\n setLevel(null);\n return;\n }\n // 首次进入展示态,或在关闭动画尚未结束时重新打开,都分配当前最高叠层。\n if (!entry.current || opened) {\n entry.current = releaseLayer(entry.current);\n const next = layers.length ? Math.max(...layers.map((item) => item.level)) + 1 : 0;\n const item = { id: Symbol(), level: next };\n layers.push(item);\n entry.current = item;\n setLevel(next);\n }\n }, [present, open]);\n\n useBrowserLayoutEffect(\n () => () => {\n entry.current = releaseLayer(entry.current);\n },\n [],\n );\n\n return useMemo(() => {\n const offset = level !== null && level > 0 ? level * OVERLAY_Z_STEP : 0;\n if (offset === 0) {\n return {\n level,\n offset: 0,\n maskStyle: undefined,\n popupStyle: undefined,\n floatingStyle: undefined,\n };\n }\n const popupValue = overlayZIndex(offset + 1);\n return {\n level,\n offset,\n maskStyle: { zIndex: overlayZIndex(offset) },\n popupStyle: { '--leaf-z-index-popup': popupValue } as CSSProperties,\n floatingStyle: {\n zIndex: popupValue,\n '--leaf-z-index-popup': popupValue,\n } as CSSProperties,\n };\n }, [level]);\n}\nexport type FocusTarget = RefObject<HTMLElement | null> | (() => HTMLElement | null);\nexport interface DialogFocusOptions {\n initialFocus?: FocusTarget;\n returnFocus?: boolean | FocusTarget;\n}\nlet savedOverflow = '';\nlet scrollLocks = 0;\n\n/** Share focus, Escape and scroll ownership between nested dialogs and drawers. */\nexport function useDialog(\n open: boolean,\n panel: RefObject<HTMLDivElement | null>,\n owner: string,\n onClose: () => void,\n keyboard: boolean,\n options: DialogFocusOptions = {},\n ready = true,\n modal = true,\n) {\n const focusOptions = useRef(options);\n focusOptions.current = options;\n const close = useRef(onClose);\n close.current = onClose;\n const keyboardRef = useRef(keyboard);\n keyboardRef.current = keyboard;\n useEffect(() => {\n const node = panel.current;\n if (!open || !node || !ready) return;\n const active = deepActiveElement();\n const previous = active instanceof HTMLElement ? active : null;\n const focusable = () =>\n tabbable(node, { getShadowRoot: (element) => element.shadowRoot ?? undefined });\n if (modal && scrollLocks++ === 0) {\n savedOverflow = document.body.style.overflow;\n document.body.style.overflow = 'hidden';\n }\n stack.push(node);\n const resolve = (target?: FocusTarget) =>\n typeof target === 'function' ? target() : target?.current;\n (resolve(focusOptions.current.initialFocus) ?? focusable()[0] ?? node).focus();\n const key = (event: KeyboardEvent) => {\n if (stack.at(-1) !== node || event.defaultPrevented) return;\n if (event.key === 'Escape' && keyboardRef.current) {\n event.preventDefault();\n event.stopPropagation();\n close.current();\n }\n if (event.key === 'Tab') {\n if (!modal) return;\n const items = focusable();\n if (!items.length) {\n event.preventDefault();\n node.focus();\n return;\n }\n const index = items.indexOf(deepActiveElement() as HTMLElement);\n if (event.shiftKey && index <= 0) {\n event.preventDefault();\n items.at(-1)?.focus();\n } else if (!event.shiftKey && (index < 0 || index === items.length - 1)) {\n event.preventDefault();\n items[0]?.focus();\n }\n }\n };\n const focus = (event: FocusEvent) => {\n const target = composedEventTarget(event);\n if (\n stack.at(-1) === node &&\n modal &&\n target instanceof HTMLElement &&\n !event.composedPath().includes(node) &&\n target.closest('[data-leaf-owner]')?.getAttribute('data-leaf-owner') !== owner\n )\n (focusable()[0] ?? node).focus();\n };\n document.addEventListener('keydown', key);\n document.addEventListener('focusin', focus);\n return () => {\n document.removeEventListener('keydown', key);\n document.removeEventListener('focusin', focus);\n const wasTop = stack.at(-1) === node;\n const index = stack.indexOf(node);\n if (index >= 0) stack.splice(index, 1);\n if (modal && --scrollLocks === 0) document.body.style.overflow = savedOverflow;\n if (wasTop && focusOptions.current.returnFocus !== false) {\n const destination =\n typeof focusOptions.current.returnFocus === 'object' ||\n typeof focusOptions.current.returnFocus === 'function'\n ? resolve(focusOptions.current.returnFocus)\n : previous;\n if (destination?.isConnected) destination.focus();\n }\n };\n }, [open, panel, owner, ready, modal]);\n}\n"],"names":["stack","layers","OVERLAY_Z_STEP","useBrowserLayoutEffect","window","useEffect","useLayoutEffect","overlayZIndex","addend","releaseLayer","current","index","useOverlayLayer","present","open","level","setLevel","useState","entry","useRef","wasOpen","opened","next","Math","item","Symbol","useMemo","offset","undefined","popupValue","savedOverflow","scrollLocks","useDialog","panel","owner","onClose","keyboard","options","ready","modal","focusOptions","close","keyboardRef","node","active","deepActiveElement","previous","HTMLElement","focusable","tabbable","element","document","resolve","target","key","event","items","focus","composedEventTarget","wasTop","destination"],"mappings":";;;;AAYA,MAAMA,QAAuB,EAAE;AAC/B,MAAMC,gBAA0C,EAAE;AAClD,MAAMC,iBAAiB;AACvB,MAAMC,yBAAyB,AAAkB,MAAlB,OAAOC,SAAyBC,YAAYC;AAE3E,MAAMC,gBAAgB,CAACC,SAAmB,CAAC,uCAAuC,EAAEA,OAAO,CAAC,CAAC;AAE7F,SAASC,aAAaC,OAA6C;IACjE,IAAIA,SAAS;QACX,MAAMC,QAAQV,cAAO,OAAO,CAACS;QAC7B,IAAIC,SAAS,GAAGV,cAAO,MAAM,CAACU,OAAO;IACvC;IACA,OAAO;AACT;AAWO,SAASC,gBAAgBC,OAAgB,EAAEC,OAAOD,OAAO;IAC9D,MAAM,CAACE,OAAOC,SAAS,GAAGC,SAAwB;IAClD,MAAMC,QAAQC,OAA6C;IAC3D,MAAMC,UAAUD,OAAO;IAEvBhB,uBAAuB;QACrB,MAAMkB,SAASP,QAAQ,CAACM,QAAQ,OAAO;QACvCA,QAAQ,OAAO,GAAGN;QAClB,IAAI,CAACD,SAAS;YACZK,MAAM,OAAO,GAAGT,aAAaS,MAAM,OAAO;YAC1CF,SAAS;YACT;QACF;QAEA,IAAI,CAACE,MAAM,OAAO,IAAIG,QAAQ;YAC5BH,MAAM,OAAO,GAA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AAE,EAAE;gBACZ;YACF;QACF;QACA,MAAMC,QAAQ,CAACF;YACb,MAAMF,SAASK,oBAAoBH;YACnC,IACEvD,MAAM,EAAE,CAAC,QAAQ2C,QACjBJ,SACAc,kBAAkBN,eAClB,CAACQ,MAAM,YAAY,GAAG,QAAQ,CAACZ,SAC/BU,OAAO,OAAO,CAAC,sBAAsB,aAAa,uBAAuBnB,OAExEc,AAAAA,CAAAA,WAAW,CAAC,EAAE,IAAIL,IAAG,EAAG,KAAK;QAClC;QACAQ,SAAS,gBAAgB,CAAC,WAAWG;QACrCH,SAAS,gBAAgB,CAAC,WAAWM;QACrC,OAAO;YACLN,SAAS,mBAAmB,CAAC,WAAWG;YACxCH,SAAS,mBAAmB,CAAC,WAAWM;YACxC,MAAME,SAAS3D,MAAM,EAAE,CAAC,QAAQ2C;YAChC,MAAMhC,QAAQX,MAAM,OAAO,CAAC2C;YAC5B,IAAIhC,SAAS,GAAGX,MAAM,MAAM,CAACW,OAAO;YACpC,IAAI4B,SAAS,AAAkB,MAAlB,EAAER,aAAmBoB,SAAS,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAGrB;YACjE,IAAI6B,UAAUnB,AAAqC,UAArCA,aAAa,OAAO,CAAC,WAAW,EAAY;gBACxD,MAAMoB,cACJ,AAA4C,YAA5C,OAAOpB,aAAa,OAAO,CAAC,WAAW,IACvC,AAA4C,cAA5C,OAAOA,aAAa,OAAO,CAAC,WAAW,GACnCY,QAAQZ,aAAa,OAAO,CAAC,WAAW,IACxCM;gBACN,IAAIc,aAAa,aAAaA,YAAY,KAAK;YACjD;QACF;IACF,GAAG;QAAC9C;QAAMmB;QAAOC;QAAOI;QAAOC;KAAM;AACvC"}
|
|
@@ -6,7 +6,7 @@ import { useEffect, useId, useRef, useState } from "react";
|
|
|
6
6
|
import { ButtonControl } from "../button/button.js";
|
|
7
7
|
import { useComponentProps } from "../config-provider/component-defaults.js";
|
|
8
8
|
import { useLeafConfig } from "../config-provider/context.js";
|
|
9
|
-
import { useDialog } from "../shared/dialog.js";
|
|
9
|
+
import { useDialog, useOverlayLayer } from "../shared/dialog.js";
|
|
10
10
|
import { FloatingPanel } from "../shared/floating.js";
|
|
11
11
|
import { inertProps } from "../shared/inert.js";
|
|
12
12
|
import { useContentTransition, usePresence } from "../shared/presence.js";
|
|
@@ -18,6 +18,10 @@ function TourFocus({ panel, owner, close, modal, open, children }) {
|
|
|
18
18
|
useDialog(open, panel, owner, close, true, {}, true, modal);
|
|
19
19
|
return children;
|
|
20
20
|
}
|
|
21
|
+
function TourStage({ present, active, children }) {
|
|
22
|
+
const layer = useOverlayLayer(present, active);
|
|
23
|
+
return children(layer);
|
|
24
|
+
}
|
|
21
25
|
function Tour(rawProps) {
|
|
22
26
|
const { open, steps, current, defaultCurrent = 0, onChange, onClose, onFinish, missingTarget = 'center', mask = true, padding = 8, getPopupContainer } = useComponentProps('Tour', rawProps);
|
|
23
27
|
const t = useText();
|
|
@@ -146,74 +150,81 @@ function Tour(rawProps) {
|
|
|
146
150
|
});
|
|
147
151
|
return /*#__PURE__*/ jsx(ScopedPortal, {
|
|
148
152
|
container: getPopupContainer,
|
|
149
|
-
children: /*#__PURE__*/
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
children:
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
153
|
+
children: /*#__PURE__*/ jsx(TourStage, {
|
|
154
|
+
present: present,
|
|
155
|
+
active: open && Boolean(step),
|
|
156
|
+
children: (layer)=>/*#__PURE__*/ jsxs("div", {
|
|
157
|
+
ref: root,
|
|
158
|
+
className: "leaf-tour-root",
|
|
159
|
+
style: layer.maskStyle,
|
|
160
|
+
"data-state": open ? 'open' : 'closing',
|
|
161
|
+
"aria-hidden": !open || void 0,
|
|
162
|
+
...inertProps(!open),
|
|
163
|
+
children: [
|
|
164
|
+
mask && /*#__PURE__*/ jsx("div", {
|
|
165
|
+
className: "leaf-tour__mask",
|
|
166
|
+
"aria-hidden": "true",
|
|
167
|
+
children: rect ? /*#__PURE__*/ jsxs(Fragment, {
|
|
168
|
+
children: [
|
|
169
|
+
/*#__PURE__*/ jsx("div", {
|
|
170
|
+
style: {
|
|
171
|
+
inset: "0 0 auto 0",
|
|
172
|
+
height: Math.max(0, rect.top - padding)
|
|
173
|
+
}
|
|
174
|
+
}),
|
|
175
|
+
/*#__PURE__*/ jsx("div", {
|
|
176
|
+
style: {
|
|
177
|
+
inset: `${rect.bottom + padding}px 0 0 0`
|
|
178
|
+
}
|
|
179
|
+
}),
|
|
180
|
+
/*#__PURE__*/ jsx("div", {
|
|
181
|
+
style: {
|
|
182
|
+
top: rect.top - padding,
|
|
183
|
+
left: 0,
|
|
184
|
+
width: Math.max(0, rect.left - padding),
|
|
185
|
+
height: rect.height + 2 * padding
|
|
186
|
+
}
|
|
187
|
+
}),
|
|
188
|
+
/*#__PURE__*/ jsx("div", {
|
|
189
|
+
style: {
|
|
190
|
+
top: rect.top - padding,
|
|
191
|
+
left: rect.right + padding,
|
|
192
|
+
right: 0,
|
|
193
|
+
height: rect.height + 2 * padding
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
]
|
|
197
|
+
}) : /*#__PURE__*/ jsx("div", {
|
|
181
198
|
style: {
|
|
182
|
-
|
|
183
|
-
left: rect.right + padding,
|
|
184
|
-
right: 0,
|
|
185
|
-
height: rect.height + 2 * padding
|
|
199
|
+
inset: 0
|
|
186
200
|
}
|
|
187
201
|
})
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
className: "leaf-tour leaf-tour--center",
|
|
214
|
-
children: content
|
|
202
|
+
}),
|
|
203
|
+
rect ? /*#__PURE__*/ jsx(FloatingPanel, {
|
|
204
|
+
open: open,
|
|
205
|
+
triggerRef: target,
|
|
206
|
+
panelRef: panel,
|
|
207
|
+
placement: step.placement ?? 'bottom',
|
|
208
|
+
container: getPopupContainer,
|
|
209
|
+
role: "dialog",
|
|
210
|
+
"aria-modal": mask || void 0,
|
|
211
|
+
"aria-labelledby": `${id}-title`,
|
|
212
|
+
className: "leaf-floating leaf-tour",
|
|
213
|
+
style: layer.floatingStyle,
|
|
214
|
+
tabIndex: -1,
|
|
215
|
+
children: content
|
|
216
|
+
}) : /*#__PURE__*/ jsx("div", {
|
|
217
|
+
ref: panel,
|
|
218
|
+
role: "dialog",
|
|
219
|
+
"aria-modal": mask || void 0,
|
|
220
|
+
"aria-labelledby": `${id}-title`,
|
|
221
|
+
tabIndex: -1,
|
|
222
|
+
className: "leaf-tour leaf-tour--center",
|
|
223
|
+
style: layer.floatingStyle,
|
|
224
|
+
children: content
|
|
225
|
+
})
|
|
226
|
+
]
|
|
215
227
|
})
|
|
216
|
-
]
|
|
217
228
|
})
|
|
218
229
|
});
|
|
219
230
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tour/tour.js","sources":["../../../../../src/tour/tour.tsx"],"sourcesContent":["import { X } from 'lucide-react';\nimport { type ReactNode, type RefObject, useEffect, useId, useRef, useState } from 'react';\nimport { ButtonControl } from '../button/button';\nimport { useComponentProps } from '../config-provider/component-defaults';\nimport { useLeafConfig } from '../config-provider/context';\nimport { useDialog } from '../shared/dialog';\nimport { FloatingPanel, type PopupOptions } from '../shared/floating';\nimport { inertProps } from '../shared/inert';\nimport { useContentTransition, usePresence } from '../shared/presence';\nimport { ScopedPortal } from '../shared/scoped-portal';\nimport { useControllable } from '../shared/use-controllable';\nimport { useText } from '../shared/use-text';\nexport interface TourStep {\n key?: string;\n title: ReactNode;\n description?: ReactNode;\n target?: string | (() => HTMLElement | null);\n placement?: PopupOptions['popupPlacement'];\n}\nexport interface TourProps {\n open: boolean;\n steps: readonly TourStep[];\n current?: number;\n defaultCurrent?: number;\n onChange?: (current: number) => void;\n onClose?: () => void;\n onFinish?: () => void;\n missingTarget?: 'center' | 'skip' | 'close';\n mask?: boolean;\n padding?: number;\n getPopupContainer?: PopupOptions['getPopupContainer'];\n}\nfunction TourFocus({\n panel,\n owner,\n close,\n modal,\n open,\n children,\n}: {\n panel: RefObject<HTMLDivElement | null>;\n owner: string;\n close: () => void;\n modal: boolean;\n open: boolean;\n children: ReactNode;\n}) {\n useDialog(open, panel, owner, close, true, {}, true, modal);\n return children;\n}\nexport function Tour(rawProps: TourProps) {\n const {\n open,\n steps,\n current,\n defaultCurrent = 0,\n onChange,\n onClose,\n onFinish,\n missingTarget = 'center',\n mask = true,\n padding = 8,\n getPopupContainer,\n } = useComponentProps('Tour', rawProps);\n const t = useText();\n const { messages } = useLeafConfig();\n const [index, setIndex] = useControllable(current, defaultCurrent, onChange);\n const latestStep = useRef(steps[index]);\n if (open && steps[index]) latestStep.current = steps[index];\n const step = open ? steps[index] : latestStep.current;\n const target = useRef<HTMLElement | null>(null),\n panel = useRef<HTMLDivElement>(null);\n const root = useRef<HTMLDivElement>(null);\n const contentView = useRef<HTMLDivElement>(null);\n const present = usePresence(open && Boolean(step), root);\n useContentTransition(contentView, `${open}:${index}`);\n const id = useId();\n const [rect, setRect] = useState<DOMRect | null>(null);\n const callbacks = useRef({ setIndex, onClose });\n callbacks.current = { setIndex, onClose };\n useEffect(() => {\n if (!open || !step) return;\n let frame = 0;\n const node =\n typeof step.target === 'string'\n ? document.querySelector<HTMLElement>(step.target)\n : step.target?.();\n target.current = node ?? null;\n if (!node) {\n setRect(null);\n if (missingTarget === 'skip' && index < steps.length - 1)\n callbacks.current.setIndex(index + 1);\n else if (missingTarget === 'close' || missingTarget === 'skip') callbacks.current.onClose?.();\n return;\n }\n node.scrollIntoView?.({ block: 'center', behavior: 'instant' });\n const update = () => {\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(() => setRect(node.getBoundingClientRect()));\n };\n const observer = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(update) : undefined;\n observer?.observe(node);\n window.addEventListener('scroll', update, true);\n window.addEventListener('resize', update);\n update();\n return () => {\n cancelAnimationFrame(frame);\n observer?.disconnect();\n window.removeEventListener('scroll', update, true);\n window.removeEventListener('resize', update);\n };\n }, [open, step, index, missingTarget, steps.length]);\n if (!present || !step) return null;\n const content = (\n <TourFocus panel={panel} owner={id} close={() => onClose?.()} modal={mask} open={open}>\n <div ref={contentView} className=\"leaf-tour__content\">\n <div className=\"leaf-tour__header\">\n <h3 id={`${id}-title`}>{step.title}</h3>\n <ButtonControl\n size=\"sm\"\n variant=\"text\"\n startIcon={<X size={16} />}\n aria-label={messages.common.close}\n onClick={onClose}\n />\n </div>\n <div className=\"leaf-tour__description\">{step.description}</div>\n <div className=\"leaf-tour__footer\">\n <span>\n {index + 1} / {steps.length}\n </span>\n {index > 0 && (\n <ButtonControl size=\"sm\" variant=\"outline\" onClick={() => setIndex(index - 1)}>\n {t('tour.previous')}\n </ButtonControl>\n )}\n <ButtonControl\n size=\"sm\"\n variant=\"solid\"\n onClick={() => {\n if (index < steps.length - 1) setIndex(index + 1);\n else {\n onFinish?.();\n onClose?.();\n }\n }}\n >\n {index === steps.length - 1 ? t('tour.finish') : t('tour.next')}\n </ButtonControl>\n </div>\n </div>\n </TourFocus>\n );\n return (\n <ScopedPortal container={getPopupContainer}>\n <div\n ref={root}\n className=\"leaf-tour-root\"\n data-state={open ? 'open' : 'closing'}\n aria-hidden={!open || undefined}\n {...inertProps(!open)}\n >\n {mask && (\n <div className=\"leaf-tour__mask\" aria-hidden=\"true\">\n {rect ? (\n <>\n <div style={{ inset: `0 0 auto 0`, height: Math.max(0, rect.top - padding) }} />\n <div style={{ inset: `${rect.bottom + padding}px 0 0 0` }} />\n <div\n style={{\n top: rect.top - padding,\n left: 0,\n width: Math.max(0, rect.left - padding),\n height: rect.height + 2 * padding,\n }}\n />\n <div\n style={{\n top: rect.top - padding,\n left: rect.right + padding,\n right: 0,\n height: rect.height + 2 * padding,\n }}\n />\n </>\n ) : (\n <div style={{ inset: 0 }} />\n )}\n </div>\n )}\n {rect ? (\n <FloatingPanel\n open={open}\n triggerRef={target}\n panelRef={panel}\n placement={step.placement ?? 'bottom'}\n container={getPopupContainer}\n role=\"dialog\"\n aria-modal={mask || undefined}\n aria-labelledby={`${id}-title`}\n className=\"leaf-floating leaf-tour\"\n tabIndex={-1}\n >\n {content}\n </FloatingPanel>\n ) : (\n <div\n ref={panel}\n role=\"dialog\"\n aria-modal={mask || undefined}\n aria-labelledby={`${id}-title`}\n tabIndex={-1}\n className=\"leaf-tour leaf-tour--center\"\n >\n {content}\n </div>\n )}\n </div>\n </ScopedPortal>\n );\n}\n"],"names":["TourFocus","panel","owner","close","modal","open","children","useDialog","Tour","rawProps","steps","current","defaultCurrent","onChange","onClose","onFinish","missingTarget","mask","padding","getPopupContainer","useComponentProps","t","useText","messages","useLeafConfig","index","setIndex","useControllable","latestStep","useRef","step","target","root","contentView","present","usePresence","Boolean","useContentTransition","id","useId","rect","setRect","useState","callbacks","useEffect","frame","node","document","update","cancelAnimationFrame","requestAnimationFrame","observer","ResizeObserver","undefined","window","content","ButtonControl","X","ScopedPortal","inertProps","Math","FloatingPanel"],"mappings":";;;;;;;;;;;;;;;;AAgCA,SAASA,UAAU,EACjBC,KAAK,EACLC,KAAK,EACLC,KAAK,EACLC,KAAK,EACLC,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B,KAAK,GAAG,GAAGtB;oCAChB,MAAMsB,KAAK,KAAK,GAAGtB;oCACnB,OAAO;oCACP,QAAQsB,KAAK,MAAM,GAAG,IAAItB;gCAC5B;;;uCAIJ,IAAC;wBAAI,OAAO;4BAAE,OAAO;wBAAE;;;gBAI5BsB,OAAO,WAAPA,GACC,IAACqB,eAAaA;oBACZ,MAAMxD;oBACN,YAAY0B;oBACZ,UAAU9B;oBACV,WAAW6B,KAAK,SAAS,IAAI;oBAC7B,WAAWX;oBACX,MAAK;oBACL,cAAYF,QAAQoC;oBACpB,mBAAiB,GAAGf,GAAG,MAAM,CAAC;oBAC9B,WAAU;oBACV,UAAU;8BAETiB;mCAGH,IAAC;oBACC,KAAKtD;oBACL,MAAK;oBACL,cAAYgB,QAAQoC;oBACpB,mBAAiB,GAAGf,GAAG,MAAM,CAAC;oBAC9B,UAAU;oBACV,WAAU;8BAETiB;;;;;AAMb"}
|
|
1
|
+
{"version":3,"file":"tour/tour.js","sources":["../../../../../src/tour/tour.tsx"],"sourcesContent":["import { X } from 'lucide-react';\nimport { type ReactNode, type RefObject, useEffect, useId, useRef, useState } from 'react';\nimport { ButtonControl } from '../button/button';\nimport { useComponentProps } from '../config-provider/component-defaults';\nimport { useLeafConfig } from '../config-provider/context';\nimport { type OverlayLayer, useDialog, useOverlayLayer } from '../shared/dialog';\nimport { FloatingPanel, type PopupOptions } from '../shared/floating';\nimport { inertProps } from '../shared/inert';\nimport { useContentTransition, usePresence } from '../shared/presence';\nimport { ScopedPortal } from '../shared/scoped-portal';\nimport { useControllable } from '../shared/use-controllable';\nimport { useText } from '../shared/use-text';\nexport interface TourStep {\n key?: string;\n title: ReactNode;\n description?: ReactNode;\n target?: string | (() => HTMLElement | null);\n placement?: PopupOptions['popupPlacement'];\n}\nexport interface TourProps {\n open: boolean;\n steps: readonly TourStep[];\n current?: number;\n defaultCurrent?: number;\n onChange?: (current: number) => void;\n onClose?: () => void;\n onFinish?: () => void;\n missingTarget?: 'center' | 'skip' | 'close';\n mask?: boolean;\n padding?: number;\n getPopupContainer?: PopupOptions['getPopupContainer'];\n}\nfunction TourFocus({\n panel,\n owner,\n close,\n modal,\n open,\n children,\n}: {\n panel: RefObject<HTMLDivElement | null>;\n owner: string;\n close: () => void;\n modal: boolean;\n open: boolean;\n children: ReactNode;\n}) {\n useDialog(open, panel, owner, close, true, {}, true, modal);\n return children;\n}\nfunction TourStage({\n present,\n active,\n children,\n}: {\n present: boolean;\n active: boolean;\n children: (layer: OverlayLayer) => ReactNode;\n}) {\n // 在 ScopedPortal 就绪后分配叠层,确保与 Modal/Drawer 同轮挂载时叠层顺序一致。\n const layer = useOverlayLayer(present, active);\n return children(layer);\n}\nexport function Tour(rawProps: TourProps) {\n const {\n open,\n steps,\n current,\n defaultCurrent = 0,\n onChange,\n onClose,\n onFinish,\n missingTarget = 'center',\n mask = true,\n padding = 8,\n getPopupContainer,\n } = useComponentProps('Tour', rawProps);\n const t = useText();\n const { messages } = useLeafConfig();\n const [index, setIndex] = useControllable(current, defaultCurrent, onChange);\n const latestStep = useRef(steps[index]);\n if (open && steps[index]) latestStep.current = steps[index];\n const step = open ? steps[index] : latestStep.current;\n const target = useRef<HTMLElement | null>(null),\n panel = useRef<HTMLDivElement>(null);\n const root = useRef<HTMLDivElement>(null);\n const contentView = useRef<HTMLDivElement>(null);\n const present = usePresence(open && Boolean(step), root);\n useContentTransition(contentView, `${open}:${index}`);\n const id = useId();\n const [rect, setRect] = useState<DOMRect | null>(null);\n const callbacks = useRef({ setIndex, onClose });\n callbacks.current = { setIndex, onClose };\n useEffect(() => {\n if (!open || !step) return;\n let frame = 0;\n const node =\n typeof step.target === 'string'\n ? document.querySelector<HTMLElement>(step.target)\n : step.target?.();\n target.current = node ?? null;\n if (!node) {\n setRect(null);\n if (missingTarget === 'skip' && index < steps.length - 1)\n callbacks.current.setIndex(index + 1);\n else if (missingTarget === 'close' || missingTarget === 'skip') callbacks.current.onClose?.();\n return;\n }\n node.scrollIntoView?.({ block: 'center', behavior: 'instant' });\n const update = () => {\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(() => setRect(node.getBoundingClientRect()));\n };\n const observer = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(update) : undefined;\n observer?.observe(node);\n window.addEventListener('scroll', update, true);\n window.addEventListener('resize', update);\n update();\n return () => {\n cancelAnimationFrame(frame);\n observer?.disconnect();\n window.removeEventListener('scroll', update, true);\n window.removeEventListener('resize', update);\n };\n }, [open, step, index, missingTarget, steps.length]);\n if (!present || !step) return null;\n const content = (\n <TourFocus panel={panel} owner={id} close={() => onClose?.()} modal={mask} open={open}>\n <div ref={contentView} className=\"leaf-tour__content\">\n <div className=\"leaf-tour__header\">\n <h3 id={`${id}-title`}>{step.title}</h3>\n <ButtonControl\n size=\"sm\"\n variant=\"text\"\n startIcon={<X size={16} />}\n aria-label={messages.common.close}\n onClick={onClose}\n />\n </div>\n <div className=\"leaf-tour__description\">{step.description}</div>\n <div className=\"leaf-tour__footer\">\n <span>\n {index + 1} / {steps.length}\n </span>\n {index > 0 && (\n <ButtonControl size=\"sm\" variant=\"outline\" onClick={() => setIndex(index - 1)}>\n {t('tour.previous')}\n </ButtonControl>\n )}\n <ButtonControl\n size=\"sm\"\n variant=\"solid\"\n onClick={() => {\n if (index < steps.length - 1) setIndex(index + 1);\n else {\n onFinish?.();\n onClose?.();\n }\n }}\n >\n {index === steps.length - 1 ? t('tour.finish') : t('tour.next')}\n </ButtonControl>\n </div>\n </div>\n </TourFocus>\n );\n return (\n <ScopedPortal container={getPopupContainer}>\n <TourStage present={present} active={open && Boolean(step)}>\n {(layer) => (\n <div\n ref={root}\n className=\"leaf-tour-root\"\n style={layer.maskStyle}\n data-state={open ? 'open' : 'closing'}\n aria-hidden={!open || undefined}\n {...inertProps(!open)}\n >\n {mask && (\n <div className=\"leaf-tour__mask\" aria-hidden=\"true\">\n {rect ? (\n <>\n <div style={{ inset: `0 0 auto 0`, height: Math.max(0, rect.top - padding) }} />\n <div style={{ inset: `${rect.bottom + padding}px 0 0 0` }} />\n <div\n style={{\n top: rect.top - padding,\n left: 0,\n width: Math.max(0, rect.left - padding),\n height: rect.height + 2 * padding,\n }}\n />\n <div\n style={{\n top: rect.top - padding,\n left: rect.right + padding,\n right: 0,\n height: rect.height + 2 * padding,\n }}\n />\n </>\n ) : (\n <div style={{ inset: 0 }} />\n )}\n </div>\n )}\n {rect ? (\n <FloatingPanel\n open={open}\n triggerRef={target}\n panelRef={panel}\n placement={step.placement ?? 'bottom'}\n container={getPopupContainer}\n role=\"dialog\"\n aria-modal={mask || undefined}\n aria-labelledby={`${id}-title`}\n className=\"leaf-floating leaf-tour\"\n style={layer.floatingStyle}\n tabIndex={-1}\n >\n {content}\n </FloatingPanel>\n ) : (\n <div\n ref={panel}\n role=\"dialog\"\n aria-modal={mask || undefined}\n aria-labelledby={`${id}-title`}\n tabIndex={-1}\n className=\"leaf-tour leaf-tour--center\"\n style={layer.floatingStyle}\n >\n {content}\n </div>\n )}\n </div>\n )}\n </TourStage>\n </ScopedPortal>\n );\n}\n"],"names":["TourFocus","panel","owner","close","modal","open","children","useDialog","TourStage","present","active","layer","useOverlayLayer","Tour","rawProps","steps","current","defaultCurrent","onChange","onClose","onFinish","missingTarget","mask","padding","getPopupContainer","useComponentProps","t","useText","messages","useLeafConfig","index","setIndex","useControllable","latestStep","useRef","step","target","root","contentView","usePresence","Boolean","useContentTransition","id","useId","rect","setRect","useState","callbacks","useEffect","frame","node","document","update","cancelAnimationFrame","requestAnimationFrame","observer","ResizeObserver","undefined","window","content","ButtonControl","X","ScopedPortal","inertProps","Math","FloatingPanel"],"mappings":";;;;;;;;;;;;;;;;AAgCA,SAASA,UAAU,EACjBC,KAAK,EACLC,KAAK,EACLC,KAAK,EACLC,KAAK,EACLC,IAAI,EACJC,QAAQ,EAQT;IACCC,UAAUF,MAAMJ,OAAOC,OAAOC,OAAO,MAAM,CAAC,GAAG,MAAMC;IACrD,OAAOE;AACT;AACA,SAASE,UAAU,EACjBC,OAA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KAAK,IAAI,GAAGrB;4CAC/B,QAAQqB,KAAK,MAAM,GAAG,IAAIrB;wCAC5B;;kDAEF,IAAC;wCACC,OAAO;4CACL,KAAKqB,KAAK,GAAG,GAAGrB;4CAChB,MAAMqB,KAAK,KAAK,GAAGrB;4CACnB,OAAO;4CACP,QAAQqB,KAAK,MAAM,GAAG,IAAIrB;wCAC5B;;;+CAIJ,IAAC;gCAAI,OAAO;oCAAE,OAAO;gCAAE;;;wBAI5BqB,OAAO,WAAPA,GACC,IAACqB,eAAaA;4BACZ,MAAM5D;4BACN,YAAY+B;4BACZ,UAAUnC;4BACV,WAAWkC,KAAK,SAAS,IAAI;4BAC7B,WAAWX;4BACX,MAAK;4BACL,cAAYF,QAAQmC;4BACpB,mBAAiB,GAAGf,GAAG,MAAM,CAAC;4BAC9B,WAAU;4BACV,OAAO/B,MAAM,aAAa;4BAC1B,UAAU;sCAETgD;2CAGH,IAAC;4BACC,KAAK1D;4BACL,MAAK;4BACL,cAAYqB,QAAQmC;4BACpB,mBAAiB,GAAGf,GAAG,MAAM,CAAC;4BAC9B,UAAU;4BACV,WAAU;4BACV,OAAO/B,MAAM,aAAa;sCAEzBgD;;;;;;AAQjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drawer.d.ts","sourceRoot":"","sources":["../../../src/drawer/drawer.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,SAAS,EAOf,MAAM,OAAO,CAAC;AAKf,OAAO,EAAE,KAAK,kBAAkB,
|
|
1
|
+
{"version":3,"file":"drawer.d.ts","sourceRoot":"","sources":["../../../src/drawer/drawer.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,SAAS,EAOf,MAAM,OAAO,CAAC;AAKf,OAAO,EAAE,KAAK,kBAAkB,EAA8B,MAAM,kBAAkB,CAAC;AAKvF,OAAO,EAAgB,KAAK,SAAS,EAAgB,MAAM,cAAc,CAAC;AAI1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,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAiWD,wBAAgB,MAAM,CAAC,QAAQ,EAAE,WAAW,+BAW3C"}
|
|
@@ -6,7 +6,7 @@ import { useComponentProps } from "../config-provider/component-defaults.js";
|
|
|
6
6
|
import { useLeafConfig } from "../config-provider/context.js";
|
|
7
7
|
import { ScrollbarControl } from "../scrollbar/scrollbar.js";
|
|
8
8
|
import { classes } from "../shared/classes.js";
|
|
9
|
-
import { useDialog } from "../shared/dialog.js";
|
|
9
|
+
import { useDialog, useOverlayLayer } from "../shared/dialog.js";
|
|
10
10
|
import { inertProps } from "../shared/inert.js";
|
|
11
11
|
import { OverlayOwner } from "../shared/overlay-owner.js";
|
|
12
12
|
import { useContentTransition, usePresence } from "../shared/presence.js";
|
|
@@ -116,6 +116,7 @@ function DrawerSurface({ open, title, description, icon, divided = false, tabs,
|
|
|
116
116
|
const backdrop = useRef(null);
|
|
117
117
|
const content = useRef(null);
|
|
118
118
|
const present = usePresence(open, backdrop);
|
|
119
|
+
const layer = useOverlayLayer(present, open);
|
|
119
120
|
const hasTabs = Boolean(tabs?.items?.length);
|
|
120
121
|
const hasHeading = null != title || null != description || null != icon;
|
|
121
122
|
const contentRevision = useRef({
|
|
@@ -173,6 +174,7 @@ function DrawerSurface({ open, title, description, icon, divided = false, tabs,
|
|
|
173
174
|
return /*#__PURE__*/ jsxs("div", {
|
|
174
175
|
hidden: !present,
|
|
175
176
|
className: classes('leaf-drawer-mask', `leaf-drawer-mask--${placement}`),
|
|
177
|
+
style: layer.maskStyle,
|
|
176
178
|
"data-blur": maskBlur ? void 0 : 'off',
|
|
177
179
|
"data-state": open ? 'open' : 'closing',
|
|
178
180
|
"aria-hidden": !open || void 0,
|
|
@@ -209,6 +211,7 @@ function DrawerSurface({ open, title, description, icon, divided = false, tabs,
|
|
|
209
211
|
height: resized ?? height,
|
|
210
212
|
width: '100%'
|
|
211
213
|
},
|
|
214
|
+
...layer.popupStyle,
|
|
212
215
|
...style
|
|
213
216
|
},
|
|
214
217
|
children: [
|
|
@@ -293,6 +296,11 @@ function DrawerSurface({ open, title, description, icon, divided = false, tabs,
|
|
|
293
296
|
}
|
|
294
297
|
function Drawer(rawProps) {
|
|
295
298
|
const props = useComponentProps('Drawer', rawProps);
|
|
299
|
+
const visited = useRef(false);
|
|
300
|
+
if (props.open || props.forceRender) visited.current = true;
|
|
301
|
+
if (!visited.current) return /*#__PURE__*/ jsx("span", {
|
|
302
|
+
hidden: true
|
|
303
|
+
});
|
|
296
304
|
return /*#__PURE__*/ jsx(ScopedPortal, {
|
|
297
305
|
container: props.container,
|
|
298
306
|
children: /*#__PURE__*/ jsx(DrawerSurface, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drawer/drawer.js","sources":["../../../src/drawer/drawer.tsx"],"sourcesContent":["import { X } from 'lucide-react';\nimport {\n type HTMLAttributes,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useId,\n useRef,\n useState,\n} from 'react';\nimport { useComponentProps } from '../config-provider/component-defaults';\nimport { useLeafConfig } from '../config-provider/context';\nimport { ScrollbarControl } 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 { useContentTransition, usePresence } from '../shared/presence';\nimport { ScopedPortal } from '../shared/scoped-portal';\nimport { type TabItem, type TabsProps, useTabsParts } from '../tabs/tabs';\n\nconst emptyTabItems: readonly TabItem[] = [];\n\n/** Tabs controls integrated with the drawer; Drawer fixes the line type and top placement. */\nexport interface DrawerTabsProps extends Omit<TabsProps, 'type' | 'placement' | 'children'> {}\n\nexport interface DrawerProps\n extends Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'onResize'>,\n DialogFocusOptions {\n open: boolean;\n title?: ReactNode;\n description?: ReactNode;\n icon?: ReactNode;\n divided?: boolean;\n /** Embedded tabs placed below the heading, or replacing it when no title is supplied. */\n tabs?: DrawerTabsProps;\n footer?: ReactNode;\n extra?: ReactNode;\n placement?: 'left' | 'right' | 'top' | 'bottom';\n width?: number | string;\n height?: 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 push?: boolean | number;\n resizable?: boolean;\n minSize?: number;\n maxSize?: number;\n onResize?: (size: number) => void;\n}\n\ninterface DrawerInnerProps {\n id: string;\n open: boolean;\n title?: ReactNode;\n description?: ReactNode;\n icon?: ReactNode;\n tabs?: DrawerTabsProps;\n extra?: ReactNode;\n footer?: ReactNode;\n closable: boolean;\n onClose?: () => void;\n contentRef: Ref<HTMLDivElement>;\n ariaLabel?: string;\n ariaLabelledBy?: string;\n children?: ReactNode;\n}\n\nfunction DrawerInner({\n id,\n open,\n title,\n description,\n icon,\n tabs,\n extra,\n footer,\n closable,\n onClose,\n contentRef,\n ariaLabel,\n ariaLabelledBy,\n children,\n}: DrawerInnerProps) {\n const { messages } = useLeafConfig();\n const hasTabs = Boolean(tabs?.items?.length);\n const hasHeading = title != null || description != null || icon != null;\n const closeButton = closable ? (\n <button\n type=\"button\"\n className=\"leaf-drawer__close\"\n aria-label={messages.common.close}\n onClick={onClose}\n >\n <X size={16} aria-hidden=\"true\" />\n </button>\n ) : null;\n const extraNode = extra != null ? <div className=\"leaf-drawer__extra\">{extra}</div> : null;\n const tabExtra =\n !hasHeading && (extra != null || closable) ? (\n <div className=\"leaf-dialog-tab-extra leaf-drawer__tab-extra\">\n {tabs?.extra}\n {extraNode}\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 ? `${id}-title`\n : tabs?.['aria-label'] == null\n ? ariaLabelledBy\n : undefined);\n const parts = useTabsParts({\n ...tabs,\n items: tabs?.items ?? emptyTabItems,\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-drawer__tabs',\n tabs?.className,\n ),\n panelsClassName: 'leaf-dialog-panels',\n visibilityKey: open,\n });\n\n return (\n <>\n {(hasHeading || (!hasTabs && (extra != null || closable))) && (\n <div\n className={classes('leaf-drawer__header', !hasHeading && 'leaf-drawer__header--compact')}\n >\n {icon != null && (\n <span className=\"leaf-drawer__icon\" aria-hidden=\"true\">\n {icon}\n </span>\n )}\n {(title != null || description != null) && (\n <div className=\"leaf-drawer__heading\">\n {title != null && <h2 id={`${id}-title`}>{title}</h2>}\n {description != null && (\n <div id={`${id}-description`} className=\"leaf-drawer__description\">\n {description}\n </div>\n )}\n </div>\n )}\n {extraNode}\n {closeButton}\n </div>\n )}\n {parts && <div {...parts.rootProps}>{parts.header}</div>}\n <ScrollbarControl\n className=\"leaf-drawer__body\"\n viewportClassName=\"leaf-drawer__viewport\"\n orientation=\"vertical\"\n role={title != null || ariaLabel ? 'region' : 'presentation'}\n aria-labelledby={title != null ? `${id}-title` : undefined}\n aria-label={title == null ? (ariaLabel ?? tabs?.['aria-label']) : undefined}\n >\n <div ref={contentRef} className=\"leaf-drawer__content\">\n {parts?.panels}\n {children}\n </div>\n </ScrollbarControl>\n {footer != null && <div className=\"leaf-drawer__footer\">{footer}</div>}\n </>\n );\n}\n\nfunction DrawerSurface({\n open,\n title,\n description,\n icon,\n divided = false,\n tabs,\n footer,\n extra,\n placement = 'right',\n width = 380,\n height = 300,\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 push = false,\n resizable = false,\n minSize = 240,\n maxSize = 900,\n onResize,\n children,\n className,\n style,\n ...props\n}: DrawerProps) {\n const { messages, maskBlur } = useLeafConfig();\n const id = useId();\n const panel = useRef<HTMLDivElement>(null);\n const backdrop = useRef<HTMLButtonElement>(null);\n const content = useRef<HTMLDivElement>(null);\n const present = usePresence(open, backdrop);\n const hasTabs = Boolean(tabs?.items?.length);\n const hasHeading = title != null || description != null || icon != null;\n const contentRevision = useRef({ children, revision: 0 });\n if (children !== contentRevision.current.children)\n contentRevision.current = { children, revision: contentRevision.current.revision + 1 };\n useContentTransition(\n content,\n hasTabs ? String(open) : `${open}:${contentRevision.current.revision}`,\n 0,\n true,\n );\n const owner = useContext(OverlayOwner);\n const [resized, setResized] = useState<number>();\n const stopDragging = useRef<(() => void) | undefined>(undefined);\n useEffect(() => () => stopDragging.current?.(), []);\n const horizontal = placement === 'left' || placement === 'right';\n // biome-ignore lint/correctness/useExhaustiveDependencies: Resizing resets when the configured dimensions change.\n useEffect(() => {\n setResized(undefined);\n }, [width, height]);\n useEffect(() => {\n if (!open || !push || !owner) return;\n const parent = document.getElementById(owner);\n if (!parent) return;\n const previous = parent.style.transform;\n const distance = typeof push === 'number' ? push : 40;\n parent.style.transform = `translate${horizontal ? 'X' : 'Y'}(${placement === 'right' || placement === 'bottom' ? -distance : distance}px)`;\n return () => {\n parent.style.transform = previous;\n };\n }, [open, push, owner, placement, horizontal]);\n const previous = useRef(false);\n useEffect(() => {\n if (previous.current && !present) afterClose?.();\n previous.current = present;\n }, [present, afterClose]);\n useDialog(open, panel, id, () => onClose?.(), 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={classes('leaf-drawer-mask', `leaf-drawer-mask--${placement}`)}\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 tabIndex={-1}\n className=\"leaf-drawer-backdrop\"\n aria-label={messages.common.close}\n onClick={() => {\n if (maskClosable) onClose?.();\n }}\n />\n <div\n {...props}\n ref={panel}\n id={props.id ?? id}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={title != null ? `${id}-title` : props['aria-labelledby']}\n aria-describedby={\n [props['aria-describedby'], description != null && `${id}-description`]\n .filter(Boolean)\n .join(' ') || undefined\n }\n tabIndex={-1}\n className={classes(\n 'leaf-drawer',\n divided && 'leaf-drawer--divided',\n hasTabs && 'leaf-drawer--tabbed',\n hasHeading && 'leaf-drawer--headed',\n className,\n )}\n style={{\n ...(horizontal\n ? { width: resized ?? width, height: '100%' }\n : { height: resized ?? height, width: '100%' }),\n ...style,\n }}\n >\n {resizable && (\n // biome-ignore lint/a11y/useSemanticElements: This is the adjustable ARIA window-splitter handle, not a decorative separator.\n <div\n role=\"separator\"\n tabIndex={0}\n aria-label={messages.tree.expand}\n aria-orientation={horizontal ? 'vertical' : 'horizontal'}\n aria-valuemin={minSize}\n aria-valuemax={maxSize}\n aria-valuenow={\n resized ??\n (typeof (horizontal ? width : height) === 'number'\n ? Number(horizontal ? width : height)\n : undefined)\n }\n className=\"leaf-drawer__resize\"\n onPointerDown={(event) => {\n if (!panel.current) return;\n stopDragging.current?.();\n event.preventDefault();\n event.currentTarget.setPointerCapture(event.pointerId);\n const start = horizontal ? event.clientX : event.clientY;\n const bounds = panel.current.getBoundingClientRect();\n const size = horizontal ? bounds.width : bounds.height;\n const update = (event: PointerEvent) => {\n const next = Math.min(\n maxSize,\n Math.max(\n minSize,\n size +\n ((horizontal ? event.clientX : event.clientY) - start) *\n (placement === 'right' || placement === 'bottom' ? -1 : 1),\n ),\n );\n setResized(next);\n onResize?.(next);\n };\n const end = () => {\n window.removeEventListener('pointermove', update);\n window.removeEventListener('pointerup', end);\n window.removeEventListener('pointercancel', end);\n };\n stopDragging.current = end;\n window.addEventListener('pointermove', update);\n window.addEventListener('pointerup', end, { once: true });\n window.addEventListener('pointercancel', end, { once: true });\n }}\n onKeyDown={(event) => {\n if (!panel.current) return;\n if (!['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(event.key)) return;\n event.preventDefault();\n const bounds = panel.current.getBoundingClientRect();\n const size = horizontal ? bounds.width : bounds.height;\n const next = Math.min(\n maxSize,\n Math.max(\n minSize,\n size +\n (['ArrowRight', 'ArrowDown'].includes(event.key) ? 10 : -10) *\n (placement === 'right' || placement === 'bottom' ? -1 : 1),\n ),\n );\n setResized(next);\n onResize?.(next);\n }}\n />\n )}\n <OverlayOwner.Provider value={id}>\n <DrawerInner\n id={id}\n open={open}\n title={title}\n description={description}\n icon={icon}\n tabs={tabs}\n extra={extra}\n footer={footer}\n closable={closable}\n onClose={onClose}\n contentRef={content}\n ariaLabel={props['aria-label']}\n ariaLabelledBy={props['aria-labelledby']}\n >\n {children}\n </DrawerInner>\n </OverlayOwner.Provider>\n </div>\n </div>\n );\n}\nexport function Drawer(rawProps: DrawerProps) {\n const props = useComponentProps('Drawer', rawProps);\n return (\n <ScopedPortal container={props.container}>\n <DrawerSurface {...props} />\n </ScopedPortal>\n );\n}\n"],"names":["emptyTabItems","DrawerInner","id","open","title","description","icon","tabs","extra","footer","closable","onClose","contentRef","ariaLabel","ariaLabelledBy","children","messages","useLeafConfig","hasTabs","Boolean","hasHeading","closeButton","X","extraNode","tabExtra","tabLabel","tabLabelledBy","undefined","parts","useTabsParts","classes","ScrollbarControl","DrawerSurface","divided","placement","width","height","maskClosable","keyboard","afterClose","forceRender","destroyOnClose","preserve","initialFocus","returnFocus","_container","push","resizable","minSize","maxSize","onResize","className","style","props","maskBlur","useId","panel","useRef","backdrop","content","present","usePresence","contentRevision","useContentTransition","String","owner","useContext","OverlayOwner","resized","setResized","useState","stopDragging","useEffect","horizontal","parent","document","previous","distance","useDialog","visited","inertProps","Number","event","start","bounds","size","update","next","Math","end","window","Drawer","rawProps","useComponentProps","ScopedPortal"],"mappings":";;;;;;;;;;;;;;AAsBA,MAAMA,gBAAoC,EAAE;AAqD5C,SAASC,YAAY,EACnBC,EAAE,EACFC,IAAI,EACJC,KAAK,EACLC,WAAW,EACXC,IAAI,EACJC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACPC,UAAU,EACVC,SAAS,EACTC,cAAc,EACdC,QAAQ,EACS;IACjB,MAAM,EAAEC,QAAQ,EAAE,GAAGC;IACrB,MAAMC,UAAUC,QAAQZ,MAAM,OAAO;IACrC,MAAMa,aAAahB,AAAS,QAATA,SAAiBC,AAAe,QAAfA,eAAuBC,AAAQ,QAARA;IAC3D,MAAMe,cAAcX,WAAW,WAAXA,GAClB,IAAC;QACC,MAAK;QACL,WAAU;QACV,cAAYM,SAAS,MAAM,CAAC,KAAK;QACjC,SAASL;kBAET,kBAACW,GAACA;YAAC,MAAM;YAAI,eAAY;;SAEzB;IACJ,MAAMC,YAAYf,AAAS,QAATA,QAAgB,WAAP,GAAO,IAAC;QAAI,WAAU;kBAAsBA;SAAe;IACtF,MAAMgB,WACJ,CAACJ,cAAeZ,CAAAA,AAAS,QAATA,SAAiBE,QAAO,kBACtC,KAAC;QAAI,WAAU;;YACZH,MAAM;YACNgB;YACAF;;SAGHd,MAAM;IAEV,MAAMkB,WAAWlB,MAAM,CAAC,aAAa,IAAK,CAAiB,YAAjB,OAAOH,QAAqBA,QAAQS,SAAQ;IACtF,MAAMa,gBACJnB,MAAM,CAAC,kBAAkB,IACxBA,CAAAA,MAAM,CAAC,aAAa,IAAI,QAAQH,AAAS,QAATA,QAC7B,GAAGF,GAAG,MAAM,CAAC,GACbK,MAAM,CAAC,aAAa,IAAI,OACtBO,iBACAa,MAAQ;IAChB,MAAMC,QAAQC,aAAa;QACzB,GAAGtB,IAAI;QACP,OAAOA,MAAM,SAASP;QACtB,MAAM;QACN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AAyB,KAAK;4BAGhEmC,WAAWkB;4BACXrC,WAAWqC;wBACb;;kCAGJ,IAACpB,aAAa,QAAQ;wBAAC,OAAOjE;kCAC5B,kBAACD,aAAWA;4BACV,IAAIC;4BACJ,MAAMC;4BACN,OAAOC;4BACP,aAAaC;4BACb,MAAMC;4BACN,MAAMC;4BACN,OAAOC;4BACP,QAAQC;4BACR,UAAUC;4BACV,SAASC;4BACT,YAAYgD;4BACZ,WAAWN,KAAK,CAAC,aAAa;4BAC9B,gBAAgBA,KAAK,CAAC,kBAAkB;sCAEvCtC;;;;;;;AAMb;AACO,SAAS4E,OAAOC,QAAqB;IAC1C,MAAMvC,QAAQwC,kBAAkB,UAAUD;IAC1C,OAAO,WAAP,GACE,IAACE,cAAYA;QAAC,WAAWzC,MAAM,SAAS;kBACtC,kBAACrB,eAAaA;YAAE,GAAGqB,KAAK;;;AAG9B"}
|
|
1
|
+
{"version":3,"file":"drawer/drawer.js","sources":["../../../src/drawer/drawer.tsx"],"sourcesContent":["import { X } from 'lucide-react';\nimport {\n type HTMLAttributes,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useId,\n useRef,\n useState,\n} from 'react';\nimport { useComponentProps } from '../config-provider/component-defaults';\nimport { useLeafConfig } from '../config-provider/context';\nimport { ScrollbarControl } from '../scrollbar/scrollbar';\nimport { classes } from '../shared/classes';\nimport { type DialogFocusOptions, useDialog, useOverlayLayer } from '../shared/dialog';\nimport { inertProps } from '../shared/inert';\nimport { OverlayOwner } from '../shared/overlay-owner';\nimport { useContentTransition, usePresence } from '../shared/presence';\nimport { ScopedPortal } from '../shared/scoped-portal';\nimport { type TabItem, type TabsProps, useTabsParts } from '../tabs/tabs';\n\nconst emptyTabItems: readonly TabItem[] = [];\n\n/** Tabs controls integrated with the drawer; Drawer fixes the line type and top placement. */\nexport interface DrawerTabsProps extends Omit<TabsProps, 'type' | 'placement' | 'children'> {}\n\nexport interface DrawerProps\n extends Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'onResize'>,\n DialogFocusOptions {\n open: boolean;\n title?: ReactNode;\n description?: ReactNode;\n icon?: ReactNode;\n divided?: boolean;\n /** Embedded tabs placed below the heading, or replacing it when no title is supplied. */\n tabs?: DrawerTabsProps;\n footer?: ReactNode;\n extra?: ReactNode;\n placement?: 'left' | 'right' | 'top' | 'bottom';\n width?: number | string;\n height?: 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 push?: boolean | number;\n resizable?: boolean;\n minSize?: number;\n maxSize?: number;\n onResize?: (size: number) => void;\n}\n\ninterface DrawerInnerProps {\n id: string;\n open: boolean;\n title?: ReactNode;\n description?: ReactNode;\n icon?: ReactNode;\n tabs?: DrawerTabsProps;\n extra?: ReactNode;\n footer?: ReactNode;\n closable: boolean;\n onClose?: () => void;\n contentRef: Ref<HTMLDivElement>;\n ariaLabel?: string;\n ariaLabelledBy?: string;\n children?: ReactNode;\n}\n\nfunction DrawerInner({\n id,\n open,\n title,\n description,\n icon,\n tabs,\n extra,\n footer,\n closable,\n onClose,\n contentRef,\n ariaLabel,\n ariaLabelledBy,\n children,\n}: DrawerInnerProps) {\n const { messages } = useLeafConfig();\n const hasTabs = Boolean(tabs?.items?.length);\n const hasHeading = title != null || description != null || icon != null;\n const closeButton = closable ? (\n <button\n type=\"button\"\n className=\"leaf-drawer__close\"\n aria-label={messages.common.close}\n onClick={onClose}\n >\n <X size={16} aria-hidden=\"true\" />\n </button>\n ) : null;\n const extraNode = extra != null ? <div className=\"leaf-drawer__extra\">{extra}</div> : null;\n const tabExtra =\n !hasHeading && (extra != null || closable) ? (\n <div className=\"leaf-dialog-tab-extra leaf-drawer__tab-extra\">\n {tabs?.extra}\n {extraNode}\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 ? `${id}-title`\n : tabs?.['aria-label'] == null\n ? ariaLabelledBy\n : undefined);\n const parts = useTabsParts({\n ...tabs,\n items: tabs?.items ?? emptyTabItems,\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-drawer__tabs',\n tabs?.className,\n ),\n panelsClassName: 'leaf-dialog-panels',\n visibilityKey: open,\n });\n\n return (\n <>\n {(hasHeading || (!hasTabs && (extra != null || closable))) && (\n <div\n className={classes('leaf-drawer__header', !hasHeading && 'leaf-drawer__header--compact')}\n >\n {icon != null && (\n <span className=\"leaf-drawer__icon\" aria-hidden=\"true\">\n {icon}\n </span>\n )}\n {(title != null || description != null) && (\n <div className=\"leaf-drawer__heading\">\n {title != null && <h2 id={`${id}-title`}>{title}</h2>}\n {description != null && (\n <div id={`${id}-description`} className=\"leaf-drawer__description\">\n {description}\n </div>\n )}\n </div>\n )}\n {extraNode}\n {closeButton}\n </div>\n )}\n {parts && <div {...parts.rootProps}>{parts.header}</div>}\n <ScrollbarControl\n className=\"leaf-drawer__body\"\n viewportClassName=\"leaf-drawer__viewport\"\n orientation=\"vertical\"\n role={title != null || ariaLabel ? 'region' : 'presentation'}\n aria-labelledby={title != null ? `${id}-title` : undefined}\n aria-label={title == null ? (ariaLabel ?? tabs?.['aria-label']) : undefined}\n >\n <div ref={contentRef} className=\"leaf-drawer__content\">\n {parts?.panels}\n {children}\n </div>\n </ScrollbarControl>\n {footer != null && <div className=\"leaf-drawer__footer\">{footer}</div>}\n </>\n );\n}\n\nfunction DrawerSurface({\n open,\n title,\n description,\n icon,\n divided = false,\n tabs,\n footer,\n extra,\n placement = 'right',\n width = 380,\n height = 300,\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 push = false,\n resizable = false,\n minSize = 240,\n maxSize = 900,\n onResize,\n children,\n className,\n style,\n ...props\n}: DrawerProps) {\n const { messages, maskBlur } = useLeafConfig();\n const id = useId();\n const panel = useRef<HTMLDivElement>(null);\n const backdrop = useRef<HTMLButtonElement>(null);\n const content = useRef<HTMLDivElement>(null);\n const present = usePresence(open, backdrop);\n const layer = useOverlayLayer(present, open);\n const hasTabs = Boolean(tabs?.items?.length);\n const hasHeading = title != null || description != null || icon != null;\n const contentRevision = useRef({ children, revision: 0 });\n if (children !== contentRevision.current.children)\n contentRevision.current = { children, revision: contentRevision.current.revision + 1 };\n useContentTransition(\n content,\n hasTabs ? String(open) : `${open}:${contentRevision.current.revision}`,\n 0,\n true,\n );\n const owner = useContext(OverlayOwner);\n const [resized, setResized] = useState<number>();\n const stopDragging = useRef<(() => void) | undefined>(undefined);\n useEffect(() => () => stopDragging.current?.(), []);\n const horizontal = placement === 'left' || placement === 'right';\n // biome-ignore lint/correctness/useExhaustiveDependencies: Resizing resets when the configured dimensions change.\n useEffect(() => {\n setResized(undefined);\n }, [width, height]);\n useEffect(() => {\n if (!open || !push || !owner) return;\n const parent = document.getElementById(owner);\n if (!parent) return;\n const previous = parent.style.transform;\n const distance = typeof push === 'number' ? push : 40;\n parent.style.transform = `translate${horizontal ? 'X' : 'Y'}(${placement === 'right' || placement === 'bottom' ? -distance : distance}px)`;\n return () => {\n parent.style.transform = previous;\n };\n }, [open, push, owner, placement, horizontal]);\n const previous = useRef(false);\n useEffect(() => {\n if (previous.current && !present) afterClose?.();\n previous.current = present;\n }, [present, afterClose]);\n useDialog(open, panel, id, () => onClose?.(), 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={classes('leaf-drawer-mask', `leaf-drawer-mask--${placement}`)}\n style={layer.maskStyle}\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 tabIndex={-1}\n className=\"leaf-drawer-backdrop\"\n aria-label={messages.common.close}\n onClick={() => {\n if (maskClosable) onClose?.();\n }}\n />\n <div\n {...props}\n ref={panel}\n id={props.id ?? id}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={title != null ? `${id}-title` : props['aria-labelledby']}\n aria-describedby={\n [props['aria-describedby'], description != null && `${id}-description`]\n .filter(Boolean)\n .join(' ') || undefined\n }\n tabIndex={-1}\n className={classes(\n 'leaf-drawer',\n divided && 'leaf-drawer--divided',\n hasTabs && 'leaf-drawer--tabbed',\n hasHeading && 'leaf-drawer--headed',\n className,\n )}\n style={{\n ...(horizontal\n ? { width: resized ?? width, height: '100%' }\n : { height: resized ?? height, width: '100%' }),\n ...layer.popupStyle,\n ...style,\n }}\n >\n {resizable && (\n // biome-ignore lint/a11y/useSemanticElements: This is the adjustable ARIA window-splitter handle, not a decorative separator.\n <div\n role=\"separator\"\n tabIndex={0}\n aria-label={messages.tree.expand}\n aria-orientation={horizontal ? 'vertical' : 'horizontal'}\n aria-valuemin={minSize}\n aria-valuemax={maxSize}\n aria-valuenow={\n resized ??\n (typeof (horizontal ? width : height) === 'number'\n ? Number(horizontal ? width : height)\n : undefined)\n }\n className=\"leaf-drawer__resize\"\n onPointerDown={(event) => {\n if (!panel.current) return;\n stopDragging.current?.();\n event.preventDefault();\n event.currentTarget.setPointerCapture(event.pointerId);\n const start = horizontal ? event.clientX : event.clientY;\n const bounds = panel.current.getBoundingClientRect();\n const size = horizontal ? bounds.width : bounds.height;\n const update = (event: PointerEvent) => {\n const next = Math.min(\n maxSize,\n Math.max(\n minSize,\n size +\n ((horizontal ? event.clientX : event.clientY) - start) *\n (placement === 'right' || placement === 'bottom' ? -1 : 1),\n ),\n );\n setResized(next);\n onResize?.(next);\n };\n const end = () => {\n window.removeEventListener('pointermove', update);\n window.removeEventListener('pointerup', end);\n window.removeEventListener('pointercancel', end);\n };\n stopDragging.current = end;\n window.addEventListener('pointermove', update);\n window.addEventListener('pointerup', end, { once: true });\n window.addEventListener('pointercancel', end, { once: true });\n }}\n onKeyDown={(event) => {\n if (!panel.current) return;\n if (!['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(event.key)) return;\n event.preventDefault();\n const bounds = panel.current.getBoundingClientRect();\n const size = horizontal ? bounds.width : bounds.height;\n const next = Math.min(\n maxSize,\n Math.max(\n minSize,\n size +\n (['ArrowRight', 'ArrowDown'].includes(event.key) ? 10 : -10) *\n (placement === 'right' || placement === 'bottom' ? -1 : 1),\n ),\n );\n setResized(next);\n onResize?.(next);\n }}\n />\n )}\n <OverlayOwner.Provider value={id}>\n <DrawerInner\n id={id}\n open={open}\n title={title}\n description={description}\n icon={icon}\n tabs={tabs}\n extra={extra}\n footer={footer}\n closable={closable}\n onClose={onClose}\n contentRef={content}\n ariaLabel={props['aria-label']}\n ariaLabelledBy={props['aria-labelledby']}\n >\n {children}\n </DrawerInner>\n </OverlayOwner.Provider>\n </div>\n </div>\n );\n}\nexport function Drawer(rawProps: DrawerProps) {\n const props = useComponentProps('Drawer', rawProps);\n const visited = useRef(false);\n // 首次打开或显式 forceRender 前保留行内锚点并延迟挂载 ScopedPortal,避免提前在 body 占位。\n if (props.open || props.forceRender) visited.current = true;\n if (!visited.current) return <span hidden />;\n return (\n <ScopedPortal container={props.container}>\n <DrawerSurface {...props} />\n </ScopedPortal>\n );\n}\n"],"names":["emptyTabItems","DrawerInner","id","open","title","description","icon","tabs","extra","footer","closable","onClose","contentRef","ariaLabel","ariaLabelledBy","children","messages","useLeafConfig","hasTabs","Boolean","hasHeading","closeButton","X","extraNode","tabExtra","tabLabel","tabLabelledBy","undefined","parts","useTabsParts","classes","ScrollbarControl","DrawerSurface","divided","placement","width","height","maskClosable","keyboard","afterClose","forceRender","destroyOnClose","preserve","initialFocus","returnFocus","_container","push","resizable","minSize","maxSize","onResize","className","style","props","maskBlur","useId","panel","useRef","backdrop","content","present","usePresence","layer","useOverlayLayer","contentRevision","useContentTransition","String","owner","useContext","OverlayOwner","resized","setResized","useState","stopDragging","useEffect","horizontal","parent","document","previous","distance","useDialog","visited","inertProps","Number","event","start","bounds","size","update","next","Math","end","window","Drawer","rawProps","useComponentProps","ScopedPortal"],"mappings":";;;;;;;;;;;;;;AAsBA,MAAMA,gBAAoC,EAAE;AAqD5C,SAASC,YAAY,EACnBC,EAAE,EACFC,IAAI,EACJC,KAAK,EACLC,WAAW,EACXC,IAAI,EACJC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACPC,UAAU,EACVC,SAAS,EACTC,cAAc,EACdC,QAAQ,EACS;IACjB,MAAM,EAAEC,QAAQ,EAAE,GAAGC;IACrB,MAAMC,UAAUC,QAAQZ,MAAM,OAAO;IACrC,MAAMa,aAAahB,AAAS,QAATA,SAAiBC,AAAe,QAAfA,eAAuBC,AAAQ,QAARA;IAC3D,MAAMe,cAAcX,WAAW,WAAXA,GAClB,IAAC;QACC,MAAK;QACL,WAAU;QACV,cAAYM,SAAS,MAAM,CAAC,KAAK;QACjC,SAASL;kBAET,kBAACW,GAACA;YAAC,MAAM;YAAI,eAAY;;SAEzB;IACJ,MAAMC,YAAYf,AAAS,QAATA,QAAgB,WAAP,GAAO,IAAC;QAAI,WAAU;kBAAsBA;SAAe;IACtF,MAAMgB,WACJ,CAACJ,cAAeZ,CAAAA,AAAS,QAATA,SAAiBE,QAAO,kBACtC,KAAC;QAAI,WAAU;;YACZH,MAAM;YACNgB;YACAF;;SAGHd,MAAM;IAEV,MAAMkB,WAAWlB,MAAM,CAAC,aAAa,IAAK,CAAiB,YAAjB,OAAOH,QAAqBA,QAAQS,SAAQ;IAC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Horizontal2, FlipVertical2, ImageOff, Minus, Plus, RefreshCw, RotateCcw, RotateCw, X } from "lucide-react";
|
|
4
4
|
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
5
|
-
import { useDialog } from "../shared/dialog.js";
|
|
5
|
+
import { useDialog, useOverlayLayer } from "../shared/dialog.js";
|
|
6
6
|
import { useMotionEnabled } from "../shared/motion.js";
|
|
7
7
|
import { usePresence } from "../shared/presence.js";
|
|
8
8
|
import { ScopedPortal } from "../shared/scoped-portal.js";
|
|
@@ -151,6 +151,7 @@ function ViewerHost({ items, open, index = 0, thumbnails = true, downloadable =
|
|
|
151
151
|
initialFocus: root,
|
|
152
152
|
returnFocus: false
|
|
153
153
|
});
|
|
154
|
+
const layer = useOverlayLayer(present, visible);
|
|
154
155
|
useEffect(()=>{
|
|
155
156
|
if (present) {
|
|
156
157
|
reportedHidden.current = false;
|
|
@@ -459,6 +460,7 @@ function ViewerHost({ items, open, index = 0, thumbnails = true, downloadable =
|
|
|
459
460
|
"aria-describedby": `${id}-position`,
|
|
460
461
|
tabIndex: -1,
|
|
461
462
|
className: "leaf-image-viewer",
|
|
463
|
+
style: layer.maskStyle,
|
|
462
464
|
"data-state": visible ? 'open' : 'closing',
|
|
463
465
|
"data-motion": motion ? 'on' : 'off',
|
|
464
466
|
onKeyDown: (event)=>{
|