@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,161 @@
1
+ import type { AroundFill, JsonValue, SlotFill, SlotPlan, StoryAround } from '../lib/types.js';
2
+ export type { AroundFill, SlotFill, SlotPlan, StoryAround };
3
+ type Json = unknown;
4
+ /** A fill the editor cannot author: a `raw` body, a `scoped` slot or a
5
+ * `part` call, each per-target strings. It is held verbatim, so it can be
6
+ * moved or removed but not edited, and serializes back unchanged. */
7
+ export type OpaqueFill = Extract<SlotFill, {
8
+ kind: 'raw' | 'scoped' | 'part';
9
+ }>;
10
+ export type EditorNode = {
11
+ kind: 'text';
12
+ value: string;
13
+ id?: string;
14
+ } | {
15
+ kind: 'element';
16
+ component: string;
17
+ props: Record<string, Json>;
18
+ slots: Record<string, EditorNode[]>;
19
+ id?: string;
20
+ } | {
21
+ kind: 'html';
22
+ tag: string;
23
+ props: Record<string, Json>;
24
+ slots: Record<string, EditorNode[]>;
25
+ id?: string;
26
+ } | {
27
+ kind: 'opaque';
28
+ fill: OpaqueFill;
29
+ id?: string;
30
+ };
31
+ /** A node that holds content of its own: an element or an HTML tag. */
32
+ export type ContainerNode = Extract<EditorNode, {
33
+ kind: 'element' | 'html';
34
+ }>;
35
+ export declare function isContainer(node: EditorNode): node is ContainerNode;
36
+ export declare const DEFAULT_SLOT = "default";
37
+ /** The plain wrapper tags an HTML node can be, picked from a list rather than
38
+ * typed: the layout and content elements a slot fill might need around its
39
+ * children. */
40
+ export declare const HTML_TAGS: string[];
41
+ /** Gives every node in the content an id, in place: idempotent, and the spreads
42
+ * every update makes carry a node's id along. */
43
+ export declare function ensureIds(content: Record<string, EditorNode[]>): void;
44
+ /** The root's state: its component, its props and its content keyed by
45
+ * slot. The content the story renders beside the root is not the tree's: it
46
+ * is the story's (`PreviewComponent.around`), which no edit reaches. */
47
+ export interface EditorState {
48
+ root: string;
49
+ props: Record<string, Json>;
50
+ slots: Record<string, EditorNode[]>;
51
+ }
52
+ /** One hop into a slot: which slot, and the node's index in it. */
53
+ export interface Step {
54
+ slot: string;
55
+ index: number;
56
+ }
57
+ /** A node's address: the hops from the root, one per slot it descends into.
58
+ * The empty path `[]` addresses the root itself. */
59
+ export type NodePath = Step[];
60
+ /** Where a move lands: into `slot` of the node at `parent`, before `index`
61
+ * (counted before the moved node is removed). */
62
+ export interface DropTarget {
63
+ parent: Step[];
64
+ slot: string;
65
+ index: number;
66
+ }
67
+ /** Apply `transform` to the node at `path` (path must be non-empty). */
68
+ export declare function updateAt(content: Record<string, EditorNode[]>, path: Step[], transform: (node: EditorNode) => EditorNode): Record<string, EditorNode[]>;
69
+ /** Insert `child` into `slot` of the node at `parentPath` (empty path = the
70
+ * root's slots) at `index`; an omitted index appends. */
71
+ export declare function insertAt(content: Record<string, EditorNode[]>, parentPath: Step[], slot: string, child: EditorNode, index?: number): Record<string, EditorNode[]>;
72
+ /** Remove the node at `path` (path must be non-empty). */
73
+ export declare function removeAt(content: Record<string, EditorNode[]>, path: Step[]): Record<string, EditorNode[]>;
74
+ /** The node at `path`, or null when nothing is there. The root is the tree
75
+ * itself rather than a node of its content, so the empty path gives null. */
76
+ export declare function nodeAt(content: Record<string, EditorNode[]>, path: Step[]): EditorNode | null;
77
+ /**
78
+ * The path of a child: the node at `index` in `slot` of the node at `parent`.
79
+ *
80
+ * @param parent - The parent's path; `[]` for the root.
81
+ * @param slot - The slot the child is in.
82
+ * @param index - The child's index in the slot.
83
+ * @returns The child's path.
84
+ */
85
+ export declare function childPath(parent: NodePath, slot: string, index: number): NodePath;
86
+ /**
87
+ * A string that identifies a path, for a key or a lookup: `'root'` for the
88
+ * root, otherwise each step's slot and index.
89
+ *
90
+ * @param path - The path.
91
+ * @returns The key, such as `'default:0/header:1'`.
92
+ */
93
+ export declare function pathKey(path: NodePath): string;
94
+ /** Move the node at `from` to `target`: remove it, then insert it, adjusting the
95
+ * target for the index shift the removal causes in a shared sibling list. The
96
+ * root, a missing node, and a drop into the node's own subtree leave the
97
+ * content unchanged (the same object back). */
98
+ export declare function moveNode(content: Record<string, EditorNode[]>, from: Step[], target: DropTarget): Record<string, EditorNode[]>;
99
+ /** A sortable list's address: the parent whose slot it lists, and the slot. */
100
+ export interface SortableListAddress {
101
+ parent: Step[];
102
+ slot: string;
103
+ }
104
+ /** Translate a sortable move (where the node ends up in its list) into the path
105
+ * it leaves and the drop target `moveNode` takes (the index it goes before,
106
+ * counted before the removal). */
107
+ export declare function resolveSortableMove(source: SortableListAddress, target: SortableListAddress, sameList: boolean, fromIndex: number, toIndex: number): {
108
+ from: Step[];
109
+ target: DropTarget;
110
+ };
111
+ /** What the editor reads of a manifest component to seed a node from it. */
112
+ export interface SeedableComponent {
113
+ name: string;
114
+ defaultProps: Record<string, Json>;
115
+ content?: SlotPlan;
116
+ }
117
+ /** A component swapped in under an existing node: its default props, with a
118
+ * string `children` default as a default-slot text child (children is the
119
+ * default slot, not a prop). */
120
+ export declare function seedNode(component: SeedableComponent): EditorNode;
121
+ /** A component added through the add dialog. With `props` the node carries them
122
+ * plus the component's curated slot content (the default or a named scenario);
123
+ * without, it comes in empty - no props, no content. */
124
+ export declare function seedComponentNode(component: SeedableComponent, props?: Record<string, Json>): EditorNode;
125
+ /** The root seeded from its story file content, so the tree starts from what the
126
+ * browse view renders, with `props` (a story's scenario-merged props) or the
127
+ * component's defaults. */
128
+ export declare function seedRoot(component: SeedableComponent, props?: Record<string, Json>): EditorState;
129
+ /**
130
+ * A key for a tree's slot content, equal for two trees of the same content
131
+ * whatever their node ids or the order of their props' keys: what the
132
+ * regeneration payload would carry, serialized with sorted keys.
133
+ */
134
+ export declare function slotsKey(slots: Record<string, EditorNode[]>): string;
135
+ /** A value as JSON with every object's keys sorted, so two values equal by
136
+ * content serialize the same; `undefined` entries are left out. */
137
+ export declare function stableStringify(value: unknown): string;
138
+ /**
139
+ * The props as JSON, each one left unset (`undefined`) left out. An empty
140
+ * string is a value like any other and stays, so a component given `''`
141
+ * keeps it on every update; a story unsets a prop with `null`.
142
+ *
143
+ * @param record - The props, from the controls or a pane's write-back.
144
+ * @returns The props that are set.
145
+ */
146
+ export declare function cleanRecord(record: Record<string, Json>): Record<string, JsonValue>;
147
+ export declare function namedFills(slots: Record<string, EditorNode[]>): Record<string, SlotFill>;
148
+ export declare function fillToNodes(fill: SlotFill | undefined): EditorNode[];
149
+ /** Seed a root component's slot content from its story file SlotPlan, falling back to
150
+ * a default-slot text child when a string `children` prop is the only content. */
151
+ export declare function seedSlots(content: SlotPlan | undefined, props: Record<string, Json>): Record<string, EditorNode[]>;
152
+ /** The regeneration payload for a root component, its props and its slot
153
+ * content. */
154
+ export declare function toPayload(state: EditorState): {
155
+ rootComponent: string;
156
+ props: Record<string, JsonValue>;
157
+ slots: {
158
+ named?: Record<string, SlotFill> | undefined;
159
+ default?: SlotFill | undefined;
160
+ } | undefined;
161
+ };
@@ -0,0 +1,62 @@
1
+ import type { JsonValue, SlotPlan, StoryAround } from '../lib/types.js';
2
+ /** A story to print as html: the root component, its props and its slot content. */
3
+ export interface HtmlSourceRequest {
4
+ /** The root component's name. */
5
+ rootComponent: string;
6
+ /** The props to render it with. */
7
+ props: Record<string, JsonValue>;
8
+ /** Its slot content: the default slot and the named slots. */
9
+ slots?: SlotPlan;
10
+ /** The content beside the root, as its siblings: `before` and `after` it. */
11
+ around?: StoryAround;
12
+ }
13
+ /**
14
+ * A story's html: its markup, with the styles the kit's build wrote for the
15
+ * components it renders when there are any and the warnings for what the
16
+ * markup leaves out when there are any, or what keeps it from having markup.
17
+ */
18
+ export type HtmlSourceResponse = {
19
+ markup: string;
20
+ stylesheet?: string;
21
+ warnings?: string[];
22
+ } | {
23
+ missing: string[];
24
+ };
25
+ /**
26
+ * Prints a story's html. It resolves with the markup or what the story holds
27
+ * that has no markup, and rejects with the reason it could not print; the
28
+ * controller aborts `signal` when the story changes before it answers.
29
+ */
30
+ export type HtmlSourceTransport = (request: HtmlSourceRequest, signal: AbortSignal) => Promise<HtmlSourceResponse>;
31
+ /**
32
+ * Reads the html printed ahead of time for a component's scenarios, by
33
+ * scenario id (`''` for the anonymous default). It rejects when there is
34
+ * none to read.
35
+ */
36
+ export type ScenarioHtmlSourceLoader = (componentId: string) => Promise<Record<string, HtmlSourceResponse>>;
37
+ /** The path the preview's development server answers html source requests on. */
38
+ export declare const HTML_SOURCE_ENDPOINT = "/__preview_html_source";
39
+ /** The directory, under the URL the preview is served from, that the static
40
+ * build keeps each component's scenario html in, one `<component id>.json`
41
+ * each. */
42
+ export declare const HTML_SOURCE_DIRECTORY = "html-source";
43
+ /**
44
+ * A transport that POSTs the story as JSON to the development server's html
45
+ * source endpoint and reads the JSON it answers. A response that is not ok
46
+ * rejects with the response's text, or its status when the text is empty.
47
+ *
48
+ * @param endpoint - The endpoint's path; the development server's by default.
49
+ * @param fetchImplementation - The `fetch` to use; the global one by default.
50
+ * @returns The transport.
51
+ */
52
+ export declare function createFetchHtmlSourceTransport(endpoint?: string, fetchImplementation?: typeof fetch): HtmlSourceTransport;
53
+ /**
54
+ * A loader that fetches a component's scenario html from the files the
55
+ * static build serves, `<baseUrl>html-source/<component id>.json`, once per
56
+ * component.
57
+ *
58
+ * @param baseUrl - The URL the preview is served under, ending in `/`.
59
+ * @param fetchImplementation - The `fetch` to use; the global one by default.
60
+ * @returns The loader.
61
+ */
62
+ export declare function createStaticHtmlSourceLoader(baseUrl: string, fetchImplementation?: typeof fetch): ScenarioHtmlSourceLoader;
@@ -0,0 +1,9 @@
1
+ export { createPreviewController, PREVIEW_FRAME_SHOWN_ATTRIBUTE, REGENERATION_DEBOUNCE_MILLISECONDS, SCRATCH_STORY_ID, type PreviewController, type PreviewControllerOptions, type PreviewEditorState, type PreviewEvent, type PreviewFrameReadiness, type PreviewFrameTarget, type PreviewHtmlSource, type PreviewInsertTarget, type PreviewNodeRequest, type PreviewOptionDescriptor, type PreviewRegenerationStatus, type PreviewSelection, type PreviewSortableDrop, type PreviewCode, type PreviewState, type PreviewTimers, } from './create-preview-controller.js';
2
+ export { printStorySource, type PreviewTargetCode } from './source.js';
3
+ export { createFetchHtmlSourceTransport, createStaticHtmlSourceLoader, HTML_SOURCE_DIRECTORY, HTML_SOURCE_ENDPOINT, type HtmlSourceRequest, type HtmlSourceResponse, type HtmlSourceTransport, type ScenarioHtmlSourceLoader, } from './html-source.js';
4
+ export { previewStore, type PreviewStore } from './store.js';
5
+ export type { PreviewPaneWidth } from '../lib/types.js';
6
+ export { catalogFromManifest, DEFAULT_PANE_WIDTHS, defaultScenarioId, nodeAddSlots, nodeSlots, scenarioChoices, storyFrameKey, type CatalogManifest, type PreviewBinding, type PreviewCatalog, type PreviewCatalogView, type PreviewComponent, type PreviewImport, type PreviewLanding, type PreviewNavigationNode, type PreviewPropType, type PreviewScenario, type PreviewSource, type PreviewStoryReference, type ScenarioChoice, } from './catalog.js';
7
+ export { acceptsPropValue, changedProps, isPaneWidth, MAXIMUM_PANE_WIDTH, parseTargets, parseOptionValue, parsePaneWidth, parseProps, readUrlState, storageKey, URL_PARAMETER, writeUrlState, type PreviewStorage, type UrlState, type UrlStateToWrite, } from './persistence.js';
8
+ export { createFetchRegenerationTransport, REGENERATION_ENDPOINT, type RegenerationPayload, type RegenerationTransport, } from './regeneration.js';
9
+ export { childPath, cleanRecord, DEFAULT_SLOT, HTML_TAGS, isContainer, nodeAt, pathKey, seedNode, type AroundFill, type ContainerNode, type DropTarget, type EditorNode, type EditorState, type NodePath, type OpaqueFill, type SortableListAddress, type Step, type StoryAround, } from './editor-tree.js';
@@ -0,0 +1,191 @@
1
+ import type { PreviewPropType } from '../lib/types.js';
2
+ import { type OptionValue, type PreviewOption } from '../options.js';
3
+ import type { PreviewTarget } from '../protocol.js';
4
+ /** The host page's query parameters the controller reads and writes. */
5
+ export declare const URL_PARAMETER: {
6
+ /** The selected component story's id. */
7
+ readonly component: "component";
8
+ /** The selected custom view's id. */
9
+ readonly view: "view";
10
+ /** The selected scenario's id. */
11
+ readonly scenario: "scenario";
12
+ /** The story's root props that differ from its scenario's, as JSON. */
13
+ readonly props: "props";
14
+ /** The visible targets, comma-separated, when not every one is visible. */
15
+ readonly targets: "targets";
16
+ /** The width the story panes are laid out at, in CSS pixels, when they
17
+ * are not fitted to the space the shell gives them. */
18
+ readonly width: "width";
19
+ /** The prefix of an option's parameter: `option.<id>=<value>`. */
20
+ readonly optionPrefix: "option.";
21
+ };
22
+ /** The part of the Web Storage interface the controller uses. */
23
+ export type PreviewStorage = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
24
+ /** What the query parameters say, before it is checked against the catalog. */
25
+ export interface UrlState {
26
+ component?: string;
27
+ view?: string;
28
+ scenario?: string;
29
+ /** The root props as written: JSON, unparsed. */
30
+ props?: string;
31
+ /** The visible targets as written: a comma-separated list. */
32
+ targets?: string;
33
+ /** The story panes' width as written. */
34
+ width?: string;
35
+ /** Option values as written, keyed by option id. */
36
+ options: Record<string, string>;
37
+ }
38
+ /** What the controller writes to the query parameters. */
39
+ export interface UrlStateToWrite {
40
+ selection: {
41
+ kind: 'component' | 'view';
42
+ id: string;
43
+ };
44
+ /** The scenario, when it is not the story's default. */
45
+ scenario?: string;
46
+ /** The root props that differ from the scenario's, a prop of the
47
+ * scenario's the story leaves out set to `null`. */
48
+ props?: Record<string, unknown>;
49
+ /** The visible targets, `html` among them, when not every one of the
50
+ * kit's is visible. */
51
+ targets?: readonly PreviewTarget[];
52
+ /** The story panes' width in CSS pixels, when they are not fitted. */
53
+ width?: number;
54
+ /** The option values to keep, keyed by option id. */
55
+ options: Record<string, OptionValue>;
56
+ }
57
+ /**
58
+ * Read the controller's parameters from a query string.
59
+ *
60
+ * @param search - The query string, with or without its leading `?`.
61
+ * @returns The parameters, unchecked.
62
+ */
63
+ export declare function readUrlState(search: string): UrlState;
64
+ /**
65
+ * An option's value as written in a query parameter or storage: `true` or
66
+ * `false` for a boolean, one of its values for a choice.
67
+ *
68
+ * @param option - The option.
69
+ * @param raw - The value as written.
70
+ * @returns The value, or `undefined` when the option cannot hold it.
71
+ */
72
+ export declare function parseOptionValue(option: Pick<PreviewOption, 'values'>, raw: unknown): OptionValue | undefined;
73
+ /**
74
+ * The visible targets a query parameter names, among the kit's, `html`
75
+ * included where the kit builds it. An empty parameter names none; one that
76
+ * names none of the kit's is ignored.
77
+ *
78
+ * @param raw - The parameter as written: a comma-separated list.
79
+ * @param targets - The kit's targets (`PreviewCatalog.targets`).
80
+ * @returns The targets in the kit's order, or `undefined` when the
81
+ * parameter is to be ignored.
82
+ */
83
+ export declare function parseTargets(raw: string, targets: readonly PreviewTarget[]): PreviewTarget[] | undefined;
84
+ /** The widest a story pane is laid out at, in CSS pixels: an 8K screen's width. */
85
+ export declare const MAXIMUM_PANE_WIDTH = 7680;
86
+ /**
87
+ * Whether `value` can be a story pane's width: a whole number of CSS pixels,
88
+ * from 1 to `MAXIMUM_PANE_WIDTH`.
89
+ *
90
+ * @param value - The candidate width.
91
+ * @returns Whether it is one.
92
+ */
93
+ export declare function isPaneWidth(value: unknown): value is number;
94
+ /**
95
+ * The story panes' width a query parameter names: a whole number of CSS
96
+ * pixels, from 1 to `MAXIMUM_PANE_WIDTH`.
97
+ *
98
+ * @param raw - The parameter as written, such as `768`.
99
+ * @returns The width, or `undefined` when the parameter is to be ignored.
100
+ */
101
+ export declare function parsePaneWidth(raw: string): number | undefined;
102
+ /**
103
+ * Whether a prop's control can hold `value`: a boolean for a toggle, a
104
+ * finite number for a number input, one of its values for a select, one of
105
+ * the color tokens for a color select, and a string or a number for a text
106
+ * input.
107
+ *
108
+ * @param propType - The prop.
109
+ * @param value - The candidate value.
110
+ * @param colorTokens - The color tokens a color select offers.
111
+ * @returns Whether the prop accepts the value.
112
+ */
113
+ export declare function acceptsPropValue(propType: Pick<PreviewPropType, 'control' | 'options'>, value: unknown, colorTokens: readonly (string | null)[]): boolean;
114
+ /**
115
+ * The props that differ from `base`, as the address holds them: each prop
116
+ * whose value differs, and each prop of `base` the props leave out, as
117
+ * `null`, so a link opens on what renders. {@link parseProps} reads them
118
+ * back over the same `base`.
119
+ *
120
+ * @param props - The props the story renders with.
121
+ * @param base - The props the story starts from: its scenario's.
122
+ * @param marksMissing - Whether a prop of `base` the props leave out is
123
+ * written as `null`.
124
+ * @returns The props that differ, in their order, then those left out.
125
+ * @example
126
+ * ```ts
127
+ * changedProps({ selected: 'b', items }, { selected: 'a', items, icon: 'plus' }, () => true);
128
+ * // { selected: 'b', icon: null }
129
+ * ```
130
+ */
131
+ export declare function changedProps(props: Record<string, unknown>, base: Record<string, unknown>, marksMissing: (name: string) => boolean): Record<string, unknown>;
132
+ /**
133
+ * The root props a query parameter gives, checked against the component's
134
+ * props. The parameter holds the props that differ from the scenario's: a
135
+ * prop it leaves out takes its value in `defaults`, the scenario's props, as
136
+ * a freshly picked scenario does, and a prop it sets to `null` is left out
137
+ * of the result, unless `fallback` holds `null` for it, which keeps the
138
+ * `null`.
139
+ * Only props the component declares, with a value its control
140
+ * accepts, are kept; a declared prop whose value is refused keeps its value
141
+ * in `fallback`, the scenario's props, or else its default. A parameter that
142
+ * is not a JSON object is ignored.
143
+ *
144
+ * @param raw - The parameter as written.
145
+ * @param propTypes - The component's props.
146
+ * @param defaults - The props a prop left out keeps: the scenario's.
147
+ * @param fallback - The scenario's props, for a refused value.
148
+ * @param colorTokens - The color tokens a color select offers.
149
+ * @returns The props, or `undefined` when the parameter is to be ignored.
150
+ * @example
151
+ * ```ts
152
+ * parseProps('{"variant":"ghost","icon":null}', propTypes, { size: 'md', icon: 'plus' }, {}, []);
153
+ * // { size: 'md', variant: 'ghost' }
154
+ * ```
155
+ */
156
+ export declare function parseProps(raw: string, propTypes: readonly Pick<PreviewPropType, 'name' | 'control' | 'options'>[], defaults: Record<string, unknown>, fallback: Record<string, unknown>, colorTokens: readonly (string | null)[]): Record<string, unknown> | undefined;
157
+ /**
158
+ * Write the controller's parameters into a query string, keeping every
159
+ * parameter that is not the controller's.
160
+ *
161
+ * @param search - The current query string.
162
+ * @param state - What to write.
163
+ * @returns The new query string, without its leading `?`.
164
+ */
165
+ export declare function writeUrlState(search: string, state: UrlStateToWrite): string;
166
+ /**
167
+ * The local-storage key a kit's remembered option values live under.
168
+ *
169
+ * @param kitName - The kit's name.
170
+ * @returns The key.
171
+ */
172
+ export declare function storageKey(kitName: string): string;
173
+ /**
174
+ * The option values remembered under `key`, those the options can still
175
+ * hold. Storage that cannot be read, or holds something else, gives none.
176
+ *
177
+ * @param storage - The storage.
178
+ * @param key - The key.
179
+ * @param options - The options the values may belong to.
180
+ * @returns The values, keyed by option id.
181
+ */
182
+ export declare function readStoredOptions(storage: PreviewStorage, key: string, options: Array<Pick<PreviewOption, 'id' | 'values'>>): Record<string, OptionValue>;
183
+ /**
184
+ * Remember option values under `key`; with none, forget them. A storage that
185
+ * refuses the write (private browsing, a full or blocked store) is ignored.
186
+ *
187
+ * @param storage - The storage.
188
+ * @param key - The key.
189
+ * @param values - The values to remember, keyed by option id.
190
+ */
191
+ export declare function writeStoredOptions(storage: PreviewStorage, key: string, values: Record<string, OptionValue>): void;
@@ -0,0 +1,30 @@
1
+ import type { JsonValue, SlotPlan, StoryAround } from '../lib/types.js';
2
+ /** The scratch story to regenerate: the root component, its props and its slot content. */
3
+ export interface RegenerationPayload {
4
+ /** The root component's export name. */
5
+ rootComponent: string;
6
+ /** The root's own props. */
7
+ props: Record<string, JsonValue>;
8
+ /** The root's slot content: its default slot and its named slots. */
9
+ slots?: SlotPlan;
10
+ /** The content beside the root, as its siblings: `before` and `after` it. */
11
+ around?: StoryAround;
12
+ }
13
+ /**
14
+ * Carries a regeneration payload to whatever writes the scratch story. It resolves
15
+ * once the story is written and rejects with the reason it was not; the
16
+ * controller reports the rejection's message.
17
+ */
18
+ export type RegenerationTransport = (payload: RegenerationPayload) => Promise<void>;
19
+ /** The path the preview's development server answers regeneration requests on. */
20
+ export declare const REGENERATION_ENDPOINT = "/__preview_regenerate";
21
+ /**
22
+ * A transport that POSTs the payload as JSON to the development server's
23
+ * regeneration endpoint. A response that is not ok rejects with the response's text,
24
+ * or its status when the text is empty.
25
+ *
26
+ * @param endpoint - The endpoint's path; the development server's by default.
27
+ * @param fetchImplementation - The `fetch` to use; the global one by default.
28
+ * @returns The transport.
29
+ */
30
+ export declare function createFetchRegenerationTransport(endpoint?: string, fetchImplementation?: typeof fetch): RegenerationTransport;
@@ -0,0 +1,80 @@
1
+ import { type SourceBinding } from '../emit/source.js';
2
+ import type { JsonValue, SlotFill, StoryAround } from '../lib/types.js';
3
+ import type { PreviewScriptedTarget } from '../protocol.js';
4
+ import { type PreviewCatalog, type PreviewComponent, type PreviewScenario, type PreviewStoryReference } from './catalog.js';
5
+ import { type EditorState } from './editor-tree.js';
6
+ /** A story's source, by scripted target: what a consumer writes. */
7
+ export type PreviewTargetCode = Partial<Record<PreviewScriptedTarget, string>>;
8
+ /** A story resolved for printing: its component, the props to print and its
9
+ * slot content. */
10
+ export interface ResolvedSourceStory {
11
+ /** The root component's name. */
12
+ component: string;
13
+ /** The props a consumer writes: those that differ from what the component
14
+ * and the preview start from. */
15
+ props: Record<string, JsonValue>;
16
+ /** Default-slot content. */
17
+ children?: SlotFill;
18
+ /** Named-slot content, by slot name. */
19
+ named: Record<string, SlotFill>;
20
+ /** The content beside the component, as its siblings. */
21
+ around?: StoryAround;
22
+ /** The two-way props the story gives, which the printed source binds to
23
+ * state of its own. Absent when it gives none. */
24
+ bindings?: SourceBinding[];
25
+ }
26
+ /** The catalog fields the printing reads. */
27
+ export type SourceCatalog = Pick<PreviewCatalog, 'imports' | 'sources' | 'kitName'> & Partial<Pick<PreviewCatalog, 'svelteMode' | 'reactAttributeNames'>>;
28
+ /**
29
+ * Whether a story's default-slot text is the component's name the preview
30
+ * shows in a default slot the story leaves unfilled, which a consumer never
31
+ * writes: the preview's own starting text, while the scenario does not give
32
+ * `children` itself.
33
+ */
34
+ export declare function isPlaceholder(component: PreviewComponent, text: string, input: {
35
+ scenario?: PreviewScenario;
36
+ }): boolean;
37
+ /**
38
+ * Resolve what a story's source prints. Without a tree, the slot content is
39
+ * the story's own and a string `children` is its default-slot text; with the
40
+ * editor's tree, the root's props and content are the tree's. A prop is left
41
+ * out while it holds the component's declared default, or the preview's own
42
+ * starting value that the scenario does not set, as is the component's name
43
+ * the preview shows in a default slot the story leaves unfilled.
44
+ */
45
+ export declare function resolveSourceStory(component: PreviewComponent, input: {
46
+ props: Record<string, unknown>;
47
+ scenario?: PreviewScenario;
48
+ tree?: EditorState;
49
+ }): ResolvedSourceStory;
50
+ /**
51
+ * Print a resolved story in each of `targets`: a two-way prop it gives
52
+ * bound to state of the source's own, in the catalog's Svelte mode.
53
+ *
54
+ * @param catalog - The catalog the components' imports are read from.
55
+ * @param story - The story, resolved.
56
+ * @param targets - The targets to print.
57
+ * @returns The source per target.
58
+ */
59
+ export declare function printSourceStory(catalog: SourceCatalog, story: ResolvedSourceStory, targets: readonly PreviewScriptedTarget[]): PreviewTargetCode;
60
+ /**
61
+ * Print any story of the catalog as the source a consumer writes, per
62
+ * target the component renders in: the component with the props of the
63
+ * scenario over its defaults and `props` over those, its slot content, and
64
+ * imports from the kit's package entry for each target. A prop is left
65
+ * out while it holds the component's declared default. It takes the story
66
+ * reference `frames.mountStory` takes, so a shell can show the code beside a
67
+ * detached pane. The html source is the preview's own (`state.code.html`)
68
+ * and is not printed here.
69
+ *
70
+ * @param catalog - The controller's catalog.
71
+ * @param story - The story: a component's id, a scenario (omitted, the one
72
+ * the story starts on; `''`, the anonymous default) and props over its own.
73
+ * @returns The source per target, in the component's targets.
74
+ * @throws When the component or the scenario is unknown.
75
+ * @example
76
+ * ```ts
77
+ * const { react } = printStorySource(controller.catalog, { component: 'components-button', scenario: 'ghost' });
78
+ * ```
79
+ */
80
+ export declare function printStorySource(catalog: PreviewCatalog, story: PreviewStoryReference): PreviewTargetCode;
@@ -0,0 +1,27 @@
1
+ import type { PreviewController, PreviewState } from './create-preview-controller.js';
2
+ /** A readable store: `subscribe` calls `listener` with the current value
3
+ * immediately, then with each new value, until the returned function is called. */
4
+ export interface PreviewStore<Value> {
5
+ subscribe(listener: (value: Value) => void): () => void;
6
+ }
7
+ /**
8
+ * A store of the controller's state, or of a slice of it. Each subscriber is
9
+ * called with the current slice when it subscribes, and again only when the
10
+ * slice changes by identity, so `selector` returns a field of the state (or a
11
+ * primitive derived from it) rather than a fresh object or array.
12
+ *
13
+ * @param controller - The controller to read.
14
+ * @param selector - Picks the slice; the whole state when omitted.
15
+ * @returns The store.
16
+ * @example
17
+ * ```svelte
18
+ * <script lang="ts">
19
+ * import { previewStore } from '@scaffold-ui-kit/preview/shell';
20
+ * const preview = previewStore(controller);
21
+ * const scenario = previewStore(controller, (state) => state.scenario);
22
+ * </script>
23
+ *
24
+ * <p>{$preview.selection.id}: {$scenario}</p>
25
+ * ```
26
+ */
27
+ export declare function previewStore<Selected = PreviewState>(controller: Pick<PreviewController, 'getState' | 'subscribe'>, selector?: (state: PreviewState) => Selected): PreviewStore<Selected>;
@@ -0,0 +1,103 @@
1
+ import type { JsonValue, SlotFill, ResolvedStory } from '../lib/types.js';
2
+ export declare function serialize(value: JsonValue): string;
3
+ /**
4
+ * Text as a Vue or Svelte template reads it back: `&` and `<` escaped, as
5
+ * either would start a character reference or open a tag.
6
+ *
7
+ * @param value - The text as the story gives it.
8
+ * @returns The text as markup.
9
+ */
10
+ export declare function markupText(value: string): string;
11
+ /**
12
+ * Whether a text has whitespace a template does not keep as written:
13
+ * whitespace at an edge, a run of it or a line break, which a template
14
+ * trims, collapses, or loses where the printed element breaks over lines.
15
+ *
16
+ * @param value - The text as the story gives it.
17
+ * @returns Whether the text has to be printed as a string expression.
18
+ */
19
+ export declare function hasFragileWhitespace(value: string): boolean;
20
+ /**
21
+ * Text as a Vue template reads it back: markup text with each `{{` held in
22
+ * an interpolation of its own, so it does not open one.
23
+ *
24
+ * @param value - The text as the story gives it.
25
+ * @returns The text as Vue template content.
26
+ * @example
27
+ * vueText('Type {{ name }} here');
28
+ * // 'Type {{ "{{" }} name }} here'
29
+ */
30
+ export declare function vueText(value: string): string;
31
+ /**
32
+ * Text as a printed Vue template keeps it: {@link vueText}, or one string
33
+ * interpolation for a text with whitespace at an edge, a run of it or a
34
+ * line break, which Vue condenses and a printed element's line breaks
35
+ * replace.
36
+ *
37
+ * @param value - The text as the story gives it.
38
+ * @returns The text as Vue template content.
39
+ * @example
40
+ * vueSourceText(' 1 ripburger');
41
+ * // '{{ " 1 ripburger" }}'
42
+ */
43
+ export declare function vueSourceText(value: string): string;
44
+ /**
45
+ * The Vue template content before a junction, given the content joined onto
46
+ * it: a trailing `{` before content starting with one is held in an
47
+ * interpolation of its own, as the two would otherwise open one.
48
+ *
49
+ * @param before - The content before the junction.
50
+ * @param next - The content joined onto it.
51
+ * @returns The content before the junction, safe to join.
52
+ * @example
53
+ * vueJunction('Price: {', '{ amount }}');
54
+ * // "Price: {{ '{' }}"
55
+ */
56
+ export declare function vueJunction(before: string, next: string): string;
57
+ /**
58
+ * Vue template pieces joined into one, each junction separated by
59
+ * {@link vueJunction}.
60
+ *
61
+ * @param pieces - The template content, in order.
62
+ * @returns The joined content.
63
+ */
64
+ export declare function joinVue(pieces: string[]): string;
65
+ /**
66
+ * Text as a Svelte template reads it back: markup text with each brace held
67
+ * in an expression of its own, so none opens one. Svelte trims the whitespace
68
+ * at the edges of an element's or a component's content and collapses a run
69
+ * of it, so a text with whitespace at an edge, a run of it or a line break
70
+ * is one string expression instead, which Svelte renders as it is.
71
+ *
72
+ * @param value - The text as the story gives it.
73
+ * @returns The text as Svelte markup.
74
+ * @example
75
+ * svelteText('Price: {amount}');
76
+ * // "Price: {'{'}amount{'}'}"
77
+ * svelteText(' 1 ripburger');
78
+ * // '{" 1 ripburger"}'
79
+ */
80
+ export declare function svelteText(value: string): string;
81
+ /**
82
+ * A value as a Vue template's bound attribute holds it, single-quoted:
83
+ * the value's expression with `&` and `'` as character references, which
84
+ * the template reads back as the characters, so neither ends the attribute
85
+ * nor starts a reference of its own.
86
+ *
87
+ * @param value - The prop's value.
88
+ * @returns The attribute's text, quotes included.
89
+ * @example
90
+ * vueBoundAttribute("Don't");
91
+ * // `'"Don&#39;t"'`
92
+ */
93
+ export declare function vueBoundAttribute(value: JsonValue): string;
94
+ export declare function needsColor(model: ResolvedStory): boolean;
95
+ export declare function propTypesBody(model: ResolvedStory): string;
96
+ /** The effective default-slot fill: an explicit story file fill, or the `children`
97
+ * text prop for components that have a default slot and no story file fill. */
98
+ export type DefaultSlot = SlotFill | {
99
+ kind: 'propText';
100
+ prop: string;
101
+ } | undefined;
102
+ export declare function effectiveDefaultSlot(model: ResolvedStory): DefaultSlot;
103
+ export declare function namedSlots(model: ResolvedStory): Record<string, SlotFill>;