@xemahq/ui-kernel 0.9.0 → 0.9.1

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 (238) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/biome-host/biome-registry.d.ts.map +1 -1
  6. package/dist/lib/biome-host/biome-registry.js +14 -9
  7. package/dist/lib/biome-host/biome-registry.js.map +1 -1
  8. package/dist/lib/contribution-registry/contribution-registry.d.ts +24 -0
  9. package/dist/lib/contribution-registry/contribution-registry.d.ts.map +1 -0
  10. package/dist/lib/contribution-registry/contribution-registry.js +67 -0
  11. package/dist/lib/contribution-registry/contribution-registry.js.map +1 -0
  12. package/dist/lib/contribution-registry/index.d.ts +3 -0
  13. package/dist/lib/contribution-registry/index.d.ts.map +1 -0
  14. package/dist/lib/contribution-registry/index.js +3 -0
  15. package/dist/lib/contribution-registry/index.js.map +1 -0
  16. package/dist/lib/contribution-registry/renderable-registry.d.ts +33 -0
  17. package/dist/lib/contribution-registry/renderable-registry.d.ts.map +1 -0
  18. package/dist/lib/contribution-registry/renderable-registry.js +51 -0
  19. package/dist/lib/contribution-registry/renderable-registry.js.map +1 -0
  20. package/dist/ui/capture/field-spec-to-zod.d.ts +1 -0
  21. package/dist/ui/capture/field-spec-to-zod.d.ts.map +1 -1
  22. package/dist/ui/capture/field-spec-to-zod.js +19 -0
  23. package/dist/ui/capture/field-spec-to-zod.js.map +1 -1
  24. package/dist/ui/capture/field-spec-validate.d.ts +4 -0
  25. package/dist/ui/capture/field-spec-validate.d.ts.map +1 -0
  26. package/dist/ui/capture/field-spec-validate.js +129 -0
  27. package/dist/ui/capture/field-spec-validate.js.map +1 -0
  28. package/dist/ui/capture/field-spec.d.ts +13 -1
  29. package/dist/ui/capture/field-spec.d.ts.map +1 -1
  30. package/dist/ui/capture/field-spec.js +25 -0
  31. package/dist/ui/capture/field-spec.js.map +1 -1
  32. package/dist/ui/capture/index.d.ts +4 -2
  33. package/dist/ui/capture/index.d.ts.map +1 -1
  34. package/dist/ui/capture/index.js +4 -2
  35. package/dist/ui/capture/index.js.map +1 -1
  36. package/dist/ui/capture/schema-field-input.d.ts.map +1 -1
  37. package/dist/ui/capture/schema-field-input.js +39 -12
  38. package/dist/ui/capture/schema-field-input.js.map +1 -1
  39. package/dist/ui/capture/submit-values.d.ts +6 -0
  40. package/dist/ui/capture/submit-values.d.ts.map +1 -0
  41. package/dist/ui/capture/submit-values.js +28 -0
  42. package/dist/ui/capture/submit-values.js.map +1 -0
  43. package/dist/ui/index.d.ts +1 -0
  44. package/dist/ui/index.d.ts.map +1 -1
  45. package/dist/ui/index.js +1 -0
  46. package/dist/ui/index.js.map +1 -1
  47. package/dist/ui/primitives/overflow-tabs.d.ts +5 -0
  48. package/dist/ui/primitives/overflow-tabs.d.ts.map +1 -1
  49. package/dist/ui/primitives/overflow-tabs.js +4 -4
  50. package/dist/ui/primitives/overflow-tabs.js.map +1 -1
  51. package/dist/ui/primitives/url-preview-chrome.d.ts +8 -0
  52. package/dist/ui/primitives/url-preview-chrome.d.ts.map +1 -0
  53. package/dist/ui/primitives/url-preview-chrome.js +40 -0
  54. package/dist/ui/primitives/url-preview-chrome.js.map +1 -0
  55. package/dist/vista/GenericCatalogueSurface.d.ts +10 -0
  56. package/dist/vista/GenericCatalogueSurface.d.ts.map +1 -0
  57. package/dist/vista/GenericCatalogueSurface.js +80 -0
  58. package/dist/vista/GenericCatalogueSurface.js.map +1 -0
  59. package/dist/vista/SurfaceFallbackCard.d.ts +9 -0
  60. package/dist/vista/SurfaceFallbackCard.d.ts.map +1 -0
  61. package/dist/vista/SurfaceFallbackCard.js +44 -0
  62. package/dist/vista/SurfaceFallbackCard.js.map +1 -0
  63. package/dist/vista/VistaPanel.d.ts +21 -0
  64. package/dist/vista/VistaPanel.d.ts.map +1 -0
  65. package/dist/vista/VistaPanel.js +31 -0
  66. package/dist/vista/VistaPanel.js.map +1 -0
  67. package/dist/vista/html/CustomUiFrame.d.ts +20 -0
  68. package/dist/vista/html/CustomUiFrame.d.ts.map +1 -0
  69. package/dist/vista/html/CustomUiFrame.js +69 -0
  70. package/dist/vista/html/CustomUiFrame.js.map +1 -0
  71. package/dist/vista/html/custom-ui-frame-bridge.d.ts +13 -0
  72. package/dist/vista/html/custom-ui-frame-bridge.d.ts.map +1 -0
  73. package/dist/vista/html/custom-ui-frame-bridge.js +30 -0
  74. package/dist/vista/html/custom-ui-frame-bridge.js.map +1 -0
  75. package/dist/vista/html/custom-ui-frame-contract.d.ts +29 -0
  76. package/dist/vista/html/custom-ui-frame-contract.d.ts.map +1 -0
  77. package/dist/vista/html/custom-ui-frame-contract.js +16 -0
  78. package/dist/vista/html/custom-ui-frame-contract.js.map +1 -0
  79. package/dist/vista/html/custom-ui-intents.d.ts +20 -0
  80. package/dist/vista/html/custom-ui-intents.d.ts.map +1 -0
  81. package/dist/vista/html/custom-ui-intents.js +57 -0
  82. package/dist/vista/html/custom-ui-intents.js.map +1 -0
  83. package/dist/vista/html/custom-ui-srcdoc.d.ts +17 -0
  84. package/dist/vista/html/custom-ui-srcdoc.d.ts.map +1 -0
  85. package/dist/vista/html/custom-ui-srcdoc.js +70 -0
  86. package/dist/vista/html/custom-ui-srcdoc.js.map +1 -0
  87. package/dist/vista/html/index.d.ts +6 -0
  88. package/dist/vista/html/index.d.ts.map +1 -0
  89. package/dist/vista/html/index.js +6 -0
  90. package/dist/vista/html/index.js.map +1 -0
  91. package/dist/vista/index.d.ts +18 -0
  92. package/dist/vista/index.d.ts.map +1 -0
  93. package/dist/vista/index.js +18 -0
  94. package/dist/vista/index.js.map +1 -0
  95. package/dist/vista/surface-catalogue.d.ts +5 -0
  96. package/dist/vista/surface-catalogue.d.ts.map +1 -0
  97. package/dist/vista/surface-catalogue.js +30 -0
  98. package/dist/vista/surface-catalogue.js.map +1 -0
  99. package/dist/vista/surface-icons.d.ts +7 -0
  100. package/dist/vista/surface-icons.d.ts.map +1 -0
  101. package/dist/vista/surface-icons.js +26 -0
  102. package/dist/vista/surface-icons.js.map +1 -0
  103. package/dist/vista/surface-registry.d.ts +7 -0
  104. package/dist/vista/surface-registry.d.ts.map +1 -0
  105. package/dist/vista/surface-registry.js +7 -0
  106. package/dist/vista/surface-registry.js.map +1 -0
  107. package/dist/vista/surfaces/ChartSurface.d.ts +4 -0
  108. package/dist/vista/surfaces/ChartSurface.d.ts.map +1 -0
  109. package/dist/vista/surfaces/ChartSurface.js +17 -0
  110. package/dist/vista/surfaces/ChartSurface.js.map +1 -0
  111. package/dist/vista/surfaces/FilesSurface.d.ts +15 -0
  112. package/dist/vista/surfaces/FilesSurface.d.ts.map +1 -0
  113. package/dist/vista/surfaces/FilesSurface.js +121 -0
  114. package/dist/vista/surfaces/FilesSurface.js.map +1 -0
  115. package/dist/vista/surfaces/FormSurface.d.ts +4 -0
  116. package/dist/vista/surfaces/FormSurface.d.ts.map +1 -0
  117. package/dist/vista/surfaces/FormSurface.js +97 -0
  118. package/dist/vista/surfaces/FormSurface.js.map +1 -0
  119. package/dist/vista/surfaces/HtmlSurface.d.ts +4 -0
  120. package/dist/vista/surfaces/HtmlSurface.d.ts.map +1 -0
  121. package/dist/vista/surfaces/HtmlSurface.js +11 -0
  122. package/dist/vista/surfaces/HtmlSurface.js.map +1 -0
  123. package/dist/vista/surfaces/TableSurface.d.ts +4 -0
  124. package/dist/vista/surfaces/TableSurface.d.ts.map +1 -0
  125. package/dist/vista/surfaces/TableSurface.js +42 -0
  126. package/dist/vista/surfaces/TableSurface.js.map +1 -0
  127. package/dist/vista/surfaces/UrlSurface.d.ts +4 -0
  128. package/dist/vista/surfaces/UrlSurface.d.ts.map +1 -0
  129. package/dist/vista/surfaces/UrlSurface.js +7 -0
  130. package/dist/vista/surfaces/UrlSurface.js.map +1 -0
  131. package/dist/vista/surfaces/blob-surfaces.d.ts +6 -0
  132. package/dist/vista/surfaces/blob-surfaces.d.ts.map +1 -0
  133. package/dist/vista/surfaces/blob-surfaces.js +38 -0
  134. package/dist/vista/surfaces/blob-surfaces.js.map +1 -0
  135. package/dist/vista/surfaces/elicitation-transport.d.ts +18 -0
  136. package/dist/vista/surfaces/elicitation-transport.d.ts.map +1 -0
  137. package/dist/vista/surfaces/elicitation-transport.js +100 -0
  138. package/dist/vista/surfaces/elicitation-transport.js.map +1 -0
  139. package/dist/vista/surfaces/index.d.ts +11 -0
  140. package/dist/vista/surfaces/index.d.ts.map +1 -0
  141. package/dist/vista/surfaces/index.js +89 -0
  142. package/dist/vista/surfaces/index.js.map +1 -0
  143. package/dist/vista/surfaces/text-surfaces.d.ts +8 -0
  144. package/dist/vista/surfaces/text-surfaces.d.ts.map +1 -0
  145. package/dist/vista/surfaces/text-surfaces.js +54 -0
  146. package/dist/vista/surfaces/text-surfaces.js.map +1 -0
  147. package/dist/vista/use-vista-tabs.d.ts +30 -0
  148. package/dist/vista/use-vista-tabs.d.ts.map +1 -0
  149. package/dist/vista/use-vista-tabs.js +77 -0
  150. package/dist/vista/use-vista-tabs.js.map +1 -0
  151. package/dist/vista/vista-code-renderer.d.ts +12 -0
  152. package/dist/vista/vista-code-renderer.d.ts.map +1 -0
  153. package/dist/vista/vista-code-renderer.js +10 -0
  154. package/dist/vista/vista-code-renderer.js.map +1 -0
  155. package/dist/vista/vista-file-source.d.ts +20 -0
  156. package/dist/vista/vista-file-source.d.ts.map +1 -0
  157. package/dist/vista/vista-file-source.js +69 -0
  158. package/dist/vista/vista-file-source.js.map +1 -0
  159. package/dist/vista/vista-form-host.d.ts +16 -0
  160. package/dist/vista/vista-form-host.d.ts.map +1 -0
  161. package/dist/vista/vista-form-host.js +10 -0
  162. package/dist/vista/vista-form-host.js.map +1 -0
  163. package/dist/vista/vista-model.d.ts +12 -0
  164. package/dist/vista/vista-model.d.ts.map +1 -0
  165. package/dist/vista/vista-model.js +72 -0
  166. package/dist/vista/vista-model.js.map +1 -0
  167. package/dist/vista/vista-open-context.d.ts +9 -0
  168. package/dist/vista/vista-open-context.d.ts.map +1 -0
  169. package/dist/vista/vista-open-context.js +10 -0
  170. package/dist/vista/vista-open-context.js.map +1 -0
  171. package/dist/vista/vista-payloads.d.ts +107 -0
  172. package/dist/vista/vista-payloads.d.ts.map +1 -0
  173. package/dist/vista/vista-payloads.js +305 -0
  174. package/dist/vista/vista-payloads.js.map +1 -0
  175. package/dist/vista/vista-tabs-manifest.d.ts +17 -0
  176. package/dist/vista/vista-tabs-manifest.d.ts.map +1 -0
  177. package/dist/vista/vista-tabs-manifest.js +60 -0
  178. package/dist/vista/vista-tabs-manifest.js.map +1 -0
  179. package/dist/vista/vista-tools.d.ts +41 -0
  180. package/dist/vista/vista-tools.d.ts.map +1 -0
  181. package/dist/vista/vista-tools.js +113 -0
  182. package/dist/vista/vista-tools.js.map +1 -0
  183. package/package.json +3 -3
  184. package/src/index.ts +5 -0
  185. package/src/lib/biome-host/biome-registry.ts +31 -11
  186. package/src/lib/contribution-registry/contribution-registry.spec.ts +141 -0
  187. package/src/lib/contribution-registry/contribution-registry.ts +202 -0
  188. package/src/lib/contribution-registry/index.ts +9 -0
  189. package/src/lib/contribution-registry/renderable-registry.ts +142 -0
  190. package/src/ui/capture/field-spec-to-zod.ts +22 -0
  191. package/src/ui/capture/field-spec-validate.ts +147 -0
  192. package/src/ui/capture/field-spec.ts +62 -0
  193. package/src/ui/capture/index.ts +9 -1
  194. package/src/ui/capture/schema-field-input.tsx +134 -14
  195. package/src/ui/capture/submit-values.test.ts +70 -0
  196. package/src/ui/capture/submit-values.ts +63 -0
  197. package/src/ui/index.ts +4 -0
  198. package/src/ui/primitives/overflow-tabs.tsx +24 -4
  199. package/src/ui/primitives/url-preview-chrome.tsx +102 -0
  200. package/src/vista/GenericCatalogueSurface.tsx +177 -0
  201. package/src/vista/SurfaceFallbackCard.tsx +109 -0
  202. package/src/vista/VistaPanel.tsx +155 -0
  203. package/src/vista/form-payload.spec.ts +93 -0
  204. package/src/vista/html/CustomUiFrame.spec.tsx +125 -0
  205. package/src/vista/html/CustomUiFrame.tsx +204 -0
  206. package/src/vista/html/custom-ui-frame-bridge.spec.ts +191 -0
  207. package/src/vista/html/custom-ui-frame-bridge.ts +92 -0
  208. package/src/vista/html/custom-ui-frame-contract.ts +88 -0
  209. package/src/vista/html/custom-ui-intents.spec.ts +133 -0
  210. package/src/vista/html/custom-ui-intents.ts +151 -0
  211. package/src/vista/html/custom-ui-srcdoc.spec.ts +151 -0
  212. package/src/vista/html/custom-ui-srcdoc.ts +193 -0
  213. package/src/vista/html/index.ts +13 -0
  214. package/src/vista/index.ts +48 -0
  215. package/src/vista/surface-catalogue.spec.ts +140 -0
  216. package/src/vista/surface-catalogue.ts +84 -0
  217. package/src/vista/surface-icons.ts +57 -0
  218. package/src/vista/surface-registry.ts +56 -0
  219. package/src/vista/surfaces/ChartSurface.tsx +34 -0
  220. package/src/vista/surfaces/FilesSurface.tsx +268 -0
  221. package/src/vista/surfaces/FormSurface.tsx +264 -0
  222. package/src/vista/surfaces/HtmlSurface.tsx +43 -0
  223. package/src/vista/surfaces/TableSurface.tsx +99 -0
  224. package/src/vista/surfaces/UrlSurface.tsx +40 -0
  225. package/src/vista/surfaces/blob-surfaces.tsx +129 -0
  226. package/src/vista/surfaces/elicitation-transport.spec.ts +187 -0
  227. package/src/vista/surfaces/elicitation-transport.ts +175 -0
  228. package/src/vista/surfaces/index.tsx +157 -0
  229. package/src/vista/surfaces/text-surfaces.tsx +119 -0
  230. package/src/vista/use-vista-tabs.ts +188 -0
  231. package/src/vista/vista-code-renderer.tsx +46 -0
  232. package/src/vista/vista-file-source.tsx +163 -0
  233. package/src/vista/vista-form-host.tsx +78 -0
  234. package/src/vista/vista-model.ts +130 -0
  235. package/src/vista/vista-open-context.tsx +42 -0
  236. package/src/vista/vista-payloads.ts +514 -0
  237. package/src/vista/vista-tabs-manifest.ts +123 -0
  238. package/src/vista/vista-tools.ts +220 -0
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Registration of the first-party surface renderers the UI KERNEL owns.
3
+ *
4
+ * ── The partition (deliberate, and the reason there is no slot-soup) ─────────
5
+ * A kind is registered HERE when the kernel can render it standalone from its
6
+ * payload (plus, for a file-backed kind, the host's injected `VistaFileSource`):
7
+ *
8
+ * url · html · code · json · diff · table · chart · files · image · media ·
9
+ * pdf · form
10
+ *
11
+ * `form` (secure elicitation) belongs here even though it talks to a service:
12
+ * it does so through the host-supplied `VistaFormHost` seam, exactly the way a
13
+ * file-backed surface reads through `VistaFileSource`. The kernel owns the
14
+ * renderer; the host owns only the token and the outcome sink.
15
+ *
16
+ * The remaining first-party kinds are HOST-COUPLED — they need the host's
17
+ * router, its object views, its markdown renderer, or its biome registry — so
18
+ * the HOST registers them with
19
+ * `vistaSurfaceRegistry.registerFirstParty(...)`:
20
+ *
21
+ * markdown · web · biome-route · object · graph · app
22
+ *
23
+ * Every unregistered kind resolves to `SurfaceFallbackCard` with
24
+ * `unknown-kind` — visible, typed, never blank.
25
+ *
26
+ * Importing this module REGISTERS. It is imported for its side effect by
27
+ * `../index.ts`, so any consumer of `@xemahq/ui-kernel/vista` gets the kernel
28
+ * builtins wired without an explicit call.
29
+ */
30
+ import { SurfaceKind } from '@xemahq/kernel-contracts/surface';
31
+
32
+ import {
33
+ ImageSurface,
34
+ MediaSurface,
35
+ PdfSurface,
36
+ } from './blob-surfaces';
37
+ import { ChartSurface } from './ChartSurface';
38
+ import { FilesSurface } from './FilesSurface';
39
+ import { FormSurface } from './FormSurface';
40
+ import { HtmlSurface } from './HtmlSurface';
41
+ import { TableSurface } from './TableSurface';
42
+ import { CodeSurface, DiffSurface, JsonSurface } from './text-surfaces';
43
+ import { UrlSurface } from './UrlSurface';
44
+ import { vistaSurfaceRegistry } from '../surface-registry';
45
+ import { VISTA_SURFACE_VERSION } from '../vista-model';
46
+ import {
47
+ validateBlobPayload,
48
+ validateChartPayload,
49
+ validateDiffPayload,
50
+ validateFilesPayload,
51
+ validateFormPayload,
52
+ validateHtmlPayload,
53
+ validateJsonPayload,
54
+ validateTablePayload,
55
+ validateTextPayload,
56
+ validateUrlPayload,
57
+ type VistaBlobPayload,
58
+ } from '../vista-payloads';
59
+
60
+ /**
61
+ * `media` additionally REQUIRES `contentType`: choosing between `<audio>` and
62
+ * `<video>` from a URL would be a heuristic that fails on an extension-less
63
+ * URL, and this plane does not ship heuristics that can be wrong.
64
+ */
65
+ function validateMediaPayload(raw: unknown): VistaBlobPayload | null {
66
+ const payload = validateBlobPayload(raw);
67
+ if (payload === null) return null;
68
+ return payload.contentType === undefined ? null : payload;
69
+ }
70
+
71
+ vistaSurfaceRegistry.registerFirstParty(SurfaceKind.Url, {
72
+ version: VISTA_SURFACE_VERSION,
73
+ validate: validateUrlPayload,
74
+ render: (payload) => <UrlSurface {...payload} />,
75
+ });
76
+
77
+ vistaSurfaceRegistry.registerFirstParty(SurfaceKind.Html, {
78
+ version: VISTA_SURFACE_VERSION,
79
+ validate: validateHtmlPayload,
80
+ render: (payload) => <HtmlSurface {...payload} />,
81
+ });
82
+
83
+ vistaSurfaceRegistry.registerFirstParty(SurfaceKind.Code, {
84
+ version: VISTA_SURFACE_VERSION,
85
+ validate: validateTextPayload,
86
+ render: (payload) => <CodeSurface {...payload} />,
87
+ });
88
+
89
+ vistaSurfaceRegistry.registerFirstParty(SurfaceKind.Json, {
90
+ version: VISTA_SURFACE_VERSION,
91
+ validate: validateJsonPayload,
92
+ render: (payload) => <JsonSurface data={payload.data} />,
93
+ });
94
+
95
+ vistaSurfaceRegistry.registerFirstParty(SurfaceKind.Diff, {
96
+ version: VISTA_SURFACE_VERSION,
97
+ validate: validateDiffPayload,
98
+ render: (payload) => <DiffSurface {...payload} />,
99
+ });
100
+
101
+ vistaSurfaceRegistry.registerFirstParty(SurfaceKind.Table, {
102
+ version: VISTA_SURFACE_VERSION,
103
+ validate: validateTablePayload,
104
+ render: (payload) => <TableSurface {...payload} />,
105
+ });
106
+
107
+ vistaSurfaceRegistry.registerFirstParty(SurfaceKind.Chart, {
108
+ version: VISTA_SURFACE_VERSION,
109
+ validate: validateChartPayload,
110
+ render: (payload) => <ChartSurface {...payload} />,
111
+ });
112
+
113
+ vistaSurfaceRegistry.registerFirstParty(SurfaceKind.Files, {
114
+ version: VISTA_SURFACE_VERSION,
115
+ validate: validateFilesPayload,
116
+ render: (payload) => <FilesSurface {...payload} />,
117
+ });
118
+
119
+ vistaSurfaceRegistry.registerFirstParty(SurfaceKind.Image, {
120
+ version: VISTA_SURFACE_VERSION,
121
+ validate: validateBlobPayload,
122
+ render: (payload) => <ImageSurface {...payload} />,
123
+ });
124
+
125
+ vistaSurfaceRegistry.registerFirstParty(SurfaceKind.Media, {
126
+ version: VISTA_SURFACE_VERSION,
127
+ validate: validateMediaPayload,
128
+ render: (payload) => <MediaSurface {...payload} />,
129
+ });
130
+
131
+ vistaSurfaceRegistry.registerFirstParty(SurfaceKind.Pdf, {
132
+ version: VISTA_SURFACE_VERSION,
133
+ validate: validateBlobPayload,
134
+ render: (payload) => <PdfSurface {...payload} />,
135
+ });
136
+
137
+ vistaSurfaceRegistry.registerFirstParty(SurfaceKind.Form, {
138
+ version: VISTA_SURFACE_VERSION,
139
+ validate: validateFormPayload,
140
+ render: (payload) => <FormSurface {...payload} />,
141
+ });
142
+
143
+ export { ChartSurface } from './ChartSurface';
144
+ export { FilesSurface, fileExtMeta, groupFilesByFolder } from './FilesSurface';
145
+ export { FormSurface } from './FormSurface';
146
+ export {
147
+ submitElicitationFields,
148
+ readElicitationStatus,
149
+ extractServiceMessage,
150
+ VistaFormSubmitError,
151
+ } from './elicitation-transport';
152
+ export { HtmlSurface } from './HtmlSurface';
153
+ export { TableSurface } from './TableSurface';
154
+ export { UrlSurface } from './UrlSurface';
155
+ export { CodeSurface, DiffSurface, JsonSurface } from './text-surfaces';
156
+ export { ImageSurface, MediaSurface, PdfSurface } from './blob-surfaces';
157
+ export type { VistaFileGroup } from './FilesSurface';
@@ -0,0 +1,119 @@
1
+ /**
2
+ * The text-bodied first-party surfaces: `code`, `json`, `diff`.
3
+ *
4
+ * Each accepts an inline `content` or a workspace `path` resolved through the
5
+ * host {@link VistaFileSource}, so a panel can open a file lazily without the
6
+ * kernel knowing anything about the host's file endpoints.
7
+ *
8
+ * `code` is a mono pane — it is also where a plain-text file lands (the legacy
9
+ * `plain` tab kind was collapsed into it; one kind, one renderer, no alias).
10
+ */
11
+
12
+ import { useVistaCodeRenderer } from '../vista-code-renderer';
13
+ import { VistaFileText } from '../vista-file-source';
14
+
15
+ import type { VistaTextPayload } from '../vista-payloads';
16
+ import type { ReactElement, ReactNode } from 'react';
17
+
18
+ const PANE_STYLE = {
19
+ height: '100%',
20
+ width: '100%',
21
+ margin: 0,
22
+ overflow: 'auto',
23
+ padding: '14px 16px',
24
+ fontSize: 12,
25
+ lineHeight: 1.6,
26
+ color: 'hsl(var(--ink-2))',
27
+ whiteSpace: 'pre-wrap' as const,
28
+ };
29
+
30
+ /** Render inline content, or fetch the path first — one seam for all three. */
31
+ function TextBody({
32
+ payload,
33
+ render,
34
+ }: Readonly<{
35
+ payload: VistaTextPayload;
36
+ render: (content: string) => ReactNode;
37
+ }>): ReactElement {
38
+ if (payload.content !== undefined) return <>{render(payload.content)}</>;
39
+ // `validateTextPayload` guarantees exactly one of content/path.
40
+ return <VistaFileText path={payload.path as string} render={render} />;
41
+ }
42
+
43
+ export function CodeSurface(payload: VistaTextPayload): ReactElement {
44
+ // A host that ships a code editor provides it through
45
+ // `VistaCodeRendererProvider`; with none the mono pane below IS the intended
46
+ // rendering (see `vista-code-renderer.tsx`).
47
+ const hostRenderer = useVistaCodeRenderer();
48
+ return (
49
+ <TextBody
50
+ payload={payload}
51
+ render={(content) =>
52
+ hostRenderer === null ? (
53
+ <pre className="mono" style={PANE_STYLE}>
54
+ {content}
55
+ </pre>
56
+ ) : (
57
+ hostRenderer({
58
+ content,
59
+ ...(payload.path === undefined ? {} : { path: payload.path }),
60
+ ...(payload.language === undefined
61
+ ? {}
62
+ : { language: payload.language }),
63
+ })
64
+ )
65
+ }
66
+ />
67
+ );
68
+ }
69
+
70
+ /**
71
+ * `json` — pretty-printed and inspectable. An inline payload carries parsed
72
+ * `data`; a path-backed one carries the raw text, which is re-serialised when it
73
+ * parses and shown VERBATIM when it does not (a malformed JSON file is shown as
74
+ * it is, never swallowed).
75
+ */
76
+ export function JsonSurface({ data }: Readonly<{ data: unknown }>): ReactElement {
77
+ let text: string;
78
+ try {
79
+ text = JSON.stringify(data, null, 2) ?? String(data);
80
+ } catch {
81
+ text = String(data);
82
+ }
83
+ return (
84
+ <pre className="mono" style={PANE_STYLE}>
85
+ {text}
86
+ </pre>
87
+ );
88
+ }
89
+
90
+ /** Colour a unified-diff line by its leading marker. */
91
+ function diffLineColor(line: string): string | undefined {
92
+ if (line.startsWith('+++') || line.startsWith('---')) return 'hsl(var(--ink-3))';
93
+ if (line.startsWith('@@')) return 'hsl(var(--info))';
94
+ if (line.startsWith('+')) return 'hsl(var(--success))';
95
+ if (line.startsWith('-')) return 'hsl(var(--destructive, var(--danger)))';
96
+ return undefined;
97
+ }
98
+
99
+ export function DiffSurface(payload: VistaTextPayload): ReactElement {
100
+ return (
101
+ <TextBody
102
+ payload={payload}
103
+ render={(content) => (
104
+ <pre className="mono" style={PANE_STYLE}>
105
+ {content.split('\n').map((line, index) => (
106
+ <div
107
+ // A diff has no stable per-line identity other than its position.
108
+
109
+ key={index}
110
+ style={{ color: diffLineColor(line) }}
111
+ >
112
+ {line === '' ? ' ' : line}
113
+ </div>
114
+ ))}
115
+ </pre>
116
+ )}
117
+ />
118
+ );
119
+ }
@@ -0,0 +1,188 @@
1
+ /**
2
+ * `useVistaTabs` — the ONE tab-state machine behind every Vista panel.
3
+ *
4
+ * Lifted from `SessionWorkspaceThin`'s (already host-agnostic) chrome and
5
+ * generalised to {@link VistaSurface} envelopes, so the thin session workspace,
6
+ * the Design-System-Builder preview, and the agent-driven `vista_*` tools all
7
+ * drive the SAME state. Behaviours carried over verbatim:
8
+ *
9
+ * • PINNED FIRST TAB. A surface with `pinned: true` sorts first and can never
10
+ * be closed (`close()` returns `false`).
11
+ * • HOST TABS vs. OPENED TABS. `hostTabs` are host-driven (a live workspace
12
+ * scan, an artifact list) and reconcile every render; `open()` tabs are
13
+ * user/agent-driven and persist until closed.
14
+ * • CLOSED-HOST-TAB MEMORY. Closing a host tab records its id so the next
15
+ * scan does NOT resurrect a tab the user dismissed. The record is pruned
16
+ * when the host stops offering that id, so a genuinely new occurrence shows
17
+ * again — no stale suppression.
18
+ * • ACTIVE RECONCILIATION. If the active tab disappears, the first remaining
19
+ * tab becomes active (never a dangling id, never a blank pane).
20
+ */
21
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
22
+
23
+ import type { VistaTab } from './vista-model';
24
+
25
+ /** A partial update applied to an open tab (`vista_update`). */
26
+ export interface VistaSurfacePatch {
27
+ readonly kind?: string;
28
+ readonly version?: number;
29
+ readonly title?: string;
30
+ readonly payload?: unknown;
31
+ readonly pinned?: boolean;
32
+ }
33
+
34
+ /** A tab summary — what `vista_list()` returns to the agent. */
35
+ export interface VistaTabSummary {
36
+ readonly tabId: string;
37
+ readonly kind: string;
38
+ readonly title: string;
39
+ readonly pinned: boolean;
40
+ readonly active: boolean;
41
+ }
42
+
43
+ /** The tab-state surface a panel (and the `vista_*` dispatcher) drives. */
44
+ export interface VistaTabsController {
45
+ /** Host tabs (reconciled) followed by opened tabs, pinned ones first. */
46
+ readonly tabs: readonly VistaTab[];
47
+ readonly activeTabId: string | null;
48
+ /** Activate a tab. No-op for an id that is not open. */
49
+ activate(tabId: string): void;
50
+ /** Open (or REPLACE, when `tabId` is already open) a surface, and focus it. */
51
+ open(surface: VistaTab): string;
52
+ /** Patch an open tab. `false` when the tab is not open. */
53
+ update(tabId: string, patch: VistaSurfacePatch): boolean;
54
+ /** Close a tab. `false` when it is not open or is pinned. */
55
+ close(tabId: string): boolean;
56
+ /** Snapshot of every open tab. */
57
+ list(): readonly VistaTabSummary[];
58
+ }
59
+
60
+ export interface UseVistaTabsOptions {
61
+ /**
62
+ * Host-driven tabs, reconciled live (a workspace scan, an artifact set). A
63
+ * pinned entry here is the panel's permanent first tab.
64
+ */
65
+ readonly hostTabs?: readonly VistaTab[];
66
+ /** Tab active on first render. Falls back to the first tab. */
67
+ readonly initialActiveTabId?: string;
68
+ }
69
+
70
+ const NO_HOST_TABS: readonly VistaTab[] = [];
71
+
72
+ /** Pinned tabs first, otherwise insertion order (stable). */
73
+ function sortPinnedFirst(tabs: readonly VistaTab[]): VistaTab[] {
74
+ const pinned = tabs.filter((t) => t.pinned === true);
75
+ const rest = tabs.filter((t) => t.pinned !== true);
76
+ return [...pinned, ...rest];
77
+ }
78
+
79
+ export function useVistaTabs({
80
+ hostTabs = NO_HOST_TABS,
81
+ initialActiveTabId,
82
+ }: UseVistaTabsOptions = {}): VistaTabsController {
83
+ const [openedTabs, setOpenedTabs] = useState<readonly VistaTab[]>([]);
84
+ const [closedHostTabIds, setClosedHostTabIds] = useState<readonly string[]>(
85
+ [],
86
+ );
87
+ const [activeTabId, setActiveTabId] = useState<string | null>(
88
+ initialActiveTabId ?? null,
89
+ );
90
+
91
+ const tabs = useMemo(
92
+ () =>
93
+ sortPinnedFirst([
94
+ ...hostTabs.filter((t) => !closedHostTabIds.includes(t.tabId)),
95
+ ...openedTabs,
96
+ ]),
97
+ [hostTabs, closedHostTabIds, openedTabs],
98
+ );
99
+
100
+ // Prune `closedHostTabIds` entries the host no longer offers, so if the same
101
+ // id reappears later it shows again (no stale suppression).
102
+ useEffect(() => {
103
+ setClosedHostTabIds((prev) => {
104
+ const next = prev.filter((id) => hostTabs.some((t) => t.tabId === id));
105
+ return next.length === prev.length ? prev : next;
106
+ });
107
+ }, [hostTabs]);
108
+
109
+ // Keep the active tab valid as host/opened tabs change. If it disappears (or
110
+ // was never set), fall back to the first available tab.
111
+ useEffect(() => {
112
+ setActiveTabId((current) => {
113
+ if (current !== null && tabs.some((t) => t.tabId === current)) {
114
+ return current;
115
+ }
116
+ return tabs[0]?.tabId ?? null;
117
+ });
118
+ }, [tabs]);
119
+
120
+ // A stable snapshot for `list()` — the controller identity must not change on
121
+ // every render, so the callbacks read through a ref instead of closing over
122
+ // `tabs`.
123
+ const tabsRef = useRef(tabs);
124
+ tabsRef.current = tabs;
125
+ const openedTabsRef = useRef(openedTabs);
126
+ openedTabsRef.current = openedTabs;
127
+ const activeRef = useRef(activeTabId);
128
+ activeRef.current = activeTabId;
129
+
130
+ const activate = useCallback((tabId: string): void => {
131
+ if (!tabsRef.current.some((t) => t.tabId === tabId)) return;
132
+ setActiveTabId(tabId);
133
+ }, []);
134
+
135
+ const open = useCallback((surface: VistaTab): string => {
136
+ setOpenedTabs((prev) => {
137
+ const index = prev.findIndex((t) => t.tabId === surface.tabId);
138
+ if (index === -1) return [...prev, surface];
139
+ // Re-opening the same tabId REPLACES it (the `VistaSurface` contract).
140
+ const next = [...prev];
141
+ next[index] = surface;
142
+ return next;
143
+ });
144
+ // Re-opening a host tab the user had dismissed un-dismisses it.
145
+ setClosedHostTabIds((prev) => prev.filter((id) => id !== surface.tabId));
146
+ setActiveTabId(surface.tabId);
147
+ return surface.tabId;
148
+ }, []);
149
+
150
+ const update = useCallback(
151
+ (tabId: string, patch: VistaSurfacePatch): boolean => {
152
+ // A HOST tab is owned by the host's data flow — a patch here would be
153
+ // overwritten on the next reconcile, so it is REFUSED rather than
154
+ // silently lost. Ownership is decided synchronously from the ref, not
155
+ // inside the state updater (which React may invoke twice).
156
+ if (!openedTabsRef.current.some((t) => t.tabId === tabId)) return false;
157
+ setOpenedTabs((prev) =>
158
+ prev.map((tab) => (tab.tabId === tabId ? { ...tab, ...patch } : tab)),
159
+ );
160
+ return true;
161
+ },
162
+ [],
163
+ );
164
+
165
+ const close = useCallback((tabId: string): boolean => {
166
+ const tab = tabsRef.current.find((t) => t.tabId === tabId);
167
+ if (tab === undefined || tab.pinned === true) return false;
168
+ setOpenedTabs((prev) => prev.filter((t) => t.tabId !== tabId));
169
+ setClosedHostTabIds((prev) =>
170
+ prev.includes(tabId) ? prev : [...prev, tabId],
171
+ );
172
+ return true;
173
+ }, []);
174
+
175
+ const list = useCallback(
176
+ (): readonly VistaTabSummary[] =>
177
+ tabsRef.current.map((tab) => ({
178
+ tabId: tab.tabId,
179
+ kind: tab.kind,
180
+ title: tab.title,
181
+ pinned: tab.pinned === true,
182
+ active: tab.tabId === activeRef.current,
183
+ })),
184
+ [],
185
+ );
186
+
187
+ return { tabs, activeTabId, activate, open, update, close, list };
188
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * `VistaCodeRenderer` — the seam through which a host swaps in a real code
3
+ * editor for the `code` surface.
4
+ *
5
+ * The kernel ships NO syntax-highlighting engine (a Monaco/Prism dependency in
6
+ * a host-framework-agnostic package would be imposed on every consumer), so
7
+ * {@link CodeSurface}'s built-in body is a mono `<pre>`. That is a COMPLETE
8
+ * rendering of a file's bytes, not a degraded one — but a host that already
9
+ * ships an editor (host-web ships Monaco) provides it here and every `code`
10
+ * tab picks it up.
11
+ *
12
+ * This is an extension point, not a fallback chain: with no provider the mono
13
+ * pane is the intended rendering, and with a provider the host's renderer is
14
+ * the intended rendering. Neither is an error path.
15
+ */
16
+ import {
17
+ createContext,
18
+ useContext,
19
+ type ReactElement,
20
+ type ReactNode,
21
+ } from 'react';
22
+
23
+ /** Draw a code body. `path` is present for a file-backed surface. */
24
+ export type VistaCodeRenderer = (args: {
25
+ readonly content: string;
26
+ readonly path?: string;
27
+ readonly language?: string;
28
+ }) => ReactNode;
29
+
30
+ const VistaCodeRendererContext = createContext<VistaCodeRenderer | null>(null);
31
+
32
+ export function VistaCodeRendererProvider({
33
+ renderer,
34
+ children,
35
+ }: Readonly<{ renderer: VistaCodeRenderer; children: ReactNode }>): ReactElement {
36
+ return (
37
+ <VistaCodeRendererContext.Provider value={renderer}>
38
+ {children}
39
+ </VistaCodeRendererContext.Provider>
40
+ );
41
+ }
42
+
43
+ /** The host's code renderer, or `null` for the built-in mono pane. */
44
+ export function useVistaCodeRenderer(): VistaCodeRenderer | null {
45
+ return useContext(VistaCodeRendererContext);
46
+ }
@@ -0,0 +1,163 @@
1
+ /**
2
+ * `VistaFileSource` — the ONE seam through which a file-backed surface reads
3
+ * bytes.
4
+ *
5
+ * `@xemahq/ui-kernel` is host-framework-agnostic and carries no API client, so
6
+ * a `code`/`markdown`/`pdf`/`image` surface addressed by a workspace `path`
7
+ * cannot fetch on its own. The host provides a source (bound to its own
8
+ * session-file / artifact endpoints) exactly once, at the panel boundary; every
9
+ * first-party renderer reads through it.
10
+ *
11
+ * There is deliberately NO default: a path-backed surface mounted without a
12
+ * provider renders a visible error, never a blank pane and never a silent
13
+ * "content unavailable".
14
+ */
15
+ import {
16
+ createContext,
17
+ useContext,
18
+ useEffect,
19
+ useState,
20
+ type ReactElement,
21
+ type ReactNode,
22
+ } from 'react';
23
+
24
+ /** Host-supplied byte access for path-backed surfaces. */
25
+ export interface VistaFileSource {
26
+ /** Read a workspace-relative path as text. Rejects on failure. */
27
+ readText(path: string): Promise<string>;
28
+ /**
29
+ * Resolve a workspace-relative path to a fetchable URL (`blob:`, `data:`, or
30
+ * a durable `https:` URL) for binary surfaces. Rejects on failure.
31
+ *
32
+ * The host owns the lifetime of anything it creates (e.g. revoking an object
33
+ * URL); the surface only reads.
34
+ */
35
+ resolveUrl(path: string): Promise<string>;
36
+ /**
37
+ * Opaque revision token. Change it to make every mounted path-backed surface
38
+ * re-read (the host bumps it on a workspace file-change event).
39
+ */
40
+ readonly revision?: string | number;
41
+ }
42
+
43
+ const VistaFileSourceContext = createContext<VistaFileSource | null>(null);
44
+
45
+ export function VistaFileSourceProvider({
46
+ source,
47
+ children,
48
+ }: Readonly<{ source: VistaFileSource; children: ReactNode }>): ReactElement {
49
+ return (
50
+ <VistaFileSourceContext.Provider value={source}>
51
+ {children}
52
+ </VistaFileSourceContext.Provider>
53
+ );
54
+ }
55
+
56
+ /** The active file source, or `null` when no provider is mounted. */
57
+ export function useVistaFileSource(): VistaFileSource | null {
58
+ return useContext(VistaFileSourceContext);
59
+ }
60
+
61
+ /** Async load state for a path-backed surface. */
62
+ type LoadState =
63
+ | { readonly status: 'loading' }
64
+ | { readonly status: 'ready'; readonly value: string }
65
+ | { readonly status: 'error'; readonly message: string };
66
+
67
+ const LOADING: LoadState = { status: 'loading' };
68
+
69
+ function useResolvedFile(
70
+ path: string,
71
+ mode: 'text' | 'url',
72
+ ): LoadState {
73
+ const source = useVistaFileSource();
74
+ const revision = source?.revision;
75
+ const [state, setState] = useState<LoadState>(LOADING);
76
+
77
+ useEffect(() => {
78
+ if (source === null) {
79
+ setState({
80
+ status: 'error',
81
+ message:
82
+ 'No file source is mounted for this panel, so path-backed content cannot be read.',
83
+ });
84
+ return;
85
+ }
86
+ let cancelled = false;
87
+ setState(LOADING);
88
+ const promise =
89
+ mode === 'text' ? source.readText(path) : source.resolveUrl(path);
90
+ promise.then(
91
+ (value) => {
92
+ if (!cancelled) setState({ status: 'ready', value });
93
+ },
94
+ (error: unknown) => {
95
+ if (cancelled) return;
96
+ setState({
97
+ status: 'error',
98
+ message: error instanceof Error ? error.message : String(error),
99
+ });
100
+ },
101
+ );
102
+ return () => {
103
+ cancelled = true;
104
+ };
105
+ }, [source, path, mode, revision]);
106
+
107
+ return state;
108
+ }
109
+
110
+ function LoadNotice({
111
+ state,
112
+ }: Readonly<{ state: Exclude<LoadState, { status: 'ready' }> }>): ReactElement {
113
+ return (
114
+ <div
115
+ role={state.status === 'error' ? 'alert' : undefined}
116
+ style={{
117
+ display: 'flex',
118
+ height: '100%',
119
+ alignItems: 'center',
120
+ justifyContent: 'center',
121
+ padding: 24,
122
+ fontSize: 12.5,
123
+ textAlign: 'center',
124
+ color:
125
+ state.status === 'error'
126
+ ? 'hsl(var(--destructive))'
127
+ : 'hsl(var(--ink-4))',
128
+ }}
129
+ >
130
+ {state.status === 'loading' ? 'Loading…' : state.message}
131
+ </div>
132
+ );
133
+ }
134
+
135
+ /**
136
+ * Render a path-backed surface body from its TEXT content. The load/error
137
+ * states are explicit and visible — a failed read never renders as empty
138
+ * content.
139
+ */
140
+ export function VistaFileText({
141
+ path,
142
+ render,
143
+ }: Readonly<{
144
+ path: string;
145
+ render: (content: string) => ReactNode;
146
+ }>): ReactElement {
147
+ const state = useResolvedFile(path, 'text');
148
+ if (state.status !== 'ready') return <LoadNotice state={state} />;
149
+ return <>{render(state.value)}</>;
150
+ }
151
+
152
+ /** Render a path-backed surface body from a resolved fetchable URL. */
153
+ export function VistaFileUrl({
154
+ path,
155
+ render,
156
+ }: Readonly<{
157
+ path: string;
158
+ render: (url: string) => ReactNode;
159
+ }>): ReactElement {
160
+ const state = useResolvedFile(path, 'url');
161
+ if (state.status !== 'ready') return <LoadNotice state={state} />;
162
+ return <>{render(state.value)}</>;
163
+ }