@scaffold-ui-kit/preview 0.0.0-stage → 2.3.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 (350) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1868 -2
  3. package/application/host/bootstrap.ts +43 -0
  4. package/application/host/main.ts +31 -0
  5. package/application/host/shell-host.ts +47 -0
  6. package/application/index.html +12 -0
  7. package/application/lib/base-url.ts +15 -0
  8. package/application/lib/no-code-block.ts +7 -0
  9. package/application/lib/no-setup.ts +3 -0
  10. package/application/lib/no-views.ts +6 -0
  11. package/application/preview/code/code.html +12 -0
  12. package/application/preview/code/main.ts +89 -0
  13. package/application/preview/globals.ts +254 -0
  14. package/application/preview/html/main.ts +93 -0
  15. package/application/preview/html/preview.html +12 -0
  16. package/application/preview/react/main.tsx +146 -0
  17. package/application/preview/react/preview.html +12 -0
  18. package/application/preview/svelte/Preview.svelte +104 -0
  19. package/application/preview/svelte/main.ts +13 -0
  20. package/application/preview/svelte/preview.html +12 -0
  21. package/application/preview/svelte/story-props.ts +172 -0
  22. package/application/preview/view/main.ts +124 -0
  23. package/application/preview/view/view.html +12 -0
  24. package/application/preview/vue/main.ts +145 -0
  25. package/application/preview/vue/preview.html +12 -0
  26. package/application/shells/charcell/components/Application/index.css +37 -0
  27. package/application/shells/charcell/components/Application/index.tsx +65 -0
  28. package/application/shells/charcell/components/Bar/index.css +68 -0
  29. package/application/shells/charcell/components/Bar/index.tsx +60 -0
  30. package/application/shells/charcell/components/CodePane/index.css +60 -0
  31. package/application/shells/charcell/components/CodePane/index.tsx +113 -0
  32. package/application/shells/charcell/components/ComponentStage/index.css +26 -0
  33. package/application/shells/charcell/components/ComponentStage/index.tsx +110 -0
  34. package/application/shells/charcell/components/Control/index.css +20 -0
  35. package/application/shells/charcell/components/Control/index.tsx +118 -0
  36. package/application/shells/charcell/components/CopyLink/index.tsx +35 -0
  37. package/application/shells/charcell/components/Description/index.css +6 -0
  38. package/application/shells/charcell/components/Description/index.tsx +24 -0
  39. package/application/shells/charcell/components/EditorAddDialog/index.css +9 -0
  40. package/application/shells/charcell/components/EditorAddDialog/index.tsx +158 -0
  41. package/application/shells/charcell/components/EditorPanel/index.css +48 -0
  42. package/application/shells/charcell/components/EditorPanel/index.tsx +496 -0
  43. package/application/shells/charcell/components/EventsRow/index.css +42 -0
  44. package/application/shells/charcell/components/EventsRow/index.tsx +68 -0
  45. package/application/shells/charcell/components/HeadingRow/index.css +11 -0
  46. package/application/shells/charcell/components/HeadingRow/index.tsx +16 -0
  47. package/application/shells/charcell/components/Hint/index.css +16 -0
  48. package/application/shells/charcell/components/Hint/index.tsx +81 -0
  49. package/application/shells/charcell/components/HtmlWarnings/index.tsx +45 -0
  50. package/application/shells/charcell/components/KeyHints/index.css +27 -0
  51. package/application/shells/charcell/components/KeyHints/index.tsx +106 -0
  52. package/application/shells/charcell/components/KitCodeBlock/index.css +55 -0
  53. package/application/shells/charcell/components/KitCodeBlock/index.tsx +18 -0
  54. package/application/shells/charcell/components/Markdown/index.tsx +16 -0
  55. package/application/shells/charcell/components/Navigation/index.css +13 -0
  56. package/application/shells/charcell/components/Navigation/index.tsx +98 -0
  57. package/application/shells/charcell/components/NavigationSplit/index.css +16 -0
  58. package/application/shells/charcell/components/NavigationSplit/index.tsx +82 -0
  59. package/application/shells/charcell/components/OptionControls/index.tsx +93 -0
  60. package/application/shells/charcell/components/PaneStatus/index.css +7 -0
  61. package/application/shells/charcell/components/PaneStatus/index.tsx +47 -0
  62. package/application/shells/charcell/components/PaneWidth/index.tsx +45 -0
  63. package/application/shells/charcell/components/PreviewGrid/index.css +39 -0
  64. package/application/shells/charcell/components/PreviewGrid/index.tsx +344 -0
  65. package/application/shells/charcell/components/PreviewPane/index.css +127 -0
  66. package/application/shells/charcell/components/PreviewPane/index.tsx +182 -0
  67. package/application/shells/charcell/components/PromptBar/index.tsx +133 -0
  68. package/application/shells/charcell/components/ScenarioRow/index.css +36 -0
  69. package/application/shells/charcell/components/ScenarioRow/index.tsx +71 -0
  70. package/application/shells/charcell/components/Select/index.tsx +48 -0
  71. package/application/shells/charcell/components/SlotOutlet/index.css +7 -0
  72. package/application/shells/charcell/components/SlotOutlet/index.tsx +25 -0
  73. package/application/shells/charcell/components/StageBar/index.css +7 -0
  74. package/application/shells/charcell/components/StageBar/index.tsx +109 -0
  75. package/application/shells/charcell/components/StageSplit/index.css +11 -0
  76. package/application/shells/charcell/components/StageSplit/index.tsx +99 -0
  77. package/application/shells/charcell/components/StatusBar/index.tsx +30 -0
  78. package/application/shells/charcell/components/ViewControls/index.css +15 -0
  79. package/application/shells/charcell/components/ViewControls/index.tsx +58 -0
  80. package/application/shells/charcell/components/ViewHeading/index.css +13 -0
  81. package/application/shells/charcell/components/ViewHeading/index.tsx +8 -0
  82. package/application/shells/charcell/components/ViewStage/index.css +9 -0
  83. package/application/shells/charcell/components/ViewStage/index.tsx +25 -0
  84. package/application/shells/charcell/components/WrapToggle/index.tsx +27 -0
  85. package/application/shells/charcell/configuration.ts +45 -0
  86. package/application/shells/charcell/controller-context.ts +27 -0
  87. package/application/shells/charcell/fit-labels.ts +42 -0
  88. package/application/shells/charcell/html-warnings.ts +18 -0
  89. package/application/shells/charcell/index.tsx +82 -0
  90. package/application/shells/charcell/page-loading.html +57 -0
  91. package/application/shells/charcell/placement.ts +24 -0
  92. package/application/shells/charcell/shell-options.ts +23 -0
  93. package/application/shells/charcell/shell.css +37 -0
  94. package/application/shells/charcell/shell.tsx +25 -0
  95. package/application/shells/charcell/split-reset.ts +47 -0
  96. package/application/shells/charcell/stacked-rows.ts +117 -0
  97. package/application/shells/charcell/stage-toggles.ts +93 -0
  98. package/application/types/manifest.d.ts +6 -0
  99. package/application/types/preview-configuration.d.ts +10 -0
  100. package/application/types/preview-shell.d.ts +7 -0
  101. package/application/types/react-registry.d.ts +15 -0
  102. package/application/types/vue-registry.d.ts +6 -0
  103. package/dist/build.d.ts +24 -0
  104. package/dist/build.js +34 -0
  105. package/dist/check.d.ts +48 -0
  106. package/dist/check.js +781 -0
  107. package/dist/cli.d.ts +2 -0
  108. package/dist/cli.js +88 -0
  109. package/dist/context.d.ts +179 -0
  110. package/dist/context.js +783 -0
  111. package/dist/controller/catalog.d.ts +339 -0
  112. package/dist/controller/catalog.js +367 -0
  113. package/dist/controller/create-preview-controller.d.ts +532 -0
  114. package/dist/controller/create-preview-controller.js +1707 -0
  115. package/dist/controller/editor-tree.d.ts +161 -0
  116. package/dist/controller/editor-tree.js +373 -0
  117. package/dist/controller/html-source.d.ts +62 -0
  118. package/dist/controller/html-source.js +61 -0
  119. package/dist/controller/index.d.ts +9 -0
  120. package/dist/controller/index.js +12 -0
  121. package/dist/controller/persistence.d.ts +191 -0
  122. package/dist/controller/persistence.js +315 -0
  123. package/dist/controller/regeneration.d.ts +30 -0
  124. package/dist/controller/regeneration.js +27 -0
  125. package/dist/controller/source.d.ts +80 -0
  126. package/dist/controller/source.js +236 -0
  127. package/dist/controller/store.d.ts +27 -0
  128. package/dist/controller/store.js +40 -0
  129. package/dist/declarations/application/shells/charcell/components/Application/index.d.ts +2 -0
  130. package/dist/declarations/application/shells/charcell/components/Bar/index.d.ts +11 -0
  131. package/dist/declarations/application/shells/charcell/components/CodePane/index.d.ts +5 -0
  132. package/dist/declarations/application/shells/charcell/components/ComponentStage/index.d.ts +2 -0
  133. package/dist/declarations/application/shells/charcell/components/Control/index.d.ts +9 -0
  134. package/dist/declarations/application/shells/charcell/components/CopyLink/index.d.ts +1 -0
  135. package/dist/declarations/application/shells/charcell/components/Description/index.d.ts +5 -0
  136. package/dist/declarations/application/shells/charcell/components/EditorAddDialog/index.d.ts +6 -0
  137. package/dist/declarations/application/shells/charcell/components/EditorPanel/index.d.ts +2 -0
  138. package/dist/declarations/application/shells/charcell/components/EventsRow/index.d.ts +4 -0
  139. package/dist/declarations/application/shells/charcell/components/HeadingRow/index.d.ts +6 -0
  140. package/dist/declarations/application/shells/charcell/components/Hint/index.d.ts +11 -0
  141. package/dist/declarations/application/shells/charcell/components/HtmlWarnings/index.d.ts +5 -0
  142. package/dist/declarations/application/shells/charcell/components/KeyHints/index.d.ts +2 -0
  143. package/dist/declarations/application/shells/charcell/components/KitCodeBlock/index.d.ts +5 -0
  144. package/dist/declarations/application/shells/charcell/components/Markdown/index.d.ts +3 -0
  145. package/dist/declarations/application/shells/charcell/components/Navigation/index.d.ts +8 -0
  146. package/dist/declarations/application/shells/charcell/components/NavigationSplit/index.d.ts +7 -0
  147. package/dist/declarations/application/shells/charcell/components/OptionControls/index.d.ts +7 -0
  148. package/dist/declarations/application/shells/charcell/components/PaneStatus/index.d.ts +2 -0
  149. package/dist/declarations/application/shells/charcell/components/PaneWidth/index.d.ts +4 -0
  150. package/dist/declarations/application/shells/charcell/components/PreviewGrid/index.d.ts +7 -0
  151. package/dist/declarations/application/shells/charcell/components/PreviewPane/index.d.ts +9 -0
  152. package/dist/declarations/application/shells/charcell/components/PromptBar/index.d.ts +1 -0
  153. package/dist/declarations/application/shells/charcell/components/ScenarioRow/index.d.ts +2 -0
  154. package/dist/declarations/application/shells/charcell/components/Select/index.d.ts +16 -0
  155. package/dist/declarations/application/shells/charcell/components/SlotOutlet/index.d.ts +5 -0
  156. package/dist/declarations/application/shells/charcell/components/StageBar/index.d.ts +2 -0
  157. package/dist/declarations/application/shells/charcell/components/StageSplit/index.d.ts +17 -0
  158. package/dist/declarations/application/shells/charcell/components/StatusBar/index.d.ts +1 -0
  159. package/dist/declarations/application/shells/charcell/components/ViewControls/index.d.ts +9 -0
  160. package/dist/declarations/application/shells/charcell/components/ViewHeading/index.d.ts +4 -0
  161. package/dist/declarations/application/shells/charcell/components/ViewStage/index.d.ts +4 -0
  162. package/dist/declarations/application/shells/charcell/components/WrapToggle/index.d.ts +1 -0
  163. package/dist/declarations/application/shells/charcell/configuration.d.ts +31 -0
  164. package/dist/declarations/application/shells/charcell/controller-context.d.ts +9 -0
  165. package/dist/declarations/application/shells/charcell/fit-labels.d.ts +18 -0
  166. package/dist/declarations/application/shells/charcell/html-warnings.d.ts +5 -0
  167. package/dist/declarations/application/shells/charcell/index.d.ts +39 -0
  168. package/dist/declarations/application/shells/charcell/placement.d.ts +7 -0
  169. package/dist/declarations/application/shells/charcell/shell-options.d.ts +15 -0
  170. package/dist/declarations/application/shells/charcell/shell.d.ts +9 -0
  171. package/dist/declarations/application/shells/charcell/split-reset.d.ts +30 -0
  172. package/dist/declarations/application/shells/charcell/stacked-rows.d.ts +58 -0
  173. package/dist/declarations/application/shells/charcell/stage-toggles.d.ts +28 -0
  174. package/dist/declarations/src/controller/catalog.d.ts +339 -0
  175. package/dist/declarations/src/controller/create-preview-controller.d.ts +532 -0
  176. package/dist/declarations/src/controller/editor-tree.d.ts +161 -0
  177. package/dist/declarations/src/controller/html-source.d.ts +62 -0
  178. package/dist/declarations/src/controller/index.d.ts +9 -0
  179. package/dist/declarations/src/controller/persistence.d.ts +191 -0
  180. package/dist/declarations/src/controller/regeneration.d.ts +30 -0
  181. package/dist/declarations/src/controller/source.d.ts +80 -0
  182. package/dist/declarations/src/controller/store.d.ts +27 -0
  183. package/dist/declarations/src/emit/common.d.ts +103 -0
  184. package/dist/declarations/src/emit/manifest.d.ts +138 -0
  185. package/dist/declarations/src/emit/source.d.ts +87 -0
  186. package/dist/declarations/src/lib/jsx-roots.d.ts +22 -0
  187. package/dist/declarations/src/lib/module-of-source.d.ts +18 -0
  188. package/dist/declarations/src/lib/naming.d.ts +29 -0
  189. package/dist/declarations/src/lib/react-spelling.d.ts +68 -0
  190. package/dist/declarations/src/lib/scenario-story.d.ts +41 -0
  191. package/dist/declarations/src/lib/slot-fill.d.ts +15 -0
  192. package/dist/declarations/src/lib/types.d.ts +741 -0
  193. package/dist/declarations/src/options.d.ts +224 -0
  194. package/dist/declarations/src/protocol.d.ts +541 -0
  195. package/dist/declarations/src/react-view.d.ts +22 -0
  196. package/dist/declarations/src/react.d.ts +17 -0
  197. package/dist/declarations/src/shell.d.ts +99 -0
  198. package/dist/declarations/src/views.d.ts +152 -0
  199. package/dist/development-server.d.ts +121 -0
  200. package/dist/development-server.js +331 -0
  201. package/dist/emit/common.d.ts +103 -0
  202. package/dist/emit/common.js +170 -0
  203. package/dist/emit/html-source.d.ts +46 -0
  204. package/dist/emit/html-source.js +322 -0
  205. package/dist/emit/manifest.d.ts +138 -0
  206. package/dist/emit/manifest.js +74 -0
  207. package/dist/emit/react.d.ts +16 -0
  208. package/dist/emit/react.js +210 -0
  209. package/dist/emit/scratch.d.ts +40 -0
  210. package/dist/emit/scratch.js +116 -0
  211. package/dist/emit/source.d.ts +87 -0
  212. package/dist/emit/source.js +789 -0
  213. package/dist/emit/svelte.d.ts +9 -0
  214. package/dist/emit/svelte.js +177 -0
  215. package/dist/emit/vue.d.ts +2 -0
  216. package/dist/emit/vue.js +152 -0
  217. package/dist/enumerate.d.ts +2 -0
  218. package/dist/enumerate.js +162 -0
  219. package/dist/generate.d.ts +43 -0
  220. package/dist/generate.js +302 -0
  221. package/dist/html-stylesheet.d.ts +43 -0
  222. package/dist/html-stylesheet.js +145 -0
  223. package/dist/index.d.ts +18 -0
  224. package/dist/index.js +21 -0
  225. package/dist/landing.d.ts +16 -0
  226. package/dist/landing.js +45 -0
  227. package/dist/lib/exported-types.d.ts +42 -0
  228. package/dist/lib/exported-types.js +86 -0
  229. package/dist/lib/html-attributes.d.ts +2 -0
  230. package/dist/lib/html-attributes.js +111 -0
  231. package/dist/lib/html-warnings.d.ts +19 -0
  232. package/dist/lib/html-warnings.js +79 -0
  233. package/dist/lib/jsx-roots.d.ts +22 -0
  234. package/dist/lib/jsx-roots.js +243 -0
  235. package/dist/lib/module-of-source.d.ts +18 -0
  236. package/dist/lib/module-of-source.js +24 -0
  237. package/dist/lib/naming.d.ts +29 -0
  238. package/dist/lib/naming.js +56 -0
  239. package/dist/lib/parse-type.d.ts +32 -0
  240. package/dist/lib/parse-type.js +103 -0
  241. package/dist/lib/react-spelling.d.ts +68 -0
  242. package/dist/lib/react-spelling.js +197 -0
  243. package/dist/lib/scenario-story.d.ts +41 -0
  244. package/dist/lib/scenario-story.js +84 -0
  245. package/dist/lib/slot-fill.d.ts +15 -0
  246. package/dist/lib/slot-fill.js +92 -0
  247. package/dist/lib/template-files.d.ts +14 -0
  248. package/dist/lib/template-files.js +25 -0
  249. package/dist/lib/types.d.ts +741 -0
  250. package/dist/lib/types.js +13 -0
  251. package/dist/lib/void-elements.d.ts +7 -0
  252. package/dist/lib/void-elements.js +13 -0
  253. package/dist/load.d.ts +37 -0
  254. package/dist/load.js +82 -0
  255. package/dist/model.d.ts +44 -0
  256. package/dist/model.js +464 -0
  257. package/dist/options.d.ts +224 -0
  258. package/dist/options.js +223 -0
  259. package/dist/prop-types.d.ts +26 -0
  260. package/dist/prop-types.js +102 -0
  261. package/dist/props-from.d.ts +84 -0
  262. package/dist/props-from.js +510 -0
  263. package/dist/protocol.d.ts +541 -0
  264. package/dist/protocol.js +819 -0
  265. package/dist/react-view.d.ts +22 -0
  266. package/dist/react-view.js +36 -0
  267. package/dist/react.d.ts +17 -0
  268. package/dist/react.js +23 -0
  269. package/dist/sass-importers.d.ts +26 -0
  270. package/dist/sass-importers.js +32 -0
  271. package/dist/shell-acceptance.d.ts +21 -0
  272. package/dist/shell-acceptance.js +37 -0
  273. package/dist/shell-page.d.ts +36 -0
  274. package/dist/shell-page.js +90 -0
  275. package/dist/shell-peers.d.ts +38 -0
  276. package/dist/shell-peers.js +61 -0
  277. package/dist/shell.d.ts +99 -0
  278. package/dist/shell.js +52 -0
  279. package/dist/shells/charcell/page.d.ts +8 -0
  280. package/dist/shells/charcell/page.js +69 -0
  281. package/dist/story-source.d.ts +113 -0
  282. package/dist/story-source.js +271 -0
  283. package/dist/story.d.ts +5 -0
  284. package/dist/story.js +28 -0
  285. package/dist/testing.d.ts +218 -0
  286. package/dist/testing.js +284 -0
  287. package/dist/views.d.ts +152 -0
  288. package/dist/views.js +7 -0
  289. package/dist/vite-configuration.d.ts +114 -0
  290. package/dist/vite-configuration.js +578 -0
  291. package/package.json +123 -3
  292. package/src/build.ts +51 -0
  293. package/src/check.ts +1062 -0
  294. package/src/cli.ts +123 -0
  295. package/src/context.ts +1168 -0
  296. package/src/controller/catalog.ts +719 -0
  297. package/src/controller/create-preview-controller.ts +2683 -0
  298. package/src/controller/editor-tree.ts +530 -0
  299. package/src/controller/html-source.ts +114 -0
  300. package/src/controller/index.ts +105 -0
  301. package/src/controller/persistence.ts +403 -0
  302. package/src/controller/regeneration.ts +55 -0
  303. package/src/controller/source.ts +333 -0
  304. package/src/controller/store.ts +55 -0
  305. package/src/development-server.ts +442 -0
  306. package/src/emit/common.ts +201 -0
  307. package/src/emit/html-source.ts +402 -0
  308. package/src/emit/manifest.ts +241 -0
  309. package/src/emit/react.ts +263 -0
  310. package/src/emit/scratch.ts +175 -0
  311. package/src/emit/source.ts +1094 -0
  312. package/src/emit/svelte.ts +230 -0
  313. package/src/emit/vue.ts +194 -0
  314. package/src/enumerate.ts +220 -0
  315. package/src/generate.ts +443 -0
  316. package/src/html-stylesheet.ts +173 -0
  317. package/src/index.ts +60 -0
  318. package/src/landing.ts +58 -0
  319. package/src/lib/exported-types.ts +114 -0
  320. package/src/lib/html-attributes.ts +113 -0
  321. package/src/lib/html-warnings.ts +81 -0
  322. package/src/lib/jsx-roots.ts +238 -0
  323. package/src/lib/module-of-source.ts +26 -0
  324. package/src/lib/naming.ts +65 -0
  325. package/src/lib/parse-type.ts +143 -0
  326. package/src/lib/react-spelling.ts +235 -0
  327. package/src/lib/scenario-story.ts +97 -0
  328. package/src/lib/slot-fill.ts +102 -0
  329. package/src/lib/template-files.ts +31 -0
  330. package/src/lib/types.ts +778 -0
  331. package/src/lib/void-elements.ts +15 -0
  332. package/src/load.ts +144 -0
  333. package/src/model.ts +568 -0
  334. package/src/options.ts +435 -0
  335. package/src/prop-types.ts +133 -0
  336. package/src/props-from.ts +678 -0
  337. package/src/protocol.ts +1135 -0
  338. package/src/react-view.ts +45 -0
  339. package/src/react.ts +34 -0
  340. package/src/sass-importers.ts +45 -0
  341. package/src/shell-acceptance.ts +45 -0
  342. package/src/shell-page.ts +133 -0
  343. package/src/shell-peers.ts +70 -0
  344. package/src/shell.ts +194 -0
  345. package/src/shells/charcell/page.ts +82 -0
  346. package/src/story-source.ts +391 -0
  347. package/src/story.ts +42 -0
  348. package/src/testing.ts +497 -0
  349. package/src/views.ts +183 -0
  350. package/src/vite-configuration.ts +675 -0
