vrembem 3.0.5 → 3.0.8

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.
@@ -297,27 +297,25 @@ function getPrefix() {
297
297
  }
298
298
 
299
299
  function localStore(key, enable = true) {
300
- function getStore() {
301
- const value = localStorage.getItem(key);
302
- return value ? JSON.parse(value) : {};
303
- }
300
+ const local = localStorage.getItem(key);
301
+ const store = local ? JSON.parse(local) : {};
302
+ return {
303
+ get(prop) {
304
+ return prop ? store[prop] : store;
305
+ },
304
306
 
305
- function setStore(obj) {
306
- localStorage.setItem(key, JSON.stringify(obj));
307
- }
307
+ set(prop, value) {
308
+ if (value) {
309
+ store[prop] = value;
310
+ } else {
311
+ delete store[prop];
312
+ }
308
313
 
309
- return new Proxy(getStore(), {
310
- set: (target, property, value) => {
311
- target[property] = value;
312
- if (enable) setStore(target);
313
- return true;
314
- },
315
- deleteProperty: (target, property) => {
316
- delete target[property];
317
- if (enable) setStore(target);
318
- return true;
314
+ if (enable) localStorage.setItem(key, JSON.stringify(store));
315
+ return store;
319
316
  }
320
- });
317
+
318
+ };
321
319
  }
322
320
 
323
321
  /**
@@ -631,7 +629,7 @@ async function deregister$2(obj, close = true) {
631
629
  } // Remove entry from local store.
632
630
 
633
631
 
634
- delete this.store[entry.id]; // Unmount the MatchMedia functionality.
632
+ this.store.set(entry.id); // Unmount the MatchMedia functionality.
635
633
 
636
634
  entry.unmountBreakpoint(); // Delete properties from collection entry.
637
635
 
@@ -646,12 +644,12 @@ async function deregister$2(obj, close = true) {
646
644
  return this.collection;
647
645
  }
648
646
 
649
- function L() {
647
+ function g() {
650
648
  return getComputedStyle(document.body).getPropertyValue("--vrembem-variable-prefix").trim();
651
649
  }
652
650
 
653
651
  function getBreakpoint(drawer) {
654
- const prefix = L();
652
+ const prefix = g();
655
653
  const bp = drawer.getAttribute(`data-${this.settings.dataBreakpoint}`);
656
654
 
657
655
  if (this.settings.breakpoints && this.settings.breakpoints[bp]) {
@@ -735,9 +733,9 @@ async function initialState(entry) {
735
733
  // 1. If a store state is available, restore from local store.
736
734
  // 2. If opened state class is set, set state to opened.
737
735
  // 3. Else, initialize default state.
738
- if (this.store[entry.id]) {
736
+ if (this.store.get(entry.id)) {
739
737
  // Restore drawers to saved inline state.
740
- if (this.store[entry.id] === 'opened') {
738
+ if (this.store.get(entry.id) === 'opened') {
741
739
  await entry.open(false, false);
742
740
  } else {
743
741
  await entry.close(false, false);
@@ -895,9 +893,9 @@ async function toModal(entry) {
895
893
 
896
894
  entry.dialog.setAttribute('aria-modal', 'true'); // If there isn't a stored state but also has the opened state class...
897
895
 
898
- if (!this.store[entry.id] && entry.el.classList.contains(entry.getSetting('stateOpened'))) {
896
+ if (!this.store.get(entry.id) && entry.el.classList.contains(entry.getSetting('stateOpened'))) {
899
897
  // Save the opened state in local store.
900
- this.store[entry.id] = 'opened';
898
+ this.store.set(entry.id, 'opened');
901
899
  } // Modal drawer defaults to closed state.
902
900
 
903
901
 
@@ -978,7 +976,7 @@ async function register$2(el, dialog) {
978
976
  __state = value; // Save 'opened' and 'closed' states to store if mode is inline.
979
977
 
980
978
  if (value === 'opened' || value === 'closed') {
981
- if (this.mode === 'inline') root.store[this.id] = this.state;
979
+ if (this.mode === 'inline') root.store.set(this.id, this.state);
982
980
  }
983
981
  },
984
982
 
@@ -1233,14 +1231,6 @@ function updateFocusState() {
1233
1231
  }
1234
1232
  }
1235
1233
 
1236
- function updateStackIndex(stack) {
1237
- stack.forEach((entry, index) => {
1238
- entry.el.style.zIndex = null;
1239
- const value = getComputedStyle(entry.el)['z-index'];
1240
- entry.el.style.zIndex = parseInt(value) + index + 1;
1241
- });
1242
- }
1243
-
1244
1234
  async function handleClick$1(event) {
1245
1235
  // If an open or replace button was clicked, open or replace the modal.
1246
1236
  let trigger = event.target.closest(`[data-${this.settings.dataOpen}], [data-${this.settings.dataReplace}]`);
@@ -1297,14 +1287,8 @@ async function deregister$1(obj, close = true) {
1297
1287
  if (close && entry.state === 'opened') {
1298
1288
  await entry.close(false);
1299
1289
  } else {
1300
- // Get index of modal in stack array.
1301
- const stackIndex = this.stack.findIndex(item => {
1302
- return item.id === entry.id;
1303
- }); // Remove modal from stack array.
1304
-
1305
- if (stackIndex >= 0) {
1306
- this.stack.splice(stackIndex, 1);
1307
- }
1290
+ // Remove modal from stack.
1291
+ this.stack.remove(entry);
1308
1292
  } // Return teleported modal if a reference has been set.
1309
1293
 
1310
1294
 
@@ -1331,29 +1315,15 @@ async function open$1(query, transition, focus = true) {
1331
1315
  const config = _extends({}, this.settings, modal.settings); // Add transition parameter to configuration.
1332
1316
 
1333
1317
 
1334
- if (transition !== undefined) config.transition = transition; // Check if modal is already in the stack.
1335
-
1336
- const index = this.stack.findIndex(entry => {
1337
- return entry.id === modal.id;
1338
- }); // If modal is already open.
1339
-
1340
- if (index >= 0) {
1341
- // Remove modal from stack array.
1342
- this.stack.splice(index, 1); // Move back to end of stack.
1343
-
1344
- this.stack.push(modal);
1345
- } // If modal is closed.
1318
+ if (transition !== undefined) config.transition = transition; // Maybe add modal to top of stack.
1346
1319
 
1320
+ this.stack.moveToTop(modal); // If modal is closed.
1347
1321
 
1348
1322
  if (modal.state === 'closed') {
1349
1323
  // Update modal state.
1350
- modal.state = 'opening'; // Apply z-index styles based on stack length.
1351
-
1352
- modal.el.style.zIndex = null;
1353
- const value = getComputedStyle(modal.el)['z-index'];
1354
- modal.el.style.zIndex = parseInt(value) + this.stack.length + 1; // Store modal in stack array.
1324
+ modal.state = 'opening'; // Add modal to stack.
1355
1325
 
1356
- this.stack.push(modal); // Run the open transition.
1326
+ this.stack.add(modal); // Run the open transition.
1357
1327
 
1358
1328
  await openTransition(modal.el, config); // Update modal state.
1359
1329
 
@@ -1389,15 +1359,9 @@ async function close$1(query, transition, focus = true) {
1389
1359
 
1390
1360
  document.activeElement.blur(); // Run the close transition.
1391
1361
 
1392
- await closeTransition(modal.el, config); // Remove z-index styles.
1393
-
1394
- modal.el.style.zIndex = null; // Get index of modal in stack array.
1395
-
1396
- const index = this.stack.findIndex(entry => {
1397
- return entry.id === modal.id;
1398
- }); // Remove modal from stack array.
1362
+ await closeTransition(modal.el, config); // Remove modal from stack.
1399
1363
 
1400
- this.stack.splice(index, 1); // Update focus if the focus param is true.
1364
+ this.stack.remove(modal); // Update focus if the focus param is true.
1401
1365
 
1402
1366
  if (focus) {
1403
1367
  updateFocusState.call(this);
@@ -1418,7 +1382,7 @@ async function close$1(query, transition, focus = true) {
1418
1382
 
1419
1383
  async function closeAll$1(exclude, transition) {
1420
1384
  const result = [];
1421
- await Promise.all(this.stack.map(async modal => {
1385
+ await Promise.all(this.stack.value.map(async modal => {
1422
1386
  if (exclude && exclude === modal.id) {
1423
1387
  Promise.resolve();
1424
1388
  } else {
@@ -1552,6 +1516,74 @@ async function register$1(el, dialog) {
1552
1516
  return entry;
1553
1517
  }
1554
1518
 
1519
+ function stack(settings) {
1520
+ const stackArray = [];
1521
+ return {
1522
+ get value() {
1523
+ return [...stackArray];
1524
+ },
1525
+
1526
+ get top() {
1527
+ return stackArray[stackArray.length - 1];
1528
+ },
1529
+
1530
+ updateIndex() {
1531
+ stackArray.forEach((entry, index) => {
1532
+ entry.el.style.zIndex = null;
1533
+ const value = getComputedStyle(entry.el)['z-index'];
1534
+ entry.el.style.zIndex = parseInt(value) + index + 1;
1535
+ });
1536
+ },
1537
+
1538
+ updateGlobalState() {
1539
+ updateGlobalState(this.top, settings);
1540
+ this.updateIndex();
1541
+ },
1542
+
1543
+ add(entry) {
1544
+ // Apply z-index styles based on stack length.
1545
+ entry.el.style.zIndex = null;
1546
+ const value = getComputedStyle(entry.el)['z-index'];
1547
+ entry.el.style.zIndex = parseInt(value) + stackArray.length + 1; // Move back to end of stack.
1548
+
1549
+ stackArray.push(entry); // Update the global state.
1550
+
1551
+ this.updateGlobalState();
1552
+ },
1553
+
1554
+ remove(entry) {
1555
+ // Get the index of the entry.
1556
+ const index = stackArray.findIndex(item => {
1557
+ return item.id === entry.id;
1558
+ }); // If entry is in stack...
1559
+
1560
+ if (index >= 0) {
1561
+ // Remove z-index styles.
1562
+ entry.el.style.zIndex = null; // Remove entry from stack array.
1563
+
1564
+ stackArray.splice(index, 1); // Update the global state.
1565
+
1566
+ this.updateGlobalState();
1567
+ }
1568
+ },
1569
+
1570
+ moveToTop(entry) {
1571
+ // Get the index of the entry.
1572
+ const index = stackArray.findIndex(item => {
1573
+ return item.id === entry.id;
1574
+ }); // If entry is in stack...
1575
+
1576
+ if (index >= 0) {
1577
+ // Remove entry from stack array.
1578
+ stackArray.splice(index, 1); // Add entry back to top of stack.
1579
+
1580
+ this.add(entry);
1581
+ }
1582
+ }
1583
+
1584
+ };
1585
+ }
1586
+
1555
1587
  var _handleClick = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
1556
1588
 
1557
1589
  var _handleKeydown$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
@@ -1570,27 +1602,16 @@ class Modal extends Collection {
1570
1602
  this.defaults = defaults$1;
1571
1603
  this.settings = _extends({}, this.defaults, options);
1572
1604
  this.trigger = null;
1573
- this.focusTrap = new FocusTrap(); // Setup a proxy for stack array.
1574
-
1575
- this.stack = new Proxy([], {
1576
- set: (target, property, value) => {
1577
- target[property] = value; // Update global state if stack length changed.
1578
-
1579
- if (property === 'length') {
1580
- updateGlobalState(this.active, this.settings);
1581
- updateStackIndex(this.stack);
1582
- }
1605
+ this.focusTrap = new FocusTrap(); // Setup stack module.
1583
1606
 
1584
- return true;
1585
- }
1586
- });
1607
+ this.stack = stack(this.settings);
1587
1608
  _classPrivateFieldLooseBase(this, _handleClick)[_handleClick] = handleClick$1.bind(this);
1588
1609
  _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1] = handleKeydown$1.bind(this);
1589
1610
  if (this.settings.autoInit) this.init();
1590
1611
  }
1591
1612
 
1592
1613
  get active() {
1593
- return this.stack[this.stack.length - 1];
1614
+ return this.stack.top;
1594
1615
  }
1595
1616
 
1596
1617
  async init(options) {
@@ -1697,7 +1718,7 @@ function getConfig(el, settings) {
1697
1718
 
1698
1719
  for (const prop in config) {
1699
1720
  // Get the CSS variable property values.
1700
- const prefix = L();
1721
+ const prefix = g();
1701
1722
  const value = styles.getPropertyValue(`--${prefix}popover-${prop}`).trim(); // If a value was found, replace the default in config obj.
1702
1723
 
1703
1724
  if (value) {