@xemahq/ui-kernel 0.11.1 → 0.11.2

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 (234) hide show
  1. package/package.json +1 -2
  2. package/src/index.ts +0 -17
  3. package/src/lib/biome-host/agent-validation.ts +0 -239
  4. package/src/lib/biome-host/biome-builders.ts +0 -112
  5. package/src/lib/biome-host/biome-mode.ts +0 -6
  6. package/src/lib/biome-host/biome-navigation.ts +0 -37
  7. package/src/lib/biome-host/biome-registry.ts +0 -299
  8. package/src/lib/biome-host/biome-scope-hooks.ts +0 -41
  9. package/src/lib/biome-host/biome-scope.tsx +0 -52
  10. package/src/lib/biome-host/biome-scoped-query.ts +0 -134
  11. package/src/lib/biome-host/create-biome-orval-config.ts +0 -82
  12. package/src/lib/biome-host/define-web-biome.spec.ts +0 -221
  13. package/src/lib/biome-host/define-web-biome.ts +0 -222
  14. package/src/lib/biome-host/errors.ts +0 -220
  15. package/src/lib/biome-host/frontend-biome.ts +0 -256
  16. package/src/lib/biome-host/host-bridge.ts +0 -281
  17. package/src/lib/biome-host/host-sources.ts +0 -54
  18. package/src/lib/biome-host/i18n-hooks.ts +0 -51
  19. package/src/lib/biome-host/i18n-port.test.ts +0 -50
  20. package/src/lib/biome-host/i18n-port.ts +0 -96
  21. package/src/lib/biome-host/index.ts +0 -35
  22. package/src/lib/biome-host/realtime-hooks.ts +0 -75
  23. package/src/lib/biome-host/realtime-port.ts +0 -115
  24. package/src/lib/biome-host/session-contributions.ts +0 -296
  25. package/src/lib/biome-host/use-mutation-with-error-toast.ts +0 -90
  26. package/src/lib/biome-host/use-page-state.ts +0 -248
  27. package/src/lib/capabilities/capability-context.ts +0 -25
  28. package/src/lib/capabilities/capability-provider.tsx +0 -73
  29. package/src/lib/capabilities/index.ts +0 -17
  30. package/src/lib/capabilities/types.ts +0 -69
  31. package/src/lib/capabilities/use-capability.ts +0 -79
  32. package/src/lib/contribution-registry/contribution-registry.spec.ts +0 -141
  33. package/src/lib/contribution-registry/contribution-registry.ts +0 -204
  34. package/src/lib/contribution-registry/index.ts +0 -9
  35. package/src/lib/contribution-registry/renderable-registry.ts +0 -142
  36. package/src/lib/system-bus/capability-invoke.ts +0 -92
  37. package/src/lib/system-bus/deeplink.ts +0 -210
  38. package/src/lib/system-bus/enums.ts +0 -86
  39. package/src/lib/system-bus/host-ports.ts +0 -93
  40. package/src/lib/system-bus/index.ts +0 -16
  41. package/src/lib/system-bus/intent-registry.ts +0 -109
  42. package/src/lib/system-bus/intents.ts +0 -113
  43. package/src/lib/system-bus/palette.ts +0 -78
  44. package/src/lib/system-bus/system-bus-builder.ts +0 -159
  45. package/src/lib/system-bus/system-bus.ts +0 -37
  46. package/src/lib/system-bus/windows.ts +0 -51
  47. package/src/offline/id.ts +0 -16
  48. package/src/offline/index.ts +0 -54
  49. package/src/offline/mutation.ts +0 -75
  50. package/src/offline/offline-status-badge.tsx +0 -51
  51. package/src/offline/online-controller.ts +0 -105
  52. package/src/offline/outbox.test.ts +0 -172
  53. package/src/offline/outbox.ts +0 -348
  54. package/src/offline/react-hooks.ts +0 -40
  55. package/src/offline/react.tsx +0 -32
  56. package/src/offline/storage.ts +0 -112
  57. package/src/offline/types.ts +0 -77
  58. package/src/org-db/components/DbResultTable.tsx +0 -176
  59. package/src/org-db/index.ts +0 -1
  60. package/src/pdf/index.ts +0 -11
  61. package/src/registry/index.ts +0 -9
  62. package/src/registry/lib/agent-validation-host.ts +0 -36
  63. package/src/registry/lib/biome-slot.tsx +0 -50
  64. package/src/registry/lib/biomes-enabled-context.ts +0 -20
  65. package/src/registry/lib/extension-points.ts +0 -134
  66. package/src/registry/lib/primitives/SessionEventCard.tsx +0 -164
  67. package/src/registry/lib/primitives/SessionEventTimeline.tsx +0 -95
  68. package/src/registry/lib/primitives/SessionMutationBar.tsx +0 -76
  69. package/src/registry/lib/primitives/SessionTabbedDrawer.tsx +0 -165
  70. package/src/registry/lib/primitives/index.ts +0 -18
  71. package/src/registry/lib/session-context-builder.ts +0 -84
  72. package/src/registry/lib/session-context-provider.tsx +0 -33
  73. package/src/registry/lib/session-context.ts +0 -21
  74. package/src/registry/lib/session-selectors.ts +0 -272
  75. package/src/session/comments/CommentRail.tsx +0 -164
  76. package/src/session/index.ts +0 -3
  77. package/src/session/lib/cn.ts +0 -11
  78. package/src/session/shell/SessionWorkspaceShell.tsx +0 -147
  79. package/src/session-kit/approvals/ApprovalButton.tsx +0 -89
  80. package/src/session-kit/approvals/ApprovalCard.tsx +0 -341
  81. package/src/session-kit/approvals/ApprovalsCenter.tsx +0 -336
  82. package/src/session-kit/approvals/CapabilityApprovalStickyBar.tsx +0 -118
  83. package/src/session-kit/approvals/Obligation.tsx +0 -111
  84. package/src/session-kit/approvals/ScopedBody.tsx +0 -392
  85. package/src/session-kit/approvals/approval-icons.ts +0 -31
  86. package/src/session-kit/approvals/approval-model.ts +0 -204
  87. package/src/session-kit/approvals/index.ts +0 -22
  88. package/src/session-kit/approvals/obligation-display.ts +0 -100
  89. package/src/session-kit/approvals/risk-accent.ts +0 -47
  90. package/src/session-kit/approvals/scope-icons.ts +0 -19
  91. package/src/session-kit/combobox/Combobox.tsx +0 -358
  92. package/src/session-kit/combobox/use-click-outside.ts +0 -21
  93. package/src/session-kit/display/ContextHeader.tsx +0 -148
  94. package/src/session-kit/display/FileDiffCard.tsx +0 -140
  95. package/src/session-kit/display/MD.tsx +0 -162
  96. package/src/session-kit/display/MessageTurn.tsx +0 -157
  97. package/src/session-kit/display/ThinkingPanel.tsx +0 -81
  98. package/src/session-kit/display/TodoChecklist.tsx +0 -120
  99. package/src/session-kit/display/TokenMeter.tsx +0 -89
  100. package/src/session-kit/display/ToolStrip.tsx +0 -278
  101. package/src/session-kit/display/TypingDots.tsx +0 -24
  102. package/src/session-kit/index.ts +0 -44
  103. package/src/session-kit/lib/enums.ts +0 -66
  104. package/src/session-kit/lib/portal-accent.ts +0 -30
  105. package/src/session-kit/lib/status-dot.ts +0 -68
  106. package/src/session-kit/primitives/Avatar.tsx +0 -44
  107. package/src/session-kit/primitives/PortalGlyph.tsx +0 -51
  108. package/src/session-kit/primitives/RiskPill.tsx +0 -95
  109. package/src/session-kit/primitives/ScopeDot.tsx +0 -47
  110. package/src/session-kit/primitives/Segmented.tsx +0 -71
  111. package/src/ui/branding/app-branding-context.ts +0 -20
  112. package/src/ui/branding/app-branding-provider.tsx +0 -123
  113. package/src/ui/branding/sanitize.ts +0 -89
  114. package/src/ui/breakpoints.ts +0 -14
  115. package/src/ui/capture/document-preview.tsx +0 -166
  116. package/src/ui/capture/field-spec-to-zod.test.ts +0 -81
  117. package/src/ui/capture/field-spec-to-zod.ts +0 -174
  118. package/src/ui/capture/field-spec-validate.ts +0 -236
  119. package/src/ui/capture/field-spec.test.ts +0 -49
  120. package/src/ui/capture/field-spec.ts +0 -274
  121. package/src/ui/capture/index.ts +0 -51
  122. package/src/ui/capture/schema-field-input.tsx +0 -620
  123. package/src/ui/capture/schema-form.tsx +0 -149
  124. package/src/ui/capture/submit-values.test.ts +0 -70
  125. package/src/ui/capture/submit-values.ts +0 -63
  126. package/src/ui/capture/use-prefill.ts +0 -186
  127. package/src/ui/capture/use-schema-validation.ts +0 -145
  128. package/src/ui/capture/use-wizard.ts +0 -180
  129. package/src/ui/capture/value-format.ts +0 -32
  130. package/src/ui/capture/wizard.tsx +0 -105
  131. package/src/ui/charts/bar-chart.tsx +0 -139
  132. package/src/ui/charts/chart-frame.tsx +0 -125
  133. package/src/ui/charts/chart-types.ts +0 -52
  134. package/src/ui/charts/chart-utils.ts +0 -190
  135. package/src/ui/charts/charts.test.tsx +0 -204
  136. package/src/ui/charts/donut-chart.tsx +0 -129
  137. package/src/ui/charts/index.ts +0 -27
  138. package/src/ui/charts/line-chart.tsx +0 -202
  139. package/src/ui/charts/sparkline.tsx +0 -109
  140. package/src/ui/chrome/AsyncBoundary.tsx +0 -74
  141. package/src/ui/chrome/EmptyState.tsx +0 -257
  142. package/src/ui/chrome/ErrorCard.tsx +0 -63
  143. package/src/ui/chrome/LoadingState.tsx +0 -61
  144. package/src/ui/chrome/PageHeader.tsx +0 -137
  145. package/src/ui/chrome/RecordCardList.tsx +0 -98
  146. package/src/ui/chrome/StateCard.tsx +0 -150
  147. package/src/ui/chrome/confirm-delete-dialog.tsx +0 -59
  148. package/src/ui/chrome/page-shell.spec.tsx +0 -117
  149. package/src/ui/chrome/page-shell.tsx +0 -221
  150. package/src/ui/chrome/scope-badge.tsx +0 -40
  151. package/src/ui/chrome/status-badge.tsx +0 -79
  152. package/src/ui/cn.ts +0 -32
  153. package/src/ui/design-tokens.ts +0 -372
  154. package/src/ui/hooks/use-debounced-value.ts +0 -16
  155. package/src/ui/hooks/use-is-mobile.ts +0 -28
  156. package/src/ui/index.ts +0 -110
  157. package/src/ui/pdf/pdf-preview.tsx +0 -122
  158. package/src/ui/primitives/alert-dialog.tsx +0 -104
  159. package/src/ui/primitives/async-combobox.tsx +0 -182
  160. package/src/ui/primitives/badge-variants.ts +0 -21
  161. package/src/ui/primitives/badge.tsx +0 -25
  162. package/src/ui/primitives/button-variants.ts +0 -31
  163. package/src/ui/primitives/button.tsx +0 -29
  164. package/src/ui/primitives/card.tsx +0 -43
  165. package/src/ui/primitives/checkbox.tsx +0 -26
  166. package/src/ui/primitives/collapsible.tsx +0 -9
  167. package/src/ui/primitives/dialog.tsx +0 -103
  168. package/src/ui/primitives/dropdown-menu.tsx +0 -179
  169. package/src/ui/primitives/form-stepper.tsx +0 -94
  170. package/src/ui/primitives/form-stepper.types.ts +0 -15
  171. package/src/ui/primitives/input.tsx +0 -22
  172. package/src/ui/primitives/label.tsx +0 -17
  173. package/src/ui/primitives/overflow-tabs.tsx +0 -331
  174. package/src/ui/primitives/popover.tsx +0 -33
  175. package/src/ui/primitives/preview-device-frame.tsx +0 -213
  176. package/src/ui/primitives/radio-group.tsx +0 -36
  177. package/src/ui/primitives/resizable.tsx +0 -67
  178. package/src/ui/primitives/scroll-area.tsx +0 -38
  179. package/src/ui/primitives/select.tsx +0 -143
  180. package/src/ui/primitives/separator.tsx +0 -20
  181. package/src/ui/primitives/sheet.tsx +0 -107
  182. package/src/ui/primitives/skeleton.tsx +0 -99
  183. package/src/ui/primitives/switch.tsx +0 -27
  184. package/src/ui/primitives/table.tsx +0 -72
  185. package/src/ui/primitives/tabs.tsx +0 -53
  186. package/src/ui/primitives/tag-multi-select.tsx +0 -261
  187. package/src/ui/primitives/textarea.tsx +0 -21
  188. package/src/ui/primitives/tooltip.tsx +0 -30
  189. package/src/ui/primitives/url-preview-chrome.tsx +0 -103
  190. package/src/vista/GenericCatalogueSurface.tsx +0 -179
  191. package/src/vista/SurfaceFallbackCard.tsx +0 -109
  192. package/src/vista/VistaPanel.tsx +0 -163
  193. package/src/vista/form-payload.spec.ts +0 -139
  194. package/src/vista/html/CustomUiFrame.spec.tsx +0 -127
  195. package/src/vista/html/CustomUiFrame.tsx +0 -206
  196. package/src/vista/html/custom-ui-frame-bridge.spec.ts +0 -191
  197. package/src/vista/html/custom-ui-frame-bridge.ts +0 -98
  198. package/src/vista/html/custom-ui-frame-contract.ts +0 -88
  199. package/src/vista/html/custom-ui-intents.spec.ts +0 -135
  200. package/src/vista/html/custom-ui-intents.ts +0 -155
  201. package/src/vista/html/custom-ui-srcdoc.spec.ts +0 -151
  202. package/src/vista/html/custom-ui-srcdoc.ts +0 -193
  203. package/src/vista/html/index.ts +0 -13
  204. package/src/vista/index.ts +0 -52
  205. package/src/vista/surface-catalogue.spec.ts +0 -140
  206. package/src/vista/surface-catalogue.ts +0 -90
  207. package/src/vista/surface-icons.ts +0 -57
  208. package/src/vista/surface-registry.ts +0 -56
  209. package/src/vista/surfaces/ChartSurface.tsx +0 -34
  210. package/src/vista/surfaces/FilesSurface.tsx +0 -202
  211. package/src/vista/surfaces/FormSurface.tsx +0 -380
  212. package/src/vista/surfaces/HtmlSurface.tsx +0 -43
  213. package/src/vista/surfaces/TableSurface.tsx +0 -100
  214. package/src/vista/surfaces/UrlSurface.tsx +0 -40
  215. package/src/vista/surfaces/blob-surfaces.tsx +0 -139
  216. package/src/vista/surfaces/elicitation-transport.spec.ts +0 -369
  217. package/src/vista/surfaces/elicitation-transport.ts +0 -367
  218. package/src/vista/surfaces/file-surface-utils.ts +0 -69
  219. package/src/vista/surfaces/index.ts +0 -24
  220. package/src/vista/surfaces/register-surfaces.tsx +0 -139
  221. package/src/vista/surfaces/text-surfaces.tsx +0 -132
  222. package/src/vista/use-vista-tabs.ts +0 -196
  223. package/src/vista/vista-code-renderer-context.ts +0 -16
  224. package/src/vista/vista-code-renderer.tsx +0 -35
  225. package/src/vista/vista-file-context.ts +0 -14
  226. package/src/vista/vista-file-source.tsx +0 -141
  227. package/src/vista/vista-form-context.ts +0 -20
  228. package/src/vista/vista-form-host.tsx +0 -48
  229. package/src/vista/vista-model.ts +0 -137
  230. package/src/vista/vista-open-context.tsx +0 -27
  231. package/src/vista/vista-open-state.ts +0 -11
  232. package/src/vista/vista-payloads.ts +0 -635
  233. package/src/vista/vista-tabs-manifest.ts +0 -138
  234. package/src/vista/vista-tools.ts +0 -232
