@opentiny/vue-renderless 3.1.0-alpha.0

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 (397) hide show
  1. package/action-sheet/index.js +28 -0
  2. package/action-sheet/vue.js +29 -0
  3. package/alert/index.js +23 -0
  4. package/alert/vue.js +37 -0
  5. package/autocomplete/index.js +175 -0
  6. package/autocomplete/vue.js +171 -0
  7. package/avatar/index.js +29 -0
  8. package/avatar/vue.js +24 -0
  9. package/badge/index.js +16 -0
  10. package/badge/vue.js +30 -0
  11. package/breadcrumb/vue.js +4 -0
  12. package/breadcrumb-item/vue.js +24 -0
  13. package/bulletin-board/index.js +21 -0
  14. package/bulletin-board/vue.js +36 -0
  15. package/button/index.js +19 -0
  16. package/button/vue.js +43 -0
  17. package/button-group/index.js +25 -0
  18. package/button-group/vue.js +51 -0
  19. package/calendar/index.js +279 -0
  20. package/calendar/vue.js +124 -0
  21. package/card-template/index.js +39 -0
  22. package/card-template/vue.js +34 -0
  23. package/carousel/index.js +206 -0
  24. package/carousel/vue.js +222 -0
  25. package/carousel-item/index.js +93 -0
  26. package/carousel-item/vue.js +57 -0
  27. package/cascader/index.js +511 -0
  28. package/cascader/vue.js +342 -0
  29. package/cascader-menu/index.js +41 -0
  30. package/cascader-menu/vue.js +36 -0
  31. package/cascader-node/index.js +63 -0
  32. package/cascader-node/vue.js +62 -0
  33. package/cascader-panel/index.js +359 -0
  34. package/cascader-panel/node.js +199 -0
  35. package/cascader-panel/store.js +80 -0
  36. package/cascader-panel/vue.js +217 -0
  37. package/checkbox/index.js +145 -0
  38. package/checkbox/vue.js +139 -0
  39. package/checkbox-button/index.js +102 -0
  40. package/checkbox-button/vue.js +150 -0
  41. package/checkbox-group/index.js +12 -0
  42. package/checkbox-group/vue.js +33 -0
  43. package/col/index.js +132 -0
  44. package/col/vue.js +34 -0
  45. package/collapse/index.js +45 -0
  46. package/collapse/vue.js +35 -0
  47. package/collapse-item/index.js +38 -0
  48. package/collapse-item/vue.js +48 -0
  49. package/common/array.js +120 -0
  50. package/common/bigInt.js +352 -0
  51. package/common/browser.js +69 -0
  52. package/common/dataset/index.js +135 -0
  53. package/common/date.js +352 -0
  54. package/common/decimal.js +203 -0
  55. package/common/deps/ResizeObserver.js +474 -0
  56. package/common/deps/after-leave.js +25 -0
  57. package/common/deps/clickoutside.js +61 -0
  58. package/common/deps/date-util.js +262 -0
  59. package/common/deps/date.js +308 -0
  60. package/common/deps/debounce.js +4 -0
  61. package/common/deps/dom.js +190 -0
  62. package/common/deps/fullscreen/apis.js +157 -0
  63. package/common/deps/fullscreen/screenfull.js +106 -0
  64. package/common/deps/letter-only.js +15 -0
  65. package/common/deps/memorize.js +149 -0
  66. package/common/deps/number-only.js +16 -0
  67. package/common/deps/popper.js +713 -0
  68. package/common/deps/popup-manager.js +179 -0
  69. package/common/deps/repeat-click.js +24 -0
  70. package/common/deps/requestAnimationFrame.js +25 -0
  71. package/common/deps/resize-event.js +29 -0
  72. package/common/deps/scroll-into-view.js +29 -0
  73. package/common/deps/scrollbar-width.js +25 -0
  74. package/common/deps/throttle.js +34 -0
  75. package/common/deps/touch.js +33 -0
  76. package/common/deps/tree-model/node.js +586 -0
  77. package/common/deps/tree-model/tree-store.js +377 -0
  78. package/common/deps/tree-model/util.js +14 -0
  79. package/common/deps/upload-ajax.js +71 -0
  80. package/common/deps/vue-emitter.js +30 -0
  81. package/common/deps/vue-popper.js +291 -0
  82. package/common/deps/vue-popup.js +211 -0
  83. package/common/event.js +17 -0
  84. package/common/index.js +288 -0
  85. package/common/object.js +228 -0
  86. package/common/runtime.js +52 -0
  87. package/common/string.js +446 -0
  88. package/common/type.js +65 -0
  89. package/common/validate/index.js +6 -0
  90. package/common/validate/messages.js +68 -0
  91. package/common/validate/rules/enum.js +8 -0
  92. package/common/validate/rules/index.js +14 -0
  93. package/common/validate/rules/pattern.js +16 -0
  94. package/common/validate/rules/range.js +62 -0
  95. package/common/validate/rules/required.js +13 -0
  96. package/common/validate/rules/type.js +110 -0
  97. package/common/validate/rules/whitespace.js +6 -0
  98. package/common/validate/schema.js +323 -0
  99. package/common/validate/util.js +198 -0
  100. package/common/validate/validations/array.js +25 -0
  101. package/common/validate/validations/date.js +35 -0
  102. package/common/validate/validations/enum.js +24 -0
  103. package/common/validate/validations/float.js +24 -0
  104. package/common/validate/validations/index.js +42 -0
  105. package/common/validate/validations/integer.js +24 -0
  106. package/common/validate/validations/method.js +23 -0
  107. package/common/validate/validations/number.js +27 -0
  108. package/common/validate/validations/pattern.js +23 -0
  109. package/common/validate/validations/required.js +15 -0
  110. package/common/validate/validations/string.js +29 -0
  111. package/common/validate/validations/type.js +25 -0
  112. package/common/xss.js +325 -0
  113. package/container/index.js +110 -0
  114. package/container/vue.js +63 -0
  115. package/credit-card/index.js +107 -0
  116. package/credit-card/vue.js +117 -0
  117. package/credit-card-form/index.js +143 -0
  118. package/credit-card-form/vue.js +150 -0
  119. package/crop/index.js +297 -0
  120. package/crop/vue.js +191 -0
  121. package/date-panel/index.js +584 -0
  122. package/date-panel/vue.js +319 -0
  123. package/date-picker/index.js +301 -0
  124. package/date-picker/vue.js +169 -0
  125. package/date-range/index.js +463 -0
  126. package/date-range/vue.js +297 -0
  127. package/date-table/index.js +457 -0
  128. package/date-table/vue.js +151 -0
  129. package/detail-page/index.js +135 -0
  130. package/detail-page/vue.js +145 -0
  131. package/dialog-box/index.js +268 -0
  132. package/dialog-box/vue.js +226 -0
  133. package/drop-times/index.js +23 -0
  134. package/drop-times/vue.js +28 -0
  135. package/dropdown/index.js +259 -0
  136. package/dropdown/vue.js +107 -0
  137. package/dropdown-item/index.js +155 -0
  138. package/dropdown-item/vue.js +124 -0
  139. package/dropdown-menu/index.js +148 -0
  140. package/dropdown-menu/vue.js +44 -0
  141. package/exception/index.js +13 -0
  142. package/exception/vue.js +25 -0
  143. package/fall-menu/index.js +121 -0
  144. package/fall-menu/vue.js +90 -0
  145. package/file-upload/index.js +1940 -0
  146. package/file-upload/vue.js +458 -0
  147. package/floatbar/index.js +10 -0
  148. package/floatbar/vue.js +17 -0
  149. package/form/index.js +186 -0
  150. package/form/vue.js +69 -0
  151. package/form-item/index.js +364 -0
  152. package/form-item/vue.js +210 -0
  153. package/fullscreen/index.js +138 -0
  154. package/fullscreen/vue.js +77 -0
  155. package/grid/core/index.js +3 -0
  156. package/grid/core/interceptor.js +38 -0
  157. package/grid/core/storeMap.js +19 -0
  158. package/grid/plugins/export.js +169 -0
  159. package/grid/plugins/exportExcel.js +749 -0
  160. package/grid/plugins/header.js +58 -0
  161. package/grid/plugins/resize.js +82 -0
  162. package/grid/static/array/arrayEach.js +12 -0
  163. package/grid/static/array/arrayIndexOf.js +11 -0
  164. package/grid/static/array/eachTree.js +32 -0
  165. package/grid/static/array/every.js +2 -0
  166. package/grid/static/array/filterTree.js +16 -0
  167. package/grid/static/array/find.js +3 -0
  168. package/grid/static/array/findTree.js +46 -0
  169. package/grid/static/array/helperCreateIterateHandle.js +59 -0
  170. package/grid/static/array/helperCreateTreeFunc.js +18 -0
  171. package/grid/static/array/includes.js +5 -0
  172. package/grid/static/array/lastArrayEach.js +6 -0
  173. package/grid/static/array/map.js +23 -0
  174. package/grid/static/array/mapTree.js +33 -0
  175. package/grid/static/array/slice.js +10 -0
  176. package/grid/static/array/sortBy.js +69 -0
  177. package/grid/static/array/sum.js +28 -0
  178. package/grid/static/array/toArray.js +7 -0
  179. package/grid/static/array/toTreeArray.js +24 -0
  180. package/grid/static/base/clear.js +44 -0
  181. package/grid/static/base/clone.js +18 -0
  182. package/grid/static/base/destructuring.js +18 -0
  183. package/grid/static/base/each.js +9 -0
  184. package/grid/static/base/eqNull.js +6 -0
  185. package/grid/static/base/findIndexOf.js +10 -0
  186. package/grid/static/base/get.js +42 -0
  187. package/grid/static/base/has.js +60 -0
  188. package/grid/static/base/hasOwnProp.js +4 -0
  189. package/grid/static/base/helperCreateGetObjects.js +26 -0
  190. package/grid/static/base/helperCreateInInObjectString.js +7 -0
  191. package/grid/static/base/helperCreateInTypeof.js +6 -0
  192. package/grid/static/base/helperCreateIndexOf.js +21 -0
  193. package/grid/static/base/helperCreateiterateIndexOf.js +21 -0
  194. package/grid/static/base/helperDefaultCompare.js +4 -0
  195. package/grid/static/base/helperDeleteProperty.js +8 -0
  196. package/grid/static/base/helperEqualCompare.js +60 -0
  197. package/grid/static/base/helperGetHGSKeys.js +4 -0
  198. package/grid/static/base/indexOf.js +3 -0
  199. package/grid/static/base/isArray.js +3 -0
  200. package/grid/static/base/isBoolean.js +4 -0
  201. package/grid/static/base/isDate.js +3 -0
  202. package/grid/static/base/isEmpty.js +8 -0
  203. package/grid/static/base/isEqual.js +11 -0
  204. package/grid/static/base/isFunction.js +4 -0
  205. package/grid/static/base/isNaN.js +5 -0
  206. package/grid/static/base/isNull.js +4 -0
  207. package/grid/static/base/isNumber.js +4 -0
  208. package/grid/static/base/isObject.js +5 -0
  209. package/grid/static/base/isPlainObject.js +2 -0
  210. package/grid/static/base/isRegExp.js +3 -0
  211. package/grid/static/base/isSet.js +5 -0
  212. package/grid/static/base/isString.js +4 -0
  213. package/grid/static/base/isUndefined.js +4 -0
  214. package/grid/static/base/keys.js +3 -0
  215. package/grid/static/base/lastEach.js +9 -0
  216. package/grid/static/base/remove.js +44 -0
  217. package/grid/static/base/set.js +43 -0
  218. package/grid/static/base/toJSONString.js +4 -0
  219. package/grid/static/base/toStringJSON.js +13 -0
  220. package/grid/static/base/uniqueId.js +5 -0
  221. package/grid/static/browse/browse.js +54 -0
  222. package/grid/static/function/property.js +7 -0
  223. package/grid/static/function/throttle.js +43 -0
  224. package/grid/static/index.js +55 -0
  225. package/grid/static/number/helperCreateToNumber.js +12 -0
  226. package/grid/static/number/toNumber.js +3 -0
  227. package/grid/static/object/assign.js +41 -0
  228. package/grid/static/object/extend.js +3 -0
  229. package/grid/static/object/lastObjectEach.js +8 -0
  230. package/grid/static/object/objectEach.js +11 -0
  231. package/grid/static/object/objectMap.js +20 -0
  232. package/grid/static/object/values.js +9 -0
  233. package/grid/static/static/staticDocument.js +4 -0
  234. package/grid/static/static/staticHGKeyRE.js +2 -0
  235. package/grid/static/static/staticParseInt.js +2 -0
  236. package/grid/static/static/staticStrUndefined.js +2 -0
  237. package/grid/static/static/staticWindow.js +4 -0
  238. package/grid/static/string/template.js +12 -0
  239. package/grid/static/string/toString.js +12 -0
  240. package/grid/utils/column.js +72 -0
  241. package/grid/utils/common.js +155 -0
  242. package/grid/utils/dom.js +213 -0
  243. package/grid/utils/event.js +40 -0
  244. package/grid/utils/index.js +5 -0
  245. package/image/index.js +187 -0
  246. package/image/vue.js +142 -0
  247. package/image-viewer/index.js +469 -0
  248. package/image-viewer/vue.js +243 -0
  249. package/input/index.js +319 -0
  250. package/input/vue.js +319 -0
  251. package/ip-address/index.js +370 -0
  252. package/ip-address/vue.js +185 -0
  253. package/layout/vue.js +4 -0
  254. package/link/index.js +10 -0
  255. package/link/vue.js +26 -0
  256. package/link-menu/index.js +146 -0
  257. package/link-menu/vue.js +138 -0
  258. package/list/index.js +13 -0
  259. package/list/vue.js +17 -0
  260. package/loading/index.js +29 -0
  261. package/loading/vue.js +28 -0
  262. package/milestone/index.js +92 -0
  263. package/milestone/vue.js +31 -0
  264. package/mini-picker/index.js +227 -0
  265. package/mini-picker/vue.js +142 -0
  266. package/modal/index.js +866 -0
  267. package/modal/vue.js +130 -0
  268. package/month-range/index.js +169 -0
  269. package/month-range/vue.js +104 -0
  270. package/month-table/index.js +232 -0
  271. package/month-table/vue.js +72 -0
  272. package/nav-menu/index.js +457 -0
  273. package/nav-menu/vue.js +187 -0
  274. package/notify/index.js +91 -0
  275. package/notify/vue.js +67 -0
  276. package/numeric/index.js +419 -0
  277. package/numeric/vue.js +218 -0
  278. package/option/index.js +79 -0
  279. package/option/vue.js +219 -0
  280. package/option-group/index.js +18 -0
  281. package/option-group/vue.js +37 -0
  282. package/package.json +179 -0
  283. package/pager-item/index.js +122 -0
  284. package/pager-item/vue.js +52 -0
  285. package/panel/index.js +30 -0
  286. package/panel/vue.js +26 -0
  287. package/picker/index.js +1039 -0
  288. package/picker/timezone.js +974 -0
  289. package/picker/vue.js +415 -0
  290. package/picker-column/index.js +261 -0
  291. package/picker-column/vue.js +163 -0
  292. package/pop-upload/index.js +324 -0
  293. package/pop-upload/vue.js +292 -0
  294. package/popeditor/index.js +884 -0
  295. package/popeditor/vue.js +368 -0
  296. package/popover/index.js +203 -0
  297. package/popover/vue.js +174 -0
  298. package/popup/index.js +139 -0
  299. package/popup/vue.js +129 -0
  300. package/progress/index.js +174 -0
  301. package/progress/vue.js +118 -0
  302. package/pull-refresh/index.js +104 -0
  303. package/pull-refresh/vue.js +64 -0
  304. package/radio/index.js +83 -0
  305. package/radio/vue.js +99 -0
  306. package/radio-button/index.js +58 -0
  307. package/radio-button/vue.js +70 -0
  308. package/radio-group/index.js +51 -0
  309. package/radio-group/vue.js +34 -0
  310. package/rate/index.js +254 -0
  311. package/rate/vue.js +158 -0
  312. package/row/index.js +19 -0
  313. package/row/vue.js +24 -0
  314. package/scroll-text/index.js +24 -0
  315. package/scroll-text/vue.js +31 -0
  316. package/scrollbar/index.js +127 -0
  317. package/scrollbar/vue-bar.js +49 -0
  318. package/scrollbar/vue.js +43 -0
  319. package/search/index.js +110 -0
  320. package/search/vue.js +110 -0
  321. package/select/index.js +1766 -0
  322. package/select/vue.js +693 -0
  323. package/select-dropdown/index.js +23 -0
  324. package/select-dropdown/vue.js +122 -0
  325. package/slide-bar/index.js +94 -0
  326. package/slide-bar/vue.js +58 -0
  327. package/slider/index.js +434 -0
  328. package/slider/vue.js +172 -0
  329. package/split/index.js +122 -0
  330. package/split/vue.js +131 -0
  331. package/steps/vue.js +4 -0
  332. package/switch/index.js +45 -0
  333. package/switch/vue.js +62 -0
  334. package/tab-bar/index.js +51 -0
  335. package/tab-bar/vue.js +16 -0
  336. package/tab-dropdown/index.js +11 -0
  337. package/tab-dropdown/vue.js +17 -0
  338. package/tab-item/index.js +37 -0
  339. package/tab-item/vue.js +49 -0
  340. package/tab-nav/index.js +247 -0
  341. package/tab-nav/vue.js +106 -0
  342. package/tabbar/index.js +32 -0
  343. package/tabbar/vue.js +54 -0
  344. package/tabbar-item/index.js +55 -0
  345. package/tabbar-item/vue.js +53 -0
  346. package/table/index.js +111 -0
  347. package/table/vue.js +66 -0
  348. package/tabs/index.js +174 -0
  349. package/tabs/vue.js +141 -0
  350. package/tag/index.js +14 -0
  351. package/tag/vue.js +13 -0
  352. package/tall-storage/index.js +161 -0
  353. package/tall-storage/vue-storage-box.js +25 -0
  354. package/tall-storage/vue.js +38 -0
  355. package/text-popup/index.js +75 -0
  356. package/text-popup/vue.js +64 -0
  357. package/time/index.js +121 -0
  358. package/time/vue.js +124 -0
  359. package/time-line/index.js +60 -0
  360. package/time-line/vue.js +49 -0
  361. package/time-panel/index.js +189 -0
  362. package/time-panel/scrollIntoView.js +23 -0
  363. package/time-panel/vue.js +110 -0
  364. package/time-range/index.js +199 -0
  365. package/time-range/vue.js +129 -0
  366. package/time-spinner/index.js +175 -0
  367. package/time-spinner/vue.js +122 -0
  368. package/toggle-menu/index.js +104 -0
  369. package/toggle-menu/vue.js +74 -0
  370. package/tooltip/index.js +171 -0
  371. package/tooltip/vue.js +133 -0
  372. package/top-box/index.js +81 -0
  373. package/top-box/vue.js +77 -0
  374. package/transfer/index.js +296 -0
  375. package/transfer/vue.js +138 -0
  376. package/transfer-panel/index.js +364 -0
  377. package/transfer-panel/vue.js +258 -0
  378. package/tree/index.js +642 -0
  379. package/tree/vue.js +268 -0
  380. package/tree-menu/index.js +124 -0
  381. package/tree-menu/vue.js +60 -0
  382. package/tree-node/index.js +271 -0
  383. package/tree-node/vue.js +211 -0
  384. package/upload/index.js +324 -0
  385. package/upload/vue.js +93 -0
  386. package/upload-dragger/index.js +50 -0
  387. package/upload-dragger/vue.js +27 -0
  388. package/upload-list/index.js +55 -0
  389. package/upload-list/vue.js +48 -0
  390. package/user-contact/index.js +13 -0
  391. package/user-contact/vue.js +20 -0
  392. package/user-head/index.js +71 -0
  393. package/user-head/vue.js +47 -0
  394. package/wizard/index.js +123 -0
  395. package/wizard/vue.js +45 -0
  396. package/year-table/index.js +40 -0
  397. package/year-table/vue.js +23 -0
