@makeswift/runtime 0.25.0-canary.13 → 0.25.0-canary.14

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 (274) hide show
  1. package/dist/cjs/api/site-version/index.js +103 -0
  2. package/dist/cjs/api/site-version/index.js.map +1 -0
  3. package/dist/cjs/api-handler/handlers/manifest.js +2 -3
  4. package/dist/cjs/api-handler/handlers/manifest.js.map +1 -1
  5. package/dist/cjs/api-handler/handlers/{clear-draft.js → redirect-live.js} +19 -10
  6. package/dist/cjs/api-handler/handlers/redirect-live.js.map +1 -0
  7. package/dist/cjs/api-handler/index.js +6 -5
  8. package/dist/cjs/api-handler/index.js.map +1 -1
  9. package/dist/cjs/api-handler/request-response.js +9 -0
  10. package/dist/cjs/api-handler/request-response.js.map +1 -1
  11. package/dist/cjs/client/index.js +67 -59
  12. package/dist/cjs/client/index.js.map +1 -1
  13. package/dist/cjs/components/builtin/Root/Root.js +4 -4
  14. package/dist/cjs/components/builtin/Root/Root.js.map +1 -1
  15. package/dist/cjs/components/builtin/Video/Video.js +3 -13
  16. package/dist/cjs/components/builtin/Video/Video.js.map +1 -1
  17. package/dist/cjs/components/hooks/useMediaQuery.js +1 -2
  18. package/dist/cjs/components/hooks/useMediaQuery.js.map +1 -1
  19. package/dist/cjs/components/shared/BackgroundsContainer/components/BackgroundVideo/index.js +3 -13
  20. package/dist/cjs/components/shared/BackgroundsContainer/components/BackgroundVideo/index.js.map +1 -1
  21. package/dist/cjs/components/shared/react-player.js +41 -0
  22. package/dist/cjs/components/shared/react-player.js.map +1 -0
  23. package/dist/cjs/next/api-handler/config/app-router.js +7 -9
  24. package/dist/cjs/next/api-handler/config/app-router.js.map +1 -1
  25. package/dist/cjs/next/api-handler/config/pages-router.js +7 -9
  26. package/dist/cjs/next/api-handler/config/pages-router.js.map +1 -1
  27. package/dist/cjs/next/api-handler/handlers/{redirect-draft.js → app-router-redirect-preview.js} +30 -26
  28. package/dist/cjs/next/api-handler/handlers/app-router-redirect-preview.js.map +1 -0
  29. package/dist/cjs/next/api-handler/handlers/{redirect-preview.js → pages-router-redirect-preview.js} +29 -22
  30. package/dist/cjs/next/api-handler/handlers/pages-router-redirect-preview.js.map +1 -0
  31. package/dist/cjs/next/api-handler/index.js +1 -1
  32. package/dist/cjs/next/api-handler/index.js.map +1 -1
  33. package/dist/cjs/next/api-handler/{draft.js → preview.js} +14 -9
  34. package/dist/cjs/next/api-handler/preview.js.map +1 -0
  35. package/dist/cjs/next/{draft-mode/index.js → app-router-site-version.js} +11 -27
  36. package/dist/cjs/next/app-router-site-version.js.map +1 -0
  37. package/dist/cjs/next/client.js +9 -3
  38. package/dist/cjs/next/client.js.map +1 -1
  39. package/dist/cjs/next/components/framework-provider/index.js.map +1 -1
  40. package/dist/cjs/next/components/page.js +1 -1
  41. package/dist/cjs/next/components/page.js.map +1 -1
  42. package/dist/cjs/next/index.js.map +1 -1
  43. package/dist/cjs/next/middleware/request-utils.js +11 -17
  44. package/dist/cjs/next/middleware/request-utils.js.map +1 -1
  45. package/dist/cjs/next/root-style-registry.js +13 -20
  46. package/dist/cjs/next/root-style-registry.js.map +1 -1
  47. package/dist/cjs/next/server.js +2 -2
  48. package/dist/cjs/next/server.js.map +1 -1
  49. package/dist/cjs/next/testing/page-rendering.js +2 -2
  50. package/dist/cjs/next/testing/page-rendering.js.map +1 -1
  51. package/dist/cjs/next/testing/react-provider.js +2 -2
  52. package/dist/cjs/next/testing/react-provider.js.map +1 -1
  53. package/dist/cjs/next/tests/test-utils.js +6 -4
  54. package/dist/cjs/next/tests/test-utils.js.map +1 -1
  55. package/dist/cjs/runtimes/react/components/RuntimeProvider.js +7 -9
  56. package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
  57. package/dist/cjs/runtimes/react/components/framework-context.js +1 -1
  58. package/dist/cjs/runtimes/react/components/framework-context.js.map +1 -1
  59. package/dist/cjs/runtimes/react/components/page/index.js +18 -16
  60. package/dist/cjs/runtimes/react/components/page/index.js.map +1 -1
  61. package/dist/cjs/runtimes/react/components/{draft-switcher/draft-switcher.js → preview-switcher/preview-switcher.js} +12 -22
  62. package/dist/cjs/runtimes/react/components/preview-switcher/preview-switcher.js.map +1 -0
  63. package/dist/cjs/runtimes/react/components/{draft-switcher/draft-toolbar.js → preview-switcher/preview-toolbar.js} +17 -9
  64. package/dist/cjs/runtimes/react/components/preview-switcher/preview-toolbar.js.map +1 -0
  65. package/dist/cjs/runtimes/react/hooks/makeswift-api.js +9 -10
  66. package/dist/cjs/runtimes/react/hooks/makeswift-api.js.map +1 -1
  67. package/dist/cjs/runtimes/react/hooks/use-selector.js +1 -1
  68. package/dist/cjs/runtimes/react/hooks/use-selector.js.map +1 -1
  69. package/dist/cjs/runtimes/react/root-style-registry.js +24 -13
  70. package/dist/cjs/runtimes/react/root-style-registry.js.map +1 -1
  71. package/dist/cjs/{next/preview-mode.js → testing/fixtures.js} +16 -18
  72. package/dist/cjs/testing/fixtures.js.map +1 -0
  73. package/dist/cjs/utils/esm-compat.js +29 -0
  74. package/dist/cjs/utils/esm-compat.js.map +1 -0
  75. package/dist/esm/api/site-version/index.js +75 -0
  76. package/dist/esm/api/site-version/index.js.map +1 -0
  77. package/dist/esm/api-handler/handlers/manifest.js +2 -3
  78. package/dist/esm/api-handler/handlers/manifest.js.map +1 -1
  79. package/dist/esm/api-handler/handlers/redirect-live.js +26 -0
  80. package/dist/esm/api-handler/handlers/redirect-live.js.map +1 -0
  81. package/dist/esm/api-handler/index.js +7 -6
  82. package/dist/esm/api-handler/index.js.map +1 -1
  83. package/dist/esm/api-handler/request-response.js +9 -0
  84. package/dist/esm/api-handler/request-response.js.map +1 -1
  85. package/dist/esm/client/index.js +65 -58
  86. package/dist/esm/client/index.js.map +1 -1
  87. package/dist/esm/components/builtin/Root/Root.js +4 -4
  88. package/dist/esm/components/builtin/Root/Root.js.map +1 -1
  89. package/dist/esm/components/builtin/Video/Video.js +1 -1
  90. package/dist/esm/components/builtin/Video/Video.js.map +1 -1
  91. package/dist/esm/components/hooks/useMediaQuery.js +1 -2
  92. package/dist/esm/components/hooks/useMediaQuery.js.map +1 -1
  93. package/dist/esm/components/shared/BackgroundsContainer/components/BackgroundVideo/index.js +1 -1
  94. package/dist/esm/components/shared/BackgroundsContainer/components/BackgroundVideo/index.js.map +1 -1
  95. package/dist/esm/components/shared/react-player.js +7 -0
  96. package/dist/esm/components/shared/react-player.js.map +1 -0
  97. package/dist/esm/next/api-handler/config/app-router.js +7 -9
  98. package/dist/esm/next/api-handler/config/app-router.js.map +1 -1
  99. package/dist/esm/next/api-handler/config/pages-router.js +7 -9
  100. package/dist/esm/next/api-handler/config/pages-router.js.map +1 -1
  101. package/dist/esm/next/api-handler/handlers/app-router-redirect-preview.js +64 -0
  102. package/dist/esm/next/api-handler/handlers/app-router-redirect-preview.js.map +1 -0
  103. package/dist/esm/next/api-handler/handlers/pages-router-redirect-preview.js +52 -0
  104. package/dist/esm/next/api-handler/handlers/pages-router-redirect-preview.js.map +1 -0
  105. package/dist/esm/next/api-handler/index.js +1 -1
  106. package/dist/esm/next/api-handler/index.js.map +1 -1
  107. package/dist/esm/next/api-handler/preview.js +18 -0
  108. package/dist/esm/next/api-handler/preview.js.map +1 -0
  109. package/dist/esm/next/app-router-site-version.js +16 -0
  110. package/dist/esm/next/app-router-site-version.js.map +1 -0
  111. package/dist/esm/next/client.js +10 -4
  112. package/dist/esm/next/client.js.map +1 -1
  113. package/dist/esm/next/components/framework-provider/index.js.map +1 -1
  114. package/dist/esm/next/components/page.js +2 -4
  115. package/dist/esm/next/components/page.js.map +1 -1
  116. package/dist/esm/next/index.js.map +1 -1
  117. package/dist/esm/next/middleware/request-utils.js +14 -17
  118. package/dist/esm/next/middleware/request-utils.js.map +1 -1
  119. package/dist/esm/next/root-style-registry.js +12 -17
  120. package/dist/esm/next/root-style-registry.js.map +1 -1
  121. package/dist/esm/next/server.js +1 -1
  122. package/dist/esm/next/server.js.map +1 -1
  123. package/dist/esm/next/testing/page-rendering.js +2 -2
  124. package/dist/esm/next/testing/page-rendering.js.map +1 -1
  125. package/dist/esm/next/testing/react-provider.js +2 -2
  126. package/dist/esm/next/testing/react-provider.js.map +1 -1
  127. package/dist/esm/next/tests/test-utils.js +6 -4
  128. package/dist/esm/next/tests/test-utils.js.map +1 -1
  129. package/dist/esm/runtimes/react/components/RuntimeProvider.js +7 -9
  130. package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
  131. package/dist/esm/runtimes/react/components/framework-context.js +5 -2
  132. package/dist/esm/runtimes/react/components/framework-context.js.map +1 -1
  133. package/dist/esm/runtimes/react/components/page/index.js +19 -17
  134. package/dist/esm/runtimes/react/components/page/index.js.map +1 -1
  135. package/dist/esm/runtimes/react/components/{draft-switcher/draft-switcher.js → preview-switcher/preview-switcher.js} +8 -18
  136. package/dist/esm/runtimes/react/components/preview-switcher/preview-switcher.js.map +1 -0
  137. package/dist/esm/runtimes/react/components/{draft-switcher/draft-toolbar.js → preview-switcher/preview-toolbar.js} +13 -5
  138. package/dist/esm/runtimes/react/components/preview-switcher/preview-toolbar.js.map +1 -0
  139. package/dist/esm/runtimes/react/hooks/makeswift-api.js +1 -2
  140. package/dist/esm/runtimes/react/hooks/makeswift-api.js.map +1 -1
  141. package/dist/esm/runtimes/react/hooks/use-selector.js +1 -1
  142. package/dist/esm/runtimes/react/hooks/use-selector.js.map +1 -1
  143. package/dist/esm/runtimes/react/root-style-registry.js +24 -13
  144. package/dist/esm/runtimes/react/root-style-registry.js.map +1 -1
  145. package/dist/esm/testing/fixtures.js +13 -0
  146. package/dist/esm/testing/fixtures.js.map +1 -0
  147. package/dist/esm/utils/esm-compat.js +5 -0
  148. package/dist/esm/utils/esm-compat.js.map +1 -0
  149. package/dist/types/api/site-version/index.d.ts +19 -0
  150. package/dist/types/api/site-version/index.d.ts.map +1 -0
  151. package/dist/types/api/site-version/site-version.test.d.ts +2 -0
  152. package/dist/types/api/site-version/site-version.test.d.ts.map +1 -0
  153. package/dist/types/api-handler/handlers/manifest.d.ts +0 -2
  154. package/dist/types/api-handler/handlers/manifest.d.ts.map +1 -1
  155. package/dist/types/api-handler/handlers/redirect-live.d.ts +5 -0
  156. package/dist/types/api-handler/handlers/redirect-live.d.ts.map +1 -0
  157. package/dist/types/api-handler/index.d.ts +4 -4
  158. package/dist/types/api-handler/index.d.ts.map +1 -1
  159. package/dist/types/api-handler/request-response.d.ts +1 -0
  160. package/dist/types/api-handler/request-response.d.ts.map +1 -1
  161. package/dist/types/client/index.d.ts +32 -23
  162. package/dist/types/client/index.d.ts.map +1 -1
  163. package/dist/types/components/builtin/Root/Root.d.ts +1 -1
  164. package/dist/types/components/builtin/Root/Root.d.ts.map +1 -1
  165. package/dist/types/components/hooks/useMediaQuery.d.ts.map +1 -1
  166. package/dist/types/components/shared/BackgroundsContainer/components/BackgroundVideo/index.d.ts.map +1 -1
  167. package/dist/types/components/shared/react-player.d.ts +3 -0
  168. package/dist/types/components/shared/react-player.d.ts.map +1 -0
  169. package/dist/types/next/api-handler/config/app-router.d.ts +3 -2
  170. package/dist/types/next/api-handler/config/app-router.d.ts.map +1 -1
  171. package/dist/types/next/api-handler/config/pages-router.d.ts +3 -2
  172. package/dist/types/next/api-handler/config/pages-router.d.ts.map +1 -1
  173. package/dist/types/next/api-handler/handlers/app-router-redirect-preview.d.ts +5 -0
  174. package/dist/types/next/api-handler/handlers/app-router-redirect-preview.d.ts.map +1 -0
  175. package/dist/types/next/api-handler/handlers/app-router-redirect-preview.test.d.ts +2 -0
  176. package/dist/types/next/api-handler/handlers/app-router-redirect-preview.test.d.ts.map +1 -0
  177. package/dist/types/next/api-handler/handlers/pages-router-redirect-preview.d.ts +4 -0
  178. package/dist/types/next/api-handler/handlers/pages-router-redirect-preview.d.ts.map +1 -0
  179. package/dist/types/next/api-handler/preview.d.ts +11 -0
  180. package/dist/types/next/api-handler/preview.d.ts.map +1 -0
  181. package/dist/types/next/app-router-site-version.d.ts +3 -0
  182. package/dist/types/next/app-router-site-version.d.ts.map +1 -0
  183. package/dist/types/next/client.d.ts +3 -3
  184. package/dist/types/next/client.d.ts.map +1 -1
  185. package/dist/types/next/components/page.d.ts +2 -6
  186. package/dist/types/next/components/page.d.ts.map +1 -1
  187. package/dist/types/next/index.d.ts +1 -1
  188. package/dist/types/next/index.d.ts.map +1 -1
  189. package/dist/types/next/middleware/request-utils.d.ts +1 -0
  190. package/dist/types/next/middleware/request-utils.d.ts.map +1 -1
  191. package/dist/types/next/root-style-registry.d.ts +3 -12
  192. package/dist/types/next/root-style-registry.d.ts.map +1 -1
  193. package/dist/types/next/server.d.ts +1 -1
  194. package/dist/types/next/server.d.ts.map +1 -1
  195. package/dist/types/next/testing/react-provider.d.ts +3 -2
  196. package/dist/types/next/testing/react-provider.d.ts.map +1 -1
  197. package/dist/types/next/tests/server.api-handler-app-router-redirect-preview.test.d.ts +2 -0
  198. package/dist/types/next/tests/server.api-handler-app-router-redirect-preview.test.d.ts.map +1 -0
  199. package/dist/types/next/tests/server.api-handler-pages-router-redirect-preview.test.d.ts +2 -0
  200. package/dist/types/next/tests/server.api-handler-pages-router-redirect-preview.test.d.ts.map +1 -0
  201. package/dist/types/next/tests/server.api-handler-redirect-live.test.d.ts +2 -0
  202. package/dist/types/next/tests/server.api-handler-redirect-live.test.d.ts.map +1 -0
  203. package/dist/types/next/tests/test-utils.d.ts.map +1 -1
  204. package/dist/types/runtimes/react/components/RuntimeProvider.d.ts +3 -2
  205. package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
  206. package/dist/types/runtimes/react/components/framework-context.d.ts +2 -2
  207. package/dist/types/runtimes/react/components/framework-context.d.ts.map +1 -1
  208. package/dist/types/runtimes/react/components/page/index.d.ts +23 -3
  209. package/dist/types/runtimes/react/components/page/index.d.ts.map +1 -1
  210. package/dist/types/runtimes/react/components/preview-switcher/preview-switcher.d.ts +4 -0
  211. package/dist/types/runtimes/react/components/preview-switcher/preview-switcher.d.ts.map +1 -0
  212. package/dist/types/runtimes/react/components/preview-switcher/preview-toolbar.d.ts +2 -0
  213. package/dist/types/runtimes/react/components/preview-switcher/preview-toolbar.d.ts.map +1 -0
  214. package/dist/types/runtimes/react/hooks/makeswift-api.d.ts.map +1 -1
  215. package/dist/types/runtimes/react/hooks/use-selector.d.ts.map +1 -1
  216. package/dist/types/runtimes/react/root-style-registry.d.ts +23 -11
  217. package/dist/types/runtimes/react/root-style-registry.d.ts.map +1 -1
  218. package/dist/types/testing/fixtures.d.ts +7 -0
  219. package/dist/types/testing/fixtures.d.ts.map +1 -0
  220. package/dist/types/utils/esm-compat.d.ts +2 -0
  221. package/dist/types/utils/esm-compat.d.ts.map +1 -0
  222. package/package.json +6 -5
  223. package/dist/cjs/api/site-version.js +0 -42
  224. package/dist/cjs/api/site-version.js.map +0 -1
  225. package/dist/cjs/api-handler/handlers/clear-draft.js.map +0 -1
  226. package/dist/cjs/next/api-handler/draft.js.map +0 -1
  227. package/dist/cjs/next/api-handler/handlers/redirect-draft.js.map +0 -1
  228. package/dist/cjs/next/api-handler/handlers/redirect-preview.js.map +0 -1
  229. package/dist/cjs/next/draft-mode/index.js.map +0 -1
  230. package/dist/cjs/next/preview-mode.js.map +0 -1
  231. package/dist/cjs/runtimes/react/components/draft-switcher/draft-switcher.js.map +0 -1
  232. package/dist/cjs/runtimes/react/components/draft-switcher/draft-toolbar.js.map +0 -1
  233. package/dist/esm/api/site-version.js +0 -15
  234. package/dist/esm/api/site-version.js.map +0 -1
  235. package/dist/esm/api-handler/handlers/clear-draft.js +0 -17
  236. package/dist/esm/api-handler/handlers/clear-draft.js.map +0 -1
  237. package/dist/esm/next/api-handler/draft.js +0 -14
  238. package/dist/esm/next/api-handler/draft.js.map +0 -1
  239. package/dist/esm/next/api-handler/handlers/redirect-draft.js +0 -52
  240. package/dist/esm/next/api-handler/handlers/redirect-draft.js.map +0 -1
  241. package/dist/esm/next/api-handler/handlers/redirect-preview.js +0 -37
  242. package/dist/esm/next/api-handler/handlers/redirect-preview.js.map +0 -1
  243. package/dist/esm/next/draft-mode/index.js +0 -30
  244. package/dist/esm/next/draft-mode/index.js.map +0 -1
  245. package/dist/esm/next/preview-mode.js +0 -16
  246. package/dist/esm/next/preview-mode.js.map +0 -1
  247. package/dist/esm/runtimes/react/components/draft-switcher/draft-switcher.js.map +0 -1
  248. package/dist/esm/runtimes/react/components/draft-switcher/draft-toolbar.js.map +0 -1
  249. package/dist/types/api/site-version.d.ts +0 -7
  250. package/dist/types/api/site-version.d.ts.map +0 -1
  251. package/dist/types/api-handler/handlers/clear-draft.d.ts +0 -7
  252. package/dist/types/api-handler/handlers/clear-draft.d.ts.map +0 -1
  253. package/dist/types/next/api-handler/draft.d.ts +0 -8
  254. package/dist/types/next/api-handler/draft.d.ts.map +0 -1
  255. package/dist/types/next/api-handler/handlers/redirect-draft.d.ts +0 -6
  256. package/dist/types/next/api-handler/handlers/redirect-draft.d.ts.map +0 -1
  257. package/dist/types/next/api-handler/handlers/redirect-draft.test.d.ts +0 -2
  258. package/dist/types/next/api-handler/handlers/redirect-draft.test.d.ts.map +0 -1
  259. package/dist/types/next/api-handler/handlers/redirect-preview.d.ts +0 -5
  260. package/dist/types/next/api-handler/handlers/redirect-preview.d.ts.map +0 -1
  261. package/dist/types/next/draft-mode/index.d.ts +0 -15
  262. package/dist/types/next/draft-mode/index.d.ts.map +0 -1
  263. package/dist/types/next/preview-mode.d.ts +0 -17
  264. package/dist/types/next/preview-mode.d.ts.map +0 -1
  265. package/dist/types/next/tests/server.api-handler-clear-draft.test.d.ts +0 -2
  266. package/dist/types/next/tests/server.api-handler-clear-draft.test.d.ts.map +0 -1
  267. package/dist/types/next/tests/server.api-handler-redirect-draft.test.d.ts +0 -2
  268. package/dist/types/next/tests/server.api-handler-redirect-draft.test.d.ts.map +0 -1
  269. package/dist/types/next/tests/server.api-handler-redirect-preview.test.d.ts +0 -2
  270. package/dist/types/next/tests/server.api-handler-redirect-preview.test.d.ts.map +0 -1
  271. package/dist/types/runtimes/react/components/draft-switcher/draft-switcher.d.ts +0 -4
  272. package/dist/types/runtimes/react/components/draft-switcher/draft-switcher.d.ts.map +0 -1
  273. package/dist/types/runtimes/react/components/draft-switcher/draft-toolbar.d.ts +0 -6
  274. package/dist/types/runtimes/react/components/draft-switcher/draft-toolbar.d.ts.map +0 -1
