dbm 1.0.6 → 1.1.1

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.
Files changed (67) hide show
  1. package/flow/controllers/index.js +1 -0
  2. package/flow/controllers/select/SingleSelection.js +65 -0
  3. package/flow/controllers/select/index.js +1 -0
  4. package/flow/index.js +1 -0
  5. package/flow/updatefunctions/basic/Length.js +20 -0
  6. package/flow/updatefunctions/basic/PropertyOf.js +21 -0
  7. package/flow/updatefunctions/basic/index.js +17 -0
  8. package/flow/updatefunctions/dom/ElementPosition.js +1 -1
  9. package/flow/updatefunctions/dom/HorizontalFlip.js +5 -6
  10. package/flow/updatefunctions/dom/StyleObject.js +1 -1
  11. package/flow/updatefunctions/logic/Condition.js +12 -1
  12. package/flow/updatefunctions/logic/Invert.js +18 -0
  13. package/flow/updatefunctions/logic/Switch.js +6 -0
  14. package/flow/updatefunctions/logic/index.js +8 -0
  15. package/graphapi/webclient/GraphApi.js +4 -0
  16. package/graphapi/webclient/WebSocketConnection.js +23 -8
  17. package/graphapi/webclient/decode/index.js +16 -0
  18. package/package.json +1 -1
  19. package/react/BaseObject.js +18 -7
  20. package/react/ChildFunctions.js +27 -0
  21. package/react/admin/EditPage.js +41 -1
  22. package/react/admin/{Editor.js → editor/Editor.js} +27 -11
  23. package/react/admin/{EditorBlock.js → editor/EditorBlock.js} +15 -4
  24. package/react/admin/editor/EditorBlockFields.js +23 -0
  25. package/react/admin/editor/EditorBlockName.js +28 -0
  26. package/react/admin/editor/fields/CheckboxField.js +54 -0
  27. package/react/admin/editor/fields/ImageField.js +137 -0
  28. package/react/admin/editor/fields/RichTextField.js +75 -0
  29. package/react/admin/editor/fields/TextField.js +53 -0
  30. package/react/admin/editor/fields/index.js +4 -0
  31. package/react/admin/editor/index.js +6 -0
  32. package/react/admin/index.js +3 -4
  33. package/react/animation/AnimatedElement.js +22 -0
  34. package/react/animation/AnimationController.js +53 -0
  35. package/react/animation/index.js +22 -0
  36. package/react/area/HasData.js +5 -0
  37. package/react/area/InsertElement.js +1 -1
  38. package/react/area/List.js +46 -0
  39. package/react/area/OpenCloseExpandableArea.js +14 -5
  40. package/react/area/ResponsiveLayout.js +48 -0
  41. package/react/area/index.js +12 -1
  42. package/react/blocks/Image.js +17 -0
  43. package/react/blocks/index.js +69 -55
  44. package/react/cookies/CookieSettings.js +1 -1
  45. package/react/form/Checkbox.js +2 -1
  46. package/react/form/FileDropArea.js +92 -0
  47. package/react/form/FormField.js +1 -0
  48. package/react/form/LabelledArea.js +22 -0
  49. package/react/form/index.js +3 -1
  50. package/react/image/CoverScaledImage.js +32 -0
  51. package/react/image/Image.js +37 -0
  52. package/react/image/LocalImage.js +42 -0
  53. package/react/image/WidthScaledImage.js +30 -0
  54. package/react/image/index.js +4 -0
  55. package/react/index.js +6 -1
  56. package/react/interaction/CommandButton.js +97 -0
  57. package/react/interaction/index.js +3 -0
  58. package/react/login/LoginForm.js +1 -1
  59. package/react/source/index.js +15 -1
  60. package/react/text/Link.js +18 -0
  61. package/react/text/index.js +1 -0
  62. package/site/SiteDataLoader.js +1 -1
  63. package/tracking/Controller.js +1 -1
  64. package/utils/ArrayFunctions.js +128 -2
  65. package/utils/UrlFunctions.js +77 -0
  66. package/utils/index.js +2 -1
  67. package/react/admin/EditorBlockName.js +0 -19
