@kodaris/krubble-app-components 1.0.141 → 1.0.143

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.
@@ -12171,6 +12171,17 @@
12171
12171
  return c > 3 && r && Object.defineProperty(target, key, r), r;
12172
12172
  };
12173
12173
  class KRRouter {
12174
+ /**
12175
+ * The current route's resolved data: everything every matched level's static resolve() returned,
12176
+ * merged with deeper levels winning on a shared key.
12177
+ *
12178
+ * Read it in connectedCallback — the router fills it before any element mounts. A child route gets
12179
+ * what its parent resolved from here, so a tab component needs no resolve() of its own. Use
12180
+ * KRRouter.getParams() for the route's params.
12181
+ */
12182
+ static getData() {
12183
+ return KRRouter.data;
12184
+ }
12174
12185
  static configure(config) {
12175
12186
  KRRouter.base = config.base;
12176
12187
  KRRouter.routes = config.routes;
@@ -12232,40 +12243,61 @@
12232
12243
  }
12233
12244
  }
12234
12245
  const token = ++KRRouter.navToken;
12235
- // Resolve every route's matching component (screen).
12246
+ // Resolve every route's matching component (screen), keeping each level's resolved data alongside
12247
+ // its element so the whole chain can be merged once they've all settled.
12236
12248
  Promise.all(matched.routes.map(match => {
12237
- // Reuse the cached element for this url if we have one
12249
+ // Reuse the cached element for this url if we have one. Its data is cached with it — resolve()
12250
+ // doesn't run again, but the level still has to contribute to the merge below.
12238
12251
  const cached = KRRouter.routeCache.get(match.url);
12239
12252
  if (cached) {
12240
- return Promise.resolve(cached.el);
12253
+ return Promise.resolve({
12254
+ el: cached.el,
12255
+ data: cached.data,
12256
+ });
12241
12257
  }
12242
12258
  // Create and cache the screen element
12243
12259
  const el = document.createElement(match.route.component);
12244
- KRRouter.routeCache.set(match.url, {
12260
+ const entry = {
12245
12261
  el,
12246
12262
  scrolls: [],
12247
- });
12248
- // If the component class defines a static resolve(params), await it and hand the result to the
12249
- // element as `routeSnapshot` = { params, data } before it mounts, so it paints with data instead
12250
- // of flashing empty
12263
+ data: null,
12264
+ };
12265
+ KRRouter.routeCache.set(match.url, entry);
12266
+ // If the component class defines a static resolve(params), await it. Every level's result is
12267
+ // merged into KRRouter.data below before anything mounts, so a component paints with its data
12268
+ // already in hand instead of flashing empty.
12251
12269
  const constructor = customElements.get(match.route.component);
12252
12270
  if (constructor && typeof constructor.resolve === 'function') {
12253
12271
  return Promise.resolve(constructor.resolve(KRRouter.getParams())).then(data => {
12254
- const routeSnapshot = Object.freeze({
12255
- params: match.params,
12272
+ entry.data = data;
12273
+ return {
12274
+ el,
12256
12275
  data,
12257
- });
12258
- el.routeSnapshot = routeSnapshot;
12259
- return el;
12276
+ };
12260
12277
  });
12261
12278
  }
12262
- return Promise.resolve(el);
12279
+ return Promise.resolve({
12280
+ el,
12281
+ data: null,
12282
+ });
12263
12283
  }))
12264
- .then(elements => {
12284
+ .then(resolved => {
12265
12285
  // A newer navigation started while we were resolving — its elements are the current truth.
12266
12286
  if (token !== KRRouter.navToken) {
12267
12287
  return;
12268
12288
  }
12289
+ // Merge the whole chain's resolved data into one object, parents first so a deeper route can
12290
+ // override a key it shares with an ancestor. Set BEFORE any element mounts, so every component
12291
+ // — at any depth — reads it with KRRouter.getData() in connectedCallback: a tab component gets
12292
+ // what its parent resolved with no resolve() of its own and no second request. Mirrors
12293
+ // KNNavigator.data() in kodaris-ngx, which searches the Angular route tree by key.
12294
+ KRRouter.data = {};
12295
+ for (const item of resolved) {
12296
+ if (item.data) {
12297
+ Object.assign(KRRouter.data, item.data);
12298
+ }
12299
+ }
12300
+ const elements = resolved.map(item => item.el);
12269
12301
  // ---- PASS 1: deactivate, deepest level first ----
12270
12302
  // Remove screen elements that no longer apply to the new current routes for the current url
12271
12303
  const levels = Array.from(KRRouter.outletContexts.keys()).sort((a, b) => b - a);
@@ -12538,6 +12570,9 @@
12538
12570
  // One token per navigation. A slower navigation that has been superseded must not activate its
12539
12571
  // (stale) elements, so it checks the token before committing anything.
12540
12572
  KRRouter.navToken = 0;
12573
+ // Every matched route level's resolved data, merged into one object for the current navigation. This
12574
+ // is set before anything mounts — see the merge in handleNavigation.
12575
+ KRRouter.data = {};
12541
12576
  exports.RouterOutlet = class KRRouterOutlet extends i$3 {
12542
12577
  constructor() {
12543
12578
  super(...arguments);