@kinetis/vector-ui 0.10.1 → 0.10.3

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/app/components/Vx/Action/Dialog.vue +15 -9
  3. package/app/components/Vx/Cell/RichText.vue +1 -1
  4. package/app/components/Vx/Import/Dialog.vue +14 -3
  5. package/app/components/Vx/Inbox.vue +10 -3
  6. package/app/components/Vx/Input/KeyValue.vue +9 -4
  7. package/app/components/Vx/Input/Number.vue +2 -1
  8. package/app/components/Vx/Input/Relation.vue +15 -5
  9. package/app/components/Vx/Input/Repeater.vue +15 -5
  10. package/app/components/Vx/Input/RichText.vue +2 -2
  11. package/app/components/Vx/Input/Upload.vue +5 -3
  12. package/app/components/Vx/List/BulkEdit.vue +5 -5
  13. package/app/components/Vx/List/FilterBar.vue +14 -10
  14. package/app/components/Vx/Resource/Audit.vue +4 -1
  15. package/app/components/Vx/Resource/Form.vue +23 -8
  16. package/app/components/Vx/Resource/RelationPanel.vue +2 -1
  17. package/app/components/Vx/Resource/Table.vue +32 -15
  18. package/app/components/Vx/Widget/Card.vue +2 -1
  19. package/app/components/Vx/Widget/Table.vue +22 -4
  20. package/app/components/Vx/Widget/Trend.vue +1 -1
  21. package/app/composables/useVectorApi.ts +70 -14
  22. package/app/composables/useVectorAuthStore.ts +32 -7
  23. package/app/composables/useVectorBranding.ts +1 -1
  24. package/app/composables/useVectorExtensions.ts +1 -1
  25. package/app/composables/useVectorFields.ts +7 -1
  26. package/app/composables/useVectorForm.ts +8 -3
  27. package/app/composables/useVectorIdle.ts +3 -1
  28. package/app/composables/useVectorImpersonation.ts +11 -11
  29. package/app/composables/useVectorInputs.ts +6 -6
  30. package/app/composables/useVectorJobs.ts +6 -3
  31. package/app/composables/useVectorLocale.ts +3 -5
  32. package/app/composables/useVectorResource.ts +37 -32
  33. package/app/composables/useVectorSchema.ts +9 -1
  34. package/app/i18n/ar/actions.ts +1 -0
  35. package/app/i18n/ar/shell.ts +3 -0
  36. package/app/i18n/de/actions.ts +1 -0
  37. package/app/i18n/de/shell.ts +3 -0
  38. package/app/i18n/en/actions.ts +1 -0
  39. package/app/i18n/en/shell.ts +3 -0
  40. package/app/i18n/es/actions.ts +1 -0
  41. package/app/i18n/es/shell.ts +3 -0
  42. package/app/i18n/fr/actions.ts +1 -0
  43. package/app/i18n/fr/shell.ts +3 -0
  44. package/app/i18n/he/actions.ts +1 -0
  45. package/app/i18n/he/shell.ts +3 -0
  46. package/app/i18n/index.ts +15 -1
  47. package/app/i18n/it/actions.ts +1 -0
  48. package/app/i18n/it/shell.ts +3 -0
  49. package/app/i18n/ja/actions.ts +1 -0
  50. package/app/i18n/ja/shell.ts +3 -0
  51. package/app/i18n/ko/actions.ts +1 -0
  52. package/app/i18n/ko/shell.ts +3 -0
  53. package/app/i18n/nl/actions.ts +1 -0
  54. package/app/i18n/nl/shell.ts +3 -0
  55. package/app/i18n/pl/actions.ts +1 -0
  56. package/app/i18n/pl/shell.ts +3 -0
  57. package/app/i18n/pt/actions.ts +1 -0
  58. package/app/i18n/pt/shell.ts +3 -0
  59. package/app/i18n/pt-BR/actions.ts +1 -0
  60. package/app/i18n/pt-BR/shell.ts +3 -0
  61. package/app/i18n/ru/actions.ts +1 -0
  62. package/app/i18n/ru/shell.ts +3 -0
  63. package/app/i18n/tr/actions.ts +1 -0
  64. package/app/i18n/tr/shell.ts +3 -0
  65. package/app/i18n/uk/actions.ts +1 -0
  66. package/app/i18n/uk/shell.ts +3 -0
  67. package/app/i18n/zh-Hans/actions.ts +1 -0
  68. package/app/i18n/zh-Hans/shell.ts +3 -0
  69. package/app/pages/jobs/index.vue +18 -4
  70. package/app/pages/login.vue +11 -4
  71. package/app/pages/settings.vue +4 -3
  72. package/app/plugins/vector-extensions.client.ts +1 -1
  73. package/app/plugins/vector-i18n.ts +2 -2
  74. package/app/utils/files.ts +5 -2
  75. package/app/utils/internal/paths.ts +12 -0
  76. package/app/utils/internal/patterns.ts +50 -0
  77. package/app/utils/internal/violations.ts +26 -0
  78. package/app/utils/richtext.ts +2 -2
  79. package/app/utils/rules.ts +2 -12
  80. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,94 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.10.3] - 2026-10-22
