@motifx/core 1.2.0-rc.0 → 1.2.0-rc.2

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.umd.js CHANGED
@@ -10258,6 +10258,7 @@
10258
10258
  viewport;
10259
10259
  positions = new Map();
10260
10260
  currentKey = '';
10261
+ currentPath = null;
10261
10262
  visited = false;
10262
10263
  restoring = false;
10263
10264
  cancelFrame = null;
@@ -10289,11 +10290,13 @@
10289
10290
  this.remember(this.currentKey, this.viewport.scrollTop());
10290
10291
  this.persist();
10291
10292
  }
10292
- arrived(uri) {
10293
+ arrived(uri, direction) {
10293
10294
  this.visited = true;
10294
10295
  const { path, hash } = splitUri(uri);
10296
+ const inPage = !!hash && path === this.currentPath && (direction === 'push' || direction === 'replace' || direction === 'traverse');
10297
+ this.currentPath = path;
10295
10298
  this.currentKey = this.keyOf(path);
10296
- this.restore(this.currentKey, this.options.anchor === false ? '' : hash || (this.locationAnchor ? locationHash() : ''));
10299
+ this.restore(this.currentKey, this.options.anchor === false ? '' : hash || (this.locationAnchor ? locationHash() : ''), inPage);
10297
10300
  }
10298
10301
  saved(key) {
10299
10302
  return this.positions.get(this.keyOf(splitUri(key).path)) ?? 0;
@@ -10320,7 +10323,7 @@
10320
10323
  this.positions.delete(oldest.value);
10321
10324
  }
10322
10325
  }
10323
- restore(key, anchor) {
10326
+ restore(key, anchor, follow) {
10324
10327
  this.cancelRestore();
10325
10328
  const target = this.positions.get(key) ?? 0;
10326
10329
  if (!anchor && target <= 0) {
@@ -10333,7 +10336,7 @@
10333
10336
  const startedAt = Date.now();
10334
10337
  const attempt = () => {
10335
10338
  this.cancelFrame = null;
10336
- const done = anchor ? this.viewport.scrollToAnchor(anchor) : this.reached(target);
10339
+ const done = anchor ? this.viewport.scrollToAnchor(anchor, follow) : this.reached(target);
10337
10340
  if (done || Date.now() - startedAt >= settleMs) {
10338
10341
  this.cancelRestore();
10339
10342
  this.remember(key, this.viewport.scrollTop());
@@ -10425,16 +10428,30 @@
10425
10428
  },
10426
10429
  scrollTo: (top) => {
10427
10430
  try {
10428
- window.scrollTo(0, top);
10431
+ window.scrollTo({ top, behavior: 'instant' });
10432
+ }
10433
+ catch {
10434
+ try {
10435
+ window.scrollTo(0, top);
10436
+ }
10437
+ catch { }
10429
10438
  }
10430
- catch { }
10431
10439
  },
10432
- scrollToAnchor: (id) => {
10440
+ scrollToAnchor: (id, follow) => {
10433
10441
  try {
10434
10442
  const node = document.getElementById(id);
10435
10443
  if (!node)
10436
10444
  return false;
10437
- node.scrollIntoView();
10445
+ if (follow)
10446
+ node.scrollIntoView();
10447
+ else {
10448
+ try {
10449
+ node.scrollIntoView({ behavior: 'instant' });
10450
+ }
10451
+ catch {
10452
+ node.scrollIntoView();
10453
+ }
10454
+ }
10438
10455
  return true;
10439
10456
  }
10440
10457
  catch {
@@ -10471,11 +10488,16 @@
10471
10488
  return;
10472
10489
  }
10473
10490
  try {
10474
- el.scrollTop = top;
10491
+ el.scrollTo({ top, behavior: 'instant' });
10492
+ }
10493
+ catch {
10494
+ try {
10495
+ el.scrollTop = top;
10496
+ }
10497
+ catch { }
10475
10498
  }
10476
- catch { }
10477
10499
  },
10478
- scrollToAnchor: (id) => fallback.scrollToAnchor(id),
10500
+ scrollToAnchor: (id, follow) => fallback.scrollToAnchor(id, follow),
10479
10501
  };
10480
10502
  }
10481
10503
  /** `/docs/x#bolum` → `{ path: '/docs/x', hash: 'bolum' }`. */
@@ -12369,7 +12391,7 @@
12369
12391
  const h = w?.location?.hash || '';
12370
12392
  return h && h.startsWith('#') ? h.slice(1) || '/' : '/';
12371
12393
  }
12372
- return (w?.location?.pathname || '/') + (w?.location?.search || '');
12394
+ return (w?.location?.pathname || '/') + (w?.location?.search || '') + (w?.location?.hash || '');
12373
12395
  }
12374
12396
  catch {
12375
12397
  return '/';
@@ -12644,7 +12666,7 @@
12644
12666
  }
12645
12667
  const snapshotOf = (result) => ({
12646
12668
  target: result,
12647
- chain: result.chain.map(r => this.routingEngine.generatePathString(r.path, result.params) || ''),
12669
+ chain: this.chainOf(result),
12648
12670
  direction,
12649
12671
  state: entryState,
12650
12672
  });
@@ -12688,7 +12710,7 @@
12688
12710
  this._handleScrollBehavior(navOptions.scroll);
12689
12711
  }
