@conduction/nextcloud-vue 2.79.0 → 2.80.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 (197) hide show
  1. package/dist/esm/components/CnActionButtons/CnActionButtons.vue2.js.map +1 -1
  2. package/dist/esm/components/CnActionButtons/CnActionButtons.vue3.js +3 -1
  3. package/dist/esm/components/CnActionButtons/CnActionButtons.vue3.js.map +1 -1
  4. package/dist/esm/components/CnActionsBar/CnActionsBar.vue2.js +32 -3
  5. package/dist/esm/components/CnActionsBar/CnActionsBar.vue2.js.map +1 -1
  6. package/dist/esm/components/CnActionsBar/CnActionsBar.vue3.js +10 -8
  7. package/dist/esm/components/CnActionsBar/CnActionsBar.vue3.js.map +1 -1
  8. package/dist/esm/components/CnBannerWidget/CnBannerWidget.vue2.js +39 -3
  9. package/dist/esm/components/CnBannerWidget/CnBannerWidget.vue2.js.map +1 -1
  10. package/dist/esm/components/CnBannerWidget/CnBannerWidget.vue3.js.map +1 -1
  11. package/dist/esm/components/CnCellRenderer/CnCellRenderer.vue2.js +79 -1
  12. package/dist/esm/components/CnCellRenderer/CnCellRenderer.vue2.js.map +1 -1
  13. package/dist/esm/components/CnCellRenderer/CnCellRenderer.vue3.js +133 -96
  14. package/dist/esm/components/CnCellRenderer/CnCellRenderer.vue3.js.map +1 -1
  15. package/dist/esm/components/CnDataTable/CnDataTable.vue2.js.map +1 -1
  16. package/dist/esm/components/CnDataTable/CnDataTable.vue3.js +1 -0
  17. package/dist/esm/components/CnDataTable/CnDataTable.vue3.js.map +1 -1
  18. package/dist/esm/components/CnDetailPage/CnDetailPage.vue2.js +62 -4
  19. package/dist/esm/components/CnDetailPage/CnDetailPage.vue2.js.map +1 -1
  20. package/dist/esm/components/CnDetailPage/CnDetailPage.vue3.js.map +1 -1
  21. package/dist/esm/components/CnDetailWidgetHost/CnDetailWidgetHost.vue2.js +24 -0
  22. package/dist/esm/components/CnDetailWidgetHost/CnDetailWidgetHost.vue2.js.map +1 -1
  23. package/dist/esm/components/CnDetailWidgetHost/CnDetailWidgetHost.vue3.js +43 -4
  24. package/dist/esm/components/CnDetailWidgetHost/CnDetailWidgetHost.vue3.js.map +1 -1
  25. package/dist/esm/components/CnFactsWidget/CnFactsWidget.vue.js +11 -0
  26. package/dist/esm/components/CnFactsWidget/CnFactsWidget.vue.js.map +1 -0
  27. package/dist/esm/components/CnFactsWidget/CnFactsWidget.vue2.js +736 -0
  28. package/dist/esm/components/CnFactsWidget/CnFactsWidget.vue2.js.map +1 -0
  29. package/dist/esm/components/CnFactsWidget/CnFactsWidget.vue3.js +238 -0
  30. package/dist/esm/components/CnFactsWidget/CnFactsWidget.vue3.js.map +1 -0
  31. package/dist/esm/components/CnFactsWidget/index.js +30 -0
  32. package/dist/esm/components/CnFactsWidget/index.js.map +1 -0
  33. package/dist/esm/components/CnFieldListWidget/CnFieldListWidget.vue.js +10 -0
  34. package/dist/esm/components/CnFieldListWidget/CnFieldListWidget.vue.js.map +1 -0
  35. package/dist/esm/components/CnFieldListWidget/CnFieldListWidget.vue2.js +551 -0
  36. package/dist/esm/components/CnFieldListWidget/CnFieldListWidget.vue2.js.map +1 -0
  37. package/dist/esm/components/CnFieldListWidget/CnFieldListWidget.vue3.js +183 -0
  38. package/dist/esm/components/CnFieldListWidget/CnFieldListWidget.vue3.js.map +1 -0
  39. package/dist/esm/components/CnFieldListWidget/index.js +29 -0
  40. package/dist/esm/components/CnFieldListWidget/index.js.map +1 -0
  41. package/dist/esm/components/CnFormDialog/CnFormDialog.vue2.js +65 -17
  42. package/dist/esm/components/CnFormDialog/CnFormDialog.vue2.js.map +1 -1
  43. package/dist/esm/components/CnFormDialog/CnFormDialog.vue3.js +4 -4
  44. package/dist/esm/components/CnFormDialog/CnFormDialog.vue3.js.map +1 -1
  45. package/dist/esm/components/CnFormPage/CnFormPage.vue2.js +18 -3
  46. package/dist/esm/components/CnFormPage/CnFormPage.vue2.js.map +1 -1
  47. package/dist/esm/components/CnFormPage/CnFormPage.vue3.js.map +1 -1
  48. package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js +305 -72
  49. package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js.map +1 -1
  50. package/dist/esm/components/CnIndexPage/CnIndexPage.vue3.js +31 -13
  51. package/dist/esm/components/CnIndexPage/CnIndexPage.vue3.js.map +1 -1
  52. package/dist/esm/components/CnIndexPage/CnIndexPageWidgets.vue.js +10 -0
  53. package/dist/esm/components/CnIndexPage/CnIndexPageWidgets.vue.js.map +1 -0
  54. package/dist/esm/components/CnIndexPage/CnIndexPageWidgets.vue2.js +99 -0
  55. package/dist/esm/components/CnIndexPage/CnIndexPageWidgets.vue2.js.map +1 -0
  56. package/dist/esm/components/CnIndexPage/CnIndexPageWidgets.vue3.js +48 -0
  57. package/dist/esm/components/CnIndexPage/CnIndexPageWidgets.vue3.js.map +1 -0
  58. package/dist/esm/components/CnPageRenderer/CnPageRenderer.vue2.js +29 -1
  59. package/dist/esm/components/CnPageRenderer/CnPageRenderer.vue2.js.map +1 -1
  60. package/dist/esm/components/CnPageRenderer/CnPageRenderer.vue3.js.map +1 -1
  61. package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue.js +10 -0
  62. package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue.js.map +1 -0
  63. package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue2.js +387 -0
  64. package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue2.js.map +1 -0
  65. package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue3.js +169 -0
  66. package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue3.js.map +1 -0
  67. package/dist/esm/components/CnRecordListWidget/index.js +31 -0
  68. package/dist/esm/components/CnRecordListWidget/index.js.map +1 -0
  69. package/dist/esm/components/CnSectionsWidget/CnSectionsWidget.vue.js +10 -0
  70. package/dist/esm/components/CnSectionsWidget/CnSectionsWidget.vue.js.map +1 -0
  71. package/dist/esm/components/CnSectionsWidget/CnSectionsWidget.vue2.js +351 -0
  72. package/dist/esm/components/CnSectionsWidget/CnSectionsWidget.vue2.js.map +1 -0
  73. package/dist/esm/components/CnSectionsWidget/CnSectionsWidget.vue3.js +71 -0
  74. package/dist/esm/components/CnSectionsWidget/CnSectionsWidget.vue3.js.map +1 -0
  75. package/dist/esm/components/CnSectionsWidget/index.js +35 -0
  76. package/dist/esm/components/CnSectionsWidget/index.js.map +1 -0
  77. package/dist/esm/components/CnStagesWidget/CnStagesWidget.vue2.js +81 -2
  78. package/dist/esm/components/CnStagesWidget/CnStagesWidget.vue2.js.map +1 -1
  79. package/dist/esm/components/CnStagesWidget/CnStagesWidget.vue3.js.map +1 -1
  80. package/dist/esm/components/CnStatWidget/CnStatWidget.vue2.js.map +1 -1
  81. package/dist/esm/components/CnStatWidget/CnStatWidget.vue3.js +1 -0
  82. package/dist/esm/components/CnStatWidget/CnStatWidget.vue3.js.map +1 -1
  83. package/dist/esm/components/CnTabsWidget/CnTabsWidget.vue2.js +122 -7
  84. package/dist/esm/components/CnTabsWidget/CnTabsWidget.vue2.js.map +1 -1
  85. package/dist/esm/components/CnTabsWidget/CnTabsWidget.vue3.js +84 -23
  86. package/dist/esm/components/CnTabsWidget/CnTabsWidget.vue3.js.map +1 -1
  87. package/dist/esm/components/CnWidgetGrid/registerDashboardWidgets.js +4 -0
  88. package/dist/esm/components/CnWidgetGrid/registerDashboardWidgets.js.map +1 -1
  89. package/dist/esm/components/CnWorkspaceFilterWidget/CnWorkspaceFilterWidget.vue2.js +106 -2
  90. package/dist/esm/components/CnWorkspaceFilterWidget/CnWorkspaceFilterWidget.vue2.js.map +1 -1
  91. package/dist/esm/components/CnWorkspaceFilterWidget/CnWorkspaceFilterWidget.vue3.js +105 -53
  92. package/dist/esm/components/CnWorkspaceFilterWidget/CnWorkspaceFilterWidget.vue3.js.map +1 -1
  93. package/dist/esm/composables/useFormDraft.js +140 -9
  94. package/dist/esm/composables/useFormDraft.js.map +1 -1
  95. package/dist/esm/index.js +4 -0
  96. package/dist/esm/index.js.map +1 -1
  97. package/dist/esm/integrations/builtin/field-inspection/CnFieldInspectionCard.vue2.js +28 -20
  98. package/dist/esm/integrations/builtin/field-inspection/CnFieldInspectionCard.vue2.js.map +1 -1
  99. package/dist/esm/integrations/builtin/field-inspection/CnFieldInspectionCard.vue3.js +9 -0
  100. package/dist/esm/integrations/builtin/field-inspection/CnFieldInspectionCard.vue3.js.map +1 -1
  101. package/dist/esm/integrations/builtin/field-inspection.js +21 -0
  102. package/dist/esm/integrations/builtin/field-inspection.js.map +1 -1
  103. package/dist/esm/integrations/offline/checklistSubmission.js +141 -0
  104. package/dist/esm/integrations/offline/checklistSubmission.js.map +1 -0
  105. package/dist/esm/integrations/offline/fieldCollectionHelpers.js +70 -5
  106. package/dist/esm/integrations/offline/fieldCollectionHelpers.js.map +1 -1
  107. package/dist/esm/integrations/offline/index.js +2 -1
  108. package/dist/esm/integrations/offline/index.js.map +1 -1
  109. package/dist/esm/integrations/offline/offlineDb.js +6 -1
  110. package/dist/esm/integrations/offline/offlineDb.js.map +1 -1
  111. package/dist/esm/integrations/offline/syncReplayService.js +8 -2
  112. package/dist/esm/integrations/offline/syncReplayService.js.map +1 -1
  113. package/dist/esm/l10n/en.json.js +12 -1
  114. package/dist/esm/l10n/en.json.js.map +1 -1
  115. package/dist/esm/l10n/nl.json.js +16 -2
  116. package/dist/esm/l10n/nl.json.js.map +1 -1
  117. package/dist/esm/nextcloud-vue.css +1000 -59
  118. package/dist/esm/utils/detailActionModel.js +60 -3
  119. package/dist/esm/utils/detailActionModel.js.map +1 -1
  120. package/dist/esm/utils/fillTemplate.js +114 -0
  121. package/dist/esm/utils/fillTemplate.js.map +1 -0
  122. package/dist/esm/utils/libraryWidgetKeys.js +4 -0
  123. package/dist/esm/utils/libraryWidgetKeys.js.map +1 -1
  124. package/dist/esm/utils/queryPresets.js +96 -0
  125. package/dist/esm/utils/queryPresets.js.map +1 -0
  126. package/dist/esm/utils/resolveFilterTokens.js +11 -0
  127. package/dist/esm/utils/resolveFilterTokens.js.map +1 -1
  128. package/dist/esm/utils/schema.js +21 -0
  129. package/dist/esm/utils/schema.js.map +1 -1
  130. package/dist/esm/utils/sentinelTokens.js +3 -3
  131. package/dist/esm/utils/sentinelTokens.js.map +1 -1
  132. package/dist/esm/utils/validateManifestV2.compiled.js +3 -3
  133. package/dist/esm/utils/validateManifestV2.compiled.js.map +1 -1
  134. package/dist/esm/utils/widgetDispatch.js +7 -1
  135. package/dist/esm/utils/widgetDispatch.js.map +1 -1
  136. package/dist/nextcloud-vue.cjs.js +12368 -7717
  137. package/dist/nextcloud-vue.cjs.js.map +2 -2
  138. package/dist/nextcloud-vue.css +1000 -59
  139. package/l10n/en.json +12 -1
  140. package/l10n/nl.json +16 -2
  141. package/package.json +1 -1
  142. package/src/components/CnActionButtons/CnActionButtons.vue +2 -0
  143. package/src/components/CnActionsBar/CnActionsBar.md +4 -0
  144. package/src/components/CnActionsBar/CnActionsBar.vue +42 -10
  145. package/src/components/CnBannerWidget/CnBannerWidget.vue +39 -3
  146. package/src/components/CnCellRenderer/CnCellRenderer.vue +188 -1
  147. package/src/components/CnDataTable/CnDataTable.vue +1 -0
  148. package/src/components/CnDetailPage/CnDetailPage.md +1 -1
  149. package/src/components/CnDetailPage/CnDetailPage.vue +63 -3
  150. package/src/components/CnDetailWidgetHost/CnDetailWidgetHost.vue +66 -0
  151. package/src/components/CnFactsWidget/CnFactsWidget.vue +1050 -0
  152. package/src/components/CnFactsWidget/index.js +29 -0
  153. package/src/components/CnFieldListWidget/CnFieldListWidget.vue +746 -0
  154. package/src/components/CnFieldListWidget/index.js +28 -0
  155. package/src/components/CnFormDialog/CnFormDialog.md +9 -3
  156. package/src/components/CnFormDialog/CnFormDialog.vue +69 -21
  157. package/src/components/CnFormPage/CnFormPage.vue +18 -3
  158. package/src/components/CnIndexPage/CnIndexPage.vue +254 -6
  159. package/src/components/CnIndexPage/CnIndexPageWidgets.vue +169 -0
  160. package/src/components/CnPageRenderer/CnPageRenderer.vue +29 -1
  161. package/src/components/CnRecordListWidget/CnRecordListWidget.vue +603 -0
  162. package/src/components/CnRecordListWidget/index.js +30 -0
  163. package/src/components/CnSectionsWidget/CnSectionsWidget.vue +489 -0
  164. package/src/components/CnSectionsWidget/index.js +34 -0
  165. package/src/components/CnStagesWidget/CnStagesWidget.vue +81 -2
  166. package/src/components/CnStatWidget/CnStatWidget.vue +1 -1
  167. package/src/components/CnTabsWidget/CnTabsWidget.vue +184 -8
  168. package/src/components/CnWidgetGrid/registerDashboardWidgets.js +4 -0
  169. package/src/components/CnWorkspaceFilterWidget/CnWorkspaceFilterWidget.vue +188 -4
  170. package/src/components/index.js +4 -0
  171. package/src/composables/__tests__/useFormDraft.spec.js +69 -0
  172. package/src/composables/useFormDraft.js +139 -8
  173. package/src/css/form-field.css +14 -0
  174. package/src/css/index-page.css +71 -0
  175. package/src/css/kpi-card.css +32 -0
  176. package/src/css/look-board-detail.css +77 -0
  177. package/src/css/look-board-index.css +51 -0
  178. package/src/css/look-board.css +37 -2
  179. package/src/css/table.css +19 -0
  180. package/src/index.js +4 -0
  181. package/src/integrations/builtin/field-inspection/CnFieldInspectionCard.vue +35 -20
  182. package/src/integrations/builtin/field-inspection.js +21 -0
  183. package/src/integrations/offline/checklistSubmission.js +137 -0
  184. package/src/integrations/offline/fieldCollectionHelpers.js +69 -4
  185. package/src/integrations/offline/index.js +3 -0
  186. package/src/integrations/offline/offlineDb.js +6 -1
  187. package/src/integrations/offline/syncReplayService.js +8 -2
  188. package/src/schemas/app-manifest-v2.schema.json +104 -5
  189. package/src/utils/detailActionModel.js +59 -2
  190. package/src/utils/fillTemplate.js +110 -0
  191. package/src/utils/libraryWidgetKeys.js +4 -0
  192. package/src/utils/queryPresets.js +93 -0
  193. package/src/utils/resolveFilterTokens.js +11 -0
  194. package/src/utils/schema.js +21 -0
  195. package/src/utils/sentinelTokens.js +3 -3
  196. package/src/utils/validateManifestV2.compiled.js +3 -3
  197. package/src/utils/widgetDispatch.js +7 -1
