dbm 1.0.2 → 1.0.4
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/WebSocketConnection.js +63 -6
- 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";
|
|
@@ -4,22 +4,39 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
4
4
|
_construct() {
|
|
5
5
|
super._construct();
|
|
6
6
|
|
|
7
|
+
this._url = null;
|
|
7
8
|
this._webSocket = null;
|
|
9
|
+
|
|
10
|
+
this._intervalId = -1;
|
|
8
11
|
this._callback_onOpenBound = this._callback_onOpen.bind(this);
|
|
9
12
|
this._callback_onMessageBound = this._callback_onMessage.bind(this);
|
|
13
|
+
this._callback_onMessageBound = this._callback_onMessage.bind(this);
|
|
14
|
+
this._callback_onCloseBound = this._callback_onClose.bind(this);
|
|
15
|
+
this._callback_onErrorBound = this._callback_onError.bind(this);
|
|
16
|
+
this._callback_sendHeartbeatBound = this._callback_sendHeartbeat.bind(this);
|
|
10
17
|
|
|
11
18
|
this.item.setValue("requests", []);
|
|
12
19
|
this.item.setValue("status", 0);
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
setup(aUrl) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this._webSocket.onopen = this._callback_onOpenBound;
|
|
20
|
-
this._webSocket.onmessage = this._callback_onMessageBound;
|
|
23
|
+
this._url = aUrl;
|
|
24
|
+
this._connect();
|
|
25
|
+
|
|
21
26
|
return this;
|
|
22
27
|
}
|
|
28
|
+
|
|
29
|
+
_connect() {
|
|
30
|
+
if(this.item.status === 0) {
|
|
31
|
+
this._webSocket = new WebSocket(this._url);
|
|
32
|
+
this.item.setValue("status", 2);
|
|
33
|
+
|
|
34
|
+
this._webSocket.onopen = this._callback_onOpenBound;
|
|
35
|
+
this._webSocket.onmessage = this._callback_onMessageBound;
|
|
36
|
+
this._webSocket.onclose = this._callback_onCloseBound;
|
|
37
|
+
this._webSocket.onerror = this._callback_onErrorBound;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
23
40
|
|
|
24
41
|
_getRequestItem() {
|
|
25
42
|
let requestId = "graphApi/webSocketRequest" + Dbm.getInstance().getNextId();
|
|
@@ -94,10 +111,47 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
94
111
|
}
|
|
95
112
|
|
|
96
113
|
_callback_onOpen(aEvent) {
|
|
97
|
-
|
|
114
|
+
console.log("_callback_onOpen");
|
|
115
|
+
|
|
116
|
+
if(this._intervalId === -1) {
|
|
117
|
+
this._intervalId = setInterval(this._callback_sendHeartbeatBound, 20*1000);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
_callback_onClose(aEvent) {
|
|
122
|
+
console.log("_callback_onClose");
|
|
123
|
+
console.log(aEvent);
|
|
124
|
+
|
|
125
|
+
if(this._intervalId !== -1) {
|
|
126
|
+
clearInterval(this._intervalId);
|
|
127
|
+
this._intervalId = -1;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if(this._webSocket) {
|
|
131
|
+
this._webSocket.onopen = null;
|
|
132
|
+
this._webSocket.onmessage = null;
|
|
133
|
+
this._webSocket.onclose = null;
|
|
134
|
+
this._webSocket.onerror = null;
|
|
135
|
+
|
|
136
|
+
this._webSocket = null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
this.item.setValue("status", 0);
|
|
140
|
+
this._connect();;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
_callback_onError(aEvent) {
|
|
144
|
+
console.log("_callback_onError");
|
|
145
|
+
console.log(aEvent);
|
|
98
146
|
|
|
99
147
|
//MENOTE: do nothing
|
|
100
148
|
}
|
|
149
|
+
|
|
150
|
+
_callback_sendHeartbeat() {
|
|
151
|
+
console.log("_callback_sendHeartbeat");
|
|
152
|
+
|
|
153
|
+
this._webSocket.send(JSON.stringify({"type": "heartbeat"}));
|
|
154
|
+
}
|
|
101
155
|
|
|
102
156
|
_connectionReady() {
|
|
103
157
|
this.item.setValue("status", 1);
|
|
@@ -213,6 +267,9 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
213
267
|
this._connectionReady();
|
|
214
268
|
}
|
|
215
269
|
break;
|
|
270
|
+
case "heartbeat/response":
|
|
271
|
+
//MENOTE: do nothing
|
|
272
|
+
break;
|
|
216
273
|
default:
|
|
217
274
|
console.warn("Unknown message type " + data.type);
|
|
218
275
|
break;
|
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