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.
Proposal for new editor system
Proposal for the new editors system. This would replace existing editors system in order to simplify requirements for custom editors. Also it removes static EditorManager in favor of editors registry controlled through React context.
API overview:
EditorsRegistry - Application should use it to register their on custom editors or custom editors provided by some dependencies so that they would be accessible to all components in the application that uses editors system:
EditorsRegistryProvider
- adds supplied editors to the registry hold inReact
context. It supports nesting multipleEditorsRegistryProvider
to allow registering custom editors specific for some component that have higher priority than the ones registered near the root of the application.useEditor
- hook to get the editor that should be used to edit the supplied value. First it looks for applicable editor in EditorsRegistry and if none was found it fallbacks to the default editors.Editor
(name subject to change) - wrapper around EditorRegistry that provides a convenient way to render editors for specific value.CommitingEditor
(name subject to change) - wrapper aroundEditor
that works as uncontrolled component that commits value onEnter
or when editor completes value change (e.g. Toggle click). Also allows to cancel editing onEsc
.Value
- type for all values that are supported by editors.ValueMetadata
- type for additional metadata that can be supplied to editors alongside value itself. It can be extended when implementing custom editors. (E.g. passing available choices and icons to the enum editor that is rendered as button group)Default editors and accompanying
use<EditorName>Props
hooks that acts as a type guard to conveniently convert from generalEditorProps
to the specific editor props.EditorInterop
- internal implementation that mapsPropertyRecord
to the newValue
andValueMetadata
types. It is needed to support existing usage on the editors.Units supports
New editors system was aimed to provide better support for units. There is base component that should help with that
FormattedNumericInput
. It should be easy to write an editor on top of it that would know how to findParser
/Formatter
for specific unit. E.g: https://github.com/iTwin/appui/tree/editors/new-system/ui/imodel-components-react/src/imodel-components-react/inputs/newEditorsCustom editors
The goal of the new editors system is to remove the need for static editor registration and provide more convenient API for implementing custom editors. Current API has quite a lot optional properties that do not make sense (
propertyRecord
is optional but if it isundefined
there is no way to figure out what to render):Example of custom editor using old editor system and react class components:
Custom editor using old system and react functional components:
Custom boolean editor using new system:
The new system removes all the code that was associated with class components and accessing values through editor
ref
. It is not clear if that was used/useful so the chosen approach is to add something similar later if that is still needed. Majority of that was used byEditorContainer
that is represented byCommitingEditor
in the new system.TODO
PropertyEditorParams
fromPropertyRecord
. Need to find a way how to sunset thosePropertyEditorParams
in the future but in mean time if should be possible to maintain what is already there in the old system.PropertyEditorParams
. The initial approach is to maintains internal registry (iconName: string) => ReactNode that would hold currently used icons. Open for suggestions on this one.CommitingEditor
as general solutions for committing entered values only on Enter/Blur or each components should have it's own logic to handle such workflows?