@makeswift/runtime 0.26.4-canary.0 → 0.27.0-canary.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/dist/cjs/api/client.js +2 -4
  2. package/dist/cjs/api/client.js.map +1 -1
  3. package/dist/cjs/api-handler/handlers/manifest.js +1 -1
  4. package/dist/cjs/api-handler/index.js +1 -2
  5. package/dist/cjs/api-handler/index.js.map +1 -1
  6. package/dist/cjs/client/index.js +8 -13
  7. package/dist/cjs/client/index.js.map +1 -1
  8. package/dist/cjs/next/api-handler/index.js +2 -2
  9. package/dist/cjs/next/api-handler/index.js.map +1 -1
  10. package/dist/cjs/next/components/framework-provider/index.js +1 -3
  11. package/dist/cjs/next/components/framework-provider/index.js.map +1 -1
  12. package/dist/cjs/next/components/tests/controls/style-control/fixtures.js.map +1 -1
  13. package/dist/cjs/next/index.js +3 -0
  14. package/dist/cjs/next/index.js.map +1 -1
  15. package/dist/cjs/next/runtime.js +38 -0
  16. package/dist/cjs/next/runtime.js.map +1 -0
  17. package/dist/cjs/next/tests/test-utils.js +3 -6
  18. package/dist/cjs/next/tests/test-utils.js.map +1 -1
  19. package/dist/cjs/react/index.js +0 -3
  20. package/dist/cjs/react/index.js.map +1 -1
  21. package/dist/cjs/runtimes/react/components/RuntimeProvider.js +13 -32
  22. package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
  23. package/dist/cjs/runtimes/react/components/framework-context.js +3 -14
  24. package/dist/cjs/runtimes/react/components/framework-context.js.map +1 -1
  25. package/dist/cjs/runtimes/react/hooks/use-async-effect.js +55 -0
  26. package/dist/cjs/runtimes/react/hooks/use-async-effect.js.map +1 -0
  27. package/dist/cjs/runtimes/react/hooks/use-store.js +2 -9
  28. package/dist/cjs/runtimes/react/hooks/use-store.js.map +1 -1
  29. package/dist/cjs/runtimes/react/host-api-client.js +2 -24
  30. package/dist/cjs/runtimes/react/host-api-client.js.map +1 -1
  31. package/dist/cjs/runtimes/react/index.js +0 -5
  32. package/dist/cjs/runtimes/react/index.js.map +1 -1
  33. package/dist/cjs/runtimes/react/react-runtime-core.js +0 -3
  34. package/dist/cjs/runtimes/react/react-runtime-core.js.map +1 -1
  35. package/dist/cjs/runtimes/react/react-runtime.js +2 -2
  36. package/dist/cjs/runtimes/react/react-runtime.js.map +1 -1
  37. package/dist/cjs/runtimes/react/runtime-core.js +42 -3
  38. package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
  39. package/dist/cjs/runtimes/react/testing/react-runtime.js +2 -1
  40. package/dist/cjs/runtimes/react/testing/react-runtime.js.map +1 -1
  41. package/dist/cjs/state/actions/internal/read-only-actions.js +15 -1
  42. package/dist/cjs/state/actions/internal/read-only-actions.js.map +1 -1
  43. package/dist/cjs/state/makeswift-api-client.js +32 -18
  44. package/dist/cjs/state/makeswift-api-client.js.map +1 -1
  45. package/dist/cjs/state/middleware/{read-write/makeswift-api-client-sync.js → makeswift-api-client-sync.js} +1 -1
  46. package/dist/cjs/state/middleware/makeswift-api-client-sync.js.map +1 -0
  47. package/dist/cjs/state/middleware/read-write/index.js +40 -0
  48. package/dist/cjs/state/middleware/read-write/index.js.map +1 -0
  49. package/dist/cjs/state/middleware/{prop-controller-handles.js → read-write/prop-controller-handles.js} +8 -8
  50. package/dist/cjs/state/middleware/read-write/prop-controller-handles.js.map +1 -0
  51. package/dist/cjs/state/modules/locale.js +53 -0
  52. package/dist/cjs/state/modules/locale.js.map +1 -0
  53. package/dist/cjs/state/modules/site-version.js +50 -0
  54. package/dist/cjs/state/modules/site-version.js.map +1 -0
  55. package/dist/cjs/state/read-only-state.js +2 -0
  56. package/dist/cjs/state/read-only-state.js.map +1 -1
  57. package/dist/cjs/state/read-write-state.js +9 -2
  58. package/dist/cjs/state/read-write-state.js.map +1 -1
  59. package/dist/cjs/state/store.js +184 -0
  60. package/dist/cjs/state/store.js.map +1 -0
  61. package/dist/cjs/state/unified-state.js +17 -0
  62. package/dist/cjs/state/unified-state.js.map +1 -0
  63. package/dist/cjs/unstable-framework-support/index.js +2 -4
  64. package/dist/cjs/unstable-framework-support/index.js.map +1 -1
  65. package/dist/cjs/{state/mixins/setup-teardown.js → utils/deferred.js} +15 -11
  66. package/dist/cjs/utils/deferred.js.map +1 -0
  67. package/dist/esm/api/client.js +2 -4
  68. package/dist/esm/api/client.js.map +1 -1
  69. package/dist/esm/api-handler/handlers/manifest.js +1 -1
  70. package/dist/esm/api-handler/index.js +1 -2
  71. package/dist/esm/api-handler/index.js.map +1 -1
  72. package/dist/esm/client/index.js +8 -13
  73. package/dist/esm/client/index.js.map +1 -1
  74. package/dist/esm/next/api-handler/index.js +2 -2
  75. package/dist/esm/next/api-handler/index.js.map +1 -1
  76. package/dist/esm/next/components/framework-provider/index.js +2 -7
  77. package/dist/esm/next/components/framework-provider/index.js.map +1 -1
  78. package/dist/esm/next/components/tests/controls/style-control/fixtures.js.map +1 -1
  79. package/dist/esm/next/index.js +2 -0
  80. package/dist/esm/next/index.js.map +1 -1
  81. package/dist/esm/next/runtime.js +14 -0
  82. package/dist/esm/next/runtime.js.map +1 -0
  83. package/dist/esm/next/tests/test-utils.js +3 -6
  84. package/dist/esm/next/tests/test-utils.js.map +1 -1
  85. package/dist/esm/react/index.js +0 -2
  86. package/dist/esm/react/index.js.map +1 -1
  87. package/dist/esm/runtimes/react/components/RuntimeProvider.js +14 -23
  88. package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
  89. package/dist/esm/runtimes/react/components/framework-context.js +2 -15
  90. package/dist/esm/runtimes/react/components/framework-context.js.map +1 -1
  91. package/dist/esm/runtimes/react/hooks/use-async-effect.js +31 -0
  92. package/dist/esm/runtimes/react/hooks/use-async-effect.js.map +1 -0
  93. package/dist/esm/runtimes/react/hooks/use-store.js +2 -8
  94. package/dist/esm/runtimes/react/hooks/use-store.js.map +1 -1
  95. package/dist/esm/runtimes/react/host-api-client.js +2 -23
  96. package/dist/esm/runtimes/react/host-api-client.js.map +1 -1
  97. package/dist/esm/runtimes/react/index.js +1 -4
  98. package/dist/esm/runtimes/react/index.js.map +1 -1
  99. package/dist/esm/runtimes/react/react-runtime-core.js +0 -3
  100. package/dist/esm/runtimes/react/react-runtime-core.js.map +1 -1
  101. package/dist/esm/runtimes/react/react-runtime.js +2 -2
  102. package/dist/esm/runtimes/react/react-runtime.js.map +1 -1
  103. package/dist/esm/runtimes/react/runtime-core.js +45 -2
  104. package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
  105. package/dist/esm/runtimes/react/testing/react-runtime.js +2 -1
  106. package/dist/esm/runtimes/react/testing/react-runtime.js.map +1 -1
  107. package/dist/esm/state/actions/internal/read-only-actions.js +13 -1
  108. package/dist/esm/state/actions/internal/read-only-actions.js.map +1 -1
  109. package/dist/esm/state/makeswift-api-client.js +32 -18
  110. package/dist/esm/state/makeswift-api-client.js.map +1 -1
  111. package/dist/esm/state/middleware/{read-write/makeswift-api-client-sync.js → makeswift-api-client-sync.js} +1 -1
  112. package/dist/esm/state/middleware/makeswift-api-client-sync.js.map +1 -0
  113. package/dist/esm/state/middleware/read-write/index.js +16 -0
  114. package/dist/esm/state/middleware/read-write/index.js.map +1 -0
  115. package/dist/esm/state/middleware/{prop-controller-handles.js → read-write/prop-controller-handles.js} +8 -8
  116. package/dist/esm/state/middleware/read-write/prop-controller-handles.js.map +1 -0
  117. package/dist/esm/state/modules/locale.js +27 -0
  118. package/dist/esm/state/modules/locale.js.map +1 -0
  119. package/dist/esm/state/modules/site-version.js +24 -0
  120. package/dist/esm/state/modules/site-version.js.map +1 -0
  121. package/dist/esm/state/read-only-state.js +2 -0
  122. package/dist/esm/state/read-only-state.js.map +1 -1
  123. package/dist/esm/state/read-write-state.js +7 -1
  124. package/dist/esm/state/read-write-state.js.map +1 -1
  125. package/dist/esm/state/store.js +153 -0
  126. package/dist/esm/state/store.js.map +1 -0
  127. package/dist/esm/state/unified-state.js +1 -0
  128. package/dist/esm/state/unified-state.js.map +1 -0
  129. package/dist/esm/unstable-framework-support/index.js +2 -4
  130. package/dist/esm/unstable-framework-support/index.js.map +1 -1
  131. package/dist/esm/utils/deferred.js +15 -0
  132. package/dist/esm/utils/deferred.js.map +1 -0
  133. package/dist/types/api/client.d.ts +1 -2
  134. package/dist/types/api/client.d.ts.map +1 -1
  135. package/dist/types/api-handler/handlers/webhook/types.d.ts +4 -4
  136. package/dist/types/api-handler/index.d.ts +1 -3
  137. package/dist/types/api-handler/index.d.ts.map +1 -1
  138. package/dist/types/client/index.d.ts +10 -11
  139. package/dist/types/client/index.d.ts.map +1 -1
  140. package/dist/types/components/hooks/useIsomorphicLayoutEffect.d.ts +2 -2
  141. package/dist/types/components/hooks/useIsomorphicLayoutEffect.d.ts.map +1 -1
  142. package/dist/types/next/api-handler/index.d.ts +1 -1
  143. package/dist/types/next/api-handler/index.d.ts.map +1 -1
  144. package/dist/types/next/components/framework-provider/index.d.ts.map +1 -1
  145. package/dist/types/next/components/tests/controls/style-control/fixtures.d.ts +1 -1
  146. package/dist/types/next/components/tests/controls/style-control/fixtures.d.ts.map +1 -1
  147. package/dist/types/next/index.d.ts +1 -0
  148. package/dist/types/next/index.d.ts.map +1 -1
  149. package/dist/types/next/runtime.d.ts +10 -0
  150. package/dist/types/next/runtime.d.ts.map +1 -0
  151. package/dist/types/next/tests/test-utils.d.ts.map +1 -1
  152. package/dist/types/react/index.d.ts +0 -1
  153. package/dist/types/react/index.d.ts.map +1 -1
  154. package/dist/types/runtimes/react/components/RuntimeProvider.d.ts +2 -4
  155. package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
  156. package/dist/types/runtimes/react/components/framework-context.d.ts +0 -4
  157. package/dist/types/runtimes/react/components/framework-context.d.ts.map +1 -1
  158. package/dist/types/runtimes/react/hooks/__tests__/use-async-effect.test.d.ts +2 -0
  159. package/dist/types/runtimes/react/hooks/__tests__/use-async-effect.test.d.ts.map +1 -0
  160. package/dist/types/runtimes/react/hooks/use-async-effect.d.ts +3 -0
  161. package/dist/types/runtimes/react/hooks/use-async-effect.d.ts.map +1 -0
  162. package/dist/types/runtimes/react/hooks/use-store.d.ts +1 -26
  163. package/dist/types/runtimes/react/hooks/use-store.d.ts.map +1 -1
  164. package/dist/types/runtimes/react/host-api-client.d.ts +0 -5
  165. package/dist/types/runtimes/react/host-api-client.d.ts.map +1 -1
  166. package/dist/types/runtimes/react/index.d.ts +1 -2
  167. package/dist/types/runtimes/react/index.d.ts.map +1 -1
  168. package/dist/types/runtimes/react/react-runtime-core.d.ts +0 -4
  169. package/dist/types/runtimes/react/react-runtime-core.d.ts.map +1 -1
  170. package/dist/types/runtimes/react/react-runtime.d.ts +1 -4
  171. package/dist/types/runtimes/react/react-runtime.d.ts.map +1 -1
  172. package/dist/types/runtimes/react/runtime-core.d.ts +20 -3
  173. package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
  174. package/dist/types/runtimes/react/testing/react-runtime.d.ts.map +1 -1
  175. package/dist/types/state/__tests__/store.read-write-state.test.d.ts +2 -0
  176. package/dist/types/state/__tests__/store.read-write-state.test.d.ts.map +1 -0
  177. package/dist/types/state/__tests__/test-store.d.ts +29 -0
  178. package/dist/types/state/__tests__/test-store.d.ts.map +1 -0
  179. package/dist/types/state/actions/index.d.ts +2 -0
  180. package/dist/types/state/actions/index.d.ts.map +1 -1
  181. package/dist/types/state/actions/internal/index.d.ts +2 -0
  182. package/dist/types/state/actions/internal/index.d.ts.map +1 -1
  183. package/dist/types/state/actions/internal/read-only-actions.d.ts +13 -1
  184. package/dist/types/state/actions/internal/read-only-actions.d.ts.map +1 -1
  185. package/dist/types/state/makeswift-api-client.d.ts +11 -2
  186. package/dist/types/state/makeswift-api-client.d.ts.map +1 -1
  187. package/dist/types/state/middleware/makeswift-api-client-sync.d.ts +5 -0
  188. package/dist/types/state/middleware/makeswift-api-client-sync.d.ts.map +1 -0
  189. package/dist/types/state/middleware/read-write/index.d.ts +5 -0
  190. package/dist/types/state/middleware/read-write/index.d.ts.map +1 -0
  191. package/dist/types/state/middleware/{prop-controller-handles.d.ts → read-write/prop-controller-handles.d.ts} +1 -1
  192. package/dist/types/state/middleware/read-write/prop-controller-handles.d.ts.map +1 -0
  193. package/dist/types/state/modules/locale.d.ts +6 -0
  194. package/dist/types/state/modules/locale.d.ts.map +1 -0
  195. package/dist/types/state/modules/site-version.d.ts +7 -0
  196. package/dist/types/state/modules/site-version.d.ts.map +1 -0
  197. package/dist/types/state/read-only-state.d.ts +3 -0
  198. package/dist/types/state/read-only-state.d.ts.map +1 -1
  199. package/dist/types/state/read-write-state.d.ts +5 -1
  200. package/dist/types/state/read-write-state.d.ts.map +1 -1
  201. package/dist/types/state/{react-page.d.ts → store.d.ts} +25 -6
  202. package/dist/types/state/store.d.ts.map +1 -0
  203. package/dist/types/state/unified-state.d.ts +9 -0
  204. package/dist/types/state/unified-state.d.ts.map +1 -0
  205. package/dist/types/unstable-framework-support/index.d.ts +2 -1
  206. package/dist/types/unstable-framework-support/index.d.ts.map +1 -1
  207. package/dist/types/utils/deferred.d.ts +7 -0
  208. package/dist/types/utils/deferred.d.ts.map +1 -0
  209. package/package.json +2 -2
  210. package/dist/cjs/runtimes/react/components/LiveProvider.js +0 -50
  211. package/dist/cjs/runtimes/react/components/LiveProvider.js.map +0 -1
  212. package/dist/cjs/runtimes/react/components/PreviewProvider.js +0 -63
  213. package/dist/cjs/runtimes/react/components/PreviewProvider.js.map +0 -1
  214. package/dist/cjs/state/middleware/prop-controller-handles.js.map +0 -1
  215. package/dist/cjs/state/middleware/read-write/makeswift-api-client-sync.js.map +0 -1
  216. package/dist/cjs/state/mixins/setup-teardown.js.map +0 -1
  217. package/dist/cjs/state/react-builder-preview.js +0 -96
  218. package/dist/cjs/state/react-builder-preview.js.map +0 -1
  219. package/dist/cjs/state/react-page.js +0 -69
  220. package/dist/cjs/state/react-page.js.map +0 -1
  221. package/dist/esm/runtimes/react/components/LiveProvider.js +0 -20
  222. package/dist/esm/runtimes/react/components/LiveProvider.js.map +0 -1
  223. package/dist/esm/runtimes/react/components/PreviewProvider.js +0 -33
  224. package/dist/esm/runtimes/react/components/PreviewProvider.js.map +0 -1
  225. package/dist/esm/state/middleware/prop-controller-handles.js.map +0 -1
  226. package/dist/esm/state/middleware/read-write/makeswift-api-client-sync.js.map +0 -1
  227. package/dist/esm/state/mixins/setup-teardown.js +0 -11
  228. package/dist/esm/state/mixins/setup-teardown.js.map +0 -1
  229. package/dist/esm/state/react-builder-preview.js +0 -62
  230. package/dist/esm/state/react-builder-preview.js.map +0 -1
  231. package/dist/esm/state/react-page.js +0 -35
  232. package/dist/esm/state/react-page.js.map +0 -1
  233. package/dist/types/runtimes/react/components/LiveProvider.d.ts +0 -3
  234. package/dist/types/runtimes/react/components/LiveProvider.d.ts.map +0 -1
  235. package/dist/types/runtimes/react/components/PreviewProvider.d.ts +0 -5
  236. package/dist/types/runtimes/react/components/PreviewProvider.d.ts.map +0 -1
  237. package/dist/types/state/middleware/prop-controller-handles.d.ts.map +0 -1
  238. package/dist/types/state/middleware/read-write/makeswift-api-client-sync.d.ts +0 -5
  239. package/dist/types/state/middleware/read-write/makeswift-api-client-sync.d.ts.map +0 -1
  240. package/dist/types/state/mixins/setup-teardown.d.ts +0 -7
  241. package/dist/types/state/mixins/setup-teardown.d.ts.map +0 -1
  242. package/dist/types/state/react-builder-preview.d.ts +0 -41
  243. package/dist/types/state/react-builder-preview.d.ts.map +0 -1
  244. package/dist/types/state/react-page.d.ts.map +0 -1
