@pageboard/html 0.10.23 → 0.10.25

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.
@@ -16,30 +16,36 @@ exports.consent_form = {
16
16
  id: "content",
17
17
  nodes: "block+"
18
18
  },
19
- upgrade: {
20
- 'content.': 'content.content'
21
- },
22
19
  html: `<form is="element-consent" class="ui form" data-transient="[transient]">
23
- <x[transient|?:template:div|fill] block-content="content"></x[transient|?:template:div|fill]>
20
+ <template block-content="content"></template>
21
+ <div class="view"></div>
24
22
  </form>`,
25
23
  scripts: ['../ui/storage.js', '../ui/consent.js'],
26
24
  stylesheets: ['../ui/consent.css']
27
25
  };
28
26
 
27
+ const consents = [];
28
+
29
29
  exports.input_radio_yes = {
30
30
  title: 'Yes',
31
31
  icon: '<i class="thumbs up icon"></i>',
32
32
  menu: "form",
33
33
  group: "block",
34
34
  context: 'consent_form//',
35
+ properties: {
36
+ consent: {
37
+ title: 'Consent',
38
+ anyOf: consents
39
+ }
40
+ },
35
41
  contents: {
36
42
  id: 'label',
37
43
  nodes: 'inline*'
38
44
  },
39
45
  html: `<div class="field">
40
46
  <div class="ui radio checkbox">
41
- <input type="radio" name="consent" value="yes" id="for-consent-yes" />
42
- <label block-content="label" for="for-consent-yes">Yes</label>
47
+ <input type="radio" name="consent.[consent]" value="yes" id="for-consent-yes-[consent]" />
48
+ <label block-content="label" for="for-consent-yes-[consent]">Yes</label>
43
49
  </div>
44
50
  </div>`
45
51
  };
@@ -50,14 +56,20 @@ exports.input_radio_no = {
50
56
  menu: "form",
51
57
  group: "block",
52
58
  context: 'consent_form//',
59
+ properties: {
60
+ consent: {
61
+ title: 'Consent',
62
+ anyOf: consents
63
+ }
64
+ },
53
65
  contents: {
54
66
  id: 'label',
55
67
  nodes: 'inline*'
56
68
  },
57
69
  html: `<div class="field">
58
70
  <div class="ui radio checkbox">
59
- <input type="radio" name="consent" value="no" id="for-consent-no" />
60
- <label block-content="label" for="for-consent-no">No</label>
71
+ <input type="radio" name="consent.[consent]" value="no" id="for-consent-no-[consent]" />
72
+ <label block-content="label" for="for-consent-no-[consent]">No</label>
61
73
  </div>
62
74
  </div>`
63
75
  };
package/elements/embed.js CHANGED
@@ -36,3 +36,7 @@ exports.embed = {
36
36
  ]
37
37
  };
38
38
 
39
+ exports.input_radio_yes.properties.consent.anyOf.push({
40
+ title: "Embeds",
41
+ const: "embed"
42
+ });
package/lib/nouislider.js CHANGED
@@ -713,7 +713,9 @@
713
713
  var snap = entry.indexOf("snap") >= 0;
714
714
  var hover = entry.indexOf("hover") >= 0;
715
715
  var unconstrained = entry.indexOf("unconstrained") >= 0;
716
+ var invertConnects = entry.indexOf("invert-connects") >= 0;
716
717
  var dragAll = entry.indexOf("drag-all") >= 0;
718
+ var smoothSteps = entry.indexOf("smooth-steps") >= 0;
717
719
  if (fixed) {
718
720
  if (parsed.handles !== 2) {
719
721
  throw new Error("noUiSlider: 'fixed' behaviour must be used with 2 handles");
@@ -721,6 +723,9 @@
721
723
  // Use margin to enforce fixed state
722
724
  testMargin(parsed, parsed.start[1] - parsed.start[0]);
723
725
  }
726
+ if (invertConnects && parsed.handles !== 2) {
727
+ throw new Error("noUiSlider: 'invert-connects' behaviour must be used with 2 handles");
728
+ }
724
729
  if (unconstrained && (parsed.margin || parsed.limit)) {
725
730
  throw new Error("noUiSlider: 'unconstrained' behaviour cannot be used with margin or limit");
726
731
  }
@@ -728,10 +733,12 @@
728
733
  tap: tap || snap,
729
734
  drag: drag,
730
735
  dragAll: dragAll,
736
+ smoothSteps: smoothSteps,
731
737
  fixed: fixed,
732
738
  snap: snap,
733
739
  hover: hover,
734
740
  unconstrained: unconstrained,
741
+ invertConnects: invertConnects,
735
742
  };
