dishui 0.0.82 → 0.0.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Button/index.d.ts +1 -0
- package/dist/components/Button/index.js.map +1 -1
- package/dist/components/ButtonMenu/index.d.ts +28 -0
- package/dist/components/ButtonMenu/index.js +197 -0
- package/dist/components/ButtonMenu/index.js.map +1 -0
- package/dist/components/Demo/index.d.ts +5 -0
- package/dist/components/Demo/index.js +131 -56
- package/dist/components/Demo/index.js.map +1 -1
- package/dist/components/Demo/source.d.ts +9 -0
- package/dist/components/Demo/source.js +32 -0
- package/dist/components/Demo/source.js.map +1 -0
- package/dist/components/Field/index.d.ts +8 -0
- package/dist/components/Field/index.js +43 -0
- package/dist/components/Field/index.js.map +1 -0
- package/dist/components/LayoutSuite/DashboardSuite.d.ts +35 -0
- package/dist/components/LayoutSuite/DashboardSuite.js +61 -0
- package/dist/components/LayoutSuite/DashboardSuite.js.map +1 -0
- package/dist/components/LayoutSuite/index.d.ts +56 -0
- package/dist/components/LayoutSuite/index.js +101 -0
- package/dist/components/LayoutSuite/index.js.map +1 -0
- package/dist/components/Modal/focusScope.d.ts +1 -0
- package/dist/components/Modal/focusScope.js +81 -0
- package/dist/components/Modal/focusScope.js.map +1 -0
- package/dist/components/Modal/index.d.ts +4 -1
- package/dist/components/Modal/index.js +48 -43
- package/dist/components/Modal/index.js.map +1 -1
- package/dist/components/Page/Float.d.ts +14 -0
- package/dist/components/Page/Float2.js +154 -0
- package/dist/components/Page/Float2.js.map +1 -0
- package/dist/components/Page/index.d.ts +18 -5
- package/dist/components/Page/index.js +103 -34
- package/dist/components/Page/index.js.map +1 -1
- package/dist/components/Page/resize.d.ts +28 -0
- package/dist/components/Page/resize2.js +95 -0
- package/dist/components/Page/resize2.js.map +1 -0
- package/dist/components/PageHeader/index.d.ts +10 -3
- package/dist/components/PageHeader/index.js +46 -25
- package/dist/components/PageHeader/index.js.map +1 -1
- package/dist/components/PagePanel/index.d.ts +29 -0
- package/dist/components/PagePanel/index.js +99 -0
- package/dist/components/PagePanel/index.js.map +1 -0
- package/dist/components/Resizable/ResizeGrip.d.ts +5 -0
- package/dist/components/Resizable/ResizeGrip.js +14 -0
- package/dist/components/Resizable/ResizeGrip.js.map +1 -0
- package/dist/components/Resizable/index.js +57 -59
- package/dist/components/Resizable/index.js.map +1 -1
- package/dist/components/Resizable/useResize.d.ts +6 -0
- package/dist/components/Resizable/useResize.js +29 -28
- package/dist/components/Resizable/useResize.js.map +1 -1
- package/dist/components/SidebarToggleButton/index.d.ts +5 -3
- package/dist/components/SidebarToggleButton/index.js +24 -21
- package/dist/components/SidebarToggleButton/index.js.map +1 -1
- package/dist/components/Table/index.d.ts +10 -12
- package/dist/components/Table/index.js +25 -20
- package/dist/components/Table/index.js.map +1 -1
- package/dist/components/Text/index.d.ts +1 -1
- package/dist/components/Text/index.js +11 -10
- package/dist/components/Text/index.js.map +1 -1
- package/dist/components/Textarea/index.d.ts +14 -0
- package/dist/components/Textarea/index.js +44 -0
- package/dist/components/Textarea/index.js.map +1 -0
- package/dist/components/Tree/Tree.d.ts +2 -0
- package/dist/components/Tree/Tree.js +49 -40
- package/dist/components/Tree/Tree.js.map +1 -1
- package/dist/dishui.css +1 -1
- package/dist/index-nostyled.d.ts +9 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +119 -113
- package/dist/layouts/Sidebar.d.ts +12 -1
- package/dist/layouts/Sidebar.js +121 -97
- package/dist/layouts/Sidebar.js.map +1 -1
- package/dist/lite.d.ts +10 -2
- package/dist/lite.js +17 -12
- package/dist/utils/menu.js +14 -16
- package/dist/utils/menu.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PagePanel from '../PagePanel';
|
|
3
|
+
export type PageResizeProps = {
|
|
4
|
+
/** 启用侧栏宽度调整,默认 false。 */
|
|
5
|
+
resizable?: boolean;
|
|
6
|
+
/** 调宽手柄外观,默认 pill;line 仅显示分隔线。 */
|
|
7
|
+
resizeVariant?: 'pill' | 'line';
|
|
8
|
+
/** 可调整的最小像素宽度,默认 160。 */
|
|
9
|
+
minWidth?: number;
|
|
10
|
+
/** 可调整的最大像素宽度,默认 600。 */
|
|
11
|
+
maxWidth?: number;
|
|
12
|
+
/** 用户调整宽度时触发,参数为像素宽度。 */
|
|
13
|
+
onWidthChange?: (width: number) => void;
|
|
14
|
+
};
|
|
15
|
+
export declare function resizeLimits(min?: number, max?: number): readonly [number, number];
|
|
16
|
+
export declare const clampWidth: (width: number, min: number, max: number) => number;
|
|
17
|
+
type Props = Omit<PageResizeProps, 'resizable'> & {
|
|
18
|
+
panel: React.ReactElement<React.ComponentProps<typeof PagePanel>>;
|
|
19
|
+
};
|
|
20
|
+
/** Keep the legacy aside markup/scroll owner; the separator belongs to the shell. */
|
|
21
|
+
export default function ResizableAside({ panel, minWidth, maxWidth, onWidthChange, resizeVariant }: Props): React.ReactElement<import(".").PagePanelProps & import("../PagePanel").PageAutoHideProps & {
|
|
22
|
+
edge: 'header' | 'footer' | 'left' | 'right';
|
|
23
|
+
width?: number | string;
|
|
24
|
+
hideOnMobile?: boolean;
|
|
25
|
+
children: React.ReactNode;
|
|
26
|
+
resizeHandle?: React.ReactNode;
|
|
27
|
+
}, string | React.JSXElementConstructor<any>>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { useResize as e } from "../Resizable/useResize.js";
|
|
2
|
+
import { ResizeGrip as t } from "../Resizable/ResizeGrip.js";
|
|
3
|
+
/* empty css */
|
|
4
|
+
import n, { useEffect as r, useId as i, useLayoutEffect as a, useRef as o, useState as s } from "react";
|
|
5
|
+
import { jsx as c } from "react/jsx-runtime";
|
|
6
|
+
//#region src/components/Page/resize.tsx
|
|
7
|
+
function l(e = 160, t = 600) {
|
|
8
|
+
let n = Number.isFinite(e) ? Math.max(0, e) : 160;
|
|
9
|
+
return [n, Number.isFinite(t) ? Math.max(n, t) : Math.max(n, 600)];
|
|
10
|
+
}
|
|
11
|
+
var u = (e, t, n) => Math.min(n, Math.max(t, e));
|
|
12
|
+
function d({ panel: d, minWidth: f, maxWidth: p, onWidthChange: m, resizeVariant: h = "pill" }) {
|
|
13
|
+
let { width: g = 260, open: _ = !0, edge: v } = d.props, [y, b] = l(f, p), [x, S] = s({ source: g });
|
|
14
|
+
x.source !== g && S({ source: g });
|
|
15
|
+
let C = o(void 0), [w, T] = s(typeof g == "number" ? u(g, y, b) : y), E = o(null), D = i(), O = d.props.children, k = O.props.id ?? D, A = x.source === g && x.value !== void 0 ? u(x.value, y, b) : typeof g == "number" ? u(g, y, b) : g, j = v === "right" ? -1 : 1, M = e({
|
|
16
|
+
value: typeof A == "number" ? A : w,
|
|
17
|
+
getValue: () => E.current?.getBoundingClientRect().width ?? w,
|
|
18
|
+
min: y,
|
|
19
|
+
max: b,
|
|
20
|
+
disabled: !_,
|
|
21
|
+
getScale: () => j,
|
|
22
|
+
keyboardDirection: j,
|
|
23
|
+
step: 8,
|
|
24
|
+
shiftMultiplier: 4,
|
|
25
|
+
threshold: 0,
|
|
26
|
+
onChange: (e) => P(e)
|
|
27
|
+
}), N = M.cancel;
|
|
28
|
+
a(() => {
|
|
29
|
+
g !== C.current && N();
|
|
30
|
+
}, [g, N]), r(() => {
|
|
31
|
+
let e = window.matchMedia("(min-width: 768px)"), t = () => N();
|
|
32
|
+
return e.addEventListener("change", t), () => {
|
|
33
|
+
e.removeEventListener("change", t), N();
|
|
34
|
+
};
|
|
35
|
+
}, [N]), r(() => {
|
|
36
|
+
_ || N();
|
|
37
|
+
}, [_, N]), a(() => {
|
|
38
|
+
let e = E.current;
|
|
39
|
+
if (!e) return;
|
|
40
|
+
let t = () => {
|
|
41
|
+
window.matchMedia("(min-width: 768px)").matches && _ && T(u(e.getBoundingClientRect().width, y, b));
|
|
42
|
+
};
|
|
43
|
+
t();
|
|
44
|
+
let n = new ResizeObserver(t);
|
|
45
|
+
return n.observe(e), () => n.disconnect();
|
|
46
|
+
}, [
|
|
47
|
+
y,
|
|
48
|
+
b,
|
|
49
|
+
_
|
|
50
|
+
]);
|
|
51
|
+
let P = (e) => {
|
|
52
|
+
let t = u(e, y, b);
|
|
53
|
+
t !== (E.current?.getBoundingClientRect().width ?? w) && (C.current = t, S({
|
|
54
|
+
source: g,
|
|
55
|
+
value: t
|
|
56
|
+
}), T(t), m?.(t));
|
|
57
|
+
}, F = () => _ && window.matchMedia("(min-width: 768px)").matches, I = /* @__PURE__ */ c("div", {
|
|
58
|
+
className: "dishui-resize-handle dishui-page-resize-handle",
|
|
59
|
+
"data-orientation": "horizontal",
|
|
60
|
+
"data-variant": h,
|
|
61
|
+
"data-dragging": M.dragging || void 0,
|
|
62
|
+
role: "separator",
|
|
63
|
+
tabIndex: _ ? 0 : -1,
|
|
64
|
+
"aria-label": v === "right" ? "Resize right panel" : "Resize left panel",
|
|
65
|
+
"aria-orientation": "vertical",
|
|
66
|
+
"aria-controls": k,
|
|
67
|
+
"aria-valuemin": y,
|
|
68
|
+
"aria-valuemax": b,
|
|
69
|
+
"aria-valuenow": typeof A == "number" ? A : w,
|
|
70
|
+
onPointerDown: (e) => {
|
|
71
|
+
F() && (e.preventDefault(), M.onPointerDown(e));
|
|
72
|
+
},
|
|
73
|
+
onClickCapture: M.onClickCapture,
|
|
74
|
+
onKeyDown: (e) => {
|
|
75
|
+
F() && M.onKeyDown(e);
|
|
76
|
+
},
|
|
77
|
+
children: /* @__PURE__ */ c(t, { variant: h })
|
|
78
|
+
});
|
|
79
|
+
return n.cloneElement(d, {
|
|
80
|
+
width: typeof A == "string" ? `clamp(${y}px, ${A}, ${b}px)` : A,
|
|
81
|
+
resizeHandle: I
|
|
82
|
+
}, n.cloneElement(O, {
|
|
83
|
+
ref: E,
|
|
84
|
+
id: k,
|
|
85
|
+
style: {
|
|
86
|
+
...O.props.style,
|
|
87
|
+
width: void 0,
|
|
88
|
+
"--dishui-aside-w": typeof A == "number" ? `${A}px` : A
|
|
89
|
+
}
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { u as clampWidth, d as default, l as resizeLimits };
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=resize2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resize2.js","names":[],"sources":["../../../src/components/Page/resize.tsx"],"sourcesContent":["import React, { useEffect, useId, useLayoutEffect, useRef, useState } from 'react';\nimport PagePanel from '../PagePanel';\nimport { useResize } from '../Resizable/useResize';\nimport { ResizeGrip } from '../Resizable/ResizeGrip';\nimport './resize.css';\n\nexport type PageResizeProps = {\n /** 启用侧栏宽度调整,默认 false。 */\n resizable?: boolean;\n /** 调宽手柄外观,默认 pill;line 仅显示分隔线。 */\n resizeVariant?: 'pill' | 'line';\n /** 可调整的最小像素宽度,默认 160。 */\n minWidth?: number;\n /** 可调整的最大像素宽度,默认 600。 */\n maxWidth?: number;\n /** 用户调整宽度时触发,参数为像素宽度。 */\n onWidthChange?: (width: number) => void;\n};\n\nexport function resizeLimits(min = 160, max = 600) {\n const lower = Number.isFinite(min) ? Math.max(0, min) : 160;\n return [lower, Number.isFinite(max) ? Math.max(lower, max) : Math.max(lower, 600)] as const;\n}\n\nexport const clampWidth = (width: number, min: number, max: number) => Math.min(max, Math.max(min, width));\n\ntype Props = Omit<PageResizeProps, 'resizable'> & {\n panel: React.ReactElement<React.ComponentProps<typeof PagePanel>>;\n};\n\n/** Keep the legacy aside markup/scroll owner; the separator belongs to the shell. */\nexport default function ResizableAside({ panel, minWidth, maxWidth, onWidthChange, resizeVariant = 'pill' }: Props) {\n const { width = 260, open = true, edge } = panel.props;\n const [min, max] = resizeLimits(minWidth, maxWidth);\n const [local, setLocal] = useState<{ source: number | string; value?: number }>({ source: width });\n // Reset on prop changes, not on every parent render or callback notification.\n if (local.source !== width) setLocal({ source: width });\n const lastRequestedWidth = useRef<number | undefined>(undefined);\n const [measured, setMeasured] = useState(typeof width === 'number' ? clampWidth(width, min, max) : min);\n const asideRef = useRef<HTMLElement>(null);\n\n const generatedId = useId();\n const aside = panel.props.children as React.ReactElement<React.HTMLAttributes<HTMLElement>>;\n const id = aside.props.id ?? generatedId;\n const effective = local.source === width && local.value !== undefined ? clampWidth(local.value, min, max)\n : typeof width === 'number' ? clampWidth(width, min, max) : width;\n const direction = edge === 'right' ? -1 : 1;\n\n const resize = useResize({\n value: typeof effective === 'number' ? effective : measured,\n getValue: () => asideRef.current?.getBoundingClientRect().width ?? measured,\n min, max, disabled: !open,\n getScale: () => direction,\n keyboardDirection: direction,\n step: 8, shiftMultiplier: 4, threshold: 0,\n onChange: value => change(value),\n });\n const stop = resize.cancel;\n\n // Parent feedback acknowledges the drag; unrelated external changes cancel it.\n useLayoutEffect(() => {\n if (width !== lastRequestedWidth.current) stop();\n }, [width, stop]);\n useEffect(() => {\n const media = window.matchMedia('(min-width: 768px)');\n const cancel = () => stop();\n media.addEventListener('change', cancel);\n return () => { media.removeEventListener('change', cancel); stop(); };\n }, [stop]);\n useEffect(() => { if (!open) stop(); }, [open, stop]);\n useLayoutEffect(() => {\n const element = asideRef.current;\n if (!element) return;\n const measure = () => {\n if (window.matchMedia('(min-width: 768px)').matches && open) {\n setMeasured(clampWidth(element.getBoundingClientRect().width, min, max));\n }\n };\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(element);\n return () => observer.disconnect();\n }, [min, max, open]);\n\n const change = (value: number) => {\n const next = clampWidth(value, min, max);\n const current = asideRef.current?.getBoundingClientRect().width ?? measured;\n if (next === current) return;\n lastRequestedWidth.current = next;\n setLocal({ source: width, value: next });\n setMeasured(next);\n onWidthChange?.(next);\n };\n const enabled = () => open && window.matchMedia('(min-width: 768px)').matches;\n const handle = <div\n className=\"dishui-resize-handle dishui-page-resize-handle\"\n data-orientation=\"horizontal\"\n data-variant={resizeVariant}\n data-dragging={resize.dragging || undefined}\n role=\"separator\"\n tabIndex={open ? 0 : -1}\n aria-label={edge === 'right' ? 'Resize right panel' : 'Resize left panel'}\n aria-orientation=\"vertical\"\n aria-controls={id}\n aria-valuemin={min}\n aria-valuemax={max}\n aria-valuenow={typeof effective === 'number' ? effective : measured}\n onPointerDown={event => {\n if (!enabled()) return;\n event.preventDefault();\n resize.onPointerDown(event);\n }}\n onClickCapture={resize.onClickCapture}\n onKeyDown={event => {\n if (!enabled()) return;\n resize.onKeyDown(event);\n }}\n ><ResizeGrip variant={resizeVariant} /></div>;\n return React.cloneElement(panel, {\n width: typeof effective === 'string' ? `clamp(${min}px, ${effective}, ${max}px)` : effective,\n resizeHandle: handle,\n },\n React.cloneElement(aside as React.ReactElement<React.HTMLAttributes<HTMLElement> & React.RefAttributes<HTMLElement>>, {\n ref: asideRef,\n id,\n style: { ...aside.props.style, width: undefined, '--dishui-aside-w': typeof effective === 'number' ? `${effective}px` : effective } as React.CSSProperties,\n }));\n}\n"],"mappings":";;;;;;AAmBA,SAAgB,EAAa,IAAM,KAAK,IAAM,KAAK;CAC/C,IAAM,IAAQ,OAAO,SAAS,CAAG,IAAI,KAAK,IAAI,GAAG,CAAG,IAAI;CACxD,OAAO,CAAC,GAAO,OAAO,SAAS,CAAG,IAAI,KAAK,IAAI,GAAO,CAAG,IAAI,KAAK,IAAI,GAAO,GAAG,CAAC;AACrF;AAEA,IAAa,KAAc,GAAe,GAAa,MAAgB,KAAK,IAAI,GAAK,KAAK,IAAI,GAAK,CAAK,CAAC;AAOzG,SAAwB,EAAe,EAAE,UAAO,aAAU,aAAU,kBAAe,mBAAgB,UAAiB;CAChH,IAAM,EAAE,WAAQ,KAAK,UAAO,IAAM,YAAS,EAAM,OAC3C,CAAC,GAAK,KAAO,EAAa,GAAU,CAAQ,GAC5C,CAAC,GAAO,KAAY,EAAsD,EAAE,QAAQ,EAAM,CAAC;CAEjG,AAAI,EAAM,WAAW,KAAO,EAAS,EAAE,QAAQ,EAAM,CAAC;CACtD,IAAM,IAAqB,EAA2B,KAAA,CAAS,GACzD,CAAC,GAAU,KAA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from '../PagePanel';
|
|
3
|
+
export type PageHeaderProps = PagePanelProps & PageAutoHideProps & {
|
|
3
4
|
/** 页面标题 */
|
|
4
|
-
title
|
|
5
|
+
title?: React.ReactNode;
|
|
6
|
+
/** 覆盖默认图标、标题和描述;null 清空,undefined 使用旧 API。 */
|
|
7
|
+
left?: React.ReactNode;
|
|
8
|
+
/** 相对整个 header 水平居中的内容。 */
|
|
9
|
+
center?: React.ReactNode;
|
|
10
|
+
/** 覆盖 actions;null 清空,undefined 使用 actions。 */
|
|
11
|
+
right?: React.ReactNode;
|
|
5
12
|
/** 标题下方的描述文字 */
|
|
6
13
|
description?: React.ReactNode;
|
|
7
14
|
/** 标题左侧的图标(通常为 lucide 图标) */
|
|
@@ -16,5 +23,5 @@ export type PageHeaderProps = {
|
|
|
16
23
|
* 页面头部:统一管理后台等页面的标题 / 描述 / 操作区排版。
|
|
17
24
|
* 相比页面内手写的 `text-3xl` 标题,默认字号更精致(text-lg)。
|
|
18
25
|
*/
|
|
19
|
-
declare const PageHeader: ({ title, description, icon, actions, compact, className, }: PageHeaderProps) => React.JSX.Element;
|
|
26
|
+
declare const PageHeader: ({ open, mode, animated, duration, autoHide, title, description, icon, actions, left, center, right, compact, className, }: PageHeaderProps) => React.JSX.Element;
|
|
20
27
|
export default PageHeader;
|
|
@@ -1,32 +1,53 @@
|
|
|
1
|
-
import "
|
|
2
|
-
|
|
1
|
+
import e from "../PagePanel/index.js";
|
|
2
|
+
/* empty css */
|
|
3
|
+
import t from "react";
|
|
4
|
+
import { Fragment as n, jsx as r, jsxs as i } from "react/jsx-runtime";
|
|
3
5
|
//#region src/components/PageHeader/index.tsx
|
|
4
|
-
var
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
className: `shrink-0 text-base-content/70 ${l}`,
|
|
14
|
-
children: i
|
|
15
|
-
}), /* @__PURE__ */ e("h1", {
|
|
16
|
-
className: `truncate font-semibold text-base-content ${c}`,
|
|
17
|
-
children: n
|
|
18
|
-
})]
|
|
19
|
-
}), r && /* @__PURE__ */ e("p", {
|
|
20
|
-
className: "mt-1 text-body-sm leading-5 text-base-content/70",
|
|
21
|
-
children: r
|
|
22
|
-
})]
|
|
23
|
-
}), a && /* @__PURE__ */ e("div", {
|
|
24
|
-
className: "flex flex-wrap items-center gap-2",
|
|
25
|
-
children: a
|
|
6
|
+
var a = (e) => t.Children.toArray(e).some((e) => t.isValidElement(e) && e.type === t.Fragment ? a(e.props.children) : typeof e != "string" || e.trim().length > 0), o = ({ open: t, mode: o, animated: s, duration: c, autoHide: l, title: u, description: d, icon: f, actions: p, left: m, center: h, right: g, compact: _ = !0, className: v = "" }) => {
|
|
7
|
+
let y = _ ? "text-lg" : "text-xl", b = _ ? "[&>svg]:h-5 [&>svg]:w-5" : "[&>svg]:h-6 [&>svg]:w-6", x = _ ? "mb-4" : "mb-6", S = /* @__PURE__ */ i(n, { children: [(a(f) || a(u)) && /* @__PURE__ */ i("div", {
|
|
8
|
+
className: "flex min-w-0 items-center gap-2.5",
|
|
9
|
+
children: [a(f) && /* @__PURE__ */ r("span", {
|
|
10
|
+
className: `shrink-0 text-base-content/70 ${b}`,
|
|
11
|
+
children: f
|
|
12
|
+
}), a(u) && /* @__PURE__ */ r("h1", {
|
|
13
|
+
className: `min-w-0 truncate font-semibold text-base-content ${y}`,
|
|
14
|
+
children: u
|
|
26
15
|
})]
|
|
16
|
+
}), a(d) && /* @__PURE__ */ r("p", {
|
|
17
|
+
className: "mt-1 text-body-sm leading-5 text-base-content/70",
|
|
18
|
+
children: d
|
|
19
|
+
})] }), C = m === void 0 ? S : m, w = g === void 0 ? p : g;
|
|
20
|
+
return /* @__PURE__ */ r(e, {
|
|
21
|
+
edge: "header",
|
|
22
|
+
autoHide: l,
|
|
23
|
+
open: t,
|
|
24
|
+
mode: o,
|
|
25
|
+
animated: s,
|
|
26
|
+
duration: c,
|
|
27
|
+
children: /* @__PURE__ */ r("header", {
|
|
28
|
+
className: `dishui-page-header text-body ${x} ${v}`.trim(),
|
|
29
|
+
children: /* @__PURE__ */ i("div", {
|
|
30
|
+
className: "dishui-page-header-layout",
|
|
31
|
+
"data-centered": a(h) || void 0,
|
|
32
|
+
children: [
|
|
33
|
+
a(C) && /* @__PURE__ */ r("div", {
|
|
34
|
+
className: "dishui-page-header-left",
|
|
35
|
+
children: C
|
|
36
|
+
}),
|
|
37
|
+
a(h) && /* @__PURE__ */ r("div", {
|
|
38
|
+
className: "dishui-page-header-center",
|
|
39
|
+
children: h
|
|
40
|
+
}),
|
|
41
|
+
a(w) && /* @__PURE__ */ r("div", {
|
|
42
|
+
className: "dishui-page-header-right",
|
|
43
|
+
children: w
|
|
44
|
+
})
|
|
45
|
+
]
|
|
46
|
+
})
|
|
47
|
+
})
|
|
27
48
|
});
|
|
28
49
|
};
|
|
29
50
|
//#endregion
|
|
30
|
-
export {
|
|
51
|
+
export { o as default };
|
|
31
52
|
|
|
32
53
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/PageHeader/index.tsx"],"sourcesContent":["import React from 'react';\n\nexport type PageHeaderProps = {\n /** 页面标题 */\n title
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/PageHeader/index.tsx"],"sourcesContent":["import React from 'react';\nimport PagePanel, { type PagePanelProps, type PageAutoHideProps } from '../PagePanel';\nimport './style.css';\n\nexport type PageHeaderProps = PagePanelProps & PageAutoHideProps & {\n /** 页面标题 */\n title?: React.ReactNode;\n /** 覆盖默认图标、标题和描述;null 清空,undefined 使用旧 API。 */\n left?: React.ReactNode;\n /** 相对整个 header 水平居中的内容。 */\n center?: React.ReactNode;\n /** 覆盖 actions;null 清空,undefined 使用 actions。 */\n right?: React.ReactNode;\n /** 标题下方的描述文字 */\n description?: React.ReactNode;\n /** 标题左侧的图标(通常为 lucide 图标) */\n icon?: React.ReactNode;\n /** 右侧操作区(按钮组等) */\n actions?: React.ReactNode;\n /** 紧凑模式:标题与间距更小 */\n compact?: boolean;\n className?: string;\n};\n\nconst hasContent = (node: React.ReactNode): boolean =>\n React.Children.toArray(node).some(child =>\n React.isValidElement<{ children?: React.ReactNode }>(child) && child.type === React.Fragment\n ? hasContent(child.props.children)\n : typeof child !== 'string' || child.trim().length > 0,\n );\n\n/**\n * 页面头部:统一管理后台等页面的标题 / 描述 / 操作区排版。\n * 相比页面内手写的 `text-3xl` 标题,默认字号更精致(text-lg)。\n */\nconst PageHeader = ({\n open, mode, animated, duration, autoHide,\n title,\n description,\n icon,\n actions,\n left,\n center,\n right,\n compact = true,\n className = '',\n}: PageHeaderProps) => {\n const titleSize = compact ? 'text-lg' : 'text-xl';\n const iconSize = compact ? '[&>svg]:h-5 [&>svg]:w-5' : '[&>svg]:h-6 [&>svg]:w-6';\n const spacing = compact ? 'mb-4' : 'mb-6';\n\n\n const defaultLeft = (\n <>\n {(hasContent(icon) || hasContent(title)) && (\n <div className=\"flex min-w-0 items-center gap-2.5\">\n {hasContent(icon) && (\n <span className={`shrink-0 text-base-content/70 ${iconSize}`}>{icon}</span>\n )}\n {hasContent(title) && (\n <h1 className={`min-w-0 truncate font-semibold text-base-content ${titleSize}`}>{title}</h1>\n )}\n </div>\n )}\n {hasContent(description) && (\n <p className=\"mt-1 text-body-sm leading-5 text-base-content/70\">{description}</p>\n )}\n </>\n );\n const leftContent = left !== undefined ? left : defaultLeft;\n const rightContent = right !== undefined ? right : actions;\n\n return (\n <PagePanel edge=\"header\" autoHide={autoHide} open={open} mode={mode} animated={animated} duration={duration}>\n <header className={`dishui-page-header text-body ${spacing} ${className}`.trim()}>\n <div className=\"dishui-page-header-layout\" data-centered={hasContent(center) || undefined}>\n {hasContent(leftContent) && <div className=\"dishui-page-header-left\">{leftContent}</div>}\n {hasContent(center) && <div className=\"dishui-page-header-center\">{center}</div>}\n {hasContent(rightContent) && <div className=\"dishui-page-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2B,UAAA;KAAiB,CAAA;KACtF,EAAW,CAAM,KAAK,kBAAC,OAAD;MAAK,WAAU;MAA6B,UAAA;KAAY,CAAA;KAC9E,EAAW,CAAY,KAAK,kBAAC,OAAD;MAAK,WAAU;MAA4B,UAAA;KAAkB,CAAA;IACzF;;EACD,CAAA;CACD,CAAA;AAEnB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type PagePanelProps = {
|
|
3
|
+
/** 是否展开,默认 true。折叠时保留内容挂载,但禁用交互。 */
|
|
4
|
+
open?: boolean;
|
|
5
|
+
/** push 占用布局空间;overlay 覆盖 Page / Body,默认 push。 */
|
|
6
|
+
mode?: 'push' | 'overlay';
|
|
7
|
+
/** 是否启用动画,默认 true;遵循 prefers-reduced-motion。 */
|
|
8
|
+
animated?: boolean;
|
|
9
|
+
/** 动画时长(毫秒),默认 200。 */
|
|
10
|
+
duration?: number;
|
|
11
|
+
};
|
|
12
|
+
export type PageAutoHideProps = {
|
|
13
|
+
/** 正文下滚隐藏、上滚或到顶显示。默认 false;阈值默认 24px。显式 open 优先。 */
|
|
14
|
+
autoHide?: boolean | {
|
|
15
|
+
threshold?: number;
|
|
16
|
+
/** 达到下滚阈值后等待的毫秒数,默认 0;与动画 duration 独立。 */
|
|
17
|
+
delay?: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type PanelProps = PagePanelProps & PageAutoHideProps & {
|
|
21
|
+
edge: 'header' | 'footer' | 'left' | 'right';
|
|
22
|
+
width?: number | string;
|
|
23
|
+
hideOnMobile?: boolean;
|
|
24
|
+
children: React.ReactNode;
|
|
25
|
+
/** Internal resize control, outside the clipping/scrolling content. */
|
|
26
|
+
resizeHandle?: React.ReactNode;
|
|
27
|
+
};
|
|
28
|
+
declare const PagePanel: (props: PanelProps) => React.JSX.Element;
|
|
29
|
+
export default PagePanel;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
import { useEffect as e, useRef as t, useState as n } from "react";
|
|
3
|
+
import { jsx as r, jsxs as i } from "react/jsx-runtime";
|
|
4
|
+
//#region src/components/PagePanel/index.tsx
|
|
5
|
+
var a = ({ open: e = !0, mode: t = "push", animated: n = !0, duration: a = 200, edge: o, width: s, hideOnMobile: c = !1, children: l, resizeHandle: u }, d) => /* @__PURE__ */ i("div", {
|
|
6
|
+
ref: d,
|
|
7
|
+
className: "dishui-page-panel",
|
|
8
|
+
"data-edge": o,
|
|
9
|
+
"data-resizable": u ? !0 : void 0,
|
|
10
|
+
"data-mode": t,
|
|
11
|
+
"data-open": e,
|
|
12
|
+
"data-hide-mobile": c || void 0,
|
|
13
|
+
inert: !e,
|
|
14
|
+
"aria-hidden": !e || void 0,
|
|
15
|
+
style: {
|
|
16
|
+
"--dishui-panel-duration": `${n && Number.isFinite(a) ? Math.max(0, a) : 0}ms`,
|
|
17
|
+
"--dishui-panel-width": typeof s == "number" ? `${s}px` : s
|
|
18
|
+
},
|
|
19
|
+
children: [/* @__PURE__ */ r("div", {
|
|
20
|
+
className: "dishui-page-panel-clip",
|
|
21
|
+
children: l
|
|
22
|
+
}), u]
|
|
23
|
+
}), o = (r) => {
|
|
24
|
+
let i = t(null), [o, s] = n(!0), c = !!r.autoHide && r.open === void 0, l = typeof r.autoHide == "object" ? r.autoHide.threshold : void 0, u = typeof l == "number" && Number.isFinite(l) && l > 0 ? l : 24, d = typeof r.autoHide == "object" ? r.autoHide.delay : void 0, f = typeof d == "number" && Number.isFinite(d) && d >= 0 ? Math.min(d, 2147483647) : 0;
|
|
25
|
+
return e(() => {
|
|
26
|
+
if (!c) {
|
|
27
|
+
s(!0);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
let e = i.current, t = e?.closest(".dishui-page");
|
|
31
|
+
if (!e || !t) return;
|
|
32
|
+
let n = e.ownerDocument, r = n.defaultView;
|
|
33
|
+
if (!r) return;
|
|
34
|
+
let a = Array.from(t.querySelectorAll(".dishui-page-main")).find((e) => e.closest(".dishui-page") === t);
|
|
35
|
+
if (!a) return;
|
|
36
|
+
let o = () => /auto|scroll|overlay/.test(r.getComputedStyle(a).overflowY), l = () => {
|
|
37
|
+
let e = o(), t = e ? a : n.scrollingElement;
|
|
38
|
+
return {
|
|
39
|
+
local: e,
|
|
40
|
+
top: Math.max(0, t.scrollTop),
|
|
41
|
+
max: Math.max(0, t.scrollHeight - t.clientHeight),
|
|
42
|
+
origin: e ? 0 : a.getBoundingClientRect().top + r.scrollY
|
|
43
|
+
};
|
|
44
|
+
}, d = l(), p = 0, m = 0, h, g = () => {
|
|
45
|
+
h !== void 0 && r.clearTimeout(h), h = void 0;
|
|
46
|
+
}, _ = () => {
|
|
47
|
+
let e = t.getBoundingClientRect();
|
|
48
|
+
return e.bottom > 0 && e.top < r.innerHeight && e.right > 0 && e.left < r.innerWidth;
|
|
49
|
+
}, v = () => {
|
|
50
|
+
if (h !== void 0) return;
|
|
51
|
+
let t = () => {
|
|
52
|
+
h = void 0, !e.contains(n.activeElement) && _() && l().top > 0 && s(!1);
|
|
53
|
+
};
|
|
54
|
+
f === 0 ? t() : h = r.setTimeout(t, f);
|
|
55
|
+
}, y = () => {
|
|
56
|
+
m = 0;
|
|
57
|
+
let i = l(), a = t.getBoundingClientRect(), o = Math.abs(i.max - d.max) + Math.abs(i.origin - d.origin), c = i.local !== d.local, f = i.top - d.top;
|
|
58
|
+
d = i;
|
|
59
|
+
let h = o > .5 && Math.abs(f) <= o + 1;
|
|
60
|
+
if (c || h || a.bottom <= 0 || a.top >= r.innerHeight || a.right <= 0 || a.left >= r.innerWidth) {
|
|
61
|
+
p = 0, (c || !_()) && g();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (f) {
|
|
65
|
+
if (f < 0 && g(), i.top <= 0) {
|
|
66
|
+
g(), p = 0, s(!0);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (e.contains(n.activeElement)) {
|
|
70
|
+
g(), p = 0;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
p = Math.sign(f) === Math.sign(p) ? p + f : f, Math.abs(p) >= u && (p < 0 ? s(!0) : v(), p = 0);
|
|
74
|
+
}
|
|
75
|
+
}, b = () => {
|
|
76
|
+
m ||= r.requestAnimationFrame(y);
|
|
77
|
+
}, x = (e) => {
|
|
78
|
+
(o() ? e.target === a : e.target === n || e.target === r) && b();
|
|
79
|
+
}, S = () => {
|
|
80
|
+
g(), p = 0, s(!0);
|
|
81
|
+
};
|
|
82
|
+
a.addEventListener("scroll", x, { passive: !0 }), r.addEventListener("scroll", x, { passive: !0 }), e.addEventListener("focusin", S);
|
|
83
|
+
let C = new ResizeObserver(b);
|
|
84
|
+
return C.observe(a), C.observe(t), C.observe(n.documentElement), () => {
|
|
85
|
+
a.removeEventListener("scroll", x), r.removeEventListener("scroll", x), e.removeEventListener("focusin", S), C.disconnect(), g(), r.cancelAnimationFrame(m);
|
|
86
|
+
};
|
|
87
|
+
}, [
|
|
88
|
+
c,
|
|
89
|
+
u,
|
|
90
|
+
f
|
|
91
|
+
]), a({
|
|
92
|
+
...r,
|
|
93
|
+
open: r.open ?? (!c || o)
|
|
94
|
+
}, i);
|
|
95
|
+
}, s = (e) => e.edge === "header" || e.edge === "footer" ? /* @__PURE__ */ r(o, { ...e }) : a(e);
|
|
96
|
+
//#endregion
|
|
97
|
+
export { s as default };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/PagePanel/index.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport './style.css';\n\nexport type PagePanelProps = {\n /** 是否展开,默认 true。折叠时保留内容挂载,但禁用交互。 */\n open?: boolean;\n /** push 占用布局空间;overlay 覆盖 Page / Body,默认 push。 */\n mode?: 'push' | 'overlay';\n /** 是否启用动画,默认 true;遵循 prefers-reduced-motion。 */\n animated?: boolean;\n /** 动画时长(毫秒),默认 200。 */\n duration?: number;\n};\n\nexport type PageAutoHideProps = {\n /** 正文下滚隐藏、上滚或到顶显示。默认 false;阈值默认 24px。显式 open 优先。 */\n autoHide?: boolean | {\n threshold?: number;\n /** 达到下滚阈值后等待的毫秒数,默认 0;与动画 duration 独立。 */\n delay?: number;\n };\n};\n\ntype PanelProps = PagePanelProps & PageAutoHideProps & {\n edge: 'header' | 'footer' | 'left' | 'right';\n width?: number | string;\n hideOnMobile?: boolean;\n children: React.ReactNode;\n /** Internal resize control, outside the clipping/scrolling content. */\n resizeHandle?: React.ReactNode;\n};\n\n/** Layout-only shell: consumer classes and HTML attributes stay on the semantic content. */\nconst renderPanel = ({\n open = true,\n mode = 'push',\n animated = true,\n duration = 200,\n edge,\n width,\n hideOnMobile = false,\n children,\n resizeHandle,\n}: PanelProps, ref?: React.Ref<HTMLDivElement>) => (\n <div\n ref={ref}\n className=\"dishui-page-panel\"\n data-edge={edge}\n data-resizable={resizeHandle ? true : undefined}\n data-mode={mode}\n data-open={open}\n data-hide-mobile={hideOnMobile || undefined}\n inert={!open}\n aria-hidden={!open || undefined}\n style={{\n '--dishui-panel-duration': `${animated && Number.isFinite(duration) ? Math.max(0, duration) : 0}ms`,\n '--dishui-panel-width': typeof width === 'number' ? `${width}px` : width,\n } as React.CSSProperties}\n >\n <div className=\"dishui-page-panel-clip\">{children}</div>\n {resizeHandle}\n </div>\n);\n\nconst AutoHidePanel = (props: PanelProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const [open, setOpen] = useState(true);\n const enabled = Boolean(props.autoHide) && props.open === undefined;\n const value = typeof props.autoHide === 'object' ? props.autoHide.threshold : undefined;\n const threshold = typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 24;\n\n const requestedDelay = typeof props.autoHide === 'object' ? props.autoHide.delay : undefined;\n const delay = typeof requestedDelay === 'number' && Number.isFinite(requestedDelay) && requestedDelay >= 0\n ? Math.min(requestedDelay, 2147483647) : 0;\n\n useEffect(() => {\n if (!enabled) {\n setOpen(true);\n return;\n }\n const panel = ref.current;\n const page = panel?.closest<HTMLElement>('.dishui-page');\n if (!panel || !page) return;\n const doc = panel.ownerDocument;\n const win = doc.defaultView;\n if (!win) return;\n const main = Array.from(page.querySelectorAll<HTMLElement>('.dishui-page-main'))\n .find(node => node.closest('.dishui-page') === page);\n if (!main) return;\n const internal = () => /auto|scroll|overlay/.test(win.getComputedStyle(main).overflowY);\n const measure = () => {\n const local = internal();\n const scroller = local ? main : doc.scrollingElement!;\n return {\n local,\n top: Math.max(0, scroller.scrollTop),\n max: Math.max(0, scroller.scrollHeight - scroller.clientHeight),\n origin: local ? 0 : main.getBoundingClientRect().top + win.scrollY,\n };\n };\n let previous = measure();\n let travel = 0;\n let frame = 0;\n let hideTimer: number | undefined;\n const cancelHide = () => {\n if (hideTimer !== undefined) win.clearTimeout(hideTimer);\n hideTimer = undefined;\n };\n const visible = () => {\n const rect = page.getBoundingClientRect();\n return rect.bottom > 0 && rect.top < win.innerHeight && rect.right > 0 && rect.left < win.innerWidth;\n };\n const hide = () => {\n if (hideTimer !== undefined) return;\n const commit = () => {\n hideTimer = undefined;\n if (!panel.contains(doc.activeElement) && visible() && measure().top > 0) setOpen(false);\n };\n if (delay === 0) commit();\n else hideTimer = win.setTimeout(commit, delay);\n };\n const sample = () => {\n frame = 0;\n const next = measure();\n const rect = page.getBoundingClientRect();\n // Grid collapse, scroll anchoring and bottom clamping are layout, not intent.\n const layoutMovement = Math.abs(next.max - previous.max) + Math.abs(next.origin - previous.origin);\n const sourceChanged = next.local !== previous.local;\n const delta = next.top - previous.top;\n previous = next;\n // A larger movement cannot be explained by anchoring/clamping alone;\n // keep responding to deliberate scrolling during an animation.\n const layoutOnly = layoutMovement > 0.5 && Math.abs(delta) <= layoutMovement + 1;\n if (sourceChanged || layoutOnly || rect.bottom <= 0 || rect.top >= win.innerHeight\n || rect.right <= 0 || rect.left >= win.innerWidth) {\n travel = 0;\n if (sourceChanged || !visible()) cancelHide();\n return;\n }\n if (!delta) return;\n if (delta < 0) cancelHide();\n if (next.top <= 0) {\n cancelHide();\n travel = 0;\n setOpen(true);\n return;\n }\n if (panel.contains(doc.activeElement)) {\n cancelHide();\n travel = 0;\n return;\n }\n travel = Math.sign(delta) === Math.sign(travel) ? travel + delta : delta;\n if (Math.abs(travel) >= threshold) {\n if (travel < 0) setOpen(true);\n else hide();\n travel = 0;\n }\n };\n const schedule = () => { if (!frame) frame = win.requestAnimationFrame(sample); };\n const onScroll = (event: Event) => {\n if (internal() ? event.target === main : event.target === doc || event.target === win) schedule();\n };\n const onFocus = () => { cancelHide(); travel = 0; setOpen(true); };\n main.addEventListener('scroll', onScroll, { passive: true });\n win.addEventListener('scroll', onScroll, { passive: true });\n panel.addEventListener('focusin', onFocus);\n const observer = new ResizeObserver(schedule);\n observer.observe(main);\n observer.observe(page);\n observer.observe(doc.documentElement);\n return () => {\n main.removeEventListener('scroll', onScroll);\n win.removeEventListener('scroll', onScroll);\n panel.removeEventListener('focusin', onFocus);\n observer.disconnect();\n cancelHide();\n win.cancelAnimationFrame(frame);\n };\n }, [enabled, threshold, delay]);\n\n return renderPanel({ ...props, open: props.open ?? (enabled ? open : true) }, ref);\n};\n\nconst PagePanel = (props: PanelProps) => props.edge === 'header' || props.edge === 'footer'\n ? <AutoHidePanel {...props} />\n : renderPanel(props);\n\nexport default PagePanel;\n"],"mappings":";;;;AAiCA,IAAM,KAAe,EACjB,UAAO,IACP,UAAO,QACP,cAAW,IACX,cAAW,KACX,SACA,UACA,kBAAe,IACf,aACA,mBACW,MACX,kBAAC,OAAD;CACS;CACL,WAAU;CACV,aAAW;CACX,kBAAgB,IAAe,KAAO,KAAA;CACtC,aAAW;CACX,aAAW;CACX,oBAAkB,KAAgB,KAAA;CAClC,OAAO,CAAC;CACR,eAAa,CAAC,KAAQ,KAAA;CACtB,OAAO;EACH,2BAA2B,GAAG,KAAY,OAAO,SAAS,CAAQ,IAAI,KAAK,IAAI,GAAG,CAAQ,IAAI,EAAE;EA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sx-runtime";
|
|
4
|
+
//#region src/components/Resizable/ResizeGrip.tsx
|
|
5
|
+
function t({ variant: t = "pill" }) {
|
|
6
|
+
return t === "pill" ? /* @__PURE__ */ e("span", {
|
|
7
|
+
className: "dishui-resizable-grip",
|
|
8
|
+
"aria-hidden": "true"
|
|
9
|
+
}) : null;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { t as ResizeGrip };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=ResizeGrip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResizeGrip.js","names":[],"sources":["../../../src/components/Resizable/ResizeGrip.tsx"],"sourcesContent":["import React from 'react';\nimport './ResizeHandle.css';\n\n/** Visual-only primitive; consumers own layout, semantics and interaction. */\nexport function ResizeGrip({ variant = 'pill' }: { variant?: 'pill' | 'line' }) {\n return variant === 'pill' ? <span className=\"dishui-resizable-grip\" aria-hidden=\"true\" /> : null;\n}\n"],"mappings":";;;;AAIA,SAAgB,EAAW,EAAE,aAAU,UAAyC;CAC9E,OAAO,MAAY,SAAS,kBAAC,QAAD;EAAM,WAAU;EAAwB,eAAY;CAAQ,CAAA,IAAI;AAC9F"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { useResize as e } from "./useResize.js";
|
|
2
|
+
import { ResizeGrip as t } from "./ResizeGrip.js";
|
|
2
3
|
/* empty css */
|
|
3
|
-
import { Children as
|
|
4
|
-
import { jsx as
|
|
4
|
+
import { Children as n, createContext as r, isValidElement as i, useContext as a, useId as o, useLayoutEffect as s, useRef as c, useState as l } from "react";
|
|
5
|
+
import { jsx as u } from "react/jsx-runtime";
|
|
5
6
|
//#region src/components/Resizable/index.tsx
|
|
6
|
-
var
|
|
7
|
-
function
|
|
8
|
-
let o =
|
|
7
|
+
var d = r(null), f = r(0);
|
|
8
|
+
function p({ minSize: e, maxSize: t, className: n = "", style: r, ...i }) {
|
|
9
|
+
let o = a(d), s = a(f);
|
|
9
10
|
if (!o) throw Error("Resizable.Panel must be inside Resizable");
|
|
10
|
-
return /* @__PURE__ */
|
|
11
|
-
...
|
|
11
|
+
return /* @__PURE__ */ u("div", {
|
|
12
|
+
...i,
|
|
12
13
|
id: o.ids[s],
|
|
13
14
|
className: `dishui-resizable-panel ${n}`,
|
|
14
15
|
style: {
|
|
@@ -17,59 +18,56 @@ function f({ minSize: e, maxSize: t, className: n = "", style: r, ...a }) {
|
|
|
17
18
|
}
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
|
-
function
|
|
21
|
-
let
|
|
22
|
-
if (!
|
|
23
|
-
let
|
|
24
|
-
orientation:
|
|
25
|
-
value:
|
|
26
|
-
min:
|
|
27
|
-
max:
|
|
28
|
-
disabled:
|
|
29
|
-
step:
|
|
21
|
+
function m({ variant: n = "pill", disabled: r = !1, step: i = 1, className: o = "", onPointerDown: s, onKeyDown: c, onClickCapture: l, children: p, ...m }) {
|
|
22
|
+
let h = a(d), g = a(f);
|
|
23
|
+
if (!h) throw Error("Resizable.Handle must be inside Resizable");
|
|
24
|
+
let _ = h.sizes[g] + h.sizes[g + 1], v = Math.max(h.bounds[g].min, _ - h.bounds[g + 1].max), y = Math.min(h.bounds[g].max, _ - h.bounds[g + 1].min), b = r || h.disabled || v >= y, x = e({
|
|
25
|
+
orientation: h.orientation,
|
|
26
|
+
value: h.sizes[g],
|
|
27
|
+
min: v,
|
|
28
|
+
max: y,
|
|
29
|
+
disabled: b,
|
|
30
|
+
step: i,
|
|
30
31
|
getScale: () => {
|
|
31
|
-
let e =
|
|
32
|
+
let e = h.root.current;
|
|
32
33
|
if (!e) return 0;
|
|
33
|
-
let t =
|
|
34
|
+
let t = h.orientation === "horizontal" ? "width" : "height", n = Array.from(e.children).filter((e) => e.classList.contains("dishui-resizable-panel")).reduce((e, n) => e + n.getBoundingClientRect()[t], 0), r = h.orientation === "horizontal" && getComputedStyle(e).direction === "rtl";
|
|
34
35
|
return n > 0 ? (r ? -100 : 100) / n : 0;
|
|
35
36
|
},
|
|
36
|
-
onChange: (e) =>
|
|
37
|
-
onCommit: (e) =>
|
|
37
|
+
onChange: (e) => h.change(g, e),
|
|
38
|
+
onCommit: (e) => h.change(g, e, !0)
|
|
38
39
|
});
|
|
39
|
-
return /* @__PURE__ */
|
|
40
|
-
...
|
|
40
|
+
return /* @__PURE__ */ u("div", {
|
|
41
|
+
...m,
|
|
41
42
|
role: "separator",
|
|
42
|
-
tabIndex:
|
|
43
|
-
"aria-label":
|
|
44
|
-
"aria-orientation":
|
|
45
|
-
"aria-controls":
|
|
46
|
-
"aria-valuemin":
|
|
47
|
-
"aria-valuemax":
|
|
48
|
-
"aria-valuenow":
|
|
49
|
-
"aria-valuetext": `${Number(
|
|
50
|
-
"aria-disabled":
|
|
51
|
-
"data-orientation":
|
|
52
|
-
"data-variant":
|
|
53
|
-
"data-dragging":
|
|
54
|
-
className: `dishui-resizable-handle ${
|
|
43
|
+
tabIndex: b ? -1 : 0,
|
|
44
|
+
"aria-label": m["aria-label"] ?? "Resize panels",
|
|
45
|
+
"aria-orientation": h.orientation === "horizontal" ? "vertical" : "horizontal",
|
|
46
|
+
"aria-controls": h.ids[g],
|
|
47
|
+
"aria-valuemin": v,
|
|
48
|
+
"aria-valuemax": y,
|
|
49
|
+
"aria-valuenow": h.sizes[g],
|
|
50
|
+
"aria-valuetext": `${Number(h.sizes[g].toFixed(2))}%`,
|
|
51
|
+
"aria-disabled": b,
|
|
52
|
+
"data-orientation": h.orientation,
|
|
53
|
+
"data-variant": n,
|
|
54
|
+
"data-dragging": x.dragging || void 0,
|
|
55
|
+
className: `dishui-resize-handle dishui-resizable-handle ${o}`,
|
|
55
56
|
onPointerDown: (e) => {
|
|
56
|
-
|
|
57
|
+
s?.(e), e.defaultPrevented || x.onPointerDown(e);
|
|
57
58
|
},
|
|
58
59
|
onKeyDown: (e) => {
|
|
59
|
-
|
|
60
|
+
c?.(e), e.defaultPrevented || x.onKeyDown(e);
|
|
60
61
|
},
|
|
61
62
|
onClickCapture: (e) => {
|
|
62
|
-
|
|
63
|
+
x.onClickCapture(e), e.defaultPrevented || l?.(e);
|
|
63
64
|
},
|
|
64
|
-
children:
|
|
65
|
-
className: "dishui-resizable-grip",
|
|
66
|
-
"aria-hidden": "true"
|
|
67
|
-
}) : null)
|
|
65
|
+
children: p ?? /* @__PURE__ */ u(t, { variant: n })
|
|
68
66
|
});
|
|
69
67
|
}
|
|
70
|
-
function
|
|
71
|
-
let x =
|
|
72
|
-
if (!C.length || C.some((e, t) => !
|
|
68
|
+
function h({ orientation: e = "horizontal", sizes: t, defaultSizes: r, onSizesChange: a, onSizesCommit: h, disabled: g = !1, children: _, className: v = "", style: y, ...b }) {
|
|
69
|
+
let x = c(null), S = o(), C = n.toArray(_);
|
|
70
|
+
if (!C.length || C.some((e, t) => !i(e) || e.type !== (t % 2 == 0 ? p : m)) || C.length % 2 == 0) throw Error("Resizable requires alternating Panel / Handle children, starting and ending with Panel. Nest groups inside a Panel.");
|
|
73
71
|
let w = C.filter((e, t) => t % 2 == 0), T = w.map((e) => ({
|
|
74
72
|
min: e.props.minSize ?? 0,
|
|
75
73
|
max: e.props.maxSize ?? 100
|
|
@@ -83,19 +81,19 @@ function m({ orientation: e = "horizontal", sizes: n, defaultSizes: i, onSizesCh
|
|
|
83
81
|
t[e] += r, n -= r;
|
|
84
82
|
}
|
|
85
83
|
return t;
|
|
86
|
-
}, [D, O] =
|
|
87
|
-
|
|
84
|
+
}, [D, O] = l(() => E(r)), k = E(t ?? (D.length === w.length ? D : void 0)), A = c(k);
|
|
85
|
+
s(() => {
|
|
88
86
|
A.current = k;
|
|
89
87
|
});
|
|
90
|
-
let j = (e,
|
|
91
|
-
let i = [...A.current],
|
|
92
|
-
if (i[e] =
|
|
88
|
+
let j = (e, n, r = !1) => {
|
|
89
|
+
let i = [...A.current], o = i[e] + i[e + 1];
|
|
90
|
+
if (i[e] = n, i[e + 1] = o - n, r) {
|
|
93
91
|
h?.(i);
|
|
94
92
|
return;
|
|
95
93
|
}
|
|
96
|
-
|
|
94
|
+
t || (A.current = i, O(i)), a?.(i);
|
|
97
95
|
}, M = w.map((e, t) => e.props.id ?? `${S}-panel-${t}`);
|
|
98
|
-
return /* @__PURE__ */
|
|
96
|
+
return /* @__PURE__ */ u(d.Provider, {
|
|
99
97
|
value: {
|
|
100
98
|
orientation: e,
|
|
101
99
|
disabled: g,
|
|
@@ -105,24 +103,24 @@ function m({ orientation: e = "horizontal", sizes: n, defaultSizes: i, onSizesCh
|
|
|
105
103
|
root: x,
|
|
106
104
|
change: j
|
|
107
105
|
},
|
|
108
|
-
children: /* @__PURE__ */
|
|
106
|
+
children: /* @__PURE__ */ u("div", {
|
|
109
107
|
...b,
|
|
110
108
|
ref: x,
|
|
111
109
|
className: `dishui-resizable ${v}`,
|
|
112
110
|
"data-orientation": e,
|
|
113
111
|
style: y,
|
|
114
|
-
children: C.map((e, t) => /* @__PURE__ */
|
|
112
|
+
children: C.map((e, t) => /* @__PURE__ */ u(f.Provider, {
|
|
115
113
|
value: Math.floor(t / 2),
|
|
116
114
|
children: e
|
|
117
115
|
}, e.key ?? t))
|
|
118
116
|
})
|
|
119
117
|
});
|
|
120
118
|
}
|
|
121
|
-
var
|
|
122
|
-
Panel:
|
|
123
|
-
Handle:
|
|
119
|
+
var g = Object.assign(h, {
|
|
120
|
+
Panel: p,
|
|
121
|
+
Handle: m
|
|
124
122
|
});
|
|
125
123
|
//#endregion
|
|
126
|
-
export {
|
|
124
|
+
export { g as Resizable, g as default, m as ResizableHandle, p as ResizablePanel, e as useResize };
|
|
127
125
|
|
|
128
126
|
//# sourceMappingURL=index.js.map
|