@pageboard/html 0.12.32 → 0.12.33

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.
package/lib/nouislider.js CHANGED
@@ -713,6 +713,7 @@
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;
717
718
  var smoothSteps = entry.indexOf("smooth-steps") >= 0;
718
719
  if (fixed) {
@@ -722,6 +723,9 @@
722
723
  // Use margin to enforce fixed state
723
724
  testMargin(parsed, parsed.start[1] - parsed.start[0]);
724
725
  }
726
+ if (invertConnects && parsed.handles !== 2) {
727
+ throw new Error("noUiSlider: 'invert-connects' behaviour must be used with 2 handles");
728
+ }
725
729
  if (unconstrained && (parsed.margin || parsed.limit)) {
726
730
  throw new Error("noUiSlider: 'unconstrained' behaviour cannot be used with margin or limit");
727
731
  }
@@ -734,6 +738,7 @@
734
738
  snap: snap,
735
739
  hover: hover,
736
740
  unconstrained: unconstrained,
741
+ invertConnects: invertConnects,
737
742
  };
738
743
  }
739
744
  function testTooltips(parsed, entry) {
@@ -904,6 +909,7 @@
904
909
  // Slider DOM Nodes
905
910
  var scope_Target = target;
906
911
  var scope_Base;
912
+ var scope_ConnectBase;
907
913
  var scope_Handles;
908
914
  var scope_Connects;
909
915
  var scope_Pips;
@@ -915,6 +921,7 @@
915
921
  var scope_HandleNumbers = [];
916
922
  var scope_ActiveHandlesCount = 0;
917
923
  var scope_Events = {};
924
+ var scope_ConnectsInverted = false;
918
925
  // Document Nodes
919
926
  var scope_Document = target.ownerDocument;
920
927
  var scope_DocumentElement = options.documentElement || scope_Document.documentElement;
@@ -971,17 +978,17 @@
971
978
  }
972
979
  // Add handles to the slider base.
973
980
  function addElements(connectOptions, base) {
974
- var connectBase = addNodeTo(base, options.cssClasses.connects);
981
+ scope_ConnectBase = addNodeTo(base, options.cssClasses.connects);
975
982
  scope_Handles = [];
976
983
  scope_Connects = [];
977
- scope_Connects.push(addConnect(connectBase, connectOptions[0]));
984
+ scope_Connects.push(addConnect(scope_ConnectBase, connectOptions[0]));
978
985
  // [::::O====O====O====]
979
986
  // connectOptions = [0, 1, 1, 1]
980
987
  for (var i = 0; i < options.handles; i++) {
981
988
  // Keep a list of all added handles.
982
989
  scope_Handles.push(addOrigin(base, i));
983
990
  scope_HandleNumbers[i] = i;
984
- scope_Connects.push(addConnect(connectBase, connectOptions[i + 1]));
991
+ scope_Connects.push(addConnect(scope_ConnectBase, connectOptions[i + 1]));
985
992
  }
986
993
  }
987
994
  // Initialize a single slider.
@@ -1930,8 +1937,26 @@
1930
1937
  var translation = transformDirection(to, 0) - scope_DirOffset;
1931
1938
  var translateRule = "translate(" + inRuleOrder(translation + "%", "0") + ")";
1932
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
+ }
1933
1953
  updateConnect(handleNumber);
1934
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
+ }
1935
1960
  }
1936
1961
  // Handles before the slider middle are stacked later = higher,
1937
1962
  // Handles after the middle later is lower
@@ -1961,13 +1986,20 @@
1961
1986
  if (!scope_Connects[index]) {
1962
1987
  return;
1963
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
+ }
1964
1996
  var l = 0;
1965
1997
  var h = 100;
1966
1998
  if (index !== 0) {
1967
- l = scope_Locations[index - 1];
1999
+ l = locations[index - 1];
1968
2000
  }
1969
2001
  if (index !== scope_Connects.length - 1) {
1970
- h = scope_Locations[index];
2002
+ h = locations[index];
1971
2003
  }
1972
2004
  // We use two rules:
1973
2005
  // 'translate' to change the left/top offset;
@@ -2159,6 +2191,7 @@
2159
2191
  "format",
2160
2192
  "pips",
2161
2193
  "tooltips",
2194
+ "connect",
2162
2195
  ];
2163
2196
  // Only change options that we're actually passed to update.
