@quazardous/qdadm 2.52.0 → 2.53.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.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The pill form of the generic cards (#5389): the one figure the domain bar
3
+ * keeps of each, and the count its badge shows.
4
+ */
5
+ import type { CardPill } from '../types'
6
+ import { formatNumber } from './shared'
7
+
8
+ type Opts = Record<string, unknown>
9
+ const fmt = (n: number, o: Opts, locale: string): string =>
10
+ formatNumber(n, locale, { decimals: typeof o.decimals === 'number' ? o.decimals : undefined, unit: typeof o.unit === 'string' ? o.unit : undefined })
11
+ const count = (n: unknown): number | null => (typeof n === 'number' && Number.isFinite(n) ? n : null)
12
+
13
+ export const PILLS: Record<string, (data: unknown, options: Opts, locale: string) => CardPill> = {
14
+ metric: (d, o, l) => {
15
+ const v = (d as { value: number }).value
16
+ return { value: fmt(v, o, l), count: count(v) }
17
+ },
18
+ queue: (d, _o, l) => {
19
+ const q = d as { total?: number; items: unknown[] }
20
+ const n = q.total ?? q.items.length
21
+ return { value: formatNumber(n, l), count: n }
22
+ },
23
+ goal: (d, o, l) => {
24
+ const g = d as { value: number; target: number }
25
+ return { value: `${fmt(g.value, o, l)} / ${fmt(g.target, o, l)}`, count: null }
26
+ },
27
+ compare: (d, o, l) => {
28
+ const v = (d as { now: { value: number } }).now.value
29
+ return { value: fmt(v, o, l), count: null }
30
+ },
31
+ split: (d, o, l) => {
32
+ const s = d as { total?: number; parts: Array<{ value: number }> }
33
+ const n = s.total ?? s.parts.reduce((sum, p) => sum + p.value, 0)
34
+ return { value: fmt(n, o, l), count: count(n) }
35
+ },
36
+ }
@@ -23,6 +23,7 @@ export type {
23
23
  CardOptionSheet,
24
24
  CardDefinition,
25
25
  CardBodyProps,
26
+ CardPill,
26
27
  } from './types'
27
28
 
28
29
  registerBuiltinCards()
@@ -81,6 +81,16 @@ export interface CardMeta {
81
81
  }
82
82
  }
83
83
 
84
+ /**
85
+ * A card reduced to a pill (#5389): what the domain bar shows of it. `count`
86
+ * is the badge's number, `null` when the card counts nothing.
87
+ */
88
+ export interface CardPill {
89
+ /** The value as written: "14", "68 / 100" */
90
+ value: string
91
+ count: number | null
92
+ }
93
+
84
94
  /** A card type, as registerCard takes it */