11
+
12
+ ### Changed
13
+
14
+ - The file and image inputs, and a rich-text field's image upload, send
15
+ the id of the record they edit in the upload's multipart `record`
16
+ part, which kinetis/vector now requires to upload while editing
17
+ without create permission. `useVectorResource().upload()` takes it as
18
+ an optional argument.
19
+
20
+ ### Fixed
21
+
22
+ - A 401 while impersonating in bearer mode ends the impersonation in the
23
+ signed-in user's own session, renewed with their refresh token, and
24
+ says so, instead of discarding that session and sending them to sign
25
+ in; when it cannot be renewed, the login page says the impersonation
26
+ ran out. The impersonation's expiry no longer forgets the signer's
27
+ refresh token, and a request refused for the impersonation token is
28
+ never repeated as the signer.
29
+ - The jobs list and the settings page say why when they fail to load,
30
+ as the record page does, instead of showing no jobs or "no settings".
31
+ - Several requests refused (401) together, whose shared renewal of the
32
+ session fails, sign the user out once: one trip to the login page
33
+ instead of one per request.
34
+ - The admin refuses a descriptor whose `version` is not the contract it
35
+ reads (4), naming both versions, instead of rendering it as if it were.
36
+ - Following a job no longer adds a listener to the page's abort signal on
37
+ every poll without removing it; a long job's page held one per poll.
38
+ - A request refused (401) for an access token another request has
39
+ already renewed is repeated with the new token instead of renewing the
40
+ session a second time, which spent the new refresh token and could end
41
+ a session that was still good.
42
+ - A relation input whose search fails says why under the input and keeps
43
+ the choices it listed, instead of failing silently with an unhandled
44
+ promise rejection.
45
+ - Opening a notification whose mark-as-read fails says why, instead of
46
+ failing silently with an unhandled promise rejection.
47
+ - A problem+json error without a `detail` shows its `title` instead of
48
+ the request's generic failure message.
49
+ - An entry of a 422 document's `errors` that is not a violation (no
50
+ `path` list of names and indexes, or no `message` text) is ignored by
51
+ the forms, the settings, bulk edit, action dialogs, inline list edits
52
+ and uploads, instead of being read as one: a `null` entry made a form
53
+ or the list's changeset fail without showing anything.
54
+ - A record form shows a server error on a field it does not show — hidden
55
+ by `visibleWhen`, or preset by the relation the form was opened from —
56
+ above the form, under the field's label; it was shown nowhere, and the
57
+ save failed without a reason.
58
+
59
+ ### Security
60
+
61
+ - An action answering `ActionResponse::openUrl()` opens the URL only
62
+ when it is http(s), mailto or relative — the rule a URL cell and a
63
+ rich-text link follow. A `javascript:` or `data:` URL, which an action
64
+ echoing a record's value could return, is no longer opened.
65
+ - A notification's link is followed only when it is a path of the
66
+ admin, the rule the sign-in page's `redirect` follows; `//host`,
67
+ `/\host` and a URL with a scheme are not.
68
+ - The sign-in page's `redirect`, and a notification's link, are refused
69
+ when they hold a backslash, whitespace or a control character anywhere:
70
+ a browser strips tab, CR and LF from a URL, so `/<tab>/host` was
71
+ followed as `//host`, another origin.
72
+ - A dashboard table widget's row opens its `_link` only when it is a path
73
+ of the admin, by the same rule, and a row whose link is not is not
74
+ offered as a link; a failed navigation is reported instead of
75
+ rejecting unhandled.
76
+ - An action answering `ActionResponse::redirect()` is followed only when
77
+ its URL is a path of the admin, checked before the dialog reports the
78
+ action done; any other URL, or none, is reported and not followed.
79
+
80
+ ## [0.10.2] - 2026-10-21
81
+
82
+ ### Fixed
83
+
84
+ - A row of the jobs list, and a linked row of a dashboard table widget,
85
+ takes keyboard focus and opens with Enter or Space, as a click opens
86
+ it.
87
+ - An inline-editable list cell is a button, so Space starts editing it
88
+ as Enter does.
89
+ - Table column headers are marked as column headers; a trend widget's
90
+ sparkline is hidden from screen readers, which read its range and total
91
+ beside it; the rich text editor's image picker is labelled.
92
+ - A key-value input, a repeater's rows and the filter bar's "any of"
93
+ groups are fieldsets, with the accessible names they had.
94
+ - The Email rule, the sign-in form's e-mail check and the Regex rule's
95
+ delimiter parsing run in linear time, accepting exactly what they
96
+ accepted before.
97
+
10
98
  ## [0.10.1] - 2026-10-21
