@telperion/elements 1.0.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/LICENSE +21 -0
- package/README.md +102 -0
- package/bundle.js +164 -0
- package/bundle.mjs +2630 -0
- package/drag-drop/drag-element.cjs +438 -0
- package/drag-drop/drag-element.d.ts +120 -0
- package/drag-drop/drag-element.js +437 -0
- package/drag-drop/drag-element.js.map +1 -0
- package/drag-drop/drag-handle-element.cjs +35 -0
- package/drag-drop/drag-handle-element.d.ts +12 -0
- package/drag-drop/drag-handle-element.js +34 -0
- package/drag-drop/drag-handle-element.js.map +1 -0
- package/drag-drop/dropzone-element.cjs +117 -0
- package/drag-drop/dropzone-element.d.ts +17 -0
- package/drag-drop/dropzone-element.js +116 -0
- package/drag-drop/dropzone-element.js.map +1 -0
- package/drag-drop/index.cjs +11 -0
- package/drag-drop/index.d.ts +22 -0
- package/drag-drop/index.js +6 -0
- package/drag-drop/index.js.map +1 -0
- package/drag-drop/private-props.cjs +6 -0
- package/drag-drop/private-props.d.ts +3 -0
- package/drag-drop/private-props.js +5 -0
- package/drag-drop/private-props.js.map +1 -0
- package/drag-drop/tha-drag-event.cjs +34 -0
- package/drag-drop/tha-drag-event.d.ts +19 -0
- package/drag-drop/tha-drag-event.js +32 -0
- package/drag-drop/tha-drag-event.js.map +1 -0
- package/icon/icon-element.cjs +114 -0
- package/icon/icon-element.d.ts +40 -0
- package/icon/icon-element.js +113 -0
- package/icon/icon-element.js.map +1 -0
- package/icon/index.cjs +5 -0
- package/icon/index.d.ts +1 -0
- package/icon/index.js +3 -0
- package/icon/index.js.map +1 -0
- package/icon/material-symbols.css +22 -0
- package/index.cjs +11 -0
- package/index.d.ts +6 -0
- package/index.js +10 -0
- package/index.js.map +1 -0
- package/package.json +127 -0
- package/router/history-managed.cjs +97 -0
- package/router/history-managed.d.ts +76 -0
- package/router/history-managed.js +95 -0
- package/router/history-managed.js.map +1 -0
- package/router/history.cjs +65 -0
- package/router/history.d.ts +48 -0
- package/router/history.js +63 -0
- package/router/history.js.map +1 -0
- package/router/index.cjs +15 -0
- package/router/index.d.ts +6 -0
- package/router/index.js +8 -0
- package/router/index.js.map +1 -0
- package/router/signal-watcher-lit-element.cjs +11 -0
- package/router/signal-watcher-lit-element.d.ts +25 -0
- package/router/signal-watcher-lit-element.js +10 -0
- package/router/signal-watcher-lit-element.js.map +1 -0
- package/router/tha-route.cjs +125 -0
- package/router/tha-route.d.ts +90 -0
- package/router/tha-route.js +124 -0
- package/router/tha-route.js.map +1 -0
- package/router/tha-router-config.cjs +241 -0
- package/router/tha-router-config.d.ts +223 -0
- package/router/tha-router-config.js +240 -0
- package/router/tha-router-config.js.map +1 -0
- package/router/tha-router-link.cjs +209 -0
- package/router/tha-router-link.d.ts +95 -0
- package/router/tha-router-link.js +208 -0
- package/router/tha-router-link.js.map +1 -0
- package/router/tha-router-outlet.cjs +215 -0
- package/router/tha-router-outlet.d.ts +112 -0
- package/router/tha-router-outlet.js +214 -0
- package/router/tha-router-outlet.js.map +1 -0
- package/router/tha-router-param.cjs +278 -0
- package/router/tha-router-param.d.ts +226 -0
- package/router/tha-router-param.js +277 -0
- package/router/tha-router-param.js.map +1 -0
- package/router/tha-router.cjs +163 -0
- package/router/tha-router.d.ts +69 -0
- package/router/tha-router.js +162 -0
- package/router/tha-router.js.map +1 -0
- package/tha-url-output.cjs +79 -0
- package/tha-url-output.d.ts +41 -0
- package/tha-url-output.js +78 -0
- package/tha-url-output.js.map +1 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ThaRouterConfig = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const decorators_js_1 = require("lit/decorators.js");
|
|
6
|
+
const history_1 = require("./history");
|
|
7
|
+
const history_managed_1 = require("./history-managed");
|
|
8
|
+
const signal_watcher_lit_element_1 = require("./signal-watcher-lit-element");
|
|
9
|
+
const noop_1 = require("@telperion/js-utils/function/noop");
|
|
10
|
+
/**
|
|
11
|
+
* A custom element for configuring router history settings.
|
|
12
|
+
*
|
|
13
|
+
* This element serves dual purposes depending on its placement in the DOM:
|
|
14
|
+
*
|
|
15
|
+
* ## Global Configuration (placed in `<head>`)
|
|
16
|
+
*
|
|
17
|
+
* When placed in the `<head>` element, it sets the **global default history**
|
|
18
|
+
* for all routers in the application that don't specify their own history or
|
|
19
|
+
* inherit from a parent.
|
|
20
|
+
*
|
|
21
|
+
* ```html
|
|
22
|
+
* <head>
|
|
23
|
+
* <!-- All routers will use hash routing by default -->
|
|
24
|
+
* <tha-router-config history="hash"></tha-router-config>
|
|
25
|
+
* </head>
|
|
26
|
+
* <body>
|
|
27
|
+
* <tha-router>
|
|
28
|
+
* <!-- Uses hash history (global default) -->
|
|
29
|
+
* <tha-route path="/home">...</tha-route>
|
|
30
|
+
* </tha-router>
|
|
31
|
+
* </body>
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* ## Local Configuration (placed in `<body>`)
|
|
35
|
+
*
|
|
36
|
+
* When placed in the `<body>` element, it provides history configuration
|
|
37
|
+
* for its **descendant routers only**. This allows different sections of
|
|
38
|
+
* your application to use different history strategies.
|
|
39
|
+
*
|
|
40
|
+
* ```html
|
|
41
|
+
* <body>
|
|
42
|
+
* <!-- Section 1: Hash routing -->
|
|
43
|
+
* <tha-router-config history="hash">
|
|
44
|
+
* <tha-router>
|
|
45
|
+
* <!-- Uses hash history from parent config -->
|
|
46
|
+
* <tha-route path="/dashboard">...</tha-route>
|
|
47
|
+
* </tha-router>
|
|
48
|
+
* </tha-router-config>
|
|
49
|
+
*
|
|
50
|
+
* <!-- Section 2: Memory routing (isolated) -->
|
|
51
|
+
* <tha-router-config history="memory">
|
|
52
|
+
* <tha-router>
|
|
53
|
+
* <!-- Uses memory history from parent config -->
|
|
54
|
+
* <tha-route path="/preview">...</tha-route>
|
|
55
|
+
* </tha-router>
|
|
56
|
+
* </tha-router-config>
|
|
57
|
+
* </body>
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* ## Usage Patterns
|
|
61
|
+
*
|
|
62
|
+
* ### Set Global Default
|
|
63
|
+
*
|
|
64
|
+
* Place in `<head>` to configure all routers:
|
|
65
|
+
*
|
|
66
|
+
* ```html
|
|
67
|
+
* <!DOCTYPE html>
|
|
68
|
+
* <html>
|
|
69
|
+
* <head>
|
|
70
|
+
* <tha-router-config history="browser"></tha-router-config>
|
|
71
|
+
* </head>
|
|
72
|
+
* <body>
|
|
73
|
+
* <!-- All routers use browser history -->
|
|
74
|
+
* </body>
|
|
75
|
+
* </html>
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* ### Override for Specific Section
|
|
79
|
+
*
|
|
80
|
+
* Use local config to override global default:
|
|
81
|
+
*
|
|
82
|
+
* ```html
|
|
83
|
+
* <head>
|
|
84
|
+
* <!-- Global: browser history -->
|
|
85
|
+
* <tha-router-config history="browser"></tha-router-config>
|
|
86
|
+
* </head>
|
|
87
|
+
* <body>
|
|
88
|
+
* <!-- Main app uses browser history -->
|
|
89
|
+
* <tha-router>...</tha-router>
|
|
90
|
+
*
|
|
91
|
+
* <!-- Admin section uses hash history -->
|
|
92
|
+
* <tha-router-config history="hash">
|
|
93
|
+
* <tha-router>...</tha-router>
|
|
94
|
+
* </tha-router-config>
|
|
95
|
+
* </body>
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* ### Isolate Components with Memory History
|
|
99
|
+
*
|
|
100
|
+
* Use named memory history for component isolation:
|
|
101
|
+
*
|
|
102
|
+
* ```html
|
|
103
|
+
* <body>
|
|
104
|
+
* <!-- Each component has independent navigation -->
|
|
105
|
+
* <tha-router-config history="memory:component1">
|
|
106
|
+
* <my-widget>
|
|
107
|
+
* <tha-router>...</tha-router>
|
|
108
|
+
* </my-widget>
|
|
109
|
+
* </tha-router-config>
|
|
110
|
+
*
|
|
111
|
+
* <tha-router-config history="memory:component2">
|
|
112
|
+
* <my-widget>
|
|
113
|
+
* <tha-router>...</tha-router>
|
|
114
|
+
* </my-widget>
|
|
115
|
+
* </tha-router-config>
|
|
116
|
+
* </body>
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* ### Testing with Memory History
|
|
120
|
+
*
|
|
121
|
+
* Use memory history to avoid affecting browser URL during tests:
|
|
122
|
+
*
|
|
123
|
+
* ```typescript
|
|
124
|
+
* import { fixture, html } from '@open-wc/testing';
|
|
125
|
+
*
|
|
126
|
+
* it('should navigate', async () => {
|
|
127
|
+
* const el = await fixture(html`
|
|
128
|
+
* <tha-router-config history="memory:test">
|
|
129
|
+
* <tha-router>
|
|
130
|
+
* <tha-route path="/test">Test Page</tha-route>
|
|
131
|
+
* </tha-router>
|
|
132
|
+
* </tha-router-config>
|
|
133
|
+
* `);
|
|
134
|
+
*
|
|
135
|
+
* // Test navigation without affecting browser URL
|
|
136
|
+
* });
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* ## History Resolution
|
|
140
|
+
*
|
|
141
|
+
* Router components resolve their history in this order:
|
|
142
|
+
*
|
|
143
|
+
* 1. **Own `history` attribute** (highest priority)
|
|
144
|
+
* 2. **Parent `tha-router-config`** (local configuration)
|
|
145
|
+
* 3. **Global `tha-router-config`** (in `<head>`)
|
|
146
|
+
* 4. **Default** (`"browser"`)
|
|
147
|
+
*
|
|
148
|
+
* ## Best Practices
|
|
149
|
+
*
|
|
150
|
+
* ✅ **DO**: Place one `tha-router-config` in `<head>` for global settings
|
|
151
|
+
*
|
|
152
|
+
* ```html
|
|
153
|
+
* <head>
|
|
154
|
+
* <tha-router-config history="browser"></tha-router-config>
|
|
155
|
+
* </head>
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* ✅ **DO**: Use local configs for sections with different routing needs
|
|
159
|
+
*
|
|
160
|
+
* ```html
|
|
161
|
+
* <tha-router-config history="memory">
|
|
162
|
+
* <component-preview>...</component-preview>
|
|
163
|
+
* </tha-router-config>
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* ✅ **DO**: Use named memory history for isolated components
|
|
167
|
+
*
|
|
168
|
+
* ```html
|
|
169
|
+
* <tha-router-config history="memory:sidebar">
|
|
170
|
+
* <sidebar-nav>...</sidebar-nav>
|
|
171
|
+
* </tha-router-config>
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* ❌ **DON'T**: Place multiple configs in `<head>` (last one wins)
|
|
175
|
+
*
|
|
176
|
+
* ```html
|
|
177
|
+
* <head>
|
|
178
|
+
* <tha-router-config history="browser"></tha-router-config>
|
|
179
|
+
* <tha-router-config history="hash"></tha-router-config> <!-- Overrides above -->
|
|
180
|
+
* </head>
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* ❌ **DON'T**: Nest configs unnecessarily (inner configs take precedence)
|
|
184
|
+
*
|
|
185
|
+
* ```html
|
|
186
|
+
* <tha-router-config history="browser">
|
|
187
|
+
* <tha-router-config history="hash">
|
|
188
|
+
* <!-- Uses hash, not browser -->
|
|
189
|
+
* </tha-router-config>
|
|
190
|
+
* </tha-router-config>
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
let ThaRouterConfig = class ThaRouterConfig extends (0, history_managed_1.HistoryManaged)(signal_watcher_lit_element_1.SignalWatcherLitElement) {
|
|
194
|
+
/**
|
|
195
|
+
* Cleanup function for the global history effect.
|
|
196
|
+
* Only used when the element is placed in `<head>`.
|
|
197
|
+
* @private
|
|
198
|
+
*/
|
|
199
|
+
#globalHistoryUnsubscribe = noop_1.noop;
|
|
200
|
+
/**
|
|
201
|
+
* Called when the element is connected to the DOM.
|
|
202
|
+
*
|
|
203
|
+
* - If in `<head>`: Sets up a reactive effect to update global history
|
|
204
|
+
* - If in `<body>`: Only provides history to descendants (no special setup)
|
|
205
|
+
*/
|
|
206
|
+
connectedCallback() {
|
|
207
|
+
super.connectedCallback();
|
|
208
|
+
if (!document.head.contains(this))
|
|
209
|
+
return;
|
|
210
|
+
console.log('ThaRouterConfig: Setting global history type to', this[history_managed_1.HISTORY_TYPE].get());
|
|
211
|
+
// Set the global history type when this element is connected in <head>
|
|
212
|
+
this.#globalHistoryUnsubscribe = this.updateEffect(() => {
|
|
213
|
+
history_1.GLOBAL_HISTORY_TYPE.set(this[history_managed_1.HISTORY_TYPE].get());
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Called when the element is disconnected from the DOM.
|
|
218
|
+
*
|
|
219
|
+
* Cleans up the global history effect if it was set up.
|
|
220
|
+
*/
|
|
221
|
+
disconnectedCallback() {
|
|
222
|
+
super.disconnectedCallback();
|
|
223
|
+
try {
|
|
224
|
+
this.#globalHistoryUnsubscribe();
|
|
225
|
+
}
|
|
226
|
+
catch { }
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Creates the render root for the element.
|
|
230
|
+
* Returns the element itself to render children in light DOM.
|
|
231
|
+
*
|
|
232
|
+
* @returns The element itself (not a shadow root)
|
|
233
|
+
*/
|
|
234
|
+
createRenderRoot() {
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
exports.ThaRouterConfig = ThaRouterConfig;
|
|
239
|
+
exports.ThaRouterConfig = ThaRouterConfig = tslib_1.__decorate([
|
|
240
|
+
(0, decorators_js_1.customElement)('tha-router-config')
|
|
241
|
+
], ThaRouterConfig);
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
declare global {
|
|
3
|
+
interface HTMLElementTagNameMap {
|
|
4
|
+
/**
|
|
5
|
+
* A configuration element for managing router history settings.
|
|
6
|
+
*
|
|
7
|
+
* Behavior depends on placement:
|
|
8
|
+
* - **In `<head>`**: Sets global history for all routers
|
|
9
|
+
* - **In `<body>`**: Provides local history for descendant routers
|
|
10
|
+
*/
|
|
11
|
+
"tha-router-config": ThaRouterConfig;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
declare const ThaRouterConfig_base: (new (...args: any[]) => import("./history-managed").HistoryManagedLitElementType) & (new () => LitElement & {
|
|
15
|
+
updateEffect(fn: () => void, options?: import("./signal-watcher-lit-element").EffectOptions): () => void;
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* A custom element for configuring router history settings.
|
|
19
|
+
*
|
|
20
|
+
* This element serves dual purposes depending on its placement in the DOM:
|
|
21
|
+
*
|
|
22
|
+
* ## Global Configuration (placed in `<head>`)
|
|
23
|
+
*
|
|
24
|
+
* When placed in the `<head>` element, it sets the **global default history**
|
|
25
|
+
* for all routers in the application that don't specify their own history or
|
|
26
|
+
* inherit from a parent.
|
|
27
|
+
*
|
|
28
|
+
* ```html
|
|
29
|
+
* <head>
|
|
30
|
+
* <!-- All routers will use hash routing by default -->
|
|
31
|
+
* <tha-router-config history="hash"></tha-router-config>
|
|
32
|
+
* </head>
|
|
33
|
+
* <body>
|
|
34
|
+
* <tha-router>
|
|
35
|
+
* <!-- Uses hash history (global default) -->
|
|
36
|
+
* <tha-route path="/home">...</tha-route>
|
|
37
|
+
* </tha-router>
|
|
38
|
+
* </body>
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* ## Local Configuration (placed in `<body>`)
|
|
42
|
+
*
|
|
43
|
+
* When placed in the `<body>` element, it provides history configuration
|
|
44
|
+
* for its **descendant routers only**. This allows different sections of
|
|
45
|
+
* your application to use different history strategies.
|
|
46
|
+
*
|
|
47
|
+
* ```html
|
|
48
|
+
* <body>
|
|
49
|
+
* <!-- Section 1: Hash routing -->
|
|
50
|
+
* <tha-router-config history="hash">
|
|
51
|
+
* <tha-router>
|
|
52
|
+
* <!-- Uses hash history from parent config -->
|
|
53
|
+
* <tha-route path="/dashboard">...</tha-route>
|
|
54
|
+
* </tha-router>
|
|
55
|
+
* </tha-router-config>
|
|
56
|
+
*
|
|
57
|
+
* <!-- Section 2: Memory routing (isolated) -->
|
|
58
|
+
* <tha-router-config history="memory">
|
|
59
|
+
* <tha-router>
|
|
60
|
+
* <!-- Uses memory history from parent config -->
|
|
61
|
+
* <tha-route path="/preview">...</tha-route>
|
|
62
|
+
* </tha-router>
|
|
63
|
+
* </tha-router-config>
|
|
64
|
+
* </body>
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* ## Usage Patterns
|
|
68
|
+
*
|
|
69
|
+
* ### Set Global Default
|
|
70
|
+
*
|
|
71
|
+
* Place in `<head>` to configure all routers:
|
|
72
|
+
*
|
|
73
|
+
* ```html
|
|
74
|
+
* <!DOCTYPE html>
|
|
75
|
+
* <html>
|
|
76
|
+
* <head>
|
|
77
|
+
* <tha-router-config history="browser"></tha-router-config>
|
|
78
|
+
* </head>
|
|
79
|
+
* <body>
|
|
80
|
+
* <!-- All routers use browser history -->
|
|
81
|
+
* </body>
|
|
82
|
+
* </html>
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* ### Override for Specific Section
|
|
86
|
+
*
|
|
87
|
+
* Use local config to override global default:
|
|
88
|
+
*
|
|
89
|
+
* ```html
|
|
90
|
+
* <head>
|
|
91
|
+
* <!-- Global: browser history -->
|
|
92
|
+
* <tha-router-config history="browser"></tha-router-config>
|
|
93
|
+
* </head>
|
|
94
|
+
* <body>
|
|
95
|
+
* <!-- Main app uses browser history -->
|
|
96
|
+
* <tha-router>...</tha-router>
|
|
97
|
+
*
|
|
98
|
+
* <!-- Admin section uses hash history -->
|
|
99
|
+
* <tha-router-config history="hash">
|
|
100
|
+
* <tha-router>...</tha-router>
|
|
101
|
+
* </tha-router-config>
|
|
102
|
+
* </body>
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* ### Isolate Components with Memory History
|
|
106
|
+
*
|
|
107
|
+
* Use named memory history for component isolation:
|
|
108
|
+
*
|
|
109
|
+
* ```html
|
|
110
|
+
* <body>
|
|
111
|
+
* <!-- Each component has independent navigation -->
|
|
112
|
+
* <tha-router-config history="memory:component1">
|
|
113
|
+
* <my-widget>
|
|
114
|
+
* <tha-router>...</tha-router>
|
|
115
|
+
* </my-widget>
|
|
116
|
+
* </tha-router-config>
|
|
117
|
+
*
|
|
118
|
+
* <tha-router-config history="memory:component2">
|
|
119
|
+
* <my-widget>
|
|
120
|
+
* <tha-router>...</tha-router>
|
|
121
|
+
* </my-widget>
|
|
122
|
+
* </tha-router-config>
|
|
123
|
+
* </body>
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* ### Testing with Memory History
|
|
127
|
+
*
|
|
128
|
+
* Use memory history to avoid affecting browser URL during tests:
|
|
129
|
+
*
|
|
130
|
+
* ```typescript
|
|
131
|
+
* import { fixture, html } from '@open-wc/testing';
|
|
132
|
+
*
|
|
133
|
+
* it('should navigate', async () => {
|
|
134
|
+
* const el = await fixture(html`
|
|
135
|
+
* <tha-router-config history="memory:test">
|
|
136
|
+
* <tha-router>
|
|
137
|
+
* <tha-route path="/test">Test Page</tha-route>
|
|
138
|
+
* </tha-router>
|
|
139
|
+
* </tha-router-config>
|
|
140
|
+
* `);
|
|
141
|
+
*
|
|
142
|
+
* // Test navigation without affecting browser URL
|
|
143
|
+
* });
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* ## History Resolution
|
|
147
|
+
*
|
|
148
|
+
* Router components resolve their history in this order:
|
|
149
|
+
*
|
|
150
|
+
* 1. **Own `history` attribute** (highest priority)
|
|
151
|
+
* 2. **Parent `tha-router-config`** (local configuration)
|
|
152
|
+
* 3. **Global `tha-router-config`** (in `<head>`)
|
|
153
|
+
* 4. **Default** (`"browser"`)
|
|
154
|
+
*
|
|
155
|
+
* ## Best Practices
|
|
156
|
+
*
|
|
157
|
+
* ✅ **DO**: Place one `tha-router-config` in `<head>` for global settings
|
|
158
|
+
*
|
|
159
|
+
* ```html
|
|
160
|
+
* <head>
|
|
161
|
+
* <tha-router-config history="browser"></tha-router-config>
|
|
162
|
+
* </head>
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* ✅ **DO**: Use local configs for sections with different routing needs
|
|
166
|
+
*
|
|
167
|
+
* ```html
|
|
168
|
+
* <tha-router-config history="memory">
|
|
169
|
+
* <component-preview>...</component-preview>
|
|
170
|
+
* </tha-router-config>
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* ✅ **DO**: Use named memory history for isolated components
|
|
174
|
+
*
|
|
175
|
+
* ```html
|
|
176
|
+
* <tha-router-config history="memory:sidebar">
|
|
177
|
+
* <sidebar-nav>...</sidebar-nav>
|
|
178
|
+
* </tha-router-config>
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* ❌ **DON'T**: Place multiple configs in `<head>` (last one wins)
|
|
182
|
+
*
|
|
183
|
+
* ```html
|
|
184
|
+
* <head>
|
|
185
|
+
* <tha-router-config history="browser"></tha-router-config>
|
|
186
|
+
* <tha-router-config history="hash"></tha-router-config> <!-- Overrides above -->
|
|
187
|
+
* </head>
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* ❌ **DON'T**: Nest configs unnecessarily (inner configs take precedence)
|
|
191
|
+
*
|
|
192
|
+
* ```html
|
|
193
|
+
* <tha-router-config history="browser">
|
|
194
|
+
* <tha-router-config history="hash">
|
|
195
|
+
* <!-- Uses hash, not browser -->
|
|
196
|
+
* </tha-router-config>
|
|
197
|
+
* </tha-router-config>
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export declare class ThaRouterConfig extends ThaRouterConfig_base {
|
|
201
|
+
#private;
|
|
202
|
+
/**
|
|
203
|
+
* Called when the element is connected to the DOM.
|
|
204
|
+
*
|
|
205
|
+
* - If in `<head>`: Sets up a reactive effect to update global history
|
|
206
|
+
* - If in `<body>`: Only provides history to descendants (no special setup)
|
|
207
|
+
*/
|
|
208
|
+
connectedCallback(): void;
|
|
209
|
+
/**
|
|
210
|
+
* Called when the element is disconnected from the DOM.
|
|
211
|
+
*
|
|
212
|
+
* Cleans up the global history effect if it was set up.
|
|
213
|
+
*/
|
|
214
|
+
disconnectedCallback(): void;
|
|
215
|
+
/**
|
|
216
|
+
* Creates the render root for the element.
|
|
217
|
+
* Returns the element itself to render children in light DOM.
|
|
218
|
+
*
|
|
219
|
+
* @returns The element itself (not a shadow root)
|
|
220
|
+
*/
|
|
221
|
+
protected createRenderRoot(): this;
|
|
222
|
+
}
|
|
223
|
+
export {};
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { customElement } from "lit/decorators.js";
|
|
3
|
+
import { GLOBAL_HISTORY_TYPE } from "./history";
|
|
4
|
+
import { HISTORY_TYPE, HistoryManaged } from "./history-managed";
|
|
5
|
+
import { SignalWatcherLitElement } from "./signal-watcher-lit-element";
|
|
6
|
+
import { noop } from "@telperion/js-utils/function/noop";
|
|
7
|
+
/**
|
|
8
|
+
* A custom element for configuring router history settings.
|
|
9
|
+
*
|
|
10
|
+
* This element serves dual purposes depending on its placement in the DOM:
|
|
11
|
+
*
|
|
12
|
+
* ## Global Configuration (placed in `<head>`)
|
|
13
|
+
*
|
|
14
|
+
* When placed in the `<head>` element, it sets the **global default history**
|
|
15
|
+
* for all routers in the application that don't specify their own history or
|
|
16
|
+
* inherit from a parent.
|
|
17
|
+
*
|
|
18
|
+
* ```html
|
|
19
|
+
* <head>
|
|
20
|
+
* <!-- All routers will use hash routing by default -->
|
|
21
|
+
* <tha-router-config history="hash"></tha-router-config>
|
|
22
|
+
* </head>
|
|
23
|
+
* <body>
|
|
24
|
+
* <tha-router>
|
|
25
|
+
* <!-- Uses hash history (global default) -->
|
|
26
|
+
* <tha-route path="/home">...</tha-route>
|
|
27
|
+
* </tha-router>
|
|
28
|
+
* </body>
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* ## Local Configuration (placed in `<body>`)
|
|
32
|
+
*
|
|
33
|
+
* When placed in the `<body>` element, it provides history configuration
|
|
34
|
+
* for its **descendant routers only**. This allows different sections of
|
|
35
|
+
* your application to use different history strategies.
|
|
36
|
+
*
|
|
37
|
+
* ```html
|
|
38
|
+
* <body>
|
|
39
|
+
* <!-- Section 1: Hash routing -->
|
|
40
|
+
* <tha-router-config history="hash">
|
|
41
|
+
* <tha-router>
|
|
42
|
+
* <!-- Uses hash history from parent config -->
|
|
43
|
+
* <tha-route path="/dashboard">...</tha-route>
|
|
44
|
+
* </tha-router>
|
|
45
|
+
* </tha-router-config>
|
|
46
|
+
*
|
|
47
|
+
* <!-- Section 2: Memory routing (isolated) -->
|
|
48
|
+
* <tha-router-config history="memory">
|
|
49
|
+
* <tha-router>
|
|
50
|
+
* <!-- Uses memory history from parent config -->
|
|
51
|
+
* <tha-route path="/preview">...</tha-route>
|
|
52
|
+
* </tha-router>
|
|
53
|
+
* </tha-router-config>
|
|
54
|
+
* </body>
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* ## Usage Patterns
|
|
58
|
+
*
|
|
59
|
+
* ### Set Global Default
|
|
60
|
+
*
|
|
61
|
+
* Place in `<head>` to configure all routers:
|
|
62
|
+
*
|
|
63
|
+
* ```html
|
|
64
|
+
* <!DOCTYPE html>
|
|
65
|
+
* <html>
|
|
66
|
+
* <head>
|
|
67
|
+
* <tha-router-config history="browser"></tha-router-config>
|
|
68
|
+
* </head>
|
|
69
|
+
* <body>
|
|
70
|
+
* <!-- All routers use browser history -->
|
|
71
|
+
* </body>
|
|
72
|
+
* </html>
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* ### Override for Specific Section
|
|
76
|
+
*
|
|
77
|
+
* Use local config to override global default:
|
|
78
|
+
*
|
|
79
|
+
* ```html
|
|
80
|
+
* <head>
|
|
81
|
+
* <!-- Global: browser history -->
|
|
82
|
+
* <tha-router-config history="browser"></tha-router-config>
|
|
83
|
+
* </head>
|
|
84
|
+
* <body>
|
|
85
|
+
* <!-- Main app uses browser history -->
|
|
86
|
+
* <tha-router>...</tha-router>
|
|
87
|
+
*
|
|
88
|
+
* <!-- Admin section uses hash history -->
|
|
89
|
+
* <tha-router-config history="hash">
|
|
90
|
+
* <tha-router>...</tha-router>
|
|
91
|
+
* </tha-router-config>
|
|
92
|
+
* </body>
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* ### Isolate Components with Memory History
|
|
96
|
+
*
|
|
97
|
+
* Use named memory history for component isolation:
|
|
98
|
+
*
|
|
99
|
+
* ```html
|
|
100
|
+
* <body>
|
|
101
|
+
* <!-- Each component has independent navigation -->
|
|
102
|
+
* <tha-router-config history="memory:component1">
|
|
103
|
+
* <my-widget>
|
|
104
|
+
* <tha-router>...</tha-router>
|
|
105
|
+
* </my-widget>
|
|
106
|
+
* </tha-router-config>
|
|
107
|
+
*
|
|
108
|
+
* <tha-router-config history="memory:component2">
|
|
109
|
+
* <my-widget>
|
|
110
|
+
* <tha-router>...</tha-router>
|
|
111
|
+
* </my-widget>
|
|
112
|
+
* </tha-router-config>
|
|
113
|
+
* </body>
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* ### Testing with Memory History
|
|
117
|
+
*
|
|
118
|
+
* Use memory history to avoid affecting browser URL during tests:
|
|
119
|
+
*
|
|
120
|
+
* ```typescript
|
|
121
|
+
* import { fixture, html } from '@open-wc/testing';
|
|
122
|
+
*
|
|
123
|
+
* it('should navigate', async () => {
|
|
124
|
+
* const el = await fixture(html`
|
|
125
|
+
* <tha-router-config history="memory:test">
|
|
126
|
+
* <tha-router>
|
|
127
|
+
* <tha-route path="/test">Test Page</tha-route>
|
|
128
|
+
* </tha-router>
|
|
129
|
+
* </tha-router-config>
|
|
130
|
+
* `);
|
|
131
|
+
*
|
|
132
|
+
* // Test navigation without affecting browser URL
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* ## History Resolution
|
|
137
|
+
*
|
|
138
|
+
* Router components resolve their history in this order:
|
|
139
|
+
*
|
|
140
|
+
* 1. **Own `history` attribute** (highest priority)
|
|
141
|
+
* 2. **Parent `tha-router-config`** (local configuration)
|
|
142
|
+
* 3. **Global `tha-router-config`** (in `<head>`)
|
|
143
|
+
* 4. **Default** (`"browser"`)
|
|
144
|
+
*
|
|
145
|
+
* ## Best Practices
|
|
146
|
+
*
|
|
147
|
+
* ✅ **DO**: Place one `tha-router-config` in `<head>` for global settings
|
|
148
|
+
*
|
|
149
|
+
* ```html
|
|
150
|
+
* <head>
|
|
151
|
+
* <tha-router-config history="browser"></tha-router-config>
|
|
152
|
+
* </head>
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* ✅ **DO**: Use local configs for sections with different routing needs
|
|
156
|
+
*
|
|
157
|
+
* ```html
|
|
158
|
+
* <tha-router-config history="memory">
|
|
159
|
+
* <component-preview>...</component-preview>
|
|
160
|
+
* </tha-router-config>
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* ✅ **DO**: Use named memory history for isolated components
|
|
164
|
+
*
|
|
165
|
+
* ```html
|
|
166
|
+
* <tha-router-config history="memory:sidebar">
|
|
167
|
+
* <sidebar-nav>...</sidebar-nav>
|
|
168
|
+
* </tha-router-config>
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* ❌ **DON'T**: Place multiple configs in `<head>` (last one wins)
|
|
172
|
+
*
|
|
173
|
+
* ```html
|
|
174
|
+
* <head>
|
|
175
|
+
* <tha-router-config history="browser"></tha-router-config>
|
|
176
|
+
* <tha-router-config history="hash"></tha-router-config> <!-- Overrides above -->
|
|
177
|
+
* </head>
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* ❌ **DON'T**: Nest configs unnecessarily (inner configs take precedence)
|
|
181
|
+
*
|
|
182
|
+
* ```html
|
|
183
|
+
* <tha-router-config history="browser">
|
|
184
|
+
* <tha-router-config history="hash">
|
|
185
|
+
* <!-- Uses hash, not browser -->
|
|
186
|
+
* </tha-router-config>
|
|
187
|
+
* </tha-router-config>
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
let ThaRouterConfig = class ThaRouterConfig extends HistoryManaged(SignalWatcherLitElement) {
|
|
191
|
+
/**
|
|
192
|
+
* Cleanup function for the global history effect.
|
|
193
|
+
* Only used when the element is placed in `<head>`.
|
|
194
|
+
* @private
|
|
195
|
+
*/
|
|
196
|
+
#globalHistoryUnsubscribe = noop;
|
|
197
|
+
/**
|
|
198
|
+
* Called when the element is connected to the DOM.
|
|
199
|
+
*
|
|
200
|
+
* - If in `<head>`: Sets up a reactive effect to update global history
|
|
201
|
+
* - If in `<body>`: Only provides history to descendants (no special setup)
|
|
202
|
+
*/
|
|
203
|
+
connectedCallback() {
|
|
204
|
+
super.connectedCallback();
|
|
205
|
+
if (!document.head.contains(this))
|
|
206
|
+
return;
|
|
207
|
+
console.log('ThaRouterConfig: Setting global history type to', this[HISTORY_TYPE].get());
|
|
208
|
+
// Set the global history type when this element is connected in <head>
|
|
209
|
+
this.#globalHistoryUnsubscribe = this.updateEffect(() => {
|
|
210
|
+
GLOBAL_HISTORY_TYPE.set(this[HISTORY_TYPE].get());
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Called when the element is disconnected from the DOM.
|
|
215
|
+
*
|
|
216
|
+
* Cleans up the global history effect if it was set up.
|
|
217
|
+
*/
|
|
218
|
+
disconnectedCallback() {
|
|
219
|
+
super.disconnectedCallback();
|
|
220
|
+
try {
|
|
221
|
+
this.#globalHistoryUnsubscribe();
|
|
222
|
+
}
|
|
223
|
+
catch { }
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Creates the render root for the element.
|
|
227
|
+
* Returns the element itself to render children in light DOM.
|
|
228
|
+
*
|
|
229
|
+
* @returns The element itself (not a shadow root)
|
|
230
|
+
*/
|
|
231
|
+
createRenderRoot() {
|
|
232
|
+
return this;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
ThaRouterConfig = __decorate([
|
|
236
|
+
customElement('tha-router-config')
|
|
237
|
+
], ThaRouterConfig);
|
|
238
|
+
export { ThaRouterConfig };
|
|
239
|
+
|
|
240
|
+
//# sourceMappingURL=tha-router-config.js.map
|