@@ -1,15 +1,9 @@
1
1
  "use client";
2
- import { createContext, useContext } from "react";
3
- const StoreContext = createContext(null);
2
+ import { useReactRuntime } from "./use-react-runtime";
4
3
  function useStore() {
5
- const store = useContext(StoreContext);
6
- if (store == null) {
7
- throw new Error("`useStore` must be used within a `StoreProvider`");
8
- }
9
- return store;
4
+ return useReactRuntime().store;
10
5
  }
11
6
  export {
12
- StoreContext,
13
7
  useStore
14
8
  };
15
9
  //# sourceMappingURL=use-store.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-store.ts"],"sourcesContent":["'use client'\n\nimport { createContext, useContext } from 'react'\nimport { type Store } from '../../../state/react-page'\n\nexport const StoreContext = createContext<Store | null>(null)\n\nexport function useStore(): Store {\n const store = useContext(StoreContext)\n if (store == null) {\n throw new Error('`useStore` must be used within a `StoreProvider`')\n }\n\n return store\n}\n"],"mappings":";AAEA,SAAS,eAAe,kBAAkB;AAGnC,MAAM,eAAe,cAA4B,IAAI;AAErD,SAAS,WAAkB;AAChC,QAAM,QAAQ,WAAW,YAAY;AACrC,MAAI,SAAS,MAAM;AACjB,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-store.ts"],"sourcesContent":["'use client'\n\nimport { type Store } from '../../../state/store'\nimport { useReactRuntime } from './use-react-runtime'\n\nexport function useStore(): Store {\n return useReactRuntime().store\n}\n"],"mappings":";AAGA,SAAS,uBAAuB;AAEzB,SAAS,WAAkB;AAChC,SAAO,gBAAgB,EAAE;AAC3B;","names":[]}
@@ -1,30 +1,9 @@
1
1
  "use client";
2
- import { jsx } from "react/jsx-runtime";
3
- import { createContext, useContext } from "react";
4
- import { MakeswiftHostApiClient } from "../../api/client";
5
- const Context = createContext(
6
- new MakeswiftHostApiClient({
7
- uri: "https://api.makeswift.com/graphql",
8
- fetch: async (url, init) => {
9
- console.warn(
10
- "Using fallback `fetch` implementation, resource revalidation may not work as expected.",
11
- { url }
12
- );
13
- return fetch(url, init);
14
- }
15
- })
16
- );
2
+ import { useReactRuntime } from "./hooks/use-react-runtime";
17
3
  function useMakeswiftHostApiClient() {
18
- return useContext(Context);
19
- }
20
- function MakeswiftHostApiClientProvider({
21
- client,
22
- children
23
- }) {
24
- return /* @__PURE__ */ jsx(Context.Provider, { value: client, children });
4
+ return useReactRuntime().hostApiClient;
25
5
  }
26
6
  export {
27
- MakeswiftHostApiClientProvider,
28
7
  useMakeswiftHostApiClient
29
8
  };
