dbm 1.0.6 → 1.1.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.
Files changed (52) hide show
  1. package/flow/updatefunctions/dom/ElementPosition.js +1 -1
  2. package/flow/updatefunctions/dom/HorizontalFlip.js +5 -6
  3. package/flow/updatefunctions/dom/StyleObject.js +1 -1
  4. package/flow/updatefunctions/logic/Switch.js +6 -0
  5. package/graphapi/webclient/WebSocketConnection.js +13 -8
  6. package/graphapi/webclient/decode/index.js +16 -0
  7. package/package.json +1 -1
  8. package/react/BaseObject.js +18 -7
  9. package/react/ChildFunctions.js +27 -0
  10. package/react/admin/EditPage.js +12 -1
  11. package/react/admin/{Editor.js → editor/Editor.js} +27 -11
  12. package/react/admin/{EditorBlock.js → editor/EditorBlock.js} +15 -4
  13. package/react/admin/editor/EditorBlockFields.js +23 -0
  14. package/react/admin/editor/EditorBlockName.js +28 -0
  15. package/react/admin/editor/fields/CheckboxField.js +54 -0
  16. package/react/admin/editor/fields/ImageField.js +137 -0
  17. package/react/admin/editor/fields/RichTextField.js +75 -0
  18. package/react/admin/editor/fields/TextField.js +53 -0
  19. package/react/admin/editor/fields/index.js +4 -0
  20. package/react/admin/editor/index.js +6 -0
  21. package/react/admin/index.js +3 -4
  22. package/react/animation/AnimatedElement.js +22 -0
  23. package/react/animation/AnimationController.js +53 -0
  24. package/react/animation/index.js +22 -0
  25. package/react/area/HasData.js +5 -0
  26. package/react/area/InsertElement.js +1 -1
  27. package/react/area/List.js +46 -0
  28. package/react/area/OpenCloseExpandableArea.js +5 -3
  29. package/react/area/ResponsiveLayout.js +48 -0
  30. package/react/area/index.js +12 -1
  31. package/react/blocks/Image.js +17 -0
  32. package/react/blocks/index.js +69 -55
  33. package/react/cookies/CookieSettings.js +1 -1
  34. package/react/form/Checkbox.js +2 -1
  35. package/react/form/FormField.js +1 -0
  36. package/react/form/LabelledArea.js +22 -0
  37. package/react/form/index.js +2 -1
  38. package/react/image/CoverScaledImage.js +32 -0
  39. package/react/image/Image.js +37 -0
  40. package/react/image/WidthScaledImage.js +30 -0
  41. package/react/image/index.js +3 -0
  42. package/react/index.js +6 -1
  43. package/react/login/LoginForm.js +1 -1
  44. package/react/source/index.js +15 -1
  45. package/react/text/Link.js +18 -0
  46. package/react/text/index.js +1 -0
  47. package/site/SiteDataLoader.js +1 -1
  48. package/tracking/Controller.js +1 -1
  49. package/utils/ArrayFunctions.js +58 -4
  50. package/utils/UrlFunctions.js +77 -0
  51. package/utils/index.js +2 -1
  52. package/react/admin/EditorBlockName.js +0 -19
@@ -49,7 +49,7 @@ export default class ElementPosition extends Dbm.flow.FlowUpdateFunction {
49
49
  }
50
50
 
