dbm 1.2.8 → 1.2.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbm",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {},
@@ -5,7 +5,7 @@ export default class FixedWidthInfiniteSlideshow extends Dbm.react.BaseObject {
5
5
  _construct() {
6
6
  super._construct();
7
7
 
8
-
8
+ this._sliderItems = {};
9
9
  }
10
10
 
11
11
  _removedUsedProps(aProps) {
@@ -13,6 +13,22 @@ export default class FixedWidthInfiniteSlideshow extends Dbm.react.BaseObject {
13
13
  delete aProps["prepareLength"];
14
14
  delete aProps["elementWidth"];
15
15
  delete aProps["spacing"];
16
+ delete aProps["index"];
17
+ delete aProps["startPositionOffset"];
18
+ delete aProps["itemClasses"];
19
+ }
20
+
21
+ _getItemForIndex(aIndex) {
22
+ let currentItem = this._sliderItems["i"+ aIndex];
23
+ if(!currentItem) {
24
+ currentItem = new Dbm.repository.Item();
25
+ currentItem.setValue("index", aIndex);
26
+ currentItem.setValue("envelope", 0);
27
+ currentItem.setValue("localPosition", 0);
28
+ this._sliderItems["i"+ aIndex] = currentItem;
29
+ }
30
+
31
+ return currentItem;
16
32
  }
17
33
 
18
34
  _renderMainElement() {
@@ -23,6 +39,8 @@ export default class FixedWidthInfiniteSlideshow extends Dbm.react.BaseObject {
23
39
  let prepLength = this.getPropValueWithDefault("prepareLength", 20);
24
40
  let elementWidth = this.getPropValueWithDefault("elementWidth", 200);
25
41
  let spacing = this.getPropValueWithDefault("spacing", 0);
42
+ let startPositionOffset = this.getPropValueWithDefault("startPositionOffset", 0);
43
+ let itemClasses = this.getPropValueWithDefault("itemClasses", "full-size");
26
44
 
27
45
  let index = this.getPropValue("index");
28
46
 
@@ -33,7 +51,7 @@ export default class FixedWidthInfiniteSlideshow extends Dbm.react.BaseObject {
33
51
  let stepLength = elementWidth+spacing;
34
52
  let movedLength = index*stepLength;
35
53
 
36
- let startPosition = movedLength-prepLength;
54
+ let startPosition = movedLength-prepLength-startPositionOffset;
37
55
  let startIndex = Math.floor(startPosition/stepLength);
38
56
 
39
57
  let endPosition = (startPosition + viewWidth + 2*prepLength);
@@ -41,12 +59,21 @@ export default class FixedWidthInfiniteSlideshow extends Dbm.react.BaseObject {
41
59
 
42
60
  let children = [];
43
61
  for(let i = startIndex; i <= endIndex; i++) {
44
- let currentPosition = i*stepLength-movedLength;
62
+ let currentPosition = i*stepLength-movedLength+startPositionOffset;
45
63
  let elementIndex = Dbm.utils.NumberFunctions.floatMod(i, numberOfElements);
46
64
 
47
- //METODO: send in styles instead of forcing full size
65
+ let indexItem = this._getItemForIndex(i);
66
+ let localPosition = i-index;
67
+ indexItem.localPosition = localPosition;
68
+ let envelope = 1-Math.min(1, Math.abs(localPosition));
69
+ indexItem.envelope = envelope;
70
+
48
71
  let style = {"transform": "translateX(" + currentPosition + "px)", position: "absolute", left: 0, top: 0};
49
- let child = React.createElement("div", {"key": i, "className": "full-size", "style": style}, elements[elementIndex])
72
+ let child = React.createElement("div", {"key": i, "className": itemClasses, "style": style},
73
+ React.createElement(Dbm.react.context.AddContextVariables, {"values": {"sliderItem": indexItem}},
74
+ elements[elementIndex]
75
+ )
76
+ );
50
77
  children.push(child);
51
78
  }
52
79
 
@@ -377,4 +377,19 @@ export const stepFromCenter = function(aStep, aLength) {
377
377
  let index = startIndex + step * (swing * direction);
378
378
 
379
379
  return index;
380
+ }
381
+
382
+ export const scoreItems = function(aArray, aScoreFunction) {
383
+ let returnArray = [];
384
+
385
+ let currentArray = aArray;
386
+ let currentArrayLength = currentArray.length;
387
+ for(let i = 0; i < currentArrayLength; i++) {
388
+ let item = currentArray[i];
389
+ returnArray.push({"key": item, "value": aScoreFunction(item)});
390
+ }
391
+
392
+ sortOnField(returnArray, "value");
393
+
394
+ return returnArray;
380
395
  }
@@ -0,0 +1,15 @@
1
+ export default class ArrayOperationResult {
2
+
3
+ constructor() {
4
+
5
+ this.added = [];
6
+ this.noChange = [];
7
+ this.removed = [];
8
+
9
+ return this;
10
+ }
11
+
12
+ get changed() {
13
+ return (this.added.length > 0 || this.removed.length > 0);
14
+ }
15
+ }
@@ -0,0 +1,36 @@
1
+ import Dbm from "../index.js";
2
+
3
+ export const compare = function(aString1, aString2) {
4
+
5
+ let string1Length = aString1.length+1;
6
+ let string2Length = aString2.length+1;
7
+
8
+ let values = new Dbm.utils.MultidimensionalArrayHolder();
9
+
10
+ values.setLengths([string1Length, string2Length]);
11
+
12
+ values.setValue(0, 0, 0);
13
+
14
+ for(let i = 0; i < string1Length; i++) {
15
+ values.setValue(i, 0, i);
16
+ }
17
+ for(let i = 1; i < string2Length; i++) {
18
+ values.setValue(0, i, i);
19
+ }
20
+
21
+ for(let i = 1; i < string2Length; i++) {
22
+ for(let j = 1; j < string1Length; j++) {
23
+ let char1 = aString1[j-1];
24
+ let char2 = aString2[i-1];
25
+
26
+ if(char1 === char2) {
27
+ values.setValue(j, i, values.getValue(j-1, i-1));
28
+ }
29
+ else {
30
+ values.setValue(j, i, Math.min(values.getValue(j-1, i), values.getValue(j, i-1), values.getValue(j-1, i-1))+1);
31
+ }
32
+ }
33
+ }
34
+
35
+ return values.getValue(string1Length-1, string2Length-1);
36
+ };
@@ -0,0 +1,65 @@
1
+ export default class MultidimensionalArrayHolder {
2
+
3
+ constructor() {
4
+
5
+ this._lengths = null;
6
+ this.array = [];
7
+
8
+ return this;
9
+ }
10
+
11
+ getDimesionLength(aDimension) {
12
+ return this._lengths[aDimension];
13
+ }
14
+
15
+ _getArrayPosition(aPositions) {
16
+
17
+ var returnValue = 0;
18
+ var multiplier = 1;
19
+
20
+ var currentArray = this._lengths;
21
+ var currentArrayLength = currentArray.length;
22
+ for(var i = currentArrayLength; --i >= 0;) { //MENOTE: loop from end to start
23
+ returnValue += multiplier*aPositions[i];
24
+ multiplier *= currentArray[i];
25
+ }
26
+
27
+ return returnValue;
28
+ }
29
+
30
+ getValue(...aPositions) {
31
+
32
+ if(aPositions.length !== this._lengths.length) {
33
+ //METODO: error message
34
+ return null;
35
+ }
36
+
37
+ var arrayPosition = this._getArrayPosition(aPositions);
38
+ return this.array[arrayPosition];
39
+ }
40
+
41
+ setValue(...aPositionsAndValue) {
42
+ if(aPositionsAndValue.length !== this._lengths.length+1) {
43
+ console.error("Number of positions (" + (aPositionsAndValue.length-1) + ") doesn't match dimensions of this array (" + this._lengths.length + ").");
44
+ return;
45
+ }
46
+
47
+ let value = aPositionsAndValue.pop();
48
+
49
+ var arrayPosition = this._getArrayPosition(aPositionsAndValue);
50
+ this.array[arrayPosition] = value;
51
+ }
52
+
53
+ setLengths(aLengths) {
54
+ this._lengths = aLengths;
55
+ var totalLength = 1;
56
+ var currentArray = this._lengths;
57
+ var currentArrayLength = currentArray.length;
58
+ for(var i = 0; i < currentArrayLength; i++) {
59
+ totalLength *= currentArray[i];
60
+ }
61
+ this.array = new Array(totalLength);
62
+
63
+ return this;
64
+ }
65
+ }
package/utils/index.js CHANGED
@@ -4,5 +4,9 @@ export * as StringFunctions from "./StringFunctions.js";
4
4
  export * as UrlFunctions from "./UrlFunctions.js";
5
5
  export * as CompareFunctions from "./CompareFunctions.js";
6
6
  export * as TranslationFunctions from "./TranslationFunctions.js";
7
+ export * as LevenshteinDistance from "./LevenshteinDistance.js";
8
+
9
+ export {default as MultidimensionalArrayHolder} from "./MultidimensionalArrayHolder.js";
10
+ export {default as ArrayOperationResult} from "./ArrayOperationResult.js";
7
11
 
8
12
  export * as thirdparty from "./thirdparty/index.js";