-
Notifications
You must be signed in to change notification settings - Fork 2
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
Proposal for new editors system #1166
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good for the most part, however I'd really like to reduce the API surface to a minimum before merging this in (instead of thinking about all the what-if use-cases).
One more major thing to address is the addition of core-quantity
peer dep.
I like the iconName
-> React.ReactNode
mapping for abstract iconSpec
types. However, let's do this in a separate PR.
@@ -53,24 +49,6 @@ export function createEditorFrontstageProvider(): UiItemsProvider { | |||
icon: <SvgEdit />, | |||
}), | |||
], | |||
getToolbarItems: () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CreateArcTool
, CreateLineStringTool
are not exported from "@itwin/editor-frontend" after version bump
apps/test-app/package.json
Outdated
@@ -102,7 +102,10 @@ | |||
"@itwin/itwinui-icons-react": "^2.8.0", | |||
"@itwin/itwinui-layouts-react": "~0.4.1", | |||
"@itwin/itwinui-layouts-css": "~0.4.0", | |||
"@itwin/presentation-backend": "4.4.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these presentation
dependencies necessary to showcase the new editors? Should we simply create a new frontstage for editors and use tool settings/dummy data in one of widgets?
Need to think about names, current EditorFrontstage
is really for opening iModels in read-write.
(I see the comment now, that this is actually planned to be removed)
export const editorsRegistryContext = React.createContext<EditorsRegistry>({ | ||
editors: [], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const editorsRegistryContext = React.createContext<EditorsRegistry>({ | |
editors: [], | |
}); | |
export const EditorsRegistryContext = React.createContext<EditorsRegistry>({ | |
editors: [], | |
}); | |
EditorsRegistryContext.displayName = "uifw:EditorsRegistryContext"; |
ui/components-react/src/components-react/newEditors/CommittingEditor.tsx
Outdated
Show resolved
Hide resolved
/** | ||
* A type that makes a specific properties required in a type. | ||
* @beta | ||
*/ | ||
export type RequiredProps<TProps, TKey extends keyof TProps> = Omit< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* A type that makes a specific properties required in a type. | |
* @beta | |
*/ | |
export type RequiredProps<TProps, TKey extends keyof TProps> = Omit< | |
/** | |
* A type that makes a specific properties required in a type. | |
* @internal | |
*/ | |
export type RequiredProps<TProps, TKey extends keyof TProps> = Omit< |
onChange: (value: TValue) => void; | ||
onFinish: () => void; | ||
disabled?: boolean; | ||
size?: "small" | "large"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size
should probably not be controlled per editor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those props are pass to each editor implementation by Editor
(EditorContainer
would be more suitable name I guess).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed most of the stuff in components-react
and imodel-components-react
.
ui/components-react/src/components-react/newEditors/values/Values.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/values/Values.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/values/Metadata.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/values/Values.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/values/Metadata.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/editors/enum/UseEnumEditorProps.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/editors/text/UseTextEditorProps.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/editors/numeric/FormattedNumericInput.tsx
Outdated
Show resolved
Hide resolved
ui/imodel-components-react/src/imodel-components-react/editors/NewColorEditor.tsx
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/new-editors/interop/IconsRegistry.tsx
Show resolved
Hide resolved
ui/components-react/src/components-react/new-editors/EditorRenderer.tsx
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/new-editors/editors-registry/DefaultEditors.tsx
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/new-editors/editors/FormattedNumericInput.tsx
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/new-editors/editors/FormattedNumericInput.tsx
Show resolved
Hide resolved
ui/components-react/src/components-react/new-editors/editors/NumericEditor.tsx
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/new-editors/interop/EditorInterop.ts
Outdated
Show resolved
Hide resolved
ui/imodel-components-react/src/imodel-components-react/editors/NewWeightEditor.tsx
Outdated
Show resolved
Hide resolved
ui/imodel-components-react/src/imodel-components-react/inputs/newEditors/QuantityEditor.tsx
Outdated
Show resolved
Hide resolved
ui/imodel-components-react/src/imodel-components-react/inputs/newEditors/QuantityInput.tsx
Outdated
Show resolved
Hide resolved
ui/imodel-components-react/src/imodel-components-react/inputs/newEditors/UseQuantityInfo.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the legacy APIs be deprecated in this PR? Or are you planning to do that separately?
I want to do that in separate PR. Have an issue for that #1224. |
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.EditorRenderer
- wrapper around EditorRegistry that provides a convenient way to render editors for specific value.useCommittableValue
- custom React hooks that provides a convenient way to addcancel/commit
actions onEsc
/Enter
key click to the editor.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)createEditorSpec
- an utility function to that provides a convenient way to defined editor spec for typed editors.PropertyRecordEditor
- React component that allows to use existingPropertyRecord
type with the new editors system.Usage
Some examples of the new editors system usage.
Rendering editor and registering custom editors
Defining component that renders value editor:
Defining component that renders value editor with
Commit
/Cancel
actions:Registering custom editors to be available through out all application:
Registering custom editors that should be available only for specific component:
Defining custom 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):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 replaced byuseCommittableValue
hook in the new system.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.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 maintain 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?