@vertz/ui 0.2.23 → 0.2.24

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  injectCSS
3
- } from "./chunk-xhc7arn9.js";
3
+ } from "./chunk-t3rnfxc0.js";
4
4
 
5
5
  // src/dom/animation.ts
6
6
  function onAnimationsComplete(el, callback) {
@@ -0,0 +1,39 @@
1
+ import {
2
+ getSSRContext
3
+ } from "./chunk-656n0x6y.js";
4
+
5
+ // src/query/invalidate.ts
6
+ var registry = new Set;
7
+ function registerActiveQuery(entityMeta, refetch, clearData) {
8
+ const registration = { entityMeta, refetch, clearData };
9
+ registry.add(registration);
10
+ return () => registry.delete(registration);
11
+ }
12
+ function invalidate(descriptor) {
13
+ const meta = descriptor._entity;
14
+ if (!meta)
15
+ return;
16
+ if (meta.kind === "get" && !meta.id)
17
+ return;
18
+ for (const reg of [...registry]) {
19
+ if (reg.entityMeta.entityType !== meta.entityType)
20
+ continue;
21
+ if (reg.entityMeta.kind !== meta.kind)
22
+ continue;
23
+ if (meta.kind === "get" && reg.entityMeta.id !== meta.id)
24
+ continue;
25
+ reg.refetch();
26
+ }
27
+ }
28
+ function invalidateTenantQueries() {
29
+ if (getSSRContext() !== undefined)
30
+ return;
31
+ for (const reg of [...registry]) {
32
+ if (reg.entityMeta.tenantScoped !== true)
33
+ continue;
34
+ reg.clearData?.();
35
+ reg.refetch();
36
+ }
37
+ }
38
+
39
+ export { registerActiveQuery, invalidate, invalidateTenantQueries };
@@ -1,17 +1,17 @@
1
1
  import {
2
- __classList,
3
2
  __on,
4
3
  beginDeferringMounts,
5
4
  discardDeferredMounts,
6
5
  flushDeferredMounts
7
- } from "./chunk-2kyhn86t.js";
6
+ } from "./chunk-ge2e6y2s.js";
8
7
  import {
9
8
  __append,
9
+ __classList,
10
10
  __element,
11
11
  __enterChildren,
12
12
  __exitChildren,
13
13
  __staticText
14
- } from "./chunk-13tvh4wq.js";
14
+ } from "./chunk-mbnda3pv.js";
15
15
  import {
16
16
  RouterContext
17
17
  } from "./chunk-f4d5nphq.js";
@@ -34,6 +34,64 @@ import {
34
34
  useContext
35
35
  } from "./chunk-656n0x6y.js";
36
36
 
37
+ // src/component/error-boundary-context.ts
38
+ var handlerStack = [];
39
+ function pushErrorHandler(handler) {
40
+ handlerStack.push(handler);
41
+ }
42
+ function popErrorHandler() {
43
+ handlerStack.pop();
44
+ }
45
+ function getCurrentErrorHandler() {
46
+ if (handlerStack.length === 0) {
47
+ return;
48
+ }
49
+ return handlerStack[handlerStack.length - 1];
50
+ }
51
+
52
+ // src/component/error-boundary.ts
53
+ function toError(value) {
54
+ if (value instanceof Error) {
55
+ return value;
56
+ }
57
+ return new Error(String(value));
58
+ }
59
+ function ErrorBoundary(props) {
60
+ function handleAsyncError(error, placeholder) {
61
+ const fallbackNode = props.fallback(error, retry);
62
+ function retry() {
63
+ try {
64
+ const retryResult = props.children();
65
+ if (fallbackNode.parentNode) {
66
+ fallbackNode.parentNode.replaceChild(retryResult, fallbackNode);
67
+ }
68
+ } catch (_retryThrown) {}
69
+ }
70
+ if (placeholder.parentNode) {
71
+ placeholder.parentNode.replaceChild(fallbackNode, placeholder);
72
+ }
73
+ }
74
+ try {
75
+ pushErrorHandler(handleAsyncError);
76
+ const result = props.children();
77
+ popErrorHandler();
78
+ return result;
79
+ } catch (thrown) {
80
+ let retry = function() {
81
+ try {
82
+ const retryResult = props.children();
83
+ if (fallbackNode.parentNode) {
84
+ fallbackNode.parentNode.replaceChild(retryResult, fallbackNode);
85
+ }
86
+ } catch (_retryThrown) {}
87
+ };
88
+ popErrorHandler();
89
+ const error = toError(thrown);
90
+ const fallbackNode = props.fallback(error, retry);
91
+ return fallbackNode;
92
+ }
93
+ }
94
+
37
95
  // src/router/link.ts
