abledom 0.0.4 → 0.1.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/dist/esm/index.js CHANGED
@@ -62,9 +62,6 @@ var ui_default = "#abledom-report {\n bottom: 20px;\n display: flex;\n flex-d
62
62
 
63
63
  // src/ui/domBuilder.ts
64
64
  var DOMBuilder = class {
65
- // static fromString(parent: HTMLElement | DocumentFragment, html: string): void {
66
- // // const builder = new DOMBuilder(parent);
67
- // }
68
65
  constructor(parent) {
69
66
  __publicField(this, "_doc");
70
67
  __publicField(this, "_stack");
@@ -107,8 +104,8 @@ var DOMBuilder = class {
107
104
  (_a = this._stack[0]) == null ? void 0 : _a.appendChild(document.createTextNode(text));
108
105
  return this;
109
106
  }
110
- builder(buildDOM) {
111
- buildDOM(this._stack[0]);
107
+ element(callback) {
108
+ callback(this._stack[0]);
112
109
  return this;
113
110
  }
114
111
  };
@@ -323,7 +320,7 @@ var _NotificationUI = class _NotificationUI {
323
320
  );
324
321
  };
325
322
  }
326
- ).builder(log_default).closeTag().openTag(
323
+ ).element(log_default).closeTag().openTag(
327
324
  "button",
328
325
  {
329
326
  class: "button",
@@ -347,12 +344,20 @@ var _NotificationUI = class _NotificationUI {
347
344
  revealButton.style.display = "none";
348
345
  }
349
346
  }
350
- ).builder(reveal_default).closeTag().text(notification.message).openTag("a", {
351
- class: "button close",
352
- href: "/",
353
- title: "Open help",
354
- target: "_blank"
355
- }).builder(help_default).closeTag().openTag(
347
+ ).element(reveal_default).closeTag().text(notification.message).openTag(
348
+ "a",
349
+ {
350
+ class: "button close",
351
+ href: notification.help || "/",
352
+ title: "Open help",
353
+ target: "_blank"
354
+ },
355
+ (help) => {
356
+ if (!notification.help) {
357
+ help.style.display = "none";
358
+ }
359
+ }
360
+ ).element(help_default).closeTag().openTag(
356
361
  "button",
357
362
  {
358
363
  class: "button close",
@@ -365,7 +370,7 @@ var _NotificationUI = class _NotificationUI {
365
370
  (_a = _NotificationUI._highlight) == null ? void 0 : _a.hide();
366
371
  };
367
372
  }
368
- ).builder(close_default).closeTag().closeTag().closeTag();
373
+ ).element(close_default).closeTag().closeTag().closeTag();
369
374
  }
