@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.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +102 -0
  3. package/bundle.js +164 -0
  4. package/bundle.mjs +2630 -0
  5. package/drag-drop/drag-element.cjs +438 -0
  6. package/drag-drop/drag-element.d.ts +120 -0
  7. package/drag-drop/drag-element.js +437 -0
  8. package/drag-drop/drag-element.js.map +1 -0
  9. package/drag-drop/drag-handle-element.cjs +35 -0
  10. package/drag-drop/drag-handle-element.d.ts +12 -0
  11. package/drag-drop/drag-handle-element.js +34 -0
  12. package/drag-drop/drag-handle-element.js.map +1 -0
  13. package/drag-drop/dropzone-element.cjs +117 -0
  14. package/drag-drop/dropzone-element.d.ts +17 -0
  15. package/drag-drop/dropzone-element.js +116 -0
  16. package/drag-drop/dropzone-element.js.map +1 -0
  17. package/drag-drop/index.cjs +11 -0
  18. package/drag-drop/index.d.ts +22 -0
  19. package/drag-drop/index.js +6 -0
  20. package/drag-drop/index.js.map +1 -0
  21. package/drag-drop/private-props.cjs +6 -0
  22. package/drag-drop/private-props.d.ts +3 -0
  23. package/drag-drop/private-props.js +5 -0
  24. package/drag-drop/private-props.js.map +1 -0
  25. package/drag-drop/tha-drag-event.cjs +34 -0
  26. package/drag-drop/tha-drag-event.d.ts +19 -0
  27. package/drag-drop/tha-drag-event.js +32 -0
  28. package/drag-drop/tha-drag-event.js.map +1 -0
  29. package/icon/icon-element.cjs +114 -0
  30. package/icon/icon-element.d.ts +40 -0
  31. package/icon/icon-element.js +113 -0
  32. package/icon/icon-element.js.map +1 -0
  33. package/icon/index.cjs +5 -0
  34. package/icon/index.d.ts +1 -0
  35. package/icon/index.js +3 -0
  36. package/icon/index.js.map +1 -0
  37. package/icon/material-symbols.css +22 -0
  38. package/index.cjs +11 -0
  39. package/index.d.ts +6 -0
  40. package/index.js +10 -0
  41. package/index.js.map +1 -0
  42. package/package.json +127 -0
  43. package/router/history-managed.cjs +97 -0
  44. package/router/history-managed.d.ts +76 -0
  45. package/router/history-managed.js +95 -0
  46. package/router/history-managed.js.map +1 -0
  47. package/router/history.cjs +65 -0
  48. package/router/history.d.ts +48 -0
  49. package/router/history.js +63 -0
  50. package/router/history.js.map +1 -0
  51. package/router/index.cjs +15 -0
  52. package/router/index.d.ts +6 -0
  53. package/router/index.js +8 -0
  54. package/router/index.js.map +1 -0
  55. package/router/signal-watcher-lit-element.cjs +11 -0
  56. package/router/signal-watcher-lit-element.d.ts +25 -0
  57. package/router/signal-watcher-lit-element.js +10 -0
  58. package/router/signal-watcher-lit-element.js.map +1 -0
  59. package/router/tha-route.cjs +125 -0
  60. package/router/tha-route.d.ts +90 -0
  61. package/router/tha-route.js +124 -0
  62. package/router/tha-route.js.map +1 -0
  63. package/router/tha-router-config.cjs +241 -0
  64. package/router/tha-router-config.d.ts +223 -0
  65. package/router/tha-router-config.js +240 -0
  66. package/router/tha-router-config.js.map +1 -0
  67. package/router/tha-router-link.cjs +209 -0
  68. package/router/tha-router-link.d.ts +95 -0
  69. package/router/tha-router-link.js +208 -0
  70. package/router/tha-router-link.js.map +1 -0
  71. package/router/tha-router-outlet.cjs +215 -0
  72. package/router/tha-router-outlet.d.ts +112 -0
  73. package/router/tha-router-outlet.js +214 -0
  74. package/router/tha-router-outlet.js.map +1 -0
  75. package/router/tha-router-param.cjs +278 -0
  76. package/router/tha-router-param.d.ts +226 -0
  77. package/router/tha-router-param.js +277 -0
  78. package/router/tha-router-param.js.map +1 -0
  79. package/router/tha-router.cjs +163 -0
  80. package/router/tha-router.d.ts +69 -0
  81. package/router/tha-router.js +162 -0
  82. package/router/tha-router.js.map +1 -0
  83. package/tha-url-output.cjs +79 -0
  84. package/tha-url-output.d.ts +41 -0
  85. package/tha-url-output.js +78 -0
  86. package/tha-url-output.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/elements/src/router/tha-router-config.ts"],"names":[],"m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CAAA,CAAC;IACZ,CAAC;IAED;;;;;OAKG;IACgB,gBAAgB;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAjDY,eAAe;IAD3B,aAAa,CAAC,mBAAmB,CAAC;GACtB,eAAe,CAiD3B","file":"tha-router-config.js","sourcesContent":["import { LitElement } from \"lit\";\nimport { customElement } from \"lit/decorators.js\";\nimport { GLOBAL_HISTORY_TYPE } from \"./history\";\nimport { HISTORY_TYPE, HistoryManaged } from \"./history-managed\";\nimport { SignalWatcherLitElement } from \"./signal-watcher-lit-element\";\nimport { noop } from \"@telperion/js-utils/function/noop\";\n\ndeclare global {\n interface HTMLElementTagNameMap {\n /**\n * A configuration element for managing router history settings.\n *\n * Behavior depends on placement:\n * - **In `<head>`**: Sets global history for all routers\n * - **In `<body>`**: Provides local history for descendant routers\n */\n \"tha-router-config\": ThaRouterConfig;\n }\n}\n\n/**\n * A custom element for configuring router history settings.\n *\n * This element serves dual purposes depending on its placement in the DOM:\n *\n * ## Global Configuration (placed in `<head>`)\n *\n * When placed in the `<head>` element, it sets the **global default history**\n * for all routers in the application that don't specify their own history or\n * inherit from a parent.\n *\n * ```html\n * <head>\n * <!-- All routers will use hash routing by default -->\n * <tha-router-config history=\"hash\"></tha-router-config>\n * </head>\n * <body>\n * <tha-router>\n * <!-- Uses hash history (global default) -->\n * <tha-route path=\"/home\">...</tha-route>\n * </tha-router>\n * </body>\n * ```\n *\n * ## Local Configuration (placed in `<body>`)\n *\n * When placed in the `<body>` element, it provides history configuration\n * for its **descendant routers only**. This allows different sections of\n * your application to use different history strategies.\n *\n * ```html\n * <body>\n * <!-- Section 1: Hash routing -->\n * <tha-router-config history=\"hash\">\n * <tha-router>\n * <!-- Uses hash history from parent config -->\n * <tha-route path=\"/dashboard\">...</tha-route>\n * </tha-router>\n * </tha-router-config>\n *\n * <!-- Section 2: Memory routing (isolated) -->\n * <tha-router-config history=\"memory\">\n * <tha-router>\n * <!-- Uses memory history from parent config -->\n * <tha-route path=\"/preview\">...</tha-route>\n * </tha-router>\n * </tha-router-config>\n * </body>\n * ```\n *\n * ## Usage Patterns\n *\n * ### Set Global Default\n *\n * Place in `<head>` to configure all routers:\n *\n * ```html\n * <!DOCTYPE html>\n * <html>\n * <head>\n * <tha-router-config history=\"browser\"></tha-router-config>\n * </head>\n * <body>\n * <!-- All routers use browser history -->\n * </body>\n * </html>\n * ```\n *\n * ### Override for Specific Section\n *\n * Use local config to override global default:\n *\n * ```html\n * <head>\n * <!-- Global: browser history -->\n * <tha-router-config history=\"browser\"></tha-router-config>\n * </head>\n * <body>\n * <!-- Main app uses browser history -->\n * <tha-router>...</tha-router>\n *\n * <!-- Admin section uses hash history -->\n * <tha-router-config history=\"hash\">\n * <tha-router>...</tha-router>\n * </tha-router-config>\n * </body>\n * ```\n *\n * ### Isolate Components with Memory History\n *\n * Use named memory history for component isolation:\n *\n * ```html\n * <body>\n * <!-- Each component has independent navigation -->\n * <tha-router-config history=\"memory:component1\">\n * <my-widget>\n * <tha-router>...</tha-router>\n * </my-widget>\n * </tha-router-config>\n *\n * <tha-router-config history=\"memory:component2\">\n * <my-widget>\n * <tha-router>...</tha-router>\n * </my-widget>\n * </tha-router-config>\n * </body>\n * ```\n *\n * ### Testing with Memory History\n *\n * Use memory history to avoid affecting browser URL during tests:\n *\n * ```typescript\n * import { fixture, html } from '@open-wc/testing';\n *\n * it('should navigate', async () => {\n * const el = await fixture(html`\n * <tha-router-config history=\"memory:test\">\n * <tha-router>\n * <tha-route path=\"/test\">Test Page</tha-route>\n * </tha-router>\n * </tha-router-config>\n * `);\n *\n * // Test navigation without affecting browser URL\n * });\n * ```\n *\n * ## History Resolution\n *\n * Router components resolve their history in this order:\n *\n * 1. **Own `history` attribute** (highest priority)\n * 2. **Parent `tha-router-config`** (local configuration)\n * 3. **Global `tha-router-config`** (in `<head>`)\n * 4. **Default** (`\"browser\"`)\n *\n * ## Best Practices\n *\n * ✅ **DO**: Place one `tha-router-config` in `<head>` for global settings\n *\n * ```html\n * <head>\n * <tha-router-config history=\"browser\"></tha-router-config>\n * </head>\n * ```\n *\n * ✅ **DO**: Use local configs for sections with different routing needs\n *\n * ```html\n * <tha-router-config history=\"memory\">\n * <component-preview>...</component-preview>\n * </tha-router-config>\n * ```\n *\n * ✅ **DO**: Use named memory history for isolated components\n *\n * ```html\n * <tha-router-config history=\"memory:sidebar\">\n * <sidebar-nav>...</sidebar-nav>\n * </tha-router-config>\n * ```\n *\n * ❌ **DON'T**: Place multiple configs in `<head>` (last one wins)\n *\n * ```html\n * <head>\n * <tha-router-config history=\"browser\"></tha-router-config>\n * <tha-router-config history=\"hash\"></tha-router-config> <!-- Overrides above -->\n * </head>\n * ```\n *\n * ❌ **DON'T**: Nest configs unnecessarily (inner configs take precedence)\n *\n * ```html\n * <tha-router-config history=\"browser\">\n * <tha-router-config history=\"hash\">\n * <!-- Uses hash, not browser -->\n * </tha-router-config>\n * </tha-router-config>\n * ```\n */\n@customElement('tha-router-config')\nexport class ThaRouterConfig extends HistoryManaged(SignalWatcherLitElement) {\n /**\n * Cleanup function for the global history effect.\n * Only used when the element is placed in `<head>`.\n * @private\n */\n #globalHistoryUnsubscribe = noop;\n\n /**\n * Called when the element is connected to the DOM.\n *\n * - If in `<head>`: Sets up a reactive effect to update global history\n * - If in `<body>`: Only provides history to descendants (no special setup)\n */\n override connectedCallback(): void {\n super.connectedCallback();\n\n if (!document.head.contains(this)) return;\n\n console.log('ThaRouterConfig: Setting global history type to', this[HISTORY_TYPE].get());\n\n // Set the global history type when this element is connected in <head>\n this.#globalHistoryUnsubscribe = this.updateEffect(() => {\n GLOBAL_HISTORY_TYPE.set(this[HISTORY_TYPE].get()!);\n });\n }\n\n /**\n * Called when the element is disconnected from the DOM.\n *\n * Cleans up the global history effect if it was set up.\n */\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n\n try {\n this.#globalHistoryUnsubscribe();\n } catch {}\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,209 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ThaRouterLink = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const lit_1 = require("lit");
