@itwin/saved-views-react 1.1.0 → 1.1.2
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyExtraction, extractArray, extractArrayConditionally, extractBoolean, extractColor, extractColorLegacy, extractConditionally, extractLinePixels, extractNumber, extractNumberOrBool, extractObject, extractPlainTypedMap, extractRGB, extractSimpleArray, extractString, extractStringOrArray, extractStringOrNumber, extractStringOrNumberArray, isAnyColorFormat, simpleTypeOf, } from "./extractionUtilities.js";
|
|
1
|
+
import { applyExtraction, extractArray, extractArrayConditionally, extractArrayElementsConditionally, extractBoolean, extractColor, extractColorLegacy, extractConditionally, extractLinePixels, extractNumber, extractNumberOrBool, extractObject, extractPlainTypedMap, extractRGB, extractSimpleArray, extractString, extractStringOrArray, extractStringOrNumber, extractStringOrNumberArray, extractValidPlainTypedMap, isAnyColorFormat, simpleTypeOf, simpleTypeOrArrayOf, } from "./extractionUtilities.js";
|
|
2
2
|
const viewFlagMappings = [
|
|
3
3
|
extractNumber("renderMode"),
|
|
4
4
|
extractBoolean("noConstructions", "noConstruct"),
|
|
@@ -202,6 +202,8 @@ const imageMapLayerPropsMapping = [
|
|
|
202
202
|
extractString("url"),
|
|
203
203
|
extractString("formatId"),
|
|
204
204
|
extractArray(mapSubLayerMappings, "subLayers"),
|
|
205
|
+
extractValidPlainTypedMap(simpleTypeOf("string"), simpleTypeOf("string"), "queryParams"),
|
|
206
|
+
extractValidPlainTypedMap(simpleTypeOrArrayOf(["string", "number", "boolean"]), simpleTypeOf("string"), "properties"),
|
|
205
207
|
];
|
|
206
208
|
const baseMapLayerPropsMapping = [
|
|
207
209
|
...imageMapLayerPropsMapping,
|
|
@@ -411,7 +413,7 @@ const displayStylesLegacyMapping = [
|
|
|
411
413
|
extractNumber("timePoint"),
|
|
412
414
|
extractArray(displayStyleSubCategoryLegacyMappings, "subCategoryOvr", "subCategoryOverrides"),
|
|
413
415
|
extractObject(backgroundMapMappings, "backgroundMap"),
|
|
414
|
-
|
|
416
|
+
extractArrayElementsConditionally((value) => value && !value.invisible, contextRealityModelsLegacyMappings, "contextRealityModels"),
|
|
415
417
|
extractStringOrArray("excludedElements"),
|
|
416
418
|
extractObject(mapImageryLegacyMapping, "mapImagery"),
|
|
417
419
|
extractArray(displayStyleModelAppearanceLegacyMappings, "modelOvr", "modelOverrides"),
|
|
@@ -5,6 +5,12 @@ import type { Rgba, RgbatColorProps } from "./RgbColor.js";
|
|
|
5
5
|
* @returns
|
|
6
6
|
*/
|
|
7
7
|
export declare const simpleTypeOf: (typeOfString: string) => (value: unknown) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Returns a function that does determines if a value is of any of the provided types or arrays of those types
|
|
10
|
+
* @param typeOfString Array of strings to compare against type
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare const simpleTypeOrArrayOf: (typeOfString: string[]) => (value: unknown) => boolean;
|
|
8
14
|
/**
|
|
9
15
|
* Returns true if the given value is in any of the color formats that we accept to transform
|
|
10
16
|
* @param value
|
|
@@ -185,6 +191,16 @@ export declare const extractConditionally: (params: ConditionalExtractParams[],
|
|
|
185
191
|
* @param extractionFunc
|
|
186
192
|
*/
|
|
187
193
|
export declare const extractArray: (extractionFunc: ExtractionFunc<void, void>[], from: string, to?: string) => (input: any, output: any) => void;
|
|
194
|
+
/**
|
|
195
|
+
* Creates an extraction function that will extract each value of an array if it meets the given condition
|
|
196
|
+
* by using a single extraction function on each of the array values
|
|
197
|
+
* @param condition Function that checks if the value should be extracted
|
|
198
|
+
* @param extractionFunc Array of extraction functions to apply to each value in the array that meets the condition
|
|
199
|
+
* @param from Accessor string where the array is in the input object
|
|
200
|
+
* @param to Accessor string to store it in the output object
|
|
201
|
+
* @returns Function that extracts an array of values conditionally
|
|
202
|
+
*/
|
|
203
|
+
export declare const extractArrayElementsConditionally: (condition: (value: any) => boolean, extractionFunc: ExtractionFunc<void, void>[], from: string, to?: string) => (input: any, output: any) => void;
|
|
188
204
|
/**
|
|
189
205
|
* Creates an extraction function that will extract the values inside a 2D array from the given accessor
|
|
190
206
|
* @param extractionFunc Extraction functions to apply to each entry in the array
|
|
@@ -207,6 +223,15 @@ export declare const extractArrayConditionally: (params: ConditionalExtractParam
|
|
|
207
223
|
* @returns
|
|
208
224
|
*/
|
|
209
225
|
export declare const extractPlainTypedMap: (extractionFuncs: ExtractionFunc<void, void>[], isValidKey: (key: unknown) => boolean, from: string, to?: string) => (input: any, output: any) => void;
|
|
226
|
+
/**
|
|
227
|
+
* Creates an extraction function that will extract a plain typed map
|
|
228
|
+
* @param isValidValue Checker for the validity of the values
|
|
229
|
+
* @param isValidKey Checker for the validity of the key
|
|
230
|
+
* @param from Accessor where the plain typed map exists
|
|
231
|
+
* @param to Accessor to store the plain typed map to
|
|
232
|
+
* @returns
|
|
233
|
+
*/
|
|
234
|
+
export declare const extractValidPlainTypedMap: (isValidValue: (value: unknown) => boolean, isValidKey: (key: unknown) => boolean, from: string, to?: string) => (input: any, output: any) => void;
|
|
210
235
|
/**
|
|
211
236
|
* Applies an array of extraction functions to extract the data from the input object
|
|
212
237
|
* into the output object
|
|
@@ -12,6 +12,19 @@ import { LinePixels } from "@itwin/saved-views-client";
|
|
|
12
12
|
export const simpleTypeOf = (typeOfString) => {
|
|
13
13
|
return (value) => typeof value === typeOfString;
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Returns a function that does determines if a value is of any of the provided types or arrays of those types
|
|
17
|
+
* @param typeOfString Array of strings to compare against type
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export const simpleTypeOrArrayOf = (typeOfString) => {
|
|
21
|
+
return (value) => typeOfString.some((type) => {
|
|
22
|
+
if (Array.isArray(value)) {
|
|
23
|
+
return value.every((inner) => typeof inner === type);
|
|
24
|
+
}
|
|
25
|
+
return typeof value === type;
|
|
26
|
+
});
|
|
27
|
+
};
|
|
15
28
|
/**
|
|
16
29
|
* Type check for colors in format {r: number, g: number, b:number}
|
|
17
30
|
* @param value
|
|
@@ -439,6 +452,34 @@ export const extractArray = (extractionFunc, from, to) => {
|
|
|
439
452
|
}
|
|
440
453
|
};
|
|
441
454
|
};
|
|
455
|
+
/**
|
|
456
|
+
* Creates an extraction function that will extract each value of an array if it meets the given condition
|
|
457
|
+
* by using a single extraction function on each of the array values
|
|
458
|
+
* @param condition Function that checks if the value should be extracted
|
|
459
|
+
* @param extractionFunc Array of extraction functions to apply to each value in the array that meets the condition
|
|
460
|
+
* @param from Accessor string where the array is in the input object
|
|
461
|
+
* @param to Accessor string to store it in the output object
|
|
462
|
+
* @returns Function that extracts an array of values conditionally
|
|
463
|
+
*/
|
|
464
|
+
export const extractArrayElementsConditionally = (
|
|
465
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
466
|
+
condition, extractionFunc, from, to) => {
|
|
467
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
468
|
+
return (input, output) => {
|
|
469
|
+
const adjustedTo = to ?? from;
|
|
470
|
+
if (input[from] !== undefined && Array.isArray(input[from])) {
|
|
471
|
+
output[adjustedTo] = [];
|
|
472
|
+
let outputIndex = 0;
|
|
473
|
+
input[from].forEach((_, index) => {
|
|
474
|
+
if (condition(input[from][index])) {
|
|
475
|
+
output[adjustedTo].push({});
|
|
476
|
+
extractionFunc.forEach((func) => func(input[from][index], output[adjustedTo][outputIndex]));
|
|
477
|
+
outputIndex++;
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
};
|
|
442
483
|
/**
|
|
443
484
|
* Creates an extraction function that will extract the values inside a 2D array from the given accessor
|
|
444
485
|
* @param extractionFunc Extraction functions to apply to each entry in the array
|
|
@@ -515,6 +556,28 @@ export const extractPlainTypedMap = (extractionFuncs, isValidKey, from, to) => {
|
|
|
515
556
|
}
|
|
516
557
|
};
|
|
517
558
|
};
|
|
559
|
+
/**
|
|
560
|
+
* Creates an extraction function that will extract a plain typed map
|
|
561
|
+
* @param isValidValue Checker for the validity of the values
|
|
562
|
+
* @param isValidKey Checker for the validity of the key
|
|
563
|
+
* @param from Accessor where the plain typed map exists
|
|
564
|
+
* @param to Accessor to store the plain typed map to
|
|
565
|
+
* @returns
|
|
566
|
+
*/
|
|
567
|
+
export const extractValidPlainTypedMap = (isValidValue, isValidKey, from, to) => {
|
|
568
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
569
|
+
return (input, output) => {
|
|
570
|
+
if (input[from] !== undefined) {
|
|
571
|
+
const adjustedTo = to ?? from;
|
|
572
|
+
output[adjustedTo] = {};
|
|
573
|
+
for (const prop in input[from]) {
|
|
574
|
+
if (isValidKey(prop) && isValidValue(input[from][prop])) {
|
|
575
|
+
output[adjustedTo][prop] = input[from][prop];
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
};
|
|
518
581
|
/**
|
|
519
582
|
* Applies an array of extraction functions to extract the data from the input object
|
|
520
583
|
* into the output object
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/saved-views-react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@itwin/itwinui-icons-react": "^2.9.0",
|
|
69
69
|
"@itwin/itwinui-react": "^3.15.0",
|
|
70
70
|
"fuse.js": "^6.6.2",
|
|
71
|
-
"@itwin/saved-views-client": "^0.5.
|
|
71
|
+
"@itwin/saved-views-client": "^0.5.3"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"build": "run-p build:*",
|