@telperion/elements 7.0.0 → 7.1.0
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/.build-manifest.json +1 -1
- package/README.md +5 -5
- package/custom-elements.json +714 -242
- package/fesm/elements.mjs +501 -216
- package/fesm/elements.mjs.map +1 -1
- package/iife/elements.js +36 -36
- package/iife/elements.js.map +1 -1
- package/iife/router/index.js +23 -23
- package/iife/router/index.js.map +1 -1
- package/index.cjs +23 -18
- package/index.cjs.map +1 -1
- package/index.d.cts +1 -1
- package/index.d.ts +1 -1
- package/index.js +8 -6
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/router/history-managed.cjs +1 -1
- package/router/history-managed.cjs.map +1 -1
- package/router/history-managed.js +1 -1
- package/router/history-managed.js.map +1 -1
- package/router/index.cjs +23 -18
- package/router/index.cjs.map +1 -1
- package/router/index.d.cts +273 -168
- package/router/index.d.ts +273 -168
- package/router/index.js +8 -6
- package/router/index.js.map +1 -1
- package/router/route-element.cjs +244 -0
- package/router/route-element.cjs.map +1 -0
- package/router/route-element.js +239 -0
- package/router/route-element.js.map +1 -0
- package/router/route-events.cjs +14 -0
- package/router/route-events.cjs.map +1 -0
- package/router/route-events.js +10 -0
- package/router/route-events.js.map +1 -0
- package/router/route-source.cjs +134 -0
- package/router/route-source.cjs.map +1 -0
- package/router/route-source.js +129 -0
- package/router/route-source.js.map +1 -0
- package/router/route-templates.cjs +18 -0
- package/router/route-templates.cjs.map +1 -0
- package/router/route-templates.js +16 -0
- package/router/route-templates.js.map +1 -0
- package/router/{tha-router-config.cjs → router-config-element.cjs} +51 -51
- package/router/router-config-element.cjs.map +1 -0
- package/router/{tha-router-config.js → router-config-element.js} +52 -52
- package/router/router-config-element.js.map +1 -0
- package/router/{tha-router.cjs → router-element.cjs} +47 -33
- package/router/router-element.cjs.map +1 -0
- package/router/{tha-router.js → router-element.js} +47 -33
- package/router/router-element.js.map +1 -0
- package/router/{tha-router-link.cjs → router-link-element.cjs} +15 -15
- package/router/router-link-element.cjs.map +1 -0
- package/router/{tha-router-link.js → router-link-element.js} +16 -16
- package/router/router-link-element.js.map +1 -0
- package/router/{tha-router-outlet.cjs → router-outlet-element.cjs} +44 -31
- package/router/router-outlet-element.cjs.map +1 -0
- package/router/{tha-router-outlet.js → router-outlet-element.js} +43 -30
- package/router/router-outlet-element.js.map +1 -0
- package/router/{tha-router-param.cjs → router-param-element.cjs} +62 -62
- package/router/router-param-element.cjs.map +1 -0
- package/router/{tha-router-param.js → router-param-element.js} +62 -62
- package/router/router-param-element.js.map +1 -0
- package/router/tha-route.cjs +0 -128
- package/router/tha-route.cjs.map +0 -1
- package/router/tha-route.js +0 -125
- package/router/tha-route.js.map +0 -1
- package/router/tha-router-config.cjs.map +0 -1
- package/router/tha-router-config.js.map +0 -1
- package/router/tha-router-link.cjs.map +0 -1
- package/router/tha-router-link.js.map +0 -1
- package/router/tha-router-outlet.cjs.map +0 -1
- package/router/tha-router-outlet.js.map +0 -1
- package/router/tha-router-param.cjs.map +0 -1
- package/router/tha-router-param.js.map +0 -1
- package/router/tha-router.cjs.map +0 -1
- package/router/tha-router.js.map +0 -1
|
@@ -4,7 +4,7 @@ var tslib = require('tslib');
|
|
|
4
4
|
var decorators_js = require('lit/decorators.js');
|
|
5
5
|
var signalWatcherLitElement = require('../utils/signal-watcher-lit-element.cjs');
|
|
6
6
|
var signals = require('@lit-labs/signals');
|
|
7
|
-
var
|
|
7
|
+
var routerOutletElement = require('./router-outlet-element.cjs');
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @fileoverview Router parameter display component
|
|
@@ -12,14 +12,14 @@ var thaRouterOutlet = require('./tha-router-outlet.cjs');
|
|
|
12
12
|
* Provides a declarative way to display dynamic route parameter values
|
|
13
13
|
* directly in HTML templates without requiring JavaScript.
|
|
14
14
|
*
|
|
15
|
-
* @module router/
|
|
15
|
+
* @module router/tp-router-param
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
18
|
* Custom element for displaying dynamic route parameter values.
|
|
19
19
|
*
|
|
20
20
|
* This component provides a declarative way to access and display URL
|
|
21
21
|
* parameters extracted from dynamic route segments without writing JavaScript.
|
|
22
|
-
* It must be used inside a `<
|
|
22
|
+
* It must be used inside a `<tp-router-outlet>` element.
|
|
23
23
|
*
|
|
24
24
|
* ## Features
|
|
25
25
|
*
|
|
@@ -33,15 +33,15 @@ var thaRouterOutlet = require('./tha-router-outlet.cjs');
|
|
|
33
33
|
* ### Basic Parameter Display
|
|
34
34
|
*
|
|
35
35
|
* ```html
|
|
36
|
-
* <
|
|
37
|
-
* <
|
|
36
|
+
* <tp-router>
|
|
37
|
+
* <tp-route path="/users/:id">
|
|
38
38
|
* <template>
|
|
39
39
|
* <h1>User Profile</h1>
|
|
40
|
-
* <p>User ID: <
|
|
40
|
+
* <p>User ID: <tp-router-param name="id"></tp-router-param></p>
|
|
41
41
|
* </template>
|
|
42
|
-
* </
|
|
43
|
-
* <
|
|
44
|
-
* </
|
|
42
|
+
* </tp-route>
|
|
43
|
+
* <tp-router-outlet></tp-router-outlet>
|
|
44
|
+
* </tp-router>
|
|
45
45
|
* ```
|
|
46
46
|
*
|
|
47
47
|
* When navigating to `/users/123`, the component renders: `User ID: 123`
|
|
@@ -49,19 +49,19 @@ var thaRouterOutlet = require('./tha-router-outlet.cjs');
|
|
|
49
49
|
* ### Multiple Parameters
|
|
50
50
|
*
|
|
51
51
|
* ```html
|
|
52
|
-
* <
|
|
52
|
+
* <tp-route path="/blog/:year/:month/:slug">
|
|
53
53
|
* <template>
|
|
54
54
|
* <article>
|
|
55
55
|
* <header>
|
|
56
56
|
* <time>
|
|
57
|
-
* <
|
|
58
|
-
* <
|
|
57
|
+
* <tp-router-param name="year"></tp-router-param>-
|
|
58
|
+
* <tp-router-param name="month"></tp-router-param>
|
|
59
59
|
* </time>
|
|
60
|
-
* <h1><
|
|
60
|
+
* <h1><tp-router-param name="slug"></tp-router-param></h1>
|
|
61
61
|
* </header>
|
|
62
62
|
* </article>
|
|
63
63
|
* </template>
|
|
64
|
-
* </
|
|
64
|
+
* </tp-route>
|
|
65
65
|
* ```
|
|
66
66
|
*
|
|
67
67
|
* For `/blog/2024/12/hello-world`, renders:
|
|
@@ -73,111 +73,111 @@ var thaRouterOutlet = require('./tha-router-outlet.cjs');
|
|
|
73
73
|
* ### Nested Routes with Parameter Inheritance
|
|
74
74
|
*
|
|
75
75
|
* ```html
|
|
76
|
-
* <
|
|
77
|
-
* <
|
|
76
|
+
* <tp-router>
|
|
77
|
+
* <tp-route path="/projects/:projectId">
|
|
78
78
|
* <template>
|
|
79
|
-
* <h1>Project <
|
|
79
|
+
* <h1>Project <tp-router-param name="projectId"></tp-router-param></h1>
|
|
80
80
|
*
|
|
81
81
|
* <!-- Nested outlet inherits projectId parameter -->
|
|
82
|
-
* <
|
|
83
|
-
* <
|
|
82
|
+
* <tp-router-outlet>
|
|
83
|
+
* <tp-route path="/tasks/:taskId">
|
|
84
84
|
* <template>
|
|
85
85
|
* <!-- Both params are available -->
|
|
86
86
|
* <h2>Task Details</h2>
|
|
87
|
-
* <p>Project: <
|
|
88
|
-
* <p>Task: <
|
|
87
|
+
* <p>Project: <tp-router-param name="projectId"></tp-router-param></p>
|
|
88
|
+
* <p>Task: <tp-router-param name="taskId"></tp-router-param></p>
|
|
89
89
|
* </template>
|
|
90
|
-
* </
|
|
91
|
-
* </
|
|
90
|
+
* </tp-route>
|
|
91
|
+
* </tp-router-outlet>
|
|
92
92
|
* </template>
|
|
93
|
-
* </
|
|
94
|
-
* <
|
|
95
|
-
* </
|
|
93
|
+
* </tp-route>
|
|
94
|
+
* <tp-router-outlet></tp-router-outlet>
|
|
95
|
+
* </tp-router>
|
|
96
96
|
* ```
|
|
97
97
|
*
|
|
98
98
|
* ### With Styling
|
|
99
99
|
*
|
|
100
100
|
* ```html
|
|
101
101
|
* <style>
|
|
102
|
-
*
|
|
102
|
+
* tp-router-param {
|
|
103
103
|
* font-weight: bold;
|
|
104
104
|
* color: var(--primary-color);
|
|
105
105
|
* }
|
|
106
106
|
*
|
|
107
|
-
*
|
|
107
|
+
* tp-router-param[name="id"] {
|
|
108
108
|
* font-family: monospace;
|
|
109
109
|
* }
|
|
110
110
|
* </style>
|
|
111
111
|
*
|
|
112
|
-
* <
|
|
112
|
+
* <tp-route path="/users/:id">
|
|
113
113
|
* <template>
|
|
114
|
-
* <span>User: <
|
|
114
|
+
* <span>User: <tp-router-param name="id"></tp-router-param></span>
|
|
115
115
|
* </template>
|
|
116
|
-
* </
|
|
116
|
+
* </tp-route>
|
|
117
117
|
* ```
|
|
118
118
|
*
|
|
119
119
|
* ## How It Works
|
|
120
120
|
*
|
|
121
|
-
* 1. On connection, finds the nearest parent `<
|
|
121
|
+
* 1. On connection, finds the nearest parent `<tp-router-outlet>`
|
|
122
122
|
* 2. Accesses the outlet's PARAMS signal containing all route parameters
|
|
123
123
|
* 3. Computes and displays the value for the specified parameter name
|
|
124
124
|
* 4. Automatically re-renders when the route (and thus params) change
|
|
125
125
|
*
|
|
126
126
|
* ## Error Handling
|
|
127
127
|
*
|
|
128
|
-
* Throws an error if not placed within a `<
|
|
128
|
+
* Throws an error if not placed within a `<tp-router-outlet>`:
|
|
129
129
|
*
|
|
130
130
|
* ```javascript
|
|
131
131
|
* // ✗ Wrong - not inside outlet
|
|
132
|
-
* <
|
|
132
|
+
* <tp-router-param name="id"></tp-router-param>
|
|
133
133
|
*
|
|
134
134
|
* // ✓ Correct - inside outlet
|
|
135
|
-
* <
|
|
136
|
-
* <
|
|
137
|
-
* </
|
|
135
|
+
* <tp-router-outlet>
|
|
136
|
+
* <tp-router-param name="id"></tp-router-param>
|
|
137
|
+
* </tp-router-outlet>
|
|
138
138
|
* ```
|
|
139
139
|
*
|
|
140
140
|
* ## Alternative: Using Attributes
|
|
141
141
|
*
|
|
142
|
-
* The parent `<
|
|
142
|
+
* The parent `<tp-router-outlet>` also exposes parameters as `param-*` attributes,
|
|
143
143
|
* which can be used as an alternative approach:
|
|
144
144
|
*
|
|
145
145
|
* ```html
|
|
146
|
-
* <
|
|
146
|
+
* <tp-router-outlet id="outlet">
|
|
147
147
|
* <script>
|
|
148
148
|
* const outlet = document.getElementById('outlet');
|
|
149
149
|
* // Params available as: outlet.getAttribute('param-id')
|
|
150
150
|
* </script>
|
|
151
|
-
* </
|
|
151
|
+
* </tp-router-outlet>
|
|
152
152
|
* ```
|
|
153
153
|
*
|
|
154
|
-
* However, `<
|
|
154
|
+
* However, `<tp-router-param>` is preferred for declarative templates.
|
|
155
155
|
*
|
|
156
156
|
* @example Basic usage
|
|
157
157
|
* ```html
|
|
158
|
-
* <
|
|
159
|
-
* <
|
|
158
|
+
* <tp-router>
|
|
159
|
+
* <tp-route path="/product/:sku">
|
|
160
160
|
* <template>
|
|
161
|
-
* <h1>Product: <
|
|
161
|
+
* <h1>Product: <tp-router-param name="sku"></tp-router-param></h1>
|
|
162
162
|
* </template>
|
|
163
|
-
* </
|
|
164
|
-
* <
|
|
165
|
-
* </
|
|
163
|
+
* </tp-route>
|
|
164
|
+
* <tp-router-outlet></tp-router-outlet>
|
|
165
|
+
* </tp-router>
|
|
166
166
|
* ```
|
|
167
167
|
*
|
|
168
168
|
* @example Multiple params with formatting
|
|
169
169
|
* ```html
|
|
170
|
-
* <
|
|
170
|
+
* <tp-route path="/user/:username/post/:postId">
|
|
171
171
|
* <template>
|
|
172
172
|
* <article>
|
|
173
|
-
* <p>@<
|
|
174
|
-
* <p>Post #<
|
|
173
|
+
* <p>@<tp-router-param name="username"></tp-router-param></p>
|
|
174
|
+
* <p>Post #<tp-router-param name="postId"></tp-router-param></p>
|
|
175
175
|
* </article>
|
|
176
176
|
* </template>
|
|
177
|
-
* </
|
|
177
|
+
* </tp-route>
|
|
178
178
|
* ```
|
|
179
179
|
*/
|
|
180
|
-
exports.
|
|
180
|
+
exports.RouterParamElement = class RouterParamElement extends signalWatcherLitElement.SignalWatcherLitElement {
|
|
181
181
|
constructor() {
|
|
182
182
|
super(...arguments);
|
|
183
183
|
/**
|
|
@@ -194,7 +194,7 @@ exports.ThaRouterParam = class ThaRouterParam extends signalWatcherLitElement.Si
|
|
|
194
194
|
* Computed signal that extracts the parameter value.
|
|
195
195
|
* Reactively updates when the outlet's params or name changes.
|
|
196
196
|
*/
|
|
197
|
-
this.#value = signals.computed(() => this.#outlet.get()?.[
|
|
197
|
+
this.#value = signals.computed(() => this.#outlet.get()?.[routerOutletElement.PARAMS]?.get()[this.#name.get()]);
|
|
198
198
|
/**
|
|
199
199
|
* The name of the route parameter to display.
|
|
200
200
|
*
|
|
@@ -224,16 +224,16 @@ exports.ThaRouterParam = class ThaRouterParam extends signalWatcherLitElement.Si
|
|
|
224
224
|
/**
|
|
225
225
|
* Lifecycle callback when element is connected to the DOM.
|
|
226
226
|
*
|
|
227
|
-
* Finds the parent `<
|
|
227
|
+
* Finds the parent `<tp-router-outlet>` and stores a reference.
|
|
228
228
|
* Throws an error if not used within an outlet.
|
|
229
229
|
*
|
|
230
|
-
* @throws {Error} If no parent
|
|
230
|
+
* @throws {Error} If no parent tp-router-outlet is found
|
|
231
231
|
*/
|
|
232
232
|
connectedCallback() {
|
|
233
233
|
super.connectedCallback();
|
|
234
|
-
const outlet = this.closest('
|
|
234
|
+
const outlet = this.closest('tp-router-outlet');
|
|
235
235
|
if (!outlet) {
|
|
236
|
-
throw new Error('<
|
|
236
|
+
throw new Error('<tp-router-param> must be used within a <tp-router-outlet>.');
|
|
237
237
|
}
|
|
238
238
|
this.#outlet.set(outlet);
|
|
239
239
|
}
|
|
@@ -271,8 +271,8 @@ exports.ThaRouterParam = class ThaRouterParam extends signalWatcherLitElement.Si
|
|
|
271
271
|
tslib.__decorate([
|
|
272
272
|
decorators_js.property({ type: String }),
|
|
273
273
|
tslib.__metadata("design:type", String)
|
|
274
|
-
], exports.
|
|
275
|
-
exports.
|
|
276
|
-
decorators_js.customElement('
|
|
277
|
-
], exports.
|
|
278
|
-
//# sourceMappingURL=
|
|
274
|
+
], exports.RouterParamElement.prototype, "name", void 0);
|
|
275
|
+
exports.RouterParamElement = tslib.__decorate([
|
|
276
|
+
decorators_js.customElement('tp-router-param')
|
|
277
|
+
], exports.RouterParamElement);
|
|
278
|
+
//# sourceMappingURL=router-param-element.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-param-element.cjs","sources":["../../../../libs/elements/src/router/router-param-element.ts"],"sourcesContent":[null],"names":["RouterParamElement","SignalWatcherLitElement","signal","computed","PARAMS","html","__decorate","property","customElement"],"mappings":";;;;;;;;AAAA;;;;;;;AAOG;AAmBH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkKG;AAEUA,0BAAkB,GAAxB,MAAM,kBAAmB,SAAQC,+CAAuB,CAAA;AAAxD,IAAA,WAAA,GAAA;;AACL;;;AAGG;AACH,QAAA,IAAA,CAAA,OAAO,GAAGC,cAAM,CAAsB,IAAK,CAAC;AAE5C;;;AAGG;AACH,QAAA,IAAA,CAAA,KAAK,GAAGA,cAAM,CAAS,EAAE,CAAC;AAE1B;;;AAGG;AACH,QAAA,IAAA,CAAA,MAAM,GAAGC,gBAAQ,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAGC,0BAAM,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;AAE9E;;;;;;;;AAQG;QAEH,IAAA,CAAA,IAAI,GAAW,EAAE;IAsDnB;AAlFE;;;AAGG;AACH,IAAA,OAAO;AAEP;;;AAGG;AACH,IAAA,KAAK;AAEL;;;AAGG;AACH,IAAA,MAAM;AAcN;;;;;;;AAOG;IACM,iBAAiB,GAAA;QACxB,KAAK,CAAC,iBAAiB,EAAE;QAEzB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC;QAE/C,IAAI,CAAC,MAAM,EAAE;AACX,YAAA,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC;QAChF;AAEA,QAAA,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;IAC1B;AAEA;;;;;;;;;AASG;AACM,IAAA,wBAAwB,CAAC,IAAY,EAAE,IAAmB,EAAE,KAAoB,EAAA;QACvF,KAAK,CAAC,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC;QAEjD,QAAQ,IAAI;AACV,YAAA,KAAK,MAAM;gBACT,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC3B;;IAEN;AAEA;;;;;;;;AAQG;IACgB,MAAM,GAAA;AACvB,QAAA,OAAOC,YAAI,CAAA,CAAA,EAAG,IAAI,CAAC,MAAM,EAAE;IAC7B;;AArDAC,gBAAA,CAAA;AADC,IAAAC,sBAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;AACT,CAAA,EAAAP,0BAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AA7BPA,0BAAkB,GAAAM,gBAAA,CAAA;IAD9BE,2BAAa,CAAC,iBAAiB;AACnB,CAAA,EAAAR,0BAAkB,CAmF9B;;"}
|
|
@@ -2,7 +2,7 @@ import { __decorate, __metadata } from 'tslib';
|
|
|
2
2
|
import { property, customElement } from 'lit/decorators.js';
|
|
3
3
|
import { SignalWatcherLitElement } from '../utils/signal-watcher-lit-element.js';
|
|
4
4
|
import { signal, computed, html } from '@lit-labs/signals';
|
|
5
|
-
import { PARAMS } from './
|
|
5
|
+
import { PARAMS } from './router-outlet-element.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @fileoverview Router parameter display component
|
|
@@ -10,14 +10,14 @@ import { PARAMS } from './tha-router-outlet.js';
|
|
|
10
10
|
* Provides a declarative way to display dynamic route parameter values
|
|
11
11
|
* directly in HTML templates without requiring JavaScript.
|
|
12
12
|
*
|
|
13
|
-
* @module router/
|
|
13
|
+
* @module router/tp-router-param
|
|
14
14
|
*/
|
|
15
15
|
/**
|
|
16
16
|
* Custom element for displaying dynamic route parameter values.
|
|
17
17
|
*
|
|
18
18
|
* This component provides a declarative way to access and display URL
|
|
19
19
|
* parameters extracted from dynamic route segments without writing JavaScript.
|
|
20
|
-
* It must be used inside a `<
|
|
20
|
+
* It must be used inside a `<tp-router-outlet>` element.
|
|
21
21
|
*
|
|
22
22
|
* ## Features
|
|
23
23
|
*
|
|
@@ -31,15 +31,15 @@ import { PARAMS } from './tha-router-outlet.js';
|
|
|
31
31
|
* ### Basic Parameter Display
|
|
32
32
|
*
|
|
33
33
|
* ```html
|
|
34
|
-
* <
|
|
35
|
-
* <
|
|
34
|
+
* <tp-router>
|
|
35
|
+
* <tp-route path="/users/:id">
|
|
36
36
|
* <template>
|
|
37
37
|
* <h1>User Profile</h1>
|
|
38
|
-
* <p>User ID: <
|
|
38
|
+
* <p>User ID: <tp-router-param name="id"></tp-router-param></p>
|
|
39
39
|
* </template>
|
|
40
|
-
* </
|
|
41
|
-
* <
|
|
42
|
-
* </
|
|
40
|
+
* </tp-route>
|
|
41
|
+
* <tp-router-outlet></tp-router-outlet>
|
|
42
|
+
* </tp-router>
|
|
43
43
|
* ```
|
|
44
44
|
*
|
|
45
45
|
* When navigating to `/users/123`, the component renders: `User ID: 123`
|
|
@@ -47,19 +47,19 @@ import { PARAMS } from './tha-router-outlet.js';
|
|
|
47
47
|
* ### Multiple Parameters
|
|
48
48
|
*
|
|
49
49
|
* ```html
|
|
50
|
-
* <
|
|
50
|
+
* <tp-route path="/blog/:year/:month/:slug">
|
|
51
51
|
* <template>
|
|
52
52
|
* <article>
|
|
53
53
|
* <header>
|
|
54
54
|
* <time>
|
|
55
|
-
* <
|
|
56
|
-
* <
|
|
55
|
+
* <tp-router-param name="year"></tp-router-param>-
|
|
56
|
+
* <tp-router-param name="month"></tp-router-param>
|
|
57
57
|
* </time>
|
|
58
|
-
* <h1><
|
|
58
|
+
* <h1><tp-router-param name="slug"></tp-router-param></h1>
|
|
59
59
|
* </header>
|
|
60
60
|
* </article>
|
|
61
61
|
* </template>
|
|
62
|
-
* </
|
|
62
|
+
* </tp-route>
|
|
63
63
|
* ```
|
|
64
64
|
*
|
|
65
65
|
* For `/blog/2024/12/hello-world`, renders:
|
|
@@ -71,111 +71,111 @@ import { PARAMS } from './tha-router-outlet.js';
|
|
|
71
71
|
* ### Nested Routes with Parameter Inheritance
|
|
72
72
|
*
|
|
73
73
|
* ```html
|
|
74
|
-
* <
|
|
75
|
-
* <
|
|
74
|
+
* <tp-router>
|
|
75
|
+
* <tp-route path="/projects/:projectId">
|
|
76
76
|
* <template>
|
|
77
|
-
* <h1>Project <
|
|
77
|
+
* <h1>Project <tp-router-param name="projectId"></tp-router-param></h1>
|
|
78
78
|
*
|
|
79
79
|
* <!-- Nested outlet inherits projectId parameter -->
|
|
80
|
-
* <
|
|
81
|
-
* <
|
|
80
|
+
* <tp-router-outlet>
|
|
81
|
+
* <tp-route path="/tasks/:taskId">
|
|
82
82
|
* <template>
|
|
83
83
|
* <!-- Both params are available -->
|
|
84
84
|
* <h2>Task Details</h2>
|
|
85
|
-
* <p>Project: <
|
|
86
|
-
* <p>Task: <
|
|
85
|
+
* <p>Project: <tp-router-param name="projectId"></tp-router-param></p>
|
|
86
|
+
* <p>Task: <tp-router-param name="taskId"></tp-router-param></p>
|
|
87
87
|
* </template>
|
|
88
|
-
* </
|
|
89
|
-
* </
|
|
88
|
+
* </tp-route>
|
|
89
|
+
* </tp-router-outlet>
|
|
90
90
|
* </template>
|
|
91
|
-
* </
|
|
92
|
-
* <
|
|
93
|
-
* </
|
|
91
|
+
* </tp-route>
|
|
92
|
+
* <tp-router-outlet></tp-router-outlet>
|
|
93
|
+
* </tp-router>
|
|
94
94
|
* ```
|
|
95
95
|
*
|
|
96
96
|
* ### With Styling
|
|
97
97
|
*
|
|
98
98
|
* ```html
|
|
99
99
|
* <style>
|
|
100
|
-
*
|
|
100
|
+
* tp-router-param {
|
|
101
101
|
* font-weight: bold;
|
|
102
102
|
* color: var(--primary-color);
|
|
103
103
|
* }
|
|
104
104
|
*
|
|
105
|
-
*
|
|
105
|
+
* tp-router-param[name="id"] {
|
|
106
106
|
* font-family: monospace;
|
|
107
107
|
* }
|
|
108
108
|
* </style>
|
|
109
109
|
*
|
|
110
|
-
* <
|
|
110
|
+
* <tp-route path="/users/:id">
|
|
111
111
|
* <template>
|
|
112
|
-
* <span>User: <
|
|
112
|
+
* <span>User: <tp-router-param name="id"></tp-router-param></span>
|
|
113
113
|
* </template>
|
|
114
|
-
* </
|
|
114
|
+
* </tp-route>
|
|
115
115
|
* ```
|
|
116
116
|
*
|
|
117
117
|
* ## How It Works
|
|
118
118
|
*
|
|
119
|
-
* 1. On connection, finds the nearest parent `<
|
|
119
|
+
* 1. On connection, finds the nearest parent `<tp-router-outlet>`
|
|
120
120
|
* 2. Accesses the outlet's PARAMS signal containing all route parameters
|
|
121
121
|
* 3. Computes and displays the value for the specified parameter name
|
|
122
122
|
* 4. Automatically re-renders when the route (and thus params) change
|
|
123
123
|
*
|
|
124
124
|
* ## Error Handling
|
|
125
125
|
*
|
|
126
|
-
* Throws an error if not placed within a `<
|
|
126
|
+
* Throws an error if not placed within a `<tp-router-outlet>`:
|
|
127
127
|
*
|
|
128
128
|
* ```javascript
|
|
129
129
|
* // ✗ Wrong - not inside outlet
|
|
130
|
-
* <
|
|
130
|
+
* <tp-router-param name="id"></tp-router-param>
|
|
131
131
|
*
|
|
132
132
|
* // ✓ Correct - inside outlet
|
|
133
|
-
* <
|
|
134
|
-
* <
|
|
135
|
-
* </
|
|
133
|
+
* <tp-router-outlet>
|
|
134
|
+
* <tp-router-param name="id"></tp-router-param>
|
|
135
|
+
* </tp-router-outlet>
|
|
136
136
|
* ```
|
|
137
137
|
*
|
|
138
138
|
* ## Alternative: Using Attributes
|
|
139
139
|
*
|
|
140
|
-
* The parent `<
|
|
140
|
+
* The parent `<tp-router-outlet>` also exposes parameters as `param-*` attributes,
|
|
141
141
|
* which can be used as an alternative approach:
|
|
142
142
|
*
|
|
143
143
|
* ```html
|
|
144
|
-
* <
|
|
144
|
+
* <tp-router-outlet id="outlet">
|
|
145
145
|
* <script>
|
|
146
146
|
* const outlet = document.getElementById('outlet');
|
|
147
147
|
* // Params available as: outlet.getAttribute('param-id')
|
|
148
148
|
* </script>
|
|
149
|
-
* </
|
|
149
|
+
* </tp-router-outlet>
|
|
150
150
|
* ```
|
|
151
151
|
*
|
|
152
|
-
* However, `<
|
|
152
|
+
* However, `<tp-router-param>` is preferred for declarative templates.
|
|
153
153
|
*
|
|
154
154
|
* @example Basic usage
|
|
155
155
|
* ```html
|
|
156
|
-
* <
|
|
157
|
-
* <
|
|
156
|
+
* <tp-router>
|
|
157
|
+
* <tp-route path="/product/:sku">
|
|
158
158
|
* <template>
|
|
159
|
-
* <h1>Product: <
|
|
159
|
+
* <h1>Product: <tp-router-param name="sku"></tp-router-param></h1>
|
|
160
160
|
* </template>
|
|
161
|
-
* </
|
|
162
|
-
* <
|
|
163
|
-
* </
|
|
161
|
+
* </tp-route>
|
|
162
|
+
* <tp-router-outlet></tp-router-outlet>
|
|
163
|
+
* </tp-router>
|
|
164
164
|
* ```
|
|
165
165
|
*
|
|
166
166
|
* @example Multiple params with formatting
|
|
167
167
|
* ```html
|
|
168
|
-
* <
|
|
168
|
+
* <tp-route path="/user/:username/post/:postId">
|
|
169
169
|
* <template>
|
|
170
170
|
* <article>
|
|
171
|
-
* <p>@<
|
|
172
|
-
* <p>Post #<
|
|
171
|
+
* <p>@<tp-router-param name="username"></tp-router-param></p>
|
|
172
|
+
* <p>Post #<tp-router-param name="postId"></tp-router-param></p>
|
|
173
173
|
* </article>
|
|
174
174
|
* </template>
|
|
175
|
-
* </
|
|
175
|
+
* </tp-route>
|
|
176
176
|
* ```
|
|
177
177
|
*/
|
|
178
|
-
let
|
|
178
|
+
let RouterParamElement = class RouterParamElement extends SignalWatcherLitElement {
|
|
179
179
|
constructor() {
|
|
180
180
|
super(...arguments);
|
|
181
181
|
/**
|
|
@@ -222,16 +222,16 @@ let ThaRouterParam = class ThaRouterParam extends SignalWatcherLitElement {
|
|
|
222
222
|
/**
|
|
223
223
|
* Lifecycle callback when element is connected to the DOM.
|
|
224
224
|
*
|
|
225
|
-
* Finds the parent `<
|
|
225
|
+
* Finds the parent `<tp-router-outlet>` and stores a reference.
|
|
226
226
|
* Throws an error if not used within an outlet.
|
|
227
227
|
*
|
|
228
|
-
* @throws {Error} If no parent
|
|
228
|
+
* @throws {Error} If no parent tp-router-outlet is found
|
|
229
229
|
*/
|
|
230
230
|
connectedCallback() {
|
|
231
231
|
super.connectedCallback();
|
|
232
|
-
const outlet = this.closest('
|
|
232
|
+
const outlet = this.closest('tp-router-outlet');
|
|
233
233
|
if (!outlet) {
|
|
234
|
-
throw new Error('<
|
|
234
|
+
throw new Error('<tp-router-param> must be used within a <tp-router-outlet>.');
|
|
235
235
|
}
|
|
236
236
|
this.#outlet.set(outlet);
|
|
237
237
|
}
|
|
@@ -269,10 +269,10 @@ let ThaRouterParam = class ThaRouterParam extends SignalWatcherLitElement {
|
|
|
269
269
|
__decorate([
|
|
270
270
|
property({ type: String }),
|
|
271
271
|
__metadata("design:type", String)
|
|
272
|
-
],
|
|
273
|
-
|
|
274
|
-
customElement('
|
|
275
|
-
],
|
|
272
|
+
], RouterParamElement.prototype, "name", void 0);
|
|
273
|
+
RouterParamElement = __decorate([
|
|
274
|
+
customElement('tp-router-param')
|
|
275
|
+
], RouterParamElement);
|
|
276
276
|
|
|
277
|
-
export {
|
|
278
|
-
//# sourceMappingURL=
|
|
277
|
+
export { RouterParamElement };
|
|
278
|
+
//# sourceMappingURL=router-param-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-param-element.js","sources":["../../../../libs/elements/src/router/router-param-element.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAAA;;;;;;;AAOG;AAmBH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkKG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,uBAAuB,CAAA;AAAxD,IAAA,WAAA,GAAA;;AACL;;;AAGG;AACH,QAAA,IAAA,CAAA,OAAO,GAAG,MAAM,CAAsB,IAAK,CAAC;AAE5C;;;AAGG;AACH,QAAA,IAAA,CAAA,KAAK,GAAG,MAAM,CAAS,EAAE,CAAC;AAE1B;;;AAGG;AACH,QAAA,IAAA,CAAA,MAAM,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;AAE9E;;;;;;;;AAQG;QAEH,IAAA,CAAA,IAAI,GAAW,EAAE;IAsDnB;AAlFE;;;AAGG;AACH,IAAA,OAAO;AAEP;;;AAGG;AACH,IAAA,KAAK;AAEL;;;AAGG;AACH,IAAA,MAAM;AAcN;;;;;;;AAOG;IACM,iBAAiB,GAAA;QACxB,KAAK,CAAC,iBAAiB,EAAE;QAEzB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC;QAE/C,IAAI,CAAC,MAAM,EAAE;AACX,YAAA,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC;QAChF;AAEA,QAAA,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;IAC1B;AAEA;;;;;;;;;AASG;AACM,IAAA,wBAAwB,CAAC,IAAY,EAAE,IAAmB,EAAE,KAAoB,EAAA;QACvF,KAAK,CAAC,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC;QAEjD,QAAQ,IAAI;AACV,YAAA,KAAK,MAAM;gBACT,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC3B;;IAEN;AAEA;;;;;;;;AAQG;IACgB,MAAM,GAAA;AACvB,QAAA,OAAO,IAAI,CAAA,CAAA,EAAG,IAAI,CAAC,MAAM,EAAE;IAC7B;;AArDA,UAAA,CAAA;AADC,IAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;AACT,CAAA,EAAA,kBAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AA7BP,kBAAkB,GAAA,UAAA,CAAA;IAD9B,aAAa,CAAC,iBAAiB;AACnB,CAAA,EAAA,kBAAkB,CAmF9B;;;;"}
|
package/router/tha-route.cjs
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var tslib = require('tslib');
|
|
4
|
-
var signals = require('@lit-labs/signals');
|
|
5
|
-
var lit = require('lit');
|
|
6
|
-
var decorators_js = require('lit/decorators.js');
|
|
7
|
-
|
|
8
|
-
var _a, _b;
|
|
9
|
-
/**
|
|
10
|
-
* Symbol used to access the route's template fragment signal.
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
const FRAGMENT = Symbol('ThaRoute:fragment');
|
|
14
|
-
/**
|
|
15
|
-
* Symbol used to access the route's URLPattern instance.
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
const PATH_PATTERN = Symbol('ThaRoute:path-pattern');
|
|
19
|
-
/**
|
|
20
|
-
* A custom element that defines a route in the router.
|
|
21
|
-
*
|
|
22
|
-
* Each route contains a template element with the content to render when
|
|
23
|
-
* the route matches the current URL. The router watches for changes to
|
|
24
|
-
* the template content and automatically updates the outlet.
|
|
25
|
-
*
|
|
26
|
-
* The `path` attribute uses URLPattern syntax and supports:
|
|
27
|
-
* - Static paths: `/about`, `/users`
|
|
28
|
-
* - Dynamic segments: `/users/:id`, `/posts/:category/:slug`
|
|
29
|
-
* - Wildcards: `/blog/*`, `/docs/**`
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```html
|
|
33
|
-
* <tha-router>
|
|
34
|
-
* <tha-route path="/">
|
|
35
|
-
* <template><h1>Home Page</h1></template>
|
|
36
|
-
* </tha-route>
|
|
37
|
-
* <tha-route path="/users/:id">
|
|
38
|
-
* <template><h1>User Profile</h1></template>
|
|
39
|
-
* </tha-route>
|
|
40
|
-
* <tha-router-outlet></tha-router-outlet>
|
|
41
|
-
* </tha-router>
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
exports.ThaRoute = class ThaRoute extends lit.LitElement {
|
|
45
|
-
constructor() {
|
|
46
|
-
super(...arguments);
|
|
47
|
-
/**
|
|
48
|
-
* Signal containing weak reference to the template's DocumentFragment.
|
|
49
|
-
* Automatically updates when the template content changes.
|
|
50
|
-
* @internal
|
|
51
|
-
*/
|
|
52
|
-
this[_a] = signals.signal(this.#getTemplateFragment());
|
|
53
|
-
/**
|
|
54
|
-
* URLPattern instance for matching the current URL against this route's path.
|
|
55
|
-
* @internal
|
|
56
|
-
*/
|
|
57
|
-
this[_b] = null;
|
|
58
|
-
/**
|
|
59
|
-
* The URL pattern to match for this route.
|
|
60
|
-
* Uses URLPattern syntax with support for dynamic segments and wildcards.
|
|
61
|
-
*
|
|
62
|
-
* @attr path
|
|
63
|
-
* @example "/users/:id"
|
|
64
|
-
* @example "/blog/*"
|
|
65
|
-
*/
|
|
66
|
-
this.path = null;
|
|
67
|
-
/** Observes changes to child elements to detect template updates */
|
|
68
|
-
this.#templateObserver = new MutationObserver(() => {
|
|
69
|
-
this[FRAGMENT].set(this.#getTemplateFragment());
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
static { _a = FRAGMENT, _b = PATH_PATTERN; }
|
|
73
|
-
/** Observes changes to child elements to detect template updates */
|
|
74
|
-
#templateObserver;
|
|
75
|
-
/**
|
|
76
|
-
* Lifecycle callback when the element is connected to the DOM.
|
|
77
|
-
* Sets up observer to watch for template content changes.
|
|
78
|
-
*/
|
|
79
|
-
connectedCallback() {
|
|
80
|
-
super.connectedCallback();
|
|
81
|
-
this.#templateObserver.observe(this, { childList: true });
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Lifecycle callback when an attribute changes.
|
|
85
|
-
* Updates the URLPattern when the path attribute changes.
|
|
86
|
-
*
|
|
87
|
-
* @param name - The attribute name that changed
|
|
88
|
-
* @param _old - The old attribute value
|
|
89
|
-
* @param value - The new attribute value
|
|
90
|
-
*/
|
|
91
|
-
attributeChangedCallback(name, _old, value) {
|
|
92
|
-
super.attributeChangedCallback(name, _old, value);
|
|
93
|
-
switch (name) {
|
|
94
|
-
case 'path':
|
|
95
|
-
this[PATH_PATTERN] = value ? new URLPattern({ pathname: value }) : null;
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Extracts the DocumentFragment from the template element.
|
|
101
|
-
* Returns a weak reference to prevent memory leaks.
|
|
102
|
-
*
|
|
103
|
-
* @returns Weak reference to the template fragment, or null if no template found
|
|
104
|
-
*/
|
|
105
|
-
#getTemplateFragment() {
|
|
106
|
-
const template = this.querySelector('template');
|
|
107
|
-
return template ? new WeakRef(template.content) : null;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Lifecycle callback when the element is disconnected from the DOM.
|
|
111
|
-
* Cleans up the template observer.
|
|
112
|
-
*/
|
|
113
|
-
disconnectedCallback() {
|
|
114
|
-
super.disconnectedCallback();
|
|
115
|
-
this.#templateObserver.disconnect();
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
tslib.__decorate([
|
|
119
|
-
decorators_js.property({ type: String }),
|
|
120
|
-
tslib.__metadata("design:type", Object)
|
|
121
|
-
], exports.ThaRoute.prototype, "path", void 0);
|
|
122
|
-
exports.ThaRoute = tslib.__decorate([
|
|
123
|
-
decorators_js.customElement('tha-route')
|
|
124
|
-
], exports.ThaRoute);
|
|
125
|
-
|
|
126
|
-
exports.FRAGMENT = FRAGMENT;
|
|
127
|
-
exports.PATH_PATTERN = PATH_PATTERN;
|
|
128
|
-
//# sourceMappingURL=tha-route.cjs.map
|