@bagelink/vue 0.0.1167 → 0.0.1174

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.
@@ -1,62 +1,11 @@
1
- import type { BglFormSchemaFnT, BtnOptions, ThemeType } from '@bagelink/vue'
2
1
  import type { InjectionKey, Plugin } from 'vue'
2
+ import type { ConfirmModalUserOptions, ModalComponentProps, ModalConfirmOptions, ModalFormComponentProps, ModalFormOptions, ModalOptions, ModalType } from './modalTypes'
3
3
  import { Modal, ModalConfirm, ModalForm } from '@bagelink/vue'
4
4
  import { defineComponent, h, inject } from 'vue'
5
5
 
6
- // Interface Definitions
7
- export interface ModalOptions {
8
- title?: string
9
- dismissable?: boolean
10
- side?: boolean
11
- width?: string
12
- actions?: BtnOptions[]
13
- class?: string
14
- visible?: boolean
15
- }
16
-
17
- export interface ModalFormOptions extends ModalOptions {
18
- 'schema': BglFormSchemaFnT<any>
19
- 'onSubmit'?: (formData: any) => any
20
- 'submitText'?: string
21
- 'cancelText'?: string
22
- 'deleteText'?: string
23
- 'duplicateText'?: string
24
- 'onDelete'?: (id: string) => Promise<void>
25
- 'onDuplicate'?: (formData: any) => Promise<void>
26
- 'onError'?: (err: any) => void
27
- 'modelValue'?: { [key: string]: any }
28
- 'onUpdate:modelValue'?: (val: any) => void
29
- }
30
-
31
- export interface ModalConfirmOptions {
32
- 'title': string
33
- 'message': string
34
- 'confirmText'?: string
35
- 'confirmBtnColor'?: ThemeType
36
- 'cancelText'?: string
37
- 'cancelBtnColor'?: ThemeType
38
- 'resolve': (val: boolean) => void
39
- 'onUpdate:visible': () => void
40
- 'visible': boolean
41
- }
42
-
43
- type ModalType = 'modal' | 'modalForm' | 'confirmModal'
44
- type ConfirmModalUserOptions = string | { title: string, message: string, confirmText?: string, cancelText?: string, confirmBtnColor?: string, cancelBtnColor?: string }
45
-
46
- export interface ModalComponentProps {
47
- componentSlots: { [key: string]: any }
48
- modalType: ModalType
49
- modalOptions: ModalOptions | ModalFormOptions | ModalConfirmOptions
50
- }
51
-
52
- export interface ModalFormComponentProps extends ModalComponentProps {
53
- modalType: 'modalForm'
54
- modalOptions: ModalFormOptions
55
- }
56
-
57
6
  export interface ModalApi {
58
7
  showModal: (options: ModalOptions, slots?: { [key: string]: any }) => ModalComponentProps | undefined
59
- showModalForm: (options: ModalFormOptions, slots?: { [key: string]: any }) => ModalFormComponentProps | undefined
8
+ showModalForm: <T extends { [key: string]: any }>(options: ModalFormOptions<T>, slots?: { [key: string]: any }) => ModalFormComponentProps<T> | undefined
60
9
  hideModal: (index?: number) => void
61
10
  confirmModal: (options: ConfirmModalUserOptions) => Promise<boolean>
62
11
  }
@@ -88,11 +37,11 @@ export const ModalPlugin: Plugin = {
88
37
  })
89
38
  }
90
39
 
91
- const showModal = (
40
+ const showModal = <T extends { [key: string]: any } = any>(
92
41
  modalType: ModalType,
93
- options: ModalOptions | ModalFormOptions,
42
+ options: ModalOptions | ModalFormOptions<T>,
94
43
  slots: { [key: string]: any } = {}
95
- ): ModalComponentProps | ModalFormComponentProps | undefined => {
44
+ ): ModalComponentProps | ModalFormComponentProps<T> | undefined => {
96
45
  const modalComponent = {
97
46
  modalOptions: options,
98
47
  modalType,
@@ -101,7 +50,7 @@ export const ModalPlugin: Plugin = {
101
50
  modalStack.push(modalComponent)
102
51
 
103
52
  if (modalType === 'modalForm') {
104
- return modalComponent as ModalFormComponentProps
53
+ return modalComponent as ModalFormComponentProps<T>
105
54
  }
106
55
  return modalComponent
107
56
  }
@@ -109,7 +58,7 @@ export const ModalPlugin: Plugin = {
109
58
  app.provide(ModalSymbol, {
110
59
  showModal: (options: ModalOptions, slots?: { [key: string]: any }) => showModal('modal', options, slots),
111
60
 
112
- showModalForm: (options: ModalFormOptions, slots?: { [key: string]: any }) => showModal('modalForm', options, slots) as ModalFormComponentProps,
61
+ showModalForm: <T extends { [key: string]: any }>(options: ModalFormOptions<T>, slots?: { [key: string]: any }) => showModal<T>('modalForm', options, slots) as ModalFormComponentProps<T>,
113
62
 
114
63
  confirmModal: (options: ConfirmModalUserOptions) => confirmModal(options),
115
64
 
@@ -137,7 +86,6 @@ export const ModalPlugin: Plugin = {
137
86
  })
138
87
  },
139
88
  })
140
-
141
89
  app.component('ModalContainer', ModalComponent)
142
90
  },
143
91
  }
