@qrvey/utils 1.17.1 → 1.18.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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [@qrvey/utils](https://bitbucket.org/qrvey/qrvey_utils/wiki/Home) *1.17.1*
1
+ # [@qrvey/utils](https://bitbucket.org/qrvey/qrvey_utils/wiki/Home) *1.18.0*
2
2
 
3
3
  > Helper, Utils for all Qrvey Projects
4
4
 
@@ -17,10 +17,12 @@ const applyDynamicSizeStrategies = {
17
17
  };
18
18
  const recalculateStrategies = {
19
19
  fixed: (elements, currentElements, canvasWidth, device, options) => {
20
- const isSorted = !currentElements.length;
20
+ const { newElements, scopeElements } = (0, element_1.normalizeElements)(currentElements, device, interfaces_1.VemPositionType.FIXED);
21
+ const elementsToCalculate = [...newElements, ...elements];
22
+ const isSorted = !scopeElements.length;
21
23
  const changedElements = (options.allowCopy
22
- ? (0, element_1.copyDesktopPositionToDevice)(elements, device, interfaces_1.VemPositionType.FIXED)
23
- : elements);
24
+ ? (0, element_1.copyDesktopPositionToDevice)(elementsToCalculate, device, interfaces_1.VemPositionType.FIXED)
25
+ : elementsToCalculate);
24
26
  const orderedElements = isSorted
25
27
  ? (0, fixed_1.sortElementsFromReferencePoint)(changedElements, options.sort, {
26
28
  x: 0,
@@ -28,18 +30,20 @@ const recalculateStrategies = {
28
30
  })
29
31
  : changedElements;
30
32
  return options.keepPosition
31
- ? (0, fixed_1.recalculatePreservingPositions)(orderedElements, currentElements, device, canvasWidth, options.canvasHeight)
32
- : (0, fixed_1.findFixedAvailablePositions)(canvasWidth, orderedElements, currentElements, device, false, false, options?.canvasHeight);
33
+ ? (0, fixed_1.recalculatePreservingPositions)(orderedElements, scopeElements, device, canvasWidth, options.canvasHeight)
34
+ : (0, fixed_1.findFixedAvailablePositions)(canvasWidth, orderedElements, scopeElements, device, false, false, options?.canvasHeight);
33
35
  },
34
36
  responsive: (elements, currentElements, canvasWidth, device, options) => {
35
- const isSorted = !currentElements.length;
37
+ const { scopeElements, newElements } = (0, element_1.normalizeElements)(currentElements, device, interfaces_1.VemPositionType.RESPONSIVE);
38
+ const elementsToCalculate = [...newElements, ...elements];
39
+ const isSorted = !scopeElements.length;
36
40
  const changedElements = (options.allowCopy
37
- ? (0, element_1.copyDesktopPositionToDevice)(elements, device, interfaces_1.VemPositionType.RESPONSIVE)
38
- : elements);
41
+ ? (0, element_1.copyDesktopPositionToDevice)(elementsToCalculate, device, interfaces_1.VemPositionType.RESPONSIVE)
42
+ : elementsToCalculate);
39
43
  const orderedElements = isSorted
40
44
  ? (0, responsive_1.sortResponsiveElements)(changedElements, options.sort)
41
45
  : changedElements;
42
- return (0, responsive_1.findResponsiveAvailablePositions)(canvasWidth, orderedElements, currentElements, device);
46
+ return (0, responsive_1.findResponsiveAvailablePositions)(canvasWidth, orderedElements, scopeElements, device);
43
47
  },
44
48
  };
45
49
  const calculateCanvasHeightStrategies = {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.copyDesktopPositionToDevice = void 0;
3
+ exports.normalizeElements = exports.copyDesktopPositionToDevice = void 0;
4
4
  const position_1 = require("./position");
5
5
  const ICanvasGrid_1 = require("../interfaces/ICanvasGrid");
6
6
  const IVemPosition_1 = require("../interfaces/IVemPosition");
@@ -16,7 +16,7 @@ const copyDesktopPositionToDevice = (elements, newCanvasDevice, canvasType) => {
16
16
  },
17
17
  };
