@makeswift/runtime 0.27.2 → 0.27.3

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 (240) hide show
  1. package/dist/cjs/api/api-resources-client.js +160 -0
  2. package/dist/cjs/api/api-resources-client.js.map +1 -0
  3. package/dist/cjs/api-handler/handlers/manifest.js +1 -1
  4. package/dist/cjs/api-handler/handlers/webhook/diff-projection.js +62 -0
  5. package/dist/cjs/api-handler/handlers/webhook/diff-projection.js.map +1 -0
  6. package/dist/cjs/box-model.js +33 -0
  7. package/dist/cjs/box-model.js.map +1 -0
  8. package/dist/cjs/builder/serialization.js +78 -0
  9. package/dist/cjs/builder/serialization.js.map +1 -0
  10. package/dist/cjs/client/index.js +3 -3
  11. package/dist/cjs/components/builtin/index.js +84 -0
  12. package/dist/cjs/components/builtin/index.js.map +1 -0
  13. package/dist/cjs/components/index.js +25 -0
  14. package/dist/cjs/components/index.js.map +1 -0
  15. package/dist/cjs/controls/rich-text-v2/translation.js +187 -0
  16. package/dist/cjs/controls/rich-text-v2/translation.js.map +1 -0
  17. package/dist/cjs/controls/serialization/base/index.js +78 -0
  18. package/dist/cjs/controls/serialization/base/index.js.map +1 -0
  19. package/dist/cjs/controls/serialization/base/visitor.js +59 -0
  20. package/dist/cjs/controls/serialization/base/visitor.js.map +1 -0
  21. package/dist/cjs/controls/serialization/index.js +55 -0
  22. package/dist/cjs/controls/serialization/index.js.map +1 -0
  23. package/dist/cjs/controls/serialization/message-port/function-serialization.js +79 -0
  24. package/dist/cjs/controls/serialization/message-port/function-serialization.js.map +1 -0
  25. package/dist/cjs/controls/serialization/message-port/index.js +25 -0
  26. package/dist/cjs/controls/serialization/message-port/index.js.map +1 -0
  27. package/dist/cjs/controls/serialization/message-port/visitor.js +48 -0
  28. package/dist/cjs/controls/serialization/message-port/visitor.js.map +1 -0
  29. package/dist/cjs/core/index.js +57 -0
  30. package/dist/cjs/core/index.js.map +1 -0
  31. package/dist/cjs/next/api-handler/config/pages-router.js +1 -1
  32. package/dist/cjs/next/api-handler/config/pages-router.js.map +1 -1
  33. package/dist/cjs/next/fetch.js +30 -0
  34. package/dist/cjs/next/fetch.js.map +1 -0
  35. package/dist/cjs/prop-controllers/index.js +48 -0
  36. package/dist/cjs/prop-controllers/index.js.map +1 -0
  37. package/dist/cjs/prop-controllers/serialization.js +355 -0
  38. package/dist/cjs/prop-controllers/serialization.js.map +1 -0
  39. package/dist/cjs/react.js +40 -0
  40. package/dist/cjs/react.js.map +1 -0
  41. package/dist/cjs/runtimes/react/components/LiveProvider.js.map +1 -1
  42. package/dist/cjs/runtimes/react/components/MakeswiftFonts.js +33 -0
  43. package/dist/cjs/runtimes/react/components/MakeswiftFonts.js.map +1 -0
  44. package/dist/cjs/runtimes/react/components/PreviewProvider.js +3 -9
  45. package/dist/cjs/runtimes/react/components/PreviewProvider.js.map +1 -1
  46. package/dist/cjs/runtimes/react/components/hooks/use-builder-connection-ping.js +10 -5
  47. package/dist/cjs/runtimes/react/components/hooks/use-builder-connection-ping.js.map +1 -1
  48. package/dist/cjs/runtimes/react/hooks/use-current-breakpoint.js +39 -0
  49. package/dist/cjs/runtimes/react/hooks/use-current-breakpoint.js.map +1 -0
  50. package/dist/cjs/runtimes/react/lib/resolved-style-to-css.js +59 -0
  51. package/dist/cjs/runtimes/react/lib/resolved-style-to-css.js.map +1 -0
  52. package/dist/cjs/runtimes/react/resource-resolver.js +52 -0
  53. package/dist/cjs/runtimes/react/resource-resolver.js.map +1 -0
  54. package/dist/cjs/state/actions.js +423 -0
  55. package/dist/cjs/state/actions.js.map +1 -0
  56. package/dist/cjs/state/api-client/client-store.js +81 -0
  57. package/dist/cjs/state/api-client/client-store.js.map +1 -0
  58. package/dist/cjs/state/api-client/fetch-api-resource.js +125 -0
  59. package/dist/cjs/state/api-client/fetch-api-resource.js.map +1 -0
  60. package/dist/cjs/state/api-client/state.js +89 -0
  61. package/dist/cjs/state/api-client/state.js.map +1 -0
  62. package/dist/cjs/state/api-client/store.js +36 -0
  63. package/dist/cjs/state/api-client/store.js.map +1 -0
  64. package/dist/cjs/state/builder-api/api.js +17 -0
  65. package/dist/cjs/state/builder-api/api.js.map +1 -0
  66. package/dist/cjs/state/builder-api/navigation-listener.js +110 -0
  67. package/dist/cjs/state/builder-api/navigation-listener.js.map +1 -0
  68. package/dist/cjs/state/mixins/breakpoint-watch.js +72 -0
  69. package/dist/cjs/state/mixins/breakpoint-watch.js.map +1 -0
  70. package/dist/cjs/state/react-builder-preview.js +97 -73
  71. package/dist/cjs/state/react-builder-preview.js.map +1 -1
  72. package/dist/cjs/state/react-page.js +57 -15
  73. package/dist/cjs/state/react-page.js.map +1 -1
  74. package/dist/cjs/utils/ref-counted-map.js +120 -0
  75. package/dist/cjs/utils/ref-counted-map.js.map +1 -0
  76. package/dist/esm/api/api-resources-client.js +127 -0
  77. package/dist/esm/api/api-resources-client.js.map +1 -0
  78. package/dist/esm/api-handler/handlers/manifest.js +1 -1
  79. package/dist/esm/api-handler/handlers/webhook/diff-projection.js +38 -0
  80. package/dist/esm/api-handler/handlers/webhook/diff-projection.js.map +1 -0
  81. package/dist/esm/box-model.js +7 -0
  82. package/dist/esm/box-model.js.map +1 -0
  83. package/dist/esm/builder/serialization.js +59 -0
  84. package/dist/esm/builder/serialization.js.map +1 -0
  85. package/dist/esm/client/index.js +3 -3
  86. package/dist/esm/components/builtin/index.js +34 -0
  87. package/dist/esm/components/builtin/index.js.map +1 -0
  88. package/dist/esm/components/index.js +3 -0
  89. package/dist/esm/components/index.js.map +1 -0
  90. package/dist/esm/controls/rich-text-v2/translation.js +152 -0
  91. package/dist/esm/controls/rich-text-v2/translation.js.map +1 -0
  92. package/dist/esm/controls/serialization/base/index.js +78 -0
  93. package/dist/esm/controls/serialization/base/index.js.map +1 -0
  94. package/dist/esm/controls/serialization/base/visitor.js +39 -0
  95. package/dist/esm/controls/serialization/base/visitor.js.map +1 -0
  96. package/dist/esm/controls/serialization/index.js +30 -0
  97. package/dist/esm/controls/serialization/index.js.map +1 -0
  98. package/dist/esm/controls/serialization/message-port/function-serialization.js +52 -0
  99. package/dist/esm/controls/serialization/message-port/function-serialization.js.map +1 -0
  100. package/dist/esm/controls/serialization/message-port/index.js +3 -0
  101. package/dist/esm/controls/serialization/message-port/index.js.map +1 -0
  102. package/dist/esm/controls/serialization/message-port/visitor.js +24 -0
  103. package/dist/esm/controls/serialization/message-port/visitor.js.map +1 -0
  104. package/dist/esm/core/index.js +35 -0
  105. package/dist/esm/core/index.js.map +1 -0
  106. package/dist/esm/next/api-handler/config/pages-router.js +1 -1
  107. package/dist/esm/next/api-handler/config/pages-router.js.map +1 -1
  108. package/dist/esm/next/fetch.js +6 -0
  109. package/dist/esm/next/fetch.js.map +1 -0
  110. package/dist/esm/prop-controllers/index.js +11 -0
  111. package/dist/esm/prop-controllers/index.js.map +1 -0
  112. package/dist/esm/prop-controllers/serialization.js +338 -0
  113. package/dist/esm/prop-controllers/serialization.js.map +1 -0
  114. package/dist/esm/react.js +11 -0
  115. package/dist/esm/react.js.map +1 -0
  116. package/dist/esm/runtimes/react/components/LiveProvider.js.map +1 -1
  117. package/dist/esm/runtimes/react/components/MakeswiftFonts.js +9 -0
  118. package/dist/esm/runtimes/react/components/MakeswiftFonts.js.map +1 -0
  119. package/dist/esm/runtimes/react/components/PreviewProvider.js +3 -9
  120. package/dist/esm/runtimes/react/components/PreviewProvider.js.map +1 -1
  121. package/dist/esm/runtimes/react/components/hooks/use-builder-connection-ping.js +10 -5
  122. package/dist/esm/runtimes/react/components/hooks/use-builder-connection-ping.js.map +1 -1
  123. package/dist/esm/runtimes/react/hooks/use-current-breakpoint.js +15 -0
  124. package/dist/esm/runtimes/react/hooks/use-current-breakpoint.js.map +1 -0
  125. package/dist/esm/runtimes/react/lib/resolved-style-to-css.js +38 -0
  126. package/dist/esm/runtimes/react/lib/resolved-style-to-css.js.map +1 -0
  127. package/dist/esm/runtimes/react/resource-resolver.js +28 -0
  128. package/dist/esm/runtimes/react/resource-resolver.js.map +1 -0
  129. package/dist/esm/state/actions.js +349 -0
  130. package/dist/esm/state/actions.js.map +1 -0
  131. package/dist/esm/state/api-client/client-store.js +49 -0
  132. package/dist/esm/state/api-client/client-store.js.map +1 -0
  133. package/dist/esm/state/api-client/fetch-api-resource.js +93 -0
  134. package/dist/esm/state/api-client/fetch-api-resource.js.map +1 -0
  135. package/dist/esm/state/api-client/state.js +52 -0
  136. package/dist/esm/state/api-client/state.js.map +1 -0
  137. package/dist/esm/state/api-client/store.js +12 -0
  138. package/dist/esm/state/api-client/store.js.map +1 -0
  139. package/dist/esm/state/builder-api/api.js +1 -0
  140. package/dist/esm/state/builder-api/api.js.map +1 -0
  141. package/dist/esm/state/builder-api/navigation-listener.js +86 -0
  142. package/dist/esm/state/builder-api/navigation-listener.js.map +1 -0
  143. package/dist/esm/state/mixins/breakpoint-watch.js +48 -0
  144. package/dist/esm/state/mixins/breakpoint-watch.js.map +1 -0
  145. package/dist/esm/state/react-builder-preview.js +115 -72
  146. package/dist/esm/state/react-builder-preview.js.map +1 -1
  147. package/dist/esm/state/react-page.js +62 -11
  148. package/dist/esm/state/react-page.js.map +1 -1
  149. package/dist/esm/utils/ref-counted-map.js +96 -0
  150. package/dist/esm/utils/ref-counted-map.js.map +1 -0
  151. package/dist/types/api/api-resources-client.d.ts +57 -0
  152. package/dist/types/api/api-resources-client.d.ts.map +1 -0
  153. package/dist/types/api-handler/handlers/webhook/diff-projection.d.ts +201 -0
  154. package/dist/types/api-handler/handlers/webhook/diff-projection.d.ts.map +1 -0
  155. package/dist/types/box-model.d.ts +3 -0
  156. package/dist/types/box-model.d.ts.map +1 -0
  157. package/dist/types/builder/serialization.d.ts +23 -0
  158. package/dist/types/builder/serialization.d.ts.map +1 -0
  159. package/dist/types/builder/serialization.test.d.ts +2 -0
  160. package/dist/types/builder/serialization.test.d.ts.map +1 -0
  161. package/dist/types/client/tests/client.get-component-snapshots.test.d.ts +2 -0
  162. package/dist/types/client/tests/client.get-component-snapshots.test.d.ts.map +1 -0
  163. package/dist/types/client/tests/client.introspect-many.test.d.ts +2 -0
  164. package/dist/types/client/tests/client.introspect-many.test.d.ts.map +1 -0
  165. package/dist/types/components/builtin/index.d.ts +17 -0
  166. package/dist/types/components/builtin/index.d.ts.map +1 -0
  167. package/dist/types/components/hooks/__tests__/useMediaQuery.test.d.ts +3 -0
  168. package/dist/types/components/hooks/__tests__/useMediaQuery.test.d.ts.map +1 -0
  169. package/dist/types/components/index.d.ts +3 -0
  170. package/dist/types/components/index.d.ts.map +1 -0
  171. package/dist/types/controls/rich-text-v2/translation.d.ts +6 -0
  172. package/dist/types/controls/rich-text-v2/translation.d.ts.map +1 -0
  173. package/dist/types/controls/serialization/base/index.d.ts +10 -0
  174. package/dist/types/controls/serialization/base/index.d.ts.map +1 -0
  175. package/dist/types/controls/serialization/base/visitor.d.ts +7 -0
  176. package/dist/types/controls/serialization/base/visitor.d.ts.map +1 -0
  177. package/dist/types/controls/serialization/index.d.ts +10 -0
  178. package/dist/types/controls/serialization/index.d.ts.map +1 -0
  179. package/dist/types/controls/serialization/message-port/function-serialization.d.ts +16 -0
  180. package/dist/types/controls/serialization/message-port/function-serialization.d.ts.map +1 -0
  181. package/dist/types/controls/serialization/message-port/function-serialization.test.d.ts +2 -0
  182. package/dist/types/controls/serialization/message-port/function-serialization.test.d.ts.map +1 -0
  183. package/dist/types/controls/serialization/message-port/index.d.ts +3 -0
  184. package/dist/types/controls/serialization/message-port/index.d.ts.map +1 -0
  185. package/dist/types/controls/serialization/message-port/visitor.d.ts +7 -0
  186. package/dist/types/controls/serialization/message-port/visitor.d.ts.map +1 -0
  187. package/dist/types/core/index.d.ts +2 -0
  188. package/dist/types/core/index.d.ts.map +1 -0
  189. package/dist/types/next/api-handler/config/pages-router.test.d.ts +2 -0
  190. package/dist/types/next/api-handler/config/pages-router.test.d.ts.map +1 -0
  191. package/dist/types/next/components/tests/controls/code-control.test.d.ts +2 -0
  192. package/dist/types/next/components/tests/controls/code-control.test.d.ts.map +1 -0
  193. package/dist/types/next/components/tests/makeswift-component-rendering.test.d.ts +3 -0
  194. package/dist/types/next/components/tests/makeswift-component-rendering.test.d.ts.map +1 -0
  195. package/dist/types/next/fetch.d.ts +3 -0
  196. package/dist/types/next/fetch.d.ts.map +1 -0
  197. package/dist/types/prop-controllers/index.d.ts +8 -0
  198. package/dist/types/prop-controllers/index.d.ts.map +1 -0
  199. package/dist/types/prop-controllers/serialization.d.ts +228 -0
  200. package/dist/types/prop-controllers/serialization.d.ts.map +1 -0
  201. package/dist/types/react.d.ts +4 -0
  202. package/dist/types/react.d.ts.map +1 -0
  203. package/dist/types/runtimes/react/components/LiveProvider.d.ts +2 -2
  204. package/dist/types/runtimes/react/components/LiveProvider.d.ts.map +1 -1
  205. package/dist/types/runtimes/react/components/MakeswiftFonts.d.ts +7 -0
  206. package/dist/types/runtimes/react/components/MakeswiftFonts.d.ts.map +1 -0
  207. package/dist/types/runtimes/react/components/PreviewProvider.d.ts +2 -4
  208. package/dist/types/runtimes/react/components/PreviewProvider.d.ts.map +1 -1
  209. package/dist/types/runtimes/react/components/hooks/use-builder-connection-ping.d.ts.map +1 -1
  210. package/dist/types/runtimes/react/hooks/use-current-breakpoint.d.ts +3 -0
  211. package/dist/types/runtimes/react/hooks/use-current-breakpoint.d.ts.map +1 -0
  212. package/dist/types/runtimes/react/lib/resolved-style-to-css.d.ts +4 -0
  213. package/dist/types/runtimes/react/lib/resolved-style-to-css.d.ts.map +1 -0
  214. package/dist/types/runtimes/react/resource-resolver.d.ts +10 -0
  215. package/dist/types/runtimes/react/resource-resolver.d.ts.map +1 -0
  216. package/dist/types/state/actions.d.ts +461 -0
  217. package/dist/types/state/actions.d.ts.map +1 -0
  218. package/dist/types/state/api-client/client-store.d.ts +6 -0
  219. package/dist/types/state/api-client/client-store.d.ts.map +1 -0
  220. package/dist/types/state/api-client/fetch-api-resource.d.ts +11 -0
  221. package/dist/types/state/api-client/fetch-api-resource.d.ts.map +1 -0
  222. package/dist/types/state/api-client/state.d.ts +30 -0
  223. package/dist/types/state/api-client/state.d.ts.map +1 -0
  224. package/dist/types/state/api-client/store.d.ts +18 -0
  225. package/dist/types/state/api-client/store.d.ts.map +1 -0
  226. package/dist/types/state/builder-api/api.d.ts +9 -0
  227. package/dist/types/state/builder-api/api.d.ts.map +1 -0
  228. package/dist/types/state/builder-api/navigation-listener.d.ts +3 -0
  229. package/dist/types/state/builder-api/navigation-listener.d.ts.map +1 -0
  230. package/dist/types/state/mixins/breakpoint-watch.d.ts +11 -0
  231. package/dist/types/state/mixins/breakpoint-watch.d.ts.map +1 -0
  232. package/dist/types/state/react-builder-preview.d.ts +7 -5
  233. package/dist/types/state/react-builder-preview.d.ts.map +1 -1
  234. package/dist/types/state/react-page.d.ts +3 -3
  235. package/dist/types/state/react-page.d.ts.map +1 -1
  236. package/dist/types/utils/__tests__/ref-counted-map.test.d.ts +2 -0
  237. package/dist/types/utils/__tests__/ref-counted-map.test.d.ts.map +1 -0
  238. package/dist/types/utils/ref-counted-map.d.ts +32 -0
  239. package/dist/types/utils/ref-counted-map.d.ts.map +1 -0
  240. package/package.json +3 -3
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var fetch_api_resource_exports = {};
30
+ __export(fetch_api_resource_exports, {
31
+ fetchAPIResource: () => fetchAPIResource
32
+ });
33
+ module.exports = __toCommonJS(fetch_api_resource_exports);
34
+ var import_site_version = require("../../api/site-version");
35
+ var SiteVersionState = __toESM(require("../modules/site-version"));
36
+ var import_read_only_actions = require("../actions/internal/read-only-actions");
37
+ var import_host_api = require("../host-api");
38
+ var import_api = require("../../api");
39
+ var import_state = require("./state");
40
+ function fetchAPIResource(resourceType, resourceId, fetch, locale) {
41
+ const fetchVersioned = async (url, version) => {
42
+ const response = await fetch(url, {
43
+ headers: {
44
+ "Content-Type": "application/json",
45
+ ...version != null ? { [import_site_version.ApiHandlerHeaders.SiteVersion]: (0, import_site_version.serializeSiteVersion)(version) } : {}
46
+ }
47
+ });
48
+ if (response.status === 404)
49
+ return null;
50
+ if (!response.ok)
51
+ throw new Error(response.statusText);
52
+ if (response.headers.get("content-type")?.includes("application/json") !== true) {
53
+ throw new Error(
54
+ `Expected JSON response from "${url}" but got "${response.headers.get("content-type")}"`
55
+ );
56
+ }
57
+ return response.json();
58
+ };
59
+ return async (dispatch, getState) => {
60
+ const state = getState();
61
+ const version = SiteVersionState.getSiteVersion(state.siteVersion);
62
+ if ((0, import_state.getHasAPIResource)(state, resourceType, resourceId, locale)) {
63
+ return (0, import_state.getAPIResource)(state, resourceType, resourceId, locale);
64
+ }
65
+ let resource;
66
+ switch (resourceType) {
67
+ case import_api.APIResourceType.Swatch:
68
+ resource = await fetchVersioned(`/api/makeswift/swatches/${resourceId}`, version);
69
+ break;
70
+ case import_api.APIResourceType.File:
71
+ resource = await fetchVersioned(`/api/makeswift/files/${resourceId}`, version);
72
+ break;
73
+ case import_api.APIResourceType.Typography:
74
+ resource = await fetchVersioned(
75
+ `/api/makeswift/typographies/${resourceId}`,
76
+ version
77
+ );
78
+ break;
79
+ case import_api.APIResourceType.GlobalElement:
80
+ resource = await fetchVersioned(
81
+ `/api/makeswift/global-elements/${resourceId}`,
82
+ version
83
+ );
84
+ break;
85
+ case import_api.APIResourceType.LocalizedGlobalElement: {
86
+ if (locale == null)
87
+ throw new Error("Locale is required to fetch LocalizedGlobalElement");
88
+ if ((0, import_state.getLocalizedResourceId)(state, locale, resourceId) === null) {
89
+ return null;
90
+ }
91
+ resource = await fetchVersioned(
92
+ `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,
93
+ version
94
+ );
95
+ dispatch(
96
+ (0, import_host_api.setLocalizedResourceId)({
97
+ locale,
98
+ resourceId,
99
+ localizedResourceId: resource?.id ?? null
100
+ })
101
+ );
102
+ break;
103
+ }
104
+ case import_api.APIResourceType.PagePathnameSlice: {
105
+ const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, "http://n");
106
+ if (locale != null)
107
+ url.searchParams.set("locale", locale);
108
+ resource = await fetchVersioned(url.pathname + url.search, version);
109
+ break;
110
+ }
111
+ case import_api.APIResourceType.Table:
112
+ resource = await fetchVersioned(`/api/makeswift/tables/${resourceId}`, version);
113
+ break;
114
+ default:
115
+ resource = null;
116
+ }
117
+ dispatch((0, import_read_only_actions.apiResourceFulfilled)(resourceType, resourceId, resource, locale));
118
+ return resource;
119
+ };
120
+ }
121
+ // Annotate the CommonJS export names for ESM import in node:
122
+ 0 && (module.exports = {
123
+ fetchAPIResource
124
+ });
125
+ //# sourceMappingURL=fetch-api-resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/state/api-client/fetch-api-resource.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { type SiteVersion, ApiHandlerHeaders, serializeSiteVersion } from '../../api/site-version'\n\nimport * as SiteVersionState from '../modules/site-version'\n\nimport { type Action } from '../actions'\nimport { apiResourceFulfilled } from '../actions/internal/read-only-actions'\nimport { setLocalizedResourceId } from '../host-api'\n\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n} from '../../api'\n\nimport { type State, getHasAPIResource, getAPIResource, getLocalizedResourceId } from './state'\n\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n fetch: HttpFetch,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n const fetchVersioned = async <T>(url: string, version: SiteVersion | null): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(version != null\n ? { [ApiHandlerHeaders.SiteVersion]: serializeSiteVersion(version) }\n : {}),\n },\n })\n\n if (response.status === 404) return null\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n }\n\n return async (dispatch, getState) => {\n const state = getState()\n const version = SiteVersionState.getSiteVersion(state.siteVersion)\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchVersioned<Swatch>(`/api/makeswift/swatches/${resourceId}`, version)\n break\n\n case APIResourceType.File:\n resource = await fetchVersioned<File>(`/api/makeswift/files/${resourceId}`, version)\n break\n\n case APIResourceType.Typography:\n resource = await fetchVersioned<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchVersioned<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchVersioned<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n version,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchVersioned<PagePathnameSlice>(url.pathname + url.search, version)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchVersioned<Table>(`/api/makeswift/tables/${resourceId}`, version)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAA0E;AAE1E,uBAAkC;AAGlC,+BAAqC;AACrC,sBAAuC;AAEvC,iBAWO;AAEP,mBAAsF;AAM/E,SAAS,iBACd,cACA,YACA,OACA,QACgE;AAChE,QAAM,iBAAiB,OAAU,KAAa,YAAmD;AAC/F,UAAM,WAAW,MAAM,MAAM,KAAK;AAAA,MAChC,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,GAAI,WAAW,OACX,EAAE,CAAC,sCAAkB,WAAW,OAAG,0CAAqB,OAAO,EAAE,IACjE,CAAC;AAAA,MACP;AAAA,IACF,CAAC;AAED,QAAI,SAAS,WAAW;AAAK,aAAO;AACpC,QAAI,CAAC,SAAS;AAAI,YAAM,IAAI,MAAM,SAAS,UAAU;AAErD,QAAI,SAAS,QAAQ,IAAI,cAAc,GAAG,SAAS,kBAAkB,MAAM,MAAM;AAC/E,YAAM,IAAI;AAAA,QACR,gCAAgC,GAAG,cAAc,SAAS,QAAQ,IAAI,cAAc,CAAC;AAAA,MACvF;AAAA,IACF;AAEA,WAAO,SAAS,KAAK;AAAA,EACvB;AAEA,SAAO,OAAO,UAAU,aAAa;AACnC,UAAM,QAAQ,SAAS;AACvB,UAAM,UAAU,iBAAiB,eAAe,MAAM,WAAW;AAEjE,YAAI,gCAAkB,OAAO,cAAc,YAAY,MAAM,GAAG;AAC9D,iBAAO,6BAAe,OAAO,cAAc,YAAY,MAAM;AAAA,IAC/D;AAEA,QAAI;AAEJ,YAAQ,cAAc;AAAA,MACpB,KAAK,2BAAgB;AACnB,mBAAW,MAAM,eAAuB,2BAA2B,UAAU,IAAI,OAAO;AACxF;AAAA,MAEF,KAAK,2BAAgB;AACnB,mBAAW,MAAM,eAAqB,wBAAwB,UAAU,IAAI,OAAO;AACnF;AAAA,MAEF,KAAK,2BAAgB;AACnB,mBAAW,MAAM;AAAA,UACf,+BAA+B,UAAU;AAAA,UACzC;AAAA,QACF;AACA;AAAA,MAEF,KAAK,2BAAgB;AACnB,mBAAW,MAAM;AAAA,UACf,kCAAkC,UAAU;AAAA,UAC5C;AAAA,QACF;AACA;AAAA,MAEF,KAAK,2BAAgB,wBAAwB;AAC3C,YAAI,UAAU;AAAM,gBAAM,IAAI,MAAM,oDAAoD;AAIxF,gBAAI,qCAAuB,OAAO,QAAQ,UAAU,MAAM,MAAM;AAC9D,iBAAO;AAAA,QACT;AAEA,mBAAW,MAAM;AAAA,UACf,4CAA4C,UAAU,IAAI,MAAM;AAAA,UAChE;AAAA,QACF;AAEA;AAAA,cACE,wCAAuB;AAAA,YACrB;AAAA,YACA;AAAA,YACA,qBAAqB,UAAU,MAAM;AAAA,UACvC,CAAC;AAAA,QACH;AAEA;AAAA,MACF;AAAA,MAEA,KAAK,2BAAgB,mBAAmB;AACtC,cAAM,MAAM,IAAI,IAAI,uCAAuC,UAAU,IAAI,UAAU;AAEnF,YAAI,UAAU;AAAM,cAAI,aAAa,IAAI,UAAU,MAAM;AAEzD,mBAAW,MAAM,eAAkC,IAAI,WAAW,IAAI,QAAQ,OAAO;AACrF;AAAA,MACF;AAAA,MAEA,KAAK,2BAAgB;AACnB,mBAAW,MAAM,eAAsB,yBAAyB,UAAU,IAAI,OAAO;AACrF;AAAA,MAEF;AACE,mBAAW;AAAA,IACf;AAEA,iBAAS,+CAAqB,cAAc,YAAY,UAAU,MAAM,CAAC;AAEzE,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var state_exports = {};
30
+ __export(state_exports, {
31
+ getAPIResource: () => getAPIResource,
32
+ getHasAPIResource: () => getHasAPIResource,
33
+ getLocalizedResourceId: () => getLocalizedResourceId,
34
+ reducer: () => reducer
35
+ });
36
+ module.exports = __toCommonJS(state_exports);
37
+ var import_toolkit = require("@reduxjs/toolkit");
38
+ var SiteVersionState = __toESM(require("../modules/site-version"));
39
+ var LocaleState = __toESM(require("../modules/locale"));
40
+ var APIResources = __toESM(require("../modules/api-resources"));
41
+ var LocalizedResourcesMap = __toESM(require("../modules/localized-resources-map"));
42
+ var import_api = require("../../api");
43
+ const reducer = (0, import_toolkit.combineReducers)({
44
+ siteVersion: SiteVersionState.reducer,
45
+ locale: LocaleState.reducer,
46
+ apiResources: APIResources.reducer,
47
+ localizedResourcesMap: LocalizedResourcesMap.reducer
48
+ });
49
+ function getLocalizedResourceId(state, locale, resourceId) {
50
+ return LocalizedResourcesMap.getLocalizedResourceId(
51
+ state.localizedResourcesMap,
52
+ locale,
53
+ resourceId
54
+ );
55
+ }
56
+ function getHasAPIResource(state, resourceType, resourceId, locale) {
57
+ switch (resourceType) {
58
+ case import_api.APIResourceType.LocalizedGlobalElement:
59
+ if (locale == null) {
60
+ console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`);
61
+ return false;
62
+ }
63
+ const localizedId = getLocalizedResourceId(state, locale, resourceId);
64
+ return localizedId != null && APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale);
65
+ default:
66
+ return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale);
67
+ }
68
+ }
69
+ function getAPIResource(state, resourceType, resourceId, locale) {
70
+ switch (resourceType) {
71
+ case import_api.APIResourceType.LocalizedGlobalElement:
72
+ if (locale == null) {
73
+ console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`);
74
+ return null;
75
+ }
76
+ const localizedId = getLocalizedResourceId(state, locale, resourceId);
77
+ return localizedId != null ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale) : null;
78
+ default:
79
+ return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale);
80
+ }
81
+ }
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ getAPIResource,
85
+ getHasAPIResource,
86
+ getLocalizedResourceId,
87
+ reducer
88
+ });
89
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/state/api-client/state.ts"],"sourcesContent":["import { combineReducers, type ThunkDispatch } from '@reduxjs/toolkit'\n\nimport * as SiteVersionState from '../modules/site-version'\nimport * as LocaleState from '../modules/locale'\nimport * as APIResources from '../modules/api-resources'\nimport * as LocalizedResourcesMap from '../modules/localized-resources-map'\n\nimport { type Action } from '../actions'\n\nimport { APIResourceType, type APIResource, type APIResourceLocale } from '../../api'\n\nexport const reducer = combineReducers({\n siteVersion: SiteVersionState.reducer,\n locale: LocaleState.reducer,\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nexport function getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAoD;AAEpD,uBAAkC;AAClC,kBAA6B;AAC7B,mBAA8B;AAC9B,4BAAuC;AAIvC,iBAA0E;AAEnE,MAAM,cAAU,gCAAgB;AAAA,EACrC,aAAa,iBAAiB;AAAA,EAC9B,QAAQ,YAAY;AAAA,EACpB,cAAc,aAAa;AAAA,EAC3B,uBAAuB,sBAAsB;AAC/C,CAAC;AAUM,SAAS,uBACd,OACA,QACA,YAC2B;AAC3B,SAAO,sBAAsB;AAAA,IAC3B,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,kBACd,OACA,cACA,YACA,QACS;AACT,UAAQ,cAAc;AAAA,IACpB,KAAK,2BAAgB;AACnB,UAAI,UAAU,MAAM;AAClB,gBAAQ,MAAM,qBAAqB,YAAY,IAAI,UAAU,mBAAmB;AAChF,eAAO;AAAA,MACT;AAEA,YAAM,cAAc,uBAAuB,OAAO,QAAQ,UAAU;AACpE,aACE,eAAe,QACf,aAAa,kBAAkB,MAAM,cAAc,cAAc,aAAa,MAAM;AAAA,IAGxF;AACE,aAAO,aAAa,kBAAkB,MAAM,cAAc,cAAc,YAAY,MAAM;AAAA,EAC9F;AACF;AAEO,SAAS,eACd,OACA,cACA,YACA,QACgD;AAChD,UAAQ,cAAc;AAAA,IACpB,KAAK,2BAAgB;AACnB,UAAI,UAAU,MAAM;AAClB,gBAAQ,MAAM,qBAAqB,YAAY,IAAI,UAAU,mBAAmB;AAChF,eAAO;AAAA,MACT;AAEA,YAAM,cAAc,uBAAuB,OAAO,QAAQ,UAAU;AACpE,aAAO,eAAe,OAClB,aAAa,eAAe,MAAM,cAAc,cAAc,aAAa,MAAM,IACjF;AAAA,IAEN;AACE,aAAO,aAAa,eAAe,MAAM,cAAc,cAAc,YAAY,MAAM;AAAA,EAC3F;AACF;","names":[]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var store_exports = {};
20
+ __export(store_exports, {
21
+ configureStore: () => configureStore
22
+ });
23
+ module.exports = __toCommonJS(store_exports);
24
+ var import_toolkit = require("@reduxjs/toolkit");
25
+ var import_state = require("./state");
26
+ function configureStore({ preloadedState }) {
27
+ return (0, import_toolkit.configureStore)({
28
+ reducer: import_state.reducer,
29
+ preloadedState
30
+ });
31
+ }
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ configureStore
35
+ });
36
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/state/api-client/store.ts"],"sourcesContent":["import { configureStore as configureReduxStore } from '@reduxjs/toolkit'\n\nimport { type State, reducer } from './state'\n\nexport function configureStore({ preloadedState }: { preloadedState: Partial<State> }) {\n return configureReduxStore({\n reducer,\n preloadedState,\n })\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsD;AAEtD,mBAAoC;AAE7B,SAAS,eAAe,EAAE,eAAe,GAAuC;AACrF,aAAO,eAAAA,gBAAoB;AAAA,IACzB;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["configureReduxStore"]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var api_exports = {};
16
+ module.exports = __toCommonJS(api_exports);
17
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/state/builder-api/api.ts"],"sourcesContent":["export type HostNavigationEvent = {\n url: string | null\n navigationCompleted?: 'initial-page-load' | 'client-side-navigation'\n // indicates whether the navigation event was captured via the Navigation API or\n // via our polyfill for browsers lacking Navigation API support\n polyfilled?: boolean\n}\n\nexport type BuilderApi = {\n handleHostNavigate(event: HostNavigationEvent): void\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var navigation_listener_exports = {};
20
+ __export(navigation_listener_exports, {
21
+ setupNavigationListener: () => setupNavigationListener
22
+ });
23
+ module.exports = __toCommonJS(navigation_listener_exports);
24
+ const CLICK_NAVIGATION_THRESHOLD_MS = 100;
25
+ const CLICK_NAVIGATION_CHECK_INTERVAL_MS = 200;
26
+ const CLICK_NAVIGATION_MAX_CHECKS = 20;
27
+ function setupNavigationListener(callback) {
28
+ let previousLocation = null;
29
+ const handleNavigate = (event) => {
30
+ if (!event.navigationCompleted && event.url === previousLocation)
31
+ return;
32
+ callback(event);
33
+ previousLocation = event.url;
34
+ };
35
+ handleNavigate({ url: windowLocation(), navigationCompleted: "initial-page-load" });
36
+ if (typeof window === "undefined") {
37
+ return () => {
38
+ };
39
+ }
40
+ const unsubscribes = [];
41
+ if ("navigation" in window && window.navigation) {
42
+ const navigation = window.navigation;
43
+ const navigateHandler = ({ destination }) => handleNavigate({ url: destination.url });
44
+ const navigateSuccessHandler = () => {
45
+ handleNavigate({
46
+ url: navigation.currentEntry.url,
47
+ navigationCompleted: "client-side-navigation"
48
+ });
49
+ };
50
+ navigation.addEventListener("navigate", navigateHandler);
51
+ navigation.addEventListener("navigatesuccess", navigateSuccessHandler);
52
+ unsubscribes.push(() => navigation.removeEventListener("navigate", navigateHandler));
53
+ unsubscribes.push(
54
+ () => navigation.removeEventListener("navigatesuccess", navigateSuccessHandler)
55
+ );
56
+ return () => {
57
+ unsubscribes.forEach((u) => u());
58
+ };
59
+ }
60
+ let lastClickEvent = null;
61
+ const clickHandler = (e) => {
62
+ const a = e.composedPath?.()?.find((n) => n instanceof HTMLAnchorElement) ?? (e.target instanceof Element && e.target.closest?.("a"));
63
+ if (!a)
64
+ return;
65
+ lastClickEvent = { href: a.href, timestamp: Date.now() };
66
+ const pageUrlBeforeClick = windowLocation();
67
+ let navigationCheckCounter = 0;
68
+ const checkIfNavigationOccurred = () => {
69
+ const url = windowLocation();
70
+ if (url !== pageUrlBeforeClick) {
71
+ handleNavigate({ url, polyfilled: true });
72
+ return;
73
+ }
74
+ if (++navigationCheckCounter < CLICK_NAVIGATION_MAX_CHECKS) {
75
+ window.setTimeout(checkIfNavigationOccurred, CLICK_NAVIGATION_CHECK_INTERVAL_MS);
76
+ }
77
+ };
78
+ window.setTimeout(checkIfNavigationOccurred, CLICK_NAVIGATION_CHECK_INTERVAL_MS);
79
+ };
80
+ window.document.addEventListener(
81
+ "click",
82
+ clickHandler,
83
+ { capture: true }
84
+ // run before bubbling to fortify against `stopPropagation()` calls
85
+ );
86
+ unsubscribes.push(
87
+ () => window.document.removeEventListener("click", clickHandler, { capture: true })
88
+ );
89
+ const unloadHandler = () => {
90
+ if (!lastClickEvent)
91
+ return;
92
+ const msSinceLastClick = Date.now() - lastClickEvent.timestamp;
93
+ handleNavigate({
94
+ url: msSinceLastClick < CLICK_NAVIGATION_THRESHOLD_MS ? lastClickEvent.href ?? null : null,
95
+ polyfilled: true
96
+ });
97
+ lastClickEvent = null;
98
+ };
99
+ window.addEventListener("beforeunload", unloadHandler);
100
+ unsubscribes.push(() => window.removeEventListener("beforeunload", unloadHandler));
101
+ return () => {
102
+ unsubscribes.forEach((u) => u());
103
+ };
104
+ }
105
+ const windowLocation = () => typeof window !== "undefined" ? window.location.href : null;
106
+ // Annotate the CommonJS export names for ESM import in node:
107
+ 0 && (module.exports = {
108
+ setupNavigationListener
109
+ });
110
+ //# sourceMappingURL=navigation-listener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/state/builder-api/navigation-listener.ts"],"sourcesContent":["import { type HostNavigationEvent } from './api'\n\ntype ClickEvent = {\n href: string\n timestamp: number\n}\n\nconst CLICK_NAVIGATION_THRESHOLD_MS = 100\nconst CLICK_NAVIGATION_CHECK_INTERVAL_MS = 200\nconst CLICK_NAVIGATION_MAX_CHECKS = 20\n\nexport function setupNavigationListener(\n callback: (args: HostNavigationEvent) => void,\n): VoidFunction {\n let previousLocation: string | null = null\n\n const handleNavigate = (event: HostNavigationEvent) => {\n if (!event.navigationCompleted && event.url === previousLocation) return\n\n callback(event)\n previousLocation = event.url\n }\n\n // trigger navigation callback on initial page load\n handleNavigate({ url: windowLocation(), navigationCompleted: 'initial-page-load' })\n\n if (typeof window === 'undefined') {\n return () => {}\n }\n\n const unsubscribes: (() => void)[] = []\n\n // check for availability of the Navigation API (baseline feature since January 2026),\n // see https://developer.mozilla.org/en-US/docs/Web/API/Navigation_API\n if ('navigation' in window && window.navigation) {\n const navigation = window.navigation\n\n const navigateHandler = ({ destination }: NavigateEvent) =>\n handleNavigate({ url: destination.url })\n\n const navigateSuccessHandler = () => {\n handleNavigate({\n url: navigation.currentEntry.url,\n navigationCompleted: 'client-side-navigation',\n })\n }\n\n // note that in order to capture destination URLs that might not be Makeswift-enabled,\n // we send a `SiteNavigationEvent` at the start of navigation, but do not track whether\n // the navigation was successful or not (possible future improvement)\n navigation.addEventListener('navigate', navigateHandler)\n navigation.addEventListener('navigatesuccess', navigateSuccessHandler)\n unsubscribes.push(() => navigation.removeEventListener('navigate', navigateHandler))\n unsubscribes.push(() =>\n navigation.removeEventListener('navigatesuccess', navigateSuccessHandler),\n )\n\n return () => {\n unsubscribes.forEach(u => u())\n }\n }\n\n // for browsers lacking Navigation API support, we manually track:\n // - link clicks to capture destination URLs\n // - page unload events to detect cross-page navigation\n //\n // this works well enough to keep this polyfill in place for now, but not nearly as\n // reliably as the Navigation API\n let lastClickEvent: ClickEvent | null = null\n\n const clickHandler = (e: MouseEvent) => {\n const a =\n e.composedPath?.()?.find(n => n instanceof HTMLAnchorElement) ??\n (e.target instanceof Element && e.target.closest?.('a'))\n\n if (!a) return\n\n lastClickEvent = { href: a.href, timestamp: Date.now() }\n\n const pageUrlBeforeClick = windowLocation()\n let navigationCheckCounter = 0\n\n // handle navigation between pages in the host; note that we intentionally are\n // not cancelling the timer on cleanup to ensure we report the navigation\n const checkIfNavigationOccurred = () => {\n const url = windowLocation()\n\n if (url !== pageUrlBeforeClick) {\n // the host navigated to a different page, report the new URL to the builder\n handleNavigate({ url, polyfilled: true })\n return\n }\n\n // we're still on the same page, recheck until the max number of checks is reached\n if (++navigationCheckCounter < CLICK_NAVIGATION_MAX_CHECKS) {\n window.setTimeout(checkIfNavigationOccurred, CLICK_NAVIGATION_CHECK_INTERVAL_MS)\n }\n }\n\n window.setTimeout(checkIfNavigationOccurred, CLICK_NAVIGATION_CHECK_INTERVAL_MS)\n }\n\n window.document.addEventListener(\n 'click',\n clickHandler,\n { capture: true }, // run before bubbling to fortify against `stopPropagation()` calls\n )\n\n unsubscribes.push(() =>\n window.document.removeEventListener('click', clickHandler, { capture: true }),\n )\n\n // handle external navigation\n const unloadHandler = () => {\n if (!lastClickEvent) return\n\n const msSinceLastClick = Date.now() - lastClickEvent.timestamp\n handleNavigate({\n url: msSinceLastClick < CLICK_NAVIGATION_THRESHOLD_MS ? (lastClickEvent.href ?? null) : null,\n polyfilled: true,\n })\n\n lastClickEvent = null\n }\n\n window.addEventListener('beforeunload', unloadHandler)\n unsubscribes.push(() => window.removeEventListener('beforeunload', unloadHandler))\n\n return () => {\n unsubscribes.forEach(u => u())\n }\n}\n\nconst windowLocation = (): string | null =>\n typeof window !== 'undefined' ? window.location.href : null\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,MAAM,gCAAgC;AACtC,MAAM,qCAAqC;AAC3C,MAAM,8BAA8B;AAE7B,SAAS,wBACd,UACc;AACd,MAAI,mBAAkC;AAEtC,QAAM,iBAAiB,CAAC,UAA+B;AACrD,QAAI,CAAC,MAAM,uBAAuB,MAAM,QAAQ;AAAkB;AAElE,aAAS,KAAK;AACd,uBAAmB,MAAM;AAAA,EAC3B;AAGA,iBAAe,EAAE,KAAK,eAAe,GAAG,qBAAqB,oBAAoB,CAAC;AAElF,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AAEA,QAAM,eAA+B,CAAC;AAItC,MAAI,gBAAgB,UAAU,OAAO,YAAY;AAC/C,UAAM,aAAa,OAAO;AAE1B,UAAM,kBAAkB,CAAC,EAAE,YAAY,MACrC,eAAe,EAAE,KAAK,YAAY,IAAI,CAAC;AAEzC,UAAM,yBAAyB,MAAM;AACnC,qBAAe;AAAA,QACb,KAAK,WAAW,aAAa;AAAA,QAC7B,qBAAqB;AAAA,MACvB,CAAC;AAAA,IACH;AAKA,eAAW,iBAAiB,YAAY,eAAe;AACvD,eAAW,iBAAiB,mBAAmB,sBAAsB;AACrE,iBAAa,KAAK,MAAM,WAAW,oBAAoB,YAAY,eAAe,CAAC;AACnF,iBAAa;AAAA,MAAK,MAChB,WAAW,oBAAoB,mBAAmB,sBAAsB;AAAA,IAC1E;AAEA,WAAO,MAAM;AACX,mBAAa,QAAQ,OAAK,EAAE,CAAC;AAAA,IAC/B;AAAA,EACF;AAQA,MAAI,iBAAoC;AAExC,QAAM,eAAe,CAAC,MAAkB;AACtC,UAAM,IACJ,EAAE,eAAe,GAAG,KAAK,OAAK,aAAa,iBAAiB,MAC3D,EAAE,kBAAkB,WAAW,EAAE,OAAO,UAAU,GAAG;AAExD,QAAI,CAAC;AAAG;AAER,qBAAiB,EAAE,MAAM,EAAE,MAAM,WAAW,KAAK,IAAI,EAAE;AAEvD,UAAM,qBAAqB,eAAe;AAC1C,QAAI,yBAAyB;AAI7B,UAAM,4BAA4B,MAAM;AACtC,YAAM,MAAM,eAAe;AAE3B,UAAI,QAAQ,oBAAoB;AAE9B,uBAAe,EAAE,KAAK,YAAY,KAAK,CAAC;AACxC;AAAA,MACF;AAGA,UAAI,EAAE,yBAAyB,6BAA6B;AAC1D,eAAO,WAAW,2BAA2B,kCAAkC;AAAA,MACjF;AAAA,IACF;AAEA,WAAO,WAAW,2BAA2B,kCAAkC;AAAA,EACjF;AAEA,SAAO,SAAS;AAAA,IACd;AAAA,IACA;AAAA,IACA,EAAE,SAAS,KAAK;AAAA;AAAA,EAClB;AAEA,eAAa;AAAA,IAAK,MAChB,OAAO,SAAS,oBAAoB,SAAS,cAAc,EAAE,SAAS,KAAK,CAAC;AAAA,EAC9E;AAGA,QAAM,gBAAgB,MAAM;AAC1B,QAAI,CAAC;AAAgB;AAErB,UAAM,mBAAmB,KAAK,IAAI,IAAI,eAAe;AACrD,mBAAe;AAAA,MACb,KAAK,mBAAmB,gCAAiC,eAAe,QAAQ,OAAQ;AAAA,MACxF,YAAY;AAAA,IACd,CAAC;AAED,qBAAiB;AAAA,EACnB;AAEA,SAAO,iBAAiB,gBAAgB,aAAa;AACrD,eAAa,KAAK,MAAM,OAAO,oBAAoB,gBAAgB,aAAa,CAAC;AAEjF,SAAO,MAAM;AACX,iBAAa,QAAQ,OAAK,EAAE,CAAC;AAAA,EAC/B;AACF;AAEA,MAAM,iBAAiB,MACrB,OAAO,WAAW,cAAc,OAAO,SAAS,OAAO;","names":[]}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var breakpoint_watch_exports = {};
20
+ __export(breakpoint_watch_exports, {
21
+ breakpointWatchMixin: () => breakpointWatchMixin
22
+ });
23
+ module.exports = __toCommonJS(breakpoint_watch_exports);
24
+ var import_read_only_actions = require("../actions/internal/read-only-actions");
25
+ var import_breakpoints = require("../modules/breakpoints");
26
+ var import_read_only_state = require("../read-only-state");
27
+ function breakpointWatchMixin({
28
+ dispatch,
29
+ getState,
30
+ subscribe: storeSubscribe
31
+ }) {
32
+ let mediaQueryUnsubscribes = [];
33
+ let storeUnsubscribe = null;
34
+ let watchedBreakpoints = [];
35
+ const startWatch = (breakpoints) => {
36
+ mediaQueryUnsubscribes.forEach((fn) => fn());
37
+ const updateState = () => dispatch((0, import_read_only_actions.updateClientBreakpoint)());
38
+ mediaQueryUnsubscribes = (0, import_breakpoints.getDeviceQueries)(breakpoints).map((q) => {
39
+ const mediaQueryList = window.matchMedia(q.query);
40
+ mediaQueryList.addEventListener("change", updateState);
41
+ return () => mediaQueryList.removeEventListener("change", updateState);
42
+ });
43
+ watchedBreakpoints = breakpoints;
44
+ updateState();
45
+ };
46
+ return {
47
+ startBreakpointWatch: () => {
48
+ if (storeUnsubscribe !== null) {
49
+ console.warn("Unexpected `BreakpointWatch.startBreakpointWatch` call, already watching");
50
+ return;
51
+ }
52
+ startWatch((0, import_read_only_state.getBreakpoints)(getState()));
53
+ storeUnsubscribe = storeSubscribe(() => {
54
+ const breakpoints = (0, import_read_only_state.getBreakpoints)(getState());
55
+ if (breakpoints !== watchedBreakpoints) {
56
+ startWatch(breakpoints);
57
+ }
58
+ });
59
+ },
60
+ stopBreakpointWatch: () => {
61
+ mediaQueryUnsubscribes.forEach((fn) => fn());
62
+ mediaQueryUnsubscribes = [];
63
+ storeUnsubscribe?.();
64
+ storeUnsubscribe = null;
65
+ }
66
+ };
67
+ }
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ breakpointWatchMixin
71
+ });
72
+ //# sourceMappingURL=breakpoint-watch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/state/mixins/breakpoint-watch.ts"],"sourcesContent":["import { updateClientBreakpoint } from '../actions/internal/read-only-actions'\nimport { Breakpoints, getDeviceQueries } from '../modules/breakpoints'\n\nimport { type State, type Dispatch } from '../unified-state'\nimport { getBreakpoints } from '../read-only-state'\n\nexport interface BreakpointWatch {\n startBreakpointWatch(): void\n stopBreakpointWatch(): void\n}\n\nexport function breakpointWatchMixin({\n dispatch,\n getState,\n subscribe: storeSubscribe,\n}: {\n dispatch: Dispatch\n getState: () => State\n subscribe: (listener: VoidFunction) => VoidFunction\n}): BreakpointWatch {\n let mediaQueryUnsubscribes: VoidFunction[] = []\n let storeUnsubscribe: VoidFunction | null = null\n let watchedBreakpoints: Breakpoints = []\n\n // client-side breakpoint watch\n const startWatch = (breakpoints: Breakpoints) => {\n mediaQueryUnsubscribes.forEach(fn => fn())\n\n const updateState = () => dispatch(updateClientBreakpoint())\n\n mediaQueryUnsubscribes = getDeviceQueries(breakpoints).map(q => {\n const mediaQueryList = window.matchMedia(q.query)\n mediaQueryList.addEventListener('change', updateState)\n return () => mediaQueryList.removeEventListener('change', updateState)\n })\n\n watchedBreakpoints = breakpoints\n\n // reconcile the store with the current client breakpoint after subscribing;\n // this heals any stale breakpoint state from changes that happened\n // after the store was created or updated but before the listeners were attached\n updateState()\n }\n\n return {\n startBreakpointWatch: () => {\n if (storeUnsubscribe !== null) {\n console.warn('Unexpected `BreakpointWatch.startBreakpointWatch` call, already watching')\n return\n }\n\n startWatch(getBreakpoints(getState()))\n\n storeUnsubscribe = storeSubscribe(() => {\n const breakpoints = getBreakpoints(getState())\n if (breakpoints !== watchedBreakpoints) {\n startWatch(breakpoints)\n }\n })\n },\n\n stopBreakpointWatch: () => {\n mediaQueryUnsubscribes.forEach(fn => fn())\n mediaQueryUnsubscribes = []\n\n storeUnsubscribe?.()\n storeUnsubscribe = null\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAAuC;AACvC,yBAA8C;AAG9C,6BAA+B;AAOxB,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA,WAAW;AACb,GAIoB;AAClB,MAAI,yBAAyC,CAAC;AAC9C,MAAI,mBAAwC;AAC5C,MAAI,qBAAkC,CAAC;AAGvC,QAAM,aAAa,CAAC,gBAA6B;AAC/C,2BAAuB,QAAQ,QAAM,GAAG,CAAC;AAEzC,UAAM,cAAc,MAAM,aAAS,iDAAuB,CAAC;AAE3D,iCAAyB,qCAAiB,WAAW,EAAE,IAAI,OAAK;AAC9D,YAAM,iBAAiB,OAAO,WAAW,EAAE,KAAK;AAChD,qBAAe,iBAAiB,UAAU,WAAW;AACrD,aAAO,MAAM,eAAe,oBAAoB,UAAU,WAAW;AAAA,IACvE,CAAC;AAED,yBAAqB;AAKrB,gBAAY;AAAA,EACd;AAEA,SAAO;AAAA,IACL,sBAAsB,MAAM;AAC1B,UAAI,qBAAqB,MAAM;AAC7B,gBAAQ,KAAK,0EAA0E;AACvF;AAAA,MACF;AAEA,qBAAW,uCAAe,SAAS,CAAC,CAAC;AAErC,yBAAmB,eAAe,MAAM;AACtC,cAAM,kBAAc,uCAAe,SAAS,CAAC;AAC7C,YAAI,gBAAgB,oBAAoB;AACtC,qBAAW,WAAW;AAAA,QACxB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IAEA,qBAAqB,MAAM;AACzB,6BAAuB,QAAQ,QAAM,GAAG,CAAC;AACzC,+BAAyB,CAAC;AAE1B,yBAAmB;AACnB,yBAAmB;AAAA,IACrB;AAAA,EACF;AACF;","names":[]}