defuss 3.4.4 → 3.4.5

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.
package/dist/index.cjs CHANGED
@@ -1163,10 +1163,10 @@ const setupRouter = (config = {
1163
1163
  pendingResolvers: [],
1164
1164
  currentPath: "",
1165
1165
  popAttached: false,
1166
- lifecycleHooks: { beforeUnmount: [], unmount: [] }
1166
+ lifecycleHooks: { beforeLeave: [], leave: [] }
1167
1167
  };
1168
1168
  if (!state.lifecycleHooks) {
1169
- state.lifecycleHooks = { beforeUnmount: [], unmount: [] };
1169
+ state.lifecycleHooks = { beforeLeave: [], leave: [] };
1170
1170
  }
1171
1171
  const routeRegistrations = state.routeRegistrations;
1172
1172
  if (typeof window !== "undefined" && !windowImpl) {
@@ -1295,30 +1295,30 @@ const setupRouter = (config = {
1295
1295
  return {
1296
1296
  request,
1297
1297
  onBeforeLeave(fn) {
1298
- state.lifecycleHooks.beforeUnmount.push(fn);
1298
+ state.lifecycleHooks.beforeLeave.push(fn);
1299
1299
  },
1300
1300
  onLeave(fn) {
1301
- state.lifecycleHooks.unmount.push(fn);
1301
+ state.lifecycleHooks.leave.push(fn);
1302
1302
  }
1303
1303
  };
1304
1304
  },
1305
- async runBeforeUnmountHooks() {
1306
- for (const fn of state.lifecycleHooks.beforeUnmount) {
1305
+ async runBeforeLeaveHooks() {
1306
+ for (const fn of state.lifecycleHooks.beforeLeave) {
1307
1307
  const result = await fn();
1308
1308
  if (result === false) return false;
1309
1309
  }
1310
1310
  return true;
1311
1311
  },
1312
- runUnmountHooks() {
1313
- for (const fn of state.lifecycleHooks.unmount) {
1312
+ runLeaveHooks() {
1313
+ for (const fn of state.lifecycleHooks.leave) {
1314
1314
  fn();
1315
1315
  }
1316
1316
  },
1317
1317
  clearRouteLifecycle() {
1318
- const oldUnmountHooks = [...state.lifecycleHooks.unmount];
1319
- state.lifecycleHooks.beforeUnmount = [];
1320
- state.lifecycleHooks.unmount = [];
1321
- return { unmountHooks: oldUnmountHooks };
1318
+ const oldLeaveHooks = [...state.lifecycleHooks.leave];
1319
+ state.lifecycleHooks.beforeLeave = [];
1320
+ state.lifecycleHooks.leave = [];
1321
+ return { leaveHooks: oldLeaveHooks };
1322
1322
  }
1323
1323
  };
1324
1324
  const handlePopState = (event) => {
@@ -1349,7 +1349,7 @@ if (!globalThis[ROUTER_STATE_KEY]) {
1349
1349
  pendingResolvers: [],
1350
1350
  currentPath: "",
1351
1351
  popAttached: false,
1352
- lifecycleHooks: { beforeUnmount: [], unmount: [] }
1352
+ lifecycleHooks: { beforeLeave: [], leave: [] }
1353
1353
  };
1354
1354
  }
1355
1355
  const getRouterState = () => globalThis[ROUTER_STATE_KEY];
@@ -1422,18 +1422,18 @@ const RouterSlot = ({
1422
1422
  const currentPath = router.getRequest().path;
1423
1423
  const isSamePath = currentPath === lastPath;
1424
1424
  if (!isSamePath) {
1425
- const allowed = await router.runBeforeUnmountHooks();
1425
+ const allowed = await router.runBeforeLeaveHooks();
1426
1426
  if (!allowed) {
1427
1427
  window.history.pushState({}, "", lastPath);
1428
1428
  router.resolve(lastPath);
1429
1429
  return;
1430
1430
  }
1431
- const { unmountHooks } = router.clearRouteLifecycle();
1431
+ const { leaveHooks } = router.clearRouteLifecycle();
1432
1432
  await dom.$(ref).update(
1433
1433
  typeof RouterOutlet === "function" ? RouterOutlet() : [],
1434
1434
  transitionConfig
1435
1435
  );
1436
- for (const fn of unmountHooks) {
1436
+ for (const fn of leaveHooks) {
1437
1437
  fn();
1438
1438
  }
1439
1439
  } else {
package/dist/index.d.ts CHANGED
@@ -137,8 +137,8 @@ declare const T: ({ key, values, tag, ref, ...attrs }: TransProps<string>) => VN
137
137
  type OnHandleRouteChangeFn = (newRoute: string, oldRoute: string) => void;
138
138
  type OnRouteChangeFn = (cb: OnHandleRouteChangeFn) => void;
139
139
  type RouterStrategy = "page-refresh" | "slot-refresh";
140
- type BeforeUnmountHookFn = () => boolean | void | Promise<boolean | void>;
141
- type UnmountHookFn = () => void;
140
+ type BeforeLeaveHookFn = () => boolean | void | Promise<boolean | void>;
141
+ type LeaveHookFn = () => void;
142
142
  /**
143
143
  * Context object passed to components rendered via Route's `component` prop.
144
144
  * Provides access to the current route request and lifecycle hooks.
@@ -161,30 +161,30 @@ interface RouteContext {
161
161
  /** The matched RouteRequest for the current route */
162
162
  request: RouteRequest;
163
163
  /**
164
- * Register a hook that fires before leaving the current route.
164
+ * Register a hook that fires before the route is unmounted.
165
165
  * Returning `false` (or a Promise resolving to `false`) blocks navigation,
166
166
  * allowing implementation of confirmation dialogs.
167
167
  */
168
- onBeforeLeave(fn: BeforeUnmountHookFn): void;
168
+ onBeforeLeave(fn: BeforeLeaveHookFn): void;
169
169
  /**
170
- * Register a hook that fires after the route has been left
170
+ * Register a hook that fires after the route has been unmounted
171
171
  * (navigation completed, new route is rendered).
172
172
  */
173
- onLeave(fn: UnmountHookFn): void;
173
+ onLeave(fn: LeaveHookFn): void;
174
174
  }
175
175
  /**
176
- * Props mixin for screen components rendered by `<Route component={...} />`.
177
- * Extend your component props with this to get typed access to route context.
176
+ * Props interface for components rendered via Route's `component` prop.
177
+ * Extend your component's props with this to receive the `route` context.
178
178
  *
179
179
  * @example
180
180
  * ```tsx
181
- * import { Router, type Props, type RouteProps } from "defuss";
181
+ * import { type Props, type RouteProps } from "defuss";
182
182
  *
183
- * export interface ProjectDetailsProps extends Props, RouteProps {}
183
+ * interface MyScreenProps extends Props, RouteProps {}
184
184
  *
185
- * export function ProjectDetailsScreen({ route }: ProjectDetailsProps) {
186
- * const { projectName } = route.request.params;
187
- * return <h1>Project: {projectName}</h1>;
185
+ * function MyScreen({ route }: MyScreenProps) {
186
+ * const { userId } = route.request.params;
187
+ * return <h1>User #{userId}</h1>;
188
188
  * }
189
189
  * ```
190
190
  */
@@ -323,8 +323,8 @@ interface RouterState {
323
323
  currentPath: string;
324
324
  popAttached: boolean;
325
325
  lifecycleHooks: {
326
- beforeUnmount: Array<BeforeUnmountHookFn>;
327
- unmount: Array<UnmountHookFn>;
326
+ beforeLeave: Array<BeforeLeaveHookFn>;
327
+ leave: Array<LeaveHookFn>;
328
328
  };
329
329
  }
330
330
  declare global {
@@ -381,8 +381,8 @@ interface RouteComponentProps extends Props {
381
381
  *
382
382
  * The component receives a `route` prop (RouteContext) with:
383
383
  * - `route.request` — the matched RouteRequest with params, query, etc.
384
- * - `route.onBeforeLeave(fn)` — register a hook before route leaves; return `false` to block
385
- * - `route.onLeave(fn)` — register a hook after route has been left
384
+ * - `route.onBeforeUnmount(fn)` — register a hook before route leaves; return `false` to block
385
+ * - `route.onUnmount(fn)` — register a hook after route has been left
386
386
  *
387
387
  * When the component is async and Route has children, the children are
388
388
  * shown as a loading fallback until the async component resolves.
@@ -486,4 +486,4 @@ declare const Suspense: ({ fallback, ref, children, class: _class, className, id
486
486
  };
487
487
 
488
488
  export { Async, AsyncDefussChild, DOMElement, FC, Globals, NodeType, PersistenceProviderImpl, PersistenceProviderOptions, PersistenceProviderType, Props, Redirect, Ref, RenderInput, Route, Router, RouterSlot, RouterSlotId, Suspense, T, Trans, TransitionConfig, VNode, VNodeAttributes, VNodeChild, addElementEvent, areDomNodesEqual, changeLanguage, checkElementVisibility, clearElementEvents, createI18n, createTrans, domNodeToVNode, getEventMap, getLanguage, getMimeType, getRouterState, htmlStringToVNodes, i18n, inDevMode, isHTML, isMarkup, isSVG, loadLanguage, matchRouteRegistrations, parseDOM, processAllFormElements, queueCallback, removeElementEvent, renderMarkup, replaceDomWithVdom, setupRouter, t, tokenizePath, updateDomWithVdom, waitForDOM, webstorage };
489
- export type { AsyncProps, AsyncState, AsyncStateRef, BeforeUnmountHookFn, I18nStore, MatchRouteRegistrationsOpts, OnHandleRouteChangeFn, OnLanguageChangeListener, OnRouteChangeFn, RedirectProps, Replacements, Resolve, RouteComponentProps, RouteContext, RouteHandler, RouteParams, RouteProps, RouteRegistration, RouteRequest, RouterConfig, RouterSlotProps, RouterStrategy, TokenizedPath, TransProps, TransRef, TranslationKeys, TranslationObject, Translations, UnmountHookFn, ValidChild };
489
+ export type { AsyncProps, AsyncState, AsyncStateRef, BeforeLeaveHookFn, I18nStore, LeaveHookFn, MatchRouteRegistrationsOpts, OnHandleRouteChangeFn, OnLanguageChangeListener, OnRouteChangeFn, RedirectProps, Replacements, Resolve, RouteComponentProps, RouteContext, RouteHandler, RouteParams, RouteProps, RouteRegistration, RouteRequest, RouterConfig, RouterSlotProps, RouterStrategy, TokenizedPath, TransProps, TransRef, TranslationKeys, TranslationObject, Translations, ValidChild };
package/dist/index.mjs CHANGED
@@ -1162,10 +1162,10 @@ const setupRouter = (config = {
1162
1162
  pendingResolvers: [],
1163
1163
  currentPath: "",
1164
1164
  popAttached: false,
1165
- lifecycleHooks: { beforeUnmount: [], unmount: [] }
1165
+ lifecycleHooks: { beforeLeave: [], leave: [] }
1166
1166
  };
1167
1167
  if (!state.lifecycleHooks) {
1168
- state.lifecycleHooks = { beforeUnmount: [], unmount: [] };
1168
+ state.lifecycleHooks = { beforeLeave: [], leave: [] };
1169
1169
  }
1170
1170
  const routeRegistrations = state.routeRegistrations;
1171
1171
  if (typeof window !== "undefined" && !windowImpl) {
@@ -1294,30 +1294,30 @@ const setupRouter = (config = {
1294
1294
  return {
1295
1295
  request,
1296
1296
  onBeforeLeave(fn) {
1297
- state.lifecycleHooks.beforeUnmount.push(fn);
1297
+ state.lifecycleHooks.beforeLeave.push(fn);
1298
1298
  },
1299
1299
  onLeave(fn) {
1300
- state.lifecycleHooks.unmount.push(fn);
1300
+ state.lifecycleHooks.leave.push(fn);
1301
1301
  }
1302
1302
  };
1303
1303
  },
1304
- async runBeforeUnmountHooks() {
1305
- for (const fn of state.lifecycleHooks.beforeUnmount) {
1304
+ async runBeforeLeaveHooks() {
1305
+ for (const fn of state.lifecycleHooks.beforeLeave) {
1306
1306
  const result = await fn();
1307
1307
  if (result === false) return false;
1308
1308
  }
1309
1309
  return true;
1310
1310
  },
1311
- runUnmountHooks() {
1312
- for (const fn of state.lifecycleHooks.unmount) {
1311
+ runLeaveHooks() {
1312
+ for (const fn of state.lifecycleHooks.leave) {
1313
1313
  fn();
1314
1314
  }
1315
1315
  },
1316
1316
  clearRouteLifecycle() {
1317
- const oldUnmountHooks = [...state.lifecycleHooks.unmount];
1318
- state.lifecycleHooks.beforeUnmount = [];
1319
- state.lifecycleHooks.unmount = [];
1320
- return { unmountHooks: oldUnmountHooks };
1317
+ const oldLeaveHooks = [...state.lifecycleHooks.leave];
1318
+ state.lifecycleHooks.beforeLeave = [];
1319
+ state.lifecycleHooks.leave = [];
1320
+ return { leaveHooks: oldLeaveHooks };
1321
1321
  }
1322
1322
  };
1323
1323
  const handlePopState = (event) => {
@@ -1348,7 +1348,7 @@ if (!globalThis[ROUTER_STATE_KEY]) {
1348
1348
  pendingResolvers: [],
1349
1349
  currentPath: "",
1350
1350
  popAttached: false,
1351
- lifecycleHooks: { beforeUnmount: [], unmount: [] }
1351
+ lifecycleHooks: { beforeLeave: [], leave: [] }
1352
1352
  };
1353
1353
  }
1354
1354
  const getRouterState = () => globalThis[ROUTER_STATE_KEY];
@@ -1421,18 +1421,18 @@ const RouterSlot = ({
1421
1421
  const currentPath = router.getRequest().path;
1422
1422
  const isSamePath = currentPath === lastPath;
1423
1423
  if (!isSamePath) {
1424
- const allowed = await router.runBeforeUnmountHooks();
1424
+ const allowed = await router.runBeforeLeaveHooks();
1425
1425
  if (!allowed) {
1426
1426
  window.history.pushState({}, "", lastPath);
1427
1427
  router.resolve(lastPath);
1428
1428
  return;
1429
1429
  }
1430
- const { unmountHooks } = router.clearRouteLifecycle();
1430
+ const { leaveHooks } = router.clearRouteLifecycle();
1431
1431
  await $(ref).update(
1432
1432
  typeof RouterOutlet === "function" ? RouterOutlet() : [],
1433
1433
  transitionConfig
1434
1434
  );
1435
- for (const fn of unmountHooks) {
1435
+ for (const fn of leaveHooks) {
1436
1436
  fn();
1437
1437
  }
1438
1438
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "defuss",
3
- "version": "3.4.4",
3
+ "version": "3.4.5",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"