@farm.js/core 0.1.0-beta.55 → 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 (59) hide show
  1. package/dist/{chunk-YBHLSG7E.mjs → chunk-5T2XATMK.mjs} +22 -18
  2. package/dist/chunk-5T2XATMK.mjs.map +1 -0
  3. package/dist/{chunk-MSQDIAQW.mjs → chunk-FOEPWRHM.mjs} +2 -2
  4. package/dist/{chunk-ZP5IWDTE.mjs → chunk-FPLRESQA.mjs} +25 -14
  5. package/dist/chunk-FPLRESQA.mjs.map +1 -0
  6. package/dist/{chunk-OGFWHBDO.mjs → chunk-UH5R4J5M.mjs} +2 -2
  7. package/dist/{chunk-BLTATPSB.mjs → chunk-XLQVJDK2.mjs} +2 -2
  8. package/dist/{chunk-BLTATPSB.mjs.map → chunk-XLQVJDK2.mjs.map} +1 -1
  9. package/dist/{chunk-RAZ7L3UY.mjs → chunk-YPKCFGA7.mjs} +9 -3
  10. package/dist/chunk-YPKCFGA7.mjs.map +1 -0
  11. package/dist/{chunk-2ISN27CV.mjs → chunk-ZOQLQAUG.mjs} +2 -2
  12. package/dist/client/lifecycle.mjs +2 -2
  13. package/dist/client-plugins.cjs +1 -1
  14. package/dist/client-plugins.cjs.map +1 -1
  15. package/dist/client-plugins.mjs +2 -2
  16. package/dist/client.cjs +51 -27
  17. package/dist/client.cjs.map +1 -1
  18. package/dist/client.d.mts +0 -3
  19. package/dist/client.d.ts +0 -3
  20. package/dist/client.mjs +4 -4
  21. package/dist/index.cjs +60 -28
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.mjs +7 -7
  24. package/dist/internal/build-runtime.cjs +8 -2
  25. package/dist/internal/build-runtime.cjs.map +1 -1
  26. package/dist/internal/build-runtime.mjs +3 -3
  27. package/dist/internal/client-runtime.cjs +1 -1
  28. package/dist/internal/client-runtime.cjs.map +1 -1
  29. package/dist/internal/client-runtime.mjs +2 -2
  30. package/dist/navigation.cjs +49 -24
  31. package/dist/navigation.cjs.map +1 -1
  32. package/dist/navigation.mjs +3 -3
  33. package/dist/plugin.cjs +1 -1
  34. package/dist/plugin.cjs.map +1 -1
  35. package/dist/plugin.mjs +2 -2
  36. package/dist/query/client.cjs +28 -13
  37. package/dist/query/client.cjs.map +1 -1
  38. package/dist/query/client.mjs +8 -7
  39. package/dist/query/client.mjs.map +1 -1
  40. package/dist/renderer-client.cjs +32 -8
  41. package/dist/renderer-client.cjs.map +1 -1
  42. package/dist/renderer-client.mjs +5 -7
  43. package/dist/renderer-client.mjs.map +1 -1
  44. package/dist/server.cjs +1 -1
  45. package/dist/server.cjs.map +1 -1
  46. package/dist/server.mjs +2 -2
  47. package/dist/version.cjs +1 -1
  48. package/dist/version.cjs.map +1 -1
  49. package/dist/version.mjs +1 -1
  50. package/dist/vite.cjs +1 -1
  51. package/dist/vite.cjs.map +1 -1
  52. package/dist/vite.mjs +2 -2
  53. package/package.json +1 -1
  54. package/dist/chunk-RAZ7L3UY.mjs.map +0 -1
  55. package/dist/chunk-YBHLSG7E.mjs.map +0 -1
  56. package/dist/chunk-ZP5IWDTE.mjs.map +0 -1
  57. /package/dist/{chunk-MSQDIAQW.mjs.map → chunk-FOEPWRHM.mjs.map} +0 -0
  58. /package/dist/{chunk-OGFWHBDO.mjs.map → chunk-UH5R4J5M.mjs.map} +0 -0
  59. /package/dist/{chunk-2ISN27CV.mjs.map → chunk-ZOQLQAUG.mjs.map} +0 -0
