@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,162 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { css } from "lit";
|
|
3
|
+
import { customElement } from "lit/decorators.js";
|
|
4
|
+
import { PATH_PATTERN, ThaRoute } from "./tha-route";
|
|
5
|
+
import { signal } from '@lit-labs/signals';
|
|
6
|
+
import { RENDER_ROUTE } from "./tha-router-outlet";
|
|
7
|
+
import { noop } from "@telperion/js-utils/function/noop";
|
|
8
|
+
import { defer } from "@telperion/js-utils/function/defer";
|
|
9
|
+
import { SignalWatcherLitElement } from "./signal-watcher-lit-element";
|
|
10
|
+
import { HISTORY, HistoryManaged } from "./history-managed";
|
|
11
|
+
/**
|
|
12
|
+
* A custom element that manages client-side routing for single-page applications.
|
|
13
|
+
*
|
|
14
|
+
* The router watches for navigation events and matches the current URL against
|
|
15
|
+
* registered routes (tha-route elements), rendering the matching route's content
|
|
16
|
+
* in a tha-router-outlet element.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```html
|
|
20
|
+
* <tha-router history="browser">
|
|
21
|
+
* <tha-route path="/">
|
|
22
|
+
* <template><h1>Home</h1></template>
|
|
23
|
+
* </tha-route>
|
|
24
|
+
* <tha-route path="/about">
|
|
25
|
+
* <template><h1>About</h1></template>
|
|
26
|
+
* </tha-route>
|
|
27
|
+
* <tha-router-outlet></tha-router-outlet>
|
|
28
|
+
* </tha-router>
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
let ThaRouter = class ThaRouter extends HistoryManaged(SignalWatcherLitElement) {
|
|
32
|
+
/**
|
|
33
|
+
* Injects global styles for tha-router elements to hide non-outlet children.
|
|
34
|
+
* Ensures that only tha-router-outlet elements are visible within the router.
|
|
35
|
+
*/
|
|
36
|
+
static {
|
|
37
|
+
const styleEl = document.createElement("style");
|
|
38
|
+
styleEl.setAttribute("type", "text/css");
|
|
39
|
+
styleEl.setAttribute("data-id", "tha-router-styles");
|
|
40
|
+
styleEl.textContent = css `
|
|
41
|
+
tha-router {
|
|
42
|
+
& > :not(tha-router-outlet) {
|
|
43
|
+
display: none;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
`.toString();
|
|
47
|
+
document.head.appendChild(styleEl);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Observes changes to child elements to detect when routes are added or removed.
|
|
51
|
+
* Updates the #routeEls signal whenever tha-route children change.
|
|
52
|
+
*/
|
|
53
|
+
#routeChildObserver = new MutationObserver((mutations) => {
|
|
54
|
+
const childListMutations = mutations.filter(mutation => mutation.type === 'childList');
|
|
55
|
+
if (!childListMutations.length)
|
|
56
|
+
return;
|
|
57
|
+
this.#routeEls.set(Array.from(this.children).filter(child => child instanceof ThaRoute).map(routeEl => new WeakRef(routeEl)));
|
|
58
|
+
});
|
|
59
|
+
/** Cleanup function for the route children rendering effect */
|
|
60
|
+
#routeChildrenEffectCleaner = noop;
|
|
61
|
+
/** Cleanup function for the history type change effect */
|
|
62
|
+
#historyTypeEffectCleaner = noop;
|
|
63
|
+
/** Cleanup function to remove history listener */
|
|
64
|
+
#historyListenerRemover = noop;
|
|
65
|
+
/** Signal containing weak references to all tha-route children */
|
|
66
|
+
#routeEls = signal([]);
|
|
67
|
+
/** Signal containing weak reference to the currently active route */
|
|
68
|
+
#activeRoute = signal(null);
|
|
69
|
+
/** Signal containing weak reference to the assigned outlet element */
|
|
70
|
+
#outlet = signal(null);
|
|
71
|
+
/**
|
|
72
|
+
* Lifecycle callback when the element is connected to the DOM.
|
|
73
|
+
* Sets up observers, effects, and history listeners.
|
|
74
|
+
*/
|
|
75
|
+
connectedCallback() {
|
|
76
|
+
super.connectedCallback();
|
|
77
|
+
// Start observing child route elements
|
|
78
|
+
this.#routeChildObserver.observe(this, { childList: true });
|
|
79
|
+
// Effect to render the active route in the assigned outlet
|
|
80
|
+
this.#routeChildrenEffectCleaner = this.updateEffect(() => {
|
|
81
|
+
const activeRoute = this.#activeRoute.get()?.deref() ?? null;
|
|
82
|
+
const outlet = this.#outlet.get()?.deref() ?? null;
|
|
83
|
+
outlet?.[RENDER_ROUTE](activeRoute);
|
|
84
|
+
});
|
|
85
|
+
// Effect to handle history type changes
|
|
86
|
+
this.#historyTypeEffectCleaner = this.updateEffect(() => {
|
|
87
|
+
const history = this[HISTORY].get();
|
|
88
|
+
this.#historyListenerRemover();
|
|
89
|
+
this.#handleRouteChange({
|
|
90
|
+
location: this[HISTORY].get().location,
|
|
91
|
+
action: 'POP',
|
|
92
|
+
});
|
|
93
|
+
// Set up listener for navigation events
|
|
94
|
+
this.#historyListenerRemover = history ? history.listen(this.#handleRouteChange) : noop;
|
|
95
|
+
});
|
|
96
|
+
// Initial route matching on connect
|
|
97
|
+
defer(() => {
|
|
98
|
+
this.#handleRouteChange({
|
|
99
|
+
location: this[HISTORY].get().location,
|
|
100
|
+
action: 'POP',
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Assigns a router outlet to this router.
|
|
106
|
+
* The outlet will be used to render the active route's content.
|
|
107
|
+
*
|
|
108
|
+
* @param outlet - The outlet element to assign, or null to unassign
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
assignOutlet(outlet) {
|
|
112
|
+
this.#outlet.set(outlet ? new WeakRef(outlet) : null);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Handles navigation events by matching the new URL against registered routes.
|
|
116
|
+
* Updates the active route signal when a match is found.
|
|
117
|
+
*
|
|
118
|
+
* @param update - The history update containing the new location
|
|
119
|
+
*/
|
|
120
|
+
#handleRouteChange = (update) => {
|
|
121
|
+
const routes = this.#routeEls.get()
|
|
122
|
+
.map(weakRef => weakRef.deref())
|
|
123
|
+
.filter(Boolean);
|
|
124
|
+
for (const route of routes) {
|
|
125
|
+
const pathPattern = route[PATH_PATTERN];
|
|
126
|
+
if (pathPattern?.test({ pathname: update.location.pathname })) {
|
|
127
|
+
this.#activeRoute.set(new WeakRef(route));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
this.#activeRoute.set(null);
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Lifecycle callback when the element is disconnected from the DOM.
|
|
135
|
+
* Cleans up all observers, effects, and listeners.
|
|
136
|
+
*/
|
|
137
|
+
disconnectedCallback() {
|
|
138
|
+
super.disconnectedCallback();
|
|
139
|
+
try {
|
|
140
|
+
this.#routeChildrenEffectCleaner();
|
|
141
|
+
this.#historyTypeEffectCleaner();
|
|
142
|
+
}
|
|
143
|
+
catch { /* no-op */ }
|
|
144
|
+
this.#routeChildObserver.disconnect();
|
|
145
|
+
this.#historyListenerRemover();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Creates the render root for the element.
|
|
149
|
+
* Returns the element itself to render children in light DOM.
|
|
150
|
+
*
|
|
151
|
+
* @returns The element itself (not a shadow root)
|
|
152
|
+
*/
|
|
153
|
+
createRenderRoot() {
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
ThaRouter = __decorate([
|
|
158
|
+
customElement("tha-router")
|
|
159
|
+
], ThaRouter);
|
|
160
|
+
export { ThaRouter };
|
|
161
|
+
|
|
162
|
+
//# sourceMappingURL=tha-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/elements/src/router/tha-router.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAc,MAAM,KAAK,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAmB,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,mCAAmC,CAAC;AAEzD,OAAO,EAAE,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAkB5D;;;;;;;;;;;;;;;;;;;GAmBG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,cAAc,CAAC,uBAAuB,CAAC;IACpE;;;OAGG;IACH;QACE,MAAM,OAAO,GAAG,QAAQ,CAAC,aA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,SAAS;IADrB,aAAa,CAAC,YAAY,CAAC;GACf,SAAS,CAmJrB","file":"tha-router.js","sourcesContent":["import { css, LitElement } from \"lit\";\nimport { customElement } from \"lit/decorators.js\";\nimport { PATH_PATTERN, ThaRoute } from \"./tha-route\";\nimport { signal } from '@lit-labs/signals';\nimport { RENDER_ROUTE, ThaRouterOutlet } from \"./tha-router-outlet\";\nimport { noop } from \"@telperion/js-utils/function/noop\";\nimport { Update } from 'history';\nimport { defer } from \"@telperion/js-utils/function/defer\";\nimport { SignalWatcherLitElement } from \"./signal-watcher-lit-element\";\nimport { HISTORY, HistoryManaged } from \"./history-managed\";\n\ndeclare global {\n interface HTMLElementTagNameMap {\n /**\n * A router element that manages client-side routing for single-page applications.\n * It watches for navigation events and matches the current URL against registered routes\n * (tha-route elements), rendering the matching route's content in a tha-router-outlet element.\n * The `history` attribute specifies the history management strategy:\n * - 'browser' for HTML5 History API (default)\n * - 'hash' for hash-based routing\n * - 'memory' for in-memory history (testing)\n * - 'memory:name' for named memory history instances\n */\n \"tha-router\": ThaRouter;\n }\n}\n\n/**\n * A custom element that manages client-side routing for single-page applications.\n *\n * The router watches for navigation events and matches the current URL against\n * registered routes (tha-route elements), rendering the matching route's content\n * in a tha-router-outlet element.\n *\n * @example\n * ```html\n * <tha-router history=\"browser\">\n * <tha-route path=\"/\">\n * <template><h1>Home</h1></template>\n * </tha-route>\n * <tha-route path=\"/about\">\n * <template><h1>About</h1></template>\n * </tha-route>\n * <tha-router-outlet></tha-router-outlet>\n * </tha-router>\n * ```\n */\n@customElement(\"tha-router\")\nexport class ThaRouter extends HistoryManaged(SignalWatcherLitElement) {\n /**\n * Injects global styles for tha-router elements to hide non-outlet children.\n * Ensures that only tha-router-outlet elements are visible within the router.\n */\n static {\n const styleEl = document.createElement(\"style\");\n\n styleEl.setAttribute(\"type\", \"text/css\");\n styleEl.setAttribute(\"data-id\", \"tha-router-styles\");\n styleEl.textContent = css`\n tha-router {\n & > :not(tha-router-outlet) {\n display: none;\n }\n }\n `.toString();\n document.head.appendChild(styleEl);\n }\n\n /**\n * Observes changes to child elements to detect when routes are added or removed.\n * Updates the #routeEls signal whenever tha-route children change.\n */\n #routeChildObserver = new MutationObserver((mutations) => {\n const childListMutations = mutations.filter(mutation => mutation.type === 'childList');\n\n if (!childListMutations.length) return;\n\n this.#routeEls.set(\n Array.from(this.children).filter(child => child instanceof ThaRoute).map(routeEl => new WeakRef(routeEl))\n );\n });\n\n /** Cleanup function for the route children rendering effect */\n #routeChildrenEffectCleaner = noop;\n /** Cleanup function for the history type change effect */\n #historyTypeEffectCleaner = noop;\n /** Cleanup function to remove history listener */\n #historyListenerRemover = noop;\n\n /** Signal containing weak references to all tha-route children */\n #routeEls = signal<WeakRef<ThaRoute>[]>([]);\n /** Signal containing weak reference to the currently active route */\n #activeRoute = signal<WeakRef<ThaRoute> | null>(null);\n /** Signal containing weak reference to the assigned outlet element */\n #outlet = signal<WeakRef<ThaRouterOutlet> | null>(null);\n\n /**\n * Lifecycle callback when the element is connected to the DOM.\n * Sets up observers, effects, and history listeners.\n */\n override connectedCallback(): void {\n super.connectedCallback();\n\n // Start observing child route elements\n this.#routeChildObserver.observe(this, { childList: true});\n\n // Effect to render the active route in the assigned outlet\n this.#routeChildrenEffectCleaner = this.updateEffect(() => {\n const activeRoute = this.#activeRoute.get()?.deref() ?? null;\n const outlet = this.#outlet.get()?.deref() ?? null;\n\n outlet?.[RENDER_ROUTE](activeRoute);\n });\n\n // Effect to handle history type changes\n this.#historyTypeEffectCleaner = this.updateEffect(() => {\n const history = this[HISTORY].get();\n\n this.#historyListenerRemover();\n\n this.#handleRouteChange({\n location: this[HISTORY].get()!.location,\n action: 'POP' as Update['action'],\n });\n\n // Set up listener for navigation events\n this.#historyListenerRemover = history ? history.listen(this.#handleRouteChange) : noop;\n });\n\n // Initial route matching on connect\n defer(() => {\n this.#handleRouteChange({\n location: this[HISTORY].get()!.location,\n action: 'POP' as Update['action'],\n });\n });\n }\n\n /**\n * Assigns a router outlet to this router.\n * The outlet will be used to render the active route's content.\n *\n * @param outlet - The outlet element to assign, or null to unassign\n * @internal\n */\n assignOutlet(outlet: ThaRouterOutlet | null) {\n this.#outlet.set(outlet ? new WeakRef(outlet) : null);\n }\n\n /**\n * Handles navigation events by matching the new URL against registered routes.\n * Updates the active route signal when a match is found.\n *\n * @param update - The history update containing the new location\n */\n #handleRouteChange = (update: Update) => {\n const routes = this.#routeEls.get()\n .map(weakRef => weakRef.deref()!)\n .filter(Boolean);\n\n for (const route of routes) {\n const pathPattern = route[PATH_PATTERN];\n if (pathPattern?.test({ pathname: update.location.pathname })) {\n this.#activeRoute.set(new WeakRef(route));\n return;\n }\n }\n this.#activeRoute.set(null);\n };\n\n /**\n * Lifecycle callback when the element is disconnected from the DOM.\n * Cleans up all observers, effects, and listeners.\n */\n override disconnectedCallback() {\n super.disconnectedCallback();\n\n try {\n this.#routeChildrenEffectCleaner();\n this.#historyTypeEffectCleaner();\n } catch { /* no-op */ }\n\n this.#routeChildObserver.disconnect();\n this.#historyListenerRemover();\n }\n\n /**\n * Creates the render root for the element.\n * Returns the element itself to render children in light DOM.\n *\n * @returns The element itself (not a shadow root)\n */\n protected override createRenderRoot() {\n return this;\n }\n}\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ThaUrlOutput = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const decorators_js_1 = require("lit/decorators.js");
|
|
6
|
+
const signals_1 = require("@lit-labs/signals");
|
|
7
|
+
const history_managed_1 = require("../src/router/history-managed");
|
|
8
|
+
const signal_watcher_lit_element_1 = require("../src/router/signal-watcher-lit-element");
|
|
9
|
+
const noop_1 = require("@telperion/js-utils/function/noop");
|
|
10
|
+
/**
|
|
11
|
+
* A custom element for displaying router history URL and actual browser URL.
|
|
12
|
+
*
|
|
13
|
+
* This component is useful for debugging and demonstrations to visualize:
|
|
14
|
+
* - The URL from the router's history object (pathname + search + hash)
|
|
15
|
+
* - The actual browser window URL (from window.location)
|
|
16
|
+
*
|
|
17
|
+
* This helps understand the difference between router-managed navigation
|
|
18
|
+
* (especially with memory or hash history) and the browser's actual location.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```html
|
|
22
|
+
* <!-- Show URLs for browser history -->
|
|
23
|
+
* <tha-url-output history="browser"></tha-url-output>
|
|
24
|
+
*
|
|
25
|
+
* <!-- Show URLs for hash history -->
|
|
26
|
+
* <tha-url-output history="hash"></tha-url-output>
|
|
27
|
+
*
|
|
28
|
+
* <!-- Show URLs for memory history (browser URL won't change) -->
|
|
29
|
+
* <tha-url-output history="memory"></tha-url-output>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
let ThaUrlOutput = class ThaUrlOutput extends (0, history_managed_1.HistoryManaged)(signal_watcher_lit_element_1.SignalWatcherLitElement) {
|
|
33
|
+
#historyChangeUnsubscribe = noop_1.noop;
|
|
34
|
+
#historyEventsUnsubscribe = noop_1.noop;
|
|
35
|
+
#browserUrl = (0, signals_1.signal)(location.href);
|
|
36
|
+
#historyUrl = (0, signals_1.signal)(this[history_managed_1.HISTORY].get().location.pathname + this[history_managed_1.HISTORY].get().location.search + this[history_managed_1.HISTORY].get().location.hash);
|
|
37
|
+
connectedCallback() {
|
|
38
|
+
super.connectedCallback();
|
|
39
|
+
addEventListener('popstate', this.#onLocationChange);
|
|
40
|
+
addEventListener('pushstate', this.#onLocationChange);
|
|
41
|
+
addEventListener('hashchange', this.#onLocationChange);
|
|
42
|
+
this.#historyChangeUnsubscribe = this.updateEffect(() => {
|
|
43
|
+
const history = this[history_managed_1.HISTORY].get();
|
|
44
|
+
this.#historyUrl.set(history.location.pathname + history.location.search + history.location.hash);
|
|
45
|
+
this.#historyEventsUnsubscribe();
|
|
46
|
+
this.#historyEventsUnsubscribe = history.listen(({ location }) => {
|
|
47
|
+
this.#historyUrl.set(location.pathname + location.search + location.hash);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
render() {
|
|
52
|
+
return (0, signals_1.html) `
|
|
53
|
+
<div>
|
|
54
|
+
<strong>History URL:</strong> ${this.#historyUrl}
|
|
55
|
+
</div>
|
|
56
|
+
<div>
|
|
57
|
+
<strong>Browser URL:</strong> ${this.#browserUrl}
|
|
58
|
+
</div>
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
61
|
+
#onLocationChange = () => {
|
|
62
|
+
this.#browserUrl.set(window.location.href);
|
|
63
|
+
};
|
|
64
|
+
disconnectedCallback() {
|
|
65
|
+
super.disconnectedCallback();
|
|
66
|
+
removeEventListener('popstate', this.#onLocationChange);
|
|
67
|
+
removeEventListener('pushstate', this.#onLocationChange);
|
|
68
|
+
removeEventListener('hashchange', this.#onLocationChange);
|
|
69
|
+
this.#historyEventsUnsubscribe();
|
|
70
|
+
try {
|
|
71
|
+
this.#historyChangeUnsubscribe();
|
|
72
|
+
}
|
|
73
|
+
catch { }
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.ThaUrlOutput = ThaUrlOutput;
|
|
77
|
+
exports.ThaUrlOutput = ThaUrlOutput = tslib_1.__decorate([
|
|
78
|
+
(0, decorators_js_1.customElement)('tha-url-output')
|
|
79
|
+
], ThaUrlOutput);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface HTMLElementTagNameMap {
|
|
3
|
+
/**
|
|
4
|
+
* A debugging component that displays the current history URL and the actual browser URL.
|
|
5
|
+
* Useful for understanding the difference between router state and browser location.
|
|
6
|
+
*/
|
|
7
|
+
"tha-url-output": ThaUrlOutput;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
declare const ThaUrlOutput_base: (new (...args: any[]) => import("../src/router/history-managed").HistoryManagedLitElementType) & (new () => import("lit").LitElement & {
|
|
11
|
+
updateEffect(fn: () => void, options?: import("../src/router/signal-watcher-lit-element").EffectOptions): () => void;
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* A custom element for displaying router history URL and actual browser URL.
|
|
15
|
+
*
|
|
16
|
+
* This component is useful for debugging and demonstrations to visualize:
|
|
17
|
+
* - The URL from the router's history object (pathname + search + hash)
|
|
18
|
+
* - The actual browser window URL (from window.location)
|
|
19
|
+
*
|
|
20
|
+
* This helps understand the difference between router-managed navigation
|
|
21
|
+
* (especially with memory or hash history) and the browser's actual location.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```html
|
|
25
|
+
* <!-- Show URLs for browser history -->
|
|
26
|
+
* <tha-url-output history="browser"></tha-url-output>
|
|
27
|
+
*
|
|
28
|
+
* <!-- Show URLs for hash history -->
|
|
29
|
+
* <tha-url-output history="hash"></tha-url-output>
|
|
30
|
+
*
|
|
31
|
+
* <!-- Show URLs for memory history (browser URL won't change) -->
|
|
32
|
+
* <tha-url-output history="memory"></tha-url-output>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class ThaUrlOutput extends ThaUrlOutput_base {
|
|
36
|
+
#private;
|
|
37
|
+
connectedCallback(): void;
|
|
38
|
+
protected render(): import("lit").TemplateResult;
|
|
39
|
+
disconnectedCallback(): void;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { customElement } from "lit/decorators.js";
|
|
3
|
+
import { html, signal } from "@lit-labs/signals";
|
|
4
|
+
import { HISTORY, HistoryManaged } from "../src/router/history-managed";
|
|
5
|
+
import { SignalWatcherLitElement } from "../src/router/signal-watcher-lit-element";
|
|
6
|
+
import { noop } from "@telperion/js-utils/function/noop";
|
|
7
|
+
/**
|
|
8
|
+
* A custom element for displaying router history URL and actual browser URL.
|
|
9
|
+
*
|
|
10
|
+
* This component is useful for debugging and demonstrations to visualize:
|
|
11
|
+
* - The URL from the router's history object (pathname + search + hash)
|
|
12
|
+
* - The actual browser window URL (from window.location)
|
|
13
|
+
*
|
|
14
|
+
* This helps understand the difference between router-managed navigation
|
|
15
|
+
* (especially with memory or hash history) and the browser's actual location.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```html
|
|
19
|
+
* <!-- Show URLs for browser history -->
|
|
20
|
+
* <tha-url-output history="browser"></tha-url-output>
|
|
21
|
+
*
|
|
22
|
+
* <!-- Show URLs for hash history -->
|
|
23
|
+
* <tha-url-output history="hash"></tha-url-output>
|
|
24
|
+
*
|
|
25
|
+
* <!-- Show URLs for memory history (browser URL won't change) -->
|
|
26
|
+
* <tha-url-output history="memory"></tha-url-output>
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
let ThaUrlOutput = class ThaUrlOutput extends HistoryManaged(SignalWatcherLitElement) {
|
|
30
|
+
#historyChangeUnsubscribe = noop;
|
|
31
|
+
#historyEventsUnsubscribe = noop;
|
|
32
|
+
#browserUrl = signal(location.href);
|
|
33
|
+
#historyUrl = signal(this[HISTORY].get().location.pathname + this[HISTORY].get().location.search + this[HISTORY].get().location.hash);
|
|
34
|
+
connectedCallback() {
|
|
35
|
+
super.connectedCallback();
|
|
36
|
+
addEventListener('popstate', this.#onLocationChange);
|
|
37
|
+
addEventListener('pushstate', this.#onLocationChange);
|
|
38
|
+
addEventListener('hashchange', this.#onLocationChange);
|
|
39
|
+
this.#historyChangeUnsubscribe = this.updateEffect(() => {
|
|
40
|
+
const history = this[HISTORY].get();
|
|
41
|
+
this.#historyUrl.set(history.location.pathname + history.location.search + history.location.hash);
|
|
42
|
+
this.#historyEventsUnsubscribe();
|
|
43
|
+
this.#historyEventsUnsubscribe = history.listen(({ location }) => {
|
|
44
|
+
this.#historyUrl.set(location.pathname + location.search + location.hash);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
render() {
|
|
49
|
+
return html `
|
|
50
|
+
<div>
|
|
51
|
+
<strong>History URL:</strong> ${this.#historyUrl}
|
|
52
|
+
</div>
|
|
53
|
+
<div>
|
|
54
|
+
<strong>Browser URL:</strong> ${this.#browserUrl}
|
|
55
|
+
</div>
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
58
|
+
#onLocationChange = () => {
|
|
59
|
+
this.#browserUrl.set(window.location.href);
|
|
60
|
+
};
|
|
61
|
+
disconnectedCallback() {
|
|
62
|
+
super.disconnectedCallback();
|
|
63
|
+
removeEventListener('popstate', this.#onLocationChange);
|
|
64
|
+
removeEventListener('pushstate', this.#onLocationChange);
|
|
65
|
+
removeEventListener('hashchange', this.#onLocationChange);
|
|
66
|
+
this.#historyEventsUnsubscribe();
|
|
67
|
+
try {
|
|
68
|
+
this.#historyChangeUnsubscribe();
|
|
69
|
+
}
|
|
70
|
+
catch { }
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
ThaUrlOutput = __decorate([
|
|
74
|
+
customElement('tha-url-output')
|
|
75
|
+
], ThaUrlOutput);
|
|
76
|
+
export { ThaUrlOutput };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=tha-url-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/elements/.storybook/tha-url-output.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAS,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,IAAI,EAAE,MAAM,mCAAmC,CAAC;AAYzD;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEI,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,cAAc,CAAC,uBAAuB,CAAC;IACvE,yBAAyB,GAAG,IAAI,CAAC;IACjC,yBAAyB,GAAG,IAAI,CAAC;IAEjC,WAAW,GAAG,MA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WAAW;;;wCAGhB,IAAI,CAAC,WAAW;;KAEnD,CAAC;IACJ,CAAC;IAED,iBAAiB,GAAG,GAAG,EAAE;QACvB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC,CAAC;IAEO,oBAAoB;QAC3B,KAAK,CAAC,oBAAoB,EAAE,CAAC;QAE7B,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACxD,mBAAmB,CAAC,WAAW,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACzD,mBAAmB,CAAC,YAAY,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAE1D,IAAI,CAAC,yBAAyB,EAAE,CAAC;QAEjC,IAAI,CAAC;YACH,IAAI,CAAC,yBAAyB,EAAE,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACZ,CAAC;CACF,CAAA;AAtDY,YAAY;IADxB,aAAa,CAAC,gBAAgB,CAAC;GACnB,YAAY,CAsDxB","file":"tha-url-output.js","sourcesContent":["import { customElement } from \"lit/decorators.js\";\nimport { html, signal, watch } from \"@lit-labs/signals\";\nimport { HISTORY, HistoryManaged } from \"../src/router/history-managed\";\nimport { SignalWatcherLitElement } from \"../src/router/signal-watcher-lit-element\";\nimport { noop } from \"@telperion/js-utils/function/noop\";\n\ndeclare global {\n interface HTMLElementTagNameMap {\n /**\n * A debugging component that displays the current history URL and the actual browser URL.\n * Useful for understanding the difference between router state and browser location.\n */\n \"tha-url-output\": ThaUrlOutput;\n }\n}\n\n/**\n * A custom element for displaying router history URL and actual browser URL.\n *\n * This component is useful for debugging and demonstrations to visualize:\n * - The URL from the router's history object (pathname + search + hash)\n * - The actual browser window URL (from window.location)\n *\n * This helps understand the difference between router-managed navigation\n * (especially with memory or hash history) and the browser's actual location.\n *\n * @example\n * ```html\n * <!-- Show URLs for browser history -->\n * <tha-url-output history=\"browser\"></tha-url-output>\n *\n * <!-- Show URLs for hash history -->\n * <tha-url-output history=\"hash\"></tha-url-output>\n *\n * <!-- Show URLs for memory history (browser URL won't change) -->\n * <tha-url-output history=\"memory\"></tha-url-output>\n * ```\n */\n@customElement('tha-url-output')\nexport class ThaUrlOutput extends HistoryManaged(SignalWatcherLitElement) {\n #historyChangeUnsubscribe = noop;\n #historyEventsUnsubscribe = noop;\n\n #browserUrl = signal(location.href);\n #historyUrl = signal(this[HISTORY].get()!.location.pathname + this[HISTORY].get()!.location.search + this[HISTORY].get()!.location.hash);\n\n override connectedCallback(): void {\n super.connectedCallback();\n\n addEventListener('popstate', this.#onLocationChange);\n addEventListener('pushstate', this.#onLocationChange);\n addEventListener('hashchange', this.#onLocationChange);\n\n this.#historyChangeUnsubscribe = this.updateEffect(() => {\n const history = this[HISTORY].get();\n\n this.#historyUrl.set(history.location.pathname + history.location.search + history.location.hash);\n\n this.#historyEventsUnsubscribe();\n this.#historyEventsUnsubscribe = history.listen(({ location }) => {\n this.#historyUrl.set(location.pathname + location.search + location.hash);\n });\n })\n }\n\n protected override render() {\n return html`\n <div>\n <strong>History URL:</strong> ${this.#historyUrl}\n </div>\n <div>\n <strong>Browser URL:</strong> ${this.#browserUrl}\n </div>\n `;\n }\n\n #onLocationChange = () => {\n this.#browserUrl.set(window.location.href);\n };\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n\n removeEventListener('popstate', this.#onLocationChange);\n removeEventListener('pushstate', this.#onLocationChange);\n removeEventListener('hashchange', this.#onLocationChange);\n\n this.#historyEventsUnsubscribe();\n\n try {\n this.#historyChangeUnsubscribe();\n } catch {}\n }\n}\n"]}
|