@tailng-ui/primitives 0.1.0 → 0.12.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 +97 -11
- package/package.json +9 -3
- package/src/index.d.ts +5 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +5 -0
- package/src/index.js.map +1 -1
- package/src/lib/feedback/empty/tng-empty.d.ts.map +1 -1
- package/src/lib/feedback/empty/tng-empty.js +5 -0
- package/src/lib/feedback/empty/tng-empty.js.map +1 -1
- package/src/lib/feedback/progress-bar/tng-progress-bar.d.ts.map +1 -1
- package/src/lib/feedback/progress-bar/tng-progress-bar.js +4 -1
- package/src/lib/feedback/progress-bar/tng-progress-bar.js.map +1 -1
- package/src/lib/feedback/progress-spinner/tng-progress-spinner.d.ts.map +1 -1
- package/src/lib/feedback/progress-spinner/tng-progress-spinner.js +3 -1
- package/src/lib/feedback/progress-spinner/tng-progress-spinner.js.map +1 -1
- package/src/lib/feedback/skeleton/tng-skeleton.d.ts +1 -0
- package/src/lib/feedback/skeleton/tng-skeleton.d.ts.map +1 -1
- package/src/lib/feedback/skeleton/tng-skeleton.js +5 -0
- package/src/lib/feedback/skeleton/tng-skeleton.js.map +1 -1
- package/src/lib/feedback/toast/tng-toast.d.ts.map +1 -1
- package/src/lib/feedback/toast/tng-toast.js +2 -0
- package/src/lib/feedback/toast/tng-toast.js.map +1 -1
- package/src/lib/form/checkbox/tng-checkbox.d.ts.map +1 -1
- package/src/lib/form/checkbox/tng-checkbox.js +1 -0
- package/src/lib/form/checkbox/tng-checkbox.js.map +1 -1
- package/src/lib/form/chips/tng-chips.d.ts +53 -1
- package/src/lib/form/chips/tng-chips.d.ts.map +1 -1
- package/src/lib/form/chips/tng-chips.js +284 -1
- package/src/lib/form/chips/tng-chips.js.map +1 -1
- package/src/lib/form/combobox/tng-combobox.d.ts.map +1 -1
- package/src/lib/form/combobox/tng-combobox.js +1 -0
- package/src/lib/form/combobox/tng-combobox.js.map +1 -1
- package/src/lib/form/input-otp/tng-input-otp.d.ts +22 -0
- package/src/lib/form/input-otp/tng-input-otp.d.ts.map +1 -1
- package/src/lib/form/input-otp/tng-input-otp.js +106 -1
- package/src/lib/form/input-otp/tng-input-otp.js.map +1 -1
- package/src/lib/form/label/tng-label.d.ts +2 -0
- package/src/lib/form/label/tng-label.d.ts.map +1 -1
- package/src/lib/form/label/tng-label.js +10 -0
- package/src/lib/form/label/tng-label.js.map +1 -1
- package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.trigger.d.ts +1 -0
- package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.trigger.d.ts.map +1 -1
- package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.trigger.js +26 -0
- package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.trigger.js.map +1 -1
- package/src/lib/form/multiselect/tng-multiselect.d.ts.map +1 -1
- package/src/lib/form/multiselect/tng-multiselect.js +1 -0
- package/src/lib/form/multiselect/tng-multiselect.js.map +1 -1
- package/src/lib/form/radio/tng-radio.d.ts +26 -0
- package/src/lib/form/radio/tng-radio.d.ts.map +1 -1
- package/src/lib/form/radio/tng-radio.js +130 -1
- package/src/lib/form/radio/tng-radio.js.map +1 -1
- package/src/lib/form/slider/tng-slider.d.ts.map +1 -1
- package/src/lib/form/slider/tng-slider.js +1 -0
- package/src/lib/form/slider/tng-slider.js.map +1 -1
- package/src/lib/form/switch/tng-switch.d.ts.map +1 -1
- package/src/lib/form/switch/tng-switch.js +1 -0
- package/src/lib/form/switch/tng-switch.js.map +1 -1
- package/src/lib/form/textarea/tng-textarea.d.ts +6 -14
- package/src/lib/form/textarea/tng-textarea.d.ts.map +1 -1
- package/src/lib/form/textarea/tng-textarea.js +42 -85
- package/src/lib/form/textarea/tng-textarea.js.map +1 -1
- package/src/lib/form/toggle/tng-toggle.d.ts.map +1 -1
- package/src/lib/form/toggle/tng-toggle.js +1 -0
- package/src/lib/form/toggle/tng-toggle.js.map +1 -1
- package/src/lib/form/toggle-group/tng-toggle-group.d.ts.map +1 -1
- package/src/lib/form/toggle-group/tng-toggle-group.js +1 -0
- package/src/lib/form/toggle-group/tng-toggle-group.js.map +1 -1
- package/src/lib/layout/accordion/tng-accordion.d.ts +9 -0
- package/src/lib/layout/accordion/tng-accordion.d.ts.map +1 -1
- package/src/lib/layout/accordion/tng-accordion.js +113 -0
- package/src/lib/layout/accordion/tng-accordion.js.map +1 -1
- package/src/lib/layout/bottom-sheet/tng-bottom-sheet.d.ts.map +1 -1
- package/src/lib/layout/bottom-sheet/tng-bottom-sheet.js +1 -0
- package/src/lib/layout/bottom-sheet/tng-bottom-sheet.js.map +1 -1
- package/src/lib/layout/card/tng-card.d.ts.map +1 -1
- package/src/lib/layout/card/tng-card.js +10 -0
- package/src/lib/layout/card/tng-card.js.map +1 -1
- package/src/lib/layout/collapsible/tng-collapsible.d.ts.map +1 -1
- package/src/lib/layout/collapsible/tng-collapsible.js +3 -0
- package/src/lib/layout/collapsible/tng-collapsible.js.map +1 -1
- package/src/lib/layout/grid/tng-grid.d.ts.map +1 -1
- package/src/lib/layout/grid/tng-grid.js +1 -0
- package/src/lib/layout/grid/tng-grid.js.map +1 -1
- package/src/lib/layout/separator/tng-separator.d.ts.map +1 -1
- package/src/lib/layout/separator/tng-separator.js +1 -0
- package/src/lib/layout/separator/tng-separator.js.map +1 -1
- package/src/lib/layout/stepper/tng-stepper.d.ts.map +1 -1
- package/src/lib/layout/stepper/tng-stepper.js +1 -0
- package/src/lib/layout/stepper/tng-stepper.js.map +1 -1
- package/src/lib/layout/tree/__tests__/tng-tree.test-harness.d.ts +20 -0
- package/src/lib/layout/tree/__tests__/tng-tree.test-harness.d.ts.map +1 -0
- package/src/lib/layout/tree/__tests__/tng-tree.test-harness.js +106 -0
- package/src/lib/layout/tree/__tests__/tng-tree.test-harness.js.map +1 -0
- package/src/lib/layout/tree/index.d.ts +5 -0
- package/src/lib/layout/tree/index.d.ts.map +1 -0
- package/src/lib/layout/tree/index.js +5 -0
- package/src/lib/layout/tree/index.js.map +1 -0
- package/src/lib/layout/tree/tng-tree-group.d.ts +10 -0
- package/src/lib/layout/tree/tng-tree-group.d.ts.map +1 -0
- package/src/lib/layout/tree/tng-tree-group.js +29 -0
- package/src/lib/layout/tree/tng-tree-group.js.map +1 -0
- package/src/lib/layout/tree/tng-tree-indicator.d.ts +8 -0
- package/src/lib/layout/tree/tng-tree-indicator.d.ts.map +1 -0
- package/src/lib/layout/tree/tng-tree-indicator.js +36 -0
- package/src/lib/layout/tree/tng-tree-indicator.js.map +1 -0
- package/src/lib/layout/tree/tng-tree-item.d.ts +36 -0
- package/src/lib/layout/tree/tng-tree-item.d.ts.map +1 -0
- package/src/lib/layout/tree/tng-tree-item.js +139 -0
- package/src/lib/layout/tree/tng-tree-item.js.map +1 -0
- package/src/lib/layout/tree/tng-tree.d.ts +64 -1
- package/src/lib/layout/tree/tng-tree.d.ts.map +1 -1
- package/src/lib/layout/tree/tng-tree.js +536 -1
- package/src/lib/layout/tree/tng-tree.js.map +1 -1
- package/src/lib/layout/tree/tng-tree.transforms.d.ts +10 -0
- package/src/lib/layout/tree/tng-tree.transforms.d.ts.map +1 -0
- package/src/lib/layout/tree/tng-tree.transforms.js +46 -0
- package/src/lib/layout/tree/tng-tree.transforms.js.map +1 -0
- package/src/lib/navigation/breadcrumb/tng-breadcrumb.d.ts.map +1 -1
- package/src/lib/navigation/breadcrumb/tng-breadcrumb.js +5 -0
- package/src/lib/navigation/breadcrumb/tng-breadcrumb.js.map +1 -1
- package/src/lib/navigation/dropdown-menu/tng-dropdown-menu.d.ts.map +1 -1
- package/src/lib/navigation/dropdown-menu/tng-dropdown-menu.js +1 -0
- package/src/lib/navigation/dropdown-menu/tng-dropdown-menu.js.map +1 -1
- package/src/lib/navigation/navigation-menu/tng-navigation-menu.d.ts.map +1 -1
- package/src/lib/navigation/navigation-menu/tng-navigation-menu.js +1 -0
- package/src/lib/navigation/navigation-menu/tng-navigation-menu.js.map +1 -1
- package/src/lib/navigation/toolbar/tng-toolbar.d.ts.map +1 -1
- package/src/lib/navigation/toolbar/tng-toolbar.js +1 -0
- package/src/lib/navigation/toolbar/tng-toolbar.js.map +1 -1
- package/src/lib/overlay/dialog/tng-dialog.d.ts +158 -0
- package/src/lib/overlay/dialog/tng-dialog.d.ts.map +1 -0
- package/src/lib/overlay/dialog/tng-dialog.js +854 -0
- package/src/lib/overlay/dialog/tng-dialog.js.map +1 -0
- package/src/lib/overlay/popover/tng-popover.d.ts +121 -0
- package/src/lib/overlay/popover/tng-popover.d.ts.map +1 -0
- package/src/lib/overlay/popover/tng-popover.js +614 -0
- package/src/lib/overlay/popover/tng-popover.js.map +1 -0
- package/src/lib/overlay/tng-overlay-runtime.d.ts +11 -0
- package/src/lib/overlay/tng-overlay-runtime.d.ts.map +1 -0
- package/src/lib/overlay/tng-overlay-runtime.js +6 -0
- package/src/lib/overlay/tng-overlay-runtime.js.map +1 -0
- package/src/lib/overlay/tooltip/tng-tooltip.d.ts +92 -3
- package/src/lib/overlay/tooltip/tng-tooltip.d.ts.map +1 -1
- package/src/lib/overlay/tooltip/tng-tooltip.js +477 -3
- package/src/lib/overlay/tooltip/tng-tooltip.js.map +1 -1
- package/src/lib/utility/avatar/tng-avatar.d.ts.map +1 -1
- package/src/lib/utility/avatar/tng-avatar.js +3 -0
- package/src/lib/utility/avatar/tng-avatar.js.map +1 -1
- package/src/lib/utility/badge/tng-badge.d.ts +6 -0
- package/src/lib/utility/badge/tng-badge.d.ts.map +1 -1
- package/src/lib/utility/badge/tng-badge.js +66 -0
- package/src/lib/utility/badge/tng-badge.js.map +1 -1
- package/src/lib/utility/code-block/tng-code-block.d.ts.map +1 -1
- package/src/lib/utility/code-block/tng-code-block.js +5 -0
- package/src/lib/utility/code-block/tng-code-block.js.map +1 -1
- package/src/lib/utility/copy/tng-copy.d.ts +21 -10
- package/src/lib/utility/copy/tng-copy.d.ts.map +1 -1
- package/src/lib/utility/copy/tng-copy.js +118 -88
- package/src/lib/utility/copy/tng-copy.js.map +1 -1
- package/src/lib/utility/press/tng-press.d.ts.map +1 -1
- package/src/lib/utility/press/tng-press.js +1 -0
- package/src/lib/utility/press/tng-press.js.map +1 -1
- package/src/lib/utility/tag/tng-tag.d.ts +37 -0
- package/src/lib/utility/tag/tng-tag.d.ts.map +1 -1
- package/src/lib/utility/tag/tng-tag.js +198 -1
- package/src/lib/utility/tag/tng-tag.js.map +1 -1
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { Directive, ElementRef, HostBinding, HostListener, afterNextRender, booleanAttribute, effect, inject, Injector, input, output, signal, } from '@angular/core';
|
|
3
|
+
import { createOverlayFocusHandoffController, resolveFocusableElements, createTngIdFactory, } from '@tailng-ui/cdk';
|
|
4
|
+
import { tngPrimitiveOverlayRuntime } from '../tng-overlay-runtime';
|
|
5
|
+
const createPopoverId = createTngIdFactory('tng-popover');
|
|
6
|
+
const createPopoverPanelId = createTngIdFactory('tng-popover-panel');
|
|
7
|
+
const createPopoverFocusableId = createTngIdFactory('tng-popover-focusable');
|
|
8
|
+
function normalizeOptionalBooleanInput(value) {
|
|
9
|
+
if (value === null || value === undefined) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return booleanAttribute(value);
|
|
13
|
+
}
|
|
14
|
+
function isPopoverCloseReason(value) {
|
|
15
|
+
return value === 'escape' || value === 'outside-pointer' || value === 'programmatic' || value === 'trigger-toggle';
|
|
16
|
+
}
|
|
17
|
+
function mapOverlayDismissReason(reason) {
|
|
18
|
+
if (reason === 'escape-key') {
|
|
19
|
+
return 'escape';
|
|
20
|
+
}
|
|
21
|
+
if (reason === 'outside-pointer') {
|
|
22
|
+
return 'outside-pointer';
|
|
23
|
+
}
|
|
24
|
+
return 'programmatic';
|
|
25
|
+
}
|
|
26
|
+
const popoverGlobalDocument = typeof document === 'undefined' ? null : document;
|
|
27
|
+
const popoverFocusHandoff = createOverlayFocusHandoffController();
|
|
28
|
+
export function resolvePopoverActiveElement(documentRef) {
|
|
29
|
+
if (!(documentRef instanceof Document)) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const active = documentRef.activeElement;
|
|
33
|
+
return active instanceof HTMLElement ? active : null;
|
|
34
|
+
}
|
|
35
|
+
export function resolvePopoverFocusableElements(container) {
|
|
36
|
+
return resolveFocusableElements(container);
|
|
37
|
+
}
|
|
38
|
+
export function resolvePopoverMarkedInitialElement(container) {
|
|
39
|
+
if (!(container instanceof HTMLElement)) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const markedInitial = container.querySelector('[data-tng-popover-initial-focus]');
|
|
43
|
+
if (markedInitial === null) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
if (resolvePopoverFocusableElements(container).includes(markedInitial)) {
|
|
47
|
+
return markedInitial;
|
|
48
|
+
}
|
|
49
|
+
return resolvePopoverFocusableElements(markedInitial)[0] ?? null;
|
|
50
|
+
}
|
|
51
|
+
let TngPopover = class TngPopover {
|
|
52
|
+
openInput = input(undefined, {
|
|
53
|
+
alias: 'open',
|
|
54
|
+
transform: normalizeOptionalBooleanInput,
|
|
55
|
+
});
|
|
56
|
+
defaultOpen = input(false, {
|
|
57
|
+
transform: booleanAttribute,
|
|
58
|
+
});
|
|
59
|
+
disabled = input(false, {
|
|
60
|
+
transform: booleanAttribute,
|
|
61
|
+
});
|
|
62
|
+
closeOnEscape = input(true, {
|
|
63
|
+
transform: booleanAttribute,
|
|
64
|
+
});
|
|
65
|
+
closeOnOutsidePointer = input(true, {
|
|
66
|
+
transform: booleanAttribute,
|
|
67
|
+
});
|
|
68
|
+
restoreFocus = input(true, {
|
|
69
|
+
transform: booleanAttribute,
|
|
70
|
+
});
|
|
71
|
+
autoFocus = input('first-focusable', {
|
|
72
|
+
transform: (value) => {
|
|
73
|
+
return value === 'none' || value === 'panel' || value === 'first-focusable' ? value : 'first-focusable';
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
side = input('bottom', {
|
|
77
|
+
transform: (value) => {
|
|
78
|
+
return value === 'top' || value === 'right' || value === 'bottom' || value === 'left' ? value : 'bottom';
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
align = input('start', {
|
|
82
|
+
transform: (value) => {
|
|
83
|
+
return value === 'start' || value === 'center' || value === 'end' ? value : 'start';
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
panelRole = input('dialog', {
|
|
87
|
+
transform: (value) => {
|
|
88
|
+
return value === 'dialog' || value === 'menu' || value === 'listbox' || value === 'region' || value === 'none'
|
|
89
|
+
? value
|
|
90
|
+
: 'dialog';
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
ariaHasPopup = input('dialog', {
|
|
94
|
+
transform: (value) => {
|
|
95
|
+
return value === 'dialog'
|
|
96
|
+
|| value === 'menu'
|
|
97
|
+
|| value === 'listbox'
|
|
98
|
+
|| value === 'tree'
|
|
99
|
+
|| value === 'grid'
|
|
100
|
+
|| value === 'true'
|
|
101
|
+
? value
|
|
102
|
+
: 'dialog';
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
ariaLabel = input(null);
|
|
106
|
+
openChange = output();
|
|
107
|
+
closed = output();
|
|
108
|
+
hostRef = inject(ElementRef);
|
|
109
|
+
injector = inject(Injector);
|
|
110
|
+
documentRef = popoverGlobalDocument;
|
|
111
|
+
instanceId = createPopoverId();
|
|
112
|
+
uncontrolledOpen = signal(false);
|
|
113
|
+
openStateEffect = effect(() => {
|
|
114
|
+
if (!this.initialized) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (this.isOpen()) {
|
|
118
|
+
this.activatePopover();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
this.deactivatePopover();
|
|
122
|
+
});
|
|
123
|
+
initialized = false;
|
|
124
|
+
isActive = false;
|
|
125
|
+
isFocusLayerRegistered = false;
|
|
126
|
+
isOverlayLayerRegistered = false;
|
|
127
|
+
panelElement = null;
|
|
128
|
+
panelElementId = null;
|
|
129
|
+
triggerElement = null;
|
|
130
|
+
dataSlot = 'popover';
|
|
131
|
+
get dataOpenAttr() {
|
|
132
|
+
return this.isOpen() ? 'true' : 'false';
|
|
133
|
+
}
|
|
134
|
+
get dataStateAttr() {
|
|
135
|
+
return this.isOpen() ? 'open' : 'closed';
|
|
136
|
+
}
|
|
137
|
+
get dataDisabledAttr() {
|
|
138
|
+
return this.disabled() ? '' : null;
|
|
139
|
+
}
|
|
140
|
+
get dataSideAttr() {
|
|
141
|
+
return this.side();
|
|
142
|
+
}
|
|
143
|
+
get dataAlignAttr() {
|
|
144
|
+
return this.align();
|
|
145
|
+
}
|
|
146
|
+
ngOnInit() {
|
|
147
|
+
if (!this.isControlled()) {
|
|
148
|
+
this.uncontrolledOpen.set(this.defaultOpen());
|
|
149
|
+
}
|
|
150
|
+
this.initialized = true;
|
|
151
|
+
if (this.isOpen()) {
|
|
152
|
+
this.activatePopover();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
ngOnDestroy() {
|
|
156
|
+
this.openStateEffect.destroy();
|
|
157
|
+
this.deactivatePopover();
|
|
158
|
+
}
|
|
159
|
+
isOpen() {
|
|
160
|
+
return this.openInput() ?? this.uncontrolledOpen();
|
|
161
|
+
}
|
|
162
|
+
openPopover() {
|
|
163
|
+
if (this.disabled() || this.isOpen()) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
this.setOpenState(true);
|
|
167
|
+
}
|
|
168
|
+
closePopover(reason = 'programmatic') {
|
|
169
|
+
this.requestClose(reason);
|
|
170
|
+
}
|
|
171
|
+
togglePopover(force) {
|
|
172
|
+
if (force === true) {
|
|
173
|
+
this.openPopover();
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (force === false) {
|
|
177
|
+
this.closePopover('programmatic');
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (this.isOpen()) {
|
|
181
|
+
this.requestClose('trigger-toggle');
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
this.openPopover();
|
|
185
|
+
}
|
|
186
|
+
requestClose(reason) {
|
|
187
|
+
if (!this.isOpen()) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
this.closed.emit(reason);
|
|
191
|
+
this.setOpenState(false);
|
|
192
|
+
}
|
|
193
|
+
registerTrigger(trigger) {
|
|
194
|
+
this.triggerElement = trigger;
|
|
195
|
+
}
|
|
196
|
+
unregisterTrigger(trigger) {
|
|
197
|
+
if (this.triggerElement === trigger) {
|
|
198
|
+
this.triggerElement = null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
registerPanel(panel, id) {
|
|
202
|
+
this.panelElement = panel;
|
|
203
|
+
this.panelElementId = id;
|
|
204
|
+
}
|
|
205
|
+
unregisterPanel(panel) {
|
|
206
|
+
if (this.panelElement === panel) {
|
|
207
|
+
this.panelElement = null;
|
|
208
|
+
this.panelElementId = null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
getPanelId() {
|
|
212
|
+
return this.panelElementId;
|
|
213
|
+
}
|
|
214
|
+
resolvePanelRole() {
|
|
215
|
+
const role = this.panelRole();
|
|
216
|
+
return role === 'none' ? null : role;
|
|
217
|
+
}
|
|
218
|
+
activatePopover() {
|
|
219
|
+
if (this.isActive) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
this.isActive = true;
|
|
223
|
+
this.registerFocusLayer();
|
|
224
|
+
this.activateFocusLayer();
|
|
225
|
+
this.registerOverlayLayer();
|
|
226
|
+
this.focusInitialElement();
|
|
227
|
+
}
|
|
228
|
+
deactivatePopover() {
|
|
229
|
+
if (!this.isActive) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
this.isActive = false;
|
|
233
|
+
this.deactivateFocusLayer();
|
|
234
|
+
this.unregisterFocusLayer();
|
|
235
|
+
this.unregisterOverlayLayer();
|
|
236
|
+
}
|
|
237
|
+
focusInitialElement() {
|
|
238
|
+
if (this.autoFocus() === 'none') {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
afterNextRender(() => {
|
|
242
|
+
if (!this.isOpen()) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const panel = this.panelElement;
|
|
246
|
+
if (panel === null) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (this.autoFocus() === 'panel') {
|
|
250
|
+
this.focusElement(panel);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const focusTarget = resolvePopoverMarkedInitialElement(panel) ?? resolvePopoverFocusableElements(panel)[0] ?? panel;
|
|
254
|
+
this.focusElement(focusTarget);
|
|
255
|
+
}, { injector: this.injector });
|
|
256
|
+
}
|
|
257
|
+
recordFocusedElement(target) {
|
|
258
|
+
if (!(target instanceof HTMLElement) || !this.isOpen()) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const panel = this.panelElement;
|
|
262
|
+
if (!panel?.contains(target)) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const targetId = this.ensureElementId(target);
|
|
266
|
+
popoverFocusHandoff.recordFocus(this.instanceId, targetId);
|
|
267
|
+
}
|
|
268
|
+
setOpenState(next) {
|
|
269
|
+
if (this.isOpen() === next) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (!this.isControlled()) {
|
|
273
|
+
this.uncontrolledOpen.set(next);
|
|
274
|
+
}
|
|
275
|
+
this.openChange.emit(next);
|
|
276
|
+
}
|
|
277
|
+
isControlled() {
|
|
278
|
+
return this.openInput() !== undefined;
|
|
279
|
+
}
|
|
280
|
+
shouldCloseFromEscape() {
|
|
281
|
+
return this.isOpen() && this.closeOnEscape();
|
|
282
|
+
}
|
|
283
|
+
shouldCloseFromOutsidePointer() {
|
|
284
|
+
return this.isOpen() && this.closeOnOutsidePointer();
|
|
285
|
+
}
|
|
286
|
+
activateFocusLayer() {
|
|
287
|
+
const activeElement = resolvePopoverActiveElement(this.documentRef);
|
|
288
|
+
const restoreFocusTargetId = activeElement === null ? null : this.ensureElementId(activeElement);
|
|
289
|
+
popoverFocusHandoff.activateLayer(this.instanceId, restoreFocusTargetId);
|
|
290
|
+
}
|
|
291
|
+
deactivateFocusLayer() {
|
|
292
|
+
const restoreFocusTargetId = popoverFocusHandoff.deactivateLayer(this.instanceId);
|
|
293
|
+
if (!this.restoreFocus() || restoreFocusTargetId === null) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const restoreFocusTarget = this.resolveElementById(restoreFocusTargetId) ?? this.triggerElement;
|
|
297
|
+
restoreFocusTarget?.focus();
|
|
298
|
+
}
|
|
299
|
+
registerFocusLayer() {
|
|
300
|
+
if (this.isFocusLayerRegistered) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
popoverFocusHandoff.registerLayer({
|
|
304
|
+
layerId: this.instanceId,
|
|
305
|
+
members: () => {
|
|
306
|
+
const panel = this.panelElement;
|
|
307
|
+
if (panel === null) {
|
|
308
|
+
return [];
|
|
309
|
+
}
|
|
310
|
+
return this.resolveFocusableMemberIds(panel);
|
|
311
|
+
},
|
|
312
|
+
restoreFocus: this.restoreFocus(),
|
|
313
|
+
trapFocus: false,
|
|
314
|
+
});
|
|
315
|
+
this.isFocusLayerRegistered = true;
|
|
316
|
+
}
|
|
317
|
+
unregisterFocusLayer() {
|
|
318
|
+
if (!this.isFocusLayerRegistered) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
popoverFocusHandoff.unregisterLayer(this.instanceId);
|
|
322
|
+
this.isFocusLayerRegistered = false;
|
|
323
|
+
}
|
|
324
|
+
registerOverlayLayer() {
|
|
325
|
+
const hostElement = this.hostRef.nativeElement;
|
|
326
|
+
tngPrimitiveOverlayRuntime.registerLayer({
|
|
327
|
+
containsTarget: (target, path) => {
|
|
328
|
+
if (target instanceof Node && hostElement.contains(target)) {
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
return path.includes(hostElement);
|
|
332
|
+
},
|
|
333
|
+
dismissOnEscape: this.shouldCloseFromEscape(),
|
|
334
|
+
dismissOnOutsidePointer: this.shouldCloseFromOutsidePointer(),
|
|
335
|
+
id: this.instanceId,
|
|
336
|
+
onDismiss: (reason) => {
|
|
337
|
+
if (reason === 'escape-key' && !this.shouldCloseFromEscape()) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (reason === 'outside-pointer' && !this.shouldCloseFromOutsidePointer()) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
this.requestClose(mapOverlayDismissReason(reason));
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
this.isOverlayLayerRegistered = true;
|
|
347
|
+
}
|
|
348
|
+
unregisterOverlayLayer() {
|
|
349
|
+
if (!this.isOverlayLayerRegistered) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
tngPrimitiveOverlayRuntime.unregisterLayer(this.instanceId);
|
|
353
|
+
this.isOverlayLayerRegistered = false;
|
|
354
|
+
}
|
|
355
|
+
focusElement(target) {
|
|
356
|
+
const targetId = this.ensureElementId(target);
|
|
357
|
+
const resolvedTargetId = popoverFocusHandoff.resolveFocusCandidate(this.instanceId, targetId);
|
|
358
|
+
if (resolvedTargetId === null) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const resolvedTarget = this.resolveElementById(resolvedTargetId);
|
|
362
|
+
if (resolvedTarget === null) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
resolvedTarget.focus();
|
|
366
|
+
popoverFocusHandoff.recordFocus(this.instanceId, resolvedTargetId);
|
|
367
|
+
}
|
|
368
|
+
resolveFocusableMemberIds(panel) {
|
|
369
|
+
const focusableElements = resolvePopoverFocusableElements(panel);
|
|
370
|
+
const memberIds = [];
|
|
371
|
+
const seenIds = new Set();
|
|
372
|
+
const registerMember = (element) => {
|
|
373
|
+
const id = this.ensureElementId(element);
|
|
374
|
+
if (seenIds.has(id)) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
seenIds.add(id);
|
|
378
|
+
memberIds.push(id);
|
|
379
|
+
};
|
|
380
|
+
registerMember(panel);
|
|
381
|
+
for (const element of focusableElements) {
|
|
382
|
+
registerMember(element);
|
|
383
|
+
}
|
|
384
|
+
return memberIds;
|
|
385
|
+
}
|
|
386
|
+
ensureElementId(element) {
|
|
387
|
+
const existingId = element.id.trim();
|
|
388
|
+
if (existingId.length > 0) {
|
|
389
|
+
return existingId;
|
|
390
|
+
}
|
|
391
|
+
const generatedId = createPopoverFocusableId();
|
|
392
|
+
element.id = generatedId;
|
|
393
|
+
return generatedId;
|
|
394
|
+
}
|
|
395
|
+
resolveElementById(id) {
|
|
396
|
+
if (this.documentRef === null) {
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
const element = this.documentRef.getElementById(id);
|
|
400
|
+
return element instanceof HTMLElement ? element : null;
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
__decorate([
|
|
404
|
+
HostBinding('attr.data-slot')
|
|
405
|
+
], TngPopover.prototype, "dataSlot", void 0);
|
|
406
|
+
__decorate([
|
|
407
|
+
HostBinding('attr.data-open')
|
|
408
|
+
], TngPopover.prototype, "dataOpenAttr", null);
|
|
409
|
+
__decorate([
|
|
410
|
+
HostBinding('attr.data-state')
|
|
411
|
+
], TngPopover.prototype, "dataStateAttr", null);
|
|
412
|
+
__decorate([
|
|
413
|
+
HostBinding('attr.data-disabled')
|
|
414
|
+
], TngPopover.prototype, "dataDisabledAttr", null);
|
|
415
|
+
__decorate([
|
|
416
|
+
HostBinding('attr.data-side')
|
|
417
|
+
], TngPopover.prototype, "dataSideAttr", null);
|
|
418
|
+
__decorate([
|
|
419
|
+
HostBinding('attr.data-align')
|
|
420
|
+
], TngPopover.prototype, "dataAlignAttr", null);
|
|
421
|
+
TngPopover = __decorate([
|
|
422
|
+
Directive({
|
|
423
|
+
selector: '[tngPopover]',
|
|
424
|
+
exportAs: 'tngPopover',
|
|
425
|
+
standalone: true,
|
|
426
|
+
})
|
|
427
|
+
], TngPopover);
|
|
428
|
+
export { TngPopover };
|
|
429
|
+
let TngPopoverTrigger = class TngPopoverTrigger {
|
|
430
|
+
hostRef = inject(ElementRef);
|
|
431
|
+
parentPopover = inject(TngPopover, { optional: true });
|
|
432
|
+
popoverFor = input(null, {
|
|
433
|
+
alias: 'tngPopoverTrigger',
|
|
434
|
+
});
|
|
435
|
+
get ariaHasPopupAttr() {
|
|
436
|
+
return this.resolvePopover()?.ariaHasPopup() ?? 'dialog';
|
|
437
|
+
}
|
|
438
|
+
get ariaControlsAttr() {
|
|
439
|
+
return this.resolvePopover()?.getPanelId() ?? null;
|
|
440
|
+
}
|
|
441
|
+
get ariaExpandedAttr() {
|
|
442
|
+
return this.resolvePopover()?.isOpen() ? 'true' : 'false';
|
|
443
|
+
}
|
|
444
|
+
dataSlot = 'popover-trigger';
|
|
445
|
+
get dataOpenAttr() {
|
|
446
|
+
return this.resolvePopover()?.isOpen() ? 'true' : 'false';
|
|
447
|
+
}
|
|
448
|
+
get dataStateAttr() {
|
|
449
|
+
return this.resolvePopover()?.isOpen() ? 'open' : 'closed';
|
|
450
|
+
}
|
|
451
|
+
get dataDisabledAttr() {
|
|
452
|
+
return this.resolvePopover()?.disabled() ? '' : null;
|
|
453
|
+
}
|
|
454
|
+
ngOnInit() {
|
|
455
|
+
this.resolvePopover()?.registerTrigger(this.hostRef.nativeElement);
|
|
456
|
+
}
|
|
457
|
+
ngOnDestroy() {
|
|
458
|
+
this.resolvePopover()?.unregisterTrigger(this.hostRef.nativeElement);
|
|
459
|
+
}
|
|
460
|
+
onClick() {
|
|
461
|
+
this.resolvePopover()?.togglePopover();
|
|
462
|
+
}
|
|
463
|
+
resolvePopover() {
|
|
464
|
+
return this.popoverFor() ?? this.parentPopover;
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
__decorate([
|
|
468
|
+
HostBinding('attr.aria-haspopup')
|
|
469
|
+
], TngPopoverTrigger.prototype, "ariaHasPopupAttr", null);
|
|
470
|
+
__decorate([
|
|
471
|
+
HostBinding('attr.aria-controls')
|
|
472
|
+
], TngPopoverTrigger.prototype, "ariaControlsAttr", null);
|
|
473
|
+
__decorate([
|
|
474
|
+
HostBinding('attr.aria-expanded')
|
|
475
|
+
], TngPopoverTrigger.prototype, "ariaExpandedAttr", null);
|
|
476
|
+
__decorate([
|
|
477
|
+
HostBinding('attr.data-slot')
|
|
478
|
+
], TngPopoverTrigger.prototype, "dataSlot", void 0);
|
|
479
|
+
__decorate([
|
|
480
|
+
HostBinding('attr.data-open')
|
|
481
|
+
], TngPopoverTrigger.prototype, "dataOpenAttr", null);
|
|
482
|
+
__decorate([
|
|
483
|
+
HostBinding('attr.data-state')
|
|
484
|
+
], TngPopoverTrigger.prototype, "dataStateAttr", null);
|
|
485
|
+
__decorate([
|
|
486
|
+
HostBinding('attr.data-disabled')
|
|
487
|
+
], TngPopoverTrigger.prototype, "dataDisabledAttr", null);
|
|
488
|
+
__decorate([
|
|
489
|
+
HostListener('click')
|
|
490
|
+
], TngPopoverTrigger.prototype, "onClick", null);
|
|
491
|
+
TngPopoverTrigger = __decorate([
|
|
492
|
+
Directive({
|
|
493
|
+
selector: '[tngPopoverTrigger]',
|
|
494
|
+
exportAs: 'tngPopoverTrigger',
|
|
495
|
+
standalone: true,
|
|
496
|
+
})
|
|
497
|
+
], TngPopoverTrigger);
|
|
498
|
+
export { TngPopoverTrigger };
|
|
499
|
+
let TngPopoverPanel = class TngPopoverPanel {
|
|
500
|
+
popover = inject(TngPopover);
|
|
501
|
+
hostRef = inject(ElementRef);
|
|
502
|
+
generatedId = createPopoverPanelId();
|
|
503
|
+
resolvedId = '';
|
|
504
|
+
dataSlot = 'popover-panel';
|
|
505
|
+
get dataOpenAttr() {
|
|
506
|
+
return this.popover.isOpen() ? 'true' : 'false';
|
|
507
|
+
}
|
|
508
|
+
get dataStateAttr() {
|
|
509
|
+
return this.popover.isOpen() ? 'open' : 'closed';
|
|
510
|
+
}
|
|
511
|
+
get dataSideAttr() {
|
|
512
|
+
return this.popover.side();
|
|
513
|
+
}
|
|
514
|
+
get dataAlignAttr() {
|
|
515
|
+
return this.popover.align();
|
|
516
|
+
}
|
|
517
|
+
get hiddenAttr() {
|
|
518
|
+
return this.popover.isOpen() ? null : '';
|
|
519
|
+
}
|
|
520
|
+
get idAttr() {
|
|
521
|
+
return this.resolvedId;
|
|
522
|
+
}
|
|
523
|
+
get roleAttr() {
|
|
524
|
+
return this.popover.resolvePanelRole();
|
|
525
|
+
}
|
|
526
|
+
get ariaLabelAttr() {
|
|
527
|
+
return this.popover.ariaLabel();
|
|
528
|
+
}
|
|
529
|
+
tabIndexAttr = '-1';
|
|
530
|
+
ngOnInit() {
|
|
531
|
+
const hostId = this.hostRef.nativeElement.id.trim();
|
|
532
|
+
this.resolvedId = hostId.length > 0 ? hostId : this.generatedId;
|
|
533
|
+
this.popover.registerPanel(this.hostRef.nativeElement, this.resolvedId);
|
|
534
|
+
}
|
|
535
|
+
ngOnDestroy() {
|
|
536
|
+
this.popover.unregisterPanel(this.hostRef.nativeElement);
|
|
537
|
+
}
|
|
538
|
+
onFocusIn(target) {
|
|
539
|
+
this.popover.recordFocusedElement(target);
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
__decorate([
|
|
543
|
+
HostBinding('attr.data-slot')
|
|
544
|
+
], TngPopoverPanel.prototype, "dataSlot", void 0);
|
|
545
|
+
__decorate([
|
|
546
|
+
HostBinding('attr.data-open')
|
|
547
|
+
], TngPopoverPanel.prototype, "dataOpenAttr", null);
|
|
548
|
+
__decorate([
|
|
549
|
+
HostBinding('attr.data-state')
|
|
550
|
+
], TngPopoverPanel.prototype, "dataStateAttr", null);
|
|
551
|
+
__decorate([
|
|
552
|
+
HostBinding('attr.data-side')
|
|
553
|
+
], TngPopoverPanel.prototype, "dataSideAttr", null);
|
|
554
|
+
__decorate([
|
|
555
|
+
HostBinding('attr.data-align')
|
|
556
|
+
], TngPopoverPanel.prototype, "dataAlignAttr", null);
|
|
557
|
+
__decorate([
|
|
558
|
+
HostBinding('attr.hidden')
|
|
559
|
+
], TngPopoverPanel.prototype, "hiddenAttr", null);
|
|
560
|
+
__decorate([
|
|
561
|
+
HostBinding('attr.id')
|
|
562
|
+
], TngPopoverPanel.prototype, "idAttr", null);
|
|
563
|
+
__decorate([
|
|
564
|
+
HostBinding('attr.role')
|
|
565
|
+
], TngPopoverPanel.prototype, "roleAttr", null);
|
|
566
|
+
__decorate([
|
|
567
|
+
HostBinding('attr.aria-label')
|
|
568
|
+
], TngPopoverPanel.prototype, "ariaLabelAttr", null);
|
|
569
|
+
__decorate([
|
|
570
|
+
HostBinding('attr.tabindex')
|
|
571
|
+
], TngPopoverPanel.prototype, "tabIndexAttr", void 0);
|
|
572
|
+
__decorate([
|
|
573
|
+
HostListener('focusin', ['$event.target'])
|
|
574
|
+
], TngPopoverPanel.prototype, "onFocusIn", null);
|
|
575
|
+
TngPopoverPanel = __decorate([
|
|
576
|
+
Directive({
|
|
577
|
+
selector: '[tngPopoverPanel], [tngPopoverContent]',
|
|
578
|
+
exportAs: 'tngPopoverPanel',
|
|
579
|
+
standalone: true,
|
|
580
|
+
})
|
|
581
|
+
], TngPopoverPanel);
|
|
582
|
+
export { TngPopoverPanel };
|
|
583
|
+
let TngPopoverClose = class TngPopoverClose {
|
|
584
|
+
popover = inject(TngPopover);
|
|
585
|
+
closeReason = input(null, {
|
|
586
|
+
alias: 'tngPopoverClose',
|
|
587
|
+
});
|
|
588
|
+
dataSlot = 'popover-close';
|
|
589
|
+
onClick() {
|
|
590
|
+
this.popover.requestClose(this.resolveCloseReason());
|
|
591
|
+
}
|
|
592
|
+
resolveCloseReason() {
|
|
593
|
+
const raw = this.closeReason()?.trim();
|
|
594
|
+
if (raw === undefined || raw.length === 0) {
|
|
595
|
+
return 'programmatic';
|
|
596
|
+
}
|
|
597
|
+
return isPopoverCloseReason(raw) ? raw : 'programmatic';
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
__decorate([
|
|
601
|
+
HostBinding('attr.data-slot')
|
|
602
|
+
], TngPopoverClose.prototype, "dataSlot", void 0);
|
|
603
|
+
__decorate([
|
|
604
|
+
HostListener('click')
|
|
605
|
+
], TngPopoverClose.prototype, "onClick", null);
|
|
606
|
+
TngPopoverClose = __decorate([
|
|
607
|
+
Directive({
|
|
608
|
+
selector: '[tngPopoverClose]',
|
|
609
|
+
exportAs: 'tngPopoverClose',
|
|
610
|
+
standalone: true,
|
|
611
|
+
})
|
|
612
|
+
], TngPopoverClose);
|
|
613
|
+
export { TngPopoverClose };
|
|
614
|
+
//# sourceMappingURL=tng-popover.js.map
|