@quazardous/qdadm 2.30.0 → 2.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quazardous/qdadm",
3
- "version": "2.30.0",
3
+ "version": "2.31.0",
4
4
  "description": "Vue 3 framework for admin dashboards with PrimeVue",
5
5
  "author": "quazardous",
6
6
  "license": "MIT",
@@ -28,7 +28,7 @@
28
28
  import { computed, type PropType } from 'vue'
29
29
  import { RouterLink, type RouteLocationRaw } from 'vue-router'
30
30
  import Tag from 'primevue/tag'
31
- import { formatDate, formatNumber, formatCurrency } from '../../utils/formatters'
31
+ import { formatDate, formatNumber, formatCurrency, getEmptyPlaceholder } from '../../utils/formatters'
32
32
 
33
33
  type DisplayType =
34
34
  | 'text'
@@ -80,6 +80,8 @@ interface FieldConfig {
80
80
  imageHeight?: string
81
81
  // Custom render
82
82
  render?: (value: unknown) => string
83
+ /** Shown for an empty value; defaults to the kernel's `display.emptyPlaceholder` (#2772). */
84
+ emptyText?: string
83
85
  }
84
86
 
85
87
  const props = defineProps({
@@ -97,16 +99,19 @@ const isEmpty = computed(() => {
97
99
  return props.value === null || props.value === undefined || props.value === ''
98
100
  })
99
101
 
102
+ // What an empty value shows: the field's own, else the app-wide placeholder (#2772)
103
+ const emptyText = computed(() => props.field.emptyText ?? getEmptyPlaceholder())
104
+
100
105
  // Format text value
101
106
  const textValue = computed(() => {
102
- if (isEmpty.value) return '-'
107
+ if (isEmpty.value) return emptyText.value
103
108
  if (props.field.render) return props.field.render(props.value)
104
109
  return String(props.value)
105
110
  })
106
111
 
107
112
  // Format number value (browser locale by default — utils/formatters policy)
108
113
  const numberValue = computed(() => {
109
- if (isEmpty.value) return '-'
114
+ if (isEmpty.value) return emptyText.value
110
115
  const num = Number(props.value)
111
116
  if (isNaN(num)) return String(props.value)
112
117
  // useGrouping: false → no locale digit grouping (years, ids… "1965",
@@ -117,7 +122,7 @@ const numberValue = computed(() => {
117
122
 
118
123
  // Format currency value
119
124
  const currencyValue = computed(() => {
120
- if (isEmpty.value) return '-'
125
+ if (isEmpty.value) return emptyText.value
121
126
  const num = Number(props.value)
122
127
  if (isNaN(num)) return String(props.value)
123
128
  return formatCurrency(num, props.field.currencyCode || 'USD', props.field.locale)
@@ -125,7 +130,7 @@ const currencyValue = computed(() => {
125
130
 
126
131
  // Format boolean value
127
132
  const booleanValue = computed(() => {
128
- if (isEmpty.value) return '-'
133
+ if (isEmpty.value) return emptyText.value
129
134
  const labels = props.field.booleanLabels || { true: 'Yes', false: 'No' }
130
135
  return props.value ? labels.true : labels.false
131
136
  })
@@ -142,7 +147,7 @@ const booleanIconClass = computed(() => {
142
147
 
143
148
  // Format date value
144
149
  const dateValue = computed(() => {
145
- if (isEmpty.value) return '-'
150
+ if (isEmpty.value) return emptyText.value
146
151
  const v = props.value as unknown
147
152
  const date = (typeof v === 'object' && v instanceof Date) ? v : new Date(String(v))
148
153
  if (isNaN(date.getTime())) return String(props.value)
@@ -152,7 +157,7 @@ const dateValue = computed(() => {
152
157
 
153
158
  // Format datetime value
154
159
  const datetimeValue = computed(() => {
155
- if (isEmpty.value) return '-'
160
+ if (isEmpty.value) return emptyText.value
156
161
  const v = props.value as unknown
157
162
  const date = (typeof v === 'object' && v instanceof Date) ? v : new Date(String(v))
158
163
  if (isNaN(date.getTime())) return String(props.value)
@@ -161,7 +166,7 @@ const datetimeValue = computed(() => {
161
166
 
162
167
  // Format select value (lookup label from options)
163
168
  const selectValue = computed(() => {
164
- if (isEmpty.value) return '-'
169
+ if (isEmpty.value) return emptyText.value
165
170
  const options = props.field.options || []
166
171
  const optionValue = props.field.optionValue || 'value'
167
172
  const optionLabel = props.field.optionLabel || 'label'
@@ -184,7 +189,7 @@ const referenceRoute = computed<RouteLocationRaw | null>(() => {
184
189
 
185
190
  // Reference label
186
191
  const referenceLabel = computed(() => {
187
- if (isEmpty.value) return '-'
192
+ if (isEmpty.value) return emptyText.value
188
193
  if (typeof props.field.referenceLabel === 'function') {
189
194
  return props.field.referenceLabel(props.value)
190
195
  }
@@ -215,7 +220,7 @@ const badgeIcon = computed(() => badgeDescriptor.value.icon)
215
220
 
216
221
  // JSON formatted
217
222
  const jsonValue = computed(() => {
218
- if (isEmpty.value) return '-'
223
+ if (isEmpty.value) return emptyText.value
219
224
  try {
220
225
  return JSON.stringify(props.value, null, 2)
221
226
  } catch {
@@ -232,7 +237,7 @@ const imageStyle = computed(() => ({
232
237
 
233
238
  <template>
234
239
  <!-- Empty value -->
235
- <span v-if="isEmpty" class="show-display show-display--empty">-</span>
240
+ <span v-if="isEmpty" class="show-display show-display--empty">{{ emptyText }}</span>
236
241
 
237
242
  <!-- Text -->
238
243
  <span v-else-if="displayType === 'text'" class="show-display show-display--text">
@@ -361,6 +361,7 @@ export function useEntityItemShowPage<T = Record<string, unknown>>(
361
361
  notifications.addNotification({ severity: 'info', keep: 'short', ...to, ...entry })
362
362
  }, {
363
363
  id: () => entityId.value,
364
+ screen: 'show',
364
365
  // The update has arrived: say so on the badge at once — before the reload is
365
366
  // coalesced, let alone finished (#2679).
366
367
  onEvent: () => notifications.flash(),
@@ -1227,7 +1227,7 @@ export function useListPage<T = unknown>(config: UseListPageOptions<T>): UseList
1227
1227
  keptKeys.has((item as Record<string, unknown>)[resolvedDataKey])
1228
1228
  ) as T[]
1229
1229
  }
1230
- })
1230
+ }, { screen: 'list' })
1231
1231
 
1232
1232
  // ============ UTILITIES ============
1233
1233
  // Browser-locale by default (unified policy — see utils/formatters).
@@ -10,7 +10,9 @@
10
10
  * There is no page-level opt-in, deliberately. The gate is upstream: only an
11
11
  * entity the app declared in `sse.entities` ever produces a remote event, so an
12
12
  * app with no live backend sees no behaviour change and has no flag to forget.
13
- * What the entity does about it is its own policy (`live` on the manager).
13
+ * What the entity does about it is its own policy (`live` on the manager) —
14
+ * which may differ per screen and per change kind (#2971); the page builders
15
+ * only say which screen they are.
14
16
  *
15
17
  * @experimental Shape may change in a minor release — see docs/API_STABILITY.md.
16
18
  */
@@ -33,10 +35,17 @@ export interface UseLiveEntityOptions {
33
35
  * notification badge's flash.
34
36
  */
35
37
  onEvent?: () => void
38
+ /**
39
+ * Which screen this is, to pick its rule when the entity's `live.refresh`
40
+ * is set per screen (#2971). Without it, a per-screen policy means `'mounted'`.
41
+ */
42
+ screen?: 'list' | 'show'
36
43
  }
37
44
 
45
+ type RefreshRule = 'mounted' | false | string[]
46
+
38
47
  interface LivePolicy {
39
- refresh?: 'mounted' | false
48
+ refresh?: RefreshRule | { list?: RefreshRule; show?: RefreshRule }
40
49
  coalesceMs?: number
41
50
  }
42
51
 
@@ -62,9 +71,15 @@ export function useLiveEntity(
62
71
  if (!signals || !entityName) return () => {}
63
72
 
64
73
  const policy = (manager as { live?: LivePolicy } | null | undefined)?.live ?? {}
65
- // `refresh: false` — invalidation still happened upstream, the screen just
66
- // does not chase it. Subscribing would only burn a listener.
67
- if (policy.refresh === false) return () => {}
74
+ const refresh = policy.refresh
75
+ const rule: RefreshRule = refresh !== null && typeof refresh === 'object' && !Array.isArray(refresh)
76
+ ? (options.screen ? refresh[options.screen] : undefined) ?? 'mounted'
77
+ : refresh ?? 'mounted'
78
+ // `false` — invalidation still happened upstream, the screen just does not
79
+ // chase it. Subscribing would only burn a listener.
80
+ if (rule === false) return () => {}
81
+ // An array names the change kinds worth a reload (#2971).
82
+ const kinds = Array.isArray(rule) ? new Set(rule) : null
68
83
 
69
84
  const coalesceMs = policy.coalesceMs ?? 300
70
85
  let timer: ReturnType<typeof setTimeout> | null = null
@@ -114,6 +129,7 @@ export function useLiveEntity(
114
129
  const payload = (event.data || {}) as {
115
130
  entity?: string
116
131
  id?: string | number
132
+ action?: string
117
133
  source?: string
118
134
  }
119
135
 
@@ -135,6 +151,10 @@ export function useLiveEntity(
135
151
  }
136
152
  }
137
153
 
154
+ // A kind this screen ignores is not news to it: no cue, no reload. An event
155
+ // carrying no kind is an update, as the live router reports it by default.
156
+ if (kinds && !kinds.has(payload.action ?? 'updated')) return
157
+
138
158
  options.onEvent?.()
139
159
 
140
160
  // Coalesce: a backend replaying fifty rows must cost one reload, not fifty.
@@ -18,6 +18,7 @@ import type { HookRegistry } from '../hooks/HookRegistry'
18
18
  import type { EntityManager } from './EntityManager'
19
19
  import type { RouteStatePersister } from '../routeState'
20
20
  import type { NewNotification } from '../notifications/NotificationStore'
21
+ import type { LiveEntityAction } from '../kernel/LiveEntityRouter'
21
22
 
22
23
  // ============ INTERNAL TYPES ============
23
24
 
@@ -224,8 +225,13 @@ export interface LiveEntityPolicy {
224
225
  /**
225
226
  * `'mounted'` (default) — a screen currently showing this entity reloads.
226
227
  * `false` — invalidate the cache only; the screen updates next time it asks.
228
+ * An array of change kinds — reload only for those (`['created', 'deleted']`:
229
+ * rows came or went). An event carrying no kind counts as `'updated'`.
230
+ *
231
+ * One rule applies to every screen; `{ list, show }` sets it per screen
232
+ * (#2971), a screen left out keeping `'mounted'`.
227
233
  */
228
- refresh?: 'mounted' | false
234
+ refresh?: LiveRefreshRule | LiveRefreshPolicy
229
235
  /**
230
236
  * Window (ms) over which a burst of events collapses into a single reload.
231
237
  * Default 300. `0` reloads on every event — rarely what you want.
@@ -246,6 +252,15 @@ export interface LiveEntityPolicy {
246
252
  describeUpdate?: (before: EntityRecord, after: EntityRecord) => LiveUpdateEntry | null | undefined
247
253
  }
248
254
 
255
+ /** What a screen does about a change made elsewhere (#2971). */
256
+ export type LiveRefreshRule = 'mounted' | false | LiveEntityAction[]
257
+
258
+ /** `LiveEntityPolicy.refresh` per screen (#2971): the list pages and the detail pages. */
259
+ export interface LiveRefreshPolicy {
260
+ list?: LiveRefreshRule
261
+ show?: LiveRefreshRule
262
+ }
263
+
249
264
  /** The notification entry `LiveEntityPolicy.describeUpdate` asks for (#2685). */
250
265
  export type LiveUpdateEntry = Omit<NewNotification, 'severity'> & Partial<Pick<NewNotification, 'severity'>>
251
266
 
package/src/index.ts CHANGED
@@ -41,7 +41,7 @@ export { SSEBridge, createSSEBridge, SSE_SIGNALS } from './kernel/SSEBridge'
41
41
  export type { SSEBridgeOptions } from './kernel/SSEBridge'
42
42
  export { useLiveEntity } from './composables/useLiveEntity'
43
43
  export type { UseLiveEntityOptions } from './composables/useLiveEntity'
44
- export type { LiveEntityPolicy, LiveUpdateEntry } from './entity/EntityManager.types'
44
+ export type { LiveEntityPolicy, LiveUpdateEntry, LiveRefreshRule, LiveRefreshPolicy } from './entity/EntityManager.types'
45
45
  export { LiveEntityRouter, createLiveEntityRouter } from './kernel/LiveEntityRouter'
46
46
  export type {
47
47
  LiveEntityRouterOptions,
@@ -375,7 +375,7 @@ export function applyRegistryMethods(KernelClass: { prototype: Kernel }): void {
375
375
  */
376
376
  const KNOWN_KERNEL_OPTIONS = new Set([
377
377
  'apiClient', 'app', 'authAdapter', 'authTypes', 'basePath', 'coreRoutes',
378
- 'debug', 'debugBar', 'defaultEntityCacheTtlMs', 'entityAuthAdapter',
378
+ 'debug', 'debugBar', 'defaultEntityCacheTtlMs', 'display', 'entityAuthAdapter',
379
379
  'eventRouter', 'existingApp', 'existingRouter', 'existingSignals',
380
380
  'features', 'hashMode', 'homeRoute', 'i18n', 'layouts', 'managerRegistry',
381
381
  'managerResolver', 'managers', 'moduleDefs', 'modules', 'modulesOptions',
@@ -81,6 +81,7 @@ import { applyApiMethods } from './Kernel.api'
81
81
  import { applyI18nMethods } from './Kernel.i18n'
82
82
  import type { I18n } from '../i18n/I18n'
83
83
  import type { SseSubscriptions } from './sseSubscriptions'
84
+ import { setEmptyPlaceholder } from '../utils/formatters'
84
85
 
85
86
  export class Kernel {
86
87
  options: KernelOptions
@@ -133,6 +134,8 @@ export class Kernel {
133
134
  _authImpersonationCleanup: (() => void) | null = null
134
135
 
135
136
  constructor(options: KernelOptions) {
137
+ // Module-level, like the formatters that read it: one app per page (#2772).
138
+ if (options.display?.emptyPlaceholder !== undefined) setEmptyPlaceholder(options.display.emptyPlaceholder)
136
139
  // Auto-inject DebugModule if debugBar.module is provided
137
140
  if (options.debugBar?.module) {
138
141
  const DebugModuleClass = options.debugBar.module
@@ -268,6 +268,11 @@ export interface KernelOptions {
268
268
  routeState?: string | RouteStatePersister
269
269
  debugBar?: DebugBarConfig
270
270
  notifications?: NotificationsConfig
271
+ /** App-wide display defaults (#2772). */
272
+ display?: {
273
+ /** What a missing value shows, in detail pages and formatters. Default `'-'`. */
274
+ emptyPlaceholder?: string
275
+ }
271
276
  toast?: Record<string, unknown>
272
277
  debug?: boolean
273
278
  onAuthExpired?: (payload: unknown) => void
@@ -109,6 +109,8 @@ export interface FieldConfig {
109
109
  filterable?: boolean
110
110
  searchable?: boolean
111
111
  validator?: (value: unknown) => boolean | string
112
+ /** Shown in displays for an empty value; defaults to the kernel's `display.emptyPlaceholder` (#2772). */
113
+ emptyText?: string
112
114
  [key: string]: unknown
113
115
  }
114
116
 
@@ -8,6 +8,25 @@
8
8
  * {{ formatDateTime(item.updated_at) }}
9
9
  */
10
10
 
11
+ // =============================================================================
12
+ // EMPTY PLACEHOLDER
13
+ // =============================================================================
14
+
15
+ let emptyPlaceholder = '-'
16
+
17
+ /**
18
+ * What qdadm shows for a missing value (#2772): the formatters and detail
19
+ * pages. Set once by the kernel from `display.emptyPlaceholder`.
20
+ */
21
+ export function setEmptyPlaceholder(value: string): void {
22
+ emptyPlaceholder = value
23
+ }
24
+
25
+ /** The current empty placeholder, `'-'` unless configured. */
26
+ export function getEmptyPlaceholder(): string {
27
+ return emptyPlaceholder
28
+ }
29
+
11
30
  // =============================================================================
12
31
  // DATE/TIME FORMATTING
13
32
  // =============================================================================
@@ -22,16 +41,16 @@
22
41
  * @param dateStr - ISO date string or Date object
23
42
  * @param options - Intl.DateTimeFormat options
24
43
  * @param locale - Explicit locale override (default: browser locale)
25
- * @returns Formatted date string or '-' if empty
44
+ * @returns Formatted date string or the empty placeholder if empty
26
45
  */
27
46
  export function formatDate(
28
47
  dateStr: string | Date | null | undefined,
29
48
  options: Intl.DateTimeFormatOptions = {},
30
49
  locale?: string
31
50
  ): string {
32
- if (!dateStr) return '-'
51
+ if (!dateStr) return emptyPlaceholder
33
52
  const date = new Date(dateStr)
34
- if (isNaN(date.getTime())) return '-'
53
+ if (isNaN(date.getTime())) return emptyPlaceholder
35
54
 
36
55
  if (Object.keys(options).length === 0) {
37
56
  return date.toLocaleString(locale)
@@ -75,9 +94,9 @@ export function formatDateOnly(
75
94
  options: Intl.DateTimeFormatOptions = {},
76
95
  locale?: string
77
96
  ): string {
78
- if (!dateStr) return '-'
97
+ if (!dateStr) return emptyPlaceholder
79
98
  const date = new Date(dateStr)
80
- if (isNaN(date.getTime())) return '-'
99
+ if (isNaN(date.getTime())) return emptyPlaceholder
81
100
  return date.toLocaleDateString(locale, {
82
101
  year: 'numeric',
83
102
  month: '2-digit',
@@ -90,9 +109,9 @@ export function formatDateOnly(
90
109
  * Format to time only (14:30:00)
91
110
  */
92
111
  export function formatTimeOnly(dateStr: string | Date | null | undefined): string {
93
- if (!dateStr) return '-'
112
+ if (!dateStr) return emptyPlaceholder
94
113
  const date = new Date(dateStr)
95
- if (isNaN(date.getTime())) return '-'
114
+ if (isNaN(date.getTime())) return emptyPlaceholder
96
115
  return date.toLocaleTimeString()
97
116
  }
98
117
 
@@ -115,7 +134,7 @@ export function formatDateOrNever(dateStr: string | Date | null | undefined): st
115
134
  * @returns Human-readable duration (e.g., "2h 30m 15s" or "45.2s")
116
135
  */
117
136
  export function formatDuration(ms: number | null | undefined): string {
118
- if (ms === null || ms === undefined) return '-'
137
+ if (ms === null || ms === undefined) return emptyPlaceholder
119
138
  if (ms < 1000) return `${ms}ms`
120
139
 
121
140
  const seconds = Math.floor(ms / 1000)
@@ -142,10 +161,10 @@ export function formatDurationBetween(
142
161
  startDate: string | Date | null | undefined,
143
162
  endDate: string | Date | null | undefined
144
163
  ): string {
145
- if (!startDate || !endDate) return '-'
164
+ if (!startDate || !endDate) return emptyPlaceholder
146
165
  const start = new Date(startDate)
147
166
  const end = new Date(endDate)
148
- if (isNaN(start.getTime()) || isNaN(end.getTime())) return '-'
167
+ if (isNaN(start.getTime()) || isNaN(end.getTime())) return emptyPlaceholder
149
168
  return formatDuration(end.getTime() - start.getTime())
150
169
  }
151
170
 
@@ -163,7 +182,7 @@ export function formatNumber(
163
182
  options: Intl.NumberFormatOptions = {},
164
183
  locale?: string
165
184
  ): string {
166
- if (value === null || value === undefined) return '-'
185
+ if (value === null || value === undefined) return emptyPlaceholder
167
186
  return value.toLocaleString(locale, options)
168
187
  }
169
188
 
@@ -178,7 +197,7 @@ export function formatCurrency(
178
197
  currencyCode = 'USD',
179
198
  locale?: string
180
199
  ): string {
181
- if (value === null || value === undefined) return '-'
200
+ if (value === null || value === undefined) return emptyPlaceholder
182
201
  return new Intl.NumberFormat(locale, { style: 'currency', currency: currencyCode }).format(value)
183
202
  }
184
203
 
@@ -186,7 +205,7 @@ export function formatCurrency(
186
205
  * Format bytes to human-readable size
187
206
  */
188
207
  export function formatBytes(bytes: number | null | undefined): string {
189
- if (bytes === null || bytes === undefined) return '-'
208
+ if (bytes === null || bytes === undefined) return emptyPlaceholder
190
209
  if (bytes === 0) return '0 B'
191
210
 
192
211
  const units = ['B', 'KB', 'MB', 'GB', 'TB']
@@ -200,7 +219,7 @@ export function formatBytes(bytes: number | null | undefined): string {
200
219
  * Format a percentage
201
220
  */
202
221
  export function formatPercent(value: number | null | undefined, decimals = 1): string {
203
- if (value === null || value === undefined) return '-'
222
+ if (value === null || value === undefined) return emptyPlaceholder
204
223
  return `${(value * 100).toFixed(decimals)}%`
205
224
  }
206
225
 
@@ -16,6 +16,8 @@ export {
16
16
  formatCurrency,
17
17
  formatBytes,
18
18
  formatPercent,
19
+ setEmptyPlaceholder,
20
+ getEmptyPlaceholder,
19
21
  } from './formatters'
20
22
 
21
23
  // Error formatting