@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
@@ -1,5 +1,5 @@
1
1
  export { a as FarmClientHydrationCompleteEvent, b as FarmClientHydrationEvent, d as FarmClientHydrationMode, e as FarmClientHydrationSession, f as FarmClientLocation, g as FarmClientNavigationAction, h as FarmClientNavigationErrorEvent, i as FarmClientNavigationEvent, j as FarmClientNavigationLoadedEvent, k as FarmClientNavigationResolvedEvent, l as FarmClientNavigationSession, m as FarmClientPerformanceEvent, n as FarmClientPlugin, o as FarmClientPluginCloseEvent, p as FarmClientPluginEnforce, q as FarmClientPluginErrorEvent, r as FarmClientPluginErrorPhase, F as FarmClientPluginManager, s as FarmClientPluginManagerOptions, t as FarmClientPluginMetadata, u as FarmClientPluginRegistration, v as FarmClientPluginRouter, w as FarmClientPluginSetupEvent, x as FarmClientPluginStateEvent, c as createClientPluginManager } from './lifecycle-De0vQG45.mjs';
2
- export { a7 as FarmPlugin, aO as FarmPluginContext, aR as FarmRequestPluginContext, aS as FarmRequestStore } from './client-plugins-BtfLE4dW.mjs';
2
+ export { a7 as FarmPlugin, aO as FarmPluginContext, aR as FarmRequestPluginContext, aS as FarmRequestStore } from './client-plugins-HizW0gLc.mjs';
3
3
  import './renderer.mjs';
4
4
  import 'http';
5
5
  import './types-D1A6-XvH.mjs';
@@ -1,5 +1,5 @@
1
1
  export { a as FarmClientHydrationCompleteEvent, b as FarmClientHydrationEvent, d as FarmClientHydrationMode, e as FarmClientHydrationSession, f as FarmClientLocation, g as FarmClientNavigationAction, h as FarmClientNavigationErrorEvent, i as FarmClientNavigationEvent, j as FarmClientNavigationLoadedEvent, k as FarmClientNavigationResolvedEvent, l as FarmClientNavigationSession, m as FarmClientPerformanceEvent, n as FarmClientPlugin, o as FarmClientPluginCloseEvent, p as FarmClientPluginEnforce, q as FarmClientPluginErrorEvent, r as FarmClientPluginErrorPhase, F as FarmClientPluginManager, s as FarmClientPluginManagerOptions, t as FarmClientPluginMetadata, u as FarmClientPluginRegistration, v as FarmClientPluginRouter, w as FarmClientPluginSetupEvent, x as FarmClientPluginStateEvent, c as createClientPluginManager } from './lifecycle-De0vQG45.js';
2
- export { a7 as FarmPlugin, aO as FarmPluginContext, aR as FarmRequestPluginContext, aS as FarmRequestStore } from './client-plugins-C4me5UPd.js';
2
+ export { a7 as FarmPlugin, aO as FarmPluginContext, aR as FarmRequestPluginContext, aS as FarmRequestStore } from './client-plugins-w_b1wA8e.js';
3
3
  import './renderer.js';
4
4
  import 'http';
5
5
  import './types-D1A6-XvH.js';
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  FarmClientPluginManager,
3
3
  createClientPluginManager
4
- } from "./chunk-3UGGCJT5.mjs";
4
+ } from "./chunk-HSCQGINR.mjs";
5
5
  import "./chunk-FXG2PS27.mjs";
6
- import "./chunk-OEI62POE.mjs";
6
+ import "./chunk-6NV2RJSZ.mjs";
7
7
  import "./chunk-CGILA3WO.mjs";
