king-design-analyzer 2.1.2 → 2.1.3

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.
@@ -0,0 +1,92 @@
1
+ {
2
+ "id": "useIdEntity",
3
+ "name": "useIdEntity",
4
+ "displayName": "ID 实体映射",
5
+ "category": "state",
6
+ "description": "根据 ID 从列表中查找对应的实体对象。当 ID 或列表变化时自动更新实体,并可选择性地触发回调。常用于 Select 等组件中需要根据选中 ID 获取完整对象信息的场景。",
7
+ "importStatement": "import { useIdEntity } from '@ksyun-internal/versatile';",
8
+ "source": "@ksyun-internal/versatile",
9
+ "params": [
10
+ {
11
+ "name": "id",
12
+ "type": "Ref<string | number | undefined | null>",
13
+ "required": true,
14
+ "description": "要查找的实体 ID(响应式值)"
15
+ },
16
+ {
17
+ "name": "list",
18
+ "type": "Ref<Entity[] | undefined | null>",
19
+ "required": true,
20
+ "description": "实体列表(响应式值)"
21
+ },
22
+ {
23
+ "name": "key",
24
+ "type": "keyof Entity",
25
+ "required": true,
26
+ "description": "用于匹配的实体属性名(如 'id', 'WorkspaceId' 等)"
27
+ },
28
+ {
29
+ "name": "emit",
30
+ "type": "(entity: Entity | undefined) => void",
31
+ "required": false,
32
+ "description": "实体变化时的回调函数"
33
+ },
34
+ {
35
+ "name": "deps",
36
+ "type": "WatchSource[]",
37
+ "required": false,
38
+ "description": "额外的依赖项,当这些依赖变化时也会触发重新查找"
39
+ },
40
+ {
41
+ "name": "enable",
42
+ "type": "(item: Entity, index: number) => boolean",
43
+ "required": false,
44
+ "description": "过滤函数,用于筛选可用的实体"
45
+ }
46
+ ],
47
+ "returnType": "Ref<Entity | undefined>",
48
+ "examples": [
49
+ {
50
+ "id": "basic_usage",
51
+ "title": "基础用法",
52
+ "description": "根据选中的 ID 获取对应的工作空间对象",
53
+ "code": "<script setup lang=\"ts\">\nimport { ref } from 'vue';\nimport { useIdEntity } from '@ksyun-internal/versatile';\n\nconst selectedId = ref('ws-001');\nconst workspaceList = ref([\n { WorkspaceId: 'ws-001', WorkspaceName: '工作空间1' },\n { WorkspaceId: 'ws-002', WorkspaceName: '工作空间2' },\n]);\n\nconst selectedWorkspace = useIdEntity(selectedId, workspaceList, 'WorkspaceId');\n// selectedWorkspace.value = { WorkspaceId: 'ws-001', WorkspaceName: '工作空间1' }\n</script>"
54
+ },
55
+ {
56
+ "id": "with_callback",
57
+ "title": "带回调函数",
58
+ "description": "当实体变化时触发回调",
59
+ "code": "<script setup lang=\"ts\">\nimport { useToState, useIdEntity } from '@ksyun-internal/versatile';\n\nconst props = defineProps<{ modelValue?: string }>();\nconst emit = defineEmits<{ (e: 'update:modelValue', v?: string): void }>();\n\nconst modelValue = useToState(props, 'modelValue', emit, '');\nconst { workspaceList } = useWorkspaces();\n\nuseIdEntity(modelValue, workspaceList, 'WorkspaceId', (entity) => {\n emit('update:modelValue', entity?.WorkspaceId);\n});\n</script>"
60
+ },
61
+ {
62
+ "id": "with_enable_filter",
63
+ "title": "带过滤函数",
64
+ "description": "只在启用状态的实体中查找",
65
+ "code": "<script setup lang=\"ts\">\nimport { ref } from 'vue';\nimport { useIdEntity } from '@ksyun-internal/versatile';\n\nconst selectedId = ref('item-1');\nconst itemList = ref([\n { id: 'item-1', name: '项目1', enabled: true },\n { id: 'item-2', name: '项目2', enabled: false },\n]);\n\n// 只在 enabled: true 的项目中查找\nconst entity = useIdEntity(\n selectedId,\n itemList,\n 'id',\n undefined,\n undefined,\n (item) => item.enabled\n);\n</script>"
66
+ }
67
+ ],
68
+ "commonMistakes": [
69
+ {
70
+ "id": "non_ref_id",
71
+ "description": "id 参数传入非响应式值",
72
+ "wrongCode": "const entity = useIdEntity('ws-001', workspaceList, 'WorkspaceId');",
73
+ "correctCode": "const id = ref('ws-001');\nconst entity = useIdEntity(id, workspaceList, 'WorkspaceId');",
74
+ "explanation": "id 参数必须是 Ref 类型,否则无法监听变化"
75
+ },
76
+ {
77
+ "id": "wrong_key_name",
78
+ "description": "key 参数与实体属性名不匹配",
79
+ "wrongCode": "useIdEntity(id, workspaceList, 'id'); // 实体中是 WorkspaceId",
80
+ "correctCode": "useIdEntity(id, workspaceList, 'WorkspaceId');",
81
+ "explanation": "key 必须与实体对象中用作唯一标识的属性名完全匹配"
82
+ }
83
+ ],
84
+ "searchKeywords": [
85
+ "useIdEntity",
86
+ "id",
87
+ "entity",
88
+ "列表查找",
89
+ "实体映射",
90
+ "select"
91
+ ]
92
+ }
@@ -0,0 +1,97 @@
1
+ {
2
+ "id": "useToState",
3
+ "name": "useToState",
4
+ "displayName": "Props 转 State",
5
+ "category": "state",
6
+ "description": "将 props 中的属性转换为响应式 state,支持 v-model 双向绑定。当 props 变化时自动更新 state,当 state 变化时自动触发 emit 更新父组件。",
7
+ "importStatement": "import { useToState } from '@ksyun-internal/versatile';",
8
+ "source": "@ksyun-internal/versatile",
9
+ "params": [
10
+ {
11
+ "name": "props",
12
+ "type": "P extends object",
13
+ "required": true,
14
+ "description": "组件的 props 对象(通过 defineProps 获取)"
15
+ },
16
+ {
17
+ "name": "key",
18
+ "type": "keyof P",
19
+ "required": true,
20
+ "description": "要监听的 prop 名称(字符串)"
21
+ },
22
+ {
23
+ "name": "emit",
24
+ "type": "Emits<K & string, P[K]>",
25
+ "required": true,
26
+ "description": "组件的 emit 函数(通过 defineEmits 获取),需要包含 update:key 事件"
27
+ },
28
+ {
29
+ "name": "defaults",
30
+ "type": "NonNullable<P[K]>",
31
+ "required": false,
32
+ "description": "默认值。如果提供,返回的 Ref 将保证不为 undefined"
33
+ }
34
+ ],
35
+ "returnType": "Ref<P[K]>",
36
+ "overloads": [
37
+ {
38
+ "signature": "useToState<P, K>(props: P, key: K, emit: Emits): Ref<P[K]>",
39
+ "description": "基础用法,返回可能为 undefined 的响应式值"
40
+ },
41
+ {
42
+ "signature": "useToState<P, K>(props: P, key: K, emit: Emits, defaults: NonNullable<P[K]>): Ref<NonNullable<P[K]>>",
43
+ "description": "带默认值用法,返回保证非 undefined 的响应式值"
44
+ }
45
+ ],
46
+ "examples": [
47
+ {
48
+ "id": "basic_usage",
49
+ "title": "基础用法",
50
+ "description": "将 modelValue prop 转换为响应式 state",
51
+ "code": "<script setup lang=\"ts\">\nimport { useToState } from '@ksyun-internal/versatile';\n\ntype Props = { modelValue?: string };\ntype Emits = { (e: 'update:modelValue', v?: string): void };\n\nconst props = defineProps<Props>();\nconst emit = defineEmits<Emits>();\n\nconst value = useToState(props, 'modelValue', emit);\n</script>\n<template>\n <input v-model=\"value\" />\n</template>"
52
+ },
53
+ {
54
+ "id": "with_defaults",
55
+ "title": "带默认值用法",
56
+ "description": "提供默认值,确保返回值不为 undefined",
57
+ "code": "<script setup lang=\"ts\">\nimport { useToState } from '@ksyun-internal/versatile';\n\nconst props = defineProps<{ count?: number }>();\nconst emit = defineEmits(['update:count']);\n\n// 默认值为 0,count 永远不为 undefined\nconst count = useToState(props, 'count', emit, 0);\n</script>\n<template>\n <div>{{ count }}</div>\n</template>"
58
+ },
59
+ {
60
+ "id": "object_value",
61
+ "title": "对象类型值",
62
+ "description": "将对象类型的 prop 转换为响应式 state",
63
+ "code": "<script setup lang=\"ts\">\nimport { useToState } from '@ksyun-internal/versatile';\n\ntype FormData = { name: string; age: number };\ntype Props = { modelValue?: FormData };\ntype Emits = { (e: 'update:modelValue', v?: FormData): void };\n\nconst props = defineProps<Props>();\nconst emit = defineEmits<Emits>();\n\nconst formData = useToState(props, 'modelValue', emit, { name: '', age: 0 });\n</script>\n<template>\n <input v-model=\"formData.name\" />\n <input v-model.number=\"formData.age\" />\n</template>"
64
+ }
65
+ ],
66
+ "commonMistakes": [
67
+ {
68
+ "id": "missing_emit",
69
+ "description": "忘记传递 emit 参数",
70
+ "wrongCode": "const value = useToState(props, 'modelValue');",
71
+ "correctCode": "const value = useToState(props, 'modelValue', emit);",
72
+ "explanation": "useToState 需要 emit 函数来实现双向绑定,缺少 emit 会导致编译错误"
73
+ },
74
+ {
75
+ "id": "wrong_emit_event",
76
+ "description": "emit 没有定义对应的 update:key 事件",
77
+ "wrongCode": "const emit = defineEmits(['change']);\nconst value = useToState(props, 'modelValue', emit);",
78
+ "correctCode": "const emit = defineEmits(['update:modelValue']);\nconst value = useToState(props, 'modelValue', emit);",
79
+ "explanation": "useToState 内部会调用 emit('update:key', newValue),必须在 defineEmits 中声明对应事件"
80
+ },
81
+ {
82
+ "id": "key_not_in_props",
83
+ "description": "key 参数不是 props 中定义的属性",
84
+ "wrongCode": "const props = defineProps<{ name: string }>();\nconst value = useToState(props, 'age', emit);",
85
+ "correctCode": "const props = defineProps<{ name: string; age?: number }>();\nconst value = useToState(props, 'age', emit);",
86
+ "explanation": "key 必须是 props 中已定义的属性名"
87
+ }
88
+ ],
89
+ "searchKeywords": [
90
+ "useToState",
91
+ "props",
92
+ "state",
93
+ "v-model",
94
+ "双向绑定",
95
+ "响应式"
96
+ ]
97
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "king-design-analyzer",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "AST-based code analyzer for King Design Vue components with on-demand modular imports",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -45,7 +45,8 @@
45
45
  "files": [
46
46
  "dist",
47
47
  "components",
48
- "docs_for_llm"
48
+ "docs_for_llm",
49
+ "hooks"
49
50
  ],
50
51
  "scripts": {
51
52
  "build": "tsup",