@antsoo-lib/core 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/core.css +1 -1
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.js +6 -5
  5. package/dist/types/BaseSearch/index.d.ts +1 -1
  6. package/dist/types/BaseTable/index.d.ts +5 -475
  7. package/dist/types/Form/CoreForm.d.ts +82 -0
  8. package/dist/types/SSelectPage/index.d.ts +102 -0
  9. package/package.json +3 -3
  10. package/src/BaseSearch/index.vue +371 -371
  11. package/src/BaseTable/index.vue +910 -910
  12. package/src/Form/CoreForm.vue +782 -782
  13. package/src/Form/types.ts +86 -86
  14. package/src/SSelectPage/index.vue +607 -607
  15. package/src/index.ts +17 -17
  16. package/src/render/AreaCascader.tsx +64 -64
  17. package/src/render/AutoComplete.tsx +101 -101
  18. package/src/render/Button.tsx +62 -62
  19. package/src/render/Cascader.tsx +45 -45
  20. package/src/render/Checkbox.tsx +65 -65
  21. package/src/render/CheckboxGroup.tsx +57 -57
  22. package/src/render/Custom.tsx +19 -19
  23. package/src/render/DatePicker.tsx +83 -83
  24. package/src/render/Input.tsx +140 -140
  25. package/src/render/InputGroup.tsx +115 -115
  26. package/src/render/InputNumber.tsx +205 -205
  27. package/src/render/InputPassword.tsx +81 -81
  28. package/src/render/InputRange.tsx +154 -154
  29. package/src/render/RadioGroup.tsx +63 -63
  30. package/src/render/Select.tsx +96 -96
  31. package/src/render/SselectPage.tsx +107 -107
  32. package/src/render/Switch.tsx +60 -60
  33. package/src/render/Tree.tsx +136 -136
  34. package/src/render/TreeSelect.tsx +81 -81
  35. package/src/render/Upload.tsx +91 -91
  36. package/src/render/helper.tsx +221 -221
  37. package/src/render/index.ts +108 -108
  38. package/src/render/registry.ts +20 -20
  39. package/src/render/state.ts +37 -37
  40. package/src/render/types.ts +567 -567
  41. package/src/utils/attrMapping.ts +106 -106
  42. package/vite.config.ts +61 -61
  43. package/.turbo/turbo-build.log +0 -40
