@cicctencent/formily 0.0.0-stage → 0.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 (308) hide show
  1. package/.eslintrc.js +40 -0
  2. package/.prettierrc.js +28 -0
  3. package/.vscode/launch.json +23 -0
  4. package/CHANGELOG.md +8 -0
  5. package/README.md +22 -2
  6. package/babel.config.js +3 -0
  7. package/build/build.js +96 -0
  8. package/build/rollup.config.bundle.js +63 -0
  9. package/build/update.version.js +35 -0
  10. package/dist/index.css +2516 -0
  11. package/dist/index.js +8377 -0
  12. package/dist/schema-field/index.css +2466 -0
  13. package/dist/schema-field/index.js +8213 -0
  14. package/dist/transform/index.js +551 -0
  15. package/dist/validate/index.js +1104 -0
  16. package/dist/vue-form/index.css +2516 -0
  17. package/dist/vue-form/index.js +8359 -0
  18. package/docs/.vuepress/client.ts +15 -0
  19. package/docs/.vuepress/components/code-preview.vue +203 -0
  20. package/docs/.vuepress/components/highlight.ts +53 -0
  21. package/docs/.vuepress/config.ts +39 -0
  22. package/docs/.vuepress/util.ts +7 -0
  23. package/docs/README.md +30 -0
  24. package/docs/components/anyOf.md +26 -0
  25. package/docs/components/array-cards.md +12 -0
  26. package/docs/components/array-collapse.md +12 -0
  27. package/docs/components/array-items.md +12 -0
  28. package/docs/components/array-table.md +12 -0
  29. package/docs/components/array-tabs.md +16 -0
  30. package/docs/components/cascader.md +12 -0
  31. package/docs/components/checkbox.md +12 -0
  32. package/docs/components/event.md +27 -0
  33. package/docs/components/hotArea.md +25 -0
  34. package/docs/components/index.md +4 -0
  35. package/docs/components/input.md +30 -0
  36. package/docs/components/layout-group.md +19 -0
  37. package/docs/components/link.md +22 -0
  38. package/docs/components/oneOf.md +8 -0
  39. package/docs/components/radio.md +12 -0
  40. package/docs/components/rich-editor.md +21 -0
  41. package/docs/components/select.md +34 -0
  42. package/docs/components/space.md +11 -0
  43. package/docs/components/switch.md +20 -0
  44. package/docs/components/text.md +21 -0
  45. package/docs/components/time-picker.md +11 -0
  46. package/docs/components/transfer.md +14 -0
  47. package/docs/components/upload-button.md +28 -0
  48. package/docs/demos/any-of/index.vue +66 -0
  49. package/docs/demos/array-cards/index.vue +105 -0
  50. package/docs/demos/array-collapse/index.vue +155 -0
  51. package/docs/demos/array-items/index.vue +171 -0
  52. package/docs/demos/array-table/index.vue +115 -0
  53. package/docs/demos/array-tabs/index.vue +56 -0
  54. package/docs/demos/cascader/index.vue +297 -0
  55. package/docs/demos/checkbox/index.vue +39 -0
  56. package/docs/demos/event/index.vue +436 -0
  57. package/docs/demos/hotArea/index.vue +240 -0
  58. package/docs/demos/index.vue +36 -0
  59. package/docs/demos/input/index.vue +46 -0
  60. package/docs/demos/layout-group/index.vue +51 -0
  61. package/docs/demos/link/index.vue +32 -0
  62. package/docs/demos/radio/index.vue +36 -0
  63. package/docs/demos/rich-editor/index.vue +22 -0
  64. package/docs/demos/select/index.vue +76 -0
  65. package/docs/demos/space/index.vue +93 -0
  66. package/docs/demos/switch/index.vue +31 -0
  67. package/docs/demos/text/index.vue +38 -0
  68. package/docs/demos/time-picker/index.vue +39 -0
  69. package/docs/demos/transfer/index.vue +26 -0
  70. package/docs/demos/upload-button/index.vue +27 -0
  71. package/docs/demos/x-data/add-button-title.vue +101 -0
  72. package/docs/demos/x-data/send-message.vue +33 -0
  73. package/docs/demos/x-reactions/any-of.vue +40 -0
  74. package/docs/demos/x-reactions/x-reactions.vue +39 -0
  75. package/docs/guide/component-extend.md +23 -0
  76. package/docs/guide/extra-bury-report.md +64 -0
  77. package/docs/guide/schema.md +22 -0
  78. package/docs/guide/x-data.md +41 -0
  79. package/docs/guide/x-reactions.md +20 -0
  80. package/example/.browserslistrc +4 -0
  81. package/example/.eslintrc.js +20 -0
  82. package/example/README.md +24 -0
  83. package/example/index.html +15 -0
  84. package/example/jest.config.js +26 -0
  85. package/example/package.json +50 -0
  86. package/example/public/favicon.ico +0 -0
  87. package/example/public/index.html +17 -0
  88. package/example/src/App.vue +25 -0
  89. package/example/src/assets/logo.png +0 -0
  90. package/example/src/components/HelloWorld.vue +148 -0
  91. package/example/src/components/group/index.vue +16 -0
  92. package/example/src/components/uploadBtn/index.vue +44 -0
  93. package/example/src/components/uploadBtn/upload-icon.svg +6 -0
  94. package/example/src/layout/component/Aside.vue +39 -0
  95. package/example/src/layout/component/Main.vue +9 -0
  96. package/example/src/layout/index.vue +15 -0
  97. package/example/src/main.ts +17 -0
  98. package/example/src/router/index.ts +99 -0
  99. package/example/src/shims-vue.d.ts +6 -0
  100. package/example/src/store/index.ts +9 -0
  101. package/example/src/views/demo/any-of/data.ts +38 -0
  102. package/example/src/views/demo/any-of/index.vue +35 -0
  103. package/example/src/views/demo/array-cards/data.ts +65 -0
  104. package/example/src/views/demo/array-cards/index.vue +33 -0
  105. package/example/src/views/demo/array-items/data.ts +29 -0
  106. package/example/src/views/demo/array-items/index.vue +33 -0
  107. package/example/src/views/demo/cloud-button/data.ts +14 -0
  108. package/example/src/views/demo/cloud-button/index.vue +22 -0
  109. package/example/src/views/demo/color-group/data.ts +15 -0
  110. package/example/src/views/demo/color-group/index.vue +22 -0
  111. package/example/src/views/demo/color-picker/data.ts +21 -0
  112. package/example/src/views/demo/color-picker/index.vue +33 -0
  113. package/example/src/views/demo/datatime/data.ts +62 -0
  114. package/example/src/views/demo/datatime/index.vue +22 -0
  115. package/example/src/views/demo/event/data.ts +184 -0
  116. package/example/src/views/demo/event/index.vue +33 -0
  117. package/example/src/views/demo/hot-area/data.ts +196 -0
  118. package/example/src/views/demo/hot-area/index.vue +33 -0
  119. package/example/src/views/demo/input/data.ts +39 -0
  120. package/example/src/views/demo/input/index.vue +33 -0
  121. package/example/src/views/demo/link/data.ts +23 -0
  122. package/example/src/views/demo/link/index.vue +22 -0
  123. package/example/src/views/demo/one-of/data.ts +139 -0
  124. package/example/src/views/demo/one-of/index.vue +33 -0
  125. package/example/src/views/demo/rich-editor/data.ts +12 -0
  126. package/example/src/views/demo/rich-editor/index.vue +24 -0
  127. package/example/src/views/demo/select/data.ts +38 -0
  128. package/example/src/views/demo/select/index.vue +33 -0
  129. package/example/src/views/demo/upload-button/data1.ts +11 -0
  130. package/example/src/views/demo/upload-button/data2.ts +12 -0
  131. package/example/src/views/demo/upload-button/index.vue +42 -0
  132. package/example/tsconfig.json +32 -0
  133. package/example/vite.config.ts +12 -0
  134. package/jest.config.js +4 -0
  135. package/package.json +92 -4
  136. package/src/components/__builtins__/configs/index.ts +1 -0
  137. package/src/components/__builtins__/index.ts +2 -0
  138. package/src/components/__builtins__/shared/create-context.ts +54 -0
  139. package/src/components/__builtins__/shared/index.ts +7 -0
  140. package/src/components/__builtins__/shared/loading.ts +20 -0
  141. package/src/components/__builtins__/shared/portal.ts +43 -0
  142. package/src/components/__builtins__/shared/resolve-component.ts +22 -0
  143. package/src/components/__builtins__/shared/transform-component.ts +33 -0
  144. package/src/components/__builtins__/shared/types.ts +8 -0
  145. package/src/components/__builtins__/shared/utils.ts +35 -0
  146. package/src/components/__builtins__/styles/common.scss +22 -0
  147. package/src/components/__builtins__/styles/element-plus.scss +1094 -0
  148. package/src/components/any-of/index.ts +20 -0
  149. package/src/components/array-base/index.ts +413 -0
  150. package/src/components/array-base/style.scss +53 -0
  151. package/src/components/array-base/style.ts +2 -0
  152. package/src/components/array-cards/index.ts +253 -0
  153. package/src/components/array-cards/style.scss +33 -0
  154. package/src/components/array-cards/style.ts +7 -0
  155. package/src/components/array-collapse/index.ts +381 -0
  156. package/src/components/array-collapse/style.scss +38 -0
  157. package/src/components/array-collapse/style.ts +10 -0
  158. package/src/components/array-items/index.ts +213 -0
  159. package/src/components/array-items/style.scss +82 -0
  160. package/src/components/array-items/style.ts +4 -0
  161. package/src/components/array-table/index.ts +567 -0
  162. package/src/components/array-table/style.scss +84 -0
  163. package/src/components/array-table/style.ts +11 -0
  164. package/src/components/array-tabs/index.ts +141 -0
  165. package/src/components/array-tabs/style.scss +16 -0
  166. package/src/components/array-tabs/style.ts +5 -0
  167. package/src/components/base/AnyOf/index.ts +155 -0
  168. package/src/components/base/AnyOf/index.vue +111 -0
  169. package/src/components/base/CloudButton/index.ts +46 -0
  170. package/src/components/base/CloudButton/index.vue +128 -0
  171. package/src/components/base/ColorGroup/index.ts +57 -0
  172. package/src/components/base/ColorGroup/index.vue +30 -0
  173. package/src/components/base/ColorPicker/index.ts +45 -0
  174. package/src/components/base/ColorPicker/index.vue +50 -0
  175. package/src/components/base/Container/index.vue +39 -0
  176. package/src/components/base/HotArea/index.ts +698 -0
  177. package/src/components/base/HotArea/index.vue +565 -0
  178. package/src/components/base/HotArea/type.ts +18 -0
  179. package/src/components/base/Input/index.vue +150 -0
  180. package/src/components/base/LayoutGroup/index.vue +40 -0
  181. package/src/components/base/Link/index.vue +43 -0
  182. package/src/components/base/Middleware/index.ts +235 -0
  183. package/src/components/base/Middleware/index.vue +169 -0
  184. package/src/components/base/OneOf/index.ts +105 -0
  185. package/src/components/base/OneOf/index.vue +85 -0
  186. package/src/components/base/RichEditor/index.ts +13 -0
  187. package/src/components/base/RichEditor/index.vue +120 -0
  188. package/src/components/base/RichEditor/options.ts +24 -0
  189. package/src/components/base/Select/index.ts +106 -0
  190. package/src/components/base/Select/index.vue +161 -0
  191. package/src/components/base/Switch/index.vue +42 -0
  192. package/src/components/base/Text/index.vue +47 -0
  193. package/src/components/base/event/index.ts +226 -0
  194. package/src/components/base/event/index.vue +356 -0
  195. package/src/components/cascader/index.ts +48 -0
  196. package/src/components/cascader/style.ts +5 -0
  197. package/src/components/checkbox/index.ts +166 -0
  198. package/src/components/checkbox/style.ts +5 -0
  199. package/src/components/cloud-button/index.ts +21 -0
  200. package/src/components/color-group/index.ts +18 -0
  201. package/src/components/color-picker/index.ts +18 -0
  202. package/src/components/container/index.ts +18 -0
  203. package/src/components/data-time/index.ts +24 -0
  204. package/src/components/date-picker/index.ts +51 -0
  205. package/src/components/date-picker/style.ts +4 -0
  206. package/src/components/editable/index.ts +261 -0
  207. package/src/components/editable/style.scss +55 -0
  208. package/src/components/editable/style.ts +5 -0
  209. package/src/components/el-form-item/index.ts +21 -0
  210. package/src/components/el-form-item/style.ts +3 -0
  211. package/src/components/event/index.ts +16 -0
  212. package/src/components/form/index.ts +94 -0
  213. package/src/components/form/style.scss +0 -0
  214. package/src/components/form/style.ts +3 -0
  215. package/src/components/form-button-group/index.ts +74 -0
  216. package/src/components/form-button-group/style.scss +0 -0
  217. package/src/components/form-button-group/style.ts +4 -0
  218. package/src/components/form-collapse/index.ts +215 -0
  219. package/src/components/form-collapse/style.scss +6 -0
  220. package/src/components/form-collapse/style.ts +4 -0
  221. package/src/components/form-dialog/index.ts +433 -0
  222. package/src/components/form-dialog/style.ts +4 -0
  223. package/src/components/form-drawer/index.ts +424 -0
  224. package/src/components/form-drawer/style.scss +21 -0
  225. package/src/components/form-drawer/style.ts +4 -0
  226. package/src/components/form-grid/index.ts +181 -0
  227. package/src/components/form-grid/style.scss +5 -0
  228. package/src/components/form-grid/style.ts +1 -0
  229. package/src/components/form-item/animation.scss +72 -0
  230. package/src/components/form-item/grid.scss +171 -0
  231. package/src/components/form-item/index.ts +642 -0
  232. package/src/components/form-item/style.scss +521 -0
  233. package/src/components/form-item/style.ts +2 -0
  234. package/src/components/form-item/var.scss +17 -0
  235. package/src/components/form-layout/index.ts +161 -0
  236. package/src/components/form-layout/style.scss +6 -0
  237. package/src/components/form-layout/style.ts +1 -0
  238. package/src/components/form-layout/useResponsiveFormLayout.ts +118 -0
  239. package/src/components/form-step/index.ts +210 -0
  240. package/src/components/form-step/style.ts +2 -0
  241. package/src/components/form-tab/index.ts +172 -0
  242. package/src/components/form-tab/style.scss +6 -0
  243. package/src/components/form-tab/style.ts +4 -0
  244. package/src/components/hot-area/index.ts +20 -0
  245. package/src/components/index.ts +49 -0
  246. package/src/components/input/index.ts +35 -0
  247. package/src/components/input/style.ts +4 -0
  248. package/src/components/input-number/index.ts +36 -0
  249. package/src/components/input-number/style.ts +3 -0
  250. package/src/components/layout-group/index.ts +18 -0
  251. package/src/components/link/index.ts +18 -0
  252. package/src/components/middleware/index.ts +21 -0
  253. package/src/components/one-of/index.ts +20 -0
  254. package/src/components/placeholder-input/index.ts +21 -0
  255. package/src/components/placeholder-input/index.vue +87 -0
  256. package/src/components/preview-text/index.ts +303 -0
  257. package/src/components/preview-text/style.ts +9 -0
  258. package/src/components/radio/index.ts +109 -0
  259. package/src/components/radio/style.ts +3 -0
  260. package/src/components/reset/index.ts +52 -0
  261. package/src/components/reset/style.ts +1 -0
  262. package/src/components/rich-editor/index.ts +18 -0
  263. package/src/components/row/index.ts +20 -0
  264. package/src/components/row/index.vue +53 -0
  265. package/src/components/select/index.ts +19 -0
  266. package/src/components/select/style.ts +5 -0
  267. package/src/components/space/index.ts +98 -0
  268. package/src/components/space/style.scss +24 -0
  269. package/src/components/space/style.ts +1 -0
  270. package/src/components/submit/index.ts +59 -0
  271. package/src/components/submit/style.ts +1 -0
  272. package/src/components/switch/index.ts +9 -0
  273. package/src/components/switch/style.ts +1 -0
  274. package/src/components/text/index.ts +21 -0
  275. package/src/components/time-picker/index.ts +21 -0
  276. package/src/components/time-picker/style.ts +4 -0
  277. package/src/components/transfer/index.ts +12 -0
  278. package/src/components/transfer/style.ts +1 -0
  279. package/src/components/upload/index.ts +136 -0
  280. package/src/components/upload/style.ts +2 -0
  281. package/src/components/upload-button/index.ts +21 -0
  282. package/src/components/upload-button/index.vue +199 -0
  283. package/src/createScemaField.ts +14 -0
  284. package/src/index.ts +41 -0
  285. package/src/schema-field/index.ts +11 -0
  286. package/src/scope.ts +29 -0
  287. package/src/transform/core.ts +404 -0
  288. package/src/transform/index.ts +11 -0
  289. package/src/transform/transform.ts +59 -0
  290. package/src/transform/utils/constant.ts +79 -0
  291. package/src/transform/utils/func.ts +145 -0
  292. package/src/typings/common.ts +37 -0
  293. package/src/typings/vue-shim.d.ts +7 -0
  294. package/src/typings/vue-test-utils.d.ts +11 -0
  295. package/src/utils/anyof_utils.ts +95 -0
  296. package/src/utils/common.ts +15 -0
  297. package/src/validate/index.ts +648 -0
  298. package/src/validate/utils/constant.ts +2 -0
  299. package/src/vue-form/index.ts +18 -0
  300. package/src/vue-form/index.vue +106 -0
  301. package/src/vue-form/useForm.ts +112 -0
  302. package/tests/data/anyof.ts +40 -0
  303. package/tests/data/image.ts +472 -0
  304. package/tests/fixtures/validate.ts +63 -0
  305. package/tests/unit/transform.spec.ts +253 -0
  306. package/tests/unit/utils.spec.ts +10 -0
  307. package/tests/unit/validate.spec.ts +256 -0
  308. package/tsconfig.json +23 -0
