@qrvey/utils 1.16.0-4 → 1.16.0-5

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.
@@ -94,3 +94,13 @@ export declare const sortElementsFromReferencePoint: (elements: VemFixed<unknown
94
94
  x: number;
95
95
  y: number;
96
96
  }) => VemFixed<unknown>[];
97
+ /**
98
+ * Updates the height of a given container element based on the bottom limit of other scoped elements.
99
+ * It ensures the container has at least the height required to encompass all scoped elements.
100
+ *
101
+ * @param containerItem - The element to update.
102
+ * @param device - The target device context (used to access device-specific dimensions).
103
+ * @param scopeElements
104
+ * @returns - A new version of the container element with updated height if needed.
105
+ */
106
+ export declare const updateFixedElementDimensions: (containerItem: VemFixed<unknown>, device: CanvasDevice, scopeElements: VemFixed<unknown>[]) => VemFixed<unknown>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sortElementsFromReferencePoint = exports.calculateDistancesToReferencePoint = exports.getFixedGridElementsBottomLimit = exports.updateFixedElementWidth = exports.recalculatePreservingPositions = exports.findFixedAvailablePositions = exports.getFixedPositionByDevice = exports.findAvailablePosition = exports.updateFixedPosition = void 0;
3
+ exports.updateFixedElementDimensions = exports.sortElementsFromReferencePoint = exports.calculateDistancesToReferencePoint = exports.getFixedGridElementsBottomLimit = exports.updateFixedElementWidth = exports.recalculatePreservingPositions = exports.findFixedAvailablePositions = exports.getFixedPositionByDevice = exports.findAvailablePosition = exports.updateFixedPosition = void 0;
4
4
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
5
5
  const ICanvasGrid_1 = require("../interfaces/ICanvasGrid");
6
6
  const IVemPosition_1 = require("../interfaces/IVemPosition");
@@ -246,3 +246,22 @@ const sortElementsFromReferencePoint = (elements, device, referencePoint) => {
246
246
  return sortedElements.map((element) => element.element);
247
247
  };
248
248
  exports.sortElementsFromReferencePoint = sortElementsFromReferencePoint;