2164
2197
  updateAble.forEach(function (name) {
@@ -2196,6 +2229,32 @@
2196
2229
  // Invalidate the current positioning so valueSet forces an update.
2197
2230
  scope_Locations = [];
2198
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();
2199
2258
  }
2200
2259
  // Initialization steps
2201
2260
  function setupSlider() {
@@ -2,6 +2,10 @@ this.window = this.window || {};
2
2
  this.window.objectFitImages = (function () {
3
3
  'use strict';
4
4
 
5
+ function getDefaultExportFromCjs (x) {
6
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
7
+ }
8
+
5
9
  /*! npm.im/object-fit-images 3.2.4 */
6
10
 
7
11
  var OFI = 'bfred-it:object-fit-images';
@@ -233,6 +237,8 @@ this.window.objectFitImages = (function () {
233
237
 
234
238
  var ofi_commonJs = fix;
235
239
 
236
- return ofi_commonJs;
240
+ var ofi_commonJs$1 = /*@__PURE__*/getDefaultExportFromCjs(ofi_commonJs);
241
+
242
+ return ofi_commonJs$1;
237
243
 
238
244
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pageboard/html",
3
- "version": "0.12.32",
3
+ "version": "0.12.33",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "repository": {
package/ui/consent.js CHANGED
@@ -3,51 +3,62 @@ class HTMLElementConsent extends Page.create(HTMLFormElement) {
3
3
  dataTransient: false
4
4
  };
5
5
 
6
- static ask() {
7
- this.waiting = false;
6
+ static explicits = new Set();
7
+
8
+ static ask(state, consent) {
8
9
  let tacit = true;
9
- for (const node of document.querySelectorAll('[block-type="consent_form"]')) {
10
+ const forms = document.querySelectorAll('[block-type="consent_form"]');
11
+ const consents = state.scope.storage.all();
12
+ for (const node of forms) {
13
+ window.HTMLElementForm.prototype.fill.call(node, consents);
10
14
  node.classList.add('visible');
11
- tacit = false;
15
+ tacit = consent && !node.querySelector(`[name="${consent}"]`) || false;
12
16
  }
13
- return !tacit;
17
+ if (!tacit) this.explicits.add(consent);
18
+ return tacit ? "yes" : null;
14
19
  }
15
20
  setup(state) {
16
21
  if (state.scope.$write) return;
22
+ this.constructor.explicits = new Set();
23
+ const view = this.ownView;
24
+ view.textContent = '';
25
+ const tmpl = this.ownTpl.prerender();
26
+ view.appendChild(tmpl.content.cloneNode(true));
27
+ state.chain('consent', this);
28
+ }
29
+ chainConsent(state) {
17
30
  if (this.options.transient) {
18
- const tmpl = this.ownTpl.prerender();
19
- if (tmpl.content && tmpl.children.length == 0) {
20
- tmpl.appendChild(tmpl.content);
21
- }
31
+ this.classList.remove('visible');
32
+ } else {
33
+ window.HTMLElementForm.prototype.fill.call(this, state.scope.storage.all());
22
34
  }
23
- state.consent(this);
24
35
  }
25
- chainConsent(state) {
26
- window.HTMLElementForm.prototype.fill.call(this, {
27
- consent: state.scope.$consent
28
- });
29
- if (this.options.transient) this.classList.remove('visible');
36
+ handleChange(e, state) {
37
+ if (e.type == "submit" || !this.elements.find(item => item.type == "submit")) {
38
+ this.handleSubmit(e, state);
39
+ }
30
40
  }
31
41
  handleSubmit(e, state) {
32
42
  if (e.type == "submit") e.preventDefault();
33
43
  if (state.scope.$write) return;
34
- const fd = window.HTMLElementForm.prototype.read.call(this);
35
- const consent = fd.consent;
36
- if (consent == null) {
44
+ const consents = window.HTMLElementForm.prototype.read.call(this);
45
+ const list = Array.from(this.constructor.explicits);
46
+ const def = consents.consent;
47
+ for (const consent of list) {
48
+ if (def != "custom") consents[consent] = def;
49
+ }
50
+ if (list.some(c => consents[c] == null)) {
51
+ // not all explicit consents have been answered
37
52
  return;
38
53
  }
39
- state.scope.storage.set('consent', consent);
40
- state.scope.$consent = consent;
41
- state.runChain('consent');
42
- }
43
- handleChange(e, state) {
44
- this.handleSubmit(e, state);
54
+ for (const [key, val] of Object.entries(consents)) {
55
+ state.scope.storage.set(key, val);
56
+ }
57
+ state.copy().runChain('consent');
45
58
  }
46
59
  patch(state) {
47
60
  if (state.scope.$write) return;
48
- if (this.options.transient) {
49
- this.ownTpl.prerender();
50
- }
61
+ this.ownTpl.prerender();
51
62
  }
52
63
  get ownTpl() {
53
64
  return this.children.find(
@@ -59,43 +70,42 @@ class HTMLElementConsent extends Page.create(HTMLFormElement) {
59
70
  }
60
71
  }
61
72
 
62
-
63
- Page.define(`element-consent`, HTMLElementConsent, 'form');
64
-
65
-
66
- Page.constructor.prototype.consent = function (fn) {
67
- const initial = this.scope.$consent === undefined;
68
- let consent = this.scope.storage.get('consent');
69
- if (consent == null && initial) consent = undefined;
70
- this.scope.$consent = consent;
71
- this.chain('consent', fn);
72
- if (consent === undefined) {
73
- HTMLElementConsent.waiting = true;
74
- } else if (consent === null) {
75
- // setup finished but no consent is done yet, ask consent
76
- this.reconsent();
73
+ Page.constructor.prototype.consents = function (name, val) {
74
+ const { storage } = this.scope;
75
+ const key = "consent." + name;
76
+ if (val === null) {
77
+ storage.remove(key);
78
+ } else if (val !== undefined) {
79
+ storage.set(key, val ? "yes" : "no");
80
+ } else {
81
+ const str = storage.get(key);
82
+ if (str == "yes") return true;
83
+ else if (str == "no") return false;
84
+ else return null;
77
85
  }
78
86
  };
79
87
 
80
- Page.constructor.prototype.reconsent = function (fn) {
81
- if (fn) this.consent(fn);
82
- const consent = this.scope.$consent;
83
- let asking = false;
84
- if (consent != "yes") {
85
- asking = HTMLElementConsent.ask();
88
+ Page.constructor.prototype.consent = function (listener, ask) {
89
+ const { consent } = listener.constructor;
90
+ if (!consent) {
91
+ console.warn("Expected a static consent field", listener);
92
+ return;
86
93
  }
87
- if (!asking) {
88
- if (consent == null) this.scope.$consent = "yes";
94
+ const cur = this.consents(consent);
95
+ if (cur == null || ask) {
96
+ this.consents(consent, HTMLElementConsent.ask(this, consent));
89
97
  }
90
- return asking;
98
+ this.chain('consent', listener);
91
99
  };
92
100
 
101
+ Page.define(`element-consent`, HTMLElementConsent, 'form');
102
+
103
+
93
104
  Page.paint(state => {
94
105
  state.finish(() => {
95
- let run = true;
96
- if (HTMLElementConsent.waiting) {
97
- if (state.reconsent()) run = false;
106
+ if (!HTMLElementConsent.explicits.size) {
107
+ // last chance for implicit consents
108
+ state.runChain('consent');
98
109
  }
99
- if (run) state.runChain('consent');
100
110
  });
101
111
  });
package/ui/embed.js CHANGED
@@ -1,4 +1,5 @@
1
1
  class HTMLElementEmbed extends Page.Element {
2
+ static consent = "marketing";
2
3
  static defaults = {
3
4
  src: null,
4
5
  query: null,
@@ -21,12 +22,12 @@ class HTMLElementEmbed extends Page.Element {
21
22
  if (width && height) this.style.paddingBottom = `calc(${height} / ${width} * 100%)`;
22
23
  }
23
24
  consent(state) {
24
- const consent = state.scope.$consent;
25
- this.classList.toggle('denied', consent == "no");
26
- this.classList.toggle('waiting', consent == null);
25
+ const consent = state.consents(this.constructor.consent);
26
+ this.classList.toggle('denied', consent === false);
27
+ this.classList.toggle('waiting', consent === null);
27
28
 
28
29
  const iframe = this.querySelector('iframe');
29
- if (consent != "yes") {
30
+ if (consent !== true) {
30
31
  iframe.src = "";
31
32
  return;
32
33
  }
@@ -57,7 +58,9 @@ class HTMLElementEmbed extends Page.Element {
57
58
  }
58
59
  }
59
60
  captureClick(e, state) {
60
- if (this.matches('.denied')) state.reconsent();
61
+ if (this.matches('.denied')) {
62
+ state.consent(this, true);
63
+ }
61
64
  }
62
65
  captureLoad() {
63
66
  this.classList.remove('loading');
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
7
  try {
7
- val = storage.getItem(key);
8
- } catch(ex) {
9
- storage = null;
8
+ return this.#store.getItem(key);
9
+ } catch (ex) {
10
+ console.error(ex);
10
11
  }
11
- }
12
- if (!storage) {
13
- val = this.getCookies()[key];
14
- }
15
- return val;
16
12
  }
17
13
  set(key, val) {
18
- let storage = window.localStorage;
19
- if (storage) {
20
14
  try {
21
- storage.setItem(key, val);
22
- } catch(ex) {
23
- storage = null;
24
- }
25
- }
26
- if (!storage) {
27
- this.setCookie(key, val);
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
22
  try {
34
- storage.removeItem(key);
35
- } catch(ex) {
36
- storage = null;
37
- }
38
- }
39
- if (!storage) {
40
- this.clearCookie(key);
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(state => state.scope.storage = new UserStore());
56
+ Page.paint(state => state.scope.storage = new UserStore());
72
57