@tailng-ui/primitives 0.27.0 → 0.30.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/README.md +1 -1
- package/package.json +2 -4
- package/src/lib/form/_shared/select/tng-select.overlay.shared.d.ts +2 -0
- package/src/lib/form/_shared/select/tng-select.overlay.shared.d.ts.map +1 -1
- package/src/lib/form/_shared/select/tng-select.overlay.shared.js +94 -1
- package/src/lib/form/_shared/select/tng-select.overlay.shared.js.map +1 -1
- package/src/lib/form/autocomplete/tng-autocomplete.overlay.d.ts +2 -0
- package/src/lib/form/autocomplete/tng-autocomplete.overlay.d.ts.map +1 -1
- package/src/lib/form/autocomplete/tng-autocomplete.overlay.js +87 -0
- package/src/lib/form/autocomplete/tng-autocomplete.overlay.js.map +1 -1
- package/src/lib/form/index.d.ts +0 -1
- package/src/lib/form/index.d.ts.map +1 -1
- package/src/lib/form/index.js +0 -1
- package/src/lib/form/index.js.map +1 -1
- package/src/lib/form/input-otp/tng-input-otp.d.ts +49 -3
- package/src/lib/form/input-otp/tng-input-otp.d.ts.map +1 -1
- package/src/lib/form/input-otp/tng-input-otp.js +372 -9
- package/src/lib/form/input-otp/tng-input-otp.js.map +1 -1
- package/src/lib/form/combobox/tng-combobox.d.ts +0 -7
- package/src/lib/form/combobox/tng-combobox.d.ts.map +0 -1
- package/src/lib/form/combobox/tng-combobox.js +0 -18
- package/src/lib/form/combobox/tng-combobox.js.map +0 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Headless Angular primitives for TailNG UI, providing accessibility-first behavio
|
|
|
12
12
|
<h1>@tailng-ui/primitives</h1>
|
|
13
13
|
|
|
14
14
|
<p>
|
|
15
|
-
<strong>
|
|
15
|
+
<strong>Accessible Angular UI, built to be owned.</strong>
|
|
16
16
|
</p>
|
|
17
17
|
|
|
18
18
|
<p>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tailng-ui/primitives",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,11 +15,9 @@
|
|
|
15
15
|
"default": "./src/index.js"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"@tailng-ui/cdk": "^0.22.0"
|
|
20
|
-
},
|
|
21
18
|
"peerDependencies": {
|
|
22
19
|
"@angular/core": "^21.1.0",
|
|
20
|
+
"@tailng-ui/cdk": "^0.24.0",
|
|
23
21
|
"tslib": "^2.3.0"
|
|
24
22
|
},
|
|
25
23
|
"sideEffects": false
|
|
@@ -30,6 +30,8 @@ export declare class TngSelectOverlay {
|
|
|
30
30
|
private setupRepositionListeners;
|
|
31
31
|
private teardownRepositionListeners;
|
|
32
32
|
private findTriggerEl;
|
|
33
|
+
private syncPortalledThemeVars;
|
|
34
|
+
private clearPortalledThemeVars;
|
|
33
35
|
private mountToBodyAndPosition;
|
|
34
36
|
private restoreToPlaceholder;
|
|
35
37
|
private setupOutsidePointer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tng-select.overlay.shared.d.ts","sourceRoot":"","sources":["../../../../../../../../../libs/tailng-ui/primitives/src/lib/form/_shared/select/tng-select.overlay.shared.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"tng-select.overlay.shared.d.ts","sourceRoot":"","sources":["../../../../../../../../../libs/tailng-ui/primitives/src/lib/form/_shared/select/tng-select.overlay.shared.ts"],"names":[],"mappings":";AAmGA,qBAIa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA6C;IAClE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmC;IACzD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IAEjD,OAAO,CAAC,qBAAqB,CAA4B;IACzD,OAAO,CAAC,oBAAoB,CAA6B;IACzD,OAAO,CAAC,oBAAoB,CAA6B;IACzD,OAAO,CAAC,cAAc,CAA+B;IAErD,QAAQ,CAAC,SAAS;;;oBAAqD;IACvE,QAAQ,CAAC,MAAM;;;oBAAkD;IACjE,QAAQ,CAAC,SAAS;;;;oBAA4D;IAG9E,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAoB;IAGjE,SAAS,KAAK,MAAM,IAAI,EAAE,GAAG,IAAI,CAEhC;IAED,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAqB;IAC3C,OAAO,CAAC,wBAAwB,CAA6B;;IAsB7D,OAAO,CAAC,UAAU;IAuBlB,OAAO,CAAC,wBAAwB;IAyBhC,OAAO,CAAC,2BAA2B;IASnC,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,sBAAsB;IAqB9B,OAAO,CAAC,uBAAuB;IAU/B,OAAO,CAAC,sBAAsB;IA4C9B,OAAO,CAAC,oBAAoB;IAqC5B,OAAO,CAAC,mBAAmB;IA0B3B,OAAO,CAAC,sBAAsB;IAK9B,OAAO,CAAC,mBAAmB;yCA3PhB,gBAAgB;2CAAhB,gBAAgB;CAwQ5B"}
|
|
@@ -2,6 +2,66 @@ import { DestroyRef, Directive, ElementRef, HostBinding, inject, input, effect,
|
|
|
2
2
|
import { computeOverlayPosition } from '@tailng-ui/cdk';
|
|
3
3
|
import { TNG_SELECT_HOST } from './tng-select.tokens.shared';
|
|
4
4
|
import * as i0 from "@angular/core";
|
|
5
|
+
const PORTALLED_SELECT_THEME_VARS = [
|
|
6
|
+
'--tng-select-radius',
|
|
7
|
+
'--tng-select-trigger-width',
|
|
8
|
+
'--tng-select-trigger-min-height',
|
|
9
|
+
'--tng-select-trigger-py',
|
|
10
|
+
'--tng-select-trigger-px',
|
|
11
|
+
'--tng-select-trigger-gap',
|
|
12
|
+
'--tng-select-icon-size',
|
|
13
|
+
'--tng-select-icon-opacity',
|
|
14
|
+
'--tng-select-icon-margin-inline-start',
|
|
15
|
+
'--tng-select-overlay-padding',
|
|
16
|
+
'--tng-select-overlay-radius',
|
|
17
|
+
'--tng-select-overlay-shadow',
|
|
18
|
+
'--tng-select-overlay-max-width',
|
|
19
|
+
'--tng-select-overlay-border',
|
|
20
|
+
'--tng-select-overlay-bg',
|
|
21
|
+
'--tng-select-overlay-max-height',
|
|
22
|
+
'--tng-select-listbox-gap',
|
|
23
|
+
'--tng-select-option-min-height',
|
|
24
|
+
'--tng-select-option-py',
|
|
25
|
+
'--tng-select-option-px',
|
|
26
|
+
'--tng-select-option-radius',
|
|
27
|
+
'--tng-select-option-bg-active',
|
|
28
|
+
'--tng-select-option-border-active',
|
|
29
|
+
'--tng-select-option-bg-selected',
|
|
30
|
+
'--tng-select-option-border-selected',
|
|
31
|
+
'--tng-select-option-fg-selected',
|
|
32
|
+
'--tng-select-option-bg-selected-active',
|
|
33
|
+
'--tng-select-option-border-selected-active',
|
|
34
|
+
'--tng-select-option-shadow-selected-active',
|
|
35
|
+
'--tng-select-option-disabled-opacity',
|
|
36
|
+
'--tng-select-option-font-weight',
|
|
37
|
+
'--tng-select-value-font-size',
|
|
38
|
+
'--tng-select-value-font-weight',
|
|
39
|
+
'--tng-select-value-color',
|
|
40
|
+
'--tng-select-icon-margin-inline-end',
|
|
41
|
+
'--tng-select-border',
|
|
42
|
+
'--tng-select-border-strong',
|
|
43
|
+
'--tng-select-border-hover',
|
|
44
|
+
'--tng-select-bg',
|
|
45
|
+
'--tng-select-surface',
|
|
46
|
+
'--tng-select-fg',
|
|
47
|
+
'--tng-select-muted',
|
|
48
|
+
'--tng-select-brand',
|
|
49
|
+
'--tng-select-danger',
|
|
50
|
+
'--tng-select-focus-ring',
|
|
51
|
+
'--tng-select-ease',
|
|
52
|
+
'--tng-select-shadow',
|
|
53
|
+
'--tng-select-shadow-focus',
|
|
54
|
+
'--tng-semantic-background-base',
|
|
55
|
+
'--tng-semantic-background-surface',
|
|
56
|
+
'--tng-semantic-border-subtle',
|
|
57
|
+
'--tng-semantic-border-strong',
|
|
58
|
+
'--tng-semantic-foreground-primary',
|
|
59
|
+
'--tng-semantic-foreground-secondary',
|
|
60
|
+
'--tng-semantic-foreground-muted',
|
|
61
|
+
'--tng-semantic-accent-brand',
|
|
62
|
+
'--tng-semantic-accent-danger',
|
|
63
|
+
'--tng-semantic-focus-ring',
|
|
64
|
+
];
|
|
5
65
|
function rectFromClientRect(r) {
|
|
6
66
|
return { left: r.left, top: r.top, width: r.width, height: r.height };
|
|
7
67
|
}
|
|
@@ -105,6 +165,33 @@ export class TngSelectOverlay {
|
|
|
105
165
|
const root = this.host.hostElement;
|
|
106
166
|
return root.querySelector('[data-slot="select-trigger"]');
|
|
107
167
|
}
|
|
168
|
+
syncPortalledThemeVars() {
|
|
169
|
+
const panel = this.elRef.nativeElement;
|
|
170
|
+
const hostStyles = getComputedStyle(this.host.hostElement);
|
|
171
|
+
for (const cssVar of PORTALLED_SELECT_THEME_VARS) {
|
|
172
|
+
const value = hostStyles.getPropertyValue(cssVar).trim();
|
|
173
|
+
if (value) {
|
|
174
|
+
panel.style.setProperty(cssVar, value);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
panel.style.removeProperty(cssVar);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const colorScheme = hostStyles.colorScheme?.trim();
|
|
181
|
+
if (colorScheme && colorScheme !== 'normal') {
|
|
182
|
+
panel.style.colorScheme = colorScheme;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
panel.style.removeProperty('color-scheme');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
clearPortalledThemeVars() {
|
|
189
|
+
const panel = this.elRef.nativeElement;
|
|
190
|
+
for (const cssVar of PORTALLED_SELECT_THEME_VARS) {
|
|
191
|
+
panel.style.removeProperty(cssVar);
|
|
192
|
+
}
|
|
193
|
+
panel.style.removeProperty('color-scheme');
|
|
194
|
+
}
|
|
108
195
|
mountToBodyAndPosition() {
|
|
109
196
|
this.lastFocusedBeforeOpen = document.activeElement;
|
|
110
197
|
this.setupRepositionListeners();
|
|
@@ -116,6 +203,7 @@ export class TngSelectOverlay {
|
|
|
116
203
|
panel.style.left = '0px';
|
|
117
204
|
panel.style.top = '0px';
|
|
118
205
|
panel.style.zIndex = '1000';
|
|
206
|
+
this.syncPortalledThemeVars();
|
|
119
207
|
queueMicrotask(() => {
|
|
120
208
|
if (!this.host.open())
|
|
121
209
|
return;
|
|
@@ -123,7 +211,10 @@ export class TngSelectOverlay {
|
|
|
123
211
|
if (!trigger)
|
|
124
212
|
return;
|
|
125
213
|
const anchor = rectFromClientRect(trigger.getBoundingClientRect());
|
|
126
|
-
|
|
214
|
+
const viewportWidth = viewportRect().width;
|
|
215
|
+
const inlineSize = Math.max(0, Math.min(anchor.width, viewportWidth - 16));
|
|
216
|
+
panel.style.width = `${inlineSize}px`;
|
|
217
|
+
panel.style.minWidth = `${inlineSize}px`;
|
|
127
218
|
const overlay = rectFromClientRect(panel.getBoundingClientRect());
|
|
128
219
|
const viewport = viewportRect();
|
|
129
220
|
const result = computeOverlayPosition({
|
|
@@ -165,7 +256,9 @@ export class TngSelectOverlay {
|
|
|
165
256
|
panel.style.left = '';
|
|
166
257
|
panel.style.top = '';
|
|
167
258
|
panel.style.zIndex = '';
|
|
259
|
+
panel.style.width = '';
|
|
168
260
|
panel.style.minWidth = '';
|
|
261
|
+
this.clearPortalledThemeVars();
|
|
169
262
|
this.teardownOutsidePointer();
|
|
170
263
|
}
|
|
171
264
|
setupOutsidePointer() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tng-select.overlay.shared.js","sourceRoot":"","sources":["../../../../../../../../../libs/tailng-ui/primitives/src/lib/form/_shared/select/tng-select.overlay.shared.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACX,MAAM,EACN,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;AAMvB,OAAO,EAAE,sB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AE,CAAC;YACrC,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACrC,OAAO,EAAE,KAAK,EAAE,CAAC;YACjB,OAAO;QACT,CAAC;QACD,IAAI,QAAQ,CAAC,aAAa,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACrC,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;uGAlOU,gBAAgB;2FAAhB,gBAAgB;;2FAAhB,gBAAgB;kBAJ5B,SAAS;mBAAC;oBACT,QAAQ,EAAE,oBAAoB;oBAC9B,QAAQ,EAAE,kBAAkB;iBAC7B;;sBAeE,WAAW;uBAAC,gBAAgB;;sBAG5B,WAAW;uBAAC,aAAa","sourcesContent":["import {\n DestroyRef,\n Directive,\n ElementRef,\n HostBinding,\n inject,\n input,\n effect,\n} from '@angular/core';\nimport type {\n TngOverlayCollisionOptions,\n TngOverlayOffset,\n TngOverlayPlacement,\n} from '@tailng-ui/cdk';\nimport { computeOverlayPosition } from '@tailng-ui/cdk';\n\nimport { TNG_SELECT_HOST } from './tng-select.tokens.shared';\nimport type { TngSelectHostApi } from './tng-select.host-api';\n\ntype MaybeRect = Readonly<{\n left: number;\n top: number;\n width: number;\n height: number;\n}>;\n\nfunction rectFromClientRect(r: DOMRect | ClientRect): MaybeRect {\n return { left: r.left, top: r.top, width: r.width, height: r.height };\n}\n\nfunction viewportRect(): MaybeRect {\n return { left: 0, top: 0, width: window.innerWidth || 1024, height: window.innerHeight || 768 };\n}\n\nfunction isInside(target: EventTarget | null, container: HTMLElement): boolean {\n return !!target && target instanceof Node && container.contains(target);\n}\n\n@Directive({\n selector: '[tngSelectOverlay]',\n exportAs: 'tngSelectOverlay',\n})\nexport class TngSelectOverlay {\n private readonly host = inject<TngSelectHostApi>(TNG_SELECT_HOST);\n private readonly elRef = inject(ElementRef<HTMLElement>);\n private readonly destroyRef = inject(DestroyRef);\n\n private lastFocusedBeforeOpen: HTMLElement | null = null;\n private removeResizeListener: (() => void) | null = null;\n private removeScrollListener: (() => void) | null = null;\n private resizeObserver: ResizeObserver | null = null;\n\n readonly placement = input<TngOverlayPlacement | undefined>(undefined);\n readonly offset = input<TngOverlayOffset | undefined>(undefined);\n readonly collision = input<TngOverlayCollisionOptions | undefined>(undefined);\n\n @HostBinding('attr.data-slot')\n protected readonly dataSlot: 'select-overlay' = 'select-overlay';\n\n @HostBinding('attr.hidden')\n protected get hidden(): '' | null {\n return this.host.open() ? null : '';\n }\n\n private placeholder: Comment | null = null;\n private originalParent: Node | null = null;\n private removeDocPointerListener: (() => void) | null = null;\n\n constructor() {\n this.placeholder = document.createComment('tng-select-overlay-anchor');\n const hostEl = this.elRef.nativeElement;\n this.originalParent = hostEl.parentNode;\n this.originalParent?.insertBefore(this.placeholder, hostEl);\n\n effect(() => {\n const open = this.host.open();\n if (open) this.mountToBodyAndPosition();\n else this.restoreToPlaceholder();\n });\n\n this.destroyRef.onDestroy(() => {\n this.teardownOutsidePointer();\n this.restoreToPlaceholder(true);\n this.placeholder = null;\n this.originalParent = null;\n });\n }\n\n private reposition(): void {\n if (!this.host.open()) return;\n const panel = this.elRef.nativeElement;\n const trigger = this.findTriggerEl();\n if (!trigger) return;\n\n const anchor = rectFromClientRect(trigger.getBoundingClientRect());\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n placement: this.placement(),\n offset: this.offset(),\n collision: this.collision(),\n });\n\n panel.style.left = `${result.x}px`;\n panel.style.top = `${result.y}px`;\n }\n\n private setupRepositionListeners(): void {\n let rafId: number | null = null;\n const schedule = () => {\n if (rafId !== null) return;\n rafId = requestAnimationFrame(() => {\n rafId = null;\n this.reposition();\n });\n };\n\n const onResize = () => schedule();\n const onScroll = () => schedule();\n window.addEventListener('resize', onResize);\n window.addEventListener('scroll', onScroll, true);\n this.removeResizeListener = () => window.removeEventListener('resize', onResize);\n this.removeScrollListener = () => window.removeEventListener('scroll', onScroll, true);\n\n if ('ResizeObserver' in window) {\n this.resizeObserver = new ResizeObserver(() => schedule());\n const trigger = this.findTriggerEl();\n if (trigger) this.resizeObserver.observe(trigger);\n this.resizeObserver.observe(this.elRef.nativeElement);\n }\n }\n\n private teardownRepositionListeners(): void {\n this.removeResizeListener?.();\n this.removeScrollListener?.();\n this.removeResizeListener = null;\n this.removeScrollListener = null;\n this.resizeObserver?.disconnect();\n this.resizeObserver = null;\n }\n\n private findTriggerEl(): HTMLElement | null {\n const root = this.host.hostElement;\n return root.querySelector('[data-slot=\"select-trigger\"]') as HTMLElement | null;\n }\n\n private mountToBodyAndPosition(): void {\n this.lastFocusedBeforeOpen = document.activeElement as HTMLElement | null;\n this.setupRepositionListeners();\n const panel = this.elRef.nativeElement;\n\n if (panel.parentNode !== document.body) {\n document.body.appendChild(panel);\n }\n\n panel.style.position = 'fixed';\n panel.style.left = '0px';\n panel.style.top = '0px';\n panel.style.zIndex = '1000';\n\n queueMicrotask(() => {\n if (!this.host.open()) return;\n const trigger = this.findTriggerEl();\n if (!trigger) return;\n\n const anchor = rectFromClientRect(trigger.getBoundingClientRect());\n panel.style.minWidth = `${anchor.width}px`;\n\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n placement: this.placement(),\n offset: this.offset(),\n collision: this.collision(),\n });\n\n panel.style.left = `${result.x}px`;\n panel.style.top = `${result.y}px`;\n });\n\n this.setupOutsidePointer();\n }\n\n private restoreToPlaceholder(force = false): void {\n const panel = this.elRef.nativeElement;\n if (!force && panel.parentNode !== document.body) {\n this.teardownOutsidePointer();\n return;\n }\n\n if (this.placeholder?.parentNode) {\n this.placeholder.parentNode.insertBefore(panel, this.placeholder);\n } else if (this.originalParent) {\n this.originalParent.appendChild(panel);\n }\n\n this.teardownRepositionListeners();\n\n if (\n this.lastFocusedBeforeOpen &&\n document.contains(this.lastFocusedBeforeOpen)\n ) {\n const active = document.activeElement as HTMLElement | null;\n const panelEl = this.elRef.nativeElement;\n if (!active || panelEl.contains(active)) {\n this.lastFocusedBeforeOpen.focus();\n }\n }\n\n this.restoreFocusOnClose();\n panel.style.position = '';\n panel.style.left = '';\n panel.style.top = '';\n panel.style.zIndex = '';\n panel.style.minWidth = '';\n this.teardownOutsidePointer();\n }\n\n private setupOutsidePointer(): void {\n if (this.removeDocPointerListener) return;\n\n const onPointerDown = (ev: PointerEvent) => {\n if (!this.host.open()) return;\n const panel = this.elRef.nativeElement;\n const trigger = this.findTriggerEl();\n if (isInside(ev.target, panel)) return;\n if (trigger && isInside(ev.target, trigger)) return;\n if (\n this.host.multiple() &&\n ev.target &&\n (ev.target as Element).closest?.(\n '[data-slot=\"select-option\"], [data-slot=\"multi-select-option\"]'\n )\n )\n return;\n this.host.close();\n };\n\n document.addEventListener('pointerdown', onPointerDown, true);\n this.removeDocPointerListener = () => {\n document.removeEventListener('pointerdown', onPointerDown, true);\n };\n }\n\n private teardownOutsidePointer(): void {\n this.removeDocPointerListener?.();\n this.removeDocPointerListener = null;\n }\n\n private restoreFocusOnClose(): void {\n const panel = this.elRef.nativeElement;\n const active = document.activeElement as HTMLElement | null;\n if (active && panel.contains(active)) {\n const trigger = this.findTriggerEl();\n trigger?.focus();\n return;\n }\n if (document.activeElement === document.body) {\n const trigger = this.findTriggerEl();\n trigger?.focus();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tng-select.overlay.shared.js","sourceRoot":"","sources":["../../../../../../../../../libs/tailng-ui/primitives/src/lib/form/_shared/select/tng-select.overlay.shared.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACX,MAAM,EACN,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;AAMvB,OAAO,EAAE,sBAAsB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AC;QACD,IAAI,QAAQ,CAAC,aAAa,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACrC,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;uGAvQU,gBAAgB;2FAAhB,gBAAgB;;2FAAhB,gBAAgB;kBAJ5B,SAAS;mBAAC;oBACT,QAAQ,EAAE,oBAAoB;oBAC9B,QAAQ,EAAE,kBAAkB;iBAC7B;;sBAeE,WAAW;uBAAC,gBAAgB;;sBAG5B,WAAW;uBAAC,aAAa","sourcesContent":["import {\n DestroyRef,\n Directive,\n ElementRef,\n HostBinding,\n inject,\n input,\n effect,\n} from '@angular/core';\nimport type {\n TngOverlayCollisionOptions,\n TngOverlayOffset,\n TngOverlayPlacement,\n} from '@tailng-ui/cdk';\nimport { computeOverlayPosition } from '@tailng-ui/cdk';\n\nimport { TNG_SELECT_HOST } from './tng-select.tokens.shared';\nimport type { TngSelectHostApi } from './tng-select.host-api';\n\ntype MaybeRect = Readonly<{\n left: number;\n top: number;\n width: number;\n height: number;\n}>;\n\nconst PORTALLED_SELECT_THEME_VARS = [\n '--tng-select-radius',\n '--tng-select-trigger-width',\n '--tng-select-trigger-min-height',\n '--tng-select-trigger-py',\n '--tng-select-trigger-px',\n '--tng-select-trigger-gap',\n '--tng-select-icon-size',\n '--tng-select-icon-opacity',\n '--tng-select-icon-margin-inline-start',\n '--tng-select-overlay-padding',\n '--tng-select-overlay-radius',\n '--tng-select-overlay-shadow',\n '--tng-select-overlay-max-width',\n '--tng-select-overlay-border',\n '--tng-select-overlay-bg',\n '--tng-select-overlay-max-height',\n '--tng-select-listbox-gap',\n '--tng-select-option-min-height',\n '--tng-select-option-py',\n '--tng-select-option-px',\n '--tng-select-option-radius',\n '--tng-select-option-bg-active',\n '--tng-select-option-border-active',\n '--tng-select-option-bg-selected',\n '--tng-select-option-border-selected',\n '--tng-select-option-fg-selected',\n '--tng-select-option-bg-selected-active',\n '--tng-select-option-border-selected-active',\n '--tng-select-option-shadow-selected-active',\n '--tng-select-option-disabled-opacity',\n '--tng-select-option-font-weight',\n '--tng-select-value-font-size',\n '--tng-select-value-font-weight',\n '--tng-select-value-color',\n '--tng-select-icon-margin-inline-end',\n '--tng-select-border',\n '--tng-select-border-strong',\n '--tng-select-border-hover',\n '--tng-select-bg',\n '--tng-select-surface',\n '--tng-select-fg',\n '--tng-select-muted',\n '--tng-select-brand',\n '--tng-select-danger',\n '--tng-select-focus-ring',\n '--tng-select-ease',\n '--tng-select-shadow',\n '--tng-select-shadow-focus',\n '--tng-semantic-background-base',\n '--tng-semantic-background-surface',\n '--tng-semantic-border-subtle',\n '--tng-semantic-border-strong',\n '--tng-semantic-foreground-primary',\n '--tng-semantic-foreground-secondary',\n '--tng-semantic-foreground-muted',\n '--tng-semantic-accent-brand',\n '--tng-semantic-accent-danger',\n '--tng-semantic-focus-ring',\n] as const;\n\nfunction rectFromClientRect(r: DOMRect | ClientRect): MaybeRect {\n return { left: r.left, top: r.top, width: r.width, height: r.height };\n}\n\nfunction viewportRect(): MaybeRect {\n return { left: 0, top: 0, width: window.innerWidth || 1024, height: window.innerHeight || 768 };\n}\n\nfunction isInside(target: EventTarget | null, container: HTMLElement): boolean {\n return !!target && target instanceof Node && container.contains(target);\n}\n\n@Directive({\n selector: '[tngSelectOverlay]',\n exportAs: 'tngSelectOverlay',\n})\nexport class TngSelectOverlay {\n private readonly host = inject<TngSelectHostApi>(TNG_SELECT_HOST);\n private readonly elRef = inject(ElementRef<HTMLElement>);\n private readonly destroyRef = inject(DestroyRef);\n\n private lastFocusedBeforeOpen: HTMLElement | null = null;\n private removeResizeListener: (() => void) | null = null;\n private removeScrollListener: (() => void) | null = null;\n private resizeObserver: ResizeObserver | null = null;\n\n readonly placement = input<TngOverlayPlacement | undefined>(undefined);\n readonly offset = input<TngOverlayOffset | undefined>(undefined);\n readonly collision = input<TngOverlayCollisionOptions | undefined>(undefined);\n\n @HostBinding('attr.data-slot')\n protected readonly dataSlot: 'select-overlay' = 'select-overlay';\n\n @HostBinding('attr.hidden')\n protected get hidden(): '' | null {\n return this.host.open() ? null : '';\n }\n\n private placeholder: Comment | null = null;\n private originalParent: Node | null = null;\n private removeDocPointerListener: (() => void) | null = null;\n\n constructor() {\n this.placeholder = document.createComment('tng-select-overlay-anchor');\n const hostEl = this.elRef.nativeElement;\n this.originalParent = hostEl.parentNode;\n this.originalParent?.insertBefore(this.placeholder, hostEl);\n\n effect(() => {\n const open = this.host.open();\n if (open) this.mountToBodyAndPosition();\n else this.restoreToPlaceholder();\n });\n\n this.destroyRef.onDestroy(() => {\n this.teardownOutsidePointer();\n this.restoreToPlaceholder(true);\n this.placeholder = null;\n this.originalParent = null;\n });\n }\n\n private reposition(): void {\n if (!this.host.open()) return;\n const panel = this.elRef.nativeElement;\n const trigger = this.findTriggerEl();\n if (!trigger) return;\n\n const anchor = rectFromClientRect(trigger.getBoundingClientRect());\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n placement: this.placement(),\n offset: this.offset(),\n collision: this.collision(),\n });\n\n panel.style.left = `${result.x}px`;\n panel.style.top = `${result.y}px`;\n }\n\n private setupRepositionListeners(): void {\n let rafId: number | null = null;\n const schedule = () => {\n if (rafId !== null) return;\n rafId = requestAnimationFrame(() => {\n rafId = null;\n this.reposition();\n });\n };\n\n const onResize = () => schedule();\n const onScroll = () => schedule();\n window.addEventListener('resize', onResize);\n window.addEventListener('scroll', onScroll, true);\n this.removeResizeListener = () => window.removeEventListener('resize', onResize);\n this.removeScrollListener = () => window.removeEventListener('scroll', onScroll, true);\n\n if ('ResizeObserver' in window) {\n this.resizeObserver = new ResizeObserver(() => schedule());\n const trigger = this.findTriggerEl();\n if (trigger) this.resizeObserver.observe(trigger);\n this.resizeObserver.observe(this.elRef.nativeElement);\n }\n }\n\n private teardownRepositionListeners(): void {\n this.removeResizeListener?.();\n this.removeScrollListener?.();\n this.removeResizeListener = null;\n this.removeScrollListener = null;\n this.resizeObserver?.disconnect();\n this.resizeObserver = null;\n }\n\n private findTriggerEl(): HTMLElement | null {\n const root = this.host.hostElement;\n return root.querySelector('[data-slot=\"select-trigger\"]') as HTMLElement | null;\n }\n\n private syncPortalledThemeVars(): void {\n const panel = this.elRef.nativeElement;\n const hostStyles = getComputedStyle(this.host.hostElement);\n\n for (const cssVar of PORTALLED_SELECT_THEME_VARS) {\n const value = hostStyles.getPropertyValue(cssVar).trim();\n if (value) {\n panel.style.setProperty(cssVar, value);\n } else {\n panel.style.removeProperty(cssVar);\n }\n }\n\n const colorScheme = hostStyles.colorScheme?.trim();\n if (colorScheme && colorScheme !== 'normal') {\n panel.style.colorScheme = colorScheme;\n } else {\n panel.style.removeProperty('color-scheme');\n }\n }\n\n private clearPortalledThemeVars(): void {\n const panel = this.elRef.nativeElement;\n\n for (const cssVar of PORTALLED_SELECT_THEME_VARS) {\n panel.style.removeProperty(cssVar);\n }\n\n panel.style.removeProperty('color-scheme');\n }\n\n private mountToBodyAndPosition(): void {\n this.lastFocusedBeforeOpen = document.activeElement as HTMLElement | null;\n this.setupRepositionListeners();\n const panel = this.elRef.nativeElement;\n\n if (panel.parentNode !== document.body) {\n document.body.appendChild(panel);\n }\n\n panel.style.position = 'fixed';\n panel.style.left = '0px';\n panel.style.top = '0px';\n panel.style.zIndex = '1000';\n this.syncPortalledThemeVars();\n\n queueMicrotask(() => {\n if (!this.host.open()) return;\n const trigger = this.findTriggerEl();\n if (!trigger) return;\n\n const anchor = rectFromClientRect(trigger.getBoundingClientRect());\n const viewportWidth = viewportRect().width;\n const inlineSize = Math.max(0, Math.min(anchor.width, viewportWidth - 16));\n panel.style.width = `${inlineSize}px`;\n panel.style.minWidth = `${inlineSize}px`;\n\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n placement: this.placement(),\n offset: this.offset(),\n collision: this.collision(),\n });\n\n panel.style.left = `${result.x}px`;\n panel.style.top = `${result.y}px`;\n });\n\n this.setupOutsidePointer();\n }\n\n private restoreToPlaceholder(force = false): void {\n const panel = this.elRef.nativeElement;\n if (!force && panel.parentNode !== document.body) {\n this.teardownOutsidePointer();\n return;\n }\n\n if (this.placeholder?.parentNode) {\n this.placeholder.parentNode.insertBefore(panel, this.placeholder);\n } else if (this.originalParent) {\n this.originalParent.appendChild(panel);\n }\n\n this.teardownRepositionListeners();\n\n if (\n this.lastFocusedBeforeOpen &&\n document.contains(this.lastFocusedBeforeOpen)\n ) {\n const active = document.activeElement as HTMLElement | null;\n const panelEl = this.elRef.nativeElement;\n if (!active || panelEl.contains(active)) {\n this.lastFocusedBeforeOpen.focus();\n }\n }\n\n this.restoreFocusOnClose();\n panel.style.position = '';\n panel.style.left = '';\n panel.style.top = '';\n panel.style.zIndex = '';\n panel.style.width = '';\n panel.style.minWidth = '';\n this.clearPortalledThemeVars();\n this.teardownOutsidePointer();\n }\n\n private setupOutsidePointer(): void {\n if (this.removeDocPointerListener) return;\n\n const onPointerDown = (ev: PointerEvent) => {\n if (!this.host.open()) return;\n const panel = this.elRef.nativeElement;\n const trigger = this.findTriggerEl();\n if (isInside(ev.target, panel)) return;\n if (trigger && isInside(ev.target, trigger)) return;\n if (\n this.host.multiple() &&\n ev.target &&\n (ev.target as Element).closest?.(\n '[data-slot=\"select-option\"], [data-slot=\"multi-select-option\"]'\n )\n )\n return;\n this.host.close();\n };\n\n document.addEventListener('pointerdown', onPointerDown, true);\n this.removeDocPointerListener = () => {\n document.removeEventListener('pointerdown', onPointerDown, true);\n };\n }\n\n private teardownOutsidePointer(): void {\n this.removeDocPointerListener?.();\n this.removeDocPointerListener = null;\n }\n\n private restoreFocusOnClose(): void {\n const panel = this.elRef.nativeElement;\n const active = document.activeElement as HTMLElement | null;\n if (active && panel.contains(active)) {\n const trigger = this.findTriggerEl();\n trigger?.focus();\n return;\n }\n if (document.activeElement === document.body) {\n const trigger = this.findTriggerEl();\n trigger?.focus();\n }\n }\n}\n"]}
|
|
@@ -34,6 +34,8 @@ export declare class TngAutocompleteOverlay {
|
|
|
34
34
|
private teardownRepositionListeners;
|
|
35
35
|
private setupOutsidePointer;
|
|
36
36
|
private teardownOutsidePointer;
|
|
37
|
+
private syncPortalledThemeVars;
|
|
38
|
+
private clearPortalledThemeVars;
|
|
37
39
|
private mountToBodyAndPosition;
|
|
38
40
|
private restoreToPlaceholder;
|
|
39
41
|
private restoreFocusOnClose;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tng-autocomplete.overlay.d.ts","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/autocomplete/tng-autocomplete.overlay.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"tng-autocomplete.overlay.d.ts","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/autocomplete/tng-autocomplete.overlay.ts"],"names":[],"mappings":";AA2FA,qBAIa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA6C;IAC1E,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmC;IACzD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IAEjD,OAAO,CAAC,qBAAqB,CAA4B;IACzD,OAAO,CAAC,oBAAoB,CAA6B;IACzD,OAAO,CAAC,oBAAoB,CAA6B;IACzD,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,wBAAwB,CAA6B;IAE7D,QAAQ,CAAC,SAAS;;;oBAAqD;IACvE,QAAQ,CAAC,MAAM;;;oBAAkD;IACjE,QAAQ,CAAC,SAAS;;;;oBAA4D;IAE9E,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAqB;IAG3C,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAG,sBAAsB,CAAU;IAG9D,SAAS,KAAK,MAAM,IAAI,EAAE,GAAG,IAAI,CAEhC;;IAsBD,uFAAuF;IACvF,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,UAAU;IAoBlB,OAAO,CAAC,wBAAwB;IAuBhC,OAAO,CAAC,2BAA2B;IASnC,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,sBAAsB;IAK9B,OAAO,CAAC,sBAAsB;IAqB9B,OAAO,CAAC,uBAAuB;IAU/B,OAAO,CAAC,sBAAsB;IAoC9B,OAAO,CAAC,oBAAoB;IAmC5B,OAAO,CAAC,mBAAmB;yCA1OhB,sBAAsB;2CAAtB,sBAAsB;CA4PlC"}
|
|
@@ -2,6 +2,64 @@ import { DestroyRef, Directive, ElementRef, HostBinding, inject, input, effect,
|
|
|
2
2
|
import { computeOverlayPosition } from '@tailng-ui/cdk';
|
|
3
3
|
import { TNG_AUTOCOMPLETE } from './tng-autocomplete.tokens';
|
|
4
4
|
import * as i0 from "@angular/core";
|
|
5
|
+
const PORTALLED_AUTOCOMPLETE_THEME_VARS = [
|
|
6
|
+
'--tng-autocomplete-radius',
|
|
7
|
+
'--tng-autocomplete-trigger-width',
|
|
8
|
+
'--tng-autocomplete-trigger-min-height',
|
|
9
|
+
'--tng-autocomplete-trigger-container-min-height',
|
|
10
|
+
'--tng-autocomplete-trigger-container-gap',
|
|
11
|
+
'--tng-autocomplete-trigger-container-px',
|
|
12
|
+
'--tng-autocomplete-trigger-py',
|
|
13
|
+
'--tng-autocomplete-trigger-px',
|
|
14
|
+
'--tng-autocomplete-icon-size',
|
|
15
|
+
'--tng-autocomplete-icon-box-size',
|
|
16
|
+
'--tng-autocomplete-icon-opacity',
|
|
17
|
+
'--tng-autocomplete-icon-margin-inline-end',
|
|
18
|
+
'--tng-autocomplete-overlay-padding',
|
|
19
|
+
'--tng-autocomplete-overlay-radius',
|
|
20
|
+
'--tng-autocomplete-overlay-shadow',
|
|
21
|
+
'--tng-autocomplete-overlay-max-width',
|
|
22
|
+
'--tng-autocomplete-overlay-border',
|
|
23
|
+
'--tng-autocomplete-overlay-bg',
|
|
24
|
+
'--tng-autocomplete-listbox-gap',
|
|
25
|
+
'--tng-autocomplete-option-min-height',
|
|
26
|
+
'--tng-autocomplete-option-py',
|
|
27
|
+
'--tng-autocomplete-option-px',
|
|
28
|
+
'--tng-autocomplete-option-radius',
|
|
29
|
+
'--tng-autocomplete-option-bg-active',
|
|
30
|
+
'--tng-autocomplete-option-border-active',
|
|
31
|
+
'--tng-autocomplete-option-bg-selected',
|
|
32
|
+
'--tng-autocomplete-option-border-selected',
|
|
33
|
+
'--tng-autocomplete-option-fg-selected',
|
|
34
|
+
'--tng-autocomplete-option-bg-selected-active',
|
|
35
|
+
'--tng-autocomplete-option-border-selected-active',
|
|
36
|
+
'--tng-autocomplete-option-shadow-selected-active',
|
|
37
|
+
'--tng-autocomplete-option-disabled-opacity',
|
|
38
|
+
'--tng-autocomplete-border',
|
|
39
|
+
'--tng-autocomplete-border-strong',
|
|
40
|
+
'--tng-autocomplete-border-hover',
|
|
41
|
+
'--tng-autocomplete-bg',
|
|
42
|
+
'--tng-autocomplete-surface',
|
|
43
|
+
'--tng-autocomplete-fg',
|
|
44
|
+
'--tng-autocomplete-muted',
|
|
45
|
+
'--tng-autocomplete-brand',
|
|
46
|
+
'--tng-autocomplete-danger',
|
|
47
|
+
'--tng-autocomplete-focus-ring',
|
|
48
|
+
'--tng-autocomplete-ease',
|
|
49
|
+
'--tng-autocomplete-shadow',
|
|
50
|
+
'--tng-autocomplete-shadow-focus',
|
|
51
|
+
'--tng-semantic-background-base',
|
|
52
|
+
'--tng-semantic-background-canvas',
|
|
53
|
+
'--tng-semantic-background-surface',
|
|
54
|
+
'--tng-semantic-border-subtle',
|
|
55
|
+
'--tng-semantic-border-strong',
|
|
56
|
+
'--tng-semantic-foreground-primary',
|
|
57
|
+
'--tng-semantic-foreground-secondary',
|
|
58
|
+
'--tng-semantic-foreground-muted',
|
|
59
|
+
'--tng-semantic-accent-brand',
|
|
60
|
+
'--tng-semantic-accent-danger',
|
|
61
|
+
'--tng-semantic-focus-ring',
|
|
62
|
+
];
|
|
5
63
|
function rectFromClientRect(r) {
|
|
6
64
|
return { left: r.left, top: r.top, width: r.width, height: r.height };
|
|
7
65
|
}
|
|
@@ -136,6 +194,33 @@ export class TngAutocompleteOverlay {
|
|
|
136
194
|
this.removeDocPointerListener?.();
|
|
137
195
|
this.removeDocPointerListener = null;
|
|
138
196
|
}
|
|
197
|
+
syncPortalledThemeVars() {
|
|
198
|
+
const panel = this.elRef.nativeElement;
|
|
199
|
+
const hostStyles = getComputedStyle(this.autocomplete.hostElement);
|
|
200
|
+
for (const cssVar of PORTALLED_AUTOCOMPLETE_THEME_VARS) {
|
|
201
|
+
const value = hostStyles.getPropertyValue(cssVar).trim();
|
|
202
|
+
if (value) {
|
|
203
|
+
panel.style.setProperty(cssVar, value);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
panel.style.removeProperty(cssVar);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const colorScheme = hostStyles.colorScheme?.trim();
|
|
210
|
+
if (colorScheme && colorScheme !== 'normal') {
|
|
211
|
+
panel.style.colorScheme = colorScheme;
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
panel.style.removeProperty('color-scheme');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
clearPortalledThemeVars() {
|
|
218
|
+
const panel = this.elRef.nativeElement;
|
|
219
|
+
for (const cssVar of PORTALLED_AUTOCOMPLETE_THEME_VARS) {
|
|
220
|
+
panel.style.removeProperty(cssVar);
|
|
221
|
+
}
|
|
222
|
+
panel.style.removeProperty('color-scheme');
|
|
223
|
+
}
|
|
139
224
|
mountToBodyAndPosition() {
|
|
140
225
|
this.lastFocusedBeforeOpen = document.activeElement;
|
|
141
226
|
this.setupRepositionListeners();
|
|
@@ -147,6 +232,7 @@ export class TngAutocompleteOverlay {
|
|
|
147
232
|
panel.style.left = '0px';
|
|
148
233
|
panel.style.top = '0px';
|
|
149
234
|
panel.style.zIndex = '1000';
|
|
235
|
+
this.syncPortalledThemeVars();
|
|
150
236
|
queueMicrotask(() => {
|
|
151
237
|
if (!this.autocomplete.open())
|
|
152
238
|
return;
|
|
@@ -198,6 +284,7 @@ export class TngAutocompleteOverlay {
|
|
|
198
284
|
panel.style.top = '';
|
|
199
285
|
panel.style.zIndex = '';
|
|
200
286
|
panel.style.minWidth = '';
|
|
287
|
+
this.clearPortalledThemeVars();
|
|
201
288
|
this.teardownOutsidePointer();
|
|
202
289
|
}
|
|
203
290
|
restoreFocusOnClose() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tng-autocomplete.overlay.js","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/autocomplete/tng-autocomplete.overlay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACX,MAAM,EACN,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;AAMvB,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;;AAK7D,SAAS,kBAAkB,CAAC,CAAuB;IACjD,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;AACxE,CAAC;AAED,SAAS,YAAY;IACnB,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,UAAU,IAAI,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,WAAW,IAAI,GAAG,EAAE,CAAC;AAClG,CAAC;AAED,SAAS,QAA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AC;YAChB,cAAc,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACrE,OAAO;QACT,CAAC;QACD,IAAI,QAAQ,CAAC,aAAa,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC7C,IAAI,CAAC,YAAY,CAAC,eAAe,GAAG,IAAI,CAAC;YACzC,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,cAAc,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;uGA1NU,sBAAsB;2FAAtB,sBAAsB;;2FAAtB,sBAAsB;kBAJlC,SAAS;mBAAC;oBACT,QAAQ,EAAE,0BAA0B;oBACpC,QAAQ,EAAE,wBAAwB;iBACnC;;sBAmBE,WAAW;uBAAC,gBAAgB;;sBAG5B,WAAW;uBAAC,aAAa","sourcesContent":["import {\n DestroyRef,\n Directive,\n ElementRef,\n HostBinding,\n inject,\n input,\n effect,\n} from '@angular/core';\nimport type {\n TngOverlayCollisionOptions,\n TngOverlayOffset,\n TngOverlayPlacement,\n} from '@tailng-ui/cdk';\nimport { computeOverlayPosition } from '@tailng-ui/cdk';\nimport { TNG_AUTOCOMPLETE } from './tng-autocomplete.tokens';\nimport type { TngAutocomplete } from './tng-autocomplete';\n\ntype MaybeRect = Readonly<{ left: number; top: number; width: number; height: number }>;\n\nfunction rectFromClientRect(r: DOMRect | ClientRect): MaybeRect {\n return { left: r.left, top: r.top, width: r.width, height: r.height };\n}\n\nfunction viewportRect(): MaybeRect {\n return { left: 0, top: 0, width: window.innerWidth || 1024, height: window.innerHeight || 768 };\n}\n\nfunction isInside(target: EventTarget | null, container: HTMLElement): boolean {\n return !!target && target instanceof Node && container.contains(target);\n}\n\n@Directive({\n selector: '[tngAutocompleteOverlay]',\n exportAs: 'tngAutocompleteOverlay',\n})\nexport class TngAutocompleteOverlay {\n private readonly autocomplete = inject<TngAutocomplete>(TNG_AUTOCOMPLETE);\n private readonly elRef = inject(ElementRef<HTMLElement>);\n private readonly destroyRef = inject(DestroyRef);\n\n private lastFocusedBeforeOpen: HTMLElement | null = null;\n private removeResizeListener: (() => void) | null = null;\n private removeScrollListener: (() => void) | null = null;\n private resizeObserver: ResizeObserver | null = null;\n private removeDocPointerListener: (() => void) | null = null;\n\n readonly placement = input<TngOverlayPlacement | undefined>(undefined);\n readonly offset = input<TngOverlayOffset | undefined>(undefined);\n readonly collision = input<TngOverlayCollisionOptions | undefined>(undefined);\n\n private placeholder: Comment | null = null;\n private originalParent: Node | null = null;\n\n @HostBinding('attr.data-slot')\n protected readonly dataSlot = 'autocomplete-overlay' as const;\n\n @HostBinding('attr.hidden')\n protected get hidden(): '' | null {\n return this.autocomplete.open() ? null : '';\n }\n\n constructor() {\n this.placeholder = document.createComment('tng-autocomplete-overlay-anchor');\n const hostEl = this.elRef.nativeElement;\n this.originalParent = hostEl.parentNode;\n this.originalParent?.insertBefore(this.placeholder, hostEl);\n\n effect(() => {\n const open = this.autocomplete.open();\n if (open) this.mountToBodyAndPosition();\n else this.restoreToPlaceholder();\n });\n\n this.destroyRef.onDestroy(() => {\n this.teardownOutsidePointer();\n this.restoreToPlaceholder(true);\n this.placeholder = null;\n this.originalParent = null;\n });\n }\n\n /** Anchor for overlay: container (trigger+icon) if present, else the input trigger. */\n private findAnchorEl(): HTMLElement | null {\n const root = this.autocomplete.hostElement;\n const container = root.querySelector('[data-slot=\"autocomplete-trigger-container\"]') as HTMLElement | null;\n if (container) return container;\n return root.querySelector('[data-slot=\"autocomplete-trigger\"]') as HTMLElement | null;\n }\n\n private findTriggerEl(): HTMLElement | null {\n const root = this.autocomplete.hostElement;\n return root.querySelector('[data-slot=\"autocomplete-trigger\"]') as HTMLElement | null;\n }\n\n private reposition(): void {\n if (!this.autocomplete.open()) return;\n const panel = this.elRef.nativeElement;\n const anchorEl = this.findAnchorEl();\n if (!anchorEl) return;\n const anchor = rectFromClientRect(anchorEl.getBoundingClientRect());\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n placement: this.placement(),\n offset: this.offset(),\n collision: this.collision(),\n });\n panel.style.left = `${result.x}px`;\n panel.style.top = `${result.y}px`;\n }\n\n private setupRepositionListeners(): void {\n let rafId: number | null = null;\n const schedule = () => {\n if (rafId !== null) return;\n rafId = requestAnimationFrame(() => {\n rafId = null;\n this.reposition();\n });\n };\n const onResize = () => schedule();\n const onScroll = () => schedule();\n window.addEventListener('resize', onResize);\n window.addEventListener('scroll', onScroll, true);\n this.removeResizeListener = () => window.removeEventListener('resize', onResize);\n this.removeScrollListener = () => window.removeEventListener('scroll', onScroll, true);\n if ('ResizeObserver' in window) {\n this.resizeObserver = new ResizeObserver(() => schedule());\n const anchorEl = this.findAnchorEl();\n if (anchorEl) this.resizeObserver.observe(anchorEl);\n this.resizeObserver.observe(this.elRef.nativeElement);\n }\n }\n\n private teardownRepositionListeners(): void {\n this.removeResizeListener?.();\n this.removeScrollListener?.();\n this.removeResizeListener = null;\n this.removeScrollListener = null;\n this.resizeObserver?.disconnect();\n this.resizeObserver = null;\n }\n\n private setupOutsidePointer(): void {\n if (this.removeDocPointerListener) return;\n const onPointerDown = (ev: PointerEvent) => {\n if (!this.autocomplete.open()) return;\n const panel = this.elRef.nativeElement;\n const anchorEl = this.findAnchorEl();\n if (isInside(ev.target, panel)) return;\n if (anchorEl && isInside(ev.target, anchorEl)) return;\n if (ev.target && (ev.target as Element).closest?.('[data-slot=\"autocomplete-option\"]')) return;\n this.autocomplete.close();\n };\n document.addEventListener('pointerdown', onPointerDown, true);\n this.removeDocPointerListener = () =>\n document.removeEventListener('pointerdown', onPointerDown, true);\n }\n\n private teardownOutsidePointer(): void {\n this.removeDocPointerListener?.();\n this.removeDocPointerListener = null;\n }\n\n private mountToBodyAndPosition(): void {\n this.lastFocusedBeforeOpen = document.activeElement as HTMLElement | null;\n this.setupRepositionListeners();\n const panel = this.elRef.nativeElement;\n if (panel.parentNode !== document.body) {\n document.body.appendChild(panel);\n }\n panel.style.position = 'fixed';\n panel.style.left = '0px';\n panel.style.top = '0px';\n panel.style.zIndex = '1000';\n\n queueMicrotask(() => {\n if (!this.autocomplete.open()) return;\n const anchorEl = this.findAnchorEl();\n if (!anchorEl) return;\n const anchor = rectFromClientRect(anchorEl.getBoundingClientRect());\n panel.style.minWidth = `${anchor.width}px`;\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n placement: this.placement(),\n offset: this.offset(),\n collision: this.collision(),\n });\n panel.style.left = `${result.x}px`;\n panel.style.top = `${result.y}px`;\n });\n\n this.setupOutsidePointer();\n }\n\n private restoreToPlaceholder(force = false): void {\n const panel = this.elRef.nativeElement;\n if (!force && panel.parentNode !== document.body) {\n this.teardownOutsidePointer();\n return;\n }\n if (this.placeholder?.parentNode) {\n this.placeholder.parentNode.insertBefore(panel, this.placeholder);\n } else if (this.originalParent) {\n this.originalParent.appendChild(panel);\n }\n this.teardownRepositionListeners();\n\n if (\n this.lastFocusedBeforeOpen &&\n document.contains(this.lastFocusedBeforeOpen)\n ) {\n const active = document.activeElement as HTMLElement | null;\n if (!active || panel.contains(active)) {\n this.autocomplete._restoringFocus = true;\n this.lastFocusedBeforeOpen.focus();\n queueMicrotask(() => { this.autocomplete._restoringFocus = false; });\n }\n }\n this.restoreFocusOnClose();\n\n panel.style.position = '';\n panel.style.left = '';\n panel.style.top = '';\n panel.style.zIndex = '';\n panel.style.minWidth = '';\n this.teardownOutsidePointer();\n }\n\n private restoreFocusOnClose(): void {\n const panel = this.elRef.nativeElement;\n const active = document.activeElement as HTMLElement | null;\n const trigger = this.findTriggerEl();\n if (!trigger) return;\n\n if (active && panel.contains(active)) {\n this.autocomplete._restoringFocus = true;\n trigger.focus();\n queueMicrotask(() => { this.autocomplete._restoringFocus = false; });\n return;\n }\n if (document.activeElement === document.body) {\n this.autocomplete._restoringFocus = true;\n trigger.focus();\n queueMicrotask(() => { this.autocomplete._restoringFocus = false; });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tng-autocomplete.overlay.js","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/autocomplete/tng-autocomplete.overlay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACX,MAAM,EACN,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;AAMvB,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;;AAK7D,MAAM,iCAAiC,GAAG;IACxC,2BAA2B;IAC3B,kCAAkC;IAClC,uCAAuC;IACvC,iDAAiD;IACjD,0CAA0C;IAC1C,yCAAyC;IACzC,+BAA+B;IAC/B,+BAA+B;IAC/B,8BAA8B;IAC9B,kCAAkC;IAClC,iCAAiC;IACjC,2CAA2C;IAC3C,oCAAoC;IACpC,mCAAmC;IACnC,mCAAmC;IACnC,sCAAsC;IACtC,mCAAmC;IACnC,+BAA+B;IAC/B,gCAAgC;IAChC,sCAAsC;IACtC,8BAA8B;IAC9B,8BAA8B;IAC9B,kCAAkC;IAClC,qCAAqC;IACrC,yCAAyC;IACzC,uCAAuC;IACvC,2CAA2C;IAC3C,uCAAuC;IACvC,8CAA8C;IAC9C,kDAAkD;IAClD,kDAAkD;IAClD,4CAA4C;IAC5C,2BAA2B;IAC3B,kCAAkC;IAClC,iCAAiC;IACjC,uBAAuB;IACvB,4BAA4B;IAC5B,uBAAuB;IACvB,0BAA0B;IAC1B,0BAA0B;IAC1B,2BAA2B;IAC3B,+BAA+B;IAC/B,yBAAyB;IACzB,2BAA2B;I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\n TngOverlayCollisionOptions,\n TngOverlayOffset,\n TngOverlayPlacement,\n} from '@tailng-ui/cdk';\nimport { computeOverlayPosition } from '@tailng-ui/cdk';\nimport { TNG_AUTOCOMPLETE } from './tng-autocomplete.tokens';\nimport type { TngAutocomplete } from './tng-autocomplete';\n\ntype MaybeRect = Readonly<{ left: number; top: number; width: number; height: number }>;\n\nconst PORTALLED_AUTOCOMPLETE_THEME_VARS = [\n '--tng-autocomplete-radius',\n '--tng-autocomplete-trigger-width',\n '--tng-autocomplete-trigger-min-height',\n '--tng-autocomplete-trigger-container-min-height',\n '--tng-autocomplete-trigger-container-gap',\n '--tng-autocomplete-trigger-container-px',\n '--tng-autocomplete-trigger-py',\n '--tng-autocomplete-trigger-px',\n '--tng-autocomplete-icon-size',\n '--tng-autocomplete-icon-box-size',\n '--tng-autocomplete-icon-opacity',\n '--tng-autocomplete-icon-margin-inline-end',\n '--tng-autocomplete-overlay-padding',\n '--tng-autocomplete-overlay-radius',\n '--tng-autocomplete-overlay-shadow',\n '--tng-autocomplete-overlay-max-width',\n '--tng-autocomplete-overlay-border',\n '--tng-autocomplete-overlay-bg',\n '--tng-autocomplete-listbox-gap',\n '--tng-autocomplete-option-min-height',\n '--tng-autocomplete-option-py',\n '--tng-autocomplete-option-px',\n '--tng-autocomplete-option-radius',\n '--tng-autocomplete-option-bg-active',\n '--tng-autocomplete-option-border-active',\n '--tng-autocomplete-option-bg-selected',\n '--tng-autocomplete-option-border-selected',\n '--tng-autocomplete-option-fg-selected',\n '--tng-autocomplete-option-bg-selected-active',\n '--tng-autocomplete-option-border-selected-active',\n '--tng-autocomplete-option-shadow-selected-active',\n '--tng-autocomplete-option-disabled-opacity',\n '--tng-autocomplete-border',\n '--tng-autocomplete-border-strong',\n '--tng-autocomplete-border-hover',\n '--tng-autocomplete-bg',\n '--tng-autocomplete-surface',\n '--tng-autocomplete-fg',\n '--tng-autocomplete-muted',\n '--tng-autocomplete-brand',\n '--tng-autocomplete-danger',\n '--tng-autocomplete-focus-ring',\n '--tng-autocomplete-ease',\n '--tng-autocomplete-shadow',\n '--tng-autocomplete-shadow-focus',\n '--tng-semantic-background-base',\n '--tng-semantic-background-canvas',\n '--tng-semantic-background-surface',\n '--tng-semantic-border-subtle',\n '--tng-semantic-border-strong',\n '--tng-semantic-foreground-primary',\n '--tng-semantic-foreground-secondary',\n '--tng-semantic-foreground-muted',\n '--tng-semantic-accent-brand',\n '--tng-semantic-accent-danger',\n '--tng-semantic-focus-ring',\n] as const;\n\nfunction rectFromClientRect(r: DOMRect | ClientRect): MaybeRect {\n return { left: r.left, top: r.top, width: r.width, height: r.height };\n}\n\nfunction viewportRect(): MaybeRect {\n return { left: 0, top: 0, width: window.innerWidth || 1024, height: window.innerHeight || 768 };\n}\n\nfunction isInside(target: EventTarget | null, container: HTMLElement): boolean {\n return !!target && target instanceof Node && container.contains(target);\n}\n\n@Directive({\n selector: '[tngAutocompleteOverlay]',\n exportAs: 'tngAutocompleteOverlay',\n})\nexport class TngAutocompleteOverlay {\n private readonly autocomplete = inject<TngAutocomplete>(TNG_AUTOCOMPLETE);\n private readonly elRef = inject(ElementRef<HTMLElement>);\n private readonly destroyRef = inject(DestroyRef);\n\n private lastFocusedBeforeOpen: HTMLElement | null = null;\n private removeResizeListener: (() => void) | null = null;\n private removeScrollListener: (() => void) | null = null;\n private resizeObserver: ResizeObserver | null = null;\n private removeDocPointerListener: (() => void) | null = null;\n\n readonly placement = input<TngOverlayPlacement | undefined>(undefined);\n readonly offset = input<TngOverlayOffset | undefined>(undefined);\n readonly collision = input<TngOverlayCollisionOptions | undefined>(undefined);\n\n private placeholder: Comment | null = null;\n private originalParent: Node | null = null;\n\n @HostBinding('attr.data-slot')\n protected readonly dataSlot = 'autocomplete-overlay' as const;\n\n @HostBinding('attr.hidden')\n protected get hidden(): '' | null {\n return this.autocomplete.open() ? null : '';\n }\n\n constructor() {\n this.placeholder = document.createComment('tng-autocomplete-overlay-anchor');\n const hostEl = this.elRef.nativeElement;\n this.originalParent = hostEl.parentNode;\n this.originalParent?.insertBefore(this.placeholder, hostEl);\n\n effect(() => {\n const open = this.autocomplete.open();\n if (open) this.mountToBodyAndPosition();\n else this.restoreToPlaceholder();\n });\n\n this.destroyRef.onDestroy(() => {\n this.teardownOutsidePointer();\n this.restoreToPlaceholder(true);\n this.placeholder = null;\n this.originalParent = null;\n });\n }\n\n /** Anchor for overlay: container (trigger+icon) if present, else the input trigger. */\n private findAnchorEl(): HTMLElement | null {\n const root = this.autocomplete.hostElement;\n const container = root.querySelector('[data-slot=\"autocomplete-trigger-container\"]') as HTMLElement | null;\n if (container) return container;\n return root.querySelector('[data-slot=\"autocomplete-trigger\"]') as HTMLElement | null;\n }\n\n private findTriggerEl(): HTMLElement | null {\n const root = this.autocomplete.hostElement;\n return root.querySelector('[data-slot=\"autocomplete-trigger\"]') as HTMLElement | null;\n }\n\n private reposition(): void {\n if (!this.autocomplete.open()) return;\n const panel = this.elRef.nativeElement;\n const anchorEl = this.findAnchorEl();\n if (!anchorEl) return;\n const anchor = rectFromClientRect(anchorEl.getBoundingClientRect());\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n placement: this.placement(),\n offset: this.offset(),\n collision: this.collision(),\n });\n panel.style.left = `${result.x}px`;\n panel.style.top = `${result.y}px`;\n }\n\n private setupRepositionListeners(): void {\n let rafId: number | null = null;\n const schedule = () => {\n if (rafId !== null) return;\n rafId = requestAnimationFrame(() => {\n rafId = null;\n this.reposition();\n });\n };\n const onResize = () => schedule();\n const onScroll = () => schedule();\n window.addEventListener('resize', onResize);\n window.addEventListener('scroll', onScroll, true);\n this.removeResizeListener = () => window.removeEventListener('resize', onResize);\n this.removeScrollListener = () => window.removeEventListener('scroll', onScroll, true);\n if ('ResizeObserver' in window) {\n this.resizeObserver = new ResizeObserver(() => schedule());\n const anchorEl = this.findAnchorEl();\n if (anchorEl) this.resizeObserver.observe(anchorEl);\n this.resizeObserver.observe(this.elRef.nativeElement);\n }\n }\n\n private teardownRepositionListeners(): void {\n this.removeResizeListener?.();\n this.removeScrollListener?.();\n this.removeResizeListener = null;\n this.removeScrollListener = null;\n this.resizeObserver?.disconnect();\n this.resizeObserver = null;\n }\n\n private setupOutsidePointer(): void {\n if (this.removeDocPointerListener) return;\n const onPointerDown = (ev: PointerEvent) => {\n if (!this.autocomplete.open()) return;\n const panel = this.elRef.nativeElement;\n const anchorEl = this.findAnchorEl();\n if (isInside(ev.target, panel)) return;\n if (anchorEl && isInside(ev.target, anchorEl)) return;\n if (ev.target && (ev.target as Element).closest?.('[data-slot=\"autocomplete-option\"]')) return;\n this.autocomplete.close();\n };\n document.addEventListener('pointerdown', onPointerDown, true);\n this.removeDocPointerListener = () =>\n document.removeEventListener('pointerdown', onPointerDown, true);\n }\n\n private teardownOutsidePointer(): void {\n this.removeDocPointerListener?.();\n this.removeDocPointerListener = null;\n }\n\n private syncPortalledThemeVars(): void {\n const panel = this.elRef.nativeElement;\n const hostStyles = getComputedStyle(this.autocomplete.hostElement);\n\n for (const cssVar of PORTALLED_AUTOCOMPLETE_THEME_VARS) {\n const value = hostStyles.getPropertyValue(cssVar).trim();\n if (value) {\n panel.style.setProperty(cssVar, value);\n } else {\n panel.style.removeProperty(cssVar);\n }\n }\n\n const colorScheme = hostStyles.colorScheme?.trim();\n if (colorScheme && colorScheme !== 'normal') {\n panel.style.colorScheme = colorScheme;\n } else {\n panel.style.removeProperty('color-scheme');\n }\n }\n\n private clearPortalledThemeVars(): void {\n const panel = this.elRef.nativeElement;\n\n for (const cssVar of PORTALLED_AUTOCOMPLETE_THEME_VARS) {\n panel.style.removeProperty(cssVar);\n }\n\n panel.style.removeProperty('color-scheme');\n }\n\n private mountToBodyAndPosition(): void {\n this.lastFocusedBeforeOpen = document.activeElement as HTMLElement | null;\n this.setupRepositionListeners();\n const panel = this.elRef.nativeElement;\n if (panel.parentNode !== document.body) {\n document.body.appendChild(panel);\n }\n panel.style.position = 'fixed';\n panel.style.left = '0px';\n panel.style.top = '0px';\n panel.style.zIndex = '1000';\n this.syncPortalledThemeVars();\n\n queueMicrotask(() => {\n if (!this.autocomplete.open()) return;\n const anchorEl = this.findAnchorEl();\n if (!anchorEl) return;\n const anchor = rectFromClientRect(anchorEl.getBoundingClientRect());\n panel.style.minWidth = `${anchor.width}px`;\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n placement: this.placement(),\n offset: this.offset(),\n collision: this.collision(),\n });\n panel.style.left = `${result.x}px`;\n panel.style.top = `${result.y}px`;\n });\n\n this.setupOutsidePointer();\n }\n\n private restoreToPlaceholder(force = false): void {\n const panel = this.elRef.nativeElement;\n if (!force && panel.parentNode !== document.body) {\n this.teardownOutsidePointer();\n return;\n }\n if (this.placeholder?.parentNode) {\n this.placeholder.parentNode.insertBefore(panel, this.placeholder);\n } else if (this.originalParent) {\n this.originalParent.appendChild(panel);\n }\n this.teardownRepositionListeners();\n\n if (\n this.lastFocusedBeforeOpen &&\n document.contains(this.lastFocusedBeforeOpen)\n ) {\n const active = document.activeElement as HTMLElement | null;\n if (!active || panel.contains(active)) {\n this.autocomplete._restoringFocus = true;\n this.lastFocusedBeforeOpen.focus();\n queueMicrotask(() => { this.autocomplete._restoringFocus = false; });\n }\n }\n this.restoreFocusOnClose();\n\n panel.style.position = '';\n panel.style.left = '';\n panel.style.top = '';\n panel.style.zIndex = '';\n panel.style.minWidth = '';\n this.clearPortalledThemeVars();\n this.teardownOutsidePointer();\n }\n\n private restoreFocusOnClose(): void {\n const panel = this.elRef.nativeElement;\n const active = document.activeElement as HTMLElement | null;\n const trigger = this.findTriggerEl();\n if (!trigger) return;\n\n if (active && panel.contains(active)) {\n this.autocomplete._restoringFocus = true;\n trigger.focus();\n queueMicrotask(() => { this.autocomplete._restoringFocus = false; });\n return;\n }\n if (document.activeElement === document.body) {\n this.autocomplete._restoringFocus = true;\n trigger.focus();\n queueMicrotask(() => { this.autocomplete._restoringFocus = false; });\n }\n }\n}\n"]}
|
package/src/lib/form/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export * from './autocomplete';
|
|
|
5
5
|
export * from './button-toggle/tng-button-toggle';
|
|
6
6
|
export * from './checkbox/tng-checkbox';
|
|
7
7
|
export * from './chips/tng-chips';
|
|
8
|
-
export * from './combobox/tng-combobox';
|
|
9
8
|
export * from './datepicker';
|
|
10
9
|
export * from './input/tng-input';
|
|
11
10
|
export * from './input/tng-input-group';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../libs/tailng-ui/primitives/src/lib/form/index.ts"],"names":[],"mappings":"AAKA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../libs/tailng-ui/primitives/src/lib/form/index.ts"],"names":[],"mappings":"AAKA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AAErC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAElD,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC"}
|
package/src/lib/form/index.js
CHANGED
|
@@ -9,7 +9,6 @@ export * from './autocomplete';
|
|
|
9
9
|
export * from './button-toggle/tng-button-toggle';
|
|
10
10
|
export * from './checkbox/tng-checkbox';
|
|
11
11
|
export * from './chips/tng-chips';
|
|
12
|
-
export * from './combobox/tng-combobox';
|
|
13
12
|
export * from './datepicker';
|
|
14
13
|
export * from './input/tng-input';
|
|
15
14
|
export * from './input/tng-input-group';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/tailng-ui/primitives/src/lib/form/index.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,EAAE;AACF,+FAA+F;AAC/F,4CAA4C;AAE5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/tailng-ui/primitives/src/lib/form/index.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,EAAE;AACF,+FAA+F;AAC/F,4CAA4C;AAE5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AAErC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAElD,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC","sourcesContent":["// Form primitives\n//\n// Note: keep exports aligned with `src/index.ts` (root barrel) so the public API stays stable.\n// The root barrel will re-export this file.\n\nexport * from './listbox/listbox.directive';\nexport * from './listbox/option.directive';\nexport * from './listbox/tokens';\nexport * from './autocomplete';\nexport * from './button-toggle/tng-button-toggle';\nexport * from './checkbox/tng-checkbox';\nexport * from './chips/tng-chips';\nexport * from './datepicker';\nexport * from './input/tng-input';\nexport * from './input/tng-input-group';\nexport * from './input/tng-adornment';\nexport * from './input-otp/tng-input-otp';\nexport * from './label/tng-label';\nexport * from './multiselect/tng-multiselect';\nexport * from './multi-select';\nexport * from './radio/tng-radio';\nexport * from './multi-autocomplete';\n\nexport * from './select/tng-select';\nexport * from './select/tng-select.parts';\nexport * from './select/tng-select.overlay';\nexport * from './select/tng-select.listbox';\nexport * from './select/tng-select.listbox.types';\n\nexport * from './slider/tng-slider';\nexport * from './switch/tng-switch';\nexport * from './textarea/tng-textarea';\nexport * from './toggle/tng-toggle';\nexport * from './toggle-group/tng-toggle-group';\n\n"]}
|
|
@@ -3,17 +3,34 @@ export declare function normalizeTngOtpLength(value: number): number;
|
|
|
3
3
|
export type TngOtpCompletionState = 'complete' | 'empty' | 'partial';
|
|
4
4
|
export declare function normalizeTngOtpValue(value: unknown): string;
|
|
5
5
|
export declare function clampTngOtpValue(value: string, length: number): string;
|
|
6
|
+
export type TngInputOtpType = 'numeric' | 'alphanumeric' | 'custom';
|
|
7
|
+
export declare function sanitizeTngOtpCharacters(value: string, mode: TngInputOtpType, pattern: string | RegExp | null): readonly string[];
|
|
8
|
+
export declare function toTngOtpSlots(length: number, value: string): readonly string[];
|
|
9
|
+
export declare function applyTngOtpCharacters(value: string, startIndex: number, characters: readonly string[], maxLength: number): string;
|
|
10
|
+
export declare function removeTngOtpCharacter(value: string, index: number): string;
|
|
11
|
+
export declare function resolveTngOtpEntryIndex(value: string, length: number): number;
|
|
12
|
+
export declare function resolveTngOtpEndIndex(value: string, length: number): number;
|
|
13
|
+
export type TngOtpBackspaceResult = Readonly<{
|
|
14
|
+
focusIndex: number;
|
|
15
|
+
value: string;
|
|
16
|
+
}>;
|
|
6
17
|
export declare function resolveTngOtpState(length: number, value: string): TngOtpCompletionState;
|
|
18
|
+
export declare function resolveTngOtpBackspaceResult(value: string, index: number, length: number): TngOtpBackspaceResult | null;
|
|
7
19
|
export declare class TngInputOtp {
|
|
20
|
+
readonly hostElement: any;
|
|
8
21
|
readonly length: import("@angular/core").InputSignalWithTransform<number, string | number>;
|
|
9
|
-
readonly value: import("@angular/core").
|
|
22
|
+
readonly value: import("@angular/core").ModelSignal<string>;
|
|
10
23
|
readonly disabled: import("@angular/core").InputSignalWithTransform<boolean, string | boolean>;
|
|
11
24
|
readonly readonly: import("@angular/core").InputSignalWithTransform<boolean, string | boolean>;
|
|
12
25
|
readonly required: import("@angular/core").InputSignalWithTransform<boolean, string | boolean>;
|
|
13
26
|
readonly invalid: import("@angular/core").InputSignalWithTransform<boolean, string | boolean>;
|
|
14
27
|
readonly focused: import("@angular/core").InputSignalWithTransform<boolean, string | boolean>;
|
|
15
28
|
readonly focusVisible: import("@angular/core").InputSignalWithTransform<boolean, string | boolean>;
|
|
16
|
-
readonly activeIndex: import("@angular/core").
|
|
29
|
+
readonly activeIndex: import("@angular/core").ModelSignal<number | null>;
|
|
30
|
+
readonly type: import("@angular/core").InputSignal<TngInputOtpType>;
|
|
31
|
+
readonly pattern: import("@angular/core").InputSignal<string | RegExp | null>;
|
|
32
|
+
readonly selectOnFocus: import("@angular/core").InputSignalWithTransform<boolean, string | boolean>;
|
|
33
|
+
readonly complete: import("@angular/core").OutputEmitterRef<string>;
|
|
17
34
|
protected readonly dataSlot: "input-otp";
|
|
18
35
|
protected readonly roleAttr: "group";
|
|
19
36
|
protected get dataEmptyAttr(): '' | null;
|
|
@@ -26,7 +43,36 @@ export declare class TngInputOtp {
|
|
|
26
43
|
protected get dataFocusedAttr(): '' | null;
|
|
27
44
|
protected get dataFocusVisibleAttr(): '' | null;
|
|
28
45
|
protected get dataActiveAttr(): string | null;
|
|
46
|
+
slotValue(index: number): string;
|
|
47
|
+
isSlotTabbable(index: number): boolean;
|
|
48
|
+
handleSlotFocus(index: number, target: HTMLInputElement | null): void;
|
|
49
|
+
handleSlotKeydown(index: number, event: KeyboardEvent): void;
|
|
50
|
+
handleSlotInput(index: number, target: HTMLInputElement | null): void;
|
|
51
|
+
handleSlotPaste(index: number, event: ClipboardEvent): void;
|
|
52
|
+
private normalizedValue;
|
|
53
|
+
private resolvedActiveIndex;
|
|
54
|
+
private resolveEditableIndex;
|
|
55
|
+
private handleBackspace;
|
|
56
|
+
private handleDelete;
|
|
57
|
+
private commitValue;
|
|
58
|
+
private focusSlot;
|
|
59
|
+
private syncSlotInputValues;
|
|
29
60
|
static ɵfac: i0.ɵɵFactoryDeclaration<TngInputOtp, never>;
|
|
30
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<TngInputOtp, "[tngInputOtp]", ["tngInputOtp"], { "length": { "alias": "length"; "required": false; "isSignal": true; }; "value": { "alias": "value"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; "readonly": { "alias": "readonly"; "required": false; "isSignal": true; }; "required": { "alias": "required"; "required": false; "isSignal": true; }; "invalid": { "alias": "invalid"; "required": false; "isSignal": true; }; "focused": { "alias": "focused"; "required": false; "isSignal": true; }; "focusVisible": { "alias": "focusVisible"; "required": false; "isSignal": true; }; "activeIndex": { "alias": "activeIndex"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
61
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<TngInputOtp, "[tngInputOtp]", ["tngInputOtp"], { "length": { "alias": "length"; "required": false; "isSignal": true; }; "value": { "alias": "value"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; "readonly": { "alias": "readonly"; "required": false; "isSignal": true; }; "required": { "alias": "required"; "required": false; "isSignal": true; }; "invalid": { "alias": "invalid"; "required": false; "isSignal": true; }; "focused": { "alias": "focused"; "required": false; "isSignal": true; }; "focusVisible": { "alias": "focusVisible"; "required": false; "isSignal": true; }; "activeIndex": { "alias": "activeIndex"; "required": false; "isSignal": true; }; "type": { "alias": "type"; "required": false; "isSignal": true; }; "pattern": { "alias": "pattern"; "required": false; "isSignal": true; }; "selectOnFocus": { "alias": "selectOnFocus"; "required": false; "isSignal": true; }; }, { "value": "valueChange"; "activeIndex": "activeIndexChange"; "complete": "complete"; }, never, never, true, never>;
|
|
62
|
+
}
|
|
63
|
+
export declare class TngInputOtpSlot {
|
|
64
|
+
private readonly otp;
|
|
65
|
+
private readonly elementRef;
|
|
66
|
+
readonly index: import("@angular/core").InputSignalWithTransform<number, string | number>;
|
|
67
|
+
protected readonly dataSlot: "input-otp-slot";
|
|
68
|
+
protected get dataIndexAttr(): string;
|
|
69
|
+
protected get valueProp(): string;
|
|
70
|
+
protected get tabIndexProp(): number;
|
|
71
|
+
protected onFocus(): void;
|
|
72
|
+
protected onKeydown(event: KeyboardEvent): void;
|
|
73
|
+
protected onInput(): void;
|
|
74
|
+
protected onPaste(event: ClipboardEvent): void;
|
|
75
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<TngInputOtpSlot, never>;
|
|
76
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<TngInputOtpSlot, "input[tngInputOtpSlot]", ["tngInputOtpSlot"], { "index": { "alias": "tngInputOtpSlot"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
31
77
|
}
|
|
32
78
|
//# sourceMappingURL=tng-input-otp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tng-input-otp.d.ts","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/input-otp/tng-input-otp.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"tng-input-otp.d.ts","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/input-otp/tng-input-otp.ts"],"names":[],"mappings":";AAYA,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAW3D;AAED,MAAM,MAAM,qBAAqB,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,CAAC;AAErE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAM3D;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,cAAc,GAAG,QAAQ,CAAC;AAUpE,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAC9B,SAAS,MAAM,EAAE,CA4BnB;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAc9E;AAED,wBAAgB,qBAAqB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CArThB,WAAW;2CAAX,WAAW;CAoUvB;AAED,qBAIa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAuB;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoD;IAE/E,SAAgB,KAAK,4EAMlB;IAGH,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAG,gBAAgB,CAAU;IAGxD,SAAS,KAAK,aAAa,IAAI,MAAM,CAEpC;IAGD,SAAS,KAAK,SAAS,IAAI,MAAM,CAEhC;IAGD,SAAS,KAAK,YAAY,IAAI,MAAM,CAEnC;IAGD,SAAS,CAAC,OAAO,IAAI,IAAI;IAKzB,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAK/C,SAAS,CAAC,OAAO,IAAI,IAAI;IAKzB,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;yCA9CnC,eAAe;2CAAf,eAAe;CAiD3B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Directive, HostBinding, booleanAttribute, input } from '@angular/core';
|
|
1
|
+
import { Directive, ElementRef, HostBinding, HostListener, booleanAttribute, inject, input, model, output, } from '@angular/core';
|
|
2
2
|
import * as i0 from "@angular/core";
|
|
3
3
|
export function normalizeTngOtpLength(value) {
|
|
4
4
|
if (!Number.isFinite(value)) {
|
|
@@ -19,6 +19,103 @@ export function normalizeTngOtpValue(value) {
|
|
|
19
19
|
export function clampTngOtpValue(value, length) {
|
|
20
20
|
return Array.from(value).slice(0, length).join('');
|
|
21
21
|
}
|
|
22
|
+
const tngOtpDigitPattern = /^\d$/;
|
|
23
|
+
const tngOtpAlphanumericPattern = /^[a-zA-Z0-9]$/;
|
|
24
|
+
function toNonGlobalRegex(pattern) {
|
|
25
|
+
const flags = pattern.flags.replace(/g/g, '');
|
|
26
|
+
return new RegExp(pattern.source, flags);
|
|
27
|
+
}
|
|
28
|
+
export function sanitizeTngOtpCharacters(value, mode, pattern) {
|
|
29
|
+
const compiledPattern = mode !== 'custom'
|
|
30
|
+
? null
|
|
31
|
+
: typeof pattern === 'string'
|
|
32
|
+
? new RegExp(pattern)
|
|
33
|
+
: pattern === null
|
|
34
|
+
? null
|
|
35
|
+
: toNonGlobalRegex(pattern);
|
|
36
|
+
const acceptedChars = [];
|
|
37
|
+
for (const char of Array.from(value)) {
|
|
38
|
+
if (mode === 'numeric' && !tngOtpDigitPattern.test(char)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (mode === 'alphanumeric' && !tngOtpAlphanumericPattern.test(char)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (compiledPattern && !compiledPattern.test(char)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
acceptedChars.push(char);
|
|
48
|
+
}
|
|
49
|
+
return acceptedChars;
|
|
50
|
+
}
|
|
51
|
+
export function toTngOtpSlots(length, value) {
|
|
52
|
+
const safeLength = normalizeTngOtpLength(length);
|
|
53
|
+
const slots = Array.from({ length: safeLength }, () => '');
|
|
54
|
+
const chars = Array.from(clampTngOtpValue(value, safeLength));
|
|
55
|
+
for (const [index, char] of chars.entries()) {
|
|
56
|
+
if (index >= safeLength) {
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
slots[index] = char;
|
|
60
|
+
}
|
|
61
|
+
return slots;
|
|
62
|
+
}
|
|
63
|
+
export function applyTngOtpCharacters(value, startIndex, characters, maxLength) {
|
|
64
|
+
const safeLength = normalizeTngOtpLength(maxLength);
|
|
65
|
+
const nextChars = Array.from(clampTngOtpValue(value, safeLength));
|
|
66
|
+
const safeStart = Math.max(0, Math.min(startIndex, safeLength - 1));
|
|
67
|
+
let cursor = nextChars.length < safeLength ? Math.min(safeStart, nextChars.length) : safeStart;
|
|
68
|
+
for (const char of characters) {
|
|
69
|
+
if (cursor >= safeLength) {
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
if (cursor < nextChars.length) {
|
|
73
|
+
nextChars[cursor] = char;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
nextChars.push(char);
|
|
77
|
+
}
|
|
78
|
+
cursor += 1;
|
|
79
|
+
}
|
|
80
|
+
return nextChars.slice(0, safeLength).join('');
|
|
81
|
+
}
|
|
82
|
+
export function removeTngOtpCharacter(value, index) {
|
|
83
|
+
const chars = Array.from(value);
|
|
84
|
+
if (index < 0 || index >= chars.length) {
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
chars.splice(index, 1);
|
|
88
|
+
return chars.join('');
|
|
89
|
+
}
|
|
90
|
+
export function resolveTngOtpEntryIndex(value, length) {
|
|
91
|
+
const safeLength = normalizeTngOtpLength(length);
|
|
92
|
+
const safeValue = clampTngOtpValue(value, safeLength);
|
|
93
|
+
if (safeValue.length >= safeLength) {
|
|
94
|
+
return safeLength - 1;
|
|
95
|
+
}
|
|
96
|
+
return safeValue.length;
|
|
97
|
+
}
|
|
98
|
+
export function resolveTngOtpEndIndex(value, length) {
|
|
99
|
+
const safeLength = normalizeTngOtpLength(length);
|
|
100
|
+
const safeValue = clampTngOtpValue(value, safeLength);
|
|
101
|
+
if (safeValue.length === 0) {
|
|
102
|
+
return safeLength - 1;
|
|
103
|
+
}
|
|
104
|
+
return Math.max(0, safeValue.length - 1);
|
|
105
|
+
}
|
|
106
|
+
function clampOtpIndex(index, length) {
|
|
107
|
+
const safeLength = normalizeTngOtpLength(length);
|
|
108
|
+
if (!Number.isFinite(index)) {
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
if (index < 0) {
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
if (index >= safeLength) {
|
|
115
|
+
return safeLength - 1;
|
|
116
|
+
}
|
|
117
|
+
return Math.trunc(index);
|
|
118
|
+
}
|
|
22
119
|
export function resolveTngOtpState(length, value) {
|
|
23
120
|
const normalizedLength = normalizeTngOtpLength(length);
|
|
24
121
|
const clampedValue = clampTngOtpValue(normalizeTngOtpValue(value), normalizedLength);
|
|
@@ -27,26 +124,55 @@ export function resolveTngOtpState(length, value) {
|
|
|
27
124
|
}
|
|
28
125
|
return clampedValue.length >= normalizedLength ? 'complete' : 'partial';
|
|
29
126
|
}
|
|
127
|
+
export function resolveTngOtpBackspaceResult(value, index, length) {
|
|
128
|
+
const normalizedLength = normalizeTngOtpLength(length);
|
|
129
|
+
const normalizedValue = clampTngOtpValue(normalizeTngOtpValue(value), normalizedLength);
|
|
130
|
+
if (normalizedValue.length === 0) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
const boundedIndex = Number.isFinite(index)
|
|
134
|
+
? Math.max(0, Math.min(Math.trunc(index), normalizedLength - 1))
|
|
135
|
+
: 0;
|
|
136
|
+
const nextChars = Array.from(normalizedValue);
|
|
137
|
+
if (boundedIndex < normalizedValue.length) {
|
|
138
|
+
nextChars.splice(boundedIndex, 1);
|
|
139
|
+
return {
|
|
140
|
+
focusIndex: Math.max(0, boundedIndex - 1),
|
|
141
|
+
value: nextChars.join(''),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
const previousIndex = Math.max(0, normalizedValue.length - 1);
|
|
145
|
+
nextChars.splice(previousIndex, 1);
|
|
146
|
+
return {
|
|
147
|
+
focusIndex: Math.max(0, previousIndex),
|
|
148
|
+
value: nextChars.join(''),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
30
151
|
export class TngInputOtp {
|
|
152
|
+
hostElement = inject((ElementRef)).nativeElement;
|
|
31
153
|
length = input(6, { ...(ngDevMode ? { debugName: "length" } : {}), transform: (value) => normalizeTngOtpLength(typeof value === 'number' ? value : Number(value)) });
|
|
32
|
-
value =
|
|
154
|
+
value = model('', ...(ngDevMode ? [{ debugName: "value" }] : []));
|
|
33
155
|
disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : {}), transform: booleanAttribute });
|
|
34
156
|
readonly = input(false, { ...(ngDevMode ? { debugName: "readonly" } : {}), transform: booleanAttribute });
|
|
35
157
|
required = input(false, { ...(ngDevMode ? { debugName: "required" } : {}), transform: booleanAttribute });
|
|
36
158
|
invalid = input(false, { ...(ngDevMode ? { debugName: "invalid" } : {}), transform: booleanAttribute });
|
|
37
159
|
focused = input(false, { ...(ngDevMode ? { debugName: "focused" } : {}), transform: booleanAttribute });
|
|
38
160
|
focusVisible = input(false, { ...(ngDevMode ? { debugName: "focusVisible" } : {}), transform: booleanAttribute });
|
|
39
|
-
activeIndex =
|
|
161
|
+
activeIndex = model(null, ...(ngDevMode ? [{ debugName: "activeIndex" }] : []));
|
|
162
|
+
type = input('numeric', ...(ngDevMode ? [{ debugName: "type" }] : []));
|
|
163
|
+
pattern = input(null, ...(ngDevMode ? [{ debugName: "pattern" }] : []));
|
|
164
|
+
selectOnFocus = input(true, { ...(ngDevMode ? { debugName: "selectOnFocus" } : {}), transform: booleanAttribute });
|
|
165
|
+
complete = output();
|
|
40
166
|
dataSlot = 'input-otp';
|
|
41
167
|
roleAttr = 'group';
|
|
42
168
|
get dataEmptyAttr() {
|
|
43
|
-
return resolveTngOtpState(this.length(), this.
|
|
169
|
+
return resolveTngOtpState(this.length(), this.normalizedValue()) === 'empty' ? '' : null;
|
|
44
170
|
}
|
|
45
171
|
get dataPartialAttr() {
|
|
46
|
-
return resolveTngOtpState(this.length(), this.
|
|
172
|
+
return resolveTngOtpState(this.length(), this.normalizedValue()) === 'partial' ? '' : null;
|
|
47
173
|
}
|
|
48
174
|
get dataCompleteAttr() {
|
|
49
|
-
return resolveTngOtpState(this.length(), this.
|
|
175
|
+
return resolveTngOtpState(this.length(), this.normalizedValue()) === 'complete' ? '' : null;
|
|
50
176
|
}
|
|
51
177
|
get dataDisabledAttr() {
|
|
52
178
|
return this.disabled() ? '' : null;
|
|
@@ -74,10 +200,184 @@ export class TngInputOtp {
|
|
|
74
200
|
if (index < 0 || index >= this.length()) {
|
|
75
201
|
return null;
|
|
76
202
|
}
|
|
77
|
-
return String(index);
|
|
203
|
+
return String(clampOtpIndex(index, this.length()));
|
|
204
|
+
}
|
|
205
|
+
slotValue(index) {
|
|
206
|
+
const slot = toTngOtpSlots(this.length(), this.normalizedValue())[index];
|
|
207
|
+
return slot ?? '';
|
|
208
|
+
}
|
|
209
|
+
isSlotTabbable(index) {
|
|
210
|
+
return this.resolvedActiveIndex() === index;
|
|
211
|
+
}
|
|
212
|
+
handleSlotFocus(index, target) {
|
|
213
|
+
const nextIndex = this.resolveEditableIndex(index);
|
|
214
|
+
this.activeIndex.set(nextIndex);
|
|
215
|
+
if (this.selectOnFocus() && target instanceof HTMLInputElement) {
|
|
216
|
+
target.select();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
handleSlotKeydown(index, event) {
|
|
220
|
+
const editableIndex = this.resolveEditableIndex(index);
|
|
221
|
+
const total = this.length();
|
|
222
|
+
if (event.key === 'ArrowLeft') {
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
this.focusSlot(Math.max(0, editableIndex - 1), true);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (event.key === 'ArrowRight') {
|
|
228
|
+
event.preventDefault();
|
|
229
|
+
this.focusSlot(Math.min(total - 1, editableIndex + 1), true);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (event.key === 'Home') {
|
|
233
|
+
event.preventDefault();
|
|
234
|
+
this.focusSlot(0, true);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (event.key === 'End') {
|
|
238
|
+
event.preventDefault();
|
|
239
|
+
this.focusSlot(resolveTngOtpEndIndex(this.normalizedValue(), total), true);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (event.key === 'Backspace') {
|
|
243
|
+
event.preventDefault();
|
|
244
|
+
this.handleBackspace(editableIndex);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (event.key === 'Delete') {
|
|
248
|
+
event.preventDefault();
|
|
249
|
+
this.handleDelete(editableIndex);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if ((this.disabled() || this.readonly()) && event.key.length === 1) {
|
|
253
|
+
event.preventDefault();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
handleSlotInput(index, target) {
|
|
257
|
+
if (!(target instanceof HTMLInputElement)) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (this.disabled() || this.readonly()) {
|
|
261
|
+
target.value = this.slotValue(this.resolveEditableIndex(index));
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const chars = sanitizeTngOtpCharacters(target.value, this.type(), this.pattern());
|
|
265
|
+
if (chars.length === 0) {
|
|
266
|
+
const nextValue = removeTngOtpCharacter(this.normalizedValue(), this.resolveEditableIndex(index));
|
|
267
|
+
this.commitValue(nextValue, this.resolveEditableIndex(index));
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const previousValue = this.normalizedValue();
|
|
271
|
+
const totalLength = this.length();
|
|
272
|
+
const editableIndex = this.resolveEditableIndex(index);
|
|
273
|
+
const wasCompleteBeforeInput = previousValue.length >= totalLength;
|
|
274
|
+
const wasReplacingExistingCharacter = editableIndex < previousValue.length;
|
|
275
|
+
const nextValue = applyTngOtpCharacters(previousValue, editableIndex, chars, totalLength);
|
|
276
|
+
const nextFocus = wasCompleteBeforeInput || wasReplacingExistingCharacter
|
|
277
|
+
? Math.min(totalLength - 1, editableIndex + chars.length)
|
|
278
|
+
: nextValue.length >= totalLength
|
|
279
|
+
? totalLength - 1
|
|
280
|
+
: Math.min(totalLength - 1, Math.max(editableIndex + chars.length, nextValue.length));
|
|
281
|
+
this.commitValue(nextValue, nextFocus);
|
|
282
|
+
}
|
|
283
|
+
handleSlotPaste(index, event) {
|
|
284
|
+
if (this.disabled() || this.readonly()) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const clipboardValue = event.clipboardData?.getData('text') ?? '';
|
|
288
|
+
const chars = sanitizeTngOtpCharacters(clipboardValue, this.type(), this.pattern());
|
|
289
|
+
if (chars.length === 0) {
|
|
290
|
+
event.preventDefault();
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
event.preventDefault();
|
|
294
|
+
const editableIndex = this.resolveEditableIndex(index);
|
|
295
|
+
const nextValue = applyTngOtpCharacters(this.normalizedValue(), editableIndex, chars, this.length());
|
|
296
|
+
const nextFocus = nextValue.length >= this.length()
|
|
297
|
+
? this.length() - 1
|
|
298
|
+
: Math.min(this.length() - 1, nextValue.length);
|
|
299
|
+
this.commitValue(nextValue, nextFocus);
|
|
300
|
+
}
|
|
301
|
+
normalizedValue() {
|
|
302
|
+
const chars = sanitizeTngOtpCharacters(normalizeTngOtpValue(this.value()), this.type(), this.pattern());
|
|
303
|
+
return chars.slice(0, this.length()).join('');
|
|
304
|
+
}
|
|
305
|
+
resolvedActiveIndex() {
|
|
306
|
+
const current = this.activeIndex();
|
|
307
|
+
if (typeof current === 'number' && Number.isFinite(current)) {
|
|
308
|
+
return clampOtpIndex(current, this.length());
|
|
309
|
+
}
|
|
310
|
+
return resolveTngOtpEntryIndex(this.normalizedValue(), this.length());
|
|
311
|
+
}
|
|
312
|
+
resolveEditableIndex(index) {
|
|
313
|
+
const safeIndex = clampOtpIndex(index, this.length());
|
|
314
|
+
const currentValueLength = this.normalizedValue().length;
|
|
315
|
+
if (currentValueLength >= this.length()) {
|
|
316
|
+
return safeIndex;
|
|
317
|
+
}
|
|
318
|
+
return Math.min(safeIndex, currentValueLength);
|
|
319
|
+
}
|
|
320
|
+
handleBackspace(index) {
|
|
321
|
+
if (this.disabled() || this.readonly()) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const nextState = resolveTngOtpBackspaceResult(this.normalizedValue(), index, this.length());
|
|
325
|
+
if (nextState === null) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
this.commitValue(nextState.value, nextState.focusIndex);
|
|
329
|
+
}
|
|
330
|
+
handleDelete(index) {
|
|
331
|
+
if (this.disabled() || this.readonly()) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (index >= this.normalizedValue().length) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const nextValue = removeTngOtpCharacter(this.normalizedValue(), index);
|
|
338
|
+
this.commitValue(nextValue, index);
|
|
339
|
+
}
|
|
340
|
+
commitValue(nextValue, nextFocusIndex) {
|
|
341
|
+
const previousValue = this.normalizedValue();
|
|
342
|
+
const normalized = clampTngOtpValue(sanitizeTngOtpCharacters(nextValue, this.type(), this.pattern()).join(''), this.length());
|
|
343
|
+
const didChange = normalized !== previousValue;
|
|
344
|
+
this.value.set(normalized);
|
|
345
|
+
this.activeIndex.set(clampOtpIndex(nextFocusIndex, this.length()));
|
|
346
|
+
if (didChange && resolveTngOtpState(this.length(), normalized) === 'complete') {
|
|
347
|
+
this.complete.emit(normalized);
|
|
348
|
+
}
|
|
349
|
+
queueMicrotask(() => {
|
|
350
|
+
this.syncSlotInputValues();
|
|
351
|
+
this.focusSlot(this.resolvedActiveIndex(), this.selectOnFocus());
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
focusSlot(index, select) {
|
|
355
|
+
const safeIndex = clampOtpIndex(index, this.length());
|
|
356
|
+
const slot = this.hostElement.querySelector(`[data-tng-otp-slot='${safeIndex}']`);
|
|
357
|
+
if (!(slot instanceof HTMLInputElement)) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
slot.focus();
|
|
361
|
+
if (select) {
|
|
362
|
+
slot.select();
|
|
363
|
+
}
|
|
364
|
+
this.activeIndex.set(safeIndex);
|
|
365
|
+
}
|
|
366
|
+
syncSlotInputValues() {
|
|
367
|
+
const slotInputs = this.hostElement.querySelectorAll('[data-tng-otp-slot]');
|
|
368
|
+
slotInputs.forEach((slotInput) => {
|
|
369
|
+
if (!(slotInput instanceof HTMLInputElement)) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const slotIndex = Number(slotInput.getAttribute('data-tng-otp-slot'));
|
|
373
|
+
if (!Number.isFinite(slotIndex)) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
slotInput.value = this.slotValue(slotIndex);
|
|
377
|
+
});
|
|
78
378
|
}
|
|
79
379
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngInputOtp, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
80
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.1", type: TngInputOtp, isStandalone: true, selector: "[tngInputOtp]", inputs: { length: { classPropertyName: "length", publicName: "length", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, focused: { classPropertyName: "focused", publicName: "focused", isSignal: true, isRequired: false, transformFunction: null }, focusVisible: { classPropertyName: "focusVisible", publicName: "focusVisible", isSignal: true, isRequired: false, transformFunction: null }, activeIndex: { classPropertyName: "activeIndex", publicName: "activeIndex", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.data-slot": "this.dataSlot", "attr.role": "this.roleAttr", "attr.data-empty": "this.dataEmptyAttr", "attr.data-partial": "this.dataPartialAttr", "attr.data-complete": "this.dataCompleteAttr", "attr.data-disabled": "this.dataDisabledAttr", "attr.data-readonly": "this.dataReadonlyAttr", "attr.data-required": "this.dataRequiredAttr", "attr.data-invalid": "this.dataInvalidAttr", "attr.data-focused": "this.dataFocusedAttr", "attr.data-focus-visible": "this.dataFocusVisibleAttr", "attr.data-active": "this.dataActiveAttr" } }, exportAs: ["tngInputOtp"], ngImport: i0 });
|
|
380
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.1", type: TngInputOtp, isStandalone: true, selector: "[tngInputOtp]", inputs: { length: { classPropertyName: "length", publicName: "length", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, focused: { classPropertyName: "focused", publicName: "focused", isSignal: true, isRequired: false, transformFunction: null }, focusVisible: { classPropertyName: "focusVisible", publicName: "focusVisible", isSignal: true, isRequired: false, transformFunction: null }, activeIndex: { classPropertyName: "activeIndex", publicName: "activeIndex", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, pattern: { classPropertyName: "pattern", publicName: "pattern", isSignal: true, isRequired: false, transformFunction: null }, selectOnFocus: { classPropertyName: "selectOnFocus", publicName: "selectOnFocus", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange", activeIndex: "activeIndexChange", complete: "complete" }, host: { properties: { "attr.data-slot": "this.dataSlot", "attr.role": "this.roleAttr", "attr.data-empty": "this.dataEmptyAttr", "attr.data-partial": "this.dataPartialAttr", "attr.data-complete": "this.dataCompleteAttr", "attr.data-disabled": "this.dataDisabledAttr", "attr.data-readonly": "this.dataReadonlyAttr", "attr.data-required": "this.dataRequiredAttr", "attr.data-invalid": "this.dataInvalidAttr", "attr.data-focused": "this.dataFocusedAttr", "attr.data-focus-visible": "this.dataFocusVisibleAttr", "attr.data-active": "this.dataActiveAttr" } }, exportAs: ["tngInputOtp"], ngImport: i0 });
|
|
81
381
|
}
|
|
82
382
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngInputOtp, decorators: [{
|
|
83
383
|
type: Directive,
|
|
@@ -85,7 +385,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
|
|
|
85
385
|
selector: '[tngInputOtp]',
|
|
86
386
|
exportAs: 'tngInputOtp',
|
|
87
387
|
}]
|
|
88
|
-
}], propDecorators: { length: [{ type: i0.Input, args: [{ isSignal: true, alias: "length", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }], focused: [{ type: i0.Input, args: [{ isSignal: true, alias: "focused", required: false }] }], focusVisible: [{ type: i0.Input, args: [{ isSignal: true, alias: "focusVisible", required: false }] }], activeIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeIndex", required: false }] }], dataSlot: [{
|
|
388
|
+
}], propDecorators: { length: [{ type: i0.Input, args: [{ isSignal: true, alias: "length", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }], focused: [{ type: i0.Input, args: [{ isSignal: true, alias: "focused", required: false }] }], focusVisible: [{ type: i0.Input, args: [{ isSignal: true, alias: "focusVisible", required: false }] }], activeIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeIndex", required: false }] }, { type: i0.Output, args: ["activeIndexChange"] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], pattern: [{ type: i0.Input, args: [{ isSignal: true, alias: "pattern", required: false }] }], selectOnFocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectOnFocus", required: false }] }], complete: [{ type: i0.Output, args: ["complete"] }], dataSlot: [{
|
|
89
389
|
type: HostBinding,
|
|
90
390
|
args: ['attr.data-slot']
|
|
91
391
|
}], roleAttr: [{
|
|
@@ -122,4 +422,67 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
|
|
|
122
422
|
type: HostBinding,
|
|
123
423
|
args: ['attr.data-active']
|
|
124
424
|
}] } });
|
|
425
|
+
export class TngInputOtpSlot {
|
|
426
|
+
otp = inject(TngInputOtp);
|
|
427
|
+
elementRef = inject(ElementRef);
|
|
428
|
+
index = input(0, { ...(ngDevMode ? { debugName: "index" } : {}), alias: 'tngInputOtpSlot',
|
|
429
|
+
transform: (value) => Number.isFinite(typeof value === 'number' ? value : Number(value))
|
|
430
|
+
? Math.trunc(typeof value === 'number' ? value : Number(value))
|
|
431
|
+
: 0 });
|
|
432
|
+
dataSlot = 'input-otp-slot';
|
|
433
|
+
get dataIndexAttr() {
|
|
434
|
+
return String(this.index());
|
|
435
|
+
}
|
|
436
|
+
get valueProp() {
|
|
437
|
+
return this.otp.slotValue(this.index());
|
|
438
|
+
}
|
|
439
|
+
get tabIndexProp() {
|
|
440
|
+
return this.otp.isSlotTabbable(this.index()) ? 0 : -1;
|
|
441
|
+
}
|
|
442
|
+
onFocus() {
|
|
443
|
+
this.otp.handleSlotFocus(this.index(), this.elementRef.nativeElement);
|
|
444
|
+
}
|
|
445
|
+
onKeydown(event) {
|
|
446
|
+
this.otp.handleSlotKeydown(this.index(), event);
|
|
447
|
+
}
|
|
448
|
+
onInput() {
|
|
449
|
+
this.otp.handleSlotInput(this.index(), this.elementRef.nativeElement);
|
|
450
|
+
}
|
|
451
|
+
onPaste(event) {
|
|
452
|
+
this.otp.handleSlotPaste(this.index(), event);
|
|
453
|
+
}
|
|
454
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngInputOtpSlot, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
455
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.1", type: TngInputOtpSlot, isStandalone: true, selector: "input[tngInputOtpSlot]", inputs: { index: { classPropertyName: "index", publicName: "tngInputOtpSlot", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "focus": "onFocus()", "keydown": "onKeydown($event)", "input": "onInput()", "paste": "onPaste($event)" }, properties: { "attr.data-slot": "this.dataSlot", "attr.data-tng-otp-slot": "this.dataIndexAttr", "value": "this.valueProp", "tabIndex": "this.tabIndexProp" } }, exportAs: ["tngInputOtpSlot"], ngImport: i0 });
|
|
456
|
+
}
|
|
457
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngInputOtpSlot, decorators: [{
|
|
458
|
+
type: Directive,
|
|
459
|
+
args: [{
|
|
460
|
+
selector: 'input[tngInputOtpSlot]',
|
|
461
|
+
exportAs: 'tngInputOtpSlot',
|
|
462
|
+
}]
|
|
463
|
+
}], propDecorators: { index: [{ type: i0.Input, args: [{ isSignal: true, alias: "tngInputOtpSlot", required: false }] }], dataSlot: [{
|
|
464
|
+
type: HostBinding,
|
|
465
|
+
args: ['attr.data-slot']
|
|
466
|
+
}], dataIndexAttr: [{
|
|
467
|
+
type: HostBinding,
|
|
468
|
+
args: ['attr.data-tng-otp-slot']
|
|
469
|
+
}], valueProp: [{
|
|
470
|
+
type: HostBinding,
|
|
471
|
+
args: ['value']
|
|
472
|
+
}], tabIndexProp: [{
|
|
473
|
+
type: HostBinding,
|
|
474
|
+
args: ['tabIndex']
|
|
475
|
+
}], onFocus: [{
|
|
476
|
+
type: HostListener,
|
|
477
|
+
args: ['focus']
|
|
478
|
+
}], onKeydown: [{
|
|
479
|
+
type: HostListener,
|
|
480
|
+
args: ['keydown', ['$event']]
|
|
481
|
+
}], onInput: [{
|
|
482
|
+
type: HostListener,
|
|
483
|
+
args: ['input']
|
|
484
|
+
}], onPaste: [{
|
|
485
|
+
type: HostListener,
|
|
486
|
+
args: ['paste', ['$event']]
|
|
487
|
+
}] } });
|
|
125
488
|
//# sourceMappingURL=tng-input-otp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tng-input-otp.js","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/input-otp/tng-input-otp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;;AAEhF,MAAM,UAAU,qBAAqB,CAAC,KAAa;IACjD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;QAChB,OAAO,CAAC,CAAC;IACX,CAAC;IAED,OAAO,OAAO,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AACrC,CAAC;AAID,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAa,EAAE,MAAc;IAC5D,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,E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AED,IACc,oBAAoB;QAChC,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACzC,CAAC;IAED,IACc,cAAc;QAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACzD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;YACxC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;uGAzFU,WAAW;2FAAX,WAAW;;2FAAX,WAAW;kBAJvB,SAAS;mBAAC;oBACT,QAAQ,EAAE,eAAe;oBACzB,QAAQ,EAAE,aAAa;iBACxB;;sBA2BE,WAAW;uBAAC,gBAAgB;;sBAG5B,WAAW;uBAAC,WAAW;;sBAGvB,WAAW;uBAAC,iBAAiB;;sBAK7B,WAAW;uBAAC,mBAAmB;;sBAK/B,WAAW;uBAAC,oBAAoB;;sBAKhC,WAAW;uBAAC,oBAAoB;;sBAKhC,WAAW;uBAAC,oBAAoB;;sBAKhC,WAAW;uBAAC,oBAAoB;;sBAKhC,WAAW;uBAAC,mBAAmB;;sBAK/B,WAAW;uBAAC,mBAAmB;;sBAK/B,WAAW;uBAAC,yBAAyB;;sBAKrC,WAAW;uBAAC,kBAAkB","sourcesContent":["import { Directive, HostBinding, booleanAttribute, input } from '@angular/core';\n\nexport function normalizeTngOtpLength(value: number): number {\n if (!Number.isFinite(value)) {\n return 6;\n }\n\n const rounded = Math.trunc(value);\n if (rounded < 1) {\n return 1;\n }\n\n return rounded > 12 ? 12 : rounded;\n}\n\nexport type TngOtpCompletionState = 'complete' | 'empty' | 'partial';\n\nexport function normalizeTngOtpValue(value: unknown): string {\n if (typeof value !== 'string') {\n return '';\n }\n\n return value;\n}\n\nexport function clampTngOtpValue(value: string, length: number): string {\n return Array.from(value).slice(0, length).join('');\n}\n\nexport function resolveTngOtpState(length: number, value: string): TngOtpCompletionState {\n const normalizedLength = normalizeTngOtpLength(length);\n const clampedValue = clampTngOtpValue(normalizeTngOtpValue(value), normalizedLength);\n\n if (clampedValue.length === 0) {\n return 'empty';\n }\n\n return clampedValue.length >= normalizedLength ? 'complete' : 'partial';\n}\n\n@Directive({\n selector: '[tngInputOtp]',\n exportAs: 'tngInputOtp',\n})\nexport class TngInputOtp {\n public readonly length = input<number, number | string>(6, {\n transform: (value: number | string): number =>\n normalizeTngOtpLength(typeof value === 'number' ? value : Number(value)),\n });\n public readonly value = input<string>('');\n public readonly disabled = input<boolean, boolean | string>(false, {\n transform: booleanAttribute,\n });\n public readonly readonly = input<boolean, boolean | string>(false, {\n transform: booleanAttribute,\n });\n public readonly required = input<boolean, boolean | string>(false, {\n transform: booleanAttribute,\n });\n public readonly invalid = input<boolean, boolean | string>(false, {\n transform: booleanAttribute,\n });\n public readonly focused = input<boolean, boolean | string>(false, {\n transform: booleanAttribute,\n });\n public readonly focusVisible = input<boolean, boolean | string>(false, {\n transform: booleanAttribute,\n });\n public readonly activeIndex = input<number | null>(null);\n\n @HostBinding('attr.data-slot')\n protected readonly dataSlot = 'input-otp' as const;\n\n @HostBinding('attr.role')\n protected readonly roleAttr = 'group' as const;\n\n @HostBinding('attr.data-empty')\n protected get dataEmptyAttr(): '' | null {\n return resolveTngOtpState(this.length(), this.value()) === 'empty' ? '' : null;\n }\n\n @HostBinding('attr.data-partial')\n protected get dataPartialAttr(): '' | null {\n return resolveTngOtpState(this.length(), this.value()) === 'partial' ? '' : null;\n }\n\n @HostBinding('attr.data-complete')\n protected get dataCompleteAttr(): '' | null {\n return resolveTngOtpState(this.length(), this.value()) === 'complete' ? '' : null;\n }\n\n @HostBinding('attr.data-disabled')\n protected get dataDisabledAttr(): '' | null {\n return this.disabled() ? '' : null;\n }\n\n @HostBinding('attr.data-readonly')\n protected get dataReadonlyAttr(): '' | null {\n return this.readonly() ? '' : null;\n }\n\n @HostBinding('attr.data-required')\n protected get dataRequiredAttr(): '' | null {\n return this.required() ? '' : null;\n }\n\n @HostBinding('attr.data-invalid')\n protected get dataInvalidAttr(): '' | null {\n return this.invalid() ? '' : null;\n }\n\n @HostBinding('attr.data-focused')\n protected get dataFocusedAttr(): '' | null {\n return this.focused() ? '' : null;\n }\n\n @HostBinding('attr.data-focus-visible')\n protected get dataFocusVisibleAttr(): '' | null {\n return this.focusVisible() ? '' : null;\n }\n\n @HostBinding('attr.data-active')\n protected get dataActiveAttr(): string | null {\n const index = this.activeIndex();\n if (typeof index !== 'number' || !Number.isFinite(index)) {\n return null;\n }\n\n if (index < 0 || index >= this.length()) {\n return null;\n }\n\n return String(index);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tng-input-otp.js","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/input-otp/tng-input-otp.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,MAAM,EACN,KAAK,EACL,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;;AAEvB,MAAM,UAAU,qBAAqB,CAAC,KAAa;IACjD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;QAChB,OAAO,CAAC,CAAC;IACX,CAAC;IAED,OAAO,OAAO,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AACrC,CAAC;AAID,MAAM,UAAU,oBAAoB,CAAC,KA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AY;uBAAC,SAAS,EAAE,CAAC,QAAQ,CAAC;;sBAKlC,YAAY;uBAAC,OAAO;;sBAKpB,YAAY;uBAAC,OAAO,EAAE,CAAC,QAAQ,CAAC","sourcesContent":["import {\n Directive,\n ElementRef,\n HostBinding,\n HostListener,\n booleanAttribute,\n inject,\n input,\n model,\n output,\n} from '@angular/core';\n\nexport function normalizeTngOtpLength(value: number): number {\n if (!Number.isFinite(value)) {\n return 6;\n }\n\n const rounded = Math.trunc(value);\n if (rounded < 1) {\n return 1;\n }\n\n return rounded > 12 ? 12 : rounded;\n}\n\nexport type TngOtpCompletionState = 'complete' | 'empty' | 'partial';\n\nexport function normalizeTngOtpValue(value: unknown): string {\n if (typeof value !== 'string') {\n return '';\n }\n\n return value;\n}\n\nexport function clampTngOtpValue(value: string, length: number): string {\n return Array.from(value).slice(0, length).join('');\n}\n\nexport type TngInputOtpType = 'numeric' | 'alphanumeric' | 'custom';\n\nconst tngOtpDigitPattern = /^\\d$/;\nconst tngOtpAlphanumericPattern = /^[a-zA-Z0-9]$/;\n\nfunction toNonGlobalRegex(pattern: RegExp): RegExp {\n const flags = pattern.flags.replace(/g/g, '');\n return new RegExp(pattern.source, flags);\n}\n\nexport function sanitizeTngOtpCharacters(\n value: string,\n mode: TngInputOtpType,\n pattern: string | RegExp | null,\n): readonly string[] {\n const compiledPattern =\n mode !== 'custom'\n ? null\n : typeof pattern === 'string'\n ? new RegExp(pattern)\n : pattern === null\n ? null\n : toNonGlobalRegex(pattern);\n\n const acceptedChars: string[] = [];\n for (const char of Array.from(value)) {\n if (mode === 'numeric' && !tngOtpDigitPattern.test(char)) {\n continue;\n }\n\n if (mode === 'alphanumeric' && !tngOtpAlphanumericPattern.test(char)) {\n continue;\n }\n\n if (compiledPattern && !compiledPattern.test(char)) {\n continue;\n }\n\n acceptedChars.push(char);\n }\n\n return acceptedChars;\n}\n\nexport function toTngOtpSlots(length: number, value: string): readonly string[] {\n const safeLength = normalizeTngOtpLength(length);\n const slots = Array.from({ length: safeLength }, () => '');\n const chars = Array.from(clampTngOtpValue(value, safeLength));\n\n for (const [index, char] of chars.entries()) {\n if (index >= safeLength) {\n break;\n }\n\n slots[index] = char;\n }\n\n return slots;\n}\n\nexport function applyTngOtpCharacters(\n value: string,\n startIndex: number,\n characters: readonly string[],\n maxLength: number,\n): string {\n const safeLength = normalizeTngOtpLength(maxLength);\n const nextChars = Array.from(clampTngOtpValue(value, safeLength));\n const safeStart = Math.max(0, Math.min(startIndex, safeLength - 1));\n\n let cursor = nextChars.length < safeLength ? Math.min(safeStart, nextChars.length) : safeStart;\n for (const char of characters) {\n if (cursor >= safeLength) {\n break;\n }\n\n if (cursor < nextChars.length) {\n nextChars[cursor] = char;\n } else {\n nextChars.push(char);\n }\n\n cursor += 1;\n }\n\n return nextChars.slice(0, safeLength).join('');\n}\n\nexport function removeTngOtpCharacter(value: string, index: number): string {\n const chars = Array.from(value);\n if (index < 0 || index >= chars.length) {\n return value;\n }\n\n chars.splice(index, 1);\n return chars.join('');\n}\n\nexport function resolveTngOtpEntryIndex(value: string, length: number): number {\n const safeLength = normalizeTngOtpLength(length);\n const safeValue = clampTngOtpValue(value, safeLength);\n if (safeValue.length >= safeLength) {\n return safeLength - 1;\n }\n\n return safeValue.length;\n}\n\nexport function resolveTngOtpEndIndex(value: string, length: number): number {\n const safeLength = normalizeTngOtpLength(length);\n const safeValue = clampTngOtpValue(value, safeLength);\n if (safeValue.length === 0) {\n return safeLength - 1;\n }\n\n return Math.max(0, safeValue.length - 1);\n}\n\nfunction clampOtpIndex(index: number, length: number): number {\n const safeLength = normalizeTngOtpLength(length);\n if (!Number.isFinite(index)) {\n return 0;\n }\n\n if (index < 0) {\n return 0;\n }\n\n if (index >= safeLength) {\n return safeLength - 1;\n }\n\n return Math.trunc(index);\n}\n\nexport type TngOtpBackspaceResult = Readonly<{\n focusIndex: number;\n value: string;\n}>;\n\nexport function resolveTngOtpState(length: number, value: string): TngOtpCompletionState {\n const normalizedLength = normalizeTngOtpLength(length);\n const clampedValue = clampTngOtpValue(normalizeTngOtpValue(value), normalizedLength);\n\n if (clampedValue.length === 0) {\n return 'empty';\n }\n\n return clampedValue.length >= normalizedLength ? 'complete' : 'partial';\n}\n\nexport function resolveTngOtpBackspaceResult(\n value: string,\n index: number,\n length: number,\n): TngOtpBackspaceResult | null {\n const normalizedLength = normalizeTngOtpLength(length);\n const normalizedValue = clampTngOtpValue(normalizeTngOtpValue(value), normalizedLength);\n if (normalizedValue.length === 0) {\n return null;\n }\n\n const boundedIndex = Number.isFinite(index)\n ? Math.max(0, Math.min(Math.trunc(index), normalizedLength - 1))\n : 0;\n const nextChars = Array.from(normalizedValue);\n\n if (boundedIndex < normalizedValue.length) {\n nextChars.splice(boundedIndex, 1);\n return {\n focusIndex: Math.max(0, boundedIndex - 1),\n value: nextChars.join(''),\n };\n }\n\n const previousIndex = Math.max(0, normalizedValue.length - 1);\n nextChars.splice(previousIndex, 1);\n return {\n focusIndex: Math.max(0, previousIndex),\n value: nextChars.join(''),\n };\n}\n\n@Directive({\n selector: '[tngInputOtp]',\n exportAs: 'tngInputOtp',\n})\nexport class TngInputOtp {\n readonly hostElement = inject(ElementRef<HTMLElement>).nativeElement;\n\n public readonly length = input<number, number | string>(6, {\n transform: (value: number | string): number =>\n normalizeTngOtpLength(typeof value === 'number' ? value : Number(value)),\n });\n public readonly value = model<string>('');\n public readonly disabled = input<boolean, boolean | string>(false, {\n transform: booleanAttribute,\n });\n public readonly readonly = input<boolean, boolean | string>(false, {\n transform: booleanAttribute,\n });\n public readonly required = input<boolean, boolean | string>(false, {\n transform: booleanAttribute,\n });\n public readonly invalid = input<boolean, boolean | string>(false, {\n transform: booleanAttribute,\n });\n public readonly focused = input<boolean, boolean | string>(false, {\n transform: booleanAttribute,\n });\n public readonly focusVisible = input<boolean, boolean | string>(false, {\n transform: booleanAttribute,\n });\n public readonly activeIndex = model<number | null>(null);\n public readonly type = input<TngInputOtpType>('numeric');\n public readonly pattern = input<string | RegExp | null>(null);\n public readonly selectOnFocus = input<boolean, boolean | string>(true, {\n transform: booleanAttribute,\n });\n\n public readonly complete = output<string>();\n\n @HostBinding('attr.data-slot')\n protected readonly dataSlot = 'input-otp' as const;\n\n @HostBinding('attr.role')\n protected readonly roleAttr = 'group' as const;\n\n @HostBinding('attr.data-empty')\n protected get dataEmptyAttr(): '' | null {\n return resolveTngOtpState(this.length(), this.normalizedValue()) === 'empty' ? '' : null;\n }\n\n @HostBinding('attr.data-partial')\n protected get dataPartialAttr(): '' | null {\n return resolveTngOtpState(this.length(), this.normalizedValue()) === 'partial' ? '' : null;\n }\n\n @HostBinding('attr.data-complete')\n protected get dataCompleteAttr(): '' | null {\n return resolveTngOtpState(this.length(), this.normalizedValue()) === 'complete' ? '' : null;\n }\n\n @HostBinding('attr.data-disabled')\n protected get dataDisabledAttr(): '' | null {\n return this.disabled() ? '' : null;\n }\n\n @HostBinding('attr.data-readonly')\n protected get dataReadonlyAttr(): '' | null {\n return this.readonly() ? '' : null;\n }\n\n @HostBinding('attr.data-required')\n protected get dataRequiredAttr(): '' | null {\n return this.required() ? '' : null;\n }\n\n @HostBinding('attr.data-invalid')\n protected get dataInvalidAttr(): '' | null {\n return this.invalid() ? '' : null;\n }\n\n @HostBinding('attr.data-focused')\n protected get dataFocusedAttr(): '' | null {\n return this.focused() ? '' : null;\n }\n\n @HostBinding('attr.data-focus-visible')\n protected get dataFocusVisibleAttr(): '' | null {\n return this.focusVisible() ? '' : null;\n }\n\n @HostBinding('attr.data-active')\n protected get dataActiveAttr(): string | null {\n const index = this.activeIndex();\n if (typeof index !== 'number' || !Number.isFinite(index)) {\n return null;\n }\n\n if (index < 0 || index >= this.length()) {\n return null;\n }\n\n return String(clampOtpIndex(index, this.length()));\n }\n\n public slotValue(index: number): string {\n const slot = toTngOtpSlots(this.length(), this.normalizedValue())[index];\n return slot ?? '';\n }\n\n public isSlotTabbable(index: number): boolean {\n return this.resolvedActiveIndex() === index;\n }\n\n public handleSlotFocus(index: number, target: HTMLInputElement | null): void {\n const nextIndex = this.resolveEditableIndex(index);\n this.activeIndex.set(nextIndex);\n\n if (this.selectOnFocus() && target instanceof HTMLInputElement) {\n target.select();\n }\n }\n\n public handleSlotKeydown(index: number, event: KeyboardEvent): void {\n const editableIndex = this.resolveEditableIndex(index);\n const total = this.length();\n\n if (event.key === 'ArrowLeft') {\n event.preventDefault();\n this.focusSlot(Math.max(0, editableIndex - 1), true);\n return;\n }\n\n if (event.key === 'ArrowRight') {\n event.preventDefault();\n this.focusSlot(Math.min(total - 1, editableIndex + 1), true);\n return;\n }\n\n if (event.key === 'Home') {\n event.preventDefault();\n this.focusSlot(0, true);\n return;\n }\n\n if (event.key === 'End') {\n event.preventDefault();\n this.focusSlot(resolveTngOtpEndIndex(this.normalizedValue(), total), true);\n return;\n }\n\n if (event.key === 'Backspace') {\n event.preventDefault();\n this.handleBackspace(editableIndex);\n return;\n }\n\n if (event.key === 'Delete') {\n event.preventDefault();\n this.handleDelete(editableIndex);\n return;\n }\n\n if ((this.disabled() || this.readonly()) && event.key.length === 1) {\n event.preventDefault();\n }\n }\n\n public handleSlotInput(index: number, target: HTMLInputElement | null): void {\n if (!(target instanceof HTMLInputElement)) {\n return;\n }\n\n if (this.disabled() || this.readonly()) {\n target.value = this.slotValue(this.resolveEditableIndex(index));\n return;\n }\n\n const chars = sanitizeTngOtpCharacters(target.value, this.type(), this.pattern());\n if (chars.length === 0) {\n const nextValue = removeTngOtpCharacter(this.normalizedValue(), this.resolveEditableIndex(index));\n this.commitValue(nextValue, this.resolveEditableIndex(index));\n return;\n }\n\n const previousValue = this.normalizedValue();\n const totalLength = this.length();\n const editableIndex = this.resolveEditableIndex(index);\n const wasCompleteBeforeInput = previousValue.length >= totalLength;\n const wasReplacingExistingCharacter = editableIndex < previousValue.length;\n const nextValue = applyTngOtpCharacters(previousValue, editableIndex, chars, totalLength);\n const nextFocus =\n wasCompleteBeforeInput || wasReplacingExistingCharacter\n ? Math.min(totalLength - 1, editableIndex + chars.length)\n : nextValue.length >= totalLength\n ? totalLength - 1\n : Math.min(totalLength - 1, Math.max(editableIndex + chars.length, nextValue.length));\n\n this.commitValue(nextValue, nextFocus);\n }\n\n public handleSlotPaste(index: number, event: ClipboardEvent): void {\n if (this.disabled() || this.readonly()) {\n return;\n }\n\n const clipboardValue = event.clipboardData?.getData('text') ?? '';\n const chars = sanitizeTngOtpCharacters(clipboardValue, this.type(), this.pattern());\n if (chars.length === 0) {\n event.preventDefault();\n return;\n }\n\n event.preventDefault();\n const editableIndex = this.resolveEditableIndex(index);\n const nextValue = applyTngOtpCharacters(this.normalizedValue(), editableIndex, chars, this.length());\n const nextFocus =\n nextValue.length >= this.length()\n ? this.length() - 1\n : Math.min(this.length() - 1, nextValue.length);\n\n this.commitValue(nextValue, nextFocus);\n }\n\n private normalizedValue(): string {\n const chars = sanitizeTngOtpCharacters(normalizeTngOtpValue(this.value()), this.type(), this.pattern());\n return chars.slice(0, this.length()).join('');\n }\n\n private resolvedActiveIndex(): number {\n const current = this.activeIndex();\n if (typeof current === 'number' && Number.isFinite(current)) {\n return clampOtpIndex(current, this.length());\n }\n\n return resolveTngOtpEntryIndex(this.normalizedValue(), this.length());\n }\n\n private resolveEditableIndex(index: number): number {\n const safeIndex = clampOtpIndex(index, this.length());\n const currentValueLength = this.normalizedValue().length;\n\n if (currentValueLength >= this.length()) {\n return safeIndex;\n }\n\n return Math.min(safeIndex, currentValueLength);\n }\n\n private handleBackspace(index: number): void {\n if (this.disabled() || this.readonly()) {\n return;\n }\n\n const nextState = resolveTngOtpBackspaceResult(this.normalizedValue(), index, this.length());\n if (nextState === null) {\n return;\n }\n\n this.commitValue(nextState.value, nextState.focusIndex);\n }\n\n private handleDelete(index: number): void {\n if (this.disabled() || this.readonly()) {\n return;\n }\n\n if (index >= this.normalizedValue().length) {\n return;\n }\n\n const nextValue = removeTngOtpCharacter(this.normalizedValue(), index);\n this.commitValue(nextValue, index);\n }\n\n private commitValue(nextValue: string, nextFocusIndex: number): void {\n const previousValue = this.normalizedValue();\n const normalized = clampTngOtpValue(\n sanitizeTngOtpCharacters(nextValue, this.type(), this.pattern()).join(''),\n this.length(),\n );\n const didChange = normalized !== previousValue;\n\n this.value.set(normalized);\n this.activeIndex.set(clampOtpIndex(nextFocusIndex, this.length()));\n\n if (didChange && resolveTngOtpState(this.length(), normalized) === 'complete') {\n this.complete.emit(normalized);\n }\n\n queueMicrotask(() => {\n this.syncSlotInputValues();\n this.focusSlot(this.resolvedActiveIndex(), this.selectOnFocus());\n });\n }\n\n private focusSlot(index: number, select: boolean): void {\n const safeIndex = clampOtpIndex(index, this.length());\n const slot = this.hostElement.querySelector(\n `[data-tng-otp-slot='${safeIndex}']`,\n ) as HTMLInputElement | null;\n\n if (!(slot instanceof HTMLInputElement)) {\n return;\n }\n\n slot.focus();\n if (select) {\n slot.select();\n }\n\n this.activeIndex.set(safeIndex);\n }\n\n private syncSlotInputValues(): void {\n const slotInputs = this.hostElement.querySelectorAll('[data-tng-otp-slot]');\n slotInputs.forEach((slotInput: Element) => {\n if (!(slotInput instanceof HTMLInputElement)) {\n return;\n }\n\n const slotIndex = Number(slotInput.getAttribute('data-tng-otp-slot'));\n if (!Number.isFinite(slotIndex)) {\n return;\n }\n\n slotInput.value = this.slotValue(slotIndex);\n });\n }\n}\n\n@Directive({\n selector: 'input[tngInputOtpSlot]',\n exportAs: 'tngInputOtpSlot',\n})\nexport class TngInputOtpSlot {\n private readonly otp = inject(TngInputOtp);\n private readonly elementRef = inject<ElementRef<HTMLInputElement>>(ElementRef);\n\n public readonly index = input<number, number | string>(0, {\n alias: 'tngInputOtpSlot',\n transform: (value: number | string): number =>\n Number.isFinite(typeof value === 'number' ? value : Number(value))\n ? Math.trunc(typeof value === 'number' ? value : Number(value))\n : 0,\n });\n\n @HostBinding('attr.data-slot')\n protected readonly dataSlot = 'input-otp-slot' as const;\n\n @HostBinding('attr.data-tng-otp-slot')\n protected get dataIndexAttr(): string {\n return String(this.index());\n }\n\n @HostBinding('value')\n protected get valueProp(): string {\n return this.otp.slotValue(this.index());\n }\n\n @HostBinding('tabIndex')\n protected get tabIndexProp(): number {\n return this.otp.isSlotTabbable(this.index()) ? 0 : -1;\n }\n\n @HostListener('focus')\n protected onFocus(): void {\n this.otp.handleSlotFocus(this.index(), this.elementRef.nativeElement);\n }\n\n @HostListener('keydown', ['$event'])\n protected onKeydown(event: KeyboardEvent): void {\n this.otp.handleSlotKeydown(this.index(), event);\n }\n\n @HostListener('input')\n protected onInput(): void {\n this.otp.handleSlotInput(this.index(), this.elementRef.nativeElement);\n }\n\n @HostListener('paste', ['$event'])\n protected onPaste(event: ClipboardEvent): void {\n this.otp.handleSlotPaste(this.index(), event);\n }\n}\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as i0 from "@angular/core";
|
|
2
|
-
export declare class TngCombobox {
|
|
3
|
-
protected readonly dataSlot: "combobox";
|
|
4
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<TngCombobox, never>;
|
|
5
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<TngCombobox, "[tngCombobox]", ["tngCombobox"], {}, {}, never, never, true, never>;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=tng-combobox.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tng-combobox.d.ts","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/combobox/tng-combobox.ts"],"names":[],"mappings":";AAEA,qBAIa,WAAW;IAEtB,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAG,UAAU,CAAU;yCAFvC,WAAW;2CAAX,WAAW;CAGvB"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Directive, HostBinding } from '@angular/core';
|
|
2
|
-
import * as i0 from "@angular/core";
|
|
3
|
-
export class TngCombobox {
|
|
4
|
-
dataSlot = 'combobox';
|
|
5
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngCombobox, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
6
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.1", type: TngCombobox, isStandalone: true, selector: "[tngCombobox]", host: { properties: { "attr.data-slot": "this.dataSlot" } }, exportAs: ["tngCombobox"], ngImport: i0 });
|
|
7
|
-
}
|
|
8
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngCombobox, decorators: [{
|
|
9
|
-
type: Directive,
|
|
10
|
-
args: [{
|
|
11
|
-
selector: '[tngCombobox]',
|
|
12
|
-
exportAs: 'tngCombobox',
|
|
13
|
-
}]
|
|
14
|
-
}], propDecorators: { dataSlot: [{
|
|
15
|
-
type: HostBinding,
|
|
16
|
-
args: ['attr.data-slot']
|
|
17
|
-
}] } });
|
|
18
|
-
//# sourceMappingURL=tng-combobox.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tng-combobox.js","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/combobox/tng-combobox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;;AAMvD,MAAM,OAAO,WAAW;IAEH,QAAQ,GAAG,UAAmB,CAAC;uGAFvC,WAAW;2FAAX,WAAW;;2FAAX,WAAW;kBAJvB,SAAS;mBAAC;oBACT,QAAQ,EAAE,eAAe;oBACzB,QAAQ,EAAE,aAAa;iBACxB;;sBAEE,WAAW;uBAAC,gBAAgB","sourcesContent":["import { Directive, HostBinding } from '@angular/core';\n\n@Directive({\n selector: '[tngCombobox]',\n exportAs: 'tngCombobox',\n})\nexport class TngCombobox {\n @HostBinding('attr.data-slot')\n protected readonly dataSlot = 'combobox' as const;\n}\n"]}
|