@farm.js/core 0.1.0-beta.54 → 0.1.0-beta.56

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 (67) hide show
  1. package/dist/{chunk-427JQ6OZ.mjs → chunk-5T2XATMK.mjs} +58 -11
  2. package/dist/chunk-5T2XATMK.mjs.map +1 -0
  3. package/dist/{chunk-J34JCW6R.mjs → chunk-FOEPWRHM.mjs} +2 -2
  4. package/dist/{chunk-BDHDDITP.mjs → chunk-FPLRESQA.mjs} +30 -18
  5. package/dist/chunk-FPLRESQA.mjs.map +1 -0
  6. package/dist/{chunk-JECGLPIS.mjs → chunk-PYIVNTDI.mjs} +4 -4
  7. package/dist/{chunk-GPHLXAFT.mjs → chunk-UH5R4J5M.mjs} +2 -2
  8. package/dist/{chunk-ENPB4CSY.mjs → chunk-XLQVJDK2.mjs} +2 -2
  9. package/dist/{chunk-ENPB4CSY.mjs.map → chunk-XLQVJDK2.mjs.map} +1 -1
  10. package/dist/{chunk-GVQ54ERX.mjs → chunk-YPKCFGA7.mjs} +9 -3
  11. package/dist/chunk-YPKCFGA7.mjs.map +1 -0
  12. package/dist/{chunk-PGZVE6P7.mjs → chunk-ZOQLQAUG.mjs} +2 -2
  13. package/dist/client/lifecycle.mjs +2 -2
  14. package/dist/client-plugins.cjs +1 -1
  15. package/dist/client-plugins.cjs.map +1 -1
  16. package/dist/client-plugins.mjs +2 -2
  17. package/dist/client.cjs +76 -23
  18. package/dist/client.cjs.map +1 -1
  19. package/dist/client.d.mts +2 -5
  20. package/dist/client.d.ts +2 -5
  21. package/dist/client.mjs +11 -11
  22. package/dist/index.cjs +85 -24
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.mts +1 -1
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.mjs +17 -17
  27. package/dist/internal/build-runtime.cjs +8 -2
  28. package/dist/internal/build-runtime.cjs.map +1 -1
  29. package/dist/internal/build-runtime.mjs +3 -3
  30. package/dist/internal/client-runtime.cjs +1 -1
  31. package/dist/internal/client-runtime.cjs.map +1 -1
  32. package/dist/internal/client-runtime.mjs +2 -2
  33. package/dist/navigation.cjs +74 -20
  34. package/dist/navigation.cjs.map +1 -1
  35. package/dist/navigation.mjs +4 -4
  36. package/dist/plugin.cjs +1 -1
  37. package/dist/plugin.cjs.map +1 -1
  38. package/dist/plugin.mjs +2 -2
  39. package/dist/query/client.cjs +105 -11
  40. package/dist/query/client.cjs.map +1 -1
  41. package/dist/query/client.mjs +18 -11
  42. package/dist/query/client.mjs.map +1 -1
  43. package/dist/renderer-client.cjs +56 -12
  44. package/dist/renderer-client.cjs.map +1 -1
  45. package/dist/renderer-client.d.mts +1 -1
  46. package/dist/renderer-client.d.ts +1 -1
  47. package/dist/renderer-client.mjs +12 -11
  48. package/dist/renderer-client.mjs.map +1 -1
  49. package/dist/server.cjs +1 -1
  50. package/dist/server.cjs.map +1 -1
  51. package/dist/server.mjs +2 -2
  52. package/dist/{spa-router-BD7iUG-C.d.mts → spa-router-BV71GGW0.d.mts} +4 -3
  53. package/dist/{spa-router-swFKTqwR.d.ts → spa-router-BylM6JXm.d.ts} +4 -3
  54. package/dist/version.cjs +1 -1
  55. package/dist/version.cjs.map +1 -1
  56. package/dist/version.mjs +1 -1
  57. package/dist/vite.cjs +1 -1
  58. package/dist/vite.cjs.map +1 -1
  59. package/dist/vite.mjs +2 -2
  60. package/package.json +1 -1
  61. package/dist/chunk-427JQ6OZ.mjs.map +0 -1
  62. package/dist/chunk-BDHDDITP.mjs.map +0 -1
  63. package/dist/chunk-GVQ54ERX.mjs.map +0 -1
  64. /package/dist/{chunk-J34JCW6R.mjs.map → chunk-FOEPWRHM.mjs.map} +0 -0
  65. /package/dist/{chunk-JECGLPIS.mjs.map → chunk-PYIVNTDI.mjs.map} +0 -0
  66. /package/dist/{chunk-GPHLXAFT.mjs.map → chunk-UH5R4J5M.mjs.map} +0 -0
  67. /package/dist/{chunk-PGZVE6P7.mjs.map → chunk-ZOQLQAUG.mjs.map} +0 -0
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  createClientPluginManager,
3
3
  installChunkErrorRecovery
