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.
@@ -606,29 +606,23 @@ function localStore(key, enable) {
606
606
  enable = true;
607
607
  }
608
608
 
609
- function getStore() {
610
- var value = localStorage.getItem(key);
611
- return value ? JSON.parse(value) : {};
612
- }
613
-
614
- function setStore(obj) {
615
- localStorage.setItem(key, JSON.stringify(obj));
616
- }
617
-
618
- return new Proxy(getStore(), {
619
- set: function set(target, property, value) {
620
- console.log('localStore() => set');
621
-
622
- if (value === undefined) {
623
- delete target[property];
609
+ var local = localStorage.getItem(key);
610
+ var store = local ? JSON.parse(local) : {};
611
+ return {
612
+ get: function get(prop) {
613
+ return prop ? store[prop] : store;
614
+ },
615
+ set: function set(prop, value) {
616
+ if (value) {
617
+ store[prop] = value;
624
618
  } else {
625
- target[property] = value;
619
+ delete store[prop];
626
620
  }
627
621
 
628
- if (enable) setStore(target);
629
- return true;
622
+ if (enable) localStorage.setItem(key, JSON.stringify(store));
623
+ return store;
630
624
  }
631
- });
625
+ };
632
626
  }
633
627
 
634
628
  /**
@@ -968,7 +962,8 @@ var deregister$2 = function deregister(obj, close) {
968
962
  if (index >= 0) {
969
963
  var _temp7 = function _temp7() {
970
964
  // Remove entry from local store.
971
- _this2.store[_entry.id] = undefined; // Unmount the MatchMedia functionality.
965
+ _this2.store.set(_entry.id); // Unmount the MatchMedia functionality.
966
+
972
967
 
973
968
  _entry.unmountBreakpoint(); // Delete properties from collection entry.
974
969
 
@@ -1089,9 +1084,9 @@ var initialState = function initialState(entry) {
1089
1084
  var _this2 = this;
1090
1085
 
1091
1086
  var _temp3 = function () {
1092
- if (_this2.store[entry.id]) {
1087
+ if (_this2.store.get(entry.id)) {
1093
1088
  var _temp4 = function () {
1094
- if (_this2.store[entry.id] === 'opened') {
1089
+ if (_this2.store.get(entry.id) === 'opened') {
1095
1090
  return Promise.resolve(entry.open(false, false)).then(function () {});
1096
1091
  } else {
1097
1092
  return Promise.resolve(entry.close(false, false)).then(function () {});
@@ -1270,9 +1265,9 @@ var toModal = function toModal(entry) {
1270
1265
 
1271
1266
  entry.dialog.setAttribute('aria-modal', 'true'); // If there isn't a stored state but also has the opened state class...
1272
1267
 
1273
- if (!_this4.store[entry.id] && entry.el.classList.contains(entry.getSetting('stateOpened'))) {
1268
+ if (!_this4.store.get(entry.id) && entry.el.classList.contains(entry.getSetting('stateOpened'))) {
1274
1269
  // Save the opened state in local store.
1275
- _this4.store[entry.id] = 'opened';
1270
+ _this4.store.set(entry.id, 'opened');
1276
1271
  } // Modal drawer defaults to closed state.
1277
1272
 
1278
1273
 
@@ -1393,7 +1388,7 @@ var register$2 = function register(el, dialog) {
1393
1388
  __state = value; // Save 'opened' and 'closed' states to store if mode is inline.
1394
1389
 
1395
1390
  if (value === 'opened' || value === 'closed') {
1396
- if (this.mode === 'inline') root.store[this.id] = this.state;
1391
+ if (this.mode === 'inline') root.store.set(this.id, this.state);
1397
1392
  }
1398
1393
  },
1399
1394
 
@@ -1686,14 +1681,6 @@ function updateFocusState() {
1686
1681
  }
1687
1682
  }
1688
1683
 
1689
- function updateStackIndex(stack) {
1690
- stack.forEach(function (entry, index) {
1691
- entry.el.style.zIndex = null;
1692
- var value = getComputedStyle(entry.el)['z-index'];
1693
- entry.el.style.zIndex = parseInt(value) + index + 1;
1694
- });
1695
- }
1696
-
1697
1684
  var handleClick$1 = function handleClick(event) {
1698
1685
  try {
1699
1686
  var _this2 = this;
@@ -1787,15 +1774,8 @@ var deregister$1 = function deregister(obj, close) {
1787
1774
  if (close && _entry.state === 'opened') {
1788
1775
  return Promise.resolve(_entry.close(false)).then(function () {});
1789
1776
  } else {
1790
- // Get index of modal in stack array.
1791
- var stackIndex = _this2.stack.findIndex(function (item) {
1792
- return item.id === _entry.id;
1793
- }); // Remove modal from stack array.
1794
-
1795
-
1796
- if (stackIndex >= 0) {
1797
- _this2.stack.splice(stackIndex, 1);
1798
- }
1777
+ // Remove modal from stack.
1778
+ _this2.stack.remove(_entry);
1799
1779
  }
1800
1780
  }();
1801
1781
 
@@ -1838,32 +1818,17 @@ var open$1 = function open(query, transition, focus) {
1838
1818
  var config = _extends({}, _this2.settings, modal.settings); // Add transition parameter to configuration.
1839
1819
 
1840
1820
 
1841
- if (transition !== undefined) config.transition = transition; // Check if modal is already in the stack.
1842
-
1843
- var index = _this2.stack.findIndex(function (entry) {
1844
- return entry.id === modal.id;
1845
- }); // If modal is already open.
1821
+ if (transition !== undefined) config.transition = transition; // Maybe add modal to top of stack.
1846
1822
 
1847
-
1848
- if (index >= 0) {
1849
- // Remove modal from stack array.
1850
- _this2.stack.splice(index, 1); // Move back to end of stack.
1851
-
1852
-
1853
- _this2.stack.push(modal);
1854
- } // If modal is closed.
1823
+ _this2.stack.moveToTop(modal); // If modal is closed.
1855
1824
 
1856
1825
 
1857
1826
  var _temp4 = function () {
1858
1827
  if (modal.state === 'closed') {
1859
1828
  // Update modal state.
1860
- modal.state = 'opening'; // Apply z-index styles based on stack length.
1861
-
1862
- modal.el.style.zIndex = null;
1863
- var value = getComputedStyle(modal.el)['z-index'];
1864
- modal.el.style.zIndex = parseInt(value) + _this2.stack.length + 1; // Store modal in stack array.
1829
+ modal.state = 'opening'; // Add modal to stack.
1865
1830
 
1866
- _this2.stack.push(modal); // Run the open transition.
1831
+ _this2.stack.add(modal); // Run the open transition.
1867
1832
 
1868
1833
 
1869
1834
  return Promise.resolve(openTransition(modal.el, config)).then(function () {
@@ -1903,15 +1868,8 @@ var close$1 = function close(query, transition, focus) {
1903
1868
  document.activeElement.blur(); // Run the close transition.
1904
1869
 
1905
1870
  return Promise.resolve(closeTransition(modal.el, config)).then(function () {
1906
- // Remove z-index styles.
1907
- modal.el.style.zIndex = null; // Get index of modal in stack array.
1908
-
1909
- var index = _this2.stack.findIndex(function (entry) {
1910
- return entry.id === modal.id;
1911
- }); // Remove modal from stack array.
1912
-
1913
-
1914
- _this2.stack.splice(index, 1); // Update focus if the focus param is true.
1871
+ // Remove modal from stack.
1872
+ _this2.stack.remove(modal); // Update focus if the focus param is true.
1915
1873
 
1916
1874
 
1917
1875
  if (focus) {
@@ -1943,7 +1901,7 @@ var closeAll$1 = function closeAll(exclude, transition) {
1943
1901
  var _this2 = this;
1944
1902
 
1945
1903
  var result = [];
1946
- return Promise.resolve(Promise.all(_this2.stack.map(function (modal) {
1904
+ return Promise.resolve(Promise.all(_this2.stack.value.map(function (modal) {
1947
1905
  try {
1948
1906
  var _temp3 = function _temp3() {
1949
1907
  modal.trigger = null;
@@ -2125,6 +2083,70 @@ var register$1 = function register(el, dialog) {
2125
2083
  }
2126
2084
  };
2127
2085
 
2086
+ function stack(settings) {
2087
+ var stackArray = [];
2088
+ return {
2089
+ get value() {
2090
+ return [].concat(stackArray);
2091
+ },
2092
+
2093
+ get top() {
2094
+ return stackArray[stackArray.length - 1];
2095
+ },
2096
+
2097
+ updateIndex: function updateIndex() {
2098
+ stackArray.forEach(function (entry, index) {
2099
+ entry.el.style.zIndex = null;
2100
+ var value = getComputedStyle(entry.el)['z-index'];
2101
+ entry.el.style.zIndex = parseInt(value) + index + 1;
2102
+ });
2103
+ },
2104
+ updateGlobalState: function updateGlobalState$1() {
2105
+ updateGlobalState(this.top, settings);
2106
+
2107
+ this.updateIndex();
2108
+ },
2109
+ add: function add(entry) {
2110
+ // Apply z-index styles based on stack length.
2111
+ entry.el.style.zIndex = null;
2112
+ var value = getComputedStyle(entry.el)['z-index'];
2113
+ entry.el.style.zIndex = parseInt(value) + stackArray.length + 1; // Move back to end of stack.
2114
+
2115
+ stackArray.push(entry); // Update the global state.
2116
+
2117
+ this.updateGlobalState();
2118
+ },
2119
+ remove: function remove(entry) {
2120
+ // Get the index of the entry.
2121
+ var index = stackArray.findIndex(function (item) {
2122
+ return item.id === entry.id;
2123
+ }); // If entry is in stack...
2124
+
2125
+ if (index >= 0) {
2126
+ // Remove z-index styles.
2127
+ entry.el.style.zIndex = null; // Remove entry from stack array.
2128
+
2129
+ stackArray.splice(index, 1); // Update the global state.
2130
+
2131
+ this.updateGlobalState();
2132
+ }
2133
+ },
2134
+ moveToTop: function moveToTop(entry) {
2135
+ // Get the index of the entry.
2136
+ var index = stackArray.findIndex(function (item) {
2137
+ return item.id === entry.id;
2138
+ }); // If entry is in stack...
2139
+
2140
+ if (index >= 0) {
2141
+ // Remove entry from stack array.
2142
+ stackArray.splice(index, 1); // Add entry back to top of stack.
2143
+
2144
+ this.add(entry);
2145
+ }
2146
+ }
2147
+ };
2148
+ }
2149
+
2128
2150
  var _handleClick = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
2129
2151
 
2130
2152
  var _handleKeydown$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
@@ -2147,20 +2169,9 @@ var Modal = /*#__PURE__*/function (_Collection) {
2147
2169
  _this.defaults = defaults$1;
2148
2170
  _this.settings = _extends({}, _this.defaults, options);
2149
2171
  _this.trigger = null;
2150
- _this.focusTrap = new FocusTrap(); // Setup a proxy for stack array.
2151
-
2152
- _this.stack = new Proxy([], {
2153
- set: function set(target, property, value) {
2154
- target[property] = value; // Update global state if stack length changed.
2155
-
2156
- if (property === 'length') {
2157
- updateGlobalState(_this.active, _this.settings);
2158
- updateStackIndex(_this.stack);
2159
- }
2172
+ _this.focusTrap = new FocusTrap(); // Setup stack module.
2160
2173
 
2161
- return true;
2162
- }
2163
- });
2174
+ _this.stack = stack(_this.settings);
2164
2175
  _classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleClick)[_handleClick] = handleClick$1.bind(_assertThisInitialized(_this));
2165
2176
  _classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleKeydown$1)[_handleKeydown$1] = handleKeydown$1.bind(_assertThisInitialized(_this));
2166
2177
  if (_this.settings.autoInit) _this.init();
@@ -2274,7 +2285,7 @@ var Modal = /*#__PURE__*/function (_Collection) {
2274
2285
  _createClass(Modal, [{
2275
2286
  key: "active",
2276
2287
  get: function get() {
2277
- return this.stack[this.stack.length - 1];
2288
+ return this.stack.top;
2278
2289
  }
2279
2290
  }]);
2280
2291