@quazardous/qdadm 2.51.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.
Files changed (129) hide show
  1. package/dist/node/cards/tools/cardsTool.d.ts +32 -0
  2. package/dist/node/cards/tools/cardsTool.js +151 -0
  3. package/dist/node/cards/tools/cli.d.ts +2 -0
  4. package/dist/node/cards/tools/cli.js +38 -0
  5. package/dist/node/cards/validate.d.ts +35 -0
  6. package/dist/node/cards/validate.js +94 -0
  7. package/dist/styles/qdadm.css +1 -1
  8. package/package.json +7 -2
  9. package/src/board/QdBoardBlock.vue +67 -0
  10. package/src/board/QdDomainBoard.vue +64 -0
  11. package/src/board/blocks/BreakdownBlock.vue +44 -0
  12. package/src/board/blocks/KpiBlock.vue +31 -0
  13. package/src/board/blocks/TimelineBlock.vue +63 -0
  14. package/src/board/blocks/TopBlock.vue +57 -0
  15. package/src/board/blocks/schemas.ts +107 -0
  16. package/src/board/index.ts +31 -0
  17. package/src/board/registry.ts +33 -0
  18. package/src/board/types.ts +32 -0
  19. package/src/cards/QdCard.vue +175 -0
  20. package/src/cards/QdCardView.vue +53 -0
  21. package/src/cards/QdCardsGallery.vue +103 -0
  22. package/src/cards/QdFavoritesCard.vue +50 -0
  23. package/src/cards/QdRecentCard.vue +44 -0
  24. package/src/cards/builtin/agenda/AgendaCard.vue +37 -0
  25. package/src/cards/builtin/agenda/meta.json +60 -0
  26. package/src/cards/builtin/agenda/schema.json +48 -0
  27. package/src/cards/builtin/bullet/BulletCard.vue +76 -0
  28. package/src/cards/builtin/bullet/meta.json +38 -0
  29. package/src/cards/builtin/bullet/schema.json +18 -0
  30. package/src/cards/builtin/cards-index.json +1694 -0
  31. package/src/cards/builtin/compare/CompareCard.vue +47 -0
  32. package/src/cards/builtin/compare/meta.json +79 -0
  33. package/src/cards/builtin/compare/schema.json +40 -0
  34. package/src/cards/builtin/favorites/FavoritesCard.vue +50 -0
  35. package/src/cards/builtin/favorites/meta.json +33 -0
  36. package/src/cards/builtin/favorites/schema.json +20 -0
  37. package/src/cards/builtin/feed/FeedCard.vue +39 -0
  38. package/src/cards/builtin/feed/meta.json +64 -0
  39. package/src/cards/builtin/feed/schema.json +54 -0
  40. package/src/cards/builtin/funnel/FunnelCard.vue +44 -0
  41. package/src/cards/builtin/funnel/meta.json +53 -0
  42. package/src/cards/builtin/funnel/schema.json +37 -0
  43. package/src/cards/builtin/goal/GoalCard.vue +73 -0
  44. package/src/cards/builtin/goal/meta.json +43 -0
  45. package/src/cards/builtin/goal/schema.json +12 -0
  46. package/src/cards/builtin/heat/HeatCard.vue +46 -0
  47. package/src/cards/builtin/heat/meta.json +101 -0
  48. package/src/cards/builtin/heat/schema.json +39 -0
  49. package/src/cards/builtin/index.ts +71 -0
  50. package/src/cards/builtin/metric/MetricCard.vue +82 -0
  51. package/src/cards/builtin/metric/meta.json +109 -0
  52. package/src/cards/builtin/metric/schema.json +35 -0
  53. package/src/cards/builtin/pills.ts +36 -0
  54. package/src/cards/builtin/queue/QueueCard.vue +65 -0
  55. package/src/cards/builtin/queue/meta.json +47 -0
  56. package/src/cards/builtin/queue/schema.json +32 -0
  57. package/src/cards/builtin/ranking/RankingCard.vue +37 -0
  58. package/src/cards/builtin/ranking/meta.json +71 -0
  59. package/src/cards/builtin/ranking/schema.json +35 -0
  60. package/src/cards/builtin/recent/RecentCard.vue +41 -0
  61. package/src/cards/builtin/recent/meta.json +32 -0
  62. package/src/cards/builtin/recent/schema.json +21 -0
  63. package/src/cards/builtin/shared.ts +83 -0
  64. package/src/cards/builtin/split/SplitCard.vue +52 -0
  65. package/src/cards/builtin/split/meta.json +72 -0
  66. package/src/cards/builtin/split/schema.json +40 -0
  67. package/src/cards/builtin/trend/TrendCard.vue +75 -0
  68. package/src/cards/builtin/trend/meta.json +81 -0
  69. package/src/cards/builtin/trend/schema.json +58 -0
  70. package/src/cards/index.ts +29 -0
  71. package/src/cards/registry.ts +57 -0
  72. package/src/cards/tools/cardsTool.ts +181 -0
  73. package/src/cards/tools/cli.ts +35 -0
  74. package/src/cards/types.ts +111 -0
  75. package/src/cards/validate.ts +111 -0
  76. package/src/components/edit/FormActions.vue +9 -5
  77. package/src/components/edit/FormPage.vue +17 -2
  78. package/src/components/layout/AppLayout.vue +4 -0
  79. package/src/components/layout/BaseLayout.vue +4 -0
  80. package/src/components/layout/CardParamsForm.vue +157 -0
  81. package/src/components/layout/CardsDashboard.vue +276 -57
  82. package/src/components/layout/PageHeader.vue +22 -1
  83. package/src/components/layout/QdFavoriteStar.vue +71 -0
  84. package/src/components/layout/Zone.vue +2 -1
  85. package/src/components/lists/ListPage.vue +9 -1
  86. package/src/components/lists/QdSaveSearch.vue +79 -0
  87. package/src/components/pages/NotFoundPage.vue +5 -2
  88. package/src/components/run/QdRunBar.vue +99 -0
  89. package/src/components/show/ShowPage.vue +10 -1
  90. package/src/composables/useBreadcrumb.ts +1 -1
  91. package/src/composables/useCardsArrangement.ts +297 -27
  92. package/src/composables/useEntityItemFormPage.ts +39 -3
  93. package/src/composables/useEntityItemFormPage.types.ts +8 -0
  94. package/src/composables/useEntityItemShowPage.ts +22 -0
  95. package/src/composables/useListPage.ts +71 -0
  96. package/src/composables/useListPage.types.ts +6 -0
  97. package/src/composables/useUnsavedChangesGuard.ts +17 -1
  98. package/src/domain/QdBadge.vue +36 -0
  99. package/src/domain/QdDomainBar.vue +213 -0
  100. package/src/domain/QdDomainBarZone.vue +19 -0
  101. package/src/domain/index.ts +6 -0
  102. package/src/domain/registry.ts +122 -0
  103. package/src/favorites/index.ts +7 -0
  104. package/src/favorites/store.ts +172 -0
  105. package/src/favorites/useFavorites.ts +217 -0
  106. package/src/i18n/defaults/core.en.generated.ts +132 -0
  107. package/src/i18n/defaults/core.en.yml +132 -0
  108. package/src/i18n/defaults/core.fr.generated.ts +132 -0
  109. package/src/i18n/defaults/core.fr.yml +132 -0
  110. package/src/index.ts +23 -0
  111. package/src/kernel/Kernel.routing.ts +4 -15
  112. package/src/kernel/Kernel.types.ts +5 -1
  113. package/src/kernel/Kernel.vue.ts +2 -2
  114. package/src/kernel/KernelContext.routing.ts +10 -1
  115. package/src/kernel/KernelContext.ts +7 -0
  116. package/src/kernel/KernelContext.types.ts +2 -0
  117. package/src/kernel/homeRoute.ts +45 -0
  118. package/src/module/moduleRegistry.ts +4 -0
  119. package/src/run/index.ts +6 -0
  120. package/src/run/run.ts +162 -0
  121. package/src/run/useRun.ts +207 -0
  122. package/src/styles/_cards-dashboard.scss +190 -0
  123. package/src/styles/_qd-board.scss +359 -0
  124. package/src/styles/_qd-cards.scss +1197 -0
  125. package/src/styles/_qd-domain-bar.scss +159 -0
  126. package/src/styles/_qd-run.scss +135 -0
  127. package/src/styles/index.scss +4 -0
  128. package/src/zones/ZoneRegistry.ts +16 -0
  129. package/src/zones/index.ts +1 -0