@@ -0,0 +1,58 @@
1
+ import type { BglFormSchemaFnT, BtnOptions, ThemeType } from '@bagelink/vue'
2
+
3
+ export interface ModalOptions {
4
+ title?: string
5
+ dismissable?: boolean
6
+ side?: boolean
7
+ width?: string
8
+ actions?: BtnOptions[]
9
+ class?: string
10
+ visible?: boolean
11
+ }
12
+
13
+ export interface ModalConfirmOptions {
14
+ 'title': string
15
+ 'message': string
16
+ 'confirmText'?: string
17
+ 'confirmBtnColor'?: ThemeType
18
+ 'cancelText'?: string
19
+ 'cancelBtnColor'?: ThemeType
20
+ 'resolve': (val: boolean) => void
21
+ 'onUpdate:visible': () => void
22
+ 'visible': boolean
23
+ }
24
+
25
+ export type ModalType = 'modal' | 'modalForm' | 'confirmModal'
26
+ export type ConfirmModalUserOptions = string | { title: string, message: string, confirmText?: string, cancelText?: string, confirmBtnColor?: string, cancelBtnColor?: string }
27
+
28
+ export interface ModalComponentProps {
29
+ componentSlots: { [key: string]: any }
30
+ modalType: ModalType
31
+ modalOptions: ModalOptions | ModalFormOptions | ModalConfirmOptions
32
+ }
33
+
34
+ export interface ModalFormComponentProps<T extends { [key: string]: any } = any> extends ModalComponentProps {
35
+ modalType: 'modalForm'
36
+ modalOptions: ModalFormOptions<T>
37
+ }
38
+
39
+ export interface ModalFormOptions<T extends { [key: string]: any } = any> {
40
+ 'schema': BglFormSchemaFnT<T>
41
+ 'modelValue'?: T
42
+ 'onUpdate:modelValue'?: (val: T) => void
43
+ 'onSubmit'?: (formData: T) => any
44
+ 'onDelete'?: (formData: T) => Promise<void>
45
+ 'onDuplicate'?: (formData: T) => Promise<void>
46
+ 'submitText'?: string
47
+ 'cancelText'?: string
48
+ 'deleteText'?: string
49
+ 'duplicateText'?: string
50
+ 'onError'?: (err: any) => void
51
+ 'side'?: boolean
52
+ 'title'?: string
53
+ 'width'?: string
54
+ 'dismissable'?: boolean
55
+ 'visible'?: boolean
56
+ 'actions'?: BtnOptions[]
57
+ 'class'?: string
58
+ }
@@ -1,10 +1,8 @@
1
1
  export type {
2
- ModalApi,
3
2
  ModalComponentProps,
4
3
  ModalComponentProps as ModalFormComponentProps,
5
- ModalFormOptions,
6
4
  ModalOptions,
7
- } from '../plugins/modal'
5
+ } from '../plugins/modalTypes'
8
6
 
9
7
  import type { IconType, MaterialIcons } from '../components/Icon/types'
10
8
 
@@ -38,9 +38,12 @@ interface NumFieldOptions extends InputOptions {
38
38
 
39
39
  type RichTextOptions = InputOptions
40
40
 
41
- export function getBaseField<T>(id?: string, labelOrRest: string | Partial<Field<T>> = {}, rest: Partial<Field<T>> = {}): Field<T> {
41
+ export function getBaseField<T extends { [key: string]: any }>(
42
+ id?: keyof T extends string ? keyof T : string,
43
+ labelOrRest: string | Partial<Field<T>> = {},
44
+ rest: Partial<Field<T>> = {}
45
+ ): Field<T> {
42
46
  if (typeof labelOrRest === 'object') return { id, ...labelOrRest }
43
-
44
47
  return { id, label: labelOrRest, ...rest }
45
48
  }
46
49