@kodaris/krubble-app-components 1.0.49 → 1.0.50

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.d.ts CHANGED
@@ -2,7 +2,9 @@ export { KRScaffold } from './scaffold.js';
2
2
  export { KRScreenNav } from './screen-nav.js';
3
3
  export { KRScreenDetail } from './screen-detail.js';
4
4
  export { KRSubbar } from './subbar.js';
5
+ export { KRRouter, KRRouterOutlet } from './router.js';
5
6
  export type { KRSubbarBreadcrumb } from './subbar.js';
6
7
  export type { KRNavItem, KRNavItemFlat, KRUser } from './scaffold.js';
7
8
  export type { KRScreenNavItem } from './screen-nav.js';
9
+ export type { KRRoute, KRRouterConfig, KRMatchedRoute } from './router.js';
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGtD,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACtE,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEvD,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGtD,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACtE,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -3,4 +3,5 @@ export { KRScaffold } from './scaffold.js';
3
3
  export { KRScreenNav } from './screen-nav.js';
4
4
  export { KRScreenDetail } from './screen-detail.js';
5
5
  export { KRSubbar } from './subbar.js';
6
+ export { KRRouter, KRRouterOutlet } from './router.js';
6
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
@@ -65,7 +65,7 @@ const t={ATTRIBUTE:1,CHILD:2},e$2=t=>(...e)=>({_$litDirective$:t,values:e});clas
65
65
  * SPDX-License-Identifier: BSD-3-Clause