package/form/vue.js ADDED
@@ -0,0 +1,69 @@
1
+ import { watchRules, computedAutoLabelWidth, created, resetFields, clearValidate, validate, validateField, getLabelWidthIndex, registerLabelWidth, deregisterLabelWidth, updateTip, bindDialogEvent } from './index';
2
+ export var api = ['state', 'resetFields', 'clearValidate', 'validate', 'validateField', 'getLabelWidthIndex', 'registerLabelWidth', 'deregisterLabelWidth', 'updateTip'];
3
+ export var renderless = function renderless(props, _ref, _ref2) {
4
+ var computed = _ref.computed,
5
+ inject = _ref.inject,
6
+ provide = _ref.provide,
7
+ reactive = _ref.reactive,
8
+ watch = _ref.watch;
9
+ var parent = _ref2.parent;
10
+ var api = {};
11
+ var dialog = inject('dialog', null);
12
+ var state = reactive({
13
+ fields: [],
14
+ timer: null,
15
+ potentialLabelWidthArr: [],
16
+ autoLabelWidth: computed(function () {
17
+ return api.computedAutoLabelWidth();
18
+ })
19
+ });
20
+ Object.assign(api, {
21
+ state: state,
22
+ updateTip: updateTip({
23
+ props: props,
24
+ state: state
25
+ }),
26
+ computedAutoLabelWidth: computedAutoLabelWidth({
27
+ state: state
28
+ }),
29
+ created: created({
30
+ parent: parent,
31
+ state: state
32
+ }),
33
+ resetFields: resetFields({
34
+ props: props,
35
+ state: state
36
+ }),
37
+ clearValidate: clearValidate(state),
38
+ validate: validate({
39
+ props: props,
40
+ state: state
41
+ }),
42
+ validateField: validateField(state),
43
+ getLabelWidthIndex: getLabelWidthIndex(state),
44
+ registerLabelWidth: registerLabelWidth({
45
+ api: api,
46
+ state: state
47
+ }),
48
+ deregisterLabelWidth: deregisterLabelWidth({
49
+ api: api,
50
+ state: state
51
+ }),
52
+ watchRules: watchRules({
53
+ api: api,
54
+ props: props,
55
+ state: state
56
+ })
57
+ });
58
+ api.created();
59
+ provide('form', parent);
60
+ bindDialogEvent({
61
+ api: api,
62
+ dialog: dialog,
63
+ state: state
64
+ });
65
+ watch(function () {
66
+ return props.rules;
67
+ }, api.watchRules);
68
+ return api;
69
+ };
@@ -0,0 +1,364 @@
1
+ import { POSITION, VALIDATE_STATE } from '@opentiny/vue-renderless/common';
2
+ import { merge } from '@opentiny/vue-renderless/common/object';
3
+ import Validator from '@opentiny/vue-renderless/common/validate';
4
+ import { isNull } from '@opentiny/vue-renderless/common/type';
5
+ import debounce from '@opentiny/vue-renderless/common/deps/debounce';
6
+ export var watchError = function watchError(state) {
7
+ return function (value) {
8
+ if (!isNull(value) && state.getValidateType === 'tip') {
9
+ state.canShowTip = true;
10
+ }
11
+ state.validateMessage = value;
12
+ state.validateState = value ? VALIDATE_STATE.Error : '';
13
+ };
14
+ };
15
+ export var watchValidateStatus = function watchValidateStatus(state) {
16
+ return function (value) {
17
+ state.validateState = value;
18
+ };
19
+ };
20
+ export var computedGetValidateType = function computedGetValidateType(_ref) {
21
+ var props = _ref.props,
22
+ state = _ref.state;
23
+ return function () {
24
+ return props.validateType || (state.formInstance ? state.formInstance.validateType : '');
25
+ };
26
+ };
27
+ export var computedLabelStyle = function computedLabelStyle(_ref2) {
28
+ var props = _ref2.props,
29
+ state = _ref2.state;
30
+ return function () {
31
+ var result = {};
32
+ if (state.form.labelPosition === POSITION.Top) return result;
33
+ var labelWidth = props.labelWidth || state.form.labelWidth;
34
+ if (labelWidth) {
35
+ result.width = labelWidth;
36
+ }
37
+ return result;
38
+ };
39
+ };
40
+ export var computedContentStyle = function computedContentStyle(_ref3) {
41
+ var props = _ref3.props,
42
+ state = _ref3.state;
43
+ return function () {
44
+ var result = {};
45
+ var label = props.label;
46
+ if (state.form.labelPosition === POSITION.Top || state.form.inline) return result;
47
+ if (!label && !props.labelWidth && state.isNested) return result;
48
+ var labelWidth = props.labelWidth || state.form.labelWidth;
49
+ if (labelWidth === 'auto') {
50
+ if (props.labelWidth === 'auto') {
51
+ result.marginLeft = state.computedLabelWidth;
52
+ } else if (state.form.labelWidth === 'auto') {
53
+ result.marginLeft = state.formInstance.state.autoLabelWidth;
54
+ }
55
+ } else {
56
+ result.marginLeft = labelWidth;
57
+ }
58
+ return result;
59
+ };
60
+ };
61
+ export var computedForm = function computedForm(_ref4) {
62
+ var constants = _ref4.constants,
63
+ instance = _ref4.instance,
64
+ state = _ref4.state;
65
+ return function () {
66
+ var FORM_NAME = constants.FORM_NAME,
67
+ FORM_ITEM_NAME = constants.FORM_ITEM_NAME;
68
+ var parent = instance.$parent;
69
+ var parentName = parent.$options.componentName;
70
+ while (parentName !== FORM_NAME) {
71
+ if (parentName === FORM_ITEM_NAME) {
72
+ state.isNested = true;
73
+ }
74
+ parent = parent.$parent;
75
+ parentName = parent.$options.componentName;
76
+ }
77
+ return parent;
78
+ };
79
+ };
80
+ export var computedIsRequired = function computedIsRequired(_ref5) {
81
+ var api = _ref5.api,
82
+ state = _ref5.state;
83
+ return function () {
84
+ if (state.validationRequired) {
85
+ return true;
86
+ }
87
+ var rules = api.getRules();
88
+ var isRequired = false;
89
+ if (rules && rules.length) {
90
+ rules.every(function (rule) {
91
+ if (rule.required) {
92
+ isRequired = true;
93
+ return false;
94
+ }
95
+ return true;
96
+ });
97
+ }
98
+ return isRequired;
99
+ };
100
+ };
101
+ export var getPropByPath = function getPropByPath(obj, path, strict) {
102
+ var findObj = obj;
103
+ path = path.replace(/\[(\w+)\]/g, '.$1');
104
+ path = path.replace(/^\./, '');
105
+ var index = 0;
106
+ var keys = path.split('.');
107
+ for (var len = keys.length; index < len - 1; ++index) {
108
+ if (!findObj && !strict) {
109
+ break;
110
+ }
111
+ var key = keys[index];
112
+ if (key in findObj) {
113
+ findObj = findObj[key];
114
+ } else {
115
+ if (strict) {
116
+ throw new Error('[Tiny Form] please transfer a valid prop path to form item!');
117
+ }
118
+ break;
119
+ }
120
+ }
121
+ return {
122
+ o: findObj,
123
+ k: keys[index],
124
+ v: findObj ? findObj[keys[index]] : null
125
+ };
126
+ };
127
+ export var computedFieldValue = function computedFieldValue(_ref6) {
128
+ var props = _ref6.props,
129
+ state = _ref6.state;
130
+ return function () {
131
+ var model = state.form.model;
132
+ if (!model || !props.prop) {
133
+ return;
134
+ }
135
+ var path = props.prop;
136
+ if (path.indexOf(':') !== -1) {
137
+ path = path.replace(/:/, '.');
138
+ }
139
+ return getPropByPath(model, path, true).v;
140
+ };
141
+ };
142
+ export var mounted = function mounted(_ref7) {
143
+ var api = _ref7.api,
144
+ instance = _ref7.instance,
145
+ props = _ref7.props,
146
+ state = _ref7.state,
147
+ refs = _ref7.refs;
148
+ return function () {
149
+ state.tooltip = refs.tooltip;
150
+ if (props.prop) {
151
+ api.dispatch('Form', 'form:addField', instance);
152
+ var initialValue = state.fieldValue;
153
+ if (Array.isArray(initialValue)) {
154
+ initialValue = [].concat(initialValue);
155
+ }
156
+ state.initialValue = initialValue;
157
+ api.addValidateEvents();
158
+ }
159
+ };
160
+ };
161
+ export var unmounted = function unmounted(_ref8) {
162
+ var api = _ref8.api,
163
+ instance = _ref8.instance,
164
+ state = _ref8.state;
165
+ return function () {
166
+ state.canShowTip = false;
167
+ api.dispatch('Form', 'form:removeField', instance);
168
+ };
169
+ };
170
+ export var validate = function validate(_ref9) {
171
+ var api = _ref9.api,
172
+ props = _ref9.props,
173
+ state = _ref9.state,
174
+ t = _ref9.t;
175
+ return function (trigger) {
176
+ var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
177
+ return undefined;
178
+ };
179
+ state.validateDisabled = false;
180
+ var rules = api.getFilteredRule(trigger);
181
+ if ((!rules || rules.length === 0) && props.required === undefined) {
182
+ callback();
183
+ return true;
184
+ }
185
+ state.validateState = VALIDATE_STATE.Validating;
186
+ var descriptor = {};
187
+ if (rules && rules.length > 0) {
188
+ rules.forEach(function (rule) {
189
+ delete rule.trigger;
190
+ });
191
+ }
192
+ descriptor[props.prop] = rules;
193
+ var validator = new Validator(descriptor, t);
194
+ var model = {};
195
+ model[props.prop] = state.fieldValue;
196
+ validator.validate(model, {
197
+ firstFields: true
198
+ }, function (errors, invalidFields) {
199
+ api.clearValidate();
200
+ var handlerError = function handlerError() {
201
+ state.validateState = !errors ? VALIDATE_STATE.Success : VALIDATE_STATE.Error;
202
+ state.validateMessage = errors ? errors[0].message : '';
203
+ state.canShowTip = !!errors;
204
+ callback(state.validateMessage, invalidFields);
205
+ state.formInstance && state.formInstance.$emit('validate', props.prop, !errors, state.validateMessage || null);
206
+ };
207
+ if (errors && state.stowed[0] === errors[0].field) {
208
+ handlerError();
209
+ return;
210
+ }
211
+ errors && (state.stowed[0] = errors[0].field);
212
+ handlerError();
213
+ });
214
+ };
215
+ };
216
+ export var clearValidate = function clearValidate(state) {
217
+ return function () {
218
+ state.validateState = '';
219
+ state.validateMessage = '';
220
+ state.validateDisabled = false;
221
+ };
222
+ };
223
+ export var resetField = function resetField(_ref10) {
224
+ var api = _ref10.api,
225
+ nextTick = _ref10.nextTick,
226
+ props = _ref10.props,
227
+ state = _ref10.state;
228
+ return function () {
229
+ if (state.getValidateType === 'tip') {
230
+ state.canShowTip = false;
231
+ }
232
+ state.validateState = '';
233
+ state.validateMessage = '';
234
+ var model = state.form.model;
235
+ var value = state.fieldValue;
236
+ var path = props.prop;
237
+ if (path.indexOf(':') !== -1) {
238
+ path = path.replace(/:/, '.');
239
+ }
240
+ var prop = getPropByPath(model, path, true);
241
+ state.validateDisabled = true;
242
+ if (Array.isArray(value)) {
243
+ prop.o[prop.k] = [].concat(state.initialValue);
244
+ } else {
245
+ prop.o[prop.k] = state.initialValue;
246
+ }
247
+ nextTick(function () {
248
+ state.validateDisabled = false;
249
+ });
250
+ setTimeout(function () {
251
+ return state.validateState && (state.validateState = '');
252
+ });
253
+ api.broadcast('timeSelect', 'fieldReset', state.initialValue);
254
+ };
255
+ };
256
+ export var getRules = function getRules(_ref11) {
257
+ var props = _ref11.props,
258
+ state = _ref11.state;
259
+ return function () {
260
+ var formRules = state.form.rules;
261
+ var selfRules = props.rules;
262
+ var requiredRule = props.required !== undefined ? {
263
+ required: !!props.required
264
+ } : [];
265
+ var prop = getPropByPath(formRules, props.prop || '');
266
+ formRules = formRules ? prop.o[props.prop || ''] || prop.v : [];
267
+ return [].concat(selfRules || formRules || []).concat(requiredRule);
268
+ };
269
+ };
270
+ export var getFilteredRule = function getFilteredRule(api) {
271
+ return function (trigger) {
272
+ var rules = api.getRules();
273
+ return rules.filter(function (rule) {
274
+ if (!rule.trigger || trigger === '') return true;
275
+ if (Array.isArray(rule.trigger)) {
276
+ return rule.trigger.indexOf(trigger) > -1;
277
+ }
278
+ return rule.trigger === trigger;
279
+ }).map(function (rule) {
280
+ return merge({}, rule);
281
+ });
282
+ };
283
+ };
284
+ export var onFieldBlur = function onFieldBlur(api) {
285
+ return function () {
286
+ api.validate('blur');
287
+ };
288
+ };
289
+ export var onFieldChange = function onFieldChange(_ref12) {
290
+ var api = _ref12.api,
291
+ state = _ref12.state;
292
+ return function () {
293
+ if (state.validateDisabled) {
294
+ state.validateDisabled = false;
295
+ return;
296
+ }
297
+ api.validate('change');
298
+ };
299
+ };
300
+ export var updateComputedLabelWidth = function updateComputedLabelWidth(state) {
301
+ return function (width) {
302
+ state.computedLabelWidth = width ? "".concat(width, "px") : '';
303
+ };
304
+ };
305
+ export var addValidateEvents = function addValidateEvents(_ref13) {
306
+ var api = _ref13.api,
307
+ instance = _ref13.instance,
308
+ props = _ref13.props,
309
+ state = _ref13.state;
310
+ return function () {
311
+ var rules = api.getRules();
312
+ if (rules.length || props.required !== undefined) {
313
+ var manual = props.manual || (state.formInstance ? state.formInstance.manual : false);
314
+ if (!manual) {
315
+ instance.$on('form.blur', api.onFieldBlur);
316
+ instance.$on('form.change', api.onFieldChange);
317
+ }
318
+ }
319
+ };
320
+ };
321
+ export var removeValidateEvents = function removeValidateEvents(instance) {
322
+ return function () {
323
+ instance.$off();
324
+ };
325
+ };
326
+ export var updateTip = function updateTip(_ref14) {
327
+ var refs = _ref14.refs,
328
+ state = _ref14.state;
329
+ return function () {
330
+ if (state.getValidateType !== 'tip' && !state.canShowTip) {
331
+ return;
332
+ }
333
+ var tooltip = refs.tooltip;
334
+ if (!tooltip) {
335
+ return;
336
+ }
337
+ tooltip.updatePopper();
338
+ };
339
+ };
340
+ export var getValueByPath = function getValueByPath(object, prop) {
341
+ prop = prop || '';
342
+ var paths = prop.split('.');
343
+ var current = object;
344
+ var result = null;
345
+ for (var i = 0, len = paths.length; i < len; i++) {
346
+ var path = paths[i];
347
+ if (!current) break;
348
+ if (i === len - 1) {
349
+ result = current[path];
350
+ break;
351
+ }
352
+ current = current[path];
353
+ }
354
+ return result;
355
+ };
356
+ export var wrapValidate = function wrapValidate(_ref15) {
357
+ var validateFunc = _ref15.validateFunc,
358
+ props = _ref15.props;
359
+ if (props.validateDebounce) {
360
+ return debounce(50, validateFunc);
361
+ } else {
362
+ return validateFunc;
363
+ }
364
+ };
@@ -0,0 +1,210 @@
1
+ import { validate, clearValidate, resetField, getRules, getFilteredRule, onFieldBlur, onFieldChange, updateComputedLabelWidth, addValidateEvents, removeValidateEvents, mounted, unmounted, watchError, watchValidateStatus, computedLabelStyle, computedContentStyle, computedForm, computedIsRequired, computedFieldValue, computedGetValidateType, updateTip, wrapValidate } from './index';
2
+ export var api = ['state', 'validate', 'clearValidate', 'resetField', 'getRules', 'getFilteredRule', 'onFieldBlur', 'onFieldChange', 'updateComputedLabelWidth', 'addValidateEvents', 'removeValidateEvents', 'updateTip'];
3
+ var initState = function initState(_ref) {
4
+ var reactive = _ref.reactive,
5
+ computed = _ref.computed,
6
+ api = _ref.api,
7
+ mode = _ref.mode,
8
+ inject = _ref.inject,
9
+ props = _ref.props;
10
+ var state = reactive({
11
+ mode: mode,
12
+ validateState: '',
13
+ validateMessage: '',
14
+ validateDisabled: false,
15
+ validator: {},
16
+ stowed: [],
17
+ isNested: false,
18
+ computedLabelWidth: '',
19
+ initialValue: null,
20
+ canShowTip: false,
21
+ validationRequired: false,
22
+ tooltip: null,
23
+ formInstance: inject('form', null),
24
+ labelFor: computed(function () {
25
+ return props["for"] || props.prop;
26
+ }),
27
+ labelStyle: computed(function () {
28
+ return api.computedLabelStyle();
29
+ }),
30
+ contentStyle: computed(function () {
31
+ return api.computedContentStyle();
32
+ }),
33
+ form: computed(function () {
34
+ return api.computedForm();
35
+ }),
36
+ fieldValue: computed(function () {
37
+ return api.computedFieldValue();
38
+ }),
39
+ isRequired: computed(function () {
40
+ return api.computedIsRequired();
41
+ }),
42
+ formSize: computed(function () {
43
+ return state.formInstance.size;
44
+ }),
45
+ formItemSize: computed(function () {
46
+ return props.size || state.formSize;
47
+ }),
48
+ sizeClass: computed(function () {
49
+ return state.formItemSize;
50
+ }),
51
+ getValidateType: computed(function () {
52
+ return api.computedGetValidateType();
53
+ })
54
+ });
55
+ return state;
56
+ };
57
+ var initApi = function initApi(_ref2) {
58
+ var api = _ref2.api,
59
+ state = _ref2.state,
60
+ dispatch = _ref2.dispatch,
61
+ broadcast = _ref2.broadcast,
62
+ refs = _ref2.refs,
63
+ props = _ref2.props,
64
+ constants = _ref2.constants,
65
+ instance = _ref2.instance,
66
+ t = _ref2.t,
67
+ nextTick = _ref2.nextTick;
68
+ Object.assign(api, {
69
+ state: state,
70
+ dispatch: dispatch,
71
+ broadcast: broadcast,
72
+ watchError: watchError(state),
73
+ updateTip: updateTip({
74
+ refs: refs,
75
+ state: state
76
+ }),
77
+ watchValidateStatus: watchValidateStatus(state),
78
+ computedLabelStyle: computedLabelStyle({
79
+ props: props,
80
+ state: state
81
+ }),
82
+ computedContentStyle: computedContentStyle({
83
+ props: props,
84
+ state: state
85
+ }),
86
+ computedForm: computedForm({
87
+ constants: constants,
88
+ instance: instance,
89
+ state: state
90
+ }),
91
+ computedFieldValue: computedFieldValue({
92
+ props: props,
93
+ state: state
94
+ }),
95
+ computedGetValidateType: computedGetValidateType({
96
+ props: props,
97
+ state: state
98
+ }),
99
+ clearValidate: clearValidate(state),
100
+ getRules: getRules({
101
+ props: props,
102
+ state: state
103
+ }),
104
+ updateComputedLabelWidth: updateComputedLabelWidth(state),
105
+ removeValidateEvents: removeValidateEvents(instance),
106
+ unmounted: unmounted({
107
+ api: api,
108
+ instance: instance,
109
+ state: state
110
+ }),
111
+ mounted: mounted({
112
+ api: api,
113
+ instance: instance,
114
+ props: props,
115
+ state: state,
116
+ refs: refs
117
+ }),
118
+ computedIsRequired: computedIsRequired({
119
+ api: api,
120
+ state: state
121
+ }),
122
+ resetField: resetField({
123
+ api: api,
124
+ nextTick: nextTick,
125
+ props: props,
126
+ state: state
127
+ }),
128
+ getFilteredRule: getFilteredRule(api),
129
+ onFieldBlur: onFieldBlur(api),
130
+ onFieldChange: onFieldChange({
131
+ api: api,
132
+ state: state
133
+ }),
134
+ addValidateEvents: addValidateEvents({
135
+ api: api,
136
+ instance: instance,
137
+ props: props,
138
+ state: state
139
+ }),
140
+ validate: wrapValidate({
141
+ validateFunc: validate({
142
+ api: api,
143
+ props: props,
144
+ state: state,
145
+ t: t
146
+ }),
147
+ props: props
148
+ })
149
+ });
150
+ };
151
+ var initWatch = function initWatch(_ref3) {
152
+ var watch = _ref3.watch,
153
+ api = _ref3.api,
154
+ props = _ref3.props;
155
+ watch(function () {
156
+ return props.error;
157
+ }, api.watchError, {
158
+ immediate: true
159
+ });
160
+ watch(function () {
161
+ return props.validateStatus;
162
+ }, api.watchValidateStatus);
163
+ };
164
+ export var renderless = function renderless(props, _ref4, _ref5) {
165
+ var computed = _ref4.computed,
166
+ inject = _ref4.inject,
167
+ onMounted = _ref4.onMounted,
168
+ onUnmounted = _ref4.onUnmounted,
169
+ provide = _ref4.provide,
170
+ reactive = _ref4.reactive,
171
+ watch = _ref4.watch;
172
+ var instance = _ref5.vm,
173
+ constants = _ref5.constants,
174
+ t = _ref5.t,
175
+ nextTick = _ref5.nextTick,
176
+ refs = _ref5.refs,
177
+ broadcast = _ref5.broadcast,
178
+ dispatch = _ref5.dispatch,
179
+ mode = _ref5.mode;
180
+ var api = {};
181
+ var state = initState({
182
+ reactive: reactive,
183
+ computed: computed,
184
+ api: api,
185
+ mode: mode,
186
+ inject: inject,
187
+ props: props
188
+ });
189
+ provide('formItem', instance);
190
+ initApi({
191
+ api: api,
192
+ state: state,
193
+ dispatch: dispatch,
194
+ broadcast: broadcast,
195
+ refs: refs,
196
+ props: props,
197
+ constants: constants,
198
+ instance: instance,
199
+ t: t,
200
+ nextTick: nextTick
201
+ });
202
+ initWatch({
203
+ watch: watch,
204
+ api: api,
205
+ props: props
206
+ });
207
+ onMounted(api.mounted);
208
+ onUnmounted(api.unmounted);
209
+ return api;
210
+ };