@farm.js/core 0.1.0-beta.80 → 0.1.0-beta.81

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 (113) hide show
  1. package/dist/agent-runtime.d.mts +1 -1
  2. package/dist/agent-runtime.d.ts +1 -1
  3. package/dist/{app-D1fYgNSZ.d.mts → app-B9tbSdKW.d.mts} +3 -3
  4. package/dist/{app-DKW_R78N.d.ts → app-C7twWiJY.d.ts} +3 -3
  5. package/dist/app-markdown.d.mts +2 -2
  6. package/dist/app-markdown.d.ts +2 -2
  7. package/dist/{chunk-OEI62POE.mjs → chunk-6NV2RJSZ.mjs} +2 -2
  8. package/dist/{chunk-OEI62POE.mjs.map → chunk-6NV2RJSZ.mjs.map} +1 -1
  9. package/dist/{chunk-DNPQOJQW.mjs → chunk-CRK3RQ7C.mjs} +3 -3
  10. package/dist/{chunk-DBG42367.mjs → chunk-CVCIL6KH.mjs} +37 -14
  11. package/dist/chunk-CVCIL6KH.mjs.map +1 -0
  12. package/dist/{chunk-3UGGCJT5.mjs → chunk-HSCQGINR.mjs} +2 -2
  13. package/dist/{chunk-YSX4KDLV.mjs → chunk-VPEC2CWG.mjs} +42 -8
  14. package/dist/chunk-VPEC2CWG.mjs.map +1 -0
  15. package/dist/{chunk-3HIATXA4.mjs → chunk-XSUYR4Q3.mjs} +67 -25
  16. package/dist/chunk-XSUYR4Q3.mjs.map +1 -0
  17. package/dist/{chunk-3S7V7QHJ.mjs → chunk-Z73XASLT.mjs} +46 -19
  18. package/dist/chunk-Z73XASLT.mjs.map +1 -0
  19. package/dist/client/lifecycle.mjs +2 -2
  20. package/dist/{client-plugins-BtfLE4dW.d.mts → client-plugins-HizW0gLc.d.mts} +13 -1
  21. package/dist/{client-plugins-C4me5UPd.d.ts → client-plugins-w_b1wA8e.d.ts} +13 -1
  22. package/dist/client-plugins.cjs +1 -1
  23. package/dist/client-plugins.cjs.map +1 -1
  24. package/dist/client-plugins.d.mts +1 -1
  25. package/dist/client-plugins.d.ts +1 -1
  26. package/dist/client-plugins.mjs +2 -2
  27. package/dist/client.cjs +102 -37
  28. package/dist/client.cjs.map +1 -1
  29. package/dist/client.d.mts +4 -4
  30. package/dist/client.d.ts +4 -4
  31. package/dist/client.mjs +4 -4
  32. package/dist/config.d.mts +1 -1
  33. package/dist/config.d.ts +1 -1
  34. package/dist/index.cjs +186 -60
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.mts +9 -9
  37. package/dist/index.d.ts +9 -9
  38. package/dist/index.mjs +7 -7
  39. package/dist/integrations.d.mts +1 -1
  40. package/dist/integrations.d.ts +1 -1
  41. package/dist/internal/build-runtime.cjs +85 -24
  42. package/dist/internal/build-runtime.cjs.map +1 -1
  43. package/dist/internal/build-runtime.d.mts +3 -3
  44. package/dist/internal/build-runtime.d.ts +3 -3
  45. package/dist/internal/build-runtime.mjs +3 -3
  46. package/dist/internal/client-runtime.cjs +1 -1
  47. package/dist/internal/client-runtime.cjs.map +1 -1
  48. package/dist/internal/client-runtime.mjs +2 -2
  49. package/dist/internal/config-runtime.d.mts +2 -2
  50. package/dist/internal/config-runtime.d.ts +2 -2
  51. package/dist/internal/product-telemetry-runtime.cjs +1 -1
  52. package/dist/internal/product-telemetry-runtime.cjs.map +1 -1
  53. package/dist/internal/product-telemetry-runtime.mjs +1 -1
  54. package/dist/internal/production-runtime.d.mts +5 -5
  55. package/dist/internal/production-runtime.d.ts +5 -5
  56. package/dist/{metadata-route-Bf4aVrYO.d.mts → metadata-route-CjF_sf9F.d.mts} +1 -1
  57. package/dist/{metadata-route-CUPYRgfT.d.ts → metadata-route-DkyJlQFD.d.ts} +1 -1
  58. package/dist/middleware.d.mts +3 -3
  59. package/dist/middleware.d.ts +3 -3
  60. package/dist/navigation.cjs +66 -24
  61. package/dist/navigation.cjs.map +1 -1
  62. package/dist/navigation.mjs +3 -3
  63. package/dist/plugin.cjs +40 -7
  64. package/dist/plugin.cjs.map +1 -1
  65. package/dist/plugin.d.mts +1 -1
  66. package/dist/plugin.d.ts +1 -1
  67. package/dist/plugin.mjs +2 -2
  68. package/dist/{production-runtime-D5ECiSmc.d.mts → production-runtime-CDSs0Rwo.d.mts} +1 -1
  69. package/dist/{production-runtime-Cb29k5Oi.d.ts → production-runtime-CSPVu_3h.d.ts} +1 -1
  70. package/dist/query/client.cjs +9 -5
  71. package/dist/query/client.cjs.map +1 -1
  72. package/dist/query/client.mjs +1 -1
  73. package/dist/{render-plan-DZ0LA8wX.d.ts → render-plan-C62oFdVD.d.ts} +1 -1
  74. package/dist/{render-plan-HL0ChBbH.d.mts → render-plan-D3TuPEmY.d.mts} +1 -1
  75. package/dist/renderer-client.cjs +66 -24
  76. package/dist/renderer-client.cjs.map +1 -1
  77. package/dist/renderer-client.d.mts +3 -3
  78. package/dist/renderer-client.d.ts +3 -3
  79. package/dist/renderer-client.mjs +1 -1
  80. package/dist/{request-8__ppqcz.d.ts → request-C-ZYE89s.d.ts} +1 -1
  81. package/dist/{request-DAZMscB9.d.mts → request-DPMdCOtv.d.mts} +1 -1
  82. package/dist/request.d.mts +2 -2
  83. package/dist/request.d.ts +2 -2
  84. package/dist/routes.d.mts +1 -1
  85. package/dist/routes.d.ts +1 -1
  86. package/dist/server-plugins.d.mts +2 -2
  87. package/dist/server-plugins.d.ts +2 -2
  88. package/dist/server.cjs +40 -7
  89. package/dist/server.cjs.map +1 -1
  90. package/dist/server.d.mts +7 -7
  91. package/dist/server.d.ts +7 -7
  92. package/dist/server.mjs +2 -2
  93. package/dist/{spa-router-DMKCWHT5.d.ts → spa-router-C7RwU8o-.d.ts} +6 -2
  94. package/dist/{spa-router-BM-OHflh.d.mts → spa-router-Cr39oWnX.d.mts} +6 -2
  95. package/dist/testing.d.mts +1 -1
  96. package/dist/testing.d.ts +1 -1
  97. package/dist/{utils-B8t0bZ5X.d.ts → utils-B6Jk-ITz.d.ts} +1 -1
  98. package/dist/{utils-B7dij0CU.d.mts → utils-U4zuTiDB.d.mts} +1 -1
  99. package/dist/version.cjs +1 -1
  100. package/dist/version.cjs.map +1 -1
  101. package/dist/version.mjs +1 -1
  102. package/dist/vite.cjs +42 -7
  103. package/dist/vite.cjs.map +1 -1
  104. package/dist/vite.d.mts +1 -1
  105. package/dist/vite.d.ts +1 -1
  106. package/dist/vite.mjs +4 -2
  107. package/package.json +1 -1
  108. package/dist/chunk-3HIATXA4.mjs.map +0 -1
  109. package/dist/chunk-3S7V7QHJ.mjs.map +0 -1
  110. package/dist/chunk-DBG42367.mjs.map +0 -1
  111. package/dist/chunk-YSX4KDLV.mjs.map +0 -1
  112. /package/dist/{chunk-DNPQOJQW.mjs.map → chunk-CRK3RQ7C.mjs.map} +0 -0
  113. /package/dist/{chunk-3UGGCJT5.mjs.map → chunk-HSCQGINR.mjs.map} +0 -0
