vue-devui 1.0.0-rc.1 → 1.0.0-rc.12

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 (352) hide show
  1. package/README.md +70 -121
  2. package/alert/index.es.js +46 -15
  3. package/alert/index.umd.js +1 -1
  4. package/alert/style.css +1 -1
  5. package/auto-complete/index.es.js +8204 -296
  6. package/auto-complete/index.umd.js +29 -1
  7. package/auto-complete/style.css +1 -1
  8. package/avatar/index.es.js +153 -146
  9. package/avatar/index.umd.js +1 -1
  10. package/avatar/style.css +1 -1
  11. package/badge/index.es.js +36 -5
  12. package/badge/index.umd.js +1 -1
  13. package/badge/style.css +1 -1
  14. package/button/index.es.js +5727 -111
  15. package/button/index.umd.js +27 -1
  16. package/button/style.css +1 -1
  17. package/card/index.es.js +63 -35
  18. package/card/index.umd.js +1 -1
  19. package/card/style.css +1 -1
  20. package/checkbox/index.es.js +8068 -255
  21. package/checkbox/index.umd.js +27 -1
  22. package/checkbox/style.css +1 -1
  23. package/{accordion → collapse}/index.d.ts +0 -0
  24. package/collapse/index.es.js +213 -0
  25. package/collapse/index.umd.js +1 -0
  26. package/{anchor → collapse}/package.json +1 -1
  27. package/collapse/style.css +1 -0
  28. package/countdown/index.es.js +59 -19
  29. package/countdown/index.umd.js +1 -1
  30. package/{anchor → date-picker-pro}/index.d.ts +0 -0
  31. package/date-picker-pro/index.es.js +10856 -0
  32. package/date-picker-pro/index.umd.js +27 -0
  33. package/{breadcrumb → date-picker-pro}/package.json +1 -1
  34. package/date-picker-pro/style.css +1 -0
  35. package/drawer/index.es.js +31 -4
  36. package/drawer/index.umd.js +1 -1
  37. package/drawer/style.css +1 -1
  38. package/dropdown/index.es.js +210 -149
  39. package/dropdown/index.umd.js +1 -1
  40. package/dropdown/style.css +1 -1
  41. package/editable-select/index.es.js +569 -159
  42. package/editable-select/index.umd.js +1 -1
  43. package/editable-select/style.css +1 -1
  44. package/form/index.es.js +1048 -1187
  45. package/form/index.umd.js +15 -15
  46. package/form/style.css +1 -1
  47. package/fullscreen/index.es.js +29 -5
  48. package/fullscreen/index.umd.js +1 -1
  49. package/fullscreen/style.css +1 -1
  50. package/grid/index.es.js +101 -86
  51. package/grid/index.umd.js +1 -1
  52. package/grid/style.css +1 -1
  53. package/icon/index.es.js +183 -23
  54. package/icon/index.umd.js +1 -1
  55. package/icon/style.css +1 -0
  56. package/image-preview/index.es.js +53 -30
  57. package/image-preview/index.umd.js +1 -1
  58. package/image-preview/style.css +1 -1
  59. package/input/index.es.js +8101 -144
  60. package/input/index.umd.js +27 -1
  61. package/input/style.css +1 -1
  62. package/input-number/index.es.js +274 -177
  63. package/input-number/index.umd.js +1 -1
  64. package/input-number/style.css +1 -1
  65. package/layout/index.es.js +40 -25
  66. package/layout/index.umd.js +1 -1
  67. package/layout/style.css +1 -1
  68. package/loading/index.es.js +74 -35
  69. package/loading/index.umd.js +1 -1
  70. package/loading/style.css +1 -1
  71. package/modal/index.es.js +375 -171
  72. package/modal/index.umd.js +1 -1
  73. package/modal/style.css +1 -1
  74. package/notification/index.es.js +293 -40
  75. package/notification/index.umd.js +1 -1
  76. package/notification/style.css +1 -1
  77. package/nuxt/components/ButtonGroup.js +3 -0
  78. package/nuxt/components/CheckboxButton.js +3 -0
  79. package/nuxt/components/CheckboxGroup.js +3 -0
  80. package/nuxt/components/Collapse.js +3 -0
  81. package/nuxt/components/CollapseItem.js +3 -0
  82. package/nuxt/components/DRangeDatePickerPro.js +3 -0
  83. package/nuxt/components/DatePickerPro.js +3 -0
  84. package/nuxt/components/DropdownPropsKey.js +3 -0
  85. package/nuxt/components/FORM_ITEM_TOKEN.js +3 -0
  86. package/nuxt/components/FORM_TOKEN.js +3 -0
  87. package/nuxt/components/Icon.js +1 -0
  88. package/nuxt/components/IconGroup.js +3 -0
  89. package/nuxt/components/LABEL_DATA.js +3 -0
  90. package/nuxt/components/LoadingOptions.js +3 -0
  91. package/nuxt/components/Option.js +3 -0
  92. package/nuxt/components/OptionGroup.js +3 -0
  93. package/nuxt/components/RadioButton.js +3 -0
  94. package/nuxt/components/Step.js +3 -0
  95. package/nuxt/components/Steps.js +3 -0
  96. package/nuxt/components/TABLE_TOKEN.js +3 -0
  97. package/nuxt/components/Tab.js +3 -0
  98. package/nuxt/components/TimeSelect.js +3 -0
  99. package/nuxt/components/autoCompleteProps.js +3 -0
  100. package/nuxt/components/avatarProps.js +3 -0
  101. package/nuxt/components/buttonGroupInjectionKey.js +3 -0
  102. package/nuxt/components/buttonGroupProps.js +3 -0
  103. package/nuxt/components/cardProps.js +3 -0
  104. package/nuxt/components/checkboxGroupInjectionKey.js +3 -0
  105. package/nuxt/components/checkboxGroupProps.js +3 -0
  106. package/nuxt/components/checkboxProps.js +3 -0
  107. package/nuxt/components/colProps.js +3 -0
  108. package/nuxt/components/colPropsBaseClass.js +3 -0
  109. package/nuxt/components/colPropsBaseStyle.js +3 -0
  110. package/nuxt/components/collapseItemProps.js +3 -0
  111. package/nuxt/components/collapseProps.js +3 -0
  112. package/nuxt/components/countdownProps.js +3 -0
  113. package/nuxt/components/datePickerProCommonProps.js +3 -0
  114. package/nuxt/components/datePickerProPanelProps.js +3 -0
  115. package/nuxt/components/datePickerProProps.js +3 -0
  116. package/nuxt/components/editableSelectProps.js +3 -0
  117. package/nuxt/components/formItemProps.js +3 -0
  118. package/nuxt/components/formProps.js +3 -0
  119. package/nuxt/components/iconProps.js +1 -0
  120. package/nuxt/components/imagePreviewProps.js +3 -0
  121. package/nuxt/components/inputProps.js +3 -0
  122. package/nuxt/components/loadingProps.js +3 -0
  123. package/nuxt/components/modalProps.js +3 -0
  124. package/nuxt/components/progressProps.js +3 -0
  125. package/nuxt/components/rateProps.js +3 -0
  126. package/nuxt/components/resultProps.js +3 -0
  127. package/nuxt/components/rowProps.js +3 -0
  128. package/nuxt/components/screenSizes.js +3 -0
  129. package/nuxt/components/skeletonProps.js +3 -0
  130. package/nuxt/components/sliderProps.js +3 -0
  131. package/nuxt/components/splitterProps.js +3 -0
  132. package/nuxt/components/statisticProps.js +3 -0
  133. package/nuxt/components/stepProps.js +3 -0
  134. package/nuxt/components/stepsProps.js +3 -0
  135. package/nuxt/components/svgIconProps.js +3 -0
  136. package/nuxt/components/switchProps.js +3 -0
  137. package/nuxt/components/tableProps.js +3 -0
  138. package/nuxt/components/tabsProps.js +3 -0
  139. package/nuxt/components/tagProps.js +3 -0
  140. package/nuxt/components/textareaProps.js +3 -0
  141. package/nuxt/components/timeAxisProps.js +3 -0
  142. package/nuxt/components/timerPickerPanelProps.js +3 -0
  143. package/nuxt/components/treeProps.js +3 -0
  144. package/overlay/index.es.js +104 -133
  145. package/overlay/index.umd.js +1 -1
  146. package/overlay/style.css +1 -1
  147. package/package.json +4 -2
  148. package/pagination/index.es.js +171 -141
  149. package/pagination/index.umd.js +1 -1
  150. package/pagination/style.css +1 -1
  151. package/panel/style.css +1 -1
  152. package/popover/index.es.js +294 -230
  153. package/popover/index.umd.js +15 -15
  154. package/popover/style.css +1 -1
  155. package/progress/index.es.js +110 -56
  156. package/progress/index.umd.js +3 -3
  157. package/progress/style.css +1 -1
  158. package/radio/index.es.js +7967 -146
  159. package/radio/index.umd.js +27 -1
  160. package/radio/style.css +1 -1
  161. package/rate/index.es.js +77 -55
  162. package/rate/index.umd.js +1 -1
  163. package/rate/style.css +1 -1
  164. package/result/index.es.js +170 -27
  165. package/result/index.umd.js +1 -1
  166. package/result/style.css +1 -1
  167. package/ripple/index.es.js +43 -42
  168. package/ripple/index.umd.js +1 -1
  169. package/search/index.es.js +3660 -1097
  170. package/search/index.umd.js +18 -18
  171. package/search/style.css +1 -1
  172. package/select/index.es.js +8998 -487
  173. package/select/index.umd.js +27 -1
  174. package/select/style.css +1 -1
  175. package/skeleton/index.es.js +46 -24
  176. package/skeleton/index.umd.js +1 -1
  177. package/skeleton/style.css +1 -1
  178. package/slider/index.es.js +144 -138
  179. package/slider/index.umd.js +1 -1
  180. package/slider/style.css +1 -1
  181. package/splitter/index.es.js +468 -340
  182. package/splitter/index.umd.js +16 -16
  183. package/splitter/style.css +1 -1
  184. package/statistic/index.es.js +41 -34
  185. package/statistic/index.umd.js +1 -1
  186. package/statistic/style.css +1 -1
  187. package/status/index.es.js +26 -2
  188. package/status/index.umd.js +1 -1
  189. package/status/style.css +1 -1
  190. package/{back-top → steps}/index.d.ts +0 -0
  191. package/steps/index.es.js +385 -0
  192. package/steps/index.umd.js +1 -0
  193. package/{gantt → steps}/package.json +1 -1
  194. package/steps/style.css +1 -0
  195. package/style.css +1 -1
  196. package/switch/index.es.js +7802 -64
  197. package/switch/index.umd.js +27 -1
  198. package/switch/style.css +1 -1
  199. package/table/index.es.js +10315 -1147
  200. package/table/index.umd.js +27 -1
  201. package/table/style.css +1 -1
  202. package/tabs/index.es.js +345 -142
  203. package/tabs/index.umd.js +1 -1
  204. package/tabs/style.css +1 -1
  205. package/tag/index.es.js +47 -23
  206. package/tag/index.umd.js +1 -1
  207. package/tag/style.css +1 -1
  208. package/textarea/index.es.js +7921 -83
  209. package/textarea/index.umd.js +35 -1
  210. package/textarea/style.css +1 -1
  211. package/time-picker/index.es.js +8704 -559
  212. package/time-picker/index.umd.js +27 -1
  213. package/time-picker/style.css +1 -1
  214. package/{breadcrumb → time-select}/index.d.ts +0 -0
  215. package/{color-picker → time-select}/index.es.js +4116 -2914
  216. package/time-select/index.umd.js +27 -0
  217. package/{back-top → time-select}/package.json +1 -1
  218. package/time-select/style.css +1 -0
  219. package/timeline/index.es.js +177 -37
  220. package/timeline/index.umd.js +1 -1
  221. package/timeline/style.css +1 -1
  222. package/tooltip/index.es.js +286 -221
  223. package/tooltip/index.umd.js +15 -15
  224. package/tooltip/style.css +1 -1
  225. package/tree/index.es.js +5325 -1855
  226. package/tree/index.umd.js +18 -18
  227. package/tree/style.css +1 -1
  228. package/upload/index.es.js +456 -133
  229. package/upload/index.umd.js +1 -1
  230. package/upload/style.css +1 -1
  231. package/vue-devui.es.js +14986 -16343
  232. package/vue-devui.umd.js +30 -20
  233. package/accordion/index.es.js +0 -723
  234. package/accordion/index.umd.js +0 -1
  235. package/accordion/package.json +0 -7
  236. package/accordion/style.css +0 -1
  237. package/anchor/index.es.js +0 -263
  238. package/anchor/index.umd.js +0 -1
  239. package/anchor/style.css +0 -1
  240. package/back-top/index.es.js +0 -130
  241. package/back-top/index.umd.js +0 -1
  242. package/back-top/style.css +0 -1
  243. package/breadcrumb/index.es.js +0 -128
  244. package/breadcrumb/index.umd.js +0 -1
  245. package/breadcrumb/style.css +0 -1
  246. package/carousel/index.d.ts +0 -7
  247. package/carousel/index.es.js +0 -314
  248. package/carousel/index.umd.js +0 -1
  249. package/carousel/package.json +0 -7
  250. package/carousel/style.css +0 -1
  251. package/cascader/index.d.ts +0 -7
  252. package/cascader/index.es.js +0 -5971
  253. package/cascader/index.umd.js +0 -27
  254. package/cascader/package.json +0 -7
  255. package/cascader/style.css +0 -1
  256. package/color-picker/index.d.ts +0 -7
  257. package/color-picker/index.umd.js +0 -27
  258. package/color-picker/package.json +0 -7
  259. package/color-picker/style.css +0 -1
  260. package/comment/index.d.ts +0 -7
  261. package/comment/index.es.js +0 -86
  262. package/comment/index.umd.js +0 -1
  263. package/comment/package.json +0 -7
  264. package/comment/style.css +0 -1
  265. package/date-picker/index.d.ts +0 -7
  266. package/date-picker/index.es.js +0 -1154
  267. package/date-picker/index.umd.js +0 -1
  268. package/date-picker/package.json +0 -7
  269. package/date-picker/style.css +0 -1
  270. package/dragdrop/index.d.ts +0 -7
  271. package/dragdrop/index.es.js +0 -157
  272. package/dragdrop/index.umd.js +0 -1
  273. package/dragdrop/package.json +0 -7
  274. package/gantt/index.d.ts +0 -7
  275. package/gantt/index.es.js +0 -523
  276. package/gantt/index.umd.js +0 -1
  277. package/gantt/style.css +0 -1
  278. package/input-icon/index.d.ts +0 -7
  279. package/input-icon/index.es.js +0 -332
  280. package/input-icon/index.umd.js +0 -1
  281. package/input-icon/package.json +0 -7
  282. package/input-icon/style.css +0 -1
  283. package/list/index.d.ts +0 -7
  284. package/list/index.es.js +0 -39
  285. package/list/index.umd.js +0 -1
  286. package/list/package.json +0 -7
  287. package/list/style.css +0 -1
  288. package/nav-sprite/index.d.ts +0 -7
  289. package/nav-sprite/index.es.js +0 -68
  290. package/nav-sprite/index.umd.js +0 -1
  291. package/nav-sprite/package.json +0 -7
  292. package/nuxt/components/Accordion.js +0 -3
  293. package/nuxt/components/Anchor.js +0 -3
  294. package/nuxt/components/BackTop.js +0 -3
  295. package/nuxt/components/Breadcrumb.js +0 -3
  296. package/nuxt/components/Carousel.js +0 -3
  297. package/nuxt/components/CarouselItem.js +0 -3
  298. package/nuxt/components/Cascader.js +0 -3
  299. package/nuxt/components/ColorPicker.js +0 -3
  300. package/nuxt/components/Comment.js +0 -3
  301. package/nuxt/components/DatePicker.js +0 -3
  302. package/nuxt/components/FormControl.js +0 -3
  303. package/nuxt/components/FormLabel.js +0 -3
  304. package/nuxt/components/Gantt.js +0 -3
  305. package/nuxt/components/InputIcon.js +0 -3
  306. package/nuxt/components/List.js +0 -3
  307. package/nuxt/components/ListItem.js +0 -3
  308. package/nuxt/components/NavSprite.js +0 -2
  309. package/nuxt/components/QuadrantDiagram.js +0 -3
  310. package/nuxt/components/ReadTip.js +0 -3
  311. package/nuxt/components/StepsGuide.js +0 -3
  312. package/nuxt/components/StickSlider.js +0 -3
  313. package/nuxt/components/Sticky.js +0 -2
  314. package/nuxt/components/TagInput.js +0 -3
  315. package/nuxt/components/Transfer.js +0 -3
  316. package/nuxt/components/TreeSelect.js +0 -3
  317. package/nuxt/components/overlayEmits.js +0 -3
  318. package/nuxt/components/overlayProps.js +0 -3
  319. package/quadrant-diagram/index.d.ts +0 -7
  320. package/quadrant-diagram/index.es.js +0 -5728
  321. package/quadrant-diagram/index.umd.js +0 -27
  322. package/quadrant-diagram/package.json +0 -7
  323. package/quadrant-diagram/style.css +0 -1
  324. package/read-tip/index.d.ts +0 -7
  325. package/read-tip/index.es.js +0 -261
  326. package/read-tip/index.umd.js +0 -1
  327. package/read-tip/package.json +0 -7
  328. package/read-tip/style.css +0 -1
  329. package/steps-guide/index.d.ts +0 -7
  330. package/steps-guide/index.es.js +0 -242
  331. package/steps-guide/index.umd.js +0 -1
  332. package/steps-guide/package.json +0 -7
  333. package/steps-guide/style.css +0 -1
  334. package/sticky/index.d.ts +0 -7
  335. package/sticky/index.es.js +0 -197
  336. package/sticky/index.umd.js +0 -1
  337. package/sticky/package.json +0 -7
  338. package/tag-input/index.d.ts +0 -7
  339. package/tag-input/index.es.js +0 -331
  340. package/tag-input/index.umd.js +0 -1
  341. package/tag-input/package.json +0 -7
  342. package/tag-input/style.css +0 -1
  343. package/transfer/index.d.ts +0 -7
  344. package/transfer/index.es.js +0 -7615
  345. package/transfer/index.umd.js +0 -27
  346. package/transfer/package.json +0 -7
  347. package/transfer/style.css +0 -1
  348. package/tree-select/index.d.ts +0 -7
  349. package/tree-select/index.es.js +0 -627
  350. package/tree-select/index.umd.js +0 -1
  351. package/tree-select/package.json +0 -7
  352. package/tree-select/style.css +0 -1
