dbm 1.0.1 → 1.0.3
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/flow/updatefunctions/dom/ElementPosition.js +89 -0
- package/flow/updatefunctions/dom/index.js +2 -1
- package/graphapi/webclient/ApiConnection.js +110 -0
- package/graphapi/webclient/ApiRequest.js +30 -0
- package/graphapi/webclient/GraphApi.js +61 -0
- package/graphapi/webclient/WebSocketConnection.js +2 -1
- package/graphapi/webclient/index.js +3 -0
- package/package.json +1 -1
- package/react/BaseObject.js +1 -1
- package/react/admin/EditPage.js +1 -0
- package/react/area/ScrollActivatedArea.js +44 -0
- package/react/area/index.js +2 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import Dbm from "../../../index.js";
|
|
2
|
+
|
|
3
|
+
export default class ElementPosition extends Dbm.flow.FlowUpdateFunction {
|
|
4
|
+
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
this.input.register("element", null);
|
|
9
|
+
this.input.register("prepareX", 0);
|
|
10
|
+
this.input.register("prepareY", 0);
|
|
11
|
+
|
|
12
|
+
this.output.register("screenX", NaN);
|
|
13
|
+
this.output.register("screenY", NaN);
|
|
14
|
+
|
|
15
|
+
this.output.register("parameterX", NaN);
|
|
16
|
+
this.output.register("parameterY", NaN);
|
|
17
|
+
|
|
18
|
+
this.output.register("visible", false);
|
|
19
|
+
this.output.register("prepare", false);
|
|
20
|
+
|
|
21
|
+
this._callback_scrollBound = this._callback_scroll.bind(this);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
start() {
|
|
25
|
+
window.addEventListener("resize", this._callback_scrollBound, false);
|
|
26
|
+
window.addEventListener("scroll", this._callback_scrollBound, false);
|
|
27
|
+
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
_update() {
|
|
32
|
+
//console.log("_update");
|
|
33
|
+
|
|
34
|
+
let element = this.input.element;
|
|
35
|
+
|
|
36
|
+
if(element) {
|
|
37
|
+
console.log(element);
|
|
38
|
+
//this.output.width = element.clientWidth;
|
|
39
|
+
//this.output.height = element.clientHeight;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
//this.output.width = 0;
|
|
43
|
+
//this.output.height = 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
_callback_scroll(aEvent) {
|
|
48
|
+
console.log("_callback_scroll");
|
|
49
|
+
|
|
50
|
+
let element = this.input.element;
|
|
51
|
+
|
|
52
|
+
if(element) {
|
|
53
|
+
|
|
54
|
+
//let thePageXOffset = window.pageXOffset;
|
|
55
|
+
let theInnerWidth = window.innerWidth;
|
|
56
|
+
//let thePageYOffset = window.pageYOffset;
|
|
57
|
+
let theInnerHeight = window.innerHeight;
|
|
58
|
+
|
|
59
|
+
//console.log(theInnerWidth, theInnerHeight);
|
|
60
|
+
|
|
61
|
+
let rect = element.getBoundingClientRect();
|
|
62
|
+
//console.log(rect);
|
|
63
|
+
|
|
64
|
+
let prepareX = this.input.prepareX;
|
|
65
|
+
let prepareY = this.input.prepareY;
|
|
66
|
+
|
|
67
|
+
let screenX = rect.x;
|
|
68
|
+
let screenY = rect.y;
|
|
69
|
+
|
|
70
|
+
let elementWidth = rect.width;
|
|
71
|
+
let elementHeight = rect.height;
|
|
72
|
+
|
|
73
|
+
let visible = ((screenX < theInnerWidth) && (screenX+elementWidth > 0)) && ((screenY < theInnerHeight) && (screenY+elementHeight > 0));
|
|
74
|
+
let prepare = ((screenX-prepareX < theInnerWidth) && (screenX+elementWidth+prepareX > 0)) && ((screenY-prepareY < theInnerHeight) && (screenY+elementHeight+prepareY > 0));
|
|
75
|
+
|
|
76
|
+
let parameterX = (screenX+elementWidth)/(theInnerWidth+elementWidth);
|
|
77
|
+
let parameterY = (screenY+elementHeight)/(theInnerHeight+elementHeight);
|
|
78
|
+
|
|
79
|
+
this.output.properties.screenX._internal_setValueInFlowOutsideOfUpdate(screenX);
|
|
80
|
+
this.output.properties.screenY._internal_setValueInFlowOutsideOfUpdate(screenY);
|
|
81
|
+
|
|
82
|
+
this.output.properties.parameterX._internal_setValueInFlowOutsideOfUpdate(parameterX);
|
|
83
|
+
this.output.properties.parameterY._internal_setValueInFlowOutsideOfUpdate(parameterY);
|
|
84
|
+
|
|
85
|
+
this.output.properties.visible._internal_setValueInFlowOutsideOfUpdate(visible);
|
|
86
|
+
this.output.properties.prepare._internal_setValueInFlowOutsideOfUpdate(prepare);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export {default as ElementSize} from "./ElementSize.js";
|
|
2
2
|
export {default as StyleObject} from "./StyleObject.js";
|
|
3
|
-
export {default as HorizontalFlip} from "./HorizontalFlip.js";
|
|
3
|
+
export {default as HorizontalFlip} from "./HorizontalFlip.js";
|
|
4
|
+
export {default as ElementPosition} from "./ElementPosition.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);
|
|
@@ -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
package/react/BaseObject.js
CHANGED
package/react/admin/EditPage.js
CHANGED
|
@@ -26,6 +26,7 @@ export default class EditPage extends Dbm.react.BaseObject {
|
|
|
26
26
|
{"type": "setField", "data": {"value": this.item.content, "field": "content"}},
|
|
27
27
|
{"type": "setField", "data": {"value": this.item.title, "field": "title"}},
|
|
28
28
|
{"type": "setField", "data": {"value": this.item.description, "field": "meta/description"}},
|
|
29
|
+
{"type": "setField", "data": {"value": (new Date()).toISOString(), "field": "lastModified"}},
|
|
29
30
|
{"type": "setUrl", "data": {"value": this.item.url}}
|
|
30
31
|
], ["content", "title", "url", "meta/description"]);
|
|
31
32
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Dbm from "../../index.js";
|
|
3
|
+
|
|
4
|
+
export default class ScrollActivatedArea extends Dbm.react.BaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
let elementProperty = this.item.requireProperty("element", null);
|
|
9
|
+
this.item.requireProperty("activated", false);
|
|
10
|
+
|
|
11
|
+
let position = new Dbm.flow.updatefunctions.dom.ElementPosition();
|
|
12
|
+
this.item.setValue("position", position);
|
|
13
|
+
position.input.properties.element.connectInput(elementProperty);
|
|
14
|
+
|
|
15
|
+
let prepareProperty = this.item.requireProperty("prepare", 100);
|
|
16
|
+
position.input.properties.prepareY.connectInput(prepareProperty);
|
|
17
|
+
|
|
18
|
+
position.start();
|
|
19
|
+
|
|
20
|
+
Dbm.flow.addUpdateCommand(position.output.properties.prepare, Dbm.commands.callFunction(this._prepareChanged.bind(this)));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
_prepareChanged() {
|
|
24
|
+
//console.log("_prepareChanged");
|
|
25
|
+
|
|
26
|
+
if(this.item.position.output.prepare) {
|
|
27
|
+
this.item.setValue("activated", true);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
_renderMainElement() {
|
|
32
|
+
//console.log("ScrollActivatedArea::render");
|
|
33
|
+
//console.log(this);
|
|
34
|
+
|
|
35
|
+
return this._createMainElement("div", {"ref": this.createRef("element")},
|
|
36
|
+
React.createElement(Dbm.react.area.HasData, {"check": this.item.properties.activated},
|
|
37
|
+
this.getPropValue("children")
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
package/react/area/index.js
CHANGED