@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,9 +1,9 @@
1
1
  import {
2
2
  FarmClientPluginManager,
3
3
  createClientPluginManager
4
- } from "./chunk-J34JCW6R.mjs";
4
+ } from "./chunk-FOEPWRHM.mjs";
5
5
  import "./chunk-FXG2PS27.mjs";
6
- import "./chunk-ENPB4CSY.mjs";
6
+ import "./chunk-XLQVJDK2.mjs";
7
7
  import "./chunk-CGILA3WO.mjs";
8
8
  export {
9
9
  FarmClientPluginManager,
package/dist/client.cjs CHANGED
@@ -4664,6 +4664,35 @@ function rejectPendingDeferred(controllers, message) {
4664
4664
  }
4665
4665
  __name(rejectPendingDeferred, "rejectPendingDeferred");
4666
4666
 
4667
+ // src/client/history-sync.ts
4668
+ var FARM_HISTORY_CHANGE_EVENT = "farm:historychange";
4669
+ function notifyHistoryChange(kind) {
4670
+ if (typeof window === "undefined") return;
4671
+ setTimeout(() => {
4672
+ if (kind === "url-search" && !getInstalledFarmSPARouter()) {
4673
+ window.dispatchEvent(new PopStateEvent("popstate"));
4674
+ return;
4675
+ }
4676
+ window.dispatchEvent(
4677
+ new CustomEvent(FARM_HISTORY_CHANGE_EVENT, {
4678
+ detail: { kind }
4679
+ })
4680
+ );
4681
+ }, 0);
4682
+ }
4683
+ __name(notifyHistoryChange, "notifyHistoryChange");
4684
+ function subscribeHistoryChange(listener) {
4685
+ if (typeof window === "undefined") return () => {
4686
+ };
4687
+ window.addEventListener("popstate", listener);
4688
+ window.addEventListener(FARM_HISTORY_CHANGE_EVENT, listener);
4689
+ return () => {
4690
+ window.removeEventListener("popstate", listener);
4691
+ window.removeEventListener(FARM_HISTORY_CHANGE_EVENT, listener);
4692
+ };
4693
+ }
4694
+ __name(subscribeHistoryChange, "subscribeHistoryChange");
4695
+
4667
4696
  // src/deployment.ts
4668
4697
  var FARM_DEPLOYMENT_ID_HEADER = "x-farm-deployment-id";
4669
4698
  var FARM_DEPLOYMENT_MISMATCH_HEADER = "x-farm-deployment-mismatch";
@@ -4738,6 +4767,16 @@ var _SPARouter = class _SPARouter {
4738
4767
  this.navigationListeners = /* @__PURE__ */ new Set();
4739
4768
  this.navigationState = IDLE_NAVIGATION_STATE;
4740
4769
  this.scrollElements = /* @__PURE__ */ new Map();
4770
+ this.onPopState = /* @__PURE__ */ __name((event) => {
4771
+ void this.handlePopState(event);
4772
+ }, "onPopState");
4773
+ this.onBeforeUnload = /* @__PURE__ */ __name((event) => {
4774
+ if (this.blockers.size > 0) {
4775
+ event.preventDefault();
4776
+ event.returnValue = "";
4777
+ }
4778
+ this.saveScrollPosition(window.location.pathname);
4779
+ }, "onBeforeUnload");
4741
4780
  this.options = {
4742
4781
  prefetchTimeout: options.prefetchTimeout ?? 100,
4743
4782
  cacheMaxAge: options.cacheMaxAge ?? 3e4,
@@ -4747,16 +4786,16 @@ var _SPARouter = class _SPARouter {
4747
4786
  deploymentId: options.deploymentId ?? readBrowserDeploymentId()
4748
4787
  };
4749
4788
  if (typeof window !== "undefined") {
4750
- window.addEventListener("popstate", this.handlePopState.bind(this));
4751
- window.addEventListener("beforeunload", (event) => {
4752
- if (this.blockers.size > 0) {
4753
- event.preventDefault();
4754
- event.returnValue = "";
4755
- }
4756
- this.saveScrollPosition(window.location.pathname);
4757
- });
4789
+ window.addEventListener("popstate", this.onPopState);
4790
+ window.addEventListener("beforeunload", this.onBeforeUnload);
4758
4791
  }
4759
4792
  }
4793
+ /** Remove global listeners. Intended for tests and teardown. */
4794
+ destroy() {
4795
+ if (typeof window === "undefined") return;
4796
+ window.removeEventListener("popstate", this.onPopState);
4797
+ window.removeEventListener("beforeunload", this.onBeforeUnload);
4798
+ }
4760
4799
  /**
4761
4800
  * Set the navigation handler that updates React
4762
4801
  */
@@ -5150,7 +5189,7 @@ var _SPARouter = class _SPARouter {
5150
5189
  } else {
5151
5190
  window.history.pushState(nextState, "", url);
5152
5191
  }
5153
- window.dispatchEvent(new PopStateEvent("popstate", { state: nextState }));
5192
+ notifyHistoryChange("page-state");
5154
5193
  }
5155
5194
  /**
5156
5195
  * Save scroll position for a path
@@ -5219,11 +5258,16 @@ function dispatchDeploymentMismatch(error) {
5219
5258
  window.dispatchEvent(new CustomEvent("farm:deployment-mismatch", { detail: error }));
5220
5259
  }
5221
5260
  __name(dispatchDeploymentMismatch, "dispatchDeploymentMismatch");
5261
+ function getInstalledFarmSPARouter() {
5262
+ if (typeof window === "undefined") return void 0;
5263
+ return window.__FARM_SPA_ROUTER__;
5264
+ }
5265
+ __name(getInstalledFarmSPARouter, "getInstalledFarmSPARouter");
5222
5266
  function getRouter2() {
5223
5267
  if (typeof window === "undefined") {
5224
5268
  return new SPARouter();
5225
5269
  }
5226
- const installedRouter = window.__FARM_SPA_ROUTER__;
5270
+ const installedRouter = getInstalledFarmSPARouter();
5227
5271
  if (installedRouter) {
5228
5272
  routerInstance = installedRouter;
5229
5273
  return installedRouter;
@@ -5292,6 +5336,22 @@ function getScrollElementStorageKey(path, key) {
5292
5336
  __name(getScrollElementStorageKey, "getScrollElementStorageKey");
5293
5337
 
5294
5338
  // src/client/router.ts
5339
+ function navigateViaRouter(href, basePath, replace) {
5340
+ if (typeof window === "undefined") return;
5341
+ const url = href.startsWith("/") ? basePath + href : href;
5342
+ const spaRouter = getInstalledFarmSPARouter();
5343
+ if (spaRouter) {
5344
+ void spaRouter.navigate(url, { replace });
5345
+ return;
5346
+ }
5347
+ if (replace) {
5348
+ window.history.replaceState(null, "", url);
5349
+ } else {
5350
+ window.history.pushState(null, "", url);
5351
+ }
5352
+ notifyHistoryChange("url-search");
5353
+ }
5354
+ __name(navigateViaRouter, "navigateViaRouter");
5295
5355
  function useRouter(options = {}) {
5296
5356
  const basePath = options.basePath || "";
5297
5357
  const routes = options.routes;
@@ -5309,20 +5369,14 @@ function useRouter(options = {}) {
5309
5369
  setState(readRouterState(basePath, routeMatcher));
5310
5370
  }, "handlePopState");
5311
5371
  handlePopState();
5312
- window.addEventListener("popstate", handlePopState);
5313
- return () => window.removeEventListener("popstate", handlePopState);
5372
+ const unsubscribe = subscribeHistoryChange(handlePopState);
5373
+ return unsubscribe;
5314
5374
  }, [basePath, routeMatcher]);
5315
5375
  const push = /* @__PURE__ */ __name((href) => {
5316
- if (typeof window === "undefined") return;
5317
- const url = href.startsWith("/") ? basePath + href : href;
5318
- window.history.pushState(null, "", url);
5319
- window.dispatchEvent(new PopStateEvent("popstate"));
5376
+ navigateViaRouter(href, basePath, false);
5320
5377
  }, "push");
5321
5378
  const replace = /* @__PURE__ */ __name((href) => {
5322
- if (typeof window === "undefined") return;
5323
- const url = href.startsWith("/") ? basePath + href : href;
5324
- window.history.replaceState(null, "", url);
5325
- window.dispatchEvent(new PopStateEvent("popstate"));
5379
+ navigateViaRouter(href, basePath, true);
5326
5380
  }, "replace");
5327
5381
  const pushState2 = /* @__PURE__ */ __name((pageState, href) => {
5328
5382
  if (typeof window === "undefined") return;
@@ -5361,8 +5415,7 @@ function usePageState() {
5361
5415
  setState(readPageState());
5362
5416
  }, "handlePopState");
5363
5417
  handlePopState();
5364
- window.addEventListener("popstate", handlePopState);
5365
- return () => window.removeEventListener("popstate", handlePopState);
5418
+ return subscribeHistoryChange(handlePopState);
5366
5419
  }, []);
5367
5420
  return state;
5368
5421
  }
@@ -6049,7 +6102,7 @@ body {
6049
6102
  `;
6050
6103
 
6051
6104
  // package.json
6052
- var version = "0.1.0-beta.54";
6105
+ var version = "0.1.0-beta.56";
6053
6106
 
6054
6107
  // src/version.ts
6055
6108
  var FARM_VERSION = version;