@kodaris/krubble-app-components 1.0.153 → 1.0.154

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.
@@ -12544,6 +12544,46 @@
12544
12544
  window.history.pushState({}, '', fullPath);
12545
12545
  window.dispatchEvent(new PopStateEvent('popstate'));
12546
12546
  }
12547
+ /**
12548
+ * Rewrite the current url in place, keeping the mounted screen as it is — no popstate is dispatched,
12549
+ * so nothing in flight (a streaming response, an open editor) is torn down. For when a screen's url
12550
+ * becomes more specific after a server round-trip: a new chat's first message resolves a conversation
12551
+ * id, a new record's save yields its key.
12552
+ *
12553
+ * Use this instead of a bare history.replaceState. The cache files each screen under its url, so a raw
12554
+ * rewrite would leave the screen keyed by the OLD url: navigating back to that url would be a cache hit
12555
+ * handing back this same screen with all its state — a chat rewritten from `new` to `all/123` would
12556
+ * reopen conversation 123 on the next New Chat click instead of starting fresh. So the deepest level's
12557
+ * cache entry is re-filed under the new url, and its outlet context follows.
12558
+ */
12559
+ static replace(path) {
12560
+ const before = KRRouter.matchRoutes();
12561
+ let fullPath = path;
12562
+ if (!path.startsWith('/')) {
12563
+ fullPath = KRRouter.base + '/' + path;
12564
+ }
12565
+ window.history.replaceState({}, '', fullPath);
12566
+ const after = KRRouter.matchRoutes();
12567
+ if (!before.routes.length || !after.routes.length) {
12568
+ return;
12569
+ }
12570
+ // The caller is the deepest matched screen rewriting its own url; shallower levels keep theirs.
12571
+ const level = before.routes.length - 1;
12572
+ const oldUrl = before.routes[level].url;
12573
+ const newUrl = after.routes[after.routes.length - 1].url;
12574
+ if (oldUrl === newUrl) {
12575
+ return;
12576
+ }
12577
+ const entry = KRRouter.routeCache.get(oldUrl);
12578
+ if (entry) {
12579
+ KRRouter.routeCache.delete(oldUrl);
12580
+ KRRouter.routeCache.set(newUrl, entry);
12581
+ }
12582
+ const context = KRRouter.outletContexts.get(level);
12583
+ if (context && context.url === oldUrl) {
12584
+ context.url = newUrl;
12585
+ }
12586
+ }
12547
12587
  static getParams() {
12548
12588
  const matched = KRRouter.matchRoutes();
12549
12589
  const params = {};