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.
@@ -611,27 +611,23 @@
611
611
  enable = true;
612
612
  }
613
613
 
614
- function getStore() {
615
- var value = localStorage.getItem(key);
616
- return value ? JSON.parse(value) : {};
617
- }
618
-
619
- function setStore(obj) {
620
- localStorage.setItem(key, JSON.stringify(obj));
621
- }
622
-
623
- return new Proxy(getStore(), {
624
- set: function set(target, property, value) {
625
- target[property] = value;
626
- if (enable) setStore(target);
627
- return true;
614
+ var local = localStorage.getItem(key);
615
+ var store = local ? JSON.parse(local) : {};
616
+ return {
617
+ get: function get(prop) {
618
+ return prop ? store[prop] : store;
628
619
  },
629
- deleteProperty: function deleteProperty(target, property) {
630
- delete target[property];
631
- if (enable) setStore(target);
632
- return true;
620
+ set: function set(prop, value) {
621
+ if (value) {
622
+ store[prop] = value;
623
+ } else {
624
+ delete store[prop];
625
+ }
626
+
627
+ if (enable) localStorage.setItem(key, JSON.stringify(store));
628
+ return store;
633
629
  }
634
- });
630
+ };
635
631
  }
636
632
 
637
633
  /**
@@ -971,7 +967,8 @@
971
967
  if (index >= 0) {
972
968
  var _temp7 = function _temp7() {
973
969
  // Remove entry from local store.
974
- delete _this2.store[_entry.id]; // Unmount the MatchMedia functionality.
970
+ _this2.store.set(_entry.id); // Unmount the MatchMedia functionality.
971
+
975
972
 
976
973
  _entry.unmountBreakpoint(); // Delete properties from collection entry.
977
974
 
@@ -1003,12 +1000,12 @@
1003
1000
  }
1004
1001
  };
1005
1002
 
1006
- function L() {
1003
+ function g() {
1007
1004
  return getComputedStyle(document.body).getPropertyValue("--vrembem-variable-prefix").trim();
1008
1005
  }
1009
1006
 
1010
1007
  function getBreakpoint(drawer) {
1011
- var prefix = L();
1008
+ var prefix = g();
1012
1009
  var bp = drawer.getAttribute("data-" + this.settings.dataBreakpoint);
1013
1010
 
1014
1011
  if (this.settings.breakpoints && this.settings.breakpoints[bp]) {
@@ -1092,9 +1089,9 @@
1092
1089
  var _this2 = this;
1093
1090
 
1094
1091
  var _temp3 = function () {
1095
- if (_this2.store[entry.id]) {
1092
+ if (_this2.store.get(entry.id)) {
1096
1093
  var _temp4 = function () {
1097
- if (_this2.store[entry.id] === 'opened') {
1094
+ if (_this2.store.get(entry.id) === 'opened') {
1098
1095
  return Promise.resolve(entry.open(false, false)).then(function () {});
1099
1096
  } else {
1100
1097
  return Promise.resolve(entry.close(false, false)).then(function () {});
@@ -1273,9 +1270,9 @@
1273
1270
 
1274
1271
  entry.dialog.setAttribute('aria-modal', 'true'); // If there isn't a stored state but also has the opened state class...
1275
1272
 
1276
- if (!_this4.store[entry.id] && entry.el.classList.contains(entry.getSetting('stateOpened'))) {
1273
+ if (!_this4.store.get(entry.id) && entry.el.classList.contains(entry.getSetting('stateOpened'))) {
1277
1274
  // Save the opened state in local store.
1278
- _this4.store[entry.id] = 'opened';
1275
+ _this4.store.set(entry.id, 'opened');
1279
1276
  } // Modal drawer defaults to closed state.
1280
1277
 
1281
1278
 
@@ -1396,7 +1393,7 @@
1396
1393
  __state = value; // Save 'opened' and 'closed' states to store if mode is inline.
1397
1394
 
1398
1395
  if (value === 'opened' || value === 'closed') {
1399
- if (this.mode === 'inline') root.store[this.id] = this.state;
1396
+ if (this.mode === 'inline') root.store.set(this.id, this.state);
1400
1397
  }
1401
1398
  },
1402
1399
 
@@ -1689,14 +1686,6 @@
1689
1686
  }
1690
1687
  }
1691
1688
 
1692
- function updateStackIndex(stack) {
1693
- stack.forEach(function (entry, index) {
1694
- entry.el.style.zIndex = null;
1695
- var value = getComputedStyle(entry.el)['z-index'];
1696
- entry.el.style.zIndex = parseInt(value) + index + 1;
1697
- });
1698
- }
1699
-
1700
1689
  var handleClick$1 = function handleClick(event) {
1701
1690
  try {
1702
1691
  var _this2 = this;
@@ -1790,15 +1779,8 @@
1790
1779
  if (close && _entry.state === 'opened') {
1791
1780
  return Promise.resolve(_entry.close(false)).then(function () {});
1792
1781
  } else {
1793
- // Get index of modal in stack array.
1794
- var stackIndex = _this2.stack.findIndex(function (item) {
1795
- return item.id === _entry.id;
1796
- }); // Remove modal from stack array.
1797
-
1798
-
1799
- if (stackIndex >= 0) {
1800
- _this2.stack.splice(stackIndex, 1);
1801
- }
1782
+ // Remove modal from stack.
1783
+ _this2.stack.remove(_entry);
1802
1784
  }
1803
1785
  }();
1804
1786
 
@@ -1841,32 +1823,17 @@
1841
1823
  var config = _extends({}, _this2.settings, modal.settings); // Add transition parameter to configuration.
1842
1824
 
1843
1825
 
1844
- if (transition !== undefined) config.transition = transition; // Check if modal is already in the stack.
1845
-
1846
- var index = _this2.stack.findIndex(function (entry) {
1847
- return entry.id === modal.id;
1848
- }); // If modal is already open.
1826
+ if (transition !== undefined) config.transition = transition; // Maybe add modal to top of stack.
1849
1827
 
1850
-
1851
- if (index >= 0) {
1852
- // Remove modal from stack array.
1853
- _this2.stack.splice(index, 1); // Move back to end of stack.
1854
-
1855
-
1856
- _this2.stack.push(modal);
1857
- } // If modal is closed.
1828
+ _this2.stack.moveToTop(modal); // If modal is closed.
1858
1829
 
1859
1830
 
1860
1831
  var _temp4 = function () {
1861
1832
  if (modal.state === 'closed') {
1862
1833
  // Update modal state.
1863
- modal.state = 'opening'; // Apply z-index styles based on stack length.
1864
-
1865
- modal.el.style.zIndex = null;
1866
- var value = getComputedStyle(modal.el)['z-index'];
1867
- modal.el.style.zIndex = parseInt(value) + _this2.stack.length + 1; // Store modal in stack array.
1834
+ modal.state = 'opening'; // Add modal to stack.
1868
1835
 
1869
- _this2.stack.push(modal); // Run the open transition.
1836
+ _this2.stack.add(modal); // Run the open transition.
1870
1837
 
1871
1838
 
1872
1839
  return Promise.resolve(openTransition(modal.el, config)).then(function () {
@@ -1906,15 +1873,8 @@
1906
1873
  document.activeElement.blur(); // Run the close transition.
1907
1874
 
1908
1875
  return Promise.resolve(closeTransition(modal.el, config)).then(function () {
1909
- // Remove z-index styles.
1910
- modal.el.style.zIndex = null; // Get index of modal in stack array.
1911
-
1912
- var index = _this2.stack.findIndex(function (entry) {
1913
- return entry.id === modal.id;
1914
- }); // Remove modal from stack array.
1915
-
1916
-
1917
- _this2.stack.splice(index, 1); // Update focus if the focus param is true.
1876
+ // Remove modal from stack.
1877
+ _this2.stack.remove(modal); // Update focus if the focus param is true.
1918
1878
 
1919
1879
 
1920
1880
  if (focus) {
@@ -1946,7 +1906,7 @@
1946
1906
  var _this2 = this;
1947
1907
 
1948
1908
  var result = [];
1949
- return Promise.resolve(Promise.all(_this2.stack.map(function (modal) {
1909
+ return Promise.resolve(Promise.all(_this2.stack.value.map(function (modal) {
1950
1910
  try {
1951
1911
  var _temp3 = function _temp3() {
1952
1912
  modal.trigger = null;
@@ -2128,6 +2088,70 @@
2128
2088
  }
2129
2089
  };
2130
2090
 
2091
+ function stack(settings) {
2092
+ var stackArray = [];
2093
+ return {
2094
+ get value() {
2095
+ return [].concat(stackArray);
2096
+ },
2097
+
2098
+ get top() {
2099
+ return stackArray[stackArray.length - 1];
2100
+ },
2101
+
2102
+ updateIndex: function updateIndex() {
2103
+ stackArray.forEach(function (entry, index) {
2104
+ entry.el.style.zIndex = null;
2105
+ var value = getComputedStyle(entry.el)['z-index'];
2106
+ entry.el.style.zIndex = parseInt(value) + index + 1;
2107
+ });
2108
+ },
2109
+ updateGlobalState: function updateGlobalState$1() {
2110
+ updateGlobalState(this.top, settings);
2111
+
2112
+ this.updateIndex();
2113
+ },
2114
+ add: function add(entry) {
2115
+ // Apply z-index styles based on stack length.
2116
+ entry.el.style.zIndex = null;
2117
+ var value = getComputedStyle(entry.el)['z-index'];
2118
+ entry.el.style.zIndex = parseInt(value) + stackArray.length + 1; // Move back to end of stack.
2119
+
2120
+ stackArray.push(entry); // Update the global state.
2121
+
2122
+ this.updateGlobalState();
2123
+ },
2124
+ remove: function remove(entry) {
2125
+ // Get the index of the entry.
2126
+ var index = stackArray.findIndex(function (item) {
2127
+ return item.id === entry.id;
2128
+ }); // If entry is in stack...
2129
+
2130
+ if (index >= 0) {
2131
+ // Remove z-index styles.
2132
+ entry.el.style.zIndex = null; // Remove entry from stack array.
2133
+
2134
+ stackArray.splice(index, 1); // Update the global state.
2135
+
2136
+ this.updateGlobalState();
2137
+ }
2138
+ },
2139
+ moveToTop: function moveToTop(entry) {
2140
+ // Get the index of the entry.
2141
+ var index = stackArray.findIndex(function (item) {
2142
+ return item.id === entry.id;
2143
+ }); // If entry is in stack...
2144
+
2145
+ if (index >= 0) {
2146
+ // Remove entry from stack array.
2147
+ stackArray.splice(index, 1); // Add entry back to top of stack.
2148
+
2149
+ this.add(entry);
2150
+ }
2151
+ }
2152
+ };
2153
+ }
2154
+
2131
2155
  var _handleClick = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
2132
2156
 
2133
2157
  var _handleKeydown$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
@@ -2150,20 +2174,9 @@
2150
2174
  _this.defaults = defaults$1;
2151
2175
  _this.settings = _extends({}, _this.defaults, options);
2152
2176
  _this.trigger = null;
2153
- _this.focusTrap = new FocusTrap(); // Setup a proxy for stack array.
2154
-
2155
- _this.stack = new Proxy([], {
2156
- set: function set(target, property, value) {
2157
- target[property] = value; // Update global state if stack length changed.
2158
-
2159
- if (property === 'length') {
2160
- updateGlobalState(_this.active, _this.settings);
2161
- updateStackIndex(_this.stack);
2162
- }
2177
+ _this.focusTrap = new FocusTrap(); // Setup stack module.
2163
2178
 
2164
- return true;
2165
- }
2166
- });
2179
+ _this.stack = stack(_this.settings);
2167
2180
  _classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleClick)[_handleClick] = handleClick$1.bind(_assertThisInitialized(_this));
2168
2181
  _classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleKeydown$1)[_handleKeydown$1] = handleKeydown$1.bind(_assertThisInitialized(_this));
2169
2182
  if (_this.settings.autoInit) _this.init();
@@ -2277,7 +2290,7 @@
2277
2290
  _createClass(Modal, [{
2278
2291
  key: "active",
2279
2292
  get: function get() {
2280
- return this.stack[this.stack.length - 1];
2293
+ return this.stack.top;
2281
2294
  }
2282
2295
  }]);
2283
2296
 
@@ -2313,7 +2326,7 @@
2313
2326
 
2314
2327
  for (var prop in config) {
2315
2328
  // Get the CSS variable property values.
2316
- var prefix = L();
2329
+ var prefix = g();
2317
2330
  var value = styles.getPropertyValue("--" + prefix + "popover-" + prop).trim(); // If a value was found, replace the default in config obj.
2318
2331
 
2319
2332
  if (value) {