8
8
  export {
9
9
  FarmClientPluginManager,
package/dist/client.cjs CHANGED
@@ -5146,6 +5146,14 @@ __name(rejectPendingDeferred, "rejectPendingDeferred");
5146
5146
 
5147
5147
  // src/client/history-sync.ts
5148
5148
  var FARM_HISTORY_CHANGE_EVENT = "farm:historychange";
5149
+ function dispatchHistoryChange(kind) {
5150
+ window.dispatchEvent(
5151
+ new CustomEvent(FARM_HISTORY_CHANGE_EVENT, {
5152
+ detail: { kind }
5153
+ })
5154
+ );
5155
+ }
5156
+ __name(dispatchHistoryChange, "dispatchHistoryChange");
5149
5157
  function notifyHistoryChange(kind) {
5150
5158
  if (typeof window === "undefined") return;
5151
5159
  setTimeout(() => {
@@ -5153,14 +5161,15 @@ function notifyHistoryChange(kind) {
5153
5161
  window.dispatchEvent(new PopStateEvent("popstate"));
5154
5162
  return;
5155
5163
  }
5156
- window.dispatchEvent(
5157
- new CustomEvent(FARM_HISTORY_CHANGE_EVENT, {
5158
- detail: { kind }
5159
- })
5160
- );
5164
+ dispatchHistoryChange(kind);
5161
5165
  }, 0);
5162
5166
  }
5163
5167
  __name(notifyHistoryChange, "notifyHistoryChange");
5168
+ function notifyRouterHistoryChange() {
5169
+ if (typeof window === "undefined") return;
5170
+ setTimeout(() => dispatchHistoryChange("url-search"), 0);
5171
+ }
5172
+ __name(notifyRouterHistoryChange, "notifyRouterHistoryChange");
5164
5173
  function subscribeHistoryChange(listener) {
5165
5174
  if (typeof window === "undefined") return () => {
5166
5175
  };
@@ -5270,6 +5279,7 @@ var _SPARouter = class _SPARouter {
5270
5279
  this.prefetchingUrls = /* @__PURE__ */ new Set();
5271
5280
  this.observers = /* @__PURE__ */ new Map();
5272
5281
  this.blockers = /* @__PURE__ */ new Set();
5282
+ this.unloadBlockers = /* @__PURE__ */ new Map();
5273
5283
  this.navigationListeners = /* @__PURE__ */ new Set();
5274
5284
  this.navigationState = IDLE_NAVIGATION_STATE;
5275
5285
  this.currentHistoryPath = null;
@@ -5281,7 +5291,7 @@ var _SPARouter = class _SPARouter {
5281
5291
  void this.handlePopState(event);
5282
5292
  }, "onPopState");
5283
5293
  this.onBeforeUnload = /* @__PURE__ */ __name((event) => {
5284
- if (this.blockers.size > 0) {
5294
+ if (this.shouldBlockUnload()) {
5285
5295
  event.preventDefault();
5286
5296
  event.returnValue = "";
5287
5297
  }
@@ -5459,6 +5469,7 @@ var _SPARouter = class _SPARouter {
5459
5469
  if (isFarmLocaleChangeHref(href)) return;
5460
5470
  const url = new URL(href, window.location.origin);
5461
5471
  if (isFarmExternalNavigationURL(url, window.location.origin)) return;
5472
+ if (this.options.shouldUseDocumentNavigation(url.pathname)) return;
5462
5473
  const fullPath = url.pathname + url.search;
5463
5474
  const interceptFrom = window.location.pathname + window.location.search;
5464
5475
  if (this.prefetchingUrls.has(fullPath)) return;
@@ -5507,10 +5518,15 @@ var _SPARouter = class _SPARouter {
5507
5518
  this.observers.delete(element);
5508
5519
  }
5509
5520
  }
5510
- addBlocker(blocker) {
5521
+ addBlocker(blocker, shouldBlockUnload2) {
5511
5522
  this.blockers.add(blocker);
5523
+ this.unloadBlockers.set(
5524
+ blocker,
5525
+ shouldBlockUnload2 ?? (() => this.evaluateBlockerForUnload(blocker))
5526
+ );
5512
5527
  return () => {
5513
5528
  this.blockers.delete(blocker);
5529
+ this.unloadBlockers.delete(blocker);
5514
5530
  };
5515
5531
  }
5516
5532
  getNavigationState() {
@@ -5539,11 +5555,16 @@ var _SPARouter = class _SPARouter {
5539
5555
  this.writePageState("replace", state, href);
5540
5556
  }
5541
5557
  async commitNavigation(options) {
5542
- const historyPath = options.pageData.canonicalPath || options.fullPath;
5558
+ const historyUrl = new URL(
5559
+ options.pageData.canonicalPath || options.fullPath,
5560
+ window.location.origin
5561
+ );
5562
+ historyUrl.hash = options.url.hash;
5563
+ const historyPath = historyUrl.pathname + historyUrl.search + historyUrl.hash;
5543
5564
  const historyState = createHistoryState(
5544
5565
  historyPath,
5545
5566
  options.state,
5546
- void 0,
5567
+ options.replace ? window.history.state : void 0,
5547
5568
  options.pageData.interception?.from ?? null
5548
5569
  );
5549
5570
  const nextHistoryIndex = this.currentHistoryIndex == null ? null : options.replace ? this.currentHistoryIndex : this.currentHistoryIndex + 1;
@@ -5557,18 +5578,8 @@ var _SPARouter = class _SPARouter {
5557
5578
  }
5558
5579
  this.currentHistoryIndex = nextHistoryIndex;
5559
5580
  this.currentHistoryPath = new URL(historyPath, window.location.origin).pathname + new URL(historyPath, window.location.origin).search;
5560
- if (options.pageData.metadata?.title) {
5561
- document.title = options.pageData.metadata.title;
5562
- }
5563
- if (options.pageData.metadata?.description) {
5564
- let metaDesc = document.querySelector('meta[name="description"]');
5565
- if (!metaDesc) {
5566
- metaDesc = document.createElement("meta");
5567
- metaDesc.setAttribute("name", "description");
5568
- document.head.appendChild(metaDesc);
5569
- }
5570
- metaDesc.setAttribute("content", options.pageData.metadata.description);
5571
- }
5581
+ notifyRouterHistoryChange();
5582
+ this.updateDocumentMetadata(options.pageData.metadata);
5572
5583
  _hydrateFarmI18n(options.pageData.i18n);
5573
5584
  if (this.onNavigate) {
5574
5585
  await this.onNavigate(options.pageData);
@@ -5718,9 +5729,7 @@ var _SPARouter = class _SPARouter {
5718
5729
  await this.clientPlugins?.markNavigationLoaded(clientNavigation, pageData);
5719
5730
  }
5720
5731
  if (!this.isCurrentNavigation(navigation, clientNavigation)) return;
5721
- if (pageData.metadata?.title) {
5722
- document.title = pageData.metadata.title;
5723
- }
5732
+ this.updateDocumentMetadata(pageData.metadata);
5724
5733
  _hydrateFarmI18n(pageData.i18n);
5725
5734
  if (this.onNavigate) {
5726
5735
  await this.onNavigate(pageData);
@@ -5764,6 +5773,39 @@ var _SPARouter = class _SPARouter {
5764
5773
  }
5765
5774
  return false;
5766
5775
  }
5776
+ evaluateBlockerForUnload(blocker) {
5777
+ const path = window.location.pathname + window.location.search;
5778
+ const result = blocker({ from: path, to: path, action: "replace" });
5779
+ if (result && typeof result !== "boolean") {
5780
+ void result.catch(() => void 0);
5781
+ return true;
5782
+ }
5783
+ return result === true;
5784
+ }
5785
+ shouldBlockUnload() {
5786
+ for (const blocker of this.blockers) {
5787
+ try {
5788
+ if (this.unloadBlockers.get(blocker)?.()) return true;
5789
+ } catch {
5790
+ return true;
5791
+ }
5792
+ }
5793
+ return false;
5794
+ }
5795
+ updateDocumentMetadata(metadata) {
5796
+ document.title = metadata?.title || "Farm.js App";
5797
+ let description = document.querySelector('meta[name="description"]');
5798
+ if (!metadata?.description) {
5799
+ description?.remove();
5800
+ return;
5801
+ }
5802
+ if (!description) {
5803
+ description = document.createElement("meta");
5804
+ description.setAttribute("name", "description");
5805
+ document.head.appendChild(description);
5806
+ }
5807
+ description.setAttribute("content", metadata.description);
5808
+ }
5767
5809
  startNavigation(options) {
5768
5810
  this.activeNavigation?.controller.abort("superseded");
5769
5811
  const navigation = {
@@ -5974,6 +6016,26 @@ function _resolveCurrentRequest() {
5974
6016
  __name(_resolveCurrentRequest, "_resolveCurrentRequest");
5975
6017
 
5976
6018
  // src/client/router.ts
6019
+ function shouldBlockUnload(options) {
6020
+ const path = window.location.pathname + window.location.search;
6021
+ const context2 = {
6022
+ from: path,
6023
+ to: path,
6024
+ action: "replace"
6025
+ };
6026
+ const when = typeof options.when === "function" ? options.when(context2) : options.when;
6027
+ if (!when) return false;
6028
+ if (!options.shouldBlock) return true;
6029
+ try {
6030
+ const result = options.shouldBlock(context2);
6031
+ if (typeof result === "boolean") return result;
6032
+ void result.catch(() => void 0);
6033
+ return true;
6034
+ } catch {
6035
+ return true;
6036
+ }
6037
+ }
6038
+ __name(shouldBlockUnload, "shouldBlockUnload");
5977
6039
  function navigateViaRouter(href, basePath, replace) {
5978
6040
  if (typeof window === "undefined") return;
5979
6041
  const url = applyFarmBasePath(href, basePath);
@@ -6077,18 +6139,21 @@ function useBlocker(options) {
6077
6139
  if (typeof window === "undefined" || !active) {
6078
6140
  return;
6079
6141
  }
6080
- return getRouter2().addBlocker(async (context2) => {
6081
- const current = optionsRef.current;
6082
- const when = typeof current.when === "function" ? current.when(context2) : current.when;
6083
- if (!when) return false;
6084
- if (current.shouldBlock && !await current.shouldBlock(context2)) {
6085
- return false;
6086
- }
6087
- if (current.message && typeof window.confirm === "function") {
6088
- return !window.confirm(current.message);
6089
- }
6090
- return true;
6091
- });
6142
+ return getRouter2().addBlocker(
6143
+ async (context2) => {
6144
+ const current = optionsRef.current;
6145
+ const when = typeof current.when === "function" ? current.when(context2) : current.when;
6146
+ if (!when) return false;
6147
+ if (current.shouldBlock && !await current.shouldBlock(context2)) {
6148
+ return false;
6149
+ }
6150
+ if (current.message && typeof window.confirm === "function") {
6151
+ return !window.confirm(current.message);
6152
+ }
6153
+ return true;
6154
+ },
6155
+ () => shouldBlockUnload(optionsRef.current)
6156
+ );
6092
6157
  }, [active]);
6093
6158
  return { active };
6094
6159
  }
@@ -6767,7 +6832,7 @@ body {
6767
6832
  `;
6768
6833
 
6769
6834
  // package.json
6770
- var version = "0.1.0-beta.80";
6835
+ var version = "0.1.0-beta.81";
6771
6836
 
6772
6837
  // src/version.ts
6773
6838
  var FARM_VERSION = version;