@@ -39,7 +39,7 @@ async function testMakeswiftPageHeadRendering(props, { forcePagesRouter = false
39
39
  });
40
40
  return await (0, import_test_utils.act)(
41
41
  async () => (0, import_react2.render)(
42
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_provider.ReactProvider, { runtime, previewMode: false, forcePagesRouter, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_page.Page, { ...props }) }),
42
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_provider.ReactProvider, { runtime, siteVersion: null, forcePagesRouter, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_page.Page, { ...props }) }),
43
43
  {
44
44
  container: document.body.appendChild(document.createElement("head"))
45
45
  }
@@ -50,7 +50,7 @@ async function testMakeswiftPageRendering(props, { forcePagesRouter = false } =
50
50
  const runtime = new import_react_runtime.ReactRuntime();
51
51
  return await (0, import_test_utils.act)(
52
52
  async () => (0, import_react2.render)(
53
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_provider.ReactProvider, { runtime, previewMode: false, forcePagesRouter, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_page.Page, { ...props }) }),
53
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_provider.ReactProvider, { runtime, siteVersion: null, forcePagesRouter, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_page.Page, { ...props }) }),
54
54
  {
55
55
  container: document.body.appendChild(document.createElement("div"))
56
56
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/testing/page-rendering.tsx"],"sourcesContent":["import { type ComponentPropsWithoutRef } from 'react'\n\nimport '@testing-library/jest-dom'\nimport { act } from 'react-dom/test-utils'\nimport { render } from '@testing-library/react'\n\nimport { ReactRuntime } from '../../runtimes/react/react-runtime'\nimport { MakeswiftComponentType } from '../../components'\n\nimport { Page as MakeswiftPage } from '../components/page'\n\nimport { ReactProvider } from './react-provider'\n\nexport async function testMakeswiftPageHeadRendering(\n props: ComponentPropsWithoutRef<typeof MakeswiftPage>,\n { forcePagesRouter = false }: { forcePagesRouter?: boolean } = {},\n) {\n const runtime = new ReactRuntime()\n\n runtime.registerComponent(() => <></>, {\n type: MakeswiftComponentType.Root,\n label: 'Root',\n props: {},\n })\n\n return await act(async () =>\n render(\n <ReactProvider runtime={runtime} previewMode={false} forcePagesRouter={forcePagesRouter}>\n <MakeswiftPage {...props} />\n </ReactProvider>,\n {\n container: document.body.appendChild(document.createElement('head')),\n },\n ),\n )\n}\n\nexport async function testMakeswiftPageRendering(\n props: ComponentPropsWithoutRef<typeof MakeswiftPage>,\n { forcePagesRouter = false }: { forcePagesRouter?: boolean } = {},\n) {\n const runtime = new ReactRuntime()\n\n return await act(async () =>\n render(\n <ReactProvider runtime={runtime} previewMode={false} forcePagesRouter={forcePagesRouter}>\n <MakeswiftPage {...props} />\n </ReactProvider>,\n {\n container: document.body.appendChild(document.createElement('div')),\n },\n ),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBkC;AAjBlC,sBAAO;AACP,wBAAoB;AACpB,IAAAA,gBAAuB;AAEvB,2BAA6B;AAC7B,wBAAuC;AAEvC,kBAAsC;AAEtC,4BAA8B;AAE9B,eAAsB,+BACpB,OACA,EAAE,mBAAmB,MAAM,IAAoC,CAAC,GAChE;AACA,QAAM,UAAU,IAAI,kCAAa;AAEjC,UAAQ,kBAAkB,MAAM,2EAAE,GAAK;AAAA,IACrC,MAAM,yCAAuB;AAAA,IAC7B,OAAO;AAAA,IACP,OAAO,CAAC;AAAA,EACV,CAAC;AAED,SAAO,UAAM;AAAA,IAAI,gBACf;AAAA,MACE,4CAAC,uCAAc,SAAkB,aAAa,OAAO,kBACnD,sDAAC,YAAAC,MAAA,EAAe,GAAG,OAAO,GAC5B;AAAA,MACA;AAAA,QACE,WAAW,SAAS,KAAK,YAAY,SAAS,cAAc,MAAM,CAAC;AAAA,MACrE;AAAA,IACF;AAAA,EACF;AACF;AAEA,eAAsB,2BACpB,OACA,EAAE,mBAAmB,MAAM,IAAoC,CAAC,GAChE;AACA,QAAM,UAAU,IAAI,kCAAa;AAEjC,SAAO,UAAM;AAAA,IAAI,gBACf;AAAA,MACE,4CAAC,uCAAc,SAAkB,aAAa,OAAO,kBACnD,sDAAC,YAAAA,MAAA,EAAe,GAAG,OAAO,GAC5B;AAAA,MACA;AAAA,QACE,WAAW,SAAS,KAAK,YAAY,SAAS,cAAc,KAAK,CAAC;AAAA,MACpE;AAAA,IACF;AAAA,EACF;AACF;","names":["import_react","MakeswiftPage"]}
1
+ {"version":3,"sources":["../../../../src/next/testing/page-rendering.tsx"],"sourcesContent":["import { type ComponentPropsWithoutRef } from 'react'\n\nimport '@testing-library/jest-dom'\nimport { act } from 'react-dom/test-utils'\nimport { render } from '@testing-library/react'\n\nimport { ReactRuntime } from '../../runtimes/react/react-runtime'\nimport { MakeswiftComponentType } from '../../components'\n\nimport { Page as MakeswiftPage } from '../components/page'\n\nimport { ReactProvider } from './react-provider'\n\nexport async function testMakeswiftPageHeadRendering(\n props: ComponentPropsWithoutRef<typeof MakeswiftPage>,\n { forcePagesRouter = false }: { forcePagesRouter?: boolean } = {},\n) {\n const runtime = new ReactRuntime()\n\n runtime.registerComponent(() => <></>, {\n type: MakeswiftComponentType.Root,\n label: 'Root',\n props: {},\n })\n\n return await act(async () =>\n render(\n <ReactProvider runtime={runtime} siteVersion={null} forcePagesRouter={forcePagesRouter}>\n <MakeswiftPage {...props} />\n </ReactProvider>,\n {\n container: document.body.appendChild(document.createElement('head')),\n },\n ),\n )\n}\n\nexport async function testMakeswiftPageRendering(\n props: ComponentPropsWithoutRef<typeof MakeswiftPage>,\n { forcePagesRouter = false }: { forcePagesRouter?: boolean } = {},\n) {\n const runtime = new ReactRuntime()\n\n return await act(async () =>\n render(\n <ReactProvider runtime={runtime} siteVersion={null} forcePagesRouter={forcePagesRouter}>\n <MakeswiftPage {...props} />\n </ReactProvider>,\n {\n container: document.body.appendChild(document.createElement('div')),\n },\n ),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBkC;AAjBlC,sBAAO;AACP,wBAAoB;AACpB,IAAAA,gBAAuB;AAEvB,2BAA6B;AAC7B,wBAAuC;AAEvC,kBAAsC;AAEtC,4BAA8B;AAE9B,eAAsB,+BACpB,OACA,EAAE,mBAAmB,MAAM,IAAoC,CAAC,GAChE;AACA,QAAM,UAAU,IAAI,kCAAa;AAEjC,UAAQ,kBAAkB,MAAM,2EAAE,GAAK;AAAA,IACrC,MAAM,yCAAuB;AAAA,IAC7B,OAAO;AAAA,IACP,OAAO,CAAC;AAAA,EACV,CAAC;AAED,SAAO,UAAM;AAAA,IAAI,gBACf;AAAA,MACE,4CAAC,uCAAc,SAAkB,aAAa,MAAM,kBAClD,sDAAC,YAAAC,MAAA,EAAe,GAAG,OAAO,GAC5B;AAAA,MACA;AAAA,QACE,WAAW,SAAS,KAAK,YAAY,SAAS,cAAc,MAAM,CAAC;AAAA,MACrE;AAAA,IACF;AAAA,EACF;AACF;AAEA,eAAsB,2BACpB,OACA,EAAE,mBAAmB,MAAM,IAAoC,CAAC,GAChE;AACA,QAAM,UAAU,IAAI,kCAAa;AAEjC,SAAO,UAAM;AAAA,IAAI,gBACf;AAAA,MACE,4CAAC,uCAAc,SAAkB,aAAa,MAAM,kBAClD,sDAAC,YAAAA,MAAA,EAAe,GAAG,OAAO,GAC5B;AAAA,MACA;AAAA,QACE,WAAW,SAAS,KAAK,YAAY,SAAS,cAAc,KAAK,CAAC;AAAA,MACpE;AAAA,IACF;AAAA,EACF;AACF;","names":["import_react","MakeswiftPage"]}
@@ -28,10 +28,10 @@ var import_root_style_registry = require("../root-style-registry");
28
28
  function ReactProvider({
29
29
  children,
30
30
  runtime,
31
- previewMode = false,
31
+ siteVersion = null,
32
32
  forcePagesRouter = false
33
33
  }) {
34
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_framework_provider.FrameworkProvider, { forcePagesRouter, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_RuntimeProvider.RuntimeProvider, { previewMode, runtime, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_root_style_registry.NextRootStyleRegistry, { children }) }) });
34
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_framework_provider.FrameworkProvider, { forcePagesRouter, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_RuntimeProvider.RuntimeProvider, { siteVersion, runtime, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_root_style_registry.NextRootStyleRegistry, { children }) }) });
35
35
  }