4
- } from "../chunk-J34JCW6R.mjs";
4
+ } from "../chunk-FOEPWRHM.mjs";
5
5
  import {
6
6
  searchParamsToObject
7
7
  } from "../chunk-4DCGM2BW.mjs";
8
8
  import "../chunk-FXG2PS27.mjs";
9
- import "../chunk-ENPB4CSY.mjs";
9
+ import "../chunk-XLQVJDK2.mjs";
10
10
  import {
11
11
  __name
12
12
  } from "../chunk-CGILA3WO.mjs";
@@ -435,6 +435,35 @@ function rejectPendingDeferred(controllers, message) {
435
435
  }
436
436
  __name(rejectPendingDeferred, "rejectPendingDeferred");
437
437
 
438
+ // src/client/history-sync.ts
439
+ var FARM_HISTORY_CHANGE_EVENT = "farm:historychange";
440
+ function notifyHistoryChange(kind) {
441
+ if (typeof window === "undefined") return;
442
+ setTimeout(() => {
443
+ if (kind === "url-search" && !getInstalledFarmSPARouter()) {
444
+ window.dispatchEvent(new PopStateEvent("popstate"));
445
+ return;
446
+ }
447
+ window.dispatchEvent(
448
+ new CustomEvent(FARM_HISTORY_CHANGE_EVENT, {
449
+ detail: { kind }
450
+ })
451
+ );
452
+ }, 0);
453
+ }
454
+ __name(notifyHistoryChange, "notifyHistoryChange");
455
+ function subscribeHistoryChange(listener) {
456
+ if (typeof window === "undefined") return () => {
457
+ };
458
+ window.addEventListener("popstate", listener);
459
+ window.addEventListener(FARM_HISTORY_CHANGE_EVENT, listener);
460
+ return () => {
461
+ window.removeEventListener("popstate", listener);
462
+ window.removeEventListener(FARM_HISTORY_CHANGE_EVENT, listener);
463
+ };
464
+ }
465
+ __name(subscribeHistoryChange, "subscribeHistoryChange");
466
+
438
467
  // src/deployment.ts
439
468
  var FARM_DEPLOYMENT_ID_HEADER = "x-farm-deployment-id";
440
469
  var FARM_DEPLOYMENT_MISMATCH_HEADER = "x-farm-deployment-mismatch";
@@ -616,6 +645,16 @@ var _SPARouter = class _SPARouter {
616
645
  this.navigationListeners = /* @__PURE__ */ new Set();
617
646
  this.navigationState = IDLE_NAVIGATION_STATE;
618
647
  this.scrollElements = /* @__PURE__ */ new Map();
648
+ this.onPopState = /* @__PURE__ */ __name((event) => {
649
+ void this.handlePopState(event);
650
+ }, "onPopState");
651
+ this.onBeforeUnload = /* @__PURE__ */ __name((event) => {
652
+ if (this.blockers.size > 0) {
653
+ event.preventDefault();
654
+ event.returnValue = "";
655
+ }
656
+ this.saveScrollPosition(window.location.pathname);
657
+ }, "onBeforeUnload");
619
658
  this.options = {
620
659
  prefetchTimeout: options.prefetchTimeout ?? 100,
621
660
  cacheMaxAge: options.cacheMaxAge ?? 3e4,
@@ -625,16 +664,16 @@ var _SPARouter = class _SPARouter {
625
664
  deploymentId: options.deploymentId ?? readBrowserDeploymentId()
626
665
  };
627
666
  if (typeof window !== "undefined") {
628
- window.addEventListener("popstate", this.handlePopState.bind(this));
629
- window.addEventListener("beforeunload", (event) => {
630
- if (this.blockers.size > 0) {
631
- event.preventDefault();
632
- event.returnValue = "";
633
- }
634
- this.saveScrollPosition(window.location.pathname);
635
- });
667
+ window.addEventListener("popstate", this.onPopState);
668
+ window.addEventListener("beforeunload", this.onBeforeUnload);
636
669
  }
637
670
  }
671
+ /** Remove global listeners. Intended for tests and teardown. */
672
+ destroy() {
673
+ if (typeof window === "undefined") return;
674
+ window.removeEventListener("popstate", this.onPopState);
675
+ window.removeEventListener("beforeunload", this.onBeforeUnload);
676
+ }
638
677
  /**
639
678
  * Set the navigation handler that updates React
640
679
  */
@@ -1028,7 +1067,7 @@ var _SPARouter = class _SPARouter {
1028
1067
  } else {
1029
1068
  window.history.pushState(nextState, "", url);
1030
1069
  }
1031
- window.dispatchEvent(new PopStateEvent("popstate", { state: nextState }));
1070
+ notifyHistoryChange("page-state");
1032
1071
  }