30
9
  //# sourceMappingURL=host-api-client.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, createContext, useContext } from 'react'\nimport { MakeswiftHostApiClient } from '../../api/client'\n\nconst Context = createContext(\n new MakeswiftHostApiClient({\n uri: 'https://api.makeswift.com/graphql',\n fetch: async (url, init) => {\n console.warn(\n 'Using fallback `fetch` implementation, resource revalidation may not work as expected.',\n { url },\n )\n return fetch(url, init)\n },\n }),\n)\n\nexport function useMakeswiftHostApiClient(): MakeswiftHostApiClient {\n return useContext(Context)\n}\n\nexport function MakeswiftHostApiClientProvider({\n client,\n children,\n}: {\n client: MakeswiftHostApiClient\n children: ReactNode\n}) {\n return <Context.Provider value={client}>{children}</Context.Provider>\n}\n"],"mappings":";AA6BS;AA3BT,SAAoB,eAAe,kBAAkB;AACrD,SAAS,8BAA8B;AAEvC,MAAM,UAAU;AAAA,EACd,IAAI,uBAAuB;AAAA,IACzB,KAAK;AAAA,IACL,OAAO,OAAO,KAAK,SAAS;AAC1B,cAAQ;AAAA,QACN;AAAA,QACA,EAAE,IAAI;AAAA,MACR;AACA,aAAO,MAAM,KAAK,IAAI;AAAA,IACxB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,4BAAoD;AAClE,SAAO,WAAW,OAAO;AAC3B;AAEO,SAAS,+BAA+B;AAAA,EAC7C;AAAA,EACA;AACF,GAGG;AACD,SAAO,oBAAC,QAAQ,UAAR,EAAiB,OAAO,QAAS,UAAS;AACpD;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\n\nimport { useReactRuntime } from './hooks/use-react-runtime'\n\nexport function useMakeswiftHostApiClient(): MakeswiftHostApiClient {\n return useReactRuntime().hostApiClient\n}\n"],"mappings":";AAIA,SAAS,uBAAuB;AAEzB,SAAS,4BAAoD;AAClE,SAAO,gBAAgB,EAAE;AAC3B;","names":[]}
@@ -1,4 +1,3 @@
1
- import { ReactRuntime } from "./react-runtime";
2
1
  import { Element } from "./components/Element";
3
2
  import { DocumentRoot } from "./components/DocumentRoot";
4
3
  import { RuntimeProvider } from "./components/RuntimeProvider";
@@ -9,13 +8,11 @@ import { useElementId } from "./hooks/use-element-id";
9
8
  import { useIsInBuilder } from "./hooks/use-is-in-builder";
10
9
  import { useIsReadOnly } from "./hooks/use-is-read-only";
11
10
  import { useSelector } from "./hooks/use-selector";
12
- import { StoreContext, useStore } from "./hooks/use-store";
11
+ import { useStore } from "./hooks/use-store";
13
12
  export {
14
13
  DocumentRoot,
15
14
  Element,
16
- ReactRuntime,
17
15
  RuntimeProvider,
18
- StoreContext,
19
16
  useBreakpoints,
20
17
  useBuilderEditMode,
21
18
  useDocumentKey,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/index.ts"],"sourcesContent":["export { ReactRuntime } from './react-runtime'\n\nexport { Element } from './components/Element'\nexport { DocumentRoot } from './components/DocumentRoot'\nexport { RuntimeProvider } from './components/RuntimeProvider'\n\nexport { useBreakpoints } from './hooks/use-breakpoints'\nexport { useBuilderEditMode } from './hooks/use-builder-edit-mode'\nexport { useDocumentKey } from './hooks/use-document-context'\nexport { useElementId } from './hooks/use-element-id'\nexport { useIsInBuilder } from './hooks/use-is-in-builder'\nexport { useIsReadOnly } from './hooks/use-is-read-only'\nexport { useSelector } from './hooks/use-selector'\nexport { StoreContext, useStore } from './hooks/use-store'\n"],"mappings":"AAAA,SAAS,oBAAoB;AAE7B,SAAS,eAAe;AACxB,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAEhC,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AACnC,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,cAAc,gBAAgB;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/index.ts"],"sourcesContent":["export { Element } from './components/Element'\nexport { DocumentRoot } from './components/DocumentRoot'\nexport { RuntimeProvider } from './components/RuntimeProvider'\n\nexport { useBreakpoints } from './hooks/use-breakpoints'\nexport { useBuilderEditMode } from './hooks/use-builder-edit-mode'\nexport { useDocumentKey } from './hooks/use-document-context'\nexport { useElementId } from './hooks/use-element-id'\nexport { useIsInBuilder } from './hooks/use-is-in-builder'\nexport { useIsReadOnly } from './hooks/use-is-read-only'\nexport { useSelector } from './hooks/use-selector'\nexport { useStore } from './hooks/use-store'\n"],"mappings":"AAAA,SAAS,eAAe;AACxB,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAEhC,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AACnC,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;","names":[]}
@@ -44,9 +44,6 @@ class ReactRuntimeCore extends RuntimeCore {
44
44
  unregisterReactComponent();
45
45
  };
46
46
  }
47
- constructor({ breakpoints } = {}) {
48
- super({ breakpoints });
49
- }
50
47
  }
