@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,532 @@
1
+ import { type OptionValue, type PreviewOption, type PreviewShellOption } from '../options.js';
2
+ import { type PreviewContentSize, type PreviewScriptedTarget, type PreviewTarget } from '../protocol.js';
3
+ import { type PreviewCatalog, type PreviewStoryReference } from './catalog.js';
4
+ import { type DropTarget, type EditorNode, type EditorState, type SortableListAddress, type Step } from './editor-tree.js';
5
+ import type { RegenerationTransport } from './regeneration.js';
6
+ import type { HtmlSourceTransport, ScenarioHtmlSourceLoader } from './html-source.js';
7
+ import { type PreviewTargetCode } from './source.js';
8
+ import type { PreviewPersistence } from '../lib/types.js';
9
+ import { type PreviewStorage } from './persistence.js';
10
+ /** The time edits coalesce for before the preview regenerates what they
11
+ * change, in milliseconds: the scratch story, and a story's html from the
12
+ * development server. */
13
+ export declare const REGENERATION_DEBOUNCE_MILLISECONDS = 250;
14
+ /** The story id the regenerated scratch story is mounted under. */
15
+ export declare const SCRATCH_STORY_ID = "scratch";
16
+ /**
17
+ * The attribute the controller sets on an iframe it mounted once the iframe
18
+ * shows its first content, and takes away while it loads again. Until then
19
+ * the iframe is hidden; a shell's CSS can show a loading note beside one
20
+ * without it.
21
+ */
22
+ export declare const PREVIEW_FRAME_SHOWN_ATTRIBUTE = "data-preview-shown";
23
+ /**
24
+ * An option a shell shows a control for: one of the kit's, or one the shell
25
+ * declared for itself, whose id is namespaced under `shell.` and whose value
26
+ * stays in the host page.
27
+ */
28
+ export interface PreviewOptionDescriptor extends Omit<PreviewOption, 'apply'> {
29
+ /** Whether the option is the kit's or the shell's own. */
30
+ origin: 'kit' | 'shell';
31
+ }
32
+ /** What the preview shows: a component story or a custom view. */
33
+ export type PreviewSelection = {
34
+ kind: 'component';
35
+ id: string;
36
+ } | {
37
+ kind: 'view';
38
+ id: string;
39
+ };
40
+ /** A preview iframe: a scripted target's pane, the html pane or the custom-view pane. */
41
+ export type PreviewFrameTarget = PreviewTarget | 'view';
42
+ /** Whether a mounted iframe has announced that it listens for messages. */
43
+ export type PreviewFrameReadiness = 'loading' | 'ready';
44
+ /** One call a story made of one of its events, as a pane recorded it. */
45
+ export interface PreviewEvent {
46
+ /** Its number among the events recorded, for a stable key. */
47
+ id: number;
48
+ /** The pane it was recorded in. */
49
+ target: PreviewFrameTarget;
50
+ /** The event: the function prop the story called. */
51
+ name: string;
52
+ /** A readable, one-line summary of what it was called with. */
53
+ payload: string;
54
+ /** When, in milliseconds since the epoch. */
55
+ time: number;
56
+ }
57
+ /** Where the regeneration of the scratch story stands. */
58
+ export interface PreviewRegenerationStatus {
59
+ /** `pending` from an edit until the story is written and the panes reloaded. */
60
+ status: 'idle' | 'pending' | 'error';
61
+ /** Why the last regeneration failed, while `status` is `error`. */
62
+ message?: string;
63
+ }
64
+ /** The scenario editor's state. */
65
+ export interface PreviewEditorState {
66
+ /** Whether a shell shows the editor. */
67
+ open: boolean;
68
+ /** The tree being edited: the story's component, its props and its slot
69
+ * content. Present while the editor is open or the Empty scenario is shown. */
70
+ tree?: EditorState;
71
+ /**
72
+ * Whether the tree's slot content differs from what it was seeded with:
73
+ * a node inserted, removed, moved or replaced, a nested node's props or a
74
+ * text changed. The root's props are not counted, as they live in `props`
75
+ * and the address. Content is compared by value, so an edit undone by hand
76
+ * counts as no change. A change of the root's text, which `props` shows as
77
+ * `children`, counts too. `false` without a tree, and again once the tree
78
+ * is seeded afresh (another story, or another scenario with the editor
79
+ * open). While it is `true` the address may not reproduce the panes, which
80
+ * show the edited content.
81
+ */
82
+ modified: boolean;
83
+ }
84
+ /**
85
+ * Where the html source of what the panes show stands: `ready` with the
86
+ * markup, `loading` while it is being printed, or `unavailable` with the
87
+ * reason, such as a story holding a part that has no markup, or a static
88
+ * build asked for props it printed no html for.
89
+ */
90
+ export type PreviewHtmlSource = {
91
+ status: 'ready';
92
+ source: string;
93
+ /** The styles the kit's build wrote for the components the markup
94
+ * renders, which the html pane shows it under. */
95
+ stylesheet?: string;
96
+ /** What the markup could not work out at rest and left out, such as
97
+ * an expression reading the component's script state, so that part
98
+ * shows at a default. Absent when there is nothing to name. */
99
+ warnings?: string[];
100
+ } | {
101
+ status: 'loading';
102
+ } | {
103
+ status: 'unavailable';
104
+ reason: string;
105
+ };
106
+ /** The code of what the selection's panes show. */
107
+ export interface PreviewCode {
108
+ /**
109
+ * The code a consumer writes for the story, per target the story
110
+ * renders in (`targets.supported`), html aside: the component with the props the
111
+ * panes show and its slot content, or the editor's tree while it holds
112
+ * one, importing from the kit's package entry for each target. A prop is
113
+ * left out while it holds the component's declared default. Printed as the
114
+ * state changes, so it is always present.
115
+ */
116
+ targets: PreviewTargetCode;
117
+ /** The markup the story renders to, at rest, for a reader who works
118
+ * without a framework. */
119
+ html: PreviewHtmlSource;
120
+ }
121
+ /**
122
+ * The preview's state as a shell reads it. Every field is plain data: a
123
+ * snapshot is immutable, and a new one replaces it on each change, with the
124
+ * unchanged fields kept by reference.
125
+ */
126
+ export interface PreviewState {
127
+ selection: PreviewSelection;
128
+ /** The selected scenario's id; `''` is the anonymous default. */
129
+ scenario: string;
130
+ /**
131
+ * The root props the selection's panes show now: the scenario's over the
132
+ * component's defaults, then whatever `setProps` or the editor's root set.
133
+ * While the editor holds a tree, a string `children` the story draws its
134
+ * default slot from is the root's text: `children` is the text while the
135
+ * root's default slot holds one text node and nothing else, and absent
136
+ * otherwise, as other content in that slot takes its place on screen. A
137
+ * story with default-slot content of its own shows that content and not
138
+ * `children`, so its props carry no `children` then. While a view is
139
+ * selected, the last story's.
140
+ */
141
+ props: Record<string, unknown>;
142
+ /** Every option's current value, the story's own defaults applied, keyed by
143
+ * option id; a shell's own options under their `shell.` ids. */
144
+ options: Record<string, OptionValue>;
145
+ /** The options a shell hides the controls of: those the selected story marks
146
+ * unavailable, and every story option while a view is selected. */
147
+ unavailableOptions: string[];
148
+ /**
149
+ * The story panes, by what each renders in: the kit's scripted targets, and
150
+ * `html` after them where the kit builds html. The html pane shows the
151
+ * markup in `code.html`, with the kit's stylesheets and options and no
152
+ * behavior; every story supports it.
153
+ */
154
+ targets: {
155
+ /** What the selected story renders in, among the kit's. */
156
+ supported: PreviewTarget[];
157
+ /** What is turned on among the kit's, whether or not the story supports it. */
158
+ visible: PreviewTarget[];
159
+ /** The panes a shell mounts: the supported ones that are turned on, in order. */
160
+ panes: PreviewTarget[];
161
+ };
162
+ /**
163
+ * The width a shell lays each of the selection's story panes out at, in
164
+ * CSS pixels, so a component that responds to its width shows as it does
165
+ * on a screen that wide: one of `catalog.paneWidths`, or any width a link
166
+ * names. Absent while the panes fit the space the shell gives them. A
167
+ * shell decides how a pane wider than its space shows, such as scrolling
168
+ * across it. It outlasts the story, and a view's pane does not follow it.
169
+ */
170
+ paneWidth?: number;
171
+ /** The readiness of the selection's panes, by target (`html` among
172
+ * them), and of the view pane under `view`. */
173
+ frames: Partial<Record<PreviewFrameTarget, PreviewFrameReadiness>>;
174
+ /** The readiness of the detached story panes `frames.mountStory` mounted,
175
+ * by the key `storyFrameKey(target, story)` gives. */
176
+ storyFrames: Record<string, PreviewFrameReadiness>;
177
+ /**
178
+ * The size of what each of the selection's panes shows, by target, and
179
+ * of the view pane under `view`, as the pane last reported it: its story
180
+ * or view with the space the kit's canvas puts around it, in whole CSS
181
+ * pixels. A shell that sizes a pane to its content sets the iframe's height
182
+ * to `height`. An entry appears once the pane has rendered, keeps its last
183
+ * size while the pane reloads, and goes when the pane is unmounted. The
184
+ * width is the content's at the pane's current width, as block content
185
+ * fills the pane.
186
+ */
187
+ frameSizes: Partial<Record<PreviewFrameTarget, PreviewContentSize>>;
188
+ /** What each of the selection's panes threw as its story rendered, by
189
+ * target: the error's message, shown in the story's place. An entry
190
+ * goes when the pane mounts a story that renders, and when the pane is
191
+ * unmounted. */
192
+ frameErrors: Partial<Record<PreviewFrameTarget, string>>;
193
+ /** The events the selection's panes recorded, oldest first and the last
194
+ * hundred at most: each call a story made of one of its events
195
+ * (`PreviewComponent.events`). Cleared when another story or a view is
196
+ * selected, and by `actions.clearEvents`. */
197
+ events: PreviewEvent[];
198
+ /** The size of what each detached story pane shows, as `frameSizes` holds
199
+ * the selection's, by the key `storyFrameKey(target, story)` gives. */
200
+ storyFrameSizes: Record<string, PreviewContentSize>;
201
+ editor: PreviewEditorState;
202
+ regeneration: PreviewRegenerationStatus;
203
+ /** The code of what the selection's panes show, per target and as
204
+ * html. Absent while a view is selected. */
205
+ code?: PreviewCode;
206
+ }
207
+ /** What `createNode` makes: a text leaf, a plain HTML tag, or a component. */
208
+ export type PreviewNodeRequest = {
209
+ kind: 'text';
210
+ value: string;
211
+ } | {
212
+ kind: 'html';
213
+ tag: string;
214
+ } | {
215
+ kind: 'component';
216
+ /** The component's export name. */
217
+ name: string;
218
+ /** What the component comes in with: nothing (`empty`, the default), its
219
+ * curated defaults and slot content (`default`), or a scenario's props
220
+ * over its defaults. A component with no slot content and no scenarios
221
+ * always comes in with its defaults. */
222
+ importAs?: 'empty' | 'default' | {
223
+ scenario: string;
224
+ };
225
+ };
226
+ /** Where a node is inserted: into `slot` of the node at `parent` (the root's
227
+ * slots when empty), before `index`, or at the end when `index` is omitted. */
228
+ export interface PreviewInsertTarget {
229
+ parent: Step[];
230
+ slot: string;
231
+ index?: number;
232
+ }
233
+ /** What a shell's sortable lists report when a node is dropped. */
234
+ export interface PreviewSortableDrop {
235
+ /** The list the node was dragged from. */
236
+ source: SortableListAddress;
237
+ /** The list it was dropped in. */
238
+ target: SortableListAddress;
239
+ /** Whether the two are the same list. */
240
+ sameList: boolean;
241
+ /** The node's index in the source list. */
242
+ fromIndex: number;
243
+ /** The index it was dropped at in the target list. */
244
+ toIndex: number;
245
+ }
246
+ /** The timers the controller debounces with; the global ones by default. */
247
+ export interface PreviewTimers {
248
+ setTimeout(callback: () => void, milliseconds: number): unknown;
249
+ clearTimeout(handle: unknown): void;
250
+ }
251
+ /** What `createPreviewController` takes. */
252
+ export interface PreviewControllerOptions {
253
+ /** The kit's catalog. */
254
+ catalog: PreviewCatalog;
255
+ /** The kit's preview options. */
256
+ options: PreviewOption[];
257
+ /** The shell's own options, as it declares them; the controller namespaces
258
+ * their ids under `shell.`. */
259
+ shellOptions?: PreviewShellOption[];
260
+ /** Carries the scratch story to whatever writes it. Without one, the
261
+ * preview cannot regenerate and `capabilities.regeneration` is `false`. */
262
+ regeneration?: RegenerationTransport;
263
+ /** Prints the html of any story, as the development server does. Asked
264
+ * once a story's changes pause, and aborted when the story changes again. */
265
+ htmlSource?: HtmlSourceTransport;
266
+ /** Reads the html printed ahead of time for each scenario, as the static
267
+ * build serves it. Used without `htmlSource`; the html of props that differ
268
+ * from a scenario's, or of the editor's tree, is then unavailable. */
269
+ scenarioHtmlSources?: ScenarioHtmlSourceLoader;
270
+ /** The window the iframes post their messages to, and whose location holds
271
+ * the preview's query parameters; the global one by default. */
272
+ window?: Window;
273
+ /** Where the controller remembers what a person chose: the query parameters
274
+ * alone (`'url'`, the default), or also the global option values in local
275
+ * storage, per kit name (`'url-and-local-storage'`). */
276
+ persistence?: PreviewPersistence;
277
+ /** The storage `'url-and-local-storage'` uses; the window's local storage by default. */
278
+ storage?: PreviewStorage;
279
+ /** The timers to debounce with; the global ones by default. */
280
+ timers?: PreviewTimers;
281
+ /** The URL the preview's pages are served under, ending in `/`, such as
282
+ * `https://example.com/kit/`: the iframes load their pages from it. It
283
+ * is fixed when the controller is created, so a shell that changes the
284
+ * host page's path or hash for its own routing does not move the iframes.
285
+ * `/`, the root of the host page's origin, by default. */
286
+ baseUrl?: string;
287
+ }
288
+ /** The preview's behavior, for a shell to render. */
289
+ export interface PreviewController {
290
+ /** The version of this contract. */
291
+ readonly apiVersion: 1;
292
+ /** The kit's catalog, static for the controller's lifetime. */
293
+ readonly catalog: PreviewCatalog;
294
+ /** The options a shell shows controls for: the kit's, then the shell's own. */
295
+ readonly options: PreviewOptionDescriptor[];
296
+ readonly capabilities: {
297
+ /** Whether the scratch story can be regenerated, which the editor and the
298
+ * Empty scenario need. False in a static build. */
299
+ regeneration: boolean;
300
+ };
301
+ /** The current state. */
302
+ getState(): PreviewState;
303
+ /**
304
+ * Call `listener` with each new state.
305
+ *
306
+ * @returns A function that stops the calls.
307
+ */
308
+ subscribe(listener: (state: PreviewState) => void): () => void;
309
+ actions: {
310
+ /**
311
+ * Show a component's story, on its baseline scenario, or with `props`
312
+ * over its defaults when given. The option values the baseline scenario
313
+ * sets are set as `pickScenario` sets them. A component that is not
314
+ * standalone and an unknown id are ignored.
315
+ */
316
+ selectComponent(id: string, props?: Record<string, unknown>): void;
317
+ /** Show a custom view. Unknown ids are ignored. */
318
+ selectView(id: string): void;
319
+ /**
320
+ * Show what `selection` names: a component's story on its baseline
321
+ * scenario, or a custom view. One navigation control can hand over the
322
+ * selection it lists without telling the two apart.
323
+ *
324
+ * @example
325
+ * ```ts
326
+ * controller.actions.select({ kind: 'view', id: 'swatches' });
327
+ * ```
328
+ */
329
+ select(selection: PreviewSelection): void;
330
+ /**
331
+ * Pick a scenario of the selected story; `''` is the anonymous default.
332
+ * The option values the scenario sets (`PreviewScenario.options`) are set
333
+ * as `setOption` sets them, so the panes, the controls and the address
334
+ * follow; the values it does not set stay as they are, and picking
335
+ * another scenario keeps them, apart from those the next one sets. The
336
+ * Empty scenario is ignored where the preview cannot regenerate.
337
+ */
338
+ pickScenario(id: string): void;
339
+ /** Set an option's value. A story option's value lasts until another story is selected. */
340
+ setOption(id: string, value: OptionValue): void;
341
+ /**
342
+ * Replace the selected story's root props with `props`, which are not
343
+ * merged into the current ones. They reach the panes live, with no
344
+ * regeneration, whether or not the editor is open; the editor's root
345
+ * takes them too. While the editor holds a tree, `children` is the
346
+ * root's text, as `state.props` shows it: a new string replaces the
347
+ * content of the root's default slot with that one text, and leaving
348
+ * `children` out removes a lone text, each an edit of the tree's content
349
+ * that regenerates the story; content other than a lone text stays while
350
+ * `children` is left out. A story with default-slot content of its own
351
+ * takes no `children` then. Props that are `undefined` are dropped. Ignored
352
+ * while a view is selected; picking a scenario or a story seeds them
353
+ * afresh.
354
+ *
355
+ * @example
356
+ * ```ts
357
+ * const { props } = controller.getState();
358
+ * controller.actions.setProps({ ...props, variant: 'ghost' });
359
+ * ```
360
+ */
361
+ setProps(props: Record<string, unknown>): void;
362
+ /** Turn a scripted target's pane, or the html pane, on or off. The choice
363
+ * outlasts the story. */
364
+ setTargetVisible(target: PreviewTarget, visible: boolean): void;
365
+ /**
366
+ * Lay the story panes out at `width` CSS pixels, or, with `undefined`,
367
+ * fit them to the shell's space again (`state.paneWidth`). A width that
368
+ * is not a whole number from 1 to `MAXIMUM_PANE_WIDTH` (7680) is
369
+ * ignored. The choice outlasts the story.
370
+ *
371
+ * @example
372
+ * ```ts
373
+ * const medium = controller.catalog.paneWidths.find((paneWidth) => paneWidth.label === 'medium');
374
+ * controller.actions.setPaneWidth(medium?.width);
375
+ * ```
376
+ */
377
+ setPaneWidth(width: number | undefined): void;
378
+ /** Empty the log of recorded events. */
379
+ clearEvents(): void;
380
+ };
381
+ editor: {
382
+ /** Open the editor on the selected story, seeding its tree from the story's content. */
383
+ open(): void;
384
+ /** Close the editor. Its tree stays as it is until another story or scenario is selected. */
385
+ close(): void;
386
+ /**
387
+ * Make a node to insert, by the catalog's component data.
388
+ *
389
+ * @param request - What to make: a text leaf, an HTML tag, or a
390
+ * component by its export name.
391
+ * @returns The tree's node: `{ kind: 'text', value }`,
392
+ * `{ kind: 'html', tag, props, slots }`, or, for a component,
393
+ * `{ kind: 'element', component, props, slots }`.
394
+ */
395
+ createNode(request: PreviewNodeRequest): EditorNode;
396
+ insert(target: PreviewInsertTarget, node: EditorNode): void;
397
+ /** Move the node at `from` to `to`, whose index is counted before the node
398
+ * is taken out, as a drop reports it; a move into the node's own subtree
399
+ * is ignored. */
400
+ move(from: Step[], to: DropTarget): void;
401
+ /**
402
+ * Move the node at `path` within its slot by `offset` places: `-1` one
403
+ * up, `1` one down. The move stops at either end of the slot, and a node
404
+ * already there stays put.
405
+ *
406
+ * @example
407
+ * ```ts
408
+ * controller.editor.moveBy(path, -1); // one place up
409
+ * ```
410
+ */
411
+ moveBy(path: Step[], offset: number): void;
412
+ /** Put `node` in place of the node at `path`. */
413
+ replace(path: Step[], node: EditorNode): void;
414
+ remove(path: Step[]): void;
415
+ /** Replace the props of the node at `path` with `props`, which are not
416
+ * merged into the node's current ones. The empty path is the root: it
417
+ * does what `actions.setProps(props)` does, live, without a regeneration,
418
+ * except that the root's content, and so its `children`, stays as it
419
+ * is, as the tree's root props never hold `children`. */
420
+ setNodeProps(path: Step[], props: Record<string, unknown>): void;
421
+ /** Set the value of the text node at `path`. */
422
+ setText(path: Step[], text: string): void;
423
+ /** The move a sortable drop amounts to. */
424
+ resolveDrop(drop: PreviewSortableDrop): {
425
+ from: Step[];
426
+ to: DropTarget;
427
+ };
428
+ };
429
+ frames: {
430
+ /**
431
+ * Mount a scripted target's pane, or the html pane, inside `element`: an
432
+ * iframe with no size of its own, which the shell sizes. The controller
433
+ * owns the iframe: it loads it, reloads a scripted target's after each
434
+ * regeneration and answers it. The html pane shows the markup of
435
+ * `code.html` as it changes, keeping what it shows while the next is
436
+ * printed and saying why when there is none; it runs none of the story's
437
+ * behavior. The pane's readiness reaches subscribers after this call
438
+ * returns, never during it, and the size of what it shows reaches
439
+ * `frameSizes` once it renders.
440
+ *
441
+ * @returns A function that unmounts the pane.
442
+ */
443
+ mount(element: HTMLElement, target: PreviewTarget): () => void;
444
+ /**
445
+ * Mount a custom view's pane inside `element`, as `mount` mounts a
446
+ * target's: a bare iframe the shell sizes, its readiness reported after
447
+ * this call returns.
448
+ *
449
+ * @returns A function that unmounts the pane.
450
+ */
451
+ mountView(element: HTMLElement, viewId: string): () => void;
452
+ /**
453
+ * Mount a read-only pane of any story inside `element`, apart from the
454
+ * selection: a bare iframe the shell sizes, as `mount` makes. Its props
455
+ * are the scenario's over the component's defaults, then `story.props`
456
+ * over those. `scenario` omitted is the story's starting scenario, as
457
+ * selecting the story picks it, and `''` the anonymous default. The pane
458
+ * follows the global options; its story options are the component's own,
459
+ * as selecting it would seed them, and the option values its scenario
460
+ * sets stay over both. It never shows the editor's content and is not
461
+ * reloaded by a regeneration. Its readiness is reported in
462
+ * `storyFrames` under `storyFrameKey(target, story)`, after this call
463
+ * returns, and the size of what it shows in `storyFrameSizes` under the
464
+ * same key.
465
+ *
466
+ * @param element - The element to append the iframe to.
467
+ * @param target - The target to render the story in.
468
+ * @param story - The story: a browseable component's id, a scenario and props.
469
+ * @returns A function that unmounts the pane.
470
+ * @throws When the component is unknown or not standalone, the target is
471
+ * not among its targets, or the scenario is unknown or the Empty one,
472
+ * which renders through the selection's regenerated story.
473
+ * @example
474
+ * ```ts
475
+ * for (const scenario of component.scenarios.filter((scenario) => !scenario.empty)) {
476
+ * const cell = grid.appendChild(document.createElement('div'));
477
+ * controller.frames.mountStory(cell, 'react', { component: component.id, scenario: scenario.id });
478
+ * }
479
+ * ```
480
+ */
481
+ mountStory(element: HTMLElement, target: PreviewScriptedTarget, story: PreviewStoryReference): () => void;
482
+ /**
483
+ * Mount the kit's code block inside `element`, showing `target`'s source
484
+ * of the selection: an iframe the shell sizes, which the block fills and
485
+ * scrolls as it likes. It follows the source as the story, its props and
486
+ * its content change, and the global option values: a story option sets
487
+ * nothing in a code block. For a kit that names a code block
488
+ * (`catalog.codeBlock`); its readiness and size are the block's own and
489
+ * reach no state.
490
+ *
491
+ * @returns A function that unmounts the block.
492
+ */
493
+ mountCode(element: HTMLElement, target: PreviewTarget): () => void;
494
+ /**
495
+ * Tell the kit's code blocks whether the shell wraps its code panes'
496
+ * long lines, as `wrap` in their content; false until a shell says. A
497
+ * shell with a wrap choice calls it as the choice changes.
498
+ */
499
+ wrapCode(wrap: boolean): void;
500
+ /**
501
+ * Load the selection's pane for `target` again: its readiness goes back
502
+ * to loading until it answers, and it shows the selection as it is now.
503
+ */
504
+ reload(target: PreviewFrameTarget): void;
505
+ /**
506
+ * The address of the selection's pane for a target opened on its own,
507
+ * outside the preview: the story it shows now - the scratch story while
508
+ * the editor's content renders - with its props and the option values.
509
+ * It follows nothing after it opens.
510
+ */
511
+ standaloneUrl(target: PreviewScriptedTarget): string;
512
+ };
513
+ /** Unmount every pane, drop a pending regeneration and stop listening. */
514
+ dispose(): void;
515
+ }
516
+ /**
517
+ * Create a preview controller.
518
+ *
519
+ * @param controllerOptions - The catalog, the options and the environment.
520
+ * @returns The controller.
521
+ * @example
522
+ * ```ts
523
+ * const controller = createPreviewController({
524
+ * catalog: catalogFromManifest(manifest, views),
525
+ * options: previewOptions,
526
+ * regeneration: createFetchRegenerationTransport(),
527
+ * });
528
+ * const stop = controller.subscribe((state) => render(state));
529
+ * controller.actions.selectComponent('components-button');
530
+ * ```
531
+ */
532
+ export declare function createPreviewController(controllerOptions: PreviewControllerOptions): PreviewController;