@tailng-ui/primitives 0.52.0 → 0.53.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/package.json +2 -2
- package/src/lib/form/autocomplete/tng-autocomplete.overlay.d.ts.map +1 -1
- package/src/lib/form/autocomplete/tng-autocomplete.overlay.js +17 -14
- package/src/lib/form/autocomplete/tng-autocomplete.overlay.js.map +1 -1
- package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.d.ts.map +1 -1
- package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.js +8 -2
- package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tailng-ui/primitives",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"@angular/core": "^21.1.0",
|
|
20
|
-
"@tailng-ui/cdk": "^0.
|
|
20
|
+
"@tailng-ui/cdk": "^0.39.0",
|
|
21
21
|
"tslib": "^2.3.0"
|
|
22
22
|
},
|
|
23
23
|
"sideEffects": false
|
|
@@ -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":";AAwIA,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;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,UAAU;IA4BlB,OAAO,CAAC,wBAAwB;IAuBhC,OAAO,CAAC,2BAA2B;IASnC,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,sBAAsB;IAK9B,OAAO,CAAC,sBAAsB;IAqB9B,OAAO,CAAC,sBAAsB;IAM9B,OAAO,CAAC,uBAAuB;IAU/B,OAAO,CAAC,sBAAsB;IAgD9B,OAAO,CAAC,oBAAoB;IAqC5B,OAAO,CAAC,mBAAmB;yCA7QhB,sBAAsB;2CAAtB,sBAAsB;CA+RlC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DestroyRef, Directive, ElementRef, HostBinding, inject, input, effect, } from '@angular/core';
|
|
2
|
-
import { computeOverlayPosition } from '@tailng-ui/cdk';
|
|
2
|
+
import { computeOverlayPosition, resolveAnchoredYWhenOffscreen } from '@tailng-ui/cdk';
|
|
3
3
|
import { TNG_AUTOCOMPLETE } from './tng-autocomplete.tokens';
|
|
4
4
|
import * as i0 from "@angular/core";
|
|
5
5
|
const PORTALLED_AUTOCOMPLETE_THEME_VARS = [
|
|
@@ -69,17 +69,6 @@ function rectFromClientRect(r) {
|
|
|
69
69
|
function viewportRect() {
|
|
70
70
|
return { left: 0, top: 0, width: window.innerWidth || 1024, height: window.innerHeight || 768 };
|
|
71
71
|
}
|
|
72
|
-
function resolveAnchoredYWhenOffscreen(resultY, anchor, overlay, viewport, side, sideOffset) {
|
|
73
|
-
const viewportBottom = viewport.top + viewport.height;
|
|
74
|
-
const anchorBottom = anchor.top + anchor.height;
|
|
75
|
-
if (anchorBottom < viewport.top && side === 'bottom') {
|
|
76
|
-
return anchorBottom + sideOffset;
|
|
77
|
-
}
|
|
78
|
-
if (anchor.top > viewportBottom && side === 'top') {
|
|
79
|
-
return anchor.top - overlay.height - sideOffset;
|
|
80
|
-
}
|
|
81
|
-
return resultY;
|
|
82
|
-
}
|
|
83
72
|
function isInside(target, container) {
|
|
84
73
|
return !!target && target instanceof Node && container.contains(target);
|
|
85
74
|
}
|
|
@@ -202,7 +191,14 @@ export class TngAutocompleteOverlay {
|
|
|
202
191
|
collision: this.collision(),
|
|
203
192
|
});
|
|
204
193
|
panel.style.left = `${result.x}px`;
|
|
205
|
-
panel.style.top = `${resolveAnchoredYWhenOffscreen(
|
|
194
|
+
panel.style.top = `${resolveAnchoredYWhenOffscreen({
|
|
195
|
+
anchorRect: anchor,
|
|
196
|
+
overlayRect: overlay,
|
|
197
|
+
side: result.side,
|
|
198
|
+
sideOffset: offset?.side,
|
|
199
|
+
viewportRect: viewport,
|
|
200
|
+
y: result.y,
|
|
201
|
+
})}px`;
|
|
206
202
|
}
|
|
207
203
|
setupRepositionListeners() {
|
|
208
204
|
let rafId = null;
|
|
@@ -326,7 +322,14 @@ export class TngAutocompleteOverlay {
|
|
|
326
322
|
collision: this.collision(),
|
|
327
323
|
});
|
|
328
324
|
panel.style.left = `${result.x}px`;
|
|
329
|
-
panel.style.top = `${resolveAnchoredYWhenOffscreen(
|
|
325
|
+
panel.style.top = `${resolveAnchoredYWhenOffscreen({
|
|
326
|
+
anchorRect: anchor,
|
|
327
|
+
overlayRect: overlay,
|
|
328
|
+
side: result.side,
|
|
329
|
+
sideOffset: offset?.side,
|
|
330
|
+
viewportRect: viewport,
|
|
331
|
+
y: result.y,
|
|
332
|
+
})}px`;
|
|
330
333
|
});
|
|
331
334
|
this.setupOutsidePointer();
|
|
332
335
|
}
|
|
@@ -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,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,8BAA8B;IAC9B,oCAAoC;IACpC,iBAAiB;IACjB,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,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AAC,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;uGA9RU,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\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-z-overlay',\n '--tng-autocomplete-overlay-z-index',\n '--tng-z-overlay',\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 resolveAnchoredYWhenOffscreen(\n resultY: number,\n anchor: MaybeRect,\n overlay: MaybeRect,\n viewport: MaybeRect,\n side: 'bottom' | 'top' | 'left' | 'right',\n sideOffset: number,\n): number {\n const viewportBottom = viewport.top + viewport.height;\n const anchorBottom = anchor.top + anchor.height;\n\n if (anchorBottom < viewport.top && side === 'bottom') {\n return anchorBottom + sideOffset;\n }\n\n if (anchor.top > viewportBottom && side === 'top') {\n return anchor.top - overlay.height - sideOffset;\n }\n\n return resultY;\n}\n\nfunction isInside(target: EventTarget | null, container: HTMLElement): boolean {\n return !!target && target instanceof Node && container.contains(target);\n}\n\n/**\n * When the overlay's host element lives inside a `tng-form-field`, the form-field\n * is the visible frame the consumer sees, so the overlay should align with it\n * (width + left/right edges). For the `left` label layout the form-field's root\n * spans the label column too, so anchor on the inner control-row instead.\n */\nfunction findFormFieldAnchor(host: HTMLElement): HTMLElement | null {\n const formField = host.closest('[data-slot=\"form-field\"]') as HTMLElement | null;\n if (!formField) return null;\n if (formField.getAttribute('data-label-position') === 'left') {\n const row = formField.querySelector('.tng-form-field__control-row') as HTMLElement | null;\n return row ?? formField;\n }\n return formField;\n}\n\n/**\n * Rect to use for overlay positioning. When the anchor is a form-field root, the\n * horizontal extent is taken from the form-field (so the overlay spans the field\n * frame) but the vertical extent is taken from the inner fieldset (the input row)\n * so the overlay opens directly under the input rather than below the messages\n * region beneath the frame.\n */\nfunction anchorRectFor(anchorEl: HTMLElement): MaybeRect {\n const widthRect = anchorEl.getBoundingClientRect();\n if (!anchorEl.matches('[data-slot=\"form-field\"]')) {\n return rectFromClientRect(widthRect);\n }\n const labelPosition = anchorEl.getAttribute('data-label-position');\n const fieldset = anchorEl.querySelector('[data-slot=\"form-field-control-row\"]') as HTMLElement | null;\n const innerRow = anchorEl.querySelector('.tng-form-field__control-row') as HTMLElement | null;\n const positionEl = labelPosition === 'outline' ? (fieldset ?? innerRow) : (innerRow ?? fieldset);\n if (!positionEl) return rectFromClientRect(widthRect);\n const positionRect = positionEl.getBoundingClientRect();\n return {\n left: widthRect.left,\n width: widthRect.width,\n top: positionRect.top,\n height: positionRect.height,\n };\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 /**\n * Anchor for overlay positioning, width, and dismiss boundary.\n * Prefer the enclosing form-field (so the overlay aligns with the visible\n * field frame), else the trigger container (trigger + icon), else the input\n * trigger itself.\n */\n private findAnchorEl(): HTMLElement | null {\n const root = this.autocomplete.hostElement;\n const formFieldAnchor = findFormFieldAnchor(root);\n if (formFieldAnchor) return formFieldAnchor;\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 = anchorRectFor(anchorEl);\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const offset = this.offset();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n placement: this.placement(),\n offset,\n collision: this.collision(),\n });\n panel.style.left = `${result.x}px`;\n panel.style.top = `${resolveAnchoredYWhenOffscreen(\n result.y,\n anchor,\n overlay,\n viewport,\n result.side,\n offset?.side ?? 0,\n )}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 applyPortalledStacking(): void {\n const panel = this.elRef.nativeElement;\n\n panel.style.zIndex = 'var(--tng-autocomplete-z-overlay, var(--tng-autocomplete-overlay-z-index, var(--tng-z-overlay, 2)))';\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 this.syncPortalledThemeVars();\n this.applyPortalledStacking();\n\n queueMicrotask(() => {\n if (!this.autocomplete.open()) return;\n const anchorEl = this.findAnchorEl();\n if (!anchorEl) return;\n const anchor = anchorRectFor(anchorEl);\n panel.style.minWidth = `${anchor.width}px`;\n if (findFormFieldAnchor(this.autocomplete.hostElement)) {\n panel.style.width = `${anchor.width}px`;\n panel.style.maxWidth = 'none';\n }\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const offset = this.offset();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n placement: this.placement(),\n offset,\n collision: this.collision(),\n });\n panel.style.left = `${result.x}px`;\n panel.style.top = `${resolveAnchoredYWhenOffscreen(\n result.y,\n anchor,\n overlay,\n viewport,\n result.side,\n offset?.side ?? 0,\n )}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 panel.style.width = '';\n panel.style.maxWidth = '';\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"]}
|
|
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,E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AG,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;uGA9RU,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, resolveAnchoredYWhenOffscreen } 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-z-overlay',\n '--tng-autocomplete-overlay-z-index',\n '--tng-z-overlay',\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/**\n * When the overlay's host element lives inside a `tng-form-field`, the form-field\n * is the visible frame the consumer sees, so the overlay should align with it\n * (width + left/right edges). For the `left` label layout the form-field's root\n * spans the label column too, so anchor on the inner control-row instead.\n */\nfunction findFormFieldAnchor(host: HTMLElement): HTMLElement | null {\n const formField = host.closest('[data-slot=\"form-field\"]') as HTMLElement | null;\n if (!formField) return null;\n if (formField.getAttribute('data-label-position') === 'left') {\n const row = formField.querySelector('.tng-form-field__control-row') as HTMLElement | null;\n return row ?? formField;\n }\n return formField;\n}\n\n/**\n * Rect to use for overlay positioning. When the anchor is a form-field root, the\n * horizontal extent is taken from the form-field (so the overlay spans the field\n * frame) but the vertical extent is taken from the inner fieldset (the input row)\n * so the overlay opens directly under the input rather than below the messages\n * region beneath the frame.\n */\nfunction anchorRectFor(anchorEl: HTMLElement): MaybeRect {\n const widthRect = anchorEl.getBoundingClientRect();\n if (!anchorEl.matches('[data-slot=\"form-field\"]')) {\n return rectFromClientRect(widthRect);\n }\n const labelPosition = anchorEl.getAttribute('data-label-position');\n const fieldset = anchorEl.querySelector('[data-slot=\"form-field-control-row\"]') as HTMLElement | null;\n const innerRow = anchorEl.querySelector('.tng-form-field__control-row') as HTMLElement | null;\n const positionEl = labelPosition === 'outline' ? (fieldset ?? innerRow) : (innerRow ?? fieldset);\n if (!positionEl) return rectFromClientRect(widthRect);\n const positionRect = positionEl.getBoundingClientRect();\n return {\n left: widthRect.left,\n width: widthRect.width,\n top: positionRect.top,\n height: positionRect.height,\n };\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 /**\n * Anchor for overlay positioning, width, and dismiss boundary.\n * Prefer the enclosing form-field (so the overlay aligns with the visible\n * field frame), else the trigger container (trigger + icon), else the input\n * trigger itself.\n */\n private findAnchorEl(): HTMLElement | null {\n const root = this.autocomplete.hostElement;\n const formFieldAnchor = findFormFieldAnchor(root);\n if (formFieldAnchor) return formFieldAnchor;\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 = anchorRectFor(anchorEl);\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const offset = this.offset();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n placement: this.placement(),\n offset,\n collision: this.collision(),\n });\n panel.style.left = `${result.x}px`;\n panel.style.top = `${resolveAnchoredYWhenOffscreen({\n anchorRect: anchor,\n overlayRect: overlay,\n side: result.side,\n sideOffset: offset?.side,\n viewportRect: viewport,\n y: result.y,\n })}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 applyPortalledStacking(): void {\n const panel = this.elRef.nativeElement;\n\n panel.style.zIndex = 'var(--tng-autocomplete-z-overlay, var(--tng-autocomplete-overlay-z-index, var(--tng-z-overlay, 2)))';\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 this.syncPortalledThemeVars();\n this.applyPortalledStacking();\n\n queueMicrotask(() => {\n if (!this.autocomplete.open()) return;\n const anchorEl = this.findAnchorEl();\n if (!anchorEl) return;\n const anchor = anchorRectFor(anchorEl);\n panel.style.minWidth = `${anchor.width}px`;\n if (findFormFieldAnchor(this.autocomplete.hostElement)) {\n panel.style.width = `${anchor.width}px`;\n panel.style.maxWidth = 'none';\n }\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const offset = this.offset();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n placement: this.placement(),\n offset,\n collision: this.collision(),\n });\n panel.style.left = `${result.x}px`;\n panel.style.top = `${resolveAnchoredYWhenOffscreen({\n anchorRect: anchor,\n overlayRect: overlay,\n side: result.side,\n sideOffset: offset?.side,\n viewportRect: viewport,\n y: result.y,\n })}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 panel.style.width = '';\n panel.style.maxWidth = '';\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tng-multi-autocomplete.overlay.d.ts","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.ts"],"names":[],"mappings":";AAmGA,qBAIa,2BAA2B;IACtC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAwD;IAC9E,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmC;IACzD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IAEjD,OAAO,CAAC,oBAAoB,CAA6B;IACzD,OAAO,CAAC,oBAAoB,CAA6B;IACzD,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,wBAAwB,CAA6B;IAC7D,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAqB;IAG3C,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAG,4BAA4B,CAAU;IAGpE,SAAS,KAAK,MAAM,IAAI,EAAE,GAAG,IAAI,CAEhC;;IA2BD;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,UAAU;
|
|
1
|
+
{"version":3,"file":"tng-multi-autocomplete.overlay.d.ts","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.ts"],"names":[],"mappings":";AAmGA,qBAIa,2BAA2B;IACtC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAwD;IAC9E,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmC;IACzD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IAEjD,OAAO,CAAC,oBAAoB,CAA6B;IACzD,OAAO,CAAC,oBAAoB,CAA6B;IACzD,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,wBAAwB,CAA6B;IAC7D,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAqB;IAG3C,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAG,4BAA4B,CAAU;IAGpE,SAAS,KAAK,MAAM,IAAI,EAAE,GAAG,IAAI,CAEhC;;IA2BD;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,UAAU;IAwBlB,OAAO,CAAC,wBAAwB;IA2BhC,OAAO,CAAC,2BAA2B;IASnC,OAAO,CAAC,mBAAmB;IAqB3B,OAAO,CAAC,sBAAsB;IAK9B,OAAO,CAAC,sBAAsB;IAqB9B,OAAO,CAAC,sBAAsB;IAK9B,OAAO,CAAC,uBAAuB;IAU/B,OAAO,CAAC,sBAAsB;IA4B9B,OAAO,CAAC,oBAAoB;yCA5MjB,2BAA2B;2CAA3B,2BAA2B;CAmOvC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DestroyRef, Directive, ElementRef, HostBinding, effect, inject, } from '@angular/core';
|
|
2
|
-
import { computeOverlayPosition } from '@tailng-ui/cdk';
|
|
2
|
+
import { computeOverlayPosition, resolveAnchoredYWhenOffscreen } from '@tailng-ui/cdk';
|
|
3
3
|
import { TNG_MULTI_AUTOCOMPLETE } from './tng-multi-autocomplete.tokens';
|
|
4
4
|
import * as i0 from "@angular/core";
|
|
5
5
|
const PORTALLED_MULTI_AUTOCOMPLETE_THEME_VARS = [
|
|
@@ -142,7 +142,13 @@ export class TngMultiAutocompleteOverlay {
|
|
|
142
142
|
viewportRect: viewport,
|
|
143
143
|
});
|
|
144
144
|
panel.style.left = `${result.x}px`;
|
|
145
|
-
panel.style.top = `${
|
|
145
|
+
panel.style.top = `${resolveAnchoredYWhenOffscreen({
|
|
146
|
+
anchorRect: anchor,
|
|
147
|
+
overlayRect: overlay,
|
|
148
|
+
side: result.side,
|
|
149
|
+
viewportRect: viewport,
|
|
150
|
+
y: result.y,
|
|
151
|
+
})}px`;
|
|
146
152
|
}
|
|
147
153
|
setupRepositionListeners() {
|
|
148
154
|
let rafId = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tng-multi-autocomplete.overlay.js","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/multi-autocomplete/tng-multi-aut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CAAC;YAC/B,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;QAED,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC;QAC1B,KAAK,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC;QACtB,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC;QACrB,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC;QACxB,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC;QACvB,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC/B,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAChC,CAAC;uGA5NU,2BAA2B;2FAA3B,2BAA2B;;2FAA3B,2BAA2B;kBAJvC,SAAS;mBAAC;oBACT,QAAQ,EAAE,+BAA+B;oBACzC,QAAQ,EAAE,6BAA6B;iBACxC;;sBAaE,WAAW;uBAAC,gBAAgB;;sBAG5B,WAAW;uBAAC,aAAa","sourcesContent":["import {\n DestroyRef,\n Directive,\n ElementRef,\n HostBinding,\n effect,\n inject,\n} from '@angular/core';\nimport { computeOverlayPosition } from '@tailng-ui/cdk';\nimport { TNG_MULTI_AUTOCOMPLETE } from './tng-multi-autocomplete.tokens';\nimport type { TngMultiAutocomplete } from './tng-multi-autocomplete';\n\ntype MaybeRect = Readonly<{ left: number; top: number; width: number; height: number }>;\n\nconst PORTALLED_MULTI_AUTOCOMPLETE_THEME_VARS = [\n '--tng-multi-autocomplete-radius',\n '--tng-multi-autocomplete-padding',\n '--tng-multi-autocomplete-trigger-py',\n '--tng-multi-autocomplete-trigger-px',\n '--tng-multi-autocomplete-chip-py',\n '--tng-multi-autocomplete-chip-px',\n '--tng-multi-autocomplete-option-py',\n '--tng-multi-autocomplete-option-px',\n '--tng-multi-autocomplete-z-overlay',\n '--tng-multi-autocomplete-overlay-z-index',\n '--tng-z-overlay',\n '--tng-multi-autocomplete-border',\n '--tng-multi-autocomplete-border-strong',\n '--tng-multi-autocomplete-bg',\n '--tng-multi-autocomplete-surface',\n '--tng-multi-autocomplete-fg',\n '--tng-multi-autocomplete-muted',\n '--tng-multi-autocomplete-brand',\n '--tng-multi-autocomplete-danger',\n '--tng-multi-autocomplete-focus-ring',\n '--tng-multi-autocomplete-ease',\n '--tng-multi-autocomplete-shadow',\n '--tng-multi-autocomplete-shadow-focus',\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 {\n left: 0,\n top: 0,\n width: window.innerWidth || 1024,\n height: window.innerHeight || 768,\n };\n}\n\nfunction isInside(target: EventTarget | null, container: HTMLElement): boolean {\n return !!target && target instanceof Node && container.contains(target);\n}\n\n/**\n * When the overlay's host element lives inside a `tng-form-field`, the form-field\n * is the visible frame the consumer sees, so the overlay should align with it\n * (width + left/right edges). For the `left` label layout the form-field's root\n * spans the label column too, so anchor on the inner control-row instead.\n */\nfunction findFormFieldAnchor(host: HTMLElement): HTMLElement | null {\n const formField = host.closest('[data-slot=\"form-field\"]') as HTMLElement | null;\n if (!formField) return null;\n if (formField.getAttribute('data-label-position') === 'left') {\n const row = formField.querySelector('.tng-form-field__control-row') as HTMLElement | null;\n return row ?? formField;\n }\n return formField;\n}\n\n/**\n * Rect to use for overlay positioning. When the anchor is a form-field root, the\n * horizontal extent is taken from the form-field (so the overlay spans the field\n * frame) but the vertical extent is taken from the inner fieldset (the input row)\n * so the overlay opens directly under the input rather than below the messages\n * region beneath the frame.\n */\nfunction anchorRectFor(anchorEl: HTMLElement): MaybeRect {\n const widthRect = anchorEl.getBoundingClientRect();\n if (!anchorEl.matches('[data-slot=\"form-field\"]')) {\n return rectFromClientRect(widthRect);\n }\n const labelPosition = anchorEl.getAttribute('data-label-position');\n const fieldset = anchorEl.querySelector('[data-slot=\"form-field-control-row\"]') as HTMLElement | null;\n const innerRow = anchorEl.querySelector('.tng-form-field__control-row') as HTMLElement | null;\n const positionEl = labelPosition === 'outline' ? (fieldset ?? innerRow) : (innerRow ?? fieldset);\n if (!positionEl) return rectFromClientRect(widthRect);\n const positionRect = positionEl.getBoundingClientRect();\n return {\n left: widthRect.left,\n width: widthRect.width,\n top: positionRect.top,\n height: positionRect.height,\n };\n}\n\n@Directive({\n selector: '[tngMultiAutocompleteOverlay]',\n exportAs: 'tngMultiAutocompleteOverlay',\n})\nexport class TngMultiAutocompleteOverlay {\n private readonly multi = inject<TngMultiAutocomplete>(TNG_MULTI_AUTOCOMPLETE);\n private readonly elRef = inject(ElementRef<HTMLElement>);\n private readonly destroyRef = inject(DestroyRef);\n\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 private placeholder: Comment | null = null;\n private originalParent: Node | null = null;\n\n @HostBinding('attr.data-slot')\n protected readonly dataSlot = 'multi-autocomplete-overlay' as const;\n\n @HostBinding('attr.hidden')\n protected get hidden(): '' | null {\n return this.multi.open() ? null : '';\n }\n\n constructor() {\n const hostEl = this.elRef.nativeElement;\n this.placeholder = document.createComment('tng-multi-autocomplete-overlay-anchor');\n this.originalParent = hostEl.parentNode;\n this.originalParent?.insertBefore(this.placeholder, hostEl);\n this.multi.setOverlayElement(hostEl);\n\n effect(() => {\n const open = this.multi.open();\n if (open) {\n this.mountToBodyAndPosition();\n } else {\n this.restoreToPlaceholder();\n }\n });\n\n this.destroyRef.onDestroy(() => {\n this.teardownOutsidePointer();\n this.restoreToPlaceholder(true);\n this.multi.setOverlayElement(null);\n this.placeholder = null;\n this.originalParent = null;\n });\n }\n\n /**\n * Anchor for overlay positioning, width, and dismiss boundary.\n * Prefer the enclosing form-field (so the overlay aligns with the visible\n * field frame), else the multi-autocomplete host element itself.\n */\n private findAnchorEl(): HTMLElement {\n return findFormFieldAnchor(this.multi.hostElement) ?? this.multi.hostElement;\n }\n\n private reposition(): void {\n if (!this.multi.open()) return;\n\n const panel = this.elRef.nativeElement;\n const anchorEl = this.findAnchorEl();\n const anchor = anchorRectFor(anchorEl);\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\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\n const schedule = () => {\n if (rafId !== null) return;\n\n rafId = requestAnimationFrame(() => {\n rafId = null;\n this.reposition();\n });\n };\n\n const onResize = () => schedule();\n const onScroll = () => schedule();\n\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 this.resizeObserver.observe(this.findAnchorEl());\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\n const onPointerDown = (event: PointerEvent) => {\n if (!this.multi.open()) return;\n\n const panel = this.elRef.nativeElement;\n if (isInside(event.target, panel)) return;\n if (isInside(event.target, this.findAnchorEl())) return;\n if (event.target && (event.target as Element).closest?.('[data-slot=\"multi-autocomplete-option\"]')) {\n return;\n }\n\n this.multi.close();\n };\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.multi.hostElement);\n\n for (const cssVar of PORTALLED_MULTI_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 applyPortalledStacking(): void {\n this.elRef.nativeElement.style.zIndex =\n 'var(--tng-multi-autocomplete-z-overlay, var(--tng-multi-autocomplete-overlay-z-index, var(--tng-z-overlay, 2)))';\n }\n\n private clearPortalledThemeVars(): void {\n const panel = this.elRef.nativeElement;\n\n for (const cssVar of PORTALLED_MULTI_AUTOCOMPLETE_THEME_VARS) {\n panel.style.removeProperty(cssVar);\n }\n\n panel.style.removeProperty('color-scheme');\n }\n\n private mountToBodyAndPosition(): void {\n this.setupRepositionListeners();\n\n const panel = this.elRef.nativeElement;\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 this.syncPortalledThemeVars();\n this.applyPortalledStacking();\n\n queueMicrotask(() => {\n if (!this.multi.open()) return;\n\n const anchor = anchorRectFor(this.findAnchorEl());\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 this.reposition();\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 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"]}
|
|
1
|
+
{"version":3,"file":"tng-multi-autocomplete.overlay.js","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACX,MAAM,EACN,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AACvF,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;;AAKzE,MAAM,uCAAuC,GAAG;IAC9C,iCAAiC;IACjC,kCAAkC;IAClC,qCAAqC;IACrC,qCAAqC;IACrC,kCAAkC;IAClC,kCAAkC;IAClC,oCAAoC;IACpC,oCAAoC;IACpC,oCAAoC;IACpC,0CAA0C;IAC1C,iBAAiB;IACjB,iCAAiC;IACjC,wCAAwC;IACxC,6BAA6B;IAC7B,kCAAkC;IAClC,6BAA6B;IAC7B,gCAAgC;IAChC,gCAAgC;IAChC,iCAAiC;IACjC,qCAAqC;IACrC,+BAA+B;IAC/B,iCAAiC;IACjC,uCAAuC;CAC/B,CAAC;AAEX,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;QACL,IAAI,EAAE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BAAC,aAAa","sourcesContent":["import {\n DestroyRef,\n Directive,\n ElementRef,\n HostBinding,\n effect,\n inject,\n} from '@angular/core';\nimport { computeOverlayPosition, resolveAnchoredYWhenOffscreen } from '@tailng-ui/cdk';\nimport { TNG_MULTI_AUTOCOMPLETE } from './tng-multi-autocomplete.tokens';\nimport type { TngMultiAutocomplete } from './tng-multi-autocomplete';\n\ntype MaybeRect = Readonly<{ left: number; top: number; width: number; height: number }>;\n\nconst PORTALLED_MULTI_AUTOCOMPLETE_THEME_VARS = [\n '--tng-multi-autocomplete-radius',\n '--tng-multi-autocomplete-padding',\n '--tng-multi-autocomplete-trigger-py',\n '--tng-multi-autocomplete-trigger-px',\n '--tng-multi-autocomplete-chip-py',\n '--tng-multi-autocomplete-chip-px',\n '--tng-multi-autocomplete-option-py',\n '--tng-multi-autocomplete-option-px',\n '--tng-multi-autocomplete-z-overlay',\n '--tng-multi-autocomplete-overlay-z-index',\n '--tng-z-overlay',\n '--tng-multi-autocomplete-border',\n '--tng-multi-autocomplete-border-strong',\n '--tng-multi-autocomplete-bg',\n '--tng-multi-autocomplete-surface',\n '--tng-multi-autocomplete-fg',\n '--tng-multi-autocomplete-muted',\n '--tng-multi-autocomplete-brand',\n '--tng-multi-autocomplete-danger',\n '--tng-multi-autocomplete-focus-ring',\n '--tng-multi-autocomplete-ease',\n '--tng-multi-autocomplete-shadow',\n '--tng-multi-autocomplete-shadow-focus',\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 {\n left: 0,\n top: 0,\n width: window.innerWidth || 1024,\n height: window.innerHeight || 768,\n };\n}\n\nfunction isInside(target: EventTarget | null, container: HTMLElement): boolean {\n return !!target && target instanceof Node && container.contains(target);\n}\n\n/**\n * When the overlay's host element lives inside a `tng-form-field`, the form-field\n * is the visible frame the consumer sees, so the overlay should align with it\n * (width + left/right edges). For the `left` label layout the form-field's root\n * spans the label column too, so anchor on the inner control-row instead.\n */\nfunction findFormFieldAnchor(host: HTMLElement): HTMLElement | null {\n const formField = host.closest('[data-slot=\"form-field\"]') as HTMLElement | null;\n if (!formField) return null;\n if (formField.getAttribute('data-label-position') === 'left') {\n const row = formField.querySelector('.tng-form-field__control-row') as HTMLElement | null;\n return row ?? formField;\n }\n return formField;\n}\n\n/**\n * Rect to use for overlay positioning. When the anchor is a form-field root, the\n * horizontal extent is taken from the form-field (so the overlay spans the field\n * frame) but the vertical extent is taken from the inner fieldset (the input row)\n * so the overlay opens directly under the input rather than below the messages\n * region beneath the frame.\n */\nfunction anchorRectFor(anchorEl: HTMLElement): MaybeRect {\n const widthRect = anchorEl.getBoundingClientRect();\n if (!anchorEl.matches('[data-slot=\"form-field\"]')) {\n return rectFromClientRect(widthRect);\n }\n const labelPosition = anchorEl.getAttribute('data-label-position');\n const fieldset = anchorEl.querySelector('[data-slot=\"form-field-control-row\"]') as HTMLElement | null;\n const innerRow = anchorEl.querySelector('.tng-form-field__control-row') as HTMLElement | null;\n const positionEl = labelPosition === 'outline' ? (fieldset ?? innerRow) : (innerRow ?? fieldset);\n if (!positionEl) return rectFromClientRect(widthRect);\n const positionRect = positionEl.getBoundingClientRect();\n return {\n left: widthRect.left,\n width: widthRect.width,\n top: positionRect.top,\n height: positionRect.height,\n };\n}\n\n@Directive({\n selector: '[tngMultiAutocompleteOverlay]',\n exportAs: 'tngMultiAutocompleteOverlay',\n})\nexport class TngMultiAutocompleteOverlay {\n private readonly multi = inject<TngMultiAutocomplete>(TNG_MULTI_AUTOCOMPLETE);\n private readonly elRef = inject(ElementRef<HTMLElement>);\n private readonly destroyRef = inject(DestroyRef);\n\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 private placeholder: Comment | null = null;\n private originalParent: Node | null = null;\n\n @HostBinding('attr.data-slot')\n protected readonly dataSlot = 'multi-autocomplete-overlay' as const;\n\n @HostBinding('attr.hidden')\n protected get hidden(): '' | null {\n return this.multi.open() ? null : '';\n }\n\n constructor() {\n const hostEl = this.elRef.nativeElement;\n this.placeholder = document.createComment('tng-multi-autocomplete-overlay-anchor');\n this.originalParent = hostEl.parentNode;\n this.originalParent?.insertBefore(this.placeholder, hostEl);\n this.multi.setOverlayElement(hostEl);\n\n effect(() => {\n const open = this.multi.open();\n if (open) {\n this.mountToBodyAndPosition();\n } else {\n this.restoreToPlaceholder();\n }\n });\n\n this.destroyRef.onDestroy(() => {\n this.teardownOutsidePointer();\n this.restoreToPlaceholder(true);\n this.multi.setOverlayElement(null);\n this.placeholder = null;\n this.originalParent = null;\n });\n }\n\n /**\n * Anchor for overlay positioning, width, and dismiss boundary.\n * Prefer the enclosing form-field (so the overlay aligns with the visible\n * field frame), else the multi-autocomplete host element itself.\n */\n private findAnchorEl(): HTMLElement {\n return findFormFieldAnchor(this.multi.hostElement) ?? this.multi.hostElement;\n }\n\n private reposition(): void {\n if (!this.multi.open()) return;\n\n const panel = this.elRef.nativeElement;\n const anchorEl = this.findAnchorEl();\n const anchor = anchorRectFor(anchorEl);\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n });\n\n panel.style.left = `${result.x}px`;\n panel.style.top = `${resolveAnchoredYWhenOffscreen({\n anchorRect: anchor,\n overlayRect: overlay,\n side: result.side,\n viewportRect: viewport,\n y: result.y,\n })}px`;\n }\n\n private setupRepositionListeners(): void {\n let rafId: number | null = null;\n\n const schedule = () => {\n if (rafId !== null) return;\n\n rafId = requestAnimationFrame(() => {\n rafId = null;\n this.reposition();\n });\n };\n\n const onResize = () => schedule();\n const onScroll = () => schedule();\n\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 this.resizeObserver.observe(this.findAnchorEl());\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\n const onPointerDown = (event: PointerEvent) => {\n if (!this.multi.open()) return;\n\n const panel = this.elRef.nativeElement;\n if (isInside(event.target, panel)) return;\n if (isInside(event.target, this.findAnchorEl())) return;\n if (event.target && (event.target as Element).closest?.('[data-slot=\"multi-autocomplete-option\"]')) {\n return;\n }\n\n this.multi.close();\n };\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.multi.hostElement);\n\n for (const cssVar of PORTALLED_MULTI_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 applyPortalledStacking(): void {\n this.elRef.nativeElement.style.zIndex =\n 'var(--tng-multi-autocomplete-z-overlay, var(--tng-multi-autocomplete-overlay-z-index, var(--tng-z-overlay, 2)))';\n }\n\n private clearPortalledThemeVars(): void {\n const panel = this.elRef.nativeElement;\n\n for (const cssVar of PORTALLED_MULTI_AUTOCOMPLETE_THEME_VARS) {\n panel.style.removeProperty(cssVar);\n }\n\n panel.style.removeProperty('color-scheme');\n }\n\n private mountToBodyAndPosition(): void {\n this.setupRepositionListeners();\n\n const panel = this.elRef.nativeElement;\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 this.syncPortalledThemeVars();\n this.applyPortalledStacking();\n\n queueMicrotask(() => {\n if (!this.multi.open()) return;\n\n const anchor = anchorRectFor(this.findAnchorEl());\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 this.reposition();\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 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"]}
|