@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.
@@ -9161,6 +9161,7 @@ class ScrollMemory {
9161
9161
  viewport;
9162
9162
  positions = new Map();
9163
9163
  currentKey = '';
9164
+ currentPath = null;
9164
9165
  visited = false;
9165
9166
  restoring = false;
9166
9167
  cancelFrame = null;
@@ -9192,11 +9193,13 @@ class ScrollMemory {
9192
9193
  this.remember(this.currentKey, this.viewport.scrollTop());
9193
9194
  this.persist();
9194
9195
  }
9195
- arrived(uri) {
9196
+ arrived(uri, direction) {
9196
9197
  this.visited = true;
9197
9198
  const { path, hash } = splitUri(uri);
9199
+ const inPage = !!hash && path === this.currentPath && (direction === 'push' || direction === 'replace' || direction === 'traverse');
9200
+ this.currentPath = path;
9198
9201
  this.currentKey = this.keyOf(path);
9199
- this.restore(this.currentKey, this.options.anchor === false ? '' : hash || (this.locationAnchor ? locationHash() : ''));
9202
+ this.restore(this.currentKey, this.options.anchor === false ? '' : hash || (this.locationAnchor ? locationHash() : ''), inPage);
9200
9203
  }
9201
9204
  saved(key) {
9202
9205
  return this.positions.get(this.keyOf(splitUri(key).path)) ?? 0;
@@ -9223,7 +9226,7 @@ class ScrollMemory {
9223
9226
  this.positions.delete(oldest.value);
9224
9227
  }
9225
9228
  }
9226
- restore(key, anchor) {
9229
+ restore(key, anchor, follow) {
9227
9230
  this.cancelRestore();
9228
9231
  const target = this.positions.get(key) ?? 0;
9229
9232
  if (!anchor && target <= 0) {
@@ -9236,7 +9239,7 @@ class ScrollMemory {
9236
9239
  const startedAt = Date.now();
9237
9240
  const attempt = () => {
9238
9241
  this.cancelFrame = null;
9239
- const done = anchor ? this.viewport.scrollToAnchor(anchor) : this.reached(target);
9242
+ const done = anchor ? this.viewport.scrollToAnchor(anchor, follow) : this.reached(target);
9240
9243
  if (done || Date.now() - startedAt >= settleMs) {
9241
9244
  this.cancelRestore();
9242
9245
  this.remember(key, this.viewport.scrollTop());
@@ -9328,16 +9331,30 @@ function windowViewport() {
9328
9331
  },
9329
9332
  scrollTo: (top) => {
9330
9333
  try {
9331
- window.scrollTo(0, top);
9334
+ window.scrollTo({ top, behavior: 'instant' });
9335
+ }
9336
+ catch {
9337
+ try {
9338
+ window.scrollTo(0, top);
9339
+ }
9340
+ catch { }
9332
9341
  }
9333
- catch { }
9334
9342
  },
9335
- scrollToAnchor: (id) => {
9343
+ scrollToAnchor: (id, follow) => {
9336
9344
  try {
9337
9345
  const node = document.getElementById(id);
9338
9346
  if (!node)
9339
9347
  return false;
9340
- node.scrollIntoView();
9348
+ if (follow)
9349
+ node.scrollIntoView();
9350
+ else {
9351
+ try {
9352
+ node.scrollIntoView({ behavior: 'instant' });
9353
+ }
9354
+ catch {
9355
+ node.scrollIntoView();
9356
+ }
9357
+ }
9341
9358
  return true;
9342
9359
  }
9343
9360
  catch {
@@ -9374,11 +9391,16 @@ function containerViewport(container) {
9374
9391
  return;
9375
9392
  }
9376
9393
  try {
9377
- el.scrollTop = top;
9394
+ el.scrollTo({ top, behavior: 'instant' });
9395
+ }
9396
+ catch {
9397
+ try {
9398
+ el.scrollTop = top;
9399
+ }
9400
+ catch { }
9378
9401
  }
9379
- catch { }
9380
9402
  },
9381
- scrollToAnchor: (id) => fallback.scrollToAnchor(id),
9403
+ scrollToAnchor: (id, follow) => fallback.scrollToAnchor(id, follow),
9382
9404
  };
9383
9405
  }
9384
9406
  /** `/docs/x#bolum` → `{ path: '/docs/x', hash: 'bolum' }`. */
@@ -11232,7 +11254,7 @@ class UrlRoutingModule {
11232
11254
  const h = w?.location?.hash || '';
11233
11255
  return h && h.startsWith('#') ? h.slice(1) || '/' : '/';
11234
11256
  }
11235
- return (w?.location?.pathname || '/') + (w?.location?.search || '');
11257
+ return (w?.location?.pathname || '/') + (w?.location?.search || '') + (w?.location?.hash || '');
11236
11258
  }
11237
11259
  catch {
11238
11260
  return '/';
@@ -11507,7 +11529,7 @@ class UrlRoutingModule {
11507
11529
  }
11508
11530
  const snapshotOf = (result) => ({
11509
11531
  target: result,
11510
- chain: result.chain.map(r => this.routingEngine.generatePathString(r.path, result.params) || ''),
11532
+ chain: this.chainOf(result),
11511
11533
  direction,
11512
11534
  state: entryState,
11513
11535
  });
@@ -11551,7 +11573,7 @@ class UrlRoutingModule {
11551
11573
  this._handleScrollBehavior(navOptions.scroll);
11552
11574
  }
11553
11575
  else {
11554
- this._scroll?.arrived(this._uriWithHash(appliedPath, uri));
11576
+ this._scroll?.arrived(this._uriWithHash(appliedPath, uri), direction);
11555
11577
  }
11556
11578
  this.application.fire?.('motifjs-router-navigated', {
11557
11579
  uri: appliedPath,
@@ -11733,6 +11755,9 @@ class UrlRoutingModule {
11733
11755
  }
11734
11756
  return { proceed, uri: urix };
11735
11757
  }
11758
+ chainOf(result) {
11759
+ return result.chain.map(r => this.routingEngine.generatePathString(r.path, result.params) || '');
11760
+ }
11736
11761
  resolve(uri) {
11737
11762
  const candidates = [];
11738
11763
  const pageSearch = this._pageSearch();
@@ -11930,8 +11955,14 @@ class UrlRoutingModule {
11930
11955
  return;
11931
11956
  }
11932
11957
  if (w?.history && typeof w.history.pushState === 'function') {
11933
- const current = (w.location.pathname || '/') + (w.location.search || '');
11934
- if (current !== uri) {
11958
+ const current = (w.location.pathname || '/') + (w.location.search || '') + (w.location.hash || '');
11959
+ let wanted = uri;
11960
+ try {
11961
+ const url = new URL(uri, w.location.href);
11962
+ wanted = url.pathname + url.search + url.hash;
11963
+ }
11964
+ catch { }
11965
+ if (current !== wanted) {
11935
11966
  if (options.replace) {
11936
11967
  const stamp = this._nextHistoryStamp(false);
11937
11968
  w.history.replaceState(this._routerState(options.state, stamp), '', uri);
@@ -12116,15 +12147,19 @@ function createRouter(state, module) {
12116
12147
  return module()?.routeInfos() ?? [];
12117
12148
  },
12118
12149
  navigate: async (uri, options) => {
12119
- await required().navigate(uri, options);
12150
+ return await required().navigate(uri, options);
12120
12151
  },
12121
12152
  navigateByName: async (name, params, options) => {
12122
- await required().navigateByName(name, params, options);
12153
+ return await required().navigateByName(name, params, options);
12123
12154
  },
12124
12155
  evict: async (route) => {
12125
12156
  await required().evict(route);
12126
12157
  },
12127
- resolve: (uri) => required().resolve(uri),
12158
+ resolve: (uri) => {
12159
+ const current = required();
12160
+ const result = current.resolve(uri);
12161
+ return { chain: current.chainOf(result), result };
12162
+ },
12128
12163
  href: (name, params) => required().href(name, params),
12129
12164
  };
12130
12165
  }
@@ -12530,4 +12565,4 @@ function useApplication() {
12530
12565
  }
12531
12566
 
12532
12567
  export { useApplication as $, Application as A, ErrorHandler as B, Component as C, Disposable as D, Emitter as E, FNComponent as F, FragmentNode as G, Frame as H, inject as I, LazyComputed as J, LinkedList as K, Lazy as L, MotifError as M, motifCompiled as N, motifComponent as O, motifFragment as P, NodeTypes as Q, reactive as R, RouterView as S, safeCall as T, safeCallAsync as U, safeCallSilent as V, ServiceCollection as W, ServiceProvider as X, setUnexpectedErrorHandler as Y, Signal as Z, toDisposable as _, reportError as a, useModel as a0, useNavigation as a1, debugGetDeps as a2, debugGetDepMap as a3, UrlRoutingModule as a4, RoutingEngine as a5, RouterState as a6, createRouter as a7, Scanner as a8, RouteCollection as a9, ComponentBase as b, contentBlocks as c, autoRegistry as d, effect as e, findAppendableComponent$1 as f, formatMotifMessage as g, ApplicationBuilder as h, asyncTracking as i, clearModel as j, ComponentMotif as k, Computed as l, motifError as m, notifyDeactivated as n, configureReactivityLeakMonitor as o, ControlCollection as p, createComputed as q, reportWarning as r, createLazyComputed as s, createSignal as t, untracked as u, deepClone as v, disposableCore as w, DisposableStore as x, dom as y, errorHandler as z };
12533
- //# sourceMappingURL=core-vVL0WG0n.esm.js.map
12568
+ //# sourceMappingURL=core-C5z0P3iY.esm.js.map