@tak-ps/vue-tabler 5.8.0 → 5.10.0
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/CHANGELOG.md +9 -0
- package/components/Schema.vue +103 -2
- package/package.json +1 -1
- package/test/Schema.spec.ts +129 -0
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,15 @@
|
|
|
12
12
|
|
|
13
13
|
### Pending
|
|
14
14
|
|
|
15
|
+
### v5.10.0 - 2026-10-18
|
|
16
|
+
|
|
17
|
+
- :tada: `TablerSchema` renders a property carrying an `@widget` hint through a `widget-<name>` scoped slot (`field`, `property`, `modelValue`, `disabled`, `update`) when the parent provides one, falling back to the input implied by the property type otherwise
|
|
18
|
+
|
|
19
|
+
### v5.9.0 - 2026-10-13
|
|
20
|
+
|
|
21
|
+
- :bug: `TablerSchema` renders an array of strings, numbers or booleans as a list of inline inputs with add & remove controls - previously each entry was an empty `Entry N` box as the item schema has no properties to recurse into
|
|
22
|
+
- :white_check_mark: Add `TablerSchema` primitive list tests
|
|
23
|
+
|
|
15
24
|
### v5.8.0 - 2026-09-21
|
|
16
25
|
|
|
17
26
|
- :tada: Add a `dismissable` prop to `TablerModal`, off by default, that emits `close` when the backdrop is clicked
|
package/components/Schema.vue
CHANGED
|
@@ -7,7 +7,17 @@
|
|
|
7
7
|
:key='key'
|
|
8
8
|
class='py-2 floating-input'
|
|
9
9
|
>
|
|
10
|
-
<template v-if='
|
|
10
|
+
<template v-if='widgetSlot(key)'>
|
|
11
|
+
<slot
|
|
12
|
+
:name='widgetSlot(key)'
|
|
13
|
+
:field='key'
|
|
14
|
+
:property='s.properties[key]'
|
|
15
|
+
:model-value='data[key]'
|
|
16
|
+
:disabled='disabled'
|
|
17
|
+
:update='(value: unknown) => data[key] = value'
|
|
18
|
+
/>
|
|
19
|
+
</template>
|
|
20
|
+
<template v-else-if='isMultiEnum(s.properties[key])'>
|
|
11
21
|
<TablerMultiEnum
|
|
12
22
|
v-model='data[key]'
|
|
13
23
|
:label='key'
|
|
@@ -178,6 +188,78 @@
|
|
|
178
188
|
/>
|
|
179
189
|
</div>
|
|
180
190
|
</template>
|
|
191
|
+
<template v-else-if='isPrimitiveList(s.properties[key])'>
|
|
192
|
+
<div class='d-flex align-items-center'>
|
|
193
|
+
<label
|
|
194
|
+
class='form-label mb-0'
|
|
195
|
+
v-text='key'
|
|
196
|
+
/>
|
|
197
|
+
<span
|
|
198
|
+
v-if='s.properties[key].required'
|
|
199
|
+
class='text-red mx-1'
|
|
200
|
+
>*</span>
|
|
201
|
+
<div
|
|
202
|
+
v-if='!disabled'
|
|
203
|
+
class='ms-auto d-flex'
|
|
204
|
+
>
|
|
205
|
+
<TablerIconButton
|
|
206
|
+
title='Add Entry'
|
|
207
|
+
@click='push(key)'
|
|
208
|
+
>
|
|
209
|
+
<IconPlus
|
|
210
|
+
:size='32'
|
|
211
|
+
stroke='1'
|
|
212
|
+
/>
|
|
213
|
+
</TablerIconButton>
|
|
214
|
+
</div>
|
|
215
|
+
</div>
|
|
216
|
+
<div
|
|
217
|
+
v-if='s.properties[key].description'
|
|
218
|
+
class='text-muted small mb-1'
|
|
219
|
+
v-text='s.properties[key].description'
|
|
220
|
+
/>
|
|
221
|
+
|
|
222
|
+
<div
|
|
223
|
+
v-for='(entry, i) of data[key]'
|
|
224
|
+
:key='i'
|
|
225
|
+
class='d-flex align-items-center my-1'
|
|
226
|
+
>
|
|
227
|
+
<div class='flex-grow-1'>
|
|
228
|
+
<TablerToggle
|
|
229
|
+
v-if='s.properties[key].items.type === "boolean"'
|
|
230
|
+
v-model='data[key][i]'
|
|
231
|
+
:label='`${key} ${Number(i) + 1}`'
|
|
232
|
+
:disabled='disabled'
|
|
233
|
+
/>
|
|
234
|
+
<TablerInput
|
|
235
|
+
v-else
|
|
236
|
+
v-model='data[key][i]'
|
|
237
|
+
:type='s.properties[key].items.type === "string" ? "text" : s.properties[key].items.type'
|
|
238
|
+
:step='s.properties[key].items.type === "integer" ? 1 : "any"'
|
|
239
|
+
:placeholder='`${key} ${Number(i) + 1}`'
|
|
240
|
+
:disabled='disabled'
|
|
241
|
+
/>
|
|
242
|
+
</div>
|
|
243
|
+
<TablerIconButton
|
|
244
|
+
v-if='!disabled'
|
|
245
|
+
title='Remove Entry'
|
|
246
|
+
class='ms-2'
|
|
247
|
+
@click='data[key].splice(i, 1)'
|
|
248
|
+
>
|
|
249
|
+
<IconTrash
|
|
250
|
+
:size='32'
|
|
251
|
+
stroke='1'
|
|
252
|
+
/>
|
|
253
|
+
</TablerIconButton>
|
|
254
|
+
</div>
|
|
255
|
+
|
|
256
|
+
<TablerNone
|
|
257
|
+
v-if='!data[key].length'
|
|
258
|
+
:label='key'
|
|
259
|
+
:create='!disabled'
|
|
260
|
+
@create='push(key)'
|
|
261
|
+
/>
|
|
262
|
+
</template>
|
|
181
263
|
<template v-else-if='s.properties[key].type === "array"'>
|
|
182
264
|
<div class='d-flex'>
|
|
183
265
|
<label
|
|
@@ -301,7 +383,7 @@
|
|
|
301
383
|
</template>
|
|
302
384
|
|
|
303
385
|
<script setup lang="ts">
|
|
304
|
-
import { ref, reactive, computed, watch, onMounted } from 'vue'
|
|
386
|
+
import { ref, reactive, computed, watch, onMounted, useSlots } from 'vue'
|
|
305
387
|
import TablerInput from './input/Input.vue';
|
|
306
388
|
import TablerToggle from './input/Toggle.vue';
|
|
307
389
|
import TablerEnum from './input/Enum.vue';
|
|
@@ -337,6 +419,8 @@ const emit = defineEmits<{
|
|
|
337
419
|
(e: 'update:modelValue', value: any): void;
|
|
338
420
|
}>();
|
|
339
421
|
|
|
422
|
+
const slots = useSlots();
|
|
423
|
+
|
|
340
424
|
const loading = ref(true);
|
|
341
425
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
342
426
|
const s = ref<any>({});
|
|
@@ -364,6 +448,14 @@ const csv = reactive({
|
|
|
364
448
|
/** Selected union variant index per property key */
|
|
365
449
|
const variant = reactive<Record<string, number>>({});
|
|
366
450
|
|
|
451
|
+
/** Name of the `widget-<name>` slot a property's `@widget` hint is rendered with, when the parent provides one */
|
|
452
|
+
const widgetSlot = (key: string): string | undefined => {
|
|
453
|
+
const widget = s.value.properties[key]['@widget'];
|
|
454
|
+
if (typeof widget !== 'string') return;
|
|
455
|
+
const name = `widget-${widget}`;
|
|
456
|
+
return slots[name] ? name : undefined;
|
|
457
|
+
}
|
|
458
|
+
|
|
367
459
|
/** Properties with a fixed const value are seeded but never rendered */
|
|
368
460
|
const visibleKeys = computed<string[]>(() => {
|
|
369
461
|
if (!s.value.properties) return [];
|
|
@@ -467,6 +559,15 @@ const isObjectTable = (prop: any): boolean => {
|
|
|
467
559
|
&& !!prop.items.properties;
|
|
468
560
|
}
|
|
469
561
|
|
|
562
|
+
/** An array of strings, numbers or booleans is rendered as a list of inline inputs */
|
|
563
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
564
|
+
const isPrimitiveList = (prop: any): boolean => {
|
|
565
|
+
return prop.type === 'array'
|
|
566
|
+
&& prop.items
|
|
567
|
+
&& !prop.items.enum
|
|
568
|
+
&& ['string', 'number', 'integer', 'boolean'].includes(prop.items.type);
|
|
569
|
+
}
|
|
570
|
+
|
|
470
571
|
const columns = (key: string): string[] => {
|
|
471
572
|
const prop = s.value.properties[key];
|
|
472
573
|
if (!prop || !isObjectTable(prop)) return [];
|
package/package.json
CHANGED
package/test/Schema.spec.ts
CHANGED
|
@@ -385,6 +385,103 @@ describe('TablerSchema editing primitives', () => {
|
|
|
385
385
|
})
|
|
386
386
|
})
|
|
387
387
|
|
|
388
|
+
describe('TablerSchema primitive lists', () => {
|
|
389
|
+
it('renders an array of strings as one text input per entry', async () => {
|
|
390
|
+
const wrapper = mount(Schema, {
|
|
391
|
+
props: {
|
|
392
|
+
modelValue: { Agencies: ['BVFD', 'KCCAMB'] },
|
|
393
|
+
schema: {
|
|
394
|
+
type: 'object',
|
|
395
|
+
properties: {
|
|
396
|
+
Agencies: { type: 'array', items: { type: 'string' }, description: 'Agency codes' },
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
})
|
|
401
|
+
|
|
402
|
+
await flushPromises()
|
|
403
|
+
|
|
404
|
+
const inputs = wrapper.findAll('input[type="text"]')
|
|
405
|
+
expect(inputs.map((i) => (i.element as HTMLInputElement).value)).toEqual(['BVFD', 'KCCAMB'])
|
|
406
|
+
expect(wrapper.text()).toContain('Agency codes')
|
|
407
|
+
|
|
408
|
+
await inputs[1].setValue('CWVFD')
|
|
409
|
+
await flushPromises()
|
|
410
|
+
expect(lastEmitted(wrapper).Agencies).toEqual(['BVFD', 'CWVFD'])
|
|
411
|
+
})
|
|
412
|
+
|
|
413
|
+
it('adds and removes entries', async () => {
|
|
414
|
+
const wrapper = mount(Schema, {
|
|
415
|
+
props: {
|
|
416
|
+
modelValue: {},
|
|
417
|
+
schema: {
|
|
418
|
+
type: 'object',
|
|
419
|
+
properties: {
|
|
420
|
+
Agencies: { type: 'array', items: { type: 'string' } },
|
|
421
|
+
},
|
|
422
|
+
},
|
|
423
|
+
},
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
await flushPromises()
|
|
427
|
+
expect(wrapper.findAll('input[type="text"]').length).toBe(0)
|
|
428
|
+
|
|
429
|
+
await wrapper.find('[title="Add Entry"]').trigger('click')
|
|
430
|
+
await flushPromises()
|
|
431
|
+
expect(wrapper.findAll('input[type="text"]').length).toBe(1)
|
|
432
|
+
|
|
433
|
+
await wrapper.find('input[type="text"]').setValue('SFD')
|
|
434
|
+
await flushPromises()
|
|
435
|
+
expect(lastEmitted(wrapper).Agencies).toEqual(['SFD'])
|
|
436
|
+
|
|
437
|
+
await wrapper.find('[title="Remove Entry"]').trigger('click')
|
|
438
|
+
await flushPromises()
|
|
439
|
+
expect(lastEmitted(wrapper).Agencies).toEqual([])
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
it('emits typed values for number and boolean lists', async () => {
|
|
443
|
+
const wrapper = mount(Schema, {
|
|
444
|
+
props: {
|
|
445
|
+
modelValue: { Ports: [80], Flags: [false] },
|
|
446
|
+
schema: {
|
|
447
|
+
type: 'object',
|
|
448
|
+
properties: {
|
|
449
|
+
Ports: { type: 'array', items: { type: 'integer' } },
|
|
450
|
+
Flags: { type: 'array', items: { type: 'boolean' } },
|
|
451
|
+
},
|
|
452
|
+
},
|
|
453
|
+
},
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
await flushPromises()
|
|
457
|
+
|
|
458
|
+
await wrapper.find('input[type="number"]').setValue('443')
|
|
459
|
+
await wrapper.find('.form-switch input').setValue(true)
|
|
460
|
+
await flushPromises()
|
|
461
|
+
|
|
462
|
+
const data = lastEmitted(wrapper)
|
|
463
|
+
expect(data.Ports).toEqual([443])
|
|
464
|
+
expect(data.Flags).toEqual([true])
|
|
465
|
+
})
|
|
466
|
+
|
|
467
|
+
it('leaves enum arrays to the multi enum control', async () => {
|
|
468
|
+
const wrapper = mount(Schema, {
|
|
469
|
+
props: {
|
|
470
|
+
modelValue: {},
|
|
471
|
+
schema: {
|
|
472
|
+
type: 'object',
|
|
473
|
+
properties: {
|
|
474
|
+
Roles: { type: 'array', uniqueItems: true, items: { type: 'string', enum: ['admin', 'user'] } },
|
|
475
|
+
},
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
})
|
|
479
|
+
|
|
480
|
+
await flushPromises()
|
|
481
|
+
expect(wrapper.find('[title="Add Entry"]').exists()).toBe(false)
|
|
482
|
+
})
|
|
483
|
+
})
|
|
484
|
+
|
|
388
485
|
const DEFAULT_SCHEMA = {
|
|
389
486
|
type: 'object',
|
|
390
487
|
properties: {
|
|
@@ -515,4 +612,36 @@ describe('TablerSchema applying default values', () => {
|
|
|
515
612
|
expect((wrapper.find('select').element as HTMLSelectElement).value).toBe('Team Account')
|
|
516
613
|
expect(lastEmitted(wrapper)).toEqual({ Source: { Mode: 'Team', TeamId: 't', Verbose: true } })
|
|
517
614
|
})
|
|
615
|
+
|
|
616
|
+
it('renders a property with an @widget hint through its slot and takes the slot update', async () => {
|
|
617
|
+
const wrapper = mount(Schema, {
|
|
618
|
+
props: {
|
|
619
|
+
modelValue: {},
|
|
620
|
+
schema: {
|
|
621
|
+
type: 'object',
|
|
622
|
+
properties: {
|
|
623
|
+
Type: { type: 'string', default: 'a-f-G', '@widget': 'type' },
|
|
624
|
+
Icon: { type: 'string', '@widget': 'icon' },
|
|
625
|
+
},
|
|
626
|
+
},
|
|
627
|
+
},
|
|
628
|
+
slots: {
|
|
629
|
+
'widget-type': `<template #widget-type='{ field, modelValue, update }'>
|
|
630
|
+
<button class='widget' :data-field='field' @click='update("a-h-G")'>{{ modelValue }}</button>
|
|
631
|
+
</template>`,
|
|
632
|
+
},
|
|
633
|
+
})
|
|
634
|
+
|
|
635
|
+
await flushPromises()
|
|
636
|
+
|
|
637
|
+
const widget = wrapper.get('button.widget')
|
|
638
|
+
expect(widget.attributes('data-field')).toBe('Type')
|
|
639
|
+
expect(widget.text()).toBe('a-f-G')
|
|
640
|
+
expect(wrapper.findAll('input').length).toBe(1)
|
|
641
|
+
|
|
642
|
+
await widget.trigger('click')
|
|
643
|
+
await flushPromises()
|
|
644
|
+
|
|
645
|
+
expect(lastEmitted(wrapper)).toEqual({ Type: 'a-h-G', Icon: '' })
|
|
646
|
+
})
|
|
518
647
|
})
|