@@ -1,95 +0,0 @@
1
- /**
2
- * Capability risk-tier pill. Reuses the kernel `CapabilityRiskTier`
3
- * enum (low / medium / high / critical) — it does NOT define a parallel
4
- * string union. Critical renders an optional caller-supplied alert icon
5
- * (the kit carries no icon dependency, matching the rest of ui-kernel).
6
- *
7
- * Risk → colour:
8
- * low → ink / muted
9
- * medium → --info
10
- * high → --warning
11
- * critical → --destructive (always explicit)
12
- */
13
- import { CapabilityRiskTier } from '@xemahq/kernel-contracts/capability';
14
-
15
- import type { CSSProperties, ReactElement, ReactNode } from 'react';
16
-
17
- export { CapabilityRiskTier };
18
-
19
- interface RiskStyle {
20
- readonly label: string;
21
- readonly fg: string;
22
- readonly bg: string;
23
- readonly bd: string;
24
- }
25
-
26
- const DANGER = 'var(--destructive, var(--danger))';
27
-
28
- const RISK: Record<CapabilityRiskTier, RiskStyle> = {
29
- [CapabilityRiskTier.Low]: {
30
- label: 'Low',
31
- fg: 'hsl(var(--ink-3))',
32
- bg: 'hsl(var(--muted))',
33
- bd: 'hsl(var(--rule))',
34
- },
35
- [CapabilityRiskTier.Medium]: {
36
- label: 'Medium',
37
- fg: 'hsl(var(--info))',
38
- bg: 'hsl(var(--info) / 0.09)',
39
- bd: 'hsl(var(--info) / 0.28)',
40
- },
41
- [CapabilityRiskTier.High]: {
42
- label: 'High',
43
- fg: 'hsl(var(--warning))',
44
- bg: 'hsl(var(--warning) / 0.1)',
45
- bd: 'hsl(var(--warning) / 0.3)',
46
- },
47
- [CapabilityRiskTier.Critical]: {
48
- label: 'Critical',
49
- fg: `hsl(${DANGER})`,
50
- bg: `hsl(${DANGER} / 0.09)`,
51
- bd: `hsl(${DANGER} / 0.32)`,
52
- },
53
- };
54
-
55
- export type RiskPillSize = 'xs' | 'sm';
56
-
57
- export interface RiskPillProps {
58
- readonly tier: CapabilityRiskTier;
59
- readonly size?: RiskPillSize;
60
- /** Rendered before the label for the `critical` tier (e.g. an alert glyph). */
61
- readonly criticalIcon?: ReactNode;
62
- readonly style?: CSSProperties;
63
- }
64
-
65
- export function RiskPill({
66
- tier,
67
- size = 'sm',
68
- criticalIcon,
69
- style,
70
- }: RiskPillProps): ReactElement {
71
- const r = RISK[tier];
72
- return (
73
- <span
74
- className="mono"
75
- style={{
76
- display: 'inline-flex',
77
- alignItems: 'center',
78
- gap: 4,
79
- padding: size === 'xs' ? '1px 6px' : '2px 8px',
80
- fontSize: size === 'xs' ? 9.5 : 10,
81
- fontWeight: 600,
82
- textTransform: 'uppercase',
83
- letterSpacing: '0.06em',
84
- color: r.fg,
85
- background: r.bg,
86
- border: `1px solid ${r.bd}`,
87
- borderRadius: 5,
88
- ...style,
89
- }}
90
- >
91
- {tier === CapabilityRiskTier.Critical && criticalIcon}
92
- {r.label}
93
- </span>
94
- );
95
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * Biome provenance dot — a tiny colour-coded circle keyed on
3
- * `BiomeScope` (system / platform / community).
4
- */
5
- import { BiomeScope } from '../lib/enums';
6
-
7
- import type { CSSProperties, ReactElement } from 'react';
8
-
9
-
10
- interface ScopeStyle {
11
- readonly color: string;
12
- readonly label: string;
13
- }
14
-
15
- const SCOPE: Record<BiomeScope, ScopeStyle> = {
16
- [BiomeScope.System]: { color: 'hsl(var(--ink-4))', label: 'System' },
17
- [BiomeScope.Platform]: { color: 'hsl(var(--primary))', label: 'Platform' },
18
- [BiomeScope.Community]: { color: 'hsl(var(--p-people))', label: 'Community' },
19
- };
20
-
21
- export interface ScopeDotProps {
22
- readonly scope: BiomeScope;
23
- readonly size?: number;
24
- readonly style?: CSSProperties;
25
- }
26
-
27
- export function ScopeDot({
28
- scope,
29
- size = 7,
30
- style,
31
- }: ScopeDotProps): ReactElement {
32
- const s = SCOPE[scope];
33
- return (
34
- <span
35
- title={s.label}
36
- style={{
37
- width: size,
38
- height: size,
39
- borderRadius: '50%',
40
- background: s.color,
41
- flexShrink: 0,
42
- display: 'inline-block',
43
- ...style,
44
- }}
45
- />
46
- );
47
- }
@@ -1,71 +0,0 @@
1
- /**
2
- * Small segmented control. Generic over the option value type so a
3
- * caller can drive it with a closed enum directly.
4
- */
5
- import type { CSSProperties, ReactElement, ReactNode } from 'react';
6
-
7
- export interface SegmentedOption<V extends string> {
8
- readonly value: V;
9
- readonly label: ReactNode;
10
- /** Optional leading icon node (host-supplied). */
11
- readonly icon?: ReactNode;
12
- }
13
-
14
- export type SegmentedSize = 'sm' | 'md';
15
-
16
- export interface SegmentedProps<V extends string> {
17
- readonly options: ReadonlyArray<SegmentedOption<V>>;
18
- readonly value: V;
19
- readonly onChange: (value: V) => void;
20
- readonly size?: SegmentedSize;
21
- readonly style?: CSSProperties;
22
- }
23
-
24
- export function Segmented<V extends string>({
25
- options,
26
- value,
27
- onChange,
28
- size = 'sm',
29
- style,
30
- }: SegmentedProps<V>): ReactElement {
31
- return (
32
- <div
33
- style={{
34
- display: 'inline-flex',
35
- padding: 2,
36
- gap: 2,
37
- background: 'hsl(var(--paper-sunk))',
38
- border: '1px solid hsl(var(--rule))',
39
- borderRadius: 8,
40
- ...style,
41
- }}
42
- >
43
- {options.map((option) => {
44
- const on = option.value === value;
45
- return (
46
- <button
47
- key={option.value}
48
- type="button"
49
- onClick={() => onChange(option.value)}
50
- style={{
51
- display: 'inline-flex',
52
- alignItems: 'center',
53
- gap: 5,
54
- padding: size === 'sm' ? '4px 10px' : '6px 12px',
55
- fontSize: size === 'sm' ? 12 : 13,
56
- fontWeight: on ? 600 : 450,
57
- borderRadius: 6,
58
- color: on ? 'hsl(var(--ink))' : 'hsl(var(--ink-3))',
59
- background: on ? 'hsl(var(--paper-elev))' : 'transparent',
60
- boxShadow: on ? 'var(--shadow-2, var(--shadow-1))' : 'none',
61
- transition: 'background 140ms ease, color 140ms ease, box-shadow 140ms ease',
62
- }}
63
- >
64
- {option.icon}
65
- {option.label}
66
- </button>
67
- );
68
- })}
69
- </div>
70
- );
71
- }
@@ -1,20 +0,0 @@
1
- import * as React from 'react';
2
-
3
- export interface AppBrandingContextValue {
4
- readonly displayName: string;
5
- readonly logoUrl?: string;
6
- readonly primaryColor?: string;
7
- }
8
-
9
- export const AppBrandingContext =
10
- React.createContext<AppBrandingContextValue | null>(null);
11
-
12
- export function useAppBranding(): AppBrandingContextValue {
13
- const ctx = React.useContext(AppBrandingContext);
14
- if (ctx === null) {
15
- throw new Error(
16
- 'useAppBranding must be used within an <AppBrandingProvider>.',
17
- );
18
- }
19
- return ctx;
20
- }
@@ -1,123 +0,0 @@
1
- // ═══════════════════════════════════════════════════════════════════════════
2
- // AppBrandingProvider — the runtime branding applier
3
- //
4
- // Takes a kernel `BrandingConfig` (plus an optional per-sub-tenant override)
5
- // and APPLIES it at runtime:
6
- //
7
- // • writes `primaryColor` → `--app-primary-color` and every `cssTokens`
8
- // entry → `--<key>` as CSS custom properties on its OWN wrapper element,
9
- // so they cascade ONLY to the app subtree — never onto
10
- // `document.documentElement`, so an app's branding cannot leak into the
11
- // host chrome;
12
- // • exposes `displayName` / `logoUrl` / `primaryColor` to children through
13
- // context (`useAppBranding`) for a branded header to render.
14
- //
15
- // Every value crosses `sanitize.ts` first: an unsafe CSS value or a
16
- // non-`http(s)` logo URL is dropped, never written raw.
17
- //
18
- // This is the reusable half of Wave 8.4 — a biome imports it from
19
- // `@xemahq/ui-kernel/ui`, like `useIsMobile` / `Sheet`.
20
- // ═══════════════════════════════════════════════════════════════════════════
21
- import * as React from 'react';
22
-
23
- import { cn } from '../cn';
24
- import {
25
- AppBrandingContext,
26
- type AppBrandingContextValue,
27
- } from './app-branding-context';
28
- import {
29
- sanitizeCssCustomPropertyName,
30
- sanitizeCssValue,
31
- sanitizeLogoUrl,
32
- } from './sanitize';
33
-
34
- import type { BrandingConfig } from '@xemahq/kernel-contracts/app-platform';
35
-
36
- /** CSS custom property carrying the app's resolved primary brand color. */
37
- export const APP_PRIMARY_COLOR_VAR = '--app-primary-color';
38
-
39
- export interface AppBrandingProviderProps {
40
- /** The app's base branding (from the App definition / release). */
41
- readonly branding: BrandingConfig;
42
- /**
43
- * Per-sub-tenant override, resolved from `AppRoleBinding.tenantId`. Each
44
- * present field shadows the base; absent fields fall through to `branding`.
45
- * Optional — apps with no sub-tenant branding pass nothing.
46
- */
47
- readonly tenantBranding?: Partial<BrandingConfig>;
48
- /** Extra classes for the wrapper element. */
49
- readonly className?: string;
50
- readonly children: React.ReactNode;
51
- }
52
-
53
- /**
54
- * Merge base branding with an optional per-sub-tenant override (override wins
55
- * per field), then sanitize every applied value.
56
- */
57
- function resolveBranding(
58
- branding: BrandingConfig,
59
- tenantBranding: Partial<BrandingConfig> | undefined,
60
- ): {
61
- readonly context: AppBrandingContextValue;
62
- readonly cssVars: Record<string, string>;
63
- } {
64
- const displayName = tenantBranding?.displayName ?? branding.displayName;
65
- const rawPrimary = tenantBranding?.primaryColor ?? branding.primaryColor;
66
- const rawLogo = tenantBranding?.logoUrl ?? branding.logoUrl;
67
- const cssTokens = { ...branding.cssTokens, ...tenantBranding?.cssTokens };
68
-
69
- const primaryColor =
70
- rawPrimary !== undefined
71
- ? (sanitizeCssValue(rawPrimary) ?? undefined)
72
- : undefined;
73
- const logoUrl = sanitizeLogoUrl(rawLogo);
74
-
75
- const cssVars: Record<string, string> = {};
76
- if (primaryColor !== undefined) {
77
- cssVars[APP_PRIMARY_COLOR_VAR] = primaryColor;
78
- }
79
- for (const [rawKey, rawValue] of Object.entries(cssTokens)) {
80
- const name = sanitizeCssCustomPropertyName(rawKey);
81
- const value = sanitizeCssValue(rawValue);
82
- if (name !== null && value !== null) {
83
- cssVars[name] = value;
84
- }
85
- }
86
-
87
- return {
88
- context: { displayName, logoUrl, primaryColor },
89
- cssVars,
90
- };
91
- }
92
-
93
- /**
94
- * Scopes an app's branding to its subtree. Renders a wrapper element carrying
95
- * the CSS custom properties inline, so they cascade to the app content and
96
- * nowhere else. On unmount the element (and its properties) simply disappear —
97
- * no cleanup, no global mutation.
98
- */
99
- export function AppBrandingProvider({
100
- branding,
101
- tenantBranding,
102
- className,
103
- children,
104
- }: AppBrandingProviderProps): React.ReactElement {
105
- const { context, cssVars } = React.useMemo(
106
- () => resolveBranding(branding, tenantBranding),
107
- [branding, tenantBranding],
108
- );
109
-
110
- return (
111
- <AppBrandingContext.Provider value={context}>
112
- <div
113
- data-app-branding=""
114
- className={cn(className)}
115
- // Custom properties are not part of `React.CSSProperties`; the cast is
116
- // the standard way to set `--*` vars inline.
117
- style={cssVars}
118
- >
119
- {children}
120
- </div>
121
- </AppBrandingContext.Provider>
122
- );
123
- }
@@ -1,89 +0,0 @@
1
- // ═══════════════════════════════════════════════════════════════════════════
2
- // Branding DOM-boundary sanitizers
3
- //
4
- // A `BrandingConfig` is validated server-side (hex/rgb(a) `primaryColor`, a
5
- // URL `logoUrl`), but the runtime applier writes those values into the live
6
- // DOM — a CSS custom-property value and an `<img src>`. This module is the
7
- // fail-closed boundary: a value that could break out of the property it is
8
- // written into, or a URL scheme that could execute, is DROPPED (returns
9
- // `null` / `undefined`), never written raw. Pure functions, no React — unit
10
- // tested directly.
11
- // ═══════════════════════════════════════════════════════════════════════════
12
-
13
- /**
14
- * Characters that could terminate a CSS declaration/value and inject a new
15
- * declaration or rule (`;`, `{`, `}`), close a surrounding context (`<`, `>`),
16
- * escape (`\`), or open/close a CSS comment. React writes custom properties
17
- * through the CSSOM, which already treats the string as a single value — this
18
- * is defence in depth so a crafted value is refused at the seam.
19
- */
20
- const CSS_VALUE_UNSAFE = /[;{}<>\\]|\/\*|\*\//;
21
-
22
- /**
23
- * A CSS custom-property name (without the leading `--`): a CSS identifier. A
24
- * `cssTokens` key becomes `--<key>`, so a key with breakout characters would be
25
- * a foothold; anything that is not a plain ident is refused.
26
- */
27
- const CSS_CUSTOM_PROPERTY_NAME = /^[a-zA-Z_][a-zA-Z0-9_-]*$/;
28
-
29
- /** True when the string contains any ASCII control character (0x00–0x1f, 0x7f). */
30
- function hasControlChar(value: string): boolean {
31
- for (let i = 0; i < value.length; i += 1) {
32
- const code = value.charCodeAt(i);
33
- if (code < 0x20 || code === 0x7f) {
34
- return true;
35
- }
36
- }
37
- return false;
38
- }
39
-
40
- /**
41
- * Sanitize a value destined for a CSS custom property (`--app-primary-color`
42
- * or a `cssTokens` value). Returns the trimmed value, or `null` to DROP it.
43
- */
44
- export function sanitizeCssValue(raw: string): string | null {
45
- const value = raw.trim();
46
- if (value.length === 0) {
47
- return null;
48
- }
49
- if (CSS_VALUE_UNSAFE.test(value)) {
50
- return null;
51
- }
52
- if (hasControlChar(value)) {
53
- return null;
54
- }
55
- return value;
56
- }
57
-
58
- /**
59
- * Sanitize a `cssTokens` KEY into a `--<name>` custom-property name. Returns
60
- * the full property name (`--<name>`), or `null` to DROP the token.
61
- */
62
- export function sanitizeCssCustomPropertyName(rawKey: string): string | null {
63
- const name = rawKey.trim();
64
- if (!CSS_CUSTOM_PROPERTY_NAME.test(name)) {
65
- return null;
66
- }
67
- return `--${name}`;
68
- }
69
-
70
- /**
71
- * Sanitize a logo URL destined for an `<img src>`. Only absolute `http(s)`
72
- * URLs pass; a `javascript:`, `data:`, or otherwise-schemed / unparseable value
73
- * is refused (returns `undefined`) so it never reaches `src`.
74
- */
75
- export function sanitizeLogoUrl(raw: string | undefined): string | undefined {
76
- if (raw === undefined) {
77
- return undefined;
78
- }
79
- let parsed: URL;
80
- try {
81
- parsed = new URL(raw);
82
- } catch {
83
- return undefined;
84
- }
85
- if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
86
- return undefined;
87
- }
88
- return parsed.href;
89
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * Responsive breakpoint token — the single source of truth shared by the
3
- * JS side (`useIsMobile`) and Tailwind's `md` utility.
4
- *
5
- * Tailwind's default `md` breakpoint is `min-width: 768px`. Anything narrower
6
- * than that is "mobile". Binding the JS constant to that exact value is what
7
- * lets a component decide table-vs-cards in JS and stay in lockstep with the
8
- * `md:` classes the same component (or its siblings) use — there is exactly
9
- * ONE breakpoint system, not two.
10
- *
11
- * If the Tailwind `md` screen is ever re-tuned, change it HERE and in the
12
- * Tailwind theme in the same commit — they are two faces of one token.
13
- */
14
- export const MOBILE_BREAKPOINT = 768;
@@ -1,166 +0,0 @@
1
- // ═══════════════════════════════════════════════════════════════════════════
2
- // <DocumentPreview> — read-only "final document" view for the review step
3
- //
4
- // Renders a structured record as the document it will become — grouped by
5
- // section, one labelled row per field, nested objects/lists expanded inline.
6
- // Presentational + theme-aware (semantic tokens, light/dark) + responsive.
7
- // Feed it the SAME schema you gave `<SchemaForm>` so the review mirrors input.
8
- // ═══════════════════════════════════════════════════════════════════════════
9
- import { type ReactNode } from 'react';
10
-
11
- import { cn } from '../cn';
12
- import {
13
- CaptureFieldType,
14
- type CaptureFieldSpec,
15
- type CaptureSchema,
16
- type CaptureSection,
17
- type CaptureValues,
18
- toSections,
19
- } from './field-spec';
20
- import { formatScalar } from './value-format';
21
-
22
- export interface DocumentPreviewProps {
23
- readonly fields?: readonly CaptureFieldSpec[];
24
- readonly sections?: readonly CaptureSection[];
25
- readonly schema?: CaptureSchema;
26
- readonly values: CaptureValues;
27
- readonly title?: string;
28
- /** Text shown for an unset field (default "—"). */
29
- readonly emptyText?: string;
30
- readonly className?: string;
31
- }
32
-
33
- /**
34
- * @example
35
- * <DocumentPreview title="Review" sections={sections} values={values} />
36
- */
37
- export function DocumentPreview({
38
- fields,
39
- sections,
40
- schema,
41
- values,
42
- title,
43
- emptyText = '—',
44
- className,
45
- }: DocumentPreviewProps) {
46
- const resolved = toSections(sections ?? (fields ? fields : schema) ?? []);
47
- return (
48
- <article
49
- className={cn(
50
- 'rounded-xl border border-border bg-card p-5 text-card-foreground shadow-sm sm:p-6',
51
- className,
52
- )}
53
- >
54
- {title ? (
55
- <h2 className="mb-4 text-title font-semibold tracking-tight text-ink">
56
- {title}
57
- </h2>
58
- ) : null}
59
- <div className="space-y-6">
60
- {resolved.map((section) => (
61
- <section key={section.key}>
62
- {section.title ? (
63
- <h3 className="mb-2 border-b border-rule pb-1 text-caption font-semibold uppercase tracking-wider text-ink-3">
64
- {section.title}
65
- </h3>
66
- ) : null}
67
- <dl className="grid grid-cols-1 gap-x-6 gap-y-3 sm:grid-cols-[minmax(8rem,12rem)_1fr]">
68
- {section.fields.map((field) => (
69
- <FieldRow
70
- key={field.key}
71
- field={field}
72
- value={values[field.key]}
73
- emptyText={emptyText}
74
- />
75
- ))}
76
- </dl>
77
- </section>
78
- ))}
79
- </div>
80
- </article>
81
- );
82
- }
83
-
84
- function FieldRow({
85
- field,
86
- value,
87
- emptyText,
88
- }: {
89
- field: CaptureFieldSpec;
90
- value: unknown;
91
- emptyText: string;
92
- }) {
93
- return (
94
- <>
95
- <dt className="text-body-1 font-medium text-ink-3 sm:text-right">
96
- {field.label}
97
- </dt>
98
- <dd className="min-w-0 text-body-1 text-ink">
99
- {renderValue(field, value, emptyText)}
100
- </dd>
101
- </>
102
- );
103
- }
104
-
105
- function renderValue(
106
- field: CaptureFieldSpec,
107
- value: unknown,
108
- emptyText: string,
109
- ): ReactNode {
110
- if (field.type === CaptureFieldType.Object) {
111
- const record = (
112
- value && typeof value === 'object' && !Array.isArray(value) ? value : null
113
- ) as CaptureValues | null;
114
- if (!record) {
115
- return <span className="text-ink-3">{emptyText}</span>;
116
- }
117
- return (
118
- <dl className="space-y-1 rounded-md border border-rule bg-paper-elev/40 p-2">
119
- {(field.fields ?? []).map((child) => (
120
- <div key={child.key} className="flex flex-wrap gap-2">
121
- <dt className="text-caption font-medium text-ink-3">
122
- {child.label}:
123
- </dt>
124
- <dd className="text-caption text-ink">
125
- {renderValue(child, record[child.key], emptyText)}
126
- </dd>
127
- </div>
128
- ))}
129
- </dl>
130
- );
131
- }
132
- if (field.type === CaptureFieldType.List) {
133
- const items = (Array.isArray(value) ? value : []) as CaptureValues[];
134
- if (items.length === 0) {
135
- return <span className="text-ink-3">{emptyText}</span>;
136
- }
137
- return (
138
- <ol className="space-y-2">
139
- {items.map((item, index) => (
140
- <li
141
- key={index}
142
- className="rounded-md border border-rule bg-paper-elev/40 p-2"
143
- >
144
- <p className="mb-1 text-caption font-medium text-ink-3">
145
- {field.label} #{index + 1}
146
- </p>
147
- <dl className="space-y-1">
148
- {(field.fields ?? []).map((child) => (
149
- <div key={child.key} className="flex flex-wrap gap-2">
150
- <dt className="text-caption font-medium text-ink-3">
151
- {child.label}:
152
- </dt>
153
- <dd className="text-caption text-ink">
154
- {renderValue(child, item[child.key], emptyText)}
155
- </dd>
156
- </div>
157
- ))}
158
- </dl>
159
- </li>
160
- ))}
161
- </ol>
162
- );
163
- }
164
- const text = formatScalar(field, value, emptyText);
165
- return <span className={cn(text === emptyText && 'text-ink-3')}>{text}</span>;
166
- }