51
48
  export {
52
49
  ReactRuntimeCore
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/react-runtime-core.ts"],"sourcesContent":["import { ControlDefinition as UnifiedControlDefinition } from '@makeswift/controls'\n\nimport { type LegacyDescriptor, type DescriptorValueType } from '../../prop-controllers/descriptors'\n\nimport { supportsActivity } from './components/activity-with-fallback'\n\nimport {\n registerComponentEffect,\n registerReactComponentEffect,\n} from '../../state/actions/internal/read-only-actions'\n\nimport { BreakpointsInput } from '../../state/modules/breakpoints'\nimport { ComponentIcon } from '../../state/modules/components-meta'\nimport type { ComponentType } from '../../state/read-only-state'\n\nimport { RuntimeCore } from './runtime-core'\n\nfunction validateComponentType(type: string, component?: ComponentType): void {\n const componentName = component?.name ?? 'Component'\n if (typeof type !== 'string' || type === '') {\n throw new Error(\n `${componentName}: A non-empty string \\`type\\` is required for component registration, got ${type}`,\n )\n }\n}\n\nexport class ReactRuntimeCore extends RuntimeCore {\n registerComponent<\n ControlDef extends UnifiedControlDefinition,\n P extends Record<string, LegacyDescriptor | ControlDef>,\n C extends ComponentType<{ [K in keyof P]: DescriptorValueType<P[K]> }>,\n >(\n component: C,\n {\n type,\n label,\n icon = ComponentIcon.Cube,\n hidden = false,\n description,\n builtinSuspense,\n props,\n }: {\n type: string\n label: string\n icon?: ComponentIcon\n hidden?: boolean\n description?: string\n /**\n * In React <= 19.1, controls the default `<Suspense>` boundary.\n * Ignored in React >= 19.2; components are always wrapped in `<Activity>`.\n * Defaults to `true`.\n */\n builtinSuspense?: boolean\n props?: P\n },\n ): () => void {\n validateComponentType(type, component as unknown as ComponentType)\n\n const unregisterComponent = this.store.dispatch(\n registerComponentEffect(\n type,\n { label, icon, hidden, description, builtinSuspense },\n props ?? {},\n ),\n )\n\n if (supportsActivity() && builtinSuspense !== undefined) {\n console.warn(\n 'builtinSuspense is ignored in React >= 19.2; components are always wrapped in <Activity>.',\n )\n }\n\n const unregisterReactComponent = this.store.dispatch(\n registerReactComponentEffect(type, component as unknown as ComponentType),\n )\n\n return () => {\n unregisterComponent()\n unregisterReactComponent()\n }\n }\n\n constructor({ breakpoints }: { breakpoints?: BreakpointsInput } = {}) {\n super({ breakpoints })\n }\n}\n"],"mappings":"AAIA,SAAS,wBAAwB;AAEjC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAGP,SAAS,qBAAqB;AAG9B,SAAS,mBAAmB;AAE5B,SAAS,sBAAsB,MAAc,WAAiC;AAC5E,QAAM,gBAAgB,WAAW,QAAQ;AACzC,MAAI,OAAO,SAAS,YAAY,SAAS,IAAI;AAC3C,UAAM,IAAI;AAAA,MACR,GAAG,aAAa,6EAA6E,IAAI;AAAA,IACnG;AAAA,EACF;AACF;AAEO,MAAM,yBAAyB,YAAY;AAAA,EAChD,kBAKE,WACA;AAAA,IACE;AAAA,IACA;AAAA,IACA,OAAO,cAAc;AAAA,IACrB,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAcY;AACZ,0BAAsB,MAAM,SAAqC;AAEjE,UAAM,sBAAsB,KAAK,MAAM;AAAA,MACrC;AAAA,QACE;AAAA,QACA,EAAE,OAAO,MAAM,QAAQ,aAAa,gBAAgB;AAAA,QACpD,SAAS,CAAC;AAAA,MACZ;AAAA,IACF;AAEA,QAAI,iBAAiB,KAAK,oBAAoB,QAAW;AACvD,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,UAAM,2BAA2B,KAAK,MAAM;AAAA,MAC1C,6BAA6B,MAAM,SAAqC;AAAA,IAC1E;AAEA,WAAO,MAAM;AACX,0BAAoB;AACpB,+BAAyB;AAAA,IAC3B;AAAA,EACF;AAAA,EAEA,YAAY,EAAE,YAAY,IAAwC,CAAC,GAAG;AACpE,UAAM,EAAE,YAAY,CAAC;AAAA,EACvB;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/react-runtime-core.ts"],"sourcesContent":["import { ControlDefinition as UnifiedControlDefinition } from '@makeswift/controls'\n\nimport { type LegacyDescriptor, type DescriptorValueType } from '../../prop-controllers/descriptors'\n\nimport { supportsActivity } from './components/activity-with-fallback'\n\nimport {\n registerComponentEffect,\n registerReactComponentEffect,\n} from '../../state/actions/internal/read-only-actions'\n\nimport { ComponentIcon } from '../../state/modules/components-meta'\nimport type { ComponentType } from '../../state/read-only-state'\n\nimport { RuntimeCore } from './runtime-core'\n\nfunction validateComponentType(type: string, component?: ComponentType): void {\n const componentName = component?.name ?? 'Component'\n if (typeof type !== 'string' || type === '') {\n throw new Error(\n `${componentName}: A non-empty string \\`type\\` is required for component registration, got ${type}`,\n )\n }\n}\n\nexport class ReactRuntimeCore extends RuntimeCore {\n registerComponent<\n ControlDef extends UnifiedControlDefinition,\n P extends Record<string, LegacyDescriptor | ControlDef>,\n C extends ComponentType<{ [K in keyof P]: DescriptorValueType<P[K]> }>,\n >(\n component: C,\n {\n type,\n label,\n icon = ComponentIcon.Cube,\n hidden = false,\n description,\n builtinSuspense,\n props,\n }: {\n type: string\n label: string\n icon?: ComponentIcon\n hidden?: boolean\n description?: string\n /**\n * In React <= 19.1, controls the default `<Suspense>` boundary.\n * Ignored in React >= 19.2; components are always wrapped in `<Activity>`.\n * Defaults to `true`.\n */\n builtinSuspense?: boolean\n props?: P\n },\n ): () => void {\n validateComponentType(type, component as unknown as ComponentType)\n\n const unregisterComponent = this.store.dispatch(\n registerComponentEffect(\n type,\n { label, icon, hidden, description, builtinSuspense },\n props ?? {},\n ),\n )\n\n if (supportsActivity() && builtinSuspense !== undefined) {\n console.warn(\n 'builtinSuspense is ignored in React >= 19.2; components are always wrapped in <Activity>.',\n )\n }\n\n const unregisterReactComponent = this.store.dispatch(\n registerReactComponentEffect(type, component as unknown as ComponentType),\n )\n\n return () => {\n unregisterComponent()\n unregisterReactComponent()\n }\n }\n}\n"],"mappings":"AAIA,SAAS,wBAAwB;AAEjC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,qBAAqB;AAG9B,SAAS,mBAAmB;AAE5B,SAAS,sBAAsB,MAAc,WAAiC;AAC5E,QAAM,gBAAgB,WAAW,QAAQ;AACzC,MAAI,OAAO,SAAS,YAAY,SAAS,IAAI;AAC3C,UAAM,IAAI;AAAA,MACR,GAAG,aAAa,6EAA6E,IAAI;AAAA,IACnG;AAAA,EACF;AACF;AAEO,MAAM,yBAAyB,YAAY;AAAA,EAChD,kBAKE,WACA;AAAA,IACE;AAAA,IACA;AAAA,IACA,OAAO,cAAc;AAAA,IACrB,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAcY;AACZ,0BAAsB,MAAM,SAAqC;AAEjE,UAAM,sBAAsB,KAAK,MAAM;AAAA,MACrC;AAAA,QACE;AAAA,QACA,EAAE,OAAO,MAAM,QAAQ,aAAa,gBAAgB;AAAA,QACpD,SAAS,CAAC;AAAA,MACZ;AAAA,IACF;AAEA,QAAI,iBAAiB,KAAK,oBAAoB,QAAW;AACvD,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,UAAM,2BAA2B,KAAK,MAAM;AAAA,MAC1C,6BAA6B,MAAM,SAAqC;AAAA,IAC1E;AAEA,WAAO,MAAM;AACX,0BAAoB;AACpB,+BAAyB;AAAA,IAC3B;AAAA,EACF;AACF;","names":[]}
@@ -1,8 +1,8 @@
1
1
  import { registerBuiltinComponents } from "../../components/builtin/register";
2
2
  import { ReactRuntimeCore } from "./react-runtime-core";
3
3
  class ReactRuntime extends ReactRuntimeCore {
4
- constructor({ breakpoints } = {}) {
5
- super({ breakpoints });
4
+ constructor(...args) {
5
+ super(...args);
6
6
  registerBuiltinComponents(this);
7
7
  }
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/react-runtime.ts"],"sourcesContent":["import { registerBuiltinComponents } from '../../components/builtin/register'\nimport { BreakpointsInput } from '../../state/modules/breakpoints'\nimport { ReactRuntimeCore } from './react-runtime-core'\n\nexport class ReactRuntime extends ReactRuntimeCore {\n constructor({ breakpoints }: { breakpoints?: BreakpointsInput } = {}) {\n super({ breakpoints })\n registerBuiltinComponents(this)\n }\n}\n"],"mappings":"AAAA,SAAS,iCAAiC;AAE1C,SAAS,wBAAwB;AAE1B,MAAM,qBAAqB,iBAAiB;AAAA,EACjD,YAAY,EAAE,YAAY,IAAwC,CAAC,GAAG;AACpE,UAAM,EAAE,YAAY,CAAC;AACrB,8BAA0B,IAAI;AAAA,EAChC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/react-runtime.ts"],"sourcesContent":["import { registerBuiltinComponents } from '../../components/builtin/register'\nimport { ReactRuntimeCore } from './react-runtime-core'\n\nexport class ReactRuntime extends ReactRuntimeCore {\n constructor(...args: ConstructorParameters<typeof ReactRuntimeCore>) {\n super(...args)\n registerBuiltinComponents(this)\n }\n}\n"],"mappings":"AAAA,SAAS,iCAAiC;AAC1C,SAAS,wBAAwB;AAE1B,MAAM,qBAAqB,iBAAiB;AAAA,EACjD,eAAe,MAAsD;AACnE,UAAM,GAAG,IAAI;AACb,8BAA0B,IAAI;AAAA,EAChC;AACF;","names":[]}
@@ -1,18 +1,54 @@
1
+ import { MakeswiftHostApiClient } from "../../api/client";
1
2
  import {
2
3
  parseBreakpointsInput
3
4
  } from "../../state/modules/breakpoints";
4
5
  import { copyElementTree } from "../../state/ops/copy-element-tree";
5
6
  import { getBreakpoints } from "../../state/read-only-state";
6
- import { configureStore } from "../../state/react-page";
7
+ import { configureStore } from "../../state/store";
8
+ import { setLocale } from "../../builder";
9
+ import {
10
+ resetLocaleState,
11
+ setIsReadOnly,
12
+ setSiteVersion
13
+ } from "../../state/actions/internal/read-only-actions";
7
14
  class RuntimeCore {
8
15
  store;
9
- constructor({ breakpoints }) {
16
+ hostApiClient;
17
+ appOrigin;
18
+ apiOrigin;
19
+ constructor({
20
+ appOrigin = "https://app.makeswift.com",
21
+ apiOrigin = "https://api.makeswift.com",
22
+ breakpoints,
23
+ fetch
24
+ }) {
25
+ this.appOrigin = validateOrigin(appOrigin, "appOrigin");
26
+ this.apiOrigin = validateOrigin(apiOrigin, "apiOrigin");
27
+ this.hostApiClient = new MakeswiftHostApiClient({
28
+ uri: new URL("graphql", this.apiOrigin).href,
29
+ fetch
30
+ });
10
31
  this.store = configureStore({
11
32
  name: "Runtime store",
33
+ hostApiClient: this.hostApiClient,
34
+ appOrigin: this.appOrigin,
12
35
  preloadedState: null,
13
36
  breakpoints: breakpoints ? parseBreakpointsInput(breakpoints) : void 0
14
37
  });
15
38
  }
39
+ setIdempotent({
40
+ siteVersion,
41
+ isReadOnly,
42
+ locale
43
+ }) {
44
+ this.store.dispatch(setSiteVersion(siteVersion));
45
+ this.store.dispatch(setIsReadOnly(isReadOnly));
46
+ this.store.dispatch(locale != null ? setLocale(new Intl.Locale(locale)) : resetLocaleState());
47
+ }
48
+ async setupStore({ isReadOnly }) {
49
+ const unloadReadWriteState = await this.store.loadReadWriteState({ isReadOnly });
50
+ return () => unloadReadWriteState();
51
+ }
16
52
  copyElementTree(elementTree, replacementContext) {
17
53
  return copyElementTree(this.store.getState(), elementTree, replacementContext);
18
54
  }
@@ -20,6 +56,13 @@ class RuntimeCore {
20
56
  return getBreakpoints(this.store.getState());
21
57
  }
22
58
  }
59
+ function validateOrigin(url, name) {
60
+ try {
61
+ return new URL(url).origin;
62
+ } catch {
63
+ throw new Error(`The Makeswift runtime received an invalid \`${name}\` parameter: "${url}".`);
64
+ }
65
+ }
23
66
  export {
24
67
  RuntimeCore
25
68
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport {\n Breakpoints,\n BreakpointsInput,\n parseBreakpointsInput,\n} from '../../state/modules/breakpoints'\n\nimport { copyElementTree } from '../../state/ops/copy-element-tree'\n\nimport { getBreakpoints, type Element, type ElementData } from '../../state/read-only-state'\nimport { configureStore, type Store } from '../../state/react-page'\n\nexport class RuntimeCore {\n store: Store\n\n constructor({ breakpoints }: { breakpoints?: BreakpointsInput }) {\n this.store = configureStore({\n name: 'Runtime store',\n preloadedState: null,\n breakpoints: breakpoints ? parseBreakpointsInput(breakpoints) : undefined,\n })\n }\n\n copyElementTree(\n elementTree: ElementData,\n replacementContext: SerializableReplacementContext,\n ): Element {\n return copyElementTree(this.store.getState(), elementTree, replacementContext)\n }\n\n getBreakpoints(): Breakpoints {\n return getBreakpoints(this.store.getState())\n }\n}\n"],"mappings":"AAEA;AAAA,EAGE;AAAA,OACK;AAEP,SAAS,uBAAuB;AAEhC,SAAS,sBAAsD;AAC/D,SAAS,sBAAkC;AAEpC,MAAM,YAAY;AAAA,EACvB;AAAA,EAEA,YAAY,EAAE,YAAY,GAAuC;AAC/D,SAAK,QAAQ,eAAe;AAAA,MAC1B,MAAM;AAAA,MACN,gBAAgB;AAAA,MAChB,aAAa,cAAc,sBAAsB,WAAW,IAAI;AAAA,IAClE,CAAC;AAAA,EACH;AAAA,EAEA,gBACE,aACA,oBACS;AACT,WAAO,gBAAgB,KAAK,MAAM,SAAS,GAAG,aAAa,kBAAkB;AAAA,EAC/E;AAAA,EAEA,iBAA8B;AAC5B,WAAO,eAAe,KAAK,MAAM,SAAS,CAAC;AAAA,EAC7C;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\nimport * as MakeswiftApiClient from '../../state/makeswift-api-client'\nimport { type SiteVersion } from '../../api/site-version'\n\nimport {\n Breakpoints,\n BreakpointsInput,\n parseBreakpointsInput,\n} from '../../state/modules/breakpoints'\n\nimport { copyElementTree } from '../../state/ops/copy-element-tree'\n\nimport { getBreakpoints, type Element, type ElementData } from '../../state/read-only-state'\nimport { configureStore, type Store } from '../../state/store'\nimport { setLocale } from '../../builder'\nimport {\n resetLocaleState,\n setIsReadOnly,\n setSiteVersion,\n} from '../../state/actions/internal/read-only-actions'\n\nexport class RuntimeCore {\n readonly store: Store\n readonly hostApiClient: MakeswiftHostApiClient\n readonly appOrigin: string\n readonly apiOrigin: string\n\n constructor({\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n breakpoints,\n fetch,\n }: {\n appOrigin?: string\n apiOrigin?: string\n breakpoints?: BreakpointsInput\n fetch: MakeswiftApiClient.HttpFetch\n }) {\n this.appOrigin = validateOrigin(appOrigin, 'appOrigin')\n this.apiOrigin = validateOrigin(apiOrigin, 'apiOrigin')\n\n this.hostApiClient = new MakeswiftHostApiClient({\n uri: new URL('graphql', this.apiOrigin).href,\n fetch: fetch,\n })\n\n this.store = configureStore({\n name: 'Runtime store',\n hostApiClient: this.hostApiClient,\n appOrigin: this.appOrigin,\n preloadedState: null,\n breakpoints: breakpoints ? parseBreakpointsInput(breakpoints) : undefined,\n })\n }\n\n setIdempotent({\n siteVersion,\n isReadOnly,\n locale,\n }: {\n siteVersion: SiteVersion | null\n isReadOnly: boolean\n locale: string | undefined\n }): void {\n this.store.dispatch(setSiteVersion(siteVersion))\n this.store.dispatch(setIsReadOnly(isReadOnly))\n this.store.dispatch(locale != null ? setLocale(new Intl.Locale(locale)) : resetLocaleState())\n }\n\n async setupStore({ isReadOnly }: { isReadOnly: boolean }): Promise<() => void> {\n const unloadReadWriteState = await this.store.loadReadWriteState({ isReadOnly })\n return () => unloadReadWriteState()\n }\n\n copyElementTree(\n elementTree: ElementData,\n replacementContext: SerializableReplacementContext,\n ): Element {\n return copyElementTree(this.store.getState(), elementTree, replacementContext)\n }\n\n getBreakpoints(): Breakpoints {\n return getBreakpoints(this.store.getState())\n }\n}\n\nfunction validateOrigin(url: string, name: string): string {\n try {\n return new URL(url).origin\n } catch {\n throw new Error(`The Makeswift runtime received an invalid \\`${name}\\` parameter: \"${url}\".`)\n }\n}\n"],"mappings":"AAEA,SAAS,8BAA8B;AAIvC;AAAA,EAGE;AAAA,OACK;AAEP,SAAS,uBAAuB;AAEhC,SAAS,sBAAsD;AAC/D,SAAS,sBAAkC;AAC3C,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,MAAM,YAAY;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY;AAAA,IACV,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,EACF,GAKG;AACD,SAAK,YAAY,eAAe,WAAW,WAAW;AACtD,SAAK,YAAY,eAAe,WAAW,WAAW;AAEtD,SAAK,gBAAgB,IAAI,uBAAuB;AAAA,MAC9C,KAAK,IAAI,IAAI,WAAW,KAAK,SAAS,EAAE;AAAA,MACxC;AAAA,IACF,CAAC;AAED,SAAK,QAAQ,eAAe;AAAA,MAC1B,MAAM;AAAA,MACN,eAAe,KAAK;AAAA,MACpB,WAAW,KAAK;AAAA,MAChB,gBAAgB;AAAA,MAChB,aAAa,cAAc,sBAAsB,WAAW,IAAI;AAAA,IAClE,CAAC;AAAA,EACH;AAAA,EAEA,cAAc;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAIS;AACP,SAAK,MAAM,SAAS,eAAe,WAAW,CAAC;AAC/C,SAAK,MAAM,SAAS,cAAc,UAAU,CAAC;AAC7C,SAAK,MAAM,SAAS,UAAU,OAAO,UAAU,IAAI,KAAK,OAAO,MAAM,CAAC,IAAI,iBAAiB,CAAC;AAAA,EAC9F;AAAA,EAEA,MAAM,WAAW,EAAE,WAAW,GAAiD;AAC7E,UAAM,uBAAuB,MAAM,KAAK,MAAM,mBAAmB,EAAE,WAAW,CAAC;AAC/E,WAAO,MAAM,qBAAqB;AAAA,EACpC;AAAA,EAEA,gBACE,aACA,oBACS;AACT,WAAO,gBAAgB,KAAK,MAAM,SAAS,GAAG,aAAa,kBAAkB;AAAA,EAC/E;AAAA,EAEA,iBAA8B;AAC5B,WAAO,eAAe,KAAK,MAAM,SAAS,CAAC;AAAA,EAC7C;AACF;AAEA,SAAS,eAAe,KAAa,MAAsB;AACzD,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAQ;AACN,UAAM,IAAI,MAAM,+CAA+C,IAAI,kBAAkB,GAAG,IAAI;AAAA,EAC9F;AACF;","names":[]}
@@ -1,6 +1,7 @@
1
+ import { TestOrigins } from "../../../testing/fixtures";
1
2
  import { ReactRuntime } from "../react-runtime";
2
3
  function createReactRuntime() {
3
- return new ReactRuntime();
4
+ return new ReactRuntime({ fetch, ...TestOrigins });
4
5
  }
5
6
  export {
6
7
  createReactRuntime
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/testing/react-runtime.tsx"],"sourcesContent":["import { ReactRuntime } from '../react-runtime'\n\nexport function createReactRuntime() {\n return new ReactRuntime()\n}\n"],"mappings":"AAAA,SAAS,oBAAoB;AAEtB,SAAS,qBAAqB;AACnC,SAAO,IAAI,aAAa;AAC1B;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/testing/react-runtime.tsx"],"sourcesContent":["import { TestOrigins } from '../../../testing/fixtures'\nimport { ReactRuntime } from '../react-runtime'\n\nexport function createReactRuntime() {\n return new ReactRuntime({ fetch, ...TestOrigins })\n}\n"],"mappings":"AAAA,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAEtB,SAAS,qBAAqB;AACnC,SAAO,IAAI,aAAa,EAAE,OAAO,GAAG,YAAY,CAAC;AACnD;","names":[]}
@@ -15,7 +15,11 @@ const ReadOnlyActionTypes = {
15
15
  REGISTER_REACT_COMPONENT: "REGISTER_REACT_COMPONENT",
16
16
  UNREGISTER_REACT_COMPONENT: "UNREGISTER_REACT_COMPONENT",
17
17
  SET_IS_IN_BUILDER: "SET_IS_IN_BUILDER",
18
- SET_IS_READ_ONLY: "SET_IS_READ_ONLY"
18
+ SET_IS_READ_ONLY: "SET_IS_READ_ONLY",
19
+ SET_SITE_VERSION: "SET_SITE_VERSION",
20
+ // TODO: consolidate with `SET_LOCALE` action in `shared-api.ts`
21
+ // (requires changes to the builder to handle null locales)
22
+ RESET_LOCALE_STATE: "RESET_LOCALE_STATE"
19
23
  };
20
24
  function apiResourceFulfilled(resourceType, resourceId, resource, locale) {
21
25
  return {
@@ -113,6 +117,12 @@ function setIsInBuilder(isInBuilder) {
113
117
  function setIsReadOnly(isReadOnly) {
114
118
  return { type: ReadOnlyActionTypes.SET_IS_READ_ONLY, payload: isReadOnly };
115
119
  }
120
+ function setSiteVersion(siteVersion) {
121
+ return { type: ReadOnlyActionTypes.SET_SITE_VERSION, payload: siteVersion };
122
+ }
123
+ function resetLocaleState() {
124
+ return { type: ReadOnlyActionTypes.RESET_LOCALE_STATE };
125
+ }
116
126
  export {
117
127
  ReadOnlyActionTypes,
118
128
  apiResourceFulfilled,
@@ -125,8 +135,10 @@ export {
125
135
  registerPropControllers,
126
136
  registerPropControllersHandle,
127
137
  registerReactComponentEffect,
138
+ resetLocaleState,
128
139
  setIsInBuilder,
129
140
  setIsReadOnly,
141
+ setSiteVersion,
130
142
  unregisterComponent,
131
143
  unregisterPropControllers,
132
144
  unregisterPropControllersHandle
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/state/actions/internal/read-only-actions.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { ControlInstance } from '@makeswift/controls'\n\nimport { ElementImperativeHandle } from '../../../runtimes/react/element-imperative-handle'\n\nimport { type APIResource, APIResourceType, APIResourceLocale } from '../../../api/types'\nimport { type Descriptor as PropControllerDescriptor } from '../../../prop-controllers/descriptors'\n\nimport { type ComponentMeta } from '../../modules/components-meta'\nimport { type PropControllersHandle } from '../../modules/prop-controller-handles'\nimport { type ComponentType } from '../../modules/react-components'\nimport { type DescriptorsByComponentType } from '../../modules/prop-controllers'\n\nimport { type DocumentPayload } from '../../shared-api'\n\nexport const ReadOnlyActionTypes = {\n // TODO: this one should be a read-write action and we should refuse\n // to fetch resources on the client in read-only mode\n API_RESOURCE_FULFILLED: 'API_RESOURCE_FULFILLED',\n\n CREATE_ELEMENT_TREE: 'CREATE_ELEMENT_TREE',\n DELETE_ELEMENT_TREE: 'DELETE_ELEMENT_TREE',\n\n REGISTER_COMPONENT: 'REGISTER_COMPONENT',\n UNREGISTER_COMPONENT: 'UNREGISTER_COMPONENT',\n REGISTER_COMPONENT_HANDLE: 'REGISTER_COMPONENT_HANDLE',\n UNREGISTER_COMPONENT_HANDLE: 'UNREGISTER_COMPONENT_HANDLE',\n\n REGISTER_PROP_CONTROLLERS: 'REGISTER_PROP_CONTROLLERS',\n UNREGISTER_PROP_CONTROLLERS: 'UNREGISTER_PROP_CONTROLLERS',\n REGISTER_PROP_CONTROLLERS_HANDLE: 'REGISTER_PROP_CONTROLLERS_HANDLE',\n UNREGISTER_PROP_CONTROLLERS_HANDLE: 'UNREGISTER_PROP_CONTROLLERS_HANDLE',\n\n REGISTER_REACT_COMPONENT: 'REGISTER_REACT_COMPONENT',\n UNREGISTER_REACT_COMPONENT: 'UNREGISTER_REACT_COMPONENT',\n\n SET_IS_IN_BUILDER: 'SET_IS_IN_BUILDER',\n SET_IS_READ_ONLY: 'SET_IS_READ_ONLY',\n} as const\n\ntype APIResourceFulfilledAction = {\n type: typeof ReadOnlyActionTypes.API_RESOURCE_FULFILLED\n payload: {\n resourceType: APIResourceType\n resourceId: string\n resource: APIResource | null\n locale?: string | null\n }\n}\n\ntype CreateElementTreeAction = {\n type: typeof ReadOnlyActionTypes.CREATE_ELEMENT_TREE\n payload: { document: DocumentPayload; descriptors: DescriptorsByComponentType }\n}\n\ntype DeleteElementTreeAction = {\n type: typeof ReadOnlyActionTypes.DELETE_ELEMENT_TREE\n payload: { documentKey: string }\n}\n\nexport type RegisterComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT\n payload: {\n type: string\n meta: ComponentMeta\n propControllerDescriptors: Record<string, PropControllerDescriptor>\n }\n}\n\nexport type UnregisterComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT\n payload: { type: string }\n}\n\ntype RegisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string; componentHandle: ElementImperativeHandle }\n}\n\ntype UnregisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string; handle: PropControllersHandle }\n}\n\ntype UnregisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS\n payload: {\n documentKey: string\n elementKey: string\n propControllers: Record<string, ControlInstance>\n }\n}\n\ntype UnregisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_REACT_COMPONENT\n payload: { type: string; component: ComponentType }\n}\n\ntype UnregisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT\n payload: { type: string }\n}\n\ntype SetIsInBuilderAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_IN_BUILDER\n payload: boolean\n}\n\ntype SetIsReadOnlyAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_READ_ONLY\n payload: boolean\n}\nexport type ReadOnlyAction =\n | APIResourceFulfilledAction\n | CreateElementTreeAction\n | DeleteElementTreeAction\n | RegisterComponentAction\n | UnregisterComponentAction\n | RegisterComponentHandleAction\n | UnregisterComponentHandleAction\n | RegisterPropControllersHandleAction\n | UnregisterPropControllersHandleAction\n | RegisterPropControllersAction\n | UnregisterPropControllersAction\n | RegisterReactComponentAction\n | UnregisterReactComponentAction\n | SetIsInBuilderAction\n | SetIsReadOnlyAction\n\nexport function apiResourceFulfilled<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n resource: APIResource | null,\n locale?: APIResourceLocale<T>,\n): APIResourceFulfilledAction {\n return {\n type: ReadOnlyActionTypes.API_RESOURCE_FULFILLED,\n payload: { resourceType, resourceId, resource, locale },\n }\n}\n\nexport function createElementTree(\n payload: CreateElementTreeAction['payload'],\n): CreateElementTreeAction {\n return {\n type: ReadOnlyActionTypes.CREATE_ELEMENT_TREE,\n payload,\n }\n}\n\nexport function deleteElementTree(\n payload: DeleteElementTreeAction['payload'],\n): DeleteElementTreeAction {\n return { type: ReadOnlyActionTypes.DELETE_ELEMENT_TREE, payload }\n}\n\nexport function registerComponent(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): RegisterComponentAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT,\n payload: { type, meta, propControllerDescriptors },\n }\n}\n\nexport function unregisterComponent(type: string): UnregisterComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_COMPONENT, payload: { type } }\n}\n\nexport function registerComponentEffect(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponent(type, meta, propControllerDescriptors))\n\n return () => {\n dispatch(unregisterComponent(type))\n }\n }\n}\n\nexport function registerComponentHandle(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): RegisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey, componentHandle },\n }\n}\n\nfunction unregisterComponentHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerComponentHandleEffect(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponentHandle(documentKey, elementKey, componentHandle))\n\n return () => {\n dispatch(unregisterComponentHandle(documentKey, elementKey))\n }\n }\n}\n\nexport function registerPropControllersHandle(\n documentKey: string,\n elementKey: string,\n handle: PropControllersHandle,\n): RegisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey, handle },\n }\n}\n\nexport function unregisterPropControllersHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerPropControllers(\n documentKey: string,\n elementKey: string,\n propControllers: Record<string, ControlInstance>,\n): RegisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey, propControllers },\n }\n}\n\nexport function unregisterPropControllers(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey },\n }\n}\n\nfunction registerReactComponent(\n type: string,\n component: ComponentType,\n): RegisterReactComponentAction {\n return { type: ReadOnlyActionTypes.REGISTER_REACT_COMPONENT, payload: { type, component } }\n}\n\nfunction unregisterReactComponent(type: string): UnregisterReactComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT, payload: { type } }\n}\n\nexport function registerReactComponentEffect(\n type: string,\n component: ComponentType,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerReactComponent(type, component))\n\n return () => {\n dispatch(unregisterReactComponent(type))\n }\n }\n}\n\nexport function setIsInBuilder(isInBuilder: boolean): SetIsInBuilderAction {\n return { type: ReadOnlyActionTypes.SET_IS_IN_BUILDER, payload: isInBuilder }\n}\n\nexport function setIsReadOnly(isReadOnly: boolean): SetIsReadOnlyAction {\n return { type: ReadOnlyActionTypes.SET_IS_READ_ONLY, payload: isReadOnly }\n}\n"],"mappings":"AAgBO,MAAM,sBAAsB;AAAA;AAAA;AAAA,EAGjC,wBAAwB;AAAA,EAExB,qBAAqB;AAAA,EACrB,qBAAqB;AAAA,EAErB,oBAAoB;AAAA,EACpB,sBAAsB;AAAA,EACtB,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAE7B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAC7B,kCAAkC;AAAA,EAClC,oCAAoC;AAAA,EAEpC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C7D;AAAA,EACF;AACF;AAEO,SAAS,8BACd,aACA,YACA,QACqC;AACrC,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,aAAa,YAAY,OAAO;AAAA,EAC7C;AACF;AAEO,SAAS,gCACd,aACA,YACuC;AACvC,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,aAAa,WAAW;AAAA,EACrC;AACF;AAEO,SAAS,wBACd,aACA,YACA,iBAC+B;AAC/B,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,aAAa,YAAY,gBAAgB;AAAA,EACtD;AACF;AAEO,SAAS,0BACd,aACA,YACiC;AACjC,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,aAAa,WAAW;AAAA,EACrC;AACF;AAEA,SAAS,uBACP,MACA,WAC8B;AAC9B,SAAO,EAAE,MAAM,oBAAoB,0BAA0B,SAAS,EAAE,MAAM,UAAU,EAAE;AAC5F;AAEA,SAAS,yBAAyB,MAA8C;AAC9E,SAAO,EAAE,MAAM,oBAAoB,4BAA4B,SAAS,EAAE,KAAK,EAAE;AACnF;AAEO,SAAS,6BACd,MACA,WAC2D;AAC3D,SAAO,cAAY;AACjB,aAAS,uBAAuB,MAAM,SAAS,CAAC;AAEhD,WAAO,MAAM;AACX,eAAS,yBAAyB,IAAI,CAAC;AAAA,IACzC;AAAA,EACF;AACF;AAEO,SAAS,eAAe,aAA4C;AACzE,SAAO,EAAE,MAAM,oBAAoB,mBAAmB,SAAS,YAAY;AAC7E;AAEO,SAAS,cAAc,YAA0C;AACtE,SAAO,EAAE,MAAM,oBAAoB,kBAAkB,SAAS,WAAW;AAC3E;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/state/actions/internal/read-only-actions.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { ControlInstance } from '@makeswift/controls'\n\nimport { ElementImperativeHandle } from '../../../runtimes/react/element-imperative-handle'\n\nimport { type APIResource, APIResourceType, APIResourceLocale } from '../../../api/types'\nimport { type SiteVersion } from '../../../api/site-version'\nimport { type Descriptor as PropControllerDescriptor } from '../../../prop-controllers/descriptors'\n\nimport { type ComponentMeta } from '../../modules/components-meta'\nimport { type PropControllersHandle } from '../../modules/prop-controller-handles'\nimport { type ComponentType } from '../../modules/react-components'\nimport { type DescriptorsByComponentType } from '../../modules/prop-controllers'\n\nimport { type DocumentPayload } from '../../shared-api'\n\nexport const ReadOnlyActionTypes = {\n // TODO: this one should be a read-write action and we should refuse\n // to fetch resources on the client in read-only mode\n API_RESOURCE_FULFILLED: 'API_RESOURCE_FULFILLED',\n\n CREATE_ELEMENT_TREE: 'CREATE_ELEMENT_TREE',\n DELETE_ELEMENT_TREE: 'DELETE_ELEMENT_TREE',\n\n REGISTER_COMPONENT: 'REGISTER_COMPONENT',\n UNREGISTER_COMPONENT: 'UNREGISTER_COMPONENT',\n REGISTER_COMPONENT_HANDLE: 'REGISTER_COMPONENT_HANDLE',\n UNREGISTER_COMPONENT_HANDLE: 'UNREGISTER_COMPONENT_HANDLE',\n\n REGISTER_PROP_CONTROLLERS: 'REGISTER_PROP_CONTROLLERS',\n UNREGISTER_PROP_CONTROLLERS: 'UNREGISTER_PROP_CONTROLLERS',\n REGISTER_PROP_CONTROLLERS_HANDLE: 'REGISTER_PROP_CONTROLLERS_HANDLE',\n UNREGISTER_PROP_CONTROLLERS_HANDLE: 'UNREGISTER_PROP_CONTROLLERS_HANDLE',\n\n REGISTER_REACT_COMPONENT: 'REGISTER_REACT_COMPONENT',\n UNREGISTER_REACT_COMPONENT: 'UNREGISTER_REACT_COMPONENT',\n\n SET_IS_IN_BUILDER: 'SET_IS_IN_BUILDER',\n SET_IS_READ_ONLY: 'SET_IS_READ_ONLY',\n SET_SITE_VERSION: 'SET_SITE_VERSION',\n\n // TODO: consolidate with `SET_LOCALE` action in `shared-api.ts`\n // (requires changes to the builder to handle null locales)\n RESET_LOCALE_STATE: 'RESET_LOCALE_STATE',\n} as const\n\ntype APIResourceFulfilledAction = {\n type: typeof ReadOnlyActionTypes.API_RESOURCE_FULFILLED\n payload: {\n resourceType: APIResourceType\n resourceId: string\n resource: APIResource | null\n locale?: string | null\n }\n}\n\ntype CreateElementTreeAction = {\n type: typeof ReadOnlyActionTypes.CREATE_ELEMENT_TREE\n payload: { document: DocumentPayload; descriptors: DescriptorsByComponentType }\n}\n\ntype DeleteElementTreeAction = {\n type: typeof ReadOnlyActionTypes.DELETE_ELEMENT_TREE\n payload: { documentKey: string }\n}\n\nexport type RegisterComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT\n payload: {\n type: string\n meta: ComponentMeta\n propControllerDescriptors: Record<string, PropControllerDescriptor>\n }\n}\n\nexport type UnregisterComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT\n payload: { type: string }\n}\n\ntype RegisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string; componentHandle: ElementImperativeHandle }\n}\n\ntype UnregisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string; handle: PropControllersHandle }\n}\n\ntype UnregisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS\n payload: {\n documentKey: string\n elementKey: string\n propControllers: Record<string, ControlInstance>\n }\n}\n\ntype UnregisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_REACT_COMPONENT\n payload: { type: string; component: ComponentType }\n}\n\ntype UnregisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT\n payload: { type: string }\n}\n\ntype SetIsInBuilderAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_IN_BUILDER\n payload: boolean\n}\n\ntype SetIsReadOnlyAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_READ_ONLY\n payload: boolean\n}\n\ntype SetSiteVersionAction = {\n type: typeof ReadOnlyActionTypes.SET_SITE_VERSION\n payload: SiteVersion | null\n}\n\ntype ResetLocaleStateAction = {\n type: typeof ReadOnlyActionTypes.RESET_LOCALE_STATE\n}\n\nexport type ReadOnlyAction =\n | APIResourceFulfilledAction\n | CreateElementTreeAction\n | DeleteElementTreeAction\n | RegisterComponentAction\n | UnregisterComponentAction\n | RegisterComponentHandleAction\n | UnregisterComponentHandleAction\n | RegisterPropControllersHandleAction\n | UnregisterPropControllersHandleAction\n | RegisterPropControllersAction\n | UnregisterPropControllersAction\n | RegisterReactComponentAction\n | UnregisterReactComponentAction\n | SetIsInBuilderAction\n | SetIsReadOnlyAction\n | SetSiteVersionAction\n | ResetLocaleStateAction\n\nexport function apiResourceFulfilled<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n resource: APIResource | null,\n locale?: APIResourceLocale<T>,\n): APIResourceFulfilledAction {\n return {\n type: ReadOnlyActionTypes.API_RESOURCE_FULFILLED,\n payload: { resourceType, resourceId, resource, locale },\n }\n}\n\nexport function createElementTree(\n payload: CreateElementTreeAction['payload'],\n): CreateElementTreeAction {\n return {\n type: ReadOnlyActionTypes.CREATE_ELEMENT_TREE,\n payload,\n }\n}\n\nexport function deleteElementTree(\n payload: DeleteElementTreeAction['payload'],\n): DeleteElementTreeAction {\n return { type: ReadOnlyActionTypes.DELETE_ELEMENT_TREE, payload }\n}\n\nexport function registerComponent(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): RegisterComponentAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT,\n payload: { type, meta, propControllerDescriptors },\n }\n}\n\nexport function unregisterComponent(type: string): UnregisterComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_COMPONENT, payload: { type } }\n}\n\nexport function registerComponentEffect(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponent(type, meta, propControllerDescriptors))\n\n return () => {\n dispatch(unregisterComponent(type))\n }\n }\n}\n\nexport function registerComponentHandle(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): RegisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey, componentHandle },\n }\n}\n\nfunction unregisterComponentHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerComponentHandleEffect(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponentHandle(documentKey, elementKey, componentHandle))\n\n return () => {\n dispatch(unregisterComponentHandle(documentKey, elementKey))\n }\n }\n}\n\nexport function registerPropControllersHandle(\n documentKey: string,\n elementKey: string,\n handle: PropControllersHandle,\n): RegisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey, handle },\n }\n}\n\nexport function unregisterPropControllersHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerPropControllers(\n documentKey: string,\n elementKey: string,\n propControllers: Record<string, ControlInstance>,\n): RegisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey, propControllers },\n }\n}\n\nexport function unregisterPropControllers(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey },\n }\n}\n\nfunction registerReactComponent(\n type: string,\n component: ComponentType,\n): RegisterReactComponentAction {\n return { type: ReadOnlyActionTypes.REGISTER_REACT_COMPONENT, payload: { type, component } }\n}\n\nfunction unregisterReactComponent(type: string): UnregisterReactComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT, payload: { type } }\n}\n\nexport function registerReactComponentEffect(\n type: string,\n component: ComponentType,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerReactComponent(type, component))\n\n return () => {\n dispatch(unregisterReactComponent(type))\n }\n }\n}\n\nexport function setIsInBuilder(isInBuilder: boolean): SetIsInBuilderAction {\n return { type: ReadOnlyActionTypes.SET_IS_IN_BUILDER, payload: isInBuilder }\n}\n\nexport function setIsReadOnly(isReadOnly: boolean): SetIsReadOnlyAction {\n return { type: ReadOnlyActionTypes.SET_IS_READ_ONLY, payload: isReadOnly }\n}\n\nexport function setSiteVersion(siteVersion: SiteVersion | null): SetSiteVersionAction {\n return { type: ReadOnlyActionTypes.SET_SITE_VERSION, payload: siteVersion }\n}\n\nexport function resetLocaleState(): ResetLocaleStateAction {\n return { type: ReadOnlyActionTypes.RESET_LOCALE_STATE }\n}\n"],"mappings":"AAiBO,MAAM,sBAAsB;AAAA;AAAA;AAAA,EAGjC,wBAAwB;AAAA,EAExB,qBAAqB;AAAA,EACrB,qBAAqB;AAAA,EAErB,oBAAoB;AAAA,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AAO,EAAE,MAAM,oBAAoB,kBAAkB,SAAS,WAAW;AAC3E;AAEO,SAAS,eAAe,aAAuD;AACpF,SAAO,EAAE,MAAM,oBAAoB,kBAAkB,SAAS,YAAY;AAC5E;AAEO,SAAS,mBAA2C;AACzD,SAAO,EAAE,MAAM,oBAAoB,mBAAmB;AACxD;","names":[]}
@@ -2,6 +2,9 @@ import {
2
2
  configureStore as configureReduxStore,
3
3
  combineReducers
4
4
  } from "@reduxjs/toolkit";
5
+ import { ApiHandlerHeaders, serializeSiteVersion } from "../api/site-version";
6
+ import * as SiteVersionState from "./modules/site-version";
7
+ import * as LocaleState from "./modules/locale";
5
8
  import * as APIResources from "./modules/api-resources";
6
9
  import * as LocalizedResourcesMap from "./modules/localized-resources-map";
7
10
  import { ActionTypes } from "./actions";
@@ -12,6 +15,8 @@ import {
12
15
  APIResourceType
13
16
  } from "../api";
14
17
  const reducer = combineReducers({
18
+ siteVersion: SiteVersionState.reducer,
19
+ locale: LocaleState.reducer,
15
20
  apiResources: APIResources.reducer,
16
21
  localizedResourcesMap: LocalizedResourcesMap.reducer
17
22
  });
@@ -49,10 +54,11 @@ function getAPIResource(state, resourceType, resourceId, locale) {
49
54
  }
50
55
  }
51
56
  function fetchAPIResource(resourceType, resourceId, fetch, locale) {
52
- const fetchJson = async (url) => {
57
+ const fetchVersioned = async (url, version) => {
53
58
  const response = await fetch(url, {
54
59
  headers: {
55
- "Content-Type": "application/json"
60
+ "Content-Type": "application/json",
61
+ ...version != null ? { [ApiHandlerHeaders.SiteVersion]: serializeSiteVersion(version) } : {}
56
62
  }
57
63
  });
58
64
  if (response.status === 404)
@@ -68,22 +74,29 @@ function fetchAPIResource(resourceType, resourceId, fetch, locale) {
68
74
  };
69
75
  return async (dispatch, getState) => {
70
76
  const state = getState();
77
+ const version = SiteVersionState.getSiteVersion(state.siteVersion);
71
78
  if (getHasAPIResource(state, resourceType, resourceId, locale)) {
72
79
  return getAPIResource(state, resourceType, resourceId, locale);
73
80
  }
74
81
  let resource;
75
82
  switch (resourceType) {
76
83
  case APIResourceType.Swatch:
77
- resource = await fetchJson(`/api/makeswift/swatches/${resourceId}`);
84
+ resource = await fetchVersioned(`/api/makeswift/swatches/${resourceId}`, version);
78
85
  break;
79
86
  case APIResourceType.File:
80
- resource = await fetchJson(`/api/makeswift/files/${resourceId}`);
87
+ resource = await fetchVersioned(`/api/makeswift/files/${resourceId}`, version);
81
88
  break;
82
89
  case APIResourceType.Typography:
83
- resource = await fetchJson(`/api/makeswift/typographies/${resourceId}`);
90
+ resource = await fetchVersioned(
91
+ `/api/makeswift/typographies/${resourceId}`,
92
+ version
93
+ );
84
94
  break;
85
95
  case APIResourceType.GlobalElement:
86
- resource = await fetchJson(`/api/makeswift/global-elements/${resourceId}`);
96
+ resource = await fetchVersioned(
97
+ `/api/makeswift/global-elements/${resourceId}`,
98
+ version
99
+ );
87
100
  break;
88
101
  case APIResourceType.LocalizedGlobalElement: {
89
102
  if (locale == null)
@@ -91,8 +104,9 @@ function fetchAPIResource(resourceType, resourceId, fetch, locale) {
91
104
  if (getLocalizedResourceId(state, locale, resourceId) === null) {
92
105
  return null;
93
106
  }
94
- resource = await fetchJson(
95
- `/api/makeswift/localized-global-elements/${resourceId}/${locale}`
107
+ resource = await fetchVersioned(
108
+ `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,
109
+ version
96
110
  );
97
111
  dispatch(
98
112
  setLocalizedResourceId({
@@ -107,11 +121,11 @@ function fetchAPIResource(resourceType, resourceId, fetch, locale) {
107
121
  const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, "http://n");
108
122
  if (locale != null)
109
123
  url.searchParams.set("locale", locale);
110
- resource = await fetchJson(url.pathname + url.search);
124
+ resource = await fetchVersioned(url.pathname + url.search, version);
111
125
  break;
112
126
  }
113
127
  case APIResourceType.Table:
114
- resource = await fetchJson(`/api/makeswift/tables/${resourceId}`);
128
+ resource = await fetchVersioned(`/api/makeswift/tables/${resourceId}`, version);
115
129
  break;
116
130
  default:
117
131
  resource = null;
@@ -120,8 +134,8 @@ function fetchAPIResource(resourceType, resourceId, fetch, locale) {
120
134
  return resource;
121
135
  };
122
136
  }
123
- function defaultLocaleMiddleware(defaultLocale) {
124
- return actionMiddleware(() => (next) => {
137
+ function defaultLocaleMiddleware() {
138
+ return actionMiddleware(({ getState }) => (next) => {
125
139
  return (action) => {
126
140
  switch (action.type) {
127
141
  case ActionTypes.CHANGE_API_RESOURCE:
@@ -130,7 +144,10 @@ function defaultLocaleMiddleware(defaultLocale) {
130
144
  const { locale } = action.payload;
131
145
  return next({
132
146
  ...action,
133
- payload: { ...action.payload, locale: locale ?? defaultLocale }
147
+ payload: {
148
+ ...action.payload,
149
+ locale: locale ?? LocaleState.getLocale(getState().locale)
150
+ }
134
151
  });
135
152
  }
136
153
  }
@@ -138,10 +155,7 @@ function defaultLocaleMiddleware(defaultLocale) {
138
155
  };
139
156
  });
140
157
  }
141
- function configureStore({
142
- defaultLocale,
143
- serializedState
144
- }) {
158
+ function configureStore({ serializedState }) {
145
159
  return configureReduxStore({
146
160
  reducer,
147
161
  preloadedState: {
@@ -150,7 +164,7 @@ function configureStore({
150
164
  serializedState?.localizedResourcesMap
151
165
  )
152
166
  },
153
- middleware: (getDefaultMiddleware) => getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware(defaultLocale)),
167
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware()),
154
168
  devTools: devToolsConfig({
155
169
  name: `API client store (${(/* @__PURE__ */ new Date()).toISOString()})`,
156
170
  actionsDenylist: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkAction,\n type ThunkMiddleware,\n type ThunkDispatch,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\nimport { type Action, ActionTypes } from './actions'\nimport { apiResourceFulfilled } from './actions/internal/read-only-actions'\nimport { setLocalizedResourceId } from './host-api'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\n\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n} from '../api'\n\nconst reducer = combineReducers({\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n fetch: HttpFetch,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n const fetchJson = async <T>(url: string): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n\n if (response.status === 404) return null\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n }\n\n return async (dispatch, getState) => {\n const state = getState()\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchJson<Swatch>(`/api/makeswift/swatches/${resourceId}`)\n break\n\n case APIResourceType.File:\n resource = await fetchJson<File>(`/api/makeswift/files/${resourceId}`)\n break\n\n case APIResourceType.Typography:\n resource = await fetchJson<Typography>(`/api/makeswift/typographies/${resourceId}`)\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchJson<GlobalElement>(`/api/makeswift/global-elements/${resourceId}`)\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchJson<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchJson<PagePathnameSlice>(url.pathname + url.search)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchJson<Table>(`/api/makeswift/tables/${resourceId}`)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(\n defaultLocale: string | undefined,\n): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: { ...action.payload, locale: locale ?? defaultLocale },\n } as Action)\n }\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({\n defaultLocale,\n serializedState,\n}: {\n defaultLocale: string | undefined\n serializedState?: SerializedState\n}) {\n return configureReduxStore({\n reducer,\n preloadedState: {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware(defaultLocale)),\n\n devTools: devToolsConfig({\n name: `API client store (${new Date().toISOString()})`,\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n}\n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,wBAAwB,aAAa,CAAC;AAAA,IAEvF,UAAU,eAAe;AAAA,MACvB,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkAction,\n type ThunkMiddleware,\n type ThunkDispatch,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport { type SiteVersion, ApiHandlerHeaders, serializeSiteVersion } from '../api/site-version'\n\nimport * as SiteVersionState from './modules/site-version'\nimport * as LocaleState from './modules/locale'\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\n\nimport { type Action, ActionTypes } from './actions'\nimport { apiResourceFulfilled } from './actions/internal/read-only-actions'\nimport { setLocalizedResourceId } from './host-api'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\n\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n} from '../api'\n\nconst reducer = combineReducers({\n siteVersion: SiteVersionState.reducer,\n locale: LocaleState.reducer,\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n fetch: HttpFetch,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n const fetchVersioned = async <T>(url: string, version: SiteVersion | null): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(version != null\n ? { [ApiHandlerHeaders.SiteVersion]: serializeSiteVersion(version) }\n : {}),\n },\n })\n\n if (response.status === 404) return null\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n }\n\n return async (dispatch, getState) => {\n const state = getState()\n const version = SiteVersionState.getSiteVersion(state.siteVersion)\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchVersioned<Swatch>(`/api/makeswift/swatches/${resourceId}`, version)\n break\n\n case APIResourceType.File:\n resource = await fetchVersioned<File>(`/api/makeswift/files/${resourceId}`, version)\n break\n\n case APIResourceType.Typography:\n resource = await fetchVersioned<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchVersioned<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchVersioned<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n version,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchVersioned<PagePathnameSlice>(url.pathname + url.search, version)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchVersioned<Table>(`/api/makeswift/tables/${resourceId}`, version)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(({ getState }) => next => {\n return (action: Action) => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: {\n ...action.payload,\n locale: locale ?? LocaleState.getLocale(getState().locale),\n },\n } as Action)\n }\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({ serializedState }: { serializedState?: SerializedState }) {\n return configureReduxStore({\n reducer,\n preloadedState: {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware()),\n\n devTools: devToolsConfig({\n name: `API client store (${new Date().toISOString()})`,\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":"AAAA;AAAA,EACE,kBAAkB;AAAA,EAClB;AAAA,OAKK;AAEP,SAA2B,mBAAmB,4BAA4B;AAE1E,YAAY,sBAAsB;AAClC,YAAY,iBAAiB;AAC7B,YAAY,kBAAkB;AAC9B,YAAY,2BAA2B;AAEvC,SAAsB,mBAAmB;AACzC,SAAS,4BAA4B;AACrC,SAAS,8BAA8B;AACvC,SAAS,kBAAkB,mBAAmB,sBAAsB;AAEpE;AAAA,EACE;AAAA,OAUK;AAEP,MAAM,UAAU,gBAAgB;AAAA,EAC9B,aAAa,iBAAiB;AAAA,EAC9B,QAAQ,YAAY;AAAA,EACpB,cAAc,aAAa;AAAA,EAC3B,uBAAuB,sBAAsB;AAC/C,CAAC;AAWD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,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
@@ -1,4 +1,4 @@
1
- import { actionMiddleware } from "../../toolkit";
1
+ import { actionMiddleware } from "../toolkit";
2
2
  function makeswiftApiClientSyncMiddleware(client) {
3
3
  return actionMiddleware(() => (next) => {
4
4
  return (action) => {
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/state/middleware/makeswift-api-client-sync.ts"],"sourcesContent":["import { type Middleware } from '@reduxjs/toolkit'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\n\nimport { type Action } from '../actions'\nimport { actionMiddleware } from '../toolkit'\nimport { type State, type Dispatch } from '../unified-state'\n\nexport function makeswiftApiClientSyncMiddleware(\n client: MakeswiftHostApiClient,\n): Middleware<Dispatch, State, Dispatch> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n client.makeswiftApiClient.dispatch(action)\n\n return next(action)\n }\n })\n}\n"],"mappings":"AAKA,SAAS,wBAAwB;AAG1B,SAAS,iCACd,QACuC;AACvC,SAAO,iBAAiB,MAAM,UAAQ;AACpC,WAAO,CAAC,WAAmB;AACzB,aAAO,mBAAmB,SAAS,MAAM;AAEzC,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,16 @@
1
+ import { updateElementTreeMiddleware } from "./update-element-tree";
2
+ import { measureBoxModelsMiddleware } from "./measure-box-models";
3
+ import { builderAPIMiddleware } from "./builder-api";
4
+ import { propControllerHandlesMiddleware } from "./prop-controller-handles";
5
+ function createReadWriteMiddleware({ builderProxy }) {
6
+ return [
7
+ updateElementTreeMiddleware(),
8
+ measureBoxModelsMiddleware(),
9
+ builderAPIMiddleware(builderProxy),
10
+ propControllerHandlesMiddleware()
11
+ ];
12
+ }
13
+ export {
14
+ createReadWriteMiddleware
15
+ };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/state/middleware/read-write/index.ts"],"sourcesContent":["import { type BuilderAPIProxy } from '../../builder-api/proxy'\n\nimport { updateElementTreeMiddleware } from './update-element-tree'\nimport { measureBoxModelsMiddleware } from './measure-box-models'\nimport { builderAPIMiddleware } from './builder-api'\nimport { propControllerHandlesMiddleware } from './prop-controller-handles'\n\nexport function createReadWriteMiddleware({ builderProxy }: { builderProxy: BuilderAPIProxy }) {\n return [\n updateElementTreeMiddleware(),\n measureBoxModelsMiddleware(),\n builderAPIMiddleware(builderProxy),\n propControllerHandlesMiddleware(),\n ]\n}\n"],"mappings":"AAEA,SAAS,mCAAmC;AAC5C,SAAS,kCAAkC;AAC3C,SAAS,4BAA4B;AACrC,SAAS,uCAAuC;AAEzC,SAAS,0BAA0B,EAAE,aAAa,GAAsC;AAC7F,SAAO;AAAA,IACL,4BAA4B;AAAA,IAC5B,2BAA2B;AAAA,IAC3B,qBAAqB,YAAY;AAAA,IACjC,gCAAgC;AAAA,EAClC;AACF;","names":[]}
@@ -1,11 +1,11 @@
1
- import * as PropControllerHandles from "../modules/prop-controller-handles";
2
- import * as Builder from "../builder-api/actions";
3
- import { ReadOnlyActionTypes } from "../actions/internal/read-only-actions";
4
- import * as ReadOnly from "../actions/internal/read-only-actions";
5
- import { actionMiddleware } from "../toolkit";
6
- import { createPropController } from "../../prop-controllers/instances";
7
- import { HostActionTypes } from "../host-api";
8
- import * as ReadOnlyState from "../read-only-state";
1
+ import * as PropControllerHandles from "../../modules/prop-controller-handles";
2
+ import * as Builder from "../../builder-api/actions";
3
+ import { ReadOnlyActionTypes } from "../../actions/internal/read-only-actions";
4
+ import * as ReadOnly from "../../actions/internal/read-only-actions";
5
+ import { actionMiddleware } from "../../toolkit";
6
+ import { createPropController } from "../../../prop-controllers/instances";
7
+ import { HostActionTypes } from "../../host-api";
8
+ import * as ReadOnlyState from "../../read-only-state";
9
9
  function createAndRegisterPropControllers(documentKey, elementKey) {
10
10
  return (dispatch, getState) => {
11
11
  const descriptors = ReadOnlyState.getElementPropControllerDescriptors(
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/state/middleware/read-write/prop-controller-handles.ts"],"sourcesContent":["import { type Middleware, type ThunkAction } from '@reduxjs/toolkit'\n\nimport { ControlInstance } from '@makeswift/controls'\n\nimport * as PropControllerHandles from '../../modules/prop-controller-handles'\n\nimport { type Action } from '../../actions'\n\nimport * as Builder from '../../builder-api/actions'\n\nimport { ReadOnlyActionTypes } from '../../actions/internal/read-only-actions'\nimport * as ReadOnly from '../../actions/internal/read-only-actions'\n\nimport { actionMiddleware } from '../../toolkit'\n\nimport { createPropController } from '../../../prop-controllers/instances'\nimport { HostActionTypes } from '../../host-api'\n\nimport * as ReadOnlyState from '../../read-only-state'\nimport { type State, type Dispatch } from '../../read-write-state'\n\nfunction createAndRegisterPropControllers(\n documentKey: string,\n elementKey: string,\n): ThunkAction<Record<string, ControlInstance> | null, State, unknown, Action> {\n return (dispatch, getState) => {\n const descriptors = ReadOnlyState.getElementPropControllerDescriptors(\n getState(),\n documentKey,\n elementKey,\n )\n\n if (descriptors == null) return null\n\n const propControllers = Object.entries(descriptors).reduce(\n (acc, [propName, descriptor]) => {\n const propController = createPropController(descriptor, message =>\n dispatch(\n Builder.messageBuilderPropController(documentKey, elementKey, propName, message),\n ),\n ) as ControlInstance\n\n return { ...acc, [propName]: propController }\n },\n {} as Record<string, ControlInstance>,\n )\n\n dispatch(ReadOnly.registerPropControllers(documentKey, elementKey, propControllers))\n\n return propControllers\n }\n}\n\nexport function propControllerHandlesMiddleware(): Middleware<Dispatch, State, Dispatch> {\n return actionMiddleware(({ dispatch, getState }) => next => {\n return (action: Action) => {\n switch (action.type) {\n case ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE: {\n const { documentKey, elementKey, componentHandle } = action.payload\n const element = ReadOnlyState.getElement(getState(), documentKey, elementKey)\n const propControllers = dispatch(\n createAndRegisterPropControllers(documentKey, elementKey),\n )\n\n if (\n element != null &&\n !ReadOnlyState.isElementReference(element) &&\n PropControllerHandles.isPropControllersHandle(componentHandle)\n ) {\n dispatch(\n ReadOnly.registerPropControllersHandle(documentKey, elementKey, componentHandle),\n )\n componentHandle.setPropControllers(propControllers)\n }\n\n break\n }\n\n case ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE: {\n const { documentKey, elementKey } = action.payload\n const handle = ReadOnlyState.getPropControllersHandle(getState(), {\n documentKey,\n elementKey,\n })\n\n handle?.setPropControllers(null)\n\n dispatch(ReadOnly.unregisterPropControllers(documentKey, elementKey))\n\n break\n }\n\n case HostActionTypes.MESSAGE_HOST_PROP_CONTROLLER: {\n const { documentKey, elementKey, propName, message } = action.payload\n const propController = ReadOnlyState.getPropController(getState(), {\n documentKey,\n elementKey,\n propName,\n })\n\n if (propController) propController.recv(message)\n }\n }\n\n return next(action)\n }\n })\n}\n"],"mappings":"AAIA,YAAY,2BAA2B;AAIvC,YAAY,aAAa;AAEzB,SAAS,2BAA2B;AACpC,YAAY,cAAc;AAE1B,SAAS,wBAAwB;AAEjC,SAAS,4BAA4B;AACrC,SAAS,uBAAuB;AAEhC,YAAY,mBAAmB;AAG/B,SAAS,iCACP,aACA,YAC6E;AAC7E,SAAO,CAAC,UAAU,aAAa;AAC7B,UAAM,cAAc,cAAc;AAAA,MAChC,SAAS;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAEA,QAAI,eAAe;AAAM,aAAO;AAEhC,UAAM,kBAAkB,OAAO,QAAQ,WAAW,EAAE;AAAA,MAClD,CAAC,KAAK,CAAC,UAAU,UAAU,MAAM;AAC/B,cAAM,iBAAiB;AAAA,UAAqB;AAAA,UAAY,aACtD;AAAA,YACE,QAAQ,6BAA6B,aAAa,YAAY,UAAU,OAAO;AAAA,UACjF;AAAA,QACF;AAEA,eAAO,EAAE,GAAG,KAAK,CAAC,QAAQ,GAAG,eAAe;AAAA,MAC9C;AAAA,MACA,CAAC;AAA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