package/dist/client.d.mts CHANGED
@@ -286,9 +286,6 @@ interface UseBlockerOptions {
286
286
  interface UseBlockerReturn {
287
287
  active: boolean;
288
288
  }
289
- /**
290
- * Hook for accessing router state and navigation
291
- */
292
289
  declare function useRouter(options?: UseRouterOptions): {
293
290
  push: (href: string) => void;
294
291
  replace: (href: string) => void;
package/dist/client.d.ts CHANGED
@@ -286,9 +286,6 @@ interface UseBlockerOptions {
286
286
  interface UseBlockerReturn {
287
287
  active: boolean;
288
288
  }
289
- /**
290
- * Hook for accessing router state and navigation
291
- */
292
289
  declare function useRouter(options?: UseRouterOptions): {
293
290
  push: (href: string) => void;
294
291
  replace: (href: string) => void;
package/dist/client.mjs CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  usePageState,
17
17
  useRouter,
18
18
  useScrollRestoration
19
- } from "./chunk-ZP5IWDTE.mjs";
19
+ } from "./chunk-FPLRESQA.mjs";
20
20
  import {
21
21
  useTheme
22
22
  } from "./chunk-CHITERV2.mjs";
@@ -53,7 +53,7 @@ import {
53
53
  pushState,
54
54
  readPageState,
55
55
  replaceState
56
- } from "./chunk-YBHLSG7E.mjs";
56
+ } from "./chunk-5T2XATMK.mjs";
57
57
  import "./chunk-ITN462YM.mjs";
58
58
  import "./chunk-C4XSKA7P.mjs";
59
59
  import "./chunk-SCFX4UTD.mjs";
@@ -62,7 +62,7 @@ import {
62
62
  createClientPluginManager,
63
63
  installChunkErrorRecovery,
64
64
  isChunkLoadError
65
- } from "./chunk-MSQDIAQW.mjs";
65
+ } from "./chunk-FOEPWRHM.mjs";
66
66
  import "./chunk-GQVQESLY.mjs";