38
96
  var DANGEROUS_SCHEMES = ["javascript:", "data:", "vbscript:"];
39
97
  function isSafeUrl(url) {
@@ -256,12 +314,13 @@ function Outlet() {
256
314
  }
257
315
 
258
316
  // src/router/router-view.ts
259
- function RouterView({ router, fallback }) {
317
+ function RouterView({ router, fallback, errorFallback }) {
260
318
  const container = __element("div");
261
319
  let isFirstHydrationRender = getIsHydrating();
262
320
  let renderGen = 0;
263
321
  let pageCleanups = [];
264
322
  let prevLevels = [];
323
+ let prevParamsKey;
265
324
  __enterChildren(container);
266
325
  const dispose = domEffect(() => {
267
326
  const match = router.current.value;
@@ -274,17 +333,23 @@ function RouterView({ router, fallback }) {
274
333
  if (prevLevels[divergeAt].route !== newMatched[divergeAt].route)
275
334
  break;
276
335
  }
277
- if (prevLevels.length > 0 && divergeAt === prevLevels.length && divergeAt === newMatched.length) {
336
+ const currentParamsKey = match ? JSON.stringify(match.params) : undefined;
337
+ const chainIdentical = prevLevels.length > 0 && divergeAt === prevLevels.length && divergeAt === newMatched.length;
338
+ if (chainIdentical && prevParamsKey === currentParamsKey) {
278
339
  return;
279
340
  }
341
+ if (chainIdentical) {
342
+ divergeAt = 0;
343
+ }
280
344
  if (divergeAt > 0 && newMatched.length > 0) {
281
345
  const newLevels = buildLevels(newMatched);
282
- const newChildFactory = buildInsideOutFactory(newMatched, newLevels, divergeAt, router);
346
+ const newChildFactory = buildInsideOutFactory(newMatched, newLevels, divergeAt, router, errorFallback);
283
347
  const parentLevel = prevLevels[divergeAt - 1];
284
348
  if (parentLevel.childSignal) {
285
349
  parentLevel.childSignal.value = newChildFactory;
286
350
  }
287
351
  prevLevels = [...prevLevels.slice(0, divergeAt), ...newLevels.slice(divergeAt)];
352
+ prevParamsKey = currentParamsKey;
288
353
  return;
289
354
  }
290
355
  runCleanups(pageCleanups);
@@ -299,6 +364,7 @@ function RouterView({ router, fallback }) {
299
364
  pageCleanups = pushScope();
300
365
  if (!match) {
301
366
  prevLevels = [];
367
+ prevParamsKey = undefined;
302
368
  if (fallback) {
303
369
  container.appendChild(fallback());
304
370
  }
@@ -306,7 +372,8 @@ function RouterView({ router, fallback }) {
306
372
  return;
307
373
  }
308
374
  const levels = buildLevels(newMatched);
309
- const rootFactory = buildInsideOutFactory(newMatched, levels, 0, router);
375
+ const rootFactory = buildInsideOutFactory(newMatched, levels, 0, router, errorFallback);
376
+ const lazyFallback = match ? match.route.errorComponent ?? errorFallback : undefined;
310
377
  let asyncRoute = false;
311
378
  RouterContext.Provider(router, () => {
312
379
  const result = rootFactory();
@@ -352,11 +419,35 @@ function RouterView({ router, fallback }) {
352
419
  container.appendChild(node);
353
420
  });
354
421
  }
422
+ } catch (thrown) {
423
+ if (lazyFallback) {
424
+ const error = thrown instanceof Error ? thrown : new Error(String(thrown));
425
+ while (container.firstChild) {
426
+ container.removeChild(container.firstChild);
427
+ }
428
+ const fallbackNode = lazyFallback({
429
+ error,
430
+ retry: () => {
431
+ try {
432
+ const retryNode = mod.default();
433
+ if (fallbackNode.parentNode) {
434
+ fallbackNode.parentNode.replaceChild(retryNode, fallbackNode);
435
+ }
436
+ } catch {}
437
+ }
438
+ });
439
+ container.appendChild(fallbackNode);
440
+ } else {
441
+ throw thrown;
442
+ }
355
443
  } finally {
356
444
  popScope();
357
445
  }
358
446
  });
359
447
  } else {
448
+ if (gen !== renderGen) {
449
+ return;
450
+ }
360
451
  __append(container, result);
361
452
  if (getIsHydrating() && !container.contains(result)) {
362
453
  while (container.firstChild) {
@@ -366,7 +457,10 @@ function RouterView({ router, fallback }) {
366
457
  }
367
458
  }
368
459
  });
369
- prevLevels = levels;
460
+ if (gen === renderGen) {
461
+ prevLevels = levels;
462
+ prevParamsKey = currentParamsKey;
463
+ }
370
464
  if (!asyncRoute) {
371
465
  popScope();
372
466
  }
@@ -387,7 +481,7 @@ function buildLevels(matched) {
387
481
  route: m.route
388
482
  }));
389
483
  }
390
- function buildInsideOutFactory(matched, levels, startAt, router) {
484
+ function buildInsideOutFactory(matched, levels, startAt, router, errorFallback) {
391
485
  const ssrCtx = getSSRContext();
392
486
  const wrapForSSR = (route, routeIndex) => {
393
487
  if (!ssrCtx)
@@ -415,12 +509,22 @@ function buildInsideOutFactory(matched, levels, startAt, router) {
415
509
  return result;
416
510
  };
417
511
  };
418
- let factory = wrapForSSR(matched[matched.length - 1].route, matched.length - 1);
512
+ const resolveFallback = (route) => route.errorComponent ?? errorFallback;
513
+ const maybeWrapInBoundary = (componentFn, fb) => {
514
+ if (!fb)
515
+ return componentFn;
516
+ return () => ErrorBoundary({
517
+ children: componentFn,
518
+ fallback: (error, retry) => fb({ error, retry })
519
+ });
520
+ };
521
+ const leafRoute = matched[matched.length - 1].route;
522
+ let factory = maybeWrapInBoundary(wrapForSSR(leafRoute, matched.length - 1), resolveFallback(leafRoute));
419
523
  for (let i = matched.length - 2;i >= startAt; i--) {
420
524
  const level = levels[i];
421
525
  const childFactory = factory;
422
526
  level.childSignal.value = childFactory;
423
- const parentComponent = wrapForSSR(level.route, i);
527
+ const parentComponent = maybeWrapInBoundary(wrapForSSR(level.route, i), resolveFallback(level.route));
424
528
  const cs = level.childSignal;
425
529
  factory = () => {
426
530
  let result;
@@ -451,4 +555,4 @@ function useSearchParams(searchSignal) {
451
555
  return searchSignal.value;
452
556
  }
453
557
 
454
- export { createLink, Link, OutletContext, Outlet, RouterView, parseSearchParams, useSearchParams };
558
+ export { getCurrentErrorHandler, ErrorBoundary, createLink, Link, OutletContext, Outlet, RouterView, parseSearchParams, useSearchParams };