@bagelink/vue 0.0.819 → 0.0.821
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/dist/components/Carousel.vue.d.ts.map +1 -1
- package/dist/components/Pill.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/FileUpload.vue.d.ts.map +1 -1
- package/dist/index.cjs +98 -48
- package/dist/index.mjs +98 -48
- package/dist/style.css +77 -87
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Carousel.vue +41 -48
- package/src/components/Pill.vue +1 -1
- package/src/components/form/inputs/FileUpload.vue +24 -2
- package/src/utils/index.ts +55 -31
package/src/utils/index.ts
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
import type { Attributes, BglFormSchemaT } from '@bagelink/vue'
|
|
2
2
|
|
|
3
|
-
export function debounce<T extends (...args:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export function debounce<T extends (...args: Parameters<T>) => ReturnType<T>>(
|
|
4
|
+
callback: T,
|
|
5
|
+
wait: number,
|
|
6
|
+
immediate?: boolean
|
|
7
|
+
): (...args: Parameters<T>) => void {
|
|
8
|
+
let timeout: NodeJS.Timeout | undefined
|
|
9
|
+
|
|
10
|
+
return function (this: ThisParameterType<T>, ...args: Parameters<T>): void {
|
|
11
|
+
const later = () => {
|
|
12
|
+
timeout = undefined
|
|
13
|
+
if (!immediate) callback.apply(this, args)
|
|
9
14
|
}
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
const callNow = immediate && timeout === undefined
|
|
17
|
+
clearTimeout(timeout)
|
|
18
|
+
timeout = setTimeout(later, wait)
|
|
19
|
+
|
|
20
|
+
if (callNow) callback.apply(this, args)
|
|
14
21
|
}
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
export function keyToLabel(key?: string): string | undefined {
|
|
18
25
|
if (key === undefined) return key
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
return (
|
|
27
|
+
key
|
|
28
|
+
.split('_')
|
|
29
|
+
.map(k => k.charAt(0).toUpperCase() + k.slice(1))
|
|
30
|
+
.join(' ') || key
|
|
31
|
+
)
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
export async function copyText(text: string, cb?: (msg: string) => void) {
|
|
@@ -38,19 +48,27 @@ export function useEscape(event: KeyboardEvent, closeModel: () => void) {
|
|
|
38
48
|
}
|
|
39
49
|
|
|
40
50
|
export function classify(fieldVal?: any, row?: any, ...classes: any[]) {
|
|
41
|
-
return classes
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
return classes
|
|
52
|
+
.map((cls) => {
|
|
53
|
+
if (typeof cls === 'function') return cls(fieldVal, row)
|
|
54
|
+
return cls
|
|
55
|
+
})
|
|
56
|
+
.join(' ')
|
|
45
57
|
}
|
|
46
58
|
|
|
47
|
-
export function bindAttrs<T = { [key: string]: any }>(
|
|
59
|
+
export function bindAttrs<T = { [key: string]: any }>(
|
|
60
|
+
attrs?: Attributes,
|
|
61
|
+
fieldVal?: any,
|
|
62
|
+
row?: T
|
|
63
|
+
) {
|
|
48
64
|
if (!attrs) return {}
|
|
49
65
|
const exclude = ['class']
|
|
50
|
-
const arr = Object.entries(attrs)
|
|
51
|
-
key
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
const arr = Object.entries(attrs)
|
|
67
|
+
.filter(([key]) => !exclude.includes(key))
|
|
68
|
+
.map(([key, value]) => [
|
|
69
|
+
key,
|
|
70
|
+
typeof value === 'function' ? value(fieldVal, row) : value,
|
|
71
|
+
])
|
|
54
72
|
|
|
55
73
|
const resolvedAttrs = Object.fromEntries(arr)
|
|
56
74
|
return resolvedAttrs
|
|
@@ -60,7 +78,8 @@ export function iffer(field: any, itemData: any) {
|
|
|
60
78
|
if (field['v-if'] === undefined) return true
|
|
61
79
|
if (typeof field['v-if'] === 'boolean') return field['v-if']
|
|
62
80
|
if (typeof field['v-if'] === 'string') return true
|
|
63
|
-
if (typeof field['v-if'] === 'function')
|
|
81
|
+
if (typeof field['v-if'] === 'function')
|
|
82
|
+
return field['v-if']?.(itemData?.[field.id], itemData)
|
|
64
83
|
return true
|
|
65
84
|
}
|
|
66
85
|
|
|
@@ -77,22 +96,25 @@ export { useLang } from './lang'
|
|
|
77
96
|
|
|
78
97
|
export { formatString } from './strings'
|
|
79
98
|
|
|
80
|
-
export function getFallbackSchema<T>(
|
|
99
|
+
export function getFallbackSchema<T>(
|
|
100
|
+
data?: any[],
|
|
101
|
+
showFields?: string[]
|
|
102
|
+
): BglFormSchemaT<T> {
|
|
81
103
|
const keys = Array.from(new Set((data ?? []).flatMap(Object.keys)))
|
|
82
104
|
|
|
83
|
-
const schema: BglFormSchemaT<T> = keys.map(
|
|
84
|
-
id
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
})
|
|
88
|
-
)
|
|
105
|
+
const schema: BglFormSchemaT<T> = keys.map(id => ({
|
|
106
|
+
id,
|
|
107
|
+
label: keyToLabel(id),
|
|
108
|
+
}))
|
|
89
109
|
|
|
90
110
|
return showFields
|
|
91
111
|
? schema.filter(f => showFields.includes(f.id as string) || !f.id)
|
|
92
112
|
: schema
|
|
93
113
|
}
|
|
94
114
|
|
|
95
|
-
export
|
|
115
|
+
export function sleep(ms: number = 100) {
|
|
116
|
+
return new Promise(resolve => setTimeout(resolve, ms))
|
|
117
|
+
}
|
|
96
118
|
|
|
97
119
|
export function appendScript(src: string): Promise<void> {
|
|
98
120
|
return new Promise((resolve, reject) => {
|
|
@@ -102,7 +124,9 @@ export function appendScript(src: string): Promise<void> {
|
|
|
102
124
|
}
|
|
103
125
|
const script = document.createElement('script')
|
|
104
126
|
script.src = src
|
|
105
|
-
script.onload = () => {
|
|
127
|
+
script.onload = () => {
|
|
128
|
+
resolve()
|
|
129
|
+
}
|
|
106
130
|
script.onerror = reject
|
|
107
131
|
document.head.append(script)
|
|
108
132
|
})
|