6
+ const decorators_js_1 = require("lit/decorators.js");
7
+ const signals_1 = require("@lit-labs/signals");
8
+ const compact_1 = require("@telperion/js-utils/array/compact");
9
+ const noop_1 = require("@telperion/js-utils/function/noop");
10
+ const history_managed_1 = require("./history-managed");
11
+ const signal_watcher_lit_element_1 = require("./signal-watcher-lit-element");
12
+ /**
13
+ * A custom element that provides navigation links for client-side routing.
14
+ *
15
+ * The link handles click events to navigate using the History API, preventing
16
+ * full page reloads. It supports absolute paths, relative paths, and special
17
+ * symbols ('back', 'forward') for browser history navigation.
18
+ *
19
+ * The `active` attribute automatically reflects whether the link's path
20
+ * matches the current route, useful for styling active navigation items.
21
+ *
22
+ * @example
23
+ * ```html
24
+ * <!-- Absolute path -->
25
+ * <tha-router-link to="/about">About</tha-router-link>
26
+ *
27
+ * <!-- Relative path -->
28
+ * <tha-router-link to="./details">Details</tha-router-link>
29
+ * <tha-router-link to="../users">Back to Users</tha-router-link>
30
+ *
31
+ * <!-- History navigation -->
32
+ * <tha-router-link to="back">← Back</tha-router-link>
33
+ * <tha-router-link to="forward">Forward →</tha-router-link>
34
+ * ```
35
+ */
36
+ let ThaRouterLink = class ThaRouterLink extends (0, history_managed_1.HistoryManaged)(signal_watcher_lit_element_1.SignalWatcherLitElement) {
37
+ constructor() {
38
+ super(...arguments);
39
+ /**
40
+ * The navigation target. Can be:
41
+ * - Absolute path: `/users`, `/about`
42
+ * - Relative path: `./details`, `../users`
43
+ * - History symbol: `back`, `forward`
44
+ *
45
+ * @attr to
46
+ */
47
+ this.to = null;
48
+ /**
49
+ * Reflects whether this link matches the current route.
50
+ * Automatically updated when the route changes.
51
+ *
52
+ * @attr active
53
+ * @readonly
54
+ */
55
+ this.active = false;
56
+ /** Cleanup function for the active state effect */
57
+ this.#activeStateEffectCleaner = noop_1.noop;
58
+ /** Cleanup function to remove history listener */
59
+ this.#historyListenerRemover = noop_1.noop;
60
+ /** Signal containing the current 'to' value */
61
+ this.#to = (0, signals_1.signal)(null);
62
+ /** Computed URLPattern for matching against the current route */
63
+ this.#urlPattern = (0, signals_1.computed)(() => {
64
+ const to = this.#to.get();
65
+ if (!to || to === 'back' || to === 'forward')
66
+ return null;
67
+ try {
68
+ return new URLPattern({ pathname: to });
69
+ }
70
+ catch {
71
+ return null;
72
+ }
73
+ });
74
+ /**
75
+ * Handles click events to perform navigation.
76
+ *
77
+ * - For 'back'/'forward', calls the corresponding history method
78
+ * - For relative paths, resolves them against the current location
79
+ * - For absolute paths, navigates directly
80
+ *
81
+ * Prevents default link behavior to avoid full page reloads.
82
+ *
83
+ * @param event - The click event
84
+ */
85
+ this.#handleClick = (event) => {
86
+ const history = this[history_managed_1.HISTORY].get();
87
+ console.log(this[history_managed_1.HISTORY_TYPE].get());
88
+ if (this.to === 'back')
89
+ return history.back();
90
+ if (this.to === 'forward')
91
+ return history.forward();
92
+ const currentPath = history.location.pathname + history.location.search + history.location.hash;
93
+ let link = this.to;
94
+ if (link?.startsWith('.')) {
95
+ const segments = (0, compact_1.compact)(currentPath.split('/'));
96
+ const linkSegments = (0, compact_1.compact)(link.split('/'));
97
+ for (const segment of linkSegments) {
98
+ if (segment === '..') {
99
+ segments.pop();
100
+ }
101
+ else if (segment !== '.') {
102
+ segments.push(segment);
103
+ }
104
+ }
105
+ link = '/' + segments.join('/');
106
+ }
107
+ link = link?.replaceAll('//', '/');
108
+ this[history_managed_1.HISTORY].get()?.push(link || '/');
109
+ };
110
+ }
111
+ /** Injects global styles for tha-router-link elements to show pointer cursor */
112
+ static {
113
+ const styleEl = document.createElement("style");
114
+ styleEl.setAttribute("type", "text/css");
115
+ styleEl.setAttribute("data-id", "tha-router-link-styles");
116
+ styleEl.textContent = (0, lit_1.css) `
117
+ tha-router-link {
118
+ cursor: pointer;
119
+ }
120
+ `.toString();
121
+ document.head.appendChild(styleEl);
122
+ }
123
+ /** Cleanup function for the active state effect */
124
+ #activeStateEffectCleaner;
125
+ /** Cleanup function to remove history listener */
126
+ #historyListenerRemover;
127
+ /** Signal containing the current 'to' value */
128
+ #to;
129
+ /** Computed URLPattern for matching against the current route */
130
+ #urlPattern;
131
+ /**
132
+ * Lifecycle callback when the element is connected to the DOM.
133
+ * Sets up click listener and active state tracking effect.
134
+ */
135
+ connectedCallback() {
136
+ super.connectedCallback();
137
+ this.addEventListener('click', this.#handleClick);
138
+ this.#activeStateEffectCleaner = this.updateEffect(() => {
139
+ const history = this[history_managed_1.HISTORY].get();
140
+ const pattern = this.#urlPattern.get();
141
+ this.active = pattern?.test({ pathname: history?.location.pathname ?? '' }) ?? false;
142
+ this.#historyListenerRemover = history?.listen(() => {
143
+ this.active = pattern?.test({ pathname: history.location.pathname }) ?? false;
144
+ }) ?? noop_1.noop;
145
+ });
146
+ }
147
+ /**
148
+ * Lifecycle callback when an attribute changes.
149
+ * Updates signals when history or to attributes change.
150
+ *
151
+ * @param name - The attribute name that changed
152
+ * @param _old - The old attribute value
153
+ * @param value - The new attribute value
154
+ */
155
+ attributeChangedCallback(name, _old, value) {
156
+ super.attributeChangedCallback(name, _old, value);
157
+ switch (name) {
158
+ case 'to':
159
+ this.#to.set(value);
160
+ break;
161
+ }
162
+ }
163
+ /**
164
+ * Handles click events to perform navigation.
165
+ *
166
+ * - For 'back'/'forward', calls the corresponding history method
167
+ * - For relative paths, resolves them against the current location
168
+ * - For absolute paths, navigates directly
169
+ *
170
+ * Prevents default link behavior to avoid full page reloads.
171
+ *
172
+ * @param event - The click event
173
+ */
174
+ #handleClick;
175
+ /**
176
+ * Lifecycle callback when the element is disconnected from the DOM.
177
+ * Cleans up effects, listeners, and event handlers.
178
+ */
179
+ disconnectedCallback() {
180
+ super.disconnectedCallback();
181
+ try {
182
+ this.#activeStateEffectCleaner();
183
+ }
184
+ catch { }
185
+ this.#historyListenerRemover();
186
+ this.removeEventListener('click', this.#handleClick);
187
+ }
188
+ /**
189
+ * Creates the render root for the element.
190
+ * Returns the element itself to render content in light DOM.
191
+ *
192
+ * @returns The element itself (not a shadow root)
193
+ */
194
+ createRenderRoot() {
195
+ return this;
196
+ }
197
+ };
198
+ exports.ThaRouterLink = ThaRouterLink;
199
+ tslib_1.__decorate([
200
+ (0, decorators_js_1.property)({ type: String }),
201
+ tslib_1.__metadata("design:type", Object)
202
+ ], ThaRouterLink.prototype, "to", void 0);
203
+ tslib_1.__decorate([
204
+ (0, decorators_js_1.property)({ type: Boolean, reflect: true }),
205
+ tslib_1.__metadata("design:type", Object)
206
+ ], ThaRouterLink.prototype, "active", void 0);
207
+ exports.ThaRouterLink = ThaRouterLink = tslib_1.__decorate([
208
+ (0, decorators_js_1.customElement)("tha-router-link")
209
+ ], ThaRouterLink);
@@ -0,0 +1,95 @@
1
+ import { LitElement } from "lit";
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ /**
5
+ * A navigation link element for client-side routing.
6
+ * It handles click events to navigate using the History API without full page reloads.
7
+ * The `to` attribute specifies the navigation target (absolute, relative, or 'back'/'forward').
8
+ * The `active` attribute reflects whether the link matches the current route.
9
+ * The `history` attribute specifies which history instance to use.
10
+ */
11
+ "tha-router-link": ThaRouterLink;
12
+ }
13
+ }
14
+ /** Navigation symbols for browser history operations */
15
+ type LinkSymbol = 'back' | 'forward';
16
+ /** Absolute path starting with / */
17
+ type AbsolutePath = '/' | `/${string}`;
18
+ /** Relative path starting with ./ or ../ */
19
+ type RelativePath = './' | `./${string}` | `../${string}`;
20
+ /** Union of all supported link types */
21
+ type LinkType = LinkSymbol | AbsolutePath | RelativePath;
22
+ declare const ThaRouterLink_base: (new (...args: any[]) => import("./history-managed").HistoryManagedLitElementType) & (new () => LitElement & {
23
+ updateEffect(fn: () => void, options?: import("./signal-watcher-lit-element").EffectOptions): () => void;
24
+ });
25
+ /**
26
+ * A custom element that provides navigation links for client-side routing.
27
+ *
28
+ * The link handles click events to navigate using the History API, preventing
29
+ * full page reloads. It supports absolute paths, relative paths, and special
30
+ * symbols ('back', 'forward') for browser history navigation.
31
+ *
32
+ * The `active` attribute automatically reflects whether the link's path
33
+ * matches the current route, useful for styling active navigation items.
34
+ *
35
+ * @example
36
+ * ```html
37
+ * <!-- Absolute path -->
38
+ * <tha-router-link to="/about">About</tha-router-link>
39
+ *
40
+ * <!-- Relative path -->
41
+ * <tha-router-link to="./details">Details</tha-router-link>
42
+ * <tha-router-link to="../users">Back to Users</tha-router-link>
43
+ *
44
+ * <!-- History navigation -->
45
+ * <tha-router-link to="back">← Back</tha-router-link>
46
+ * <tha-router-link to="forward">Forward →</tha-router-link>
47
+ * ```
48
+ */
49
+ export declare class ThaRouterLink extends ThaRouterLink_base {
50
+ #private;
51
+ /**
52
+ * The navigation target. Can be:
53
+ * - Absolute path: `/users`, `/about`
54
+ * - Relative path: `./details`, `../users`
55
+ * - History symbol: `back`, `forward`
56
+ *
57
+ * @attr to
58
+ */
59
+ to: LinkType | null;
60
+ /**
61
+ * Reflects whether this link matches the current route.
62
+ * Automatically updated when the route changes.
63
+ *
64
+ * @attr active
65
+ * @readonly
66
+ */
67
+ active: boolean;
68
+ /**
69
+ * Lifecycle callback when the element is connected to the DOM.
70
+ * Sets up click listener and active state tracking effect.
71
+ */
72
+ connectedCallback(): void;
73
+ /**
74
+ * Lifecycle callback when an attribute changes.
75
+ * Updates signals when history or to attributes change.
76
+ *
77
+ * @param name - The attribute name that changed
78
+ * @param _old - The old attribute value
79
+ * @param value - The new attribute value
80
+ */
81
+ attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
82
+ /**
83
+ * Lifecycle callback when the element is disconnected from the DOM.
84
+ * Cleans up effects, listeners, and event handlers.
85
+ */
86
+ disconnectedCallback(): void;
87
+ /**
88
+ * Creates the render root for the element.
89
+ * Returns the element itself to render content in light DOM.
90
+ *
91
+ * @returns The element itself (not a shadow root)
92
+ */
93
+ protected createRenderRoot(): this;
94
+ }
95
+ export {};
@@ -0,0 +1,208 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { css } from "lit";
3
+ import { customElement, property } from "lit/decorators.js";
4
+ import { computed, signal } from "@lit-labs/signals";
5
+ import { compact } from '@telperion/js-utils/array/compact';
6
+ import { noop } from "@telperion/js-utils/function/noop";
7
+ import { HISTORY, HISTORY_TYPE, HistoryManaged } from "./history-managed";
8
+ import { SignalWatcherLitElement } from "./signal-watcher-lit-element";
9
+ /**
10
+ * A custom element that provides navigation links for client-side routing.
11
+ *
12
+ * The link handles click events to navigate using the History API, preventing
13
+ * full page reloads. It supports absolute paths, relative paths, and special
14
+ * symbols ('back', 'forward') for browser history navigation.
15
+ *
16
+ * The `active` attribute automatically reflects whether the link's path
17
+ * matches the current route, useful for styling active navigation items.
18
+ *
19
+ * @example
20
+ * ```html
21
+ * <!-- Absolute path -->
22
+ * <tha-router-link to="/about">About</tha-router-link>
23
+ *
24
+ * <!-- Relative path -->
25
+ * <tha-router-link to="./details">Details</tha-router-link>
26
+ * <tha-router-link to="../users">Back to Users</tha-router-link>
27
+ *
28
+ * <!-- History navigation -->
29
+ * <tha-router-link to="back">← Back</tha-router-link>
30
+ * <tha-router-link to="forward">Forward →</tha-router-link>
31
+ * ```
32
+ */
33
+ let ThaRouterLink = class ThaRouterLink extends HistoryManaged(SignalWatcherLitElement) {
34
+ constructor() {
35
+ super(...arguments);
36
+ /**
37
+ * The navigation target. Can be:
38
+ * - Absolute path: `/users`, `/about`
39
+ * - Relative path: `./details`, `../users`
40
+ * - History symbol: `back`, `forward`
41
+ *
42
+ * @attr to
43
+ */
44
+ this.to = null;
45
+ /**
46
+ * Reflects whether this link matches the current route.
47
+ * Automatically updated when the route changes.
48
+ *
49
+ * @attr active
50
+ * @readonly
51
+ */
52
+ this.active = false;
53
+ /** Cleanup function for the active state effect */
54
+ this.#activeStateEffectCleaner = noop;
55
+ /** Cleanup function to remove history listener */
56
+ this.#historyListenerRemover = noop;
57
+ /** Signal containing the current 'to' value */
58
+ this.#to = signal(null);
59
+ /** Computed URLPattern for matching against the current route */
60
+ this.#urlPattern = computed(() => {
61
+ const to = this.#to.get();
62
+ if (!to || to === 'back' || to === 'forward')
63
+ return null;
64
+ try {
65
+ return new URLPattern({ pathname: to });
66
+ }
67
+ catch {
68
+ return null;
69
+ }
70
+ });
71
+ /**
72
+ * Handles click events to perform navigation.
73
+ *
74
+ * - For 'back'/'forward', calls the corresponding history method
75
+ * - For relative paths, resolves them against the current location
76
+ * - For absolute paths, navigates directly
77
+ *
78
+ * Prevents default link behavior to avoid full page reloads.
79
+ *
80
+ * @param event - The click event
81
+ */
82
+ this.#handleClick = (event) => {
83
+ const history = this[HISTORY].get();
84
+ console.log(this[HISTORY_TYPE].get());
85
+ if (this.to === 'back')
86
+ return history.back();
87
+ if (this.to === 'forward')
88
+ return history.forward();
89
+ const currentPath = history.location.pathname + history.location.search + history.location.hash;
90
+ let link = this.to;
91
+ if (link?.startsWith('.')) {
92
+ const segments = compact(currentPath.split('/'));
93
+ const linkSegments = compact(link.split('/'));
94
+ for (const segment of linkSegments) {
95
+ if (segment === '..') {
96
+ segments.pop();
97
+ }
98
+ else if (segment !== '.') {
99
+ segments.push(segment);
100
+ }
101
+ }
102
+ link = '/' + segments.join('/');
103
+ }
104
+ link = link?.replaceAll('//', '/');
105
+ this[HISTORY].get()?.push(link || '/');
106
+ };
107
+ }
108
+ /** Injects global styles for tha-router-link elements to show pointer cursor */
109
+ static {
110
+ const styleEl = document.createElement("style");
111
+ styleEl.setAttribute("type", "text/css");
112
+ styleEl.setAttribute("data-id", "tha-router-link-styles");
113
+ styleEl.textContent = css `
114
+ tha-router-link {
115
+ cursor: pointer;
116
+ }
117
+ `.toString();
118
+ document.head.appendChild(styleEl);
119
+ }
120
+ /** Cleanup function for the active state effect */
121
+ #activeStateEffectCleaner;
122
+ /** Cleanup function to remove history listener */
123
+ #historyListenerRemover;
124
+ /** Signal containing the current 'to' value */
125
+ #to;
126
+ /** Computed URLPattern for matching against the current route */
127
+ #urlPattern;
128
+ /**
129
+ * Lifecycle callback when the element is connected to the DOM.
130
+ * Sets up click listener and active state tracking effect.
131
+ */
132
+ connectedCallback() {
133
+ super.connectedCallback();
134
+ this.addEventListener('click', this.#handleClick);
135
+ this.#activeStateEffectCleaner = this.updateEffect(() => {
136
+ const history = this[HISTORY].get();
137
+ const pattern = this.#urlPattern.get();
138
+ this.active = pattern?.test({ pathname: history?.location.pathname ?? '' }) ?? false;
139
+ this.#historyListenerRemover = history?.listen(() => {
140
+ this.active = pattern?.test({ pathname: history.location.pathname }) ?? false;
141
+ }) ?? noop;
142
+ });
143
+ }
144
+ /**
145
+ * Lifecycle callback when an attribute changes.
146
+ * Updates signals when history or to attributes change.
147
+ *
148
+ * @param name - The attribute name that changed
149
+ * @param _old - The old attribute value
150
+ * @param value - The new attribute value
151
+ */
152
+ attributeChangedCallback(name, _old, value) {
153
+ super.attributeChangedCallback(name, _old, value);
154
+ switch (name) {
155
+ case 'to':
156
+ this.#to.set(value);
157
+ break;
158
+ }
159
+ }
160
+ /**
161
+ * Handles click events to perform navigation.
162
+ *
163
+ * - For 'back'/'forward', calls the corresponding history method
164
+ * - For relative paths, resolves them against the current location
165
+ * - For absolute paths, navigates directly
166
+ *
167
+ * Prevents default link behavior to avoid full page reloads.
168
+ *
169
+ * @param event - The click event
170
+ */
171
+ #handleClick;
172
+ /**
173
+ * Lifecycle callback when the element is disconnected from the DOM.
174
+ * Cleans up effects, listeners, and event handlers.
175
+ */
176
+ disconnectedCallback() {
177
+ super.disconnectedCallback();
178
+ try {
179
+ this.#activeStateEffectCleaner();
180
+ }
181
+ catch { }
182
+ this.#historyListenerRemover();
183
+ this.removeEventListener('click', this.#handleClick);
184
+ }
185
+ /**
186
+ * Creates the render root for the element.
187
+ * Returns the element itself to render content in light DOM.
188
+ *
189
+ * @returns The element itself (not a shadow root)
190
+ */
191
+ createRenderRoot() {
192
+ return this;
193
+ }
194
+ };
195
+ __decorate([
196
+ property({ type: String }),
197
+ __metadata("design:type", Object)
198
+ ], ThaRouterLink.prototype, "to", void 0);
199
+ __decorate([
200
+ property({ type: Boolean, reflect: true }),
201
+ __metadata("design:type", Object)
202
+ ], ThaRouterLink.prototype, "active", void 0);
203
+ ThaRouterLink = __decorate([
204
+ customElement("tha-router-link")
205
+ ], ThaRouterLink);
206
+ export { ThaRouterLink };
207
+
208
+ //# sourceMappingURL=tha-router-link.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/elements/src/router/tha-router-link.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAc,MAAM,KAAK,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,mCAAmC,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAwBvE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,cAAc,CAAC,uBAAuB,CAAC;IAAnE;;QAeL;;;;;;;WAOG;QAEH,OAAE,GAAoB,IAAI,CAAC;QAE3B;;;;;;WAMG;QAEH,WAAM,GAAG,KAAK,CAAC;QAEf,mDAAmD;QACnD,8BAAyB,GAAG,IAAI,CAAC;QACjC,kDAAkD;QAClD,4BAAuB,GAAG,IAAI,CAAC;QAE/B,+CAA+C;QAC/C,QAAG,GAAG,MAAM,CAAkB,IAAI,CAAC,CAAC;QACpC,iEAAiE;QACjE,gBAAW,GAAG,QAAQ,CAAC,GAAG,EAAE;YA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xIC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;yCACA;AAU3B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;6CAC5B;AAlCJ,aAAa;IADzB,aAAa,CAAC,iBAAiB,CAAC;GACpB,aAAa,CAgKzB","file":"tha-router-link.js","sourcesContent":["import { css, LitElement } from \"lit\";\nimport { customElement, property } from \"lit/decorators.js\";\nimport { computed, signal } from \"@lit-labs/signals\";\nimport { compact } from '@telperion/js-utils/array/compact';\nimport { noop } from \"@telperion/js-utils/function/noop\";\nimport { HISTORY, HISTORY_TYPE, HistoryManaged } from \"./history-managed\";\nimport { SignalWatcherLitElement } from \"./signal-watcher-lit-element\";\n\ndeclare global {\n interface HTMLElementTagNameMap {\n /**\n * A navigation link element for client-side routing.\n * It handles click events to navigate using the History API without full page reloads.\n * The `to` attribute specifies the navigation target (absolute, relative, or 'back'/'forward').\n * The `active` attribute reflects whether the link matches the current route.\n * The `history` attribute specifies which history instance to use.\n */\n \"tha-router-link\": ThaRouterLink;\n }\n}\n\n/** Navigation symbols for browser history operations */\ntype LinkSymbol = 'back' | 'forward';\n/** Absolute path starting with / */\ntype AbsolutePath = '/' | `/${string}`;\n/** Relative path starting with ./ or ../ */\ntype RelativePath = './' | `./${string}` | `../${string}`;\n/** Union of all supported link types */\ntype LinkType = LinkSymbol | AbsolutePath | RelativePath;\n\n/**\n * A custom element that provides navigation links for client-side routing.\n *\n * The link handles click events to navigate using the History API, preventing\n * full page reloads. It supports absolute paths, relative paths, and special\n * symbols ('back', 'forward') for browser history navigation.\n *\n * The `active` attribute automatically reflects whether the link's path\n * matches the current route, useful for styling active navigation items.\n *\n * @example\n * ```html\n * <!-- Absolute path -->\n * <tha-router-link to=\"/about\">About</tha-router-link>\n *\n * <!-- Relative path -->\n * <tha-router-link to=\"./details\">Details</tha-router-link>\n * <tha-router-link to=\"../users\">Back to Users</tha-router-link>\n *\n * <!-- History navigation -->\n * <tha-router-link to=\"back\">← Back</tha-router-link>\n * <tha-router-link to=\"forward\">Forward →</tha-router-link>\n * ```\n */\n@customElement(\"tha-router-link\")\nexport class ThaRouterLink extends HistoryManaged(SignalWatcherLitElement) {\n /** Injects global styles for tha-router-link elements to show pointer cursor */\n static {\n const styleEl = document.createElement(\"style\");\n\n styleEl.setAttribute(\"type\", \"text/css\");\n styleEl.setAttribute(\"data-id\", \"tha-router-link-styles\");\n styleEl.textContent = css`\n tha-router-link {\n cursor: pointer;\n }\n `.toString();\n document.head.appendChild(styleEl);\n }\n\n /**\n * The navigation target. Can be:\n * - Absolute path: `/users`, `/about`\n * - Relative path: `./details`, `../users`\n * - History symbol: `back`, `forward`\n *\n * @attr to\n */\n @property({ type: String })\n to: LinkType | null = null;\n\n /**\n * Reflects whether this link matches the current route.\n * Automatically updated when the route changes.\n *\n * @attr active\n * @readonly\n */\n @property({ type: Boolean, reflect: true })\n active = false;\n\n /** Cleanup function for the active state effect */\n #activeStateEffectCleaner = noop;\n /** Cleanup function to remove history listener */\n #historyListenerRemover = noop;\n\n /** Signal containing the current 'to' value */\n #to = signal<LinkType | null>(null);\n /** Computed URLPattern for matching against the current route */\n #urlPattern = computed(() => {\n const to = this.#to.get();\n if (!to || to === 'back' || to === 'forward') return null;\n\n try {\n return new URLPattern({ pathname: to });\n } catch {\n return null;\n }\n });\n\n /**\n * Lifecycle callback when the element is connected to the DOM.\n * Sets up click listener and active state tracking effect.\n */\n override connectedCallback(): void {\n super.connectedCallback();\n\n this.addEventListener('click', this.#handleClick);\n\n this.#activeStateEffectCleaner = (this as any).updateEffect(() => {\n const history = this[HISTORY].get();\n const pattern = this.#urlPattern.get();\n\n this.active = pattern?.test({ pathname: history?.location.pathname ?? '' }) ?? false;\n\n this.#historyListenerRemover = history?.listen(() => {\n this.active = pattern?.test({ pathname: history.location.pathname }) ?? false;\n }) ?? noop;\n });\n }\n\n /**\n * Lifecycle callback when an attribute changes.\n * Updates signals when history or to attributes change.\n *\n * @param name - The attribute name that changed\n * @param _old - The old attribute value\n * @param value - The new attribute value\n */\n override attributeChangedCallback(name: string, _old: string | null, value: string | null): void {\n super.attributeChangedCallback(name, _old, value);\n\n switch (name) {\n case 'to':\n this.#to.set(value as LinkType | null);\n break;\n }\n }\n\n /**\n * Handles click events to perform navigation.\n *\n * - For 'back'/'forward', calls the corresponding history method\n * - For relative paths, resolves them against the current location\n * - For absolute paths, navigates directly\n *\n * Prevents default link behavior to avoid full page reloads.\n *\n * @param event - The click event\n */\n #handleClick = (event: MouseEvent) => {\n const history = this[HISTORY].get();\n\n console.log(this[HISTORY_TYPE].get());\n\n if (this.to === 'back') return history.back();\n if (this.to === 'forward') return history.forward();\n\n const currentPath = history.location.pathname + history.location.search + history.location.hash;\n\n let link = this.to;\n if (link?.startsWith('.')) {\n const segments = compact(currentPath.split('/'));\n const linkSegments = compact(link!.split('/'));\n\n for (const segment of linkSegments) {\n if (segment === '..') {\n segments.pop();\n } else if (segment !== '.') {\n segments.push(segment);\n }\n }\n\n link = '/' + segments.join('/');\n }\n\n link = link?.replaceAll('//', '/') as '/';\n\n this[HISTORY].get()?.push(link || '/');\n };\n\n /**\n * Lifecycle callback when the element is disconnected from the DOM.\n * Cleans up effects, listeners, and event handlers.\n */\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n\n try {\n this.#activeStateEffectCleaner();\n } catch {}\n\n this.#historyListenerRemover();\n this.removeEventListener('click', this.#handleClick);\n }\n\n /**\n * Creates the render root for the element.\n * Returns the element itself to render content in light DOM.\n *\n * @returns The element itself (not a shadow root)\n */\n protected override createRenderRoot() {\n return this;\n }\n}\n"]}