drab 6.5.0 → 7.0.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.
Files changed (39) hide show
  1. package/dist/announcer/index.d.ts +2 -0
  2. package/dist/base/index.d.ts +101 -1536
  3. package/dist/base/index.js +87 -76
  4. package/dist/contextmenu/index.d.ts +1045 -3
  5. package/dist/contextmenu/index.js +15 -15
  6. package/dist/define.d.ts +11 -1
  7. package/dist/define.js +11 -5
  8. package/dist/dialog/index.d.ts +1047 -6
  9. package/dist/dialog/index.js +22 -22
  10. package/dist/editor/index.d.ts +1047 -12
  11. package/dist/editor/index.js +36 -36
  12. package/dist/fullscreen/index.d.ts +1045 -7
  13. package/dist/fullscreen/index.js +8 -8
  14. package/dist/index.d.ts +0 -3
  15. package/dist/index.js +0 -3
  16. package/dist/intersect/index.d.ts +1059 -16
  17. package/dist/intersect/index.js +26 -33
  18. package/dist/prefetch/index.d.ts +706 -25
  19. package/dist/prefetch/index.js +25 -44
  20. package/dist/share/index.d.ts +1413 -11
  21. package/dist/share/index.js +50 -18
  22. package/dist/tablesort/index.d.ts +1390 -5
  23. package/dist/tablesort/index.js +5 -5
  24. package/dist/tabs/index.d.ts +702 -4
  25. package/dist/tabs/index.js +3 -3
  26. package/dist/types/index.d.ts +29 -0
  27. package/dist/wakelock/index.d.ts +1390 -6
  28. package/dist/wakelock/index.js +16 -16
  29. package/package.json +14 -24
  30. package/dist/base/define.js +0 -3
  31. package/dist/copy/define.d.ts +0 -1
  32. package/dist/copy/define.js +0 -3
  33. package/dist/copy/index.d.ts +0 -30
  34. package/dist/copy/index.js +0 -39
  35. package/dist/youtube/define.d.ts +0 -1
  36. package/dist/youtube/define.js +0 -3
  37. package/dist/youtube/index.d.ts +0 -31
  38. package/dist/youtube/index.js +0 -56
  39. /package/dist/{base/define.d.ts → types/index.js} +0 -0
@@ -1,33 +1,65 @@
1
- import { Copy } from "../copy/index.js";
1
+ import { Announce, Content, Lifecycle, Trigger, } from "../base/index.js";
2
2
  /**
3
3
  * Uses the
4
4
  * [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
+ * to share the `url` if `navigator.share` is supported.
6
+ *
7
+ * Otherwise uses the
8
+ * [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText)
9
+ * to copy the `url` or `text` provided.
6
10
  *
7
11
  * ### Attributes
8
12
  *
9
- * `value`
13
+ * `url`
14
+ *
15
+ * URL to share.
16
+ *
17
+ * `text`
18
+ *
19
+ * Text to copy, or the `ShareData` text if `url` is set (only supported on some targets).
10
20
  *
11
- * Text to share.
21
+ * `share-title`
22
+ *
23
+ * `ShareData` title (only supported on some targets).
12
24
  */
13
- export class Share extends Copy {
25
+ export class Share extends Lifecycle(Trigger(Content(Announce()))) {
14
26
  constructor() {
15
27
  super();
16
28
  }
17
- /**
18
- * Shares or copies the `value`.
19
- * @param url The `url` to share, defaults to `this.value`
20
- */
21
- share(url = this.value) {
22
- if (navigator.canShare && navigator.canShare({ url })) {
23
- return navigator.share({ url });
24
- }
25
- else {
26
- // progressively enhance, copy the link
27
- return this.copy();
28
- }
29
+ // helper since ShareData expects undefined instead of null
30
+ #attrOrUndefined(name) {
31
+ return this.getAttribute(name) ?? undefined;
32
+ }
33
+ get #title() {
34
+ return this.#attrOrUndefined("share-title");
35
+ }
36
+ get #text() {
37
+ return this.#attrOrUndefined("text");
38
+ }
39
+ get #url() {
40
+ return this.#attrOrUndefined("url");
29
41
  }
30
42
  mount() {
31
- this.triggerListener(() => this.share());
43
+ this.listener(() => {
44
+ const data = {
45
+ title: this.#title,
46
+ text: this.#text,
47
+ url: this.#url,
48
+ };
49
+ if (data.url && navigator.canShare && navigator.canShare(data)) {
50
+ return navigator.share(data).catch((e) => {
51
+ // catch abort errors when user cancels the share
52
+ if (!(e instanceof Error) || e.name !== "AbortError")
53
+ throw e;
54
+ });
55
+ }
56
+ const copy = data.url || data.text;
57
+ if (copy) {
58
+ return navigator.clipboard.writeText(copy).then(() => {
59
+ this.announce("copied to clipboard");
60
+ this.swap();
61
+ });
62
+ }
63
+ });
32
64
  }
33
65
  }