@bioturing/components 0.15.0 → 0.15.1
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/Badge/component.js +21 -0
- package/dist/components/Badge/component.js.map +1 -0
- package/dist/components/Badge/style.css +1 -0
- package/dist/components/Breadcrumb/component.js +46 -0
- package/dist/components/Breadcrumb/component.js.map +1 -0
- package/dist/components/Breadcrumb/style.css +1 -0
- package/dist/components/Breadcrumb/useItemRender.js +27 -0
- package/dist/components/Breadcrumb/useItemRender.js.map +1 -0
- package/dist/components/Button/component.js +9 -0
- package/dist/components/Button/component.js.map +1 -0
- package/dist/components/Button/style.css +1 -0
- package/dist/components/Checkbox/component.js +11 -0
- package/dist/components/Checkbox/component.js.map +1 -0
- package/dist/components/Checkbox/style.css +1 -0
- package/dist/components/CodeBlock/component.js +127 -0
- package/dist/components/CodeBlock/component.js.map +1 -0
- package/dist/components/CodeBlock/style.css +1 -0
- package/dist/components/DSRoot/component.js +21 -0
- package/dist/components/DSRoot/component.js.map +1 -0
- package/dist/components/DSRoot/context.js +9 -0
- package/dist/components/DSRoot/context.js.map +1 -0
- package/dist/components/DSRoot/style.css +1 -0
- package/dist/components/DropdownMenu/component.js +103 -0
- package/dist/components/DropdownMenu/component.js.map +1 -0
- package/dist/components/DropdownMenu/style.css +1 -0
- package/dist/components/Empty/component.js +48 -0
- package/dist/components/Empty/component.js.map +1 -0
- package/dist/components/Empty/style.css +1 -0
- package/dist/components/Field/component.js +30 -0
- package/dist/components/Field/component.js.map +1 -0
- package/dist/components/Field/style.css +1 -0
- package/dist/components/Form/component.js +23 -0
- package/dist/components/Form/component.js.map +1 -0
- package/dist/components/Form/item.js +30 -0
- package/dist/components/Form/item.js.map +1 -0
- package/dist/components/Form/style.css +1 -0
- package/dist/components/IconButton/component.js +49 -0
- package/dist/components/IconButton/component.js.map +1 -0
- package/dist/components/IconButton/style.css +1 -0
- package/dist/components/Input/component.js +25 -0
- package/dist/components/Input/component.js.map +1 -0
- package/dist/components/Modal/Modal.js +161 -0
- package/dist/components/Modal/Modal.js.map +1 -0
- package/dist/components/Modal/ModalProvider.js +70 -0
- package/dist/components/Modal/ModalProvider.js.map +1 -0
- package/dist/components/Modal/ModalService.js +25 -0
- package/dist/components/Modal/ModalService.js.map +1 -0
- package/dist/components/Modal/constants.js +5 -0
- package/dist/components/Modal/constants.js.map +1 -0
- package/dist/components/Modal/functions.js +27 -0
- package/dist/components/Modal/functions.js.map +1 -0
- package/dist/components/Modal/index.js +20 -0
- package/dist/components/Modal/index.js.map +1 -0
- package/dist/components/Modal/style.css +1 -0
- package/dist/components/Popover/component.js +12 -0
- package/dist/components/Popover/component.js.map +1 -0
- package/dist/components/PopupPanel/component.js +190 -0
- package/dist/components/PopupPanel/component.js.map +1 -0
- package/dist/components/PopupPanel/constants.js +5 -0
- package/dist/components/PopupPanel/constants.js.map +1 -0
- package/dist/components/PopupPanel/style.css +1 -0
- package/dist/components/Radio/component.js +22 -0
- package/dist/components/Radio/component.js.map +1 -0
- package/dist/components/Radio/style.css +1 -0
- package/dist/components/ScrollArea/component.js +40 -0
- package/dist/components/ScrollArea/component.js.map +1 -0
- package/dist/components/ScrollArea/style.css +1 -0
- package/dist/components/Segmented/component.js +9 -0
- package/dist/components/Segmented/component.js.map +1 -0
- package/dist/components/Segmented/style.css +1 -0
- package/dist/components/Select/component.js +135 -0
- package/dist/components/Select/component.js.map +1 -0
- package/dist/components/Select/style.css +1 -0
- package/dist/components/Slider/component.js +23 -0
- package/dist/components/Slider/component.js.map +1 -0
- package/dist/components/Spin/component.js +12 -0
- package/dist/components/Spin/component.js.map +1 -0
- package/dist/components/Spin/style.css +1 -0
- package/dist/components/Splitter/component.js +40 -0
- package/dist/components/Splitter/component.js.map +1 -0
- package/dist/components/Splitter/style.css +1 -0
- package/dist/components/Stack/Stack.js +37 -0
- package/dist/components/Stack/Stack.js.map +1 -0
- package/dist/components/Stack/StackChild.js +57 -0
- package/dist/components/Stack/StackChild.js.map +1 -0
- package/dist/components/Stack/index.js +9 -0
- package/dist/components/Stack/index.js.map +1 -0
- package/dist/components/Stack/style.css +1 -0
- package/dist/components/Switch/component.js +9 -0
- package/dist/components/Switch/component.js.map +1 -0
- package/dist/components/Switch/style.css +1 -0
- package/dist/components/Table/component.js +68 -0
- package/dist/components/Table/component.js.map +1 -0
- package/dist/components/Table/style.css +1 -0
- package/dist/components/Tag/component.js +30 -0
- package/dist/components/Tag/component.js.map +1 -0
- package/dist/components/Tag/style.css +1 -0
- package/dist/components/ThemeProvider/component.js +41 -0
- package/dist/components/ThemeProvider/component.js.map +1 -0
- package/dist/components/ThemeProvider/style.css +1 -0
- package/dist/components/Toast/component.js +101 -0
- package/dist/components/Toast/component.js.map +1 -0
- package/dist/components/Toast/function.js +25 -0
- package/dist/components/Toast/function.js.map +1 -0
- package/dist/components/Toast/style.css +1 -0
- package/dist/components/Tooltip/component.js +26 -0
- package/dist/components/Tooltip/component.js.map +1 -0
- package/dist/components/Tooltip/style.css +1 -0
- package/dist/components/Tour/component.js +35 -0
- package/dist/components/Tour/component.js.map +1 -0
- package/dist/components/Tour/style.css +1 -0
- package/dist/components/Transition/component.js +44 -0
- package/dist/components/Transition/component.js.map +1 -0
- package/dist/components/Tree/components.js +67 -0
- package/dist/components/Tree/components.js.map +1 -0
- package/dist/components/Tree/helpers.js +53 -0
- package/dist/components/Tree/helpers.js.map +1 -0
- package/dist/components/Tree/useTreeCommon.js +86 -0
- package/dist/components/Tree/useTreeCommon.js.map +1 -0
- package/dist/components/Tree/useUniqueKeysTree.js +142 -0
- package/dist/components/Tree/useUniqueKeysTree.js.map +1 -0
- package/dist/components/Truncate/component.js +93 -0
- package/dist/components/Truncate/component.js.map +1 -0
- package/dist/components/Truncate/helpers.js +36 -0
- package/dist/components/Truncate/helpers.js.map +1 -0
- package/dist/components/Truncate/style.css +1 -0
- package/dist/components/Upload/component.js +39 -0
- package/dist/components/Upload/component.js.map +1 -0
- package/dist/components/Upload/dragger.js +23 -0
- package/dist/components/Upload/dragger.js.map +1 -0
- package/dist/components/Upload/hooks.js +18 -0
- package/dist/components/Upload/hooks.js.map +1 -0
- package/dist/components/Upload/item.js +84 -0
- package/dist/components/Upload/item.js.map +1 -0
- package/dist/components/Upload/utils.js +7 -0
- package/dist/components/Upload/utils.js.map +1 -0
- package/dist/components/VerticalCollapsiblePanel/component.js +125 -0
- package/dist/components/VerticalCollapsiblePanel/component.js.map +1 -0
- package/dist/components/VerticalCollapsiblePanel/style.css +1 -0
- package/dist/components/hooks/antd.js +22 -0
- package/dist/components/hooks/antd.js.map +1 -0
- package/dist/components/hooks/base-ui.js +47 -0
- package/dist/components/hooks/base-ui.js.map +1 -0
- package/dist/components/hooks/useCharts.js +28 -0
- package/dist/components/hooks/useCharts.js.map +1 -0
- package/dist/components/hooks/useControlledState.js +15 -0
- package/dist/components/hooks/useControlledState.js.map +1 -0
- package/dist/components/utils/WithAntdTokens.js +24 -0
- package/dist/components/utils/WithAntdTokens.js.map +1 -0
- package/dist/components/utils/antdUtils.js +58 -0
- package/dist/components/utils/antdUtils.js.map +1 -0
- package/dist/components/utils/cn.js +27 -0
- package/dist/components/utils/cn.js.map +1 -0
- package/dist/components/utils/isTracebackError.js +10 -0
- package/dist/components/utils/isTracebackError.js.map +1 -0
- package/dist/components/utils/reactToString.js +23 -0
- package/dist/components/utils/reactToString.js.map +1 -0
- package/dist/index.d.ts +2497 -3
- package/dist/index.js +188 -4004
- package/dist/index.js.map +1 -0
- package/dist/metadata.js +513 -0
- package/dist/metadata.js.map +1 -0
- package/dist/tailwind.css +1 -121
- package/dist/tailwind.d.ts +1 -0
- package/dist/tokens/and-theme/tokens.js +351 -0
- package/dist/tokens/and-theme/tokens.js.map +1 -0
- package/dist/tokens/charts/index.js +18 -0
- package/dist/tokens/charts/index.js.map +1 -0
- package/dist/tokens/charts/tokens.js +208 -0
- package/dist/tokens/charts/tokens.js.map +1 -0
- package/dist/tokens/utils.js +37 -0
- package/dist/tokens/utils.js.map +1 -0
- package/package.json +10 -108
- package/dist/Badge.css +0 -6
- package/dist/Badge.js +0 -41
- package/dist/Breadcrumb.css +0 -83
- package/dist/Breadcrumb.js +0 -92
- package/dist/Checkbox.css +0 -13
- package/dist/Checkbox.js +0 -12
- package/dist/CodeBlock.css +0 -213
- package/dist/CodeBlock.js +0 -644
- package/dist/Collapse.css +0 -21
- package/dist/Collapse.js +0 -49
- package/dist/DSRoot.css +0 -667
- package/dist/DSRoot.js +0 -1428
- package/dist/DropdownMenu.css +0 -95
- package/dist/DropdownMenu.js +0 -211
- package/dist/Empty.css +0 -19
- package/dist/Empty.js +0 -53
- package/dist/Field.css +0 -14
- package/dist/Field.js +0 -66
- package/dist/Form.css +0 -64
- package/dist/Form.js +0 -125
- package/dist/IconButton.css +0 -52
- package/dist/IconButton.js +0 -82
- package/dist/Input.js +0 -48
- package/dist/Modal.css +0 -317
- package/dist/Modal.js +0 -677
- package/dist/Popover.js +0 -10
- package/dist/PopupPanel.css +0 -170
- package/dist/PopupPanel.js +0 -333
- package/dist/Radio.css +0 -14
- package/dist/Radio.js +0 -24
- package/dist/ScrollArea.css +0 -64
- package/dist/ScrollArea.js +0 -50
- package/dist/Segmented.css +0 -16
- package/dist/Segmented.js +0 -10
- package/dist/Select.css +0 -24
- package/dist/Select.js +0 -157
- package/dist/Slider.js +0 -39
- package/dist/Spin.css +0 -36
- package/dist/Spin.js +0 -33
- package/dist/Splitter.css +0 -6
- package/dist/Splitter.js +0 -47
- package/dist/Switch.css +0 -7
- package/dist/Switch.js +0 -10
- package/dist/Table.css +0 -116
- package/dist/Table.js +0 -126
- package/dist/Tag.css +0 -17
- package/dist/Tag.js +0 -24
- package/dist/ThemeProvider.css +0 -39
- package/dist/ThemeProvider.js +0 -403
- package/dist/Toast.css +0 -622
- package/dist/Toast.js +0 -1401
- package/dist/Tooltip.css +0 -6
- package/dist/Tooltip.js +0 -36
- package/dist/Tour.css +0 -73
- package/dist/Tour.js +0 -54
- package/dist/Tree.js +0 -318
- package/dist/Truncate.css +0 -31
- package/dist/Truncate.js +0 -216
- package/dist/Upload.css +0 -144
- package/dist/Upload.js +0 -516
- package/dist/VerticalCollapsiblePanel.css +0 -193
- package/dist/VerticalCollapsiblePanel.js +0 -469
- package/dist/components/Badge/component.d.ts +0 -4
- package/dist/components/Badge/index.d.ts +0 -1
- package/dist/components/Breadcrumb/component.d.ts +0 -6
- package/dist/components/Breadcrumb/index.d.ts +0 -2
- package/dist/components/Breadcrumb/types.d.ts +0 -18
- package/dist/components/Breadcrumb/useItemRender.d.ts +0 -6
- package/dist/components/Button/component.d.ts +0 -8
- package/dist/components/Button/index.d.ts +0 -1
- package/dist/components/Checkbox/component.d.ts +0 -11
- package/dist/components/Checkbox/index.d.ts +0 -1
- package/dist/components/CodeBlock/component.d.ts +0 -3
- package/dist/components/CodeBlock/index.d.ts +0 -2
- package/dist/components/CodeBlock/types.d.ts +0 -59
- package/dist/components/Collapse/component.d.ts +0 -14
- package/dist/components/Collapse/index.d.ts +0 -1
- package/dist/components/DSRoot/component.d.ts +0 -14
- package/dist/components/DSRoot/context.d.ts +0 -7
- package/dist/components/DSRoot/index.d.ts +0 -1
- package/dist/components/DropdownMenu/component.d.ts +0 -31
- package/dist/components/DropdownMenu/index.d.ts +0 -2
- package/dist/components/Empty/component.d.ts +0 -13
- package/dist/components/Empty/index.d.ts +0 -1
- package/dist/components/Field/component.d.ts +0 -42
- package/dist/components/Field/index.d.ts +0 -1
- package/dist/components/Form/component.d.ts +0 -19
- package/dist/components/Form/index.d.ts +0 -1
- package/dist/components/Form/item.d.ts +0 -5
- package/dist/components/IconButton/component.d.ts +0 -30
- package/dist/components/IconButton/index.d.ts +0 -1
- package/dist/components/Input/component.d.ts +0 -30
- package/dist/components/Input/index.d.ts +0 -1
- package/dist/components/Modal/Modal.d.ts +0 -84
- package/dist/components/Modal/ModalProvider.d.ts +0 -5
- package/dist/components/Modal/ModalService.d.ts +0 -33
- package/dist/components/Modal/constants.d.ts +0 -9
- package/dist/components/Modal/functions.d.ts +0 -27
- package/dist/components/Modal/index.d.ts +0 -15
- package/dist/components/Popover/component.d.ts +0 -9
- package/dist/components/Popover/index.d.ts +0 -1
- package/dist/components/PopupPanel/component.d.ts +0 -61
- package/dist/components/PopupPanel/constants.d.ts +0 -7
- package/dist/components/PopupPanel/index.d.ts +0 -1
- package/dist/components/Radio/component.d.ts +0 -8
- package/dist/components/Radio/index.d.ts +0 -2
- package/dist/components/Radio/interface.d.ts +0 -5
- package/dist/components/ScrollArea/component.d.ts +0 -32
- package/dist/components/ScrollArea/index.d.ts +0 -1
- package/dist/components/Segmented/component.d.ts +0 -10
- package/dist/components/Segmented/index.d.ts +0 -1
- package/dist/components/Select/component.d.ts +0 -24
- package/dist/components/Select/index.d.ts +0 -1
- package/dist/components/Slider/component.d.ts +0 -5
- package/dist/components/Slider/index.d.ts +0 -1
- package/dist/components/Spin/component.d.ts +0 -4
- package/dist/components/Spin/index.d.ts +0 -1
- package/dist/components/Splitter/component.d.ts +0 -13
- package/dist/components/Splitter/index.d.ts +0 -1
- package/dist/components/Stack/Stack.d.ts +0 -39
- package/dist/components/Stack/StackChild.d.ts +0 -30
- package/dist/components/Stack/index.d.ts +0 -8
- package/dist/components/Switch/component.d.ts +0 -9
- package/dist/components/Switch/index.d.ts +0 -1
- package/dist/components/Table/component.d.ts +0 -20
- package/dist/components/Table/index.d.ts +0 -1
- package/dist/components/Tag/component.d.ts +0 -12
- package/dist/components/Tag/index.d.ts +0 -1
- package/dist/components/ThemeProvider/component.d.ts +0 -7
- package/dist/components/ThemeProvider/index.d.ts +0 -1
- package/dist/components/Toast/component.d.ts +0 -15
- package/dist/components/Toast/function.d.ts +0 -10
- package/dist/components/Toast/index.d.ts +0 -3
- package/dist/components/Toast/types.d.ts +0 -3
- package/dist/components/Tooltip/component.d.ts +0 -10
- package/dist/components/Tooltip/index.d.ts +0 -1
- package/dist/components/Tour/component.d.ts +0 -8
- package/dist/components/Tour/index.d.ts +0 -1
- package/dist/components/Transition/component.d.ts +0 -17
- package/dist/components/Transition/index.d.ts +0 -1
- package/dist/components/Tree/components.d.ts +0 -13
- package/dist/components/Tree/helpers.d.ts +0 -4
- package/dist/components/Tree/index.d.ts +0 -4
- package/dist/components/Tree/types.d.ts +0 -55
- package/dist/components/Tree/useTreeCommon.d.ts +0 -178
- package/dist/components/Tree/useUniqueKeysTree.d.ts +0 -33
- package/dist/components/Truncate/component.d.ts +0 -15
- package/dist/components/Truncate/helpers.d.ts +0 -5
- package/dist/components/Truncate/index.d.ts +0 -1
- package/dist/components/Upload/component.d.ts +0 -16
- package/dist/components/Upload/dragger.d.ts +0 -13
- package/dist/components/Upload/hooks.d.ts +0 -5
- package/dist/components/Upload/index.d.ts +0 -4
- package/dist/components/Upload/item.d.ts +0 -11
- package/dist/components/Upload/utils.d.ts +0 -1
- package/dist/components/VerticalCollapsiblePanel/component.d.ts +0 -65
- package/dist/components/VerticalCollapsiblePanel/index.d.ts +0 -1
- package/dist/components/hooks/antd.d.ts +0 -11
- package/dist/components/hooks/base-ui.d.ts +0 -7
- package/dist/components/hooks/index.d.ts +0 -4
- package/dist/components/hooks/useCharts.d.ts +0 -22
- package/dist/components/hooks/useControlledState.d.ts +0 -1
- package/dist/components/index.d.ts +0 -41
- package/dist/components/utils/WithAntdTokens.d.ts +0 -7
- package/dist/components/utils/antdUtils.d.ts +0 -15
- package/dist/components/utils/client.d.ts +0 -2
- package/dist/components/utils/cn.d.ts +0 -4
- package/dist/components/utils/index.d.ts +0 -3
- package/dist/components/utils/isTracebackError.d.ts +0 -1
- package/dist/components/utils/main.d.ts +0 -3
- package/dist/components/utils/reactToString.d.ts +0 -2
- package/dist/components/utils/types.d.ts +0 -9
- package/dist/hooks.js +0 -961
- package/dist/index.css +0 -1471
- package/dist/metadata.d.ts +0 -363
- package/dist/tokens/and-theme/index.d.ts +0 -1
- package/dist/tokens/and-theme/tokens.d.ts +0 -5
- package/dist/tokens/charts/index.d.ts +0 -6
- package/dist/tokens/charts/tokens.d.ts +0 -455
- package/dist/tokens/index.d.ts +0 -2
- package/dist/tokens/utils.d.ts +0 -16
- package/dist/utils.js +0 -120
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as h } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as y, useEffect as R } from "react";
|
|
3
|
+
import { useRender as b } from "@base-ui-components/react/use-render";
|
|
4
|
+
import { mergeProps as j } from "@base-ui-components/react/merge-props";
|
|
5
|
+
import { useTransitionStatus as v } from "@base-ui-components/react/utils";
|
|
6
|
+
import { useLatestRef as x, useAnimationsFinished as N } from "../hooks/base-ui.js";
|
|
7
|
+
import { clsx as w } from "../utils/cn.js";
|
|
8
|
+
const k = (c) => {
|
|
9
|
+
const {
|
|
10
|
+
children: r = /* @__PURE__ */ h("div", {}),
|
|
11
|
+
className: d,
|
|
12
|
+
starting: n,
|
|
13
|
+
ending: o,
|
|
14
|
+
show: t = !0,
|
|
15
|
+
keepMounted: s = !1,
|
|
16
|
+
...i
|
|
17
|
+
} = c, { mounted: p, setMounted: a, transitionStatus: e } = v(t), m = x(t), g = w(
|
|
18
|
+
d,
|
|
19
|
+
e === "starting" && typeof n == "string" && n,
|
|
20
|
+
e === "ending" && typeof o == "string" && o
|
|
21
|
+
), f = y(null), u = N(f, t), { renderElement: l } = b({
|
|
22
|
+
render: typeof r == "function" ? r(i, {}) : r,
|
|
23
|
+
props: j({
|
|
24
|
+
...i,
|
|
25
|
+
ref: f,
|
|
26
|
+
className: g,
|
|
27
|
+
"data-starting": e === "starting" ? "true" : void 0,
|
|
28
|
+
"data-ending": e === "ending" ? "true" : void 0,
|
|
29
|
+
style: {
|
|
30
|
+
...e === "starting" && typeof n == "object" ? n : {},
|
|
31
|
+
...e === "ending" && typeof o == "object" ? o : {}
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
return R(() => {
|
|
36
|
+
s || u(() => {
|
|
37
|
+
t === m.current && a(t);
|
|
38
|
+
});
|
|
39
|
+
}, [t, s, u, a, m]), p ? l() : null;
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
k as Transition
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../../src/components/Transition/component.tsx"],"sourcesContent":["\"use client\";\nimport { CSSProperties, useEffect, useRef } from \"react\";\nimport { useRender } from \"@base-ui-components/react/use-render\";\nimport { mergeProps } from \"@base-ui-components/react/merge-props\";\nimport { useTransitionStatus } from \"@base-ui-components/react/utils\";\nimport { clsx } from \"../utils\";\nimport { useAnimationsFinished, useLatestRef } from \"../hooks\";\n\nexport interface TransitionProps\n extends Omit<useRender.ComponentProps<\"div\">, \"render\" | \"children\"> {\n /** Whether the component should be shown */\n show?: boolean;\n /** CSS classes to apply when the component is opened */\n starting?: string | CSSProperties;\n /** CSS classes to apply when the component is closed */\n ending?: string | CSSProperties;\n /** CSS classes to apply to the component */\n className?: string;\n /** Child component to render */\n children: useRender.ComponentProps<\"div\">[\"render\"];\n /** Keep mounted */\n keepMounted?: boolean;\n}\n\nexport const Transition = (props: TransitionProps) => {\n const {\n children = <div />,\n className,\n starting,\n ending,\n show = true,\n keepMounted = false,\n ...otherProps\n } = props;\n\n const { mounted, setMounted, transitionStatus } = useTransitionStatus(show);\n const showRef = useLatestRef(show);\n\n const combinedClassName = clsx(\n className,\n transitionStatus === \"starting\" && typeof starting == \"string\" && starting,\n transitionStatus === \"ending\" && typeof ending == \"string\" && ending\n );\n\n const ref = useRef<HTMLDivElement>(null);\n const runOnceAnimationsFinish = useAnimationsFinished(ref, show);\n\n const { renderElement } = useRender({\n render: typeof children == \"function\" ? children(otherProps, {}) : children,\n props: mergeProps<\"div\">({\n ...otherProps,\n ref,\n className: combinedClassName,\n ...{\n \"data-starting\": transitionStatus === \"starting\" ? \"true\" : undefined,\n \"data-ending\": transitionStatus === \"ending\" ? \"true\" : undefined,\n },\n style: {\n ...(transitionStatus === \"starting\" && typeof starting === \"object\"\n ? starting\n : {}),\n ...(transitionStatus === \"ending\" && typeof ending === \"object\"\n ? ending\n : {}),\n },\n } as React.HTMLAttributes<HTMLDivElement>),\n });\n\n useEffect(() => {\n if (keepMounted) return;\n runOnceAnimationsFinish(() => {\n if (show === showRef.current) {\n setMounted(show);\n }\n });\n }, [show, keepMounted, runOnceAnimationsFinish, setMounted, showRef]);\n\n return mounted ? renderElement() : null;\n};\n"],"names":["Transition","props","children","className","starting","ending","show","keepMounted","otherProps","mounted","setMounted","transitionStatus","useTransitionStatus","showRef","useLatestRef","combinedClassName","clsx","ref","useRef","runOnceAnimationsFinish","useAnimationsFinished","renderElement","useRender","mergeProps","useEffect"],"mappings":";;;;;;;AAwBa,MAAAA,IAAa,CAACC,MAA2B;AAC9C,QAAA;AAAA,IACJ,UAAAC,sBAAY,OAAI,EAAA;AAAA,IAChB,WAAAC;AAAA,IACA,UAAAC;AAAA,IACA,QAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,aAAAC,IAAc;AAAA,IACd,GAAGC;AAAA,EAAA,IACDP,GAEE,EAAE,SAAAQ,GAAS,YAAAC,GAAY,kBAAAC,EAAiB,IAAIC,EAAoBN,CAAI,GACpEO,IAAUC,EAAaR,CAAI,GAE3BS,IAAoBC;AAAA,IACxBb;AAAA,IACAQ,MAAqB,cAAc,OAAOP,KAAY,YAAYA;AAAA,IAClEO,MAAqB,YAAY,OAAON,KAAU,YAAYA;AAAA,EAChE,GAEMY,IAAMC,EAAuB,IAAI,GACjCC,IAA0BC,EAAsBH,GAAKX,CAAI,GAEzD,EAAE,eAAAe,EAAc,IAAIC,EAAU;AAAA,IAClC,QAAQ,OAAOpB,KAAY,aAAaA,EAASM,GAAY,CAAE,CAAA,IAAIN;AAAA,IACnE,OAAOqB,EAAkB;AAAA,MACvB,GAAGf;AAAA,MACH,KAAAS;AAAA,MACA,WAAWF;AAAA,MAET,iBAAiBJ,MAAqB,aAAa,SAAS;AAAA,MAC5D,eAAeA,MAAqB,WAAW,SAAS;AAAA,MAE1D,OAAO;AAAA,QACL,GAAIA,MAAqB,cAAc,OAAOP,KAAa,WACvDA,IACA,CAAC;AAAA,QACL,GAAIO,MAAqB,YAAY,OAAON,KAAW,WACnDA,IACA,CAAA;AAAA,MAAC;AAAA,IAEgC,CAAA;AAAA,EAAA,CAC1C;AAED,SAAAmB,EAAU,MAAM;AACd,IAAIjB,KACJY,EAAwB,MAAM;AACxB,MAAAb,MAASO,EAAQ,WACnBH,EAAWJ,CAAI;AAAA,IACjB,CACD;AAAA,EAAA,GACA,CAACA,GAAMC,GAAaY,GAAyBT,GAAYG,CAAO,CAAC,GAE7DJ,IAAUY,MAAkB;AACrC;"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as T } from "react/jsx-runtime";
|
|
2
|
+
import p from "antd/es/tree";
|
|
3
|
+
import { forwardRef as l } from "react";
|
|
4
|
+
import { useTreeCommon as u } from "./useTreeCommon.js";
|
|
5
|
+
import { clsx as k } from "../utils/cn.js";
|
|
6
|
+
const y = (e, r) => {
|
|
7
|
+
const {
|
|
8
|
+
cls: c,
|
|
9
|
+
customSwitcherIcon: n,
|
|
10
|
+
processedTreeData: t,
|
|
11
|
+
currentUniqueExpandedKeys: s,
|
|
12
|
+
currentUniqueCheckedKeys: o,
|
|
13
|
+
handleAntTreeExpand: a,
|
|
14
|
+
handleAntTreeCheck: d,
|
|
15
|
+
restProps: h,
|
|
16
|
+
className: i,
|
|
17
|
+
switcherIcon: m
|
|
18
|
+
} = u(e);
|
|
19
|
+
return /* @__PURE__ */ T(
|
|
20
|
+
p,
|
|
21
|
+
{
|
|
22
|
+
ref: r,
|
|
23
|
+
className: k(c("tree"), i),
|
|
24
|
+
switcherIcon: m || n,
|
|
25
|
+
treeData: t,
|
|
26
|
+
expandedKeys: s,
|
|
27
|
+
onExpand: a,
|
|
28
|
+
checkedKeys: { checked: o, halfChecked: [] },
|
|
29
|
+
onCheck: d,
|
|
30
|
+
...h
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
}, x = (e, r) => {
|
|
34
|
+
const {
|
|
35
|
+
cls: c,
|
|
36
|
+
customSwitcherIcon: n,
|
|
37
|
+
processedTreeData: t,
|
|
38
|
+
currentUniqueExpandedKeys: s,
|
|
39
|
+
currentUniqueCheckedKeys: o,
|
|
40
|
+
handleAntTreeExpand: a,
|
|
41
|
+
handleAntTreeCheck: d,
|
|
42
|
+
restProps: h,
|
|
43
|
+
className: i,
|
|
44
|
+
switcherIcon: m
|
|
45
|
+
} = u(e);
|
|
46
|
+
return /* @__PURE__ */ T(
|
|
47
|
+
p.DirectoryTree,
|
|
48
|
+
{
|
|
49
|
+
ref: r,
|
|
50
|
+
className: k(c("directory-tree"), i),
|
|
51
|
+
switcherIcon: m || n,
|
|
52
|
+
treeData: t,
|
|
53
|
+
expandedKeys: s,
|
|
54
|
+
onExpand: a,
|
|
55
|
+
checkedKeys: { checked: o, halfChecked: [] },
|
|
56
|
+
onCheck: d,
|
|
57
|
+
...h
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
}, f = l(y), C = l(x), N = Object.assign(f, {
|
|
61
|
+
DirectoryTree: C,
|
|
62
|
+
TreeNode: p.TreeNode
|
|
63
|
+
});
|
|
64
|
+
export {
|
|
65
|
+
N as Tree
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../../src/components/Tree/components.tsx"],"sourcesContent":["\"use client\";\nimport {\n default as AntTree,\n type DataNode as AntTreeDataNode,\n} from \"antd/es/tree\";\n\nimport { forwardRef } from \"react\";\nimport { clsx } from \"../utils\";\nimport type { TreeDataNode, TreeProps, DirectoryTreeProps } from \"./types\";\nimport { useTreeCommon } from \"./useTreeCommon\";\n\n// Create inner function for main Tree with forwarded ref\n// Ensure generic constraint matches TreeProps if it uses AntTreeDataNode\nconst MainTreeInner = <T extends AntTreeDataNode = TreeDataNode>(\n props: TreeProps<T>,\n ref: React.Ref<React.ComponentRef<typeof AntTree<T>>>\n) => {\n const {\n cls,\n customSwitcherIcon,\n processedTreeData,\n currentUniqueExpandedKeys,\n currentUniqueCheckedKeys,\n handleAntTreeExpand,\n handleAntTreeCheck,\n restProps,\n className,\n switcherIcon,\n } = useTreeCommon(props);\n\n return (\n <AntTree\n ref={ref}\n className={clsx(cls(\"tree\"), className)}\n switcherIcon={switcherIcon || customSwitcherIcon}\n // Pass processed props to AntTree\n treeData={processedTreeData}\n expandedKeys={currentUniqueExpandedKeys}\n onExpand={handleAntTreeExpand}\n // Pass checked keys in the object format\n checkedKeys={{ checked: currentUniqueCheckedKeys, halfChecked: [] }}\n onCheck={handleAntTreeCheck}\n {...restProps} // Pass other props like checkable, showLine, etc.\n />\n );\n};\n\n// Create inner function for DirectoryTree with forwarded ref\nconst DirectoryTreeInner = <T extends AntTreeDataNode = TreeDataNode>(\n props: DirectoryTreeProps<T>,\n ref: React.Ref<React.ComponentRef<typeof AntTree<T>>>\n) => {\n const {\n cls,\n customSwitcherIcon,\n processedTreeData,\n currentUniqueExpandedKeys,\n currentUniqueCheckedKeys,\n handleAntTreeExpand,\n handleAntTreeCheck,\n restProps,\n className,\n switcherIcon,\n } = useTreeCommon(props as any);\n\n return (\n <AntTree.DirectoryTree\n ref={ref}\n className={clsx(cls(\"directory-tree\"), className)}\n switcherIcon={switcherIcon || customSwitcherIcon}\n // Pass processed props to AntTree.DirectoryTree\n treeData={processedTreeData as T[]}\n expandedKeys={currentUniqueExpandedKeys}\n onExpand={handleAntTreeExpand}\n // Pass checked keys in the object format\n checkedKeys={{ checked: currentUniqueCheckedKeys, halfChecked: [] }}\n onCheck={handleAntTreeCheck}\n {...restProps} // Pass other props like checkable, showLine, etc.\n />\n );\n};\n\n// Use forwardRef with type assertion for main Tree\n// Ensure the generic constraint here matches TreeProps\nconst MainTree = forwardRef(MainTreeInner) as <\n T extends AntTreeDataNode = TreeDataNode // Use AntTreeDataNode if TreeProps uses it\n>(\n props: TreeProps<T> & {\n ref?: React.ForwardedRef<React.ComponentRef<typeof AntTree<T>>>;\n }\n) => ReturnType<typeof MainTreeInner<T>>;\n\n// Use forwardRef with type assertion for DirectoryTree\nconst DirectoryTree = forwardRef(DirectoryTreeInner) as <\n T extends AntTreeDataNode = AntTreeDataNode\n>(\n props: DirectoryTreeProps<T> & {\n ref?: React.ForwardedRef<React.ComponentRef<typeof AntTree<T>>>; // Check ref type consistency\n }\n) => ReturnType<typeof DirectoryTreeInner<T>>;\n\n// Create the final component with DirectoryTree property\nexport const Tree = Object.assign(MainTree, {\n DirectoryTree,\n TreeNode: AntTree.TreeNode,\n});\n"],"names":["MainTreeInner","props","ref","cls","customSwitcherIcon","processedTreeData","currentUniqueExpandedKeys","currentUniqueCheckedKeys","handleAntTreeExpand","handleAntTreeCheck","restProps","className","switcherIcon","useTreeCommon","jsx","AntTree","clsx","DirectoryTreeInner","MainTree","forwardRef","DirectoryTree","Tree"],"mappings":";;;;;AAaA,MAAMA,IAAgB,CACpBC,GACAC,MACG;AACG,QAAA;AAAA,IACJ,KAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,2BAAAC;AAAA,IACA,0BAAAC;AAAA,IACA,qBAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,WAAAC;AAAA,IACA,WAAAC;AAAA,IACA,cAAAC;AAAA,EAAA,IACEC,EAAcZ,CAAK;AAGrB,SAAA,gBAAAa;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,KAAAb;AAAA,MACA,WAAWc,EAAKb,EAAI,MAAM,GAAGQ,CAAS;AAAA,MACtC,cAAcC,KAAgBR;AAAA,MAE9B,UAAUC;AAAA,MACV,cAAcC;AAAA,MACd,UAAUE;AAAA,MAEV,aAAa,EAAE,SAASD,GAA0B,aAAa,CAAA,EAAG;AAAA,MAClE,SAASE;AAAA,MACR,GAAGC;AAAA,IAAA;AAAA,EACN;AAEJ,GAGMO,IAAqB,CACzBhB,GACAC,MACG;AACG,QAAA;AAAA,IACJ,KAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,2BAAAC;AAAA,IACA,0BAAAC;AAAA,IACA,qBAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,WAAAC;AAAA,IACA,WAAAC;AAAA,IACA,cAAAC;AAAA,EAAA,IACEC,EAAcZ,CAAY;AAG5B,SAAA,gBAAAa;AAAA,IAACC,EAAQ;AAAA,IAAR;AAAA,MACC,KAAAb;AAAA,MACA,WAAWc,EAAKb,EAAI,gBAAgB,GAAGQ,CAAS;AAAA,MAChD,cAAcC,KAAgBR;AAAA,MAE9B,UAAUC;AAAA,MACV,cAAcC;AAAA,MACd,UAAUE;AAAA,MAEV,aAAa,EAAE,SAASD,GAA0B,aAAa,CAAA,EAAG;AAAA,MAClE,SAASE;AAAA,MACR,GAAGC;AAAA,IAAA;AAAA,EACN;AAEJ,GAIMQ,IAAWC,EAAWnB,CAAa,GASnCoB,IAAgBD,EAAWF,CAAkB,GAStCI,IAAO,OAAO,OAAOH,GAAU;AAAA,EAC1C,eAAAE;AAAA,EACA,UAAUL,EAAQ;AACpB,CAAC;"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { File as g, FolderOpen as y, Folder as p } from "@bioturing/assets";
|
|
3
|
+
const k = (n, t, s) => {
|
|
4
|
+
if (!n) return [];
|
|
5
|
+
let i = [];
|
|
6
|
+
return n.forEach((e) => {
|
|
7
|
+
const r = s.get(e.key);
|
|
8
|
+
r !== void 0 && t.has(r) && i.push(e.key), e.children && (i = i.concat(
|
|
9
|
+
k(e.children, t, s)
|
|
10
|
+
));
|
|
11
|
+
}), i;
|
|
12
|
+
}, m = (n, t, s = "", i) => {
|
|
13
|
+
if (n)
|
|
14
|
+
return n.map((e) => {
|
|
15
|
+
const r = e.key;
|
|
16
|
+
if (r == null)
|
|
17
|
+
return console.warn(
|
|
18
|
+
"Tree node is missing a key. Skipping unique key generation for this node and its children.",
|
|
19
|
+
e
|
|
20
|
+
), {
|
|
21
|
+
...e
|
|
22
|
+
// Optionally process children even if parent key is missing
|
|
23
|
+
// children: processTreeData(node.children as T[] | undefined, expandedOriginalKeys, '', keyMap)
|
|
24
|
+
};
|
|
25
|
+
const c = "/", o = String(r);
|
|
26
|
+
o.includes(c) && console.warn(
|
|
27
|
+
`Tree node original key "${o}" contains the separator character "${c}". This might lead to unexpected behavior if keys are not truly unique.`,
|
|
28
|
+
e
|
|
29
|
+
);
|
|
30
|
+
const a = s ? `${s}${c}${o}` : o;
|
|
31
|
+
i.set(a, r);
|
|
32
|
+
const u = t.has(r), h = e.icon || (e.isLeaf ? /* @__PURE__ */ l(g, {}) : u ? /* @__PURE__ */ l(y, {}) : /* @__PURE__ */ l(p, {})), f = m(
|
|
33
|
+
e.children,
|
|
34
|
+
// Cast children to T[]
|
|
35
|
+
t,
|
|
36
|
+
a,
|
|
37
|
+
// Pass the generated unique key as the prefix for children
|
|
38
|
+
i
|
|
39
|
+
);
|
|
40
|
+
return {
|
|
41
|
+
...e,
|
|
42
|
+
key: a,
|
|
43
|
+
// Override key with the unique one
|
|
44
|
+
icon: h,
|
|
45
|
+
children: f
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
k as getUniqueKeysFromOriginals,
|
|
51
|
+
m as processTreeData
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../../../src/components/Tree/helpers.tsx"],"sourcesContent":["\"use client\";\nimport React, { type Key } from \"react\";\nimport { type DataNode as AntTreeDataNode } from \"antd/es/tree\";\nimport { File, Folder, FolderOpen } from \"@bioturing/assets\";\n\n// Function to recursively find unique keys corresponding to original keys\nexport const getUniqueKeysFromOriginals = (\n nodes: AntTreeDataNode[] | undefined,\n originalKeysToFind: Set<Key>,\n map: Map<Key, Key>\n): Key[] => {\n if (!nodes) return [];\n let keys: Key[] = [];\n nodes.forEach((node) => {\n const originalKey = map.get(node.key);\n if (originalKey !== undefined && originalKeysToFind.has(originalKey)) {\n keys.push(node.key); // Add the unique key\n }\n if (node.children) {\n keys = keys.concat(\n getUniqueKeysFromOriginals(node.children, originalKeysToFind, map)\n );\n }\n });\n return keys;\n};\n\n// Helper function to generate unique keys and apply icons\nexport const processTreeData = <T extends AntTreeDataNode = AntTreeDataNode>(\n nodes: T[] | undefined,\n expandedOriginalKeys: Set<Key>, // Use Set for faster lookups\n parentKeyPrefix: string = \"\",\n keyMap: Map<Key, Key> // Map uniqueKey -> originalKey\n): T[] | undefined => {\n if (!nodes) return undefined;\n\n return nodes.map((node) => {\n const originalKey = node.key;\n // Ensure nodes have a valid key for unique key generation\n if (originalKey === null || originalKey === undefined) {\n console.warn(\n \"Tree node is missing a key. Skipping unique key generation for this node and its children.\",\n node\n );\n // Return node as is, or handle based on requirements\n return {\n ...node,\n // Optionally process children even if parent key is missing\n // children: processTreeData(node.children as T[] | undefined, expandedOriginalKeys, '', keyMap)\n };\n }\n\n const separator = \"/\"; // Use / as the separator\n const originalKeyString = String(originalKey);\n\n // Warn if the original key contains the separator\n if (originalKeyString.includes(separator)) {\n console.warn(\n `Tree node original key \"${originalKeyString}\" contains the separator character \"${separator}\". This might lead to unexpected behavior if keys are not truly unique.`,\n node\n );\n }\n\n const uniqueKey = parentKeyPrefix\n ? `${parentKeyPrefix}${separator}${originalKeyString}` // Use separator\n : originalKeyString;\n keyMap.set(uniqueKey, originalKey); // Store mapping uniqueKey -> originalKey\n\n const isExpanded = expandedOriginalKeys.has(originalKey);\n // Apply default icons based on expansion state and type (leaf/directory)\n const icon =\n node.icon ||\n (node.isLeaf ? <File /> : isExpanded ? <FolderOpen /> : <Folder />);\n\n // Recursively process children\n const processedChildren = processTreeData(\n node.children as T[] | undefined, // Cast children to T[]\n expandedOriginalKeys,\n uniqueKey, // Pass the generated unique key as the prefix for children\n keyMap\n );\n\n return {\n ...node,\n key: uniqueKey, // Override key with the unique one\n icon: icon,\n children: processedChildren,\n };\n });\n};\n"],"names":["getUniqueKeysFromOriginals","nodes","originalKeysToFind","map","keys","node","originalKey","processTreeData","expandedOriginalKeys","parentKeyPrefix","keyMap","separator","originalKeyString","uniqueKey","isExpanded","icon","jsx","File","FolderOpen","Folder","processedChildren"],"mappings":";;AAMO,MAAMA,IAA6B,CACxCC,GACAC,GACAC,MACU;AACN,MAAA,CAACF,EAAO,QAAO,CAAC;AACpB,MAAIG,IAAc,CAAC;AACb,SAAAH,EAAA,QAAQ,CAACI,MAAS;AACtB,UAAMC,IAAcH,EAAI,IAAIE,EAAK,GAAG;AACpC,IAAIC,MAAgB,UAAaJ,EAAmB,IAAII,CAAW,KAC5DF,EAAA,KAAKC,EAAK,GAAG,GAEhBA,EAAK,aACPD,IAAOA,EAAK;AAAA,MACVJ,EAA2BK,EAAK,UAAUH,GAAoBC,CAAG;AAAA,IACnE;AAAA,EACF,CACD,GACMC;AACT,GAGaG,IAAkB,CAC7BN,GACAO,GACAC,IAA0B,IAC1BC,MACoB;AAChB,MAACT;AAEE,WAAAA,EAAM,IAAI,CAACI,MAAS;AACzB,YAAMC,IAAcD,EAAK;AAErB,UAAAC,KAAgB;AACV,uBAAA;AAAA,UACN;AAAA,UACAD;AAAA,QACF,GAEO;AAAA,UACL,GAAGA;AAAA;AAAA;AAAA,QAGL;AAGF,YAAMM,IAAY,KACZC,IAAoB,OAAON,CAAW;AAGxC,MAAAM,EAAkB,SAASD,CAAS,KAC9B,QAAA;AAAA,QACN,2BAA2BC,CAAiB,uCAAuCD,CAAS;AAAA,QAC5FN;AAAA,MACF;AAGI,YAAAQ,IAAYJ,IACd,GAAGA,CAAe,GAAGE,CAAS,GAAGC,CAAiB,KAClDA;AACG,MAAAF,EAAA,IAAIG,GAAWP,CAAW;AAE3B,YAAAQ,IAAaN,EAAqB,IAAIF,CAAW,GAEjDS,IACJV,EAAK,SACJA,EAAK,SAAS,gBAAAW,EAACC,GAAK,CAAA,CAAA,IAAKH,IAAa,gBAAAE,EAACE,GAAW,CAAA,CAAA,sBAAMC,GAAO,CAAA,CAAA,IAG5DC,IAAoBb;AAAA,QACxBF,EAAK;AAAA;AAAA,QACLG;AAAA,QACAK;AAAA;AAAA,QACAH;AAAA,MACF;AAEO,aAAA;AAAA,QACL,GAAGL;AAAA,QACH,KAAKQ;AAAA;AAAA,QACL,MAAAE;AAAA,QACA,UAAUK;AAAA,MACZ;AAAA,IAAA,CACD;AACH;"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { jsx as v } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as I } from "react";
|
|
3
|
+
import { CaretRight as M } from "@bioturing/assets";
|
|
4
|
+
import { useUniqueKeysTree as S } from "./useUniqueKeysTree.js";
|
|
5
|
+
import { useCls as U } from "../utils/antdUtils.js";
|
|
6
|
+
function z(h) {
|
|
7
|
+
const {
|
|
8
|
+
treeData: o = [],
|
|
9
|
+
expandedKeys: u,
|
|
10
|
+
defaultExpandedKeys: r = [],
|
|
11
|
+
defaultExpandAll: d = !1,
|
|
12
|
+
defaultExpandParent: i = !0,
|
|
13
|
+
onExpand: f,
|
|
14
|
+
checkedKeys: y,
|
|
15
|
+
defaultCheckedKeys: m,
|
|
16
|
+
onCheck: x,
|
|
17
|
+
allowDuplicatedKeys: E,
|
|
18
|
+
className: K,
|
|
19
|
+
switcherIcon: k,
|
|
20
|
+
...w
|
|
21
|
+
} = h, A = I(() => {
|
|
22
|
+
if (d) {
|
|
23
|
+
const n = [], s = (c = []) => {
|
|
24
|
+
c.forEach((t) => {
|
|
25
|
+
n.push(t.key), Array.isArray(t.children) && s(t.children);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
return s(o), n;
|
|
29
|
+
}
|
|
30
|
+
if (i && (r != null && r.length)) {
|
|
31
|
+
const n = /* @__PURE__ */ new Map(), s = (t, a) => {
|
|
32
|
+
t.forEach((e) => {
|
|
33
|
+
a && n.set(e.key, a.key);
|
|
34
|
+
const p = Array.isArray(e.children) ? e.children : [];
|
|
35
|
+
p.length && s(p, e);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
s(o);
|
|
39
|
+
const c = new Set(r);
|
|
40
|
+
return r.forEach((t) => {
|
|
41
|
+
let a = t;
|
|
42
|
+
for (; n.has(a); ) {
|
|
43
|
+
const e = n.get(a);
|
|
44
|
+
c.has(e) || c.add(e), a = e;
|
|
45
|
+
}
|
|
46
|
+
}), Array.from(c);
|
|
47
|
+
}
|
|
48
|
+
return r ?? [];
|
|
49
|
+
}, [
|
|
50
|
+
o,
|
|
51
|
+
d,
|
|
52
|
+
i,
|
|
53
|
+
r
|
|
54
|
+
]), {
|
|
55
|
+
processedTreeData: C,
|
|
56
|
+
currentUniqueExpandedKeys: g,
|
|
57
|
+
currentUniqueCheckedKeys: T,
|
|
58
|
+
handleAntTreeExpand: D,
|
|
59
|
+
handleAntTreeCheck: q
|
|
60
|
+
} = S({
|
|
61
|
+
treeData: o,
|
|
62
|
+
expandedKeys: u,
|
|
63
|
+
defaultExpandedKeys: A,
|
|
64
|
+
onExpand: f,
|
|
65
|
+
checkedKeys: y,
|
|
66
|
+
defaultCheckedKeys: m,
|
|
67
|
+
onCheck: x,
|
|
68
|
+
allowDuplicatedKeys: E
|
|
69
|
+
}), l = U();
|
|
70
|
+
return {
|
|
71
|
+
cls: l,
|
|
72
|
+
customSwitcherIcon: () => /* @__PURE__ */ v(M, { weight: "bold", className: l("caret-switcher-icon") }),
|
|
73
|
+
processedTreeData: C,
|
|
74
|
+
currentUniqueExpandedKeys: g,
|
|
75
|
+
currentUniqueCheckedKeys: T,
|
|
76
|
+
handleAntTreeExpand: D,
|
|
77
|
+
handleAntTreeCheck: q,
|
|
78
|
+
restProps: w,
|
|
79
|
+
className: K,
|
|
80
|
+
switcherIcon: k
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export {
|
|
84
|
+
z as useTreeCommon
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=useTreeCommon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTreeCommon.js","sources":["../../../src/components/Tree/useTreeCommon.tsx"],"sourcesContent":["\"use client\";\nimport { type DataNode as AntTreeDataNode } from \"antd/es/tree\";\n\nimport { useMemo, type Key } from \"react\";\nimport { useCls } from \"../utils\";\nimport { CaretRight } from \"@bioturing/assets\";\nimport type { TreeDataNode, TreeProps, DirectoryTreeProps } from \"./types\";\nimport { useUniqueKeysTree } from \"./useUniqueKeysTree\";\n\nexport function useTreeCommon<T extends AntTreeDataNode>(\n props: TreeProps<T> | DirectoryTreeProps<T>\n) {\n const {\n treeData: originTreeData = [],\n expandedKeys: propExpandedKeys,\n defaultExpandedKeys: propDefaultExpandedKeys = [],\n defaultExpandAll = false,\n defaultExpandParent = true,\n onExpand: propOnExpand,\n checkedKeys,\n defaultCheckedKeys,\n onCheck,\n allowDuplicatedKeys,\n className,\n switcherIcon,\n ...restProps\n } = props;\n\n // compute resolved defaultExpandedKeys\n const resolvedDefaultExpandedKeys = useMemo<Key[]>(() => {\n if (defaultExpandAll) {\n const keys: Key[] = [];\n const traverse = (nodes: TreeDataNode[] = []) => {\n nodes.forEach((node) => {\n keys.push(node.key);\n if (Array.isArray(node.children))\n traverse(node.children as TreeDataNode[]);\n });\n };\n traverse(originTreeData as TreeDataNode[]);\n return keys;\n }\n if (defaultExpandParent && propDefaultExpandedKeys?.length) {\n // build parent map\n const parentMap = new Map<Key, Key>();\n const traverse = (nodes: TreeDataNode[], parent?: TreeDataNode) => {\n nodes.forEach((node) => {\n if (parent) parentMap.set(node.key, parent.key);\n const children = Array.isArray(node.children)\n ? (node.children as TreeDataNode[])\n : [];\n if (children.length) traverse(children, node);\n });\n };\n traverse(originTreeData as TreeDataNode[]);\n // collect all expansions: original keys + their ancestors\n const expanded = new Set<Key>(propDefaultExpandedKeys);\n propDefaultExpandedKeys.forEach((key) => {\n let k = key;\n while (parentMap.has(k)) {\n const p = parentMap.get(k)!;\n if (!expanded.has(p)) expanded.add(p);\n k = p;\n }\n });\n return Array.from(expanded);\n }\n return propDefaultExpandedKeys ?? [];\n }, [\n originTreeData,\n defaultExpandAll,\n defaultExpandParent,\n propDefaultExpandedKeys,\n ]);\n\n // use unique keys hook\n const {\n processedTreeData,\n currentUniqueExpandedKeys,\n currentUniqueCheckedKeys,\n handleAntTreeExpand,\n handleAntTreeCheck,\n } = useUniqueKeysTree({\n treeData: originTreeData,\n expandedKeys: propExpandedKeys,\n defaultExpandedKeys: resolvedDefaultExpandedKeys,\n onExpand: propOnExpand,\n checkedKeys,\n defaultCheckedKeys,\n onCheck,\n allowDuplicatedKeys,\n });\n\n const cls = useCls();\n const customSwitcherIcon: TreeProps<T>[\"switcherIcon\"] = () => (\n <CaretRight weight=\"bold\" className={cls(\"caret-switcher-icon\")} />\n );\n\n return {\n cls,\n customSwitcherIcon,\n processedTreeData,\n currentUniqueExpandedKeys,\n currentUniqueCheckedKeys,\n handleAntTreeExpand,\n handleAntTreeCheck,\n restProps,\n className,\n switcherIcon,\n };\n}\n"],"names":["useTreeCommon","props","originTreeData","propExpandedKeys","propDefaultExpandedKeys","defaultExpandAll","defaultExpandParent","propOnExpand","checkedKeys","defaultCheckedKeys","onCheck","allowDuplicatedKeys","className","switcherIcon","restProps","resolvedDefaultExpandedKeys","useMemo","keys","traverse","nodes","node","parentMap","parent","children","expanded","key","k","p","processedTreeData","currentUniqueExpandedKeys","currentUniqueCheckedKeys","handleAntTreeExpand","handleAntTreeCheck","useUniqueKeysTree","cls","useCls","jsx","CaretRight"],"mappings":";;;;;AASO,SAASA,EACdC,GACA;AACM,QAAA;AAAA,IACJ,UAAUC,IAAiB,CAAC;AAAA,IAC5B,cAAcC;AAAA,IACd,qBAAqBC,IAA0B,CAAC;AAAA,IAChD,kBAAAC,IAAmB;AAAA,IACnB,qBAAAC,IAAsB;AAAA,IACtB,UAAUC;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AAAA,IACAG;AAAA,IACAC;AAAA,IACAF;AAAA,EAAA,CACD,GAGK;AAAA,IACJ,mBAAAwB;AAAA,IACA,2BAAAC;AAAA,IACA,0BAAAC;AAAA,IACA,qBAAAC;AAAA,IACA,oBAAAC;AAAA,MACEC,EAAkB;AAAA,IACpB,UAAU/B;AAAA,IACV,cAAcC;AAAA,IACd,qBAAqBY;AAAA,IACrB,UAAUR;AAAA,IACV,aAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,SAAAC;AAAA,IACA,qBAAAC;AAAA,EAAA,CACD,GAEKuB,IAAMC,EAAO;AAKZ,SAAA;AAAA,IACL,KAAAD;AAAA,IACA,oBANuD,MACtD,gBAAAE,EAAAC,GAAA,EAAW,QAAO,QAAO,WAAWH,EAAI,qBAAqB,GAAG;AAAA,IAMjE,mBAAAN;AAAA,IACA,2BAAAC;AAAA,IACA,0BAAAC;AAAA,IACA,qBAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,WAAAlB;AAAA,IACA,WAAAF;AAAA,IACA,cAAAC;AAAA,EACF;AACF;"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { useMemo as p, useCallback as q } from "react";
|
|
2
|
+
import { processTreeData as V, getUniqueKeysFromOriginals as v } from "./helpers.js";
|
|
3
|
+
import { useControlledState as U } from "../hooks/useControlledState.js";
|
|
4
|
+
const N = ({
|
|
5
|
+
treeData: A,
|
|
6
|
+
expandedKeys: M,
|
|
7
|
+
defaultExpandedKeys: K = [],
|
|
8
|
+
onExpand: u,
|
|
9
|
+
checkedKeys: d,
|
|
10
|
+
defaultCheckedKeys: h = [],
|
|
11
|
+
onCheck: a,
|
|
12
|
+
allowDuplicatedKeys: i
|
|
13
|
+
}) => {
|
|
14
|
+
const [c, m] = U(
|
|
15
|
+
M,
|
|
16
|
+
void 0,
|
|
17
|
+
// Handle onChange manually in handlers
|
|
18
|
+
K
|
|
19
|
+
), x = p(() => {
|
|
20
|
+
if (d)
|
|
21
|
+
return Array.isArray(d) ? d : d.checked;
|
|
22
|
+
}, [d]), [g, y] = U(
|
|
23
|
+
x,
|
|
24
|
+
// Pass the array of original keys
|
|
25
|
+
void 0,
|
|
26
|
+
// Handle onChange manually in handlers
|
|
27
|
+
h
|
|
28
|
+
), { processedTreeData: l, uniqueToOriginalKeyMap: n } = p(() => {
|
|
29
|
+
if (!i)
|
|
30
|
+
return {
|
|
31
|
+
processedTreeData: A,
|
|
32
|
+
uniqueToOriginalKeyMap: /* @__PURE__ */ new Map()
|
|
33
|
+
};
|
|
34
|
+
const e = /* @__PURE__ */ new Map(), t = new Set(c);
|
|
35
|
+
return { processedTreeData: V(
|
|
36
|
+
A,
|
|
37
|
+
t,
|
|
38
|
+
"",
|
|
39
|
+
e
|
|
40
|
+
), uniqueToOriginalKeyMap: e };
|
|
41
|
+
}, [A, c, i]), O = p(() => {
|
|
42
|
+
if (!i)
|
|
43
|
+
return c;
|
|
44
|
+
const e = new Set(c);
|
|
45
|
+
return v(
|
|
46
|
+
l,
|
|
47
|
+
e,
|
|
48
|
+
n
|
|
49
|
+
);
|
|
50
|
+
}, [
|
|
51
|
+
c,
|
|
52
|
+
l,
|
|
53
|
+
n,
|
|
54
|
+
i
|
|
55
|
+
]), b = p(() => {
|
|
56
|
+
if (!i)
|
|
57
|
+
return g;
|
|
58
|
+
const e = new Set(g);
|
|
59
|
+
return v(
|
|
60
|
+
l,
|
|
61
|
+
e,
|
|
62
|
+
n
|
|
63
|
+
);
|
|
64
|
+
}, [
|
|
65
|
+
g,
|
|
66
|
+
l,
|
|
67
|
+
n,
|
|
68
|
+
i
|
|
69
|
+
]), j = q(
|
|
70
|
+
(e, t) => {
|
|
71
|
+
const r = Array.from(e);
|
|
72
|
+
m(r), u && u(r, t);
|
|
73
|
+
},
|
|
74
|
+
[u, m]
|
|
75
|
+
), k = q(
|
|
76
|
+
(e, t) => {
|
|
77
|
+
const r = e.map((s) => n.get(s)).filter((s) => s !== void 0), o = n.get(t.node.key);
|
|
78
|
+
m(r), u && u(r, {
|
|
79
|
+
...t,
|
|
80
|
+
triggeredOriginalKey: o
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
[n, m, u]
|
|
84
|
+
), E = q(
|
|
85
|
+
(e, t) => {
|
|
86
|
+
let r;
|
|
87
|
+
Array.isArray(e) ? r = Array.from(e) : e && typeof e == "object" && "checked" in e ? r = Array.from(e.checked) : r = [], y(r), a && a(r, t);
|
|
88
|
+
},
|
|
89
|
+
[a, y]
|
|
90
|
+
), P = q(
|
|
91
|
+
(e, t) => {
|
|
92
|
+
const r = t.node.key, o = n.get(r);
|
|
93
|
+
if (o === void 0) {
|
|
94
|
+
console.error(
|
|
95
|
+
"Could not find original key for unique key:",
|
|
96
|
+
r
|
|
97
|
+
);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!t.checked) {
|
|
101
|
+
const f = [...g].filter(
|
|
102
|
+
(F) => F !== o
|
|
103
|
+
);
|
|
104
|
+
y(f), a && a(f, {
|
|
105
|
+
...t,
|
|
106
|
+
triggeredOriginalKey: o
|
|
107
|
+
});
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
let s;
|
|
111
|
+
Array.isArray(e) ? s = e : e && typeof e == "object" && "checked" in e ? s = e.checked : s = [];
|
|
112
|
+
const T = /* @__PURE__ */ new Set();
|
|
113
|
+
for (const S of s) {
|
|
114
|
+
const f = n.get(S);
|
|
115
|
+
f !== void 0 && T.add(f);
|
|
116
|
+
}
|
|
117
|
+
T.add(o);
|
|
118
|
+
const C = Array.from(T);
|
|
119
|
+
y(C), a && a(C, {
|
|
120
|
+
...t,
|
|
121
|
+
triggeredOriginalKey: o
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
[
|
|
125
|
+
n,
|
|
126
|
+
y,
|
|
127
|
+
a,
|
|
128
|
+
g
|
|
129
|
+
]
|
|
130
|
+
);
|
|
131
|
+
return {
|
|
132
|
+
processedTreeData: i ? l : A,
|
|
133
|
+
currentUniqueExpandedKeys: O,
|
|
134
|
+
currentUniqueCheckedKeys: b,
|
|
135
|
+
handleAntTreeExpand: i ? k : j,
|
|
136
|
+
handleAntTreeCheck: i ? P : E
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
export {
|
|
140
|
+
N as useUniqueKeysTree
|
|
141
|
+
};
|
|
142
|
+
//# sourceMappingURL=useUniqueKeysTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUniqueKeysTree.js","sources":["../../../src/components/Tree/useUniqueKeysTree.ts"],"sourcesContent":["import { useCallback, useMemo, type Key } from \"react\";\nimport type { DataNode as AntTreeDataNode, EventDataNode } from \"antd/es/tree\";\nimport { useControlledState } from \"../hooks\";\nimport { processTreeData, getUniqueKeysFromOriginals } from \"./helpers\";\nimport type { CheckInfo, ExpandInfo } from \"./types\";\n\ninterface UseUniqueKeysTreeProps<T extends AntTreeDataNode> {\n treeData: T[] | undefined;\n expandedKeys?: Key[];\n defaultExpandedKeys?: Key[];\n onExpand?: (expandedKeys: Key[], info: ExpandInfo<T>) => void;\n checkedKeys?: Key[] | { checked: Key[]; halfChecked: Key[] };\n defaultCheckedKeys?: Key[];\n onCheck?: (\n checkedKeys: Key[],\n info: CheckInfo<T> & { triggeredOriginalKey?: Key }\n ) => void;\n allowDuplicatedKeys?: boolean;\n}\n\nexport const useUniqueKeysTree = <T extends AntTreeDataNode>({\n treeData: originTreeData,\n expandedKeys,\n defaultExpandedKeys = [],\n onExpand,\n checkedKeys,\n defaultCheckedKeys = [],\n onCheck,\n allowDuplicatedKeys,\n}: UseUniqueKeysTreeProps<T>) => {\n // Always define all hooks at the top level, regardless of allowDuplicatedKeys\n // State hook for ORIGINAL expanded keys\n const [currentOriginalExpandedKeys, setCurrentOriginalExpandedKeys] =\n useControlledState<Key[]>(\n expandedKeys,\n undefined, // Handle onChange manually in handlers\n defaultExpandedKeys\n );\n\n // State hook for ORIGINAL checked keys\n const controlledCheckedKeysValue = useMemo(() => {\n if (!checkedKeys) return undefined;\n return Array.isArray(checkedKeys) ? checkedKeys : checkedKeys.checked;\n }, [checkedKeys]);\n\n const [currentOriginalCheckedKeys, setCurrentOriginalCheckedKeys] =\n useControlledState<Key[]>(\n controlledCheckedKeysValue, // Pass the array of original keys\n undefined, // Handle onChange manually in handlers\n defaultCheckedKeys\n );\n\n // Process tree data to handle duplicated keys (only used when allowDuplicatedKeys is true)\n const { processedTreeData, uniqueToOriginalKeyMap } = useMemo(() => {\n if (!allowDuplicatedKeys) {\n // Return a simple passthrough mapping when not handling duplicates\n return {\n processedTreeData: originTreeData,\n uniqueToOriginalKeyMap: new Map<Key, Key>(),\n };\n }\n\n const map = new Map<Key, Key>();\n const expandedOriginalKeySet = new Set(currentOriginalExpandedKeys);\n const data = processTreeData(\n originTreeData,\n expandedOriginalKeySet,\n \"\",\n map\n );\n return { processedTreeData: data, uniqueToOriginalKeyMap: map };\n }, [originTreeData, currentOriginalExpandedKeys, allowDuplicatedKeys]);\n\n // Create unique keys mappings (only used when allowDuplicatedKeys is true)\n const currentUniqueExpandedKeys = useMemo(() => {\n if (!allowDuplicatedKeys) {\n return currentOriginalExpandedKeys;\n }\n\n const originalKeysSet = new Set(currentOriginalExpandedKeys);\n return getUniqueKeysFromOriginals(\n processedTreeData as AntTreeDataNode[] | undefined,\n originalKeysSet,\n uniqueToOriginalKeyMap\n );\n }, [\n currentOriginalExpandedKeys,\n processedTreeData,\n uniqueToOriginalKeyMap,\n allowDuplicatedKeys,\n ]);\n\n const currentUniqueCheckedKeys = useMemo(() => {\n if (!allowDuplicatedKeys) {\n return currentOriginalCheckedKeys;\n }\n\n const originalKeysSet = new Set(currentOriginalCheckedKeys);\n return getUniqueKeysFromOriginals(\n processedTreeData as AntTreeDataNode[] | undefined,\n originalKeysSet,\n uniqueToOriginalKeyMap\n );\n }, [\n currentOriginalCheckedKeys,\n processedTreeData,\n uniqueToOriginalKeyMap,\n allowDuplicatedKeys,\n ]);\n\n // Simple expand handler for when allowDuplicatedKeys is false\n const handleOriginalExpand = useCallback(\n (\n keys: readonly Key[],\n info: {\n node: EventDataNode<T>;\n expanded: boolean;\n nativeEvent: MouseEvent;\n }\n ) => {\n const keysArray = Array.from(keys);\n setCurrentOriginalExpandedKeys(keysArray);\n\n if (onExpand) {\n onExpand(keysArray, info);\n }\n },\n [onExpand, setCurrentOriginalExpandedKeys]\n );\n\n // Advanced expand handler for when allowDuplicatedKeys is true\n const handleUniqueExpand = useCallback(\n (\n uniqueKeys: readonly Key[],\n info: {\n node: EventDataNode<T>;\n expanded: boolean;\n nativeEvent: MouseEvent;\n }\n ) => {\n const originalKeys = uniqueKeys\n .map((uk) => uniqueToOriginalKeyMap.get(uk))\n .filter((ok): ok is Key => ok !== undefined); // Type guard\n const triggeredOriginalKey = uniqueToOriginalKeyMap.get(info.node.key);\n\n setCurrentOriginalExpandedKeys(originalKeys);\n\n if (onExpand) {\n onExpand(originalKeys, {\n ...info,\n triggeredOriginalKey: triggeredOriginalKey,\n });\n }\n },\n [uniqueToOriginalKeyMap, setCurrentOriginalExpandedKeys, onExpand]\n );\n\n // Simple check handler for when allowDuplicatedKeys is false\n const handleOriginalCheck = useCallback(\n (\n checkedInfoOrKeys:\n | readonly Key[]\n | { checked: readonly Key[]; halfChecked: readonly Key[] },\n info: CheckInfo<T>\n ) => {\n let checkedArray: Key[];\n\n if (Array.isArray(checkedInfoOrKeys)) {\n checkedArray = Array.from(checkedInfoOrKeys);\n } else if (\n checkedInfoOrKeys &&\n typeof checkedInfoOrKeys === \"object\" &&\n \"checked\" in checkedInfoOrKeys\n ) {\n checkedArray = Array.from(checkedInfoOrKeys.checked);\n } else {\n checkedArray = [];\n }\n\n setCurrentOriginalCheckedKeys(checkedArray);\n\n if (onCheck) {\n onCheck(checkedArray, info);\n }\n },\n [onCheck, setCurrentOriginalCheckedKeys]\n );\n\n // Advanced check handler for when allowDuplicatedKeys is true\n const handleUniqueCheck = useCallback(\n (\n checkedInfoOrKeys:\n | readonly Key[]\n | { checked: readonly Key[]; halfChecked: readonly Key[] },\n info: CheckInfo<T> // Contains info about the node that triggered the event\n ) => {\n const triggeredUniqueKey = info.node.key;\n const triggeredOriginalKey =\n uniqueToOriginalKeyMap.get(triggeredUniqueKey);\n\n if (triggeredOriginalKey === undefined) {\n console.error(\n \"Could not find original key for unique key:\",\n triggeredUniqueKey\n );\n return;\n }\n\n // Special handling for unchecking - this is the critical part\n if (!info.checked) {\n // When unchecking, we need to completely rebuild the checked keys list\n // excluding the original key that was unchecked\n\n // 1. Get the current original checked keys\n const currentKeys = [...currentOriginalCheckedKeys];\n\n // 2. Filter out the original key that was unchecked\n const newCheckedKeys = currentKeys.filter(\n (key) => key !== triggeredOriginalKey\n );\n\n // 3. Update the state with the filtered keys\n setCurrentOriginalCheckedKeys(newCheckedKeys);\n\n // 4. Call the user's onCheck callback\n if (onCheck) {\n onCheck(newCheckedKeys, {\n ...info,\n triggeredOriginalKey: triggeredOriginalKey,\n });\n }\n\n // Return early to prevent further processing\n return;\n }\n\n // Handle checking (normal flow for checking items)\n // 1. Extract unique checked keys from Ant Design's final state\n let uniqueCheckedKeys: readonly Key[];\n if (Array.isArray(checkedInfoOrKeys)) {\n uniqueCheckedKeys = checkedInfoOrKeys;\n } else if (\n checkedInfoOrKeys &&\n typeof checkedInfoOrKeys === \"object\" &&\n \"checked\" in checkedInfoOrKeys\n ) {\n uniqueCheckedKeys = checkedInfoOrKeys.checked;\n } else {\n uniqueCheckedKeys = [];\n }\n\n // 2. Map these unique keys to their original keys\n const derivedOriginalKeys = new Set<Key>();\n for (const uniqueKey of uniqueCheckedKeys) {\n const originalKey = uniqueToOriginalKeyMap.get(uniqueKey);\n if (originalKey !== undefined) {\n derivedOriginalKeys.add(originalKey);\n }\n }\n\n // 3. Ensure the triggered original key is included when checking\n derivedOriginalKeys.add(triggeredOriginalKey);\n\n const originalKeysArray = Array.from(derivedOriginalKeys);\n\n // 4. Update the controlled state\n setCurrentOriginalCheckedKeys(originalKeysArray);\n\n // 5. Call the user's onCheck callback\n if (onCheck) {\n onCheck(originalKeysArray, {\n ...info,\n triggeredOriginalKey: triggeredOriginalKey,\n });\n }\n },\n [\n uniqueToOriginalKeyMap,\n setCurrentOriginalCheckedKeys,\n onCheck,\n currentOriginalCheckedKeys,\n ]\n );\n\n // Choose appropriate handlers and data based on allowDuplicatedKeys\n const handleAntTreeExpand = allowDuplicatedKeys\n ? handleUniqueExpand\n : handleOriginalExpand;\n const handleAntTreeCheck = allowDuplicatedKeys\n ? handleUniqueCheck\n : handleOriginalCheck;\n const finalProcessedTreeData = allowDuplicatedKeys\n ? processedTreeData\n : originTreeData;\n\n return {\n processedTreeData: finalProcessedTreeData,\n currentUniqueExpandedKeys,\n currentUniqueCheckedKeys,\n handleAntTreeExpand,\n handleAntTreeCheck,\n };\n};\n"],"names":["useUniqueKeysTree","originTreeData","expandedKeys","defaultExpandedKeys","onExpand","checkedKeys","defaultCheckedKeys","onCheck","allowDuplicatedKeys","currentOriginalExpandedKeys","setCurrentOriginalExpandedKeys","useControlledState","controlledCheckedKeysValue","useMemo","currentOriginalCheckedKeys","setCurrentOriginalCheckedKeys","processedTreeData","uniqueToOriginalKeyMap","map","expandedOriginalKeySet","processTreeData","currentUniqueExpandedKeys","originalKeysSet","getUniqueKeysFromOriginals","currentUniqueCheckedKeys","handleOriginalExpand","useCallback","keys","info","keysArray","handleUniqueExpand","uniqueKeys","originalKeys","uk","ok","triggeredOriginalKey","handleOriginalCheck","checkedInfoOrKeys","checkedArray","handleUniqueCheck","triggeredUniqueKey","newCheckedKeys","key","uniqueCheckedKeys","derivedOriginalKeys","uniqueKey","originalKey","originalKeysArray"],"mappings":";;;AAoBO,MAAMA,IAAoB,CAA4B;AAAA,EAC3D,UAAUC;AAAA,EACV,cAAAC;AAAA,EACA,qBAAAC,IAAsB,CAAC;AAAA,EACvB,UAAAC;AAAA,EACA,aAAAC;AAAA,EACA,oBAAAC,IAAqB,CAAC;AAAA,EACtB,SAAAC;AAAA,EACA,qBAAAC;AACF,MA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AQA,MAAQP;AAAA,QACnB;AAGA,QAAApB,EAA8B0B,CAAc,GAGxClC,KACFA,EAAQkC,GAAgB;AAAA,UACtB,GAAGb;AAAA,UACH,sBAAAO;AAAA,QAAA,CACD;AAIH;AAAA,MAAA;AAKE,UAAAQ;AACA,MAAA,MAAM,QAAQN,CAAiB,IACbM,IAAAN,IAEpBA,KACA,OAAOA,KAAsB,YAC7B,aAAaA,IAEbM,IAAoBN,EAAkB,UAEtCM,IAAoB,CAAC;AAIjB,YAAAC,wBAA0B,IAAS;AACzC,iBAAWC,KAAaF,GAAmB;AACnC,cAAAG,IAAc7B,EAAuB,IAAI4B,CAAS;AACxD,QAAIC,MAAgB,UAClBF,EAAoB,IAAIE,CAAW;AAAA,MACrC;AAIF,MAAAF,EAAoB,IAAIT,CAAoB;AAEtC,YAAAY,IAAoB,MAAM,KAAKH,CAAmB;AAGxD,MAAA7B,EAA8BgC,CAAiB,GAG3CxC,KACFA,EAAQwC,GAAmB;AAAA,QACzB,GAAGnB;AAAA,QACH,sBAAAO;AAAA,MAAA,CACD;AAAA,IAEL;AAAA,IACA;AAAA,MACElB;AAAA,MACAF;AAAA,MACAR;AAAA,MACAO;AAAA,IAAA;AAAA,EAEJ;AAaO,SAAA;AAAA,IACL,mBAL6BN,IAC3BQ,IACAf;AAAA,IAIF,2BAAAoB;AAAA,IACA,0BAAAG;AAAA,IACA,qBAd0BhB,IACxBsB,IACAL;AAAA,IAaF,oBAZyBjB,IACvB+B,IACAH;AAAA,EAWJ;AACF;"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { jsx as W } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as N, useState as z, useCallback as P, useLayoutEffect as D } from "react";
|
|
3
|
+
import { getMiddleTruncatedString as G } from "./helpers.js";
|
|
4
|
+
import './style.css';/* empty css */
|
|
5
|
+
import { useCls as J } from "../utils/antdUtils.js";
|
|
6
|
+
import { clsx as K } from "../utils/cn.js";
|
|
7
|
+
const ee = ({
|
|
8
|
+
children: h,
|
|
9
|
+
position: a = "end",
|
|
10
|
+
lines: r = 1,
|
|
11
|
+
className: E,
|
|
12
|
+
style: f,
|
|
13
|
+
...O
|
|
14
|
+
}) => {
|
|
15
|
+
const l = J(), y = N(null), [R, p] = z(!1), [g, d] = z(h), n = h, k = P(() => r !== "auto" ? {
|
|
16
|
+
...f,
|
|
17
|
+
...r > 1 ? { "--ds-line-clamp": r } : {}
|
|
18
|
+
} : {
|
|
19
|
+
...f,
|
|
20
|
+
// Set a temporary high value to ensure it fits the parent
|
|
21
|
+
"--ds-line-clamp": 999
|
|
22
|
+
}, [r, f]);
|
|
23
|
+
return D(() => {
|
|
24
|
+
var v, T, H, x, C, S;
|
|
25
|
+
const e = y.current;
|
|
26
|
+
if (!e) return;
|
|
27
|
+
if (r === "auto") {
|
|
28
|
+
d(n);
|
|
29
|
+
const i = () => {
|
|
30
|
+
const t = e.parentElement;
|
|
31
|
+
if (!t) return;
|
|
32
|
+
const s = window.getComputedStyle(e), q = parseFloat(s.fontSize), B = s.lineHeight === "normal" ? q * 1.2 : parseFloat(s.lineHeight), m = window.getComputedStyle(t), A = parseFloat(m.paddingTop) || 0, L = parseFloat(m.paddingBottom) || 0, M = parseFloat(m.borderTopWidth) || 0, I = parseFloat(m.borderBottomWidth) || 0, F = t.clientHeight - A - L - M - I, $ = Math.max(1, Math.floor(F / B));
|
|
33
|
+
e && e.style.setProperty("--ds-line-clamp", String($));
|
|
34
|
+
const o = document.createElement("span");
|
|
35
|
+
o.style.visibility = "hidden", o.style.position = "absolute", o.style.width = `${e.clientWidth}px`, o.style.fontSize = s.fontSize, o.style.fontFamily = s.fontFamily, o.style.lineHeight = s.lineHeight, o.textContent = n, document.body.appendChild(o);
|
|
36
|
+
const j = o.scrollHeight > F;
|
|
37
|
+
document.body.removeChild(o), p(j);
|
|
38
|
+
};
|
|
39
|
+
(T = (v = window.document.fonts) == null ? void 0 : v.ready) == null || T.then(i);
|
|
40
|
+
const c = new ResizeObserver(() => {
|
|
41
|
+
window.requestAnimationFrame(i);
|
|
42
|
+
});
|
|
43
|
+
return c.observe(e), e.parentElement && c.observe(e.parentElement), () => c.disconnect();
|
|
44
|
+
}
|
|
45
|
+
if (typeof r == "number" && r > 1) {
|
|
46
|
+
d(n);
|
|
47
|
+
const i = () => {
|
|
48
|
+
const t = document.createElement("span");
|
|
49
|
+
t.style.visibility = "hidden", t.style.position = "absolute", t.style.width = `${e.clientWidth}px`, t.textContent = n, document.body.appendChild(t);
|
|
50
|
+
const s = t.scrollHeight > (e.clientHeight || e.offsetHeight);
|
|
51
|
+
document.body.removeChild(t), p(s);
|
|
52
|
+
};
|
|
53
|
+
(x = (H = window.document.fonts) == null ? void 0 : H.ready) == null || x.then(i);
|
|
54
|
+
const c = new ResizeObserver(() => {
|
|
55
|
+
window.requestAnimationFrame(i);
|
|
56
|
+
});
|
|
57
|
+
return c.observe(e), () => c.disconnect();
|
|
58
|
+
}
|
|
59
|
+
let u = { cancelled: !1 };
|
|
60
|
+
const b = () => {
|
|
61
|
+
u && (u.cancelled = !0);
|
|
62
|
+
const i = { cancelled: !1 };
|
|
63
|
+
u = i;
|
|
64
|
+
const c = G(n, "…", e);
|
|
65
|
+
i.cancelled || d(c);
|
|
66
|
+
};
|
|
67
|
+
a == "middle" && ((S = (C = window.document.fonts) == null ? void 0 : C.ready) == null || S.then(b)), a == "end" && d(n);
|
|
68
|
+
const w = new ResizeObserver(() => {
|
|
69
|
+
a == "middle" && window.requestAnimationFrame(b), a == "end" && e.scrollWidth > e.clientWidth && p(!0);
|
|
70
|
+
});
|
|
71
|
+
return w.observe(e), () => {
|
|
72
|
+
u.cancelled = !0, w.disconnect();
|
|
73
|
+
};
|
|
74
|
+
}, [n, a, r]), /* @__PURE__ */ W(
|
|
75
|
+
"span",
|
|
76
|
+
{
|
|
77
|
+
ref: y,
|
|
78
|
+
style: k(),
|
|
79
|
+
className: K(
|
|
80
|
+
l(r === 1 ? "truncate" : "truncate-multiline"),
|
|
81
|
+
l(a === "middle" ? "truncate-middle" : "truncate-end"),
|
|
82
|
+
E
|
|
83
|
+
),
|
|
84
|
+
title: R ? n : void 0,
|
|
85
|
+
...O,
|
|
86
|
+
children: n === g ? n : /* @__PURE__ */ W("span", { children: g })
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
export {
|
|
91
|
+
ee as Truncate
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../../src/components/Truncate/component.tsx"],"sourcesContent":["\"use client\";\nimport React, { useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport { clsx, useCls } from \"../utils\";\nimport { getMiddleTruncatedString } from \"./helpers\";\n\nimport \"./style.css\";\n\nexport type TruncatePosition = \"middle\" | \"end\";\n\nexport type Props = {\n text: string;\n} & React.CSSProperties;\n\nexport interface TruncateProps\n extends Omit<React.ComponentPropsWithoutRef<\"span\">, \"title\"> {\n /** Text content to be truncated */\n children: string;\n /** Where to truncate the text: start, middle, or end */\n position?: TruncatePosition;\n /** Number of lines to display before truncating (default: 1, 'auto' to fit parent height) */\n lines?: number | \"auto\";\n}\n\nexport const Truncate: React.FC<TruncateProps> = ({\n children,\n position = \"end\",\n lines = 1,\n className,\n style,\n ...rest\n}) => {\n const cls = useCls();\n const containerRef = useRef<HTMLElement>(null);\n const [isTruncated, setIsTruncated] = useState(false);\n const [truncatedText, setTruncatedText] = useState(children);\n\n const text = children;\n\n // Get appropriate container styles based on position and lines\n const getContainerStyles = useCallback(() => {\n // For explicit line numbers or single line\n if (lines !== \"auto\") {\n return {\n ...style,\n ...(lines > 1 ? { \"--ds-line-clamp\": lines } : {}),\n } as React.CSSProperties;\n }\n\n // For auto line calculation, we'll let the useLayoutEffect handle it\n return {\n ...style,\n // Set a temporary high value to ensure it fits the parent\n \"--ds-line-clamp\": 999,\n } as React.CSSProperties;\n }, [lines, style]);\n\n useLayoutEffect(() => {\n const container = containerRef.current;\n if (!container) return;\n\n // Handle auto-height calculation\n if (lines === \"auto\") {\n setTruncatedText(text);\n\n const calculateLines = () => {\n // Get the parent element's height\n const parent = container.parentElement;\n if (!parent) return;\n\n // Calculate the font size and line height\n const styles = window.getComputedStyle(container);\n const fontSize = parseFloat(styles.fontSize);\n const lineHeight =\n styles.lineHeight === \"normal\"\n ? fontSize * 1.2 // Approximate for \"normal\"\n : parseFloat(styles.lineHeight);\n\n // Get parent's padding and border to subtract from available height\n const parentStyles = window.getComputedStyle(parent);\n const paddingTop = parseFloat(parentStyles.paddingTop) || 0;\n const paddingBottom = parseFloat(parentStyles.paddingBottom) || 0;\n const borderTopWidth = parseFloat(parentStyles.borderTopWidth) || 0;\n const borderBottomWidth =\n parseFloat(parentStyles.borderBottomWidth) || 0;\n\n // Calculate how many lines can fit in the available space\n const parentHeight = parent.clientHeight;\n const availableHeight =\n parentHeight -\n paddingTop -\n paddingBottom -\n borderTopWidth -\n borderBottomWidth;\n const maxLines = Math.max(1, Math.floor(availableHeight / lineHeight));\n\n // Apply the calculated line-clamp\n if (container) {\n container.style.setProperty(\"--ds-line-clamp\", String(maxLines));\n }\n\n // Check if the text is truncated\n const clone = document.createElement(\"span\");\n clone.style.visibility = \"hidden\";\n clone.style.position = \"absolute\";\n clone.style.width = `${container.clientWidth}px`;\n clone.style.fontSize = styles.fontSize;\n clone.style.fontFamily = styles.fontFamily;\n clone.style.lineHeight = styles.lineHeight;\n clone.textContent = text;\n document.body.appendChild(clone);\n\n const isTruncated = clone.scrollHeight > availableHeight;\n document.body.removeChild(clone);\n\n setIsTruncated(isTruncated);\n };\n\n window.document.fonts?.ready?.then(calculateLines);\n const observer = new ResizeObserver(() => {\n window.requestAnimationFrame(calculateLines);\n });\n\n observer.observe(container);\n if (container.parentElement) {\n observer.observe(container.parentElement);\n }\n\n return () => observer.disconnect();\n }\n\n // Skip custom truncation logic for multi-line mode\n if (typeof lines === \"number\" && lines > 1) {\n setTruncatedText(text);\n // Check if text is truncated by comparing heights\n const checkIfTruncated = () => {\n const clone = document.createElement(\"span\");\n clone.style.visibility = \"hidden\";\n clone.style.position = \"absolute\";\n clone.style.width = `${container.clientWidth}px`;\n clone.textContent = text;\n document.body.appendChild(clone);\n const isTruncated =\n clone.scrollHeight >\n (container.clientHeight || container.offsetHeight);\n document.body.removeChild(clone);\n setIsTruncated(isTruncated);\n };\n\n window.document.fonts?.ready?.then(checkIfTruncated);\n const observer = new ResizeObserver(() => {\n window.requestAnimationFrame(checkIfTruncated);\n });\n\n observer.observe(container);\n return () => observer.disconnect();\n }\n\n // Original single-line truncation logic\n let cancellationToken = { cancelled: false };\n\n const calculateTruncatedString = () => {\n if (cancellationToken) cancellationToken.cancelled = true;\n\n const requestCancellationToken = { cancelled: false };\n cancellationToken = requestCancellationToken;\n\n const truncated = getMiddleTruncatedString(text, \"\\u2026\", container);\n\n if (requestCancellationToken.cancelled) return;\n\n setTruncatedText(truncated);\n };\n\n if (position == \"middle\") {\n window.document.fonts?.ready?.then(calculateTruncatedString);\n }\n\n if (position == \"end\") {\n setTruncatedText(text);\n }\n\n const observer = new ResizeObserver(() => {\n if (position == \"middle\")\n window.requestAnimationFrame(calculateTruncatedString);\n if (position == \"end\") {\n const isOverflowing = container.scrollWidth > container.clientWidth;\n if (isOverflowing) {\n setIsTruncated(true);\n }\n }\n });\n\n observer.observe(container);\n\n return () => {\n cancellationToken.cancelled = true;\n observer.disconnect();\n };\n }, [text, position, lines]);\n\n return (\n <span\n ref={containerRef}\n style={getContainerStyles()}\n className={clsx(\n lines === 1 ? cls(\"truncate\") : cls(\"truncate-multiline\"),\n position === \"middle\" ? cls(\"truncate-middle\") : cls(\"truncate-end\"),\n className\n )}\n title={isTruncated ? text : undefined}\n {...rest}\n >\n {text === truncatedText ? text : <span>{truncatedText}</span>}\n </span>\n );\n};\n"],"names":["Truncate","children","position","lines","className","style","rest","cls","useCls","containerRef","useRef","isTruncated","setIsTruncated","useState","truncatedText","setTruncatedText","text","getContainerStyles","useCallback","useLayoutEffect","container","calculateLines","parent","styles","fontSize","lineHeight","parentStyles","paddingTop","paddingBottom","borderTopWidth","borderBottomWidth","availableHeight","maxLines","clone","_b","_a","observer","checkIfTruncated","_d","_c","cancellationToken","calculateTruncatedString","requestCancellationToken","truncated","getMiddleTruncatedString","_f","_e","jsx","clsx"],"mappings":";;;;;;AAuBO,MAAMA,KAAoC,CAAC;AAAA,EAChD,UAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,OAAAC,IAAQ;AAAA,EACR,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,GAAGC;AACL,MAAM;AACJ,QAAMC,IAAMC,EAAO,GACbC,IAAeC,EAAoB,IAAI,GACvC,CAACC,GAAaC,CAAc,IAAIC,EAAS,EAAK,GAC9C,CAACC,GAAeC,CAAgB,IAAIF,EAASZ,CAAQ,GAErDe,IAAOf,GAGPgB,IAAqBC,EAAY,MAEjCf,MAAU,SACL;AAAA,IACL,GAAGE;AAAA,IACH,GAAIF,IAAQ,IAAI,EAAE,mBAAmBA,EAAA,IAAU,CAAA;AAAA,EACjD,IAIK;AAAA,IACL,GAAGE;AAAA;AAAA,IAEH,mBAAmB;AAAA,EACrB,GACC,CAACF,GAAOE,CAAK,CAAC;AAEjB,SAAAc,EAAgB,MAAM;;AACpB,UAAMC,IAAYX,EAAa;AAC/B,QAAI,CAACW,EAAW;AAGhB,QAAIjB,MAAU,QAAQ;AACpB,MAAAY,EAAiBC,CAAI;AAErB,YAAMK,IAAiB,MAAM;AAE3B,cAAMC,IAASF,EAAU;AACzB,YAAI,CAACE,EAAQ;AAGP,cAAAC,IAAS,OAAO,iBAAiBH,CAAS,GAC1CI,IAAW,WAAWD,EAAO,QAAQ,GACrCE,IACJF,EAAO,eAAe,WAClBC,IAAW,MACX,WAAWD,EAAO,UAAU,GAG5BG,IAAe,OAAO,iBAAiBJ,CAAM,GAC7CK,IAAa,WAAWD,EAAa,UAAU,KAAK,GACpDE,IAAgB,WAAWF,EA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L,OAAOQ,EAAmB;AAAA,MAC1B,WAAW+B;AAAA,QACKzC,EAAdJ,MAAU,IAAQ,aAAkB,oBAAR;AAAA,QACJI,EAAxBL,MAAa,WAAe,oBAAyB,cAAR;AAAA,QAC7CE;AAAA,MACF;AAAA,MACA,OAAOO,IAAcK,IAAO;AAAA,MAC3B,GAAGV;AAAA,MAEH,UAASU,MAAAF,IAAgBE,IAAO,gBAAA+B,EAAC,UAAM,UAAcjC,EAAA,CAAA;AAAA,IAAA;AAAA,EACxD;AAEJ;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const b = (e) => {
|
|
2
|
+
const t = document.createElement("span");
|
|
3
|
+
return t.style.opacity = "0", t.style.position = "absolute", t.style.top = "-1000px", t.style.left = "-1000px", t.style.whiteSpace = "nowrap", t.style.pointerEvents = "none", e.appendChild(t), {
|
|
4
|
+
measure: (o) => (t.innerText = o, t.clientWidth),
|
|
5
|
+
destroy: () => {
|
|
6
|
+
e.removeChild(t);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
}, g = (e, t, o) => {
|
|
10
|
+
var h;
|
|
11
|
+
if (!e) return e;
|
|
12
|
+
const { measure: i, destroy: l } = b(o), d = i(e), s = o.clientWidth, f = Math.floor(s / d * e.length);
|
|
13
|
+
if (d <= s)
|
|
14
|
+
return l(), e;
|
|
15
|
+
let n = f;
|
|
16
|
+
const r = {}, p = 20, m = 10;
|
|
17
|
+
for (; Object.values(r).length <= p && !r[n]; ) {
|
|
18
|
+
if (n <= 1) {
|
|
19
|
+
r[0] = [0, t];
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
const a = e.slice(0, Math.ceil((n - t.length) / 2 - 1)).trimEnd(), y = e.slice(Math.floor((n - t.length) / 2) - n).trimStart(), u = a + t + y, c = i(u);
|
|
23
|
+
if (r[n] = [c, u], c >= s)
|
|
24
|
+
n = n - 2;
|
|
25
|
+
else {
|
|
26
|
+
if (s - c < m) break;
|
|
27
|
+
n = n + 2;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return l(), ((h = Object.values(r).reverse().find(([a]) => a < s)) == null ? void 0 : h[1]) ?? Object.values(r)[0][1];
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
g as getMiddleTruncatedString,
|
|
34
|
+
b as measureText
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../../../src/components/Truncate/helpers.ts"],"sourcesContent":["export const measureText = (container: HTMLElement) => {\n const span = document.createElement(\"span\");\n span.style.opacity = \"0\";\n span.style.position = \"absolute\";\n span.style.top = \"-1000px\";\n span.style.left = \"-1000px\";\n span.style.whiteSpace = \"nowrap\";\n span.style.pointerEvents = \"none\";\n container.appendChild(span);\n\n return {\n measure: (text: string) => {\n span.innerText = text;\n return span.clientWidth;\n },\n destroy: () => {\n container.removeChild(span);\n },\n };\n};\n\nexport const getMiddleTruncatedString = (\n text: string,\n ellipsis: string,\n container: HTMLElement\n): string => {\n if (!text) return text;\n\n const { measure: getTextWidth, destroy: destroyMeasure } =\n measureText(container);\n\n const textWidth = getTextWidth(text);\n const containerWidth = container.clientWidth;\n const initialOffset = Math.floor((containerWidth / textWidth) * text.length);\n\n if (textWidth <= containerWidth) {\n destroyMeasure();\n return text;\n }\n\n let offset = initialOffset;\n const attempts: Record<number, [number, string]> = {};\n const maxAttempts = 20;\n const buffer = 10;\n\n while (Object.values(attempts).length <= maxAttempts) {\n // If we have already tried this offset, stop\n if (attempts[offset]) break;\n\n // If we are at the beginning of the string, just return the ellipsis\n if (offset <= 1) {\n attempts[0] = [0, ellipsis];\n break;\n }\n\n const start = text\n .slice(0, Math.ceil((offset - ellipsis.length) / 2 - 1))\n .trimEnd();\n const end = text\n .slice(Math.floor((offset - ellipsis.length) / 2) - offset)\n .trimStart();\n const truncatedStr = start + ellipsis + end;\n const width = getTextWidth(truncatedStr);\n\n attempts[offset] = [width, truncatedStr];\n\n if (width >= containerWidth) {\n offset = offset - 2;\n } else {\n // If we are close to the container width, stop\n if (containerWidth - width < buffer) break;\n offset = offset + 2;\n }\n }\n\n // Remove the span element used for measuring text\n destroyMeasure();\n\n // Find the closest attempt that is smaller than the container width\n return (\n Object.values(attempts)\n .reverse()\n .find(([width]) => width < containerWidth)?.[1] ??\n Object.values(attempts)[0][1]\n );\n};\n"],"names":["measureText","container","span","text","getMiddleTruncatedString","ellipsis","_a","getTextWidth","destroyMeasure","textWidth","containerWidth","initialOffset","offset","attempts","maxAttempts","buffer","start","end","truncatedStr","width"],"mappings":"AAAa,MAAAA,IAAc,CAACC,MAA2B;AAC/C,QAAAC,IAAO,SAAS,cAAc,MAAM;AAC1C,SAAAA,EAAK,MAAM,UAAU,KACrBA,EAAK,MAAM,WAAW,YACtBA,EAAK,MAAM,MAAM,WACjBA,EAAK,MAAM,OAAO,WAClBA,EAAK,MAAM,aAAa,UACxBA,EAAK,MAAM,gBAAgB,QAC3BD,EAAU,YAAYC,CAAI,GAEnB;AAAA,IACL,SAAS,CAACC,OACRD,EAAK,YAAYC,GACVD,EAAK;AAAA,IAEd,SAAS,MAAM;AACb,MAAAD,EAAU,YAAYC,CAAI;AAAA,IAAA;AAAA,EAE9B;AACF,GAEaE,IAA2B,CACtCD,GACAE,GACAJ,MACW;AAzBA,MAAAK;AA0BP,MAAA,CAACH,EAAa,QAAAA;AAElB,QAAM,EAAE,SAASI,GAAc,SAASC,EAAe,IACrDR,EAAYC,CAAS,GAEjBQ,IAAYF,EAAaJ,CAAI,GAC7BO,IAAiBT,EAAU,aAC3BU,IAAgB,KAAK,MAAOD,IAAiBD,IAAaN,EAAK,MAAM;AAE3E,MAAIM,KAAaC;AACA,WAAAF,EAAA,GACRL;AAGT,MAAIS,IAASD;AACb,QAAME,IAA6C,CAAC,GAC9CC,IAAc,IACdC,IAAS;AAEf,SAAO,OAAO,OAAOF,CAAQ,EAAE,UAAUC,KAEnC,CAAAD,EAASD,CA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