@tu-design/vue 0.2.2 → 0.3.0

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.
Files changed (37) hide show
  1. package/dist/index.d.mts +3365 -1104
  2. package/dist/index.mjs +7167 -1354
  3. package/dist/registry/vue/alert.json +22 -0
  4. package/dist/registry/vue/avatar-group.json +21 -0
  5. package/dist/registry/vue/avatar.json +3 -3
  6. package/dist/registry/vue/calendar.json +34 -0
  7. package/dist/registry/vue/card.json +3 -33
  8. package/dist/registry/vue/cascader.json +34 -0
  9. package/dist/registry/vue/checkbox.json +1 -1
  10. package/dist/registry/vue/currency-input.json +1 -1
  11. package/dist/registry/vue/date-picker.json +22 -0
  12. package/dist/registry/vue/date-range-picker.json +22 -0
  13. package/dist/registry/vue/date-shared.json +26 -0
  14. package/dist/registry/vue/dialog.json +3 -45
  15. package/dist/registry/vue/dropdown-menu.json +11 -35
  16. package/dist/registry/vue/empty.json +21 -0
  17. package/dist/registry/vue/form-render.json +115 -0
  18. package/dist/registry/vue/form.json +2 -2
  19. package/dist/registry/vue/month-picker.json +22 -0
  20. package/dist/registry/vue/number-input.json +1 -1
  21. package/dist/registry/vue/popover.json +3 -15
  22. package/dist/registry/vue/progress.json +22 -0
  23. package/dist/registry/vue/radio-group.json +2 -8
  24. package/dist/registry/vue/registry.json +114 -6
  25. package/dist/registry/vue/select.json +3 -27
  26. package/dist/registry/vue/slider.json +1 -1
  27. package/dist/registry/vue/spin.json +22 -0
  28. package/dist/registry/vue/table-render.json +62 -0
  29. package/dist/registry/vue/tabs.json +2 -20
  30. package/dist/registry/vue/toast.json +28 -0
  31. package/dist/registry/vue/tokens.json +1 -1
  32. package/dist/registry/vue/tooltip.json +2 -14
  33. package/dist/registry/vue/tree-select.json +34 -0
  34. package/dist/registry/vue/tree-shared.json +92 -0
  35. package/dist/registry/vue/week-picker.json +22 -0
  36. package/dist/registry/vue/year-picker.json +22 -0
  37. package/package.json +3 -1
