@varlet/ui 2.17.1 → 2.18.0-alpha.1697511280107
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/es/action-sheet/actionSheet.css +1 -1
- package/es/drag/Drag.mjs +2 -2
- package/es/form/Form.mjs +3 -3
- package/es/image-preview/ImagePreview.mjs +2 -2
- package/es/index-bar/indexBar.css +1 -1
- package/es/index.bundle.mjs +13 -1
- package/es/index.mjs +11 -1
- package/es/input/Input.mjs +2 -2
- package/es/menu/style/index.mjs +1 -1
- package/es/menu-option/MenuOption.mjs +122 -0
- package/es/menu-option/MenuOptionSfc.css +0 -0
- package/es/menu-option/index.mjs +11 -0
- package/es/menu-option/menuOption.css +1 -0
- package/es/menu-option/props.mjs +8 -0
- package/es/menu-option/provide.mjs +19 -0
- package/es/menu-option/style/index.mjs +5 -0
- package/es/menu-select/MenuSelect.mjs +111 -0
- package/es/menu-select/MenuSelectSfc.css +0 -0
- package/es/menu-select/index.mjs +9 -0
- package/es/menu-select/menuSelect.css +1 -0
- package/es/menu-select/props.mjs +57 -0
- package/es/menu-select/provide.mjs +16 -0
- package/es/menu-select/style/index.mjs +5 -0
- package/es/pull-refresh/PullRefresh.mjs +2 -2
- package/es/ripple/index.mjs +2 -0
- package/es/select/Select.mjs +14 -47
- package/es/select/useSelectController.mjs +67 -0
- package/es/slider/Slider.mjs +2 -2
- package/es/style.css +1 -1
- package/es/style.mjs +2 -0
- package/es/swipe/Swipe.mjs +13 -13
- package/es/themes/dark/index.mjs +4 -2
- package/es/themes/dark/menuOption.mjs +6 -0
- package/es/themes/dark/menuSelect.mjs +6 -0
- package/es/time-picker/TimePicker.mjs +2 -2
- package/es/varlet.esm.js +5571 -5279
- package/highlight/web-types.en-US.json +327 -89
- package/highlight/web-types.zh-CN.json +240 -2
- package/lib/style.css +1 -1
- package/lib/varlet.cjs.js +1998 -1645
- package/package.json +7 -7
- package/types/index.d.ts +4 -0
- package/types/menuOption.d.ts +20 -0
- package/types/menuSelect.d.ts +69 -0
- package/umd/varlet.js +6 -6
package/es/select/Select.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import { useOptions } from "./provide.mjs";
|
|
|
11
11
|
import { useForm } from "../form/provide.mjs";
|
|
12
12
|
import { toPxNum } from "../utils/elements.mjs";
|
|
13
13
|
import { error } from "../utils/logger.mjs";
|
|
14
|
+
import { useSelectController } from "./useSelectController.mjs";
|
|
14
15
|
const { name, n, classes } = createNamespace("select");
|
|
15
16
|
import { renderSlot as _renderSlot, renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, resolveComponent as _resolveComponent, withModifiers as _withModifiers, normalizeClass as _normalizeClass, withCtx as _withCtx, createBlock as _createBlock, createCommentVNode as _createCommentVNode, createElementVNode as _createElementVNode, normalizeStyle as _normalizeStyle, createVNode as _createVNode, normalizeProps as _normalizeProps, guardReactiveProps as _guardReactiveProps, createSlots as _createSlots, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue";
|
|
16
17
|
const _withScopeId = (n2) => (_pushScopeId(""), n2 = n2(), _popScopeId(), n2);
|
|
@@ -237,13 +238,17 @@ const __sfc__ = defineComponent({
|
|
|
237
238
|
const showMenu = ref(false);
|
|
238
239
|
const multiple = computed(() => props2.multiple);
|
|
239
240
|
const focusColor = computed(() => props2.focusColor);
|
|
240
|
-
const label = ref("");
|
|
241
|
-
const labels = ref([]);
|
|
242
241
|
const isEmptyModelValue = computed(() => isEmpty(props2.modelValue));
|
|
243
242
|
const cursor = computed(() => props2.disabled || props2.readonly ? "" : "pointer");
|
|
244
243
|
const offsetY = ref(0);
|
|
245
244
|
const { bindForm, form } = useForm();
|
|
246
245
|
const { length, options, bindOptions } = useOptions();
|
|
246
|
+
const { label, labels, computeLabel, getSelectedValue } = useSelectController({
|
|
247
|
+
modelValue: () => props2.modelValue,
|
|
248
|
+
multiple: () => props2.multiple,
|
|
249
|
+
optionProviders: () => options,
|
|
250
|
+
optionProvidersLength: () => length.value
|
|
251
|
+
});
|
|
247
252
|
const {
|
|
248
253
|
errorMessage,
|
|
249
254
|
validateWithTrigger: vt,
|
|
@@ -285,43 +290,14 @@ const __sfc__ = defineComponent({
|
|
|
285
290
|
}
|
|
286
291
|
}
|
|
287
292
|
);
|
|
288
|
-
watch(() => props2.modelValue, syncOptions, { deep: true });
|
|
289
|
-
watch(() => length.value, syncOptions);
|
|
290
293
|
bindOptions(selectProvider);
|
|
291
294
|
call(bindForm, selectProvider);
|
|
292
|
-
function computeLabel() {
|
|
293
|
-
const { multiple: multiple2, modelValue } = props2;
|
|
294
|
-
if (multiple2) {
|
|
295
|
-
const rawModelValue = modelValue;
|
|
296
|
-
labels.value = rawModelValue.map(findLabel);
|
|
297
|
-
}
|
|
298
|
-
if (!multiple2 && !isEmpty(modelValue)) {
|
|
299
|
-
label.value = findLabel(modelValue);
|
|
300
|
-
}
|
|
301
|
-
if (!multiple2 && isEmpty(modelValue)) {
|
|
302
|
-
label.value = "";
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
295
|
function validateWithTrigger(trigger) {
|
|
306
296
|
nextTick(() => {
|
|
307
297
|
const { validateTrigger, rules, modelValue } = props2;
|
|
308
298
|
vt(validateTrigger, trigger, rules, modelValue);
|
|
309
299
|
});
|
|
310
300
|
}
|
|
311
|
-
function findValueOrLabel({ value, label: label2 }) {
|
|
312
|
-
if (value.value != null) {
|
|
313
|
-
return value.value;
|
|
314
|
-
}
|
|
315
|
-
return label2.value;
|
|
316
|
-
}
|
|
317
|
-
function findLabel(modelValue) {
|
|
318
|
-
var _a;
|
|
319
|
-
let option = options.find(({ value }) => value.value === modelValue);
|
|
320
|
-
if (!option) {
|
|
321
|
-
option = options.find(({ label: label2 }) => label2.value === modelValue);
|
|
322
|
-
}
|
|
323
|
-
return (_a = option == null ? void 0 : option.label.value) != null ? _a : "";
|
|
324
|
-
}
|
|
325
301
|
function handleFocus() {
|
|
326
302
|
const { disabled, readonly, onFocus } = props2;
|
|
327
303
|
if ((form == null ? void 0 : form.disabled.value) || (form == null ? void 0 : form.readonly.value) || disabled || readonly) {
|
|
@@ -346,7 +322,7 @@ const __sfc__ = defineComponent({
|
|
|
346
322
|
if ((form == null ? void 0 : form.disabled.value) || (form == null ? void 0 : form.readonly.value) || disabled || readonly) {
|
|
347
323
|
return;
|
|
348
324
|
}
|
|
349
|
-
const selectedValue =
|
|
325
|
+
const selectedValue = getSelectedValue(option);
|
|
350
326
|
call(props2["onUpdate:modelValue"], selectedValue);
|
|
351
327
|
call(onChange, selectedValue);
|
|
352
328
|
validateWithTrigger("onChange");
|
|
@@ -377,26 +353,17 @@ const __sfc__ = defineComponent({
|
|
|
377
353
|
if ((form == null ? void 0 : form.disabled.value) || (form == null ? void 0 : form.readonly.value) || disabled || readonly) {
|
|
378
354
|
return;
|
|
379
355
|
}
|
|
380
|
-
const rawModelValue = modelValue;
|
|
381
356
|
const option = options.find(({ label: label2 }) => label2.value === text);
|
|
382
|
-
const currentModelValue =
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
357
|
+
const currentModelValue = modelValue.filter(
|
|
358
|
+
(value) => {
|
|
359
|
+
var _a;
|
|
360
|
+
return value !== ((_a = option.value.value) != null ? _a : option.label.value);
|
|
361
|
+
}
|
|
362
|
+
);
|
|
386
363
|
call(props2["onUpdate:modelValue"], currentModelValue);
|
|
387
364
|
call(onClose, currentModelValue);
|
|
388
365
|
validateWithTrigger("onClose");
|
|
389
366
|
}
|
|
390
|
-
function syncOptions() {
|
|
391
|
-
const { multiple: multiple2, modelValue } = props2;
|
|
392
|
-
if (multiple2) {
|
|
393
|
-
const rawModelValue = modelValue;
|
|
394
|
-
options.forEach((option) => option.sync(rawModelValue.includes(findValueOrLabel(option))));
|
|
395
|
-
} else {
|
|
396
|
-
options.forEach((option) => option.sync(modelValue === findValueOrLabel(option)));
|
|
397
|
-
}
|
|
398
|
-
computeLabel();
|
|
399
|
-
}
|
|
400
367
|
function focus() {
|
|
401
368
|
offsetY.value = toPxNum(props2.offsetY);
|
|
402
369
|
isFocus.value = true;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ref, watch } from "vue";
|
|
2
|
+
import { isEmpty } from "@varlet/shared";
|
|
3
|
+
function useSelectController(options) {
|
|
4
|
+
const {
|
|
5
|
+
multiple: multipleGetter,
|
|
6
|
+
modelValue: modelValueGetter,
|
|
7
|
+
optionProviders: optionProvidersGetter,
|
|
8
|
+
optionProvidersLength: optionProvidersLengthGetter
|
|
9
|
+
} = options;
|
|
10
|
+
const label = ref("");
|
|
11
|
+
const labels = ref([]);
|
|
12
|
+
watch(modelValueGetter, syncOptions, { deep: true });
|
|
13
|
+
watch(optionProvidersLengthGetter, syncOptions);
|
|
14
|
+
function computeLabel() {
|
|
15
|
+
const multiple = multipleGetter();
|
|
16
|
+
const modelValue = modelValueGetter();
|
|
17
|
+
if (multiple) {
|
|
18
|
+
labels.value = modelValue.map(findLabel);
|
|
19
|
+
}
|
|
20
|
+
if (!multiple && !isEmpty(modelValue)) {
|
|
21
|
+
label.value = findLabel(modelValue);
|
|
22
|
+
}
|
|
23
|
+
if (!multiple && isEmpty(modelValue)) {
|
|
24
|
+
label.value = "";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function findLabel(targetValue) {
|
|
28
|
+
var _a;
|
|
29
|
+
const options2 = optionProvidersGetter();
|
|
30
|
+
let option = options2.find(({ value }) => value.value === targetValue);
|
|
31
|
+
if (!option) {
|
|
32
|
+
option = options2.find(({ label: label2 }) => label2.value === targetValue);
|
|
33
|
+
}
|
|
34
|
+
return (_a = option == null ? void 0 : option.label.value) != null ? _a : "";
|
|
35
|
+
}
|
|
36
|
+
function findValueOrLabel({ value, label: label2 }) {
|
|
37
|
+
if (value.value != null) {
|
|
38
|
+
return value.value;
|
|
39
|
+
}
|
|
40
|
+
return label2.value;
|
|
41
|
+
}
|
|
42
|
+
function getSelectedValue(option) {
|
|
43
|
+
const multiple = multipleGetter();
|
|
44
|
+
const options2 = optionProvidersGetter();
|
|
45
|
+
return multiple ? options2.filter(({ selected }) => selected.value).map(findValueOrLabel) : findValueOrLabel(option);
|
|
46
|
+
}
|
|
47
|
+
function syncOptions() {
|
|
48
|
+
const multiple = multipleGetter();
|
|
49
|
+
const modelValue = modelValueGetter();
|
|
50
|
+
const options2 = optionProvidersGetter();
|
|
51
|
+
if (multiple) {
|
|
52
|
+
options2.forEach((option) => option.sync(modelValue.includes(findValueOrLabel(option))));
|
|
53
|
+
} else {
|
|
54
|
+
options2.forEach((option) => option.sync(modelValue === findValueOrLabel(option)));
|
|
55
|
+
}
|
|
56
|
+
computeLabel();
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
label,
|
|
60
|
+
labels,
|
|
61
|
+
computeLabel,
|
|
62
|
+
getSelectedValue
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
useSelectController
|
|
67
|
+
};
|
package/es/slider/Slider.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { useValidation, createNamespace, call } from "../utils/components.mjs";
|
|
|
6
6
|
import { useForm } from "../form/provide.mjs";
|
|
7
7
|
import { getLeft, multiplySizeUnit } from "../utils/elements.mjs";
|
|
8
8
|
import { warn } from "../utils/logger.mjs";
|
|
9
|
-
import { isArray, isNumber, toNumber, getRect } from "@varlet/shared";
|
|
9
|
+
import { isArray, isNumber, toNumber, getRect, preventDefault } from "@varlet/shared";
|
|
10
10
|
import { props, Thumbs } from "./props.mjs";
|
|
11
11
|
import { onSmartMounted } from "@varlet/use";
|
|
12
12
|
const { name, n, classes } = createNamespace("slider");
|
|
@@ -367,7 +367,7 @@ const __sfc__ = defineComponent({
|
|
|
367
367
|
thumbsProps[type].startPosition = isVertical.value ? clientY : clientX;
|
|
368
368
|
}
|
|
369
369
|
function move(event) {
|
|
370
|
-
|
|
370
|
+
preventDefault(event);
|
|
371
371
|
if (isDisabled.value || isReadonly.value || !isScroll.value)
|
|
372
372
|
return;
|
|
373
373
|
const { startPosition, currentOffset } = thumbsProps[activeThumb];
|