dbm 1.0.0 → 1.0.2

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.
@@ -0,0 +1,67 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class HorizontalFlip extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("envelope", 0);
9
+ console.log(this.input.properties.envelope);
10
+ this.input.register("perspective", "3000px");
11
+
12
+ this.output.register("style1", {});
13
+ this.output.register("style2", {"opacity": 0, "position": "absolute", "top": 0, "left": 0, "width": "100%", "dispaly": "none"});
14
+ this.output.register("inDom1", true);
15
+ this.output.register("inDom2", false);
16
+ }
17
+
18
+ _update() {
19
+ //console.log("_update");
20
+
21
+ let envelope = this.input.envelope;
22
+ let perspective = this.input.perspective;
23
+
24
+ let inDom1 = (Math.round(Math.abs(180*envelope)+180)%360 !== 0);
25
+ let inDom2 = (Math.round(Math.abs(180*envelope))%360 !== 0);
26
+
27
+ this.output.inDom1 = inDom1;
28
+ this.output.inDom2 = inDom2;
29
+
30
+ if(!inDom1) {
31
+ this.output.style1 = {"opacity": 0, "position": "absolute", "top": 0, "left": 0, "width": "100%", "dispaly": "none"};
32
+ this.output.style2 = {};
33
+ }
34
+ else if(!inDom2) {
35
+ this.output.style1 = {};
36
+ this.output.style2 = {"opacity": 0, "position": "absolute", "top": 0, "left": 0, "width": "100%", "dispaly": "none"};
37
+ }
38
+ else {
39
+ let angle1 = 180*envelope;
40
+ let angle2 = angle1-180;
41
+ let localAngle = Dbm.utils.NumberFunctions.floatMod(angle1, 360);
42
+
43
+ let styleObject1 = {"transform": "perspective(" + perspective + ") rotateY(" + angle1 + "deg)"};
44
+ let styleObject2 = {"transform": "perspective(" + perspective + ") rotateY(" + angle2 + "deg)"};
45
+
46
+ if(localAngle < 90 || localAngle >= 3*90) {
47
+ styleObject1["opacity"] = 1;
48
+ styleObject2["opacity"] = 0;
49
+ styleObject2["position"] = "absolute";
50
+ styleObject2["top"] = 0;
51
+ styleObject2["left"] = 0;
52
+ styleObject2["width"] = 0;
53
+ }
54
+ else {
55
+ styleObject1["opacity"] = 0;
56
+ styleObject2["opacity"] = 1;
57
+ styleObject1["position"] = "absolute";
58
+ styleObject1["top"] = 0;
59
+ styleObject1["left"] = 0;
60
+ styleObject1["width"] = 0;
61
+ }
62
+
63
+ this.output.style1 = styleObject1;
64
+ this.output.style2 = styleObject2;
65
+ }
66
+ }
67
+ }
@@ -1,2 +1,3 @@
1
1
  export {default as ElementSize} from "./ElementSize.js";
