@opentiny/vue-renderless 3.26.0 → 3.28.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.
- package/autocomplete/index.js +7 -2
- package/autocomplete/vue.js +1 -1
- package/base-select/index.js +189 -86
- package/base-select/vue.js +82 -20
- package/calendar-view/index.js +6 -3
- package/calendar-view/vue.js +9 -5
- package/color-picker/vue.js +4 -0
- package/color-select-panel/alpha-select/index.js +17 -12
- package/color-select-panel/alpha-select/vue.js +4 -2
- package/color-select-panel/hue-select/index.js +42 -11
- package/color-select-panel/hue-select/vue.js +32 -6
- package/color-select-panel/index.js +223 -39
- package/color-select-panel/linear-gradient/index.js +131 -0
- package/color-select-panel/linear-gradient/vue.js +21 -0
- package/color-select-panel/sv-select/index.js +12 -9
- package/color-select-panel/sv-select/vue.js +4 -2
- package/color-select-panel/utils/color-map.js +154 -0
- package/color-select-panel/utils/color-points.js +86 -0
- package/color-select-panel/utils/color.js +1 -1
- package/color-select-panel/utils/context.js +14 -0
- package/color-select-panel/vue.js +3 -3
- package/common/deps/infinite-scroll.js +1 -1
- package/dialog-box/index.js +3 -3
- package/dialog-box/vue.js +1 -0
- package/drawer/index.js +20 -0
- package/drawer/vue.js +9 -1
- package/dropdown/index.js +10 -4
- package/file-upload/index.js +18 -4
- package/form-item/index.js +28 -16
- package/form-item/vue.js +50 -11
- package/grid/static/array/eachTree.js +1 -0
- package/grid/utils/common.js +10 -3
- package/grid-select/index.js +418 -32
- package/grid-select/vue.js +103 -9
- package/guide/index.js +3 -3
- package/guide/vue.js +11 -1
- package/input/vue.js +2 -1
- package/package.json +3 -3
- package/picker/index.js +30 -13
- package/picker/vue.js +10 -0
- package/popover/index.js +1 -1
- package/rich-text/index.js +42 -0
- package/select/index.js +32 -15
- package/select/vue.js +31 -10
- package/select-dropdown/vue.js +8 -3
- package/select-wrapper/vue.js +134 -0
- package/slider/vue.js +7 -0
- package/space/index.js +30 -0
- package/space/vue.js +39 -0
- package/switch/vue.js +19 -0
- package/tab-nav/index.js +2 -2
- package/tabs-mf/index.js +9 -1
- package/tabs-mf/vue-nav.js +70 -22
- package/tabs-mf/vue-slider-bar.js +24 -0
- package/tabs-mf/vue.js +23 -5
- package/tag/index.js +1 -1
- package/transfer-panel/index.js +2 -1
- package/tree-menu/index.js +4 -0
- package/tree-menu/vue.js +3 -0
- package/tree-select/index.js +13 -4
- package/tree-select/vue.js +19 -3
- package/types/autocomplete.type.d.ts +2 -1
- package/types/color-select-panel.type.d.ts +197 -1
- package/types/date-picker.type.d.ts +38 -2
- package/types/file-upload.type.d.ts +1 -1
- package/types/form-item.type.d.ts +1 -1
- package/types/{form.type-dd403065.d.ts → form.type-a54e1c06.d.ts} +2 -2
- package/types/form.type.d.ts +1 -1
- package/types/input.type.d.ts +1 -1
- package/types/modal.type.d.ts +4 -0
- package/types/numeric.type.d.ts +1 -1
- package/types/picker.type.d.ts +42 -2
- package/types/popeditor.type.d.ts +76 -4
- package/types/popover.type.d.ts +1 -1
- package/types/space.type.d.ts +31 -0
- package/types/switch.type.d.ts +2 -1
- package/types/transfer.type.d.ts +3 -3
- package/types/tree-menu.type.d.ts +38 -2
- package/types/upload-dragger.type.d.ts +1 -1
- package/types/{upload-list.type-36a8374a.d.ts → upload-list.type-d5ff675d.d.ts} +1 -1
- package/types/upload-list.type.d.ts +1 -1
- package/types/upload.type.d.ts +1 -1
package/base-select/vue.js
CHANGED
|
@@ -57,6 +57,7 @@ import {
|
|
|
57
57
|
watchPropsOption,
|
|
58
58
|
onMouseenterNative,
|
|
59
59
|
onMouseleaveNative,
|
|
60
|
+
onMouseenterSelf,
|
|
60
61
|
onCopying,
|
|
61
62
|
defaultOnQueryChange,
|
|
62
63
|
queryChange,
|
|
@@ -100,10 +101,14 @@ import {
|
|
|
100
101
|
updateSelectedData,
|
|
101
102
|
hidePanel,
|
|
102
103
|
computedShowTagText,
|
|
103
|
-
isTagClosable
|
|
104
|
+
isTagClosable,
|
|
105
|
+
computedCurrentSizeMap,
|
|
106
|
+
watchOptionsWhenAutoSelect
|
|
104
107
|
} from "./index";
|
|
105
108
|
import { debounce } from "@opentiny/utils";
|
|
106
109
|
import { isNumber } from "@opentiny/utils";
|
|
110
|
+
import { useUserAgent } from "@opentiny/vue-hooks";
|
|
111
|
+
import { isServer } from "@opentiny/utils";
|
|
107
112
|
const api = [
|
|
108
113
|
"state",
|
|
109
114
|
"toggleCheckAll",
|
|
@@ -148,6 +153,7 @@ const api = [
|
|
|
148
153
|
"navigateOptions",
|
|
149
154
|
"onMouseenterNative",
|
|
150
155
|
"onMouseleaveNative",
|
|
156
|
+
"onMouseenterSelf",
|
|
151
157
|
"onCopying",
|
|
152
158
|
"handleDropdownClick",
|
|
153
159
|
"handleEnterTag",
|
|
@@ -160,14 +166,25 @@ const api = [
|
|
|
160
166
|
"computedShowTagText",
|
|
161
167
|
"isTagClosable"
|
|
162
168
|
];
|
|
163
|
-
const initState = ({
|
|
169
|
+
const initState = ({
|
|
170
|
+
reactive,
|
|
171
|
+
computed,
|
|
172
|
+
props,
|
|
173
|
+
api: api2,
|
|
174
|
+
emitter,
|
|
175
|
+
parent,
|
|
176
|
+
constants,
|
|
177
|
+
isMobileFirstMode,
|
|
178
|
+
useBreakpoint,
|
|
179
|
+
vm,
|
|
180
|
+
designConfig
|
|
181
|
+
}) => {
|
|
164
182
|
const stateAdd = initStateAdd({ computed, props, api: api2, parent });
|
|
165
183
|
const state = reactive(__spreadProps(__spreadValues({}, stateAdd), {
|
|
166
184
|
selectEmitter: emitter(),
|
|
167
185
|
datas: [],
|
|
168
186
|
initDatas: [],
|
|
169
187
|
query: "",
|
|
170
|
-
magicKey: 0,
|
|
171
188
|
options: [],
|
|
172
189
|
visible: false,
|
|
173
190
|
showCopy: computed(() => api2.computedShowCopy()),
|
|
@@ -185,7 +202,7 @@ const initState = ({ reactive, computed, props, api: api2, emitter, parent, cons
|
|
|
185
202
|
optionsAllDisabled: computed(() => api2.computedOptionsAllDisabled()),
|
|
186
203
|
collapseTagSize: computed(() => api2.computedCollapseTagSize()),
|
|
187
204
|
showNewOption: computed(() => api2.computedShowNewOption()),
|
|
188
|
-
selectSize: computed(() => props.size || state.formItemSize),
|
|
205
|
+
selectSize: computed(() => !isServer ? props.size || state.formItemSize : 0),
|
|
189
206
|
optimizeOpts: computed(() => api2.computeOptimizeOpts()),
|
|
190
207
|
optimizeStore: { valueIndex: 0, recycleScrollerHeight: computed(() => api2.recycleScrollerHeight()) },
|
|
191
208
|
collapseTags: computed(() => api2.computeCollapseTags()),
|
|
@@ -202,11 +219,39 @@ const initState = ({ reactive, computed, props, api: api2, emitter, parent, cons
|
|
|
202
219
|
selectedCopy: [],
|
|
203
220
|
compareValue: null,
|
|
204
221
|
selectedVal: computed(
|
|
205
|
-
() => state.device === "mb" && props.multiple && state.visible ? state.selectedCopy : state.selected
|
|
206
|
-
),
|
|
207
|
-
displayOnlyContent: computed(
|
|
208
|
-
() => props.multiple && Array.isArray(state.selected) ? state.selected.map((item) => item.state ? item.state.currentLabel : item.currentLabel).join("; ") : ""
|
|
222
|
+
() => isMobileFirstMode && state.device === "mb" && props.multiple && state.visible ? state.selectedCopy : state.selected
|
|
209
223
|
),
|
|
224
|
+
displayOnlyContent: computed(() => {
|
|
225
|
+
var _a;
|
|
226
|
+
if (vm.$slots.reference) {
|
|
227
|
+
return "";
|
|
228
|
+
}
|
|
229
|
+
if (props.multiple) {
|
|
230
|
+
if (Array.isArray(state.selected)) {
|
|
231
|
+
if (state.isDisplayOnly && props.options && props.options.length > 0) {
|
|
232
|
+
return state.selected.map((item) => {
|
|
233
|
+
const find = props.options.find((opt) => opt[props.valueField] === item.value);
|
|
234
|
+
return find ? find[props.textField] : "";
|
|
235
|
+
}).join("; ");
|
|
236
|
+
} else {
|
|
237
|
+
return state.selected.map((item) => item.state ? item.state.currentLabel : item.currentLabel).join("; ");
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
return "";
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
if (state.selected) {
|
|
244
|
+
if (state.isDisplayOnly && props.options && props.options.length > 0) {
|
|
245
|
+
const find = props.options.find((opt) => opt[props.valueField] === state.selected.value);
|
|
246
|
+
return find ? find[props.textField] : "";
|
|
247
|
+
} else {
|
|
248
|
+
return ((_a = state.selected.state) == null ? void 0 : _a.currentLabel) || state.selected.currentLabel || state.selected.label || "";
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
return "";
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}),
|
|
210
255
|
breakpoint: useBreakpoint ? useBreakpoint().current : "",
|
|
211
256
|
isSaaSTheme: vm.theme === "saas",
|
|
212
257
|
disabledOptionHover: false,
|
|
@@ -220,11 +265,18 @@ const initState = ({ reactive, computed, props, api: api2, emitter, parent, cons
|
|
|
220
265
|
return designConfig.state.autoHideDownIcon;
|
|
221
266
|
}
|
|
222
267
|
return true;
|
|
223
|
-
})()
|
|
268
|
+
})(),
|
|
269
|
+
designConfig,
|
|
270
|
+
currentSizeMap: computed(() => api2.computedCurrentSizeMap()),
|
|
271
|
+
rootAutoTipConfig: computed(() => __spreadValues({
|
|
272
|
+
content: state.displayOnlyContent,
|
|
273
|
+
always: !!state.displayOnlyContent
|
|
274
|
+
}, props.tooltipConfig))
|
|
224
275
|
}));
|
|
225
276
|
return state;
|
|
226
277
|
};
|
|
227
278
|
const initStateAdd = ({ computed, props, api: api2, parent }) => {
|
|
279
|
+
const { isIOS } = useUserAgent();
|
|
228
280
|
return {
|
|
229
281
|
selectedTags: [],
|
|
230
282
|
tips: "",
|
|
@@ -269,16 +321,20 @@ const initStateAdd = ({ computed, props, api: api2, parent }) => {
|
|
|
269
321
|
isDisplayOnly: computed(() => props.displayOnly || (parent.form || {}).displayOnly),
|
|
270
322
|
isDisabled: computed(() => props.disabled || (parent.form || {}).disabled),
|
|
271
323
|
isShowTagText: computed(() => api2.computedShowTagText()),
|
|
272
|
-
searchSingleCopy: computed(() => props.allowCopy && !props.multiple && props.filterable),
|
|
324
|
+
searchSingleCopy: computed(() => props.allowCopy && !props.multiple && (props.filterable || props.searchable)),
|
|
273
325
|
childrenName: computed(() => "children"),
|
|
274
326
|
tooltipContent: {},
|
|
275
327
|
isHidden: false,
|
|
276
328
|
optionIndexArr: [],
|
|
329
|
+
isIOS,
|
|
277
330
|
showCollapseTag: false,
|
|
278
331
|
exceedMaxVisibleRow: false,
|
|
279
332
|
// 是否超出默认最大显示行数
|
|
280
|
-
toHideIndex: Infinity
|
|
333
|
+
toHideIndex: Infinity,
|
|
281
334
|
// 第一个超出被隐藏的索引
|
|
335
|
+
willFocusRun: false,
|
|
336
|
+
// 进入focus时,延时等一下看是否触发blur,触发则不进入focus
|
|
337
|
+
willFocusTimer: 0
|
|
282
338
|
};
|
|
283
339
|
};
|
|
284
340
|
const initApi = ({
|
|
@@ -308,12 +364,12 @@ const initApi = ({
|
|
|
308
364
|
getChildValue: getChildValue(),
|
|
309
365
|
getOption: getOption({ props, state, api: api2 }),
|
|
310
366
|
getSelectedOption: getSelectedOption({ props, state }),
|
|
311
|
-
emitChange: emitChange({ emit, props, state, constants }),
|
|
312
|
-
directEmitChange: directEmitChange({ emit, props, state, constants }),
|
|
367
|
+
emitChange: emitChange({ emit, props, state, constants, isMobileFirstMode }),
|
|
368
|
+
directEmitChange: directEmitChange({ emit, props, state, constants, isMobileFirstMode }),
|
|
313
369
|
toggleMenu: toggleMenu({ vm, state, props, api: api2, isMobileFirstMode }),
|
|
314
370
|
showTip: showTip({ props, state, vm }),
|
|
315
371
|
onOptionDestroy: onOptionDestroy(state),
|
|
316
|
-
setSoftFocus: setSoftFocus({ vm, state }),
|
|
372
|
+
setSoftFocus: setSoftFocus({ vm, state, props }),
|
|
317
373
|
resetInputWidth: resetInputWidth({ vm, state }),
|
|
318
374
|
resetHoverIndex: resetHoverIndex({ props, state }),
|
|
319
375
|
resetDatas: resetDatas({ props, state }),
|
|
@@ -332,6 +388,7 @@ const initApi = ({
|
|
|
332
388
|
watchPropsOption: watchPropsOption({ constants, parent, props, state }),
|
|
333
389
|
onMouseenterNative: onMouseenterNative({ state }),
|
|
334
390
|
onMouseleaveNative: onMouseleaveNative({ state }),
|
|
391
|
+
onMouseenterSelf: onMouseenterSelf({ state }),
|
|
335
392
|
onCopying: onCopying({ state, vm }),
|
|
336
393
|
watchHoverIndex: watchHoverIndex({ state }),
|
|
337
394
|
computeOptimizeOpts: computeOptimizeOpts({ props, designConfig }),
|
|
@@ -339,16 +396,16 @@ const initApi = ({
|
|
|
339
396
|
computeMultipleLimit: computeMultipleLimit({ props, state }),
|
|
340
397
|
watchInputHover: watchInputHover({ vm }),
|
|
341
398
|
initQuery: initQuery({ props, state, constants, vm }),
|
|
342
|
-
updateModelValue: updateModelValue({ props, emit, state }),
|
|
399
|
+
updateModelValue: updateModelValue({ props, emit, state, isMobileFirstMode }),
|
|
343
400
|
computedTagsStyle: computedTagsStyle({ props, parent, state, vm }),
|
|
344
|
-
computedReadonly: computedReadonly({ props, state }),
|
|
401
|
+
computedReadonly: computedReadonly({ props, state, isMobileFirstMode }),
|
|
345
402
|
computedShowClose: computedShowClose({ props, state }),
|
|
346
403
|
computedCollapseTagSize: computedCollapseTagSize(state),
|
|
347
|
-
computedShowNewOption: computedShowNewOption({ props, state }),
|
|
404
|
+
computedShowNewOption: computedShowNewOption({ props, state, isMobileFirstMode }),
|
|
348
405
|
computedShowCopy: computedShowCopy({ props, state }),
|
|
349
406
|
computedOptionsAllDisabled: computedOptionsAllDisabled(state),
|
|
350
|
-
computedDisabledTooltipContent: computedDisabledTooltipContent(state),
|
|
351
|
-
computedSelectDisabled: computedSelectDisabled({
|
|
407
|
+
computedDisabledTooltipContent: computedDisabledTooltipContent({ props, state }),
|
|
408
|
+
computedSelectDisabled: computedSelectDisabled({ state }),
|
|
352
409
|
computedIsExpand: computedIsExpand({ props, state }),
|
|
353
410
|
watchInitValue: watchInitValue({ props, emit }),
|
|
354
411
|
watchShowClose: watchShowClose({ nextTick, state, parent }),
|
|
@@ -360,7 +417,9 @@ const initApi = ({
|
|
|
360
417
|
computedShowTagText: computedShowTagText({ state }),
|
|
361
418
|
isTagClosable: isTagClosable(),
|
|
362
419
|
updateSelectedData: updateSelectedData({ state }),
|
|
363
|
-
hidePanel: hidePanel({ state })
|
|
420
|
+
hidePanel: hidePanel({ state }),
|
|
421
|
+
computedCurrentSizeMap: computedCurrentSizeMap({ state, designConfig }),
|
|
422
|
+
watchOptionsWhenAutoSelect: watchOptionsWhenAutoSelect({ state, props, nextTick, api: api2 })
|
|
364
423
|
});
|
|
365
424
|
addApi({ api: api2, props, state, emit, constants, parent, nextTick, dispatch, vm, isMobileFirstMode, designConfig });
|
|
366
425
|
};
|
|
@@ -485,6 +544,8 @@ const initWatch = ({ watch, props, api: api2, state, nextTick }) => {
|
|
|
485
544
|
};
|
|
486
545
|
const addWatch = ({ watch, props, api: api2, state, nextTick }) => {
|
|
487
546
|
watch(() => [...state.options], api2.watchOptions);
|
|
547
|
+
watch(() => state.options, api2.watchOptionsWhenAutoSelect);
|
|
548
|
+
props.options && watch(() => props.options, api2.watchOptionsWhenAutoSelect);
|
|
488
549
|
watch(() => state.hoverIndex, api2.watchHoverIndex);
|
|
489
550
|
props.options && watch(() => props.options, api2.watchPropsOption, { immediate: true, deep: true });
|
|
490
551
|
props.optimization && watch(() => state.optimizeOpts, api2.watchOptimizeOpts, { immediate: true });
|
|
@@ -505,6 +566,7 @@ const renderless = (props, { computed, onBeforeUnmount, onMounted, reactive, wat
|
|
|
505
566
|
emitter,
|
|
506
567
|
parent,
|
|
507
568
|
constants,
|
|
569
|
+
isMobileFirstMode,
|
|
508
570
|
useBreakpoint,
|
|
509
571
|
vm,
|
|
510
572
|
designConfig
|
package/calendar-view/index.js
CHANGED
|
@@ -426,15 +426,18 @@ const toToday = ({ state, api, nextTick }) => () => {
|
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
428
|
};
|
|
429
|
-
const currentDateChange = ({ state, api }) => (date) => {
|
|
429
|
+
const currentDateChange = ({ state, api, nextTick }) => (date) => {
|
|
430
430
|
const currentDate = new Date(date);
|
|
431
431
|
const year = currentDate.getFullYear();
|
|
432
432
|
const month = currentDate.getMonth() + 1;
|
|
433
|
+
const day = currentDate.getDate();
|
|
433
434
|
state.activeMonth = month;
|
|
434
435
|
state.activeYear = year;
|
|
436
|
+
state.currentDate = `${year}-${month}-${day}`;
|
|
435
437
|
if (state.mode !== "month") {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
+
nextTick(() => {
|
|
439
|
+
api.initWeeklyCalendar(currentDate);
|
|
440
|
+
});
|
|
438
441
|
}
|
|
439
442
|
};
|
|
440
443
|
const getAllWednesdaysInYear = ({ state }) => (year) => {
|
package/calendar-view/vue.js
CHANGED
|
@@ -123,11 +123,12 @@ const initState = ({ reactive, props, computed, api: api2, images, modesIcon })
|
|
|
123
123
|
multiSelect: computed(() => props.multiSelect),
|
|
124
124
|
cascaderVisible: false,
|
|
125
125
|
eventTipContent: {},
|
|
126
|
-
activeYear: props.year,
|
|
126
|
+
activeYear: props.year || (/* @__PURE__ */ new Date()).getFullYear(),
|
|
127
127
|
displayMode: props.mode,
|
|
128
|
-
activeMonth: props.month,
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
activeMonth: props.month || (/* @__PURE__ */ new Date()).getMonth() + 1,
|
|
129
|
+
dateType: computed(() => !props.day ? "month" : "date"),
|
|
130
|
+
currentDate: props.year && props.month && props.day ? `${props.year}-${props.month}-${props.day}` : props.year && props.month ? `${props.year}-${props.month}` : `${(/* @__PURE__ */ new Date()).getFullYear()}-${(/* @__PURE__ */ new Date()).getMonth() + 1}-${(/* @__PURE__ */ new Date()).getDate()}`,
|
|
131
|
+
cascaderCurrent: [props.year || (/* @__PURE__ */ new Date()).getFullYear(), props.month || (/* @__PURE__ */ new Date()).getMonth() + 1],
|
|
131
132
|
cascaderOptions: computed(() => api2.computeCascaderOptions()),
|
|
132
133
|
calendar: computed(() => api2.computedCalendar("cur")),
|
|
133
134
|
prevCalendar: computed(() => api2.computedCalendar("prev")),
|
|
@@ -153,6 +154,9 @@ const initWatch = ({ watch, props, state, emit, api: api2, nextTick }) => {
|
|
|
153
154
|
() => state.mode,
|
|
154
155
|
(val) => {
|
|
155
156
|
emit("mode-change", val);
|
|
157
|
+
if (val !== "month") {
|
|
158
|
+
api2.getAllDatesOfCurrWeek(state.currentDate);
|
|
159
|
+
}
|
|
156
160
|
if (val === "schedule") {
|
|
157
161
|
api2.getCurWeekEvent();
|
|
158
162
|
}
|
|
@@ -266,7 +270,7 @@ const initApi = ({ vm, api: api2, state, t, props, emit, nextTick }) => {
|
|
|
266
270
|
initWeeklyCalendar: initWeeklyCalendar({ api: api2, state }),
|
|
267
271
|
getDatesOfPreviousWeek: getDatesOfPreviousWeek({ api: api2, state }),
|
|
268
272
|
getDatesOfNextWeek: getDatesOfNextWeek({ api: api2, state }),
|
|
269
|
-
currentDateChange: currentDateChange({ api: api2, state }),
|
|
273
|
+
currentDateChange: currentDateChange({ api: api2, state, nextTick }),
|
|
270
274
|
newSchedule: newSchedule({ emit }),
|
|
271
275
|
getPrevWeek: throttle(50, true, getPrevWeek({ api: api2, state, emit })),
|
|
272
276
|
getNextWeek: throttle(50, true, getNextWeek({ api: api2, state, emit })),
|
package/color-picker/vue.js
CHANGED
|
@@ -50,6 +50,10 @@ const renderless = (props, ctx, { emit }) => {
|
|
|
50
50
|
ctx.watch(
|
|
51
51
|
() => props.modelValue,
|
|
52
52
|
() => {
|
|
53
|
+
if (props.colorMode === "linear-gradient") {
|
|
54
|
+
state.hex = props.modelValue;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
53
57
|
color.fromString(props.modelValue);
|
|
54
58
|
const { r, g, b, a } = color.toRgba();
|
|
55
59
|
state.hex = `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import "../../chunk-G2ADBYYC.js";
|
|
2
2
|
import { getClientXY } from "../utils/getClientXY";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { useContext } from "../utils/context";
|
|
4
|
+
const initState = (hooks) => {
|
|
5
|
+
const { ref, reactive } = hooks;
|
|
6
|
+
const ctx = useContext(hooks);
|
|
7
|
+
const background = ref(ctx.activeColor.value.color.value);
|
|
5
8
|
const left = ref(0);
|
|
6
|
-
const state = reactive({ background, left });
|
|
9
|
+
const state = reactive({ background, left, activeColor: ctx.activeColor });
|
|
7
10
|
return state;
|
|
8
11
|
};
|
|
9
|
-
const useEvent = (state, slider, alphaWrapper, alphaThumb, props) => {
|
|
12
|
+
const useEvent = (state, slider, alphaWrapper, alphaThumb, props, ctx) => {
|
|
10
13
|
const onDrag = (event) => {
|
|
11
14
|
if (!slider.value || !alphaThumb.value) {
|
|
12
15
|
return;
|
|
@@ -20,7 +23,7 @@ const useEvent = (state, slider, alphaWrapper, alphaThumb, props) => {
|
|
|
20
23
|
const alpha = Math.round(
|
|
21
24
|
(left - alphaThumb.value.offsetWidth / 2) / (rect.width - alphaThumb.value.offsetWidth) * 100
|
|
22
25
|
);
|
|
23
|
-
|
|
26
|
+
ctx.activeColor.value.color.set("alpha", alpha);
|
|
24
27
|
};
|
|
25
28
|
const onClick = (event) => {
|
|
26
29
|
if (event.target !== alphaThumb.value) {
|
|
@@ -36,12 +39,12 @@ const useEvent = (state, slider, alphaWrapper, alphaThumb, props) => {
|
|
|
36
39
|
if (!el) {
|
|
37
40
|
return 0;
|
|
38
41
|
}
|
|
39
|
-
const alpha =
|
|
42
|
+
const alpha = ctx.activeColor.value.color.get("alpha");
|
|
40
43
|
return alpha * (el.offsetWidth - thumb.offsetWidth / 2) / 100;
|
|
41
44
|
};
|
|
42
45
|
const getBackground = () => {
|
|
43
|
-
if (
|
|
44
|
-
const { r, g, b } =
|
|
46
|
+
if (ctx.activeColor && ctx.activeColor.value) {
|
|
47
|
+
const { r, g, b } = ctx.activeColor.value.color.toRgb();
|
|
45
48
|
return `linear-gradient(to right, rgba(${r}, ${g}, ${b}, 0) 0%, rgba(${r}, ${g}, ${b}, 1) 100%)`;
|
|
46
49
|
}
|
|
47
50
|
return "";
|
|
@@ -52,14 +55,16 @@ const useEvent = (state, slider, alphaWrapper, alphaThumb, props) => {
|
|
|
52
55
|
};
|
|
53
56
|
return { onDrag, onClick, update };
|
|
54
57
|
};
|
|
55
|
-
const initWatch = (props, update, { watch }) => {
|
|
58
|
+
const initWatch = (props, update, { watch }, ctx) => {
|
|
56
59
|
watch(
|
|
57
|
-
() =>
|
|
58
|
-
() =>
|
|
60
|
+
() => ctx.activeColor.value.color,
|
|
61
|
+
() => {
|
|
62
|
+
update();
|
|
63
|
+
},
|
|
59
64
|
{ deep: true }
|
|
60
65
|
);
|
|
61
66
|
watch(
|
|
62
|
-
() =>
|
|
67
|
+
() => ctx.activeColor,
|
|
63
68
|
() => update(),
|
|
64
69
|
{ deep: true }
|
|
65
70
|
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "../../chunk-G2ADBYYC.js";
|
|
2
2
|
import { draggable } from "../utils/use-drag";
|
|
3
3
|
import { initState, initWatch, useEvent } from ".";
|
|
4
|
+
import { useContext } from "../utils/context";
|
|
4
5
|
const api = ["state", "color", "slider", "alphaWrapper", "alphaThumb", "onClick"];
|
|
5
6
|
const renderless = (props, hooks, utils) => {
|
|
6
7
|
const { onMounted, ref } = hooks;
|
|
@@ -8,8 +9,9 @@ const renderless = (props, hooks, utils) => {
|
|
|
8
9
|
const slider = ref();
|
|
9
10
|
const alphaWrapper = ref();
|
|
10
11
|
const alphaThumb = ref();
|
|
12
|
+
const ctx = useContext(hooks);
|
|
11
13
|
const state = initState(hooks);
|
|
12
|
-
const { update, onClick, onDrag } = useEvent(state, slider, alphaWrapper, alphaThumb, props);
|
|
14
|
+
const { update, onClick, onDrag } = useEvent(state, slider, alphaWrapper, alphaThumb, props, ctx);
|
|
13
15
|
onMounted(() => {
|
|
14
16
|
if (!slider.value || !alphaThumb.value) {
|
|
15
17
|
return;
|
|
@@ -27,7 +29,7 @@ const renderless = (props, hooks, utils) => {
|
|
|
27
29
|
update();
|
|
28
30
|
emit("ready", update);
|
|
29
31
|
});
|
|
30
|
-
initWatch(props, update, hooks);
|
|
32
|
+
initWatch(props, update, hooks, ctx);
|
|
31
33
|
const api2 = {
|
|
32
34
|
state,
|
|
33
35
|
slider,
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import "../../chunk-G2ADBYYC.js";
|
|
2
|
+
import { Color } from "../utils/color";
|
|
2
3
|
import { getClientXY } from "../utils/getClientXY";
|
|
3
|
-
|
|
4
|
+
import { useContext } from "../utils/context";
|
|
5
|
+
import { ColorPoint } from "../utils/color-points";
|
|
6
|
+
const useOnClickBar = ({ addPoint, setActivePoint, getActviePoint }, { bar }, getLeft) => {
|
|
7
|
+
return (event) => {
|
|
8
|
+
const activePoint = getActviePoint().value;
|
|
9
|
+
const color = new Color({
|
|
10
|
+
enableAlpha: activePoint.color.enableAlpha,
|
|
11
|
+
format: activePoint.color.format,
|
|
12
|
+
value: activePoint.color.value
|
|
13
|
+
});
|
|
14
|
+
const left = getLeft(bar.value, event);
|
|
15
|
+
const colorPoint = new ColorPoint(color, left);
|
|
16
|
+
addPoint(colorPoint);
|
|
17
|
+
setActivePoint(colorPoint);
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const initState = (props, hooks) => {
|
|
21
|
+
const { reactive, ref, computed } = hooks;
|
|
22
|
+
const ctx = useContext(hooks);
|
|
4
23
|
const hueValue = computed(() => props.color.get("hue"));
|
|
5
24
|
const thumbLeft = ref(0);
|
|
6
|
-
const state = reactive({ hueValue, thumbLeft });
|
|
25
|
+
const state = reactive({ hueValue, thumbLeft, ctx });
|
|
7
26
|
return state;
|
|
8
27
|
};
|
|
9
28
|
const initDom = ({ ref }) => {
|
|
@@ -13,7 +32,7 @@ const initDom = ({ ref }) => {
|
|
|
13
32
|
wrapper: ref()
|
|
14
33
|
};
|
|
15
34
|
};
|
|
16
|
-
const useEvent = ({ thumb, bar }, state, props, { emit }) => {
|
|
35
|
+
const useEvent = ({ thumb, bar }, state, props, { emit }, ctx) => {
|
|
17
36
|
const onSvReady = (update2) => {
|
|
18
37
|
emit("svReady", update2);
|
|
19
38
|
};
|
|
@@ -21,7 +40,7 @@ const useEvent = ({ thumb, bar }, state, props, { emit }) => {
|
|
|
21
40
|
if (!thumb.value) {
|
|
22
41
|
return 0;
|
|
23
42
|
}
|
|
24
|
-
const hue =
|
|
43
|
+
const hue = ctx.activeColor.value.color.get("hue");
|
|
25
44
|
if (!bar.value) {
|
|
26
45
|
return 0;
|
|
27
46
|
}
|
|
@@ -29,6 +48,20 @@ const useEvent = ({ thumb, bar }, state, props, { emit }) => {
|
|
|
29
48
|
};
|
|
30
49
|
const update = () => {
|
|
31
50
|
state.thumbLeft = getThumbTop();
|
|
51
|
+
if (ctx.colorMode.value !== "linear-gradient") {
|
|
52
|
+
ctx.activeColor.value.cursorLeft = state.thumbLeft;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const getLeft = (barEl, event) => {
|
|
56
|
+
if (!thumb.value) {
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
const rect = barEl == null ? void 0 : barEl.getBoundingClientRect();
|
|
60
|
+
const { clientX } = getClientXY(event);
|
|
61
|
+
let left = clientX - rect.left;
|
|
62
|
+
left = Math.min(left, rect.width - thumb.value.offsetWidth / 2);
|
|
63
|
+
left = Math.max(thumb.value.offsetWidth / 2, left);
|
|
64
|
+
return left;
|
|
32
65
|
};
|
|
33
66
|
const onDrag = (event) => {
|
|
34
67
|
if (!bar.value || !thumb.value) {
|
|
@@ -38,20 +71,18 @@ const useEvent = ({ thumb, bar }, state, props, { emit }) => {
|
|
|
38
71
|
if (!el) {
|
|
39
72
|
return;
|
|
40
73
|
}
|
|
74
|
+
const left = getLeft(el, event);
|
|
41
75
|
const rect = el == null ? void 0 : el.getBoundingClientRect();
|
|
42
|
-
const { clientX } = getClientXY(event);
|
|
43
|
-
let left = clientX - rect.left;
|
|
44
|
-
left = Math.min(left, rect.width - thumb.value.offsetWidth / 2);
|
|
45
|
-
left = Math.max(thumb.value.offsetWidth / 2, left);
|
|
46
76
|
const hue = Math.round((left - thumb.value.offsetWidth / 2) / (rect.width - thumb.value.offsetWidth) * 360);
|
|
47
77
|
state.thumbLeft = left;
|
|
48
78
|
emit("hueUpdate", hue);
|
|
49
|
-
|
|
79
|
+
ctx.activeColor.value.color.set("hue", hue);
|
|
50
80
|
};
|
|
51
|
-
return { update, onDrag, onSvReady };
|
|
81
|
+
return { update, onDrag, onSvReady, getLeft, getThumbTop };
|
|
52
82
|
};
|
|
53
83
|
export {
|
|
54
84
|
initDom,
|
|
55
85
|
initState,
|
|
56
|
-
useEvent
|
|
86
|
+
useEvent,
|
|
87
|
+
useOnClickBar
|
|
57
88
|
};
|
|
@@ -1,19 +1,38 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
__objRest,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "../../chunk-G2ADBYYC.js";
|
|
2
5
|
import { draggable } from "../utils/use-drag";
|
|
3
|
-
import { initDom, initState, useEvent } from ".";
|
|
4
|
-
|
|
6
|
+
import { initDom, initState, useEvent, useOnClickBar } from ".";
|
|
7
|
+
import { useContext } from "../utils/context";
|
|
8
|
+
import { useColorPoints } from "../utils/color-points";
|
|
9
|
+
const api = ["state", "onSvReady", "bar", "thumb", "wrapper", "onClickBar"];
|
|
5
10
|
const renderless = (props, hooks, utils) => {
|
|
6
|
-
const { onMounted } = hooks;
|
|
11
|
+
const { onMounted, watch } = hooks;
|
|
7
12
|
const { emit } = utils;
|
|
8
13
|
const { thumb, bar, wrapper } = initDom(hooks);
|
|
9
14
|
const state = initState(props, hooks);
|
|
10
|
-
const
|
|
15
|
+
const ctx = useContext(hooks);
|
|
16
|
+
const { onSvReady, onDrag, update, getLeft, getThumbTop } = useEvent(
|
|
17
|
+
{ thumb, bar, wrapper },
|
|
18
|
+
state,
|
|
19
|
+
props,
|
|
20
|
+
utils,
|
|
21
|
+
ctx
|
|
22
|
+
);
|
|
23
|
+
const _a = useColorPoints(
|
|
24
|
+
{ wrapper: bar, points: [ctx.activeColor.value] },
|
|
25
|
+
hooks,
|
|
26
|
+
ctx
|
|
27
|
+
), { addPoint, setActivePoint } = _a, rest = __objRest(_a, ["addPoint", "setActivePoint"]);
|
|
28
|
+
const onClickBar = useOnClickBar(__spreadValues({ addPoint, setActivePoint }, rest), { bar, thumb, wrapper }, getLeft);
|
|
11
29
|
const api2 = {
|
|
12
30
|
state,
|
|
13
31
|
onSvReady,
|
|
14
32
|
bar,
|
|
15
33
|
thumb,
|
|
16
|
-
wrapper
|
|
34
|
+
wrapper,
|
|
35
|
+
onClickBar
|
|
17
36
|
};
|
|
18
37
|
onMounted(() => {
|
|
19
38
|
if (!bar.value || !thumb.value) {
|
|
@@ -32,6 +51,13 @@ const renderless = (props, hooks, utils) => {
|
|
|
32
51
|
emit("hueReady", update);
|
|
33
52
|
update();
|
|
34
53
|
});
|
|
54
|
+
watch(
|
|
55
|
+
() => ctx.activeColor.value.color,
|
|
56
|
+
() => {
|
|
57
|
+
state.thumbLeft = getThumbTop();
|
|
58
|
+
},
|
|
59
|
+
{ immediate: true, deep: true }
|
|
60
|
+
);
|
|
35
61
|
return api2;
|
|
36
62
|
};
|
|
37
63
|
export {
|