736
743
  }
737
744
  function testTooltips(parsed, entry) {
@@ -902,6 +909,7 @@
902
909
  // Slider DOM Nodes
903
910
  var scope_Target = target;
904
911
  var scope_Base;
912
+ var scope_ConnectBase;
905
913
  var scope_Handles;
906
914
  var scope_Connects;
907
915
  var scope_Pips;
@@ -913,6 +921,7 @@
913
921
  var scope_HandleNumbers = [];
914
922
  var scope_ActiveHandlesCount = 0;
915
923
  var scope_Events = {};
924
+ var scope_ConnectsInverted = false;
916
925
  // Document Nodes
917
926
  var scope_Document = target.ownerDocument;
918
927
  var scope_DocumentElement = options.documentElement || scope_Document.documentElement;
@@ -957,6 +966,7 @@
957
966
  else if (handleNumber === options.handles - 1) {
958
967
  addClass(handle, options.cssClasses.handleUpper);
959
968
  }
969
+ origin.handle = handle;
960
970
  return origin;
961
971
  }
962
972
  // Insert nodes for connect elements
@@ -968,17 +978,17 @@
968
978
  }
969
979
  // Add handles to the slider base.
970
980
  function addElements(connectOptions, base) {
971
- var connectBase = addNodeTo(base, options.cssClasses.connects);
981
+ scope_ConnectBase = addNodeTo(base, options.cssClasses.connects);
972
982
  scope_Handles = [];
973
983
  scope_Connects = [];
974
- scope_Connects.push(addConnect(connectBase, connectOptions[0]));
984
+ scope_Connects.push(addConnect(scope_ConnectBase, connectOptions[0]));
975
985
  // [::::O====O====O====]
976
986
  // connectOptions = [0, 1, 1, 1]
977
987
  for (var i = 0; i < options.handles; i++) {
978
988
  // Keep a list of all added handles.
979
989
  scope_Handles.push(addOrigin(base, i));
980
990
  scope_HandleNumbers[i] = i;
981
- scope_Connects.push(addConnect(connectBase, connectOptions[i + 1]));
991
+ scope_Connects.push(addConnect(scope_ConnectBase, connectOptions[i + 1]));
982
992
  }
983
993
  }
984
994
  // Initialize a single slider.
@@ -1020,6 +1030,31 @@
1020
1030
  var handleOrigin = scope_Handles[handleNumber];
1021
1031
  return handleOrigin.hasAttribute("disabled");
1022
1032
  }
1033
+ function disable(handleNumber) {
1034
+ if (handleNumber !== null && handleNumber !== undefined) {
1035
+ scope_Handles[handleNumber].setAttribute("disabled", "");
1036
+ scope_Handles[handleNumber].handle.removeAttribute("tabindex");
1037
+ }
1038
+ else {
1039
+ scope_Target.setAttribute("disabled", "");
1040
+ scope_Handles.forEach(function (handle) {
1041
+ handle.handle.removeAttribute("tabindex");
1042
+ });
1043
+ }
1044
+ }
1045
+ function enable(handleNumber) {
1046
+ if (handleNumber !== null && handleNumber !== undefined) {
1047
+ scope_Handles[handleNumber].removeAttribute("disabled");
1048
+ scope_Handles[handleNumber].handle.setAttribute("tabindex", "0");
1049
+ }
1050
+ else {
1051
+ scope_Target.removeAttribute("disabled");
1052
+ scope_Handles.forEach(function (handle) {
1053
+ handle.removeAttribute("disabled");
1054
+ handle.handle.setAttribute("tabindex", "0");
1055
+ });
1056
+ }
1057
+ }
1023
1058
  function removeTooltips() {
1024
1059
  if (scope_Tooltips) {
1025
1060
  removeEvent("update" + INTERNAL_EVENT_NS.tooltips);
@@ -1472,6 +1507,14 @@
1472
1507
  scope_Body.removeEventListener("selectstart", preventDefault);
1473
1508
  }
1474
1509
  }
1510
+ if (options.events.smoothSteps) {
1511
+ data.handleNumbers.forEach(function (handleNumber) {
1512
+ setHandle(handleNumber, scope_Locations[handleNumber], true, true, false, false);
1513
+ });
1514
+ data.handleNumbers.forEach(function (handleNumber) {
1515
+ fireEvent("update", handleNumber);
1516
+ });
1517
+ }
1475
1518
  data.handleNumbers.forEach(function (handleNumber) {
1476
1519
  fireEvent("change", handleNumber);
1477
1520
  fireEvent("set", handleNumber);
@@ -1771,7 +1814,7 @@
1771
1814
  });