@@ -504,6 +504,14 @@ __name(rejectPendingDeferred, "rejectPendingDeferred");
504
504
 
505
505
  // src/client/history-sync.ts
506
506
  var FARM_HISTORY_CHANGE_EVENT = "farm:historychange";
507
+ function dispatchHistoryChange(kind) {
508
+ window.dispatchEvent(
509
+ new CustomEvent(FARM_HISTORY_CHANGE_EVENT, {
510
+ detail: { kind }
511
+ })
512
+ );
513
+ }
514
+ __name(dispatchHistoryChange, "dispatchHistoryChange");
507
515
  function notifyHistoryChange(kind) {
508
516
  if (typeof window === "undefined") return;
509
517
  setTimeout(() => {
@@ -511,14 +519,15 @@ function notifyHistoryChange(kind) {
511
519
  window.dispatchEvent(new PopStateEvent("popstate"));
512
520
  return;
513
521
  }
514
- window.dispatchEvent(
515
- new CustomEvent(FARM_HISTORY_CHANGE_EVENT, {
516
- detail: { kind }
517
- })
518
- );
522
+ dispatchHistoryChange(kind);
519
523
  }, 0);
520
524
  }
521
525
  __name(notifyHistoryChange, "notifyHistoryChange");
526
+ function notifyRouterHistoryChange() {
527
+ if (typeof window === "undefined") return;
528
+ setTimeout(() => dispatchHistoryChange("url-search"), 0);
529
+ }
530
+ __name(notifyRouterHistoryChange, "notifyRouterHistoryChange");
522
531
  function subscribeHistoryChange(listener) {
523
532
  if (typeof window === "undefined") return () => {
524
533
  };
@@ -760,6 +769,7 @@ var _SPARouter = class _SPARouter {
760
769
  this.prefetchingUrls = /* @__PURE__ */ new Set();
761
770
  this.observers = /* @__PURE__ */ new Map();
762
771
  this.blockers = /* @__PURE__ */ new Set();
772
+ this.unloadBlockers = /* @__PURE__ */ new Map();
763
773
  this.navigationListeners = /* @__PURE__ */ new Set();
764
774
  this.navigationState = IDLE_NAVIGATION_STATE;
765
775
  this.currentHistoryPath = null;
@@ -771,7 +781,7 @@ var _SPARouter = class _SPARouter {
771
781
  void this.handlePopState(event);
772
782
  }, "onPopState");
773
783
  this.onBeforeUnload = /* @__PURE__ */ __name((event) => {
774
- if (this.blockers.size > 0) {
784
+ if (this.shouldBlockUnload()) {
775
785
  event.preventDefault();
776
786
  event.returnValue = "";
777
787
  }
@@ -949,6 +959,7 @@ var _SPARouter = class _SPARouter {
949
959
  if (isFarmLocaleChangeHref(href)) return;
950
960
  const url = new URL(href, window.location.origin);
951
961
  if (isFarmExternalNavigationURL(url, window.location.origin)) return;
962
+ if (this.options.shouldUseDocumentNavigation(url.pathname)) return;
952
963
  const fullPath = url.pathname + url.search;
953
964
  const interceptFrom = window.location.pathname + window.location.search;
954
965
  if (this.prefetchingUrls.has(fullPath)) return;
@@ -997,10 +1008,15 @@ var _SPARouter = class _SPARouter {
997
1008
  this.observers.delete(element);
998
1009
  }
999
1010
  }
1000
- addBlocker(blocker) {
1011
+ addBlocker(blocker, shouldBlockUnload) {
1001
1012
  this.blockers.add(blocker);
1013
+ this.unloadBlockers.set(
1014
+ blocker,
1015
+ shouldBlockUnload ?? (() => this.evaluateBlockerForUnload(blocker))
1016
+ );
1002
1017
  return () => {
1003
1018
  this.blockers.delete(blocker);
1019
+ this.unloadBlockers.delete(blocker);
1004
1020
  };
1005
1021
  }
1006
1022
  getNavigationState() {
@@ -1029,11 +1045,16 @@ var _SPARouter = class _SPARouter {
1029
1045
  this.writePageState("replace", state, href);
1030
1046
  }
1031
1047
  async commitNavigation(options) {
1032
- const historyPath = options.pageData.canonicalPath || options.fullPath;
1048
+ const historyUrl = new URL(
1049
+ options.pageData.canonicalPath || options.fullPath,
1050
+ window.location.origin
1051
+ );
1052
+ historyUrl.hash = options.url.hash;
1053
+ const historyPath = historyUrl.pathname + historyUrl.search + historyUrl.hash;
1033
1054
  const historyState = createHistoryState(
1034
1055
  historyPath,
1035
1056
  options.state,
1036
- void 0,
1057
+ options.replace ? window.history.state : void 0,
1037
1058
  options.pageData.interception?.from ?? null
1038
1059
  );
1039
1060
  const nextHistoryIndex = this.currentHistoryIndex == null ? null : options.replace ? this.currentHistoryIndex : this.currentHistoryIndex + 1;
@@ -1047,18 +1068,8 @@ var _SPARouter = class _SPARouter {
1047
1068
  }
1048
1069
  this.currentHistoryIndex = nextHistoryIndex;
1049
1070
  this.currentHistoryPath = new URL(historyPath, window.location.origin).pathname + new URL(historyPath, window.location.origin).search;
1050
- if (options.pageData.metadata?.title) {
1051
- document.title = options.pageData.metadata.title;
1052
- }
1053
- if (options.pageData.metadata?.description) {
1054
- let metaDesc = document.querySelector('meta[name="description"]');
1055
- if (!metaDesc) {
1056
- metaDesc = document.createElement("meta");
1057
- metaDesc.setAttribute("name", "description");
1058
- document.head.appendChild(metaDesc);
1059
- }
1060
- metaDesc.setAttribute("content", options.pageData.metadata.description);
1061
- }
1071
+ notifyRouterHistoryChange();
1072
+ this.updateDocumentMetadata(options.pageData.metadata);
1062
1073
  _hydrateFarmI18n(options.pageData.i18n);
1063
1074
  if (this.onNavigate) {
1064
1075
  await this.onNavigate(options.pageData);
@@ -1208,9 +1219,7 @@ var _SPARouter = class _SPARouter {
1208
1219
  await this.clientPlugins?.markNavigationLoaded(clientNavigation, pageData);
1209
1220
  }
1210
1221
  if (!this.isCurrentNavigation(navigation, clientNavigation)) return;
1211
- if (pageData.metadata?.title) {
1212
- document.title = pageData.metadata.title;
1213
- }
1222
+ this.updateDocumentMetadata(pageData.metadata);
1214
1223
  _hydrateFarmI18n(pageData.i18n);
1215
1224
  if (this.onNavigate) {
1216
1225
  await this.onNavigate(pageData);
@@ -1254,6 +1263,39 @@ var _SPARouter = class _SPARouter {
1254
1263
  }
1255
1264
  return false;
1256
1265
  }
1266
+ evaluateBlockerForUnload(blocker) {
1267
+ const path = window.location.pathname + window.location.search;
1268
+ const result = blocker({ from: path, to: path, action: "replace" });
1269
+ if (result && typeof result !== "boolean") {
1270
+ void result.catch(() => void 0);
1271
+ return true;
1272
+ }
1273
+ return result === true;
1274
+ }
1275
+ shouldBlockUnload() {
1276
+ for (const blocker of this.blockers) {
1277
+ try {
1278
+ if (this.unloadBlockers.get(blocker)?.()) return true;
1279
+ } catch {
1280
+ return true;
1281
+ }
1282
+ }
1283
+ return false;
1284
+ }
1285
+ updateDocumentMetadata(metadata) {
1286
+ document.title = metadata?.title || "Farm.js App";
1287
+ let description = document.querySelector('meta[name="description"]');
1288
+ if (!metadata?.description) {
1289
+ description?.remove();
1290
+ return;
1291
+ }
1292
+ if (!description) {
1293
+ description = document.createElement("meta");
1294
+ description.setAttribute("name", "description");
1295
+ document.head.appendChild(description);
1296
+ }
1297
+ description.setAttribute("content", metadata.description);
1298
+ }
1257
1299
  startNavigation(options) {
1258
1300
  this.activeNavigation?.controller.abort("superseded");
1259
1301
  const navigation = {