11
99
 
12
100
  ### Security
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import type { SubmitEventPromise } from 'vuetify'
3
3
  import type { VectorAction, VectorResource, VectorSelection } from '#vector/app/types/vector'
4
+ import { isAdminPath } from '#vector/app/utils/internal/paths'
4
5
 
5
6
  // Runs one action: the confirmation, the dialog's fields, the request,
6
7
  // and what the response asks the client to do.
@@ -28,13 +29,12 @@ for (const field of props.action.fields) {
28
29
  values[field.name] = initialValue(field)
29
30
  }
30
31
 
31
- const subject = computed(() => props.action.standalone
32
- ? ''
33
- : props.selection?.all
34
- ? props.count === null
35
- ? t('actions.subjectAllUncounted', { label: noun(props.resource.labelSingular) })
36
- : t('actions.subjectAll', { label: noun(props.resource.labelSingular), count: props.count })
37
- : t('actions.subjectCount', { count: props.count, label: noun(props.count === 1 ? props.resource.labelSingular : props.resource.label) }))
32
+ const subject = computed(() => {
33
+ if (props.action.standalone) return ''
34
+ if (!props.selection?.all) return t('actions.subjectCount', { count: props.count, label: noun(props.count === 1 ? props.resource.labelSingular : props.resource.label) })
35
+ if (props.count === null) return t('actions.subjectAllUncounted', { label: noun(props.resource.labelSingular) })
36
+ return t('actions.subjectAll', { label: noun(props.resource.labelSingular), count: props.count })
37
+ })
38
38
 
