-
Notifications
You must be signed in to change notification settings - Fork 225
Add FormatSetFormatsProvider to ecschema-metadata #8438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b6457ac
Add FormatSetFormatsProvider to ecschema-metadata
hl662 6308071
add next version doc
hl662 ac0a5d3
add resolver for native schema item names
hl662 a48e489
update doccomments
hl662 c5b19fc
clarify documentation
hl662 2417349
Merge branch 'master' into nam/format-set-provider
hl662 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
common/changes/@itwin/core-quantity/nam-format-set-provider_2025-08-19-16-29.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@itwin/core-quantity", | ||
"comment": "Add documentation to public methods", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@itwin/core-quantity" | ||
} |
10 changes: 10 additions & 0 deletions
10
common/changes/@itwin/ecschema-metadata/nam-format-set-provider_2025-08-18-20-19.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@itwin/ecschema-metadata", | ||
"comment": "Add FormatSetFormatsProvider", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@itwin/ecschema-metadata" | ||
} |
61 changes: 61 additions & 0 deletions
61
core/ecschema-metadata/src/Formatting/FormatSetFormatsProvider.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { BeEvent } from "@itwin/core-bentley"; | ||
import { FormatDefinition, FormatsChangedArgs, FormatsProvider, MutableFormatsProvider } from "@itwin/core-quantity"; | ||
import { FormatSet } from "../Deserialization/JsonProps"; | ||
import { SchemaItem } from "../Metadata/SchemaItem"; | ||
|
||
/** | ||
* A mutable format provider that manages format definitions within a format set. | ||
* When formats are added or removed, the underlying format set is automatically updated. | ||
* @beta | ||
*/ | ||
export class FormatSetFormatsProvider implements MutableFormatsProvider { | ||
public onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void> = new BeEvent<(args: FormatsChangedArgs) => void>(); | ||
|
||
private _formatSet: FormatSet; | ||
private _fallbackProvider?: FormatsProvider; | ||
|
||
public constructor(props: {formatSet: FormatSet, fallbackProvider?: FormatsProvider}) { | ||
this._formatSet = props.formatSet; | ||
this._fallbackProvider = props.fallbackProvider; | ||
} | ||
|
||
/** | ||
* Adds a format definition to the format set or updates an existing one. | ||
* @param name The name of the format to add or update | ||
* @param format The format definition to add or update | ||
*/ | ||
public async addFormat(name: string, format: FormatDefinition): Promise<void> { | ||
this._formatSet.formats[name] = format; | ||
this.onFormatsChanged.raiseEvent({ formatsChanged: [name] }); | ||
} | ||
|
||
/** | ||
* Clears the fallback provider, if one is set. | ||
*/ | ||
public clearFallbackProvider(): void { | ||
this._fallbackProvider = undefined; | ||
} | ||
|
||
/** | ||
* Retrieves a format definition by its name from the format set. If not found, it checks the fallback provider to find the format, else returns undefined. | ||
*/ | ||
public async getFormat(input: string): Promise<FormatDefinition | undefined> { | ||
// Normalizes any schemaItem names coming from node addon 'schemaName:schemaItemName' -> 'schemaName.schemaItemName' | ||
const [schemaName, itemName] = SchemaItem.parseFullName(input); | ||
|
||
const name = (schemaName === "") ? itemName : `${schemaName}.${itemName}`; | ||
const format = this._formatSet.formats[name]; | ||
if (format) return format; | ||
if (this._fallbackProvider) return this._fallbackProvider.getFormat(name); | ||
return undefined; | ||
} | ||
|
||
/** | ||
* Removes a format definition from the format set. | ||
* @param name The name of the format to remove | ||
*/ | ||
public async removeFormat(name: string): Promise<void> { | ||
delete this._formatSet.formats[name]; | ||
this.onFormatsChanged.raiseEvent({ formatsChanged: [name] }); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.