vrembem 3.0.10 → 3.0.13
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/LICENSE +1 -1
- package/dev/scripts.esm.js +721 -818
- package/dev/scripts.esm.js.map +1 -1
- package/dev/scripts.js +721 -818
- package/dev/scripts.js.map +1 -1
- package/dev/scripts.modern.mjs +584 -545
- package/dev/scripts.modern.mjs.map +1 -1
- package/dev/scripts.umd.js +723 -820
- package/dev/scripts.umd.js.map +1 -1
- package/dev/styles.css +69 -69
- package/dev/styles.css.map +1 -1
- package/dist/scripts.esm.js +1 -1
- package/dist/scripts.esm.js.map +1 -1
- package/dist/scripts.js +1 -1
- package/dist/scripts.js.map +1 -1
- package/dist/scripts.modern.mjs +1 -1
- package/dist/scripts.modern.mjs.map +1 -1
- package/dist/scripts.umd.js +1 -1
- package/dist/scripts.umd.js.map +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +28 -28
package/dev/scripts.modern.mjs
CHANGED
|
@@ -2,35 +2,28 @@ function _extends() {
|
|
|
2
2
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
3
3
|
for (var i = 1; i < arguments.length; i++) {
|
|
4
4
|
var source = arguments[i];
|
|
5
|
-
|
|
6
5
|
for (var key in source) {
|
|
7
6
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
8
7
|
target[key] = source[key];
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
return target;
|
|
14
12
|
};
|
|
15
13
|
return _extends.apply(this, arguments);
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
var id = 0;
|
|
19
|
-
|
|
20
16
|
function _classPrivateFieldLooseKey(name) {
|
|
21
17
|
return "__private_" + id++ + "_" + name;
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
function _classPrivateFieldLooseBase(receiver, privateKey) {
|
|
25
20
|
if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
|
|
26
21
|
throw new TypeError("attempted to use private field on non-instance");
|
|
27
22
|
}
|
|
28
|
-
|
|
29
23
|
return receiver;
|
|
30
24
|
}
|
|
31
25
|
|
|
32
26
|
var _handler = /*#__PURE__*/_classPrivateFieldLooseKey("handler");
|
|
33
|
-
|
|
34
27
|
class Breakpoint {
|
|
35
28
|
constructor(value, handler) {
|
|
36
29
|
Object.defineProperty(this, _handler, {
|
|
@@ -41,12 +34,11 @@ class Breakpoint {
|
|
|
41
34
|
_classPrivateFieldLooseBase(this, _handler)[_handler] = handler;
|
|
42
35
|
this.mql = null;
|
|
43
36
|
}
|
|
44
|
-
|
|
45
37
|
get handler() {
|
|
46
38
|
return _classPrivateFieldLooseBase(this, _handler)[_handler];
|
|
47
|
-
}
|
|
48
|
-
|
|
39
|
+
}
|
|
49
40
|
|
|
41
|
+
// Unmount existing handler before setting a new one.
|
|
50
42
|
set handler(func) {
|
|
51
43
|
if (this.mql) {
|
|
52
44
|
// Conditionally use removeListener() for IE11 support.
|
|
@@ -56,66 +48,62 @@ class Breakpoint {
|
|
|
56
48
|
this.mql.removeListener(_classPrivateFieldLooseBase(this, _handler)[_handler]);
|
|
57
49
|
}
|
|
58
50
|
}
|
|
59
|
-
|
|
60
51
|
_classPrivateFieldLooseBase(this, _handler)[_handler] = func;
|
|
61
52
|
}
|
|
62
|
-
|
|
63
53
|
mount(value, handler) {
|
|
64
54
|
// Update passed params.
|
|
65
55
|
if (value) this.value = value;
|
|
66
|
-
if (handler) _classPrivateFieldLooseBase(this, _handler)[_handler] = handler;
|
|
56
|
+
if (handler) _classPrivateFieldLooseBase(this, _handler)[_handler] = handler;
|
|
67
57
|
|
|
68
|
-
|
|
58
|
+
// Guard if no breakpoint was set.
|
|
59
|
+
if (!this.value) return this;
|
|
69
60
|
|
|
70
|
-
|
|
61
|
+
// Setup and store the MediaQueryList instance.
|
|
62
|
+
this.mql = window.matchMedia(`(min-width: ${this.value})`);
|
|
71
63
|
|
|
64
|
+
// Conditionally use addListener() for IE11 support.
|
|
72
65
|
if (typeof this.mql.addEventListener === 'function') {
|
|
73
66
|
this.mql.addEventListener('change', _classPrivateFieldLooseBase(this, _handler)[_handler]);
|
|
74
67
|
} else {
|
|
75
68
|
this.mql.addListener(_classPrivateFieldLooseBase(this, _handler)[_handler]);
|
|
76
|
-
}
|
|
77
|
-
|
|
69
|
+
}
|
|
78
70
|
|
|
71
|
+
// Run the handler.
|
|
79
72
|
_classPrivateFieldLooseBase(this, _handler)[_handler](this.mql);
|
|
80
|
-
|
|
81
73
|
return this;
|
|
82
74
|
}
|
|
83
|
-
|
|
84
75
|
unmount() {
|
|
85
76
|
// Guard if no MediaQueryList instance exists.
|
|
86
|
-
if (!this.mql) return this;
|
|
77
|
+
if (!this.mql) return this;
|
|
87
78
|
|
|
79
|
+
// Conditionally use removeListener() for IE11 support.
|
|
88
80
|
if (typeof this.mql.removeEventListener === 'function') {
|
|
89
81
|
this.mql.removeEventListener('change', _classPrivateFieldLooseBase(this, _handler)[_handler]);
|
|
90
82
|
} else {
|
|
91
83
|
this.mql.removeListener(_classPrivateFieldLooseBase(this, _handler)[_handler]);
|
|
92
|
-
}
|
|
93
|
-
|
|
84
|
+
}
|
|
94
85
|
|
|
86
|
+
// Set value, handler and MediaQueryList to null.
|
|
95
87
|
this.value = null;
|
|
96
88
|
_classPrivateFieldLooseBase(this, _handler)[_handler] = null;
|
|
97
89
|
this.mql = null;
|
|
98
90
|
return this;
|
|
99
91
|
}
|
|
100
|
-
|
|
101
92
|
}
|
|
102
93
|
|
|
103
94
|
class Collection {
|
|
104
95
|
constructor() {
|
|
105
96
|
this.collection = [];
|
|
106
97
|
}
|
|
107
|
-
|
|
108
98
|
async register(item) {
|
|
109
99
|
await this.deregister(item);
|
|
110
100
|
this.collection.push(item);
|
|
111
101
|
return this.collection;
|
|
112
102
|
}
|
|
113
|
-
|
|
114
103
|
async deregister(ref) {
|
|
115
104
|
const index = this.collection.findIndex(entry => {
|
|
116
105
|
return entry === ref;
|
|
117
106
|
});
|
|
118
|
-
|
|
119
107
|
if (index >= 0) {
|
|
120
108
|
const entry = this.collection[index];
|
|
121
109
|
Object.getOwnPropertyNames(entry).forEach(prop => {
|
|
@@ -123,54 +111,55 @@ class Collection {
|
|
|
123
111
|
});
|
|
124
112
|
this.collection.splice(index, 1);
|
|
125
113
|
}
|
|
126
|
-
|
|
127
114
|
return this.collection;
|
|
128
115
|
}
|
|
129
|
-
|
|
130
116
|
async registerCollection(items) {
|
|
131
117
|
await Promise.all(Array.from(items, item => {
|
|
132
118
|
this.register(item);
|
|
133
119
|
}));
|
|
134
120
|
return this.collection;
|
|
135
121
|
}
|
|
136
|
-
|
|
137
122
|
async deregisterCollection() {
|
|
138
123
|
while (this.collection.length > 0) {
|
|
139
124
|
await this.deregister(this.collection[0]);
|
|
140
125
|
}
|
|
141
|
-
|
|
142
126
|
return this.collection;
|
|
143
127
|
}
|
|
144
|
-
|
|
145
128
|
get(value, key = 'id') {
|
|
146
129
|
return this.collection.find(item => {
|
|
147
130
|
return item[key] === value;
|
|
148
131
|
});
|
|
149
132
|
}
|
|
150
|
-
|
|
151
133
|
}
|
|
152
134
|
|
|
153
|
-
|
|
154
|
-
'
|
|
155
|
-
'
|
|
156
|
-
'
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
135
|
+
const not = {
|
|
136
|
+
inert: ':not([inert]):not([inert] *)',
|
|
137
|
+
negTabIndex: ':not([tabindex^="-"])',
|
|
138
|
+
disabled: ':not(:disabled)',
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
var e = [
|
|
142
|
+
`a[href]${not.inert}${not.negTabIndex}`,
|
|
143
|
+
`area[href]${not.inert}${not.negTabIndex}`,
|
|
144
|
+
`input:not([type="hidden"]):not([type="radio"])${not.inert}${not.negTabIndex}${not.disabled}`,
|
|
145
|
+
`input[type="radio"]${not.inert}${not.negTabIndex}${not.disabled}`,
|
|
146
|
+
`select${not.inert}${not.negTabIndex}${not.disabled}`,
|
|
147
|
+
`textarea${not.inert}${not.negTabIndex}${not.disabled}`,
|
|
148
|
+
`button${not.inert}${not.negTabIndex}${not.disabled}`,
|
|
149
|
+
`details${not.inert} > summary:first-of-type${not.negTabIndex}`,
|
|
150
|
+
// Discard until Firefox supports `:has()`
|
|
151
|
+
// See: https://github.com/KittyGiraudel/focusable-selectors/issues/12
|
|
152
|
+
// `details:not(:has(> summary))${not.inert}${not.negTabIndex}`,
|
|
153
|
+
`iframe${not.inert}${not.negTabIndex}`,
|
|
154
|
+
`audio[controls]${not.inert}${not.negTabIndex}`,
|
|
155
|
+
`video[controls]${not.inert}${not.negTabIndex}`,
|
|
156
|
+
`[contenteditable]${not.inert}${not.negTabIndex}`,
|
|
157
|
+
`[tabindex]${not.inert}${not.negTabIndex}`,
|
|
166
158
|
];
|
|
167
159
|
|
|
168
160
|
var _focusable = /*#__PURE__*/_classPrivateFieldLooseKey("focusable");
|
|
169
|
-
|
|
170
161
|
var _handleFocusTrap = /*#__PURE__*/_classPrivateFieldLooseKey("handleFocusTrap");
|
|
171
|
-
|
|
172
162
|
var _handleFocusLock = /*#__PURE__*/_classPrivateFieldLooseKey("handleFocusLock");
|
|
173
|
-
|
|
174
163
|
class FocusTrap {
|
|
175
164
|
constructor(el = null, selectorFocus = '[data-focus]') {
|
|
176
165
|
Object.defineProperty(this, _focusable, {
|
|
@@ -190,15 +179,14 @@ class FocusTrap {
|
|
|
190
179
|
_classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap] = handleFocusTrap.bind(this);
|
|
191
180
|
_classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock] = handleFocusLock.bind(this);
|
|
192
181
|
}
|
|
193
|
-
|
|
194
182
|
get focusable() {
|
|
195
183
|
return _classPrivateFieldLooseBase(this, _focusable)[_focusable];
|
|
196
184
|
}
|
|
197
|
-
|
|
198
185
|
set focusable(value) {
|
|
199
186
|
// Update the focusable value.
|
|
200
|
-
_classPrivateFieldLooseBase(this, _focusable)[_focusable] = value;
|
|
187
|
+
_classPrivateFieldLooseBase(this, _focusable)[_focusable] = value;
|
|
201
188
|
|
|
189
|
+
// Apply event listeners based on new focusable array length.
|
|
202
190
|
if (_classPrivateFieldLooseBase(this, _focusable)[_focusable].length) {
|
|
203
191
|
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock]);
|
|
204
192
|
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap]);
|
|
@@ -207,74 +195,76 @@ class FocusTrap {
|
|
|
207
195
|
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock]);
|
|
208
196
|
}
|
|
209
197
|
}
|
|
210
|
-
|
|
211
198
|
get focusableFirst() {
|
|
212
199
|
return this.focusable[0];
|
|
213
200
|
}
|
|
214
|
-
|
|
215
201
|
get focusableLast() {
|
|
216
202
|
return this.focusable[this.focusable.length - 1];
|
|
217
203
|
}
|
|
218
|
-
|
|
219
204
|
mount(el, selectorFocus) {
|
|
220
205
|
// Update passed params.
|
|
221
206
|
if (el) this.el = el;
|
|
222
|
-
if (selectorFocus) this.selectorFocus = selectorFocus;
|
|
207
|
+
if (selectorFocus) this.selectorFocus = selectorFocus;
|
|
223
208
|
|
|
224
|
-
|
|
209
|
+
// Get the focusable elements.
|
|
210
|
+
this.focusable = this.getFocusable();
|
|
225
211
|
|
|
212
|
+
// Set the focus on the element.
|
|
226
213
|
this.focus();
|
|
227
214
|
}
|
|
228
|
-
|
|
229
215
|
unmount() {
|
|
230
216
|
// Set element to null.
|
|
231
|
-
this.el = null;
|
|
217
|
+
this.el = null;
|
|
232
218
|
|
|
233
|
-
|
|
219
|
+
// Apply empty array to focusable.
|
|
220
|
+
this.focusable = [];
|
|
234
221
|
|
|
222
|
+
// Remove event listeners
|
|
235
223
|
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap]);
|
|
236
224
|
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock]);
|
|
237
225
|
}
|
|
238
|
-
|
|
239
226
|
focus(el = this.el, selectorFocus = this.selectorFocus) {
|
|
240
227
|
// Query for the focus selector, otherwise return this element.
|
|
241
|
-
const result = el.querySelector(selectorFocus) || el;
|
|
242
|
-
|
|
228
|
+
const result = el.querySelector(selectorFocus) || el;
|
|
229
|
+
// Give the returned element focus.
|
|
243
230
|
result.focus();
|
|
244
231
|
}
|
|
245
|
-
|
|
246
232
|
getFocusable(el = this.el) {
|
|
247
233
|
// Initialize the focusable array.
|
|
248
|
-
const focusable = [];
|
|
234
|
+
const focusable = [];
|
|
249
235
|
|
|
236
|
+
// Store the initial focus and scroll position.
|
|
250
237
|
const initFocus = document.activeElement;
|
|
251
|
-
const initScrollTop = el.scrollTop;
|
|
238
|
+
const initScrollTop = el.scrollTop;
|
|
252
239
|
|
|
253
|
-
|
|
240
|
+
// Query for all the focusable elements.
|
|
241
|
+
const els = el.querySelectorAll(e.join(','));
|
|
254
242
|
|
|
243
|
+
// Loop through all focusable elements.
|
|
255
244
|
els.forEach(el => {
|
|
256
245
|
// Set them to focus and check
|
|
257
|
-
el.focus();
|
|
258
|
-
|
|
246
|
+
el.focus();
|
|
247
|
+
// Test that the element took focus.
|
|
259
248
|
if (document.activeElement === el) {
|
|
260
249
|
// Add element to the focusable array.
|
|
261
250
|
focusable.push(el);
|
|
262
251
|
}
|
|
263
|
-
});
|
|
252
|
+
});
|
|
264
253
|
|
|
254
|
+
// Restore the initial scroll position and focus.
|
|
265
255
|
el.scrollTop = initScrollTop;
|
|
266
|
-
initFocus.focus();
|
|
256
|
+
initFocus.focus();
|
|
267
257
|
|
|
258
|
+
// Return the focusable array.
|
|
268
259
|
return focusable;
|
|
269
260
|
}
|
|
270
|
-
|
|
271
261
|
}
|
|
272
|
-
|
|
273
262
|
function handleFocusTrap(event) {
|
|
274
263
|
// Check if the click was a tab and return if not.
|
|
275
264
|
const isTab = event.key === 'Tab' || event.keyCode === 9;
|
|
276
|
-
if (!isTab) return;
|
|
265
|
+
if (!isTab) return;
|
|
277
266
|
|
|
267
|
+
// If the shift key is pressed.
|
|
278
268
|
if (event.shiftKey) {
|
|
279
269
|
// If the active element is either the root el or first focusable.
|
|
280
270
|
if (document.activeElement === this.focusableFirst || document.activeElement === this.el) {
|
|
@@ -291,7 +281,6 @@ function handleFocusTrap(event) {
|
|
|
291
281
|
}
|
|
292
282
|
}
|
|
293
283
|
}
|
|
294
|
-
|
|
295
284
|
function handleFocusLock(event) {
|
|
296
285
|
// Ignore the tab key by preventing default.
|
|
297
286
|
const isTab = event.key === 'Tab' || event.keyCode === 9;
|
|
@@ -315,18 +304,15 @@ function localStore(key, enable = true) {
|
|
|
315
304
|
get(prop) {
|
|
316
305
|
return prop ? store[prop] : store;
|
|
317
306
|
},
|
|
318
|
-
|
|
319
307
|
set(prop, value) {
|
|
320
308
|
if (value) {
|
|
321
309
|
store[prop] = value;
|
|
322
310
|
} else {
|
|
323
311
|
delete store[prop];
|
|
324
312
|
}
|
|
325
|
-
|
|
326
313
|
if (enable) localStorage.setItem(key, JSON.stringify(store));
|
|
327
314
|
return store;
|
|
328
315
|
}
|
|
329
|
-
|
|
330
316
|
};
|
|
331
317
|
}
|
|
332
318
|
|
|
@@ -344,31 +330,37 @@ function localStore(key, enable = true) {
|
|
|
344
330
|
function teleport(what, where, how) {
|
|
345
331
|
// Check if ref is either a comment or element node.
|
|
346
332
|
const isComment = where.nodeType === Node.COMMENT_NODE;
|
|
347
|
-
const isElement = where.nodeType === Node.ELEMENT_NODE;
|
|
333
|
+
const isElement = where.nodeType === Node.ELEMENT_NODE;
|
|
348
334
|
|
|
349
|
-
|
|
335
|
+
// Get the reference element.
|
|
336
|
+
where = isComment || isElement ? where : document.querySelector(where);
|
|
350
337
|
|
|
351
|
-
|
|
338
|
+
// If ref is a comment, set teleport type to 'after'.
|
|
339
|
+
if (isComment) how = 'after';
|
|
352
340
|
|
|
341
|
+
// Must be a valid reference element and method.
|
|
353
342
|
if (!where) throw new Error(`Not a valid teleport reference: '${where}'`);
|
|
354
|
-
if (typeof where[how] != 'function') throw new Error(`Not a valid teleport method: '${how}'`);
|
|
343
|
+
if (typeof where[how] != 'function') throw new Error(`Not a valid teleport method: '${how}'`);
|
|
355
344
|
|
|
356
|
-
|
|
345
|
+
// Initial return ref is null.
|
|
346
|
+
let returnRef = null;
|
|
357
347
|
|
|
348
|
+
// If ref is not a comment, set a return reference comment.
|
|
358
349
|
if (!isComment) {
|
|
359
350
|
returnRef = document.createComment('teleported #' + what.id);
|
|
360
351
|
what.before(returnRef);
|
|
361
|
-
}
|
|
362
|
-
|
|
352
|
+
}
|
|
363
353
|
|
|
364
|
-
|
|
354
|
+
// Teleport the target node.
|
|
355
|
+
where[how](what);
|
|
365
356
|
|
|
357
|
+
// Delete the comment node if element was returned to a comment reference.
|
|
366
358
|
if (isComment) {
|
|
367
359
|
where.remove();
|
|
368
|
-
}
|
|
369
|
-
// returned to a comment reference.
|
|
370
|
-
|
|
360
|
+
}
|
|
371
361
|
|
|
362
|
+
// Return the return reference if it was teleported else return null if it was
|
|
363
|
+
// returned to a comment reference.
|
|
372
364
|
return returnRef;
|
|
373
365
|
}
|
|
374
366
|
|
|
@@ -421,7 +413,6 @@ function setOverflowHidden(state, selector) {
|
|
|
421
413
|
});
|
|
422
414
|
}
|
|
423
415
|
}
|
|
424
|
-
|
|
425
416
|
function setInert(state, selector) {
|
|
426
417
|
if (selector) {
|
|
427
418
|
const els = document.querySelectorAll(selector);
|
|
@@ -436,11 +427,11 @@ function setInert(state, selector) {
|
|
|
436
427
|
});
|
|
437
428
|
}
|
|
438
429
|
}
|
|
439
|
-
|
|
440
430
|
function updateGlobalState(param, config) {
|
|
441
431
|
// Set inert state based on if a modal is active.
|
|
442
|
-
setInert(!!param, config.selectorInert);
|
|
432
|
+
setInert(!!param, config.selectorInert);
|
|
443
433
|
|
|
434
|
+
// Set overflow state based on if a modal is active.
|
|
444
435
|
setOverflowHidden(!!param, config.selectorOverflow);
|
|
445
436
|
}
|
|
446
437
|
|
|
@@ -471,7 +462,6 @@ class Checkbox {
|
|
|
471
462
|
this.__handlerClick = this.handlerClick.bind(this);
|
|
472
463
|
if (this.settings.autoInit) this.init();
|
|
473
464
|
}
|
|
474
|
-
|
|
475
465
|
init(options = null) {
|
|
476
466
|
if (options) this.settings = _extends({}, this.settings, options);
|
|
477
467
|
const selector = `[${this.settings.stateAttr}="${this.settings.stateValue}"]`;
|
|
@@ -479,11 +469,9 @@ class Checkbox {
|
|
|
479
469
|
this.setIndeterminate(mixed);
|
|
480
470
|
document.addEventListener('click', this.__handlerClick, false);
|
|
481
471
|
}
|
|
482
|
-
|
|
483
472
|
destroy() {
|
|
484
473
|
document.removeEventListener('click', this.__handlerClick, false);
|
|
485
474
|
}
|
|
486
|
-
|
|
487
475
|
handlerClick(event) {
|
|
488
476
|
const selector = `[${this.settings.stateAttr}="${this.settings.stateValue}"]`;
|
|
489
477
|
const el = event.target.closest(selector);
|
|
@@ -491,21 +479,18 @@ class Checkbox {
|
|
|
491
479
|
this.removeAriaState(el);
|
|
492
480
|
this.setIndeterminate(el);
|
|
493
481
|
}
|
|
494
|
-
|
|
495
482
|
setAriaState(el, value = this.settings.stateValue) {
|
|
496
483
|
el = el.forEach ? el : [el];
|
|
497
484
|
el.forEach(el => {
|
|
498
485
|
el.setAttribute(this.settings.stateAttr, value);
|
|
499
486
|
});
|
|
500
487
|
}
|
|
501
|
-
|
|
502
488
|
removeAriaState(el) {
|
|
503
489
|
el = el.forEach ? el : [el];
|
|
504
490
|
el.forEach(el => {
|
|
505
491
|
el.removeAttribute(this.settings.stateAttr);
|
|
506
492
|
});
|
|
507
493
|
}
|
|
508
|
-
|
|
509
494
|
setIndeterminate(el) {
|
|
510
495
|
el = el.forEach ? el : [el];
|
|
511
496
|
el.forEach(el => {
|
|
@@ -516,7 +501,6 @@ class Checkbox {
|
|
|
516
501
|
}
|
|
517
502
|
});
|
|
518
503
|
}
|
|
519
|
-
|
|
520
504
|
}
|
|
521
505
|
|
|
522
506
|
var defaults$2 = {
|
|
@@ -557,60 +541,59 @@ function handleClick$2(event) {
|
|
|
557
541
|
[data-${this.settings.dataToggle}],
|
|
558
542
|
[data-${this.settings.dataClose}]
|
|
559
543
|
`);
|
|
560
|
-
|
|
561
544
|
if (trigger) {
|
|
562
545
|
// Prevent the default behavior of the trigger.
|
|
563
|
-
event.preventDefault();
|
|
546
|
+
event.preventDefault();
|
|
564
547
|
|
|
548
|
+
// If it's a toggle trigger...
|
|
565
549
|
if (trigger.matches(`[data-${this.settings.dataToggle}]`)) {
|
|
566
550
|
const selectors = trigger.getAttribute(`data-${this.settings.dataToggle}`).trim().split(' ');
|
|
567
551
|
selectors.forEach(selector => {
|
|
568
552
|
// Get the entry from collection using the attribute value.
|
|
569
|
-
const entry = this.get(selector);
|
|
570
|
-
|
|
571
|
-
entry.trigger = trigger;
|
|
572
|
-
|
|
553
|
+
const entry = this.get(selector);
|
|
554
|
+
// Store the trigger on the entry.
|
|
555
|
+
entry.trigger = trigger;
|
|
556
|
+
// Toggle the drawer
|
|
573
557
|
entry.toggle();
|
|
574
558
|
});
|
|
575
|
-
}
|
|
576
|
-
|
|
559
|
+
}
|
|
577
560
|
|
|
561
|
+
// If it's a open trigger...
|
|
578
562
|
if (trigger.matches(`[data-${this.settings.dataOpen}]`)) {
|
|
579
563
|
const selectors = trigger.getAttribute(`data-${this.settings.dataOpen}`).trim().split(' ');
|
|
580
564
|
selectors.forEach(selector => {
|
|
581
565
|
// Get the entry from collection using the attribute value.
|
|
582
|
-
const entry = this.get(selector);
|
|
583
|
-
|
|
584
|
-
entry.trigger = trigger;
|
|
585
|
-
|
|
566
|
+
const entry = this.get(selector);
|
|
567
|
+
// Store the trigger on the entry.
|
|
568
|
+
entry.trigger = trigger;
|
|
569
|
+
// Open the drawer.
|
|
586
570
|
entry.open();
|
|
587
571
|
});
|
|
588
|
-
}
|
|
589
|
-
|
|
572
|
+
}
|
|
590
573
|
|
|
574
|
+
// If it's a close trigger...
|
|
591
575
|
if (trigger.matches(`[data-${this.settings.dataClose}]`)) {
|
|
592
576
|
const selectors = trigger.getAttribute(`data-${this.settings.dataClose}`).trim().split(' ');
|
|
593
577
|
selectors.forEach(selector => {
|
|
594
578
|
if (selector) {
|
|
595
579
|
// Get the entry from collection using the attribute value.
|
|
596
|
-
const entry = this.get(selector);
|
|
597
|
-
|
|
598
|
-
entry.trigger = trigger;
|
|
599
|
-
|
|
580
|
+
const entry = this.get(selector);
|
|
581
|
+
// Store the trigger on the entry.
|
|
582
|
+
entry.trigger = trigger;
|
|
583
|
+
// Close the drawer.
|
|
600
584
|
entry.close();
|
|
601
585
|
} else {
|
|
602
586
|
// If no value is set on close trigger, get the parent drawer.
|
|
603
|
-
const parent = event.target.closest(this.settings.selectorDrawer);
|
|
604
|
-
|
|
587
|
+
const parent = event.target.closest(this.settings.selectorDrawer);
|
|
588
|
+
// If a parent drawer was found, close it.
|
|
605
589
|
if (parent) this.close(parent);
|
|
606
590
|
}
|
|
607
591
|
});
|
|
608
592
|
}
|
|
609
|
-
|
|
610
593
|
return;
|
|
611
|
-
}
|
|
612
|
-
|
|
594
|
+
}
|
|
613
595
|
|
|
596
|
+
// If the modal drawer screen was clicked...
|
|
614
597
|
if (event.target.matches(this.settings.selectorDrawer)) {
|
|
615
598
|
// Close the modal drawer.
|
|
616
599
|
this.close(event.target.id);
|
|
@@ -625,34 +608,38 @@ function handleKeydown$2(event) {
|
|
|
625
608
|
|
|
626
609
|
async function deregister$2(obj, close = true) {
|
|
627
610
|
// Return collection if nothing was passed.
|
|
628
|
-
if (!obj) return this.collection;
|
|
611
|
+
if (!obj) return this.collection;
|
|
629
612
|
|
|
613
|
+
// Check if entry has been registered in the collection.
|
|
630
614
|
const index = this.collection.findIndex(entry => {
|
|
631
615
|
return entry.id === obj.id;
|
|
632
616
|
});
|
|
633
|
-
|
|
634
617
|
if (index >= 0) {
|
|
635
618
|
// Get the collection entry.
|
|
636
|
-
const entry = this.collection[index];
|
|
619
|
+
const entry = this.collection[index];
|
|
637
620
|
|
|
621
|
+
// If entry is in the opened state.
|
|
638
622
|
if (close && entry.state === 'opened') {
|
|
639
623
|
// Close the drawer.
|
|
640
624
|
await entry.close(false);
|
|
641
|
-
}
|
|
642
|
-
|
|
625
|
+
}
|
|
643
626
|
|
|
644
|
-
|
|
627
|
+
// Remove entry from local store.
|
|
628
|
+
this.store.set(entry.id);
|
|
645
629
|
|
|
646
|
-
|
|
630
|
+
// Unmount the MatchMedia functionality.
|
|
631
|
+
entry.unmountBreakpoint();
|
|
647
632
|
|
|
633
|
+
// Delete properties from collection entry.
|
|
648
634
|
Object.getOwnPropertyNames(entry).forEach(prop => {
|
|
649
635
|
delete entry[prop];
|
|
650
|
-
});
|
|
636
|
+
});
|
|
651
637
|
|
|
638
|
+
// Remove entry from collection.
|
|
652
639
|
this.collection.splice(index, 1);
|
|
653
|
-
}
|
|
654
|
-
|
|
640
|
+
}
|
|
655
641
|
|
|
642
|
+
// Return the modified collection.
|
|
656
643
|
return this.collection;
|
|
657
644
|
}
|
|
658
645
|
|
|
@@ -663,7 +650,6 @@ function g() {
|
|
|
663
650
|
function getBreakpoint(drawer) {
|
|
664
651
|
const prefix = g();
|
|
665
652
|
const bp = drawer.getAttribute(`data-${this.settings.dataBreakpoint}`);
|
|
666
|
-
|
|
667
653
|
if (this.settings.breakpoints && this.settings.breakpoints[bp]) {
|
|
668
654
|
return this.settings.breakpoints[bp];
|
|
669
655
|
} else if (getComputedStyle(document.body).getPropertyValue(`--${prefix}breakpoint-${bp}`).trim()) {
|
|
@@ -675,8 +661,9 @@ function getBreakpoint(drawer) {
|
|
|
675
661
|
|
|
676
662
|
function getDrawer(query) {
|
|
677
663
|
// Get the entry from collection.
|
|
678
|
-
const entry = typeof query === 'string' ? this.get(query) : this.get(query.id);
|
|
664
|
+
const entry = typeof query === 'string' ? this.get(query) : this.get(query.id);
|
|
679
665
|
|
|
666
|
+
// Return entry if it was resolved, otherwise throw error.
|
|
680
667
|
if (entry) {
|
|
681
668
|
return entry;
|
|
682
669
|
} else {
|
|
@@ -688,37 +675,49 @@ function getDrawerID(obj) {
|
|
|
688
675
|
// If it's a string, return the string.
|
|
689
676
|
if (typeof obj === 'string') {
|
|
690
677
|
return obj;
|
|
691
|
-
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// If it's an HTML element.
|
|
692
681
|
else if (typeof obj.hasAttribute === 'function') {
|
|
693
682
|
// If it's a drawer open trigger, return data value.
|
|
694
683
|
if (obj.hasAttribute(`data-${this.settings.dataOpen}`)) {
|
|
695
684
|
return obj.getAttribute(`data-${this.settings.dataOpen}`);
|
|
696
|
-
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// If it's a drawer close trigger, return data value or false.
|
|
697
688
|
else if (obj.hasAttribute(`data-${this.settings.dataClose}`)) {
|
|
698
689
|
return obj.getAttribute(`data-${this.settings.dataClose}`) || false;
|
|
699
|
-
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// If it's a drawer toggle trigger, return data value.
|
|
700
693
|
else if (obj.hasAttribute(`data-${this.settings.dataToggle}`)) {
|
|
701
694
|
return obj.getAttribute(`data-${this.settings.dataToggle}`);
|
|
702
|
-
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// If it's a drawer element, return the id.
|
|
703
698
|
else if (obj.closest(this.settings.selectorDrawer)) {
|
|
704
699
|
obj = obj.closest(this.settings.selectorDrawer);
|
|
705
700
|
return obj.id || false;
|
|
706
|
-
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// Return false if no id was found.
|
|
707
704
|
else return false;
|
|
708
|
-
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// If it has an id property, return its value.
|
|
709
708
|
else if (obj.id) {
|
|
710
709
|
return obj.id;
|
|
711
|
-
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
// Return false if no id was found.
|
|
712
713
|
else return false;
|
|
713
714
|
}
|
|
714
715
|
|
|
715
716
|
function getDrawerElements(query) {
|
|
716
717
|
const id = getDrawerID.call(this, query);
|
|
717
|
-
|
|
718
718
|
if (id) {
|
|
719
719
|
const drawer = document.querySelector(`#${id}`);
|
|
720
720
|
const dialog = drawer ? drawer.querySelector(this.settings.selectorDialog) : null;
|
|
721
|
-
|
|
722
721
|
if (!drawer && !dialog) {
|
|
723
722
|
return {
|
|
724
723
|
error: new Error(`No drawer elements found using the ID: "${id}".`)
|
|
@@ -758,8 +757,8 @@ async function initialState(entry) {
|
|
|
758
757
|
} else {
|
|
759
758
|
// Remove transition state classes.
|
|
760
759
|
entry.el.classList.remove(this.settings.stateOpening);
|
|
761
|
-
entry.el.classList.remove(this.settings.stateClosing);
|
|
762
|
-
|
|
760
|
+
entry.el.classList.remove(this.settings.stateClosing);
|
|
761
|
+
// Add closed state class.
|
|
763
762
|
entry.el.classList.add(this.settings.stateClosed);
|
|
764
763
|
}
|
|
765
764
|
}
|
|
@@ -779,85 +778,98 @@ function updateFocusState$1(entry) {
|
|
|
779
778
|
entry.trigger.focus();
|
|
780
779
|
entry.trigger = null;
|
|
781
780
|
}
|
|
782
|
-
|
|
783
781
|
this.focusTrap.unmount();
|
|
784
782
|
}
|
|
785
783
|
}
|
|
786
784
|
|
|
787
785
|
async function open$2(query, transition, focus = true) {
|
|
788
786
|
// Get the drawer from collection.
|
|
789
|
-
const drawer = getDrawer.call(this, query);
|
|
790
|
-
|
|
791
|
-
const config = _extends({}, this.settings, drawer.settings); // Add transition parameter to configuration.
|
|
787
|
+
const drawer = getDrawer.call(this, query);
|
|
792
788
|
|
|
789
|
+
// Get the modal configuration.
|
|
790
|
+
const config = _extends({}, this.settings, drawer.settings);
|
|
793
791
|
|
|
794
|
-
|
|
792
|
+
// Add transition parameter to configuration.
|
|
793
|
+
if (transition !== undefined) config.transition = transition;
|
|
795
794
|
|
|
795
|
+
// If drawer is closed.
|
|
796
796
|
if (drawer.state === 'closed') {
|
|
797
797
|
// Update drawer state.
|
|
798
|
-
drawer.state = 'opening';
|
|
798
|
+
drawer.state = 'opening';
|
|
799
799
|
|
|
800
|
-
|
|
800
|
+
// Run the open transition.
|
|
801
|
+
await openTransition(drawer.el, config);
|
|
801
802
|
|
|
802
|
-
|
|
803
|
+
// Update the global state if mode is modal.
|
|
804
|
+
if (drawer.mode === 'modal') updateGlobalState(true, config);
|
|
803
805
|
|
|
806
|
+
// Update drawer state.
|
|
804
807
|
drawer.state = 'opened';
|
|
805
|
-
}
|
|
806
|
-
|
|
808
|
+
}
|
|
807
809
|
|
|
810
|
+
// Set focus to the drawer element if the focus param is true.
|
|
808
811
|
if (focus) {
|
|
809
812
|
updateFocusState$1.call(this, drawer);
|
|
810
|
-
}
|
|
811
|
-
|
|
813
|
+
}
|
|
812
814
|
|
|
815
|
+
// Dispatch custom opened event.
|
|
813
816
|
drawer.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'opened', {
|
|
814
817
|
detail: this,
|
|
815
818
|
bubbles: true
|
|
816
|
-
}));
|
|
819
|
+
}));
|
|
817
820
|
|
|
821
|
+
// Return the drawer.
|
|
818
822
|
return drawer;
|
|
819
823
|
}
|
|
820
824
|
|
|
821
825
|
async function close$2(query, transition, focus = true) {
|
|
822
826
|
// Get the drawer from collection.
|
|
823
|
-
const drawer = getDrawer.call(this, query);
|
|
827
|
+
const drawer = getDrawer.call(this, query);
|
|
824
828
|
|
|
825
|
-
|
|
829
|
+
// Get the modal configuration.
|
|
830
|
+
const config = _extends({}, this.settings, drawer.settings);
|
|
826
831
|
|
|
832
|
+
// Add transition parameter to configuration.
|
|
833
|
+
if (transition !== undefined) config.transition = transition;
|
|
827
834
|
|
|
828
|
-
|
|
829
|
-
|
|
835
|
+
// If drawer is opened.
|
|
830
836
|
if (drawer.state === 'opened') {
|
|
831
837
|
// Update drawer state.
|
|
832
|
-
drawer.state = 'closing';
|
|
838
|
+
drawer.state = 'closing';
|
|
833
839
|
|
|
834
|
-
|
|
840
|
+
// Remove focus from active element.
|
|
841
|
+
document.activeElement.blur();
|
|
835
842
|
|
|
836
|
-
|
|
843
|
+
// Run the close transition.
|
|
844
|
+
await closeTransition(drawer.el, config);
|
|
837
845
|
|
|
838
|
-
|
|
846
|
+
// Update the global state if mode is modal.
|
|
847
|
+
if (drawer.mode === 'modal') updateGlobalState(false, config);
|
|
839
848
|
|
|
849
|
+
// Set focus to the trigger element if the focus param is true.
|
|
840
850
|
if (focus) {
|
|
841
851
|
updateFocusState$1.call(this, drawer);
|
|
842
|
-
}
|
|
843
|
-
|
|
852
|
+
}
|
|
844
853
|
|
|
845
|
-
|
|
854
|
+
// Update drawer state.
|
|
855
|
+
drawer.state = 'closed';
|
|
846
856
|
|
|
857
|
+
// Dispatch custom closed event.
|
|
847
858
|
drawer.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'closed', {
|
|
848
859
|
detail: this,
|
|
849
860
|
bubbles: true
|
|
850
861
|
}));
|
|
851
|
-
}
|
|
852
|
-
|
|
862
|
+
}
|
|
853
863
|
|
|
864
|
+
// Return the drawer.
|
|
854
865
|
return drawer;
|
|
855
866
|
}
|
|
856
867
|
|
|
857
868
|
async function toggle(query, transition, focus) {
|
|
858
869
|
// Get the drawer from collection.
|
|
859
|
-
const drawer = getDrawer.call(this, query);
|
|
870
|
+
const drawer = getDrawer.call(this, query);
|
|
860
871
|
|
|
872
|
+
// Open or close the drawer based on its current state.
|
|
861
873
|
if (drawer.state === 'closed') {
|
|
862
874
|
return open$2.call(this, drawer, transition, focus);
|
|
863
875
|
} else {
|
|
@@ -869,179 +881,175 @@ function switchMode(entry) {
|
|
|
869
881
|
switch (entry.mode) {
|
|
870
882
|
case 'inline':
|
|
871
883
|
return toInline.call(this, entry);
|
|
872
|
-
|
|
873
884
|
case 'modal':
|
|
874
885
|
return toModal.call(this, entry);
|
|
875
|
-
|
|
876
886
|
default:
|
|
877
887
|
throw new Error(`"${entry.mode}" is not a valid drawer mode.`);
|
|
878
888
|
}
|
|
879
889
|
}
|
|
880
|
-
|
|
881
890
|
async function toInline(entry) {
|
|
882
891
|
// Remove the modal class.
|
|
883
|
-
entry.el.classList.remove(entry.getSetting('classModal'));
|
|
892
|
+
entry.el.classList.remove(entry.getSetting('classModal'));
|
|
884
893
|
|
|
885
|
-
|
|
894
|
+
// Remove the aria-modal attribute.
|
|
895
|
+
entry.dialog.removeAttribute('aria-modal');
|
|
886
896
|
|
|
887
|
-
|
|
897
|
+
// Update the global state.
|
|
898
|
+
updateGlobalState(false, _extends({}, this.settings, entry.settings));
|
|
888
899
|
|
|
889
|
-
|
|
900
|
+
// Remove any focus traps.
|
|
901
|
+
this.focusTrap.unmount();
|
|
890
902
|
|
|
891
|
-
|
|
903
|
+
// Setup initial state.
|
|
904
|
+
await initialState.call(this, entry);
|
|
892
905
|
|
|
906
|
+
// Dispatch custom switch event.
|
|
893
907
|
entry.el.dispatchEvent(new CustomEvent(entry.getSetting('customEventPrefix') + 'switchMode', {
|
|
894
908
|
detail: this,
|
|
895
909
|
bubbles: true
|
|
896
|
-
}));
|
|
910
|
+
}));
|
|
897
911
|
|
|
912
|
+
// Return the entry.
|
|
898
913
|
return entry;
|
|
899
914
|
}
|
|
900
|
-
|
|
901
915
|
async function toModal(entry) {
|
|
902
916
|
// Get the drawer configuration.
|
|
917
|
+
|
|
903
918
|
// Add the modal class.
|
|
904
|
-
entry.el.classList.add(entry.getSetting('classModal'));
|
|
919
|
+
entry.el.classList.add(entry.getSetting('classModal'));
|
|
905
920
|
|
|
906
|
-
|
|
921
|
+
// Set aria-modal attribute to true.
|
|
922
|
+
entry.dialog.setAttribute('aria-modal', 'true');
|
|
907
923
|
|
|
924
|
+
// If there isn't a stored state but also has the opened state class...
|
|
908
925
|
if (!this.store.get(entry.id) && entry.el.classList.contains(entry.getSetting('stateOpened'))) {
|
|
909
926
|
// Save the opened state in local store.
|
|
910
927
|
this.store.set(entry.id, 'opened');
|
|
911
|
-
}
|
|
912
|
-
|
|
928
|
+
}
|
|
913
929
|
|
|
914
|
-
|
|
930
|
+
// Modal drawer defaults to closed state.
|
|
931
|
+
await close$2.call(this, entry, false, false);
|
|
915
932
|
|
|
933
|
+
// Dispatch custom switch event.
|
|
916
934
|
entry.el.dispatchEvent(new CustomEvent(entry.getSetting('customEventPrefix') + 'switchMode', {
|
|
917
935
|
detail: this,
|
|
918
936
|
bubbles: true
|
|
919
|
-
}));
|
|
937
|
+
}));
|
|
920
938
|
|
|
939
|
+
// Return the entry.
|
|
921
940
|
return entry;
|
|
922
941
|
}
|
|
923
942
|
|
|
924
943
|
async function register$2(el, dialog) {
|
|
925
944
|
// Deregister entry incase it has already been registered.
|
|
926
|
-
await deregister$2.call(this, el, false);
|
|
945
|
+
await deregister$2.call(this, el, false);
|
|
927
946
|
|
|
928
|
-
|
|
947
|
+
// Save root this for use inside methods API.
|
|
948
|
+
const root = this;
|
|
929
949
|
|
|
930
|
-
|
|
950
|
+
// Create an instance of the Breakpoint class.
|
|
951
|
+
const breakpoint = new Breakpoint();
|
|
931
952
|
|
|
953
|
+
// Setup methods API.
|
|
932
954
|
const methods = {
|
|
933
955
|
open(transition, focus) {
|
|
934
956
|
return open$2.call(root, this, transition, focus);
|
|
935
957
|
},
|
|
936
|
-
|
|
937
958
|
close(transition, focus) {
|
|
938
959
|
return close$2.call(root, this, transition, focus);
|
|
939
960
|
},
|
|
940
|
-
|
|
941
961
|
toggle(transition, focus) {
|
|
942
962
|
return toggle.call(root, this, transition, focus);
|
|
943
963
|
},
|
|
944
|
-
|
|
945
964
|
deregister() {
|
|
946
965
|
return deregister$2.call(root, this);
|
|
947
966
|
},
|
|
948
|
-
|
|
949
967
|
mountBreakpoint() {
|
|
950
968
|
const value = this.breakpoint;
|
|
951
969
|
const handler = this.handleBreakpoint.bind(this);
|
|
952
970
|
breakpoint.mount(value, handler);
|
|
953
971
|
return this;
|
|
954
972
|
},
|
|
955
|
-
|
|
956
973
|
unmountBreakpoint() {
|
|
957
974
|
breakpoint.unmount();
|
|
958
975
|
return this;
|
|
959
976
|
},
|
|
960
|
-
|
|
961
977
|
handleBreakpoint(event) {
|
|
962
978
|
this.mode = event.matches ? 'inline' : 'modal';
|
|
963
979
|
return this;
|
|
964
980
|
},
|
|
965
|
-
|
|
966
981
|
getSetting(key) {
|
|
967
982
|
return key in this.settings ? this.settings[key] : root.settings[key];
|
|
968
983
|
}
|
|
984
|
+
};
|
|
969
985
|
|
|
970
|
-
|
|
971
|
-
|
|
986
|
+
// Setup the drawer object.
|
|
972
987
|
const entry = _extends({
|
|
973
988
|
id: el.id,
|
|
974
989
|
el: el,
|
|
975
990
|
dialog: dialog,
|
|
976
991
|
trigger: null,
|
|
977
992
|
settings: getConfig$1(el, this.settings.dataConfig),
|
|
978
|
-
|
|
979
993
|
get breakpoint() {
|
|
980
994
|
return getBreakpoint.call(root, el);
|
|
981
995
|
},
|
|
982
|
-
|
|
983
996
|
get state() {
|
|
984
997
|
return __state;
|
|
985
998
|
},
|
|
986
|
-
|
|
987
999
|
set state(value) {
|
|
988
|
-
__state = value;
|
|
989
|
-
|
|
1000
|
+
__state = value;
|
|
1001
|
+
// Save 'opened' and 'closed' states to store if mode is inline.
|
|
990
1002
|
if (value === 'opened' || value === 'closed') {
|
|
991
1003
|
if (this.mode === 'inline') root.store.set(this.id, this.state);
|
|
992
1004
|
}
|
|
993
1005
|
},
|
|
994
|
-
|
|
995
1006
|
get mode() {
|
|
996
1007
|
return __mode;
|
|
997
1008
|
},
|
|
998
|
-
|
|
999
1009
|
set mode(value) {
|
|
1000
1010
|
__mode = value;
|
|
1001
1011
|
switchMode.call(root, this);
|
|
1002
1012
|
}
|
|
1013
|
+
}, methods);
|
|
1003
1014
|
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
let __state = el.classList.contains(entry.getSetting('stateOpened')) ? 'opened' : 'closed'; // Create the mode var with the initial mode.
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
let __mode = el.classList.contains(entry.getSetting('classModal')) ? 'modal' : 'inline'; // Setup mode specific attributes.
|
|
1015
|
+
// Create the state var with the initial state.
|
|
1016
|
+
let __state = el.classList.contains(entry.getSetting('stateOpened')) ? 'opened' : 'closed';
|
|
1011
1017
|
|
|
1018
|
+
// Create the mode var with the initial mode.
|
|
1019
|
+
let __mode = el.classList.contains(entry.getSetting('classModal')) ? 'modal' : 'inline';
|
|
1012
1020
|
|
|
1021
|
+
// Setup mode specific attributes.
|
|
1013
1022
|
if (entry.mode === 'modal') {
|
|
1014
1023
|
// Set aria-modal attribute to true.
|
|
1015
1024
|
entry.dialog.setAttribute('aria-modal', 'true');
|
|
1016
1025
|
} else {
|
|
1017
1026
|
// Remove the aria-modal attribute.
|
|
1018
1027
|
entry.dialog.removeAttribute('aria-modal');
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1028
|
+
}
|
|
1021
1029
|
|
|
1030
|
+
// Set tabindex="-1" so dialog is focusable via JS or click.
|
|
1022
1031
|
if (entry.getSetting('setTabindex')) {
|
|
1023
1032
|
entry.dialog.setAttribute('tabindex', '-1');
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1033
|
+
}
|
|
1026
1034
|
|
|
1027
|
-
|
|
1035
|
+
// Add entry to collection.
|
|
1036
|
+
this.collection.push(entry);
|
|
1028
1037
|
|
|
1038
|
+
// If the entry has a breakpoint...
|
|
1029
1039
|
if (entry.breakpoint) {
|
|
1030
1040
|
// Mount media query breakpoint functionality.
|
|
1031
1041
|
entry.mountBreakpoint();
|
|
1032
1042
|
} else {
|
|
1033
1043
|
// Else, Setup initial state.
|
|
1034
1044
|
await initialState.call(this, entry);
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1045
|
+
}
|
|
1037
1046
|
|
|
1047
|
+
// Return the registered entry.
|
|
1038
1048
|
return entry;
|
|
1039
1049
|
}
|
|
1040
1050
|
|
|
1041
1051
|
var _handleClick$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
|
|
1042
|
-
|
|
1043
1052
|
var _handleKeydown$2 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
|
|
1044
|
-
|
|
1045
1053
|
class Drawer extends Collection {
|
|
1046
1054
|
constructor(options) {
|
|
1047
1055
|
super();
|
|
@@ -1055,81 +1063,71 @@ class Drawer extends Collection {
|
|
|
1055
1063
|
});
|
|
1056
1064
|
this.defaults = defaults$2;
|
|
1057
1065
|
this.settings = _extends({}, this.defaults, options);
|
|
1058
|
-
this.focusTrap = new FocusTrap();
|
|
1066
|
+
this.focusTrap = new FocusTrap();
|
|
1059
1067
|
|
|
1068
|
+
// Setup local store for inline drawer state management.
|
|
1060
1069
|
this.store = localStore(this.settings.storeKey, this.settings.store);
|
|
1061
1070
|
_classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1] = handleClick$2.bind(this);
|
|
1062
1071
|
_classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2] = handleKeydown$2.bind(this);
|
|
1063
1072
|
if (this.settings.autoInit) this.init();
|
|
1064
1073
|
}
|
|
1065
|
-
|
|
1066
1074
|
get activeModal() {
|
|
1067
1075
|
return this.collection.find(entry => {
|
|
1068
1076
|
return entry.state === 'opened' && entry.mode === 'modal';
|
|
1069
1077
|
});
|
|
1070
1078
|
}
|
|
1071
|
-
|
|
1072
1079
|
async init(options = null) {
|
|
1073
1080
|
// Update settings with passed options.
|
|
1074
|
-
if (options) this.settings = _extends({}, this.settings, options);
|
|
1081
|
+
if (options) this.settings = _extends({}, this.settings, options);
|
|
1075
1082
|
|
|
1076
|
-
|
|
1083
|
+
// Get all the modals.
|
|
1084
|
+
const drawers = document.querySelectorAll(this.settings.selectorDrawer);
|
|
1077
1085
|
|
|
1078
|
-
|
|
1086
|
+
// Register the collections array with modal instances.
|
|
1087
|
+
await this.registerCollection(drawers);
|
|
1079
1088
|
|
|
1089
|
+
// If eventListeners are enabled, init event listeners.
|
|
1080
1090
|
if (this.settings.eventListeners) {
|
|
1081
1091
|
this.initEventListeners();
|
|
1082
1092
|
}
|
|
1083
|
-
|
|
1084
1093
|
return this;
|
|
1085
1094
|
}
|
|
1086
|
-
|
|
1087
1095
|
async destroy() {
|
|
1088
1096
|
// Remove all entries from the collection.
|
|
1089
|
-
await this.deregisterCollection();
|
|
1097
|
+
await this.deregisterCollection();
|
|
1090
1098
|
|
|
1099
|
+
// If eventListeners are enabled, init event listeners.
|
|
1091
1100
|
if (this.settings.eventListeners) {
|
|
1092
1101
|
this.destroyEventListeners();
|
|
1093
1102
|
}
|
|
1094
|
-
|
|
1095
1103
|
return this;
|
|
1096
1104
|
}
|
|
1097
|
-
|
|
1098
1105
|
initEventListeners() {
|
|
1099
1106
|
document.addEventListener('click', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1100
|
-
document.addEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1101
1107
|
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2], false);
|
|
1102
1108
|
}
|
|
1103
|
-
|
|
1104
1109
|
destroyEventListeners() {
|
|
1105
1110
|
document.removeEventListener('click', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1106
|
-
document.removeEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1107
1111
|
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2], false);
|
|
1108
1112
|
}
|
|
1109
|
-
|
|
1110
1113
|
register(query) {
|
|
1111
1114
|
const els = getDrawerElements.call(this, query);
|
|
1112
1115
|
if (els.error) return Promise.reject(els.error);
|
|
1113
1116
|
return register$2.call(this, els.drawer, els.dialog);
|
|
1114
1117
|
}
|
|
1115
|
-
|
|
1116
1118
|
deregister(query) {
|
|
1117
1119
|
const entry = this.get(getDrawerID.call(this, query));
|
|
1118
1120
|
return deregister$2.call(this, entry);
|
|
1119
1121
|
}
|
|
1120
|
-
|
|
1121
1122
|
open(id, transition, focus) {
|
|
1122
1123
|
return open$2.call(this, id, transition, focus);
|
|
1123
1124
|
}
|
|
1124
|
-
|
|
1125
1125
|
close(id, transition, focus) {
|
|
1126
1126
|
return close$2.call(this, id, transition, focus);
|
|
1127
1127
|
}
|
|
1128
|
-
|
|
1129
1128
|
toggle(id, transition, focus) {
|
|
1130
1129
|
return toggle.call(this, id, transition, focus);
|
|
1131
1130
|
}
|
|
1132
|
-
|
|
1133
1131
|
}
|
|
1134
1132
|
|
|
1135
1133
|
var defaults$1 = {
|
|
@@ -1162,8 +1160,9 @@ var defaults$1 = {
|
|
|
1162
1160
|
|
|
1163
1161
|
function getModal(query) {
|
|
1164
1162
|
// Get the entry from collection.
|
|
1165
|
-
const entry = typeof query === 'string' ? this.get(query) : this.get(query.id);
|
|
1163
|
+
const entry = typeof query === 'string' ? this.get(query) : this.get(query.id);
|
|
1166
1164
|
|
|
1165
|
+
// Return entry if it was resolved, otherwise throw error.
|
|
1167
1166
|
if (entry) {
|
|
1168
1167
|
return entry;
|
|
1169
1168
|
} else {
|
|
@@ -1175,37 +1174,49 @@ function getModalID(obj) {
|
|
|
1175
1174
|
// If it's a string, return the string.
|
|
1176
1175
|
if (typeof obj === 'string') {
|
|
1177
1176
|
return obj;
|
|
1178
|
-
}
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
// If it's an HTML element.
|
|
1179
1180
|
else if (typeof obj.hasAttribute === 'function') {
|
|
1180
1181
|
// If it's a modal open trigger, return data value.
|
|
1181
1182
|
if (obj.hasAttribute(`data-${this.settings.dataOpen}`)) {
|
|
1182
1183
|
return obj.getAttribute(`data-${this.settings.dataOpen}`);
|
|
1183
|
-
}
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// If it's a modal close trigger, return data value or false.
|
|
1184
1187
|
else if (obj.hasAttribute(`data-${this.settings.dataClose}`)) {
|
|
1185
1188
|
return obj.getAttribute(`data-${this.settings.dataClose}`) || false;
|
|
1186
|
-
}
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
// If it's a modal replace trigger, return data value.
|
|
1187
1192
|
else if (obj.hasAttribute(`data-${this.settings.dataReplace}`)) {
|
|
1188
1193
|
return obj.getAttribute(`data-${this.settings.dataReplace}`);
|
|
1189
|
-
}
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
// If it's a modal element, return the id.
|
|
1190
1197
|
else if (obj.closest(this.settings.selectorModal)) {
|
|
1191
1198
|
obj = obj.closest(this.settings.selectorModal);
|
|
1192
1199
|
return obj.id || false;
|
|
1193
|
-
}
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
// Return false if no id was found.
|
|
1194
1203
|
else return false;
|
|
1195
|
-
}
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
// If it has an id property, return its value.
|
|
1196
1207
|
else if (obj.id) {
|
|
1197
1208
|
return obj.id;
|
|
1198
|
-
}
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
// Return false if no id was found.
|
|
1199
1212
|
else return false;
|
|
1200
1213
|
}
|
|
1201
1214
|
|
|
1202
1215
|
function getModalElements(query) {
|
|
1203
1216
|
const id = getModalID.call(this, query);
|
|
1204
|
-
|
|
1205
1217
|
if (id) {
|
|
1206
1218
|
const modal = document.querySelector(`#${id}`);
|
|
1207
1219
|
const dialog = modal ? modal.querySelector(this.settings.selectorDialog) : null;
|
|
1208
|
-
|
|
1209
1220
|
if (!modal && !dialog) {
|
|
1210
1221
|
return {
|
|
1211
1222
|
error: new Error(`No modal elements found using the ID: "${id}".`)
|
|
@@ -1238,7 +1249,6 @@ function updateFocusState() {
|
|
|
1238
1249
|
this.trigger.focus();
|
|
1239
1250
|
this.trigger = null;
|
|
1240
1251
|
}
|
|
1241
|
-
|
|
1242
1252
|
this.focusTrap.unmount();
|
|
1243
1253
|
}
|
|
1244
1254
|
}
|
|
@@ -1246,30 +1256,28 @@ function updateFocusState() {
|
|
|
1246
1256
|
async function handleClick$1(event) {
|
|
1247
1257
|
// If an open or replace button was clicked, open or replace the modal.
|
|
1248
1258
|
let trigger = event.target.closest(`[data-${this.settings.dataOpen}], [data-${this.settings.dataReplace}]`);
|
|
1249
|
-
|
|
1250
1259
|
if (trigger) {
|
|
1251
|
-
event.preventDefault();
|
|
1252
|
-
|
|
1260
|
+
event.preventDefault();
|
|
1261
|
+
// Save the trigger if it's not coming from inside a modal.
|
|
1253
1262
|
const fromModal = event.target.closest(this.settings.selectorModal);
|
|
1254
|
-
if (!fromModal) this.trigger = trigger;
|
|
1255
|
-
|
|
1256
|
-
const modal = this.get(getModalID.call(this, trigger));
|
|
1257
|
-
|
|
1263
|
+
if (!fromModal) this.trigger = trigger;
|
|
1264
|
+
// Get the modal.
|
|
1265
|
+
const modal = this.get(getModalID.call(this, trigger));
|
|
1266
|
+
// Depending on the button type, either open or replace the modal.
|
|
1258
1267
|
return trigger.matches(`[data-${this.settings.dataOpen}]`) ? modal.open() : modal.replace();
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1268
|
+
}
|
|
1261
1269
|
|
|
1270
|
+
// If a close button was clicked, close the modal.
|
|
1262
1271
|
trigger = event.target.closest(`[data-${this.settings.dataClose}]`);
|
|
1263
|
-
|
|
1264
1272
|
if (trigger) {
|
|
1265
|
-
event.preventDefault();
|
|
1266
|
-
|
|
1267
|
-
const value = trigger.getAttribute(`data-${this.settings.dataClose}`);
|
|
1268
|
-
|
|
1273
|
+
event.preventDefault();
|
|
1274
|
+
// Get the value of the data attribute.
|
|
1275
|
+
const value = trigger.getAttribute(`data-${this.settings.dataClose}`);
|
|
1276
|
+
// Close all if * wildcard is passed, otherwise close a single modal.
|
|
1269
1277
|
return value === '*' ? this.closeAll() : this.close(value);
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1278
|
+
}
|
|
1272
1279
|
|
|
1280
|
+
// If the modal screen was clicked, close the modal.
|
|
1273
1281
|
if (event.target.matches(this.settings.selectorModal) && !event.target.querySelector(this.settings.selectorRequired)) {
|
|
1274
1282
|
return this.close(getModalID.call(this, event.target));
|
|
1275
1283
|
}
|
|
@@ -1286,109 +1294,125 @@ function handleKeydown$1(event) {
|
|
|
1286
1294
|
|
|
1287
1295
|
async function deregister$1(obj, close = true) {
|
|
1288
1296
|
// Return collection if nothing was passed.
|
|
1289
|
-
if (!obj) return this.collection;
|
|
1297
|
+
if (!obj) return this.collection;
|
|
1290
1298
|
|
|
1299
|
+
// Check if entry has been registered in the collection.
|
|
1291
1300
|
const index = this.collection.findIndex(entry => {
|
|
1292
1301
|
return entry.id === obj.id;
|
|
1293
1302
|
});
|
|
1294
|
-
|
|
1295
1303
|
if (index >= 0) {
|
|
1296
1304
|
// Get the collection entry.
|
|
1297
|
-
const entry = this.collection[index];
|
|
1305
|
+
const entry = this.collection[index];
|
|
1298
1306
|
|
|
1307
|
+
// If entry is in the opened state, close it.
|
|
1299
1308
|
if (close && entry.state === 'opened') {
|
|
1300
1309
|
await entry.close(false);
|
|
1301
1310
|
} else {
|
|
1302
1311
|
// Remove modal from stack.
|
|
1303
1312
|
this.stack.remove(entry);
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1313
|
+
}
|
|
1306
1314
|
|
|
1315
|
+
// Return teleported modal if a reference has been set.
|
|
1307
1316
|
if (entry.getSetting('teleport')) {
|
|
1308
1317
|
entry.teleportReturn();
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1318
|
+
}
|
|
1311
1319
|
|
|
1320
|
+
// Delete properties from collection entry.
|
|
1312
1321
|
Object.getOwnPropertyNames(entry).forEach(prop => {
|
|
1313
1322
|
delete entry[prop];
|
|
1314
|
-
});
|
|
1323
|
+
});
|
|
1315
1324
|
|
|
1325
|
+
// Remove entry from collection.
|
|
1316
1326
|
this.collection.splice(index, 1);
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1327
|
+
}
|
|
1319
1328
|
|
|
1329
|
+
// Return the modified collection.
|
|
1320
1330
|
return this.collection;
|
|
1321
1331
|
}
|
|
1322
1332
|
|
|
1323
1333
|
async function open$1(query, transition, focus = true) {
|
|
1324
1334
|
// Get the modal from collection.
|
|
1325
|
-
const modal = getModal.call(this, query);
|
|
1335
|
+
const modal = getModal.call(this, query);
|
|
1326
1336
|
|
|
1327
|
-
|
|
1337
|
+
// Get the modal configuration.
|
|
1338
|
+
const config = _extends({}, this.settings, modal.settings);
|
|
1328
1339
|
|
|
1340
|
+
// Add transition parameter to configuration.
|
|
1341
|
+
if (transition !== undefined) config.transition = transition;
|
|
1329
1342
|
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
this.stack.moveToTop(modal); // If modal is closed.
|
|
1343
|
+
// Maybe add modal to top of stack.
|
|
1344
|
+
this.stack.moveToTop(modal);
|
|
1333
1345
|
|
|
1346
|
+
// If modal is closed.
|
|
1334
1347
|
if (modal.state === 'closed') {
|
|
1335
1348
|
// Update modal state.
|
|
1336
|
-
modal.state = 'opening';
|
|
1349
|
+
modal.state = 'opening';
|
|
1337
1350
|
|
|
1338
|
-
|
|
1351
|
+
// Add modal to stack.
|
|
1352
|
+
this.stack.add(modal);
|
|
1339
1353
|
|
|
1340
|
-
|
|
1354
|
+
// Run the open transition.
|
|
1355
|
+
await openTransition(modal.el, config);
|
|
1341
1356
|
|
|
1357
|
+
// Update modal state.
|
|
1342
1358
|
modal.state = 'opened';
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1359
|
+
}
|
|
1345
1360
|
|
|
1361
|
+
// Update focus if the focus param is true.
|
|
1346
1362
|
if (focus) {
|
|
1347
1363
|
updateFocusState.call(this);
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1364
|
+
}
|
|
1350
1365
|
|
|
1366
|
+
// Dispatch custom opened event.
|
|
1351
1367
|
modal.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'opened', {
|
|
1352
1368
|
detail: this,
|
|
1353
1369
|
bubbles: true
|
|
1354
|
-
}));
|
|
1370
|
+
}));
|
|
1355
1371
|
|
|
1372
|
+
// Return the modal.
|
|
1356
1373
|
return modal;
|
|
1357
1374
|
}
|
|
1358
1375
|
|
|
1359
1376
|
async function close$1(query, transition, focus = true) {
|
|
1360
1377
|
// Get the modal from collection, or top modal in stack if no query is provided.
|
|
1361
|
-
const modal = query ? getModal.call(this, query) : this.active;
|
|
1378
|
+
const modal = query ? getModal.call(this, query) : this.active;
|
|
1362
1379
|
|
|
1380
|
+
// If a modal exists and its state is opened.
|
|
1363
1381
|
if (modal && modal.state === 'opened') {
|
|
1364
1382
|
// Update modal state.
|
|
1365
|
-
modal.state = 'closing';
|
|
1366
|
-
|
|
1367
|
-
const config = _extends({}, this.settings, modal.settings); // Add transition parameter to configuration.
|
|
1383
|
+
modal.state = 'closing';
|
|
1368
1384
|
|
|
1385
|
+
// Get the modal configuration.
|
|
1386
|
+
const config = _extends({}, this.settings, modal.settings);
|
|
1369
1387
|
|
|
1370
|
-
|
|
1388
|
+
// Add transition parameter to configuration.
|
|
1389
|
+
if (transition !== undefined) config.transition = transition;
|
|
1371
1390
|
|
|
1372
|
-
|
|
1391
|
+
// Remove focus from active element.
|
|
1392
|
+
document.activeElement.blur();
|
|
1373
1393
|
|
|
1374
|
-
|
|
1394
|
+
// Run the close transition.
|
|
1395
|
+
await closeTransition(modal.el, config);
|
|
1375
1396
|
|
|
1376
|
-
|
|
1397
|
+
// Remove modal from stack.
|
|
1398
|
+
this.stack.remove(modal);
|
|
1377
1399
|
|
|
1400
|
+
// Update focus if the focus param is true.
|
|
1378
1401
|
if (focus) {
|
|
1379
1402
|
updateFocusState.call(this);
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1403
|
+
}
|
|
1382
1404
|
|
|
1383
|
-
|
|
1405
|
+
// Update modal state.
|
|
1406
|
+
modal.state = 'closed';
|
|
1384
1407
|
|
|
1408
|
+
// Dispatch custom closed event.
|
|
1385
1409
|
modal.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'closed', {
|
|
1386
1410
|
detail: this,
|
|
1387
1411
|
bubbles: true
|
|
1388
1412
|
}));
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1413
|
+
}
|
|
1391
1414
|
|
|
1415
|
+
// Return the modal.
|
|
1392
1416
|
return modal;
|
|
1393
1417
|
}
|
|
1394
1418
|
|
|
@@ -1400,7 +1424,6 @@ async function closeAll$1(exclude, transition) {
|
|
|
1400
1424
|
} else {
|
|
1401
1425
|
result.push(await close$1.call(this, modal, transition, false));
|
|
1402
1426
|
}
|
|
1403
|
-
|
|
1404
1427
|
modal.trigger = null;
|
|
1405
1428
|
}));
|
|
1406
1429
|
return result;
|
|
@@ -1408,10 +1431,10 @@ async function closeAll$1(exclude, transition) {
|
|
|
1408
1431
|
|
|
1409
1432
|
async function replace(query, transition, focus = true) {
|
|
1410
1433
|
// Get the modal from collection.
|
|
1411
|
-
const modal = getModal.call(this, query);
|
|
1434
|
+
const modal = getModal.call(this, query);
|
|
1412
1435
|
|
|
1436
|
+
// Setup results for return.
|
|
1413
1437
|
let resultOpened, resultClosed;
|
|
1414
|
-
|
|
1415
1438
|
if (modal.state === 'opened') {
|
|
1416
1439
|
// If modal is open, close all modals except for replacement.
|
|
1417
1440
|
resultOpened = modal;
|
|
@@ -1421,14 +1444,14 @@ async function replace(query, transition, focus = true) {
|
|
|
1421
1444
|
resultOpened = open$1.call(this, modal, transition, false);
|
|
1422
1445
|
resultClosed = closeAll$1.call(this, false, transition);
|
|
1423
1446
|
await Promise.all([resultOpened, resultClosed]);
|
|
1424
|
-
}
|
|
1425
|
-
|
|
1447
|
+
}
|
|
1426
1448
|
|
|
1449
|
+
// Update focus if the focus param is true.
|
|
1427
1450
|
if (focus) {
|
|
1428
1451
|
updateFocusState.call(this);
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1452
|
+
}
|
|
1431
1453
|
|
|
1454
|
+
// Return the modals there were opened and closed.
|
|
1432
1455
|
return {
|
|
1433
1456
|
opened: resultOpened,
|
|
1434
1457
|
closed: resultClosed
|
|
@@ -1437,27 +1460,25 @@ async function replace(query, transition, focus = true) {
|
|
|
1437
1460
|
|
|
1438
1461
|
async function register$1(el, dialog) {
|
|
1439
1462
|
// Deregister entry incase it has already been registered.
|
|
1440
|
-
await deregister$1.call(this, el, false);
|
|
1463
|
+
await deregister$1.call(this, el, false);
|
|
1441
1464
|
|
|
1442
|
-
|
|
1465
|
+
// Save root this for use inside methods API.
|
|
1466
|
+
const root = this;
|
|
1443
1467
|
|
|
1468
|
+
// Setup methods API.
|
|
1444
1469
|
const methods = {
|
|
1445
1470
|
open(transition, focus) {
|
|
1446
1471
|
return open$1.call(root, this, transition, focus);
|
|
1447
1472
|
},
|
|
1448
|
-
|
|
1449
1473
|
close(transition, focus) {
|
|
1450
1474
|
return close$1.call(root, this, transition, focus);
|
|
1451
1475
|
},
|
|
1452
|
-
|
|
1453
1476
|
replace(transition, focus) {
|
|
1454
1477
|
return replace.call(root, this, transition, focus);
|
|
1455
1478
|
},
|
|
1456
|
-
|
|
1457
1479
|
deregister() {
|
|
1458
1480
|
return deregister$1.call(root, this);
|
|
1459
1481
|
},
|
|
1460
|
-
|
|
1461
1482
|
teleport(ref = this.getSetting('teleport'), method = this.getSetting('teleportMethod')) {
|
|
1462
1483
|
if (!this.returnRef) {
|
|
1463
1484
|
this.returnRef = teleport(this.el, ref, method);
|
|
@@ -1467,7 +1488,6 @@ async function register$1(el, dialog) {
|
|
|
1467
1488
|
return false;
|
|
1468
1489
|
}
|
|
1469
1490
|
},
|
|
1470
|
-
|
|
1471
1491
|
teleportReturn() {
|
|
1472
1492
|
if (this.returnRef) {
|
|
1473
1493
|
this.returnRef = teleport(this.el, this.returnRef);
|
|
@@ -1477,13 +1497,12 @@ async function register$1(el, dialog) {
|
|
|
1477
1497
|
return false;
|
|
1478
1498
|
}
|
|
1479
1499
|
},
|
|
1480
|
-
|
|
1481
1500
|
getSetting(key) {
|
|
1482
1501
|
return key in this.settings ? this.settings[key] : root.settings[key];
|
|
1483
1502
|
}
|
|
1503
|
+
};
|
|
1484
1504
|
|
|
1485
|
-
|
|
1486
|
-
|
|
1505
|
+
// Setup the modal object.
|
|
1487
1506
|
const entry = _extends({
|
|
1488
1507
|
id: el.id,
|
|
1489
1508
|
state: 'closed',
|
|
@@ -1491,40 +1510,42 @@ async function register$1(el, dialog) {
|
|
|
1491
1510
|
dialog: dialog,
|
|
1492
1511
|
returnRef: null,
|
|
1493
1512
|
settings: getConfig$1(el, this.settings.dataConfig)
|
|
1494
|
-
}, methods);
|
|
1495
|
-
|
|
1513
|
+
}, methods);
|
|
1496
1514
|
|
|
1497
|
-
|
|
1515
|
+
// Set aria-modal attribute to true.
|
|
1516
|
+
entry.dialog.setAttribute('aria-modal', 'true');
|
|
1498
1517
|
|
|
1518
|
+
// If a role attribute is not set, set it to "dialog" as the default.
|
|
1499
1519
|
if (!entry.dialog.hasAttribute('role')) {
|
|
1500
1520
|
entry.dialog.setAttribute('role', 'dialog');
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1521
|
+
}
|
|
1503
1522
|
|
|
1523
|
+
// Set tabindex="-1" so dialog is focusable via JS or click.
|
|
1504
1524
|
if (entry.getSetting('setTabindex')) {
|
|
1505
1525
|
entry.dialog.setAttribute('tabindex', '-1');
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1526
|
+
}
|
|
1508
1527
|
|
|
1528
|
+
// Teleport modal if a reference has been set.
|
|
1509
1529
|
if (entry.getSetting('teleport')) {
|
|
1510
1530
|
entry.teleport();
|
|
1511
|
-
}
|
|
1512
|
-
|
|
1531
|
+
}
|
|
1513
1532
|
|
|
1514
|
-
|
|
1533
|
+
// Add entry to collection.
|
|
1534
|
+
this.collection.push(entry);
|
|
1515
1535
|
|
|
1536
|
+
// Setup initial state.
|
|
1516
1537
|
if (entry.el.classList.contains(this.settings.stateOpened)) {
|
|
1517
1538
|
// Open entry with transitions disabled.
|
|
1518
1539
|
await entry.open(false);
|
|
1519
1540
|
} else {
|
|
1520
1541
|
// Remove transition state classes.
|
|
1521
1542
|
entry.el.classList.remove(this.settings.stateOpening);
|
|
1522
|
-
entry.el.classList.remove(this.settings.stateClosing);
|
|
1523
|
-
|
|
1543
|
+
entry.el.classList.remove(this.settings.stateClosing);
|
|
1544
|
+
// Add closed state class.
|
|
1524
1545
|
entry.el.classList.add(this.settings.stateClosed);
|
|
1525
|
-
}
|
|
1526
|
-
|
|
1546
|
+
}
|
|
1527
1547
|
|
|
1548
|
+
// Return the registered entry.
|
|
1528
1549
|
return entry;
|
|
1529
1550
|
}
|
|
1530
1551
|
|
|
@@ -1534,11 +1555,9 @@ function stack(settings) {
|
|
|
1534
1555
|
get value() {
|
|
1535
1556
|
return [...stackArray];
|
|
1536
1557
|
},
|
|
1537
|
-
|
|
1538
1558
|
get top() {
|
|
1539
1559
|
return stackArray[stackArray.length - 1];
|
|
1540
1560
|
},
|
|
1541
|
-
|
|
1542
1561
|
updateIndex() {
|
|
1543
1562
|
stackArray.forEach((entry, index) => {
|
|
1544
1563
|
entry.el.style.zIndex = null;
|
|
@@ -1546,60 +1565,60 @@ function stack(settings) {
|
|
|
1546
1565
|
entry.el.style.zIndex = parseInt(value) + index + 1;
|
|
1547
1566
|
});
|
|
1548
1567
|
},
|
|
1549
|
-
|
|
1550
1568
|
updateGlobalState() {
|
|
1551
1569
|
updateGlobalState(this.top, settings);
|
|
1552
1570
|
this.updateIndex();
|
|
1553
1571
|
},
|
|
1554
|
-
|
|
1555
1572
|
add(entry) {
|
|
1556
1573
|
// Apply z-index styles based on stack length.
|
|
1557
1574
|
entry.el.style.zIndex = null;
|
|
1558
1575
|
const value = getComputedStyle(entry.el)['z-index'];
|
|
1559
|
-
entry.el.style.zIndex = parseInt(value) + stackArray.length + 1;
|
|
1576
|
+
entry.el.style.zIndex = parseInt(value) + stackArray.length + 1;
|
|
1560
1577
|
|
|
1561
|
-
|
|
1578
|
+
// Move back to end of stack.
|
|
1579
|
+
stackArray.push(entry);
|
|
1562
1580
|
|
|
1581
|
+
// Update the global state.
|
|
1563
1582
|
this.updateGlobalState();
|
|
1564
1583
|
},
|
|
1565
|
-
|
|
1566
1584
|
remove(entry) {
|
|
1567
1585
|
// Get the index of the entry.
|
|
1568
1586
|
const index = stackArray.findIndex(item => {
|
|
1569
1587
|
return item.id === entry.id;
|
|
1570
|
-
});
|
|
1588
|
+
});
|
|
1571
1589
|
|
|
1590
|
+
// If entry is in stack...
|
|
1572
1591
|
if (index >= 0) {
|
|
1573
1592
|
// Remove z-index styles.
|
|
1574
|
-
entry.el.style.zIndex = null;
|
|
1593
|
+
entry.el.style.zIndex = null;
|
|
1575
1594
|
|
|
1576
|
-
|
|
1595
|
+
// Remove entry from stack array.
|
|
1596
|
+
stackArray.splice(index, 1);
|
|
1577
1597
|
|
|
1598
|
+
// Update the global state.
|
|
1578
1599
|
this.updateGlobalState();
|
|
1579
1600
|
}
|
|
1580
1601
|
},
|
|
1581
|
-
|
|
1582
1602
|
moveToTop(entry) {
|
|
1583
1603
|
// Get the index of the entry.
|
|
1584
1604
|
const index = stackArray.findIndex(item => {
|
|
1585
1605
|
return item.id === entry.id;
|
|
1586
|
-
});
|
|
1606
|
+
});
|
|
1587
1607
|
|
|
1608
|
+
// If entry is in stack...
|
|
1588
1609
|
if (index >= 0) {
|
|
1589
1610
|
// Remove entry from stack array.
|
|
1590
|
-
stackArray.splice(index, 1);
|
|
1611
|
+
stackArray.splice(index, 1);
|
|
1591
1612
|
|
|
1613
|
+
// Add entry back to top of stack.
|
|
1592
1614
|
this.add(entry);
|
|
1593
1615
|
}
|
|
1594
1616
|
}
|
|
1595
|
-
|
|
1596
1617
|
};
|
|
1597
1618
|
}
|
|
1598
1619
|
|
|
1599
1620
|
var _handleClick = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
|
|
1600
|
-
|
|
1601
1621
|
var _handleKeydown$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
|
|
1602
|
-
|
|
1603
1622
|
class Modal extends Collection {
|
|
1604
1623
|
constructor(options) {
|
|
1605
1624
|
super();
|
|
@@ -1614,91 +1633,80 @@ class Modal extends Collection {
|
|
|
1614
1633
|
this.defaults = defaults$1;
|
|
1615
1634
|
this.settings = _extends({}, this.defaults, options);
|
|
1616
1635
|
this.trigger = null;
|
|
1617
|
-
this.focusTrap = new FocusTrap();
|
|
1636
|
+
this.focusTrap = new FocusTrap();
|
|
1618
1637
|
|
|
1638
|
+
// Setup stack module.
|
|
1619
1639
|
this.stack = stack(this.settings);
|
|
1620
1640
|
_classPrivateFieldLooseBase(this, _handleClick)[_handleClick] = handleClick$1.bind(this);
|
|
1621
1641
|
_classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1] = handleKeydown$1.bind(this);
|
|
1622
1642
|
if (this.settings.autoInit) this.init();
|
|
1623
1643
|
}
|
|
1624
|
-
|
|
1625
1644
|
get active() {
|
|
1626
1645
|
return this.stack.top;
|
|
1627
1646
|
}
|
|
1628
|
-
|
|
1629
1647
|
async init(options) {
|
|
1630
1648
|
// Update settings with passed options.
|
|
1631
|
-
if (options) this.settings = _extends({}, this.settings, options);
|
|
1649
|
+
if (options) this.settings = _extends({}, this.settings, options);
|
|
1632
1650
|
|
|
1633
|
-
|
|
1651
|
+
// Get all the modals.
|
|
1652
|
+
const modals = document.querySelectorAll(this.settings.selectorModal);
|
|
1634
1653
|
|
|
1635
|
-
|
|
1654
|
+
// Register the collections array with modal instances.
|
|
1655
|
+
await this.registerCollection(modals);
|
|
1636
1656
|
|
|
1657
|
+
// If eventListeners are enabled, init event listeners.
|
|
1637
1658
|
if (this.settings.eventListeners) {
|
|
1638
1659
|
this.initEventListeners();
|
|
1639
1660
|
}
|
|
1640
|
-
|
|
1641
1661
|
return this;
|
|
1642
1662
|
}
|
|
1643
|
-
|
|
1644
1663
|
async destroy() {
|
|
1645
1664
|
// Clear stored trigger.
|
|
1646
|
-
this.trigger = null;
|
|
1665
|
+
this.trigger = null;
|
|
1647
1666
|
|
|
1648
|
-
|
|
1667
|
+
// Remove all entries from the collection.
|
|
1668
|
+
await this.deregisterCollection();
|
|
1649
1669
|
|
|
1670
|
+
// If eventListeners are enabled, destroy event listeners.
|
|
1650
1671
|
if (this.settings.eventListeners) {
|
|
1651
1672
|
this.destroyEventListeners();
|
|
1652
1673
|
}
|
|
1653
|
-
|
|
1654
1674
|
return this;
|
|
1655
1675
|
}
|
|
1656
|
-
|
|
1657
1676
|
initEventListeners() {
|
|
1658
1677
|
document.addEventListener('click', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
1659
|
-
document.addEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
1660
1678
|
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1], false);
|
|
1661
1679
|
}
|
|
1662
|
-
|
|
1663
1680
|
destroyEventListeners() {
|
|
1664
1681
|
document.removeEventListener('click', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
1665
|
-
document.removeEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
1666
1682
|
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1], false);
|
|
1667
1683
|
}
|
|
1668
|
-
|
|
1669
1684
|
register(query) {
|
|
1670
1685
|
const els = getModalElements.call(this, query);
|
|
1671
1686
|
if (els.error) return Promise.reject(els.error);
|
|
1672
1687
|
return register$1.call(this, els.modal, els.dialog);
|
|
1673
1688
|
}
|
|
1674
|
-
|
|
1675
1689
|
deregister(query) {
|
|
1676
1690
|
const modal = this.get(getModalID.call(this, query));
|
|
1677
1691
|
return deregister$1.call(this, modal);
|
|
1678
1692
|
}
|
|
1679
|
-
|
|
1680
1693
|
open(id, transition, focus) {
|
|
1681
1694
|
return open$1.call(this, id, transition, focus);
|
|
1682
1695
|
}
|
|
1683
|
-
|
|
1684
1696
|
close(id, transition, focus) {
|
|
1685
1697
|
return close$1.call(this, id, transition, focus);
|
|
1686
1698
|
}
|
|
1687
|
-
|
|
1688
1699
|
replace(id, transition, focus) {
|
|
1689
1700
|
return replace.call(this, id, transition, focus);
|
|
1690
1701
|
}
|
|
1691
|
-
|
|
1692
1702
|
async closeAll(exclude = false, transition, focus = true) {
|
|
1693
|
-
const result = await closeAll$1.call(this, exclude, transition);
|
|
1694
|
-
|
|
1703
|
+
const result = await closeAll$1.call(this, exclude, transition);
|
|
1704
|
+
// Update focus if the focus param is true.
|
|
1695
1705
|
if (focus) {
|
|
1696
1706
|
updateFocusState.call(this);
|
|
1697
1707
|
}
|
|
1698
|
-
|
|
1699
1708
|
return result;
|
|
1700
1709
|
}
|
|
1701
|
-
|
|
1702
1710
|
}
|
|
1703
1711
|
|
|
1704
1712
|
var defaults = {
|
|
@@ -1716,8 +1724,9 @@ var defaults = {
|
|
|
1716
1724
|
|
|
1717
1725
|
function getConfig(el, settings) {
|
|
1718
1726
|
// Get the computed styles of the element.
|
|
1719
|
-
const styles = getComputedStyle(el);
|
|
1727
|
+
const styles = getComputedStyle(el);
|
|
1720
1728
|
|
|
1729
|
+
// Setup the config obj with default values.
|
|
1721
1730
|
const config = {
|
|
1722
1731
|
'placement': settings.placement,
|
|
1723
1732
|
'event': settings.eventType,
|
|
@@ -1726,36 +1735,40 @@ function getConfig(el, settings) {
|
|
|
1726
1735
|
'flip-padding': 0,
|
|
1727
1736
|
'arrow-element': settings.selectorArrow,
|
|
1728
1737
|
'arrow-padding': 0
|
|
1729
|
-
};
|
|
1738
|
+
};
|
|
1730
1739
|
|
|
1740
|
+
// Loop through config obj.
|
|
1731
1741
|
for (const prop in config) {
|
|
1732
1742
|
// Get the CSS variable property values.
|
|
1733
1743
|
const prefix = g();
|
|
1734
|
-
const value = styles.getPropertyValue(`--${prefix}popover-${prop}`).trim();
|
|
1744
|
+
const value = styles.getPropertyValue(`--${prefix}popover-${prop}`).trim();
|
|
1735
1745
|
|
|
1746
|
+
// If a value was found, replace the default in config obj.
|
|
1736
1747
|
if (value) {
|
|
1737
1748
|
config[prop] = value;
|
|
1738
1749
|
}
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1750
|
+
}
|
|
1741
1751
|
|
|
1752
|
+
// Return the config obj.
|
|
1742
1753
|
return config;
|
|
1743
1754
|
}
|
|
1744
1755
|
|
|
1745
1756
|
function getPadding(value) {
|
|
1746
|
-
let padding;
|
|
1757
|
+
let padding;
|
|
1747
1758
|
|
|
1748
|
-
|
|
1759
|
+
// Split the value by spaces if it's a string.
|
|
1760
|
+
const array = typeof value === 'string' ? value.trim().split(' ') : [value];
|
|
1749
1761
|
|
|
1762
|
+
// Convert individual values to integers.
|
|
1750
1763
|
array.forEach(function (item, index) {
|
|
1751
1764
|
array[index] = parseInt(item, 10);
|
|
1752
|
-
});
|
|
1765
|
+
});
|
|
1753
1766
|
|
|
1767
|
+
// Build the padding object based on the number of values passed.
|
|
1754
1768
|
switch (array.length) {
|
|
1755
1769
|
case 1:
|
|
1756
1770
|
padding = array[0];
|
|
1757
1771
|
break;
|
|
1758
|
-
|
|
1759
1772
|
case 2:
|
|
1760
1773
|
padding = {
|
|
1761
1774
|
top: array[0],
|
|
@@ -1764,7 +1777,6 @@ function getPadding(value) {
|
|
|
1764
1777
|
left: array[1]
|
|
1765
1778
|
};
|
|
1766
1779
|
break;
|
|
1767
|
-
|
|
1768
1780
|
case 3:
|
|
1769
1781
|
padding = {
|
|
1770
1782
|
top: array[0],
|
|
@@ -1773,7 +1785,6 @@ function getPadding(value) {
|
|
|
1773
1785
|
left: array[1]
|
|
1774
1786
|
};
|
|
1775
1787
|
break;
|
|
1776
|
-
|
|
1777
1788
|
case 4:
|
|
1778
1789
|
padding = {
|
|
1779
1790
|
top: array[0],
|
|
@@ -1782,13 +1793,12 @@ function getPadding(value) {
|
|
|
1782
1793
|
left: array[3]
|
|
1783
1794
|
};
|
|
1784
1795
|
break;
|
|
1785
|
-
|
|
1786
1796
|
default:
|
|
1787
1797
|
padding = false;
|
|
1788
1798
|
break;
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1799
|
+
}
|
|
1791
1800
|
|
|
1801
|
+
// Return the padding object.
|
|
1792
1802
|
return padding;
|
|
1793
1803
|
}
|
|
1794
1804
|
|
|
@@ -1819,8 +1829,9 @@ function getModifiers(options) {
|
|
|
1819
1829
|
|
|
1820
1830
|
function getPopover(query) {
|
|
1821
1831
|
// Get the entry from collection.
|
|
1822
|
-
const entry = typeof query === 'string' ? this.get(query) : this.get(query.id);
|
|
1832
|
+
const entry = typeof query === 'string' ? this.get(query) : this.get(query.id);
|
|
1823
1833
|
|
|
1834
|
+
// Return entry if it was resolved, otherwise throw error.
|
|
1824
1835
|
if (entry) {
|
|
1825
1836
|
return entry;
|
|
1826
1837
|
} else {
|
|
@@ -1832,34 +1843,44 @@ function getPopoverID(obj) {
|
|
|
1832
1843
|
// If it's a string, return the string.
|
|
1833
1844
|
if (typeof obj === 'string') {
|
|
1834
1845
|
return obj;
|
|
1835
|
-
}
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
// If it's an HTML element.
|
|
1836
1849
|
else if (typeof obj.hasAttribute === 'function') {
|
|
1837
1850
|
// If it's a popover element, return the id.
|
|
1838
1851
|
if (obj.closest(this.settings.selectorPopover)) {
|
|
1839
1852
|
obj = obj.closest(this.settings.selectorPopover);
|
|
1840
1853
|
return obj.id;
|
|
1841
|
-
}
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
// If it's a popover trigger, return value of aria-controls.
|
|
1842
1857
|
else if (obj.hasAttribute('aria-controls')) {
|
|
1843
1858
|
return obj.getAttribute('aria-controls');
|
|
1844
|
-
}
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
// If it's a popover tooltip trigger, return the value of aria-describedby.
|
|
1845
1862
|
else if (obj.hasAttribute('aria-describedby')) {
|
|
1846
1863
|
return obj.getAttribute('aria-describedby');
|
|
1847
|
-
}
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
// Return false if no id was found.
|
|
1848
1867
|
else return false;
|
|
1849
|
-
}
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
// If it has an id property, return its value.
|
|
1850
1871
|
else if (obj.id) {
|
|
1851
1872
|
return obj.id;
|
|
1852
|
-
}
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
// Return false if no id was found.
|
|
1853
1876
|
else return false;
|
|
1854
1877
|
}
|
|
1855
1878
|
|
|
1856
1879
|
function getPopoverElements(query) {
|
|
1857
1880
|
const id = getPopoverID.call(this, query);
|
|
1858
|
-
|
|
1859
1881
|
if (id) {
|
|
1860
1882
|
const popover = document.querySelector(`#${id}`);
|
|
1861
1883
|
const trigger = document.querySelector(`[aria-controls="${id}"]`) || document.querySelector(`[aria-describedby="${id}"]`);
|
|
1862
|
-
|
|
1863
1884
|
if (!trigger && !popover) {
|
|
1864
1885
|
return {
|
|
1865
1886
|
error: new Error(`No popover elements found using the ID: "${id}".`)
|
|
@@ -1887,32 +1908,36 @@ function getPopoverElements(query) {
|
|
|
1887
1908
|
|
|
1888
1909
|
async function close(query) {
|
|
1889
1910
|
// Get the popover from collection.
|
|
1890
|
-
const popover = query ? getPopover.call(this, query) : await closeAll.call(this);
|
|
1911
|
+
const popover = query ? getPopover.call(this, query) : await closeAll.call(this);
|
|
1891
1912
|
|
|
1913
|
+
// If a modal exists and its state is opened.
|
|
1892
1914
|
if (popover && popover.state === 'opened') {
|
|
1893
1915
|
// Update state class.
|
|
1894
|
-
popover.el.classList.remove(this.settings.stateActive);
|
|
1916
|
+
popover.el.classList.remove(this.settings.stateActive);
|
|
1895
1917
|
|
|
1918
|
+
// Update accessibility attribute(s).
|
|
1896
1919
|
if (popover.trigger.hasAttribute('aria-controls')) {
|
|
1897
1920
|
popover.trigger.setAttribute('aria-expanded', 'false');
|
|
1898
|
-
}
|
|
1899
|
-
|
|
1921
|
+
}
|
|
1900
1922
|
|
|
1923
|
+
// Disable popper event listeners.
|
|
1901
1924
|
popover.popper.setOptions({
|
|
1902
1925
|
modifiers: [{
|
|
1903
1926
|
name: 'eventListeners',
|
|
1904
1927
|
enabled: false
|
|
1905
1928
|
}]
|
|
1906
|
-
});
|
|
1929
|
+
});
|
|
1907
1930
|
|
|
1908
|
-
|
|
1931
|
+
// Update popover state.
|
|
1932
|
+
popover.state = 'closed';
|
|
1909
1933
|
|
|
1934
|
+
// Clear root trigger if popover trigger matches.
|
|
1910
1935
|
if (popover.trigger === this.trigger) {
|
|
1911
1936
|
this.trigger = null;
|
|
1912
1937
|
}
|
|
1913
|
-
}
|
|
1914
|
-
|
|
1938
|
+
}
|
|
1915
1939
|
|
|
1940
|
+
// Return the popover.
|
|
1916
1941
|
return popover;
|
|
1917
1942
|
}
|
|
1918
1943
|
async function closeAll() {
|
|
@@ -1926,19 +1951,22 @@ async function closeAll() {
|
|
|
1926
1951
|
}
|
|
1927
1952
|
function closeCheck(popover) {
|
|
1928
1953
|
// Only run closeCheck if provided popover is currently open.
|
|
1929
|
-
if (popover.state != 'opened') return;
|
|
1954
|
+
if (popover.state != 'opened') return;
|
|
1930
1955
|
|
|
1956
|
+
// Needed to correctly check which element is currently being focused.
|
|
1931
1957
|
setTimeout(() => {
|
|
1932
1958
|
// Check if trigger or element are being hovered.
|
|
1933
|
-
const isHovered = popover.el.closest(':hover') === popover.el || popover.trigger.closest(':hover') === popover.trigger;
|
|
1959
|
+
const isHovered = popover.el.closest(':hover') === popover.el || popover.trigger.closest(':hover') === popover.trigger;
|
|
1934
1960
|
|
|
1935
|
-
|
|
1961
|
+
// Check if trigger or element are being focused.
|
|
1962
|
+
const isFocused = document.activeElement.closest(`#${popover.id}, [aria-controls="${popover.id}"], [aria-describedby="${popover.id}"]`);
|
|
1936
1963
|
|
|
1964
|
+
// Close if the trigger and element are not currently hovered or focused.
|
|
1937
1965
|
if (!isHovered && !isFocused) {
|
|
1938
1966
|
popover.close();
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1967
|
+
}
|
|
1941
1968
|
|
|
1969
|
+
// Return the popover.
|
|
1942
1970
|
return popover;
|
|
1943
1971
|
}, 1);
|
|
1944
1972
|
}
|
|
@@ -1958,16 +1986,13 @@ function handleKeydown(event) {
|
|
|
1958
1986
|
if (this.trigger) {
|
|
1959
1987
|
this.trigger.focus();
|
|
1960
1988
|
}
|
|
1961
|
-
|
|
1962
1989
|
closeAll.call(this);
|
|
1963
1990
|
return;
|
|
1964
|
-
|
|
1965
1991
|
case 'Tab':
|
|
1966
1992
|
this.collection.forEach(popover => {
|
|
1967
1993
|
closeCheck.call(this, popover);
|
|
1968
1994
|
});
|
|
1969
1995
|
return;
|
|
1970
|
-
|
|
1971
1996
|
default:
|
|
1972
1997
|
return;
|
|
1973
1998
|
}
|
|
@@ -1976,8 +2001,9 @@ function handleDocumentClick(popover) {
|
|
|
1976
2001
|
const root = this;
|
|
1977
2002
|
document.addEventListener('click', function _f(event) {
|
|
1978
2003
|
// Check if a popover or its trigger was clicked.
|
|
1979
|
-
const wasClicked = event.target.closest(`#${popover.id}, [aria-controls="${popover.id}"], [aria-describedby="${popover.id}"]`);
|
|
2004
|
+
const wasClicked = event.target.closest(`#${popover.id}, [aria-controls="${popover.id}"], [aria-describedby="${popover.id}"]`);
|
|
1980
2005
|
|
|
2006
|
+
// If popover or popover trigger was clicked...
|
|
1981
2007
|
if (wasClicked) {
|
|
1982
2008
|
// If popover element exists and is not active...
|
|
1983
2009
|
if (popover.el && !popover.el.classList.contains(root.settings.stateActive)) {
|
|
@@ -1988,7 +2014,6 @@ function handleDocumentClick(popover) {
|
|
|
1988
2014
|
if (popover.el && popover.el.classList.contains(root.settings.stateActive)) {
|
|
1989
2015
|
popover.close();
|
|
1990
2016
|
}
|
|
1991
|
-
|
|
1992
2017
|
this.removeEventListener('click', _f);
|
|
1993
2018
|
}
|
|
1994
2019
|
});
|
|
@@ -2154,38 +2179,57 @@ var max = Math.max;
|
|
|
2154
2179
|
var min = Math.min;
|
|
2155
2180
|
var round = Math.round;
|
|
2156
2181
|
|
|
2157
|
-
function
|
|
2182
|
+
function getUAString() {
|
|
2183
|
+
var uaData = navigator.userAgentData;
|
|
2184
|
+
|
|
2185
|
+
if (uaData != null && uaData.brands && Array.isArray(uaData.brands)) {
|
|
2186
|
+
return uaData.brands.map(function (item) {
|
|
2187
|
+
return item.brand + "/" + item.version;
|
|
2188
|
+
}).join(' ');
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
return navigator.userAgent;
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2194
|
+
function isLayoutViewport() {
|
|
2195
|
+
return !/^((?!chrome|android).)*safari/i.test(getUAString());
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
function getBoundingClientRect(element, includeScale, isFixedStrategy) {
|
|
2158
2199
|
if (includeScale === void 0) {
|
|
2159
2200
|
includeScale = false;
|
|
2160
2201
|
}
|
|
2161
2202
|
|
|
2162
|
-
|
|
2203
|
+
if (isFixedStrategy === void 0) {
|
|
2204
|
+
isFixedStrategy = false;
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
var clientRect = element.getBoundingClientRect();
|
|
2163
2208
|
var scaleX = 1;
|
|
2164
2209
|
var scaleY = 1;
|
|
2165
2210
|
|
|
2166
|
-
if (isHTMLElement(element)
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
// Fallback to 1 in case both values are `0`
|
|
2170
|
-
|
|
2171
|
-
if (offsetWidth > 0) {
|
|
2172
|
-
scaleX = round(rect.width) / offsetWidth || 1;
|
|
2173
|
-
}
|
|
2174
|
-
|
|
2175
|
-
if (offsetHeight > 0) {
|
|
2176
|
-
scaleY = round(rect.height) / offsetHeight || 1;
|
|
2177
|
-
}
|
|
2211
|
+
if (includeScale && isHTMLElement(element)) {
|
|
2212
|
+
scaleX = element.offsetWidth > 0 ? round(clientRect.width) / element.offsetWidth || 1 : 1;
|
|
2213
|
+
scaleY = element.offsetHeight > 0 ? round(clientRect.height) / element.offsetHeight || 1 : 1;
|
|
2178
2214
|
}
|
|
2179
2215
|
|
|
2216
|
+
var _ref = isElement(element) ? getWindow(element) : window,
|
|
2217
|
+
visualViewport = _ref.visualViewport;
|
|
2218
|
+
|
|
2219
|
+
var addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
|
|
2220
|
+
var x = (clientRect.left + (addVisualOffsets && visualViewport ? visualViewport.offsetLeft : 0)) / scaleX;
|
|
2221
|
+
var y = (clientRect.top + (addVisualOffsets && visualViewport ? visualViewport.offsetTop : 0)) / scaleY;
|
|
2222
|
+
var width = clientRect.width / scaleX;
|
|
2223
|
+
var height = clientRect.height / scaleY;
|
|
2180
2224
|
return {
|
|
2181
|
-
width:
|
|
2182
|
-
height:
|
|
2183
|
-
top:
|
|
2184
|
-
right:
|
|
2185
|
-
bottom:
|
|
2186
|
-
left:
|
|
2187
|
-
x:
|
|
2188
|
-
y:
|
|
2225
|
+
width: width,
|
|
2226
|
+
height: height,
|
|
2227
|
+
top: y,
|
|
2228
|
+
right: x + width,
|
|
2229
|
+
bottom: y + height,
|
|
2230
|
+
left: x,
|
|
2231
|
+
x: x,
|
|
2232
|
+
y: y
|
|
2189
2233
|
};
|
|
2190
2234
|
}
|
|
2191
2235
|
|
|
@@ -2280,8 +2324,8 @@ function getTrueOffsetParent(element) {
|
|
|
2280
2324
|
|
|
2281
2325
|
|
|
2282
2326
|
function getContainingBlock(element) {
|
|
2283
|
-
var isFirefox =
|
|
2284
|
-
var isIE =
|
|
2327
|
+
var isFirefox = /firefox/i.test(getUAString());
|
|
2328
|
+
var isIE = /Trident/i.test(getUAString());
|
|
2285
2329
|
|
|
2286
2330
|
if (isIE && isHTMLElement(element)) {
|
|
2287
2331
|
// In IE 9, 10 and 11 fixed elements containing block is always established by the viewport
|
|
@@ -2426,7 +2470,6 @@ function effect$1(_ref2) {
|
|
|
2426
2470
|
}
|
|
2427
2471
|
|
|
2428
2472
|
if (!contains(state.elements.popper, arrowElement)) {
|
|
2429
|
-
|
|
2430
2473
|
return;
|
|
2431
2474
|
}
|
|
2432
2475
|
|
|
@@ -2457,10 +2500,9 @@ var unsetSides = {
|
|
|
2457
2500
|
// Zooming can change the DPR, but it seems to report a value that will
|
|
2458
2501
|
// cleanly divide the values into the appropriate subpixels.
|
|
2459
2502
|
|
|
2460
|
-
function roundOffsetsByDPR(_ref) {
|
|
2503
|
+
function roundOffsetsByDPR(_ref, win) {
|
|
2461
2504
|
var x = _ref.x,
|
|
2462
2505
|
y = _ref.y;
|
|
2463
|
-
var win = window;
|
|
2464
2506
|
var dpr = win.devicePixelRatio || 1;
|
|
2465
2507
|
return {
|
|
2466
2508
|
x: round(x * dpr) / dpr || 0,
|
|
@@ -2543,7 +2585,7 @@ function mapToStyles(_ref2) {
|
|
|
2543
2585
|
var _ref4 = roundOffsets === true ? roundOffsetsByDPR({
|
|
2544
2586
|
x: x,
|
|
2545
2587
|
y: y
|
|
2546
|
-
}) : {
|
|
2588
|
+
}, getWindow(popper)) : {
|
|
2547
2589
|
x: x,
|
|
2548
2590
|
y: y
|
|
2549
2591
|
};
|
|
@@ -2569,7 +2611,6 @@ function computeStyles(_ref5) {
|
|
|
2569
2611
|
adaptive = _options$adaptive === void 0 ? true : _options$adaptive,
|
|
2570
2612
|
_options$roundOffsets = options.roundOffsets,
|
|
2571
2613
|
roundOffsets = _options$roundOffsets === void 0 ? true : _options$roundOffsets;
|
|
2572
|
-
|
|
2573
2614
|
var commonStyles = {
|
|
2574
2615
|
placement: getBasePlacement(state.placement),
|
|
2575
2616
|
variation: getVariation(state.placement),
|
|
@@ -2702,31 +2743,21 @@ function getWindowScrollBarX(element) {
|
|
|
2702
2743
|
return getBoundingClientRect(getDocumentElement(element)).left + getWindowScroll(element).scrollLeft;
|
|
2703
2744
|
}
|
|
2704
2745
|
|
|
2705
|
-
function getViewportRect(element) {
|
|
2746
|
+
function getViewportRect(element, strategy) {
|
|
2706
2747
|
var win = getWindow(element);
|
|
2707
2748
|
var html = getDocumentElement(element);
|
|
2708
2749
|
var visualViewport = win.visualViewport;
|
|
2709
2750
|
var width = html.clientWidth;
|
|
2710
2751
|
var height = html.clientHeight;
|
|
2711
2752
|
var x = 0;
|
|
2712
|
-
var y = 0;
|
|
2713
|
-
// can be obscured underneath it.
|
|
2714
|
-
// Also, `html.clientHeight` adds the bottom bar height in Safari iOS, even
|
|
2715
|
-
// if it isn't open, so if this isn't available, the popper will be detected
|
|
2716
|
-
// to overflow the bottom of the screen too early.
|
|
2753
|
+
var y = 0;
|
|
2717
2754
|
|
|
2718
2755
|
if (visualViewport) {
|
|
2719
2756
|
width = visualViewport.width;
|
|
2720
|
-
height = visualViewport.height;
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
// Feature detection fails in mobile emulation mode in Chrome.
|
|
2725
|
-
// Math.abs(win.innerWidth / visualViewport.scale - visualViewport.width) <
|
|
2726
|
-
// 0.001
|
|
2727
|
-
// Fallback here: "Not Safari" userAgent
|
|
2728
|
-
|
|
2729
|
-
if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
|
|
2757
|
+
height = visualViewport.height;
|
|
2758
|
+
var layoutViewport = isLayoutViewport();
|
|
2759
|
+
|
|
2760
|
+
if (layoutViewport || !layoutViewport && strategy === 'fixed') {
|
|
2730
2761
|
x = visualViewport.offsetLeft;
|
|
2731
2762
|
y = visualViewport.offsetTop;
|
|
2732
2763
|
}
|
|
@@ -2820,8 +2851,8 @@ function rectToClientRect(rect) {
|
|
|
2820
2851
|
});
|
|
2821
2852
|
}
|
|
2822
2853
|
|
|
2823
|
-
function getInnerBoundingClientRect(element) {
|
|
2824
|
-
var rect = getBoundingClientRect(element);
|
|
2854
|
+
function getInnerBoundingClientRect(element, strategy) {
|
|
2855
|
+
var rect = getBoundingClientRect(element, false, strategy === 'fixed');
|
|
2825
2856
|
rect.top = rect.top + element.clientTop;
|
|
2826
2857
|
rect.left = rect.left + element.clientLeft;
|
|
2827
2858
|
rect.bottom = rect.top + element.clientHeight;
|
|
@@ -2833,8 +2864,8 @@ function getInnerBoundingClientRect(element) {
|
|
|
2833
2864
|
return rect;
|
|
2834
2865
|
}
|
|
2835
2866
|
|
|
2836
|
-
function getClientRectFromMixedType(element, clippingParent) {
|
|
2837
|
-
return clippingParent === viewport ? rectToClientRect(getViewportRect(element)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
|
|
2867
|
+
function getClientRectFromMixedType(element, clippingParent, strategy) {
|
|
2868
|
+
return clippingParent === viewport ? rectToClientRect(getViewportRect(element, strategy)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent, strategy) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
|
|
2838
2869
|
} // A "clipping parent" is an overflowable container with the characteristic of
|
|
2839
2870
|
// clipping (or hiding) overflowing elements with a position different from
|
|
2840
2871
|
// `initial`
|
|
@@ -2857,18 +2888,18 @@ function getClippingParents(element) {
|
|
|
2857
2888
|
// clipping parents
|
|
2858
2889
|
|
|
2859
2890
|
|
|
2860
|
-
function getClippingRect(element, boundary, rootBoundary) {
|
|
2891
|
+
function getClippingRect(element, boundary, rootBoundary, strategy) {
|
|
2861
2892
|
var mainClippingParents = boundary === 'clippingParents' ? getClippingParents(element) : [].concat(boundary);
|
|
2862
2893
|
var clippingParents = [].concat(mainClippingParents, [rootBoundary]);
|
|
2863
2894
|
var firstClippingParent = clippingParents[0];
|
|
2864
2895
|
var clippingRect = clippingParents.reduce(function (accRect, clippingParent) {
|
|
2865
|
-
var rect = getClientRectFromMixedType(element, clippingParent);
|
|
2896
|
+
var rect = getClientRectFromMixedType(element, clippingParent, strategy);
|
|
2866
2897
|
accRect.top = max(rect.top, accRect.top);
|
|
2867
2898
|
accRect.right = min(rect.right, accRect.right);
|
|
2868
2899
|
accRect.bottom = min(rect.bottom, accRect.bottom);
|
|
2869
2900
|
accRect.left = max(rect.left, accRect.left);
|
|
2870
2901
|
return accRect;
|
|
2871
|
-
}, getClientRectFromMixedType(element, firstClippingParent));
|
|
2902
|
+
}, getClientRectFromMixedType(element, firstClippingParent, strategy));
|
|
2872
2903
|
clippingRect.width = clippingRect.right - clippingRect.left;
|
|
2873
2904
|
clippingRect.height = clippingRect.bottom - clippingRect.top;
|
|
2874
2905
|
clippingRect.x = clippingRect.left;
|
|
@@ -2949,6 +2980,8 @@ function detectOverflow(state, options) {
|
|
|
2949
2980
|
var _options = options,
|
|
2950
2981
|
_options$placement = _options.placement,
|
|
2951
2982
|
placement = _options$placement === void 0 ? state.placement : _options$placement,
|
|
2983
|
+
_options$strategy = _options.strategy,
|
|
2984
|
+
strategy = _options$strategy === void 0 ? state.strategy : _options$strategy,
|
|
2952
2985
|
_options$boundary = _options.boundary,
|
|
2953
2986
|
boundary = _options$boundary === void 0 ? clippingParents : _options$boundary,
|
|
2954
2987
|
_options$rootBoundary = _options.rootBoundary,
|
|
@@ -2963,7 +2996,7 @@ function detectOverflow(state, options) {
|
|
|
2963
2996
|
var altContext = elementContext === popper ? reference : popper;
|
|
2964
2997
|
var popperRect = state.rects.popper;
|
|
2965
2998
|
var element = state.elements[altBoundary ? altContext : elementContext];
|
|
2966
|
-
var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary);
|
|
2999
|
+
var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary, strategy);
|
|
2967
3000
|
var referenceClientRect = getBoundingClientRect(state.elements.reference);
|
|
2968
3001
|
var popperOffsets = computeOffsets({
|
|
2969
3002
|
reference: referenceClientRect,
|
|
@@ -3477,7 +3510,7 @@ function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
|
|
|
3477
3510
|
var isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
3478
3511
|
var offsetParentIsScaled = isHTMLElement(offsetParent) && isElementScaled(offsetParent);
|
|
3479
3512
|
var documentElement = getDocumentElement(offsetParent);
|
|
3480
|
-
var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled);
|
|
3513
|
+
var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled, isFixed);
|
|
3481
3514
|
var scroll = {
|
|
3482
3515
|
scrollLeft: 0,
|
|
3483
3516
|
scrollTop: 0
|
|
@@ -3645,8 +3678,7 @@ function popperGenerator(generatorOptions) {
|
|
|
3645
3678
|
|
|
3646
3679
|
state.orderedModifiers = orderedModifiers.filter(function (m) {
|
|
3647
3680
|
return m.enabled;
|
|
3648
|
-
});
|
|
3649
|
-
|
|
3681
|
+
});
|
|
3650
3682
|
runModifierEffects();
|
|
3651
3683
|
return instance.update();
|
|
3652
3684
|
},
|
|
@@ -3666,7 +3698,6 @@ function popperGenerator(generatorOptions) {
|
|
|
3666
3698
|
// anymore
|
|
3667
3699
|
|
|
3668
3700
|
if (!areValidElements(reference, popper)) {
|
|
3669
|
-
|
|
3670
3701
|
return;
|
|
3671
3702
|
} // Store the reference and popper rects to be read by modifiers
|
|
3672
3703
|
|
|
@@ -3691,7 +3722,6 @@ function popperGenerator(generatorOptions) {
|
|
|
3691
3722
|
});
|
|
3692
3723
|
|
|
3693
3724
|
for (var index = 0; index < state.orderedModifiers.length; index++) {
|
|
3694
|
-
|
|
3695
3725
|
if (state.reset === true) {
|
|
3696
3726
|
state.reset = false;
|
|
3697
3727
|
index = -1;
|
|
@@ -3729,7 +3759,6 @@ function popperGenerator(generatorOptions) {
|
|
|
3729
3759
|
};
|
|
3730
3760
|
|
|
3731
3761
|
if (!areValidElements(reference, popper)) {
|
|
3732
|
-
|
|
3733
3762
|
return instance;
|
|
3734
3763
|
}
|
|
3735
3764
|
|
|
@@ -3744,11 +3773,11 @@ function popperGenerator(generatorOptions) {
|
|
|
3744
3773
|
// one.
|
|
3745
3774
|
|
|
3746
3775
|
function runModifierEffects() {
|
|
3747
|
-
state.orderedModifiers.forEach(function (
|
|
3748
|
-
var name =
|
|
3749
|
-
|
|
3750
|
-
options =
|
|
3751
|
-
effect =
|
|
3776
|
+
state.orderedModifiers.forEach(function (_ref) {
|
|
3777
|
+
var name = _ref.name,
|
|
3778
|
+
_ref$options = _ref.options,
|
|
3779
|
+
options = _ref$options === void 0 ? {} : _ref$options,
|
|
3780
|
+
effect = _ref.effect;
|
|
3752
3781
|
|
|
3753
3782
|
if (typeof effect === 'function') {
|
|
3754
3783
|
var cleanupFn = effect({
|
|
@@ -3783,33 +3812,37 @@ var createPopper = /*#__PURE__*/popperGenerator({
|
|
|
3783
3812
|
|
|
3784
3813
|
async function deregister(obj) {
|
|
3785
3814
|
// Return collection if nothing was passed.
|
|
3786
|
-
if (!obj) return this.collection;
|
|
3815
|
+
if (!obj) return this.collection;
|
|
3787
3816
|
|
|
3817
|
+
// Check if entry has been registered in the collection.
|
|
3788
3818
|
const index = this.collection.findIndex(entry => {
|
|
3789
3819
|
return entry.id === obj.id;
|
|
3790
3820
|
});
|
|
3791
|
-
|
|
3792
3821
|
if (index >= 0) {
|
|
3793
3822
|
// Get the collection entry.
|
|
3794
|
-
const entry = this.collection[index];
|
|
3823
|
+
const entry = this.collection[index];
|
|
3795
3824
|
|
|
3825
|
+
// If entry is in the opened state, close it.
|
|
3796
3826
|
if (entry.state === 'opened') {
|
|
3797
3827
|
entry.close();
|
|
3798
|
-
}
|
|
3799
|
-
|
|
3828
|
+
}
|
|
3800
3829
|
|
|
3801
|
-
|
|
3830
|
+
// Clean up the popper instance.
|
|
3831
|
+
entry.popper.destroy();
|
|
3802
3832
|
|
|
3803
|
-
|
|
3833
|
+
// Remove event listeners.
|
|
3834
|
+
deregisterEventListeners(entry);
|
|
3804
3835
|
|
|
3836
|
+
// Delete properties from collection entry.
|
|
3805
3837
|
Object.getOwnPropertyNames(entry).forEach(prop => {
|
|
3806
3838
|
delete entry[prop];
|
|
3807
|
-
});
|
|
3839
|
+
});
|
|
3808
3840
|
|
|
3841
|
+
// Remove entry from collection.
|
|
3809
3842
|
this.collection.splice(index, 1);
|
|
3810
|
-
}
|
|
3811
|
-
|
|
3843
|
+
}
|
|
3812
3844
|
|
|
3845
|
+
// Return the modified collection.
|
|
3813
3846
|
return this.collection;
|
|
3814
3847
|
}
|
|
3815
3848
|
function deregisterEventListeners(entry) {
|
|
@@ -3822,65 +3855,71 @@ function deregisterEventListeners(entry) {
|
|
|
3822
3855
|
entry[el].removeEventListener(type, evObj.listener, false);
|
|
3823
3856
|
});
|
|
3824
3857
|
});
|
|
3825
|
-
});
|
|
3826
|
-
|
|
3858
|
+
});
|
|
3827
3859
|
|
|
3860
|
+
// Remove eventListeners object from collection.
|
|
3828
3861
|
delete entry.__eventListeners;
|
|
3829
|
-
}
|
|
3830
|
-
|
|
3862
|
+
}
|
|
3831
3863
|
|
|
3864
|
+
// Return the entry object.
|
|
3832
3865
|
return entry;
|
|
3833
3866
|
}
|
|
3834
3867
|
|
|
3835
3868
|
async function open(query) {
|
|
3836
3869
|
// Get the popover from collection.
|
|
3837
|
-
const popover = getPopover.call(this, query);
|
|
3870
|
+
const popover = getPopover.call(this, query);
|
|
3838
3871
|
|
|
3839
|
-
|
|
3872
|
+
// Update state class.
|
|
3873
|
+
popover.el.classList.add(this.settings.stateActive);
|
|
3840
3874
|
|
|
3875
|
+
// Update accessibility attribute(s).
|
|
3841
3876
|
if (popover.trigger.hasAttribute('aria-controls')) {
|
|
3842
3877
|
popover.trigger.setAttribute('aria-expanded', 'true');
|
|
3843
|
-
}
|
|
3844
|
-
|
|
3878
|
+
}
|
|
3845
3879
|
|
|
3846
|
-
|
|
3880
|
+
// Update popover config.
|
|
3881
|
+
popover.config = getConfig(popover.el, this.settings);
|
|
3847
3882
|
|
|
3883
|
+
// Enable popper event listeners and set placement/modifiers.
|
|
3848
3884
|
popover.popper.setOptions({
|
|
3849
3885
|
placement: popover.config['placement'],
|
|
3850
3886
|
modifiers: [{
|
|
3851
3887
|
name: 'eventListeners',
|
|
3852
3888
|
enabled: true
|
|
3853
3889
|
}, ...getModifiers(popover.config)]
|
|
3854
|
-
});
|
|
3890
|
+
});
|
|
3855
3891
|
|
|
3856
|
-
|
|
3892
|
+
// Update popover position.
|
|
3893
|
+
popover.popper.update();
|
|
3857
3894
|
|
|
3858
|
-
|
|
3895
|
+
// Update popover state.
|
|
3896
|
+
popover.state = 'opened';
|
|
3859
3897
|
|
|
3898
|
+
// Return the popover.
|
|
3860
3899
|
return popover;
|
|
3861
3900
|
}
|
|
3862
3901
|
|
|
3863
3902
|
async function register(el, trigger) {
|
|
3864
3903
|
// Deregister entry incase it has already been registered.
|
|
3865
|
-
deregister.call(this, el);
|
|
3904
|
+
deregister.call(this, el);
|
|
3866
3905
|
|
|
3867
|
-
|
|
3906
|
+
// Save root this for use inside methods API.
|
|
3907
|
+
const root = this;
|
|
3868
3908
|
|
|
3909
|
+
// Setup methods API.
|
|
3869
3910
|
const methods = {
|
|
3870
3911
|
open() {
|
|
3871
3912
|
return open.call(root, this);
|
|
3872
3913
|
},
|
|
3873
|
-
|
|
3874
3914
|
close() {
|
|
3875
3915
|
return close.call(root, this);
|
|
3876
3916
|
},
|
|
3877
|
-
|
|
3878
3917
|
deregister() {
|
|
3879
3918
|
return deregister.call(root, this);
|
|
3880
3919
|
}
|
|
3920
|
+
};
|
|
3881
3921
|
|
|
3882
|
-
|
|
3883
|
-
|
|
3922
|
+
// Setup the popover object.
|
|
3884
3923
|
const entry = _extends({
|
|
3885
3924
|
id: el.id,
|
|
3886
3925
|
state: 'closed',
|
|
@@ -3888,32 +3927,35 @@ async function register(el, trigger) {
|
|
|
3888
3927
|
trigger: trigger,
|
|
3889
3928
|
popper: createPopper(trigger, el),
|
|
3890
3929
|
config: getConfig(el, this.settings)
|
|
3891
|
-
}, methods);
|
|
3892
|
-
|
|
3930
|
+
}, methods);
|
|
3893
3931
|
|
|
3932
|
+
// Set aria-expanded to false if trigger has aria-controls attribute.
|
|
3894
3933
|
if (entry.trigger.hasAttribute('aria-controls')) {
|
|
3895
3934
|
entry.trigger.setAttribute('aria-expanded', 'false');
|
|
3896
|
-
}
|
|
3897
|
-
|
|
3935
|
+
}
|
|
3898
3936
|
|
|
3899
|
-
|
|
3937
|
+
// Setup event listeners.
|
|
3938
|
+
registerEventListeners.call(this, entry);
|
|
3900
3939
|
|
|
3901
|
-
|
|
3940
|
+
// Add entry to collection.
|
|
3941
|
+
this.collection.push(entry);
|
|
3902
3942
|
|
|
3943
|
+
// Set initial state.
|
|
3903
3944
|
if (entry.el.classList.contains(this.settings.stateActive)) {
|
|
3904
3945
|
await entry.open();
|
|
3905
3946
|
handleDocumentClick.call(this, entry);
|
|
3906
|
-
}
|
|
3907
|
-
|
|
3947
|
+
}
|
|
3908
3948
|
|
|
3949
|
+
// Return the registered entry.
|
|
3909
3950
|
return entry;
|
|
3910
3951
|
}
|
|
3911
3952
|
function registerEventListeners(entry) {
|
|
3912
3953
|
// If event listeners aren't already setup.
|
|
3913
3954
|
if (!entry.__eventListeners) {
|
|
3914
3955
|
// Add event listeners based on event type.
|
|
3915
|
-
const eventType = entry.config['event'];
|
|
3956
|
+
const eventType = entry.config['event'];
|
|
3916
3957
|
|
|
3958
|
+
// If the event type is hover.
|
|
3917
3959
|
if (eventType === 'hover') {
|
|
3918
3960
|
// Setup event listeners object for hover.
|
|
3919
3961
|
entry.__eventListeners = [{
|
|
@@ -3924,8 +3966,9 @@ function registerEventListeners(entry) {
|
|
|
3924
3966
|
el: ['el', 'trigger'],
|
|
3925
3967
|
type: ['mouseleave', 'focusout'],
|
|
3926
3968
|
listener: closeCheck.bind(this, entry)
|
|
3927
|
-
}];
|
|
3969
|
+
}];
|
|
3928
3970
|
|
|
3971
|
+
// Loop through listeners and apply to the appropriate elements.
|
|
3929
3972
|
entry.__eventListeners.forEach(evObj => {
|
|
3930
3973
|
evObj.el.forEach(el => {
|
|
3931
3974
|
evObj.type.forEach(type => {
|
|
@@ -3933,15 +3976,18 @@ function registerEventListeners(entry) {
|
|
|
3933
3976
|
});
|
|
3934
3977
|
});
|
|
3935
3978
|
});
|
|
3936
|
-
}
|
|
3979
|
+
}
|
|
3980
|
+
|
|
3981
|
+
// Else the event type is click.
|
|
3937
3982
|
else {
|
|
3938
3983
|
// Setup event listeners object for click.
|
|
3939
3984
|
entry.__eventListeners = [{
|
|
3940
3985
|
el: ['trigger'],
|
|
3941
3986
|
type: ['click'],
|
|
3942
3987
|
listener: handleClick.bind(this, entry)
|
|
3943
|
-
}];
|
|
3988
|
+
}];
|
|
3944
3989
|
|
|
3990
|
+
// Loop through listeners and apply to the appropriate elements.
|
|
3945
3991
|
entry.__eventListeners.forEach(evObj => {
|
|
3946
3992
|
evObj.el.forEach(el => {
|
|
3947
3993
|
evObj.type.forEach(type => {
|
|
@@ -3950,14 +3996,13 @@ function registerEventListeners(entry) {
|
|
|
3950
3996
|
});
|
|
3951
3997
|
});
|
|
3952
3998
|
}
|
|
3953
|
-
}
|
|
3954
|
-
|
|
3999
|
+
}
|
|
3955
4000
|
|
|
4001
|
+
// Return the entry object.
|
|
3956
4002
|
return entry;
|
|
3957
4003
|
}
|
|
3958
4004
|
|
|
3959
4005
|
var _handleKeydown = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
|
|
3960
|
-
|
|
3961
4006
|
class Popover extends Collection {
|
|
3962
4007
|
constructor(options) {
|
|
3963
4008
|
super();
|
|
@@ -3971,82 +4016,76 @@ class Popover extends Collection {
|
|
|
3971
4016
|
_classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown] = handleKeydown.bind(this);
|
|
3972
4017
|
if (this.settings.autoInit) this.init();
|
|
3973
4018
|
}
|
|
3974
|
-
|
|
3975
4019
|
async init(options) {
|
|
3976
4020
|
// Update settings with passed options.
|
|
3977
|
-
if (options) this.settings = _extends({}, this.settings, options);
|
|
4021
|
+
if (options) this.settings = _extends({}, this.settings, options);
|
|
3978
4022
|
|
|
3979
|
-
|
|
4023
|
+
// Get all the popovers.
|
|
4024
|
+
const popovers = document.querySelectorAll(this.settings.selectorPopover);
|
|
3980
4025
|
|
|
3981
|
-
|
|
4026
|
+
// Register the collections array with popover instances.
|
|
4027
|
+
await this.registerCollection(popovers);
|
|
3982
4028
|
|
|
4029
|
+
// If eventListeners are enabled, init event listeners.
|
|
3983
4030
|
if (this.settings.eventListeners) {
|
|
3984
4031
|
// Pass false to initEventListeners() since registerCollection()
|
|
3985
4032
|
// already adds event listeners to popovers.
|
|
3986
4033
|
this.initEventListeners(false);
|
|
3987
4034
|
}
|
|
3988
|
-
|
|
3989
4035
|
return this;
|
|
3990
4036
|
}
|
|
3991
|
-
|
|
3992
4037
|
async destroy() {
|
|
3993
4038
|
// Clear stored trigger.
|
|
3994
|
-
this.trigger = null;
|
|
4039
|
+
this.trigger = null;
|
|
3995
4040
|
|
|
3996
|
-
|
|
4041
|
+
// Remove all entries from the collection.
|
|
4042
|
+
await this.deregisterCollection();
|
|
3997
4043
|
|
|
4044
|
+
// If eventListeners are enabled, destroy event listeners.
|
|
3998
4045
|
if (this.settings.eventListeners) {
|
|
3999
4046
|
// Pass false to destroyEventListeners() since deregisterCollection()
|
|
4000
4047
|
// already removes event listeners from popovers.
|
|
4001
4048
|
this.destroyEventListeners(false);
|
|
4002
4049
|
}
|
|
4003
|
-
|
|
4004
4050
|
return this;
|
|
4005
4051
|
}
|
|
4006
|
-
|
|
4007
4052
|
initEventListeners(processCollection = true) {
|
|
4008
4053
|
if (processCollection) {
|
|
4009
4054
|
// Loop through collection and setup event listeners.
|
|
4010
4055
|
this.collection.forEach(popover => {
|
|
4011
4056
|
registerEventListeners.call(this, popover);
|
|
4012
4057
|
});
|
|
4013
|
-
}
|
|
4014
|
-
|
|
4058
|
+
}
|
|
4015
4059
|
|
|
4060
|
+
// Add keydown global event listener.
|
|
4016
4061
|
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown], false);
|
|
4017
4062
|
}
|
|
4018
|
-
|
|
4019
4063
|
destroyEventListeners(processCollection = true) {
|
|
4020
4064
|
if (processCollection) {
|
|
4021
4065
|
// Loop through collection and remove event listeners.
|
|
4022
4066
|
this.collection.forEach(popover => {
|
|
4023
4067
|
deregisterEventListeners(popover);
|
|
4024
4068
|
});
|
|
4025
|
-
}
|
|
4026
|
-
|
|
4069
|
+
}
|
|
4027
4070
|
|
|
4071
|
+
// Remove keydown global event listener.
|
|
4028
4072
|
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown], false);
|
|
4029
4073
|
}
|
|
4030
|
-
|
|
4031
4074
|
register(query) {
|
|
4032
4075
|
const els = getPopoverElements.call(this, query);
|
|
4033
4076
|
if (els.error) return Promise.reject(els.error);
|
|
4034
4077
|
return register.call(this, els.popover, els.trigger);
|
|
4035
4078
|
}
|
|
4036
|
-
|
|
4037
4079
|
deregister(query) {
|
|
4038
4080
|
const popover = this.get(getPopoverID.call(this, query));
|
|
4039
4081
|
return deregister.call(this, popover);
|
|
4040
4082
|
}
|
|
4041
|
-
|
|
4042
4083
|
open(id) {
|
|
4043
4084
|
return open.call(this, id);
|
|
4044
4085
|
}
|
|
4045
|
-
|
|
4046
4086
|
close(id) {
|
|
4047
4087
|
return close.call(this, id);
|
|
4048
4088
|
}
|
|
4049
|
-
|
|
4050
4089
|
}
|
|
4051
4090
|
|
|
4052
4091
|
export { Checkbox, Drawer, Modal, Popover, index as core };
|