2
- export {default as StyleObject} from "./StyleObject.js";
2
+ export {default as StyleObject} from "./StyleObject.js";
3
+ export {default as HorizontalFlip} from "./HorizontalFlip.js";
@@ -0,0 +1,44 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class All extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("checks", []);
9
+
10
+ this.output.register("value", false);
11
+ }
12
+
13
+ addCheck(aValue) {
14
+
15
+ let checks = [].concat(this.input.checks);
16
+
17
+ let property = this.input.register("property_" + checks.length, null).setOrConnect(aValue);
18
+
19
+ checks.push(property);
20
+
21
+ this.input.checks = checks;
22
+
23
+ return this;
24
+ }
25
+
26
+ _update() {
27
+ //console.log("_update");
28
+
29
+ let returnValue = true;
30
+
31
+ let currentArray = this.input.checks;
32
+ let currentArrayLength = currentArray.length;
33
+ for(let i = 0; i < currentArrayLength; i++) {
34
+ let currentProperty = currentArray[i];
35
+
36
+ if(!currentProperty.value) {
37
+ returnValue = false;
38
+ break;
39
+ }
40
+ }
41
+
42
+ this.output.value = returnValue;
43
+ }
44
+ }
@@ -0,0 +1,46 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class AllAtValue extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("matchValue", 1);
9
+ this.input.register("checks", []);
10
+
11
+ this.output.register("value", false);
12
+ }
13
+
14
+ addCheck(aValue) {
15
+
16
+ let checks = [].concat(this.input.checks);
17
+
18
+ let property = this.input.register("property_" + checks.length, null).setOrConnect(aValue);
19
+
20
+ checks.push(property);
21
+
22
+ this.input.checks = checks;
23
+
24
+ return this;
25
+ }
26
+
27
+ _update() {
28
+ //console.log("_update");
29
+
30
+ let matchValue = this.input.matchValue;
31
+ let returnValue = true;
32
+
33
+ let currentArray = this.input.checks;
34
+ let currentArrayLength = currentArray.length;
35
+ for(let i = 0; i < currentArrayLength; i++) {
36
+ let currentProperty = currentArray[i];
37
+
38
+ if(currentProperty.value !== matchValue) {
39
+ returnValue = false;
40
+ break;
41
+ }
42
+ }
43
+
44
+ this.output.value = returnValue;
45
+ }
46
+ }
@@ -0,0 +1,44 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class Any extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("checks", []);
9
+
10
+ this.output.register("value", false);
11
+ }
12
+
13
+ addCheck(aValue) {
14
+
15
+ let checks = [].concat(this.input.checks);
16
+
17
+ let property = this.input.register("property_" + checks.length, null).setOrConnect(aValue);
18
+
19
+ checks.push(property);
20
+
21
+ this.input.checks = checks;
22
+
23
+ return this;
24
+ }
25
+
26
+ _update() {
27
+ //console.log("_update");
28
+
29
+ let returnValue = false;
30
+
31
+ let currentArray = this.input.checks;
32
+ let currentArrayLength = currentArray.length;
33
+ for(let i = 0; i < currentArrayLength; i++) {
34
+ let currentProperty = currentArray[i];
35
+
36
+ if(currentProperty.value) {
37
+ returnValue = true;
38
+ break;
39
+ }
40
+ }
41
+
42
+ this.output.value = returnValue;
43
+ }
44
+ }
@@ -0,0 +1,20 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class Condition extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("input1", null);
9
+ this.input.register("operation", function(aA, aB) {return aA === aB;});
10
+ this.input.register("input2", null);
11
+
12
+ this.output.register("result", true);
13
+ }
14
+
15
+ _update() {
16
+ //console.log("_update");
17
+
18
+ this.output.result = this.input.operation.call(this, this.input.input1, this.input.input2);
19
+ }
20
+ }
@@ -15,6 +15,7 @@ export default class RangeSwitch extends Dbm.flow.FlowUpdateFunction {
15
15
  addValueForRange(aOutputValue, aMinInputValue = null, aMaxInputValue = null) {
16
16
 
17
17
  let rangeData = {value: aOutputValue, min: aMinInputValue, max: aMaxInputValue};
18
+ //METODO: connect values to flow
18
19
 
19
20
  let newRanges = [].concat(this.input.ranges);
20
21
 
@@ -0,0 +1,47 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class Switch extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("value", 0);
9
+ this.input.register("defaultValue", null);
10
+ this.input.register("cases", []);
11
+
12
+ this.output.register("value", null);
13
+ }
14
+
15
+ addCase(aKey, aOutputValue) {
16
+
17
+ let newCase = {key: aKey, value: aOutputValue};
18
+ //METODO: connect key and value to flow
19
+
20
+ let newCases = [].concat(this.input.cases);
21
+
22
+ newCases.push(newCase);
23
+
24
+ this.input.cases = newCases;
25
+
26
+ return this;
27
+ }
28
+
29
+ _update() {
30
+ //console.log("_update");
31
+
32
+ let value = this.input.value;
33
+
34
+ let currentArray = this.input.ranges;
35
+ let currentArrayLength = currentArray.length;
36
+ for(let i = 0; i < currentArrayLength; i++) {
37
+ let currentCase = currentArray[i];
38
+
39
+ if(value === currentCase["key"]) {
40
+ this.output.value = currentRange["value"];
41
+ return;
42
+ }
43
+ }
44
+
45
+ this.output.value = this.input.defaultValue;
46
+ }
47
+ }
@@ -4,6 +4,11 @@ export {default as Addition} from "./Addition.js";
4
4
  export {default as Multiplication} from "./Multiplication.js";
5
5
  export {default as RangeSwitch} from "./RangeSwitch.js";
6
6
  export {default as Subtraction} from "./Subtraction.js";
7
+ export {default as Switch} from "./Switch.js";
8
+ export {default as Condition} from "./Condition.js";
9
+ export {default as All} from "./All.js";
10
+ export {default as Any} from "./Any.js";
11
+ export {default as AllAtValue} from "./AllAtValue.js";
7
12
 