1033
1072
  /**
1034
1073
  * Save scroll position for a path
@@ -1097,11 +1136,16 @@ function dispatchDeploymentMismatch(error) {
1097
1136
  window.dispatchEvent(new CustomEvent("farm:deployment-mismatch", { detail: error }));
1098
1137
  }
1099
1138
  __name(dispatchDeploymentMismatch, "dispatchDeploymentMismatch");
1139
+ function getInstalledFarmSPARouter() {
1140
+ if (typeof window === "undefined") return void 0;
1141
+ return window.__FARM_SPA_ROUTER__;
1142
+ }
1143
+ __name(getInstalledFarmSPARouter, "getInstalledFarmSPARouter");
1100
1144
  function getRouter() {
1101
1145
  if (typeof window === "undefined") {
1102
1146
  return new SPARouter();
1103
1147
  }
1104
- const installedRouter = window.__FARM_SPA_ROUTER__;
1148
+ const installedRouter = getInstalledFarmSPARouter();
1105
1149
  if (installedRouter) {
1106
1150
  routerInstance = installedRouter;
1107
1151
  return installedRouter;
@@ -1154,6 +1198,22 @@ function getScrollElementStorageKey(path, key) {
1154
1198
  __name(getScrollElementStorageKey, "getScrollElementStorageKey");
1155
1199
 
1156
1200
  // src/client/router.ts
1201
+ function navigateViaRouter(href, basePath, replace) {
1202
+ if (typeof window === "undefined") return;
1203
+ const url = href.startsWith("/") ? basePath + href : href;
1204
+ const spaRouter = getInstalledFarmSPARouter();
1205
+ if (spaRouter) {
1206
+ void spaRouter.navigate(url, { replace });
1207
+ return;
1208
+ }
1209
+ if (replace) {
1210
+ window.history.replaceState(null, "", url);
1211
+ } else {
1212
+ window.history.pushState(null, "", url);
1213
+ }
1214
+ notifyHistoryChange("url-search");
1215
+ }
1216
+ __name(navigateViaRouter, "navigateViaRouter");
1157
1217
  function useRouter(options = {}) {
1158
1218
  const basePath = options.basePath || "";
1159
1219
  const routes = options.routes;
@@ -1171,20 +1231,14 @@ function useRouter(options = {}) {
1171
1231
  setState(readRouterState(basePath, routeMatcher));
1172
1232
  }, "handlePopState");
1173
1233
  handlePopState();
1174
- window.addEventListener("popstate", handlePopState);
1175
- return () => window.removeEventListener("popstate", handlePopState);
1234
+ const unsubscribe = subscribeHistoryChange(handlePopState);
1235
+ return unsubscribe;
1176
1236
  }, [basePath, routeMatcher]);
1177
1237
  const push = /* @__PURE__ */ __name((href) => {
1178
- if (typeof window === "undefined") return;
1179
- const url = href.startsWith("/") ? basePath + href : href;
1180
- window.history.pushState(null, "", url);
1181
- window.dispatchEvent(new PopStateEvent("popstate"));
1238
+ navigateViaRouter(href, basePath, false);
1182
1239
  }, "push");
1183
1240
  const replace = /* @__PURE__ */ __name((href) => {
1184
- if (typeof window === "undefined") return;
1185
- const url = href.startsWith("/") ? basePath + href : href;
1186
- window.history.replaceState(null, "", url);
1187
- window.dispatchEvent(new PopStateEvent("popstate"));
1241
+ navigateViaRouter(href, basePath, true);
1188
1242
  }, "replace");
1189
1243
  const pushState = /* @__PURE__ */ __name((pageState, href) => {
1190
1244
  if (typeof window === "undefined") return;