67
67
  import {
68
68
  api,
@@ -80,7 +80,7 @@ import "./chunk-RBRLLZL5.mjs";
80
80
  import "./chunk-WZ5QFROO.mjs";
81
81
  import "./chunk-7ZMKVETU.mjs";
82
82
  import "./chunk-FXG2PS27.mjs";
83
- import "./chunk-BLTATPSB.mjs";
83
+ import "./chunk-XLQVJDK2.mjs";
84
84
  import "./chunk-CGILA3WO.mjs";
85
85
  export {
86
86
  APIClientError,
package/dist/index.cjs CHANGED
@@ -15255,7 +15255,7 @@ var init_server3 = __esm({
15255
15255
  var version;
15256
15256
  var init_package = __esm({
15257
15257
  "package.json"() {
15258
- version = "0.1.0-beta.55";
15258
+ version = "0.1.0-beta.56";
15259
15259
  }
15260
15260
  });
15261
15261
 
@@ -40879,7 +40879,13 @@ function generateUniversalRouterStateProperties() {
40879
40879
  } else {
40880
40880
  window.history.pushState(nextState, "", url);
40881
40881
  }
40882
- window.dispatchEvent(new PopStateEvent("popstate", { state: nextState }));
40882
+ // Announce on the dedicated history channel; a synthetic popstate would
40883
+ // be treated as back/forward by the popstate listener below and trigger
40884
+ // a full navigation for a shallow page-state write. The bundled client
40885
+ // hooks subscribe to this event via subscribeHistoryChange.
40886
+ window.dispatchEvent(
40887
+ new CustomEvent("farm:historychange", { detail: { kind: "page-state" } }),
40888
+ );
40883
40889
  },
40884
40890
 
40885
40891
  registerScrollElement: function(key, element) {
@@ -47904,6 +47910,37 @@ var import_react11 = require("react");
47904
47910
 
47905
47911
  // src/client/spa-router.ts
47906
47912
  init_deferred();
47913
+
47914
+ // src/client/history-sync.ts
47915
+ var FARM_HISTORY_CHANGE_EVENT = "farm:historychange";
47916
+ function notifyHistoryChange(kind) {
47917
+ if (typeof window === "undefined") return;
47918
+ setTimeout(() => {
47919
+ if (kind === "url-search" && !getInstalledFarmSPARouter()) {
47920
+ window.dispatchEvent(new PopStateEvent("popstate"));
47921
+ return;
47922
+ }
47923
+ window.dispatchEvent(
47924
+ new CustomEvent(FARM_HISTORY_CHANGE_EVENT, {
47925
+ detail: { kind }
47926
+ })
47927
+ );
47928
+ }, 0);
47929
+ }
47930
+ __name(notifyHistoryChange, "notifyHistoryChange");
47931
+ function subscribeHistoryChange(listener) {
47932
+ if (typeof window === "undefined") return () => {
47933
+ };
47934
+ window.addEventListener("popstate", listener);
47935
+ window.addEventListener(FARM_HISTORY_CHANGE_EVENT, listener);
47936
+ return () => {
47937
+ window.removeEventListener("popstate", listener);
47938
+ window.removeEventListener(FARM_HISTORY_CHANGE_EVENT, listener);
47939
+ };
47940
+ }
47941
+ __name(subscribeHistoryChange, "subscribeHistoryChange");
47942
+
47943
+ // src/client/spa-router.ts
47907
47944
  init_deployment();
47908
47945
  var FARM_PAGE_STATE_KEY = "__farmPageState";
47909
47946
  var FARM_INTERCEPT_FROM_KEY = "__farmInterceptFrom";
@@ -48355,7 +48392,7 @@ var _SPARouter = class _SPARouter {
48355
48392
  } else {
48356
48393
  window.history.pushState(nextState, "", url);
48357
48394
  }
48358
- window.dispatchEvent(new PopStateEvent("popstate", { state: nextState }));
48395
+ notifyHistoryChange("page-state");
48359
48396
  }
48360
48397
  /**
48361
48398
  * Save scroll position for a path
@@ -48501,22 +48538,24 @@ function getScrollElementStorageKey(path38, key) {
48501
48538
  }
48502
48539
  __name(getScrollElementStorageKey, "getScrollElementStorageKey");
48503
48540
 
48504
- // src/client/url-search-sync.ts
48505
- var FARM_URL_SEARCH_CHANGE_EVENT = "farm:urlsearchchange";
48506
- function subscribeUrlSearchObservers(listener) {
48507
- if (typeof window === "undefined") return () => {
48508
- };
48509
- window.addEventListener("popstate", listener);
48510
- window.addEventListener(FARM_URL_SEARCH_CHANGE_EVENT, listener);
48511
- return () => {
48512
- window.removeEventListener("popstate", listener);
48513
- window.removeEventListener(FARM_URL_SEARCH_CHANGE_EVENT, listener);
48514
- };
48515
- }
48516
- __name(subscribeUrlSearchObservers, "subscribeUrlSearchObservers");
48517
-
48518
48541
  // src/client/router.ts
48519
48542
  init_routing();
48543
+ function navigateViaRouter(href, basePath, replace) {
48544
+ if (typeof window === "undefined") return;
48545
+ const url = href.startsWith("/") ? basePath + href : href;
48546
+ const spaRouter = getInstalledFarmSPARouter();
48547
+ if (spaRouter) {
48548
+ void spaRouter.navigate(url, { replace });
48549
+ return;
48550
+ }
48551
+ if (replace) {
48552
+ window.history.replaceState(null, "", url);
48553
+ } else {
48554
+ window.history.pushState(null, "", url);
48555
+ }
48556
+ notifyHistoryChange("url-search");
48557
+ }
48558
+ __name(navigateViaRouter, "navigateViaRouter");
48520
48559
  function useRouter(options = {}) {
48521
48560
  const basePath = options.basePath || "";
48522
48561
  const routes = options.routes;
@@ -48534,20 +48573,14 @@ function useRouter(options = {}) {
48534
48573
  setState(readRouterState(basePath, routeMatcher));
48535
48574
  }, "handlePopState");
48536
48575
  handlePopState();
48537
- const unsubscribe = subscribeUrlSearchObservers(handlePopState);
48576
+ const unsubscribe = subscribeHistoryChange(handlePopState);
48538
48577
  return unsubscribe;
48539
48578
  }, [basePath, routeMatcher]);
48540
48579
  const push = /* @__PURE__ */ __name((href) => {
48541
- if (typeof window === "undefined") return;
48542
- const url = href.startsWith("/") ? basePath + href : href;
48543
- window.history.pushState(null, "", url);
48544
- window.dispatchEvent(new PopStateEvent("popstate"));
48580
+ navigateViaRouter(href, basePath, false);
48545
48581
  }, "push");
48546
48582
  const replace = /* @__PURE__ */ __name((href) => {
48547
- if (typeof window === "undefined") return;
48548
- const url = href.startsWith("/") ? basePath + href : href;
48549
- window.history.replaceState(null, "", url);
48550
- window.dispatchEvent(new PopStateEvent("popstate"));
48583
+ navigateViaRouter(href, basePath, true);
48551
48584
  }, "replace");
48552
48585
  const pushState2 = /* @__PURE__ */ __name((pageState, href) => {
48553
48586
  if (typeof window === "undefined") return;
@@ -48586,8 +48619,7 @@ function usePageState() {
48586
48619
  setState(readPageState());
48587
48620
  }, "handlePopState");
48588
48621
  handlePopState();
48589
- window.addEventListener("popstate", handlePopState);
48590
- return () => window.removeEventListener("popstate", handlePopState);
48622
+ return subscribeHistoryChange(handlePopState);
48591
48623
  }, []);
48592
48624
  return state;
48593
48625
  }