dbm 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/flow/controllers/index.js +1 -0
- package/flow/controllers/select/SingleSelection.js +65 -0
- package/flow/controllers/select/index.js +1 -0
- package/flow/index.js +1 -0
- package/flow/updatefunctions/basic/Length.js +20 -0
- package/flow/updatefunctions/basic/PropertyOf.js +21 -0
- package/flow/updatefunctions/basic/index.js +17 -0
- package/flow/updatefunctions/logic/Condition.js +12 -1
- package/flow/updatefunctions/logic/Invert.js +18 -0
- package/flow/updatefunctions/logic/index.js +8 -0
- package/graphapi/webclient/GraphApi.js +4 -0
- package/graphapi/webclient/WebSocketConnection.js +10 -0
- package/package.json +1 -1
- package/react/admin/EditPage.js +31 -2
- package/react/admin/editor/fields/ImageField.js +1 -1
- package/react/area/OpenCloseExpandableArea.js +10 -3
- package/react/form/FileDropArea.js +92 -0
- package/react/form/index.js +2 -1
- package/react/image/LocalImage.js +42 -0
- package/react/image/index.js +2 -1
- package/react/index.js +1 -1
- package/react/interaction/CommandButton.js +97 -0
- package/react/interaction/index.js +3 -0
- package/utils/ArrayFunctions.js +72 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as select from "./select/index.js";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import Dbm from "../../../index.js";
|
|
2
|
+
|
|
3
|
+
export default class SingleSelection extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
|
|
7
|
+
let valueUpdatedCommand = Dbm.commands.callFunction(this._valueUpdated.bind(this));
|
|
8
|
+
|
|
9
|
+
this._selectionChangedBound = this._selectionChanged.bind(this);
|
|
10
|
+
|
|
11
|
+
Dbm.flow.addUpdateCommand(this.item.requireProperty("value", null), valueUpdatedCommand);
|
|
12
|
+
Dbm.flow.addUpdateCommand(this.item.requireProperty("selections", []), valueUpdatedCommand);
|
|
13
|
+
|
|
14
|
+
this.item.requireProperty("matched", false);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
addSelectionValue(aValue) {
|
|
18
|
+
let selections = [].concat(this.item.selections);
|
|
19
|
+
|
|
20
|
+
let property = new Dbm.flow.FlowProperty();
|
|
21
|
+
property.setValue(false);
|
|
22
|
+
Dbm.flow.addUpdateCommand(property, Dbm.commands.callFunction(this._selectionChangedBound, [property, aValue]));
|
|
23
|
+
|
|
24
|
+
selections.push({"value": aValue, "property": property});
|
|
25
|
+
this.item.selections = selections;
|
|
26
|
+
|
|
27
|
+
return property;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
_selectionChanged(aSelected, aValue) {
|
|
31
|
+
//console.log("_selectionChanged");
|
|
32
|
+
//console.log(aSelected, aValue);
|
|
33
|
+
|
|
34
|
+
if(aSelected) {
|
|
35
|
+
this.item.properties.value.getMostUpstreamProperty().setValue(aValue);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if(this.item.properties.value === aValue) {
|
|
39
|
+
this.item.properties.value.getMostUpstreamProperty().setValue(null);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_valueUpdated() {
|
|
45
|
+
//console.log("_valueUpdated");
|
|
46
|
+
let value = this.item.value;
|
|
47
|
+
|
|
48
|
+
let matched = false;
|
|
49
|
+
|
|
50
|
+
let currentArray = this.item.selections;
|
|
51
|
+
let currentArrayLength = currentArray.length;
|
|
52
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
53
|
+
let currentSelection = currentArray[i];
|
|
54
|
+
if(currentSelection.value === value) {
|
|
55
|
+
currentSelection.property.value = true;
|
|
56
|
+
matched = true;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
currentSelection.property.value = false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.item.matched = matched;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {default as SingleSelection} from "./SingleSelection.js";
|
package/flow/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export {default as DirtyCommands} from "./DirtyCommands.js";
|
|
|
9
9
|
export {default as FlowPropertyWithExternalInput} from "./FlowPropertyWithExternalInput.js";
|
|
10
10
|
|
|
11
11
|
export * as updatefunctions from "./updatefunctions/index.js";
|
|
12
|
+
export * as controllers from "./controllers/index.js";
|
|
12
13
|
|
|
13
14
|
export let addUpdateCommand = function(aProperty, aCommand) {
|
|
14
15
|
let updateFunction = new Dbm.flow.updatefunctions.basic.RunCommand();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Dbm from "../../../index.js";
|
|
2
|
+
|
|
3
|
+
export default class Length extends Dbm.flow.FlowUpdateFunction {
|
|
4
|
+
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
this.input.register("value", "");
|
|
9
|
+
|
|
10
|
+
this.output.register("length", 0);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
_update() {
|
|
14
|
+
//console.log("_update");
|
|
15
|
+
|
|
16
|
+
let value = this.input.value;
|
|
17
|
+
|
|
18
|
+
this.output.length = value ? value.length : 0;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Dbm from "../../../index.js";
|
|
2
|
+
|
|
3
|
+
export default class Length extends Dbm.flow.FlowUpdateFunction {
|
|
4
|
+
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
this.input.register("value", "");
|
|
9
|
+
this.input.register("propertyName", "");
|
|
10
|
+
|
|
11
|
+
this.output.register("value", null);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
_update() {
|
|
15
|
+
//console.log("_update");
|
|
16
|
+
|
|
17
|
+
let value = this.input.value;
|
|
18
|
+
|
|
19
|
+
this.output.value = Dbm.objectPath(value, this.input.propertyName);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -2,6 +2,8 @@ import Dbm from "../../../index.js";
|
|
|
2
2
|
|
|
3
3
|
export {default as RunCommand} from "./RunCommand.js";
|
|
4
4
|
export {default as CombineString} from "./CombineString.js";
|
|
5
|
+
export {default as Length} from "./Length.js";
|
|
6
|
+
export {default as PropertyOf} from "./PropertyOf.js";
|
|
5
7
|
|
|
6
8
|
export const runCommand = function(aValue, aCommand) {
|
|
7
9
|
let updateFunction = new Dbm.flow.updatefunctions.basic.RunCommand();
|
|
@@ -15,4 +17,19 @@ export const transformValue = function(aValue, aFunction) {
|
|
|
15
17
|
let command = Dbm.commands.callFunction(aFunction, [Dbm.core.source.event()]);
|
|
16
18
|
|
|
17
19
|
return Dbm.flow.updatefunctions.basic.runCommand(aValue, command);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const length = function(aValue) {
|
|
23
|
+
let updateFunction = new Dbm.flow.updatefunctions.basic.Length();
|
|
24
|
+
updateFunction.input.properties.value.setOrConnect(aValue);
|
|
25
|
+
|
|
26
|
+
return updateFunction;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const propertyOf = function(aValue, aPropertyName) {
|
|
30
|
+
let updateFunction = new Dbm.flow.updatefunctions.basic.PropertyOf();
|
|
31
|
+
updateFunction.input.properties.value.setOrConnect(aValue);
|
|
32
|
+
updateFunction.input.properties.propertyName.setOrConnect(aPropertyName);
|
|
33
|
+
|
|
34
|
+
return updateFunction;
|
|
18
35
|
}
|
|
@@ -15,6 +15,17 @@ export default class Condition extends Dbm.flow.FlowUpdateFunction {
|
|
|
15
15
|
_update() {
|
|
16
16
|
//console.log("_update");
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
let operation = this.input.operation;
|
|
19
|
+
if(typeof(operation) === "string") {
|
|
20
|
+
if(operation === "!==") {
|
|
21
|
+
operation = function(aA, aB) {return aA !== aB;}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
//METODO: add more operations
|
|
25
|
+
operation = function(aA, aB) {return aA === aB;}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.output.result = operation.call(this, this.input.input1, this.input.input2);
|
|
19
30
|
}
|
|
20
31
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Dbm from "../../../index.js";
|
|
2
|
+
|
|
3
|
+
export default class Invert extends Dbm.flow.FlowUpdateFunction {
|
|
4
|
+
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
this.input.register("input", false);
|
|
9
|
+
|
|
10
|
+
this.output.register("result", true);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
_update() {
|
|
14
|
+
//console.log("_update");
|
|
15
|
+
|
|
16
|
+
this.output.result = !this.input.input;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -10,6 +10,7 @@ export {default as All} from "./All.js";
|
|
|
10
10
|
export {default as Any} from "./Any.js";
|
|
11
11
|
export {default as AllAtValue} from "./AllAtValue.js";
|
|
12
12
|
export {default as WhenMatched} from "./WhenMatched.js";
|
|
13
|
+
export {default as Invert} from "./Invert.js";
|
|
13
14
|
|
|
14
15
|
export let subtract = function(aInput1 = 0, aInput2 = 0) {
|
|
15
16
|
let updateFunction = new Dbm.flow.updatefunctions.logic.Subtraction();
|
|
@@ -19,6 +20,13 @@ export let subtract = function(aInput1 = 0, aInput2 = 0) {
|
|
|
19
20
|
return updateFunction;
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
export let invert = function(aValue = false) {
|
|
24
|
+
let updateFunction = new Dbm.flow.updatefunctions.logic.Invert();
|
|
25
|
+
updateFunction.input.properties.input.setValue(aValue);
|
|
26
|
+
|
|
27
|
+
return updateFunction;
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
export let invertP = function(aP = 0) {
|
|
23
31
|
let updateFunction = new Dbm.flow.updatefunctions.logic.Subtraction();
|
|
24
32
|
updateFunction.input.properties.input1.setValue(1);
|
|
@@ -32,6 +32,10 @@ export default class GraphApi extends Dbm.core.BaseObject {
|
|
|
32
32
|
return this._websocketConnection.requestData(aFunctionName, aData);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
performAction(aFunctionName, aData) {
|
|
36
|
+
return this._websocketConnection.performAction(aFunctionName, aData);
|
|
37
|
+
}
|
|
38
|
+
|
|
35
39
|
createItem(aTypes, aVisibility = "draft", aChanges = [], aEncode = []) {
|
|
36
40
|
return this._websocketConnection.createItem(aTypes, aVisibility, aChanges, aEncode);
|
|
37
41
|
}
|
|
@@ -87,6 +87,15 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
87
87
|
return item;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
performAction(aFunctionName, aData) {
|
|
91
|
+
//console.log("performAction");
|
|
92
|
+
let item = this._getRequestItem();
|
|
93
|
+
item.setValue("requestData", {"type": "action", "functionName": aFunctionName, "data": aData, "requestId": item.id});
|
|
94
|
+
this._runRequest(item);
|
|
95
|
+
|
|
96
|
+
return item;
|
|
97
|
+
}
|
|
98
|
+
|
|
90
99
|
createItem(aTypes, aVisibility = "draft", aChanges = [], aEncode = []) {
|
|
91
100
|
let item = this._getRequestItem();
|
|
92
101
|
item.setValue("requestData", {"type": "admin/createObject", "types": aTypes, "visibility": aVisibility, "changes": aChanges, "encode": aEncode, "requestId": item.id});
|
|
@@ -212,6 +221,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
212
221
|
}
|
|
213
222
|
break;
|
|
214
223
|
case "data/response":
|
|
224
|
+
case "action/response":
|
|
215
225
|
{
|
|
216
226
|
let item = repository.getItem(data["requestId"]);
|
|
217
227
|
item.setValue("data", data["data"]);
|
package/package.json
CHANGED
package/react/admin/EditPage.js
CHANGED
|
@@ -13,6 +13,10 @@ export default class EditPage extends Dbm.react.BaseObject {
|
|
|
13
13
|
this.item.setValue("description", page["meta/description"]);
|
|
14
14
|
this.item.setValue("url", page.url);
|
|
15
15
|
|
|
16
|
+
let descriptionLength = Dbm.flow.updatefunctions.basic.length(this.item.properties.description);
|
|
17
|
+
|
|
18
|
+
this.item.requireProperty("descriptionLength", 0).connectInput(descriptionLength.output.properties.length);
|
|
19
|
+
|
|
16
20
|
//METODO: add editors
|
|
17
21
|
}
|
|
18
22
|
|
|
@@ -22,8 +26,8 @@ export default class EditPage extends Dbm.react.BaseObject {
|
|
|
22
26
|
let page = this.context.page;
|
|
23
27
|
let id = page.id;
|
|
24
28
|
let graphApi = Dbm.getInstance().repository.getItem("graphApi").controller;
|
|
25
|
-
console.log(this.item.content);
|
|
26
|
-
console.log(this.item.content.blocks[1].data.text);
|
|
29
|
+
//console.log(this.item.content);
|
|
30
|
+
//console.log(this.item.content.blocks[1].data.text);
|
|
27
31
|
|
|
28
32
|
graphApi.editItem(id, [
|
|
29
33
|
{"type": "setField", "data": {"value": this.item.content, "field": "content"}},
|
|
@@ -35,6 +39,20 @@ export default class EditPage extends Dbm.react.BaseObject {
|
|
|
35
39
|
], ["content", "title", "url", "meta/description"]);
|
|
36
40
|
}
|
|
37
41
|
|
|
42
|
+
_generateSeoSummary() {
|
|
43
|
+
let graphApi = Dbm.getInstance().repository.getItem("graphApi").controller;
|
|
44
|
+
|
|
45
|
+
let request = graphApi.requestData("admin/seoSummary", {"value": {"title": this.item.title, "content": this.item.content}});
|
|
46
|
+
Dbm.flow.addUpdateCommandWhenMatched(request.properties.status, Dbm.loading.LoadingStatus.LOADED, Dbm.commands.callFunction(this._dataLoaded.bind(this), [request]));
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
_dataLoaded(aRequest) {
|
|
51
|
+
let summary = Dbm.objectPath(aRequest, "data.seoSummary");
|
|
52
|
+
|
|
53
|
+
this.item.description = summary;
|
|
54
|
+
}
|
|
55
|
+
|
|
38
56
|
_renderMainElement() {
|
|
39
57
|
|
|
40
58
|
return React.createElement("div", {},
|
|
@@ -66,6 +84,17 @@ export default class EditPage extends Dbm.react.BaseObject {
|
|
|
66
84
|
"Seo description"
|
|
67
85
|
),
|
|
68
86
|
React.createElement(Dbm.react.form.FormField, {"value": this.item.properties.description, className: "standard-field standard-field-padding full-width", placeholder: "Description"}),
|
|
87
|
+
React.createElement("div", {className: "spacing micro"}),
|
|
88
|
+
React.createElement("div", {className: "flex-row justify-between"},
|
|
89
|
+
React.createElement("div", {className: "flex-row-item"},
|
|
90
|
+
React.createElement("div", {onClick: () => {this._generateSeoSummary()}}, "Generate"),
|
|
91
|
+
),
|
|
92
|
+
React.createElement("div", {className: "flex-row-item"},
|
|
93
|
+
Dbm.react.text.text(this.item.properties.descriptionLength),
|
|
94
|
+
" / ",
|
|
95
|
+
"155"
|
|
96
|
+
)
|
|
97
|
+
)
|
|
69
98
|
),
|
|
70
99
|
React.createElement("div", {className: "spacing standard"}),
|
|
71
100
|
React.createElement("div", {"className": "dbm-admin-box dbm-admin-box-padding"},
|
|
@@ -19,7 +19,7 @@ export default class ImageField extends Dbm.react.BaseObject {
|
|
|
19
19
|
|
|
20
20
|
let imageElement = React.createElement("div", {className: "flex-row small-item-spacing"},
|
|
21
21
|
React.createElement("div", {className: "flex-row-item flex-no-resize"},
|
|
22
|
-
React.createElement(Dbm.react.image.
|
|
22
|
+
React.createElement(Dbm.react.image.WidthScaledImage, {"image": Dbm.react.source.contextVariable("moduleData.editorData.data." + fieldName), targetWidth: 120, className: "editor-preview background-contain"}),
|
|
23
23
|
),
|
|
24
24
|
React.createElement("div", {className: "flex-row-item flex-resize"},
|
|
25
25
|
Dbm.react.text.text(Dbm.react.source.contextVariable("moduleData.editorData.data." + fieldName + ".url"))
|
|
@@ -7,6 +7,9 @@ export default class OpenCloseExpandableArea extends Dbm.react.BaseObject {
|
|
|
7
7
|
|
|
8
8
|
let startValue = this.getPropValue("startState") === "open";
|
|
9
9
|
let openProperty = this.getDynamicProp("open", startValue);
|
|
10
|
+
|
|
11
|
+
let invert = Dbm.flow.updatefunctions.logic.invert(openProperty);
|
|
12
|
+
this.item.requireProperty("ariaHidden", !openProperty.value);
|
|
10
13
|
|
|
11
14
|
let switchValue = Dbm.flow.updatefunctions.logic.switchValue(openProperty).addCase(false, 0).addCase(true, 1);
|
|
12
15
|
let animateValueObject = Dbm.flow.animateValue(switchValue.output.properties.value);
|
|
@@ -34,10 +37,14 @@ export default class OpenCloseExpandableArea extends Dbm.react.BaseObject {
|
|
|
34
37
|
_renderMainElement() {
|
|
35
38
|
//console.log("OpenCloseExpandableArea::_renderMainElement");
|
|
36
39
|
//console.log(this);
|
|
40
|
+
|
|
41
|
+
let openProperty = this.getDynamicProp("open");
|
|
37
42
|
|
|
38
|
-
return this._createMainElement(Dbm.react.animation.AnimatedElement, {"className": "animation-element", "controller": this.item.animation.item},
|
|
39
|
-
React.createElement(
|
|
40
|
-
this.
|
|
43
|
+
return this._createMainElement(Dbm.react.animation.AnimatedElement, {"className": "animation-element", "controller": this.item.animation.item, "aria-hidden": this.item.properties.ariaHidden},
|
|
44
|
+
React.createElement(Dbm.react.context.AddContextVariables, {"values": {"open": openProperty}},
|
|
45
|
+
React.createElement("div", {"ref": this.createRef("element")},
|
|
46
|
+
this.getPropValue("children")
|
|
47
|
+
)
|
|
41
48
|
)
|
|
42
49
|
);
|
|
43
50
|
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Dbm from "../../index.js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export default class FileDropArea extends Dbm.react.BaseObject {
|
|
6
|
+
|
|
7
|
+
_construct() {
|
|
8
|
+
super._construct();
|
|
9
|
+
|
|
10
|
+
this._id = "dropField" + Dbm.getInstance().getNextId();
|
|
11
|
+
this.item.requireProperty("dropHighlightClass", "");
|
|
12
|
+
let classNameAdd = Dbm.flow.updatefunctions.logic.add("file-drop-area display-block cursor-pointer", this.item.properties.dropHighlightClass)
|
|
13
|
+
|
|
14
|
+
this.item.setValue("classNameAdd", classNameAdd);
|
|
15
|
+
this.item.requireProperty("fullClass", "").connectInput(classNameAdd.output.properties.result);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
_handleFiles(aFiles) {
|
|
19
|
+
console.log("_handleFiles");
|
|
20
|
+
console.log(aFiles);
|
|
21
|
+
|
|
22
|
+
let command = this.getPropValue("changeCommands");
|
|
23
|
+
|
|
24
|
+
command.perform(this, aFiles);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_highlight(aEvent) {
|
|
28
|
+
aEvent.preventDefault()
|
|
29
|
+
aEvent.stopPropagation()
|
|
30
|
+
|
|
31
|
+
this.item.setValue("dropHighlightClass", "drop-file-highlight");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_unhighlight(aEvent) {
|
|
35
|
+
aEvent.preventDefault()
|
|
36
|
+
aEvent.stopPropagation()
|
|
37
|
+
|
|
38
|
+
this.item.setValue("dropHighlightClass", "");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
_handleDrop(aEvent) {
|
|
42
|
+
console.log("_handleDrop");
|
|
43
|
+
|
|
44
|
+
aEvent.preventDefault()
|
|
45
|
+
aEvent.stopPropagation()
|
|
46
|
+
|
|
47
|
+
this.item.setValue("dropHighlightClass", "");
|
|
48
|
+
|
|
49
|
+
let dataTransfer = aEvent.dataTransfer;
|
|
50
|
+
let files = dataTransfer.files;
|
|
51
|
+
|
|
52
|
+
this._handleFiles(files);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
_handleChange(aEvent) {
|
|
56
|
+
console.log("_handleChange");
|
|
57
|
+
|
|
58
|
+
this._handleFiles(aEvent.target.files);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
_selectFiles() {
|
|
62
|
+
var input = document.createElement('input');
|
|
63
|
+
input.type = 'file';
|
|
64
|
+
|
|
65
|
+
let accept = this.getPropValue("accept");
|
|
66
|
+
if(accept) {
|
|
67
|
+
input.accept = accept;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
input.addEventListener("change", (aEvent) => {this._handleChange(aEvent)});
|
|
71
|
+
input.click();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_renderMainElement() {
|
|
75
|
+
|
|
76
|
+
return this._createMainElement(Dbm.react.BaseObject, {
|
|
77
|
+
role: "button",
|
|
78
|
+
tabIndex: 0,
|
|
79
|
+
className: this.item.properties.fullClass,
|
|
80
|
+
onDragEnter: (aEvent) => {this._highlight(aEvent);},
|
|
81
|
+
onDragOver: (aEvent) => {this._highlight(aEvent);},
|
|
82
|
+
onDragLeave: (aEvent) => {this._unhighlight(aEvent);},
|
|
83
|
+
onDrop: (aEvent) => {this._handleDrop(aEvent);},
|
|
84
|
+
onKeyDown: function(aEvent) {console.log(aEvent); if(aEvent.key === "Enter") aEvent.target.click()},
|
|
85
|
+
onClick: (aEvent) => {this._selectFiles();}
|
|
86
|
+
},
|
|
87
|
+
this.getPropValue("children")
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
package/react/form/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export {default as Checkbox} from "./Checkbox.js";
|
|
2
2
|
export {default as FormField} from "./FormField.js";
|
|
3
|
-
export {default as LabelledArea} from "./LabelledArea.js";
|
|
3
|
+
export {default as LabelledArea} from "./LabelledArea.js";
|
|
4
|
+
export {default as FileDropArea} from "./FileDropArea.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import Dbm from "../../index.js";
|
|
2
|
+
|
|
3
|
+
export default class LocalImage extends Dbm.react.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
|
|
7
|
+
this.item.requireProperty("url", null);
|
|
8
|
+
let fileProp = this.getDynamicProp("file");
|
|
9
|
+
|
|
10
|
+
Dbm.flow.addUpdateCommand(fileProp, Dbm.commands.callFunction(this._fileChanged.bind(this)));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
_fileChanged() {
|
|
14
|
+
|
|
15
|
+
let file = this.getPropValue("file");
|
|
16
|
+
|
|
17
|
+
if(file) {
|
|
18
|
+
let fileReader = new FileReader();
|
|
19
|
+
fileReader.onload = (function(aEvent) {
|
|
20
|
+
this._fileLoaded(file, fileReader.result);
|
|
21
|
+
}).bind(this);
|
|
22
|
+
fileReader.readAsDataURL(file);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.item.setValue("url", null);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
_fileLoaded(aFile, aData) {
|
|
30
|
+
this.item.setValue("url", aData);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
_removedUsedProps(aProps) {
|
|
34
|
+
delete aProps["file"];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
_renderMainElement() {
|
|
38
|
+
|
|
39
|
+
return this._createMainElement(Dbm.react.image.Image, {src: this.item.properties.url}, this.getPropValue("children"));
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
}
|
package/react/image/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export {default as Image} from "./Image.js";
|
|
2
2
|
export {default as WidthScaledImage} from "./WidthScaledImage.js";
|
|
3
|
-
export {default as CoverScaledImage} from "./CoverScaledImage.js";
|
|
3
|
+
export {default as CoverScaledImage} from "./CoverScaledImage.js";
|
|
4
|
+
export {default as LocalImage} from "./LocalImage.js";
|
package/react/index.js
CHANGED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Dbm from "../../index.js";
|
|
3
|
+
|
|
4
|
+
export default class CommandButton extends Dbm.react.BaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
this._callback_clickBound = this._callback_click.bind(this);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
_callback_click(aEvent) {
|
|
12
|
+
//console.log("_callback_click");
|
|
13
|
+
//console.log(aEvent);
|
|
14
|
+
|
|
15
|
+
let command = this.getPropValue("command");
|
|
16
|
+
|
|
17
|
+
command.perform(this, aEvent);
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
_performClone(aChild, aProps) {
|
|
22
|
+
|
|
23
|
+
if(aChild instanceof Array) {
|
|
24
|
+
let returnArray = [];
|
|
25
|
+
|
|
26
|
+
let currentArray = aChild;
|
|
27
|
+
let currentArrayLength = currentArray.length;
|
|
28
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
29
|
+
let currentChild = currentArray[i];
|
|
30
|
+
returnArray.push(this._performClone(currentChild, aProps));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return returnArray;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let newProps = aProps;
|
|
37
|
+
/*
|
|
38
|
+
//MENOTE: this is a more generalized version, but we never pass in className in this function
|
|
39
|
+
if(aChild && aChild.props && aChild.props.className) {
|
|
40
|
+
newProps = {...aProps};
|
|
41
|
+
|
|
42
|
+
if(aProps.className) {
|
|
43
|
+
newProps.className = aProps.className + " " + aChild.props.className;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
newProps.className = aChild.props.className;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
let callArray = [aChild, newProps];
|
|
53
|
+
|
|
54
|
+
if(aChild && aChild.props) {
|
|
55
|
+
let firstChildChildren = aChild.props.children;
|
|
56
|
+
if(!firstChildChildren) {
|
|
57
|
+
//MENOTE: do nothing
|
|
58
|
+
}
|
|
59
|
+
else if(firstChildChildren instanceof Array) {
|
|
60
|
+
callArray = callArray.concat(firstChildChildren);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
callArray.push(firstChildChildren);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return React.cloneElement.apply(React, callArray);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
_renderMainElement() {
|
|
71
|
+
|
|
72
|
+
let children = Dbm.utils.ArrayFunctions.singleOrArray(this.getPropValue("children"));
|
|
73
|
+
|
|
74
|
+
let replacedChildren = [];
|
|
75
|
+
|
|
76
|
+
let currentArray = children;
|
|
77
|
+
let currentArrayLength = currentArray.length;
|
|
78
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
79
|
+
let currentChild = currentArray[i];
|
|
80
|
+
if(currentChild) {
|
|
81
|
+
if(typeof(currentChild) === "string") {
|
|
82
|
+
replacedChildren.push(React.createElement("span"), {"onClick": this._callback_clickBound, onKeyDown: function(aEvent) {if(aEvent.key === "Enter") aEvent.target.click()}}, currentChild);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
replacedChildren.push(this._performClone(currentChild, {"onClick": this._callback_clickBound, onKeyDown: function(aEvent) {if(aEvent.key === "Enter") aEvent.target.click()}}));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
replacedChildren.push(currentChild);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
return React.createElement(React.Fragment, {}, replacedChildren);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
package/utils/ArrayFunctions.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import Dbm from "../index.js";
|
|
2
|
+
|
|
1
3
|
export const range = function(aStartValue, aEndValue, aStepValue = 1, aIncludeEndValue = true) {
|
|
2
4
|
|
|
3
5
|
let returnArray = new Array();
|
|
@@ -60,4 +62,74 @@ export const singleOrArray = function(aData) {
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
return [aData];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const removeValues = function(aArray, aRemoveValues) {
|
|
68
|
+
let returnArray = new Array();
|
|
69
|
+
|
|
70
|
+
let currentArray = aArray;
|
|
71
|
+
let currentArrayLength = currentArray.length;
|
|
72
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
73
|
+
let currentValue = currentArray[i];
|
|
74
|
+
if(aRemoveValues.indexOf(currentValue) === -1) {
|
|
75
|
+
returnArray.push(currentValue);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return returnArray;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const trimArray = function(aArray, aMode = 3) {
|
|
83
|
+
|
|
84
|
+
if(aMode > 0) {
|
|
85
|
+
//METODO: use mode
|
|
86
|
+
if(aArray) {
|
|
87
|
+
let currentArray = aArray;
|
|
88
|
+
let currentArrayLength = currentArray.length;
|
|
89
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
90
|
+
let currentString = currentArray[i];
|
|
91
|
+
|
|
92
|
+
if(typeof(currentString) === "string") {
|
|
93
|
+
currentArray[i] = currentString.trim();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return aArray;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const arrayOrSeparatedString = function(aData, aSeparator = ",", aTrim = 3) {
|
|
103
|
+
if(aData === null || aData === undefined) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
else if(aData instanceof Array) {
|
|
107
|
+
return aData;
|
|
108
|
+
}
|
|
109
|
+
else if(typeof(aData) === "string") {
|
|
110
|
+
if(aData === "") {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
return trimArray(aData.split(aSeparator));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
console.error(aData + " is not array or string.");
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export const filterByField = function(aArray, aField, aValue) {
|
|
121
|
+
let returnArray = [];
|
|
122
|
+
|
|
123
|
+
let currentArray = aArray;
|
|
124
|
+
let currentArrayLength = currentArray.length;
|
|
125
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
126
|
+
let currentItem = aArray[i];
|
|
127
|
+
let currentValue = Dbm.objectPath(aArray[i], aField);
|
|
128
|
+
console.log(currentValue, aValue);
|
|
129
|
+
if(currentValue === aValue) {
|
|
130
|
+
returnArray.push(currentItem);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return returnArray;
|
|
63
135
|
}
|