36
36
  // Annotate the CommonJS export names for ESM import in node:
37
37
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/testing/react-provider.tsx"],"sourcesContent":["import { ReactRuntime } from '../../runtimes/react/react-runtime'\nimport { RuntimeProvider } from '../../runtimes/react/components/RuntimeProvider'\n\nimport { FrameworkProvider } from '../components/framework-provider'\nimport { NextRootStyleRegistry } from '../root-style-registry'\n\nexport function ReactProvider({\n children,\n runtime,\n previewMode = false,\n forcePagesRouter = false,\n}: {\n children: React.ReactNode\n runtime: ReactRuntime\n previewMode?: boolean\n forcePagesRouter?: boolean\n}) {\n return (\n <FrameworkProvider forcePagesRouter={forcePagesRouter}>\n <RuntimeProvider previewMode={previewMode} runtime={runtime}>\n <NextRootStyleRegistry>{children}</NextRootStyleRegistry>\n </RuntimeProvider>\n </FrameworkProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBQ;AAnBR,6BAAgC;AAEhC,gCAAkC;AAClC,iCAAsC;AAE/B,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,mBAAmB;AACrB,GAKG;AACD,SACE,4CAAC,+CAAkB,kBACjB,sDAAC,0CAAgB,aAA0B,SACzC,sDAAC,oDAAuB,UAAS,GACnC,GACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/next/testing/react-provider.tsx"],"sourcesContent":["import { ReactRuntime } from '../../runtimes/react/react-runtime'\nimport { RuntimeProvider } from '../../runtimes/react/components/RuntimeProvider'\n\nimport { FrameworkProvider } from '../components/framework-provider'\nimport { NextRootStyleRegistry } from '../root-style-registry'\nimport { SiteVersion } from '../../api/site-version'\n\nexport function ReactProvider({\n children,\n runtime,\n siteVersion = null,\n forcePagesRouter = false,\n}: {\n children: React.ReactNode\n runtime: ReactRuntime\n siteVersion?: SiteVersion | null\n forcePagesRouter?: boolean\n}) {\n return (\n <FrameworkProvider forcePagesRouter={forcePagesRouter}>\n <RuntimeProvider siteVersion={siteVersion} runtime={runtime}>\n <NextRootStyleRegistry>{children}</NextRootStyleRegistry>\n </RuntimeProvider>\n </FrameworkProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBQ;AApBR,6BAAgC;AAEhC,gCAAkC;AAClC,iCAAsC;AAG/B,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,mBAAmB;AACrB,GAKG;AACD,SACE,4CAAC,+CAAkB,kBACjB,sDAAC,0CAAgB,aAA0B,SACzC,sDAAC,oDAAuB,UAAS,GACnC,GACF;AAEJ;","names":[]}
@@ -28,13 +28,15 @@ var import_server = require("next/server");
28
28
  var import_node_mocks_http = require("node-mocks-http");
29
29
  var import_api_handler = require("../api-handler");
30
30
  var import_react = require("../../react");
31
+ var import_fixtures = require("../../testing/fixtures");
32
+ var import_preview = require("../api-handler/preview");
31
33
  function createHandler(apiKey, args = {}) {
32
34
  const runtime = new import_react.ReactRuntime();
33
35
  return (0, import_api_handler.MakeswiftApiHandler)(apiKey, {
34
36
  ...args,
35
37
  runtime,
36
- apiOrigin: "https://api.fakeswift.com",
37
- appOrigin: "https://app.fakeswift.com"
38
+ apiOrigin: import_fixtures.TestOrigins.apiOrigin,
39
+ appOrigin: import_fixtures.TestOrigins.appOrigin
38
40
  });
39
41
  }
40
42
  const hostUrl = (path) => new URL(path, "https://example.com");
@@ -56,7 +58,7 @@ function createNextApiRequest({
56
58
  query: {
57
59
  ...routeParams(hostUrl(path)),
58
60
  ...Object.fromEntries(url.searchParams.entries()),
59
- ...originalPath ? { path: originalPath } : {}
61
+ ...originalPath ? { [import_preview.RewriteRuleMatches.OriginalPath]: originalPath } : {}
60
62
  },
61
63
  body,
62
64
  headers
@@ -95,7 +97,7 @@ function pagesRouterApiRequestFixture(args = {}, responseMock) {
95
97
  return response._getHeaders()["set-cookie"];
96
98
  },
97
99
  get(key) {
98
- return key.toLowerCase() === "location" ? response._getRedirectUrl() : response._getHeaders()[key];
100
+ return key.toLowerCase() === "location" ? response._getRedirectUrl() || response._getHeaders()["location"] : response._getHeaders()[key];
99
101
  }
100
102
  }
101
103
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/next/tests/test-utils.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { NextRequest } from 'next/server'\nimport {\n createRequest,\n createResponse,\n type RequestMethod,\n type MockResponse,\n} from 'node-mocks-http'\n\nimport { MakeswiftApiHandler } from '../api-handler'\nimport { ReactRuntime } from '../../react'\n\nexport type MakeswiftApiHandlerArgs = Partial<Parameters<typeof MakeswiftApiHandler>[1]>\n\nfunction createHandler(apiKey: string, args: Partial<MakeswiftApiHandlerArgs> = {}) {\n const runtime = new ReactRuntime()\n return MakeswiftApiHandler(apiKey, {\n ...args,\n runtime,\n apiOrigin: 'https://api.fakeswift.com',\n appOrigin: 'https://app.fakeswift.com',\n })\n}\n\nexport const hostUrl = (path: string) => new URL(path, 'https://example.com')\n\nfunction routeParams(url: URL) {\n // simulate Next.js API route's context params, e.g. /api/makeswift/revalidate -> { 'makeswift': ['revalidate'] }\n const segments = url.pathname.split('/').filter(Boolean).slice(1)\n return { [segments[0]]: segments.slice(1) }\n}\n\nexport type RequestParams = {\n method: RequestMethod\n path: string\n originalPath?: string\n body?: Record<string, unknown>\n headers?: Record<string, string>\n}\n\nfunction createNextApiRequest({\n method,\n path,\n originalPath,\n body,\n headers,\n}: RequestParams): NextApiRequest {\n const url = hostUrl(originalPath ?? path)\n return createRequest<NextApiRequest>({\n method,\n url: url.toString(),\n query: {\n ...routeParams(hostUrl(path)),\n ...Object.fromEntries(url.searchParams.entries()),\n ...(originalPath ? { path: originalPath } : {}),\n },\n body,\n headers,\n })\n}\n\nfunction createNextRequestWithContext({\n method,\n path,\n originalPath,\n body,\n headers,\n}: RequestParams): [NextRequest, { params: { [key: string]: string | string[] } }] {\n const request = new NextRequest(hostUrl(originalPath ?? path), {\n method,\n body: JSON.stringify(body),\n headers,\n })\n\n return [request, { params: routeParams(hostUrl(path)) }]\n}\n\nexport function pagesRouterApiRequestFixture(\n args: MakeswiftApiHandlerArgs = {},\n responseMock?: MockResponse<NextApiResponse>,\n) {\n const apiKey = 'pages-router-api-key'\n const handler = createHandler(apiKey, args)\n\n const response = responseMock ?? createResponse<NextApiResponse>()\n const testApiRequest = async (reqParams: RequestParams) => {\n await handler(createNextApiRequest(reqParams), response)\n return {\n statusCode: response.statusCode,\n get jsonBody() {\n return response._getJSONData()\n },\n get textBody() {\n return response._getData()\n },\n headers: {\n getSetCookie() {\n return response._getHeaders()['set-cookie']\n },\n get(key: string) {\n return key.toLowerCase() === 'location'\n ? response._getRedirectUrl()\n : response._getHeaders()[key]\n },\n },\n }\n }\n\n return { testApiRequest, apiKey }\n}\n\nexport function appRouterApiRequestFixture(args: MakeswiftApiHandlerArgs = {}) {\n const apiKey = 'app-router-api-key'\n const handler = createHandler(apiKey, args)\n const testApiRequest = async (reqParams: RequestParams) => {\n const response = await handler(...createNextRequestWithContext(reqParams))\n return {\n statusCode: response?.status,\n get jsonBody() {\n return response?.json()\n },\n get textBody() {\n return response?.text()\n },\n headers: response?.headers ?? new Headers(),\n }\n }\n\n return { testApiRequest, apiKey }\n}\n\nexport const apiRequestFixtures = [\n { fixture: pagesRouterApiRequestFixture, router: 'pages' },\n { fixture: appRouterApiRequestFixture, router: 'app' },\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA4B;AAC5B,6BAKO;AAEP,yBAAoC;AACpC,mBAA6B;AAI7B,SAAS,cAAc,QAAgB,OAAyC,CAAC,GAAG;AAClF,QAAM,UAAU,IAAI,0BAAa;AACjC,aAAO,wCAAoB,QAAQ;AAAA,IACjC,GAAG;AAAA,IACH;AAAA,IACA,WAAW;AAAA,IACX,WAAW;AAAA,EACb,CAAC;AACH;AAEO,MAAM,UAAU,CAAC,SAAiB,IAAI,IAAI,MAAM,qBAAqB;AAE5E,SAAS,YAAY,KAAU;AAE7B,QAAM,WAAW,IAAI,SAAS,MAAM,GAAG,EAAE,OAAO,OAAO,EAAE,MAAM,CAAC;AAChE,SAAO,EAAE,CAAC,SAAS,CAAC,CAAC,GAAG,SAAS,MAAM,CAAC,EAAE;AAC5C;AAUA,SAAS,qBAAqB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAkC;AAChC,QAAM,MAAM,QAAQ,gBAAgB,IAAI;AACxC,aAAO,sCAA8B;AAAA,IACnC;AAAA,IACA,KAAK,IAAI,SAAS;AAAA,IAClB,OAAO;AAAA,MACL,GAAG,YAAY,QAAQ,IAAI,CAAC;AAAA,MAC5B,GAAG,OAAO,YAAY,IAAI,aAAa,QAAQ,CAAC;AAAA,MAChD,GAAI,eAAe,EAAE,MAAM,aAAa,IAAI,CAAC;AAAA,IAC/C;AAAA,IACA;AAAA,IACA;AAAA,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xB;AAAA,MACA,IAAI,WAAW;AACb,eAAO,UAAU,KAAK;AAAA,MACxB;AAAA,MACA,SAAS,UAAU,WAAW,IAAI,QAAQ;AAAA,IAC5C;AAAA,EACF;AAEA,SAAO,EAAE,gBAAgB,OAAO;AAClC;AAEO,MAAM,qBAAqB;AAAA,EAChC,EAAE,SAAS,8BAA8B,QAAQ,QAAQ;AAAA,EACzD,EAAE,SAAS,4BAA4B,QAAQ,MAAM;AACvD;","names":[]}
1
+ {"version":3,"sources":["../../../../src/next/tests/test-utils.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { NextRequest } from 'next/server'\nimport {\n createRequest,\n createResponse,\n type RequestMethod,\n type MockResponse,\n} from 'node-mocks-http'\n\nimport { MakeswiftApiHandler } from '../api-handler'\nimport { ReactRuntime } from '../../react'\nimport { TestOrigins } from '../../testing/fixtures'\nimport { RewriteRuleMatches } from '../api-handler/preview'\n\nexport type MakeswiftApiHandlerArgs = Partial<Parameters<typeof MakeswiftApiHandler>[1]>\n\nfunction createHandler(apiKey: string, args: Partial<MakeswiftApiHandlerArgs> = {}) {\n const runtime = new ReactRuntime()\n return MakeswiftApiHandler(apiKey, {\n ...args,\n runtime,\n apiOrigin: TestOrigins.apiOrigin,\n appOrigin: TestOrigins.appOrigin,\n })\n}\n\nexport const hostUrl = (path: string) => new URL(path, 'https://example.com')\n\nfunction routeParams(url: URL) {\n // simulate Next.js API route's context params, e.g. /api/makeswift/revalidate -> { 'makeswift': ['revalidate'] }\n const segments = url.pathname.split('/').filter(Boolean).slice(1)\n return { [segments[0]]: segments.slice(1) }\n}\n\nexport type RequestParams = {\n method: RequestMethod\n path: string\n originalPath?: string\n body?: Record<string, unknown>\n headers?: Record<string, string>\n}\n\nfunction createNextApiRequest({\n method,\n path,\n originalPath,\n body,\n headers,\n}: RequestParams): NextApiRequest {\n const url = hostUrl(originalPath ?? path)\n return createRequest<NextApiRequest>({\n method,\n url: url.toString(),\n query: {\n ...routeParams(hostUrl(path)),\n ...Object.fromEntries(url.searchParams.entries()),\n ...(originalPath ? { [RewriteRuleMatches.OriginalPath]: originalPath } : {}),\n },\n body,\n headers,\n })\n}\n\nfunction createNextRequestWithContext({\n method,\n path,\n originalPath,\n body,\n headers,\n}: RequestParams): [NextRequest, { params: { [key: string]: string | string[] } }] {\n const request = new NextRequest(hostUrl(originalPath ?? path), {\n method,\n body: JSON.stringify(body),\n headers,\n })\n\n return [request, { params: routeParams(hostUrl(path)) }]\n}\n\nexport function pagesRouterApiRequestFixture(\n args: MakeswiftApiHandlerArgs = {},\n responseMock?: MockResponse<NextApiResponse>,\n) {\n const apiKey = 'pages-router-api-key'\n const handler = createHandler(apiKey, args)\n\n const response = responseMock ?? createResponse<NextApiResponse>()\n const testApiRequest = async (reqParams: RequestParams) => {\n await handler(createNextApiRequest(reqParams), response)\n return {\n statusCode: response.statusCode,\n get jsonBody() {\n return response._getJSONData()\n },\n get textBody() {\n return response._getData()\n },\n headers: {\n getSetCookie() {\n return response._getHeaders()['set-cookie']\n },\n get(key: string) {\n return key.toLowerCase() === 'location'\n ? response._getRedirectUrl() || response._getHeaders()['location']\n : response._getHeaders()[key]\n },\n },\n }\n }\n\n return { testApiRequest, apiKey }\n}\n\nexport function appRouterApiRequestFixture(args: MakeswiftApiHandlerArgs = {}) {\n const apiKey = 'app-router-api-key'\n const handler = createHandler(apiKey, args)\n const testApiRequest = async (reqParams: RequestParams) => {\n const response = await handler(...createNextRequestWithContext(reqParams))\n return {\n statusCode: response?.status,\n get jsonBody() {\n return response?.json()\n },\n get textBody() {\n return response?.text()\n },\n headers: response?.headers ?? new Headers(),\n }\n }\n\n return { testApiRequest, apiKey }\n}\n\nexport const apiRequestFixtures = [\n { fixture: pagesRouterApiRequestFixture, router: 'pages' },\n { fixture: appRouterApiRequestFixture, router: 'app' },\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA4B;AAC5B,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,QAAQ,MAAM;AACvD;","names":[]}
@@ -37,8 +37,7 @@ var import_react = require("react");
37
37
  var import_react2 = require("../../../api/react");
38
38
  var import_use_react_runtime = require("../hooks/use-react-runtime");
39
39
  var import_host_api_client = require("../host-api-client");
40
- var import_site_version = require("../../../api/site-version");
41
- var import_draft_switcher = require("./draft-switcher/draft-switcher");
40
+ var import_preview_switcher = require("./preview-switcher/preview-switcher");
42
41
  var import_use_builder_connection_ping = require("./hooks/use-builder-connection-ping");
43
42
  var import_use_framework_context = require("./hooks/use-framework-context");
44
43
  const LiveProvider = (0, import_react.lazy)(() => Promise.resolve().then(() => __toESM(require("./LiveProvider"))));
@@ -46,7 +45,7 @@ const PreviewProvider = (0, import_react.lazy)(() => Promise.resolve().then(() =
46
45
  function RuntimeProvider({
47
46
  children,
48
47
  runtime,
49
- previewMode,
48
+ siteVersion,
50
49
  appOrigin = "https://app.makeswift.com",
51
50
  apiOrigin = "https://api.makeswift.com",
52
51
  locale = void 0
@@ -56,17 +55,16 @@ function RuntimeProvider({
56
55
  () => new import_react2.MakeswiftHostApiClient({
57
56
  uri: new URL("graphql", apiOrigin).href,
58
57
  locale,
59
- fetch: versionedFetch(
60
- previewMode ? import_site_version.MakeswiftSiteVersion.Working : import_site_version.MakeswiftSiteVersion.Live
61
- )
58
+ fetch: versionedFetch(siteVersion)
62
59
  }),
63
- [apiOrigin, locale, previewMode, versionedFetch]
60
+ [apiOrigin, locale, siteVersion, versionedFetch]
64
61
  );
65
- const StoreProvider = previewMode ? PreviewProvider : LiveProvider;
62
+ const isPreview = siteVersion != null;
63
+ const StoreProvider = isPreview ? PreviewProvider : LiveProvider;
66
64
  (0, import_use_builder_connection_ping.useBuilderConnectionPing)({ appOrigin });
67
65
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_use_react_runtime.ReactRuntimeContext.Provider, { value: runtime, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_host_api_client.MakeswiftHostApiClientProvider, { client, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(StoreProvider, { children: [
68
66
  children,
69
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_draft_switcher.DraftSwitcher, { isDraft: previewMode })
67
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_preview_switcher.PreviewSwitcher, { isPreview })
70
68
  ] }) }) });
71
69
  }
72
70
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/components/RuntimeProvider.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, useMemo, lazy } from 'react'\n\nimport { MakeswiftHostApiClient } from '../../../api/react'\nimport { ReactRuntimeContext } from '../hooks/use-react-runtime'\nimport { ReactRuntime } from '../react-runtime'\nimport { MakeswiftHostApiClientProvider } from '../host-api-client'\nimport { MakeswiftSiteVersion } from '../../../api/site-version'\nimport { DraftSwitcher } from './draft-switcher/draft-switcher'\nimport { useBuilderConnectionPing } from './hooks/use-builder-connection-ping'\nimport { useFrameworkContext } from './hooks/use-framework-context'\n\nconst LiveProvider = lazy(() => import('./LiveProvider'))\nconst PreviewProvider = lazy(() => import('./PreviewProvider'))\n\nexport function RuntimeProvider({\n children,\n runtime,\n previewMode,\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n locale = undefined,\n}: {\n children: ReactNode\n runtime: ReactRuntime\n previewMode: boolean\n apiOrigin?: string\n appOrigin?: string\n locale?: string\n}) {\n const { versionedFetch } = useFrameworkContext()\n\n const client = useMemo(\n () =>\n new MakeswiftHostApiClient({\n uri: new URL('graphql', apiOrigin).href,\n locale,\n fetch: versionedFetch(\n previewMode ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live,\n ),\n }),\n [apiOrigin, locale, previewMode, versionedFetch],\n )\n\n const StoreProvider = previewMode ? PreviewProvider : LiveProvider\n\n useBuilderConnectionPing({ appOrigin })\n\n return (\n <ReactRuntimeContext.Provider value={runtime}>\n <MakeswiftHostApiClientProvider client={client}>\n <StoreProvider>\n {children}\n <DraftSwitcher isDraft={previewMode} />\n </StoreProvider>\n </MakeswiftHostApiClientProvider>\n </ReactRuntimeContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoDQ;AAlDR,mBAAyC;AAEzC,IAAAA,gBAAuC;AACvC,+BAAoC;AAEpC,6BAA+C;AAC/C,0BAAqC;AACrC,4BAA8B;AAC9B,yCAAyC;AACzC,mCAAoC;AAEpC,MAAM,mBAAe,mBAAK,MAAM,6CAAO,gBAAgB,GAAC;AACxD,MAAM,sBAAkB,mBAAK,MAAM,6CAAO,mBAAmB,GAAC;AAEvD,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,SAAS;AACX,GAOG;AACD,QAAM,EAAE,eAAe,QAAI,kDAAoB;AAE/C,QAAM,aAAS;AAAA,IACb,MACE,IAAI,qCAAuB;AAAA,MACzB,KAAK,IAAI,IAAI,WAAW,SAAS,EAAE;AAAA,MACnC;AAAA,MACA,OAAO;AAAA,QACL,cAAc,yCAAqB,UAAU,yCAAqB;AAAA,MACpE;AAAA,IACF,CAAC;AAAA,IACH,CAAC,WAAW,QAAQ,aAAa,cAAc;AAAA,EACjD;AAEA,QAAM,gBAAgB,cAAc,kBAAkB;AAEtD,mEAAyB,EAAE,UAAU,CAAC;AAEtC,SACE,4CAAC,6CAAoB,UAApB,EAA6B,OAAO,SACnC,sDAAC,yDAA+B,QAC9B,uDAAC,iBACE;AAAA;AAAA,IACD,4CAAC,uCAAc,SAAS,aAAa;AAAA,KACvC,GACF,GACF;AAEJ;","names":["import_react"]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/components/RuntimeProvider.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, useMemo, lazy } from 'react'\n\nimport { MakeswiftHostApiClient } from '../../../api/react'\nimport { ReactRuntimeContext } from '../hooks/use-react-runtime'\nimport { ReactRuntime } from '../react-runtime'\nimport { MakeswiftHostApiClientProvider } from '../host-api-client'\nimport { type SiteVersion } from '../../../api/site-version'\nimport { PreviewSwitcher } from './preview-switcher/preview-switcher'\nimport { useBuilderConnectionPing } from './hooks/use-builder-connection-ping'\nimport { useFrameworkContext } from './hooks/use-framework-context'\n\nconst LiveProvider = lazy(() => import('./LiveProvider'))\nconst PreviewProvider = lazy(() => import('./PreviewProvider'))\n\nexport function RuntimeProvider({\n children,\n runtime,\n siteVersion,\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n locale = undefined,\n}: {\n children: ReactNode\n runtime: ReactRuntime\n siteVersion: SiteVersion | null\n apiOrigin?: string\n appOrigin?: string\n locale?: string\n}) {\n const { versionedFetch } = useFrameworkContext()\n\n const client = useMemo(\n () =>\n new MakeswiftHostApiClient({\n uri: new URL('graphql', apiOrigin).href,\n locale,\n fetch: versionedFetch(siteVersion),\n }),\n [apiOrigin, locale, siteVersion, versionedFetch],\n )\n\n const isPreview = siteVersion != null\n const StoreProvider = isPreview ? PreviewProvider : LiveProvider\n\n useBuilderConnectionPing({ appOrigin })\n\n return (\n <ReactRuntimeContext.Provider value={runtime}>\n <MakeswiftHostApiClientProvider client={client}>\n <StoreProvider>\n {children}\n <PreviewSwitcher isPreview={isPreview} />\n </StoreProvider>\n </MakeswiftHostApiClientProvider>\n </ReactRuntimeContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmDQ;AAjDR,mBAAyC;AAEzC,IAAAA,gBAAuC;AACvC,+BAAoC;AAEpC,6BAA+C;AAE/C,8BAAgC;AAChC,yCAAyC;AACzC,mCAAoC;AAEpC,MAAM,mBAAe,mBAAK,MAAM,6CAAO,gBAAgB,GAAC;AACxD,MAAM,sBAAkB,mBAAK,MAAM,6CAAO,mBAAmB,GAAC;AAEvD,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,SAAS;AACX,GAOG;AACD,QAAM,EAAE,eAAe,QAAI,kDAAoB;AAE/C,QAAM,aAAS;AAAA,IACb,MACE,IAAI,qCAAuB;AAAA,MACzB,KAAK,IAAI,IAAI,WAAW,SAAS,EAAE;AAAA,MACnC;AAAA,MACA,OAAO,eAAe,WAAW;AAAA,IACnC,CAAC;AAAA,IACH,CAAC,WAAW,QAAQ,aAAa,cAAc;AAAA,EACjD;AAEA,QAAM,YAAY,eAAe;AACjC,QAAM,gBAAgB,YAAY,kBAAkB;AAEpD,mEAAyB,EAAE,UAAU,CAAC;AAEtC,SACE,4CAAC,6CAAoB,UAApB,EAA6B,OAAO,SACnC,sDAAC,yDAA+B,QAC9B,uDAAC,iBACE;AAAA;AAAA,IACD,4CAAC,2CAAgB,WAAsB;AAAA,KACzC,GACF,GACF;AAEJ;","names":["import_react"]}
@@ -52,7 +52,7 @@ const versionedFetch = (siteVersion) => (url, init) => fetch(url, {
52
52
  ...init,
53
53
  headers: {
54
54
  ...init?.headers,
55
- [import_site_version.API_HANDLER_SITE_VERSION_HEADER]: siteVersion
55
+ ...siteVersion != null ? { [import_site_version.ApiHandlerHeaders.SiteVersion]: (0, import_site_version.serializeSiteVersion)(siteVersion) } : {}
56
56
  }
57
57
  });
58
58
  const FrameworkContext = (0, import_react.createContext)({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/components/framework-context.tsx"],"sourcesContent":["import {\n createContext,\n type ReactNode,\n type PropsWithChildren,\n type CSSProperties,\n type ComponentPropsWithoutRef,\n type MouseEvent,\n type ForwardRefExoticComponent,\n type RefAttributes,\n forwardRef,\n} from 'react'\n\nimport { type LinkData } from '@makeswift/prop-controllers'\n\nimport { type Snippet } from '../../../client'\nimport { type HttpFetch } from '../../../state/makeswift-api-client'\nimport { API_HANDLER_SITE_VERSION_HEADER, MakeswiftSiteVersion } from '../../../api/site-version'\n\nimport { BaseHeadSnippet } from './page/HeadSnippet'\n\ntype HeadComponent = (props: { children: ReactNode }) => ReactNode\ntype HeadSnippet = (props: { snippet: Snippet }) => ReactNode\ntype ImageComponent = (props: {\n src: string\n alt: string\n sizes?: string\n width?: number\n height?: number\n priority?: boolean\n fill?: boolean\n style?: CSSProperties\n}) => ReactNode\n\ntype LinkProps = Omit<ComponentPropsWithoutRef<'a'>, 'onClick'> & {\n linkType?: LinkData['type']\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => unknown\n}\n\ntype LinkComponent = ForwardRefExoticComponent<RefAttributes<HTMLAnchorElement> & LinkProps>\n\nexport type FrameworkContext = {\n Head: HeadComponent\n HeadSnippet: HeadSnippet\n Image: ImageComponent\n Link: LinkComponent\n versionedFetch: (siteVersion: MakeswiftSiteVersion) => HttpFetch\n}\n\n// React 19 automatically hoists metadata tags to the <head>\nexport const DefaultHead = ({ children }: PropsWithChildren) => <>{children}</>\n\nexport const DefaultImage: ImageComponent = ({ priority, fill, style, ...props }) => (\n <img\n {...props}\n style={{\n ...(fill\n ? {\n height: '100%',\n width: '100%',\n objectFit: 'cover',\n }\n : {}),\n ...style,\n }}\n loading={priority ? 'eager' : 'lazy'}\n />\n)\n\nexport const DefaultLink: LinkComponent = forwardRef<HTMLAnchorElement, LinkProps>(\n ({ linkType, ...props }, ref) => <a {...props} ref={ref} />,\n)\n\nexport const versionedFetch: FrameworkContext['versionedFetch'] = siteVersion => (url, init) =>\n fetch(url, {\n ...init,\n headers: {\n ...init?.headers,\n [API_HANDLER_SITE_VERSION_HEADER]: siteVersion,\n },\n })\n\nexport const FrameworkContext = createContext<FrameworkContext>({\n Head: DefaultHead,\n HeadSnippet: BaseHeadSnippet,\n Image: DefaultImage,\n Link: DefaultLink,\n versionedFetch,\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiDgE;AAjDhE,mBAUO;AAMP,0BAAsE;AAEtE,yBAAgC;AA+BzB,MAAM,cAAc,CAAC,EAAE,SAAS,MAAyB,2EAAG,UAAS;AAErE,MAAM,eAA+B,CAAC,EAAE,UAAU,MAAM,OAAO,GAAG,MAAM,MAC7E;AAAA,EAAC;AAAA;AAAA,IACE,GAAG;AAAA,IACJ,OAAO;AAAA,MACL,GAAI,OACA;AAAA,QACE,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,WAAW;AAAA,MACb,IACA,CAAC;AAAA,MACL,GAAG;AAAA,IACL;AAAA,IACA,SAAS,WAAW,UAAU;AAAA;AAChC;AAGK,MAAM,kBAA6B;AAAA,EACxC,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ,4CAAC,OAAG,GAAG,OAAO,KAAU;AAC3D;AAEO,MAAM,iBAAqD,iBAAe,CAAC,KAAK,SACrF,MAAM,KAAK;AAAA,EACT,GAAG;AAAA,EACH,SAAS;AAAA,IACP,GAAG,MAAM;AAAA,IACT,CAAC,mDAA+B,GAAG;AAAA,EACrC;AACF,CAAC;AAEI,MAAM,uBAAmB,4BAAgC;AAAA,EAC9D,MAAM;AAAA,EACN,aAAa;AAAA,EACb,OAAO;AAAA,EACP,MAAM;AAAA,EACN;AACF,CAAC;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/components/framework-context.tsx"],"sourcesContent":["import {\n createContext,\n type ReactNode,\n type PropsWithChildren,\n type CSSProperties,\n type ComponentPropsWithoutRef,\n type MouseEvent,\n type ForwardRefExoticComponent,\n type RefAttributes,\n forwardRef,\n} from 'react'\n\nimport { type LinkData } from '@makeswift/prop-controllers'\n\nimport { type Snippet } from '../../../client'\nimport { type HttpFetch } from '../../../state/makeswift-api-client'\nimport {\n ApiHandlerHeaders,\n serializeSiteVersion,\n type SiteVersion,\n} from '../../../api/site-version'\n\nimport { BaseHeadSnippet } from './page/HeadSnippet'\n\ntype HeadComponent = (props: { children: ReactNode }) => ReactNode\ntype HeadSnippet = (props: { snippet: Snippet }) => ReactNode\ntype ImageComponent = (props: {\n src: string\n alt: string\n sizes?: string\n width?: number\n height?: number\n priority?: boolean\n fill?: boolean\n style?: CSSProperties\n}) => ReactNode\n\ntype LinkProps = Omit<ComponentPropsWithoutRef<'a'>, 'onClick'> & {\n linkType?: LinkData['type']\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => unknown\n}\n\ntype LinkComponent = ForwardRefExoticComponent<RefAttributes<HTMLAnchorElement> & LinkProps>\n\nexport type FrameworkContext = {\n Head: HeadComponent\n HeadSnippet: HeadSnippet\n Image: ImageComponent\n Link: LinkComponent\n versionedFetch: (siteVersion: SiteVersion | null) => HttpFetch\n}\n\n// React 19 automatically hoists metadata tags to the <head>\nexport const DefaultHead = ({ children }: PropsWithChildren) => <>{children}</>\n\nexport const DefaultImage: ImageComponent = ({ priority, fill, style, ...props }) => (\n <img\n {...props}\n style={{\n ...(fill\n ? {\n height: '100%',\n width: '100%',\n objectFit: 'cover',\n }\n : {}),\n ...style,\n }}\n loading={priority ? 'eager' : 'lazy'}\n />\n)\n\nexport const DefaultLink: LinkComponent = forwardRef<HTMLAnchorElement, LinkProps>(\n ({ linkType, ...props }, ref) => <a {...props} ref={ref} />,\n)\n\nexport const versionedFetch: FrameworkContext['versionedFetch'] = siteVersion => (url, init) =>\n fetch(url, {\n ...init,\n headers: {\n ...init?.headers,\n ...(siteVersion != null\n ? { [ApiHandlerHeaders.SiteVersion]: serializeSiteVersion(siteVersion) }\n : {}),\n },\n })\n\nexport const FrameworkContext = createContext<FrameworkContext>({\n Head: DefaultHead,\n HeadSnippet: BaseHeadSnippet,\n Image: DefaultImage,\n Link: DefaultLink,\n versionedFetch,\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqDgE;AArDhE,mBAUO;AAMP,0BAIO;AAEP,yBAAgC;AA+BzB,MAAM,cAAc,CAAC,EAAE,SAAS,MAAyB,2EAAG,UAAS;AAErE,MAAM,eAA+B,CAAC,EAAE,UAAU,MAAM,OAAO,GAAG,MAAM,MAC7E;AAAA,EAAC;AAAA;AAAA,IACE,GAAG;AAAA,IACJ,OAAO;AAAA,MACL,GAAI,OACA;AAAA,QACE,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,WAAW;AAAA,MACb,IACA,CAAC;AAAA,MACL,GAAG;AAAA,IACL;AAAA,IACA,SAAS,WAAW,UAAU;AAAA;AAChC;AAGK,MAAM,kBAA6B;AAAA,EACxC,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ,4CAAC,OAAG,GAAG,OAAO,KAAU;AAC3D;AAEO,MAAM,iBAAqD,iBAAe,CAAC,KAAK,SACrF,MAAM,KAAK;AAAA,EACT,GAAG;AAAA,EACH,SAAS;AAAA,IACP,GAAG,MAAM;AAAA,IACT,GAAI,eAAe,OACf,EAAE,CAAC,sCAAkB,WAAW,OAAG,0CAAqB,WAAW,EAAE,IACrE,CAAC;AAAA,EACP;AACF,CAAC;AAEI,MAAM,uBAAmB,4BAAgC;AAAA,EAC9D,MAAM;AAAA,EACN,aAAa;AAAA,EACb,OAAO;AAAA,EACP,MAAM;AAAA,EACN;AACF,CAAC;","names":[]}
@@ -38,22 +38,24 @@ function useRegisterPageDocument(pageDocument) {
38
38
  (0, import_use_universal_dispatch.useUniversalDispatch)(dispatch, import_actions.registerDocumentsEffect, [rootDocuments]);
39
39
  return rootDocuments[0];
40
40
  }
41
- const Page = ({
42
- snapshot,
43
- metadata
44
- }) => {
45
- (0, import_use_cache_data.useCacheData)(snapshot.cacheData);
46
- const rootDocument = useRegisterPageDocument(snapshot.document);
47
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
48
- import_Page.Page,
49
- {
50
- page: snapshot.document,
51
- rootDocument,
52
- metadata
53
- },
54
- snapshot.document.data.key
55
- ) });
56
- };
41
+ const Page = (0, import_react.memo)(
42
+ ({
43
+ snapshot,
44
+ metadata = true
45
+ }) => {
46
+ (0, import_use_cache_data.useCacheData)(snapshot.cacheData);
47
+ const rootDocument = useRegisterPageDocument(snapshot.document);
48
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
49
+ import_Page.Page,
50
+ {
51
+ page: snapshot.document,
52
+ rootDocument,
53
+ metadata
54
+ },
55
+ snapshot.document.data.key
56
+ ) });
57
+ }
58
+ );
57
59
  // Annotate the CommonJS export names for ESM import in node:
58
60
  0 && (module.exports = {
59
61
  Page
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/runtimes/react/components/page/index.tsx"],"sourcesContent":["import { Suspense, useMemo } from 'react'\n\nimport { useDispatch } from '../../hooks/use-dispatch'\nimport { useUniversalDispatch } from '../../hooks/use-universal-dispatch'\nimport { useCacheData } from '../../hooks/use-cache-data'\n\nimport {\n type MakeswiftPageSnapshot,\n type MakeswiftPageDocument,\n pageToRootDocument,\n} from '../../../../client'\n\nimport * as ReactPage from '../../../../state/react-page'\nimport { registerDocumentsEffect } from '../../../../state/actions'\n\nimport { type PageMetadataSettings } from './page-seo-settings'\nimport { Page as PageComponent } from './Page'\n\nexport { type PageMetadataSettings } from './page-seo-settings'\n\nfunction useRegisterPageDocument(pageDocument: MakeswiftPageDocument): ReactPage.Document {\n const dispatch = useDispatch()\n const rootDocuments: [ReactPage.Document] = useMemo(\n () => [pageToRootDocument(pageDocument)],\n [pageDocument],\n )\n\n useUniversalDispatch(dispatch, registerDocumentsEffect, [rootDocuments])\n\n return rootDocuments[0]\n}\n\nexport const Page = ({\n snapshot,\n metadata,\n}: {\n snapshot: MakeswiftPageSnapshot\n metadata: boolean | PageMetadataSettings\n}) => {\n useCacheData(snapshot.cacheData)\n\n const rootDocument = useRegisterPageDocument(snapshot.document)\n\n return (\n <Suspense>\n {/* We use a key here to reset the Snippets state in the PageMeta component */}\n <PageComponent\n key={snapshot.document.data.key}\n page={snapshot.document}\n rootDocument={rootDocument}\n metadata={metadata}\n />\n </Suspense>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8CM;AA9CN,mBAAkC;AAElC,0BAA4B;AAC5B,oCAAqC;AACrC,4BAA6B;AAE7B,oBAIO;AAGP,qBAAwC;AAGxC,kBAAsC;AAItC,SAAS,wBAAwB,cAAyD;AACxF,QAAM,eAAW,iCAAY;AAC7B,QAAM,oBAAsC;AAAA,IAC1C,MAAM,KAAC,kCAAmB,YAAY,CAAC;AAAA,IACvC,CAAC,YAAY;AAAA,EACf;AAEA,0DAAqB,UAAU,wCAAyB,CAAC,aAAa,CAAC;AAEvE,SAAO,cAAc,CAAC;AACxB;AAEO,MAAM,OAAO,CAAC;AAAA,EACnB;AAAA,EACA;AACF,MAGM;AACJ,0CAAa,SAAS,SAAS;AAE/B,QAAM,eAAe,wBAAwB,SAAS,QAAQ;AAE9D,SACE,4CAAC,yBAEC;AAAA,IAAC,YAAAA;AAAA,IAAA;AAAA,MAEC,MAAM,SAAS;AAAA,MACf;AAAA,MACA;AAAA;AAAA,IAHK,SAAS,SAAS,KAAK;AAAA,EAI9B,GACF;AAEJ;","names":["PageComponent"]}
1
+ {"version":3,"sources":["../../../../../../src/runtimes/react/components/page/index.tsx"],"sourcesContent":["import { Suspense, useMemo, memo, type ComponentProps } from 'react'\n\nimport { useDispatch } from '../../hooks/use-dispatch'\nimport { useUniversalDispatch } from '../../hooks/use-universal-dispatch'\nimport { useCacheData } from '../../hooks/use-cache-data'\n\nimport {\n type MakeswiftPageSnapshot,\n type MakeswiftPageDocument,\n pageToRootDocument,\n} from '../../../../client'\n\nimport * as ReactPage from '../../../../state/react-page'\nimport { registerDocumentsEffect } from '../../../../state/actions'\n\nimport { type PageMetadataSettings } from './page-seo-settings'\nimport { Page as PageComponent } from './Page'\n\nexport { type PageMetadataSettings } from './page-seo-settings'\n\nfunction useRegisterPageDocument(pageDocument: MakeswiftPageDocument): ReactPage.Document {\n const dispatch = useDispatch()\n const rootDocuments: [ReactPage.Document] = useMemo(\n () => [pageToRootDocument(pageDocument)],\n [pageDocument],\n )\n\n useUniversalDispatch(dispatch, registerDocumentsEffect, [rootDocuments])\n\n return rootDocuments[0]\n}\n\n/**\n * @param snapshot - The snapshot of the page to render, from\n * `client.getPageSnapshot()`.\n * @param metadata - Allows control over whether to use data from Makeswift for\n * rendering metadata tags in the `<head>` of the page. Pass `true` (default if\n * not provided) to render all metadata tags, or `false` to not render any. For\n * more granular control, pass an object with boolean values for specific\n * metadata fields. Valid fields include:\n * - `title`\n * - `description`\n * - `keywords`\n * - `socialImage`\n * - `canonicalUrl`\n * - `indexingBlocked`\n * - `favicon`\n *\n * If a field is not provided, it will default to `false`.\n */\nexport const Page = memo(\n ({\n snapshot,\n metadata = true,\n }: {\n snapshot: MakeswiftPageSnapshot\n metadata?: boolean | PageMetadataSettings\n }) => {\n useCacheData(snapshot.cacheData)\n\n const rootDocument = useRegisterPageDocument(snapshot.document)\n\n return (\n <Suspense>\n {/* We use a key here to reset the Snippets state in the PageMeta component */}\n <PageComponent\n key={snapshot.document.data.key}\n page={snapshot.document}\n rootDocument={rootDocument}\n metadata={metadata}\n />\n </Suspense>\n )\n },\n)\n\nexport type PageProps = ComponentProps<typeof Page>\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiEQ;AAjER,mBAA6D;AAE7D,0BAA4B;AAC5B,oCAAqC;AACrC,4BAA6B;AAE7B,oBAIO;AAGP,qBAAwC;AAGxC,kBAAsC;AAItC,SAAS,wBAAwB,cAAyD;AACxF,QAAM,eAAW,iCAAY;AAC7B,QAAM,oBAAsC;AAAA,IAC1C,MAAM,KAAC,kCAAmB,YAAY,CAAC;AAAA,IACvC,CAAC,YAAY;AAAA,EACf;AAEA,0DAAqB,UAAU,wCAAyB,CAAC,aAAa,CAAC;AAEvE,SAAO,cAAc,CAAC;AACxB;AAoBO,MAAM,WAAO;AAAA,EAClB,CAAC;AAAA,IACC;AAAA,IACA,WAAW;AAAA,EACb,MAGM;AACJ,4CAAa,SAAS,SAAS;AAE/B,UAAM,eAAe,wBAAwB,SAAS,QAAQ;AAE9D,WACE,4CAAC,yBAEC;AAAA,MAAC,YAAAA;AAAA,MAAA;AAAA,QAEC,MAAM,SAAS;AAAA,QACf;AAAA,QACA;AAAA;AAAA,MAHK,SAAS,SAAS,KAAK;AAAA,IAI9B,GACF;AAAA,EAEJ;AACF;","names":["PageComponent"]}
@@ -16,32 +16,22 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var draft_switcher_exports = {};
20
- __export(draft_switcher_exports, {
21
- DraftSwitcher: () => DraftSwitcher
19
+ var preview_switcher_exports = {};
20
+ __export(preview_switcher_exports, {
21
+ PreviewSwitcher: () => PreviewSwitcher
22
22
  });
23
- module.exports = __toCommonJS(draft_switcher_exports);
23
+ module.exports = __toCommonJS(preview_switcher_exports);
24
24
  var import_jsx_runtime = require("react/jsx-runtime");
25
25
  var import_react = require("react");
26
26
  var import_react_dom = require("react-dom");
27
27
  var import_head_tags = require("../page/head-tags");
28
28
  var import_use_is_in_builder = require("../../hooks/use-is-in-builder");
29
- var import_draft_toolbar = require("./draft-toolbar");
30
- const ClearDraftModeRequestPath = "/api/makeswift/clear-draft";
31
- async function exitDraftMode() {
32
- try {
33
- await fetch(ClearDraftModeRequestPath);
34
- window.location.reload();
35
- } catch (err) {
36
- console.error("Could not clear Makeswift cookies. Please report this error to your developer.");
37
- console.error(err);
38
- }
39
- }
40
- function DraftSwitcher({ isDraft }) {
29
+ var import_preview_toolbar = require("./preview-toolbar");
30
+ function PreviewSwitcher({ isPreview }) {
41
31
  const shadowContainerRef = (0, import_react.useRef)(null);
42
32
  const [shadowRoot, setShadowRoot] = (0, import_react.useState)(null);
43
33
  const isInBuilder = (0, import_use_is_in_builder.useIsInBuilder)();
44
- const showToolbar = !isInBuilder && isDraft;
34
+ const showToolbar = !isInBuilder && isPreview;
45
35
  (0, import_react.useEffect)(() => {
46
36
  if (!showToolbar)
47
37
  return;
@@ -51,18 +41,18 @@ function DraftSwitcher({ isDraft }) {
51
41
  }
52
42
  }, [showToolbar, shadowRoot, setShadowRoot]);
53
43
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
54
- showToolbar && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { id: "makeswift-draft-switcher", ref: shadowContainerRef, children: shadowRoot ? (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_draft_toolbar.DraftToolbar, { onExitDraft: exitDraftMode }), shadowRoot) : null }),
44
+ showToolbar && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { id: "makeswift-preview-switcher", ref: shadowContainerRef, children: shadowRoot ? (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_preview_toolbar.PreviewToolbar, {}), shadowRoot) : null }),
55
45
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
56
46
  import_head_tags.PageMeta,
57
47
  {
58
- name: "makeswift-draft-info",
59
- content: JSON.stringify({ draft: isDraft, inBuilder: isInBuilder })
48
+ name: "makeswift-preview-info",
49
+ content: JSON.stringify({ isPreview, inBuilder: isInBuilder })
60
50
  }
61
51
  )
62
52
  ] });
63
53
  }
64
54
  // Annotate the CommonJS export names for ESM import in node:
65
55
  0 && (module.exports = {
66
- DraftSwitcher
56
+ PreviewSwitcher
67
57
  });
68
- //# sourceMappingURL=draft-switcher.js.map
58
+ //# sourceMappingURL=preview-switcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/runtimes/react/components/preview-switcher/preview-switcher.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\n\nimport { PageMeta } from '../page/head-tags'\nimport { useIsInBuilder } from '../../hooks/use-is-in-builder'\nimport { PreviewToolbar } from './preview-toolbar'\n\nexport function PreviewSwitcher({ isPreview }: { isPreview: boolean }) {\n const shadowContainerRef = useRef<HTMLSpanElement | null>(null)\n const [shadowRoot, setShadowRoot] = useState<ShadowRoot | null>(null)\n const isInBuilder = useIsInBuilder()\n\n const showToolbar = !isInBuilder && isPreview\n\n useEffect(() => {\n if (!showToolbar) return\n if (\n shadowContainerRef.current &&\n shadowContainerRef.current.shadowRoot == null &&\n shadowRoot == null\n ) {\n const root = shadowContainerRef.current.attachShadow({ mode: 'open' })\n setShadowRoot(root)\n }\n }, [showToolbar, shadowRoot, setShadowRoot])\n\n return (\n <>\n {showToolbar && (\n <span id=\"makeswift-preview-switcher\" ref={shadowContainerRef}>\n {shadowRoot ? createPortal(<PreviewToolbar />, shadowRoot) : null}\n </span>\n )}\n {/* Insert preview mode information into the DOM to make it easier to debug preview mode-related\n issues on production sites */}\n <PageMeta\n name=\"makeswift-preview-info\"\n content={JSON.stringify({ isPreview: isPreview, inBuilder: isInBuilder })}\n />\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BI;AA3BJ,mBAA4C;AAC5C,uBAA6B;AAE7B,uBAAyB;AACzB,+BAA+B;AAC/B,6BAA+B;AAExB,SAAS,gBAAgB,EAAE,UAAU,GAA2B;AACrE,QAAM,yBAAqB,qBAA+B,IAAI;AAC9D,QAAM,CAAC,YAAY,aAAa,QAAI,uBAA4B,IAAI;AACpE,QAAM,kBAAc,yCAAe;AAEnC,QAAM,cAAc,CAAC,eAAe;AAEpC,8BAAU,MAAM;AACd,QAAI,CAAC;AAAa;AAClB,QACE,mBAAmB,WACnB,mBAAmB,QAAQ,cAAc,QACzC,cAAc,MACd;AACA,YAAM,OAAO,mBAAmB,QAAQ,aAAa,EAAE,MAAM,OAAO,CAAC;AACrE,oBAAc,IAAI;AAAA,IACpB;AAAA,EACF,GAAG,CAAC,aAAa,YAAY,aAAa,CAAC;AAE3C,SACE,4EACG;AAAA,mBACC,4CAAC,UAAK,IAAG,8BAA6B,KAAK,oBACxC,2BAAa,+BAAa,4CAAC,yCAAe,GAAI,UAAU,IAAI,MAC/D;AAAA,IAIF;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,SAAS,KAAK,UAAU,EAAE,WAAsB,WAAW,YAAY,CAAC;AAAA;AAAA,IAC1E;AAAA,KACF;AAEJ;","names":[]}
@@ -16,12 +16,13 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var draft_toolbar_exports = {};
20
- __export(draft_toolbar_exports, {
21
- DraftToolbar: () => DraftToolbar
19
+ var preview_toolbar_exports = {};
20
+ __export(preview_toolbar_exports, {
21
+ PreviewToolbar: () => PreviewToolbar
22
22
  });
23
- module.exports = __toCommonJS(draft_toolbar_exports);
23
+ module.exports = __toCommonJS(preview_toolbar_exports);
24
24
  var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_react = require("react");
25
26
  const makeswiftIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACIAAAAiCAYAAAA6RwvCAAAACXBIWXMAABcRAAAXEQHKJvM/AAABjElEQVRYhc2XzU3EMBCFB8TddAAXn6EE6GCpgNABZ1/IXnymBOgAOmA7YM8+ABVsXEHQQFaKQryeN3Yk3ilKJtEnv/nLUd/3pFG0riGi88yrnQn+UfJ5FUi0riWiB2H4nQn+KRd0DFP8agXEfkqCYJBoHdtxIQxfm+DfFgEhoith3NYE30o/qgGR2BJB+xY7kdYEL8oNFUi0jiFMJuxVWrJqEMFxsyUNCsE6AeNztvBp7aJ143vXksoRnwhYtmNdSoIQa6RlO9YXEWW7KgoCleOgxgTf1QZBT+RZ2lXFING6UxCCq+ceeUE8fYdknY599v9sJvzGBP+yCEgC7GPmETc0OJ+0awAlkhe2pAbIXAeFZ8xe2g2Nk3c3ub0xwWt6zY9qbmiqGVMbZK21ZC/YmhlbeBMTzZNDQqcvDb1kM1x32iqZSt1HaqukfKvq34BAOTLsrH+ETNmUkKHHA+428RgeclPVWozeSyAI2EdWB34jtqXNTAySOY3i/KgFIlqOa4GkFmBegorzg4joG07he/M7zl6jAAAAAElFTkSuQmCC";
26
27
  const styles = `
27
28
  .exit-preview-container {
@@ -41,6 +42,7 @@ const styles = `
41
42
  0 11px 40px 0 rgba(0, 0, 0, 0.25),
42
43
  0 2px 10px 0 rgba(0, 0, 0, 0.12);
43
44
  transition: 150ms;
45
+ text-decoration: none;
44
46
 
45
47
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji',
46
48
  'Segoe UI Emoji';
@@ -63,17 +65,23 @@ const styles = `
63
65
  0 6px 10px 0 rgba(0, 0, 0, 0.15);
64
66
  }
65
67
  `;
66
- function DraftToolbar({ onExitDraft }) {
68
+ function PreviewToolbar() {
69
+ const redirectLiveUrl = (0, import_react.useMemo)(() => {
70
+ const currentUrl = new URL(window.location.href);
71
+ const destination = `${currentUrl.pathname}${currentUrl.search}${currentUrl.hash}`;
72
+ currentUrl.searchParams.set("x-makeswift-redirect-live", encodeURIComponent(destination));
73
+ return currentUrl.toString();
74
+ }, []);
67
75
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
68
76
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { dangerouslySetInnerHTML: { __html: styles } }),
69
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "exit-preview-container", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { className: "exit-preview-button", onClick: onExitDraft, children: [
77
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "exit-preview-container", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("a", { className: "exit-preview-button", href: redirectLiveUrl, children: [
70
78
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: makeswiftIcon, alt: "Makeswift Logo", width: 18, height: 18 }),
71
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "label", children: "Exit Preview" })
79
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "label", children: "Exit preview" })
72
80
  ] }) })
