@tak-ps/vue-tabler 5.7.0 → 5.9.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 +10 -0
- package/components/Modal.vue +16 -2
- package/components/Schema.vue +81 -0
- package/package.json +1 -1
- package/test/Modal.spec.ts +58 -0
- package/test/Schema.spec.ts +97 -0
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,16 @@
|
|
|
12
12
|
|
|
13
13
|
### Pending
|
|
14
14
|
|
|
15
|
+
### v5.9.0 - 2026-10-13
|
|
16
|
+
|
|
17
|
+
- :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
|
|
18
|
+
- :white_check_mark: Add `TablerSchema` primitive list tests
|
|
19
|
+
|
|
20
|
+
### v5.8.0 - 2026-09-21
|
|
21
|
+
|
|
22
|
+
- :tada: Add a `dismissable` prop to `TablerModal`, off by default, that emits `close` when the backdrop is clicked
|
|
23
|
+
- :white_check_mark: Add `TablerModal` tests
|
|
24
|
+
|
|
15
25
|
### v5.7.0 - 2026-09-18
|
|
16
26
|
|
|
17
27
|
- :tada: Add `TablerMarkdownEditor`, a WYSIWYG Markdown editor built on Tiptap with a formatting toolbar & table editing. It is `v-model`'d with a Markdown string, emits `submit` on `Ctrl/Cmd+Enter` and is exported as an async component so ProseMirror is only loaded when an editor is first rendered
|
package/components/Modal.vue
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
style='display: block;'
|
|
14
14
|
aria-modal='true'
|
|
15
15
|
role='dialog'
|
|
16
|
+
@mousedown='pressed = $event.target'
|
|
17
|
+
@click.self='clickAway'
|
|
16
18
|
>
|
|
17
19
|
<div
|
|
18
20
|
class='modal-dialog modal-dialog-centered'
|
|
@@ -39,14 +41,26 @@ import { ref, onMounted, nextTick } from 'vue'
|
|
|
39
41
|
export interface ModalProps {
|
|
40
42
|
size?: 'sm' | 'md' | 'lg' | 'xl';
|
|
41
43
|
fade?: boolean;
|
|
44
|
+
dismissable?: boolean;
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
withDefaults(defineProps<ModalProps>(), {
|
|
47
|
+
const props = withDefaults(defineProps<ModalProps>(), {
|
|
45
48
|
size: 'sm',
|
|
46
|
-
fade: true
|
|
49
|
+
fade: true,
|
|
50
|
+
dismissable: false
|
|
47
51
|
});
|
|
48
52
|
|
|
53
|
+
const emit = defineEmits<{
|
|
54
|
+
(e: 'close'): void
|
|
55
|
+
}>()
|
|
56
|
+
|
|
49
57
|
const modal = ref<HTMLElement | null>(null)
|
|
58
|
+
const pressed = ref<EventTarget | null>(null)
|
|
59
|
+
|
|
60
|
+
// Ignore drags that start inside the dialog and end on the backdrop
|
|
61
|
+
const clickAway = () => {
|
|
62
|
+
if (props.dismissable && pressed.value === modal.value) emit('close')
|
|
63
|
+
}
|
|
50
64
|
|
|
51
65
|
onMounted(() => {
|
|
52
66
|
nextTick(() => {
|
package/components/Schema.vue
CHANGED
|
@@ -178,6 +178,78 @@
|
|
|
178
178
|
/>
|
|
179
179
|
</div>
|
|
180
180
|
</template>
|
|
181
|
+
<template v-else-if='isPrimitiveList(s.properties[key])'>
|
|
182
|
+
<div class='d-flex align-items-center'>
|
|
183
|
+
<label
|
|
184
|
+
class='form-label mb-0'
|
|
185
|
+
v-text='key'
|
|
186
|
+
/>
|
|
187
|
+
<span
|
|
188
|
+
v-if='s.properties[key].required'
|
|
189
|
+
class='text-red mx-1'
|
|
190
|
+
>*</span>
|
|
191
|
+
<div
|
|
192
|
+
v-if='!disabled'
|
|
193
|
+
class='ms-auto d-flex'
|
|
194
|
+
>
|
|
195
|
+
<TablerIconButton
|
|
196
|
+
title='Add Entry'
|
|
197
|
+
@click='push(key)'
|
|
198
|
+
>
|
|
199
|
+
<IconPlus
|
|
200
|
+
:size='32'
|
|
201
|
+
stroke='1'
|
|
202
|
+
/>
|
|
203
|
+
</TablerIconButton>
|
|
204
|
+
</div>
|
|
205
|
+
</div>
|
|
206
|
+
<div
|
|
207
|
+
v-if='s.properties[key].description'
|
|
208
|
+
class='text-muted small mb-1'
|
|
209
|
+
v-text='s.properties[key].description'
|
|
210
|
+
/>
|
|
211
|
+
|
|
212
|
+
<div
|
|
213
|
+
v-for='(entry, i) of data[key]'
|
|
214
|
+
:key='i'
|
|
215
|
+
class='d-flex align-items-center my-1'
|
|
216
|
+
>
|
|
217
|
+
<div class='flex-grow-1'>
|
|
218
|
+
<TablerToggle
|
|
219
|
+
v-if='s.properties[key].items.type === "boolean"'
|
|
220
|
+
v-model='data[key][i]'
|
|
221
|
+
:label='`${key} ${Number(i) + 1}`'
|
|
222
|
+
:disabled='disabled'
|
|
223
|
+
/>
|
|
224
|
+
<TablerInput
|
|
225
|
+
v-else
|
|
226
|
+
v-model='data[key][i]'
|
|
227
|
+
:type='s.properties[key].items.type === "string" ? "text" : s.properties[key].items.type'
|
|
228
|
+
:step='s.properties[key].items.type === "integer" ? 1 : "any"'
|
|
229
|
+
:placeholder='`${key} ${Number(i) + 1}`'
|
|
230
|
+
:disabled='disabled'
|
|
231
|
+
/>
|
|
232
|
+
</div>
|
|
233
|
+
<TablerIconButton
|
|
234
|
+
v-if='!disabled'
|
|
235
|
+
title='Remove Entry'
|
|
236
|
+
class='ms-2'
|
|
237
|
+
@click='data[key].splice(i, 1)'
|
|
238
|
+
>
|
|
239
|
+
<IconTrash
|
|
240
|
+
:size='32'
|
|
241
|
+
stroke='1'
|
|
242
|
+
/>
|
|
243
|
+
</TablerIconButton>
|
|
244
|
+
</div>
|
|
245
|
+
|
|
246
|
+
<TablerNone
|
|
247
|
+
v-if='!data[key].length'
|
|
248
|
+
:label='key'
|
|
249
|
+
:create='!disabled'
|
|
250
|
+
@create='push(key)'
|
|
251
|
+
/>
|
|
252
|
+
</template>
|
|
181
253
|
<template v-else-if='s.properties[key].type === "array"'>
|
|
182
254
|
<div class='d-flex'>
|
|
183
255
|
<label
|
|
@@ -467,6 +539,15 @@ const isObjectTable = (prop: any): boolean => {
|
|
|
467
539
|
&& !!prop.items.properties;
|
|
468
540
|
}
|
|
469
541
|
|
|
542
|
+
/** An array of strings, numbers or booleans is rendered as a list of inline inputs */
|
|
543
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
544
|
+
const isPrimitiveList = (prop: any): boolean => {
|
|
545
|
+
return prop.type === 'array'
|
|
546
|
+
&& prop.items
|
|
547
|
+
&& !prop.items.enum
|
|
548
|
+
&& ['string', 'number', 'integer', 'boolean'].includes(prop.items.type);
|
|
549
|
+
}
|
|
550
|
+
|
|
470
551
|
const columns = (key: string): string[] => {
|
|
471
552
|
const prop = s.value.properties[key];
|
|
472
553
|
if (!prop || !isObjectTable(prop)) return [];
|
package/package.json
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import { mount, VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import Modal from '../components/Modal.vue'
|
|
4
|
+
|
|
5
|
+
let wrapper: VueWrapper | undefined
|
|
6
|
+
|
|
7
|
+
const mountModal = (props: Record<string, unknown> = {}) => {
|
|
8
|
+
wrapper = mount(Modal, {
|
|
9
|
+
props: { fade: false, ...props },
|
|
10
|
+
slots: { default: '<div class="modal-body">Body</div>' },
|
|
11
|
+
attachTo: document.body,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
return wrapper
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const click = (down: Element, up: Element = down) => {
|
|
18
|
+
down.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }))
|
|
19
|
+
up.dispatchEvent(new MouseEvent('click', { bubbles: true }))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('TablerModal', () => {
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
wrapper?.unmount()
|
|
25
|
+
wrapper = undefined
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('does not emit close on a backdrop click by default', () => {
|
|
29
|
+
const modal = mountModal()
|
|
30
|
+
click(document.body.querySelector('.modal') as Element)
|
|
31
|
+
|
|
32
|
+
expect(modal.emitted('close')).toBeUndefined()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('emits close on a backdrop click when dismissable', () => {
|
|
36
|
+
const modal = mountModal({ dismissable: true })
|
|
37
|
+
click(document.body.querySelector('.modal') as Element)
|
|
38
|
+
|
|
39
|
+
expect(modal.emitted('close')).toHaveLength(1)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('does not emit close for a click inside of the dialog', () => {
|
|
43
|
+
const modal = mountModal({ dismissable: true })
|
|
44
|
+
click(document.body.querySelector('.modal-body') as Element)
|
|
45
|
+
|
|
46
|
+
expect(modal.emitted('close')).toBeUndefined()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('does not emit close for a drag from the dialog onto the backdrop', () => {
|
|
50
|
+
const modal = mountModal({ dismissable: true })
|
|
51
|
+
click(
|
|
52
|
+
document.body.querySelector('.modal-body') as Element,
|
|
53
|
+
document.body.querySelector('.modal') as Element,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
expect(modal.emitted('close')).toBeUndefined()
|
|
57
|
+
})
|
|
58
|
+
})
|
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: {
|