249
+ /**
250
+ * Updates the height of a given container element based on the bottom limit of other scoped elements.
251
+ * It ensures the container has at least the height required to encompass all scoped elements.
252
+ *
253
+ * @param containerItem - The element to update.
254
+ * @param device - The target device context (used to access device-specific dimensions).
255
+ * @param scopeElements
256
+ * @returns - A new version of the container element with updated height if needed.
257
+ */
258
+ const updateFixedElementDimensions = (containerItem, device, scopeElements) => {
259
+ let currentElement = containerItem;
260
+ const calculatedHeight = (0, fixed_position_1.dxGetFixedGridItemsBottomLimit)(scopeElements, device);
261
+ const currentHeight = currentElement.position.fixed[device].height;
262
+ currentElement = updateFixedPosition(currentElement, {
263
+ height: Math.max(currentHeight, calculatedHeight),
264
+ }, device);
265
+ return currentElement;
266
+ };
267
+ exports.updateFixedElementDimensions = updateFixedElementDimensions;
@@ -17,6 +17,18 @@ interface RecalculateOptions {
17
17
  * @returns - A list of elements with updated positions if the canvas type is "fixed" or "responsive".
18
18
  */
19
19
  export declare function recalculateElements(newElements: Vem[], currentElements: Vem[], canvasWidth: number, canvasType: string, device: CanvasDevice, options?: RecalculateOptions): Vem[];
20
+ /**
21
+ * Updates the dimensions of a container element using a strategy based on the given canvas type.
22
+ *
23
+ * Delegates the update logic to a specific strategy found in `updateDimensionStrategies`
24
+ * using the provided `canvasType` key.
25
+ * @param containerItem The element whose dimensions need to be updated
26
+ * @param scopeElements A list of elements to consider in the update strategy
27
+ * @param device The device context (e.g., desktop, tablet, mobile) used to retrieve device-specific properties
28
+ * @param canvasType The type of canvas that determines which strategy to use.
29
+ * @returns - The updated element with modified dimensions, or `undefined` if no strategy is found.
30
+ */
31
+ export declare function updateElementDimensions(containerItem: Vem, scopeElements: Vem[], device: CanvasDevice, canvasType: string): Vem | undefined;
20
32
  /**
21
33
  * The calculation is delegated to a specific strategy based on the `canvasType`.
22
34
  * @param elements - The list of elements in the canvas.
@@ -1,10 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateCanvasHeight = exports.recalculateElements = void 0;
3
+ exports.calculateCanvasHeight = exports.updateElementDimensions = exports.recalculateElements = void 0;
4
4
  const fixed_1 = require("./fixed");
5
5
  const responsive_1 = require("./responsive");
6
6
  const interfaces_1 = require("../interfaces");
7
7
  const element_1 = require("../utils/element");
8
+ const updateDimensionStrategies = {
9
+ fixed: (containerItem, scopeElements, device) => {
10
+ return (0, fixed_1.updateFixedElementDimensions)(containerItem, device, scopeElements);
11
+ },
12
+ };
8
13
  const recalculateStrategies = {
9
14
  fixed: (elements, currentElements, canvasWidth, device, options) => {
10
15
  const isSorted = !currentElements.length;
@@ -18,7 +23,7 @@ const recalculateStrategies = {
18
23
  y: 0,
19
24
  })
20
25
  : changedElements;
21
- return options.canvasHeight
26
+ return options.keepPosition
22
27
  ? (0, fixed_1.recalculatePreservingPositions)(orderedElements, device, canvasWidth, options.canvasHeight)
23
28
  : (0, fixed_1.findFixedAvailablePositions)(canvasWidth, orderedElements, currentElements, device, false, false, options === null || options === void 0 ? void 0 : options.canvasHeight);
24
29
  },
@@ -65,6 +70,25 @@ function recalculateElements(newElements, currentElements, canvasWidth, canvasTy
65
70
  return strategy(newElements, currentElements, canvasWidth, device, calculatedOptions);
66
71
  }
67
72
  exports.recalculateElements = recalculateElements;
73
+ /**
74
+ * Updates the dimensions of a container element using a strategy based on the given canvas type.
75
+ *
76
+ * Delegates the update logic to a specific strategy found in `updateDimensionStrategies`
77
+ * using the provided `canvasType` key.
78
+ * @param containerItem The element whose dimensions need to be updated
79
+ * @param scopeElements A list of elements to consider in the update strategy
80
+ * @param device The device context (e.g., desktop, tablet, mobile) used to retrieve device-specific properties
81
+ * @param canvasType The type of canvas that determines which strategy to use.
82
+ * @returns - The updated element with modified dimensions, or `undefined` if no strategy is found.
83
+ */
84
+ function updateElementDimensions(containerItem, scopeElements, device, canvasType) {
85
+ const strategy = updateDimensionStrategies[canvasType];
86
+ if (!strategy) {
87
+ return;
88
+ }
89
+ return strategy(containerItem, scopeElements, device);
90
+ }
91
+ exports.updateElementDimensions = updateElementDimensions;
68
92
  /**
69
93
  * The calculation is delegated to a specific strategy based on the `canvasType`.
70
94
  * @param elements - The list of elements in the canvas.
@@ -10,3 +10,4 @@ export declare const dxGetFixedGridItemY: (element: VemFixed, device: CanvasDevi
10
10
  export declare const dxGetFixedGridItemZ: (element: VemFixed, device: CanvasDevice) => number;
11
11
  export declare const dxGetFixedGridItemHeight: (element: VemFixed, device: CanvasDevice) => number;
12
12
  export declare const dxGetFixedGridItemWidth: (element: VemFixed, device: CanvasDevice) => number;
13
+ export declare const dxGetFixedGridItemsBottomLimit: (items: VemFixed[], device: CanvasDevice, allowNegative?: boolean) => number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dxGetFixedGridItemWidth = exports.dxGetFixedGridItemHeight = exports.dxGetFixedGridItemZ = exports.dxGetFixedGridItemY = exports.dxGetFixedGridItemX = exports.dxGetFixedGridItemDevice = exports.checkFixedGridItemsOverlap = exports.itemYOverflow = exports.itemXOverflow = exports.hasOverlap = exports.hasOverflow = void 0;
3
+ exports.dxGetFixedGridItemsBottomLimit = exports.dxGetFixedGridItemWidth = exports.dxGetFixedGridItemHeight = exports.dxGetFixedGridItemZ = exports.dxGetFixedGridItemY = exports.dxGetFixedGridItemX = exports.dxGetFixedGridItemDevice = exports.checkFixedGridItemsOverlap = exports.itemYOverflow = exports.itemXOverflow = exports.hasOverlap = exports.hasOverflow = void 0;
4
4
  const hasOverflow = (element, device, resolution, canvasHeight) => {
5
5
  const hasXOverflow = (0, exports.itemXOverflow)(element, device, resolution);
6
6
  const hasYOverflow = canvasHeight
@@ -84,3 +84,10 @@ const dxGetFixedGridItemWidth = (element, device) => {
84
84
  return (_a = position === null || position === void 0 ? void 0 : position.width) !== null && _a !== void 0 ? _a : 400;
85
85
  };
86
86
  exports.dxGetFixedGridItemWidth = dxGetFixedGridItemWidth;
87
+ const dxGetFixedGridItemsBottomLimit = (items, device, allowNegative = false) => {
88
+ return items.length === 0
89
+ ? 0
90
+ : Math.max(...items.map((gridItem) => (0, exports.dxGetFixedGridItemY)(gridItem, device, allowNegative) +
91
+ (0, exports.dxGetFixedGridItemHeight)(gridItem, device)));
92
+ };
93
+ exports.dxGetFixedGridItemsBottomLimit = dxGetFixedGridItemsBottomLimit;
@@ -94,3 +94,13 @@ export declare const sortElementsFromReferencePoint: (elements: VemFixed<unknown
94
94
  x: number;
95
95
  y: number;
96
96
  }) => VemFixed<unknown>[];
97
+ /**
98
+ * Updates the height of a given container element based on the bottom limit of other scoped elements.
99
+ * It ensures the container has at least the height required to encompass all scoped elements.
100
+ *
101
+ * @param containerItem - The element to update.
102
+ * @param device - The target device context (used to access device-specific dimensions).
103
+ * @param scopeElements
104
+ * @returns - A new version of the container element with updated height if needed.
105
+ */
106
+ export declare const updateFixedElementDimensions: (containerItem: VemFixed<unknown>, device: CanvasDevice, scopeElements: VemFixed<unknown>[]) => VemFixed<unknown>;
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
2
2
  import { CanvasDevice } from "../interfaces/ICanvasGrid";
3
3
  import { VemPositionType } from "../interfaces/IVemPosition";
4
- import { dxGetFixedGridItemDevice, hasOverflow, hasOverlap, } from "../utils/fixed.position";
4
+ import { dxGetFixedGridItemDevice, dxGetFixedGridItemsBottomLimit, hasOverflow, hasOverlap, } from "../utils/fixed.position";
5
5
  import { sortByDistanceFunction } from "../utils/general";
6
6
  import { OverlapIntervalTree } from "../utils/overlap";
7
7
  import { setElementPosition } from "../utils/position";
@@ -234,3 +234,21 @@ export const sortElementsFromReferencePoint = (elements, device, referencePoint)
234
234
  const sortedElements = [...calculatedElements].sort(sortByDistanceFunction);
235
235
  return sortedElements.map((element) => element.element);
236
236
  };
