@bagelink/vue 1.6.9 → 1.6.21
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/Swiper.vue.d.ts +1 -1
- package/dist/components/Swiper.vue.d.ts.map +1 -1
- package/dist/components/form/FieldArray.vue.d.ts.map +1 -1
- package/dist/index.cjs +25 -21
- package/dist/index.mjs +4225 -4146
- package/dist/style.css +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/ListItem.vue +2 -2
- package/src/components/Swiper.vue +10 -8
- package/src/components/form/FieldArray.vue +56 -50
- package/src/components/form/inputs/CodeEditor/Index.vue +1 -1
- package/src/composables/useExcel.ts +6 -6
- package/src/styles/colors.css +176 -0
- package/src/styles/layout.css +231 -0
- package/src/styles/mobilLayout.css +232 -0
- package/src/styles/mobileColors.css +176 -0
- package/src/utils/index.ts +46 -25
package/src/utils/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ export function slugify(str: string) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function keyToLabel(key?: string): string | undefined {
|
|
23
|
-
if (key === undefined) {return key}
|
|
23
|
+
if (key === undefined) { return key }
|
|
24
24
|
return (
|
|
25
25
|
key
|
|
26
26
|
.split('_')
|
|
@@ -31,7 +31,7 @@ export function keyToLabel(key?: string): string | undefined {
|
|
|
31
31
|
|
|
32
32
|
export async function copyText(text: string, cb?: (msg: string) => void) {
|
|
33
33
|
await navigator.clipboard.writeText(text)
|
|
34
|
-
if (cb) {cb('Copied to clipboard')}
|
|
34
|
+
if (cb) { cb('Copied to clipboard') }
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export function initials(...strArr: string[]) {
|
|
@@ -40,7 +40,7 @@ export function initials(...strArr: string[]) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export function useEscape(event: KeyboardEvent, closeModel: () => void) {
|
|
43
|
-
if ('Escape'
|
|
43
|
+
if (event.key === 'Escape') {
|
|
44
44
|
closeModel()
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -48,7 +48,7 @@ export function useEscape(event: KeyboardEvent, closeModel: () => void) {
|
|
|
48
48
|
export function classify(fieldVal?: any, row?: any, ...classes: any[]) {
|
|
49
49
|
return classes
|
|
50
50
|
.map((cls) => {
|
|
51
|
-
if ('function'
|
|
51
|
+
if (typeof cls === 'function') { return cls(fieldVal, row) }
|
|
52
52
|
return cls
|
|
53
53
|
})
|
|
54
54
|
.join(' ')
|
|
@@ -60,14 +60,14 @@ export function bindAttrs<T, P extends Path<T>>(
|
|
|
60
60
|
row?: T
|
|
61
61
|
) {
|
|
62
62
|
// TODO: Fix this so that you don't have to return a fn for other on* event handlers
|
|
63
|
-
if (!attrs) {return {}}
|
|
63
|
+
if (!attrs) { return {} }
|
|
64
64
|
|
|
65
65
|
const exclude = ['class', 'onClick', '$el'] as const
|
|
66
66
|
const arr = Object.entries(attrs)
|
|
67
67
|
.filter(([key]) => !exclude.includes(key as typeof exclude[number]))
|
|
68
68
|
.map(([key, value]) => [
|
|
69
69
|
key,
|
|
70
|
-
|
|
70
|
+
typeof value === 'function' ? value(fieldVal, row) : value,
|
|
71
71
|
])
|
|
72
72
|
|
|
73
73
|
const resolvedAttrs: { [key: string]: any } = Object.fromEntries(arr)
|
|
@@ -84,16 +84,16 @@ export function bindAttrs<T, P extends Path<T>>(
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
export function iffer(field: any, itemData: any) {
|
|
87
|
-
if (field['v-if'] === undefined) {return true}
|
|
88
|
-
if (
|
|
89
|
-
if (
|
|
90
|
-
if (
|
|
91
|
-
|
|
87
|
+
if (field['v-if'] === undefined) { return true }
|
|
88
|
+
if (typeof field['v-if'] === 'boolean') { return field['v-if'] }
|
|
89
|
+
if (typeof field['v-if'] === 'string') { return true }
|
|
90
|
+
if (typeof field['v-if'] === 'function')
|
|
91
|
+
{ return field['v-if']?.(itemData?.[field.id], itemData) }
|
|
92
92
|
return true
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
export function denullify(itemData?: { [key: string]: any }, fieldID?: string) {
|
|
96
|
-
if (!fieldID) {return undefined}
|
|
96
|
+
if (!fieldID) { return undefined }
|
|
97
97
|
return itemData ? itemData[fieldID] : undefined
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -110,7 +110,7 @@ export function getFallbackSchema<T>(
|
|
|
110
110
|
label: keyToLabel(id),
|
|
111
111
|
transform: (val: any) => {
|
|
112
112
|
const dateFields = ['created_at', 'updated_at']
|
|
113
|
-
if (dateFields.includes(id)) {return val ? new Date(val).toLocaleString() : val}
|
|
113
|
+
if (dateFields.includes(id)) { return val ? new Date(val).toLocaleString() : val }
|
|
114
114
|
return val
|
|
115
115
|
},
|
|
116
116
|
})) as BglFormSchemaT<T>
|
|
@@ -133,13 +133,13 @@ export async function appendScript(src: string, options?: { id?: string }): Prom
|
|
|
133
133
|
// If this script is already loading, return the existing promise
|
|
134
134
|
if (scriptsLoading.has(scriptId)) {
|
|
135
135
|
const existingPromise = scriptsLoading.get(scriptId)
|
|
136
|
-
if (existingPromise) {return existingPromise}
|
|
136
|
+
if (existingPromise) { return existingPromise }
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
// Check if script is already in the document
|
|
140
140
|
if (options?.id && document.getElementById(options.id)) {
|
|
141
141
|
return Promise.resolve()
|
|
142
|
-
}if (document.querySelector(`script[src="${src}"]`)) {
|
|
142
|
+
} if (document.querySelector(`script[src="${src}"]`)) {
|
|
143
143
|
return Promise.resolve()
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -188,13 +188,13 @@ export function appendStyle(src: string): Promise<void> {
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
export function normalizeURL(url: string) {
|
|
191
|
-
if (url.startsWith('https://')) {return url}
|
|
191
|
+
if (url.startsWith('https://')) { return url }
|
|
192
192
|
url = url.replace(/http:\/\//, '')
|
|
193
193
|
return `https://${url}`
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
export function normalizeDimension(value: string | number | undefined, defaultMetric = 'px'): string | undefined {
|
|
197
|
-
if ('number'
|
|
197
|
+
if (typeof value === 'number') { return `${value}${defaultMetric}` }
|
|
198
198
|
return value
|
|
199
199
|
}
|
|
200
200
|
|
|
@@ -211,7 +211,7 @@ import { getBagelInstance } from '../composables/useBagel'
|
|
|
211
211
|
const URL_REGEX = /^https?:\/\/|^\/\//
|
|
212
212
|
|
|
213
213
|
export function pathKeyToURL(pathKey?: string) {
|
|
214
|
-
if (pathKey === undefined ||
|
|
214
|
+
if (pathKey === undefined || pathKey === '' || URL_REGEX.test(pathKey)) { return pathKey }
|
|
215
215
|
|
|
216
216
|
const bagel = getBagelInstance()
|
|
217
217
|
if (!bagel) {
|
|
@@ -220,7 +220,7 @@ export function pathKeyToURL(pathKey?: string) {
|
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
if (pathKey.startsWith('static/')) {
|
|
223
|
-
if (bagel.host === undefined ||
|
|
223
|
+
if (bagel.host === undefined || bagel.host === '') {
|
|
224
224
|
console.warn('Bagel host is not configured. Please set it in BagelVue options.')
|
|
225
225
|
return pathKey
|
|
226
226
|
}
|
|
@@ -231,12 +231,12 @@ export function pathKeyToURL(pathKey?: string) {
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
export function getNestedValue(obj: any, path?: string, defaultValue: any = undefined): any {
|
|
234
|
-
if (!path) {return obj}
|
|
234
|
+
if (!path) { return obj }
|
|
235
235
|
const keys = path.split(/[.[]/)
|
|
236
236
|
let current = obj
|
|
237
237
|
|
|
238
238
|
for (const key of keys) {
|
|
239
|
-
if (!current || 'object'
|
|
239
|
+
if (!current || typeof current !== 'object' || !(key in current)) {
|
|
240
240
|
return defaultValue
|
|
241
241
|
}
|
|
242
242
|
current = current[key]
|
|
@@ -247,19 +247,40 @@ export function getNestedValue(obj: any, path?: string, defaultValue: any = unde
|
|
|
247
247
|
|
|
248
248
|
const upgradeHeaders = (url: string) => url.replace(/http:\/\//, '//')
|
|
249
249
|
|
|
250
|
+
export function tryRun<T>(func: () => T, callback?: (error: Error) => void): T | undefined {
|
|
251
|
+
try {
|
|
252
|
+
return func()
|
|
253
|
+
} catch (error) {
|
|
254
|
+
if (callback) {
|
|
255
|
+
callback(error as Error)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
250
260
|
export function downloadFile(source: string | Blob, fileName?: string) {
|
|
261
|
+
if (typeof document === 'undefined') { return } // SSR / non-browser guard
|
|
262
|
+
|
|
251
263
|
const link = document.createElement('a')
|
|
252
264
|
link.target = '_blank'
|
|
265
|
+
link.rel = 'noopener noreferrer'
|
|
266
|
+
|
|
267
|
+
const hasProvidedFileName
|
|
268
|
+
= fileName !== undefined
|
|
269
|
+
&& fileName !== ''
|
|
253
270
|
|
|
254
|
-
if ('string'
|
|
271
|
+
if (typeof source === 'string') {
|
|
255
272
|
link.href = upgradeHeaders(source)
|
|
256
273
|
const fileNameFromSource = source.split('/').pop()
|
|
257
|
-
|
|
274
|
+
const hasFileNameFromSource = fileNameFromSource !== undefined && fileNameFromSource !== ''
|
|
275
|
+
link.download = hasProvidedFileName
|
|
276
|
+
? fileName
|
|
277
|
+
: (hasFileNameFromSource ? fileNameFromSource : 'download')
|
|
258
278
|
} else {
|
|
259
279
|
const url = URL.createObjectURL(source)
|
|
260
280
|
link.href = url
|
|
261
|
-
link.download = fileName
|
|
262
|
-
|
|
281
|
+
link.download = hasProvidedFileName ? fileName : 'download'
|
|
282
|
+
// IMPORTANT: revoke after the browser started consuming (revoking immediately can break the download .
|
|
283
|
+
setTimeout(() => tryRun(() => { URL.revokeObjectURL(url) }), 0)
|
|
263
284
|
}
|
|
264
285
|
|
|
265
286
|
document.body.appendChild(link)
|