@varlet/ui 2.19.2 → 2.19.3-alpha.1701190302604

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.
@@ -2,7 +2,7 @@ import { computed, defineComponent, nextTick, watch } from "vue";
2
2
  import { useCollapseItem } from "./provide.mjs";
3
3
  import { props } from "./props.mjs";
4
4
  import { createNamespace } from "../utils/components.mjs";
5
- import { isArray, call } from "@varlet/shared";
5
+ import { normalizeToArray, call, isArray, removeArrayBlank } from "@varlet/shared";
6
6
  const { name, n } = createNamespace("collapse");
7
7
  import { renderSlot as _renderSlot, normalizeClass as _normalizeClass, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue";
8
8
  function __render__(_ctx, _cache) {
@@ -22,13 +22,12 @@ const __sfc__ = defineComponent({
22
22
  name,
23
23
  props,
24
24
  setup(props2) {
25
- const active = computed(() => props2.modelValue);
26
25
  const offset = computed(() => props2.offset);
27
26
  const divider = computed(() => props2.divider);
28
27
  const elevation = computed(() => props2.elevation);
29
- const { length, collapseItem, bindCollapseItem } = useCollapseItem();
28
+ const normalizeValues = computed(() => normalizeToArray(props2.modelValue));
29
+ const { length, collapseItems, bindCollapseItems } = useCollapseItem();
30
30
  const collapseProvider = {
31
- active,
32
31
  offset,
33
32
  divider,
34
33
  elevation,
@@ -42,64 +41,44 @@ const __sfc__ = defineComponent({
42
41
  () => props2.modelValue,
43
42
  () => nextTick().then(resize)
44
43
  );
45
- bindCollapseItem(collapseProvider);
46
- function checkValue() {
47
- if (!props2.accordion && !isArray(props2.modelValue)) {
48
- console.error('[Varlet] Collapse: type of prop "modelValue" should be an Array');
49
- return false;
50
- }
51
- if (props2.accordion && isArray(props2.modelValue)) {
52
- console.error('[Varlet] Collapse: type of prop "modelValue" should be a String or Number');
53
- return false;
44
+ bindCollapseItems(collapseProvider);
45
+ function updateItem(itemValue, targetExpand) {
46
+ if (props2.accordion) {
47
+ const value2 = targetExpand ? itemValue : void 0;
48
+ updateModelValue(isArray(props2.modelValue) ? removeArrayBlank([value2]) : value2);
49
+ return;
54
50
  }
55
- return true;
51
+ const value = targetExpand ? [...normalizeValues.value, itemValue] : normalizeValues.value.filter((value2) => value2 !== itemValue);
52
+ updateModelValue(value);
56
53
  }
57
- function getValue(value, isExpand) {
58
- if (!checkValue())
59
- return null;
60
- if (isExpand)
61
- return props2.accordion ? value : [...props2.modelValue, value];
62
- return props2.accordion ? null : props2.modelValue.filter((name2) => name2 !== value);
63
- }
64
- function updateItem(value, isExpand) {
65
- const modelValue = getValue(value, isExpand);
54
+ function updateModelValue(modelValue) {
66
55
  call(props2["onUpdate:modelValue"], modelValue);
67
56
  call(props2.onChange, modelValue);
68
57
  }
69
- function matchName() {
70
- if (props2.accordion) {
71
- return collapseItem.find(({ name: name2 }) => props2.modelValue === name2.value);
72
- }
73
- const filterItem = collapseItem.filter(({ name: name2 }) => {
74
- if (name2.value === void 0)
75
- return false;
76
- return props2.modelValue.includes(name2.value);
77
- });
78
- return filterItem.length ? filterItem : void 0;
79
- }
80
- function matchIndex() {
58
+ function matchItems() {
81
59
  if (props2.accordion) {
82
- return collapseItem.find(
83
- ({ index, name: name2 }) => name2.value === void 0 && props2.modelValue === index.value
84
- );
60
+ const [value] = normalizeValues.value;
61
+ if (value == null) {
62
+ return;
63
+ }
64
+ const matchedNameItem = collapseItems.find(({ name: name2 }) => value === name2.value);
65
+ if (matchedNameItem == null) {
66
+ return collapseItems.find(({ index, name: name2 }) => name2.value == null && value === index.value);
67
+ }
68
+ return matchedNameItem;
85
69
  }
86
- return collapseItem.filter(
87
- ({ index, name: name2 }) => name2.value === void 0 && props2.modelValue.includes(index.value)
70
+ const matchedNameItems = collapseItems.filter(
71
+ ({ name: name2 }) => name2.value != null && normalizeValues.value.includes(name2.value)
72
+ );
73
+ const matchedIndexItems = collapseItems.filter(
74
+ ({ index, name: name2 }) => name2.value == null && normalizeValues.value.includes(index.value)
88
75
  );
76
+ return [...matchedNameItems, ...matchedIndexItems];
89
77
  }
90
78
  function resize() {
91
- if (!checkValue())
92
- return;
93
- const matchProviders = matchName() || matchIndex();
94
- if (props2.accordion && !matchProviders || !props2.accordion && !matchProviders.length) {
95
- collapseItem.forEach((provider) => {
96
- provider.init(props2.accordion, false);
97
- });
98
- return;
99
- }
100
- collapseItem.forEach((provider) => {
101
- const isShow = props2.accordion ? matchProviders === provider : matchProviders.includes(provider);
102
- provider.init(props2.accordion, isShow);
79
+ const matchedItems = removeArrayBlank(normalizeToArray(matchItems()));
80
+ collapseItems.forEach((collapseItem) => {
81
+ collapseItem.init(matchedItems.includes(collapseItem));
103
82
  });
104
83
  }
105
84
  return {
@@ -6,8 +6,8 @@ function useCollapseItem() {
6
6
  );
7
7
  return {
8
8
  length,
9
- collapseItem: childProviders,
10
- bindCollapseItem: bindChildren
9
+ collapseItems: childProviders,
10
+ bindCollapseItems: bindChildren
11
11
  };
12
12
  }
13
13
  export {
@@ -20,7 +20,7 @@ var __async = (__this, __arguments, generator) => {
20
20
  };
21
21
  import VarIcon from "../icon/index.mjs";
22
22
  import { defineComponent, ref, watch, computed } from "vue";
23
- import { isArray, doubleRaf, raf } from "@varlet/shared";
23
+ import { doubleRaf, raf } from "@varlet/shared";
24
24
  import { createNamespace, formatElevation } from "../utils/components.mjs";
25
25
  import { useCollapse } from "./provide.mjs";
26
26
  import { props } from "./props.mjs";
@@ -48,7 +48,7 @@ function __render__(_ctx, _cache) {
48
48
  "div",
49
49
  {
50
50
  class: _normalizeClass(_ctx.n("header")),
51
- onClick: _cache[0] || (_cache[0] = ($event) => _ctx.toggle())
51
+ onClick: _cache[0] || (_cache[0] = (...args) => _ctx.toggle && _ctx.toggle(...args))
52
52
  },
53
53
  [
54
54
  _createElementVNode(
@@ -138,7 +138,7 @@ const __sfc__ = defineComponent({
138
138
  const contentEl = ref(null);
139
139
  const name2 = computed(() => props2.name);
140
140
  const { index, collapse, bindCollapse } = useCollapse();
141
- const { active, offset, divider, elevation, updateItem } = collapse;
141
+ const { offset, divider, elevation, updateItem } = collapse;
142
142
  const collapseItemProvider = {
143
143
  index,
144
144
  name: name2,
@@ -187,18 +187,15 @@ const __sfc__ = defineComponent({
187
187
  contentEl.value.style.height = "0px";
188
188
  });
189
189
  }
190
- function init(accordion, show) {
191
- if (active.value === void 0 || accordion && isArray(active.value) || show === isShow.value)
192
- return;
190
+ function init(show) {
193
191
  isShow.value = show;
194
- toggle(true);
195
192
  }
196
- function toggle(initOrAccordion) {
197
- if (props2.disabled)
193
+ function toggle() {
194
+ var _a;
195
+ if (props2.disabled) {
198
196
  return;
199
- if (!initOrAccordion) {
200
- updateItem(props2.name || index.value, !isShow.value);
201
197
  }
198
+ updateItem((_a = props2.name) != null ? _a : index.value, !isShow.value);
202
199
  }
203
200
  function start() {
204
201
  isInitToTrigger = false;
@@ -189,9 +189,10 @@ const __sfc__ = defineComponent({
189
189
  );
190
190
  const sortWeekList = computed(() => {
191
191
  const index = WEEK_HEADER.findIndex((week) => week === props.componentProps.firstDayOfWeek);
192
- if (index === -1 || index === 0)
192
+ if (index === -1 || index === 0) {
193
193
  return WEEK_HEADER;
194
- return WEEK_HEADER.slice(index).concat(WEEK_HEADER.slice(0, index));
194
+ }
195
+ return [...WEEK_HEADER.slice(index), ...WEEK_HEADER.slice(0, index)];
195
196
  });
196
197
  const getDayAbbr = (key) => {
197
198
  var _a, _b;
@@ -259,7 +259,7 @@ import './tooltip/style/index.mjs'
259
259
  import './uploader/style/index.mjs'
260
260
  import './watermark/style/index.mjs'
261
261
 
262
- const version = '2.19.2'
262
+ const version = '2.19.3-alpha.1701190302604'
263
263
 
264
264
  function install(app) {
265
265
  ActionSheet.install && app.use(ActionSheet)
package/es/index.mjs CHANGED
@@ -172,7 +172,7 @@ export * from './tooltip/index.mjs'
172
172
  export * from './uploader/index.mjs'
173
173
  export * from './watermark/index.mjs'
174
174
 
175
- const version = '2.19.2'
175
+ const version = '2.19.3-alpha.1701190302604'
176
176
 
177
177
  function install(app) {
178
178
  ActionSheet.install && app.use(ActionSheet)
@@ -248,7 +248,11 @@ const __sfc__ = defineComponent({
248
248
  if (props2.type === "number") {
249
249
  value = formatNumber(value);
250
250
  }
251
- return withMaxlength(withTrim(value));
251
+ const targetValue = withMaxlength(withTrim(value));
252
+ if (targetValue === props2.modelValue) {
253
+ target.value = targetValue;
254
+ }
255
+ return targetValue;
252
256
  }
253
257
  function handleCompositionStart() {
254
258
  isComposing.value = true;