@bagelink/vue 1.4.115 → 1.4.122

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,6 +1,27 @@
1
- import type { ArrayBagelField, ArrayFieldVal, Attributes, BaseBagelField, BglFormSchemaT, FieldByP, IconType, InputBagelField, Path, SchemaChild, SelectBagelField, ShallowBglFormSchemaT, UploadInputProps } from '@bagelink/vue'
1
+ // Import types from type-fest first
2
2
  import type { DefaultPathsOptions, PathsOptions } from 'type-fest/source/paths'
3
- import type { InputTypeHTMLAttribute, MaybeRefOrGetter } from 'vue'
3
+
4
+ // Import types from local types file
5
+ import type {
6
+ Path,
7
+ BaseBagelField,
8
+ InputBagelField,
9
+ SelectBagelField,
10
+ ArrayBagelField,
11
+ ArrayFieldVal,
12
+ Attributes,
13
+ BglFormSchemaT,
14
+ FieldByP,
15
+ SchemaChild,
16
+ ShallowBglFormSchemaT,
17
+ UploadInputProps
18
+ } from '../types/BagelForm'
19
+
20
+ // Local type definitions for internal use only
21
+ interface IconType { name: string }
22
+ interface AutoFillField { name: string }
23
+ interface InputTypeHTMLAttribute { type: string }
24
+ type MaybeRefOrGetter<T> = T | (() => T) | { value: T }
4
25
 
5
26
  export interface InputOptions<
6
27
  T,
@@ -19,7 +40,7 @@ export interface DateOptions<T, K extends Path<T>> extends InputOptions<T, K> {
19
40
  }
20
41
 
