@makeswift/runtime 0.24.0-canary.0 → 0.24.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 (484) hide show
  1. package/dist/cjs/api/react.js +28 -7
  2. package/dist/cjs/api/react.js.map +1 -1
  3. package/dist/cjs/api/site-version.js +36 -0
  4. package/dist/cjs/api/site-version.js.map +1 -0
  5. package/dist/cjs/components/builtin/Box/register.js +3 -3
  6. package/dist/cjs/components/builtin/Box/register.js.map +1 -1
  7. package/dist/cjs/components/builtin/Button/register.js +2 -2
  8. package/dist/cjs/components/builtin/Button/register.js.map +1 -1
  9. package/dist/cjs/components/builtin/Carousel/Carousel.js +6 -5
  10. package/dist/cjs/components/builtin/Carousel/Carousel.js.map +1 -1
  11. package/dist/cjs/components/builtin/Carousel/register.js +2 -2
  12. package/dist/cjs/components/builtin/Carousel/register.js.map +1 -1
  13. package/dist/cjs/components/builtin/Countdown/register.js +2 -2
  14. package/dist/cjs/components/builtin/Countdown/register.js.map +1 -1
  15. package/dist/cjs/components/builtin/Form/register.js +4 -4
  16. package/dist/cjs/components/builtin/Form/register.js.map +1 -1
  17. package/dist/cjs/components/builtin/Image/Image.js +3 -3
  18. package/dist/cjs/components/builtin/Image/Image.js.map +1 -1
  19. package/dist/cjs/components/builtin/Navigation/register.js +4 -4
  20. package/dist/cjs/components/builtin/Navigation/register.js.map +1 -1
  21. package/dist/cjs/components/builtin/SocialLinks/register.js +3 -3
  22. package/dist/cjs/components/builtin/SocialLinks/register.js.map +1 -1
  23. package/dist/cjs/components/builtin/Text/register.js +3 -3
  24. package/dist/cjs/components/builtin/Text/register.js.map +1 -1
  25. package/dist/cjs/components/hooks/useMediaQuery.js +5 -5
  26. package/dist/cjs/components/hooks/useMediaQuery.js.map +1 -1
  27. package/dist/cjs/components/page/Page.js +7 -4
  28. package/dist/cjs/components/page/Page.js.map +1 -1
  29. package/dist/cjs/components/page/PageHead.js +17 -8
  30. package/dist/cjs/components/page/PageHead.js.map +1 -1
  31. package/dist/cjs/components/page/page-seo-settings.js +43 -0
  32. package/dist/cjs/components/page/page-seo-settings.js.map +1 -0
  33. package/dist/cjs/components/shared/Link/index.js +3 -1
  34. package/dist/cjs/components/shared/Link/index.js.map +1 -1
  35. package/dist/cjs/components/utils/responsive-style.js +2 -3
  36. package/dist/cjs/components/utils/responsive-style.js.map +1 -1
  37. package/dist/cjs/core/index.js +18 -2
  38. package/dist/cjs/core/index.js.map +1 -1
  39. package/dist/cjs/jest-setup.js +3 -0
  40. package/dist/cjs/jest-setup.js.map +1 -1
  41. package/dist/cjs/locale.js +79 -0
  42. package/dist/cjs/locale.js.map +1 -1
  43. package/dist/cjs/next/api-handler/handlers/clear-draft.js +64 -0
  44. package/dist/cjs/next/api-handler/handlers/clear-draft.js.map +1 -0
  45. package/dist/cjs/next/api-handler/handlers/manifest.js +3 -2
  46. package/dist/cjs/next/api-handler/handlers/manifest.js.map +1 -1
  47. package/dist/cjs/next/api-handler/handlers/redirect-draft.js +77 -0
  48. package/dist/cjs/next/api-handler/handlers/redirect-draft.js.map +1 -0
  49. package/dist/cjs/next/api-handler/handlers/redirect-preview.js +67 -0
  50. package/dist/cjs/next/api-handler/handlers/redirect-preview.js.map +1 -0
  51. package/dist/cjs/next/api-handler/handlers/utils/draft.js +53 -0
  52. package/dist/cjs/next/api-handler/handlers/utils/draft.js.map +1 -0
  53. package/dist/cjs/next/api-handler/handlers/webhook/index.js +3 -3
  54. package/dist/cjs/next/api-handler/handlers/webhook/index.js.map +1 -1
  55. package/dist/cjs/next/api-handler/handlers/webhook/site-published.js +8 -5
  56. package/dist/cjs/next/api-handler/handlers/webhook/site-published.js.map +1 -1
  57. package/dist/cjs/next/api-handler/handlers/webhook/types.js.map +1 -1
  58. package/dist/cjs/next/api-handler/index.js +24 -9
  59. package/dist/cjs/next/api-handler/index.js.map +1 -1
  60. package/dist/cjs/next/cache.js +29 -0
  61. package/dist/cjs/next/cache.js.map +1 -0
  62. package/dist/cjs/next/client.js +135 -60
  63. package/dist/cjs/next/client.js.map +1 -1
  64. package/dist/cjs/next/components/page.js +3 -2
  65. package/dist/cjs/next/components/page.js.map +1 -1
  66. package/dist/cjs/next/components/tests/controls/color-control/fixtures.js +51 -0
  67. package/dist/cjs/next/components/tests/controls/color-control/fixtures.js.map +1 -0
  68. package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js +91 -35
  69. package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
  70. package/dist/cjs/next/components/tests/controls/rich-text-v2-control/fixtures.js +91 -0
  71. package/dist/cjs/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -0
  72. package/dist/cjs/next/components/tests/controls/style-control/fixtures.js +60 -0
  73. package/dist/cjs/next/components/tests/controls/style-control/fixtures.js.map +1 -0
  74. package/dist/cjs/next/components/tests/prop-controllers/page-prop-controller.js +20 -11
  75. package/dist/cjs/next/components/tests/prop-controllers/page-prop-controller.js.map +1 -1
  76. package/dist/cjs/next/document.js +1 -3
  77. package/dist/cjs/next/document.js.map +1 -1
  78. package/dist/cjs/next/draft-mode/index.js +3 -3
  79. package/dist/cjs/next/draft-mode/index.js.map +1 -1
  80. package/dist/cjs/next/hooks/use-is-pages-router.js.map +1 -1
  81. package/dist/cjs/next/index.js +0 -3
  82. package/dist/cjs/next/index.js.map +1 -1
  83. package/dist/cjs/next/middleware/index.js +29 -0
  84. package/dist/cjs/next/middleware/index.js.map +1 -0
  85. package/dist/cjs/next/middleware/request-utils.js +49 -0
  86. package/dist/cjs/next/middleware/request-utils.js.map +1 -0
  87. package/dist/cjs/next/preview-mode.js +4 -110
  88. package/dist/cjs/next/preview-mode.js.map +1 -1
  89. package/dist/cjs/next/root-style-registry.js +24 -20
  90. package/dist/cjs/next/root-style-registry.js.map +1 -1
  91. package/dist/cjs/next/server.js +0 -3
  92. package/dist/cjs/next/server.js.map +1 -1
  93. package/dist/cjs/next/tests/test-utils.js +61 -0
  94. package/dist/cjs/next/tests/test-utils.js.map +1 -0
  95. package/dist/cjs/runtimes/react/components/Document.js +1 -1
  96. package/dist/cjs/runtimes/react/components/Document.js.map +1 -1
  97. package/dist/cjs/runtimes/react/components/ElementData.js +1 -0
  98. package/dist/cjs/runtimes/react/components/ElementData.js.map +1 -1
  99. package/dist/cjs/runtimes/react/components/RuntimeProvider.js +14 -3
  100. package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
  101. package/dist/cjs/runtimes/react/components/draft-switcher/draft-switcher.js +72 -0
  102. package/dist/cjs/runtimes/react/components/draft-switcher/draft-switcher.js.map +1 -0
  103. package/dist/cjs/runtimes/react/components/draft-switcher/draft-toolbar.js +79 -0
  104. package/dist/cjs/runtimes/react/components/draft-switcher/draft-toolbar.js.map +1 -0
  105. package/dist/cjs/runtimes/react/components/hooks/use-builder-connection-ping.js +67 -0
  106. package/dist/cjs/runtimes/react/components/hooks/use-builder-connection-ping.js.map +1 -0
  107. package/dist/cjs/runtimes/react/components/hooks/use-builder-handshake.js +45 -0
  108. package/dist/cjs/runtimes/react/components/hooks/use-builder-handshake.js.map +1 -0
  109. package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.js +1 -1
  110. package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.js.map +1 -1
  111. package/dist/cjs/runtimes/react/hooks/use-cache-data.js +2 -2
  112. package/dist/cjs/runtimes/react/hooks/use-cache-data.js.map +1 -1
  113. package/dist/cjs/runtimes/react/hooks/use-document-context.js +8 -13
  114. package/dist/cjs/runtimes/react/hooks/use-document-context.js.map +1 -1
  115. package/dist/cjs/runtimes/react/hooks/use-register-document.js +8 -1
  116. package/dist/cjs/runtimes/react/hooks/use-register-document.js.map +1 -1
  117. package/dist/cjs/runtimes/react/hooks/use-resolvable-record.js +68 -0
  118. package/dist/cjs/runtimes/react/hooks/use-resolvable-record.js.map +1 -0
  119. package/dist/cjs/runtimes/react/hooks/use-resolved-props.js +6 -5
  120. package/dist/cjs/runtimes/react/hooks/use-resolved-props.js.map +1 -1
  121. package/dist/cjs/runtimes/react/hooks/use-resolved-value.js +1 -1
  122. package/dist/cjs/runtimes/react/hooks/use-resolved-value.js.map +1 -1
  123. package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js +2 -1
  124. package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
  125. package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js +1 -2
  126. package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -1
  127. package/dist/cjs/runtimes/react/host-api-client.js +5 -1
  128. package/dist/cjs/runtimes/react/host-api-client.js.map +1 -1
  129. package/dist/cjs/{utils/tests/breakpoint-test-util.js → runtimes/react/testing/breakpoints.js} +4 -4
  130. package/dist/cjs/runtimes/react/testing/breakpoints.js.map +1 -0
  131. package/dist/cjs/{utils/tests/element-data-test-test.js → runtimes/react/testing/element-data.js} +33 -7
  132. package/dist/cjs/runtimes/react/testing/element-data.js.map +1 -0
  133. package/dist/cjs/runtimes/react/testing/index.js +27 -0
  134. package/dist/cjs/runtimes/react/testing/index.js.map +1 -0
  135. package/dist/cjs/runtimes/react/testing/react-provider.js +38 -0
  136. package/dist/cjs/runtimes/react/testing/react-provider.js.map +1 -0
  137. package/dist/cjs/runtimes/react/use-style.js +2 -2
  138. package/dist/cjs/runtimes/react/use-style.js.map +1 -1
  139. package/dist/cjs/slate/BlockPlugin/setBlockKeyForDevice.js +1 -2
  140. package/dist/cjs/slate/BlockPlugin/setBlockKeyForDevice.js.map +1 -1
  141. package/dist/cjs/slate/TypographyPlugin/setActiveTypographyStyle.js +2 -2
  142. package/dist/cjs/slate/TypographyPlugin/setActiveTypographyStyle.js.map +1 -1
  143. package/dist/cjs/slate/selectors.js +2 -3
  144. package/dist/cjs/slate/selectors.js.map +1 -1
  145. package/dist/cjs/state/makeswift-api-client.js +23 -12
  146. package/dist/cjs/state/makeswift-api-client.js.map +1 -1
  147. package/dist/cjs/state/modules/breakpoints.js +1 -44
  148. package/dist/cjs/state/modules/breakpoints.js.map +1 -1
  149. package/dist/cjs/state/modules/element-trees.js +10 -7
  150. package/dist/cjs/state/modules/element-trees.js.map +1 -1
  151. package/dist/esm/api/react.js +28 -7
  152. package/dist/esm/api/react.js.map +1 -1
  153. package/dist/esm/api/site-version.js +10 -0
  154. package/dist/esm/api/site-version.js.map +1 -0
  155. package/dist/esm/components/builtin/Box/register.js +1 -1
  156. package/dist/esm/components/builtin/Box/register.js.map +1 -1
  157. package/dist/esm/components/builtin/Button/register.js +1 -1
  158. package/dist/esm/components/builtin/Button/register.js.map +1 -1
  159. package/dist/esm/components/builtin/Carousel/Carousel.js +5 -4
  160. package/dist/esm/components/builtin/Carousel/Carousel.js.map +1 -1
  161. package/dist/esm/components/builtin/Carousel/register.js +1 -1
  162. package/dist/esm/components/builtin/Carousel/register.js.map +1 -1
  163. package/dist/esm/components/builtin/Countdown/register.js +1 -1
  164. package/dist/esm/components/builtin/Countdown/register.js.map +1 -1
  165. package/dist/esm/components/builtin/Form/register.js +1 -1
  166. package/dist/esm/components/builtin/Form/register.js.map +1 -1
  167. package/dist/esm/components/builtin/Image/Image.js +1 -1
  168. package/dist/esm/components/builtin/Image/Image.js.map +1 -1
  169. package/dist/esm/components/builtin/Navigation/register.js +1 -1
  170. package/dist/esm/components/builtin/Navigation/register.js.map +1 -1
  171. package/dist/esm/components/builtin/SocialLinks/register.js +1 -1
  172. package/dist/esm/components/builtin/SocialLinks/register.js.map +1 -1
  173. package/dist/esm/components/builtin/Text/register.js +1 -1
  174. package/dist/esm/components/builtin/Text/register.js.map +1 -1
  175. package/dist/esm/components/hooks/useMediaQuery.js +1 -1
  176. package/dist/esm/components/hooks/useMediaQuery.js.map +1 -1
  177. package/dist/esm/components/page/Page.js +5 -2
  178. package/dist/esm/components/page/Page.js.map +1 -1
  179. package/dist/esm/components/page/PageHead.js +17 -8
  180. package/dist/esm/components/page/PageHead.js.map +1 -1
  181. package/dist/esm/components/page/page-seo-settings.js +19 -0
  182. package/dist/esm/components/page/page-seo-settings.js.map +1 -0
  183. package/dist/esm/components/shared/Link/index.js +3 -1
  184. package/dist/esm/components/shared/Link/index.js.map +1 -1
  185. package/dist/esm/components/utils/responsive-style.js +3 -2
  186. package/dist/esm/components/utils/responsive-style.js.map +1 -1
  187. package/dist/esm/core/index.js +18 -2
  188. package/dist/esm/core/index.js.map +1 -1
  189. package/dist/esm/jest-setup.js +4 -1
  190. package/dist/esm/jest-setup.js.map +1 -1
  191. package/dist/esm/locale.js +79 -0
  192. package/dist/esm/locale.js.map +1 -1
  193. package/dist/esm/next/api-handler/handlers/clear-draft.js +50 -0
  194. package/dist/esm/next/api-handler/handlers/clear-draft.js.map +1 -0
  195. package/dist/esm/next/api-handler/handlers/manifest.js +3 -2
  196. package/dist/esm/next/api-handler/handlers/manifest.js.map +1 -1
  197. package/dist/esm/next/api-handler/handlers/redirect-draft.js +63 -0
  198. package/dist/esm/next/api-handler/handlers/redirect-draft.js.map +1 -0
  199. package/dist/esm/next/api-handler/handlers/redirect-preview.js +53 -0
  200. package/dist/esm/next/api-handler/handlers/redirect-preview.js.map +1 -0
  201. package/dist/esm/next/api-handler/handlers/utils/draft.js +24 -0
  202. package/dist/esm/next/api-handler/handlers/utils/draft.js.map +1 -0
  203. package/dist/esm/next/api-handler/handlers/webhook/index.js +3 -3
  204. package/dist/esm/next/api-handler/handlers/webhook/index.js.map +1 -1
  205. package/dist/esm/next/api-handler/handlers/webhook/site-published.js +7 -3
  206. package/dist/esm/next/api-handler/handlers/webhook/site-published.js.map +1 -1
  207. package/dist/esm/next/api-handler/handlers/webhook/types.js.map +1 -1
  208. package/dist/esm/next/api-handler/index.js +28 -9
  209. package/dist/esm/next/api-handler/index.js.map +1 -1
  210. package/dist/esm/next/cache.js +5 -0
  211. package/dist/esm/next/cache.js.map +1 -0
  212. package/dist/esm/next/client.js +128 -54
  213. package/dist/esm/next/client.js.map +1 -1
  214. package/dist/esm/next/components/page.js +3 -2
  215. package/dist/esm/next/components/page.js.map +1 -1
  216. package/dist/esm/next/components/tests/controls/color-control/fixtures.js +24 -0
  217. package/dist/esm/next/components/tests/controls/color-control/fixtures.js.map +1 -0
  218. package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js +82 -39
  219. package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
  220. package/dist/esm/next/components/tests/controls/rich-text-v2-control/fixtures.js +56 -0
  221. package/dist/esm/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -0
  222. package/dist/esm/next/components/tests/controls/style-control/fixtures.js +35 -0
  223. package/dist/esm/next/components/tests/controls/style-control/fixtures.js.map +1 -0
  224. package/dist/esm/next/components/tests/prop-controllers/page-prop-controller.js +7 -11
  225. package/dist/esm/next/components/tests/prop-controllers/page-prop-controller.js.map +1 -1
  226. package/dist/esm/next/document.js +1 -3
  227. package/dist/esm/next/document.js.map +1 -1
  228. package/dist/esm/next/draft-mode/index.js +1 -1
  229. package/dist/esm/next/draft-mode/index.js.map +1 -1
  230. package/dist/esm/next/hooks/use-is-pages-router.js.map +1 -1
  231. package/dist/esm/next/index.js +0 -2
  232. package/dist/esm/next/index.js.map +1 -1
  233. package/dist/esm/next/middleware/index.js +5 -0
  234. package/dist/esm/next/middleware/index.js.map +1 -0
  235. package/dist/esm/next/middleware/request-utils.js +28 -0
  236. package/dist/esm/next/middleware/request-utils.js.map +1 -0
  237. package/dist/esm/next/preview-mode.js +2 -105
  238. package/dist/esm/next/preview-mode.js.map +1 -1
  239. package/dist/esm/next/root-style-registry.js +24 -20
  240. package/dist/esm/next/root-style-registry.js.map +1 -1
  241. package/dist/esm/next/server.js +0 -2
  242. package/dist/esm/next/server.js.map +1 -1
  243. package/dist/esm/next/tests/test-utils.js +37 -0
  244. package/dist/esm/next/tests/test-utils.js.map +1 -0
  245. package/dist/esm/runtimes/react/components/Document.js +2 -2
  246. package/dist/esm/runtimes/react/components/Document.js.map +1 -1
  247. package/dist/esm/runtimes/react/components/ElementData.js +1 -0
  248. package/dist/esm/runtimes/react/components/ElementData.js.map +1 -1
  249. package/dist/esm/runtimes/react/components/RuntimeProvider.js +15 -4
  250. package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
  251. package/dist/esm/runtimes/react/components/draft-switcher/draft-switcher.js +48 -0
  252. package/dist/esm/runtimes/react/components/draft-switcher/draft-switcher.js.map +1 -0
  253. package/dist/esm/runtimes/react/components/draft-switcher/draft-toolbar.js +55 -0
  254. package/dist/esm/runtimes/react/components/draft-switcher/draft-toolbar.js.map +1 -0
  255. package/dist/esm/runtimes/react/components/hooks/use-builder-connection-ping.js +43 -0
  256. package/dist/esm/runtimes/react/components/hooks/use-builder-connection-ping.js.map +1 -0
  257. package/dist/esm/runtimes/react/components/hooks/use-builder-handshake.js +21 -0
  258. package/dist/esm/runtimes/react/components/hooks/use-builder-handshake.js.map +1 -0
  259. package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.js +2 -2
  260. package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.js.map +1 -1
  261. package/dist/esm/runtimes/react/hooks/use-cache-data.js +2 -2
  262. package/dist/esm/runtimes/react/hooks/use-cache-data.js.map +1 -1
  263. package/dist/esm/runtimes/react/hooks/use-document-context.js +6 -11
  264. package/dist/esm/runtimes/react/hooks/use-document-context.js.map +1 -1
  265. package/dist/esm/runtimes/react/hooks/use-register-document.js +9 -2
  266. package/dist/esm/runtimes/react/hooks/use-register-document.js.map +1 -1
  267. package/dist/esm/runtimes/react/hooks/use-resolvable-record.js +44 -0
  268. package/dist/esm/runtimes/react/hooks/use-resolvable-record.js.map +1 -0
  269. package/dist/esm/runtimes/react/hooks/use-resolved-props.js +6 -5
  270. package/dist/esm/runtimes/react/hooks/use-resolved-props.js.map +1 -1
  271. package/dist/esm/runtimes/react/hooks/use-resolved-value.js +1 -1
  272. package/dist/esm/runtimes/react/hooks/use-resolved-value.js.map +1 -1
  273. package/dist/esm/runtimes/react/hooks/use-resource-resolver.js +3 -2
  274. package/dist/esm/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
  275. package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js +2 -2
  276. package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -1
  277. package/dist/esm/runtimes/react/host-api-client.js +5 -1
  278. package/dist/esm/runtimes/react/host-api-client.js.map +1 -1
  279. package/dist/esm/{utils/tests/breakpoint-test-util.js → runtimes/react/testing/breakpoints.js} +1 -1
  280. package/dist/esm/runtimes/react/testing/breakpoints.js.map +1 -0
  281. package/dist/esm/{utils/tests/element-data-test-test.js → runtimes/react/testing/element-data.js} +29 -4
  282. package/dist/esm/runtimes/react/testing/element-data.js.map +1 -0
  283. package/dist/esm/runtimes/react/testing/index.js +4 -0
  284. package/dist/esm/runtimes/react/testing/index.js.map +1 -0
  285. package/dist/esm/runtimes/react/testing/react-provider.js +14 -0
  286. package/dist/esm/runtimes/react/testing/react-provider.js.map +1 -0
  287. package/dist/esm/runtimes/react/use-style.js +2 -2
  288. package/dist/esm/runtimes/react/use-style.js.map +1 -1
  289. package/dist/esm/slate/BlockPlugin/setBlockKeyForDevice.js +4 -2
  290. package/dist/esm/slate/BlockPlugin/setBlockKeyForDevice.js.map +1 -1
  291. package/dist/esm/slate/TypographyPlugin/setActiveTypographyStyle.js +3 -1
  292. package/dist/esm/slate/TypographyPlugin/setActiveTypographyStyle.js.map +1 -1
  293. package/dist/esm/slate/selectors.js +4 -2
  294. package/dist/esm/slate/selectors.js.map +1 -1
  295. package/dist/esm/state/makeswift-api-client.js +22 -11
  296. package/dist/esm/state/makeswift-api-client.js.map +1 -1
  297. package/dist/esm/state/modules/breakpoints.js +1 -42
  298. package/dist/esm/state/modules/breakpoints.js.map +1 -1
  299. package/dist/esm/state/modules/element-trees.js +10 -7
  300. package/dist/esm/state/modules/element-trees.js.map +1 -1
  301. package/dist/types/api/react.d.ts +4 -1
  302. package/dist/types/api/react.d.ts.map +1 -1
  303. package/dist/types/api/site-version.d.ts +6 -0
  304. package/dist/types/api/site-version.d.ts.map +1 -0
  305. package/dist/types/components/builtin/Box/register.d.ts.map +1 -1
  306. package/dist/types/components/builtin/Button/register.d.ts.map +1 -1
  307. package/dist/types/components/builtin/Carousel/Carousel.d.ts.map +1 -1
  308. package/dist/types/components/builtin/Image/Image.d.ts.map +1 -1
  309. package/dist/types/components/hooks/useMediaQuery.d.ts +1 -1
  310. package/dist/types/components/hooks/useMediaQuery.d.ts.map +1 -1
  311. package/dist/types/components/page/Page.d.ts +3 -1
  312. package/dist/types/components/page/Page.d.ts.map +1 -1
  313. package/dist/types/components/page/PageHead.d.ts +3 -1
  314. package/dist/types/components/page/PageHead.d.ts.map +1 -1
  315. package/dist/types/components/page/page-seo-settings.d.ts +11 -0
  316. package/dist/types/components/page/page-seo-settings.d.ts.map +1 -0
  317. package/dist/types/components/shared/Link/index.d.ts.map +1 -1
  318. package/dist/types/components/utils/responsive-style.d.ts +1 -1
  319. package/dist/types/components/utils/responsive-style.d.ts.map +1 -1
  320. package/dist/types/controls/link.d.ts +1 -1
  321. package/dist/types/core/index.d.ts +1 -1
  322. package/dist/types/core/index.d.ts.map +1 -1
  323. package/dist/types/locale.d.ts +3 -3
  324. package/dist/types/locale.d.ts.map +1 -1
  325. package/dist/types/next/api-handler/handlers/clear-draft.d.ts +20 -0
  326. package/dist/types/next/api-handler/handlers/clear-draft.d.ts.map +1 -0
  327. package/dist/types/next/api-handler/handlers/manifest.d.ts +1 -0
  328. package/dist/types/next/api-handler/handlers/manifest.d.ts.map +1 -1
  329. package/dist/types/next/api-handler/handlers/redirect-draft.d.ts +18 -0
  330. package/dist/types/next/api-handler/handlers/redirect-draft.d.ts.map +1 -0
  331. package/dist/types/next/api-handler/handlers/redirect-preview.d.ts +18 -0
  332. package/dist/types/next/api-handler/handlers/redirect-preview.d.ts.map +1 -0
  333. package/dist/types/next/api-handler/handlers/utils/draft.d.ts +16 -0
  334. package/dist/types/next/api-handler/handlers/utils/draft.d.ts.map +1 -0
  335. package/dist/types/next/api-handler/handlers/webhook/index.d.ts +9 -11
  336. package/dist/types/next/api-handler/handlers/webhook/index.d.ts.map +1 -1
  337. package/dist/types/next/api-handler/handlers/webhook/site-published.d.ts +6 -3
  338. package/dist/types/next/api-handler/handlers/webhook/site-published.d.ts.map +1 -1
  339. package/dist/types/next/api-handler/handlers/webhook/types.d.ts +13 -12
  340. package/dist/types/next/api-handler/handlers/webhook/types.d.ts.map +1 -1
  341. package/dist/types/next/api-handler/index.d.ts +10 -5
  342. package/dist/types/next/api-handler/index.d.ts.map +1 -1
  343. package/dist/types/next/cache.d.ts +2 -0
  344. package/dist/types/next/cache.d.ts.map +1 -0
  345. package/dist/types/next/client.d.ts +14 -12
  346. package/dist/types/next/client.d.ts.map +1 -1
  347. package/dist/types/next/components/page.d.ts +21 -1
  348. package/dist/types/next/components/page.d.ts.map +1 -1
  349. package/dist/types/next/components/tests/controls/color-control/client.test.d.ts +3 -0
  350. package/dist/types/next/components/tests/controls/color-control/client.test.d.ts.map +1 -0
  351. package/dist/types/next/components/tests/controls/color-control/fixtures.d.ts +11 -0
  352. package/dist/types/next/components/tests/controls/color-control/fixtures.d.ts.map +1 -0
  353. package/dist/types/next/components/tests/controls/color-control/server.test.d.ts +2 -0
  354. package/dist/types/next/components/tests/controls/color-control/server.test.d.ts.map +1 -0
  355. package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts +2 -3
  356. package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts.map +1 -1
  357. package/dist/types/next/components/tests/controls/rich-text-v2-control/client.test.d.ts +2 -0
  358. package/dist/types/next/components/tests/controls/rich-text-v2-control/client.test.d.ts.map +1 -0
  359. package/dist/types/next/components/tests/controls/rich-text-v2-control/fixtures.d.ts +42 -0
  360. package/dist/types/next/components/tests/controls/rich-text-v2-control/fixtures.d.ts.map +1 -0
  361. package/dist/types/next/components/tests/controls/rich-text-v2-control/server.test.d.ts +2 -0
  362. package/dist/types/next/components/tests/controls/rich-text-v2-control/server.test.d.ts.map +1 -0
  363. package/dist/types/next/components/tests/controls/style-control/client.test.d.ts +2 -0
  364. package/dist/types/next/components/tests/controls/style-control/client.test.d.ts.map +1 -0
  365. package/dist/types/next/components/tests/controls/style-control/fixtures.d.ts +6 -0
  366. package/dist/types/next/components/tests/controls/style-control/fixtures.d.ts.map +1 -0
  367. package/dist/types/next/components/tests/controls/style-control/server.test.d.ts +2 -0
  368. package/dist/types/next/components/tests/controls/style-control/server.test.d.ts.map +1 -0
  369. package/dist/types/next/components/tests/makeswift-page-metadata-rendering.test.d.ts +3 -0
  370. package/dist/types/next/components/tests/makeswift-page-metadata-rendering.test.d.ts.map +1 -0
  371. package/dist/types/next/components/tests/prop-controllers/page-prop-controller.d.ts.map +1 -1
  372. package/dist/types/next/document.d.ts +1 -5
  373. package/dist/types/next/document.d.ts.map +1 -1
  374. package/dist/types/next/draft-mode/index.d.ts +2 -2
  375. package/dist/types/next/hooks/use-is-pages-router.d.ts.map +1 -1
  376. package/dist/types/next/index.d.ts +0 -1
  377. package/dist/types/next/index.d.ts.map +1 -1
  378. package/dist/types/next/middleware/index.d.ts +2 -0
  379. package/dist/types/next/middleware/index.d.ts.map +1 -0
  380. package/dist/types/next/middleware/request-utils.d.ts +3 -0
  381. package/dist/types/next/middleware/request-utils.d.ts.map +1 -0
  382. package/dist/types/next/middleware/request-utils.test.d.ts +2 -0
  383. package/dist/types/next/middleware/request-utils.test.d.ts.map +1 -0
  384. package/dist/types/next/preview-mode.d.ts +3 -10
  385. package/dist/types/next/preview-mode.d.ts.map +1 -1
  386. package/dist/types/next/root-style-registry.d.ts +2 -1
  387. package/dist/types/next/root-style-registry.d.ts.map +1 -1
  388. package/dist/types/next/server.d.ts +0 -1
  389. package/dist/types/next/server.d.ts.map +1 -1
  390. package/dist/types/next/tests/client.error-handling.test.d.ts +2 -0
  391. package/dist/types/next/tests/client.error-handling.test.d.ts.map +1 -0
  392. package/dist/types/next/tests/client.get-page-snapshot.test.d.ts +2 -0
  393. package/dist/types/next/tests/client.get-page-snapshot.test.d.ts.map +1 -0
  394. package/dist/types/next/tests/client.get-resources.test.d.ts +2 -0
  395. package/dist/types/next/tests/client.get-resources.test.d.ts.map +1 -0
  396. package/dist/types/next/tests/server.makeswift-api-handler.test.d.ts +2 -0
  397. package/dist/types/next/tests/server.makeswift-api-handler.test.d.ts.map +1 -0
  398. package/dist/types/next/tests/test-utils.d.ts +8 -0
  399. package/dist/types/next/tests/test-utils.d.ts.map +1 -0
  400. package/dist/types/runtimes/react/components/Document.d.ts.map +1 -1
  401. package/dist/types/runtimes/react/components/ElementData.d.ts.map +1 -1
  402. package/dist/types/runtimes/react/components/RuntimeProvider.d.ts +2 -1
  403. package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
  404. package/dist/types/runtimes/react/components/draft-switcher/draft-switcher.d.ts +4 -0
  405. package/dist/types/runtimes/react/components/draft-switcher/draft-switcher.d.ts.map +1 -0
  406. package/dist/types/runtimes/react/components/draft-switcher/draft-toolbar.d.ts +6 -0
  407. package/dist/types/runtimes/react/components/draft-switcher/draft-toolbar.d.ts.map +1 -0
  408. package/dist/types/runtimes/react/components/hooks/use-builder-connection-ping.d.ts +4 -0
  409. package/dist/types/runtimes/react/components/hooks/use-builder-connection-ping.d.ts.map +1 -0
  410. package/dist/types/runtimes/react/components/hooks/use-builder-handshake.d.ts +4 -0
  411. package/dist/types/runtimes/react/components/hooks/use-builder-handshake.d.ts.map +1 -0
  412. package/dist/types/runtimes/react/hooks/use-cache-data.d.ts.map +1 -1
  413. package/dist/types/runtimes/react/hooks/use-document-context.d.ts +2 -7
  414. package/dist/types/runtimes/react/hooks/use-document-context.d.ts.map +1 -1
  415. package/dist/types/runtimes/react/hooks/use-register-document.d.ts.map +1 -1
  416. package/dist/types/runtimes/react/hooks/use-resolvable-record.d.ts +3 -0
  417. package/dist/types/runtimes/react/hooks/use-resolvable-record.d.ts.map +1 -0
  418. package/dist/types/runtimes/react/hooks/use-resolved-props.d.ts.map +1 -1
  419. package/dist/types/runtimes/react/hooks/use-resource-resolver.d.ts.map +1 -1
  420. package/dist/types/runtimes/react/hooks/use-stylesheet-factory.d.ts.map +1 -1
  421. package/dist/types/runtimes/react/host-api-client.d.ts.map +1 -1
  422. package/dist/types/{utils/tests/breakpoint-test-util.d.ts → runtimes/react/testing/breakpoints.d.ts} +1 -1
  423. package/dist/types/runtimes/react/testing/breakpoints.d.ts.map +1 -0
  424. package/dist/types/{utils/tests/element-data-test-test.d.ts → runtimes/react/testing/element-data.d.ts} +7 -3
  425. package/dist/types/runtimes/react/testing/element-data.d.ts.map +1 -0
  426. package/dist/types/runtimes/react/testing/index.d.ts +4 -0
  427. package/dist/types/runtimes/react/testing/index.d.ts.map +1 -0
  428. package/dist/types/runtimes/react/testing/react-provider.d.ts +8 -0
  429. package/dist/types/runtimes/react/testing/react-provider.d.ts.map +1 -0
  430. package/dist/types/slate/BlockPlugin/setBlockKeyForDevice.d.ts +1 -1
  431. package/dist/types/slate/BlockPlugin/setBlockKeyForDevice.d.ts.map +1 -1
  432. package/dist/types/slate/TypographyPlugin/setActiveTypographyStyle.d.ts +1 -1
  433. package/dist/types/slate/TypographyPlugin/setActiveTypographyStyle.d.ts.map +1 -1
  434. package/dist/types/slate/selectors.d.ts +1 -2
  435. package/dist/types/slate/selectors.d.ts.map +1 -1
  436. package/dist/types/state/makeswift-api-client.d.ts +2 -1
  437. package/dist/types/state/makeswift-api-client.d.ts.map +1 -1
  438. package/dist/types/state/modules/__tests__/fixtures/element-trees-demo-component.d.ts +7 -0
  439. package/dist/types/state/modules/__tests__/fixtures/element-trees-demo-component.d.ts.map +1 -0
  440. package/dist/types/state/modules/__tests__/fixtures/element-trees.d.ts +239 -0
  441. package/dist/types/state/modules/__tests__/fixtures/element-trees.d.ts.map +1 -1
  442. package/dist/types/state/modules/breakpoints.d.ts +2 -7
  443. package/dist/types/state/modules/breakpoints.d.ts.map +1 -1
  444. package/dist/types/state/modules/element-trees.d.ts +1 -1
  445. package/dist/types/state/modules/element-trees.d.ts.map +1 -1
  446. package/package.json +17 -5
  447. package/dist/cjs/next/api-handler/handlers/proxy-draft-mode.js +0 -80
  448. package/dist/cjs/next/api-handler/handlers/proxy-draft-mode.js.map +0 -1
  449. package/dist/cjs/next/api-handler/handlers/proxy-preview-mode.js +0 -100
  450. package/dist/cjs/next/api-handler/handlers/proxy-preview-mode.js.map +0 -1
  451. package/dist/cjs/next/draft-mode/draft-mode-script.js +0 -137
  452. package/dist/cjs/next/draft-mode/draft-mode-script.js.map +0 -1
  453. package/dist/cjs/runtimes/react/resolvable-record.js +0 -67
  454. package/dist/cjs/runtimes/react/resolvable-record.js.map +0 -1
  455. package/dist/cjs/utils/tests/breakpoint-test-util.js.map +0 -1
  456. package/dist/cjs/utils/tests/element-data-test-test.js.map +0 -1
  457. package/dist/esm/next/api-handler/handlers/proxy-draft-mode.js +0 -60
  458. package/dist/esm/next/api-handler/handlers/proxy-draft-mode.js.map +0 -1
  459. package/dist/esm/next/api-handler/handlers/proxy-preview-mode.js +0 -80
  460. package/dist/esm/next/api-handler/handlers/proxy-preview-mode.js.map +0 -1
  461. package/dist/esm/next/draft-mode/draft-mode-script.js +0 -103
  462. package/dist/esm/next/draft-mode/draft-mode-script.js.map +0 -1
  463. package/dist/esm/runtimes/react/resolvable-record.js +0 -43
  464. package/dist/esm/runtimes/react/resolvable-record.js.map +0 -1
  465. package/dist/esm/utils/tests/breakpoint-test-util.js.map +0 -1
  466. package/dist/esm/utils/tests/element-data-test-test.js.map +0 -1
  467. package/dist/types/next/api-handler/handlers/proxy-draft-mode.d.ts +0 -20
  468. package/dist/types/next/api-handler/handlers/proxy-draft-mode.d.ts.map +0 -1
  469. package/dist/types/next/api-handler/handlers/proxy-draft-mode.test.d.ts +0 -2
  470. package/dist/types/next/api-handler/handlers/proxy-draft-mode.test.d.ts.map +0 -1
  471. package/dist/types/next/api-handler/handlers/proxy-preview-mode.d.ts +0 -20
  472. package/dist/types/next/api-handler/handlers/proxy-preview-mode.d.ts.map +0 -1
  473. package/dist/types/next/components/tests/controls/color-control.test.d.ts +0 -3
  474. package/dist/types/next/components/tests/controls/color-control.test.d.ts.map +0 -1
  475. package/dist/types/next/components/tests/controls/rich-text-v2-control.test.d.ts +0 -2
  476. package/dist/types/next/components/tests/controls/rich-text-v2-control.test.d.ts.map +0 -1
  477. package/dist/types/next/components/tests/controls/style-control.test.d.ts +0 -2
  478. package/dist/types/next/components/tests/controls/style-control.test.d.ts.map +0 -1
  479. package/dist/types/next/draft-mode/draft-mode-script.d.ts +0 -6
  480. package/dist/types/next/draft-mode/draft-mode-script.d.ts.map +0 -1
  481. package/dist/types/runtimes/react/resolvable-record.d.ts +0 -3
  482. package/dist/types/runtimes/react/resolvable-record.d.ts.map +0 -1
  483. package/dist/types/utils/tests/breakpoint-test-util.d.ts.map +0 -1
  484. package/dist/types/utils/tests/element-data-test-test.d.ts.map +0 -1
