@nanahoshi/mona-ui 0.24.8 → 0.24.10
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-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-color-picker.mjs +2 -2
- package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +101 -47
- package/fesm2022/nanahoshi-mona-ui-dialog.mjs +342 -102
- package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +119 -69
- package/fesm2022/nanahoshi-mona-ui-editor.mjs +1054 -452
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-DdyHnUIr.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DhKLnW06.mjs} +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-B6gq7Hu3.mjs → nanahoshi-mona-ui-grid-grid-list.component-voGbKOiB.mjs} +4 -4
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-DdUY3I7P.mjs → nanahoshi-mona-ui-grid-grid-row.component-HQ1Kv6R9.mjs} +2 -3
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-DG8Bu4Dy.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-PNLJFcuH.mjs} +4 -4
- package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CVqpbMcb.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BO19AVwC.mjs} +9 -9
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +23 -0
- package/fesm2022/nanahoshi-mona-ui-internal.mjs +567 -33
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +20 -0
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +20 -0
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +20 -0
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +20 -0
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +20 -0
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +20 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +20 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +20 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +20 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +20 -0
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +20 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +20 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +20 -0
- package/fesm2022/nanahoshi-mona-ui-menubar.mjs +127 -133
- 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-window.mjs +594 -311
- package/i18n/catalogs/en-US.messages.json +24 -4
- package/locales/ar-sa/ar-sa.messages.json +20 -0
- package/locales/de-de/de-de.messages.json +20 -0
- package/locales/es-es/es-es.messages.json +20 -0
- package/locales/fr-fr/fr-fr.messages.json +20 -0
- package/locales/id-id/id-id.messages.json +20 -0
- package/locales/it-it/it-it.messages.json +20 -0
- package/locales/ja-jp/ja-jp.messages.json +20 -0
- package/locales/ko-kr/ko-kr.messages.json +20 -0
- package/locales/pt-br/pt-br.messages.json +20 -0
- package/locales/ru-ru/ru-ru.messages.json +20 -0
- package/locales/tr-tr/tr-tr.messages.json +20 -0
- package/locales/zh-cn/zh-cn.messages.json +20 -0
- package/locales/zh-tw/zh-tw.messages.json +20 -0
- 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-editor.d.ts +118 -21
- package/types/nanahoshi-mona-ui-i18n.d.ts +37 -0
- package/types/nanahoshi-mona-ui-internal.d.ts +142 -16
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +20 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +20 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +20 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +20 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +20 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +20 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +20 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +20 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +20 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +20 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +20 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +20 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +20 -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-window.d.ts +103 -14
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
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.
|
|
@@ -261,20 +285,86 @@ function focusCanReturn(document, ...containers) {
|
|
|
261
285
|
return containers.some(container => container?.contains(activeElement));
|
|
262
286
|
}
|
|
263
287
|
|
|
288
|
+
/**
|
|
289
|
+
* Focuses an element given directly, by reference, or by a selector inside `host`, and returns it (or `null` when the
|
|
290
|
+
* selector matches nothing).
|
|
291
|
+
*/
|
|
264
292
|
function focusElement(host, element) {
|
|
265
|
-
|
|
266
|
-
element.nativeElement
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
293
|
+
const target = element instanceof ElementRef
|
|
294
|
+
? element.nativeElement
|
|
295
|
+
: element instanceof HTMLElement
|
|
296
|
+
? element
|
|
297
|
+
: host.querySelector(element);
|
|
298
|
+
target?.focus();
|
|
299
|
+
return target;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* How many open modal overlays made each element inert. An element is made inert by the first and released by the
|
|
304
|
+
* last, so closing one of two stacked modals leaves the page behind the other one inert.
|
|
305
|
+
*/
|
|
306
|
+
const inertCounts = new WeakMap();
|
|
307
|
+
/** Elements left alone: they hold no content, or announce for everyone (live regions, CDK's live announcer). */
|
|
308
|
+
const isExempt = (element) => element instanceof HTMLScriptElement ||
|
|
309
|
+
element instanceof HTMLStyleElement ||
|
|
310
|
+
element instanceof HTMLTemplateElement ||
|
|
311
|
+
element.hasAttribute("aria-live") ||
|
|
312
|
+
element.classList.contains("cdk-overlay-backdrop");
|
|
313
|
+
/**
|
|
314
|
+
* Makes everything outside a modal overlay inert, so assistive technology, the pointer and Tab can't reach the page
|
|
315
|
+
* behind it. Walking up from `element` to `<body>`, every sibling is made inert, except that inside the CDK overlay
|
|
316
|
+
* container only the overlays opened before this one are: popups opened later (a dropdown inside the dialog) stay
|
|
317
|
+
* usable. Elements that were inert already are left as they are.
|
|
318
|
+
* @param element the overlay's host element (the CDK overlay wrapper)
|
|
319
|
+
* @returns the function that releases what this call made inert
|
|
320
|
+
*/
|
|
321
|
+
const inertOutside = (element) => {
|
|
322
|
+
const body = element.ownerDocument.body;
|
|
323
|
+
const acquired = [];
|
|
324
|
+
let node = element;
|
|
325
|
+
while (node && node !== body && node.parentElement) {
|
|
326
|
+
const parent = node.parentElement;
|
|
327
|
+
const onlyEarlier = parent.classList.contains("cdk-overlay-container");
|
|
328
|
+
for (const sibling of Array.from(parent.children)) {
|
|
329
|
+
if (sibling === node) {
|
|
330
|
+
if (onlyEarlier) {
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (isExempt(sibling)) {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
const count = inertCounts.get(sibling) ?? 0;
|
|
339
|
+
if (count === 0 && sibling.hasAttribute("inert")) {
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
inertCounts.set(sibling, count + 1);
|
|
343
|
+
if (count === 0) {
|
|
344
|
+
sibling.setAttribute("inert", "");
|
|
345
|
+
}
|
|
346
|
+
acquired.push(sibling);
|
|
275
347
|
}
|
|
348
|
+
node = parent;
|
|
276
349
|
}
|
|
277
|
-
|
|
350
|
+
let released = false;
|
|
351
|
+
return () => {
|
|
352
|
+
if (released) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
released = true;
|
|
356
|
+
for (const sibling of acquired) {
|
|
357
|
+
const count = (inertCounts.get(sibling) ?? 1) - 1;
|
|
358
|
+
if (count <= 0) {
|
|
359
|
+
inertCounts.delete(sibling);
|
|
360
|
+
sibling.removeAttribute("inert");
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
inertCounts.set(sibling, count);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
};
|
|
278
368
|
|
|
279
369
|
/**
|
|
280
370
|
* The text of the elements an `aria-labelledby` value points to, joined with spaces, for names built from a
|
|
@@ -302,6 +392,31 @@ function injectLabelledByText(ids) {
|
|
|
302
392
|
return text.asReadonly();
|
|
303
393
|
}
|
|
304
394
|
|
|
395
|
+
/**
|
|
396
|
+
* Places a global overlay through its position strategy, so later `updatePosition()` calls (a direction change, a
|
|
397
|
+
* resize) keep it where it is instead of resetting inline styles. Each axis is independent: a `top` alone keeps the
|
|
398
|
+
* overlay centered horizontally. Centering follows the overlay's size as it grows or shrinks.
|
|
399
|
+
*/
|
|
400
|
+
const positionGlobalOverlay = (overlayRef, position) => {
|
|
401
|
+
const strategy = overlayRef.getConfig().positionStrategy;
|
|
402
|
+
if (!(strategy instanceof GlobalPositionStrategy)) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (position.left != null) {
|
|
406
|
+
strategy.left(`${position.left}px`);
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
strategy.centerHorizontally();
|
|
410
|
+
}
|
|
411
|
+
if (position.top != null) {
|
|
412
|
+
strategy.top(`${position.top}px`);
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
strategy.centerVertically();
|
|
416
|
+
}
|
|
417
|
+
overlayRef.updatePosition();
|
|
418
|
+
};
|
|
419
|
+
|
|
305
420
|
const rxFromResize = (target, options) => {
|
|
306
421
|
return new Observable(observer => {
|
|
307
422
|
const elements = target instanceof Element ? [target] : Array.from(target ?? []);
|
|
@@ -317,6 +432,125 @@ const rxFromResize = (target, options) => {
|
|
|
317
432
|
});
|
|
318
433
|
};
|
|
319
434
|
|
|
435
|
+
/** Marks the controls the toolbar manages, so they are still found once their Tab stop is set to -1. */
|
|
436
|
+
const ITEM_MARKER = "data-mona-toolbar-item";
|
|
437
|
+
const ITEM_SELECTOR = `:is(button, input, select, textarea, a[href], [tabindex]):not([tabindex='-1']), [${ITEM_MARKER}]`;
|
|
438
|
+
/** Input types whose Left and Right arrows don't do anything, so the toolbar can use them. */
|
|
439
|
+
const BUTTON_LIKE_INPUT_TYPES = new Set(["button", "checkbox", "color", "file", "image", "radio", "reset", "submit"]);
|
|
440
|
+
/** Roles of widgets that use Left and Right themselves. A select-only combobox uses only Up and Down. */
|
|
441
|
+
const HORIZONTAL_KEY_ROLES = new Set(["radiogroup", "searchbox", "slider", "spinbutton", "tablist", "textbox"]);
|
|
442
|
+
function usesHorizontalArrows(element) {
|
|
443
|
+
if (element instanceof HTMLInputElement) {
|
|
444
|
+
return !BUTTON_LIKE_INPUT_TYPES.has(element.type);
|
|
445
|
+
}
|
|
446
|
+
if (element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement || element.isContentEditable) {
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
const role = element.getAttribute("role");
|
|
450
|
+
return role != null && HORIZONTAL_KEY_ROLES.has(role);
|
|
451
|
+
}
|
|
452
|
+
function isUnavailable(element) {
|
|
453
|
+
const disabled = (element instanceof HTMLButtonElement ||
|
|
454
|
+
element instanceof HTMLInputElement ||
|
|
455
|
+
element instanceof HTMLSelectElement ||
|
|
456
|
+
element instanceof HTMLTextAreaElement) &&
|
|
457
|
+
element.disabled;
|
|
458
|
+
return (disabled ||
|
|
459
|
+
element.hasAttribute("disabled") ||
|
|
460
|
+
element.getAttribute("aria-disabled") === "true" ||
|
|
461
|
+
element.closest("[hidden], [aria-hidden='true']") != null);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* The keyboard of an APG toolbar over controls that other components render: one Tab stop, Left and Right (mirrored
|
|
465
|
+
* in right-to-left text) to move between controls, Home and End to the ends. Disabled and hidden controls are
|
|
466
|
+
* skipped; a control inside another one (a button inside a combobox) belongs to it.
|
|
467
|
+
*
|
|
468
|
+
* Call {@link sync} after every render, so controls added later join the Tab stop, and forward the toolbar's
|
|
469
|
+
* `focusin` and `keydown` events.
|
|
470
|
+
*/
|
|
471
|
+
class RovingToolbar {
|
|
472
|
+
#element;
|
|
473
|
+
#active = null;
|
|
474
|
+
#activeIndex = 0;
|
|
475
|
+
constructor(element) {
|
|
476
|
+
this.#element = element;
|
|
477
|
+
}
|
|
478
|
+
/** The Tab stop follows focus, also when a control is clicked. */
|
|
479
|
+
onFocusIn(event) {
|
|
480
|
+
const target = event.target;
|
|
481
|
+
const item = this.#targets().find(candidate => candidate === target || candidate.contains(target));
|
|
482
|
+
if (item != null && item !== this.#active) {
|
|
483
|
+
this.#active = item;
|
|
484
|
+
this.sync();
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
onKeydown(event) {
|
|
488
|
+
const key = event.key;
|
|
489
|
+
if (key !== "ArrowLeft" && key !== "ArrowRight" && key !== "Home" && key !== "End") {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
const target = event.target;
|
|
493
|
+
if (event.defaultPrevented ||
|
|
494
|
+
event.isComposing ||
|
|
495
|
+
event.altKey ||
|
|
496
|
+
event.ctrlKey ||
|
|
497
|
+
event.metaKey ||
|
|
498
|
+
usesHorizontalArrows(target)) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
const targets = this.#targets();
|
|
502
|
+
const currentIndex = targets.findIndex(item => item === target || item.contains(target));
|
|
503
|
+
if (currentIndex === -1) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
event.preventDefault();
|
|
507
|
+
let nextIndex;
|
|
508
|
+
if (key === "Home") {
|
|
509
|
+
nextIndex = 0;
|
|
510
|
+
}
|
|
511
|
+
else if (key === "End") {
|
|
512
|
+
nextIndex = targets.length - 1;
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
const element = this.#element();
|
|
516
|
+
const rtl = element?.ownerDocument.defaultView?.getComputedStyle(element).direction === "rtl";
|
|
517
|
+
const step = (key === "ArrowRight") !== rtl ? 1 : -1;
|
|
518
|
+
nextIndex = (currentIndex + step + targets.length) % targets.length;
|
|
519
|
+
}
|
|
520
|
+
this.#active = targets[nextIndex];
|
|
521
|
+
this.sync();
|
|
522
|
+
targets[nextIndex].focus();
|
|
523
|
+
}
|
|
524
|
+
/** Gives the active control the Tab stop and takes it from the others. */
|
|
525
|
+
sync() {
|
|
526
|
+
const targets = this.#targets();
|
|
527
|
+
if (targets.length === 0) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
const itemIndex = this.#active == null ? -1 : targets.indexOf(this.#active);
|
|
531
|
+
const activeIndex = itemIndex !== -1 ? itemIndex : Math.min(this.#activeIndex, targets.length - 1);
|
|
532
|
+
this.#active = targets[activeIndex];
|
|
533
|
+
this.#activeIndex = activeIndex;
|
|
534
|
+
for (const [index, target] of targets.entries()) {
|
|
535
|
+
const tabIndex = index === activeIndex ? "0" : "-1";
|
|
536
|
+
if (target.getAttribute("tabindex") !== tabIndex) {
|
|
537
|
+
target.setAttribute("tabindex", tabIndex);
|
|
538
|
+
}
|
|
539
|
+
if (!target.hasAttribute(ITEM_MARKER)) {
|
|
540
|
+
target.setAttribute(ITEM_MARKER, "");
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
#targets() {
|
|
545
|
+
const element = this.#element();
|
|
546
|
+
if (element == null) {
|
|
547
|
+
return [];
|
|
548
|
+
}
|
|
549
|
+
const candidates = Array.from(element.querySelectorAll(ITEM_SELECTOR)).filter(candidate => !isUnavailable(candidate));
|
|
550
|
+
return candidates.filter(candidate => !candidates.some(other => other !== candidate && other.contains(candidate)));
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
320
554
|
const rxTimeout = (destroyRef, fn, delay = 0) => {
|
|
321
555
|
timer(delay)
|
|
322
556
|
.pipe(takeUntilDestroyed(destroyRef), take(1))
|
|
@@ -351,6 +585,326 @@ const themeOverlaySurfaceClasses = `
|
|
|
351
585
|
${themeOverlayBackdropClasses}
|
|
352
586
|
`;
|
|
353
587
|
|
|
588
|
+
/**
|
|
589
|
+
* How long a popup opened by hovering waits after the pointer leaves its anchor, so the pointer can cross the gap
|
|
590
|
+
* onto the popup and stay there (WCAG 1.4.13, Content on Hover or Focus).
|
|
591
|
+
*/
|
|
592
|
+
const HOVER_GRACE = 100;
|
|
593
|
+
/**
|
|
594
|
+
* When to show and hide a popup that follows the pointer and focus, shared by the tooltip and the hover popover.
|
|
595
|
+
*
|
|
596
|
+
* - A show waits for `showDelay`, and leaving the anchor first cancels it.
|
|
597
|
+
* - The popup stays while the pointer is on the anchor or on the popup, or focus is on the anchor. Leaving waits for
|
|
598
|
+
* `hideDelay` (at least {@link HOVER_GRACE} for the pointer), and coming back cancels the hide.
|
|
599
|
+
* - Moving to another anchor replaces the popup.
|
|
600
|
+
* - After a dismissal (Escape), the popup stays closed until the pointer and focus have left that anchor.
|
|
601
|
+
*/
|
|
602
|
+
class HoverIntent {
|
|
603
|
+
#config;
|
|
604
|
+
#anchor = null;
|
|
605
|
+
#dismissed = null;
|
|
606
|
+
#focused = false;
|
|
607
|
+
#hideTimer = null;
|
|
608
|
+
#hovered = false;
|
|
609
|
+
#panelCleanup = null;
|
|
610
|
+
#panelHovered = false;
|
|
611
|
+
#pending = null;
|
|
612
|
+
#showTimer = null;
|
|
613
|
+
#tracked = null;
|
|
614
|
+
constructor(config) {
|
|
615
|
+
this.#config = config;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Reports that the popup for `anchor` started closing for a reason of its own (Escape, an outside click, being
|
|
619
|
+
* disabled). With `dismissed`, it stays closed until the pointer and focus have left the anchor.
|
|
620
|
+
*/
|
|
621
|
+
closed(anchor, dismissed = false) {
|
|
622
|
+
if (this.#anchor !== anchor) {
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (dismissed && (this.#hovered || this.#focused)) {
|
|
626
|
+
this.#dismissed = anchor;
|
|
627
|
+
}
|
|
628
|
+
this.#release();
|
|
629
|
+
}
|
|
630
|
+
/** Stops every timer and forgets every anchor, without closing anything. */
|
|
631
|
+
dispose() {
|
|
632
|
+
this.#clearShow();
|
|
633
|
+
this.#cancelHide();
|
|
634
|
+
this.#release();
|
|
635
|
+
this.#pending = null;
|
|
636
|
+
this.#tracked = null;
|
|
637
|
+
this.#dismissed = null;
|
|
638
|
+
}
|
|
639
|
+
/** The pointer moved onto `anchor`, or focus moved into it. */
|
|
640
|
+
enter(anchor, source) {
|
|
641
|
+
if (anchor !== this.#tracked) {
|
|
642
|
+
this.#tracked = anchor;
|
|
643
|
+
this.#hovered = false;
|
|
644
|
+
this.#focused = false;
|
|
645
|
+
}
|
|
646
|
+
this.#setActive(source, true);
|
|
647
|
+
if (this.#dismissed === anchor) {
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
this.#dismissed = null;
|
|
651
|
+
this.#cancelHide();
|
|
652
|
+
if (this.#anchor === anchor || this.#pending === anchor) {
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
this.#clearShow();
|
|
656
|
+
this.#pending = anchor;
|
|
657
|
+
const delay = this.#config.showDelay();
|
|
658
|
+
if (delay > 0) {
|
|
659
|
+
this.#showTimer = setTimeout(() => this.#show(anchor), delay);
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
this.#show(anchor);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
/** Hides the popup now, as leaving would, and cancels a pending show. */
|
|
666
|
+
hideNow() {
|
|
667
|
+
this.#clearShow();
|
|
668
|
+
this.#pending = null;
|
|
669
|
+
this.#cancelHide();
|
|
670
|
+
if (this.#anchor) {
|
|
671
|
+
this.#release();
|
|
672
|
+
this.#config.hide();
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
/** The pointer left `anchor`, or focus left it. */
|
|
676
|
+
leave(anchor, source) {
|
|
677
|
+
if (anchor !== this.#tracked) {
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
this.#setActive(source, false);
|
|
681
|
+
if (this.#hovered || this.#focused) {
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
if (this.#dismissed === anchor) {
|
|
685
|
+
this.#dismissed = null;
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (this.#pending === anchor) {
|
|
689
|
+
this.#clearShow();
|
|
690
|
+
this.#pending = null;
|
|
691
|
+
}
|
|
692
|
+
if (this.#anchor === anchor && !this.#panelHovered) {
|
|
693
|
+
this.#scheduleHide(source);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Reports that the popup for `anchor` is open. While the pointer is on `panel`, the popup stays.
|
|
698
|
+
*/
|
|
699
|
+
opened(anchor, panel) {
|
|
700
|
+
this.#release();
|
|
701
|
+
this.#anchor = anchor;
|
|
702
|
+
if (!panel) {
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
const enter = (event) => {
|
|
706
|
+
if (event.pointerType === "touch") {
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
this.#panelHovered = true;
|
|
710
|
+
this.#cancelHide();
|
|
711
|
+
};
|
|
712
|
+
const leave = (event) => {
|
|
713
|
+
if (event.pointerType === "touch") {
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
this.#panelHovered = false;
|
|
717
|
+
if (this.#anchor === anchor && !this.#hovered && !this.#focused) {
|
|
718
|
+
this.#scheduleHide("pointer");
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
panel.addEventListener("pointerenter", enter);
|
|
722
|
+
panel.addEventListener("pointerleave", leave);
|
|
723
|
+
this.#panelCleanup = () => {
|
|
724
|
+
panel.removeEventListener("pointerenter", enter);
|
|
725
|
+
panel.removeEventListener("pointerleave", leave);
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
#cancelHide() {
|
|
729
|
+
if (this.#hideTimer != null) {
|
|
730
|
+
clearTimeout(this.#hideTimer);
|
|
731
|
+
this.#hideTimer = null;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
#clearShow() {
|
|
735
|
+
if (this.#showTimer != null) {
|
|
736
|
+
clearTimeout(this.#showTimer);
|
|
737
|
+
this.#showTimer = null;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
#release() {
|
|
741
|
+
this.#panelCleanup?.();
|
|
742
|
+
this.#panelCleanup = null;
|
|
743
|
+
this.#panelHovered = false;
|
|
744
|
+
this.#anchor = null;
|
|
745
|
+
this.#cancelHide();
|
|
746
|
+
}
|
|
747
|
+
#scheduleHide(source) {
|
|
748
|
+
this.#cancelHide();
|
|
749
|
+
const delay = Math.max(this.#config.hideDelay(), source === "pointer" ? HOVER_GRACE : 0);
|
|
750
|
+
const hide = () => {
|
|
751
|
+
this.#hideTimer = null;
|
|
752
|
+
if (this.#anchor) {
|
|
753
|
+
this.#release();
|
|
754
|
+
this.#config.hide();
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
if (delay > 0) {
|
|
758
|
+
this.#hideTimer = setTimeout(hide, delay);
|
|
759
|
+
}
|
|
760
|
+
else {
|
|
761
|
+
hide();
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
#setActive(source, active) {
|
|
765
|
+
if (source === "pointer") {
|
|
766
|
+
this.#hovered = active;
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
this.#focused = active;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
#show(anchor) {
|
|
773
|
+
this.#showTimer = null;
|
|
774
|
+
this.#pending = null;
|
|
775
|
+
if (this.#anchor && this.#anchor !== anchor) {
|
|
776
|
+
this.#release();
|
|
777
|
+
this.#config.hide();
|
|
778
|
+
}
|
|
779
|
+
this.#config.show(anchor);
|
|
780
|
+
}
|
|
781
|
+
/** The anchor whose popup is open, if any. */
|
|
782
|
+
get anchor() {
|
|
783
|
+
return this.#anchor;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Feeds a {@link HoverIntent} from pointer and focus events delegated on `root`, so anchors added, removed or
|
|
788
|
+
* re-rendered later need no listeners of their own. Touch pointers are ignored: a tap that focuses the anchor shows
|
|
789
|
+
* the popup through focus instead, and it isn't hidden again by the pointer leaving after the tap.
|
|
790
|
+
* @param resolve the anchor an event target belongs to, or `null`
|
|
791
|
+
* @returns the function that removes the listeners
|
|
792
|
+
*/
|
|
793
|
+
const listenForHover = (root, resolve, intent) => {
|
|
794
|
+
const anchorOf = (target) => target instanceof Element ? resolve(target) : null;
|
|
795
|
+
const stillInside = (anchor, to) => to instanceof Node && anchor.contains(to);
|
|
796
|
+
const over = (event) => {
|
|
797
|
+
if (event.pointerType === "touch") {
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
const anchor = anchorOf(event.target);
|
|
801
|
+
if (anchor) {
|
|
802
|
+
intent.enter(anchor, "pointer");
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
const out = (event) => {
|
|
806
|
+
if (event.pointerType === "touch") {
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
const anchor = anchorOf(event.target);
|
|
810
|
+
if (anchor && !stillInside(anchor, event.relatedTarget)) {
|
|
811
|
+
intent.leave(anchor, "pointer");
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
const focusIn = (event) => {
|
|
815
|
+
const anchor = anchorOf(event.target);
|
|
816
|
+
if (anchor) {
|
|
817
|
+
intent.enter(anchor, "focus");
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
const focusOut = (event) => {
|
|
821
|
+
const anchor = anchorOf(event.target);
|
|
822
|
+
if (anchor && !stillInside(anchor, event.relatedTarget)) {
|
|
823
|
+
intent.leave(anchor, "focus");
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
root.addEventListener("pointerover", over);
|
|
827
|
+
root.addEventListener("pointerout", out);
|
|
828
|
+
root.addEventListener("focusin", focusIn);
|
|
829
|
+
root.addEventListener("focusout", focusOut);
|
|
830
|
+
return () => {
|
|
831
|
+
root.removeEventListener("pointerover", over);
|
|
832
|
+
root.removeEventListener("pointerout", out);
|
|
833
|
+
root.removeEventListener("focusin", focusIn);
|
|
834
|
+
root.removeEventListener("focusout", focusOut);
|
|
835
|
+
};
|
|
836
|
+
};
|
|
837
|
+
/**
|
|
838
|
+
* Calls `callback` once `element` leaves the document, for a popup that would otherwise stay anchored to nothing.
|
|
839
|
+
* @returns the function that stops watching
|
|
840
|
+
*/
|
|
841
|
+
const onDisconnect = (element, callback) => {
|
|
842
|
+
const view = element.ownerDocument.defaultView;
|
|
843
|
+
if (!view?.MutationObserver) {
|
|
844
|
+
return () => undefined;
|
|
845
|
+
}
|
|
846
|
+
const observer = new view.MutationObserver(() => {
|
|
847
|
+
if (!element.isConnected) {
|
|
848
|
+
observer.disconnect();
|
|
849
|
+
callback();
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
observer.observe(element.ownerDocument.body, { childList: true, subtree: true });
|
|
853
|
+
return () => observer.disconnect();
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
const OPPOSITE = {
|
|
857
|
+
bottom: "top",
|
|
858
|
+
left: "right",
|
|
859
|
+
right: "left",
|
|
860
|
+
top: "bottom"
|
|
861
|
+
};
|
|
862
|
+
const resolveOverlaySide = (side, direction) => {
|
|
863
|
+
if (side === "start") {
|
|
864
|
+
return direction === "rtl" ? "right" : "left";
|
|
865
|
+
}
|
|
866
|
+
if (side === "end") {
|
|
867
|
+
return direction === "rtl" ? "left" : "right";
|
|
868
|
+
}
|
|
869
|
+
return side;
|
|
870
|
+
};
|
|
871
|
+
const positionFor = (side, gap, direction) => {
|
|
872
|
+
// The overlay's start and end follow its direction, so a physical side is translated for RTL.
|
|
873
|
+
const left = direction === "rtl" ? "end" : "start";
|
|
874
|
+
const right = direction === "rtl" ? "start" : "end";
|
|
875
|
+
switch (side) {
|
|
876
|
+
case "top":
|
|
877
|
+
return new ConnectionPositionPair({ originX: "center", originY: "top" }, { overlayX: "center", overlayY: "bottom" }, 0, -gap);
|
|
878
|
+
case "bottom":
|
|
879
|
+
return new ConnectionPositionPair({ originX: "center", originY: "bottom" }, { overlayX: "center", overlayY: "top" }, 0, gap);
|
|
880
|
+
case "left":
|
|
881
|
+
return new ConnectionPositionPair({ originX: left, originY: "center" }, { overlayX: right, overlayY: "center" }, -gap, 0);
|
|
882
|
+
case "right":
|
|
883
|
+
return new ConnectionPositionPair({ originX: right, originY: "center" }, { overlayX: left, overlayY: "center" }, gap, 0);
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
/**
|
|
887
|
+
* Positions for a popup centered on `side` of its anchor, flipping to the opposite side when it doesn't fit. Each
|
|
888
|
+
* position carries its own offset, so the gap stays between the popup and its anchor after a flip.
|
|
889
|
+
* @param gap the distance between the anchor and the popup, in pixels
|
|
890
|
+
* @param direction the overlay's direction
|
|
891
|
+
*/
|
|
892
|
+
const overlaySidePositions = (side, gap, direction) => [positionFor(side, gap, direction), positionFor(OPPOSITE[side], gap, direction)];
|
|
893
|
+
/**
|
|
894
|
+
* The physical side of its anchor a popup ended up on, from the position the overlay chose.
|
|
895
|
+
*/
|
|
896
|
+
const sideOfPosition = (position, direction) => {
|
|
897
|
+
if (position.overlayY === "bottom" && position.overlayX === "center") {
|
|
898
|
+
return "top";
|
|
899
|
+
}
|
|
900
|
+
if (position.overlayY === "top" && position.overlayX === "center") {
|
|
901
|
+
return "bottom";
|
|
902
|
+
}
|
|
903
|
+
// A popup to the anchor's right touches it with its left edge: the overlay's start in LTR, its end in RTL.
|
|
904
|
+
const leftEdge = position.overlayX === (direction === "rtl" ? "end" : "start");
|
|
905
|
+
return leftEdge ? "right" : "left";
|
|
906
|
+
};
|
|
907
|
+
|
|
354
908
|
const restoreOverlayScroll = (overlayRef, element) => {
|
|
355
909
|
requestAnimationFrame(() => {
|
|
356
910
|
const scrollableContent = findScrollableElement(overlayRef.overlayElement);
|
|
@@ -380,26 +934,6 @@ const findScrollableElement = (container) => {
|
|
|
380
934
|
return null;
|
|
381
935
|
};
|
|
382
936
|
|
|
383
|
-
const toPixels = (value) => (value != null ? `${value}px` : "");
|
|
384
|
-
const setWindowStyles = (element, settings) => {
|
|
385
|
-
if (!element) {
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
const classes = typeof settings.windowClass === "string" ? [settings.windowClass] : (settings.windowClass ?? []);
|
|
389
|
-
classes
|
|
390
|
-
.flatMap(className => (className ?? "").split(/\s+/))
|
|
391
|
-
.filter(className => className !== "")
|
|
392
|
-
.forEach(className => element.classList.add(className));
|
|
393
|
-
const minWidth = toPixels(settings.minWidth);
|
|
394
|
-
const minHeight = toPixels(settings.minHeight);
|
|
395
|
-
const maxWidth = toPixels(settings.maxWidth);
|
|
396
|
-
const maxHeight = toPixels(settings.maxHeight);
|
|
397
|
-
const top = settings.top != null ? `${settings.top}px` : `calc(50% - ${element.getBoundingClientRect().height / 2}px)`;
|
|
398
|
-
const left = settings.left != null ? `${settings.left}px` : `calc(50% - ${element.getBoundingClientRect().width / 2}px)`;
|
|
399
|
-
const position = "absolute";
|
|
400
|
-
Object.assign(element.style, { left, maxHeight, maxWidth, minHeight, minWidth, position, top });
|
|
401
|
-
};
|
|
402
|
-
|
|
403
937
|
/**
|
|
404
938
|
* Converts a number or a string into a CSS-compliant value.
|
|
405
939
|
* - If the input is a number (e.g., 100), it appends 'px'.
|
|
@@ -433,7 +967,7 @@ var NavigationKeys;
|
|
|
433
967
|
NavigationKeys["PageUp"] = "PageUp";
|
|
434
968
|
NavigationKeys["Space"] = " ";
|
|
435
969
|
})(NavigationKeys || (NavigationKeys = {}));
|
|
436
|
-
const NavigationKeysList = Object.
|
|
970
|
+
const NavigationKeysList = Object.values(NavigationKeys);
|
|
437
971
|
const isNavigationKey = (key) => {
|
|
438
972
|
return NavigationKeysList.includes(key);
|
|
439
973
|
};
|
|
@@ -460,5 +994,5 @@ const setupTypeahead = (typeaheadKey$) => {
|
|
|
460
994
|
* Generated bundle index. Do not edit.
|
|
461
995
|
*/
|
|
462
996
|
|
|
463
|
-
export { AttributeBinderDirective, NavigationKeys, NavigationKeysList, TYPEAHEAD_RESET_DELAY, createElementControlId, focusCanReturn, focusElement, hex2rgba, hsla2hsva, hsva2rgba, injectLabelledByText, isNavigationKey, isTypeaheadKey, isValidHex, isValidHsla, isValidRgb, restoreOverlayScroll, rgba2hex, rgba2hsla, rgba2hsva, rxFromResize, rxTimeout,
|
|
997
|
+
export { AttributeBinderDirective, HOVER_GRACE, HoverIntent, NavigationKeys, NavigationKeysList, RovingToolbar, 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 };
|
|
464
998
|
//# sourceMappingURL=nanahoshi-mona-ui-internal.mjs.map
|