@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,25 @@
1
+ // The charcell shell's root. The terminal look is charcell (the standalone kit
2
+ // the look was extracted into); the shell's own surfaces (the editor panel,
3
+ // controls, layout) are styled on charcell's tokens. The behavior is the
4
+ // controller's: this component provides it and the shell's configuration to
5
+ // the tree, and the interface inside lays out the prompt bar, navigation, stage
6
+ // and status bar (Application). The stylesheets come in charcell's order:
7
+ // charcell's own, then the shell's layers and page (shell.css), then each
8
+ // component's, which it imports itself.
9
+ import 'charcell/css/full';
10
+ import './shell.css';
11
+ import type { PreviewController } from '../../../src/shell';
12
+ import { Application } from './components/Application';
13
+ import type { CharcellShellConfiguration } from './configuration';
14
+ import { PreviewControllerContext, ShellConfigurationContext } from './controller-context';
15
+
16
+ /** The shell as one React element: the controller and the configuration provided, the interface inside. */
17
+ export function CharcellApplication(props: { controller: PreviewController; configuration: CharcellShellConfiguration }) {
18
+ return (
19
+ <PreviewControllerContext.Provider value={props.controller}>
20
+ <ShellConfigurationContext.Provider value={props.configuration}>
21
+ <Application />
22
+ </ShellConfigurationContext.Provider>
23
+ </PreviewControllerContext.Provider>
24
+ );
25
+ }
@@ -0,0 +1,47 @@
1
+ // The reset gesture on the stage grid's handles (PreviewGrid): a double-click
2
+ // on a handle, or Enter while it holds the focus, puts the split it moves
3
+ // back at its even distribution. The handle's own handlers, charcell's
4
+ // dragging and stepping, run first and keep working as they do.
5
+
6
+ /** The key that resets a focused handle. */
7
+ export const RESET_KEY = 'Enter';
8
+
9
+ /** A handle's props, as the grid hands them, with their event handlers. */
10
+ type HandleProps = Record<string, unknown>;
11
+
12
+ /** The handlers the reset gesture composes with a handle's own. */
13
+ export interface ResetHandlers {
14
+ onDoubleClick: (event: { button?: number }) => void;
15
+ onKeyDown: (event: { key: string; ctrlKey?: boolean; altKey?: boolean; metaKey?: boolean; shiftKey?: boolean }) => void;
16
+ }
17
+
18
+ /** Calls the handler `props` holds under `name`, if it holds one. */
19
+ function callOwn(props: HandleProps, name: string, event: unknown): void {
20
+ const own = props[name];
21
+ if (typeof own === 'function') own(event);
22
+ }
23
+
24
+ /**
25
+ * A handle's props with the reset gesture added: `reset` runs on a
26
+ * double-click on the handle, and on Enter while it holds the focus, after
27
+ * the handle's own `onDoubleClick` and `onKeyDown`.
28
+ *
29
+ * @param props - The handle's props, as the grid hands them.
30
+ * @param reset - Puts the handle's split back at its even distribution.
31
+ * @returns The props, their double-click and key handlers composed with the reset.
32
+ * @example
33
+ * <SplitGridHandle {...withResetGesture(grid.columnHandleProps(0), () => grid.columnsApi.resetSizes())} />
34
+ */
35
+ export function withResetGesture<Props extends HandleProps>(props: Props, reset: () => void): Props & ResetHandlers {
36
+ return {
37
+ ...props,
38
+ onDoubleClick: (event) => {
39
+ callOwn(props, 'onDoubleClick', event);
40
+ if ((event.button ?? 0) === 0) reset();
41
+ },
42
+ onKeyDown: (event) => {
43
+ callOwn(props, 'onKeyDown', event);
44
+ if (event.key === RESET_KEY && !event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey) reset();
45
+ },
46
+ };
47
+ }
@@ -0,0 +1,117 @@
1
+ // The cells the stacked output rows start at (PreviewGrid): while the story
2
+ // panes are laid out at a width wider than a column, the grid stacks a row
3
+ // per target over the code row. Every row starts at its story's height when
4
+ // the stories fit; when they don't, the rows share the space equally, a
5
+ // shorter story keeping its own height. Each row has a least: a readable
6
+ // height, or its story's when that is shorter. The grid is made tall enough
7
+ // for every row's least and the code row's, and the stage scrolls past it
8
+ // only when those don't fit.
9
+
10
+ /** The code row under the stacked rows: the least it keeps and its share. */
11
+ export interface StackedCodeRow {
12
+ /** The fewest cells the code row keeps. */
13
+ least: number;
14
+ /** The share of the rows' space it starts at, in percent, as far as the
15
+ * output rows keep their least. */
16
+ share: number;
17
+ }
18
+
19
+ /**
20
+ * Each stacked output row's least, in cells: `least`, or the cells its
21
+ * story and the pane around it take when that is fewer. A story that has
22
+ * not reported its height (`undefined`) counts as `least`.
23
+ *
24
+ * @param wanted - The cells each output row's content takes.
25
+ * @param least - The readable least of an output row.
26
+ * @returns The least per row.
27
+ * @example
28
+ * stackedRowMinimums([4.2, undefined, 30], 10); // [5, 10, 10]
29
+ */
30
+ export function stackedRowMinimums(wanted: readonly (number | undefined)[], least: number): number[] {
31
+ return wanted.map((cells) => (cells === undefined ? least : Math.max(1, Math.min(least, Math.ceil(cells)))));
32
+ }
33
+
34
+ /**
35
+ * The cells each stacked output row starts at, then the code row's when
36
+ * there is one. A row's `wanted` is the cells its story and the pane around
37
+ * it take (undefined while the story has not reported its height, which asks
38
+ * for as much as it can get); `total` is the cells the rows share. Rows that
39
+ * fit start at what they want, the space left over going to the code row, or
40
+ * to the last row without one, so no row above the last is taller than its
41
+ * story. Rows that don't fit share the space equally, a row that wants less
42
+ * than its share keeping what it wants. The code row starts at its share as
43
+ * far as the output rows keep their least (`stackedRowMinimums`). The rows
44
+ * share at least their leasts and the code row's, even when that is more
45
+ * than `total` holds.
46
+ *
47
+ * @param options.wanted - The cells each output row's content takes.
48
+ * @param options.total - The whole cells the rows share.
49
+ * @param options.least - The readable least of an output row.
50
+ * @param options.code - The code row under the output rows, if it shows.
51
+ * @returns The cells per row, the output rows first and then the code row.
52
+ * @example
53
+ * stackedRowCells({ wanted: [5, 40, 40], total: 60, least: 4 }); // [5, 27, 28]
54
+ */
55
+ export function stackedRowCells({
56
+ wanted,
57
+ total,
58
+ least,
59
+ code,
60
+ }: {
61
+ wanted: (number | undefined)[];
62
+ total: number;
63
+ least: number;
64
+ code?: StackedCodeRow;
65
+ }): number[] {
66
+ const count = wanted.length;
67
+ const outputLeast = stackedRowMinimums(wanted, least).reduce((all, cells) => all + cells, 0);
68
+ const space = Math.max(Math.floor(total), outputLeast + (code ? code.least : 0));
69
+ const codeCells = code
70
+ ? Math.max(code.least, Math.min(Math.round((code.share / 100) * space), space - outputLeast))
71
+ : 0;
72
+ const output = space - codeCells;
73
+ const wants = wanted.map((cells) => Math.max(1, Math.ceil(cells ?? Number.POSITIVE_INFINITY)));
74
+ const sum = wants.reduce((all, cells) => all + cells, 0);
75
+ let cells: number[];
76
+ if (sum <= output) {
77
+ cells = [...wants];
78
+ // What is left over goes under the last story: to the code row, or the
79
+ // last output row.
80
+ if (code) return [...cells, codeCells + output - sum];
81
+ cells[count - 1] += output - sum;
82
+ return cells;
83
+ }
84
+ // The rows that want least first, each taking its want or an equal share
85
+ // of what is left, whichever is less; the one that wants most, the rest.
86
+ // Since the space holds every row's least, a row wanting more than
87
+ // `least` is left at least `least` this way.
88
+ cells = new Array<number>(count).fill(0);
89
+ const order = wants.map((_, index) => index).sort((first, second) => wants[first] - wants[second]);
90
+ let left = output;
91
+ order.forEach((index, position) => {
92
+ const share = position === count - 1 ? left : Math.min(wants[index], Math.floor(left / (count - position)));
93
+ cells[index] = share;
94
+ left -= share;
95
+ });
96
+ return code ? [...cells, codeCells] : cells;
97
+ }
98
+
99
+ /**
100
+ * The cells a stacked grid needs at least: each output row's least
101
+ * (`stackedRowMinimums`), the code row's, and a cell for each handle
102
+ * between two rows.
103
+ *
104
+ * @param wanted - The cells each output row's content takes.
105
+ * @param least - The readable least of an output row.
106
+ * @param code - The code row under the output rows, if it shows.
107
+ * @returns The grid's least height, in cells.
108
+ */
109
+ export function stackedLeastCells(
110
+ wanted: readonly (number | undefined)[],
111
+ least: number,
112
+ code?: StackedCodeRow,
113
+ ): number {
114
+ const rows = wanted.length + (code ? 1 : 0);
115
+ const output = stackedRowMinimums(wanted, least).reduce((all, cells) => all + cells, 0);
116
+ return output + (code ? code.least : 0) + (rows - 1);
117
+ }
@@ -0,0 +1,93 @@
1
+ // Showing and hiding the stage's views and targets, from the top bar's
2
+ // toggles and the shell's keys alike. In a narrow window the stage shows one
3
+ // view and one target at a time: the first of each the state turns on, and
4
+ // turning one on turns the others off, the one showing staying on. The
5
+ // narrow layout starts below a width of the window's (NARROW_WIDTH). It
6
+ // narrows what the stage shows, not the state: a window that loads or
7
+ // becomes narrow changes no option and leaves the address as it is, and
8
+ // widening it shows every view and target the state turns on again. Only a
9
+ // toggle a person turns writes the state.
10
+ import { useEffect, useMemo, useState } from 'react';
11
+ import type { OptionValue, PreviewController, PreviewTarget } from '../../../src/shell';
12
+ import { usePreviewState } from './controller-context';
13
+ import { CODE_VIEW_OPTION, EVENTS_VIEW_OPTION, OUTPUT_VIEW_OPTION, SCENARIO_VIEW_OPTION } from './shell-options';
14
+
15
+ /** The window width, in CSS pixels, below which the stage is narrow. */
16
+ export const NARROW_WIDTH = 900;
17
+
18
+ /** The views' options, top to bottom. */
19
+ export const VIEW_OPTIONS = [SCENARIO_VIEW_OPTION, OUTPUT_VIEW_OPTION, CODE_VIEW_OPTION, EVENTS_VIEW_OPTION] as const;
20
+
21
+ /** Whether a view's option turns it on, by its value: output unless turned
22
+ * off, the others once turned on. */
23
+ export function viewShown(option: string, value: unknown): boolean {
24
+ return option === OUTPUT_VIEW_OPTION ? value !== false : value === true;
25
+ }
26
+
27
+ /** The views the stage shows, top to bottom: those the options turn on, or,
28
+ * narrow, the first of them. */
29
+ export function stageViews(options: Record<string, OptionValue | undefined>, narrow: boolean): string[] {
30
+ const views = VIEW_OPTIONS.filter((option) => viewShown(option, options[option]));
31
+ return narrow ? views.slice(0, 1) : views;
32
+ }
33
+
34
+ /** The panes the stage shows: the state's, or, narrow, the first of them. */
35
+ export function stagePanes(panes: PreviewTarget[], narrow: boolean): PreviewTarget[] {
36
+ return narrow ? panes.slice(0, 1) : panes;
37
+ }
38
+
39
+ /** Whether the window is narrow, following it as it resizes. */
40
+ export function useNarrow(): boolean {
41
+ const query = `(max-width: ${NARROW_WIDTH - 1}px)`;
42
+ const [narrow, setNarrow] = useState(() => typeof matchMedia === 'function' && matchMedia(query).matches);
43
+ useEffect(() => {
44
+ if (typeof matchMedia !== 'function') return;
45
+ const list = matchMedia(query);
46
+ const follow = () => setNarrow(list.matches);
47
+ follow();
48
+ list.addEventListener('change', follow);
49
+ return () => list.removeEventListener('change', follow);
50
+ }, [query]);
51
+ return narrow;
52
+ }
53
+
54
+ /** What the stage shows now: whether it is narrow, which views show, and the
55
+ * panes, following the state and the window. */
56
+ export function useStage(): { narrow: boolean; views: ReadonlySet<string>; panes: PreviewTarget[] } {
57
+ const narrow = useNarrow();
58
+ const options = usePreviewState((state) => state.options);
59
+ const panes = usePreviewState((state) => state.targets.panes);
60
+ return useMemo(
61
+ () => ({ narrow, views: new Set(stageViews(options, narrow)), panes: stagePanes(panes, narrow) }),
62
+ [narrow, options, panes],
63
+ );
64
+ }
65
+
66
+ /** Show or hide a view; narrow, showing one hides the others, and the one
67
+ * showing stays. */
68
+ export function toggleView(controller: PreviewController, option: string, narrow: boolean): void {
69
+ const { options } = controller.getState();
70
+ if (!narrow) {
71
+ controller.actions.setOption(option, !viewShown(option, options[option]));
72
+ return;
73
+ }
74
+ if (stageViews(options, true)[0] === option) return;
75
+ controller.actions.setOption(option, true);
76
+ for (const other of VIEW_OPTIONS) {
77
+ if (other !== option && viewShown(other, options[other])) controller.actions.setOption(other, false);
78
+ }
79
+ }
80
+
81
+ /** Show or hide a target; narrow, showing one hides the others, and the one
82
+ * showing stays. */
83
+ export function toggleTarget(controller: PreviewController, target: PreviewTarget, narrow: boolean): void {
84
+ const { visible, supported, panes } = controller.getState().targets;
85
+ if (!supported.includes(target)) return;
86
+ if (!narrow) {
87
+ controller.actions.setTargetVisible(target, !visible.includes(target));
88
+ return;
89
+ }
90
+ if (stagePanes(panes, true)[0] === target) return;
91
+ controller.actions.setTargetVisible(target, true);
92
+ for (const other of visible) if (other !== target) controller.actions.setTargetVisible(other, false);
93
+ }
@@ -0,0 +1,6 @@
1
+ // The generated manifest (`@preview-generated/manifest.json`), typed as the
2
+ // generator emits it.
3
+ import type { Manifest } from '../../src/emit/manifest';
4
+
5
+ declare const manifest: Manifest;
6
+ export default manifest;
@@ -0,0 +1,10 @@
1
+ // The data of the kit's preview block as the app type-checks against it:
2
+ // exactly what the `@preview-configuration` module the preview serves
3
+ // exports, one constant per key the pages read.
4
+ import type { PreviewBrowserConfiguration } from '../../src/lib/types';
5
+
6
+ export declare const options: PreviewBrowserConfiguration['options'];
7
+ export declare const canvas: PreviewBrowserConfiguration['canvas'];
8
+ export declare const themes: PreviewBrowserConfiguration['themes'];
9
+ export declare const mount: PreviewBrowserConfiguration['mount'];
10
+ export declare const viewCanvas: PreviewBrowserConfiguration['viewCanvas'];
@@ -0,0 +1,7 @@
1
+ // The shell module as the app type-checks against it: `@preview-shell` is
2
+ // aliased at build time to the module `preview.shell` names, whose
3
+ // default export is a shell.
4
+ import type { PreviewShell } from '../../src/shell';
5
+
6
+ declare const shell: PreviewShell;
7
+ export default shell;
@@ -0,0 +1,15 @@
1
+ // A generated React render-registry (`@preview-generated/react/registry`,
2
+ // `@preview-generated/scratch/react`): component id to a render function,
3
+ // and what the React pane spells a story's props with. The scratch module is
4
+ // a placeholder holding an empty `registry` alone until the editor's first
5
+ // edit, so its other exports may be absent.
6
+ import type { ReactNode } from 'react';
7
+
8
+ export declare const registry: Record<
9
+ string,
10
+ (props: Record<string, unknown>) => ReactNode
11
+ >;
12
+ /** How React spells the HTML attributes it renames, by their HTML names. */
13
+ export declare const reactAttributeNames: Record<string, string> | undefined;
14
+ /** The names each story's root declares that React would otherwise respell. */
15
+ export declare const declaredAttributes: Record<string, string[]> | undefined;
@@ -0,0 +1,6 @@
1
+ // A generated Vue render-registry (`@preview-generated/vue/registry`,
2
+ // `@preview-generated/scratch/vue`): component id to the components a string
3
+ // template mounts.
4
+ import type { Component } from 'vue';
5
+
6
+ export declare const registry: Record<string, { components: Record<string, Component>; template: string }>;
@@ -0,0 +1,24 @@
1
+ import type { ConfigurationLookupOptions } from 'scaffold-ui-kit';
2
+ import type { InlineConfig } from 'vite';
3
+ /** What a static build did. */
4
+ export interface PreviewBuildResult {
5
+ /** Whether the preview was built: false when the check found errors. */
6
+ built: boolean;
7
+ /** The check's errors, each a line naming its component. */
8
+ errors: string[];
9
+ /** The check's warnings, which do not stop the build. */
10
+ warnings: string[];
11
+ }
12
+ /**
13
+ * Builds a kit's static preview: removes the previous build, checks the
14
+ * kit's story files and manual specs, and, when the check finds no errors,
15
+ * generates the preview with every story's html and builds it with Vite.
16
+ *
17
+ * @param kitRoot - The kit root (where its package.json lives).
18
+ * @param build - The Vite build to run; Vite's own by default.
19
+ * @param options - The kit configuration file, when it is not the one the
20
+ * kit root gives.
21
+ * @returns Whether it built, the check's errors that stopped it, and its
22
+ * warnings.
23
+ */
24
+ export declare function buildPreview(kitRoot: string, build?: (configuration: InlineConfig) => Promise<unknown>, options?: ConfigurationLookupOptions): Promise<PreviewBuildResult>;
package/dist/build.js ADDED
@@ -0,0 +1,34 @@
1
+ // The static build, as `scaffold-ui-kit-preview build` runs it: check the
2
+ // story files and manual specs first, then generate and build the preview into
3
+ // the kit's static root. A check error stops the build, as it would leave a
4
+ // story the preview shows wrong or not at all.
5
+ import { rmSync } from 'node:fs';
6
+ import { checkPreview } from './check.js';
7
+ import { loadPreviewContext } from './context.js';
8
+ import { generatePreview } from './generate.js';
9
+ import { buildViteConfiguration } from './vite-configuration.js';
10
+ /**
11
+ * Builds a kit's static preview: removes the previous build, checks the
12
+ * kit's story files and manual specs, and, when the check finds no errors,
13
+ * generates the preview with every story's html and builds it with Vite.
14
+ *
15
+ * @param kitRoot - The kit root (where its package.json lives).
16
+ * @param build - The Vite build to run; Vite's own by default.
17
+ * @param options - The kit configuration file, when it is not the one the
18
+ * kit root gives.
19
+ * @returns Whether it built, the check's errors that stopped it, and its
20
+ * warnings.
21
+ */
22
+ export async function buildPreview(kitRoot, build, options = {}) {
23
+ const context = loadPreviewContext(kitRoot, options);
24
+ // The previous build goes first, so a build that fails leaves no output
25
+ // behind that looks current.
26
+ rmSync(context.staticRoot, { recursive: true, force: true });
27
+ const { errors, warnings } = await checkPreview(kitRoot, options);
28
+ if (errors.length > 0)
29
+ return { built: false, errors, warnings };
30
+ await generatePreview(context, { htmlSources: true });
31
+ const runBuild = build ?? (await import('vite')).build;
32
+ await runBuild(buildViteConfiguration(context));
33
+ return { built: true, errors, warnings };
34
+ }
@@ -0,0 +1,48 @@
1
+ import type { ConfigurationLookupOptions } from 'scaffold-ui-kit';
2
+ export interface PreviewCheckOptions extends ConfigurationLookupOptions {
3
+ /** Report missing scenario coverage as errors, not warnings. */
4
+ strict?: boolean;
5
+ }
6
+ /** The check's findings, each a line naming its component. */
7
+ export interface PreviewCheckReport {
8
+ /** Story file or manual-spec mistakes, and what fails `scaffold-ui-kit
9
+ * build` for a template in the kit's `src/components/` (a line naming the
10
+ * template's path, as the build prints it); under `strict`, coverage
11
+ * gaps too. */
12
+ errors: string[];
13
+ /** What reading the kit configuration warns of, such as its old file
14
+ * name, which stays a warning under `strict`; an enum value or boolean
15
+ * no scenario sets, among the props generation
16
+ * covers: a curated scenario that takes a generated id replaces that
17
+ * scenario, and is named when it does not set the value (an error under
18
+ * `strict`); a scenario prop set to `undefined` that the story's starting
19
+ * value covers, which `null` would unset (an error under `strict`); and
20
+ * what `scaffold-ui-kit build` warns of for a template in
21
+ * `src/components/`, named by its path, which stays a warning under
22
+ * `strict`. The build's lines cover validating and
23
+ * rendering each template, by the kit's own installed scaffolder; a
24
+ * driver colliding with a generated file and the stylesheets compiled
25
+ * under `stylesheetLink: 'both'` are reported by the build alone. */
26
+ warnings: string[];
27
+ /** Props hidden from the controls because their type is not a control. */
28
+ hidden: string[];
29
+ /** Select and boolean props the story file's `generate` leaves out of scenario
30
+ * generation and coverage: still controls, but no scenario is expected. */
31
+ ungenerated: string[];
32
+ }
33
+ /**
34
+ * Checks a kit's preview story files and manual specs against its components.
35
+ *
36
+ * @param kitRoot - The kit root (where its package.json lives)
37
+ * @param options - `strict` turns coverage warnings into errors; `configuration`
38
+ * names the kit configuration file, as `--configuration` does
39
+ * @returns The errors, warnings and hidden props, each a line naming its component
40
+ * @example
41
+ * ```ts
42
+ * it('keeps the preview in step with the components', async () => {
43
+ * const report = await checkPreview(process.cwd());
44
+ * expect(report.errors).toEqual([]);
45
+ * });
46
+ * ```
47
+ */
48
+ export declare function checkPreview(kitRoot: string, options?: PreviewCheckOptions): Promise<PreviewCheckReport>;