@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.
- package/dist/components/BglComponent.vue.d.ts.map +1 -1
- package/dist/components/TableSchema.vue.d.ts.map +1 -1
- package/dist/components/form/BglField.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/SelectInput.vue.d.ts +0 -4
- package/dist/components/form/inputs/SelectInput.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/TelInput.vue.d.ts +1 -1
- package/dist/components/form/inputs/TelInput.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/TextInput.vue.d.ts +0 -2
- package/dist/components/form/inputs/TextInput.vue.d.ts.map +1 -1
- package/dist/index.cjs +68 -48
- package/dist/index.mjs +68 -48
- package/dist/style.css +69 -69
- package/dist/utils/BagelFormUtils.d.ts +2 -228
- package/dist/utils/BagelFormUtils.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/BglComponent.vue +20 -8
- package/src/components/TableSchema.vue +0 -1
- package/src/components/form/BglField.vue +5 -1
- package/src/components/form/inputs/RangeInput.vue +4 -4
- package/src/components/form/inputs/TextInput.vue +6 -8
- package/src/utils/BagelFormUtils.ts +3 -3
- package/src/utils/index.ts +9 -19
|
@@ -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
|
-
|
|
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
|
-
{{
|
|
165
|
-
<
|
|
171
|
+
{{ computedFieldData }}
|
|
172
|
+
<template
|
|
166
173
|
v-for="(child, ii) in field.children"
|
|
167
|
-
:
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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>
|
|
@@ -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
|
-
|
|
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="
|
|
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="
|
|
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
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
void debounceUpdate()
|
|
58
|
+
emitValue()
|
|
59
|
+
debounce(emitValue, 300)
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
watch(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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:
|
|
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:
|
|
203
|
+
$el: 'bagelform',
|
|
204
204
|
attrs: {
|
|
205
205
|
schema: [idOrField, ...schema]
|
|
206
206
|
},
|
package/src/utils/index.ts
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
import type { Attributes, BglFormSchemaT } from '@bagelink/vue'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 {
|