@@ -0,0 +1,97 @@
1
+ import React from "react";
2
+ import Dbm from "../../index.js";
3
+
4
+ export default class CommandButton extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this._callback_clickBound = this._callback_click.bind(this);
9
+ }
10
+
11
+ _callback_click(aEvent) {
12
+ //console.log("_callback_click");
13
+ //console.log(aEvent);
14
+
15
+ let command = this.getPropValue("command");
16
+
17
+ command.perform(this, aEvent);
18
+
19
+ }
20
+
21
+ _performClone(aChild, aProps) {
22
+
23
+ if(aChild instanceof Array) {
24
+ let returnArray = [];
25
+
26
+ let currentArray = aChild;
27
+ let currentArrayLength = currentArray.length;
28
+ for(let i = 0; i < currentArrayLength; i++) {
29
+ let currentChild = currentArray[i];
30
+ returnArray.push(this._performClone(currentChild, aProps));
31
+ }
32
+
33
+ return returnArray;
34
+ }
35
+
36
+ let newProps = aProps;
37
+ /*
38
+ //MENOTE: this is a more generalized version, but we never pass in className in this function
39
+ if(aChild && aChild.props && aChild.props.className) {
40
+ newProps = {...aProps};
41
+
42
+ if(aProps.className) {
43
+ newProps.className = aProps.className + " " + aChild.props.className;
44
+ }
45
+ else {
46
+ newProps.className = aChild.props.className;
47
+ }
48
+ }
49
+ */
50
+
51
+
52
+ let callArray = [aChild, newProps];
53
+
54
+ if(aChild && aChild.props) {
55
+ let firstChildChildren = aChild.props.children;
56
+ if(!firstChildChildren) {
57
+ //MENOTE: do nothing
58
+ }
59
+ else if(firstChildChildren instanceof Array) {
60
+ callArray = callArray.concat(firstChildChildren);
61
+ }
62
+ else {
63
+ callArray.push(firstChildChildren);
64
+ }
65
+ }
66
+
67
+ return React.cloneElement.apply(React, callArray);
68
+ }
69
+
70
+ _renderMainElement() {
71
+
72
+ let children = Dbm.utils.ArrayFunctions.singleOrArray(this.getPropValue("children"));
73
+
74
+ let replacedChildren = [];
75
+
76
+ let currentArray = children;
77
+ let currentArrayLength = currentArray.length;
78
+ for(let i = 0; i < currentArrayLength; i++) {
79
+ let currentChild = currentArray[i];
80
+ if(currentChild) {
81
+ if(typeof(currentChild) === "string") {
82
+ replacedChildren.push(React.createElement("span"), {"onClick": this._callback_clickBound, onKeyDown: function(aEvent) {if(aEvent.key === "Enter") aEvent.target.click()}}, currentChild);
83
+ }
84
+ else {
85
+ replacedChildren.push(this._performClone(currentChild, {"onClick": this._callback_clickBound, onKeyDown: function(aEvent) {if(aEvent.key === "Enter") aEvent.target.click()}}));
86
+ }
87
+ }
88
+ else {
89
+ replacedChildren.push(currentChild);
90
+ }
91
+ }
92
+
93
+
94
+ return React.createElement(React.Fragment, {}, replacedChildren);
95
+ }
96
+ }
97
+
@@ -0,0 +1,3 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export {default as CommandButton} from "./CommandButton.js";
@@ -87,7 +87,7 @@ export default class LoginForm extends Dbm.react.BaseObject {
87
87
 
88
88
  _renderMainElement() {
89
89
 
90
- return this._createMainElement("div", {},
90
+ return this._createMainElement("div", {className: "content-narrow"},
91
91
  React.createElement("div", {className: "body-text"},
92
92
  React.createElement("div", {"className": ""},
93
93
  React.createElement("label", {className: "standard-field-label"},
@@ -1 +1,15 @@
1
- export {default as ContextVariableSource} from "./ContextVariableSource.js";
1
+ import Dbm from "../../index.js";
2
+
3
+ export {default as ContextVariableSource} from "./ContextVariableSource.js";
4
+
5
+ export let contextVariable = function(aPath) {
6
+ let newSource = new Dbm.react.source.ContextVariableSource();
7
+ newSource.item.path = aPath;
8
+
9
+ return newSource;
10
+ }
11
+
12
+ export let blockData = function(aPath) {
13
+ //METODO: check if blockdata is a source
14
+ return contextVariable("blockData." + aPath);
15
+ }
@@ -0,0 +1,18 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class Link extends Dbm.react.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+ }
7
+
8
+ _renderMainElement() {
9
+
10
+ let url = this.getPropValue("href");
11
+ let prefix = this.getPropValue("prefix");
12
+ if(prefix) {
13
+ url = prefix + url;
14
+ }
15
+
16
+ return this._createMainElement("a", {href: url}, this.getPropValue("children"));
17
+ }
18
+ }
@@ -3,6 +3,7 @@ import {createElement} from "react";
3
3
 
4
4
  export {default as Text} from "./Text.js";
5
5
  export {default as HtmlText} from "./HtmlText.js";
6
+ export {default as Link} from "./Link.js";
6
7
 
7
8
  export let text = function(aText) {
8
9
  if(typeof(aText) === "string") {
@@ -16,7 +16,7 @@ export default class SiteDataLoader extends Dbm.core.BaseObject {
16
16
  }
17
17
 
18
18
  _loadUrl() {
19
- console.log("_loadUrl");
19
+ //console.log("_loadUrl");
20
20
 
21
21
  let url = this.item.url;
22
22
  if(url != null) {
@@ -44,7 +44,7 @@ export default class Controller extends Dbm.core.BaseObject {
44
44
  }
45
45
 
46
46
  start() {
47
- console.log("start");
47
+ //console.log("start");
48
48
  this.item.active = true;
49
49
 
50
50
  return this;
@@ -1,9 +1,135 @@
1
- export let range = function(aStartValue, aEndValue, aStep = 1) {
1
+ import Dbm from "../index.js";
2
+
3
+ export const range = function(aStartValue, aEndValue, aStepValue = 1, aIncludeEndValue = true) {
4
+
5
+ let returnArray = new Array();
6
+
7
+ let loopCompare;
8
+
9
+ if(aStepValue > 0) {
10
+ if(aIncludeEndValue) {
11
+ loopCompare = function(aIndex, aLimit) {
12
+ return aIndex <= aLimit;
13
+ };
14
+ }
15
+ else {
16
+ loopCompare = function(aIndex, aLimit) {
17
+ return aIndex < aLimit;
18
+ };
19
+ }
20
+ }
21
+ else {
22
+ if(aIncludeEndValue) {
23
+ loopCompare = function(aIndex, aLimit) {
24
+ return aIndex >= aLimit;
25
+ };
26
+ }
27
+ else {
28
+ loopCompare = function(aIndex, aLimit) {
29
+ return aIndex > aLimit;
30
+ };
31
+ }
32
+ }
33
+
34
+ for(let i = aStartValue; loopCompare(i, aEndValue); i += aStepValue) {
35
+ returnArray.push(i);
36
+ }
37
+
38
+ return returnArray;
39
+ }
40
+
41
+ export const removeDuplicates = function(aArray) {
2
42
  let returnArray = [];
43
+
44
+ let currentArray = aArray;
45
+ let currentArrayLength = currentArray.length;
46
+ for(let i = 0; i < currentArrayLength; i++) {
47
+ let currentValue = currentArray[i];
48
+ if(returnArray.indexOf(currentValue) === -1) {
49
+ returnArray.push(currentValue);
50
+ }
51
+ }
52
+
53
+ return returnArray;
54
+ }
55
+
56
+ export const singleOrArray = function(aData) {
57
+ if(aData === null || aData === undefined) {
58
+ return [];
59
+ }
60
+ else if(aData instanceof Array) {
61
+ return aData;
62
+ }
63
+
64
+ return [aData];
65
+ }
3
66
 
67
+ export const removeValues = function(aArray, aRemoveValues) {
68
+ let returnArray = new Array();
69
+
70
+ let currentArray = aArray;
71
+ let currentArrayLength = currentArray.length;
72
+ for(let i = 0; i < currentArrayLength; i++) {
73
+ let currentValue = currentArray[i];
74
+ if(aRemoveValues.indexOf(currentValue) === -1) {
75
+ returnArray.push(currentValue);
76
+ }
77
+ }
78
+
4
79
  return returnArray;
5
80
  }
6
81
 
7
- export let removeDuplicates = function(aArray) {
82
+ export const trimArray = function(aArray, aMode = 3) {
83
+
84
+ if(aMode > 0) {
85
+ //METODO: use mode
86
+ if(aArray) {
87
+ let currentArray = aArray;
88
+ let currentArrayLength = currentArray.length;
89
+ for(let i = 0; i < currentArrayLength; i++) {
90
+ let currentString = currentArray[i];
91
+
92
+ if(typeof(currentString) === "string") {
93
+ currentArray[i] = currentString.trim();
94
+ }
95
+ }
96
+ }
97
+ }
98
+
8
99
  return aArray;
100
+ }
101
+
102
+ export const arrayOrSeparatedString = function(aData, aSeparator = ",", aTrim = 3) {
103
+ if(aData === null || aData === undefined) {
104
+ return [];
105
+ }
106
+ else if(aData instanceof Array) {
107
+ return aData;
108
+ }
109
+ else if(typeof(aData) === "string") {
110
+ if(aData === "") {
111
+ return [];
112
+ }
113
+ return trimArray(aData.split(aSeparator));
114
+ }
115
+
116
+ console.error(aData + " is not array or string.");
117
+ return [];
118
+ }
119
+
120
+ export const filterByField = function(aArray, aField, aValue) {
121
+ let returnArray = [];
122
+
123
+ let currentArray = aArray;
124
+ let currentArrayLength = currentArray.length;
125
+ for(let i = 0; i < currentArrayLength; i++) {
126
+ let currentItem = aArray[i];
127
+ let currentValue = Dbm.objectPath(aArray[i], aField);
128
+ console.log(currentValue, aValue);
129
+ if(currentValue === aValue) {
130
+ returnArray.push(currentItem);
131
+ }
132
+ }
133
+
134
+ return returnArray;
9
135
  }
@@ -0,0 +1,77 @@
1
+ export let createScaledImageUrl = function(aImageData, aWantedWidth) {
2
+ if(!aImageData || !aImageData["url"]) {
3
+ return null;
4
+ }
5
+
6
+ let url = aImageData["url"];
7
+ if(url.substring(url.length-4).toLowerCase() === ".svg") {
8
+ return url;
9
+ }
10
+
11
+ if(aImageData["resizeUrl"]) {
12
+ let scaleToWidth = Math.min(
13
+ Math.round(window.devicePixelRatio*aWantedWidth),
14
+ Math.max(
15
+ 100,
16
+ 100*Math.round(window.devicePixelRatio*window.innerWidth/100)
17
+ )
18
+ );
19
+ url = aImageData["resizeUrl"].split("{scale}").join("width=" + scaleToWidth);
20
+ }
21
+
22
+ return url;
23
+ }
24
+
25
+ export let createCoverScaledImageUrl = function(aImageData, aWantedWidth, aWantedHeight) {
26
+ if(!aImageData || !aImageData["url"]) {
27
+ return null;
28
+ }
29
+
30
+ let url = aImageData["url"];
31
+ if(url.substring(url.length-4).toLowerCase() === ".svg") {
32
+ return url;
33
+ }
34
+
35
+ if(aImageData["resizeUrl"]) {
36
+ let scaleToWidth = Math.min(
37
+ Math.round(window.devicePixelRatio*aWantedWidth),
38
+ Math.max(
39
+ 100,
40
+ 100*Math.round(window.devicePixelRatio*window.innerWidth/100)
41
+ )
42
+ );
43
+
44
+ let scaleToHeight = Math.round(aWantedHeight*scaleToWidth/aWantedWidth);
45
+
46
+ url = aImageData["resizeUrl"].split("{scale}").join("width=" + scaleToWidth + ",height=" + scaleToHeight + ",fit=cover");
47
+ }
48
+
49
+ return url;
50
+ }
51
+
52
+ export let createContainScaledImageUrl = function(aImageData, aWantedWidth, aWantedHeight) {
53
+ if(!aImageData || !aImageData["url"]) {
54
+ return null;
55
+ }
56
+
57
+ let url = aImageData["url"];
58
+ if(url.substring(url.length-4).toLowerCase() === ".svg") {
59
+ return url;
60
+ }
61
+
62
+ if(aImageData["resizeUrl"]) {
63
+ let scaleToWidth = Math.min(
64
+ Math.round(window.devicePixelRatio*aWantedWidth),
65
+ Math.max(
66
+ 100,
67
+ 100*Math.round(window.devicePixelRatio*window.innerWidth/100)
68
+ )
69
+ );
70
+
71
+ let scaleToHeight = Math.round(aWantedHeight*scaleToWidth/aWantedWidth);
72
+
73
+ url = aImageData["resizeUrl"].split("{scale}").join("width=" + scaleToWidth + ",height=" + scaleToHeight + ",fit=contain");
74
+ }
75
+
76
+ return url;
77
+ }
package/utils/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * as ArrayFunctions from "./ArrayFunctions.js";
2
2
  export * as NumberFunctions from "./NumberFunctions.js";
3
- export * as StringFunctions from "./StringFunctions.js";
3
+ export * as StringFunctions from "./StringFunctions.js";
4
+ export * as UrlFunctions from "./UrlFunctions.js";
@@ -1,19 +0,0 @@
1
- import React from "react";
2
- import Dbm from "../../index.js";
3
-
4
- export default class EditorBlockName extends Dbm.react.BaseObject {
5
- _construct() {
6
- super._construct();
7
- }
8
-
9
- _renderMainElement() {
10
-
11
- let textSource = new Dbm.react.source.ContextVariableSource();
12
- textSource.item.path = "moduleData.editorData.name";
13
-
14
- return React.createElement("div", {"className": "editor-block-box editor-block-box-padding text-align-center"},
15
- Dbm.react.text.text(textSource),
16
- );
17
- }
18
- }
19
-