@opentiny/vue-renderless 3.13.1 → 3.14.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 (321) hide show
  1. package/action-sheet/index.js +20 -13
  2. package/action-sheet/vue.js +8 -7
  3. package/amount/index.js +100 -25
  4. package/amount/vue.js +102 -26
  5. package/anchor/index.js +1 -0
  6. package/area/index.js +8 -8
  7. package/area/vue.js +5 -5
  8. package/async-flowchart/index.js +16 -3
  9. package/autocomplete/index.js +58 -14
  10. package/autocomplete/vue.js +40 -12
  11. package/badge/index.js +12 -0
  12. package/badge/vue.js +6 -4
  13. package/breadcrumb/vue.js +3 -1
  14. package/breadcrumb-item/vue.js +6 -2
  15. package/button/index.js +5 -1
  16. package/calendar/index.js +2 -86
  17. package/calendar-bar/index.js +18 -4
  18. package/calendar-view/index.js +5 -1
  19. package/calendar-view/vue.js +16 -3
  20. package/card-group/vue.js +4 -2
  21. package/cascader/index.js +86 -34
  22. package/cascader/vue.js +61 -20
  23. package/cascader-menu/index.js +7 -7
  24. package/cascader-menu/vue.js +2 -3
  25. package/cascader-mobile/index.js +36 -23
  26. package/cascader-mobile/vue.js +6 -0
  27. package/cascader-node/index.js +13 -1
  28. package/cascader-node/vue.js +15 -4
  29. package/cascader-panel/index.js +1 -1
  30. package/cascader-select/column-index.js +150 -0
  31. package/cascader-select/column.js +120 -0
  32. package/cascader-select/index.js +29 -165
  33. package/cascader-select/usePicker.js +251 -0
  34. package/cascader-select/useTouch.js +65 -0
  35. package/cascader-select/vue.js +35 -47
  36. package/cell/vue.js +2 -1
  37. package/chart-bar/index.js +2 -3
  38. package/chart-core/deps/constants.js +43 -43
  39. package/chart-core/index.js +1 -1
  40. package/chart-gauge/index.js +2 -2
  41. package/chart-heatmap/index.js +17 -10
  42. package/chart-line/index.js +8 -9
  43. package/chart-tree/index.js +2 -2
  44. package/chart-waterfall/index.js +4 -6
  45. package/checkbox/index.js +18 -1
  46. package/checkbox/vue.js +15 -7
  47. package/checkbox-group/vue.js +1 -0
  48. package/col/vue.js +1 -1
  49. package/collapse/index.js +3 -3
  50. package/color-select-panel/vue.js +0 -7
  51. package/column-list-item/index.js +17 -1
  52. package/column-list-item/vue.js +8 -3
  53. package/common/date.js +7 -5
  54. package/common/deps/clickoutside.js +6 -2
  55. package/common/deps/dom.js +19 -4
  56. package/common/deps/popper.js +44 -11
  57. package/common/deps/resize-event.js +1 -0
  58. package/common/deps/touch-emulator.js +4 -1
  59. package/common/deps/tree-model/node.js +2 -2
  60. package/common/deps/tree-model/tree-store.js +2 -13
  61. package/common/deps/useRect.js +25 -0
  62. package/common/deps/vue-popper.js +38 -20
  63. package/common/index.js +2 -2
  64. package/common/runtime.js +1 -1
  65. package/common/string.js +2 -2
  66. package/common/type.js +2 -1
  67. package/common/validate/rules/enum.js +1 -1
  68. package/common/validate/rules/pattern.js +2 -2
  69. package/common/validate/rules/range.js +8 -5
  70. package/common/validate/rules/required.js +1 -1
  71. package/common/validate/rules/type.js +5 -5
  72. package/common/validate/rules/whitespace.js +1 -1
  73. package/common/validate/util.js +15 -16
  74. package/common/validate/validations/integer.js +1 -1
  75. package/common/validate/validations/method.js +1 -1
  76. package/currency/index.js +74 -7
  77. package/currency/vue.js +21 -5
  78. package/date-panel/index.js +16 -0
  79. package/date-panel/vue.js +8 -2
  80. package/date-picker-mobile/index.js +12 -0
  81. package/date-picker-mobile/vue.js +7 -1
  82. package/date-range/vue.js +14 -6
  83. package/date-table/index.js +5 -0
  84. package/date-table/vue.js +3 -1
  85. package/dialog-box/index.js +46 -14
  86. package/dialog-box/vue.js +30 -7
  87. package/dialog-select/index.js +6 -3
  88. package/dialog-select/vue.js +8 -4
  89. package/drawer/index.js +27 -5
  90. package/drawer/vue.js +14 -7
  91. package/dropdown/index.js +7 -7
  92. package/dropdown/vue.js +6 -2
  93. package/dropdown-item/index.js +9 -1
  94. package/dropdown-item/mf.js +6 -10
  95. package/dropdown-item/vue.js +20 -7
  96. package/dropdown-menu/index.js +20 -7
  97. package/dropdown-menu/vue.js +4 -3
  98. package/exception/index.js +2 -7
  99. package/exception/vue.js +7 -10
  100. package/fall-menu/index.js +5 -1
  101. package/fall-menu/vue.js +13 -2
  102. package/file-upload/index.js +68 -18
  103. package/file-upload/vue.js +38 -8
  104. package/filter-box/index.js +1 -0
  105. package/float-button/index.js +42 -0
  106. package/float-button/vue.js +101 -0
  107. package/floating-button/index.js +62 -16
  108. package/floating-button/vue.js +27 -9
  109. package/flowchart/index.js +134 -25
  110. package/flowchart/node.js +13 -4
  111. package/flowchart/vue.js +16 -4
  112. package/form/vue.js +8 -0
  113. package/form-item/index.js +5 -5
  114. package/form-item/vue.js +3 -1
  115. package/fullscreen/index.js +5 -5
  116. package/fullscreen/vue.js +3 -3
  117. package/grid/plugins/export.js +5 -2
  118. package/grid/utils/column.js +1 -0
  119. package/grid/utils/dom.js +7 -1
  120. package/image/index.js +6 -1
  121. package/image/vue.js +6 -3
  122. package/image-viewer/index.js +62 -51
  123. package/image-viewer/vue.js +17 -5
  124. package/input/index.js +81 -20
  125. package/input/vue.js +44 -18
  126. package/ip-address/index.js +61 -19
  127. package/ip-address/vue.js +22 -4
  128. package/link/vue.js +3 -1
  129. package/loading/index.js +2 -2
  130. package/loading/vue.js +8 -2
  131. package/logout/index.js +1 -1
  132. package/menu/index.js +15 -2
  133. package/menu/vue.js +22 -17
  134. package/mind-map/index.js +47 -0
  135. package/mind-map/vue.js +53 -0
  136. package/modal/index.js +44 -4
  137. package/modal/vue.js +18 -4
  138. package/multi-select/index.js +186 -11
  139. package/multi-select/vue.js +60 -15
  140. package/multi-select-item/index.js +23 -0
  141. package/multi-select-item/vue.js +31 -0
  142. package/numeric/index.js +46 -12
  143. package/numeric/vue.js +44 -19
  144. package/option/index.js +27 -9
  145. package/option/vue.js +37 -21
  146. package/option-group/index.js +3 -3
  147. package/package.json +1 -1
  148. package/pager/index.js +18 -4
  149. package/pager/vue.js +16 -5
  150. package/picker/index.js +258 -49
  151. package/picker/mb.js +42 -0
  152. package/picker/vue.js +70 -17
  153. package/picker-column/index.js +1 -1
  154. package/pop-upload/vue.js +3 -0
  155. package/popconfirm/index.js +3 -6
  156. package/popconfirm/vue.js +1 -1
  157. package/popeditor/index.js +71 -32
  158. package/popeditor/vue.js +15 -11
  159. package/popover/index.js +4 -4
  160. package/popover/vue.js +6 -6
  161. package/popup/index.js +3 -3
  162. package/popup/vue.js +5 -5
  163. package/pull-refresh/index.js +13 -13
  164. package/pull-refresh/vue.js +5 -4
  165. package/radio/index.js +0 -17
  166. package/radio/vue.js +4 -10
  167. package/rate/index.js +1 -1
  168. package/rate/vue.js +0 -2
  169. package/record/index.js +4 -1
  170. package/rich-text/clipboard.js +54 -0
  171. package/rich-text/index.js +192 -0
  172. package/rich-text/module/file-upload.js +107 -0
  173. package/rich-text/module/image-drop.js +63 -0
  174. package/rich-text/module/image-upload.js +89 -0
  175. package/rich-text/options.js +141 -0
  176. package/rich-text/table-module.js +382 -0
  177. package/rich-text/vue.js +102 -0
  178. package/{rich-text-edtior → rich-text-editor}/index.js +2 -2
  179. package/{rich-text-edtior → rich-text-editor}/vue.js +2 -5
  180. package/scrollbar/index.js +11 -11
  181. package/scrollbar/vue-bar.js +3 -3
  182. package/scrollbar/vue.js +5 -5
  183. package/search/index.js +9 -9
  184. package/search/vue.js +8 -6
  185. package/select/index.js +457 -389
  186. package/select/vue.js +257 -161
  187. package/select-dropdown/index.js +61 -3
  188. package/select-dropdown/vue.js +85 -8
  189. package/select-view/index.js +3 -1
  190. package/selected-box/index.js +2 -0
  191. package/selected-box/vue.js +6 -3
  192. package/signature/index.js +241 -0
  193. package/signature/vue.js +88 -0
  194. package/skeleton/index.js +14 -0
  195. package/skeleton/vue.js +15 -0
  196. package/skeleton-item/vue.js +15 -0
  197. package/slider/index.js +70 -17
  198. package/slider/vue.js +16 -7
  199. package/split/index.js +5 -3
  200. package/split/vue.js +4 -6
  201. package/standard-list-item/index.js +15 -1
  202. package/standard-list-item/vue.js +6 -5
  203. package/steps/index.js +25 -2
  204. package/steps/slide-bar.js +8 -1
  205. package/steps/vue.js +15 -3
  206. package/tab-item-mf/vue.js +14 -8
  207. package/tab-nav/index.js +30 -5
  208. package/tab-nav/vue.js +16 -4
  209. package/tabbar/vue.js +9 -3
  210. package/tabbar-item/vue.js +3 -2
  211. package/tabs/index.js +16 -4
  212. package/tabs/vue.js +2 -1
  213. package/tabs-mf/index.js +20 -6
  214. package/tabs-mf/vue-nav.js +26 -11
  215. package/tabs-mf/vue.js +7 -7
  216. package/tabs-mf/wheel.js +1 -0
  217. package/tag/index.js +1 -1
  218. package/tag-group/index.js +2 -1
  219. package/time/index.js +5 -2
  220. package/time/vue.js +1 -1
  221. package/time-line/index.js +3 -3
  222. package/time-line/vue.js +2 -2
  223. package/time-picker-mobile/index.js +24 -5
  224. package/time-picker-mobile/vue.js +17 -7
  225. package/time-range/index.js +2 -0
  226. package/timeline-item/vue.js +1 -1
  227. package/tooltip/index.js +6 -3
  228. package/tooltip/vue.js +4 -4
  229. package/transfer/index.js +20 -22
  230. package/transfer/vue.js +1 -6
  231. package/transfer-panel/vue.js +3 -5
  232. package/tree/index.js +21 -4
  233. package/tree/vue.js +10 -8
  234. package/tree-menu/index.js +31 -5
  235. package/tree-menu/vue.js +28 -15
  236. package/tree-node/index.js +18 -18
  237. package/tree-node/vue.js +6 -5
  238. package/types/action-sheet.type.d.ts +118 -1
  239. package/types/alert.type.d.ts +1 -1
  240. package/types/amount.type.d.ts +168 -1
  241. package/types/area.type.d.ts +134 -1
  242. package/types/async-flowchart.type.d.ts +72 -0
  243. package/types/autocomplete.type.d.ts +199 -1
  244. package/types/badge.type.d.ts +3 -1
  245. package/types/breadcrumb-item.type.d.ts +2 -0
  246. package/types/breadcrumb.type.d.ts +2 -0
  247. package/types/button-group.type.d.ts +3 -3
  248. package/types/button.type.d.ts +4 -0
  249. package/types/cascader-menu.type.d.ts +3 -4
  250. package/types/cascader-node.type.d.ts +5 -2
  251. package/types/cascader-panel.type-2bd03be3.d.ts +241 -0
  252. package/types/cascader-panel.type.d.ts +3 -241
  253. package/types/cascader.type.d.ts +329 -1
  254. package/types/checkbox.type.d.ts +9 -3
  255. package/types/collapse.type.d.ts +20 -3
  256. package/types/date-picker.type.d.ts +37 -0
  257. package/types/dialog-box.type.d.ts +13 -3
  258. package/types/drawer.type.d.ts +133 -1
  259. package/types/{dropdown-item.type-8ea6c633.d.ts → dropdown-item.type-8475a549.d.ts} +7 -13
  260. package/types/dropdown-item.type.d.ts +1 -1
  261. package/types/dropdown-menu.type.d.ts +1 -1
  262. package/types/dropdown.type.d.ts +1 -5
  263. package/types/fall-menu.type.d.ts +94 -1
  264. package/types/file-upload.type.d.ts +1 -1
  265. package/types/float-button.type.d.ts +123 -0
  266. package/types/form-item.type.d.ts +1 -1
  267. package/types/{form.type-d0fd42f3.d.ts → form.type-222799ae.d.ts} +5 -2
  268. package/types/form.type.d.ts +1 -1
  269. package/types/{index-e0250f63.d.ts → index-b012f687.d.ts} +9 -0
  270. package/types/input.type.d.ts +1 -5
  271. package/types/ip-address.type.d.ts +160 -1
  272. package/types/link.type.d.ts +6 -3
  273. package/types/loading.type.d.ts +7 -0
  274. package/types/milestone.type.d.ts +1 -1
  275. package/types/mind-map.type.d.ts +20 -0
  276. package/types/modal.type.d.ts +29 -2
  277. package/types/numeric.type.d.ts +41 -10
  278. package/types/pager.type.d.ts +13 -1
  279. package/types/picker.type.d.ts +18 -0
  280. package/types/popconfirm.type.d.ts +86 -1
  281. package/types/popeditor.type.d.ts +5 -1
  282. package/types/popover.type.d.ts +3 -3
  283. package/types/progress.type.d.ts +3 -1
  284. package/types/radio.type.d.ts +0 -4
  285. package/types/rate.type.d.ts +236 -1
  286. package/types/search.type.d.ts +88 -1
  287. package/types/shared.type.d.ts +1 -1
  288. package/types/skeleton-item.type.d.ts +38 -0
  289. package/types/skeleton.type.d.ts +45 -0
  290. package/types/slider.type.d.ts +49 -10
  291. package/types/steps.type.d.ts +15 -4
  292. package/types/switch.type.d.ts +3 -3
  293. package/types/tab-bar.type.d.ts +1 -1
  294. package/types/tab-nav.type.d.ts +7 -2
  295. package/types/tabs.type.d.ts +9 -1
  296. package/types/tag-group.type.d.ts +64 -1
  297. package/types/{time-line.type-d7daa669.d.ts → time-line.type-b155cb4f.d.ts} +12 -0
  298. package/types/time-line.type.d.ts +1 -1
  299. package/types/timeline-item.type.d.ts +1 -1
  300. package/types/tooltip.type.d.ts +2 -2
  301. package/types/transfer.type.d.ts +185 -1
  302. package/types/tree-menu.type.d.ts +210 -1
  303. package/types/upload-dragger.type.d.ts +2 -2
  304. package/types/{upload-list.type-343e8c11.d.ts → upload-list.type-a29aea50.d.ts} +31 -8
  305. package/types/upload-list.type.d.ts +1 -1
  306. package/types/upload.type.d.ts +1 -1
  307. package/types/user-head.type.d.ts +146 -1
  308. package/types/wizard.type.d.ts +1 -0
  309. package/upload/index.js +64 -34
  310. package/upload/vue.js +9 -5
  311. package/upload-dragger/index.js +22 -20
  312. package/upload-list/index.js +24 -18
  313. package/upload-list/vue.js +9 -4
  314. package/user/index.js +34 -25
  315. package/user/vue.js +1 -1
  316. package/user-head/index.js +3 -3
  317. package/watermark/index.js +11 -0
  318. package/wheel/index.js +3 -0
  319. package/wizard/vue.js +4 -2
  320. package/common/deps/modal-queue.js +0 -6
  321. package/common/deps/requestAnimationFrame.js +0 -25
