@aussieljk/forkbook 0.0.0-stage → 0.0.1-2

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 (598) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +77 -2
  3. package/assets/addon-vitest/templates/vitest.config.4.template.ts +36 -0
  4. package/assets/browser/favicon-wrapper.svg +46 -0
  5. package/assets/browser/favicon.svg +1 -0
  6. package/assets/browser/nunito-sans-bold-italic.woff2 +0 -0
  7. package/assets/browser/nunito-sans-bold.woff2 +0 -0
  8. package/assets/browser/nunito-sans-italic.woff2 +0 -0
  9. package/assets/browser/nunito-sans-regular.woff2 +0 -0
  10. package/assets/builder-vite/iframe.html +99 -0
  11. package/assets/create/rendererAssets/.eslintrc.json +16 -0
  12. package/assets/create/rendererAssets/common/Configure.mdx +388 -0
  13. package/assets/create/rendererAssets/common/assets/accessibility.png +0 -0
  14. package/assets/create/rendererAssets/common/assets/accessibility.svg +1 -0
  15. package/assets/create/rendererAssets/common/assets/addon-library.png +0 -0
  16. package/assets/create/rendererAssets/common/assets/assets.png +0 -0
  17. package/assets/create/rendererAssets/common/assets/avif-test-image.avif +0 -0
  18. package/assets/create/rendererAssets/common/assets/context.png +0 -0
  19. package/assets/create/rendererAssets/common/assets/discord.svg +1 -0
  20. package/assets/create/rendererAssets/common/assets/docs.png +0 -0
  21. package/assets/create/rendererAssets/common/assets/figma-plugin.png +0 -0
  22. package/assets/create/rendererAssets/common/assets/github.svg +1 -0
  23. package/assets/create/rendererAssets/common/assets/share.png +0 -0
  24. package/assets/create/rendererAssets/common/assets/styling.png +0 -0
  25. package/assets/create/rendererAssets/common/assets/testing.png +0 -0
  26. package/assets/create/rendererAssets/common/assets/theming.png +0 -0
  27. package/assets/create/rendererAssets/common/assets/tutorials.svg +1 -0
  28. package/assets/create/rendererAssets/common/assets/youtube.svg +1 -0
  29. package/assets/create/rendererAssets/common/button.css +30 -0
  30. package/assets/create/rendererAssets/common/header.css +32 -0
  31. package/assets/create/rendererAssets/common/page.css +68 -0
  32. package/assets/create/templates/react-native/index.expo.js +20 -0
  33. package/assets/create/templates/react-native/index.js +25 -0
  34. package/assets/docs/addon-backgrounds.gif +0 -0
  35. package/assets/docs/addon-controls-args-annotated.png +0 -0
  36. package/assets/docs/addon-controls-args-background-color.png +0 -0
  37. package/assets/docs/addon-controls-args-background-string.png +0 -0
  38. package/assets/docs/addon-controls-args-docs.png +0 -0
  39. package/assets/docs/addon-controls-args-logging.png +0 -0
  40. package/assets/docs/addon-controls-args-no-annotation.png +0 -0
  41. package/assets/docs/addon-controls-args-reflow-slider.png +0 -0
  42. package/assets/docs/addon-controls-args-reflow.png +0 -0
  43. package/assets/docs/addon-controls-args-template.png +0 -0
  44. package/assets/docs/addon-controls-expanded.png +0 -0
  45. package/assets/docs/addon-controls-hero.gif +0 -0
  46. package/assets/docs/addon-controls-install.png +0 -0
  47. package/assets/docs/hero.gif +0 -0
  48. package/assets/docs/highlight.png +0 -0
  49. package/assets/docs/message-reference.png +0 -0
  50. package/assets/docs/viewport.png +0 -0
  51. package/assets/react-native/metro-env.d.ts +69 -0
  52. package/assets/server/addon.tsconfig.json +6 -0
  53. package/assets/server/base-preview-body.html +116 -0
  54. package/assets/server/base-preview-head.html +494 -0
  55. package/assets/server/openBrowser.applescript +94 -0
  56. package/assets/server/template.ejs +87 -0
  57. package/dist/.build-stamp +0 -0
  58. package/dist/_browser-chunks/Color-PCLE2J36.js +1025 -0
  59. package/dist/_browser-chunks/DocsRenderer-JXND3PVQ.js +10 -0
  60. package/dist/_browser-chunks/WithTooltip-XSQFTBMB.js +1619 -0
  61. package/dist/_browser-chunks/chunk-2JDQ35OA.js +247 -0
  62. package/dist/_browser-chunks/chunk-2JT76G3E.js +104 -0
  63. package/dist/_browser-chunks/chunk-2MEPHP35.js +17 -0
  64. package/dist/_browser-chunks/chunk-2SCZVUKW.js +24 -0
  65. package/dist/_browser-chunks/chunk-46Z7NGAS.js +41 -0
  66. package/dist/_browser-chunks/chunk-4ATQOMJB.js +30 -0
  67. package/dist/_browser-chunks/chunk-52CW7FF7.js +49 -0
  68. package/dist/_browser-chunks/chunk-5I7E4GMO.js +62 -0
  69. package/dist/_browser-chunks/chunk-5P4QA6MY.js +20 -0
  70. package/dist/_browser-chunks/chunk-5WMXI5GW.js +816 -0
  71. package/dist/_browser-chunks/chunk-66OCZ54D.js +2604 -0
  72. package/dist/_browser-chunks/chunk-6SXYJQST.js +253 -0
  73. package/dist/_browser-chunks/chunk-AYRF6EJB.js +36 -0
  74. package/dist/_browser-chunks/chunk-B4AUNNU4.js +156 -0
  75. package/dist/_browser-chunks/chunk-BCP2FFXF.js +369 -0
  76. package/dist/_browser-chunks/chunk-C3D4HEFY.js +3396 -0
  77. package/dist/_browser-chunks/chunk-CFAOWGL7.js +43 -0
  78. package/dist/_browser-chunks/chunk-CFWWCCZV.js +223 -0
  79. package/dist/_browser-chunks/chunk-CNED6RYH.js +18 -0
  80. package/dist/_browser-chunks/chunk-DRQKCCAG.js +136 -0
  81. package/dist/_browser-chunks/chunk-ECQ75MKQ.js +0 -0
  82. package/dist/_browser-chunks/chunk-EIYAKDGP.js +302 -0
  83. package/dist/_browser-chunks/chunk-ENKK74N4.js +12 -0
  84. package/dist/_browser-chunks/chunk-FENFYI4X.js +698 -0
  85. package/dist/_browser-chunks/chunk-FJGWSWL5.js +155 -0
  86. package/dist/_browser-chunks/chunk-FVSEPWWX.js +2810 -0
  87. package/dist/_browser-chunks/chunk-GNZY6LOW.js +10116 -0
  88. package/dist/_browser-chunks/chunk-IE4ULIOQ.js +14 -0
  89. package/dist/_browser-chunks/chunk-IMSF75WX.js +42 -0
  90. package/dist/_browser-chunks/chunk-IWQGIXJS.js +14 -0
  91. package/dist/_browser-chunks/chunk-JMC7AIKT.js +108 -0
  92. package/dist/_browser-chunks/chunk-JPUOQJUI.js +8 -0
  93. package/dist/_browser-chunks/chunk-JSBKXXXF.js +218 -0
  94. package/dist/_browser-chunks/chunk-JWSKPMPC.js +73 -0
  95. package/dist/_browser-chunks/chunk-JYVGARBG.js +2943 -0
  96. package/dist/_browser-chunks/chunk-KBK7GKBN.js +35 -0
  97. package/dist/_browser-chunks/chunk-KQ7CRO2B.js +108 -0
  98. package/dist/_browser-chunks/chunk-LAWXTSXK.js +18 -0
  99. package/dist/_browser-chunks/chunk-LE2LTDW3.js +14 -0
  100. package/dist/_browser-chunks/chunk-LEVSOOLQ.js +48 -0
  101. package/dist/_browser-chunks/chunk-LV5PIKV4.js +93 -0
  102. package/dist/_browser-chunks/chunk-MDOL7KML.js +56 -0
  103. package/dist/_browser-chunks/chunk-MFMDGWP6.js +34 -0
  104. package/dist/_browser-chunks/chunk-MLBOOZL4.js +67 -0
  105. package/dist/_browser-chunks/chunk-NQUD4B7H.js +91 -0
  106. package/dist/_browser-chunks/chunk-NULBREPZ.js +43 -0
  107. package/dist/_browser-chunks/chunk-NZMVUW5T.js +7 -0
  108. package/dist/_browser-chunks/chunk-OD6IBQCC.js +117 -0
  109. package/dist/_browser-chunks/chunk-ODVJ3XZJ.js +157 -0
  110. package/dist/_browser-chunks/chunk-OQWFVDIN.js +386 -0
  111. package/dist/_browser-chunks/chunk-OVH3USFB.js +20 -0
  112. package/dist/_browser-chunks/chunk-OZZPSYQR.js +14 -0
  113. package/dist/_browser-chunks/chunk-P6PK47TQ.js +1970 -0
  114. package/dist/_browser-chunks/chunk-PFRNG3UC.js +22 -0
  115. package/dist/_browser-chunks/chunk-PJSMZ27A.js +13 -0
  116. package/dist/_browser-chunks/chunk-QC4HFS6K.js +41 -0
  117. package/dist/_browser-chunks/chunk-QDXFODK4.js +274 -0
  118. package/dist/_browser-chunks/chunk-RBCHTR7C.js +28 -0
  119. package/dist/_browser-chunks/chunk-RMYQ3QN3.js +294 -0
  120. package/dist/_browser-chunks/chunk-RNTIV5CE.js +411 -0
  121. package/dist/_browser-chunks/chunk-RSPAQWVJ.js +80 -0
  122. package/dist/_browser-chunks/chunk-S6TK43XQ.js +836 -0
  123. package/dist/_browser-chunks/chunk-SC67XZST.js +18 -0
  124. package/dist/_browser-chunks/chunk-SFVA4SBT.js +683 -0
  125. package/dist/_browser-chunks/chunk-SZYFOQMT.js +25 -0
  126. package/dist/_browser-chunks/chunk-TBJCJXK4.js +18 -0
  127. package/dist/_browser-chunks/chunk-UMDO3KB7.js +205 -0
  128. package/dist/_browser-chunks/chunk-V2G23FV7.js +11 -0
  129. package/dist/_browser-chunks/chunk-V5M7Q4HT.js +88 -0
  130. package/dist/_browser-chunks/chunk-W5M6NPS3.js +198 -0
  131. package/dist/_browser-chunks/chunk-W7NE2JXW.js +84 -0
  132. package/dist/_browser-chunks/chunk-WGVAAM43.js +1110 -0
  133. package/dist/_browser-chunks/chunk-WHQRNHXD.js +8 -0
  134. package/dist/_browser-chunks/chunk-WOSOWBCA.js +12 -0
  135. package/dist/_browser-chunks/chunk-WZ7KR7SH.js +85 -0
  136. package/dist/_browser-chunks/chunk-YEKO6BHJ.js +20 -0
  137. package/dist/_browser-chunks/chunk-YI2IBIQS.js +7 -0
  138. package/dist/_browser-chunks/chunk-YTIT5NA5.js +1966 -0
  139. package/dist/_browser-chunks/chunk-ZEHRUHTA.js +6 -0
  140. package/dist/_browser-chunks/chunk-ZTQ5MEJ5.js +203 -0
  141. package/dist/_browser-chunks/matchers-YLBYSYAF.js +1263 -0
  142. package/dist/_browser-chunks/react-dom-client-4OHE3QDV.js +9 -0
  143. package/dist/_node-chunks/attached-runtime-I2G4WLJI.js +282 -0
  144. package/dist/_node-chunks/builder-manager-VVHYQXCH.js +1661 -0
  145. package/dist/_node-chunks/chunk-2BUPBPFB.js +82 -0
  146. package/dist/_node-chunks/chunk-2DSIDINN.js +884 -0
  147. package/dist/_node-chunks/chunk-2RU7BKEW.js +23 -0
  148. package/dist/_node-chunks/chunk-34EO2PUT.js +26 -0
  149. package/dist/_node-chunks/chunk-3BKIBF5S.js +3008 -0
  150. package/dist/_node-chunks/chunk-3SDUYDXH.js +98 -0
  151. package/dist/_node-chunks/chunk-3T4ZSNPH.js +662 -0
  152. package/dist/_node-chunks/chunk-3W7F2B7P.js +79 -0
  153. package/dist/_node-chunks/chunk-3Y6AAY5H.js +80 -0
  154. package/dist/_node-chunks/chunk-42UWAGPW.js +1193 -0
  155. package/dist/_node-chunks/chunk-4FEANXWU.js +1986 -0
  156. package/dist/_node-chunks/chunk-5DQFEZEA.js +40 -0
  157. package/dist/_node-chunks/chunk-6KEHV53S.js +1218 -0
  158. package/dist/_node-chunks/chunk-6LMWA44H.js +3837 -0
  159. package/dist/_node-chunks/chunk-6YKBRP72.js +20 -0
  160. package/dist/_node-chunks/chunk-7GUDZVRQ.js +110 -0
  161. package/dist/_node-chunks/chunk-B5J7Q7J4.js +21 -0
  162. package/dist/_node-chunks/chunk-BS2WMZMR.js +90 -0
  163. package/dist/_node-chunks/chunk-BSKFCWQD.js +47 -0
  164. package/dist/_node-chunks/chunk-BXVYT7SB.js +36 -0
  165. package/dist/_node-chunks/chunk-CCOTJ4FC.js +688 -0
  166. package/dist/_node-chunks/chunk-CQKMLL5J.js +33 -0
  167. package/dist/_node-chunks/chunk-CXRU72ET.js +63 -0
  168. package/dist/_node-chunks/chunk-DC7DKR5K.js +20 -0
  169. package/dist/_node-chunks/chunk-DHJFTB4K.js +25 -0
  170. package/dist/_node-chunks/chunk-DUR55DJJ.js +1094 -0
  171. package/dist/_node-chunks/chunk-E6YESGLX.js +7032 -0
  172. package/dist/_node-chunks/chunk-EHUNOMDD.js +52345 -0
  173. package/dist/_node-chunks/chunk-ET7PWEO7.js +298 -0
  174. package/dist/_node-chunks/chunk-EWOX7HPJ.js +20 -0
  175. package/dist/_node-chunks/chunk-F3ZFKBHY.js +844 -0
  176. package/dist/_node-chunks/chunk-FK7KGTV7.js +26 -0
  177. package/dist/_node-chunks/chunk-FPZB5OI7.js +35 -0
  178. package/dist/_node-chunks/chunk-FW2HQUBQ.js +25 -0
  179. package/dist/_node-chunks/chunk-FY6UXW6G.js +11 -0
  180. package/dist/_node-chunks/chunk-GEFQN7K3.js +499 -0
  181. package/dist/_node-chunks/chunk-GRBLDJCR.js +989 -0
  182. package/dist/_node-chunks/chunk-H32DYT6P.js +87 -0
  183. package/dist/_node-chunks/chunk-H4PPVMP5.js +23 -0
  184. package/dist/_node-chunks/chunk-HMP2G23X.js +25 -0
  185. package/dist/_node-chunks/chunk-ICPBH3E7.js +59 -0
  186. package/dist/_node-chunks/chunk-IDEL2J23.js +23 -0
  187. package/dist/_node-chunks/chunk-IK4FGZLR.js +223 -0
  188. package/dist/_node-chunks/chunk-JDXXX6LB.js +68 -0
  189. package/dist/_node-chunks/chunk-JGGFYIG5.js +5468 -0
  190. package/dist/_node-chunks/chunk-JPAZLYJ3.js +29 -0
  191. package/dist/_node-chunks/chunk-JZOO7GGC.js +48 -0
  192. package/dist/_node-chunks/chunk-KISMCCP5.js +4744 -0
  193. package/dist/_node-chunks/chunk-LCK4ZQKG.js +115 -0
  194. package/dist/_node-chunks/chunk-LO56I6E2.js +132 -0
  195. package/dist/_node-chunks/chunk-LXBD4UL4.js +104 -0
  196. package/dist/_node-chunks/chunk-MA24JW6C.js +7162 -0
  197. package/dist/_node-chunks/chunk-MK2KYAI6.js +5414 -0
  198. package/dist/_node-chunks/chunk-NDWKJ4CL.js +2102 -0
  199. package/dist/_node-chunks/chunk-NIBT7XDZ.js +168 -0
  200. package/dist/_node-chunks/chunk-NPO45IMH.js +33 -0
  201. package/dist/_node-chunks/chunk-OISX4AGQ.js +414 -0
  202. package/dist/_node-chunks/chunk-OUW6R7C3.js +26 -0
  203. package/dist/_node-chunks/chunk-OWNFOGTA.js +194 -0
  204. package/dist/_node-chunks/chunk-Q7QNUM5H.js +49 -0
  205. package/dist/_node-chunks/chunk-QEQLR22M.js +1877 -0
  206. package/dist/_node-chunks/chunk-RRN2V55B.js +45 -0
  207. package/dist/_node-chunks/chunk-RWFIFGO5.js +144 -0
  208. package/dist/_node-chunks/chunk-RXNJDRGO.js +209 -0
  209. package/dist/_node-chunks/chunk-RZMQ7S3L.js +92 -0
  210. package/dist/_node-chunks/chunk-SIEXZVCR.js +51 -0
  211. package/dist/_node-chunks/chunk-SLWQNBGO.js +2034 -0
  212. package/dist/_node-chunks/chunk-SVTBJ7Q3.js +35 -0
  213. package/dist/_node-chunks/chunk-SWO5CDYU.js +32 -0
  214. package/dist/_node-chunks/chunk-TD5PLLQG.js +121 -0
  215. package/dist/_node-chunks/chunk-TEQGGSP7.js +33 -0
  216. package/dist/_node-chunks/chunk-TFCEV2XX.js +155 -0
  217. package/dist/_node-chunks/chunk-TFEWM4E3.js +1073 -0
  218. package/dist/_node-chunks/chunk-TINO74G5.js +21 -0
  219. package/dist/_node-chunks/chunk-TNJIXE37.js +40 -0
  220. package/dist/_node-chunks/chunk-TWI4GVH7.js +19 -0
  221. package/dist/_node-chunks/chunk-U5W53R2J.js +1011 -0
  222. package/dist/_node-chunks/chunk-UBOGWBEA.js +148 -0
  223. package/dist/_node-chunks/chunk-UMUBKI6E.js +3787 -0
  224. package/dist/_node-chunks/chunk-UVINFLGY.js +56 -0
  225. package/dist/_node-chunks/chunk-V2DY426G.js +1133 -0
  226. package/dist/_node-chunks/chunk-VLOXOXXE.js +45 -0
  227. package/dist/_node-chunks/chunk-W4OMYLSP.js +1297 -0
  228. package/dist/_node-chunks/chunk-WAXVSN3O.js +18 -0
  229. package/dist/_node-chunks/chunk-WCULS5TP.js +3767 -0
  230. package/dist/_node-chunks/chunk-WNZ2UMFM.js +153 -0
  231. package/dist/_node-chunks/chunk-WZJF2OUH.js +74 -0
  232. package/dist/_node-chunks/chunk-XGIUVY52.js +611 -0
  233. package/dist/_node-chunks/chunk-XHL2LVBM.js +415 -0
  234. package/dist/_node-chunks/chunk-XI6B6P47.js +59 -0
  235. package/dist/_node-chunks/chunk-XLP2ZKXV.js +60 -0
  236. package/dist/_node-chunks/chunk-YCMRA6RX.js +95 -0
  237. package/dist/_node-chunks/chunk-YZFWBA5L.js +2700 -0
  238. package/dist/_node-chunks/chunk-ZMAMXQKP.js +4731 -0
  239. package/dist/_node-chunks/chunk-ZWBCQ4MJ.js +110 -0
  240. package/dist/_node-chunks/dist-VTSTZKUB.js +16 -0
  241. package/dist/_node-chunks/globby-OEMHPBFY.js +2884 -0
  242. package/dist/_node-chunks/jiti-NFX6UU74.js +3848 -0
  243. package/dist/_node-chunks/lib-MDVARD7W.js +366 -0
  244. package/dist/_node-chunks/local-runtime-NTKIN2QT.js +78 -0
  245. package/dist/_node-chunks/mdx-plugin-MWISDWDQ.js +5680 -0
  246. package/dist/_node-chunks/monorepo-LIRFMQXE.js +121 -0
  247. package/dist/_node-chunks/monorepo-optimized-tests-relaxed-limits-no-story-deletion-CPDW4XTW.js +121 -0
  248. package/dist/_node-chunks/optimized-tests-HDOLR3EY.js +22 -0
  249. package/dist/_node-chunks/pattern-copy-play-EKHIUAU2.js +807 -0
  250. package/dist/_node-chunks/postinstallAddon-GYGMWDL6.js +20 -0
  251. package/dist/_node-chunks/rehype-external-links-BUN3HUCO.js +121 -0
  252. package/dist/_node-chunks/rehype-slug-PLADX223.js +52 -0
  253. package/dist/_node-chunks/relaxed-limits-GBHW6KIQ.js +117 -0
  254. package/dist/_node-chunks/run-KDTIZNSY.js +103 -0
  255. package/dist/_node-chunks/run-NL66VTNR.js +4532 -0
  256. package/dist/_node-chunks/session-id-KIIVOQLR.js +23 -0
  257. package/dist/_node-chunks/setup-MGC7BQO6.js +278 -0
  258. package/dist/_node-chunks/vitest.config.4.template-JH2THZFG.js +54 -0
  259. package/dist/actions/decorator.d.ts +7 -0
  260. package/dist/actions/decorator.js +43 -0
  261. package/dist/actions/index.d.ts +67 -0
  262. package/dist/actions/index.js +28 -0
  263. package/dist/addon-a11y/index.d.ts +52 -0
  264. package/dist/addon-a11y/index.js +16 -0
  265. package/dist/addon-a11y/manager.js +1429 -0
  266. package/dist/addon-a11y/preset.js +18 -0
  267. package/dist/addon-a11y/preview.d.ts +17 -0
  268. package/dist/addon-a11y/preview.js +15 -0
  269. package/dist/addon-docs/blocks.d.ts +1061 -0
  270. package/dist/addon-docs/blocks.js +2461 -0
  271. package/dist/addon-docs/index.d.ts +236 -0
  272. package/dist/addon-docs/index.js +16 -0
  273. package/dist/addon-docs/manager.js +90 -0
  274. package/dist/addon-docs/mdx-react-shim.d.ts +1 -0
  275. package/dist/addon-docs/mdx-react-shim.js +2 -0
  276. package/dist/addon-docs/preset.js +378 -0
  277. package/dist/addon-docs/preview.d.ts +4 -0
  278. package/dist/addon-docs/preview.js +7 -0
  279. package/dist/addon-links/index.d.ts +22 -0
  280. package/dist/addon-links/index.js +20 -0
  281. package/dist/addon-links/manager.js +14 -0
  282. package/dist/addon-links/preview.d.ts +6 -0
  283. package/dist/addon-links/preview.js +9 -0
  284. package/dist/addon-links/react/index.d.ts +25 -0
  285. package/dist/addon-links/react/index.js +52 -0
  286. package/dist/addon-mcp/preset.js +1345 -0
  287. package/dist/addon-mcp/preview.js +29 -0
  288. package/dist/addon-mcp/tools/preview-stories/preview-stories-app-script.js +1153 -0
  289. package/dist/addon-ondevice-actions/index.d.ts +4 -0
  290. package/dist/addon-ondevice-actions/index.js +7 -0
  291. package/dist/addon-ondevice-actions/register.js +7 -0
  292. package/dist/addon-ondevice-controls/index.d.ts +6 -0
  293. package/dist/addon-ondevice-controls/index.js +14 -0
  294. package/dist/addon-ondevice-controls/register.js +10 -0
  295. package/dist/addon-pseudo-states/index.d.ts +35 -0
  296. package/dist/addon-pseudo-states/index.js +15 -0
  297. package/dist/addon-pseudo-states/manager.js +53 -0
  298. package/dist/addon-pseudo-states/preview.d.ts +9 -0
  299. package/dist/addon-pseudo-states/preview.js +10 -0
  300. package/dist/addon-themes/index.d.ts +80 -0
  301. package/dist/addon-themes/index.js +104 -0
  302. package/dist/addon-themes/manager.js +97 -0
  303. package/dist/addon-themes/postinstall.js +33 -0
  304. package/dist/addon-themes/preview.d.ts +6 -0
  305. package/dist/addon-themes/preview.js +8 -0
  306. package/dist/addon-vitest/constants.d.ts +132 -0
  307. package/dist/addon-vitest/constants.js +66 -0
  308. package/dist/addon-vitest/index.d.ts +4 -0
  309. package/dist/addon-vitest/index.js +8 -0
  310. package/dist/addon-vitest/manager.js +665 -0
  311. package/dist/addon-vitest/node/coverage-reporter.js +1284 -0
  312. package/dist/addon-vitest/node/vitest.js +674 -0
  313. package/dist/addon-vitest/postinstall.js +24 -0
  314. package/dist/addon-vitest/preset.js +943 -0
  315. package/dist/addon-vitest/vitest-plugin/global-setup.js +162 -0
  316. package/dist/addon-vitest/vitest-plugin/index.d.ts +56 -0
  317. package/dist/addon-vitest/vitest-plugin/index.js +463 -0
  318. package/dist/addon-vitest/vitest-plugin/setup-file-with-project-annotations.js +9 -0
  319. package/dist/addon-vitest/vitest-plugin/setup-file.browser.4.js +20 -0
  320. package/dist/addon-vitest/vitest-plugin/setup-file.js +50 -0
  321. package/dist/addon-vitest/vitest-plugin/test-utils.js +128 -0
  322. package/dist/babel/index.d.ts +2301 -0
  323. package/dist/babel/index.js +61 -0
  324. package/dist/backgrounds/index.d.ts +6 -0
  325. package/dist/backgrounds/index.js +15 -0
  326. package/dist/bin/core.js +1705 -0
  327. package/dist/bin/dispatcher.js +43 -0
  328. package/dist/bin/loader.js +115 -0
  329. package/dist/builder-vite/index.d.ts +50 -0
  330. package/dist/builder-vite/index.js +245 -0
  331. package/dist/builder-vite/preset.js +27 -0
  332. package/dist/channels/index.d.ts +2 -0
  333. package/dist/channels/index.js +352 -0
  334. package/dist/chunk-B2t1tGRh.d.ts +284 -0
  335. package/dist/chunk-BCoJQE-f.d.ts +602 -0
  336. package/dist/chunk-BGkgZp-H.d.ts +214 -0
  337. package/dist/chunk-BTVrWliM.d.ts +115 -0
  338. package/dist/chunk-BXLImeLy.d.ts +197 -0
  339. package/dist/chunk-BfBzpgct.d.ts +916 -0
  340. package/dist/chunk-Bpi2tz-6.d.ts +511 -0
  341. package/dist/chunk-BxWufQms.d.ts +142 -0
  342. package/dist/chunk-C-bavsOH.d.ts +34 -0
  343. package/dist/chunk-C2p5r3Vt.d.ts +13001 -0
  344. package/dist/chunk-C6PAgHLT.d.ts +12 -0
  345. package/dist/chunk-CMeX4WRe.d.ts +179 -0
  346. package/dist/chunk-Ct9xd6IM.d.ts +65 -0
  347. package/dist/chunk-CwQKNaYL.d.ts +15 -0
  348. package/dist/chunk-D7DwV41f.d.ts +3622 -0
  349. package/dist/chunk-DEVFdzxR.d.ts +253 -0
  350. package/dist/chunk-DaVb55-_.d.ts +124 -0
  351. package/dist/chunk-DgRNfmj_.d.ts +40 -0
  352. package/dist/chunk-DoIGKY33.d.ts +666 -0
  353. package/dist/chunk-Dr3R0DXk.d.ts +40 -0
  354. package/dist/chunk-DtHByo32.d.ts +55 -0
  355. package/dist/chunk-Dw1z1Pki.d.ts +933 -0
  356. package/dist/chunk-DzuY9DXg.d.ts +79 -0
  357. package/dist/chunk-FjDVzZTj.d.ts +62 -0
  358. package/dist/chunk-Kt1tW-D1.d.ts +59 -0
  359. package/dist/chunk-XP8oHzpE.d.ts +6 -0
  360. package/dist/chunk-gCX81nOr.d.ts +61 -0
  361. package/dist/chunk-pcFXCimE.d.ts +741 -0
  362. package/dist/cli/index.d.ts +1174 -0
  363. package/dist/cli/index.js +5613 -0
  364. package/dist/cli/skills/content/index.d.ts +72 -0
  365. package/dist/cli/skills/content/index.js +335 -0
  366. package/dist/cli/tools/sdk/child-host.d.ts +61 -0
  367. package/dist/cli/tools/sdk/child-host.js +131 -0
  368. package/dist/cli/tools/sdk/index.d.ts +137 -0
  369. package/dist/cli/tools/sdk/index.js +44 -0
  370. package/dist/cli-commands/bin/index.js +25 -0
  371. package/dist/client-logger/index.d.ts +31 -0
  372. package/dist/client-logger/index.js +63 -0
  373. package/dist/common/index.d.ts +1103 -0
  374. package/dist/common/index.js +364 -0
  375. package/dist/components/index.d.ts +1924 -0
  376. package/dist/components/index.js +13759 -0
  377. package/dist/core-events/index.d.ts +155 -0
  378. package/dist/core-events/index.js +136 -0
  379. package/dist/core-server/index.d.ts +2200 -0
  380. package/dist/core-server/index.js +4165 -0
  381. package/dist/core-server/presets/common-manager.css +170 -0
  382. package/dist/core-server/presets/common-manager.js +4168 -0
  383. package/dist/core-server/presets/common-override-preset.js +81 -0
  384. package/dist/core-server/presets/common-preset.js +2187 -0
  385. package/dist/create/bin/index.js +23 -0
  386. package/dist/create/index.js +25 -0
  387. package/dist/csf/csf-utils.d.ts +2 -0
  388. package/dist/csf/csf-utils.js +19 -0
  389. package/dist/csf/index.d.ts +7 -0
  390. package/dist/csf/index.js +2142 -0
  391. package/dist/csf-tools/index.d.ts +1157 -0
  392. package/dist/csf-tools/index.js +736 -0
  393. package/dist/docs-tools/index.d.ts +197 -0
  394. package/dist/docs-tools/index.js +61 -0
  395. package/dist/highlight/index.d.ts +10 -0
  396. package/dist/highlight/index.js +15 -0
  397. package/dist/instrumenter/index.d.ts +113 -0
  398. package/dist/instrumenter/index.js +2595 -0
  399. package/dist/manager/_manager-chunks/globals-runtime-8HkdnU2F.js +6144 -0
  400. package/dist/manager/_manager-chunks/globals-runtime-BIKBO23x.js +3389 -0
  401. package/dist/manager/_manager-chunks/globals-runtime-BdGkqNEt.js +45 -0
  402. package/dist/manager/_manager-chunks/globals-runtime-BmphMP6z.js +1190 -0
  403. package/dist/manager/_manager-chunks/globals-runtime-BvM-NY2g.js +13307 -0
  404. package/dist/manager/_manager-chunks/globals-runtime-C02fvgcd.js +9243 -0
  405. package/dist/manager/_manager-chunks/globals-runtime-DkAPXCvc.js +9766 -0
  406. package/dist/manager/_manager-chunks/globals-runtime-DpNYC-qi.js +5564 -0
  407. package/dist/manager/_manager-chunks/globals-runtime-DtcOnYHR.js +5357 -0
  408. package/dist/manager/_manager-chunks/globals-runtime-DwFqpqya.js +722 -0
  409. package/dist/manager/_manager-chunks/globals-runtime-FC201B7s.js +6837 -0
  410. package/dist/manager/_manager-chunks/globals-runtime-Rp_zjGnh.js +121 -0
  411. package/dist/manager/_manager-chunks/globals-runtime-ZHrQFa3-.js +10463 -0
  412. package/dist/manager/_manager-chunks/globals-runtime-eLPTIfX-.js +7759 -0
  413. package/dist/manager/_manager-chunks/globals-runtime-qKvCZHFY.js +4468 -0
  414. package/dist/manager/_manager-chunks/globals-runtime-sGpNlIJ1.js +5102 -0
  415. package/dist/manager/_manager-chunks/runtime-B1L9TH89.js +452 -0
  416. package/dist/manager/_manager-chunks/runtime-BK0zF7FN.js +22 -0
  417. package/dist/manager/_manager-chunks/runtime-BhkT2CXl.js +1408 -0
  418. package/dist/manager/_manager-chunks/runtime-Bly6WJLN.js +998 -0
  419. package/dist/manager/_manager-chunks/runtime-D0UOWx0U.js +979 -0
  420. package/dist/manager/_manager-chunks/runtime-D94Vq3oR.js +4014 -0
  421. package/dist/manager/_manager-chunks/runtime-DMig8mT7.js +77 -0
  422. package/dist/manager/_manager-chunks/runtime-EITvVbkG.js +46 -0
  423. package/dist/manager/_manager-chunks/runtime-cp5pazY2.js +8936 -0
  424. package/dist/manager/_manager-chunks/runtime-eDVAYF7N.js +6860 -0
  425. package/dist/manager/_manager-chunks/runtime-i-PDAHLR.js +2493 -0
  426. package/dist/manager/globals-runtime.js +2 -0
  427. package/dist/manager/globals.d.ts +23 -0
  428. package/dist/manager/globals.js +26 -0
  429. package/dist/manager/manager-stores.d.ts +2 -0
  430. package/dist/manager/manager-stores.js +19 -0
  431. package/dist/manager/runtime.js +2 -0
  432. package/dist/manager-api/index.d.ts +2 -0
  433. package/dist/manager-api/index.js +3257 -0
  434. package/dist/manager-errors.d.ts +89 -0
  435. package/dist/manager-errors.js +20 -0
  436. package/dist/mcp/index.d.ts +270 -0
  437. package/dist/mcp/index.js +305 -0
  438. package/dist/mocking-utils/index.d.ts +689 -0
  439. package/dist/mocking-utils/index.js +521 -0
  440. package/dist/mocking-utils/mocker-runtime.js +1254 -0
  441. package/dist/nextjs-vite/config/preview.js +3 -0
  442. package/dist/nextjs-vite/export-mocks/cache/index.d.ts +25 -0
  443. package/dist/nextjs-vite/export-mocks/cache/index.js +29 -0
  444. package/dist/nextjs-vite/export-mocks/headers/index.d.ts +37 -0
  445. package/dist/nextjs-vite/export-mocks/headers/index.js +54 -0
  446. package/dist/nextjs-vite/export-mocks/link/index.d.ts +9 -0
  447. package/dist/nextjs-vite/export-mocks/link/index.js +59 -0
  448. package/dist/nextjs-vite/export-mocks/navigation/index.d.ts +28 -0
  449. package/dist/nextjs-vite/export-mocks/navigation/index.js +58 -0
  450. package/dist/nextjs-vite/export-mocks/router/index.d.ts +34 -0
  451. package/dist/nextjs-vite/export-mocks/router/index.js +63 -0
  452. package/dist/nextjs-vite/index.d.ts +92 -0
  453. package/dist/nextjs-vite/index.js +58 -0
  454. package/dist/nextjs-vite/node/index.d.ts +6 -0
  455. package/dist/nextjs-vite/node/index.js +20 -0
  456. package/dist/nextjs-vite/preset.js +648 -0
  457. package/dist/nextjs-vite/preview.d.ts +20 -0
  458. package/dist/nextjs-vite/preview.js +11 -0
  459. package/dist/nextjs-vite/vite-plugin/index.d.ts +6 -0
  460. package/dist/nextjs-vite/vite-plugin/index.js +19 -0
  461. package/dist/nextjs-vite-plugin/index.d.ts +28 -0
  462. package/dist/nextjs-vite-plugin/index.js +923 -0
  463. package/dist/nextjs-vite-plugin/mocks/storybook.global.js +29 -0
  464. package/dist/nextjs-vite-plugin/plugins/next-image/alias/image-context.js +8 -0
  465. package/dist/nextjs-vite-plugin/plugins/next-image/alias/image-default-loader.js +23 -0
  466. package/dist/nextjs-vite-plugin/plugins/next-image/alias/next-image.js +28 -0
  467. package/dist/nextjs-vite-plugin/plugins/next-image/alias/next-legacy-image.js +17 -0
  468. package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/cache/index.js +29 -0
  469. package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/dynamic/index.js +40 -0
  470. package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/headers/index.js +55 -0
  471. package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/link/index.js +63 -0
  472. package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/navigation/index.js +71 -0
  473. package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/router/index.js +74 -0
  474. package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/rsc/server-only.js +7 -0
  475. package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/safe-stable-stringify/index.js +13 -0
  476. package/dist/nextjs-vite-plugin/plugins/next-mocks/compatibility/draft-mode.compat.js +7 -0
  477. package/dist/node-logger/index.d.ts +495 -0
  478. package/dist/node-logger/index.js +42 -0
  479. package/dist/oxc-parser/index.d.ts +99 -0
  480. package/dist/oxc-parser/index.js +275 -0
  481. package/dist/oxc-parser/worker.js +37 -0
  482. package/dist/preview/_chunks/runtime-BIzIdDbb.js +10263 -0
  483. package/dist/preview/_chunks/runtime-BTPtVY1p.js +1102 -0
  484. package/dist/preview/_chunks/runtime-BZSnICCg.js +8484 -0
  485. package/dist/preview/_chunks/runtime-BdGkqNEt.js +45 -0
  486. package/dist/preview/_chunks/runtime-BwSxqk3t.js +63 -0
  487. package/dist/preview/_chunks/runtime-CqHxptiK.js +6143 -0
  488. package/dist/preview/_chunks/runtime-CsV4HZPV.js +5064 -0
  489. package/dist/preview/_chunks/runtime-CxZK_Ln3.js +284 -0
  490. package/dist/preview/_chunks/runtime-DZToXfvO.js +9767 -0
  491. package/dist/preview/_chunks/runtime-DrTjJkPY.js +3872 -0
  492. package/dist/preview/_chunks/runtime-DuHdxMFA.js +387 -0
  493. package/dist/preview/_chunks/runtime-iXdo8CR8.js +3635 -0
  494. package/dist/preview/_chunks/runtime-q3wt0e_N.js +6838 -0
  495. package/dist/preview/globals.d.ts +16 -0
  496. package/dist/preview/globals.js +20 -0
  497. package/dist/preview/runtime.js +6 -0
  498. package/dist/preview-api/index.d.ts +4 -0
  499. package/dist/preview-api/index.js +147 -0
  500. package/dist/preview-errors.d.ts +186 -0
  501. package/dist/preview-errors.js +56 -0
  502. package/dist/react/docgen/docgen-worker.js +38 -0
  503. package/dist/react/entry-preview-argtypes.js +9 -0
  504. package/dist/react/entry-preview-docs.js +12 -0
  505. package/dist/react/entry-preview-rsc.js +11 -0
  506. package/dist/react/entry-preview.js +21 -0
  507. package/dist/react/index.d.ts +119 -0
  508. package/dist/react/index.js +26 -0
  509. package/dist/react/preset.js +301 -0
  510. package/dist/react/preview.d.ts +2 -0
  511. package/dist/react/preview.js +11 -0
  512. package/dist/react-native/bin/get-stories.js +34 -0
  513. package/dist/react-native/index.d.ts +160 -0
  514. package/dist/react-native/index.js +1547 -0
  515. package/dist/react-native/metro/node.d.ts +83 -0
  516. package/dist/react-native/metro/node.js +21 -0
  517. package/dist/react-native/metro/withStorybook.d.ts +2269 -0
  518. package/dist/react-native/metro/withStorybook.js +138 -0
  519. package/dist/react-native/preview.d.ts +6 -0
  520. package/dist/react-native/preview.js +20 -0
  521. package/dist/react-native/scripts/generate.d.ts +22 -0
  522. package/dist/react-native/scripts/generate.js +18 -0
  523. package/dist/react-native/stub.js +20 -0
  524. package/dist/react-native-theming/index.d.ts +175 -0
  525. package/dist/react-native-theming/index.js +2591 -0
  526. package/dist/react-native-ui/index.d.ts +130 -0
  527. package/dist/react-native-ui/index.js +1448 -0
  528. package/dist/react-native-ui-common/index.d.ts +230 -0
  529. package/dist/react-native-ui-common/index.js +514 -0
  530. package/dist/react-vite/index.d.ts +4 -0
  531. package/dist/react-vite/index.js +8 -0
  532. package/dist/react-vite/node/index.d.ts +6 -0
  533. package/dist/react-vite/node/index.js +20 -0
  534. package/dist/react-vite/preset.d.ts +6 -0
  535. package/dist/react-vite/preset.js +21 -0
  536. package/dist/router/index.d.ts +141 -0
  537. package/dist/router/index.js +1217 -0
  538. package/dist/server-errors.d.ts +2 -0
  539. package/dist/server-errors.js +149 -0
  540. package/dist/shared/open-service/index.d.ts +3 -0
  541. package/dist/shared/open-service/index.js +115 -0
  542. package/dist/shared/open-service/services/docgen/worker/docgen-worker.js +75 -0
  543. package/dist/shared/open-service/toolsets/docs/public.d.ts +1296 -0
  544. package/dist/shared/open-service/toolsets/docs/public.js +991 -0
  545. package/dist/telemetry/index.d.ts +314 -0
  546. package/dist/telemetry/index.js +103 -0
  547. package/dist/test/index.d.ts +158 -0
  548. package/dist/test/index.js +19421 -0
  549. package/dist/theming/create.d.ts +15 -0
  550. package/dist/theming/create.js +11 -0
  551. package/dist/theming/index.d.ts +54 -0
  552. package/dist/theming/index.js +511 -0
  553. package/dist/types/index.d.ts +2 -0
  554. package/dist/types/index.js +48 -0
  555. package/dist/viewport/index.d.ts +275 -0
  556. package/dist/viewport/index.js +21 -0
  557. package/package.json +1054 -4
  558. package/template/nextjs-vite/cli/.eslintrc.json +6 -0
  559. package/template/nextjs-vite/cli/js/Button.jsx +42 -0
  560. package/template/nextjs-vite/cli/js/Button.stories.js +49 -0
  561. package/template/nextjs-vite/cli/js/Configure.mdx +470 -0
  562. package/template/nextjs-vite/cli/js/Header.jsx +58 -0
  563. package/template/nextjs-vite/cli/js/Header.stories.js +30 -0
  564. package/template/nextjs-vite/cli/js/Page.jsx +68 -0
  565. package/template/nextjs-vite/cli/js/Page.stories.js +28 -0
  566. package/template/nextjs-vite/cli/ts/Button.stories.ts +54 -0
  567. package/template/nextjs-vite/cli/ts/Button.tsx +39 -0
  568. package/template/nextjs-vite/cli/ts/Configure.mdx +446 -0
  569. package/template/nextjs-vite/cli/ts/Header.stories.ts +34 -0
  570. package/template/nextjs-vite/cli/ts/Header.tsx +54 -0
  571. package/template/nextjs-vite/cli/ts/Page.stories.ts +33 -0
  572. package/template/nextjs-vite/cli/ts/Page.tsx +73 -0
  573. package/template/react/cli/.eslintrc.json +5 -0
  574. package/template/react/cli/js/Button.jsx +39 -0
  575. package/template/react/cli/js/Button.stories.js +49 -0
  576. package/template/react/cli/js/Header.jsx +56 -0
  577. package/template/react/cli/js/Header.stories.js +29 -0
  578. package/template/react/cli/js/Page.jsx +69 -0
  579. package/template/react/cli/js/Page.stories.js +28 -0
  580. package/template/react/cli/ts/Button.stories.ts +54 -0
  581. package/template/react/cli/ts/Button.tsx +37 -0
  582. package/template/react/cli/ts/Header.stories.ts +34 -0
  583. package/template/react/cli/ts/Header.tsx +56 -0
  584. package/template/react/cli/ts/Page.stories.ts +33 -0
  585. package/template/react/cli/ts/Page.tsx +73 -0
  586. package/template/react-vite/cli/.eslintrc.json +5 -0
  587. package/template/react-vite/cli/js/Button.jsx +39 -0
  588. package/template/react-vite/cli/js/Button.stories.js +49 -0
  589. package/template/react-vite/cli/js/Header.jsx +56 -0
  590. package/template/react-vite/cli/js/Header.stories.js +29 -0
  591. package/template/react-vite/cli/js/Page.jsx +69 -0
  592. package/template/react-vite/cli/js/Page.stories.js +28 -0
  593. package/template/react-vite/cli/ts/Button.stories.ts +54 -0
  594. package/template/react-vite/cli/ts/Button.tsx +37 -0
  595. package/template/react-vite/cli/ts/Header.stories.ts +34 -0
  596. package/template/react-vite/cli/ts/Header.tsx +56 -0
  597. package/template/react-vite/cli/ts/Page.stories.ts +33 -0
  598. package/template/react-vite/cli/ts/Page.tsx +73 -0
