@itwin/presentation-shared
Advanced tools
Comparing version 0.2.0 to 0.3.0
# @itwin/presentation-shared | ||
## 0.3.0 | ||
### Minor Changes | ||
- [#628](https://github.com/iTwin/presentation/pull/628): Added support for nested concatenated values by adding `ConcatenatedValue` to the `ConcatenatedValuePart` union. In addition: | ||
- A type guard `ConcatenatedValuePart.isConcatenatedValue` has been added to distinguish it from other types of `ConcatenatedValuePart`. | ||
- `ConcatenatedValue.serialize` has been modified to handle the new type of part seamlessly, so the `partFormatter` prop function receives the same 3 types of `ConcatenatedValuePart`, expanded from nested `ConcatenatedValue` if necessary. | ||
The change makes combining multiple concatenated values easier, e.g. now you can do this: | ||
```ts | ||
const value: ConcatenatedValue = [createConcatenatedValueX(), { type: "String", value: " - " }, createConcatenatedValueY()]; | ||
``` | ||
## 0.2.0 | ||
@@ -4,0 +19,0 @@ |
import { PrimitivePropertyValue, TypedPrimitiveValue } from "./Values"; | ||
/** | ||
* A part of a `ConcatenatedValue`, describing one piece of the value. Possible types: | ||
* - `ConcatenatedValue` describes a nested concatenated value. | ||
* - `PrimitivePropertyValue` describes an ECProperty value. Generally the value is formatted according to | ||
@@ -13,3 +14,3 @@ * property metadata before concatenating with other parts. | ||
*/ | ||
export type ConcatenatedValuePart = PrimitivePropertyValue | TypedPrimitiveValue | string; | ||
export type ConcatenatedValuePart = ConcatenatedValue | PrimitivePropertyValue | TypedPrimitiveValue | string; | ||
/** @beta */ | ||
@@ -23,2 +24,4 @@ export declare namespace ConcatenatedValuePart { | ||
function isProperty(part: ConcatenatedValuePart): part is PrimitivePropertyValue; | ||
/** @beta */ | ||
function isConcatenatedValue(part: ConcatenatedValuePart): part is ConcatenatedValue; | ||
} | ||
@@ -44,3 +47,3 @@ /** | ||
/** Parts formatter to convert each part to string */ | ||
partFormatter: (part: ConcatenatedValuePart) => Promise<string>; | ||
partFormatter: (part: Exclude<ConcatenatedValuePart, ConcatenatedValue>) => Promise<string>; | ||
/** Optional separator for joining the parts. Defaults to an empty string. */ | ||
@@ -47,0 +50,0 @@ separator?: string; |
@@ -28,2 +28,7 @@ "use strict"; | ||
ConcatenatedValuePart.isProperty = isProperty; | ||
/** @beta */ | ||
function isConcatenatedValue(part) { | ||
return Array.isArray(part); | ||
} | ||
ConcatenatedValuePart.isConcatenatedValue = isConcatenatedValue; | ||
})(ConcatenatedValuePart || (exports.ConcatenatedValuePart = ConcatenatedValuePart = {})); | ||
@@ -41,4 +46,9 @@ /** @beta */ | ||
async function serialize(props) { | ||
const { parts, partFormatter } = props; | ||
return (await Promise.all(parts.map(partFormatter))).join(props.separator ?? ""); | ||
const { parts, partFormatter, separator } = props; | ||
return (await Promise.all(parts.map(async (part) => { | ||
if (ConcatenatedValuePart.isConcatenatedValue(part)) { | ||
return serialize({ parts: part, partFormatter, separator }); | ||
} | ||
return partFormatter(part); | ||
}))).join(separator ?? ""); | ||
} | ||
@@ -45,0 +55,0 @@ ConcatenatedValue.serialize = serialize; |
import { PrimitivePropertyValue, TypedPrimitiveValue } from "./Values"; | ||
/** | ||
* A part of a `ConcatenatedValue`, describing one piece of the value. Possible types: | ||
* - `ConcatenatedValue` describes a nested concatenated value. | ||
* - `PrimitivePropertyValue` describes an ECProperty value. Generally the value is formatted according to | ||
@@ -13,3 +14,3 @@ * property metadata before concatenating with other parts. | ||
*/ | ||
export type ConcatenatedValuePart = PrimitivePropertyValue | TypedPrimitiveValue | string; | ||
export type ConcatenatedValuePart = ConcatenatedValue | PrimitivePropertyValue | TypedPrimitiveValue | string; | ||
/** @beta */ | ||
@@ -23,2 +24,4 @@ export declare namespace ConcatenatedValuePart { | ||
function isProperty(part: ConcatenatedValuePart): part is PrimitivePropertyValue; | ||
/** @beta */ | ||
function isConcatenatedValue(part: ConcatenatedValuePart): part is ConcatenatedValue; | ||
} | ||
@@ -44,3 +47,3 @@ /** | ||
/** Parts formatter to convert each part to string */ | ||
partFormatter: (part: ConcatenatedValuePart) => Promise<string>; | ||
partFormatter: (part: Exclude<ConcatenatedValuePart, ConcatenatedValue>) => Promise<string>; | ||
/** Optional separator for joining the parts. Defaults to an empty string. */ | ||
@@ -47,0 +50,0 @@ separator?: string; |
@@ -25,2 +25,7 @@ /*--------------------------------------------------------------------------------------------- | ||
ConcatenatedValuePart.isProperty = isProperty; | ||
/** @beta */ | ||
function isConcatenatedValue(part) { | ||
return Array.isArray(part); | ||
} | ||
ConcatenatedValuePart.isConcatenatedValue = isConcatenatedValue; | ||
})(ConcatenatedValuePart || (ConcatenatedValuePart = {})); | ||
@@ -38,4 +43,9 @@ /** @beta */ | ||
async function serialize(props) { | ||
const { parts, partFormatter } = props; | ||
return (await Promise.all(parts.map(partFormatter))).join(props.separator ?? ""); | ||
const { parts, partFormatter, separator } = props; | ||
return (await Promise.all(parts.map(async (part) => { | ||
if (ConcatenatedValuePart.isConcatenatedValue(part)) { | ||
return serialize({ parts: part, partFormatter, separator }); | ||
} | ||
return partFormatter(part); | ||
}))).join(separator ?? ""); | ||
} | ||
@@ -42,0 +52,0 @@ ConcatenatedValue.serialize = serialize; |
{ | ||
"name": "@itwin/presentation-shared", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "The package contains types and utilities used across different iTwin.js Presentation packages.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
290851
4124