dbm 1.1.22 → 1.2.0

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/dbm.js CHANGED
@@ -1,16 +1,19 @@
1
1
  import {GlobalObject} from "./core/index.js";
2
2
 
3
- if(!globalThis.dbm) {
4
- globalThis.dbm = new GlobalObject();
3
+ export const setupGlobalInstance = function(aObject, aPath) {
4
+ if(!globalThis.dbm) {
5
+ globalThis.dbm = new GlobalObject();
6
+ }
5
7
  }
6
8
 
7
- export let getInstance = function() {
9
+
10
+ export const getInstance = function() {
8
11
  return globalThis.dbm;
9
12
  }
10
13
 
11
14
  //export {getInstance};
12
15
 
13
- export let objectPath = function(aObject, aPath) {
16
+ export const objectPath = function(aObject, aPath) {
14
17
  //console.log("objectPath");
15
18
 
16
19
  let currentObject = aObject;
@@ -57,7 +60,7 @@ export let objectPath = function(aObject, aPath) {
57
60
  return currentObject;
58
61
  }
59
62
 
60
- export let setAtObjectPath = function(aObject, aPath, aValue) {
63
+ export const setAtObjectPath = function(aObject, aPath, aValue) {
61
64
  aPath += "";
62
65
  if(aPath.length === 0) {
63
66
  return 0;
@@ -30,12 +30,10 @@ export default class ElementPosition extends Dbm.flow.FlowUpdateFunction {
30
30
  }
31
31
 
32
32
  _update() {
33
- console.log("_update");
33
+ //console.log("_update");
34
34
 
35
35
  let element = this.input.element;
36
36
 
37
- console.log(element, this.input.prepareX, this.input.prepareY);
38
-
39
37
  if(element) {
40
38
 
41
39
  //this.output.width = element.clientWidth;
@@ -85,7 +83,7 @@ export default class ElementPosition extends Dbm.flow.FlowUpdateFunction {
85
83
  }
86
84
 
87
85
  _callback_scroll(aEvent) {
88
- console.log("_callback_scroll");
86
+ //console.log("_callback_scroll");
89
87
 
90
88
  let element = this.input.element;
91
89
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbm",
3
- "version": "1.1.22",
3
+ "version": "1.2.0",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {},
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ import Dbm from "../../../index.js";
3
+
4
+ export default class AnchorPosition extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+ }
8
+
9
+ _renderMainElement() {
10
+ return React.createElement("div", {"id": this.context.blockData.linkName});
11
+ }
12
+ }
@@ -1,2 +1,3 @@
1
1
  export {default as Card} from "./Card.js";
2
- export {default as ContentBlock} from "./ContentBlock.js";
2
+ export {default as ContentBlock} from "./ContentBlock.js";
3
+ export {default as AnchorPosition} from "./AnchorPosition.js";
@@ -215,6 +215,15 @@ export let registerAllBlocks = function() {
215
215
  registerBlock("content/contentBlock", "Content block", createElement(Dbm.react.blocks.content.ContentBlock, {}), editor, {}, {});
216
216
  }
217
217
 
218
+ {
219
+ let editor = createElement(Dbm.react.admin.editor.EditorBlockName, {},
220
+ createElement(Dbm.react.form.LabelledArea, {label: "Link name"},
221
+ createElement(Dbm.react.admin.editor.fields.TextField, {name: "linkName"})
222
+ )
223
+ );
224
+ registerBlock("content/anchorPosition", "Anchor position", createElement(Dbm.react.blocks.content.AnchorPosition, {}), editor, {}, {});
225
+ }
226
+
218
227
  {
219
228
  let editor = createElement(Dbm.react.admin.editor.EditorBlockName, {},
220
229
  createElement(Dbm.react.form.LabelledArea, {label: "Initial sections"},
@@ -0,0 +1,188 @@
1
+ import React from "react";
2
+ import Dbm from "../../index.js";
3
+ import Cookies from "js-cookie";
4
+
5
+ export default class CookieOverlayMessage extends Dbm.react.BaseObject {
6
+ _construct() {
7
+ super._construct();
8
+
9
+ let openProperty = this.getDynamicProp("open", false);
10
+ this.item.requireProperty("envelope", 0);
11
+
12
+ let stateToEnvelope = Dbm.flow.updatefunctions.logic.switchValue(openProperty).setDefaultValue(100).addCase(true, 0);
13
+ let inDomCase = Dbm.flow.updatefunctions.logic.switchValue(this.item.properties.envelope).setDefaultValue(true).addCase(100, false);
14
+
15
+ this.item.requireProperty("inDom", false).connectInput(inDomCase.output.properties.value);
16
+
17
+ let animation = new Dbm.flow.animateValue(stateToEnvelope.output.properties.value);
18
+
19
+ this.item.properties.envelope.connectInput(animation.properties.output);
20
+
21
+ let transform = new Dbm.flow.updatefunctions.dom.TransformStyle();
22
+ transform.translateY(animation.properties.output, "%");
23
+
24
+ let style = new Dbm.flow.updatefunctions.dom.StyleObject();
25
+ style.addProperty("transform", transform.output.properties.value);
26
+ this.item.requireProperty("style", null).connectInput(style.output.properties.style);
27
+
28
+ let shouldShow = Cookies.get("cookie/hideCookieBar") !== "1";
29
+
30
+ this.getDynamicProp("open").getMostUpstreamProperty().setValue(shouldShow);
31
+
32
+ this.item.setValue("widthElement", null);
33
+
34
+ let elementSize = new Dbm.flow.updatefunctions.dom.ElementSize();
35
+ this.item.setValue("elementSize", elementSize);
36
+
37
+ elementSize.input.properties.element.connectInput(this.item.properties.widthElement);
38
+ elementSize.start();
39
+
40
+ let layoutSwitch = new Dbm.flow.updatefunctions.logic.RangeSwitch();
41
+ layoutSwitch.input.properties.value.connectInput(elementSize.output.properties.width);
42
+
43
+ layoutSwitch.input.defaultValue = React.createElement("div", {},
44
+ React.createElement("div", {className: "cookie-bar cookie-bar-padding all-pointer-events"},
45
+
46
+ React.createElement("div", {},
47
+ React.createElement("div", {"className": "cookie-bar-title"},
48
+ "Your privacy is important to us"
49
+ ),
50
+ React.createElement("div", {"className": "cookie-bar-description"},
51
+ "We use cookies to make our site work properly and to improve your experience. You can choose to accept all cookies, allow only those that are necessary, or manage your preferences in the settings."
52
+ )
53
+ ),
54
+ React.createElement("div", {"className": "spacing small"}),
55
+ React.createElement("div", {"className": "standard-button standard-button-padding big text-align-center", onClick: () => this._acceptAll()}, "Allow all"),
56
+ React.createElement("div", {"className": "spacing small"}),
57
+ React.createElement("div", {"className": "secondary-button standard-button-padding text-align-center", onClick: () => this._rejectAll()}, "Only necessary"),
58
+ React.createElement("div", {"className": "spacing small"}),
59
+ React.createElement("div", {"className": "cookie-overlay-message-divider"}),
60
+ React.createElement("div", {"className": "spacing small"}),
61
+ React.createElement("div", {"className": "text-align-center"},
62
+ "Take full control over how we use cookies:"
63
+ ),
64
+ React.createElement("div", {"className": "spacing small"}),
65
+ React.createElement("a", {"href": "/cookie-settings/", className:"custom-styled-link"},
66
+ React.createElement("div", {"className": "secondary-button standard-button-padding text-align-center"}, "Settings")
67
+ )
68
+
69
+ )
70
+ );
71
+
72
+ let desktopLayout = React.createElement("div", {className: "centered-site"},
73
+ React.createElement("div", {className: "cookie-overlay-message-box cookie-overlay-message-box-padding all-pointer-events"},
74
+ React.createElement("div", {"className": "flex-row small-item-spacing"},
75
+ React.createElement("div", {"className": "flex-row-item half"},
76
+ React.createElement("div", {"className": "cookie-bar-title"},
77
+ "Your privacy is important to us"
78
+ ),
79
+ React.createElement("div", {"className": "cookie-bar-description"},
80
+ "We use cookies to make our site work properly and to improve your experience. You can choose to accept all cookies, allow only those that are necessary, or manage your preferences in the settings."
81
+ )
82
+ ),
83
+ React.createElement("div", {"className": "flex-row-item quarter"}),
84
+ React.createElement("div", {"className": "flex-row-item quarter"},
85
+ React.createElement("div", {"className": "standard-button standard-button-padding big full-width text-align-center", onClick: () => this._acceptAll()}, "Allow all"),
86
+ React.createElement("div", {"className": "spacing medium"}),
87
+ React.createElement("div", {"className": "secondary-button standard-button-padding full-width text-align-center", onClick: () => this._rejectAll()}, "Only necessary")
88
+
89
+ )
90
+ ),
91
+ React.createElement("div", {"className": "spacing standard"}),
92
+ React.createElement("div", {"className": "cookie-overlay-message-divider"}),
93
+ React.createElement("div", {"className": "spacing standard"}),
94
+ React.createElement("div", {"className": "flex-row small-item-spacing justify-between"},
95
+ React.createElement("div", {"className": "flex-row-item"},
96
+ "Take full control over how we use cookies:"
97
+ ),
98
+ React.createElement("div", {"className": "flex-row-item"},
99
+ React.createElement("a", {"href": "/cookie-settings/", className:"custom-styled-link"},
100
+ React.createElement("div", {"className": "cookie-settings-link"}, "Settings >")
101
+ )
102
+ ),
103
+ )
104
+ ),
105
+ React.createElement("div", {"className": "spacing double"}),
106
+ React.createElement("div", {"className": "spacing double"}),
107
+ );
108
+
109
+ layoutSwitch.addValueForRange(desktopLayout, 700);
110
+
111
+ this.item.setValue("element", null);
112
+ this.item.properties.element.connectInput(layoutSwitch.output.properties.value);
113
+ }
114
+
115
+ _getDomain() {
116
+
117
+ let parts = document.location.hostname.split('.');
118
+
119
+ let length = parts.length;
120
+ if (length === 1) {
121
+ return parts[0];
122
+ }
123
+ else if(parts[length-2] === "co" && parts[length-1] === "uk") {
124
+ return '.' + parts.slice(-3).join('.');
125
+ }
126
+
127
+ return '.' + parts.slice(-2).join('.');
128
+ }
129
+
130
+ _acceptAll() {
131
+ console.log("_acceptAll");
132
+
133
+ let options = {"expires": 365, "domain": this._getDomain()};
134
+
135
+ Cookies.set("cookie/allowPreferences", "1", options);
136
+ Cookies.set("cookie/allowStatistics", "1", options);
137
+ Cookies.set("cookie/allowMarketing", "1", options);
138
+ Cookies.set("cookie/hideCookieBar", "1", options);
139
+
140
+ let consentTime = (new Date()).toISOString();
141
+
142
+ Cookies.set("cookie/consentTime", consentTime, options);
143
+
144
+ Dbm.getInstance().repository.getItem("trackingController").allowStatistics = true;
145
+ Dbm.getInstance().repository.getItem("trackingController").allowMarketing = true;
146
+
147
+ Dbm.getInstance().repository.getItem("userSettings").setValue("hideCookieBar", true);
148
+
149
+ this.getDynamicProp("open").getMostUpstreamProperty().setValue(false);
150
+ }
151
+
152
+ _rejectAll() {
153
+
154
+ let options = {"expires": 365, "domain": this._getDomain()};
155
+
156
+ Cookies.set("cookie/allowPreferences", "0", options);
157
+ Cookies.set("cookie/allowStatistics", "0", options);
158
+ Cookies.set("cookie/allowMarketing", "0", options);
159
+ Cookies.set("cookie/hideCookieBar", "1", options);
160
+
161
+ let consentTime = (new Date()).toISOString();
162
+
163
+ Cookies.set("cookie/consentTime", consentTime, options);
164
+
165
+ Dbm.getInstance().repository.getItem("trackingController").allowStatistics = false;
166
+ Dbm.getInstance().repository.getItem("trackingController").allowMarketing = false;
167
+
168
+ Dbm.getInstance().repository.getItem("userSettings").setValue("hideCookieBar", true);
169
+
170
+ this.getDynamicProp("open").getMostUpstreamProperty().setValue(false);
171
+ }
172
+
173
+ _renderMainElement() {
174
+
175
+ return this._createMainElement("div", {className: "cookie-bar-position no-pointer-events cookie-overlay-message-layer", ref: this.createRef("widthElement")},
176
+ React.createElement(Dbm.react.area.HasData, {"check": this.item.properties.inDom},
177
+ React.createElement("div", {className: "overflow-hidden"},
178
+ React.createElement(Dbm.react.BaseObject, {style: this.item.properties.style},
179
+ React.createElement("div", {},
180
+ React.createElement(Dbm.react.area.InsertElement, {element: this.item.properties.element})
181
+ )
182
+ )
183
+ )
184
+ )
185
+ );
186
+ }
187
+ }
188
+
@@ -1,2 +1,3 @@
1
1
  export {default as CookieSettings} from "./CookieSettings.js";
2
- export {default as CookieBar} from "./CookieBar.js";
2
+ export {default as CookieBar} from "./CookieBar.js";
3
+ export {default as CookieOverlayMessage} from "./CookieOverlayMessage.js";
@@ -0,0 +1,49 @@
1
+ import React from "react";
2
+ import Dbm from "../../index.js";
3
+
4
+ export default class Form extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this._callback_submitBound = this._callback_submit.bind(this);
9
+ }
10
+
11
+ _callback_submit(aEvent) {
12
+ //console.log("_callback_submit");
13
+ //console.log(aEvent);
14
+
15
+ let preventSubmit = this.getPropValue("preventSubmit");
16
+ if(preventSubmit) {
17
+ aEvent.preventDefault();
18
+ }
19
+
20
+ let commands = this.getPropValue("commands");
21
+ if(!commands) {
22
+ commands = this.getPropValue("command");
23
+ }
24
+ if(commands) {
25
+ aEvent.preventDefault();
26
+ commands = Dbm.utils.ArrayFunctions.singleOrArray(commands);
27
+
28
+ let currentArray = commands;
29
+ let currentArrayLength = currentArray.length;
30
+ for(let i = 0; i < currentArrayLength; i++) {
31
+ let command = currentArray[i];
32
+ command.perform(this, aEvent);
33
+ }
34
+ }
35
+ else{
36
+ return !preventSubmit;
37
+ }
38
+
39
+ return false;
40
+ }
41
+
42
+ _renderMainElement() {
43
+
44
+ let children = this.getPropValue("children");
45
+
46
+ return this._createMainElement("form", {onSubmit: this._callback_submitBound}, children);
47
+ }
48
+ }
49
+
@@ -8,4 +8,5 @@ export {default as GraphApiSelectOrCreateObject} from "./GraphApiSelectOrCreateO
8
8
  export {default as GraphApiImage} from "./GraphApiImage.js";
9
9
  export {default as EditArray} from "./EditArray.js";
10
10
  export {default as TextArea} from "./TextArea.js";
11
- export {default as EditObjectProperty} from "./EditObjectProperty.js";
11
+ export {default as EditObjectProperty} from "./EditObjectProperty.js";
12
+ export {default as Form} from "./Form.js";
@@ -10,6 +10,7 @@ export default class CoverScaledImage extends Dbm.react.BaseObject {
10
10
  delete aProps["image"];
11
11
  delete aProps["targetWidth"];
12
12
  delete aProps["targetHeight"];
13
+ delete aProps["skipWindowSize"];
13
14
  }
14
15
 
15
16
  _renderMainElement() {
@@ -17,7 +18,15 @@ export default class CoverScaledImage extends Dbm.react.BaseObject {
17
18
  let image = this.getPropValue("image");
18
19
  let width = this.getPropValue("targetWidth");
19
20
  let height = this.getPropValue("targetHeight");
20
- let url = Dbm.utils.UrlFunctions.createCoverScaledImageUrl(image, width, height);
21
+ let url;
22
+
23
+ if(this.getPropValue("skipWindowSize")) {
24
+ url = Dbm.utils.UrlFunctions.createCoverScaledImageUrlWithPixelDensity(image, width, height, Math.floor(window.devicePixelRatio), 10000);
25
+ }
26
+ else {
27
+ url = Dbm.utils.UrlFunctions.createCoverScaledImageUrl(image, width, height);
28
+ }
29
+
21
30
 
22
31
  let newProps = this._copyProps({src: url});
23
32
 
@@ -29,6 +38,16 @@ export default class CoverScaledImage extends Dbm.react.BaseObject {
29
38
  let elementType = this.getPropValue("elementType");
30
39
  if(elementType) {
31
40
  newProps["elementType"] = elementType;
41
+
42
+ if(elementType === "img" && Dbm.utils.UrlFunctions.imageShouldScale(image)) {
43
+
44
+ let images = [];
45
+ images.push(Dbm.utils.UrlFunctions.createCoverScaledImageUrlWithPixelDensity(image, width, height, 1, 10000) + " 1x");
46
+ images.push(Dbm.utils.UrlFunctions.createCoverScaledImageUrlWithPixelDensity(image, width, height, 2, 10000) + " 2x");
47
+ images.push(Dbm.utils.UrlFunctions.createCoverScaledImageUrlWithPixelDensity(image, width, height, 3, 10000) + " 3x");
48
+
49
+ newProps["srcset"] = images.join(", ");
50
+ }
32
51
  }
33
52
 
34
53
  return React.createElement(Dbm.react.image.Image, newProps, this.getPropValue("children"));
@@ -12,10 +12,23 @@ export default class CommandButton extends Dbm.react.BaseObject {
12
12
  //console.log("_callback_click");
13
13
  //console.log(aEvent);
14
14
 
15
- let command = this.getPropValue("command");
16
-
17
- command.perform(this, aEvent);
15
+ let commands = this.getPropValue("commands");
16
+ if(!commands) {
17
+ commands = this.getPropValue("command");
18
+ }
19
+ if(commands) {
20
+ commands = Dbm.utils.ArrayFunctions.singleOrArray(commands);
18
21
 
22
+ let currentArray = commands;
23
+ let currentArrayLength = currentArray.length;
24
+ for(let i = 0; i < currentArrayLength; i++) {
25
+ let command = currentArray[i];
26
+ command.perform(this, aEvent);
27
+ }
28
+ }
29
+ else{
30
+ console.warn("Button doesn't have any commands", this);
31
+ }
19
32
  }
20
33
 
21
34
  _performClone(aChild, aProps) {
@@ -127,6 +127,11 @@ export default class SiteNavigation extends Dbm.core.BaseObject {
127
127
  if(hardNavigation) {
128
128
  shouldSkip = true;
129
129
  }
130
+
131
+ let target = currentNode.getAttribute("target");
132
+ if(target === "_blank") {
133
+ shouldSkip = true;
134
+ }
130
135
  break;
131
136
  }
132
137
  }
@@ -31,7 +31,7 @@ export let createScaledImageUrlWithPixelDensity = function(aImageData, aWantedWi
31
31
  }
32
32
 
33
33
  export let createScaledImageUrl = function(aImageData, aWantedWidth) {
34
- return createScaledImageUrlWithPixelDensity(aImageData, aWantedWidth, window.devicePixelRatio, window.innerWidth);
34
+ return createScaledImageUrlWithPixelDensity(aImageData, aWantedWidth, Math.floor(window.devicePixelRatio), window.innerWidth);
35
35
  }
36
36
 
37
37
  export let getCoverScaledImageUrlWithPixelDensity = function(aUrl, aWantedWidth, aWantedHeight, aPixelDensity, aMaxSize) {
@@ -56,7 +56,24 @@ export let getCoverScaledImageUrlWithPixelDensity = function(aUrl, aWantedWidth,
56
56
  }
57
57
 
58
58
  export const getCoverScaledImageUrl = function(aUrl, aWantedWidth, aWantedHeight) {
59
- return getCoverScaledImageUrlWithPixelDensity(aUrl, aWantedWidth, aWantedHeight, window.devicePixelRatio, window.innerWidth);
59
+ return getCoverScaledImageUrlWithPixelDensity(aUrl, aWantedWidth, aWantedHeight, Math.floor(window.devicePixelRatio), window.innerWidth);
60
+ }
61
+
62
+ export const imageShouldScale = function(aImageData) {
63
+ if(!aImageData || !aImageData["url"]) {
64
+ return false;
65
+ }
66
+
67
+ let url = aImageData["url"];
68
+ if(url.substring(url.length-4).toLowerCase() === ".svg") {
69
+ return false;
70
+ }
71
+
72
+ if(!aImageData["resizeUrl"]) {
73
+ return false;
74
+ }
75
+
76
+ return true;
60
77
  }
61
78
 
62
79
  export let createCoverScaledImageUrlWithPixelDensity = function(aImageData, aWantedWidth, aWantedHeight, aPixelDensity, aMaxSize) {
@@ -70,14 +87,14 @@ export let createCoverScaledImageUrlWithPixelDensity = function(aImageData, aWan
70
87
  }
71
88
 
72
89
  if(aImageData["resizeUrl"]) {
73
- url = getCoverScaledImageUrl(aImageData["resizeUrl"], aWantedWidth, aWantedHeight);
90
+ url = getCoverScaledImageUrlWithPixelDensity(aImageData["resizeUrl"], aWantedWidth, aWantedHeight, aPixelDensity, aMaxSize);
74
91
  }
75
92
 
76
93
  return url;
77
94
  }
78
95
 
79
96
  export let createCoverScaledImageUrl = function(aImageData, aWantedWidth, aWantedHeight) {
80
- return createCoverScaledImageUrlWithPixelDensity(aImageData, aWantedWidth, aWantedHeight, window.devicePixelRatio, window.innerWidth);
97
+ return createCoverScaledImageUrlWithPixelDensity(aImageData, aWantedWidth, aWantedHeight, Math.floor(window.devicePixelRatio), window.innerWidth);
81
98
  }
82
99
 
83
100
  export const getContainScaledImageUrlWithPixelDensity = function(aUrl, aWantedWidth, aWantedHeight, aPixelDensity, aMaxSize) {
@@ -102,7 +119,7 @@ export const getContainScaledImageUrlWithPixelDensity = function(aUrl, aWantedWi
102
119
  }
103
120
 
104
121
  export const getContainScaledImageUrl = function(aUrl, aWantedWidth, aWantedHeight) {
105
- return getContainScaledImageUrlWithPixelDensity(aUrl, aWantedWidth, aWantedHeight, window.devicePixelRatio, window.innerWidth);
122
+ return getContainScaledImageUrlWithPixelDensity(aUrl, aWantedWidth, aWantedHeight, Math.floor(window.devicePixelRatio), window.innerWidth);
106
123
  }
107
124
 
108
125
  export let createContainScaledImageUrl = function(aImageData, aWantedWidth, aWantedHeight) {