@@ -1,106 +1,106 @@
1
- /**
2
- * 通用 attr 映射工具函数集合
3
- * - 支持 attr 为字符串数组(按顺序映射)或对象映射(targetKey -> sourcePath)
4
- * - 对象映射不再限制 ids/names,允许任意键值对
5
- */
6
- import type { AnyObject } from '@antsoo-lib/shared'
7
- import { isArray, isObject } from '@antsoo-lib/utils'
8
-
9
- /**
10
- * 安全获取嵌套属性值,支持 a.b.c 路径
11
- */
12
- export function getByPath(obj: any, path?: string): any {
13
- if (!path || typeof path !== 'string') return undefined
14
- return path.split('.').reduce((cur: any, key: string) => (cur ? cur[key] : undefined), obj)
15
- }
16
-
17
- /**
18
- * 根据 attr 规则从 formData 聚合初始值:
19
- * - 数组:返回对应字段的值数组
20
- * - 对象:返回 { [sourcePath]: formData[targetKey] } 结构,便于组件按源字段进行回显
21
- */
22
- export function buildValueFromAttr(formData: AnyObject, attr: string[] | AnyObject): any {
23
- // 1) 数组:按顺序返回对应值
24
- if (isArray(attr)) {
25
- return (attr as string[]).map((k) => formData[k])
26
- }
27
-
28
- // 2) 对象:支持两类结构并可混合:
29
- // a) 分组数组结构(如 { ids: [..], names: [..] } 或 { values: [..], codes: [..] })
30
- // 返回以数组元素为键的对象:{ [fieldKey]: formData[fieldKey] }
31
- // b) 键值映射结构(如 { dataEditCompany: "id", dataEditCompanyName: "coName" })
32
- // 返回以 sourcePath 为键的对象:{ [sourcePath]: formData[targetKey] }
33
- if (isObject(attr)) {
34
- const result: AnyObject = {}
35
- let handled = false
36
-
37
- // a) 处理分组数组结构:遍历所有值为字符串数组的键
38
- Object.entries(attr as AnyObject).forEach(([_, groupVal]) => {
39
- if (isArray(groupVal)) {
40
- ;(groupVal as string[]).forEach((fieldKey) => {
41
- if (!fieldKey) return
42
- result[fieldKey] = formData[fieldKey]
43
- })
44
- handled = true
45
- }
46
- })
47
-
48
- // b) 处理键值映射结构:遍历所有值为字符串的键
49
- Object.entries(attr as AnyObject).forEach(([targetKey, sourcePath]) => {
50
- if (typeof sourcePath === 'string') {
51
- result[sourcePath] = formData[targetKey]
52
- handled = true
53
- }
54
- })
55
-
56
- // 如果所有映射得到的值都为 undefined/null,则不返回占位对象,避免清空场景下出现形如 { id: ... } 的残留对象
57
- if (!handled) return undefined
58
- const allUndefined =
59
- Object.keys(result).length > 0 &&
60
- Object.values(result).every((v) => v === undefined || v === null)
61
- return allUndefined ? undefined : result
62
- }
63
-
64
- return undefined
65
- }
66
-
67
- /**
68
- * 按 attr 对象映射将选项数据写入 formData:
69
- * - 支持单选与多选;
70
- * - 优先使用 option.__raw 原始对象,其次使用 option 自身;
71
- * - sourcePath 支持嵌套路径(例如 'data.id')。
72
- */
73
- export function applyAttrMapping(
74
- formData: AnyObject,
75
- toolbarState: { setValue: (k: string, v: any) => void },
76
- attr: Record<string, string>,
77
- value: any,
78
- option: any,
79
- isMultiple: boolean,
80
- ) {
81
- const mapOne = (opt: any, targetKey: string, sourcePath: string) => {
82
- const raw = opt && (opt.__raw ?? opt)
83
- const v = getByPath(raw, sourcePath)
84
- formData[targetKey] = v
85
- toolbarState.setValue(targetKey, v)
86
- return v
87
- }
88
-
89
- Object.entries(attr).forEach(([targetKey, sourcePath]) => {
90
- if (!targetKey || !sourcePath || typeof sourcePath !== 'string') return
91
- if (isMultiple) {
92
- const arr = Array.isArray(option) ? option : []
93
- const values = arr.map((opt) => mapOne(opt, targetKey, sourcePath))
94
- formData[targetKey] = values
95
- toolbarState.setValue(targetKey, values)
96
- } else {
97
- mapOne(option, targetKey, sourcePath)
98
- }
99
- })
100
- }
101
-
102
- export default {
103
- buildValueFromAttr,
104
- applyAttrMapping,
105
- getByPath,
106
- }
1
+ /**
2
+ * 通用 attr 映射工具函数集合
3
+ * - 支持 attr 为字符串数组(按顺序映射)或对象映射(targetKey -> sourcePath)
4
+ * - 对象映射不再限制 ids/names,允许任意键值对
5
+ */
6
+ import type { AnyObject } from '@antsoo-lib/shared'
7
+ import { isArray, isObject } from '@antsoo-lib/utils'
8
+
9
+ /**
10
+ * 安全获取嵌套属性值,支持 a.b.c 路径
11
+ */
12
+ export function getByPath(obj: any, path?: string): any {
13
+ if (!path || typeof path !== 'string') return undefined
14
+ return path.split('.').reduce((cur: any, key: string) => (cur ? cur[key] : undefined), obj)
15
+ }
16
+
17
+ /**
18
+ * 根据 attr 规则从 formData 聚合初始值:
19
+ * - 数组:返回对应字段的值数组
20
+ * - 对象:返回 { [sourcePath]: formData[targetKey] } 结构,便于组件按源字段进行回显
21
+ */
22
+ export function buildValueFromAttr(formData: AnyObject, attr: string[] | AnyObject): any {
23
+ // 1) 数组:按顺序返回对应值
24
+ if (isArray(attr)) {
25
+ return (attr as string[]).map((k) => formData[k])
26
+ }
27
+
28
+ // 2) 对象:支持两类结构并可混合:
29
+ // a) 分组数组结构(如 { ids: [..], names: [..] } 或 { values: [..], codes: [..] })
30
+ // 返回以数组元素为键的对象:{ [fieldKey]: formData[fieldKey] }
31
+ // b) 键值映射结构(如 { dataEditCompany: "id", dataEditCompanyName: "coName" })
32
+ // 返回以 sourcePath 为键的对象:{ [sourcePath]: formData[targetKey] }
33
+ if (isObject(attr)) {
34
+ const result: AnyObject = {}
35
+ let handled = false
36
+
37
+ // a) 处理分组数组结构:遍历所有值为字符串数组的键
38
+ Object.entries(attr as AnyObject).forEach(([_, groupVal]) => {
39
+ if (isArray(groupVal)) {
40
+ ;(groupVal as string[]).forEach((fieldKey) => {
41
+ if (!fieldKey) return
42
+ result[fieldKey] = formData[fieldKey]
43
+ })
44
+ handled = true
45
+ }
46
+ })
47
+
48
+ // b) 处理键值映射结构:遍历所有值为字符串的键
49
+ Object.entries(attr as AnyObject).forEach(([targetKey, sourcePath]) => {
50
+ if (typeof sourcePath === 'string') {
51
+ result[sourcePath] = formData[targetKey]
52
+ handled = true
53
+ }
54
+ })
55
+
56
+ // 如果所有映射得到的值都为 undefined/null,则不返回占位对象,避免清空场景下出现形如 { id: ... } 的残留对象
57
+ if (!handled) return undefined
58
+ const allUndefined =
59
+ Object.keys(result).length > 0 &&
60
+ Object.values(result).every((v) => v === undefined || v === null)
61
+ return allUndefined ? undefined : result
62
+ }
63
+
64
+ return undefined
65
+ }
66
+
67
+ /**
68
+ * 按 attr 对象映射将选项数据写入 formData:
69
+ * - 支持单选与多选;
70
+ * - 优先使用 option.__raw 原始对象,其次使用 option 自身;
71
+ * - sourcePath 支持嵌套路径(例如 'data.id')。
72
+ */
73
+ export function applyAttrMapping(
74
+ formData: AnyObject,
75
+ toolbarState: { setValue: (k: string, v: any) => void },
76
+ attr: Record<string, string>,
77
+ value: any,
78
+ option: any,
79
+ isMultiple: boolean,
80
+ ) {
81
+ const mapOne = (opt: any, targetKey: string, sourcePath: string) => {
82
+ const raw = opt && (opt.__raw ?? opt)
83
+ const v = getByPath(raw, sourcePath)
84
+ formData[targetKey] = v
85
+ toolbarState.setValue(targetKey, v)
86
+ return v
87
+ }
88
+
89
+ Object.entries(attr).forEach(([targetKey, sourcePath]) => {
90
+ if (!targetKey || !sourcePath || typeof sourcePath !== 'string') return
91
+ if (isMultiple) {
92
+ const arr = Array.isArray(option) ? option : []
93
+ const values = arr.map((opt) => mapOne(opt, targetKey, sourcePath))
94
+ formData[targetKey] = values
95
+ toolbarState.setValue(targetKey, values)
96
+ } else {
97
+ mapOne(option, targetKey, sourcePath)
98
+ }
99
+ })
100
+ }
101
+
102
+ export default {
103
+ buildValueFromAttr,
104
+ applyAttrMapping,
105
+ getByPath,
106
+ }
package/vite.config.ts CHANGED
@@ -1,61 +1,61 @@
1
- import vue from '@vitejs/plugin-vue'
2
- import vueJsx from '@vitejs/plugin-vue-jsx'
3
- import { resolve } from 'node:path'
4
- import { defineConfig } from 'vite'
5
- import dts from 'vite-plugin-dts'
6
-
7
- export default defineConfig({
8
- resolve: {
9
- extensions: ['.ts', '.tsx', '.vue'],
10
- },
11
- plugins: [
12
- vue(),
13
- vueJsx(),
14
- dts({
15
- entryRoot: 'src',
16
- include: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.vue'],
17
- outDir: 'dist/types',
18
- cleanVueFileName: true,
19
- }),
20
- ],
21
- build: {
22
- cssCodeSplit: false,
23
- lib: {
24
- entry: resolve(__dirname, './src/index.ts'),
25
- name: 'AntsooTableCore',
26
- fileName: (format) => `index.${format === 'es' ? 'js' : 'cjs'}`,
27
- formats: ['es', 'cjs'],
28
- },
29
- rollupOptions: {
30
- external: [
31
- 'vue',
32
- '@antsoo-lib/utils',
33
- '@antsoo-lib/shared',
34
- '@antsoo-lib/components',
35
- 'lodash-es',
36
- '@vxe-ui/plugin-export-xlsx',
37
- '@vxe-ui/plugin-menu',
38
- '@vxe-ui/plugin-render-wangeditor',
39
- 'vxe-pc-ui',
40
- 'vxe-table',
41
- 'xe-utils',
42
- /^@ant-design\/icons-svg/,
43
- ],
44
- output: {
45
- globals: {
46
- vue: 'Vue',
47
- '@antsoo-lib/utils': 'AntsooUtils',
48
- '@antsoo-lib/shared': 'AntsooShared',
49
- '@antsoo-lib/components': 'AntsooComponents',
50
- 'lodash-es': 'lodash-es',
51
- '@vxe-ui/plugin-export-xlsx': 'VxeExportXlsxPlugin',
52
- '@vxe-ui/plugin-menu': 'VxeMenuPlugin',
53
- '@vxe-ui/plugin-render-wangeditor': 'VxeRenderWangEditorPlugin',
54
- 'vxe-pc-ui': 'VxePCUI',
55
- 'vxe-table': 'VxeTable',
56
- 'xe-utils': 'XeUtils',
57
- },
58
- },
59
- },
60
- },
61
- })
1
+ import vue from '@vitejs/plugin-vue'
2
+ import vueJsx from '@vitejs/plugin-vue-jsx'
3
+ import { resolve } from 'node:path'
4
+ import { defineConfig } from 'vite'
5
+ import dts from 'vite-plugin-dts'
6
+
7
+ export default defineConfig({
8
+ resolve: {
9
+ extensions: ['.ts', '.tsx', '.vue'],
10
+ },
11
+ plugins: [
12
+ vue(),
13
+ vueJsx(),
14
+ dts({
15
+ entryRoot: 'src',
16
+ include: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.vue'],
17
+ outDir: 'dist/types',
18
+ cleanVueFileName: true,
19
+ }),
20
+ ],
21
+ build: {
22
+ cssCodeSplit: false,
23
+ lib: {
24
+ entry: resolve(__dirname, './src/index.ts'),
25
+ name: 'AntsooTableCore',
26
+ fileName: (format) => `index.${format === 'es' ? 'js' : 'cjs'}`,
27
+ formats: ['es', 'cjs'],
28
+ },
29
+ rollupOptions: {
30
+ external: [
31
+ 'vue',
32
+ '@antsoo-lib/utils',
33
+ '@antsoo-lib/shared',
34
+ '@antsoo-lib/components',
35
+ 'lodash-es',
36
+ '@vxe-ui/plugin-export-xlsx',
37
+ '@vxe-ui/plugin-menu',
38
+ '@vxe-ui/plugin-render-wangeditor',
39
+ 'vxe-pc-ui',
40
+ 'vxe-table',
41
+ 'xe-utils',
42
+ /^@ant-design\/icons-svg/,
43
+ ],
44
+ output: {
45
+ globals: {
46
+ vue: 'Vue',
47
+ '@antsoo-lib/utils': 'AntsooUtils',
48
+ '@antsoo-lib/shared': 'AntsooShared',
49
+ '@antsoo-lib/components': 'AntsooComponents',
50
+ 'lodash-es': 'lodash-es',
51
+ '@vxe-ui/plugin-export-xlsx': 'VxeExportXlsxPlugin',
52
+ '@vxe-ui/plugin-menu': 'VxeMenuPlugin',
53
+ '@vxe-ui/plugin-render-wangeditor': 'VxeRenderWangEditorPlugin',
54
+ 'vxe-pc-ui': 'VxePCUI',
55
+ 'vxe-table': 'VxeTable',
56
+ 'xe-utils': 'XeUtils',
57
+ },
58
+ },
59
+ },
60
+ },
61
+ })
@@ -1,40 +0,0 @@
1
-
2
- 
3
- > @antsoo-lib/core@2.0.5 build /Users/weishaodaren/databank/antsoo-lib/packages/core
4
- > vite build
5
-
6
- vite v7.3.1 building client environment for production...
7
- transforming (1) src/index.tstransforming (2) src/render/registry.tstransforming (21) src/render/Tree.tsxtransforming (41) ../icons/dist/index.jstransforming (49) ../../node_modules/.pnpm/@ant-design+icons-vue@7.0.1_vue@3.5.27_typescript@5.9.3_/node_modules/@ant-design/icons-vue/es/icons/AccountBookFilled.jstransforming (842) ../../node_modules/.pnpm/@ant-design+colors@6.0.0/node_modules/@ant-design/colors/dist/index.esm.js✓ 855 modules transformed.
8
- rendering chunks (1)...
9
- [vite:dts] Start generate declaration files...
10
- src/Form/CoreForm.vue:1440:10 - error TS2742: The inferred type of '__VLS_template' cannot be named without a reference to '@/packages/components/node_modules/vue-types/dist'. This is likely not portable. A type annotation is necessary.
11
-
12
- 1440 function __VLS_template() {
13
-    ~~~~~~~~~~~~~~
14
- src/Form/CoreForm.vue:1676:7 - error TS2742: The inferred type of '__VLS_component' cannot be named without a reference to '@/packages/components/node_modules/vue-types/dist'. This is likely not portable. A type annotation is necessary.
15
-
16
- 1676 const __VLS_component = (await import('vue')).defineComponent({
17
-    ~~~~~~~~~~~~~~~
18
- src/SSelectPage/index.vue:1343:1 - error TS2742: The inferred type of 'default' cannot be named without a reference to '@/packages/components/node_modules/vue-types/dist'. This is likely not portable. A type annotation is necessary.
19
-
20
- 1343 export default (await import('vue')).defineComponent({
21
-   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22
- 1344 setup() {
23
-   ~~~~~~~~~
24
-  ...
25
- 1353 __typeEl: {} as __VLS_TemplateResult['rootEl'],
26
-   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27
- 1354 });
28
-   ~~~
29
- src/BaseTable/index.vue:819:26 - error TS7022: 'slotName' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
30
-
31
- 819 <template v-for="(_, slotName) in $slots" #[slotName]="slotProps">
32
-    ~~~~~~~~
33
-
34
- computing gzip size (0)...computing gzip size (1)...computing gzip size (2)...dist/core.css  4.50 kB │ gzip: 1.05 kB
35
- dist/index.js 148.56 kB │ gzip: 31.92 kB
36
- [vite:dts] Declaration files built in 3244ms.
37
- 
38
- rendering chunks (1)...computing gzip size (1)...computing gzip size (2)...dist/core.css  4.50 kB │ gzip: 1.05 kB
39
- dist/index.cjs 118.94 kB │ gzip: 27.04 kB
40
- ✓ built in 4.63s