package/form/index.es.js CHANGED
@@ -17,28 +17,24 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import { defineComponent, provide, createVNode, toRefs, Teleport, Transition, renderSlot, isVNode, computed, onMounted, watch, onUnmounted, ref, unref, nextTick, mergeProps, Fragment, reactive, inject, onBeforeUnmount, withDirectives, resolveDirective } from "vue";
21
- import { shift, offset, autoPlacement, arrow, computePosition } from "@floating-ui/dom";
22
- function mitt(n) {
23
- return { all: n = n || /* @__PURE__ */ new Map(), on: function(t, e) {
24
- var i = n.get(t);
25
- i ? i.push(e) : n.set(t, [e]);
26
- }, off: function(t, e) {
27
- var i = n.get(t);
28
- i && (e ? i.splice(i.indexOf(e) >>> 0, 1) : n.set(t, []));
29
- }, emit: function(t, e) {
30
- var i = n.get(t);
31
- i && i.slice().map(function(n2) {
32
- n2(e);
33
- }), (i = n.get("*")) && i.slice().map(function(n2) {
34
- n2(t, e);
35
- });
36
- } };
37
- }
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ import { defineComponent, watch, provide, reactive, toRefs, createVNode, onUnmounted, Transition, mergeProps, ref, unref, nextTick, Comment, Text, h, Fragment, inject, withDirectives, cloneVNode, computed, onMounted, Teleport, createTextVNode, onBeforeUnmount } from "vue";
33
+ import { offset, autoPlacement, arrow, shift, computePosition } from "@floating-ui/dom";
38
34
  const formProps = {
39
- formData: {
35
+ data: {
40
36
  type: Object,
41
- default: {}
37
+ default: () => ({})
42
38
  },
43
39
  layout: {
44
40
  type: String,
@@ -46,531 +42,73 @@ const formProps = {
46
42
  },
47
43
  labelSize: {
48
44
  type: String,
49
- default: ""
45
+ default: "md"
50
46
  },
51
47
  labelAlign: {
52
48
  type: String,
53
49
  default: "start"
54
50
  },
55
51
  rules: {
56
- type: Object,
57
- default: {}
52
+ type: Object
58
53
  },
59
- columnsClass: {
54
+ messageType: {
60
55
  type: String,
61
- default: ""
56
+ default: "popover"
62
57
  },
63
- name: {
64
- type: String,
65
- default: ""
58
+ popPosition: {
59
+ type: Array,
60
+ default: ["right", "bottom"]
66
61
  },
67
- messageShowType: {
68
- type: String,
69
- default: "popover"
70
- }
71
- };
72
- const formItemProps = {
73
- dHasFeedback: {
62
+ validateOnRuleChange: {
74
63
  type: Boolean,
75
64
  default: false
76
65
  },
77
- prop: {
78
- type: String,
79
- default: ""
80
- }
81
- };
82
- const formLabelProps = {
83
- required: {
66
+ showFeedback: {
84
67
  type: Boolean,
85
68
  default: false
86
69
  },
87
- hasHelp: {
70
+ disabled: {
88
71
  type: Boolean,
89
72
  default: false
90
73
  },
91
- helpTips: {
92
- type: String,
93
- default: ""
94
- }
95
- };
96
- const formControlProps = {
97
- feedbackStatus: {
98
- type: String,
99
- default: ""
100
- },
101
- extraInfo: {
102
- type: String,
103
- default: ""
104
- }
105
- };
106
- const dFormEvents = {
107
- addField: "d.form.addField",
108
- removeField: "d.form.removeField"
109
- };
110
- const formInjectionKey = Symbol("dForm");
111
- const formItemInjectionKey = Symbol("dFormItem");
112
- const dFormItemEvents = {
113
- blur: "d.form.blur",
114
- change: "d.form.change",
115
- input: "d.form.input"
116
- };
117
- var eventBus = mitt();
118
- const EventBus = eventBus;
119
- function isObject(obj) {
120
- return Object.prototype.toString.call(obj).slice(8, -1) === "Object";
121
- }
122
- function hasKey(obj, key) {
123
- if (!isObject(obj)) {
124
- return false;
125
- }
126
- return Object.prototype.hasOwnProperty.call(obj, key);
127
- }
128
- function getElOffset(curEl) {
129
- let totalLeft = 0;
130
- let totalTop = 0;
131
- let par = curEl.offsetParent;
132
- totalLeft += curEl.offsetLeft;
133
- totalTop += curEl.offsetTop;
134
- while (par) {
135
- if (navigator.userAgent.indexOf("MSIE 8.0") === -1) {
136
- totalTop += par.clientTop;
137
- totalLeft += par.clientLeft;
138
- }
139
- totalTop += par.offsetTop;
140
- totalLeft += par.offsetLeft;
141
- par = par.offsetParent;
142
- }
143
- return { left: totalLeft, top: totalTop };
144
- }
145
- var form = "";
146
- var Form = defineComponent({
147
- name: "DForm",
148
- props: formProps,
149
- emits: ["submit"],
150
- setup(props, ctx2) {
151
- const formMitt = mitt();
152
- const fields = [];
153
- const resetFormFields = () => {
154
- fields.forEach((field) => {
155
- field.resetField();
156
- });
157
- };
158
- formMitt.on(dFormEvents.addField, (field) => {
159
- if (field) {
160
- fields.push(field);
161
- }
162
- });
163
- formMitt.on(dFormEvents.removeField, (field) => {
164
- if (field.prop) {
165
- fields.splice(fields.indexOf(field), 1);
166
- }
167
- });
168
- provide(formInjectionKey, {
169
- formData: props.formData,
170
- formMitt,
171
- labelData: {
172
- layout: props.layout,
173
- labelSize: props.labelSize,
174
- labelAlign: props.labelAlign
175
- },
176
- rules: props.rules,
177
- columnsClass: props.columnsClass,
178
- messageShowType: "popover"
179
- });
180
- const onSubmit = (e) => {
181
- e.preventDefault();
182
- ctx2.emit("submit", e);
183
- EventBus.emit(`formSubmit:${props.name}`);
184
- };
185
- return {
186
- fields,
187
- formMitt,
188
- onSubmit,
189
- resetFormFields
190
- };
191
- },
192
- render() {
193
- var _a, _b;
194
- const {
195
- onSubmit
196
- } = this;
197
- return createVNode("form", {
198
- "onSubmit": onSubmit,
199
- "class": "devui-form"
200
- }, [(_b = (_a = this.$slots).default) == null ? void 0 : _b.call(_a)]);
201
- }
202
- });
203
- const iconProps = {
204
- name: {
205
- type: String,
206
- default: "",
207
- required: true
208
- },
209
74
  size: {
210
- type: String,
211
- default: "inherit"
212
- },
213
- color: {
214
- type: String,
215
- default: "inherit"
216
- },
217
- classPrefix: {
218
- type: String,
219
- default: "icon"
75
+ type: String
220
76
  }
221
77
  };
222
- var Icon = defineComponent({
223
- name: "DIcon",
224
- props: iconProps,
225
- setup(props) {
226
- const {
227
- name,
228
- size,
229
- color,
230
- classPrefix
231
- } = toRefs(props);
232
- return () => {
233
- return /^((https?):)?\/\//.test(name.value) ? createVNode("img", {
234
- "src": name.value,
235
- "alt": name.value.split("/")[name.value.split("/").length - 1],
236
- "style": {
237
- width: size.value,
238
- verticalAlign: "text-bottom"
239
- }
240
- }, null) : createVNode("i", {
241
- "class": `${classPrefix.value} ${classPrefix.value}-${name.value}`,
242
- "style": {
243
- fontSize: size.value,
244
- color: color.value
245
- }
246
- }, null);
247
- };
248
- }
249
- });
250
- var baseOverlay = "";
251
- function _isSlot(s) {
252
- return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
253
- }
254
- const CommonOverlay = defineComponent({
255
- setup(props, ctx2) {
256
- return () => {
257
- let _slot;
258
- return createVNode(Teleport, {
259
- "to": "#d-overlay-anchor"
260
- }, {
261
- default: () => [createVNode(Transition, {
262
- "name": "devui-overlay-fade"
263
- }, _isSlot(_slot = renderSlot(ctx2.slots, "default")) ? _slot : {
264
- default: () => [_slot]
265
- })]
266
- });
267
- };
268
- }
269
- });
270
- const overlayProps = {
271
- visible: {
272
- type: Boolean
273
- },
274
- backgroundBlock: {
275
- type: Boolean,
276
- default: false
277
- },
278
- backgroundClass: {
279
- type: String,
280
- default: ""
281
- },
282
- backgroundStyle: {
283
- type: [String, Object]
284
- },
285
- onBackdropClick: {
286
- type: Function
287
- },
288
- backdropClose: {
289
- type: Boolean,
290
- default: true
291
- },
292
- hasBackdrop: {
293
- type: Boolean,
294
- default: true
78
+ const FORM_TOKEN = Symbol("dForm");
79
+ function createBem(namespace, element, modifier) {
80
+ let cls = namespace;
81
+ if (element) {
82
+ cls += `__${element}`;
295
83
  }
296
- };
297
- const fixedOverlayProps = __spreadProps(__spreadValues({}, overlayProps), {
298
- overlayStyle: {
299
- type: [String, Object],
300
- default: void 0
84
+ if (modifier) {
85
+ cls += `--${modifier}`;
301
86
  }
302
- });
303
- const overlayEmits = ["update:visible", "backdropClick"];
304
- function useOverlayLogic(props, ctx2) {
305
- const backgroundClass = computed(() => {
306
- return [
307
- "devui-overlay-background",
308
- props.backgroundClass,
309
- !props.hasBackdrop ? "devui-overlay-background__disabled" : "devui-overlay-background__color"
310
- ];
311
- });
312
- const overlayClass = computed(() => {
313
- return "devui-overlay";
314
- });
315
- const handleBackdropClick = (event) => {
316
- var _a;
317
- event.preventDefault();
318
- (_a = props.onBackdropClick) == null ? void 0 : _a.call(props);
319
- if (props.backdropClose) {
320
- ctx2.emit("update:visible", false);
321
- }
322
- };
323
- const handleOverlayBubbleCancel = (event) => event.cancelBubble = true;
324
- onMounted(() => {
325
- const body = document.body;
326
- const originOverflow = body.style.overflow;
327
- const originPosition = body.style.position;
328
- watch([() => props.visible, () => props.backgroundBlock], ([visible, backgroundBlock]) => {
329
- if (backgroundBlock) {
330
- const top = body.getBoundingClientRect().y;
331
- if (visible) {
332
- body.style.overflowY = "scroll";
333
- body.style.position = visible ? "fixed" : "";
334
- body.style.top = `${top}px`;
335
- } else {
336
- body.style.overflowY = originOverflow;
337
- body.style.position = originPosition;
338
- body.style.top = "";
339
- window.scrollTo(0, -top);
340
- }
341
- }
342
- });
343
- onUnmounted(() => {
344
- document.body.style.overflow = originOverflow;
345
- });
346
- });
87
+ return cls;
88
+ }
89
+ function useNamespace(block, needDot = false) {
90
+ const namespace = needDot ? `.devui-${block}` : `devui-${block}`;
91
+ const b = () => createBem(namespace);
92
+ const e = (element) => element ? createBem(namespace, element) : "";
93
+ const m = (modifier) => modifier ? createBem(namespace, "", modifier) : "";
94
+ const em = (element, modifier) => element && modifier ? createBem(namespace, element, modifier) : "";
347
95
  return {
348
- backgroundClass,
349
- overlayClass,
350
- handleBackdropClick,
351
- handleOverlayBubbleCancel
96
+ b,
97
+ e,
98
+ m,
99
+ em
352
100
  };
353
101
  }
354
- var fixedOverlay = "";
355
- defineComponent({
356
- name: "DFixedOverlay",
357
- props: fixedOverlayProps,
358
- emits: overlayEmits,
359
- setup(props, ctx2) {
360
- const {
361
- backgroundClass,
362
- overlayClass,
363
- handleBackdropClick,
364
- handleOverlayBubbleCancel
365
- } = useOverlayLogic(props, ctx2);
366
- return () => createVNode(CommonOverlay, null, {
367
- default: () => [props.visible && createVNode("div", {
368
- "class": backgroundClass.value,
369
- "style": props.backgroundStyle,
370
- "onClick": handleBackdropClick
371
- }, [createVNode("div", {
372
- "class": overlayClass.value,
373
- "style": props.overlayStyle,
374
- "onClick": handleOverlayBubbleCancel
375
- }, [renderSlot(ctx2.slots, "default")])])]
376
- });
377
- }
378
- });
379
- const flexibleOverlayProps = {
380
- modelValue: {
381
- type: Boolean,
382
- default: false
383
- },
384
- origin: {
385
- type: Object,
386
- require: true
387
- },
388
- position: {
389
- type: Array,
390
- default: ["bottom"]
391
- },
392
- offset: {
393
- type: [Number, Object],
394
- default: 8
395
- },
396
- align: {
397
- type: String,
398
- default: null
399
- },
400
- showArrow: {
401
- type: Boolean,
402
- default: false
403
- },
404
- isArrowCenter: {
405
- type: Boolean,
406
- default: true
407
- }
408
- };
409
- function getScrollParent(element) {
410
- const overflowRegex = /(auto|scroll|hidden)/;
411
- for (let parent = element; parent = parent.parentElement; parent.parentElement !== document.body) {
412
- const style2 = window.getComputedStyle(parent);
413
- if (overflowRegex.test(style2.overflow + style2.overflowX + style2.overflowY)) {
414
- return parent;
415
- }
416
- }
417
- return window;
418
- }
419
- function adjustArrowPosition(isArrowCenter, point, placement, originRect) {
420
- let { x, y } = point;
421
- if (!isArrowCenter) {
422
- const { width, height } = originRect;
423
- if (x && placement.includes("start")) {
424
- x = 12;
425
- }
426
- if (x && placement.includes("end")) {
427
- x = Math.round(width - 24);
428
- }
429
- if (y && placement.includes("start")) {
430
- y = 10;
431
- }
432
- if (y && placement.includes("end")) {
433
- y = height - 14;
434
- }
435
- }
436
- return { x, y };
437
- }
438
- function useOverlay(props, emit) {
439
- const overlayRef = ref();
440
- const arrowRef = ref();
441
- const updateArrowPosition = (arrowEl, placement, point, overlayEl) => {
442
- const { x, y } = adjustArrowPosition(props.isArrowCenter, point, placement, overlayEl.getBoundingClientRect());
443
- const staticSide = {
444
- top: "bottom",
445
- right: "left",
446
- bottom: "top",
447
- left: "right"
448
- }[placement.split("-")[0]];
449
- Object.assign(arrowEl.style, {
450
- left: x ? `${x}px` : "",
451
- top: y ? `${y}px` : "",
452
- right: "",
453
- bottom: "",
454
- [staticSide]: "-4px"
455
- });
102
+ function useFieldCollection() {
103
+ const itemContexts = [];
104
+ const addItemContext = (field) => {
105
+ itemContexts.push(field);
456
106
  };
457
- const updatePosition = async () => {
458
- const hostEl = props.origin;
459
- const overlayEl = unref(overlayRef.value);
460
- const arrowEl = unref(arrowRef.value);
461
- const middleware = [
462
- shift(),
463
- offset(props.offset),
464
- autoPlacement({
465
- alignment: props.align,
466
- allowedPlacements: props.position
467
- })
468
- ];
469
- props.showArrow && middleware.push(arrow({ element: arrowEl }));
470
- const { x, y, placement, middlewareData } = await computePosition(hostEl, overlayEl, {
471
- strategy: "fixed",
472
- middleware
473
- });
474
- emit("positionChange", placement);
475
- Object.assign(overlayEl.style, { top: `${y}px`, left: `${x}px` });
476
- props.showArrow && updateArrowPosition(arrowEl, placement, middlewareData.arrow, overlayEl);
107
+ const removeItemContext = (field) => {
108
+ itemContexts.splice(itemContexts.indexOf(field), 1);
477
109
  };
478
- watch(() => props.modelValue, () => {
479
- const originParent = getScrollParent(props.origin);
480
- if (props.modelValue && props.origin) {
481
- nextTick(updatePosition);
482
- originParent.addEventListener("scroll", updatePosition);
483
- originParent !== window && window.addEventListener("scroll", updatePosition);
484
- window.addEventListener("resize", updatePosition);
485
- } else {
486
- originParent.removeEventListener("scroll", updatePosition);
487
- originParent !== window && window.removeEventListener("scroll", updatePosition);
488
- window.removeEventListener("resize", updatePosition);
489
- }
490
- });
491
- onUnmounted(() => {
492
- const originParent = getScrollParent(props.origin);
493
- originParent.removeEventListener("scroll", updatePosition);
494
- originParent !== window && window.removeEventListener("scroll", updatePosition);
495
- window.removeEventListener("resize", updatePosition);
496
- });
497
- return { arrowRef, overlayRef, updatePosition };
110
+ return { itemContexts, addItemContext, removeItemContext };
498
111
  }
499
- var flexibleOverlay = "";
500
- const FlexibleOverlay = defineComponent({
501
- name: "DFlexibleOverlay",
502
- inheritAttrs: false,
503
- props: flexibleOverlayProps,
504
- emits: ["update:modelValue", "positionChange"],
505
- setup(props, {
506
- slots,
507
- attrs,
508
- emit,
509
- expose
510
- }) {
511
- const {
512
- arrowRef,
513
- overlayRef,
514
- updatePosition
515
- } = useOverlay(props, emit);
516
- expose({
517
- updatePosition
518
- });
519
- return () => {
520
- var _a;
521
- return props.modelValue && createVNode("div", mergeProps({
522
- "ref": overlayRef,
523
- "class": "devui-flexible-overlay"
524
- }, attrs), [(_a = slots.default) == null ? void 0 : _a.call(slots), props.showArrow && createVNode("div", {
525
- "ref": arrowRef,
526
- "class": "devui-flexible-overlay-arrow"
527
- }, null)]);
528
- };
529
- }
530
- });
531
- const inBrowser = typeof window !== "undefined";
532
- const popoverProps = {
533
- isOpen: {
534
- type: Boolean,
535
- default: false
536
- },
537
- position: {
538
- type: Array,
539
- default: ["bottom"]
540
- },
541
- align: {
542
- type: String,
543
- default: null
544
- },
545
- offset: {
546
- type: [Number, Object],
547
- default: 8
548
- },
549
- content: {
550
- type: String,
551
- default: ""
552
- },
553
- trigger: {
554
- type: String,
555
- default: "click"
556
- },
557
- popType: {
558
- type: String,
559
- default: "default"
560
- },
561
- showAnimation: {
562
- type: Boolean,
563
- default: true
564
- },
565
- mouseEnterDelay: {
566
- type: Number,
567
- default: 150
568
- },
569
- mouseLeaveDelay: {
570
- type: Number,
571
- default: 100
572
- }
573
- };
574
112
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
575
113
  var lodash = { exports: {} };
576
114
  /**
@@ -5972,17 +5510,511 @@ var lodash = { exports: {} };
5972
5510
  if (symIterator) {
5973
5511
  lodash2.prototype[symIterator] = wrapperToIterator;
5974
5512
  }
5975
- return lodash2;
5976
- };
5977
- var _ = runInContext();
5978
- if (freeModule) {
5979
- (freeModule.exports = _)._ = _;
5980
- freeExports._ = _;
5513
+ return lodash2;
5514
+ };
5515
+ var _ = runInContext();
5516
+ if (freeModule) {
5517
+ (freeModule.exports = _)._ = _;
5518
+ freeExports._ = _;
5519
+ } else {
5520
+ root._ = _;
5521
+ }
5522
+ }).call(commonjsGlobal);
5523
+ })(lodash, lodash.exports);
5524
+ function useFormValidation(itemContexts) {
5525
+ const getValidateFields = (fields) => {
5526
+ if (!itemContexts.length) {
5527
+ return [];
5528
+ }
5529
+ const normalizedFields = lodash.exports.castArray(fields);
5530
+ const filteredFields = normalizedFields.length ? itemContexts.filter((context) => context.field && normalizedFields.includes(context.field)) : itemContexts;
5531
+ if (!filteredFields.length) {
5532
+ return [];
5533
+ }
5534
+ return filteredFields;
5535
+ };
5536
+ const execValidateFields = async (fields = []) => {
5537
+ const validateFields2 = getValidateFields(fields);
5538
+ if (!validateFields2.length) {
5539
+ return true;
5540
+ }
5541
+ let errors = {};
5542
+ for (const field of validateFields2) {
5543
+ try {
5544
+ await field.validate("");
5545
+ } catch (err) {
5546
+ errors = __spreadValues(__spreadValues({}, errors), err);
5547
+ }
5548
+ }
5549
+ if (!Object.keys(errors).length) {
5550
+ return true;
5551
+ }
5552
+ return Promise.reject(errors);
5553
+ };
5554
+ const validateFields = async (fields = [], callback) => {
5555
+ try {
5556
+ const result = await execValidateFields(fields);
5557
+ if (result) {
5558
+ callback == null ? void 0 : callback(result);
5559
+ }
5560
+ return result;
5561
+ } catch (err) {
5562
+ const invalidFields = err;
5563
+ callback == null ? void 0 : callback(false, invalidFields);
5564
+ return !callback && Promise.reject(invalidFields);
5565
+ }
5566
+ };
5567
+ const validate = async (callback) => validateFields(void 0, callback);
5568
+ const clearValidate = (fields = []) => {
5569
+ getValidateFields(fields).forEach((field) => field.clearValidate());
5570
+ };
5571
+ const resetFields = (fields = []) => {
5572
+ getValidateFields(fields).forEach((field) => field.resetField());
5573
+ };
5574
+ return { validate, validateFields, resetFields, clearValidate };
5575
+ }
5576
+ var Form = defineComponent({
5577
+ name: "DForm",
5578
+ props: formProps,
5579
+ emits: ["validate"],
5580
+ setup(props, ctx) {
5581
+ const ns2 = useNamespace("form");
5582
+ const {
5583
+ itemContexts,
5584
+ addItemContext,
5585
+ removeItemContext
5586
+ } = useFieldCollection();
5587
+ const {
5588
+ validate,
5589
+ validateFields,
5590
+ resetFields,
5591
+ clearValidate
5592
+ } = useFormValidation(itemContexts);
5593
+ const onSubmit = (e) => {
5594
+ e.preventDefault();
5595
+ };
5596
+ watch(() => props.rules, () => {
5597
+ if (props.validateOnRuleChange) {
5598
+ validate();
5599
+ }
5600
+ }, {
5601
+ deep: true
5602
+ });
5603
+ provide(FORM_TOKEN, reactive(__spreadProps(__spreadValues({}, toRefs(props)), {
5604
+ emit: ctx.emit,
5605
+ addItemContext,
5606
+ removeItemContext
5607
+ })));
5608
+ ctx.expose({
5609
+ validate,
5610
+ validateFields,
5611
+ resetFields,
5612
+ clearValidate
5613
+ });
5614
+ return () => {
5615
+ var _a, _b;
5616
+ return createVNode("form", {
5617
+ "onSubmit": onSubmit,
5618
+ "class": ns2.b()
5619
+ }, [(_b = (_a = ctx.slots).default) == null ? void 0 : _b.call(_a)]);
5620
+ };
5621
+ }
5622
+ });
5623
+ const formItemProps = {
5624
+ label: {
5625
+ type: String
5626
+ },
5627
+ field: {
5628
+ type: String,
5629
+ default: ""
5630
+ },
5631
+ required: {
5632
+ type: Boolean,
5633
+ default: false
5634
+ },
5635
+ messageType: {
5636
+ type: String
5637
+ },
5638
+ popPosition: {
5639
+ type: Array
5640
+ },
5641
+ rules: {
5642
+ type: [Object, Array]
5643
+ },
5644
+ showFeedback: {
5645
+ type: Boolean,
5646
+ default: void 0
5647
+ },
5648
+ helpTips: {
5649
+ type: String,
5650
+ default: ""
5651
+ },
5652
+ feedbackStatus: {
5653
+ type: String
5654
+ },
5655
+ extraInfo: {
5656
+ type: String,
5657
+ default: ""
5658
+ }
5659
+ };
5660
+ const FORM_ITEM_TOKEN = Symbol("dFormItem");
5661
+ const LABEL_DATA = Symbol("labelData");
5662
+ const formLabelProps = {
5663
+ helpTips: {
5664
+ type: String,
5665
+ default: ""
5666
+ }
5667
+ };
5668
+ const fixedOverlayProps = {
5669
+ modelValue: {
5670
+ type: Boolean,
5671
+ default: false
5672
+ },
5673
+ lockScroll: {
5674
+ type: Boolean,
5675
+ default: true
5676
+ },
5677
+ closeOnClickOverlay: {
5678
+ type: Boolean,
5679
+ default: true
5680
+ }
5681
+ };
5682
+ function lockScroll() {
5683
+ if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
5684
+ const scrollTop = document.documentElement.scrollTop;
5685
+ const style = document.documentElement.getAttribute("style");
5686
+ document.documentElement.style.position = "fixed";
5687
+ document.documentElement.style.top = `-${scrollTop}px`;
5688
+ document.documentElement.style.width = document.documentElement.style.width || "100%";
5689
+ document.documentElement.style.overflowY = "scroll";
5690
+ return () => {
5691
+ if (style) {
5692
+ document.documentElement.setAttribute("style", style);
5693
+ } else {
5694
+ document.documentElement.removeAttribute("style");
5695
+ }
5696
+ document.documentElement.scrollTop = scrollTop;
5697
+ };
5698
+ }
5699
+ return;
5700
+ }
5701
+ function useFixedOverlay(props, ctx) {
5702
+ let lockScrollCb;
5703
+ const onClick = (event) => {
5704
+ event.preventDefault();
5705
+ ctx.emit("click", event);
5706
+ if (props.closeOnClickOverlay) {
5707
+ ctx.emit("update:modelValue", false);
5708
+ }
5709
+ };
5710
+ const removeBodyAdditions = () => {
5711
+ lockScrollCb == null ? void 0 : lockScrollCb();
5712
+ };
5713
+ watch(() => props.modelValue, (val) => {
5714
+ if (val) {
5715
+ props.lockScroll && (lockScrollCb = lockScroll());
5716
+ } else {
5717
+ removeBodyAdditions();
5718
+ }
5719
+ });
5720
+ onUnmounted(removeBodyAdditions);
5721
+ return { onClick };
5722
+ }
5723
+ var fixedOverlay = "";
5724
+ defineComponent({
5725
+ name: "DFixedOverlay",
5726
+ inheritAttrs: false,
5727
+ props: fixedOverlayProps,
5728
+ emits: ["update:modelValue", "click"],
5729
+ setup(props, ctx) {
5730
+ const {
5731
+ modelValue
5732
+ } = toRefs(props);
5733
+ const ns2 = useNamespace("fixed-overlay");
5734
+ const {
5735
+ onClick
5736
+ } = useFixedOverlay(props, ctx);
5737
+ return () => createVNode(Transition, {
5738
+ "name": ns2.m("fade")
5739
+ }, {
5740
+ default: () => {
5741
+ var _a, _b;
5742
+ return [modelValue.value && createVNode("div", mergeProps({
5743
+ "class": ns2.b()
5744
+ }, ctx.attrs, {
5745
+ "onClick": onClick
5746
+ }), [(_b = (_a = ctx.slots).default) == null ? void 0 : _b.call(_a)])];
5747
+ }
5748
+ });
5749
+ }
5750
+ });
5751
+ const flexibleOverlayProps = {
5752
+ modelValue: {
5753
+ type: Boolean,
5754
+ default: false
5755
+ },
5756
+ origin: {
5757
+ type: Object,
5758
+ require: true
5759
+ },
5760
+ position: {
5761
+ type: Array,
5762
+ default: ["bottom"]
5763
+ },
5764
+ offset: {
5765
+ type: [Number, Object],
5766
+ default: 8
5767
+ },
5768
+ shiftOffset: {
5769
+ type: Number
5770
+ },
5771
+ align: {
5772
+ type: String,
5773
+ default: null
5774
+ },
5775
+ showArrow: {
5776
+ type: Boolean,
5777
+ default: false
5778
+ },
5779
+ isArrowCenter: {
5780
+ type: Boolean,
5781
+ default: true
5782
+ }
5783
+ };
5784
+ function getScrollParent(element) {
5785
+ const overflowRegex = /(auto|scroll|hidden)/;
5786
+ for (let parent = element; parent = parent.parentElement; parent.parentElement !== document.body) {
5787
+ const style = window.getComputedStyle(parent);
5788
+ if (overflowRegex.test(style.overflow + style.overflowX + style.overflowY)) {
5789
+ return parent;
5790
+ }
5791
+ }
5792
+ return window;
5793
+ }
5794
+ function adjustArrowPosition(isArrowCenter, point, placement, originRect) {
5795
+ let { x, y } = point;
5796
+ if (!isArrowCenter) {
5797
+ const { width, height } = originRect;
5798
+ if (x && placement.includes("start")) {
5799
+ x = 12;
5800
+ }
5801
+ if (x && placement.includes("end")) {
5802
+ x = Math.round(width - 24);
5803
+ }
5804
+ if (y && placement.includes("start")) {
5805
+ y = 10;
5806
+ }
5807
+ if (y && placement.includes("end")) {
5808
+ y = height - 14;
5809
+ }
5810
+ }
5811
+ return { x, y };
5812
+ }
5813
+ function useOverlay(props, emit) {
5814
+ const overlayRef = ref();
5815
+ const arrowRef = ref();
5816
+ let originParent = null;
5817
+ const updateArrowPosition = (arrowEl, placement, point, overlayEl) => {
5818
+ const { x, y } = adjustArrowPosition(props.isArrowCenter, point, placement, overlayEl.getBoundingClientRect());
5819
+ const staticSide = {
5820
+ top: "bottom",
5821
+ right: "left",
5822
+ bottom: "top",
5823
+ left: "right"
5824
+ }[placement.split("-")[0]];
5825
+ Object.assign(arrowEl.style, {
5826
+ left: x ? `${x}px` : "",
5827
+ top: y ? `${y}px` : "",
5828
+ right: "",
5829
+ bottom: "",
5830
+ [staticSide]: "-4px"
5831
+ });
5832
+ };
5833
+ const updatePosition = async () => {
5834
+ const hostEl = props.origin;
5835
+ const overlayEl = unref(overlayRef.value);
5836
+ const arrowEl = unref(arrowRef.value);
5837
+ const middleware = [
5838
+ offset(props.offset),
5839
+ autoPlacement({
5840
+ alignment: props.align,
5841
+ allowedPlacements: props.position
5842
+ })
5843
+ ];
5844
+ props.showArrow && middleware.push(arrow({ element: arrowEl }));
5845
+ props.shiftOffset !== void 0 && middleware.push(shift());
5846
+ const { x, y, placement, middlewareData } = await computePosition(hostEl, overlayEl, {
5847
+ strategy: "fixed",
5848
+ middleware
5849
+ });
5850
+ let applyX = x;
5851
+ let applyY = y;
5852
+ if (props.shiftOffset !== void 0) {
5853
+ const { x: shiftX, y: shiftY } = middlewareData.shift;
5854
+ shiftX < 0 && (applyX -= props.shiftOffset);
5855
+ shiftX > 0 && (applyX += props.shiftOffset);
5856
+ shiftY < 0 && (applyY -= props.shiftOffset);
5857
+ shiftY > 0 && (applyY += props.shiftOffset);
5858
+ }
5859
+ emit("positionChange", placement);
5860
+ Object.assign(overlayEl.style, { top: `${applyY}px`, left: `${applyX}px` });
5861
+ props.showArrow && updateArrowPosition(arrowEl, placement, middlewareData.arrow, overlayEl);
5862
+ };
5863
+ watch(() => props.modelValue, () => {
5864
+ if (props.modelValue && props.origin) {
5865
+ originParent = getScrollParent(props.origin);
5866
+ nextTick(updatePosition);
5867
+ originParent == null ? void 0 : originParent.addEventListener("scroll", updatePosition);
5868
+ originParent !== window && window.addEventListener("scroll", updatePosition);
5869
+ window.addEventListener("resize", updatePosition);
5981
5870
  } else {
5982
- root._ = _;
5871
+ originParent == null ? void 0 : originParent.removeEventListener("scroll", updatePosition);
5872
+ originParent !== window && window.removeEventListener("scroll", updatePosition);
5873
+ window.removeEventListener("resize", updatePosition);
5983
5874
  }
5984
- }).call(commonjsGlobal);
5985
- })(lodash, lodash.exports);
5875
+ });
5876
+ onUnmounted(() => {
5877
+ originParent == null ? void 0 : originParent.removeEventListener("scroll", updatePosition);
5878
+ originParent !== window && window.removeEventListener("scroll", updatePosition);
5879
+ window.removeEventListener("resize", updatePosition);
5880
+ });
5881
+ return { arrowRef, overlayRef, updatePosition };
5882
+ }
5883
+ var flexibleOverlay = "";
5884
+ const FlexibleOverlay = defineComponent({
5885
+ name: "DFlexibleOverlay",
5886
+ inheritAttrs: false,
5887
+ props: flexibleOverlayProps,
5888
+ emits: ["update:modelValue", "positionChange"],
5889
+ setup(props, {
5890
+ slots,
5891
+ attrs,
5892
+ emit,
5893
+ expose
5894
+ }) {
5895
+ const ns2 = useNamespace("flexible-overlay");
5896
+ const {
5897
+ arrowRef,
5898
+ overlayRef,
5899
+ updatePosition
5900
+ } = useOverlay(props, emit);
5901
+ expose({
5902
+ updatePosition
5903
+ });
5904
+ return () => {
5905
+ var _a;
5906
+ return props.modelValue && createVNode("div", mergeProps({
5907
+ "ref": overlayRef,
5908
+ "class": ns2.b()
5909
+ }, attrs), [(_a = slots.default) == null ? void 0 : _a.call(slots), props.showArrow && createVNode("div", {
5910
+ "ref": arrowRef,
5911
+ "class": ns2.e("arrow")
5912
+ }, null)]);
5913
+ };
5914
+ }
5915
+ });
5916
+ const POPPER_TRIGGER_TOKEN = Symbol("popper-trigger");
5917
+ const isObject = (val) => val !== null && typeof val === "object";
5918
+ const ns$1 = useNamespace("popper-trigger");
5919
+ function wrapContent(content) {
5920
+ return h("span", { class: ns$1.b() }, content);
5921
+ }
5922
+ function getFirstValidChild(nodes) {
5923
+ for (const child of nodes) {
5924
+ if (isObject(child)) {
5925
+ if (child.type === Comment) {
5926
+ continue;
5927
+ }
5928
+ if (child.type === "svg" || child.type === Text) {
5929
+ return wrapContent(child);
5930
+ }
5931
+ if (child.type === Fragment) {
5932
+ return getFirstValidChild(child.children);
5933
+ }
5934
+ return child;
5935
+ }
5936
+ return wrapContent(child);
5937
+ }
5938
+ return null;
5939
+ }
5940
+ var PopperTrigger = defineComponent({
5941
+ name: "DPopperTrigger",
5942
+ setup(_, ctx) {
5943
+ const {
5944
+ slots,
5945
+ attrs
5946
+ } = ctx;
5947
+ return () => {
5948
+ var _a;
5949
+ const defaultSlot = (_a = slots.default) == null ? void 0 : _a.call(slots, attrs);
5950
+ const triggerRef = inject(POPPER_TRIGGER_TOKEN);
5951
+ if (!defaultSlot) {
5952
+ return null;
5953
+ }
5954
+ const firstValidChild = getFirstValidChild(defaultSlot);
5955
+ if (!firstValidChild) {
5956
+ return null;
5957
+ }
5958
+ return withDirectives(cloneVNode(firstValidChild, attrs), [[{
5959
+ mounted(el) {
5960
+ triggerRef.value = el;
5961
+ },
5962
+ updated(el) {
5963
+ triggerRef.value = el;
5964
+ },
5965
+ unmounted() {
5966
+ triggerRef.value = null;
5967
+ }
5968
+ }]]);
5969
+ };
5970
+ }
5971
+ });
5972
+ const popoverProps = {
5973
+ isOpen: {
5974
+ type: Boolean,
5975
+ default: false
5976
+ },
5977
+ position: {
5978
+ type: Array,
5979
+ default: ["bottom"]
5980
+ },
5981
+ align: {
5982
+ type: String,
5983
+ default: null
5984
+ },
5985
+ offset: {
5986
+ type: [Number, Object],
5987
+ default: 8
5988
+ },
5989
+ content: {
5990
+ type: String,
5991
+ default: ""
5992
+ },
5993
+ trigger: {
5994
+ type: String,
5995
+ default: "click"
5996
+ },
5997
+ popType: {
5998
+ type: String,
5999
+ default: "default"
6000
+ },
6001
+ showAnimation: {
6002
+ type: Boolean,
6003
+ default: true
6004
+ },
6005
+ mouseEnterDelay: {
6006
+ type: Number,
6007
+ default: 150
6008
+ },
6009
+ mouseLeaveDelay: {
6010
+ type: Number,
6011
+ default: 100
6012
+ },
6013
+ disabled: {
6014
+ type: Boolean,
6015
+ default: false
6016
+ }
6017
+ };
5986
6018
  const TransformOriginMap = {
5987
6019
  top: "50% calc(100% + 8px)",
5988
6020
  bottom: "50% -8px",
@@ -5996,8 +6028,8 @@ function usePopover(props, visible, placement, origin, popoverRef) {
5996
6028
  transformOrigin: TransformOriginMap[placement.value]
5997
6029
  }));
5998
6030
  const onDocumentClick = (e) => {
5999
- var _a;
6000
- if (!origin.value.contains(e.target) && !((_a = popoverRef.value.$el) == null ? void 0 : _a.contains(e.target))) {
6031
+ var _a, _b;
6032
+ if (!((_a = origin.value) == null ? void 0 : _a.contains(e.target)) && !((_b = popoverRef.value.$el) == null ? void 0 : _b.contains(e.target))) {
6001
6033
  visible.value = false;
6002
6034
  }
6003
6035
  };
@@ -6017,11 +6049,16 @@ function usePopover(props, visible, placement, origin, popoverRef) {
6017
6049
  return { overlayStyles };
6018
6050
  }
6019
6051
  function usePopoverEvent(props, visible, origin) {
6020
- const { trigger, position, mouseEnterDelay, mouseLeaveDelay } = toRefs(props);
6052
+ const { trigger, position, mouseEnterDelay, mouseLeaveDelay, disabled } = toRefs(props);
6021
6053
  const isClick = computed(() => trigger.value === "click");
6022
6054
  const placement = ref(position.value[0].split("-")[0]);
6023
6055
  const isEnter = ref(false);
6024
- const onClick = () => isClick.value && (visible.value = !visible.value);
6056
+ const onClick = () => {
6057
+ if (disabled.value) {
6058
+ return;
6059
+ }
6060
+ isClick.value && (visible.value = !visible.value);
6061
+ };
6025
6062
  const enter = lodash.exports.debounce(() => {
6026
6063
  isEnter.value && (visible.value = true);
6027
6064
  }, mouseEnterDelay.value);
@@ -6029,6 +6066,9 @@ function usePopoverEvent(props, visible, origin) {
6029
6066
  !isEnter.value && (visible.value = false);
6030
6067
  }, mouseLeaveDelay.value);
6031
6068
  const onMouseenter = () => {
6069
+ if (disabled.value) {
6070
+ return;
6071
+ }
6032
6072
  if (!isClick.value) {
6033
6073
  isEnter.value = true;
6034
6074
  enter();
@@ -6040,6 +6080,15 @@ function usePopoverEvent(props, visible, origin) {
6040
6080
  leave();
6041
6081
  }
6042
6082
  };
6083
+ const quickLeave = () => {
6084
+ isEnter.value = false;
6085
+ visible.value = false;
6086
+ };
6087
+ watch(disabled, (newVal) => {
6088
+ if (newVal && visible.value) {
6089
+ quickLeave();
6090
+ }
6091
+ });
6043
6092
  const handlePositionChange = (pos) => {
6044
6093
  placement.value = pos.split("-")[0];
6045
6094
  };
@@ -6051,11 +6100,12 @@ function usePopoverEvent(props, visible, origin) {
6051
6100
  origin.value.addEventListener("mouseleave", onMouseleave);
6052
6101
  }
6053
6102
  });
6054
- return { placement, handlePositionChange };
6103
+ return { placement, handlePositionChange, onMouseenter, onMouseleave };
6055
6104
  }
6056
- function SuccessIcon() {
6105
+ const ns = useNamespace("popover");
6106
+ function SuccessIcon$1() {
6057
6107
  return createVNode("svg", {
6058
- "class": "devui-icon devui-icon-success",
6108
+ "class": [ns.e("icon"), ns.em("icon", "success")],
6059
6109
  "viewBox": "0 0 16 16",
6060
6110
  "version": "1.1",
6061
6111
  "xmlns": "http://www.w3.org/2000/svg"
@@ -6079,7 +6129,7 @@ function SuccessIcon() {
6079
6129
  }
6080
6130
  function WarningIcon() {
6081
6131
  return createVNode("svg", {
6082
- "class": "devui-icon devui-icon-warning",
6132
+ "class": [ns.e("icon"), ns.em("icon", "warning")],
6083
6133
  "viewBox": "0 0 16 16",
6084
6134
  "version": "1.1",
6085
6135
  "xmlns": "http://www.w3.org/2000/svg"
@@ -6089,14 +6139,14 @@ function WarningIcon() {
6089
6139
  "fill": "none",
6090
6140
  "fill-rule": "evenodd"
6091
6141
  }, [createVNode("polygon", {
6092
- "points": "7.5 1.74501946 1.39184847 13.5954649 7.08947368 14.2207621 13.9973698 13.5954649 10.9383683 5.61273879 8.40084114 1.27624313"
6142
+ "points": "7.5 1.74501946 1.39184847 13.5954649 7.08947368 14.2207621 13.9973698 13.5954649 10.9383683 5.61273879 8.40084114 1.27624313"
6093
6143
  }, null), createVNode("path", {
6094
- "d": "M8.51325441,0.127397589 C8.70423071,0.228333932 8.8605922,0.383286648 8.96244623,0.57254229 L15.8714442,13.4101975 C16.1549662,13.9370117 15.9538562,14.5918482 15.4222523,14.8728158 C15.2642579,14.9563203 15.0879506,15 14.9088903,15 L1.09089441,15 C0.488410063,15 0,14.5159904 0,13.9189343 C0,13.7414873 0.0440768395,13.5667684 0.128340519,13.4101975 L7.03733844,0.57254229 C7.32086049,0.0457280838 7.98165058,-0.153569987 8.51325441,0.127397589 Z M8.87894737,11.2105263 L7.08947368,11.2105263 L7.08947368,13 L8.87894737,13 L8.87894737,11.2105263 Z M8.96842105,4.5 L7,4.5 L7.08947368,9.86842105 L8.87894737,9.86842105 L8.96842105,4.5 Z"
6144
+ "d": "M8.51325441,0.127397589 C8.70423071,0.228333932 8.8605922,0.383286648 8.96244623,0.57254229 L15.8714442,13.4101975 C16.1549662,13.9370117 15.9538562,14.5918482 15.4222523,14.8728158 C15.2642579,14.9563203 15.0879506,15 14.9088903,15 L1.09089441,15 C0.488410063,15 0,14.5159904 0,13.9189343 C0,13.7414873 0.0440768395,13.5667684 0.128340519,13.4101975 L7.03733844,0.57254229 C7.32086049,0.0457280838 7.98165058,-0.153569987 8.51325441,0.127397589 Z M8.87894737,11.2105263 L7.08947368,11.2105263 L7.08947368,13 L8.87894737,13 L8.87894737,11.2105263 Z M8.96842105,4.5 L7,4.5 L7.08947368,9.86842105 L8.87894737,9.86842105 L8.96842105,4.5 Z"
6095
6145
  }, null)])]);
6096
6146
  }
6097
6147
  function InfoIcon() {
6098
6148
  return createVNode("svg", {
6099
- "class": "devui-icon devui-icon-info",
6149
+ "class": [ns.e("icon"), ns.em("icon", "info")],
6100
6150
  "viewBox": "0 0 16 16",
6101
6151
  "version": "1.1",
6102
6152
  "xmlns": "http://www.w3.org/2000/svg"
@@ -6112,12 +6162,12 @@ function InfoIcon() {
6112
6162
  }, null), createVNode("g", {
6113
6163
  "stroke-width": "1"
6114
6164
  }, [createVNode("path", {
6115
- "d": "M8,0 C3.6,0 0,3.6 0,8 C0,12.4 3.6,16 8,16 C12.4,16 16,12.4 16,8 C16,3.6 12.4,0 8,0 Z M9,5 L7,5 L7,3 L9,3 L9,5 Z M9,12.6 L7,12.6 L7,6.6 L9,6.6 L9,12.6 Z"
6165
+ "d": "M8,0 C3.6,0 0,3.6 0,8 C0,12.4 3.6,16 8,16 C12.4,16 16,12.4 16,8 C16,3.6 12.4,0 8,0 Z M9,5 L7,5 L7,3 L9,3 L9,5 Z M9,12.6 L7,12.6 L7,6.6 L9,6.6 L9,12.6 Z"
6116
6166
  }, null)])])]);
6117
6167
  }
6118
- function ErrorIcon() {
6168
+ function ErrorIcon$1() {
6119
6169
  return createVNode("svg", {
6120
- "class": "devui-icon devui-icon-error",
6170
+ "class": [ns.e("icon"), ns.em("icon", "error")],
6121
6171
  "width": "16px",
6122
6172
  "height": "16px",
6123
6173
  "viewBox": "0 0 16 16",
@@ -6133,7 +6183,7 @@ function ErrorIcon() {
6133
6183
  "cy": "8",
6134
6184
  "r": "7"
6135
6185
  }, null), createVNode("path", {
6136
- "d": "M8,0 C3.6,0 0,3.6 0,8 C0,12.4 3.6,16 8,16 C12.4,16 16,12.4 16,8 C16,3.6 12.4,0 8,0 Z M9,12.6 L7,12.6 L7,10.6 L9,10.6 L9,12.6 Z M9,9.1 L7,9.1 L6.9,3.1 L9.1,3.1 L9,9.1 Z",
6186
+ "d": "M8,0 C3.6,0 0,3.6 0,8 C0,12.4 3.6,16 8,16 C12.4,16 16,12.4 16,8 C16,3.6 12.4,0 8,0 Z M9,12.6 L7,12.6 L7,10.6 L9,10.6 L9,12.6 Z M9,9.1 L7,9.1 L6.9,3.1 L9.1,3.1 L9,9.1 Z",
6137
6187
  "fill-rule": "nonzero"
6138
6188
  }, null)])]);
6139
6189
  }
@@ -6146,9 +6196,10 @@ var PopoverIcon = defineComponent({
6146
6196
  }
6147
6197
  },
6148
6198
  setup(props) {
6199
+ const ns2 = useNamespace("popover");
6149
6200
  return () => props.type && props.type !== "default" && createVNode("span", {
6150
- "class": "devui-popover-icon"
6151
- }, [props.type === "success" && createVNode(SuccessIcon, null, null), props.type === "warning" && createVNode(WarningIcon, null, null), props.type === "info" && createVNode(InfoIcon, null, null), props.type === "error" && createVNode(ErrorIcon, null, null)]);
6201
+ "class": ns2.e("icon-wrap")
6202
+ }, [props.type === "success" && createVNode(SuccessIcon$1, null, null), props.type === "warning" && createVNode(WarningIcon, null, null), props.type === "info" && createVNode(InfoIcon, null, null), props.type === "error" && createVNode(ErrorIcon$1, null, null)]);
6152
6203
  }
6153
6204
  });
6154
6205
  var popover = "";
@@ -6156,9 +6207,11 @@ var Popover = defineComponent({
6156
6207
  name: "DPopover",
6157
6208
  inheritAttrs: false,
6158
6209
  props: popoverProps,
6210
+ emits: ["show", "hide"],
6159
6211
  setup(props, {
6160
6212
  slots,
6161
- attrs
6213
+ attrs,
6214
+ emit
6162
6215
  }) {
6163
6216
  const {
6164
6217
  content,
@@ -6173,89 +6226,260 @@ var Popover = defineComponent({
6173
6226
  const visible = ref(false);
6174
6227
  const {
6175
6228
  placement,
6176
- handlePositionChange
6229
+ handlePositionChange,
6230
+ onMouseenter,
6231
+ onMouseleave
6177
6232
  } = usePopoverEvent(props, visible, origin);
6178
6233
  const {
6179
6234
  overlayStyles
6180
6235
  } = usePopover(props, visible, placement, origin, popoverRef);
6181
- return () => {
6182
- var _a;
6183
- return createVNode(Fragment, null, [createVNode("div", {
6184
- "ref": origin,
6185
- "class": "devui-popover-reference"
6186
- }, [(_a = slots.reference) == null ? void 0 : _a.call(slots)]), createVNode(Teleport, {
6187
- "to": "body"
6236
+ const ns2 = useNamespace("popover");
6237
+ provide(POPPER_TRIGGER_TOKEN, origin);
6238
+ watch(visible, (newVal) => {
6239
+ if (newVal) {
6240
+ emit("show");
6241
+ } else {
6242
+ emit("hide");
6243
+ }
6244
+ });
6245
+ return () => createVNode(Fragment, null, [createVNode(PopperTrigger, null, {
6246
+ default: () => {
6247
+ var _a;
6248
+ return [(_a = slots.default) == null ? void 0 : _a.call(slots)];
6249
+ }
6250
+ }), createVNode(Teleport, {
6251
+ "to": "body"
6252
+ }, {
6253
+ default: () => [createVNode(Transition, {
6254
+ "name": showAnimation.value ? ns2.m(`fade-${placement.value}`) : ""
6188
6255
  }, {
6189
- default: () => [createVNode(Transition, {
6190
- "name": showAnimation.value ? `devui-popover-fade-${placement.value}` : ""
6191
- }, {
6192
- default: () => [createVNode(FlexibleOverlay, mergeProps({
6193
- "modelValue": visible.value,
6194
- "onUpdate:modelValue": ($event) => visible.value = $event,
6195
- "ref": popoverRef,
6196
- "origin": origin.value,
6197
- "position": position.value,
6198
- "align": align.value,
6199
- "offset": offset2.value,
6200
- "class": ["devui-popover-content", popType.value !== "default" ? "is-icon" : ""],
6201
- "show-arrow": true,
6202
- "is-arrow-center": false,
6203
- "style": overlayStyles.value
6204
- }, attrs, {
6205
- "onPositionChange": handlePositionChange
6206
- }), {
6207
- default: () => {
6208
- var _a2;
6209
- return [createVNode(PopoverIcon, {
6210
- "type": popType.value
6211
- }, null), ((_a2 = slots.content) == null ? void 0 : _a2.call(slots)) || createVNode("span", null, [content.value])];
6212
- }
6213
- })]
6256
+ default: () => [createVNode(FlexibleOverlay, mergeProps({
6257
+ "modelValue": visible.value,
6258
+ "onUpdate:modelValue": ($event) => visible.value = $event,
6259
+ "ref": popoverRef,
6260
+ "origin": origin.value,
6261
+ "position": position.value,
6262
+ "align": align.value,
6263
+ "offset": offset2.value,
6264
+ "class": [ns2.e("content"), popType.value !== "default" ? "is-icon" : ""],
6265
+ "show-arrow": true,
6266
+ "is-arrow-center": false,
6267
+ "style": overlayStyles.value
6268
+ }, attrs, {
6269
+ "onPositionChange": handlePositionChange,
6270
+ "onMouseenter": onMouseenter,
6271
+ "onMouseleave": onMouseleave
6272
+ }), {
6273
+ default: () => {
6274
+ var _a;
6275
+ return [createVNode(PopoverIcon, {
6276
+ "type": popType.value
6277
+ }, null), ((_a = slots.content) == null ? void 0 : _a.call(slots)) || createVNode("span", null, [content.value])];
6278
+ }
6214
6279
  })]
6215
- })]);
6216
- };
6280
+ })]
6281
+ })]);
6217
6282
  }
6218
6283
  });
6284
+ function HelpTipsIcon() {
6285
+ return createVNode("svg", {
6286
+ "width": "16px",
6287
+ "height": "16px",
6288
+ "viewBox": "0 0 16 16"
6289
+ }, [createVNode("g", {
6290
+ "stroke": "none",
6291
+ "stroke-width": "1",
6292
+ "fill": "none",
6293
+ "fill-rule": "evenodd"
6294
+ }, [createVNode("g", null, [createVNode("path", {
6295
+ "d": "M8.5,8.95852078 L8.5,11 L7.5,11 L7.5,8.5 C7.5,8.22385763 7.72385763,8 8,8 C9.1045695,8 10,7.1045695 10,6 C10,4.8954305 9.1045695,4 8,4 C6.8954305,4 6,4.8954305 6,6 L5,6 C5,4.34314575 6.34314575,3 8,3 C9.65685425,3 11,4.34314575 11,6 C11,7.48649814 9.91885667,8.72048173 8.5,8.95852078 L8.5,8.95852078 Z M8,16 C3.581722,16 0,12.418278 0,8 C0,3.581722 3.581722,0 8,0 C12.418278,0 16,3.581722 16,8 C16,12.418278 12.418278,16 8,16 Z M8,15 C11.8659932,15 15,11.8659932 15,8 C15,4.13400675 11.8659932,1 8,1 C4.13400675,1 1,4.13400675 1,8 C1,11.8659932 4.13400675,15 8,15 Z M7.5,12 L8.5,12 L8.5,13 L7.5,13 L7.5,12 Z",
6296
+ "fill": "#293040",
6297
+ "fill-rule": "nonzero"
6298
+ }, null)])])]);
6299
+ }
6300
+ function ErrorIcon() {
6301
+ return createVNode("svg", {
6302
+ "width": "14px",
6303
+ "height": "14px",
6304
+ "viewBox": "0 0 16 16"
6305
+ }, [createVNode("g", {
6306
+ "stroke": "none",
6307
+ "stroke-width": "1",
6308
+ "fill": "none",
6309
+ "fill-rule": "evenodd"
6310
+ }, [createVNode("circle", {
6311
+ "cx": "8",
6312
+ "cy": "8",
6313
+ "r": "8"
6314
+ }, null), createVNode("polygon", {
6315
+ "points": "8.07106781 6.65685425 10.8994949 3.82842712 12.3137085 5.24264069 9.48528137 8.07106781 12.3137085 10.8994949 10.8994949 12.3137085 8.07106781 9.48528137 5.24264069 12.3137085 3.82842712 10.8994949 6.65685425 8.07106781 3.82842712 5.24264069 5.24264069 3.82842712"
6316
+ }, null)])]);
6317
+ }
6318
+ function SuccessIcon() {
6319
+ return createVNode("svg", {
6320
+ "width": "14px",
6321
+ "height": "14px",
6322
+ "viewBox": "0 0 16 16"
6323
+ }, [createVNode("g", {
6324
+ "stroke": "none",
6325
+ "stroke-width": "1",
6326
+ "fill": "none",
6327
+ "fill-rule": "evenodd"
6328
+ }, [createVNode("circle", {
6329
+ "cx": "8",
6330
+ "cy": "8",
6331
+ "r": "8"
6332
+ }, null), createVNode("polygon", {
6333
+ "points": "6.53553391 9.77817459 12.1923882 4.12132034 13.6066017 5.53553391 6.53553391 12.6066017 3 9.07106781 4.41421356 7.65685425 6.53553391 9.77817459"
6334
+ }, null)])]);
6335
+ }
6336
+ function PendingIcon() {
6337
+ return createVNode("svg", {
6338
+ "width": "14px",
6339
+ "height": "14px",
6340
+ "viewBox": "0 0 16 16"
6341
+ }, [createVNode("g", {
6342
+ "id": "loading",
6343
+ "stroke": "none",
6344
+ "stroke-width": "1",
6345
+ "fill": "none",
6346
+ "fill-rule": "evenodd"
6347
+ }, [createVNode("path", {
6348
+ "d": "M8,0 C12.4,0 16,3.6 16,8 C16,12.4 12.4,16 8,16 C3.6,16 0,12.4 0,8 C0,3.6 3.6,0 8,0 Z M8,1 C4.15,1 1,4.15 1,8 C1,11.85 4.15,15 8,15 C11.85,15 15,11.85 15,8 C15,4.15 11.85,1 8,1 Z",
6349
+ "fill-rule": "nonzero"
6350
+ }, null), createVNode("path", {
6351
+ "d": "M8,0 C12.4,0 16,3.6 16,8 L15,8 C15,4.15 11.85,1 8,1 L8,0 Z",
6352
+ "fill-rule": "nonzero"
6353
+ }, null)])]);
6354
+ }
6355
+ function useFormLabel() {
6356
+ const formItemContext = inject(FORM_ITEM_TOKEN);
6357
+ const labelData = inject(LABEL_DATA);
6358
+ const ns2 = useNamespace("form");
6359
+ const labelClasses = computed(() => ({
6360
+ [`${ns2.e("label")}`]: true,
6361
+ [`${ns2.em("label", "vertical")}`]: labelData.value.layout === "vertical",
6362
+ [`${ns2.em("label", labelData.value.labelSize)}`]: labelData.value.layout === "horizontal",
6363
+ [`${ns2.em("label", labelData.value.labelAlign)}`]: labelData.value.layout === "horizontal"
6364
+ }));
6365
+ const labelInnerClasses = computed(() => ({
6366
+ [`${ns2.e("label-span")}`]: true,
6367
+ [`${ns2.em("label", "required")}`]: formItemContext.isRequired
6368
+ }));
6369
+ return { labelClasses, labelInnerClasses };
6370
+ }
6219
6371
  var formLabel = "";
6220
6372
  var FormLabel = defineComponent({
6221
6373
  name: "DFormLabel",
6222
6374
  props: formLabelProps,
6223
- setup(props, ctx2) {
6224
- const dForm = reactive(inject(formInjectionKey, {}));
6225
- const labelData = reactive(dForm.labelData);
6226
- const isHorizontal = computed(() => labelData.layout === "horizontal").value;
6227
- const isLg = computed(() => labelData.labelSize === "lg").value;
6228
- const isSm = computed(() => labelData.labelSize === "sm").value;
6229
- const isCenter = computed(() => labelData.labelAlign === "center").value;
6230
- const isEnd = computed(() => labelData.labelAlign === "end").value;
6231
- const wrapperCls = `devui-form-label${isHorizontal ? isSm ? " devui-form-label_sm" : isLg ? " devui-form-label_lg" : " devui-form-label_sd" : ""}${isCenter ? " devui-form-label_center" : isEnd ? " devui-form-label_end" : ""}`;
6232
- const className = `${props.required ? " devui-required" : ""}`;
6233
- const style2 = {
6234
- display: isHorizontal ? "inline" : "inline-block"
6235
- };
6375
+ setup(props, ctx) {
6376
+ const ns2 = useNamespace("form");
6377
+ const {
6378
+ labelClasses,
6379
+ labelInnerClasses
6380
+ } = useFormLabel();
6236
6381
  return () => {
6237
6382
  var _a, _b;
6238
6383
  return createVNode("span", {
6239
- "class": wrapperCls,
6240
- "style": style2
6384
+ "class": labelClasses.value
6241
6385
  }, [createVNode("span", {
6242
- "class": className
6243
- }, [(_b = (_a = ctx2.slots).default) == null ? void 0 : _b.call(_a), props.hasHelp && props.helpTips && createVNode(Popover, {
6386
+ "class": labelInnerClasses.value
6387
+ }, [(_b = (_a = ctx.slots).default) == null ? void 0 : _b.call(_a)]), props.helpTips && createVNode(Popover, {
6244
6388
  "content": props.helpTips,
6245
- "showAnimation": false,
6246
- "position": "top",
6247
- "trigger": "hover"
6389
+ "position": ["top"],
6390
+ "trigger": "hover",
6391
+ "pop-type": "info"
6248
6392
  }, {
6249
- reference: () => createVNode("span", {
6250
- "class": "devui-form-label-help"
6251
- }, [createVNode(Icon, {
6252
- "name": "helping",
6253
- "color": "#252b3a"
6254
- }, null)])
6255
- })])]);
6393
+ default: () => [createVNode(HelpTipsIcon, {
6394
+ "class": ns2.e("label-help")
6395
+ }, null), createTextVNode(",")]
6396
+ })]);
6256
6397
  };
6257
6398
  }
6258
6399
  });
6400
+ const formControlProps = {
6401
+ feedbackStatus: {
6402
+ type: String
6403
+ },
6404
+ extraInfo: {
6405
+ type: String,
6406
+ default: ""
6407
+ }
6408
+ };
6409
+ function useFormControl(props) {
6410
+ const labelData = inject(LABEL_DATA);
6411
+ const ns2 = useNamespace("form");
6412
+ const { feedbackStatus } = toRefs(props);
6413
+ const controlClasses = computed(() => ({
6414
+ [ns2.e("control")]: true,
6415
+ [ns2.em("control", "horizontal")]: labelData.value.layout === "horizontal"
6416
+ }));
6417
+ const controlContainerClasses = computed(() => ({
6418
+ [ns2.e("control-container")]: true,
6419
+ [ns2.em("control-container", "horizontal")]: labelData.value.layout === "horizontal",
6420
+ [ns2.em("control-container", "has-feedback")]: Boolean(feedbackStatus == null ? void 0 : feedbackStatus.value),
6421
+ [ns2.em("control-container", "feedback-error")]: Boolean((feedbackStatus == null ? void 0 : feedbackStatus.value) === "error")
6422
+ }));
6423
+ return { controlClasses, controlContainerClasses };
6424
+ }
6425
+ function useFormControlValidate() {
6426
+ const formItemContext = inject(FORM_ITEM_TOKEN);
6427
+ const feedbackStatus = computed(() => formItemContext.validateState);
6428
+ const showFeedback = computed(() => formItemContext.showFeedback && Boolean(formItemContext.validateState));
6429
+ const showPopover = computed(() => formItemContext.messageType === "popover" && formItemContext.validateState === "error");
6430
+ const showMessage = computed(() => formItemContext.messageType === "text" && formItemContext.validateState === "error");
6431
+ const errorMessage = computed(() => formItemContext.validateMessage);
6432
+ const popPosition = computed(() => formItemContext.popPosition);
6433
+ return { feedbackStatus, showFeedback, showPopover, showMessage, errorMessage, popPosition };
6434
+ }
6435
+ var formControl = "";
6436
+ var FormControl = defineComponent({
6437
+ name: "DFormControl",
6438
+ props: formControlProps,
6439
+ setup(props, ctx) {
6440
+ const formControl2 = ref();
6441
+ const ns2 = useNamespace("form");
6442
+ const {
6443
+ controlClasses,
6444
+ controlContainerClasses
6445
+ } = useFormControl(props);
6446
+ const {
6447
+ feedbackStatus,
6448
+ showFeedback,
6449
+ showPopover,
6450
+ showMessage,
6451
+ errorMessage,
6452
+ popPosition
6453
+ } = useFormControlValidate();
6454
+ return () => createVNode("div", {
6455
+ "class": controlClasses.value,
6456
+ "ref": formControl2
6457
+ }, [createVNode("div", {
6458
+ "class": controlContainerClasses.value
6459
+ }, [createVNode(Popover, {
6460
+ "is-open": showPopover.value,
6461
+ "trigger": "manually",
6462
+ "content": errorMessage.value,
6463
+ "pop-type": "error",
6464
+ "position": popPosition.value
6465
+ }, {
6466
+ default: () => {
6467
+ var _a, _b;
6468
+ return [createVNode("div", {
6469
+ "class": ns2.e("control-content")
6470
+ }, [(_b = (_a = ctx.slots).default) == null ? void 0 : _b.call(_a)]), createTextVNode(",")];
6471
+ }
6472
+ }), showFeedback.value && createVNode("span", {
6473
+ "class": [ns2.e("feedback-icon"), ns2.em("feedback-icon", feedbackStatus.value)]
6474
+ }, [feedbackStatus.value === "error" && createVNode(ErrorIcon, null, null), feedbackStatus.value === "success" && createVNode(SuccessIcon, null, null), feedbackStatus.value === "pending" && createVNode(PendingIcon, null, null)])]), createVNode("div", {
6475
+ "class": ns2.e("control-info")
6476
+ }, [showMessage.value && createVNode("div", {
6477
+ "class": "error-message"
6478
+ }, [errorMessage.value]), props.extraInfo && createVNode("div", {
6479
+ "class": ns2.e("control-extra")
6480
+ }, [props.extraInfo])])]);
6481
+ }
6482
+ });
6259
6483
  function _extends() {
6260
6484
  _extends = Object.assign || function(target) {
6261
6485
  for (var i = 1; i < arguments.length; i++) {
@@ -7258,619 +7482,256 @@ Schema.register = function register(type4, validator) {
7258
7482
  Schema.warning = warning;
7259
7483
  Schema.messages = messages;
7260
7484
  Schema.validators = validators;
7261
- var formItem = "";
7262
- var FormItem = defineComponent({
7263
- name: "DFormItem",
7264
- props: formItemProps,
7265
- setup(props, ctx2) {
7266
- const formItemMitt = mitt();
7267
- const dForm = reactive(inject(formInjectionKey, {}));
7268
- const formData = reactive(dForm.formData);
7269
- const columnsClass = ref(dForm.columnsClass);
7270
- const initFormItemData = formData[props.prop];
7271
- const labelData = reactive(dForm.labelData);
7272
- const rules2 = reactive(dForm.rules);
7273
- const resetField = () => {
7274
- if (Array.isArray(initFormItemData)) {
7275
- formData[props.prop] = [...initFormItemData];
7276
- } else {
7277
- formData[props.prop] = initFormItemData;
7485
+ function getFieldValue(obj, path) {
7486
+ return {
7487
+ get value() {
7488
+ return lodash.exports.get(obj, path);
7489
+ },
7490
+ set value(val) {
7491
+ lodash.exports.set(obj, path, val);
7492
+ }
7493
+ };
7494
+ }
7495
+ function useFormItem(messageType, _rules, validateState) {
7496
+ const formContext = inject(FORM_TOKEN);
7497
+ const ns2 = useNamespace("form");
7498
+ const itemClasses = computed(() => ({
7499
+ [`${ns2.em("item", "horizontal")}`]: formContext.layout === "horizontal",
7500
+ [`${ns2.em("item", "vertical")}`]: formContext.layout === "vertical",
7501
+ [`${ns2.em("item", "error")}`]: messageType.value === "text" && validateState.value === "error"
7502
+ }));
7503
+ const isRequired = computed(() => _rules.value.some((rule) => Boolean(rule.required)));
7504
+ return { itemClasses, isRequired };
7505
+ }
7506
+ function useFormItemRule(props) {
7507
+ const formContext = inject(FORM_TOKEN);
7508
+ const _rules = computed(() => {
7509
+ const rules2 = props.rules ? lodash.exports.castArray(props.rules) : [];
7510
+ const formRules = formContext.rules;
7511
+ if (formRules && props.field) {
7512
+ const _itemRules = lodash.exports.get(formRules, props.field, void 0);
7513
+ if (_itemRules) {
7514
+ rules2.push(...lodash.exports.castArray(_itemRules));
7278
7515
  }
7279
- };
7280
- const formItem2 = reactive({
7281
- dHasFeedback: props.dHasFeedback,
7282
- prop: props.prop,
7283
- formItemMitt,
7284
- resetField
7285
- });
7286
- provide(formItemInjectionKey, formItem2);
7287
- const isHorizontal = labelData.layout === "horizontal";
7288
- const isVertical = labelData.layout === "vertical";
7289
- const isColumns = labelData.layout === "columns";
7290
- const showMessage = ref(false);
7291
- const tipMessage = ref("");
7292
- const validate = (trigger) => {
7293
- const ruleKey = props.prop;
7294
- const ruleItem = rules2[ruleKey];
7295
- const descriptor = {};
7296
- descriptor[ruleKey] = ruleItem;
7297
- const validator = new Schema(descriptor);
7298
- validator.validate({
7299
- [ruleKey]: formData[ruleKey]
7300
- }).then(() => {
7301
- showMessage.value = false;
7302
- tipMessage.value = "";
7303
- }).catch(({
7304
- errors
7305
- }) => {
7306
- showMessage.value = true;
7307
- tipMessage.value = errors[0].message;
7308
- });
7309
- };
7310
- const validateEvents = [];
7311
- const addValidateEvents = () => {
7312
- if (rules2 && rules2[props.prop]) {
7313
- const ruleItem = rules2[props.prop];
7314
- let eventName = ruleItem["trigger"];
7315
- if (Array.isArray(ruleItem)) {
7316
- ruleItem.forEach((item) => {
7317
- eventName = item["trigger"];
7318
- const cb = () => validate();
7319
- validateEvents.push({
7320
- eventName: cb
7321
- });
7322
- formItem2.formItemMitt.on(dFormItemEvents[eventName], cb);
7323
- });
7324
- } else {
7325
- const cb = () => validate();
7326
- validateEvents.push({
7327
- eventName: cb
7328
- });
7329
- ruleItem && formItem2.formItemMitt.on(dFormItemEvents[eventName], cb);
7330
- }
7516
+ }
7517
+ if (props.required) {
7518
+ rules2.push({ required: Boolean(props.required) });
7519
+ }
7520
+ return rules2;
7521
+ });
7522
+ return { _rules };
7523
+ }
7524
+ function useFormItemValidate(props, _rules) {
7525
+ const formContext = inject(FORM_TOKEN);
7526
+ const validateState = ref("");
7527
+ const validateMessage = ref("");
7528
+ let initFieldValue = void 0;
7529
+ let isResetting = false;
7530
+ const computedField = computed(() => {
7531
+ return typeof props.field === "string" ? props.field : "";
7532
+ });
7533
+ const fieldValue = computed(() => {
7534
+ const formData = formContext.data;
7535
+ if (!formData || !props.field) {
7536
+ return;
7537
+ }
7538
+ return getFieldValue(formData, props.field).value;
7539
+ });
7540
+ const getRuleByTrigger = (triggerVal) => {
7541
+ return _rules.value.filter((rule) => {
7542
+ if (!rule.trigger || !triggerVal) {
7543
+ return true;
7331
7544
  }
7332
- };
7333
- const removeValidateEvents = () => {
7334
- if (rules2 && rules2[props.prop] && validateEvents.length > 0) {
7335
- validateEvents.forEach((item) => {
7336
- formItem2.formItemMitt.off(item.eventName, item.cb);
7337
- });
7545
+ if (Array.isArray(rule.trigger)) {
7546
+ return rule.trigger.includes(triggerVal);
7547
+ } else {
7548
+ return rule.trigger === triggerVal;
7338
7549
  }
7339
- };
7340
- onMounted(() => {
7341
- dForm.formMitt.emit(dFormEvents.addField, formItem2);
7342
- addValidateEvents();
7550
+ }).map((_a) => {
7551
+ var _b = _a, { trigger } = _b, rule = __objRest(_b, ["trigger"]);
7552
+ return rule;
7343
7553
  });
7344
- onBeforeUnmount(() => {
7345
- dForm.formMitt.emit(dFormEvents.removeField, formItem2);
7346
- removeValidateEvents();
7554
+ };
7555
+ const onValidateSuccess = () => {
7556
+ validateState.value = "success";
7557
+ validateMessage.value = "";
7558
+ formContext.emit("validate", props.field, true, "");
7559
+ };
7560
+ const onValidateError = ({ errors }) => {
7561
+ var _a;
7562
+ validateState.value = "error";
7563
+ validateMessage.value = ((_a = errors == null ? void 0 : errors[0]) == null ? void 0 : _a.message) || "";
7564
+ formContext.emit("validate", props.field, false, validateMessage.value);
7565
+ };
7566
+ const execValidate = async (rules2) => {
7567
+ const ruleName = computedField.value;
7568
+ const validator = new Schema({
7569
+ [ruleName]: rules2
7347
7570
  });
7348
- return () => {
7349
- var _a, _b;
7350
- return createVNode("div", {
7351
- "class": `devui-form-item${isHorizontal ? "" : isVertical ? " devui-form-item-vertical" : " devui-form-item-columns"}${isColumns ? " devui-column-item " + columnsClass.value : ""}`
7352
- }, [(_b = (_a = ctx2.slots).default) == null ? void 0 : _b.call(_a), createVNode("div", {
7353
- "class": `devui-validate-tip${isHorizontal ? " devui-validate-tip-horizontal" : ""}`
7354
- }, [showMessage.value && tipMessage.value])]);
7355
- };
7356
- }
7357
- });
7358
- function on(element, eventName, handler) {
7359
- if (document.addEventListener) {
7360
- if (element && eventName && handler) {
7361
- element.addEventListener(eventName, handler, false);
7571
+ return validator.validate({ [ruleName]: fieldValue.value }, { firstFields: true }).then(() => {
7572
+ onValidateSuccess();
7573
+ return true;
7574
+ }).catch((error) => {
7575
+ onValidateError(error);
7576
+ return Promise.reject(error);
7577
+ });
7578
+ };
7579
+ const validate = async (trigger, callback) => {
7580
+ if (isResetting) {
7581
+ isResetting = false;
7582
+ return false;
7362
7583
  }
7363
- } else {
7364
- if (element && eventName && handler) {
7365
- element.attachEvent("on" + eventName, handler);
7584
+ const rules2 = getRuleByTrigger(trigger);
7585
+ if (!rules2.length) {
7586
+ callback == null ? void 0 : callback(true);
7587
+ return true;
7366
7588
  }
7367
- }
7368
- }
7369
- const ctx = Symbol("@@clickoutside");
7370
- const nodeList = /* @__PURE__ */ new Map();
7371
- let startClick;
7372
- let nid = 0;
7373
- let isFirst = true;
7374
- function createDocumentHandler(el, binding, vnode) {
7375
- if (inBrowser && isFirst) {
7376
- isFirst = false;
7377
- on(document, "mousedown", (e) => {
7378
- startClick = e;
7379
- });
7380
- on(document, "mouseup", (e) => {
7381
- for (const [id, node] of nodeList) {
7382
- node[ctx].documentHandler(e, startClick);
7383
- }
7589
+ validateState.value = "pending";
7590
+ return execValidate(rules2).then(() => {
7591
+ callback == null ? void 0 : callback(true);
7592
+ return true;
7593
+ }).catch((error) => {
7594
+ const { fields } = error;
7595
+ callback == null ? void 0 : callback(false, fields);
7596
+ return lodash.exports.isFunction(callback) ? false : Promise.reject(fields);
7384
7597
  });
7385
- }
7386
- return function(mouseup, mousedown) {
7387
- if (!vnode || !binding.instance || !mouseup.target || !mousedown.target || el.contains(mouseup.target) || el.contains(mousedown.target) || el === mouseup.target) {
7598
+ };
7599
+ const clearValidate = () => {
7600
+ validateState.value = "";
7601
+ validateMessage.value = "";
7602
+ };
7603
+ const resetField = async () => {
7604
+ if (!formContext.data || !props.field) {
7388
7605
  return;
7389
7606
  }
7390
- el[ctx].bindingFn && el[ctx].bindingFn();
7607
+ const currentValue = getFieldValue(formContext.data, props.field);
7608
+ if (!lodash.exports.isEqual(currentValue.value, initFieldValue)) {
7609
+ isResetting = true;
7610
+ }
7611
+ currentValue.value = initFieldValue;
7612
+ await nextTick();
7613
+ clearValidate();
7391
7614
  };
7615
+ onMounted(() => {
7616
+ initFieldValue = lodash.exports.clone(fieldValue.value);
7617
+ });
7618
+ return { validateState, validateMessage, validate, resetField, clearValidate };
7392
7619
  }
7393
- const clickoutsideDirective = {
7394
- beforeMount: function(el, binding, vnode) {
7395
- nid++;
7396
- nodeList.set(nid, el);
7397
- el[ctx] = {
7398
- nid,
7399
- documentHandler: createDocumentHandler(el, binding, vnode),
7400
- bindingFn: binding.value
7401
- };
7402
- },
7403
- updated: function(el, binding, vnode) {
7404
- el[ctx].documentHandler = createDocumentHandler(el, binding, vnode);
7405
- el[ctx].bindingFn = binding.value;
7406
- },
7407
- unmounted: function(el) {
7408
- nodeList.delete(el[ctx].nid);
7409
- delete el[ctx];
7410
- }
7411
- };
7412
- var formControl = "";
7413
- var FormControl = defineComponent({
7414
- name: "DFormControl",
7415
- directives: {
7416
- clickoutside: clickoutsideDirective
7417
- },
7418
- props: formControlProps,
7419
- setup(props, ctx2) {
7420
- const formControl2 = ref();
7421
- const dForm = reactive(inject(formInjectionKey, {}));
7422
- const labelData = reactive(dForm.labelData);
7423
- const isHorizontal = labelData.layout === "horizontal";
7424
- const uid = lodash.exports.uniqueId("dfc-");
7425
- const showPopover = ref(false);
7426
- const updateOn = ref("change");
7427
- const tipMessage = ref("");
7428
- const popPosition = ref("bottom");
7429
- let rectInfo = {
7430
- width: 0,
7431
- height: 0
7432
- };
7433
- let elOffset = {
7434
- left: 0,
7435
- top: 0
7436
- };
7437
- let popoverLeftPosition = 0;
7438
- let popoverTopPosition = 0;
7439
- onMounted(() => {
7440
- const el = document.getElementById(uid);
7441
- elOffset = getElOffset(el);
7442
- EventBus.on("showPopoverErrorMessage", (data) => {
7443
- var _a;
7444
- if (uid === data.uid) {
7445
- rectInfo = el.getBoundingClientRect();
7446
- showPopover.value = data.showPopover;
7447
- tipMessage.value = data.message;
7448
- popPosition.value = data.popPosition;
7449
- popoverLeftPosition = popPosition.value === "top" || popPosition.value === "bottom" ? rectInfo.right - rectInfo.width / 2 : rectInfo.right;
7450
- popoverTopPosition = popPosition.value === "top" ? elOffset.top + rectInfo.height / 2 - rectInfo.height : elOffset.top + rectInfo.height / 2;
7451
- updateOn.value = (_a = data.updateOn) != null ? _a : "change";
7452
- }
7453
- });
7620
+ var formItem = "";
7621
+ var FormItem = defineComponent({
7622
+ name: "DFormItem",
7623
+ props: formItemProps,
7624
+ setup(props, ctx) {
7625
+ const formContext = inject(FORM_TOKEN);
7626
+ const _a = toRefs(props), {
7627
+ messageType: itemMessageType,
7628
+ popPosition: itemPopPosition,
7629
+ showFeedback: itemShowFeedback
7630
+ } = _a, otherProps = __objRest(_a, [
7631
+ "messageType",
7632
+ "popPosition",
7633
+ "showFeedback"
7634
+ ]);
7635
+ const {
7636
+ label,
7637
+ helpTips,
7638
+ feedbackStatus,
7639
+ extraInfo
7640
+ } = toRefs(props);
7641
+ const showFeedback = computed(() => (itemShowFeedback == null ? void 0 : itemShowFeedback.value) !== void 0 ? itemShowFeedback.value : formContext.showFeedback);
7642
+ const messageType = computed(() => (itemMessageType == null ? void 0 : itemMessageType.value) || formContext.messageType);
7643
+ const popPosition = computed(() => (itemPopPosition == null ? void 0 : itemPopPosition.value) || formContext.popPosition);
7644
+ const {
7645
+ _rules
7646
+ } = useFormItemRule(props);
7647
+ const {
7648
+ validateState,
7649
+ validateMessage,
7650
+ validate,
7651
+ resetField,
7652
+ clearValidate
7653
+ } = useFormItemValidate(props, _rules);
7654
+ const {
7655
+ itemClasses,
7656
+ isRequired
7657
+ } = useFormItem(messageType, _rules, validateState);
7658
+ const labelData = computed(() => ({
7659
+ layout: formContext.layout,
7660
+ labelSize: formContext.labelSize,
7661
+ labelAlign: formContext.labelAlign
7662
+ }));
7663
+ provide(LABEL_DATA, labelData);
7664
+ const context = reactive(__spreadProps(__spreadValues({}, otherProps), {
7665
+ showFeedback,
7666
+ messageType,
7667
+ popPosition,
7668
+ isRequired,
7669
+ validateState,
7670
+ validateMessage,
7671
+ validate,
7672
+ resetField,
7673
+ clearValidate
7674
+ }));
7675
+ provide(FORM_ITEM_TOKEN, context);
7676
+ ctx.expose({
7677
+ resetField,
7678
+ clearValidate
7454
7679
  });
7455
- const iconData = computed(() => {
7456
- switch (props.feedbackStatus) {
7457
- case "pending":
7458
- return {
7459
- name: "priority",
7460
- color: "#e9edfa"
7461
- };
7462
- case "success":
7463
- return {
7464
- name: "right-o",
7465
- color: "rgb(61, 204, 166)"
7466
- };
7467
- case "error":
7468
- return {
7469
- name: "error-o",
7470
- color: "rgb(249, 95, 91)"
7471
- };
7472
- default:
7473
- return {
7474
- name: "",
7475
- color: ""
7476
- };
7680
+ onMounted(() => {
7681
+ if (props.field) {
7682
+ formContext == null ? void 0 : formContext.addItemContext(context);
7477
7683
  }
7478
7684
  });
7479
- const handleClickOutside = () => {
7480
- if (updateOn.value !== "change") {
7481
- showPopover.value = false;
7482
- }
7483
- };
7484
- return () => {
7485
- var _a, _b, _c, _d, _e, _f, _g, _h;
7486
- const {
7487
- feedbackStatus,
7488
- extraInfo
7489
- } = props;
7490
- return withDirectives(createVNode("div", {
7491
- "class": "devui-form-control",
7492
- "ref": formControl2,
7493
- "data-uid": uid
7494
- }, [showPopover.value && createVNode(Teleport, {
7495
- "to": "body"
7496
- }, {
7497
- default: () => [createVNode("div", {
7498
- "style": {
7499
- position: "absolute",
7500
- left: popoverLeftPosition + "px",
7501
- top: popoverTopPosition + "px",
7502
- width: rectInfo.width + "px",
7503
- height: rectInfo.height + "px"
7504
- }
7505
- }, [createVNode(Popover, {
7506
- "controlled": updateOn.value !== "change",
7507
- "visible": showPopover.value,
7508
- "content": tipMessage.value,
7509
- "popType": "error",
7510
- "position": popPosition.value
7511
- }, null)])]
7512
- }), createVNode("div", {
7513
- "class": `devui-form-control-container${isHorizontal ? " devui-form-control-container-horizontal" : ""}${feedbackStatus ? " devui-has-feedback" : ""}${feedbackStatus === "error" ? " devui-feedback-error" : ""}`
7514
- }, [createVNode("div", {
7515
- "class": "devui-control-content-wrapper",
7516
- "id": uid
7517
- }, [(_b = (_a = ctx2.slots).default) == null ? void 0 : _b.call(_a)]), (feedbackStatus || ((_d = (_c = ctx2.slots).suffixTemplate) == null ? void 0 : _d.call(_c))) && createVNode("span", {
7518
- "class": "devui-feedback-status"
7519
- }, [((_f = (_e = ctx2.slots).suffixTemplate) == null ? void 0 : _f.call(_e)) ? (_h = (_g = ctx2.slots).suffixTemplate) == null ? void 0 : _h.call(_g) : createVNode(Icon, {
7520
- "name": iconData.value.name,
7521
- "color": iconData.value.color
7522
- }, null)])]), extraInfo && createVNode("div", {
7523
- "class": "devui-form-control-extra-info"
7524
- }, [extraInfo])]), [[resolveDirective("clickoutside"), handleClickOutside]]);
7525
- };
7685
+ onBeforeUnmount(() => {
7686
+ formContext == null ? void 0 : formContext.removeItemContext(context);
7687
+ });
7688
+ return () => createVNode("div", {
7689
+ "class": itemClasses.value
7690
+ }, [createVNode(FormLabel, {
7691
+ "help-tips": helpTips.value
7692
+ }, {
7693
+ default: () => [label == null ? void 0 : label.value]
7694
+ }), createVNode(FormControl, {
7695
+ "feedback-status": feedbackStatus == null ? void 0 : feedbackStatus.value,
7696
+ "extra-info": extraInfo.value
7697
+ }, {
7698
+ default: () => {
7699
+ var _a2, _b;
7700
+ return [(_b = (_a2 = ctx.slots).default) == null ? void 0 : _b.call(_a2)];
7701
+ }
7702
+ })]);
7526
7703
  }
7527
7704
  });
7528
7705
  var formOperation = "";
7529
7706
  var FormOperation = defineComponent({
7530
7707
  name: "DFormOperation",
7531
- props: {},
7532
- setup(props, ctx2) {
7708
+ setup(props, ctx) {
7709
+ const formContext = inject(FORM_TOKEN);
7710
+ const LabelSizeMap = {
7711
+ sm: 80,
7712
+ md: 100,
7713
+ lg: 150
7714
+ };
7715
+ const styles = computed(() => ({
7716
+ marginLeft: formContext.layout === "horizontal" ? `${LabelSizeMap[formContext.labelSize] + 16}px` : void 0
7717
+ }));
7533
7718
  return () => {
7534
7719
  var _a, _b;
7535
7720
  return createVNode("div", {
7536
- "class": "devui-form-operation"
7537
- }, [(_b = (_a = ctx2.slots).default) == null ? void 0 : _b.call(_a)]);
7721
+ "class": "devui-form-operation",
7722
+ "style": styles.value
7723
+ }, [(_b = (_a = ctx.slots).default) == null ? void 0 : _b.call(_a)]);
7538
7724
  };
7539
7725
  }
7540
7726
  });
7541
- var style = "";
7542
- function getAvaliableRuleObj(ruleName, value) {
7543
- if (!ruleName) {
7544
- console.error("[v-d-validate] validator's key is invalid");
7545
- return null;
7546
- }
7547
- switch (ruleName) {
7548
- case "maxlength":
7549
- return {
7550
- type: "string",
7551
- max: value,
7552
- asyncValidator: (rule, val) => {
7553
- return new Promise((resolve, reject) => {
7554
- if (val.length > value) {
7555
- reject("\u6700\u5927\u957F\u5EA6\u4E3A" + value);
7556
- } else {
7557
- resolve("\u6821\u9A8C\u901A\u8FC7");
7558
- }
7559
- });
7560
- }
7561
- };
7562
- case "minlength":
7563
- return {
7564
- type: "string",
7565
- min: value,
7566
- asyncValidator: (rule, val) => {
7567
- return new Promise((resolve, reject) => {
7568
- if (val.length < value) {
7569
- reject("\u6700\u5C0F\u957F\u5EA6\u4E3A" + value);
7570
- } else {
7571
- resolve("\u6821\u9A8C\u901A\u8FC7");
7572
- }
7573
- });
7574
- }
7575
- };
7576
- case "min":
7577
- return {
7578
- type: "number",
7579
- asyncValidator: (rule, val) => {
7580
- return new Promise((resolve, reject) => {
7581
- if (val < value) {
7582
- reject("\u6700\u5C0F\u503C\u4E3A" + value);
7583
- } else {
7584
- resolve("\u6821\u9A8C\u901A\u8FC7");
7585
- }
7586
- });
7587
- }
7588
- };
7589
- case "max":
7590
- return {
7591
- type: "number",
7592
- asyncValidator: (rule, val) => {
7593
- return new Promise((resolve, reject) => {
7594
- if (val > value) {
7595
- reject("\u6700\u5927\u503C\u4E3A" + value);
7596
- } else {
7597
- resolve("\u6821\u9A8C\u901A\u8FC7");
7598
- }
7599
- });
7600
- }
7601
- };
7602
- case "required":
7603
- return {
7604
- reqiured: true,
7605
- asyncValidator: (rule, val) => {
7606
- return new Promise((resolve, reject) => {
7607
- if (!val) {
7608
- reject("\u5FC5\u586B\u9879");
7609
- } else {
7610
- resolve("\u6821\u9A8C\u901A\u8FC7");
7611
- }
7612
- });
7613
- }
7614
- };
7615
- case "requiredTrue":
7616
- return {
7617
- asyncValidator: (rule, val) => {
7618
- return new Promise((resolve, reject) => {
7619
- if (!val) {
7620
- reject("\u5FC5\u987B\u4E3Atrue\u503C");
7621
- } else {
7622
- resolve("\u6821\u9A8C\u901A\u8FC7");
7623
- }
7624
- });
7625
- }
7626
- };
7627
- case "email":
7628
- return {
7629
- type: "email",
7630
- message: "\u90AE\u7BB1\u683C\u5F0F\u4E0D\u6B63\u786E"
7631
- };
7632
- case "pattern":
7633
- return {
7634
- type: "regexp",
7635
- pattern: value,
7636
- message: "\u53EA\u80FD\u5305\u542B\u6570\u5B57\u4E0E\u5927\u5C0F\u5199\u5B57\u7B26",
7637
- validator: (rule, val) => value.test(val)
7638
- };
7639
- case "whitespace":
7640
- return {
7641
- message: "\u8F93\u5165\u4E0D\u80FD\u5168\u90E8\u4E3A\u7A7A\u683C\u6216\u7A7A\u5B57\u7B26",
7642
- validator: (rule, val) => !!val.trim()
7643
- };
7644
- default:
7645
- return {
7646
- [ruleName]: value
7647
- };
7648
- }
7649
- }
7650
- function getKeyValueOfObjectList(obj) {
7651
- const kvArr = [];
7652
- for (const key in obj) {
7653
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
7654
- kvArr.push({
7655
- key,
7656
- value: obj[key]
7657
- });
7658
- }
7659
- }
7660
- return kvArr;
7661
- }
7662
- function handleErrorStrategy(el) {
7663
- const classList = [...el.classList];
7664
- classList.push("devui-validate-rules-error-pristine");
7665
- el.setAttribute("class", classList.join(" "));
7666
- }
7667
- function handleErrorStrategyPass(el) {
7668
- const classList = [...el.classList];
7669
- const index2 = classList.indexOf("devui-validate-rules-error-pristine");
7670
- index2 !== -1 && classList.splice(index2, 1);
7671
- el.setAttribute("class", classList.join(" "));
7672
- }
7673
- function getFormControlUID(el) {
7674
- if (el.tagName.toLocaleLowerCase() === "body") {
7675
- return "";
7676
- }
7677
- if (el.parentElement.id.startsWith("dfc-")) {
7678
- return el.parentElement.id;
7679
- } else {
7680
- getFormControlUID(el.parentElement);
7681
- }
7682
- }
7683
- function handleValidateError({ el, tipEl, message = "", isFormTag, messageShowType, dfcUID, popPosition = "right-bottom", updateOn }) {
7684
- if (isFormTag && messageShowType === "toast") {
7685
- alert(message);
7686
- return;
7687
- }
7688
- if (!dfcUID) {
7689
- dfcUID = getFormControlUID(el);
7690
- }
7691
- if (messageShowType === "popover") {
7692
- EventBus.emit("showPopoverErrorMessage", { showPopover: true, message, uid: dfcUID, popPosition, updateOn });
7693
- return;
7694
- }
7695
- tipEl.innerText = "" + message;
7696
- tipEl.style.display = "inline-flex";
7697
- tipEl.setAttribute("class", "devui-validate-tip");
7698
- handleErrorStrategy(el);
7699
- }
7700
- function handleValidatePass(el, tipEl) {
7701
- tipEl.style.display = "none";
7702
- handleErrorStrategyPass(el);
7703
- }
7704
- function getRefName(binding) {
7705
- const _refs = binding.instance.$refs;
7706
- const refName = Object.keys(_refs)[0];
7707
- return refName;
7708
- }
7709
- function getFormName(binding) {
7710
- const _refs = binding.instance.$refs;
7711
- const key = Object.keys(_refs)[0];
7712
- return _refs[key]["name"];
7713
- }
7714
- function validateFn({ validator, modelValue, el, tipEl, isFormTag, messageShowType, dfcUID, popPosition, updateOn }) {
7715
- validator.validate({ modelName: modelValue }).then(() => {
7716
- handleValidatePass(el, tipEl);
7717
- }).catch((err) => {
7718
- const { errors } = err;
7719
- if (!errors || errors.length === 0) {
7720
- return;
7721
- }
7722
- let msg = "";
7723
- if (typeof errors[0].message === "object") {
7724
- msg = errors[0].message.default;
7725
- } else {
7726
- msg = errors[0].message;
7727
- }
7728
- handleValidateError({ el, tipEl, message: msg, isFormTag, messageShowType, dfcUID, popPosition, updateOn });
7729
- });
7730
- }
7731
- function checkValidPopsition(positionStr) {
7732
- const validPosition = ["left", "right", "top", "bottom", "left-top", "left-bottom", "top-left", "top-right", "right-top", "right-bottom", "bottom-left", "bottom-right"];
7733
- const isValid = validPosition.includes(positionStr);
7734
- !isValid && console.warn(`invalid popPosition value '${positionStr}'.`);
7735
- return isValid;
7736
- }
7737
- var dValidateRules = {
7738
- mounted(el, binding, vnode) {
7739
- var _a;
7740
- const isFormTag = el.tagName === "FORM";
7741
- const dfcUID = el.parentNode.parentNode.parentElement.dataset.uid;
7742
- const refName = getRefName(binding);
7743
- const hasOptions = isObject(binding.value) && hasKey(binding.value, "options");
7744
- let {
7745
- rules: bindingRules,
7746
- options = {},
7747
- messageShowType = "popover"
7748
- } = binding.value;
7749
- let { errorStrategy } = binding.value;
7750
- if (refName) {
7751
- messageShowType = (_a = binding.instance[refName]["messageShowType"]) != null ? _a : "popover";
7752
- }
7753
- let {
7754
- updateOn = "change",
7755
- errorStrategy: ErrorStrategy = "dirty",
7756
- asyncDebounceTime = 300,
7757
- popPosition = ["right", "bottom"]
7758
- } = options;
7759
- if (messageShowType === "popover") {
7760
- if (Array.isArray(popPosition)) {
7761
- popPosition = popPosition.length > 1 ? popPosition.join("-") : popPosition[0];
7762
- if (!checkValidPopsition(popPosition)) {
7763
- popPosition = "right-bottom";
7764
- }
7765
- } else if (!checkValidPopsition(popPosition)) {
7766
- popPosition = "right-bottom";
7767
- }
7768
- }
7769
- if (!errorStrategy) {
7770
- errorStrategy = ErrorStrategy;
7771
- }
7772
- let customRule = {};
7773
- if (hasOptions) {
7774
- customRule = bindingRules != null ? bindingRules : binding.value;
7775
- } else {
7776
- customRule = binding.value;
7777
- }
7778
- const isCustomValidator = customRule && isObject(customRule) && (hasKey(customRule, "validators") || hasKey(customRule, "asyncValidators"));
7779
- const rules2 = Array.isArray(customRule) ? customRule : [customRule];
7780
- const tipEl = document.createElement("span");
7781
- if (messageShowType !== "none") {
7782
- el.parentNode.append(tipEl);
7783
- }
7784
- const descriptor = {
7785
- modelName: []
7786
- };
7787
- rules2.forEach((rule) => {
7788
- const kvObjList = !Array.isArray(rule) && getKeyValueOfObjectList(rule);
7789
- let ruleObj = {};
7790
- let avaliableRuleObj = {};
7791
- kvObjList.forEach((item) => {
7792
- avaliableRuleObj = getAvaliableRuleObj(item.key, item.value);
7793
- ruleObj = __spreadValues(__spreadValues({}, ruleObj), avaliableRuleObj);
7794
- });
7795
- descriptor.modelName.push(ruleObj);
7796
- });
7797
- if (isCustomValidator) {
7798
- const { validators: validators2, asyncValidators } = customRule;
7799
- validators2 && validators2.forEach((item) => {
7800
- const ruleObj = {
7801
- message: (item == null ? void 0 : item.message) || "",
7802
- validator: (rule, value) => item.validator(rule, value)
7803
- };
7804
- descriptor.modelName.push(ruleObj);
7805
- });
7806
- asyncValidators && asyncValidators.forEach((item) => {
7807
- const ruleObj = {
7808
- message: (item == null ? void 0 : item.message) || "",
7809
- asyncValidator: (rule, value) => {
7810
- return new Promise(lodash.exports.debounce((resolve, reject) => {
7811
- const res = item.asyncValidator(rule, value);
7812
- if (res) {
7813
- resolve("");
7814
- } else {
7815
- reject(rule.message);
7816
- }
7817
- }, asyncDebounceTime));
7818
- }
7819
- };
7820
- descriptor.modelName.push(ruleObj);
7821
- });
7822
- }
7823
- const validator = new Schema(descriptor);
7824
- const htmlEventValidateHandler = (e) => {
7825
- const modelValue = e.target.value;
7826
- if (messageShowType === "popover") {
7827
- EventBus.emit("showPopoverErrorMessage", { showPopover: false, message: "", uid: dfcUID, popPosition, updateOn });
7828
- }
7829
- validateFn({ validator, modelValue, el, tipEl, isFormTag: false, messageShowType, dfcUID, popPosition, updateOn });
7830
- };
7831
- vnode.children[0].el.addEventListener(updateOn, htmlEventValidateHandler);
7832
- if (messageShowType === "popover" && updateOn === "change") {
7833
- vnode.children[0].el.addEventListener("focus", () => {
7834
- EventBus.emit("showPopoverErrorMessage", { showPopover: false, uid: dfcUID, updateOn });
7835
- });
7836
- }
7837
- if (errorStrategy === "pristine") {
7838
- handleErrorStrategy(el);
7839
- vnode.children[0].props.value = "" + vnode.children[0].props.value;
7840
- }
7841
- const formName = getFormName(binding);
7842
- formName && EventBus.on(`formSubmit:${formName}`, () => {
7843
- const modelValue = isFormTag ? "" : vnode.children[0].el.value;
7844
- validateFn({ validator, modelValue, el, tipEl, isFormTag, messageShowType, updateOn: "submit" });
7845
- });
7846
- }
7847
- };
7848
- Form.install = function(app) {
7849
- app.component(Form.name, Form);
7850
- app.directive("d-validate-rules", dValidateRules);
7851
- };
7852
- FormLabel.install = function(app) {
7853
- app.component(FormLabel.name, FormLabel);
7854
- };
7855
- FormItem.install = function(app) {
7856
- app.component(FormItem.name, FormItem);
7857
- };
7858
- FormControl.install = function(app) {
7859
- app.component(FormControl.name, FormControl);
7860
- };
7861
- FormOperation.install = function(app) {
7862
- app.component(FormOperation.name, FormOperation);
7863
- };
7864
7727
  var index = {
7865
7728
  title: "Form \u8868\u5355",
7866
7729
  category: "\u6570\u636E\u5F55\u5165",
7867
7730
  status: "75%",
7868
7731
  install(app) {
7869
- app.use(Form);
7870
- app.use(FormLabel);
7871
- app.use(FormItem);
7872
- app.use(FormControl);
7873
- app.use(FormOperation);
7732
+ app.component(Form.name, Form);
7733
+ app.component(FormItem.name, FormItem);
7734
+ app.component(FormOperation.name, FormOperation);
7874
7735
  }
7875
7736
  };
7876
- export { Form, FormControl, FormItem, FormLabel, FormOperation, index as default };
7737
+ export { FORM_ITEM_TOKEN, FORM_TOKEN, Form, FormItem, FormOperation, LABEL_DATA, index as default, formItemProps, formProps };