@bagelink/vue 0.0.1048 → 0.0.1056

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.
@@ -117,6 +117,10 @@ const fieldData = $computed({
117
117
  }
118
118
  })
119
119
 
120
+ const computedFieldData = $computed(
121
+ () => props.field.transform?.(fieldData, props.modelValue as T) ?? fieldData
122
+ )
123
+
120
124
  const vIf = $computed(() => {
121
125
  if (props.field['v-if'] === undefined && props.field.vIf === undefined) return true
122
126
  if (typeof props.field['v-if'] === 'boolean' || typeof props.field.vIf === 'boolean') return props.field['v-if']
@@ -132,7 +136,10 @@ const computedOptions = $computed(
132
136
 
133
137
  const computedAttrs = $computed(() => {
134
138
  const attrs = { ...customAttrs, ...props.field.attrs }
135
- return bindAttrs(attrs, fieldData, props.modelValue)
139
+ const boundAttrs = bindAttrs(attrs, fieldData, props.modelValue)
140
+ return Object.fromEntries(
141
+ Object.entries(boundAttrs).filter(([_, value]) => value !== undefined)
142
+ )
136
143
  })
137
144
 
138
145
  const computedClass = $computed(
@@ -161,14 +168,19 @@ const computedClass = $computed(
161
168
  <slot />
162
169
  </template>
163
170
  <template v-else>
164
- {{ fieldData }}
165
- <BglComponent
171
+ {{ computedFieldData }}
172
+ <template
166
173
  v-for="(child, ii) in field.children"
167
- :id="[props.id, child.id].filter(Boolean).join('.')"
168
- :key="child.id || ii"
169
- :field="child"
170
- :parent-path="props.id"
171
- />
174
+ :key="ii"
175
+ >
176
+ <BglComponent
177
+ v-if="(typeof child !== 'string')"
178
+ :id="[props.id, child.id].filter(Boolean).join('.')"
179
+ :field="child"
180
+ :parent-path="props.id"
181
+ />
182
+ <span v-else>{{ child }}</span>
183
+ </template>
172
184
  </template>
173
185
  </component>
174
186
  </template>
@@ -113,7 +113,6 @@ function transform(rowData: any) {
113
113
 
114
114
  for (const field of schemaFields) {
115
115
  const fieldData = rowData[`${field.id}`]
116
-
117
116
  const newFieldVal = field.transform?.(fieldData, rowData)
118
117
 
119
118
  Object.assign(obj, {
@@ -95,7 +95,10 @@ const computedOptions = $computed(
95
95
  const computedAttrs = $computed(() => {
96
96
  const attrs = { ...customAttrs, ...props.field.attrs }
97
97
  delete attrs.schema
98
- return bindAttrs(attrs, fieldData, formState?.data.value)
98
+ const boundAttrs = bindAttrs(attrs, fieldData, formState?.data.value)
99
+ return Object.fromEntries(
100
+ Object.entries(boundAttrs).filter(([_, value]) => value !== undefined)
101
+ )
99
102
  })
100
103
 
101
104
  const computedClass = $computed(
@@ -120,6 +123,7 @@ const computedClass = $computed(
120
123
  :helptext="field.helptext"
121
124
  :schema="field.attrs?.schema ?? undefined"
122
125
  >
126
+ {{ computedFieldData }}
123
127
  <template v-for="(child, ii) in field.children" :key="ii">
124
128
  <BglField
125
129
  v-if="(typeof child !== 'string')"
@@ -41,8 +41,8 @@ const toPercentage = $computed(() => ((validTo - min) / (max - min)) * 100)
41
41
 
42
42
  watch(() => props.modelValue, (newVal) => {
43
43
  if (Array.isArray(newVal) && multiRange) {
44
- from = newVal[0]
45
- to = newVal[1]
44
+ from = newVal[0] ?? min
45
+ to = newVal[1] ?? max
46
46
  } else if (!Array.isArray(newVal)) {
47
47
  from = newVal ?? min
48
48
  to = max
@@ -84,7 +84,7 @@ const displayTo = $computed(() => formatValue(validTo))
84
84
  class="from"
85
85
  type="range"
86
86
  :min="min"
87
- :max="multiRange ? validTo : max"
87
+ :max="max"
88
88
  :step="step"
89
89
  :required="required"
90
90
  :disabled="disabled"
@@ -96,7 +96,7 @@ const displayTo = $computed(() => formatValue(validTo))
96
96
  :value="validTo"
97
97
  class="to"
98
98
  type="range"
99
- :min="validFrom"
99
+ :min="min"
100
100
  :max="max"
101
101
  :step="step"
102
102
  :required="required"
@@ -1,8 +1,8 @@
1
1
  <script setup lang="ts">
2
2
  import {
3
+ debounce,
3
4
  MaterialIcon,
4
5
  type MaterialIcons,
5
- useDebounceFn,
6
6
  } from '@bagelink/vue'
7
7
  import { onMounted, watch } from 'vue'
8
8
 
@@ -30,13 +30,11 @@ const props = withDefaults(
30
30
  lines?: number | string
31
31
  autocomplete?: AutoFillField
32
32
  autofocus?: boolean
33
- debounceDelay?: number
34
33
  onFocusout?: (e: FocusEvent) => void
35
34
  }>(),
36
35
  {
37
36
  type: 'text',
38
37
  modelValue: '',
39
- debounceDelay: 300,
40
38
  },
41
39
  )
42
40
  const emit = defineEmits(['update:modelValue', 'debounce'])
@@ -51,14 +49,14 @@ const rows = $computed(() => {
51
49
  return 1
52
50
  })
53
51
 
54
- const debounceUpdate = useDebounceFn(() => { emit('debounce', inputVal) }, props.debounceDelay)
52
+ function emitValue() {
53
+ emit('update:modelValue', inputVal as string)
54
+ }
55
55
 
56
56
  function updateInputVal() {
57
57
  if (props.disabled) return
58
-
59
- emit('update:modelValue', inputVal as string)
60
-
61
- void debounceUpdate()
58
+ emitValue()
59
+ debounce(emitValue, 300)
62
60
  }
63
61
 
64
62
  watch(
@@ -1,4 +1,4 @@
1
- import { BagelForm, type BglFormSchemaT, type Field, type Option, TelInput } from '@bagelink/vue'
1
+ import { type BglFormSchemaT, type Field, type Option, TelInput } from '@bagelink/vue'
2
2
  import { markRaw } from 'vue'
3
3
 
4
4
  interface InputOptions {
@@ -192,7 +192,7 @@ export function uploadField(id: string, label?: string, options?: UploadOptions)
192
192
  export function bglForm(idOrField?: string | Field, ...schema: Field[]) {
193
193
  if (typeof idOrField === 'string') {
194
194
  return {
195
- $el: markRaw(BagelForm),
195
+ $el: 'bagelform',
196
196
  id: idOrField,
197
197
  attrs: {
198
198
  schema: [idOrField, ...schema],
@@ -200,7 +200,7 @@ export function bglForm(idOrField?: string | Field, ...schema: Field[]) {
200
200
  }
201
201
  }
202
202
  return {
203
- $el: markRaw(BagelForm),
203
+ $el: 'bagelform',
204
204
  attrs: {
205
205
  schema: [idOrField, ...schema]
206
206
  },
@@ -1,24 +1,14 @@
1
1
  import type { Attributes, BglFormSchemaT } from '@bagelink/vue'
2
2
 
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)
14
- }
15
-
16
- const callNow = immediate && timeout === undefined
17
- clearTimeout(timeout)
18
- timeout = setTimeout(later, wait)
19
-
20
- if (callNow) callback.apply(this, args)
21
- }
3
+ const debouncers = new Map<() => void, ReturnType<typeof setTimeout>>()
4
+
5
+ export function debounce(fn: () => void, wait: number = 500) {
6
+ clearTimeout(debouncers.get(fn))
7
+ const timeout = setTimeout(() => {
8
+ fn()
9
+ debouncers.delete(fn)
10
+ }, wait)
11
+ debouncers.set(fn, timeout)
22
12
  }
23
13
 
24
14
  export function keyToLabel(key?: string): string | undefined {