@tu-design/vue 0.5.6 → 0.5.8
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/index.d.mts +160 -56
- package/dist/index.mjs +688 -76
- package/dist/registry/vue/alert-dialog.json +1 -1
- package/dist/registry/vue/alert.json +1 -1
- package/dist/registry/vue/avatar-group.json +1 -1
- package/dist/registry/vue/avatar.json +2 -2
- package/dist/registry/vue/badge.json +1 -1
- package/dist/registry/vue/button.json +1 -1
- package/dist/registry/vue/calendar.json +3 -3
- package/dist/registry/vue/card.json +1 -1
- package/dist/registry/vue/cascader.json +1 -1
- package/dist/registry/vue/checkbox.json +1 -1
- package/dist/registry/vue/context-menu.json +1 -1
- package/dist/registry/vue/currency-input.json +2 -2
- package/dist/registry/vue/date-picker.json +1 -1
- package/dist/registry/vue/date-range-picker.json +1 -1
- package/dist/registry/vue/date-shared.json +4 -4
- package/dist/registry/vue/dialog.json +1 -1
- package/dist/registry/vue/drawer.json +1 -1
- package/dist/registry/vue/dropdown-menu.json +1 -1
- package/dist/registry/vue/empty.json +1 -1
- package/dist/registry/vue/form-render.json +12 -12
- package/dist/registry/vue/form.json +1 -1
- package/dist/registry/vue/icon-shared.json +1 -1
- package/dist/registry/vue/input.json +1 -1
- package/dist/registry/vue/label.json +1 -1
- package/dist/registry/vue/month-picker.json +1 -1
- package/dist/registry/vue/number-input.json +3 -3
- package/dist/registry/vue/overlay-shared.json +5 -5
- package/dist/registry/vue/password-input.json +1 -1
- package/dist/registry/vue/pin-input.json +1 -1
- package/dist/registry/vue/popconfirm.json +1 -1
- package/dist/registry/vue/popover.json +2 -2
- package/dist/registry/vue/progress.json +1 -1
- package/dist/registry/vue/radio-group.json +1 -1
- package/dist/registry/vue/registry.json +52 -52
- package/dist/registry/vue/select.json +3 -3
- package/dist/registry/vue/separator.json +1 -1
- package/dist/registry/vue/skeleton.json +1 -1
- package/dist/registry/vue/slider.json +1 -1
- package/dist/registry/vue/slot.json +3 -2
- package/dist/registry/vue/spin.json +1 -1
- package/dist/registry/vue/switch.json +1 -1
- package/dist/registry/vue/table-render.json +9 -9
- package/dist/registry/vue/tabs.json +2 -1
- package/dist/registry/vue/textarea.json +1 -1
- package/dist/registry/vue/timeline.json +2 -2
- package/dist/registry/vue/toast.json +2 -2
- package/dist/registry/vue/tokens.json +1 -1
- package/dist/registry/vue/tooltip.json +1 -1
- package/dist/registry/vue/tree-select.json +1 -1
- package/dist/registry/vue/tree-shared.json +9 -9
- package/dist/registry/vue/utils.json +2 -2
- package/dist/registry/vue/week-picker.json +2 -2
- package/dist/registry/vue/year-picker.json +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
3
|
"name": "timeline",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.8",
|
|
5
5
|
"type": "registry:ui",
|
|
6
6
|
"description": "时间轴:数据驱动 items 渲染竖向事件流,支持单列/左右交替、五种语义节点色与空心节点、#item 作用域插槽自定义内容。",
|
|
7
7
|
"registryDependencies": ["utils"],
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"path": "timeline/Timeline.vue",
|
|
12
12
|
"type": "registry:component",
|
|
13
13
|
"target": "components/ui/timeline/Timeline.vue",
|
|
14
|
-
"content": "<script setup lang=\"ts\">\nimport { computed } from \"vue\";\nimport { cn } from \"@/lib/utils\";\nimport {\n timelineDotVariants,\n timelineItemVariants,\n timelineVariants,\n type TimelineItemData,\n type TimelineItemVariants,\n type TimelineVariants,\n} from \"./index\";\n\ninterface Props {\n /** 数据源:按数组顺序自上而下渲染 */\n items: TimelineItemData[];\n /** 布局模式:right 单列(节点靠左)/ alternate 沿中轴左右交替 */\n mode?: TimelineVariants[\"mode\"];\n /** 尺寸:联动节点大小、连线位置与字号间距 */\n size?: TimelineItemVariants[\"size\"];\n /** 追加/覆盖样式(经 cn 合并) */\n class?: string;\n}\n\nconst props = withDefaults(defineProps<Props>(), {\n mode: \"right\",\n size: \"default\",\n});\n\nconst rootClass = computed(() => cn(timelineVariants({ mode: props.mode }), props.class));\n\nconst itemClass = computed(() => timelineItemVariants({ mode: props.mode, size: props.size }));\n\nconst titleClass = computed(() =>\n props.size === \"sm\"\n ? \"text-xs leading-4 font-medium text-foreground\"\n : \"text-sm font-medium leading-5 text-foreground\",\n);\n\nconst descriptionClass = computed(() =>\n props.size === \"sm\"\n ? \"mt-1 text-xs leading-relaxed text-muted-foreground\"\n : \"mt-1 text-sm leading-relaxed text-muted-foreground\",\n);\n\n
|
|
14
|
+
"content": "<script setup lang=\"ts\">\nimport { computed } from \"vue\";\nimport { cn } from \"@/lib/utils\";\nimport {\n timelineDotVariants,\n timelineItemVariants,\n timelineVariants,\n type TimelineItemData,\n type TimelineItemVariants,\n type TimelineVariants,\n} from \"./index\";\n\ninterface Props {\n /** 数据源:按数组顺序自上而下渲染 */\n items: TimelineItemData[];\n /** 布局模式:right 单列(节点靠左)/ alternate 沿中轴左右交替 */\n mode?: TimelineVariants[\"mode\"];\n /** 尺寸:联动节点大小、连线位置与字号间距 */\n size?: TimelineItemVariants[\"size\"];\n /** 追加/覆盖样式(经 cn 合并) */\n class?: string;\n}\n\nconst props = withDefaults(defineProps<Props>(), {\n mode: \"right\",\n size: \"default\",\n});\n\nconst rootClass = computed(() => cn(timelineVariants({ mode: props.mode }), props.class));\n\nconst itemClass = computed(() => timelineItemVariants({ mode: props.mode, size: props.size }));\n\nconst titleClass = computed(() =>\n props.size === \"sm\"\n ? \"text-xs leading-4 font-medium text-foreground\"\n : \"text-sm font-medium leading-5 text-foreground\",\n);\n\nconst descriptionClass = computed(() =>\n props.size === \"sm\"\n ? \"mt-1 text-xs leading-relaxed text-muted-foreground\"\n : \"mt-1 text-sm leading-relaxed text-muted-foreground\",\n);\n\n/**\n * 连线类:首末项按 index 裁切(不用 first:/last: 伪类——line 恒为 li 首个子元素,伪类会全量误命中)\n * @param index - 项在 items 中的下标\n * @returns 连线元素的 class\n */\nfunction lineClass(index: number): string {\n const isFirst = index === 0;\n const isLast = index === props.items.length - 1;\n return cn(\n \"absolute w-0.5 -translate-x-1/2 bg-border\",\n props.mode === \"alternate\" ? \"left-1/2\" : props.size === \"sm\" ? \"left-[5px]\" : \"left-[6px]\",\n isFirst ? \"top-[10px]\" : \"top-0\",\n isLast ? \"bottom-[calc(100%-10px)]\" : \"bottom-0\",\n );\n}\n\n/**\n * 节点类:颜色/空心取自单项数据,位置与尺寸取自组件变体\n * @param item - 时间轴单项数据\n * @returns 节点元素的 class\n */\nfunction dotClass(item: TimelineItemData): string {\n return cn(\n timelineDotVariants({\n mode: props.mode,\n size: props.size,\n color: item.dotColor,\n hollow: item.hollow,\n }),\n );\n}\n\n/**\n * 内容区类:right 占第 2 列;alternate 按奇偶交替占第 1/3 列并切换对齐\n * @param index - 项在 items 中的下标(alternate 模式据此决定占列与对齐)\n * @returns 内容区元素的 class\n */\nfunction contentClass(index: number): string {\n const base = \"min-w-0 flex flex-col\";\n if (props.mode === \"alternate\") {\n return cn(\n base,\n index % 2 === 0\n ? \"col-start-1 row-start-1 pr-4 text-right\"\n : \"col-start-3 row-start-1 pl-4 text-left\",\n );\n }\n return cn(base, props.size === \"sm\" ? \"pl-2.5\" : \"pl-3\");\n}\n\n/**\n * 时间戳类:bottom 时 DOM 仍在前部,仅切 order-last 移到内容下方(不分支 DOM)\n * @param item - 时间轴单项数据(读 timestampPlacement)\n * @returns 时间戳元素的 class\n */\nfunction timestampClass(item: TimelineItemData): string {\n return item.timestampPlacement === \"bottom\"\n ? \"mb-1 mt-1.5 order-last text-xs leading-4 text-muted-foreground tabular-nums\"\n : \"mb-1 text-xs leading-4 text-muted-foreground tabular-nums\";\n}\n</script>\n\n<template>\n <ol data-slot=\"timeline\" :class=\"rootClass\">\n <li v-for=\"(item, index) in items\" :key=\"index\" data-slot=\"timeline-item\" :class=\"itemClass\">\n <span data-slot=\"timeline-line\" aria-hidden=\"true\" :class=\"lineClass(index)\" />\n <span data-slot=\"timeline-dot\" :class=\"dotClass(item)\" />\n <div data-slot=\"timeline-content\" :class=\"contentClass(index)\">\n <!-- #item 整项内容覆盖(dot 与 line 不受影响),默认渲染 timestamp/title/content -->\n <slot name=\"item\" :item=\"item\" :index=\"index\">\n <span\n v-if=\"item.timestamp\"\n data-slot=\"timeline-timestamp\"\n :class=\"timestampClass(item)\"\n >{{ item.timestamp }}</span\n >\n <p v-if=\"item.title\" data-slot=\"timeline-title\" :class=\"titleClass\">{{ item.title }}</p>\n <p v-if=\"item.content\" data-slot=\"timeline-description\" :class=\"descriptionClass\">\n {{ item.content }}\n </p>\n </slot>\n </div>\n </li>\n </ol>\n</template>\n"
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
"path": "timeline/index.ts",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
3
|
"name": "toast",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.8",
|
|
5
5
|
"type": "registry:ui",
|
|
6
6
|
"description": "全局轻提示:ToastProvider 在应用根部挂载一次,useToast() 提供命令式 API(success/error/info/warning/loading/promise/dismiss);基于 Ark UI Toast 原语,语义 type 映射主题 token 配色。",
|
|
7
7
|
"registryDependencies": ["icon-shared", "utils"],
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"path": "toast/useToast.ts",
|
|
24
24
|
"type": "registry:lib",
|
|
25
25
|
"target": "components/ui/toast/useToast.ts",
|
|
26
|
-
"content": "import { createToaster } from \"@ark-ui/vue/toast\";\nimport type {\n ToastOptions as ArkToastOptions,\n ToastPlacement as ArkToastPlacement,\n ToastPromiseOptions as ArkToastPromiseOptions,\n} from \"@ark-ui/vue/toast\";\n\nexport type ToastOptions = ArkToastOptions;\nexport type ToastPlacement = ArkToastPlacement;\nexport type ToastPromiseOptions<T> = ArkToastPromiseOptions<T>;\n\n/** Provider 缺省配置(与 Provider props 默认值保持一致) */\nconst DEFAULTS = {\n placement: \"bottom-end\" as ArkToastPlacement,\n duration: 3000,\n max: 3,\n};\n\n// 模块级单例:useToast() 在任何地方返回同一个外观对象(引用稳定),\n// 内部转发到 current 指向的 zag store;Provider 挂载时按 props 重建 store。\nlet current = createToaster(DEFAULTS);\nlet currentConfig = { ...DEFAULTS };\nlet providerMounted = false;\n\n/**\n * 按 props 重建单例内部 store(ToastProvider 挂载时调用)。\n * 配置未变化时复用现有 store,避免 Provider 重挂载丢弃排队中的 toast。\n * 返回 store 供 Provider 的 <Toaster> 渲染使用。\n */\nexport function __configureToaster(\n props: Partial<{ placement: ArkToastPlacement; duration: number; max: number }> = {},\n) {\n const next = { ...DEFAULTS, ...props };\n if (\n next.placement === currentConfig.placement &&\n next.duration === currentConfig.duration &&\n next.max === currentConfig.max\n ) {\n return current;\n }\n currentConfig = next;\n current = createToaster(next);\n return current;\n}\n\n
|
|
26
|
+
"content": "import { createToaster } from \"@ark-ui/vue/toast\";\nimport type {\n ToastOptions as ArkToastOptions,\n ToastPlacement as ArkToastPlacement,\n ToastPromiseOptions as ArkToastPromiseOptions,\n} from \"@ark-ui/vue/toast\";\n\nexport type ToastOptions = ArkToastOptions;\nexport type ToastPlacement = ArkToastPlacement;\nexport type ToastPromiseOptions<T> = ArkToastPromiseOptions<T>;\n\n/** Provider 缺省配置(与 Provider props 默认值保持一致) */\nconst DEFAULTS = {\n placement: \"bottom-end\" as ArkToastPlacement,\n duration: 3000,\n max: 3,\n};\n\n// 模块级单例:useToast() 在任何地方返回同一个外观对象(引用稳定),\n// 内部转发到 current 指向的 zag store;Provider 挂载时按 props 重建 store。\nlet current = createToaster(DEFAULTS);\nlet currentConfig = { ...DEFAULTS };\nlet providerMounted = false;\n\n/**\n * 按 props 重建单例内部 store(ToastProvider 挂载时调用)。\n * 配置未变化时复用现有 store,避免 Provider 重挂载丢弃排队中的 toast。\n * 返回 store 供 Provider 的 <Toaster> 渲染使用。\n * @param props - Provider 传入的 placement/duration/max 配置,缺省项回退内置默认值\n * @returns 当前 toast store 实例\n */\nexport function __configureToaster(\n props: Partial<{ placement: ArkToastPlacement; duration: number; max: number }> = {},\n) {\n const next = { ...DEFAULTS, ...props };\n if (\n next.placement === currentConfig.placement &&\n next.duration === currentConfig.duration &&\n next.max === currentConfig.max\n ) {\n return current;\n }\n currentConfig = next;\n current = createToaster(next);\n return current;\n}\n\n/**\n * 读取当前内部 store(测试用)。\n * @returns 当前模块单例指向的 toast store 实例\n */\nexport function __getInternalToaster() {\n return current;\n}\n\n/**\n * 标记 Provider 已挂载/已卸载(Provider 生命周期与测试用)。\n * @param value - true 表示 Provider 已挂载,false 表示已卸载\n */\nexport function __setToastMounted(value: boolean) {\n providerMounted = value;\n}\n\n/**\n * Provider 未挂载时在开发环境输出告警,提醒先在应用根部挂载 <ToastProvider>。\n */\nfunction warnIfUnmounted() {\n if (!providerMounted && import.meta.env.DEV) {\n console.warn(\n \"[tu-design] 在 <ToastProvider> 挂载前调用了 toast。请在应用根部挂载一次 <ToastProvider>,否则提示不会渲染。\",\n );\n }\n}\n\n// 外观对象在模块级创建一次,保证 useToast() 引用恒定\nconst toastApi = {\n /**\n * 成功提示。\n * @param options - toast 配置(标题、描述、时长等)\n * @returns 该条 toast 的创建结果,可用于后续控制\n */\n success: (options: ToastOptions) => {\n warnIfUnmounted();\n return current.create({ ...options, type: \"success\" });\n },\n /**\n * 错误提示。\n * @param options - toast 配置(标题、描述、时长等)\n * @returns 该条 toast 的创建结果,可用于后续控制\n */\n error: (options: ToastOptions) => {\n warnIfUnmounted();\n return current.create({ ...options, type: \"error\" });\n },\n /**\n * 信息提示。\n * @param options - toast 配置(标题、描述、时长等)\n * @returns 该条 toast 的创建结果,可用于后续控制\n */\n info: (options: ToastOptions) => {\n warnIfUnmounted();\n return current.create({ ...options, type: \"info\" });\n },\n /**\n * 警告提示。\n * @param options - toast 配置(标题、描述、时长等)\n * @returns 该条 toast 的创建结果,可用于后续控制\n */\n warning: (options: ToastOptions) => {\n warnIfUnmounted();\n return current.create({ ...options, type: \"warning\" });\n },\n /**\n * 加载中提示。\n * @param options - toast 配置(标题、描述、时长等)\n * @returns 该条 toast 的创建结果,可用于后续控制\n */\n loading: (options: ToastOptions) => {\n warnIfUnmounted();\n return current.create({ ...options, type: \"loading\" });\n },\n /**\n * 跟踪 Promise 状态的提示。\n * @param promise - 待跟踪的 Promise 或返回 Promise 的工厂函数\n * @param options - Promise 各阶段(loading/success/error)的 toast 配置\n * @param shared - 各阶段共享的基础配置(不含 type)\n * @returns 该条 toast 的创建结果,可用于后续控制\n */\n promise: <T>(\n promise: Promise<T> | (() => Promise<T>),\n options: ArkToastPromiseOptions<T>,\n shared?: Omit<ToastOptions, \"type\">,\n ) => {\n warnIfUnmounted();\n return current.promise(promise, options, shared);\n },\n /**\n * 关闭指定 toast;不传 id 时关闭全部。\n * @param id - 目标 toast 的 id;缺省时关闭全部\n */\n dismiss: (id?: string) => {\n warnIfUnmounted();\n current.dismiss(id);\n },\n};\n\n/**\n * 获取 toast API。模块级单例外观对象,任意位置调用返回同一引用(引用稳定);\n * 内部转发到 Provider 挂载后重建的 store,调用前须在应用根部挂载 <ToastProvider>。\n * @returns toast 操作 API(success/error/info/warning/loading/promise/dismiss)\n */\nexport function useToast() {\n return toastApi;\n}\n\nexport type ToastApi = typeof toastApi;\n"
|
|
27
27
|
}
|
|
28
28
|
]
|
|
29
29
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
3
|
"name": "tokens",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.8",
|
|
5
5
|
"type": "registry:style",
|
|
6
6
|
"description": "Tailwind CSS v4 语义 tokens(shadcn 官方 v4 集合)。",
|
|
7
7
|
"dependencies": ["tw-animate-css@^1.4.0"],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
3
|
"name": "tooltip",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.8",
|
|
5
5
|
"type": "registry:ui",
|
|
6
6
|
"description": "文字提示气泡:悬停触发,基于 Ark UI Tooltip 原语,支持 asChild 与延迟配置。",
|
|
7
7
|
"registryDependencies": ["utils", "overlay-shared"],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
3
|
"name": "tree-select",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.8",
|
|
5
5
|
"type": "registry:ui",
|
|
6
6
|
"description": "树形下拉选择:一站式 props 驱动,支持单/多选、勾选级联、过滤与多标签折叠。",
|
|
7
7
|
"registryDependencies": ["icon-shared", "tree-shared", "utils", "date-shared", "overlay-shared"],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
3
|
"name": "tree-shared",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.8",
|
|
5
5
|
"type": "registry:ui",
|
|
6
6
|
"description": "树形数据层与共享类型(移植自 treemate v0.3.11,MIT)。",
|
|
7
7
|
"registryDependencies": ["icon-shared", "utils"],
|
|
@@ -16,25 +16,25 @@
|
|
|
16
16
|
"path": "tree-shared/check.ts",
|
|
17
17
|
"type": "registry:lib",
|
|
18
18
|
"target": "components/ui/tree-shared/check.ts",
|
|
19
|
-
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:无实质改动。\n */\nimport type { Key, TreeMate, MergedKeys, TreeNode } from \"./interface\";\nimport { isExpilicitlyNotLoaded, merge, minus, traverseWithCb, TRAVERSE_COMMAND } from \"./utils\";\n\nexport class SubtreeNotLoadedError extends Error {\n constructor() {\n super();\n this.message =\n \"SubtreeNotLoadedError: checking a subtree whose required nodes are not fully loaded.\";\n }\n}\n\nfunction getExtendedCheckedKeySetAfterCheck<R, G, I>(\n checkKeys: Key[],\n currentCheckedKeys: Key[],\n treeMate: TreeMate<R, G, I>,\n): Set<Key> {\n return getExtendedCheckedKeySet(currentCheckedKeys.concat(checkKeys), treeMate);\n}\n\nfunction getAvailableAscendantNodeSet<R, G, I>(\n uncheckedKeys: Key[],\n treeMate: TreeMate<R, G, I>,\n): Set<Key> {\n const visitedKeys: Set<Key> = new Set();\n uncheckedKeys.forEach((uncheckedKey) => {\n const uncheckedTreeNode = treeMate.treeNodeMap.get(uncheckedKey);\n if (uncheckedTreeNode !== undefined) {\n let nodeCursor = uncheckedTreeNode.parent;\n while (nodeCursor !== null) {\n if (nodeCursor.disabled) break;\n if (visitedKeys.has(nodeCursor.key)) break;\n else {\n visitedKeys.add(nodeCursor.key);\n }\n nodeCursor = nodeCursor.parent;\n }\n }\n });\n return visitedKeys;\n}\n\nfunction getExtendedCheckedKeySetAfterUncheck<R, G, I>(\n uncheckedKeys: Key[],\n currentCheckedKeys: Key[],\n treeMate: TreeMate<R, G, I>,\n): Set<Key> {\n const extendedCheckedKeySet = getExtendedCheckedKeySet(currentCheckedKeys, treeMate);\n const extendedKeySetToUncheck = getExtendedCheckedKeySet(uncheckedKeys, treeMate, true);\n const ascendantKeySet: Set<Key> = getAvailableAscendantNodeSet(uncheckedKeys, treeMate);\n const keysToRemove: Key[] = [];\n extendedCheckedKeySet.forEach((key) => {\n if (extendedKeySetToUncheck.has(key) || ascendantKeySet.has(key)) {\n keysToRemove.push(key);\n }\n });\n keysToRemove.forEach((key) => extendedCheckedKeySet.delete(key));\n return extendedCheckedKeySet;\n}\n\nexport function getCheckedKeys<R, G, I>(\n options: {\n checkedKeys: Key[];\n indeterminateKeys: Key[];\n keysToCheck?: Key[];\n keysToUncheck?: Key[];\n cascade: boolean;\n leafOnly: boolean;\n checkStrategy: string;\n },\n treeMate: TreeMate<R, G, I>,\n): MergedKeys {\n const {\n checkedKeys,\n keysToCheck,\n keysToUncheck,\n indeterminateKeys,\n cascade,\n leafOnly,\n checkStrategy,\n } = options;\n if (!cascade) {\n if (keysToCheck !== undefined) {\n return {\n checkedKeys: merge(checkedKeys, keysToCheck),\n indeterminateKeys: Array.from(indeterminateKeys),\n };\n } else if (keysToUncheck !== undefined) {\n return {\n checkedKeys: minus(checkedKeys, keysToUncheck),\n indeterminateKeys: Array.from(indeterminateKeys),\n };\n } else {\n return {\n checkedKeys: Array.from(checkedKeys),\n indeterminateKeys: Array.from(indeterminateKeys),\n };\n }\n }\n const { levelTreeNodeMap } = treeMate;\n let extendedCheckedKeySet: Set<Key>;\n if (keysToUncheck !== undefined) {\n extendedCheckedKeySet = getExtendedCheckedKeySetAfterUncheck(\n keysToUncheck,\n checkedKeys,\n treeMate,\n );\n } else if (keysToCheck !== undefined) {\n extendedCheckedKeySet = getExtendedCheckedKeySetAfterCheck(keysToCheck, checkedKeys, treeMate);\n } else {\n extendedCheckedKeySet = getExtendedCheckedKeySet(checkedKeys, treeMate);\n }\n\n const checkStrategyIsParent = checkStrategy === \"parent\";\n const checkStrategyIsChild = checkStrategy === \"child\" || leafOnly;\n\n const syntheticCheckedKeySet: Set<Key> = extendedCheckedKeySet;\n const syntheticIndeterminateKeySet: Set<Key> = new Set();\n const maxLevel = Math.max.apply(null, Array.from(levelTreeNodeMap.keys()));\n // cascade check\n // 1. if tree is fully loaded, it just works\n // 2. if the tree is not fully loaded, we assume that keys which is in not\n // loaded tree are not in checked keys\n // for example:\n // a -- b(fully-loaded) -- c(fully-loaded)\n // |- d(partial-loaded) -- ?e(not-loaded)\n // in the case, `e` is assumed not to be checked, nor we can't calc `d`'s\n // and `a`'s status\n for (let level = maxLevel; level >= 0; level -= 1) {\n const levelIsZero = level === 0;\n // it should exists, nor it is a bug\n const levelTreeNodes = levelTreeNodeMap.get(level);\n for (const levelTreeNode of levelTreeNodes as Array<TreeNode<R, G, I>>) {\n if (levelTreeNode.isLeaf) continue;\n const { key: levelTreeNodeKey, shallowLoaded } = levelTreeNode;\n if (checkStrategyIsChild && shallowLoaded) {\n levelTreeNode.children!.forEach((v) => {\n if (!v.disabled && !v.isLeaf && v.shallowLoaded && syntheticCheckedKeySet.has(v.key)) {\n syntheticCheckedKeySet.delete(v.key);\n }\n });\n }\n if (levelTreeNode.disabled || !shallowLoaded) {\n continue;\n }\n let fullyChecked = true;\n let partialChecked = false;\n let allDisabled = true;\n // it is shallow loaded, so `children` must exist\n for (const childNode of levelTreeNode.children as Array<TreeNode<R, G, I>>) {\n const childKey = childNode.key;\n if (childNode.disabled) continue;\n if (allDisabled) allDisabled = false;\n if (syntheticCheckedKeySet.has(childKey)) {\n partialChecked = true;\n } else if (syntheticIndeterminateKeySet.has(childKey)) {\n partialChecked = true;\n fullyChecked = false;\n break;\n } else {\n fullyChecked = false;\n if (partialChecked) {\n break;\n }\n }\n }\n if (fullyChecked && !allDisabled) {\n if (checkStrategyIsParent) {\n levelTreeNode.children!.forEach((v) => {\n if (!v.disabled && syntheticCheckedKeySet.has(v.key)) {\n syntheticCheckedKeySet.delete(v.key);\n }\n });\n }\n syntheticCheckedKeySet.add(levelTreeNodeKey);\n } else if (partialChecked) {\n syntheticIndeterminateKeySet.add(levelTreeNodeKey);\n }\n if (levelIsZero && checkStrategyIsChild && syntheticCheckedKeySet.has(levelTreeNodeKey)) {\n syntheticCheckedKeySet.delete(levelTreeNodeKey);\n }\n }\n }\n return {\n checkedKeys: Array.from(syntheticCheckedKeySet),\n indeterminateKeys: Array.from(syntheticIndeterminateKeySet),\n };\n}\n\n// unchecking is safe when doing cascade uncheck in async mode\nexport function getExtendedCheckedKeySet<R, G, I>(\n checkedKeys: Key[],\n treeMate: TreeMate<R, G, I>,\n isUnchecking: boolean = false,\n): Set<Key> {\n const { treeNodeMap, getChildren } = treeMate;\n const visitedKeySet: Set<Key> = new Set();\n const extendedKeySet: Set<Key> = new Set(checkedKeys);\n checkedKeys.forEach((checkedKey) => {\n const checkedTreeNode = treeNodeMap.get(checkedKey);\n if (checkedTreeNode !== undefined) {\n traverseWithCb(checkedTreeNode, (treeNode) => {\n if (treeNode.disabled) {\n return TRAVERSE_COMMAND.STOP;\n }\n const { key } = treeNode;\n if (visitedKeySet.has(key)) return;\n visitedKeySet.add(key);\n // Adding keys before loaded check is okay, since if not valid error\n // would be thrown\n extendedKeySet.add(key);\n if (isExpilicitlyNotLoaded(treeNode.rawNode, getChildren)) {\n if (isUnchecking) {\n return TRAVERSE_COMMAND.STOP;\n } else {\n throw new SubtreeNotLoadedError();\n }\n }\n });\n }\n });\n return extendedKeySet;\n}\n"
|
|
19
|
+
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:无实质改动。\n */\nimport type { Key, TreeMate, MergedKeys, TreeNode } from \"./interface\";\nimport { isExpilicitlyNotLoaded, merge, minus, traverseWithCb, TRAVERSE_COMMAND } from \"./utils\";\n\nexport class SubtreeNotLoadedError extends Error {\n constructor() {\n super();\n this.message =\n \"SubtreeNotLoadedError: checking a subtree whose required nodes are not fully loaded.\";\n }\n}\n\n/**\n * 计算勾选后的完整选中 key 集合:把新增勾选并入当前选中集,再级联扩展到子孙节点。\n * @param checkKeys - 本次新增勾选的节点 key 列表\n * @param currentCheckedKeys - 当前已选中的 key 列表\n * @param treeMate - 树 mate 实例,用于查询节点与子树\n * @returns 扩展后的选中 key 集合\n */\nfunction getExtendedCheckedKeySetAfterCheck<R, G, I>(\n checkKeys: Key[],\n currentCheckedKeys: Key[],\n treeMate: TreeMate<R, G, I>,\n): Set<Key> {\n return getExtendedCheckedKeySet(currentCheckedKeys.concat(checkKeys), treeMate);\n}\n\n/**\n * 收集取消勾选节点的可用祖先 key 集合(级联反选时这些祖先需同步取消勾选);\n * 上溯在遇到 disabled 节点或已访问节点时截断。\n * @param uncheckedKeys - 被取消勾选的节点 key 列表\n * @param treeMate - 树 mate 实例,用于查询节点父子关系\n * @returns 需要联动取消勾选的祖先 key 集合\n */\nfunction getAvailableAscendantNodeSet<R, G, I>(\n uncheckedKeys: Key[],\n treeMate: TreeMate<R, G, I>,\n): Set<Key> {\n const visitedKeys: Set<Key> = new Set();\n uncheckedKeys.forEach((uncheckedKey) => {\n const uncheckedTreeNode = treeMate.treeNodeMap.get(uncheckedKey);\n if (uncheckedTreeNode !== undefined) {\n let nodeCursor = uncheckedTreeNode.parent;\n while (nodeCursor !== null) {\n if (nodeCursor.disabled) break;\n if (visitedKeys.has(nodeCursor.key)) break;\n else {\n visitedKeys.add(nodeCursor.key);\n }\n nodeCursor = nodeCursor.parent;\n }\n }\n });\n return visitedKeys;\n}\n\n/**\n * 计算取消勾选后的完整选中 key 集合:从扩展选中集移除被取消的 key\n * 及其可用祖先,返回剩余集合。\n * @param uncheckedKeys - 本次取消勾选的节点 key 列表\n * @param currentCheckedKeys - 当前已选中的 key 列表\n * @param treeMate - 树 mate 实例\n * @returns 取消勾选后剩余的选中 key 集合\n */\nfunction getExtendedCheckedKeySetAfterUncheck<R, G, I>(\n uncheckedKeys: Key[],\n currentCheckedKeys: Key[],\n treeMate: TreeMate<R, G, I>,\n): Set<Key> {\n const extendedCheckedKeySet = getExtendedCheckedKeySet(currentCheckedKeys, treeMate);\n const extendedKeySetToUncheck = getExtendedCheckedKeySet(uncheckedKeys, treeMate, true);\n const ascendantKeySet: Set<Key> = getAvailableAscendantNodeSet(uncheckedKeys, treeMate);\n const keysToRemove: Key[] = [];\n extendedCheckedKeySet.forEach((key) => {\n if (extendedKeySetToUncheck.has(key) || ascendantKeySet.has(key)) {\n keysToRemove.push(key);\n }\n });\n keysToRemove.forEach((key) => extendedCheckedKeySet.delete(key));\n return extendedCheckedKeySet;\n}\n\n/**\n * 计算树勾选结果:cascade=false 时直接在现有选中集上增删;\n * cascade=true 时先扩展选中集,再自底向上按层归并出最终勾选状态\n * (checkStrategy 为 all/parent/child 时分别保留全部/父节点/叶子选中)。\n * @param options - 勾选参数:当前选中与半选 key、本次勾选/取消的 key、\n * cascade、leafOnly 与 checkStrategy\n * @param treeMate - 树 mate 实例,提供层级节点表用于自底向上归并\n * @returns 最终的选中 key 列表与半选 key 列表\n */\nexport function getCheckedKeys<R, G, I>(\n options: {\n checkedKeys: Key[];\n indeterminateKeys: Key[];\n keysToCheck?: Key[];\n keysToUncheck?: Key[];\n cascade: boolean;\n leafOnly: boolean;\n checkStrategy: string;\n },\n treeMate: TreeMate<R, G, I>,\n): MergedKeys {\n const {\n checkedKeys,\n keysToCheck,\n keysToUncheck,\n indeterminateKeys,\n cascade,\n leafOnly,\n checkStrategy,\n } = options;\n if (!cascade) {\n if (keysToCheck !== undefined) {\n return {\n checkedKeys: merge(checkedKeys, keysToCheck),\n indeterminateKeys: Array.from(indeterminateKeys),\n };\n } else if (keysToUncheck !== undefined) {\n return {\n checkedKeys: minus(checkedKeys, keysToUncheck),\n indeterminateKeys: Array.from(indeterminateKeys),\n };\n } else {\n return {\n checkedKeys: Array.from(checkedKeys),\n indeterminateKeys: Array.from(indeterminateKeys),\n };\n }\n }\n const { levelTreeNodeMap } = treeMate;\n let extendedCheckedKeySet: Set<Key>;\n if (keysToUncheck !== undefined) {\n extendedCheckedKeySet = getExtendedCheckedKeySetAfterUncheck(\n keysToUncheck,\n checkedKeys,\n treeMate,\n );\n } else if (keysToCheck !== undefined) {\n extendedCheckedKeySet = getExtendedCheckedKeySetAfterCheck(keysToCheck, checkedKeys, treeMate);\n } else {\n extendedCheckedKeySet = getExtendedCheckedKeySet(checkedKeys, treeMate);\n }\n\n const checkStrategyIsParent = checkStrategy === \"parent\";\n const checkStrategyIsChild = checkStrategy === \"child\" || leafOnly;\n\n const syntheticCheckedKeySet: Set<Key> = extendedCheckedKeySet;\n const syntheticIndeterminateKeySet: Set<Key> = new Set();\n const maxLevel = Math.max.apply(null, Array.from(levelTreeNodeMap.keys()));\n // cascade check\n // 1. if tree is fully loaded, it just works\n // 2. if the tree is not fully loaded, we assume that keys which is in not\n // loaded tree are not in checked keys\n // for example:\n // a -- b(fully-loaded) -- c(fully-loaded)\n // |- d(partial-loaded) -- ?e(not-loaded)\n // in the case, `e` is assumed not to be checked, nor we can't calc `d`'s\n // and `a`'s status\n for (let level = maxLevel; level >= 0; level -= 1) {\n const levelIsZero = level === 0;\n // it should exists, nor it is a bug\n const levelTreeNodes = levelTreeNodeMap.get(level);\n for (const levelTreeNode of levelTreeNodes as Array<TreeNode<R, G, I>>) {\n if (levelTreeNode.isLeaf) continue;\n const { key: levelTreeNodeKey, shallowLoaded } = levelTreeNode;\n if (checkStrategyIsChild && shallowLoaded) {\n levelTreeNode.children!.forEach((v) => {\n if (!v.disabled && !v.isLeaf && v.shallowLoaded && syntheticCheckedKeySet.has(v.key)) {\n syntheticCheckedKeySet.delete(v.key);\n }\n });\n }\n if (levelTreeNode.disabled || !shallowLoaded) {\n continue;\n }\n let fullyChecked = true;\n let partialChecked = false;\n let allDisabled = true;\n // it is shallow loaded, so `children` must exist\n for (const childNode of levelTreeNode.children as Array<TreeNode<R, G, I>>) {\n const childKey = childNode.key;\n if (childNode.disabled) continue;\n if (allDisabled) allDisabled = false;\n if (syntheticCheckedKeySet.has(childKey)) {\n partialChecked = true;\n } else if (syntheticIndeterminateKeySet.has(childKey)) {\n partialChecked = true;\n fullyChecked = false;\n break;\n } else {\n fullyChecked = false;\n if (partialChecked) {\n break;\n }\n }\n }\n if (fullyChecked && !allDisabled) {\n if (checkStrategyIsParent) {\n levelTreeNode.children!.forEach((v) => {\n if (!v.disabled && syntheticCheckedKeySet.has(v.key)) {\n syntheticCheckedKeySet.delete(v.key);\n }\n });\n }\n syntheticCheckedKeySet.add(levelTreeNodeKey);\n } else if (partialChecked) {\n syntheticIndeterminateKeySet.add(levelTreeNodeKey);\n }\n if (levelIsZero && checkStrategyIsChild && syntheticCheckedKeySet.has(levelTreeNodeKey)) {\n syntheticCheckedKeySet.delete(levelTreeNodeKey);\n }\n }\n }\n return {\n checkedKeys: Array.from(syntheticCheckedKeySet),\n indeterminateKeys: Array.from(syntheticIndeterminateKeySet),\n };\n}\n\n// unchecking is safe when doing cascade uncheck in async mode\n/**\n * 计算扩展选中 key 集合:把每个选中节点连同其可达子孙并入集合,遇 disabled 子树停止下钻;\n * 子树未完全加载时,勾选流程抛出 SubtreeNotLoadedError,取消勾选流程安全截断。\n * @param checkedKeys - 当前选中的节点 key 列表\n * @param treeMate - 树 mate 实例,提供节点映射与 getChildren\n * @param isUnchecking - 是否处于取消勾选流程,决定未加载子树的处理方式\n * @returns 含全部级联选中节点的 key 集合\n */\nexport function getExtendedCheckedKeySet<R, G, I>(\n checkedKeys: Key[],\n treeMate: TreeMate<R, G, I>,\n isUnchecking: boolean = false,\n): Set<Key> {\n const { treeNodeMap, getChildren } = treeMate;\n const visitedKeySet: Set<Key> = new Set();\n const extendedKeySet: Set<Key> = new Set(checkedKeys);\n checkedKeys.forEach((checkedKey) => {\n const checkedTreeNode = treeNodeMap.get(checkedKey);\n if (checkedTreeNode !== undefined) {\n traverseWithCb(checkedTreeNode, (treeNode) => {\n if (treeNode.disabled) {\n return TRAVERSE_COMMAND.STOP;\n }\n const { key } = treeNode;\n if (visitedKeySet.has(key)) return;\n visitedKeySet.add(key);\n // Adding keys before loaded check is okay, since if not valid error\n // would be thrown\n extendedKeySet.add(key);\n if (isExpilicitlyNotLoaded(treeNode.rawNode, getChildren)) {\n if (isUnchecking) {\n return TRAVERSE_COMMAND.STOP;\n } else {\n throw new SubtreeNotLoadedError();\n }\n }\n });\n }\n });\n return extendedKeySet;\n}\n"
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
"path": "tree-shared/contains.ts",
|
|
23
23
|
"type": "registry:lib",
|
|
24
24
|
"target": "components/ui/tree-shared/contains.ts",
|
|
25
|
-
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:无实质改动。\n */\nimport type { TreeNode } from \"./interface\";\n\nexport function contains<R, G, I>(\n parent: TreeNode<R, G, I>,\n child: TreeNode<R, G, I> | null | undefined,\n): boolean {\n const parentKey = parent.key;\n while (child) {\n if (child.key === parentKey) return true;\n child = child.parent as any;\n }\n return false;\n}\n"
|
|
25
|
+
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:无实质改动。\n */\nimport type { TreeNode } from \"./interface\";\n\n/**\n * 判断 child 是否为 parent 的后代(含自身),沿父链逐级上溯比对 key。\n * @param parent - 祖先节点\n * @param child - 待判定的节点,可为 null 或 undefined\n * @returns child 位于 parent 子树内(含相等)时返回 true\n */\nexport function contains<R, G, I>(\n parent: TreeNode<R, G, I>,\n child: TreeNode<R, G, I> | null | undefined,\n): boolean {\n const parentKey = parent.key;\n while (child) {\n if (child.key === parentKey) return true;\n child = child.parent as any;\n }\n return false;\n}\n"
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
"path": "tree-shared/create.ts",
|
|
29
29
|
"type": "registry:lib",
|
|
30
30
|
"target": "components/ui/tree-shared/create.ts",
|
|
31
|
-
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:process.env.NODE_ENV 守卫替换为 import.meta.env?.DEV。\n */\nimport type {\n CheckOptions,\n GetChildren,\n GetNonLeafKeysOptions,\n GetPathOptions,\n GetPrevNextOptions,\n InputMergedKeys,\n Key,\n LevelTreeNodeMap,\n RawNode,\n TreeMate,\n TreeMateOptions,\n TreeNode,\n TreeNodeMap,\n} from \"./interface\";\nimport { getCheckedKeys } from \"./check\";\nimport {\n defaultGetChildren,\n defaultGetKey,\n getNonLeafKeys,\n isDisabled,\n isGroup,\n isIgnored,\n isLeaf,\n isNodeInvalid,\n isShallowLoaded,\n toArray,\n unwrapCheckedKeys,\n unwrapIndeterminateKeys,\n} from \"./utils\";\nimport { getPath } from \"./path\";\nimport { getFirstAvailableNode, moveMethods } from \"./move\";\nimport { flatten } from \"./flatten\";\nimport { contains } from \"./contains\";\n\nfunction createTreeNodes<R, G, I>(\n rawNodes: Array<R | G | I>,\n treeNodeMap: TreeNodeMap<R, G, I>,\n levelTreeNodeMap: LevelTreeNodeMap<R, G, I>,\n nodeProto: any,\n getChildren: GetChildren<R, G, I>,\n parent: TreeNode<R, G> | null = null,\n level: number = 0,\n): Array<TreeNode<R, G, I>> {\n const treeNodes: Array<TreeNode<R, G, I>> = [];\n rawNodes.forEach((rawNode, index) => {\n if (import.meta.env?.DEV && isNodeInvalid(rawNode, getChildren)) {\n console.error(\"[treemate]: node\", rawNode, \"is invalid\");\n }\n const treeNode: TreeNode<R, G, I> = Object.create(nodeProto);\n treeNode.rawNode = rawNode;\n treeNode.siblings = treeNodes;\n treeNode.level = level;\n treeNode.index = index;\n treeNode.isFirstChild = index === 0;\n treeNode.isLastChild = index + 1 === rawNodes.length;\n treeNode.parent = parent;\n if (!treeNode.ignored) {\n const rawChildren = getChildren(rawNode as R | G);\n if (Array.isArray(rawChildren)) {\n treeNode.children = createTreeNodes<R, G, I>(\n rawChildren,\n treeNodeMap,\n levelTreeNodeMap,\n nodeProto,\n getChildren,\n treeNode as unknown as TreeNode<R, G>,\n level + 1,\n );\n }\n }\n treeNodes.push(treeNode);\n treeNodeMap.set(treeNode.key, treeNode);\n if (!levelTreeNodeMap.has(level)) levelTreeNodeMap.set(level, []);\n levelTreeNodeMap.get(level)?.push(treeNode);\n });\n return treeNodes as any;\n}\n\nexport function createTreeMate<R = RawNode, G = R, I = R>(\n rawNodes: Array<R | G | I>,\n options: TreeMateOptions<R, G, I> = {},\n): TreeMate<R, G, I> {\n const treeNodeMap: TreeNodeMap<R, G, I> = new Map();\n const levelTreeNodeMap: LevelTreeNodeMap<R, G, I> = new Map();\n const {\n getDisabled = isDisabled,\n getIgnored = isIgnored,\n getIsGroup = isGroup,\n getKey = defaultGetKey,\n } = options;\n const _getChildren = options.getChildren ?? defaultGetChildren;\n const getChildren = options.ignoreEmptyChildren\n ? (node: R | I | G) => {\n const children = _getChildren(node);\n if (Array.isArray(children)) {\n if (!children.length) return null;\n return children;\n }\n return children;\n }\n : _getChildren;\n const nodeProto = Object.assign(\n {\n get key(): Key {\n // do not pass parent or related things to it\n // the key need to be specified explicitly\n return getKey((this as any).rawNode);\n },\n get disabled(): boolean {\n return getDisabled((this as any).rawNode);\n },\n get isGroup(): boolean {\n return getIsGroup((this as any).rawNode);\n },\n get isLeaf(): boolean {\n return isLeaf((this as any).rawNode, getChildren);\n },\n get shallowLoaded(): boolean {\n return isShallowLoaded((this as any).rawNode, getChildren);\n },\n get ignored(): boolean {\n return getIgnored((this as any).rawNode);\n },\n contains<R, G, I>(this: TreeNode<R, G, I>, node: TreeNode<R, G, I>): boolean {\n return contains(this, node);\n },\n },\n moveMethods,\n );\n\n const treeNodes: Array<TreeNode<R, G, I>> = createTreeNodes<R, G, I>(\n rawNodes,\n treeNodeMap,\n levelTreeNodeMap,\n nodeProto,\n getChildren,\n );\n // get only raw node\n function getNode<T extends Key | null | undefined>(\n key: T,\n ): T extends null | undefined ? null : TreeNode<R>;\n function getNode(key: Key | null | undefined): TreeNode<R> | null {\n if (key === null || key === undefined) return null;\n const tmNode = treeNodeMap.get(key);\n if (tmNode && !tmNode.isGroup && !tmNode.ignored) {\n return tmNode as unknown as TreeNode<R>;\n }\n return null;\n }\n // get group & raw node, for internally usage\n function _getNode<T extends Key | null | undefined>(\n key: T,\n ): T extends null | undefined ? null : TreeNode<R, G>;\n function _getNode(key: Key | null | undefined): TreeNode<R, G> | null {\n if (key === null || key === undefined) return null;\n const tmNode = treeNodeMap.get(key);\n if (tmNode && !tmNode.ignored) {\n return tmNode as unknown as TreeNode<R, G>;\n }\n return null;\n }\n function getPrev<T extends Key | null | undefined>(\n key: T,\n options?: GetPrevNextOptions,\n ): T extends null | undefined ? null : TreeNode<R>;\n function getPrev(key: Key | null | undefined, options?: GetPrevNextOptions): TreeNode<R> | null {\n const node = _getNode(key);\n if (!node) return null;\n return node.getPrev(options);\n }\n function getNext<T extends Key | null | undefined>(\n key: T,\n options?: GetPrevNextOptions,\n ): T extends null | undefined ? null : TreeNode<R>;\n function getNext(key: Key | null | undefined, options?: GetPrevNextOptions): TreeNode<R> | null {\n const node = _getNode(key);\n if (!node) return null;\n return node.getNext(options);\n }\n function getParent<T extends Key | null | undefined>(\n key: T,\n ): T extends null | undefined ? null : TreeNode<R>;\n function getParent(key: Key | null | undefined): TreeNode<R> | null {\n const node = _getNode(key);\n if (!node) return null;\n return node.getParent();\n }\n function getChild<T extends Key | null | undefined>(\n key: T,\n ): T extends null | undefined ? null : TreeNode<R>;\n function getChild(key: Key | null | undefined): TreeNode<R> | null {\n const node = _getNode(key);\n if (!node) return null;\n return node.getChild();\n }\n const treemate: TreeMate<R, G, I> = {\n treeNodes,\n treeNodeMap,\n levelTreeNodeMap,\n maxLevel: Math.max(...levelTreeNodeMap.keys()),\n getChildren,\n getFlattenedNodes(expandedKeys?: Key[]) {\n return flatten(treeNodes, expandedKeys);\n },\n getNode,\n getPrev,\n getNext,\n getParent,\n getChild,\n getFirstAvailableNode() {\n return getFirstAvailableNode(treeNodes);\n },\n getPath<T extends boolean>(key: Key | null | undefined, options: GetPathOptions<T> = {}) {\n return getPath<R, G, I, T>(key, options, treemate);\n },\n getCheckedKeys(\n checkedKeys: Key[] | InputMergedKeys | null | undefined,\n options: CheckOptions = {},\n ) {\n const { cascade = true, leafOnly = false, checkStrategy = \"all\" } = options;\n return getCheckedKeys(\n {\n checkedKeys: unwrapCheckedKeys(checkedKeys),\n indeterminateKeys: unwrapIndeterminateKeys(checkedKeys),\n cascade,\n leafOnly,\n checkStrategy,\n },\n treemate,\n );\n },\n check(\n keysToCheck: Key | Key[] | null | undefined,\n checkedKeys: Key[] | InputMergedKeys,\n options: CheckOptions = {},\n ) {\n const { cascade = true, leafOnly = false, checkStrategy = \"all\" } = options;\n return getCheckedKeys(\n {\n checkedKeys: unwrapCheckedKeys(checkedKeys),\n indeterminateKeys: unwrapIndeterminateKeys(checkedKeys),\n keysToCheck:\n keysToCheck === undefined || keysToCheck === null ? [] : toArray(keysToCheck),\n cascade,\n leafOnly,\n checkStrategy,\n },\n treemate,\n );\n },\n uncheck(\n keysToUncheck: Key | Key[] | null | undefined,\n checkedKeys: Key[] | InputMergedKeys,\n options: CheckOptions = {},\n ) {\n const { cascade = true, leafOnly = false, checkStrategy = \"all\" } = options;\n return getCheckedKeys(\n {\n checkedKeys: unwrapCheckedKeys(checkedKeys),\n indeterminateKeys: unwrapIndeterminateKeys(checkedKeys),\n keysToUncheck:\n keysToUncheck === null || keysToUncheck === undefined ? [] : toArray(keysToUncheck),\n cascade,\n leafOnly,\n checkStrategy,\n },\n treemate,\n );\n },\n getNonLeafKeys(options: GetNonLeafKeysOptions = {}) {\n return getNonLeafKeys(treeNodes, options);\n },\n };\n return treemate;\n}\n"
|
|
31
|
+
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:process.env.NODE_ENV 守卫替换为 import.meta.env?.DEV。\n */\nimport type {\n CheckOptions,\n GetChildren,\n GetNonLeafKeysOptions,\n GetPathOptions,\n GetPrevNextOptions,\n InputMergedKeys,\n Key,\n LevelTreeNodeMap,\n RawNode,\n TreeMate,\n TreeMateOptions,\n TreeNode,\n TreeNodeMap,\n} from \"./interface\";\nimport { getCheckedKeys } from \"./check\";\nimport {\n defaultGetChildren,\n defaultGetKey,\n getNonLeafKeys,\n isDisabled,\n isGroup,\n isIgnored,\n isLeaf,\n isNodeInvalid,\n isShallowLoaded,\n toArray,\n unwrapCheckedKeys,\n unwrapIndeterminateKeys,\n} from \"./utils\";\nimport { getPath } from \"./path\";\nimport { getFirstAvailableNode, moveMethods } from \"./move\";\nimport { flatten } from \"./flatten\";\nimport { contains } from \"./contains\";\n\n/**\n * 递归构建树节点:以 nodeProto 为原型创建实例,回填 siblings/level/index/父子\n * 等结构信息,并把每个节点登记进 treeNodeMap 与 levelTreeNodeMap。\n * @param rawNodes - 当前层级的原始节点数组\n * @param treeNodeMap - key → 节点 的全量映射(原地写入)\n * @param levelTreeNodeMap - 层级 → 该层节点列表 的映射(原地写入)\n * @param nodeProto - 节点实例共享的原型(惰性 getter 与移动方法)\n * @param getChildren - 取子节点的函数\n * @param parent - 父节点;根层调用时为 null\n * @param level - 当前层级,根为 0\n * @returns 当前层级构建好的节点数组\n */\nfunction createTreeNodes<R, G, I>(\n rawNodes: Array<R | G | I>,\n treeNodeMap: TreeNodeMap<R, G, I>,\n levelTreeNodeMap: LevelTreeNodeMap<R, G, I>,\n nodeProto: any,\n getChildren: GetChildren<R, G, I>,\n parent: TreeNode<R, G> | null = null,\n level: number = 0,\n): Array<TreeNode<R, G, I>> {\n const treeNodes: Array<TreeNode<R, G, I>> = [];\n rawNodes.forEach((rawNode, index) => {\n if (import.meta.env?.DEV && isNodeInvalid(rawNode, getChildren)) {\n console.error(\"[treemate]: node\", rawNode, \"is invalid\");\n }\n const treeNode: TreeNode<R, G, I> = Object.create(nodeProto);\n treeNode.rawNode = rawNode;\n treeNode.siblings = treeNodes;\n treeNode.level = level;\n treeNode.index = index;\n treeNode.isFirstChild = index === 0;\n treeNode.isLastChild = index + 1 === rawNodes.length;\n treeNode.parent = parent;\n if (!treeNode.ignored) {\n const rawChildren = getChildren(rawNode as R | G);\n if (Array.isArray(rawChildren)) {\n treeNode.children = createTreeNodes<R, G, I>(\n rawChildren,\n treeNodeMap,\n levelTreeNodeMap,\n nodeProto,\n getChildren,\n treeNode as unknown as TreeNode<R, G>,\n level + 1,\n );\n }\n }\n treeNodes.push(treeNode);\n treeNodeMap.set(treeNode.key, treeNode);\n if (!levelTreeNodeMap.has(level)) levelTreeNodeMap.set(level, []);\n levelTreeNodeMap.get(level)?.push(treeNode);\n });\n return treeNodes as any;\n}\n\n/**\n * 创建 TreeMate 实例:以 options 覆盖默认的取 key/子节点/禁用等策略,构建共享节点原型\n * (惰性 getter 与移动、contains 方法),并暴露节点查询、路径、展开拍平与勾选级联计算等 API。\n * @param rawNodes - 原始节点树\n * @param options - 自定义策略(getKey/getChildren/getDisabled/getIgnored/getIsGroup、\n * ignoreEmptyChildren 等);缺省走默认实现\n * @returns TreeMate 实例\n */\nexport function createTreeMate<R = RawNode, G = R, I = R>(\n rawNodes: Array<R | G | I>,\n options: TreeMateOptions<R, G, I> = {},\n): TreeMate<R, G, I> {\n const treeNodeMap: TreeNodeMap<R, G, I> = new Map();\n const levelTreeNodeMap: LevelTreeNodeMap<R, G, I> = new Map();\n const {\n getDisabled = isDisabled,\n getIgnored = isIgnored,\n getIsGroup = isGroup,\n getKey = defaultGetKey,\n } = options;\n const _getChildren = options.getChildren ?? defaultGetChildren;\n const getChildren = options.ignoreEmptyChildren\n ? (node: R | I | G) => {\n const children = _getChildren(node);\n if (Array.isArray(children)) {\n if (!children.length) return null;\n return children;\n }\n return children;\n }\n : _getChildren;\n const nodeProto = Object.assign(\n {\n get key(): Key {\n // do not pass parent or related things to it\n // the key need to be specified explicitly\n return getKey((this as any).rawNode);\n },\n get disabled(): boolean {\n return getDisabled((this as any).rawNode);\n },\n get isGroup(): boolean {\n return getIsGroup((this as any).rawNode);\n },\n get isLeaf(): boolean {\n return isLeaf((this as any).rawNode, getChildren);\n },\n get shallowLoaded(): boolean {\n return isShallowLoaded((this as any).rawNode, getChildren);\n },\n get ignored(): boolean {\n return getIgnored((this as any).rawNode);\n },\n contains<R, G, I>(this: TreeNode<R, G, I>, node: TreeNode<R, G, I>): boolean {\n return contains(this, node);\n },\n },\n moveMethods,\n );\n\n const treeNodes: Array<TreeNode<R, G, I>> = createTreeNodes<R, G, I>(\n rawNodes,\n treeNodeMap,\n levelTreeNodeMap,\n nodeProto,\n getChildren,\n );\n // get only raw node\n /**\n * 按 key 获取节点,仅返回非 group、非 ignored 的普通节点。\n * @param key - 节点 key;null/undefined 返回 null\n * @returns 对应节点;不存在或不可用时返回 null\n */\n function getNode<T extends Key | null | undefined>(\n key: T,\n ): T extends null | undefined ? null : TreeNode<R>;\n function getNode(key: Key | null | undefined): TreeNode<R> | null {\n if (key === null || key === undefined) return null;\n const tmNode = treeNodeMap.get(key);\n if (tmNode && !tmNode.isGroup && !tmNode.ignored) {\n return tmNode as unknown as TreeNode<R>;\n }\n return null;\n }\n // get group & raw node, for internally usage\n /**\n * 按 key 获取节点(含 group 节点,供内部移动/路径逻辑使用)。\n * @param key - 节点 key;null/undefined 返回 null\n * @returns 对应节点;不存在或被忽略时返回 null\n */\n function _getNode<T extends Key | null | undefined>(\n key: T,\n ): T extends null | undefined ? null : TreeNode<R, G>;\n function _getNode(key: Key | null | undefined): TreeNode<R, G> | null {\n if (key === null || key === undefined) return null;\n const tmNode = treeNodeMap.get(key);\n if (tmNode && !tmNode.ignored) {\n return tmNode as unknown as TreeNode<R, G>;\n }\n return null;\n }\n /**\n * 按 key 获取相邻的前一个可用节点。\n * @param key - 节点 key;null/undefined 返回 null\n * @param options - 移动选项\n * @returns 前一个可用节点;无入参对应节点或无相邻节点时返回 null\n */\n function getPrev<T extends Key | null | undefined>(\n key: T,\n options?: GetPrevNextOptions,\n ): T extends null | undefined ? null : TreeNode<R>;\n function getPrev(key: Key | null | undefined, options?: GetPrevNextOptions): TreeNode<R> | null {\n const node = _getNode(key);\n if (!node) return null;\n return node.getPrev(options);\n }\n /**\n * 按 key 获取相邻的下一个可用节点。\n * @param key - 节点 key;null/undefined 返回 null\n * @param options - 移动选项\n * @returns 下一个可用节点;无入参对应节点或无相邻节点时返回 null\n */\n function getNext<T extends Key | null | undefined>(\n key: T,\n options?: GetPrevNextOptions,\n ): T extends null | undefined ? null : TreeNode<R>;\n function getNext(key: Key | null | undefined, options?: GetPrevNextOptions): TreeNode<R> | null {\n const node = _getNode(key);\n if (!node) return null;\n return node.getNext(options);\n }\n /**\n * 按 key 获取父节点(跳过 group 节点)。\n * @param key - 节点 key;null/undefined 返回 null\n * @returns 父节点;无入参对应节点或已到根时返回 null\n */\n function getParent<T extends Key | null | undefined>(\n key: T,\n ): T extends null | undefined ? null : TreeNode<R>;\n function getParent(key: Key | null | undefined): TreeNode<R> | null {\n const node = _getNode(key);\n if (!node) return null;\n return node.getParent();\n }\n /**\n * 按 key 获取第一个可用子节点。\n * @param key - 节点 key;null/undefined 返回 null\n * @returns 第一个可用子节点;无入参对应节点或无子节点时返回 null\n */\n function getChild<T extends Key | null | undefined>(\n key: T,\n ): T extends null | undefined ? null : TreeNode<R>;\n function getChild(key: Key | null | undefined): TreeNode<R> | null {\n const node = _getNode(key);\n if (!node) return null;\n return node.getChild();\n }\n const treemate: TreeMate<R, G, I> = {\n treeNodes,\n treeNodeMap,\n levelTreeNodeMap,\n maxLevel: Math.max(...levelTreeNodeMap.keys()),\n getChildren,\n getFlattenedNodes(expandedKeys?: Key[]) {\n return flatten(treeNodes, expandedKeys);\n },\n getNode,\n getPrev,\n getNext,\n getParent,\n getChild,\n getFirstAvailableNode() {\n return getFirstAvailableNode(treeNodes);\n },\n getPath<T extends boolean>(key: Key | null | undefined, options: GetPathOptions<T> = {}) {\n return getPath<R, G, I, T>(key, options, treemate);\n },\n getCheckedKeys(\n checkedKeys: Key[] | InputMergedKeys | null | undefined,\n options: CheckOptions = {},\n ) {\n const { cascade = true, leafOnly = false, checkStrategy = \"all\" } = options;\n return getCheckedKeys(\n {\n checkedKeys: unwrapCheckedKeys(checkedKeys),\n indeterminateKeys: unwrapIndeterminateKeys(checkedKeys),\n cascade,\n leafOnly,\n checkStrategy,\n },\n treemate,\n );\n },\n check(\n keysToCheck: Key | Key[] | null | undefined,\n checkedKeys: Key[] | InputMergedKeys,\n options: CheckOptions = {},\n ) {\n const { cascade = true, leafOnly = false, checkStrategy = \"all\" } = options;\n return getCheckedKeys(\n {\n checkedKeys: unwrapCheckedKeys(checkedKeys),\n indeterminateKeys: unwrapIndeterminateKeys(checkedKeys),\n keysToCheck:\n keysToCheck === undefined || keysToCheck === null ? [] : toArray(keysToCheck),\n cascade,\n leafOnly,\n checkStrategy,\n },\n treemate,\n );\n },\n uncheck(\n keysToUncheck: Key | Key[] | null | undefined,\n checkedKeys: Key[] | InputMergedKeys,\n options: CheckOptions = {},\n ) {\n const { cascade = true, leafOnly = false, checkStrategy = \"all\" } = options;\n return getCheckedKeys(\n {\n checkedKeys: unwrapCheckedKeys(checkedKeys),\n indeterminateKeys: unwrapIndeterminateKeys(checkedKeys),\n keysToUncheck:\n keysToUncheck === null || keysToUncheck === undefined ? [] : toArray(keysToUncheck),\n cascade,\n leafOnly,\n checkStrategy,\n },\n treemate,\n );\n },\n getNonLeafKeys(options: GetNonLeafKeysOptions = {}) {\n return getNonLeafKeys(treeNodes, options);\n },\n };\n return treemate;\n}\n"
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
34
|
"path": "tree-shared/flatten.ts",
|
|
35
35
|
"type": "registry:lib",
|
|
36
36
|
"target": "components/ui/tree-shared/flatten.ts",
|
|
37
|
-
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:无实质改动。\n */\nimport type { Key, TreeNode } from \"./interface\";\n\nexport function flatten<R, G, I>(\n treeNodes: Array<TreeNode<R, G, I>>,\n expandedKeys?: Key[],\n): Array<TreeNode<R, G, I>> {\n const expandedKeySet = expandedKeys ? new Set<Key>(expandedKeys) : undefined;\n const flattenedNodes: Array<TreeNode<R, G, I>> = [];\n function traverse(treeNodes: Array<TreeNode<R, G, I>>): void {\n treeNodes.forEach((treeNode) => {\n flattenedNodes.push(treeNode);\n if (treeNode.isLeaf || !treeNode.children || treeNode.ignored) return;\n if (treeNode.isGroup) {\n // group node shouldn't be expanded\n traverse(treeNode.children);\n } else if (\n // normal non-leaf node\n expandedKeySet === undefined ||\n expandedKeySet.has(treeNode.key)\n ) {\n traverse(treeNode.children);\n }\n });\n }\n traverse(treeNodes);\n return flattenedNodes;\n}\n"
|
|
37
|
+
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:无实质改动。\n */\nimport type { Key, TreeNode } from \"./interface\";\n\n/**\n * 按展开状态把节点树拍平为一维列表:group 节点总是下钻;普通节点仅在\n * 未提供 expandedKeys 或其 key 在展开集合内时下钻;ignored 节点不下钻。\n * @param treeNodes - 待拍平的节点树\n * @param expandedKeys - 已展开节点的 key 列表;缺省视为全部展开\n * @returns 深度优先顺序的一维节点列表\n */\nexport function flatten<R, G, I>(\n treeNodes: Array<TreeNode<R, G, I>>,\n expandedKeys?: Key[],\n): Array<TreeNode<R, G, I>> {\n const expandedKeySet = expandedKeys ? new Set<Key>(expandedKeys) : undefined;\n const flattenedNodes: Array<TreeNode<R, G, I>> = [];\n /**\n * 深度优先收集当前层节点并按展开状态决定是否下钻。\n * @param treeNodes - 当前层的节点列表\n * @returns 无返回值\n */\n function traverse(treeNodes: Array<TreeNode<R, G, I>>): void {\n treeNodes.forEach((treeNode) => {\n flattenedNodes.push(treeNode);\n if (treeNode.isLeaf || !treeNode.children || treeNode.ignored) return;\n if (treeNode.isGroup) {\n // group node shouldn't be expanded\n traverse(treeNode.children);\n } else if (\n // normal non-leaf node\n expandedKeySet === undefined ||\n expandedKeySet.has(treeNode.key)\n ) {\n traverse(treeNode.children);\n }\n });\n }\n traverse(treeNodes);\n return flattenedNodes;\n}\n"
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
"path": "tree-shared/index.ts",
|
|
@@ -52,19 +52,19 @@
|
|
|
52
52
|
"path": "tree-shared/keyboard.ts",
|
|
53
53
|
"type": "registry:lib",
|
|
54
54
|
"target": "components/ui/tree-shared/keyboard.ts",
|
|
55
|
-
"content": "/*!\n * 树形键盘游标移动(本仓库自研,供 TreeSelect / Cascader 面板共用)。\n */\n\nimport type { Key, RawNode, TreeNode } from \"./interface\";\n\nexport type MoveKey = \"ArrowDown\" | \"ArrowUp\" | \"Home\" | \"End\";\n\n/**\n * 计算键盘移动后的活动节点 key。\n * - 仅在非 disabled 节点间移动;loop 默认 true(末尾循环回首行)。\n * - activeKey 为 null 或不在候选序列时,ArrowDown 从首行开始、ArrowUp 从末行开始。\n */\nexport function nextActiveKey<R = RawNode, G = R, I = R>(\n flattened: Array<TreeNode<R, G, I>>,\n activeKey: Key | null,\n key: MoveKey,\n options?: { loop?: boolean },\n): Key | null {\n const loop = options?.loop ?? true;\n const candidates = flattened.filter((n) => !n.disabled);\n if (candidates.length === 0) return null;\n const found = activeKey === null ? -1 : candidates.findIndex((n) => n.key === activeKey);\n switch (key) {\n case \"Home\":\n return candidates[0]!.key;\n case \"End\":\n return candidates[candidates.length - 1]!.key;\n case \"ArrowDown\": {\n if (found === -1) return candidates[0]!.key;\n const nextIndex = found + 1;\n if (nextIndex >= candidates.length) {\n return loop ? candidates[0]!.key : candidates[found]!.key;\n }\n return candidates[nextIndex]!.key;\n }\n case \"ArrowUp\": {\n if (found === -1) return candidates[candidates.length - 1]!.key;\n const prevIndex = found - 1;\n if (prevIndex < 0) {\n return loop ? candidates[candidates.length - 1]!.key : candidates[0]!.key;\n }\n return candidates[prevIndex]!.key;\n }\n }\n}\n"
|
|
55
|
+
"content": "/*!\n * 树形键盘游标移动(本仓库自研,供 TreeSelect / Cascader 面板共用)。\n */\n\nimport type { Key, RawNode, TreeNode } from \"./interface\";\n\nexport type MoveKey = \"ArrowDown\" | \"ArrowUp\" | \"Home\" | \"End\";\n\n/**\n * 计算键盘移动后的活动节点 key。\n * - 仅在非 disabled 节点间移动;loop 默认 true(末尾循环回首行)。\n * - activeKey 为 null 或不在候选序列时,ArrowDown 从首行开始、ArrowUp 从末行开始。\n * @param flattened - 已展开的扁平节点列表\n * @param activeKey - 当前活动节点 key;null 表示尚无活动节点\n * @param key - 本次键盘操作(ArrowDown/ArrowUp/Home/End)\n * @param options - 选项;loop 控制到端点后是否循环绕回(默认 true)\n * @returns 移动后的活动节点 key;无可用候选节点时返回 null\n */\nexport function nextActiveKey<R = RawNode, G = R, I = R>(\n flattened: Array<TreeNode<R, G, I>>,\n activeKey: Key | null,\n key: MoveKey,\n options?: { loop?: boolean },\n): Key | null {\n const loop = options?.loop ?? true;\n const candidates = flattened.filter((n) => !n.disabled);\n if (candidates.length === 0) return null;\n const found = activeKey === null ? -1 : candidates.findIndex((n) => n.key === activeKey);\n switch (key) {\n case \"Home\":\n return candidates[0]!.key;\n case \"End\":\n return candidates[candidates.length - 1]!.key;\n case \"ArrowDown\": {\n if (found === -1) return candidates[0]!.key;\n const nextIndex = found + 1;\n if (nextIndex >= candidates.length) {\n return loop ? candidates[0]!.key : candidates[found]!.key;\n }\n return candidates[nextIndex]!.key;\n }\n case \"ArrowUp\": {\n if (found === -1) return candidates[candidates.length - 1]!.key;\n const prevIndex = found - 1;\n if (prevIndex < 0) {\n return loop ? candidates[candidates.length - 1]!.key : candidates[0]!.key;\n }\n return candidates[prevIndex]!.key;\n }\n }\n}\n"
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
"path": "tree-shared/move.ts",
|
|
59
59
|
"type": "registry:lib",
|
|
60
60
|
"target": "components/ui/tree-shared/move.ts",
|
|
61
|
-
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:无实质改动。\n */\nimport type { GetPrevNextOptions, TreeNode } from \"./interface\";\n\nexport function getFirstAvailableNode<R, G, I>(\n nodes: Array<TreeNode<R, G, I>>,\n): TreeNode<R> | null {\n if (nodes.length === 0) return null;\n const node = nodes[0]!;\n if (node.isGroup || node.ignored || node.disabled) {\n return node.getNext();\n }\n return node as unknown as TreeNode<R>;\n}\n\nfunction rawGetNext(node: TreeNode, loop: boolean): TreeNode | null {\n const sibs = node.siblings;\n const l = sibs.length;\n const { index } = node;\n if (loop) {\n return sibs[(index + 1) % l]!;\n } else {\n if (index === sibs.length - 1) return null;\n return sibs[index + 1]!;\n }\n}\n\nfunction move(\n fromNode: TreeNode,\n dir: \"prev\" | \"next\",\n { loop = false, includeDisabled = false }: GetPrevNextOptions = {},\n): TreeNode | null {\n const iterate = dir === \"prev\" ? rawGetPrev : rawGetNext;\n const getChildOptions = {\n reverse: dir === \"prev\",\n };\n let meet = false;\n let endNode: TreeNode | null = null;\n function traverse(node: TreeNode | null): void {\n if (node === null) return;\n if (node === fromNode) {\n if (!meet) {\n meet = true;\n } else if (!fromNode.disabled && !fromNode.isGroup) {\n endNode = fromNode;\n return;\n }\n } else {\n if ((!node.disabled || includeDisabled) && !node.ignored && !node.isGroup) {\n endNode = node;\n return;\n }\n }\n if (node.isGroup) {\n const child = getChild(node, getChildOptions);\n if (child !== null) {\n endNode = child;\n } else {\n traverse(iterate(node, loop));\n }\n } else {\n const nextNode = iterate(node, false);\n if (nextNode !== null) {\n traverse(nextNode);\n } else {\n const parent = rawGetParent(node);\n if (parent?.isGroup) {\n traverse(iterate(parent, loop));\n } else if (loop) {\n traverse(iterate(node, true));\n }\n }\n }\n }\n traverse(fromNode);\n return endNode;\n}\n\nfunction rawGetPrev(node: TreeNode, loop: boolean): TreeNode | null {\n const sibs = node.siblings;\n const l = sibs.length;\n const { index } = node;\n if (loop) {\n return sibs[(index - 1 + l) % l]!;\n } else {\n if (index === 0) return null;\n return sibs[index - 1]!;\n }\n}\n\nfunction rawGetParent(node: TreeNode): TreeNode | null {\n return node.parent;\n}\n\nfunction getChild(node: TreeNode, options: { reverse?: boolean } = {}): TreeNode | null {\n const { reverse = false } = options;\n const { children } = node;\n if (children) {\n const { length } = children;\n const start = reverse ? length - 1 : 0;\n const end = reverse ? -1 : length;\n const delta = reverse ? -1 : 1;\n for (let i = start; i !== end; i += delta) {\n const child = children[i]!;\n if (!child.disabled && !child.ignored) {\n if (child.isGroup) {\n const childInGroup = getChild(child, options);\n if (childInGroup !== null) return childInGroup;\n } else {\n return child;\n }\n }\n }\n }\n return null;\n}\n\nexport const moveMethods: Pick<TreeNode, \"getChild\" | \"getNext\" | \"getParent\" | \"getPrev\"> = {\n getChild(this: TreeNode) {\n if (this.ignored) return null;\n return getChild(this);\n },\n getParent(this: TreeNode) {\n const { parent } = this;\n if (parent?.isGroup) {\n return parent.getParent();\n }\n return parent;\n },\n getNext(this: TreeNode, options: GetPrevNextOptions = {}) {\n return move(this, \"next\", options);\n },\n getPrev(this: TreeNode, options: GetPrevNextOptions = {}) {\n return move(this, \"prev\", options);\n },\n};\n"
|
|
61
|
+
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:无实质改动。\n */\nimport type { GetPrevNextOptions, TreeNode } from \"./interface\";\n\n/**\n * 返回树中第一个可用节点(非 group、非 ignored、非 disabled);\n * 首节点不可用时沿 getNext 继续向后找。\n * @param nodes - 顶层节点列表\n * @returns 首个可用节点;整树不可用时返回 null\n */\nexport function getFirstAvailableNode<R, G, I>(\n nodes: Array<TreeNode<R, G, I>>,\n): TreeNode<R> | null {\n if (nodes.length === 0) return null;\n const node = nodes[0]!;\n if (node.isGroup || node.ignored || node.disabled) {\n return node.getNext();\n }\n return node as unknown as TreeNode<R>;\n}\n\n/**\n * 取同级下一兄弟节点;loop 为 true 时越过末尾循环回首节点,否则返回 null。\n * @param node - 当前节点\n * @param loop - 是否循环绕回\n * @returns 下一兄弟节点或 null\n */\nfunction rawGetNext(node: TreeNode, loop: boolean): TreeNode | null {\n const sibs = node.siblings;\n const l = sibs.length;\n const { index } = node;\n if (loop) {\n return sibs[(index + 1) % l]!;\n } else {\n if (index === sibs.length - 1) return null;\n return sibs[index + 1]!;\n }\n}\n\n/**\n * 沿 dir 方向游标移动到下一个可用节点(非 group、非 ignored;disabled 需 includeDisabled),\n * 遇 group 节点下钻其子节点;loop 为 true 时绕树循环一周回到起点即以起点为结果。\n * @param fromNode - 起始节点\n * @param dir - 移动方向:prev 向前、next 向后\n * @param root0 - 移动选项对象(GetPrevNextOptions)\n * @param root0.loop - 到达端点后是否循环绕回\n * @param root0.includeDisabled - 是否把 disabled 节点纳入游标可达范围\n * @returns 目标节点;无可达节点时返回 null\n */\nfunction move(\n fromNode: TreeNode,\n dir: \"prev\" | \"next\",\n { loop = false, includeDisabled = false }: GetPrevNextOptions = {},\n): TreeNode | null {\n const iterate = dir === \"prev\" ? rawGetPrev : rawGetNext;\n const getChildOptions = {\n reverse: dir === \"prev\",\n };\n let meet = false;\n let endNode: TreeNode | null = null;\n /**\n * 沿方向游标遍历,记录第一个遇到的可用节点。\n * @param node - 当前游标节点\n * @returns 无返回值\n */\n function traverse(node: TreeNode | null): void {\n if (node === null) return;\n if (node === fromNode) {\n if (!meet) {\n meet = true;\n } else if (!fromNode.disabled && !fromNode.isGroup) {\n endNode = fromNode;\n return;\n }\n } else {\n if ((!node.disabled || includeDisabled) && !node.ignored && !node.isGroup) {\n endNode = node;\n return;\n }\n }\n if (node.isGroup) {\n const child = getChild(node, getChildOptions);\n if (child !== null) {\n endNode = child;\n } else {\n traverse(iterate(node, loop));\n }\n } else {\n const nextNode = iterate(node, false);\n if (nextNode !== null) {\n traverse(nextNode);\n } else {\n const parent = rawGetParent(node);\n if (parent?.isGroup) {\n traverse(iterate(parent, loop));\n } else if (loop) {\n traverse(iterate(node, true));\n }\n }\n }\n }\n traverse(fromNode);\n return endNode;\n}\n\n/**\n * 取同级上一兄弟节点;loop 为 true 时越过开头循环回尾节点,否则返回 null。\n * @param node - 当前节点\n * @param loop - 是否循环绕回\n * @returns 上一兄弟节点或 null\n */\nfunction rawGetPrev(node: TreeNode, loop: boolean): TreeNode | null {\n const sibs = node.siblings;\n const l = sibs.length;\n const { index } = node;\n if (loop) {\n return sibs[(index - 1 + l) % l]!;\n } else {\n if (index === 0) return null;\n return sibs[index - 1]!;\n }\n}\n\n/**\n * 取节点的直接父节点。\n * @param node - 当前节点\n * @returns 父节点;根节点返回 null\n */\nfunction rawGetParent(node: TreeNode): TreeNode | null {\n return node.parent;\n}\n\n/**\n * 取节点下第一个可用子节点(非 disabled、非 ignored,递归下钻 group);\n * reverse 为 true 时从末尾向前查找。\n * @param node - 父节点\n * @param options - 查找选项;reverse 表示从末尾向前查找\n * @returns 可用子节点;不存在时返回 null\n */\nfunction getChild(node: TreeNode, options: { reverse?: boolean } = {}): TreeNode | null {\n const { reverse = false } = options;\n const { children } = node;\n if (children) {\n const { length } = children;\n const start = reverse ? length - 1 : 0;\n const end = reverse ? -1 : length;\n const delta = reverse ? -1 : 1;\n for (let i = start; i !== end; i += delta) {\n const child = children[i]!;\n if (!child.disabled && !child.ignored) {\n if (child.isGroup) {\n const childInGroup = getChild(child, options);\n if (childInGroup !== null) return childInGroup;\n } else {\n return child;\n }\n }\n }\n }\n return null;\n}\n\nexport const moveMethods: Pick<TreeNode, \"getChild\" | \"getNext\" | \"getParent\" | \"getPrev\"> = {\n getChild(this: TreeNode) {\n if (this.ignored) return null;\n return getChild(this);\n },\n getParent(this: TreeNode) {\n const { parent } = this;\n if (parent?.isGroup) {\n return parent.getParent();\n }\n return parent;\n },\n getNext(this: TreeNode, options: GetPrevNextOptions = {}) {\n return move(this, \"next\", options);\n },\n getPrev(this: TreeNode, options: GetPrevNextOptions = {}) {\n return move(this, \"prev\", options);\n },\n};\n"
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
64
|
"path": "tree-shared/path.ts",
|
|
65
65
|
"type": "registry:lib",
|
|
66
66
|
"target": "components/ui/tree-shared/path.ts",
|
|
67
|
-
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:无实质改动。\n */\nimport type { GetPathOptions, Key, MergedPath, TreeMate, TreeNode } from \"./interface\";\n\nexport function getPath<R, G, I, T extends boolean>(\n key: Key | null | undefined,\n { includeGroup = false as any, includeSelf = true }: GetPathOptions<T>,\n treeMate: TreeMate<R, G, I>,\n): T extends true ? MergedPath<R, G> : MergedPath<R, R> {\n const treeNodeMap = treeMate.treeNodeMap;\n let treeNode = key === null || key === undefined ? null : (treeNodeMap.get(key) ?? null);\n const mergedPath: MergedPath<R, G> = {\n keyPath: [],\n treeNodePath: [],\n treeNode: treeNode as unknown as TreeNode<R, G> | null,\n };\n if (treeNode?.ignored) {\n mergedPath.treeNode = null;\n return mergedPath as any;\n }\n while (treeNode) {\n if (!treeNode.ignored && (includeGroup || !treeNode.isGroup)) {\n mergedPath.treeNodePath.push(treeNode as any);\n }\n treeNode = treeNode.parent as any;\n }\n mergedPath.treeNodePath.reverse();\n if (!includeSelf) mergedPath.treeNodePath.pop();\n mergedPath.keyPath = mergedPath.treeNodePath.map((treeNode) => treeNode.key);\n return mergedPath as any;\n}\n"
|
|
67
|
+
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:无实质改动。\n */\nimport type { GetPathOptions, Key, MergedPath, TreeMate, TreeNode } from \"./interface\";\n\n/**\n * 计算指定节点的路径信息:从目标节点沿父链上溯收集并反转,得到根到该节点的\n * keyPath 与 treeNodePath;ignored 节点返回空路径且 treeNode 为 null。\n * @param key - 目标节点 key;null/undefined 时返回空路径\n * @param root0 - 路径选项\n * @param root0.includeGroup - 是否在路径中包含 group 节点\n * @param root0.includeSelf - 是否在路径中包含自身节点\n * @param treeMate - 树 mate 实例,提供节点映射查询\n * @returns 合并后的路径对象(keyPath、treeNodePath 与 treeNode)\n */\nexport function getPath<R, G, I, T extends boolean>(\n key: Key | null | undefined,\n { includeGroup = false as any, includeSelf = true }: GetPathOptions<T>,\n treeMate: TreeMate<R, G, I>,\n): T extends true ? MergedPath<R, G> : MergedPath<R, R> {\n const treeNodeMap = treeMate.treeNodeMap;\n let treeNode = key === null || key === undefined ? null : (treeNodeMap.get(key) ?? null);\n const mergedPath: MergedPath<R, G> = {\n keyPath: [],\n treeNodePath: [],\n treeNode: treeNode as unknown as TreeNode<R, G> | null,\n };\n if (treeNode?.ignored) {\n mergedPath.treeNode = null;\n return mergedPath as any;\n }\n while (treeNode) {\n if (!treeNode.ignored && (includeGroup || !treeNode.isGroup)) {\n mergedPath.treeNodePath.push(treeNode as any);\n }\n treeNode = treeNode.parent as any;\n }\n mergedPath.treeNodePath.reverse();\n if (!includeSelf) mergedPath.treeNodePath.pop();\n mergedPath.keyPath = mergedPath.treeNodePath.map((treeNode) => treeNode.key);\n return mergedPath as any;\n}\n"
|
|
68
68
|
},
|
|
69
69
|
{
|
|
70
70
|
"path": "tree-shared/types.ts",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"path": "tree-shared/utils.ts",
|
|
77
77
|
"type": "registry:lib",
|
|
78
78
|
"target": "components/ui/tree-shared/utils.ts",
|
|
79
|
-
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:defaultGetChildren 返回类型同步 GetChildren 塌缩为 `unknown`(语义不变)。\n */\nimport type {\n GetChildren,\n GetNonLeafKeysOptions,\n InputMergedKeys,\n Key,\n RawNode,\n TreeNode,\n} from \"./interface\";\n\nexport function toArray<T>(arg: T): T extends any[] ? T : T[] {\n if (Array.isArray(arg)) return arg as any;\n return [arg] as any;\n}\n\n// Do not use enum for lint plugin has error\nexport const TRAVERSE_COMMAND = {\n STOP: \"STOP\",\n};\n\nexport function traverseWithCb<R, G, I>(\n treeNode: TreeNode<R, G, I>,\n callback: (treeNode: TreeNode<R, G, I>) => any,\n): void {\n const command = callback(treeNode);\n if (treeNode.children !== undefined && command !== TRAVERSE_COMMAND.STOP) {\n treeNode.children.forEach((childNode) => traverseWithCb(childNode, callback));\n }\n}\n\nexport function getNonLeafKeys<R, G, I>(\n treeNodes: Array<TreeNode<R, G, I>>,\n options: GetNonLeafKeysOptions = {},\n): Key[] {\n const { preserveGroup = false } = options;\n const keys: Key[] = [];\n const cb = preserveGroup\n ? (node: TreeNode<R, G, I>) => {\n if (!node.isLeaf) {\n keys.push(node.key);\n traverse(node.children as Array<TreeNode<R, G, I>>);\n }\n }\n : (node: TreeNode<R, G, I>) => {\n if (!node.isLeaf) {\n if (!node.isGroup) keys.push(node.key);\n traverse(node.children as Array<TreeNode<R, G, I>>);\n }\n };\n function traverse(nodes: Array<TreeNode<R, G, I>>): void {\n nodes.forEach(cb);\n }\n traverse(treeNodes);\n return keys;\n}\n\nexport function isLeaf<R = RawNode, G = R, I = R>(\n rawNode: R | G | I,\n getChildren: GetChildren<R, G, I>,\n): boolean {\n const { isLeaf } = rawNode as any;\n if (isLeaf !== undefined) return isLeaf;\n else if (!getChildren(rawNode)) return true;\n return false;\n}\n\nexport function defaultGetChildren<R, G, I>(node: R | G | I): unknown {\n return (node as any).children;\n}\n\nexport function defaultGetKey(node: unknown): Key {\n return (node as any).key;\n}\n\nexport function isIgnored(): boolean {\n return false;\n}\n\nexport function isShallowLoaded<R = RawNode, G = R, I = R>(\n rawNode: R,\n getChildren: GetChildren<R, G, I>,\n): boolean {\n const { isLeaf } = rawNode as any;\n if (isLeaf === false && !Array.isArray(getChildren(rawNode))) return false;\n return true;\n}\n\nexport function isDisabled(rawNode: RawNode): boolean {\n return rawNode.disabled === true;\n}\n\nexport function isExpilicitlyNotLoaded<R = RawNode, G = R, I = R>(\n rawNode: R | G | I,\n getChildren: GetChildren<R, G, I>,\n): boolean {\n return (rawNode as any).isLeaf === false && !Array.isArray(getChildren(rawNode));\n}\n\nexport function isNodeInvalid<R = RawNode, G = R, I = R>(\n rawNode: R | G | I,\n getChildren: GetChildren<R, G, I>,\n): boolean {\n if ((rawNode as any).isLeaf === true) {\n const children = getChildren(rawNode);\n if (Array.isArray(children) && children.length > 0) return true;\n }\n return false;\n}\n\nexport function unwrapCheckedKeys(result?: InputMergedKeys | Key[] | null): Key[] {\n if (result === undefined || result === null) return [];\n if (Array.isArray(result)) return result;\n return result.checkedKeys ?? [];\n}\n\nexport function unwrapIndeterminateKeys(result?: InputMergedKeys | Key[] | null): Key[] {\n if (result === undefined || result === null || Array.isArray(result)) {\n return [];\n }\n return result.indeterminateKeys ?? [];\n}\n\nexport function merge(originalKeys: Key[], keysToAdd: Key[]): Key[] {\n const set = new Set(originalKeys);\n keysToAdd.forEach((key) => {\n if (!set.has(key)) {\n set.add(key);\n }\n });\n return Array.from(set);\n}\n\nexport function minus(originalKeys: Key[], keysToRemove: Key[]): Key[] {\n const set = new Set(originalKeys);\n keysToRemove.forEach((key) => {\n if (set.has(key)) {\n set.delete(key);\n }\n });\n return Array.from(set);\n}\n\nexport function isGroup(rawNode: RawNode): boolean {\n return rawNode?.type === \"group\";\n}\n\nexport type IndexGetter = (key: Key) => number | null;\n\nexport function createIndexGetter<R, G, I>(treeNodes: Array<TreeNode<R, G, I>>): IndexGetter {\n const map = new Map<Key, number>();\n treeNodes.forEach((treeNode, i) => {\n map.set(treeNode.key, i);\n });\n return (key: Key) => map.get(key) ?? null;\n}\n"
|
|
79
|
+
"content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:defaultGetChildren 返回类型同步 GetChildren 塌缩为 `unknown`(语义不变)。\n */\nimport type {\n GetChildren,\n GetNonLeafKeysOptions,\n InputMergedKeys,\n Key,\n RawNode,\n TreeNode,\n} from \"./interface\";\n\n/**\n * 把任意值归一为数组:本身是数组则原样返回,否则包装为单元素数组。\n * @param arg - 任意输入值\n * @returns 数组形式的输入值\n */\nexport function toArray<T>(arg: T): T extends any[] ? T : T[] {\n if (Array.isArray(arg)) return arg as any;\n return [arg] as any;\n}\n\n// Do not use enum for lint plugin has error\nexport const TRAVERSE_COMMAND = {\n STOP: \"STOP\",\n};\n\n/**\n * 深度优先遍历节点子树,callback 返回 STOP 指令时终止该分支的继续下钻。\n * @param treeNode - 遍历起点节点\n * @param callback - 访问每个节点时执行的回调\n * @returns 无返回值\n */\nexport function traverseWithCb<R, G, I>(\n treeNode: TreeNode<R, G, I>,\n callback: (treeNode: TreeNode<R, G, I>) => any,\n): void {\n const command = callback(treeNode);\n if (treeNode.children !== undefined && command !== TRAVERSE_COMMAND.STOP) {\n treeNode.children.forEach((childNode) => traverseWithCb(childNode, callback));\n }\n}\n\n/**\n * 收集树中所有非叶子节点的 key;preserveGroup 为 true 时保留 group 节点,\n * 否则排除 group,仅返回普通父节点 key。\n * @param treeNodes - 待收集的节点树\n * @param options - 选项;preserveGroup 控制是否包含 group 节点\n * @returns 非叶子节点 key 列表\n */\nexport function getNonLeafKeys<R, G, I>(\n treeNodes: Array<TreeNode<R, G, I>>,\n options: GetNonLeafKeysOptions = {},\n): Key[] {\n const { preserveGroup = false } = options;\n const keys: Key[] = [];\n const cb = preserveGroup\n ? (node: TreeNode<R, G, I>) => {\n if (!node.isLeaf) {\n keys.push(node.key);\n traverse(node.children as Array<TreeNode<R, G, I>>);\n }\n }\n : (node: TreeNode<R, G, I>) => {\n if (!node.isLeaf) {\n if (!node.isGroup) keys.push(node.key);\n traverse(node.children as Array<TreeNode<R, G, I>>);\n }\n };\n /**\n * 用预设回调遍历当前层节点列表。\n * @param nodes - 当前层的节点列表\n * @returns 无返回值\n */\n function traverse(nodes: Array<TreeNode<R, G, I>>): void {\n nodes.forEach(cb);\n }\n traverse(treeNodes);\n return keys;\n}\n\n/**\n * 判断原始节点是否为叶子:显式 isLeaf 字段优先,否则以取不到子节点视为叶子。\n * @param rawNode - 原始节点数据\n * @param getChildren - 取子节点的函数\n * @returns 是否为叶子节点\n */\nexport function isLeaf<R = RawNode, G = R, I = R>(\n rawNode: R | G | I,\n getChildren: GetChildren<R, G, I>,\n): boolean {\n const { isLeaf } = rawNode as any;\n if (isLeaf !== undefined) return isLeaf;\n else if (!getChildren(rawNode)) return true;\n return false;\n}\n\n/**\n * 默认取子节点实现:读取节点数据的 children 字段。\n * @param node - 原始节点数据\n * @returns 子节点数组或 undefined\n */\nexport function defaultGetChildren<R, G, I>(node: R | G | I): unknown {\n return (node as any).children;\n}\n\n/**\n * 默认取 key 实现:读取节点数据的 key 字段。\n * @param node - 原始节点数据\n * @returns 节点 key\n */\nexport function defaultGetKey(node: unknown): Key {\n return (node as any).key;\n}\n\n/**\n * 默认的节点忽略判定:始终返回 false。\n * @returns 恒为 false\n */\nexport function isIgnored(): boolean {\n return false;\n}\n\n/**\n * 判断节点是否处于浅加载完成状态:显式 isLeaf=false 但取不到子节点数组时视为未加载,\n * 其余情况(含已加载)均视为完成。\n * @param rawNode - 原始节点数据\n * @param getChildren - 取子节点的函数\n * @returns 节点是否已浅加载\n */\nexport function isShallowLoaded<R = RawNode, G = R, I = R>(\n rawNode: R,\n getChildren: GetChildren<R, G, I>,\n): boolean {\n const { isLeaf } = rawNode as any;\n if (isLeaf === false && !Array.isArray(getChildren(rawNode))) return false;\n return true;\n}\n\n/**\n * 判断原始节点是否被禁用。\n * @param rawNode - 原始节点数据\n * @returns disabled === true 时返回 true\n */\nexport function isDisabled(rawNode: RawNode): boolean {\n return rawNode.disabled === true;\n}\n\n/**\n * 判断节点是否显式未加载:isLeaf === false 且 getChildren 未返回数组\n * (异步加载占位,子树尚未到位)。\n * @param rawNode - 原始节点数据\n * @param getChildren - 取子节点的函数\n * @returns 是否显式未加载\n */\nexport function isExpilicitlyNotLoaded<R = RawNode, G = R, I = R>(\n rawNode: R | G | I,\n getChildren: GetChildren<R, G, I>,\n): boolean {\n return (rawNode as any).isLeaf === false && !Array.isArray(getChildren(rawNode));\n}\n\n/**\n * 判断节点数据是否非法:声明 isLeaf === true 却仍返回非空子节点数组。\n * @param rawNode - 原始节点数据\n * @param getChildren - 取子节点的函数\n * @returns 数据非法时返回 true\n */\nexport function isNodeInvalid<R = RawNode, G = R, I = R>(\n rawNode: R | G | I,\n getChildren: GetChildren<R, G, I>,\n): boolean {\n if ((rawNode as any).isLeaf === true) {\n const children = getChildren(rawNode);\n if (Array.isArray(children) && children.length > 0) return true;\n }\n return false;\n}\n\n/**\n * 从勾选结果中取出选中 key 列表:兼容 key 数组直传与 merged 结果对象两种形态,\n * 空值返回空数组。\n * @param result - 勾选结果(key 数组、merged 对象或空值)\n * @returns 选中 key 数组\n */\nexport function unwrapCheckedKeys(result?: InputMergedKeys | Key[] | null): Key[] {\n if (result === undefined || result === null) return [];\n if (Array.isArray(result)) return result;\n return result.checkedKeys ?? [];\n}\n\n/**\n * 从勾选结果中取出半选 key 列表:仅 merged 结果对象包含该信息,\n * 数组与空值均返回空数组。\n * @param result - 勾选结果(key 数组、merged 对象或空值)\n * @returns 半选 key 数组\n */\nexport function unwrapIndeterminateKeys(result?: InputMergedKeys | Key[] | null): Key[] {\n if (result === undefined || result === null || Array.isArray(result)) {\n return [];\n }\n return result.indeterminateKeys ?? [];\n}\n\n/**\n * 求并集:把 keysToAdd 中不存在的 key 追加到 originalKeys,保持原有顺序。\n * @param originalKeys - 原始 key 列表\n * @param keysToAdd - 待追加的 key 列表\n * @returns 合并去重后的 key 列表\n */\nexport function merge(originalKeys: Key[], keysToAdd: Key[]): Key[] {\n const set = new Set(originalKeys);\n keysToAdd.forEach((key) => {\n if (!set.has(key)) {\n set.add(key);\n }\n });\n return Array.from(set);\n}\n\n/**\n * 求差集:从 originalKeys 中移除 keysToRemove 里出现的 key,保持原有顺序。\n * @param originalKeys - 原始 key 列表\n * @param keysToRemove - 待移除的 key 列表\n * @returns 移除后的 key 列表\n */\nexport function minus(originalKeys: Key[], keysToRemove: Key[]): Key[] {\n const set = new Set(originalKeys);\n keysToRemove.forEach((key) => {\n if (set.has(key)) {\n set.delete(key);\n }\n });\n return Array.from(set);\n}\n\n/**\n * 判断原始节点是否为 group 分组节点(type === \"group\")。\n * @param rawNode - 原始节点数据\n * @returns 是否 group 节点\n */\nexport function isGroup(rawNode: RawNode): boolean {\n return rawNode?.type === \"group\";\n}\n\nexport type IndexGetter = (key: Key) => number | null;\n\n/**\n * 构建扁平节点列表的 key → 下标查询器,用于 O(1) 定位节点在扁平序列中的位置。\n * @param treeNodes - 扁平节点列表\n * @returns 查询函数:返回 key 对应下标,未命中返回 null\n */\nexport function createIndexGetter<R, G, I>(treeNodes: Array<TreeNode<R, G, I>>): IndexGetter {\n const map = new Map<Key, number>();\n treeNodes.forEach((treeNode, i) => {\n map.set(treeNode.key, i);\n });\n return (key: Key) => map.get(key) ?? null;\n}\n"
|
|
80
80
|
}
|
|
81
81
|
]
|
|
82
82
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
3
|
"name": "utils",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.8",
|
|
5
5
|
"type": "registry:lib",
|
|
6
6
|
"description": "cn 类名合并工具(clsx + tailwind-merge)。",
|
|
7
7
|
"dependencies": ["clsx@^2.1.1", "tailwind-merge@^3.7.0", "class-variance-authority@^0.7.1"],
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"path": "lib/utils.ts",
|
|
11
11
|
"type": "registry:lib",
|
|
12
12
|
"target": "lib/utils.ts",
|
|
13
|
-
"content": "import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"
|
|
13
|
+
"content": "import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\n/**\n * 合并 Tailwind CSS 类名:clsx 组合条件类名,tailwind-merge 消解冲突规则。\n * @param inputs - 任意数量的类名值(字符串、数组或对象)\n * @returns 消解冲突后的类名字符串\n */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"
|
|
14
14
|
}
|
|
15
15
|
]
|
|
16
16
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
3
|
"name": "week-picker",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.8",
|
|
5
5
|
"type": "registry:ui",
|
|
6
6
|
"description": "周选择器:输入框 + 日历弹层,点任意可选日归一到所在周并整周高亮,值以 \"yyyy-MM-dd\"(所在周起始日)字符串受控;周起点跟随 locale(zh-CN 周一起始),输入框回显 \"start ~ end\"。",
|
|
7
7
|
"registryDependencies": ["utils", "date-shared", "calendar"],
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"path": "week-picker/WeekPicker.vue",
|
|
12
12
|
"type": "registry:component",
|
|
13
13
|
"target": "components/ui/week-picker/WeekPicker.vue",
|
|
14
|
-
"content": "<script setup lang=\"ts\">\nimport type { DateValue } from \"@ark-ui/vue/date-picker\";\nimport type { PickerPositioning } from \"../date-shared/positioning\";\nimport type { PropType } from \"vue\";\nimport { computed, provide } from \"vue\";\nimport { Calendar as TCalendar } from \"../calendar\";\nimport PickerShell from \"../date-shared/PickerShell.vue\";\nimport {\n CALENDAR_IN_PICKER,\n formatIsoWeek,\n parseIsoDate,\n weekStartOf,\n} from \"../date-shared/shared\";\nimport { usePickerBridge } from \"../date-shared/usePickerBridge\";\n\nconst props = defineProps({\n /** 受控值(\"yyyy-MM-dd\",语义=所在周起始日);undefined 走内部非受控,null 表示空 */\n modelValue: { type: String as PropType<string | null | undefined>, default: undefined },\n /** 非受控初值(\"yyyy-MM-dd\",内部归一到所在周起始日) */\n defaultValue: { type: String, default: undefined },\n /** 弹层开合受控;undefined 走内部非受控(default: undefined 禁用 Boolean casting) */\n open: { type: Boolean as PropType<boolean | undefined>, default: undefined },\n defaultOpen: { type: Boolean, default: false },\n placeholder: { type: String, default: \"请选择周\" },\n disabled: { type: Boolean as PropType<boolean | undefined>, default: undefined },\n invalid: { type: Boolean as PropType<boolean | undefined>, default: undefined },\n readOnly: { type: Boolean as PropType<boolean | undefined>, default: undefined },\n /** 可选下界(\"yyyy-MM-dd\",含当日;日粒度,周条带可能视觉越界但不影响点选禁用) */\n min: { type: String, default: undefined },\n /** 可选上界(\"yyyy-MM-dd\",含当日) */\n max: { type: String, default: undefined },\n /** 不可选日期谓词(参数为 ark 的 DateValue;命中格不可点,同周其余日仍可选) */\n isDateUnavailable: {\n type: Function as PropType<(date: DateValue) => boolean>,\n default: undefined,\n },\n /** 选中后是否自动关弹层 */\n closeOnSelect: { type: Boolean, default: true },\n /** 文案与周起点跟随 locale(zh-CN 默认周一起始) */\n locale: { type: String, default: \"zh-CN\" },\n /** Ark DatePicker Root 的 positioning 配置(placement/gutter 等);\n iframe realm(wujie graft / iframe 嵌入)下 strategy 未显式指定时默认 fixed\n (absolute 包含块错位修正,机制详注见 useSandboxOverlay / sandbox.ts) */\n positioning: {\n type: Object as PropType<PickerPositioning>,\n default: undefined,\n },\n class: { type: String, default: undefined },\n});\n\nconst emit = defineEmits<{\n \"update:modelValue\": [value: string | null];\n \"update:open\": [open: boolean];\n}>();\n\n// attrs(id/aria-*)转发给真实 input,保证 TLabel/TFormControl 关联\ndefineOptions({ inheritAttrs: false });\n\n// 弹层内的 TCalendar 探测到宿主标记 → embedded 内嵌形态(纯卡片内核,不自建 Root,值归本 Picker)\nprovide(CALENDAR_IN_PICKER, true);\n\n
|
|
14
|
+
"content": "<script setup lang=\"ts\">\nimport type { DateValue } from \"@ark-ui/vue/date-picker\";\nimport type { PickerPositioning } from \"../date-shared/positioning\";\nimport type { PropType } from \"vue\";\nimport { computed, provide } from \"vue\";\nimport { Calendar as TCalendar } from \"../calendar\";\nimport PickerShell from \"../date-shared/PickerShell.vue\";\nimport {\n CALENDAR_IN_PICKER,\n formatIsoWeek,\n parseIsoDate,\n weekStartOf,\n} from \"../date-shared/shared\";\nimport { usePickerBridge } from \"../date-shared/usePickerBridge\";\n\nconst props = defineProps({\n /** 受控值(\"yyyy-MM-dd\",语义=所在周起始日);undefined 走内部非受控,null 表示空 */\n modelValue: { type: String as PropType<string | null | undefined>, default: undefined },\n /** 非受控初值(\"yyyy-MM-dd\",内部归一到所在周起始日) */\n defaultValue: { type: String, default: undefined },\n /** 弹层开合受控;undefined 走内部非受控(default: undefined 禁用 Boolean casting) */\n open: { type: Boolean as PropType<boolean | undefined>, default: undefined },\n defaultOpen: { type: Boolean, default: false },\n placeholder: { type: String, default: \"请选择周\" },\n disabled: { type: Boolean as PropType<boolean | undefined>, default: undefined },\n invalid: { type: Boolean as PropType<boolean | undefined>, default: undefined },\n readOnly: { type: Boolean as PropType<boolean | undefined>, default: undefined },\n /** 可选下界(\"yyyy-MM-dd\",含当日;日粒度,周条带可能视觉越界但不影响点选禁用) */\n min: { type: String, default: undefined },\n /** 可选上界(\"yyyy-MM-dd\",含当日) */\n max: { type: String, default: undefined },\n /** 不可选日期谓词(参数为 ark 的 DateValue;命中格不可点,同周其余日仍可选) */\n isDateUnavailable: {\n type: Function as PropType<(date: DateValue) => boolean>,\n default: undefined,\n },\n /** 选中后是否自动关弹层 */\n closeOnSelect: { type: Boolean, default: true },\n /** 文案与周起点跟随 locale(zh-CN 默认周一起始) */\n locale: { type: String, default: \"zh-CN\" },\n /** Ark DatePicker Root 的 positioning 配置(placement/gutter 等);\n iframe realm(wujie graft / iframe 嵌入)下 strategy 未显式指定时默认 fixed\n (absolute 包含块错位修正,机制详注见 useSandboxOverlay / sandbox.ts) */\n positioning: {\n type: Object as PropType<PickerPositioning>,\n default: undefined,\n },\n class: { type: String, default: undefined },\n});\n\nconst emit = defineEmits<{\n \"update:modelValue\": [value: string | null];\n \"update:open\": [open: boolean];\n}>();\n\n// attrs(id/aria-*)转发给真实 input,保证 TLabel/TFormControl 关联\ndefineOptions({ inheritAttrs: false });\n\n// 弹层内的 TCalendar 探测到宿主标记 → embedded 内嵌形态(纯卡片内核,不自建 Root,值归本 Picker)\nprovide(CALENDAR_IN_PICKER, true);\n\n/**\n * \"yyyy-MM-dd\" → 归一到所在周起始日的 ISO 串(非法输入返回 undefined)\n * @param raw - 输入的 ISO 日期串\n * @returns 该日期所在周起始日的 ISO 串;解析失败返回 undefined\n */\nfunction formatIsoWeekStart(raw: string): string | undefined {\n const date = parseIsoDate(raw);\n return date ? weekStartOf(date, props.locale).toString() : undefined;\n}\n\nconst { rootValue, isOpen, setOpen, handleValueUpdate } = usePickerBridge({\n modelValue: () => props.modelValue,\n defaultValue: () => props.defaultValue,\n open: () => props.open,\n defaultOpen: () => props.defaultOpen,\n disabled: () => props.disabled,\n readOnly: () => props.readOnly,\n parse: parseIsoDate,\n normalizeDefault: (raw) => formatIsoWeekStart(raw) ?? null,\n toPublicValue: (date) => formatIsoWeekStart(date.toString()) ?? null,\n onUpdateModelValue: (value) => emit(\"update:modelValue\", value),\n onUpdateOpen: (open) => emit(\"update:open\", open),\n});\n\nconst minDate = computed(() => parseIsoDate(props.min ?? \"\"));\nconst maxDate = computed(() => parseIsoDate(props.max ?? \"\"));\n\n// 输入框回显整周区间(format 钩子按单值调用,zag 自行拼接)\nfunction formatDate(date: DateValue): string {\n return formatIsoWeek(date, props.locale);\n}\n\n// 键入解析:任意合法日期键入归一到周起点;非法返回 undefined 由 zag 忽略\nfunction parseDate(raw: string): DateValue | undefined {\n const date = parseIsoDate(raw);\n return date ? weekStartOf(date, props.locale) : undefined;\n}\n</script>\n\n<template>\n <PickerShell\n v-bind=\"$attrs\"\n :model-value=\"rootValue\"\n :open=\"isOpen\"\n :locale=\"props.locale\"\n :min=\"minDate\"\n :max=\"maxDate\"\n :is-date-unavailable=\"props.isDateUnavailable\"\n :close-on-select=\"props.closeOnSelect\"\n :read-only=\"props.readOnly\"\n :disabled=\"props.disabled\"\n :invalid=\"props.invalid\"\n :placeholder=\"props.placeholder\"\n :positioning=\"props.positioning\"\n :class=\"props.class\"\n :format=\"formatDate\"\n :parse=\"parseDate\"\n @update:model-value=\"handleValueUpdate\"\n @update:open=\"setOpen\"\n >\n <TCalendar week :locale=\"props.locale\" />\n </PickerShell>\n</template>\n"
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
"path": "week-picker/index.ts",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
3
|
"name": "year-picker",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.8",
|
|
5
5
|
"type": "registry:ui",
|
|
6
6
|
"description": "年份选择器:输入框 + 锁定年视图的日历弹层(decade 网格),值以 \"yyyy\" 字符串受控,min/max 为年粒度闭区间。",
|
|
7
7
|
"registryDependencies": ["utils", "date-shared", "calendar"],
|