@@ -1,21 +1,16 @@
1
1
  "use client";
2
2
  import { createContext, useContext } from "react";
3
- const DocumentContext = createContext({
4
- key: null,
5
- locale: null
6
- });
7
- function useDocumentContext() {
8
- return useContext(DocumentContext);
9
- }
3
+ const DocumentKeyContext = createContext(null);
4
+ const DocumentLocaleContext = createContext(null);
10
5
  function useDocumentKey() {
11
- return useDocumentContext().key;
6
+ return useContext(DocumentKeyContext);
12
7
  }
13
8
  function useDocumentLocale() {
14
- return useDocumentContext().locale;
9
+ return useContext(DocumentLocaleContext);
15
10
  }
16
11
  export {
17
- DocumentContext,
18
- useDocumentContext,
12
+ DocumentKeyContext,
13
+ DocumentLocaleContext,
19
14
  useDocumentKey,
20
15
  useDocumentLocale
21
16
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-document-context.ts"],"sourcesContent":["'use client'\n\nimport { createContext, useContext } from 'react'\n\ntype ContextValue = {\n key: string | null\n locale: string | null\n}\n\nexport const DocumentContext = createContext<ContextValue>({\n key: null,\n locale: null,\n})\n\nexport function useDocumentContext(): ContextValue {\n return useContext(DocumentContext)\n}\n\nexport function useDocumentKey(): string | null {\n return useDocumentContext().key\n}\n\nexport function useDocumentLocale(): string | null {\n return useDocumentContext().locale\n}\n"],"mappings":";AAEA,SAAS,eAAe,kBAAkB;AAOnC,MAAM,kBAAkB,cAA4B;AAAA,EACzD,KAAK;AAAA,EACL,QAAQ;AACV,CAAC;AAEM,SAAS,qBAAmC;AACjD,SAAO,WAAW,eAAe;AACnC;AAEO,SAAS,iBAAgC;AAC9C,SAAO,mBAAmB,EAAE;AAC9B;AAEO,SAAS,oBAAmC;AACjD,SAAO,mBAAmB,EAAE;AAC9B;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-document-context.ts"],"sourcesContent":["'use client'\n\nimport { createContext, useContext } from 'react'\n\nexport const DocumentKeyContext = createContext<string | null>(null)\nexport const DocumentLocaleContext = createContext<string | null>(null)\n\nexport function useDocumentKey(): string | null {\n return useContext(DocumentKeyContext)\n}\n\nexport function useDocumentLocale(): string | null {\n return useContext(DocumentLocaleContext)\n}\n"],"mappings":";AAEA,SAAS,eAAe,kBAAkB;AAEnC,MAAM,qBAAqB,cAA6B,IAAI;AAC5D,MAAM,wBAAwB,cAA6B,IAAI;AAE/D,SAAS,iBAAgC;AAC9C,SAAO,WAAW,kBAAkB;AACtC;AAEO,SAAS,oBAAmC;AACjD,SAAO,WAAW,qBAAqB;AACzC;","names":[]}
@@ -1,11 +1,18 @@
1
1
  import { useEffect } from "react";
2
2
  import { useDispatch } from "./use-dispatch";
3
3
  import { useIsInBuilder } from "./use-is-in-builder";
4
- import { registerBuilderDocumentsEffect, registerDocumentsEffect } from "../../../state/actions";
4
+ import { registerBuilderDocumentsEffect, registerDocument, registerDocumentsEffect } from "../../../state/actions";
5
+ import { isServer } from "../../../utils/is-server";
6
+ import { useIsomorphicLayoutEffect } from "../../../components/hooks/useIsomorphicLayoutEffect";
5
7
  function useRegisterDocument(document) {
6
8
  const isInBuilder = useIsInBuilder();
7
9
  const dispatch = useDispatch();
8
- useEffect(() => dispatch(registerDocumentsEffect([document])), [document]);
10
+ if (isServer()) {
11
+ dispatch(registerDocument(document));
12
+ }
13
+ useIsomorphicLayoutEffect(() => {
14
+ return dispatch(registerDocumentsEffect([document]));
15
+ }, [dispatch, document]);
9
16
  useEffect(() => {
10
17
  if (!isInBuilder)
11
18
  return;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-register-document.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { type Document } from '../../../state/react-page'\nimport { useDispatch } from './use-dispatch'\nimport { useIsInBuilder } from './use-is-in-builder'\nimport { registerBuilderDocumentsEffect, registerDocumentsEffect } from '../../../state/actions'\n\n/**\n * @param document Document to register\n */\nexport function useRegisterDocument(document: Document): void {\n const isInBuilder = useIsInBuilder()\n const dispatch = useDispatch()\n\n useEffect(() => dispatch(registerDocumentsEffect([document])), [document])\n\n // TODO: Decide whether to do this via middleware or via explicit action (like\n // what we're doing below)\n useEffect(() => {\n if (!isInBuilder) return\n return dispatch(registerBuilderDocumentsEffect([document]))\n }, [isInBuilder, document])\n}\n"],"mappings":"AAAA,SAAS,iBAAiB;AAE1B,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,gCAAgC,+BAA+B;AAKjE,SAAS,oBAAoB,UAA0B;AAC5D,QAAM,cAAc,eAAe;AACnC,QAAM,WAAW,YAAY;AAE7B,YAAU,MAAM,SAAS,wBAAwB,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC;AAIzE,YAAU,MAAM;AACd,QAAI,CAAC;AAAa;AAClB,WAAO,SAAS,+BAA+B,CAAC,QAAQ,CAAC,CAAC;AAAA,EAC5D,GAAG,CAAC,aAAa,QAAQ,CAAC;AAC5B;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-register-document.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { type Document } from '../../../state/react-page'\nimport { useDispatch } from './use-dispatch'\nimport { useIsInBuilder } from './use-is-in-builder'\nimport { registerBuilderDocumentsEffect, registerDocument, registerDocumentsEffect } from '../../../state/actions'\nimport { isServer } from '../../../utils/is-server'\nimport { useIsomorphicLayoutEffect } from '../../../components/hooks/useIsomorphicLayoutEffect'\n\n/**\n * @param document Document to register\n */\nexport function useRegisterDocument(document: Document): void {\n const isInBuilder = useIsInBuilder()\n const dispatch = useDispatch()\n\n if (isServer()) {\n dispatch(registerDocument(document))\n }\n\n /*\n Layout effect is to ensure that the document registration happens prior to the\n attempted creation/registration of prop controllers in child components.\n */\n useIsomorphicLayoutEffect(() => {\n return dispatch(registerDocumentsEffect([document]))\n }, [dispatch, document])\n\n // TODO: Decide whether to do this via middleware or via explicit action (like\n // what we're doing below)\n useEffect(() => {\n if (!isInBuilder) return\n return dispatch(registerBuilderDocumentsEffect([document]))\n }, [isInBuilder, document])\n}\n"],"mappings":"AAAA,SAAS,iBAAiB;AAE1B,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,gCAAgC,kBAAkB,+BAA+B;AAC1F,SAAS,gBAAgB;AACzB,SAAS,iCAAiC;AAKnC,SAAS,oBAAoB,UAA0B;AAC5D,QAAM,cAAc,eAAe;AACnC,QAAM,WAAW,YAAY;AAE7B,MAAI,SAAS,GAAG;AACd,aAAS,iBAAiB,QAAQ,CAAC;AAAA,EACrC;AAMA,4BAA0B,MAAM;AAC9B,WAAO,SAAS,wBAAwB,CAAC,QAAQ,CAAC,CAAC;AAAA,EACrD,GAAG,CAAC,UAAU,QAAQ,CAAC;AAIvB,YAAU,MAAM;AACd,QAAI,CAAC;AAAa;AAClB,WAAO,SAAS,+BAA+B,CAAC,QAAQ,CAAC,CAAC;AAAA,EAC5D,GAAG,CAAC,aAAa,QAAQ,CAAC;AAC5B;","names":[]}
@@ -0,0 +1,44 @@
1
+ import { useMemo, useRef } from "react";
2
+ function useResolvableRecord(resolvables) {
3
+ const snapshot = useRef({ resolvedValues: {}, dirtyProps: /* @__PURE__ */ new Set() });
4
+ return useMemo(() => {
5
+ return {
6
+ name: "resolvable-record",
7
+ subscribe: (onUpdate) => {
8
+ const unsubscribes = Object.values(resolvables).map((s) => s.subscribe(onUpdate));
9
+ return () => {
10
+ unsubscribes.forEach((u) => u());
11
+ };
12
+ },
13
+ readStable: () => {
14
+ const nextSnapshot = Object.entries(resolvables).reduce(
15
+ ({ dirtyProps, resolvedValues }, [propName, subscription]) => {
16
+ const lastPropValue = snapshot.current.resolvedValues[propName];
17
+ const propValue = subscription.readStable();
18
+ const isDirty = propValue !== lastPropValue;
19
+ return {
20
+ dirtyProps: isDirty ? dirtyProps.add(propName) : dirtyProps,
21
+ resolvedValues: { ...resolvedValues, [propName]: propValue }
22
+ };
23
+ },
24
+ { resolvedValues: {}, dirtyProps: /* @__PURE__ */ new Set() }
25
+ );
26
+ if (nextSnapshot.dirtyProps.size > 0) {
27
+ snapshot.current = nextSnapshot;
28
+ }
29
+ return snapshot.current.resolvedValues;
30
+ },
31
+ triggerResolve: async () => {
32
+ return await Promise.all(
33
+ Object.entries(resolvables).map(
34
+ ([propName, sub]) => sub.triggerResolve(snapshot.current.resolvedValues[propName])
35
+ )
36
+ );
37
+ }
38
+ };
39
+ }, [resolvables]);
40
+ }
41
+ export {
42
+ useResolvableRecord
43
+ };
44
+ //# sourceMappingURL=use-resolvable-record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolvable-record.tsx"],"sourcesContent":["import { type Resolvable } from '@makeswift/controls'\nimport { useMemo, useRef } from 'react'\n\ntype Snapshot = {\n resolvedValues: Record<string, unknown>\n dirtyProps: Set<string>\n}\n\nexport function useResolvableRecord(\n resolvables: Record<string, Resolvable<unknown>>,\n): Resolvable<Record<string, unknown>> {\n const snapshot = useRef<Snapshot>({ resolvedValues: {}, dirtyProps: new Set() })\n\n return useMemo<Resolvable<Record<string, unknown>>>(() => {\n return {\n name: 'resolvable-record',\n subscribe: (onUpdate: () => void): (() => void) => {\n const unsubscribes = Object.values(resolvables).map(s => s.subscribe(onUpdate))\n return () => {\n unsubscribes.forEach(u => u())\n }\n },\n\n readStable: () => {\n const nextSnapshot = Object.entries(resolvables).reduce<Snapshot>(\n ({ dirtyProps, resolvedValues }, [propName, subscription]) => {\n const lastPropValue = snapshot.current.resolvedValues[propName]\n const propValue = subscription.readStable()\n const isDirty = propValue !== lastPropValue\n\n return {\n dirtyProps: isDirty ? dirtyProps.add(propName) : dirtyProps,\n resolvedValues: { ...resolvedValues, [propName]: propValue },\n }\n },\n { resolvedValues: {}, dirtyProps: new Set() },\n )\n\n if (nextSnapshot.dirtyProps.size > 0) {\n snapshot.current = nextSnapshot\n }\n\n return snapshot.current.resolvedValues\n },\n\n triggerResolve: async () => {\n // While we _could_ only trigger resolution on the dirty props, this is\n // not an airtight solution. Some controls will resolve to nullish\n // values even when the underlying data changes, so they won't be dirty\n // (ex: an Image control where the data changes from `undefined` to a\n // file that has not yet been fetched). Even if you add a nullish check\n // on the resolved value, some controls can resolve to non-nullish value\n // when the resolution does not occur (ex: swatches can resolve to\n // black). The true solution is to trigger resolve on underlying data\n // change, and moving these dirtiness optimizations for resolution\n // triggering at the control level.\n return await Promise.all(\n Object.entries(resolvables).map(([propName, sub]) =>\n sub.triggerResolve(snapshot.current.resolvedValues[propName]),\n ),\n )\n },\n }\n }, [resolvables])\n}\n"],"mappings":"AACA,SAAS,SAAS,cAAc;AAOzB,SAAS,oBACd,aACqC;AACrC,QAAM,WAAW,OAAiB,EAAE,gBAAgB,CAAC,GAAG,YAAY,oBAAI,IAAI,EAAE,CAAC;AAE/E,SAAO,QAA6C,MAAM;AACxD,WAAO;AAAA,MACL,MAAM;AAAA,MACN,WAAW,CAAC,aAAuC;AACjD,cAAM,eAAe,OAAO,OAAO,WAAW,EAAE,IAAI,OAAK,EAAE,UAAU,QAAQ,CAAC;AAC9E,eAAO,MAAM;AACX,uBAAa,QAAQ,OAAK,EAAE,CAAC;AAAA,QAC/B;AAAA,MACF;AAAA,MAEA,YAAY,MAAM;AAChB,cAAM,eAAe,OAAO,QAAQ,WAAW,EAAE;AAAA,UAC/C,CAAC,EAAE,YAAY,eAAe,GAAG,CAAC,UAAU,YAAY,MAAM;AAC5D,kBAAM,gBAAgB,SAAS,QAAQ,eAAe,QAAQ;AAC9D,kBAAM,YAAY,aAAa,WAAW;AAC1C,kBAAM,UAAU,cAAc;AAE9B,mBAAO;AAAA,cACL,YAAY,UAAU,WAAW,IAAI,QAAQ,IAAI;AAAA,cACjD,gBAAgB,EAAE,GAAG,gBAAgB,CAAC,QAAQ,GAAG,UAAU;AAAA,YAC7D;AAAA,UACF;AAAA,UACA,EAAE,gBAAgB,CAAC,GAAG,YAAY,oBAAI,IAAI,EAAE;AAAA,QAC9C;AAEA,YAAI,aAAa,WAAW,OAAO,GAAG;AACpC,mBAAS,UAAU;AAAA,QACrB;AAEA,eAAO,SAAS,QAAQ;AAAA,MAC1B;AAAA,MAEA,gBAAgB,YAAY;AAW1B,eAAO,MAAM,QAAQ;AAAA,UACnB,OAAO,QAAQ,WAAW,EAAE;AAAA,YAAI,CAAC,CAAC,UAAU,GAAG,MAC7C,IAAI,eAAe,SAAS,QAAQ,eAAe,QAAQ,CAAC;AAAA,UAC9D;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,WAAW,CAAC;AAClB;","names":[]}
@@ -7,7 +7,7 @@ import { useResourceResolver } from "./use-resource-resolver";
7
7
  import { useDocumentKey } from "./use-document-context";
8
8
  import { useSelector } from "./use-selector";
9
9
  import { useStylesheetFactory } from "./use-stylesheet-factory";
10
- import { resolvableRecord } from "../resolvable-record";
10
+ import { useResolvableRecord } from "./use-resolvable-record";
11
11
  import { propErrorHandlingProxy } from "../utils/prop-error-handling-proxy";
12
12
  function useControlInstances(elementKey) {
13
13
  const documentKey = useDocumentKey();
@@ -52,12 +52,13 @@ function useResolvedProps(propDefs, elementData, elementKey) {
52
52
  }),
53
53
  [propDefs, resolveProp]
54
54
  );
55
- const props = useMemo(() => resolvableRecord(resolvables), [resolvables]);
56
- stylesheetFactory.useDefinedStyles();
55
+ const props = useResolvableRecord(resolvables);
57
56
  useEffect(() => {
58
57
  props.triggerResolve();
59
- }, []);
60
- return useSyncExternalStore(props.subscribe, props.readStable, props.readStable);
58
+ }, [props]);
59
+ const resolvedProps = useSyncExternalStore(props.subscribe, props.readStable, props.readStable);
60
+ stylesheetFactory.useDefinedStyles();
61
+ return resolvedProps;
61
62
  }
62
63
  export {
63
64
  useResolvedProps
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolved-props.ts"],"sourcesContent":["import { useMemo, useEffect, useRef, useSyncExternalStore, useCallback } from 'react'\nimport {\n ControlDefinition,\n ControlInstance,\n mapValues,\n type Data,\n type Resolvable,\n} from '@makeswift/controls'\n\nimport * as ReactPage from '../../../state/react-page'\nimport { useResourceResolver } from './use-resource-resolver'\nimport { useDocumentKey } from './use-document-context'\nimport { useSelector } from './use-selector'\n\nimport { useStylesheetFactory } from './use-stylesheet-factory'\n\nimport { resolvableRecord } from '../resolvable-record'\nimport { propErrorHandlingProxy } from '../utils/prop-error-handling-proxy'\n\nfunction useControlInstances(elementKey: string): Record<string, ControlInstance> | null {\n const documentKey = useDocumentKey()\n\n return useSelector(state => {\n if (documentKey == null) return null\n\n return ReactPage.getPropControllers(state, documentKey, elementKey)\n })\n}\n\ntype CacheItem = {\n data: Data\n control: ControlInstance | undefined\n resolvedValue: Resolvable<unknown>\n}\n\nexport function useResolvedProps(\n propDefs: Record<string, ControlDefinition>,\n elementData: Record<string, Data>,\n elementKey: string,\n): Record<string, unknown> {\n const stylesheetFactory = useStylesheetFactory()\n const resourceResolver = useResourceResolver()\n const controls = useControlInstances(elementKey)\n\n const cache = useRef<Record<string, CacheItem>>({}).current\n const resolveProp = useCallback(\n (def: ControlDefinition, propName: string) => {\n const data = elementData[propName]\n const control = controls?.[propName]\n\n if (\n cache[propName] != null &&\n data === cache[propName].data &&\n control === cache[propName].control\n ) {\n return cache[propName].resolvedValue\n }\n\n const resolvedValue = def.resolveValue(\n data,\n resourceResolver,\n stylesheetFactory.get(propName),\n control,\n )\n\n cache[propName] = { data, control, resolvedValue }\n return resolvedValue\n },\n [controls, elementData, resourceResolver, stylesheetFactory],\n )\n\n const resolvables = useMemo(\n () =>\n mapValues(propDefs, (def, propName) => {\n const defaultValue = (def.config as any)?.defaultValue\n return propErrorHandlingProxy(resolveProp(def, propName), defaultValue, error => {\n console.warn(\n `Error reading value for prop \"${propName}\", falling back to \\`${defaultValue}\\`.`,\n { control: def, error },\n )\n })\n }),\n [propDefs, resolveProp],\n )\n\n const props = useMemo(() => resolvableRecord(resolvables), [resolvables])\n\n stylesheetFactory.useDefinedStyles()\n\n useEffect(() => {\n props.triggerResolve()\n }, [])\n\n return useSyncExternalStore(props.subscribe, props.readStable, props.readStable)\n}\n"],"mappings":"AAAA,SAAS,SAAS,WAAW,QAAQ,sBAAsB,mBAAmB;AAC9E;AAAA,EAGE;AAAA,OAGK;AAEP,YAAY,eAAe;AAC3B,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAE5B,SAAS,4BAA4B;AAErC,SAAS,wBAAwB;AACjC,SAAS,8BAA8B;AAEvC,SAAS,oBAAoB,YAA4D;AACvF,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY,WAAS;AAC1B,QAAI,eAAe;AAAM,aAAO;AAEhC,WAAO,UAAU,mBAAmB,OAAO,aAAa,UAAU;AAAA,EACpE,CAAC;AACH;AAQO,SAAS,iBACd,UACA,aACA,YACyB;AACzB,QAAM,oBAAoB,qBAAqB;AAC/C,QAAM,mBAAmB,oBAAoB;AAC7C,QAAM,WAAW,oBAAoB,UAAU;AAE/C,QAAM,QAAQ,OAAkC,CAAC,CAAC,EAAE;AACpD,QAAM,cAAc;AAAA,IAClB,CAAC,KAAwB,aAAqB;AAC5C,YAAM,OAAO,YAAY,QAAQ;AACjC,YAAM,UAAU,WAAW,QAAQ;AAEnC,UACE,MAAM,QAAQ,KAAK,QACnB,SAAS,MAAM,QAAQ,EAAE,QACzB,YAAY,MAAM,QAAQ,EAAE,SAC5B;AACA,eAAO,MAAM,QAAQ,EAAE;AAAA,MACzB;AAEA,YAAM,gBAAgB,IAAI;AAAA,QACxB;AAAA,QACA;AAAA,QACA,kBAAkB,IAAI,QAAQ;AAAA,QAC9B;AAAA,MACF;AAEA,YAAM,QAAQ,IAAI,EAAE,MAAM,SAAS,cAAc;AACjD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,UAAU,aAAa,kBAAkB,iBAAiB;AAAA,EAC7D;AAEA,QAAM,cAAc;AAAA,IAClB,MACE,UAAU,UAAU,CAAC,KAAK,aAAa;AACrC,YAAM,eAAgB,IAAI,QAAgB;AAC1C,aAAO,uBAAuB,YAAY,KAAK,QAAQ,GAAG,cAAc,WAAS;AAC/E,gBAAQ;AAAA,UACN,iCAAiC,QAAQ,wBAAwB,YAAY;AAAA,UAC7E,EAAE,SAAS,KAAK,MAAM;AAAA,QACxB;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,IACH,CAAC,UAAU,WAAW;AAAA,EACxB;AAEA,QAAM,QAAQ,QAAQ,MAAM,iBAAiB,WAAW,GAAG,CAAC,WAAW,CAAC;AAExE,oBAAkB,iBAAiB;AAEnC,YAAU,MAAM;AACd,UAAM,eAAe;AAAA,EACvB,GAAG,CAAC,CAAC;AAEL,SAAO,qBAAqB,MAAM,WAAW,MAAM,YAAY,MAAM,UAAU;AACjF;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolved-props.ts"],"sourcesContent":["import { useMemo, useEffect, useRef, useSyncExternalStore, useCallback } from 'react'\nimport {\n ControlDefinition,\n ControlInstance,\n mapValues,\n type Data,\n type Resolvable,\n} from '@makeswift/controls'\n\nimport * as ReactPage from '../../../state/react-page'\nimport { useResourceResolver } from './use-resource-resolver'\nimport { useDocumentKey } from './use-document-context'\nimport { useSelector } from './use-selector'\n\nimport { useStylesheetFactory } from './use-stylesheet-factory'\n\nimport { useResolvableRecord } from './use-resolvable-record'\nimport { propErrorHandlingProxy } from '../utils/prop-error-handling-proxy'\n\nfunction useControlInstances(elementKey: string): Record<string, ControlInstance> | null {\n const documentKey = useDocumentKey()\n\n return useSelector(state => {\n if (documentKey == null) return null\n\n return ReactPage.getPropControllers(state, documentKey, elementKey)\n })\n}\n\ntype CacheItem = {\n data: Data\n control: ControlInstance | undefined\n resolvedValue: Resolvable<unknown>\n}\n\nexport function useResolvedProps(\n propDefs: Record<string, ControlDefinition>,\n elementData: Record<string, Data>,\n elementKey: string,\n): Record<string, unknown> {\n const stylesheetFactory = useStylesheetFactory()\n const resourceResolver = useResourceResolver()\n const controls = useControlInstances(elementKey)\n\n const cache = useRef<Record<string, CacheItem>>({}).current\n const resolveProp = useCallback(\n (def: ControlDefinition, propName: string) => {\n const data = elementData[propName]\n const control = controls?.[propName]\n\n if (\n cache[propName] != null &&\n data === cache[propName].data &&\n control === cache[propName].control\n ) {\n return cache[propName].resolvedValue\n }\n\n const resolvedValue = def.resolveValue(\n data,\n resourceResolver,\n stylesheetFactory.get(propName),\n control,\n )\n\n cache[propName] = { data, control, resolvedValue }\n return resolvedValue\n },\n [controls, elementData, resourceResolver, stylesheetFactory],\n )\n\n const resolvables = useMemo<Record<string, Resolvable<unknown>>>(\n () =>\n mapValues(propDefs, (def, propName) => {\n const defaultValue = (def.config as any)?.defaultValue\n return propErrorHandlingProxy(resolveProp(def, propName), defaultValue, error => {\n console.warn(\n `Error reading value for prop \"${propName}\", falling back to \\`${defaultValue}\\`.`,\n { control: def, error },\n )\n })\n }),\n [propDefs, resolveProp],\n )\n\n const props = useResolvableRecord(resolvables)\n\n // no need to call `triggerResolve` on the server, all the resources should already be in\n // the host API client's cache (populated from the snapshot's cache)\n useEffect(() => {\n props.triggerResolve()\n }, [props])\n\n // the order is important here, the styles are defined in the process of the props resolution,\n // calling `useDefinedStyles` before the props are resolved would effectively be a noop\n const resolvedProps = useSyncExternalStore(props.subscribe, props.readStable, props.readStable)\n\n stylesheetFactory.useDefinedStyles()\n\n return resolvedProps\n}\n"],"mappings":"AAAA,SAAS,SAAS,WAAW,QAAQ,sBAAsB,mBAAmB;AAC9E;AAAA,EAGE;AAAA,OAGK;AAEP,YAAY,eAAe;AAC3B,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAE5B,SAAS,4BAA4B;AAErC,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AAEvC,SAAS,oBAAoB,YAA4D;AACvF,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY,WAAS;AAC1B,QAAI,eAAe;AAAM,aAAO;AAEhC,WAAO,UAAU,mBAAmB,OAAO,aAAa,UAAU;AAAA,EACpE,CAAC;AACH;AAQO,SAAS,iBACd,UACA,aACA,YACyB;AACzB,QAAM,oBAAoB,qBAAqB;AAC/C,QAAM,mBAAmB,oBAAoB;AAC7C,QAAM,WAAW,oBAAoB,UAAU;AAE/C,QAAM,QAAQ,OAAkC,CAAC,CAAC,EAAE;AACpD,QAAM,cAAc;AAAA,IAClB,CAAC,KAAwB,aAAqB;AAC5C,YAAM,OAAO,YAAY,QAAQ;AACjC,YAAM,UAAU,WAAW,QAAQ;AAEnC,UACE,MAAM,QAAQ,KAAK,QACnB,SAAS,MAAM,QAAQ,EAAE,QACzB,YAAY,MAAM,QAAQ,EAAE,SAC5B;AACA,eAAO,MAAM,QAAQ,EAAE;AAAA,MACzB;AAEA,YAAM,gBAAgB,IAAI;AAAA,QACxB;AAAA,QACA;AAAA,QACA,kBAAkB,IAAI,QAAQ;AAAA,QAC9B;AAAA,MACF;AAEA,YAAM,QAAQ,IAAI,EAAE,MAAM,SAAS,cAAc;AACjD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,UAAU,aAAa,kBAAkB,iBAAiB;AAAA,EAC7D;AAEA,QAAM,cAAc;AAAA,IAClB,MACE,UAAU,UAAU,CAAC,KAAK,aAAa;AACrC,YAAM,eAAgB,IAAI,QAAgB;AAC1C,aAAO,uBAAuB,YAAY,KAAK,QAAQ,GAAG,cAAc,WAAS;AAC/E,gBAAQ;AAAA,UACN,iCAAiC,QAAQ,wBAAwB,YAAY;AAAA,UAC7E,EAAE,SAAS,KAAK,MAAM;AAAA,QACxB;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,IACH,CAAC,UAAU,WAAW;AAAA,EACxB;AAEA,QAAM,QAAQ,oBAAoB,WAAW;AAI7C,YAAU,MAAM;AACd,UAAM,eAAe;AAAA,EACvB,GAAG,CAAC,KAAK,CAAC;AAIV,QAAM,gBAAgB,qBAAqB,MAAM,WAAW,MAAM,YAAY,MAAM,UAAU;AAE9F,oBAAkB,iBAAiB;AAEnC,SAAO;AACT;","names":[]}
@@ -10,7 +10,7 @@ function useResolvedValue(data, resolver, defaultValue) {
10
10
  }, [data, resourceResolver, defaultValue]);
11
11
  useEffect(() => {
12
12
  resolvable.triggerResolve();
13
- }, []);
13
+ }, [resolvable]);
14
14
  return useSyncExternalStore(resolvable.subscribe, resolvable.readStable, resolvable.readStable);
