@qrvey/utils 1.16.0-12 → 1.16.0-13
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/dist/cjs/elements/helpers/gridStrategy.d.ts +2 -1
- package/dist/cjs/elements/helpers/gridStrategy.js +10 -6
- package/dist/cjs/elements/helpers/responsive.d.ts +11 -1
- package/dist/cjs/elements/helpers/responsive.js +27 -1
- package/dist/elements/helpers/gridStrategy.d.ts +2 -1
- package/dist/elements/helpers/gridStrategy.js +9 -5
- package/dist/elements/helpers/responsive.d.ts +11 -1
- package/dist/elements/helpers/responsive.js +25 -0
- package/package.json +1 -1
|
@@ -26,9 +26,10 @@ export declare function recalculateElements(newElements: Vem[], currentElements:
|
|
|
26
26
|
* @param scopeElements A list of elements to consider in the update strategy
|
|
27
27
|
* @param device The device context (e.g., desktop, tablet, mobile) used to retrieve device-specific properties
|
|
28
28
|
* @param canvasType The type of canvas that determines which strategy to use.
|
|
29
|
+
* @param gap The type of canvas that determines which strategy to use.
|
|
29
30
|
* @returns - The updated element with modified dimensions, or `undefined` if no strategy is found.
|
|
30
31
|
*/
|
|
31
|
-
export declare function
|
|
32
|
+
export declare function applyDynamicSize(containerItem: Vem, scopeElements: Vem[], device: CanvasDevice, canvasType: string, gap?: number): Vem | undefined;
|
|
32
33
|
/**
|
|
33
34
|
* The calculation is delegated to a specific strategy based on the `canvasType`.
|
|
34
35
|
* @param elements - The list of elements in the canvas.
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateCanvasHeight = exports.
|
|
3
|
+
exports.calculateCanvasHeight = exports.applyDynamicSize = 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
|
|
8
|
+
const applyDynamicSizeStrategies = {
|
|
9
9
|
fixed: (containerItem, scopeElements, device) => {
|
|
10
10
|
return (0, fixed_1.updateFixedElementDimensions)(containerItem, device, scopeElements);
|
|
11
11
|
},
|
|
12
|
+
responsive: (containerItem, scopeElements, device, gap) => {
|
|
13
|
+
return (0, responsive_1.updateResponsiveElementDimensions)(containerItem, device, scopeElements, gap);
|
|
14
|
+
},
|
|
12
15
|
};
|
|
13
16
|
const recalculateStrategies = {
|
|
14
17
|
fixed: (elements, currentElements, canvasWidth, device, options) => {
|
|
@@ -79,16 +82,17 @@ exports.recalculateElements = recalculateElements;
|
|
|
79
82
|
* @param scopeElements A list of elements to consider in the update strategy
|
|
80
83
|
* @param device The device context (e.g., desktop, tablet, mobile) used to retrieve device-specific properties
|
|
81
84
|
* @param canvasType The type of canvas that determines which strategy to use.
|
|
85
|
+
* @param gap The type of canvas that determines which strategy to use.
|
|
82
86
|
* @returns - The updated element with modified dimensions, or `undefined` if no strategy is found.
|
|
83
87
|
*/
|
|
84
|
-
function
|
|
85
|
-
const strategy =
|
|
88
|
+
function applyDynamicSize(containerItem, scopeElements, device, canvasType, gap = 0) {
|
|
89
|
+
const strategy = applyDynamicSizeStrategies[canvasType];
|
|
86
90
|
if (!strategy) {
|
|
87
91
|
return;
|
|
88
92
|
}
|
|
89
|
-
return strategy(containerItem, scopeElements, device);
|
|
93
|
+
return strategy(containerItem, scopeElements, device, gap);
|
|
90
94
|
}
|
|
91
|
-
exports.
|
|
95
|
+
exports.applyDynamicSize = applyDynamicSize;
|
|
92
96
|
/**
|
|
93
97
|
* The calculation is delegated to a specific strategy based on the `canvasType`.
|
|
94
98
|
* @param elements - The list of elements in the canvas.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CanvasDevice } from "../interfaces/ICanvasGrid";
|
|
2
|
-
import { VemResponsive } from "../interfaces/IVemCore";
|
|
2
|
+
import { VemFixed, VemResponsive } from "../interfaces/IVemCore";
|
|
3
3
|
import { VemPositionResponsive } from "../interfaces/IVemPosition";
|
|
4
4
|
/**
|
|
5
5
|
* Finds the first available position for a new responsive element within a canvas.
|
|
@@ -85,3 +85,13 @@ export declare const sortByDistanceInResponsiveFunction: (a: {
|
|
|
85
85
|
element: VemResponsive;
|
|
86
86
|
}, _device: CanvasDevice) => number;
|
|
87
87
|
export declare const sortResponsiveElements: (elements: VemResponsive<unknown>[], sortByDevice?: CanvasDevice) => VemResponsive<unknown>[];
|
|
88
|
+
/**
|
|
89
|
+
* Updates the height (`rowSpan`) of a fixed container element based on the positions.
|
|
90
|
+
* of the fixed elements it contains, ensuring it is tall enough to encompass all child elements.
|
|
91
|
+
* @param containerItem - The container element whose height needs to be updated.
|
|
92
|
+
* @param device - The target device (used to retrieve responsive dimensions).
|
|
93
|
+
* @param scopeElements - The list of fixed elements that are scoped to the container.
|
|
94
|
+
* @param rowGapSize - row gap
|
|
95
|
+
* @returns A new container element with the updated responsive `rowSpan` height for the given device.
|
|
96
|
+
*/
|
|
97
|
+
export declare const updateResponsiveElementDimensions: (containerItem: VemResponsive<unknown>, device: CanvasDevice, scopeElements: VemFixed<unknown>[], rowGapSize: number) => VemResponsive<unknown>;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sortResponsiveElements = exports.sortByDistanceInResponsiveFunction = exports.calculateDistancesToReferencePoint = exports.getResponsiveGridElementsBottomLimit = exports.updateResponsiveElementColSpan = exports.findResponsiveAvailablePositions = exports.updateResponsivePosition = exports.findAvailablePosition = void 0;
|
|
3
|
+
exports.updateResponsiveElementDimensions = exports.sortResponsiveElements = exports.sortByDistanceInResponsiveFunction = exports.calculateDistancesToReferencePoint = exports.getResponsiveGridElementsBottomLimit = exports.updateResponsiveElementColSpan = exports.findResponsiveAvailablePositions = exports.updateResponsivePosition = exports.findAvailablePosition = void 0;
|
|
4
|
+
const general_1 = require("../../general");
|
|
4
5
|
const ICanvasGrid_1 = require("../interfaces/ICanvasGrid");
|
|
5
6
|
const IVemPosition_1 = require("../interfaces/IVemPosition");
|
|
7
|
+
const fixed_position_1 = require("../utils/fixed.position");
|
|
6
8
|
const overlap_1 = require("../utils/overlap");
|
|
7
9
|
const position_1 = require("../utils/position");
|
|
8
10
|
const SPACE_DELTA = 1;
|
|
9
11
|
const HEIGHT_DELTA = 32;
|
|
12
|
+
const CANVAS_EXTRA_ROW = 1;
|
|
10
13
|
/**
|
|
11
14
|
* Finds the first available position for a new responsive element within a canvas.
|
|
12
15
|
* @param canvasWidth - The width of the canvas in terms of columns.
|
|
@@ -164,3 +167,26 @@ const sortResponsiveElements = (elements, sortByDevice) => {
|
|
|
164
167
|
return sortedElements.map((element) => element.element);
|
|
165
168
|
};
|
|
166
169
|
exports.sortResponsiveElements = sortResponsiveElements;
|
|
170
|
+
/**
|
|
171
|
+
* Updates the height (`rowSpan`) of a fixed container element based on the positions.
|
|
172
|
+
* of the fixed elements it contains, ensuring it is tall enough to encompass all child elements.
|
|
173
|
+
* @param containerItem - The container element whose height needs to be updated.
|
|
174
|
+
* @param device - The target device (used to retrieve responsive dimensions).
|
|
175
|
+
* @param scopeElements - The list of fixed elements that are scoped to the container.
|
|
176
|
+
* @param rowGapSize - row gap
|
|
177
|
+
* @returns A new container element with the updated responsive `rowSpan` height for the given device.
|
|
178
|
+
*/
|
|
179
|
+
const updateResponsiveElementDimensions = (containerItem, device, scopeElements, rowGapSize) => {
|
|
180
|
+
let currentElement = (0, general_1.objectCopy)(containerItem);
|
|
181
|
+
const currentHeight = currentElement.position.responsive[device].rowSpan;
|
|
182
|
+
const delta = HEIGHT_DELTA + rowGapSize;
|
|
183
|
+
// height in px
|
|
184
|
+
const calculatedHeight = (0, fixed_position_1.dxGetFixedGridItemsBottomLimit)(scopeElements, device);
|
|
185
|
+
// convert to rows
|
|
186
|
+
const transformToRows = Math.round(calculatedHeight / delta);
|
|
187
|
+
currentElement = updateResponsivePosition(currentElement, {
|
|
188
|
+
rowSpan: Math.max(currentHeight, transformToRows) + CANVAS_EXTRA_ROW,
|
|
189
|
+
}, device);
|
|
190
|
+
return Object.assign({}, currentElement);
|
|
191
|
+
};
|
|
192
|
+
exports.updateResponsiveElementDimensions = updateResponsiveElementDimensions;
|
|
@@ -26,9 +26,10 @@ export declare function recalculateElements(newElements: Vem[], currentElements:
|
|
|
26
26
|
* @param scopeElements A list of elements to consider in the update strategy
|
|
27
27
|
* @param device The device context (e.g., desktop, tablet, mobile) used to retrieve device-specific properties
|
|
28
28
|
* @param canvasType The type of canvas that determines which strategy to use.
|
|
29
|
+
* @param gap The type of canvas that determines which strategy to use.
|
|
29
30
|
* @returns - The updated element with modified dimensions, or `undefined` if no strategy is found.
|
|
30
31
|
*/
|
|
31
|
-
export declare function
|
|
32
|
+
export declare function applyDynamicSize(containerItem: Vem, scopeElements: Vem[], device: CanvasDevice, canvasType: string, gap?: number): Vem | undefined;
|
|
32
33
|
/**
|
|
33
34
|
* The calculation is delegated to a specific strategy based on the `canvasType`.
|
|
34
35
|
* @param elements - The list of elements in the canvas.
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { findFixedAvailablePositions, getFixedGridElementsBottomLimit, recalculatePreservingPositions, sortElementsFromReferencePoint, updateFixedElementDimensions, } from "./fixed";
|
|
2
|
-
import { findResponsiveAvailablePositions, getResponsiveGridElementsBottomLimit, sortResponsiveElements, } from "./responsive";
|
|
2
|
+
import { findResponsiveAvailablePositions, getResponsiveGridElementsBottomLimit, sortResponsiveElements, updateResponsiveElementDimensions, } from "./responsive";
|
|
3
3
|
import { CanvasDevice, VemPositionType, } from "../interfaces";
|
|
4
4
|
import { copyDesktopPositionToDevice } from "../utils/element";
|
|
5
|
-
const
|
|
5
|
+
const applyDynamicSizeStrategies = {
|
|
6
6
|
fixed: (containerItem, scopeElements, device) => {
|
|
7
7
|
return updateFixedElementDimensions(containerItem, device, scopeElements);
|
|
8
8
|
},
|
|
9
|
+
responsive: (containerItem, scopeElements, device, gap) => {
|
|
10
|
+
return updateResponsiveElementDimensions(containerItem, device, scopeElements, gap);
|
|
11
|
+
},
|
|
9
12
|
};
|
|
10
13
|
const recalculateStrategies = {
|
|
11
14
|
fixed: (elements, currentElements, canvasWidth, device, options) => {
|
|
@@ -75,14 +78,15 @@ export function recalculateElements(newElements, currentElements, canvasWidth, c
|
|
|
75
78
|
* @param scopeElements A list of elements to consider in the update strategy
|
|
76
79
|
* @param device The device context (e.g., desktop, tablet, mobile) used to retrieve device-specific properties
|
|
77
80
|
* @param canvasType The type of canvas that determines which strategy to use.
|
|
81
|
+
* @param gap The type of canvas that determines which strategy to use.
|
|
78
82
|
* @returns - The updated element with modified dimensions, or `undefined` if no strategy is found.
|
|
79
83
|
*/
|
|
80
|
-
export function
|
|
81
|
-
const strategy =
|
|
84
|
+
export function applyDynamicSize(containerItem, scopeElements, device, canvasType, gap = 0) {
|
|
85
|
+
const strategy = applyDynamicSizeStrategies[canvasType];
|
|
82
86
|
if (!strategy) {
|
|
83
87
|
return;
|
|
84
88
|
}
|
|
85
|
-
return strategy(containerItem, scopeElements, device);
|
|
89
|
+
return strategy(containerItem, scopeElements, device, gap);
|
|
86
90
|
}
|
|
87
91
|
/**
|
|
88
92
|
* The calculation is delegated to a specific strategy based on the `canvasType`.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CanvasDevice } from "../interfaces/ICanvasGrid";
|
|
2
|
-
import { VemResponsive } from "../interfaces/IVemCore";
|
|
2
|
+
import { VemFixed, VemResponsive } from "../interfaces/IVemCore";
|
|
3
3
|
import { VemPositionResponsive } from "../interfaces/IVemPosition";
|
|
4
4
|
/**
|
|
5
5
|
* Finds the first available position for a new responsive element within a canvas.
|
|
@@ -85,3 +85,13 @@ export declare const sortByDistanceInResponsiveFunction: (a: {
|
|
|
85
85
|
element: VemResponsive;
|
|
86
86
|
}, _device: CanvasDevice) => number;
|
|
87
87
|
export declare const sortResponsiveElements: (elements: VemResponsive<unknown>[], sortByDevice?: CanvasDevice) => VemResponsive<unknown>[];
|
|
88
|
+
/**
|
|
89
|
+
* Updates the height (`rowSpan`) of a fixed container element based on the positions.
|
|
90
|
+
* of the fixed elements it contains, ensuring it is tall enough to encompass all child elements.
|
|
91
|
+
* @param containerItem - The container element whose height needs to be updated.
|
|
92
|
+
* @param device - The target device (used to retrieve responsive dimensions).
|
|
93
|
+
* @param scopeElements - The list of fixed elements that are scoped to the container.
|
|
94
|
+
* @param rowGapSize - row gap
|
|
95
|
+
* @returns A new container element with the updated responsive `rowSpan` height for the given device.
|
|
96
|
+
*/
|
|
97
|
+
export declare const updateResponsiveElementDimensions: (containerItem: VemResponsive<unknown>, device: CanvasDevice, scopeElements: VemFixed<unknown>[], rowGapSize: number) => VemResponsive<unknown>;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { objectCopy } from "../../general";
|
|
1
2
|
import { CanvasDevice } from "../interfaces/ICanvasGrid";
|
|
2
3
|
import { VemPositionType, } from "../interfaces/IVemPosition";
|
|
4
|
+
import { dxGetFixedGridItemsBottomLimit } from "../utils/fixed.position";
|
|
3
5
|
import { OverlapIntervalTree } from "../utils/overlap";
|
|
4
6
|
import { setElementPosition } from "../utils/position";
|
|
5
7
|
const SPACE_DELTA = 1;
|
|
6
8
|
const HEIGHT_DELTA = 32;
|
|
9
|
+
const CANVAS_EXTRA_ROW = 1;
|
|
7
10
|
/**
|
|
8
11
|
* Finds the first available position for a new responsive element within a canvas.
|
|
9
12
|
* @param canvasWidth - The width of the canvas in terms of columns.
|
|
@@ -153,3 +156,25 @@ export const sortResponsiveElements = (elements, sortByDevice) => {
|
|
|
153
156
|
}).sort((a, b) => sortByDistanceInResponsiveFunction(a, b, sortByDevice));
|
|
154
157
|
return sortedElements.map((element) => element.element);
|
|
155
158
|
};
|
|
159
|
+
/**
|
|
160
|
+
* Updates the height (`rowSpan`) of a fixed container element based on the positions.
|
|
161
|
+
* of the fixed elements it contains, ensuring it is tall enough to encompass all child elements.
|
|
162
|
+
* @param containerItem - The container element whose height needs to be updated.
|
|
163
|
+
* @param device - The target device (used to retrieve responsive dimensions).
|
|
164
|
+
* @param scopeElements - The list of fixed elements that are scoped to the container.
|
|
165
|
+
* @param rowGapSize - row gap
|
|
166
|
+
* @returns A new container element with the updated responsive `rowSpan` height for the given device.
|
|
167
|
+
*/
|
|
168
|
+
export const updateResponsiveElementDimensions = (containerItem, device, scopeElements, rowGapSize) => {
|
|
169
|
+
let currentElement = objectCopy(containerItem);
|
|
170
|
+
const currentHeight = currentElement.position.responsive[device].rowSpan;
|
|
171
|
+
const delta = HEIGHT_DELTA + rowGapSize;
|
|
172
|
+
// height in px
|
|
173
|
+
const calculatedHeight = dxGetFixedGridItemsBottomLimit(scopeElements, device);
|
|
174
|
+
// convert to rows
|
|
175
|
+
const transformToRows = Math.round(calculatedHeight / delta);
|
|
176
|
+
currentElement = updateResponsivePosition(currentElement, {
|
|
177
|
+
rowSpan: Math.max(currentHeight, transformToRows) + CANVAS_EXTRA_ROW,
|
|
178
|
+
}, device);
|
|
179
|
+
return Object.assign({}, currentElement);
|
|
180
|
+
};
|