@kinetis/vector-ui 0.10.3 → 0.10.4

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 CHANGED
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.10.4] - 2026-10-22
11
+
12
+ ### Changed
13
+
14
+ - The resource form, the resource table and the rich-text schema are
15
+ split into smaller functions. Their behavior is unchanged.
16
+
10
17
  ## [0.10.3] - 2026-10-22
11
18
 
12
19
  ### Changed
@@ -1,7 +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
+ import { type Violation, violationsOf } from '#vector/app/utils/internal/violations'
5
5
 
6
6
  // A create or edit form generated from the descriptor: one input per
7
7
  // editable field, client rules mirroring the server's, and the server's
@@ -205,48 +205,58 @@ async function save({ valid, errors }: { valid: boolean, errors: { id: string |
205
205
  }
206
206
 
207
207
  try {
208
- let response
209
-
210
- if (props.operation === 'create') {
211
- response = await client.create(payload(false))
212
- } else {
213
- const version = props.record?._version as number | undefined
214
- response = await client.update(props.record!.id, payload(true), version)
215
- }
208
+ const response = await persist()
216
209
 
217
210
  notifications.success(t('record.saved', { label: props.resource.labelSingular }))
218
211
  // what is saved is no longer a change: leaving now asks nothing
219
212
  for (const field of fields.value) initial[field.name] = clone(values[field.name])
220
213
  emit('saved', response.data, variant)
221
214
  } catch (error) {
222
- const failure = error as { status?: number, statusCode?: number, data?: { errors?: unknown } } | null
223
- const violations = failure?.data?.errors
224
-
225
- if ((failure?.status ?? failure?.statusCode) === 422 && Array.isArray(violations)) {
226
- for (const violation of violationsOf(violations)) {
227
- // a repeater row's own violation stays with its row: `lines.2.quantity`
228
- const repeated = violation.path.length >= 3 && fields.value.some(f => f.name === violation.path[0] && f.repeater)
229
- const key = repeated ? violation.path.slice(0, 3).join('.') : String(violation.path[0] ?? '')
230
-
231
- if (key && (key in values || repeated)) {
232
- serverErrors[key] ??= []
233
- serverErrors[key].push(`${violation.message.charAt(0).toUpperCase()}${violation.message.slice(1)}`)
234
- } else {
235
- formError.value = violation.message
236
- }
237
- }
238
-
239
- if (!formError.value && Object.keys(serverErrors).length === 0) {
240
- formError.value = t('common.serverRejected')
241
- }
242
- } else {
243
- formError.value = vectorErrorMessage(error)
244
- }
215
+ showFailure(error)
245
216
  } finally {
246
217
  submitting.value = false
247
218
  }
248
219
  }
249
220
 
221
+ /** Creates the record, or updates it with what changed. */
222
+ function persist() {
223
+ if (props.operation === 'create') return client.create(payload(false))
224
+
225
+ const version = props.record?._version as number | undefined
226
+ return client.update(props.record!.id, payload(true), version)
227
+ }
228
+
229
+ /** A failed save: the server's 422 mapped onto the fields it names, anything else above the form. */
230
+ function showFailure(error: unknown) {
231
+ const failure = error as { status?: number, statusCode?: number, data?: { errors?: unknown } } | null
232
+ const violations = failure?.data?.errors
233
+
234
+ if ((failure?.status ?? failure?.statusCode) !== 422 || !Array.isArray(violations)) {
235
+ formError.value = vectorErrorMessage(error)
236
+ return
237
+ }
238
+
239
+ for (const violation of violationsOf(violations)) showViolation(violation)
240
+
241
+ if (!formError.value && Object.keys(serverErrors).length === 0) {
242
+ formError.value = t('common.serverRejected')
243
+ }
244
+ }
245
+
246
+ /** One violation under the field it names, or above the form when it names none the form holds. */
247
+ function showViolation(violation: Violation) {
248
+ // a repeater row's own violation stays with its row: `lines.2.quantity`
249
+ const repeated = violation.path.length >= 3 && fields.value.some(f => f.name === violation.path[0] && f.repeater)
250
+ const key = repeated ? violation.path.slice(0, 3).join('.') : String(violation.path[0] ?? '')
251
+
252
+ if (key && (key in values || repeated)) {
253
+ serverErrors[key] ??= []
254
+ serverErrors[key].push(`${violation.message.charAt(0).toUpperCase()}${violation.message.slice(1)}`)
255
+ } else {
256
+ formError.value = violation.message
257
+ }
258
+ }
259
+
250
260
  /** Create sends every editable field; update sends only what changed. */
251
261
  function payload(onlyChanged: boolean): Record<string, unknown> {
252
262
  const body: Record<string, unknown> = {}
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { fieldProps, type VectorAction, type VectorExportFormat, type VectorField, type VectorFilterGroup, type VectorFilterQuery, type VectorFilters, type VectorListState, type VectorPage, type VectorRecord, type VectorResource, type VectorSelection, type VectorSort, type VectorSavedView } from '#vector/app/types/vector'
3
3
  import type { VectorPageStep } from '#vector/app/composables/useVectorCursorPager'
4
- import { violationsOf } from '#vector/app/utils/internal/violations'
4
+ import { type Violation, violationsOf } from '#vector/app/utils/internal/violations'
5
5
 
6
6
  // The list view: a server-driven table whose every option — page, size,
7
7
  // sort, filters, search, grouping, columns — becomes one list request,
@@ -192,38 +192,62 @@ function setPerPage(perPage: number) {
192
192
  // --- views ------------------------------------------------------------
193
193
  const viewMenu = ref<{ views: VectorSavedView[] } | null>(null)
194
194
 
195
+ /** A stored filter as the bar edits it. */
196
+ interface DecodedFilter {
197
+ filters: VectorFilters
198
+ groups: VectorFilterGroup[]
199
+ advanced: VectorFilterQuery[]
200
+ trashed: 'without' | 'only' | 'with'
201
+ }
202
+
195
203
  /**
196
204
  * A stored filter back into what the bar edits: its conditions, its
197
205
  * "any of" groups of plain alternatives, and anything deeper kept as it
198
206
  * is. Conditions on fields this account cannot see are dropped.
199
207
  */
200
- function decodeFilter(filter: VectorFilterQuery, known: Set<string>) {
201
- const out = { filters: {} as VectorFilters, groups: [] as VectorFilterGroup[], advanced: [] as VectorFilterQuery[], trashed: 'without' as 'without' | 'only' | 'with' }
202
- const plain = (node: VectorFilterQuery): node is VectorFilters => Object.entries(node).every(([k, v]) => k !== 'or' && k !== 'and' && k !== 'trashed' && typeof v === 'object' && !Array.isArray(v))
208
+ function decodeFilter(filter: VectorFilterQuery, known: Set<string>): DecodedFilter {
209
+ const out: DecodedFilter = { filters: {}, groups: [], advanced: [], trashed: 'without' }
203
210
 
204
211
  for (const [key, spec] of Object.entries(filter)) {
205
- if (key === 'trashed') {
206
- const value = typeof spec === 'string' ? spec : (spec as Record<string, string> | undefined)?.eq ?? (spec as Record<string, string> | undefined)?.['']
207
- out.trashed = (value === 'only' || value === 'with' ? value : 'without')
208
- } else if (key === 'or' && Array.isArray(spec)) {
209
- if (spec.every(plain)) out.groups.push(spec.map(a => Object.fromEntries(Object.entries(a).filter(([name]) => known.has(name)))).filter(a => Object.keys(a).length > 0))
210
- else out.advanced.push({ or: spec })
211
- } else if (key === 'and' && Array.isArray(spec)) {
212
- for (const child of spec) {
213
- const inner = decodeFilter(child, known)
214
- for (const [name, ops] of Object.entries(inner.filters)) out.filters[name] = { ...out.filters[name], ...ops }
215
- out.groups.push(...inner.groups)
216
- out.advanced.push(...inner.advanced)
217
- }
218
- } else if (known.has(key) && spec !== undefined && !Array.isArray(spec)) {
219
- out.filters[key] = typeof spec === 'string' ? { eq: spec } : { ...spec }
220
- }
212
+ if (key === 'trashed') out.trashed = decodeTrashed(spec)
213
+ else if (key === 'or' && Array.isArray(spec)) decodeAlternatives(out, spec, known)
214
+ else if (key === 'and' && Array.isArray(spec)) decodeConjunction(out, spec, known)
215
+ else if (known.has(key) && spec !== undefined && !Array.isArray(spec)) out.filters[key] = typeof spec === 'string' ? { eq: spec } : { ...spec }
221
216
  }
222
217
 
223
218
  out.groups = out.groups.filter(g => g.length > 0)
224
219
  return out
225
220
  }
226
221
 
222
+ /** Whether a filter node is plain conditions: no `or`, `and` or `trashed`, every value an operator object. */
223
+ const plainConditions = (node: VectorFilterQuery): node is VectorFilters => Object.entries(node).every(([k, v]) => k !== 'or' && k !== 'and' && k !== 'trashed' && typeof v === 'object' && !Array.isArray(v))
224
+
225
+ /** A stored `trashed`, as a string or an operator: anything it does not know is "without". */
226
+ function decodeTrashed(spec: VectorFilterQuery[string]): DecodedFilter['trashed'] {
227
+ const value = typeof spec === 'string' ? spec : (spec as Record<string, string> | undefined)?.eq ?? (spec as Record<string, string> | undefined)?.['']
228
+ return value === 'only' || value === 'with' ? value : 'without'
229
+ }
230
+
231
+ /** An `or` the bar can edit as a group of plain alternatives, its unknown fields dropped; any deeper one kept as it is. */
232
+ function decodeAlternatives(out: DecodedFilter, spec: VectorFilterQuery[], known: Set<string>) {
233
+ if (!spec.every(plainConditions)) {
234
+ out.advanced.push({ or: spec })
235
+ return
236
+ }
237
+
238
+ out.groups.push(spec.map(a => Object.fromEntries(Object.entries(a).filter(([name]) => known.has(name)))).filter(a => Object.keys(a).length > 0))
239
+ }
240
+
241
+ /** An `and`: each of its children decoded and merged into `out`. */
242
+ function decodeConjunction(out: DecodedFilter, spec: VectorFilterQuery[], known: Set<string>) {
243
+ for (const child of spec) {
244
+ const inner = decodeFilter(child, known)
245
+ for (const [name, ops] of Object.entries(inner.filters)) out.filters[name] = { ...out.filters[name], ...ops }
246
+ out.groups.push(...inner.groups)
247
+ out.advanced.push(...inner.advanced)
248
+ }
249
+ }
250
+
227
251
  function applyView(view: VectorSavedView | null) {
228
252
  activeView.value = view?.id ?? null
229
253
  const s = view?.state ?? {}
@@ -405,26 +429,34 @@ async function saveChanges() {
405
429
  discardChanges()
406
430
  await load()
407
431
  } catch (error) {
408
- const failure = error as { status?: number, statusCode?: number, data?: { errors?: unknown } } | null
409
- const status = failure?.status ?? failure?.statusCode
410
-
411
- if (status === 422 && Array.isArray(failure?.data?.errors)) {
412
- for (const violation of violationsOf(failure.data.errors)) {
413
- const [, index, field] = violation.path
414
- const change = typeof index === 'number' ? list[index] : undefined
415
- if (change && typeof field === 'string' && field in change.values) cellErrors[cellKey(change.id, field)] = violation.message
416
- else notifications.error(field ? `${String(field)}: ${violation.message}` : violation.message)
417
- }
418
- } else if (status === 409) {
419
- notifications.error(t('list.inline.conflict'))
420
- } else {
421
- notifications.error(vectorErrorMessage(error))
422
- }
432
+ showChangesFailure(error, list)
423
433
  } finally {
424
434
  savingChanges.value = false
425
435
  }
426
436
  }
427
437
 
438
+ /** A changeset the server refused: a 422 on the cells it names, a conflict or any other failure as a notification. */
439
+ function showChangesFailure(error: unknown, list: { id: string | number, values: Record<string, unknown> }[]) {
440
+ const failure = error as { status?: number, statusCode?: number, data?: { errors?: unknown } } | null
441
+ const status = failure?.status ?? failure?.statusCode
442
+
443
+ if (status === 422 && Array.isArray(failure?.data?.errors)) {
444
+ for (const violation of violationsOf(failure.data.errors)) showChangeViolation(violation, list)
445
+ } else if (status === 409) {
446
+ notifications.error(t('list.inline.conflict'))
447
+ } else {
448
+ notifications.error(vectorErrorMessage(error))
449
+ }
450
+ }
451
+
452
+ /** One violation of a changeset, `changes.{index}.{field}`: on its cell when that cell changed, else as a notification. */
453
+ function showChangeViolation(violation: Violation, list: { id: string | number, values: Record<string, unknown> }[]) {
454
+ const [, index, field] = violation.path
455
+ const change = typeof index === 'number' ? list[index] : undefined
456
+ if (change && typeof field === 'string' && field in change.values) cellErrors[cellKey(change.id, field)] = violation.message
457
+ else notifications.error(field ? `${String(field)}: ${violation.message}` : violation.message)
458
+ }
459
+
428
460
  async function mayLeave(): Promise<boolean> {
429
461
  if (!pendingCount.value) return true
430
462
  return await confirm({ title: t('list.inline.leaveTitle', { count: pendingCount.value }, pendingCount.value), text: t('list.inline.leaveText'), confirmText: t('list.inline.discard'), destructive: true })
@@ -1,6 +1,6 @@
1
1
  import type { AnyExtension, Extensions, JSONContent } from '@tiptap/core'
2
2
  import { generateHTML, generateJSON, generateText } from '@tiptap/core'
3
- import StarterKit from '@tiptap/starter-kit'
3
+ import StarterKit, { type StarterKitOptions } from '@tiptap/starter-kit'
4
4
  import { TableKit } from '@tiptap/extension-table'
5
5
  import Image from '@tiptap/extension-image'
6
6
  import Placeholder from '@tiptap/extension-placeholder'
@@ -38,35 +38,45 @@ export interface RichTextOptions {
38
38
  custom?: ReadonlyMap<string, AnyExtension>
39
39
  }
40
40
 
41
+ /** The StarterKit parts turned on with their default options, each by the feature that allows it. */
42
+ const STARTER_KIT_FEATURES = {
43
+ bold: 'bold',
44
+ italic: 'italic',
45
+ underline: 'underline',
46
+ strike: 'strike',
47
+ code: 'code',
48
+ bulletList: 'list',
49
+ orderedList: 'list',
50
+ listItem: 'list',
51
+ listKeymap: 'list',
52
+ blockquote: 'blockquote',
53
+ codeBlock: 'codeBlock',
54
+ horizontalRule: 'horizontalRule',
55
+ } as const
56
+
57
+ /** StarterKit's options for a field: each part on exactly when its feature is, headings up to h4, links only where allowedHref lets them go. */
58
+ function starterKitOptions(on: (feature: string) => boolean): Partial<StarterKitOptions> {
59
+ const parts = Object.fromEntries(Object.entries(STARTER_KIT_FEATURES).map(([part, feature]) => [part, on(feature) ? {} : false]))
60
+
61
+ return {
62
+ ...parts,
63
+ heading: on('heading') ? { levels: [1, 2, 3, 4] } : false,
64
+ link: on('link')
65
+ ? {
66
+ openOnClick: false,
67
+ autolink: true,
68
+ protocols: [],
69
+ HTMLAttributes: { target: '_blank', rel: 'noopener noreferrer nofollow' },
70
+ isAllowedUri: (url: string) => allowedHref(url),
71
+ }
72
+ : false,
73
+ }
74
+ }
75
+
41
76
  /** The Tiptap extensions for a field: exactly its features, nothing else. */
42
77
  export function richTextExtensions(options: RichTextOptions): Extensions {
43
78
  const on = (feature: string) => options.features.includes(feature)
44
- const extensions: Extensions = [
45
- StarterKit.configure({
46
- bold: on('bold') ? {} : false,
47
- italic: on('italic') ? {} : false,
48
- underline: on('underline') ? {} : false,
49
- strike: on('strike') ? {} : false,
50
- code: on('code') ? {} : false,
51
- heading: on('heading') ? { levels: [1, 2, 3, 4] } : false,
52
- bulletList: on('list') ? {} : false,
53
- orderedList: on('list') ? {} : false,
54
- listItem: on('list') ? {} : false,
55
- listKeymap: on('list') ? {} : false,
56
- blockquote: on('blockquote') ? {} : false,
57
- codeBlock: on('codeBlock') ? {} : false,
58
- horizontalRule: on('horizontalRule') ? {} : false,
59
- link: on('link')
60
- ? {
61
- openOnClick: false,
62
- autolink: true,
63
- protocols: [],
64
- HTMLAttributes: { target: '_blank', rel: 'noopener noreferrer nofollow' },
65
- isAllowedUri: (url: string) => allowedHref(url),
66
- }
67
- : false,
68
- }),
69
- ]
79
+ const extensions: Extensions = [StarterKit.configure(starterKitOptions(on))]
70
80
 
71
81
  if (on('table')) {
72
82
  // not resizable: resizing writes style attributes a strict CSP refuses
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kinetis/vector-ui",
3
- "version": "0.10.3",
3
+ "version": "0.10.4",
4
4
  "description": "The Kinetis Vector admin UI, as a Nuxt layer on Vuetify.",
5
5
  "keywords": [
6
6
  "kinetis",