39
39
  async function run(event: SubmitEventPromise) {
40
40
  const { valid } = await event
@@ -56,12 +56,18 @@ async function run(event: SubmitEventPromise) {
56
56
  return
57
57
  case 'redirect':
58
58
  if (response.message) notifications.success(response.message)
59
+ // only a path of this admin, as a notification's link, checked before the dialog is done
60
+ if (!response.url || !isAdminPath(response.url)) {
61
+ notifications.error(t('actions.redirectRefused'))
62
+ break
63
+ }
59
64
  emit('done', response.affected)
60
- await navigateTo(`${appConfig.vector.basePath}${response.url ?? ''}`)
65
+ await navigateTo(`${appConfig.vector.basePath}${response.url}`)
61
66
  return
62
67
  case 'url':
63
68
  if (response.message) notifications.success(response.message)
64
- if (response.url && import.meta.client) window.open(response.url, '_blank', 'noopener')
69
+ // only where a link could go, as a URL cell: an action may echo a record's value
70
+ if (response.url && allowedHref(response.url) && import.meta.client) window.open(response.url, '_blank', 'noopener')
65
71
  break
66
72
  case 'download':
67
73
  notifications.success(t('actions.downloadStarted'))
@@ -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.getAttribute('data-vector-key')!
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(m => m === 'create' ? props.resource.permissions.create : m === 'update' ? props.resource.permissions.update : props.resource.permissions.create && props.resource.permissions.update)
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 = mode.value === 'create' ? ['create'] : mode.value === 'update' ? ['update'] : ['create', 'update']
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>
@@ -1,4 +1,6 @@
1
1
  <script setup lang="ts">
2
+ import { isAdminPath } from '#vector/app/utils/internal/paths'
3
+
2
4
  // The bell: unread count polled every 30 seconds, the latest messages in a menu.
3
5
  const appConfig = useAppConfig()
4
6
  const inbox = useVectorNotificationsInbox()
@@ -10,10 +12,15 @@ const { pause } = useIntervalFn(() => inbox.refresh().catch(() => undefined), 30
10
12
  onUnmounted(pause)
11
13
  watch(open, o => { if (o) inbox.refresh().catch(() => undefined) })
12
14
 
15
+ // A link is a path of this admin: `//host`, `/\host`, `/\t/host` and anything with a scheme are not followed, as the login redirect.
13
16
  async function go(id: number, link: string | null) {
14
- await inbox.markRead(id)
15
- open.value = false
16
- if (link) navigateTo(`${appConfig.vector.basePath}${link}`)
17
+ try {
18
+ await inbox.markRead(id)
19
+ open.value = false
20
+ if (link && isAdminPath(link)) await navigateTo(`${appConfig.vector.basePath}${link}`)
21
+ } catch (error) {
22
+ useVectorNotifications().error(vectorErrorMessage(error))
23
+ }
17
24
  }
18
25
  </script>
19
26
 
@@ -50,9 +50,9 @@ const messages = computed(() => [...(repeated.value.length ? [t('fields.keyValue
50
50
  </script>
51
51
 
52
52
  <template>
53
- <div role="group" :aria-label="field.label">
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
- <div v-for="(row, index) in rows" :key="index" class="d-flex ga-2 align-start mb-1" role="group" :aria-label="t('fields.keyValue.entry', { n: index + 1 })">
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
- </div>
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
- </div>
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
- return typeof d === 'number' ? d : (props.field.valueType === 'float' ? 2 : 0)
8
+ if (typeof d === 'number') return d
9
+ return props.field.valueType === 'float' ? 2 : 0
9
10
  })
10
11
  </script>
11
12
 
@@ -29,6 +29,8 @@ function loadThumbs(options: VectorRelationValue[]) {
29
29
 
30
30
  const search = ref('')
31
31
  const loading = ref(false)
32
+ /** Why the last search found nothing to show: the choices already listed stay. */
33
+ const loadError = ref<string | null>(null)
32
34
  let requestId = 0
33
35
 
34
36
  const dependsOn = computed(() => props.field.relation?.dependsOn ?? null)
@@ -36,7 +38,8 @@ const dependency = computed<string | number | null>(() => {
36
38
  if (!dependsOn.value) return null
37
39
  const value = props.record?.[dependsOn.value.field]
38
40
  const key = value && typeof value === 'object' && 'id' in value ? (value as { id: unknown }).id : value
39
- return typeof key === 'number' || (typeof key === 'string' && key !== '') ? key : typeof key === 'boolean' ? Number(key) : null
41
+ if (typeof key === 'number' || (typeof key === 'string' && key !== '')) return key
42
+ return typeof key === 'boolean' ? Number(key) : null
40
43
  })
41
44
  const waiting = computed(() => dependsOn.value !== null && dependency.value === null)
42
45
 
@@ -56,7 +59,10 @@ async function fetchOptions(query: string, ids: (number | string)[] = []) {
56
59
  const merged = [...selected, ...result.data.filter(r => !selected.some(s => s.id === r.id))]
57
60
  items.value = merged
58
61
  loadThumbs(result.data)
62
+ loadError.value = null
59
63
  }
64
+ } catch (error) {
65
+ if (id === requestId) loadError.value = vectorErrorMessage(error)
60
66
  } finally {
61
67
  if (id === requestId) loading.value = false
62
68
  }
@@ -77,11 +83,15 @@ watch(dependency, (now, before) => {
77
83
  fetchOptions('')
78
84
  })
79
85
 
86
+ /** The identifiers the input starts with. */
87
+ function initialIds(): (number | string)[] {
88
+ if (multiple.value) return Array.isArray(model.value) ? model.value : []
89
+ return model.value === null || model.value === undefined || Array.isArray(model.value) ? [] : [model.value]
90
+ }
91
+
80
92
  // Resolve the labels of an initial value once.
81
93
  onMounted(async () => {
82
- const initial: (number | string)[] = multiple.value
83
- ? (Array.isArray(model.value) ? model.value : [])
84
- : (model.value === null || model.value === undefined || Array.isArray(model.value) ? [] : [model.value])
94
+ const initial = initialIds()
85
95
  await fetchOptions('', initial.length ? initial : [])
86
96
  if (initial.length) await fetchOptions('')
87
97
  })
@@ -100,7 +110,7 @@ onMounted(async () => {
100
110
  :closable-chips="multiple"
101
111
  :loading="loading"
102
112
  :rules="rules"
103
- :error-messages="errorMessages"
113
+ :error-messages="loadError ? [...errorMessages, loadError] : errorMessages"
104
114
  :clearable="field.nullable === true || multiple"
105
115
  :disabled="disabled || waiting"
106
116
  no-filter
@@ -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.hasDefault ? f.default : f.type === 'boolean' ? false : null]))
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
- <div
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
- </div>
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>
@@ -91,7 +91,7 @@ async function insertImage(event: Event) {
91
91
  uploading.value = true
92
92
  uploadError.value = null
93
93
  try {
94
- const { key } = await client.upload(rich.value.imageField, file)
94
+ const { key } = await client.upload(rich.value.imageField, file, props.record?.id as string | number | undefined)
95
95
  uploaded.set(key, await dataUrl(file))
96
96
  run(e => e.chain().focus().setImage({ src: key, alt: file.name }).run())
97
97
  } catch (error) {
@@ -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())" />
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import type { VectorField, VectorUploaded } from '#vector/app/types/vector'
3
+ import { violationsOf } from '#vector/app/utils/internal/violations'
3
4
 
4
5
  // A file or image field: pick a file, it uploads at once, and the field
5
6
  // takes the key the server issued. The server detects the format from the
@@ -39,12 +40,13 @@ async function choose(files: File | File[] | null) {
39
40
 
40
41
  uploading.value = true
41
42
  try {
42
- picked.value = await client.upload(props.field.name, file)
43
+ picked.value = await client.upload(props.field.name, file, props.record?.id as string | number | undefined)
43
44
  model.value = picked.value.key
44
45
  preview.value = image.value ? await dataUrl(file) : null
45
46
  } catch (error) {
46
- const failure = error as { data?: { errors?: { message: string }[] } } | null
47
- uploadError.value = failure?.data?.errors?.[0]?.message ? t('fields.upload.rejected', { message: failure.data.errors[0].message }) : vectorErrorMessage(error)
47
+ const failure = error as { data?: { errors?: unknown } } | null
48
+ const rejected = violationsOf(failure?.data?.errors)[0]
49
+ uploadError.value = rejected?.message ? t('fields.upload.rejected', { message: rejected.message }) : vectorErrorMessage(error)
48
50
  } finally {
49
51
  uploading.value = false
50
52
  }
@@ -34,11 +34,11 @@ watch(chosen, (names) => {
34
34
  }
35
35
  })
36
36
 
37
- const subject = computed(() => props.selection.all
38
- ? props.count === null
39
- ? t('list.bulkEdit.everyMatchingUncounted', { noun: noun(props.resource.labelSingular) })
40
- : t('list.bulkEdit.everyMatching', { noun: noun(props.resource.labelSingular), count: props.count })
41
- : t('list.bulkEdit.some', { count: props.count, noun: noun(props.count === 1 ? props.resource.labelSingular : props.resource.label) }))
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]: { ...(model.value[name] ?? {}), ...condition } }
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]: { ...(alternative[name] ?? {}), ...condition } } : alternative))
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 = { ...(next[name] ?? {}) }
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 = { ...(next[name] ?? {}) }
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
- <div
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
- <span class="d-inline-flex align-center ga-1" role="group" :aria-label="t('list.filter.alternative', { n: a + 1 })">
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
- </span>
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
- </div>
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
- const show = (value: unknown) => value === null || value === undefined ? t('common.none') : typeof value === 'object' ? JSON.stringify(value) : String(value)
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. */
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import type { SubmitEventPromise } from 'vuetify'
3
3
  import type { VectorField, VectorFieldState, VectorLayoutNode, VectorRecord, VectorResource } from '#vector/app/types/vector'