73
81
  ] });
74
82
  }
75
83
  // Annotate the CommonJS export names for ESM import in node:
76
84
  0 && (module.exports = {
77
- DraftToolbar
85
+ PreviewToolbar
78
86
  });
79
- //# sourceMappingURL=draft-toolbar.js.map
87
+ //# sourceMappingURL=preview-toolbar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/runtimes/react/components/preview-switcher/preview-toolbar.tsx"],"sourcesContent":["import { useMemo } from 'react'\n\nconst makeswiftIcon =\n 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACIAAAAiCAYAAAA6RwvCAAAACXBIWXMAABcRAAAXEQHKJvM/AAABjElEQVRYhc2XzU3EMBCFB8TddAAXn6EE6GCpgNABZ1/IXnymBOgAOmA7YM8+ABVsXEHQQFaKQryeN3Yk3ilKJtEnv/nLUd/3pFG0riGi88yrnQn+UfJ5FUi0riWiB2H4nQn+KRd0DFP8agXEfkqCYJBoHdtxIQxfm+DfFgEhoith3NYE30o/qgGR2BJB+xY7kdYEL8oNFUi0jiFMJuxVWrJqEMFxsyUNCsE6AeNztvBp7aJ143vXksoRnwhYtmNdSoIQa6RlO9YXEWW7KgoCleOgxgTf1QZBT+RZ2lXFING6UxCCq+ceeUE8fYdknY599v9sJvzGBP+yCEgC7GPmETc0OJ+0awAlkhe2pAbIXAeFZ8xe2g2Nk3c3ub0xwWt6zY9qbmiqGVMbZK21ZC/YmhlbeBMTzZNDQqcvDb1kM1x32iqZSt1HaqukfKvq34BAOTLsrH+ETNmUkKHHA+428RgeclPVWozeSyAI2EdWB34jtqXNTAySOY3i/KgFIlqOa4GkFmBegorzg4joG07he/M7zl6jAAAAAElFTkSuQmCC'\n\nconst styles = `\n.exit-preview-container {\n position: fixed;\n bottom: 16px;\n right: 16px;\n z-index: 2147483647;\n}\n\n.exit-preview-button {\n background: #2e2e2e;\n padding: 10px 18px 10px 14px;\n border: 0px;\n border-radius: 32px;\n color: #efefef;\n box-shadow:\n 0 11px 40px 0 rgba(0, 0, 0, 0.25),\n 0 2px 10px 0 rgba(0, 0, 0, 0.12);\n transition: 150ms;\n text-decoration: none;\n\n font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji',\n 'Segoe UI Emoji';\n font-size: 14px;\n cursor: pointer;\n\n display: flex;\n align-items: center;\n gap: 6px;\n}\n\n.exit-preview-button > .label {\n transform: translateY(-1px);\n}\n\n.exit-preview-container:hover > .exit-preview-button {\n transform: translateY(-2px);\n box-shadow:\n 0 15px 40px 0 rgba(0, 0, 0, 0.3),\n 0 6px 10px 0 rgba(0, 0, 0, 0.15);\n}\n`\n\nexport function PreviewToolbar() {\n const redirectLiveUrl = useMemo(() => {\n const currentUrl = new URL(window.location.href)\n const destination = `${currentUrl.pathname}${currentUrl.search}${currentUrl.hash}`\n currentUrl.searchParams.set('x-makeswift-redirect-live', encodeURIComponent(destination))\n return currentUrl.toString()\n }, [])\n\n return (\n <>\n <style dangerouslySetInnerHTML={{ __html: styles }} />\n <div className=\"exit-preview-container\">\n <a className=\"exit-preview-button\" href={redirectLiveUrl}>\n <img src={makeswiftIcon} alt=\"Makeswift Logo\" width={18} height={18} />\n <span className=\"label\">Exit preview</span>\n </a>\n </div>\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwDI;AAxDJ,mBAAwB;AAExB,MAAM,gBACJ;AAEF,MAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0CR,SAAS,iBAAiB;AAC/B,QAAM,sBAAkB,sBAAQ,MAAM;AACpC,UAAM,aAAa,IAAI,IAAI,OAAO,SAAS,IAAI;AAC/C,UAAM,cAAc,GAAG,WAAW,QAAQ,GAAG,WAAW,MAAM,GAAG,WAAW,IAAI;AAChF,eAAW,aAAa,IAAI,6BAA6B,mBAAmB,WAAW,CAAC;AACxF,WAAO,WAAW,SAAS;AAAA,EAC7B,GAAG,CAAC,CAAC;AAEL,SACE,4EACE;AAAA,gDAAC,WAAM,yBAAyB,EAAE,QAAQ,OAAO,GAAG;AAAA,IACpD,4CAAC,SAAI,WAAU,0BACb,uDAAC,OAAE,WAAU,uBAAsB,MAAM,iBACvC;AAAA,kDAAC,SAAI,KAAK,eAAe,KAAI,kBAAiB,OAAO,IAAI,QAAQ,IAAI;AAAA,MACrE,4CAAC,UAAK,WAAU,SAAQ,0BAAY;AAAA,OACtC,GACF;AAAA,KACF;AAEJ;","names":[]}
@@ -31,13 +31,12 @@ __export(makeswift_api_exports, {
31
31
  });