@@ -0,0 +1,3257 @@
1
+ import {
2
+ throttle
3
+ } from "../_browser-chunks/chunk-W7NE2JXW.js";
4
+ import {
5
+ UniversalStore
6
+ } from "../_browser-chunks/chunk-OQWFVDIN.js";
7
+ import {
8
+ parse,
9
+ stringify as stringify2
10
+ } from "../_browser-chunks/chunk-WGVAAM43.js";
11
+ import {
12
+ UNIVERSAL_STATUS_STORE_OPTIONS,
13
+ countStatusesByValue,
14
+ createStatusStore,
15
+ statusValueShortName,
16
+ toStatusValue
17
+ } from "../_browser-chunks/chunk-FJGWSWL5.js";
18
+ import {
19
+ dequal,
20
+ getService,
21
+ registerService,
22
+ useServiceCommand,
23
+ useServiceQuery
24
+ } from "../_browser-chunks/chunk-JMC7AIKT.js";
25
+ import {
26
+ countBy,
27
+ partition
28
+ } from "../_browser-chunks/chunk-4ATQOMJB.js";
29
+ import {
30
+ isReviewManagerRoute
31
+ } from "../_browser-chunks/chunk-YI2IBIQS.js";
32
+ import "../_browser-chunks/chunk-RNTIV5CE.js";
33
+ import {
34
+ BUILT_IN_FILTERS,
35
+ Tag,
36
+ USER_TAG_FILTER,
37
+ mockChannel
38
+ } from "../_browser-chunks/chunk-CFAOWGL7.js";
39
+ import "../_browser-chunks/chunk-YTIT5NA5.js";
40
+ import {
41
+ getChannel,
42
+ setChannel
43
+ } from "../_browser-chunks/chunk-OD6IBQCC.js";
44
+ import "../_browser-chunks/chunk-QC4HFS6K.js";
45
+ import "../_browser-chunks/chunk-6SXYJQST.js";
46
+ import {
47
+ stringify
48
+ } from "../_browser-chunks/chunk-SFVA4SBT.js";
49
+ import {
50
+ require_memoizerific
51
+ } from "../_browser-chunks/chunk-DRQKCCAG.js";
52
+ import {
53
+ mapValues,
54
+ mergeWith,
55
+ omit,
56
+ pick,
57
+ toMerged
58
+ } from "../_browser-chunks/chunk-2JDQ35OA.js";
59
+ import "../_browser-chunks/chunk-IE4ULIOQ.js";
60
+ import {
61
+ isEqual
62
+ } from "../_browser-chunks/chunk-B4AUNNU4.js";
63
+ import "../_browser-chunks/chunk-NZMVUW5T.js";
64
+ import "../_browser-chunks/chunk-JWSKPMPC.js";
65
+ import "../_browser-chunks/chunk-JPUOQJUI.js";
66
+ import "../_browser-chunks/chunk-RSPAQWVJ.js";
67
+ import "../_browser-chunks/chunk-V5M7Q4HT.js";
68
+ import "../_browser-chunks/chunk-SC67XZST.js";
69
+ import {
70
+ __commonJS,
71
+ __export,
72
+ __toESM
73
+ } from "../_browser-chunks/chunk-IMSF75WX.js";
74
+
75
+ // ../../node_modules/toggle-selection/index.js
76
+ var require_toggle_selection = __commonJS({
77
+ "../../node_modules/toggle-selection/index.js"(exports, module) {
78
+ module.exports = function() {
79
+ var selection = document.getSelection();
80
+ if (!selection.rangeCount)
81
+ return function() {
82
+ };
83
+ for (var active = document.activeElement, ranges = [], i = 0; i < selection.rangeCount; i++)
84
+ ranges.push(selection.getRangeAt(i));
85
+ switch (active.tagName.toUpperCase()) {
86
+ // .toUpperCase handles XHTML
87
+ case "INPUT":
88
+ case "TEXTAREA":
89
+ active.blur();
90
+ break;
91
+ default:
92
+ active = null;
93
+ break;
94
+ }
95
+ return selection.removeAllRanges(), function() {
96
+ selection.type === "Caret" && selection.removeAllRanges(), selection.rangeCount || ranges.forEach(function(range) {
97
+ selection.addRange(range);
98
+ }), active && active.focus();
99
+ };
100
+ };
101
+ }
102
+ });
103
+
104
+ // ../../node_modules/copy-to-clipboard/index.js
105
+ var require_copy_to_clipboard = __commonJS({
106
+ "../../node_modules/copy-to-clipboard/index.js"(exports, module) {
107
+ "use strict";
108
+ var deselectCurrent = require_toggle_selection(), clipboardToIE11Formatting = {
109
+ "text/plain": "Text",
110
+ "text/html": "Url",
111
+ default: "Text"
112
+ }, defaultMessage = "Copy to clipboard: #{key}, Enter";
113
+ function format(message) {
114
+ var copyKey = (/mac os x/i.test(navigator.userAgent) ? "\u2318" : "Ctrl") + "+C";
115
+ return message.replace(/#{\s*key\s*}/g, copyKey);
116
+ }
117
+ function copy2(text, options) {
118
+ var debug, message, reselectPrevious, range, selection, mark, success = !1;
119
+ options || (options = {}), debug = options.debug || !1;
120
+ try {
121
+ reselectPrevious = deselectCurrent(), range = document.createRange(), selection = document.getSelection(), mark = document.createElement("span"), mark.textContent = text, mark.ariaHidden = "true", mark.style.all = "unset", mark.style.position = "fixed", mark.style.top = 0, mark.style.clip = "rect(0, 0, 0, 0)", mark.style.whiteSpace = "pre", mark.style.webkitUserSelect = "text", mark.style.MozUserSelect = "text", mark.style.msUserSelect = "text", mark.style.userSelect = "text", mark.addEventListener("copy", function(e) {
122
+ if (e.stopPropagation(), options.format)
123
+ if (e.preventDefault(), typeof e.clipboardData > "u") {
124
+ debug && console.warn("unable to use e.clipboardData"), debug && console.warn("trying IE specific stuff"), window.clipboardData.clearData();
125
+ var format2 = clipboardToIE11Formatting[options.format] || clipboardToIE11Formatting.default;
126
+ window.clipboardData.setData(format2, text);
127
+ } else
128
+ e.clipboardData.clearData(), e.clipboardData.setData(options.format, text);
129
+ options.onCopy && (e.preventDefault(), options.onCopy(e.clipboardData));
130
+ }), document.body.appendChild(mark), range.selectNodeContents(mark), selection.addRange(range);
131
+ var successful = document.execCommand("copy");
132
+ if (!successful)
133
+ throw new Error("copy command was unsuccessful");
134
+ success = !0;
135
+ } catch (err) {
136
+ debug && console.error("unable to copy using execCommand: ", err), debug && console.warn("trying IE specific stuff");
137
+ try {
138
+ window.clipboardData.setData(options.format || "text", text), options.onCopy && options.onCopy(window.clipboardData), success = !0;
139
+ } catch (err2) {
140
+ debug && console.error("unable to copy using clipboardData: ", err2), debug && console.error("falling back to prompt"), message = format("message" in options ? options.message : defaultMessage), window.prompt(message, text);
141
+ }
142
+ } finally {
143
+ selection && (typeof selection.removeRange == "function" ? selection.removeRange(range) : selection.removeAllRanges()), mark && document.body.removeChild(mark), reselectPrevious();
144
+ }
145
+ return success;
146
+ }
147
+ module.exports = copy2;
148
+ }
149
+ });
150
+
151
+ // ../../node_modules/store2/dist/store2.js
152
+ var require_store2 = __commonJS({
153
+ "../../node_modules/store2/dist/store2.js"(exports, module) {
154
+ (function(window2, define) {
155
+ var _ = {
156
+ version: "2.14.4",
157
+ areas: {},
158
+ apis: {},
159
+ nsdelim: ".",
160
+ // utilities
161
+ inherit: function(api, o) {
162
+ for (var p in api)
163
+ o.hasOwnProperty(p) || Object.defineProperty(o, p, Object.getOwnPropertyDescriptor(api, p));
164
+ return o;
165
+ },
166
+ stringify: function(d, fn) {
167
+ return d === void 0 || typeof d == "function" ? d + "" : JSON.stringify(d, fn || _.replace);
168
+ },
169
+ parse: function(s, fn) {
170
+ try {
171
+ return JSON.parse(s, fn || _.revive);
172
+ } catch {
173
+ return s;
174
+ }
175
+ },
176
+ // extension hooks
177
+ fn: function(name, fn) {
178
+ _.storeAPI[name] = fn;
179
+ for (var api in _.apis)
180
+ _.apis[api][name] = fn;
181
+ },
182
+ get: function(area, key) {
183
+ return area.getItem(key);
184
+ },
185
+ set: function(area, key, string) {
186
+ area.setItem(key, string);
187
+ },
188
+ remove: function(area, key) {
189
+ area.removeItem(key);
190
+ },
191
+ key: function(area, i) {
192
+ return area.key(i);
193
+ },
194
+ length: function(area) {
195
+ return area.length;
196
+ },
197
+ clear: function(area) {
198
+ area.clear();
199
+ },
200
+ // core functions
201
+ Store: function(id, area, namespace) {
202
+ var store3 = _.inherit(_.storeAPI, function(key, data, overwrite) {
203
+ return arguments.length === 0 ? store3.getAll() : typeof data == "function" ? store3.transact(key, data, overwrite) : data !== void 0 ? store3.set(key, data, overwrite) : typeof key == "string" || typeof key == "number" ? store3.get(key) : typeof key == "function" ? store3.each(key) : key ? store3.setAll(key, data) : store3.clear();
204
+ });
205
+ store3._id = id;
206
+ try {
207
+ var testKey = "__store2_test";
208
+ area.setItem(testKey, "ok"), store3._area = area, area.removeItem(testKey);
209
+ } catch {
210
+ store3._area = _.storage("fake");
211
+ }
212
+ return store3._ns = namespace || "", _.areas[id] || (_.areas[id] = store3._area), _.apis[store3._ns + store3._id] || (_.apis[store3._ns + store3._id] = store3), store3;
213
+ },
214
+ storeAPI: {
215
+ // admin functions
216
+ area: function(id, area) {
217
+ var store3 = this[id];
218
+ return (!store3 || !store3.area) && (store3 = _.Store(id, area, this._ns), this[id] || (this[id] = store3)), store3;
219
+ },
220
+ namespace: function(namespace, singleArea, delim) {
221
+ if (delim = delim || this._delim || _.nsdelim, !namespace)
222
+ return this._ns ? this._ns.substring(0, this._ns.length - delim.length) : "";
223
+ var ns = namespace, store3 = this[ns];
224
+ if ((!store3 || !store3.namespace) && (store3 = _.Store(this._id, this._area, this._ns + ns + delim), store3._delim = delim, this[ns] || (this[ns] = store3), !singleArea))
225
+ for (var name in _.areas)
226
+ store3.area(name, _.areas[name]);
227
+ return store3;
228
+ },
229
+ isFake: function(force) {
230
+ return force ? (this._real = this._area, this._area = _.storage("fake")) : force === !1 && (this._area = this._real || this._area), this._area.name === "fake";
231
+ },
232
+ toString: function() {
233
+ return "store" + (this._ns ? "." + this.namespace() : "") + "[" + this._id + "]";
234
+ },
235
+ // storage functions
236
+ has: function(key) {
237
+ return this._area.has ? this._area.has(this._in(key)) : this._in(key) in this._area;
238
+ },
239
+ size: function() {
240
+ return this.keys().length;
241
+ },
242
+ each: function(fn, fill) {
243
+ for (var i = 0, m = _.length(this._area); i < m; i++) {
244
+ var key = this._out(_.key(this._area, i));
245
+ if (key !== void 0 && fn.call(this, key, this.get(key), fill) === !1)
246
+ break;
247
+ m > _.length(this._area) && (m--, i--);
248
+ }
249
+ return fill || this;
250
+ },
251
+ keys: function(fillList) {
252
+ return this.each(function(k, v, list) {
253
+ list.push(k);
254
+ }, fillList || []);
255
+ },
256
+ get: function(key, alt) {
257
+ var s = _.get(this._area, this._in(key)), fn;
258
+ return typeof alt == "function" && (fn = alt, alt = null), s !== null ? _.parse(s, fn) : alt ?? s;
259
+ },
260
+ getAll: function(fillObj) {
261
+ return this.each(function(k, v, all) {
262
+ all[k] = v;
263
+ }, fillObj || {});
264
+ },
265
+ transact: function(key, fn, alt) {
266
+ var val = this.get(key, alt), ret = fn(val);
267
+ return this.set(key, ret === void 0 ? val : ret), this;
268
+ },
269
+ set: function(key, data, overwrite) {
270
+ var d = this.get(key), replacer;
271
+ return d != null && overwrite === !1 ? data : (typeof overwrite == "function" && (replacer = overwrite, overwrite = void 0), _.set(this._area, this._in(key), _.stringify(data, replacer), overwrite) || d);
272
+ },
273
+ setAll: function(data, overwrite) {
274
+ var changed, val;
275
+ for (var key in data)
276
+ val = data[key], this.set(key, val, overwrite) !== val && (changed = !0);
277
+ return changed;
278
+ },
279
+ add: function(key, data, replacer) {
280
+ var d = this.get(key);
281
+ if (d instanceof Array)
282
+ data = d.concat(data);
283
+ else if (d !== null) {
284
+ var type = typeof d;
285
+ if (type === typeof data && type === "object") {
286
+ for (var k in data)
287
+ d[k] = data[k];
288
+ data = d;
289
+ } else
290
+ data = d + data;
291
+ }
292
+ return _.set(this._area, this._in(key), _.stringify(data, replacer)), data;
293
+ },
294
+ remove: function(key, alt) {
295
+ var d = this.get(key, alt);
296
+ return _.remove(this._area, this._in(key)), d;
297
+ },
298
+ clear: function() {
299
+ return this._ns ? this.each(function(k) {
300
+ _.remove(this._area, this._in(k));
301
+ }, 1) : _.clear(this._area), this;
302
+ },
303
+ clearAll: function() {
304
+ var area = this._area;
305
+ for (var id in _.areas)
306
+ _.areas.hasOwnProperty(id) && (this._area = _.areas[id], this.clear());
307
+ return this._area = area, this;
308
+ },
309
+ // internal use functions
310
+ _in: function(k) {
311
+ return typeof k != "string" && (k = _.stringify(k)), this._ns ? this._ns + k : k;
312
+ },
313
+ _out: function(k) {
314
+ return this._ns ? k && k.indexOf(this._ns) === 0 ? k.substring(this._ns.length) : void 0 : (
315
+ // so each() knows to skip it
316
+ k
317
+ );
318
+ }
319
+ },
320
+ // end _.storeAPI
321
+ storage: function(name) {
322
+ return _.inherit(_.storageAPI, { items: {}, name });
323
+ },
324
+ storageAPI: {
325
+ length: 0,
326
+ has: function(k) {
327
+ return this.items.hasOwnProperty(k);
328
+ },
329
+ key: function(i) {
330
+ var c = 0;
331
+ for (var k in this.items)
332
+ if (this.has(k) && i === c++)
333
+ return k;
334
+ },
335
+ setItem: function(k, v) {
336
+ this.has(k) || this.length++, this.items[k] = v;
337
+ },
338
+ removeItem: function(k) {
339
+ this.has(k) && (delete this.items[k], this.length--);
340
+ },
341
+ getItem: function(k) {
342
+ return this.has(k) ? this.items[k] : null;
343
+ },
344
+ clear: function() {
345
+ for (var k in this.items)
346
+ this.removeItem(k);
347
+ }
348
+ }
349
+ // end _.storageAPI
350
+ }, store2 = (
351
+ // safely set this up (throws error in IE10/32bit mode for local files)
352
+ _.Store("local", (function() {
353
+ try {
354
+ return localStorage;
355
+ } catch {
356
+ }
357
+ })())
358
+ );
359
+ store2.local = store2, store2._ = _, store2.area("session", (function() {
360
+ try {
361
+ return sessionStorage;
362
+ } catch {
363
+ }
364
+ })()), store2.area("page", _.storage("page")), typeof define == "function" && define.amd !== void 0 ? define("store2", [], function() {
365
+ return store2;
366
+ }) : typeof module < "u" && module.exports ? module.exports = store2 : (window2.store && (_.conflict = window2.store), window2.store = store2);
367
+ })(exports, exports && exports.define);
368
+ }
369
+ });
370
+
371
+ // src/manager-api/root.tsx
372
+ import React2, {
373
+ Component,
374
+ Fragment,
375
+ useCallback as useCallback2,
376
+ useContext,
377
+ useEffect,
378
+ useMemo,
379
+ useRef as useRef2,
380
+ useState
381
+ } from "react";
382
+ import {
383
+ DOCS_PREPARED as DOCS_PREPARED2,
384
+ SET_STORIES as SET_STORIES2,
385
+ SHARED_STATE_CHANGED,
386
+ SHARED_STATE_SET,
387
+ STORY_CHANGED as STORY_CHANGED2,
388
+ STORY_PREPARED as STORY_PREPARED2
389
+ } from "@aussieljk/forkbook/internal/core-events";
390
+
391
+ // src/manager-api/context.ts
392
+ import { createContext as ReactCreateContext } from "react";
393
+ var createContext = ({ api, state }) => ReactCreateContext({ api, state });
394
+
395
+ // src/manager-api/lib/merge.ts
396
+ import { logger } from "@aussieljk/forkbook/internal/client-logger";
397
+ var merge_default = (a, ...b) => {
398
+ let target = {};
399
+ target = mergeWith(
400
+ {},
401
+ a,
402
+ (objValue, srcValue) => {
403
+ if (Array.isArray(srcValue) && Array.isArray(objValue))
404
+ return srcValue.forEach((s) => {
405
+ objValue.find((o) => o === s || isEqual(o, s)) || objValue.push(s);
406
+ }), objValue;
407
+ if (Array.isArray(objValue))
408
+ return logger.log(["the types mismatch, picking", objValue]), objValue;
409
+ }
410
+ );
411
+ for (let obj of b)
412
+ target = mergeWith(target, obj, (objValue, srcValue) => {
413
+ if (Array.isArray(srcValue) && Array.isArray(objValue))
414
+ return srcValue.forEach((s) => {
415
+ objValue.find((o) => o === s || isEqual(o, s)) || objValue.push(s);
416
+ }), objValue;
417
+ if (Array.isArray(objValue))
418
+ return logger.log(["the types mismatch, picking", objValue]), objValue;
419
+ });
420
+ return target;
421
+ }, noArrayMerge = (a, ...b) => {
422
+ let target = {};
423
+ target = mergeWith(
424
+ {},
425
+ a,
426
+ (objValue, srcValue) => {
427
+ if (Array.isArray(srcValue))
428
+ return srcValue;
429
+ }
430
+ );
431
+ for (let obj of b)
432
+ target = mergeWith(target, obj, (objValue, srcValue) => {
433
+ if (Array.isArray(srcValue))
434
+ return srcValue;
435
+ });
436
+ return target;
437
+ };
438
+
439
+ // src/manager-api/initial-state.ts
440
+ var main = (...additions) => additions.reduce((acc, item) => merge_default(acc, item), {}), initial_state_default = main;
441
+
442
+ // src/manager-api/lib/addons.ts
443
+ import { logger as logger2 } from "@aussieljk/forkbook/internal/client-logger";
444
+ import { SET_CONFIG } from "@aussieljk/forkbook/internal/core-events";
445
+ import { Addon_TypesEnum } from "@aussieljk/forkbook/internal/types";
446
+ var AddonStore = class {
447
+ constructor() {
448
+ this.loaders = {};
449
+ this.elements = {};
450
+ this.config = {};
451
+ this.getChannel = () => {
452
+ if (this.channel)
453
+ return this.channel;
454
+ let installed = getChannel();
455
+ return installed ? (this.channel = installed, this.resolve(), this.channel) : mockChannel();
456
+ };
457
+ this.ready = () => this.promise;
458
+ this.hasChannel = () => !!this.channel || !!getChannel();
459
+ this.setChannel = (channel) => {
460
+ this.channel = channel, setChannel(channel), this.resolve();
461
+ };
462
+ this.setConfig = (value) => {
463
+ Object.assign(this.config, value), this.hasChannel() ? this.getChannel().emit(SET_CONFIG, this.config) : this.ready().then((channel) => {
464
+ channel.emit(SET_CONFIG, this.config);
465
+ });
466
+ };
467
+ this.getConfig = () => this.config;
468
+ /**
469
+ * Registers an addon loader function.
470
+ *
471
+ * @param {string} id - The id of the addon loader.
472
+ * @param {(api: API) => void} callback - The function that will be called to register the addon.
473
+ * @returns {void}
474
+ */
475
+ this.register = (id, callback) => {
476
+ this.loaders[id] && logger2.warn(`${id} was loaded twice, this could have bad side-effects`), this.loaders[id] = callback;
477
+ };
478
+ this.loadAddons = (api) => {
479
+ Object.values(this.loaders).forEach((value) => value(api));
480
+ };
481
+ this.promise = new Promise((res) => {
482
+ this.resolve = () => res(this.getChannel());
483
+ });
484
+ }
485
+ getElements(type) {
486
+ return this.elements[type] || (this.elements[type] = {}), this.elements[type];
487
+ }
488
+ /**
489
+ * Adds an addon to the addon store.
490
+ *
491
+ * @param {string} id - The id of the addon.
492
+ * @param {Addon_Type} addon - The addon to add.
493
+ * @returns {void}
494
+ */
495
+ add(id, addon) {
496
+ let { type } = addon, collection = this.getElements(type);
497
+ collection[id] = { ...addon, id };
498
+ }
499
+ experimental_getRegisteredAddons(type) {
500
+ return Object.keys(type ? this.getElements(type) : this.loaders);
501
+ }
502
+ }, KEY = "__STORYBOOK_ADDONS_MANAGER";
503
+ function getAddonsStore() {
504
+ return globalThis[KEY] || (globalThis[KEY] = new AddonStore()), globalThis[KEY];
505
+ }
506
+ var addons = getAddonsStore();
507
+
508
+ // src/manager-api/modules/addons.ts
509
+ var addons_exports = {};
510
+ __export(addons_exports, {
511
+ ensurePanel: () => ensurePanel,
512
+ init: () => init
513
+ });
514
+ import { logger as logger3 } from "@aussieljk/forkbook/internal/client-logger";
515
+ import { Addon_TypesEnum as Addon_TypesEnum2 } from "@aussieljk/forkbook/internal/types";
516
+ function ensurePanel(panels, selectedPanel, currentPanel) {
517
+ let keys2 = Object.keys(panels ?? {});
518
+ return keys2.indexOf(selectedPanel) >= 0 ? selectedPanel : keys2.length ? keys2[0] : currentPanel;
519
+ }
520
+ var init = ({ provider, store: store2, fullAPI }) => {
521
+ let api = {
522
+ getElements: (type) => provider.getElements(type),
523
+ clearStatuses: () => {
524
+ let testProviders = api.getElements(Addon_TypesEnum2.experimental_TEST_PROVIDER);
525
+ Object.values(testProviders).forEach((testProvider) => {
526
+ try {
527
+ testProvider.clear?.();
528
+ } catch (e) {
529
+ try {
530
+ logger3.warn(`Failed to clear test provider "${testProvider.id}":`, e);
531
+ } catch {
532
+ }
533
+ }
534
+ });
535
+ },
536
+ getSelectedPanel: () => {
537
+ let { selectedPanel } = store2.getState();
538
+ return ensurePanel(api.getElements(Addon_TypesEnum2.PANEL), selectedPanel, selectedPanel);
539
+ },
540
+ setSelectedPanel: (panelName) => {
541
+ store2.setState({ selectedPanel: panelName }, { persistence: "session" });
542
+ },
543
+ setAddonState(addonId, newStateOrMerger, options) {
544
+ let merger = typeof newStateOrMerger == "function" ? newStateOrMerger : () => newStateOrMerger;
545
+ return store2.setState(
546
+ (s) => ({ ...s, addons: { ...s.addons, [addonId]: merger(s.addons[addonId]) } }),
547
+ options
548
+ ).then(() => api.getAddonState(addonId));
549
+ },
550
+ getAddonState: (addonId) => store2.getState().addons[addonId] || globalThis?.FORKBOOK_ADDON_STATE[addonId]
551
+ };
552
+ return {
553
+ api,
554
+ state: {
555
+ selectedPanel: ensurePanel(
556
+ api.getElements(Addon_TypesEnum2.PANEL),
557
+ store2.getState().selectedPanel
558
+ ),
559
+ addons: {}
560
+ }
561
+ };
562
+ };
563
+
564
+ // src/manager-api/modules/channel.ts
565
+ var channel_exports = {};
566
+ __export(channel_exports, {
567
+ init: () => init2
568
+ });
569
+ var init2 = ({ provider }) => ({ api: {
570
+ getChannel: () => provider.channel,
571
+ on: (type, handler) => (provider.channel?.on(type, handler), () => provider.channel?.off(type, handler)),
572
+ off: (type, handler) => provider.channel?.off(type, handler),
573
+ once: (type, handler) => provider.channel?.once(type, handler),
574
+ emit: (type, data, ...args) => {
575
+ data?.options?.target && data.options.target !== "storybook-preview-iframe" && !data.options.target.startsWith("storybook-ref-") && (data.options.target = data.options.target !== "storybook_internal" ? `storybook-ref-${data.options.target}` : "storybook-preview-iframe"), provider.channel?.emit(type, data, ...args);
576
+ }
577
+ }, state: {} });
578
+
579
+ // src/manager-api/modules/globals.ts
580
+ var globals_exports = {};
581
+ __export(globals_exports, {
582
+ init: () => init4
583
+ });
584
+ import { logger as logger5 } from "@aussieljk/forkbook/internal/client-logger";
585
+ import {
586
+ GLOBALS_UPDATED,
587
+ SET_GLOBALS,
588
+ UPDATE_GLOBALS
589
+ } from "@aussieljk/forkbook/internal/core-events";
590
+
591
+ // src/manager-api/lib/events.ts
592
+ import { logger as logger4 } from "@aussieljk/forkbook/internal/client-logger";
593
+
594
+ // src/manager-api/modules/refs.ts
595
+ var refs_exports = {};
596
+ __export(refs_exports, {
597
+ defaultStoryMapper: () => defaultStoryMapper,
598
+ getSourceType: () => getSourceType,
599
+ init: () => init3
600
+ });
601
+ import { global } from "@storybook/global";
602
+ import { dedent as dedent2 } from "ts-dedent";
603
+
604
+ // src/manager-api/lib/stories.ts
605
+ import { sanitize } from "@aussieljk/forkbook/internal/csf";
606
+ var import_memoizerific = __toESM(require_memoizerific(), 1);
607
+ import { dedent } from "ts-dedent";
608
+
609
+ // src/manager-api/lib/intersect.ts
610
+ var intersect_default = (a, b) => !Array.isArray(a) || !Array.isArray(b) || !a.length || !b.length ? [] : a.reduce((acc, aValue) => (b.includes(aValue) && acc.push(aValue), acc), []);
611
+
612
+ // src/manager-api/lib/stories.ts
613
+ var TITLE_PATH_SEPARATOR = /\s*\/\s*/, denormalizeStoryParameters = ({
614
+ globalParameters,
615
+ kindParameters,
616
+ stories
617
+ }) => mapValues(stories, (storyData) => ({
618
+ ...storyData,
619
+ parameters: combineParameters(
620
+ globalParameters,
621
+ kindParameters[storyData.kind],
622
+ storyData.parameters
623
+ )
624
+ })), transformSetStoriesStoryDataToPreparedStoryIndex = (stories) => ({ v: 5, entries: Object.entries(stories).reduce(
625
+ (acc, [id, story]) => {
626
+ if (!story)
627
+ return acc;
628
+ let { docsOnly, fileName, ...parameters } = story.parameters, base = {
629
+ title: story.kind,
630
+ id,
631
+ name: story.name,
632
+ importPath: fileName
633
+ };
634
+ if (docsOnly)
635
+ acc[id] = {
636
+ type: "docs",
637
+ tags: ["stories-mdx"],
638
+ storiesImports: [],
639
+ ...base
640
+ };
641
+ else {
642
+ let { argTypes, args, initialArgs } = story;
643
+ acc[id] = {
644
+ type: "story",
645
+ subtype: "story",
646
+ ...base,
647
+ parameters,
648
+ argTypes,
649
+ args,
650
+ initialArgs
651
+ };
652
+ }
653
+ return acc;
654
+ },
655
+ {}
656
+ ) }), transformStoryIndexV2toV3 = (index) => ({
657
+ v: 3,
658
+ stories: Object.values(index.stories).reduce(
659
+ (acc, entry) => (acc[entry.id] = {
660
+ ...entry,
661
+ title: entry.kind,
662
+ name: entry.name || entry.story,
663
+ importPath: entry.parameters.fileName || ""
664
+ }, acc),
665
+ {}
666
+ )
667
+ }), transformStoryIndexV3toV4 = (index) => {
668
+ let countByTitle = countBy(Object.values(index.stories), (item) => item.title);
669
+ return {
670
+ v: 4,
671
+ entries: Object.values(index.stories).reduce(
672
+ (acc, entry) => {
673
+ let type = "story";
674
+ return (entry.parameters?.docsOnly || entry.name === "Page" && countByTitle[entry.title] === 1) && (type = "docs"), acc[entry.id] = {
675
+ type,
676
+ ...type === "docs" && { tags: ["stories-mdx"], storiesImports: [] },
677
+ ...entry
678
+ }, delete acc[entry.id].story, delete acc[entry.id].kind, acc;
679
+ },
680
+ {}
681
+ )
682
+ };
683
+ }, transformStoryIndexV4toV5 = (index) => ({
684
+ v: 5,
685
+ entries: Object.values(index.entries).reduce(
686
+ (acc, entry) => (acc[entry.id] = {
687
+ ...entry,
688
+ tags: entry.tags ? [Tag.DEV, Tag.TEST, ...entry.tags] : [Tag.DEV]
689
+ }, acc),
690
+ {}
691
+ )
692
+ }), transformStoryIndexToStoriesHash = (input, { provider, docsOptions, filters, allStatuses, statusFilterKey }) => {
693
+ if (!input.v)
694
+ throw new Error("Composition: Missing stories.json version");
695
+ let index = input;
696
+ index = index.v === 2 ? transformStoryIndexV2toV3(index) : index, index = index.v === 3 ? transformStoryIndexV3toV4(index) : index, index = index.v === 4 ? transformStoryIndexV4toV5(index) : index, index = index;
697
+ let indexEntries = Object.values(index.entries), filterFunctions = Object.values(filters), statusFilterFn = statusFilterKey ? filters[statusFilterKey] : void 0, entryValues = indexEntries.filter((entry) => {
698
+ let statuses = allStatuses[entry.id] ?? {};
699
+ return statusFilterFn && !statusFilterFn({ ...entry, statuses }) && !indexEntries.filter((item) => "parent" in item && item.parent === entry.id).some(
700
+ (child) => statusFilterFn({ ...child, statuses: allStatuses[child.id] ?? {} })
701
+ ) ? !1 : Object.values(statuses).some(({ value }) => value === "status-value:error") || filterFunctions.every((fn) => fn({ ...entry, statuses })) ? !0 : indexEntries.filter((item) => "parent" in item && item.parent === entry.id).some((child) => filterFunctions.every((fn) => fn({ ...child, statuses })));
702
+ }), { sidebar = {} } = provider.getConfig(), { showRoots, collapsedRoots = [], renderAriaLabel, renderLabel } = sidebar, setShowRoots = typeof showRoots < "u", storiesHashOutOfOrder = entryValues.reduce((acc, item) => {
703
+ if (docsOptions.docsMode && item.type !== "docs")
704
+ return acc;
705
+ let { title } = item, groups = title.trim().split(TITLE_PATH_SEPARATOR), root = (!setShowRoots || showRoots) && groups.length > 1 ? [groups.shift()] : [], names = [...root, ...groups], paths = names.reduce((list, name, idx) => {
706
+ let parent = idx > 0 && list[idx - 1], id = sanitize(parent ? `${parent}-${name}` : name);
707
+ if (name.trim() === "")
708
+ throw new Error(dedent`Invalid title ${title} ending in slash.`);
709
+ if (parent === id)
710
+ throw new Error(
711
+ dedent`
712
+ Invalid part '${name}', leading to id === parentId ('${id}'), inside title '${title}'
713
+
714
+ Did you create a path that uses the separator char accidentally, such as 'Vue <docs/>' where '/' is a separator char? See https://github.com/storybookjs/storybook/issues/6128
715
+ `
716
+ );
717
+ return list.push(id), list;
718
+ }, []);
719
+ return paths.forEach((id, idx) => {
720
+ let childId = paths[idx + 1] || item.id;
721
+ root.length && idx === 0 ? acc[id] = merge_default(acc[id] || {}, {
722
+ type: "root",
723
+ id,
724
+ name: names[idx],
725
+ tags: [],
726
+ depth: idx,
727
+ renderAriaLabel,
728
+ renderLabel,
729
+ startCollapsed: collapsedRoots.includes(id),
730
+ // Note that this will later get appended to the previous list of children (see below)
731
+ children: [childId]
732
+ }) : (!acc[id] || acc[id].type === "component") && idx === paths.length - 1 ? acc[id] = merge_default(acc[id] || {}, {
733
+ type: "component",
734
+ id,
735
+ name: names[idx],
736
+ tags: [],
737
+ parent: paths[idx - 1],
738
+ depth: idx,
739
+ renderAriaLabel,
740
+ renderLabel,
741
+ ...childId && {
742
+ children: [childId]
743
+ }
744
+ }) : acc[id] = merge_default(acc[id] || {}, {
745
+ type: "group",
746
+ id,
747
+ name: names[idx],
748
+ tags: [],
749
+ parent: paths[idx - 1],
750
+ depth: idx,
751
+ renderAriaLabel,
752
+ renderLabel,
753
+ ...childId && {
754
+ children: [childId]
755
+ }
756
+ });
757
+ }), acc[item.id] = {
758
+ tags: [],
759
+ ...item,
760
+ depth: paths.length,
761
+ parent: "parent" in item ? item.parent : paths[paths.length - 1],
762
+ renderAriaLabel,
763
+ renderLabel,
764
+ prepared: !!item.parameters
765
+ }, acc;
766
+ }, {});
767
+ function addItem(acc, item) {
768
+ if (acc[item.id] || (acc[item.id] = item, "children" in item && item.children && (item.children.forEach((childId) => addItem(acc, storiesHashOutOfOrder[childId])), item.tags = item.children.reduce((currentTags, childId) => currentTags === null ? acc[childId].tags : intersect_default(currentTags, acc[childId].tags), null) || [])), item.type === "component") {
769
+ let firstChild = acc[item.children[0]];
770
+ firstChild && "importPath" in firstChild && (item.importPath = firstChild.importPath);
771
+ }
772
+ return acc;
773
+ }
774
+ let storiesHash = Object.values(storiesHashOutOfOrder).filter((i) => i.type !== "root" && !i.parent).reduce((acc, item) => addItem(acc, item), {});
775
+ return storiesHash = Object.values(storiesHashOutOfOrder).filter((i) => i.type === "root").reduce(addItem, storiesHash), storiesHash = Object.values(storiesHash).reduce((acc, item) => {
776
+ if (item.type === "story" && item.subtype === "test") {
777
+ let story = acc[item.parent], component = acc[story.parent];
778
+ acc[component.id] = {
779
+ ...component,
780
+ // Remove test from the component node as it will be attached to the story node instead
781
+ children: component.children && component.children.filter((id) => id !== item.id)
782
+ }, acc[story.id] = {
783
+ ...story,
784
+ // Add test to the story node
785
+ children: (story.children || []).concat(item.id)
786
+ }, acc[item.id] = {
787
+ ...item,
788
+ depth: item.depth + 1
789
+ };
790
+ } else
791
+ acc[item.id] = item;
792
+ return acc;
793
+ }, {}), storiesHash;
794
+ }, addPreparedStories = (newHash, oldHash) => oldHash ? Object.fromEntries(
795
+ Object.entries(newHash).map(([id, newEntry]) => {
796
+ let oldEntry = oldHash[id];
797
+ return newEntry.type === "story" && oldEntry?.type === "story" && oldEntry.prepared ? ("children" in oldEntry && delete oldEntry.children, [id, { ...oldEntry, ...newEntry, prepared: !0 }]) : [id, newEntry];
798
+ })
799
+ ) : newHash, getComponentLookupList = (0, import_memoizerific.default)(1)((hash) => Object.entries(hash).reduce((acc, i) => {
800
+ let value = i[1];
801
+ return value.type === "component" && acc.push([...value.children]), acc;
802
+ }, [])), getStoriesLookupList = (0, import_memoizerific.default)(1)((hash) => Object.keys(hash).filter((k) => ["story", "docs"].includes(hash[k].type)));
803
+
804
+ // src/manager-api/modules/refs.ts
805
+ var { location, fetch } = global, getSourceType = (source, refId) => {
806
+ let { origin: localOrigin, pathname: localPathname } = location, { origin: sourceOrigin, pathname: sourcePathname } = new URL(source), localFull = `${localOrigin + localPathname}`.replace(/\/[^\/]*$/, ""), sourceFull = `${sourceOrigin + sourcePathname}`.replace(/\/[^\/]*$/, "");
807
+ return localFull === sourceFull ? ["local", sourceFull] : refId || source ? ["external", sourceFull] : [null, null];
808
+ }, defaultStoryMapper = (b, a) => ({ ...a, kind: a.kind.replace("|", "/") }), addRefIds = (input, ref) => Object.entries(input).reduce((acc, [id, item]) => ({ ...acc, [id]: { ...item, refId: ref.id } }), {}), applyRefStoryUpdates = (index, storyUpdates) => (storyUpdates && Object.entries(storyUpdates).forEach(([id, update2]) => {
809
+ let entry = index[id];
810
+ entry && (entry.type === "story" || entry.type === "docs") && (index[id] = { ...entry, ...update2 });
811
+ }), index);
812
+ async function handleRequest(request) {
813
+ if (!request)
814
+ return {};
815
+ try {
816
+ let response = await request;
817
+ if (response === !1 || response === !0)
818
+ throw new Error("Unexpected boolean response");
819
+ if (!response.ok) {
820
+ if (response.status === 401)
821
+ try {
822
+ let json2 = await response.json();
823
+ if (json2.loginUrl)
824
+ return { loginUrl: json2.loginUrl };
825
+ } catch {
826
+ }
827
+ throw new Error(`Unexpected response not OK: ${response.statusText}`);
828
+ }
829
+ let json = await response.json();
830
+ return json.entries || json.stories ? { storyIndex: json } : json;
831
+ } catch (err) {
832
+ return { indexError: err };
833
+ }
834
+ }
835
+ var parseUrl = (url) => {
836
+ let credentialsRegex = /https?:\/\/(.+:.+)@/, cleanUrl = url, authorization, [, credentials] = url.match(credentialsRegex) || [];
837
+ return credentials && (cleanUrl = url.replace(`${credentials}@`, ""), authorization = btoa(`${credentials}`)), {
838
+ url: cleanUrl,
839
+ authorization
840
+ };
841
+ }, getRedirectedRefUrl = (refUrl, indexResponseUrl) => {
842
+ if (!indexResponseUrl)
843
+ return refUrl;
844
+ let served = new URL(indexResponseUrl);
845
+ return served.origin === new URL(refUrl, location.href).origin || !served.pathname.endsWith("/index.json") ? refUrl : served.origin + served.pathname.slice(0, -11);
846
+ }, map = (input, ref, options) => {
847
+ let { storyMapper } = options;
848
+ return storyMapper ? Object.entries(input).reduce((acc, [id, item]) => ({ ...acc, [id]: storyMapper(ref, item) }), {}) : input;
849
+ }, init3 = ({ store: store2, provider, singleStory, docsOptions = {} }, { runCheck = !0 } = {}) => {
850
+ let api = {
851
+ findRef: (source) => {
852
+ let refs2 = api.getRefs();
853
+ return Object.values(refs2).find(({ url }) => url.match(source));
854
+ },
855
+ changeRefVersion: async (id, url) => {
856
+ let { versions, title } = api.getRefs()[id], ref = {
857
+ id,
858
+ url,
859
+ versions,
860
+ title,
861
+ index: {},
862
+ filteredIndex: {},
863
+ expanded: !0
864
+ };
865
+ await api.setRef(id, { ...ref, type: "unknown" }, !1), await api.checkRef(ref);
866
+ },
867
+ changeRefState: (id, previewInitialized) => {
868
+ let { [id]: ref, ...updated } = api.getRefs();
869
+ updated[id] = { ...ref, previewInitialized }, store2.setState({
870
+ refs: updated
871
+ });
872
+ },
873
+ checkRef: async (ref) => {
874
+ let { id, url, version: version2, type } = ref, isPublic = type === "server-checked", loadedData = {}, query = version2 ? `?version=${version2}` : "", credentials = isPublic ? "omit" : "include", urlParseResult = parseUrl(url), headers = {
875
+ Accept: "application/json"
876
+ };
877
+ urlParseResult.authorization && Object.assign(headers, {
878
+ Authorization: `Basic ${urlParseResult.authorization}`
879
+ });
880
+ let [indexRequest, storiesRequest] = ["index.json", "stories.json"].map(
881
+ (file) => fetch(`${urlParseResult.url}/${file}${query}`, {
882
+ headers,
883
+ credentials
884
+ })
885
+ ), [indexResult, storiesResult] = await Promise.all([
886
+ handleRequest(indexRequest),
887
+ handleRequest(storiesRequest)
888
+ ]), refUrl = global.CONFIG_TYPE === "DEVELOPMENT" && indexResult.storyIndex ? getRedirectedRefUrl(urlParseResult.url, (await indexRequest).url) : urlParseResult.url;
889
+ if (!indexResult.indexError || !storiesResult.indexError) {
890
+ let metadata = await handleRequest(
891
+ fetch(`${urlParseResult.url}/metadata.json${query}`, {
892
+ headers,
893
+ credentials,
894
+ cache: "no-cache"
895
+ }).catch(() => !1)
896
+ );
897
+ Object.assign(loadedData, {
898
+ ...indexResult.indexError ? storiesResult : indexResult,
899
+ ...!metadata.indexError && metadata
900
+ });
901
+ } else isPublic || (loadedData.indexError = {
902
+ message: dedent2`
903
+ Error: Loading of ref failed
904
+ at fetch (lib/api/src/modules/refs.ts)
905
+
906
+ URL: ${urlParseResult.url}
907
+
908
+ We weren't able to load the above URL,
909
+ it's possible a CORS error happened.
910
+
911
+ Please check your dev-tools network tab.
912
+ `
913
+ });
914
+ let versions = ref.versions && Object.keys(ref.versions).length ? ref.versions : loadedData.versions;
915
+ await api.setRef(id, {
916
+ id,
917
+ url: refUrl,
918
+ ...loadedData,
919
+ ...versions ? { versions } : {},
920
+ type: loadedData.storyIndex ? "lazy" : "auto-inject"
921
+ });
922
+ },
923
+ getRefs: () => {
924
+ let { refs: refs2 = {} } = store2.getState();
925
+ return refs2;
926
+ },
927
+ setRef: async (id, { storyIndex, setStoriesData, ...rest }, ready = !1) => {
928
+ if (singleStory)
929
+ return;
930
+ let internal_index, index, filteredIndex, { filters } = store2.getState(), { storyMapper = defaultStoryMapper } = provider.getConfig(), ref = api.getRefs()[id];
931
+ (storyIndex || setStoriesData) && (internal_index = setStoriesData ? transformSetStoriesStoryDataToPreparedStoryIndex(
932
+ map(setStoriesData, ref, { storyMapper })
933
+ ) : storyIndex, filteredIndex = transformStoryIndexToStoriesHash(storyIndex, {
934
+ provider,
935
+ docsOptions,
936
+ filters,
937
+ allStatuses: {}
938
+ }), index = transformStoryIndexToStoriesHash(storyIndex, {
939
+ provider,
940
+ docsOptions,
941
+ filters: {},
942
+ allStatuses: {}
943
+ })), index && (index = addRefIds(index, ref), index = applyRefStoryUpdates(index, ref?.storyUpdates)), filteredIndex && (filteredIndex = addRefIds(filteredIndex, ref), filteredIndex = applyRefStoryUpdates(filteredIndex, ref?.storyUpdates)), await api.updateRef(id, { ...ref, ...rest, index, filteredIndex, internal_index });
944
+ },
945
+ updateRef: async (id, data) => {
946
+ let { [id]: ref, ...updated } = api.getRefs();
947
+ updated[id] = { ...ref, ...data };
948
+ let ordered = Object.keys(initialState).reduce((obj, key) => (obj[key] = updated[key], obj), {});
949
+ await store2.setState({
950
+ refs: ordered
951
+ });
952
+ }
953
+ }, refs = !singleStory && global.REFS || {}, initialState = refs;
954
+ return runCheck && new Promise(async (resolve) => {
955
+ for (let ref of Object.values(refs))
956
+ await api.checkRef({ ...ref, stories: {} });
957
+ resolve(void 0);
958
+ }), {
959
+ api,
960
+ state: {
961
+ refs: initialState
962
+ }
963
+ };
964
+ };
965
+
966
+ // src/manager-api/lib/events.ts
967
+ var getEventMetadata = (context, fullAPI) => {
968
+ let { source, refId, type } = context, [sourceType, sourceLocation] = getSourceType(source, refId), ref;
969
+ (refId || sourceType === "external") && (ref = refId && fullAPI.getRefs()[refId] ? fullAPI.getRefs()[refId] : fullAPI.findRef(sourceLocation));
970
+ let meta = {
971
+ source,
972
+ sourceType,
973
+ sourceLocation,
974
+ refId,
975
+ ref,
976
+ type
977
+ };
978
+ switch (!0) {
979
+ case typeof refId == "string":
980
+ case sourceType === "local":
981
+ case sourceType === "external":
982
+ return meta;
983
+ // if we couldn't find the source, something risky happened, we ignore the input, and log a warning
984
+ default:
985
+ return logger4.warn(`Received a ${type} frame that was not configured as a ref`), null;
986
+ }
987
+ };
988
+
989
+ // src/manager-api/modules/globals.ts
990
+ var init4 = ({ store: store2, fullAPI, provider }) => {
991
+ let api = {
992
+ getGlobals() {
993
+ return store2.getState().globals;
994
+ },
995
+ getUserGlobals() {
996
+ return store2.getState().userGlobals;
997
+ },
998
+ getStoryGlobals() {
999
+ return store2.getState().storyGlobals;
1000
+ },
1001
+ getGlobalTypes() {
1002
+ return store2.getState().globalTypes;
1003
+ },
1004
+ updateGlobals(newGlobals) {
1005
+ provider.channel?.emit(UPDATE_GLOBALS, {
1006
+ globals: newGlobals,
1007
+ options: {
1008
+ target: "storybook-preview-iframe"
1009
+ }
1010
+ });
1011
+ }
1012
+ }, state = {
1013
+ globals: {},
1014
+ userGlobals: {},
1015
+ storyGlobals: {},
1016
+ globalTypes: {}
1017
+ }, updateGlobals = ({
1018
+ globals,
1019
+ storyGlobals,
1020
+ userGlobals
1021
+ }) => {
1022
+ let {
1023
+ globals: currentGlobals,
1024
+ userGlobals: currentUserGlobals,
1025
+ storyGlobals: currentStoryGlobals
1026
+ } = store2.getState();
1027
+ dequal(globals, currentGlobals) || store2.setState({ globals }), dequal(userGlobals, currentUserGlobals) || store2.setState({ userGlobals }), dequal(storyGlobals, currentStoryGlobals) || store2.setState({ storyGlobals });
1028
+ };
1029
+ return provider.channel?.on(
1030
+ GLOBALS_UPDATED,
1031
+ function({ globals, storyGlobals, userGlobals }) {
1032
+ let { ref } = getEventMetadata(this, fullAPI);
1033
+ ref ? logger5.warn(
1034
+ "received a GLOBALS_UPDATED from a non-local ref. This is not currently supported."
1035
+ ) : updateGlobals({ globals, storyGlobals, userGlobals });
1036
+ }
1037
+ ), provider.channel?.on(
1038
+ SET_GLOBALS,
1039
+ function({ globals, globalTypes }) {
1040
+ let { ref } = getEventMetadata(this, fullAPI), currentUserGlobals = store2.getState()?.userGlobals;
1041
+ ref ? Object.keys(globals).length > 0 && logger5.warn("received globals from a non-local ref. This is not currently supported.") : store2.setState({ globals, userGlobals: globals, globalTypes }), currentUserGlobals && Object.keys(currentUserGlobals).length !== 0 && !dequal(globals, currentUserGlobals) && api.updateGlobals(currentUserGlobals);
1042
+ }
1043
+ ), {
1044
+ api,
1045
+ state
1046
+ };
1047
+ };
1048
+
1049
+ // src/manager-api/modules/layout.ts
1050
+ var layout_exports = {};
1051
+ __export(layout_exports, {
1052
+ ActiveTabs: () => ActiveTabs,
1053
+ DEFAULT_BOTTOM_PANEL_HEIGHT: () => DEFAULT_BOTTOM_PANEL_HEIGHT,
1054
+ DEFAULT_NAV_SIZE: () => DEFAULT_NAV_SIZE,
1055
+ DEFAULT_RIGHT_PANEL_WIDTH: () => DEFAULT_RIGHT_PANEL_WIDTH,
1056
+ focusableUIElements: () => focusableUIElements,
1057
+ getDefaultLayoutState: () => getDefaultLayoutState,
1058
+ init: () => init5,
1059
+ isDesktopViewport: () => isDesktopViewport,
1060
+ isPagesViewMode: () => isPagesViewMode
1061
+ });
1062
+ import { SET_CONFIG as SET_CONFIG2 } from "@aussieljk/forkbook/internal/core-events";
1063
+ import { global as global2 } from "@storybook/global";
1064
+ import { create } from "@aussieljk/forkbook/theming/create";
1065
+ var { document: document2 } = global2, isFunction = (val) => typeof val == "function", ActiveTabs = {
1066
+ SIDEBAR: "sidebar",
1067
+ CANVAS: "canvas",
1068
+ ADDONS: "addons"
1069
+ }, isPagesViewMode = (viewMode) => viewMode !== void 0 && viewMode !== "story" && viewMode !== "docs" && viewMode !== "review", DEFAULT_NAV_SIZE = 300, DEFAULT_BOTTOM_PANEL_HEIGHT = 300, DEFAULT_RIGHT_PANEL_WIDTH = 400, getDefaultLayoutState = () => ({
1070
+ ui: {
1071
+ enableShortcuts: !0
1072
+ },
1073
+ layout: {
1074
+ initialActive: ActiveTabs.CANVAS,
1075
+ navSize: DEFAULT_NAV_SIZE,
1076
+ bottomPanelHeight: DEFAULT_BOTTOM_PANEL_HEIGHT,
1077
+ rightPanelWidth: DEFAULT_RIGHT_PANEL_WIDTH,
1078
+ recentVisibleSizes: {
1079
+ navSize: DEFAULT_NAV_SIZE,
1080
+ bottomPanelHeight: DEFAULT_BOTTOM_PANEL_HEIGHT,
1081
+ rightPanelWidth: DEFAULT_RIGHT_PANEL_WIDTH
1082
+ },
1083
+ panelPosition: "bottom",
1084
+ showNav: !0,
1085
+ showPanel: !0,
1086
+ showToolbar: !0,
1087
+ showMobileNavigation: !1
1088
+ },
1089
+ layoutCustomisations: {
1090
+ showPanel: void 0,
1091
+ showSidebar: void 0,
1092
+ showToolbar: void 0
1093
+ },
1094
+ selectedPanel: void 0,
1095
+ theme: create()
1096
+ }), focusableUIElements = {
1097
+ addonPanel: "storybook-panel-region",
1098
+ storySearchField: "storybook-explorer-searchfield",
1099
+ storyListMenu: "storybook-explorer-menu",
1100
+ storyPanelRoot: "storybook-panel-root",
1101
+ showAddonPanel: "storybook-show-addon-panel",
1102
+ sidebarRegion: "storybook-sidebar-region",
1103
+ showSidebar: "storybook-show-sidebar"
1104
+ }, getIsNavShown = (state) => state.layout.navSize > 0, getIsPanelShown = (state) => {
1105
+ let { bottomPanelHeight, rightPanelWidth, panelPosition } = state.layout;
1106
+ return panelPosition === "bottom" && bottomPanelHeight > 0 || panelPosition === "right" && rightPanelWidth > 0;
1107
+ }, getIsFullscreen = (state) => !getIsNavShown(state) && !getIsPanelShown(state), getRecentVisibleSizes = (layoutState) => ({
1108
+ navSize: layoutState.navSize > 0 ? layoutState.navSize : layoutState.recentVisibleSizes.navSize,
1109
+ bottomPanelHeight: layoutState.bottomPanelHeight > 0 ? layoutState.bottomPanelHeight : layoutState.recentVisibleSizes.bottomPanelHeight,
1110
+ rightPanelWidth: layoutState.rightPanelWidth > 0 ? layoutState.rightPanelWidth : layoutState.recentVisibleSizes.rightPanelWidth
1111
+ }), applyLayoutOptions = (layoutState, options, singleStory) => {
1112
+ let { showPanel, showNav } = options ?? {}, layoutKeys = Object.keys(layoutState), nextLayoutState = toMerged(layoutState, pick(options ?? {}, layoutKeys));
1113
+ return showNav === !1 || singleStory ? (nextLayoutState.recentVisibleSizes = getRecentVisibleSizes(nextLayoutState), nextLayoutState.navSize = 0) : showNav === !0 && (nextLayoutState.navSize = nextLayoutState.recentVisibleSizes.navSize), showPanel === !1 ? (nextLayoutState.recentVisibleSizes = getRecentVisibleSizes(nextLayoutState), nextLayoutState.bottomPanelHeight = 0, nextLayoutState.rightPanelWidth = 0) : showPanel === !0 && (nextLayoutState.bottomPanelHeight = nextLayoutState.recentVisibleSizes.bottomPanelHeight, nextLayoutState.rightPanelWidth = nextLayoutState.recentVisibleSizes.rightPanelWidth), nextLayoutState;
1114
+ }, applyUiOptions = (uiState, options) => {
1115
+ let uiKeys = Object.keys(uiState);
1116
+ return toMerged(uiState, pick(options ?? {}, uiKeys));
1117
+ }, isDesktopViewport = () => global2.matchMedia?.("(min-width: 600px)")?.matches ?? !0, init5 = ({ store: store2, provider, singleStory }) => {
1118
+ let api = {
1119
+ toggleFullscreen(nextState) {
1120
+ return store2.setState(
1121
+ (state) => {
1122
+ let isFullscreen = getIsFullscreen(state), shouldFullscreen = typeof nextState == "boolean" ? nextState : !isFullscreen;
1123
+ return shouldFullscreen === isFullscreen ? { layout: state.layout } : shouldFullscreen ? {
1124
+ layout: {
1125
+ ...state.layout,
1126
+ navSize: 0,
1127
+ bottomPanelHeight: 0,
1128
+ rightPanelWidth: 0,
1129
+ recentVisibleSizes: getRecentVisibleSizes(state.layout)
1130
+ }
1131
+ } : {
1132
+ layout: {
1133
+ ...state.layout,
1134
+ navSize: state.singleStory ? 0 : state.layout.recentVisibleSizes.navSize,
1135
+ bottomPanelHeight: state.layout.recentVisibleSizes.bottomPanelHeight,
1136
+ rightPanelWidth: state.layout.recentVisibleSizes.rightPanelWidth
1137
+ }
1138
+ };
1139
+ },
1140
+ { persistence: "session" }
1141
+ );
1142
+ },
1143
+ togglePanel(nextState) {
1144
+ return store2.setState(
1145
+ (state) => {
1146
+ let isPanelShown = getIsPanelShown(state), shouldShowPanel = typeof nextState == "boolean" ? nextState : !isPanelShown;
1147
+ return shouldShowPanel === isPanelShown ? { layout: state.layout } : shouldShowPanel ? {
1148
+ layout: {
1149
+ ...state.layout,
1150
+ bottomPanelHeight: state.layout.recentVisibleSizes.bottomPanelHeight,
1151
+ rightPanelWidth: state.layout.recentVisibleSizes.rightPanelWidth
1152
+ }
1153
+ } : {
1154
+ layout: {
1155
+ ...state.layout,
1156
+ bottomPanelHeight: 0,
1157
+ rightPanelWidth: 0,
1158
+ recentVisibleSizes: getRecentVisibleSizes(state.layout)
1159
+ }
1160
+ };
1161
+ },
1162
+ { persistence: "session" }
1163
+ );
1164
+ },
1165
+ togglePanelPosition(position) {
1166
+ return store2.setState(
1167
+ (state) => {
1168
+ let nextPosition = position || (state.layout.panelPosition === "right" ? "bottom" : "right");
1169
+ return {
1170
+ layout: {
1171
+ ...state.layout,
1172
+ panelPosition: nextPosition,
1173
+ bottomPanelHeight: state.layout.recentVisibleSizes.bottomPanelHeight,
1174
+ rightPanelWidth: state.layout.recentVisibleSizes.rightPanelWidth
1175
+ }
1176
+ };
1177
+ },
1178
+ { persistence: "permanent" }
1179
+ );
1180
+ },
1181
+ toggleNav(nextState) {
1182
+ return isDesktopViewport() ? store2.setState(
1183
+ (state) => {
1184
+ if (state.singleStory)
1185
+ return { layout: state.layout };
1186
+ let isNavShown = getIsNavShown(state), shouldShowNav = typeof nextState == "boolean" ? nextState : !isNavShown;
1187
+ return shouldShowNav === isNavShown ? { layout: state.layout } : shouldShowNav ? {
1188
+ layout: {
1189
+ ...state.layout,
1190
+ navSize: state.layout.recentVisibleSizes.navSize
1191
+ }
1192
+ } : {
1193
+ layout: {
1194
+ ...state.layout,
1195
+ navSize: 0,
1196
+ recentVisibleSizes: getRecentVisibleSizes(state.layout)
1197
+ }
1198
+ };
1199
+ },
1200
+ { persistence: "session" }
1201
+ ) : store2.setState((state) => ({
1202
+ layout: {
1203
+ ...state.layout,
1204
+ showMobileNavigation: typeof nextState == "boolean" ? nextState : !state.layout.showMobileNavigation
1205
+ }
1206
+ }));
1207
+ },
1208
+ setMobileNavigation(show) {
1209
+ return store2.setState((state) => ({
1210
+ layout: { ...state.layout, showMobileNavigation: show }
1211
+ }));
1212
+ },
1213
+ toggleToolbar(toggled) {
1214
+ return store2.setState(
1215
+ (state) => {
1216
+ let value = typeof toggled < "u" ? toggled : !state.layout.showToolbar;
1217
+ return {
1218
+ layout: {
1219
+ ...state.layout,
1220
+ showToolbar: value
1221
+ }
1222
+ };
1223
+ },
1224
+ { persistence: "session" }
1225
+ );
1226
+ },
1227
+ setSizes({
1228
+ navSize,
1229
+ bottomPanelHeight,
1230
+ rightPanelWidth
1231
+ }) {
1232
+ return store2.setState(
1233
+ (state) => {
1234
+ let nextLayoutState = {
1235
+ ...state.layout,
1236
+ navSize: navSize ?? state.layout.navSize,
1237
+ bottomPanelHeight: bottomPanelHeight ?? state.layout.bottomPanelHeight,
1238
+ rightPanelWidth: rightPanelWidth ?? state.layout.rightPanelWidth
1239
+ };
1240
+ return {
1241
+ layout: {
1242
+ ...nextLayoutState,
1243
+ recentVisibleSizes: getRecentVisibleSizes(nextLayoutState)
1244
+ }
1245
+ };
1246
+ },
1247
+ { persistence: "session" }
1248
+ );
1249
+ },
1250
+ /**
1251
+ * Attempts to focus (and select) an element identified by its ID. It is the responsibility of
1252
+ * the callee to ensure that the element is present in the DOM and that no focus trap is
1253
+ * available. When polling is enabled, this API polls and attempts to perform the focus for a
1254
+ * set duration (max 500ms), so that race conditions can be avoided with the current API
1255
+ * design.
1256
+ *
1257
+ * @param elementId The id of the element to focus.
1258
+ * @param options When a boolean, treated as the `select` option for backwards compatibility.
1259
+ * When an object, may contain `select` and `poll` options.
1260
+ * @returns Whether the element was successfully focused. Returns a Promise when polling.
1261
+ */
1262
+ focusOnUIElement(elementId, options) {
1263
+ let {
1264
+ forceFocus = !1,
1265
+ select = !1,
1266
+ poll = !0
1267
+ } = typeof options == "boolean" ? { select: options } : options ?? {};
1268
+ if (!elementId)
1269
+ return !1;
1270
+ let attemptFocus = () => {
1271
+ let element = document2.getElementById(elementId);
1272
+ return !element || (element.focus(), element !== document2.activeElement && forceFocus && element.getAttribute("tabindex") === null && (element.setAttribute("tabindex", "-1"), element.focus()), element !== document2.activeElement && element.id !== document2.activeElement?.id) ? !1 : (select && element.select?.(), !0);
1273
+ };
1274
+ return attemptFocus() ? !0 : poll ? new Promise((resolve) => {
1275
+ let startTime = Date.now(), maxDuration = 500, intervalId = setInterval(() => {
1276
+ let elapsed = Date.now() - startTime;
1277
+ if (attemptFocus()) {
1278
+ clearInterval(intervalId), resolve(!0);
1279
+ return;
1280
+ }
1281
+ elapsed >= maxDuration && (clearInterval(intervalId), resolve(!1));
1282
+ }, 50);
1283
+ }) : !1;
1284
+ },
1285
+ getInitialOptions() {
1286
+ let userConfig = provider.getConfig(), defaultLayoutState = getDefaultLayoutState(), { theme, selectedPanel, layoutCustomisations } = userConfig;
1287
+ return {
1288
+ ...defaultLayoutState,
1289
+ layout: applyLayoutOptions(defaultLayoutState.layout, userConfig.layout, !!singleStory),
1290
+ layoutCustomisations: {
1291
+ ...defaultLayoutState.layoutCustomisations,
1292
+ ...layoutCustomisations ?? {}
1293
+ },
1294
+ ui: applyUiOptions(defaultLayoutState.ui, userConfig.ui),
1295
+ selectedPanel: selectedPanel || defaultLayoutState.selectedPanel,
1296
+ theme: theme || defaultLayoutState.theme
1297
+ };
1298
+ },
1299
+ getIsFullscreen() {
1300
+ return getIsFullscreen(store2.getState());
1301
+ },
1302
+ getIsPanelShown() {
1303
+ return getIsPanelShown(store2.getState());
1304
+ },
1305
+ getIsNavShown() {
1306
+ return getIsNavShown(store2.getState());
1307
+ },
1308
+ getNavAvailability() {
1309
+ let state = store2.getState();
1310
+ return isReviewManagerRoute(state.path, state.customQueryParams) ? "unavailable" : getIsNavShown(state) ? "shown" : "hidden";
1311
+ },
1312
+ getShowToolbarWithCustomisations(showToolbar) {
1313
+ let state = store2.getState();
1314
+ return isFunction(state.layoutCustomisations.showToolbar) ? state.layoutCustomisations.showToolbar(state, showToolbar) ?? showToolbar : showToolbar;
1315
+ },
1316
+ getShowPanelWithCustomisations(showPanel) {
1317
+ let state = store2.getState();
1318
+ return isFunction(state.layoutCustomisations.showPanel) ? state.layoutCustomisations.showPanel(state, showPanel) ?? showPanel : showPanel;
1319
+ },
1320
+ getNavSizeWithCustomisations(navSize) {
1321
+ let state = store2.getState();
1322
+ if (isFunction(state.layoutCustomisations.showSidebar)) {
1323
+ let shouldShowNav = state.layoutCustomisations.showSidebar(state, navSize !== 0);
1324
+ if (navSize === 0 && shouldShowNav === !0)
1325
+ return state.layout.recentVisibleSizes.navSize;
1326
+ if (navSize !== 0 && shouldShowNav === !1)
1327
+ return 0;
1328
+ }
1329
+ return navSize;
1330
+ },
1331
+ setOptions: (options) => {
1332
+ let { layout, ui, selectedPanel, theme } = store2.getState();
1333
+ if (!options)
1334
+ return;
1335
+ let updatedLayout = applyLayoutOptions(layout, options.layout, !!singleStory), updatedUi = applyUiOptions(ui, options.ui), updatedTheme = {
1336
+ ...theme,
1337
+ ...options.theme
1338
+ }, modification = {};
1339
+ isEqual(ui, updatedUi) || (modification.ui = updatedUi), isEqual(layout, updatedLayout) || (modification.layout = updatedLayout), options.selectedPanel && !isEqual(selectedPanel, options.selectedPanel) && (modification.selectedPanel = options.selectedPanel), Object.keys(modification).length && store2.setState(modification, { persistence: "permanent" }), isEqual(theme, updatedTheme) || store2.setState({ theme: updatedTheme });
1340
+ }
1341
+ }, persisted = pick(store2.getState(), ["layout", "selectedPanel"]);
1342
+ return persisted.layout && (persisted.layout = { ...persisted.layout, showMobileNavigation: !1 }), provider.channel?.on(SET_CONFIG2, () => {
1343
+ api.setOptions(merge_default(api.getInitialOptions(), persisted));
1344
+ }), {
1345
+ api,
1346
+ state: merge_default(api.getInitialOptions(), persisted)
1347
+ };
1348
+ };
1349
+
1350
+ // src/manager-api/modules/notifications.ts
1351
+ var notifications_exports = {};
1352
+ __export(notifications_exports, {
1353
+ init: () => init6
1354
+ });
1355
+ var init6 = ({ store: store2 }) => ({
1356
+ api: {
1357
+ addNotification: (newNotification) => {
1358
+ store2.setState(({ notifications }) => {
1359
+ let [existing, others] = partition(notifications, (n) => n.id === newNotification.id);
1360
+ return existing.forEach((notification) => {
1361
+ notification.onClear && notification.onClear({ dismissed: !1, timeout: !1 });
1362
+ }), { notifications: [...others, newNotification] };
1363
+ });
1364
+ },
1365
+ clearNotification: (notificationId) => {
1366
+ store2.setState(({ notifications }) => {
1367
+ let [matching, others] = partition(notifications, (n) => n.id === notificationId);
1368
+ return matching.forEach((notification) => {
1369
+ notification.onClear && notification.onClear({ dismissed: !1, timeout: !1 });
1370
+ }), { notifications: others };
1371
+ });
1372
+ }
1373
+ },
1374
+ state: { notifications: [] }
1375
+ });
1376
+
1377
+ // src/manager-api/modules/open-in-editor.tsx
1378
+ var open_in_editor_exports = {};
1379
+ __export(open_in_editor_exports, {
1380
+ init: () => init7
1381
+ });
1382
+ import {
1383
+ OPEN_IN_EDITOR_REQUEST,
1384
+ OPEN_IN_EDITOR_RESPONSE
1385
+ } from "@aussieljk/forkbook/internal/core-events";
1386
+ import { FailedIcon } from "@storybook/icons";
1387
+ import { jsx } from "react/jsx-runtime";
1388
+ var init7 = ({ provider, fullAPI }) => ({
1389
+ api: {
1390
+ openInEditor(payload) {
1391
+ return new Promise((resolve) => {
1392
+ let { file, line, column } = payload, handler = (res) => {
1393
+ res.file === file && res.line === line && res.column === column && (provider.channel?.off(OPEN_IN_EDITOR_RESPONSE, handler), resolve(res));
1394
+ };
1395
+ provider.channel?.on(OPEN_IN_EDITOR_RESPONSE, handler), provider.channel?.emit(OPEN_IN_EDITOR_REQUEST, payload);
1396
+ });
1397
+ }
1398
+ },
1399
+ state: { notifications: [] },
1400
+ init: async () => {
1401
+ let { color } = await import("../theming/index.js");
1402
+ provider.channel?.on(OPEN_IN_EDITOR_RESPONSE, (payload) => {
1403
+ payload.error !== null && fullAPI.addNotification({
1404
+ id: "open-in-editor-error",
1405
+ content: {
1406
+ headline: "Failed to open in editor",
1407
+ subHeadline: payload.error || "Check the Forkbook process on the command line for more details."
1408
+ },
1409
+ icon: jsx(FailedIcon, { color: color.negative }),
1410
+ duration: 8e3
1411
+ });
1412
+ });
1413
+ }
1414
+ });
1415
+
1416
+ // src/manager-api/modules/provider.ts
1417
+ var provider_exports = {};
1418
+ __export(provider_exports, {
1419
+ init: () => init8
1420
+ });
1421
+ var init8 = ({ provider }) => ({
1422
+ api: provider.renderPreview ? { renderPreview: provider.renderPreview } : {},
1423
+ state: {}
1424
+ });
1425
+
1426
+ // src/manager-api/modules/settings.ts
1427
+ var settings_exports = {};
1428
+ __export(settings_exports, {
1429
+ init: () => init9
1430
+ });
1431
+ var init9 = ({ store: store2, navigate, fullAPI }) => ({
1432
+ state: { settings: { lastTrackedStoryId: null } },
1433
+ api: {
1434
+ closeSettings: () => {
1435
+ let {
1436
+ settings: { lastTrackedStoryId }
1437
+ } = store2.getState();
1438
+ lastTrackedStoryId ? fullAPI.selectStory(lastTrackedStoryId) : fullAPI.selectFirstStory();
1439
+ },
1440
+ changeSettingsTab: (path) => {
1441
+ navigate(`/settings/${path}`);
1442
+ },
1443
+ isSettingsScreenActive: () => {
1444
+ let { path } = fullAPI.getUrlState();
1445
+ return !!(path || "").match(/^\/settings/);
1446
+ },
1447
+ retrieveSelection() {
1448
+ let { settings } = store2.getState();
1449
+ return settings.lastTrackedStoryId;
1450
+ },
1451
+ storeSelection: async () => {
1452
+ let { storyId, settings } = store2.getState();
1453
+ await store2.setState({
1454
+ settings: { ...settings, lastTrackedStoryId: storyId }
1455
+ });
1456
+ }
1457
+ }
1458
+ });
1459
+
1460
+ // src/manager-api/modules/shortcuts.ts
1461
+ var shortcuts_exports = {};
1462
+ __export(shortcuts_exports, {
1463
+ controlOrMetaKey: () => controlOrMetaKey2,
1464
+ defaultShortcuts: () => defaultShortcuts,
1465
+ init: () => init10,
1466
+ isMacLike: () => isMacLike2,
1467
+ keys: () => keys
1468
+ });
1469
+ var import_copy_to_clipboard = __toESM(require_copy_to_clipboard(), 1);
1470
+ import {
1471
+ FORCE_REMOUNT,
1472
+ PREVIEW_KEYDOWN,
1473
+ STORIES_COLLAPSE_ALL,
1474
+ STORIES_EXPAND_ALL
1475
+ } from "@aussieljk/forkbook/internal/core-events";
1476
+ import { global as global4 } from "@storybook/global";
1477
+ import { logger as logger6 } from "@aussieljk/forkbook/internal/client-logger";
1478
+
1479
+ // src/manager-api/lib/platform.ts
1480
+ import { global as global3 } from "@storybook/global";
1481
+ var { navigator: navigator2 } = global3, isMacLike = () => navigator2 && navigator2.platform ? !!navigator2.platform.match(/(Mac|iPhone|iPod|iPad)/i) : !1;
1482
+
1483
+ // src/manager-api/lib/shortcut.ts
1484
+ var controlOrMetaSymbol = () => isMacLike() ? "\u2318" : "ctrl", controlOrMetaKey = () => isMacLike() ? "meta" : "control", optionOrAltSymbol = () => isMacLike() ? "\u2325" : "alt", isShortcutTaken = (arr1, arr2) => JSON.stringify(arr1) === JSON.stringify(arr2), eventToShortcut = (e) => {
1485
+ if (["Meta", "Alt", "Control", "Shift", "Tab"].includes(e.key))
1486
+ return null;
1487
+ let keys2 = [];
1488
+ e.altKey && keys2.push("alt"), e.ctrlKey && keys2.push("control"), e.metaKey && keys2.push("meta"), e.shiftKey && keys2.push("shift");
1489
+ let codeUpper = e.code?.toUpperCase(), codeToCharMap = {
1490
+ MINUS: "-",
1491
+ EQUAL: "=",
1492
+ BRACKETLEFT: "[",
1493
+ BRACKETRIGHT: "]",
1494
+ BACKSLASH: "\\",
1495
+ SEMICOLON: ";",
1496
+ QUOTE: "'",
1497
+ BACKQUOTE: "`",
1498
+ COMMA: ",",
1499
+ PERIOD: ".",
1500
+ SLASH: "/"
1501
+ }, codeChar = codeUpper ? codeUpper.startsWith("KEY") && codeUpper.length === 4 ? codeUpper.replace("KEY", "") : codeUpper.startsWith("DIGIT") ? codeUpper.replace("DIGIT", "") : codeToCharMap[codeUpper] : void 0;
1502
+ if (e.key && e.key.length === 1 && e.key !== " ") {
1503
+ let key = e.key.toUpperCase(), code = codeChar;
1504
+ code && code.length === 1 && code !== key ? keys2.push([key, code]) : keys2.push(key);
1505
+ } else e.key === "Dead" && codeChar && keys2.push(codeChar);
1506
+ return e.key === " " && keys2.push("space"), e.key === "Escape" && keys2.push("escape"), e.key === "ArrowRight" && keys2.push("ArrowRight"), e.key === "ArrowDown" && keys2.push("ArrowDown"), e.key === "ArrowUp" && keys2.push("ArrowUp"), e.key === "ArrowLeft" && keys2.push("ArrowLeft"), keys2.length > 0 ? keys2 : null;
1507
+ }, shortcutMatchesShortcut = (inputShortcut, shortcut) => !inputShortcut || !shortcut || (inputShortcut.join("").startsWith("shift/") && inputShortcut.shift(), inputShortcut.length !== shortcut.length) ? !1 : !inputShortcut.find(
1508
+ (input, i) => Array.isArray(input) ? !input.includes(shortcut[i]) : input !== shortcut[i]
1509
+ ), eventMatchesShortcut = (e, shortcut) => shortcutMatchesShortcut(eventToShortcut(e), shortcut), keyToSymbol = (key) => key === "alt" ? optionOrAltSymbol() : key === "control" ? "\u2303" : key === "meta" ? "\u2318" : key === "shift" ? "\u21E7\u200B" : key === "Enter" || key === "Backspace" || key === "Esc" ? "" : key === " " ? "SPACE" : key === "ArrowUp" ? "\u2191" : key === "ArrowDown" ? "\u2193" : key === "ArrowLeft" ? "\u2190" : key === "ArrowRight" ? "\u2192" : key?.toUpperCase(), shortcutToHumanString = (shortcut) => shortcut.map(keyToSymbol).join(" "), shortcutToAriaKeyshortcuts = (shortcut) => shortcut.map((shortcut2) => shortcut2 === "+" ? "plus" : shortcut2 === " " ? "space" : shortcut2).join("+");
1510
+
1511
+ // src/manager-api/modules/shortcuts.ts
1512
+ var { navigator: navigator3, document: document3 } = global4;
1513
+ function wasFocusInElement(element) {
1514
+ return document3.activeElement && element?.contains(document3.activeElement);
1515
+ }
1516
+ var isMacLike2 = () => navigator3 && navigator3.platform ? !!navigator3.platform.match(/(Mac|iPhone|iPod|iPad)/i) : !1, controlOrMetaKey2 = () => isMacLike2() ? "meta" : "control";
1517
+ function keys(o) {
1518
+ return Object.keys(o);
1519
+ }
1520
+ var defaultShortcuts = Object.freeze({
1521
+ fullScreen: ["alt", "F"],
1522
+ togglePanel: ["alt", "A"],
1523
+ panelPosition: ["alt", "D"],
1524
+ toggleNav: ["alt", "S"],
1525
+ toolbar: ["alt", "T"],
1526
+ search: [controlOrMetaKey2(), "K"],
1527
+ focusNav: ["1"],
1528
+ focusIframe: ["2"],
1529
+ focusPanel: ["3"],
1530
+ prevComponent: ["alt", "ArrowUp"],
1531
+ nextComponent: ["alt", "ArrowDown"],
1532
+ prevStory: ["alt", "ArrowLeft"],
1533
+ nextStory: ["alt", "ArrowRight"],
1534
+ shortcutsPage: [controlOrMetaKey2(), "shift", ","],
1535
+ aboutPage: [controlOrMetaKey2(), ","],
1536
+ collapseAll: [controlOrMetaKey2(), "shift", "ArrowUp"],
1537
+ expandAll: [controlOrMetaKey2(), "shift", "ArrowDown"],
1538
+ remount: ["alt", "R"],
1539
+ openInEditor: ["alt", "shift", "E"],
1540
+ openInIsolation: ["alt", "shift", "I"],
1541
+ copyStoryLink: ["alt", "shift", "L"],
1542
+ goToPreviousLandmark: ["shift", "F6"],
1543
+ // hardcoded in useLandmark
1544
+ goToNextLandmark: ["F6"]
1545
+ // hardcoded in useLandmark
1546
+ // TODO: bring this back once we want to add shortcuts for this
1547
+ // copyStoryName: ['alt', 'shift', 'C'],
1548
+ }), addonsShortcuts = {};
1549
+ function shouldSkipShortcut(event) {
1550
+ let target = event.target;
1551
+ return !!(/input|textarea/i.test(target.tagName) || target.getAttribute("contenteditable") !== null || target.closest("dialog[open]"));
1552
+ }
1553
+ var init10 = ({ store: store2, fullAPI, provider }) => {
1554
+ let api = {
1555
+ // Getting and setting shortcuts
1556
+ getShortcutKeys() {
1557
+ return store2.getState().shortcuts;
1558
+ },
1559
+ getDefaultShortcuts() {
1560
+ return {
1561
+ ...defaultShortcuts,
1562
+ ...api.getAddonsShortcutDefaults()
1563
+ };
1564
+ },
1565
+ getAddonsShortcuts() {
1566
+ return addonsShortcuts;
1567
+ },
1568
+ getAddonsShortcutLabels() {
1569
+ let labels = {};
1570
+ return Object.entries(api.getAddonsShortcuts()).forEach(([actionName, { label }]) => {
1571
+ labels[actionName] = label;
1572
+ }), labels;
1573
+ },
1574
+ getAddonsShortcutDefaults() {
1575
+ let defaults = {};
1576
+ return Object.entries(api.getAddonsShortcuts()).forEach(([actionName, { defaultShortcut }]) => {
1577
+ defaults[actionName] = defaultShortcut;
1578
+ }), defaults;
1579
+ },
1580
+ async setShortcuts(update2) {
1581
+ let { shortcuts } = await store2.setState(
1582
+ (state2) => ({ shortcuts: typeof update2 == "function" ? update2(state2.shortcuts) : update2 }),
1583
+ { persistence: "permanent" }
1584
+ );
1585
+ return shortcuts;
1586
+ },
1587
+ async restoreAllDefaultShortcuts() {
1588
+ return api.setShortcuts(api.getDefaultShortcuts());
1589
+ },
1590
+ async setShortcut(action, value) {
1591
+ return await api.setShortcuts((shortcuts) => ({ ...shortcuts, [action]: value })), value;
1592
+ },
1593
+ async setAddonShortcut(addon, shortcut) {
1594
+ return await api.setShortcuts((shortcuts) => ({
1595
+ ...shortcuts,
1596
+ [`${addon}-${shortcut.actionName}`]: shortcut.defaultShortcut
1597
+ })), addonsShortcuts[`${addon}-${shortcut.actionName}`] = shortcut, shortcut;
1598
+ },
1599
+ async restoreDefaultShortcut(action) {
1600
+ let defaultShortcut = api.getDefaultShortcuts()[action];
1601
+ return api.setShortcut(action, defaultShortcut);
1602
+ },
1603
+ // Listening to shortcut events
1604
+ handleKeydownEvent(event) {
1605
+ if (!store2.getState().ui.enableShortcuts)
1606
+ return;
1607
+ let shortcut = eventToShortcut(event), shortcuts = api.getShortcutKeys(), matchedFeature = keys(shortcuts).find((feature) => !shortcutMatchesShortcut(shortcut, shortcuts[feature]) || fullAPI.getNavAvailability() === "unavailable" && ["focusNav", "search", "toggleNav"].includes(feature) ? !1 : feature in defaultShortcuts ? !0 : feature in addonsShortcuts);
1608
+ return matchedFeature && api.handleShortcutFeature(matchedFeature, event), matchedFeature;
1609
+ },
1610
+ // warning: event might not have a full prototype chain because it may originate from the channel
1611
+ handleShortcutFeature(feature, event) {
1612
+ let state2 = store2.getState(), {
1613
+ ui: { enableShortcuts },
1614
+ storyId,
1615
+ refId,
1616
+ viewMode
1617
+ } = state2;
1618
+ if (!enableShortcuts)
1619
+ return;
1620
+ let isSidebarShortcutBlocked = fullAPI.getNavAvailability() === "unavailable", isSidebarShortcutFeature = ["focusNav", "search", "toggleNav"].includes(feature);
1621
+ if (!(isSidebarShortcutBlocked && isSidebarShortcutFeature))
1622
+ switch (event?.preventDefault && event.preventDefault(), feature) {
1623
+ // Handled by useLandmark and useLandmarkIndicator
1624
+ case "goToNextLandmark":
1625
+ case "goToPreviousLandmark":
1626
+ break;
1627
+ case "focusNav": {
1628
+ fullAPI.getIsFullscreen() && fullAPI.toggleFullscreen(!1), fullAPI.getIsNavShown() || fullAPI.toggleNav(!0), fullAPI.focusOnUIElement(focusableUIElements.storyListMenu);
1629
+ break;
1630
+ }
1631
+ case "search": {
1632
+ fullAPI.getIsFullscreen() && fullAPI.toggleFullscreen(!1), fullAPI.getIsNavShown() || fullAPI.toggleNav(!0), setTimeout(() => {
1633
+ fullAPI.focusOnUIElement(focusableUIElements.storySearchField, !0);
1634
+ }, 0);
1635
+ break;
1636
+ }
1637
+ case "focusIframe": {
1638
+ let element = document3.getElementById("storybook-preview-iframe");
1639
+ if (element)
1640
+ try {
1641
+ element.contentWindow.focus();
1642
+ } catch {
1643
+ }
1644
+ break;
1645
+ }
1646
+ case "focusPanel": {
1647
+ fullAPI.getIsFullscreen() && fullAPI.toggleFullscreen(!1), fullAPI.getIsPanelShown() || fullAPI.togglePanel(!0), fullAPI.focusOnUIElement(focusableUIElements.storyPanelRoot);
1648
+ break;
1649
+ }
1650
+ case "nextStory": {
1651
+ fullAPI.jumpToStory(1);
1652
+ break;
1653
+ }
1654
+ case "prevStory": {
1655
+ fullAPI.jumpToStory(-1);
1656
+ break;
1657
+ }
1658
+ case "nextComponent": {
1659
+ fullAPI.jumpToComponent(1);
1660
+ break;
1661
+ }
1662
+ case "prevComponent": {
1663
+ fullAPI.jumpToComponent(-1);
1664
+ break;
1665
+ }
1666
+ case "fullScreen": {
1667
+ fullAPI.toggleFullscreen();
1668
+ break;
1669
+ }
1670
+ case "togglePanel": {
1671
+ let wasPanelShown = fullAPI.getIsPanelShown(), panelElement = document3.getElementById(focusableUIElements.addonPanel);
1672
+ fullAPI.togglePanel(), wasPanelShown && wasFocusInElement(panelElement) && fullAPI.focusOnUIElement(focusableUIElements.showAddonPanel, {
1673
+ poll: !0
1674
+ }).then((success) => {
1675
+ success === !1 && document3.body.focus();
1676
+ }), wasPanelShown || fullAPI.focusOnUIElement(focusableUIElements.addonPanel, {
1677
+ forceFocus: !0,
1678
+ poll: !0
1679
+ });
1680
+ break;
1681
+ }
1682
+ case "toggleNav": {
1683
+ let isDesktop = isDesktopViewport(), wasNavShown = fullAPI.getIsNavShown(), sidebarElement = document3.getElementById(focusableUIElements.sidebarRegion);
1684
+ fullAPI.toggleNav(), isDesktop && (wasNavShown && wasFocusInElement(sidebarElement) && fullAPI.focusOnUIElement(focusableUIElements.showSidebar, {
1685
+ poll: !0
1686
+ }).then((success) => {
1687
+ success === !1 && document3.body.focus();
1688
+ }), wasNavShown || fullAPI.focusOnUIElement(focusableUIElements.sidebarRegion, {
1689
+ forceFocus: !0,
1690
+ poll: !0
1691
+ }));
1692
+ break;
1693
+ }
1694
+ case "toolbar": {
1695
+ fullAPI.toggleToolbar();
1696
+ break;
1697
+ }
1698
+ case "panelPosition": {
1699
+ fullAPI.getIsFullscreen() && fullAPI.toggleFullscreen(!1), fullAPI.getIsPanelShown() || fullAPI.togglePanel(!0), fullAPI.togglePanelPosition();
1700
+ break;
1701
+ }
1702
+ case "aboutPage": {
1703
+ fullAPI.navigate("/settings/about");
1704
+ break;
1705
+ }
1706
+ case "shortcutsPage": {
1707
+ fullAPI.navigate("/settings/shortcuts");
1708
+ break;
1709
+ }
1710
+ case "collapseAll": {
1711
+ fullAPI.emit(STORIES_COLLAPSE_ALL);
1712
+ break;
1713
+ }
1714
+ case "expandAll": {
1715
+ fullAPI.emit(STORIES_EXPAND_ALL);
1716
+ break;
1717
+ }
1718
+ case "remount": {
1719
+ fullAPI.emit(FORCE_REMOUNT, { storyId });
1720
+ break;
1721
+ }
1722
+ case "openInEditor": {
1723
+ global4.CONFIG_TYPE === "DEVELOPMENT" && fullAPI.openInEditor({
1724
+ file: fullAPI.getCurrentStoryData().importPath
1725
+ });
1726
+ break;
1727
+ }
1728
+ case "openInIsolation": {
1729
+ if (storyId && viewMode === "story") {
1730
+ let { previewHref } = fullAPI.getStoryHrefs(storyId, { refId });
1731
+ window.open(previewHref, "_blank", "noopener,noreferrer");
1732
+ }
1733
+ break;
1734
+ }
1735
+ // TODO: bring this back once we want to add shortcuts for this
1736
+ // case 'copyStoryName': {
1737
+ // const storyData = fullAPI.getCurrentStoryData();
1738
+ // if (storyData.type === 'story') {
1739
+ // copy(storyData.exportName);
1740
+ // }
1741
+ // break;
1742
+ // }
1743
+ case "copyStoryLink": {
1744
+ if (storyId) {
1745
+ let { managerHref } = fullAPI.getStoryHrefs(storyId, { refId });
1746
+ (0, import_copy_to_clipboard.default)(managerHref);
1747
+ }
1748
+ break;
1749
+ }
1750
+ default:
1751
+ feature in addonsShortcuts ? addonsShortcuts[feature].action() : logger6.warn(`api.handleShortcutFeature called with unknown feature: ${feature}.`);
1752
+ break;
1753
+ }
1754
+ }
1755
+ }, { shortcuts: persistedShortcuts = defaultShortcuts } = store2.getState(), state = {
1756
+ // Any saved shortcuts that are still in our set of defaults
1757
+ shortcuts: keys(defaultShortcuts).reduce(
1758
+ (acc, key) => ({ ...acc, [key]: persistedShortcuts[key] || defaultShortcuts[key] }),
1759
+ defaultShortcuts
1760
+ )
1761
+ };
1762
+ return { api, state, init: () => {
1763
+ document3.addEventListener(
1764
+ "keydown",
1765
+ (event) => {
1766
+ if (!shouldSkipShortcut(event)) {
1767
+ let matched = api.handleKeydownEvent(event);
1768
+ matched && matched !== "goToNextLandmark" && matched !== "goToPreviousLandmark" && event.stopPropagation();
1769
+ }
1770
+ },
1771
+ { capture: !0 }
1772
+ ), window.addEventListener("keydown", (event) => {
1773
+ event.key === "Escape" && !event.defaultPrevented && !shouldSkipShortcut(event) && store2.getState().ui.enableShortcuts && fullAPI.getIsFullscreen() && (event.preventDefault(), fullAPI.toggleFullscreen(!1));
1774
+ }), provider.channel?.on(PREVIEW_KEYDOWN, (data) => {
1775
+ api.handleKeydownEvent(data.event), data.event.key === "Escape" && store2.getState().ui.enableShortcuts && fullAPI.getIsFullscreen() && fullAPI.toggleFullscreen(!1);
1776
+ });
1777
+ } };
1778
+ };
1779
+
1780
+ // src/manager-api/modules/stories.ts
1781
+ var stories_exports = {};
1782
+ __export(stories_exports, {
1783
+ init: () => init11
1784
+ });
1785
+ import { logger as logger7 } from "@aussieljk/forkbook/internal/client-logger";
1786
+ import {
1787
+ CONFIG_ERROR,
1788
+ CURRENT_STORY_WAS_SET,
1789
+ DOCS_PREPARED,
1790
+ PRELOAD_ENTRIES,
1791
+ RESET_STORY_ARGS,
1792
+ SELECT_STORY,
1793
+ SET_CONFIG as SET_CONFIG3,
1794
+ SET_CURRENT_STORY,
1795
+ SET_FILTER,
1796
+ SET_INDEX,
1797
+ SET_STORIES,
1798
+ SIDEBAR_FILTER_CHANGED,
1799
+ STORY_ARGS_UPDATED,
1800
+ STORY_CHANGED,
1801
+ STORY_INDEX_INVALIDATED,
1802
+ STORY_MISSING,
1803
+ STORY_PREPARED,
1804
+ STORY_SPECIFIED,
1805
+ UPDATE_STORY_ARGS
1806
+ } from "@aussieljk/forkbook/internal/core-events";
1807
+ import { sanitize as sanitize2, toId } from "@aussieljk/forkbook/internal/csf";
1808
+ import { queryFromLocation } from "@aussieljk/forkbook/internal/router";
1809
+ import { global as global5 } from "@storybook/global";
1810
+
1811
+ // src/manager-api/lib/url.ts
1812
+ var buildNavigationUrl = (path, queryParams = {}) => {
1813
+ let params = Object.entries(queryParams).filter(([k, v]) => k !== "path" && v !== null && v !== void 0).sort(([a], [b]) => a < b ? -1 : 1).map(([k, v]) => `${k}=${v}`);
1814
+ return [path, ...params].join("&");
1815
+ };
1816
+
1817
+ // src/shared/universal-store/use-universal-store-manager.ts
1818
+ import * as React from "react";
1819
+ var useUniversalStore = (universalStore, selector) => {
1820
+ let snapshotRef = React.useRef(
1821
+ selector ? selector(universalStore.getState()) : universalStore.getState()
1822
+ ), subscribe = React.useCallback(
1823
+ (listener) => universalStore.onStateChange((state2, previousState) => {
1824
+ if (!selector) {
1825
+ snapshotRef.current = state2, listener();
1826
+ return;
1827
+ }
1828
+ let selectedState = selector(state2), selectedPreviousState = selector(previousState);
1829
+ !isEqual(selectedState, selectedPreviousState) && (snapshotRef.current = selectedState, listener());
1830
+ }),
1831
+ [universalStore, selector]
1832
+ ), getSnapshot = React.useCallback(() => {
1833
+ let currentState = universalStore.getState(), selectedState = selector ? selector(currentState) : currentState;
1834
+ return isEqual(selectedState, snapshotRef.current) || (snapshotRef.current = selectedState), snapshotRef.current;
1835
+ }, [universalStore, selector]);
1836
+ return [React.useSyncExternalStore(subscribe, getSnapshot), universalStore.setState];
1837
+ };
1838
+
1839
+ // src/manager-api/stores/status.ts
1840
+ var statusStore = createStatusStore({
1841
+ universalStatusStore: UniversalStore.create({
1842
+ ...UNIVERSAL_STATUS_STORE_OPTIONS,
1843
+ leader: globalThis.CONFIG_TYPE === "PRODUCTION"
1844
+ }),
1845
+ useUniversalStore,
1846
+ environment: "manager"
1847
+ }), { fullStatusStore, getStatusStoreByTypeId, useStatusStore, universalStatusStore } = statusStore;
1848
+
1849
+ // src/manager-api/lib/filter-param.ts
1850
+ var parseFilterParam = (param, transform) => {
1851
+ if (!param)
1852
+ return { included: [], excluded: [] };
1853
+ let included = [], excluded = [];
1854
+ return param.split(";").forEach((raw) => {
1855
+ if (!raw)
1856
+ return;
1857
+ let isExcluded = raw.startsWith("!"), value = transform(isExcluded ? raw.slice(1) : raw);
1858
+ value != null && (isExcluded ? excluded.push(value) : included.push(value));
1859
+ }), { included, excluded };
1860
+ };
1861
+
1862
+ // src/manager-api/modules/statuses.ts
1863
+ var parseStatusesParam = (statusesParam) => parseFilterParam(statusesParam, toStatusValue), serializeStatusesParam = (included, excluded) => {
1864
+ if (!included.length && !excluded.length)
1865
+ return;
1866
+ let serializedIncluded = included.map((v) => statusValueShortName(v)).sort(), serializedExcluded = excluded.map((v) => `!${statusValueShortName(v)}`).sort();
1867
+ return [...serializedIncluded, ...serializedExcluded].join(";");
1868
+ }, computeStatusFilterFn = (includedStatusFilters, excludedStatusFilters) => (entry) => {
1869
+ if (!includedStatusFilters.length && !excludedStatusFilters.length)
1870
+ return !0;
1871
+ let storyStatuses = (fullStatusStore.getAll() ?? {})[entry.id], storyStatusValues = storyStatuses ? Object.values(storyStatuses).map((s) => s.value) : [], passesInclude = !includedStatusFilters.length || includedStatusFilters.some((v) => storyStatusValues.includes(v)), passesExclude = !excludedStatusFilters.length || excludedStatusFilters.every((v) => !storyStatusValues.includes(v));
1872
+ return passesInclude && passesExclude;
1873
+ };
1874
+
1875
+ // src/manager-api/modules/tags.ts
1876
+ var import_memoizerific2 = __toESM(require_memoizerific(), 1);
1877
+ var BUILT_IN_URL_TAG_MAP = {
1878
+ $docs: "_docs",
1879
+ $play: "_play",
1880
+ $test: "_test"
1881
+ }, parseTagsParam = (tagsParam) => parseFilterParam(tagsParam, (raw) => BUILT_IN_URL_TAG_MAP[raw] ?? raw), serializeTagsParam = (included, excluded) => {
1882
+ if (!included.length && !excluded.length)
1883
+ return "";
1884
+ let reverseBuiltInUrlTagMap = Object.fromEntries(
1885
+ Object.entries(BUILT_IN_URL_TAG_MAP).map(([urlTag, internalTag]) => [internalTag, urlTag])
1886
+ ), serializedIncluded = included.map((tag) => reverseBuiltInUrlTagMap[tag] ?? tag).sort(), serializedExcluded = excluded.map((tag) => `!${reverseBuiltInUrlTagMap[tag] ?? tag}`).sort();
1887
+ return [...serializedIncluded, ...serializedExcluded].join(";");
1888
+ }, getDefaultTagsFromPreset = (0, import_memoizerific2.default)(1)((presets) => {
1889
+ let presetEntries = Object.entries(presets);
1890
+ return {
1891
+ included: presetEntries.filter(([, option]) => option.defaultFilterSelection === "include").map(([tag]) => tag),
1892
+ excluded: presetEntries.filter(([, option]) => option.defaultFilterSelection === "exclude").map(([tag]) => tag)
1893
+ };
1894
+ }), computeStaticFilterFn = (tagPresets) => {
1895
+ let staticExcludeTags = Object.entries(tagPresets).reduce(
1896
+ (acc, [tag, option]) => (option.hideFromSidebar && (acc[tag] = !0), acc),
1897
+ {}
1898
+ );
1899
+ return (item) => {
1900
+ let tags = item.tags ?? [], isCsfAutodocsEntry = item.type === "docs" && !tags.includes(Tag.ATTACHED_MDX) && !tags.includes(Tag.UNATTACHED_MDX);
1901
+ return (tags.includes(Tag.DEV) || isCsfAutodocsEntry) && tags.filter((tag) => staticExcludeTags[tag]).length === 0;
1902
+ };
1903
+ }, computeTagsFilterFn = (includedTagFilters, excludedTagFilters) => {
1904
+ let computeFilterFunctions = (set2) => Object.values(
1905
+ set2.reduce(
1906
+ (acc, tag) => (Object.hasOwn(BUILT_IN_FILTERS, tag) ? acc["built-in"].push(BUILT_IN_FILTERS[tag]) : acc.user.push(USER_TAG_FILTER(tag)), acc),
1907
+ { "built-in": [], user: [] }
1908
+ )
1909
+ ).filter((group) => group.length > 0);
1910
+ return (item) => {
1911
+ let included = computeFilterFunctions(includedTagFilters), excluded = computeFilterFunctions(excludedTagFilters);
1912
+ return (!included.length || included.every((group) => group.some((filterFn) => filterFn(item, !1)))) && (!excluded.length || excluded.every((group) => group.every((filterFn) => filterFn(item, !0))));
1913
+ };
1914
+ };
1915
+
1916
+ // src/manager-api/modules/stories.ts
1917
+ var { fetch: fetch2 } = global5, STORY_INDEX_PATH = "./index.json", TAGS_FILTER = "tags-filter", STATIC_FILTER = "static-filter", STATUS_FILTER = "status-filter", STATUS_CHANGE_REBUILD_THROTTLE = 500, BUILT_IN_TAG_IDS = new Set(Object.keys(BUILT_IN_FILTERS)), removedOptions = ["enableShortcuts", "theme", "showRoots"];
1918
+ function removeRemovedOptions(options) {
1919
+ if (!options || typeof options == "string")
1920
+ return options;
1921
+ let result = { ...options };
1922
+ return removedOptions.forEach((option) => {
1923
+ option in result && delete result[option];
1924
+ }), result;
1925
+ }
1926
+ var FILTER_KEYS = {
1927
+ tag: { included: "includedTagFilters", excluded: "excludedTagFilters" },
1928
+ status: { included: "includedStatusFilters", excluded: "excludedStatusFilters" }
1929
+ }, init11 = ({
1930
+ fullAPI,
1931
+ store: store2,
1932
+ navigate,
1933
+ provider,
1934
+ state: { location: location2 } = {},
1935
+ storyId: initialStoryId,
1936
+ viewMode: initialViewMode,
1937
+ docsOptions = {}
1938
+ }) => {
1939
+ let navigateWithQueryParams = (path, options) => {
1940
+ let { customQueryParams } = store2.getState();
1941
+ navigate(buildNavigationUrl(path, customQueryParams ?? {}), options);
1942
+ }, persistFilters = (inputPatch) => store2.setState(inputPatch, {
1943
+ persistence: "url",
1944
+ serialize: (s) => {
1945
+ let tagsValue = serializeTagsParam(s.includedTagFilters, s.excludedTagFilters), statusesValue = serializeStatusesParam(
1946
+ s.includedStatusFilters,
1947
+ s.excludedStatusFilters
1948
+ );
1949
+ return { tags: tagsValue ?? null, statuses: statusesValue ?? null };
1950
+ }
1951
+ }), urlFilterTelemetryEmitted = !1, addFilters = async (type, items, excluded) => {
1952
+ let { included, excluded: excludedKey } = FILTER_KEYS[type], state = store2.getState(), newIncluded = new Set(state[included]), newExcluded = new Set(state[excludedKey]);
1953
+ for (let item of items) {
1954
+ let [target, other] = excluded ? [newExcluded, newIncluded] : [newIncluded, newExcluded];
1955
+ other.delete(item), target.add(item);
1956
+ }
1957
+ await persistFilters({
1958
+ [included]: Array.from(newIncluded),
1959
+ [excludedKey]: Array.from(newExcluded)
1960
+ });
1961
+ }, removeFilters = async (type, items) => {
1962
+ let { included, excluded } = FILTER_KEYS[type], state = store2.getState(), itemSet = new Set(items);
1963
+ await persistFilters({
1964
+ [included]: state[included].filter((v) => !itemSet.has(v)),
1965
+ [excluded]: state[excluded].filter((v) => !itemSet.has(v))
1966
+ });
1967
+ }, emitFilterTelemetry = (trigger, changed) => {
1968
+ let state = store2.getState(), includedTags = (state.includedTagFilters ?? []).filter((id) => BUILT_IN_TAG_IDS.has(id)), excludedTags = (state.excludedTagFilters ?? []).filter((id) => BUILT_IN_TAG_IDS.has(id)), includedStatuses = state.includedStatusFilters ?? [], excludedStatuses = state.excludedStatusFilters ?? [], storyCounts = {}, entries = state.internal_index ? Object.values(state.internal_index.entries) : [];
1969
+ for (let tagId of /* @__PURE__ */ new Set([...includedTags, ...excludedTags])) {
1970
+ let filterDef = BUILT_IN_FILTERS[tagId];
1971
+ storyCounts[tagId] = entries.filter((entry) => filterDef(entry)).length;
1972
+ }
1973
+ if (includedStatuses.length > 0 || excludedStatuses.length > 0) {
1974
+ let statusCounts = countStatusesByValue(fullStatusStore.getAll());
1975
+ for (let statusValue of /* @__PURE__ */ new Set([...includedStatuses, ...excludedStatuses]))
1976
+ statusCounts[statusValue] !== void 0 && (storyCounts[statusValue] = statusCounts[statusValue]);
1977
+ }
1978
+ provider.channel?.emit(SIDEBAR_FILTER_CHANGED, {
1979
+ trigger,
1980
+ changed,
1981
+ activeTagFilters: { included: includedTags, excluded: excludedTags },
1982
+ activeStatusFilters: { included: includedStatuses, excluded: excludedStatuses },
1983
+ storyCounts
1984
+ });
1985
+ }, api = {
1986
+ storyId: toId,
1987
+ getData: (storyId, refId) => {
1988
+ let result = api.resolveStory(storyId, refId);
1989
+ if (result?.type === "story" || result?.type === "docs")
1990
+ return result;
1991
+ },
1992
+ isPrepared: (storyId, refId) => {
1993
+ let data = api.getData(storyId, refId);
1994
+ return data ? data.type === "story" ? data.prepared : !0 : !1;
1995
+ },
1996
+ resolveStory: (storyId, refId) => {
1997
+ let { refs, index } = store2.getState();
1998
+ if (!(refId && !refs[refId]))
1999
+ return refId ? refs?.[refId]?.index?.[storyId] ?? void 0 : index ? index[storyId] : void 0;
2000
+ },
2001
+ getCurrentStoryData: () => {
2002
+ let { storyId, refId } = store2.getState();
2003
+ return api.getData(storyId, refId);
2004
+ },
2005
+ getIndex: () => {
2006
+ let { internal_index } = store2.getState();
2007
+ return internal_index;
2008
+ },
2009
+ getParameters: (storyIdOrCombo, parameterName) => {
2010
+ let { storyId, refId } = typeof storyIdOrCombo == "string" ? { storyId: storyIdOrCombo, refId: void 0 } : storyIdOrCombo, data = api.getData(storyId, refId);
2011
+ if (["story", "docs"].includes(data?.type)) {
2012
+ let { parameters } = data;
2013
+ if (parameters)
2014
+ return parameterName ? parameters[parameterName] : parameters;
2015
+ }
2016
+ return null;
2017
+ },
2018
+ getCurrentParameter: (parameterName) => {
2019
+ let { storyId, refId } = store2.getState();
2020
+ return api.getParameters({ storyId, refId }, parameterName) || void 0;
2021
+ },
2022
+ jumpToComponent: (direction) => {
2023
+ let { filteredIndex, storyId, refs, refId } = store2.getState();
2024
+ if (!api.getData(storyId, refId))
2025
+ return;
2026
+ let hash = refId ? refs[refId].filteredIndex || {} : filteredIndex;
2027
+ if (!hash)
2028
+ return;
2029
+ let result = api.findSiblingStoryId(storyId, hash, direction, !0);
2030
+ result && api.selectStory(result, void 0, { ref: refId });
2031
+ },
2032
+ jumpToStory: (direction) => {
2033
+ let { filteredIndex, storyId, refs, refId } = store2.getState(), story = api.getData(storyId, refId);
2034
+ if (!story)
2035
+ return;
2036
+ let hash = story.refId ? refs[story.refId].filteredIndex : filteredIndex;
2037
+ if (!hash)
2038
+ return;
2039
+ let result = api.findSiblingStoryId(storyId, hash, direction, !1);
2040
+ result && api.selectStory(result, void 0, { ref: refId });
2041
+ },
2042
+ selectFirstStory: () => {
2043
+ let state = store2.getState(), { filteredIndex } = state;
2044
+ if (filteredIndex) {
2045
+ let firstStory2 = Object.keys(filteredIndex).find(
2046
+ (id) => filteredIndex[id].type === "story"
2047
+ );
2048
+ firstStory2 && api.selectStory(firstStory2);
2049
+ return;
2050
+ }
2051
+ let { index } = state;
2052
+ if (!index)
2053
+ return;
2054
+ let firstStory = Object.keys(index).find((id) => index[id].type === "story");
2055
+ if (firstStory) {
2056
+ api.selectStory(firstStory);
2057
+ return;
2058
+ }
2059
+ navigateWithQueryParams("/");
2060
+ },
2061
+ selectStory: (titleOrId = void 0, name = void 0, options = {}) => {
2062
+ let { ref, scrollTo } = options, { storyId, index, filteredIndex, refs, settings } = store2.getState(), gotoStory = (entry) => entry?.type === "docs" || entry?.type === "story" ? (store2.setState({ settings: { ...settings, lastTrackedStoryId: entry.id } }), navigateWithQueryParams(
2063
+ `/${entry.type}/${entry.refId ? `${entry.refId}_${entry.id}` : entry.id}${scrollTo ? `#${scrollTo}` : ""}`
2064
+ ), !0) : !1, kindSlug = storyId?.split("--", 2)[0], hash = ref ? refs[ref].index : index, filteredHash = ref ? refs[ref].filteredIndex : filteredIndex;
2065
+ if (!(!hash || !filteredHash))
2066
+ if (name)
2067
+ if (!titleOrId)
2068
+ gotoStory(hash[toId(kindSlug, name)]);
2069
+ else {
2070
+ let id = ref ? `${ref}_${toId(titleOrId, name)}` : toId(titleOrId, name);
2071
+ if (hash[id])
2072
+ gotoStory(hash[id]);
2073
+ else {
2074
+ let entry = hash[sanitize2(titleOrId)];
2075
+ if (entry?.type === "component") {
2076
+ let foundId = entry.children.find((childId) => hash[childId].name === name);
2077
+ gotoStory(foundId ? hash[foundId] : void 0);
2078
+ }
2079
+ }
2080
+ }
2081
+ else {
2082
+ let entry = titleOrId ? hash[titleOrId] || hash[sanitize2(titleOrId)] : hash[kindSlug];
2083
+ if (!entry)
2084
+ throw new Error(`Unknown id or title: '${titleOrId}'`);
2085
+ gotoStory(entry) || gotoStory(api.findLeafEntry(filteredHash, entry.id));
2086
+ }
2087
+ },
2088
+ findLeafEntry(index, storyId) {
2089
+ let entry = index[storyId];
2090
+ if (!entry)
2091
+ return;
2092
+ if (entry.type === "docs" || entry.type === "story")
2093
+ return entry;
2094
+ let childStoryId = entry.children.find((childId) => index[childId]);
2095
+ return childStoryId ? api.findLeafEntry(index, childStoryId) : void 0;
2096
+ },
2097
+ findLeafStoryId(index, storyId) {
2098
+ return api.findLeafEntry(index, storyId)?.id;
2099
+ },
2100
+ findAllLeafStoryIds(entryId) {
2101
+ let { index } = store2.getState();
2102
+ if (!index)
2103
+ return [];
2104
+ let findChildEntriesRecursively = (currentEntryId, results = []) => {
2105
+ let node = index[currentEntryId];
2106
+ return node && (node.type === "story" && results.push(node.id), "children" in node && node.children?.forEach((childId) => findChildEntriesRecursively(childId, results))), results;
2107
+ };
2108
+ return findChildEntriesRecursively(entryId, []);
2109
+ },
2110
+ findSiblingStoryId(storyId, index, direction, toSiblingGroup) {
2111
+ if (toSiblingGroup) {
2112
+ let lookupList2 = getComponentLookupList(index), position2 = lookupList2.findIndex((i) => i.includes(storyId));
2113
+ return position2 === lookupList2.length - 1 && direction > 0 || position2 === 0 && direction < 0 ? void 0 : lookupList2[position2 + direction] ? lookupList2[position2 + direction][0] : void 0;
2114
+ }
2115
+ let lookupList = getStoriesLookupList(index), position = lookupList.indexOf(storyId);
2116
+ if (!(position === lookupList.length - 1 && direction > 0) && !(position === 0 && direction < 0))
2117
+ return lookupList[position + direction];
2118
+ },
2119
+ updateStoryArgs: (story, updatedArgs) => {
2120
+ let { id: storyId, refId } = story;
2121
+ provider.channel?.emit(UPDATE_STORY_ARGS, {
2122
+ storyId,
2123
+ updatedArgs,
2124
+ options: { target: refId }
2125
+ });
2126
+ },
2127
+ resetStoryArgs: (story, argNames) => {
2128
+ let { id: storyId, refId } = story;
2129
+ provider.channel?.emit(RESET_STORY_ARGS, {
2130
+ storyId,
2131
+ argNames,
2132
+ options: { target: refId }
2133
+ });
2134
+ },
2135
+ fetchIndex: async () => {
2136
+ try {
2137
+ let result = await fetch2(STORY_INDEX_PATH);
2138
+ if (result.status !== 200)
2139
+ throw new Error(await result.text());
2140
+ let storyIndex = await result.json();
2141
+ if (storyIndex.v < 3) {
2142
+ logger7.warn(`Skipping story index with version v${storyIndex.v}, awaiting SET_STORIES.`);
2143
+ return;
2144
+ }
2145
+ await api.setIndex(storyIndex);
2146
+ } catch (err) {
2147
+ await store2.setState({ indexError: err });
2148
+ }
2149
+ },
2150
+ // The story index we receive on SET_INDEX is "prepared" in that it has parameters
2151
+ // The story index we receive on fetchStoryIndex is not, but all the prepared fields are optional
2152
+ // so we can cast one to the other easily enough
2153
+ setIndex: async (input) => {
2154
+ let { filteredIndex: oldFilteredHash, index: oldHash, filters } = store2.getState(), allStatuses = fullStatusStore.getAll(), newFilteredHash = transformStoryIndexToStoriesHash(input, {
2155
+ provider,
2156
+ docsOptions,
2157
+ filters,
2158
+ allStatuses,
2159
+ statusFilterKey: STATUS_FILTER
2160
+ }), newHash = transformStoryIndexToStoriesHash(input, {
2161
+ provider,
2162
+ docsOptions,
2163
+ filters: {},
2164
+ allStatuses
2165
+ });
2166
+ await store2.setState({
2167
+ internal_index: input,
2168
+ filteredIndex: addPreparedStories(newFilteredHash, oldFilteredHash),
2169
+ index: addPreparedStories(newHash, oldHash),
2170
+ indexError: void 0
2171
+ });
2172
+ },
2173
+ // FIXME: is there a bug where filtered stories get added back in on updateStory???
2174
+ updateStory: async (storyId, update2, ref) => {
2175
+ if (ref) {
2176
+ let { id: refId, index, filteredIndex } = ref, storyUpdates = {
2177
+ ...ref.storyUpdates,
2178
+ [storyId]: { ...ref.storyUpdates?.[storyId], ...update2 }
2179
+ };
2180
+ index && index[storyId] && (index[storyId] = {
2181
+ ...index[storyId],
2182
+ ...update2
2183
+ }), filteredIndex && filteredIndex[storyId] && (filteredIndex[storyId] = {
2184
+ ...filteredIndex[storyId],
2185
+ ...update2
2186
+ }), await fullAPI.updateRef(refId, { index, filteredIndex, storyUpdates });
2187
+ } else {
2188
+ let { index, filteredIndex } = store2.getState();
2189
+ index && index[storyId] && (index[storyId] = {
2190
+ ...index[storyId],
2191
+ ...update2
2192
+ }), filteredIndex && filteredIndex[storyId] && (filteredIndex[storyId] = {
2193
+ ...filteredIndex[storyId],
2194
+ ...update2
2195
+ }), (index || filteredIndex) && await store2.setState({ index, filteredIndex });
2196
+ }
2197
+ },
2198
+ updateDocs: async (docsId, update2, ref) => {
2199
+ if (ref) {
2200
+ let { id: refId, index, filteredIndex } = ref, storyUpdates = {
2201
+ ...ref.storyUpdates,
2202
+ [docsId]: { ...ref.storyUpdates?.[docsId], ...update2 }
2203
+ };
2204
+ index && index[docsId] && (index[docsId] = {
2205
+ ...index[docsId],
2206
+ ...update2
2207
+ }), filteredIndex && filteredIndex[docsId] && (filteredIndex[docsId] = {
2208
+ ...filteredIndex[docsId],
2209
+ ...update2
2210
+ }), await fullAPI.updateRef(refId, { index, filteredIndex, storyUpdates });
2211
+ } else {
2212
+ let { index, filteredIndex } = store2.getState();
2213
+ index && (index[docsId] = {
2214
+ ...index[docsId],
2215
+ ...update2
2216
+ }), filteredIndex && (filteredIndex[docsId] = {
2217
+ ...filteredIndex[docsId],
2218
+ ...update2
2219
+ }), (index || filteredIndex) && await store2.setState({ index, filteredIndex });
2220
+ }
2221
+ },
2222
+ setPreviewInitialized: async (ref) => {
2223
+ ref ? fullAPI.updateRef(ref.id, { previewInitialized: !0 }) : store2.setState({ previewInitialized: !0 });
2224
+ },
2225
+ setFilter: async (id, filterFunction) => {
2226
+ await api.setFilters({ [id]: filterFunction });
2227
+ },
2228
+ setFilters: async (filters) => {
2229
+ if (await store2.setState((state) => ({ filters: { ...state.filters, ...filters } })), !!await applyCurrentFilters())
2230
+ for (let id of Object.keys(filters))
2231
+ provider.channel?.emit(SET_FILTER, { id });
2232
+ },
2233
+ resetTagFilters: async () => {
2234
+ await persistFilters((s) => ({
2235
+ includedTagFilters: s.defaultIncludedTagFilters,
2236
+ excludedTagFilters: s.defaultExcludedTagFilters
2237
+ })), await recomputeTagsFilter();
2238
+ },
2239
+ setAllTagFilters: async (included, excluded) => {
2240
+ await persistFilters({ includedTagFilters: included, excludedTagFilters: excluded }), await recomputeTagsFilter();
2241
+ },
2242
+ addTagFilters: async (tags2, excluded) => {
2243
+ await addFilters("tag", tags2, excluded), await recomputeTagsFilter(), tags2.length === 1 && BUILT_IN_TAG_IDS.has(tags2[0]) && emitFilterTelemetry("interaction", {
2244
+ filterType: "tag",
2245
+ filterId: tags2[0],
2246
+ action: excluded ? "exclude" : "include"
2247
+ });
2248
+ },
2249
+ removeTagFilters: async (tags2) => {
2250
+ await removeFilters("tag", tags2), await recomputeTagsFilter(), tags2.length === 1 && BUILT_IN_TAG_IDS.has(tags2[0]) && emitFilterTelemetry("interaction", {
2251
+ filterType: "tag",
2252
+ filterId: tags2[0],
2253
+ action: "remove"
2254
+ });
2255
+ },
2256
+ resetStatusFilters: async () => {
2257
+ await persistFilters({ includedStatusFilters: [], excludedStatusFilters: [] }), await recomputeStatusFilter();
2258
+ },
2259
+ setAllStatusFilters: async (included, excluded) => {
2260
+ let prevState = store2.getState(), prevIncluded = new Set(prevState.includedStatusFilters ?? []), prevExcluded = new Set(prevState.excludedStatusFilters ?? []), nextIncluded = new Set(included), nextExcluded = new Set(excluded);
2261
+ await persistFilters({ includedStatusFilters: included, excludedStatusFilters: excluded }), await recomputeStatusFilter();
2262
+ let changedIds = /* @__PURE__ */ new Set([
2263
+ ...prevIncluded,
2264
+ ...prevExcluded,
2265
+ ...nextIncluded,
2266
+ ...nextExcluded
2267
+ ]);
2268
+ for (let id of changedIds) {
2269
+ let wasIncluded = prevIncluded.has(id), wasExcluded = prevExcluded.has(id), isIncluded = nextIncluded.has(id), isExcluded = nextExcluded.has(id);
2270
+ if (wasIncluded === isIncluded && wasExcluded === isExcluded)
2271
+ continue;
2272
+ let action;
2273
+ isIncluded ? action = "include" : isExcluded ? action = "exclude" : action = "remove", emitFilterTelemetry("interaction", {
2274
+ filterType: "status",
2275
+ filterId: id,
2276
+ action
2277
+ });
2278
+ }
2279
+ },
2280
+ addStatusFilters: async (statuses2, excluded) => {
2281
+ await addFilters("status", statuses2, excluded), await recomputeStatusFilter(), statuses2.length === 1 && emitFilterTelemetry("interaction", {
2282
+ filterType: "status",
2283
+ filterId: statuses2[0],
2284
+ action: excluded ? "exclude" : "include"
2285
+ });
2286
+ },
2287
+ removeStatusFilters: async (statuses2) => {
2288
+ await removeFilters("status", statuses2), await recomputeStatusFilter(), statuses2.length === 1 && emitFilterTelemetry("interaction", {
2289
+ filterType: "status",
2290
+ filterId: statuses2[0],
2291
+ action: "remove"
2292
+ });
2293
+ }
2294
+ }, applyCurrentFilters = async () => {
2295
+ let { internal_index: index } = store2.getState();
2296
+ if (!index)
2297
+ return !1;
2298
+ await api.setIndex(index);
2299
+ let refs = await fullAPI.getRefs();
2300
+ for (let [refId, { internal_index, ...ref }] of Object.entries(refs))
2301
+ await fullAPI.setRef(refId, { ...ref, storyIndex: internal_index }, !0);
2302
+ return !0;
2303
+ }, statusFilterRebuildQueued = !1, statusFilterRebuildInFlight = !1, flushStatusFilterRebuild = async () => {
2304
+ if (!statusFilterRebuildInFlight) {
2305
+ statusFilterRebuildInFlight = !0;
2306
+ try {
2307
+ for (; statusFilterRebuildQueued; ) {
2308
+ statusFilterRebuildQueued = !1;
2309
+ try {
2310
+ await applyCurrentFilters();
2311
+ } catch (error) {
2312
+ logger7.warn("Failed to rebuild story index after status change:", error);
2313
+ }
2314
+ }
2315
+ } finally {
2316
+ statusFilterRebuildInFlight = !1, statusFilterRebuildQueued && flushStatusFilterRebuild();
2317
+ }
2318
+ }
2319
+ }, requestStatusFilterRebuild = () => {
2320
+ statusFilterRebuildQueued = !0, flushStatusFilterRebuild();
2321
+ }, recomputeTagsFilter = () => {
2322
+ let { includedTagFilters, excludedTagFilters } = store2.getState();
2323
+ return api.setFilters({
2324
+ [TAGS_FILTER]: computeTagsFilterFn(includedTagFilters, excludedTagFilters)
2325
+ });
2326
+ }, recomputeStatusFilter = () => {
2327
+ let { includedStatusFilters, excludedStatusFilters } = store2.getState();
2328
+ return api.setFilters({
2329
+ [STATUS_FILTER]: computeStatusFilterFn(
2330
+ includedStatusFilters ?? [],
2331
+ excludedStatusFilters ?? []
2332
+ )
2333
+ });
2334
+ };
2335
+ provider.channel?.on(
2336
+ STORY_SPECIFIED,
2337
+ function({
2338
+ storyId,
2339
+ viewMode
2340
+ }) {
2341
+ let { sourceType } = getEventMetadata(this, fullAPI);
2342
+ if (sourceType === "local") {
2343
+ let state = store2.getState(), isCanvasRoute = !isReviewManagerRoute(state.path, state.customQueryParams) && (state.path === "/" || state.viewMode === "story" || state.viewMode === "docs"), stateHasSelection = state.viewMode && state.storyId, stateSelectionDifferent = state.viewMode !== viewMode || state.storyId !== storyId, { type } = state.index?.[state.storyId] || {}, isStory = !(type === "root" || type === "component" || type === "group");
2344
+ if (isCanvasRoute) {
2345
+ let { filteredIndex } = state;
2346
+ if (filteredIndex && !stateHasSelection && !(filteredIndex[storyId]?.type === "story")) {
2347
+ let firstFiltered = filteredIndex ? Object.keys(filteredIndex).find((id) => {
2348
+ let entry = filteredIndex[id];
2349
+ return entry.type === "story" || entry.type === "docs";
2350
+ }) : void 0;
2351
+ firstFiltered && navigateWithQueryParams(`/${viewMode}/${firstFiltered}`);
2352
+ return;
2353
+ }
2354
+ stateHasSelection && stateSelectionDifferent && isStory ? provider.channel?.emit(SET_CURRENT_STORY, {
2355
+ storyId: state.storyId,
2356
+ viewMode: state.viewMode
2357
+ }) : stateSelectionDifferent && navigateWithQueryParams(`/${viewMode}/${storyId}`);
2358
+ }
2359
+ }
2360
+ }
2361
+ ), provider.channel?.on(CURRENT_STORY_WAS_SET, function() {
2362
+ let { ref } = getEventMetadata(this, fullAPI);
2363
+ api.setPreviewInitialized(ref);
2364
+ }), provider.channel?.on(STORY_CHANGED, function() {
2365
+ let { sourceType } = getEventMetadata(this, fullAPI);
2366
+ if (sourceType === "local") {
2367
+ let options = api.getCurrentParameter("options");
2368
+ options && fullAPI.setOptions(removeRemovedOptions(options));
2369
+ }
2370
+ }), provider.channel?.on(
2371
+ STORY_PREPARED,
2372
+ function({ id, ...update2 }) {
2373
+ let { ref, sourceType } = getEventMetadata(this, fullAPI);
2374
+ if (api.updateStory(id, { ...update2, prepared: !0 }, ref), !ref && !store2.getState().hasCalledSetOptions) {
2375
+ let { options } = update2.parameters;
2376
+ fullAPI.setOptions(removeRemovedOptions(options)), store2.setState({ hasCalledSetOptions: !0 });
2377
+ }
2378
+ if (sourceType === "local") {
2379
+ let { storyId, index, refId } = store2.getState();
2380
+ if (!index)
2381
+ return;
2382
+ let toBePreloaded = Array.from(
2383
+ /* @__PURE__ */ new Set([
2384
+ api.findSiblingStoryId(storyId, index, 1, !0),
2385
+ api.findSiblingStoryId(storyId, index, -1, !0)
2386
+ ])
2387
+ ).filter(Boolean);
2388
+ provider.channel?.emit(PRELOAD_ENTRIES, {
2389
+ ids: toBePreloaded,
2390
+ options: { target: refId }
2391
+ });
2392
+ }
2393
+ }
2394
+ ), provider.channel?.on(
2395
+ DOCS_PREPARED,
2396
+ function({ id, ...update2 }) {
2397
+ let { ref } = getEventMetadata(this, fullAPI);
2398
+ api.updateStory(id, { ...update2, prepared: !0 }, ref);
2399
+ }
2400
+ ), provider.channel?.on(SET_INDEX, function(index) {
2401
+ let { ref } = getEventMetadata(this, fullAPI);
2402
+ if (ref)
2403
+ fullAPI.setRef(ref.id, { ...ref, storyIndex: index }, !0);
2404
+ else {
2405
+ api.setIndex(index);
2406
+ let options = api.getCurrentParameter("options");
2407
+ fullAPI.setOptions(removeRemovedOptions(options));
2408
+ }
2409
+ }), provider.channel?.on(SET_STORIES, function(data) {
2410
+ let { ref } = getEventMetadata(this, fullAPI), setStoriesData = data.v ? denormalizeStoryParameters(data) : data.stories;
2411
+ if (ref)
2412
+ fullAPI.setRef(ref.id, { ...ref, setStoriesData }, !0);
2413
+ else
2414
+ throw new Error("Cannot call SET_STORIES for local frame");
2415
+ }), provider.channel?.on(
2416
+ SELECT_STORY,
2417
+ function({
2418
+ kind,
2419
+ title = kind,
2420
+ story,
2421
+ name = story,
2422
+ storyId,
2423
+ ...rest
2424
+ }) {
2425
+ let { ref } = getEventMetadata(this, fullAPI);
2426
+ ref ? fullAPI.selectStory(storyId || title, name, { ...rest, ref: ref.id }) : fullAPI.selectStory(storyId || title, name, rest);
2427
+ }
2428
+ ), provider.channel?.on(
2429
+ STORY_ARGS_UPDATED,
2430
+ function({ storyId, args }) {
2431
+ let { ref } = getEventMetadata(this, fullAPI);
2432
+ api.updateStory(storyId, { args }, ref);
2433
+ }
2434
+ ), provider.channel?.on(CONFIG_ERROR, function(err) {
2435
+ let { ref } = getEventMetadata(this, fullAPI);
2436
+ api.setPreviewInitialized(ref);
2437
+ }), provider.channel?.on(STORY_MISSING, function(err) {
2438
+ let { ref } = getEventMetadata(this, fullAPI);
2439
+ api.setPreviewInitialized(ref);
2440
+ }), provider.channel?.on(SET_CONFIG3, async () => {
2441
+ let {
2442
+ includedTagFilters,
2443
+ excludedTagFilters,
2444
+ includedStatusFilters,
2445
+ excludedStatusFilters,
2446
+ tagPresets: tagPresets2
2447
+ } = store2.getState();
2448
+ await api.setFilters({
2449
+ [STATIC_FILTER]: computeStaticFilterFn(tagPresets2),
2450
+ [TAGS_FILTER]: computeTagsFilterFn(includedTagFilters, excludedTagFilters),
2451
+ [STATUS_FILTER]: computeStatusFilterFn(includedStatusFilters, excludedStatusFilters)
2452
+ });
2453
+ }), fullStatusStore.onAllStatusChange(
2454
+ throttle(requestStatusFilterRebuild, STATUS_CHANGE_REBUILD_THROTTLE, {
2455
+ edges: ["leading", "trailing"]
2456
+ })
2457
+ );
2458
+ let tagPresets = global5.TAGS_OPTIONS || {}, defaultTags = getDefaultTagsFromPreset(tagPresets), { tags, statuses } = queryFromLocation(location2 ?? { search: "" }), parsedTags = parseTagsParam(tags), hasTagsParam = tags !== void 0, initialIncluded = hasTagsParam ? parsedTags.included : defaultTags.included, initialExcluded = hasTagsParam ? parsedTags.excluded : defaultTags.excluded, parsedStatuses = parseStatusesParam(statuses), initialIncludedStatuses = parsedStatuses.included, initialExcludedStatuses = parsedStatuses.excluded, initialFilters = {
2459
+ [STATIC_FILTER]: computeStaticFilterFn(tagPresets),
2460
+ [TAGS_FILTER]: computeTagsFilterFn(initialIncluded, initialExcluded),
2461
+ [STATUS_FILTER]: computeStatusFilterFn(initialIncludedStatuses, initialExcludedStatuses)
2462
+ };
2463
+ return {
2464
+ api,
2465
+ state: {
2466
+ storyId: initialStoryId,
2467
+ viewMode: initialViewMode,
2468
+ hasCalledSetOptions: !1,
2469
+ previewInitialized: !1,
2470
+ filters: initialFilters,
2471
+ tagPresets,
2472
+ defaultIncludedTagFilters: defaultTags.included,
2473
+ defaultExcludedTagFilters: defaultTags.excluded,
2474
+ includedTagFilters: initialIncluded,
2475
+ excludedTagFilters: initialExcluded,
2476
+ includedStatusFilters: initialIncludedStatuses,
2477
+ excludedStatusFilters: initialExcludedStatuses
2478
+ },
2479
+ init: async () => {
2480
+ if (provider.channel?.on(STORY_INDEX_INVALIDATED, () => api.fetchIndex()), await api.fetchIndex(), urlFilterTelemetryEmitted)
2481
+ return;
2482
+ urlFilterTelemetryEmitted = !0;
2483
+ let hasBuiltInTagFilters = initialIncluded.some((id) => BUILT_IN_TAG_IDS.has(id)) || initialExcluded.some((id) => BUILT_IN_TAG_IDS.has(id)), hasStatusFilters = initialIncludedStatuses.length > 0 || initialExcludedStatuses.length > 0;
2484
+ (hasBuiltInTagFilters || hasStatusFilters) && emitFilterTelemetry("url");
2485
+ }
2486
+ };
2487
+ };
2488
+
2489
+ // src/manager-api/modules/url.ts
2490
+ var url_exports = {};
2491
+ __export(url_exports, {
2492
+ getCustomQueryParams: () => getCustomQueryParams,
2493
+ init: () => init12
2494
+ });
2495
+ import {
2496
+ GLOBALS_UPDATED as GLOBALS_UPDATED2,
2497
+ NAVIGATE_URL,
2498
+ SET_CURRENT_STORY as SET_CURRENT_STORY2,
2499
+ STORY_ARGS_UPDATED as STORY_ARGS_UPDATED2,
2500
+ UPDATE_QUERY_PARAMS
2501
+ } from "@aussieljk/forkbook/internal/core-events";
2502
+ import { buildArgsParam, queryFromLocation as queryFromLocation2 } from "@aussieljk/forkbook/internal/router";
2503
+ import { global as global6 } from "@storybook/global";
2504
+ var parseBoolean = (value) => {
2505
+ if (value === "true" || value === "1")
2506
+ return !0;
2507
+ if (value === "false" || value === "0")
2508
+ return !1;
2509
+ }, parseSerializedParam = (param) => Object.fromEntries(
2510
+ param.split(";").map((pair) => pair.split(":")).map(([key, value]) => [key, encodeURIComponent(value)]).filter(([key, value]) => key && value)
2511
+ ), mergeSerializedParams = (params, extraParams) => {
2512
+ let pairs = parseSerializedParam(params), extra = parseSerializedParam(extraParams);
2513
+ return Object.entries({ ...pairs, ...extra }).map(([key, value]) => `${key}:${value}`).join(";");
2514
+ }, resolveIframeUrl = (baseUrl, { absolute }) => {
2515
+ let resolved = new URL("iframe.html", baseUrl);
2516
+ return absolute ? resolved.href : `${resolved.pathname}${resolved.search}${resolved.hash}`;
2517
+ }, LAYOUT_QUERY_PARAM_KEYS = ["full", "panel", "nav", "shortcuts", "addonPanel", "tabs", "path"], getCustomQueryParams = (location2) => omit(queryFromLocation2(location2), LAYOUT_QUERY_PARAM_KEYS), prevParams, initialUrlSupport = ({
2518
+ state: { location: location2, path, viewMode, storyId: storyIdFromUrl },
2519
+ singleStory
2520
+ }) => {
2521
+ let { full, panel, nav, shortcuts, addonPanel } = queryFromLocation2(location2), navSize, bottomPanelHeight, rightPanelWidth;
2522
+ parseBoolean(full) === !0 ? (navSize = 0, bottomPanelHeight = 0, rightPanelWidth = 0) : parseBoolean(full) === !1 && (navSize = DEFAULT_NAV_SIZE, bottomPanelHeight = DEFAULT_BOTTOM_PANEL_HEIGHT, rightPanelWidth = DEFAULT_RIGHT_PANEL_WIDTH), singleStory || (parseBoolean(nav) === !0 && (navSize = DEFAULT_NAV_SIZE), parseBoolean(nav) === !1 && (navSize = 0)), parseBoolean(panel) === !1 && (bottomPanelHeight = 0, rightPanelWidth = 0);
2523
+ let layout = {
2524
+ navSize,
2525
+ bottomPanelHeight,
2526
+ rightPanelWidth,
2527
+ panelPosition: ["right", "bottom"].includes(panel) ? panel : void 0
2528
+ }, ui = {
2529
+ enableShortcuts: parseBoolean(shortcuts)
2530
+ }, selectedPanel = addonPanel || void 0, storyId = storyIdFromUrl, otherParams = getCustomQueryParams(location2), customQueryParams = dequal(prevParams, otherParams) ? prevParams : otherParams;
2531
+ return prevParams = customQueryParams, { viewMode, layout, ui, selectedPanel, location: location2, path, customQueryParams, storyId };
2532
+ }, init12 = (moduleArgs) => {
2533
+ let { store: store2, navigate, provider, fullAPI } = moduleArgs, navigateTo = (path, queryParams = {}, options = {}) => navigate(buildNavigationUrl(path, queryParams), options), api = {
2534
+ getStoryHrefs(storyId, options = {}) {
2535
+ let { id: currentStoryId, refId: currentRefId } = fullAPI.getCurrentStoryData() ?? {}, isCurrentStory = storyId === currentStoryId && options.refId === currentRefId, { customQueryParams, location: location2, refs } = store2.getState(), {
2536
+ base,
2537
+ inheritArgs = isCurrentStory,
2538
+ inheritGlobals = !0,
2539
+ queryParams = {},
2540
+ refId,
2541
+ viewMode = "story",
2542
+ embed = !1,
2543
+ freeze = !1
2544
+ } = options;
2545
+ if (refId && !refs[refId])
2546
+ throw new Error(`Invalid refId: ${refId}`);
2547
+ let pathname = location2.pathname || "/", originAddress = global6.window.location.origin + pathname, networkAddress = global6.FORKBOOK_NETWORK_ADDRESS ?? originAddress, managerBase = base === "origin" ? originAddress : base === "network" ? networkAddress : pathname, previewBaseUrl = base ? managerBase : global6.document?.baseURI || originAddress, previewBase = refId ? refs[refId].url + "/iframe.html" : resolveIframeUrl(previewBaseUrl, { absolute: !!base }), refParam = refId ? `&refId=${encodeURIComponent(refId)}` : "", { args = "", globals = "", ...otherParams } = queryParams, argsParam = inheritArgs ? mergeSerializedParams(customQueryParams?.args ?? "", args) : args, globalsParam = inheritGlobals ? mergeSerializedParams(customQueryParams?.globals ?? "", globals) : globals, managerQueryParams = omit(otherParams, ["embed", "freeze"]), previewQueryParams = omit(otherParams, ["id", "viewMode", "embed", "freeze"]), customManagerParams = stringify(managerQueryParams, {
2548
+ nesting: !0,
2549
+ nestingSyntax: "js"
2550
+ }), customPreviewParams = stringify(previewQueryParams, {
2551
+ nesting: !0,
2552
+ nestingSyntax: "js"
2553
+ });
2554
+ argsParam = argsParam && `&args=${argsParam}`, globalsParam = globalsParam && `&globals=${globalsParam}`, customManagerParams = customManagerParams && `&${customManagerParams}`, customPreviewParams = customPreviewParams && `&${customPreviewParams}`;
2555
+ let embedParam = embed ? "&embed=true" : "", freezeParam = freeze ? "&freeze=finished" : "";
2556
+ return {
2557
+ managerHref: `${managerBase}?path=/${viewMode}/${refId ? `${refId}_` : ""}${storyId}${argsParam}${globalsParam}${customManagerParams}`,
2558
+ previewHref: `${previewBase}?id=${storyId}&viewMode=${viewMode}${refParam}${argsParam}${refId ? "" : globalsParam}${customPreviewParams}${embedParam}${freezeParam}`
2559
+ };
2560
+ },
2561
+ getQueryParam(key) {
2562
+ let { customQueryParams } = store2.getState();
2563
+ return customQueryParams ? customQueryParams[key] : void 0;
2564
+ },
2565
+ getUrlState() {
2566
+ let { location: location2, path, customQueryParams, storyId, url, viewMode } = store2.getState();
2567
+ return {
2568
+ path,
2569
+ hash: location2?.hash ?? "",
2570
+ queryParams: customQueryParams,
2571
+ storyId,
2572
+ url,
2573
+ viewMode
2574
+ };
2575
+ },
2576
+ setQueryParams(input) {
2577
+ let { customQueryParams } = store2.getState(), update2 = { ...customQueryParams };
2578
+ for (let [key, value] of Object.entries(input))
2579
+ value == null ? delete update2[key] : update2[key] = value;
2580
+ dequal(customQueryParams, update2) || (store2.setState({ customQueryParams: update2 }), provider.channel?.emit(UPDATE_QUERY_PARAMS, update2));
2581
+ },
2582
+ applyQueryParams(input, options) {
2583
+ let { path, hash = "", queryParams } = api.getUrlState();
2584
+ navigateTo(`${path}${hash}`, { ...queryParams, ...input }, options), api.setQueryParams(input);
2585
+ },
2586
+ navigateUrl(url, options) {
2587
+ navigate(url, { plain: !0, ...options });
2588
+ }
2589
+ }, updateArgsParam = () => {
2590
+ let { path, hash = "", queryParams, viewMode } = api.getUrlState();
2591
+ if (viewMode !== "story")
2592
+ return;
2593
+ let currentStory = fullAPI.getCurrentStoryData();
2594
+ if (currentStory?.type !== "story")
2595
+ return;
2596
+ let { args, initialArgs } = currentStory, argsString = buildArgsParam(initialArgs, args);
2597
+ navigateTo(`${path}${hash}`, { ...queryParams, args: argsString || null }, { replace: !0 }), api.setQueryParams({ args: argsString || null });
2598
+ };
2599
+ provider.channel?.on(SET_CURRENT_STORY2, () => updateArgsParam());
2600
+ let handleOrId;
2601
+ return provider.channel?.on(STORY_ARGS_UPDATED2, () => {
2602
+ "requestIdleCallback" in global6.window ? (handleOrId && global6.window.cancelIdleCallback(handleOrId), handleOrId = global6.window.requestIdleCallback(updateArgsParam, { timeout: 1e3 })) : (handleOrId && clearTimeout(handleOrId), setTimeout(updateArgsParam, 100));
2603
+ }), provider.channel?.on(GLOBALS_UPDATED2, ({ userGlobals, initialGlobals }) => {
2604
+ let { path, hash = "", queryParams } = api.getUrlState(), globalsString = buildArgsParam(initialGlobals, merge_default(initialGlobals, userGlobals));
2605
+ navigateTo(
2606
+ `${path}${hash}`,
2607
+ { ...queryParams, globals: globalsString || null },
2608
+ { replace: !0 }
2609
+ ), api.setQueryParams({ globals: globalsString || null });
2610
+ }), provider.channel?.on(NAVIGATE_URL, (url, options) => {
2611
+ api.navigateUrl(url, options);
2612
+ }), {
2613
+ api,
2614
+ state: initialUrlSupport(moduleArgs),
2615
+ init: () => {
2616
+ store2.registerPersistenceHandler("url", (_patch, serialize) => {
2617
+ if (serialize) {
2618
+ let params = serialize(store2.getState());
2619
+ api.applyQueryParams(params, { replace: !0 });
2620
+ }
2621
+ });
2622
+ }
2623
+ };
2624
+ };
2625
+
2626
+ // src/manager-api/modules/versions.ts
2627
+ var versions_exports = {};
2628
+ __export(versions_exports, {
2629
+ init: () => init13
2630
+ });
2631
+ var import_memoizerific3 = __toESM(require_memoizerific(), 1);
2632
+ import { global as global7 } from "@storybook/global";
2633
+ import semver from "semver";
2634
+
2635
+ // src/manager-api/version.ts
2636
+ var version = "11.0.0-alpha.6";
2637
+
2638
+ // src/manager-api/modules/versions.ts
2639
+ var { VERSIONCHECK } = global7, getVersionCheckData = (0, import_memoizerific3.default)(1)(() => {
2640
+ try {
2641
+ return { ...JSON.parse(VERSIONCHECK).data || {} };
2642
+ } catch {
2643
+ return {};
2644
+ }
2645
+ }), normalizeRendererName = (renderer) => renderer.includes("vue") ? "vue" : renderer, init13 = ({ store: store2 }) => {
2646
+ let { dismissedVersionNotification } = store2.getState(), state = {
2647
+ versions: {
2648
+ current: {
2649
+ version
2650
+ },
2651
+ ...getVersionCheckData()
2652
+ },
2653
+ dismissedVersionNotification
2654
+ }, api = {
2655
+ getCurrentVersion: () => {
2656
+ let {
2657
+ versions: { current }
2658
+ } = store2.getState();
2659
+ return current;
2660
+ },
2661
+ getLatestVersion: () => {
2662
+ let {
2663
+ versions: { latest, next, current }
2664
+ } = store2.getState();
2665
+ return current && semver.prerelease(current.version) && next ? latest && semver.gt(latest.version, next.version) ? latest : next : latest;
2666
+ },
2667
+ // TODO: Move this to it's own "info" module later
2668
+ getDocsUrl: ({ asset, subpath = asset, versioned, renderer, ref = "ui" }) => {
2669
+ let { versions } = store2.getState(), latestVersion = versions.latest?.version, currentVersion = versions.current?.version, activeVersion = currentVersion?.startsWith("0.0.0") && latestVersion || currentVersion, url = `https://storybook.js.org/${asset ? "docs-assets" : "docs"}/`;
2670
+ if (asset && activeVersion)
2671
+ url += `${semver.major(activeVersion)}.${semver.minor(activeVersion)}/`;
2672
+ else if (versioned && activeVersion && latestVersion) {
2673
+ let versionDiff = semver.diff(latestVersion, activeVersion);
2674
+ versionDiff === "patch" || versionDiff === null || (url += `${semver.major(activeVersion)}.${semver.minor(activeVersion)}/`);
2675
+ }
2676
+ let [cleanedSubpath, hash] = subpath?.split("#") || [];
2677
+ if (cleanedSubpath && (url += asset ? cleanedSubpath : `${cleanedSubpath}/`), renderer && typeof global7.FORKBOOK_RENDERER < "u") {
2678
+ let rendererName = global7.FORKBOOK_RENDERER;
2679
+ rendererName && (url += `?renderer=${normalizeRendererName(rendererName)}`);
2680
+ }
2681
+ return ref && (url += `${url.includes("?") ? "&" : "?"}ref=${ref}`), hash && (url += `#${hash}`), url;
2682
+ },
2683
+ versionUpdateAvailable: () => {
2684
+ let latest = api.getLatestVersion(), current = api.getCurrentVersion();
2685
+ if (latest) {
2686
+ if (!latest.version || !current.version)
2687
+ return !0;
2688
+ let actualCurrent = !!semver.prerelease(current.version) ? `${semver.major(current.version)}.${semver.minor(current.version)}.${semver.patch(
2689
+ current.version
2690
+ )}` : current.version, diff = semver.diff(actualCurrent, latest.version);
2691
+ return semver.gt(latest.version, actualCurrent) && diff !== "patch" && !diff.includes("pre");
2692
+ }
2693
+ return !1;
2694
+ }
2695
+ };
2696
+ return { init: async () => {
2697
+ let { versions = {} } = store2.getState(), { latest, next } = getVersionCheckData();
2698
+ await store2.setState({
2699
+ versions: { ...versions, latest, next }
2700
+ });
2701
+ }, state, api };
2702
+ };
2703
+
2704
+ // src/manager-api/modules/whatsnew.tsx
2705
+ var whatsnew_exports = {};
2706
+ __export(whatsnew_exports, {
2707
+ init: () => init14
2708
+ });
2709
+ import {
2710
+ REQUEST_WHATS_NEW_DATA,
2711
+ RESULT_WHATS_NEW_DATA,
2712
+ SET_WHATS_NEW_CACHE,
2713
+ TOGGLE_WHATS_NEW_NOTIFICATIONS
2714
+ } from "@aussieljk/forkbook/internal/core-events";
2715
+ import { global as global8 } from "@storybook/global";
2716
+ import { jsx as jsx2 } from "react/jsx-runtime";
2717
+ var WHATS_NEW_NOTIFICATION_ID = "whats-new", StorybookIcon = ({ color = "currentColor", size = 14 }) => jsx2(
2718
+ "svg",
2719
+ {
2720
+ width: size,
2721
+ height: size,
2722
+ viewBox: "0 0 14 14",
2723
+ fill: "none",
2724
+ xmlns: "http://www.w3.org/2000/svg",
2725
+ children: jsx2(
2726
+ "path",
2727
+ {
2728
+ fillRule: "evenodd",
2729
+ clipRule: "evenodd",
2730
+ d: "M2.042.616a.704.704 0 00-.66.729L1.816 12.9c.014.367.306.66.672.677l9.395.422h.032a.704.704 0 00.704-.703V.704c0-.015 0-.03-.002-.044a.704.704 0 00-.746-.659l-.773.049.057 1.615a.105.105 0 01-.17.086l-.52-.41-.617.468a.105.105 0 01-.168-.088L9.746.134 2.042.616zm8.003 4.747c-.247.192-2.092.324-2.092.05.04-1.045-.429-1.091-.689-1.091-.247 0-.662.075-.662.634 0 .57.607.893 1.32 1.27 1.014.538 2.24 1.188 2.24 2.823 0 1.568-1.273 2.433-2.898 2.433-1.676 0-3.141-.678-2.976-3.03.065-.275 2.197-.21 2.197 0-.026.971.195 1.256.753 1.256.43 0 .624-.236.624-.634 0-.602-.633-.958-1.361-1.367-.987-.554-2.148-1.205-2.148-2.7 0-1.494 1.027-2.489 2.86-2.489 1.832 0 2.832.98 2.832 2.845z",
2731
+ fill: color
2732
+ }
2733
+ )
2734
+ }
2735
+ ), init14 = ({ fullAPI, store: store2, provider }) => {
2736
+ let state = {
2737
+ whatsNewData: void 0
2738
+ };
2739
+ function setWhatsNewState(newState) {
2740
+ store2.setState({ whatsNewData: newState }), state.whatsNewData = newState;
2741
+ }
2742
+ let api = {
2743
+ isWhatsNewUnread() {
2744
+ return state.whatsNewData?.status === "SUCCESS" && !state.whatsNewData.postIsRead;
2745
+ },
2746
+ whatsNewHasBeenRead() {
2747
+ state.whatsNewData?.status === "SUCCESS" && (setWhatsNewCache({ lastReadPost: state.whatsNewData.url }), setWhatsNewState({ ...state.whatsNewData, postIsRead: !0 }), fullAPI.clearNotification(WHATS_NEW_NOTIFICATION_ID));
2748
+ },
2749
+ toggleWhatsNewNotifications() {
2750
+ state.whatsNewData?.status === "SUCCESS" && (setWhatsNewState({
2751
+ ...state.whatsNewData,
2752
+ disableWhatsNewNotifications: !state.whatsNewData.disableWhatsNewNotifications
2753
+ }), provider.channel?.emit(TOGGLE_WHATS_NEW_NOTIFICATIONS, {
2754
+ disableWhatsNewNotifications: state.whatsNewData.disableWhatsNewNotifications
2755
+ }));
2756
+ }
2757
+ };
2758
+ function getLatestWhatsNewPost() {
2759
+ return provider.channel?.emit(REQUEST_WHATS_NEW_DATA), new Promise(
2760
+ (resolve) => provider.channel?.once(
2761
+ RESULT_WHATS_NEW_DATA,
2762
+ ({ data }) => resolve(data)
2763
+ )
2764
+ );
2765
+ }
2766
+ function setWhatsNewCache(cache) {
2767
+ provider.channel?.emit(SET_WHATS_NEW_CACHE, cache);
2768
+ }
2769
+ return { init: async () => {
2770
+ if (global8.CONFIG_TYPE !== "DEVELOPMENT")
2771
+ return;
2772
+ let whatsNewData = await getLatestWhatsNewPost();
2773
+ setWhatsNewState(whatsNewData);
2774
+ let urlState = fullAPI.getUrlState();
2775
+ !(urlState?.path === "/review/" || urlState?.path === "/review" || urlState?.path?.startsWith("/review/")) && whatsNewData.status === "SUCCESS" && !whatsNewData.disableWhatsNewNotifications && whatsNewData.showNotification && fullAPI.addNotification({
2776
+ id: WHATS_NEW_NOTIFICATION_ID,
2777
+ link: "/settings/whats-new",
2778
+ content: {
2779
+ headline: whatsNewData.title,
2780
+ subHeadline: "Learn what's new in Forkbook"
2781
+ },
2782
+ icon: jsx2(StorybookIcon, {}),
2783
+ onClear({ dismissed }) {
2784
+ dismissed && setWhatsNewCache({ lastDismissedPost: whatsNewData.url });
2785
+ }
2786
+ });
2787
+ }, state, api };
2788
+ };
2789
+
2790
+ // src/manager-api/store.ts
2791
+ var import_store2 = __toESM(require_store2(), 1);
2792
+
2793
+ // src/manager-api/lib/store-setup.ts
2794
+ var store_setup_default = (_) => {
2795
+ _.fn("set", function(key, data) {
2796
+ return _.set(
2797
+ // @ts-expect-error('this' implicitly has type 'any')
2798
+ this._area,
2799
+ // @ts-expect-error('this' implicitly has type 'any')
2800
+ this._in(key),
2801
+ stringify2(data, { maxDepth: 50 })
2802
+ );
2803
+ }), _.fn("get", function(key, alt) {
2804
+ let value = _.get(this._area, this._in(key));
2805
+ return value !== null ? parse(value) : alt || value;
2806
+ });
2807
+ };
2808
+
2809
+ // src/manager-api/store.ts
2810
+ store_setup_default(import_store2.default._);
2811
+ var STORAGE_KEY = "@storybook/manager/store";
2812
+ function get(storage) {
2813
+ return storage.get(STORAGE_KEY) || {};
2814
+ }
2815
+ function set(storage, value) {
2816
+ return storage.set(STORAGE_KEY, value);
2817
+ }
2818
+ function update(storage, patch) {
2819
+ let previous = get(storage);
2820
+ return set(storage, { ...previous, ...patch });
2821
+ }
2822
+ var Store = class {
2823
+ constructor({ allowPersistence, setState, getState }) {
2824
+ this.persistenceHandlers = /* @__PURE__ */ new Map();
2825
+ this.upstreamPersistence = allowPersistence ?? !0, this.upstreamSetState = setState, this.upstreamGetState = getState;
2826
+ }
2827
+ registerPersistenceHandler(key, handler) {
2828
+ this.persistenceHandlers.set(key, handler);
2829
+ }
2830
+ // The assumption is that this will be called once, to initialize the React state
2831
+ // when the module is instantiated
2832
+ getInitialState(base) {
2833
+ let {
2834
+ includedTagFilters: _included,
2835
+ excludedTagFilters: _excluded,
2836
+ ...local
2837
+ } = get(import_store2.default.local), session = get(import_store2.default.session);
2838
+ return { ...base, ...local, ...session };
2839
+ }
2840
+ getState() {
2841
+ return this.upstreamGetState();
2842
+ }
2843
+ async setState(inputPatch, cbOrOptions, inputOptions) {
2844
+ let callback, options;
2845
+ typeof cbOrOptions == "function" ? (callback = cbOrOptions, options = inputOptions) : options = cbOrOptions;
2846
+ let { persistence = "none" } = options || {}, patch = {}, delta = {};
2847
+ typeof inputPatch == "function" ? patch = (state) => (delta = inputPatch(state), delta) : (patch = inputPatch, delta = patch);
2848
+ let newState = await new Promise((resolve) => {
2849
+ this.upstreamSetState(patch, () => {
2850
+ resolve(this.getState());
2851
+ });
2852
+ });
2853
+ if (persistence !== "none" && this.upstreamPersistence)
2854
+ if (persistence === "url") {
2855
+ let handler = this.persistenceHandlers.get("url");
2856
+ handler && await handler(delta, options?.serialize);
2857
+ } else {
2858
+ let storage = persistence === "session" ? import_store2.default.session : import_store2.default.local;
2859
+ await update(storage, delta);
2860
+ }
2861
+ return callback && callback(newState), newState;
2862
+ }
2863
+ };
2864
+
2865
+ // src/manager-api/lib/request-response.ts
2866
+ var RequestResponseError = class extends Error {
2867
+ constructor(message, payload) {
2868
+ super(message);
2869
+ this.payload = void 0;
2870
+ this.payload = payload;
2871
+ }
2872
+ }, experimental_requestResponse = (channel, requestEvent, responseEvent, payload, timeout = 5e3) => {
2873
+ let timeoutId;
2874
+ return new Promise((resolve, reject) => {
2875
+ let request = {
2876
+ id: Math.random().toString(16).slice(2),
2877
+ payload
2878
+ }, responseHandler = (response) => {
2879
+ response.id === request.id && (clearTimeout(timeoutId), channel.off(responseEvent, responseHandler), response.success ? resolve(response.payload) : reject(new RequestResponseError(response.error, response.payload)));
2880
+ };
2881
+ channel.emit(requestEvent, request), channel.on(responseEvent, responseHandler), timeoutId = setTimeout(() => {
2882
+ channel.off(responseEvent, responseHandler), reject(new RequestResponseError("Timed out waiting for response"));
2883
+ }, timeout);
2884
+ });
2885
+ };
2886
+
2887
+ // src/manager-api/root.tsx
2888
+ import { jsx as jsx3 } from "react/jsx-runtime";
2889
+ var { ActiveTabs: ActiveTabs2 } = layout_exports;
2890
+ var ManagerContext = createContext({ api: void 0, state: initial_state_default({}) }), combineParameters = (...parameterSets) => noArrayMerge({}, ...parameterSets), ManagerProvider = class extends Component {
2891
+ constructor(props) {
2892
+ super(props);
2893
+ this.api = {};
2894
+ // Addon register callbacks run in the constructor (before mount) so manager-side listeners exist
2895
+ // before the preview iframe emits its first events. React's this.setState is a no-op before mount,
2896
+ // so store writes during registration are applied directly to this.state until this flips true.
2897
+ this.mounted = !1;
2898
+ this.initModules = () => {
2899
+ this.modules.forEach((module) => {
2900
+ "init" in module && module.init();
2901
+ });
2902
+ };
2903
+ let {
2904
+ location: location2,
2905
+ path,
2906
+ refId,
2907
+ viewMode = props.docsOptions.docsMode ? "docs" : props.viewMode,
2908
+ singleStory,
2909
+ storyId,
2910
+ docsOptions,
2911
+ navigate
2912
+ } = props, store2 = new Store({
2913
+ getState: () => this.state,
2914
+ setState: (stateChange, callback) => {
2915
+ if (!this.mounted) {
2916
+ let patch = typeof stateChange == "function" ? stateChange(this.state) : stateChange;
2917
+ return this.state = { ...this.state, ...patch }, callback?.(this.state), this.state;
2918
+ }
2919
+ return this.setState(stateChange, () => callback(this.state)), this.state;
2920
+ }
2921
+ }), routeData = { location: location2, path, viewMode, singleStory, storyId, refId }, optionsData = { docsOptions };
2922
+ this.state = store2.getInitialState(initial_state_default({ ...routeData, ...optionsData }));
2923
+ let apiData = {
2924
+ navigate,
2925
+ store: store2,
2926
+ provider: props.provider
2927
+ };
2928
+ this.modules = [
2929
+ provider_exports,
2930
+ channel_exports,
2931
+ addons_exports,
2932
+ layout_exports,
2933
+ notifications_exports,
2934
+ settings_exports,
2935
+ shortcuts_exports,
2936
+ stories_exports,
2937
+ refs_exports,
2938
+ globals_exports,
2939
+ url_exports,
2940
+ versions_exports,
2941
+ whatsnew_exports,
2942
+ open_in_editor_exports
2943
+ ].map(
2944
+ (m) => m.init({ ...routeData, ...optionsData, ...apiData, state: this.state, fullAPI: this.api })
2945
+ );
2946
+ let state = initial_state_default(this.state, ...this.modules.map((m) => m.state)), api = Object.assign(this.api, { navigate }, ...this.modules.map((m) => m.api));
2947
+ this.state = state, this.api = api, props.provider.handleAPI(this.api);
2948
+ }
2949
+ componentDidMount() {
2950
+ this.mounted = !0;
2951
+ }
2952
+ static getDerivedStateFromProps(props, state) {
2953
+ let locationSearchChanged = state.location?.search !== props.location?.search, locationHashChanged = state.location?.hash !== props.location?.hash;
2954
+ return state.path !== props.path || locationSearchChanged || locationHashChanged ? {
2955
+ ...state,
2956
+ location: props.location,
2957
+ path: props.path,
2958
+ refId: props.refId,
2959
+ viewMode: props.viewMode,
2960
+ storyId: props.storyId,
2961
+ customQueryParams: getCustomQueryParams(props.location)
2962
+ } : null;
2963
+ }
2964
+ shouldComponentUpdate(nextProps, nextState) {
2965
+ let prevProps = this.props, prevState = this.state;
2966
+ return prevProps.path !== nextProps.path || !isEqual(prevState, nextState);
2967
+ }
2968
+ render() {
2969
+ let { children } = this.props, value = {
2970
+ state: this.state,
2971
+ api: this.api
2972
+ };
2973
+ return jsx3(EffectOnMount, { effect: this.initModules, children: jsx3(ManagerContext.Provider, { value, children: jsx3(ManagerConsumer, { children }) }) });
2974
+ }
2975
+ };
2976
+ ManagerProvider.displayName = "Manager";
2977
+ var EffectOnMount = ({ children, effect }) => (React2.useEffect(effect, []), children), defaultFilter = (c) => c;
2978
+ function ManagerConsumer({
2979
+ // @ts-expect-error (Converted from ts-ignore)
2980
+ filter = defaultFilter,
2981
+ children
2982
+ }) {
2983
+ let managerContext = useContext(ManagerContext), renderer = useRef2(children), filterer = useRef2(filter);
2984
+ if (typeof renderer.current != "function")
2985
+ return jsx3(Fragment, { children: renderer.current });
2986
+ let comboData = filterer.current(managerContext), comboDataArray = useMemo(() => [...Object.entries(comboData).reduce((acc, keyval) => acc.concat(keyval), [])], [managerContext.state]);
2987
+ return useMemo(() => {
2988
+ let Child = renderer.current;
2989
+ return jsx3(Child, { ...comboData });
2990
+ }, comboDataArray);
2991
+ }
2992
+ function useStorybookState() {
2993
+ let { state } = useContext(ManagerContext);
2994
+ return state;
2995
+ }
2996
+ function useStorybookApi() {
2997
+ let { api } = useContext(ManagerContext);
2998
+ return api;
2999
+ }
3000
+ function orDefault(fromStore, defaultState) {
3001
+ return typeof fromStore > "u" ? defaultState : fromStore;
3002
+ }
3003
+ var useChannel = (eventMap, deps = []) => {
3004
+ let api = useStorybookApi();
3005
+ return useEffect(() => (Object.entries(eventMap).forEach(([type, listener]) => api.on(type, listener)), () => {
3006
+ Object.entries(eventMap).forEach(([type, listener]) => api.off(type, listener));
3007
+ }), deps), api.emit;
3008
+ };
3009
+ function useStoryPrepared(storyId) {
3010
+ return useStorybookApi().isPrepared(storyId);
3011
+ }
3012
+ function useParameter(parameterKey, defaultValue) {
3013
+ let api = useStorybookApi(), [parameter, setParameter] = useState(api.getCurrentParameter(parameterKey)), handleParameterChange = useCallback2(() => {
3014
+ let newParameter = api.getCurrentParameter(parameterKey);
3015
+ setParameter(newParameter);
3016
+ }, [api, parameterKey]);
3017
+ return useChannel(
3018
+ {
3019
+ [STORY_PREPARED2]: handleParameterChange,
3020
+ [DOCS_PREPARED2]: handleParameterChange
3021
+ },
3022
+ [handleParameterChange]
3023
+ ), orDefault(parameter, defaultValue);
3024
+ }
3025
+ globalThis.FORKBOOK_ADDON_STATE = {};
3026
+ var { FORKBOOK_ADDON_STATE } = globalThis;
3027
+ function useSharedState(stateId, defaultState) {
3028
+ let api = useStorybookApi(), existingState = api.getAddonState(stateId) || FORKBOOK_ADDON_STATE[stateId], state = orDefault(
3029
+ existingState,
3030
+ FORKBOOK_ADDON_STATE[stateId] ? FORKBOOK_ADDON_STATE[stateId] : defaultState
3031
+ ), quicksync = !1;
3032
+ state === defaultState && defaultState !== void 0 && (FORKBOOK_ADDON_STATE[stateId] = defaultState, quicksync = !0), useEffect(() => {
3033
+ quicksync && api.setAddonState(stateId, defaultState);
3034
+ }, [quicksync]);
3035
+ let setState = useCallback2(
3036
+ async (s, options) => {
3037
+ await api.setAddonState(stateId, s, options);
3038
+ let result = api.getAddonState(stateId);
3039
+ return FORKBOOK_ADDON_STATE[stateId] = result, result;
3040
+ },
3041
+ [api, stateId]
3042
+ ), allListeners = useMemo(() => {
3043
+ let stateChangeHandlers = {
3044
+ [`${SHARED_STATE_CHANGED}-client-${stateId}`]: setState,
3045
+ [`${SHARED_STATE_SET}-client-${stateId}`]: setState
3046
+ }, stateInitializationHandlers = {
3047
+ [SET_STORIES2]: async () => {
3048
+ let currentState = api.getAddonState(stateId);
3049
+ currentState ? (FORKBOOK_ADDON_STATE[stateId] = currentState, api.emit(`${SHARED_STATE_SET}-manager-${stateId}`, currentState)) : FORKBOOK_ADDON_STATE[stateId] ? (await setState(FORKBOOK_ADDON_STATE[stateId]), api.emit(`${SHARED_STATE_SET}-manager-${stateId}`, FORKBOOK_ADDON_STATE[stateId])) : defaultState !== void 0 && (await setState(defaultState), FORKBOOK_ADDON_STATE[stateId] = defaultState, api.emit(`${SHARED_STATE_SET}-manager-${stateId}`, defaultState));
3050
+ },
3051
+ [STORY_CHANGED2]: () => {
3052
+ let currentState = api.getAddonState(stateId);
3053
+ currentState !== void 0 && api.emit(`${SHARED_STATE_SET}-manager-${stateId}`, currentState);
3054
+ }
3055
+ };
3056
+ return {
3057
+ ...stateChangeHandlers,
3058
+ ...stateInitializationHandlers
3059
+ };
3060
+ }, [stateId]), emit = useChannel(allListeners), stateSetter = useCallback2(
3061
+ async (newStateOrMerger, options) => {
3062
+ await setState(newStateOrMerger, options);
3063
+ let result = api.getAddonState(stateId);
3064
+ emit(`${SHARED_STATE_CHANGED}-manager-${stateId}`, result);
3065
+ },
3066
+ [api, emit, setState, stateId]
3067
+ );
3068
+ return [state, stateSetter];
3069
+ }
3070
+ function useAddonState(addonId, defaultState) {
3071
+ return useSharedState(addonId, defaultState);
3072
+ }
3073
+ function useArgs() {
3074
+ let { getCurrentStoryData, updateStoryArgs, resetStoryArgs } = useStorybookApi(), data = getCurrentStoryData(), args = data?.type === "story" ? data.args : {}, initialArgs = data?.type === "story" ? data.initialArgs : {}, updateArgs = useCallback2(
3075
+ (newArgs) => updateStoryArgs(data, newArgs),
3076
+ [data, updateStoryArgs]
3077
+ ), resetArgs = useCallback2(
3078
+ (argNames) => resetStoryArgs(data, argNames),
3079
+ [data, resetStoryArgs]
3080
+ );
3081
+ return [args, updateArgs, resetArgs, initialArgs];
3082
+ }
3083
+ function useGlobals() {
3084
+ let api = useStorybookApi();
3085
+ return [api.getGlobals(), api.updateGlobals, api.getStoryGlobals(), api.getUserGlobals()];
3086
+ }
3087
+ function useGlobalTypes() {
3088
+ return useStorybookApi().getGlobalTypes();
3089
+ }
3090
+ function useCurrentStory() {
3091
+ let { getCurrentStoryData } = useStorybookApi();
3092
+ return getCurrentStoryData();
3093
+ }
3094
+ function useArgTypes() {
3095
+ let current = useCurrentStory();
3096
+ return current?.type === "story" && current.argTypes || {};
3097
+ }
3098
+ var typesX = Addon_TypesEnum;
3099
+
3100
+ // src/shared/universal-store/mock.ts
3101
+ import { Channel } from "@aussieljk/forkbook/internal/channels";
3102
+ import { dedent as dedent3 } from "ts-dedent";
3103
+ var MockUniversalStore = class _MockUniversalStore extends UniversalStore {
3104
+ constructor(options, testUtils) {
3105
+ UniversalStore.isInternalConstructing = !0, super(
3106
+ { ...options, leader: !0 },
3107
+ { channel: new Channel({}), environment: UniversalStore.Environment.MOCK }
3108
+ ), UniversalStore.isInternalConstructing = !1, typeof testUtils?.fn == "function" && (this.testUtils = testUtils, this.getState = testUtils.fn(this.getState), this.setState = testUtils.fn(this.setState), this.subscribe = testUtils.fn(this.subscribe), this.onStateChange = testUtils.fn(this.onStateChange), this.send = testUtils.fn(this.send));
3109
+ }
3110
+ /** Create a mock universal store. This is just an alias for the constructor */
3111
+ static create(options, testUtils) {
3112
+ return new _MockUniversalStore(options, testUtils);
3113
+ }
3114
+ unsubscribeAll() {
3115
+ if (!this.testUtils)
3116
+ throw new Error(
3117
+ dedent3`Cannot call unsubscribeAll on a store that does not have testUtils.
3118
+ Please provide testUtils as the second argument when creating the store.`
3119
+ );
3120
+ let callReturnedUnsubscribeFn = (result) => {
3121
+ try {
3122
+ result.value();
3123
+ } catch {
3124
+ }
3125
+ };
3126
+ this.subscribe.mock?.results.forEach(callReturnedUnsubscribeFn), this.onStateChange.mock?.results.forEach(callReturnedUnsubscribeFn);
3127
+ }
3128
+ };
3129
+
3130
+ // src/shared/test-provider-store/index.ts
3131
+ var UNIVERSAL_TEST_PROVIDER_STORE_OPTIONS = {
3132
+ id: "@aussieljk/forkbook/test-provider",
3133
+ leader: !0,
3134
+ initialState: {}
3135
+ };
3136
+ function createTestProviderStore({
3137
+ universalTestProviderStore: universalTestProviderStore2,
3138
+ useUniversalStore: useUniversalStore2
3139
+ }) {
3140
+ let baseStore = {
3141
+ settingsChanged: () => {
3142
+ universalTestProviderStore2.untilReady().then(() => {
3143
+ universalTestProviderStore2.send({ type: "settings-changed" });
3144
+ });
3145
+ },
3146
+ onRunAll: (listener) => universalTestProviderStore2.subscribe("run-all", listener),
3147
+ onClearAll: (listener) => universalTestProviderStore2.subscribe("clear-all", listener)
3148
+ }, fullTestProviderStore2 = {
3149
+ ...baseStore,
3150
+ getFullState: universalTestProviderStore2.getState,
3151
+ setFullState: universalTestProviderStore2.setState,
3152
+ onSettingsChanged: (listener) => universalTestProviderStore2.subscribe("settings-changed", listener),
3153
+ runAll: async () => {
3154
+ await universalTestProviderStore2.untilReady(), universalTestProviderStore2.send({ type: "run-all" });
3155
+ },
3156
+ clearAll: async () => {
3157
+ await universalTestProviderStore2.untilReady(), universalTestProviderStore2.send({ type: "clear-all" });
3158
+ }
3159
+ }, getTestProviderStoreById2 = (testProviderId) => {
3160
+ let getStateForTestProvider = () => universalTestProviderStore2.getState()[testProviderId] ?? "test-provider-state:pending", setStateForTestProvider = (state) => {
3161
+ universalTestProviderStore2.untilReady().then(() => {
3162
+ universalTestProviderStore2.setState((currentState) => ({
3163
+ ...currentState,
3164
+ [testProviderId]: state
3165
+ }));
3166
+ });
3167
+ };
3168
+ return {
3169
+ ...baseStore,
3170
+ testProviderId,
3171
+ getState: getStateForTestProvider,
3172
+ setState: setStateForTestProvider,
3173
+ runWithState: async (callback) => {
3174
+ setStateForTestProvider("test-provider-state:running");
3175
+ try {
3176
+ await callback(), setStateForTestProvider("test-provider-state:succeeded");
3177
+ } catch {
3178
+ setStateForTestProvider("test-provider-state:crashed");
3179
+ }
3180
+ }
3181
+ };
3182
+ };
3183
+ return useUniversalStore2 ? {
3184
+ getTestProviderStoreById: getTestProviderStoreById2,
3185
+ fullTestProviderStore: fullTestProviderStore2,
3186
+ universalTestProviderStore: universalTestProviderStore2,
3187
+ useTestProviderStore: (selector) => useUniversalStore2(universalTestProviderStore2, selector)[0]
3188
+ } : {
3189
+ getTestProviderStoreById: getTestProviderStoreById2,
3190
+ fullTestProviderStore: fullTestProviderStore2,
3191
+ universalTestProviderStore: universalTestProviderStore2
3192
+ };
3193
+ }
3194
+
3195
+ // src/manager-api/stores/test-provider.ts
3196
+ var testProviderStore = createTestProviderStore({
3197
+ universalTestProviderStore: UniversalStore.create({
3198
+ ...UNIVERSAL_TEST_PROVIDER_STORE_OPTIONS,
3199
+ leader: globalThis.CONFIG_TYPE === "PRODUCTION"
3200
+ }),
3201
+ useUniversalStore
3202
+ }), {
3203
+ fullTestProviderStore,
3204
+ getTestProviderStoreById,
3205
+ useTestProviderStore,
3206
+ universalTestProviderStore
3207
+ } = testProviderStore;
3208
+ export {
3209
+ ActiveTabs2 as ActiveTabs,
3210
+ ManagerConsumer as Consumer,
3211
+ ManagerContext,
3212
+ ManagerProvider as Provider,
3213
+ RequestResponseError,
3214
+ Tag,
3215
+ addons,
3216
+ combineParameters,
3217
+ controlOrMetaKey,
3218
+ controlOrMetaSymbol,
3219
+ eventMatchesShortcut,
3220
+ eventToShortcut,
3221
+ MockUniversalStore as experimental_MockUniversalStore,
3222
+ getStatusStoreByTypeId as experimental_getStatusStore,
3223
+ getTestProviderStoreById as experimental_getTestProviderStore,
3224
+ experimental_requestResponse,
3225
+ useStatusStore as experimental_useStatusStore,
3226
+ useTestProviderStore as experimental_useTestProviderStore,
3227
+ getService,
3228
+ UniversalStore as internal_UniversalStore,
3229
+ fullStatusStore as internal_fullStatusStore,
3230
+ fullTestProviderStore as internal_fullTestProviderStore,
3231
+ universalStatusStore as internal_universalStatusStore,
3232
+ universalTestProviderStore as internal_universalTestProviderStore,
3233
+ useUniversalStore as internal_useUniversalStore,
3234
+ isMacLike,
3235
+ isShortcutTaken,
3236
+ keyToSymbol,
3237
+ merge_default as merge,
3238
+ optionOrAltSymbol,
3239
+ registerService,
3240
+ shortcutMatchesShortcut,
3241
+ shortcutToAriaKeyshortcuts,
3242
+ shortcutToHumanString,
3243
+ typesX as types,
3244
+ useAddonState,
3245
+ useArgTypes,
3246
+ useArgs,
3247
+ useChannel,
3248
+ useGlobalTypes,
3249
+ useGlobals,
3250
+ useParameter,
3251
+ useServiceCommand,
3252
+ useServiceQuery,
3253
+ useSharedState,
3254
+ useStoryPrepared,
3255
+ useStorybookApi,
3256
+ useStorybookState
3257
+ };