@tu-design/vue 0.5.8 → 0.5.10
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 +242 -158
- package/dist/index.mjs +1296 -516
- package/dist/registry/vue/alert-dialog.json +2 -2
- package/dist/registry/vue/alert.json +1 -1
- package/dist/registry/vue/avatar-group.json +1 -1
- package/dist/registry/vue/avatar.json +1 -1
- package/dist/registry/vue/badge.json +1 -1
- package/dist/registry/vue/button.json +1 -1
- package/dist/registry/vue/calendar.json +1 -1
- package/dist/registry/vue/card.json +1 -1
- package/dist/registry/vue/cascader.json +2 -2
- package/dist/registry/vue/checkbox.json +2 -2
- package/dist/registry/vue/context-menu.json +1 -1
- package/dist/registry/vue/currency-input.json +1 -1
- package/dist/registry/vue/date-picker.json +1 -1
- package/dist/registry/vue/date-range-picker.json +2 -2
- package/dist/registry/vue/date-shared.json +2 -2
- package/dist/registry/vue/dialog.json +2 -2
- package/dist/registry/vue/drawer.json +2 -2
- package/dist/registry/vue/dropdown-menu.json +1 -1
- package/dist/registry/vue/empty.json +1 -1
- package/dist/registry/vue/form-render.json +9 -9
- package/dist/registry/vue/form.json +2 -2
- package/dist/registry/vue/icon-shared.json +8 -2
- package/dist/registry/vue/input.json +2 -2
- package/dist/registry/vue/label.json +1 -1
- package/dist/registry/vue/month-picker.json +1 -1
- package/dist/registry/vue/number-input.json +1 -1
- package/dist/registry/vue/overlay-shared.json +1 -1
- 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 +54 -54
- package/dist/registry/vue/select.json +1 -1
- 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 +1 -1
- package/dist/registry/vue/spin.json +1 -1
- package/dist/registry/vue/switch.json +1 -1
- package/dist/registry/vue/table-render.json +24 -11
- package/dist/registry/vue/tabs.json +1 -1
- package/dist/registry/vue/textarea.json +2 -2
- package/dist/registry/vue/timeline.json +1 -1
- package/dist/registry/vue/toast.json +1 -1
- package/dist/registry/vue/tokens.json +2 -2
- package/dist/registry/vue/tooltip.json +1 -1
- package/dist/registry/vue/tree-select.json +2 -2
- package/dist/registry/vue/tree-shared.json +1 -1
- package/dist/registry/vue/utils.json +1 -1
- package/dist/registry/vue/week-picker.json +1 -1
- 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": "textarea",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.10",
|
|
5
5
|
"type": "registry:ui",
|
|
6
6
|
"description": "多行文本输入:纯样式封装,支持 invalid 校验态。",
|
|
7
7
|
"registryDependencies": ["utils"],
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"path": "textarea/Textarea.vue",
|
|
11
11
|
"type": "registry:component",
|
|
12
12
|
"target": "components/ui/textarea/Textarea.vue",
|
|
13
|
-
"content": "<script setup lang=\"ts\">\nimport { cn } from \"@/lib/utils\";\n\nconst modelValue = defineModel<string | number>();\nconst props = defineProps<{ class?: string; invalid?: boolean }>();\n</script>\n\n<template>\n <textarea\n v-model=\"modelValue\"\n :aria-invalid=\"props.invalid ? 'true' : undefined\"\n :class=\"\n cn(\n 'flex field-sizing-content min-h-16 w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-destructive/20 aria-invalid:border-destructive md:text-sm',\n props.class,\n )\n \"\n />\n</template>\n"
|
|
13
|
+
"content": "<script setup lang=\"ts\">\nimport { cn } from \"@/lib/utils\";\n\n// 原生 <textarea> 的 v-model 回写恒为 string:跟随绑定类型归一(Input.vue 同款)。\nconst looseToNumber = (val: string | number): string | number => {\n const n = Number.parseFloat(String(val));\n return Number.isNaN(n) ? val : n;\n};\n\nconst modelValue = defineModel<string | number>({\n set: (v) => (typeof modelValue.value === \"number\" ? looseToNumber(v) : v),\n});\nconst props = defineProps<{ class?: string; invalid?: boolean }>();\n</script>\n\n<template>\n <textarea\n v-model=\"modelValue\"\n :aria-invalid=\"props.invalid ? 'true' : undefined\"\n :class=\"\n cn(\n 'flex field-sizing-content min-h-16 w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-destructive/20 aria-invalid:border-destructive md:text-sm',\n props.class,\n )\n \"\n />\n</template>\n"
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
"path": "textarea/index.ts",
|
|
@@ -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.10",
|
|
5
5
|
"type": "registry:ui",
|
|
6
6
|
"description": "时间轴:数据驱动 items 渲染竖向事件流,支持单列/左右交替、五种语义节点色与空心节点、#item 作用域插槽自定义内容。",
|
|
7
7
|
"registryDependencies": ["utils"],
|
|
@@ -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.10",
|
|
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"],
|
|
@@ -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.10",
|
|
5
5
|
"type": "registry:style",
|
|
6
6
|
"description": "Tailwind CSS v4 语义 tokens(shadcn 官方 v4 集合)。",
|
|
7
7
|
"dependencies": ["tw-animate-css@^1.4.0"],
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"path": "styles/tokens.css",
|
|
11
11
|
"type": "registry:style",
|
|
12
12
|
"target": "styles/tokens.css",
|
|
13
|
-
"content": "/* tu-design 官方 tokens —— Tailwind CSS v4 主题(shadcn v4 集合扩展)。\n *\n * 主题桥接:语义色优先消费应用级 --app-* CSS 变量(应用主题系统写入),\n * 未定义时回落官方 oklch 值 —— 无主题系统的项目观感与上游一致,零破坏。\n * 契约(--app-* 全集见各项目主题包,如 @repo/themes):\n * - --app-bg-page/surface/raised/hover → --background/--card/--popover/--muted/--accent\n * - --app-text-1/2/3 → --foreground 及各 *-foreground/--muted-foreground\n * (text-3 上游零消费,供应用侧直接使用)\n * - --app-accent/-contrast → --primary(+foreground)/--ring\n * - --app-border → --border/--input(dark 模式建议低不透明度值,如 #FFFFFF1A,对齐上游风格)\n * - --secondary/-foreground 有意不桥接(上游定位即中性灰)\n * - --app-destructive/success/warning/info → 状态色三件套:实色、-soft 浅底(未定义回落\n * color-mix 派生)、-foreground 前景(深色实色场景如 dark destructive 白字对比 borderline,\n * 建议应用侧显式定义覆盖)\n * - .dark 块同样桥接,兜底为官方暗色 oklch;--*-soft 在 .dark 内重复声明:\n * 自定义属性按声明处求值后继承,不在 .dark 重声明将无法响应暗色的实色变化。\n */\n@import \"tw-animate-css\";\n\n@custom-variant dark (&:where(.dark, .dark *));\n\n:root {\n --background: var(--app-bg-page, oklch(1 0 0));\n --foreground: var(--app-text-1, oklch(0.145 0 0));\n --card: var(--app-bg-raised, oklch(1 0 0));\n --card-foreground: var(--app-text-1, oklch(0.145 0 0));\n --popover: var(--app-bg-raised, oklch(1 0 0));\n --popover-foreground: var(--app-text-1, oklch(0.145 0 0));\n --primary: var(--app-accent, oklch(0.205 0 0));\n --primary-foreground: var(--app-accent-contrast, oklch(0.985 0 0));\n --secondary: oklch(0.97 0 0);\n --secondary-foreground: oklch(0.205 0 0);\n --muted: var(--app-bg-surface, oklch(0.97 0 0));\n --muted-foreground: var(--app-text-2, oklch(0.556 0 0));\n --accent: var(--app-bg-hover, oklch(0.97 0 0));\n --accent-foreground: var(--app-text-1, oklch(0.205 0 0));\n --destructive: var(--app-destructive, oklch(0.577 0.245 27.325));\n --destructive-soft: var(\n --app-destructive-soft,\n color-mix(in oklab, var(--destructive) 10%, transparent)\n );\n --destructive-foreground: var(--app-destructive-foreground, oklch(0.985 0 0));\n --success: var(--app-success, oklch(0.596 0.145 163.225));\n --success-soft: var(--app-success-soft, color-mix(in oklab, var(--success) 10%, transparent));\n --success-foreground: var(--app-success-foreground, oklch(0.985 0 0));\n --warning: var(--app-warning, oklch(0.666 0.179 58.318));\n --warning-soft: var(--app-warning-soft, color-mix(in oklab, var(--warning) 12%, transparent));\n --warning-foreground: var(--app-warning-foreground, oklch(0.985 0 0));\n --info: var(--app-info, oklch(0.546 0.245 262.881));\n --info-soft: var(--app-info-soft, color-mix(in oklab, var(--info) 12%, transparent));\n --info-foreground: var(--app-info-foreground, oklch(0.985 0 0));\n --border: var(--app-border, oklch(0.922 0 0));\n --input: var(--app-border, oklch(0.922 0 0));\n --ring: var(--app-accent, oklch(0.708 0 0));\n --radius: 0.625rem;\n /* 层叠序:表体 sticky < 表头普通列 sticky(fill/virtual 表头钉住,z-20 由 TableRender theadThClass 提供)\n < 表头 sticky <
|
|
13
|
+
"content": "/* tu-design 官方 tokens —— Tailwind CSS v4 主题(shadcn v4 集合扩展)。\n *\n * 主题桥接:语义色优先消费应用级 --app-* CSS 变量(应用主题系统写入),\n * 未定义时回落官方 oklch 值 —— 无主题系统的项目观感与上游一致,零破坏。\n * 契约(--app-* 全集见各项目主题包,如 @repo/themes):\n * - --app-bg-page/surface/raised/hover → --background/--card/--popover/--muted/--accent\n * - --app-text-1/2/3 → --foreground 及各 *-foreground/--muted-foreground\n * (text-3 上游零消费,供应用侧直接使用)\n * - --app-accent/-contrast → --primary(+foreground)/--ring\n * - --app-border → --border/--input(dark 模式建议低不透明度值,如 #FFFFFF1A,对齐上游风格)\n * - --secondary/-foreground 有意不桥接(上游定位即中性灰)\n * - --app-destructive/success/warning/info → 状态色三件套:实色、-soft 浅底(未定义回落\n * color-mix 派生)、-foreground 前景(深色实色场景如 dark destructive 白字对比 borderline,\n * 建议应用侧显式定义覆盖)\n * - .dark 块同样桥接,兜底为官方暗色 oklch;--*-soft 在 .dark 内重复声明:\n * 自定义属性按声明处求值后继承,不在 .dark 重声明将无法响应暗色的实色变化。\n */\n@import \"tw-animate-css\";\n\n@custom-variant dark (&:where(.dark, .dark *));\n\n:root {\n --background: var(--app-bg-page, oklch(1 0 0));\n --foreground: var(--app-text-1, oklch(0.145 0 0));\n --card: var(--app-bg-raised, oklch(1 0 0));\n --card-foreground: var(--app-text-1, oklch(0.145 0 0));\n --popover: var(--app-bg-raised, oklch(1 0 0));\n --popover-foreground: var(--app-text-1, oklch(0.145 0 0));\n --primary: var(--app-accent, oklch(0.205 0 0));\n --primary-foreground: var(--app-accent-contrast, oklch(0.985 0 0));\n --secondary: oklch(0.97 0 0);\n --secondary-foreground: oklch(0.205 0 0);\n --muted: var(--app-bg-surface, oklch(0.97 0 0));\n --muted-foreground: var(--app-text-2, oklch(0.556 0 0));\n --accent: var(--app-bg-hover, oklch(0.97 0 0));\n --accent-foreground: var(--app-text-1, oklch(0.205 0 0));\n --destructive: var(--app-destructive, oklch(0.577 0.245 27.325));\n --destructive-soft: var(\n --app-destructive-soft,\n color-mix(in oklab, var(--destructive) 10%, transparent)\n );\n --destructive-foreground: var(--app-destructive-foreground, oklch(0.985 0 0));\n --success: var(--app-success, oklch(0.596 0.145 163.225));\n --success-soft: var(--app-success-soft, color-mix(in oklab, var(--success) 10%, transparent));\n --success-foreground: var(--app-success-foreground, oklch(0.985 0 0));\n --warning: var(--app-warning, oklch(0.666 0.179 58.318));\n --warning-soft: var(--app-warning-soft, color-mix(in oklab, var(--warning) 12%, transparent));\n --warning-foreground: var(--app-warning-foreground, oklch(0.985 0 0));\n --info: var(--app-info, oklch(0.546 0.245 262.881));\n --info-soft: var(--app-info-soft, color-mix(in oklab, var(--info) 12%, transparent));\n --info-foreground: var(--app-info-foreground, oklch(0.985 0 0));\n --border: var(--app-border, oklch(0.922 0 0));\n --input: var(--app-border, oklch(0.922 0 0));\n --ring: var(--app-accent, oklch(0.708 0 0));\n --radius: 0.625rem;\n /* 层叠序:表体 sticky < 表头普通列 sticky(fill/virtual 表头钉住,z-20 由 TableRender theadThClass 提供)\n < 表头 sticky < 非模态浮层 < 宿主应用 chrome < 模态层(chrome 由消费方置于 overlay~modal 之间,\n 不得 ≥ modal,否则击穿模态遮罩;表头 fixed 列经 stickyStyle inline style 消费 --z-sticky-head)\n --z-overlay:原地锚定的 Select/Tooltip/DropdownMenu/ContextMenu(弹窗内处于 Content 栈上下文内,天然高于面板)\n --z-modal:Dialog/AlertDialog/Drawer 的 Backdrop/Positioner/Content + teleport 至 body 的\n Popover/Cascader/TreeSelect/日期弹层 Positioner(同层按 DOM 挂载次序叠放,teleport 节点恒后于应用\n 根容器,故弹窗内下拉恒浮于面板之上;模态打开时弹窗外浮层被遮罩与焦点陷阱阻断,不可达同开) */\n --z-sticky: 10;\n --z-sticky-head: 30;\n --z-overlay: 50;\n --z-modal: 60;\n}\n\n.dark {\n --background: var(--app-bg-page, oklch(0.145 0 0));\n --foreground: var(--app-text-1, oklch(0.985 0 0));\n --card: var(--app-bg-raised, oklch(0.205 0 0));\n --card-foreground: var(--app-text-1, oklch(0.985 0 0));\n --popover: var(--app-bg-raised, oklch(0.269 0 0));\n --popover-foreground: var(--app-text-1, oklch(0.985 0 0));\n --primary: var(--app-accent, oklch(0.922 0 0));\n --primary-foreground: var(--app-accent-contrast, oklch(0.205 0 0));\n --secondary: oklch(0.269 0 0);\n --secondary-foreground: oklch(0.985 0 0);\n --muted: var(--app-bg-surface, oklch(0.269 0 0));\n --muted-foreground: var(--app-text-2, oklch(0.708 0 0));\n --accent: var(--app-bg-hover, oklch(0.371 0 0));\n --accent-foreground: var(--app-text-1, oklch(0.985 0 0));\n --destructive: var(--app-destructive, oklch(0.704 0.191 22.216));\n --destructive-soft: var(\n --app-destructive-soft,\n color-mix(in oklab, var(--destructive) 10%, transparent)\n );\n --destructive-foreground: var(--app-destructive-foreground, oklch(0.985 0 0));\n --success: var(--app-success, oklch(0.696 0.17 162.48));\n --success-soft: var(--app-success-soft, color-mix(in oklab, var(--success) 10%, transparent));\n --success-foreground: var(--app-success-foreground, oklch(0.985 0 0));\n --warning: var(--app-warning, oklch(0.769 0.188 70.08));\n --warning-soft: var(--app-warning-soft, color-mix(in oklab, var(--warning) 12%, transparent));\n --warning-foreground: var(--app-warning-foreground, oklch(0.205 0 0));\n --info: var(--app-info, oklch(0.623 0.214 259.815));\n --info-soft: var(--app-info-soft, color-mix(in oklab, var(--info) 12%, transparent));\n --info-foreground: var(--app-info-foreground, oklch(0.985 0 0));\n --border: var(--app-border, oklch(1 0 0 / 10%));\n --input: var(--app-border, oklch(1 0 0 / 15%));\n --ring: var(--app-accent, oklch(0.556 0 0));\n}\n\n@theme inline {\n --radius-sm: calc(var(--radius) - 4px);\n --radius-md: calc(var(--radius) - 2px);\n --radius-lg: var(--radius);\n --radius-xl: calc(var(--radius) + 4px);\n --radius-2xl: calc(var(--radius) + 6px);\n --color-background: var(--background);\n --color-foreground: var(--foreground);\n --color-card: var(--card);\n --color-card-foreground: var(--card-foreground);\n --color-popover: var(--popover);\n --color-popover-foreground: var(--popover-foreground);\n --color-primary: var(--primary);\n --color-primary-foreground: var(--primary-foreground);\n --color-secondary: var(--secondary);\n --color-secondary-foreground: var(--secondary-foreground);\n --color-muted: var(--muted);\n --color-muted-foreground: var(--muted-foreground);\n --color-accent: var(--accent);\n --color-accent-foreground: var(--accent-foreground);\n --color-destructive: var(--destructive);\n --color-destructive-soft: var(--destructive-soft);\n --color-destructive-foreground: var(--destructive-foreground);\n --color-success: var(--success);\n --color-success-foreground: var(--success-foreground);\n --color-success-soft: var(--success-soft);\n --color-warning: var(--warning);\n --color-warning-foreground: var(--warning-foreground);\n --color-warning-soft: var(--warning-soft);\n --color-info: var(--info);\n --color-info-foreground: var(--info-foreground);\n --color-info-soft: var(--info-soft);\n --color-border: var(--border);\n --color-input: var(--input);\n --color-ring: var(--ring);\n}\n\n/* 全局边框色兜底,对齐 shadcn v4 官方 tokens(上游另含 outline-ring/50,此处仅移植 border):\n 裸 border 类不再回退 currentColor,而是使用 --border token。 */\n@layer base {\n * {\n border-color: var(--color-border);\n }\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": "tooltip",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.10",
|
|
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.10",
|
|
5
5
|
"type": "registry:ui",
|
|
6
6
|
"description": "树形下拉选择:一站式 props 驱动,支持单/多选、勾选级联、过滤与多标签折叠。",
|
|
7
7
|
"registryDependencies": ["icon-shared", "tree-shared", "utils", "date-shared", "overlay-shared"],
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"path": "tree-select/TreeSelect.vue",
|
|
18
18
|
"type": "registry:component",
|
|
19
19
|
"target": "components/ui/tree-select/TreeSelect.vue",
|
|
20
|
-
"content": "<script setup lang=\"ts\">\nimport type { PropType } from \"vue\";\nimport { computed, getCurrentInstance, nextTick, ref, useAttrs, watch } from \"vue\";\nimport { Popover as ArkPopover } from \"@ark-ui/vue/popover\";\nimport type { PopoverRootProps } from \"@ark-ui/vue/popover\";\nimport { cn } from \"@/lib/utils\";\nimport { controlCls } from \"../date-shared/shared\";\nimport { useControlledBoolean } from \"../overlay-shared/useControlledBoolean\";\nimport { useOverlayIds } from \"../overlay-shared/useOverlayIds\";\nimport { useSandboxTeleportTarget, withSandboxStrategy } from \"../overlay-shared/useSandboxOverlay\";\nimport ChevronIcon from \"../icon-shared/ChevronIcon.vue\";\nimport CloseIcon from \"../icon-shared/CloseIcon.vue\";\nimport ValueTags from \"../tree-shared/ValueTags.vue\";\nimport { createTreeMate, type Key, type TreeNode, type TreeOption } from \"../tree-shared\";\nimport { nextActiveKey, type MoveKey } from \"../tree-shared/keyboard\";\n\n// ids 全量覆盖(无冒号):ArkPopover 浮层载体,规避 wujie patch getElementById\n// 对 zag 缺省冒号 id 的 SyntaxError 刷屏(详注见 useOverlayIds)\nconst { ids: rootIds } = useOverlayIds(useAttrs(), {\n primary: \"content\",\n parts: [\n \"content\",\n \"title\",\n \"description\",\n \"anchor\",\n \"trigger\",\n \"closeTrigger\",\n \"positioner\",\n \"arrow\",\n ],\n});\nimport TreePanel from \"./TreePanel.vue\";\nimport type { TreeSelectTag } from \"./types\";\n\ndefineOptions({ inheritAttrs: false });\n\nconst props = defineProps({\n /** 树选项(key/label/children/disabled) */\n options: { type: Array as PropType<TreeOption[]>, required: true },\n /** 当前值:单选为 key,multiple 为 key 数组;不传走内部非受控 */\n modelValue: {\n type: [String, Number, Array] as PropType<Key | Key[] | undefined>,\n default: undefined,\n },\n defaultValue: {\n type: [String, Number, Array] as PropType<Key | Key[] | undefined>,\n default: undefined,\n },\n /** 多选:值恒为数组,点击节点切换选中 */\n multiple: { type: Boolean, default: false },\n /** 勾选模式:行首渲染 checkbox,值恒为数组(隐含多选语义) */\n checkable: { type: Boolean, default: false },\n /** 勾选级联:勾选父级联动全部子级(默认 false,对齐 naive-ui) */\n cascade: { type: Boolean, default: false },\n /** 勾选策略:all 值含全选节点 / parent 仅父 / child 仅叶(默认 all) */\n checkStrategy: { type: String as PropType<\"all\" | \"parent\" | \"child\">, default: \"all\" },\n /** 弹层开合受控;undefined 走内部非受控(default: undefined 禁用 Boolean casting) */\n open: { type: Boolean as PropType<boolean | undefined>, default: undefined },\n defaultOpen: { type: Boolean, default: false },\n disabled: { type: Boolean as PropType<boolean | undefined>, default: undefined },\n placeholder: { type: String, default: \"请选择\" },\n /** 多选最多展示标签数,超出折叠为 +N */\n maxTagCount: { type: Number, default: undefined },\n /** 展示清空按钮 */\n clearable: { type: Boolean, default: false },\n /** 可搜索:触发器内嵌输入框,按 label 过滤(展示命中节点及其祖先路径) */\n filterable: { type: Boolean, default: false },\n /** 受控展开键集合;undefined 走内部非受控 */\n expandedKeys: { type: Array as PropType<Key[] | undefined>, default: undefined },\n defaultExpandedKeys: { type: Array as PropType<Key[]>, default: () => [] },\n /** 初始展开全部分支 */\n defaultExpandAll: { type: Boolean, default: false },\n /** Ark Popover Root 的 positioning 配置(placement/gutter 等);\n iframe realm(wujie graft / iframe 嵌入)下 strategy 未显式指定时默认 fixed */\n positioning: {\n type: Object as PropType<PopoverRootProps[\"positioning\"]>,\n default: undefined,\n },\n class: { type: String, default: undefined },\n});\n\nconst emit = defineEmits<{\n \"update:modelValue\": [value: Key | Key[] | undefined];\n /** @deprecated 请改用 update:open(v-model:open);下一个 minor 移除 */\n \"update:show\": [open: boolean];\n \"update:open\": [open: boolean];\n \"update:expandedKeys\": [keys: Key[]];\n}>();\n\nif (import.meta.env.DEV && getCurrentInstance()?.vnode.props?.[\"onUpdate:show\"]) {\n console.warn(\"[tu-design] <TreeSelect> update:show 已弃用,请改用 update:open(v-model:open)。\");\n}\n\n// —— 受控桥接(Select/DatePicker 同款):Root 恒走受控,非受控语义由内部 ref 实现 ——\nconst internalValue = ref<Key | Key[] | undefined>(props.defaultValue);\nconst value = computed<Key | Key[] | undefined>(() =>\n props.modelValue !== undefined ? props.modelValue : internalValue.value,\n);\n\n// —— 树数据:options 变更即重建;值中的失效 key 经 getNode 静默忽略 ——\nconst treeMate = computed(() => createTreeMate(props.options, { ignoreEmptyChildren: true }));\n\nconst internalExpanded = ref<Key[]>(\n props.defaultExpandAll\n ? treeMate.value.getNonLeafKeys({ preserveGroup: true })\n : [...props.defaultExpandedKeys],\n);\nconst expandedKeys = computed<Key[]>(() => props.expandedKeys ?? internalExpanded.value);\n\n// defaultExpandAll 只在 options 首次非空时播种:首次计算时异步数据通常还是空树\nlet expandAllSeeded = !props.defaultExpandAll || treeMate.value.treeNodes.length > 0;\nwatch(\n () => props.options,\n () => {\n if (expandAllSeeded || !props.defaultExpandAll || props.expandedKeys !== undefined) return;\n if (treeMate.value.treeNodes.length === 0) return;\n expandAllSeeded = true;\n internalExpanded.value = treeMate.value.getNonLeafKeys({ preserveGroup: true });\n },\n);\n\nfunction handleExpandedUpdate(keys: Key[]) {\n internalExpanded.value = keys;\n emit(\"update:expandedKeys\", keys);\n}\n\nfunction toggleNode(node: TreeNode) {\n const next = expandedKeys.value.includes(node.key)\n ? expandedKeys.value.filter((k) => k !== node.key)\n : [...expandedKeys.value, node.key];\n handleExpandedUpdate(next);\n}\n\nfunction toArrayValue(v: Key | Key[] | undefined): Key[] {\n if (v === undefined) return [];\n return Array.isArray(v) ? v : [v];\n}\n\n// checkable 值语义恒为数组:单值 Key 输入按无选中处理并 dev 警告一次\nlet warnedNonArrayValue = false;\nfunction normalizeValue(v: Key | Key[] | undefined): Key[] {\n if (v === undefined) return [];\n if (Array.isArray(v)) return v;\n if (props.checkable) {\n if (import.meta.env?.DEV && !warnedNonArrayValue) {\n warnedNonArrayValue = true;\n console.warn(\"[TreeSelect] checkable 模式下 modelValue 需为数组,单值输入已按无选中处理。\");\n }\n return [];\n }\n return [v];\n}\n\nconst selectedKeys = computed<Key[]>(() => toArrayValue(value.value));\n\nconst checkOptions = computed(() => ({\n cascade: props.cascade,\n checkStrategy: props.checkStrategy,\n}));\n\n// 勾选模式的展示状态(级联归一后的选中/半选集合)\nconst checkedState = computed<{ checked: Key[]; indeterminate: Key[] }>(() => {\n if (!props.checkable) return { checked: selectedKeys.value, indeterminate: [] };\n const merged = treeMate.value.getCheckedKeys(normalizeValue(value.value), checkOptions.value);\n return { checked: merged.checkedKeys, indeterminate: merged.indeterminateKeys };\n});\n\nconst tags = computed<TreeSelectTag[]>(() =>\n selectedKeys.value\n .map((key) => {\n const node = treeMate.value.getNode(key);\n return node ? { key, label: (node.rawNode as TreeOption).label ?? String(key) } : null;\n })\n .filter((t): t is TreeSelectTag => t !== null),\n);\n\n// checkable 隐含多选语义(值恒为 Key[],与 multiple 等价)\nconst isMulti = computed(() => props.multiple || props.checkable);\n\nconst singleLabel = computed(() => (isMulti.value ? \"\" : (tags.value[0]?.label ?? \"\")));\n\nfunction updateValue(next: Key | Key[] | undefined) {\n internalValue.value = next;\n emit(\"update:modelValue\", next);\n}\n\nfunction selectNode(node: TreeNode) {\n if (node.disabled) return;\n if (props.checkable) {\n const current = normalizeValue(value.value);\n const isNodeChecked = checkedState.value.checked.includes(node.key);\n const merged = isNodeChecked\n ? treeMate.value.uncheck(node.key, current, checkOptions.value)\n : treeMate.value.check(node.key, current, checkOptions.value);\n updateValue(merged.checkedKeys);\n return;\n }\n if (props.multiple) {\n const current = toArrayValue(value.value);\n const next = current.includes(node.key)\n ? current.filter((k) => k !== node.key)\n : [...current, node.key];\n updateValue(next);\n } else {\n updateValue(node.key);\n setOpen(false);\n }\n}\n\n// checkStrategy / cascade 运行时切换:值集合按新策略归一\nwatch(checkOptions, () => {\n if (!props.checkable) return;\n const normalized = treeMate.value.getCheckedKeys(normalizeValue(value.value), checkOptions.value);\n const current = toArrayValue(value.value);\n if (\n normalized.checkedKeys.length !== current.length ||\n normalized.checkedKeys.some((k) => !current.includes(k))\n ) {\n updateValue(normalized.checkedKeys);\n }\n});\n\nfunction removeTag(key: Key) {\n if (props.checkable) {\n const merged = treeMate.value.uncheck(key, normalizeValue(value.value), checkOptions.value);\n updateValue(merged.checkedKeys);\n return;\n }\n updateValue(toArrayValue(value.value).filter((k) => k !== key));\n}\n\nconst hasValue = computed(() => tags.value.length > 0);\n\nfunction handleClear() {\n const next = isMulti.value ? [] : undefined;\n internalValue.value = next;\n emit(\"update:modelValue\", next);\n}\n\n// —— 弹层开合(点击/键盘 ↓ 显式驱动,保证各环境一致)——\nconst { isOpen, setOpen } = useControlledBoolean({\n controlled: () => props.open,\n defaultValue: () => props.defaultOpen,\n onChange: (open) => {\n emit(\"update:open\", open);\n emit(\"update:show\", open);\n },\n});\n\n// —— 沙箱适配(机制详注见 useSandboxOverlay / sandbox.ts):Teleport 目标降级\n// (shadow DOM / wujie graft → 应用挂载容器,避免面板落入 iframe body)+\n// iframe realm 下 strategy 默认 fixed(absolute 包含块错位,fixed 唯一正确解);\n// 无 to prop,面板恒传送 ——\nconst teleportTarget = useSandboxTeleportTarget(() => undefined);\nconst rootPositioning = computed(() =>\n withSandboxStrategy(props.positioning, { ...props.positioning }),\n);\n\nfunction openFromInput() {\n if (props.disabled || isOpen.value) return;\n syncPanelWidth();\n setOpen(true);\n}\n\n// —— 面板宽度对齐触发器 ——\nconst triggerEl = ref<HTMLElement | null>(null);\nconst panelMinWidth = ref(\"0px\");\nfunction syncPanelWidth() {\n panelMinWidth.value = `${triggerEl.value?.offsetWidth ?? 0}px`;\n}\n\nconst visibleNodes = computed(() => treeMate.value.getFlattenedNodes(expandedKeys.value));\n\n// —— 过滤:命中节点及其祖先路径可见(搜索态下全树展开)——\nconst pattern = ref(\"\");\nconst searchPattern = computed(() => pattern.value.trim().toLowerCase());\nconst filteredNodes = computed<TreeNode[]>(() => {\n if (!props.filterable || !searchPattern.value) return visibleNodes.value;\n const mate = treeMate.value;\n // 命中节点与其全部祖先均保留(祖先自身无命中也保留)\n const keep = new Set<Key>();\n const allNodes = mate.getFlattenedNodes(mate.getNonLeafKeys({ preserveGroup: true }));\n for (const node of allNodes) {\n const path = mate.getPath(node.key);\n if (path.treeNodePath.some((tn) => labelOf(tn).toLowerCase().includes(searchPattern.value))) {\n path.treeNodePath.forEach((tn) => keep.add(tn.key));\n }\n }\n return allNodes.filter((n) => keep.has(n.key));\n});\n\nfunction labelOf(node: TreeNode): string {\n return (node.rawNode as TreeOption).label ?? String(node.key);\n}\n\n// —— 键盘导航(↑↓←→ / Home / End / Enter,游标仅落在非 disabled 节点)——\nconst activeKey = ref<Key | null>(null);\nconst MOVE_KEYS: MoveKey[] = [\"ArrowDown\", \"ArrowUp\", \"Home\", \"End\"];\n\nfunction scrollActiveIntoView() {\n nextTick(() => {\n document\n .querySelector('[data-part=\"tree-node\"][data-active]')\n ?.scrollIntoView?.({ block: \"nearest\" });\n });\n}\n\nfunction moveHorizontally(expand: boolean) {\n if (activeKey.value === null) return;\n const node = filteredNodes.value.find((n) => n.key === activeKey.value);\n if (!node) return;\n if (expand) {\n if (node.isLeaf || !node.children?.length) return;\n if (!expandedKeys.value.includes(node.key)) {\n handleExpandedUpdate([...expandedKeys.value, node.key]);\n return;\n }\n const firstChild = node.children.find((c) => !c.disabled);\n if (firstChild) activeKey.value = firstChild.key;\n } else {\n if (node.children?.length && expandedKeys.value.includes(node.key)) {\n handleExpandedUpdate(expandedKeys.value.filter((k) => k !== node.key));\n return;\n }\n if (node.parent && !node.parent.ignored) activeKey.value = node.parent.key;\n }\n}\n\nfunction handleKeydown(e: KeyboardEvent) {\n if (props.disabled) return;\n if (!isOpen.value) {\n if (e.key === \"ArrowDown\" || e.key === \"Enter\") {\n e.preventDefault();\n openFromInput();\n }\n return;\n }\n if ((MOVE_KEYS as string[]).includes(e.key)) {\n e.preventDefault();\n activeKey.value = nextActiveKey(filteredNodes.value, activeKey.value, e.key as MoveKey);\n scrollActiveIntoView();\n return;\n }\n if (e.key === \"ArrowRight\" || e.key === \"ArrowLeft\") {\n e.preventDefault();\n moveHorizontally(e.key === \"ArrowRight\");\n return;\n }\n if (e.key === \"Enter\") {\n e.preventDefault();\n const node = filteredNodes.value.find((n) => n.key === activeKey.value);\n if (node) selectNode(node);\n }\n}\n\n// 弹层开合时重置键盘游标与搜索词\nwatch(isOpen, (open) => {\n activeKey.value = null;\n if (open) syncPanelWidth();\n else pattern.value = \"\";\n});\n</script>\n\n<template>\n <ArkPopover.Root\n :ids=\"rootIds\"\n :open=\"isOpen\"\n :positioning=\"rootPositioning\"\n @update:open=\"setOpen\"\n >\n <ArkPopover.Anchor as-child>\n <div\n ref=\"triggerEl\"\n v-bind=\"$attrs\"\n data-part=\"trigger\"\n role=\"button\"\n tabindex=\"0\"\n :aria-expanded=\"isOpen\"\n aria-haspopup=\"true\"\n :aria-disabled=\"props.disabled || undefined\"\n :class=\"\n cn(\n controlCls,\n 'min-h-9 cursor-pointer gap-2 px-3 py-1.5 text-sm',\n props.disabled && 'cursor-not-allowed opacity-50',\n props.class,\n )\n \"\n @click=\"openFromInput\"\n @keydown=\"handleKeydown\"\n >\n <template v-if=\"isMulti\">\n <ValueTags\n v-if=\"tags.length\"\n :values=\"tags\"\n :max-tag-count=\"props.maxTagCount\"\n :disabled=\"!!props.disabled\"\n @remove=\"removeTag\"\n />\n <input\n v-if=\"props.filterable\"\n v-model=\"pattern\"\n data-part=\"input\"\n type=\"text\"\n class=\"h-5 w-12 min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground\"\n :placeholder=\"tags.length ? '' : props.placeholder\"\n :aria-label=\"props.placeholder\"\n />\n <span v-if=\"!tags.length && !props.filterable\" class=\"truncate text-muted-foreground\">{{\n props.placeholder\n }}</span>\n </template>\n <template v-else>\n <input\n v-if=\"props.filterable\"\n v-model=\"pattern\"\n data-part=\"input\"\n type=\"text\"\n class=\"h-full w-full min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground\"\n :placeholder=\"singleLabel || props.placeholder\"\n :aria-label=\"props.placeholder\"\n />\n <template v-else>\n <span v-if=\"singleLabel\" class=\"truncate\">{{ singleLabel }}</span>\n <span v-else class=\"truncate text-muted-foreground\">{{ props.placeholder }}</span>\n </template>\n </template>\n <span class=\"ml-auto flex shrink-0 items-center gap-1\">\n <span\n v-if=\"props.clearable && hasValue && !props.disabled\"\n role=\"button\"\n data-part=\"clear\"\n class=\"text-muted-foreground hover:text-foreground\"\n aria-label=\"清空\"\n @click.stop=\"handleClear\"\n >\n <CloseIcon class=\"size-4 shrink-0\" />\n </span>\n <ChevronIcon\n :class=\"\n cn(\n 'size-4 shrink-0 text-muted-foreground transition-transform',\n isOpen ? '-rotate-90' : 'rotate-90',\n )\n \"\n />\n </span>\n </div>\n </ArkPopover.Anchor>\n\n <!-- 弹层 Teleport:脱离表单 DOM,消除 overflow 容器裁剪隐患(DatePicker 同款);\n 目标经沙箱适配降级(shadow DOM / wujie graft → 应用挂载容器) -->\n <Teleport :to=\"teleportTarget\">\n <ArkPopover.Positioner class=\"z-[var(--z-overlay)]\">\n <ArkPopover.Content\n :class=\"\n cn(\n 'bg-popover text-popover-foreground z-[var(--z-overlay)] rounded-md border p-0 shadow-md outline-none data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95',\n )\n \"\n :style=\"{ minWidth: panelMinWidth }\"\n @keydown=\"handleKeydown\"\n >\n <TreePanel\n :nodes=\"filteredNodes\"\n :selected-keys=\"selectedKeys\"\n :expanded-keys=\"expandedKeys\"\n :active-key=\"activeKey\"\n :checkable=\"props.checkable\"\n :checked-keys=\"checkedState.checked\"\n :indeterminate-keys=\"checkedState.indeterminate\"\n @select=\"selectNode\"\n @toggle=\"toggleNode\"\n />\n </ArkPopover.Content>\n </ArkPopover.Positioner>\n </Teleport>\n </ArkPopover.Root>\n</template>\n"
|
|
20
|
+
"content": "<script setup lang=\"ts\">\nimport type { PropType } from \"vue\";\nimport { computed, getCurrentInstance, nextTick, ref, useAttrs, watch } from \"vue\";\nimport { Popover as ArkPopover } from \"@ark-ui/vue/popover\";\nimport type { PopoverRootProps } from \"@ark-ui/vue/popover\";\nimport { cn } from \"@/lib/utils\";\nimport { controlCls } from \"../date-shared/shared\";\nimport { useControlledBoolean } from \"../overlay-shared/useControlledBoolean\";\nimport { useOverlayIds } from \"../overlay-shared/useOverlayIds\";\nimport { useSandboxTeleportTarget, withSandboxStrategy } from \"../overlay-shared/useSandboxOverlay\";\nimport ChevronIcon from \"../icon-shared/ChevronIcon.vue\";\nimport CloseIcon from \"../icon-shared/CloseIcon.vue\";\nimport ValueTags from \"../tree-shared/ValueTags.vue\";\nimport { createTreeMate, type Key, type TreeNode, type TreeOption } from \"../tree-shared\";\nimport { nextActiveKey, type MoveKey } from \"../tree-shared/keyboard\";\n\n// ids 全量覆盖(无冒号):ArkPopover 浮层载体,规避 wujie patch getElementById\n// 对 zag 缺省冒号 id 的 SyntaxError 刷屏(详注见 useOverlayIds)\nconst { ids: rootIds } = useOverlayIds(useAttrs(), {\n primary: \"content\",\n parts: [\n \"content\",\n \"title\",\n \"description\",\n \"anchor\",\n \"trigger\",\n \"closeTrigger\",\n \"positioner\",\n \"arrow\",\n ],\n});\nimport TreePanel from \"./TreePanel.vue\";\nimport type { TreeSelectTag } from \"./types\";\n\ndefineOptions({ inheritAttrs: false });\n\nconst props = defineProps({\n /** 树选项(key/label/children/disabled) */\n options: { type: Array as PropType<TreeOption[]>, required: true },\n /** 当前值:单选为 key,multiple 为 key 数组;不传走内部非受控 */\n modelValue: {\n type: [String, Number, Array] as PropType<Key | Key[] | undefined>,\n default: undefined,\n },\n defaultValue: {\n type: [String, Number, Array] as PropType<Key | Key[] | undefined>,\n default: undefined,\n },\n /** 多选:值恒为数组,点击节点切换选中 */\n multiple: { type: Boolean, default: false },\n /** 勾选模式:行首渲染 checkbox,值恒为数组(隐含多选语义) */\n checkable: { type: Boolean, default: false },\n /** 勾选级联:勾选父级联动全部子级(默认 false,对齐 naive-ui) */\n cascade: { type: Boolean, default: false },\n /** 勾选策略:all 值含全选节点 / parent 仅父 / child 仅叶(默认 all) */\n checkStrategy: { type: String as PropType<\"all\" | \"parent\" | \"child\">, default: \"all\" },\n /** 弹层开合受控;undefined 走内部非受控(default: undefined 禁用 Boolean casting) */\n open: { type: Boolean as PropType<boolean | undefined>, default: undefined },\n defaultOpen: { type: Boolean, default: false },\n disabled: { type: Boolean as PropType<boolean | undefined>, default: undefined },\n placeholder: { type: String, default: \"请选择\" },\n /** 多选最多展示标签数,超出折叠为 +N */\n maxTagCount: { type: Number, default: undefined },\n /** 展示清空按钮 */\n clearable: { type: Boolean, default: false },\n /** 可搜索:触发器内嵌输入框,按 label 过滤(展示命中节点及其祖先路径) */\n filterable: { type: Boolean, default: false },\n /** 受控展开键集合;undefined 走内部非受控 */\n expandedKeys: { type: Array as PropType<Key[] | undefined>, default: undefined },\n defaultExpandedKeys: { type: Array as PropType<Key[]>, default: () => [] },\n /** 初始展开全部分支 */\n defaultExpandAll: { type: Boolean, default: false },\n /** Ark Popover Root 的 positioning 配置(placement/gutter 等);\n iframe realm(wujie graft / iframe 嵌入)下 strategy 未显式指定时默认 fixed */\n positioning: {\n type: Object as PropType<PopoverRootProps[\"positioning\"]>,\n default: undefined,\n },\n class: { type: String, default: undefined },\n});\n\nconst emit = defineEmits<{\n \"update:modelValue\": [value: Key | Key[] | undefined];\n /** @deprecated 请改用 update:open(v-model:open);下一个 minor 移除 */\n \"update:show\": [open: boolean];\n \"update:open\": [open: boolean];\n \"update:expandedKeys\": [keys: Key[]];\n}>();\n\nif (import.meta.env.DEV && getCurrentInstance()?.vnode.props?.[\"onUpdate:show\"]) {\n console.warn(\"[tu-design] <TreeSelect> update:show 已弃用,请改用 update:open(v-model:open)。\");\n}\n\n// —— 受控桥接(Select/DatePicker 同款):Root 恒走受控,非受控语义由内部 ref 实现 ——\nconst internalValue = ref<Key | Key[] | undefined>(props.defaultValue);\nconst value = computed<Key | Key[] | undefined>(() =>\n props.modelValue !== undefined ? props.modelValue : internalValue.value,\n);\n\n// —— 树数据:options 变更即重建;值中的失效 key 经 getNode 静默忽略 ——\nconst treeMate = computed(() => createTreeMate(props.options, { ignoreEmptyChildren: true }));\n\nconst internalExpanded = ref<Key[]>(\n props.defaultExpandAll\n ? treeMate.value.getNonLeafKeys({ preserveGroup: true })\n : [...props.defaultExpandedKeys],\n);\nconst expandedKeys = computed<Key[]>(() => props.expandedKeys ?? internalExpanded.value);\n\n// defaultExpandAll 只在 options 首次非空时播种:首次计算时异步数据通常还是空树\nlet expandAllSeeded = !props.defaultExpandAll || treeMate.value.treeNodes.length > 0;\nwatch(\n () => props.options,\n () => {\n if (expandAllSeeded || !props.defaultExpandAll || props.expandedKeys !== undefined) return;\n if (treeMate.value.treeNodes.length === 0) return;\n expandAllSeeded = true;\n internalExpanded.value = treeMate.value.getNonLeafKeys({ preserveGroup: true });\n },\n);\n\nfunction handleExpandedUpdate(keys: Key[]) {\n internalExpanded.value = keys;\n emit(\"update:expandedKeys\", keys);\n}\n\nfunction toggleNode(node: TreeNode) {\n const next = expandedKeys.value.includes(node.key)\n ? expandedKeys.value.filter((k) => k !== node.key)\n : [...expandedKeys.value, node.key];\n handleExpandedUpdate(next);\n}\n\nfunction toArrayValue(v: Key | Key[] | undefined): Key[] {\n if (v === undefined) return [];\n return Array.isArray(v) ? v : [v];\n}\n\n// checkable 值语义恒为数组:单值 Key 输入按无选中处理并 dev 警告一次\nlet warnedNonArrayValue = false;\nfunction normalizeValue(v: Key | Key[] | undefined): Key[] {\n if (v === undefined) return [];\n if (Array.isArray(v)) return v;\n if (props.checkable) {\n if (import.meta.env?.DEV && !warnedNonArrayValue) {\n warnedNonArrayValue = true;\n console.warn(\"[TreeSelect] checkable 模式下 modelValue 需为数组,单值输入已按无选中处理。\");\n }\n return [];\n }\n return [v];\n}\n\nconst selectedKeys = computed<Key[]>(() => toArrayValue(value.value));\n\nconst checkOptions = computed(() => ({\n cascade: props.cascade,\n checkStrategy: props.checkStrategy,\n}));\n\n// 勾选模式的展示状态(级联归一后的选中/半选集合)\nconst checkedState = computed<{ checked: Key[]; indeterminate: Key[] }>(() => {\n if (!props.checkable) return { checked: selectedKeys.value, indeterminate: [] };\n const merged = treeMate.value.getCheckedKeys(normalizeValue(value.value), checkOptions.value);\n return { checked: merged.checkedKeys, indeterminate: merged.indeterminateKeys };\n});\n\nconst tags = computed<TreeSelectTag[]>(() =>\n selectedKeys.value\n .map((key) => {\n const node = treeMate.value.getNode(key);\n return node ? { key, label: (node.rawNode as TreeOption).label ?? String(key) } : null;\n })\n .filter((t): t is TreeSelectTag => t !== null),\n);\n\n// checkable 隐含多选语义(值恒为 Key[],与 multiple 等价)\nconst isMulti = computed(() => props.multiple || props.checkable);\n\nconst singleLabel = computed(() => (isMulti.value ? \"\" : (tags.value[0]?.label ?? \"\")));\n\nfunction updateValue(next: Key | Key[] | undefined) {\n internalValue.value = next;\n emit(\"update:modelValue\", next);\n}\n\nfunction selectNode(node: TreeNode) {\n if (node.disabled) return;\n if (props.checkable) {\n const current = normalizeValue(value.value);\n const isNodeChecked = checkedState.value.checked.includes(node.key);\n const merged = isNodeChecked\n ? treeMate.value.uncheck(node.key, current, checkOptions.value)\n : treeMate.value.check(node.key, current, checkOptions.value);\n updateValue(merged.checkedKeys);\n return;\n }\n if (props.multiple) {\n const current = toArrayValue(value.value);\n const next = current.includes(node.key)\n ? current.filter((k) => k !== node.key)\n : [...current, node.key];\n updateValue(next);\n } else {\n updateValue(node.key);\n setOpen(false);\n }\n}\n\n// checkStrategy / cascade 运行时切换:值集合按新策略归一\nwatch(checkOptions, () => {\n if (!props.checkable) return;\n const normalized = treeMate.value.getCheckedKeys(normalizeValue(value.value), checkOptions.value);\n const current = toArrayValue(value.value);\n if (\n normalized.checkedKeys.length !== current.length ||\n normalized.checkedKeys.some((k) => !current.includes(k))\n ) {\n updateValue(normalized.checkedKeys);\n }\n});\n\nfunction removeTag(key: Key) {\n if (props.checkable) {\n const merged = treeMate.value.uncheck(key, normalizeValue(value.value), checkOptions.value);\n updateValue(merged.checkedKeys);\n return;\n }\n updateValue(toArrayValue(value.value).filter((k) => k !== key));\n}\n\nconst hasValue = computed(() => tags.value.length > 0);\n\nfunction handleClear() {\n const next = isMulti.value ? [] : undefined;\n internalValue.value = next;\n emit(\"update:modelValue\", next);\n}\n\n// —— 弹层开合(点击/键盘 ↓ 显式驱动,保证各环境一致)——\nconst { isOpen, setOpen } = useControlledBoolean({\n controlled: () => props.open,\n defaultValue: () => props.defaultOpen,\n onChange: (open) => {\n emit(\"update:open\", open);\n emit(\"update:show\", open);\n },\n});\n\n// —— 沙箱适配(机制详注见 useSandboxOverlay / sandbox.ts):Teleport 目标降级\n// (shadow DOM / wujie graft → 应用挂载容器,避免面板落入 iframe body)+\n// iframe realm 下 strategy 默认 fixed(absolute 包含块错位,fixed 唯一正确解);\n// 无 to prop,面板恒传送 ——\nconst teleportTarget = useSandboxTeleportTarget(() => undefined);\nconst rootPositioning = computed(() =>\n withSandboxStrategy(props.positioning, { ...props.positioning }),\n);\n\nfunction openFromInput() {\n if (props.disabled || isOpen.value) return;\n syncPanelWidth();\n setOpen(true);\n}\n\n// —— 面板宽度对齐触发器 ——\nconst triggerEl = ref<HTMLElement | null>(null);\nconst panelMinWidth = ref(\"0px\");\nfunction syncPanelWidth() {\n panelMinWidth.value = `${triggerEl.value?.offsetWidth ?? 0}px`;\n}\n\nconst visibleNodes = computed(() => treeMate.value.getFlattenedNodes(expandedKeys.value));\n\n// —— 过滤:命中节点及其祖先路径可见(搜索态下全树展开)——\nconst pattern = ref(\"\");\nconst searchPattern = computed(() => pattern.value.trim().toLowerCase());\nconst filteredNodes = computed<TreeNode[]>(() => {\n if (!props.filterable || !searchPattern.value) return visibleNodes.value;\n const mate = treeMate.value;\n // 命中节点与其全部祖先均保留(祖先自身无命中也保留)\n const keep = new Set<Key>();\n const allNodes = mate.getFlattenedNodes(mate.getNonLeafKeys({ preserveGroup: true }));\n for (const node of allNodes) {\n const path = mate.getPath(node.key);\n if (path.treeNodePath.some((tn) => labelOf(tn).toLowerCase().includes(searchPattern.value))) {\n path.treeNodePath.forEach((tn) => keep.add(tn.key));\n }\n }\n return allNodes.filter((n) => keep.has(n.key));\n});\n\nfunction labelOf(node: TreeNode): string {\n return (node.rawNode as TreeOption).label ?? String(node.key);\n}\n\n// —— 键盘导航(↑↓←→ / Home / End / Enter,游标仅落在非 disabled 节点)——\nconst activeKey = ref<Key | null>(null);\nconst MOVE_KEYS: MoveKey[] = [\"ArrowDown\", \"ArrowUp\", \"Home\", \"End\"];\n\nfunction scrollActiveIntoView() {\n nextTick(() => {\n document\n .querySelector('[data-part=\"tree-node\"][data-active]')\n ?.scrollIntoView?.({ block: \"nearest\" });\n });\n}\n\nfunction moveHorizontally(expand: boolean) {\n if (activeKey.value === null) return;\n const node = filteredNodes.value.find((n) => n.key === activeKey.value);\n if (!node) return;\n if (expand) {\n if (node.isLeaf || !node.children?.length) return;\n if (!expandedKeys.value.includes(node.key)) {\n handleExpandedUpdate([...expandedKeys.value, node.key]);\n return;\n }\n const firstChild = node.children.find((c) => !c.disabled);\n if (firstChild) activeKey.value = firstChild.key;\n } else {\n if (node.children?.length && expandedKeys.value.includes(node.key)) {\n handleExpandedUpdate(expandedKeys.value.filter((k) => k !== node.key));\n return;\n }\n if (node.parent && !node.parent.ignored) activeKey.value = node.parent.key;\n }\n}\n\nfunction handleKeydown(e: KeyboardEvent) {\n if (props.disabled) return;\n if (!isOpen.value) {\n if (e.key === \"ArrowDown\" || e.key === \"Enter\") {\n e.preventDefault();\n openFromInput();\n }\n return;\n }\n if ((MOVE_KEYS as string[]).includes(e.key)) {\n e.preventDefault();\n activeKey.value = nextActiveKey(filteredNodes.value, activeKey.value, e.key as MoveKey);\n scrollActiveIntoView();\n return;\n }\n if (e.key === \"ArrowRight\" || e.key === \"ArrowLeft\") {\n e.preventDefault();\n moveHorizontally(e.key === \"ArrowRight\");\n return;\n }\n if (e.key === \"Enter\") {\n e.preventDefault();\n const node = filteredNodes.value.find((n) => n.key === activeKey.value);\n if (node) selectNode(node);\n }\n}\n\n// 弹层开合时重置键盘游标与搜索词\nwatch(isOpen, (open) => {\n activeKey.value = null;\n if (open) syncPanelWidth();\n else pattern.value = \"\";\n});\n</script>\n\n<template>\n <ArkPopover.Root\n :ids=\"rootIds\"\n :open=\"isOpen\"\n :positioning=\"rootPositioning\"\n @update:open=\"setOpen\"\n >\n <ArkPopover.Anchor as-child>\n <div\n ref=\"triggerEl\"\n v-bind=\"$attrs\"\n data-part=\"trigger\"\n role=\"button\"\n tabindex=\"0\"\n :aria-expanded=\"isOpen\"\n aria-haspopup=\"true\"\n :aria-disabled=\"props.disabled || undefined\"\n :class=\"\n cn(\n controlCls,\n 'min-h-9 cursor-pointer gap-2 px-3 py-1.5 text-sm',\n props.disabled && 'cursor-not-allowed opacity-50',\n props.class,\n )\n \"\n @click=\"openFromInput\"\n @keydown=\"handleKeydown\"\n >\n <template v-if=\"isMulti\">\n <ValueTags\n v-if=\"tags.length\"\n :values=\"tags\"\n :max-tag-count=\"props.maxTagCount\"\n :disabled=\"!!props.disabled\"\n @remove=\"removeTag\"\n />\n <input\n v-if=\"props.filterable\"\n v-model=\"pattern\"\n data-part=\"input\"\n type=\"text\"\n class=\"h-5 w-12 min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground\"\n :placeholder=\"tags.length ? '' : props.placeholder\"\n :aria-label=\"props.placeholder\"\n />\n <span v-if=\"!tags.length && !props.filterable\" class=\"truncate text-muted-foreground\">{{\n props.placeholder\n }}</span>\n </template>\n <template v-else>\n <input\n v-if=\"props.filterable\"\n v-model=\"pattern\"\n data-part=\"input\"\n type=\"text\"\n class=\"h-full w-full min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground\"\n :placeholder=\"singleLabel || props.placeholder\"\n :aria-label=\"props.placeholder\"\n />\n <template v-else>\n <span v-if=\"singleLabel\" class=\"truncate\">{{ singleLabel }}</span>\n <span v-else class=\"truncate text-muted-foreground\">{{ props.placeholder }}</span>\n </template>\n </template>\n <span class=\"ml-auto flex shrink-0 items-center gap-1\">\n <span\n v-if=\"props.clearable && hasValue && !props.disabled\"\n role=\"button\"\n data-part=\"clear\"\n class=\"text-muted-foreground hover:text-foreground\"\n aria-label=\"清空\"\n @click.stop=\"handleClear\"\n >\n <CloseIcon class=\"size-4 shrink-0\" />\n </span>\n <ChevronIcon\n :class=\"\n cn(\n 'size-4 shrink-0 text-muted-foreground transition-transform',\n isOpen ? '-rotate-90' : 'rotate-90',\n )\n \"\n />\n </span>\n </div>\n </ArkPopover.Anchor>\n\n <!-- 弹层 Teleport:脱离表单 DOM,消除 overflow 容器裁剪隐患(DatePicker 同款);\n 目标经沙箱适配降级(shadow DOM / wujie graft → 应用挂载容器) -->\n <Teleport :to=\"teleportTarget\">\n <ArkPopover.Positioner class=\"z-[var(--z-modal,60)]\">\n <ArkPopover.Content\n :class=\"\n cn(\n 'bg-popover text-popover-foreground z-[var(--z-modal,60)] rounded-md border p-0 shadow-md outline-none data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95',\n )\n \"\n :style=\"{ minWidth: panelMinWidth }\"\n @keydown=\"handleKeydown\"\n >\n <TreePanel\n :nodes=\"filteredNodes\"\n :selected-keys=\"selectedKeys\"\n :expanded-keys=\"expandedKeys\"\n :active-key=\"activeKey\"\n :checkable=\"props.checkable\"\n :checked-keys=\"checkedState.checked\"\n :indeterminate-keys=\"checkedState.indeterminate\"\n @select=\"selectNode\"\n @toggle=\"toggleNode\"\n />\n </ArkPopover.Content>\n </ArkPopover.Positioner>\n </Teleport>\n </ArkPopover.Root>\n</template>\n"
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
"path": "tree-select/index.ts",
|
|
@@ -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.10",
|
|
5
5
|
"type": "registry:ui",
|
|
6
6
|
"description": "树形数据层与共享类型(移植自 treemate v0.3.11,MIT)。",
|
|
7
7
|
"registryDependencies": ["icon-shared", "utils"],
|
|
@@ -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.10",
|
|
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"],
|
|
@@ -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.10",
|
|
5
5
|
"type": "registry:ui",
|
|
6
6
|
"description": "周选择器:输入框 + 日历弹层,点任意可选日归一到所在周并整周高亮,值以 \"yyyy-MM-dd\"(所在周起始日)字符串受控;周起点跟随 locale(zh-CN 周一起始),输入框回显 \"start ~ end\"。",
|
|
7
7
|
"registryDependencies": ["utils", "date-shared", "calendar"],
|
|
@@ -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.10",
|
|
5
5
|
"type": "registry:ui",
|
|
6
6
|
"description": "年份选择器:输入框 + 锁定年视图的日历弹层(decade 网格),值以 \"yyyy\" 字符串受控,min/max 为年粒度闭区间。",
|
|
7
7
|
"registryDependencies": ["utils", "date-shared", "calendar"],
|