4
+ import { violationsOf } from '#vector/app/utils/internal/violations'
4
5
 
5
6
  // A create or edit form generated from the descriptor: one input per
6
7
  // editable field, client rules mirroring the server's, and the server's
@@ -53,14 +54,17 @@ const clone = (value: unknown) => value === undefined ? undefined : JSON.parse(J
53
54
  const copies = (field: VectorField) => props.operation === 'create' && props.copyOf !== undefined
54
55
  && field.unique !== true && !['file', 'image', 'manyToMany', 'hasMany'].includes(field.type)
55
56
 
57
+ /** What a field starts with when nothing gives it a value: on create its declared default, else its type's empty one. */
58
+ function initialValue(field: VectorField): unknown {
59
+ return props.operation === 'create' && field.hasDefault ? JSON.parse(JSON.stringify(field.default ?? null)) : defaultFor(field)
60
+ }
61
+
56
62
  /** Fills the values from the record, the preset, the record being copied, or each field's default. */
57
63
  function start() {
58
64
  for (const field of fields.value) {
59
65
  const current = props.preset?.[field.name] ?? props.record?.[field.name] ?? (copies(field) ? props.copyOf![field.name] : undefined)
60
66
  // a new record starts from each field's default, which the server would apply as well
61
- let value: unknown = current !== undefined
62
- ? current
63
- : props.operation === 'create' && field.hasDefault ? JSON.parse(JSON.stringify(field.default ?? null)) : defaultFor(field)
67
+ let value: unknown = current === undefined ? initialValue(field) : current
64
68
 
65
69
  if (field.type === 'belongsTo' && current && typeof current === 'object' && 'id' in current) {
66
70
  value = (current as { id: unknown }).id
@@ -155,7 +159,8 @@ const chosen = computed<SaveVariant>(() => {
155
159
  })
156
160
  const variantLabel = (variant: SaveVariant) => {
157
161
  const verb = props.operation === 'create' ? 'create' : 'save'
158
- return variant === 'close' ? t(`common.${verb}`) : t(`record.variants.${verb}${variant === 'continue' ? 'Continue' : 'Another'}`)
162
+ if (variant === 'close') return t(`common.${verb}`)
163
+ return t(`record.variants.${verb}${variant === 'continue' ? 'Continue' : 'Another'}`)
159
164
  }
160
165
 
161
166
  const formRef = ref<{ validate: () => Promise<{ valid: boolean, errors: { id: string | number }[] }>, resetValidation: () => void } | null>(null)
@@ -218,13 +223,14 @@ async function save({ valid, errors }: { valid: boolean, errors: { id: string |
218
223
  const violations = failure?.data?.errors
219
224
 
220
225
  if ((failure?.status ?? failure?.statusCode) === 422 && Array.isArray(violations)) {
221
- for (const violation of violations as { path: (string | number)[], message: string }[]) {
226
+ for (const violation of violationsOf(violations)) {
222
227
  // a repeater row's own violation stays with its row: `lines.2.quantity`
223
228
  const repeated = violation.path.length >= 3 && fields.value.some(f => f.name === violation.path[0] && f.repeater)
224
229
  const key = repeated ? violation.path.slice(0, 3).join('.') : String(violation.path[0] ?? '')
225
230
 
226
231
  if (key && (key in values || repeated)) {
227
- (serverErrors[key] ??= []).push(`${violation.message.charAt(0).toUpperCase()}${violation.message.slice(1)}`)
232
+ serverErrors[key] ??= []
233
+ serverErrors[key].push(`${violation.message.charAt(0).toUpperCase()}${violation.message.slice(1)}`)
228
234
  } else {
229
235
  formError.value = violation.message
230
236
  }
@@ -284,7 +290,7 @@ defineExpose({ dirty, reset })
284
290
  // Conditions (visibleWhen, requiredWhen, disabledWhen) follow the values as they are edited.
285
291
  // Like the server, they read the stored record overlaid with the values being edited.
286
292
  const states = computed<Record<string, VectorFieldState>>(() => {
287
- const current = { ...(props.record ?? {}), ...values }
293
+ const current = { ...props.record, ...values }
288
294
  return Object.fromEntries(fields.value.map(f => [f.name, fieldState(f, current)]))
289
295
  })
290
296
  const shownFields = computed(() => fields.value.filter(f => states.value[f.name]?.visible !== false && !(props.preset && f.name in props.preset)))
@@ -306,13 +312,22 @@ const errorNames = computed(() => [...new Set([
306
312
  ...Object.entries(serverErrors).filter(([, messages]) => messages.length > 0).map(([key]) => key.split('.')[0]!),
307
313
  ...clientErrors.value,
308
314
  ])])
315
+
316
+ /** The server's errors on a field the form does not show (visibleWhen, or preset): above the form, under the field's label. */
317
+ const hiddenErrors = computed(() => Object.entries(serverErrors)
318
+ .map(([key, messages]) => [key.split('.')[0]!, messages] as const)
319
+ .filter(([name]) => !shownNames.value.has(name))
320
+ .flatMap(([name, messages]) => messages.map(message => `${fieldsByName.value.get(name)?.label ?? name}: ${message}`)))
309
321
  </script>
310
322
 
311
323
  <template>
312
324
  <v-form ref="formRef" validate-on="blur lazy" @submit.prevent="submit">
313
325
  <v-card>
314
326
  <v-card-text>
315
- <v-alert v-if="formError" type="error" variant="tonal" class="mb-4" :text="formError" />
327
+ <v-alert v-if="formError || hiddenErrors.length" type="error" variant="tonal" class="mb-4">
328
+ <div v-if="formError">{{ formError }}</div>
329
+ <div v-for="message in hiddenErrors" :key="message">{{ message }}</div>
330
+ </v-alert>
316
331
  <VxLayout :nodes="layout" :shown="name => shownNames.has(name)" :errors="errorNames" :default-span="defaultSpan">
317
332
  <template #field="{ field: name }">
318
333
  <component
@@ -148,7 +148,8 @@ async function created() {
148
148
  }
149
149
 
150
150
  function label(n: number): string {
151
- return target.value ? noun(n === 1 ? target.value.labelSingular : target.value.label) : t('record.panel.records')
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