370
375
  toggle(show, initial = false) {
371
376
  var _a;
@@ -401,7 +406,6 @@ var NotificationsUI = class {
401
406
  __publicField(this, "_alignBottomRightButton");
402
407
  __publicField(this, "_isMuted", false);
403
408
  __publicField(this, "_notifications", /* @__PURE__ */ new Set());
404
- var _a;
405
409
  const container = this._container = win.document.createElement("div");
406
410
  container.__abledomui = true;
407
411
  container.id = "abledom-report";
@@ -414,83 +418,111 @@ var NotificationsUI = class {
414
418
  container.appendChild(notificationsContainer);
415
419
  const menuElement = this._menuElement = win.document.createElement("div");
416
420
  menuElement.className = "abledom-menu-container";
417
- new DOMBuilder(menuElement).openTag("div", { class: "abledom-menu" }).openTag("span", {
418
- class: "notifications-count",
419
- title: "Number of notifications"
420
- }).closeTag().openTag("button", {
421
- class: "button",
422
- title: "Show all notifications"
423
- }).builder(showall_default).closeTag().openTag("button", {
424
- class: "button",
425
- title: "Hide all notifications"
426
- }).builder(hideall_default).closeTag().openTag("button", {
427
- class: "button",
428
- title: "Mute newly appearing notifications"
429
- }).builder(muteall_default).closeTag().openTag("button", {
430
- class: "button align-button align-button-first pressed",
431
- title: "Attach notifications to bottom left"
432
- }).builder(alignbottomleft_default).closeTag().openTag("button", {
433
- class: "button align-button",
434
- title: "Attach notifications to top left"
435
- }).builder(aligntopleft_default).closeTag().openTag("button", {
436
- class: "button align-button",
437
- title: "Attach notifications to top right"
438
- }).builder(aligntopright_default).closeTag().openTag("button", {
439
- class: "button align-button align-button-last",
440
- title: "Attach notifications to bottom right"
441
- }).builder(alignbottomright_default).closeTag().closeTag();
442
- const [
443
- notificationCountElement,
444
- showAllButton,
445
- hideAllButton,
446
- muteButton,
447
- alignBottomLeftButton,
448
- alignTopLeftButton,
449
- alignTopRightButton,
450
- alignBottomRightButton
451
- ] = ((_a = menuElement.firstElementChild) == null ? void 0 : _a.childNodes) || [];
452
- if (notificationCountElement instanceof HTMLSpanElement && showAllButton instanceof HTMLButtonElement && hideAllButton instanceof HTMLButtonElement && muteButton instanceof HTMLButtonElement && alignBottomLeftButton instanceof HTMLButtonElement && alignTopLeftButton instanceof HTMLButtonElement && alignTopRightButton instanceof HTMLButtonElement && alignBottomRightButton instanceof HTMLButtonElement) {
453
- container.appendChild(menuElement);
454
- this._notificationCountElement = notificationCountElement;
455
- this._showAllButton = showAllButton;
456
- this._hideAllButton = hideAllButton;
457
- this._alignBottomLeftButton = alignBottomLeftButton;
458
- this._alignTopLeftButton = alignTopLeftButton;
459
- this._alignTopRightButton = alignTopRightButton;
460
- this._alignBottomRightButton = alignBottomRightButton;
461
- showAllButton.onclick = () => {
462
- this.showAll();
463
- };
464
- hideAllButton.onclick = () => {
465
- this.hideAll();
466
- };
467
- muteButton.onclick = () => {
468
- const isMuted = this._isMuted = muteButton.classList.toggle(pressedClass);
469
- if (isMuted) {
470
- muteButton.setAttribute(
471
- "title",
472
- "Unmute newly appearing notifications"
473
- );
474
- } else {
475
- muteButton.setAttribute(
476
- "title",
477
- "Mute newly appearing notifications"
478
- );
479
- }
480
- };
481
- alignBottomLeftButton.onclick = () => {
482
- this.setUIAlignment("bottom-left" /* BottomLeft */);
483
- };
484
- alignBottomRightButton.onclick = () => {
485
- this.setUIAlignment("bottom-right" /* BottomRight */);
486
- };
487
- alignTopLeftButton.onclick = () => {
488
- this.setUIAlignment("top-left" /* TopLeft */);
489
- };
490
- alignTopRightButton.onclick = () => {
491
- this.setUIAlignment("top-right" /* TopRight */);
492
- };
493
- }
421
+ container.appendChild(menuElement);
422
+ new DOMBuilder(menuElement).openTag("div", { class: "abledom-menu" }).openTag(
423
+ "span",
424
+ {
425
+ class: "notifications-count",
426
+ title: "Number of notifications"
427
+ },
428
+ (notificationCountElement) => {
429
+ this._notificationCountElement = notificationCountElement;
430
+ }
431
+ ).closeTag().openTag(
432
+ "button",
433
+ {
434
+ class: "button",
435
+ title: "Show all notifications"
436
+ },
437
+ (showAllButton) => {
438
+ this._showAllButton = showAllButton;
439
+ showAllButton.onclick = () => {
440
+ this.showAll();
441
+ };
442
+ }
443
+ ).element(showall_default).closeTag().openTag(
444
+ "button",
445
+ {
446
+ class: "button",
447
+ title: "Hide all notifications"
448
+ },
449
+ (hideAllButton) => {
450
+ this._hideAllButton = hideAllButton;
451
+ hideAllButton.onclick = () => {
452
+ this.hideAll();
453
+ };
454
+ }
455
+ ).element(hideall_default).closeTag().openTag(
456
+ "button",
457
+ {
458
+ class: "button",
459
+ title: "Mute newly appearing notifications"
460
+ },
461
+ (muteButton) => {
462
+ muteButton.onclick = () => {
463
+ const isMuted = this._isMuted = muteButton.classList.toggle(pressedClass);
464
+ if (isMuted) {
465
+ muteButton.setAttribute(
466
+ "title",
467
+ "Unmute newly appearing notifications"
468
+ );
469
+ } else {
470
+ muteButton.setAttribute(
471
+ "title",
472
+ "Mute newly appearing notifications"
473
+ );
474
+ }
475
+ };
476
+ }
477
+ ).element(muteall_default).closeTag().openTag(
478
+ "button",
479
+ {
480
+ class: "button align-button align-button-first pressed",
481
+ title: "Attach notifications to bottom left"
482
+ },
483
+ (alignBottomLeftButton) => {
484
+ this._alignBottomLeftButton = alignBottomLeftButton;
485
+ alignBottomLeftButton.onclick = () => {
486
+ this.setUIAlignment("bottom-left" /* BottomLeft */);
487
+ };
488
+ }
489
+ ).element(alignbottomleft_default).closeTag().openTag(
490
+ "button",
491
+ {
492
+ class: "button align-button",
493
+ title: "Attach notifications to top left"
494
+ },
495
+ (alignTopLeftButton) => {
496
+ this._alignTopLeftButton = alignTopLeftButton;
497
+ alignTopLeftButton.onclick = () => {
498
+ this.setUIAlignment("top-left" /* TopLeft */);
499
+ };
500
+ }
501
+ ).element(aligntopleft_default).closeTag().openTag(
502
+ "button",
503
+ {
504
+ class: "button align-button",
505
+ title: "Attach notifications to top right"
506
+ },
507
+ (alignTopRightButton) => {
508
+ this._alignTopRightButton = alignTopRightButton;
509
+ alignTopRightButton.onclick = () => {
510
+ this.setUIAlignment("top-right" /* TopRight */);
511
+ };
512
+ }
513
+ ).element(aligntopright_default).closeTag().openTag(
514
+ "button",
515
+ {
516
+ class: "button align-button align-button-last",
517
+ title: "Attach notifications to bottom right"
518
+ },
519
+ (alignBottomRightButton) => {
520
+ this._alignBottomRightButton = alignBottomRightButton;
521
+ alignBottomRightButton.onclick = () => {
522
+ this.setUIAlignment("bottom-right" /* BottomRight */);
523
+ };
524
+ }
525
+ ).element(alignbottomright_default).closeTag().closeTag();
494
526
  win.document.body.appendChild(container);
495
527
  }
496
528
  setUIAlignment(alignment) {
@@ -1346,7 +1378,8 @@ var FocusableElementLabelRule = class extends ValidationRule {
1346
1378
  notification: isElementVisible(element) ? {
1347
1379
  id: "focusable-element-label",
1348
1380
  message: "Focusable element must have a non-empty text label.",
1349
- element
1381
+ element,
1382
+ help: "https://www.w3.org/WAI/tutorials/forms/labels/"
1350
1383
  } : void 0,
1351
1384
  dependsOnIds: new Set(labelledByValues)
1352
1385
  };