@tdesign/uniapp 0.7.2 → 0.8.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 (199) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +32 -2
  3. package/dist/action-sheet/README.md +1 -1
  4. package/dist/action-sheet/action-sheet.vue +158 -150
  5. package/dist/action-sheet/props.ts +2 -2
  6. package/dist/action-sheet/type.ts +1 -1
  7. package/dist/avatar/avatar.vue +89 -87
  8. package/dist/avatar-group/avatar-group.vue +69 -67
  9. package/dist/back-top/back-top.vue +60 -58
  10. package/dist/badge/badge.vue +69 -59
  11. package/dist/button/button.vue +121 -116
  12. package/dist/button/props.ts +2 -2
  13. package/dist/button/type.ts +1 -1
  14. package/dist/calendar/calendar-header.vue +4 -4
  15. package/dist/calendar/calendar.vue +308 -297
  16. package/dist/calendar/template.vue +1 -1
  17. package/dist/cascader/README.en-US.md +2 -1
  18. package/dist/cascader/README.md +2 -1
  19. package/dist/cascader/cascader.vue +340 -328
  20. package/dist/cascader/props.ts +6 -1
  21. package/dist/cascader/type.ts +6 -0
  22. package/dist/cell/cell.vue +127 -121
  23. package/dist/cell-group/cell-group.vue +32 -30
  24. package/dist/check-tag/check-tag.vue +73 -71
  25. package/dist/checkbox/README.en-US.md +6 -6
  26. package/dist/checkbox/README.md +5 -5
  27. package/dist/checkbox/checkbox.vue +127 -127
  28. package/dist/checkbox/props.ts +6 -6
  29. package/dist/checkbox/type.ts +6 -4
  30. package/dist/checkbox-group/checkbox-group.vue +175 -173
  31. package/dist/checkbox-group/props.ts +6 -6
  32. package/dist/checkbox-group/type.ts +6 -4
  33. package/dist/col/col.vue +26 -24
  34. package/dist/collapse/collapse.vue +83 -81
  35. package/dist/collapse-panel/collapse-panel.vue +121 -119
  36. package/dist/collapse-panel/props.ts +4 -4
  37. package/dist/collapse-panel/type.ts +2 -2
  38. package/dist/color-picker/README.md +1 -1
  39. package/dist/color-picker/color-picker.vue +324 -322
  40. package/dist/color-picker/props.ts +2 -2
  41. package/dist/color-picker/template.vue +14 -10
  42. package/dist/common/common.ts +1 -0
  43. package/dist/common/style/theme/index.css +57 -61
  44. package/dist/common/utils.js +7 -2
  45. package/dist/common/validator.js +172 -0
  46. package/dist/config-provider/README.en-US.md +184 -0
  47. package/dist/config-provider/README.md +234 -0
  48. package/dist/config-provider/config-provider.vue +105 -0
  49. package/dist/config-provider/config-store.js +70 -0
  50. package/dist/config-provider/props.ts +16 -0
  51. package/dist/config-provider/reactive-state.js +39 -0
  52. package/dist/config-provider/type.ts +401 -0
  53. package/dist/config-provider/use-config.js +29 -0
  54. package/dist/config-provider/utils.js +29 -0
  55. package/dist/count-down/count-down.vue +98 -97
  56. package/dist/date-time-picker/date-time-picker.vue +410 -395
  57. package/dist/demo/demo.vue +1 -0
  58. package/dist/dialog/dialog.vue +176 -173
  59. package/dist/divider/divider.vue +38 -36
  60. package/dist/draggable/draggable.vue +60 -58
  61. package/dist/drawer/README.md +1 -1
  62. package/dist/drawer/drawer.vue +48 -46
  63. package/dist/dropdown-item/dropdown-item.vue +209 -207
  64. package/dist/dropdown-item/props.ts +4 -4
  65. package/dist/dropdown-item/type.ts +3 -3
  66. package/dist/dropdown-menu/dropdown-menu.vue +93 -99
  67. package/dist/empty/empty.vue +43 -42
  68. package/dist/fab/fab.vue +88 -86
  69. package/dist/footer/footer.vue +36 -34
  70. package/dist/form/README.en-US.md +17 -24
  71. package/dist/form/README.md +18 -25
  72. package/dist/form/form.css +1 -166
  73. package/dist/form/form.vue +251 -236
  74. package/dist/form/props.ts +2 -21
  75. package/dist/form/type.ts +7 -70
  76. package/dist/form-item/README.en-US.md +4 -5
  77. package/dist/form-item/README.md +4 -5
  78. package/dist/form-item/form-item.css +69 -96
  79. package/dist/form-item/form-item.vue +315 -336
  80. package/dist/form-item/form-model.ts +125 -173
  81. package/dist/form-item/props.ts +4 -17
  82. package/dist/form-item/type.ts +43 -1
  83. package/dist/grid/grid.vue +53 -51
  84. package/dist/grid-item/grid-item.vue +121 -119
  85. package/dist/guide/README.md +1 -1
  86. package/dist/guide/guide.vue +281 -277
  87. package/dist/icon/README.md +2 -4
  88. package/dist/icon/icon.vue +78 -76
  89. package/dist/image/README.md +1 -1
  90. package/dist/image/image.vue +103 -101
  91. package/dist/image-viewer/image-viewer.vue +160 -158
  92. package/dist/image-viewer/props.ts +2 -2
  93. package/dist/image-viewer/type.ts +1 -1
  94. package/dist/index.js +3 -0
  95. package/dist/indexes/indexes.vue +264 -267
  96. package/dist/indexes-anchor/indexes-anchor.vue +41 -41
  97. package/dist/input/input.vue +192 -192
  98. package/dist/input/props.ts +6 -6
  99. package/dist/input/type.ts +3 -3
  100. package/dist/link/link.vue +73 -71
  101. package/dist/loading/loading.vue +59 -59
  102. package/dist/locale/ar_KW.ts +157 -0
  103. package/dist/locale/en_US.ts +146 -0
  104. package/dist/locale/it_IT.ts +145 -0
  105. package/dist/locale/ja_JP.ts +132 -0
  106. package/dist/locale/ko_KR.ts +132 -0
  107. package/dist/locale/ru_RU.ts +157 -0
  108. package/dist/locale/zh_CN.ts +133 -0
  109. package/dist/locale/zh_TW.ts +132 -0
  110. package/dist/message/message.vue +181 -173
  111. package/dist/message/props.ts +2 -2
  112. package/dist/message/type.ts +1 -1
  113. package/dist/message-item/message-item.vue +192 -184
  114. package/dist/mixins/using-config.js +39 -0
  115. package/dist/navbar/navbar.vue +201 -199
  116. package/dist/notice-bar/notice-bar.vue +175 -171
  117. package/dist/notice-bar/props.ts +2 -2
  118. package/dist/notice-bar/type.ts +1 -1
  119. package/dist/npm/dayjs/esm/locale/ar.js +81 -0
  120. package/dist/npm/dayjs/esm/locale/it.js +39 -0
  121. package/dist/overlay/overlay.vue +50 -48
  122. package/dist/picker/picker.vue +168 -161
  123. package/dist/picker-item/picker-item.vue +269 -269
  124. package/dist/popover/README.md +1 -1
  125. package/dist/popover/popover.vue +262 -261
  126. package/dist/popover/props.ts +4 -4
  127. package/dist/popover/type.ts +2 -2
  128. package/dist/popup/popup.vue +46 -45
  129. package/dist/progress/README.md +1 -1
  130. package/dist/progress/progress.vue +76 -76
  131. package/dist/pull-down-refresh/props.ts +2 -2
  132. package/dist/pull-down-refresh/pull-down-refresh.vue +240 -234
  133. package/dist/pull-down-refresh/type.ts +1 -1
  134. package/dist/qrcode/README.md +1 -1
  135. package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.vue +340 -338
  136. package/dist/qrcode/components/qrcode-status/qrcode-status.vue +6 -6
  137. package/dist/qrcode/qrcode.vue +93 -87
  138. package/dist/radio/props.ts +6 -6
  139. package/dist/radio/radio.vue +118 -120
  140. package/dist/radio/type.ts +3 -3
  141. package/dist/radio-group/props.ts +4 -4
  142. package/dist/radio-group/radio-group.vue +136 -134
  143. package/dist/radio-group/type.ts +4 -4
  144. package/dist/rate/computed.js +2 -2
  145. package/dist/rate/props.ts +4 -4
  146. package/dist/rate/rate.vue +155 -154
  147. package/dist/rate/type.ts +2 -2
  148. package/dist/result/result.vue +41 -39
  149. package/dist/row/row.vue +38 -36
  150. package/dist/scroll-view/scroll-view.vue +24 -22
  151. package/dist/search/props.ts +2 -2
  152. package/dist/search/search.vue +127 -125
  153. package/dist/search/type.ts +1 -1
  154. package/dist/side-bar/side-bar.vue +57 -55
  155. package/dist/side-bar-item/side-bar-item.vue +86 -86
  156. package/dist/skeleton/skeleton.vue +126 -124
  157. package/dist/slider/README.md +1 -1
  158. package/dist/slider/props.ts +2 -2
  159. package/dist/slider/slider.vue +457 -457
  160. package/dist/slider/type.ts +1 -1
  161. package/dist/step-item/step-item.vue +77 -75
  162. package/dist/stepper/props.ts +2 -2
  163. package/dist/stepper/stepper.vue +168 -149
  164. package/dist/stepper/type.ts +1 -1
  165. package/dist/steps/props.ts +2 -2
  166. package/dist/steps/steps.vue +83 -81
  167. package/dist/steps/type.ts +1 -1
  168. package/dist/sticky/sticky.vue +104 -102
  169. package/dist/swipe-cell/swipe-cell.vue +91 -89
  170. package/dist/swiper/README.md +1 -1
  171. package/dist/swiper/swiper.vue +91 -89
  172. package/dist/swiper-nav/swiper-nav.vue +38 -36
  173. package/dist/switch/props.ts +2 -2
  174. package/dist/switch/switch.vue +62 -62
  175. package/dist/switch/type.ts +1 -1
  176. package/dist/tab-bar/tab-bar.vue +88 -86
  177. package/dist/tab-bar-item/tab-bar-item.vue +85 -82
  178. package/dist/tab-panel/tab-panel.vue +66 -64
  179. package/dist/tabs/tabs.vue +294 -287
  180. package/dist/tag/tag.vue +79 -77
  181. package/dist/textarea/props.ts +6 -6
  182. package/dist/textarea/textarea.vue +127 -126
  183. package/dist/textarea/type.ts +3 -3
  184. package/dist/toast/toast.vue +107 -106
  185. package/dist/transition/transition.vue +30 -28
  186. package/dist/tree-select/tree-select.vue +151 -151
  187. package/dist/types/config-provider.d.ts +7 -0
  188. package/dist/types/index.d.ts +2 -0
  189. package/dist/types/popover.d.ts +7 -0
  190. package/dist/upload/README.en-US.md +13 -14
  191. package/dist/upload/README.md +11 -12
  192. package/dist/upload/props.ts +2 -4
  193. package/dist/upload/type.ts +12 -11
  194. package/dist/upload/upload.css +1 -1
  195. package/dist/upload/upload.vue +672 -512
  196. package/dist/watermark/watermark.vue +151 -149
  197. package/global.d.ts +2 -0
  198. package/package.json +16 -2
  199. package/dist/form/form-item-props.ts +0 -56