85
95
  export interface CardDefinition {
86
96
  type: string
@@ -89,6 +99,8 @@ export interface CardDefinition {
89
99
  meta: CardMeta
90
100
  /** The JSON Schema of `data` */
91
101
  schema: CardSchema
102
+ /** Its pill form, for the domain bar (#5389); without it, the type is not offered there */
103
+ pill?: (data: unknown, options: Record<string, unknown>, locale: string) => CardPill
92
104
  }
93
105
 
94
106
  /** What a body receives */
@@ -31,6 +31,7 @@ import SidebarBox from './SidebarBox.vue'
31
31
  import Zone from './Zone.vue'
32
32
  import AppBanner from './AppBanner.vue'
33
33
  import NavlinksGroup from './NavlinksGroup.vue'
34
+ import QdDomainBarZone from '../../domain/QdDomainBarZone.vue'
34
35
  import qdadmLogo from '../../assets/logo.svg'
35
36
  import { version as qdadmVersion } from '../../../package.json'
36
37
 
@@ -409,6 +410,9 @@ const showBreadcrumb = computed<boolean>(() => {
409
410
  <span class="mobile-header-title">{{ app.name }}</span>
410
411
  </div>
411
412
 
413
+ <!-- The domain's bar, on every page of a domain (#5389) -->
414
+ <QdDomainBarZone />
415
+
412
416
  <!-- Breadcrumb + Navlinks bar -->
413
417
  <div v-if="showBreadcrumb" class="layout-nav-bar">
414
418
  <Breadcrumb :model="breadcrumbItems" class="layout-breadcrumb">
@@ -34,6 +34,7 @@ import { useSlots, provide, ref } from 'vue'
34
34
  import { RouterView } from 'vue-router'
35
35
  import ConfirmDialog from 'primevue/confirmdialog'
36
36
  import Zone from './Zone.vue'
37
+ import QdDomainBarZone from '../../domain/QdDomainBarZone.vue'
37
38
  import AppBanner from './AppBanner.vue'
38
39
  import { LAYOUT_ZONES } from '../../zones/zones'
39
40
  import { useGuardDialog, GUARD_DIALOG_HOST } from '../../composables/useGuardStore'
@@ -99,6 +100,9 @@ provide('qdadmNavlinksOverride', navlinksOverride)
99
100
 
100
101
  <!-- Main content area -->
101
102
  <div class="main-area">
103
+ <!-- The domain's bar, on every page of a domain (#5389) -->
104
+ <QdDomainBarZone />
105
+
102
106
  <!-- Breadcrumb zone -->
103
107
  <Zone
104
108
  :name="LAYOUT_ZONES.BREADCRUMB"
@@ -0,0 +1,36 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * QdBadge (#5389): a number on a pill, like a notification count. Its tone
4
+ * comes from how things stand (critical, watch, or none); it hides at zero and
5
+ * says what it counts to screen readers.
6
+ */
7
+ import { computed } from 'vue'
8
+ import { useI18n } from '../i18n/useI18n'
9
+
10
+ const props = defineProps<{
11
+ count: number | null | undefined
12
+ /** What it counts, for screen readers */
13
+ title?: string
14
+ tone?: 'critical' | 'watch' | null
15
+ }>()
16
+
17
+ const { locale, tOr } = useI18n()
18
+ const shown = computed(() => typeof props.count === 'number' && props.count > 0)
19
+ const text = computed(() => {
20
+ const n = props.count ?? 0
21
+ return n > 99 ? '99+' : new Intl.NumberFormat(locale.value).format(n)
22
+ })
23
+ </script>
24
+
25
+ <template>
26
+ <span
27
+ v-if="shown"
28
+ class="qd-badge"
29
+ :class="tone ? `qd-badge--${tone}` : null"
30
+ :data-tone="tone || 'neutral'"
31
+ :title="title ? tOr('core.domainBar.badge', '{count} — {title}', { count: count!, title }) : undefined"
32
+ >
33
+ <span aria-hidden="true">{{ text }}</span>
34
+ <span class="qd-card-sr">{{ title ? tOr('core.domainBar.badge', '{count} — {title}', { count: count!, title }) : count }}</span>
35
+ </span>
36
+ </template>
@@ -0,0 +1,213 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * QdDomainBar (#5389): the bar on top of every page of a domain. Its title,
4
+ * its navigation (the current entry marked, a badge on each entry that names
5
+ * an indicator) and its indicators: mini cards, each read from its own source
6
+ * and drawn as a pill whose count is a badge.
7
+ *
8
+ * Compact: one line of icons and badges, on its own once the page scrolls, or
9
+ * by the person's choice, kept per account.
10
+ */
11
+ import { computed, onBeforeUnmount, onMounted, ref, watch, type Ref } from 'vue'
12
+ import { RouterLink, useRoute, useRouter, type RouteLocationRaw } from 'vue-router'
13
+ import { useI18n } from '../i18n/useI18n'
14
+ import { useAuth } from '../composables/useAuth'
15
+ import { useAsyncRead } from '../composables/useAsyncRead'
16
+ import { getCard, checkCardInput, resolveCardOptions } from '../cards/registry'
17
+ import type { CardStatus } from '../cards/types'
18
+ import QdBadge from './QdBadge.vue'
19
+ import { badgeTone, type DomainDefinition, type DomainIndicator, type DomainNavEntry } from './registry'
20
+
21
+ const props = defineProps<{ domain: DomainDefinition }>()
22
+
23
+ const { locale, tOr } = useI18n()
24
+ const route = useRoute()
25
+ const router = useRouter()
26
+
27
+ // ── The indicators: each its own read, its own state ──────────────────────────
28
+ interface IndicatorView {
29
+ def: DomainIndicator
30
+ /** The value says more than the badge: a unit, a target, no count, or a zero the badge hides */
31
+ showValue: boolean
32
+ state: 'loading' | 'unreachable' | 'invalid' | 'ready'
33
+ value: string
34
+ count: number | null
35
+ status: CardStatus | null
36
+ reason: string | null
37
+ }
38
+
39
+ function watchIndicator(def: DomainIndicator): Ref<IndicatorView> {
40
+ const read = def.load ? useAsyncRead(() => def.load!()) : null
41
+ let timer: ReturnType<typeof setInterval> | null = null
42
+ if (read && def.refresh && def.refresh > 0) {
43
+ onMounted(() => (timer = setInterval(() => void read.load(), def.refresh! * 1000)))
44
+ onBeforeUnmount(() => timer && clearInterval(timer))
45
+ }
46
+ return computed<IndicatorView>(() => {
47
+ const base = { def, value: '', count: null, status: null, reason: null, showValue: false }
48
+ if (read && !read.ready.value) {
49
+ return read.error.value ? { ...base, state: 'unreachable', reason: read.error.value } : { ...base, state: 'loading' }
50
+ }
51
+ const data = read ? read.data.value : def.data
52
+ const card = getCard(def.card)
53
+ if (!card?.pill) return { ...base, state: 'invalid', reason: `no card type '${def.card}' with a pill` }
54
+ const problems = checkCardInput(card, data, def.options ?? {})
55
+ if (problems.length) return { ...base, state: 'invalid', reason: problems.map((p) => `${p.path}: ${p.message}`).join('; ') }
56
+ const pill = card.pill(data, resolveCardOptions(card.meta, def.options ?? {}), locale.value)
57
+ const status = typeof def.status === 'function' ? def.status(data) ?? null : def.status ?? null
58
+ const plain = pill.count !== null && pill.count > 0 && pill.value === new Intl.NumberFormat(locale.value).format(pill.count)
59
+ return { ...base, state: 'ready', value: pill.value, count: pill.count, status, showValue: !plain }
60
+ })
61
+ }
62
+
63
+ const indicators = (props.domain.indicators ?? []).map(watchIndicator)
64
+ const byId = computed(() => new Map(indicators.map((i) => [i.value.def.id, i.value])))
65
+
66
+ // ── The navigation ────────────────────────────────────────────────────────────
67
+ function targetOf(entry: DomainNavEntry): RouteLocationRaw | null {
68
+ if (entry.to) return entry.to
69
+ if (entry.route && router.hasRoute(entry.route)) return { name: entry.route }
70
+ return null
71
+ }
72
+ const nav = computed(() =>
73
+ (props.domain.nav ?? [])
74
+ .map((entry) => ({ entry, to: targetOf(entry), badge: entry.badge ? byId.value.get(entry.badge) ?? null : null }))
75
+ .filter((n) => n.to !== null)
76
+ )
77
+ /** The current entry: the one whose route is the deepest matched one */
78
+ const current = computed(() => {
79
+ const matched = route.matched.map((r) => r.path)
80
+ let best = -1
81
+ let bestLen = -1
82
+ nav.value.forEach((n, i) => {
83
+ let path: string
84
+ try {
85
+ path = router.resolve(n.to!).matched.at(-1)?.path ?? ''
86
+ } catch {
87
+ return
88
+ }
89
+ if (!path) return
90
+ const hit = matched.some((m) => m === path || m.startsWith(path.endsWith('/') ? path : path + '/'))
91
+ if (hit && path.length > bestLen) {
92
+ best = i
93
+ bestLen = path.length
94
+ }
95
+ })
96
+ return best
97
+ })
98
+
99
+ // ── Compact ───────────────────────────────────────────────────────────────────
100
+ const { user } = useAuth()
101
+ const key = computed(() => {
102
+ const u = user.value as { id?: unknown; username?: unknown } | null
103
+ return `qdadm.domainBar.${props.domain.name}.${String(u?.id ?? u?.username ?? 'anonymous')}.compact`
104
+ })
105
+ function readChoice(): boolean {
106
+ try {
107
+ return globalThis.localStorage?.getItem(key.value) === '1'
108
+ } catch {
109
+ return false
110
+ }
111
+ }
112
+ const chosen = ref(readChoice())
113
+ watch(key, () => (chosen.value = readChoice()))
114
+ function toggle(): void {
115
+ chosen.value = !chosen.value
116
+ try {
117
+ if (chosen.value) globalThis.localStorage?.setItem(key.value, '1')
118
+ else globalThis.localStorage?.removeItem(key.value)
119
+ } catch {
120
+ // Blocked storage: the choice lasts the page
121
+ }
122
+ }
123
+
124
+ // Scrolled past the top: compact on its own, the person's choice untouched
125
+ const sentinel = ref<HTMLElement | null>(null)
126
+ const scrolled = ref(false)
127
+ let observer: IntersectionObserver | null = null
128
+ onMounted(() => {
129
+ if (typeof IntersectionObserver === 'undefined' || !sentinel.value) return
130
+ observer = new IntersectionObserver(([e]) => (scrolled.value = !!e && !e.isIntersecting))
131
+ observer.observe(sentinel.value)
132
+ })
133
+ onBeforeUnmount(() => observer?.disconnect())
134
+ const compact = computed(() => chosen.value || scrolled.value)
135
+
136
+ const label = computed(() => tOr('core.domainBar.label', '{domain}: its pages and indicators', { domain: props.domain.label }))
137
+ function pillTitle(i: IndicatorView): string {
138
+ const title = i.def.title
139
+ if (i.state === 'unreachable') return tOr('core.domainBar.unreachable', '{title}: unreachable ({error})', { title, error: i.reason ?? '' })
140
+ if (i.state === 'invalid') return tOr('core.domainBar.invalid', '{title}: data that does not fit', { title }) + (i.reason ? ` (${i.reason})` : '')
141
+ if (i.state === 'loading') return tOr('core.domainBar.loading', '{title}: loading', { title })
142
+ return `${title}: ${i.value}`
143
+ }
144
+ </script>
145
+
146
+ <template>
147
+ <div ref="sentinel" class="qd-domain-bar-sentinel" aria-hidden="true"></div>
148
+ <section
149
+ class="qd-domain-bar"
150
+ :class="{ 'qd-domain-bar--compact': compact }"
151
+ :aria-label="label"
152
+ :data-domain="domain.name"
153
+ :data-compact="compact ? (chosen ? 'chosen' : 'scrolled') : undefined"
154
+ >
155
+ <component :is="domain.to ? RouterLink : 'span'" :to="domain.to" class="qd-domain-bar-title">
156
+ <i v-if="domain.icon" :class="domain.icon" aria-hidden="true"></i>
157
+ <span class="qd-domain-bar-name">{{ domain.label }}</span>
158
+ </component>
159
+
160
+ <nav v-if="nav.length" class="qd-domain-bar-nav" :aria-label="tOr('core.domainBar.nav', '{domain} pages', { domain: domain.label })">
161
+ <RouterLink
162
+ v-for="(n, i) in nav"
163
+ :key="n.entry.label"
164
+ :to="n.to!"
165
+ class="qd-domain-bar-entry"
166
+ :class="{ 'qd-domain-bar-entry--current': i === current }"
167
+ :aria-current="i === current ? 'page' : undefined"
168
+ :title="compact ? n.entry.label : undefined"
169
+ data-domain-nav
170
+ >
171
+ <i v-if="n.entry.icon" :class="n.entry.icon" aria-hidden="true"></i>
172
+ <span class="qd-domain-bar-entry-label" :class="{ 'qd-card-sr': compact && n.entry.icon }">{{ n.entry.label }}</span>
173
+ <QdBadge v-if="n.badge && n.badge.state === 'ready'" :count="n.badge.count" :title="n.badge.def.title" :tone="badgeTone(n.badge.status)" />
174
+ </RouterLink>
175
+ </nav>
176
+
177
+ <ul v-if="indicators.length" class="qd-domain-bar-indicators" :aria-label="tOr('core.domainBar.indicators', '{domain} indicators', { domain: domain.label })">
178
+ <li
179
+ v-for="ind in indicators"
180
+ :key="ind.value.def.id"
181
+ class="qd-domain-pill"
182
+ :data-indicator="ind.value.def.id"
183
+ :data-state="ind.value.state"
184
+ :data-status="ind.value.status || undefined"
185
+ :title="pillTitle(ind.value)"
186
+ >
187
+ <component :is="ind.value.def.to ? RouterLink : 'span'" :to="ind.value.def.to" class="qd-domain-pill-body">
188
+ <i v-if="ind.value.def.icon" :class="ind.value.def.icon" aria-hidden="true"></i>
189
+ <span class="qd-domain-pill-title" :class="{ 'qd-card-sr': compact && ind.value.def.icon }">{{ ind.value.def.title }}</span>
190
+ <template v-if="ind.value.state === 'ready'">
191
+ <QdBadge v-if="ind.value.count !== null" :count="ind.value.count" :title="ind.value.def.title" :tone="badgeTone(ind.value.status)" />
192
+ <span v-if="ind.value.showValue" class="qd-domain-pill-value" :class="{ 'qd-domain-pill-value--zero': ind.value.count === 0 }">{{ ind.value.value }}</span>
193
+ </template>
194
+ <i v-else-if="ind.value.state === 'loading'" class="pi pi-spin pi-spinner qd-domain-pill-mark" aria-hidden="true"></i>
195
+ <i v-else class="pi pi-exclamation-triangle qd-domain-pill-mark" aria-hidden="true"></i>
196
+ <span v-if="ind.value.state !== 'ready'" class="qd-card-sr">{{ pillTitle(ind.value) }}</span>
197
+ </component>
198
+ </li>
199
+ </ul>
200
+
201
+ <button
202
+ type="button"
203
+ class="qd-domain-bar-toggle"
204
+ :aria-pressed="chosen ? 'true' : 'false'"
205
+ :aria-label="chosen ? tOr('core.domainBar.expand', 'Full bar') : tOr('core.domainBar.compact', 'Compact bar')"
206
+ :title="chosen ? tOr('core.domainBar.expand', 'Full bar') : tOr('core.domainBar.compact', 'Compact bar')"
207
+ data-domain-toggle
208
+ @click="toggle"
209
+ >
210
+ <i :class="chosen ? 'pi pi-window-maximize' : 'pi pi-window-minimize'" aria-hidden="true"></i>
211
+ </button>
212
+ </section>
213
+ </template>
@@ -0,0 +1,19 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Where the layouts draw the domain bar (#5389): the `_app:domain-bar` zone,
4
+ * on the pages of a domain only, with QdDomainBar as its default. An app
5
+ * replaces it with a block in that zone; the block receives `domain`.
6
+ */
7
+ import { computed } from 'vue'
8
+ import { useRoute } from 'vue-router'
9
+ import Zone from '../components/layout/Zone.vue'
10
+ import QdDomainBar from './QdDomainBar.vue'
11
+ import { domainOfRoute } from './registry'
12
+
13
+ const route = useRoute()
14
+ const domain = computed(() => domainOfRoute(route))
15
+ </script>
16
+
17
+ <template>
18
+ <Zone v-if="domain" :key="domain.name" class="qd-domain-bar-zone" name="_app:domain-bar" :default-component="QdDomainBar" :block-props="{ domain }" />
19
+ </template>
@@ -0,0 +1,6 @@
1
+ /** Domains and their bar (#5389) */
2
+ export { default as QdDomainBar } from './QdDomainBar.vue'
3
+ export { default as QdDomainBarZone } from './QdDomainBarZone.vue'
4
+ export { default as QdBadge } from './QdBadge.vue'
5
+ export { registerDomain, getDomain, listDomains, domainOfRoute, badgeTone } from './registry'
6
+ export type { DomainConfig, DomainDefinition, DomainIndicator, DomainNavEntry } from './registry'
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Domains (#5389): a part of the app with a bar of its own on top of every
3
+ * one of its pages: its navigation and a row of indicators, mini cards each
4
+ * read from its own source, their counts as badges.
5
+ *
6
+ * A page belongs to a domain:
7
+ * 1. when its route says so (`meta.domain`);
8
+ * 2. when its entity is one the domain lists (`entities`), from any module;
9
+ * 3. when the module that declared the domain declared the route too.
10
+ */
11
+ import type { RouteLocationNormalizedLoaded, RouteLocationRaw } from 'vue-router'
12
+ import type { CardStatus } from '../cards/types'
13
+
14
+ /** One permanent indicator: a card of a registered type, drawn as a pill */
15
+ export interface DomainIndicator {
16
+ /** Named by the nav entries that show its badge */
17
+ id: string
18
+ /** The card type (metric, queue, goal, compare, split, or one of the app's) */
19
+ card: string
20
+ /** Its name, read beside the pill and by screen readers */
21
+ title: string
22
+ icon?: string
23
+ /** The data, as the card type takes it */
24
+ data?: unknown
25
+ /** Or read it: called at once, then every `refresh` seconds */
26
+ load?: () => unknown | Promise<unknown>
27
+ /** Seconds between two reads (default: none) */
28
+ refresh?: number
29
+ /** The card type's options */
30
+ options?: Record<string, unknown>
31
+ /** How things stand: fixed, or from the data */
32
+ status?: CardStatus | ((data: unknown) => CardStatus | undefined | null)
33
+ /** Where the pill leads */
34
+ to?: RouteLocationRaw
35
+ }
36
+
37
+ /** One entry of the domain's navigation */
38
+ export interface DomainNavEntry {
39
+ label: string
40
+ icon?: string
41
+ /** A route name, or `to` */
42
+ route?: string
43
+ to?: RouteLocationRaw
44
+ /** The id of the indicator whose count shows as this entry's badge */
45
+ badge?: string
46
+ }
47
+
48
+ /** What `ctx.domain(name, …)` declares */
49
+ export interface DomainConfig {
50
+ label: string
51
+ icon?: string
52
+ /** Where the domain's title leads (its board) */
53
+ to?: RouteLocationRaw
54
+ nav?: DomainNavEntry[]
55
+ indicators?: DomainIndicator[]
56
+ /** Entities of other modules whose pages join the domain */
57
+ entities?: string[]
58
+ }
59
+
60
+ export interface DomainDefinition extends DomainConfig {
61
+ name: string
62
+ /** The module that declared it: its routes join the domain */
63
+ module: string | null
64
+ }
65
+
66
+ const domains = new Map<string, DomainDefinition>()
67
+
68
+ export function registerDomain(name: string, config: DomainConfig, module: string | null = null): void {
69
+ if (!name) throw new Error('[qdadm] domain: a domain needs a name')
70
+ if (domains.has(name)) console.warn(`[qdadm] domain('${name}'): replaces the domain already declared`)
71
+ const ids = new Set<string>()
72
+ for (const i of config.indicators ?? []) {
73
+ if (ids.has(i.id)) console.warn(`[qdadm] domain('${name}'): two indicators are named '${i.id}'`)
74
+ ids.add(i.id)
75
+ }
76
+ for (const n of config.nav ?? []) {
77
+ if (n.badge && !ids.has(n.badge)) console.warn(`[qdadm] domain('${name}'): the entry '${n.label}' shows the badge of '${n.badge}', which no indicator is`)
78
+ }
79
+ domains.set(name, { ...config, name, module })
80
+ }
81
+
82
+ export function getDomain(name: string): DomainDefinition | null {
83
+ return domains.get(name) ?? null
84
+ }
85
+
86
+ export function listDomains(): DomainDefinition[] {
87
+ return [...domains.values()]
88
+ }
89
+
90
+ /** Tests only */
91
+ export function resetDomains(): void {
92
+ domains.clear()
93
+ }
94
+
95
+ type RouteLike = Pick<RouteLocationNormalizedLoaded, 'meta' | 'matched'>
96
+
97
+ /**
98
+ * The domain a route belongs to, or null. `meta.domain: false` keeps a page
99
+ * out of its module's domain.
100
+ */
101
+ export function domainOfRoute(route: RouteLike | null | undefined): DomainDefinition | null {
102
+ if (!route || domains.size === 0) return null
103
+ const meta = route.meta ?? {}
104
+ if (meta.domain === false) return null
105
+ if (typeof meta.domain === 'string') return getDomain(meta.domain)
106
+ const entity = typeof meta.entity === 'string' ? meta.entity : null
107
+ if (entity) {
108
+ for (const d of domains.values()) if (d.entities?.includes(entity)) return d
109
+ }
110
+ // The deepest matched route with a module wins (a frame route's children carry theirs)
111
+ const modules = (route.matched ?? []).map((r) => r.meta?.module).filter((m): m is string => typeof m === 'string')
112
+ const module = modules.at(-1) ?? (typeof meta.module === 'string' ? meta.module : null)
113
+ if (module) {
114
+ for (const d of domains.values()) if (d.module === module) return d
115
+ }
116
+ return null
117
+ }
118
+
119
+ /** The tone of a badge: only bad news is coloured */
120
+ export function badgeTone(status: CardStatus | null | undefined): 'critical' | 'watch' | null {
121
+ return status === 'critical' || status === 'watch' ? status : null
122
+ }
@@ -511,6 +511,17 @@ export default `core:
511
511
  change: "{change} on the period before"
512
512
  same: Same as the period before
513
513
  timelineBars: "Volume from {from} to {to}"
514
+ # The domain bar (#5389)
515
+ domainBar:
516
+ label: "{domain}: its pages and indicators"
517
+ nav: "{domain} pages"
518
+ indicators: "{domain} indicators"
519
+ compact: Compact bar
520
+ expand: Full bar
521
+ badge: "{count} — {title}"
522
+ unreachable: "{title}: unreachable ({error})"
523
+ invalid: "{title}: data that does not fit"
524
+ loading: "{title}: loading"
514
525
  # NotFoundPage
515
526
  notFound:
516
527
  title: Page not found
@@ -509,6 +509,17 @@ core:
509
509
  change: "{change} on the period before"
510
510
  same: Same as the period before
511
511
  timelineBars: "Volume from {from} to {to}"
512
+ # The domain bar (#5389)
513
+ domainBar:
514
+ label: "{domain}: its pages and indicators"
515
+ nav: "{domain} pages"
516
+ indicators: "{domain} indicators"
517
+ compact: Compact bar
518
+ expand: Full bar
519
+ badge: "{count} — {title}"
520
+ unreachable: "{title}: unreachable ({error})"
521
+ invalid: "{title}: data that does not fit"
522
+ loading: "{title}: loading"
512
523
  # NotFoundPage
513
524
  notFound:
514
525
  title: Page not found
@@ -511,6 +511,17 @@ export default `core:
511
511
  change: "{change} sur la période précédente"
512
512
  same: Autant que la période précédente
513
513
  timelineBars: "Volume du {from} au {to}"
514
+ # Le cartouche de domaine (#5389)
515
+ domainBar:
516
+ label: "{domain} : ses pages et ses indicateurs"
517
+ nav: "Pages de {domain}"
518
+ indicators: "Indicateurs de {domain}"
519
+ compact: Cartouche compact
520
+ expand: Cartouche complet
521
+ badge: "{count} — {title}"
522
+ unreachable: "{title} : injoignable ({error})"
523
+ invalid: "{title} : données qui ne correspondent pas"
524
+ loading: "{title} : chargement"
514
525
  # NotFoundPage
515
526
  notFound:
516
527
  title: Page introuvable
@@ -509,6 +509,17 @@ core:
509
509
  change: "{change} sur la période précédente"
510
510
  same: Autant que la période précédente
511
511
  timelineBars: "Volume du {from} au {to}"
512
+ # Le cartouche de domaine (#5389)
513
+ domainBar:
514
+ label: "{domain} : ses pages et ses indicateurs"
515
+ nav: "Pages de {domain}"
516
+ indicators: "Indicateurs de {domain}"
517
+ compact: Cartouche compact
518
+ expand: Cartouche complet
519
+ badge: "{count} — {title}"
520
+ unreachable: "{title} : injoignable ({error})"
521
+ invalid: "{title} : données qui ne correspondent pas"
522
+ loading: "{title} : chargement"
512
523
  # NotFoundPage
513
524
  notFound:
514
525
  title: Page introuvable
package/src/index.ts CHANGED
@@ -462,6 +462,7 @@ export * from './cards/index'
462
462
  export * from './run/index'
463
463
  export * from './favorites/index'
464
464
  export * from './board/index'
465
+ export * from './domain/index'
465
466
  export { useTaskRunner, taskAction } from './tasks/useTaskRunner'
466
467
  export { useTaskNotifications, useTaskTrayVisible, type TasksConfig } from './tasks/useTaskNotifications'
467
468
  export {
@@ -18,6 +18,7 @@ import type { ItemTabsOptions } from '../module/moduleRegistry'
18
18
  import type { RouteRecordRaw } from 'vue-router'
19
19
  import pluralize from '../utils/pluralize'
20
20
  import { registry, getRoutes } from '../module/moduleRegistry'
21
+ import { registerDomain, type DomainConfig } from '../domain/registry'
21
22
  import type {
22
23
  ChildPageOptions,
23
24
  CrudOptions,
@@ -150,7 +151,15 @@ export function applyRoutingMethods(KernelContextClass: { prototype: KernelConte
150
151
  routes: RouteRecordRaw[],
151
152
  opts: RouteOptions = {}
152
153
  ): Self {
153
- registry.addRoutes(basePath, routes, opts)
154
+ // Each route knows its module, so a domain the module declares finds its pages (#5389)
155
+ const module = this._module?.name
156
+ const tagged = module ? routes.map((r) => ({ ...r, meta: { module, ...r.meta } }) as RouteRecordRaw) : routes
157
+ registry.addRoutes(basePath, tagged, opts)
158
+ return this
159
+ }
160
+
161
+ proto.domain = function (this: Self, name: string, config: DomainConfig): Self {
162
+ registerDomain(name, config, this._module?.name ?? null)
154
163
  return this
155
164
  }
156
165
 
@@ -36,6 +36,7 @@
36
36
  */
37
37
 
38
38
  import type { ItemTabsOptions } from '../module/moduleRegistry'
39
+ import type { DomainConfig } from '../domain/registry'
39
40
  import type { App, Component } from 'vue'
40
41
  import type { Router, RouteRecordRaw } from 'vue-router'
41
42
  import type { ListenerOptions } from '@quazardous/quarkernel'
@@ -210,6 +211,12 @@ export interface KernelContext {
210
211
  childPage(parentRouteName: string, pageName: string, options: ChildPageOptions): this
211
212
  /** Show an entity's item as tabs: its header, a tab per page of the item, the page below (#4963) */
212
213
  itemTabs(entity: string, options?: ItemTabsOptions): this
214
+ /**
215
+ * A domain (#5389): a bar on top of each of its pages, with its navigation
216
+ * and its indicators. Its pages: this module's routes, the pages of the
217
+ * entities it lists, and any route whose `meta.domain` names it.
218
+ */
219
+ domain(name: string, config: DomainConfig): this
213
220
 
214
221
  // Zones / Vue (KernelContext.zones.ts)
215
222
  zone(name: string, options?: ZoneOptions): this
@@ -28,6 +28,8 @@ import type { RouteParamResolverContext } from './KernelContext.routing'
28
28
 
29
29
  /** Extended Module interface with internal cleanup method */
30
30
  export interface ModuleWithCleanup {
31
+ /** The module's name (Module.name); routes are tagged with it (#5389) */
32
+ name?: string
31
33
  constructor?: { name?: string }
32
34
  _addSignalCleanup?: (cleanup: () => void) => void
33
35
  }
@@ -52,6 +52,10 @@ export interface ModuleRouteMeta {
52
52
  title?: string
53
53
  /** Who may open the page (#4332): enforced by the router guard; a list needs every entry */
54
54
  permission?: string | string[]
55
+ /** The module that declared the route (#5389), set by ctx.routes() */
56
+ module?: string
57
+ /** The domain whose bar the page shows (#5389); false: none, even its module's */
58
+ domain?: string | false
55
59
  [key: string]: unknown
56
60
  }
57
61