8
13
  export let subtract = function(aInput1 = 0, aInput2 = 0) {
9
14
  let updateFunction = new Dbm.flow.updatefunctions.logic.Subtraction();
@@ -34,5 +39,52 @@ export let multiply = function(aInput1 = 1, aInput2 = 1) {
34
39
  updateFunction.input.properties.input1.setOrConnect(aInput1);
35
40
  updateFunction.input.properties.input2.setOrConnect(aInput2);
36
41
 
42
+ return updateFunction;
43
+ }
44
+
45
+ export let condition = function(aInput1 = null, aOperationFunction = null, aInput2 = null) {
46
+ let updateFunction = new Dbm.flow.updatefunctions.logic.Condition();
47
+ updateFunction.input.properties.input1.setOrConnect(aInput1);
48
+ updateFunction.input.properties.operation.setOrConnect(aOperationFunction);
49
+ updateFunction.input.properties.input2.setOrConnect(aInput2);
50
+
51
+ return updateFunction;
52
+ }
53
+
54
+ export let all = function(...aValues) {
55
+ let updateFunction = new Dbm.flow.updatefunctions.logic.All();
56
+
57
+ let currentArray = aValues;
58
+ let currentArrayLength = currentArray.length;
59
+ for(let i = 0; i < currentArrayLength; i++) {
60
+ updateFunction.addCheck(currentArray[i]);
61
+ }
62
+
63
+ return updateFunction;
64
+ }
65
+
66
+ export let any = function(...aValues) {
67
+ let updateFunction = new Dbm.flow.updatefunctions.logic.Any();
68
+
69
+ let currentArray = aValues;
70
+ let currentArrayLength = currentArray.length;
71
+ for(let i = 0; i < currentArrayLength; i++) {
72
+ updateFunction.addCheck(currentArray[i]);
73
+ }
74
+
75
+ return updateFunction;
76
+ }
77
+
78
+ export let allAtValue = function(aMatchValue, ...aValues) {
79
+ let updateFunction = new Dbm.flow.updatefunctions.logic.AllAtValue();
80
+
81
+ updateFunction.input.matchValue = aMatchValue;
82
+
83
+ let currentArray = aValues;
84
+ let currentArrayLength = currentArray.length;
85
+ for(let i = 0; i < currentArrayLength; i++) {
86
+ updateFunction.addCheck(currentArray[i]);
87
+ }
88
+
37
89
  return updateFunction;
38
90
  }
@@ -0,0 +1,50 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class EditGroup extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ this.item.setValue("status", 0);
6
+ let changedProperty = this.item.requireProperty("changed", false);
7
+ this.item.setValue("showSavedMessageTimer", 0);
8
+ this.item.setValue("editors", []);
9
+
10
+ let any = Dbm.flow.updatefunctions.logic.any();
11
+ this.item.setValue("any", any);
12
+
13
+ changedProperty.connectInput(any.output.properties.value);
14
+
15
+ }
16
+
17
+ createEditor(aSavedValue) {
18
+ let newChangeObject = null; //METODO
19
+
20
+ newChangeObject.setValue("changed", false);
21
+
22
+ newChangeObject.item; //METODO: connect saved value
23
+ //METODO: setup edited value
24
+ //METODO: set up condition
25
+
26
+ this.item.any.addCheck(newChangeObject.item.properties.changed); //METODO: add to any
27
+
28
+
29
+ let editors = [].concat(this.item.editors);
30
+ editors.push(newChangeObject);
31
+ this.item.editors = editors;
32
+ }
33
+
34
+ save() {
35
+
36
+ let saveOperations = [];
37
+
38
+ let currentArray = editors;
39
+ let currentArrayLength = currentArray.length;
40
+ for(let i = 0; i < currentArrayLength; i++) {
41
+ let currentChangeObject = currentArray[i];
42
+ if(currentChangeObject.item.changed) {
43
+ let saveOperation = null; //METODO: get save operation
44
+ saveOperations.push(saveOperation);
45
+ }
46
+ }
47
+
48
+ //METODO: trigger save operations
49
+ }
50
+ }
@@ -0,0 +1 @@
1
+ export {default as EditGroup} from "./EditGroup.js";
package/graphapi/index.js CHANGED
@@ -1 +1,2 @@
1
- export * as webclient from "./webclient/index.js";
1
+ export * as webclient from "./webclient/index.js";
2
+ export * as admin from "./admin/index.js";
@@ -0,0 +1,110 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class ApiConnection extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ this._url = null;
8
+ this._setupItemResponseBound = this._setupItemResponse.bind(this);
9
+ }
10
+
11
+ setup(aUrl) {
12
+
13
+ this._url = aUrl;
14
+
15
+ return this;
16
+ }
17
+
18
+ _getRequestItem() {
19
+
20
+ let request = new Dbm.graphapi.webclient.ApiRequest();
21
+ request.item.setValue("status", Dbm.loading.LoadingStatus.NOT_STARTED);
22
+ request.item.setValue("connection", this.item);
23
+
24
+ return request.item;
25
+ }
26
+
27
+ requestRange(aSelect, aEncode) {
28
+ let item = this._getRequestItem();
29
+
30
+
31
+ return item;
32
+ }
33
+
34
+ requestItem(aId, aEncode) {
35
+ let item = this._getRequestItem();
36
+
37
+
38
+ return item;
39
+ }
40
+
41
+ requestData(aFunctionName, aData) {
42
+ let item = this._getRequestItem();
43
+
44
+
45
+ return item;
46
+ }
47
+
48
+ createItem(aTypes, aVisibility = "draft", aChanges = [], aEncode = []) {
49
+ let item = this._getRequestItem();
50
+
51
+
52
+ return item;
53
+ }
54
+
55
+ editItem(aId, aChanges, aEncode = []) {
56
+ let item = this._getRequestItem();
57
+
58
+
59
+ return item;
60
+ }
61
+
62
+ _updateObjects(aObjects) {
63
+ let repository = Dbm.getInstance().repository;
64
+
65
+ let currentArray = aObjects;
66
+ let currentArrayLength = currentArray.length;
67
+ for(let i = 0; i < currentArrayLength; i++) {
68
+ let data = currentArray[i];
69
+ let item = repository.getItem(data["id"]);
70
+ let decoder = repository.getItemIfExists("graphApi/decode/" + data["encoding"]);
71
+ if(decoder) {
72
+ decoder.controller.updateItemWithEncoding(item, data["data"]);
73
+ }
74
+ else {
75
+ console.warn("No decoder for " + data["encoding"]);
76
+ }
77
+ }
78
+ }
79
+
80
+ _setupItemResponse(aRequestItem, aData) {
81
+ this._updateObjects(aData.objects);
82
+
83
+ let repository = Dbm.getInstance().repository;
84
+
85
+ let id = aData.data.id;
86
+ if(id) {
87
+ aRequestItem.setValue("item", repository.getItem(id));
88
+ }
89
+ else {
90
+ aRequestItem.setValue("item", null);
91
+ }
92
+
93
+ aRequestItem.status = 1;
94
+ }
95
+
96
+ requestUrl(aUrl) {
97
+
98
+ let item = this._getRequestItem();
99
+
100
+ let fullUrl = this._url + "url?url=" + encodeURIComponent(aUrl);
101
+ fetch(fullUrl).then((aRequest) => {
102
+ return aRequest.json();
103
+ }).then((aData) => {
104
+ this._setupItemResponseBound(item, aData);
105
+ });
106
+
107
+ return item;
108
+ }
109
+
110
+ }
@@ -0,0 +1,30 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class ApiRequest extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ }
8
+
9
+ get processPromise() {
10
+ if(this.item.status === Dbm.loading.LoadingStatus.LOADED) {
11
+ return Promise.resolve(this.item);
12
+ }
13
+ if(this.item.status === Dbm.loading.LoadingStatus.LOADING || this.item.status === Dbm.loading.LoadingStatus.NOT_STARTED) {
14
+ if(!this.item.processPromise) {
15
+ let resolveCommand = Dbm.commands.resolvePromise(this.item);
16
+ this.item.setValue("doneCommands", [resolveCommand]);
17
+ let rejectCommand = Dbm.commands.callFunction(resolveCommand.item.reject, []);
18
+ this.item.setValue("errorCommands", [rejectCommand]);
19
+
20
+ //METODO: change these to addToArray
21
+
22
+ this.item.setValue("processPromise", resolveCommand.item.promise);
23
+ }
24
+
25
+ return this.item.processPromise;
26
+ }
27
+
28
+ return Promise.reject();
29
+ }
30
+ }
@@ -0,0 +1,61 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class GraphApi extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ this._websocketConnection = null;
8
+ this._apiConnection = null;
9
+ }
10
+
11
+ setWebsocketConnection(aConnection) {
12
+ this._websocketConnection = aConnection;
13
+
14
+ return this;
15
+ }
16
+
17
+ setApiConnection(aConnection) {
18
+ this._apiConnection = aConnection;
19
+
20
+ return this;
21
+ }
22
+
23
+ requestRange(aSelect, aEncode) {
24
+ return this._websocketConnection.requestRange(aSelect, aEncode);
25
+ }
26
+
27
+ requestItem(aId, aEncode) {
28
+ return this._websocketConnection.requestItem(aId, aEncode);
29
+ }
30
+
31
+ requestData(aFunctionName, aData) {
32
+ return this._websocketConnection.requestData(aFunctionName, aData);
33
+ }
34
+
35
+ createItem(aTypes, aVisibility = "draft", aChanges = [], aEncode = []) {
36
+ return this._websocketConnection.createItem(aTypes, aVisibility, aChanges, aEncode);
37
+ }
38
+
39
+ editItem(aId, aChanges, aEncode = []) {
40
+ return this._websocketConnection.editItem(aId, aChanges, aEncode);
41
+ }
42
+
43
+ requestUrl(aUrl) {
44
+ //console.log("requestUrl");
45
+ //console.log(aUrl);
46
+
47
+ if(this._websocketConnection && this._websocketConnection.item.status === 1) {
48
+ return this._websocketConnection.requestUrl(aUrl);
49
+ }
50
+
51
+ return this._apiConnection.requestUrl(aUrl);
52
+ }
53
+
54
+ signIn(aToken) {
55
+ return this._websocketConnection.signIn(aToken);
56
+ }
57
+
58
+ signOut() {
59
+ return this._websocketConnection.signOut();
60
+ }
61
+ }
@@ -60,7 +60,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
60
60
  }
