@kinetis/vector-ui 0.10.0 → 0.10.2
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 +27 -0
- package/app/components/Vx/Action/Dialog.vue +6 -7
- package/app/components/Vx/Cell/RichText.vue +1 -1
- package/app/components/Vx/Import/Dialog.vue +14 -3
- package/app/components/Vx/Input/KeyValue.vue +9 -4
- package/app/components/Vx/Input/Number.vue +2 -1
- package/app/components/Vx/Input/Relation.vue +9 -4
- package/app/components/Vx/Input/Repeater.vue +15 -5
- package/app/components/Vx/Input/RichText.vue +1 -1
- package/app/components/Vx/List/BulkEdit.vue +5 -5
- package/app/components/Vx/List/FilterBar.vue +14 -10
- package/app/components/Vx/Resource/Audit.vue +4 -1
- package/app/components/Vx/Resource/Form.vue +11 -6
- package/app/components/Vx/Resource/RelationPanel.vue +2 -1
- package/app/components/Vx/Resource/Table.vue +29 -13
- package/app/components/Vx/Widget/Card.vue +2 -1
- package/app/components/Vx/Widget/Table.vue +14 -2
- package/app/components/Vx/Widget/Trend.vue +1 -1
- package/app/composables/useVectorBranding.ts +1 -1
- package/app/composables/useVectorExtensions.ts +1 -1
- package/app/composables/useVectorFields.ts +7 -1
- package/app/composables/useVectorForm.ts +2 -1
- package/app/composables/useVectorIdle.ts +3 -1
- package/app/composables/useVectorImpersonation.ts +11 -11
- package/app/composables/useVectorInputs.ts +6 -6
- package/app/composables/useVectorLocale.ts +3 -5
- package/app/composables/useVectorResource.ts +31 -30
- package/app/i18n/index.ts +15 -1
- package/app/pages/jobs/index.vue +15 -2
- package/app/pages/login.vue +2 -1
- package/app/plugins/vector-extensions.client.ts +1 -1
- package/app/plugins/vector-i18n.ts +2 -2
- package/app/utils/files.ts +5 -2
- package/app/utils/internal/patterns.ts +50 -0
- package/app/utils/richtext.ts +2 -2
- package/app/utils/rules.ts +2 -12
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.10.2] - 2026-10-21
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- A row of the jobs list, and a linked row of a dashboard table widget,
|
|
15
|
+
takes keyboard focus and opens with Enter or Space, as a click opens
|
|
16
|
+
it.
|
|
17
|
+
- An inline-editable list cell is a button, so Space starts editing it
|
|
18
|
+
as Enter does.
|
|
19
|
+
- Table column headers are marked as column headers; a trend widget's
|
|
20
|
+
sparkline is hidden from screen readers, which read its range and total
|
|
21
|
+
beside it; the rich text editor's image picker is labelled.
|
|
22
|
+
- A key-value input, a repeater's rows and the filter bar's "any of"
|
|
23
|
+
groups are fieldsets, with the accessible names they had.
|
|
24
|
+
- The Email rule, the sign-in form's e-mail check and the Regex rule's
|
|
25
|
+
delimiter parsing run in linear time, accepting exactly what they
|
|
26
|
+
accepted before.
|
|
27
|
+
|
|
28
|
+
## [0.10.1] - 2026-10-21
|
|
29
|
+
|
|
30
|
+
### Security
|
|
31
|
+
|
|
32
|
+
- `markdown-it` is now required at `^15.0.3`, which fixes two
|
|
33
|
+
quadratic-time denials of service: a multi-line link reference
|
|
34
|
+
definition (GHSA-gfr2-rv44-r23c), and inline HTML parsing with HTML
|
|
35
|
+
enabled (GHSA-vfgh-jcmw-g37q).
|
|
36
|
+
|
|
10
37
|
## [0.10.0] - 2026-10-20
|
|
11
38
|
|
|
12
39
|
### Added
|
|
@@ -28,13 +28,12 @@ for (const field of props.action.fields) {
|
|
|
28
28
|
values[field.name] = initialValue(field)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const subject = computed(() =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
: t('actions.subjectCount', { count: props.count, label: noun(props.count === 1 ? props.resource.labelSingular : props.resource.label) }))
|
|
31
|
+
const subject = computed(() => {
|
|
32
|
+
if (props.action.standalone) return ''
|
|
33
|
+
if (!props.selection?.all) return t('actions.subjectCount', { count: props.count, label: noun(props.count === 1 ? props.resource.labelSingular : props.resource.label) })
|
|
34
|
+
if (props.count === null) return t('actions.subjectAllUncounted', { label: noun(props.resource.labelSingular) })
|
|
35
|
+
return t('actions.subjectAll', { label: noun(props.resource.labelSingular), count: props.count })
|
|
36
|
+
})
|
|
38
37
|
|
|
39
38
|
async function run(event: SubmitEventPromise) {
|
|
40
39
|
const { valid } = await event
|
|
@@ -27,7 +27,7 @@ watch([html, root], async () => {
|
|
|
27
27
|
if (!root.value || !imageField || id === undefined || id === null) return
|
|
28
28
|
|
|
29
29
|
for (const img of root.value.querySelectorAll<HTMLImageElement>('img[data-vector-key]')) {
|
|
30
|
-
const key = img.
|
|
30
|
+
const key = img.dataset.vectorKey!
|
|
31
31
|
client.fileBlob(id as string | number, imageField, key).then(dataUrl).then((url) => { img.src = url }).catch(() => undefined)
|
|
32
32
|
}
|
|
33
33
|
}, { immediate: true })
|
|
@@ -20,13 +20,24 @@ const error = ref<string | null>(null)
|
|
|
20
20
|
const mode = ref<VectorImportMode>(props.resource.permissions.create ? 'create' : 'update')
|
|
21
21
|
const key = ref('')
|
|
22
22
|
|
|
23
|
+
/** Whether the user may import in a mode: an upsert both creates and updates. */
|
|
24
|
+
function permits(m: VectorImportMode): boolean {
|
|
25
|
+
const { create, update } = props.resource.permissions
|
|
26
|
+
if (m === 'create') return create
|
|
27
|
+
if (m === 'update') return update
|
|
28
|
+
return create && update
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
const modes = computed(() => (['create', 'update', 'upsert'] as const)
|
|
24
|
-
.filter(
|
|
32
|
+
.filter(permits)
|
|
25
33
|
.map(m => ({ title: t(`list.import.modes.${m}`), value: m })))
|
|
26
34
|
|
|
35
|
+
// the form views whose fields each mode writes
|
|
36
|
+
const modeViews: Record<VectorImportMode, string[]> = { create: ['create'], update: ['update'], upsert: ['create', 'update'] }
|
|
37
|
+
|
|
27
38
|
// what the mode writes; an update also maps the column it matches rows by
|
|
28
39
|
const fields = computed(() => {
|
|
29
|
-
const views =
|
|
40
|
+
const views = modeViews[mode.value]
|
|
30
41
|
const writable = props.resource.fields.filter(f => !f.readonly && f.views.some(v => views.includes(v)) && !['id', 'hasOne', 'hasMany', 'computed'].includes(f.type))
|
|
31
42
|
const keys = mode.value === 'create' ? [] : keyFields.value.filter(f => !writable.includes(f))
|
|
32
43
|
|
|
@@ -110,7 +121,7 @@ async function start() {
|
|
|
110
121
|
</div>
|
|
111
122
|
<p v-if="mode !== 'create'" class="text-body-2 text-medium-emphasis mb-3">{{ t(`list.import.modeHelp.${mode}`) }}</p>
|
|
112
123
|
<v-table density="compact">
|
|
113
|
-
<thead><tr><th>{{ t('list.import.csvColumn') }}</th><th>{{ t('list.import.sample') }}</th><th style="width: 260px">{{ t('list.field') }}</th></tr></thead>
|
|
124
|
+
<thead><tr><th scope="col">{{ t('list.import.csvColumn') }}</th><th scope="col">{{ t('list.import.sample') }}</th><th scope="col" style="width: 260px">{{ t('list.field') }}</th></tr></thead>
|
|
114
125
|
<tbody>
|
|
115
126
|
<tr v-for="header in preview.headers" :key="header">
|
|
116
127
|
<td>{{ header }}</td>
|
|
@@ -50,9 +50,9 @@ const messages = computed(() => [...(repeated.value.length ? [t('fields.keyValue
|
|
|
50
50
|
</script>
|
|
51
51
|
|
|
52
52
|
<template>
|
|
53
|
-
<
|
|
53
|
+
<fieldset class="vx-fieldset" :aria-label="field.label">
|
|
54
54
|
<div class="text-body-2 text-medium-emphasis mb-1">{{ field.label }}</div>
|
|
55
|
-
<
|
|
55
|
+
<fieldset v-for="(row, index) in rows" :key="index" class="vx-fieldset d-flex ga-2 align-start mb-1" :aria-label="t('fields.keyValue.entry', { n: index + 1 })">
|
|
56
56
|
<v-text-field
|
|
57
57
|
v-model="row.key"
|
|
58
58
|
:label="keyLabel"
|
|
@@ -70,9 +70,14 @@ const messages = computed(() => [...(repeated.value.length ? [t('fields.keyValue
|
|
|
70
70
|
@update:model-value="sync"
|
|
71
71
|
/>
|
|
72
72
|
<v-btn icon="mdi-close" variant="text" size="small" class="mt-1" :disabled="disabled" :aria-label="t('fields.keyValue.remove', { n: index + 1 })" @click="remove(index)" />
|
|
73
|
-
</
|
|
73
|
+
</fieldset>
|
|
74
74
|
<v-btn variant="text" size="small" prepend-icon="mdi-plus" :disabled="disabled || rows.length >= max" @click="add">{{ t('fields.keyValue.add') }}</v-btn>
|
|
75
75
|
<div v-for="message in messages" :key="message" class="text-error text-caption" role="alert">{{ message }}</div>
|
|
76
76
|
<div v-if="field.help" class="text-caption text-medium-emphasis">{{ field.help }}</div>
|
|
77
|
-
</
|
|
77
|
+
</fieldset>
|
|
78
78
|
</template>
|
|
79
|
+
|
|
80
|
+
<style scoped>
|
|
81
|
+
/* a fieldset that groups without a fieldset's own border, padding and margin */
|
|
82
|
+
.vx-fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
|
|
83
|
+
</style>
|
|
@@ -5,7 +5,8 @@ const props = defineProps<{ field: VectorField, rules: ((v: unknown) => true | s
|
|
|
5
5
|
const model = defineModel<number | null>()
|
|
6
6
|
const decimals = computed(() => {
|
|
7
7
|
const d = fieldProps(props.field).decimals
|
|
8
|
-
|
|
8
|
+
if (typeof d === 'number') return d
|
|
9
|
+
return props.field.valueType === 'float' ? 2 : 0
|
|
9
10
|
})
|
|
10
11
|
</script>
|
|
11
12
|
|
|
@@ -36,7 +36,8 @@ const dependency = computed<string | number | null>(() => {
|
|
|
36
36
|
if (!dependsOn.value) return null
|
|
37
37
|
const value = props.record?.[dependsOn.value.field]
|
|
38
38
|
const key = value && typeof value === 'object' && 'id' in value ? (value as { id: unknown }).id : value
|
|
39
|
-
|
|
39
|
+
if (typeof key === 'number' || (typeof key === 'string' && key !== '')) return key
|
|
40
|
+
return typeof key === 'boolean' ? Number(key) : null
|
|
40
41
|
})
|
|
41
42
|
const waiting = computed(() => dependsOn.value !== null && dependency.value === null)
|
|
42
43
|
|
|
@@ -77,11 +78,15 @@ watch(dependency, (now, before) => {
|
|
|
77
78
|
fetchOptions('')
|
|
78
79
|
})
|
|
79
80
|
|
|
81
|
+
/** The identifiers the input starts with. */
|
|
82
|
+
function initialIds(): (number | string)[] {
|
|
83
|
+
if (multiple.value) return Array.isArray(model.value) ? model.value : []
|
|
84
|
+
return model.value === null || model.value === undefined || Array.isArray(model.value) ? [] : [model.value]
|
|
85
|
+
}
|
|
86
|
+
|
|
80
87
|
// Resolve the labels of an initial value once.
|
|
81
88
|
onMounted(async () => {
|
|
82
|
-
const initial
|
|
83
|
-
? (Array.isArray(model.value) ? model.value : [])
|
|
84
|
-
: (model.value === null || model.value === undefined || Array.isArray(model.value) ? [] : [model.value])
|
|
89
|
+
const initial = initialIds()
|
|
85
90
|
await fetchOptions('', initial.length ? initial : [])
|
|
86
91
|
if (initial.length) await fetchOptions('')
|
|
87
92
|
})
|
|
@@ -39,8 +39,14 @@ watch(() => rows.value.length, (length) => {
|
|
|
39
39
|
if (keys.value.length !== length) keys.value = Array.from({ length }, () => next++)
|
|
40
40
|
}, { immediate: true })
|
|
41
41
|
|
|
42
|
+
/** A new row's value for a column: its default, else unchecked for a checkbox, else empty. */
|
|
43
|
+
function blankValue(f: VectorField): unknown {
|
|
44
|
+
if (f.hasDefault) return f.default
|
|
45
|
+
return f.type === 'boolean' ? false : null
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
function blank(): Record<string, unknown> {
|
|
43
|
-
return Object.fromEntries(columns.value.map(f => [f.name, f
|
|
49
|
+
return Object.fromEntries(columns.value.map(f => [f.name, blankValue(f)]))
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
function add() {
|
|
@@ -93,11 +99,10 @@ onMounted(() => {
|
|
|
93
99
|
<v-alert v-for="message in errorMessages" :key="message" type="error" variant="tonal" density="compact" class="mb-2" :text="message" />
|
|
94
100
|
<p v-if="!child" class="text-medium-emphasis text-body-2">{{ t('fields.repeater.unavailable') }}</p>
|
|
95
101
|
<template v-else>
|
|
96
|
-
<
|
|
102
|
+
<fieldset
|
|
97
103
|
v-for="(row, index) in rows"
|
|
98
104
|
:key="keys[index]"
|
|
99
|
-
class="d-flex ga-2 align-start mb-1"
|
|
100
|
-
role="group"
|
|
105
|
+
class="vx-fieldset d-flex ga-2 align-start mb-1"
|
|
101
106
|
:aria-label="t('fields.repeater.row', { label: child.labelSingular, n: index + 1 })"
|
|
102
107
|
>
|
|
103
108
|
<v-row density="compact" class="flex-grow-1">
|
|
@@ -125,10 +130,15 @@ onMounted(() => {
|
|
|
125
130
|
:aria-label="t('fields.repeater.remove', { label: noun(child.labelSingular), n: index + 1 })"
|
|
126
131
|
@click="remove(index)"
|
|
127
132
|
/>
|
|
128
|
-
</
|
|
133
|
+
</fieldset>
|
|
129
134
|
<v-btn variant="tonal" size="small" prepend-icon="mdi-plus" :disabled="disabled || rows.length >= max" @click="add">
|
|
130
135
|
{{ t('fields.repeater.add', { label: noun(child.labelSingular) }) }}
|
|
131
136
|
</v-btn>
|
|
132
137
|
</template>
|
|
133
138
|
</v-card>
|
|
134
139
|
</template>
|
|
140
|
+
|
|
141
|
+
<style scoped>
|
|
142
|
+
/* a fieldset that groups without a fieldset's own border, padding and margin */
|
|
143
|
+
.vx-fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
|
|
144
|
+
</style>
|
|
@@ -151,7 +151,7 @@ const inTable = computed(() => active('table'))
|
|
|
151
151
|
</template>
|
|
152
152
|
<template v-if="on('image') && rich.imageField">
|
|
153
153
|
<v-btn icon="mdi-image-plus" size="small" variant="text" :loading="uploading" :aria-label="t('fields.richtext.image')" @click="picker?.click()" />
|
|
154
|
-
<input ref="picker" type="file" accept="image/png,image/jpeg,image/webp,image/gif" class="d-none" @change="insertImage">
|
|
154
|
+
<input ref="picker" type="file" accept="image/png,image/jpeg,image/webp,image/gif" class="d-none" :aria-label="t('fields.richtext.image')" @change="insertImage">
|
|
155
155
|
</template>
|
|
156
156
|
<v-spacer />
|
|
157
157
|
<v-btn icon="mdi-undo" size="small" variant="text" :aria-label="t('fields.richtext.undo')" @click="run(e => e.chain().focus().undo().run())" />
|
|
@@ -34,11 +34,11 @@ watch(chosen, (names) => {
|
|
|
34
34
|
}
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
-
const subject = computed(() =>
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
const subject = computed(() => {
|
|
38
|
+
if (!props.selection.all) return t('list.bulkEdit.some', { count: props.count, noun: noun(props.count === 1 ? props.resource.labelSingular : props.resource.label) })
|
|
39
|
+
if (props.count === null) return t('list.bulkEdit.everyMatchingUncounted', { noun: noun(props.resource.labelSingular) })
|
|
40
|
+
return t('list.bulkEdit.everyMatching', { noun: noun(props.resource.labelSingular), count: props.count })
|
|
41
|
+
})
|
|
42
42
|
|
|
43
43
|
async function save(event: SubmitEventPromise) {
|
|
44
44
|
const { valid } = await event
|
|
@@ -98,14 +98,14 @@ function add() {
|
|
|
98
98
|
const where = target.value
|
|
99
99
|
|
|
100
100
|
if (where === null) {
|
|
101
|
-
model.value = { ...model.value, [name]: { ...
|
|
101
|
+
model.value = { ...model.value, [name]: { ...model.value[name], ...condition } }
|
|
102
102
|
} else if (where.group === -1) {
|
|
103
103
|
groups.value = [...groups.value, [{ [name]: condition }]]
|
|
104
104
|
} else {
|
|
105
105
|
groups.value = groups.value.map((group, g) => {
|
|
106
106
|
if (g !== where.group) return group
|
|
107
107
|
if (where.alternative === -1) return [...group, { [name]: condition }]
|
|
108
|
-
return group.map((alternative, a) => (a === where.alternative ? { ...alternative, [name]: { ...
|
|
108
|
+
return group.map((alternative, a) => (a === where.alternative ? { ...alternative, [name]: { ...alternative[name], ...condition } } : alternative))
|
|
109
109
|
})
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -120,7 +120,7 @@ function removeFromGroup(g: number, a: number, name: string, op: string) {
|
|
|
120
120
|
: group.map((alternative, ai) => {
|
|
121
121
|
if (ai !== a) return alternative
|
|
122
122
|
const next = { ...alternative }
|
|
123
|
-
const ops = { ...
|
|
123
|
+
const ops = { ...next[name] }
|
|
124
124
|
delete ops[op as VectorOperator]
|
|
125
125
|
if (Object.keys(ops).length === 0) delete next[name]
|
|
126
126
|
else next[name] = ops
|
|
@@ -139,7 +139,7 @@ function clearAll() {
|
|
|
139
139
|
|
|
140
140
|
function remove(name: string, op: string) {
|
|
141
141
|
const next = { ...model.value }
|
|
142
|
-
const ops = { ...
|
|
142
|
+
const ops = { ...next[name] }
|
|
143
143
|
delete ops[op as VectorOperator]
|
|
144
144
|
|
|
145
145
|
if (Object.keys(ops).length === 0) delete next[name]
|
|
@@ -175,26 +175,25 @@ const anything = computed(() => active.value.length > 0 || groups.value.length >
|
|
|
175
175
|
<v-chip v-for="chip in active" :key="`${chip.name}.${chip.op}`" closable size="small" variant="tonal" color="primary" @click:close="remove(chip.name, chip.op)">
|
|
176
176
|
{{ chipText(chip.name, chip.op, chip.value) }}
|
|
177
177
|
</v-chip>
|
|
178
|
-
<
|
|
178
|
+
<fieldset
|
|
179
179
|
v-for="(group, g) in groups"
|
|
180
180
|
:key="`group-${g}`"
|
|
181
|
-
class="d-inline-flex align-center flex-wrap ga-1 px-2 py-1 rounded border"
|
|
182
|
-
role="group"
|
|
181
|
+
class="vx-fieldset d-inline-flex align-center flex-wrap ga-1 px-2 py-1 rounded border"
|
|
183
182
|
:aria-label="t('list.filter.anyOfGroup', { n: g + 1 })"
|
|
184
183
|
>
|
|
185
184
|
<span class="text-caption text-medium-emphasis">{{ t('list.filter.anyOf') }}</span>
|
|
186
185
|
<template v-for="(alternative, a) in group" :key="`alternative-${g}-${a}`">
|
|
187
186
|
<span v-if="a > 0" class="text-caption font-weight-medium">{{ t('list.filter.or') }}</span>
|
|
188
|
-
<
|
|
187
|
+
<fieldset class="vx-fieldset d-inline-flex align-center ga-1" :aria-label="t('list.filter.alternative', { n: a + 1 })">
|
|
189
188
|
<v-chip v-for="chip in chipsOf(alternative)" :key="`${chip.name}.${chip.op}`" closable size="small" variant="tonal" color="primary" @click:close="removeFromGroup(g, a, chip.name, chip.op)">
|
|
190
189
|
{{ chipText(chip.name, chip.op, chip.value) }}
|
|
191
190
|
</v-chip>
|
|
192
191
|
<v-btn icon="mdi-plus" size="x-small" variant="text" :aria-label="t('list.filter.addToAlternative', { n: a + 1 })" @click="openAdd({ group: g, alternative: a }, $event)" />
|
|
193
|
-
</
|
|
192
|
+
</fieldset>
|
|
194
193
|
</template>
|
|
195
194
|
<v-btn size="x-small" variant="text" prepend-icon="mdi-plus" @click="openAdd({ group: g, alternative: -1 }, $event)">{{ t('list.filter.orCondition') }}</v-btn>
|
|
196
195
|
<v-btn icon="mdi-close" size="x-small" variant="text" :aria-label="t('list.filter.removeGroup', { n: g + 1 })" @click="groups = groups.filter((_, i) => i !== g)" />
|
|
197
|
-
</
|
|
196
|
+
</fieldset>
|
|
198
197
|
<v-chip v-for="(node, i) in advanced" :key="`advanced-${i}`" closable size="small" variant="outlined" prepend-icon="mdi-code-braces" :title="JSON.stringify(node)" @click:close="advanced = advanced.filter((_, j) => j !== i)">
|
|
199
198
|
{{ t('list.filter.advanced') }}
|
|
200
199
|
</v-chip>
|
|
@@ -222,3 +221,8 @@ const anything = computed(() => active.value.length > 0 || groups.value.length >
|
|
|
222
221
|
<v-btn v-if="anything" size="small" variant="text" @click="clearAll">{{ t('list.filter.clear') }}</v-btn>
|
|
223
222
|
</div>
|
|
224
223
|
</template>
|
|
224
|
+
|
|
225
|
+
<style scoped>
|
|
226
|
+
/* a fieldset that groups without a fieldset's own border, padding and margin */
|
|
227
|
+
.vx-fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
|
|
228
|
+
</style>
|
|
@@ -13,7 +13,10 @@ const { data, status, error, refresh } = await useAsyncData(() => `vector.audit.
|
|
|
13
13
|
const entries = computed<VectorAuditEntry[]>(() => data.value?.data ?? [])
|
|
14
14
|
|
|
15
15
|
const label = (name: string) => props.resource.fields.find(f => f.name === name)?.label ?? name
|
|
16
|
-
|
|
16
|
+
function show(value: unknown): string {
|
|
17
|
+
if (value === null || value === undefined) return t('common.none')
|
|
18
|
+
return typeof value === 'object' ? JSON.stringify(value) : String(value)
|
|
19
|
+
}
|
|
17
20
|
const icon: Record<string, string> = { create: 'mdi-plus-circle-outline', update: 'mdi-pencil-outline', revert: 'mdi-undo-variant', delete: 'mdi-delete-outline', restore: 'mdi-restore', forceDelete: 'mdi-delete-forever-outline' }
|
|
18
21
|
|
|
19
22
|
/** The fields of an entry a revert would put back: shown, and editable on update. */
|
|
@@ -53,14 +53,17 @@ const clone = (value: unknown) => value === undefined ? undefined : JSON.parse(J
|
|
|
53
53
|
const copies = (field: VectorField) => props.operation === 'create' && props.copyOf !== undefined
|
|
54
54
|
&& field.unique !== true && !['file', 'image', 'manyToMany', 'hasMany'].includes(field.type)
|
|
55
55
|
|
|
56
|
+
/** What a field starts with when nothing gives it a value: on create its declared default, else its type's empty one. */
|
|
57
|
+
function initialValue(field: VectorField): unknown {
|
|
58
|
+
return props.operation === 'create' && field.hasDefault ? JSON.parse(JSON.stringify(field.default ?? null)) : defaultFor(field)
|
|
59
|
+
}
|
|
60
|
+
|
|
56
61
|
/** Fills the values from the record, the preset, the record being copied, or each field's default. */
|
|
57
62
|
function start() {
|
|
58
63
|
for (const field of fields.value) {
|
|
59
64
|
const current = props.preset?.[field.name] ?? props.record?.[field.name] ?? (copies(field) ? props.copyOf![field.name] : undefined)
|
|
60
65
|
// a new record starts from each field's default, which the server would apply as well
|
|
61
|
-
let value: unknown = current
|
|
62
|
-
? current
|
|
63
|
-
: props.operation === 'create' && field.hasDefault ? JSON.parse(JSON.stringify(field.default ?? null)) : defaultFor(field)
|
|
66
|
+
let value: unknown = current === undefined ? initialValue(field) : current
|
|
64
67
|
|
|
65
68
|
if (field.type === 'belongsTo' && current && typeof current === 'object' && 'id' in current) {
|
|
66
69
|
value = (current as { id: unknown }).id
|
|
@@ -155,7 +158,8 @@ const chosen = computed<SaveVariant>(() => {
|
|
|
155
158
|
})
|
|
156
159
|
const variantLabel = (variant: SaveVariant) => {
|
|
157
160
|
const verb = props.operation === 'create' ? 'create' : 'save'
|
|
158
|
-
|
|
161
|
+
if (variant === 'close') return t(`common.${verb}`)
|
|
162
|
+
return t(`record.variants.${verb}${variant === 'continue' ? 'Continue' : 'Another'}`)
|
|
159
163
|
}
|
|
160
164
|
|
|
161
165
|
const formRef = ref<{ validate: () => Promise<{ valid: boolean, errors: { id: string | number }[] }>, resetValidation: () => void } | null>(null)
|
|
@@ -224,7 +228,8 @@ async function save({ valid, errors }: { valid: boolean, errors: { id: string |
|
|
|
224
228
|
const key = repeated ? violation.path.slice(0, 3).join('.') : String(violation.path[0] ?? '')
|
|
225
229
|
|
|
226
230
|
if (key && (key in values || repeated)) {
|
|
227
|
-
|
|
231
|
+
serverErrors[key] ??= []
|
|
232
|
+
serverErrors[key].push(`${violation.message.charAt(0).toUpperCase()}${violation.message.slice(1)}`)
|
|
228
233
|
} else {
|
|
229
234
|
formError.value = violation.message
|
|
230
235
|
}
|
|
@@ -284,7 +289,7 @@ defineExpose({ dirty, reset })
|
|
|
284
289
|
// Conditions (visibleWhen, requiredWhen, disabledWhen) follow the values as they are edited.
|
|
285
290
|
// Like the server, they read the stored record overlaid with the values being edited.
|
|
286
291
|
const states = computed<Record<string, VectorFieldState>>(() => {
|
|
287
|
-
const current = { ...
|
|
292
|
+
const current = { ...props.record, ...values }
|
|
288
293
|
return Object.fromEntries(fields.value.map(f => [f.name, fieldState(f, current)]))
|
|
289
294
|
})
|
|
290
295
|
const shownFields = computed(() => fields.value.filter(f => states.value[f.name]?.visible !== false && !(props.preset && f.name in props.preset)))
|
|
@@ -148,7 +148,8 @@ async function created() {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
function label(n: number): string {
|
|
151
|
-
|
|
151
|
+
if (!target.value) return t('record.panel.records')
|
|
152
|
+
return noun(n === 1 ? target.value.labelSingular : target.value.label)
|
|
152
153
|
}
|
|
153
154
|
</script>
|
|
154
155
|
|
|
@@ -92,6 +92,12 @@ let requestId = 0
|
|
|
92
92
|
/** Whether the next load goes back to the first page: a changed search, filter, sort or page size asked for it. */
|
|
93
93
|
let restart = false
|
|
94
94
|
|
|
95
|
+
/** How many pages a step moves from the current one. */
|
|
96
|
+
function pageOffset(step: VectorPageStep): number {
|
|
97
|
+
if (step === 'forward') return 1
|
|
98
|
+
return step === 'back' ? -1 : 0
|
|
99
|
+
}
|
|
100
|
+
|
|
95
101
|
/**
|
|
96
102
|
* Loads the page shown now, or the one $step away on a list that is not
|
|
97
103
|
* counted. The step is taken only once its page has arrived: a request
|
|
@@ -121,7 +127,7 @@ async function load(step: VectorPageStep = 'stay') {
|
|
|
121
127
|
return
|
|
122
128
|
}
|
|
123
129
|
|
|
124
|
-
const target = step === 'first' ? 1 : page.value + (step
|
|
130
|
+
const target = step === 'first' ? 1 : page.value + pageOffset(step)
|
|
125
131
|
const sort: VectorSort[] = sortBy.value.map(s => ({ field: s.key, order: s.order === 'desc' ? 'desc' : 'asc' }))
|
|
126
132
|
const result: VectorPage = await client.list({
|
|
127
133
|
page: target, perPage: itemsPerPage.value, sort, filter: rawFilters(), q: term.value || undefined,
|
|
@@ -204,7 +210,7 @@ function decodeFilter(filter: VectorFilterQuery, known: Set<string>) {
|
|
|
204
210
|
} else if (key === 'and' && Array.isArray(spec)) {
|
|
205
211
|
for (const child of spec) {
|
|
206
212
|
const inner = decodeFilter(child, known)
|
|
207
|
-
for (const [name, ops] of Object.entries(inner.filters)) out.filters[name] = { ...
|
|
213
|
+
for (const [name, ops] of Object.entries(inner.filters)) out.filters[name] = { ...out.filters[name], ...ops }
|
|
208
214
|
out.groups.push(...inner.groups)
|
|
209
215
|
out.advanced.push(...inner.advanced)
|
|
210
216
|
}
|
|
@@ -231,7 +237,8 @@ function applyView(view: VectorSavedView | null) {
|
|
|
231
237
|
// a cursor list orders by the identifier: a view's grouping, sort and summaries do not apply to it
|
|
232
238
|
group.value = !byCursor.value && s.group && known.has(s.group) ? s.group : null
|
|
233
239
|
const sorts = s.sort ? s.sort.split(',').map(e => ({ key: e.replace(/^-/, ''), order: e.startsWith('-') ? 'desc' as const : 'asc' as const })).filter(x => known.has(x.key)) : []
|
|
234
|
-
|
|
240
|
+
if (byCursor.value) sortBy.value = []
|
|
241
|
+
else sortBy.value = sorts.length ? sorts : props.resource.table.defaultSort.map(x => ({ key: x.field, order: x.order }))
|
|
235
242
|
if (s.columns) columns.value = s.columns.split(',').filter(c => props.resource.table.columns.includes(c))
|
|
236
243
|
itemsPerPage.value = s.perPage ?? props.resource.table.perPage
|
|
237
244
|
summaries.value = !byCursor.value && (s.summaries ?? summaries.value)
|
|
@@ -261,6 +268,12 @@ const standaloneActions = computed(() => props.resource.actions.filter(a => a.sh
|
|
|
261
268
|
const dialogAction = ref<VectorAction | null>(null)
|
|
262
269
|
const bulkEditing = ref(false)
|
|
263
270
|
|
|
271
|
+
/** What confirming an operation warns of: nothing for a restore. */
|
|
272
|
+
function operationWarning(op: 'delete' | 'restore' | 'forceDelete'): string | undefined {
|
|
273
|
+
if (op === 'restore') return undefined
|
|
274
|
+
return props.resource.softDelete && op === 'delete' ? t('list.operation.toTrash') : t('list.operation.irreversible')
|
|
275
|
+
}
|
|
276
|
+
|
|
264
277
|
async function operation(op: 'delete' | 'restore' | 'forceDelete') {
|
|
265
278
|
const n = selectionCount.value
|
|
266
279
|
const subject = noun(n === 1 ? props.resource.labelSingular : props.resource.label)
|
|
@@ -268,7 +281,7 @@ async function operation(op: 'delete' | 'restore' | 'forceDelete') {
|
|
|
268
281
|
? { delete: t('list.operation.deleteAllTitle', { noun: subject }), restore: t('list.operation.restoreAllTitle', { noun: subject }), forceDelete: t('list.operation.forceDeleteAllTitle', { noun: subject }) }
|
|
269
282
|
: { delete: t('list.operation.deleteTitle', { count: n, noun: subject }), restore: t('list.operation.restoreTitle', { count: n, noun: subject }), forceDelete: t('list.operation.forceDeleteTitle', { count: n, noun: subject }) }
|
|
270
283
|
|
|
271
|
-
if (!await confirm({ title: titles[op], text:
|
|
284
|
+
if (!await confirm({ title: titles[op], text: operationWarning(op), confirmText: op === 'restore' ? t('common.restore') : t('common.delete'), destructive: op !== 'restore' })) return
|
|
272
285
|
|
|
273
286
|
try {
|
|
274
287
|
const { affected } = await client.batch(op, selection.value)
|
|
@@ -310,12 +323,16 @@ function actionDone() {
|
|
|
310
323
|
// --- rendering helpers ------------------------------------------------
|
|
311
324
|
const groupField = computed(() => props.resource.fields.find(f => f.name === group.value) ?? null)
|
|
312
325
|
|
|
326
|
+
/** The currency a money summary is shown in: the field's own, else the first row's, else euros. */
|
|
327
|
+
function summaryCurrency(field: VectorField): string {
|
|
328
|
+
const p = fieldProps(field)
|
|
329
|
+
if (typeof p.currency === 'string') return p.currency
|
|
330
|
+
return typeof p.currencyField === 'string' ? String(items.value[0]?.[p.currencyField] ?? 'EUR') : 'EUR'
|
|
331
|
+
}
|
|
332
|
+
|
|
313
333
|
function formatSummary(field: VectorField, value: number | null): string {
|
|
314
334
|
if (value === null) return t('common.none')
|
|
315
|
-
if (field.type === 'money')
|
|
316
|
-
const p = fieldProps(field)
|
|
317
|
-
return formatMoney(Math.round(value), typeof p.currency === 'string' ? p.currency : (typeof p.currencyField === 'string' ? String(items.value[0]?.[p.currencyField] ?? 'EUR') : 'EUR'))
|
|
318
|
-
}
|
|
335
|
+
if (field.type === 'money') return formatMoney(Math.round(value), summaryCurrency(field))
|
|
319
336
|
return formatNumber(value, field.summary === 'avg' ? 2 : undefined)
|
|
320
337
|
}
|
|
321
338
|
|
|
@@ -517,18 +534,17 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', warnBeforeUnloa
|
|
|
517
534
|
@update:model-value="(v: unknown) => setCell(item, field, v)"
|
|
518
535
|
/>
|
|
519
536
|
</div>
|
|
520
|
-
<
|
|
537
|
+
<button
|
|
521
538
|
v-else-if="field.inline && item._trashed !== true && resource.permissions.update"
|
|
539
|
+
type="button"
|
|
522
540
|
class="vx-inline-cell"
|
|
523
|
-
role="button"
|
|
524
|
-
tabindex="0"
|
|
525
541
|
:aria-label="t('list.inline.editLabel', { label: field.label })"
|
|
526
542
|
@click.stop="startEdit(item, field)"
|
|
527
543
|
@keydown.enter.stop.prevent="startEdit(item, field)"
|
|
528
544
|
>
|
|
529
545
|
<VxCell :field="field" :value="item[field.name]" :record="item" :resource="resource" context="index" />
|
|
530
546
|
<v-icon icon="mdi-pencil-outline" size="x-small" class="vx-inline-pencil" />
|
|
531
|
-
</
|
|
547
|
+
</button>
|
|
532
548
|
<span v-else :class="{ 'text-disabled': item._trashed === true }">
|
|
533
549
|
<VxCell :field="field" :value="item[field.name]" :record="item" :resource="resource" context="index" />
|
|
534
550
|
</span>
|
|
@@ -591,7 +607,7 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', warnBeforeUnloa
|
|
|
591
607
|
</template>
|
|
592
608
|
|
|
593
609
|
<style scoped>
|
|
594
|
-
.vx-inline-cell { display: inline-flex; align-items: center; gap: 4px; cursor: text; border-radius: 4px; padding: 2px 4px; margin: -2px -4px; }
|
|
610
|
+
.vx-inline-cell { display: inline-flex; align-items: center; gap: 4px; cursor: text; border-radius: 4px; padding: 2px 4px; margin: -2px -4px; border: 0; background: none; color: inherit; font: inherit; text-align: inherit; }
|
|
595
611
|
.vx-inline-cell:hover, .vx-inline-cell:focus-visible { outline: 1px dashed rgba(var(--v-theme-primary), 0.6); }
|
|
596
612
|
.vx-inline-pencil { opacity: 0; }
|
|
597
613
|
.vx-inline-cell:hover .vx-inline-pencil, .vx-inline-cell:focus-visible .vx-inline-pencil { opacity: 0.6; }
|
|
@@ -47,7 +47,8 @@ const builtIn: Record<string, Component> = {
|
|
|
47
47
|
|
|
48
48
|
const component = computed(() => {
|
|
49
49
|
const override = appConfig.vector.widgets[props.widget.type] ?? useVectorExtensions().widgets.get(props.widget.type)
|
|
50
|
-
|
|
50
|
+
if (!override) return builtIn[props.widget.type] ?? builtIn.stat!
|
|
51
|
+
return typeof override === 'string' ? resolveComponent(override) : override
|
|
51
52
|
})
|
|
52
53
|
</script>
|
|
53
54
|
|
|
@@ -6,6 +6,9 @@ const appConfig = useAppConfig()
|
|
|
6
6
|
const { t } = useVectorT()
|
|
7
7
|
const rows = computed(() => props.data.rows ?? [])
|
|
8
8
|
|
|
9
|
+
// a row with a link opens it, by mouse or by keyboard
|
|
10
|
+
const linked = (row: Record<string, unknown>) => typeof row._link === 'string'
|
|
11
|
+
|
|
9
12
|
function open(row: Record<string, unknown>) {
|
|
10
13
|
if (typeof row._link === 'string') navigateTo(`${appConfig.vector.basePath}${row._link}`)
|
|
11
14
|
}
|
|
@@ -15,10 +18,19 @@ function open(row: Record<string, unknown>) {
|
|
|
15
18
|
<div>
|
|
16
19
|
<v-table density="compact" hover>
|
|
17
20
|
<thead>
|
|
18
|
-
<tr><th v-for="col in data.columns ?? []" :key="col.key" :class="col.align === 'end' ? 'text-end' : ''">{{ col.label }}</th></tr>
|
|
21
|
+
<tr><th v-for="col in data.columns ?? []" :key="col.key" scope="col" :class="col.align === 'end' ? 'text-end' : ''">{{ col.label }}</th></tr>
|
|
19
22
|
</thead>
|
|
20
23
|
<tbody>
|
|
21
|
-
<tr
|
|
24
|
+
<tr
|
|
25
|
+
v-for="(row, i) in rows"
|
|
26
|
+
:key="i"
|
|
27
|
+
:style="linked(row) ? 'cursor: pointer' : ''"
|
|
28
|
+
:tabindex="linked(row) ? 0 : undefined"
|
|
29
|
+
:role="linked(row) ? 'link' : undefined"
|
|
30
|
+
@click="open(row)"
|
|
31
|
+
@keydown.enter.self.prevent="open(row)"
|
|
32
|
+
@keydown.space.self.prevent="open(row)"
|
|
33
|
+
>
|
|
22
34
|
<td v-for="col in data.columns ?? []" :key="col.key" :class="col.align === 'end' ? 'text-end' : ''">{{ row[col.key] }}</td>
|
|
23
35
|
</tr>
|
|
24
36
|
<tr v-if="rows.length === 0"><td :colspan="(data.columns ?? []).length" class="text-medium-emphasis">{{ t('dashboard.table.empty') }}</td></tr>
|
|
@@ -25,7 +25,7 @@ const hover = ref<number | null>(null)
|
|
|
25
25
|
<span v-if="data.total !== null && data.total !== undefined" class="font-weight-medium">{{ t('dashboard.trend.total', { value: formatWidgetValue(data.total, data.format) }) }}</span>
|
|
26
26
|
<span>{{ points[points.length - 1]?.x ?? '' }}</span>
|
|
27
27
|
</div>
|
|
28
|
-
<svg :viewBox="`0 0 ${width} ${height}`" preserveAspectRatio="none" class="w-100" style="height: 140px" @mouseleave="hover = null">
|
|
28
|
+
<svg aria-hidden="true" :viewBox="`0 0 ${width} ${height}`" preserveAspectRatio="none" class="w-100" style="height: 140px" @mouseleave="hover = null">
|
|
29
29
|
<path :d="area" fill="rgb(var(--v-theme-primary))" fill-opacity="0.12" />
|
|
30
30
|
<path :d="path" fill="none" stroke="rgb(var(--v-theme-primary))" stroke-width="2" vector-effect="non-scaling-stroke" />
|
|
31
31
|
<rect v-for="(p, i) in points" :key="p.x" :x="(i * (width / Math.max(1, points.length - 1))) - width / Math.max(1, points.length - 1) / 2" y="0" :width="width / Math.max(1, points.length - 1)" :height="height" fill="transparent" @mouseenter="hover = i" />
|
|
@@ -21,7 +21,7 @@ export function useVectorBranding() {
|
|
|
21
21
|
primaryColorDark: null,
|
|
22
22
|
theme: null,
|
|
23
23
|
footerText: null,
|
|
24
|
-
...(schema.value?.branding ?? hosted
|
|
24
|
+
...(schema.value?.branding ?? hosted),
|
|
25
25
|
}))
|
|
26
26
|
|
|
27
27
|
/** Pushes the colours into Vuetify's theme and picks the default theme once per session. */
|
|
@@ -38,7 +38,7 @@ export function useVectorPages() {
|
|
|
38
38
|
const { pages } = useVectorExtensions()
|
|
39
39
|
|
|
40
40
|
return computed<Record<string, VectorPageDefinition>>(() => ({
|
|
41
|
-
...
|
|
41
|
+
...appConfig.vector.pages,
|
|
42
42
|
...Object.fromEntries(pages.entries()),
|
|
43
43
|
}))
|
|
44
44
|
}
|
|
@@ -38,6 +38,12 @@ const cells: Record<string, Component> = {
|
|
|
38
38
|
manyToMany: defineAsyncComponent(() => import('#vector/app/components/Vx/Cell/Count.vue')),
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/** The cell type a computed field is shown as: what it is computed as, text as a string. */
|
|
42
|
+
function computedCell(field: VectorField): string {
|
|
43
|
+
const as = field.computed?.as
|
|
44
|
+
return as === 'text' ? 'string' : as ?? 'string'
|
|
45
|
+
}
|
|
46
|
+
|
|
41
47
|
export function useVectorFields() {
|
|
42
48
|
const appConfig = useAppConfig()
|
|
43
49
|
|
|
@@ -59,7 +65,7 @@ export function useVectorFields() {
|
|
|
59
65
|
}
|
|
60
66
|
|
|
61
67
|
// a computed value is shown by the cell of what it is computed as
|
|
62
|
-
const type = field.type === 'computed' ? (field
|
|
68
|
+
const type = field.type === 'computed' ? computedCell(field) : field.type
|
|
63
69
|
|
|
64
70
|
return cells[type] ?? cells.string!
|
|
65
71
|
}
|
|
@@ -26,7 +26,8 @@ export function applyViolations(error: unknown, values: Record<string, unknown>,
|
|
|
26
26
|
const key = String(violation.path[0] ?? '')
|
|
27
27
|
|
|
28
28
|
if (key && key in values) {
|
|
29
|
-
|
|
29
|
+
serverErrors[key] ??= []
|
|
30
|
+
serverErrors[key].push(`${violation.message.charAt(0).toUpperCase()}${violation.message.slice(1)}`)
|
|
30
31
|
} else {
|
|
31
32
|
general = violation.message
|
|
32
33
|
}
|
|
@@ -14,7 +14,9 @@ import { useEventListener, useIdle } from '@vueuse/core'
|
|
|
14
14
|
export function useVectorIdle(onIdle: () => void | Promise<void>): void {
|
|
15
15
|
const minutes = useAppConfig().vector.idleMinutes
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const enabled = minutes > 0
|
|
18
|
+
|
|
19
|
+
if (!import.meta.client || !enabled) return
|
|
18
20
|
|
|
19
21
|
const timeout = minutes * 60_000
|
|
20
22
|
const { idle, lastActive, reset } = useIdle(timeout, { listenForVisibilityChange: false })
|
|
@@ -49,17 +49,6 @@ export function useVectorImpersonation() {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
/** The `sub` of a JWT, read without verifying it: the server already did, and this only labels the session. */
|
|
53
|
-
function subjectOf(token: string): string | null {
|
|
54
|
-
try {
|
|
55
|
-
const payload = JSON.parse(atob(token.split('.')[1]?.replace(/-/g, '+').replace(/_/g, '/') ?? '')) as { sub?: unknown }
|
|
56
|
-
|
|
57
|
-
return typeof payload.sub === 'string' || typeof payload.sub === 'number' ? String(payload.sub) : null
|
|
58
|
-
} catch {
|
|
59
|
-
return null
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
52
|
async function start(userId: number | string) {
|
|
64
53
|
await apply(await api<Swap>(`/vector/impersonate/${encodeURIComponent(String(userId))}`, { method: 'POST' }))
|
|
65
54
|
}
|
|
@@ -76,3 +65,14 @@ export function useVectorImpersonation() {
|
|
|
76
65
|
|
|
77
66
|
return { impersonator, start, stop, refresh }
|
|
78
67
|
}
|
|
68
|
+
|
|
69
|
+
/** The `sub` of a JWT, read without verifying it: the server already did, and this only labels the session. */
|
|
70
|
+
function subjectOf(token: string): string | null {
|
|
71
|
+
try {
|
|
72
|
+
const payload = JSON.parse(atob(token.split('.')[1]?.replaceAll('-', '+').replaceAll('_', '/') ?? '')) as { sub?: unknown }
|
|
73
|
+
|
|
74
|
+
return typeof payload.sub === 'string' || typeof payload.sub === 'number' ? String(payload.sub) : null
|
|
75
|
+
} catch {
|
|
76
|
+
return null
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -32,6 +32,12 @@ const inputs: Record<string, Component> = {
|
|
|
32
32
|
hasMany: defineAsyncComponent(() => import('#vector/app/components/Vx/Input/Repeater.vue')),
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/** Whether a field is edited in this operation at all. */
|
|
36
|
+
function editable(field: VectorField, operation: 'create' | 'update'): boolean {
|
|
37
|
+
if (field.type === 'hasMany') return !!field.repeater && field.views.includes(operation)
|
|
38
|
+
return !field.readonly && field.views.includes(operation) && !['id', 'hasOne'].includes(field.type)
|
|
39
|
+
}
|
|
40
|
+
|
|
35
41
|
export function useVectorInputs() {
|
|
36
42
|
const appConfig = useAppConfig()
|
|
37
43
|
|
|
@@ -51,11 +57,5 @@ export function useVectorInputs() {
|
|
|
51
57
|
return overrides[field.type] ?? inputs[field.type] ?? inputs.string!
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
/** Whether a field is edited in this operation at all. */
|
|
55
|
-
function editable(field: VectorField, operation: 'create' | 'update'): boolean {
|
|
56
|
-
if (field.type === 'hasMany') return !!field.repeater && field.views.includes(operation)
|
|
57
|
-
return !field.readonly && field.views.includes(operation) && !['id', 'hasOne'].includes(field.type)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
60
|
return { inputFor, editable }
|
|
61
61
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { VectorLocale, VectorSchemaI18n } from '#vector/app/types/vector'
|
|
2
|
-
import { isRtl,
|
|
2
|
+
import { isRtl, knownVuetifyLocale, textDirection } from '#vector/app/i18n'
|
|
3
3
|
|
|
4
4
|
// The latest language the user picked: an earlier pick still in flight
|
|
5
5
|
// must not apply its answer over it. The UI runs in the browser only, one
|
|
@@ -25,15 +25,13 @@ export function useVectorLocale() {
|
|
|
25
25
|
|
|
26
26
|
const vuetify = nuxtApp.$vuetify as { locale?: { current: { value: string }, messages: { value: Record<string, unknown> } } } | undefined
|
|
27
27
|
if (vuetify?.locale) {
|
|
28
|
-
|
|
29
|
-
const known = vuetify.locale.messages.value
|
|
30
|
-
vuetify.locale.current.value = known[tag] ? tag : (known[code.split('-')[0]!] ? code.split('-')[0]! : 'en')
|
|
28
|
+
vuetify.locale.current.value = knownVuetifyLocale(code, vuetify.locale.messages.value)
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
if (import.meta.client) {
|
|
34
32
|
const known = locales.value.find(l => l.code === code)
|
|
35
33
|
document.documentElement.lang = code
|
|
36
|
-
document.documentElement.dir = known ? known.dir : (
|
|
34
|
+
document.documentElement.dir = known ? known.dir : textDirection(code)
|
|
37
35
|
try {
|
|
38
36
|
window.localStorage.setItem('vector.locale', code)
|
|
39
37
|
} catch {
|
|
@@ -38,46 +38,47 @@ export function filterQuery(filter: VectorFilterQuery | undefined, prefix = 'fil
|
|
|
38
38
|
return query
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
/** The
|
|
42
|
-
|
|
43
|
-
const
|
|
41
|
+
/** The query string of a list request. */
|
|
42
|
+
function listQuery(options: VectorListOptions): Record<string, string | number> {
|
|
43
|
+
const query: Record<string, string | number> = {}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (options.page) {
|
|
46
|
+
query.page = options.page
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (options.perPage) {
|
|
50
|
+
query.perPage = options.perPage
|
|
51
|
+
}
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
if (options.sort && options.sort.length > 0) {
|
|
54
|
+
query.sort = options.sort.map(s => (s.order === 'desc' ? '-' : '') + s.field).join(',')
|
|
55
|
+
}
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
if (options.q) {
|
|
58
|
+
query.q = options.q
|
|
59
|
+
}
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
if (options.group) {
|
|
62
|
+
query.group = options.group
|
|
63
|
+
}
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
if (options.summaries) {
|
|
66
|
+
query.summaries = '1'
|
|
67
|
+
}
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
if (options.columns && options.columns.length > 0) {
|
|
70
|
+
query.columns = options.columns.join(',')
|
|
71
|
+
}
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
73
|
+
return { ...query, ...filterQuery(options.filter) }
|
|
74
|
+
}
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
/** The record endpoints for one resource. */
|
|
77
|
+
export function useVectorResource(slug: MaybeRefOrGetter<string>) {
|
|
78
|
+
const api = useVectorApi()
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
function base() {
|
|
81
|
+
return `/vector/r/${encodeURIComponent(toValue(slug))}`
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
function list(options: VectorListOptions = {}): Promise<VectorPage> {
|
|
@@ -174,7 +175,7 @@ export function useVectorResource(slug: MaybeRefOrGetter<string>) {
|
|
|
174
175
|
try {
|
|
175
176
|
response = await asFile(() => api.raw(`${base()}/actions/${encodeURIComponent(name)}`, {
|
|
176
177
|
method: 'POST',
|
|
177
|
-
body: { ...
|
|
178
|
+
body: { ...selection, fields },
|
|
178
179
|
responseType: 'blob',
|
|
179
180
|
}))
|
|
180
181
|
} catch (error) {
|
package/app/i18n/index.ts
CHANGED
|
@@ -38,6 +38,19 @@ export function vuetifyLocale(tag: string): string {
|
|
|
38
38
|
return tag.replace(/-([a-z])/gi, (_, c: string) => c.toUpperCase())
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/** The Vuetify locale a tag switches to, of those `known`: its own, else its language's, else English. */
|
|
42
|
+
export function knownVuetifyLocale(tag: string, known: Record<string, unknown>): string {
|
|
43
|
+
const own = vuetifyLocale(tag)
|
|
44
|
+
if (known[own]) return own
|
|
45
|
+
const language = tag.split('-')[0]!
|
|
46
|
+
return known[language] ? language : 'en'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The direction a language tag is written in. */
|
|
50
|
+
export function textDirection(tag: string): 'ltr' | 'rtl' {
|
|
51
|
+
return isRtl(tag) ? 'rtl' : 'ltr'
|
|
52
|
+
}
|
|
53
|
+
|
|
41
54
|
/**
|
|
42
55
|
* A language's name in the viewer's language (`de` shown in English is
|
|
43
56
|
* "German", in Hebrew "גרמנית"), from the browser's own CLDR data: a
|
|
@@ -103,7 +116,8 @@ export function pluralRule(locale: string): (choice: number, choicesLength: numb
|
|
|
103
116
|
category = 'other'
|
|
104
117
|
}
|
|
105
118
|
const index = forms.indexOf(category)
|
|
106
|
-
|
|
119
|
+
if (index >= 0) return index
|
|
120
|
+
return forms.includes('other') ? forms.indexOf('other') : choicesLength - 1
|
|
107
121
|
}
|
|
108
122
|
if (choicesLength === 2) return Math.abs(choice) === 1 ? 0 : 1
|
|
109
123
|
return Math.min(Math.max(choicesLength - 1, 0), Math.abs(choice) === 1 ? 0 : choicesLength - 1)
|
package/app/pages/jobs/index.vue
CHANGED
|
@@ -14,6 +14,10 @@ onUnmounted(pause)
|
|
|
14
14
|
|
|
15
15
|
useHead({ title: () => t('jobs.title') })
|
|
16
16
|
|
|
17
|
+
function open(job: VectorJob) {
|
|
18
|
+
navigateTo(`${appConfig.vector.basePath}/jobs/${job.id}`)
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
const color: Record<VectorJob['status'], string> = { queued: 'grey', running: 'info', done: 'success', failed: 'error', stalled: 'warning' }
|
|
18
22
|
</script>
|
|
19
23
|
|
|
@@ -23,10 +27,19 @@ const color: Record<VectorJob['status'], string> = { queued: 'grey', running: 'i
|
|
|
23
27
|
<v-card>
|
|
24
28
|
<v-table hover>
|
|
25
29
|
<thead>
|
|
26
|
-
<tr><th>{{ t('jobs.columns.job') }}</th><th>{{ t('jobs.columns.resource') }}</th><th>{{ t('jobs.columns.status') }}</th><th class="text-end">{{ t('jobs.columns.progress') }}</th><th>{{ t('jobs.columns.started') }}</th><th /></tr>
|
|
30
|
+
<tr><th scope="col">{{ t('jobs.columns.job') }}</th><th scope="col">{{ t('jobs.columns.resource') }}</th><th scope="col">{{ t('jobs.columns.status') }}</th><th scope="col" class="text-end">{{ t('jobs.columns.progress') }}</th><th scope="col">{{ t('jobs.columns.started') }}</th><th scope="col" /></tr>
|
|
27
31
|
</thead>
|
|
28
32
|
<tbody>
|
|
29
|
-
<tr
|
|
33
|
+
<tr
|
|
34
|
+
v-for="job in data ?? []"
|
|
35
|
+
:key="job.id"
|
|
36
|
+
style="cursor: pointer"
|
|
37
|
+
tabindex="0"
|
|
38
|
+
role="link"
|
|
39
|
+
@click="open(job)"
|
|
40
|
+
@keydown.enter.self.prevent="open(job)"
|
|
41
|
+
@keydown.space.self.prevent="open(job)"
|
|
42
|
+
>
|
|
30
43
|
<td><span class="text-capitalize">{{ t(`jobs.kind.${job.kind}`) }}</span> <span class="text-medium-emphasis">{{ job.name }}</span></td>
|
|
31
44
|
<td>{{ job.resource }}</td>
|
|
32
45
|
<td><v-chip size="small" :color="color[job.status]" variant="tonal">{{ t(`jobs.status.${job.status}`) }}</v-chip></td>
|
package/app/pages/login.vue
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { SubmitEventPromise } from 'vuetify'
|
|
3
|
+
import { hasEmailShape } from '#vector/app/utils/internal/patterns'
|
|
3
4
|
|
|
4
5
|
definePageMeta({ layout: 'default' })
|
|
5
6
|
|
|
@@ -18,7 +19,7 @@ const notice = computed(() => route.query.reason === 'idle' ? t('shell.login.sig
|
|
|
18
19
|
|
|
19
20
|
const rules = {
|
|
20
21
|
required: (value: string) => value.trim() !== '' || t('common.required'),
|
|
21
|
-
email: (value: string) =>
|
|
22
|
+
email: (value: string) => hasEmailShape(value) || t('shell.login.invalidEmail'),
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
const runtime = useVectorRuntime()
|
|
@@ -56,7 +56,7 @@ export default defineNuxtPlugin(() => {
|
|
|
56
56
|
|
|
57
57
|
const urls = [...(window.__VECTOR__?.extensions ?? []), ...((config.public.vector as { extensions?: string[] }).extensions ?? [])]
|
|
58
58
|
|
|
59
|
-
Promise.allSettled(urls.map(url => import(/* @vite-ignore */ url)
|
|
59
|
+
void Promise.allSettled(urls.map(url => import(/* @vite-ignore */ url)
|
|
60
60
|
.then(module => (typeof module.default === 'function' ? module.default(api) : undefined))
|
|
61
61
|
.catch(error => console.error(`Vector extension ${url} failed to load`, error))))
|
|
62
62
|
.then(() => { registries.ready.value = true })
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createI18n } from 'vue-i18n'
|
|
2
2
|
import type { VectorI18n } from '#vector/app/utils/translate'
|
|
3
|
-
import { bundledMessages, isRtl, pluralRule, rtlLanguages
|
|
3
|
+
import { bundledMessages, isRtl, knownVuetifyLocale, pluralRule, rtlLanguages } from '#vector/app/i18n'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The admin's own strings, translated through vue-i18n, in the language
|
|
@@ -61,7 +61,7 @@ export default defineNuxtPlugin({
|
|
|
61
61
|
nuxtApp.hook('vuetify:before-create', async ({ vuetifyOptions }) => {
|
|
62
62
|
const all = await import('vuetify/locale') as Record<string, unknown>
|
|
63
63
|
const messages = Object.fromEntries(Object.entries(all).filter(([, value]) => value && typeof value === 'object' && !Array.isArray(value)))
|
|
64
|
-
const current =
|
|
64
|
+
const current = knownVuetifyLocale(locale, messages)
|
|
65
65
|
vuetifyOptions.locale = {
|
|
66
66
|
...(typeof vuetifyOptions.locale === 'object' ? vuetifyOptions.locale : {}),
|
|
67
67
|
locale: current,
|
package/app/utils/files.ts
CHANGED
|
@@ -7,8 +7,11 @@
|
|
|
7
7
|
export function dataUrl(blob: Blob): Promise<string> {
|
|
8
8
|
return new Promise((resolve, reject) => {
|
|
9
9
|
const reader = new FileReader()
|
|
10
|
-
reader.onload = () =>
|
|
11
|
-
|
|
10
|
+
reader.onload = () => {
|
|
11
|
+
if (typeof reader.result === 'string') resolve(reader.result)
|
|
12
|
+
else reject(new Error('The file was not read as a data URL'))
|
|
13
|
+
}
|
|
14
|
+
reader.onerror = () => reject(reader.error ?? new Error('The file could not be read'))
|
|
12
15
|
reader.readAsDataURL(blob)
|
|
13
16
|
})
|
|
14
17
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Linear-time scans the form rules use in place of backtracking regular
|
|
2
|
+
// expressions. Nested under utils/ so Nuxt does not auto-import them:
|
|
3
|
+
// they are not part of the layer's public API.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An e-mail address as the Email rule takes it: no whitespace, one `@`
|
|
7
|
+
* with text before it, and a domain with a dot that has text on both
|
|
8
|
+
* sides. Scanned, not matched, so a long input costs linear time.
|
|
9
|
+
*/
|
|
10
|
+
export function isEmailAddress(value: string): boolean {
|
|
11
|
+
if (/\s/.test(value)) return false
|
|
12
|
+
|
|
13
|
+
const at = value.indexOf('@')
|
|
14
|
+
|
|
15
|
+
if (at < 1 || value.includes('@', at + 1)) return false
|
|
16
|
+
|
|
17
|
+
const domain = value.slice(at + 1)
|
|
18
|
+
|
|
19
|
+
return domain.lastIndexOf('.', domain.length - 2) >= 1
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The sign-in form's looser check: somewhere on one line, text, an `@`,
|
|
24
|
+
* text, a dot and text again.
|
|
25
|
+
*/
|
|
26
|
+
export function hasEmailShape(value: string): boolean {
|
|
27
|
+
return value.split(/[\n\r\u2028\u2029]/).some((line) => {
|
|
28
|
+
const at = line.indexOf('@', 1)
|
|
29
|
+
|
|
30
|
+
return at !== -1 && line.lastIndexOf('.', line.length - 2) >= at + 2
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A PCRE pattern with its delimiters and flags, as the framework's Regex
|
|
36
|
+
* constraint takes it, as a JavaScript RegExp: the first character is the
|
|
37
|
+
* delimiter, its last occurrence closes the pattern, and only letters may
|
|
38
|
+
* follow it. Anything else is taken as a bare pattern.
|
|
39
|
+
*/
|
|
40
|
+
export function phpRegex(pattern: string): RegExp {
|
|
41
|
+
const delimiter = pattern.charAt(0)
|
|
42
|
+
const end = pattern.lastIndexOf(delimiter)
|
|
43
|
+
const modifiers = pattern.slice(end + 1)
|
|
44
|
+
|
|
45
|
+
if (end < 1 || '\n\r\u2028\u2029'.includes(delimiter) || !/^[a-zA-Z]*$/.test(modifiers)) return new RegExp(pattern)
|
|
46
|
+
|
|
47
|
+
const flags = [...modifiers].filter(f => 'gimsuy'.includes(f)).join('')
|
|
48
|
+
|
|
49
|
+
return new RegExp(pattern.slice(1, end), flags)
|
|
50
|
+
}
|
package/app/utils/richtext.ts
CHANGED
|
@@ -108,7 +108,7 @@ function vectorImage(imageSource?: (key: string) => Promise<string | null>): Any
|
|
|
108
108
|
return ['img', { ...rest, 'data-vector-key': src }]
|
|
109
109
|
},
|
|
110
110
|
parseHTML() {
|
|
111
|
-
return [{ tag: 'img[src]' }, { tag: 'img[data-vector-key]', getAttrs: element => ({ src: (element as HTMLElement).
|
|
111
|
+
return [{ tag: 'img[src]' }, { tag: 'img[data-vector-key]', getAttrs: element => ({ src: (element as HTMLElement).dataset.vectorKey ?? null }) }]
|
|
112
112
|
},
|
|
113
113
|
addNodeView() {
|
|
114
114
|
return ({ node }) => {
|
|
@@ -116,7 +116,7 @@ function vectorImage(imageSource?: (key: string) => Promise<string | null>): Any
|
|
|
116
116
|
img.alt = String(node.attrs.alt ?? '')
|
|
117
117
|
img.className = 'vx-richtext-image'
|
|
118
118
|
const key = String(node.attrs.src ?? '')
|
|
119
|
-
img.
|
|
119
|
+
img.dataset.vectorKey = key
|
|
120
120
|
imageSource?.(key).then((url) => {
|
|
121
121
|
if (url) img.src = url
|
|
122
122
|
}).catch(() => undefined)
|
package/app/utils/rules.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { VectorCondition, VectorField, VectorFieldState, VectorRule } from '#vector/app/types/vector'
|
|
2
|
+
import { isEmailAddress, phpRegex } from '#vector/app/utils/internal/patterns'
|
|
2
3
|
|
|
3
4
|
type Rule = (value: unknown) => true | string
|
|
4
5
|
|
|
@@ -41,7 +42,7 @@ function compile(rule: VectorRule): Rule | null {
|
|
|
41
42
|
case 'MinLength':
|
|
42
43
|
return value => empty(value) || typeof value !== 'string' || [...value].length >= Number(a) || vt('fields.rules.minLength', { min: String(a) })
|
|
43
44
|
case 'Email':
|
|
44
|
-
return value => empty(value) || (typeof value === 'string' &&
|
|
45
|
+
return value => empty(value) || (typeof value === 'string' && isEmailAddress(value)) || vt('fields.rules.email')
|
|
45
46
|
case 'Url':
|
|
46
47
|
case 'WebUrl':
|
|
47
48
|
return value => empty(value) || (typeof value === 'string' && /^https?:\/\/\S+$/i.test(value)) || vt('fields.rules.url')
|
|
@@ -62,17 +63,6 @@ function compile(rule: VectorRule): Rule | null {
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
/** A PCRE pattern with its delimiters and flags, as the framework's Regex constraint takes it, as a JavaScript RegExp. */
|
|
66
|
-
function phpRegex(pattern: string): RegExp {
|
|
67
|
-
const match = pattern.match(/^(.)([\s\S]*)\1([a-zA-Z]*)$/)
|
|
68
|
-
|
|
69
|
-
if (!match) return new RegExp(pattern)
|
|
70
|
-
|
|
71
|
-
const flags = [...match[3]!].filter(f => 'gimsuy'.includes(f)).join('')
|
|
72
|
-
|
|
73
|
-
return new RegExp(match[2]!, flags)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
66
|
/**
|
|
77
67
|
* What a field's conditions decide under the form's current values: the
|
|
78
68
|
* server evaluates the same conditions the same way, comparing a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kinetis/vector-ui",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "The Kinetis Vector admin UI, as a Nuxt layer on Vuetify.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kinetis",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@vueuse/core": "^15.0.0",
|
|
58
58
|
"@vueuse/nuxt": "^15.0.0",
|
|
59
59
|
"dompurify": "^3.4.17",
|
|
60
|
-
"markdown-it": "^15.0.
|
|
60
|
+
"markdown-it": "^15.0.3",
|
|
61
61
|
"pinia": "^4.1.0",
|
|
62
62
|
"vue-i18n": "^11.4.14"
|
|
63
63
|
},
|