@@ -0,0 +1,53 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * QdCardView - a registered card type in its envelope (#5339)
4
+ *
5
+ * <QdCardView type="metric" :envelope="{ title: 'Retours ouverts', status: 'watch', source: 'sav' }"
6
+ * :data="{ value: 23, delta: { value: 4, period: 'sem.' }, series }" :options="{ higherIs: 'worse' }" />
7
+ *
8
+ * The data and the options are checked against the type's schema and sheet
9
+ * first: what does not fit draws the `invalid` state with its reasons, and the
10
+ * board around it keeps working. An unknown type is `invalid` too.
11
+ */
12
+ import { computed } from 'vue'
13
+ import QdCard from './QdCard.vue'
14
+ import { getCard, checkCardInput, resolveCardOptions } from './registry'
15
+ import type { CardEnvelope } from './types'
16
+ import type { SchemaProblem } from './validate'
17
+
18
+ const props = withDefaults(
19
+ defineProps<{
20
+ type: string
21
+ envelope: CardEnvelope
22
+ data?: unknown
23
+ options?: Record<string, unknown>
24
+ }>(),
25
+ { data: undefined, options: () => ({}) }
26
+ )
27
+
28
+ const definition = computed(() => getCard(props.type))
29
+ const state = computed(() => props.envelope.state ?? 'ready')
30
+
31
+ const problems = computed<SchemaProblem[]>(() => {
32
+ if (!definition.value) return [{ path: 'type', message: `no card of type '${props.type}' is registered` }]
33
+ // Only data that is meant to be drawn is checked
34
+ if (state.value !== 'ready') return []
35
+ return checkCardInput(definition.value, props.data, props.options)
36
+ })
37
+
38
+ const shownState = computed(() => (problems.value.length ? 'invalid' : state.value))
39
+ const options = computed(() => (definition.value ? resolveCardOptions(definition.value.meta, props.options) : {}))
40
+ const size = computed(() => props.envelope.size ?? definition.value?.meta.sizes[0] ?? 's')
41
+ </script>
42
+
43
+ <template>
44
+ <QdCard
45
+ v-bind="envelope"
46
+ :size="size"
47
+ :state="shownState"
48
+ :problems="problems"
49
+ :data-card-type="type"
50
+ >
51
+ <component :is="definition!.component" v-if="definition" :data="data" :options="options" :size="size" />
52
+ </QdCard>
53
+ </template>
@@ -0,0 +1,103 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * QdCardsGallery - every registered card, in each state, size and theme (#5339)
4
+ *
5
+ * The reference for the look: mount it on a route of the app (the demo's
6
+ * /cards) and every card registered, qdadm's and the app's, shows from its
7
+ * sheet's example. Each tile carries data-gallery-* attributes, so a script
8
+ * can capture them one by one.
9
+ *
10
+ * <QdCardsGallery /> // all cards, light and dark
11
+ * <QdCardsGallery :types="['metric']" :themes="['light']" />
12
+ */
13
+ import { computed } from 'vue'
14
+ import QdCardView from './QdCardView.vue'
15
+ import { listCards } from './registry'
16
+ import { useI18n } from '../i18n/useI18n'
17
+ import type { CardDefinition, CardEnvelope, CardState } from './types'
18
+
19
+ const props = withDefaults(
20
+ defineProps<{
21
+ types?: string[] | null
22
+ themes?: Array<'light' | 'dark'>
23
+ /** Show the sheet (question, readings) above each card */
24
+ sheets?: boolean
25
+ }>(),
26
+ { types: null, themes: () => ['light', 'dark'], sheets: true }
27
+ )
28
+
29
+ const { t } = useI18n()
30
+
31
+ const cards = computed<CardDefinition[]>(() => listCards().filter((c) => !props.types || props.types.includes(c.type)))
32
+ const STATES: CardState[] = ['loading', 'unreachable', 'empty', 'invalid']
33
+
34
+ /** The example's envelope, read a few minutes ago, at this size and state */
35
+ function envelope(card: CardDefinition, patch: Partial<CardEnvelope>): CardEnvelope {
36
+ return { ...card.meta.example.envelope, freshness: new Date(Date.now() - 3 * 60_000), ...patch }
37
+ }
38
+ </script>
39
+
40
+ <template>
41
+ <div class="qd-cards-gallery">
42
+ <section v-for="card in cards" :key="card.type" class="qd-gallery-card" :id="`card-${card.type}`">
43
+ <header v-if="sheets" class="qd-gallery-sheet">
44
+ <h2><code>{{ card.type }}</code> {{ card.meta.question }}</h2>
45
+ <ul>
46
+ <li v-for="(r, i) in card.meta.readings" :key="i">{{ r }}</li>
47
+ </ul>
48
+ </header>
49
+
50
+ <div
51
+ v-for="theme in themes"
52
+ :key="theme"
53
+ class="qd-gallery-theme"
54
+ :class="{ 'dark-mode': theme === 'dark' }"
55
+ :data-gallery-theme="theme"
56
+ >
57
+ <div class="qd-gallery-row">
58
+ <div
59
+ v-for="size in card.meta.sizes"
60
+ :key="size"
61
+ class="qd-gallery-tile"
62
+ :style="{ '--qd-gallery-span': { s: 1, m: 2, l: 3 }[size] }"
63
+ :data-gallery-card="card.type"
64
+ data-gallery-state="ready"
65
+ :data-gallery-size="size"
66
+ >
67
+ <span class="qd-gallery-label">{{ size }}</span>
68
+ <QdCardView
69
+ :type="card.type"
70
+ :envelope="envelope(card, { size, state: 'ready' })"
71
+ :data="card.meta.example.data"
72
+ :options="card.meta.example.options"
73
+ />
74
+ </div>
75
+ </div>
76
+ <div class="qd-gallery-row">
77
+ <div
78
+ v-for="state in STATES"
79
+ :key="state"
80
+ class="qd-gallery-tile"
81
+ :data-gallery-card="card.type"
82
+ :data-gallery-state="state"
83
+ data-gallery-size="s"
84
+ >
85
+ <span class="qd-gallery-label">{{ state }}</span>
86
+ <QdCardView
87
+ :type="card.type"
88
+ :envelope="
89
+ envelope(card, {
90
+ size: 's',
91
+ state: state === 'invalid' ? 'ready' : state,
92
+ error: state === 'unreachable' ? t('core.cards.galleryUnreachable') : undefined,
93
+ })
94
+ "
95
+ :data="state === 'invalid' ? { value: 'twelve' } : card.meta.example.data"
96
+ :options="card.meta.example.options"
97
+ />
98
+ </div>
99
+ </div>
100
+ </div>
101
+ </section>
102
+ </div>
103
+ </template>
@@ -0,0 +1,50 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * QdFavoritesCard (#5349): the person's favourites, live. A star clicked in
4
+ * a page header, a search saved, show here at once.
5
+ *
6
+ * ctx.block(DASHBOARD_ZONES.WIDGETS, { id: 'favorites', component: QdFavoritesCard, card: { title: 'Favourites' } })
7
+ */
8
+ import { computed, onMounted } from 'vue'
9
+ import QdCardView from './QdCardView.vue'
10
+ import { useI18n } from '../i18n/useI18n'
11
+ import { useFavorites } from '../favorites/useFavorites'
12
+ import type { CardSize } from './types'
13
+
14
+ const props = withDefaults(defineProps<{ title?: string | null; size?: CardSize; maxItems?: number; groupByKind?: boolean }>(), {
15
+ title: null,
16
+ size: 's',
17
+ maxItems: 8,
18
+ groupByKind: true,
19
+ })
20
+ const { tOr } = useI18n()
21
+ const favorites = useFavorites()
22
+ // Read again when it shows: another tab or a page may have changed them
23
+ onMounted(() => void favorites.reload())
24
+
25
+ const envelope = computed(() => ({
26
+ title: props.title ?? tOr('core.favorites.title', 'Favourites'),
27
+ size: props.size,
28
+ state: !favorites.available
29
+ ? ('empty' as const)
30
+ : !favorites.loaded.value
31
+ ? ('loading' as const)
32
+ : favorites.error.value && !favorites.list.value.length
33
+ ? ('unreachable' as const)
34
+ : favorites.list.value.length
35
+ ? ('ready' as const)
36
+ : ('empty' as const),
37
+ error: favorites.error.value ?? undefined,
38
+ emptyText: favorites.available
39
+ ? tOr('core.favorites.none', 'No favourites yet: the star beside a page title adds one')
40
+ : tOr('core.favorites.noEntity', 'No favorites entity is declared'),
41
+ }))
42
+ const data = computed(() => ({
43
+ // The latest first
44
+ items: [...favorites.list.value].reverse().map((f) => ({ label: f.label, to: f.to, kind: f.kind })),
45
+ }))
46
+ </script>
47
+
48
+ <template>
49
+ <QdCardView type="favorites" :envelope="envelope" :data="data" :options="{ maxItems, groupByKind }" />
50
+ </template>
@@ -0,0 +1,44 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * QdRecentCard (#5349): the records the person opened lately, live.
4
+ *
5
+ * ctx.block(DASHBOARD_ZONES.WIDGETS, { id: 'recent', component: QdRecentCard, card: { title: 'Recent' } })
6
+ */
7
+ import { computed, inject, onMounted } from 'vue'
8
+ import QdCardView from './QdCardView.vue'
9
+ import { useI18n } from '../i18n/useI18n'
10
+ import { useRecent } from '../favorites/useFavorites'
11
+ import type { CardSize } from './types'
12
+
13
+ const props = withDefaults(defineProps<{ title?: string | null; size?: CardSize; maxItems?: number }>(), { title: null, size: 's', maxItems: 5 })
14
+ const { tOr } = useI18n()
15
+ const recent = useRecent()
16
+ onMounted(() => void recent.reload())
17
+ const orchestrator = inject<{ get?: (name: string) => { label?: string } | undefined } | null>('qdadmOrchestrator', null)
18
+
19
+ const envelope = computed(() => ({
20
+ title: props.title ?? tOr('core.favorites.recentTitle', 'Recent'),
21
+ size: props.size,
22
+ state: !recent.available
23
+ ? ('empty' as const)
24
+ : !recent.loaded.value
25
+ ? ('loading' as const)
26
+ : recent.error.value && !recent.list.value.length
27
+ ? ('unreachable' as const)
28
+ : recent.list.value.length
29
+ ? ('ready' as const)
30
+ : ('empty' as const),
31
+ error: recent.error.value ?? undefined,
32
+ emptyText: recent.available ? tOr('core.favorites.noneRecent', 'Nothing opened yet') : tOr('core.favorites.noRecentsEntity', 'No recents entity is declared'),
33
+ }))
34
+ const data = computed(() => ({
35
+ items: recent.list.value.map((r) => {
36
+ const note = orchestrator?.get?.(r.entity)?.label
37
+ return { label: r.label, to: r.to, at: r.at, ...(note ? { note } : {}) }
38
+ }),
39
+ }))
40
+ </script>
41
+
42
+ <template>
43
+ <QdCardView type="recent" :envelope="envelope" :data="data" :options="{ maxItems }" />
44
+ </template>
@@ -0,0 +1,37 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * agenda - what is coming? (#5355)
4
+ *
5
+ * Dated lines, the first ones first: a time for today, "tomorrow", else a
6
+ * date; each line opens its item. See meta.json for the sheet.
7
+ */
8
+ import { computed } from 'vue'
9
+ import { RouterLink, type RouteLocationRaw } from 'vue-router'
10
+ import { useI18n } from '../../../i18n/useI18n'
11
+ import { dayWords } from '../shared'
12
+ import type { CardSize } from '../../types'
13
+
14
+ const props = defineProps<{
15
+ data: { now?: string | number; items: Array<{ at: string | number; label: string; to?: RouteLocationRaw; allDay?: boolean }> }
16
+ options: { maxItems?: number }
17
+ size: CardSize
18
+ }>()
19
+ const { t, locale } = useI18n()
20
+
21
+ const lines = computed(() => {
22
+ const now = props.data.now !== undefined ? new Date(props.data.now) : new Date()
23
+ return [...props.data.items]
24
+ .sort((a, b) => new Date(a.at).getTime() - new Date(b.at).getTime())
25
+ .slice(0, props.options.maxItems ?? 4)
26
+ .map((item) => ({ ...item, ...dayWords(new Date(item.at), now, locale.value, t, !item.allDay) }))
27
+ })
28
+ </script>
29
+
30
+ <template>
31
+ <ul class="qd-agenda">
32
+ <li v-for="(line, i) in lines" :key="i" class="qd-agenda-item">
33
+ <time class="qd-agenda-when" :datetime="line.iso" :title="line.full">{{ line.when }}</time>
34
+ <component :is="line.to ? RouterLink : 'span'" :to="line.to" class="qd-agenda-label">{{ line.label }}</component>
35
+ </li>
36
+ </ul>
37
+ </template>
@@ -0,0 +1,60 @@
1
+ {
2
+ "type": "agenda",
3
+ "title": "Agenda",
4
+ "question": "What is coming?",
5
+ "readings": [
6
+ "each line: when (a time today, \"tomorrow\", a date) and what",
7
+ "the first ones first"
8
+ ],
9
+ "strengths": [
10
+ "what to get ready for, in the order it comes",
11
+ "each line opens its item"
12
+ ],
13
+ "avoid": [
14
+ "for what already happened: use feed",
15
+ "for items to process now: use queue"
16
+ ],
17
+ "sizes": [
18
+ "s",
19
+ "m"
20
+ ],
21
+ "options": {
22
+ "maxItems": {
23
+ "type": "integer",
24
+ "minimum": 1,
25
+ "maximum": 10,
26
+ "default": 4,
27
+ "description": "How many lines"
28
+ }
29
+ },
30
+ "action": "mode list: the whole calendar",
31
+ "example": {
32
+ "envelope": {
33
+ "title": "Today",
34
+ "status": "info",
35
+ "source": "logistics",
36
+ "to": "/pickups",
37
+ "size": "s"
38
+ },
39
+ "data": {
40
+ "now": "2026-11-19T09:00:00",
41
+ "items": [
42
+ {
43
+ "at": "2026-11-19T14:00:00",
44
+ "label": "DPD pickup · 41 parcels, 48 ready"
45
+ },
46
+ {
47
+ "at": "2026-11-19T16:30:00",
48
+ "label": "Chronopost pickup · 12 parcels"
49
+ },
50
+ {
51
+ "at": "2026-11-20T10:00:00",
52
+ "label": "Ingram delivery · 3 purchases expected"
53
+ }
54
+ ]
55
+ },
56
+ "options": {
57
+ "maxItems": 4
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,48 @@
1
+ {
2
+ "type": "object",
3
+ "required": [
4
+ "items"
5
+ ],
6
+ "additionalProperties": false,
7
+ "properties": {
8
+ "now": {
9
+ "type": [
10
+ "string",
11
+ "number"
12
+ ],
13
+ "description": "Today, for the words \"tomorrow\"; default the clock"
14
+ },
15
+ "items": {
16
+ "type": "array",
17
+ "items": {
18
+ "type": "object",
19
+ "required": [
20
+ "at",
21
+ "label"
22
+ ],
23
+ "additionalProperties": false,
24
+ "properties": {
25
+ "at": {
26
+ "type": [
27
+ "string",
28
+ "number"
29
+ ]
30
+ },
31
+ "label": {
32
+ "type": "string"
33
+ },
34
+ "to": {
35
+ "type": [
36
+ "string",
37
+ "object"
38
+ ],
39
+ "description": "Where it opens"
40
+ },
41
+ "allDay": {
42
+ "type": "boolean"
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,76 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * bullet - good, fair or poor, and how far from the target? (#5339)
4
+ *
5
+ * Few's bullet graph: the dark bar is the value, the upright tick the
6
+ * target, the background ranges poor / fair / good, cut at the thresholds
7
+ * written under the axis. The range the value falls in is written too.
8
+ * See meta.json for the sheet.
9
+ */
10
+ import { computed } from 'vue'
11
+ import { useI18n } from '../../../i18n/useI18n'
12
+ import { formatNumber } from '../shared'
13
+ import type { CardSize } from '../../types'
14
+
15
+ interface BulletData {
16
+ value: number
17
+ target?: number
18
+ thresholds: number[]
19
+ min?: number
20
+ max?: number
21
+ }
22
+
23
+ const props = defineProps<{ data: BulletData; options: { unit?: string; decimals?: number; higherIs?: 'better' | 'worse' }; size: CardSize }>()
24
+ const { t, locale } = useI18n()
25
+
26
+ const fmt = (v: number) => formatNumber(v, locale.value, { decimals: props.options.decimals, unit: props.options.unit })
27
+ const cuts = computed(() => [...props.data.thresholds].sort((a, b) => a - b))
28
+ const min = computed(() => props.data.min ?? 0)
29
+ const max = computed(() => {
30
+ if (props.data.max !== undefined) return props.data.max
31
+ const top = Math.max(props.data.value, props.data.target ?? -Infinity, ...cuts.value)
32
+ return top + (top - min.value) * 0.15
33
+ })
34
+ const at = (v: number) => `${Math.min(Math.max((v - min.value) / (max.value - min.value || 1), 0), 1) * 100}%`
35
+
36
+ /** The ranges, low to high, each with its word */
37
+ const ranges = computed(() => {
38
+ const bounds = [min.value, ...cuts.value, max.value]
39
+ const words = cuts.value.length === 1 ? ['poor', 'good'] : ['poor', 'fair', 'good']
40
+ const ordered = props.options.higherIs === 'worse' ? [...words].reverse() : words
41
+ return bounds.slice(0, -1).map((from, i) => ({ from, to: bounds[i + 1]!, word: ordered[i]! }))
42
+ })
43
+ const verdict = computed(() => ranges.value.find((r, i) => props.data.value < r.to || i === ranges.value.length - 1)?.word ?? 'fair')
44
+ </script>
45
+
46
+ <template>
47
+ <div class="qd-bullet">
48
+ <div class="qd-metric-line">
49
+ <span class="qd-card-value">{{ fmt(data.value) }}</span>
50
+ <span v-if="data.target !== undefined" class="qd-card-unit">{{ t('core.cards.bullet.target', { target: fmt(data.target) }) }}</span>
51
+ </div>
52
+ <div
53
+ class="qd-bullet-graph"
54
+ role="img"
55
+ :aria-label="t('core.cards.bullet.aria', { value: fmt(data.value), range: t(`core.cards.bullet.${verdict}`) })"
56
+ >
57
+ <span
58
+ v-for="(r, i) in ranges"
59
+ :key="i"
60
+ class="qd-bullet-range"
61
+ :data-range="r.word"
62
+ :style="{ left: at(r.from), width: `calc(${at(r.to)} - ${at(r.from)})` }"
63
+ ></span>
64
+ <span class="qd-bullet-value" :style="{ width: at(data.value) }"></span>
65
+ <span v-if="data.target !== undefined" class="qd-bullet-target" :style="{ left: at(data.target) }"></span>
66
+ </div>
67
+ <div class="qd-bullet-axis" aria-hidden="true">
68
+ <span :style="{ left: '0%' }">{{ fmt(min) }}</span>
69
+ <span v-for="c in cuts" :key="c" :style="{ left: at(c) }">{{ fmt(c) }}</span>
70
+ <span :style="{ left: '100%' }">{{ fmt(max) }}</span>
71
+ </div>
72
+ <p class="qd-card-note">
73
+ <strong class="qd-bullet-verdict" :data-range="verdict">{{ t(`core.cards.bullet.${verdict}`) }}</strong>
74
+ </p>
75
+ </div>
76
+ </template>
@@ -0,0 +1,38 @@
1
+ {
2
+ "type": "bullet",
3
+ "title": "Bullet",
4
+ "question": "Is the value good, fair or poor, and how far from the target?",
5
+ "readings": [
6
+ "the dark bar's length: the value",
7
+ "the upright tick: the target",
8
+ "the background ranges: poor, fair, good, cut at the thresholds written under the axis",
9
+ "the word under it: the range the value falls in"
10
+ ],
11
+ "strengths": [
12
+ "three readings in one line, without a legend (Few's bullet graph)",
13
+ "compares to a target and to thresholds at once, where a gauge needs twice the room"
14
+ ],
15
+ "avoid": [
16
+ "when time matters more than the level: use goal (pace over a period) or metric (curve)",
17
+ "without thresholds: a plain metric says as much"
18
+ ],
19
+ "sizes": ["s", "m"],
20
+ "options": {
21
+ "unit": { "type": "string", "description": "Written after the numbers: \"%\"" },
22
+ "decimals": { "type": "integer", "minimum": 0, "maximum": 4, "default": 0, "description": "Digits after the decimal point" },
23
+ "higherIs": { "type": "string", "enum": ["better", "worse"], "default": "better", "description": "Whether the good range is at the top (margin) or at the bottom (delays)" }
24
+ },
25
+ "action": "mode list: open what pulls the value down (the low-margin orders)",
26
+ "example": {
27
+ "envelope": {
28
+ "title": "Margin this month",
29
+ "status": "watch",
30
+ "source": "sales",
31
+ "freshness": "2026-11-19T08:00:00Z",
32
+ "to": "/sales/margin",
33
+ "size": "s"
34
+ },
35
+ "data": { "value": 11.8, "target": 13, "thresholds": [9, 12], "min": 0, "max": 20 },
36
+ "options": { "unit": "%", "decimals": 1 }
37
+ }
38
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "type": "object",
3
+ "required": ["value", "thresholds"],
4
+ "additionalProperties": false,
5
+ "properties": {
6
+ "value": { "type": "number" },
7
+ "target": { "type": "number", "description": "Drawn as an upright tick" },
8
+ "thresholds": {
9
+ "type": "array",
10
+ "items": { "type": "number" },
11
+ "minItems": 1,
12
+ "maxItems": 2,
13
+ "description": "Where the ranges change, ascending: [poor/fair, fair/good] when higher is better"
14
+ },
15
+ "min": { "type": "number", "description": "The axis start (default 0)" },
16
+ "max": { "type": "number", "description": "The axis end (default: a little past the largest number)" }
17
+ }
18
+ }