12690
12712
  else {
12691
- this._scroll?.arrived(this._uriWithHash(appliedPath, uri));
12713
+ this._scroll?.arrived(this._uriWithHash(appliedPath, uri), direction);
12692
12714
  }
12693
12715
  this.application.fire?.('motifjs-router-navigated', {
12694
12716
  uri: appliedPath,
@@ -12870,6 +12892,9 @@
12870
12892
  }
12871
12893
  return { proceed, uri: urix };
12872
12894
  }
12895
+ chainOf(result) {
12896
+ return result.chain.map(r => this.routingEngine.generatePathString(r.path, result.params) || '');
12897
+ }
12873
12898
  resolve(uri) {
12874
12899
  const candidates = [];
12875
12900
  const pageSearch = this._pageSearch();
@@ -13067,8 +13092,14 @@
13067
13092
  return;
13068
13093
  }
13069
13094
  if (w?.history && typeof w.history.pushState === 'function') {
13070
- const current = (w.location.pathname || '/') + (w.location.search || '');
13071
- if (current !== uri) {
13095
+ const current = (w.location.pathname || '/') + (w.location.search || '') + (w.location.hash || '');
13096
+ let wanted = uri;
13097
+ try {
13098
+ const url = new URL(uri, w.location.href);
13099
+ wanted = url.pathname + url.search + url.hash;
13100
+ }
13101
+ catch { }
13102
+ if (current !== wanted) {
13072
13103
  if (options.replace) {
13073
13104
  const stamp = this._nextHistoryStamp(false);
13074
13105
  w.history.replaceState(this._routerState(options.state, stamp), '', uri);
@@ -13253,15 +13284,19 @@
13253
13284
  return module()?.routeInfos() ?? [];
13254
13285
  },
13255
13286
  navigate: async (uri, options) => {
13256
- await required().navigate(uri, options);
13287
+ return await required().navigate(uri, options);
13257
13288
  },
13258
13289
  navigateByName: async (name, params, options) => {
13259
- await required().navigateByName(name, params, options);
13290
+ return await required().navigateByName(name, params, options);
13260
13291
  },
13261
13292
  evict: async (route) => {
13262
13293
  await required().evict(route);
13263
13294
  },
13264
- resolve: (uri) => required().resolve(uri),
13295
+ resolve: (uri) => {
13296
+ const current = required();
13297
+ const result = current.resolve(uri);
13298
+ return { chain: current.chainOf(result), result };
13299
+ },
13265
13300
  href: (name, params) => required().href(name, params),
13266
13301
  };
13267
13302
  }