@itwin/saved-views-react 0.1.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/LICENSE.md +9 -0
- package/README.md +131 -0
- package/lib/LayeredDropdownMenu/LayeredDropdownMenu.css +11 -0
- package/lib/LayeredDropdownMenu/LayeredDropdownMenu.d.ts +39 -0
- package/lib/LayeredDropdownMenu/LayeredDropdownMenu.js +53 -0
- package/lib/SavedView.d.ts +18 -0
- package/lib/SavedView.js +1 -0
- package/lib/SavedViewTile/SavedViewOptions.css +26 -0
- package/lib/SavedViewTile/SavedViewOptions.d.ts +139 -0
- package/lib/SavedViewTile/SavedViewOptions.js +173 -0
- package/lib/SavedViewTile/SavedViewTile.css +89 -0
- package/lib/SavedViewTile/SavedViewTile.d.ts +55 -0
- package/lib/SavedViewTile/SavedViewTile.js +110 -0
- package/lib/SavedViewTile/SavedViewTileContext.d.ts +14 -0
- package/lib/SavedViewTile/SavedViewTileContext.js +20 -0
- package/lib/SavedViewsClient/ITwinSavedViewsClient.d.ts +30 -0
- package/lib/SavedViewsClient/ITwinSavedViewsClient.js +132 -0
- package/lib/SavedViewsClient/SavedViewsClient.d.ts +72 -0
- package/lib/SavedViewsClient/SavedViewsClient.js +1 -0
- package/lib/SavedViewsContext.d.ts +13 -0
- package/lib/SavedViewsContext.js +38 -0
- package/lib/SavedViewsWidget/SavedViewGroupTile/SavedViewGroupOptions.d.ts +9 -0
- package/lib/SavedViewsWidget/SavedViewGroupTile/SavedViewGroupOptions.js +14 -0
- package/lib/SavedViewsWidget/SavedViewGroupTile/SavedViewGroupTile.d.ts +14 -0
- package/lib/SavedViewsWidget/SavedViewGroupTile/SavedViewGroupTile.js +37 -0
- package/lib/SavedViewsWidget/SavedViewGroupTile/SavedViewGroupTileContext.d.ts +14 -0
- package/lib/SavedViewsWidget/SavedViewGroupTile/SavedViewGroupTileContext.js +20 -0
- package/lib/SavedViewsWidget/SavedViewsExpandableBlockWidget.css +50 -0
- package/lib/SavedViewsWidget/SavedViewsExpandableBlockWidget.d.ts +36 -0
- package/lib/SavedViewsWidget/SavedViewsExpandableBlockWidget.js +36 -0
- package/lib/SavedViewsWidget/SavedViewsFolderWidget.d.ts +14 -0
- package/lib/SavedViewsWidget/SavedViewsFolderWidget.js +60 -0
- package/lib/StickyExpandableBlock/StickyExpandableBlock.css +20 -0
- package/lib/StickyExpandableBlock/StickyExpandableBlock.d.ts +29 -0
- package/lib/StickyExpandableBlock/StickyExpandableBlock.js +63 -0
- package/lib/TileGrid/TileGrid.css +28 -0
- package/lib/TileGrid/TileGrid.d.ts +48 -0
- package/lib/TileGrid/TileGrid.js +32 -0
- package/lib/api/clients/IModelQueryClient.d.ts +10 -0
- package/lib/api/clients/IModelQueryClient.js +45 -0
- package/lib/api/clients/ISavedViewsClient.d.ts +9 -0
- package/lib/api/clients/ISavedViewsClient.js +16 -0
- package/lib/api/utilities/SavedViewTypes.d.ts +48 -0
- package/lib/api/utilities/SavedViewTypes.js +1 -0
- package/lib/api/utilities/translation/ModelsAndCategoriesHelper.d.ts +3 -0
- package/lib/api/utilities/translation/ModelsAndCategoriesHelper.js +57 -0
- package/lib/api/utilities/translation/RgbColor.d.ts +29 -0
- package/lib/api/utilities/translation/RgbColor.js +1 -0
- package/lib/api/utilities/translation/SavedViewTranslation.d.ts +22 -0
- package/lib/api/utilities/translation/SavedViewTranslation.js +246 -0
- package/lib/api/utilities/translation/SavedViewsExtensionHandlers.d.ts +13 -0
- package/lib/api/utilities/translation/SavedViewsExtensionHandlers.js +42 -0
- package/lib/api/utilities/translation/clipVectorsExtractor.d.ts +5 -0
- package/lib/api/utilities/translation/clipVectorsExtractor.js +56 -0
- package/lib/api/utilities/translation/displayStyleExtractor.d.ts +17 -0
- package/lib/api/utilities/translation/displayStyleExtractor.js +499 -0
- package/lib/api/utilities/translation/extensionExtractor.d.ts +18 -0
- package/lib/api/utilities/translation/extensionExtractor.js +79 -0
- package/lib/api/utilities/translation/extractionUtilities.d.ts +209 -0
- package/lib/api/utilities/translation/extractionUtilities.js +515 -0
- package/lib/api/utilities/translation/urlConverter.d.ts +7 -0
- package/lib/api/utilities/translation/urlConverter.js +42 -0
- package/lib/api/utilities/translation/viewExtractorSavedViewToLegacySavedView.d.ts +35 -0
- package/lib/api/utilities/translation/viewExtractorSavedViewToLegacySavedView.js +298 -0
- package/lib/experimental.d.ts +4 -0
- package/lib/experimental.js +8 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +14 -0
- package/lib/localization.d.ts +52 -0
- package/lib/localization.js +51 -0
- package/lib/ui/viewlist/ModelCategoryOverrideProvider.d.ts +31 -0
- package/lib/ui/viewlist/ModelCategoryOverrideProvider.js +88 -0
- package/lib/useSavedViews.d.ts +52 -0
- package/lib/useSavedViews.js +514 -0
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +7 -0
- package/package.json +75 -0
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { ColorDef } from "@itwin/core-common";
|
|
6
|
+
/**
|
|
7
|
+
* Returns a function that does a simple typeof check on a value
|
|
8
|
+
* @param typeOfString String to compare against
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export const simpleTypeOf = (typeOfString) => {
|
|
12
|
+
return (value) => typeof value === typeOfString;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Type check for colors in format {r: number, g: number, b:number}
|
|
16
|
+
* @param value
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
const isRgbColorProps = (value) => {
|
|
20
|
+
return (typeof value === "object" &&
|
|
21
|
+
value !== null &&
|
|
22
|
+
"r" in value &&
|
|
23
|
+
typeof value.r === "number" &&
|
|
24
|
+
"g" in value &&
|
|
25
|
+
typeof value.g === "number" &&
|
|
26
|
+
"b" in value &&
|
|
27
|
+
typeof value.b === "number");
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Type check for colors in our schema format {red: number, green: number, blue: number}
|
|
31
|
+
* @param value
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
const isSchemaRgbColor = (value) => {
|
|
35
|
+
return (typeof value === "object" &&
|
|
36
|
+
value !== null &&
|
|
37
|
+
"red" in value &&
|
|
38
|
+
typeof value.red === "number" &&
|
|
39
|
+
"green" in value &&
|
|
40
|
+
typeof value.green === "number" &&
|
|
41
|
+
"blue" in value &&
|
|
42
|
+
typeof value.blue === "number");
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Returns true if the value is a ColorDef, which is simply a number
|
|
46
|
+
* @param value
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
const isColorDef = (value) => {
|
|
50
|
+
return ColorDef.isValidColor(value);
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Returns true if the given value is in any of the color formats that we accept to transform
|
|
54
|
+
* @param value
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
export const isAnyColorFormat = (value) => isColorDef(value) ||
|
|
58
|
+
isRgbColorProps(value) ||
|
|
59
|
+
isSchemaRgbColor(value);
|
|
60
|
+
// data format is broken into bits for storage of color
|
|
61
|
+
// data format is 0xTTBBGGRR
|
|
62
|
+
// where TT is the transparency bits
|
|
63
|
+
// BB GG RR are the color bits (BB =blue GG= green RR= red)
|
|
64
|
+
// something that if fully one color would be FF or 1111 1111
|
|
65
|
+
const mapColorsToBitShiftedEquivalent = (color) => {
|
|
66
|
+
const colorCodeRed = color.red; //0x 00 00 00 RR Binary 0000 0000 0000 0000 0000 0000 RRRR RRRR
|
|
67
|
+
const colorCodeGreen = color.green << 8; //0x 00 00 GG 00 Binary 0000 0000 0000 0000 GGGG GGGG 0000 0000
|
|
68
|
+
const colorCodeBlue = color.blue << 16; //0x 00 BB 00 00 Binary 0000 0000 BBBB BBBB 0000 0000 0000 0000
|
|
69
|
+
const colorCodeTransparency = (color.transparency ?? 0) << 24; //0x TT 00 00 00 Binary TTTT TTTT 0000 0000 0000 0000 0000 0000
|
|
70
|
+
return {
|
|
71
|
+
red: colorCodeRed,
|
|
72
|
+
green: colorCodeGreen,
|
|
73
|
+
blue: colorCodeBlue,
|
|
74
|
+
transparency: colorCodeTransparency,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Transforms new color value object into color format 0xTTBBGGRR value new schema ({red: number,green: number,blue:number, alpha?: number ,transparency})
|
|
79
|
+
* @param value
|
|
80
|
+
* @returns color value that is 0xTTBBGGRR
|
|
81
|
+
*/
|
|
82
|
+
const transformSchemaColor = (value) => {
|
|
83
|
+
const color = {
|
|
84
|
+
red: value.red,
|
|
85
|
+
green: value.green,
|
|
86
|
+
blue: value.blue,
|
|
87
|
+
transparency: value.alpha ? 255 - value.alpha : 0,
|
|
88
|
+
};
|
|
89
|
+
const colorsBitShifted = mapColorsToBitShiftedEquivalent(color);
|
|
90
|
+
// mix colors codes together using bit shifted or operator
|
|
91
|
+
const combineBitsForFinalColorCode = (colorsBitShifted) => {
|
|
92
|
+
return (colorsBitShifted.red |
|
|
93
|
+
colorsBitShifted.green |
|
|
94
|
+
colorsBitShifted.blue |
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
96
|
+
color.transparency);
|
|
97
|
+
};
|
|
98
|
+
return combineBitsForFinalColorCode(colorsBitShifted);
|
|
99
|
+
};
|
|
100
|
+
const createRGB = (value) => {
|
|
101
|
+
return {
|
|
102
|
+
r: value.red,
|
|
103
|
+
g: value.green,
|
|
104
|
+
b: value.blue,
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Transforms a vanilla value into our format {red: number,green: number,blue:number, alpha?: number}
|
|
109
|
+
* @param value
|
|
110
|
+
* @returns
|
|
111
|
+
*/
|
|
112
|
+
const transformSchemaColorLegacy = (value) => {
|
|
113
|
+
const color = {
|
|
114
|
+
red: value.red,
|
|
115
|
+
green: value.green,
|
|
116
|
+
blue: value.blue,
|
|
117
|
+
};
|
|
118
|
+
if (value.alpha) {
|
|
119
|
+
color.alpha = value.alpha;
|
|
120
|
+
}
|
|
121
|
+
return color;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Transform RgbColorProps {r,g,b} to our schema {red,green,blue}
|
|
125
|
+
* @param value
|
|
126
|
+
* @returns
|
|
127
|
+
*/
|
|
128
|
+
const transformRgbColorPropsLegacy = (value) => {
|
|
129
|
+
const color = {
|
|
130
|
+
red: value.r,
|
|
131
|
+
green: value.g,
|
|
132
|
+
blue: value.b,
|
|
133
|
+
};
|
|
134
|
+
if (value?.a !== undefined) {
|
|
135
|
+
color.alpha = value?.a;
|
|
136
|
+
}
|
|
137
|
+
return color;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Transform ColorDef 0xTTBBGGRR to our schema {red,green,blue,alpha if existent}
|
|
141
|
+
* @param value
|
|
142
|
+
*/
|
|
143
|
+
const transformColorDefLegacy = (value) => {
|
|
144
|
+
const color = {
|
|
145
|
+
red: value & 0xff,
|
|
146
|
+
green: (value & 0xff00) >> 8,
|
|
147
|
+
blue: (value & 0xff0000) >> 16,
|
|
148
|
+
};
|
|
149
|
+
// Extract alpha from transparency
|
|
150
|
+
if ((value & 0xff000000) !== 0) {
|
|
151
|
+
color.alpha = 255 - ((value & 0xff000000) >> 24);
|
|
152
|
+
}
|
|
153
|
+
return color;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Transforms any of the three types of colors into our schema color format {red: number, green: number, blue: number}
|
|
157
|
+
* Legacy to new schema
|
|
158
|
+
* @param value
|
|
159
|
+
* @returns
|
|
160
|
+
*/
|
|
161
|
+
export const transformColorLegacy = (value) => {
|
|
162
|
+
// No need to extract if already follows schema convention
|
|
163
|
+
if (isSchemaRgbColor(value)) {
|
|
164
|
+
return transformSchemaColorLegacy(value);
|
|
165
|
+
}
|
|
166
|
+
// Extract RgbColorProps format
|
|
167
|
+
if (isRgbColorProps(value)) {
|
|
168
|
+
return transformRgbColorPropsLegacy(value);
|
|
169
|
+
}
|
|
170
|
+
// Extract 0xTTBBGGRR format
|
|
171
|
+
if (isColorDef(value)) {
|
|
172
|
+
return transformColorDefLegacy(value);
|
|
173
|
+
}
|
|
174
|
+
return undefined;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Transforms any of the two types of colors into our schema color format 0xttbbggrr
|
|
178
|
+
* @param value
|
|
179
|
+
* @returns
|
|
180
|
+
*/
|
|
181
|
+
export const transformColor = (value) => {
|
|
182
|
+
// Transform New Schema Into Legacy Schema( Color Def)
|
|
183
|
+
if (isSchemaRgbColor(value)) {
|
|
184
|
+
return transformSchemaColor(value);
|
|
185
|
+
}
|
|
186
|
+
// Extract 0xTTBBGGRR format we want this format
|
|
187
|
+
if (isColorDef(value)) {
|
|
188
|
+
return value;
|
|
189
|
+
}
|
|
190
|
+
return undefined;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Transforms any of the three types of colors into our schema color format {r: number, g: number, b: number}
|
|
194
|
+
* @param value
|
|
195
|
+
* @returns
|
|
196
|
+
*/
|
|
197
|
+
export const transformRGB = (value) => {
|
|
198
|
+
// Extract RgbColorProps format
|
|
199
|
+
if (isSchemaRgbColor(value)) {
|
|
200
|
+
return createRGB(value);
|
|
201
|
+
}
|
|
202
|
+
//is already the proper format
|
|
203
|
+
if (isRgbColorProps(value)) {
|
|
204
|
+
return value;
|
|
205
|
+
}
|
|
206
|
+
return undefined;
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Creates a function that extracts a value from input to output
|
|
210
|
+
* @param from Accessor from where to retrieve the value
|
|
211
|
+
* @param to Accessor to add to the output object to store the value
|
|
212
|
+
* @param typeCheck Type checker for validation of the value
|
|
213
|
+
* @param transform Transform function of the value to be put in the output
|
|
214
|
+
* @returns Function that does the extraction
|
|
215
|
+
*/
|
|
216
|
+
export const createExtractionFunc = (from, to, typeCheck, transform) => {
|
|
217
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
218
|
+
return (input, output) => {
|
|
219
|
+
if (input[from] !== undefined && (!typeCheck || typeCheck(input[from]))) {
|
|
220
|
+
output[to] = transform ? transform(input[from]) : input[from];
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Creates a extraction function that will extract a number from the given accessor and put it
|
|
226
|
+
* in the given accessor if provided
|
|
227
|
+
* @param from Accessor that will be used on input to access value
|
|
228
|
+
* @param to Accessor that will be used to stored the value in the output object
|
|
229
|
+
* @returns Function that extracts a number value and type checks it
|
|
230
|
+
*/
|
|
231
|
+
export const extractNumber = (from, to) => {
|
|
232
|
+
return createExtractionFunc(from, to ?? from, simpleTypeOf("number"));
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Creates a extraction function that will extract a boolean from the given accessor and put it
|
|
236
|
+
* in the given accessor if provided
|
|
237
|
+
* @param from Accessor that will be used on input to access value
|
|
238
|
+
* @param to Accessor that will be used to stored the value in the output object
|
|
239
|
+
* @returns Function that extracts a boolean value and type checks it
|
|
240
|
+
*/
|
|
241
|
+
export const extractBoolean = (from, to) => {
|
|
242
|
+
return createExtractionFunc(from, to ?? from, simpleTypeOf("boolean"));
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* Creates a extraction function that will extract a boolean or a number with the same accessor name
|
|
246
|
+
* @param from Accessor that will be used on input to access value
|
|
247
|
+
* @param to Accessor that will be used to stored the value in the output object
|
|
248
|
+
* @returns Function that extracts a boolean or number value and type checks it
|
|
249
|
+
*/
|
|
250
|
+
export const extractNumberOrBool = (from, to) => {
|
|
251
|
+
return createExtractionFunc(from, to ?? from, (value) => typeof value === "number" || typeof value === "boolean");
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Creates a extraction function that will extract a string from the given accessor and put it
|
|
255
|
+
* in the given accessor if provided
|
|
256
|
+
* @param from Accessor that will be used on input to access value
|
|
257
|
+
* @param to Accessor that will be used to stored the value in the output object
|
|
258
|
+
* @returns Function that extracts a string value and type checks it
|
|
259
|
+
*/
|
|
260
|
+
export const extractString = (from, to) => {
|
|
261
|
+
return createExtractionFunc(from, to ?? from, simpleTypeOf("string"));
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* Creates a extraction function that will extract a string or number from them given accessor
|
|
265
|
+
* @param from Accessor that will be used on input to access value
|
|
266
|
+
* @param to Accessor that will be used to stored the value in the output object
|
|
267
|
+
* @returns Function that extracts a string or number value and type checks it
|
|
268
|
+
*/
|
|
269
|
+
export const extractStringOrNumber = (from, to) => {
|
|
270
|
+
return createExtractionFunc(from, to ?? from, (value) => typeof value === "number" || typeof value === "string");
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Creates a extraction function that will extract a string or an array of strings into the given
|
|
274
|
+
* accessor
|
|
275
|
+
* @param from Accessor that will be used on input to access value
|
|
276
|
+
* @param to Accessor that will be used to stored the value in the output object
|
|
277
|
+
* @returns Function that extracts a string or string array value and type checks it
|
|
278
|
+
*/
|
|
279
|
+
export const extractStringOrArray = (from, to) => {
|
|
280
|
+
return createExtractionFunc(from, to ?? from, (value) => typeof value === "string" ||
|
|
281
|
+
(Array.isArray(value) &&
|
|
282
|
+
value.every((inner) => typeof inner === "string")));
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* Creates a extraction function that will extract an array of type: (string | number)[]
|
|
286
|
+
* @param from Accessor that will be used on input to access value
|
|
287
|
+
* @param to Accessor that will be used to stored the value in the output object
|
|
288
|
+
* @returns Function that extracts a string | number array value and type checks it
|
|
289
|
+
*/
|
|
290
|
+
export const extractStringOrNumberArray = (from, to) => {
|
|
291
|
+
return createExtractionFunc(from, to ?? from, (value) => Array.isArray(value) &&
|
|
292
|
+
value.every((val) => typeof val === "number" || typeof val === "string"));
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Creates a extraction function that will extract an array in which all the elements are type checked with the
|
|
296
|
+
* given function
|
|
297
|
+
* @param typeCheck Function to check each value of the array
|
|
298
|
+
* @param from Accessor string where the array is in the input object
|
|
299
|
+
* @param to Accessor string to store it in the output object
|
|
300
|
+
* @returns
|
|
301
|
+
*/
|
|
302
|
+
export const extractSimpleArray = (typeCheck, from, to) => {
|
|
303
|
+
return createExtractionFunc(from, to ?? from, (value) => Array.isArray(value) && value.every((val) => typeCheck(val)));
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* Creates a extraction function that will extract a color from the given accessor and put it
|
|
307
|
+
* in the given accessor if provided. Colors will be transformed from either of the following representations:
|
|
308
|
+
* 1. Number in format: 0xTTBBGGRR
|
|
309
|
+
* 2. JSON Object in format: {r: number, g: number, b: number}
|
|
310
|
+
* 3. JSON Object in format: {red: number, green: number, blue: number}
|
|
311
|
+
*
|
|
312
|
+
* The resulting transformed color will be in format: {red: number, green: number, blue: number}
|
|
313
|
+
*
|
|
314
|
+
* @param from Accessor that will be used on input to access value
|
|
315
|
+
* @param to Accessor that will be used to store the value in the output object
|
|
316
|
+
* @returns Function that extracts a color value and type checks it
|
|
317
|
+
*/
|
|
318
|
+
export const extractColor = (from, to) => {
|
|
319
|
+
return createExtractionFunc(from, to ?? from, isAnyColorFormat, transformColor);
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* Creates a extraction function that will extract a color from the given accessor and put it
|
|
323
|
+
* in the given accessor if provided. Colors will be transformed from either of the following representations:
|
|
324
|
+
* 1. Number in format: 0xTTBBGGRR
|
|
325
|
+
* 2. JSON Object in format: {r: number, g: number, b: number}
|
|
326
|
+
* 3. JSON Object in format: {red: number, green: number, blue: number}
|
|
327
|
+
*
|
|
328
|
+
* The resulting transformed color will be in format: {red: number, green: number, blue: number}
|
|
329
|
+
*
|
|
330
|
+
* @param from Accessor that will be used on input to access value
|
|
331
|
+
* @param to Accessor that will be used to store the value in the output object
|
|
332
|
+
* @returns Function that extracts a color value and type checks it
|
|
333
|
+
*/
|
|
334
|
+
export const extractColorLegacy = (from, to) => {
|
|
335
|
+
return createExtractionFunc(from, to ?? from, isAnyColorFormat, transformColorLegacy);
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* Creates a extraction function that will extract a color from RBG format
|
|
339
|
+
*
|
|
340
|
+
* @param from Accessor that will be used on input to access value
|
|
341
|
+
* @param to Accessor that will be used to store the value in the output object
|
|
342
|
+
* @returns Function that extracts a color value and type checks it
|
|
343
|
+
*/
|
|
344
|
+
export const extractRGB = (from, to) => {
|
|
345
|
+
return createExtractionFunc(from, to ?? from, isAnyColorFormat, transformRGB);
|
|
346
|
+
};
|
|
347
|
+
/**
|
|
348
|
+
* Creates a extraction function that will extract an array of mappings from an object with the given accessor
|
|
349
|
+
* @param extractionFuncs Array of extraction functions
|
|
350
|
+
* @param from Accessor that will be used on input to access value
|
|
351
|
+
* @param to Accessor that will be used to store the value in the output object
|
|
352
|
+
* @returns Function that extracts an object
|
|
353
|
+
*/
|
|
354
|
+
export const extractObject = (extractionFuncs, from, to) => {
|
|
355
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
356
|
+
return (input, output) => {
|
|
357
|
+
const adjustedTo = to ?? from;
|
|
358
|
+
if (input[from] !== undefined) {
|
|
359
|
+
output[adjustedTo] = {};
|
|
360
|
+
extractionFuncs.forEach((func) => func(input[from], output[adjustedTo]));
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
/**
|
|
365
|
+
* Returns true if the value matches the discriminator
|
|
366
|
+
* @param value Value to check
|
|
367
|
+
* @param discriminator String to check for an accessor or function that determines whether or not a value is proper
|
|
368
|
+
*/
|
|
369
|
+
const objectMatchesDiscriminator = (
|
|
370
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
371
|
+
value, discriminator) => {
|
|
372
|
+
if (typeof discriminator === "string") {
|
|
373
|
+
return value[discriminator] !== undefined;
|
|
374
|
+
}
|
|
375
|
+
return discriminator(value);
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* Creates an extraction function that will extract different values based on a discriminator string
|
|
379
|
+
* This is to allow extracting types like 'ClassA | ClassB'
|
|
380
|
+
* @param params
|
|
381
|
+
* @param from
|
|
382
|
+
* @param to
|
|
383
|
+
* @returns
|
|
384
|
+
*/
|
|
385
|
+
export const extractConditionally = (params, from, to) => {
|
|
386
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
387
|
+
return (input, output) => {
|
|
388
|
+
const adjustedTo = to ?? from;
|
|
389
|
+
if (input[from] !== undefined) {
|
|
390
|
+
for (const param of params) {
|
|
391
|
+
// Check that the discriminator prop exist
|
|
392
|
+
if (objectMatchesDiscriminator(input[from], param.discriminator)) {
|
|
393
|
+
// If so, then apply the necessary extraction functions
|
|
394
|
+
output[adjustedTo] = {};
|
|
395
|
+
if (Array.isArray(param.mappings)) {
|
|
396
|
+
// Apply each extraction func to the inner object
|
|
397
|
+
param.mappings.forEach((func) => func(input[from], output[adjustedTo]));
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
// Apply the extraction func to the object directly
|
|
401
|
+
param.mappings(from, to ?? from)(input, output);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
/**
|
|
409
|
+
* Creates a extraction function that will extract values of an array by using a single extraction function
|
|
410
|
+
* on each of the array values
|
|
411
|
+
* @param extractionFunc
|
|
412
|
+
*/
|
|
413
|
+
export const extractArray = (extractionFunc, from, to) => {
|
|
414
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
415
|
+
return (input, output) => {
|
|
416
|
+
const adjustedTo = to ?? from;
|
|
417
|
+
if (input[from] !== undefined && Array.isArray(input[from])) {
|
|
418
|
+
output[adjustedTo] = [];
|
|
419
|
+
input[from].forEach((_, index) => {
|
|
420
|
+
output[adjustedTo].push({});
|
|
421
|
+
extractionFunc.forEach((func) => func(input[from][index], output[adjustedTo][index]));
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
427
|
+
* Creates an extraction function that will extract the values inside a 2D array from the given accessor
|
|
428
|
+
* @param extractionFunc Extraction functions to apply to each entry in the array
|
|
429
|
+
* @param from Accessor string for the 2D array in the input object
|
|
430
|
+
* @param to Accessor string for the 2D array in the output object
|
|
431
|
+
*/
|
|
432
|
+
export const extractArray2d = (extractionFunc, from, to) => {
|
|
433
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
434
|
+
return (input, output) => {
|
|
435
|
+
if (Array.isArray(input[from]) &&
|
|
436
|
+
input[from].every((inner) => Array.isArray(inner))) {
|
|
437
|
+
const adjustedTo = to ?? from;
|
|
438
|
+
output[adjustedTo] = [];
|
|
439
|
+
for (let i = 0; i < input[from].length; ++i) {
|
|
440
|
+
output[adjustedTo].push([]);
|
|
441
|
+
for (let j = 0; j < input[from][i].length; ++j) {
|
|
442
|
+
output[adjustedTo][i].push({});
|
|
443
|
+
extractionFunc.forEach((func) => func(input[from][i][j], output[adjustedTo][i][j]));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
};
|
|
449
|
+
/**
|
|
450
|
+
* Creates a extraction function that will extract values of an array by using different extraction functions
|
|
451
|
+
* based on a discriminator for each array value. This is to extract arrays of types like (ClassA | ClassB)[]
|
|
452
|
+
* @param extractionFunc
|
|
453
|
+
*/
|
|
454
|
+
export const extractArrayConditionally = (params, from, to) => {
|
|
455
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
456
|
+
return (input, output) => {
|
|
457
|
+
const adjustedTo = to ?? from;
|
|
458
|
+
if (input[from] !== undefined && Array.isArray(input[from])) {
|
|
459
|
+
output[adjustedTo] = [];
|
|
460
|
+
input[from].forEach((_, index) => {
|
|
461
|
+
output[adjustedTo].push({});
|
|
462
|
+
for (const param of params) {
|
|
463
|
+
// Check that the discriminator matches with the object
|
|
464
|
+
if (objectMatchesDiscriminator(input[from][index], param.discriminator)) {
|
|
465
|
+
// If so, then apply the necessary extraction functions
|
|
466
|
+
if (Array.isArray(param.mappings)) {
|
|
467
|
+
param.mappings.forEach((func) => func(input[from][index], output[adjustedTo][index]));
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
471
|
+
param.mappings(index, index)(input[from], output[adjustedTo]);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
};
|
|
479
|
+
/**
|
|
480
|
+
* Creates an extraction function that will extract a plain typed map
|
|
481
|
+
* @param extractionFuncs Extraction functions for the values
|
|
482
|
+
* @param isValidKey Checker for the validity of the key
|
|
483
|
+
* @param from Accessor where the plain typed map exists
|
|
484
|
+
* @param to Accessor to store the plain typed map to
|
|
485
|
+
* @returns
|
|
486
|
+
*/
|
|
487
|
+
export const extractPlainTypedMap = (extractionFuncs, isValidKey, from, to) => {
|
|
488
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
489
|
+
return (input, output) => {
|
|
490
|
+
if (input[from] !== undefined) {
|
|
491
|
+
const adjustedTo = to ?? from;
|
|
492
|
+
output[adjustedTo] = {};
|
|
493
|
+
for (const prop in input[from]) {
|
|
494
|
+
if (isValidKey(prop)) {
|
|
495
|
+
output[adjustedTo][prop] = {};
|
|
496
|
+
extractionFuncs.forEach((func) => func(input[from][prop], output[adjustedTo][prop]));
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
};
|
|
502
|
+
/**
|
|
503
|
+
* Applies an array of extraction functions to extract the data from the input object
|
|
504
|
+
* into the output object
|
|
505
|
+
* @param input Object to extract data from
|
|
506
|
+
* @param output Object to map the data to
|
|
507
|
+
* @param extractionFuncs Array of extraction functions
|
|
508
|
+
*/
|
|
509
|
+
export const applyExtraction = (
|
|
510
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
511
|
+
input,
|
|
512
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
513
|
+
output, extractionFuncs) => {
|
|
514
|
+
extractionFuncs.forEach((func) => func(input, output));
|
|
515
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ViewData } from "@itwin/saved-views-client";
|
|
2
|
+
/**
|
|
3
|
+
* Convert url that potentially contains subtituted characters ('++and++' or '++dot++') to use restricated characters ('&' or '.')
|
|
4
|
+
* @param extensionData
|
|
5
|
+
*/
|
|
6
|
+
export declare const urlToLegacyUrl: (restrictedUrl: string) => string;
|
|
7
|
+
export declare const convertAllLegacyUrlsToUrls: (savedViewData: ViewData, convert: (url: string) => string) => void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert url that potentially contains subtituted characters ('++and++' or '++dot++') to use restricated characters ('&' or '.')
|
|
3
|
+
* @param extensionData
|
|
4
|
+
*/
|
|
5
|
+
export const urlToLegacyUrl = (restrictedUrl) => {
|
|
6
|
+
const unrestrictedUrl = restrictedUrl
|
|
7
|
+
.replaceAll("++and++", "&")
|
|
8
|
+
.replaceAll("++dot++", ".");
|
|
9
|
+
return unrestrictedUrl;
|
|
10
|
+
};
|
|
11
|
+
export const convertAllLegacyUrlsToUrls = (savedViewData, convert) => {
|
|
12
|
+
const displayStyle = savedViewData?.itwin3dView.displayStyle ??
|
|
13
|
+
savedViewData?.itwinDrawingView.displayStyle ??
|
|
14
|
+
savedViewData?.itwinSheetView.displayStyle;
|
|
15
|
+
if (displayStyle === undefined) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
// Convert legacy urls to restricted urls
|
|
19
|
+
const baseUrl = displayStyle.mapImagery?.backgroundBase
|
|
20
|
+
?.url;
|
|
21
|
+
if (displayStyle.mapImagery && baseUrl) {
|
|
22
|
+
displayStyle.mapImagery.backgroundBase.url =
|
|
23
|
+
convert(baseUrl);
|
|
24
|
+
}
|
|
25
|
+
for (const layer of (displayStyle.mapImagery?.overlayLayers ??
|
|
26
|
+
[])) {
|
|
27
|
+
if (layer.url) {
|
|
28
|
+
layer.url = convert(layer.url);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
for (const layer of (displayStyle.mapImagery?.backgroundLayers ??
|
|
32
|
+
[])) {
|
|
33
|
+
if (layer.url) {
|
|
34
|
+
layer.url = convert(layer.url);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
for (const model of displayStyle.contextRealityModels ?? []) {
|
|
38
|
+
if (model.tilesetUrl) {
|
|
39
|
+
model.tilesetUrl = convert(model.tilesetUrl);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SheetViewState, type DrawingViewState, type SpatialViewState } from "@itwin/core-frontend";
|
|
2
|
+
import type { SavedViewWithDataRepresentation } from "@itwin/saved-views-client";
|
|
3
|
+
import type { LegacySavedView, LegacySavedView2d } from "../SavedViewTypes.js";
|
|
4
|
+
/**
|
|
5
|
+
* Extracts id from href
|
|
6
|
+
* @param href
|
|
7
|
+
*/
|
|
8
|
+
export declare const extractIdFromHref: (href: string) => string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Transform a ViewDataITwinDrawing into a legacy SavedView if possible
|
|
11
|
+
* @param savedViewRsp
|
|
12
|
+
* @param iModelViewData
|
|
13
|
+
* @returns SavedView2d
|
|
14
|
+
*/
|
|
15
|
+
export declare function savedViewItwinDrawingToLegacyDrawingView(savedViewRsp: SavedViewWithDataRepresentation, seedDrawingViewState: DrawingViewState): LegacySavedView2d;
|
|
16
|
+
/**
|
|
17
|
+
* Transform a ViewDataITwinSheet into a legacy SavedView if possible
|
|
18
|
+
* @param savedViewRsp
|
|
19
|
+
* @param seedSheetViewState
|
|
20
|
+
* @returns SavedView2d
|
|
21
|
+
*/
|
|
22
|
+
export declare function savedViewItwinSheetToLegacySheetSavedView(savedViewRsp: SavedViewWithDataRepresentation, seedSheetViewState: SheetViewState): LegacySavedView2d;
|
|
23
|
+
/**
|
|
24
|
+
* Transform a ViewDataItwin3d into a legacy SavedView if possible
|
|
25
|
+
* @param savedViewRsp
|
|
26
|
+
* @param seedSpatialViewState
|
|
27
|
+
* @returns SavedView
|
|
28
|
+
*/
|
|
29
|
+
export declare function savedViewITwin3dToLegacy3dSavedView(savedViewRsp: SavedViewWithDataRepresentation, seedSpatialViewState: SpatialViewState): LegacySavedView;
|
|
30
|
+
/**
|
|
31
|
+
* removes null and undefined from legacy view model selectors props models
|
|
32
|
+
* @param savedView
|
|
33
|
+
* @returns SavedViewWithData
|
|
34
|
+
*/
|
|
35
|
+
export declare const cleanLegacyViewModelSelectorPropsModels: (savedView: SavedViewWithDataRepresentation) => SavedViewWithDataRepresentation;
|