@antsoo-lib/core 2.0.5 → 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 +16 -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 +4 -480
  7. package/dist/types/Form/CoreForm.d.ts +82 -0
  8. package/dist/types/SSelectPage/index.d.ts +102 -0
  9. package/package.json +5 -5
  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,65 +1,65 @@
1
- import { Checkbox } from '@antsoo-lib/components'
2
- import type { CheckboxProps } from '@antsoo-lib/components'
3
- import type { VoidFunction } from '@antsoo-lib/shared'
4
- import { isFunction } from '@antsoo-lib/utils'
5
-
6
- import { markRaw } from 'vue'
7
- import type { VNode } from 'vue'
8
-
9
- import type { ToolbarState } from './state'
10
- import type { CheckboxToolbarItem, ToolbarItem } from './types'
11
-
12
- // 复选框渲染函数
13
- export function renderCheckbox(item: ToolbarItem, toolbarState: ToolbarState): VNode {
14
- const checkboxItem = item as CheckboxToolbarItem
15
- const { key, events = {} } = checkboxItem
16
- const { props = {}, disabled = false } = checkboxItem
17
-
18
- const isDisabled = isFunction(disabled)
19
- ? disabled(toolbarState.getAllValues(), toolbarState)
20
- : disabled
21
- const finalProps: Partial<CheckboxProps> & {
22
- disabled?: boolean
23
- checked?: boolean
24
- value?: boolean
25
- } = {
26
- ...props,
27
- disabled: isDisabled,
28
- }
29
-
30
- // 处理事件,注入工具栏状态
31
- const processedEvents: Record<string, VoidFunction> = {}
32
- Object.keys(events).forEach((eventName) => {
33
- processedEvents[eventName] = (...args: any[]) => {
34
- // 对于复选框,自动更新状态
35
- if (eventName === 'onUpdate:checked' || eventName === 'onChange') {
36
- const checked = args[0]?.target?.checked ?? args[0] // 兼容不同的事件格式
37
- toolbarState.setValue(key, checked)
38
- // 显式触发 onUpdate:value,确保 BaseForm 能接收到数据更新
39
- events['onUpdate:value']?.(checked, toolbarState.getAllValues(), toolbarState)
40
- }
41
-
42
- // 调用原始事件处理函数
43
- events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
44
- }
45
- })
46
-
47
- // 如果没有设置onChange事件,添加默认的状态更新
48
- if (!processedEvents['onUpdate:checked'] && !processedEvents.onChange) {
49
- processedEvents['onUpdate:checked'] = (checked: boolean) => {
50
- toolbarState.setValue(key, checked)
51
- }
52
- }
53
-
54
- const Comp = markRaw(Checkbox)
55
- return (
56
- <Comp
57
- key={key}
58
- checked={toolbarState.getValue(key) ?? finalProps.checked ?? finalProps.value ?? false}
59
- {...finalProps}
60
- {...processedEvents}
61
- >
62
- {checkboxItem.label}
63
- </Comp>
64
- )
65
- }
1
+ import { Checkbox } from '@antsoo-lib/components'
2
+ import type { CheckboxProps } from '@antsoo-lib/components'
3
+ import type { VoidFunction } from '@antsoo-lib/shared'
4
+ import { isFunction } from '@antsoo-lib/utils'
5
+
6
+ import { markRaw } from 'vue'
7
+ import type { VNode } from 'vue'
8
+
9
+ import type { ToolbarState } from './state'
10
+ import type { CheckboxToolbarItem, ToolbarItem } from './types'
11
+
12
+ // 复选框渲染函数
13
+ export function renderCheckbox(item: ToolbarItem, toolbarState: ToolbarState): VNode {
14
+ const checkboxItem = item as CheckboxToolbarItem
15
+ const { key, events = {} } = checkboxItem
16
+ const { props = {}, disabled = false } = checkboxItem
17
+
18
+ const isDisabled = isFunction(disabled)
19
+ ? disabled(toolbarState.getAllValues(), toolbarState)
20
+ : disabled
21
+ const finalProps: Partial<CheckboxProps> & {
22
+ disabled?: boolean
23
+ checked?: boolean
24
+ value?: boolean
25
+ } = {
26
+ ...props,
27
+ disabled: isDisabled,
28
+ }
29
+
30
+ // 处理事件,注入工具栏状态
31
+ const processedEvents: Record<string, VoidFunction> = {}
32
+ Object.keys(events).forEach((eventName) => {
33
+ processedEvents[eventName] = (...args: any[]) => {
34
+ // 对于复选框,自动更新状态
35
+ if (eventName === 'onUpdate:checked' || eventName === 'onChange') {
36
+ const checked = args[0]?.target?.checked ?? args[0] // 兼容不同的事件格式
37
+ toolbarState.setValue(key, checked)
38
+ // 显式触发 onUpdate:value,确保 BaseForm 能接收到数据更新
39
+ events['onUpdate:value']?.(checked, toolbarState.getAllValues(), toolbarState)
40
+ }
41
+
42
+ // 调用原始事件处理函数
43
+ events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
44
+ }
45
+ })
46
+
47
+ // 如果没有设置onChange事件,添加默认的状态更新
48
+ if (!processedEvents['onUpdate:checked'] && !processedEvents.onChange) {
49
+ processedEvents['onUpdate:checked'] = (checked: boolean) => {
50
+ toolbarState.setValue(key, checked)
51
+ }
52
+ }
53
+
54
+ const Comp = markRaw(Checkbox)
55
+ return (
56
+ <Comp
57
+ key={key}
58
+ checked={toolbarState.getValue(key) ?? finalProps.checked ?? finalProps.value ?? false}
59
+ {...finalProps}
60
+ {...processedEvents}
61
+ >
62
+ {checkboxItem.label}
63
+ </Comp>
64
+ )
65
+ }
@@ -1,57 +1,57 @@
1
- import { CheckboxGroup } from '@antsoo-lib/components'
2
- import type { CheckboxGroupProps } from '@antsoo-lib/components'
3
- import type { VoidFunction } from '@antsoo-lib/shared'
4
- import { isFunction } from '@antsoo-lib/utils'
5
-
6
- import { markRaw } from 'vue'
7
- import type { VNode } from 'vue'
8
-
9
- import type { ToolbarState } from './state'
10
- import type { CheckboxGroupToolbarItem, ToolbarItem } from './types'
11
-
12
- // 复选框组渲染函数
13
- export function renderCheckboxGroup(item: ToolbarItem, toolbarState: ToolbarState): VNode {
14
- const groupItem = item as CheckboxGroupToolbarItem
15
- const { key, events = {} } = groupItem
16
- const { props = {}, disabled = false } = groupItem
17
-
18
- const isDisabled = isFunction(disabled)
19
- ? disabled(toolbarState.getAllValues(), toolbarState)
20
- : disabled
21
- const finalProps: Partial<CheckboxGroupProps> & { disabled?: boolean; value?: any[] } = {
22
- ...props,
23
- disabled: isDisabled,
24
- }
25
-
26
- // 处理事件,注入工具栏状态
27
- const processedEvents: Record<string, VoidFunction> = {}
28
- Object.keys(events).forEach((eventName) => {
29
- processedEvents[eventName] = (...args: any[]) => {
30
- // 对于复选框组,自动更新状态
31
- if (eventName === 'onUpdate:value' || eventName === 'onChange') {
32
- const value = args[0] // CheckboxGroup 的 onChange 直接返回选中的值数组
33
- toolbarState.setValue(key, value)
34
- }
35
-
36
- // 调用原始事件处理函数
37
- events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
38
- }
39
- })
40
-
41
- // 如果没有设置onChange事件,添加默认的状态更新
42
- if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
43
- processedEvents['onUpdate:value'] = (value) => {
44
- toolbarState.setValue(key, value)
45
- }
46
- }
47
-
48
- const Comp = markRaw(CheckboxGroup)
49
- return (
50
- <Comp
51
- key={key}
52
- value={toolbarState.getValue(key) || finalProps.value || []}
53
- {...finalProps}
54
- {...processedEvents}
55
- />
56
- )
57
- }
1
+ import { CheckboxGroup } from '@antsoo-lib/components'
2
+ import type { CheckboxGroupProps } from '@antsoo-lib/components'
3
+ import type { VoidFunction } from '@antsoo-lib/shared'
4
+ import { isFunction } from '@antsoo-lib/utils'
5
+
6
+ import { markRaw } from 'vue'
7
+ import type { VNode } from 'vue'
8
+
9
+ import type { ToolbarState } from './state'
10
+ import type { CheckboxGroupToolbarItem, ToolbarItem } from './types'
11
+
12
+ // 复选框组渲染函数
13
+ export function renderCheckboxGroup(item: ToolbarItem, toolbarState: ToolbarState): VNode {
14
+ const groupItem = item as CheckboxGroupToolbarItem
15
+ const { key, events = {} } = groupItem
16
+ const { props = {}, disabled = false } = groupItem
17
+
18
+ const isDisabled = isFunction(disabled)
19
+ ? disabled(toolbarState.getAllValues(), toolbarState)
20
+ : disabled
21
+ const finalProps: Partial<CheckboxGroupProps> & { disabled?: boolean; value?: any[] } = {
22
+ ...props,
23
+ disabled: isDisabled,
24
+ }
25
+
26
+ // 处理事件,注入工具栏状态
27
+ const processedEvents: Record<string, VoidFunction> = {}
28
+ Object.keys(events).forEach((eventName) => {
29
+ processedEvents[eventName] = (...args: any[]) => {
30
+ // 对于复选框组,自动更新状态
31
+ if (eventName === 'onUpdate:value' || eventName === 'onChange') {
32
+ const value = args[0] // CheckboxGroup 的 onChange 直接返回选中的值数组
33
+ toolbarState.setValue(key, value)
34
+ }
35
+
36
+ // 调用原始事件处理函数
37
+ events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
38
+ }
39
+ })
40
+
41
+ // 如果没有设置onChange事件,添加默认的状态更新
42
+ if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
43
+ processedEvents['onUpdate:value'] = (value) => {
44
+ toolbarState.setValue(key, value)
45
+ }
46
+ }
47
+
48
+ const Comp = markRaw(CheckboxGroup)
49
+ return (
50
+ <Comp
51
+ key={key}
52
+ value={toolbarState.getValue(key) || finalProps.value || []}
53
+ {...finalProps}
54
+ {...processedEvents}
55
+ />
56
+ )
57
+ }
@@ -1,19 +1,19 @@
1
- import type { VNode } from 'vue'
2
-
3
- import type { ToolbarState } from './state'
4
- import type { BaseToolbarItem, ToolbarItem } from './types'
5
-
6
- // 自定义工具栏项目
7
- export interface CustomToolbarItem extends BaseToolbarItem {
8
- type: 'custom'
9
- render: (toolbarState: ToolbarState) => VNode
10
- }
11
-
12
- // 自定义渲染函数
13
- export function renderCustom(item: ToolbarItem, toolbarState: ToolbarState): VNode {
14
- const customItem = item as CustomToolbarItem
15
- if (typeof customItem.render === 'function') {
16
- return customItem.render(toolbarState)
17
- }
18
- return <div key={item.key}>{item.label || item.key || '未命名'}</div>
19
- }
1
+ import type { VNode } from 'vue'
2
+
3
+ import type { ToolbarState } from './state'
4
+ import type { BaseToolbarItem, ToolbarItem } from './types'
5
+
6
+ // 自定义工具栏项目
7
+ export interface CustomToolbarItem extends BaseToolbarItem {
8
+ type: 'custom'
9
+ render: (toolbarState: ToolbarState) => VNode
10
+ }
11
+
12
+ // 自定义渲染函数
13
+ export function renderCustom(item: ToolbarItem, toolbarState: ToolbarState): VNode {
14
+ const customItem = item as CustomToolbarItem
15
+ if (typeof customItem.render === 'function') {
16
+ return customItem.render(toolbarState)
17
+ }
18
+ return <div key={item.key}>{item.label || item.key || '未命名'}</div>
19
+ }
@@ -1,83 +1,83 @@
1
- import { DatePicker, RangePicker } from '@antsoo-lib/components'
2
- import type { DatePickerProps } from '@antsoo-lib/components'
3
- import { rangePresets } from '@antsoo-lib/shared'
4
- import type { VoidFunction } from '@antsoo-lib/shared'
5
- import { isFunction } from '@antsoo-lib/utils'
6
-
7
- import { markRaw, nextTick } from 'vue'
8
- import type { ComponentPublicInstance, VNode } from 'vue'
9
-
10
- import type { ToolbarState } from './state'
11
- import type { DatePickerToolbarItem, ToolbarItem } from './types'
12
-
13
- // 日期选择器渲染函数
14
- export function renderDatePicker(item: ToolbarItem, toolbarState: ToolbarState): VNode {
15
- const dateItem = item as DatePickerToolbarItem
16
- const { key, events = {} } = dateItem
17
- const { props = {}, disabled = false } = dateItem
18
-
19
- const isDisabled = isFunction(disabled)
20
- ? disabled(toolbarState.getAllValues(), toolbarState)
21
- : disabled
22
- const finalProps: Partial<DatePickerProps> & {
23
- disabled?: boolean
24
- value?: any
25
- autoFocus?: boolean
26
- } = {
27
- ...props,
28
- disabled: isDisabled,
29
- }
30
-
31
- // 处理事件,注入工具栏状态
32
- const processedEvents: Record<string, VoidFunction> = {}
33
- Object.keys(events).forEach((eventName) => {
34
- processedEvents[eventName] = (...args: any[]) => {
35
- // 对于日期选择器,自动更新状态
36
- if (eventName === 'onUpdate:value' || eventName === 'onChange') {
37
- const value = args[0]
38
- toolbarState.setValue(key, value)
39
- }
40
-
41
- // 调用原始事件处理函数
42
- events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
43
- }
44
- })
45
-
46
- // 如果没有设置onChange事件,添加默认的状态更新
47
- if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
48
- processedEvents['onUpdate:value'] = (value) => {
49
- toolbarState.setValue(key, value)
50
- }
51
- }
52
-
53
- // 如果需要自动聚焦,添加ref处理
54
- if (finalProps.autoFocus) {
55
- processedEvents.ref = (el: Element | ComponentPublicInstance | null) => {
56
- const element = el as HTMLElement
57
- if (element) {
58
- // 使用nextTick确保DOM已经渲染完成
59
- nextTick(() => {
60
- try {
61
- element?.focus?.()
62
- } catch {
63
- // 忽略焦点设置失败的错误
64
- }
65
- })
66
- }
67
- }
68
- }
69
-
70
- const isRange = dateItem.range
71
- const Comp = markRaw(isRange ? RangePicker : DatePicker) as any
72
- return (
73
- <Comp
74
- key={key}
75
- value={toolbarState.getValue(key) || finalProps.value}
76
- allowClear
77
- presets={isRange ? (rangePresets as any) : undefined}
78
- popupClassName={isRange ? 'custom-date-picker-presets' : undefined}
79
- {...finalProps}
80
- {...processedEvents}
81
- />
82
- )
83
- }
1
+ import { DatePicker, RangePicker } from '@antsoo-lib/components'
2
+ import type { DatePickerProps } from '@antsoo-lib/components'
3
+ import { rangePresets } from '@antsoo-lib/shared'
4
+ import type { VoidFunction } from '@antsoo-lib/shared'
5
+ import { isFunction } from '@antsoo-lib/utils'
6
+
7
+ import { markRaw, nextTick } from 'vue'
8
+ import type { ComponentPublicInstance, VNode } from 'vue'
9
+
10
+ import type { ToolbarState } from './state'
11
+ import type { DatePickerToolbarItem, ToolbarItem } from './types'
12
+
13
+ // 日期选择器渲染函数
14
+ export function renderDatePicker(item: ToolbarItem, toolbarState: ToolbarState): VNode {
15
+ const dateItem = item as DatePickerToolbarItem
16
+ const { key, events = {} } = dateItem
17
+ const { props = {}, disabled = false } = dateItem
18
+
19
+ const isDisabled = isFunction(disabled)
20
+ ? disabled(toolbarState.getAllValues(), toolbarState)
21
+ : disabled
22
+ const finalProps: Partial<DatePickerProps> & {
23
+ disabled?: boolean
24
+ value?: any
25
+ autoFocus?: boolean
26
+ } = {
27
+ ...props,
28
+ disabled: isDisabled,
29
+ }
30
+
31
+ // 处理事件,注入工具栏状态
32
+ const processedEvents: Record<string, VoidFunction> = {}
33
+ Object.keys(events).forEach((eventName) => {
34
+ processedEvents[eventName] = (...args: any[]) => {
35
+ // 对于日期选择器,自动更新状态
36
+ if (eventName === 'onUpdate:value' || eventName === 'onChange') {
37
+ const value = args[0]
38
+ toolbarState.setValue(key, value)
39
+ }
40
+
41
+ // 调用原始事件处理函数
42
+ events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
43
+ }
44
+ })
45
+
46
+ // 如果没有设置onChange事件,添加默认的状态更新
47
+ if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
48
+ processedEvents['onUpdate:value'] = (value) => {
49
+ toolbarState.setValue(key, value)
50
+ }
51
+ }
52
+
53
+ // 如果需要自动聚焦,添加ref处理
54
+ if (finalProps.autoFocus) {
55
+ processedEvents.ref = (el: Element | ComponentPublicInstance | null) => {
56
+ const element = el as HTMLElement
57
+ if (element) {
58
+ // 使用nextTick确保DOM已经渲染完成
59
+ nextTick(() => {
60
+ try {
61
+ element?.focus?.()
62
+ } catch {
63
+ // 忽略焦点设置失败的错误
64
+ }
65
+ })
66
+ }
67
+ }
68
+ }
69
+
70
+ const isRange = dateItem.range
71
+ const Comp = markRaw(isRange ? RangePicker : DatePicker) as any
72
+ return (
73
+ <Comp
74
+ key={key}
75
+ value={toolbarState.getValue(key) || finalProps.value}
76
+ allowClear
77
+ presets={isRange ? (rangePresets as any) : undefined}
78
+ popupClassName={isRange ? 'custom-date-picker-presets' : undefined}
79
+ {...finalProps}
80
+ {...processedEvents}
81
+ />
82
+ )
83
+ }