66
66
  */const e=e$2(class extends i{constructor(t$1){if(super(t$1),t$1.type!==t.ATTRIBUTE||"class"!==t$1.name||t$1.strings?.length>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(t){return " "+Object.keys(t).filter(s=>t[s]).join(" ")+" "}update(s,[i]){if(void 0===this.st){this.st=new Set,void 0!==s.strings&&(this.nt=new Set(s.strings.join(" ").split(/\s/).filter(t=>""!==t)));for(const t in i)i[t]&&!this.nt?.has(t)&&this.st.add(t);return this.render(i)}const r=s.element.classList;for(const t of this.st)t in i||(r.remove(t),this.st.delete(t));for(const t in i){const s=!!i[t];s===this.st.has(t)||this.nt?.has(t)||(s?(r.add(t),this.st.add(t)):(r.remove(t),this.st.delete(t)));}return E}});
67
67
 
68
- var __decorate$4 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
68
+ var __decorate$5 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
69
69
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
70
70
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
71
71
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -261,23 +261,23 @@ KRNavItemEdit.styles = i$4 `
261
261
  background: #d4f472;
262
262
  }
263
263
  `;
264
- __decorate$4([
264
+ __decorate$5([
265
265
  r()
266
266
  ], KRNavItemEdit.prototype, "label", void 0);
267
- __decorate$4([
267
+ __decorate$5([
268
268
  r()
269
269
  ], KRNavItemEdit.prototype, "icon", void 0);
270
- __decorate$4([
270
+ __decorate$5([
271
271
  r()
272
272
  ], KRNavItemEdit.prototype, "url", void 0);
273
- __decorate$4([
273
+ __decorate$5([
274
274
  r()
275
275
  ], KRNavItemEdit.prototype, "active", void 0);
276
- KRNavItemEdit = __decorate$4([
276
+ KRNavItemEdit = __decorate$5([
277
277
  t$1('kr-nav-item-edit')
278
278
  ], KRNavItemEdit);
279
279
 
280
- var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
280
+ var __decorate$4 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
281
281
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
282
282
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
283
283
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -2120,77 +2120,77 @@ KRScaffold.styles = i$4 `
2120
2120
  }
2121
2121
  }
2122
2122
  `;
2123
- __decorate$3([
2123
+ __decorate$4([
2124
2124
  r()
2125
2125
  ], KRScaffold.prototype, "navItemsExpanded", void 0);
2126
- __decorate$3([
2126
+ __decorate$4([
2127
2127
  r()
2128
2128
  ], KRScaffold.prototype, "navQuery", void 0);
2129
- __decorate$3([
2129
+ __decorate$4([
2130
2130
  r()
2131
2131
  ], KRScaffold.prototype, "activeNavItemId", void 0);
2132
- __decorate$3([
2132
+ __decorate$4([
2133
2133
  r()
2134
2134
  ], KRScaffold.prototype, "isNavScrolled", void 0);
2135
- __decorate$3([
2135
+ __decorate$4([
2136
2136
  r()
2137
2137
  ], KRScaffold.prototype, "isNavOpened", void 0);
2138
- __decorate$3([
2138
+ __decorate$4([
2139
2139
  r()
2140
2140
  ], KRScaffold.prototype, "isEditing", void 0);
2141
- __decorate$3([
2141
+ __decorate$4([
2142
2142
  r()
2143
2143
  ], KRScaffold.prototype, "isUserMenuOpen", void 0);
2144
- __decorate$3([
2144
+ __decorate$4([
2145
2145
  r()
2146
2146
  ], KRScaffold.prototype, "pref", void 0);
2147
- __decorate$3([
2147
+ __decorate$4([
2148
2148
  r()
2149
2149
  ], KRScaffold.prototype, "draggedNavItemId", void 0);
2150
- __decorate$3([
2150
+ __decorate$4([
2151
2151
  r()
2152
2152
  ], KRScaffold.prototype, "navItemDropTargetId", void 0);
2153
- __decorate$3([
2153
+ __decorate$4([
2154
2154
  r()
2155
2155
  ], KRScaffold.prototype, "navItemDropPosition", void 0);
2156
- __decorate$3([
2156
+ __decorate$4([
2157
2157
  r()
2158
2158
  ], KRScaffold.prototype, "pendingRequests", void 0);
2159
- __decorate$3([
2159
+ __decorate$4([
2160
2160
  n({ type: String })
2161
2161
  ], KRScaffold.prototype, "logo", void 0);
2162
- __decorate$3([
2162
+ __decorate$4([
2163
2163
  n({ type: String })
2164
2164
  ], KRScaffold.prototype, "label", void 0);
2165
- __decorate$3([
2165
+ __decorate$4([
2166
2166
  n({ type: String, attribute: 'home-url' })
2167
2167
  ], KRScaffold.prototype, "homeUrl", void 0);
2168
- __decorate$3([
2168
+ __decorate$4([
2169
2169
  n({ type: String, reflect: true })
2170
2170
  ], KRScaffold.prototype, "scheme", void 0);
2171
- __decorate$3([
2171
+ __decorate$4([
2172
2172
  n({ type: Array })
2173
2173
  ], KRScaffold.prototype, "nav", void 0);
2174
- __decorate$3([
2174
+ __decorate$4([
2175
2175
  n({ type: Boolean, attribute: 'nav-icons-displayed', reflect: true })
2176
2176
  ], KRScaffold.prototype, "navIconsDisplayed", void 0);
2177
- __decorate$3([
2177
+ __decorate$4([
2178
2178
  n({ type: Boolean, attribute: 'nav-expanded' })
2179
2179
  ], KRScaffold.prototype, "navExpanded", void 0);
2180
- __decorate$3([
2180
+ __decorate$4([
2181
2181
  n({ type: Object })
2182
2182
  ], KRScaffold.prototype, "user", void 0);
2183
- __decorate$3([
2183
+ __decorate$4([
2184
2184
  n({ type: Boolean })
2185
2185
  ], KRScaffold.prototype, "subbar", void 0);
2186
- __decorate$3([
2186
+ __decorate$4([
2187
2187
  n({ type: Array })
2188
2188
  ], KRScaffold.prototype, "breadcrumbs", void 0);
2189
- KRScaffold = __decorate$3([
2189
+ KRScaffold = __decorate$4([
2190
2190
  t$1('kr-scaffold')
2191
2191
  ], KRScaffold);
2192
2192
 
2193
- var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
2193
+ var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
2194
2194
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2195
2195
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2196
2196
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -2429,23 +2429,23 @@ KRScreenNav.styles = i$4 `
2429
2429
  overflow-y: auto;
2430
2430
  }
2431
2431
  `;
2432
- __decorate$2([
2432
+ __decorate$3([
2433
2433
  n({ type: String })
2434
2434
  ], KRScreenNav.prototype, "label", void 0);
2435
- __decorate$2([
2435
+ __decorate$3([
2436
2436
  n({ type: String })
2437
2437
  ], KRScreenNav.prototype, "subLabel", void 0);
2438
- __decorate$2([
2438
+ __decorate$3([
2439
2439
  n({ type: Array })
2440
2440
  ], KRScreenNav.prototype, "navItems", void 0);
2441
- __decorate$2([
2441
+ __decorate$3([
2442
2442
  n({ type: String })
2443
2443
  ], KRScreenNav.prototype, "activeId", void 0);
2444
- KRScreenNav = __decorate$2([
2444
+ KRScreenNav = __decorate$3([
2445
2445
  t$1('kr-screen-nav')
2446
2446
  ], KRScreenNav);
2447
2447
 
2448
- var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
2448
+ var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
2449
2449
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2450
2450
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2451
2451
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -2539,14 +2539,14 @@ KRScreenDetail.styles = i$4 `
2539
2539
  max-width: 700px;
2540
2540
  }
2541
2541
  `;
2542
- __decorate$1([
2542
+ __decorate$2([
2543
2543
  n({ type: String })
2544
2544
  ], KRScreenDetail.prototype, "title", void 0);
2545
- KRScreenDetail = __decorate$1([
2545
+ KRScreenDetail = __decorate$2([
2546
2546
  t$1('kr-screen-detail')
2547
2547
  ], KRScreenDetail);
2548
2548
 
2549
- var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
2549
+ var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
2550
2550
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2551
2551
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2552
2552
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -2719,15 +2719,200 @@ KRSubbar.styles = i$4 `
2719
2719
  height: 18px;
2720
2720
  }
2721
2721
  `;
2722
- __decorate([
2722
+ __decorate$1([
2723
2723
  n({ type: Array })
2724
2724
  ], KRSubbar.prototype, "breadcrumbs", void 0);
2725
- __decorate([
2725
+ __decorate$1([
2726
2726
  n({ type: Boolean })
2727
2727
  ], KRSubbar.prototype, "menu", void 0);
2728
- KRSubbar = __decorate([
2728
+ KRSubbar = __decorate$1([
2729
2729
  t$1('kr-subbar')
2730
2730
  ], KRSubbar);
2731
2731
 
2732
- export { KRScaffold, KRScreenDetail, KRScreenNav, KRSubbar };
2732
+ var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
2733
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2734
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2735
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2736
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2737
+ };
2738
+ class KRRouter {
2739
+ static configure(config) {
2740
+ KRRouter.base = config.base;
2741
+ KRRouter.routes = config.routes;
2742
+ // Intercept <a> clicks for client-side navigation
2743
+ window.addEventListener('click', (e) => {
2744
+ const anchor = e.composedPath().find(el => el instanceof HTMLAnchorElement);
2745
+ if (!anchor) {
2746
+ return;
2747
+ }
2748
+ if (anchor.origin !== window.location.origin) {
2749
+ return;
2750
+ }
2751
+ if (!anchor.pathname.startsWith(KRRouter.base)) {
2752
+ return;
2753
+ }
2754
+ e.preventDefault();
2755
+ KRRouter.navigate(anchor.pathname);
2756
+ });
2757
+ }
2758
+ static navigate(path) {
2759
+ let fullPath = path;
2760
+ if (!path.startsWith('/')) {
2761
+ fullPath = KRRouter.base + '/' + path;
2762
+ }
2763
+ window.history.pushState({}, '', fullPath);
2764
+ window.dispatchEvent(new PopStateEvent('popstate'));
2765
+ }
2766
+ static getParams() {
2767
+ const matched = KRRouter.matchAll();
2768
+ const params = {};
2769
+ for (const match of matched) {
2770
+ for (const key in match.params) {
2771
+ params[key] = decodeURIComponent(match.params[key]);
2772
+ }
2773
+ }
2774
+ return params;
2775
+ }
2776
+ static outlet(level) {
2777
+ const matched = KRRouter.matchAll();
2778
+ if (level >= matched.length) {
2779
+ return null;
2780
+ }
2781
+ const match = matched[level];
2782
+ const tag = match.route.component;
2783
+ const cached = KRRouter.elementCache.get(level + ':' + tag);
2784
+ if (cached) {
2785
+ return cached;
2786
+ }
2787
+ // Clear old cache entry for this level
2788
+ for (const key of KRRouter.elementCache.keys()) {
2789
+ if (key.startsWith(level + ':')) {
2790
+ KRRouter.elementCache.delete(key);
2791
+ }
2792
+ }
2793
+ const el = document.createElement(tag);
2794
+ KRRouter.elementCache.set(level + ':' + tag, el);
2795
+ return el;
2796
+ }
2797
+ static matchAll() {
2798
+ const path = window.location.pathname;
2799
+ let relative = path;
2800
+ if (path.startsWith(KRRouter.base)) {
2801
+ relative = path.slice(KRRouter.base.length);
2802
+ }
2803
+ const segments = relative.split('/').filter(s => s);
2804
+ return KRRouter.matchRoutes(KRRouter.routes, segments);
2805
+ }
2806
+ static matchRoutes(routes, segments) {
2807
+ for (const route of routes) {
2808
+ const routeSegments = route.path.split('/').filter(s => s);
2809
+ if (routeSegments.length === 0 && segments.length === 0) {
2810
+ return [{ route, params: {} }];
2811
+ }
2812
+ if (routeSegments.length === 0) {
2813
+ continue;
2814
+ }
2815
+ if (segments.length < routeSegments.length) {
2816
+ continue;
2817
+ }
2818
+ const params = {};
2819
+ let matched = true;
2820
+ for (let i = 0; i < routeSegments.length; i++) {
2821
+ if (routeSegments[i].startsWith(':')) {
2822
+ params[routeSegments[i].slice(1)] = segments[i];
2823
+ }
2824
+ else if (routeSegments[i] !== segments[i]) {
2825
+ matched = false;
2826
+ break;
2827
+ }
2828
+ }
2829
+ if (!matched) {
2830
+ continue;
2831
+ }
2832
+ const remaining = segments.slice(routeSegments.length);
2833
+ // If there are remaining segments but no children, this route doesn't fully match — try next route
2834
+ if (remaining.length > 0 && !route.children) {
2835
+ continue;
2836
+ }
2837
+ const result = [{ route, params }];
2838
+ if (route.children && remaining.length > 0) {
2839
+ const childMatches = KRRouter.matchRoutes(route.children, remaining);
2840
+ if (childMatches.length > 0) {
2841
+ result.push(...childMatches);
2842
+ return result;
2843
+ }
2844
+ }
2845
+ // No remaining segments + default child — redirect
2846
+ if (route.children && remaining.length === 0 && route.default) {
2847
+ window.history.replaceState({}, '', window.location.pathname + '/' + route.default);
2848
+ const childMatches = KRRouter.matchRoutes(route.children, [route.default]);
2849
+ if (childMatches.length > 0) {
2850
+ result.push(...childMatches);
2851
+ return result;
2852
+ }
2853
+ }
2854
+ return result;
2855
+ }
2856
+ return [];
2857
+ }
2858
+ }
2859
+ KRRouter.base = '';
2860
+ KRRouter.routes = [];
2861
+ KRRouter.elementCache = new Map();
2862
+ let KRRouterOutlet = class KRRouterOutlet extends i$1 {
2863
+ constructor() {
2864
+ super(...arguments);
2865
+ this.level = -1;
2866
+ this.handlePopState = () => {
2867
+ this.requestUpdate();
2868
+ };
2869
+ }
2870
+ connectedCallback() {
2871
+ super.connectedCallback();
2872
+ this.level = this.detectLevel();
2873
+ window.addEventListener('popstate', this.handlePopState);
2874
+ }
2875
+ disconnectedCallback() {
2876
+ super.disconnectedCallback();
2877
+ window.removeEventListener('popstate', this.handlePopState);
2878
+ }
2879
+ detectLevel() {
2880
+ let level = 0;
2881
+ let node = this;
2882
+ while (node) {
2883
+ if (node instanceof ShadowRoot) {
2884
+ node = node.host;
2885
+ continue;
2886
+ }
2887
+ if (node instanceof HTMLElement && node.tagName === 'KR-ROUTER-OUTLET' && node !== this) {
2888
+ level++;
2889
+ }
2890
+ if (node instanceof HTMLElement) {
2891
+ node = node.parentNode;
2892
+ }
2893
+ else {
2894
+ node = null;
2895
+ }
2896
+ }
2897
+ return level;
2898
+ }
2899
+ render() {
2900
+ const el = KRRouter.outlet(this.level);
2901
+ if (!el) {
2902
+ return b ``;
2903
+ }
2904
+ return b `${el}`;
2905
+ }
2906
+ };
2907
+ KRRouterOutlet.styles = i$4 `
2908
+ :host {
2909
+ display: block;
2910
+ height: 100%;
2911
+ }
2912
+ `;
2913
+ KRRouterOutlet = __decorate([
2914
+ t$1('kr-router-outlet')
2915
+ ], KRRouterOutlet);
2916
+
2917
+ export { KRRouter, KRRouterOutlet, KRScaffold, KRScreenDetail, KRScreenNav, KRSubbar };
2733
2918
  //# sourceMappingURL=krubble-app.bundled.js.map