@@ -1,7 +1,30 @@
1
1
  import "../chunk-G2ADBYYC.js";
2
- import { mounted } from "./index";
2
+ import {
3
+ mounted,
4
+ closeModal,
5
+ handleQueryChange,
6
+ toggleSelectedBox,
7
+ deleteSelected,
8
+ selectedBoxConfirm,
9
+ selectDropdownConfirm,
10
+ cancelSearch,
11
+ handleClear
12
+ } from "./index";
3
13
  import userPopper from "../common/deps/vue-popper";
4
- const api = ["state", "doDestroy"];
14
+ import PopupManager from "../common/deps/popup-manager";
15
+ import debounce from "../common/deps/debounce";
16
+ const api = [
17
+ "state",
18
+ "doDestroy",
19
+ "closeModal",
20
+ "debouncedQueryChange",
21
+ "toggleSelectedBox",
22
+ "deleteSelected",
23
+ "selectedBoxConfirm",
24
+ "selectDropdownConfirm",
25
+ "cancelSearch",
26
+ "handleClear"
27
+ ];
5
28
  const initState = ({ reactive, computed, popper, selectVm }) => {
6
29
  const { showPopper, currentPlacement, popperElm, referenceElm } = popper;
7
30
  const state = reactive({
@@ -10,16 +33,43 @@ const initState = ({ reactive, computed, popper, selectVm }) => {
10
33
  popperElm,
11
34
  referenceElm,
12
35
  minWidth: "",
36
+ query: "",
37
+ showSelectedBox: false,
38
+ debounce: 300,
39
+ selectedArr: [],
40
+ deletedArr: [],
41
+ originValue: [],
42
+ showClose: computed(() => selectVm.clearable && !selectVm.multiple && selectVm.modelValue !== ""),
43
+ filterable: computed(() => selectVm.filterable),
13
44
  multiple: computed(() => selectVm.multiple),
14
- popperClass: computed(() => selectVm.popperClass)
45
+ popperClass: computed(() => selectVm.popperClass),
46
+ selected: computed(
47
+ () => selectVm.renderType === "tree" && !selectVm.treeOp.checkStrictly ? selectVm.state.selected.filter((item) => !item.children) : selectVm.state.selected
48
+ ),
49
+ device: computed(() => selectVm.state.device),
50
+ visible: false,
51
+ windowScrollTop: 0,
52
+ zIndex: 2e3,
53
+ valueField: computed(() => selectVm.renderType === "tree" ? "id" : "value")
15
54
  });
16
55
  return state;
17
56
  };
18
- const initApi = ({ api: api2, popper, state, selectEmitter, constants, selectVm, parent }) => {
57
+ const initApi = ({ api: api2, popper, state, selectEmitter, constants, selectVm, parent, nextTick, props }) => {
19
58
  const { destroyPopper, doDestroy, updatePopper } = popper;
20
59
  Object.assign(api2, {
21
60
  state,
22
61
  doDestroy,
62
+ handleQueryChange: handleQueryChange({ state, selectVm }),
63
+ debouncedQueryChange: debounce(state.debounce, (value) => {
64
+ api2.handleQueryChange(value);
65
+ }),
66
+ toggleSelectedBox: toggleSelectedBox({ state }),
67
+ deleteSelected: deleteSelected({ state }),
68
+ selectedBoxConfirm: selectedBoxConfirm({ state, selectVm, nextTick }),
69
+ selectDropdownConfirm: selectDropdownConfirm({ state, selectVm }),
70
+ closeModal: closeModal({ state, selectVm, props }),
71
+ cancelSearch: cancelSearch({ api: api2, state, selectVm }),
72
+ handleClear: handleClear({ state, selectVm }),
23
73
  mounted: mounted({ selectEmitter, constants, state, selectVm, updatePopper, destroyPopper, parent })
24
74
  });
25
75
  };
@@ -33,8 +83,35 @@ const initWatch = ({ watch, selectVm, state, nextTick }) => {
33
83
  },
34
84
  { immediate: true }
35
85
  );
86
+ watch(
87
+ () => state.query,
88
+ (val) => {
89
+ selectVm.state.queryValue = val;
90
+ }
91
+ );
92
+ watch(
93
+ () => selectVm.state.visible,
94
+ (val) => {
95
+ state.query = "";
96
+ setTimeout(() => {
97
+ state.visible = val;
98
+ state.zIndex = PopupManager.nextZIndex();
99
+ }, 0);
100
+ if (val && selectVm.multiple) {
101
+ state.originValue = selectVm.modelValue.slice(0);
102
+ }
103
+ }
104
+ );
105
+ watch(
106
+ () => selectVm.shape,
107
+ () => {
108
+ nextTick(() => {
109
+ state.referenceElm = selectVm.$refs.reference && selectVm.$refs.reference.$el;
110
+ });
111
+ }
112
+ );
36
113
  };