15
15
  }
16
16
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolved-value.ts"],"sourcesContent":["import { useMemo, useEffect, useSyncExternalStore } from 'react'\nimport { Resolvable, ResourceResolver } from '@makeswift/controls'\n\nimport { useResourceResolver } from './use-resource-resolver'\nimport { propErrorHandlingProxy } from '../utils/prop-error-handling-proxy'\n\nexport function useResolvedValue<D, T>(\n data: D,\n resolver: (data: D, resourceResolver: ResourceResolver) => Resolvable<T>,\n defaultValue?: T,\n): T | undefined {\n const resourceResolver = useResourceResolver()\n const resolvable = useMemo(() => {\n return propErrorHandlingProxy(resolver(data, resourceResolver), defaultValue, error => {\n console.warn(`Error resolving data, falling back to \\`${defaultValue}\\`.`, { error, data })\n })\n }, [data, resourceResolver, defaultValue])\n\n useEffect(() => {\n resolvable.triggerResolve()\n }, [])\n\n return useSyncExternalStore(resolvable.subscribe, resolvable.readStable, resolvable.readStable)\n}\n"],"mappings":"AAAA,SAAS,SAAS,WAAW,4BAA4B;AAGzD,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AAEhC,SAAS,iBACd,MACA,UACA,cACe;AACf,QAAM,mBAAmB,oBAAoB;AAC7C,QAAM,aAAa,QAAQ,MAAM;AAC/B,WAAO,uBAAuB,SAAS,MAAM,gBAAgB,GAAG,cAAc,WAAS;AACrF,cAAQ,KAAK,2CAA2C,YAAY,OAAO,EAAE,OAAO,KAAK,CAAC;AAAA,IAC5F,CAAC;AAAA,EACH,GAAG,CAAC,MAAM,kBAAkB,YAAY,CAAC;AAEzC,YAAU,MAAM;AACd,eAAW,eAAe;AAAA,EAC5B,GAAG,CAAC,CAAC;AAEL,SAAO,qBAAqB,WAAW,WAAW,WAAW,YAAY,WAAW,UAAU;AAChG;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolved-value.ts"],"sourcesContent":["import { useMemo, useEffect, useSyncExternalStore } from 'react'\nimport { Resolvable, ResourceResolver } from '@makeswift/controls'\n\nimport { useResourceResolver } from './use-resource-resolver'\nimport { propErrorHandlingProxy } from '../utils/prop-error-handling-proxy'\n\nexport function useResolvedValue<D, T>(\n data: D,\n resolver: (data: D, resourceResolver: ResourceResolver) => Resolvable<T>,\n defaultValue?: T,\n): T | undefined {\n const resourceResolver = useResourceResolver()\n const resolvable = useMemo(() => {\n return propErrorHandlingProxy(resolver(data, resourceResolver), defaultValue, error => {\n console.warn(`Error resolving data, falling back to \\`${defaultValue}\\`.`, { error, data })\n })\n }, [data, resourceResolver, defaultValue])\n\n useEffect(() => {\n resolvable.triggerResolve()\n }, [resolvable])\n\n return useSyncExternalStore(resolvable.subscribe, resolvable.readStable, resolvable.readStable)\n}\n"],"mappings":"AAAA,SAAS,SAAS,WAAW,4BAA4B;AAGzD,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AAEhC,SAAS,iBACd,MACA,UACA,cACe;AACf,QAAM,mBAAmB,oBAAoB;AAC7C,QAAM,aAAa,QAAQ,MAAM;AAC/B,WAAO,uBAAuB,SAAS,MAAM,gBAAgB,GAAG,cAAc,WAAS;AACrF,cAAQ,KAAK,2CAA2C,YAAY,OAAO,EAAE,OAAO,KAAK,CAAC;AAAA,IAC5F,CAAC;AAAA,EACH,GAAG,CAAC,MAAM,kBAAkB,YAAY,CAAC;AAEzC,YAAU,MAAM;AACd,eAAW,eAAe;AAAA,EAC5B,GAAG,CAAC,UAAU,CAAC;AAEf,SAAO,qBAAqB,WAAW,WAAW,WAAW,YAAY,WAAW,UAAU;AAChG;","names":[]}
@@ -2,11 +2,12 @@ import { useMemo } from "react";
2
2
  import * as ReactPage from "../../../state/react-page";
