@qrvey/utils 1.16.0-11 → 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.
@@ -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 updateElementDimensions(containerItem: Vem, scopeElements: Vem[], device: CanvasDevice, canvasType: string): Vem | undefined;
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.updateElementDimensions = exports.recalculateElements = void 0;
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 updateDimensionStrategies = {
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 updateElementDimensions(containerItem, scopeElements, device, canvasType) {
85
- const strategy = updateDimensionStrategies[canvasType];
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.updateElementDimensions = updateElementDimensions;
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;
@@ -0,0 +1,10 @@
1
+ import { IDataset } from "../../../qrvey/interfaces/IDataset";
2
+ import { IFUData } from "../../interfaces/ui/IFUData";
3
+ /**
4
+ * Filtering the filters by the columns of datasets.
5
+ * Module specially for CLS.
6
+ * @param data the filter data
7
+ * @param datasets the collection of datasets and their columns
8
+ * @returns A new filter data with the filtered filters by columns
9
+ */
10
+ export declare function excludeFiltersByDatasetsColumns(data: IFUData, datasets?: IDataset[]): IFUData;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.excludeFiltersByDatasetsColumns = void 0;
4
+ const getDatasetColumn_1 = require("../../../columns/helpers/getDatasetColumn");
5
+ const isEmpty_1 = require("../../../general/mix/isEmpty");
6
+ const getDatasetByColumn_1 = require("../../../qrvey/helpers/getDatasetByColumn");
7
+ /**
8
+ * Filtering the filters by the columns of datasets.
9
+ * Module specially for CLS.
10
+ * @param data the filter data
11
+ * @param datasets the collection of datasets and their columns
12
+ * @returns A new filter data with the filtered filters by columns
13
+ */
14
+ function excludeFiltersByDatasetsColumns(data, datasets = []) {
15
+ if ((0, isEmpty_1.isEmpty)(data) || (0, isEmpty_1.isEmpty)(data.scopes))
16
+ return;
17
+ if ((0, isEmpty_1.isEmpty)(datasets))
18
+ return data;
19
+ const newData = Object.assign(Object.assign({}, data), { scopes: getExcludedScopes(data.scopes, datasets) });
20
+ if (!(0, isEmpty_1.isEmpty)(newData) && newData.scopes.length > 0) {
21
+ return newData;
22
+ }
23
+ }
24
+ exports.excludeFiltersByDatasetsColumns = excludeFiltersByDatasetsColumns;
25
+ /**
26
+ *
27
+ * @param scopes
28
+ * @param datasets
29
+ */
30
+ function getExcludedScopes(scopes, datasets = []) {
31
+ return scopes
32
+ .map((scope) => (Object.assign(Object.assign({}, scope), { datasets: getExcludedDatasets(scope.datasets, datasets) })))
33
+ .filter((scope) => !(0, isEmpty_1.isEmpty)(scope) && scope.datasets.length > 0);
34
+ }
35
+ /**
36
+ *
37
+ * @param scopeDatasets
38
+ * @param datasets
39
+ */
40
+ function getExcludedDatasets(scopeDatasets, datasets) {
41
+ return scopeDatasets
42
+ .map((scopeDataset) => {
43
+ const dataset = (0, getDatasetByColumn_1.getDatasetByColumn)({ qrveyid: scopeDataset.qrveyid }, datasets);
44
+ if (!(0, isEmpty_1.isEmpty)(dataset)) {
45
+ return Object.assign(Object.assign({}, scopeDataset), { filters: getExcludedFilters(scopeDataset.filters, dataset) });
46
+ }
47
+ })
48
+ .filter((dataset) => !(0, isEmpty_1.isEmpty)(dataset) && dataset.filters.length > 0);
49
+ }
50
+ /**
51
+ *
52
+ * @param filters
53
+ * @param dataset
54
+ */
55
+ function getExcludedFilters(filters, dataset) {
56
+ return filters
57
+ .map((filter) => {
58
+ const column = (0, getDatasetColumn_1.getDatasetColumn)(filter.column, dataset);
59
+ if ((0, isEmpty_1.isEmpty)(column)) {
60
+ return Object.assign({}, filter);
61
+ }
62
+ })
63
+ .filter(Boolean);
64
+ }
@@ -44,3 +44,4 @@ export * from "./mergeValues";
44
44
  export * from "./resolveDatasetConditions";
45
45
  export * from "./resolveFilterConditions";
46
46
  export * from "./resolveScopeConditions";
47
+ export * from "./excludeFiltersByDatasetsColumns";
@@ -60,3 +60,4 @@ __exportStar(require("./mergeValues"), exports);
60
60
  __exportStar(require("./resolveDatasetConditions"), exports);
61
61
  __exportStar(require("./resolveFilterConditions"), exports);
62
62
  __exportStar(require("./resolveScopeConditions"), exports);
63
+ __exportStar(require("./excludeFiltersByDatasetsColumns"), exports);
@@ -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 updateElementDimensions(containerItem: Vem, scopeElements: Vem[], device: CanvasDevice, canvasType: string): Vem | undefined;
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 updateDimensionStrategies = {
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 updateElementDimensions(containerItem, scopeElements, device, canvasType) {
81
- const strategy = updateDimensionStrategies[canvasType];
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
+ };
@@ -0,0 +1,10 @@
1
+ import { IDataset } from "../../../qrvey/interfaces/IDataset";
2
+ import { IFUData } from "../../interfaces/ui/IFUData";
3
+ /**
4
+ * Filtering the filters by the columns of datasets.
5
+ * Module specially for CLS.
6
+ * @param data the filter data
7
+ * @param datasets the collection of datasets and their columns
8
+ * @returns A new filter data with the filtered filters by columns
9
+ */
10
+ export declare function excludeFiltersByDatasetsColumns(data: IFUData, datasets?: IDataset[]): IFUData;
@@ -0,0 +1,60 @@
1
+ import { getDatasetColumn } from "../../../columns/helpers/getDatasetColumn";
2
+ import { isEmpty } from "../../../general/mix/isEmpty";
3
+ import { getDatasetByColumn } from "../../../qrvey/helpers/getDatasetByColumn";
4
+ /**
5
+ * Filtering the filters by the columns of datasets.
6
+ * Module specially for CLS.
7
+ * @param data the filter data
8
+ * @param datasets the collection of datasets and their columns
9
+ * @returns A new filter data with the filtered filters by columns
10
+ */
11
+ export function excludeFiltersByDatasetsColumns(data, datasets = []) {
12
+ if (isEmpty(data) || isEmpty(data.scopes))
13
+ return;
14
+ if (isEmpty(datasets))
15
+ return data;
16
+ const newData = Object.assign(Object.assign({}, data), { scopes: getExcludedScopes(data.scopes, datasets) });
17
+ if (!isEmpty(newData) && newData.scopes.length > 0) {
18
+ return newData;
19
+ }
20
+ }
21
+ /**
22
+ *
23
+ * @param scopes
24
+ * @param datasets
25
+ */
26
+ function getExcludedScopes(scopes, datasets = []) {
27
+ return scopes
28
+ .map((scope) => (Object.assign(Object.assign({}, scope), { datasets: getExcludedDatasets(scope.datasets, datasets) })))
29
+ .filter((scope) => !isEmpty(scope) && scope.datasets.length > 0);
30
+ }
31
+ /**
32
+ *
33
+ * @param scopeDatasets
34
+ * @param datasets
35
+ */
36
+ function getExcludedDatasets(scopeDatasets, datasets) {
37
+ return scopeDatasets
38
+ .map((scopeDataset) => {
39
+ const dataset = getDatasetByColumn({ qrveyid: scopeDataset.qrveyid }, datasets);
40
+ if (!isEmpty(dataset)) {
41
+ return Object.assign(Object.assign({}, scopeDataset), { filters: getExcludedFilters(scopeDataset.filters, dataset) });
42
+ }
43
+ })
44
+ .filter((dataset) => !isEmpty(dataset) && dataset.filters.length > 0);
45
+ }
46
+ /**
47
+ *
48
+ * @param filters
49
+ * @param dataset
50
+ */
51
+ function getExcludedFilters(filters, dataset) {
52
+ return filters
53
+ .map((filter) => {
54
+ const column = getDatasetColumn(filter.column, dataset);
55
+ if (isEmpty(column)) {
56
+ return Object.assign({}, filter);
57
+ }
58
+ })
59
+ .filter(Boolean);
60
+ }
@@ -44,3 +44,4 @@ export * from "./mergeValues";
44
44
  export * from "./resolveDatasetConditions";
45
45
  export * from "./resolveFilterConditions";
46
46
  export * from "./resolveScopeConditions";
47
+ export * from "./excludeFiltersByDatasetsColumns";
@@ -44,3 +44,4 @@ export * from "./mergeValues";
44
44
  export * from "./resolveDatasetConditions";
45
45
  export * from "./resolveFilterConditions";
46
46
  export * from "./resolveScopeConditions";
47
+ export * from "./excludeFiltersByDatasetsColumns";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.16.0-11",
3
+ "version": "1.16.0-13",
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",