18
18
  return elements.map((element) => {
19
- if (!element.position[canvasType]?.[newCanvasDevice]) {
19
+ if (!hasPositionForDevice(element, newCanvasDevice, canvasType)) {
20
20
  const desktopViewPosition = element.position[canvasType][ICanvasGrid_1.CanvasDevice.DESKTOP];
21
21
  const newDevicePosition = {
22
22
  ...desktopViewPosition,
@@ -29,3 +29,24 @@ const copyDesktopPositionToDevice = (elements, newCanvasDevice, canvasType) => {
29
29
  });
30
30
  };
31
31
  exports.copyDesktopPositionToDevice = copyDesktopPositionToDevice;
32
+ const normalizeElements = (elements, newCanvasDevice, canvasType) => {
33
+ const withPosition = [];
34
+ const withoutPosition = [];
35
+ for (const element of elements) {
36
+ if (hasPositionForDevice(element, newCanvasDevice, canvasType)) {
37
+ withPosition.push(element);
38
+ }
39
+ else {
40
+ withoutPosition.push(element);
41
+ }
42
+ }
43
+ const newElements = (0, exports.copyDesktopPositionToDevice)(withoutPosition, newCanvasDevice, canvasType);
44
+ return {
45
+ scopeElements: withPosition,
46
+ newElements,
47
+ };
48
+ };
49
+ exports.normalizeElements = normalizeElements;
50
+ const hasPositionForDevice = (element, device, canvasType) => {
51
+ return !!element.position[canvasType]?.[device];
52
+ };
@@ -1,7 +1,7 @@
1
1
  import { findFixedAvailablePositions, getFixedGridElementsBottomLimit, recalculatePreservingPositions, sortElementsFromReferencePoint, updateFixedElementDimensions, } from "./fixed";
2
2
  import { findResponsiveAvailablePositions, getResponsiveGridElementsBottomLimit, sortResponsiveElements, updateResponsiveElementDimensions, } from "./responsive";
3
3
  import { CanvasDevice, VemPositionType, } from "../interfaces";
4
- import { copyDesktopPositionToDevice } from "../utils/element";
4
+ import { copyDesktopPositionToDevice, normalizeElements, } from "../utils/element";
5
5
  const applyDynamicSizeStrategies = {
6
6
  fixed: (containerItem, scopeElements, device) => {
7
7
  return updateFixedElementDimensions(containerItem, device, scopeElements);
@@ -12,10 +12,12 @@ const applyDynamicSizeStrategies = {
12
12
  };
13
13
  const recalculateStrategies = {
14
14
  fixed: (elements, currentElements, canvasWidth, device, options) => {
15
- const isSorted = !currentElements.length;
15
+ const { newElements, scopeElements } = normalizeElements(currentElements, device, VemPositionType.FIXED);
16
+ const elementsToCalculate = [...newElements, ...elements];
17
+ const isSorted = !scopeElements.length;
16
18
  const changedElements = (options.allowCopy
17
- ? copyDesktopPositionToDevice(elements, device, VemPositionType.FIXED)
18
- : elements);
19
+ ? copyDesktopPositionToDevice(elementsToCalculate, device, VemPositionType.FIXED)
20
+ : elementsToCalculate);
19
21
  const orderedElements = isSorted
20
22
  ? sortElementsFromReferencePoint(changedElements, options.sort, {
21
23
  x: 0,
@@ -23,18 +25,20 @@ const recalculateStrategies = {
23
25
  })
24
26
  : changedElements;
25
27
  return options.keepPosition
26
- ? recalculatePreservingPositions(orderedElements, currentElements, device, canvasWidth, options.canvasHeight)
27
- : findFixedAvailablePositions(canvasWidth, orderedElements, currentElements, device, false, false, options?.canvasHeight);
28
+ ? recalculatePreservingPositions(orderedElements, scopeElements, device, canvasWidth, options.canvasHeight)
29
+ : findFixedAvailablePositions(canvasWidth, orderedElements, scopeElements, device, false, false, options?.canvasHeight);
28
30
  },
29
31
  responsive: (elements, currentElements, canvasWidth, device, options) => {
30
- const isSorted = !currentElements.length;
32
+ const { scopeElements, newElements } = normalizeElements(currentElements, device, VemPositionType.RESPONSIVE);
33
+ const elementsToCalculate = [...newElements, ...elements];
34
+ const isSorted = !scopeElements.length;
31
35
  const changedElements = (options.allowCopy
32
- ? copyDesktopPositionToDevice(elements, device, VemPositionType.RESPONSIVE)
33
- : elements);
36
+ ? copyDesktopPositionToDevice(elementsToCalculate, device, VemPositionType.RESPONSIVE)
37
+ : elementsToCalculate);
34
38
  const orderedElements = isSorted
35
39
  ? sortResponsiveElements(changedElements, options.sort)
36
40
  : changedElements;
37
- return findResponsiveAvailablePositions(canvasWidth, orderedElements, currentElements, device);
41
+ return findResponsiveAvailablePositions(canvasWidth, orderedElements, scopeElements, device);
38
42
  },
39
43
  };
40
44
  const calculateCanvasHeightStrategies = {
@@ -2,3 +2,7 @@ import { CanvasDevice } from "../interfaces/ICanvasGrid";
2
2
  import { Vem } from "../interfaces/IVemCore";
3
3
  import { VemPositionType } from "../interfaces/IVemPosition";
4
4
  export declare const copyDesktopPositionToDevice: (elements: Vem[], newCanvasDevice: CanvasDevice, canvasType: VemPositionType) => Vem[];
5
+ export declare const normalizeElements: (elements: Vem[], newCanvasDevice: CanvasDevice, canvasType: VemPositionType) => {
6
+ scopeElements: Vem[];
7
+ newElements: Vem[];
8
+ };
@@ -13,7 +13,7 @@ export const copyDesktopPositionToDevice = (elements, newCanvasDevice, canvasTyp
13
13
  },
14
14
  };
15
15
  return elements.map((element) => {
16
- if (!element.position[canvasType]?.[newCanvasDevice]) {
16
+ if (!hasPositionForDevice(element, newCanvasDevice, canvasType)) {
17
17
  const desktopViewPosition = element.position[canvasType][CanvasDevice.DESKTOP];
18
18
  const newDevicePosition = {
19
19
  ...desktopViewPosition,
@@ -25,3 +25,23 @@ export const copyDesktopPositionToDevice = (elements, newCanvasDevice, canvasTyp
25
25
  return element;
26
26
  });
27
27
  };
28
+ export const normalizeElements = (elements, newCanvasDevice, canvasType) => {
29
+ const withPosition = [];
30
+ const withoutPosition = [];
31
+ for (const element of elements) {
32
+ if (hasPositionForDevice(element, newCanvasDevice, canvasType)) {
33
+ withPosition.push(element);
34
+ }
35
+ else {
36
+ withoutPosition.push(element);
37
+ }
38
+ }
39
+ const newElements = copyDesktopPositionToDevice(withoutPosition, newCanvasDevice, canvasType);
40
+ return {
41
+ scopeElements: withPosition,
42
+ newElements,
43
+ };
44
+ };
45
+ const hasPositionForDevice = (element, device, canvasType) => {
46
+ return !!element.position[canvasType]?.[device];
47
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.17.1",
3
+ "version": "1.18.0",
4
4
  "description": "Helper, Utils for all Qrvey Projects",
5
5
  "homepage": "https://bitbucket.org/qrvey/qrvey_utils/wiki/Home",
6
6
  "main": "dist/cjs/index.js",