61
61
 
62
62
  requestData(aFunctionName, aData) {
63
- console.log("requestData");
63
+ //console.log("requestData");
64
64
  let item = this._getRequestItem();
65
65
  item.setValue("requestData", {"type": "data", "functionName": aFunctionName, "data": aData, "requestId": item.id});
66
66
  this._runRequest(item);
@@ -85,6 +85,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
85
85
  }
86
86
 
87
87
  requestUrl(aUrl) {
88
+
88
89
  let item = this._getRequestItem();
89
90
  item.setValue("requestData", {"type": "url", "url": aUrl, "requestId": item.id});
90
91
  this._runRequest(item);
@@ -47,6 +47,14 @@ let fullSetup = function() {
47
47
  currentDecoder.item.register(decodePrefix + name);
48
48
  }
49
49
 
50
+ {
51
+ let name = "url";
52
+ let currentDecoder = new Dbm.graphapi.webclient.decode.DecodeBaseObject();
53
+ currentDecoder.item.setValue("copyFields", ["url"]);
54
+ currentDecoder.item.setValue("encodingType", name);
55
+ currentDecoder.item.register(decodePrefix + name);
56
+ }
57
+
50
58
  {
51
59
  let name = "urlRequest";
52
60
  let currentDecoder = new Dbm.graphapi.webclient.decode.DecodeBaseObject();
@@ -1,4 +1,7 @@
1
1
  export {default as WebSocketConnection} from "./WebSocketConnection.js";
2
2
  export {default as WebSocketRequest} from "./WebSocketRequest.js";
3
+ export {default as GraphApi} from "./GraphApi.js";
4
+ export {default as ApiConnection} from "./ApiConnection.js";
5
+ export {default as ApiRequest} from "./ApiRequest.js";
3
6
 
4
7
  export * as decode from "./decode/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbm",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {},
@@ -60,6 +60,15 @@ export default class BaseObject extends Component {
60
60
  return this._dynamicProps[aName];
61
61
  }
62
62
 
63
+ getDynamicPropWithoutState(aName, aInitialValue = null) {
64
+ if(!this._dynamicProps[aName]) {
65
+ let newProperty = new Dbm.flow.FlowProperty();
66
+ newProperty.value = aInitialValue;
67
+ this._dynamicProps[aName] = newProperty;
68
+ }
69
+ return this._dynamicProps[aName];
70
+ }
71
+
63
72
  get item() {
64
73
  if(!this._item) {
65
74
  this._item = new Dbm.repository.Item();
@@ -0,0 +1,119 @@
1
+ import React from "react";
2
+ import Dbm from "../../index.js";
3
+
4
+ export default class CreatePage extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.item.requireProperty("title", "");
9
+ this.item.requireProperty("url", "");
10
+ this.item.requireProperty("freeUrl", "");
11
+ this.item.requireProperty("updateSlugFromTitle", true);
12
+
13
+ this._titleFieldId = "dbmField" + Dbm.getInstance().getNextId();
14
+ this._urlFieldId = "dbmField" + Dbm.getInstance().getNextId();
15
+
16
+ Dbm.flow.addUpdateCommand(this.item.properties.title, Dbm.commands.callFunction(this._titleChanged.bind(this)));
17
+ Dbm.flow.addUpdateCommand(this.item.properties.url, Dbm.commands.callFunction(this._urlChanged.bind(this)));
18
+ }
19
+
20
+ _titleChanged() {
21
+ console.log("_titleChanged");
22
+ console.log(this.item.updateSlugFromTitle);
23
+
24
+ if(this.item.updateSlugFromTitle) {
25
+ this.item.url = Dbm.utils.StringFunctions.createNiceFilePath(this.item.title);
26
+ }
27
+
28
+ }
29
+
30
+ _urlChanged() {
31
+ console.log("_urlChanged");
32
+
33
+ let currentUrl = this.item.url;
34
+
35
+ if(currentUrl !== "") {
36
+ let request = Dbm.getInstance().repository.getItem("graphApi").controller.requestData("admin/freeUrl", {"url": "/" + currentUrl});
37
+
38
+ Dbm.flow.addUpdateCommand(request.properties.status, Dbm.commands.callFunction(this._freeUrlStatusChanged.bind(this), [currentUrl, request]));
39
+ }
40
+ else {
41
+ currentUrl = Dbm.utils.StringFunctions.createNiceFilePath(this.item.title);
42
+ let request = Dbm.getInstance().repository.getItem("graphApi").controller.requestData("admin/freeUrl", {"url": "/" + currentUrl});
43
+
44
+ Dbm.flow.addUpdateCommand(request.properties.status, Dbm.commands.callFunction(this._freeUrlStatusChanged.bind(this), [currentUrl, request]));
45
+
46
+ this.item.updateSlugFromTitle = true;
47
+ }
48
+ }
49
+
50
+ _freeUrlStatusChanged(aUrl, aRequest) {
51
+ console.log("_freeUrlStatusChanged");
52
+ if(aRequest.status === 1) {
53
+ let currentUrl = this.item.url;
54
+ if(!currentUrl) {
55
+ currentUrl = Dbm.utils.StringFunctions.createNiceFilePath(this.item.title);
56
+ this.item.url = currentUrl;
57
+ }
58
+ if(currentUrl === aUrl) {
59
+ this.item.freeUrl = aRequest.data.url;
60
+ }
61
+ }
62
+ }
63
+
64
+ _callback_urlUpdatedManually(aEvent) {
65
+ this.item.updateSlugFromTitle = false;
66
+ }
67
+
68
+ _create() {
69
+ console.log("_create");
70
+
71
+ let fullUrl = this.item.freeUrl + "/";
72
+
73
+ let changes = [
74
+ {"type": "setField", "data": {"value": this.item.title, "field": "title"}},
75
+ {"type": "setUrl", "data": {"value": fullUrl}}
76
+ ]
77
+
78
+ let request = Dbm.getInstance().repository.getItem("graphApi").controller.createItem(["page"], "public", changes);
79
+
80
+ Dbm.flow.addUpdateCommand(request.properties.status, Dbm.commands.callFunction(this._pageCreated.bind(this), [fullUrl]));
81
+ }
82
+
83
+ _pageCreated(aUrl) {
84
+ Dbm.getInstance().repository.getItem("siteNavigation").controller.navigate(aUrl);
85
+ }
86
+
87
+ _renderMainElement() {
88
+
89
+ let domain = document.location.protocol + "//" + document.location.host;
90
+
91
+ return React.createElement("div", {},
92
+ React.createElement("div", {},
93
+ React.createElement("label", {className: "standard-field-label"},
94
+ "Page title"
95
+ ),
96
+ React.createElement(Dbm.react.form.FormField, {"value": this.item.properties.title, "id": this._titleFieldId, className: "standard-field standard-field-padding full-width"}),
97
+ ),
98
+ React.createElement("div", {className: "spacing standard"}),
99
+ React.createElement("div", {},
100
+ React.createElement("label", {className: "standard-field-label"},
101
+ "Url"
102
+ ),
103
+ React.createElement(Dbm.react.form.FormField, {"value": this.item.properties.url, "id": this._urlFieldId, onFocus: this._callback_urlUpdatedManually.bind(this), className: "standard-field standard-field-padding full-width"}),
104
+ ),
105
+ React.createElement("div", {className: "spacing micro"}),
106
+ React.createElement("div", {"className": "small-description"},
107
+ Dbm.react.text.text(domain),
108
+ Dbm.react.text.text(this.item.properties.freeUrl),
109
+ ),
110
+ React.createElement("div", {className: "spacing standard"}),
111
+ React.createElement("div", {className: "flex-row justify-center"},
112
+ React.createElement("div", {"className": "standard-button standard-button-padding", "onClick": () => {this._create()}},
113
+ "Create"
114
+ )
115
+ )
116
+ );
117
+ }
118
+ }
119
+
@@ -0,0 +1,78 @@
1
+ import React from "react";
2
+ import Dbm from "../../index.js";
3
+
4
+ export default class EditPage extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+
8
+ let page = this.context.page;
9
+
10
+ this.item.setValue("title", page.title);
11
+ this.item.setValue("content", page.content);
12
+ this.item.setValue("description", page["meta/description"]);
13
+ this.item.setValue("url", page.url);
14
+
15
+ //METODO: add editors
16
+ }
17
+
18
+ _save() {
19
+ console.log("_save");
20
+
21
+ let page = this.context.page;
22
+ let id = page.id;
23
+ let graphApi = Dbm.getInstance().repository.getItem("graphApi").controller;
24
+
25
+ graphApi.editItem(id, [
26
+ {"type": "setField", "data": {"value": this.item.content, "field": "content"}},
27
+ {"type": "setField", "data": {"value": this.item.title, "field": "title"}},
28
+ {"type": "setField", "data": {"value": this.item.description, "field": "meta/description"}},
29
+ {"type": "setUrl", "data": {"value": this.item.url}}
30
+ ], ["content", "title", "url", "meta/description"]);
31
+ }
32
+
33
+ _renderMainElement() {
34
+
35
+ return React.createElement("div", {},
36
+ React.createElement("div", {"className": "dbm-admin-box dbm-admin-box-padding"},
37
+ React.createElement("div", {},
38
+ React.createElement("label", {className: "standard-field-label"},
39
+ "Page title"
40
+ ),
41
+ 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"}),
42
+ ),
43
+ React.createElement("div", {className: "spacing standard"}),
44
+ React.createElement("div", {},
45
+ React.createElement("label", {className: "standard-field-label"},
46
+ "Url"
47
+ ),
48
+ React.createElement(Dbm.react.form.FormField, {"value": this.item.properties.url, className: "standard-field standard-field-padding full-width", placeholder: "Url"}),
49
+ ),
50
+ ),
51
+ React.createElement("div", {className: "spacing standard"}),
52
+ React.createElement("div", {"className": "dbm-admin-box dbm-admin-box-padding"},
53
+ React.createElement("label", {className: "standard-field-label"},
54
+ "Seo description"
55
+ ),
56
+ React.createElement(Dbm.react.form.FormField, {"value": this.item.properties.description, className: "standard-field standard-field-padding full-width", placeholder: "Description"}),
57
+ ),
58
+ React.createElement("div", {className: "spacing standard"}),
59
+ React.createElement("div", {"className": "dbm-admin-box dbm-admin-box-padding"},
60
+ React.createElement("label", {className: "standard-field-label"},
61
+ "Content"
62
+ ),
63
+ React.createElement("div", {},
64
+ React.createElement(Dbm.react.admin.Editor, {"value": this.item.properties.content}),
65
+ )
66
+ ),
67
+ React.createElement("div", {className: "spacing standard"}),
68
+ React.createElement("div", {className: "flex-row justify-center"},
69
+ React.createElement("div", {className: "flex-row-item"},
70
+ React.createElement("div", {"className": "standard-button standard-button-padding", "onClick": () => {this._save()}},
71
+ "Save"
72
+ )
73
+ )
74
+ )
75
+ );
76
+ }
77
+ }
78
+
@@ -7,21 +7,32 @@ export default class Editor extends Dbm.react.BaseObject {
7
7
  _construct() {
8
8
  super._construct();
9
9
 
10
- Dbm.loading.loadScript("https://cdn.jsdelivr.net/npm/@editorjs/image@latest");
11
- Dbm.loading.loadScript("https://cdn.jsdelivr.net/npm/@editorjs/header@latest");
12
- Dbm.loading.loadScript("https://cdn.jsdelivr.net/npm/@editorjs/image@latest");
10
+ let all = Dbm.flow.updatefunctions.logic.allAtValue(1);
11
+
12
+ all.addCheck(Dbm.loading.loadScript("https://cdn.jsdelivr.net/npm/@editorjs/image@latest").item.properties.status);
13
+ all.addCheck(Dbm.loading.loadScript("https://cdn.jsdelivr.net/npm/@editorjs/header@latest").item.properties.status);
14
+ all.addCheck(Dbm.loading.loadScript("https://cdn.jsdelivr.net/npm/@editorjs/image@latest").item.properties.status);
15
+ all.addCheck(Dbm.loading.loadScript("https://cdn.jsdelivr.net/npm/@editorjs/list@latest").item.properties.status);
16
+ all.addCheck(Dbm.loading.loadScript("https://cdn.jsdelivr.net/npm/@editorjs/raw@latest").item.properties.status);
17
+
18
+
13
19
  //METODO: select which tools should be used
14
20
 
15
- let scriptLoader = Dbm.loading.loadScript("https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest");
21
+ all.addCheck(Dbm.loading.loadScript("https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest").item.properties.status);
16
22
 
17
23
  this.item.setValue("element", document.createElement("div"));
18
24
 
19
25
  let updateFunction = new Dbm.flow.updatefunctions.basic.RunCommand();
20
26
 
21
- updateFunction.input.command = Dbm.commands.callFunction(this._scriptStatus.bind(this), [scriptLoader]);
27
+ updateFunction.input.command = Dbm.commands.callFunction(this._scriptStatus.bind(this), [all]);
22
28
 
23
29
  updateFunction.output.properties.value.startUpdating();
24
- updateFunction.input.properties.value.connectInput(scriptLoader.item.properties.status);
30
+ updateFunction.input.properties.value.connectInput(all.output.properties.value);
31
+
32
+ this.getDynamicPropWithoutState("value", {});
33
+
34
+ this._callback_saveDataUpdatedBound = this._callback_saveDataUpdated.bind(this);
35
+ this._callback_editorChangeBound = this._callback_editorChange.bind(this);
25
36
  }
26
37
 
27
38
  uploadImage(aFile) {
@@ -58,16 +69,27 @@ export default class Editor extends Dbm.react.BaseObject {
58
69
  }
59
70
  }
60
71
 
72
+ _callback_saveDataUpdated(aData) {
73
+ console.log("_callback_saveDataUpdated");
74
+ console.log(aData);
75
+
76
+ this.getDynamicProp("value").getMostUpstreamProperty().setValue(aData);
77
+ }
78
+
79
+ _callback_editorChange(aApi, aEvent) {
80
+ this.item.editor.save().then(this._callback_saveDataUpdatedBound);
81
+ }
82
+
61
83
  _scriptStatus(aLoader) {
62
84
  //console.log("_scriptStatus");
63
85
  //console.log(aLoader);
64
86
 
65
- if(aLoader.item.status === 1) {
87
+ if(aLoader.output.value) {
66
88
 
67
89
  let element = this.item.element;
68
90
  element.classList.add("full-size");
69
91
 
70
- let content = Dbm.getInstance().repository.getItem("siteDataLoader").currentPage.page.content;
92
+ let content = this.getDynamicProp("value").value;
71
93
 
72
94
  let tools = {
73
95
  image: window.ImageTool,
@@ -84,26 +106,36 @@ export default class Editor extends Dbm.react.BaseObject {
84
106
  }
85
107
  }
86
108
  }
87
- }
109
+ },
110
+ list: {
111
+ class: window.EditorjsList,
112
+ inlineToolbar: true,
113
+ config: {
114
+ defaultStyle: 'unordered'
115
+ },
116
+ },
117
+ raw: window.RawTool
88
118
  };
