@itwin/components-react 5.6.0 → 5.8.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/CHANGELOG.md +38 -0
- package/lib/components-react/editors/CustomNumberEditor.d.ts +3 -1
- package/lib/components-react/editors/CustomNumberEditor.d.ts.map +1 -1
- package/lib/components-react/editors/CustomNumberEditor.js +133 -69
- package/lib/components-react/editors/CustomNumberEditor.js.map +1 -1
- package/lib/components-react/editors/EditorContainer.d.ts +6 -0
- package/lib/components-react/editors/EditorContainer.d.ts.map +1 -1
- package/lib/components-react/editors/EditorContainer.js.map +1 -1
- package/lib/components-react/editors/NumericInputEditor.d.ts.map +1 -1
- package/lib/components-react/editors/NumericInputEditor.js +22 -3
- package/lib/components-react/editors/NumericInputEditor.js.map +1 -1
- package/lib/components-react/editors/PropertyEditorManager.d.ts +4 -2
- package/lib/components-react/editors/PropertyEditorManager.d.ts.map +1 -1
- package/lib/components-react/editors/PropertyEditorManager.js +28 -18
- package/lib/components-react/editors/PropertyEditorManager.js.map +1 -1
- package/lib/components-react/editors/TextEditor.d.ts.map +1 -1
- package/lib/components-react/editors/TextEditor.js +22 -14
- package/lib/components-react/editors/TextEditor.js.map +1 -1
- package/lib/components-react/editors/registerEditors.d.ts.map +1 -1
- package/lib/components-react/editors/registerEditors.js +26 -26
- package/lib/components-react/editors/registerEditors.js.map +1 -1
- package/lib/components-react/new-editors/editors-registry/EditorsRegistryProvider.d.ts +5 -3
- package/lib/components-react/new-editors/editors-registry/EditorsRegistryProvider.d.ts.map +1 -1
- package/lib/components-react/new-editors/editors-registry/EditorsRegistryProvider.js +7 -2
- package/lib/components-react/new-editors/editors-registry/EditorsRegistryProvider.js.map +1 -1
- package/lib/components-react/new-editors/interop/old-editors/CustomNumber.d.ts +10 -0
- package/lib/components-react/new-editors/interop/old-editors/CustomNumber.d.ts.map +1 -1
- package/lib/components-react/new-editors/interop/old-editors/CustomNumber.js +4 -2
- package/lib/components-react/new-editors/interop/old-editors/CustomNumber.js.map +1 -1
- package/lib/internal.d.ts +5 -1
- package/lib/internal.d.ts.map +1 -1
- package/lib/internal.js +4 -5
- package/lib/internal.js.map +1 -1
- package/package.json +3 -3
|
@@ -11,6 +11,7 @@ import * as React from "react";
|
|
|
11
11
|
import { PropertyEditorParamTypes, PropertyValueFormat, } from "@itwin/appui-abstract";
|
|
12
12
|
import { NumberInput } from "@itwin/core-react";
|
|
13
13
|
import { PropertyEditorBase } from "./PropertyEditorManager.js";
|
|
14
|
+
import { InputWithDecorations } from "@itwin/itwinui-react";
|
|
14
15
|
/** NumericInputEditor React component that is a property editor with numeric input & up/down buttons
|
|
15
16
|
* @public
|
|
16
17
|
*/
|
|
@@ -120,15 +121,14 @@ export class NumericInputEditor extends React.PureComponent {
|
|
|
120
121
|
});
|
|
121
122
|
}
|
|
122
123
|
render() {
|
|
124
|
+
const { decoration } = this.props;
|
|
123
125
|
const className = classnames("components-cell-editor", "components-numeric-input-editor", this.props.className);
|
|
124
126
|
const minSize = this.state.size ? this.state.size : 8;
|
|
125
127
|
const style = {
|
|
126
128
|
...this.props.style,
|
|
127
129
|
minWidth: `${minSize * 0.75}em`,
|
|
128
130
|
};
|
|
129
|
-
return (
|
|
130
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
131
|
-
React.createElement(NumberInput, { ref: this._inputElement, className: className, style: style, value: this.state.value, min: this.state.min, max: this.state.max, step: this.state.step, precision: this.state.precision, readOnly: this.state.readonly, maxLength: this.state.maxLength, onBlur: this.props.onBlur, onChange: this._updateValue, autoFocus: this.props.setFocus && !this.state.isDisabled, isControlled: this.props.shouldCommitOnChange }));
|
|
131
|
+
return (React.createElement(NumericEditor, { ref: this._inputElement, className: className, style: style, value: this.state.value, min: this.state.min, max: this.state.max, step: this.state.step, precision: this.state.precision, readOnly: this.state.readonly, maxLength: this.state.maxLength, onBlur: this.props.onBlur, onChange: this._updateValue, autoFocus: this.props.setFocus && !this.state.isDisabled, isControlled: this.props.shouldCommitOnChange, decoration: decoration }));
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
/** Numeric Input Property Editor registered for the "number" type name and "numeric-input" editor name.
|
|
@@ -144,4 +144,23 @@ export class NumericInputPropertyEditor extends PropertyEditorBase {
|
|
|
144
144
|
return false;
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
+
const NumericEditor = React.forwardRef(function NumericEditor(props, forwardedRef) {
|
|
148
|
+
const { decoration, ...rest } = props;
|
|
149
|
+
if (decoration) {
|
|
150
|
+
return (React.createElement(LockNumericEditor, { ...rest, ref: forwardedRef, decoration: decoration }));
|
|
151
|
+
}
|
|
152
|
+
return (
|
|
153
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
154
|
+
React.createElement(NumberInput, { ref: forwardedRef, ...rest }));
|
|
155
|
+
});
|
|
156
|
+
const LockNumericEditor = React.forwardRef(function LockNumericEditor(props, forwardedRef) {
|
|
157
|
+
const { decoration, precision, onChange, isControlled, ...rest } = props;
|
|
158
|
+
const handleChange = (event) => {
|
|
159
|
+
const value = event.target.value;
|
|
160
|
+
onChange?.(Number(value), value);
|
|
161
|
+
};
|
|
162
|
+
return (React.createElement(InputWithDecorations, { size: "small" },
|
|
163
|
+
React.createElement(InputWithDecorations.Input, { ...rest, ref: forwardedRef, type: "number", onChange: handleChange, size: "small" }),
|
|
164
|
+
decoration));
|
|
165
|
+
});
|
|
147
166
|
//# sourceMappingURL=NumericInputEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumericInputEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/NumericInputEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,2BAA2B,CAAC;AACnC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,C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AC,KAAK,CAAC,oBAAoB,GAC7C,CACH,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,0BAA2B,SAAQ,kBAAkB;IAChE,IAAW,SAAS;QAClB,OAAO,oBAAC,kBAAkB,OAAG,CAAC;IAChC,CAAC;IACD,IAAoB,qBAAqB;QACvC,qCAAqC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./NumericInputEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n InputEditorSizeParams,\n PropertyEditorParams,\n PropertyValue,\n RangeEditorParams,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport { NumberInput } from \"@itwin/core-react\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\n\n/** @internal */\ninterface NumericInputEditorState {\n value: number;\n readonly: boolean;\n isDisabled?: boolean;\n size?: number;\n maxLength?: number;\n\n min?: number;\n max?: number;\n step?: number;\n precision?: number;\n}\n\n/** NumericInputEditor React component that is a property editor with numeric input & up/down buttons\n * @public\n */\nexport class NumericInputEditor\n extends React.PureComponent<PropertyEditorProps, NumericInputEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _inputElement: React.RefObject<HTMLInputElement> = React.createRef();\n public hasFocus = false; // hot used since containerHandlesEnter is false\n\n public override readonly state: Readonly<NumericInputEditorState> = {\n value: 0,\n readonly: false,\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.value,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._inputElement.current;\n }\n\n private _handleCommit = async (): Promise<void> => {\n if (this.props.propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (propertyValue !== undefined) {\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue: propertyValue,\n });\n }\n }\n };\n\n private _updateValue = (\n value: number | undefined,\n _stringValue: string\n ): void => {\n const newValue = value !== undefined ? value : 0;\n\n if (this._isMounted)\n this.setState(\n {\n value: newValue,\n },\n async () => {\n await this._handleCommit();\n }\n );\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n let initialValue = 0;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n initialValue = record.value.value as number;\n }\n\n const readonly =\n record && undefined !== record.isReadonly ? record.isReadonly : false;\n let size: number | undefined;\n let maxLength: number | undefined;\n let min: number | undefined;\n let max: number | undefined;\n let step: number | undefined;\n let precision: number | undefined;\n\n const isDisabled = record ? record.isDisabled : undefined;\n\n if (\n record &&\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n const editorSizeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.InputEditorSize.valueOf()\n ) as InputEditorSizeParams;\n if (editorSizeParams) {\n if (editorSizeParams.size) size = editorSizeParams.size;\n if (editorSizeParams.maxLength) maxLength = editorSizeParams.maxLength;\n }\n\n const rangeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Range.valueOf()\n ) as RangeEditorParams;\n if (rangeParams) {\n min = rangeParams.minimum;\n max = rangeParams.maximum;\n step = rangeParams.step;\n precision = rangeParams.precision;\n }\n }\n\n if (this._isMounted)\n this.setState({\n value: initialValue,\n readonly,\n size,\n maxLength,\n isDisabled,\n min,\n max,\n step,\n precision,\n });\n }\n\n public override render(): React.ReactNode {\n const className = classnames(\n \"components-cell-editor\",\n \"components-numeric-input-editor\",\n this.props.className\n );\n const minSize = this.state.size ? this.state.size : 8;\n const style: React.CSSProperties = {\n ...this.props.style,\n minWidth: `${minSize * 0.75}em`,\n };\n\n return (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <NumberInput\n ref={this._inputElement}\n className={className}\n style={style}\n value={this.state.value}\n min={this.state.min}\n max={this.state.max}\n step={this.state.step}\n precision={this.state.precision}\n readOnly={this.state.readonly}\n maxLength={this.state.maxLength}\n onBlur={this.props.onBlur}\n onChange={this._updateValue}\n autoFocus={this.props.setFocus && !this.state.isDisabled} // eslint-disable-line jsx-a11y/no-autofocus\n isControlled={this.props.shouldCommitOnChange}\n />\n );\n }\n}\n\n/** Numeric Input Property Editor registered for the \"number\" type name and \"numeric-input\" editor name.\n * It uses the [[NumericInputEditor]] React component.\n * @public\n */\nexport class NumericInputPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <NumericInputEditor />;\n }\n public override get containerHandlesEnter(): boolean {\n // let input editor process enter key\n return false;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NumericInputEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/NumericInputEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,2BAA2B,CAAC;AACnC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW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C,oBAAC,oBAAoB,CAAC,KAAK,OACrB,IAAI,EACR,GAAG,EAAE,YAAY,EACjB,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAC,OAAO,GACZ;QACD,UAAU,CACU,CACxB,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./NumericInputEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n InputEditorSizeParams,\n PropertyEditorParams,\n PropertyValue,\n RangeEditorParams,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport { NumberInput } from \"@itwin/core-react\";\nimport type {\n InternalInputEditorProps,\n PropertyEditorProps,\n TypeEditor,\n} from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\nimport { InputWithDecorations } from \"@itwin/itwinui-react\";\n\n/** @internal */\ninterface NumericInputEditorState {\n value: number;\n readonly: boolean;\n isDisabled?: boolean;\n size?: number;\n maxLength?: number;\n\n min?: number;\n max?: number;\n step?: number;\n precision?: number;\n}\n\n/** NumericInputEditor React component that is a property editor with numeric input & up/down buttons\n * @public\n */\nexport class NumericInputEditor\n extends React.PureComponent<PropertyEditorProps, NumericInputEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _inputElement: React.RefObject<HTMLInputElement> = React.createRef();\n public hasFocus = false; // hot used since containerHandlesEnter is false\n\n public override readonly state: Readonly<NumericInputEditorState> = {\n value: 0,\n readonly: false,\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.value,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._inputElement.current;\n }\n\n private _handleCommit = async (): Promise<void> => {\n if (this.props.propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (propertyValue !== undefined) {\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue: propertyValue,\n });\n }\n }\n };\n\n private _updateValue = (\n value: number | undefined,\n _stringValue: string\n ): void => {\n const newValue = value !== undefined ? value : 0;\n\n if (this._isMounted)\n this.setState(\n {\n value: newValue,\n },\n async () => {\n await this._handleCommit();\n }\n );\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n let initialValue = 0;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n initialValue = record.value.value as number;\n }\n\n const readonly =\n record && undefined !== record.isReadonly ? record.isReadonly : false;\n let size: number | undefined;\n let maxLength: number | undefined;\n let min: number | undefined;\n let max: number | undefined;\n let step: number | undefined;\n let precision: number | undefined;\n\n const isDisabled = record ? record.isDisabled : undefined;\n\n if (\n record &&\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n const editorSizeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.InputEditorSize.valueOf()\n ) as InputEditorSizeParams;\n if (editorSizeParams) {\n if (editorSizeParams.size) size = editorSizeParams.size;\n if (editorSizeParams.maxLength) maxLength = editorSizeParams.maxLength;\n }\n\n const rangeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Range.valueOf()\n ) as RangeEditorParams;\n if (rangeParams) {\n min = rangeParams.minimum;\n max = rangeParams.maximum;\n step = rangeParams.step;\n precision = rangeParams.precision;\n }\n }\n\n if (this._isMounted)\n this.setState({\n value: initialValue,\n readonly,\n size,\n maxLength,\n isDisabled,\n min,\n max,\n step,\n precision,\n });\n }\n\n public override render(): React.ReactNode {\n const { decoration } = this.props as InternalInputEditorProps;\n const className = classnames(\n \"components-cell-editor\",\n \"components-numeric-input-editor\",\n this.props.className\n );\n const minSize = this.state.size ? this.state.size : 8;\n const style: React.CSSProperties = {\n ...this.props.style,\n minWidth: `${minSize * 0.75}em`,\n };\n\n return (\n <NumericEditor\n ref={this._inputElement}\n className={className}\n style={style}\n value={this.state.value}\n min={this.state.min}\n max={this.state.max}\n step={this.state.step}\n precision={this.state.precision}\n readOnly={this.state.readonly}\n maxLength={this.state.maxLength}\n onBlur={this.props.onBlur}\n onChange={this._updateValue}\n autoFocus={this.props.setFocus && !this.state.isDisabled} // eslint-disable-line jsx-a11y/no-autofocus\n isControlled={this.props.shouldCommitOnChange}\n decoration={decoration}\n />\n );\n }\n}\n\n/** Numeric Input Property Editor registered for the \"number\" type name and \"numeric-input\" editor name.\n * It uses the [[NumericInputEditor]] React component.\n * @public\n */\nexport class NumericInputPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <NumericInputEditor />;\n }\n public override get containerHandlesEnter(): boolean {\n // let input editor process enter key\n return false;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-deprecated\ntype NumberInputProps = React.ComponentProps<typeof NumberInput>;\n\ninterface NumericEditorProps extends Omit<NumberInputProps, \"step\"> {\n decoration?: React.ReactNode;\n step?: number;\n}\n\nconst NumericEditor = React.forwardRef<HTMLInputElement, NumericEditorProps>(\n function NumericEditor(props, forwardedRef) {\n const { decoration, ...rest } = props;\n if (decoration) {\n return (\n <LockNumericEditor\n {...rest}\n ref={forwardedRef}\n decoration={decoration}\n />\n );\n }\n\n return (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <NumberInput ref={forwardedRef} {...rest} />\n );\n }\n);\n\ninterface LockNumericEditorProps extends NumericEditorProps {\n decoration: React.ReactNode;\n}\n\nconst LockNumericEditor = React.forwardRef<\n HTMLInputElement,\n LockNumericEditorProps\n>(function LockNumericEditor(props, forwardedRef) {\n const { decoration, precision, onChange, isControlled, ...rest } = props;\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const value = event.target.value;\n onChange?.(Number(value), value);\n };\n return (\n <InputWithDecorations size=\"small\">\n <InputWithDecorations.Input\n {...rest}\n ref={forwardedRef}\n type=\"number\"\n onChange={handleChange}\n size=\"small\"\n />\n {decoration}\n </InputWithDecorations>\n );\n});\n"]}
|
|
@@ -53,10 +53,8 @@ export declare abstract class DataControllerBase implements DataController {
|
|
|
53
53
|
* @public
|
|
54
54
|
*/
|
|
55
55
|
export declare class PropertyEditorManager {
|
|
56
|
-
private static _editors;
|
|
57
56
|
private static _dataControllers;
|
|
58
57
|
static registerEditor(editType: string, editor: new () => PropertyEditorBase, editorName?: string): void;
|
|
59
|
-
private static getFullEditorName;
|
|
60
58
|
static registerDataController(controllerName: string, controller: new () => DataControllerBase): void;
|
|
61
59
|
/** @internal */
|
|
62
60
|
static deregisterDataController(controllerName: string): void;
|
|
@@ -70,4 +68,8 @@ export declare class PropertyEditorManager {
|
|
|
70
68
|
export declare class BasicPropertyEditor extends PropertyEditorBase {
|
|
71
69
|
get reactNode(): React.ReactNode;
|
|
72
70
|
}
|
|
71
|
+
/** Used to override the default property editors from the `appui-react` package.
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
export declare function registerDefaultPropertyEditor(editType: string, editor: new () => PropertyEditorBase, editorName?: string, override?: boolean): void;
|
|
73
75
|
//# sourceMappingURL=PropertyEditorManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyEditorManager.d.ts","sourceRoot":"","sources":["../../../src/components-react/editors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AE,cAAc,GACrB,OAAO,CAAC,0BAA0B,CAAC;IAOzB,aAAa,CACxB,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,0BAA0B,CAAC;CAMvC;AAED;;GAEG;AACH,8BAAsB,kBAAmB,YAAW,cAAc;IACnD,WAAW,CACtB,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,0BAA0B,CAAC;IAIzB,aAAa,CACxB,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,0BAA0B,CAAC;CAGvC;
|
|
1
|
+
{"version":3,"file":"PropertyEditorManager.d.ts","sourceRoot":"","sources":["../../../src/components-react/editors/PropertyEditorManager.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,eAAe,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,WAAW,CAAC,EAAE,aAAa,CAAC;IAC5B,YAAY,CAAC,EAAE,iBAAiB,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,aAAa,CACX,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACvC,WAAW,CACT,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,0BAA0B,CAAC,CAAC;CACxC;AAED;;G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,EAAE,MAAM,EACnB,kBAAkB,CAAC,EAAE,MAAM,GAC1B,kBAAkB;WA0BP,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO;CAI7E;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,kBAAkB;IACzD,IAAW,SAAS,IAAI,KAAK,CAAC,SAAS,CAEtC;CACF;AAQD;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,UAAU,kBAAkB,EACpC,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,UAAQ,QAQjB"}
|
|
@@ -52,23 +52,18 @@ export class DataControllerBase {
|
|
|
52
52
|
return { encounteredError: false };
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
+
const editors = {};
|
|
55
56
|
/** Manages Property Editors. Property Editors are registered with and created by the manager.
|
|
56
57
|
* @public
|
|
57
58
|
*/
|
|
58
59
|
export class PropertyEditorManager {
|
|
59
60
|
static registerEditor(editType, editor, editorName) {
|
|
60
|
-
const fullEditorName =
|
|
61
|
-
if (
|
|
62
|
-
const nameOfEditor =
|
|
61
|
+
const fullEditorName = getFullEditorName(editType, editorName);
|
|
62
|
+
if (editors.hasOwnProperty(fullEditorName)) {
|
|
63
|
+
const nameOfEditor = editors[fullEditorName].name;
|
|
63
64
|
throw Error(`PropertyEditorManager.registerEditor error: type '${fullEditorName}' already registered to '${nameOfEditor}'`);
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
static getFullEditorName(editType, editorName) {
|
|
68
|
-
let fullEditorName = editType;
|
|
69
|
-
if (editorName)
|
|
70
|
-
fullEditorName += `:${editorName}`;
|
|
71
|
-
return fullEditorName;
|
|
66
|
+
editors[fullEditorName] = editor;
|
|
72
67
|
}
|
|
73
68
|
static registerDataController(controllerName, controller) {
|
|
74
69
|
if (PropertyEditorManager._dataControllers.hasOwnProperty(controllerName)) {
|
|
@@ -84,12 +79,12 @@ export class PropertyEditorManager {
|
|
|
84
79
|
}
|
|
85
80
|
}
|
|
86
81
|
static createEditor(editType, editorName, dataControllerName) {
|
|
87
|
-
const fullEditorName =
|
|
82
|
+
const fullEditorName = getFullEditorName(editType, editorName);
|
|
88
83
|
let editor;
|
|
89
|
-
if (
|
|
90
|
-
editor = new
|
|
91
|
-
else if (
|
|
92
|
-
editor = new
|
|
84
|
+
if (editors.hasOwnProperty(fullEditorName))
|
|
85
|
+
editor = new editors[fullEditorName]();
|
|
86
|
+
else if (editors.hasOwnProperty(editType))
|
|
87
|
+
editor = new editors[editType]();
|
|
93
88
|
else
|
|
94
89
|
editor = new BasicPropertyEditor();
|
|
95
90
|
if (dataControllerName) {
|
|
@@ -102,11 +97,10 @@ export class PropertyEditorManager {
|
|
|
102
97
|
return editor;
|
|
103
98
|
}
|
|
104
99
|
static hasCustomEditor(editType, editorName) {
|
|
105
|
-
const fullEditorName =
|
|
106
|
-
return
|
|
100
|
+
const fullEditorName = getFullEditorName(editType, editorName);
|
|
101
|
+
return editors.hasOwnProperty(fullEditorName);
|
|
107
102
|
}
|
|
108
103
|
}
|
|
109
|
-
PropertyEditorManager._editors = {};
|
|
110
104
|
PropertyEditorManager._dataControllers = {};
|
|
111
105
|
/** Basic Property Editor registered for the "text" and "string" type names.
|
|
112
106
|
* It uses the [[TextEditor]] React component.
|
|
@@ -117,4 +111,20 @@ export class BasicPropertyEditor extends PropertyEditorBase {
|
|
|
117
111
|
return React.createElement(TextEditor, null);
|
|
118
112
|
}
|
|
119
113
|
}
|
|
114
|
+
function getFullEditorName(editType, editorName) {
|
|
115
|
+
let fullEditorName = editType;
|
|
116
|
+
if (editorName)
|
|
117
|
+
fullEditorName += `:${editorName}`;
|
|
118
|
+
return fullEditorName;
|
|
119
|
+
}
|
|
120
|
+
/** Used to override the default property editors from the `appui-react` package.
|
|
121
|
+
* @internal
|
|
122
|
+
*/
|
|
123
|
+
export function registerDefaultPropertyEditor(editType, editor, editorName, override = false) {
|
|
124
|
+
const fullEditorName = getFullEditorName(editType, editorName);
|
|
125
|
+
// Ignore if already registered and override is disabled.
|
|
126
|
+
if (editors.hasOwnProperty(fullEditorName) && !override)
|
|
127
|
+
return;
|
|
128
|
+
editors[fullEditorName] = editor;
|
|
129
|
+
}
|
|
120
130
|
//# sourceMappingURL=PropertyEditorManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyEditorManager.js","sourceRoot":"","sources":["../../../src/components-react/editors/PropertyEditorManager.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AA0C7C;;GAEG;AACH,MAAM,OAAgB,kBAAkB;IAAxC;QAiBS,yBAAoB,GAA+B,SAAS,CAAC;IA4BtE,CAAC;IA5CC,IAAW,oBAAoB;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,sBAAsB;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,qBAAqB;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,mBAAmB;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,gCAAgC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAMM,iBAAiB,CACtB,SAA8B,EAC9B,OAAuB,IAChB,CAAC;IAEH,KAAK,CAAC,WAAW,CACtB,QAAuB,EACvB,MAAsB;QAEtB,IAAI,IAAI,CAAC,oBAAoB;YAC3B,OAAO,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAEjE,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;IACrC,CAAC;IAEM,KAAK,CAAC,aAAa,CACxB,QAAuB,EACvB,MAAsB;QAEtB,IAAI,IAAI,CAAC,oBAAoB;YAC3B,OAAO,IAA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AAM,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,eAAe,CAAC,QAAgB,EAAE,UAAkB;QAChE,MAAM,cAAc,GAAG,qBAAqB,CAAC,iBAAiB,CAC5D,QAAQ,EACR,UAAU,CACX,CAAC;QACF,OAAO,qBAAqB,CAAC,QAAQ,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IACvE,CAAC;;AA9Fc,8BAAQ,GACrB,EAAE,CAAC;AACU,sCAAgB,GAE3B,EAAE,CAAC;AA6FT;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,kBAAkB;IACzD,IAAW,SAAS;QAClB,OAAO,oBAAC,UAAU,OAAG,CAAC;IACxB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport * as React from \"react\";\nimport { TextEditor } from \"./TextEditor.js\";\nimport type {\n DisplayMessageType,\n MessageSeverity,\n PropertyDescription,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\n\n/** Asynchronous Error Message returned as part of [[AsyncValueProcessingResult]]\n * @public\n */\nexport interface AsyncErrorMessage {\n severity: MessageSeverity;\n briefMessage: string;\n detailedMessage?: string;\n messageType?: DisplayMessageType;\n}\n\n/** Asynchronous Value Process Result\n * @public\n */\nexport interface AsyncValueProcessingResult {\n encounteredError: boolean;\n returnValue?: PropertyValue;\n errorMessage?: AsyncErrorMessage;\n}\n\n/** DataControllers can be implemented per typename to validate and commit values.\n * @public\n */\nexport interface DataController {\n validateValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult>;\n commitValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult>;\n}\n\n/** PropertyEditor is the base class for all property editors.\n * @public\n */\nexport abstract class PropertyEditorBase implements DataController {\n public get containerHandlesBlur(): boolean {\n return true;\n }\n public get containerHandlesEscape(): boolean {\n return true;\n }\n public get containerHandlesEnter(): boolean {\n return true;\n }\n public get containerHandlesTab(): boolean {\n return true;\n }\n public get containerStopsKeydownPropagation(): boolean {\n return true;\n }\n\n public customDataController: DataController | undefined = undefined;\n\n public abstract get reactNode(): React.ReactNode;\n\n public applyEditorParams(\n _property: PropertyDescription,\n _record: PropertyRecord\n ): void {}\n\n public async commitValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n if (this.customDataController)\n return this.customDataController.commitValue(newValue, record);\n\n return { encounteredError: false };\n }\n\n public async validateValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n if (this.customDataController)\n return this.customDataController.validateValue(newValue, record);\n\n return { encounteredError: false };\n }\n}\n\n/** DataControllerBase is the base class for all Data Controllers.\n * @public\n */\nexport abstract class DataControllerBase implements DataController {\n public async commitValue(\n _newValue: PropertyValue,\n _record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n return { encounteredError: false };\n }\n\n public async validateValue(\n _newValue: PropertyValue,\n _record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n return { encounteredError: false };\n }\n}\n\n/** Manages Property Editors. Property Editors are registered with and created by the manager.\n * @public\n */\nexport class PropertyEditorManager {\n private static _editors: { [index: string]: new () => PropertyEditorBase } =\n {};\n private static _dataControllers: {\n [index: string]: new () => DataControllerBase;\n } = {};\n\n public static registerEditor(\n editType: string,\n editor: new () => PropertyEditorBase,\n editorName?: string\n ): void {\n const fullEditorName = PropertyEditorManager.getFullEditorName(\n editType,\n editorName\n );\n\n if (PropertyEditorManager._editors.hasOwnProperty(fullEditorName)) {\n const nameOfEditor = PropertyEditorManager._editors[fullEditorName].name;\n throw Error(\n `PropertyEditorManager.registerEditor error: type '${fullEditorName}' already registered to '${nameOfEditor}'`\n );\n }\n PropertyEditorManager._editors[fullEditorName] = editor;\n }\n\n private static getFullEditorName(\n editType: string,\n editorName?: string\n ): string {\n let fullEditorName = editType;\n if (editorName) fullEditorName += `:${editorName}`;\n return fullEditorName;\n }\n\n public static registerDataController(\n controllerName: string,\n controller: new () => DataControllerBase\n ): void {\n if (PropertyEditorManager._dataControllers.hasOwnProperty(controllerName)) {\n throw Error(\n `PropertyEditorManager.registerDataController error: type '${controllerName}' already registered to '${(typeof PropertyEditorManager\n ._dataControllers[controllerName]).toString()}'`\n );\n }\n PropertyEditorManager._dataControllers[controllerName] = controller;\n }\n\n /** @internal */\n public static deregisterDataController(controllerName: string): void {\n if (PropertyEditorManager._dataControllers.hasOwnProperty(controllerName)) {\n delete PropertyEditorManager._dataControllers[controllerName];\n }\n }\n\n public static createEditor(\n editType: string,\n editorName?: string,\n dataControllerName?: string\n ): PropertyEditorBase {\n const fullEditorName = PropertyEditorManager.getFullEditorName(\n editType,\n editorName\n );\n\n let editor: PropertyEditorBase;\n if (PropertyEditorManager._editors.hasOwnProperty(fullEditorName))\n editor = new PropertyEditorManager._editors[fullEditorName]();\n else if (PropertyEditorManager._editors.hasOwnProperty(editType))\n editor = new PropertyEditorManager._editors[editType]();\n else editor = new BasicPropertyEditor();\n\n if (dataControllerName) {\n if (\n PropertyEditorManager._dataControllers.hasOwnProperty(\n dataControllerName\n )\n )\n editor.customDataController =\n new PropertyEditorManager._dataControllers[dataControllerName]();\n else\n throw Error(\n `PropertyEditorManager.createEditor error: data controller '${dataControllerName}' is not registered`\n );\n }\n\n return editor;\n }\n\n public static hasCustomEditor(editType: string, editorName: string): boolean {\n const fullEditorName = PropertyEditorManager.getFullEditorName(\n editType,\n editorName\n );\n return PropertyEditorManager._editors.hasOwnProperty(fullEditorName);\n }\n}\n\n/** Basic Property Editor registered for the \"text\" and \"string\" type names.\n * It uses the [[TextEditor]] React component.\n * @public\n */\nexport class BasicPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <TextEditor />;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PropertyEditorManager.js","sourceRoot":"","sources":["../../../src/components-react/editors/PropertyEditorManager.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AA0C7C;;GAEG;AACH,MAAM,OAAgB,kBAAkB;IAAxC;QAiBS,yBAAoB,GAA+B,SAAS,CAAC;IA4BtE,CAAC;IA5CC,IAAW,oBAAoB;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,sBAAsB;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,qBAAqB;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,mBAAmB;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,gCAAgC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAMM,iBAAiB,CACtB,SAA8B,EAC9B,OAAuB,IAChB,CAAC;IAEH,KAAK,CAAC,WAAW,CACtB,QAAuB,EACvB,MAAsB;QAEtB,IAAI,IAAI,CAAC,oBAAoB;YAC3B,OAAO,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAEjE,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;IACrC,CAAC;IAEM,KAAK,CAAC,aAAa,CACxB,QAAuB,EACvB,MAAsB;QAEtB,IAAI,IAAI,CAAC,oBAAoB;YAC3B,OAAO,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAEnE,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;IACrC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAgB,kBAAkB;IAC/B,KAAK,CAAC,WAAW,CACtB,SAAwB,EACxB,OAAuB;QAEvB,OAAO,EAAE,gBAAgB,EAAE,K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B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAC3C,QAAgB,EAChB,MAAoC,EACpC,UAAmB,EACnB,QAAQ,GAAG,KAAK;IAEhB,MAAM,cAAc,GAAG,iBAAiB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAE/D,yDAAyD;IACzD,IAAI,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ;QAAE,OAAO;IAEhE,OAAO,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC;AACnC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport * as React from \"react\";\nimport { TextEditor } from \"./TextEditor.js\";\nimport type {\n DisplayMessageType,\n MessageSeverity,\n PropertyDescription,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\n\n/** Asynchronous Error Message returned as part of [[AsyncValueProcessingResult]]\n * @public\n */\nexport interface AsyncErrorMessage {\n severity: MessageSeverity;\n briefMessage: string;\n detailedMessage?: string;\n messageType?: DisplayMessageType;\n}\n\n/** Asynchronous Value Process Result\n * @public\n */\nexport interface AsyncValueProcessingResult {\n encounteredError: boolean;\n returnValue?: PropertyValue;\n errorMessage?: AsyncErrorMessage;\n}\n\n/** DataControllers can be implemented per typename to validate and commit values.\n * @public\n */\nexport interface DataController {\n validateValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult>;\n commitValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult>;\n}\n\n/** PropertyEditor is the base class for all property editors.\n * @public\n */\nexport abstract class PropertyEditorBase implements DataController {\n public get containerHandlesBlur(): boolean {\n return true;\n }\n public get containerHandlesEscape(): boolean {\n return true;\n }\n public get containerHandlesEnter(): boolean {\n return true;\n }\n public get containerHandlesTab(): boolean {\n return true;\n }\n public get containerStopsKeydownPropagation(): boolean {\n return true;\n }\n\n public customDataController: DataController | undefined = undefined;\n\n public abstract get reactNode(): React.ReactNode;\n\n public applyEditorParams(\n _property: PropertyDescription,\n _record: PropertyRecord\n ): void {}\n\n public async commitValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n if (this.customDataController)\n return this.customDataController.commitValue(newValue, record);\n\n return { encounteredError: false };\n }\n\n public async validateValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n if (this.customDataController)\n return this.customDataController.validateValue(newValue, record);\n\n return { encounteredError: false };\n }\n}\n\n/** DataControllerBase is the base class for all Data Controllers.\n * @public\n */\nexport abstract class DataControllerBase implements DataController {\n public async commitValue(\n _newValue: PropertyValue,\n _record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n return { encounteredError: false };\n }\n\n public async validateValue(\n _newValue: PropertyValue,\n _record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n return { encounteredError: false };\n }\n}\n\nconst editors: { [index: string]: new () => PropertyEditorBase } = {};\n\n/** Manages Property Editors. Property Editors are registered with and created by the manager.\n * @public\n */\nexport class PropertyEditorManager {\n private static _dataControllers: {\n [index: string]: new () => DataControllerBase;\n } = {};\n\n public static registerEditor(\n editType: string,\n editor: new () => PropertyEditorBase,\n editorName?: string\n ): void {\n const fullEditorName = getFullEditorName(editType, editorName);\n\n if (editors.hasOwnProperty(fullEditorName)) {\n const nameOfEditor = editors[fullEditorName].name;\n throw Error(\n `PropertyEditorManager.registerEditor error: type '${fullEditorName}' already registered to '${nameOfEditor}'`\n );\n }\n editors[fullEditorName] = editor;\n }\n\n public static registerDataController(\n controllerName: string,\n controller: new () => DataControllerBase\n ): void {\n if (PropertyEditorManager._dataControllers.hasOwnProperty(controllerName)) {\n throw Error(\n `PropertyEditorManager.registerDataController error: type '${controllerName}' already registered to '${(typeof PropertyEditorManager\n ._dataControllers[controllerName]).toString()}'`\n );\n }\n PropertyEditorManager._dataControllers[controllerName] = controller;\n }\n\n /** @internal */\n public static deregisterDataController(controllerName: string): void {\n if (PropertyEditorManager._dataControllers.hasOwnProperty(controllerName)) {\n delete PropertyEditorManager._dataControllers[controllerName];\n }\n }\n\n public static createEditor(\n editType: string,\n editorName?: string,\n dataControllerName?: string\n ): PropertyEditorBase {\n const fullEditorName = getFullEditorName(editType, editorName);\n\n let editor: PropertyEditorBase;\n if (editors.hasOwnProperty(fullEditorName))\n editor = new editors[fullEditorName]();\n else if (editors.hasOwnProperty(editType)) editor = new editors[editType]();\n else editor = new BasicPropertyEditor();\n\n if (dataControllerName) {\n if (\n PropertyEditorManager._dataControllers.hasOwnProperty(\n dataControllerName\n )\n )\n editor.customDataController =\n new PropertyEditorManager._dataControllers[dataControllerName]();\n else\n throw Error(\n `PropertyEditorManager.createEditor error: data controller '${dataControllerName}' is not registered`\n );\n }\n\n return editor;\n }\n\n public static hasCustomEditor(editType: string, editorName: string): boolean {\n const fullEditorName = getFullEditorName(editType, editorName);\n return editors.hasOwnProperty(fullEditorName);\n }\n}\n\n/** Basic Property Editor registered for the \"text\" and \"string\" type names.\n * It uses the [[TextEditor]] React component.\n * @public\n */\nexport class BasicPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <TextEditor />;\n }\n}\n\nfunction getFullEditorName(editType: string, editorName?: string) {\n let fullEditorName = editType;\n if (editorName) fullEditorName += `:${editorName}`;\n return fullEditorName;\n}\n\n/** Used to override the default property editors from the `appui-react` package.\n * @internal\n */\nexport function registerDefaultPropertyEditor(\n editType: string,\n editor: new () => PropertyEditorBase,\n editorName?: string,\n override = false\n) {\n const fullEditorName = getFullEditorName(editType, editorName);\n\n // Ignore if already registered and override is disabled.\n if (editors.hasOwnProperty(fullEditorName) && !override) return;\n\n editors[fullEditorName] = editor;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextEditor.d.ts","sourceRoot":"","sources":["../../../src/components-react/editors/TextEditor.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,mBAAmB,CAAC;AAE3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAKV,aAAa,EACd,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"TextEditor.d.ts","sourceRoot":"","sources":["../../../src/components-react/editors/TextEditor.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,mBAAmB,CAAC;AAE3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAKV,aAAa,EACd,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,KAAK,EAEV,mBAAmB,EACnB,UAAU,EACX,MAAM,sBAAsB,CAAC;AAK9B,gBAAgB;AAChB,UAAU,eAAe;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,UACX,SAAQ,KAAK,CAAC,aAAa,CAAC,mBAAmB,EAAE,eAAe,CAChE,YAAW,UAAU;IAErB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,aAAa,CAAuC;IAE5D,SAAyB,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,CAGvD;IAEW,gBAAgB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAenE,IAAW,WAAW,IAAI,WAAW,GAAG,IAAI,CAE3C;IAED,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAED,OAAO,CAAC,iBAAiB,CAqBvB;IAEc,iBAAiB;IAKjB,oBAAoB;IAIpC,gBAAgB;IACA,kBAAkB,CAAC,SAAS,EAAE,mBAAmB;YAMnD,iBAAiB;IAuDf,MAAM,IAAI,KAAK,CAAC,SAAS;CAuC1C"}
|
|
@@ -10,7 +10,7 @@ import classnames from "classnames";
|
|
|
10
10
|
import * as React from "react";
|
|
11
11
|
import { PropertyEditorParamTypes, PropertyValueFormat, } from "@itwin/appui-abstract";
|
|
12
12
|
import { Icon, IconInput } from "@itwin/core-react";
|
|
13
|
-
import { Input } from "@itwin/itwinui-react";
|
|
13
|
+
import { Input, InputWithDecorations } from "@itwin/itwinui-react";
|
|
14
14
|
import { TypeConverterManager } from "../converters/TypeConverterManager.js";
|
|
15
15
|
import { UiComponents } from "../UiComponents.js";
|
|
16
16
|
/** TextEditor React component that is a property editor with text input
|
|
@@ -110,6 +110,7 @@ export class TextEditor extends React.PureComponent {
|
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
render() {
|
|
113
|
+
const { decoration } = this.props;
|
|
113
114
|
const className = classnames("components-cell-editor", "components-text-editor", this.props.className);
|
|
114
115
|
const minSize = this.state.size ? this.state.size : 8;
|
|
115
116
|
const minWidthStyle = {
|
|
@@ -126,20 +127,27 @@ export class TextEditor extends React.PureComponent {
|
|
|
126
127
|
onBlur: this.props.onBlur,
|
|
127
128
|
onChange: this._updateInputValue,
|
|
128
129
|
autoFocus: this.props.setFocus && !this.state.isDisabled,
|
|
130
|
+
"aria-label": UiComponents.translate("editor.text"),
|
|
129
131
|
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const icon = React.createElement(Icon, { iconSpec: this.state.iconSpec });
|
|
135
|
-
reactNode = (
|
|
136
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
137
|
-
React.createElement(IconInput, { ...inputProps, ref: this._inputElement, icon: icon, "data-testid": "components-text-editor" }));
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
reactNode = (React.createElement(Input, { ...inputProps, ref: this._inputElement, "data-testid": "components-text-editor", size: "small", id: this.props.propertyRecord?.property.name }));
|
|
141
|
-
}
|
|
142
|
-
return reactNode;
|
|
132
|
+
const icon = this.state.iconSpec ? (
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
134
|
+
React.createElement(Icon, { iconSpec: this.state.iconSpec })) : undefined;
|
|
135
|
+
return (React.createElement(LockTextEditor, { ...inputProps, ref: this._inputElement, id: this.props.propertyRecord?.property.name, icon: icon, decoration: decoration }));
|
|
143
136
|
}
|
|
144
137
|
}
|
|
138
|
+
const LockTextEditor = React.forwardRef(function LockTextEditor(props, forwardedRef) {
|
|
139
|
+
const { icon, decoration, ...rest } = props;
|
|
140
|
+
if (decoration) {
|
|
141
|
+
return (React.createElement(InputWithDecorations, { size: "small" },
|
|
142
|
+
icon && (React.createElement(InputWithDecorations.Icon, { size: "small" }, icon)),
|
|
143
|
+
React.createElement(InputWithDecorations.Input, { ...rest, ref: forwardedRef, "data-testid": "components-text-editor", size: "small" }),
|
|
144
|
+
decoration));
|
|
145
|
+
}
|
|
146
|
+
if (icon) {
|
|
147
|
+
return (
|
|
148
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
149
|
+
React.createElement(IconInput, { ...rest, ref: forwardedRef, icon: icon, "data-testid": "components-text-editor" }));
|
|
150
|
+
}
|
|
151
|
+
return (React.createElement(Input, { ...rest, ref: forwardedRef, "data-testid": "components-text-editor", size: "small" }));
|
|
152
|
+
});
|
|
145
153
|
//# sourceMappingURL=TextEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/TextEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,mBAAmB,CAAC;AAC3B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAA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CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;QAEjE,IAAI,SAA0B,CAAC;QAC/B,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACxB,4DAA4D;YAC5D,MAAM,IAAI,GAAG,oBAAC,IAAI,IAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAI,CAAC;YACrD,SAAS,GAAG;YACV,4DAA4D;YAC5D,oBAAC,SAAS,OACJ,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,EACvB,IAAI,EAAE,IAAI,iBACE,wBAAwB,GACpC,CACH,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,SAAS,GAAG,CACV,oBAAC,KAAK,OACA,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,iBACX,wBAAwB,EACpC,IAAI,EAAC,OAAO,EACZ,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,QAAQ,CAAC,IAAI,GAC5C,CACH,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./TextEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n IconEditorParams,\n InputEditorSizeParams,\n PrimitiveValue,\n PropertyEditorParams,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport { Icon, IconInput } from \"@itwin/core-react\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport { TypeConverterManager } from \"../converters/TypeConverterManager.js\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer.js\";\nimport { UiComponents } from \"../UiComponents.js\";\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Input>;\n\n/** @internal */\ninterface TextEditorState {\n inputValue: string;\n readonly: boolean;\n isDisabled?: boolean;\n size?: number;\n maxLength?: number;\n iconSpec?: string;\n}\n\n/** TextEditor React component that is a property editor with text input\n * @public\n */\nexport class TextEditor\n extends React.PureComponent<PropertyEditorProps, TextEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _inputElement = React.createRef<HTMLInputElement>();\n\n public override readonly state: Readonly<TextEditorState> = {\n inputValue: \"\",\n readonly: false,\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = await TypeConverterManager.getConverter(\n record.property.typename,\n record.property.converter?.name\n ).convertFromStringToPropertyValue(this.state.inputValue, record);\n (propertyValue as PrimitiveValue).displayValue = this.state.inputValue;\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._inputElement.current;\n }\n\n public get hasFocus(): boolean {\n return document.activeElement === this._inputElement.current;\n }\n\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (this._isMounted)\n this.setState(\n {\n inputValue: e.target.value,\n },\n async () => {\n if (\n this.props.shouldCommitOnChange &&\n this.props.onCommit &&\n this.props.propertyRecord\n ) {\n const newValue = await this.getPropertyValue();\n if (newValue)\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue,\n });\n }\n }\n );\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n let initialValue = \"\";\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n const value = record.value.value;\n initialValue = await TypeConverterManager.getConverter(\n record.property.typename,\n record.property.converter?.name\n ).convertPropertyToString(record.property, value);\n }\n\n const readonly =\n record && undefined !== record.isReadonly ? record.isReadonly : false;\n let size: number | undefined;\n let maxLength: number | undefined;\n let iconSpec: string | undefined;\n\n const isDisabled = record ? record.isDisabled : undefined;\n\n if (\n record &&\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n const editorSizeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.InputEditorSize.valueOf()\n ) as InputEditorSizeParams;\n if (editorSizeParams) {\n if (editorSizeParams.size) size = editorSizeParams.size;\n if (editorSizeParams.maxLength) maxLength = editorSizeParams.maxLength;\n }\n\n const iconParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Icon.valueOf()\n ) as IconEditorParams;\n if (iconParams) {\n iconSpec = iconParams.definition.iconSpec;\n }\n }\n\n if (this._isMounted)\n this.setState({\n inputValue: initialValue,\n readonly,\n size,\n maxLength,\n isDisabled,\n iconSpec,\n });\n }\n\n public override render(): React.ReactNode {\n const className = classnames(\n \"components-cell-editor\",\n \"components-text-editor\",\n this.props.className\n );\n const minSize = this.state.size ? this.state.size : 8;\n const minWidthStyle: React.CSSProperties = {\n minWidth: `${minSize * 0.75}em`,\n };\n const inputProps: InputProps = {\n type: \"text\",\n className,\n style: this.props.style ? this.props.style : minWidthStyle,\n readOnly: this.state.readonly,\n disabled: this.state.isDisabled,\n maxLength: this.state.maxLength,\n value: this.state.inputValue,\n onBlur: this.props.onBlur,\n onChange: this._updateInputValue,\n autoFocus: this.props.setFocus && !this.state.isDisabled,\n };\n\n inputProps[\"aria-label\"] = UiComponents.translate(\"editor.text\");\n\n let reactNode: React.ReactNode;\n if (this.state.iconSpec) {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const icon = <Icon iconSpec={this.state.iconSpec} />;\n reactNode = (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <IconInput\n {...inputProps}\n ref={this._inputElement}\n icon={icon}\n data-testid=\"components-text-editor\"\n />\n );\n } else {\n reactNode = (\n <Input\n {...inputProps}\n ref={this._inputElement}\n data-testid=\"components-text-editor\"\n size=\"small\"\n id={this.props.propertyRecord?.property.name}\n />\n );\n }\n\n return reactNode;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TextEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/TextEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,mBAAmB,CAAC;AAC3B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAM7E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAclD;;GAEG;AACH,MAAM,OAAO,UACX,SAAQ,KAAK,CAAC,aAAmD;IADnE;;QAIU,eAAU,GAAG,KAAK,CAAC;QACnB,kBAAa,GAAG,KAAK,CAAC,SAAS,EAAoB,CAAC;QAEnC,UAAK,GAA8B;YAC1D,UAAU,EAAE,EAAE;YACd,QAAQ,EAAE,KAAK;SAChB,CAAC;QAyBM,sBAAiB,GAAG,CAAC,CAAsC,EAAE,EAAE;YACrE,IAAI,IAAI,CAAC,UAAU;gBACjB,IAAI,CAAC,QAAQ,CACX;oBACE,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK;iBAC3B,EACD,KAAK,IAAI,EAAE;oBACT,IACE,IAAI,CAAC,KAAK,CAAC,oBAAoB;wBAC/B,IAAI,CAAC,K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,oBAAoB,IAAC,IAAI,EAAC,OAAO;YAC/B,IAAI,IAAI,CACP,oBAAC,oBAAoB,CAAC,IAAI,IAAC,IAAI,EAAC,OAAO,IACpC,IAAI,CACqB,CAC7B;YACD,oBAAC,oBAAoB,CAAC,KAAK,OACrB,IAAI,EACR,GAAG,EAAE,YAAY,iBACL,wBAAwB,EACpC,IAAI,EAAC,OAAO,GACZ;YACD,UAAU,CACU,CACxB,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,EAAE,CAAC;QACT,OAAO;QACL,4DAA4D;QAC5D,oBAAC,SAAS,OACJ,IAAI,EACR,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,IAAI,iBACE,wBAAwB,GACpC,CACH,CAAC;IACJ,CAAC;IACD,OAAO,CACL,oBAAC,KAAK,OACA,IAAI,EACR,GAAG,EAAE,YAAY,iBACL,wBAAwB,EACpC,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./TextEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n IconEditorParams,\n InputEditorSizeParams,\n PrimitiveValue,\n PropertyEditorParams,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport { Icon, IconInput } from \"@itwin/core-react\";\nimport { Input, InputWithDecorations } from \"@itwin/itwinui-react\";\nimport { TypeConverterManager } from \"../converters/TypeConverterManager.js\";\nimport type {\n InternalInputEditorProps,\n PropertyEditorProps,\n TypeEditor,\n} from \"./EditorContainer.js\";\nimport { UiComponents } from \"../UiComponents.js\";\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Input>;\n\n/** @internal */\ninterface TextEditorState {\n inputValue: string;\n readonly: boolean;\n isDisabled?: boolean;\n size?: number;\n maxLength?: number;\n iconSpec?: string;\n}\n\n/** TextEditor React component that is a property editor with text input\n * @public\n */\nexport class TextEditor\n extends React.PureComponent<PropertyEditorProps, TextEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _inputElement = React.createRef<HTMLInputElement>();\n\n public override readonly state: Readonly<TextEditorState> = {\n inputValue: \"\",\n readonly: false,\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = await TypeConverterManager.getConverter(\n record.property.typename,\n record.property.converter?.name\n ).convertFromStringToPropertyValue(this.state.inputValue, record);\n (propertyValue as PrimitiveValue).displayValue = this.state.inputValue;\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._inputElement.current;\n }\n\n public get hasFocus(): boolean {\n return document.activeElement === this._inputElement.current;\n }\n\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (this._isMounted)\n this.setState(\n {\n inputValue: e.target.value,\n },\n async () => {\n if (\n this.props.shouldCommitOnChange &&\n this.props.onCommit &&\n this.props.propertyRecord\n ) {\n const newValue = await this.getPropertyValue();\n if (newValue)\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue,\n });\n }\n }\n );\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n let initialValue = \"\";\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n const value = record.value.value;\n initialValue = await TypeConverterManager.getConverter(\n record.property.typename,\n record.property.converter?.name\n ).convertPropertyToString(record.property, value);\n }\n\n const readonly =\n record && undefined !== record.isReadonly ? record.isReadonly : false;\n let size: number | undefined;\n let maxLength: number | undefined;\n let iconSpec: string | undefined;\n\n const isDisabled = record ? record.isDisabled : undefined;\n\n if (\n record &&\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n const editorSizeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.InputEditorSize.valueOf()\n ) as InputEditorSizeParams;\n if (editorSizeParams) {\n if (editorSizeParams.size) size = editorSizeParams.size;\n if (editorSizeParams.maxLength) maxLength = editorSizeParams.maxLength;\n }\n\n const iconParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Icon.valueOf()\n ) as IconEditorParams;\n if (iconParams) {\n iconSpec = iconParams.definition.iconSpec;\n }\n }\n\n if (this._isMounted)\n this.setState({\n inputValue: initialValue,\n readonly,\n size,\n maxLength,\n isDisabled,\n iconSpec,\n });\n }\n\n public override render(): React.ReactNode {\n const { decoration } = this.props as InternalInputEditorProps;\n const className = classnames(\n \"components-cell-editor\",\n \"components-text-editor\",\n this.props.className\n );\n const minSize = this.state.size ? this.state.size : 8;\n const minWidthStyle: React.CSSProperties = {\n minWidth: `${minSize * 0.75}em`,\n };\n const inputProps: InputProps = {\n type: \"text\",\n className,\n style: this.props.style ? this.props.style : minWidthStyle,\n readOnly: this.state.readonly,\n disabled: this.state.isDisabled,\n maxLength: this.state.maxLength,\n value: this.state.inputValue,\n onBlur: this.props.onBlur,\n onChange: this._updateInputValue,\n autoFocus: this.props.setFocus && !this.state.isDisabled,\n \"aria-label\": UiComponents.translate(\"editor.text\"),\n };\n\n const icon = this.state.iconSpec ? (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <Icon iconSpec={this.state.iconSpec} />\n ) : undefined;\n return (\n <LockTextEditor\n {...inputProps}\n ref={this._inputElement}\n id={this.props.propertyRecord?.property.name}\n icon={icon}\n decoration={decoration}\n />\n );\n }\n}\n\ninterface LockTextEditorProps extends InputProps {\n icon?: React.ReactNode;\n decoration?: React.ReactNode;\n}\n\nconst LockTextEditor = React.forwardRef<HTMLInputElement, LockTextEditorProps>(\n function LockTextEditor(props, forwardedRef) {\n const { icon, decoration, ...rest } = props;\n if (decoration) {\n return (\n <InputWithDecorations size=\"small\">\n {icon && (\n <InputWithDecorations.Icon size=\"small\">\n {icon}\n </InputWithDecorations.Icon>\n )}\n <InputWithDecorations.Input\n {...rest}\n ref={forwardedRef}\n data-testid=\"components-text-editor\"\n size=\"small\"\n />\n {decoration}\n </InputWithDecorations>\n );\n }\n\n if (icon) {\n return (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <IconInput\n {...rest}\n ref={forwardedRef}\n icon={icon}\n data-testid=\"components-text-editor\"\n />\n );\n }\n return (\n <Input\n {...rest}\n ref={forwardedRef}\n data-testid=\"components-text-editor\"\n size=\"small\"\n />\n );\n }\n);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerEditors.d.ts","sourceRoot":"","sources":["../../../src/components-react/editors/registerEditors.ts"],"names":[],"mappings":"AAIA;;GAEG;AAsBH,gBAAgB;AAChB,wBAAgB,eAAe,
|
|
1
|
+
{"version":3,"file":"registerEditors.d.ts","sourceRoot":"","sources":["../../../src/components-react/editors/registerEditors.ts"],"names":[],"mappings":"AAIA;;GAEG;AAsBH,gBAAgB;AAChB,wBAAgB,eAAe,SA+G9B"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @module PropertyEditors
|
|
7
7
|
*/
|
|
8
8
|
import { StandardEditorNames, StandardTypeNames } from "@itwin/appui-abstract";
|
|
9
|
-
import { BasicPropertyEditor,
|
|
9
|
+
import { BasicPropertyEditor, registerDefaultPropertyEditor, } from "./PropertyEditorManager.js";
|
|
10
10
|
import { DateTimePropertyEditor, ShortDateTimePropertyEditor, } from "./DateTimeEditor.js";
|
|
11
11
|
import { BooleanPropertyEditor } from "./BooleanEditor.js";
|
|
12
12
|
import { CustomNumberPropertyEditor } from "./CustomNumberEditor.js";
|
|
@@ -20,30 +20,30 @@ import { TextareaPropertyEditor } from "./TextareaEditor.js";
|
|
|
20
20
|
import { TogglePropertyEditor } from "./ToggleEditor.js";
|
|
21
21
|
/** @internal */
|
|
22
22
|
export function registerEditors() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
23
|
+
registerDefaultPropertyEditor(StandardTypeNames.Bool, BooleanPropertyEditor);
|
|
24
|
+
registerDefaultPropertyEditor(StandardTypeNames.Boolean, BooleanPropertyEditor);
|
|
25
|
+
registerDefaultPropertyEditor(StandardTypeNames.Boolean, ImageCheckBoxPropertyEditor, StandardEditorNames.ImageCheckBox);
|
|
26
|
+
registerDefaultPropertyEditor(StandardTypeNames.Bool, ImageCheckBoxPropertyEditor, StandardEditorNames.ImageCheckBox);
|
|
27
|
+
registerDefaultPropertyEditor(StandardTypeNames.Bool, TogglePropertyEditor, StandardEditorNames.Toggle);
|
|
28
|
+
registerDefaultPropertyEditor(StandardTypeNames.Boolean, TogglePropertyEditor, StandardEditorNames.Toggle);
|
|
29
|
+
registerDefaultPropertyEditor(StandardTypeNames.Number, NumericInputPropertyEditor, StandardEditorNames.NumericInput);
|
|
30
|
+
registerDefaultPropertyEditor(StandardTypeNames.Int, NumericInputPropertyEditor, StandardEditorNames.NumericInput);
|
|
31
|
+
registerDefaultPropertyEditor(StandardTypeNames.Float, NumericInputPropertyEditor, StandardEditorNames.NumericInput);
|
|
32
|
+
registerDefaultPropertyEditor(StandardTypeNames.Double, NumericInputPropertyEditor, StandardEditorNames.NumericInput);
|
|
33
|
+
registerDefaultPropertyEditor(StandardTypeNames.Number, SliderPropertyEditor, StandardEditorNames.Slider);
|
|
34
|
+
registerDefaultPropertyEditor(StandardTypeNames.Int, SliderPropertyEditor, StandardEditorNames.Slider);
|
|
35
|
+
registerDefaultPropertyEditor(StandardTypeNames.Float, SliderPropertyEditor, StandardEditorNames.Slider);
|
|
36
|
+
registerDefaultPropertyEditor(StandardTypeNames.Double, SliderPropertyEditor, StandardEditorNames.Slider);
|
|
37
|
+
registerDefaultPropertyEditor(StandardTypeNames.Number, CustomNumberPropertyEditor, StandardEditorNames.NumberCustom);
|
|
38
|
+
registerDefaultPropertyEditor(StandardTypeNames.Text, BasicPropertyEditor);
|
|
39
|
+
registerDefaultPropertyEditor(StandardTypeNames.String, BasicPropertyEditor);
|
|
40
|
+
registerDefaultPropertyEditor(StandardTypeNames.Text, IconPropertyEditor, StandardEditorNames.IconPicker);
|
|
41
|
+
registerDefaultPropertyEditor(StandardTypeNames.String, IconPropertyEditor, StandardEditorNames.IconPicker);
|
|
42
|
+
registerDefaultPropertyEditor(StandardTypeNames.Text, TextareaPropertyEditor, StandardEditorNames.MultiLine);
|
|
43
|
+
registerDefaultPropertyEditor(StandardTypeNames.String, TextareaPropertyEditor, StandardEditorNames.MultiLine);
|
|
44
|
+
registerDefaultPropertyEditor(StandardTypeNames.Enum, EnumPropertyButtonGroupEditor, StandardEditorNames.EnumButtonGroup);
|
|
45
|
+
registerDefaultPropertyEditor(StandardTypeNames.Enum, EnumPropertyEditor);
|
|
46
|
+
registerDefaultPropertyEditor(StandardTypeNames.ShortDate, ShortDateTimePropertyEditor);
|
|
47
|
+
registerDefaultPropertyEditor(StandardTypeNames.DateTime, DateTimePropertyEditor);
|
|
48
48
|
}
|
|
49
49
|
//# sourceMappingURL=registerEditors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerEditors.js","sourceRoot":"","sources":["../../../src/components-react/editors/registerEditors.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EACL,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"registerEditors.js","sourceRoot":"","sources":["../../../src/components-react/editors/registerEditors.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EACL,mBAAmB,EACnB,6BAA6B,GAC9B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,sBAAsB,EACtB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,gBAAgB;AAChB,MAAM,UAAU,eAAe;IAC7B,6BAA6B,CAAC,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;IAC7E,6BAA6B,CAC3B,iBAAiB,CAAC,OAAO,EACzB,qBAAqB,CACtB,CAAC;IACF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;IAEF,6BAA6B,CAAC,iBAAiB,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IAC3E,6BAA6B,CAAC,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC7E,6BAA6B,CAC3B,iBAAiB,CAAC,IAAI,EACtB,kBAAkB,EAClB,mBAAmB,CAAC,UAAU,CAC/B,CAAC;IACF,6BAA6B,CAC3B,iBAAiB,CAAC,MAAM,EACxB,kBAAkB,EAClB,mBAAmB,CAAC,UAAU,CAC/B,CAAC;IACF,6BAA6B,CAC3B,iBAAiB,CAAC,IAAI,EACtB,sBAAsB,EACtB,mBAAmB,CAAC,SAAS,CAC9B,CAAC;IACF,6BAA6B,CAC3B,iBAAiB,CAAC,MAAM,EACxB,sBAAsB,EACtB,mBAAmB,CAAC,SAAS,CAC9B,CAAC;IAEF,6BAA6B,CAC3B,iBAAiB,CAAC,IAAI,EACtB,6BAA6B,EAC7B,mBAAmB,CAAC,eAAe,CACpC,CAAC;IACF,6BAA6B,CAAC,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;IAE1E,6BAA6B,CAC3B,iBAAiB,CAAC,SAAS,EAC3B,2BAA2B,CAC5B,CAAC;IACF,6BAA6B,CAC3B,iBAAiB,CAAC,QAAQ,EAC1B,sBAAsB,CACvB,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport { StandardEditorNames, StandardTypeNames } from \"@itwin/appui-abstract\";\nimport {\n BasicPropertyEditor,\n registerDefaultPropertyEditor,\n} from \"./PropertyEditorManager.js\";\nimport {\n DateTimePropertyEditor,\n ShortDateTimePropertyEditor,\n} from \"./DateTimeEditor.js\";\nimport { BooleanPropertyEditor } from \"./BooleanEditor.js\";\nimport { CustomNumberPropertyEditor } from \"./CustomNumberEditor.js\";\nimport { EnumPropertyButtonGroupEditor } from \"./EnumButtonGroupEditor.js\";\nimport { EnumPropertyEditor } from \"./EnumEditor.js\";\nimport { IconPropertyEditor } from \"./IconEditor.js\";\nimport { ImageCheckBoxPropertyEditor } from \"./ImageCheckBoxEditor.js\";\nimport { NumericInputPropertyEditor } from \"./NumericInputEditor.js\";\nimport { SliderPropertyEditor } from \"./SliderEditor.js\";\nimport { TextareaPropertyEditor } from \"./TextareaEditor.js\";\nimport { TogglePropertyEditor } from \"./ToggleEditor.js\";\n\n/** @internal */\nexport function registerEditors() {\n registerDefaultPropertyEditor(StandardTypeNames.Bool, BooleanPropertyEditor);\n registerDefaultPropertyEditor(\n StandardTypeNames.Boolean,\n BooleanPropertyEditor\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.Boolean,\n ImageCheckBoxPropertyEditor,\n StandardEditorNames.ImageCheckBox\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.Bool,\n ImageCheckBoxPropertyEditor,\n StandardEditorNames.ImageCheckBox\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.Bool,\n TogglePropertyEditor,\n StandardEditorNames.Toggle\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.Boolean,\n TogglePropertyEditor,\n StandardEditorNames.Toggle\n );\n\n registerDefaultPropertyEditor(\n StandardTypeNames.Number,\n NumericInputPropertyEditor,\n StandardEditorNames.NumericInput\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.Int,\n NumericInputPropertyEditor,\n StandardEditorNames.NumericInput\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.Float,\n NumericInputPropertyEditor,\n StandardEditorNames.NumericInput\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.Double,\n NumericInputPropertyEditor,\n StandardEditorNames.NumericInput\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.Number,\n SliderPropertyEditor,\n StandardEditorNames.Slider\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.Int,\n SliderPropertyEditor,\n StandardEditorNames.Slider\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.Float,\n SliderPropertyEditor,\n StandardEditorNames.Slider\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.Double,\n SliderPropertyEditor,\n StandardEditorNames.Slider\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.Number,\n CustomNumberPropertyEditor,\n StandardEditorNames.NumberCustom\n );\n\n registerDefaultPropertyEditor(StandardTypeNames.Text, BasicPropertyEditor);\n registerDefaultPropertyEditor(StandardTypeNames.String, BasicPropertyEditor);\n registerDefaultPropertyEditor(\n StandardTypeNames.Text,\n IconPropertyEditor,\n StandardEditorNames.IconPicker\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.String,\n IconPropertyEditor,\n StandardEditorNames.IconPicker\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.Text,\n TextareaPropertyEditor,\n StandardEditorNames.MultiLine\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.String,\n TextareaPropertyEditor,\n StandardEditorNames.MultiLine\n );\n\n registerDefaultPropertyEditor(\n StandardTypeNames.Enum,\n EnumPropertyButtonGroupEditor,\n StandardEditorNames.EnumButtonGroup\n );\n registerDefaultPropertyEditor(StandardTypeNames.Enum, EnumPropertyEditor);\n\n registerDefaultPropertyEditor(\n StandardTypeNames.ShortDate,\n ShortDateTimePropertyEditor\n );\n registerDefaultPropertyEditor(\n StandardTypeNames.DateTime,\n DateTimePropertyEditor\n );\n}\n"]}
|
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
import type { EditorSpec } from "../Types.js";
|
|
6
6
|
/**
|
|
7
|
-
* Provider that adds supplied editors into `EditorsRegistry`.
|
|
8
|
-
*
|
|
7
|
+
* Provider that adds supplied editors into `EditorsRegistry`.
|
|
8
|
+
* Multiple providers can be nested, with editors from the innermost provider taking the highest priority.
|
|
9
|
+
* You can either supply a list of editors or provide a function that customizes the current list of editors,
|
|
10
|
+
* allowing full control over the final set of editors.
|
|
9
11
|
* @beta
|
|
10
12
|
*/
|
|
11
13
|
export declare function EditorsRegistryProvider({ children, editors, }: {
|
|
12
14
|
children: React.ReactNode;
|
|
13
|
-
editors: EditorSpec[];
|
|
15
|
+
editors: EditorSpec[] | ((editors: EditorSpec[]) => EditorSpec[]);
|
|
14
16
|
}): React.JSX.Element;
|
|
15
17
|
//# sourceMappingURL=EditorsRegistryProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorsRegistryProvider.d.ts","sourceRoot":"","sources":["../../../../src/components-react/new-editors/editors-registry/EditorsRegistryProvider.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C
|
|
1
|
+
{"version":3,"file":"EditorsRegistryProvider.d.ts","sourceRoot":"","sources":["../../../../src/components-react/new-editors/editors-registry/EditorsRegistryProvider.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,QAAQ,EACR,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,CAAC,CAAC;CACnE,qBAiBA"}
|
|
@@ -9,13 +9,18 @@ import * as React from "react";
|
|
|
9
9
|
import { useContext, useMemo } from "react";
|
|
10
10
|
import { EditorsRegistryContext } from "./EditorsRegistryContext.js";
|
|
11
11
|
/**
|
|
12
|
-
* Provider that adds supplied editors into `EditorsRegistry`.
|
|
13
|
-
*
|
|
12
|
+
* Provider that adds supplied editors into `EditorsRegistry`.
|
|
13
|
+
* Multiple providers can be nested, with editors from the innermost provider taking the highest priority.
|
|
14
|
+
* You can either supply a list of editors or provide a function that customizes the current list of editors,
|
|
15
|
+
* allowing full control over the final set of editors.
|
|
14
16
|
* @beta
|
|
15
17
|
*/
|
|
16
18
|
export function EditorsRegistryProvider({ children, editors, }) {
|
|
17
19
|
const parentContext = useContext(EditorsRegistryContext);
|
|
18
20
|
const value = useMemo(() => {
|
|
21
|
+
if (typeof editors === "function") {
|
|
22
|
+
return { editors: editors(parentContext.editors) };
|
|
23
|
+
}
|
|
19
24
|
return {
|
|
20
25
|
editors: [...editors, ...parentContext.editors],
|
|
21
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorsRegistryProvider.js","sourceRoot":"","sources":["../../../../src/components-react/new-editors/editors-registry/EditorsRegistryProvider.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE
|
|
1
|
+
{"version":3,"file":"EditorsRegistryProvider.js","sourceRoot":"","sources":["../../../../src/components-react/new-editors/editors-registry/EditorsRegistryProvider.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,EACtC,QAAQ,EACR,OAAO,GAIR;IACC,MAAM,aAAa,GAAG,UAAU,CAAC,sBAAsB,CAAC,CAAC;IAEzD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;YAClC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;QACrD,CAAC;QACD,OAAO;YACL,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,aAAa,CAAC,OAAO,CAAC;SAChD,CAAC;IACJ,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC;IAE7B,OAAO,CACL,oBAAC,sBAAsB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC1C,QAAQ,CACuB,CACnC,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport * as React from \"react\";\nimport { useContext, useMemo } from \"react\";\nimport type { EditorSpec } from \"../Types.js\";\nimport { EditorsRegistryContext } from \"./EditorsRegistryContext.js\";\n\n/**\n * Provider that adds supplied editors into `EditorsRegistry`.\n * Multiple providers can be nested, with editors from the innermost provider taking the highest priority.\n * You can either supply a list of editors or provide a function that customizes the current list of editors,\n * allowing full control over the final set of editors.\n * @beta\n */\nexport function EditorsRegistryProvider({\n children,\n editors,\n}: {\n children: React.ReactNode;\n editors: EditorSpec[] | ((editors: EditorSpec[]) => EditorSpec[]);\n}) {\n const parentContext = useContext(EditorsRegistryContext);\n\n const value = useMemo(() => {\n if (typeof editors === \"function\") {\n return { editors: editors(parentContext.editors) };\n }\n return {\n editors: [...editors, ...parentContext.editors],\n };\n }, [parentContext, editors]);\n\n return (\n <EditorsRegistryContext.Provider value={value}>\n {children}\n </EditorsRegistryContext.Provider>\n );\n}\n"]}
|