@nanahoshi/mona-ui 0.24.7 → 0.24.9
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/nanahoshi-mona-ui-auto-complete.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-button-group.mjs +37 -9
- package/fesm2022/nanahoshi-mona-ui-button.mjs +8 -2
- package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +4 -3
- package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +101 -47
- package/fesm2022/nanahoshi-mona-ui-dialog.mjs +339 -101
- package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +119 -69
- package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-editor.mjs +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-vXXNWmEN.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DhKLnW06.mjs} +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-DDgNmgE0.mjs → nanahoshi-mona-ui-grid-grid-list.component-voGbKOiB.mjs} +4 -4
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-Dzf6Vbs_.mjs → nanahoshi-mona-ui-grid-grid-row.component-HQ1Kv6R9.mjs} +2 -3
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-DAPNqnWV.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-PNLJFcuH.mjs} +4 -4
- package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-B9rmDLq8.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BO19AVwC.mjs} +10 -10
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +44 -3
- package/fesm2022/nanahoshi-mona-ui-internal-filter-input.mjs +20 -4
- package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +335 -45
- package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +565 -197
- package/fesm2022/nanahoshi-mona-ui-internal.mjs +465 -23
- package/fesm2022/nanahoshi-mona-ui-list-box.mjs +598 -208
- package/fesm2022/nanahoshi-mona-ui-list-view.mjs +193 -71
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +33 -3
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +33 -3
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +40 -3
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +33 -3
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +33 -3
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +49 -3
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +29 -3
- package/fesm2022/nanahoshi-mona-ui-menubar.mjs +127 -133
- package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-notification.mjs +473 -240
- package/fesm2022/nanahoshi-mona-ui-popover.mjs +202 -90
- package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +609 -256
- package/fesm2022/nanahoshi-mona-ui-popup.mjs +2 -0
- package/fesm2022/nanahoshi-mona-ui-sheet.mjs +45 -10
- package/fesm2022/nanahoshi-mona-ui-split-button.mjs +102 -58
- package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +286 -443
- package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +205 -140
- package/fesm2022/nanahoshi-mona-ui-window.mjs +591 -310
- package/i18n/catalogs/en-US.messages.json +32 -6
- package/locales/ar-sa/ar-sa.messages.json +29 -3
- package/locales/de-de/de-de.messages.json +29 -3
- package/locales/es-es/es-es.messages.json +29 -3
- package/locales/fr-fr/fr-fr.messages.json +29 -3
- package/locales/id-id/id-id.messages.json +29 -3
- package/locales/it-it/it-it.messages.json +29 -3
- package/locales/ja-jp/ja-jp.messages.json +29 -3
- package/locales/ko-kr/ko-kr.messages.json +29 -3
- package/locales/pt-br/pt-br.messages.json +29 -3
- package/locales/ru-ru/ru-ru.messages.json +29 -3
- package/locales/tr-tr/tr-tr.messages.json +29 -3
- package/locales/zh-cn/zh-cn.messages.json +29 -3
- package/locales/zh-tw/zh-tw.messages.json +29 -3
- package/package.json +1 -1
- package/types/nanahoshi-mona-ui-button-group.d.ts +13 -3
- package/types/nanahoshi-mona-ui-button.d.ts +20 -3
- package/types/nanahoshi-mona-ui-contextmenu.d.ts +5 -6
- package/types/nanahoshi-mona-ui-dialog.d.ts +131 -20
- package/types/nanahoshi-mona-ui-dropdown-button.d.ts +75 -56
- package/types/nanahoshi-mona-ui-i18n.d.ts +69 -0
- package/types/nanahoshi-mona-ui-internal-filter-input.d.ts +14 -2
- package/types/nanahoshi-mona-ui-internal-list.d.ts +89 -10
- package/types/nanahoshi-mona-ui-internal-tree.d.ts +155 -40
- package/types/nanahoshi-mona-ui-internal.d.ts +128 -16
- package/types/nanahoshi-mona-ui-list-box.d.ts +148 -47
- package/types/nanahoshi-mona-ui-list-view.d.ts +112 -21
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +26 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +26 -0
- package/types/nanahoshi-mona-ui-menubar.d.ts +65 -62
- package/types/nanahoshi-mona-ui-notification.d.ts +76 -16
- package/types/nanahoshi-mona-ui-popover.d.ts +44 -17
- package/types/nanahoshi-mona-ui-popup-menu.d.ts +110 -32
- package/types/nanahoshi-mona-ui-popup.d.ts +2 -0
- package/types/nanahoshi-mona-ui-sheet.d.ts +16 -5
- package/types/nanahoshi-mona-ui-split-button.d.ts +29 -7
- package/types/nanahoshi-mona-ui-tooltip.d.ts +43 -20
- package/types/nanahoshi-mona-ui-tree-view.d.ts +84 -40
- package/types/nanahoshi-mona-ui-window.d.ts +103 -14
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, ElementRef, Renderer2, input, effect, Directive } from '@angular/core';
|
|
2
|
+
import { inject, ElementRef, Renderer2, input, effect, Directive, DOCUMENT, signal, afterEveryRender, untracked } from '@angular/core';
|
|
3
|
+
import { GlobalPositionStrategy, ConnectionPositionPair } from '@angular/cdk/overlay';
|
|
3
4
|
import { forEach } from '@mirei/ts-collections';
|
|
4
5
|
import { Observable, timer, take, debounceTime, map, merge, scan, filter } from 'rxjs';
|
|
5
6
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
@@ -220,6 +221,29 @@ const string2rgba = (rgbText) => {
|
|
|
220
221
|
return { r: 0, g: 0, b: 0, a: 255 };
|
|
221
222
|
};
|
|
222
223
|
|
|
224
|
+
const tokensOf = (element, attribute) => (element.getAttribute(attribute) ?? "").split(/\s+/).filter(token => token !== "");
|
|
225
|
+
/**
|
|
226
|
+
* Adds `id` to an id-list attribute such as `aria-describedby`, keeping the ids already there.
|
|
227
|
+
*/
|
|
228
|
+
const addAriaReference = (element, attribute, id) => {
|
|
229
|
+
const tokens = tokensOf(element, attribute);
|
|
230
|
+
if (!tokens.includes(id)) {
|
|
231
|
+
element.setAttribute(attribute, [...tokens, id].join(" "));
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Removes `id` from an id-list attribute, and the attribute itself once it holds no ids.
|
|
236
|
+
*/
|
|
237
|
+
const removeAriaReference = (element, attribute, id) => {
|
|
238
|
+
const tokens = tokensOf(element, attribute).filter(token => token !== id);
|
|
239
|
+
if (tokens.length) {
|
|
240
|
+
element.setAttribute(attribute, tokens.join(" "));
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
element.removeAttribute(attribute);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
223
247
|
/**
|
|
224
248
|
* Generates a unique control ID for an element.
|
|
225
249
|
* The ID consists of the `mona-` prefix followed by a random hexadecimal string.
|
|
@@ -276,6 +300,124 @@ function focusElement(host, element) {
|
|
|
276
300
|
}
|
|
277
301
|
}
|
|
278
302
|
|
|
303
|
+
/**
|
|
304
|
+
* How many open modal overlays made each element inert. An element is made inert by the first and released by the
|
|
305
|
+
* last, so closing one of two stacked modals leaves the page behind the other one inert.
|
|
306
|
+
*/
|
|
307
|
+
const inertCounts = new WeakMap();
|
|
308
|
+
/** Elements left alone: they hold no content, or announce for everyone (live regions, CDK's live announcer). */
|
|
309
|
+
const isExempt = (element) => element instanceof HTMLScriptElement ||
|
|
310
|
+
element instanceof HTMLStyleElement ||
|
|
311
|
+
element instanceof HTMLTemplateElement ||
|
|
312
|
+
element.hasAttribute("aria-live") ||
|
|
313
|
+
element.classList.contains("cdk-overlay-backdrop");
|
|
314
|
+
/**
|
|
315
|
+
* Makes everything outside a modal overlay inert, so assistive technology, the pointer and Tab can't reach the page
|
|
316
|
+
* behind it. Walking up from `element` to `<body>`, every sibling is made inert, except that inside the CDK overlay
|
|
317
|
+
* container only the overlays opened before this one are: popups opened later (a dropdown inside the dialog) stay
|
|
318
|
+
* usable. Elements that were inert already are left as they are.
|
|
319
|
+
* @param element the overlay's host element (the CDK overlay wrapper)
|
|
320
|
+
* @returns the function that releases what this call made inert
|
|
321
|
+
*/
|
|
322
|
+
const inertOutside = (element) => {
|
|
323
|
+
const body = element.ownerDocument.body;
|
|
324
|
+
const acquired = [];
|
|
325
|
+
let node = element;
|
|
326
|
+
while (node && node !== body && node.parentElement) {
|
|
327
|
+
const parent = node.parentElement;
|
|
328
|
+
const onlyEarlier = parent.classList.contains("cdk-overlay-container");
|
|
329
|
+
for (const sibling of Array.from(parent.children)) {
|
|
330
|
+
if (sibling === node) {
|
|
331
|
+
if (onlyEarlier) {
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (isExempt(sibling)) {
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const count = inertCounts.get(sibling) ?? 0;
|
|
340
|
+
if (count === 0 && sibling.hasAttribute("inert")) {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
inertCounts.set(sibling, count + 1);
|
|
344
|
+
if (count === 0) {
|
|
345
|
+
sibling.setAttribute("inert", "");
|
|
346
|
+
}
|
|
347
|
+
acquired.push(sibling);
|
|
348
|
+
}
|
|
349
|
+
node = parent;
|
|
350
|
+
}
|
|
351
|
+
let released = false;
|
|
352
|
+
return () => {
|
|
353
|
+
if (released) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
released = true;
|
|
357
|
+
for (const sibling of acquired) {
|
|
358
|
+
const count = (inertCounts.get(sibling) ?? 1) - 1;
|
|
359
|
+
if (count <= 0) {
|
|
360
|
+
inertCounts.delete(sibling);
|
|
361
|
+
sibling.removeAttribute("inert");
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
inertCounts.set(sibling, count);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* The text of the elements an `aria-labelledby` value points to, joined with spaces, for names built from a
|
|
372
|
+
* component's name ("Filter {name}"). It's read after every render, so it follows the labelling elements' text.
|
|
373
|
+
* Call it in an injection context.
|
|
374
|
+
* @param ids Returns the space-separated element ids.
|
|
375
|
+
*/
|
|
376
|
+
function injectLabelledByText(ids) {
|
|
377
|
+
const document = inject(DOCUMENT);
|
|
378
|
+
const text = signal("", /* @ts-ignore */
|
|
379
|
+
...(ngDevMode ? [{ debugName: "text" }] : /* istanbul ignore next */ []));
|
|
380
|
+
afterEveryRender({
|
|
381
|
+
read: () => {
|
|
382
|
+
const value = ids()
|
|
383
|
+
.split(/\s+/)
|
|
384
|
+
.filter(id => id.length > 0)
|
|
385
|
+
.map(id => document.getElementById(id)?.textContent?.replace(/\s+/g, " ").trim() ?? "")
|
|
386
|
+
.filter(part => part.length > 0)
|
|
387
|
+
.join(" ");
|
|
388
|
+
if (value !== untracked(text)) {
|
|
389
|
+
text.set(value);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
return text.asReadonly();
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Places a global overlay through its position strategy, so later `updatePosition()` calls (a direction change, a
|
|
398
|
+
* resize) keep it where it is instead of resetting inline styles. Each axis is independent: a `top` alone keeps the
|
|
399
|
+
* overlay centered horizontally. Centering follows the overlay's size as it grows or shrinks.
|
|
400
|
+
*/
|
|
401
|
+
const positionGlobalOverlay = (overlayRef, position) => {
|
|
402
|
+
const strategy = overlayRef.getConfig().positionStrategy;
|
|
403
|
+
if (!(strategy instanceof GlobalPositionStrategy)) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
if (position.left != null) {
|
|
407
|
+
strategy.left(`${position.left}px`);
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
strategy.centerHorizontally();
|
|
411
|
+
}
|
|
412
|
+
if (position.top != null) {
|
|
413
|
+
strategy.top(`${position.top}px`);
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
strategy.centerVertically();
|
|
417
|
+
}
|
|
418
|
+
overlayRef.updatePosition();
|
|
419
|
+
};
|
|
420
|
+
|
|
279
421
|
const rxFromResize = (target, options) => {
|
|
280
422
|
return new Observable(observer => {
|
|
281
423
|
const elements = target instanceof Element ? [target] : Array.from(target ?? []);
|
|
@@ -325,6 +467,326 @@ const themeOverlaySurfaceClasses = `
|
|
|
325
467
|
${themeOverlayBackdropClasses}
|
|
326
468
|
`;
|
|
327
469
|
|
|
470
|
+
/**
|
|
471
|
+
* How long a popup opened by hovering waits after the pointer leaves its anchor, so the pointer can cross the gap
|
|
472
|
+
* onto the popup and stay there (WCAG 1.4.13, Content on Hover or Focus).
|
|
473
|
+
*/
|
|
474
|
+
const HOVER_GRACE = 100;
|
|
475
|
+
/**
|
|
476
|
+
* When to show and hide a popup that follows the pointer and focus, shared by the tooltip and the hover popover.
|
|
477
|
+
*
|
|
478
|
+
* - A show waits for `showDelay`, and leaving the anchor first cancels it.
|
|
479
|
+
* - The popup stays while the pointer is on the anchor or on the popup, or focus is on the anchor. Leaving waits for
|
|
480
|
+
* `hideDelay` (at least {@link HOVER_GRACE} for the pointer), and coming back cancels the hide.
|
|
481
|
+
* - Moving to another anchor replaces the popup.
|
|
482
|
+
* - After a dismissal (Escape), the popup stays closed until the pointer and focus have left that anchor.
|
|
483
|
+
*/
|
|
484
|
+
class HoverIntent {
|
|
485
|
+
#config;
|
|
486
|
+
#anchor = null;
|
|
487
|
+
#dismissed = null;
|
|
488
|
+
#focused = false;
|
|
489
|
+
#hideTimer = null;
|
|
490
|
+
#hovered = false;
|
|
491
|
+
#panelCleanup = null;
|
|
492
|
+
#panelHovered = false;
|
|
493
|
+
#pending = null;
|
|
494
|
+
#showTimer = null;
|
|
495
|
+
#tracked = null;
|
|
496
|
+
constructor(config) {
|
|
497
|
+
this.#config = config;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Reports that the popup for `anchor` started closing for a reason of its own (Escape, an outside click, being
|
|
501
|
+
* disabled). With `dismissed`, it stays closed until the pointer and focus have left the anchor.
|
|
502
|
+
*/
|
|
503
|
+
closed(anchor, dismissed = false) {
|
|
504
|
+
if (this.#anchor !== anchor) {
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (dismissed && (this.#hovered || this.#focused)) {
|
|
508
|
+
this.#dismissed = anchor;
|
|
509
|
+
}
|
|
510
|
+
this.#release();
|
|
511
|
+
}
|
|
512
|
+
/** Stops every timer and forgets every anchor, without closing anything. */
|
|
513
|
+
dispose() {
|
|
514
|
+
this.#clearShow();
|
|
515
|
+
this.#cancelHide();
|
|
516
|
+
this.#release();
|
|
517
|
+
this.#pending = null;
|
|
518
|
+
this.#tracked = null;
|
|
519
|
+
this.#dismissed = null;
|
|
520
|
+
}
|
|
521
|
+
/** The pointer moved onto `anchor`, or focus moved into it. */
|
|
522
|
+
enter(anchor, source) {
|
|
523
|
+
if (anchor !== this.#tracked) {
|
|
524
|
+
this.#tracked = anchor;
|
|
525
|
+
this.#hovered = false;
|
|
526
|
+
this.#focused = false;
|
|
527
|
+
}
|
|
528
|
+
this.#setActive(source, true);
|
|
529
|
+
if (this.#dismissed === anchor) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
this.#dismissed = null;
|
|
533
|
+
this.#cancelHide();
|
|
534
|
+
if (this.#anchor === anchor || this.#pending === anchor) {
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
this.#clearShow();
|
|
538
|
+
this.#pending = anchor;
|
|
539
|
+
const delay = this.#config.showDelay();
|
|
540
|
+
if (delay > 0) {
|
|
541
|
+
this.#showTimer = setTimeout(() => this.#show(anchor), delay);
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
this.#show(anchor);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
/** Hides the popup now, as leaving would, and cancels a pending show. */
|
|
548
|
+
hideNow() {
|
|
549
|
+
this.#clearShow();
|
|
550
|
+
this.#pending = null;
|
|
551
|
+
this.#cancelHide();
|
|
552
|
+
if (this.#anchor) {
|
|
553
|
+
this.#release();
|
|
554
|
+
this.#config.hide();
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
/** The pointer left `anchor`, or focus left it. */
|
|
558
|
+
leave(anchor, source) {
|
|
559
|
+
if (anchor !== this.#tracked) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
this.#setActive(source, false);
|
|
563
|
+
if (this.#hovered || this.#focused) {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
if (this.#dismissed === anchor) {
|
|
567
|
+
this.#dismissed = null;
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
if (this.#pending === anchor) {
|
|
571
|
+
this.#clearShow();
|
|
572
|
+
this.#pending = null;
|
|
573
|
+
}
|
|
574
|
+
if (this.#anchor === anchor && !this.#panelHovered) {
|
|
575
|
+
this.#scheduleHide(source);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Reports that the popup for `anchor` is open. While the pointer is on `panel`, the popup stays.
|
|
580
|
+
*/
|
|
581
|
+
opened(anchor, panel) {
|
|
582
|
+
this.#release();
|
|
583
|
+
this.#anchor = anchor;
|
|
584
|
+
if (!panel) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const enter = (event) => {
|
|
588
|
+
if (event.pointerType === "touch") {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
this.#panelHovered = true;
|
|
592
|
+
this.#cancelHide();
|
|
593
|
+
};
|
|
594
|
+
const leave = (event) => {
|
|
595
|
+
if (event.pointerType === "touch") {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
this.#panelHovered = false;
|
|
599
|
+
if (this.#anchor === anchor && !this.#hovered && !this.#focused) {
|
|
600
|
+
this.#scheduleHide("pointer");
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
panel.addEventListener("pointerenter", enter);
|
|
604
|
+
panel.addEventListener("pointerleave", leave);
|
|
605
|
+
this.#panelCleanup = () => {
|
|
606
|
+
panel.removeEventListener("pointerenter", enter);
|
|
607
|
+
panel.removeEventListener("pointerleave", leave);
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
#cancelHide() {
|
|
611
|
+
if (this.#hideTimer != null) {
|
|
612
|
+
clearTimeout(this.#hideTimer);
|
|
613
|
+
this.#hideTimer = null;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
#clearShow() {
|
|
617
|
+
if (this.#showTimer != null) {
|
|
618
|
+
clearTimeout(this.#showTimer);
|
|
619
|
+
this.#showTimer = null;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
#release() {
|
|
623
|
+
this.#panelCleanup?.();
|
|
624
|
+
this.#panelCleanup = null;
|
|
625
|
+
this.#panelHovered = false;
|
|
626
|
+
this.#anchor = null;
|
|
627
|
+
this.#cancelHide();
|
|
628
|
+
}
|
|
629
|
+
#scheduleHide(source) {
|
|
630
|
+
this.#cancelHide();
|
|
631
|
+
const delay = Math.max(this.#config.hideDelay(), source === "pointer" ? HOVER_GRACE : 0);
|
|
632
|
+
const hide = () => {
|
|
633
|
+
this.#hideTimer = null;
|
|
634
|
+
if (this.#anchor) {
|
|
635
|
+
this.#release();
|
|
636
|
+
this.#config.hide();
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
if (delay > 0) {
|
|
640
|
+
this.#hideTimer = setTimeout(hide, delay);
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
hide();
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
#setActive(source, active) {
|
|
647
|
+
if (source === "pointer") {
|
|
648
|
+
this.#hovered = active;
|
|
649
|
+
}
|
|
650
|
+
else {
|
|
651
|
+
this.#focused = active;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
#show(anchor) {
|
|
655
|
+
this.#showTimer = null;
|
|
656
|
+
this.#pending = null;
|
|
657
|
+
if (this.#anchor && this.#anchor !== anchor) {
|
|
658
|
+
this.#release();
|
|
659
|
+
this.#config.hide();
|
|
660
|
+
}
|
|
661
|
+
this.#config.show(anchor);
|
|
662
|
+
}
|
|
663
|
+
/** The anchor whose popup is open, if any. */
|
|
664
|
+
get anchor() {
|
|
665
|
+
return this.#anchor;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Feeds a {@link HoverIntent} from pointer and focus events delegated on `root`, so anchors added, removed or
|
|
670
|
+
* re-rendered later need no listeners of their own. Touch pointers are ignored: a tap that focuses the anchor shows
|
|
671
|
+
* the popup through focus instead, and it isn't hidden again by the pointer leaving after the tap.
|
|
672
|
+
* @param resolve the anchor an event target belongs to, or `null`
|
|
673
|
+
* @returns the function that removes the listeners
|
|
674
|
+
*/
|
|
675
|
+
const listenForHover = (root, resolve, intent) => {
|
|
676
|
+
const anchorOf = (target) => target instanceof Element ? resolve(target) : null;
|
|
677
|
+
const stillInside = (anchor, to) => to instanceof Node && anchor.contains(to);
|
|
678
|
+
const over = (event) => {
|
|
679
|
+
if (event.pointerType === "touch") {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
const anchor = anchorOf(event.target);
|
|
683
|
+
if (anchor) {
|
|
684
|
+
intent.enter(anchor, "pointer");
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
const out = (event) => {
|
|
688
|
+
if (event.pointerType === "touch") {
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
const anchor = anchorOf(event.target);
|
|
692
|
+
if (anchor && !stillInside(anchor, event.relatedTarget)) {
|
|
693
|
+
intent.leave(anchor, "pointer");
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
const focusIn = (event) => {
|
|
697
|
+
const anchor = anchorOf(event.target);
|
|
698
|
+
if (anchor) {
|
|
699
|
+
intent.enter(anchor, "focus");
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
const focusOut = (event) => {
|
|
703
|
+
const anchor = anchorOf(event.target);
|
|
704
|
+
if (anchor && !stillInside(anchor, event.relatedTarget)) {
|
|
705
|
+
intent.leave(anchor, "focus");
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
root.addEventListener("pointerover", over);
|
|
709
|
+
root.addEventListener("pointerout", out);
|
|
710
|
+
root.addEventListener("focusin", focusIn);
|
|
711
|
+
root.addEventListener("focusout", focusOut);
|
|
712
|
+
return () => {
|
|
713
|
+
root.removeEventListener("pointerover", over);
|
|
714
|
+
root.removeEventListener("pointerout", out);
|
|
715
|
+
root.removeEventListener("focusin", focusIn);
|
|
716
|
+
root.removeEventListener("focusout", focusOut);
|
|
717
|
+
};
|
|
718
|
+
};
|
|
719
|
+
/**
|
|
720
|
+
* Calls `callback` once `element` leaves the document, for a popup that would otherwise stay anchored to nothing.
|
|
721
|
+
* @returns the function that stops watching
|
|
722
|
+
*/
|
|
723
|
+
const onDisconnect = (element, callback) => {
|
|
724
|
+
const view = element.ownerDocument.defaultView;
|
|
725
|
+
if (!view?.MutationObserver) {
|
|
726
|
+
return () => undefined;
|
|
727
|
+
}
|
|
728
|
+
const observer = new view.MutationObserver(() => {
|
|
729
|
+
if (!element.isConnected) {
|
|
730
|
+
observer.disconnect();
|
|
731
|
+
callback();
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
observer.observe(element.ownerDocument.body, { childList: true, subtree: true });
|
|
735
|
+
return () => observer.disconnect();
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
const OPPOSITE = {
|
|
739
|
+
bottom: "top",
|
|
740
|
+
left: "right",
|
|
741
|
+
right: "left",
|
|
742
|
+
top: "bottom"
|
|
743
|
+
};
|
|
744
|
+
const resolveOverlaySide = (side, direction) => {
|
|
745
|
+
if (side === "start") {
|
|
746
|
+
return direction === "rtl" ? "right" : "left";
|
|
747
|
+
}
|
|
748
|
+
if (side === "end") {
|
|
749
|
+
return direction === "rtl" ? "left" : "right";
|
|
750
|
+
}
|
|
751
|
+
return side;
|
|
752
|
+
};
|
|
753
|
+
const positionFor = (side, gap, direction) => {
|
|
754
|
+
// The overlay's start and end follow its direction, so a physical side is translated for RTL.
|
|
755
|
+
const left = direction === "rtl" ? "end" : "start";
|
|
756
|
+
const right = direction === "rtl" ? "start" : "end";
|
|
757
|
+
switch (side) {
|
|
758
|
+
case "top":
|
|
759
|
+
return new ConnectionPositionPair({ originX: "center", originY: "top" }, { overlayX: "center", overlayY: "bottom" }, 0, -gap);
|
|
760
|
+
case "bottom":
|
|
761
|
+
return new ConnectionPositionPair({ originX: "center", originY: "bottom" }, { overlayX: "center", overlayY: "top" }, 0, gap);
|
|
762
|
+
case "left":
|
|
763
|
+
return new ConnectionPositionPair({ originX: left, originY: "center" }, { overlayX: right, overlayY: "center" }, -gap, 0);
|
|
764
|
+
case "right":
|
|
765
|
+
return new ConnectionPositionPair({ originX: right, originY: "center" }, { overlayX: left, overlayY: "center" }, gap, 0);
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
/**
|
|
769
|
+
* Positions for a popup centered on `side` of its anchor, flipping to the opposite side when it doesn't fit. Each
|
|
770
|
+
* position carries its own offset, so the gap stays between the popup and its anchor after a flip.
|
|
771
|
+
* @param gap the distance between the anchor and the popup, in pixels
|
|
772
|
+
* @param direction the overlay's direction
|
|
773
|
+
*/
|
|
774
|
+
const overlaySidePositions = (side, gap, direction) => [positionFor(side, gap, direction), positionFor(OPPOSITE[side], gap, direction)];
|
|
775
|
+
/**
|
|
776
|
+
* The physical side of its anchor a popup ended up on, from the position the overlay chose.
|
|
777
|
+
*/
|
|
778
|
+
const sideOfPosition = (position, direction) => {
|
|
779
|
+
if (position.overlayY === "bottom" && position.overlayX === "center") {
|
|
780
|
+
return "top";
|
|
781
|
+
}
|
|
782
|
+
if (position.overlayY === "top" && position.overlayX === "center") {
|
|
783
|
+
return "bottom";
|
|
784
|
+
}
|
|
785
|
+
// A popup to the anchor's right touches it with its left edge: the overlay's start in LTR, its end in RTL.
|
|
786
|
+
const leftEdge = position.overlayX === (direction === "rtl" ? "end" : "start");
|
|
787
|
+
return leftEdge ? "right" : "left";
|
|
788
|
+
};
|
|
789
|
+
|
|
328
790
|
const restoreOverlayScroll = (overlayRef, element) => {
|
|
329
791
|
requestAnimationFrame(() => {
|
|
330
792
|
const scrollableContent = findScrollableElement(overlayRef.overlayElement);
|
|
@@ -354,26 +816,6 @@ const findScrollableElement = (container) => {
|
|
|
354
816
|
return null;
|
|
355
817
|
};
|
|
356
818
|
|
|
357
|
-
const toPixels = (value) => (value != null ? `${value}px` : "");
|
|
358
|
-
const setWindowStyles = (element, settings) => {
|
|
359
|
-
if (!element) {
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
const classes = typeof settings.windowClass === "string" ? [settings.windowClass] : (settings.windowClass ?? []);
|
|
363
|
-
classes
|
|
364
|
-
.flatMap(className => (className ?? "").split(/\s+/))
|
|
365
|
-
.filter(className => className !== "")
|
|
366
|
-
.forEach(className => element.classList.add(className));
|
|
367
|
-
const minWidth = toPixels(settings.minWidth);
|
|
368
|
-
const minHeight = toPixels(settings.minHeight);
|
|
369
|
-
const maxWidth = toPixels(settings.maxWidth);
|
|
370
|
-
const maxHeight = toPixels(settings.maxHeight);
|
|
371
|
-
const top = settings.top != null ? `${settings.top}px` : `calc(50% - ${element.getBoundingClientRect().height / 2}px)`;
|
|
372
|
-
const left = settings.left != null ? `${settings.left}px` : `calc(50% - ${element.getBoundingClientRect().width / 2}px)`;
|
|
373
|
-
const position = "absolute";
|
|
374
|
-
Object.assign(element.style, { left, maxHeight, maxWidth, minHeight, minWidth, position, top });
|
|
375
|
-
};
|
|
376
|
-
|
|
377
819
|
/**
|
|
378
820
|
* Converts a number or a string into a CSS-compliant value.
|
|
379
821
|
* - If the input is a number (e.g., 100), it appends 'px'.
|
|
@@ -407,7 +849,7 @@ var NavigationKeys;
|
|
|
407
849
|
NavigationKeys["PageUp"] = "PageUp";
|
|
408
850
|
NavigationKeys["Space"] = " ";
|
|
409
851
|
})(NavigationKeys || (NavigationKeys = {}));
|
|
410
|
-
const NavigationKeysList = Object.
|
|
852
|
+
const NavigationKeysList = Object.values(NavigationKeys);
|
|
411
853
|
const isNavigationKey = (key) => {
|
|
412
854
|
return NavigationKeysList.includes(key);
|
|
413
855
|
};
|
|
@@ -434,5 +876,5 @@ const setupTypeahead = (typeaheadKey$) => {
|
|
|
434
876
|
* Generated bundle index. Do not edit.
|
|
435
877
|
*/
|
|
436
878
|
|
|
437
|
-
export { AttributeBinderDirective, NavigationKeys, NavigationKeysList, TYPEAHEAD_RESET_DELAY, createElementControlId, focusCanReturn, focusElement, hex2rgba, hsla2hsva, hsva2rgba, isNavigationKey, isTypeaheadKey, isValidHex, isValidHsla, isValidRgb, restoreOverlayScroll, rgba2hex, rgba2hsla, rgba2hsva, rxFromResize, rxTimeout,
|
|
879
|
+
export { AttributeBinderDirective, HOVER_GRACE, HoverIntent, NavigationKeys, NavigationKeysList, TYPEAHEAD_RESET_DELAY, addAriaReference, createElementControlId, focusCanReturn, focusElement, hex2rgba, hsla2hsva, hsva2rgba, inertOutside, injectLabelledByText, isNavigationKey, isTypeaheadKey, isValidHex, isValidHsla, isValidRgb, listenForHover, onDisconnect, overlaySidePositions, positionGlobalOverlay, removeAriaReference, resolveOverlaySide, restoreOverlayScroll, rgba2hex, rgba2hsla, rgba2hsva, rxFromResize, rxTimeout, setupTypeahead, sideOfPosition, string2Hsla, string2rgba, themeControlBackdropClasses, themeControlSurfaceClasses, themeOverlayBackdropClasses, themeOverlaySurfaceClasses, themeRaisedBackdropClasses, themeRaisedSurfaceClasses, toCssValue };
|
|
438
880
|
//# sourceMappingURL=nanahoshi-mona-ui-internal.mjs.map
|