@makeswift/runtime 0.25.0-canary.9 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (704) hide show
  1. package/dist/cjs/api/react.js +10 -14
  2. package/dist/cjs/api/react.js.map +1 -1
  3. package/dist/cjs/api/site-version/index.js +103 -0
  4. package/dist/cjs/api/site-version/index.js.map +1 -0
  5. package/dist/cjs/api-handler/handlers/manifest.js +3 -4
  6. package/dist/cjs/api-handler/handlers/manifest.js.map +1 -1
  7. package/dist/cjs/api-handler/handlers/redirect-live.js +52 -0
  8. package/dist/cjs/api-handler/handlers/redirect-live.js.map +1 -0
  9. package/dist/cjs/api-handler/index.js +6 -5
  10. package/dist/cjs/api-handler/index.js.map +1 -1
  11. package/dist/cjs/api-handler/node-request-response.js +99 -0
  12. package/dist/cjs/api-handler/node-request-response.js.map +1 -0
  13. package/dist/cjs/{next/preview-mode.js → api-handler/preview.js} +12 -18
  14. package/dist/cjs/api-handler/preview.js.map +1 -0
  15. package/dist/cjs/api-handler/request-response.js +9 -0
  16. package/dist/cjs/api-handler/request-response.js.map +1 -1
  17. package/dist/cjs/client/index.js +67 -59
  18. package/dist/cjs/client/index.js.map +1 -1
  19. package/dist/cjs/components/builtin/Box/animations.js.map +1 -1
  20. package/dist/cjs/components/builtin/Form/components/Field/services/responsiveField.js.map +1 -1
  21. package/dist/cjs/components/builtin/Root/Root.js +4 -4
  22. package/dist/cjs/components/builtin/Root/Root.js.map +1 -1
  23. package/dist/cjs/components/builtin/Video/Video.js +3 -13
  24. package/dist/cjs/components/builtin/Video/Video.js.map +1 -1
  25. package/dist/cjs/components/hooks/useMediaQuery.js +1 -2
  26. package/dist/cjs/components/hooks/useMediaQuery.js.map +1 -1
  27. package/dist/cjs/components/shared/BackgroundsContainer/components/BackgroundVideo/index.js +3 -13
  28. package/dist/cjs/components/shared/BackgroundsContainer/components/BackgroundVideo/index.js.map +1 -1
  29. package/dist/cjs/components/shared/BackgroundsContainer/components/Backgrounds/index.js.map +1 -1
  30. package/dist/cjs/components/shared/Link/index.js +15 -40
  31. package/dist/cjs/components/shared/Link/index.js.map +1 -1
  32. package/dist/cjs/components/shared/react-player.js +41 -0
  33. package/dist/cjs/components/shared/react-player.js.map +1 -0
  34. package/dist/cjs/components/utils/responsive-style.js.map +1 -1
  35. package/dist/cjs/css/border-radius.js.map +1 -1
  36. package/dist/cjs/css/border.js.map +1 -1
  37. package/dist/cjs/css/margin.js.map +1 -1
  38. package/dist/cjs/css/padding.js.map +1 -1
  39. package/dist/cjs/next/api-handler/config/app-router.js +12 -10
  40. package/dist/cjs/next/api-handler/config/app-router.js.map +1 -1
  41. package/dist/cjs/next/api-handler/config/pages-router.js +9 -69
  42. package/dist/cjs/next/api-handler/config/pages-router.js.map +1 -1
  43. package/dist/cjs/next/api-handler/handlers/{redirect-draft.js → app-router-redirect-preview.js} +30 -26
  44. package/dist/cjs/next/api-handler/handlers/app-router-redirect-preview.js.map +1 -0
  45. package/dist/cjs/next/api-handler/handlers/{redirect-preview.js → pages-router-redirect-preview.js} +29 -22
  46. package/dist/cjs/next/api-handler/handlers/pages-router-redirect-preview.js.map +1 -0
  47. package/dist/cjs/next/api-handler/index.js +4 -3
  48. package/dist/cjs/next/api-handler/index.js.map +1 -1
  49. package/dist/cjs/next/api-handler/{draft.js → preview.js} +13 -11
  50. package/dist/cjs/next/api-handler/preview.js.map +1 -0
  51. package/dist/cjs/next/{draft-mode/index.js → app-router-site-version.js} +11 -27
  52. package/dist/cjs/next/app-router-site-version.js.map +1 -0
  53. package/dist/cjs/next/client.js +9 -3
  54. package/dist/cjs/next/client.js.map +1 -1
  55. package/dist/cjs/next/components/framework-provider/index.js +6 -2
  56. package/dist/cjs/next/components/framework-provider/index.js.map +1 -1
  57. package/dist/cjs/next/components/framework-provider/link.js +69 -0
  58. package/dist/cjs/next/components/framework-provider/link.js.map +1 -0
  59. package/dist/cjs/next/components/page.js +1 -1
  60. package/dist/cjs/next/components/page.js.map +1 -1
  61. package/dist/cjs/next/components/tests/__fixtures__/element-data/button-component.js +109 -0
  62. package/dist/cjs/next/components/tests/__fixtures__/element-data/button-component.js.map +1 -0
  63. package/dist/cjs/next/components/tests/__fixtures__/element-data/image-component.js +10 -0
  64. package/dist/cjs/next/components/tests/__fixtures__/element-data/image-component.js.map +1 -1
  65. package/dist/cjs/next/components/tests/__fixtures__/resources/index.js +3 -1
  66. package/dist/cjs/next/components/tests/__fixtures__/resources/index.js.map +1 -1
  67. package/dist/cjs/{api-handler/handlers/clear-draft.js → next/components/tests/__fixtures__/resources/page-pathname-slices.js} +11 -19
  68. package/dist/cjs/next/components/tests/__fixtures__/resources/page-pathname-slices.js.map +1 -0
  69. package/dist/cjs/next/document.js +2 -1
  70. package/dist/cjs/next/document.js.map +1 -1
  71. package/dist/cjs/next/index.js.map +1 -1
  72. package/dist/cjs/next/middleware/request-utils.js +11 -17
  73. package/dist/cjs/next/middleware/request-utils.js.map +1 -1
  74. package/dist/cjs/next/root-style-registry.js +10 -25
  75. package/dist/cjs/next/root-style-registry.js.map +1 -1
  76. package/dist/cjs/next/server.js +2 -2
  77. package/dist/cjs/next/server.js.map +1 -1
  78. package/dist/cjs/next/testing/page-rendering.js +2 -2
  79. package/dist/cjs/next/testing/page-rendering.js.map +1 -1
  80. package/dist/cjs/next/testing/react-provider.js +2 -2
  81. package/dist/cjs/next/testing/react-provider.js.map +1 -1
  82. package/dist/cjs/next/tests/test-utils.js +7 -5
  83. package/dist/cjs/next/tests/test-utils.js.map +1 -1
  84. package/dist/cjs/runtimes/react/components/RuntimeProvider.js +9 -7
  85. package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
  86. package/dist/cjs/runtimes/react/components/framework-context.js +20 -3
  87. package/dist/cjs/runtimes/react/components/framework-context.js.map +1 -1
  88. package/dist/cjs/runtimes/react/components/page/index.js +18 -16
  89. package/dist/cjs/runtimes/react/components/page/index.js.map +1 -1
  90. package/dist/cjs/runtimes/react/components/{draft-switcher/draft-switcher.js → preview-switcher/preview-switcher.js} +12 -22
  91. package/dist/cjs/runtimes/react/components/preview-switcher/preview-switcher.js.map +1 -0
  92. package/dist/cjs/runtimes/react/components/{draft-switcher/draft-toolbar.js → preview-switcher/preview-toolbar.js} +17 -9
  93. package/dist/cjs/runtimes/react/components/preview-switcher/preview-toolbar.js.map +1 -0
  94. package/dist/cjs/runtimes/react/controls/style.js.map +1 -1
  95. package/dist/cjs/runtimes/react/hooks/makeswift-api.js +9 -10
  96. package/dist/cjs/runtimes/react/hooks/makeswift-api.js.map +1 -1
  97. package/dist/cjs/runtimes/react/hooks/use-selector.js +1 -1
  98. package/dist/cjs/runtimes/react/hooks/use-selector.js.map +1 -1
  99. package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js +1 -1
  100. package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -1
  101. package/dist/cjs/runtimes/react/hooks/use-universal-dispatch.js.map +1 -1
  102. package/dist/cjs/runtimes/react/host-api-client.js +7 -2
  103. package/dist/cjs/runtimes/react/host-api-client.js.map +1 -1
  104. package/dist/cjs/runtimes/react/root-style-registry.js +39 -13
  105. package/dist/cjs/runtimes/react/root-style-registry.js.map +1 -1
  106. package/dist/cjs/runtimes/react/use-global-style.js +1 -1
  107. package/dist/cjs/runtimes/react/use-global-style.js.map +1 -1
  108. package/dist/cjs/runtimes/react/use-style.js +3 -3
  109. package/dist/cjs/runtimes/react/use-style.js.map +1 -1
  110. package/dist/cjs/state/actions.js +6 -0
  111. package/dist/cjs/state/actions.js.map +1 -1
  112. package/dist/cjs/state/makeswift-api-client.js +42 -57
  113. package/dist/cjs/state/makeswift-api-client.js.map +1 -1
  114. package/dist/cjs/state/mixins/setup-teardown.js.map +1 -1
  115. package/dist/cjs/state/modules/api-resources.js +2 -0
  116. package/dist/cjs/state/modules/api-resources.js.map +1 -1
  117. package/dist/cjs/state/modules/box-models.js +2 -0
  118. package/dist/cjs/state/modules/box-models.js.map +1 -1
  119. package/dist/cjs/state/modules/breakpoints.js +3 -1
  120. package/dist/cjs/state/modules/breakpoints.js.map +1 -1
  121. package/dist/cjs/state/modules/builder-edit-mode.js +2 -0
  122. package/dist/cjs/state/modules/builder-edit-mode.js.map +1 -1
  123. package/dist/cjs/state/modules/components-meta.js +2 -0
  124. package/dist/cjs/state/modules/components-meta.js.map +1 -1
  125. package/dist/cjs/state/modules/element-imperative-handles.js +2 -0
  126. package/dist/cjs/state/modules/element-imperative-handles.js.map +1 -1
  127. package/dist/cjs/state/modules/element-trees.js +2 -0
  128. package/dist/cjs/state/modules/element-trees.js.map +1 -1
  129. package/dist/cjs/state/modules/is-in-builder.js +2 -0
  130. package/dist/cjs/state/modules/is-in-builder.js.map +1 -1
  131. package/dist/cjs/state/modules/is-preview.js +3 -0
  132. package/dist/cjs/state/modules/is-preview.js.map +1 -1
  133. package/dist/cjs/state/modules/localized-resources-map.js +2 -0
  134. package/dist/cjs/state/modules/localized-resources-map.js.map +1 -1
  135. package/dist/cjs/state/modules/pointer.js +2 -0
  136. package/dist/cjs/state/modules/pointer.js.map +1 -1
  137. package/dist/cjs/state/modules/prop-controller-handles.js +2 -0
  138. package/dist/cjs/state/modules/prop-controller-handles.js.map +1 -1
  139. package/dist/cjs/state/modules/prop-controllers.js +2 -0
  140. package/dist/cjs/state/modules/prop-controllers.js.map +1 -1
  141. package/dist/cjs/state/modules/react-components.js +2 -0
  142. package/dist/cjs/state/modules/react-components.js.map +1 -1
  143. package/dist/cjs/state/modules/read-only-documents.js +2 -0
  144. package/dist/cjs/state/modules/read-only-documents.js.map +1 -1
  145. package/dist/cjs/state/modules/read-write-documents.js +2 -0
  146. package/dist/cjs/state/modules/read-write-documents.js.map +1 -1
  147. package/dist/cjs/state/react-builder-preview.js +32 -38
  148. package/dist/cjs/state/react-builder-preview.js.map +1 -1
  149. package/dist/cjs/state/react-page.js +15 -19
  150. package/dist/cjs/state/react-page.js.map +1 -1
  151. package/dist/cjs/state/toolkit.js +54 -0
  152. package/dist/cjs/state/toolkit.js.map +1 -0
  153. package/dist/cjs/testing/fixtures.js +38 -0
  154. package/dist/cjs/testing/fixtures.js.map +1 -0
  155. package/dist/cjs/utils/esm-compat.js +29 -0
  156. package/dist/cjs/utils/esm-compat.js.map +1 -0
  157. package/dist/esm/api/react.js +10 -14
  158. package/dist/esm/api/react.js.map +1 -1
  159. package/dist/esm/api/site-version/index.js +75 -0
  160. package/dist/esm/api/site-version/index.js.map +1 -0
  161. package/dist/esm/api-handler/handlers/manifest.js +3 -4
  162. package/dist/esm/api-handler/handlers/manifest.js.map +1 -1
  163. package/dist/esm/api-handler/handlers/redirect-live.js +27 -0
  164. package/dist/esm/api-handler/handlers/redirect-live.js.map +1 -0
  165. package/dist/esm/api-handler/index.js +7 -6
  166. package/dist/esm/api-handler/index.js.map +1 -1
  167. package/dist/esm/api-handler/node-request-response.js +73 -0
  168. package/dist/esm/api-handler/node-request-response.js.map +1 -0
  169. package/dist/esm/api-handler/preview.js +9 -0
  170. package/dist/esm/api-handler/preview.js.map +1 -0
  171. package/dist/esm/api-handler/request-response.js +9 -0
  172. package/dist/esm/api-handler/request-response.js.map +1 -1
  173. package/dist/esm/client/index.js +65 -58
  174. package/dist/esm/client/index.js.map +1 -1
  175. package/dist/esm/components/builtin/Box/animations.js.map +1 -1
  176. package/dist/esm/components/builtin/Form/components/Field/services/responsiveField.js.map +1 -1
  177. package/dist/esm/components/builtin/Root/Root.js +4 -4
  178. package/dist/esm/components/builtin/Root/Root.js.map +1 -1
  179. package/dist/esm/components/builtin/Video/Video.js +1 -1
  180. package/dist/esm/components/builtin/Video/Video.js.map +1 -1
  181. package/dist/esm/components/hooks/useMediaQuery.js +1 -2
  182. package/dist/esm/components/hooks/useMediaQuery.js.map +1 -1
  183. package/dist/esm/components/shared/BackgroundsContainer/components/BackgroundVideo/index.js +1 -1
  184. package/dist/esm/components/shared/BackgroundsContainer/components/BackgroundVideo/index.js.map +1 -1
  185. package/dist/esm/components/shared/BackgroundsContainer/components/Backgrounds/index.js.map +1 -1
  186. package/dist/esm/components/shared/Link/index.js +13 -28
  187. package/dist/esm/components/shared/Link/index.js.map +1 -1
  188. package/dist/esm/components/shared/react-player.js +7 -0
  189. package/dist/esm/components/shared/react-player.js.map +1 -0
  190. package/dist/esm/components/utils/responsive-style.js.map +1 -1
  191. package/dist/esm/css/border-radius.js.map +1 -1
  192. package/dist/esm/css/border.js.map +1 -1
  193. package/dist/esm/css/margin.js.map +1 -1
  194. package/dist/esm/css/padding.js.map +1 -1
  195. package/dist/esm/next/api-handler/config/app-router.js +12 -10
  196. package/dist/esm/next/api-handler/config/app-router.js.map +1 -1
  197. package/dist/esm/next/api-handler/config/pages-router.js +9 -69
  198. package/dist/esm/next/api-handler/config/pages-router.js.map +1 -1
  199. package/dist/esm/next/api-handler/handlers/app-router-redirect-preview.js +64 -0
  200. package/dist/esm/next/api-handler/handlers/app-router-redirect-preview.js.map +1 -0
  201. package/dist/esm/next/api-handler/handlers/pages-router-redirect-preview.js +52 -0
  202. package/dist/esm/next/api-handler/handlers/pages-router-redirect-preview.js.map +1 -0
  203. package/dist/esm/next/api-handler/index.js +4 -3
  204. package/dist/esm/next/api-handler/index.js.map +1 -1
  205. package/dist/esm/next/api-handler/preview.js +15 -0
  206. package/dist/esm/next/api-handler/preview.js.map +1 -0
  207. package/dist/esm/next/app-router-site-version.js +16 -0
  208. package/dist/esm/next/app-router-site-version.js.map +1 -0
  209. package/dist/esm/next/client.js +10 -4
  210. package/dist/esm/next/client.js.map +1 -1
  211. package/dist/esm/next/components/framework-provider/index.js +9 -2
  212. package/dist/esm/next/components/framework-provider/index.js.map +1 -1
  213. package/dist/esm/next/components/framework-provider/link.js +35 -0
  214. package/dist/esm/next/components/framework-provider/link.js.map +1 -0
  215. package/dist/esm/next/components/page.js +2 -4
  216. package/dist/esm/next/components/page.js.map +1 -1
  217. package/dist/esm/next/components/tests/__fixtures__/element-data/button-component.js +83 -0
  218. package/dist/esm/next/components/tests/__fixtures__/element-data/button-component.js.map +1 -0
  219. package/dist/esm/next/components/tests/__fixtures__/element-data/image-component.js +10 -0
  220. package/dist/esm/next/components/tests/__fixtures__/element-data/image-component.js.map +1 -1
  221. package/dist/esm/next/components/tests/__fixtures__/resources/index.js +1 -0
  222. package/dist/esm/next/components/tests/__fixtures__/resources/index.js.map +1 -1
  223. package/dist/esm/next/components/tests/__fixtures__/resources/page-pathname-slices.js +9 -0
  224. package/dist/esm/next/components/tests/__fixtures__/resources/page-pathname-slices.js.map +1 -0
  225. package/dist/esm/next/document.js +2 -1
  226. package/dist/esm/next/document.js.map +1 -1
  227. package/dist/esm/next/index.js.map +1 -1
  228. package/dist/esm/next/middleware/request-utils.js +14 -17
  229. package/dist/esm/next/middleware/request-utils.js.map +1 -1
  230. package/dist/esm/next/root-style-registry.js +11 -23
  231. package/dist/esm/next/root-style-registry.js.map +1 -1
  232. package/dist/esm/next/server.js +1 -1
  233. package/dist/esm/next/server.js.map +1 -1
  234. package/dist/esm/next/testing/page-rendering.js +2 -2
  235. package/dist/esm/next/testing/page-rendering.js.map +1 -1
  236. package/dist/esm/next/testing/react-provider.js +2 -2
  237. package/dist/esm/next/testing/react-provider.js.map +1 -1
  238. package/dist/esm/next/tests/test-utils.js +7 -5
  239. package/dist/esm/next/tests/test-utils.js.map +1 -1
  240. package/dist/esm/runtimes/react/components/RuntimeProvider.js +9 -7
  241. package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
  242. package/dist/esm/runtimes/react/components/framework-context.js +24 -3
  243. package/dist/esm/runtimes/react/components/framework-context.js.map +1 -1
  244. package/dist/esm/runtimes/react/components/page/index.js +19 -17
  245. package/dist/esm/runtimes/react/components/page/index.js.map +1 -1
  246. package/dist/esm/runtimes/react/components/{draft-switcher/draft-switcher.js → preview-switcher/preview-switcher.js} +8 -18
  247. package/dist/esm/runtimes/react/components/preview-switcher/preview-switcher.js.map +1 -0
  248. package/dist/esm/runtimes/react/components/{draft-switcher/draft-toolbar.js → preview-switcher/preview-toolbar.js} +13 -5
  249. package/dist/esm/runtimes/react/components/preview-switcher/preview-toolbar.js.map +1 -0
  250. package/dist/esm/runtimes/react/controls/style.js.map +1 -1
  251. package/dist/esm/runtimes/react/hooks/makeswift-api.js +1 -2
  252. package/dist/esm/runtimes/react/hooks/makeswift-api.js.map +1 -1
  253. package/dist/esm/runtimes/react/hooks/use-selector.js +1 -1
  254. package/dist/esm/runtimes/react/hooks/use-selector.js.map +1 -1
  255. package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js +1 -1
  256. package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -1
  257. package/dist/esm/runtimes/react/hooks/use-universal-dispatch.js.map +1 -1
  258. package/dist/esm/runtimes/react/host-api-client.js +7 -2
  259. package/dist/esm/runtimes/react/host-api-client.js.map +1 -1
  260. package/dist/esm/runtimes/react/root-style-registry.js +37 -13
  261. package/dist/esm/runtimes/react/root-style-registry.js.map +1 -1
  262. package/dist/esm/runtimes/react/use-global-style.js +1 -1
  263. package/dist/esm/runtimes/react/use-global-style.js.map +1 -1
  264. package/dist/esm/runtimes/react/use-style.js +1 -1
  265. package/dist/esm/runtimes/react/use-style.js.map +1 -1
  266. package/dist/esm/state/actions.js +5 -0
  267. package/dist/esm/state/actions.js.map +1 -1
  268. package/dist/esm/state/makeswift-api-client.js +42 -58
  269. package/dist/esm/state/makeswift-api-client.js.map +1 -1
  270. package/dist/esm/state/mixins/setup-teardown.js.map +1 -1
  271. package/dist/esm/state/modules/api-resources.js +3 -1
  272. package/dist/esm/state/modules/api-resources.js.map +1 -1
  273. package/dist/esm/state/modules/box-models.js +3 -1
  274. package/dist/esm/state/modules/box-models.js.map +1 -1
  275. package/dist/esm/state/modules/breakpoints.js +4 -2
  276. package/dist/esm/state/modules/breakpoints.js.map +1 -1
  277. package/dist/esm/state/modules/builder-edit-mode.js +3 -1
  278. package/dist/esm/state/modules/builder-edit-mode.js.map +1 -1
  279. package/dist/esm/state/modules/components-meta.js +3 -1
  280. package/dist/esm/state/modules/components-meta.js.map +1 -1
  281. package/dist/esm/state/modules/element-imperative-handles.js +3 -1
  282. package/dist/esm/state/modules/element-imperative-handles.js.map +1 -1
  283. package/dist/esm/state/modules/element-trees.js +3 -1
  284. package/dist/esm/state/modules/element-trees.js.map +1 -1
  285. package/dist/esm/state/modules/is-in-builder.js +3 -1
  286. package/dist/esm/state/modules/is-in-builder.js.map +1 -1
  287. package/dist/esm/state/modules/is-preview.js +3 -0
  288. package/dist/esm/state/modules/is-preview.js.map +1 -1
  289. package/dist/esm/state/modules/localized-resources-map.js +3 -1
  290. package/dist/esm/state/modules/localized-resources-map.js.map +1 -1
  291. package/dist/esm/state/modules/pointer.js +3 -1
  292. package/dist/esm/state/modules/pointer.js.map +1 -1
  293. package/dist/esm/state/modules/prop-controller-handles.js +3 -1
  294. package/dist/esm/state/modules/prop-controller-handles.js.map +1 -1
  295. package/dist/esm/state/modules/prop-controllers.js +3 -1
  296. package/dist/esm/state/modules/prop-controllers.js.map +1 -1
  297. package/dist/esm/state/modules/react-components.js +3 -1
  298. package/dist/esm/state/modules/react-components.js.map +1 -1
  299. package/dist/esm/state/modules/read-only-documents.js +6 -1
  300. package/dist/esm/state/modules/read-only-documents.js.map +1 -1
  301. package/dist/esm/state/modules/read-write-documents.js +3 -1
  302. package/dist/esm/state/modules/read-write-documents.js.map +1 -1
  303. package/dist/esm/state/react-builder-preview.js +33 -40
  304. package/dist/esm/state/react-builder-preview.js.map +1 -1
  305. package/dist/esm/state/react-page.js +16 -21
  306. package/dist/esm/state/react-page.js.map +1 -1
  307. package/dist/esm/state/toolkit.js +28 -0
  308. package/dist/esm/state/toolkit.js.map +1 -0
  309. package/dist/esm/testing/fixtures.js +13 -0
  310. package/dist/esm/testing/fixtures.js.map +1 -0
  311. package/dist/esm/utils/esm-compat.js +5 -0
  312. package/dist/esm/utils/esm-compat.js.map +1 -0
  313. package/dist/types/api/graphql/documents/queries.d.ts +7 -7
  314. package/dist/types/api/graphql/documents/queries.d.ts.map +1 -1
  315. package/dist/types/api/graphql/generated/fragment-document-nodes.d.ts.map +1 -1
  316. package/dist/types/api/react.d.ts +3 -4
  317. package/dist/types/api/react.d.ts.map +1 -1
  318. package/dist/types/api/site-version/index.d.ts +19 -0
  319. package/dist/types/api/site-version/index.d.ts.map +1 -0
  320. package/dist/types/api/site-version/site-version.test.d.ts +2 -0
  321. package/dist/types/api/site-version/site-version.test.d.ts.map +1 -0
  322. package/dist/types/api-handler/handlers/manifest.d.ts +1 -3
  323. package/dist/types/api-handler/handlers/manifest.d.ts.map +1 -1
  324. package/dist/types/api-handler/handlers/redirect-live.d.ts +6 -0
  325. package/dist/types/api-handler/handlers/redirect-live.d.ts.map +1 -0
  326. package/dist/types/api-handler/index.d.ts +5 -5
  327. package/dist/types/api-handler/index.d.ts.map +1 -1
  328. package/dist/types/api-handler/node-request-response.d.ts +8 -0
  329. package/dist/types/api-handler/node-request-response.d.ts.map +1 -0
  330. package/dist/types/api-handler/node-request-response.test.d.ts +2 -0
  331. package/dist/types/api-handler/node-request-response.test.d.ts.map +1 -0
  332. package/dist/types/api-handler/preview.d.ts +5 -0
  333. package/dist/types/api-handler/preview.d.ts.map +1 -0
  334. package/dist/types/api-handler/request-response.d.ts +1 -0
  335. package/dist/types/api-handler/request-response.d.ts.map +1 -1
  336. package/dist/types/client/index.d.ts +174 -165
  337. package/dist/types/client/index.d.ts.map +1 -1
  338. package/dist/types/components/builtin/Box/Box.d.ts +15 -147
  339. package/dist/types/components/builtin/Box/Box.d.ts.map +1 -1
  340. package/dist/types/components/builtin/Box/components/Placeholder/index.d.ts +0 -1
  341. package/dist/types/components/builtin/Box/components/Placeholder/index.d.ts.map +1 -1
  342. package/dist/types/components/builtin/Button/Button.d.ts +4 -70
  343. package/dist/types/components/builtin/Button/Button.d.ts.map +1 -1
  344. package/dist/types/components/builtin/Carousel/Carousel.d.ts +0 -1
  345. package/dist/types/components/builtin/Carousel/Carousel.d.ts.map +1 -1
  346. package/dist/types/components/builtin/Countdown/Countdown.d.ts +0 -1
  347. package/dist/types/components/builtin/Countdown/Countdown.d.ts.map +1 -1
  348. package/dist/types/components/builtin/Divider/Divider.d.ts +0 -1
  349. package/dist/types/components/builtin/Divider/Divider.d.ts.map +1 -1
  350. package/dist/types/components/builtin/Embed/Embed.d.ts +0 -1
  351. package/dist/types/components/builtin/Embed/Embed.d.ts.map +1 -1
  352. package/dist/types/components/builtin/Form/Form.d.ts +0 -1
  353. package/dist/types/components/builtin/Form/Form.d.ts.map +1 -1
  354. package/dist/types/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
  355. package/dist/types/components/builtin/Form/components/Field/components/Checkbox/index.d.ts.map +1 -1
  356. package/dist/types/components/builtin/Form/components/Field/components/CheckboxTableField/index.d.ts +0 -1
  357. package/dist/types/components/builtin/Form/components/Field/components/CheckboxTableField/index.d.ts.map +1 -1
  358. package/dist/types/components/builtin/Form/components/Field/components/EmailTableField/index.d.ts +0 -1
  359. package/dist/types/components/builtin/Form/components/Field/components/EmailTableField/index.d.ts.map +1 -1
  360. package/dist/types/components/builtin/Form/components/Field/components/Input/index.d.ts +0 -1
  361. package/dist/types/components/builtin/Form/components/Field/components/Input/index.d.ts.map +1 -1
  362. package/dist/types/components/builtin/Form/components/Field/components/LongTextTableField/index.d.ts +0 -1
  363. package/dist/types/components/builtin/Form/components/Field/components/LongTextTableField/index.d.ts.map +1 -1
  364. package/dist/types/components/builtin/Form/components/Field/components/NumberTableField/index.d.ts +0 -1
  365. package/dist/types/components/builtin/Form/components/Field/components/NumberTableField/index.d.ts.map +1 -1
  366. package/dist/types/components/builtin/Form/components/Field/components/PhoneNumberTableField/index.d.ts +0 -1
  367. package/dist/types/components/builtin/Form/components/Field/components/PhoneNumberTableField/index.d.ts.map +1 -1
  368. package/dist/types/components/builtin/Form/components/Field/components/PlaceholderTableField/index.d.ts +0 -1
  369. package/dist/types/components/builtin/Form/components/Field/components/PlaceholderTableField/index.d.ts.map +1 -1
  370. package/dist/types/components/builtin/Form/components/Field/components/RadioButton/index.d.ts +1 -1
  371. package/dist/types/components/builtin/Form/components/Field/components/RadioButton/index.d.ts.map +1 -1
  372. package/dist/types/components/builtin/Form/components/Field/components/SingleLineTextTableField/index.d.ts +0 -1
  373. package/dist/types/components/builtin/Form/components/Field/components/SingleLineTextTableField/index.d.ts.map +1 -1
  374. package/dist/types/components/builtin/Form/components/Field/components/SingleSelectTableField/components/TableColumnSingleSelect/index.d.ts +0 -1
  375. package/dist/types/components/builtin/Form/components/Field/components/SingleSelectTableField/components/TableColumnSingleSelect/index.d.ts.map +1 -1
  376. package/dist/types/components/builtin/Form/components/Field/components/TextArea/index.d.ts +0 -1
  377. package/dist/types/components/builtin/Form/components/Field/components/TextArea/index.d.ts.map +1 -1
  378. package/dist/types/components/builtin/Form/components/Field/components/URLTableField/index.d.ts +0 -1
  379. package/dist/types/components/builtin/Form/components/Field/components/URLTableField/index.d.ts.map +1 -1
  380. package/dist/types/components/builtin/Form/components/Field/index.d.ts +0 -1
  381. package/dist/types/components/builtin/Form/components/Field/index.d.ts.map +1 -1
  382. package/dist/types/components/builtin/Form/components/Field/services/responsiveField.d.ts +1 -1
  383. package/dist/types/components/builtin/Form/components/Field/services/responsiveField.d.ts.map +1 -1
  384. package/dist/types/components/builtin/Form/components/Placeholder/index.d.ts +0 -1
  385. package/dist/types/components/builtin/Form/components/Placeholder/index.d.ts.map +1 -1
  386. package/dist/types/components/builtin/Form/components/Spinner/index.d.ts +0 -1
  387. package/dist/types/components/builtin/Form/components/Spinner/index.d.ts.map +1 -1
  388. package/dist/types/components/builtin/Form/context/FormContext.d.ts +0 -1
  389. package/dist/types/components/builtin/Form/context/FormContext.d.ts.map +1 -1
  390. package/dist/types/components/builtin/Image/Image.d.ts +0 -1
  391. package/dist/types/components/builtin/Image/Image.d.ts.map +1 -1
  392. package/dist/types/components/builtin/Navigation/Navigation.d.ts +0 -1
  393. package/dist/types/components/builtin/Navigation/Navigation.d.ts.map +1 -1
  394. package/dist/types/components/builtin/Navigation/components/LinksPlaceholder/index.d.ts +0 -1
  395. package/dist/types/components/builtin/Navigation/components/LinksPlaceholder/index.d.ts.map +1 -1
  396. package/dist/types/components/builtin/Navigation/components/MobileMenu/index.d.ts +0 -1
  397. package/dist/types/components/builtin/Navigation/components/MobileMenu/index.d.ts.map +1 -1
  398. package/dist/types/components/builtin/Root/Root.d.ts +1 -2
  399. package/dist/types/components/builtin/Root/Root.d.ts.map +1 -1
  400. package/dist/types/components/builtin/Root/components/Placeholder/index.d.ts +0 -1
  401. package/dist/types/components/builtin/Root/components/Placeholder/index.d.ts.map +1 -1
  402. package/dist/types/components/builtin/SocialLinks/SocialLinks.d.ts +0 -1
  403. package/dist/types/components/builtin/SocialLinks/SocialLinks.d.ts.map +1 -1
  404. package/dist/types/components/builtin/SocialLinks/components/SocialLinksPlaceholder/index.d.ts +0 -1
  405. package/dist/types/components/builtin/SocialLinks/components/SocialLinksPlaceholder/index.d.ts.map +1 -1
  406. package/dist/types/components/builtin/Text/Text.d.ts +0 -1
  407. package/dist/types/components/builtin/Text/Text.d.ts.map +1 -1
  408. package/dist/types/components/builtin/Video/Video.d.ts +0 -1
  409. package/dist/types/components/builtin/Video/Video.d.ts.map +1 -1
  410. package/dist/types/components/hooks/useMediaQuery.d.ts.map +1 -1
  411. package/dist/types/components/shared/BackgroundsContainer/components/BackgroundVideo/index.d.ts +0 -1
  412. package/dist/types/components/shared/BackgroundsContainer/components/BackgroundVideo/index.d.ts.map +1 -1
  413. package/dist/types/components/shared/BackgroundsContainer/components/Backgrounds/index.d.ts +0 -1
  414. package/dist/types/components/shared/BackgroundsContainer/components/Backgrounds/index.d.ts.map +1 -1
  415. package/dist/types/components/shared/ErrorBoundary.d.ts +0 -1
  416. package/dist/types/components/shared/ErrorBoundary.d.ts.map +1 -1
  417. package/dist/types/components/shared/FallbackComponent/FallbackComponent.d.ts +0 -1
  418. package/dist/types/components/shared/FallbackComponent/FallbackComponent.d.ts.map +1 -1
  419. package/dist/types/components/shared/Link/index.d.ts.map +1 -1
  420. package/dist/types/components/shared/react-player.d.ts +3 -0
  421. package/dist/types/components/shared/react-player.d.ts.map +1 -0
  422. package/dist/types/components/utils/columns.d.ts.map +1 -1
  423. package/dist/types/components/utils/responsive-style.d.ts +1 -1
  424. package/dist/types/components/utils/responsive-style.d.ts.map +1 -1
  425. package/dist/types/controls/control.d.ts +1 -25
  426. package/dist/types/controls/control.d.ts.map +1 -1
  427. package/dist/types/controls/link.d.ts +3 -3
  428. package/dist/types/controls/link.d.ts.map +1 -1
  429. package/dist/types/controls/rich-text/control.d.ts.map +1 -1
  430. package/dist/types/controls/rich-text-v2/control.d.ts +13 -13
  431. package/dist/types/controls/rich-text-v2/control.d.ts.map +1 -1
  432. package/dist/types/controls/rich-text-v2/plugin.d.ts +2 -2
  433. package/dist/types/controls/rich-text-v2/plugin.d.ts.map +1 -1
  434. package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts +556 -12
  435. package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
  436. package/dist/types/css/border-radius.d.ts +1 -1
  437. package/dist/types/css/border-radius.d.ts.map +1 -1
  438. package/dist/types/css/border.d.ts +1 -1
  439. package/dist/types/css/border.d.ts.map +1 -1
  440. package/dist/types/css/margin.d.ts +1 -1
  441. package/dist/types/css/margin.d.ts.map +1 -1
  442. package/dist/types/css/padding.d.ts +1 -1
  443. package/dist/types/css/padding.d.ts.map +1 -1
  444. package/dist/types/next/api-handler/config/app-router.d.ts +10 -8
  445. package/dist/types/next/api-handler/config/app-router.d.ts.map +1 -1
  446. package/dist/types/next/api-handler/config/pages-router.d.ts +3 -2
  447. package/dist/types/next/api-handler/config/pages-router.d.ts.map +1 -1
  448. package/dist/types/next/api-handler/handlers/app-router-redirect-preview.d.ts +5 -0
  449. package/dist/types/next/api-handler/handlers/app-router-redirect-preview.d.ts.map +1 -0
  450. package/dist/types/next/api-handler/handlers/app-router-redirect-preview.test.d.ts +2 -0
  451. package/dist/types/next/api-handler/handlers/app-router-redirect-preview.test.d.ts.map +1 -0
  452. package/dist/types/next/api-handler/handlers/pages-router-redirect-preview.d.ts +4 -0
  453. package/dist/types/next/api-handler/handlers/pages-router-redirect-preview.d.ts.map +1 -0
  454. package/dist/types/next/api-handler/index.d.ts +1 -1
  455. package/dist/types/next/api-handler/index.d.ts.map +1 -1
  456. package/dist/types/next/api-handler/preview.d.ts +8 -0
  457. package/dist/types/next/api-handler/preview.d.ts.map +1 -0
  458. package/dist/types/next/app-router-site-version.d.ts +3 -0
  459. package/dist/types/next/app-router-site-version.d.ts.map +1 -0
  460. package/dist/types/next/client.d.ts +3 -3
  461. package/dist/types/next/client.d.ts.map +1 -1
  462. package/dist/types/next/components/framework-provider/index.d.ts.map +1 -1
  463. package/dist/types/next/components/framework-provider/link.d.ts +2 -0
  464. package/dist/types/next/components/framework-provider/link.d.ts.map +1 -0
  465. package/dist/types/next/components/page.d.ts +2 -7
  466. package/dist/types/next/components/page.d.ts.map +1 -1
  467. package/dist/types/next/components/tests/__fixtures__/element-data/box-component.d.ts.map +1 -1
  468. package/dist/types/next/components/tests/__fixtures__/element-data/button-component.d.ts +9 -0
  469. package/dist/types/next/components/tests/__fixtures__/element-data/button-component.d.ts.map +1 -0
  470. package/dist/types/next/components/tests/__fixtures__/element-data/image-component.d.ts.map +1 -1
  471. package/dist/types/next/components/tests/__fixtures__/resources/index.d.ts +1 -0
  472. package/dist/types/next/components/tests/__fixtures__/resources/index.d.ts.map +1 -1
  473. package/dist/types/next/components/tests/__fixtures__/resources/page-pathname-slices.d.ts +3 -0
  474. package/dist/types/next/components/tests/__fixtures__/resources/page-pathname-slices.d.ts.map +1 -0
  475. package/dist/types/next/components/tests/components/button-component-rendering.test.d.ts +3 -0
  476. package/dist/types/next/components/tests/components/button-component-rendering.test.d.ts.map +1 -0
  477. package/dist/types/next/components/tests/controls/color-control/fixtures.d.ts.map +1 -1
  478. package/dist/types/next/components/tests/controls/rich-text-v2-control/fixtures.d.ts.map +1 -1
  479. package/dist/types/next/components/tests/controls/style-control/fixtures.d.ts.map +1 -1
  480. package/dist/types/next/components/tests/prop-controllers/page-prop-controller.d.ts +3 -16
  481. package/dist/types/next/components/tests/prop-controllers/page-prop-controller.d.ts.map +1 -1
  482. package/dist/types/next/document.d.ts.map +1 -1
  483. package/dist/types/next/index.d.ts +1 -1
  484. package/dist/types/next/index.d.ts.map +1 -1
  485. package/dist/types/next/middleware/request-utils.d.ts +1 -0
  486. package/dist/types/next/middleware/request-utils.d.ts.map +1 -1
  487. package/dist/types/next/root-style-registry.d.ts +3 -12
  488. package/dist/types/next/root-style-registry.d.ts.map +1 -1
  489. package/dist/types/next/server.d.ts +1 -1
  490. package/dist/types/next/server.d.ts.map +1 -1
  491. package/dist/types/next/testing/element-data.d.ts +13 -13
  492. package/dist/types/next/testing/react-provider.d.ts +3 -3
  493. package/dist/types/next/testing/react-provider.d.ts.map +1 -1
  494. package/dist/types/next/tests/server.api-handler-app-router-redirect-preview.test.d.ts +2 -0
  495. package/dist/types/next/tests/server.api-handler-app-router-redirect-preview.test.d.ts.map +1 -0
  496. package/dist/types/next/tests/server.api-handler-pages-router-redirect-preview.test.d.ts +2 -0
  497. package/dist/types/next/tests/server.api-handler-pages-router-redirect-preview.test.d.ts.map +1 -0
  498. package/dist/types/next/tests/server.api-handler-redirect-live.test.d.ts +2 -0
  499. package/dist/types/next/tests/server.api-handler-redirect-live.test.d.ts.map +1 -0
  500. package/dist/types/next/tests/test-utils.d.ts.map +1 -1
  501. package/dist/types/runtimes/react/components/Document.d.ts +0 -1
  502. package/dist/types/runtimes/react/components/Document.d.ts.map +1 -1
  503. package/dist/types/runtimes/react/components/DocumentRoot.d.ts +0 -1
  504. package/dist/types/runtimes/react/components/DocumentRoot.d.ts.map +1 -1
  505. package/dist/types/runtimes/react/components/Element.d.ts +0 -1
  506. package/dist/types/runtimes/react/components/Element.d.ts.map +1 -1
  507. package/dist/types/runtimes/react/components/ElementData.d.ts +0 -1
  508. package/dist/types/runtimes/react/components/ElementData.d.ts.map +1 -1
  509. package/dist/types/runtimes/react/components/ElementReference.d.ts +0 -1
  510. package/dist/types/runtimes/react/components/ElementReference.d.ts.map +1 -1
  511. package/dist/types/runtimes/react/components/MakeswiftComponent.d.ts +0 -1
  512. package/dist/types/runtimes/react/components/MakeswiftComponent.d.ts.map +1 -1
  513. package/dist/types/runtimes/react/components/RuntimeProvider.d.ts +3 -2
  514. package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
  515. package/dist/types/runtimes/react/components/Slot.d.ts.map +1 -1
  516. package/dist/types/runtimes/react/components/framework-context.d.ts +13 -1
  517. package/dist/types/runtimes/react/components/framework-context.d.ts.map +1 -1
  518. package/dist/types/runtimes/react/components/page/HeadSnippet.d.ts +0 -1
  519. package/dist/types/runtimes/react/components/page/HeadSnippet.d.ts.map +1 -1
  520. package/dist/types/runtimes/react/components/page/Page.d.ts +0 -1
  521. package/dist/types/runtimes/react/components/page/Page.d.ts.map +1 -1
  522. package/dist/types/runtimes/react/components/page/PageHead.d.ts +0 -1
  523. package/dist/types/runtimes/react/components/page/PageHead.d.ts.map +1 -1
  524. package/dist/types/runtimes/react/components/page/index.d.ts +23 -3
  525. package/dist/types/runtimes/react/components/page/index.d.ts.map +1 -1
  526. package/dist/types/runtimes/react/components/preview-switcher/preview-switcher.d.ts +4 -0
  527. package/dist/types/runtimes/react/components/preview-switcher/preview-switcher.d.ts.map +1 -0
  528. package/dist/types/runtimes/react/components/preview-switcher/preview-toolbar.d.ts +2 -0
  529. package/dist/types/runtimes/react/components/preview-switcher/preview-toolbar.d.ts.map +1 -0
  530. package/dist/types/runtimes/react/components/render-hook.d.ts +0 -1
  531. package/dist/types/runtimes/react/components/render-hook.d.ts.map +1 -1
  532. package/dist/types/runtimes/react/controls/control.d.ts +0 -1
  533. package/dist/types/runtimes/react/controls/control.d.ts.map +1 -1
  534. package/dist/types/runtimes/react/controls/group.d.ts +0 -1
  535. package/dist/types/runtimes/react/controls/group.d.ts.map +1 -1
  536. package/dist/types/runtimes/react/controls/rich-text/EditableText/editable-text.d.ts +0 -1
  537. package/dist/types/runtimes/react/controls/rich-text/EditableText/editable-text.d.ts.map +1 -1
  538. package/dist/types/runtimes/react/controls/rich-text/ReadOnlyText.d.ts +0 -1
  539. package/dist/types/runtimes/react/controls/rich-text/ReadOnlyText.d.ts.map +1 -1
  540. package/dist/types/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts +0 -1
  541. package/dist/types/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts.map +1 -1
  542. package/dist/types/runtimes/react/controls/style.d.ts +1 -1
  543. package/dist/types/runtimes/react/controls/style.d.ts.map +1 -1
  544. package/dist/types/runtimes/react/controls.d.ts +0 -1
  545. package/dist/types/runtimes/react/controls.d.ts.map +1 -1
  546. package/dist/types/runtimes/react/hooks/makeswift-api.d.ts.map +1 -1
  547. package/dist/types/runtimes/react/hooks/use-disable-register-element.d.ts +0 -1
  548. package/dist/types/runtimes/react/hooks/use-disable-register-element.d.ts.map +1 -1
  549. package/dist/types/runtimes/react/hooks/use-document-context.d.ts +0 -1
  550. package/dist/types/runtimes/react/hooks/use-document-context.d.ts.map +1 -1
  551. package/dist/types/runtimes/react/hooks/use-document-cycles.d.ts +0 -1
  552. package/dist/types/runtimes/react/hooks/use-document-cycles.d.ts.map +1 -1
  553. package/dist/types/runtimes/react/hooks/use-react-runtime.d.ts +0 -1
  554. package/dist/types/runtimes/react/hooks/use-react-runtime.d.ts.map +1 -1
  555. package/dist/types/runtimes/react/hooks/use-selector.d.ts.map +1 -1
  556. package/dist/types/runtimes/react/hooks/use-store.d.ts +25 -2
  557. package/dist/types/runtimes/react/hooks/use-store.d.ts.map +1 -1
  558. package/dist/types/runtimes/react/hooks/use-stylesheet-factory.d.ts.map +1 -1
  559. package/dist/types/runtimes/react/hooks/use-universal-dispatch.d.ts +1 -1
  560. package/dist/types/runtimes/react/hooks/use-universal-dispatch.d.ts.map +1 -1
  561. package/dist/types/runtimes/react/host-api-client.d.ts.map +1 -1
  562. package/dist/types/runtimes/react/legacy-controls.d.ts +0 -1
  563. package/dist/types/runtimes/react/legacy-controls.d.ts.map +1 -1
  564. package/dist/types/runtimes/react/root-style-registry.d.ts +30 -10
  565. package/dist/types/runtimes/react/root-style-registry.d.ts.map +1 -1
  566. package/dist/types/runtimes/react/use-global-style.d.ts.map +1 -1
  567. package/dist/types/runtimes/react/use-style.d.ts +1 -1
  568. package/dist/types/runtimes/react/use-style.d.ts.map +1 -1
  569. package/dist/types/slate/BlockPlugin/index.d.ts +5 -5
  570. package/dist/types/slate/BlockPlugin/utils/location.d.ts.map +1 -1
  571. package/dist/types/slate/InlineModePlugin/index.d.ts +41 -41
  572. package/dist/types/slate/InlinePlugin/getValue.d.ts.map +1 -1
  573. package/dist/types/slate/InlinePlugin/index.d.ts +5 -6
  574. package/dist/types/slate/InlinePlugin/index.d.ts.map +1 -1
  575. package/dist/types/slate/InlinePlugin/onChange.d.ts.map +1 -1
  576. package/dist/types/slate/LinkPlugin/getValue.d.ts +1 -1
  577. package/dist/types/slate/LinkPlugin/getValue.d.ts.map +1 -1
  578. package/dist/types/slate/LinkPlugin/index.d.ts +3 -4
  579. package/dist/types/slate/LinkPlugin/index.d.ts.map +1 -1
  580. package/dist/types/slate/LinkPlugin/onChange.d.ts.map +1 -1
  581. package/dist/types/slate/TextAlignPlugin/index.d.ts +5 -6
  582. package/dist/types/slate/TextAlignPlugin/index.d.ts.map +1 -1
  583. package/dist/types/slate/TypographyPlugin/getValue.d.ts.map +1 -1
  584. package/dist/types/slate/TypographyPlugin/index.d.ts +2 -3
  585. package/dist/types/slate/TypographyPlugin/index.d.ts.map +1 -1
  586. package/dist/types/slate/test-helpers/editor-v1.d.ts +0 -1
  587. package/dist/types/slate/test-helpers/editor-v1.d.ts.map +1 -1
  588. package/dist/types/slate/test-helpers/editor-v2-inline.d.ts +0 -1
  589. package/dist/types/slate/test-helpers/editor-v2-inline.d.ts.map +1 -1
  590. package/dist/types/slate/test-helpers/editor-v2.d.ts +0 -1
  591. package/dist/types/slate/test-helpers/editor-v2.d.ts.map +1 -1
  592. package/dist/types/slate/test-helpers/slate-test-helper.d.ts +4 -4
  593. package/dist/types/slate/test-helpers/slate-test-helper.d.ts.map +1 -1
  594. package/dist/types/slate/test-helpers/test-elements.d.ts +8 -64
  595. package/dist/types/slate/test-helpers/test-elements.d.ts.map +1 -1
  596. package/dist/types/slate/utils/editor.d.ts.map +1 -1
  597. package/dist/types/slate/utils/element.d.ts.map +1 -1
  598. package/dist/types/slate/utils/location.d.ts.map +1 -1
  599. package/dist/types/slate/utils/responsive.d.ts.map +1 -1
  600. package/dist/types/state/__tests__/actions.test.d.ts +2 -0
  601. package/dist/types/state/__tests__/actions.test.d.ts.map +1 -0
  602. package/dist/types/state/actions.d.ts +3 -2
  603. package/dist/types/state/actions.d.ts.map +1 -1
  604. package/dist/types/state/makeswift-api-client.d.ts +19 -11
  605. package/dist/types/state/makeswift-api-client.d.ts.map +1 -1
  606. package/dist/types/state/mixins/setup-teardown.d.ts +1 -1
  607. package/dist/types/state/mixins/setup-teardown.d.ts.map +1 -1
  608. package/dist/types/state/modules/api-resources.d.ts +2 -2
  609. package/dist/types/state/modules/api-resources.d.ts.map +1 -1
  610. package/dist/types/state/modules/box-models.d.ts +2 -2
  611. package/dist/types/state/modules/box-models.d.ts.map +1 -1
  612. package/dist/types/state/modules/breakpoints.d.ts +2 -2
  613. package/dist/types/state/modules/breakpoints.d.ts.map +1 -1
  614. package/dist/types/state/modules/builder-edit-mode.d.ts +2 -2
  615. package/dist/types/state/modules/builder-edit-mode.d.ts.map +1 -1
  616. package/dist/types/state/modules/components-meta.d.ts +2 -2
  617. package/dist/types/state/modules/components-meta.d.ts.map +1 -1
  618. package/dist/types/state/modules/element-imperative-handles.d.ts +2 -2
  619. package/dist/types/state/modules/element-imperative-handles.d.ts.map +1 -1
  620. package/dist/types/state/modules/element-trees.d.ts +2 -2
  621. package/dist/types/state/modules/element-trees.d.ts.map +1 -1
  622. package/dist/types/state/modules/is-in-builder.d.ts +2 -2
  623. package/dist/types/state/modules/is-in-builder.d.ts.map +1 -1
  624. package/dist/types/state/modules/is-preview.d.ts +2 -2
  625. package/dist/types/state/modules/is-preview.d.ts.map +1 -1
  626. package/dist/types/state/modules/localized-resources-map.d.ts +2 -2
  627. package/dist/types/state/modules/localized-resources-map.d.ts.map +1 -1
  628. package/dist/types/state/modules/pointer.d.ts +2 -2
  629. package/dist/types/state/modules/pointer.d.ts.map +1 -1
  630. package/dist/types/state/modules/prop-controller-handles.d.ts +2 -2
  631. package/dist/types/state/modules/prop-controller-handles.d.ts.map +1 -1
  632. package/dist/types/state/modules/prop-controllers.d.ts +2 -2
  633. package/dist/types/state/modules/prop-controllers.d.ts.map +1 -1
  634. package/dist/types/state/modules/react-components.d.ts +2 -2
  635. package/dist/types/state/modules/react-components.d.ts.map +1 -1
  636. package/dist/types/state/modules/read-only-documents.d.ts +2 -2
  637. package/dist/types/state/modules/read-only-documents.d.ts.map +1 -1
  638. package/dist/types/state/modules/read-write-documents.d.ts +2 -2
  639. package/dist/types/state/modules/read-write-documents.d.ts.map +1 -1
  640. package/dist/types/state/react-builder-preview.d.ts +57 -10
  641. package/dist/types/state/react-builder-preview.d.ts.map +1 -1
  642. package/dist/types/state/react-page.d.ts +67 -36
  643. package/dist/types/state/react-page.d.ts.map +1 -1
  644. package/dist/types/state/toolkit.d.ts +11 -0
  645. package/dist/types/state/toolkit.d.ts.map +1 -0
  646. package/dist/types/testing/fixtures.d.ts +7 -0
  647. package/dist/types/testing/fixtures.d.ts.map +1 -0
  648. package/dist/types/utils/clamp.d.ts.map +1 -1
  649. package/dist/types/utils/esm-compat.d.ts +2 -0
  650. package/dist/types/utils/esm-compat.d.ts.map +1 -0
  651. package/dist/types/utils/keys.d.ts.map +1 -1
  652. package/package.json +13 -14
  653. package/dist/cjs/api/site-version.js +0 -42
  654. package/dist/cjs/api/site-version.js.map +0 -1
  655. package/dist/cjs/api-handler/handlers/clear-draft.js.map +0 -1
  656. package/dist/cjs/next/api-handler/draft.js.map +0 -1
  657. package/dist/cjs/next/api-handler/handlers/redirect-draft.js.map +0 -1
  658. package/dist/cjs/next/api-handler/handlers/redirect-preview.js.map +0 -1
  659. package/dist/cjs/next/draft-mode/index.js.map +0 -1
  660. package/dist/cjs/next/preview-mode.js.map +0 -1
  661. package/dist/cjs/runtimes/react/components/draft-switcher/draft-switcher.js.map +0 -1
  662. package/dist/cjs/runtimes/react/components/draft-switcher/draft-toolbar.js.map +0 -1
  663. package/dist/esm/api/site-version.js +0 -15
  664. package/dist/esm/api/site-version.js.map +0 -1
  665. package/dist/esm/api-handler/handlers/clear-draft.js +0 -17
  666. package/dist/esm/api-handler/handlers/clear-draft.js.map +0 -1
  667. package/dist/esm/next/api-handler/draft.js +0 -14
  668. package/dist/esm/next/api-handler/draft.js.map +0 -1
  669. package/dist/esm/next/api-handler/handlers/redirect-draft.js +0 -52
  670. package/dist/esm/next/api-handler/handlers/redirect-draft.js.map +0 -1
  671. package/dist/esm/next/api-handler/handlers/redirect-preview.js +0 -37
  672. package/dist/esm/next/api-handler/handlers/redirect-preview.js.map +0 -1
  673. package/dist/esm/next/draft-mode/index.js +0 -30
  674. package/dist/esm/next/draft-mode/index.js.map +0 -1
  675. package/dist/esm/next/preview-mode.js +0 -16
  676. package/dist/esm/next/preview-mode.js.map +0 -1
  677. package/dist/esm/runtimes/react/components/draft-switcher/draft-switcher.js.map +0 -1
  678. package/dist/esm/runtimes/react/components/draft-switcher/draft-toolbar.js.map +0 -1
  679. package/dist/types/api/site-version.d.ts +0 -7
  680. package/dist/types/api/site-version.d.ts.map +0 -1
  681. package/dist/types/api-handler/handlers/clear-draft.d.ts +0 -7
  682. package/dist/types/api-handler/handlers/clear-draft.d.ts.map +0 -1
  683. package/dist/types/next/api-handler/draft.d.ts +0 -8
  684. package/dist/types/next/api-handler/draft.d.ts.map +0 -1
  685. package/dist/types/next/api-handler/handlers/redirect-draft.d.ts +0 -6
  686. package/dist/types/next/api-handler/handlers/redirect-draft.d.ts.map +0 -1
  687. package/dist/types/next/api-handler/handlers/redirect-draft.test.d.ts +0 -2
  688. package/dist/types/next/api-handler/handlers/redirect-draft.test.d.ts.map +0 -1
  689. package/dist/types/next/api-handler/handlers/redirect-preview.d.ts +0 -5
  690. package/dist/types/next/api-handler/handlers/redirect-preview.d.ts.map +0 -1
  691. package/dist/types/next/draft-mode/index.d.ts +0 -15
  692. package/dist/types/next/draft-mode/index.d.ts.map +0 -1
  693. package/dist/types/next/preview-mode.d.ts +0 -17
  694. package/dist/types/next/preview-mode.d.ts.map +0 -1
  695. package/dist/types/next/tests/server.api-handler-clear-draft.test.d.ts +0 -2
  696. package/dist/types/next/tests/server.api-handler-clear-draft.test.d.ts.map +0 -1
  697. package/dist/types/next/tests/server.api-handler-redirect-draft.test.d.ts +0 -2
  698. package/dist/types/next/tests/server.api-handler-redirect-draft.test.d.ts.map +0 -1
  699. package/dist/types/next/tests/server.api-handler-redirect-preview.test.d.ts +0 -2
  700. package/dist/types/next/tests/server.api-handler-redirect-preview.test.d.ts.map +0 -1
  701. package/dist/types/runtimes/react/components/draft-switcher/draft-switcher.d.ts +0 -4
  702. package/dist/types/runtimes/react/components/draft-switcher/draft-switcher.d.ts.map +0 -1
  703. package/dist/types/runtimes/react/components/draft-switcher/draft-toolbar.d.ts +0 -6
  704. package/dist/types/runtimes/react/components/draft-switcher/draft-toolbar.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n applyMiddleware,\n createStore,\n combineReducers,\n type Dispatch as ReduxDispatch,\n type Store as ReduxStore,\n type Middleware,\n} from 'redux'\nimport thunk, { type ThunkAction, type ThunkDispatch } from 'redux-thunk'\n\nimport { composeWithDevToolsDevelopmentOnly } from '@redux-devtools/extension'\n\nimport { serializeState } from '../utils/serializeState'\n\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\nimport { type Action, ActionTypes, apiResourceFulfilled, setLocalizedResourceId } from './actions'\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'\nimport { MAKESWIFT_CACHE_TAG } from '../next/cache'\nimport { API_HANDLER_SITE_VERSION_HEADER, MakeswiftSiteVersion } from '../api/site-version'\n\nconst reducer = combineReducers({\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\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\nasync function fetchJson<T>(url: string, siteVersion: MakeswiftSiteVersion): Promise<T | null> {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n [API_HANDLER_SITE_VERSION_HEADER]: siteVersion,\n },\n next: { tags: [MAKESWIFT_CACHE_TAG] },\n })\n\n if (response.status === 404) return null\n\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\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n siteVersion: MakeswiftSiteVersion,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\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}`, siteVersion)\n break\n\n case APIResourceType.File:\n resource = await fetchJson<File>(`/api/makeswift/files/${resourceId}`, siteVersion)\n break\n\n case APIResourceType.Typography:\n resource = await fetchJson<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n siteVersion,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchJson<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n siteVersion,\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 fetchJson<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n siteVersion,\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, siteVersion)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchJson<Table>(`/api/makeswift/tables/${resourceId}`, siteVersion)\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\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nexport type Store = ReduxStore<State, Action> & { dispatch: Dispatch }\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): Middleware<Dispatch, State, Dispatch> {\n return () => (next: ReduxDispatch<Action>) => {\n return (action: 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}): Store {\n const composeEnhancers = composeWithDevToolsDevelopmentOnly({\n name: `API client store (${new Date().toISOString()})`,\n serialize: true,\n stateSanitizer: (state: any) => serializeState(state),\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n })\n\n return createStore(\n reducer,\n {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n composeEnhancers(applyMiddleware(thunk, defaultLocaleMiddleware(defaultLocale))),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAOO;AACP,yBAA4D;AAE5D,uBAAmD;AAEnD,4BAA+B;AAE/B,mBAA8B;AAC9B,4BAAuC;AACvC,qBAAuF;AACvF,iBAWO;AACP,mBAAoC;AACpC,0BAAsE;AAEtE,MAAM,cAAU,8BAAgB;AAAA,EAC9B,cAAc,aAAa;AAAA,EAC3B,uBAAuB,sBAAsB;AAC/C,CAAC;AASD,SAAS,uBACP,OACA,QACA,YAC2B;AAC3B,SAAO,sBAAsB;AAAA,IAC3B,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,kBACd,OACA,cACA,YACA,QACS;AACT,UAAQ,cAAc;AAAA,IACpB,KAAK,2BAAgB;AACnB,UAAI,UAAU,MAAM;AAClB,gBAAQ,MAAM,qBAAqB,YAAY,IAAI,UAAU,mBAAmB;AAChF,eAAO;AAAA,MACT;AAEA,YAAM,cAAc,uBAAuB,OAAO,QAAQ,UAAU;AACpE,aACE,eAAe,QACf,aAAa,kBAAkB,MAAM,cAAc,cAAc,aAAa,MAAM;AAAA,IAGxF;AACE,aAAO,aAAa,kBAAkB,MAAM,cAAc,cAAc,YAAY,MAAM;AAAA,EAC9F;AACF;AAEO,SAAS,eACd,OACA,cACA,YACA,QACgD;AAChD,UAAQ,cAAc;AAAA,IACpB,KAAK,2BAAgB;AACnB,UAAI,UAAU,MAAM;AAClB,gBAAQ,MAAM,qBAAqB,YAAY,IAAI,UAAU,mBAAmB;AAChF,eAAO;AAAA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AAW;AAAA,QACb;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF;AACF;AAEO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AACF,GAGU;AACR,QAAM,uBAAmB,qDAAmC;AAAA,IAC1D,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,IACnD,WAAW;AAAA,IACX,gBAAgB,CAAC,cAAe,sCAAe,KAAK;AAAA,IACpD,iBAAiB;AAAA,MACf,2BAAY;AAAA,MACZ,2BAAY;AAAA,MACZ,2BAAY;AAAA,IACd;AAAA,EACF,CAAC;AAED,aAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,cAAc,aAAa,gBAAgB,iBAAiB,YAAY;AAAA,MACxE,uBAAuB,sBAAsB;AAAA,QAC3C,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,IACA,qBAAiB,8BAAgB,mBAAAA,SAAO,wBAAwB,aAAa,CAAC,CAAC;AAAA,EACjF;AACF;","names":["thunk"]}
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, apiResourceFulfilled, setLocalizedResourceId } from './actions'\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\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAOO;AAEP,mBAA8B;AAC9B,4BAAuC;AACvC,qBAAuF;AACvF,IAAAA,kBAAoE;AAEpE,iBAWO;AAEP,MAAM,cAAU,gCAAgB;AAAA,EAC9B,cAAc,aAAa;AAAA,EAC3B,uBAAuB,sBAAsB;AAC/C,CAAC;AAWD,SAAS,uBACP,OACA,QACA,YAC2B;AAC3B,SAAO,sBAAsB;AAAA,IAC3B,MAAM;AAAA,IACN;AAAA,I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A,IACf;AAEA,iBAAS,qCAAqB,cAAc,YAAY,UAAU,MAAM,CAAC;AAEzE,WAAO;AAAA,EACT;AACF;AAIA,SAAS,wBACP,eACuC;AACvC,aAAO,kCAAiB,MAAM,UAAQ;AACpC,WAAO,CAAC,WAAmB;AACzB,cAAQ,OAAO,MAAM;AAAA,QACnB,KAAK,2BAAY;AAAA,QACjB,KAAK,2BAAY;AAAA,QACjB,KAAK,2BAAY,2BAA2B;AAC1C,gBAAM,EAAE,OAAO,IAAI,OAAO;AAC1B,iBAAO,KAAK;AAAA,YACV,GAAG;AAAA,YACH,SAAS,EAAE,GAAG,OAAO,SAAS,QAAQ,UAAU,cAAc;AAAA,UAChE,CAAW;AAAA,QACb;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AACF,GAGG;AACD,aAAO,eAAAC,gBAAoB;AAAA,IACzB;AAAA,IACA,gBAAgB;AAAA,MACd,cAAc,aAAa,gBAAgB,iBAAiB,YAAY;AAAA,MACxE,uBAAuB,sBAAsB;AAAA,QAC3C,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,IAEA,YAAY,0BACV,qBAAqB,iCAAiB,EAAE,OAAO,wBAAwB,aAAa,CAAC;AAAA,IAEvF,cAAU,gCAAe;AAAA,MACvB,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,2BAAY;AAAA,QACZ,2BAAY;AAAA,QACZ,2BAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":["import_toolkit","configureReduxStore"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/mixins/setup-teardown.ts"],"sourcesContent":["import { StoreEnhancer } from 'redux'\n\nexport interface SetupTeardownMixin {\n setup: () => void\n teardown: () => void\n}\n\nexport function withSetupTeardown(\n setup: () => void,\n teardown: () => void,\n): StoreEnhancer<SetupTeardownMixin> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n setup,\n teardown,\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,kBACd,OACA,UACmC;AACnC,SAAO,UAAQ,CAAC,SAAS,oBAAqB;AAAA,IAC5C,GAAG,KAAK,SAAS,cAAc;AAAA,IAC/B;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/state/mixins/setup-teardown.ts"],"sourcesContent":["import { type StoreEnhancer } from '@reduxjs/toolkit'\n\nexport interface SetupTeardownMixin {\n setup: () => void\n teardown: () => void\n}\n\nexport function withSetupTeardown(\n setup: () => void,\n teardown: () => void,\n): StoreEnhancer<SetupTeardownMixin> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n setup,\n teardown,\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,kBACd,OACA,UACmC;AACnC,SAAO,UAAQ,CAAC,SAAS,oBAAqB;AAAA,IAC5C,GAAG,KAAK,SAAS,cAAc;AAAA,IAC/B;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -113,6 +113,8 @@ function getAPIResource(state, resourceType, resourceId, locale) {
113
113
  return resource?.__typename === resourceType ? resource : null;
114
114
  }