21
42
  export interface TextInputOptions<T, K extends Path<T>> extends InputOptions<T, K> {
22
- type?: InputTypeHTMLAttribute
43
+ type?: InputTypeHTMLAttribute['type']
23
44
  pattern?: string
24
45
  multiline?: boolean
25
46
  autoheight?: boolean
@@ -85,12 +106,13 @@ export function richText<
85
106
 
86
107
  export function txtField<
87
108
  T,
109
+ P extends Path<T, PO>,
88
110
  PO extends PathsOptions = DefaultPathsOptions,
89
111
  >(
90
- id?: Path<T, PO>,
112
+ id?: P,
91
113
  label?: string,
92
- options?: TextInputOptions<T, Path<T, PO>>,
93
- ): InputBagelField<T, Path<T, PO>, PO> {
114
+ options?: TextInputOptions<T, P>,
115
+ ): InputBagelField<T, P, PO> {
94
116
  return {
95
117
  $el: 'text',
96
118
  id,
@@ -117,15 +139,20 @@ export function txtField<
117
139
  }
118
140
  }
119
141
 
142
+ // import type { Option } from '@bagelink/vue'
143
+
144
+ // type OptionsSource = Option[] | ((query: string) => Promise<Option[]>)
145
+
120
146
  export function selectField<
121
147
  T,
148
+ P extends Path<T, PO>,
122
149
  PO extends PathsOptions = DefaultPathsOptions,
123
150
  >(
124
- id?: Path<T, PO>,
151
+ id?: P,
125
152
  label?: string,
126
- options?: any[],
127
- fieldOptions?: SlctInputOptions<T, Path<T, PO>>,
128
- ): SelectBagelField<T, Path<T, PO>, PO> {
153
+ options?: any,
154
+ fieldOptions?: SlctInputOptions<T, P>,
155
+ ): SelectBagelField<T, P, PO> {
129
156
  return {
130
157
  $el: 'select',
131
158
  id,
@@ -156,12 +183,13 @@ interface CheckInputOptions<T, K extends Path<T>> extends Omit<InputOptions<T, K
156
183
 
157
184
  export function checkField<
158
185
  T,
186
+ P extends Path<T, PO>,
159
187
  PO extends PathsOptions = DefaultPathsOptions,
160
188
  >(
161
- id?: Path<T, PO>,
189
+ id?: P,
162
190
  label?: string,
163
- options?: CheckInputOptions<T, Path<T, PO>>,
164
- ): BaseBagelField<T, Path<T, PO>, PO> {
191
+ options?: CheckInputOptions<T, P>,
192
+ ): BaseBagelField<T, P, PO> {
165
193
  return {
166
194
  $el: 'check',
167
195
  id,
@@ -244,12 +272,13 @@ export function dateField<
244
272
 
245
273
  export function numField<
246
274
  T,
275
+ P extends Path<T, PO>,
247
276
  PO extends PathsOptions = DefaultPathsOptions,
248
277
  >(
249
- id?: Path<T, PO>,
278
+ id?: P,
250
279
  label?: string,
251
- options?: NumFieldOptions<T, Path<T, PO>>,
252
- ): BaseBagelField<T, Path<T, PO>, PO> {
280
+ options?: NumFieldOptions<T, P>,
281
+ ): BaseBagelField<T, P, PO> {
253
282
  return {
254
283
  $el: 'number',
255
284
  class: options?.class,
@@ -292,12 +321,13 @@ export interface UploadOptions<T, K extends Path<T>> extends Omit<UploadInputPro
292
321
 
293
322
  export function uploadField<
294
323
  T,
324
+ P extends Path<T, PO>,
295
325
  PO extends PathsOptions = DefaultPathsOptions,
296
326
  >(
297
- id?: Path<T, PO>,
327
+ id?: P,
298
328
  label?: string,
299
- options?: UploadOptions<T, Path<T, PO>>,
300
- ): BaseBagelField<T, Path<T, PO>, PO> {
329
+ options?: UploadOptions<T, P>,
330
+ ): BaseBagelField<T, P, PO> {
301
331
  return {
302
332
  $el: 'upload',
303
333
  id,
@@ -1,4 +1,4 @@
1
- import type { Attributes, BglFormSchemaT, Path } from '@bagelink/vue'
1
+ import type { Attributes, BglFormSchemaT, Path } from '../types/BagelForm'
2
2
 
3
3
  const debouncers = new Map<() => void, ReturnType<typeof setTimeout>>()
4
4
 
@@ -93,7 +93,7 @@ export function iffer(field: any, itemData: any) {
93
93
  }
94
94
 
95
95
  export function denullify(itemData?: { [key: string]: any }, fieldID?: string) {
96
- if (!fieldID) return
96
+ if (!fieldID) return undefined
97
97
  return itemData ? itemData[fieldID] : undefined
98
98
  }
99
99
 
@@ -132,7 +132,8 @@ export async function appendScript(src: string, options?: { id?: string }): Prom
132
132
  await sleep(1)
133
133
  // If this script is already loading, return the existing promise
134
134
  if (scriptsLoading.has(scriptId)) {
135
- return scriptsLoading.get(scriptId)!
135
+ const existingPromise = scriptsLoading.get(scriptId)
136
+ if (existingPromise) return existingPromise
136
137
  }
137
138
 
138
139
  // Check if script is already in the document
@@ -157,7 +158,7 @@ export async function appendScript(src: string, options?: { id?: string }): Prom
157
158
  }
158
159
 
159
160
  script.onerror = (err) => {
160
- reject(err)
161
+ reject(new Error(String(err)))
161
162
  // Remove from loading scripts map on error
162
163
  scriptsLoading.delete(scriptId)
163
164
  }
@@ -241,7 +242,8 @@ export function downloadFile(source: string | Blob, fileName?: string) {
241
242
 
242
243
  if (typeof source === 'string') {
243
244
  link.href = upgradeHeaders(source)
244
- link.download = fileName || source.split('/').pop() || 'download'
245
+ const fileNameFromSource = source.split('/').pop()
246
+ link.download = fileName || fileNameFromSource || 'download'
245
247
  } else {
246
248
  const url = URL.createObjectURL(source)
247
249
  link.href = url