dbm 1.1.23 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dbm.js +8 -5
- package/flow/updatefunctions/dom/ElementPosition.js +2 -4
- package/package.json +1 -1
- package/react/form/Form.js +49 -0
- package/react/form/index.js +2 -1
- package/react/image/CoverScaledImage.js +20 -1
- package/react/interaction/CommandButton.js +16 -3
- package/utils/UrlFunctions.js +22 -5
package/dbm.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import {GlobalObject} from "./core/index.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
globalThis.dbm
|
|
3
|
+
export const setupGlobalInstance = function(aObject, aPath) {
|
|
4
|
+
if(!globalThis.dbm) {
|
|
5
|
+
globalThis.dbm = new GlobalObject();
|
|
6
|
+
}
|
|
5
7
|
}
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
|
|
10
|
+
export const getInstance = function() {
|
|
8
11
|
return globalThis.dbm;
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
//export {getInstance};
|
|
12
15
|
|
|
13
|
-
export
|
|
16
|
+
export const objectPath = function(aObject, aPath) {
|
|
14
17
|
//console.log("objectPath");
|
|
15
18
|
|
|
16
19
|
let currentObject = aObject;
|
|
@@ -57,7 +60,7 @@ export let objectPath = function(aObject, aPath) {
|
|
|
57
60
|
return currentObject;
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
export
|
|
63
|
+
export const setAtObjectPath = function(aObject, aPath, aValue) {
|
|
61
64
|
aPath += "";
|
|
62
65
|
if(aPath.length === 0) {
|
|
63
66
|
return 0;
|
|
@@ -30,12 +30,10 @@ export default class ElementPosition extends Dbm.flow.FlowUpdateFunction {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
_update() {
|
|
33
|
-
console.log("_update");
|
|
33
|
+
//console.log("_update");
|
|
34
34
|
|
|
35
35
|
let element = this.input.element;
|
|
36
36
|
|
|
37
|
-
console.log(element, this.input.prepareX, this.input.prepareY);
|
|
38
|
-
|
|
39
37
|
if(element) {
|
|
40
38
|
|
|
41
39
|
//this.output.width = element.clientWidth;
|
|
@@ -85,7 +83,7 @@ export default class ElementPosition extends Dbm.flow.FlowUpdateFunction {
|
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
_callback_scroll(aEvent) {
|
|
88
|
-
console.log("_callback_scroll");
|
|
86
|
+
//console.log("_callback_scroll");
|
|
89
87
|
|
|
90
88
|
let element = this.input.element;
|
|
91
89
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Dbm from "../../index.js";
|
|
3
|
+
|
|
4
|
+
export default class Form extends Dbm.react.BaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
this._callback_submitBound = this._callback_submit.bind(this);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
_callback_submit(aEvent) {
|
|
12
|
+
//console.log("_callback_submit");
|
|
13
|
+
//console.log(aEvent);
|
|
14
|
+
|
|
15
|
+
let preventSubmit = this.getPropValue("preventSubmit");
|
|
16
|
+
if(preventSubmit) {
|
|
17
|
+
aEvent.preventDefault();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let commands = this.getPropValue("commands");
|
|
21
|
+
if(!commands) {
|
|
22
|
+
commands = this.getPropValue("command");
|
|
23
|
+
}
|
|
24
|
+
if(commands) {
|
|
25
|
+
aEvent.preventDefault();
|
|
26
|
+
commands = Dbm.utils.ArrayFunctions.singleOrArray(commands);
|
|
27
|
+
|
|
28
|
+
let currentArray = commands;
|
|
29
|
+
let currentArrayLength = currentArray.length;
|
|
30
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
31
|
+
let command = currentArray[i];
|
|
32
|
+
command.perform(this, aEvent);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else{
|
|
36
|
+
return !preventSubmit;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_renderMainElement() {
|
|
43
|
+
|
|
44
|
+
let children = this.getPropValue("children");
|
|
45
|
+
|
|
46
|
+
return this._createMainElement("form", {onSubmit: this._callback_submitBound}, children);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
package/react/form/index.js
CHANGED
|
@@ -8,4 +8,5 @@ export {default as GraphApiSelectOrCreateObject} from "./GraphApiSelectOrCreateO
|
|
|
8
8
|
export {default as GraphApiImage} from "./GraphApiImage.js";
|
|
9
9
|
export {default as EditArray} from "./EditArray.js";
|
|
10
10
|
export {default as TextArea} from "./TextArea.js";
|
|
11
|
-
export {default as EditObjectProperty} from "./EditObjectProperty.js";
|
|
11
|
+
export {default as EditObjectProperty} from "./EditObjectProperty.js";
|
|
12
|
+
export {default as Form} from "./Form.js";
|
|
@@ -10,6 +10,7 @@ export default class CoverScaledImage extends Dbm.react.BaseObject {
|
|
|
10
10
|
delete aProps["image"];
|
|
11
11
|
delete aProps["targetWidth"];
|
|
12
12
|
delete aProps["targetHeight"];
|
|
13
|
+
delete aProps["skipWindowSize"];
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
_renderMainElement() {
|
|
@@ -17,7 +18,15 @@ export default class CoverScaledImage extends Dbm.react.BaseObject {
|
|
|
17
18
|
let image = this.getPropValue("image");
|
|
18
19
|
let width = this.getPropValue("targetWidth");
|
|
19
20
|
let height = this.getPropValue("targetHeight");
|
|
20
|
-
let url
|
|
21
|
+
let url;
|
|
22
|
+
|
|
23
|
+
if(this.getPropValue("skipWindowSize")) {
|
|
24
|
+
url = Dbm.utils.UrlFunctions.createCoverScaledImageUrlWithPixelDensity(image, width, height, Math.floor(window.devicePixelRatio), 10000);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
url = Dbm.utils.UrlFunctions.createCoverScaledImageUrl(image, width, height);
|
|
28
|
+
}
|
|
29
|
+
|
|
21
30
|
|
|
22
31
|
let newProps = this._copyProps({src: url});
|
|
23
32
|
|
|
@@ -29,6 +38,16 @@ export default class CoverScaledImage extends Dbm.react.BaseObject {
|
|
|
29
38
|
let elementType = this.getPropValue("elementType");
|
|
30
39
|
if(elementType) {
|
|
31
40
|
newProps["elementType"] = elementType;
|
|
41
|
+
|
|
42
|
+
if(elementType === "img" && Dbm.utils.UrlFunctions.imageShouldScale(image)) {
|
|
43
|
+
|
|
44
|
+
let images = [];
|
|
45
|
+
images.push(Dbm.utils.UrlFunctions.createCoverScaledImageUrlWithPixelDensity(image, width, height, 1, 10000) + " 1x");
|
|
46
|
+
images.push(Dbm.utils.UrlFunctions.createCoverScaledImageUrlWithPixelDensity(image, width, height, 2, 10000) + " 2x");
|
|
47
|
+
images.push(Dbm.utils.UrlFunctions.createCoverScaledImageUrlWithPixelDensity(image, width, height, 3, 10000) + " 3x");
|
|
48
|
+
|
|
49
|
+
newProps["srcset"] = images.join(", ");
|
|
50
|
+
}
|
|
32
51
|
}
|
|
33
52
|
|
|
34
53
|
return React.createElement(Dbm.react.image.Image, newProps, this.getPropValue("children"));
|
|
@@ -12,10 +12,23 @@ export default class CommandButton extends Dbm.react.BaseObject {
|
|
|
12
12
|
//console.log("_callback_click");
|
|
13
13
|
//console.log(aEvent);
|
|
14
14
|
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
let commands = this.getPropValue("commands");
|
|
16
|
+
if(!commands) {
|
|
17
|
+
commands = this.getPropValue("command");
|
|
18
|
+
}
|
|
19
|
+
if(commands) {
|
|
20
|
+
commands = Dbm.utils.ArrayFunctions.singleOrArray(commands);
|
|
18
21
|
|
|
22
|
+
let currentArray = commands;
|
|
23
|
+
let currentArrayLength = currentArray.length;
|
|
24
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
25
|
+
let command = currentArray[i];
|
|
26
|
+
command.perform(this, aEvent);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else{
|
|
30
|
+
console.warn("Button doesn't have any commands", this);
|
|
31
|
+
}
|
|
19
32
|
}
|
|
20
33
|
|
|
21
34
|
_performClone(aChild, aProps) {
|
package/utils/UrlFunctions.js
CHANGED
|
@@ -31,7 +31,7 @@ export let createScaledImageUrlWithPixelDensity = function(aImageData, aWantedWi
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export let createScaledImageUrl = function(aImageData, aWantedWidth) {
|
|
34
|
-
return createScaledImageUrlWithPixelDensity(aImageData, aWantedWidth, window.devicePixelRatio, window.innerWidth);
|
|
34
|
+
return createScaledImageUrlWithPixelDensity(aImageData, aWantedWidth, Math.floor(window.devicePixelRatio), window.innerWidth);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export let getCoverScaledImageUrlWithPixelDensity = function(aUrl, aWantedWidth, aWantedHeight, aPixelDensity, aMaxSize) {
|
|
@@ -56,7 +56,24 @@ export let getCoverScaledImageUrlWithPixelDensity = function(aUrl, aWantedWidth,
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export const getCoverScaledImageUrl = function(aUrl, aWantedWidth, aWantedHeight) {
|
|
59
|
-
return getCoverScaledImageUrlWithPixelDensity(aUrl, aWantedWidth, aWantedHeight, window.devicePixelRatio, window.innerWidth);
|
|
59
|
+
return getCoverScaledImageUrlWithPixelDensity(aUrl, aWantedWidth, aWantedHeight, Math.floor(window.devicePixelRatio), window.innerWidth);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const imageShouldScale = function(aImageData) {
|
|
63
|
+
if(!aImageData || !aImageData["url"]) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let url = aImageData["url"];
|
|
68
|
+
if(url.substring(url.length-4).toLowerCase() === ".svg") {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if(!aImageData["resizeUrl"]) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return true;
|
|
60
77
|
}
|
|
61
78
|
|
|
62
79
|
export let createCoverScaledImageUrlWithPixelDensity = function(aImageData, aWantedWidth, aWantedHeight, aPixelDensity, aMaxSize) {
|
|
@@ -70,14 +87,14 @@ export let createCoverScaledImageUrlWithPixelDensity = function(aImageData, aWan
|
|
|
70
87
|
}
|
|
71
88
|
|
|
72
89
|
if(aImageData["resizeUrl"]) {
|
|
73
|
-
url =
|
|
90
|
+
url = getCoverScaledImageUrlWithPixelDensity(aImageData["resizeUrl"], aWantedWidth, aWantedHeight, aPixelDensity, aMaxSize);
|
|
74
91
|
}
|
|
75
92
|
|
|
76
93
|
return url;
|
|
77
94
|
}
|
|
78
95
|
|
|
79
96
|
export let createCoverScaledImageUrl = function(aImageData, aWantedWidth, aWantedHeight) {
|
|
80
|
-
return createCoverScaledImageUrlWithPixelDensity(aImageData, aWantedWidth, aWantedHeight, window.devicePixelRatio, window.innerWidth);
|
|
97
|
+
return createCoverScaledImageUrlWithPixelDensity(aImageData, aWantedWidth, aWantedHeight, Math.floor(window.devicePixelRatio), window.innerWidth);
|
|
81
98
|
}
|
|
82
99
|
|
|
83
100
|
export const getContainScaledImageUrlWithPixelDensity = function(aUrl, aWantedWidth, aWantedHeight, aPixelDensity, aMaxSize) {
|
|
@@ -102,7 +119,7 @@ export const getContainScaledImageUrlWithPixelDensity = function(aUrl, aWantedWi
|
|
|
102
119
|
}
|
|
103
120
|
|
|
104
121
|
export const getContainScaledImageUrl = function(aUrl, aWantedWidth, aWantedHeight) {
|
|
105
|
-
return getContainScaledImageUrlWithPixelDensity(aUrl, aWantedWidth, aWantedHeight, window.devicePixelRatio, window.innerWidth);
|
|
122
|
+
return getContainScaledImageUrlWithPixelDensity(aUrl, aWantedWidth, aWantedHeight, Math.floor(window.devicePixelRatio), window.innerWidth);
|
|
106
123
|
}
|
|
107
124
|
|
|
108
125
|
export let createContainScaledImageUrl = function(aImageData, aWantedWidth, aWantedHeight) {
|