@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,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,315 @@
1
+ // Where the controller keeps what a person chose: the host page's query
2
+ // parameters, which make a link a deep link into the preview, and, when the
3
+ // kit asks for it, the browser's local storage, which remembers the global
4
+ // option values across sessions. Everything read back is checked against the
5
+ // catalog and the options, so a stale or hand-edited value is ignored.
6
+ // Browser-safe: no node imports.
7
+ import { stableStringify } from './editor-tree.js';
8
+ import { acceptsOptionValue, } from '../options.js';
9
+ /** The host page's query parameters the controller reads and writes. */
10
+ export const URL_PARAMETER = {
11
+ /** The selected component story's id. */
12
+ component: 'component',
13
+ /** The selected custom view's id. */
14
+ view: 'view',
15
+ /** The selected scenario's id. */
16
+ scenario: 'scenario',
17
+ /** The story's root props that differ from its scenario's, as JSON. */
18
+ props: 'props',
19
+ /** The visible targets, comma-separated, when not every one is visible. */
20
+ targets: 'targets',
21
+ /** The width the story panes are laid out at, in CSS pixels, when they
22
+ * are not fitted to the space the shell gives them. */
23
+ width: 'width',
24
+ /** The prefix of an option's parameter: `option.<id>=<value>`. */
25
+ optionPrefix: 'option.',
26
+ };
27
+ /**
28
+ * Read the controller's parameters from a query string.
29
+ *
30
+ * @param search - The query string, with or without its leading `?`.
31
+ * @returns The parameters, unchecked.
32
+ */
33
+ export function readUrlState(search) {
34
+ const parameters = new URLSearchParams(search);
35
+ const options = {};
36
+ for (const [key, value] of parameters) {
37
+ if (key.startsWith(URL_PARAMETER.optionPrefix))
38
+ options[key.slice(URL_PARAMETER.optionPrefix.length)] = value;
39
+ }
40
+ const value = (key) => parameters.get(key) ?? undefined;
41
+ return {
42
+ component: value(URL_PARAMETER.component),
43
+ view: value(URL_PARAMETER.view),
44
+ scenario: value(URL_PARAMETER.scenario),
45
+ props: value(URL_PARAMETER.props),
46
+ targets: value(URL_PARAMETER.targets),
47
+ width: value(URL_PARAMETER.width),
48
+ options,
49
+ };
50
+ }
51
+ /**
52
+ * An option's value as written in a query parameter or storage: `true` or
53
+ * `false` for a boolean, one of its values for a choice.
54
+ *
55
+ * @param option - The option.
56
+ * @param raw - The value as written.
57
+ * @returns The value, or `undefined` when the option cannot hold it.
58
+ */
59
+ export function parseOptionValue(option, raw) {
60
+ if (option.values === undefined) {
61
+ if (raw === 'true' || raw === true)
62
+ return true;
63
+ if (raw === 'false' || raw === false)
64
+ return false;
65
+ return undefined;
66
+ }
67
+ return acceptsOptionValue(option, raw) ? raw : undefined;
68
+ }
69
+ /**
70
+ * The visible targets a query parameter names, among the kit's, `html`
71
+ * included where the kit builds it. An empty parameter names none; one that
72
+ * names none of the kit's is ignored.
73
+ *
74
+ * @param raw - The parameter as written: a comma-separated list.
75
+ * @param targets - The kit's targets (`PreviewCatalog.targets`).
76
+ * @returns The targets in the kit's order, or `undefined` when the
77
+ * parameter is to be ignored.
78
+ */
79
+ export function parseTargets(raw, targets) {
80
+ const named = raw.split(',').map((name) => name.trim());
81
+ const known = targets.filter((target) => named.includes(target));
82
+ if (raw.trim() === '')
83
+ return [];
84
+ return known.length > 0 ? known : undefined;
85
+ }
86
+ /** The widest a story pane is laid out at, in CSS pixels: an 8K screen's width. */
87
+ export const MAXIMUM_PANE_WIDTH = 7680;
88
+ /**
89
+ * Whether `value` can be a story pane's width: a whole number of CSS pixels,
90
+ * from 1 to `MAXIMUM_PANE_WIDTH`.
91
+ *
92
+ * @param value - The candidate width.
93
+ * @returns Whether it is one.
94
+ */
95
+ export function isPaneWidth(value) {
96
+ return (typeof value === 'number' &&
97
+ Number.isInteger(value) &&
98
+ value > 0 &&
99
+ value <= MAXIMUM_PANE_WIDTH);
100
+ }
101
+ /**
102
+ * The story panes' width a query parameter names: a whole number of CSS
103
+ * pixels, from 1 to `MAXIMUM_PANE_WIDTH`.
104
+ *
105
+ * @param raw - The parameter as written, such as `768`.
106
+ * @returns The width, or `undefined` when the parameter is to be ignored.
107
+ */
108
+ export function parsePaneWidth(raw) {
109
+ if (!/^\d+$/.test(raw.trim()))
110
+ return undefined;
111
+ const width = Number(raw.trim());
112
+ return isPaneWidth(width) ? width : undefined;
113
+ }
114
+ /**
115
+ * Whether a prop's control can hold `value`: a boolean for a toggle, a
116
+ * finite number for a number input, one of its values for a select, one of
117
+ * the color tokens for a color select, and a string or a number for a text
118
+ * input.
119
+ *
120
+ * @param propType - The prop.
121
+ * @param value - The candidate value.
122
+ * @param colorTokens - The color tokens a color select offers.
123
+ * @returns Whether the prop accepts the value.
124
+ */
125
+ export function acceptsPropValue(propType, value, colorTokens) {
126
+ switch (propType.control) {
127
+ case 'boolean':
128
+ return typeof value === 'boolean';
129
+ case 'number':
130
+ return typeof value === 'number' && Number.isFinite(value);
131
+ case 'select':
132
+ return ((typeof value === 'string' || typeof value === 'boolean') &&
133
+ (propType.options ?? []).includes(value));
134
+ case 'color-select':
135
+ return typeof value === 'string' && colorTokens.includes(value);
136
+ case 'text':
137
+ return (typeof value === 'string' ||
138
+ (typeof value === 'number' && Number.isFinite(value)));
139
+ }
140
+ }
141
+ /**
142
+ * The props that differ from `base`, as the address holds them: each prop
143
+ * whose value differs, and each prop of `base` the props leave out, as
144
+ * `null`, so a link opens on what renders. {@link parseProps} reads them
145
+ * back over the same `base`.
146
+ *
147
+ * @param props - The props the story renders with.
148
+ * @param base - The props the story starts from: its scenario's.
149
+ * @param marksMissing - Whether a prop of `base` the props leave out is
150
+ * written as `null`.
151
+ * @returns The props that differ, in their order, then those left out.
152
+ * @example
153
+ * ```ts
154
+ * changedProps({ selected: 'b', items }, { selected: 'a', items, icon: 'plus' }, () => true);
155
+ * // { selected: 'b', icon: null }
156
+ * ```
157
+ */
158
+ export function changedProps(props, base, marksMissing) {
159
+ const changed = {};
160
+ for (const [name, value] of Object.entries(props))
161
+ if (value !== undefined &&
162
+ stableStringify(value) !== stableStringify(base[name]))
163
+ changed[name] = value;
164
+ for (const [name, value] of Object.entries(base))
165
+ if (value !== undefined && props[name] === undefined && marksMissing(name))
166
+ changed[name] = null;
167
+ return changed;
168
+ }
169
+ /**
170
+ * The root props a query parameter gives, checked against the component's
171
+ * props. The parameter holds the props that differ from the scenario's: a
172
+ * prop it leaves out takes its value in `defaults`, the scenario's props, as
173
+ * a freshly picked scenario does, and a prop it sets to `null` is left out
174
+ * of the result, unless `fallback` holds `null` for it, which keeps the
175
+ * `null`.
176
+ * Only props the component declares, with a value its control
177
+ * accepts, are kept; a declared prop whose value is refused keeps its value
178
+ * in `fallback`, the scenario's props, or else its default. A parameter that
179
+ * is not a JSON object is ignored.
180
+ *
181
+ * @param raw - The parameter as written.
182
+ * @param propTypes - The component's props.
183
+ * @param defaults - The props a prop left out keeps: the scenario's.
184
+ * @param fallback - The scenario's props, for a refused value.
185
+ * @param colorTokens - The color tokens a color select offers.
186
+ * @returns The props, or `undefined` when the parameter is to be ignored.
187
+ * @example
188
+ * ```ts
189
+ * parseProps('{"variant":"ghost","icon":null}', propTypes, { size: 'md', icon: 'plus' }, {}, []);
190
+ * // { size: 'md', variant: 'ghost' }
191
+ * ```
192
+ */
193
+ export function parseProps(raw, propTypes, defaults, fallback, colorTokens) {
194
+ let parsed;
195
+ try {
196
+ parsed = JSON.parse(raw);
197
+ }
198
+ catch {
199
+ return undefined;
200
+ }
201
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
202
+ return undefined;
203
+ const props = { ...defaults };
204
+ for (const [name, value] of Object.entries(parsed)) {
205
+ const propType = propTypes.find((candidate) => candidate.name === name);
206
+ if (!propType)
207
+ continue;
208
+ if (value === null) {
209
+ if (fallback[name] === null)
210
+ props[name] = null;
211
+ else
212
+ delete props[name];
213
+ }
214
+ else if (acceptsPropValue(propType, value, colorTokens))
215
+ props[name] = value;
216
+ else if (fallback[name] !== undefined)
217
+ props[name] = fallback[name];
218
+ }
219
+ return props;
220
+ }
221
+ /**
222
+ * Write the controller's parameters into a query string, keeping every
223
+ * parameter that is not the controller's.
224
+ *
225
+ * @param search - The current query string.
226
+ * @param state - What to write.
227
+ * @returns The new query string, without its leading `?`.
228
+ */
229
+ export function writeUrlState(search, state) {
230
+ const parameters = new URLSearchParams(search);
231
+ for (const key of [...parameters.keys()]) {
232
+ if (key === URL_PARAMETER.component ||
233
+ key === URL_PARAMETER.view ||
234
+ key === URL_PARAMETER.scenario ||
235
+ key === URL_PARAMETER.props ||
236
+ key === URL_PARAMETER.targets ||
237
+ key === URL_PARAMETER.width ||
238
+ key.startsWith(URL_PARAMETER.optionPrefix)) {
239
+ parameters.delete(key);
240
+ }
241
+ }
242
+ parameters.set(state.selection.kind === 'view'
243
+ ? URL_PARAMETER.view
244
+ : URL_PARAMETER.component, state.selection.id);
245
+ if (state.scenario !== undefined)
246
+ parameters.set(URL_PARAMETER.scenario, state.scenario);
247
+ if (state.props !== undefined)
248
+ parameters.set(URL_PARAMETER.props, JSON.stringify(state.props));
249
+ if (state.targets !== undefined)
250
+ parameters.set(URL_PARAMETER.targets, state.targets.join(','));
251
+ if (state.width !== undefined)
252
+ parameters.set(URL_PARAMETER.width, String(state.width));
253
+ for (const [id, value] of Object.entries(state.options)) {
254
+ parameters.set(`${URL_PARAMETER.optionPrefix}${id}`, String(value));
255
+ }
256
+ // A comma and a colon need no escaping in a query string: left as they
257
+ // are, a list of targets and a story's props stay readable.
258
+ return parameters.toString().replace(/%2C/gi, ',').replace(/%3A/gi, ':');
259
+ }
260
+ /**
261
+ * The local-storage key a kit's remembered option values live under.
262
+ *
263
+ * @param kitName - The kit's name.
264
+ * @returns The key.
265
+ */
266
+ export function storageKey(kitName) {
267
+ return `scaffold-ui-kit-preview:${kitName}:options`;
268
+ }
269
+ /**
270
+ * The option values remembered under `key`, those the options can still
271
+ * hold. Storage that cannot be read, or holds something else, gives none.
272
+ *
273
+ * @param storage - The storage.
274
+ * @param key - The key.
275
+ * @param options - The options the values may belong to.
276
+ * @returns The values, keyed by option id.
277
+ */
278
+ export function readStoredOptions(storage, key, options) {
279
+ let stored;
280
+ try {
281
+ const text = storage.getItem(key);
282
+ stored = text === null ? undefined : JSON.parse(text);
283
+ }
284
+ catch {
285
+ return {};
286
+ }
287
+ if (typeof stored !== 'object' || stored === null || Array.isArray(stored))
288
+ return {};
289
+ const values = {};
290
+ for (const option of options) {
291
+ const value = parseOptionValue(option, stored[option.id]);
292
+ if (value !== undefined)
293
+ values[option.id] = value;
294
+ }
295
+ return values;
296
+ }
297
+ /**
298
+ * Remember option values under `key`; with none, forget them. A storage that
299
+ * refuses the write (private browsing, a full or blocked store) is ignored.
300
+ *
301
+ * @param storage - The storage.
302
+ * @param key - The key.
303
+ * @param values - The values to remember, keyed by option id.
304
+ */
305
+ export function writeStoredOptions(storage, key, values) {
306
+ try {
307
+ if (Object.keys(values).length === 0)
308
+ storage.removeItem(key);
309
+ else
310
+ storage.setItem(key, JSON.stringify(values));
311
+ }
312
+ catch {
313
+ // Nothing to do: the values simply are not remembered.
314
+ }
315
+ }
@@ -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,27 @@
1
+ // How the controller regenerates the scratch story: the payload it sends and
2
+ // the transport that carries it. The development server answers the request;
3
+ // a static build has no endpoint, so a controller created without a transport
4
+ // reports regeneration as unavailable. Browser-safe.
5
+ /** The path the preview's development server answers regeneration requests on. */
6
+ export const REGENERATION_ENDPOINT = '/__preview_regenerate';
7
+ /**
8
+ * A transport that POSTs the payload as JSON to the development server's
9
+ * regeneration endpoint. A response that is not ok rejects with the response's text,
10
+ * or its status when the text is empty.
11
+ *
12
+ * @param endpoint - The endpoint's path; the development server's by default.
13
+ * @param fetchImplementation - The `fetch` to use; the global one by default.
14
+ * @returns The transport.
15
+ */
16
+ export function createFetchRegenerationTransport(endpoint = REGENERATION_ENDPOINT, fetchImplementation = (...parameters) => fetch(...parameters)) {
17
+ return async (payload) => {
18
+ const response = await fetchImplementation(endpoint, {
19
+ method: 'POST',
20
+ body: JSON.stringify(payload),
21
+ });
22
+ if (!response.ok) {
23
+ const text = await response.text().catch(() => '');
24
+ throw new Error(text || `HTTP ${response.status}`);
25
+ }
26
+ };
27
+ }
@@ -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;