@radix-ng/primitives 0.41.0 → 0.42.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/fesm2022/radix-ng-primitives-focus-scope.mjs +336 -0
- package/fesm2022/radix-ng-primitives-focus-scope.mjs.map +1 -0
- package/focus-scope/README.md +1 -0
- package/focus-scope/index.d.ts +1 -0
- package/focus-scope/src/focus-scope.d.ts +53 -0
- package/focus-scope/src/stack.d.ts +13 -0
- package/focus-scope/src/utils.d.ts +46 -0
- package/hover-card/src/hover-card-root.directive.d.ts +4 -4
- package/package.json +5 -1
- package/popover/src/popover-root.directive.d.ts +4 -4
- package/tooltip/src/tooltip-root.directive.d.ts +4 -4
@@ -0,0 +1,336 @@
|
|
1
|
+
import * as i0 from '@angular/core';
|
2
|
+
import { signal, inject, Injector, ElementRef, input, booleanAttribute, output, afterNextRender, effect, Directive } from '@angular/core';
|
3
|
+
import { getActiveElement, createContext } from '@radix-ng/primitives/core';
|
4
|
+
|
5
|
+
function createGlobalState(factory) {
|
6
|
+
const state = factory();
|
7
|
+
return () => state;
|
8
|
+
}
|
9
|
+
const useFocusStackState = createGlobalState(() => signal([]));
|
10
|
+
function createFocusScopesStack() {
|
11
|
+
/** A stack of focus scopes, with the active one at the top */
|
12
|
+
const stack = useFocusStackState();
|
13
|
+
return {
|
14
|
+
add(focusScope) {
|
15
|
+
const current = stack();
|
16
|
+
const active = current[0];
|
17
|
+
if (focusScope !== active) {
|
18
|
+
active?.pause();
|
19
|
+
}
|
20
|
+
const updated = arrayRemove(current, focusScope);
|
21
|
+
updated.unshift(focusScope);
|
22
|
+
stack.set(updated);
|
23
|
+
},
|
24
|
+
remove(focusScope) {
|
25
|
+
const current = stack();
|
26
|
+
const updated = arrayRemove(current, focusScope);
|
27
|
+
stack.set(updated);
|
28
|
+
// после удаления «возобновляем» новый верхний
|
29
|
+
stack()[0]?.resume();
|
30
|
+
}
|
31
|
+
};
|
32
|
+
}
|
33
|
+
function arrayRemove(array, item) {
|
34
|
+
const copy = [...array];
|
35
|
+
const idx = copy.indexOf(item);
|
36
|
+
if (idx !== -1) {
|
37
|
+
copy.splice(idx, 1);
|
38
|
+
}
|
39
|
+
return copy;
|
40
|
+
}
|
41
|
+
function removeLinks(items) {
|
42
|
+
return items.filter((el) => el.tagName !== 'A');
|
43
|
+
}
|
44
|
+
|
45
|
+
const AUTOFOCUS_ON_MOUNT = 'focusScope.autoFocusOnMount';
|
46
|
+
const AUTOFOCUS_ON_UNMOUNT = 'focusScope.autoFocusOnUnmount';
|
47
|
+
const EVENT_OPTIONS = { bubbles: false, cancelable: true };
|
48
|
+
/**
|
49
|
+
* Attempts focusing the first element in a list of candidates.
|
50
|
+
* Stops when focus has actually moved.
|
51
|
+
*/
|
52
|
+
function focusFirst(candidates, { select = false } = {}) {
|
53
|
+
const previouslyFocusedElement = getActiveElement();
|
54
|
+
for (const candidate of candidates) {
|
55
|
+
focus(candidate, { select });
|
56
|
+
if (getActiveElement() !== previouslyFocusedElement)
|
57
|
+
return true;
|
58
|
+
}
|
59
|
+
return;
|
60
|
+
}
|
61
|
+
/**
|
62
|
+
* Returns a list of potential tabbable candidates.
|
63
|
+
*
|
64
|
+
* NOTE: This is only a close approximation. For example it doesn't take into account cases like when
|
65
|
+
* elements are not visible. This cannot be worked out easily by just reading a property, but rather
|
66
|
+
* necessitate runtime knowledge (computed styles, etc). We deal with these cases separately.
|
67
|
+
*
|
68
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
|
69
|
+
* Credit: https://github.com/discord/focus-layers/blob/master/src/util/wrapFocus.tsx#L1
|
70
|
+
*/
|
71
|
+
function getTabbableCandidates(container) {
|
72
|
+
const nodes = [];
|
73
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
74
|
+
acceptNode: (node) => {
|
75
|
+
const isHiddenInput = node.tagName === 'INPUT' && node.type === 'hidden';
|
76
|
+
if (node.disabled || node.hidden || isHiddenInput)
|
77
|
+
return NodeFilter.FILTER_SKIP;
|
78
|
+
// `.tabIndex` is not the same as the `tabindex` attribute. It works on the
|
79
|
+
// runtime's understanding of tabbability, so this automatically accounts
|
80
|
+
// for any kind of element that could be tabbed to.
|
81
|
+
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
82
|
+
}
|
83
|
+
});
|
84
|
+
while (walker.nextNode())
|
85
|
+
nodes.push(walker.currentNode);
|
86
|
+
// we do not take into account the order of nodes with positive `tabIndex` as it
|
87
|
+
// hinders accessibility to have tab order different from visual order.
|
88
|
+
return nodes;
|
89
|
+
}
|
90
|
+
function isHidden(node, { upTo }) {
|
91
|
+
if (getComputedStyle(node).visibility === 'hidden')
|
92
|
+
return true;
|
93
|
+
while (node) {
|
94
|
+
// we stop at `upTo` (excluding it)
|
95
|
+
if (upTo !== undefined && node === upTo)
|
96
|
+
return false;
|
97
|
+
if (getComputedStyle(node).display === 'none')
|
98
|
+
return true;
|
99
|
+
node = node.parentElement;
|
100
|
+
}
|
101
|
+
return false;
|
102
|
+
}
|
103
|
+
/**
|
104
|
+
* Returns the first visible element in a list.
|
105
|
+
* NOTE: Only checks visibility up to the `container`.
|
106
|
+
*/
|
107
|
+
function findVisible(elements, container) {
|
108
|
+
for (const element of elements) {
|
109
|
+
// we stop checking if it's hidden at the `container` level (excluding)
|
110
|
+
if (!isHidden(element, { upTo: container }))
|
111
|
+
return element;
|
112
|
+
}
|
113
|
+
return undefined;
|
114
|
+
}
|
115
|
+
/**
|
116
|
+
* Returns the first and last tabbable elements inside a container.
|
117
|
+
*/
|
118
|
+
function getTabbableEdges(container) {
|
119
|
+
const candidates = getTabbableCandidates(container);
|
120
|
+
const first = findVisible(candidates, container);
|
121
|
+
const last = findVisible(candidates.reverse(), container);
|
122
|
+
return [first, last];
|
123
|
+
}
|
124
|
+
function isSelectableInput(element) {
|
125
|
+
return element instanceof HTMLInputElement && 'select' in element;
|
126
|
+
}
|
127
|
+
function focus(element, { select = false } = {}) {
|
128
|
+
// only focus if that element is focusable
|
129
|
+
if (element && element.focus) {
|
130
|
+
const previouslyFocusedElement = getActiveElement();
|
131
|
+
// NOTE: we prevent scrolling on focus, to minimize jarring transitions for users
|
132
|
+
element.focus({ preventScroll: true });
|
133
|
+
// only select if its not the same element, it supports selection and we need to select
|
134
|
+
if (element !== previouslyFocusedElement && isSelectableInput(element) && select) {
|
135
|
+
element.select();
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
const [injectFocusScopeContext, provideFocusScopeContext] = createContext('FocusScope Context');
|
141
|
+
const rootContext = () => {
|
142
|
+
const context = inject(RdxFocusScope);
|
143
|
+
return {
|
144
|
+
loop: context.loop,
|
145
|
+
trapped: context.trapped
|
146
|
+
};
|
147
|
+
};
|
148
|
+
/**
|
149
|
+
* @group Components
|
150
|
+
*/
|
151
|
+
class RdxFocusScope {
|
152
|
+
constructor() {
|
153
|
+
this.injector = inject(Injector);
|
154
|
+
this.elementRef = inject(ElementRef);
|
155
|
+
/**
|
156
|
+
* When `true`, tabbing from last item will focus first tabbable
|
157
|
+
* and shift+tab from first item will focus last tababble.
|
158
|
+
*
|
159
|
+
* @group Props
|
160
|
+
* @defaultValue false
|
161
|
+
*/
|
162
|
+
this.loop = input(false, { transform: booleanAttribute });
|
163
|
+
/**
|
164
|
+
* When `true`, focus cannot escape the focus scope via keyboard,
|
165
|
+
* pointer, or a programmatic focus.
|
166
|
+
*
|
167
|
+
* @group Props
|
168
|
+
* @defaultValue false
|
169
|
+
*/
|
170
|
+
this.trapped = input(false, { transform: booleanAttribute });
|
171
|
+
/**
|
172
|
+
* Event handler called when auto-focusing on mount.
|
173
|
+
* Can be prevented.
|
174
|
+
*
|
175
|
+
* @group Emits
|
176
|
+
*/
|
177
|
+
this.mountAutoFocus = output();
|
178
|
+
/**
|
179
|
+
* Event handler called when auto-focusing on unmount.
|
180
|
+
* Can be prevented.
|
181
|
+
*
|
182
|
+
* @group Emits
|
183
|
+
*/
|
184
|
+
this.unmountAutoFocus = output();
|
185
|
+
this.lastFocusedElement = signal(null);
|
186
|
+
this.focusScopesStack = createFocusScopesStack();
|
187
|
+
this.focusScope = {
|
188
|
+
paused: signal(false),
|
189
|
+
pause: () => this.focusScope.paused.set(true),
|
190
|
+
resume: () => this.focusScope.paused.set(false)
|
191
|
+
};
|
192
|
+
afterNextRender(() => {
|
193
|
+
effect((onCleanup) => {
|
194
|
+
const container = this.elementRef.nativeElement;
|
195
|
+
if (this.trapped()) {
|
196
|
+
const handleFocusIn = (event) => {
|
197
|
+
if (this.focusScope.paused() || !container) {
|
198
|
+
return;
|
199
|
+
}
|
200
|
+
const target = event.target;
|
201
|
+
if (this.elementRef.nativeElement.contains(target)) {
|
202
|
+
this.lastFocusedElement.set(target);
|
203
|
+
}
|
204
|
+
else {
|
205
|
+
focus(this.lastFocusedElement(), { select: true });
|
206
|
+
}
|
207
|
+
};
|
208
|
+
const handleFocusOut = (event) => {
|
209
|
+
if (this.focusScope.paused() || !container) {
|
210
|
+
return;
|
211
|
+
}
|
212
|
+
const relatedTarget = event.relatedTarget;
|
213
|
+
// A `focusout` event with a `null` `relatedTarget` will happen in at least two cases:
|
214
|
+
//
|
215
|
+
// 1. When the user switches app/tabs/windows/the browser itself loses focus.
|
216
|
+
// 2. In Google Chrome, when the focused element is removed from the DOM.
|
217
|
+
//
|
218
|
+
// We let the browser do its thing here because:
|
219
|
+
//
|
220
|
+
// 1. The browser already keeps a memory of what's focused for when the page gets refocused.
|
221
|
+
// 2. In Google Chrome, if we try to focus the deleted focused element (as per below), it
|
222
|
+
// throws the CPU to 100%, so we avoid doing anything for this reason here too.
|
223
|
+
if (relatedTarget === null)
|
224
|
+
return;
|
225
|
+
// If the focus has moved to an actual legitimate element (`relatedTarget !== null`)
|
226
|
+
// that is outside the container, we move focus to the last valid focused element inside.
|
227
|
+
if (!container.contains(relatedTarget)) {
|
228
|
+
focus(this.lastFocusedElement(), { select: true });
|
229
|
+
}
|
230
|
+
};
|
231
|
+
const handleMutations = () => {
|
232
|
+
const isLastFocusedElementExist = container.contains(this.lastFocusedElement());
|
233
|
+
if (!isLastFocusedElementExist) {
|
234
|
+
focus(container);
|
235
|
+
}
|
236
|
+
};
|
237
|
+
const mutationObserver = new MutationObserver(handleMutations);
|
238
|
+
if (container) {
|
239
|
+
mutationObserver.observe(container, { childList: true, subtree: true });
|
240
|
+
}
|
241
|
+
document.addEventListener('focusin', handleFocusIn);
|
242
|
+
document.addEventListener('focusout', handleFocusOut);
|
243
|
+
onCleanup(() => {
|
244
|
+
document.removeEventListener('focusin', handleFocusIn);
|
245
|
+
document.removeEventListener('focusout', handleFocusOut);
|
246
|
+
mutationObserver.disconnect();
|
247
|
+
});
|
248
|
+
}
|
249
|
+
}, { injector: this.injector });
|
250
|
+
effect(async (onCleanup) => {
|
251
|
+
const container = this.elementRef.nativeElement;
|
252
|
+
await Promise.resolve();
|
253
|
+
if (!container) {
|
254
|
+
return;
|
255
|
+
}
|
256
|
+
this.focusScopesStack.add(this.focusScope);
|
257
|
+
const previouslyFocusedElement = getActiveElement();
|
258
|
+
const hasFocusedCandidate = container.contains(previouslyFocusedElement);
|
259
|
+
if (!hasFocusedCandidate) {
|
260
|
+
const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
|
261
|
+
container.addEventListener(AUTOFOCUS_ON_MOUNT, (ev) => this.mountAutoFocus.emit(ev));
|
262
|
+
container.dispatchEvent(mountEvent);
|
263
|
+
if (!mountEvent.defaultPrevented) {
|
264
|
+
focusFirst(removeLinks(getTabbableCandidates(container)), {
|
265
|
+
select: true
|
266
|
+
});
|
267
|
+
if (getActiveElement() === previouslyFocusedElement)
|
268
|
+
focus(container);
|
269
|
+
}
|
270
|
+
}
|
271
|
+
onCleanup(() => {
|
272
|
+
container.removeEventListener(AUTOFOCUS_ON_MOUNT, (ev) => this.mountAutoFocus.emit(ev));
|
273
|
+
const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
|
274
|
+
const unmountEventHandler = (ev) => this.unmountAutoFocus.emit(ev);
|
275
|
+
container.addEventListener(AUTOFOCUS_ON_UNMOUNT, unmountEventHandler);
|
276
|
+
container.dispatchEvent(unmountEvent);
|
277
|
+
setTimeout(() => {
|
278
|
+
if (!unmountEvent.defaultPrevented)
|
279
|
+
focus(previouslyFocusedElement ?? document.body, { select: true });
|
280
|
+
// we need to remove the listener after we `dispatchEvent`
|
281
|
+
container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, unmountEventHandler);
|
282
|
+
this.focusScopesStack.remove(this.focusScope);
|
283
|
+
}, 0);
|
284
|
+
});
|
285
|
+
}, { injector: this.injector });
|
286
|
+
});
|
287
|
+
}
|
288
|
+
handleKeyDown(event) {
|
289
|
+
const isTabKey = event.key === 'Tab' && !event.altKey && !event.ctrlKey && !event.metaKey;
|
290
|
+
const focusedElement = getActiveElement();
|
291
|
+
if (isTabKey && focusedElement) {
|
292
|
+
const container = event.currentTarget;
|
293
|
+
const [first, last] = getTabbableEdges(container);
|
294
|
+
const hasTabbableElementsInside = first && last;
|
295
|
+
// we can only wrap focus if we have tabbable edges
|
296
|
+
if (!hasTabbableElementsInside) {
|
297
|
+
if (focusedElement === container)
|
298
|
+
event.preventDefault();
|
299
|
+
}
|
300
|
+
else {
|
301
|
+
if (!event.shiftKey && focusedElement === last) {
|
302
|
+
event.preventDefault();
|
303
|
+
if (this.loop()) {
|
304
|
+
focus(first, { select: true });
|
305
|
+
}
|
306
|
+
}
|
307
|
+
else if (event.shiftKey && focusedElement === first) {
|
308
|
+
event.preventDefault();
|
309
|
+
if (this.loop()) {
|
310
|
+
focus(last, { select: true });
|
311
|
+
}
|
312
|
+
}
|
313
|
+
}
|
314
|
+
}
|
315
|
+
}
|
316
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxFocusScope, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
317
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.4", type: RdxFocusScope, isStandalone: true, selector: "[rdxFocusScope]", inputs: { loop: { classPropertyName: "loop", publicName: "loop", isSignal: true, isRequired: false, transformFunction: null }, trapped: { classPropertyName: "trapped", publicName: "trapped", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { mountAutoFocus: "mountAutoFocus", unmountAutoFocus: "unmountAutoFocus" }, host: { attributes: { "tabindex": "-1" }, listeners: { "keydown": "handleKeyDown($event)" } }, providers: [provideFocusScopeContext(rootContext)], ngImport: i0 }); }
|
318
|
+
}
|
319
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RdxFocusScope, decorators: [{
|
320
|
+
type: Directive,
|
321
|
+
args: [{
|
322
|
+
selector: '[rdxFocusScope]',
|
323
|
+
providers: [provideFocusScopeContext(rootContext)],
|
324
|
+
host: {
|
325
|
+
tabindex: '-1',
|
326
|
+
'(keydown)': 'handleKeyDown($event)'
|
327
|
+
}
|
328
|
+
}]
|
329
|
+
}], ctorParameters: () => [] });
|
330
|
+
|
331
|
+
/**
|
332
|
+
* Generated bundle index. Do not edit.
|
333
|
+
*/
|
334
|
+
|
335
|
+
export { RdxFocusScope, injectFocusScopeContext, provideFocusScopeContext };
|
336
|
+
//# sourceMappingURL=radix-ng-primitives-focus-scope.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"radix-ng-primitives-focus-scope.mjs","sources":["../../../packages/primitives/focus-scope/src/stack.ts","../../../packages/primitives/focus-scope/src/utils.ts","../../../packages/primitives/focus-scope/src/focus-scope.ts","../../../packages/primitives/focus-scope/radix-ng-primitives-focus-scope.ts"],"sourcesContent":["import { signal, WritableSignal } from '@angular/core';\n\nexport function createGlobalState<T>(factory: () => T): () => T {\n const state = factory();\n return () => state;\n}\n\nexport interface FocusScopeAPI {\n paused: WritableSignal<boolean>;\n pause(): void;\n resume(): void;\n}\n\nconst useFocusStackState = createGlobalState(() => signal<FocusScopeAPI[]>([]));\n\nexport function createFocusScopesStack() {\n /** A stack of focus scopes, with the active one at the top */\n const stack = useFocusStackState();\n\n return {\n add(focusScope: FocusScopeAPI) {\n const current = stack();\n const active = current[0];\n if (focusScope !== active) {\n active?.pause();\n }\n const updated = arrayRemove(current, focusScope);\n updated.unshift(focusScope);\n stack.set(updated);\n },\n\n remove(focusScope: FocusScopeAPI) {\n const current = stack();\n const updated = arrayRemove(current, focusScope);\n stack.set(updated);\n // после удаления «возобновляем» новый верхний\n stack()[0]?.resume();\n }\n };\n}\n\nexport function arrayRemove<T>(array: T[], item: T): T[] {\n const copy = [...array];\n const idx = copy.indexOf(item);\n if (idx !== -1) {\n copy.splice(idx, 1);\n }\n return copy;\n}\n\nexport function removeLinks(items: HTMLElement[]): HTMLElement[] {\n return items.filter((el) => el.tagName !== 'A');\n}\n","import { getActiveElement } from '@radix-ng/primitives/core';\n\nexport const AUTOFOCUS_ON_MOUNT = 'focusScope.autoFocusOnMount';\nexport const AUTOFOCUS_ON_UNMOUNT = 'focusScope.autoFocusOnUnmount';\nexport const EVENT_OPTIONS = { bubbles: false, cancelable: true };\n\ntype FocusableTarget = HTMLElement | { focus: () => void };\n\n/**\n * Attempts focusing the first element in a list of candidates.\n * Stops when focus has actually moved.\n */\nexport function focusFirst(candidates: HTMLElement[], { select = false } = {}) {\n const previouslyFocusedElement = getActiveElement();\n for (const candidate of candidates) {\n focus(candidate, { select });\n if (getActiveElement() !== previouslyFocusedElement) return true;\n }\n\n return;\n}\n\n/**\n * Returns a list of potential tabbable candidates.\n *\n * NOTE: This is only a close approximation. For example it doesn't take into account cases like when\n * elements are not visible. This cannot be worked out easily by just reading a property, but rather\n * necessitate runtime knowledge (computed styles, etc). We deal with these cases separately.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker\n * Credit: https://github.com/discord/focus-layers/blob/master/src/util/wrapFocus.tsx#L1\n */\nexport function getTabbableCandidates(container: HTMLElement) {\n const nodes: HTMLElement[] = [];\n const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {\n acceptNode: (node: any) => {\n const isHiddenInput = node.tagName === 'INPUT' && node.type === 'hidden';\n if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP;\n // `.tabIndex` is not the same as the `tabindex` attribute. It works on the\n // runtime's understanding of tabbability, so this automatically accounts\n // for any kind of element that could be tabbed to.\n return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;\n }\n });\n while (walker.nextNode()) nodes.push(walker.currentNode as HTMLElement);\n // we do not take into account the order of nodes with positive `tabIndex` as it\n // hinders accessibility to have tab order different from visual order.\n return nodes;\n}\n\nexport function isHidden(node: HTMLElement, { upTo }: { upTo?: HTMLElement }) {\n if (getComputedStyle(node).visibility === 'hidden') return true;\n while (node) {\n // we stop at `upTo` (excluding it)\n if (upTo !== undefined && node === upTo) return false;\n if (getComputedStyle(node).display === 'none') return true;\n node = node.parentElement as HTMLElement;\n }\n return false;\n}\n\n/**\n * Returns the first visible element in a list.\n * NOTE: Only checks visibility up to the `container`.\n */\nexport function findVisible(elements: HTMLElement[], container: HTMLElement): HTMLElement | undefined {\n for (const element of elements) {\n // we stop checking if it's hidden at the `container` level (excluding)\n if (!isHidden(element, { upTo: container })) return element;\n }\n return undefined;\n}\n\n/**\n * Returns the first and last tabbable elements inside a container.\n */\nexport function getTabbableEdges(container: HTMLElement) {\n const candidates = getTabbableCandidates(container);\n const first = findVisible(candidates, container);\n const last = findVisible(candidates.reverse(), container);\n return [first, last] as const;\n}\n\nexport function isSelectableInput(element: any): element is FocusableTarget & { select: () => void } {\n return element instanceof HTMLInputElement && 'select' in element;\n}\n\nexport function focus(element?: FocusableTarget | null, { select = false } = {}) {\n // only focus if that element is focusable\n if (element && element.focus) {\n const previouslyFocusedElement = getActiveElement();\n // NOTE: we prevent scrolling on focus, to minimize jarring transitions for users\n element.focus({ preventScroll: true });\n // only select if its not the same element, it supports selection and we need to select\n if (element !== previouslyFocusedElement && isSelectableInput(element) && select) {\n element.select();\n }\n }\n}\n","import { BooleanInput } from '@angular/cdk/coercion';\nimport {\n afterNextRender,\n booleanAttribute,\n Directive,\n effect,\n ElementRef,\n inject,\n Injector,\n input,\n output,\n Signal,\n signal\n} from '@angular/core';\nimport { createContext, getActiveElement } from '@radix-ng/primitives/core';\nimport { createFocusScopesStack, FocusScopeAPI, removeLinks } from './stack';\nimport {\n AUTOFOCUS_ON_MOUNT,\n AUTOFOCUS_ON_UNMOUNT,\n EVENT_OPTIONS,\n focus,\n focusFirst,\n getTabbableCandidates,\n getTabbableEdges\n} from './utils';\n\nexport interface FocusScopeContext {\n loop?: Signal<boolean>;\n\n trapped?: Signal<boolean>;\n}\n\nexport const [injectFocusScopeContext, provideFocusScopeContext] =\n createContext<FocusScopeContext>('FocusScope Context');\n\nconst rootContext = (): FocusScopeContext => {\n const context = inject(RdxFocusScope);\n\n return {\n loop: context.loop,\n trapped: context.trapped\n };\n};\n\n/**\n * @group Components\n */\n@Directive({\n selector: '[rdxFocusScope]',\n providers: [provideFocusScopeContext(rootContext)],\n host: {\n tabindex: '-1',\n '(keydown)': 'handleKeyDown($event)'\n }\n})\nexport class RdxFocusScope {\n private readonly injector = inject(Injector);\n\n private readonly elementRef = inject<ElementRef<HTMLElement>>(ElementRef);\n\n /**\n * When `true`, tabbing from last item will focus first tabbable\n * and shift+tab from first item will focus last tababble.\n *\n * @group Props\n * @defaultValue false\n */\n readonly loop = input<boolean, BooleanInput>(false, { transform: booleanAttribute });\n\n /**\n * When `true`, focus cannot escape the focus scope via keyboard,\n * pointer, or a programmatic focus.\n *\n * @group Props\n * @defaultValue false\n */\n readonly trapped = input<boolean, BooleanInput>(false, { transform: booleanAttribute });\n\n /**\n * Event handler called when auto-focusing on mount.\n * Can be prevented.\n *\n * @group Emits\n */\n readonly mountAutoFocus = output<Event>();\n\n /**\n * Event handler called when auto-focusing on unmount.\n * Can be prevented.\n *\n * @group Emits\n */\n readonly unmountAutoFocus = output<Event>();\n\n readonly lastFocusedElement = signal<HTMLElement | null>(null);\n\n private readonly focusScopesStack = createFocusScopesStack();\n\n readonly focusScope: FocusScopeAPI = {\n paused: signal(false),\n pause: () => this.focusScope.paused.set(true),\n resume: () => this.focusScope.paused.set(false)\n };\n\n constructor() {\n afterNextRender(() => {\n effect(\n (onCleanup) => {\n const container = this.elementRef.nativeElement;\n\n if (this.trapped()) {\n const handleFocusIn = (event: FocusEvent) => {\n if (this.focusScope.paused() || !container) {\n return;\n }\n\n const target = event.target as HTMLElement | null;\n if (this.elementRef.nativeElement.contains(target)) {\n this.lastFocusedElement.set(target);\n } else {\n focus(this.lastFocusedElement(), { select: true });\n }\n };\n\n const handleFocusOut = (event: FocusEvent) => {\n if (this.focusScope.paused() || !container) {\n return;\n }\n const relatedTarget = event.relatedTarget as HTMLElement | null;\n\n // A `focusout` event with a `null` `relatedTarget` will happen in at least two cases:\n //\n // 1. When the user switches app/tabs/windows/the browser itself loses focus.\n // 2. In Google Chrome, when the focused element is removed from the DOM.\n //\n // We let the browser do its thing here because:\n //\n // 1. The browser already keeps a memory of what's focused for when the page gets refocused.\n // 2. In Google Chrome, if we try to focus the deleted focused element (as per below), it\n // throws the CPU to 100%, so we avoid doing anything for this reason here too.\n if (relatedTarget === null) return;\n\n // If the focus has moved to an actual legitimate element (`relatedTarget !== null`)\n // that is outside the container, we move focus to the last valid focused element inside.\n if (!container.contains(relatedTarget)) {\n focus(this.lastFocusedElement(), { select: true });\n }\n };\n\n const handleMutations = () => {\n const isLastFocusedElementExist = container.contains(this.lastFocusedElement());\n\n if (!isLastFocusedElementExist) {\n focus(container);\n }\n };\n\n const mutationObserver = new MutationObserver(handleMutations);\n if (container) {\n mutationObserver.observe(container, { childList: true, subtree: true });\n }\n\n document.addEventListener('focusin', handleFocusIn);\n document.addEventListener('focusout', handleFocusOut);\n\n onCleanup(() => {\n document.removeEventListener('focusin', handleFocusIn);\n document.removeEventListener('focusout', handleFocusOut);\n mutationObserver.disconnect();\n });\n }\n },\n { injector: this.injector }\n );\n\n effect(\n async (onCleanup) => {\n const container = this.elementRef.nativeElement;\n\n await Promise.resolve();\n if (!container) {\n return;\n }\n\n this.focusScopesStack.add(this.focusScope);\n\n const previouslyFocusedElement = getActiveElement() as HTMLElement | null;\n const hasFocusedCandidate = container.contains(previouslyFocusedElement);\n\n if (!hasFocusedCandidate) {\n const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);\n container.addEventListener(AUTOFOCUS_ON_MOUNT, (ev: Event) => this.mountAutoFocus.emit(ev));\n container.dispatchEvent(mountEvent);\n\n if (!mountEvent.defaultPrevented) {\n focusFirst(removeLinks(getTabbableCandidates(container)), {\n select: true\n });\n if (getActiveElement() === previouslyFocusedElement) focus(container);\n }\n }\n\n onCleanup(() => {\n container.removeEventListener(AUTOFOCUS_ON_MOUNT, (ev: Event) => this.mountAutoFocus.emit(ev));\n\n const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);\n const unmountEventHandler = (ev: Event) => this.unmountAutoFocus.emit(ev);\n container.addEventListener(AUTOFOCUS_ON_UNMOUNT, unmountEventHandler);\n container.dispatchEvent(unmountEvent);\n\n setTimeout(() => {\n if (!unmountEvent.defaultPrevented)\n focus(previouslyFocusedElement ?? document.body, { select: true });\n\n // we need to remove the listener after we `dispatchEvent`\n container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, unmountEventHandler);\n\n this.focusScopesStack.remove(this.focusScope);\n }, 0);\n });\n },\n { injector: this.injector }\n );\n });\n }\n\n handleKeyDown(event: KeyboardEvent) {\n const isTabKey = event.key === 'Tab' && !event.altKey && !event.ctrlKey && !event.metaKey;\n\n const focusedElement = getActiveElement() as HTMLElement | null;\n\n if (isTabKey && focusedElement) {\n const container = event.currentTarget as HTMLElement;\n\n const [first, last] = getTabbableEdges(container);\n const hasTabbableElementsInside = first && last;\n\n // we can only wrap focus if we have tabbable edges\n if (!hasTabbableElementsInside) {\n if (focusedElement === container) event.preventDefault();\n } else {\n if (!event.shiftKey && focusedElement === last) {\n event.preventDefault();\n if (this.loop()) {\n focus(first, { select: true });\n }\n } else if (event.shiftKey && focusedElement === first) {\n event.preventDefault();\n if (this.loop()) {\n focus(last, { select: true });\n }\n }\n }\n }\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAEM,SAAU,iBAAiB,CAAI,OAAgB,EAAA;AACjD,IAAA,MAAM,KAAK,GAAG,OAAO,EAAE;AACvB,IAAA,OAAO,MAAM,KAAK;AACtB;AAQA,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,MAAM,MAAM,CAAkB,EAAE,CAAC,CAAC;SAE/D,sBAAsB,GAAA;;AAElC,IAAA,MAAM,KAAK,GAAG,kBAAkB,EAAE;IAElC,OAAO;AACH,QAAA,GAAG,CAAC,UAAyB,EAAA;AACzB,YAAA,MAAM,OAAO,GAAG,KAAK,EAAE;AACvB,YAAA,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;AACzB,YAAA,IAAI,UAAU,KAAK,MAAM,EAAE;gBACvB,MAAM,EAAE,KAAK,EAAE;;YAEnB,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,EAAE,UAAU,CAAC;AAChD,YAAA,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;AAC3B,YAAA,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;SACrB;AAED,QAAA,MAAM,CAAC,UAAyB,EAAA;AAC5B,YAAA,MAAM,OAAO,GAAG,KAAK,EAAE;YACvB,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,EAAE,UAAU,CAAC;AAChD,YAAA,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;;AAElB,YAAA,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE;;KAE3B;AACL;AAEgB,S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B,IAAI,KAAK,CAAC,QAAQ,IAAI,cAAc,KAAK,KAAK,EAAE;oBACnD,KAAK,CAAC,cAAc,EAAE;AACtB,oBAAA,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE;wBACb,KAAK,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;;;;;;8GAlMxC,aAAa,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA,CAAA;AAAb,IAAA,SAAA,IAAA,CAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,IAAA,EAAA,aAAa,ifANX,CAAC,wBAAwB,CAAC,WAAW,CAAC,CAAC,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA,CAAA;;2FAMzC,aAAa,EAAA,UAAA,EAAA,CAAA;kBARzB,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACP,oBAAA,QAAQ,EAAE,iBAAiB;AAC3B,oBAAA,SAAS,EAAE,CAAC,wBAAwB,CAAC,WAAW,CAAC,CAAC;AAClD,oBAAA,IAAI,EAAE;AACF,wBAAA,QAAQ,EAAE,IAAI;AACd,wBAAA,WAAW,EAAE;AAChB;AACJ,iBAAA;;;ACtDD;;AAEG;;;;"}
|
@@ -0,0 +1 @@
|
|
1
|
+
# @radix-ng/primitives/focus-scope
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './src/focus-scope';
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { BooleanInput } from '@angular/cdk/coercion';
|
2
|
+
import { Signal } from '@angular/core';
|
3
|
+
import { FocusScopeAPI } from './stack';
|
4
|
+
import * as i0 from "@angular/core";
|
5
|
+
export interface FocusScopeContext {
|
6
|
+
loop?: Signal<boolean>;
|
7
|
+
trapped?: Signal<boolean>;
|
8
|
+
}
|
9
|
+
export declare const injectFocusScopeContext: (optional?: boolean) => FocusScopeContext | null, provideFocusScopeContext: (useFactory: () => FocusScopeContext) => import("@angular/core").Provider;
|
10
|
+
/**
|
11
|
+
* @group Components
|
12
|
+
*/
|
13
|
+
export declare class RdxFocusScope {
|
14
|
+
private readonly injector;
|
15
|
+
private readonly elementRef;
|
16
|
+
/**
|
17
|
+
* When `true`, tabbing from last item will focus first tabbable
|
18
|
+
* and shift+tab from first item will focus last tababble.
|
19
|
+
*
|
20
|
+
* @group Props
|
21
|
+
* @defaultValue false
|
22
|
+
*/
|
23
|
+
readonly loop: import("@angular/core").InputSignalWithTransform<boolean, BooleanInput>;
|
24
|
+
/**
|
25
|
+
* When `true`, focus cannot escape the focus scope via keyboard,
|
26
|
+
* pointer, or a programmatic focus.
|
27
|
+
*
|
28
|
+
* @group Props
|
29
|
+
* @defaultValue false
|
30
|
+
*/
|
31
|
+
readonly trapped: import("@angular/core").InputSignalWithTransform<boolean, BooleanInput>;
|
32
|
+
/**
|
33
|
+
* Event handler called when auto-focusing on mount.
|
34
|
+
* Can be prevented.
|
35
|
+
*
|
36
|
+
* @group Emits
|
37
|
+
*/
|
38
|
+
readonly mountAutoFocus: import("@angular/core").OutputEmitterRef<Event>;
|
39
|
+
/**
|
40
|
+
* Event handler called when auto-focusing on unmount.
|
41
|
+
* Can be prevented.
|
42
|
+
*
|
43
|
+
* @group Emits
|
44
|
+
*/
|
45
|
+
readonly unmountAutoFocus: import("@angular/core").OutputEmitterRef<Event>;
|
46
|
+
readonly lastFocusedElement: import("@angular/core").WritableSignal<HTMLElement | null>;
|
47
|
+
private readonly focusScopesStack;
|
48
|
+
readonly focusScope: FocusScopeAPI;
|
49
|
+
constructor();
|
50
|
+
handleKeyDown(event: KeyboardEvent): void;
|
51
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RdxFocusScope, never>;
|
52
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<RdxFocusScope, "[rdxFocusScope]", never, { "loop": { "alias": "loop"; "required": false; "isSignal": true; }; "trapped": { "alias": "trapped"; "required": false; "isSignal": true; }; }, { "mountAutoFocus": "mountAutoFocus"; "unmountAutoFocus": "unmountAutoFocus"; }, never, never, true, never>;
|
53
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { WritableSignal } from '@angular/core';
|
2
|
+
export declare function createGlobalState<T>(factory: () => T): () => T;
|
3
|
+
export interface FocusScopeAPI {
|
4
|
+
paused: WritableSignal<boolean>;
|
5
|
+
pause(): void;
|
6
|
+
resume(): void;
|
7
|
+
}
|
8
|
+
export declare function createFocusScopesStack(): {
|
9
|
+
add(focusScope: FocusScopeAPI): void;
|
10
|
+
remove(focusScope: FocusScopeAPI): void;
|
11
|
+
};
|
12
|
+
export declare function arrayRemove<T>(array: T[], item: T): T[];
|
13
|
+
export declare function removeLinks(items: HTMLElement[]): HTMLElement[];
|
@@ -0,0 +1,46 @@
|
|
1
|
+
export declare const AUTOFOCUS_ON_MOUNT = "focusScope.autoFocusOnMount";
|
2
|
+
export declare const AUTOFOCUS_ON_UNMOUNT = "focusScope.autoFocusOnUnmount";
|
3
|
+
export declare const EVENT_OPTIONS: {
|
4
|
+
bubbles: boolean;
|
5
|
+
cancelable: boolean;
|
6
|
+
};
|
7
|
+
type FocusableTarget = HTMLElement | {
|
8
|
+
focus: () => void;
|
9
|
+
};
|
10
|
+
/**
|
11
|
+
* Attempts focusing the first element in a list of candidates.
|
12
|
+
* Stops when focus has actually moved.
|
13
|
+
*/
|
14
|
+
export declare function focusFirst(candidates: HTMLElement[], { select }?: {
|
15
|
+
select?: boolean | undefined;
|
16
|
+
}): true | undefined;
|
17
|
+
/**
|
18
|
+
* Returns a list of potential tabbable candidates.
|
19
|
+
*
|
20
|
+
* NOTE: This is only a close approximation. For example it doesn't take into account cases like when
|
21
|
+
* elements are not visible. This cannot be worked out easily by just reading a property, but rather
|
22
|
+
* necessitate runtime knowledge (computed styles, etc). We deal with these cases separately.
|
23
|
+
*
|
24
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
|
25
|
+
* Credit: https://github.com/discord/focus-layers/blob/master/src/util/wrapFocus.tsx#L1
|
26
|
+
*/
|
27
|
+
export declare function getTabbableCandidates(container: HTMLElement): HTMLElement[];
|
28
|
+
export declare function isHidden(node: HTMLElement, { upTo }: {
|
29
|
+
upTo?: HTMLElement;
|
30
|
+
}): boolean;
|
31
|
+
/**
|
32
|
+
* Returns the first visible element in a list.
|
33
|
+
* NOTE: Only checks visibility up to the `container`.
|
34
|
+
*/
|
35
|
+
export declare function findVisible(elements: HTMLElement[], container: HTMLElement): HTMLElement | undefined;
|
36
|
+
/**
|
37
|
+
* Returns the first and last tabbable elements inside a container.
|
38
|
+
*/
|
39
|
+
export declare function getTabbableEdges(container: HTMLElement): readonly [HTMLElement | undefined, HTMLElement | undefined];
|
40
|
+
export declare function isSelectableInput(element: any): element is FocusableTarget & {
|
41
|
+
select: () => void;
|
42
|
+
};
|
43
|
+
export declare function focus(element?: FocusableTarget | null, { select }?: {
|
44
|
+
select?: boolean | undefined;
|
45
|
+
}): void;
|
46
|
+
export {};
|
@@ -93,7 +93,7 @@ export declare class RdxHoverCardRootDirective {
|
|
93
93
|
window: Window & typeof globalThis;
|
94
94
|
primitiveConfigs?: import("./utils/types").PrimitiveConfigs;
|
95
95
|
onDestroyCallbacks: Set<() => void>;
|
96
|
-
"__#
|
96
|
+
"__#14839@#clickDomRootEventCallbacks": Set<(event: MouseEvent) => void>;
|
97
97
|
registerPrimitive<T extends object>(primitiveInstance: T): void;
|
98
98
|
deregisterPrimitive<T extends object>(primitiveInstance: T): void;
|
99
99
|
preventPrimitiveFromCdkEvent<T extends object>(primitiveInstance: T, eventType: import("./utils/types").EventType): void;
|
@@ -104,9 +104,9 @@ export declare class RdxHoverCardRootDirective {
|
|
104
104
|
primitivePreventedFromCdkEvent<T extends object>(primitiveInstance: T, eventType: import("./utils/types").EventType): boolean | undefined;
|
105
105
|
addClickDomRootEventCallback(callback: (event: MouseEvent) => void): void;
|
106
106
|
removeClickDomRootEventCallback(callback: (event: MouseEvent) => void): boolean;
|
107
|
-
"__#
|
108
|
-
"__#
|
109
|
-
"__#
|
107
|
+
"__#14839@#setPreventPrimitiveFromCdkEvent"<T extends object, R extends import("./utils/types").EventType, K extends import("./utils/types").PrimitiveConfig[`prevent${Capitalize<R>}`]>(primitiveInstance: T, eventType: R, value: K): void;
|
108
|
+
"__#14839@#registerOnDestroyCallbacks"(): void;
|
109
|
+
"__#14839@#listenToClickDomRootEvent"(): void;
|
110
110
|
} | null;
|
111
111
|
/** @ignore */
|
112
112
|
readonly destroyRef: DestroyRef;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@radix-ng/primitives",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.42.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
@@ -100,6 +100,10 @@
|
|
100
100
|
"types": "./editable/index.d.ts",
|
101
101
|
"default": "./fesm2022/radix-ng-primitives-editable.mjs"
|
102
102
|
},
|
103
|
+
"./focus-scope": {
|
104
|
+
"types": "./focus-scope/index.d.ts",
|
105
|
+
"default": "./fesm2022/radix-ng-primitives-focus-scope.mjs"
|
106
|
+
},
|
103
107
|
"./hover-card": {
|
104
108
|
"types": "./hover-card/index.d.ts",
|
105
109
|
"default": "./fesm2022/radix-ng-primitives-hover-card.mjs"
|
@@ -70,7 +70,7 @@ export declare class RdxPopoverRootDirective {
|
|
70
70
|
window: Window & typeof globalThis;
|
71
71
|
primitiveConfigs?: import("./utils/types").PrimitiveConfigs;
|
72
72
|
onDestroyCallbacks: Set<() => void>;
|
73
|
-
"__#
|
73
|
+
"__#19150@#clickDomRootEventCallbacks": Set<(event: MouseEvent) => void>;
|
74
74
|
registerPrimitive<T extends object>(primitiveInstance: T): void;
|
75
75
|
deregisterPrimitive<T extends object>(primitiveInstance: T): void;
|
76
76
|
preventPrimitiveFromCdkEvent<T extends object>(primitiveInstance: T, eventType: import("./utils/types").EventType): void;
|
@@ -81,9 +81,9 @@ export declare class RdxPopoverRootDirective {
|
|
81
81
|
primitivePreventedFromCdkEvent<T extends object>(primitiveInstance: T, eventType: import("./utils/types").EventType): boolean | undefined;
|
82
82
|
addClickDomRootEventCallback(callback: (event: MouseEvent) => void): void;
|
83
83
|
removeClickDomRootEventCallback(callback: (event: MouseEvent) => void): boolean;
|
84
|
-
"__#
|
85
|
-
"__#
|
86
|
-
"__#
|
84
|
+
"__#19150@#setPreventPrimitiveFromCdkEvent"<T extends object, R extends import("./utils/types").EventType, K extends import("./utils/types").PrimitiveConfig[`prevent${Capitalize<R>}`]>(primitiveInstance: T, eventType: R, value: K): void;
|
85
|
+
"__#19150@#registerOnDestroyCallbacks"(): void;
|
86
|
+
"__#19150@#listenToClickDomRootEvent"(): void;
|
87
87
|
} | null;
|
88
88
|
/** @ignore */
|
89
89
|
readonly destroyRef: DestroyRef;
|
@@ -79,7 +79,7 @@ export declare class RdxTooltipRootDirective {
|
|
79
79
|
window: Window & typeof globalThis;
|
80
80
|
primitiveConfigs?: import("./utils/types").PrimitiveConfigs;
|
81
81
|
onDestroyCallbacks: Set<() => void>;
|
82
|
-
"__#
|
82
|
+
"__#22995@#clickDomRootEventCallbacks": Set<(event: MouseEvent) => void>;
|
83
83
|
registerPrimitive<T extends object>(primitiveInstance: T): void;
|
84
84
|
deregisterPrimitive<T extends object>(primitiveInstance: T): void;
|
85
85
|
preventPrimitiveFromCdkEvent<T extends object>(primitiveInstance: T, eventType: import("./utils/types").EventType): void;
|
@@ -90,9 +90,9 @@ export declare class RdxTooltipRootDirective {
|
|
90
90
|
primitivePreventedFromCdkEvent<T extends object>(primitiveInstance: T, eventType: import("./utils/types").EventType): boolean | undefined;
|
91
91
|
addClickDomRootEventCallback(callback: (event: MouseEvent) => void): void;
|
92
92
|
removeClickDomRootEventCallback(callback: (event: MouseEvent) => void): boolean;
|
93
|
-
"__#
|
94
|
-
"__#
|
95
|
-
"__#
|
93
|
+
"__#22995@#setPreventPrimitiveFromCdkEvent"<T extends object, R extends import("./utils/types").EventType, K extends import("./utils/types").PrimitiveConfig[`prevent${Capitalize<R>}`]>(primitiveInstance: T, eventType: R, value: K): void;
|
94
|
+
"__#22995@#registerOnDestroyCallbacks"(): void;
|
95
|
+
"__#22995@#listenToClickDomRootEvent"(): void;
|
96
96
|
} | null;
|
97
97
|
/** @ignore */
|
98
98
|
readonly destroyRef: DestroyRef;
|