37
- const renderless = (props, { computed, onBeforeUnmount, onDeactivated, onMounted, reactive, toRefs, watch, inject }, { vm, slots, parent, emit, nextTick }) => {
114
+ const renderless = (props, { computed, onBeforeUnmount, onDeactivated, onMounted, reactive, toRefs, watch, inject }, { vm, slots, parent, emit, nextTick, isMobileFirstMode }) => {
38
115
  const api2 = {};
39
116
  const constants = parent.select._constants;
40
117
  const selectEmitter = inject("selectEmitter");
@@ -51,9 +128,9 @@ const renderless = (props, { computed, onBeforeUnmount, onDeactivated, onMounted
51
128
  toRefs,
52
129
  watch
53
130
  });
54
- const state = initState({ reactive, computed, popper, selectVm });
55
- initApi({ api: api2, popper, state, selectEmitter, constants, selectVm, parent });
56
- initWatch({ watch, selectVm, state, nextTick });
131
+ const state = initState({ reactive, computed, popper, props, selectVm });
132
+ initApi({ api: api2, popper, state, selectEmitter, constants, selectVm, parent, nextTick, props, isMobileFirstMode });
133
+ initWatch({ watch, selectVm, state, nextTick, api: api2 });
57
134
  onBeforeUnmount(() => {
58
135
  popper.destroyPopper("remove");
59
136
  state.popperElm = null;
@@ -125,7 +125,9 @@ const load = ({ state, props, api }) => () => {
125
125
  }
126
126
  const list = infiniteScroll.load({ input: search.input, options: search.options });
127
127
  if (!list) {
128
- } else if (typeof list.then === "function") {
128
+ return;
129
+ }
130
+ if (typeof list.then === "function") {
129
131
  state.search.loading = true;
130
132
  list.then((data) => {
131
133
  state.search.loading = false;
@@ -194,10 +194,12 @@ const unmount = (state) => () => {
194
194
  state.dragInstance = null;
195
195
  }
196
196
  };
197
+ const computedShowClear = (state) => () => Array.isArray(state.select) && state.select.length;
197
198
  export {
198
199
  arrayMinus,
199
200
  batchSubmit,
200
201
  computedShowAuxi,
202
+ computedShowClear,
201
203
  coverSubmit,
202
204
  emitChange,
203
205
  getParams,
@@ -19,7 +19,8 @@ import {
19
19
  arrayMinus,
20
20
  batchSubmit,
21
21
  getParams,
22
- coverSubmit
22
+ coverSubmit,
23
+ computedShowClear
23
24
  } from "./index";
24
25
  const api = [
25
26
  "state",
@@ -50,7 +51,8 @@ const renderless = (props, { reactive, computed, onBeforeMount, onMounted, onBef
50
51
  popoverVisible: false,
51
52
  popoverContent: "",
52
53
  dragInstance: null,
53
- slotParams: computed(() => ({ inverse: state.inverse, total: state.total, select: state.select }))
54
+ slotParams: computed(() => ({ inverse: state.inverse, total: state.total, select: state.select })),
55
+ showClear: computed(() => api2.computedShowClear())
54
56
  });
55
57
  const api2 = {
56
58
  state,
@@ -63,7 +65,8 @@ const renderless = (props, { reactive, computed, onBeforeMount, onMounted, onBef
63
65
  handleMouseleave: handleMouseleave(state),
64
66
  keyType: keyType(props),
65
67
  unmount: unmount(state),
66
- getParams: getParams(state)
68
+ getParams: getParams(state),
69
+ computedShowClear: computedShowClear(state)
67
70
  };
68
71
  Object.assign(api2, {
69
72
  submitSelection: submitSelection({ api: api2, state }),
@@ -0,0 +1,241 @@
1
+ import "../chunk-G2ADBYYC.js";
2
+ import { preventDefault } from "../common/deps/dom";
3
+ const getOffsetPosition = ({ touch, state }) => {
4
+ let offsetY = 0;
5
+ let offsetX = 0;
6
+ if (state.current === "default" && state.isFullscreen) {
7
+ offsetY = state.canvasRect.width - touch.clientX + (state.canvasRect.left || 0);
8
+ offsetX = touch.clientY - (state.canvasRect.top || 0);
9
+ } else {
10
+ offsetX = touch.clientX - (state.canvasRect.left || 0);
11
+ offsetY = touch.clientY - (state.canvasRect.top || 0);
12
+ }
13
+ return { offsetX, offsetY };
14
+ };
15
+ const redraw = ({ state, props, nextTick }) => ({ oldWidth, oldHeight }) => {
16
+ if (Date.now() - state.lastRedrawDate < 100) {
17
+ return;
18
+ }
19
+ state.lastRedrawDate = Date.now();
20
+ nextTick(() => {
21
+ const context = state.ctx;
22
+ context.lineWidth = props.lineWidth;
23
+ context.strokeStyle = props.penColor;
24
+ context.beginPath();
25
+ state.ctx.lineJoin = "round";
26
+ state.paths.forEach((point) => {
27
+ point.offsetX *= state.width / oldWidth;
28
+ point.offsetY *= state.height / oldHeight;
29
+ if (point.isStart) {
30
+ context.moveTo(point.offsetX, point.offsetY);
31
+ } else {
32
+ context.lineTo(point.offsetX, point.offsetY);
33
+ context.stroke();
34
+ }
35
+ });
36
+ });
37
+ };
38
+ const touchStart = ({ emit, props, state, vm, api, useRect }) => () => {
39
+ if (!state.ctx) {
40
+ return false;
41
+ }
42
+ if (!state.isBeginWrite) {
43
+ api.rewrite(true);
44
+ }
45
+ state.canvasRect = useRect(vm.$refs.canvasRef);
46
+ state.ctx.lineWidth = props.lineWidth;
47
+ state.ctx.strokeStyle = props.penColor;
48
+ const touch = event.touches[0];
49
+ if (!touch.offsetX) {
50
+ const pos = getOffsetPosition({ touch, state });
51
+ touch.offsetX = pos.offsetX;
52
+ touch.offsetY = pos.offsetY;
53
+ }
54
+ state.isDrawing = true;
55
+ const point = {
56
+ isStart: true,
57
+ offsetX: touch.offsetX,
58
+ offsetY: touch.offsetY
59
+ };
60
+ state.paths.push(point);
61
+ state.ctx.beginPath();
62
+ state.ctx.lineJoin = "round";
63
+ state.ctx.moveTo(touch.offsetX, touch.offsetY);
64
+ emit("start");
65
+ };
66
+ const touchMove = ({ emit, state }) => (e) => {
67
+ if (!state.ctx) {
68
+ return false;
69
+ }
70
+ preventDefault(e);
71
+ const touch = event.touches[0];
72
+ if (state.isDrawing) {
73
+ if (!touch.offsetX) {
74
+ const pos = getOffsetPosition({ touch, state });
75
+ touch.offsetX = pos.offsetX;
76
+ touch.offsetY = pos.offsetY;
77
+ }
78
+ state.ctx.lineTo(touch.offsetX, touch.offsetY);
79
+ state.ctx.stroke();
80
+ const point = {
81
+ isStart: false,
82
+ offsetX: touch.offsetX,
83
+ offsetY: touch.offsetY
84
+ };
85
+ state.paths.push(point);
86
+ }
87
+ emit("signing", event);
88
+ };
89
+ const touchEnd = ({ emit, state }) => (event2) => {
90
+ state.isDrawing = false;
91
+ preventDefault(event2);
92
+ emit("end");
93
+ };
94
+ const isCanvasEmpty = (canvas, props) => {
95
+ const empty = document.createElement("canvas");
96
+ const ctx = empty.getContext("2d");
97
+ empty.width = canvas.width;
98
+ empty.height = canvas.height;
99
+ ctx.font = "16px PingFangSC";
100
+ ctx.textAlign = "center";
101
+ ctx.fillStyle = "#AEAEAE";
102
+ ctx.fillText(props.placeholder, empty.width / 2, empty.height / 2);
103
+ return canvas.toDataURL() === empty.toDataURL();
104
+ };
105
+ const setCanvasBgColor = ({ props, state }) => () => {
106
+ if (state.ctx && props.backgroundColor) {
107
+ state.ctx.fillStyle = props.backgroundColor;
108
+ state.ctx.fillRect(0, 0, state.width, state.height);
109
+ }
110
+ };
111
+ const setPlaceholder = ({ props, state }) => () => {
112
+ if (state.ctx) {
113
+ state.ctx.font = "16px PingFangSC";
114
+ state.ctx.textAlign = "center";
115
+ state.ctx.fillStyle = "#AEAEAE";
116
+ state.ctx.fillText(props.placeholder, state.width / 2, state.height / 2);
117
+ }
118
+ };
119
+ const getSignatureImage = ({ props, vm, Modal, t }) => () => {
120
+ const canvas = vm.$refs.canvasRef;
121
+ if (!canvas) {
122
+ return;
123
+ }
124
+ const isEmpty = isCanvasEmpty(canvas, props);
125
+ let image = "";
126
+ if (isEmpty) {
127
+ Modal.message(t("ui.signature.tips"));
128
+ } else {
129
+ const types = {
130
+ jpg: () => canvas.toDataURL("image/jpeg", 0.8),
131
+ jpeg: () => canvas.toDataURL("image/jpeg", 0.8)
132
+ };
133
+ let type = types[props.type];
134
+ if (type) {
135
+ image = type();
136
+ } else {
137
+ image = canvas.toDataURL(`image/${props.type}`);
138
+ }
139
+ }
140
+ return { image, canvas };
141
+ };
142
+ const submit = ({ emit, api }) => () => {
143
+ const { image, canvas } = api.getSignatureImage();
144
+ emit("submit", { image, canvas });
145
+ };
146
+ const rewrite = ({ api, emit, state }) => (isBeginWrite) => {
147
+ if (state.ctx) {
148
+ state.value = false;
149
+ state.ctx.clearRect(0, 0, state.width, state.height);
150
+ state.ctx.closePath();
151
+ api.setCanvasBgColor();
152
+ state.isBeginWrite = true;
153
+ if (isBeginWrite === true)
154
+ return;
155
+ api.setPlaceholder();
156
+ state.isBeginWrite = false;
157
+ state.paths.length = 0;
158
+ emit("rewrite");
159
+ }
160
+ };
161
+ const cancel = ({ api, emit }) => () => {
162
+ api.toggleFullscreen();
163
+ emit("cancel");
164
+ };
165
+ const tranformImage = ({ api, vm, props, nextTick }) => ({ oldWidth, oldHeight }) => {
166
+ const canvas = vm.$refs.canvasRef;
167
+ if (isCanvasEmpty(canvas, props)) {
168
+ nextTick(() => {
169
+ api.setPlaceholder();
170
+ });
171
+ } else {
172
+ nextTick(() => {
173
+ api.redraw({ oldWidth, oldHeight });
174
+ });
175
+ }
176
+ };
177
+ const toggleFullscreen = ({ nextTick, api, state }) => () => {
178
+ const clientWidth = document.documentElement.clientWidth;
179
+ const clientHeight = document.documentElement.clientHeight;
180
+ const oldWidth = state.width;
181
+ const oldHeight = state.height;
182
+ state.isFullscreen = !state.isFullscreen;
183
+ nextTick(() => {
184
+ if (state.current.value === "default" && state.isFullscreen) {
185
+ state.width = clientHeight;
186
+ state.height = clientWidth;
187
+ } else {
188
+ api.initCanvas();
189
+ }
190
+ api.tranformImage({ oldWidth, oldHeight });
191
+ });
192
+ };
193
+ const initCanvas = ({ props, state, vm }) => () => {
194
+ const canvas = vm.$refs.canvasRef;
195
+ const wrap = vm.$refs.wrapRef;
196
+ const width = wrap.offsetWidth || 0;
197
+ const height = wrap.offsetHeight || 0;
198
+ state.ctx = canvas.getContext("2d");
199
+ state.width = width;
200
+ state.height = props.height || height;
201
+ };
202
+ const mounted = ({ vm, state, api, nextTick, markRaw }) => () => {
203
+ const wrap = vm.$refs.wrapRef;
204
+ const resizeObserver = new ResizeObserver((ResizeObserverEntryArr) => {
205
+ const [{ contentRect }] = ResizeObserverEntryArr;
206
+ if (contentRect.width && contentRect.height) {
207
+ api.initCanvas();
208
+ if (state.paths.length) {
209
+ api.redraw({ oldWidth: contentRect.width, oldHeight: contentRect.height });
210
+ } else {
211
+ nextTick(() => {
212
+ api.setCanvasBgColor();
213
+ api.setPlaceholder();
214
+ });
215
+ }
216
+ }
217
+ });
218
+ state.resizeObserver = markRaw(resizeObserver);
219
+ state.resizeObserver.observe(wrap);
220
+ };
221
+ const beforeUnmount = ({ vm, state }) => () => {
222
+ const wrap = vm.$refs.wrapRef;
223
+ state.resizeObserver.unobserve(wrap);
224
+ };
225
+ export {
226
+ beforeUnmount,
227
+ cancel,
228
+ getSignatureImage,
229
+ initCanvas,
230
+ mounted,
231
+ redraw,
232
+ rewrite,
233
+ setCanvasBgColor,
234
+ setPlaceholder,
235
+ submit,
236
+ toggleFullscreen,
237
+ touchEnd,
238
+ touchMove,
239
+ touchStart,
240
+ tranformImage
241
+ };
@@ -0,0 +1,88 @@
1
+ import "../chunk-G2ADBYYC.js";
2
+ import emulate from "../common/deps/touch-emulator";
3
+ import { useRect as _useRect } from "../common/deps/useRect";
4
+ import {
5
+ touchStart,
6
+ touchMove,
7
+ touchEnd,
8
+ setCanvasBgColor,
9
+ submit,
10
+ cancel,
11
+ rewrite,
12
+ mounted,
13
+ beforeUnmount,
14
+ setPlaceholder,
15
+ toggleFullscreen,
16
+ initCanvas,
17
+ tranformImage,
18
+ redraw,
19
+ getSignatureImage
20
+ } from "./index";
21
+ emulate();
22
+ const api = [
23
+ "state",
24
+ "touchStart",
25
+ "touchMove",
26
+ "touchEnd",
27
+ "rewrite",
28
+ "submit",
29
+ "toggleFullscreen",
30
+ "initCanvas",
31
+ "cancel",
32
+ "tranformImage",
33
+ "redraw",
34
+ "getSignatureImage"
35
+ ];
36
+ const renderless = (props, { unref, reactive, onMounted, onBeforeUnmount, watch, markRaw }, { emit, vm, nextTick, t, useBreakpoint }, { Modal }) => {
37
+ const { current } = useBreakpoint();
38
+ const state = reactive({
39
+ width: 0,
40
+ height: 0,
41
+ ctx: null,
42
+ isBeginWrite: false,
43
+ isFullscreen: false,
44
+ current,
45
+ canvasRect: null,
46
+ isDrawing: false,
47
+ paths: markRaw([]),
48
+ resizeObserver: null,
49
+ value: props.value,
50
+ lastRedrawDate: 0
51
+ });
52
+ watch(
53
+ () => props.value,
54
+ (newValue) => {
55
+ if (newValue) {
56
+ state.value = newValue;
57
+ }
58
+ }
59
+ );
60
+ const useRect = _useRect(unref);
61
+ const api2 = {
62
+ state,
63
+ touchMove: touchMove({ emit, state }),
64
+ touchEnd: touchEnd({ emit, state }),
65
+ setCanvasBgColor: setCanvasBgColor({ props, state }),
66
+ setPlaceholder: setPlaceholder({ props, state }),
67
+ getSignatureImage: getSignatureImage({ props, vm, Modal, t })
68
+ };
69
+ Object.assign(api2, {
70
+ touchStart: touchStart({ emit, props, state, vm, api: api2, useRect }),
71
+ rewrite: rewrite({ api: api2, emit, state }),
72
+ mounted: mounted({ state, api: api2, vm, nextTick, markRaw }),
73
+ onBeforeUnmount: beforeUnmount({ state, vm }),
74
+ initCanvas: initCanvas({ props, state, vm }),
75
+ toggleFullscreen: toggleFullscreen({ api: api2, nextTick, state }),
76
+ cancel: cancel({ api: api2, emit }),
77
+ redraw: redraw({ props, state, nextTick }),
78
+ tranformImage: tranformImage({ api: api2, vm, props, nextTick }),
79
+ submit: submit({ emit, api: api2 })
80
+ });
81
+ onMounted(() => api2.mounted());
82
+ onBeforeUnmount(() => api2.onBeforeUnmount());
83
+ return api2;
84
+ };
85
+ export {
86
+ api,
87
+ renderless
88
+ };
@@ -0,0 +1,14 @@
1
+ import "../chunk-G2ADBYYC.js";
2
+ import { isNumber, isNull } from "../common/type";
3
+ const toPxStyle = (value) => {
4
+ if (isNull(value)) {
5
+ return void 0;
6
+ }
7
+ if (isNumber(value)) {
8
+ return `${value}px`;
9
+ }
10
+ return String(value);
11
+ };
12
+ export {
13
+ toPxStyle
14
+ };
@@ -0,0 +1,15 @@
1
+ import "../chunk-G2ADBYYC.js";
2
+ import { toPxStyle } from "./index";
3
+ const api = ["toPxStyle"];
4
+ const renderless = (props, { toRefs, provide }) => {
5
+ const { active } = toRefs(props);
6
+ provide("active", active);
7
+ const api2 = {
8
+ toPxStyle
9
+ };
10
+ return api2;
11
+ };
12
+ export {
13
+ api,
14
+ renderless
15
+ };
@@ -0,0 +1,15 @@
1
+ import "../chunk-G2ADBYYC.js";
2
+ const api = ["state"];
3
+ const renderless = (props, { reactive, inject }) => {
4
+ const state = reactive({
5
+ isActive: inject("active", false)
6
+ });
7
+ const api2 = {
8
+ state
9
+ };
10
+ return api2;
11
+ };
12
+ export {
13
+ api,
14
+ renderless
15
+ };