@koordinates/xstate-tree 5.3.0 → 5.5.0

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.
@@ -16,7 +16,9 @@ function singleSlot(name) {
16
16
  return {
17
17
  type: SlotType.SingleSlot,
18
18
  name,
19
- getId: () => `${name.toLowerCase()}-slot`,
19
+ getId: (suffix) => suffix
20
+ ? `${name.toLowerCase()}-${suffix}-slot`
21
+ : `${name.toLowerCase()}-slot`,
20
22
  };
21
23
  }
22
24
  exports.singleSlot = singleSlot;
@@ -27,7 +29,9 @@ function multiSlot(name) {
27
29
  return {
28
30
  type: SlotType.MultiSlot,
29
31
  name: `${name}Multi`,
30
- getId: (id) => `${id}-${name.toLowerCase()}multi-slots`,
32
+ getId: (id, suffix) => suffix
33
+ ? `${id}-${name.toLowerCase()}multi-slots-${suffix}`
34
+ : `${id}-${name.toLowerCase()}multi-slots`,
31
35
  };
32
36
  }
33
37
  exports.multiSlot = multiSlot;
@@ -320,7 +320,7 @@ export declare type Meta<T> = T extends {
320
320
  export declare type MultiSlot<T extends string> = {
321
321
  type: SlotType.MultiSlot;
322
322
  name: `${T}Multi`;
323
- getId(id: string): string;
323
+ getId(id: string, suffix?: string): string;
324
324
  };
325
325
 
326
326
  /**
@@ -410,6 +410,7 @@ declare type RootOptions<TInput> = {
410
410
  basePath: string;
411
411
  getPathName?: () => string;
412
412
  getQueryString?: () => string;
413
+ shouldBlockActiveRouteUpdate?: (event: RoutingEvent<any>) => boolean;
413
414
  } | undefined;
414
415
  input: IsUnknown<TInput> extends true ? undefined : TInput;
415
416
  };
@@ -620,7 +621,7 @@ export declare type SharedMeta = {
620
621
  export declare type SingleSlot<T extends string> = {
621
622
  type: SlotType.SingleSlot;
622
623
  name: T;
623
- getId(): string;
624
+ getId(suffix?: string): string;
624
625
  };
625
626
 
626
627
  /**
package/lib/xstateTree.js CHANGED
@@ -331,8 +331,12 @@ function buildRootComponent(options) {
331
331
  const queryString = getQueryString();
332
332
  const result = (0, routing_1.handleLocationChange)(routing.routes, routing.basePath, getPathName(), getQueryString(), initialMeta);
333
333
  if (result) {
334
- setActiveRouteEvents(result.events);
335
- setActiveRoute({ ...result.matchedRoute });
334
+ const matchedEvent = result.events[result.events.length - 1];
335
+ const block = routing.shouldBlockActiveRouteUpdate?.(matchedEvent) === true;
336
+ if (!block) {
337
+ setActiveRouteEvents(result.events);
338
+ setActiveRoute({ ...result.matchedRoute });
339
+ }
336
340
  }
337
341
  // Hack to ensure the initial location doesn't have undefined state
338
342
  // It's not supposed to, but it does for some reason
@@ -347,8 +351,12 @@ function buildRootComponent(options) {
347
351
  const unsub = routing.history.listen((location) => {
348
352
  const result = (0, routing_1.handleLocationChange)(routing.routes, routing.basePath, location.pathname, location.search, location.state?.meta);
349
353
  if (result) {
350
- setActiveRouteEvents(result.events);
351
- setActiveRoute({ ...result.matchedRoute });
354
+ const matchedEvent = result.events[result.events.length - 1];
355
+ const block = routing.shouldBlockActiveRouteUpdate?.(matchedEvent) === true;
356
+ if (!block) {
357
+ setActiveRouteEvents(result.events);
358
+ setActiveRoute({ ...result.matchedRoute });
359
+ }
352
360
  }
353
361
  });
354
362
  return () => {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@koordinates/xstate-tree",
3
3
  "main": "lib/index.js",
4
4
  "types": "lib/xstate-tree.d.ts",
5
- "version": "5.3.0",
5
+ "version": "5.5.0",
6
6
  "license": "MIT",
7
7
  "description": "Build UIs with Actors using xstate and React",
8
8
  "keywords": [