@bagelink/vue 0.0.398 → 0.0.402

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.
@@ -120,12 +120,14 @@ const selectedLabel = $computed(() => {
120
120
  const emit = defineEmits(['update:modelValue']);
121
121
 
122
122
  const getLabel = (option: Option) => {
123
+ if (!option) return '';
123
124
  if (typeof option === 'string') return option;
124
125
  if (typeof option === 'number') return `${option}`;
125
126
  return option.label;
126
127
  };
127
128
 
128
129
  const getValue = (option: Option) => {
130
+ if (!option) return '';
129
131
  if (typeof option === 'string') return option;
130
132
  if (typeof option === 'number') return option;
131
133
  return option.value;
@@ -182,7 +184,6 @@ function compareArrays(arr1: Option[], arr2: Option[]) {
182
184
  watch(
183
185
  () => props.modelValue,
184
186
  (newVal: Option | Option[]) => {
185
- if (!newVal) return;
186
187
  if (!props.multiselect) {
187
188
  const newOption =
188
189
  props.options.find((o) => getValue(o) === newVal) || newVal;
@@ -202,7 +203,6 @@ watch(
202
203
  watch(
203
204
  () => props.options,
204
205
  () => {
205
- const original = JSON.stringify(props.options.map(getValue));
206
206
  [...selectedItems].forEach((option, i) => {
207
207
  const exists = props.options.find(
208
208
  (o) => getValue(o) === getValue(option)
@@ -210,8 +210,9 @@ watch(
210
210
  if (!exists) selectedItems.splice(i, 1);
211
211
  else selectedItems.splice(i, 1, exists);
212
212
  });
213
- const newSelection = JSON.stringify(selectedItems.map(getValue));
214
- if (original !== newSelection) emitUpdate();
213
+ // const original = JSON.stringify(props.options.map(getValue));
214
+ // const newSelection = JSON.stringify(selectedItems.map(getValue));
215
+ // if (original !== newSelection) emitUpdate();
215
216
  },
216
217
  { deep: true }
217
218
  );
@@ -20,6 +20,7 @@ export { default as Alert } from './Alert.vue';
20
20
  export { default as Badge } from './Badge.vue';
21
21
  export { default as BglVideo } from './BglVideo.vue';
22
22
  export { default as Carousel } from './Carousel.vue';
23
+ export { default as ModalConfirm } from './ModalConfirm.vue';
23
24
 
24
25
  export * from './form';
25
26
  export * from './dashboard';
@@ -3,7 +3,7 @@ import {
3
3
  } from 'vue';
4
4
  import type { Plugin } from 'vue';
5
5
  import type { BglFormSchemaT, BtnOptions } from '@bagelink/vue';
6
- import { Modal, ModalForm } from '@bagelink/vue';
6
+ import { Modal, ModalForm, ModalConfirm } from '@bagelink/vue';
7
7
 
8
8
  export interface ModalOptions {
9
9
  title?: string;
@@ -29,10 +29,20 @@ export interface ModalFormOptions {
29
29
  'onUpdate:modelValue'?: (val: any) => void;
30
30
  }
31
31
 
32
+ export type ModalConfirmOptions = {
33
+ title?: string;
34
+ message?: string;
35
+ resolve: (val: boolean) => void;
36
+ }
37
+
38
+ type ModalType = 'modal' | 'modalForm' | 'confirm'
39
+
40
+ type ConfirmModalUserOptions = string | { title: string, message: string }
41
+
32
42
  export interface ModalComponentProps {
33
43
  componentSlots: Record<string, any>,
34
- modalType: 'modal' | 'modalForm',
35
- modalOptions: ModalOptions | ModalFormOptions
44
+ modalType: ModalType,
45
+ modalOptions: ModalOptions | ModalFormOptions | ModalConfirmOptions
36
46
  }
37
47
  export interface ModalFormComponentProps {
38
48
  componentSlots: Record<string, any>,
@@ -43,6 +53,7 @@ export interface ModalApi {
43
53
  showModal: (options: ModalOptions, slots?: Record<string, any>) => void;
44
54
  showModalForm: (options: ModalFormOptions, slots?: Record<string, any>) => ModalFormComponentProps | undefined;
45
55
  hideModal: (index?: number) => void;
56
+ confirm: (options: ConfirmModalUserOptions) => Promise<boolean>;
46
57
  }
47
58
 
48
59
  export const ModalSymbol: InjectionKey<ModalApi> = Symbol('modal');
@@ -61,8 +72,17 @@ export const ModalPlugin: Plugin = {
61
72
  modalStack.splice(index, 1);
62
73
  };
63
74
 
75
+ const modalConfirm = (options: ConfirmModalUserOptions) => new Promise<boolean>((resolve) => {
76
+ if (typeof options === 'string') options = { title: options, message: '' };
77
+ modalStack.push({
78
+ modalOptions: { ...options, resolve },
79
+ modalType: 'confirm',
80
+ componentSlots: {},
81
+ });
82
+ });
83
+
64
84
  const showModal = (
65
- modalType: 'modal' | 'modalForm',
85
+ modalType: ModalType,
66
86
  options: ModalOptions | ModalFormOptions,
67
87
  slots: Record<string, any> = {},
68
88
  ) => {
@@ -78,6 +98,7 @@ export const ModalPlugin: Plugin = {
78
98
  app.provide(ModalSymbol, {
79
99
  showModal: (options: ModalOptions, slots?: Record<string, any>) => showModal('modal', options, slots),
80
100
  showModalForm: (options: ModalFormOptions, slots?: Record<string, any>) => showModal('modalForm', options, slots) as ModalFormComponentProps,
101
+ confirm: (userOptions: ConfirmModalUserOptions) => modalConfirm(userOptions),
81
102
  hideModal: (index = modalStack.length - 1) => hideModal(index),
82
103
  // modalOptions,
83
104
  });
@@ -88,6 +109,7 @@ export const ModalPlugin: Plugin = {
88
109
  return modalStack.map((modal, index) => {
89
110
  const props = { ...modal.modalOptions, visible: true, 'onUpdate:visible': () => hideModal(index) };
90
111
  if (modal.modalType === 'modalForm') return h(ModalForm, props as ModalFormOptions, modal.componentSlots);
112
+ if (modal.modalType === 'confirm') return h(ModalConfirm, props as any, {});
91
113
  return h(Modal, props, modal.componentSlots);
92
114
  });
93
115
  },
@@ -1620,6 +1620,15 @@
1620
1620
  width: 100%;
1621
1621
  }
1622
1622
 
1623
+ .ltr,
1624
+ .direction-ltr {
1625
+ direction: ltr;
1626
+ }
1627
+
1628
+ .rtl,
1629
+ .direction-rtl {
1630
+ direction: rtl;
1631
+ }
1623
1632
 
1624
1633
  @media screen and (max-width: 910px) {
1625
1634
  .grid-wrap-2 {
@@ -1520,4 +1520,15 @@
1520
1520
  .m_overflow-y-hidden {
1521
1521
  overflow-y: hidden;
1522
1522
  }
1523
+
1524
+ .m_ltr,
1525
+ .m_direction-ltr {
1526
+ direction: ltr;
1527
+ }
1528
+
1529
+ .m_rtl,
1530
+ .m_direction-rtl {
1531
+ direction: rtl;
1532
+ }
1533
+
1523
1534
  }