vrembem 3.0.7 → 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,29 +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
- console.log('localStore() => set');
626
-
627
- if (value === undefined) {
628
- delete target[property];
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;
619
+ },
620
+ set: function set(prop, value) {
621
+ if (value) {
622
+ store[prop] = value;
629
623
  } else {
630
- target[property] = value;
624
+ delete store[prop];
631
625
  }
632
626
 
633
- if (enable) setStore(target);
634
- return true;
627
+ if (enable) localStorage.setItem(key, JSON.stringify(store));
628
+ return store;
635
629
  }
636
- });
630
+ };
637
631
  }
638
632
 
639
633
  /**
@@ -973,7 +967,8 @@
973
967
  if (index >= 0) {
974
968
  var _temp7 = function _temp7() {
975
969
  // Remove entry from local store.
976
- _this2.store[_entry.id] = undefined; // Unmount the MatchMedia functionality.
970
+ _this2.store.set(_entry.id); // Unmount the MatchMedia functionality.
971
+
977
972
 
978
973
  _entry.unmountBreakpoint(); // Delete properties from collection entry.
979
974
 
@@ -1094,9 +1089,9 @@
1094
1089
  var _this2 = this;
1095
1090
 
1096
1091
  var _temp3 = function () {
1097
- if (_this2.store[entry.id]) {
1092
+ if (_this2.store.get(entry.id)) {
1098
1093
  var _temp4 = function () {
1099
- if (_this2.store[entry.id] === 'opened') {
1094
+ if (_this2.store.get(entry.id) === 'opened') {
1100
1095
  return Promise.resolve(entry.open(false, false)).then(function () {});
1101
1096
  } else {
1102
1097
  return Promise.resolve(entry.close(false, false)).then(function () {});
@@ -1275,9 +1270,9 @@
1275
1270
 
1276
1271
  entry.dialog.setAttribute('aria-modal', 'true'); // If there isn't a stored state but also has the opened state class...
1277
1272
 
1278
- 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'))) {
1279
1274
  // Save the opened state in local store.
1280
- _this4.store[entry.id] = 'opened';
1275
+ _this4.store.set(entry.id, 'opened');
1281
1276
  } // Modal drawer defaults to closed state.
1282
1277
 
1283
1278
 
@@ -1398,7 +1393,7 @@
1398
1393
  __state = value; // Save 'opened' and 'closed' states to store if mode is inline.
1399
1394
 
1400
1395
  if (value === 'opened' || value === 'closed') {
1401
- if (this.mode === 'inline') root.store[this.id] = this.state;
1396
+ if (this.mode === 'inline') root.store.set(this.id, this.state);
1402
1397
  }
1403
1398
  },
1404
1399
 
@@ -1691,14 +1686,6 @@
1691
1686
  }
1692
1687
  }
1693
1688
 
1694
- function updateStackIndex(stack) {
1695
- stack.forEach(function (entry, index) {
1696
- entry.el.style.zIndex = null;
1697
- var value = getComputedStyle(entry.el)['z-index'];
1698
- entry.el.style.zIndex = parseInt(value) + index + 1;
1699
- });
1700
- }
1701
-
1702
1689
  var handleClick$1 = function handleClick(event) {
1703
1690
  try {
1704
1691
  var _this2 = this;
@@ -1792,15 +1779,8 @@
1792
1779
  if (close && _entry.state === 'opened') {
1793
1780
  return Promise.resolve(_entry.close(false)).then(function () {});
1794
1781
  } else {
1795
- // Get index of modal in stack array.
1796
- var stackIndex = _this2.stack.findIndex(function (item) {
1797
- return item.id === _entry.id;
1798
- }); // Remove modal from stack array.
1799
-
1800
-
1801
- if (stackIndex >= 0) {
1802
- _this2.stack.splice(stackIndex, 1);
1803
- }
1782
+ // Remove modal from stack.
1783
+ _this2.stack.remove(_entry);
1804
1784
  }
1805
1785
  }();
1806
1786
 
@@ -1843,32 +1823,17 @@
1843
1823
  var config = _extends({}, _this2.settings, modal.settings); // Add transition parameter to configuration.
1844
1824
 
1845
1825
 
1846
- if (transition !== undefined) config.transition = transition; // Check if modal is already in the stack.
1847
-
1848
- var index = _this2.stack.findIndex(function (entry) {
1849
- return entry.id === modal.id;
1850
- }); // If modal is already open.
1826
+ if (transition !== undefined) config.transition = transition; // Maybe add modal to top of stack.
1851
1827
 
1852
-
1853
- if (index >= 0) {
1854
- // Remove modal from stack array.
1855
- _this2.stack.splice(index, 1); // Move back to end of stack.
1856
-
1857
-
1858
- _this2.stack.push(modal);
1859
- } // If modal is closed.
1828
+ _this2.stack.moveToTop(modal); // If modal is closed.
1860
1829
 
1861
1830
 
1862
1831
  var _temp4 = function () {
1863
1832
  if (modal.state === 'closed') {
1864
1833
  // Update modal state.
1865
- modal.state = 'opening'; // Apply z-index styles based on stack length.
1866
-
1867
- modal.el.style.zIndex = null;
1868
- var value = getComputedStyle(modal.el)['z-index'];
1869
- modal.el.style.zIndex = parseInt(value) + _this2.stack.length + 1; // Store modal in stack array.
1834
+ modal.state = 'opening'; // Add modal to stack.
1870
1835
 
1871
- _this2.stack.push(modal); // Run the open transition.
1836
+ _this2.stack.add(modal); // Run the open transition.
1872
1837
 
1873
1838
 
1874
1839
  return Promise.resolve(openTransition(modal.el, config)).then(function () {
@@ -1908,15 +1873,8 @@
1908
1873
  document.activeElement.blur(); // Run the close transition.
1909
1874
 
1910
1875
  return Promise.resolve(closeTransition(modal.el, config)).then(function () {
1911
- // Remove z-index styles.
1912
- modal.el.style.zIndex = null; // Get index of modal in stack array.
1913
-
1914
- var index = _this2.stack.findIndex(function (entry) {
1915
- return entry.id === modal.id;
1916
- }); // Remove modal from stack array.
1917
-
1918
-
1919
- _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.
1920
1878
 
1921
1879
 
1922
1880
  if (focus) {
@@ -1948,7 +1906,7 @@
1948
1906
  var _this2 = this;
1949
1907
 
1950
1908
  var result = [];
1951
- return Promise.resolve(Promise.all(_this2.stack.map(function (modal) {
1909
+ return Promise.resolve(Promise.all(_this2.stack.value.map(function (modal) {
1952
1910
  try {
1953
1911
  var _temp3 = function _temp3() {
1954
1912
  modal.trigger = null;
@@ -2130,6 +2088,70 @@
2130
2088
  }
2131
2089
  };
2132
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
+
2133
2155
  var _handleClick = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
2134
2156
 
2135
2157
  var _handleKeydown$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
@@ -2152,20 +2174,9 @@
2152
2174
  _this.defaults = defaults$1;
2153
2175
  _this.settings = _extends({}, _this.defaults, options);
2154
2176
  _this.trigger = null;
2155
- _this.focusTrap = new FocusTrap(); // Setup a proxy for stack array.
2156
-
2157
- _this.stack = new Proxy([], {
2158
- set: function set(target, property, value) {
2159
- target[property] = value; // Update global state if stack length changed.
2160
-
2161
- if (property === 'length') {
2162
- updateGlobalState(_this.active, _this.settings);
2163
- updateStackIndex(_this.stack);
2164
- }
2177
+ _this.focusTrap = new FocusTrap(); // Setup stack module.
2165
2178
 
2166
- return true;
2167
- }
2168
- });
2179
+ _this.stack = stack(_this.settings);
2169
2180
  _classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleClick)[_handleClick] = handleClick$1.bind(_assertThisInitialized(_this));
2170
2181
  _classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleKeydown$1)[_handleKeydown$1] = handleKeydown$1.bind(_assertThisInitialized(_this));
2171
2182
  if (_this.settings.autoInit) _this.init();
@@ -2279,7 +2290,7 @@
2279
2290
  _createClass(Modal, [{
2280
2291
  key: "active",
2281
2292
  get: function get() {
2282
- return this.stack[this.stack.length - 1];
2293
+ return this.stack.top;
2283
2294
  }
2284
2295
  }]);
2285
2296