1772
1815
  }
1773
1816
  // Split out the handle positioning logic so the Move event can use it, too
1774
- function checkHandlePosition(reference, handleNumber, to, lookBackward, lookForward, getValue) {
1817
+ function checkHandlePosition(reference, handleNumber, to, lookBackward, lookForward, getValue, smoothSteps) {
1775
1818
  var distance;
1776
1819
  // For sliders with multiple handles, limit movement to the other handle.
1777
1820
  // Apply the margin option by adding it to the handle positions.
@@ -1810,7 +1853,9 @@
1810
1853
  to = Math.min(to, distance);
1811
1854
  }
1812
1855
  }
1813
- to = scope_Spectrum.getStep(to);
1856
+ if (!smoothSteps) {
1857
+ to = scope_Spectrum.getStep(to);
1858
+ }
1814
1859
  // Limit percentage to the 0 - 100 range
1815
1860
  to = limit(to);
1816
1861
  // Return false if handle can't move
@@ -1830,6 +1875,7 @@
1830
1875
  var proposals = locations.slice();
1831
1876
  // Store first handle now, so we still have it in case handleNumbers is reversed
1832
1877
  var firstHandle = handleNumbers[0];
1878
+ var smoothSteps = options.events.smoothSteps;
1833
1879
  var b = [!upward, upward];
1834
1880
  var f = [upward, !upward];
1835
1881
  // Copy handleNumbers so we don't change the dataset
@@ -1842,7 +1888,7 @@
1842
1888
  // Step 1: get the maximum percentage that any of the handles can move