115
115
  function reducer(state = getInitialState(), action) {
116
+ if (!(0, import_actions.isKnownAction)(action))
117
+ return state;
116
118
  switch (action.type) {
117
119
  case import_actions.ActionTypes.UPDATE_API_CLIENT_CACHE: {
118
120
  const { apiResources } = action.payload;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/api-resources.ts"],"sourcesContent":["import {\n APIResourceType,\n APIResourceLocale,\n LocalizableAPIResourceType,\n type APIResource,\n} from '../../api'\n\nimport deepEqual from '../../utils/deepEqual'\nimport { Branded } from '../../utils/branded'\n\nimport { type Action, ActionTypes } from '../actions'\n\ntype CompositeResourceId = Branded<string, 'CompositeResourceId'>\n\nfunction isValidAPIResourceType(resourceType: string): resourceType is APIResourceType {\n return resourceType in APIResourceType\n}\n\nfunction isLocalizableAPIResourceType(\n resourceType: APIResourceType,\n): resourceType is LocalizableAPIResourceType {\n return resourceType in LocalizableAPIResourceType\n}\n\nfunction compositeId(\n resourceId: string,\n resourceType: APIResourceType,\n locale?: string | null,\n): CompositeResourceId {\n return (\n locale != null && isLocalizableAPIResourceType(resourceType)\n ? `${resourceId}@${locale}`\n : resourceId\n ) as CompositeResourceId\n}\n\nfunction parseCompositeId(compositeId: CompositeResourceId): [string, string | null] {\n const [resourceId, locale] = compositeId.split('@')\n return [resourceId, locale ?? null]\n}\n\nexport type State = Map<APIResourceType, Map<CompositeResourceId, APIResource | null>>\n\nexport type SerializedState = {\n [key in APIResourceType]?: {\n id: string\n value: Extract<APIResource, { __typename: key }> | null\n locale?: APIResourceLocale<key>\n }[]\n}\n\nexport function getInitialState(\n serializedState: SerializedState = {\n Swatch: [],\n File: [],\n Typography: [],\n PagePathnameSlice: [],\n GlobalElement: [],\n Table: [],\n Snippet: [],\n Page: [],\n Site: [],\n LocalizedGlobalElement: [],\n },\n): State {\n return new Map(\n Object.entries(serializedState).map(([resourceType, resources]) => [\n resourceType,\n new Map(\n resources.map(({ id, value, locale }) => [\n compositeId(id, resourceType as APIResourceType, locale),\n value,\n ]),\n ),\n ]),\n ) as State\n}\n\nexport function getSerializedState(state: State): SerializedState {\n const resourceMap: SerializedState = {\n Swatch: [],\n File: [],\n Typography: [],\n PagePathnameSlice: [],\n GlobalElement: [],\n Table: [],\n Snippet: [],\n Page: [],\n Site: [],\n LocalizedGlobalElement: [],\n }\n\n Array.from(state.entries()).forEach(([resourceType, resources]) => {\n const particularResourceMap: { id: string; value: any; locale?: any }[] = []\n\n Array.from(resources.entries()).forEach(([compositeId, value]) => {\n if (value != null) {\n const [id, locale] = parseCompositeId(compositeId)\n console.assert(\n locale == null || isLocalizableAPIResourceType(resourceType),\n `Unexpected locale for non-localizable resource type ${resourceType}`,\n { id, locale },\n )\n\n particularResourceMap.push(locale != null ? { id, value, locale } : { id, value })\n }\n })\n\n resourceMap[resourceType] = particularResourceMap\n })\n\n return resourceMap\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n return state.get(resourceType)?.has(compositeId(resourceId, resourceType, locale)) ?? false\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 const resource = state.get(resourceType)?.get(compositeId(resourceId, resourceType, locale))\n\n return resource?.__typename === resourceType\n ? (resource as Extract<typeof resource, { __typename: T }>)\n : null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.UPDATE_API_CLIENT_CACHE: {\n const { apiResources } = action.payload\n\n return Object.entries(apiResources).reduce((state, [resourceType, cachedResources]) => {\n const resType = resourceType as APIResourceType\n const cached:\n | { id: string; value: APIResource | null; locale?: string | null }[]\n | undefined = cachedResources\n\n const existing = state.get(resType) ?? new Map<CompositeResourceId, APIResource | null>()\n const updated = cached?.reduce((r, { id, value, locale }) => {\n const cid = compositeId(id, resType, locale)\n return r.get(cid) != null ? r : new Map(r).set(cid, value)\n }, existing)\n\n return updated == null || updated === existing\n ? state\n : new Map(state).set(resType, updated)\n }, state)\n }\n\n case ActionTypes.API_RESOURCE_FULFILLED: {\n const { resourceType, resourceId, resource, locale } = action.payload\n return new Map(state).set(\n resourceType,\n new Map(state.get(resourceType)!).set(\n compositeId(resourceId, resourceType, locale),\n resource,\n ),\n )\n }\n\n case ActionTypes.CHANGE_API_RESOURCE: {\n const { resource, locale } = action.payload\n const existingApiResource = getAPIResource(state, resource.__typename, resource.id, locale)\n\n if (deepEqual(existingApiResource, resource)) return state\n\n return new Map(state).set(\n resource.__typename,\n new Map(state.get(resource.__typename)!).set(\n compositeId(resource.id, resource.__typename, locale),\n resource,\n ),\n )\n }\n\n case ActionTypes.EVICT_API_RESOURCE: {\n const { id, locale } = action.payload\n const [resourceType, resourceId] = id.split(':')\n\n if (!isValidAPIResourceType(resourceType)) return state\n\n const resources = new Map(state.get(resourceType as APIResourceType)!)\n\n const deleted = resources.delete(compositeId(resourceId, resourceType, locale))\n\n return deleted ? new Map(state).set(resourceType as APIResourceType, resources) : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAKO;AAEP,uBAAsB;AAGtB,qBAAyC;AAIzC,SAAS,uBAAuB,cAAuD;AACrF,SAAO,gBAAgB;AACzB;AAEA,SAAS,6BACP,cAC4C;AAC5C,SAAO,gBAAgB;AACzB;AAEA,SAAS,YACP,YACA,cACA,QACqB;AACrB,SACE,UAAU,QAAQ,6BAA6B,YAAY,IACvD,GAAG,UAAU,IAAI,MAAM,KACvB;AAER;AAEA,SAAS,iBAAiBA,cAA2D;AACnF,QAAM,CAAC,YAAY,MAAM,IAAIA,aAAY,MAAM,GAAG;AAClD,SAAO,CAAC,YAAY,UAAU,IAAI;AACpC;AAYO,SAAS,gBACd,kBAAmC;AAAA,EACjC,QAAQ,CAAC;AAAA,EACT,MAAM,CAAC;AAAA,EACP,YAAY,CAAC;AAAA,EACb,mBAAmB,CAAC;AAAA,EACpB,eAAe,CAAC;AAAA,EAChB,OAAO,CAAC;AAAA,EACR,SAAS,CAAC;AAAA,EACV,MAAM,CAAC;AAAA,EACP,MAAM,CAAC;AAAA,EACP,wBAAwB,CAAC;AAC3B,GACO;AACP,SAAO,IAAI;AAAA,IACT,OAAO,QAAQ,eAAe,EAAE,IAAI,CAAC,CAAC,cAAc,SAAS,MAAM;AAAA,MACjE;AAAA,MACA,IAAI;AAAA,QACF,UAAU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AAE;AAAA,QACpB,SAAS;AAAA,QACT,IAAI,IAAI,MAAM,IAAI,SAAS,UAAU,CAAE,EAAE;AAAA,UACvC,YAAY,SAAS,IAAI,SAAS,YAAY,MAAM;AAAA,UACpD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IAEA,KAAK,2BAAY,oBAAoB;AACnC,YAAM,EAAE,IAAI,OAAO,IAAI,OAAO;AAC9B,YAAM,CAAC,cAAc,UAAU,IAAI,GAAG,MAAM,GAAG;AAE/C,UAAI,CAAC,uBAAuB,YAAY;AAAG,eAAO;AAElD,YAAM,YAAY,IAAI,IAAI,MAAM,IAAI,YAA+B,CAAE;AAErE,YAAM,UAAU,UAAU,OAAO,YAAY,YAAY,cAAc,MAAM,CAAC;AAE9E,aAAO,UAAU,IAAI,IAAI,KAAK,EAAE,IAAI,cAAiC,SAAS,IAAI;AAAA,IACpF;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":["compositeId","state","deepEqual"]}
1
+ {"version":3,"sources":["../../../../src/state/modules/api-resources.ts"],"sourcesContent":["import {\n APIResourceType,\n APIResourceLocale,\n LocalizableAPIResourceType,\n type APIResource,\n} from '../../api'\n\nimport deepEqual from '../../utils/deepEqual'\nimport { Branded } from '../../utils/branded'\n\nimport { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\ntype CompositeResourceId = Branded<string, 'CompositeResourceId'>\n\nfunction isValidAPIResourceType(resourceType: string): resourceType is APIResourceType {\n return resourceType in APIResourceType\n}\n\nfunction isLocalizableAPIResourceType(\n resourceType: APIResourceType,\n): resourceType is LocalizableAPIResourceType {\n return resourceType in LocalizableAPIResourceType\n}\n\nfunction compositeId(\n resourceId: string,\n resourceType: APIResourceType,\n locale?: string | null,\n): CompositeResourceId {\n return (\n locale != null && isLocalizableAPIResourceType(resourceType)\n ? `${resourceId}@${locale}`\n : resourceId\n ) as CompositeResourceId\n}\n\nfunction parseCompositeId(compositeId: CompositeResourceId): [string, string | null] {\n const [resourceId, locale] = compositeId.split('@')\n return [resourceId, locale ?? null]\n}\n\nexport type State = Map<APIResourceType, Map<CompositeResourceId, APIResource | null>>\n\nexport type SerializedState = {\n [key in APIResourceType]?: {\n id: string\n value: Extract<APIResource, { __typename: key }> | null\n locale?: APIResourceLocale<key>\n }[]\n}\n\nexport function getInitialState(\n serializedState: SerializedState = {\n Swatch: [],\n File: [],\n Typography: [],\n PagePathnameSlice: [],\n GlobalElement: [],\n Table: [],\n Snippet: [],\n Page: [],\n Site: [],\n LocalizedGlobalElement: [],\n },\n): State {\n return new Map(\n Object.entries(serializedState).map(([resourceType, resources]) => [\n resourceType,\n new Map(\n resources.map(({ id, value, locale }) => [\n compositeId(id, resourceType as APIResourceType, locale),\n value,\n ]),\n ),\n ]),\n ) as State\n}\n\nexport function getSerializedState(state: State): SerializedState {\n const resourceMap: SerializedState = {\n Swatch: [],\n File: [],\n Typography: [],\n PagePathnameSlice: [],\n GlobalElement: [],\n Table: [],\n Snippet: [],\n Page: [],\n Site: [],\n LocalizedGlobalElement: [],\n }\n\n Array.from(state.entries()).forEach(([resourceType, resources]) => {\n const particularResourceMap: { id: string; value: any; locale?: any }[] = []\n\n Array.from(resources.entries()).forEach(([compositeId, value]) => {\n if (value != null) {\n const [id, locale] = parseCompositeId(compositeId)\n console.assert(\n locale == null || isLocalizableAPIResourceType(resourceType),\n `Unexpected locale for non-localizable resource type ${resourceType}`,\n { id, locale },\n )\n\n particularResourceMap.push(locale != null ? { id, value, locale } : { id, value })\n }\n })\n\n resourceMap[resourceType] = particularResourceMap\n })\n\n return resourceMap\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n return state.get(resourceType)?.has(compositeId(resourceId, resourceType, locale)) ?? false\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 const resource = state.get(resourceType)?.get(compositeId(resourceId, resourceType, locale))\n\n return resource?.__typename === resourceType\n ? (resource as Extract<typeof resource, { __typename: T }>)\n : null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.UPDATE_API_CLIENT_CACHE: {\n const { apiResources } = action.payload\n\n return Object.entries(apiResources).reduce((state, [resourceType, cachedResources]) => {\n const resType = resourceType as APIResourceType\n const cached:\n | { id: string; value: APIResource | null; locale?: string | null }[]\n | undefined = cachedResources\n\n const existing = state.get(resType) ?? new Map<CompositeResourceId, APIResource | null>()\n const updated = cached?.reduce((r, { id, value, locale }) => {\n const cid = compositeId(id, resType, locale)\n return r.get(cid) != null ? r : new Map(r).set(cid, value)\n }, existing)\n\n return updated == null || updated === existing\n ? state\n : new Map(state).set(resType, updated)\n }, state)\n }\n\n case ActionTypes.API_RESOURCE_FULFILLED: {\n const { resourceType, resourceId, resource, locale } = action.payload\n return new Map(state).set(\n resourceType,\n new Map(state.get(resourceType)!).set(\n compositeId(resourceId, resourceType, locale),\n resource,\n ),\n )\n }\n\n case ActionTypes.CHANGE_API_RESOURCE: {\n const { resource, locale } = action.payload\n const existingApiResource = getAPIResource(state, resource.__typename, resource.id, locale)\n\n if (deepEqual(existingApiResource, resource)) return state\n\n return new Map(state).set(\n resource.__typename,\n new Map(state.get(resource.__typename)!).set(\n compositeId(resource.id, resource.__typename, locale),\n resource,\n ),\n )\n }\n\n case ActionTypes.EVICT_API_RESOURCE: {\n const { id, locale } = action.payload\n const [resourceType, resourceId] = id.split(':')\n\n if (!isValidAPIResourceType(resourceType)) return state\n\n const resources = new Map(state.get(resourceType as APIResourceType)!)\n\n const deleted = resources.delete(compositeId(resourceId, resourceType, locale))\n\n return deleted ? new Map(state).set(resourceType as APIResourceType, resources) : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA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;AAElD,YAAM,YAAY,IAAI,IAAI,MAAM,IAAI,YAA+B,CAAE;AAErE,YAAM,UAAU,UAAU,OAAO,YAAY,YAAY,cAAc,MAAM,CAAC;AAE9E,aAAO,UAAU,IAAI,IAAI,KAAK,EAAE,IAAI,cAAiC,SAAS,IAAI;AAAA,IACpF;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":["compositeId","state","deepEqual"]}
@@ -68,6 +68,8 @@ function getBoxModel(state, documentKey, elementKey) {
68
68
  return getBoxModels(state).get(documentKey)?.get(elementKey) ?? null;
69
69
  }
70
70
  function reducer(state = getInitialState(), action) {
71
+ if (!(0, import_actions.isKnownAction)(action))
72
+ return state;
71
73
  switch (action.type) {
72
74
  case import_actions.ActionTypes.REGISTER_MEASURABLE: {
73
75
  const { documentKey, elementKey, measurable } = action.payload;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/box-models.ts"],"sourcesContent":["import { type BoxModel } from '@makeswift/controls'\nimport {\n createBox as createBoxWithoutScroll,\n CreateBoxArgs,\n getBox as getBoxWithoutScroll,\n withScroll,\n} from 'css-box-model'\n\nimport { Action, ActionTypes } from '../actions'\n\nexport type { BoxModel }\n\nexport function parse(rawString: string): number {\n const value = Number(rawString.replace(/px$/, ''))\n\n return Number.isFinite(value) ? value : 0\n}\n\nexport function createBox(boxArgs: CreateBoxArgs): BoxModel {\n return withScroll(createBoxWithoutScroll(boxArgs))\n}\n\nexport function getBox(element: Element): BoxModel {\n return withScroll(getBoxWithoutScroll(element))\n}\n\nexport interface BoxModelHandle {\n getBoxModel(): BoxModel | null\n}\n\nexport type Measurable = Element | BoxModelHandle\n\nexport function isMeasurable(value: unknown): value is Measurable {\n if (value instanceof Element) return true\n\n if (\n typeof value === 'object' &&\n value !== null &&\n 'getBoxModel' in value &&\n typeof (value as { getBoxModel: unknown }).getBoxModel === 'function'\n ) {\n return true\n }\n\n return false\n}\n\nexport function measure(measurable: Measurable): BoxModel | null {\n if (measurable instanceof Element) return getBox(measurable)\n\n return measurable.getBoxModel()\n}\n\nexport type State = {\n measurables: Map<string, Map<string, Measurable>>\n boxModels: Map<string, Map<string, BoxModel>>\n}\n\nexport function getInitialState(): State {\n return { measurables: new Map(), boxModels: new Map() }\n}\n\nexport function getMeasurables(state: State): Map<string, Map<string, Measurable>> {\n return state.measurables\n}\n\nexport function getBoxModels(state: State): Map<string, Map<string, BoxModel>> {\n return state.boxModels\n}\n\nexport function getBoxModel(\n state: State,\n documentKey: string,\n elementKey: string,\n): BoxModel | null {\n return getBoxModels(state).get(documentKey)?.get(elementKey) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action) {\n switch (action.type) {\n case ActionTypes.REGISTER_MEASURABLE: {\n const { documentKey, elementKey, measurable } = action.payload\n\n return {\n ...state,\n measurables: new Map(state.measurables).set(\n documentKey,\n new Map(state.measurables.get(documentKey) ?? []).set(elementKey, measurable),\n ),\n }\n }\n\n case ActionTypes.UNREGISTER_MEASURABLE: {\n const { documentKey, elementKey } = action.payload\n const nextMeasurables = new Map(state.measurables.get(documentKey) ?? [])\n\n const deleted = nextMeasurables.delete(elementKey)\n\n return deleted\n ? { ...state, measurables: new Map(state.measurables).set(documentKey, nextMeasurables) }\n : state\n }\n\n case ActionTypes.CHANGE_ELEMENT_BOX_MODELS: {\n const { changedElementBoxModels } = action.payload\n\n if (changedElementBoxModels.size === 0) return state\n\n const nextBoxModels = new Map(state.boxModels)\n\n changedElementBoxModels.forEach((changedBoxModels, documentKey) => {\n const nextDocumentBoxModels = new Map(nextBoxModels.get(documentKey) ?? [])\n\n changedBoxModels.forEach((changedBoxModel, elementKey) => {\n if (changedBoxModel == null) nextDocumentBoxModels.delete(elementKey)\n else nextDocumentBoxModels.set(elementKey, changedBoxModel)\n })\n\n if (nextDocumentBoxModels.size > 0) nextBoxModels.set(documentKey, nextDocumentBoxModels)\n else nextBoxModels.delete(documentKey)\n })\n\n return { ...state, boxModels: nextBoxModels }\n }\n\n default:\n return state\n }\n}\n"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,WAAW,EAAE;AAAA,UACtC;AAAA,UACA,IAAI,IAAI,MAAM,YAAY,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,IAAI,YAAY,UAAU;AAAA,QAC9E;AAAA,MACF;AAAA,IACF;AAAA,IAEA,KAAK,2BAAY,uBAAuB;AACtC,YAAM,EAAE,aAAa,WAAW,IAAI,OAAO;AAC3C,YAAM,kBAAkB,IAAI,IAAI,MAAM,YAAY,IAAI,WAAW,KAAK,CAAC,CAAC;AAExE,YAAM,UAAU,gBAAgB,OAAO,UAAU;AAEjD,aAAO,UACH,EAAE,GAAG,OAAO,aAAa,IAAI,IAAI,MAAM,WAAW,EAAE,IAAI,aAAa,eAAe,EAAE,IACtF;AAAA,IACN;AAAA,IAEA,KAAK,2BAAY,2BAA2B;AAC1C,YAAM,EAAE,wBAAwB,IAAI,OAAO;AAE3C,UAAI,wBAAwB,SAAS;AAAG,eAAO;AAE/C,YAAM,gBAAgB,IAAI,IAAI,MAAM,SAAS;AAE7C,8BAAwB,QAAQ,CAAC,kBAAkB,gBAAgB;AACjE,cAAM,wBAAwB,IAAI,IAAI,cAAc,IAAI,WAAW,KAAK,CAAC,CAAC;AAE1E,yBAAiB,QAAQ,CAAC,iBAAiB,eAAe;AACxD,cAAI,mBAAmB;AAAM,kCAAsB,OAAO,UAAU;AAAA;AAC/D,kCAAsB,IAAI,YAAY,eAAe;AAAA,QAC5D,CAAC;AAED,YAAI,sBAAsB,OAAO;AAAG,wBAAc,IAAI,aAAa,qBAAqB;AAAA;AACnF,wBAAc,OAAO,WAAW;AAAA,MACvC,CAAC;AAED,aAAO,EAAE,GAAG,OAAO,WAAW,cAAc;AAAA,IAC9C;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":["createBoxWithoutScroll","getBoxWithoutScroll"]}
1
+ {"version":3,"sources":["../../../../src/state/modules/box-models.ts"],"sourcesContent":["import { type BoxModel } from '@makeswift/controls'\nimport {\n createBox as createBoxWithoutScroll,\n CreateBoxArgs,\n getBox as getBoxWithoutScroll,\n withScroll,\n} from 'css-box-model'\n\nimport { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\nexport type { BoxModel }\n\nexport function parse(rawString: string): number {\n const value = Number(rawString.replace(/px$/, ''))\n\n return Number.isFinite(value) ? value : 0\n}\n\nexport function createBox(boxArgs: CreateBoxArgs): BoxModel {\n return withScroll(createBoxWithoutScroll(boxArgs))\n}\n\nexport function getBox(element: Element): BoxModel {\n return withScroll(getBoxWithoutScroll(element))\n}\n\nexport interface BoxModelHandle {\n getBoxModel(): BoxModel | null\n}\n\nexport type Measurable = Element | BoxModelHandle\n\nexport function isMeasurable(value: unknown): value is Measurable {\n if (value instanceof Element) return true\n\n if (\n typeof value === 'object' &&\n value !== null &&\n 'getBoxModel' in value &&\n typeof (value as { getBoxModel: unknown }).getBoxModel === 'function'\n ) {\n return true\n }\n\n return false\n}\n\nexport function measure(measurable: Measurable): BoxModel | null {\n if (measurable instanceof Element) return getBox(measurable)\n\n return measurable.getBoxModel()\n}\n\nexport type State = {\n measurables: Map<string, Map<string, Measurable>>\n boxModels: Map<string, Map<string, BoxModel>>\n}\n\nexport function getInitialState(): State {\n return { measurables: new Map(), boxModels: new Map() }\n}\n\nexport function getMeasurables(state: State): Map<string, Map<string, Measurable>> {\n return state.measurables\n}\n\nexport function getBoxModels(state: State): Map<string, Map<string, BoxModel>> {\n return state.boxModels\n}\n\nexport function getBoxModel(\n state: State,\n documentKey: string,\n elementKey: string,\n): BoxModel | null {\n return getBoxModels(state).get(documentKey)?.get(elementKey) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction) {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.REGISTER_MEASURABLE: {\n const { documentKey, elementKey, measurable } = action.payload\n\n return {\n ...state,\n measurables: new Map(state.measurables).set(\n documentKey,\n new Map(state.measurables.get(documentKey) ?? []).set(elementKey, measurable),\n ),\n }\n }\n\n case ActionTypes.UNREGISTER_MEASURABLE: {\n const { documentKey, elementKey } = action.payload\n const nextMeasurables = new Map(state.measurables.get(documentKey) ?? [])\n\n const deleted = nextMeasurables.delete(elementKey)\n\n return deleted\n ? { ...state, measurables: new Map(state.measurables).set(documentKey, nextMeasurables) }\n : state\n }\n\n case ActionTypes.CHANGE_ELEMENT_BOX_MODELS: {\n const { changedElementBoxModels } = action.payload\n\n if (changedElementBoxModels.size === 0) return state\n\n const nextBoxModels = new Map(state.boxModels)\n\n changedElementBoxModels.forEach((changedBoxModels, documentKey) => {\n const nextDocumentBoxModels = new Map(nextBoxModels.get(documentKey) ?? [])\n\n changedBoxModels.forEach((changedBoxModel, elementKey) => {\n if (changedBoxModel == null) nextDocumentBoxModels.delete(elementKey)\n else nextDocumentBoxModels.set(elementKey, changedBoxModel)\n })\n\n if (nextDocumentBoxModels.size > 0) nextBoxModels.set(documentKey, nextDocumentBoxModels)\n else nextBoxModels.delete(documentKey)\n })\n\n return { ...state, boxModels: nextBoxModels }\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAKO;AAEP,qBAA4E;AAIrE,SAAS,MAAM,WAA2B;AAC/C,QAAM,QAAQ,OAAO,UAAU,QAAQ,OAAO,EAAE,CAAC;AAEjD,SAAO,OAAO,SAAS,KAAK,IAAI,QAAQ;AAC1C;AAEO,SAAS,UAAU,SAAkC;AAC1D,aAAO,qCAAW,qBAAAA,WAAuB,OAAO,CAAC;AACnD;AAEO,SAAS,OAAO,SAA4B;AACjD,aAAO,qCAAW,qBAAAC,QAAoB,OAAO,CAAC;AAChD;AAQO,SAAS,aAAa,OAAqC;AAChE,MAAI,iBAAiB;AAAS,WAAO;AAErC,MACE,OAAO,UAAU,YACjB,UAAU,QACV,iBAAiB,SACjB,OAAQ,MAAmC,gBAAgB,YAC3D;AACA,WAAO;AAAA,EACT;AAE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AG,eAAO;AAE/C,YAAM,gBAAgB,IAAI,IAAI,MAAM,SAAS;AAE7C,8BAAwB,QAAQ,CAAC,kBAAkB,gBAAgB;AACjE,cAAM,wBAAwB,IAAI,IAAI,cAAc,IAAI,WAAW,KAAK,CAAC,CAAC;AAE1E,yBAAiB,QAAQ,CAAC,iBAAiB,eAAe;AACxD,cAAI,mBAAmB;AAAM,kCAAsB,OAAO,UAAU;AAAA;AAC/D,kCAAsB,IAAI,YAAY,eAAe;AAAA,QAC5D,CAAC;AAED,YAAI,sBAAsB,OAAO;AAAG,wBAAc,IAAI,aAAa,qBAAqB;AAAA;AACnF,wBAAc,OAAO,WAAW;AAAA,MACvC,CAAC;AAED,aAAO,EAAE,GAAG,OAAO,WAAW,cAAc;AAAA,IAC9C;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":["createBoxWithoutScroll","getBoxWithoutScroll"]}
@@ -57,6 +57,8 @@ function getInitialState(breakpoints = DEFAULT_BREAKPOINTS) {
57
57
  return breakpoints;
58
58
  }
59
59
  function reducer(state = getInitialState(), action) {
60
+ if (!(0, import_actions.isKnownAction)(action))
61
+ return state;
60
62
  switch (action.type) {
61
63
  case import_actions.ActionTypes.SET_BREAKPOINTS: {
62
64
  const breakpoints = action.payload.breakpoints;
@@ -110,7 +112,7 @@ function validateBreakpointsInput(input) {
110
112
  const next = array[index + 1];
111
113
  if (viewport && next && viewport < next.width) {
112
114
  throw new Error(
113
- `Error on breakpoint "${id}". Viewport cannot be smaller than the next breakpoint's width.
115
+ `Error on breakpoint "${id}". Viewport cannot be smaller than the next breakpoint's width.
114
116
  "${id}" has a viewport of ${viewport}px and the next breakpoint "${next.id}" has a width of ${next.width}px.`
115
117
  );
116
118
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/breakpoints.ts"],"sourcesContent":["import { type Breakpoint, type Breakpoints } from '@makeswift/controls'\n\nimport { Action, ActionTypes } from '../actions'\n\nexport {\n getBreakpoint,\n type Breakpoint,\n type BreakpointId,\n type Breakpoints,\n} from '@makeswift/controls'\n\nexport type State = Breakpoints\n\nexport const DefaultBreakpointID = {\n Desktop: 'desktop',\n Tablet: 'tablet',\n Mobile: 'mobile',\n} as const\n\ntype DefaultBreakpointID = (typeof DefaultBreakpointID)[keyof typeof DefaultBreakpointID]\n\nexport const DEFAULT_BREAKPOINTS: Breakpoints = [\n {\n id: DefaultBreakpointID.Desktop,\n label: 'Desktop',\n minWidth: 769,\n },\n {\n id: DefaultBreakpointID.Tablet,\n label: 'Tablet',\n minWidth: 576,\n maxWidth: 768,\n viewportWidth: 760,\n },\n {\n id: DefaultBreakpointID.Mobile,\n label: 'Mobile',\n maxWidth: 575,\n viewportWidth: 390,\n },\n]\n\nexport function getInitialState(breakpoints = DEFAULT_BREAKPOINTS): State {\n return breakpoints\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.SET_BREAKPOINTS: {\n const breakpoints = action.payload.breakpoints\n\n if (breakpoints.length === 0) throw new Error('Breakpoints cannot be empty.')\n\n return breakpoints\n }\n\n default:\n return state\n }\n}\n\nexport type BreakpointsInput = Record<string, { width: number; label?: string; viewport?: number }>\n\nexport function parseBreakpointsInput(input: BreakpointsInput): Breakpoints {\n validateBreakpointsInput(input)\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n const transformed = sorted.reduce(\n (prev, curr, index, array) => {\n const { width, viewport, id, label } = curr\n const next = array[index + 1]\n\n const breakpoint: Breakpoint = {\n id,\n ...(label && { label }),\n ...(next && { minWidth: next.width + 1 }),\n maxWidth: width,\n viewportWidth: viewport ?? width,\n }\n\n return [...prev, breakpoint]\n },\n [\n { id: DefaultBreakpointID.Desktop, label: 'Desktop', minWidth: sorted[0].width + 1 },\n ] as Breakpoints,\n )\n\n return transformed\n}\n\nfunction validateBreakpointsInput(input: BreakpointsInput) {\n if (DefaultBreakpointID.Desktop in input) {\n throw new Error(\n `Cannot change the base breakpoint. \"${DefaultBreakpointID.Desktop}\" is reserved as the base breakpoint.`,\n )\n }\n\n if (Object.keys(input).length === 0) {\n throw new Error(`Breakpoints cannot be empty. You must provide at least one breakpoint.`)\n }\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n sorted.forEach(({ id, width, viewport }, index, array) => {\n // This is only valid for desktop-first. We need to check the inverse for mobile-first.\n if (viewport && viewport > width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be greater than its width.\n \"${id}\" has a viewport of ${viewport}px and a width of ${width}px.`,\n )\n }\n\n const next = array[index + 1]\n\n if (viewport && next && viewport < next.width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be smaller than the next breakpoint's width. \n \"${id}\" has a viewport of ${viewport}px and the next breakpoint \"${next.id}\" has a width of ${next.width}px.`,\n )\n }\n\n if (next && width === next.width) {\n throw new Error(\n `Breakpoints cannot have the same width. \"${id}\" and \"${next.id}\" have the same width`,\n )\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAAoC;AAEpC,IAAAA,mBAKO;AAIA,MAAM,sBAAsB;AAAA,EACjC,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AACV;AAIO,MAAM,sBAAmC;AAAA,EAC9C;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,IACV,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AACF;AAEO,SAAS,gBAA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AM,wEAAwE;AAAA,EAC1F;AAEA,QAAM,SAAS,OAAO,QAAQ,KAAK,EAChC,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE,GAAG,OAAO,GAAG,EAAE,EACvC,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AAEnC,SAAO,QAAQ,CAAC,EAAE,IAAI,OAAO,SAAS,GAAG,OAAO,UAAU;AAExD,QAAI,YAAY,WAAW,OAAO;AAChC,YAAM,IAAI;AAAA,QACR,wBAAwB,EAAE;AAAA,WACvB,EAAE,uBAAuB,QAAQ,qBAAqB,KAAK;AAAA,MAChE;AAAA,IACF;AAEA,UAAM,OAAO,MAAM,QAAQ,CAAC;AAE5B,QAAI,YAAY,QAAQ,WAAW,KAAK,OAAO;AAC7C,YAAM,IAAI;AAAA,QACR,wBAAwB,EAAE;AAAA,WACvB,EAAE,uBAAuB,QAAQ,+BAA+B,KAAK,EAAE,oBAAoB,KAAK,KAAK;AAAA,MAC1G;AAAA,IACF;AAEA,QAAI,QAAQ,UAAU,KAAK,OAAO;AAChC,YAAM,IAAI;AAAA,QACR,4CAA4C,EAAE,UAAU,KAAK,EAAE;AAAA,MACjE;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":["import_controls"]}
1
+ {"version":3,"sources":["../../../../src/state/modules/breakpoints.ts"],"sourcesContent":["import { type Breakpoint, type Breakpoints } from '@makeswift/controls'\n\nimport { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\nexport {\n getBreakpoint,\n type Breakpoint,\n type BreakpointId,\n type Breakpoints,\n} from '@makeswift/controls'\n\nexport type State = Breakpoints\n\nexport const DefaultBreakpointID = {\n Desktop: 'desktop',\n Tablet: 'tablet',\n Mobile: 'mobile',\n} as const\n\ntype DefaultBreakpointID = (typeof DefaultBreakpointID)[keyof typeof DefaultBreakpointID]\n\nexport const DEFAULT_BREAKPOINTS: Breakpoints = [\n {\n id: DefaultBreakpointID.Desktop,\n label: 'Desktop',\n minWidth: 769,\n },\n {\n id: DefaultBreakpointID.Tablet,\n label: 'Tablet',\n minWidth: 576,\n maxWidth: 768,\n viewportWidth: 760,\n },\n {\n id: DefaultBreakpointID.Mobile,\n label: 'Mobile',\n maxWidth: 575,\n viewportWidth: 390,\n },\n]\n\nexport function getInitialState(breakpoints = DEFAULT_BREAKPOINTS): State {\n return breakpoints\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.SET_BREAKPOINTS: {\n const breakpoints = action.payload.breakpoints\n\n if (breakpoints.length === 0) throw new Error('Breakpoints cannot be empty.')\n\n return breakpoints\n }\n\n default:\n return state\n }\n}\n\nexport type BreakpointsInput = Record<string, { width: number; label?: string; viewport?: number }>\n\nexport function parseBreakpointsInput(input: BreakpointsInput): Breakpoints {\n validateBreakpointsInput(input)\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n const transformed = sorted.reduce(\n (prev, curr, index, array) => {\n const { width, viewport, id, label } = curr\n const next = array[index + 1]\n\n const breakpoint: Breakpoint = {\n id,\n ...(label && { label }),\n ...(next && { minWidth: next.width + 1 }),\n maxWidth: width,\n viewportWidth: viewport ?? width,\n }\n\n return [...prev, breakpoint]\n },\n [\n { id: DefaultBreakpointID.Desktop, label: 'Desktop', minWidth: sorted[0].width + 1 },\n ] as Breakpoints,\n )\n\n return transformed\n}\n\nfunction validateBreakpointsInput(input: BreakpointsInput) {\n if (DefaultBreakpointID.Desktop in input) {\n throw new Error(\n `Cannot change the base breakpoint. \"${DefaultBreakpointID.Desktop}\" is reserved as the base breakpoint.`,\n )\n }\n\n if (Object.keys(input).length === 0) {\n throw new Error(`Breakpoints cannot be empty. You must provide at least one breakpoint.`)\n }\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n sorted.forEach(({ id, width, viewport }, index, array) => {\n // This is only valid for desktop-first. We need to check the inverse for mobile-first.\n if (viewport && viewport > width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be greater than its width.\n \"${id}\" has a viewport of ${viewport}px and a width of ${width}px.`,\n )\n }\n\n const next = array[index + 1]\n\n if (viewport && next && viewport < next.width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be smaller than the next breakpoint's width.\n \"${id}\" has a viewport of ${viewport}px and the next breakpoint \"${next.id}\" has a width of ${next.width}px.`,\n )\n }\n\n if (next && width === next.width) {\n throw new Error(\n `Breakpoints cannot have the same width. \"${id}\" and \"${next.id}\" have the same width`,\n )\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAA4E;AAE5E,IAAAA,mBAKO;AAIA,MAAM,sBAAsB;AAAA,EACjC,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AACV;AAIO,MAAM,sBAAmC;AAAA,EAC9C;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,IACV,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AACF;AAEO,SAAS,gBAAgB,cAAc,qBAA4B;AACxE,SAAO;AACT;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,KAAC,8BAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY,iBAAiB;AAChC,YAAM,cAAc,OAAO,QAAQ;AAEnC,UAAI,YAAY,WAAW;AAA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,QAAQ,CAAC,EAAE,IAAI,OAAO,SAAS,GAAG,OAAO,UAAU;AAExD,QAAI,YAAY,WAAW,OAAO;AAChC,YAAM,IAAI;AAAA,QACR,wBAAwB,EAAE;AAAA,WACvB,EAAE,uBAAuB,QAAQ,qBAAqB,KAAK;AAAA,MAChE;AAAA,IACF;AAEA,UAAM,OAAO,MAAM,QAAQ,CAAC;AAE5B,QAAI,YAAY,QAAQ,WAAW,KAAK,OAAO;AAC7C,YAAM,IAAI;AAAA,QACR,wBAAwB,EAAE;AAAA,WACvB,EAAE,uBAAuB,QAAQ,+BAA+B,KAAK,EAAE,oBAAoB,KAAK,KAAK;AAAA,MAC1G;AAAA,IACF;AAEA,QAAI,QAAQ,UAAU,KAAK,OAAO;AAChC,YAAM,IAAI;AAAA,QACR,4CAA4C,EAAE,UAAU,KAAK,EAAE;AAAA,MACjE;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":["import_controls"]}
@@ -33,6 +33,8 @@ function getInitialState() {
33
33
  return null;
34
34
  }
35
35
  function reducer(state = getInitialState(), action) {
36
+ if (!(0, import_actions.isKnownAction)(action))
37
+ return state;
36
38
  switch (action.type) {
37
39
  case import_actions.ActionTypes.SET_BUILDER_EDIT_MODE:
38
40
  return action.payload.editMode;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/builder-edit-mode.ts"],"sourcesContent":["import { Action, ActionTypes } from '../actions'\n\nexport const BuilderEditMode = {\n BUILD: 'build',\n CONTENT: 'content',\n INTERACT: 'interact',\n} as const\n\nexport type BuilderEditMode = (typeof BuilderEditMode)[keyof typeof BuilderEditMode]\n\nexport type State = BuilderEditMode | null\n\nexport function getInitialState(): State {\n return null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.SET_BUILDER_EDIT_MODE:\n return action.payload.editMode\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAoC;AAE7B,MAAM,kBAAkB;AAAA,EAC7B,OAAO;AAAA,EACP,SAAS;AAAA,EACT,UAAU;AACZ;AAMO,SAAS,kBAAyB;AACvC,SAAO;AACT;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuB;AAC/E,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,OAAO,QAAQ;AAAA,IAExB;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/state/modules/builder-edit-mode.ts"],"sourcesContent":["import { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\nexport const BuilderEditMode = {\n BUILD: 'build',\n CONTENT: 'content',\n INTERACT: 'interact',\n} as const\n\nexport type BuilderEditMode = (typeof BuilderEditMode)[keyof typeof BuilderEditMode]\n\nexport type State = BuilderEditMode | null\n\nexport function getInitialState(): State {\n return null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.SET_BUILDER_EDIT_MODE:\n return action.payload.editMode\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA4E;AAErE,MAAM,kBAAkB;AAAA,EAC7B,OAAO;AAAA,EACP,SAAS;AAAA,EACT,UAAU;AACZ;AAMO,SAAS,kBAAyB;AACvC,SAAO;AACT;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,KAAC,8BAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,OAAO,QAAQ;AAAA,IAExB;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
@@ -58,6 +58,8 @@ function getComponentsMeta(state) {
58
58
  return state;
59
59
  }
60
60
  function reducer(state = getInitialState(), action) {
61
+ if (!(0, import_actions.isKnownAction)(action))
62
+ return state;
61
63
  switch (action.type) {
62
64
  case import_actions.ActionTypes.REGISTER_COMPONENT:
63
65
  return new Map(state).set(action.payload.type, action.payload.meta);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/components-meta.ts"],"sourcesContent":["import { Action, ActionTypes } from '../actions'\n\nexport const ComponentIcon = {\n Billing: 'billing',\n Bolt: 'bolt',\n Button: 'button',\n Carousel: 'carousel',\n Chats: 'chats',\n Code: 'code',\n Countdown: 'countdown',\n Cube: 'cube',\n Database: 'database',\n Divider: 'divider',\n Form: 'form',\n Gallery: 'gallery',\n Help: 'help',\n Image: 'image',\n Layout: 'layout',\n Lock: 'lock',\n Navigation: 'navigation',\n SocialLinks: 'social-links',\n Star: 'star',\n Text: 'text',\n Users: 'users',\n Video: 'video',\n} as const\n\nexport type ComponentIcon = (typeof ComponentIcon)[keyof typeof ComponentIcon]\n\nexport type ComponentMeta = { label: string; icon: ComponentIcon; hidden: boolean, description?: string }\n\nexport type State = Map<string, ComponentMeta>\n\nexport function getInitialState({\n componentsMeta = new Map(),\n}: { componentsMeta?: Map<string, ComponentMeta> } = {}): State {\n return componentsMeta\n}\n\nexport function getComponentsMeta(state: State): Map<string, ComponentMeta> {\n return state\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT:\n return new Map(state).set(action.payload.type, action.payload.meta)\n\n case ActionTypes.UNREGISTER_COMPONENT: {\n const nextState = new Map(state)\n\n const deleted = nextState.delete(action.payload.type)\n\n return deleted ? nextState : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAoC;AAE7B,MAAM,gBAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,MAAM;AAAA,EACN,UAAU;AAAA,EACV,SAAS;AAAA,EACT,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AACT;AAQO,SAAS,gBAAgB;AAAA,EAC9B,iBAAiB,oBAAI,IAAI;AAC3B,IAAqD,CAAC,GAAU;AAC9D,SAAO;AACT;AAEO,SAAS,kBAAkB,OAA0C;AAC1E,SAAO;AACT;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuB;AAC/E,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,IAAI,IAAI,KAAK,EAAE,IAAI,OAAO,QAAQ,MAAM,OAAO,QAAQ,IAAI;AAAA,IAEpE,KAAK,2BAAY,sBAAsB;AACrC,YAAM,YAAY,IAAI,IAAI,KAAK;AAE/B,YAAM,UAAU,UAAU,OAAO,OAAO,QAAQ,IAAI;AAEpD,aAAO,UAAU,YAAY;AAAA,IAC/B;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/state/modules/components-meta.ts"],"sourcesContent":["import { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\nexport const ComponentIcon = {\n Billing: 'billing',\n Bolt: 'bolt',\n Button: 'button',\n Carousel: 'carousel',\n Chats: 'chats',\n Code: 'code',\n Countdown: 'countdown',\n Cube: 'cube',\n Database: 'database',\n Divider: 'divider',\n Form: 'form',\n Gallery: 'gallery',\n Help: 'help',\n Image: 'image',\n Layout: 'layout',\n Lock: 'lock',\n Navigation: 'navigation',\n SocialLinks: 'social-links',\n Star: 'star',\n Text: 'text',\n Users: 'users',\n Video: 'video',\n} as const\n\nexport type ComponentIcon = (typeof ComponentIcon)[keyof typeof ComponentIcon]\n\nexport type ComponentMeta = {\n label: string\n icon: ComponentIcon\n hidden: boolean\n description?: string\n}\n\nexport type State = Map<string, ComponentMeta>\n\nexport function getInitialState({\n componentsMeta = new Map(),\n}: { componentsMeta?: Map<string, ComponentMeta> } = {}): State {\n return componentsMeta\n}\n\nexport function getComponentsMeta(state: State): Map<string, ComponentMeta> {\n return state\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT:\n return new Map(state).set(action.payload.type, action.payload.meta)\n\n case ActionTypes.UNREGISTER_COMPONENT: {\n const nextState = new Map(state)\n\n const deleted = nextState.delete(action.payload.type)\n\n return deleted ? nextState : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA4E;AAErE,MAAM,gBAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,MAAM;AAAA,EACN,UAAU;AAAA,EACV,SAAS;AAAA,EACT,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AACT;AAaO,SAAS,gBAAgB;AAAA,EAC9B,iBAAiB,oBAAI,IAAI;AAC3B,IAAqD,CAAC,GAAU;AAC9D,SAAO;AACT;AAEO,SAAS,kBAAkB,OAA0C;AAC1E,SAAO;AACT;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,KAAC,8BAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,IAAI,IAAI,KAAK,EAAE,IAAI,OAAO,QAAQ,MAAM,OAAO,QAAQ,IAAI;AAAA,IAEpE,KAAK,2BAAY,sBAAsB;AACrC,YAAM,YAAY,IAAI,IAAI,KAAK;AAE/B,YAAM,UAAU,UAAU,OAAO,OAAO,QAAQ,IAAI;AAEpD,aAAO,UAAU,YAAY;AAAA,IAC/B;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
@@ -30,6 +30,8 @@ function getInitialState() {
30
30
  return /* @__PURE__ */ new Map();
31
31
  }
32
32
  function reducer(state = getInitialState(), action) {
33
+ if (!(0, import_actions.isKnownAction)(action))
34
+ return state;
33
35
  switch (action.type) {
34
36
  case import_actions.ActionTypes.REGISTER_COMPONENT_HANDLE:
35
37
  return new Map(state).set(
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/element-imperative-handles.ts"],"sourcesContent":["import { ElementImperativeHandle } from '../../runtimes/react/element-imperative-handle'\nimport { Action, ActionTypes } from '../actions'\n\ntype State = Map<string, Map<string, ElementImperativeHandle>>\n\nexport function getElementImperativeHandles(\n state: State,\n): Map<string, Map<string, ElementImperativeHandle>> {\n return state\n}\n\nfunction getInitialState(): State {\n return new Map()\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT_HANDLE:\n return new Map(state).set(\n action.payload.documentKey,\n new Map(new Map(state.get(action.payload.documentKey) ?? [])).set(\n action.payload.elementKey,\n action.payload.componentHandle,\n ),\n )\n\n case ActionTypes.UNREGISTER_COMPONENT_HANDLE: {\n const byElementKey = new Map(state.get(action.payload.documentKey) ?? [])\n\n const deleted = byElementKey.delete(action.payload.elementKey)\n\n if (!deleted) return state\n\n return new Map(state).set(action.payload.documentKey, byElementKey)\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAoC;AAI7B,SAAS,4BACd,OACmD;AACnD,SAAO;AACT;AAEA,SAAS,kBAAyB;AAChC,SAAO,oBAAI,IAAI;AACjB;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuB;AAC/E,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,IAAI,IAAI,KAAK,EAAE;AAAA,QACpB,OAAO,QAAQ;AAAA,QACf,IAAI,IAAI,IAAI,IAAI,MAAM,IAAI,OAAO,QAAQ,WAAW,KAAK,CAAC,CAAC,CAAC,EAAE;AAAA,UAC5D,OAAO,QAAQ;AAAA,UACf,OAAO,QAAQ;AAAA,QACjB;AAAA,MACF;AAAA,IAEF,KAAK,2BAAY,6BAA6B;AAC5C,YAAM,eAAe,IAAI,IAAI,MAAM,IAAI,OAAO,QAAQ,WAAW,KAAK,CAAC,CAAC;AAExE,YAAM,UAAU,aAAa,OAAO,OAAO,QAAQ,UAAU;AAE7D,UAAI,CAAC;AAAS,eAAO;AAErB,aAAO,IAAI,IAAI,KAAK,EAAE,IAAI,OAAO,QAAQ,aAAa,YAAY;AAAA,IACpE;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/state/modules/element-imperative-handles.ts"],"sourcesContent":["import { ElementImperativeHandle } from '../../runtimes/react/element-imperative-handle'\nimport { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\ntype State = Map<string, Map<string, ElementImperativeHandle>>\n\nexport function getElementImperativeHandles(\n state: State,\n): Map<string, Map<string, ElementImperativeHandle>> {\n return state\n}\n\nfunction getInitialState(): State {\n return new Map()\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT_HANDLE:\n return new Map(state).set(\n action.payload.documentKey,\n new Map(new Map(state.get(action.payload.documentKey) ?? [])).set(\n action.payload.elementKey,\n action.payload.componentHandle,\n ),\n )\n\n case ActionTypes.UNREGISTER_COMPONENT_HANDLE: {\n const byElementKey = new Map(state.get(action.payload.documentKey) ?? [])\n\n const deleted = byElementKey.delete(action.payload.elementKey)\n\n if (!deleted) return state\n\n return new Map(state).set(action.payload.documentKey, byElementKey)\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA4E;AAIrE,SAAS,4BACd,OACmD;AACnD,SAAO;AACT;AAEA,SAAS,kBAAyB;AAChC,SAAO,oBAAI,IAAI;AACjB;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,KAAC,8BAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,IAAI,IAAI,KAAK,EAAE;AAAA,QACpB,OAAO,QAAQ;AAAA,QACf,IAAI,IAAI,IAAI,IAAI,MAAM,IAAI,OAAO,QAAQ,WAAW,KAAK,CAAC,CAAC,CAAC,EAAE;AAAA,UAC5D,OAAO,QAAQ;AAAA,UACf,OAAO,QAAQ;AAAA,QACjB;AAAA,MACF;AAAA,IAEF,KAAK,2BAAY,6BAA6B;AAC5C,YAAM,eAAe,IAAI,IAAI,MAAM,IAAI,OAAO,QAAQ,WAAW,KAAK,CAAC,CAAC;AAExE,YAAM,UAAU,aAAa,OAAO,OAAO,QAAQ,UAAU;AAE7D,UAAI,CAAC;AAAS,eAAO;AAErB,aAAO,IAAI,IAAI,KAAK,EAAE,IAAI,OAAO,QAAQ,aAAa,YAAY;AAAA,IACpE;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
@@ -59,6 +59,8 @@ function getElementId(state, documentKey, elementKey) {
59
59
  return getElementIds(state, documentKey).get(elementKey) ?? null;
60
60
  }
61
61
  function reducer(state = getInitialState(), action) {
62
+ if (!(0, import_actions.isKnownAction)(action))
63
+ return state;
62
64
  switch (action.type) {
63
65
  case import_actions.ActionTypes.CREATE_ELEMENT_TREE: {
64
66
  const { document, descriptors } = action.payload;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/element-trees.ts"],"sourcesContent":["import { type Operation } from 'ot-json0'\nimport { getIn } from 'immutable'\n\nimport { type Element, type ElementData, isElementReference } from '@makeswift/controls'\n\nimport { Introspection } from '../../prop-controllers'\n\nimport { type Action, ActionTypes } from '../actions'\n\nimport { getRootElement, type Document } from './read-only-documents'\nimport { type DescriptorsByComponentType } from './prop-controllers'\n\nexport type ElementTree = {\n elements: Map<string, Element>\n elementIds: Map<string, string>\n}\n\nexport type State = Map<string, ElementTree>\n\nexport function getInitialState(\n documents?: Map<string, Document>,\n descriptors?: DescriptorsByComponentType,\n): State {\n const state = new Map<string, ElementTree>()\n if (documents == null || descriptors == null) return state\n\n for (const [documentKey, document] of documents) {\n state.set(documentKey, buildElementTree(getRootElement(document), descriptors))\n }\n\n return state\n}\n\nfunction getElementTree(state: State, documentKey: string): ElementTree | null {\n return state.get(documentKey) ?? null\n}\n\nexport function getElements(state: State, documentKey: string): Map<string, Element> {\n return getElementTree(state, documentKey)?.elements ?? new Map()\n}\n\nexport function getElementIds(state: State, documentKey: string): Map<string, string> {\n return getElementTree(state, documentKey)?.elementIds ?? new Map()\n}\n\nexport function getElement(state: State, documentKey: string, elementKey: string): Element | null {\n return getElements(state, documentKey).get(elementKey) ?? null\n}\n\nexport function getElementId(state: State, documentKey: string, elementKey: string): string | null {\n return getElementIds(state, documentKey).get(elementKey) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.CREATE_ELEMENT_TREE: {\n const { document, descriptors } = action.payload\n return new Map(state).set(\n document.key,\n buildElementTree(getRootElement(document), descriptors),\n )\n }\n\n case ActionTypes.DELETE_ELEMENT_TREE: {\n const nextState = new Map(state)\n const deleted = nextState.delete(action.payload.documentKey)\n return deleted ? nextState : state\n }\n\n case ActionTypes.CHANGE_ELEMENT_TREE: {\n const { oldDocument, newDocument, descriptors, operation } = action.payload\n const documentKey = oldDocument.key\n console.assert(\n documentKey === newDocument.key,\n `Mismatching document keys ${documentKey} !== ${newDocument.key}`,\n )\n\n const elementTree = state.get(documentKey)\n if (elementTree == null) return state\n\n const updatedElementTree = applyChanges(\n elementTree,\n descriptors,\n {\n old: getRootElement(oldDocument),\n new: getRootElement(newDocument),\n },\n operation,\n )\n\n return new Map(state).set(documentKey, updatedElementTree)\n }\n\n default:\n return state\n }\n}\n\nexport function* traverseElementTree(\n element: Element,\n descriptors: DescriptorsByComponentType,\n): Generator<Element> {\n yield element\n if (isElementReference(element)) return\n\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) return\n\n for (const [propKey, descriptor] of Object.entries(elementDescriptors)) {\n const children = Introspection.getElementChildren(descriptor, element.props[propKey])\n for (const child of children) {\n yield* traverseElementTree(child, descriptors)\n }\n }\n}\n\nfunction getElementIdProp(\n element: ElementData,\n descriptors: DescriptorsByComponentType,\n): string | null {\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) return null\n\n for (const [propName, descriptor] of Object.entries(elementDescriptors)) {\n const elementId = Introspection.getElementId(descriptor, element.props[propName])\n if (elementId != null) return elementId\n }\n\n return null\n}\n\nexport function buildElementTree(\n rootElement: Element,\n descriptors: DescriptorsByComponentType,\n): ElementTree {\n const elements = new Map<string, Element>()\n const elementIds = new Map<string, string>()\n\n for (const element of traverseElementTree(rootElement, descriptors)) {\n elements.set(element.key, element)\n if (!isElementReference(element)) {\n const elementId = getElementIdProp(element, descriptors)\n if (elementId != null) elementIds.set(element.key, elementId)\n }\n }\n\n return {\n elements,\n elementIds,\n }\n}\n\ntype OperationPath = Operation[number]['p']\n\n// performance-sensitive function, intentionally not using `elementData` schema here\nfunction isElement(item: unknown): item is Element {\n return (\n typeof item === 'object' &&\n item != null &&\n 'key' in item &&\n 'type' in item &&\n typeof item.key === 'string' &&\n typeof item.type === 'string'\n )\n}\n\ntype ElementOperationPath = { elementPath: OperationPath; propName: string | null }\n\nfunction getElementOperationPath(path: OperationPath): ElementOperationPath {\n if (path.length === 0) {\n return { elementPath: [], propName: null }\n }\n\n const i = path.findLastIndex(\n (fragment, i) =>\n typeof fragment === 'number' && (i === path.length - 1 || path[i + 1] === 'props'),\n )\n\n if ((i === -1 && path[0] !== 'props') || path.length - i < 3) {\n console.error('Operation path does not point to an element property', { path })\n return { elementPath: [], propName: null }\n }\n\n return { elementPath: path.slice(0, i + 1), propName: `${path.slice(i + 1).at(1)}` }\n}\n\nexport function getChangedElementsPaths(\n path: OperationPath,\n): [ElementOperationPath, ...ElementOperationPath[]] {\n let elementOp = getElementOperationPath(path)\n const result: [ElementOperationPath, ...ElementOperationPath[]] = [elementOp]\n while (elementOp.elementPath.length > 0) {\n elementOp = getElementOperationPath(elementOp.elementPath.slice(0, -1))\n result.push(elementOp)\n }\n\n return result\n}\n\nfunction getElementByPath(rootElement: Element, elementPath: OperationPath): Element | null {\n const item = getIn(rootElement, elementPath)\n if (!isElement(item)) {\n console.error('Expected an element, got', item, {\n rootElement,\n elementPath,\n })\n\n return null\n }\n\n return item\n}\n\nfunction getElementAndPropName(\n rootElement: Element,\n { elementPath, propName }: ElementOperationPath,\n): [Element, string | null] {\n const element = getElementByPath(rootElement, elementPath)\n return element != null ? [element, propName] : [rootElement, null]\n}\n\nfunction updateParentElements(\n elements: ElementTree['elements'],\n elementPaths: ElementOperationPath[],\n rootElement: Element,\n): void {\n elementPaths.forEach(({ elementPath }) => {\n const element = getElementByPath(rootElement, elementPath)\n if (element != null) elements.set(element.key, element)\n })\n}\n\nfunction hasChildren(\n element: Element,\n propName: string,\n descriptors: DescriptorsByComponentType,\n): boolean {\n if (isElementReference(element)) return false\n\n const propDescriptor = descriptors.get(element.type)?.[propName]\n if (propDescriptor == null) return false\n\n const children = Introspection.getElementChildren(propDescriptor, element.props[propName])\n return children.length > 0\n}\n\nfunction deleteElement(\n { elements, elementIds }: ElementTree,\n deletedElement: Element,\n propName: string | null,\n descriptors: DescriptorsByComponentType,\n) {\n if (propName == null || hasChildren(deletedElement, propName, descriptors)) {\n for (const element of traverseElementTree(deletedElement, descriptors)) {\n elements.delete(element.key)\n elementIds.delete(element.key)\n }\n } else {\n elements.delete(deletedElement.key)\n elementIds.delete(deletedElement.key)\n }\n}\n\nfunction applyDelete(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n path: OperationPath,\n): ElementTree {\n const [deleteElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [deletedElement, propName] = getElementAndPropName(rootElements.old, deleteElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n deleteElement({ elements, elementIds }, deletedElement, propName, descriptors)\n updateParentElements(elements, parentElementPaths, rootElements.new)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction insertElement(\n { elements, elementIds }: ElementTree,\n insertedElement: Element,\n propName: string | null,\n descriptors: DescriptorsByComponentType,\n) {\n if (propName == null || hasChildren(insertedElement, propName, descriptors)) {\n for (const element of traverseElementTree(insertedElement, descriptors)) {\n elements.set(element.key, element)\n if (!isElementReference(element)) {\n const elementId = getElementIdProp(element, descriptors)\n if (elementId != null) elementIds.set(element.key, elementId)\n }\n }\n } else {\n elements.set(insertedElement.key, insertedElement)\n if (!isElementReference(insertedElement)) {\n const elementId = getElementIdProp(insertedElement, descriptors)\n if (elementId != null) elementIds.set(insertedElement.key, elementId)\n }\n }\n}\n\nfunction applyInsert(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n path: OperationPath,\n): ElementTree {\n const [insertedElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [insertedElement, propName] = getElementAndPropName(rootElements.new, insertedElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n insertElement({ elements, elementIds }, insertedElement, propName, descriptors)\n updateParentElements(elements, parentElementPaths, rootElements.new)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction applyUpdate(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n path: OperationPath,\n): ElementTree {\n const [updateElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [deletedElement, propName] = getElementAndPropName(rootElements.old, updateElementPath)\n const [insertedElement, _] = getElementAndPropName(rootElements.new, updateElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n deleteElement({ elements, elementIds }, deletedElement, propName, descriptors)\n insertElement({ elements, elementIds }, insertedElement, propName, descriptors)\n\n updateParentElements(elements, parentElementPaths, rootElements.new)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction applyChanges(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n operation: Operation,\n): ElementTree {\n return operation.reduce((tree, op) => {\n const hasDelete = 'ld' in op || 'od' in op\n const hasInsert = 'li' in op || 'oi' in op\n if (hasDelete && hasInsert) {\n return applyUpdate(tree, descriptors, rootElements, op.p)\n }\n\n if (hasDelete) return applyDelete(tree, descriptors, rootElements, op.p)\n if (hasInsert) return applyInsert(tree, descriptors, rootElements, op.p)\n return tree\n }, elementTree)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAsB;AAEtB,sBAAmE;AAEnE,8BAA8B;AAE9B,qBAAyC;AAEzC,iCAA8C;AAUvC,SAAS,gBACd,WACA,aACO;AACP,QAAM,QAAQ,oBAAI,IAAyB;AAC3C,MAAI,aAAa,QAAQ,eAAe;AAAM,WAAO;AAErD,aAAW,CAAC,aAAa,QAAQ,KAAK,WAAW;AAC/C,UAAM,IAAI,aAAa,qBAAiB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,sBAAsB,aAAa,KAAK,iBAAiB;AAC5F,QAAM,CAAC,iBAAiB,CAAC,IAAI,sBAAsB,aAAa,KAAK,iBAAiB;AAEtF,QAAM,WAAW,IAAI,IAAI,YAAY,QAAQ;AAC7C,QAAM,aAAa,IAAI,IAAI,YAAY,UAAU;AAEjD,gBAAc,EAAE,UAAU,WAAW,GAAG,gBAAgB,UAAU,WAAW;AAC7E,gBAAc,EAAE,UAAU,WAAW,GAAG,iBAAiB,UAAU,WAAW;AAE9E,uBAAqB,UAAU,oBAAoB,aAAa,GAAG;AAEnE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,aACP,aACA,aACA,cACA,WACa;AACb,SAAO,UAAU,OAAO,CAAC,MAAM,OAAO;AACpC,UAAM,YAAY,QAAQ,MAAM,QAAQ;AACxC,UAAM,YAAY,QAAQ,MAAM,QAAQ;AACxC,QAAI,aAAa,WAAW;AAC1B,aAAO,YAAY,MAAM,aAAa,cAAc,GAAG,CAAC;AAAA,IAC1D;AAEA,QAAI;AAAW,aAAO,YAAY,MAAM,aAAa,cAAc,GAAG,CAAC;AACvE,QAAI;AAAW,aAAO,YAAY,MAAM,aAAa,cAAc,GAAG,CAAC;AACvE,WAAO;AAAA,EACT,GAAG,WAAW;AAChB;","names":["i"]}
1
+ {"version":3,"sources":["../../../../src/state/modules/element-trees.ts"],"sourcesContent":["import { type Operation } from 'ot-json0'\nimport { getIn } from 'immutable'\n\nimport { type Element, type ElementData, isElementReference } from '@makeswift/controls'\n\nimport { Introspection } from '../../prop-controllers'\n\nimport { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\nimport { getRootElement, type Document } from './read-only-documents'\nimport { type DescriptorsByComponentType } from './prop-controllers'\n\nexport type ElementTree = {\n elements: Map<string, Element>\n elementIds: Map<string, string>\n}\n\nexport type State = Map<string, ElementTree>\n\nexport function getInitialState(\n documents?: Map<string, Document>,\n descriptors?: DescriptorsByComponentType,\n): State {\n const state = new Map<string, ElementTree>()\n if (documents == null || descriptors == null) return state\n\n for (const [documentKey, document] of documents) {\n state.set(documentKey, buildElementTree(getRootElement(document), descriptors))\n }\n\n return state\n}\n\nfunction getElementTree(state: State, documentKey: string): ElementTree | null {\n return state.get(documentKey) ?? null\n}\n\nexport function getElements(state: State, documentKey: string): Map<string, Element> {\n return getElementTree(state, documentKey)?.elements ?? new Map()\n}\n\nexport function getElementIds(state: State, documentKey: string): Map<string, string> {\n return getElementTree(state, documentKey)?.elementIds ?? new Map()\n}\n\nexport function getElement(state: State, documentKey: string, elementKey: string): Element | null {\n return getElements(state, documentKey).get(elementKey) ?? null\n}\n\nexport function getElementId(state: State, documentKey: string, elementKey: string): string | null {\n return getElementIds(state, documentKey).get(elementKey) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.CREATE_ELEMENT_TREE: {\n const { document, descriptors } = action.payload\n return new Map(state).set(\n document.key,\n buildElementTree(getRootElement(document), descriptors),\n )\n }\n\n case ActionTypes.DELETE_ELEMENT_TREE: {\n const nextState = new Map(state)\n const deleted = nextState.delete(action.payload.documentKey)\n return deleted ? nextState : state\n }\n\n case ActionTypes.CHANGE_ELEMENT_TREE: {\n const { oldDocument, newDocument, descriptors, operation } = action.payload\n const documentKey = oldDocument.key\n console.assert(\n documentKey === newDocument.key,\n `Mismatching document keys ${documentKey} !== ${newDocument.key}`,\n )\n\n const elementTree = state.get(documentKey)\n if (elementTree == null) return state\n\n const updatedElementTree = applyChanges(\n elementTree,\n descriptors,\n {\n old: getRootElement(oldDocument),\n new: getRootElement(newDocument),\n },\n operation,\n )\n\n return new Map(state).set(documentKey, updatedElementTree)\n }\n\n default:\n return state\n }\n}\n\nexport function* traverseElementTree(\n element: Element,\n descriptors: DescriptorsByComponentType,\n): Generator<Element> {\n yield element\n if (isElementReference(element)) return\n\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) return\n\n for (const [propKey, descriptor] of Object.entries(elementDescriptors)) {\n const children = Introspection.getElementChildren(descriptor, element.props[propKey])\n for (const child of children) {\n yield* traverseElementTree(child, descriptors)\n }\n }\n}\n\nfunction getElementIdProp(\n element: ElementData,\n descriptors: DescriptorsByComponentType,\n): string | null {\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) return null\n\n for (const [propName, descriptor] of Object.entries(elementDescriptors)) {\n const elementId = Introspection.getElementId(descriptor, element.props[propName])\n if (elementId != null) return elementId\n }\n\n return null\n}\n\nexport function buildElementTree(\n rootElement: Element,\n descriptors: DescriptorsByComponentType,\n): ElementTree {\n const elements = new Map<string, Element>()\n const elementIds = new Map<string, string>()\n\n for (const element of traverseElementTree(rootElement, descriptors)) {\n elements.set(element.key, element)\n if (!isElementReference(element)) {\n const elementId = getElementIdProp(element, descriptors)\n if (elementId != null) elementIds.set(element.key, elementId)\n }\n }\n\n return {\n elements,\n elementIds,\n }\n}\n\ntype OperationPath = Operation[number]['p']\n\n// performance-sensitive function, intentionally not using `elementData` schema here\nfunction isElement(item: unknown): item is Element {\n return (\n typeof item === 'object' &&\n item != null &&\n 'key' in item &&\n 'type' in item &&\n typeof item.key === 'string' &&\n typeof item.type === 'string'\n )\n}\n\ntype ElementOperationPath = { elementPath: OperationPath; propName: string | null }\n\nfunction getElementOperationPath(path: OperationPath): ElementOperationPath {\n if (path.length === 0) {\n return { elementPath: [], propName: null }\n }\n\n const i = path.findLastIndex(\n (fragment, i) =>\n typeof fragment === 'number' && (i === path.length - 1 || path[i + 1] === 'props'),\n )\n\n if ((i === -1 && path[0] !== 'props') || path.length - i < 3) {\n console.error('Operation path does not point to an element property', { path })\n return { elementPath: [], propName: null }\n }\n\n return { elementPath: path.slice(0, i + 1), propName: `${path.slice(i + 1).at(1)}` }\n}\n\nexport function getChangedElementsPaths(\n path: OperationPath,\n): [ElementOperationPath, ...ElementOperationPath[]] {\n let elementOp = getElementOperationPath(path)\n const result: [ElementOperationPath, ...ElementOperationPath[]] = [elementOp]\n while (elementOp.elementPath.length > 0) {\n elementOp = getElementOperationPath(elementOp.elementPath.slice(0, -1))\n result.push(elementOp)\n }\n\n return result\n}\n\nfunction getElementByPath(rootElement: Element, elementPath: OperationPath): Element | null {\n const item = getIn(rootElement, elementPath)\n if (!isElement(item)) {\n console.error('Expected an element, got', item, {\n rootElement,\n elementPath,\n })\n\n return null\n }\n\n return item\n}\n\nfunction getElementAndPropName(\n rootElement: Element,\n { elementPath, propName }: ElementOperationPath,\n): [Element, string | null] {\n const element = getElementByPath(rootElement, elementPath)\n return element != null ? [element, propName] : [rootElement, null]\n}\n\nfunction updateParentElements(\n elements: ElementTree['elements'],\n elementPaths: ElementOperationPath[],\n rootElement: Element,\n): void {\n elementPaths.forEach(({ elementPath }) => {\n const element = getElementByPath(rootElement, elementPath)\n if (element != null) elements.set(element.key, element)\n })\n}\n\nfunction hasChildren(\n element: Element,\n propName: string,\n descriptors: DescriptorsByComponentType,\n): boolean {\n if (isElementReference(element)) return false\n\n const propDescriptor = descriptors.get(element.type)?.[propName]\n if (propDescriptor == null) return false\n\n const children = Introspection.getElementChildren(propDescriptor, element.props[propName])\n return children.length > 0\n}\n\nfunction deleteElement(\n { elements, elementIds }: ElementTree,\n deletedElement: Element,\n propName: string | null,\n descriptors: DescriptorsByComponentType,\n) {\n if (propName == null || hasChildren(deletedElement, propName, descriptors)) {\n for (const element of traverseElementTree(deletedElement, descriptors)) {\n elements.delete(element.key)\n elementIds.delete(element.key)\n }\n } else {\n elements.delete(deletedElement.key)\n elementIds.delete(deletedElement.key)\n }\n}\n\nfunction applyDelete(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n path: OperationPath,\n): ElementTree {\n const [deleteElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [deletedElement, propName] = getElementAndPropName(rootElements.old, deleteElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n deleteElement({ elements, elementIds }, deletedElement, propName, descriptors)\n updateParentElements(elements, parentElementPaths, rootElements.new)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction insertElement(\n { elements, elementIds }: ElementTree,\n insertedElement: Element,\n propName: string | null,\n descriptors: DescriptorsByComponentType,\n) {\n if (propName == null || hasChildren(insertedElement, propName, descriptors)) {\n for (const element of traverseElementTree(insertedElement, descriptors)) {\n elements.set(element.key, element)\n if (!isElementReference(element)) {\n const elementId = getElementIdProp(element, descriptors)\n if (elementId != null) elementIds.set(element.key, elementId)\n }\n }\n } else {\n elements.set(insertedElement.key, insertedElement)\n if (!isElementReference(insertedElement)) {\n const elementId = getElementIdProp(insertedElement, descriptors)\n if (elementId != null) elementIds.set(insertedElement.key, elementId)\n }\n }\n}\n\nfunction applyInsert(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n path: OperationPath,\n): ElementTree {\n const [insertedElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [insertedElement, propName] = getElementAndPropName(rootElements.new, insertedElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n insertElement({ elements, elementIds }, insertedElement, propName, descriptors)\n updateParentElements(elements, parentElementPaths, rootElements.new)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction applyUpdate(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n path: OperationPath,\n): ElementTree {\n const [updateElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [deletedElement, propName] = getElementAndPropName(rootElements.old, updateElementPath)\n const [insertedElement, _] = getElementAndPropName(rootElements.new, updateElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n deleteElement({ elements, elementIds }, deletedElement, propName, descriptors)\n insertElement({ elements, elementIds }, insertedElement, propName, descriptors)\n\n updateParentElements(elements, parentElementPaths, rootElements.new)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction applyChanges(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n operation: Operation,\n): ElementTree {\n return operation.reduce((tree, op) => {\n const hasDelete = 'ld' in op || 'od' in op\n const hasInsert = 'li' in op || 'oi' in op\n if (hasDelete && hasInsert) {\n return applyUpdate(tree, descriptors, rootElements, op.p)\n }\n\n if (hasDelete) return applyDelete(tree, descriptors, rootElements, op.p)\n if (hasInsert) return applyInsert(tree, descriptors, rootElements, op.p)\n return tree\n }, elementTree)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAsB;AAEtB,sBAAmE;AAEnE,8BAA8B;AAE9B,qBAA4E;AAE5E,iCAA8C;AAUvC,SAAS,gBACd,WACA,aACO;AACP,QAAM,QAAQ,oBAAI,IAAyB;AAC3C,MAAI,aAAa,QAAQ,eAAe;AAAM,WAAO;AAErD,aAAW,CAAC,aAAa,QAAQ,KAAK,WAAW;AAC/C,UAAM,IAAI,aAAa,qBAAiB,2CAAe,QAAQ,GAAG,WAAW,CAAC;AAAA,EAChF;AAEA,SAAO;AACT;AAEA,SAAS,eAAe,OAAc,aAAyC;AAC7E,SAAO,MAAM,IAAI,WAAW,KAAK;AACnC;AAEO,SAAS,YAAY,OAAc,aAA2C;AACnF,SAAO,eAAe,OAAO,WAAW,GAAG,YAAY,oBAAI,IAAI;AACjE;AAEO,SAAS,cAAc,OAAc,aAA0C;AACpF,SAAO,eAAe,OAAO,WAAW,GAAG,cAAc,oBAAI,IAAI;AACnE;AAEO,SAAS,WAAW,OAAc,aAAqB,YAAoC;AAChG,SAAO,YAAY,OAAO,WAAW,EAAE,IAAI,UAAU,KAAK;AAC5D;AAEO,SAAS,aAAa,OAAc,aAAqB,YAAmC;AACjG,SAAO,cAAc,OAAO,WAAW,EAAE,IAAI,UAAU,KAAK;AAC9D;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C,UAAM,YAAY,QAAQ,MAAM,QAAQ;AACxC,UAAM,YAAY,QAAQ,MAAM,QAAQ;AACxC,QAAI,aAAa,WAAW;AAC1B,aAAO,YAAY,MAAM,aAAa,cAAc,GAAG,CAAC;AAAA,IAC1D;AAEA,QAAI;AAAW,aAAO,YAAY,MAAM,aAAa,cAAc,GAAG,CAAC;AACvE,QAAI;AAAW,aAAO,YAAY,MAAM,aAAa,cAAc,GAAG,CAAC;AACvE,WAAO;AAAA,EACT,GAAG,WAAW;AAChB;","names":["i"]}
@@ -31,6 +31,8 @@ function getIsInBuilder(state) {
31
31
  return state;
32
32
  }
33
33
  function reducer(state = getInitialState(), action) {
34
+ if (!(0, import_actions.isKnownAction)(action))
35
+ return state;
34
36
  switch (action.type) {
35
37
  case import_actions.ActionTypes.SET_IS_IN_BUILDER:
36
38
  return action.payload;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/is-in-builder.ts"],"sourcesContent":["import { Action, ActionTypes } from '../actions'\n\nexport type State = boolean\n\nexport function getInitialState(): State {\n return false\n}\n\nexport function getIsInBuilder(state: State): boolean {\n return state\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.SET_IS_IN_BUILDER:\n return action.payload\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAoC;AAI7B,SAAS,kBAAyB;AACvC,SAAO;AACT;AAEO,SAAS,eAAe,OAAuB;AACpD,SAAO;AACT;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuB;AAC/E,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,OAAO;AAAA,IAEhB;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/state/modules/is-in-builder.ts"],"sourcesContent":["import { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\nexport type State = boolean\n\nexport function getInitialState(): State {\n return false\n}\n\nexport function getIsInBuilder(state: State): boolean {\n return state\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.SET_IS_IN_BUILDER:\n return action.payload\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA4E;AAIrE,SAAS,kBAAyB;AACvC,SAAO;AACT;AAEO,SAAS,eAAe,OAAuB;AACpD,SAAO;AACT;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,KAAC,8BAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,OAAO;AAAA,IAEhB;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
@@ -23,6 +23,7 @@ __export(is_preview_exports, {
23
23
  reducer: () => reducer
24
24
  });
25
25
  module.exports = __toCommonJS(is_preview_exports);
26
+ var import_actions = require("../actions");
26
27
  function getInitialState(isPreview = false) {
27
28
  return isPreview;
28
29
  }
@@ -30,6 +31,8 @@ function getIsPreview(state) {
30
31
  return state;
31
32
  }
32
33
  function reducer(state = getInitialState(), action) {
34
+ if (!(0, import_actions.isKnownAction)(action))
35
+ return state;
33
36
  switch (action.type) {
34
37
  default:
35
38
  return state;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/is-preview.ts"],"sourcesContent":["import { Action } from '../actions'\n\nexport type State = boolean\n\nexport function getInitialState(isPreview = false): State {\n return isPreview\n}\n\nexport function getIsPreview(state: State): boolean {\n return state\n}\n\nexport function reducer(state = getInitialState(), action: Action): State {\n switch (action.type) {\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,SAAS,gBAAgB,YAAY,OAAc;AACxD,SAAO;AACT;AAEO,SAAS,aAAa,OAAuB;AAClD,SAAO;AACT;AAEO,SAAS,QAAQ,QAAQ,gBAAgB,GAAG,QAAuB;AACxE,UAAQ,OAAO,MAAM;AAAA,IACnB;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/state/modules/is-preview.ts"],"sourcesContent":["import { type Action, type UnknownAction, isKnownAction } from '../actions'\n\nexport type State = boolean\n\nexport function getInitialState(isPreview = false): State {\n return isPreview\n}\n\nexport function getIsPreview(state: State): boolean {\n return state\n}\n\nexport function reducer(state = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA+D;AAIxD,SAAS,gBAAgB,YAAY,OAAc;AACxD,SAAO;AACT;AAEO,SAAS,aAAa,OAAuB;AAClD,SAAO;AACT;AAEO,SAAS,QAAQ,QAAQ,gBAAgB,GAAG,QAAuC;AACxF,MAAI,KAAC,8BAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
@@ -41,6 +41,8 @@ function getLocalizedResourceId(state, locale, resourceId) {
41
41
  return state.get(locale)?.get(resourceId);
42
42
  }
43
43
  function reducer(state = getInitialState(), action) {
44
+ if (!(0, import_actions.isKnownAction)(action))
45
+ return state;
44
46
  switch (action.type) {
45
47
  case import_actions.ActionTypes.SET_LOCALIZED_RESOURCE_ID: {
46
48
  const { resourceId, localizedResourceId, locale } = action.payload;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/localized-resources-map.ts"],"sourcesContent":["import { mapValues } from '@makeswift/controls'\nimport { Action, ActionTypes } from '../actions'\n\ntype State = Map<string, Map<string, string | null>>\n\nexport type SerializedState = {\n [locale: string]: {\n [resourceId: string]: string | null\n }\n}\n\nexport function getInitialState(serializedState: SerializedState = {}): State {\n return new Map(\n Object.entries(mapValues(serializedState, resources => new Map(Object.entries(resources)))),\n )\n}\n\nexport function getSerializedState(state: State): SerializedState {\n return mapValues(Object.fromEntries(state.entries()), resources =>\n Object.fromEntries(resources.entries()),\n )\n}\n\nexport function getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return state.get(locale)?.get(resourceId)\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { resourceId, localizedResourceId, locale } = action.payload\n\n if (locale == null) {\n console.error('Attempt to set a localized resource ID for a non-localized page', {\n resourceId,\n localizedResourceId,\n })\n\n return state\n }\n\n return new Map(state).set(\n locale,\n (state.get(locale) ?? new Map()).set(resourceId, localizedResourceId),\n )\n }\n\n case ActionTypes.UPDATE_API_CLIENT_CACHE: {\n const { localizedResourcesMap } = action.payload\n\n return Object.entries(localizedResourcesMap).reduce((state, [locale, resources]) => {\n const existing = state.get(locale) ?? new Map<string, string | null>()\n const updated = Object.entries(resources).reduce((r, [id, localizedId]) => {\n return r.get(id) != null ? r : new Map(r).set(id, localizedId)\n }, existing)\n\n return updated === existing ? state : new Map(state).set(locale, updated)\n }, state)\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0B;AAC1B,qBAAoC;AAU7B,SAAS,gBAAgB,kBAAmC,CAAC,GAAU;AAC5E,SAAO,IAAI;AAAA,IACT,OAAO,YAAQ,2BAAU,iBAAiB,eAAa,IAAI,IAAI,OAAO,QAAQ,SAAS,CAAC,CAAC,CAAC;AAAA,EAC5F;AACF;AAEO,SAAS,mBAAmB,OAA+B;AAChE,aAAO;AAAA,IAAU,OAAO,YAAY,MAAM,QAAQ,CAAC;AAAA,IAAG,eACpD,OAAO,YAAY,UAAU,QAAQ,CAAC;AAAA,EACxC;AACF;AAEO,SAAS,uBACd,OACA,QACA,YAC2B;AAC3B,SAAO,MAAM,IAAI,MAAM,GAAG,IAAI,UAAU;AAC1C;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuB;AAC/E,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY,2BAA2B;AAC1C,YAAM,EAAE,YAAY,qBAAqB,OAAO,IAAI,OAAO;AAE3D,UAAI,UAAU,MAAM;AAClB,gBAAQ,MAAM,mEAAmE;AAAA,UAC/E;AAAA,UACA;AAAA,QACF,CAAC;AAED,eAAO;AAAA,MACT;AAEA,aAAO,IAAI,IAAI,KAAK,EAAE;AAAA,QACpB;AAAA,SACC,MAAM,IAAI,MAAM,KAAK,oBAAI,IAAI,GAAG,IAAI,YAAY,mBAAmB;AAAA,MACtE;AAAA,IACF;AAAA,IAEA,KAAK,2BAAY,yBAAyB;AACxC,YAAM,EAAE,sBAAsB,IAAI,OAAO;AAEzC,aAAO,OAAO,QAAQ,qBAAqB,EAAE,OAAO,CAACA,QAAO,CAAC,QAAQ,SAAS,MAAM;AAClF,cAAM,WAAWA,OAAM,IAAI,MAAM,KAAK,oBAAI,IAA2B;AACrE,cAAM,UAAU,OAAO,QAAQ,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,WAAW,MAAM;AACzE,iBAAO,EAAE,IAAI,EAAE,KAAK,OAAO,IAAI,IAAI,IAAI,CAAC,EAAE,IAAI,IAAI,WAAW;AAAA,QAC/D,GAAG,QAAQ;AAEX,eAAO,YAAY,WAAWA,SAAQ,IAAI,IAAIA,MAAK,EAAE,IAAI,QAAQ,OAAO;AAAA,MAC1E,GAAG,KAAK;AAAA,IACV;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":["state"]}
1
+ {"version":3,"sources":["../../../../src/state/modules/localized-resources-map.ts"],"sourcesContent":["import { mapValues } from '@makeswift/controls'\nimport { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\ntype State = Map<string, Map<string, string | null>>\n\nexport type SerializedState = {\n [locale: string]: {\n [resourceId: string]: string | null\n }\n}\n\nexport function getInitialState(serializedState: SerializedState = {}): State {\n return new Map(\n Object.entries(mapValues(serializedState, resources => new Map(Object.entries(resources)))),\n )\n}\n\nexport function getSerializedState(state: State): SerializedState {\n return mapValues(Object.fromEntries(state.entries()), resources =>\n Object.fromEntries(resources.entries()),\n )\n}\n\nexport function getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return state.get(locale)?.get(resourceId)\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { resourceId, localizedResourceId, locale } = action.payload\n\n if (locale == null) {\n console.error('Attempt to set a localized resource ID for a non-localized page', {\n resourceId,\n localizedResourceId,\n })\n\n return state\n }\n\n return new Map(state).set(\n locale,\n (state.get(locale) ?? new Map()).set(resourceId, localizedResourceId),\n )\n }\n\n case ActionTypes.UPDATE_API_CLIENT_CACHE: {\n const { localizedResourcesMap } = action.payload\n\n return Object.entries(localizedResourcesMap).reduce((state, [locale, resources]) => {\n const existing = state.get(locale) ?? new Map<string, string | null>()\n const updated = Object.entries(resources).reduce((r, [id, localizedId]) => {\n return r.get(id) != null ? r : new Map(r).set(id, localizedId)\n }, existing)\n\n return updated === existing ? state : new Map(state).set(locale, updated)\n }, state)\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0B;AAC1B,qBAA4E;AAUrE,SAAS,gBAAgB,kBAAmC,CAAC,GAAU;AAC5E,SAAO,IAAI;AAAA,IACT,OAAO,YAAQ,2BAAU,iBAAiB,eAAa,IAAI,IAAI,OAAO,QAAQ,SAAS,CAAC,C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AA,MAC1E,GAAG,KAAK;AAAA,IACV;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":["state"]}
@@ -30,6 +30,8 @@ function getPointer(state) {
30
30
  return state.pointer;
31
31
  }
32
32
  function reducer(state = getInitialState(), action) {
33
+ if (!(0, import_actions.isKnownAction)(action))
34
+ return state;
33
35
  switch (action.type) {
34
36
  case import_actions.ActionTypes.BUILDER_POINTER_MOVE:
35
37
  return { ...state, pointer: action.payload.pointer };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/pointer.ts"],"sourcesContent":["import { Action, ActionTypes } from '../actions'\n\nexport type Point = { x: number; y: number }\n\ntype State = {\n pointer: Point | null\n}\n\nfunction getInitialState(): State {\n return { pointer: null }\n}\n\nexport function getPointer(state: State): Point | null {\n return state.pointer\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.BUILDER_POINTER_MOVE:\n return { ...state, pointer: action.payload.pointer }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAoC;AAQpC,SAAS,kBAAyB;AAChC,SAAO,EAAE,SAAS,KAAK;AACzB;AAEO,SAAS,WAAW,OAA4B;AACrD,SAAO,MAAM;AACf;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuB;AAC/E,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,EAAE,GAAG,OAAO,SAAS,OAAO,QAAQ,QAAQ;AAAA,IAErD;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/state/modules/pointer.ts"],"sourcesContent":["import { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\nexport type Point = { x: number; y: number }\n\ntype State = {\n pointer: Point | null\n}\n\nfunction getInitialState(): State {\n return { pointer: null }\n}\n\nexport function getPointer(state: State): Point | null {\n return state.pointer\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.BUILDER_POINTER_MOVE:\n return { ...state, pointer: action.payload.pointer }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA4E;AAQ5E,SAAS,kBAAyB;AAChC,SAAO,EAAE,SAAS,KAAK;AACzB;AAEO,SAAS,WAAW,OAA4B;AACrD,SAAO,MAAM;AACf;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,KAAC,8BAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,EAAE,GAAG,OAAO,SAAS,OAAO,QAAQ,QAAQ;AAAA,IAErD;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
@@ -46,6 +46,8 @@ function getPropController(state, documentKey, elementKey, propName) {
46
46
  return getPropControllers(state, documentKey, elementKey)?.[propName] ?? null;
47
47
  }
48
48
  function reducer(state = getInitialState(), action) {
49
+ if (!(0, import_actions.isKnownAction)(action))
50
+ return state;
49
51
  switch (action.type) {
50
52
  case import_actions.ActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE: {
51
53
  const { documentKey, elementKey, handle } = action.payload;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/prop-controller-handles.ts"],"sourcesContent":["import { ControlInstance } from '@makeswift/controls'\nimport { Action, ActionTypes } from '../actions'\nimport type { DescriptorsPropControllers } from '../../prop-controllers/instances'\nimport type { Descriptor } from '../../prop-controllers/descriptors'\n\nexport interface PropControllersHandle<\n T extends Record<string, Descriptor> = Record<string, Descriptor>,\n> {\n setPropControllers(propControllers: DescriptorsPropControllers<T> | null): void\n}\n\nexport function isPropControllersHandle(value: unknown): value is PropControllersHandle {\n if (\n typeof value === 'object' &&\n value !== null &&\n 'setPropControllers' in value &&\n typeof (value as { setPropControllers: unknown }).setPropControllers === 'function'\n ) {\n return true\n }\n\n return false\n}\n\nexport type State = {\n handles: Map<string, Map<string, PropControllersHandle>>\n instances: Map<string, Map<string, Record<string, ControlInstance>>>\n}\n\nexport function getInitialState(): State {\n return { handles: new Map(), instances: new Map() }\n}\n\nexport function getPropControllersHandle(\n state: State,\n documentKey: string,\n elementKey: string,\n): PropControllersHandle | null {\n return state.handles.get(documentKey)?.get(elementKey) ?? null\n}\n\nexport function getPropControllers(\n state: State,\n documentKey: string,\n elementKey: string,\n): Record<string, ControlInstance> | null {\n return state.instances.get(documentKey)?.get(elementKey) ?? null\n}\n\nexport function getPropController(\n state: State,\n documentKey: string,\n elementKey: string,\n propName: string,\n): ControlInstance | null {\n return getPropControllers(state, documentKey, elementKey)?.[propName] ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE: {\n const { documentKey, elementKey, handle } = action.payload\n\n return {\n ...state,\n handles: new Map(state.handles).set(\n documentKey,\n new Map(state.handles.get(documentKey) ?? []).set(elementKey, handle),\n ),\n }\n }\n\n case ActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE: {\n const { documentKey, elementKey } = action.payload\n const nextHandles = new Map(state.handles.get(documentKey) ?? [])\n\n const deleted = nextHandles.delete(elementKey)\n\n return deleted\n ? { ...state, handles: new Map(state.handles).set(documentKey, nextHandles) }\n : state\n }\n\n case ActionTypes.REGISTER_PROP_CONTROLLERS: {\n const { documentKey, elementKey, propControllers } = action.payload\n\n return {\n ...state,\n instances: new Map(state.instances).set(\n documentKey,\n new Map(state.instances.get(documentKey) ?? []).set(elementKey, propControllers),\n ),\n }\n }\n\n case ActionTypes.UNREGISTER_PROP_CONTROLLERS: {\n const { documentKey, elementKey } = action.payload\n const nextInstances = new Map(state.instances.get(documentKey) ?? [])\n\n const deleted = nextInstances.delete(elementKey)\n\n return deleted\n ? { ...state, instances: new Map(state.instances).set(documentKey, nextInstances) }\n : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAoC;AAU7B,SAAS,wBAAwB,OAAgD;AACtF,MACE,OAAO,UAAU,YACjB,UAAU,QACV,wBAAwB,SACxB,OAAQ,MAA0C,uBAAuB,YACzE;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAOO,SAAS,kBAAyB;AACvC,SAAO,EAAE,SAAS,oBAAI,IAAI,GAAG,WAAW,oBAAI,IAAI,EAAE;AACpD;AAEO,SAAS,yBACd,OACA,aACA,YAC8B;AAC9B,SAAO,MAAM,QAAQ,IAAI,WAAW,GAAG,IAAI,UAAU,KAAK;AAC5D;AAEO,SAAS,mBACd,OACA,aACA,YACwC;AACxC,SAAO,MAAM,UAAU,IAAI,WAAW,GAAG,IAAI,UAAU,KAAK;AAC9D;AAEO,SAAS,kBACd,OACA,aACA,YACA,UACwB;AACxB,SAAO,mBAAmB,OAAO,aAAa,UAAU,IAAI,QAAQ,KAAK;AAC3E;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuB;AAC/E,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY,kCAAkC;AACjD,YAAM,EAAE,aAAa,YAAY,OAAO,IAAI,OAAO;AAEnD,aAAO;AAAA,QACL,GAAG;AAAA,QACH,SAAS,IAAI,IAAI,MAAM,OAAO,EAAE;AAAA,UAC9B;AAAA,UACA,IAAI,IAAI,MAAM,QAAQ,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,IAAI,YAAY,MAAM;AAAA,QACtE;AAAA,MACF;AAAA,IACF;AAAA,IAEA,KAAK,2BAAY,oCAAoC;AACnD,YAAM,EAAE,aAAa,WAAW,IAAI,OAAO;AAC3C,YAAM,cAAc,IAAI,IAAI,MAAM,QAAQ,IAAI,WAAW,KAAK,CAAC,CAAC;AAEhE,YAAM,UAAU,YAAY,OAAO,UAAU;AAE7C,aAAO,UACH,EAAE,GAAG,OAAO,SAAS,IAAI,IAAI,MAAM,OAAO,EAAE,IAAI,aAAa,WAAW,EAAE,IAC1E;AAAA,IACN;AAAA,IAEA,KAAK,2BAAY,2BAA2B;AAC1C,YAAM,EAAE,aAAa,YAAY,gBAAgB,IAAI,OAAO;AAE5D,aAAO;AAAA,QACL,GAAG;AAAA,QACH,WAAW,IAAI,IAAI,MAAM,SAAS,EAAE;AAAA,UAClC;AAAA,UACA,IAAI,IAAI,MAAM,UAAU,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,IAAI,YAAY,eAAe;AAAA,QACjF;AAAA,MACF;AAAA,IACF;AAAA,IAEA,KAAK,2BAAY,6BAA6B;AAC5C,YAAM,EAAE,aAAa,WAAW,IAAI,OAAO;AAC3C,YAAM,gBAAgB,IAAI,IAAI,MAAM,UAAU,IAAI,WAAW,KAAK,CAAC,CAAC;AAEpE,YAAM,UAAU,cAAc,OAAO,UAAU;AAE/C,aAAO,UACH,EAAE,GAAG,OAAO,WAAW,IAAI,IAAI,MAAM,SAAS,EAAE,IAAI,aAAa,aAAa,EAAE,IAChF;AAAA,IACN;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/state/modules/prop-controller-handles.ts"],"sourcesContent":["import { ControlInstance } from '@makeswift/controls'\nimport { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\nimport type { DescriptorsPropControllers } from '../../prop-controllers/instances'\nimport type { Descriptor } from '../../prop-controllers/descriptors'\n\nexport interface PropControllersHandle<\n T extends Record<string, Descriptor> = Record<string, Descriptor>,\n> {\n setPropControllers(propControllers: DescriptorsPropControllers<T> | null): void\n}\n\nexport function isPropControllersHandle(value: unknown): value is PropControllersHandle {\n if (\n typeof value === 'object' &&\n value !== null &&\n 'setPropControllers' in value &&\n typeof (value as { setPropControllers: unknown }).setPropControllers === 'function'\n ) {\n return true\n }\n\n return false\n}\n\nexport type State = {\n handles: Map<string, Map<string, PropControllersHandle>>\n instances: Map<string, Map<string, Record<string, ControlInstance>>>\n}\n\nexport function getInitialState(): State {\n return { handles: new Map(), instances: new Map() }\n}\n\nexport function getPropControllersHandle(\n state: State,\n documentKey: string,\n elementKey: string,\n): PropControllersHandle | null {\n return state.handles.get(documentKey)?.get(elementKey) ?? null\n}\n\nexport function getPropControllers(\n state: State,\n documentKey: string,\n elementKey: string,\n): Record<string, ControlInstance> | null {\n return state.instances.get(documentKey)?.get(elementKey) ?? null\n}\n\nexport function getPropController(\n state: State,\n documentKey: string,\n elementKey: string,\n propName: string,\n): ControlInstance | null {\n return getPropControllers(state, documentKey, elementKey)?.[propName] ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE: {\n const { documentKey, elementKey, handle } = action.payload\n\n return {\n ...state,\n handles: new Map(state.handles).set(\n documentKey,\n new Map(state.handles.get(documentKey) ?? []).set(elementKey, handle),\n ),\n }\n }\n\n case ActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE: {\n const { documentKey, elementKey } = action.payload\n const nextHandles = new Map(state.handles.get(documentKey) ?? [])\n\n const deleted = nextHandles.delete(elementKey)\n\n return deleted\n ? { ...state, handles: new Map(state.handles).set(documentKey, nextHandles) }\n : state\n }\n\n case ActionTypes.REGISTER_PROP_CONTROLLERS: {\n const { documentKey, elementKey, propControllers } = action.payload\n\n return {\n ...state,\n instances: new Map(state.instances).set(\n documentKey,\n new Map(state.instances.get(documentKey) ?? []).set(elementKey, propControllers),\n ),\n }\n }\n\n case ActionTypes.UNREGISTER_PROP_CONTROLLERS: {\n const { documentKey, elementKey } = action.payload\n const nextInstances = new Map(state.instances.get(documentKey) ?? [])\n\n const deleted = nextInstances.delete(elementKey)\n\n return deleted\n ? { ...state, instances: new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AI,MAAM,QAAQ,IAAI,WAAW,KAAK,CAAC,CAAC;AAEhE,YAAM,UAAU,YAAY,OAAO,UAAU;AAE7C,aAAO,UACH,EAAE,GAAG,OAAO,SAAS,IAAI,IAAI,MAAM,OAAO,EAAE,IAAI,aAAa,WAAW,EAAE,IAC1E;AAAA,IACN;AAAA,IAEA,KAAK,2BAAY,2BAA2B;AAC1C,YAAM,EAAE,aAAa,YAAY,gBAAgB,IAAI,OAAO;AAE5D,aAAO;AAAA,QACL,GAAG;AAAA,QACH,WAAW,IAAI,IAAI,MAAM,SAAS,EAAE;AAAA,UAClC;AAAA,UACA,IAAI,IAAI,MAAM,UAAU,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,IAAI,YAAY,eAAe;AAAA,QACjF;AAAA,MACF;AAAA,IACF;AAAA,IAEA,KAAK,2BAAY,6BAA6B;AAC5C,YAAM,EAAE,aAAa,WAAW,IAAI,OAAO;AAC3C,YAAM,gBAAgB,IAAI,IAAI,MAAM,UAAU,IAAI,WAAW,KAAK,CAAC,CAAC;AAEpE,YAAM,UAAU,cAAc,OAAO,UAAU;AAE/C,aAAO,UACH,EAAE,GAAG,OAAO,WAAW,IAAI,IAAI,MAAM,SAAS,EAAE,IAAI,aAAa,aAAa,EAAE,IAChF;AAAA,IACN;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
@@ -37,6 +37,8 @@ function getComponentPropControllerDescriptors(state, componentType) {
37
37
  return getPropControllerDescriptors(state).get(componentType) ?? null;
38
38
  }
39
39
  function reducer(state = getInitialState(), action) {
40
+ if (!(0, import_actions.isKnownAction)(action))
41
+ return state;
40
42
  switch (action.type) {
41
43
  case import_actions.ActionTypes.REGISTER_COMPONENT:
42
44
  return new Map(state).set(action.payload.type, action.payload.propControllerDescriptors);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/prop-controllers.ts"],"sourcesContent":["import { Action, ActionTypes } from '../actions'\nimport { PropControllerDescriptor } from '../../prop-controllers'\n\nexport type { PropControllerDescriptor }\n\nexport type DescriptorsByProp = Record<string, PropControllerDescriptor>\nexport type DescriptorsByComponentType = Map<string, DescriptorsByProp>\nexport type State = DescriptorsByComponentType\n\nexport function getInitialState({\n propControllerDescriptors = new Map(),\n}: {\n propControllerDescriptors?: State\n} = {}): State {\n return propControllerDescriptors\n}\n\nexport function getPropControllerDescriptors(state: State): State {\n return state\n}\n\nexport function getComponentPropControllerDescriptors(\n state: State,\n componentType: string,\n): DescriptorsByProp | null {\n return getPropControllerDescriptors(state).get(componentType) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT:\n return new Map(state).set(action.payload.type, action.payload.propControllerDescriptors)\n\n case ActionTypes.UNREGISTER_COMPONENT: {\n const nextState = new Map(state)\n const deleted = nextState.delete(action.payload.type)\n return deleted ? nextState : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAoC;AAS7B,SAAS,gBAAgB;AAAA,EAC9B,4BAA4B,oBAAI,IAAI;AACtC,IAEI,CAAC,GAAU;AACb,SAAO;AACT;AAEO,SAAS,6BAA6B,OAAqB;AAChE,SAAO;AACT;AAEO,SAAS,sCACd,OACA,eAC0B;AAC1B,SAAO,6BAA6B,KAAK,EAAE,IAAI,aAAa,KAAK;AACnE;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuB;AAC/E,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,IAAI,IAAI,KAAK,EAAE,IAAI,OAAO,QAAQ,MAAM,OAAO,QAAQ,yBAAyB;AAAA,IAEzF,KAAK,2BAAY,sBAAsB;AACrC,YAAM,YAAY,IAAI,IAAI,KAAK;AAC/B,YAAM,UAAU,UAAU,OAAO,OAAO,QAAQ,IAAI;AACpD,aAAO,UAAU,YAAY;AAAA,IAC/B;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/state/modules/prop-controllers.ts"],"sourcesContent":["import { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\nimport { PropControllerDescriptor } from '../../prop-controllers'\n\nexport type { PropControllerDescriptor }\n\nexport type DescriptorsByProp = Record<string, PropControllerDescriptor>\nexport type DescriptorsByComponentType = Map<string, DescriptorsByProp>\nexport type State = DescriptorsByComponentType\n\nexport function getInitialState({\n propControllerDescriptors = new Map(),\n}: {\n propControllerDescriptors?: State\n} = {}): State {\n return propControllerDescriptors\n}\n\nexport function getPropControllerDescriptors(state: State): State {\n return state\n}\n\nexport function getComponentPropControllerDescriptors(\n state: State,\n componentType: string,\n): DescriptorsByProp | null {\n return getPropControllerDescriptors(state).get(componentType) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT:\n return new Map(state).set(action.payload.type, action.payload.propControllerDescriptors)\n\n case ActionTypes.UNREGISTER_COMPONENT: {\n const nextState = new Map(state)\n const deleted = nextState.delete(action.payload.type)\n return deleted ? nextState : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA4E;AASrE,SAAS,gBAAgB;AAAA,EAC9B,4BAA4B,oBAAI,IAAI;AACtC,IAEI,CAAC,GAAU;AACb,SAAO;AACT;AAEO,SAAS,6BAA6B,OAAqB;AAChE,SAAO;AACT;AAEO,SAAS,sCACd,OACA,eAC0B;AAC1B,SAAO,6BAA6B,KAAK,EAAE,IAAI,aAAa,KAAK;AACnE;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,KAAC,8BAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,IAAI,IAAI,KAAK,EAAE,IAAI,OAAO,QAAQ,MAAM,OAAO,QAAQ,yBAAyB;AAAA,IAEzF,KAAK,2BAAY,sBAAsB;AACrC,YAAM,YAAY,IAAI,IAAI,KAAK;AAC/B,YAAM,UAAU,UAAU,OAAO,OAAO,QAAQ,IAAI;AACpD,aAAO,UAAU,YAAY;AAAA,IAC/B;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
@@ -36,6 +36,8 @@ function getReactComponent(state, type) {
36
36
  return getReactComponents(state).get(type) ?? null;
37
37
  }
38
38
  function reducer(state = getInitialState(), action) {
39
+ if (!(0, import_actions.isKnownAction)(action))
40
+ return state;
39
41
  switch (action.type) {
40
42
  case import_actions.ActionTypes.REGISTER_REACT_COMPONENT:
41
43
  return new Map(state).set(action.payload.type, action.payload.component);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/react-components.tsx"],"sourcesContent":["import type { Component, PropsWithoutRef, ReactNode, RefAttributes } from 'react'\n\nimport { Action, ActionTypes } from '../actions'\n\nexport type ComponentType<P = Record<string, any>, T = any> =\n | { new (props: PropsWithoutRef<P> & RefAttributes<T>, context?: any): Component<P> }\n | ((props: PropsWithoutRef<P> & RefAttributes<T>, context?: any) => ReactNode)\n\nexport type State = Map<string, ComponentType>\n\nexport function getInitialState({\n reactComponents = new Map(),\n}: { reactComponents?: Map<string, ComponentType> } = {}): State {\n return reactComponents\n}\n\nfunction getReactComponents(state: State): Map<string, ComponentType> {\n return state\n}\n\nexport function getReactComponent(state: State, type: string): ComponentType | null {\n return getReactComponents(state).get(type) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action) {\n switch (action.type) {\n case ActionTypes.REGISTER_REACT_COMPONENT:\n return new Map(state).set(action.payload.type, action.payload.component)\n\n case ActionTypes.UNREGISTER_REACT_COMPONENT: {\n const nextState = new Map(state)\n\n const deleted = nextState.delete(action.payload.type)\n\n return deleted ? nextState : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAAoC;AAQ7B,SAAS,gBAAgB;AAAA,EAC9B,kBAAkB,oBAAI,IAAI;AAC5B,IAAsD,CAAC,GAAU;AAC/D,SAAO;AACT;AAEA,SAAS,mBAAmB,OAA0C;AACpE,SAAO;AACT;AAEO,SAAS,kBAAkB,OAAc,MAAoC;AAClF,SAAO,mBAAmB,KAAK,EAAE,IAAI,IAAI,KAAK;AAChD;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAgB;AACxE,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,IAAI,IAAI,KAAK,EAAE,IAAI,OAAO,QAAQ,MAAM,OAAO,QAAQ,SAAS;AAAA,IAEzE,KAAK,2BAAY,4BAA4B;AAC3C,YAAM,YAAY,IAAI,IAAI,KAAK;AAE/B,YAAM,UAAU,UAAU,OAAO,OAAO,QAAQ,IAAI;AAEpD,aAAO,UAAU,YAAY;AAAA,IAC/B;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/state/modules/react-components.tsx"],"sourcesContent":["import type { Component, PropsWithoutRef, ReactNode, RefAttributes } from 'react'\n\nimport { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\nexport type ComponentType<P = Record<string, any>, T = any> =\n | { new (props: PropsWithoutRef<P> & RefAttributes<T>, context?: any): Component<P> }\n | ((props: PropsWithoutRef<P> & RefAttributes<T>, context?: any) => ReactNode)\n\nexport type State = Map<string, ComponentType>\n\nexport function getInitialState({\n reactComponents = new Map(),\n}: { reactComponents?: Map<string, ComponentType> } = {}): State {\n return reactComponents\n}\n\nfunction getReactComponents(state: State): Map<string, ComponentType> {\n return state\n}\n\nexport function getReactComponent(state: State, type: string): ComponentType | null {\n return getReactComponents(state).get(type) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction) {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.REGISTER_REACT_COMPONENT:\n return new Map(state).set(action.payload.type, action.payload.component)\n\n case ActionTypes.UNREGISTER_REACT_COMPONENT: {\n const nextState = new Map(state)\n\n const deleted = nextState.delete(action.payload.type)\n\n return deleted ? nextState : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAA4E;AAQrE,SAAS,gBAAgB;AAAA,EAC9B,kBAAkB,oBAAI,IAAI;AAC5B,IAAsD,CAAC,GAAU;AAC/D,SAAO;AACT;AAEA,SAAS,mBAAmB,OAA0C;AACpE,SAAO;AACT;AAEO,SAAS,kBAAkB,OAAc,MAAoC;AAClF,SAAO,mBAAmB,KAAK,EAAE,IAAI,IAAI,KAAK;AAChD;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAgC;AACxF,MAAI,KAAC,8BAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,2BAAY;AACf,aAAO,IAAI,IAAI,KAAK,EAAE,IAAI,OAAO,QAAQ,MAAM,OAAO,QAAQ,SAAS;AAAA,IAEzE,KAAK,2BAAY,4BAA4B;AAC3C,YAAM,YAAY,IAAI,IAAI,KAAK;AAE/B,YAAM,UAAU,UAAU,OAAO,OAAO,QAAQ,IAAI;AAEpD,aAAO,UAAU,YAAY;AAAA,IAC/B;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
@@ -51,6 +51,8 @@ function getDocument(state, documentKey) {
51
51
  return getDocuments(state).get(documentKey) ?? null;
52
52
  }
53
53
  function reducer(state = getInitialState(), action) {
54
+ if (!(0, import_actions.isKnownAction)(action))
55
+ return state;
54
56
  switch (action.type) {
55
57
  case import_actions.ActionTypes.REGISTER_DOCUMENT:
56
58
  const { documentKey, document } = action.payload;