@volverjs/ui-vue 0.0.10-beta.23 → 0.0.10-beta.24

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 (89) hide show
  1. package/dist/components/VvAccordion/VvAccordion.es.js +119 -79
  2. package/dist/components/VvAccordion/VvAccordion.umd.js +1 -1
  3. package/dist/components/VvAccordion/VvAccordion.vue.d.ts +18 -4
  4. package/dist/components/VvAccordion/index.d.ts +4 -8
  5. package/dist/components/VvAccordionGroup/VvAccordionGroup.es.js +250 -119
  6. package/dist/components/VvAccordionGroup/VvAccordionGroup.umd.js +1 -1
  7. package/dist/components/VvAccordionGroup/VvAccordionGroup.vue.d.ts +18 -6
  8. package/dist/components/VvAccordionGroup/index.d.ts +3 -1
  9. package/dist/components/VvAction/VvAction.vue.d.ts +1 -1
  10. package/dist/components/VvAlert/VvAlert.vue.d.ts +1 -1
  11. package/dist/components/VvButton/VvButton.es.js +92 -98
  12. package/dist/components/VvButton/VvButton.umd.js +1 -1
  13. package/dist/components/VvButton/VvButton.vue.d.ts +7 -7
  14. package/dist/components/VvButton/index.d.ts +11 -11
  15. package/dist/components/VvButtonGroup/VvButtonGroup.es.js +7 -13
  16. package/dist/components/VvButtonGroup/VvButtonGroup.umd.js +1 -1
  17. package/dist/components/VvButtonGroup/VvButtonGroup.vue.d.ts +3 -3
  18. package/dist/components/VvCheckbox/VvCheckbox.es.js +81 -87
  19. package/dist/components/VvCheckbox/VvCheckbox.umd.js +1 -1
  20. package/dist/components/VvCheckbox/VvCheckbox.vue.d.ts +6 -6
  21. package/dist/components/VvCheckbox/index.d.ts +2 -2
  22. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.es.js +15 -29
  23. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.umd.js +1 -1
  24. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.vue.d.ts +5 -5
  25. package/dist/components/VvCombobox/VvCombobox.es.js +13 -16
  26. package/dist/components/VvCombobox/VvCombobox.umd.js +1 -1
  27. package/dist/components/VvCombobox/VvCombobox.vue.d.ts +11 -11
  28. package/dist/components/VvCombobox/index.d.ts +1 -1
  29. package/dist/components/VvDropdown/VvDropdown.vue.d.ts +5 -5
  30. package/dist/components/VvDropdown/VvDropdownAction.vue.d.ts +1 -1
  31. package/dist/components/VvDropdown/VvDropdownOption.vue.d.ts +1 -1
  32. package/dist/components/VvDropdown/index.d.ts +1 -1
  33. package/dist/components/VvInputFile/VvInputFile.es.js +183 -168
  34. package/dist/components/VvInputFile/VvInputFile.umd.js +1 -1
  35. package/dist/components/VvInputFile/VvInputFile.vue.d.ts +16 -9
  36. package/dist/components/VvInputFile/index.d.ts +12 -3
  37. package/dist/components/VvInputText/VvInputClearAction.d.ts +1 -1
  38. package/dist/components/VvInputText/VvInputStepAction.d.ts +1 -1
  39. package/dist/components/VvInputText/VvInputText.vue.d.ts +6 -6
  40. package/dist/components/VvProgress/VvProgress.vue.d.ts +1 -1
  41. package/dist/components/VvRadio/VvRadio.es.js +64 -70
  42. package/dist/components/VvRadio/VvRadio.umd.js +1 -1
  43. package/dist/components/VvRadio/VvRadio.vue.d.ts +6 -6
  44. package/dist/components/VvRadio/index.d.ts +6 -6
  45. package/dist/components/VvRadioGroup/VvRadioGroup.es.js +15 -29
  46. package/dist/components/VvRadioGroup/VvRadioGroup.umd.js +1 -1
  47. package/dist/components/VvRadioGroup/VvRadioGroup.vue.d.ts +5 -5
  48. package/dist/components/VvSelect/VvSelect.vue.d.ts +8 -8
  49. package/dist/components/VvTextarea/VvTextarea.vue.d.ts +5 -5
  50. package/dist/components/VvTooltip/VvTooltip.vue.d.ts +3 -3
  51. package/dist/components/VvTooltip/index.d.ts +1 -1
  52. package/dist/components/index.es.js +462 -323
  53. package/dist/components/index.umd.js +1 -1
  54. package/dist/composables/alert/useInjectAlert.d.ts +1 -6
  55. package/dist/composables/group/useInjectedGroupState.d.ts +4 -5
  56. package/dist/composables/group/useProvideGroupState.d.ts +3 -3
  57. package/dist/constants.d.ts +6 -10
  58. package/dist/icons.es.js +3 -3
  59. package/dist/icons.umd.js +1 -1
  60. package/dist/index.es.js +3 -2
  61. package/dist/index.umd.js +1 -1
  62. package/dist/props/index.d.ts +1 -1
  63. package/dist/resolvers/unplugin.es.js +3 -2
  64. package/dist/resolvers/unplugin.umd.js +1 -1
  65. package/dist/stories/AccordionGroup/AccordionGroup.stories.d.ts +38 -14
  66. package/dist/stories/AccordionGroup/AccordionGroupSlots.stories.d.ts +259 -101
  67. package/dist/types/group.d.ts +37 -15
  68. package/package.json +37 -36
  69. package/src/assets/icons/detailed.json +1 -1
  70. package/src/assets/icons/normal.json +1 -1
  71. package/src/assets/icons/simple.json +1 -1
  72. package/src/components/VvAccordion/VvAccordion.vue +119 -56
  73. package/src/components/VvAccordion/index.ts +8 -23
  74. package/src/components/VvAccordionGroup/VvAccordionGroup.vue +140 -41
  75. package/src/components/VvAccordionGroup/index.ts +3 -1
  76. package/src/components/VvButton/index.ts +7 -12
  77. package/src/components/VvButtonGroup/VvButtonGroup.vue +1 -2
  78. package/src/components/VvCheckbox/index.ts +2 -2
  79. package/src/components/VvCheckboxGroup/VvCheckboxGroup.vue +1 -2
  80. package/src/components/VvInputFile/VvInputFile.vue +71 -47
  81. package/src/components/VvInputFile/index.ts +5 -4
  82. package/src/components/VvRadio/index.ts +5 -5
  83. package/src/components/VvRadioGroup/VvRadioGroup.vue +1 -2
  84. package/src/composables/group/useInjectedGroupState.ts +20 -16
  85. package/src/composables/group/useProvideGroupState.ts +10 -15
  86. package/src/constants.ts +19 -14
  87. package/src/stories/AccordionGroup/AccordionGroup.test.ts +15 -9
  88. package/src/stories/AccordionGroup/AccordionGroupSlots.stories.ts +1 -1
  89. package/src/types/group.ts +22 -14