@@ -0,0 +1,20 @@
1
+ import { transformComponent } from '../__builtins__';
2
+ import { mapProps, connect } from '@formily/vue';
3
+
4
+ import JtAnyOf from '../base/AnyOf/index.vue';
5
+
6
+ export type JtAnyOfProps = typeof JtAnyOf;
7
+
8
+ const TransformJtOneAny = transformComponent<JtAnyOfProps>(JtAnyOf, {
9
+ change: 'update:modelValue',
10
+ });
11
+
12
+ export const AnyOf = connect(
13
+ TransformJtOneAny,
14
+ mapProps({
15
+ value: 'modelValue',
16
+ readOnly: 'readonly',
17
+ })
18
+ );
19
+
20
+ export default AnyOf;
@@ -0,0 +1,413 @@
1
+ import {
2
+ defineComponent,
3
+ provide,
4
+ InjectionKey,
5
+ Ref,
6
+ inject,
7
+ toRefs,
8
+ ref,
9
+ onBeforeUnmount,
10
+ PropType,
11
+ h,
12
+ } from 'vue'
13
+ import { FragmentComponent, useField, useFieldSchema } from '@formily/vue'
14
+ import { isValid, uid, clone } from '@formily/shared'
15
+ import { ArrayField } from '@formily/core'
16
+ import type { ButtonProps as ElButtonProps } from '@cicctencent/jtui'
17
+ import { ElButton } from '@cicctencent/jtui'
18
+ import type { Schema } from '@formily/json-schema'
19
+ // import { HandleDirective } from 'vue-slicksort'
20
+ import { Delete, ArrowUp, ArrowDown, Rank } from '@cicctencent/icons-vue'
21
+
22
+ import { stylePrefix } from '../__builtins__/configs'
23
+ import { composeExport } from '../__builtins__/shared'
24
+
25
+ export interface IArrayBaseAdditionProps extends ElButtonProps {
26
+ title?: string
27
+ method?: 'push' | 'unshift'
28
+ defaultValue?: any
29
+ }
30
+
31
+ export type ArrayBaseMixins = {
32
+ Addition?: typeof ArrayBaseAddition
33
+ Remove?: typeof ArrayBaseRemove
34
+ MoveUp?: typeof ArrayBaseMoveUp
35
+ MoveDown?: typeof ArrayBaseMoveDown
36
+ SortHandle?: typeof ArrayBaseSortHandle
37
+ Index?: typeof ArrayBaseIndex
38
+ useArray?: typeof useArray
39
+ useIndex?: typeof useIndex
40
+ useRecord?: typeof useRecord
41
+ }
42
+
43
+ export interface IArrayBaseProps {
44
+ disabled?: boolean
45
+ keyMap?: WeakMap<Record<string, unknown>, string> | string[] | null
46
+ }
47
+
48
+ export interface IArrayBaseItemProps {
49
+ index: number
50
+ record: any
51
+ }
52
+
53
+ export interface IArrayBaseContext {
54
+ field: Ref<ArrayField>
55
+ schema: Ref<Schema>
56
+ props: IArrayBaseProps
57
+ attrs: {
58
+ [key in string]?: any
59
+ }
60
+ keyMap?: WeakMap<Record<string, unknown>, string> | string[] | null
61
+ }
62
+
63
+ const ArrayBaseSymbol: InjectionKey<IArrayBaseContext> =
64
+ Symbol('ArrayBaseContext')
65
+ const ItemSymbol: InjectionKey<IArrayBaseItemProps> = Symbol('ItemContext')
66
+
67
+ const useArray = () => {
68
+ return inject(ArrayBaseSymbol, null)
69
+ }
70
+
71
+ const useIndex = (index?: number) => {
72
+ const { index: indexRef } = toRefs(inject(ItemSymbol) as IArrayBaseItemProps)
73
+ return indexRef ?? ref(index)
74
+ }
75
+
76
+ const useRecord = (record?: number) => {
77
+ const { record: recordRef } = toRefs(
78
+ inject(ItemSymbol) as IArrayBaseItemProps
79
+ )
80
+ return recordRef ?? ref(record)
81
+ }
82
+
83
+ const isObjectValue: (schema: Schema) => boolean = (schema: Schema) => {
84
+ if (Array.isArray(schema?.items)) return isObjectValue(schema.items[0])
85
+
86
+ if (schema?.items?.type === 'array' || schema?.items?.type === 'object') {
87
+ return true
88
+ }
89
+ return false
90
+ }
91
+
92
+ const useKey = (schema: Schema) => {
93
+ const isObject = isObjectValue(schema)
94
+ let keyMap: WeakMap<Record<string, unknown>, string> | string[] | null = null
95
+
96
+ if (isObject) {
97
+ keyMap = new WeakMap()
98
+ } else {
99
+ keyMap = []
100
+ }
101
+
102
+ onBeforeUnmount(() => {
103
+ keyMap = null
104
+ })
105
+
106
+ return {
107
+ keyMap,
108
+ getKey: (record: any, index: number) => {
109
+ if (keyMap instanceof WeakMap) {
110
+ if (!keyMap.has(record)) {
111
+ keyMap.set(record, uid())
112
+ }
113
+ return `${keyMap.get(record)}-${index}`
114
+ }
115
+
116
+ if (keyMap && !keyMap[index]) {
117
+ keyMap[index] = uid()
118
+ }
119
+ return keyMap ? `${keyMap[index]}-${index}` : undefined
120
+ },
121
+ }
122
+ }
123
+
124
+ const getDefaultValue = (defaultValue: any, schema: Schema): any => {
125
+ if (isValid(defaultValue)) return clone(defaultValue)
126
+ if (Array.isArray(schema?.items))
127
+ return getDefaultValue(defaultValue, schema.items[0])
128
+ if (schema?.items?.type === 'array') return []
129
+ if (schema?.items?.type === 'boolean') return true
130
+ if (schema?.items?.type === 'date') return ''
131
+ if (schema?.items?.type === 'datetime') return ''
132
+ if (schema?.items?.type === 'number') return 0
133
+ if (schema?.items?.type === 'object') return {}
134
+ if (schema?.items?.type === 'string') return ''
135
+ return null
136
+ }
137
+
138
+ const ArrayBaseInner = defineComponent({
139
+ name: 'ArrayBase',
140
+ props: {
141
+ disabled: {
142
+ type: Boolean,
143
+ default: false,
144
+ },
145
+ keyMap: {
146
+ type: [WeakMap, Array] as PropType<
147
+ WeakMap<Record<string, unknown>, string> | string[]
148
+ >,
149
+ },
150
+ },
151
+ setup(props, { slots, attrs }) {
152
+ const field = useField<ArrayField>()
153
+ const schema = useFieldSchema()
154
+
155
+ provide(ArrayBaseSymbol, {
156
+ field: field as any,
157
+ schema: schema as any,
158
+ props,
159
+ attrs,
160
+ keyMap: props.keyMap,
161
+ })
162
+ return () => {
163
+ return h(FragmentComponent, {}, slots)
164
+ }
165
+ },
166
+ })
167
+
168
+ const ArrayBaseItem = defineComponent({
169
+ name: 'ArrayBaseItem',
170
+ props: ['index', 'record'],
171
+ setup(props: IArrayBaseItemProps, { slots }) {
172
+ provide(ItemSymbol, props)
173
+ return () => {
174
+ return h(FragmentComponent, {}, slots)
175
+ }
176
+ },
177
+ })
178
+
179
+ const ArrayBaseSortHandle = defineComponent({
180
+ name: 'ArrayBaseSortHandle',
181
+ props: ['index'],
182
+ directives: {
183
+ // handle: HandleDirective,
184
+ },
185
+ setup(props, { attrs }) {
186
+ const array = useArray()
187
+ const prefixCls = `${stylePrefix}-array-base`
188
+
189
+ return () => {
190
+ if (!array) return null
191
+ if (array.field.value?.pattern !== 'editable') return null
192
+
193
+ return h(
194
+ ElButton,
195
+ {
196
+ directives: [{ name: 'handle' }],
197
+ size: 'small',
198
+ type: 'text',
199
+ icon: Rank,
200
+ ...attrs,
201
+ class: [`${prefixCls}-sort-handle`].concat(attrs.class as any),
202
+ },
203
+ {}
204
+ )
205
+ }
206
+ },
207
+ })
208
+
209
+ const ArrayBaseIndex = defineComponent({
210
+ name: 'ArrayBaseIndex',
211
+ setup(props, { attrs }) {
212
+ const index = useIndex()
213
+ const prefixCls = `${stylePrefix}-array-base`
214
+ return () => {
215
+ return h(
216
+ 'span',
217
+ {
218
+ class: `${prefixCls}-index`,
219
+ ...attrs,
220
+ },
221
+ {
222
+ // default: () => [`#${index.value + 1}.`],
223
+ default: () => [`${index.value + 1}.`],
224
+ }
225
+ )
226
+ }
227
+ },
228
+ })
229
+
230
+ const ArrayBaseAddition = defineComponent({
231
+ name: 'ArrayBaseAddition',
232
+ props: ['method', 'defaultValue', 'title', 'type', "plain",'size'],
233
+ setup(props, { attrs }) {
234
+ const self = useField()
235
+ const array = useArray()
236
+ const prefixCls = `${stylePrefix}-array-base`
237
+ return () => {
238
+ if (!array) return null
239
+ if (array?.field.value.pattern !== 'editable') return null
240
+ return h(
241
+ ElButton,
242
+ {
243
+ ...attrs,
244
+ ...props,
245
+ class: `${prefixCls}-addition`,
246
+ icon: 'qax-icon-Alone-Plus',
247
+ onClick: (e) => {
248
+ if (array.props?.disabled) return
249
+ const defaultValue = getDefaultValue(
250
+ props.defaultValue,
251
+ array?.schema.value
252
+ )
253
+ if (props.method === 'unshift') {
254
+ array?.field?.value.unshift(defaultValue)
255
+ array.attrs?.add?.(0)
256
+ } else {
257
+ array?.field?.value.push(defaultValue)
258
+ array.attrs?.add?.(array?.field?.value?.value?.length - 1)
259
+ }
260
+ if (typeof attrs.onClick === 'function') {
261
+ attrs.onClick(e)
262
+ }
263
+ },
264
+ },
265
+ {
266
+ default: () => [self.value.title || props.title],
267
+ }
268
+ )
269
+ }
270
+ },
271
+ })
272
+
273
+ const ArrayBaseRemove:any = defineComponent<
274
+ ElButtonProps & { title?: string; index?: number }
275
+ >({
276
+ name: 'ArrayBaseRemove',
277
+ setup(props, { attrs }) {
278
+ const indexRef = useIndex(props.index)
279
+ const base = useArray()
280
+ const prefixCls = `${stylePrefix}-array-base`
281
+ return () => {
282
+ if (base?.field.value.pattern !== 'editable') return null
283
+ return h(
284
+ ElButton,
285
+ {
286
+ class: `${prefixCls}-remove`,
287
+ type: 'text',
288
+ size: 'small',
289
+ icon: Delete,
290
+ ...attrs,
291
+ onClick: (e: MouseEvent) => {
292
+ e.stopPropagation()
293
+ if (Array.isArray(base?.keyMap)) {
294
+ base?.keyMap?.splice(indexRef.value, 1)
295
+ }
296
+
297
+ base?.field.value.remove(indexRef.value as number)
298
+ base?.attrs?.remove?.(indexRef.value as number)
299
+
300
+ if (typeof attrs.onClick === 'function') {
301
+ attrs.onClick(e)
302
+ }
303
+ },
304
+ },
305
+ {
306
+ default: () => [props.title],
307
+ }
308
+ )
309
+ }
310
+ },
311
+ })
312
+
313
+ const ArrayBaseMoveDown:any = defineComponent<
314
+ ElButtonProps & { title?: string; index?: number }
315
+ >({
316
+ name: 'ArrayBaseMoveDown',
317
+ setup(props, { attrs }) {
318
+ const indexRef = useIndex(props.index)
319
+ const base = useArray()
320
+ const prefixCls = `${stylePrefix}-array-base`
321
+ return () => {
322
+ if (base?.field.value.pattern !== 'editable') return null
323
+ return h(
324
+ ElButton,
325
+ {
326
+ class: `${prefixCls}-move-down`,
327
+ size: 'small',
328
+ type: 'text',
329
+ icon: ArrowDown,
330
+ ...attrs,
331
+ onClick: (e: MouseEvent) => {
332
+ e.stopPropagation()
333
+ if (Array.isArray(base?.keyMap)) {
334
+ base.keyMap.splice(
335
+ indexRef.value + 1,
336
+ 0,
337
+ base.keyMap.splice(indexRef.value, 1)[0]
338
+ )
339
+ }
340
+
341
+ base?.field.value.moveDown(indexRef.value as number)
342
+ base?.attrs?.moveDown?.(indexRef.value as number)
343
+
344
+ if (typeof attrs.onClick === 'function') {
345
+ attrs.onClick(e)
346
+ }
347
+ },
348
+ },
349
+ {
350
+ default: () => [props.title],
351
+ }
352
+ )
353
+ }
354
+ },
355
+ })
356
+
357
+ const ArrayBaseMoveUp:any = defineComponent<
358
+ ElButtonProps & { title?: string; index?: number }
359
+ >({
360
+ name: 'ArrayBaseMoveUp',
361
+ setup(props, { attrs }) {
362
+ const indexRef = useIndex(props.index)
363
+ const base = useArray()
364
+ const prefixCls = `${stylePrefix}-array-base`
365
+ return () => {
366
+ if (base?.field.value.pattern !== 'editable') return null
367
+ return h(
368
+ ElButton,
369
+ {
370
+ class: `${prefixCls}-move-up`,
371
+ size: 'small',
372
+ type: 'text',
373
+ icon: ArrowUp,
374
+ ...attrs,
375
+ onClick: (e: MouseEvent) => {
376
+ e.stopPropagation()
377
+ if (Array.isArray(base?.keyMap)) {
378
+ base.keyMap.splice(
379
+ indexRef.value - 1,
380
+ 0,
381
+ base.keyMap.splice(indexRef.value, 1)[0]
382
+ )
383
+ }
384
+
385
+ base?.field.value.moveUp(indexRef.value as number)
386
+ base?.attrs?.moveUp?.(indexRef.value as number)
387
+
388
+ if (typeof attrs.onClick === 'function') {
389
+ attrs.onClick(e)
390
+ }
391
+ },
392
+ },
393
+ {
394
+ default: () => [props.title],
395
+ }
396
+ )
397
+ }
398
+ },
399
+ })
400
+
401
+ export const ArrayBase = composeExport(ArrayBaseInner, {
402
+ Index: ArrayBaseIndex,
403
+ Item: ArrayBaseItem,
404
+ SortHandle: ArrayBaseSortHandle,
405
+ Addition: ArrayBaseAddition,
406
+ Remove: ArrayBaseRemove,
407
+ MoveDown: ArrayBaseMoveDown,
408
+ MoveUp: ArrayBaseMoveUp,
409
+ useArray: useArray,
410
+ useIndex: useIndex,
411
+ useKey: useKey,
412
+ useRecord: useRecord,
413
+ })
@@ -0,0 +1,53 @@
1
+ @import '../__builtins__/styles/common.scss';
2
+
3
+ $array-base-prefix-cls: '#{$formily-prefix}-array-base';
4
+
5
+ .#{$array-base-prefix-cls}-addition {
6
+ // transition: $--all-transition;
7
+ // max-width: 200px;
8
+ // border: none !important;
9
+ display: flex;
10
+ align-items: center;
11
+ font-style: normal;
12
+ font-weight: 400;
13
+ font-size: 14px;
14
+ line-height: 20px;
15
+ color: #000000;
16
+ cursor: pointer;
17
+ &::before {
18
+ content: '+';
19
+ display: block;
20
+ width: 18px;
21
+ height: 18px;
22
+ // border: 1px dashed rgba(0, 0, 0, 0.4);
23
+ display: flex;
24
+ justify-content: center;
25
+ align-items: center;
26
+ margin-right: 10px;
27
+ }
28
+ }
29
+
30
+ .#{$array-base-prefix-cls}-remove {
31
+ i {
32
+ font-size: $--font-size-base;
33
+ }
34
+ }
35
+
36
+ .#{$array-base-prefix-cls}-move-down {
37
+ i {
38
+ font-size: $--font-size-base;
39
+ }
40
+ }
41
+
42
+ .#{$array-base-prefix-cls}-move-up {
43
+ i {
44
+ font-size: $--font-size-base;
45
+ }
46
+ }
47
+
48
+ .#{$array-base-prefix-cls}-sort-handle {
49
+ i {
50
+ font-size: $--font-size-base;
51
+ cursor: move;
52
+ }
53
+ }
@@ -0,0 +1,2 @@
1
+ import '@cicctencent/jtui/theme-chalk/src/button.scss';
2
+ import './style.scss'