3
3
  import { useMakeswiftHostApiClient } from "../host-api-client";
4
4
  import { useStore } from "./use-store";
5
- import { useDocumentContext } from "./use-document-context";
5
+ import { useDocumentKey, useDocumentLocale } from "./use-document-context";
6
6
  function useResourceResolver() {
7
7
  const store = useStore();
8
8
  const client = useMakeswiftHostApiClient();
9
- const { key: documentKey, locale } = useDocumentContext();
9
+ const documentKey = useDocumentKey();
10
+ const locale = useDocumentLocale();
10
11
  return useMemo(() => {
11
12
  return {
12
13
  resolveSwatch: (swatchId) => client.resolveSwatch(swatchId),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resource-resolver.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type ResourceResolver } from '@makeswift/controls'\n\nimport * as ReactPage from '../../../state/react-page'\nimport { useMakeswiftHostApiClient } from '../host-api-client'\nimport { useStore } from './use-store'\nimport { useDocumentContext } from './use-document-context'\n\nexport function useResourceResolver(): ResourceResolver {\n const store = useStore()\n const client = useMakeswiftHostApiClient()\n const { key: documentKey, locale } = useDocumentContext()\n\n return useMemo<ResourceResolver>(() => {\n return {\n resolveSwatch: swatchId => client.resolveSwatch(swatchId),\n resolveFile: fileId => client.resolveFile(fileId),\n resolveTypography: typographyId => client.resolveTypography(typographyId),\n resolvePagePathnameSlice: pageId => client.resolvePagePathnameSlice({ pageId, locale }),\n resolveElementId: elementKey => {\n const read = () =>\n documentKey == null\n ? null\n : ReactPage.getElementId(store.getState(), documentKey, elementKey)\n\n let lastValue: string | null = null\n return {\n name: `element-id:${documentKey}:${elementKey}`,\n readStable: () => (lastValue = read()),\n subscribe: (onUpdate: () => void) =>\n store.subscribe(() => {\n if (read() !== lastValue) onUpdate()\n }),\n }\n },\n }\n }, [client, store, documentKey, locale])\n}\n"],"mappings":"AAAA,SAAS,eAAe;AAGxB,YAAY,eAAe;AAC3B,SAAS,iCAAiC;AAC1C,SAAS,gBAAgB;AACzB,SAAS,0BAA0B;AAE5B,SAAS,sBAAwC;AACtD,QAAM,QAAQ,SAAS;AACvB,QAAM,SAAS,0BAA0B;AACzC,QAAM,EAAE,KAAK,aAAa,OAAO,IAAI,mBAAmB;AAExD,SAAO,QAA0B,MAAM;AACrC,WAAO;AAAA,MACL,eAAe,cAAY,OAAO,cAAc,QAAQ;AAAA,MACxD,aAAa,YAAU,OAAO,YAAY,MAAM;AAAA,MAChD,mBAAmB,kBAAgB,OAAO,kBAAkB,YAAY;AAAA,MACxE,0BAA0B,YAAU,OAAO,yBAAyB,EAAE,QAAQ,OAAO,CAAC;AAAA,MACtF,kBAAkB,gBAAc;AAC9B,cAAM,OAAO,MACX,eAAe,OACX,OACA,UAAU,aAAa,MAAM,SAAS,GAAG,aAAa,UAAU;AAEtE,YAAI,YAA2B;AAC/B,eAAO;AAAA,UACL,MAAM,cAAc,WAAW,IAAI,UAAU;AAAA,UAC7C,YAAY,MAAO,YAAY,KAAK;AAAA,UACpC,WAAW,CAAC,aACV,MAAM,UAAU,MAAM;AACpB,gBAAI,KAAK,MAAM;AAAW,uBAAS;AAAA,UACrC,CAAC;AAAA,QACL;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,OAAO,aAAa,MAAM,CAAC;AACzC;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resource-resolver.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type ResourceResolver } from '@makeswift/controls'\n\nimport * as ReactPage from '../../../state/react-page'\nimport { useMakeswiftHostApiClient } from '../host-api-client'\nimport { useStore } from './use-store'\nimport { useDocumentKey, useDocumentLocale } from './use-document-context'\n\nexport function useResourceResolver(): ResourceResolver {\n const store = useStore()\n const client = useMakeswiftHostApiClient()\n\n const documentKey = useDocumentKey()\n const locale = useDocumentLocale()\n\n return useMemo<ResourceResolver>(() => {\n return {\n resolveSwatch: swatchId => client.resolveSwatch(swatchId),\n resolveFile: fileId => client.resolveFile(fileId),\n resolveTypography: typographyId => client.resolveTypography(typographyId),\n resolvePagePathnameSlice: pageId => client.resolvePagePathnameSlice({ pageId, locale }),\n resolveElementId: elementKey => {\n const read = () =>\n documentKey == null\n ? null\n : ReactPage.getElementId(store.getState(), documentKey, elementKey)\n\n let lastValue: string | null = null\n return {\n name: `element-id:${documentKey}:${elementKey}`,\n readStable: () => (lastValue = read()),\n subscribe: (onUpdate: () => void) =>\n store.subscribe(() => {\n if (read() !== lastValue) onUpdate()\n }),\n }\n },\n }\n }, [client, store, documentKey, locale])\n}\n"],"mappings":"AAAA,SAAS,eAAe;AAGxB,YAAY,eAAe;AAC3B,SAAS,iCAAiC;AAC1C,SAAS,gBAAgB;AACzB,SAAS,gBAAgB,yBAAyB;AAE3C,SAAS,sBAAwC;AACtD,QAAM,QAAQ,SAAS;AACvB,QAAM,SAAS,0BAA0B;AAEzC,QAAM,cAAc,eAAe;AACnC,QAAM,SAAS,kBAAkB;AAEjC,SAAO,QAA0B,MAAM;AACrC,WAAO;AAAA,MACL,eAAe,cAAY,OAAO,cAAc,QAAQ;AAAA,MACxD,aAAa,YAAU,OAAO,YAAY,MAAM;AAAA,MAChD,mBAAmB,kBAAgB,OAAO,kBAAkB,YAAY;AAAA,MACxE,0BAA0B,YAAU,OAAO,yBAAyB,EAAE,QAAQ,OAAO,CAAC;AAAA,MACtF,kBAAkB,gBAAc;AAC9B,cAAM,OAAO,MACX,eAAe,OACX,OACA,UAAU,aAAa,MAAM,SAAS,GAAG,aAAa,UAAU;AAEtE,YAAI,YAA2B;AAC/B,eAAO;AAAA,UACL,MAAM,cAAc,WAAW,IAAI,UAAU;AAAA,UAC7C,YAAY,MAAO,YAAY,KAAK;AAAA,UACpC,WAAW,CAAC,aACV,MAAM,UAAU,MAAM;AACpB,gBAAI,KAAK,MAAM;AAAW,uBAAS;AAAA,UACrC,CAAC;AAAA,QACL;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,OAAO,aAAa,MAAM,CAAC;AACzC;","names":[]}
@@ -2,10 +2,10 @@ import { useMemo, useEffect, useRef } from "react";
2
2
  import { serializeStyles } from "@emotion/serialize";
3
3
  import {
4
4
  isNotNil,
5
- getBaseBreakpoint
5
+ getBaseBreakpoint,
6
+ getBreakpointMediaQuery
6
7
  } from "@makeswift/controls";
7
8
  import { useCache } from "../../../next/root-style-registry";
8
- import { getBreakpointMediaQuery } from "../../../state/modules/breakpoints";
9
9
  import { styleV1Css } from "../controls/style";
10
10
  import { typographyCss } from "../controls/typography";
11
11
  import { useBreakpoints } from "./use-breakpoints";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-stylesheet-factory.ts"],"sourcesContent":["import { useMemo, useEffect, useRef } from 'react'\nimport { type CSSObject, serializeStyles } from '@emotion/serialize'\nimport { type EmotionCache } from '@emotion/cache'\nimport { type SerializedStyles } from '@emotion/utils'\n\nimport {\n type Breakpoints,\n type BoxModel,\n type Stylesheet,\n type ResolvedStyle,\n type ResolvedStyleV2,\n type ResolvedTypographyStyle,\n isNotNil,\n getBaseBreakpoint,\n} from '@makeswift/controls'\n\nimport { useCache } from '../../../next/root-style-registry'\nimport { getBreakpointMediaQuery } from '../../../state/modules/breakpoints'\n\nimport { styleV1Css } from '../controls/style'\nimport { typographyCss } from '../controls/typography'\n\nimport { useBreakpoints } from './use-breakpoints'\nimport { useCssId } from './use-css-id'\nimport { useStyles, serializedStyleClassName } from '../use-style'\nimport { pollBoxModel } from '../poll-box-model'\n\nexport type StylesheetFactory = {\n get(propName: string): Stylesheet\n useDefinedStyles(): void\n}\n\nexport function useStylesheetFactory(): StylesheetFactory {\n const breakpoints = useBreakpoints()\n const cache = useCache()\n const componentUid = useCssId()\n\n const computedStyles = useRef<Record<string, SerializedStyles>>({}).current\n const boxModelCallbacks = useRef<Record<string, (boxModel: BoxModel | null) => void>>({}).current\n\n return useMemo(() => {\n const getStylesheet = (styleSheetId: string): Stylesheet => ({\n breakpoints(): Breakpoints {\n return breakpoints\n },\n\n defineStyle(\n style: ResolvedStyle,\n onBoxModelChange?: (boxModel: BoxModel | null) => void,\n ): string {\n const serialized = serializeStyle(breakpoints, style, cache)\n const uid = `u-${componentUid}-${styleSheetId}`\n computedStyles[uid] = serialized\n\n const className = serializedStyleClassName(cache, serialized)\n if (!onBoxModelChange) return className\n\n boxModelCallbacks[uid] = onBoxModelChange\n return `${className} ${uid}`\n },\n\n child(id: string): Stylesheet {\n return getStylesheet(`${styleSheetId}-${id}`)\n },\n })\n\n return {\n get(propName: string): Stylesheet {\n return getStylesheet(propName)\n },\n\n useDefinedStyles() {\n useStyles(cache, Object.values(computedStyles))\n\n useEffect(() => {\n const unsubscribes = Object.entries(boxModelCallbacks)\n .map(([uid, callback]) =>\n callback != null\n ? pollBoxModel({\n element: document.querySelector(`.${uid}`),\n onBoxModelChange: callback,\n })\n : undefined,\n )\n .filter(isNotNil)\n\n return () => unsubscribes.forEach(fn => fn())\n }, [Object.keys(boxModelCallbacks).join(' ')])\n },\n }\n }, [breakpoints, cache, componentUid])\n}\n\nfunction isTypographyStyle(style: ResolvedStyle): style is ResolvedTypographyStyle {\n return Array.isArray(style)\n}\n\nfunction isStyleV2(style: ResolvedStyle): style is ResolvedStyleV2 {\n return typeof style === 'object' && 'getStyle' in style && typeof style.getStyle === 'function'\n}\n\nfunction styleV2Css(breakpoints: Breakpoints, style: ResolvedStyleV2<CSSObject>): CSSObject {\n return {\n ...style.getStyle(getBaseBreakpoint(breakpoints)),\n ...breakpoints.reduce(\n (styles, breakpoint) => ({\n ...styles,\n [getBreakpointMediaQuery(breakpoint)]: style.getStyle(breakpoint),\n }),\n {},\n ),\n }\n}\n\nfunction resolvedStyleToCss(breakpoints: Breakpoints, style: ResolvedStyle) {\n if (isTypographyStyle(style)) {\n return typographyCss(breakpoints, style)\n }\n\n if (isStyleV2(style)) {\n return styleV2Css(breakpoints, style as ResolvedStyleV2<CSSObject>)\n }\n\n const { properties, styleData } = style\n return styleV1Css(breakpoints, styleData, properties)\n}\n\nfunction serializeStyle(\n breakpoints: Breakpoints,\n style: ResolvedStyle,\n cache: EmotionCache,\n): SerializedStyles {\n const css = resolvedStyleToCss(breakpoints, style)\n return serializeStyles([css], cache.registered)\n}\n"],"mappings":"AAAA,SAAS,SAAS,WAAW,cAAc;AAC3C,SAAyB,uBAAuB;AAIhD;AAAA,EAOE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AAExC,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAE9B,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,SAAS,WAAW,gCAAgC;AACpD,SAAS,oBAAoB;AAOtB,SAAS,uBAA0C;AACxD,QAAM,cAAc,eAAe;AACnC,QAAM,QAAQ,SAAS;AACvB,QAAM,eAAe,SAAS;AAE9B,QAAM,iBAAiB,OAAyC,CAAC,CAAC,EAAE;AACpE,QAAM,oBAAoB,OAA4D,CAAC,CAAC,EAAE;AAE1F,SAAO,QAAQ,MAAM;AACnB,UAAM,gBAAgB,CAAC,kBAAsC;AAAA,MAC3D,cAA2B;AACzB,eAAO;AAAA,MACT;AAAA,MAEA,YACE,OACA,kBACQ;AACR,cAAM,aAAa,eAAe,aAA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AA,QACvB,GAAG;AAAA,QACH,CAAC,wBAAwB,UAAU,CAAC,GAAG,MAAM,SAAS,UAAU;AAAA,MAClE;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,SAAS,mBAAmB,aAA0B,OAAsB;AAC1E,MAAI,kBAAkB,KAAK,GAAG;AAC5B,WAAO,cAAc,aAAa,KAAK;AAAA,EACzC;AAEA,MAAI,UAAU,KAAK,GAAG;AACpB,WAAO,WAAW,aAAa,KAAmC;AAAA,EACpE;AAEA,QAAM,EAAE,YAAY,UAAU,IAAI;AAClC,SAAO,WAAW,aAAa,WAAW,UAAU;AACtD;AAEA,SAAS,eACP,aACA,OACA,OACkB;AAClB,QAAM,MAAM,mBAAmB,aAAa,KAAK;AACjD,SAAO,gBAAgB,CAAC,GAAG,GAAG,MAAM,UAAU;AAChD;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-stylesheet-factory.ts"],"sourcesContent":["import { useMemo, useEffect, useRef } from 'react'\nimport { type CSSObject, serializeStyles } from '@emotion/serialize'\nimport { type EmotionCache } from '@emotion/cache'\nimport { type SerializedStyles } from '@emotion/utils'\n\nimport {\n type Breakpoints,\n type BoxModel,\n type Stylesheet,\n type ResolvedStyle,\n type ResolvedStyleV2,\n type ResolvedTypographyStyle,\n isNotNil,\n getBaseBreakpoint,\n getBreakpointMediaQuery,\n} from '@makeswift/controls'\n\nimport { useCache } from '../../../next/root-style-registry'\n\nimport { styleV1Css } from '../controls/style'\nimport { typographyCss } from '../controls/typography'\n\nimport { useBreakpoints } from './use-breakpoints'\nimport { useCssId } from './use-css-id'\nimport { useStyles, serializedStyleClassName } from '../use-style'\nimport { pollBoxModel } from '../poll-box-model'\n\nexport type StylesheetFactory = {\n get(propName: string): Stylesheet\n useDefinedStyles(): void\n}\n\nexport function useStylesheetFactory(): StylesheetFactory {\n const breakpoints = useBreakpoints()\n const cache = useCache()\n const componentUid = useCssId()\n\n const computedStyles = useRef<Record<string, SerializedStyles>>({}).current\n const boxModelCallbacks = useRef<Record<string, (boxModel: BoxModel | null) => void>>({}).current\n\n return useMemo(() => {\n const getStylesheet = (styleSheetId: string): Stylesheet => ({\n breakpoints(): Breakpoints {\n return breakpoints\n },\n\n defineStyle(\n style: ResolvedStyle,\n onBoxModelChange?: (boxModel: BoxModel | null) => void,\n ): string {\n const serialized = serializeStyle(breakpoints, style, cache)\n const uid = `u-${componentUid}-${styleSheetId}`\n computedStyles[uid] = serialized\n\n const className = serializedStyleClassName(cache, serialized)\n if (!onBoxModelChange) return className\n\n boxModelCallbacks[uid] = onBoxModelChange\n return `${className} ${uid}`\n },\n\n child(id: string): Stylesheet {\n return getStylesheet(`${styleSheetId}-${id}`)\n },\n })\n\n return {\n get(propName: string): Stylesheet {\n return getStylesheet(propName)\n },\n\n useDefinedStyles() {\n useStyles(cache, Object.values(computedStyles))\n\n useEffect(() => {\n const unsubscribes = Object.entries(boxModelCallbacks)\n .map(([uid, callback]) =>\n callback != null\n ? pollBoxModel({\n element: document.querySelector(`.${uid}`),\n onBoxModelChange: callback,\n })\n : undefined,\n )\n .filter(isNotNil)\n\n return () => unsubscribes.forEach(fn => fn())\n }, [Object.keys(boxModelCallbacks).join(' ')])\n },\n }\n }, [breakpoints, cache, componentUid])\n}\n\nfunction isTypographyStyle(style: ResolvedStyle): style is ResolvedTypographyStyle {\n return Array.isArray(style)\n}\n\nfunction isStyleV2(style: ResolvedStyle): style is ResolvedStyleV2 {\n return typeof style === 'object' && 'getStyle' in style && typeof style.getStyle === 'function'\n}\n\nfunction styleV2Css(breakpoints: Breakpoints, style: ResolvedStyleV2<CSSObject>): CSSObject {\n return {\n ...style.getStyle(getBaseBreakpoint(breakpoints)),\n ...breakpoints.reduce(\n (styles, breakpoint) => ({\n ...styles,\n [getBreakpointMediaQuery(breakpoint)]: style.getStyle(breakpoint),\n }),\n {},\n ),\n }\n}\n\nfunction resolvedStyleToCss(breakpoints: Breakpoints, style: ResolvedStyle) {\n if (isTypographyStyle(style)) {\n return typographyCss(breakpoints, style)\n }\n\n if (isStyleV2(style)) {\n return styleV2Css(breakpoints, style as ResolvedStyleV2<CSSObject>)\n }\n\n const { properties, styleData } = style\n return styleV1Css(breakpoints, styleData, properties)\n}\n\nfunction serializeStyle(\n breakpoints: Breakpoints,\n style: ResolvedStyle,\n cache: EmotionCache,\n): SerializedStyles {\n const css = resolvedStyleToCss(breakpoints, style)\n return serializeStyles([css], cache.registered)\n}\n"],"mappings":"AAAA,SAAS,SAAS,WAAW,cAAc;AAC3C,SAAyB,uBAAuB;AAIhD;AAAA,EAOE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,gBAAgB;AAEzB,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAE9B,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,SAAS,WAAW,gCAAgC;AACpD,SAAS,oBAAoB;AAOtB,SAAS,uBAA0C;AACxD,QAAM,cAAc,eAAe;AACnC,QAAM,QAAQ,SAAS;AACvB,QAAM,eAAe,SAAS;AAE9B,QAAM,iBAAiB,OAAyC,CAAC,CAAC,EAAE;AACpE,QAAM,oBAAoB,OAA4D,CAAC,CAAC,EAAE;AAE1F,SAAO,QAAQ,MAAM;AACnB,UAAM,gBAAgB,CAAC,kBAAsC;AAAA,MAC3D,cAA2B;AACzB,eAAO;AAAA,MACT;AAAA,MAEA,YACE,OACA,kBACQ;AACR,cAAM,aAAa,eAAe,aAAa,OAAO,KAAK;AAC3D,cAAM,MAAM,KAAK,YAAY,IAAI,YAAY;AAC7C,uBAAe,GAAG,IAAI;AAEtB,cAAM,YAAY,yBAAyB,OAAO,UAAU;AAC5D,YAAI,CAAC;AAAkB,iBAAO;AAE9B,0BAAkB,GAAG,IAAI;AACzB,eAAO,GAAG,SAAS,IAAI,GAAG;AAAA,MAC5B;AAAA,MAEA,MAAM,IAAwB;AAC5B,eAAO,cAAc,GAAG,YAAY,IAAI,EAAE,EAAE;AAAA,MAC9C;AAAA,IACF;A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,YAAY,UAAU,IAAI;AAClC,SAAO,WAAW,aAAa,WAAW,UAAU;AACtD;AAEA,SAAS,eACP,aACA,OACA,OACkB;AAClB,QAAM,MAAM,mBAAmB,aAAa,KAAK;AACjD,SAAO,gBAAgB,CAAC,GAAG,GAAG,MAAM,UAAU;AAChD;","names":[]}
@@ -2,8 +2,12 @@
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { createContext, useContext } from "react";
4
4
  import { MakeswiftHostApiClient } from "../../api/react";
5
+ import { MakeswiftSiteVersion } from "../../api/site-version";
5
6
  const Context = createContext(
6
- new MakeswiftHostApiClient({ uri: "https://api.makeswift.com/graphql" })
7
+ new MakeswiftHostApiClient({
8
+ uri: "https://api.makeswift.com/graphql",
9
+ siteVersion: MakeswiftSiteVersion.Live
10
+ })
7
11
  );
8
12
  function useMakeswiftHostApiClient() {
9
13
  return useContext(Context);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, createContext, useContext } from 'react'\nimport { MakeswiftHostApiClient } from '../../api/react'\n\nconst Context = createContext(\n new MakeswiftHostApiClient({ uri: 'https://api.makeswift.com/graphql' }),\n)\n\nexport function useMakeswiftHostApiClient(): MakeswiftHostApiClient {\n return useContext(Context)\n}\n\nexport function MakeswiftHostApiClientProvider({\n client,\n children,\n}: {\n client: MakeswiftHostApiClient\n children: ReactNode\n}) {\n return <Context.Provider value={client}>{children}</Context.Provider>\n}\n"],"mappings":";AAoBS;AAlBT,SAAoB,eAAe,kBAAkB;AACrD,SAAS,8BAA8B;AAEvC,MAAM,UAAU;AAAA,EACd,IAAI,uBAAuB,EAAE,KAAK,oCAAoC,CAAC;AACzE;AAEO,SAAS,4BAAoD;AAClE,SAAO,WAAW,OAAO;AAC3B;AAEO,SAAS,+BAA+B;AAAA,EAC7C;AAAA,EACA;AACF,GAGG;AACD,SAAO,oBAAC,QAAQ,UAAR,EAAiB,OAAO,QAAS,UAAS;AACpD;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, createContext, useContext } from 'react'\nimport { MakeswiftHostApiClient } from '../../api/react'\nimport { MakeswiftSiteVersion } from '../../api/site-version'\n\nconst Context = createContext(\n new MakeswiftHostApiClient({\n uri: 'https://api.makeswift.com/graphql',\n siteVersion: MakeswiftSiteVersion.Live,\n }),\n)\n\nexport function useMakeswiftHostApiClient(): MakeswiftHostApiClient {\n return useContext(Context)\n}\n\nexport function MakeswiftHostApiClientProvider({\n client,\n children,\n}: {\n client: MakeswiftHostApiClient\n children: ReactNode\n}) {\n return <Context.Provider value={client}>{children}</Context.Provider>\n}\n"],"mappings":";AAwBS;AAtBT,SAAoB,eAAe,kBAAkB;AACrD,SAAS,8BAA8B;AACvC,SAAS,4BAA4B;AAErC,MAAM,UAAU;AAAA,EACd,IAAI,uBAAuB;AAAA,IACzB,KAAK;AAAA,IACL,aAAa,qBAAqB;AAAA,EACpC,CAAC;AACH;AAEO,SAAS,4BAAoD;AAClE,SAAO,WAAW,OAAO;AAC3B;AAEO,SAAS,+BAA+B;AAAA,EAC7C;AAAA,EACA;AACF,GAGG;AACD,SAAO,oBAAC,QAAQ,UAAR,EAAiB,OAAO,QAAS,UAAS;AACpD;","names":[]}
@@ -6,4 +6,4 @@ export {
6
6
  MOBILE_MEDIA_QUERY,
7
7
  TABLET_MEDIA_QUERY
8
8
  };
9
- //# sourceMappingURL=breakpoint-test-util.js.map
9
+ //# sourceMappingURL=breakpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/testing/breakpoints.ts"],"sourcesContent":["export const DESKTOP_MEDIA_QUERY = 'only screen and (min-width: 769px)'\nexport const TABLET_MEDIA_QUERY = 'only screen and (min-width: 769px)'\nexport const MOBILE_MEDIA_QUERY = 'only screen and (min-width: 769px)'\n"],"mappings":"AAAO,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;","names":[]}
@@ -1,5 +1,6 @@
1
1
  import { randomUUID } from "crypto";
2
- import { MakeswiftComponentType } from "../../components";
2
+ import { CacheData } from "../../../api/react";
3
+ import { MakeswiftComponentType } from "../../../components";
3
4
  function createRootComponent(elements, rootId) {
4
5
  return {
5
6
  key: rootId ?? randomUUID(),
@@ -37,14 +38,38 @@ function createMakeswiftPageSnapshot(elementData, {
37
38
  locale
38
39
  },
39
40
  cacheData: {
40
- apiResources: {},
41
- localizedResourcesMap: {},
41
+ ...CacheData.empty(),
42
+ ...cacheData
43
+ }
44
+ };
45
+ }
46
+ function createMakeswiftComponentSnapshot(elementData, {
47
+ cacheData = {},
48
+ locale = null
49
+ } = {}) {
50
+ return {
51
+ key: randomUUID(),
52
+ document: {
53
+ id: "test-component-id",
54
+ name: "Test Component Document",
55
+ siteId: "test-site-id",
56
+ data: elementData,
57
+ inheritsFromParent: false,
58
+ locale
59
+ },
60
+ meta: {
61
+ allowLocaleFallback: false,
62
+ requestedLocale: locale
63
+ },
64
+ cacheData: {
65
+ ...CacheData.empty(),
42
66
  ...cacheData
43
67
  }
44
68
  };
45
69
  }
46
70
  export {
71
+ createMakeswiftComponentSnapshot,
47
72
  createMakeswiftPageSnapshot,
48
73
  createRootComponent
49
74
  };
50
- //# sourceMappingURL=element-data-test-test.js.map
75
+ //# sourceMappingURL=element-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/testing/element-data.ts"],"sourcesContent":["import { randomUUID } from 'crypto'\nimport { type MakeswiftPageSnapshot, type MakeswiftComponentSnapshot } from '../../../next/client'\nimport { type ElementData } from '../../../state/react-page'\nimport { CacheData } from '../../../api/react'\nimport { MakeswiftComponentType } from '../../../components'\n\nexport function createRootComponent(elements: ElementData[], rootId?: string) {\n return {\n key: rootId ?? randomUUID(),\n type: MakeswiftComponentType.Root,\n props: {\n children: {\n columns: [\n {\n deviceId: 'desktop',\n value: {\n count: 12,\n spans: elements?.map(() => [12]),\n },\n },\n ],\n elements,\n },\n },\n }\n}\n\nexport function createMakeswiftPageSnapshot(\n elementData: ElementData,\n {\n cacheData = {},\n locale = null,\n }: { cacheData?: Partial<MakeswiftPageSnapshot['cacheData']>; locale?: string | null } = {},\n): MakeswiftPageSnapshot {\n return {\n document: {\n id: 'test-page-id',\n site: { id: 'test-site-id' },\n data: elementData,\n snippets: [],\n fonts: [],\n meta: {},\n seo: {},\n localizedPages: [],\n locale,\n },\n cacheData: {\n ...CacheData.empty(),\n ...cacheData,\n },\n }\n}\n\nexport function createMakeswiftComponentSnapshot(\n elementData: ElementData,\n {\n cacheData = {},\n locale = null,\n }: { cacheData?: Partial<MakeswiftComponentSnapshot['cacheData']>; locale?: string | null } = {},\n): MakeswiftComponentSnapshot {\n return {\n key: randomUUID(),\n document: {\n id: 'test-component-id',\n name: 'Test Component Document',\n siteId: 'test-site-id',\n data: elementData,\n inheritsFromParent: false,\n locale,\n },\n meta: {\n allowLocaleFallback: false,\n requestedLocale: locale,\n },\n cacheData: {\n ...CacheData.empty(),\n ...cacheData,\n },\n }\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAG3B,SAAS,iBAAiB;AAC1B,SAAS,8BAA8B;AAEhC,SAAS,oBAAoB,UAAyB,QAAiB;AAC5E,SAAO;AAAA,IACL,KAAK,UAAU,WAAW;AAAA,IAC1B,MAAM,uBAAuB;AAAA,IAC7B,OAAO;AAAA,MACL,UAAU;AAAA,QACR,SAAS;AAAA,UACP;AAAA,YACE,UAAU;AAAA,YACV,OAAO;AAAA,cACL,OAAO;AAAA,cACP,OAAO,UAAU,IAAI,MAAM,CAAC,EAAE,CAAC;AAAA,YACjC;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,4BACd,aACA;AAAA,EACE,YAAY,CAAC;AAAA,EACb,SAAS;AACX,IAAyF,CAAC,GACnE;AACvB,SAAO;AAAA,IACL,UAAU;AAAA,MACR,IAAI;AAAA,MACJ,MAAM,EAAE,IAAI,eAAe;AAAA,MAC3B,MAAM;AAAA,MACN,UAAU,CAAC;AAAA,MACX,OAAO,CAAC;AAAA,MACR,MAAM,CAAC;AAAA,MACP,KAAK,CAAC;AAAA,MACN,gBAAgB,CAAC;AAAA,MACjB;AAAA,IACF;AAAA,IACA,WAAW;AAAA,MACT,GAAG,UAAU,MAAM;AAAA,MACnB,GAAG;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,iCACd,aACA;AAAA,EACE,YAAY,CAAC;AAAA,EACb,SAAS;AACX,IAA8F,CAAC,GACnE;AAC5B,SAAO;AAAA,IACL,KAAK,WAAW;AAAA,IAChB,UAAU;AAAA,MACR,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,oBAAoB;AAAA,MACpB;AAAA,IACF;AAAA,IACA,MAAM;AAAA,MACJ,qBAAqB;AAAA,MACrB,iBAAiB;AAAA,IACnB;AAAA,IACA,WAAW;AAAA,MACT,GAAG,UAAU,MAAM;AAAA,MACnB,GAAG;AAAA,IACL;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,4 @@
1
+ export * from "./breakpoints";
2
+ export * from "./element-data";
3
+ export * from "./react-provider";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/testing/index.ts"],"sourcesContent":["export * from './breakpoints'\nexport * from './element-data'\nexport * from './react-provider'\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,14 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { RootStyleRegistry } from "../../../next";
3
+ import { ReactRuntimeProvider } from "../components/RuntimeProvider";
4
+ function ReactProvider({
5
+ children,
6
+ runtime,
7
+ previewMode = false
8
+ }) {
9
+ return /* @__PURE__ */ jsx(ReactRuntimeProvider, { previewMode, runtime, children: /* @__PURE__ */ jsx(RootStyleRegistry, { children }) });
10
+ }
11
+ export {
12
+ ReactProvider
13
+ };
14
+ //# sourceMappingURL=react-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/testing/react-provider.tsx"],"sourcesContent":["import { RootStyleRegistry } from '../../../next'\nimport { ReactRuntimeProvider } from '../components/RuntimeProvider'\nimport { ReactRuntime } from '../react-runtime'\n\nexport function ReactProvider({\n children,\n runtime,\n previewMode = false,\n}: {\n children: React.ReactNode\n runtime: ReactRuntime\n previewMode?: boolean\n}) {\n return (\n <ReactRuntimeProvider previewMode={previewMode} runtime={runtime}>\n <RootStyleRegistry>{children}</RootStyleRegistry>\n </ReactRuntimeProvider>\n )\n}\n"],"mappings":"AAeM;AAfN,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AAG9B,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,cAAc;AAChB,GAIG;AACD,SACE,oBAAC,wBAAqB,aAA0B,SAC9C,8BAAC,qBAAmB,UAAS,GAC/B;AAEJ;","names":[]}
@@ -2,7 +2,7 @@ import React from "react";
2
2
  import { serializeStyles } from "@emotion/serialize";
3
3
  import { registerStyles, insertStyles } from "@emotion/utils";
4
4
  import { useCache } from "../../next/root-style-registry";
5
- const isServer = typeof window === "undefined";
5
+ import { isServer } from "../../utils/is-server";
6
6
  const useInsertionEffectSpecifier = "useInsertionEffect";
7
7
  const useInsertionEffect = React[useInsertionEffectSpecifier] ?? React.useLayoutEffect;
8
8
  function useStyle(style) {
@@ -22,7 +22,7 @@ function useStyles(cache, styles) {
22
22
  }
23
23
  function useUniversalInsertionEffect(effect) {
24
24
  useInsertionEffect(effect);
25
- if (isServer)
25
+ if (isServer())
26
26
  effect();
27
27
  }
28
28
  function serializedStyleClassName(cache, serialized) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/use-style.ts"],"sourcesContent":["import React from 'react'\nimport { CSSObject } from '@emotion/css'\nimport { EmotionCache } from '@emotion/cache'\nimport { serializeStyles } from '@emotion/serialize'\nimport { registerStyles, insertStyles, type SerializedStyles } from '@emotion/utils'\n\nimport { useCache } from '../../next/root-style-registry'\n\nconst isServer = typeof window === 'undefined'\nconst useInsertionEffectSpecifier = 'useInsertionEffect'\nconst useInsertionEffect = React[useInsertionEffectSpecifier] ?? React.useLayoutEffect\n\nexport function useStyle(style: CSSObject): string {\n const cache = useCache()\n const serialized = serializeStyles([style], cache.registered)\n\n registerStyles(cache, serialized, false)\n\n useUniversalInsertionEffect(() => {\n insertStyles(cache, serialized, false)\n })\n\n return serializedStyleClassName(cache, serialized)\n}\n\nexport function useStyles(cache: EmotionCache, styles: SerializedStyles[]) {\n styles.forEach(s => registerStyles(cache, s, false))\n\n useUniversalInsertionEffect(() => {\n styles.forEach(s => insertStyles(cache, s, false))\n })\n}\n\nfunction useUniversalInsertionEffect(effect: () => void) {\n useInsertionEffect(effect)\n if (isServer) effect()\n}\n\nexport function serializedStyleClassName(\n cache: EmotionCache,\n serialized: SerializedStyles,\n): string {\n // see https://github.com/emotion-js/emotion/blob/main/packages/utils/src/index.ts#L26\n return `${cache.key}-${serialized.name}`\n}\n"],"mappings":"AAAA,OAAO,WAAW;AAGlB,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,oBAA2C;AAEpE,SAAS,gBAAgB;AAEzB,MAAM,WAAW,OAAO,WAAW;AACnC,MAAM,8BAA8B;AACpC,MAAM,qBAAqB,MAAM,2BAA2B,KAAK,MAAM;AAEhE,SAAS,SAAS,OAA0B;AACjD,QAAM,QAAQ,SAAS;AACvB,QAAM,aAAa,gBAAgB,CAAC,KAAK,GAAG,MAAM,UAAU;AAE5D,iBAAe,OAAO,YAAY,KAAK;AAEvC,8BAA4B,MAAM;AAChC,iBAAa,OAAO,YAAY,KAAK;AAAA,EACvC,CAAC;AAED,SAAO,yBAAyB,OAAO,UAAU;AACnD;AAEO,SAAS,UAAU,OAAqB,QAA4B;AACzE,SAAO,QAAQ,OAAK,eAAe,OAAO,GAAG,KAAK,CAAC;AAEnD,8BAA4B,MAAM;AAChC,WAAO,QAAQ,OAAK,aAAa,OAAO,GAAG,KAAK,CAAC;AAAA,EACnD,CAAC;AACH;AAEA,SAAS,4BAA4B,QAAoB;AACvD,qBAAmB,MAAM;AACzB,MAAI;AAAU,WAAO;AACvB;AAEO,SAAS,yBACd,OACA,YACQ;AAER,SAAO,GAAG,MAAM,GAAG,IAAI,WAAW,IAAI;AACxC;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/use-style.ts"],"sourcesContent":["import React from 'react'\nimport { CSSObject } from '@emotion/css'\nimport { EmotionCache } from '@emotion/cache'\nimport { serializeStyles } from '@emotion/serialize'\nimport { registerStyles, insertStyles, type SerializedStyles } from '@emotion/utils'\n\nimport { useCache } from '../../next/root-style-registry'\nimport { isServer } from '../../utils/is-server'\n\nconst useInsertionEffectSpecifier = 'useInsertionEffect'\nconst useInsertionEffect = React[useInsertionEffectSpecifier] ?? React.useLayoutEffect\n\nexport function useStyle(style: CSSObject): string {\n const cache = useCache()\n const serialized = serializeStyles([style], cache.registered)\n\n registerStyles(cache, serialized, false)\n\n useUniversalInsertionEffect(() => {\n insertStyles(cache, serialized, false)\n })\n\n return serializedStyleClassName(cache, serialized)\n}\n\nexport function useStyles(cache: EmotionCache, styles: SerializedStyles[]) {\n styles.forEach(s => registerStyles(cache, s, false))\n\n useUniversalInsertionEffect(() => {\n styles.forEach(s => insertStyles(cache, s, false))\n })\n}\n\nfunction useUniversalInsertionEffect(effect: () => void) {\n useInsertionEffect(effect)\n if (isServer()) effect()\n}\n\nexport function serializedStyleClassName(\n cache: EmotionCache,\n serialized: SerializedStyles,\n): string {\n // see https://github.com/emotion-js/emotion/blob/main/packages/utils/src/index.ts#L26\n return `${cache.key}-${serialized.name}`\n}\n"],"mappings":"AAAA,OAAO,WAAW;AAGlB,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,oBAA2C;AAEpE,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AAEzB,MAAM,8BAA8B;AACpC,MAAM,qBAAqB,MAAM,2BAA2B,KAAK,MAAM;AAEhE,SAAS,SAAS,OAA0B;AACjD,QAAM,QAAQ,SAAS;AACvB,QAAM,aAAa,gBAAgB,CAAC,KAAK,GAAG,MAAM,UAAU;AAE5D,iBAAe,OAAO,YAAY,KAAK;AAEvC,8BAA4B,MAAM;AAChC,iBAAa,OAAO,YAAY,KAAK;AAAA,EACvC,CAAC;AAED,SAAO,yBAAyB,OAAO,UAAU;AACnD;AAEO,SAAS,UAAU,OAAqB,QAA4B;AACzE,SAAO,QAAQ,OAAK,eAAe,OAAO,GAAG,KAAK,CAAC;AAEnD,8BAA4B,MAAM;AAChC,WAAO,QAAQ,OAAK,aAAa,OAAO,GAAG,KAAK,CAAC;AAAA,EACnD,CAAC;AACH;AAEA,SAAS,4BAA4B,QAAoB;AACvD,qBAAmB,MAAM;AACzB,MAAI,SAAS;AAAG,WAAO;AACzB;AAEO,SAAS,yBACd,OACA,YACQ;AAER,SAAO,GAAG,MAAM,GAAG,IAAI,WAAW,IAAI;AACxC;","names":[]}
@@ -1,7 +1,9 @@
1
1
  import { Transforms } from "slate";
2
- import { Slate } from "@makeswift/controls";
2
+ import {
3
+ findBreakpointOverride,
4
+ Slate
5
+ } from "@makeswift/controls";
3
6
  import { getBlocksInSelection } from "../selectors";
4
- import { findBreakpointOverride } from "../../state/modules/breakpoints";
5
7
  function setBlockKeyForDevice(editor, breakpoints, deviceId, key, value, options) {
6
8
  const at = options?.at ?? editor.selection;
7
9
  if (!at)
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/slate/BlockPlugin/setBlockKeyForDevice.ts"],"sourcesContent":["import { Editor, Transforms, Location } from 'slate'\nimport { Slate } from '@makeswift/controls'\n\nimport { getBlocksInSelection } from '../selectors'\nimport { EditableBlockKey, EditableBlockValue } from './types'\nimport { Breakpoints, BreakpointId, findBreakpointOverride } from '../../state/modules/breakpoints'\n\ntype SetBlockKeyForDeviceOptions = {\n at?: Location\n}\n\nexport function setBlockKeyForDevice(\n editor: Editor,\n breakpoints: Breakpoints,\n deviceId: BreakpointId,\n key: EditableBlockKey,\n value: EditableBlockValue[number]['value'],\n options?: SetBlockKeyForDeviceOptions,\n) {\n const at = options?.at ?? editor.selection\n if (!at) return\n\n const rootElements = getBlocksInSelection(editor)\n\n for (const [node, path] of rootElements) {\n if (Slate.isBlock(node)) {\n const deviceValues = node[key] ?? []\n const currentDeviceValue = findBreakpointOverride(breakpoints, deviceValues, deviceId, v => v)\n const nextDeviceValue = {\n ...currentDeviceValue,\n deviceId,\n value,\n }\n Transforms.setNodes(\n editor,\n {\n [key]: [...deviceValues.filter(v => v.deviceId !== deviceId), nextDeviceValue],\n },\n { at: path },\n )\n }\n }\n}\n"],"mappings":"AAAA,SAAiB,kBAA4B;AAC7C,SAAS,aAAa;AAEtB,SAAS,4BAA4B;AAErC,SAAoC,8BAA8B;AAM3D,SAAS,qBACd,QACA,aACA,UACA,KACA,OACA,SACA;AACA,QAAM,KAAK,SAAS,MAAM,OAAO;AACjC,MAAI,CAAC;AAAI;AAET,QAAM,eAAe,qBAAqB,MAAM;AAEhD,aAAW,CAAC,MAAM,IAAI,KAAK,cAAc;AACvC,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,YAAM,eAAe,KAAK,GAAG,KAAK,CAAC;AACnC,YAAM,qBAAqB,uBAAuB,aAAa,cAAc,UAAU,OAAK,CAAC;AAC7F,YAAM,kBAAkB;AAAA,QACtB,GAAG;AAAA,QACH;AAAA,QACA;AAAA,MACF;AACA,iBAAW;AAAA,QACT;AAAA,QACA;AAAA,UACE,CAAC,GAAG,GAAG,CAAC,GAAG,aAAa,OAAO,OAAK,EAAE,aAAa,QAAQ,GAAG,eAAe;AAAA,QAC/E;AAAA,QACA,EAAE,IAAI,KAAK;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/slate/BlockPlugin/setBlockKeyForDevice.ts"],"sourcesContent":["import { Editor, Transforms, Location } from 'slate'\nimport {\n type Breakpoints,\n type BreakpointId,\n findBreakpointOverride,\n Slate,\n} from '@makeswift/controls'\n\nimport { getBlocksInSelection } from '../selectors'\nimport { EditableBlockKey, EditableBlockValue } from './types'\n\ntype SetBlockKeyForDeviceOptions = {\n at?: Location\n}\n\nexport function setBlockKeyForDevice(\n editor: Editor,\n breakpoints: Breakpoints,\n deviceId: BreakpointId,\n key: EditableBlockKey,\n value: EditableBlockValue[number]['value'],\n options?: SetBlockKeyForDeviceOptions,\n) {\n const at = options?.at ?? editor.selection\n if (!at) return\n\n const rootElements = getBlocksInSelection(editor)\n\n for (const [node, path] of rootElements) {\n if (Slate.isBlock(node)) {\n const deviceValues = node[key] ?? []\n const currentDeviceValue = findBreakpointOverride(breakpoints, deviceValues, deviceId, v => v)\n const nextDeviceValue = {\n ...currentDeviceValue,\n deviceId,\n value,\n }\n Transforms.setNodes(\n editor,\n {\n [key]: [...deviceValues.filter(v => v.deviceId !== deviceId), nextDeviceValue],\n },\n { at: path },\n )\n }\n }\n}\n"],"mappings":"AAAA,SAAiB,kBAA4B;AAC7C;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,4BAA4B;AAO9B,SAAS,qBACd,QACA,aACA,UACA,KACA,OACA,SACA;AACA,QAAM,KAAK,SAAS,MAAM,OAAO;AACjC,MAAI,CAAC;AAAI;AAET,QAAM,eAAe,qBAAqB,MAAM;AAEhD,aAAW,CAAC,MAAM,IAAI,KAAK,cAAc;AACvC,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,YAAM,eAAe,KAAK,GAAG,KAAK,CAAC;AACnC,YAAM,qBAAqB,uBAAuB,aAAa,cAAc,UAAU,OAAK,CAAC;AAC7F,YAAM,kBAAkB;AAAA,QACtB,GAAG;AAAA,QACH;AAAA,QACA;AAAA,MACF;AACA,iBAAW;AAAA,QACT;AAAA,QACA;AAAA,UACE,CAAC,GAAG,GAAG,CAAC,GAAG,aAAa,OAAO,OAAK,EAAE,aAAa,QAAQ,GAAG,eAAe;AAAA,QAC/E;AAAA,QACA,EAAE,IAAI,KAAK;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1,5 +1,7 @@
1
1
  import { Editor, Transforms, Text, Range } from "slate";
2
- import { findBreakpointOverride } from "../../state/modules/breakpoints";
2
+ import {
3
+ findBreakpointOverride
4
+ } from "@makeswift/controls";
3
5
  function setActiveTypographyStyle(editor, breakpoints, deviceId, prop, value, options) {
4
6
  Editor.withoutNormalizing(editor, () => {
5
7
  const at = options?.at ?? editor.selection;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/slate/TypographyPlugin/setActiveTypographyStyle.ts"],"sourcesContent":["import { Editor, Transforms, Text, Range } from 'slate'\nimport { RichTextTypography } from '@makeswift/controls'\n\nimport { Breakpoints, findBreakpointOverride, BreakpointId } from '../../state/modules/breakpoints'\n\ntype SetActiveTypographyStyleOptions = {\n at?: Range\n}\n\nexport function setActiveTypographyStyle(\n editor: Editor,\n breakpoints: Breakpoints,\n deviceId: string,\n prop: string,\n value?: unknown,\n options?: SetActiveTypographyStyleOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const deviceOverrides = node?.typography?.style ?? []\n const deviceStyle = findBreakpointOverride(\n breakpoints,\n deviceOverrides,\n deviceId as BreakpointId,\n v => v,\n ) || {\n value: {},\n }\n const nextDeviceStyle = {\n deviceId,\n value: { ...deviceStyle.value, [prop]: value },\n }\n\n const nextTypography: RichTextTypography = {\n ...node.typography,\n style: [...deviceOverrides.filter(v => v.deviceId !== deviceId), nextDeviceStyle],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography: nextTypography,\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n"],"mappings":"AAAA,SAAS,QAAQ,YAAY,MAAM,aAAa;AAGhD,SAAsB,8BAA4C;AAM3D,SAAS,yBACd,QACA,aACA,UACA,MACA,OACA,SACA;AACA,SAAO,mBAAmB,QAAQ,MAAM;AACtC,UAAM,KAAK,SAAS,MAAM,OAAO;AACjC,QAAI,CAAC;AAAI;AACT,UAAM,QAAQ,OAAO,SAAS,QAAQ,EAAE;AAExC,QAAI,MAAM,SAAS;AACjB,iBAAW;AAAA,QACT;AAAA,QACA;AAAA,UACE,OAAO;AAAA,QACT;AAAA,QACA;AAAA,UACE,IAAI,MAAM;AAAA,UACV,OAAO,UAAQ,KAAK,OAAO,IAAI;AAAA,UAC/B,OAAO,MAAM,WAAW,MAAM,OAAO;AAAA,QACvC;AAAA,MACF;AAAA,IACF;AAEA,QAAI,MAAM,SAAS;AACjB,YAAM,YAAY,MAAM;AAAA,QACtB,OAAO,MAAM,QAAQ;AAAA,UACnB,IAAI,MAAM;AAAA,UACV,OAAO,UAAQ,KAAK,OAAO,IAAI,KAAK,KAAK,UAAU;AAAA,QACrD,CAAC;AAAA,MACH;AAEA,iBAAW,CAAC,MAAM,IAAI,KAAK,WAAW;AACpC,YAAI,KAAK,OAAO,IAAI,GAAG;AACrB,gBAAM,kBAAkB,MAAM,YAAY,SAAS,CAAC;AACpD,gBAAM,cAAc;AAAA,YAClB;AAAA,YACA;AAAA,YACA;AAAA,YACA,OAAK;AAAA,UACP,KAAK;AAAA,YACH,OAAO,CAAC;AAAA,UACV;AACA,gBAAM,kBAAkB;AAAA,YACtB;AAAA,YACA,OAAO,EAAE,GAAG,YAAY,OAAO,CAAC,IAAI,GAAG,MAAM;AAAA,UAC/C;AAEA,gBAAM,iBAAqC;AAAA,YACzC,GAAG,KAAK;AAAA,YACR,OAAO,CAAC,GAAG,gBAAgB,OAAO,OAAK,EAAE,aAAa,QAAQ,GAAG,eAAe;AAAA,UAClF;AAEA,qBAAW;AAAA,YACT;AAAA,YACA;AAAA,cACE,YAAY;AAAA,YACd;AAAA,YACA,EAAE,IAAI,KAAK;AAAA,UACb;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,MAAM;AAAA,EACd,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/slate/TypographyPlugin/setActiveTypographyStyle.ts"],"sourcesContent":["import { Editor, Transforms, Text, Range } from 'slate'\nimport {\n type Breakpoints,\n type BreakpointId,\n findBreakpointOverride,\n RichTextTypography,\n} from '@makeswift/controls'\n\ntype SetActiveTypographyStyleOptions = {\n at?: Range\n}\n\nexport function setActiveTypographyStyle(\n editor: Editor,\n breakpoints: Breakpoints,\n deviceId: string,\n prop: string,\n value?: unknown,\n options?: SetActiveTypographyStyleOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const deviceOverrides = node?.typography?.style ?? []\n const deviceStyle = findBreakpointOverride(\n breakpoints,\n deviceOverrides,\n deviceId as BreakpointId,\n v => v,\n ) || {\n value: {},\n }\n const nextDeviceStyle = {\n deviceId,\n value: { ...deviceStyle.value, [prop]: value },\n }\n\n const nextTypography: RichTextTypography = {\n ...node.typography,\n style: [...deviceOverrides.filter(v => v.deviceId !== deviceId), nextDeviceStyle],\n }\n\n Transfor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Aa,QAAQ,GAAG,eAAe;AAAA,UAClF;AAEA,qBAAW;AAAA,YACT;AAAA,YACA;AAAA,cACE,YAAY;AAAA,YACd;AAAA,YACA,EAAE,IAAI,KAAK;AAAA,UACb;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,MAAM;AAAA,EACd,CAAC;AACH;","names":[]}
@@ -1,9 +1,11 @@
1
1
  import { Editor, Text } from "slate";
2
- import { Slate } from "@makeswift/controls";
2
+ import {
3
+ findBreakpointOverride,
4
+ Slate
5
+ } from "@makeswift/controls";
3
6
  import unhangRange from "./utils/unhangRange";
4
7
  import shallowEqual from "../utils/shallowEqual";
5
8
  import { isNonNullable } from "../utils/isNonNullable";
6
- import { findBreakpointOverride } from "../state/modules/breakpoints";
7
9
  import deepEqual from "../utils/deepEqual";
8
10
  import keys from "../utils/keys";
9
11
  function getSelection(editor) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/slate/selectors.ts"],"sourcesContent":["import { Editor, NodeEntry, Range, Text } from 'slate'\nimport { Slate } from '@makeswift/controls'\n\nimport { EditableBlockKey } from './BlockPlugin/types'\n\nimport unhangRange from './utils/unhangRange'\nimport shallowEqual from '../utils/shallowEqual'\nimport { isNonNullable } from '../utils/isNonNullable'\n\nimport { Breakpoints, BreakpointId, findBreakpointOverride } from '../state/modules/breakpoints'\nimport deepEqual from '../utils/deepEqual'\nimport keys from '../utils/keys'\n\nexport function getSelection(editor: Editor): Range {\n if (editor.selection) return unhangRange(editor, editor.selection)\n return {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n }\n}\n\nexport function getBlocksInSelection(editor: Editor): NodeEntry<Slate.RootBlock>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isRootBlock(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.RootBlock> => Slate.isRootBlock(entry[0]))\n}\n\nexport function getInlinesInSelection(editor: Editor): NodeEntry<Slate.Inline>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isInline(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.Inline> => Slate.isInline(entry[0]))\n}\n\nexport function getActiveBlockType(editor: Editor): Slate.RootBlockType | null {\n const rootBlocks = getBlocksInSelection(editor).map(([node]) => node.type)\n\n return rootBlocks.reduce<Slate.RootBlockType | null>(\n (a, b) => (a === b ? b : null),\n rootBlocks.at(0) ?? null,\n )\n}\n\nexport function getActiveBlockValue(editor: Editor, key: EditableBlockKey) {\n const blocks = getBlocksInSelection(editor)\n\n const active = blocks.map(\n ([block]) => block[key] ?? null,\n ) as (Slate.ResponsiveBlockTextAlignment | null)[]\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\nexport function getActiveBlockDeviceOverrideValue(\n editor: Editor,\n key: EditableBlockKey,\n breakpoints: Breakpoints,\n deviceId: BreakpointId,\n) {\n const active: (Slate.BlockTextAlignment | null)[] = []\n const blocks = getBlocksInSelection(editor)\n\n blocks.forEach(([block]) => {\n const deviceOverride =\n findBreakpointOverride<Slate.BlockTextAlignment>(breakpoints, block[key], deviceId) || null\n active.push(deviceOverride?.value ?? null)\n })\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\n// Typography\n\nconst concat = (a: unknown[], b: unknown[]) => a.concat(b)\n\n// TODO: This is more cruft from trying to remove null from the typography type. This optimization is not worth it.\n/**\n * This is a c/p of the intersection of the utils from the root utils folder.\n * The only change is defaulting to undefined instead of to null.\n */\nexport default function intersection<A extends Record<string, unknown>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: unknown, b: unknown) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | undefined } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce(\n (acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = undefined\n\n return acc\n },\n {} as { [K in keyof A]: A[K] | undefined },\n )\n}\n\nconst fuseTypographyMarks = (\n values: Array<Slate.Typography | null | undefined>,\n breakpoints: Breakpoints,\n): Slate.Typography => {\n const devices = [\n ...new Set(\n values\n .filter(isNonNullable)\n .map(({ style }) => style.map(({ deviceId }) => deviceId))\n .reduce(concat, []),\n ),\n ] as BreakpointId[]\n\n return {\n id: values.map(v => v && v.id).reduce((a, b) => (a === b ? a : undefined)) ?? undefined,\n style: devices.map(deviceId =>\n values\n .map(\n v =>\n (v && findBreakpointOverride(breakpoints, v.style, deviceId)) || {\n deviceId,\n value: {},\n },\n )\n .reduce((acc, { value }) => {\n const a = intersection(acc.value, value)\n return {\n deviceId,\n value: a,\n }\n }),\n ),\n }\n}\n\nexport function getActiveTypographyMark(\n editor: Editor,\n breakpoints: Breakpoints,\n): Slate.Typography {\n const active: Slate.Typography[] = []\n\n const textNodes = Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Text.isText(node),\n })\n\n for (const [node] of textNodes) {\n if (Text.isText(node) && 'typography' in node && node.typography != undefined) {\n active.push(node.typography)\n }\n }\n return active.length === 0 ? { style: [] } : fuseTypographyMarks(active, breakpoints)\n}\n"],"mappings":"AAAA,SAAS,QAA0B,YAAY;AAC/C,SAAS,aAAa;AAItB,OAAO,iBAAiB;AACxB,OAAO,kBAAkB;AACzB,SAAS,qBAAqB;AAE9B,SAAoC,8BAA8B;AAClE,OAAO,eAAe;AACtB,OAAO,UAAU;AAEV,SAAS,aAAa,QAAuB;AAClD,MAAI,OAAO;AAAW,WAAO,YAAY,QAAQ,OAAO,SAAS;AACjE,SAAO;AAAA,IACL,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO,OAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,EAC9B;AACF;AAEO,SAAS,qBAAqB,QAA8C;AACjF,SAAO,MAAM;AAAA,IACX,OAAO,MAAM,QAAQ;AAAA,MACnB,IAAI,aAAa,MAAM;AAAA,MACvB,OAAO,UAAQ,MAAM,Y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;AAAA,IACrC,IAAI,aAAa,MAAM;AAAA,IACvB,OAAO,UAAQ,KAAK,OAAO,IAAI;AAAA,EACjC,CAAC;AAED,aAAW,CAAC,IAAI,KAAK,WAAW;AAC9B,QAAI,KAAK,OAAO,IAAI,KAAK,gBAAgB,QAAQ,KAAK,cAAc,QAAW;AAC7E,aAAO,KAAK,KAAK,UAAU;AAAA,IAC7B;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,oBAAoB,QAAQ,WAAW;AACtF;","names":[]}
1
+ {"version":3,"sources":["../../../src/slate/selectors.ts"],"sourcesContent":["import { Editor, NodeEntry, Range, Text } from 'slate'\nimport {\n type Breakpoints,\n type BreakpointId,\n findBreakpointOverride,\n Slate,\n} from '@makeswift/controls'\n\nimport { EditableBlockKey } from './BlockPlugin/types'\n\nimport unhangRange from './utils/unhangRange'\nimport shallowEqual from '../utils/shallowEqual'\nimport { isNonNullable } from '../utils/isNonNullable'\n\nimport deepEqual from '../utils/deepEqual'\nimport keys from '../utils/keys'\n\nexport function getSelection(editor: Editor): Range {\n if (editor.selection) return unhangRange(editor, editor.selection)\n return {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n }\n}\n\nexport function getBlocksInSelection(editor: Editor): NodeEntry<Slate.RootBlock>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isRootBlock(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.RootBlock> => Slate.isRootBlock(entry[0]))\n}\n\nexport function getInlinesInSelection(editor: Editor): NodeEntry<Slate.Inline>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isInline(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.Inline> => Slate.isInline(entry[0]))\n}\n\nexport function getActiveBlockType(editor: Editor): Slate.RootBlockType | null {\n const rootBlocks = getBlocksInSelection(editor).map(([node]) => node.type)\n\n return rootBlocks.reduce<Slate.RootBlockType | null>(\n (a, b) => (a === b ? b : null),\n rootBlocks.at(0) ?? null,\n )\n}\n\nexport function getActiveBlockValue(editor: Editor, key: EditableBlockKey) {\n const blocks = getBlocksInSelection(editor)\n\n const active = blocks.map(\n ([block]) => block[key] ?? null,\n ) as (Slate.ResponsiveBlockTextAlignment | null)[]\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\nexport function getActiveBlockDeviceOverrideValue(\n editor: Editor,\n key: EditableBlockKey,\n breakpoints: Breakpoints,\n deviceId: BreakpointId,\n) {\n const active: (Slate.BlockTextAlignment | null)[] = []\n const blocks = getBlocksInSelection(editor)\n\n blocks.forEach(([block]) => {\n const deviceOverride =\n findBreakpointOverride<Slate.BlockTextAlignment>(breakpoints, block[key], deviceId) || null\n active.push(deviceOverride?.value ?? null)\n })\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\n// Typography\n\nconst concat = (a: unknown[], b: unknown[]) => a.concat(b)\n\n// TODO: This is more cruft from trying to remove null from the typography type. This optimization is not worth it.\n/**\n * This is a c/p of the intersection of the utils from the root utils folder.\n * The only change is defaulting to undefined instead of to null.\n */\nexport default function intersection<A extends Record<string, unknown>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: unknown, b: unknown) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | undefined } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce(\n (acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = undefined\n\n return acc\n },\n {} as { [K in keyof A]: A[K] | undefined },\n )\n}\n\nconst fuseTypographyMarks = (\n values: Array<Slate.Typography | null | undefined>,\n breakpoints: Breakpoints,\n): Slate.Typography => {\n const devices = [\n ...new Set(\n values\n .filter(isNonNullable)\n .map(({ style }) => style.map(({ deviceId }) => deviceId))\n .reduce(concat, []),\n ),\n ] as BreakpointId[]\n\n return {\n id: values.map(v => v && v.id).reduce((a, b) => (a === b ? a : undefined)) ?? undefined,\n style: devices.map(deviceId =>\n values\n .map(\n v =>\n (v && findBreakpointOverride(breakpoints, v.style, deviceId)) || {\n deviceId,\n value: {},\n },\n )\n .reduce((acc, { value }) => {\n const a = intersection(acc.value, value)\n return {\n deviceId,\n value: a,\n }\n }),\n ),\n }\n}\n\nexport function getActiveTypographyMark(\n editor: Editor,\n breakpoints: Breakpoints,\n): Slate.Typography {\n const active: Slate.Typography[] = []\n\n const textNodes = Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Text.isText(node),\n })\n\n for (const [node] of textNodes) {\n if (Text.isText(node) && 'typography' in node && node.typography != undefined) {\n active.push(node.typography)\n }\n }\n return active.length === 0 ? { style: [] } : fuseTypographyMarks(active, breakpoints)\n}\n"],"mappings":"AAAA,SAAS,QAA0B,YAAY;AAC/C;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AAIP,OAAO,iBAAiB;AACxB,OAAO,kBAAkB;AACzB,SAAS,qBAAqB;AAE9B,OAAO,eAAe;AACtB,OAAO,UAAU;AAEV,SAAS,aAAa,QAAuB;AAClD,MAAI,OAAO;AAAW,WAAO,YAAY,QAAQ,OAAO,SAAS;AACjE,SAAO;AAAA,IACL,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO,OAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,EAC9B;AACF;AAEO,SAAS,qBAAqB,QAA8C;AACjF,SAAO,MAAM;AAAA,IACX,OAAO,MAAM,QAAQ;AAAA,MACnB,IAAI,aAAa,MAAM;AAAA,MACvB,OAAO,UAAQ,MAAM,YAAY,IAAI;AAAA,IACvC,CAAC;AAAA,EACH,EAAE,OAAO,CAAC,UAA+C,MAAM,YAAY,MAAM,CAAC,CAAC,CAAC;AACtF;AAEO,SAAS,sBAAsB,QAA2C;AAC/E,SAAO,MAAM;AAAA,IACX,OAAO,MAAM,QAAQ;AAAA,MACnB,IAAI,aAAa,MAAM;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