@@ -0,0 +1,92 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
3
+ "name": "tree-shared",
4
+ "type": "registry:ui",
5
+ "description": "树形数据层与共享类型(移植自 treemate v0.3.11,MIT)。",
6
+ "files": [
7
+ {
8
+ "path": "tree-shared/ChevronIcon.vue",
9
+ "type": "registry:component",
10
+ "target": "components/ui/tree-shared/ChevronIcon.vue",
11
+ "content": "<template>\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n aria-hidden=\"true\"\n class=\"size-4 shrink-0 transition-transform\"\n >\n <path d=\"m9 18 6-6-6-6\" />\n </svg>\n</template>\n"
12
+ },
13
+ {
14
+ "path": "tree-shared/ClearIcon.vue",
15
+ "type": "registry:component",
16
+ "target": "components/ui/tree-shared/ClearIcon.vue",
17
+ "content": "<template>\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n aria-hidden=\"true\"\n class=\"size-4 shrink-0\"\n >\n <path d=\"M18 6 6 18\" />\n <path d=\"m6 6 12 12\" />\n </svg>\n</template>\n"
18
+ },
19
+ {
20
+ "path": "tree-shared/ValueTags.vue",
21
+ "type": "registry:component",
22
+ "target": "components/ui/tree-shared/ValueTags.vue",
23
+ "content": "<script setup lang=\"ts\">\nimport type { PropType } from \"vue\";\nimport { computed } from \"vue\";\nimport type { Key } from \"./interface\";\n\nconst props = defineProps({\n /** 展示的选中值(key + label) */\n values: { type: Array as PropType<{ key: Key; label: string }[]>, required: true },\n /** 最多展示的 tag 数,超出折叠为 +N */\n maxTagCount: { type: Number, default: undefined },\n /** 展示尾部清空按钮(清空动作由宿主处理) */\n clearable: { type: Boolean, default: false },\n disabled: { type: Boolean, default: false },\n});\n\nconst emit = defineEmits<{\n remove: [key: Key];\n clear: [];\n}>();\n\nconst shown = computed(() =>\n props.maxTagCount === undefined ? props.values : props.values.slice(0, props.maxTagCount),\n);\nconst overflow = computed(() =>\n props.maxTagCount === undefined ? 0 : Math.max(0, props.values.length - props.maxTagCount),\n);\n</script>\n\n<template>\n <span class=\"flex min-w-0 flex-1 flex-wrap items-center gap-1\">\n <span\n v-for=\"v in shown\"\n :key=\"v.key\"\n data-part=\"tag\"\n :data-key=\"v.key\"\n class=\"inline-flex max-w-full items-center gap-0.5 rounded-sm bg-accent px-1.5 py-0.5 text-xs font-normal text-accent-foreground\"\n >\n <span class=\"truncate\">{{ v.label }}</span>\n <button\n v-if=\"!disabled\"\n type=\"button\"\n data-part=\"tag-remove\"\n class=\"text-muted-foreground hover:text-foreground\"\n :aria-label=\"`移除 ${v.label}`\"\n @click.stop=\"emit('remove', v.key)\"\n >\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n class=\"size-3\"\n aria-hidden=\"true\"\n >\n <path d=\"M18 6 6 18\" />\n <path d=\"m6 6 12 12\" />\n </svg>\n </button>\n </span>\n <span v-if=\"overflow > 0\" data-part=\"tag-overflow\" class=\"text-xs text-muted-foreground\"\n >+{{ overflow }}</span\n >\n <button\n v-if=\"clearable && !disabled\"\n type=\"button\"\n data-part=\"clear\"\n class=\"ml-auto shrink-0 text-muted-foreground hover:text-foreground\"\n aria-label=\"清空\"\n @click.stop=\"emit('clear')\"\n >\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n class=\"size-4\"\n aria-hidden=\"true\"\n >\n <path d=\"M18 6 6 18\" />\n <path d=\"m6 6 12 12\" />\n </svg>\n </button>\n </span>\n</template>\n"
24
+ },
25
+ {
26
+ "path": "tree-shared/check.ts",
27
+ "type": "registry:component",
28
+ "target": "components/ui/tree-shared/check.ts",
29
+ "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"
30
+ },
31
+ {
32
+ "path": "tree-shared/contains.ts",
33
+ "type": "registry:component",
34
+ "target": "components/ui/tree-shared/contains.ts",
35
+ "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"
36
+ },
37
+ {
38
+ "path": "tree-shared/create.ts",
39
+ "type": "registry:component",
40
+ "target": "components/ui/tree-shared/create.ts",
41
+ "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"
42
+ },
43
+ {
44
+ "path": "tree-shared/flatten.ts",
45
+ "type": "registry:component",
46
+ "target": "components/ui/tree-shared/flatten.ts",
47
+ "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"
48
+ },
49
+ {
50
+ "path": "tree-shared/index.ts",
51
+ "type": "registry:component",
52
+ "target": "components/ui/tree-shared/index.ts",
53
+ "content": "export { createTreeMate } from \"./create\";\nexport { flatten } from \"./flatten\";\nexport type {\n CheckStrategy,\n Key,\n KeyedRawNode,\n MergedKeys,\n RawNode,\n TreeNode,\n TreeMate,\n} from \"./interface\";\nexport type { TreeOption } from \"./types\";\n"
54
+ },
55
+ {
56
+ "path": "tree-shared/interface.ts",
57
+ "type": "registry:component",
58
+ "target": "components/ui/tree-shared/interface.ts",
59
+ "content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:无实质改动(仅类型导入顺序与注释格式)。\n */\nexport type Key = string | number;\n\nexport type CheckStrategy = \"all\" | \"child\" | \"parent\";\n\nexport interface RawNode {\n key?: Key;\n children?: RawNode[];\n isLeaf?: boolean;\n disabled?: boolean;\n [key: string]: unknown;\n}\n\nexport interface KeyedRawNode {\n key: Key;\n children?: KeyedRawNode[];\n isLeaf?: boolean;\n disabled?: boolean;\n [key: string]: unknown;\n}\n\nexport interface GetPrevNextOptions {\n loop?: boolean;\n includeDisabled?: boolean;\n}\n\n// R=RawNode, G=GroupNode, I=IgnoredNode\nexport interface TreeNode<R = RawNode, G = R, I = R> {\n key: Key;\n rawNode: R | G | I;\n level: number;\n index: number;\n isFirstChild: boolean;\n isLastChild: boolean;\n parent: TreeNode<R, G> | null;\n isLeaf: boolean;\n isGroup: boolean;\n ignored: boolean;\n shallowLoaded: boolean;\n disabled: boolean;\n siblings: Array<TreeNode<R, G, I>>;\n children?: Array<TreeNode<R, G, I>>;\n getPrev: (options?: GetPrevNextOptions) => TreeNode<R> | null;\n getNext: (options?: GetPrevNextOptions) => TreeNode<R> | null;\n getParent: () => TreeNode<R> | null;\n getChild: () => TreeNode<R> | null;\n contains: (treeNode: TreeNode<R, G, I> | null | undefined) => boolean;\n}\n\nexport type TreeNodeMap<R, G, I> = Map<Key, TreeNode<R, G, I>>;\n\nexport type LevelTreeNodeMap<R, G, I> = Map<number, Array<TreeNode<R, G, I>>>;\n\nexport interface MergedKeys {\n checkedKeys: Key[];\n indeterminateKeys: Key[];\n}\n\nexport type GetChildren<R, G, I> = (node: R | G | I) => Array<R | G | I> | unknown;\n\nexport interface TreeMateOptions<R, G, I> {\n ignoreEmptyChildren?: boolean;\n getChildren?: GetChildren<R, G, I>;\n getKey?: (node: R | G | I) => Key;\n getDisabled?: (node: R | G | I) => boolean;\n getIsGroup?: (node: R | G | I) => boolean;\n getIgnored?: (node: R | G | I) => boolean;\n}\n\nexport interface MergedPath<R, G = R> {\n keyPath: Key[];\n treeNodePath: Array<TreeNode<R, G>>;\n treeNode: TreeNode<R, G> | null;\n}\n\nexport interface GetPathOptions<T extends boolean> {\n includeGroup?: T;\n includeSelf?: boolean;\n}\n\nexport interface InputMergedKeys {\n checkedKeys?: Key[] | null;\n indeterminateKeys?: Key[] | null;\n}\n\nexport interface CheckOptions {\n cascade?: boolean;\n checkStrategy?: CheckStrategy;\n /** @deprecated */\n leafOnly?: boolean;\n}\n\ntype KeyToNode<R, G> = <T extends Key | null | undefined>(\n key: T,\n) => T extends null | undefined ? null : TreeNode<R, G> | null;\ntype KeyToNonGroupNode<R> = <T extends Key | null | undefined>(\n key: T,\n) => T extends null | undefined ? null : TreeNode<R, R> | null;\ntype KeyToNonGroupNodeWithOptions<R> = <T extends Key | null | undefined>(\n key: T,\n options?: GetPrevNextOptions,\n) => T extends null | undefined ? null : TreeNode<R, R> | null;\n\nexport interface GetNonLeafKeysOptions {\n preserveGroup?: boolean;\n}\n\nexport interface TreeMate<R = RawNode, G = R, I = R> {\n treeNodes: Array<TreeNode<R, G, I>>;\n treeNodeMap: TreeNodeMap<R, G, I>;\n levelTreeNodeMap: LevelTreeNodeMap<R, G, I>;\n /** start from 0 */\n maxLevel: number;\n // flattened nodes is view related, so Ignored should be included\n getFlattenedNodes: (expandedKeys?: Key[]) => Array<TreeNode<R, G, I>>;\n // I don't want Ignored & GroupNode to be accessed by getNode\n getNode: KeyToNode<R, R>;\n getChildren: GetChildren<R, G, I>;\n // check related methods\n getCheckedKeys: (\n checkedKeys: Key[] | InputMergedKeys | null | undefined,\n options?: CheckOptions,\n ) => MergedKeys;\n check: (\n keysToCheck: Key | Key[] | null | undefined,\n checkedKeys: Key[] | InputMergedKeys,\n options?: CheckOptions,\n ) => MergedKeys;\n uncheck: (\n keysToUncheck: Key | Key[] | null | undefined,\n checkedKeys: Key[] | InputMergedKeys,\n options?: CheckOptions,\n ) => MergedKeys;\n getNonLeafKeys: (options?: GetNonLeafKeysOptions) => Key[];\n // If include group, GroupNode & RawNode will be included\n // If not include group, only RawNode will be included\n getPath: <T extends boolean>(\n key: Key | null | undefined,\n options?: GetPathOptions<T>,\n ) => T extends true ? MergedPath<R, G> : MergedPath<R>;\n // In movement related methods, only RawNode can be accessed\n getFirstAvailableNode: () => TreeNode<R> | null;\n getPrev: KeyToNonGroupNodeWithOptions<R>;\n getNext: KeyToNonGroupNodeWithOptions<R>;\n getParent: KeyToNonGroupNode<R>;\n getChild: KeyToNonGroupNode<R>;\n}\n"
60
+ },
61
+ {
62
+ "path": "tree-shared/keyboard.ts",
63
+ "type": "registry:component",
64
+ "target": "components/ui/tree-shared/keyboard.ts",
65
+ "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"
66
+ },
67
+ {
68
+ "path": "tree-shared/move.ts",
69
+ "type": "registry:component",
70
+ "target": "components/ui/tree-shared/move.ts",
71
+ "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"
72
+ },
73
+ {
74
+ "path": "tree-shared/path.ts",
75
+ "type": "registry:component",
76
+ "target": "components/ui/tree-shared/path.ts",
77
+ "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"
78
+ },
79
+ {
80
+ "path": "tree-shared/types.ts",
81
+ "type": "registry:component",
82
+ "target": "components/ui/tree-shared/types.ts",
83
+ "content": "import type { Key } from \"./interface\";\n\n/** 组件公开的选项类型:key/label/children 常用字段显式化,其余字段透传(对齐 naive-ui TreeOption) */\nexport interface TreeOption {\n key: Key;\n label?: string;\n children?: TreeOption[];\n disabled?: boolean;\n isLeaf?: boolean;\n [key: string]: unknown;\n}\n"
84
+ },
85
+ {
86
+ "path": "tree-shared/utils.ts",
87
+ "type": "registry:component",
88
+ "target": "components/ui/tree-shared/utils.ts",
89
+ "content": "/*!\n * 移植自 treemate v0.3.11 —— https://github.com/07akioni/treemate\n * MIT License · Copyright (c) 07akioni\n * 本地改动:无实质改动。\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): Array<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"
90
+ }
91
+ ]
92
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
3
+ "name": "week-picker",
4
+ "type": "registry:ui",
5
+ "description": "周选择器:输入框 + 日历弹层,点任意可选日归一到所在周并整周高亮,值以 \"yyyy-MM-dd\"(所在周起始日)字符串受控;周起点跟随 locale(zh-CN 周一起始),输入框回显 \"start ~ end\"。",
6
+ "registryDependencies": ["utils", "date-shared", "calendar"],
7
+ "dependencies": ["@ark-ui/vue@^5.39.2"],
8
+ "files": [
9
+ {
10
+ "path": "week-picker/WeekPicker.vue",
11
+ "type": "registry:component",
12
+ "target": "components/ui/week-picker/WeekPicker.vue",
13
+ "content": "<script setup lang=\"ts\">\nimport type { DateValue } from \"@ark-ui/vue/date-picker\";\nimport { DatePicker as ArkDatePicker } from \"@ark-ui/vue/date-picker\";\nimport type { PropType } from \"vue\";\nimport { computed, provide, ref } from \"vue\";\nimport { cn } from \"@/lib/utils\";\nimport { Calendar as TCalendar } from \"../calendar\";\n// SFC 仅 default export,必须默认导入\nimport CalendarIcon from \"../date-shared/CalendarIcon.vue\";\nimport ClearIcon from \"../date-shared/ClearIcon.vue\";\nimport {\n CALENDAR_IN_PICKER,\n controlCls,\n formatIsoWeek,\n iconBtnCls,\n parseIsoDate,\n weekStartOf,\n} from \"../date-shared/shared\";\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 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// —— 受控桥接(DatePicker 同款;值域语义 = 所在周起始日)——\nconst internalValue = ref<string | null>(\n props.defaultValue ? formatIsoWeekStart(props.defaultValue) : null,\n);\nconst selected = computed(() => {\n const raw = props.modelValue !== undefined ? props.modelValue : internalValue.value;\n return parseIsoDate(raw ?? \"\");\n});\n// 单值收敛为 [weekStart];整周高亮由 TCalendar week 形态按同周判定补齐,不走 zag range 模式\n// (range 模式首次点击只落起点、需二次点击闭合,与「点一下选一周」语义冲突)\nconst rootValue = computed<DateValue[]>(() => (selected.value ? [selected.value] : []));\n\nconst internalOpen = ref(props.defaultOpen);\nconst isOpen = computed(() => props.open ?? internalOpen.value);\n\nconst minDate = computed(() => parseIsoDate(props.min ?? \"\"));\nconst maxDate = computed(() => parseIsoDate(props.max ?? \"\"));\n\n/** \"yyyy-MM-dd\" → 归一到所在周起始日的 ISO 串(非法输入原样返回 undefined) */\nfunction formatIsoWeekStart(raw: string): string | undefined {\n const date = parseIsoDate(raw);\n return date ? weekStartOf(date, props.locale).toString() : undefined;\n}\n\n/** zag value → 公开值域:点任意日归一到该周起始日;清空 → null */\nfunction handleValueUpdate(next: DateValue[]) {\n const value = next[0] ? (formatIsoWeekStart(next[0].toString()) ?? null) : null;\n internalValue.value = value;\n emit(\"update:modelValue\", value);\n}\n\nfunction handleOpenUpdate(next: boolean) {\n internalOpen.value = next;\n emit(\"update:open\", next);\n}\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\n// 点击/键盘 ↓ 输入框即开弹层(zag 默认仅 Trigger 开,openOnClick prop 默认关闭;\n// 显式驱动保证各环境行为一致并显式走受控 emit)\nfunction openFromInput() {\n if (props.disabled || props.readOnly || isOpen.value) return;\n handleOpenUpdate(true);\n}\n</script>\n\n<template>\n <ArkDatePicker.Root\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 :format=\"formatDate\"\n :parse=\"parseDate\"\n @update:model-value=\"handleValueUpdate\"\n @update:open=\"handleOpenUpdate\"\n >\n <ArkDatePicker.Control\n :class=\"cn(controlCls, props.class)\"\n :data-invalid=\"props.invalid ? '' : undefined\"\n >\n <ArkDatePicker.Input\n v-bind=\"$attrs\"\n :placeholder=\"props.placeholder\"\n :aria-invalid=\"props.invalid || undefined\"\n class=\"bg-transparent h-full w-full min-w-0 flex-1 px-3 text-sm tabular-nums outline-none\"\n @click=\"openFromInput\"\n @keydown.down.prevent=\"openFromInput\"\n />\n <ArkDatePicker.ClearTrigger :class=\"iconBtnCls\">\n <ClearIcon />\n </ArkDatePicker.ClearTrigger>\n <ArkDatePicker.Trigger :class=\"iconBtnCls\">\n <CalendarIcon />\n </ArkDatePicker.Trigger>\n </ArkDatePicker.Control>\n\n <!-- 弹层 Teleport 到 body:脱离表单 DOM——隔离外层 FormControl 的 group class\n (group-hover 会污染面板内全部格子),并消除 overflow 容器裁剪弹层的隐患。 -->\n <Teleport to=\"body\">\n <ArkDatePicker.Positioner class=\"z-50\">\n <ArkDatePicker.Content\n :class=\"\n cn(\n 'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 relative z-50 rounded-md border shadow-md',\n )\n \"\n >\n <TCalendar week :locale=\"props.locale\" />\n </ArkDatePicker.Content>\n </ArkDatePicker.Positioner>\n </Teleport>\n </ArkDatePicker.Root>\n</template>\n"
14
+ },
15
+ {
16
+ "path": "week-picker/index.ts",
17
+ "type": "registry:component",
18
+ "target": "components/ui/week-picker/index.ts",
19
+ "content": "export { default as WeekPicker } from \"./WeekPicker.vue\";\n"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
3
+ "name": "year-picker",
4
+ "type": "registry:ui",
5
+ "description": "年份选择器:输入框 + 锁定年视图的日历弹层(decade 网格),值以 \"yyyy\" 字符串受控,min/max 为年粒度闭区间。",
6
+ "registryDependencies": ["utils", "date-shared", "calendar"],
7
+ "dependencies": ["@ark-ui/vue@^5.39.2"],
8
+ "files": [
9
+ {
10
+ "path": "year-picker/YearPicker.vue",
11
+ "type": "registry:component",
12
+ "target": "components/ui/year-picker/YearPicker.vue",
13
+ "content": "<script setup lang=\"ts\">\nimport type { DateValue } from \"@ark-ui/vue/date-picker\";\nimport { DatePicker as ArkDatePicker } from \"@ark-ui/vue/date-picker\";\nimport type { PropType } from \"vue\";\nimport { computed, provide, ref } from \"vue\";\nimport { cn } from \"@/lib/utils\";\nimport { Calendar as TCalendar } from \"../calendar\";\n// SFC 仅 default export,必须默认导入\nimport CalendarIcon from \"../date-shared/CalendarIcon.vue\";\nimport ClearIcon from \"../date-shared/ClearIcon.vue\";\nimport {\n CALENDAR_IN_PICKER,\n controlCls,\n formatIsoYear,\n iconBtnCls,\n parseIsoYear,\n} from \"../date-shared/shared\";\n\nconst props = defineProps({\n /** 受控年份(\"yyyy\");undefined 走内部非受控,null 表示空 */\n modelValue: { type: String as PropType<string | null | undefined>, default: undefined },\n /** 非受控初值(\"yyyy\") */\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\",含当年) */\n min: { type: String, default: undefined },\n /** 可选上界(\"yyyy\",含当年) */\n max: { type: String, default: undefined },\n /** 选中后是否自动关弹层 */\n closeOnSelect: { type: Boolean, default: true },\n /** 文案与周起点跟随 locale */\n locale: { type: String, default: \"zh-CN\" },\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// —— 受控桥接(与 DatePicker 同款简化版:单值无 mirror 需求)——\nconst internalValue = ref<string | null>(props.defaultValue ?? null);\nconst selected = computed(() => {\n const raw = props.modelValue !== undefined ? props.modelValue : internalValue.value;\n return parseIsoYear(raw ?? \"\");\n});\n// zag value 为 DateValue[] 数组形态,单选语义收敛为 [date] | []\nconst rootValue = computed<DateValue[]>(() => (selected.value ? [selected.value] : []));\n\nconst internalOpen = ref(props.defaultOpen);\nconst isOpen = computed(() => props.open ?? internalOpen.value);\n\n// 年格 disabled 只比 min?.year/max?.year(zag connect isValueWithinRange),\n// 锚 1 月 1 日即安全,无需 MonthPicker 的末日换算\nconst minDate = computed(() => parseIsoYear(props.min ?? \"\"));\nconst maxDate = computed(() => parseIsoYear(props.max ?? \"\"));\n\nfunction handleValueUpdate(next: DateValue[]) {\n const value = next[0] ? formatIsoYear(next[0]) : null;\n internalValue.value = value;\n emit(\"update:modelValue\", value);\n}\n\nfunction handleOpenUpdate(next: boolean) {\n internalOpen.value = next;\n emit(\"update:open\", next);\n}\n\n// 点击/键盘 ↓ 输入框即开弹层(zag 默认仅 Trigger 开,openOnClick prop 默认关闭;\n// 显式驱动保证各环境行为一致并显式走受控 emit)\nfunction openFromInput() {\n if (props.disabled || props.readOnly || isOpen.value) return;\n handleOpenUpdate(true);\n}\n</script>\n\n<template>\n <ArkDatePicker.Root\n :model-value=\"rootValue\"\n :open=\"isOpen\"\n :locale=\"props.locale\"\n :min-view=\"'year'\"\n :max-view=\"'year'\"\n :min=\"minDate\"\n :max=\"maxDate\"\n :close-on-select=\"props.closeOnSelect\"\n :read-only=\"props.readOnly\"\n :disabled=\"props.disabled\"\n :format=\"formatIsoYear\"\n :parse=\"parseIsoYear\"\n @update:model-value=\"handleValueUpdate\"\n @update:open=\"handleOpenUpdate\"\n >\n <ArkDatePicker.Control\n :class=\"cn(controlCls, props.class)\"\n :data-invalid=\"props.invalid ? '' : undefined\"\n >\n <ArkDatePicker.Input\n v-bind=\"$attrs\"\n :placeholder=\"props.placeholder\"\n :aria-invalid=\"props.invalid || undefined\"\n class=\"bg-transparent h-full w-full min-w-0 flex-1 px-3 text-sm tabular-nums outline-none\"\n @click=\"openFromInput\"\n @keydown.down.prevent=\"openFromInput\"\n />\n <ArkDatePicker.ClearTrigger :class=\"iconBtnCls\">\n <ClearIcon />\n </ArkDatePicker.ClearTrigger>\n <ArkDatePicker.Trigger :class=\"iconBtnCls\">\n <CalendarIcon />\n </ArkDatePicker.Trigger>\n </ArkDatePicker.Control>\n\n <!-- 弹层 Teleport 到 body:脱离表单 DOM——隔离外层 FormControl 的 group class\n (group-hover 会污染面板内全部格子),并消除 overflow 容器裁剪弹层的隐患。 -->\n <Teleport to=\"body\">\n <ArkDatePicker.Positioner class=\"z-50\">\n <ArkDatePicker.Content\n :class=\"\n cn(\n 'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 relative z-50 rounded-md border shadow-md',\n )\n \"\n >\n <TCalendar mode=\"year\" />\n </ArkDatePicker.Content>\n </ArkDatePicker.Positioner>\n </Teleport>\n </ArkDatePicker.Root>\n</template>\n"
14
+ },
15
+ {
16
+ "path": "year-picker/index.ts",
17
+ "type": "registry:component",
18
+ "target": "components/ui/year-picker/index.ts",
19
+ "content": "export { default as YearPicker } from \"./YearPicker.vue\";\n"
20
+ }
21
+ ]
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tu-design/vue",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "shadcn 风格的 Vue 3 组件库:Tailwind CSS v4 主题 + Ark UI 原语,CLI 分发组件源码。",
5
5
  "keywords": [
6
6
  "components",
@@ -34,6 +34,8 @@
34
34
  "dependencies": {
35
35
  "@ark-ui/vue": "^5.39.2",
36
36
  "@tanstack/vue-form": "^1.33.5",
37
+ "@tanstack/vue-table": "^8.21.3",
38
+ "@tanstack/vue-virtual": "^3.13.47",
37
39
  "class-variance-authority": "^0.7.1",
38
40
  "clsx": "^2.1.1",
39
41
  "tailwind-merge": "^3.7.0",