51
51
  _callback_scroll(aEvent) {
52
- console.log("_callback_scroll");
52
+ //console.log("_callback_scroll");
53
53
 
54
54
  let element = this.input.element;
55
55
 
@@ -6,11 +6,10 @@ export default class HorizontalFlip extends Dbm.flow.FlowUpdateFunction {
6
6
  super._construct();
7
7
 
8
8
  this.input.register("envelope", 0);
9
- console.log(this.input.properties.envelope);
10
9
  this.input.register("perspective", "3000px");
11
10
 
12
11
  this.output.register("style1", {});
13
- this.output.register("style2", {"opacity": 0, "position": "absolute", "top": 0, "left": 0, "width": "100%", "dispaly": "none"});
12
+ this.output.register("style2", {"opacity": 0, "position": "absolute", "top": 0, "left": 0, "width": "100%", "display": "none"});
14
13
  this.output.register("inDom1", true);
15
14
  this.output.register("inDom2", false);
16
15
  }
@@ -28,12 +27,12 @@ export default class HorizontalFlip extends Dbm.flow.FlowUpdateFunction {
28
27
  this.output.inDom2 = inDom2;
29
28
 
30
29
  if(!inDom1) {
31
- this.output.style1 = {"opacity": 0, "position": "absolute", "top": 0, "left": 0, "width": "100%", "dispaly": "none"};
30
+ this.output.style1 = {"opacity": 0, "position": "absolute", "top": 0, "left": 0, "width": "100%", "display": "none"};
32
31
  this.output.style2 = {};
33
32
  }
34
33
  else if(!inDom2) {
35
34
  this.output.style1 = {};
36
- this.output.style2 = {"opacity": 0, "position": "absolute", "top": 0, "left": 0, "width": "100%", "dispaly": "none"};
35
+ this.output.style2 = {"opacity": 0, "position": "absolute", "top": 0, "left": 0, "width": "100%", "display": "none"};
37
36
  }
38
37
  else {
39
38
  let angle1 = 180*envelope;
@@ -49,7 +48,7 @@ export default class HorizontalFlip extends Dbm.flow.FlowUpdateFunction {
49
48
  styleObject2["position"] = "absolute";
50
49
  styleObject2["top"] = 0;
51
50
  styleObject2["left"] = 0;
52
- styleObject2["width"] = 0;
51
+ styleObject2["width"] = "100%";
53
52
  }
54
53
  else {
55
54
  styleObject1["opacity"] = 0;
@@ -57,7 +56,7 @@ export default class HorizontalFlip extends Dbm.flow.FlowUpdateFunction {
57
56
  styleObject1["position"] = "absolute";
58
57
  styleObject1["top"] = 0;
59
58
  styleObject1["left"] = 0;
60
- styleObject1["width"] = 0;
59
+ styleObject1["width"] = "100%";
61
60
  }
62
61
 
63
62
  this.output.style1 = styleObject1;
@@ -33,7 +33,7 @@ export default class StyleObject extends Dbm.flow.FlowUpdateFunction {
33
33
  let unit = this.input.units[objectName].value;
34
34
 
35
35
  if(unit) {
36
- value += " " + unit;
36
+ value += "" + unit;
37
37
  }
38
38
  styleObject[objectName] = value;
39
39
  }
@@ -12,6 +12,12 @@ export default class Switch extends Dbm.flow.FlowUpdateFunction {
12
12
  this.output.register("value", null);
13
13
  }
14
14
 
15
+ setDefaultValue(aValue) {
16
+ this.input.properties.defaultValue.setOrConnect(aValue);
17
+
18
+ return this;
19
+ }
20
+
15
21
  addCase(aKey, aOutputValue) {
16
22
 
17
23
  let newCase = {key: aKey, value: aOutputValue};
@@ -50,14 +50,16 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
50
50
  }
51
51
 
52
52
  _runRequest(aRequestItem) {
53
- let newRequests = [].concat(this.item.requests);
54
- newRequests.push(aRequestItem);
55
- this.item.setValue("requests", newRequests);
56
-
53
+
57
54
  if(this.item.status === 1) {
58
55
  aRequestItem.setValue("status", Dbm.loading.LoadingStatus.LOADING);
59
56
  this._webSocket.send(JSON.stringify(aRequestItem.requestData));
60
57
  }
58
+ else {
59
+ let newRequests = [].concat(this.item.requests);
60
+ newRequests.push(aRequestItem);
61
+ this.item.setValue("requests", newRequests);
62
+ }
61
63
  }
62
64
 
63
65
  requestRange(aSelect, aEncode) {
@@ -111,7 +113,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
111
113
  }
112
114
 
113
115
  _callback_onOpen(aEvent) {
114
- console.log("_callback_onOpen");
116
+ //console.log("_callback_onOpen");
115
117
 
116
118
  if(this._intervalId === -1) {
117
119
  this._intervalId = setInterval(this._callback_sendHeartbeatBound, 20*1000);
@@ -119,8 +121,8 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
119
121
  }
120
122
 
121
123
  _callback_onClose(aEvent) {
122
- console.log("_callback_onClose");
123
- console.log(aEvent);
124
+ //console.log("_callback_onClose");
125
+ //console.log(aEvent);
124
126
 
125
127
  if(this._intervalId !== -1) {
126
128
  clearInterval(this._intervalId);
@@ -148,13 +150,14 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
148
150
  }
149
151
 
150
152
  _callback_sendHeartbeat() {
151
- console.log("_callback_sendHeartbeat");
153
+ //console.log("_callback_sendHeartbeat");
152
154
 
153
155
  this._webSocket.send(JSON.stringify({"type": "heartbeat"}));
154
156
  }
155
157
 
156
158
  _connectionReady() {
157
159
  this.item.setValue("status", 1);
160
+
158
161
  let currentArray = this.item.requests;
159
162
  let currentArrayLength = currentArray.length;
160
163
  for(let i = 0; i < currentArrayLength; i++) {
@@ -162,6 +165,8 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
162
165
  currentItem.setValue("status", Dbm.loading.LoadingStatus.LOADING);
163
166
  this._webSocket.send(JSON.stringify(currentItem.requestData));
164
167
  }
168
+
169
+ this.item.requests = [];
165
170
  }
166
171
 
167
172
  _callback_onMessage(aEvent) {
@@ -62,6 +62,22 @@ let fullSetup = function() {
62
62
  currentDecoder.item.setValue("encodingType", name);
63
63
  currentDecoder.item.register(decodePrefix + name);
64
64
  }
65
+
66
+ {
67
+ let name = "navigationName";
68
+ let currentDecoder = new Dbm.graphapi.webclient.decode.DecodeBaseObject();
69
+ currentDecoder.item.setValue("copyFields", ["navigationName"]);
70
+ currentDecoder.item.setValue("encodingType", name);
71
+ currentDecoder.item.register(decodePrefix + name);
72
+ }
73
+
74
+ {
75
+ let name = "breadcrumb";
76
+ let currentDecoder = new Dbm.graphapi.webclient.decode.DecodeBaseObject();
77
+ currentDecoder.item.setValue("copyLinks", ["breadcrumbs"]);
78
+ currentDecoder.item.setValue("encodingType", name);
79
+ currentDecoder.item.register(decodePrefix + name);
80
+ }
65
81
  }
66
82
 
67
83
  export {fullSetup};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbm",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {},
@@ -25,7 +25,7 @@ export default class BaseObject extends Component {
25
25
  if(currentProp && currentProp.isSource) {
26
26
  currentProp = currentProp.getSource(this);
27
27
  let currentDynamicProperty = this.getDynamicProp(objectName);
28
- currentDynamicProperty.setValue(currentProp);
28
+ currentDynamicProperty.setOrConnect(currentProp);
29
29
  }
30
30
  else if(currentProp && currentProp.isFlowProperty) {
31
31
  let currentDynamicProperty = this.getDynamicProp(objectName);
@@ -129,15 +129,13 @@ export default class BaseObject extends Component {
129
129
  return this._performCreateMainElement(aType, aProps, children);
130
130
  }
131
131
 
132
- _performCreateMainElement(aType, aProps, children) {
132
+ _removedUsedProps(aProps) {
133
+
134
+ }
133
135
 
136
+ _copyProps(aProps) {
134
137
  let newProps = {...aProps};
135
138
 
136
- let elementType = this.getProp("elementType");
137
- if(elementType) {
138
- aType = elementType;
139
- }
140
-
141
139
  for(let objectName in this.props) {
142
140
  let currentValue = this.getPropValue(objectName);
143
141
  switch(objectName) {
@@ -178,6 +176,19 @@ export default class BaseObject extends Component {
178
176
  }
179
177
  }
180
178
 
179
+ this._removedUsedProps(newProps);
180
+ return newProps;
181
+ }
182
+
183
+ _performCreateMainElement(aType, aProps, children) {
184
+
185
+ let newProps = this._copyProps(aProps);
186
+
187
+ let elementType = this.getProp("elementType");
188
+ if(elementType) {
189
+ aType = elementType;
190
+ }
191
+
181
192
  if(!children || !children.length) {
182
193
  return createElement(aType, newProps);
183
194
  }
@@ -0,0 +1,27 @@
1
+ import Dbm from "../index.js";
2
+
3
+ export const splitIntoSlots = function(aChildren) {
4
+ let returnObject = {};
5
+
6
+ aChildren = Dbm.utils.ArrayFunctions.singleOrArray(aChildren);
7
+
8
+ if(aChildren) {
9
+ let currentArray = aChildren;
10
+ let currentArrayLength = currentArray.length;
11
+ for(let i = 0; i < currentArrayLength; i++) {
12
+ let currentElement = currentArray[i];
13
+ let currentSlot = Dbm.objectPath(currentElement, "props.data-slot");
14
+ if(!currentSlot) {
15
+ currentSlot = "main";
16
+ }
17
+ let currentArea = returnObject[currentSlot];
18
+ if(!currentArea) {
19
+ returnObject[currentSlot] = currentArea = [];
20
+ }
21
+ currentArea.push(currentElement);
22
+ }
23
+ }
24
+
25
+
26
+ return returnObject;
27
+ }
@@ -8,6 +8,7 @@ export default class EditPage extends Dbm.react.BaseObject {
8
8
  let page = this.context.page;
9
9
 
10
10
  this.item.setValue("title", page.title);
11
+ this.item.setValue("navigationName", page.navigationName);
11
12
  this.item.setValue("content", page.content);
12
13
  this.item.setValue("description", page["meta/description"]);
13
14
  this.item.setValue("url", page.url);
@@ -21,10 +22,13 @@ export default class EditPage extends Dbm.react.BaseObject {
21
22
  let page = this.context.page;
22
23
  let id = page.id;
23
24
  let graphApi = Dbm.getInstance().repository.getItem("graphApi").controller;
25
+ console.log(this.item.content);
26
+ console.log(this.item.content.blocks[1].data.text);
24
27
 
25
28
  graphApi.editItem(id, [
26
29
  {"type": "setField", "data": {"value": this.item.content, "field": "content"}},
27
30
  {"type": "setField", "data": {"value": this.item.title, "field": "title"}},
31
+ {"type": "setField", "data": {"value": this.item.navigationName, "field": "navigationName"}},
28
32
  {"type": "setField", "data": {"value": this.item.description, "field": "meta/description"}},
29
33
  {"type": "setField", "data": {"value": (new Date()).toISOString(), "field": "lastModified"}},
30
34
  {"type": "setUrl", "data": {"value": this.item.url}}
@@ -42,6 +46,13 @@ export default class EditPage extends Dbm.react.BaseObject {
42
46
  React.createElement(Dbm.react.form.FormField, {"value": this.item.properties.title, className: "standard-field standard-field-padding full-width page-title-form-field", placeholder: "Title"}),
43
47
  ),
44
48
  React.createElement("div", {className: "spacing standard"}),
49
+ React.createElement("div", {},
50
+ React.createElement("label", {className: "standard-field-label"},
51
+ "Navigation name"
52
+ ),
53
+ React.createElement(Dbm.react.form.FormField, {"value": this.item.properties.navigationName, className: "standard-field standard-field-padding full-width", placeholder: "Name showed in menues and breadcrumbs"}),
54
+ ),
55
+ React.createElement("div", {className: "spacing standard"}),
45
56
  React.createElement("div", {},
46
57
  React.createElement("label", {className: "standard-field-label"},
47
58
  "Url"
@@ -62,7 +73,7 @@ export default class EditPage extends Dbm.react.BaseObject {
62
73
  "Content"
63
74
  ),
64
75
  React.createElement("div", {},
65
- React.createElement(Dbm.react.admin.Editor, {"value": this.item.properties.content}),
76
+ React.createElement(Dbm.react.admin.editor.Editor, {"value": this.item.properties.content}),
66
77
  )
67
78
  ),
68
79
  React.createElement("div", {className: "spacing standard"}),
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import Dbm from "../../index.js";
2
+ import Dbm from "../../../index.js";
3
3
 
4
4
  import EditorBlock from "./EditorBlock.js";
5
5
 
@@ -7,6 +7,9 @@ export default class Editor extends Dbm.react.BaseObject {
7
7
  _construct() {
8
8
  super._construct();
9
9
 
10
+ let editorId = "editor/instance" + Dbm.getInstance().getNextId();
11
+ this.item.register(editorId);
12
+
10
13
  let all = Dbm.flow.updatefunctions.logic.allAtValue(1);
11
14
 
12
15
  all.addCheck(Dbm.loading.loadScript("https://cdn.jsdelivr.net/npm/@editorjs/image@latest").item.properties.status);
@@ -51,32 +54,38 @@ export default class Editor extends Dbm.react.BaseObject {
51
54
 
52
55
  if(aPreSign.status === 1) {
53
56
  let url = aPreSign.data.url;
54
- console.log(url);
57
+ console.log(url, aPreSign.data);
55
58
 
56
- const myHeaders = new Headers({
59
+ let headers = {
57
60
  'Content-Type': aFile.type,
58
- 'x-amz-acl': 'public-read'
59
- });
61
+ 'Cache-Control': 'no-cache',
62
+ };
63
+
64
+ let additionalHeaders = aPreSign.data.additionalHeaders;
65
+ for(let objectName in additionalHeaders) {
66
+ headers[objectName] = additionalHeaders[objectName];
67
+ }
68
+
60
69
  fetch(url, {
61
70
  method: 'PUT',
62
- headers: myHeaders,
71
+ headers: new Headers(headers),
63
72
  body: aFile
64
73
  }).then(() => {
65
- resolve({success: true, file: {url: aPreSign.data.publicUrl}});
74
+ resolve({success: true, file: {url: aPreSign.data.publicUrl, resizeUrl: aPreSign.data.publicResizeUrl, identifier: aPreSign.data.identifier}});
66
75
  })
67
76
 
68
-
69
77
  }
70
78
  }
71
79
 
72
80
  _callback_saveDataUpdated(aData) {
73
- console.log("_callback_saveDataUpdated");
74
- console.log(aData);
81
+ //console.log("_callback_saveDataUpdated");
82
+ //console.log(aData);
75
83
 
76
84
  this.getDynamicProp("value").getMostUpstreamProperty().setValue(aData);
77
85
  }
78
86
 
79
87
  _callback_editorChange(aApi, aEvent) {
88
+ console.log("_callback_editorChange");
80
89
  this.item.editor.save().then(this._callback_saveDataUpdatedBound);
81
90
  }
82
91
 
@@ -119,7 +128,14 @@ export default class Editor extends Dbm.react.BaseObject {
119
128
 
120
129
 
121
130
  let editorConfigItem = Dbm.getInstance().repository.getItem("editorjs");
122
- let toolsFromConfig = editorConfigItem.tools;
131
+ let toolsFromConfig = {...editorConfigItem.tools};
132
+
133
+ let editorId = this.item.id;
134
+ for(let objectName in toolsFromConfig) {
135
+ let currentTool = {...toolsFromConfig[objectName]};
136
+ currentTool["config"] = {...currentTool["config"], "editorId": editorId};
137
+ toolsFromConfig[objectName] = currentTool;
138
+ }
123
139
 
124
140
  tools = {...tools, ...toolsFromConfig};
125
141
 
@@ -1,4 +1,4 @@
1
- import Dbm from "../../index.js";
1
+ import Dbm from "../../../index.js";
2
2
 
3
3
  export default class EditorBlock extends Dbm.core.BaseObject {
4
4
 
@@ -6,11 +6,18 @@ export default class EditorBlock extends Dbm.core.BaseObject {
6
6
  super();
7
7
 
8
8
  this._settings = aSettings;
9
-
9
+
10
10
  this.item.setValue("data", aSettings.data ? aSettings.data : {});
11
11
  this.item.setValue("name", aSettings.config ? aSettings.config.name : "Unnamed block");
12
+ this.item.setValue("editor", aSettings.config ? Dbm.getInstance().repository.getItem(aSettings.config.editorId) : null);
12
13
  this.item.setValue("module", Dbm.getInstance().repository.getItem("moduleCreators/blocks/editor/" + aSettings.config.module));
14
+ this.item.setValue("editorBlock", this);
15
+
16
+ }
13
17
 
18
+ dataUpdated() {
19
+ //console.log("dataUpdated")
20
+ this._settings.block.dispatchChange();
14
21
  }
15
22
 
16
23
  render(){
@@ -35,12 +42,16 @@ export default class EditorBlock extends Dbm.core.BaseObject {
35
42
  }
36
43
 
37
44
  save(aHolderElement){
38
- console.log("save");
39
- console.log(aHolderElement);
45
+ //console.log("save");
46
+ //console.log(aHolderElement);
40
47
 
41
48
  return this.item.data;
42
49
  }
43
50
 
51
+ static get sanitize() {
52
+ return {};
53
+ }
54
+
44
55
  static get toolbox() {
45
56
 
46
57
  //'<svg xmlns="http://www.w3.org/2000/svg" viewBox="-0.5 -0.5 16 16" id="Module--Streamline-Streamline-3.0" height="16" width="16"><desc>Module Streamline Icon: https://streamlinehq.com</desc><g><path d="M14.21875 2.65625a0.625 0.625 0 0 1 0.46875 0.625v8.4375a0.625 0.625 0 0 1 -0.42500000000000004 0.59375l-6.55625 2.34375a0.625 0.625 0 0 1 -0.41250000000000003 0L0.725 12.318750000000001a0.625 0.625 0 0 1 -0.41250000000000003 -0.5874999999999999V3.2624999999999997a0.625 0.625 0 0 1 0.46875 -0.625L7.34375 0.33125000000000004a0.6625000000000001 0.6625000000000001 0 0 1 0.3125 0Z" fill="none" stroke="#000000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"></path><path d="m7.5 5.29375 0 9.393749999999999" fill="none" stroke="#000000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"></path><path d="M14.51875 2.8375 7.5 5.29375 0.48125 2.8375" fill="none" stroke="#000000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"></path></g></svg>'
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ import Dbm from "../../../index.js";
3
+
4
+ export default class EditorBlockFields 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(Dbm.react.admin.editor.EditorBlockName, {},
15
+ React.createElement(Dbm.react.form.LabelledArea, {label: "fieldName", for: "test"},
16
+ React.createElement(Dbm.react.admin.editor.fields.TextField, {name: "fieldName", id: "test"})
17
+ ),
18
+ React.createElement(Dbm.react.admin.editor.fields.RichTextField, {name: "fieldName"}),
19
+ React.createElement(Dbm.react.admin.editor.fields.ImageField, {name: "image"})
20
+ );
21
+ }
22
+ }
23
+
@@ -0,0 +1,28 @@
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 childrenAndSpacing = null;
12
+ let children = this.getPropValue("children");
13
+ if(children) {
14
+ childrenAndSpacing = React.createElement(React.Fragment, {},
15
+ React.createElement("div", {"className": "spacing standard"}),
16
+ children
17
+ )
18
+ }
19
+
20
+ return React.createElement("div", {"className": "editor-block-box editor-block-box-padding"},
21
+ React.createElement("div", {"className": "text-align-center"},
22
+ Dbm.react.text.text(Dbm.react.source.contextVariable("moduleData.editorData.name"))
23
+ ),
24
+ childrenAndSpacing
25
+ );
26
+ }
27
+ }
28
+
@@ -0,0 +1,54 @@
1
+ import React from "react";
2
+ import Dbm from "../../../../index.js";
3
+
4
+ export default class CheckboxField extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this._valueChangedBound = this._valueChanged.bind(this);
9
+ this._objectChangedBound = this._objectChanged.bind(this);
10
+
11
+ Dbm.flow.addUpdateCommand(this.item.requireProperty("value", this._getObjectData()), Dbm.commands.callFunction(this._valueChangedBound));
12
+
13
+ let editorData = Dbm.objectPath(this.context, "moduleData.editorData");
14
+ Dbm.flow.addUpdateCommand(editorData.properties.data, Dbm.commands.callFunction(this._objectChangedBound));
15
+ }
16
+
17
+ _getObjectData() {
18
+ let fieldName = this.getPropValue("name");
19
+
20
+ let editorData = Dbm.objectPath(this.context, "moduleData.editorData");
21
+
22
+ let returnData = editorData.data[fieldName];
23
+ if(!returnData) {
24
+ returnData = false;
25
+ }
26
+
27
+ return returnData;
28
+ }
29
+
30
+
31
+ _valueChanged() {
32
+ //console.log("_valueChanged");
33
+
34
+ let fieldName = this.getPropValue("name");
35
+ let newValue = this.item.value;
36
+ let editorData = Dbm.objectPath(this.context, "moduleData.editorData");
37
+
38
+ let newData = {...editorData.data};
39
+ newData[fieldName] = newValue;
40
+
41
+ editorData.data = newData;
42
+ this.context.moduleData.editorData.editorBlock.dataUpdated();
43
+ }
44
+
45
+ _objectChanged() {
46
+ //console.log("_objectChanged");
47
+
48
+ this.item.value = this._getObjectData();
49
+ }
50
+
51
+ _renderMainElement() {
52
+ return this._createMainElement(Dbm.react.form.Checkbox, {checked: this.item.properties.value});
53
+ }
54
+ }
@@ -0,0 +1,137 @@
1
+ import React from "react";
2
+ import Dbm from "../../../../index.js";
3
+
4
+ export default class ImageField extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this._valueChangedBound = this._valueChanged.bind(this);
9
+ this._objectChangedBound = this._objectChanged.bind(this);
10
+ this._callback_fileChangedBound = this._callback_fileChanged.bind(this);
11
+
12
+ let fieldName = this.getPropValue("name");
13
+
14
+ let editorData = Dbm.objectPath(this.context, "moduleData.editorData");
15
+
16
+ Dbm.flow.addUpdateCommand(this.item.requireProperty("value", this._getObjectData()), Dbm.commands.callFunction(this._valueChangedBound));
17
+
18
+ Dbm.flow.addUpdateCommand(editorData.properties.data, Dbm.commands.callFunction(this._objectChangedBound));
19
+
20
+ let imageElement = React.createElement("div", {className: "flex-row small-item-spacing"},
21
+ React.createElement("div", {className: "flex-row-item flex-no-resize"},
22
+ React.createElement(Dbm.react.image.Image, {"src": Dbm.react.source.contextVariable("moduleData.editorData.data." + fieldName + ".url"), className: "editor-preview background-contain"}),
23
+ ),
24
+ React.createElement("div", {className: "flex-row-item flex-resize"},
25
+ Dbm.react.text.text(Dbm.react.source.contextVariable("moduleData.editorData.data." + fieldName + ".url"))
26
+ ),
27
+ React.createElement("div", {className: "flex-row-item flex-no-resize"},
28
+ React.createElement("div", {onClick: () => {this.removeImage()}}, "Remove")
29
+ )
30
+ );
31
+
32
+ let uploadElement = React.createElement("input", {"type": "file", onChange: this._callback_fileChangedBound, className: "full-width"});
33
+
34
+ let elementSwitch =Dbm.flow.updatefunctions.logic.switchValue(this.item.properties.value).setDefaultValue(imageElement).addCase(null, uploadElement);
35
+
36
+ this.item.requireProperty("element", null).connectInput(elementSwitch.output.properties.value);
37
+ }
38
+
39
+ _getObjectData() {
40
+ let fieldName = this.getPropValue("name");
41
+
42
+ let editorData = Dbm.objectPath(this.context, "moduleData.editorData");
43
+
44
+ let returnData = editorData.data[fieldName];
45
+ if(!returnData) {
46
+ returnData = null;
47
+ }
48
+
49
+ return returnData;
50
+ }
51
+
52
+ _valueChanged() {
53
+ //console.log("_valueChanged");
54
+
55
+ let fieldName = this.getPropValue("name");
56
+ let newValue = this.item.value;
57
+ let editorData = Dbm.objectPath(this.context, "moduleData.editorData");
58
+
59
+ let newData = {...editorData.data};
60
+ newData[fieldName] = newValue;
61
+
62
+ editorData.data = newData;
63
+ this.context.moduleData.editorData.editorBlock.dataUpdated();
64
+ }
65
+
66
+ _objectChanged() {
67
+ //console.log("_objectChanged");
68
+
69
+ let fieldName = this.getPropValue("name");
70
+ let editorData = Dbm.objectPath(this.context, "moduleData.editorData");
71
+
72
+ this.item.value = this._getObjectData();
73
+ }
74
+
75
+ _callback_fileChanged(aEvent) {
76
+ console.log("_callback_fileChanged");
77
+ console.log(aEvent, aEvent.target.files);
78
+
79
+ let files = aEvent.target.files;
80
+ if(files.length > 0) {
81
+ this.uploadImage(files[0]);
82
+ }
83
+ }
84
+
85
+ removeImage() {
86
+ this.item.value = null;
87
+
88
+ return this;
89
+ }
90
+
91
+ uploadImage(aFile) {
92
+
93
+ let graphApi = Dbm.getInstance().repository.getItem("graphApi").controller;
94
+
95
+ let preSign = graphApi.requestData("fileUpload", {"fileName": aFile.name, "mimeType": aFile.type});
96
+
97
+ Dbm.flow.addDirectUpdateCommand(preSign.getProperty("status"), Dbm.commands.callFunction(this._statusChanged.bind(this), [preSign, aFile]));
98
+
99
+ }
100
+
101
+ _statusChanged(aPreSign, aFile) {
102
+ console.log("_statusChanged");
103
+ console.log(aPreSign, aFile);
104
+
105
+ if(aPreSign.status === 1) {
106
+ let url = aPreSign.data.url;
107
+ console.log(url, aPreSign.data);
108
+
109
+ let headers = {
110
+ 'Content-Type': aFile.type,
111
+ 'Cache-Control': 'no-cache',
112
+ };
113
+
114
+ let additionalHeaders = aPreSign.data.additionalHeaders;
115
+ for(let objectName in additionalHeaders) {
116
+ headers[objectName] = additionalHeaders[objectName];
117
+ }
118
+
119
+ fetch(url, {
120
+ method: 'PUT',
121
+ headers: new Headers(headers),
122
+ body: aFile
123
+ }).then(() => {
124
+ this.item.value = {url: aPreSign.data.publicUrl, resizeUrl: aPreSign.data.publicResizeUrl, identifier: aPreSign.data.identifier};
125
+ console.log("Uploaded", this.item.value);
126
+ //METODO: send update to editor
127
+ })
128
+
129
+ }
130
+ }
131
+
132
+ _renderMainElement() {
133
+ return this._createMainElement("div", {},
134
+ React.createElement(Dbm.react.area.InsertElement, {element: this.item.properties.element})
135
+ );
136
+ }
137
+ }