drab 6.2.0 → 6.2.2

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.
@@ -30,7 +30,7 @@ export class Base extends HTMLElement {
30
30
  * @default "click"
31
31
  */
32
32
  get event() {
33
- return (this.getAttribute("event") ?? "click");
33
+ return this.getAttribute("event") ?? "click";
34
34
  }
35
35
  set event(value) {
36
36
  this.setAttribute("event", value);
@@ -46,8 +46,7 @@ export class Base extends HTMLElement {
46
46
  * @default this.querySelectorAll("[data-trigger]")
47
47
  */
48
48
  getTrigger() {
49
- const triggers = this.querySelectorAll(this.getAttribute("trigger") ?? "[data-trigger]");
50
- return triggers;
49
+ return this.querySelectorAll(this.getAttribute("trigger") ?? "[data-trigger]");
51
50
  }
52
51
  /**
53
52
  * @param instance The instance of the desired element to validate against,
@@ -6,7 +6,7 @@ export type ContextMenuAttributes = BaseAttributes;
6
6
  export declare class ContextMenu extends Base {
7
7
  #private;
8
8
  constructor();
9
- show(e: MouseEvent | TouchEvent): Promise<void>;
10
- hide(): Promise<void>;
9
+ show(e: MouseEvent | TouchEvent): void;
10
+ hide(): void;
11
11
  mount(): void;
12
12
  }
@@ -13,7 +13,7 @@ export class ContextMenu extends Base {
13
13
  this.getContent().style.left = `${value.x}px`;
14
14
  this.getContent().style.top = `${value.y}px`;
15
15
  }
16
- async show(e) {
16
+ show(e) {
17
17
  // find coordinates of the click
18
18
  const scrollY = window.scrollY;
19
19
  const scrollX = window.scrollX;
@@ -36,7 +36,7 @@ export class ContextMenu extends Base {
36
36
  }
37
37
  this.#coordinates = { x, y };
38
38
  }
39
- async hide() {
39
+ hide() {
40
40
  this.getContent().removeAttribute("data-open");
41
41
  }
42
42
  mount() {
@@ -57,9 +57,8 @@ export class ContextMenu extends Base {
57
57
  this.triggerListener(resetTimer, "touchcancel", { passive: true });
58
58
  // keyboard
59
59
  this.safeListener("keydown", (e) => {
60
- if (e.key === "Escape") {
60
+ if (e.key === "Escape")
61
61
  this.hide();
62
- }
63
62
  });
64
63
  }
65
64
  }
@@ -1,10 +1,23 @@
1
- import { BaseCopy, type BaseCopyAttributes } from "../base/copy/index.js";
2
- export type CopyAttributes = BaseCopyAttributes;
1
+ import { Base, type BaseAttributes } from "../base/index.js";
2
+ export type CopyAttributes = BaseAttributes & {
3
+ value: string;
4
+ };
3
5
  /**
4
6
  * Uses the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText)
5
7
  * to copy text.
6
8
  */
7
- export declare class Copy extends BaseCopy {
9
+ export declare class Copy extends Base {
8
10
  constructor();
11
+ /**
12
+ * The value to copy.
13
+ *
14
+ * @default ""
15
+ */
16
+ get value(): string;
17
+ set value(value: string);
18
+ /**
19
+ * @param value The `value` to copy
20
+ */
21
+ copy(value?: string): Promise<void>;
9
22
  mount(): void;
10
23
  }
@@ -1,13 +1,32 @@
1
- import { BaseCopy } from "../base/copy/index.js";
1
+ import { Base } from "../base/index.js";
2
2
  /**
3
3
  * Uses the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText)
4
4
  * to copy text.
5
5
  */
6
- export class Copy extends BaseCopy {
6
+ export class Copy extends Base {
7
7
  constructor() {
8
8
  super();
9
9
  }
10
+ /**
11
+ * The value to copy.
12
+ *
13
+ * @default ""
14
+ */
15
+ get value() {
16
+ return this.getAttribute("value") ?? "";
17
+ }
18
+ set value(value) {
19
+ this.setAttribute("value", value);
20
+ }
21
+ /**
22
+ * @param value The `value` to copy
23
+ */
24
+ copy(value = this.value) {
25
+ this.announce(`copied ${value} to clipboard`);
26
+ this.swapContent();
27
+ return navigator.clipboard.writeText(value);
28
+ }
10
29
  mount() {
11
- this.triggerListener(async () => await this.copy());
30
+ this.triggerListener(() => this.copy());
12
31
  }
13
32
  }
@@ -22,10 +22,10 @@ export declare class Dialog extends Base {
22
22
  /** The `HTMLDialogElement` within the element. */
23
23
  get dialog(): HTMLDialogElement;
24
24
  /** `HTMLDialogElement.showModal()` with animation. */
25
- show(): Promise<void>;
25
+ show(): void;
26
26
  /** `HTMLDialogElement.close()` with animation. */
27
- close(): Promise<void>;
27
+ close(): void;
28
28
  /** `show` or `close` depending on the dialog's `open` attribute. */
29
- toggle(): Promise<void>;
29
+ toggle(): void;
30
30
  mount(): void;
31
31
  }
@@ -35,17 +35,17 @@ export class Dialog extends Base {
35
35
  }
36
36
  }
37
37
  /** `HTMLDialogElement.showModal()` with animation. */
38
- async show() {
38
+ show() {
39
39
  this.dialog.showModal();
40
40
  this.#toggleBodyScroll(true);
41
41
  }
42
42
  /** `HTMLDialogElement.close()` with animation. */
43
- async close() {
43
+ close() {
44
44
  this.#toggleBodyScroll(false);
45
45
  this.dialog.close();
46
46
  }
47
47
  /** `show` or `close` depending on the dialog's `open` attribute. */
48
- async toggle() {
48
+ toggle() {
49
49
  if (this.dialog.open)
50
50
  this.close();
51
51
  else
@@ -355,6 +355,6 @@ export class Editor extends Base {
355
355
  });
356
356
  // reset #openChars on click since the cursor has changed position
357
357
  this.textArea.addEventListener("click", () => (this.#openChars = []));
358
- this.triggerListener((e) => this.#addContent(e.target.dataset));
358
+ this.triggerListener((e) => this.#addContent(e.currentTarget.dataset));
359
359
  }
360
360
  }
@@ -1,15 +1,14 @@
1
- import { BaseCopy, type BaseCopyAttributes } from "../base/copy/index.js";
2
- export type ShareAttributes = BaseCopyAttributes;
1
+ import { Copy, type CopyAttributes } from "../copy/index.js";
2
+ export type ShareAttributes = CopyAttributes;
3
3
  /**
4
- * Uses the [Navigator API](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share) to share a url. If `share` is not supported, falls back to copy the text instead.
4
+ * Uses the [Navigator API](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share)
5
+ * to share a url. If `share` is not supported, falls back to copy the text instead.
5
6
  */
6
- export declare class Share extends BaseCopy {
7
+ export declare class Share extends Copy {
7
8
  constructor();
8
9
  /**
9
10
  * Shares or copies the `value`.
10
11
  * @param url The `url` to share, defaults to `this.value`
11
- * @returns An object containing a `result` - whether the `url` was copied or shared
12
- * depending on browser support.
13
12
  */
14
13
  share(url?: string): Promise<void>;
15
14
  mount(): void;
@@ -1,34 +1,26 @@
1
- import { BaseCopy } from "../base/copy/index.js";
1
+ import { Copy } from "../copy/index.js";
2
2
  /**
3
- * Uses the [Navigator API](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share) to share a url. If `share` is not supported, falls back to copy the text instead.
3
+ * Uses the [Navigator API](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share)
4
+ * to share a url. If `share` is not supported, falls back to copy the text instead.
4
5
  */
5
- export class Share extends BaseCopy {
6
+ export class Share extends Copy {
6
7
  constructor() {
7
8
  super();
8
9
  }
9
10
  /**
10
11
  * Shares or copies the `value`.
11
12
  * @param url The `url` to share, defaults to `this.value`
12
- * @returns An object containing a `result` - whether the `url` was copied or shared
13
- * depending on browser support.
14
13
  */
15
- async share(url = this.value) {
14
+ share(url = this.value) {
16
15
  if (navigator.canShare && navigator.canShare({ url })) {
17
- try {
18
- await navigator.share({ url });
19
- }
20
- catch (error) {
21
- if (error?.name !== "AbortError") {
22
- console.error(error);
23
- }
24
- }
16
+ return navigator.share({ url });
25
17
  }
26
18
  else {
27
19
  // progressively enhance, copy the link
28
- this.copy();
20
+ return this.copy();
29
21
  }
30
22
  }
31
23
  mount() {
32
- this.triggerListener(async () => await this.share());
24
+ this.triggerListener(() => this.share());
33
25
  }
34
26
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "drab",
3
3
  "description": "Interactivity for You",
4
- "version": "6.2.0",
4
+ "version": "6.2.2",
5
5
  "homepage": "https://drab.robino.dev",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -1,19 +0,0 @@
1
- import { Base, type BaseAttributes } from "../index.js";
2
- export type BaseCopyAttributes = BaseAttributes & {
3
- value: string;
4
- };
5
- export declare class BaseCopy extends Base {
6
- constructor();
7
- /**
8
- * The value to copy or share.
9
- *
10
- * @default "" the empty string
11
- */
12
- get value(): string;
13
- set value(value: string);
14
- /**
15
- * Copies the `text`.
16
- * @param text The `text` to share
17
- */
18
- copy(text?: string): Promise<void>;
19
- }
@@ -1,26 +0,0 @@
1
- import { Base } from "../index.js";
2
- export class BaseCopy extends Base {
3
- constructor() {
4
- super();
5
- }
6
- /**
7
- * The value to copy or share.
8
- *
9
- * @default "" the empty string
10
- */
11
- get value() {
12
- return this.getAttribute("value") ?? "";
13
- }
14
- set value(value) {
15
- this.setAttribute("value", value);
16
- }
17
- /**
18
- * Copies the `text`.
19
- * @param text The `text` to share
20
- */
21
- async copy(text = this.value) {
22
- this.announce(`copied ${text} to clipboard`);
23
- await navigator.clipboard.writeText(text);
24
- this.swapContent();
25
- }
26
- }