@@ -15,7 +15,7 @@
15
15
 
16
16
  <!-- 防止转成 px 后,尺寸没铺满 -->
17
17
  <!-- 750rpx => 100% -->
18
- <TemplateVue
18
+ <template-vue
19
19
  ref="templateVue"
20
20
  :class-prefix="classPrefix"
21
21
  :custom-style="tools._style(['width: 100%', customStyle])"
@@ -39,7 +39,7 @@
39
39
  <slot name="footer" />
40
40
  </t-popup>
41
41
  <block v-else>
42
- <TemplateVue
42
+ <template-vue
43
43
  ref="templateVue"
44
44
  :class-prefix="classPrefix"
45
45
  :custom-style="tools._style([customStyle])"
@@ -122,7 +122,7 @@ const getFormatList = (format, color) => {
122
122
  };
123
123
 
124
124
  const genSwatchList = (prop) => {
125
- if (prop === undefined) {
125
+ if (prop == undefined) {
126
126
  return DEFAULT_SYSTEM_SWATCH_COLORS;
127
127
  }
128
128
  if (!prop || !prop.length) {
@@ -131,369 +131,371 @@ const genSwatchList = (prop) => {
131
131
  return prop;
132
132
  };
133
133
 
134
- export default uniComponent({
135
- name,
136
- options: {
137
- styleIsolation: 'shared',
138
- },
134
+ export default {
139
135
  components: {
140
136
  TPopup,
141
137
  TemplateVue,
142
138
  },
143
- props: {
144
- ...props,
145
- },
146
- emits: [
147
- 'palette-bar-change',
148
- 'close',
149
- 'change',
150
- 'update:visible',
151
- ],
152
- data() {
153
- return {
154
- prefix,
155
- classPrefix: name,
156
- panelRect: {
157
- width: SATURATION_PANEL_DEFAULT_WIDTH,
158
- height: SATURATION_PANEL_DEFAULT_HEIGHT,
159
- },
160
- sliderRect: {
161
- width: SLIDER_DEFAULT_WIDTH,
162
- left: 0,
163
- },
164
- saturationInfo: {
165
- saturation: 0,
166
- value: 0,
167
- },
168
- saturationThumbStyle: {
169
- left: 0,
170
- top: 0,
171
- },
172
- sliderInfo: {
173
- value: 0, // hue
174
- },
175
- hueSliderStyle: {
176
- left: 0,
139
+ ...uniComponent({
140
+ name,
141
+ options: {
142
+ styleIsolation: 'shared',
143
+ },
144
+ props: {
145
+ ...props,
146
+ },
147
+ emits: [
148
+ 'palette-bar-change',
149
+ 'close',
150
+ 'change',
151
+ 'update:visible',
152
+ ],
153
+ data() {
154
+ return {
155
+ prefix,
156
+ classPrefix: name,
157
+ panelRect: {
158
+ width: SATURATION_PANEL_DEFAULT_WIDTH,
159
+ height: SATURATION_PANEL_DEFAULT_HEIGHT,
160
+ },
161
+ sliderRect: {
162
+ width: SLIDER_DEFAULT_WIDTH,
163
+ left: 0,
164
+ },
165
+ saturationInfo: {
166
+ saturation: 0,
167
+ value: 0,
168
+ },
169
+ saturationThumbStyle: {
170
+ left: 0,
171
+ top: 0,
172
+ },
173
+ sliderInfo: {
174
+ value: 0, // hue
175
+ },
176
+ hueSliderStyle: {
177
+ left: 0,
178
+ },
179
+ alphaSliderStyle: {
180
+ left: 0,
181
+ },
182
+ innerValue: props.defaultValue.default || props.value.default,
183
+ showPrimaryColorPreview: false,
184
+ previewColor: props.defaultValue.default || props.value.default,
185
+ formatList: [],
186
+ innerSwatchList: genSwatchList(props.swatchColors.default),
187
+ isMultiple: props.type.default === 'multiple',
188
+ defaultOverlayProps: {},
189
+ tools,
190
+ color: {},
191
+ dataVisible: this.visible,
192
+ };
193
+ },
194
+ watch: {
195
+ format: {
196
+ handler() {
197
+ this.setCoreStyle();
198
+ },
199
+ deep: true,
177
200
  },
178
- alphaSliderStyle: {
179
- left: 0,
201
+ swatchColors: {
202
+ handler(value) {
203
+ this.innerSwatchList = genSwatchList(value);
204
+ },
205
+ immediate: true,
180
206
  },
181
- innerValue: props.defaultValue.default || props.value.default,
182
- showPrimaryColorPreview: false,
183
- previewColor: props.defaultValue.default || props.value.default,
184
- formatList: [],
185
- innerSwatchList: genSwatchList(props.swatchColors.default),
186
- isMultiple: props.type.default === 'multiple',
187
- defaultOverlayProps: {},
188
- tools,
189
- color: {},
190
- dataVisible: this.visible,
191
- };
192
- },
193
- watch: {
194
- format: {
195
- handler() {
196
- this.setCoreStyle();
207
+ type: {
208
+ handler(value) {
209
+ this.isMultiple = value === 'multiple';
210
+ },
211
+ immediate: true,
197
212
  },
198
- deep: true,
199
- },
200
- swatchColors: {
201
- handler(value) {
202
- this.innerSwatchList = genSwatchList(value);
213
+ visible: {
214
+ handler(v) {
215
+ this.dataVisible = v;
216
+ },
217
+ immediate: true,
203
218
  },
204
- immediate: true,
205
- },
206
- type: {
207
- handler(value) {
208
- this.isMultiple = value === 'multiple';
219
+ usePopup: 'onWatchPopupVisible',
220
+ dataVisible: 'onWatchPopupVisible',
221
+
222
+ value(v) {
223
+ if (v) {
224
+ this.init();
225
+ }
209
226
  },
210
- immediate: true,
211
227
  },
212
- visible: {
213
- handler(v) {
214
- this.dataVisible = v;
215
- },
216
- immediate: true,
228
+ created() {
229
+ this.color = new Color(props.defaultValue.default || props.value.default || DEFAULT_COLOR);
230
+ this.formatList = getFormatList(props.format.default, this.color);
217
231
  },
218
- usePopup: 'onWatchPopupVisible',
219
- dataVisible: 'onWatchPopupVisible',
220
-
221
- value(v) {
222
- if (v) {
232
+ mounted() {
233
+ setTimeout(() => {
223
234
  this.init();
224
- }
235
+ }, 33);
236
+ this.debouncedUpdateEleRect = debounce(e => this.updateEleRect(e), 150);
225
237
  },
226
- },
227
- created() {
228
- this.color = new Color(props.defaultValue.default || props.value.default || DEFAULT_COLOR);
229
- this.formatList = getFormatList(props.format.default, this.color);
230
- },
231
- mounted() {
232
- setTimeout(() => {
233
- this.init();
234
- }, 33);
235
- this.debouncedUpdateEleRect = debounce(e => this.updateEleRect(e), 150);
236
- },
237
- beforeUnmount() {
238
- clearTimeout(this.timer);
239
- },
240
- methods: {
241
- init() {
242
- const { value, defaultValue } = this;
243
- const innerValue = value || defaultValue;
244
- if (innerValue) {
245
- this.innerValue = innerValue;
246
- }
247
- this.color = new Color(innerValue || DEFAULT_COLOR);
248
- this.updateColor();
249
- this.getEleReact();
238
+ beforeUnmount() {
239
+ clearTimeout(this.timer);
250
240
  },
241
+ methods: {
242
+ init() {
243
+ const { value, defaultValue } = this;
244
+ const innerValue = value || defaultValue;
245
+ if (innerValue) {
246
+ this.innerValue = innerValue;
247
+ }
248
+ this.color = new Color(innerValue || DEFAULT_COLOR);
249
+ this.updateColor();
250
+ this.getEleReact();
251
+ },
251
252
 
252
- updateEleRect(e) {
253
- if (!e) return;
254
-
255
- const { scrollTop } = e.detail;
256
- const { width, height, left, initTop } = this.panelRect;
257
- this.panelRect = {
258
- width,
259
- height,
260
- left,
261
- top: initTop - scrollTop,
262
- initTop,
263
- };
264
- },
253
+ updateEleRect(e) {
254
+ if (!e) return;
255
+
256
+ const { scrollTop } = e.detail;
257
+ const { width, height, left, initTop } = this.panelRect;
258
+ this.panelRect = {
259
+ width,
260
+ height,
261
+ left,
262
+ top: initTop - scrollTop,
263
+ initTop,
264
+ };
265
+ },
265
266
 
266
- getEleReact() {
267
- const saturationSelector = `.${name}__saturation`;
268
- const sliderSelector = `.${name}__slider`;
269
- // }
270
- if (!this.$refs.templateVue) return;
271
-
272
- Promise.all([
273
- this.$refs.templateVue.getRect(saturationSelector),
274
- this.$refs.templateVue.getRect(sliderSelector),
275
- ])
276
- .then(([saturationRect, sliderRect]) => {
277
- this.panelRect = {
278
- width: saturationRect.width || SATURATION_PANEL_DEFAULT_WIDTH,
279
- height: saturationRect.height || SATURATION_PANEL_DEFAULT_HEIGHT,
280
- left: saturationRect.left || 0,
281
- top: saturationRect.top || 0,
282
- initTop: saturationRect.top || 0,
283
- };
284
- this.sliderRect = {
285
- left: sliderRect.left || 0,
286
- width: sliderRect.width || SLIDER_DEFAULT_WIDTH,
287
- };
288
-
289
- setTimeout(() => {
290
- this.setCoreStyle();
291
- }, 33);
292
- })
293
- .catch(() => {
294
- });
295
- },
267
+ getEleReact() {
268
+ const saturationSelector = `.${name}__saturation`;
269
+ const sliderSelector = `.${name}__slider`;
270
+ // }
271
+ if (!this.$refs.templateVue) return;
272
+
273
+ Promise.all([
274
+ this.$refs.templateVue.getRect(saturationSelector),
275
+ this.$refs.templateVue.getRect(sliderSelector),
276
+ ])
277
+ .then(([saturationRect, sliderRect]) => {
278
+ this.panelRect = {
279
+ width: saturationRect.width || SATURATION_PANEL_DEFAULT_WIDTH,
280
+ height: saturationRect.height || SATURATION_PANEL_DEFAULT_HEIGHT,
281
+ left: saturationRect.left || 0,
282
+ top: saturationRect.top || 0,
283
+ initTop: saturationRect.top || 0,
284
+ };
285
+ this.sliderRect = {
286
+ left: sliderRect.left || 0,
287
+ width: sliderRect.width || SLIDER_DEFAULT_WIDTH,
288
+ };
289
+
290
+ setTimeout(() => {
291
+ this.setCoreStyle();
292
+ }, 33);
293
+ })
294
+ .catch(() => {
295
+ });
296
+ },
296
297
 
297
- clickSwatch(e) {
298
- const swatch = e.currentTarget.dataset.value;
299
- this.color.update(swatch);
300
- this.emitColorChange('preset');
301
- this.setCoreStyle();
302
- },
298
+ clickSwatch(e) {
299
+ const swatch = e.currentTarget.dataset.value;
300
+ this.color.update(swatch);
301
+ this.emitColorChange('preset');
302
+ this.setCoreStyle();
303
+ },
303
304
 
304
- setCoreStyle() {
305
- this.sliderInfo = {
306
- value: this.color.hue,
307
- };
308
- this.hueSliderStyle = this.getSliderThumbStyle({ value: this.color.hue, maxValue: HUE_MAX });
309
- this.alphaSliderStyle = this.getSliderThumbStyle({ value: this.color.alpha * 100, maxValue: ALPHA_MAX });
310
- this.saturationInfo = {
311
- saturation: this.color.saturation,
312
- value: this.color.value,
313
- };
314
- this.saturationThumbStyle = this.getSaturationThumbStyle({
315
- saturation: this.color.saturation,
316
- value: this.color.value,
317
- });
318
- this.previewColor = this.color.rgba;
319
- this.formatList = getFormatList(this.format, this.color);
320
- },
305
+ setCoreStyle() {
306
+ this.sliderInfo = {
307
+ value: this.color.hue,
308
+ };
309
+ this.hueSliderStyle = this.getSliderThumbStyle({ value: this.color.hue, maxValue: HUE_MAX });
310
+ this.alphaSliderStyle = this.getSliderThumbStyle({ value: this.color.alpha * 100, maxValue: ALPHA_MAX });
311
+ this.saturationInfo = {
312
+ saturation: this.color.saturation,
313
+ value: this.color.value,
314
+ };
315
+ this.saturationThumbStyle = this.getSaturationThumbStyle({
316
+ saturation: this.color.saturation,
317
+ value: this.color.value,
318
+ });
319
+ this.previewColor = this.color.rgba;
320
+ this.formatList = getFormatList(this.format, this.color);
321
+ },
321
322
 
322
- emitColorChange(trigger) {
323
- this.innerValue = this.formatValue();
323
+ emitColorChange(trigger) {
324
+ this.innerValue = this.formatValue();
324
325
 
325
- this.$emit('change', {
326
- value: this.formatValue(),
327
- context: {
328
- trigger,
329
- color: getColorObject(this.color),
330
- },
331
- });
332
- },
326
+ this.$emit('change', {
327
+ value: this.formatValue(),
328
+ context: {
329
+ trigger,
330
+ color: getColorObject(this.color),
331
+ },
332
+ });
333
+ },
333
334
 
334
- defaultEmptyColor() {
335
- return DEFAULT_COLOR;
336
- },
335
+ defaultEmptyColor() {
336
+ return DEFAULT_COLOR;
337
+ },
337
338
 
338
- updateColor() {
339
- const result = this.innerValue || this.defaultEmptyColor();
340
- this.color.update(result);
341
- },
339
+ updateColor() {
340
+ const result = this.innerValue || this.defaultEmptyColor();
341
+ this.color.update(result);
342
+ },
342
343
 
343
- getSaturationAndValueByCoordinate(coordinate) {
344
- const { width, height } = this.panelRect;
345
- const { x, y } = coordinate;
346
- let saturation = x / width;
347
- let value = 1 - y / height;
348
- saturation = Math.min(1, Math.max(0, saturation));
349
- value = Math.min(1, Math.max(0, value));
344
+ getSaturationAndValueByCoordinate(coordinate) {
345
+ const { width, height } = this.panelRect;
346
+ const { x, y } = coordinate;
347
+ let saturation = x / width;
348
+ let value = 1 - y / height;
349
+ saturation = Math.min(1, Math.max(0, saturation));
350
+ value = Math.min(1, Math.max(0, value));
351
+
352
+ return {
353
+ saturation,
354
+ value,
355
+ };
356
+ },
350
357
 
351
- return {
352
- saturation,
353
- value,
354
- };
355
- },
358
+ getSaturationThumbStyle({ saturation, value }) {
359
+ const { width, height } = this.panelRect;
360
+ const top = Math.round((1 - value) * height);
361
+ const left = Math.round(saturation * width);
362
+ return {
363
+ color: this.color.rgb,
364
+ left: `${left}px`,
365
+ top: `${top}px`,
366
+ };
367
+ },
356
368
 
357
- getSaturationThumbStyle({ saturation, value }) {
358
- const { width, height } = this.panelRect;
359
- const top = Math.round((1 - value) * height);
360
- const left = Math.round(saturation * width);
361
- return {
362
- color: this.color.rgb,
363
- left: `${left}px`,
364
- top: `${top}px`,
365
- };
366
- },
369
+ getSliderThumbStyle({ value, maxValue }) {
370
+ const { width } = this.sliderRect;
371
+ if (!width) {
372
+ return;
373
+ }
374
+ const left = Math.round((value / maxValue) * 100);
375
+ return {
376
+ left: `${left}%`,
377
+ color: this.color.rgb,
378
+ };
379
+ },
367
380
 
368
- getSliderThumbStyle({ value, maxValue }) {
369
- const { width } = this.sliderRect;
370
- if (!width) {
371
- return;
372
- }
373
- const left = Math.round((value / maxValue) * 100);
374
- return {
375
- left: `${left}%`,
376
- color: this.color.rgb,
377
- };
378
- },
381
+ onChangeSaturation({ saturation, value }) {
382
+ const { saturation: sat, value: val } = this.color;
383
+ let changeTrigger = 'palette-saturation-brightness';
384
+ if (value !== val && saturation !== sat) {
385
+ this.color.saturation = saturation;
386
+ this.color.value = value;
387
+ changeTrigger = 'palette-saturation-brightness';
388
+ } else if (saturation !== sat) {
389
+ this.color.saturation = saturation;
390
+ changeTrigger = 'palette-saturation';
391
+ } else if (value !== val) {
392
+ this.color.value = value;
393
+ changeTrigger = 'palette-brightness';
394
+ } else {
395
+ return;
396
+ }
397
+
398
+ this.$emit('palette-bar-change', {
399
+ color: getColorObject(this.color),
400
+ });
379
401
 
380
- onChangeSaturation({ saturation, value }) {
381
- const { saturation: sat, value: val } = this.color;
382
- let changeTrigger = 'palette-saturation-brightness';
383
- if (value !== val && saturation !== sat) {
384
- this.color.saturation = saturation;
385
- this.color.value = value;
386
- changeTrigger = 'palette-saturation-brightness';
387
- } else if (saturation !== sat) {
388
- this.color.saturation = saturation;
389
- changeTrigger = 'palette-saturation';
390
- } else if (value !== val) {
391
- this.color.value = value;
392
- changeTrigger = 'palette-brightness';
393
- } else {
394
- return;
395
- }
396
-
397
- this.$emit('palette-bar-change', {
398
- color: getColorObject(this.color),
399
- });
400
-
401
- this.emitColorChange(changeTrigger);
402
- this.setCoreStyle();
403
- },
402
+ this.emitColorChange(changeTrigger);
403
+ this.setCoreStyle();
404
+ },
404
405
 
405
- formatValue() {
406
- return this.color.getFormatsColorMap()[this.format] || this.color.css;
407
- },
406
+ formatValue() {
407
+ return this.color.getFormatsColorMap()[this.format] || this.color.css;
408
+ },
408
409
 
409
- onChangeSlider({ value, isAlpha }) {
410
- if (isAlpha) {
411
- this.color.alpha = value / 100;
412
- } else {
413
- this.color.hue = value;
414
- }
410
+ onChangeSlider({ value, isAlpha }) {
411
+ if (isAlpha) {
412
+ this.color.alpha = value / 100;
413
+ } else {
414
+ this.color.hue = value;
415
+ }
415
416
 
416
- this.emitColorChange(isAlpha ? 'palette-alpha-bar' : 'palette-hue-bar');
417
+ this.emitColorChange(isAlpha ? 'palette-alpha-bar' : 'palette-hue-bar');
417
418
 
418
- this.setCoreStyle();
419
- },
420
-
421
- handleSaturationDrag(e) {
422
- const { usePopup, fixed } = this;
423
- const coordinate = getCoordinate(e, this.panelRect, usePopup || fixed);
424
- const { saturation, value } = this.getSaturationAndValueByCoordinate(coordinate);
425
- this.onChangeSaturation({ saturation, value });
426
- },
419
+ this.setCoreStyle();
420
+ },
427
421
 
428
- handleSliderDrag(e, isAlpha = false) {
429
- const { width } = this.sliderRect;
430
- const coordinate = getCoordinate(e, this.sliderRect);
431
- const { x } = coordinate;
432
- const maxValue = isAlpha ? ALPHA_MAX : HUE_MAX;
422
+ handleSaturationDrag(e) {
423
+ const { usePopup, fixed } = this;
424
+ const coordinate = getCoordinate(e, this.panelRect, usePopup || fixed);
425
+ const { saturation, value } = this.getSaturationAndValueByCoordinate(coordinate);
426
+ this.onChangeSaturation({ saturation, value });
427
+ },
433
428
 
434
- let value = Math.round((x / width) * maxValue * 100) / 100;
435
- if (value < 0) value = 0;
436
- if (value > maxValue) value = maxValue;
437
- this.onChangeSlider({ value, isAlpha });
438
- },
429
+ handleSliderDrag(e, isAlpha = false) {
430
+ const { width } = this.sliderRect;
431
+ const coordinate = getCoordinate(e, this.sliderRect);
432
+ const { x } = coordinate;
433
+ const maxValue = isAlpha ? ALPHA_MAX : HUE_MAX;
439
434
 
440
- handleDiffDrag(e) {
441
- const dragType = e.target.dataset.type || e.currentTarget.dataset.type;
442
- switch (dragType) {
443
- case 'saturation':
444
- this.handleSaturationDrag(e);
445
- break;
446
- case 'hue-slider':
447
- this.handleSliderDrag(e);
448
- break;
449
- case 'alpha-slider':
450
- this.handleSliderDrag(e, true);
451
- break;
452
- default:
453
- break;
454
- }
455
- },
435
+ let value = Math.round((x / width) * maxValue * 100) / 100;
436
+ if (value < 0) value = 0;
437
+ if (value > maxValue) value = maxValue;
438
+ this.onChangeSlider({ value, isAlpha });
439
+ },
456
440
 
457
- onTouchStart(e) {
458
- this.handleDiffDrag(e);
459
- },
441
+ handleDiffDrag(e) {
442
+ const dragType = e.target.dataset.type || e.currentTarget.dataset.type;
443
+ switch (dragType) {
444
+ case 'saturation':
445
+ this.handleSaturationDrag(e);
446
+ break;
447
+ case 'hue-slider':
448
+ this.handleSliderDrag(e);
449
+ break;
450
+ case 'alpha-slider':
451
+ this.handleSliderDrag(e, true);
452
+ break;
453
+ default:
454
+ break;
455
+ }
456
+ },
460
457
 
461
- onTouchMove(e) {
462
- this.handleDiffDrag(e);
463
- },
458
+ onTouchStart(e) {
459
+ this.handleDiffDrag(e);
460
+ },
464
461
 
465
- onTouchEnd(e) {
466
- nextTick().then(() => {
462
+ onTouchMove(e) {
467
463
  this.handleDiffDrag(e);
468
- });
469
- },
464
+ },
470
465
 
471
- close(trigger) {
472
- if (this.autoClose) {
473
- this.dataVisible = false;
474
- this.$emit('update:visible', false);
475
- }
466
+ onTouchEnd(e) {
467
+ nextTick().then(() => {
468
+ this.handleDiffDrag(e);
469
+ });
470
+ },
476
471
 
477
- this.$emit('close', { trigger });
478
- },
472
+ close(trigger) {
473
+ if (this.autoClose) {
474
+ this.dataVisible = false;
475
+ this.$emit('update:visible', false);
476
+ }
479
477
 
480
- onVisibleChange() {
481
- this.close('overlay');
482
- },
478
+ this.$emit('close', { trigger });
479
+ },
480
+
481
+ onVisibleChange() {
482
+ this.close('overlay');
483
+ },
483
484
 
484
- onWatchPopupVisible() {
485
- if (this.timer) {
486
- clearTimeout(this.timer);
487
- }
485
+ onWatchPopupVisible() {
486
+ if (this.timer) {
487
+ clearTimeout(this.timer);
488
+ }
488
489
 
489
- if (this.usePopup && this.dataVisible) {
490
- this.timer = setTimeout(() => {
491
- this.getEleReact();
492
- }, 350); // popup 的 transition-duration 为 300ms,为保证 popup 已渲染完毕,故使用 350ms
493
- }
490
+ if (this.usePopup && this.dataVisible) {
491
+ this.timer = setTimeout(() => {
492
+ this.getEleReact();
493
+ }, 350); // popup 的 transition-duration 为 300ms,为保证 popup 已渲染完毕,故使用 350ms
494
+ }
495
+ },
494
496
  },
495
- },
496
- });
497
+ }),
498
+ };
497
499
 
498
500
  </script>
499
501
  <style scoped src="./color-picker.css"></style>