drab 6.5.1 → 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.
- 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 +22 -22
- 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/base/index.js
CHANGED
@@ -1,8 +1,51 @@
|
|
1
1
|
import { Announcer } from "../announcer/index.js";
|
2
2
|
import { validate } from "../util/validate.js";
|
3
|
-
export const
|
3
|
+
export const Lifecycle = (Super = HTMLElement) => class Lifecycle extends Super {
|
4
|
+
/** To clean up event listeners added to `document` when the element is removed. */
|
5
|
+
#listenerController = new AbortController();
|
6
|
+
constructor(...args) {
|
7
|
+
super(...args);
|
8
|
+
}
|
9
|
+
safeListener(type, listener, target = document.body, options = {}) {
|
10
|
+
options.signal = this.#listenerController.signal;
|
11
|
+
target.addEventListener(type, listener, options);
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* Passed into `queueMicrotask` in `connectedCallback`.
|
15
|
+
* It is overridden in each component that needs to run `connectedCallback`.
|
16
|
+
*
|
17
|
+
* The reason for this is to make these elements work better with frameworks like Svelte.
|
18
|
+
* For SSR this isn't necessary, but when client side rendering, the HTML within the
|
19
|
+
* custom element isn't available before `connectedCallback` is called. By waiting until
|
20
|
+
* the next microtask, the HTML content is available---then for example, listeners can
|
21
|
+
* be attached to elements inside.
|
22
|
+
*/
|
23
|
+
mount() { }
|
24
|
+
/** Called when custom element is added to the page. */
|
25
|
+
connectedCallback() {
|
26
|
+
queueMicrotask(() => this.mount());
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* Passed into `disconnectedCallback`, since `Base` needs to run `disconnectedCallback` as well. It is overridden in each element that needs to run `disconnectedCallback`.
|
30
|
+
*/
|
31
|
+
destroy() { }
|
32
|
+
/** Called when custom element is removed from the page. */
|
33
|
+
disconnectedCallback() {
|
34
|
+
this.destroy();
|
35
|
+
this.#listenerController.abort();
|
36
|
+
}
|
37
|
+
};
|
38
|
+
/**
|
39
|
+
* By default, `trigger`s are selected via the `data-trigger` attribute.
|
40
|
+
* Alternatively, you can set the `trigger` attribute to a CSS selector to
|
41
|
+
* change the default selector from `[data-trigger]` to a selector of your
|
42
|
+
* choosing. This can be useful if you have multiple elements within one another.
|
43
|
+
*
|
44
|
+
* Each element can have multiple `trigger`s.
|
45
|
+
*/
|
46
|
+
export const Trigger = (Super = HTMLElement) => class Trigger extends Super {
|
4
47
|
constructor(...args) {
|
5
|
-
super(args);
|
48
|
+
super(...args);
|
6
49
|
}
|
7
50
|
/**
|
8
51
|
* Event for the `trigger` to execute.
|
@@ -17,26 +60,46 @@ export const Trigger = (Super) => class Trigger extends Super {
|
|
17
60
|
set event(value) {
|
18
61
|
this.setAttribute("event", value);
|
19
62
|
}
|
20
|
-
|
63
|
+
triggers(instance = HTMLElement) {
|
21
64
|
const triggers = this.querySelectorAll(this.getAttribute("trigger") ?? "[data-trigger]");
|
22
65
|
for (const trigger of triggers)
|
23
66
|
validate(trigger, instance);
|
24
67
|
return triggers;
|
25
68
|
}
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
69
|
+
listener(listenerOrType, listenerOrOptions, optionsMaybe) {
|
70
|
+
let type;
|
71
|
+
let listener;
|
72
|
+
let options;
|
73
|
+
if (typeof listenerOrType === "function") {
|
74
|
+
// (listener, options?)
|
75
|
+
type = this.event;
|
76
|
+
listener = listenerOrType;
|
77
|
+
options = listenerOrOptions;
|
78
|
+
}
|
79
|
+
else {
|
80
|
+
// (type, listener, options?)
|
81
|
+
type = listenerOrType;
|
82
|
+
listener = listenerOrOptions;
|
83
|
+
options = optionsMaybe;
|
84
|
+
}
|
85
|
+
for (const trigger of this.triggers()) {
|
31
86
|
trigger.addEventListener(type, listener, options);
|
32
87
|
}
|
33
88
|
}
|
34
89
|
};
|
35
|
-
|
90
|
+
/**
|
91
|
+
* By default, `content` is selected via the `data-content` attribute.
|
92
|
+
* Alternatively, you can set the `trigger` to a CSS selector to change
|
93
|
+
* the default selector from `[data-trigger]` to a selector of your choosing.
|
94
|
+
* This can be useful if you have multiple elements within one another.
|
95
|
+
*
|
96
|
+
* Each element can only have one `content`.
|
97
|
+
*/
|
98
|
+
export const Content = (Super = HTMLElement) => class Content extends Super {
|
36
99
|
constructor(...args) {
|
37
|
-
super(args);
|
100
|
+
super(...args);
|
38
101
|
}
|
39
|
-
|
102
|
+
content(instance = HTMLElement) {
|
40
103
|
return validate(this.querySelector(this.getAttribute("content") ?? "[data-content]"), instance);
|
41
104
|
}
|
42
105
|
/**
|
@@ -46,12 +109,12 @@ export const Content = (Super) => class Content extends Super {
|
|
46
109
|
* @param revert Wait time (ms) before swapping back, set to `false` to not revert.
|
47
110
|
* default: `800`
|
48
111
|
*/
|
49
|
-
|
112
|
+
swap(revert = 800) {
|
50
113
|
/** The swap element, used to hold the replacement contents. */
|
51
|
-
const
|
52
|
-
if (
|
114
|
+
const swapTarget = this.querySelector(this.getAttribute("swap") ?? "[data-swap]");
|
115
|
+
if (swapTarget) {
|
53
116
|
/** A copy of the content currently in `this.getContent()`. */
|
54
|
-
const currentContent = this.
|
117
|
+
const currentContent = this.content().childNodes;
|
55
118
|
/**
|
56
119
|
* The contents of the swap element, set based on whether the
|
57
120
|
* swap is a `template` or not.
|
@@ -59,68 +122,33 @@ export const Content = (Super) => class Content extends Super {
|
|
59
122
|
const placeholder = [];
|
60
123
|
// Set the placeholder with the `swap` content, then replace the
|
61
124
|
// swap content with the `currentContent`
|
62
|
-
if (
|
125
|
+
if (swapTarget instanceof HTMLTemplateElement) {
|
63
126
|
// use `content` since it's a `template` element
|
64
|
-
placeholder.push(
|
65
|
-
|
127
|
+
placeholder.push(swapTarget.content.cloneNode(true));
|
128
|
+
swapTarget.content.replaceChildren(...currentContent);
|
66
129
|
}
|
67
130
|
else {
|
68
131
|
// not a `template`, replace children directly
|
69
|
-
placeholder.push(...
|
70
|
-
|
132
|
+
placeholder.push(...swapTarget.childNodes);
|
133
|
+
swapTarget.replaceChildren(...currentContent);
|
71
134
|
}
|
72
135
|
// finally, set the content to the contents of the placeholder
|
73
|
-
this.
|
136
|
+
this.content().replaceChildren(...placeholder);
|
74
137
|
if (revert) {
|
75
138
|
// wait and then run again to swap back
|
76
|
-
setTimeout(() => this.
|
139
|
+
setTimeout(() => this.swap(0), revert);
|
77
140
|
}
|
78
141
|
}
|
79
142
|
}
|
80
143
|
};
|
81
|
-
export const
|
82
|
-
/** To clean up event listeners added to `document` when the element is removed. */
|
83
|
-
#listenerController = new AbortController();
|
84
|
-
constructor(...args) {
|
85
|
-
super(args);
|
86
|
-
}
|
87
|
-
safeListener(type, listener, target = document.body, options = {}) {
|
88
|
-
options.signal = this.#listenerController.signal;
|
89
|
-
target.addEventListener(type, listener, options);
|
90
|
-
}
|
91
|
-
/**
|
92
|
-
* Passed into `queueMicrotask` in `connectedCallback`.
|
93
|
-
* It is overridden in each component that needs to run `connectedCallback`.
|
94
|
-
*
|
95
|
-
* The reason for this is to make these elements work better with frameworks like Svelte.
|
96
|
-
* For SSR this isn't necessary, but when client side rendering, the HTML within the
|
97
|
-
* custom element isn't available before `connectedCallback` is called. By waiting until
|
98
|
-
* the next microtask, the HTML content is available---then for example, listeners can
|
99
|
-
* be attached to elements inside.
|
100
|
-
*/
|
101
|
-
mount() { }
|
102
|
-
/** Called when custom element is added to the page. */
|
103
|
-
connectedCallback() {
|
104
|
-
queueMicrotask(() => this.mount());
|
105
|
-
}
|
106
|
-
/**
|
107
|
-
* Passed into `disconnectedCallback`, since `Base` needs to run `disconnectedCallback` as well. It is overridden in each element that needs to run `disconnectedCallback`.
|
108
|
-
*/
|
109
|
-
destroy() { }
|
110
|
-
/** Called when custom element is removed from the page. */
|
111
|
-
disconnectedCallback() {
|
112
|
-
this.destroy();
|
113
|
-
this.#listenerController.abort();
|
114
|
-
}
|
115
|
-
};
|
116
|
-
export const Announce = (Super) => class Announce extends Super {
|
144
|
+
export const Announce = (Super = HTMLElement) => class Announce extends Super {
|
117
145
|
/**
|
118
146
|
* A single `Announcer` element to share between all drab elements to announce
|
119
147
|
* interactive changes.
|
120
148
|
*/
|
121
149
|
static #announcer = Announcer.init();
|
122
150
|
constructor(...args) {
|
123
|
-
super(args);
|
151
|
+
super(...args);
|
124
152
|
}
|
125
153
|
/**
|
126
154
|
* @param message message to announce to screen readers
|
@@ -129,20 +157,3 @@ export const Announce = (Super) => class Announce extends Super {
|
|
129
157
|
Announce.#announcer.announce(message);
|
130
158
|
}
|
131
159
|
};
|
132
|
-
/**
|
133
|
-
* Each element in the library extends the `Base` class. It provides methods
|
134
|
-
* for selecting elements via HTML attributes along with other helpers.
|
135
|
-
*
|
136
|
-
* By default, `trigger`s and `content` will be selected via the `data-trigger` and
|
137
|
-
* `data-content` attributes. Alternatively, you can set the `trigger` or
|
138
|
-
* `content` attribute to a CSS selector to change the default selector from
|
139
|
-
* `[data-trigger]` or `[data-content]` to a selector of your choosing.
|
140
|
-
* This can be useful if you have multiple elements within one another.
|
141
|
-
*
|
142
|
-
* Each element can have multiple `trigger`s, but will only have one `content`.
|
143
|
-
*/
|
144
|
-
export class Base extends Trigger(Content(Lifecycle(Announce(HTMLElement)))) {
|
145
|
-
constructor() {
|
146
|
-
super();
|
147
|
-
}
|
148
|
-
}
|