1843
1889
  if (handleNumbers.length > 1) {
1844
1890
  handleNumbers.forEach(function (handleNumber, o) {
1845
- var to = checkHandlePosition(proposals, handleNumber, proposals[handleNumber] + proposal, b[o], f[o], false);
1891
+ var to = checkHandlePosition(proposals, handleNumber, proposals[handleNumber] + proposal, b[o], f[o], false, smoothSteps);
1846
1892
  // Stop if one of the handles can't move.
1847
1893
  if (to === false) {
1848
1894
  proposal = 0;
@@ -1860,7 +1906,8 @@
1860
1906
  var state = false;
1861
1907
  // Step 2: Try to set the handles with the found percentage
1862
1908
  handleNumbers.forEach(function (handleNumber, o) {
1863
- state = setHandle(handleNumber, locations[handleNumber] + proposal, b[o], f[o]) || state;
1909
+ state =
1910
+ setHandle(handleNumber, locations[handleNumber] + proposal, b[o], f[o], false, smoothSteps) || state;
1864
1911
  });
1865
1912
  // Step 3: If a handle moved, fire events
1866
1913
  if (state) {
@@ -1890,8 +1937,26 @@
1890
1937
  var translation = transformDirection(to, 0) - scope_DirOffset;
1891
1938
  var translateRule = "translate(" + inRuleOrder(translation + "%", "0") + ")";
1892
1939
  scope_Handles[handleNumber].style[options.transformRule] = translateRule;
1940
+ // sanity check for at least 2 handles (e.g. during setup)
1941
+ if (options.events.invertConnects && scope_Locations.length > 1) {
1942
+ // check if handles passed each other, but don't match the ConnectsInverted state
1943
+ var handlesAreInOrder = scope_Locations.every(function (position, index, locations) {
1944
+ return index === 0 || position >= locations[index - 1];
1945
+ });
1946
+ if (scope_ConnectsInverted !== !handlesAreInOrder) {
1947
+ // invert connects when handles pass each other
1948
+ invertConnects();
1949
+ // invertConnects already updates all connect elements
1950
+ return;
1951
+ }
1952
+ }
1893
1953
  updateConnect(handleNumber);
1894
1954
  updateConnect(handleNumber + 1);
1955
+ if (scope_ConnectsInverted) {
1956
+ // When connects are inverted, we also have to update adjacent connects
1957
+ updateConnect(handleNumber - 1);
1958
+ updateConnect(handleNumber + 2);
1959
+ }
1895
1960
  }
1896
1961
  // Handles before the slider middle are stacked later = higher,
1897
1962
  // Handles after the middle later is lower
@@ -1905,9 +1970,9 @@
1905
1970
  }
1906
1971
  // Test suggested values and apply margin, step.
1907
1972
  // if exactInput is true, don't run checkHandlePosition, then the handle can be placed in between steps (#436)
1908
- function setHandle(handleNumber, to, lookBackward, lookForward, exactInput) {
1973
+ function setHandle(handleNumber, to, lookBackward, lookForward, exactInput, smoothSteps) {
1909
1974
  if (!exactInput) {
1910
- to = checkHandlePosition(scope_Locations, handleNumber, to, lookBackward, lookForward, false);
1975
+ to = checkHandlePosition(scope_Locations, handleNumber, to, lookBackward, lookForward, false, smoothSteps);
1911
1976
  }
1912
1977
  if (to === false) {
1913
1978
  return false;
@@ -1921,13 +1986,20 @@
1921
1986
  if (!scope_Connects[index]) {
1922
1987
  return;
1923
1988
  }
1989
+ // Create a copy of locations, so we can sort them for the local scope logic
1990
+ var locations = scope_Locations.slice();
1991
+ if (scope_ConnectsInverted) {
1992
+ locations.sort(function (a, b) {
1993
+ return a - b;
1994
+ });
1995
+ }
1924
1996
  var l = 0;
1925
1997
  var h = 100;
1926
1998
  if (index !== 0) {
1927
- l = scope_Locations[index - 1];
1999
+ l = locations[index - 1];
1928
2000
  }
1929
2001
  if (index !== scope_Connects.length - 1) {
1930
- h = scope_Locations[index];
2002
+ h = locations[index];
1931
2003
  }
1932
2004
  // We use two rules:
1933
2005
  // 'translate' to change the left/top offset;
@@ -2119,6 +2191,7 @@
2119
2191
  "format",
2120
2192
  "pips",
2121
2193
  "tooltips",
2194
+ "connect",
2122
2195
  ];
2123
2196
  // Only change options that we're actually passed to update.
2124
2197
  updateAble.forEach(function (name) {
@@ -2156,6 +2229,32 @@
2156
2229
  // Invalidate the current positioning so valueSet forces an update.
2157
2230
  scope_Locations = [];
2158
2231
  valueSet(isSet(optionsToUpdate.start) ? optionsToUpdate.start : v, fireSetEvent);
2232
+ // Update connects only if it was set
2233
+ if (optionsToUpdate.connect) {
2234
+ updateConnectOption();
2235
+ }
2236
+ }
2237
+ function updateConnectOption() {
2238
+ // IE supported way of removing children including event handlers
2239
+ while (scope_ConnectBase.firstChild) {
2240
+ scope_ConnectBase.removeChild(scope_ConnectBase.firstChild);
2241
+ }
2242
+ // Adding new connects according to the new connect options
2243
+ for (var i = 0; i <= options.handles; i++) {
2244
+ scope_Connects[i] = addConnect(scope_ConnectBase, options.connect[i]);
2245
+ updateConnect(i);
2246
+ }
2247
+ // re-adding drag events for the new connect elements
2248
+ // to ignore the other events we have to negate the 'if (!behaviour.fixed)' check
2249
+ bindSliderEvents({ drag: options.events.drag, fixed: true });
2250
+ }
2251
+ // Invert options for connect handles
2252
+ function invertConnects() {
2253
+ scope_ConnectsInverted = !scope_ConnectsInverted;
2254
+ testConnect(options,
2255
+ // inverse the connect boolean array
2256
+ options.connect.map(function (b) { return !b; }));
2257
+ updateConnectOption();
2159
2258
  }
2160
2259
  // Initialization steps
2161
2260
  function setupSlider() {
@@ -2185,6 +2284,8 @@
2185
2284
  set: valueSet,
2186
2285
  setHandle: valueSetHandle,
2187
2286
  reset: valueReset,
2287
+ disable: disable,
2288
+ enable: enable,
2188
2289
  // Exposed for unit testing, don't use this in your application.
2189
2290
  __moveHandles: function (upward, proposal, handleNumbers) {
2190
2291
  moveHandles(upward, proposal, scope_Locations, handleNumbers);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pageboard/html",
3
- "version": "0.10.23",
3
+ "version": "0.10.25",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "repository": {
package/ui/consent.css CHANGED
@@ -14,7 +14,18 @@ footer [block-type="consent_form"][data-transient="true"] {
14
14
  display:none;
15
15
  }
16
16
 
17
- [contenteditable] [block-type="consent_form"][data-transient="true"],
18
- [block-type="consent_form"][data-transient="true"] > template {
17
+ [block-type="consent_form"] > [block-content="content"] {
18
+ display:none;
19
+ }
20
+ [block-type="consent_form"] > .view {
21
+ position:relative;
22
+ }
23
+ [contenteditable] [block-type="consent_form"] > [block-content="content"] {
19
24
  display:block;
25
+ min-height:1em;
26
+ }
27
+
28
+ [contenteditable] [block-focused="last"] > .form[block-type="consent_form"][data-transient="true"],
29
+ .form[block-type="consent_form"][data-transient="true"][block-focused] {
30
+ display: block;
20
31
  }
package/ui/consent.js CHANGED
@@ -7,51 +7,47 @@ class HTMLCustomConsentElement extends HTMLFormElement {
7
7
  dataTransient: false
8
8
  };
9
9
 
10
- static ask() {
11
- this.waiting = false;
10
+ static explicit;
11
+
12
+ static ask(consent) {
12
13
  let tacit = true;
13
- for (const node of document.querySelectorAll('[block-type="consent_form"]')) {
14
+ const forms = document.querySelectorAll('[block-type="consent_form"]');
15
+ this.explicit = forms.length > 0;
16
+ for (const node of forms) {
14
17
  node.classList.add('visible');
15
- tacit = false;
18
+ tacit = consent && !node.querySelector(`[name="${consent}"]`) || false;
16
19
  }
17
- return !tacit;
20
+ return tacit ? "yes" : null;
18
21
  }
19
22
  setup(state) {
20
23
  if (this.isContentEditable) return;
21
- if (this.options.transient) {
22
- const tmpl = this.ownTpl.prerender();
23
- if (tmpl.content && tmpl.children.length == 0) {
24
- tmpl.appendChild(tmpl.content);
25
- }
26
- }
27
- state.consent(this);
24
+ const view = this.ownView;
25
+ view.textContent = '';
26
+ const tmpl = this.ownTpl.prerender();
27
+ view.appendChild(tmpl.content.cloneNode(true));
28
+ state.chain('consent', this);
28
29
  }
29
30
  chainConsent(state) {
30
- window.HTMLCustomFormElement.prototype.fill.call(this, {
31
- consent: state.scope.$consent
32
- });
31
+ window.HTMLCustomFormElement.prototype.fill.call(this, state.scope.storage.all());
33
32
  if (this.options.transient) this.classList.remove('visible');
34
33
  }
34
+ handleChange(e, state) {
35
+ if (e.type == "submit" || !this.elements.find(item => item.type == "submit")) {
36
+ this.handleSubmit(e, state);
37
+ }
38
+ }
35
39
  handleSubmit(e, state) {
36
40
  if (e.type == "submit") e.preventDefault();
37
41
  if (this.isContentEditable) return;
38
- const fd = window.HTMLCustomFormElement.prototype.read.call(this);
39
- const consent = fd.consent;
40
- if (consent == null) {
41
- return;
42
+ const consents = window.HTMLCustomFormElement.prototype.read.call(this);
43
+ for (const [key, val] of Object.entries(consents)) {
44
+ Page.storage.set(key, val);
42
45
  }
43
- Page.storage.set('consent', consent);
44
- state.scope.$consent = consent;
45
46
  state.runChain('consent');
46
47
  }
47
- handleChange(e, state) {
48
- this.handleSubmit(e, state);
49
- }
50
48
  patch(state) {
51
49
  if (this.isContentEditable) return;
52
- if (this.options.transient) {
53
- this.ownTpl.prerender();
54
- }
50
+ this.ownTpl.prerender();
55
51
  }
56
52
  get ownTpl() {
57
53
  return this.children.find(
@@ -63,43 +59,27 @@ class HTMLCustomConsentElement extends HTMLFormElement {
63
59
  }
64
60
  }
65
61
 
66
- Page.ready(() => {
67
- VirtualHTMLElement.define(`element-consent`, HTMLCustomConsentElement, 'form');
68
- });
69
-
70
- Page.State.prototype.consent = function (fn) {
71
- const initial = this.scope.$consent === undefined;
72
- let consent = Page.storage.get('consent');
73
- if (consent == null && initial) consent = undefined;
74
- this.scope.$consent = consent;
75
- this.chain('consent', fn);
76
- if (consent === undefined) {
77
- HTMLCustomConsentElement.waiting = true;
78
- } else if (consent === null) {
79
- // setup finished but no consent is done yet, ask consent
80
- this.reconsent();
81
- }
82
- };
83
-
84
- Page.State.prototype.reconsent = function (fn) {
85
- if (fn) this.consent(fn);
86
- const consent = this.scope.$consent;
87
- let asking = false;
88
- if (consent != "yes") {
89
- asking = HTMLCustomConsentElement.ask();
62
+ Page.State.prototype.consent = function (listener, ask) {
63
+ const { consent } = listener.constructor;
64
+ if (!consent) {
65
+ console.warn("Expected a static consent field", listener);
66
+ return;
90
67
  }
91
- if (!asking) {
92
- if (consent == null) this.scope.$consent = "yes";
68
+ const cur = Page.storage.get(consent);
69
+ if (cur == null || ask) {
70
+ Page.storage.set(consent, HTMLCustomConsentElement.ask(consent));
93
71
  }
94
- return asking;
72
+ this.chain('consent', listener);
95
73
  };
96
74
 
97
- Page.paint((state) => {
75
+ Page.ready(() => {
76
+ VirtualHTMLElement.define(`element-consent`, HTMLCustomConsentElement, 'form');
77
+ });
78
+
79
+ Page.paint(state => {
98
80
  state.finish(() => {
99
- let run = true;
100
- if (HTMLCustomConsentElement.waiting) {
101
- if (state.reconsent()) run = false;
81
+ if (!HTMLCustomConsentElement.explicit) {
82
+ state.runChain('consent');
102
83
  }
103
- if (run) state.runChain('consent');
104
84
  });
105
85
  });
package/ui/embed.js CHANGED
@@ -1,4 +1,5 @@
1
1
  class HTMLElementEmbed extends VirtualHTMLElement {
2
+ static consent = "consent.embed";
2
3
  static defaults = {
3
4
  src: null,
4
5
  hash: null
@@ -18,7 +19,7 @@ class HTMLElementEmbed extends VirtualHTMLElement {
18
19
  return this.promise;
19
20
  }
20
21
  consent(state) {
21
- const consent = state.scope.$consent;
22
+ const consent = Page.storage.get(this.constructor.consent);
22
23
  this.classList.toggle('denied', consent == "no");
23
24
  this.classList.toggle('waiting', consent == null);
24
25
 
@@ -56,7 +57,7 @@ class HTMLElementEmbed extends VirtualHTMLElement {
56
57
  }
57
58
  }
58
59
  captureClick(e, state) {
59
- if (this.matches('.denied')) state.reconsent();
60
+ if (this.matches('.denied')) state.consent(this, true);
60
61
  }
61
62
  captureLoad() {
62
63
  this.promise.done();
package/ui/storage.js CHANGED
@@ -1,43 +1,28 @@
1
1
  class UserStore {
2
+ #store = window.localStorage ?? {};
3
+ all() {
4
+ return this.#store;
5
+ }
2
6
  get(key) {
3
- let storage = window.localStorage;
4
- let val;
5
- if (storage) {
6
- try {
7
- val = storage.getItem(key);
8
- } catch(ex) {
9
- storage = null;
10
- }
11
- }
12
- if (!storage) {
13
- val = this.getCookies()[key];
7
+ try {
8
+ return this.#store.getItem(key);
9
+ } catch (ex) {
10
+ console.error(ex);
14
11
  }
15
- return val;
16
12
  }
17
13
  set(key, val) {
18
- let storage = window.localStorage;
19
- if (storage) {
20
- try {
21
- storage.setItem(key, val);
22
- } catch(ex) {
23
- storage = null;
24
- }
25
- }
26
- if (!storage) {
27
- this.setCookie(key, val);
14
+ try {
15
+ if (val == null) return this.del(key);
16
+ else return this.#store.setItem(key, val);
17
+ } catch (ex) {
18
+ console.error(ex);
28
19
  }
29
20
  }
30
21
  del(key) {
31
- let storage = window.localStorage;
32
- if (storage) {
33
- try {
34
- storage.removeItem(key);
35
- } catch(ex) {
36
- storage = null;
37
- }
38
- }
39
- if (!storage) {
40
- this.clearCookie(key);
22
+ try {
23
+ return this.#store.removeItem(key);
24
+ } catch (ex) {
25
+ console.error(ex);
41
26
  }
42
27
  }
43
28
  clearCookies(re) {
@@ -68,5 +53,5 @@ class UserStore {
68
53
  }
69
54
  }
70
55
 
71
- Page.setup(() => Page.storage = new UserStore());
56
+ Page.paint(() => Page.storage = new UserStore());
72
57