@@ -0,0 +1,1050 @@
1
+ <!--
2
+ - SPDX-FileCopyrightText: 2026 Conduction B.V.
3
+ - SPDX-License-Identifier: EUPL-1.2
4
+ -->
5
+
6
+ <template>
7
+ <div class="cn-facts-widget" data-testid="cn-facts-widget">
8
+ <p v-if="error" class="cn-facts-widget__muted" data-testid="cn-facts-error">
9
+ {{ tr('Could not load this information') }}
10
+ </p>
11
+ <div v-else-if="loading && !record" class="cn-facts-widget__loading">
12
+ <NcLoadingIcon :size="20" />
13
+ </div>
14
+ <p v-else-if="blocks.length === 0" class="cn-facts-widget__muted" data-testid="cn-facts-empty">
15
+ {{ emptyLabel }}
16
+ </p>
17
+ <template v-else>
18
+ <template v-for="block in blocks" :key="block.key">
19
+ <dl
20
+ v-if="block.kind === 'rows'"
21
+ class="cn-facts-widget__rows">
22
+ <div
23
+ v-for="row in block.rows"
24
+ :key="row.key"
25
+ class="cn-facts-widget__row"
26
+ :data-testid="`cn-fact-${row.key}`">
27
+ <dt class="cn-facts-widget__label" :class="{ 'cn-facts-widget__label--icon': row.icon }">
28
+ <CnIcon
29
+ v-if="row.icon"
30
+ :name="row.icon"
31
+ :size="18"
32
+ aria-hidden="true" />
33
+ <span :class="{ 'hidden-visually': row.icon }">{{ row.label }}</span>
34
+ </dt>
35
+ <dd class="cn-facts-widget__value">
36
+ <a
37
+ v-if="row.href"
38
+ :href="row.href"
39
+ class="cn-facts-widget__value-link"
40
+ :target="row.external ? '_blank' : undefined"
41
+ :rel="row.external ? 'noopener noreferrer' : undefined">{{ row.value }}</a>
42
+ <span v-else>{{ row.masked && !revealed[row.key] ? row.masked : row.value }}</span>
43
+ <button
44
+ v-if="row.reveal && !revealed[row.key]"
45
+ type="button"
46
+ class="cn-facts-widget__inline-button"
47
+ :aria-label="revealLabel(row)"
48
+ :data-testid="`cn-fact-reveal-${row.key}`"
49
+ @click="reveal(row)">
50
+ <EyeOutline :size="16" aria-hidden="true" />
51
+ {{ showLabel }}
52
+ </button>
53
+ <button
54
+ v-if="row.copy"
55
+ type="button"
56
+ class="cn-facts-widget__icon-button"
57
+ :aria-label="copyLabel(row)"
58
+ :title="copyLabel(row)"
59
+ :data-testid="`cn-fact-copy-${row.key}`"
60
+ @click="copy(row)">
61
+ <Check v-if="copied === row.key" :size="16" aria-hidden="true" />
62
+ <ContentCopy v-else :size="16" aria-hidden="true" />
63
+ </button>
64
+ </dd>
65
+ </div>
66
+ </dl>
67
+ <component
68
+ :is="block.to ? 'router-link' : 'strong'"
69
+ v-else-if="block.kind === 'title'"
70
+ :to="block.to || undefined"
71
+ class="cn-facts-widget__title"
72
+ :data-testid="`cn-fact-${block.key}`">
73
+ {{ block.value }}
74
+ </component>
75
+ <span
76
+ v-else-if="block.kind === 'line'"
77
+ class="cn-facts-widget__line"
78
+ :data-testid="`cn-fact-${block.key}`">
79
+ {{ block.value }}
80
+ </span>
81
+ <span
82
+ v-else-if="block.kind === 'text'"
83
+ class="cn-facts-widget__text"
84
+ :data-testid="`cn-fact-${block.key}`">
85
+ {{ block.value }}
86
+ </span>
87
+ <div
88
+ v-else-if="block.kind === 'lead'"
89
+ class="cn-facts-widget__lead"
90
+ :data-testid="`cn-fact-${block.key}`">
91
+ <span
92
+ class="cn-facts-widget__lead-tile"
93
+ :class="`cn-facts-widget__lead-tile--${block.tone}`"
94
+ aria-hidden="true">
95
+ <CnIcon v-if="block.icon" :name="block.icon" :size="20" />
96
+ <template v-else>{{ block.initials }}</template>
97
+ </span>
98
+ <span class="cn-facts-widget__lead-text">
99
+ <strong class="cn-facts-widget__lead-title">{{ block.value }}</strong>
100
+ <span v-if="block.subtitle" class="cn-facts-widget__lead-subtitle">{{ block.subtitle }}</span>
101
+ </span>
102
+ </div>
103
+ <div v-else-if="block.kind === 'pill'">
104
+ <CnStatusBadge
105
+ :label="block.value"
106
+ :variant="block.variant"
107
+ size="small"
108
+ :data-testid="`cn-fact-${block.key}`" />
109
+ </div>
110
+ </template>
111
+ </template>
112
+ <component
113
+ :is="link.to ? 'router-link' : 'a'"
114
+ v-if="link && record"
115
+ :to="link.to || undefined"
116
+ :href="link.href || undefined"
117
+ class="cn-facts-widget__link"
118
+ data-testid="cn-facts-link">
119
+ {{ link.label }}
120
+ </component>
121
+ <button
122
+ v-if="action && record"
123
+ type="button"
124
+ class="cn-facts-widget__action"
125
+ data-testid="cn-facts-action"
126
+ @click="runAction(content.action)">
127
+ <CnIcon v-if="action.icon" :name="action.icon" :size="16" />
128
+ {{ action.label }}
129
+ </button>
130
+ </div>
131
+ </template>
132
+
133
+ <script>
134
+ import { emit } from '@nextcloud/event-bus'
135
+ import { translate as t } from '@nextcloud/l10n'
136
+ import { NcLoadingIcon } from '@nextcloud/vue'
137
+ import Check from 'vue-material-design-icons/Check.vue'
138
+ import ContentCopy from 'vue-material-design-icons/ContentCopy.vue'
139
+ import EyeOutline from 'vue-material-design-icons/EyeOutline.vue'
140
+ import CnIcon from '../CnIcon/CnIcon.vue'
141
+ import CnStatusBadge from '../CnStatusBadge/CnStatusBadge.vue'
142
+ import { resolveEndpointRequest } from '../../composables/useEndpointSource.js'
143
+ import { dispatchAction } from '../../utils/actionsDispatcher.js'
144
+ import { isBadgeVariant } from '../../utils/badgeVariants.js'
145
+ import { formatBoardDate } from '../../utils/boardDate.js'
146
+ import { parseDateValue } from '../../utils/dateVariant.js'
147
+ import { readPath } from '../../utils/readPath.js'
148
+ import { hasUnresolvedDeepTokens, resolveDeepTokens } from '../../utils/resolveFilterTokens.js'
149
+
150
+ /** Kinds of entry a `fields[]` item can be. A labelled item without `as` is a row. */
151
+ const KINDS = Object.freeze(['row', 'title', 'line', 'pill', 'lead', 'text'])
152
+
153
+ /** Event-bus channel a reveal of a masked value is announced on, so an app can log it. */
154
+ export const FACTS_REVEAL_CHANNEL = 'cn:facts:reveal'
155
+
156
+ /**
157
+ * CnFactsWidget — the `facts` widget: a card of facts about ONE object.
158
+ *
159
+ * Renders the configured fields of the current detail-page object, or of one
160
+ * other object named by `content.source`, as the side cards on the screens
161
+ * draw them: label/value rows (a two-column grid, label muted), a bold title
162
+ * line that may link, muted meta lines that join several fields with " · ",
163
+ * a status pill, and one link at the foot.
164
+ *
165
+ * Everything is configuration; nothing in it knows an app:
166
+ *
167
+ * ```json
168
+ * {
169
+ * "type": "facts",
170
+ * "title": "Zaak",
171
+ * "content": {
172
+ * "source": { "register": "dossiq", "schema": "case", "id": "@object.case" },
173
+ * "fields": [
174
+ * { "as": "title", "path": "title", "route": { "name": "CaseDetail", "params": { "id": "@source.id" } } },
175
+ * { "as": "line", "parts": ["identifier", "caseTypeTitle"] },
176
+ * { "as": "pill", "path": "status", "map": { "open": "In behandeling" } },
177
+ * { "path": "deadline", "label": "Termijn", "format": "date" }
178
+ * ],
179
+ * "link": { "label": "Naar de zaak", "route": { "name": "CaseDetail", "params": { "id": "@source.id" } } },
180
+ * "emptyText": "Geen zaak"
181
+ * }
182
+ * }
183
+ * ```
184
+ *
185
+ * Tokens: `source.id` takes the shared filter tokens; `source.url` takes them
186
+ * inside the url, the endpoint grammar (`/apps/x/api/y/@objectId`)
187
+ * (`@objectId`, `@object.<field>`, `@workspace.<key>`, `@me`, ...). Routes
188
+ * and the link also take `@source.<field>` (a field of the object shown).
189
+ * A source whose id token does not resolve renders the empty text, never a
190
+ * request for the literal token.
191
+ *
192
+ * Labels, map values, the link label and the empty text go through the host
193
+ * app's translate (`cnTranslate`).
194
+ */
195
+ export default {
196
+ name: 'CnFactsWidget',
197
+
198
+ components: { Check, CnIcon, CnStatusBadge, ContentCopy, EyeOutline, NcLoadingIcon },
199
+
200
+ inject: {
201
+ cnTranslate: { default: () => (key) => key },
202
+ cnObjectContext: { default: null },
203
+ cnWorkspaceContext: { default: null },
204
+ /** Pre-bound action dispatcher of CnPageRenderer, for `action` / `headerAction`. */
205
+ cnDispatchAction: { default: null },
206
+ },
207
+
208
+ props: {
209
+ /**
210
+ * The widget configuration.
211
+ *
212
+ * - `fields` — the entries, in order. Each is `{ path, label?, as?, format?, map?, itemPath?, parts?, separator?, route?, variant?, variantMap?, icon?, copy?, reveal?, text?, title?, subtitle?, initialsPath?, tone? }`.
213
+ * `as` is `row` (default when `label` or `icon` is set), `title`, `line`, `text` (a line in the normal ink), `lead` (an icon tile or initials beside `title` and `subtitle`) or `pill`.
214
+ * A row's `format` may also be `email`, `phone` or `url` (a link) or `masked` (the last four characters; `reveal: true` adds Show). `copy: true` adds a copy button; `icon` replaces the label.
215
+ * A part may be `{ text }`, a constant; a `line` or `text` entry without `path` or `parts` shows its `text`.
216
+ * - `action` — an action drawn as a button under the facts; `headerAction` — one drawn in the card header (reported through the `header` event).
217
+ * `format` is `text` (default), `date` (board short date), `date-long` (always with the year) or `list` (an array joined by ", ", each item read at `itemPath`).
218
+ * `map` turns a raw value into a label (translated). `parts` (on a `line`) lists paths, or `{ path, label?, format? }`, joined by `separator` (default " · "); empty parts are dropped.
219
+ * - `source` — `{ register, schema, id }` or `{ url }`; omitted = the current object.
220
+ * - `link` — `{ label, route? | href? }` at the foot.
221
+ * - `hideEmpty` — drop an entry whose value is empty (default true).
222
+ * - `emptyText` — shown when no entry has a value.
223
+ *
224
+ * @type {{fields?: Array<object>, source?: object, link?: object, hideEmpty?: boolean, emptyText?: string}}
225
+ */
226
+ content: {
227
+ type: Object,
228
+ default: () => ({}),
229
+ },
230
+
231
+ /**
232
+ * The current detail-page object, passed by the detail page host.
233
+ * Read when `content.source` is not set.
234
+ */
235
+ objectData: {
236
+ type: Object,
237
+ default: null,
238
+ },
239
+
240
+ /** The current detail-page object id, for the `@objectId` token. */
241
+ objectId: {
242
+ type: [String, Number],
243
+ default: null,
244
+ },
245
+ },
246
+
247
+ emits: ['header', 'reveal'],
248
+
249
+ data() {
250
+ return {
251
+ fetched: null,
252
+ loading: false,
253
+ error: false,
254
+ /** Keys of the masked rows the reader chose to show. */
255
+ revealed: {},
256
+ /** Key of the row whose value was just copied. */
257
+ copied: '',
258
+ }
259
+ },
260
+
261
+ computed: {
262
+ /**
263
+ * The token context: the detail object (prop, else the injected context)
264
+ * and the page workspace.
265
+ *
266
+ * @return {object}
267
+ */
268
+ tokenCtx() {
269
+ const unwrap = (c) => (c && typeof c === 'object' && 'value' in c ? c.value : c)
270
+ const injected = unwrap(this.cnObjectContext) || {}
271
+ return {
272
+ ...injected,
273
+ objectId: this.objectId ?? injected.objectId ?? this.objectData?.id ?? null,
274
+ object: this.objectData || injected.object || null,
275
+ workspace: unwrap(this.cnWorkspaceContext) || {},
276
+ }
277
+ },
278
+
279
+ /**
280
+ * The source declaration with its tokens resolved, or null for the current object.
281
+ *
282
+ * @return {object|null}
283
+ */
284
+ resolvedSource() {
285
+ const source = this.content?.source
286
+ if (!source || typeof source !== 'object') {
287
+ return null
288
+ }
289
+ if (typeof source.url === 'string' && source.url !== '') {
290
+ // The endpoint grammar: tokens INSIDE the url, and a request
291
+ // that is blocked while one leaves an empty path segment.
292
+ const request = resolveEndpointRequest({ url: source.url }, this.tokenCtx)
293
+ return { url: request.blocked ? '' : request.url }
294
+ }
295
+ return resolveDeepTokens(source, this.tokenCtx)
296
+ },
297
+
298
+ /**
299
+ * A stable key of the resolved source, so the widget refetches only when it changes.
300
+ *
301
+ * @return {string}
302
+ */
303
+ sourceKey() {
304
+ return this.resolvedSource ? JSON.stringify(this.resolvedSource) : ''
305
+ },
306
+
307
+ /**
308
+ * The object the facts are read from.
309
+ *
310
+ * @return {object|null}
311
+ */
312
+ record() {
313
+ return this.resolvedSource ? this.fetched : this.objectData
314
+ },
315
+
316
+ /**
317
+ * The entries to draw, consecutive rows grouped into one list.
318
+ *
319
+ * @return {Array<object>}
320
+ */
321
+ blocks() {
322
+ const record = this.record
323
+ if (!record) {
324
+ return []
325
+ }
326
+ const fields = Array.isArray(this.content?.fields) ? this.content.fields : []
327
+ const hideEmpty = this.content?.hideEmpty !== false
328
+ const out = []
329
+ fields.forEach((field, index) => {
330
+ if (!field || typeof field !== 'object') {
331
+ return
332
+ }
333
+ const kind = this.kindOf(field)
334
+ const key = String(field.key || field.path || `${kind}-${index}`).replace(/[^\w-]/g, '-')
335
+ const value = this.entryValue(record, field, kind)
336
+ if (value === '' && (hideEmpty || kind === 'lead')) {
337
+ return
338
+ }
339
+ if (kind === 'row') {
340
+ const last = out[out.length - 1]
341
+ const row = { key, label: this.tr(field.label || ''), value, ...this.rowExtras(record, field, value) }
342
+ if (last && last.kind === 'rows') {
343
+ last.rows.push(row)
344
+ } else {
345
+ out.push({ kind: 'rows', key: `rows-${index}`, rows: [row] })
346
+ }
347
+ return
348
+ }
349
+ const block = { kind, key, value }
350
+ if (kind === 'lead') {
351
+ block.subtitle = this.partsValue(record, field.subtitle)
352
+ block.icon = typeof field.icon === 'string' ? field.icon : ''
353
+ block.initials = block.icon ? '' : this.initialsOf(readPath(record, field.initialsPath))
354
+ block.tone = ['success', 'info', 'warning', 'error'].includes(field.tone) ? field.tone : 'neutral'
355
+ }
356
+ if (kind === 'title' && field.route) {
357
+ block.to = this.resolveRoute(field.route, record)
358
+ }
359
+ if (kind === 'pill') {
360
+ const raw = readPath(record, field.path)
361
+ const variant = (field.variantMap && field.variantMap[raw]) || field.variant
362
+ block.variant = isBadgeVariant(variant) ? variant : 'default'
363
+ }
364
+ out.push(block)
365
+ })
366
+ return out
367
+ },
368
+
369
+ /**
370
+ * The foot link, resolved, or null.
371
+ *
372
+ * @return {{label: string, to?: object, href?: string}|null}
373
+ */
374
+ link() {
375
+ const link = this.content?.link
376
+ if (!link || typeof link !== 'object' || !link.label) {
377
+ return null
378
+ }
379
+ if (link.route) {
380
+ const to = this.resolveRoute(link.route, this.record)
381
+ return to ? { label: this.tr(link.label), to } : null
382
+ }
383
+ if (typeof link.href === 'string' && link.href !== '') {
384
+ const href = this.resolveTemplate(link.href, this.record)
385
+ return href ? { label: this.tr(link.label), href } : null
386
+ }
387
+ return null
388
+ },
389
+
390
+ /**
391
+ * The action under the facts, as drawn: `{ label, icon }`, or null.
392
+ *
393
+ * @return {{label: string, icon: string}|null}
394
+ * @spec openspec/changes/screens-relation-pages/specs/relation-pages/spec.md#requirement-the-facts-card-draws-contact-details-identity-and-a-lead
395
+ */
396
+ action() {
397
+ return this.actionView(this.content?.action)
398
+ },
399
+
400
+ /**
401
+ * The header action, as drawn: `{ label, icon }`, or null.
402
+ *
403
+ * @return {{label: string, icon: string}|null}
404
+ * @spec openspec/changes/screens-relation-pages/specs/relation-pages/spec.md#requirement-the-facts-card-draws-contact-details-identity-and-a-lead
405
+ */
406
+ headerAction() {
407
+ return this.actionView(this.content?.headerAction)
408
+ },
409
+
410
+ /** @return {string} The reveal button's text. */
411
+ showLabel() {
412
+ return t('nextcloud-vue', 'Show')
413
+ },
414
+
415
+ /**
416
+ * The empty line.
417
+ *
418
+ * @return {string}
419
+ */
420
+ emptyLabel() {
421
+ return this.tr(this.content?.emptyText || 'Nothing to show yet')
422
+ },
423
+ },
424
+
425
+ watch: {
426
+ sourceKey: {
427
+ immediate: true,
428
+ handler() {
429
+ this.load()
430
+ },
431
+ },
432
+
433
+ headerAction: {
434
+ immediate: true,
435
+ handler() {
436
+ this.emitHeader()
437
+ },
438
+ },
439
+ },
440
+
441
+ methods: {
442
+ /**
443
+ * Translate through the host app.
444
+ *
445
+ * @param {string} text The text.
446
+ * @return {string}
447
+ */
448
+ tr(text) {
449
+ if (typeof text !== 'string' || text === '') {
450
+ return ''
451
+ }
452
+ return typeof this.cnTranslate === 'function' ? this.cnTranslate(text) : text
453
+ },
454
+
455
+ /**
456
+ * The kind of a field entry.
457
+ *
458
+ * @param {object} field The entry.
459
+ * @return {string} `row`, `title`, `line` or `pill`.
460
+ */
461
+ kindOf(field) {
462
+ if (KINDS.includes(field.as)) {
463
+ return field.as
464
+ }
465
+ return field.label || field.icon ? 'row' : 'line'
466
+ },
467
+
468
+ /**
469
+ * The display text of an entry of any kind: a lead's title, the parts of
470
+ * a line or text, a constant `text`, else the value at `path`.
471
+ *
472
+ * @param {object} record The object.
473
+ * @param {object} field The entry.
474
+ * @param {string} kind The entry's kind.
475
+ * @return {string}
476
+ * @spec openspec/changes/screens-relation-pages/specs/relation-pages/spec.md#requirement-the-facts-card-draws-contact-details-identity-and-a-lead
477
+ */
478
+ entryValue(record, field, kind) {
479
+ if (kind === 'lead') {
480
+ return this.partsValue(record, field.title)
481
+ }
482
+ if ((kind === 'line' || kind === 'text') && Array.isArray(field.parts)) {
483
+ return this.lineValue(record, field)
484
+ }
485
+ if ((kind === 'line' || kind === 'text') && !field.path && typeof field.text === 'string') {
486
+ return this.tr(field.text)
487
+ }
488
+ return this.valueOf(record, field)
489
+ },
490
+
491
+ /**
492
+ * A lead's title or subtitle: a path, a part spec, or an array of parts
493
+ * joined as a line joins them.
494
+ *
495
+ * @param {object} record The object.
496
+ * @param {string|object|Array} spec The declaration.
497
+ * @return {string}
498
+ */
499
+ partsValue(record, spec) {
500
+ if (typeof spec === 'string' && spec !== '') {
501
+ return this.valueOf(record, { path: spec })
502
+ }
503
+ if (Array.isArray(spec)) {
504
+ return this.lineValue(record, { parts: spec })
505
+ }
506
+ if (spec && typeof spec === 'object') {
507
+ return this.lineValue(record, { parts: [spec] })
508
+ }
509
+ return ''
510
+ },
511
+
512
+ /**
513
+ * The initials of a name: "Sanne de Vries" reads "SV".
514
+ *
515
+ * @param {unknown} name The name.
516
+ * @return {string}
517
+ */
518
+ initialsOf(name) {
519
+ if (typeof name !== 'string' || name.trim() === '') {
520
+ return ''
521
+ }
522
+ const words = name.trim().split(/\s+/).filter((word) => /^\p{Lu}/u.test(word))
523
+ const picked = words.length ? words : name.trim().split(/\s+/)
524
+ const first = picked[0].charAt(0)
525
+ const last = picked.length > 1 ? picked[picked.length - 1].charAt(0) : ''
526
+ return (first + last).toUpperCase()
527
+ },
528
+
529
+ /**
530
+ * What a row adds to its value: an icon, a link for the email, phone
531
+ * and url formats, the masked text, and the copy and reveal buttons.
532
+ *
533
+ * @param {object} record The object.
534
+ * @param {object} field The entry.
535
+ * @param {string} value The display text.
536
+ * @return {object}
537
+ * @spec openspec/changes/screens-relation-pages/specs/relation-pages/spec.md#requirement-the-facts-card-draws-contact-details-identity-and-a-lead
538
+ */
539
+ rowExtras(record, field, value) {
540
+ const extras = {
541
+ icon: typeof field.icon === 'string' ? field.icon : '',
542
+ path: field.path || '',
543
+ raw: readPath(record, field.path),
544
+ copy: field.copy === true && value !== '',
545
+ reveal: false,
546
+ masked: '',
547
+ href: '',
548
+ external: false,
549
+ }
550
+ if (value === '') {
551
+ return extras
552
+ }
553
+ if (field.format === 'email') {
554
+ extras.href = `mailto:${value}`
555
+ } else if (field.format === 'phone') {
556
+ extras.href = `tel:${value.replace(/[^\d+]/g, '')}`
557
+ } else if (field.format === 'url') {
558
+ extras.href = /^https?:\/\//i.test(value) ? value : `https://${value}`
559
+ extras.external = true
560
+ } else if (field.format === 'masked') {
561
+ extras.masked = value.length > 4 ? '*'.repeat(Math.min(value.length - 4, 5)) + value.slice(-4) : value
562
+ extras.reveal = field.reveal === true && value.length > 4
563
+ }
564
+ return extras
565
+ },
566
+
567
+ /**
568
+ * Show a masked value, and say so: the `reveal` event and the event-bus
569
+ * channel {@link FACTS_REVEAL_CHANNEL}, so an app can log who saw it.
570
+ *
571
+ * @param {object} row The row.
572
+ * @spec openspec/changes/screens-relation-pages/specs/relation-pages/spec.md#requirement-the-facts-card-draws-contact-details-identity-and-a-lead
573
+ */
574
+ reveal(row) {
575
+ this.revealed = { ...this.revealed, [row.key]: true }
576
+ const detail = { path: row.path }
577
+ /**
578
+ * @event reveal Emitted when the reader shows a masked value.
579
+ * @type {{path: string}} The path of the shown field.
580
+ */
581
+ this.$emit('reveal', detail)
582
+ emit(FACTS_REVEAL_CHANNEL, { ...detail, objectId: this.tokenCtx.objectId, register: this.tokenCtx.register || null, schema: this.tokenCtx.schema || null })
583
+ },
584
+
585
+ /**
586
+ * Copy a row's value to the clipboard.
587
+ *
588
+ * @param {object} row The row.
589
+ * @return {Promise<void>}
590
+ */
591
+ async copy(row) {
592
+ const text = row.raw === null || row.raw === undefined || typeof row.raw === 'object' ? row.value : String(row.raw)
593
+ try {
594
+ await navigator.clipboard.writeText(text)
595
+ this.copied = row.key
596
+ setTimeout(() => {
597
+ if (this.copied === row.key) {
598
+ this.copied = ''
599
+ }
600
+ }, 2000)
601
+ } catch (e) {
602
+ // eslint-disable-next-line no-console
603
+ console.warn('[CnFactsWidget] could not copy:', e?.message || e)
604
+ }
605
+ },
606
+
607
+ /**
608
+ * @param {object} row The row.
609
+ * @return {string} The copy button's accessible name.
610
+ */
611
+ copyLabel(row) {
612
+ return this.copied === row.key
613
+ ? t('nextcloud-vue', 'Copied')
614
+ : t('nextcloud-vue', 'Copy {label}', { label: row.label || row.value })
615
+ },
616
+
617
+ /**
618
+ * @param {object} row The row.
619
+ * @return {string} The reveal button's accessible name.
620
+ */
621
+ revealLabel(row) {
622
+ return t('nextcloud-vue', 'Show {label}', { label: row.label || '' }).trim()
623
+ },
624
+
625
+ /**
626
+ * The drawn part of an action declaration.
627
+ *
628
+ * @param {object} action The declaration.
629
+ * @return {{label: string, icon: string}|null}
630
+ */
631
+ actionView(action) {
632
+ if (!action || typeof action !== 'object' || typeof action.label !== 'string' || action.label === '') {
633
+ return null
634
+ }
635
+ return { label: this.tr(action.label), icon: typeof action.icon === 'string' ? action.icon : '' }
636
+ },
637
+
638
+ /**
639
+ * Dispatch an action with the record's tokens resolved (`@objectId`,
640
+ * `@object.<field>`), through the page's dispatcher when there is one.
641
+ *
642
+ * @param {object} action The declaration.
643
+ * @return {unknown}
644
+ * @spec openspec/changes/screens-relation-pages/specs/relation-pages/spec.md#requirement-the-facts-card-draws-contact-details-identity-and-a-lead
645
+ */
646
+ runAction(action) {
647
+ if (!action || typeof action !== 'object') {
648
+ return undefined
649
+ }
650
+ const resolved = resolveDeepTokens(action, this.tokenCtx)
651
+ if (typeof this.cnDispatchAction === 'function') {
652
+ return this.cnDispatchAction(resolved)
653
+ }
654
+ return dispatchAction(resolved, { router: this.$router || null })
655
+ },
656
+
657
+ /** Tell the card around the facts what its header shows (the header action). */
658
+ emitHeader() {
659
+ const view = this.headerAction
660
+ /**
661
+ * @event header Emitted with the card header's parts: the header action, if any.
662
+ * @type {{link: null, note: string, action: (object|null)}} `action` is `{ label, icon, run }`.
663
+ */
664
+ this.$emit('header', {
665
+ link: null,
666
+ note: '',
667
+ action: view ? { ...view, run: () => this.runAction(this.content.headerAction) } : null,
668
+ })
669
+ },
670
+
671
+ /**
672
+ * Read the source object.
673
+ *
674
+ * @return {Promise<void>}
675
+ */
676
+ async load() {
677
+ const source = this.resolvedSource
678
+ this.error = false
679
+ if (!source) {
680
+ this.fetched = null
681
+ return
682
+ }
683
+ const url = this.sourceUrl(source)
684
+ if (!url) {
685
+ this.fetched = null
686
+ return
687
+ }
688
+ this.loading = true
689
+ try {
690
+ const [{ default: axios }, { generateUrl }] = await Promise.all([
691
+ import('@nextcloud/axios'),
692
+ import('@nextcloud/router'),
693
+ ])
694
+ const full = url.startsWith('/apps/') || url.startsWith('/ocs/') ? generateUrl(url) : url
695
+ const response = await axios.get(full)
696
+ const data = response && response.data
697
+ this.fetched = data && typeof data === 'object' && !Array.isArray(data) ? data : null
698
+ } catch (e) {
699
+ // eslint-disable-next-line no-console
700
+ console.warn('[CnFactsWidget] the source could not be read:', e?.message || e)
701
+ this.fetched = null
702
+ this.error = true
703
+ } finally {
704
+ this.loading = false
705
+ }
706
+ },
707
+
708
+ /**
709
+ * The URL of a resolved source, or '' when it cannot be read yet.
710
+ *
711
+ * @param {object} source The resolved source.
712
+ * @return {string}
713
+ */
714
+ sourceUrl(source) {
715
+ if (typeof source.url === 'string') {
716
+ return source.url
717
+ }
718
+ if (hasUnresolvedDeepTokens(source)) {
719
+ return ''
720
+ }
721
+ const { register, schema, id } = source
722
+ if (!register || !schema || id === undefined || id === null || id === '' || typeof id === 'object') {
723
+ return ''
724
+ }
725
+ return `/apps/openregister/api/objects/${encodeURIComponent(register)}/${encodeURIComponent(schema)}/${encodeURIComponent(String(id))}`
726
+ },
727
+
728
+ /**
729
+ * The display text of one field.
730
+ *
731
+ * @param {object} record The object.
732
+ * @param {object} field The entry.
733
+ * @return {string}
734
+ */
735
+ valueOf(record, field) {
736
+ const raw = readPath(record, field.path)
737
+ return this.format(raw, field)
738
+ },
739
+
740
+ /**
741
+ * The text of a `line` entry that joins several parts.
742
+ *
743
+ * @param {object} record The object.
744
+ * @param {object} field The entry.
745
+ * @return {string}
746
+ */
747
+ lineValue(record, field) {
748
+ const separator = typeof field.separator === 'string' ? field.separator : ' · '
749
+ return field.parts
750
+ .map((part) => {
751
+ const spec = typeof part === 'string' ? { path: part } : (part || {})
752
+ // A constant part (`{ text }`): "Handelsregister" after the legal form.
753
+ if (!spec.path && typeof spec.text === 'string') {
754
+ return this.tr(spec.text)
755
+ }
756
+ const value = this.format(readPath(record, spec.path), spec)
757
+ if (value === '') {
758
+ return ''
759
+ }
760
+ return spec.label ? `${this.tr(spec.label)} ${value}` : value
761
+ })
762
+ .filter((value) => value !== '')
763
+ .join(separator)
764
+ },
765
+
766
+ /**
767
+ * Format a raw value.
768
+ *
769
+ * @param {unknown} raw The value.
770
+ * @param {object} spec `{ format?, map?, itemPath? }`.
771
+ * @return {string} The text, '' when empty.
772
+ */
773
+ format(raw, spec) {
774
+ if (raw === null || raw === undefined || raw === '') {
775
+ return ''
776
+ }
777
+ const format = spec.format || 'text'
778
+ if (format === 'list' || Array.isArray(raw)) {
779
+ const items = (Array.isArray(raw) ? raw : [raw])
780
+ .map((item) => (spec.itemPath && item && typeof item === 'object' ? readPath(item, spec.itemPath) : item))
781
+ .map((item) => this.format(item, { ...spec, format: 'text' }))
782
+ .filter((item) => item !== '')
783
+ return items.join(', ')
784
+ }
785
+ if (format === 'date' || format === 'date-long') {
786
+ const date = parseDateValue(raw)
787
+ if (date === null) {
788
+ return ''
789
+ }
790
+ // A year far from now forces the long form, so date-long reuses the board formatter.
791
+ return format === 'date-long'
792
+ ? formatBoardDate(date, new Date(date.getFullYear() + 1, 0, 1))
793
+ : formatBoardDate(date)
794
+ }
795
+ if (typeof raw === 'object') {
796
+ const label = raw.title || raw.name || raw.label || raw.displayName
797
+ return typeof label === 'string' ? label : ''
798
+ }
799
+ if (typeof raw === 'boolean') {
800
+ const mapped = spec.map && spec.map[String(raw)]
801
+ return mapped ? this.tr(mapped) : this.tr(raw ? 'Yes' : 'No')
802
+ }
803
+ if (spec.map && Object.hasOwn(spec.map, String(raw))) {
804
+ return this.tr(spec.map[String(raw)])
805
+ }
806
+ return String(raw)
807
+ },
808
+
809
+ /**
810
+ * Replace `@source.<field>` / `@source.id` and the shared tokens in a string.
811
+ *
812
+ * @param {string} value The template.
813
+ * @param {object|null} record The object shown.
814
+ * @return {string} The value, '' when a token stays unresolved.
815
+ */
816
+ resolveTemplate(value, record) {
817
+ if (typeof value !== 'string') {
818
+ return value
819
+ }
820
+ let unresolved = false
821
+ const replaced = value.replace(/@source\.([\w.@]+)/g, (match, path) => {
822
+ const read = record ? (path === 'id' ? (record.id ?? readPath(record, '@self.id')) : readPath(record, path)) : undefined
823
+ if (read === undefined || read === null || read === '') {
824
+ unresolved = true
825
+ return match
826
+ }
827
+ return String(read)
828
+ })
829
+ if (unresolved) {
830
+ return ''
831
+ }
832
+ if (replaced.charAt(0) === '@') {
833
+ const resolved = resolveDeepTokens(replaced, this.tokenCtx)
834
+ return typeof resolved === 'string' && resolved.charAt(0) === '@' ? '' : String(resolved)
835
+ }
836
+ return replaced
837
+ },
838
+
839
+ /**
840
+ * Resolve a route declaration (`{ name, params?, query? }`).
841
+ *
842
+ * @param {object} route The declaration.
843
+ * @param {object|null} record The object shown.
844
+ * @return {object|null} The route, or null when a param stays unresolved.
845
+ */
846
+ resolveRoute(route, record) {
847
+ if (!route || typeof route !== 'object' || !route.name) {
848
+ return null
849
+ }
850
+ const out = { name: route.name }
851
+ for (const key of ['params', 'query']) {
852
+ if (route[key] && typeof route[key] === 'object') {
853
+ out[key] = {}
854
+ for (const [name, value] of Object.entries(route[key])) {
855
+ const resolved = this.resolveTemplate(value, record)
856
+ if (resolved === '') {
857
+ return null
858
+ }
859
+ out[key][name] = resolved
860
+ }
861
+ }
862
+ }
863
+ return out
864
+ },
865
+ },
866
+ }
867
+ </script>
868
+
869
+ <style scoped>
870
+ .cn-facts-widget {
871
+ display: flex;
872
+ flex-direction: column;
873
+ gap: 10px;
874
+ min-width: 0;
875
+ }
876
+
877
+ .cn-facts-widget__rows {
878
+ display: grid;
879
+ grid-template-columns: max-content 1fr;
880
+ gap: 8px 16px;
881
+ margin: 0;
882
+ font-size: 14px;
883
+ }
884
+
885
+ /* Each row is a grid of its own children: the wrapper takes no box. */
886
+ .cn-facts-widget__row {
887
+ display: contents;
888
+ }
889
+
890
+ .cn-facts-widget__label {
891
+ color: var(--color-text-maxcontrast);
892
+ }
893
+
894
+ .cn-facts-widget__value {
895
+ margin: 0;
896
+ font-weight: 500;
897
+ min-width: 0;
898
+ overflow-wrap: anywhere;
899
+ }
900
+
901
+ .cn-facts-widget__title {
902
+ font-size: 15px;
903
+ font-weight: 600;
904
+ color: var(--color-main-text);
905
+ }
906
+
907
+ .cn-facts-widget__line {
908
+ font-size: 13px;
909
+ color: var(--color-text-maxcontrast);
910
+ }
911
+
912
+ .cn-facts-widget__muted {
913
+ margin: 0;
914
+ color: var(--color-text-maxcontrast);
915
+ }
916
+
917
+ .cn-facts-widget__label .hidden-visually {
918
+ clip-path: inset(50%);
919
+ height: 1px;
920
+ overflow: hidden;
921
+ position: absolute;
922
+ white-space: nowrap;
923
+ width: 1px;
924
+ }
925
+
926
+ .cn-facts-widget__label--icon {
927
+ align-items: center;
928
+ display: flex;
929
+ }
930
+
931
+ .cn-facts-widget__value-link {
932
+ color: var(--color-primary-element);
933
+ text-decoration: underline;
934
+ }
935
+
936
+ .cn-facts-widget__inline-button,
937
+ .cn-facts-widget__icon-button,
938
+ .cn-facts-widget__action {
939
+ align-items: center;
940
+ cursor: pointer;
941
+ display: inline-flex;
942
+ font: inherit;
943
+ }
944
+
945
+ .cn-facts-widget__inline-button {
946
+ background: var(--color-main-background);
947
+ border: 1px solid var(--color-border-dark);
948
+ border-radius: 16px;
949
+ font-size: 13px;
950
+ font-weight: 600;
951
+ gap: 4px;
952
+ margin-inline-start: 8px;
953
+ min-height: 28px;
954
+ padding: 0 10px;
955
+ }
956
+
957
+ .cn-facts-widget__icon-button {
958
+ background: transparent;
959
+ border: 0;
960
+ border-radius: 6px;
961
+ color: var(--color-text-maxcontrast);
962
+ margin-inline-start: 4px;
963
+ padding: 2px;
964
+ vertical-align: middle;
965
+ }
966
+
967
+ .cn-facts-widget__icon-button:hover,
968
+ .cn-facts-widget__icon-button:focus-visible {
969
+ background: var(--color-background-hover);
970
+ color: var(--color-main-text);
971
+ }
972
+
973
+ .cn-facts-widget__text {
974
+ color: var(--color-main-text);
975
+ font-size: 15px;
976
+ }
977
+
978
+ /* A lead: an icon tile or initials beside a bold title and a muted subtitle. */
979
+ .cn-facts-widget__lead {
980
+ align-items: center;
981
+ display: flex;
982
+ gap: 12px;
983
+ }
984
+
985
+ .cn-facts-widget__lead-tile {
986
+ align-items: center;
987
+ background: var(--color-background-dark);
988
+ border-radius: 8px;
989
+ color: var(--color-main-text);
990
+ display: flex;
991
+ flex: none;
992
+ font-size: 14px;
993
+ font-weight: 700;
994
+ height: 40px;
995
+ justify-content: center;
996
+ width: 40px;
997
+ }
998
+
999
+ .cn-facts-widget__lead-tile--success {
1000
+ background: color-mix(in srgb, var(--color-success) 14%, var(--color-main-background));
1001
+ border-radius: 50%;
1002
+ color: var(--color-success-text, var(--color-success));
1003
+ }
1004
+
1005
+ .cn-facts-widget__lead-tile--info {
1006
+ background: var(--color-primary-element-light);
1007
+ border-radius: 50%;
1008
+ color: var(--color-primary-element-light-text, var(--color-primary-element));
1009
+ }
1010
+
1011
+ .cn-facts-widget__lead-text {
1012
+ display: flex;
1013
+ flex-direction: column;
1014
+ min-width: 0;
1015
+ }
1016
+
1017
+ .cn-facts-widget__lead-title {
1018
+ font-size: 15px;
1019
+ }
1020
+
1021
+ .cn-facts-widget__lead-subtitle {
1022
+ color: var(--color-text-maxcontrast);
1023
+ font-size: 13px;
1024
+ }
1025
+
1026
+ .cn-facts-widget__action {
1027
+ align-self: flex-start;
1028
+ background: var(--color-primary-element-light);
1029
+ border: 0;
1030
+ border-radius: 16px;
1031
+ color: var(--color-primary-element-light-text, var(--color-primary-element));
1032
+ font-size: 13px;
1033
+ font-weight: 700;
1034
+ gap: 6px;
1035
+ min-height: 32px;
1036
+ padding: 0 14px;
1037
+ }
1038
+
1039
+ .cn-facts-widget__action:hover,
1040
+ .cn-facts-widget__action:focus-visible {
1041
+ background: var(--color-primary-element-light-hover, var(--color-primary-element-light));
1042
+ }
1043
+
1044
+ .cn-facts-widget__link {
1045
+ font-size: 14px;
1046
+ font-weight: 600;
1047
+ color: var(--color-primary-element);
1048
+ text-decoration: underline;
1049
+ }
1050
+ </style>