89
119
 
90
120
 
91
121
  let editorConfigItem = Dbm.getInstance().repository.getItem("editorjs");
92
122
  let toolsFromConfig = editorConfigItem.tools;
93
123
 
94
- tools = {...tools, ...toolsFromConfig}
124
+ tools = {...tools, ...toolsFromConfig};
95
125
 
96
126
  const editor = new window.EditorJS({
97
127
  minHeight: 0,
98
128
  holder: element,
99
129
  tools: tools,
100
- data: content
130
+ data: content,
131
+ onChange: this._callback_editorChangeBound
101
132
  });
102
133
 
103
134
  this.item.setValue("editor", editor);
104
135
  }
105
136
  }
106
137
 
138
+ /*
107
139
  _save() {
108
140
  this.item.editor.save().then((aOutputData) => {
109
141
  console.log('Article data: ', aOutputData);
@@ -119,6 +151,7 @@ export default class Editor extends Dbm.react.BaseObject {
119
151
  console.log('Saving failed: ', error)
120
152
  });
121
153
  }
154
+ */
122
155
 
123
156
  componentDidMount() {
124
157
  //console.log("componentDidMount");
@@ -135,19 +168,8 @@ export default class Editor extends Dbm.react.BaseObject {
135
168
  _renderMainElement() {
136
169
 
137
170
  return React.createElement("div", {style: {"position": "relative", "zIndex": 0}},
138
- React.createElement("div", {"ref": this.createRef("holder")}),
139
- React.createElement("div", {"className": "standard-button standard-button-padding", "onClick": () => {this._save()}},
140
- "Save"
141
- )
171
+ React.createElement("div", {"ref": this.createRef("holder")})
142
172
  );
143
- /*
144
- return <div>
145
- <div ref={this.createRef("holder")} />
146
- <div className="standard-button standard-button-padding" onClick={() => {this._save()}}>
147
- Save
148
- </div>
149
- </div>;
150
- */
151
173
  }
152
174
  }
153
175
 
@@ -1,3 +1,5 @@
1
1
  export {default as Editor} from "./Editor.js";
2
2
  export {default as EditorBlock} from "./EditorBlock.js";
3
- export {default as EditorBlockName} from "./EditorBlockName.js";
3
+ export {default as EditorBlockName} from "./EditorBlockName.js";
4
+ export {default as CreatePage} from "./CreatePage.js";
5
+ export {default as EditPage} from "./EditPage.js";
@@ -10,6 +10,7 @@ let createToolConfiguration = function(aId, aName, aInitialData = {}, aIcon = nu
10
10
  "name": aName,
11
11
  },
12
12
  "data": aInitialData,
13
+ "inlineToolbar": true,
13
14
  "toolbox": {
14
15
  title: aName,
15
16
  icon: aIcon
@@ -57,5 +58,32 @@ export let registerAllBlocks = function() {
57
58
  tools[moduleName] = createToolConfiguration(moduleName, "Login form");
58
59
  }
59
60
 
61
+ {
62
+ let moduleName = "test/test";
63
+
64
+ let displayNameModule = new Dbm.react.modules.ModuleCreator();
65
+
66
+ let displayNameEditor = createElement("div", {},
67
+ createElement("div", {contentEditable: true}, "test"),
68
+ createElement("input", {})
69
+ );
70
+ displayNameModule.setMainElement(displayNameEditor);
71
+
72
+ let editorItem = new Dbm.repository.Item();
73
+ editorItem.setValue("controller", displayNameModule);
74
+ editorItem.register("moduleCreators/blocks/editor/" + moduleName);
75
+
76
+ let elementItem = new Dbm.repository.Item();
77
+ elementItem.setValue("element",
78
+ createElement("div", {},
79
+ createElement("div", {contentEditable: true}, "test"),
80
+ createElement("input", {})
81
+ )
82
+ );
83
+ elementItem.register("blocks/" + moduleName);
84
+
85
+ tools[moduleName] = createToolConfiguration(moduleName, "Test");
86
+ }
87
+
60
88
  editorConfigItem.setValue("tools", tools);
61
89
  }
@@ -5,6 +5,7 @@ export default class FormField extends Dbm.react.BaseObject {
5
5
  super._construct();
6
6
 
7
7
  this.getDynamicProp("value", "");
8
+ this.state["formUpdate"] = 0;
8
9
 
9
10
  this._callback_changeBound = this._callback_change.bind(this);
10
11
  }
@@ -16,6 +17,7 @@ export default class FormField extends Dbm.react.BaseObject {
16
17
  let value = aEvent.target.value;
17
18
 
18
19
  this.getDynamicProp("value").getMostUpstreamProperty().setValue(value);
20
+ this.setState({"formUpdate": this.state.formUpdate}); //MENOTE: trigger change direct to not lose focus on input
19
21
  }
20
22
 
21
23
  _renderMainElement() {
@@ -90,18 +90,18 @@ export default class LoginForm extends Dbm.react.BaseObject {
90
90
  return this._createMainElement("div", {},
91
91
  React.createElement("div", {className: "body-text"},
92
92
  React.createElement("div", {"className": ""},
93
- React.createElement("label", {className: ""},
93
+ React.createElement("label", {className: "standard-field-label"},
94
94
  "Email"
95
95
  )
96
96
  ),
97
- React.createElement(Dbm.react.form.FormField, {value: this.item.properties.username}),
97
+ React.createElement(Dbm.react.form.FormField, {value: this.item.properties.username, className: "standard-field standard-field-padding full-width"}),
98
98
  React.createElement("div", {"className": "spacing standard"}),
99
99
  React.createElement("div", {"className": ""},
100
- React.createElement("label", {className: ""},
100
+ React.createElement("label", {className: "standard-field-label"},
101
101
  "Password"
102
102
  )
103
103
  ),
104
- React.createElement(Dbm.react.form.FormField, {type: "password", value: this.item.properties.password})
104
+ React.createElement(Dbm.react.form.FormField, {type: "password", value: this.item.properties.password, className: "standard-field standard-field-padding full-width"})
105
105
  ),
106
106
  React.createElement("div", {"className": "spacing standard"}),
107
107
  React.createElement("div", {"className": "flex-row justify-center"},
package/startup/index.js CHANGED
@@ -3,13 +3,13 @@ import Dbm from "../index.js";
3
3
  export {default as Runner} from "./Runner.js";
4
4
  export {default as Controller} from "./Controller.js";
5
5
 
6
- export let runStartup = function() {
7
- if(!window.dbmstartup.modules.isSetup) {
6
+ export let runStartup = function(aGlobalScope = "dbmstartup", aModulesName = "modules") {
7
+ if(!window[aGlobalScope][aModulesName].isSetup) {
8
8
  let controller = new Dbm.startup.Controller();
9
9
 
10
- let currentArray = globalThis.dbmstartup.modules._;
10
+ let currentArray = globalThis[aGlobalScope][aModulesName]._;
11
11
 
12
- globalThis.dbmstartup.modules = controller;
12
+ globalThis[aGlobalScope][aModulesName] = controller;
13
13
 
14
14
  let currentArrayLength = currentArray.length;
15
15
  for(let i = 0; i < currentArrayLength; i++) {
@@ -1,20 +1,9 @@
1
+ export let range = function(aStartValue, aEndValue, aStep = 1) {
2
+ let returnArray = [];
1
3
 
2
- let range = function(aStartValue, aEndValue, aStep = 1) {
3
- let returnArray = [];
4
-
5
- return returnArray;
6
- }
4
+ return returnArray;
5
+ }
7
6
 
8
- export {range};
9
-
10
- let removeDuplicates = function(aArray) {
11
- return aArray;
12
- }
13
-
14
- export {removeDuplicates};
15
-
16
- let removeDuplicates2 = function(aArray) {
17
- return aArray;
18
- }
19
-
20
- export {removeDuplicates2};
7
+ export let removeDuplicates = function(aArray) {
8
+ return aArray;
9
+ }
@@ -0,0 +1,8 @@
1
+ export let floatMod = function(aValue, aDivisor) {
2
+
3
+ let times = Math.floor(aValue/aDivisor);
4
+
5
+ let returnValue = aValue-(times*aDivisor);
6
+
7
+ return returnValue;
8
+ }
@@ -0,0 +1,25 @@
1
+ export let createNiceFileName = function(aFileName) {
2
+ let fileName = aFileName.toLowerCase();
3
+
4
+ fileName = fileName.replace(/[åäã]/gi, 'a');
5
+ fileName = fileName.replace(/[ö]/gi, 'o');
6
+ fileName = fileName.replace(/ /gi, '-');
7
+ fileName = fileName.replace(/[\(\),\*']/gi, '');
8
+ fileName = fileName.replace(/[^a-z0-9\-_\.]/gi, '-');
9
+ fileName = fileName.replace(/\-+/gi, '-');
10
+
11
+ return fileName;
12
+ }
13
+
14
+ export let createNiceFilePath = function(aFileName) {
15
+ let fileName = aFileName.toLowerCase();
16
+
17
+ fileName = fileName.replace(/[åäã]/gi, 'a');
18
+ fileName = fileName.replace(/[ö]/gi, 'o');
19
+ fileName = fileName.replace(/ /gi, '-');
20
+ fileName = fileName.replace(/[\(\),\*']/gi, '');
21
+ fileName = fileName.replace(/[^a-z0-9\-_\.\/]/gi, '-');
22
+ fileName = fileName.replace(/\-+/gi, '-');
23
+
24
+ return fileName;
25
+ }
package/utils/index.js CHANGED
@@ -1 +1,3 @@
1
- export * as ArrayFunctions from "./ArrayFunctions.js";
1
+ export * as ArrayFunctions from "./ArrayFunctions.js";
2
+ export * as NumberFunctions from "./NumberFunctions.js";
3
+ export * as StringFunctions from "./StringFunctions.js";