@quazardous/qdadm 2.29.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.29.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">
@@ -58,7 +58,8 @@ import {
58
58
  type ShowResolvedFieldConfig,
59
59
  } from './createShowFieldResolver'
60
60
  import type { OrchestratorLike } from '../entity/EntityManager.interface'
61
- import type { ButtonSeverity } from '../types'
61
+ import type { LiveEntityPolicy } from '../entity/EntityManager.types'
62
+ import type { ButtonSeverity, EntityRecord } from '../types'
62
63
  import { useActionRegistry } from './useActionRegistry'
63
64
  import { useLiveEntity } from './useLiveEntity'
64
65
 
@@ -329,19 +330,38 @@ export function useEntityItemShowPage<T = Record<string, unknown>>(
329
330
  const notifications = useNotifications()
330
331
  const route = useRoute()
331
332
  useLiveEntity(entity, manager, async () => {
333
+ // A burst of events is one reload, so this is the record from before the burst.
334
+ const before = data.value
332
335
  const record = await base.reload()
333
336
  // A change made elsewhere to the record on screen leaves a line in the
334
- // history (#2677): short-lived, linked back to it, never a pop-up.
337
+ // history (#2677): short-lived, linked back to it, never a pop-up. The
338
+ // entity may say the change is not worth one, or what it means (#2685).
335
339
  if (!record) return
336
- const name = entityLabel.value ? `"${entityLabel.value}"` : `#${entityId.value}`
337
- notifications.addNotification({
338
- severity: 'info',
339
- summary: `${manager.label ?? entity} ${name} updated elsewhere`,
340
- keep: 'short',
341
- ...(route?.name ? { to: { name: String(route.name), params: { ...route.params } } } : {}),
342
- })
340
+ const to = route?.name ? { to: { name: String(route.name), params: { ...route.params } } } : {}
341
+ const describeUpdate = (manager as { live?: LiveEntityPolicy }).live?.describeUpdate
342
+ if (!describeUpdate) {
343
+ const name = entityLabel.value ? `"${entityLabel.value}"` : `#${entityId.value}`
344
+ notifications.addNotification({
345
+ severity: 'info',
346
+ summary: `${manager.label ?? entity} ${name} updated elsewhere`,
347
+ keep: 'short',
348
+ ...to,
349
+ })
350
+ return
351
+ }
352
+ if (!before) return
353
+ let entry
354
+ try {
355
+ entry = describeUpdate(before as unknown as EntityRecord, record as unknown as EntityRecord)
356
+ } catch (err) {
357
+ console.warn(`[qdadm] live.describeUpdate failed for ${entity} #${entityId.value}:`, err)
358
+ return
359
+ }
360
+ if (!entry) return
361
+ notifications.addNotification({ severity: 'info', keep: 'short', ...to, ...entry })
343
362
  }, {
344
363
  id: () => entityId.value,
364
+ screen: 'show',
345
365
  // The update has arrived: say so on the badge at once — before the reload is
346
366
  // coalesced, let alone finished (#2679).
347
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.
@@ -105,7 +105,7 @@ export class EntityManager<T extends EntityRecord = EntityRecord> {
105
105
  protected _warmup: boolean
106
106
  protected _authSensitive: boolean
107
107
  /** Reaction policy for changes made outside this session (#1888). */
108
- protected _live: Required<LiveEntityPolicy>
108
+ protected _live: LiveEntityPolicy & Required<Pick<LiveEntityPolicy, 'refresh' | 'coalesceMs'>>
109
109
  protected _system: boolean
110
110
 
111
111
  protected _scopeWhitelist: string[] | null
@@ -215,6 +215,7 @@ export class EntityManager<T extends EntityRecord = EntityRecord> {
215
215
  this._live = {
216
216
  refresh: live?.refresh ?? 'mounted',
217
217
  coalesceMs: live?.coalesceMs ?? 300,
218
+ ...(live?.describeUpdate ? { describeUpdate: live.describeUpdate } : {}),
218
219
  }
219
220
  this._system = system
220
221
 
@@ -640,7 +641,7 @@ export class EntityManager<T extends EntityRecord = EntityRecord> {
640
641
  * Check if user can read entities
641
642
  */
642
643
  /** Reaction policy for changes made outside this session (#1888). */
643
- get live(): Required<LiveEntityPolicy> {
644
+ get live(): LiveEntityPolicy & Required<Pick<LiveEntityPolicy, 'refresh' | 'coalesceMs'>> {
644
645
  return this._live
645
646
  }
646
647
 
@@ -17,6 +17,8 @@ import type { HookRegistry } from '../hooks/HookRegistry'
17
17
  // Circular type import — safe because `import type` is erased at runtime
18
18
  import type { EntityManager } from './EntityManager'
19
19
  import type { RouteStatePersister } from '../routeState'
20
+ import type { NewNotification } from '../notifications/NotificationStore'
21
+ import type { LiveEntityAction } from '../kernel/LiveEntityRouter'
20
22
 
21
23
  // ============ INTERNAL TYPES ============
22
24
 
@@ -223,15 +225,45 @@ export interface LiveEntityPolicy {
223
225
  /**
224
226
  * `'mounted'` (default) — a screen currently showing this entity reloads.
225
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'`.
226
233
  */
227
- refresh?: 'mounted' | false
234
+ refresh?: LiveRefreshRule | LiveRefreshPolicy
228
235
  /**
229
236
  * Window (ms) over which a burst of events collapses into a single reload.
230
237
  * Default 300. `0` reloads on every event — rarely what you want.
231
238
  */
232
239
  coalesceMs?: number
240
+ /**
241
+ * Whether a live reload of a detail page is worth a notification entry, and
242
+ * what it says (#2685). Called once per reload, with the record that was on
243
+ * screen and the reloaded one.
244
+ *
245
+ * Return `null` / `undefined` for no entry (the badge still flashes), or the
246
+ * entry: `severity` defaults to `'info'`, `keep` to `'short'`, `to` to the
247
+ * record's page. Without this hook, the page adds a generic
248
+ * "… updated elsewhere" entry. If it throws, no entry is added.
249
+ *
250
+ * Do not mutate `before` or `after`: they are the page's own records.
251
+ */
252
+ describeUpdate?: (before: EntityRecord, after: EntityRecord) => LiveUpdateEntry | null | undefined
233
253
  }
234
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
+
264
+ /** The notification entry `LiveEntityPolicy.describeUpdate` asks for (#2685). */
265
+ export type LiveUpdateEntry = Omit<NewNotification, 'severity'> & Partial<Pick<NewNotification, 'severity'>>
266
+
235
267
  /**
236
268
  * EntityManager constructor options
237
269
  */
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 } 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
@@ -8,7 +8,7 @@
8
8
  * - Mobile: Full width overlay at bottom of screen
9
9
  *
10
10
  * Features:
11
- * - Inline action bar (mark read, clear, close) at top right
11
+ * - Toolbar row (mark read, clear, close) above the list
12
12
  * - Status items section (custom module items)
13
13
  * - Notification list (most recent first)
14
14
  * - Empty state
@@ -189,16 +189,15 @@ function formatTime(timestamp: number): string {
189
189
  left: calc(var(--fad-sidebar-width-collapsed, 2.5rem) + 0.375rem);
190
190
  }
191
191
 
192
- /* Inline toolbar - floats top-right inside the panel */
192
+ /* Toolbar - its own row above the list, so its buttons never cover an entry's dismiss button */
193
193
  .notification-toolbar {
194
- position: absolute;
195
- top: 0;
196
- right: 0;
197
194
  display: flex;
198
195
  align-items: center;
196
+ justify-content: flex-end;
199
197
  gap: 1px;
200
198
  padding: 0.25rem;
201
- z-index: 1;
199
+ border-bottom: 1px solid var(--p-surface-100, #f1f5f9);
200
+ flex-shrink: 0;
202
201
  }
203
202
 
204
203
  .notification-toolbar-btn {
@@ -228,7 +227,6 @@ function formatTime(timestamp: number): string {
228
227
  /* Status items */
229
228
  .notification-panel-status {
230
229
  padding: 0.5rem 0.625rem;
231
- padding-right: 2.5rem;
232
230
  border-bottom: 1px solid var(--p-surface-100, #f1f5f9);
233
231
  flex-shrink: 0;
234
232
  }
@@ -309,10 +307,6 @@ function formatTime(timestamp: number): string {
309
307
  transition: background 0.1s;
310
308
  }
311
309
 
312
- .notification-item:first-child {
313
- padding-right: 2.5rem;
314
- }
315
-
316
310
  .notification-item:hover {
317
311
  background: var(--p-surface-50, #f8fafc);
318
312
  }
@@ -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
 
@@ -175,7 +177,7 @@ export interface EntityManagerOptions<T extends EntityRecord = EntityRecord> {
175
177
  warmup?: boolean
176
178
  authSensitive?: boolean
177
179
  /** What this entity does when it changed elsewhere (#1888). */
178
- live?: { refresh?: 'mounted' | false; coalesceMs?: number }
180
+ live?: import('../entity/EntityManager.types').LiveEntityPolicy
179
181
  system?: boolean
180
182
  scopeWhitelist?: string[] | null
181
183
  isOwn?: ((record: T, user: unknown) => boolean) | null
@@ -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