32
32
  module.exports = __toCommonJS(makeswift_api_exports);
33
33
  var import_react = require("react");
34
- var import_shim = require("use-sync-external-store/shim");
35
34
  var import_host_api_client = require("../host-api-client");
36
35
  var import_use_document_context = require("./use-document-context");
37
36
  function useSwatch(swatchId) {
38
37
  const client = (0, import_host_api_client.useMakeswiftHostApiClient)();
39
38
  const readSwatch = () => swatchId == null ? null : client.readSwatch(swatchId);
40
- const swatch = (0, import_shim.useSyncExternalStore)(client.subscribe, readSwatch, readSwatch);
39
+ const swatch = (0, import_react.useSyncExternalStore)(client.subscribe, readSwatch, readSwatch);
41
40
  (0, import_react.useEffect)(() => {
42
41
  if (swatchId != null)
43
42
  client.fetchSwatch(swatchId).catch(console.error);
@@ -54,7 +53,7 @@ function useSwatches(swatchIds) {
54
53
  }
55
54
  return lastSnapshot.current = swatches2;
56
55
  }
57
- const swatches = (0, import_shim.useSyncExternalStore)(client.subscribe, getSnapshot, getSnapshot);
56
+ const swatches = (0, import_react.useSyncExternalStore)(client.subscribe, getSnapshot, getSnapshot);
58
57
  (0, import_react.useEffect)(() => {
59
58
  Promise.all(swatchIds.map((swatchId) => client.fetchSwatch(swatchId))).catch(console.error);
60
59
  }, [client, swatchIds]);
@@ -63,7 +62,7 @@ function useSwatches(swatchIds) {
63
62
  function useFile(fileId) {
64
63
  const client = (0, import_host_api_client.useMakeswiftHostApiClient)();
65
64
  const readFile = () => fileId == null ? null : client.readFile(fileId);
66
- const file = (0, import_shim.useSyncExternalStore)(client.subscribe, readFile, readFile);
65
+ const file = (0, import_react.useSyncExternalStore)(client.subscribe, readFile, readFile);
67
66
  (0, import_react.useEffect)(() => {
68
67
  if (fileId != null)
69
68
  client.fetchFile(fileId);
@@ -80,7 +79,7 @@ function useFiles(fileIds) {
80
79
  }
81
80
  return lastSnapshot.current = files2;
82
81
  }
83
- const files = (0, import_shim.useSyncExternalStore)(client.subscribe, getSnapshot, getSnapshot);
82
+ const files = (0, import_react.useSyncExternalStore)(client.subscribe, getSnapshot, getSnapshot);
84
83
  (0, import_react.useEffect)(() => {
85
84
  Promise.all(fileIds.map((fileId) => client.fetchFile(fileId))).catch(console.error);
86
85
  }, [client, fileIds]);
@@ -89,7 +88,7 @@ function useFiles(fileIds) {
89
88
  function useTypography(typographyId) {
90
89
  const client = (0, import_host_api_client.useMakeswiftHostApiClient)();
91
90
  const readTypography = () => typographyId == null ? null : client.readTypography(typographyId);
92
- const typography = (0, import_shim.useSyncExternalStore)(client.subscribe, readTypography, readTypography);
91
+ const typography = (0, import_react.useSyncExternalStore)(client.subscribe, readTypography, readTypography);
93
92
  (0, import_react.useEffect)(() => {
94
93
  if (typographyId != null)
95
94
  client.fetchTypography(typographyId).catch(console.error);
@@ -99,7 +98,7 @@ function useTypography(typographyId) {
99
98
  function useGlobalElement(globalElementId) {
100
99
  const client = (0, import_host_api_client.useMakeswiftHostApiClient)();
101
100
  const readGlobalElement = () => globalElementId == null ? null : client.readGlobalElement(globalElementId);
102
- const globalElement = (0, import_shim.useSyncExternalStore)(client.subscribe, readGlobalElement, readGlobalElement);
101
+ const globalElement = (0, import_react.useSyncExternalStore)(client.subscribe, readGlobalElement, readGlobalElement);
103
102
  (0, import_react.useEffect)(() => {
104
103
  if (globalElementId != null)
105
104
  client.fetchGlobalElement(globalElementId).catch(console.error);
@@ -109,7 +108,7 @@ function useGlobalElement(globalElementId) {
109
108
  function useLocalizedGlobalElement(locale, globalElementId) {
110
109
  const client = (0, import_host_api_client.useMakeswiftHostApiClient)();
111
110
  const readLocalizedGlobalElement = () => locale == null || globalElementId == null ? null : client.readLocalizedGlobalElement({ globalElementId, locale });
112
- const localizedGlobalElement = (0, import_shim.useSyncExternalStore)(
111
+ const localizedGlobalElement = (0, import_react.useSyncExternalStore)(
113
112
  client.subscribe,
114
113
  readLocalizedGlobalElement,
115
114
  readLocalizedGlobalElement
@@ -125,7 +124,7 @@ function usePagePathnameSlice(pageId) {
125
124
  const client = (0, import_host_api_client.useMakeswiftHostApiClient)();
126
125
  const locale = (0, import_use_document_context.useDocumentLocale)();
127
126
  const readPagePathnameSlice = () => pageId == null ? null : client.readPagePathnameSlice({ pageId, locale });
128
- const pagePathnameSlice = (0, import_shim.useSyncExternalStore)(
127
+ const pagePathnameSlice = (0, import_react.useSyncExternalStore)(
129
128
  client.subscribe,
130
129
  readPagePathnameSlice,
131
130
  readPagePathnameSlice
@@ -139,7 +138,7 @@ function usePagePathnameSlice(pageId) {
139
138
  function useTable(tableId) {
140
139
  const client = (0, import_host_api_client.useMakeswiftHostApiClient)();
141
140
  const readTable = () => tableId == null ? null : client.readTable(tableId);
142
- const table = (0, import_shim.useSyncExternalStore)(client.subscribe, readTable, readTable);
141
+ const table = (0, import_react.useSyncExternalStore)(client.subscribe, readTable, readTable);
143
142
  (0, import_react.useEffect)(() => {
144
143
  if (tableId != null)
145
144
  client.fetchTable(tableId).catch(console.error);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/makeswift-api.ts"],"sourcesContent":["'use client'\n\nimport { useEffect, useRef } from 'react'\nimport { useSyncExternalStore } from 'use-sync-external-store/shim'\nimport {\n File,\n GlobalElement,\n LocalizedGlobalElement,\n PagePathnameSlice,\n Swatch,\n Table,\n Typography,\n} from '../../../api'\n\nimport { useMakeswiftHostApiClient } from '../host-api-client'\nimport { useDocumentLocale } from './use-document-context'\n\nexport function useSwatch(swatchId: string | null): Swatch | null {\n const client = useMakeswiftHostApiClient()\n const readSwatch = () => (swatchId == null ? null : client.readSwatch(swatchId))\n const swatch = useSyncExternalStore(client.subscribe, readSwatch, readSwatch)\n\n useEffect(() => {\n if (swatchId != null) client.fetchSwatch(swatchId).catch(console.error)\n }, [client, swatchId])\n\n return swatch\n}\n\nexport function useSwatches(swatchIds: string[]): (Swatch | null)[] {\n const client = useMakeswiftHostApiClient()\n const lastSnapshot = useRef<(Swatch | null)[]>()\n\n function getSnapshot() {\n const swatches = swatchIds.map(swatchId => client.readSwatch(swatchId))\n\n if (\n lastSnapshot.current != null &&\n lastSnapshot.current.length === swatches.length &&\n lastSnapshot.current.every((swatch, idx) => swatches[idx] === swatch)\n ) {\n return lastSnapshot.current\n }\n\n return (lastSnapshot.current = swatches)\n }\n\n const swatches = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot)\n\n useEffect(() => {\n Promise.all(swatchIds.map(swatchId => client.fetchSwatch(swatchId))).catch(console.error)\n }, [client, swatchIds])\n\n return swatches\n}\n\nexport function useFile(fileId: string | null): File | null {\n const client = useMakeswiftHostApiClient()\n const readFile = () => (fileId == null ? null : client.readFile(fileId))\n const file = useSyncExternalStore(client.subscribe, readFile, readFile)\n\n useEffect(() => {\n if (fileId != null) client.fetchFile(fileId)\n }, [client, fileId])\n\n return file\n}\n\nexport function useFiles(fileIds: string[]): (File | null)[] {\n const client = useMakeswiftHostApiClient()\n const lastSnapshot = useRef<(File | null)[]>()\n\n function getSnapshot() {\n const files = fileIds.map(fileId => client.readFile(fileId))\n\n if (\n lastSnapshot.current != null &&\n lastSnapshot.current.length === files.length &&\n lastSnapshot.current.every((file, idx) => files[idx] === file)\n ) {\n return lastSnapshot.current\n }\n\n return (lastSnapshot.current = files)\n }\n\n const files = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot)\n\n useEffect(() => {\n Promise.all(fileIds.map(fileId => client.fetchFile(fileId))).catch(console.error)\n }, [client, fileIds])\n\n return files\n}\n\nexport function useTypography(typographyId: string | null): Typography | null {\n const client = useMakeswiftHostApiClient()\n const readTypography = () => (typographyId == null ? null : client.readTypography(typographyId))\n const typography = useSyncExternalStore(client.subscribe, readTypography, readTypography)\n\n useEffect(() => {\n if (typographyId != null) client.fetchTypography(typographyId).catch(console.error)\n }, [client, typographyId])\n\n return typography\n}\n\nexport function useGlobalElement(globalElementId: string | null): GlobalElement | null {\n const client = useMakeswiftHostApiClient()\n const readGlobalElement = () =>\n globalElementId == null ? null : client.readGlobalElement(globalElementId)\n const globalElement = useSyncExternalStore(client.subscribe, readGlobalElement, readGlobalElement)\n\n useEffect(() => {\n if (globalElementId != null) client.fetchGlobalElement(globalElementId).catch(console.error)\n }, [client, globalElementId])\n\n return globalElement\n}\n\nexport function useLocalizedGlobalElement(\n locale: string | null,\n globalElementId: string | null,\n): LocalizedGlobalElement | null {\n const client = useMakeswiftHostApiClient()\n const readLocalizedGlobalElement = () =>\n locale == null || globalElementId == null\n ? null\n : client.readLocalizedGlobalElement({ globalElementId, locale })\n\n const localizedGlobalElement = useSyncExternalStore(\n client.subscribe,\n readLocalizedGlobalElement,\n readLocalizedGlobalElement,\n )\n\n useEffect(() => {\n if (locale != null && globalElementId != null) {\n client.fetchLocalizedGlobalElement({ globalElementId, locale }).catch(console.error)\n }\n }, [client, locale, globalElementId])\n\n return localizedGlobalElement\n}\n\nexport function usePagePathnameSlice(pageId: string | null): PagePathnameSlice | null {\n const client = useMakeswiftHostApiClient()\n const locale = useDocumentLocale()\n\n const readPagePathnameSlice = () =>\n pageId == null ? null : client.readPagePathnameSlice({ pageId, locale })\n\n const pagePathnameSlice = useSyncExternalStore(\n client.subscribe,\n readPagePathnameSlice,\n readPagePathnameSlice,\n )\n\n useEffect(() => {\n if (pageId != null) client.fetchPagePathnameSlice({ pageId, locale }).catch(console.error)\n }, [client, pageId, locale])\n\n return pagePathnameSlice\n}\n\nexport function useTable(tableId: string | null): Table | null {\n const client = useMakeswiftHostApiClient()\n const readTable = () => (tableId == null ? null : client.readTable(tableId))\n const table = useSyncExternalStore(client.subscribe, readTable, readTable)\n\n useEffect(() => {\n if (tableId != null) client.fetchTable(tableId).catch(console.error)\n }, [client, tableId])\n\n return table\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAkC;AAClC,kBAAqC;AAWrC,6BAA0C;AAC1C,kCAAkC;AAE3B,SAAS,UAAU,UAAwC;AAChE,QAAM,aAAS,kDAA0B;AACzC,QAAM,aAAa,MAAO,YAAY,OAAO,OAAO,OAAO,WAAW,QAAQ;AAC9E,QAAM,aAAS,kCAAqB,OAAO,WAAW,YAAY,UAAU;AAE5E,8BAAU,MAAM;AACd,QAAI,YAAY;AAAM,aAAO,YAAY,QAAQ,EAAE,MAAM,QAAQ,KAAK;AAAA,EACxE,GAAG,CAAC,QAAQ,QAAQ,CAAC;AAErB,SAAO;AACT;AAEO,SAAS,YAAY,WAAwC;AAClE,QAAM,aAAS,kDAA0B;AACzC,QAAM,mBAAe,qBAA0B;AAE/C,WAAS,cAAc;AACrB,UAAMA,YAAW,UAAU,IAAI,cAAY,OAAO,WAAW,QAAQ,CAAC;AAEtE,QACE,aAAa,WAAW,QACxB,aAAa,QAAQ,WAAWA,UAAS,UACzC,aAAa,QAAQ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AO,sBAAsB,EAAE,QAAQ,OAAO,CAAC;AAEzE,QAAM,wBAAoB;AAAA,IACxB,OAAO;AAAA,IACP;AAAA,IACA;AAAA,EACF;AAEA,8BAAU,MAAM;AACd,QAAI,UAAU;AAAM,aAAO,uBAAuB,EAAE,QAAQ,OAAO,CAAC,EAAE,MAAM,QAAQ,KAAK;AAAA,EAC3F,GAAG,CAAC,QAAQ,QAAQ,MAAM,CAAC;AAE3B,SAAO;AACT;AAEO,SAAS,SAAS,SAAsC;AAC7D,QAAM,aAAS,kDAA0B;AACzC,QAAM,YAAY,MAAO,WAAW,OAAO,OAAO,OAAO,UAAU,OAAO;AAC1E,QAAM,YAAQ,kCAAqB,OAAO,WAAW,WAAW,SAAS;AAEzE,8BAAU,MAAM;AACd,QAAI,WAAW;AAAM,aAAO,WAAW,OAAO,EAAE,MAAM,QAAQ,KAAK;AAAA,EACrE,GAAG,CAAC,QAAQ,OAAO,CAAC;AAEpB,SAAO;AACT;","names":["swatches","files"]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/makeswift-api.ts"],"sourcesContent":["'use client'\n\nimport { useEffect, useRef, useSyncExternalStore } from 'react'\nimport {\n File,\n GlobalElement,\n LocalizedGlobalElement,\n PagePathnameSlice,\n Swatch,\n Table,\n Typography,\n} from '../../../api'\n\nimport { useMakeswiftHostApiClient } from '../host-api-client'\nimport { useDocumentLocale } from './use-document-context'\n\nexport function useSwatch(swatchId: string | null): Swatch | null {\n const client = useMakeswiftHostApiClient()\n const readSwatch = () => (swatchId == null ? null : client.readSwatch(swatchId))\n const swatch = useSyncExternalStore(client.subscribe, readSwatch, readSwatch)\n\n useEffect(() => {\n if (swatchId != null) client.fetchSwatch(swatchId).catch(console.error)\n }, [client, swatchId])\n\n return swatch\n}\n\nexport function useSwatches(swatchIds: string[]): (Swatch | null)[] {\n const client = useMakeswiftHostApiClient()\n const lastSnapshot = useRef<(Swatch | null)[]>()\n\n function getSnapshot() {\n const swatches = swatchIds.map(swatchId => client.readSwatch(swatchId))\n\n if (\n lastSnapshot.current != null &&\n lastSnapshot.current.length === swatches.length &&\n lastSnapshot.current.every((swatch, idx) => swatches[idx] === swatch)\n ) {\n return lastSnapshot.current\n }\n\n return (lastSnapshot.current = swatches)\n }\n\n const swatches = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot)\n\n useEffect(() => {\n Promise.all(swatchIds.map(swatchId => client.fetchSwatch(swatchId))).catch(console.error)\n }, [client, swatchIds])\n\n return swatches\n}\n\nexport function useFile(fileId: string | null): File | null {\n const client = useMakeswiftHostApiClient()\n const readFile = () => (fileId == null ? null : client.readFile(fileId))\n const file = useSyncExternalStore(client.subscribe, readFile, readFile)\n\n useEffect(() => {\n if (fileId != null) client.fetchFile(fileId)\n }, [client, fileId])\n\n return file\n}\n\nexport function useFiles(fileIds: string[]): (File | null)[] {\n const client = useMakeswiftHostApiClient()\n const lastSnapshot = useRef<(File | null)[]>()\n\n function getSnapshot() {\n const files = fileIds.map(fileId => client.readFile(fileId))\n\n if (\n lastSnapshot.current != null &&\n lastSnapshot.current.length === files.length &&\n lastSnapshot.current.every((file, idx) => files[idx] === file)\n ) {\n return lastSnapshot.current\n }\n\n return (lastSnapshot.current = files)\n }\n\n const files = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot)\n\n useEffect(() => {\n Promise.all(fileIds.map(fileId => client.fetchFile(fileId))).catch(console.error)\n }, [client, fileIds])\n\n return files\n}\n\nexport function useTypography(typographyId: string | null): Typography | null {\n const client = useMakeswiftHostApiClient()\n const readTypography = () => (typographyId == null ? null : client.readTypography(typographyId))\n const typography = useSyncExternalStore(client.subscribe, readTypography, readTypography)\n\n useEffect(() => {\n if (typographyId != null) client.fetchTypography(typographyId).catch(console.error)\n }, [client, typographyId])\n\n return typography\n}\n\nexport function useGlobalElement(globalElementId: string | null): GlobalElement | null {\n const client = useMakeswiftHostApiClient()\n const readGlobalElement = () =>\n globalElementId == null ? null : client.readGlobalElement(globalElementId)\n const globalElement = useSyncExternalStore(client.subscribe, readGlobalElement, readGlobalElement)\n\n useEffect(() => {\n if (globalElementId != null) client.fetchGlobalElement(globalElementId).catch(console.error)\n }, [client, globalElementId])\n\n return globalElement\n}\n\nexport function useLocalizedGlobalElement(\n locale: string | null,\n globalElementId: string | null,\n): LocalizedGlobalElement | null {\n const client = useMakeswiftHostApiClient()\n const readLocalizedGlobalElement = () =>\n locale == null || globalElementId == null\n ? null\n : client.readLocalizedGlobalElement({ globalElementId, locale })\n\n const localizedGlobalElement = useSyncExternalStore(\n client.subscribe,\n readLocalizedGlobalElement,\n readLocalizedGlobalElement,\n )\n\n useEffect(() => {\n if (locale != null && globalElementId != null) {\n client.fetchLocalizedGlobalElement({ globalElementId, locale }).catch(console.error)\n }\n }, [client, locale, globalElementId])\n\n return localizedGlobalElement\n}\n\nexport function usePagePathnameSlice(pageId: string | null): PagePathnameSlice | null {\n const client = useMakeswiftHostApiClient()\n const locale = useDocumentLocale()\n\n const readPagePathnameSlice = () =>\n pageId == null ? null : client.readPagePathnameSlice({ pageId, locale })\n\n const pagePathnameSlice = useSyncExternalStore(\n client.subscribe,\n readPagePathnameSlice,\n readPagePathnameSlice,\n )\n\n useEffect(() => {\n if (pageId != null) client.fetchPagePathnameSlice({ pageId, locale }).catch(console.error)\n }, [client, pageId, locale])\n\n return pagePathnameSlice\n}\n\nexport function useTable(tableId: string | null): Table | null {\n const client = useMakeswiftHostApiClient()\n const readTable = () => (tableId == null ? null : client.readTable(tableId))\n const table = useSyncExternalStore(client.subscribe, readTable, readTable)\n\n useEffect(() => {\n if (tableId != null) client.fetchTable(tableId).catch(console.error)\n }, [client, tableId])\n\n return table\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAwD;AAWxD,6BAA0C;AAC1C,kCAAkC;AAE3B,SAAS,UAAU,UAAwC;AAChE,QAAM,aAAS,kDAA0B;A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6B,MACjC,UAAU,QAAQ,mBAAmB,OACjC,OACA,OAAO,2BAA2B,EAAE,iBAAiB,OAAO,CAAC;AAEnE,QAAM,6BAAyB;AAAA,IAC7B,OAAO;AAAA,IACP;AAAA,IACA;AAAA,EACF;AAEA,8BAAU,MAAM;AACd,QAAI,UAAU,QAAQ,mBAAmB,MAAM;AAC7C,aAAO,4BAA4B,EAAE,iBAAiB,OAAO,CAAC,EAAE,MAAM,QAAQ,KAAK;AAAA,IACrF;AAAA,EACF,GAAG,CAAC,QAAQ,QAAQ,eAAe,CAAC;AAEpC,SAAO;AACT;AAEO,SAAS,qBAAqB,QAAiD;AACpF,QAAM,aAAS,kDAA0B;AACzC,QAAM,aAAS,+CAAkB;AAEjC,QAAM,wBAAwB,MAC5B,UAAU,OAAO,OAAO,OAAO,sBAAsB,EAAE,QAAQ,OAAO,CAAC;AAEzE,QAAM,wBAAoB;AAAA,IACxB,OAAO;AAAA,IACP;AAAA,IACA;AAAA,EACF;AAEA,8BAAU,MAAM;AACd,QAAI,UAAU;AAAM,aAAO,uBAAuB,EAAE,QAAQ,OAAO,CAAC,EAAE,MAAM,QAAQ,KAAK;AAAA,EAC3F,GAAG,CAAC,QAAQ,QAAQ,MAAM,CAAC;AAE3B,SAAO;AACT;AAEO,SAAS,SAAS,SAAsC;AAC7D,QAAM,aAAS,kDAA0B;AACzC,QAAM,YAAY,MAAO,WAAW,OAAO,OAAO,OAAO,UAAU,OAAO;AAC1E,QAAM,YAAQ,mCAAqB,OAAO,WAAW,WAAW,SAAS;AAEzE,8BAAU,MAAM;AACd,QAAI,WAAW;AAAM,aAAO,WAAW,OAAO,EAAE,MAAM,QAAQ,KAAK;AAAA,EACrE,GAAG,CAAC,QAAQ,OAAO,CAAC;AAEpB,SAAO;AACT;","names":["swatches","files"]}
@@ -21,7 +21,7 @@ __export(use_selector_exports, {
21
21
  useSelector: () => useSelector
22
22
  });
23
23
  module.exports = __toCommonJS(use_selector_exports);
24
- var import_with_selector = require("use-sync-external-store/shim/with-selector");
24
+ var import_with_selector = require("use-sync-external-store/with-selector");
25
25
  var import_use_store = require("./use-store");
26
26
  function useSelector(selector) {
27
27
  const store = (0, import_use_store.useStore)();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-selector.ts"],"sourcesContent":["import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\nimport { useStore } from './use-store'\nimport { State as ReactPageState } from '../../../state/react-page'\nimport { State as ReactBuilderPreviewState } from '../../../state/react-builder-preview'\n\ntype State = ReactPageState | ReactBuilderPreviewState\n\nexport function useSelector<R>(selector: (state: State) => R): R {\n const store = useStore()\n\n return useSyncExternalStoreWithSelector(store.subscribe, store.getState, store.getState, selector)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAiD;AACjD,uBAAyB;AAMlB,SAAS,YAAe,UAAkC;AAC/D,QAAM,YAAQ,2BAAS;AAEvB,aAAO,uDAAiC,MAAM,WAAW,MAAM,UAAU,MAAM,UAAU,QAAQ;AACnG;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-selector.ts"],"sourcesContent":["import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector'\n\nimport { useStore } from './use-store'\nimport { State as ReactPageState } from '../../../state/react-page'\nimport { State as ReactBuilderPreviewState } from '../../../state/react-builder-preview'\n\ntype State = ReactPageState | ReactBuilderPreviewState\n\nexport function useSelector<R>(selector: (state: State) => R): R {\n const store = useStore()\n\n return useSyncExternalStoreWithSelector(store.subscribe, store.getState, store.getState, selector)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAiD;AAEjD,uBAAyB;AAMlB,SAAS,YAAe,UAAkC;AAC/D,QAAM,YAAQ,2BAAS;AAEvB,aAAO,uDAAiC,MAAM,WAAW,MAAM,UAAU,MAAM,UAAU,QAAQ;AACnG;","names":[]}