drab 6.5.1 → 7.0.1
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/announcer/index.d.ts +2 -0
- package/dist/base/index.d.ts +101 -1536
- package/dist/base/index.js +87 -76
- package/dist/contextmenu/index.d.ts +1045 -3
- package/dist/contextmenu/index.js +15 -15
- package/dist/define.d.ts +11 -1
- package/dist/define.js +11 -5
- package/dist/dialog/index.d.ts +1047 -6
- package/dist/dialog/index.js +28 -25
- package/dist/editor/index.d.ts +1047 -12
- package/dist/editor/index.js +36 -36
- package/dist/fullscreen/index.d.ts +1045 -7
- package/dist/fullscreen/index.js +8 -8
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/intersect/index.d.ts +1059 -16
- package/dist/intersect/index.js +26 -33
- package/dist/prefetch/index.d.ts +706 -25
- package/dist/prefetch/index.js +25 -44
- package/dist/share/index.d.ts +1413 -11
- package/dist/share/index.js +50 -18
- package/dist/tablesort/index.d.ts +1390 -5
- package/dist/tablesort/index.js +5 -5
- package/dist/tabs/index.d.ts +702 -4
- package/dist/tabs/index.js +3 -3
- package/dist/types/index.d.ts +29 -0
- package/dist/wakelock/index.d.ts +1390 -6
- package/dist/wakelock/index.js +16 -16
- package/package.json +5 -24
- package/dist/base/define.js +0 -3
- package/dist/copy/define.d.ts +0 -1
- package/dist/copy/define.js +0 -3
- package/dist/copy/index.d.ts +0 -30
- package/dist/copy/index.js +0 -39
- package/dist/youtube/define.d.ts +0 -1
- package/dist/youtube/define.js +0 -3
- package/dist/youtube/index.d.ts +0 -31
- package/dist/youtube/index.js +0 -56
- /package/dist/{base/define.d.ts → types/index.js} +0 -0
package/dist/share/index.js
CHANGED
@@ -1,33 +1,65 @@
|
|
1
|
-
import {
|
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
|
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
|
-
* `
|
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
|
-
*
|
21
|
+
* `share-title`
|
22
|
+
*
|
23
|
+
* `ShareData` title (only supported on some targets).
|
12
24
|
*/
|
13
|
-
export class Share extends
|
25
|
+
export class Share extends Lifecycle(Trigger(Content(Announce()))) {
|
14
26
|
constructor() {
|
15
27
|
super();
|
16
28
|
}
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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.
|
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
|
}
|