@@ -1,6 +1,7 @@
1
- import { unref, inject, computed, toRef, toRefs, defineComponent, useAttrs, ref, openBlock, createElementBlock, normalizeClass, createElementVNode, withModifiers, renderSlot, normalizeProps, guardReactiveProps, createTextVNode, toDisplayString, isRef, provide, watchEffect, watch, Fragment, renderList, createBlock, mergeProps, withCtx } from "vue";
1
+ import { inject, computed, toRef, unref, defineComponent, useAttrs, toRefs, ref, watch, onBeforeUnmount, openBlock, createElementBlock, normalizeClass, createElementVNode, withModifiers, renderSlot, normalizeProps, guardReactiveProps, createTextVNode, toDisplayString, provide, watchEffect, reactive, Fragment, renderList, createBlock, mergeProps, withCtx } from "vue";
2
+ import mitt from "mitt";
2
3
  import { uid } from "uid";
3
- import { useToggle, useStorage } from "@vueuse/core";
4
+ import { useVModel, useLocalStorage } from "@vueuse/core";
4
5
  var Strategy = /* @__PURE__ */ ((Strategy2) => {
5
6
  Strategy2["absolute"] = "absolute";
6
7
  Strategy2["fixed"] = "fixed";
@@ -49,7 +50,9 @@ var AnchorTarget = /* @__PURE__ */ ((AnchorTarget2) => {
49
50
  AnchorTarget2["_top"] = "_top";
50
51
  return AnchorTarget2;
51
52
  })(AnchorTarget || {});
52
- const INJECTION_KEY_ACCORDION_GROUP = Symbol.for("accordionGroup");
53
+ const INJECTION_KEY_ACCORDION_GROUP = Symbol.for(
54
+ "accordionGroup"
55
+ );
53
56
  const LinkProps = {
54
57
  /**
55
58
  * The router-link/nuxt-link property, if it is defined the button is rendered as a ruouter-link or nuxt-link.
@@ -274,18 +277,15 @@ const ModifiersProps = {
274
277
  default: ActionTag.button
275
278
  }
276
279
  });
277
- function isEmpty(value) {
278
- return ((value2) => value2 === null || value2 === void 0 || value2 === "" || Array.isArray(value2) && value2.length === 0 || !(value2 instanceof Date) && typeof value2 === "object" && Object.keys(value2).length === 0)(unref(value));
279
- }
280
280
  function useInjectedGroupState(groupKey) {
281
281
  const group = inject(groupKey, void 0);
282
- const isInGroup = computed(() => !isEmpty(group));
282
+ const isInGroup = computed(() => group !== void 0);
283
283
  function getGroupOrLocalRef(propName, props, emit) {
284
- if (group == null ? void 0 : group.value) {
285
- const groupPropValue = unref(group.value)[propName];
284
+ const groupPropValue = group == null ? void 0 : group[propName];
285
+ if (groupPropValue) {
286
286
  return computed({
287
287
  get() {
288
- return groupPropValue == null ? void 0 : groupPropValue.value;
288
+ return groupPropValue.value;
289
289
  },
290
290
  set(value) {
291
291
  groupPropValue.value = value;
@@ -298,8 +298,9 @@ function useInjectedGroupState(groupKey) {
298
298
  return propRef.value;
299
299
  },
300
300
  set(value) {
301
- if (emit)
301
+ if (emit) {
302
302
  emit(`update:${propName}`, value);
303
+ }
303
304
  }
304
305
  });
305
306
  }
@@ -340,23 +341,16 @@ const VvAccordionProps = {
340
341
  not: Boolean
341
342
  };
342
343
  const VvAccordionEvents = ["update:modelValue"];
343
- function useGroupProps(props, emit) {
344
- const { group, isInGroup, getGroupOrLocalRef } = useInjectedGroupState(
344
+ function useGroupProps(props) {
345
+ const { group, isInGroup } = useInjectedGroupState(
345
346
  INJECTION_KEY_ACCORDION_GROUP
346
347
  );
347
- const { title, content } = toRefs(props);
348
- const modelValue = getGroupOrLocalRef("modelValue", props, emit);
349
- const not = getGroupOrLocalRef("not", props);
350
- const collapse = getGroupOrLocalRef("collapse", props);
351
348
  const disabled = computed(
352
- () => {
353
- var _a;
354
- return Boolean(props.disabled || ((_a = group == null ? void 0 : group.value) == null ? void 0 : _a.disabled.value));
355
- }
349
+ () => Boolean(props.disabled || (group == null ? void 0 : group.disabled.value))
356
350
  );
357
351
  const modifiers = computed(() => {
358
352
  let localModifiers = props.modifiers;
359
- let groupModifiers = group == null ? void 0 : group.value.modifiers.value;
353
+ let groupModifiers = group == null ? void 0 : group.modifiers.value;
360
354
  const toReturn = /* @__PURE__ */ new Set();
361
355
  if (localModifiers) {
362
356
  if (!Array.isArray(localModifiers)) {
@@ -374,16 +368,11 @@ function useGroupProps(props, emit) {
374
368
  });
375
369
  return {
376
370
  // group props
377
- modelValue,
378
- not,
379
371
  isInGroup,
380
372
  group,
381
- collapse,
382
373
  modifiers,
383
374
  disabled,
384
- // local props
385
- title,
386
- content
375
+ bus: group == null ? void 0 : group.bus
387
376
  };
388
377
  }
389
378
  function useModifiers(prefix, modifiers, others) {
@@ -419,62 +408,103 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
419
408
  ...__default__$1,
420
409
  props: VvAccordionProps,
421
410
  emits: VvAccordionEvents,
422
- setup(__props, { emit: __emit }) {
411
+ setup(__props, { expose: __expose, emit: __emit }) {
423
412
  const props = __props;
424
413
  const attrs = useAttrs();
425
414
  const emit = __emit;
415
+ const modelValue = useVModel(props, "modelValue", emit);
426
416
  const accordionName = computed(
427
417
  () => props.name || (attrs == null ? void 0 : attrs.id) || uid()
428
418
  );
429
- const {
430
- modifiers,
431
- title,
432
- content,
433
- disabled,
434
- collapse,
419
+ const { title, content, not } = toRefs(props);
420
+ const { isInGroup, modifiers, disabled, bus } = useGroupProps(props);
421
+ const isExpanded = ref(false);
422
+ watch(
435
423
  modelValue,
436
- isInGroup,
437
- not
438
- } = useGroupProps(props, emit);
439
- const localModelValue = ref(false);
440
- const isOpen = computed({
441
- get: () => {
442
- let toReturn = modelValue.value;
443
- if (isInGroup.value) {
444
- if (collapse.value && Array.isArray(modelValue.value)) {
445
- toReturn = modelValue.value.includes(accordionName.value);
446
- } else {
447
- toReturn = modelValue.value === accordionName.value;
448
- }
449
- } else if (modelValue.value === void 0) {
450
- toReturn = localModelValue.value;
424
+ (newValue) => {
425
+ if (typeof newValue === "boolean") {
426
+ isExpanded.value = not.value ? !newValue : newValue;
451
427
  }
452
- return not.value ? !toReturn : toReturn;
453
428
  },
454
- set: (newValue) => {
455
- if (not.value) {
456
- newValue = !newValue;
457
- }
458
- if (isInGroup.value) {
459
- if (collapse.value && Array.isArray(modelValue.value)) {
460
- if (newValue) {
461
- modelValue.value.push(accordionName.value);
462
- return;
463
- }
464
- modelValue.value = modelValue.value.filter(
465
- (name) => name !== accordionName.value
466
- );
467
- return;
429
+ { immediate: true }
430
+ );
431
+ watch(isExpanded, (newValue) => {
432
+ modelValue.value = not.value ? !newValue : newValue;
433
+ });
434
+ bus == null ? void 0 : bus.on("toggle", ({ name, value }) => {
435
+ if (name !== accordionName.value) {
436
+ return;
437
+ }
438
+ isExpanded.value = value;
439
+ });
440
+ const onClick = () => {
441
+ if (disabled.value) {
442
+ return;
443
+ }
444
+ if (isInGroup.value) {
445
+ bus == null ? void 0 : bus.emit("toggle", {
446
+ name: accordionName.value,
447
+ value: !isExpanded.value
448
+ });
449
+ return;
450
+ }
451
+ isExpanded.value = !isExpanded.value;
452
+ };
453
+ watch(
454
+ accordionName,
455
+ (newValue, oldValue) => {
456
+ if (bus) {
457
+ if (oldValue && oldValue !== newValue) {
458
+ bus.emit("unregister", { name: oldValue });
468
459
  }
469
- modelValue.value = newValue ? accordionName.value : null;
470
- return;
471
- }
472
- if (modelValue.value === void 0 && typeof newValue === "boolean") {
473
- localModelValue.value = newValue;
474
- return;
460
+ bus.emit("register", { name: newValue });
475
461
  }
476
- modelValue.value = newValue;
462
+ },
463
+ {
464
+ immediate: true
465
+ }
466
+ );
467
+ onBeforeUnmount(() => {
468
+ if (bus) {
469
+ bus.emit("unregister", { name: accordionName.value });
470
+ }
471
+ });
472
+ const expand = () => {
473
+ if (isExpanded.value) {
474
+ return;
475
+ }
476
+ onClick();
477
+ };
478
+ const collapse = () => {
479
+ if (!isExpanded.value) {
480
+ return;
477
481
  }
482
+ onClick();
483
+ };
484
+ const groupExpand = (name) => {
485
+ if (!bus) {
486
+ console.warn(
487
+ `[VvAccordion]: You are trying to expand accordion group of "${accordionName.value}" but it is not in a group`
488
+ );
489
+ return;
490
+ }
491
+ bus.emit("expand", { name });
492
+ };
493
+ const groupCollapse = (name) => {
494
+ if (!bus) {
495
+ console.warn(
496
+ `[VvAccordion]: You are trying to collapse accordion group of "${accordionName.value}" but it is not in a group`
497
+ );
498
+ return;
499
+ }
500
+ bus == null ? void 0 : bus.emit("collapse", { name });
501
+ };
502
+ __expose({
503
+ isExpanded,
504
+ expand,
505
+ collapse,
506
+ groupExpand,
507
+ groupCollapse
478
508
  });
479
509
  const bemCssClasses = useModifiers(
480
510
  "vv-accordion",
@@ -483,20 +513,25 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
483
513
  disabled: disabled.value
484
514
  }))
485
515
  );
486
- const onClick = useToggle(isOpen);
487
516
  return (_ctx, _cache) => {
488
517
  return openBlock(), createElementBlock("details", {
489
518
  id: unref(accordionName),
490
519
  class: normalizeClass(unref(bemCssClasses)),
491
- open: unref(isOpen)
520
+ open: unref(isExpanded)
492
521
  }, [
493
522
  createElementVNode("summary", {
494
523
  "aria-controls": unref(accordionName),
495
- "aria-expanded": unref(isOpen),
524
+ "aria-expanded": unref(isExpanded),
496
525
  class: "vv-accordion__summary",
497
- onClick: _cache[0] || (_cache[0] = withModifiers(($event) => unref(onClick)(), ["prevent"]))
526
+ onClick: _cache[0] || (_cache[0] = withModifiers(($event) => onClick(), ["prevent"]))
498
527
  }, [
499
- renderSlot(_ctx.$slots, "summary", normalizeProps(guardReactiveProps({ open: unref(isOpen) })), () => [
528
+ renderSlot(_ctx.$slots, "summary", normalizeProps(guardReactiveProps({
529
+ isExpanded: unref(isExpanded),
530
+ expand,
531
+ collapse,
532
+ groupExpand,
533
+ groupCollapse
534
+ })), () => [
500
535
  createTextVNode(
501
536
  toDisplayString(unref(title)),
502
537
  1
@@ -505,10 +540,16 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
505
540
  ])
506
541
  ], 8, _hoisted_2),
507
542
  createElementVNode("div", {
508
- "aria-hidden": !unref(isOpen),
543
+ "aria-hidden": !unref(isExpanded),
509
544
  class: "vv-accordion__content"
510
545
  }, [
511
- renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps({ open: unref(isOpen) })), () => [
546
+ renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps({
547
+ isExpanded: unref(isExpanded),
548
+ expand,
549
+ collapse,
550
+ groupExpand,
551
+ groupCollapse
552
+ })), () => [
512
553
  createTextVNode(
513
554
  toDisplayString(unref(content)),
514
555
  1
@@ -525,7 +566,9 @@ const VvAccordionGroupProps = {
525
566
  /**
526
567
  * VModel
527
568
  */
528
- modelValue: [String, Array],
569
+ modelValue: {
570
+ type: [String, Array]
571
+ },
529
572
  /**
530
573
  * Accordion items
531
574
  * @type VvAccordionGroupItem
@@ -559,15 +602,8 @@ const VvAccordionGroupProps = {
559
602
  storeKey: String
560
603
  };
561
604
  const VvAccordionGroupEvents = ["update:modelValue"];
562
- function useProvideGroupState(groupState) {
563
- if (Object.keys(groupState).some(
564
- (k) => k !== "key" && !isRef(groupState[k])
565
- ))
566
- throw Error("One or more groupState props aren't ref.");
567
- provide(
568
- groupState.key,
569
- computed(() => groupState)
570
- );
605
+ function useProvideGroupState(key, groupState) {
606
+ provide(key, groupState);
571
607
  }
572
608
  const __default__ = {
573
609
  name: "VvAccordionGroup"
@@ -576,58 +612,149 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
576
612
  ...__default__,
577
613
  props: VvAccordionGroupProps,
578
614
  emits: VvAccordionGroupEvents,
579
- setup(__props, { emit: __emit }) {
615
+ setup(__props, { expose: __expose, emit: __emit }) {
580
616
  const props = __props;
581
617
  const emit = __emit;
582
- const { disabled, collapse, modifiers, itemModifiers, items, not } = toRefs(props);
618
+ const { disabled, modifiers, itemModifiers, items } = toRefs(props);
583
619
  watchEffect(() => {
584
- if (typeof props.modelValue === "string" && collapse.value) {
620
+ if (typeof props.modelValue === "string" && props.collapse) {
585
621
  console.warn(
586
622
  `[VvAccordionGroup]: modelValue is a string but collapse is true.`
587
623
  );
588
624
  }
589
625
  });
590
- let localModelValue = ref([]);
626
+ const accordionNames = reactive(/* @__PURE__ */ new Set());
627
+ let modelValue = ref(/* @__PURE__ */ new Set());
591
628
  watch(
592
629
  () => props.storeKey,
593
- (newKey) => {
630
+ (newKey, oldKey) => {
631
+ if (oldKey && oldKey !== newKey) {
632
+ localStorage.removeItem(oldKey);
633
+ }
594
634
  if (newKey) {
595
- localModelValue = useStorage(newKey, localModelValue.value);
596
- } else {
597
- localModelValue = ref([]);
635
+ modelValue = useLocalStorage(newKey, modelValue.value);
636
+ return;
598
637
  }
638
+ modelValue = ref(new Set(modelValue.value));
599
639
  },
600
640
  { immediate: true }
601
641
  );
602
- const modelValue = computed({
603
- get: () => {
604
- var _a;
605
- if (props.modelValue !== void 0) {
606
- if (!collapse.value) {
607
- return Array.isArray(props.modelValue) ? props.modelValue[0] : props.modelValue;
608
- }
609
- return props.modelValue;
642
+ watch(
643
+ [modelValue, accordionNames, () => props.not, () => props.collapse],
644
+ () => {
645
+ if (props.not) {
646
+ emit(
647
+ "update:modelValue",
648
+ [...accordionNames].filter(
649
+ (name) => !modelValue.value.has(name)
650
+ )
651
+ );
652
+ return;
653
+ }
654
+ if (props.collapse) {
655
+ emit("update:modelValue", [...modelValue.value]);
656
+ return;
610
657
  }
611
- return !collapse.value ? (_a = localModelValue.value) == null ? void 0 : _a[0] : localModelValue.value;
658
+ emit("update:modelValue", modelValue.value.values().next().value);
612
659
  },
613
- set: (newValue) => {
614
- if (props.modelValue !== void 0) {
615
- if ((Array.isArray(props.modelValue) || collapse.value) && !Array.isArray(newValue)) {
616
- newValue = [newValue];
660
+ {
661
+ deep: true,
662
+ immediate: true
663
+ }
664
+ );
665
+ watch(
666
+ () => props.modelValue,
667
+ (newValue, oldValue) => {
668
+ if (newValue === void 0 || newValue === null || JSON.stringify(newValue) === JSON.stringify(oldValue)) {
669
+ return;
670
+ }
671
+ let toReturn = /* @__PURE__ */ new Set();
672
+ if (props.not) {
673
+ if (typeof newValue === "string") {
674
+ toReturn = new Set(
675
+ [...accordionNames].filter((name) => name !== newValue)
676
+ );
677
+ } else if (Array.isArray(newValue)) {
678
+ toReturn = new Set(
679
+ [...accordionNames].filter(
680
+ (name) => !newValue.includes(name)
681
+ )
682
+ );
617
683
  }
618
- return emit("update:modelValue", newValue);
684
+ } else if (typeof newValue === "string") {
685
+ toReturn = /* @__PURE__ */ new Set([newValue]);
686
+ } else if (Array.isArray(newValue)) {
687
+ toReturn = new Set(newValue);
688
+ }
689
+ for (const name of accordionNames) {
690
+ bus.emit("toggle", { name, value: toReturn.has(name) });
619
691
  }
620
- localModelValue.value = Array.isArray(newValue) ? newValue : [newValue];
692
+ modelValue.value = toReturn;
693
+ },
694
+ {
695
+ immediate: true
621
696
  }
622
- });
623
- useProvideGroupState({
624
- key: INJECTION_KEY_ACCORDION_GROUP,
625
- modelValue,
697
+ );
698
+ const bus = mitt();
699
+ useProvideGroupState(INJECTION_KEY_ACCORDION_GROUP, {
626
700
  disabled,
627
- collapse,
628
701
  modifiers: itemModifiers,
629
- not
702
+ bus
703
+ });
704
+ bus.on("register", ({ name }) => {
705
+ accordionNames.add(name);
706
+ });
707
+ bus.on("unregister", ({ name }) => {
708
+ accordionNames.delete(name);
709
+ });
710
+ bus.on("toggle", ({ name, value }) => {
711
+ if (value) {
712
+ if (!props.collapse) {
713
+ for (const item of modelValue.value) {
714
+ if (item !== name) {
715
+ bus.emit("toggle", { name: item, value: false });
716
+ }
717
+ }
718
+ modelValue.value.clear();
719
+ }
720
+ modelValue.value.add(name);
721
+ return;
722
+ }
723
+ modelValue.value.delete(name);
630
724
  });
725
+ const expand = (name) => {
726
+ if (typeof name === "string") {
727
+ bus.emit("toggle", { name, value: true });
728
+ return;
729
+ }
730
+ if (Array.isArray(name)) {
731
+ for (const item of name) {
732
+ bus.emit("toggle", { name: item, value: true });
733
+ }
734
+ return;
735
+ }
736
+ for (const item of accordionNames) {
737
+ bus.emit("toggle", { name: item, value: true });
738
+ }
739
+ };
740
+ bus.on("expand", ({ name }) => expand(name));
741
+ const collapse = (name) => {
742
+ if (typeof name === "string") {
743
+ bus.emit("toggle", { name, value: false });
744
+ return;
745
+ }
746
+ if (Array.isArray(name)) {
747
+ for (const item of name) {
748
+ bus.emit("toggle", { name: item, value: false });
749
+ }
750
+ return;
751
+ }
752
+ for (const item of accordionNames) {
753
+ bus.emit("toggle", { name: item, value: false });
754
+ }
755
+ };
756
+ bus.on("collapse", ({ name }) => collapse(name));
757
+ __expose({ modelValue, expand, collapse });
631
758
  const bemCssClasses = useModifiers(
632
759
  "vv-accordion-group",
633
760
  modifiers,
@@ -642,7 +769,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
642
769
  class: normalizeClass(unref(bemCssClasses))
643
770
  },
644
771
  [
645
- renderSlot(_ctx.$slots, "default", {}, () => [
772
+ renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps({
773
+ modelValue: unref(modelValue),
774
+ expand,
775
+ collapse
776
+ })), () => [
646
777
  (openBlock(true), createElementBlock(
647
778
  Fragment,
648
779
  null,
@@ -1 +1 @@
1
- !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o(require("vue"),require("uid"),require("@vueuse/core")):"function"==typeof define&&define.amd?define(["vue","uid","@vueuse/core"],o):(e="undefined"!=typeof globalThis?globalThis:e||self).VvAccordionGroup=o(e.vue,e.uid,e.core)}(this,(function(e,o,t){"use strict";var r=(e=>(e.left="left",e.right="right",e.top="top",e.bottom="bottom",e))(r||{}),l=(e=>(e.before="before",e.after="after",e))(l||{}),a=(e=>(e.button="button",e.submit="submit",e.reset="reset",e))(a||{}),n=(e=>(e.nuxtLink="nuxt-link",e.routerLink="router-link",e.a="a",e.button="button",e))(n||{});const u=Symbol.for("accordionGroup"),i=(Boolean,Boolean,Boolean,Boolean,{modifiers:{type:[String,Array],default:void 0}});function d(o){const t=e.inject(o,void 0),r=e.computed((()=>{return o=t,!(null==(r=e.unref(o))||""===r||Array.isArray(r)&&0===r.length||!(r instanceof Date)&&"object"==typeof r&&0===Object.keys(r).length);var o,r}));return{group:t,isInGroup:r,getGroupOrLocalRef:function(o,r,l){if(null==t?void 0:t.value){const r=e.unref(t.value)[o];return e.computed({get:()=>null==r?void 0:r.value,set(e){r.value=e}})}const a=e.toRef(r,o);return e.computed({get:()=>a.value,set(e){l&&l(`update:${o}`,e)}})}}}l.before,r.bottom,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,a.button,n.button;const s={...i,name:String,title:String,content:String,modelValue:{type:Boolean,default:void 0},disabled:Boolean,not:Boolean};function c(o,t,r){return e.computed((()=>{const l={[o]:!0},a="string"==typeof(null==t?void 0:t.value)?t.value.split(" "):null==t?void 0:t.value;return a&&Array.isArray(a)&&a.forEach((e=>{e&&(l[`${o}--${e}`]=!0)})),r&&Object.keys(r.value).forEach((t=>{l[`${o}--${t}`]=e.unref(r.value[t])})),l}))}const v=["id","open"],p=["aria-controls","aria-expanded"],m=["aria-hidden"],f=e.defineComponent({name:"VvAccordion",props:s,emits:["update:modelValue"],setup(r,{emit:l}){const a=r,n=e.useAttrs(),i=l,s=e.computed((()=>a.name||(null==n?void 0:n.id)||o.uid())),{modifiers:f,title:y,content:g,disabled:b,collapse:A,modelValue:B,isInGroup:V,not:h}=function(o,t){const{group:r,isInGroup:l,getGroupOrLocalRef:a}=d(u),{title:n,content:i}=e.toRefs(o),s=a("modelValue",o,t),c=a("not",o),v=a("collapse",o),p=e.computed((()=>{var e;return Boolean(o.disabled||(null==(e=null==r?void 0:r.value)?void 0:e.disabled.value))})),m=e.computed((()=>{let e=o.modifiers,t=null==r?void 0:r.value.modifiers.value;const l=new Set;return e&&(Array.isArray(e)||(e=e.split(" ")),e.forEach((e=>l.add(e)))),t&&(Array.isArray(t)||(t=t.split(" ")),t.forEach((e=>l.add(e)))),Array.from(l)}));return{modelValue:s,not:c,isInGroup:l,group:r,collapse:v,modifiers:m,disabled:p,title:n,content:i}}(a,i),k=e.ref(!1),S=e.computed({get:()=>{let e=B.value;return V.value?e=A.value&&Array.isArray(B.value)?B.value.includes(s.value):B.value===s.value:void 0===B.value&&(e=k.value),h.value?!e:e},set:e=>{if(h.value&&(e=!e),V.value)return A.value&&Array.isArray(B.value)?e?void B.value.push(s.value):void(B.value=B.value.filter((e=>e!==s.value))):void(B.value=e?s.value:null);void 0!==B.value||"boolean"!=typeof e?B.value=e:k.value=e}}),$=c("vv-accordion",f,e.computed((()=>({disabled:b.value})))),E=t.useToggle(S);return(o,t)=>(e.openBlock(),e.createElementBlock("details",{id:e.unref(s),class:e.normalizeClass(e.unref($)),open:e.unref(S)},[e.createElementVNode("summary",{"aria-controls":e.unref(s),"aria-expanded":e.unref(S),class:"vv-accordion__summary",onClick:t[0]||(t[0]=e.withModifiers((o=>e.unref(E)()),["prevent"]))},[e.renderSlot(o.$slots,"summary",e.normalizeProps(e.guardReactiveProps({open:e.unref(S)})),(()=>[e.createTextVNode(e.toDisplayString(e.unref(y)),1)]))],8,p),e.createElementVNode("div",{"aria-hidden":!e.unref(S),class:"vv-accordion__content"},[e.renderSlot(o.$slots,"default",e.normalizeProps(e.guardReactiveProps({open:e.unref(S)})),(()=>[e.createTextVNode(e.toDisplayString(e.unref(g)),1)]))],8,m)],10,v))}}),y={...i,modelValue:[String,Array],items:{type:Array,default:()=>[]},collapse:Boolean,itemModifiers:{type:[String,Array],default:""},disabled:Boolean,not:Boolean,storeKey:String};return e.defineComponent({name:"VvAccordionGroup",props:y,emits:["update:modelValue"],setup(o,{emit:r}){const l=o,a=r,{disabled:n,collapse:i,modifiers:d,itemModifiers:s,items:v,not:p}=e.toRefs(l);e.watchEffect((()=>{"string"==typeof l.modelValue&&i.value&&console.warn("[VvAccordionGroup]: modelValue is a string but collapse is true.")}));let m=e.ref([]);e.watch((()=>l.storeKey),(o=>{m=o?t.useStorage(o,m.value):e.ref([])}),{immediate:!0});const y=e.computed({get:()=>{var e;return void 0!==l.modelValue?i.value?l.modelValue:Array.isArray(l.modelValue)?l.modelValue[0]:l.modelValue:i.value?m.value:null==(e=m.value)?void 0:e[0]},set:e=>{if(void 0!==l.modelValue)return!Array.isArray(l.modelValue)&&!i.value||Array.isArray(e)||(e=[e]),a("update:modelValue",e);m.value=Array.isArray(e)?e:[e]}});!function(o){if(Object.keys(o).some((t=>"key"!==t&&!e.isRef(o[t]))))throw Error("One or more groupState props aren't ref.");e.provide(o.key,e.computed((()=>o)))}({key:u,modelValue:y,disabled:n,collapse:i,modifiers:s,not:p});const g=c("vv-accordion-group",d,e.computed((()=>({disabled:n.value}))));return(o,t)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(e.unref(g))},[e.renderSlot(o.$slots,"default",{},(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(v),(t=>(e.openBlock(),e.createBlock(f,e.mergeProps({key:t.title},{name:t.name,title:t.title,content:t.content}),{header:e.withCtx((r=>[e.renderSlot(o.$slots,`header::${t.name}`,e.normalizeProps(e.guardReactiveProps(r)))])),details:e.withCtx((r=>[e.renderSlot(o.$slots,`details::${t.name}`,e.normalizeProps(e.guardReactiveProps(r)))])),_:2},1040)))),128))]))],2))}})}));
1
+ !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o(require("vue"),require("mitt"),require("uid"),require("@vueuse/core")):"function"==typeof define&&define.amd?define(["vue","mitt","uid","@vueuse/core"],o):(e="undefined"!=typeof globalThis?globalThis:e||self).VvAccordionGroup=o(e.vue,e.mitt,e.uid,e.core)}(this,(function(e,o,t,a){"use strict";var n=(e=>(e.left="left",e.right="right",e.top="top",e.bottom="bottom",e))(n||{}),r=(e=>(e.before="before",e.after="after",e))(r||{}),l=(e=>(e.button="button",e.submit="submit",e.reset="reset",e))(l||{}),i=(e=>(e.nuxtLink="nuxt-link",e.routerLink="router-link",e.a="a",e.button="button",e))(i||{});const u=Symbol.for("accordionGroup"),s=(Boolean,Boolean,Boolean,Boolean,{modifiers:{type:[String,Array],default:void 0}});r.before,n.bottom,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,l.button,i.button;const d={...s,name:String,title:String,content:String,modelValue:{type:Boolean,default:void 0},disabled:Boolean,not:Boolean};function c(o){const{group:t,isInGroup:a}=function(o){const t=e.inject(o,void 0),a=e.computed((()=>void 0!==t));return{group:t,isInGroup:a,getGroupOrLocalRef:function(o,a,n){const r=null==t?void 0:t[o];if(r)return e.computed({get:()=>r.value,set(e){r.value=e}});const l=e.toRef(a,o);return e.computed({get:()=>l.value,set(e){n&&n(`update:${o}`,e)}})}}}(u),n=e.computed((()=>Boolean(o.disabled||(null==t?void 0:t.disabled.value)))),r=e.computed((()=>{let e=o.modifiers,a=null==t?void 0:t.modifiers.value;const n=new Set;return e&&(Array.isArray(e)||(e=e.split(" ")),e.forEach((e=>n.add(e)))),a&&(Array.isArray(a)||(a=a.split(" ")),a.forEach((e=>n.add(e)))),Array.from(n)}));return{isInGroup:a,group:t,modifiers:r,disabled:n,bus:null==t?void 0:t.bus}}function m(o,t,a){return e.computed((()=>{const n={[o]:!0},r="string"==typeof(null==t?void 0:t.value)?t.value.split(" "):null==t?void 0:t.value;return r&&Array.isArray(r)&&r.forEach((e=>{e&&(n[`${o}--${e}`]=!0)})),a&&Object.keys(a.value).forEach((t=>{n[`${o}--${t}`]=e.unref(a.value[t])})),n}))}const p=["id","open"],f=["aria-controls","aria-expanded"],v=["aria-hidden"],g=e.defineComponent({name:"VvAccordion",props:d,emits:["update:modelValue"],setup(o,{expose:n,emit:r}){const l=o,i=e.useAttrs(),u=r,s=a.useVModel(l,"modelValue",u),d=e.computed((()=>l.name||(null==i?void 0:i.id)||t.uid())),{title:g,content:y,not:b}=e.toRefs(l),{isInGroup:B,modifiers:S,disabled:x,bus:A}=c(l),h=e.ref(!1);e.watch(s,(e=>{"boolean"==typeof e&&(h.value=b.value?!e:e)}),{immediate:!0}),e.watch(h,(e=>{s.value=b.value?!e:e})),null==A||A.on("toggle",(({name:e,value:o})=>{e===d.value&&(h.value=o)}));const V=()=>{x.value||(B.value?null==A||A.emit("toggle",{name:d.value,value:!h.value}):h.value=!h.value)};e.watch(d,((e,o)=>{A&&(o&&o!==e&&A.emit("unregister",{name:o}),A.emit("register",{name:e}))}),{immediate:!0}),e.onBeforeUnmount((()=>{A&&A.emit("unregister",{name:d.value})}));const w=()=>{h.value||V()},E=()=>{h.value&&V()},k=e=>{A?A.emit("expand",{name:e}):console.warn(`[VvAccordion]: You are trying to expand accordion group of "${d.value}" but it is not in a group`)},$=e=>{A?null==A||A.emit("collapse",{name:e}):console.warn(`[VvAccordion]: You are trying to collapse accordion group of "${d.value}" but it is not in a group`)};n({isExpanded:h,expand:w,collapse:E,groupExpand:k,groupCollapse:$});const P=m("vv-accordion",S,e.computed((()=>({disabled:x.value}))));return(o,t)=>(e.openBlock(),e.createElementBlock("details",{id:e.unref(d),class:e.normalizeClass(e.unref(P)),open:e.unref(h)},[e.createElementVNode("summary",{"aria-controls":e.unref(d),"aria-expanded":e.unref(h),class:"vv-accordion__summary",onClick:t[0]||(t[0]=e.withModifiers((e=>V()),["prevent"]))},[e.renderSlot(o.$slots,"summary",e.normalizeProps(e.guardReactiveProps({isExpanded:e.unref(h),expand:w,collapse:E,groupExpand:k,groupCollapse:$})),(()=>[e.createTextVNode(e.toDisplayString(e.unref(g)),1)]))],8,f),e.createElementVNode("div",{"aria-hidden":!e.unref(h),class:"vv-accordion__content"},[e.renderSlot(o.$slots,"default",e.normalizeProps(e.guardReactiveProps({isExpanded:e.unref(h),expand:w,collapse:E,groupExpand:k,groupCollapse:$})),(()=>[e.createTextVNode(e.toDisplayString(e.unref(y)),1)]))],8,v)],10,p))}}),y={...s,modelValue:{type:[String,Array]},items:{type:Array,default:()=>[]},collapse:Boolean,itemModifiers:{type:[String,Array],default:""},disabled:Boolean,not:Boolean,storeKey:String};return e.defineComponent({name:"VvAccordionGroup",props:y,emits:["update:modelValue"],setup(t,{expose:n,emit:r}){const l=t,i=r,{disabled:s,modifiers:d,itemModifiers:c,items:p}=e.toRefs(l);e.watchEffect((()=>{"string"==typeof l.modelValue&&l.collapse&&console.warn("[VvAccordionGroup]: modelValue is a string but collapse is true.")}));const f=e.reactive(new Set);let v=e.ref(new Set);e.watch((()=>l.storeKey),((o,t)=>{t&&t!==o&&localStorage.removeItem(t),v=o?a.useLocalStorage(o,v.value):e.ref(new Set(v.value))}),{immediate:!0}),e.watch([v,f,()=>l.not,()=>l.collapse],(()=>{l.not?i("update:modelValue",[...f].filter((e=>!v.value.has(e)))):l.collapse?i("update:modelValue",[...v.value]):i("update:modelValue",v.value.values().next().value)}),{deep:!0,immediate:!0}),e.watch((()=>l.modelValue),((e,o)=>{if(null==e||JSON.stringify(e)===JSON.stringify(o))return;let t=new Set;l.not?"string"==typeof e?t=new Set([...f].filter((o=>o!==e))):Array.isArray(e)&&(t=new Set([...f].filter((o=>!e.includes(o))))):"string"==typeof e?t=new Set([e]):Array.isArray(e)&&(t=new Set(e));for(const a of f)y.emit("toggle",{name:a,value:t.has(a)});v.value=t}),{immediate:!0});const y=o();var b,B;b=u,B={disabled:s,modifiers:c,bus:y},e.provide(b,B),y.on("register",(({name:e})=>{f.add(e)})),y.on("unregister",(({name:e})=>{f.delete(e)})),y.on("toggle",(({name:e,value:o})=>{if(o){if(!l.collapse){for(const o of v.value)o!==e&&y.emit("toggle",{name:o,value:!1});v.value.clear()}v.value.add(e)}else v.value.delete(e)}));const S=e=>{if("string"!=typeof e)if(Array.isArray(e))for(const o of e)y.emit("toggle",{name:o,value:!0});else for(const o of f)y.emit("toggle",{name:o,value:!0});else y.emit("toggle",{name:e,value:!0})};y.on("expand",(({name:e})=>S(e)));const x=e=>{if("string"!=typeof e)if(Array.isArray(e))for(const o of e)y.emit("toggle",{name:o,value:!1});else for(const o of f)y.emit("toggle",{name:o,value:!1});else y.emit("toggle",{name:e,value:!1})};y.on("collapse",(({name:e})=>x(e))),n({modelValue:v,expand:S,collapse:x});const A=m("vv-accordion-group",d,e.computed((()=>({disabled:s.value}))));return(o,t)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(e.unref(A))},[e.renderSlot(o.$slots,"default",e.normalizeProps(e.guardReactiveProps({modelValue:e.unref(v),expand:S,collapse:x})),(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(p),(t=>(e.openBlock(),e.createBlock(g,e.mergeProps({key:t.title},{name:t.name,title:t.title,content:t.content}),{header:e.withCtx((a=>[e.renderSlot(o.$slots,`header::${t.name}`,e.normalizeProps(e.guardReactiveProps(a)))])),details:e.withCtx((a=>[e.renderSlot(o.$slots,`details::${t.name}`,e.normalizeProps(e.guardReactiveProps(a)))])),_:2},1040)))),128))]))],2))}})}));
@@ -1,5 +1,7 @@
1
1
  declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
2
- modelValue: (ArrayConstructor | StringConstructor)[];
2
+ modelValue: {
3
+ type: globalThis.PropType<string | string[] | undefined>;
4
+ };
3
5
  items: {
4
6
  type: globalThis.PropType<import(".").VvAccordionGroupItem[]>;
5
7
  default: () => never[];
@@ -16,10 +18,16 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
16
18
  type: globalThis.PropType<string | string[]>;
17
19
  default: undefined;
18
20
  };
19
- }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
21
+ }, {
22
+ modelValue: globalThis.Ref<Set<string> & Omit<Set<string>, keyof Set<any>>>;
23
+ expand: (name?: string | string[]) => void;
24
+ collapse: (name?: string | string[]) => void;
25
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
20
26
  [x: string]: (...args: any[]) => void;
21
27
  }, string, import("vue").PublicProps, Readonly<globalThis.ExtractPropTypes<{
22
- modelValue: (ArrayConstructor | StringConstructor)[];
28
+ modelValue: {
29
+ type: globalThis.PropType<string | string[] | undefined>;
30
+ };
23
31
  items: {
24
32
  type: globalThis.PropType<import(".").VvAccordionGroupItem[]>;
25
33
  default: () => never[];
@@ -37,14 +45,18 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
37
45
  default: undefined;
38
46
  };
39
47
  }>>, {
40
- disabled: boolean;
41
- modifiers: string | string[];
42
48
  collapse: boolean;
49
+ disabled: boolean;
43
50
  not: boolean;
51
+ modifiers: string | string[];
44
52
  items: import(".").VvAccordionGroupItem[];
45
53
  itemModifiers: string | string[];
46
54
  }, {}>, Partial<Record<`header::${string}`, (_: any) => any>> & Partial<Record<`details::${string}`, (_: any) => any>> & {
47
- default?(_: {}): any;
55
+ default?(_: {
56
+ modelValue: Set<string> & Omit<Set<string>, keyof Set<any>>;
57
+ expand: (name?: string | string[]) => void;
58
+ collapse: (name?: string | string[]) => void;
59
+ }): any;
48
60
  }>;
49
61
  export default _default;
50
62
  type __VLS_WithTemplateSlots<T, S> = T & {
@@ -9,7 +9,9 @@ export declare const VvAccordionGroupProps: {
9
9
  /**
10
10
  * VModel
11
11
  */
12
- modelValue: (ArrayConstructor | StringConstructor)[];
12
+ modelValue: {
13
+ type: globalThis.PropType<string | string[] | undefined>;
14
+ };
13
15
  /**
14
16
  * Accordion items
15
17
  * @type VvAccordionGroupItem
@@ -98,8 +98,8 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
98
98
  default: boolean;
99
99
  };
100
100
  }>>, {
101
- disabled: boolean;
102
101
  label: string | number;
102
+ disabled: boolean;
103
103
  type: "button" | "submit" | "reset";
104
104
  target: "_blank" | "_self" | "_parent" | "_top";
105
105
  ariaLabel: string;
@@ -89,9 +89,9 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
89
89
  };
90
90
  id: (StringConstructor | NumberConstructor)[];
91
91
  }>>, {
92
- modifiers: string | string[];
93
92
  title: string;
94
93
  content: string;
94
+ modifiers: string | string[];
95
95
  footer: string;
96
96
  role: "alert" | "alertdialog";
97
97
  icon: string | import("../VvIcon").VvIconProps;