@@ -0,0 +1,322 @@
1
+ // The html "source" of a story: not a source a consumer writes, but the markup
2
+ // the story renders to - the template rendered once, at build time, for the
3
+ // story's props and slot content. A kit's docs show it beside the React, Vue
4
+ // and Svelte snippets. It is markup only: no behavior, no comments, and it
5
+ // assumes the kit's stylesheet. A story with a part that has no markup form
6
+ // has no html source.
7
+ import { renderInstance, } from '@js-template-engine/core';
8
+ import { bem } from '@js-template-engine/extension-bem';
9
+ import { tailwind } from '@js-template-engine/extension-tailwind';
10
+ import { componentNameFromFile } from '../lib/naming.js';
11
+ import { styleDeclarations } from '../lib/react-spelling.js';
12
+ import { collectParts, collectSlotComponents } from '../lib/slot-fill.js';
13
+ /**
14
+ * Renders a story to markup. A component written by hand renders as the kit
15
+ * maps it - the content passed into it, at rest, or the template it names -
16
+ * inside one comment saying its behavior is not included; a slot fill
17
+ * written per framework (`raw`, `scoped`) renders its `html`. A part renders
18
+ * as a component whose template is its `html`, calling itself as deep as
19
+ * the data it is given goes. A component without a template that the kit
20
+ * does not map, or such a fill or part without `html`, leaves the story
21
+ * with no markup, and the result names them. What the render cannot work
22
+ * out at rest, such as an expression reading the component's script state,
23
+ * is left out of the markup and named in the result's warnings.
24
+ */
25
+ export function htmlSource(story) {
26
+ const templates = new Map();
27
+ // The kit component each template key (a name or an export name) is.
28
+ const componentOf = new Map();
29
+ const fills = { markups: [], missing: [] };
30
+ // The story's parts, as components of its own; a part's name wins over a
31
+ // kit component's.
32
+ const parts = new Map();
33
+ const besideFills = [story.around?.before, story.around?.after];
34
+ for (const part of collectParts([
35
+ story.children,
36
+ ...Object.values(story.named),
37
+ ...besideFills,
38
+ ]).values()) {
39
+ if (part.html === undefined) {
40
+ fills.missing.push(`the part ${part.name}, with no html`);
41
+ continue;
42
+ }
43
+ parts.set(part.name, {
44
+ type: 'component',
45
+ name: part.name,
46
+ props: Object.fromEntries(part.parameters.map((name) => [name, { type: 'unknown' }])),
47
+ children: part.html,
48
+ });
49
+ }
50
+ for (const entry of story.components) {
51
+ const template = namedTemplate(entry);
52
+ if (template === undefined)
53
+ continue;
54
+ templates.set(entry.name, template);
55
+ componentOf.set(entry.name, entry.name);
56
+ if (entry.exportName !== undefined) {
57
+ templates.set(entry.exportName, template);
58
+ componentOf.set(entry.exportName, entry.name);
59
+ }
60
+ }
61
+ const rendered = new Set();
62
+ if (story.component.template !== undefined)
63
+ rendered.add(story.component.name);
64
+ // A hand-written component's own props, read from its specification.
65
+ const ownProps = new Map();
66
+ for (const entry of story.components) {
67
+ if (entry.template !== undefined)
68
+ continue;
69
+ ownProps.set(entry.name, entry.props);
70
+ if (entry.exportName !== undefined)
71
+ ownProps.set(entry.exportName, entry.props);
72
+ }
73
+ const slots = {};
74
+ for (const [name, fill] of Object.entries(story.named))
75
+ slots[name] = slotContent(fill, fills);
76
+ const children = story.children === undefined
77
+ ? undefined
78
+ : slotContent(story.children, fills);
79
+ // A component with no template renders as a reference to itself, which the
80
+ // resolver answers from the kit's map or leaves unresolved.
81
+ const template = namedTemplate(story.component) ?? [
82
+ {
83
+ type: 'element',
84
+ tag: story.component.exportName ?? story.component.name,
85
+ attributes: attributesOf(story.props),
86
+ ...(children === undefined
87
+ ? {}
88
+ : {
89
+ children: children.content,
90
+ ...(children.slotScope === undefined
91
+ ? {}
92
+ : { slotScope: children.slotScope }),
93
+ }),
94
+ ...(Object.keys(slots).length === 0 ? {} : { slots }),
95
+ },
96
+ ];
97
+ const resolveComponent = (tag) => {
98
+ const part = parts.get(tag);
99
+ if (part !== undefined)
100
+ return part;
101
+ const template = templates.get(tag);
102
+ if (template !== undefined) {
103
+ rendered.add(componentOf.get(tag) ?? tag);
104
+ return template;
105
+ }
106
+ const mapping = handWrittenMapping(story.handWrittenComponents[tag]);
107
+ if (mapping === undefined)
108
+ return undefined;
109
+ if (mapping.template === 'content')
110
+ return { rendersAs: 'content' };
111
+ const target = templates.get(mapping.template);
112
+ if (target !== undefined)
113
+ rendered.add(componentOf.get(mapping.template) ?? mapping.template);
114
+ return target === undefined
115
+ ? undefined
116
+ : {
117
+ rendersAs: target,
118
+ props: Object.keys(ownProps.get(tag) ?? {}),
119
+ ...(mapping.slots === undefined ? {} : { slots: mapping.slots }),
120
+ };
121
+ };
122
+ const shared = {
123
+ componentName: story.component.name,
124
+ resolveComponent,
125
+ scope: story.scope,
126
+ extensions: stylingExtensions(story.styling),
127
+ placement: story.styling.placement,
128
+ };
129
+ const own = renderInstance(template, {
130
+ ...shared,
131
+ props: story.props,
132
+ children,
133
+ slots,
134
+ });
135
+ // The content beside the component renders on its own, as its siblings.
136
+ const beside = besideFills.map((fill) => fill === undefined
137
+ ? undefined
138
+ : renderInstance(fillNodes(fill, fills), shared));
139
+ const renders = [beside[0], own, beside[1]].filter((result) => result !== undefined);
140
+ const markup = renders.map((result) => result.markup).join('\n');
141
+ const unresolved = [
142
+ ...new Set(renders.flatMap((result) => result.unresolved)),
143
+ ];
144
+ const warnings = renders.flatMap((result) => result.warnings);
145
+ const missing = [
146
+ ...unresolved.map((name) => story.handWrittenComponents[name] === undefined
147
+ ? `${name}, a component with no template that handWrittenComponents does not map`
148
+ : `${name}, mapped to ${handWrittenMapping(story.handWrittenComponents[name])?.template}, which is no template of the kit`),
149
+ ...fills.missing,
150
+ ];
151
+ if (missing.length > 0)
152
+ return { missing };
153
+ // Each fill's markup went in as a placeholder text node; it takes its place.
154
+ const filled = markup.replace(/\uE000(\d+)\uE001/g, (_, index) => fills.markups[Number(index)]);
155
+ // A fill written per framework names the kit components its markup holds.
156
+ const referenced = new Set();
157
+ for (const fill of [
158
+ story.children,
159
+ ...Object.values(story.named),
160
+ ...besideFills,
161
+ ])
162
+ collectSlotComponents(fill, referenced);
163
+ for (const name of referenced) {
164
+ const component = componentOf.get(name);
165
+ if (component !== undefined)
166
+ rendered.add(component);
167
+ }
168
+ return {
169
+ markup: `${filled}\n`,
170
+ components: [...rendered],
171
+ // Only the expressions left out: a styling extension's notices belong
172
+ // to the kit's build.
173
+ warnings: [
174
+ ...new Set(warnings
175
+ .filter((warning) => warning.kind === 'unevaluated')
176
+ .map((warning) => warning.message)),
177
+ ],
178
+ };
179
+ }
180
+ /**
181
+ * A component's template under the name the kit's build gives it. A bare
182
+ * node array takes its file-derived name, as the build does, so its
183
+ * `data-jte-node` markers match the kit's stylesheet whichever tag or
184
+ * hand-written component reaches it.
185
+ */
186
+ function namedTemplate(entry) {
187
+ const template = entry.template;
188
+ if (template === undefined || !Array.isArray(template))
189
+ return template;
190
+ return {
191
+ type: 'component',
192
+ name: componentNameFromFile(entry.file),
193
+ children: template,
194
+ };
195
+ }
196
+ /** A hand-written component's entry in the kit's map, in its object form. */
197
+ function handWrittenMapping(entry) {
198
+ return typeof entry === 'string' ? { template: entry } : entry;
199
+ }
200
+ /**
201
+ * A top-level fill as slot content. A scoped fill whose html is template
202
+ * nodes reads the values the slot exposes under its parameter names.
203
+ */
204
+ function slotContent(fill, fills) {
205
+ const content = fillNodes(fill, fills);
206
+ return fill.kind === 'scoped' && Array.isArray(fill.html)
207
+ ? { content, slotScope: fill.parameters }
208
+ : { content };
209
+ }
210
+ function stylingExtensions(styling) {
211
+ return styling.extensions.map((name) => name === 'bem' ? bem(styling.bem) : tailwind(styling.tailwind));
212
+ }
213
+ /**
214
+ * A slot fill as template nodes. A fill written per framework becomes a
215
+ * placeholder for its html, which is markup and so cannot be a node.
216
+ */
217
+ function fillNodes(fill, fills) {
218
+ switch (fill.kind) {
219
+ case 'text':
220
+ return [{ type: 'text', content: fill.value }];
221
+ case 'fragment':
222
+ return fill.children.flatMap((child) => fillNodes(child, fills));
223
+ case 'html':
224
+ return [
225
+ {
226
+ type: 'element',
227
+ tag: fill.tag,
228
+ attributes: attributesOf(fill.props ?? {}),
229
+ ...(fill.children === undefined
230
+ ? {}
231
+ : { children: fillNodes(fill.children, fills) }),
232
+ },
233
+ ];
234
+ case 'element': {
235
+ const slots = {};
236
+ for (const [name, slotFill] of Object.entries(fill.slots ?? {}))
237
+ slots[name] = fillNodes(slotFill, fills);
238
+ return [
239
+ {
240
+ type: 'element',
241
+ tag: fill.component,
242
+ attributes: attributesOf(fill.props ?? {}),
243
+ ...(fill.children === undefined
244
+ ? {}
245
+ : { children: fillNodes(fill.children, fills) }),
246
+ ...(Object.keys(slots).length === 0 ? {} : { slots }),
247
+ },
248
+ ];
249
+ }
250
+ case 'part':
251
+ // The part renders as the component the story declares it as; one
252
+ // with no html is already named as missing.
253
+ if (fill.html === undefined)
254
+ return [];
255
+ return [
256
+ {
257
+ type: 'element',
258
+ tag: fill.name,
259
+ attributes: attributesOf(fill.props ?? {}),
260
+ },
261
+ ];
262
+ case 'raw':
263
+ case 'scoped': {
264
+ // Template nodes render like any other content, composed components
265
+ // included.
266
+ if (Array.isArray(fill.html))
267
+ return fill.html;
268
+ if (fill.html === undefined) {
269
+ fills.missing.push(fill.kind === 'raw'
270
+ ? 'a raw slot fill with no html'
271
+ : `a scoped slot fill (${fill.parameters.join(', ')}) with no html`);
272
+ }
273
+ // A fill with no html still holds its place, so its slot is not empty;
274
+ // the story then has no markup at all.
275
+ fills.markups.push(typeof fill.html === 'string' ? fill.html : '');
276
+ return [
277
+ {
278
+ type: 'text',
279
+ content: `\uE000${fills.markups.length - 1}\uE001`,
280
+ },
281
+ ];
282
+ }
283
+ }
284
+ }
285
+ /**
286
+ * Props as template attributes. A value an attribute cannot hold - an
287
+ * object, an array - is passed as an expression, so it still reaches a
288
+ * resolved component as its prop. A `style`, given as CSS text or an object,
289
+ * is a whole-object style expression, so it is written inline.
290
+ */
291
+ function attributesOf(props) {
292
+ const attributes = {};
293
+ for (const [name, value] of Object.entries(props)) {
294
+ if (value === undefined || value === null)
295
+ continue;
296
+ if (name === 'style') {
297
+ const style = typeof value === 'string' ? styleObject(value) : value;
298
+ attributes.style = { $expression: JSON.stringify(style) };
299
+ continue;
300
+ }
301
+ attributes[name] =
302
+ typeof value === 'object'
303
+ ? { $expression: JSON.stringify(value) }
304
+ : value;
305
+ }
306
+ return attributes;
307
+ }
308
+ /** CSS declarations - `padding-left: 2ch; color: red` - as a style object,
309
+ * a `;` inside quotes or parentheses (`url("data:...;base64,...")`) kept. */
310
+ function styleObject(css) {
311
+ const style = {};
312
+ for (const declaration of styleDeclarations(css)) {
313
+ const colon = declaration.indexOf(':');
314
+ if (colon === -1)
315
+ continue;
316
+ const property = declaration.slice(0, colon).trim();
317
+ const value = declaration.slice(colon + 1).trim();
318
+ if (property !== '' && value !== '')
319
+ style[property] = value;
320
+ }
321
+ return style;
322
+ }
@@ -0,0 +1,138 @@
1
+ import type { ContentSlots, JsonValue, PreviewLabels, PreviewLandingConfiguration, PreviewPaneWidth, PreviewPersistence, SlotPlan, StoryAround, PreviewBinding, ResolvedStory, PreviewPropType, Target } from '../lib/types.js';
2
+ import type { PreviewTarget } from '../protocol.js';
3
+ import type { ViewFramework } from '../views.js';
4
+ export interface ManifestComponent {
5
+ id: string;
6
+ name: string;
7
+ title: string;
8
+ /** What the component is, from its template. Absent when it has none. */
9
+ description?: string;
10
+ category: string;
11
+ /** Each prop's control and its declaration (type as written, whether it is
12
+ * required, the component's own default). */
13
+ propTypes: PreviewPropType[];
14
+ /** The props that are events: functions returning nothing, which the
15
+ * component calls as things happen. Absent when there are none. */
16
+ events?: string[];
17
+ /** The component's two-way props. Absent when there are none. */
18
+ bindings?: PreviewBinding[];
19
+ defaultProps: Record<string, JsonValue>;
20
+ /** The values in `defaultProps` the preview starts from on its own (a kit
21
+ * hint's), which a consumer's source leaves out. Absent when there are none. */
22
+ previewDefaults?: Record<string, JsonValue>;
23
+ scenarios: {
24
+ id: string;
25
+ label: string;
26
+ /** What the scenario shows, from the story file. Absent when it has none. */
27
+ description?: string;
28
+ props: Record<string, JsonValue>;
29
+ /** The option values picking the scenario sets. Absent when it sets none. */
30
+ options?: Record<string, string | boolean>;
31
+ default?: boolean;
32
+ generated?: boolean;
33
+ /** The slot content the scenario shows, when it has content of its own:
34
+ * its fills over the story's. Absent when it shows the story's. */
35
+ content?: SlotPlan;
36
+ /** The id the panes mount the scenario's story by, when it has content
37
+ * of its own. Absent when the panes mount the component's story. */
38
+ story?: string;
39
+ }[];
40
+ /** The slots this component accepts - the editor's add-content targets. */
41
+ slots: ContentSlots;
42
+ /** `false` for a component with no story of its own: present for the
43
+ * editor's picker, hidden from the story navigation (see
44
+ * Story.standalone). Absent ⇒ a normal browseable story. */
45
+ standalone?: boolean;
46
+ /** A story reachable at its address but left out of the navigation, the
47
+ * editor's picker and the counts (see Story.unlisted). Absent ⇒ listed. */
48
+ unlisted?: boolean;
49
+ /** The story file's curated slot content, so the per-story editor seeds its tree
50
+ * from what the browse view already renders. Absent
51
+ * when the component has no story file slot plan. */
52
+ content?: SlotPlan;
53
+ /** The content the story renders beside the component (see Story.around).
54
+ * Absent when it has none. */
55
+ around?: StoryAround;
56
+ /** Per-story preview-option defaults / availability (see Story.options). Absent
57
+ * when the component curates none. */
58
+ options?: Record<string, JsonValue | false>;
59
+ /** The preview source this component belongs to (`ManifestSource.id`). The host groups
60
+ * the navigation by source; core components are `'core'`. */
61
+ source: string;
62
+ /** The targets this component renders into, within the kit's own. The host shows
63
+ * a pane + toggle per kit target and disables the rest; a React-only fixture of
64
+ * another package's components lists just `react`. */
65
+ targets: Target[];
66
+ }
67
+ /** A navigation source - the kit's own components or another package's. The host renders one
68
+ * collapsible section per source, in `order`, its `label` the heading. */
69
+ export interface ManifestSource {
70
+ id: string;
71
+ label: string;
72
+ order: number;
73
+ /** The package the source's components import from, per target
74
+ * `<moduleBase>/<target>`, or `<moduleBase>` with `{target}` replaced by
75
+ * the target when it names one. */
76
+ moduleBase?: string;
77
+ }
78
+ /** How a consumer imports one of the kit's components. */
79
+ export interface ManifestImport {
80
+ /** The name the component is exported under. */
81
+ exportName: string;
82
+ /** The names it declares that React would otherwise respell (`class`,
83
+ * `style`, an attribute React renames, such as `tabindex`), which React
84
+ * takes as they are; any other attribute a story gives it is spelled as
85
+ * React takes it. Absent when it declares none. */
86
+ declaredAttributes?: string[];
87
+ /** The module it is imported from, per target the kit builds. */
88
+ modules: Partial<Record<Target, string>>;
89
+ /** The type names its module exports, per target the kit builds, which
90
+ * the module a consumer imports it from exports too. Absent where it
91
+ * exports none. */
92
+ types?: Partial<Record<Target, string[]>>;
93
+ }
94
+ export interface Manifest {
95
+ /** The kit's name (the kit configuration's `name`) - the host's kit selector. */
96
+ kitName: string;
97
+ /** The kit's version (its package.json `version`) - the host's version label. */
98
+ kitVersion?: string;
99
+ colorOptions: (string | null)[];
100
+ /** What the kit builds that the host offers a pane for, and for these
101
+ * alone: its targets, and `html` when it builds html. */
102
+ targets: PreviewTarget[];
103
+ /** The sources, for the navigation's per-source sections (ordered by the host). */
104
+ sources: ManifestSource[];
105
+ /** The kit's own code block, when it names one: the framework it mounts
106
+ * with. A shell mounts it in place of its own code view. */
107
+ codeBlock?: {
108
+ framework: ViewFramework;
109
+ };
110
+ components: ManifestComponent[];
111
+ /** How a consumer imports each of the kit's components, by name: every
112
+ * component, those with no story of their own included, so a story's
113
+ * source can import what its slot content names. */
114
+ imports?: Record<string, ManifestImport>;
115
+ /** The host's own copy (the synthetic empty scenario's label), in the kit's casing. */
116
+ labels: {
117
+ emptyScenario: string;
118
+ };
119
+ /** Where the host remembers what a person chose (`preview.persistence`).
120
+ * Absent means `'url'`. */
121
+ persistence?: PreviewPersistence;
122
+ /** The widths a shell offers to lay the story panes out at
123
+ * (the configuration module's `previewPaneWidths`). Absent means the preview's own. */
124
+ paneWidths?: PreviewPaneWidth[];
125
+ /** The mode the kit builds its Svelte target in (`svelte.mode`), which a
126
+ * story's Svelte source follows. Absent means `legacy`. */
127
+ svelteMode?: 'legacy' | 'runes';
128
+ /** The entry the host opens on when its address names none
129
+ * (`preview.landing`). Absent means the first listed story. */
130
+ landing?: PreviewLandingConfiguration;
131
+ /** How React spells the HTML attributes it renames (`tabindex` as
132
+ * `tabIndex`), by their HTML names, which a story's React source spells
133
+ * a component's attributes with. */
134
+ reactAttributeNames?: Record<string, string>;
135
+ }
136
+ export declare function buildManifest(models: ResolvedStory[], sources: ManifestSource[], colorTokens?: (string | null | undefined)[], kitName?: string, labels?: PreviewLabels, kitVersion?: string, persistence?: PreviewPersistence, targets?: PreviewTarget[], imports?: Record<string, ManifestImport>, codeBlock?: {
137
+ framework: ViewFramework;
138
+ }, paneWidths?: PreviewPaneWidth[], svelteMode?: 'legacy' | 'runes', reactAttributeNames?: Readonly<Record<string, string>>, landing?: PreviewLandingConfiguration): Manifest;
@@ -0,0 +1,74 @@
1
+ // Emit the framework-neutral host manifest (manifest.json): the nav list, the
2
+ // per-component controls (propTypes/defaultProps/scenarios), and the shared color
3
+ // token list for color-select controls. Custom views own their data outside
4
+ // this manifest, so it privileges no single view.
5
+ import { sanitize, scenarioStoryId } from '../lib/naming.js';
6
+ import { scenarioSlotPlan } from '../lib/scenario-story.js';
7
+ import { ALL_TARGETS } from '../lib/types.js';
8
+ function manifestComponent(model) {
9
+ return {
10
+ id: sanitize(model.title),
11
+ name: model.name,
12
+ title: model.title,
13
+ ...(model.description !== undefined
14
+ ? { description: model.description }
15
+ : {}),
16
+ category: model.title.split('/').slice(0, -1).join('/'),
17
+ propTypes: model.propTypes,
18
+ ...(model.events?.length ? { events: model.events } : {}),
19
+ ...(model.bindings?.length ? { bindings: model.bindings } : {}),
20
+ defaultProps: model.defaultProps,
21
+ ...(model.previewDefaults
22
+ ? { previewDefaults: model.previewDefaults }
23
+ : {}),
24
+ scenarios: model.scenarios.map((scenario) => ({
25
+ id: scenario.id,
26
+ label: scenario.label ?? scenario.id,
27
+ ...(scenario.description !== undefined
28
+ ? { description: scenario.description }
29
+ : {}),
30
+ props: scenario.props ?? {},
31
+ ...(scenario.options !== undefined &&
32
+ Object.keys(scenario.options).length > 0
33
+ ? { options: scenario.options }
34
+ : {}),
35
+ ...(scenario.default ? { default: true } : {}),
36
+ ...(scenario.generated ? { generated: true } : {}),
37
+ ...(scenario.slots === undefined
38
+ ? {}
39
+ : {
40
+ content: scenarioSlotPlan(model.slots, scenario.slots) ?? {},
41
+ story: scenarioStoryId(sanitize(model.title), scenario.id),
42
+ }),
43
+ })),
44
+ slots: model.contentSlots,
45
+ source: model.source ?? 'core',
46
+ targets: model.targets,
47
+ ...(model.slots ? { content: model.slots } : {}),
48
+ ...(model.around ? { around: model.around } : {}),
49
+ ...(model.standalone ? {} : { standalone: false }),
50
+ ...(model.unlisted ? { unlisted: true } : {}),
51
+ ...(model.options ? { options: model.options } : {}),
52
+ };
53
+ }
54
+ export function buildManifest(models, sources, colorTokens = [], kitName = 'kit', labels = {}, kitVersion, persistence = 'url', targets = ALL_TARGETS, imports, codeBlock, paneWidths, svelteMode, reactAttributeNames, landing) {
55
+ return {
56
+ kitName,
57
+ ...(kitVersion ? { kitVersion } : {}),
58
+ targets,
59
+ // JSON has no `undefined`; the unset color option serializes to null.
60
+ colorOptions: colorTokens.map((colorToken) => colorToken ?? null),
61
+ sources,
62
+ components: models.map(manifestComponent),
63
+ ...(imports ? { imports } : {}),
64
+ ...(codeBlock ? { codeBlock } : {}),
65
+ labels: { emptyScenario: labels.emptyScenario ?? 'Empty' },
66
+ persistence,
67
+ ...(paneWidths ? { paneWidths } : {}),
68
+ ...(svelteMode ? { svelteMode } : {}),
69
+ ...(reactAttributeNames
70
+ ? { reactAttributeNames: { ...reactAttributeNames } }
71
+ : {}),
72
+ ...(landing ? { landing: { ...landing } } : {}),
73
+ };
74
+ }
@@ -0,0 +1,16 @@
1
+ import type { ResolvedStory, Target } from '../lib/types.js';
2
+ /**
3
+ * The React render-registry module: each story's id → its render function.
4
+ *
5
+ * @param models - The stories React renders.
6
+ * @param moduleFor - The module a component is imported from, per target.
7
+ * @param exportFor - The name a component is exported under.
8
+ * @param declaredAttributes - The names a component declares that React
9
+ * would otherwise respell (`class`, `style`, an attribute React renames),
10
+ * which it takes as they are; every other attribute a story gives a
11
+ * component is spelled as React takes it.
12
+ * @returns The registry module's source: the `registry`, and the
13
+ * `reactAttributeNames` and `declaredAttributes` (of each story's root, by
14
+ * id) the React pane spells a story's live props with.
15
+ */
16
+ export declare function emitReactRegistry(models: ResolvedStory[], moduleFor: (name: string, target: Target) => string, exportFor?: (name: string) => string, declaredAttributes?: (component: string) => readonly string[]): string;