237
+ /**
238
+ * Updates the height of a given container element based on the bottom limit of other scoped elements.
239
+ * It ensures the container has at least the height required to encompass all scoped elements.
240
+ *
241
+ * @param containerItem - The element to update.
242
+ * @param device - The target device context (used to access device-specific dimensions).
243
+ * @param scopeElements
244
+ * @returns - A new version of the container element with updated height if needed.
245
+ */
246
+ export const updateFixedElementDimensions = (containerItem, device, scopeElements) => {
247
+ let currentElement = containerItem;
248
+ const calculatedHeight = dxGetFixedGridItemsBottomLimit(scopeElements, device);
249
+ const currentHeight = currentElement.position.fixed[device].height;
250
+ currentElement = updateFixedPosition(currentElement, {
251
+ height: Math.max(currentHeight, calculatedHeight),
252
+ }, device);
253
+ return currentElement;
254
+ };
@@ -17,6 +17,18 @@ interface RecalculateOptions {
17
17
  * @returns - A list of elements with updated positions if the canvas type is "fixed" or "responsive".
18
18
  */
19
19
  export declare function recalculateElements(newElements: Vem[], currentElements: Vem[], canvasWidth: number, canvasType: string, device: CanvasDevice, options?: RecalculateOptions): Vem[];
20
+ /**
21
+ * Updates the dimensions of a container element using a strategy based on the given canvas type.
22
+ *
23
+ * Delegates the update logic to a specific strategy found in `updateDimensionStrategies`
24
+ * using the provided `canvasType` key.
25
+ * @param containerItem The element whose dimensions need to be updated
26
+ * @param scopeElements A list of elements to consider in the update strategy
27
+ * @param device The device context (e.g., desktop, tablet, mobile) used to retrieve device-specific properties
28
+ * @param canvasType The type of canvas that determines which strategy to use.
29
+ * @returns - The updated element with modified dimensions, or `undefined` if no strategy is found.
30
+ */
31
+ export declare function updateElementDimensions(containerItem: Vem, scopeElements: Vem[], device: CanvasDevice, canvasType: string): Vem | undefined;
20
32
  /**
21
33
  * The calculation is delegated to a specific strategy based on the `canvasType`.
22
34
  * @param elements - The list of elements in the canvas.
@@ -1,7 +1,12 @@
1
- import { findFixedAvailablePositions, getFixedGridElementsBottomLimit, recalculatePreservingPositions, sortElementsFromReferencePoint, } from "./fixed";
1
+ import { findFixedAvailablePositions, getFixedGridElementsBottomLimit, recalculatePreservingPositions, sortElementsFromReferencePoint, updateFixedElementDimensions, } from "./fixed";
2
2
  import { findResponsiveAvailablePositions, getResponsiveGridElementsBottomLimit, sortResponsiveElements, } from "./responsive";
3
3
  import { CanvasDevice, VemPositionType, } from "../interfaces";
4
4
  import { copyDesktopPositionToDevice } from "../utils/element";
5
+ const updateDimensionStrategies = {
6
+ fixed: (containerItem, scopeElements, device) => {
7
+ return updateFixedElementDimensions(containerItem, device, scopeElements);
8
+ },
9
+ };
5
10
  const recalculateStrategies = {
6
11
  fixed: (elements, currentElements, canvasWidth, device, options) => {
7
12
  const isSorted = !currentElements.length;
@@ -15,7 +20,7 @@ const recalculateStrategies = {
15
20
  y: 0,
16
21
  })
17
22
  : changedElements;
18
- return options.canvasHeight
23
+ return options.keepPosition
19
24
  ? recalculatePreservingPositions(orderedElements, device, canvasWidth, options.canvasHeight)
20
25
  : findFixedAvailablePositions(canvasWidth, orderedElements, currentElements, device, false, false, options === null || options === void 0 ? void 0 : options.canvasHeight);
21
26
  },
@@ -61,6 +66,24 @@ export function recalculateElements(newElements, currentElements, canvasWidth, c
61
66
  const calculatedOptions = Object.assign(Object.assign({}, defaultOptions), options);
62
67
  return strategy(newElements, currentElements, canvasWidth, device, calculatedOptions);
63
68
  }
69
+ /**
70
+ * Updates the dimensions of a container element using a strategy based on the given canvas type.
71
+ *
72
+ * Delegates the update logic to a specific strategy found in `updateDimensionStrategies`
73
+ * using the provided `canvasType` key.
74
+ * @param containerItem The element whose dimensions need to be updated
75
+ * @param scopeElements A list of elements to consider in the update strategy
76
+ * @param device The device context (e.g., desktop, tablet, mobile) used to retrieve device-specific properties
77
+ * @param canvasType The type of canvas that determines which strategy to use.
78
+ * @returns - The updated element with modified dimensions, or `undefined` if no strategy is found.
79
+ */
80
+ export function updateElementDimensions(containerItem, scopeElements, device, canvasType) {
81
+ const strategy = updateDimensionStrategies[canvasType];
82
+ if (!strategy) {
83
+ return;
84
+ }
85
+ return strategy(containerItem, scopeElements, device);
86
+ }
64
87
  /**
65
88
  * The calculation is delegated to a specific strategy based on the `canvasType`.
66
89
  * @param elements - The list of elements in the canvas.
@@ -10,3 +10,4 @@ export declare const dxGetFixedGridItemY: (element: VemFixed, device: CanvasDevi
10
10
  export declare const dxGetFixedGridItemZ: (element: VemFixed, device: CanvasDevice) => number;
11
11
  export declare const dxGetFixedGridItemHeight: (element: VemFixed, device: CanvasDevice) => number;
12
12
  export declare const dxGetFixedGridItemWidth: (element: VemFixed, device: CanvasDevice) => number;
13
+ export declare const dxGetFixedGridItemsBottomLimit: (items: VemFixed[], device: CanvasDevice, allowNegative?: boolean) => number;
@@ -70,3 +70,9 @@ export const dxGetFixedGridItemWidth = (element, device) => {
70
70
  const position = element.position.fixed[device];
71
71
  return (_a = position === null || position === void 0 ? void 0 : position.width) !== null && _a !== void 0 ? _a : 400;
72
72
  };
73
+ export const dxGetFixedGridItemsBottomLimit = (items, device, allowNegative = false) => {
74
+ return items.length === 0
75
+ ? 0
76
+ : Math.max(...items.map((gridItem) => dxGetFixedGridItemY(gridItem, device, allowNegative) +
77
+ dxGetFixedGridItemHeight(gridItem, device)));
78
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.16.0-4",
3
+ "version": "1.16.0-5",
4
4
  "description": "Helper, Utils for all Qrvey Projects",
5
5
  "homepage": "https://bitbucket.org/qrvey/qrvey_utils/wiki/Home",
6
6
  "main": "dist/index.js",