@itwin/components-react 5.5.0 → 5.7.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 +39 -0
- package/lib/components-react/editors/CustomNumberEditor.d.ts +0 -1
- package/lib/components-react/editors/CustomNumberEditor.d.ts.map +1 -1
- package/lib/components-react/editors/CustomNumberEditor.js +21 -13
- 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/components-react/propertygrid/dataproviders/FilteringDataProvider.d.ts +1 -0
- package/lib/components-react/propertygrid/dataproviders/FilteringDataProvider.d.ts.map +1 -1
- package/lib/components-react/propertygrid/dataproviders/FilteringDataProvider.js +11 -2
- package/lib/components-react/propertygrid/dataproviders/FilteringDataProvider.js.map +1 -1
- package/lib/components-react/tree/controlled/TreeEventHandler.d.ts +1 -0
- package/lib/components-react/tree/controlled/TreeEventHandler.d.ts.map +1 -1
- package/lib/components-react/tree/controlled/TreeEventHandler.js +11 -2
- package/lib/components-react/tree/controlled/TreeEventHandler.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
|
@@ -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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C;QAExC,IAAI,kBAAkB,EAAE,CAAC;YACvB,IACE,qBAAqB,CAAC,gBAAgB,CAAC,cAAc,CACnD,kBAAkB,CACnB;gBAED,MAAM,CAAC,oBAAoB;oBACzB,IAAI,qBAAqB,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,EAAE,CAAC;;gBAEnE,MAAM,KAAK,CACT,8DAA8D,kBAAkB,qBAAqB,CACtG,CAAC;QACN,CAAC;QAED,OAAO,MAAM,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,oB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,MAAM,OAAO,mBAAoB,SAAQ,kBAAkB;IACzD,IAAW,SAAS;QAClB,OAAO,oBAAC,UAAU,OAAG,CAAC;IACxB,CAAC;CACF;AAED,SAAS,iBAAiB,CAAC,QAAgB,EAAE,UAAmB;IAC9D,IAAI,cAAc,GAAG,QAAQ,CAAC;IAC9B,IAAI,UAAU;QAAE,cAAc,IAAI,IAAI,UAAU,EAAE,CAAC;IACnD,OAAO,cAAc,CAAC;AACxB,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 @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AC/B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU;YAC5B,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;YACzB,QAAQ,EAAE,IAAI,CAAC,iBAAiB;YAChC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU;SACzD,CAAC;QAEF,UAAU,CAAC,YAAY,CAAC,GAAG,YAAY,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,Q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AAE,IAAI,EACV,UAAU,EAAE,UAAU,GACtB,CACH,CAAC;IACJ,CAAC;CACF;AAOD,MAAM,cAAc,GAAG,KAAK,CAAC,UAAU,CACrC,SAAS,cAAc,CAAC,KAAK,EAAE,YAAY;IACzC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IAC5C,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,CACL,oBAAC,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,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ACF,6BAA6B,CAC3B,iBAAiB,CAAC,KAAK,EACvB,oBAAoB,EACpB,mBAAmB,CAAC,MAAM,CAC3B,CAAC;IACF,6BAA6B,CAC3B,iBAAiB,CAAC,MAAM,EACxB,oBAAoB,EACpB,mBAAmB,CAAC,MAAM,CAC3B,CAAC;IACF,6BAA6B,CAC3B,iBAAiB,CAAC,MAAM,EACxB,0BAA0B,EAC1B,mBAAmB,CAAC,YAAY,CACjC,CAAC;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"]}
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { EditorProps } from "../../Types.js";
|
|
3
|
+
import type { OldEditorMetadata } from "../Metadata.js";
|
|
4
|
+
import type { NumericValue } from "../../values/Values.js";
|
|
1
5
|
/** @internal */
|
|
2
6
|
export declare const CustomNumberEditorSpec: import("../../Types.js").EditorSpec;
|
|
7
|
+
interface CustomNumberEditorProps extends EditorProps<OldEditorMetadata, NumericValue> {
|
|
8
|
+
decoration?: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
/** @internal */
|
|
11
|
+
export declare function CustomNumberEditor({ metadata, value, onChange, size, disabled, decoration, }: CustomNumberEditorProps): React.JSX.Element | null;
|
|
12
|
+
export {};
|
|
3
13
|
//# sourceMappingURL=CustomNumber.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomNumber.d.ts","sourceRoot":"","sources":["../../../../../src/components-react/new-editors/interop/old-editors/CustomNumber.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CustomNumber.d.ts","sourceRoot":"","sources":["../../../../../src/components-react/new-editors/interop/old-editors/CustomNumber.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAW3D,gBAAgB;AAChB,eAAO,MAAM,sBAAsB,qCAWjC,CAAC;AAEH,UAAU,uBACR,SAAQ,WAAW,CAAC,iBAAiB,EAAE,YAAY,CAAC;IACpD,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC9B;AAED,gBAAgB;AAChB,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,UAAU,GACX,EAAE,uBAAuB,4BAuDzB"}
|
|
@@ -20,7 +20,8 @@ export const CustomNumberEditorSpec = createEditorSpec({
|
|
|
20
20
|
isValueSupported: isNumeric,
|
|
21
21
|
Editor: CustomNumberEditor,
|
|
22
22
|
});
|
|
23
|
-
|
|
23
|
+
/** @internal */
|
|
24
|
+
export function CustomNumberEditor({ metadata, value, onChange, size, disabled, decoration, }) {
|
|
24
25
|
const formatParams = useCustomFormattedNumberParams(metadata);
|
|
25
26
|
const sizeParams = useInputEditorSizeParams(metadata);
|
|
26
27
|
const iconParams = useIconEditorParams(metadata);
|
|
@@ -53,7 +54,8 @@ function CustomNumberEditor({ metadata, value, onChange, size, disabled, }) {
|
|
|
53
54
|
};
|
|
54
55
|
return (React.createElement(InputWithDecorations, { size: size },
|
|
55
56
|
icon !== undefined ? (React.createElement(InputWithDecorations.Icon, null, icon)) : null,
|
|
56
|
-
React.createElement(InputWithDecorations.Input, { ref: inputRef, style: style, disabled: disabled, onChange: handleChange, value: inputValue })
|
|
57
|
+
React.createElement(InputWithDecorations.Input, { ref: inputRef, style: style, disabled: disabled, onChange: handleChange, value: inputValue }),
|
|
58
|
+
decoration));
|
|
57
59
|
}
|
|
58
60
|
/* v8 ignore stop */
|
|
59
61
|
//# sourceMappingURL=CustomNumber.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomNumber.js","sourceRoot":"","sources":["../../../../../src/components-react/new-editors/interop/old-editors/CustomNumber.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EACL,8BAA8B,EAC9B,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAE3D,qBAAqB;AAErB,gBAAgB;AAChB,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;IACrD,mBAAmB,EAAE,CAAC,QAAQ,EAAiC,EAAE,CAC/D,mBAAmB,CAAC,QAAQ,CAAC;QAC7B,QAAQ,CAAC,IAAI,KAAK,QAAQ;QAC1B,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CACrB,CAAC,KAAK,EAAE,EAAE,CACR,KAAK,CAAC,IAAI,KAAK,wBAAwB,CAAC,qBAAqB,CAAC,OAAO,EAAE,CAC1E;QACD,QAAQ,CAAC,eAAe,KAAK,mBAAmB,CAAC,YAAY;IAC/D,gBAAgB,EAAE,SAAS;IAC3B,MAAM,EAAE,kBAAkB;CAC3B,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"CustomNumber.js","sourceRoot":"","sources":["../../../../../src/components-react/new-editors/interop/old-editors/CustomNumber.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,mBAAm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,QAAQ,EAClB,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,UAAU,GACjB;QACD,UAAU,CACU,CACxB,CAAC;AACJ,CAAC;AAED,oBAAoB","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\nimport * as React from \"react\";\nimport {\n PropertyEditorParamTypes,\n StandardEditorNames,\n} from \"@itwin/appui-abstract\";\nimport { InputWithDecorations } from \"@itwin/itwinui-react\";\nimport type { EditorProps } from \"../../Types.js\";\nimport { createEditorSpec } from \"../../Types.js\";\nimport type { OldEditorMetadata } from \"../Metadata.js\";\nimport { isOldEditorMetadata } from \"../Metadata.js\";\nimport type { NumericValue } from \"../../values/Values.js\";\nimport {\n useCustomFormattedNumberParams,\n useIconEditorParams,\n useInputEditorSizeParams,\n} from \"./UseEditorParams.js\";\nimport { findIcon } from \"../IconsRegistry.js\";\nimport { isNumeric } from \"../../values/ValueUtilities.js\";\n\n/* v8 ignore start */\n\n/** @internal */\nexport const CustomNumberEditorSpec = createEditorSpec({\n isMetadataSupported: (metadata): metadata is OldEditorMetadata =>\n isOldEditorMetadata(metadata) &&\n metadata.type === \"number\" &&\n !!metadata.params?.find(\n (param) =>\n param.type === PropertyEditorParamTypes.CustomFormattedNumber.valueOf()\n ) &&\n metadata.preferredEditor === StandardEditorNames.NumberCustom,\n isValueSupported: isNumeric,\n Editor: CustomNumberEditor,\n});\n\ninterface CustomNumberEditorProps\n extends EditorProps<OldEditorMetadata, NumericValue> {\n decoration?: React.ReactNode;\n}\n\n/** @internal */\nexport function CustomNumberEditor({\n metadata,\n value,\n onChange,\n size,\n disabled,\n decoration,\n}: CustomNumberEditorProps) {\n const formatParams = useCustomFormattedNumberParams(metadata);\n const sizeParams = useInputEditorSizeParams(metadata);\n const iconParams = useIconEditorParams(metadata);\n const inputRef = React.useRef<HTMLInputElement>(null);\n const [inputValue, setInputValue] = React.useState(() => {\n return value?.rawValue !== undefined && formatParams\n ? formatParams.formatFunction(value.rawValue)\n : \"\";\n });\n\n if (!formatParams) {\n return null;\n }\n\n const style: React.CSSProperties | undefined =\n sizeParams?.size !== undefined\n ? {\n minWidth: `${sizeParams?.size * 0.75}em`,\n }\n : undefined;\n const icon =\n iconParams?.definition?.iconSpec !== undefined\n ? findIcon(iconParams.definition.iconSpec)\n : undefined;\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const currentValue = e.target.value;\n const result = formatParams.parseFunction(currentValue);\n const parsedValue =\n typeof result.value === \"number\" ? result.value : undefined;\n\n setInputValue(currentValue);\n\n onChange({\n rawValue: parsedValue,\n displayValue: currentValue,\n });\n };\n\n return (\n <InputWithDecorations size={size}>\n {icon !== undefined ? (\n <InputWithDecorations.Icon>{icon}</InputWithDecorations.Icon>\n ) : null}\n <InputWithDecorations.Input\n ref={inputRef}\n style={style}\n disabled={disabled}\n onChange={handleChange}\n value={inputValue}\n />\n {decoration}\n </InputWithDecorations>\n );\n}\n\n/* v8 ignore stop */\n"]}
|
|
@@ -29,6 +29,7 @@ export interface FilteredPropertyData extends PropertyData {
|
|
|
29
29
|
* @public
|
|
30
30
|
*/
|
|
31
31
|
export declare class FilteringPropertyDataProvider implements IPropertyDataProvider, Disposable {
|
|
32
|
+
#private;
|
|
32
33
|
private _dataProvider;
|
|
33
34
|
private _filterer;
|
|
34
35
|
onDataChanged: PropertyDataChangeEvent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilteringDataProvider.d.ts","sourceRoot":"","sources":["../../../../src/components-react/propertygrid/dataproviders/FilteringDataProvider.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,iCAAiC,CAAC;AAIzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAEhF,OAAO,KAAK,EACV,qBAAqB,EAErB,YAAY,EACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EACV,YAAY,EACZ,qBAAqB,EAEtB,MAAM,yCAAyC,CAAC;AAWjD;;;GAGG;AACH,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACxD;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,aAAa,GAAG,SAAS,CAAC;IAE/D,qDAAqD;IACrD,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;CAChC;AAED;;;GAGG;AACH,qBAAa,6BACX,YAAW,qBAAqB,EAAE,UAAU
|
|
1
|
+
{"version":3,"file":"FilteringDataProvider.d.ts","sourceRoot":"","sources":["../../../../src/components-react/propertygrid/dataproviders/FilteringDataProvider.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,iCAAiC,CAAC;AAIzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAEhF,OAAO,KAAK,EACV,qBAAqB,EAErB,YAAY,EACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EACV,YAAY,EACZ,qBAAqB,EAEtB,MAAM,yCAAyC,CAAC;AAWjD;;;GAGG;AACH,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACxD;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,aAAa,GAAG,SAAS,CAAC;IAE/D,qDAAqD;IACrD,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;CAChC;AAED;;;GAGG;AACH,qBAAa,6BACX,YAAW,qBAAqB,EAAE,UAAU;;IAS1C,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,SAAS;IARZ,aAAa,0BAAiC;IACrD,OAAO,CAAC,qBAAqB,CACjB;IACZ,OAAO,CAAC,6BAA6B,CAA0B;IAC/D,OAAO,CAAC,2BAA2B,CAA0B;gBAGnD,aAAa,EAAE,qBAAqB,EACpC,SAAS,EAAE,qBAAqB;IAmB1C,+CAA+C;IACxC,CAAC,MAAM,CAAC,OAAO,CAAC;IAIvB,4DAA4D;IACrD,OAAO,IAAI,IAAI;IAIT,OAAO,IAAI,OAAO,CAAC,oBAAoB,CAAC;YAgBvC,kBAAkB;CA0CjC"}
|
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
/** @packageDocumentation
|
|
6
6
|
* @module PropertyGrid
|
|
7
7
|
*/
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _FilteringPropertyDataProvider_instances, _FilteringPropertyDataProvider_dispose;
|
|
8
14
|
import "../../common/DisposePolyfill.js";
|
|
9
15
|
import { PropertyValueFormat } from "@itwin/appui-abstract";
|
|
10
16
|
import { PropertyDataChangeEvent } from "../PropertyDataProvider.js";
|
|
@@ -14,6 +20,7 @@ import { PropertyDataChangeEvent } from "../PropertyDataProvider.js";
|
|
|
14
20
|
*/
|
|
15
21
|
export class FilteringPropertyDataProvider {
|
|
16
22
|
constructor(_dataProvider, _filterer) {
|
|
23
|
+
_FilteringPropertyDataProvider_instances.add(this);
|
|
17
24
|
this._dataProvider = _dataProvider;
|
|
18
25
|
this._filterer = _filterer;
|
|
19
26
|
this.onDataChanged = new PropertyDataChangeEvent();
|
|
@@ -30,13 +37,15 @@ export class FilteringPropertyDataProvider {
|
|
|
30
37
|
});
|
|
31
38
|
}
|
|
32
39
|
/** Destructor. Must be called to clean up. */
|
|
33
|
-
[
|
|
40
|
+
[(_FilteringPropertyDataProvider_instances = new WeakSet(), _FilteringPropertyDataProvider_dispose = function _FilteringPropertyDataProvider_dispose() {
|
|
34
41
|
this._disposeDataChangedListener();
|
|
35
42
|
this._disposeFilterChangedListener();
|
|
43
|
+
}, Symbol.dispose)]() {
|
|
44
|
+
__classPrivateFieldGet(this, _FilteringPropertyDataProvider_instances, "m", _FilteringPropertyDataProvider_dispose).call(this);
|
|
36
45
|
}
|
|
37
46
|
/** @deprecated in 5.5.0. Use `[Symbol.dispose]` instead. */
|
|
38
47
|
dispose() {
|
|
39
|
-
this
|
|
48
|
+
__classPrivateFieldGet(this, _FilteringPropertyDataProvider_instances, "m", _FilteringPropertyDataProvider_dispose).call(this);
|
|
40
49
|
}
|
|
41
50
|
async getData() {
|
|
42
51
|
if (this._filteredPropertyData) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilteringDataProvider.js","sourceRoot":"","sources":["../../../../src/components-react/propertygrid/dataproviders/FilteringDataProvider.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,iCAAiC,CAAC;AAGzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAQ5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAqCrE;;;GAGG;AACH,MAAM,OAAO,6BAA6B;IASxC,YACU,aAAoC,EACpC,SAAgC;QADhC,kBAAa,GAAb,aAAa,CAAuB;QACpC,cAAS,GAAT,SAAS,CAAuB;QARnC,kBAAa,GAAG,IAAI,uBAAuB,EAAE,CAAC;QAC7C,0BAAqB,GAC3B,SAAS,CAAC;QAQV,IAAI,CAAC,6BAA6B;YAChC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,WAAW,CAAC,GAAG,EAAE;gBAC9C,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;gBACvC,I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,EAAE,GAAG,KAAK,EAAE,CAAC;QACtB,KAAK,mBAAmB,CAAC,KAAK;YAC5B,OAAO;gBACL,WAAW,EAAE,mBAAmB,CAAC,KAAK;gBACtC,aAAa,EAAE,KAAK,CAAC,aAAa;gBAClC,KAAK,EAAE,WAAW;aACnB,CAAC;QACJ,KAAK,mBAAmB,CAAC,MAAM;YAC7B,MAAM,OAAO,GAAuC,EAAE,CAAC;YACvD,WAAW,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;YACvE,OAAO;gBACL,WAAW,EAAE,mBAAmB,CAAC,MAAM;gBACvC,OAAO;aACR,CAAC;IACN,CAAC;AACH,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 PropertyGrid\n */\n\nimport \"../../common/DisposePolyfill.js\";\n\nimport type { PropertyRecord, PropertyValue } from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat } from \"@itwin/appui-abstract\";\nimport type { HighlightInfo } from \"../../common/HighlightingComponentProps.js\";\nimport type { CategoryRecordsDict } from \"../internal/flat-items/MutableGridCategory.js\";\nimport type {\n IPropertyDataProvider,\n PropertyCategory,\n PropertyData,\n} from \"../PropertyDataProvider.js\";\nimport { PropertyDataChangeEvent } from \"../PropertyDataProvider.js\";\nimport type {\n FilteredType,\n IPropertyDataFilterer,\n PropertyDataFilterResult,\n} from \"./filterers/PropertyDataFiltererBase.js\";\n\ninterface FilteredRecords {\n filteredRecords: PropertyRecord[];\n shouldExpandNodeParents: boolean;\n matchesCount: number;\n activeMatch?: HighlightInfo;\n filteredResultMatches: { id: string; matchesCount: number }[];\n filteredTypes: FilteredType[];\n}\n\n/**\n * Data returned by [[FilteringPropertyDataProvider]]\n * @public\n */\nexport interface FilteredPropertyData extends PropertyData {\n /**\n * Shows how many matches were found when filtering data.\n * `undefined` when filterer is not active\n */\n matchesCount?: number;\n\n /**\n * Function used for getting [[HighlightInfo]] by index from all the filtered matches.\n * `undefined` when filterer is not active\n */\n getMatchByIndex?: (index: number) => HighlightInfo | undefined;\n\n /** Types of objects that were used for filtering. */\n filteredTypes?: FilteredType[];\n}\n\n/**\n * [[IPropertyDataProvider]] implementation which filters wrapped provider [[PropertyData]] using passed [[IPropertyDataFilterer]].\n * @public\n */\nexport class FilteringPropertyDataProvider\n implements IPropertyDataProvider, Disposable\n{\n public onDataChanged = new PropertyDataChangeEvent();\n private _filteredPropertyData: Promise<FilteredPropertyData> | undefined =\n undefined;\n private _disposeFilterChangedListener: (...args: any[]) => any;\n private _disposeDataChangedListener: (...args: any[]) => any;\n\n public constructor(\n private _dataProvider: IPropertyDataProvider,\n private _filterer: IPropertyDataFilterer\n ) {\n this._disposeFilterChangedListener =\n this._filterer.onFilterChanged.addListener(() => {\n this._filteredPropertyData = undefined;\n this.onDataChanged.raiseEvent();\n });\n this._disposeDataChangedListener =\n this._dataProvider.onDataChanged.addListener(() => {\n this._filteredPropertyData = undefined;\n this.onDataChanged.raiseEvent();\n });\n }\n\n /** Destructor. Must be called to clean up. */\n public [Symbol.dispose]() {\n this._disposeDataChangedListener();\n this._disposeFilterChangedListener();\n }\n\n /** @deprecated in 5.5.0. Use `[Symbol.dispose]` instead. */\n public dispose(): void {\n this[Symbol.dispose]();\n }\n\n public async getData(): Promise<FilteredPropertyData> {\n if (this._filteredPropertyData) {\n return this._filteredPropertyData;\n }\n\n this._filteredPropertyData = this._dataProvider\n .getData()\n .then(async (propertyData) => {\n return this._filterer.isActive\n ? this.filterPropertyData(propertyData)\n : propertyData;\n });\n\n return this._filteredPropertyData;\n }\n\n private async filterPropertyData(propertyData: PropertyData) {\n const { categories, records, label, description } = { ...propertyData };\n const {\n filteredCategories,\n filteredRecords,\n matchesCount,\n filteredResultMatches,\n filteredTypes,\n } = await matchHierarchy(this._filterer, categories, records, undefined);\n\n const uniqueTypes = [...new Set(filteredTypes)];\n const getMatchByIndex = (index: number) => {\n let activeMatch: HighlightInfo | undefined;\n if (index <= 0) return undefined;\n\n let i = 1;\n for (const record of filteredResultMatches) {\n const fullMatchesCount = record.matchesCount;\n if (index < i + fullMatchesCount) {\n activeMatch = {\n highlightedItemIdentifier: record.id,\n highlightIndex: index - i,\n };\n break;\n }\n\n i += fullMatchesCount;\n }\n return activeMatch;\n };\n\n return {\n label,\n description,\n categories: filteredCategories,\n records: filteredRecords,\n reusePropertyDataState: false,\n matchesCount,\n getMatchByIndex,\n filteredTypes: uniqueTypes,\n };\n }\n}\n\nasync function matchHierarchy(\n filterer: IPropertyDataFilterer,\n categories: PropertyCategory[],\n records: CategoryRecordsDict,\n newRecords?: CategoryRecordsDict,\n parentMatchInfo?: PropertyDataFilterResult\n) {\n const newCategories: PropertyCategory[] = [];\n newRecords = newRecords ?? {};\n let matchesCount = 0;\n let allFilteredResultMatches: { id: string; matchesCount: number }[] = [];\n let allFilteredTypes: FilteredType[] = [];\n\n for (const category of categories) {\n const matchInfo = await filterer.categoryMatchesFilter(category, []);\n\n if (matchInfo.matchesFilter) {\n allFilteredResultMatches.push({\n id: category.name,\n matchesCount: matchInfo.matchesCount ?? 0,\n });\n allFilteredTypes = allFilteredTypes.concat(matchInfo.filteredTypes ?? []);\n matchesCount += matchInfo.matchesCount ?? 0;\n }\n\n const childRecords = records[category.name] ?? [];\n const {\n filteredRecords,\n matchesCount: count,\n filteredResultMatches,\n filteredTypes,\n } = await matchRecordHierarchy(filterer, childRecords, []);\n allFilteredResultMatches = allFilteredResultMatches.concat(\n filteredResultMatches\n );\n allFilteredTypes = allFilteredTypes.concat(filteredTypes);\n matchesCount += count;\n\n const parentInfo = parentMatchInfo?.matchesFilter\n ? parentMatchInfo\n : matchInfo;\n\n const childCategories = category.childCategories ?? [];\n const {\n filteredCategories,\n matchesCount: childCount,\n filteredResultMatches: childFilteredResultMatches,\n filteredTypes: childFilteredTypes,\n } = await matchHierarchy(\n filterer,\n childCategories,\n records,\n newRecords,\n parentInfo\n );\n allFilteredResultMatches = allFilteredResultMatches.concat(\n childFilteredResultMatches\n );\n allFilteredTypes = allFilteredTypes.concat(childFilteredTypes);\n matchesCount += childCount;\n\n let expand = !(count === 0 && childCount === 0);\n if (\n matchInfo.matchesFilter ||\n (parentMatchInfo?.matchesFilter &&\n parentMatchInfo.shouldForceIncludeDescendants)\n ) {\n newRecords[category.name] = records[category.name];\n if (matchInfo.matchesFilter) {\n expand = true;\n }\n const newCategory = copyPropertyCategory(\n category,\n filteredCategories,\n expand\n );\n newCategories.push(newCategory);\n }\n\n if (\n (filteredRecords.length !== 0 || filteredCategories.length !== 0) &&\n !matchInfo.matchesFilter &&\n !(\n parentMatchInfo?.shouldExpandNodeParents &&\n parentMatchInfo.matchesFilter\n )\n ) {\n const newCategory = copyPropertyCategory(\n category,\n filteredCategories,\n expand\n );\n newRecords[newCategory.name] = filteredRecords;\n newCategories.push(newCategory);\n }\n }\n\n return {\n filteredCategories: newCategories,\n filteredRecords: newRecords,\n matchesCount,\n filteredResultMatches: allFilteredResultMatches,\n filteredTypes: allFilteredTypes,\n };\n}\n\nasync function matchRecordHierarchy(\n filterer: IPropertyDataFilterer,\n records: PropertyRecord[],\n parents: PropertyRecord[],\n forceIncludeItem: boolean = false\n): Promise<FilteredRecords> {\n const newMatchedRecords: PropertyRecord[] = [];\n let expandParent = false; // property passed back to parent to indicate whether it should be expanded\n let matchesCount = 0;\n let filteredResultMatches: { id: string; matchesCount: number }[] = [];\n let filteredTypes: FilteredType[] = [];\n\n for (const record of records) {\n const matchInfo = await filterer.recordMatchesFilter(record, parents);\n const shouldForceIncludeDescendants =\n forceIncludeItem || matchInfo.shouldForceIncludeDescendants;\n const {\n filteredRecords: filteredChildren,\n shouldExpandNodeParents,\n matchesCount: childrenMatchesCount,\n filteredResultMatches: childrenResultMatches,\n filteredTypes: childrenFilteredTypes,\n } = await matchRecordHierarchy(\n filterer,\n record.getChildrenRecords(),\n [...parents, record],\n shouldForceIncludeDescendants\n );\n filteredResultMatches = filteredResultMatches.concat(childrenResultMatches);\n filteredTypes = [...filteredTypes, ...childrenFilteredTypes];\n matchesCount += childrenMatchesCount;\n // if child hierarchy indicates parents should be expanded, then it should be passed back up to the top parent\n expandParent = expandParent || shouldExpandNodeParents;\n\n let newRecord: PropertyRecord | undefined;\n if (matchInfo.matchesFilter) {\n filteredTypes = [...filteredTypes, ...(matchInfo.filteredTypes ?? [])];\n const recordMatchesCount = matchInfo.matchesCount ?? 0;\n matchesCount += recordMatchesCount;\n // Item is included if it matches filter\n // If at least one matched record from records list needs its parent expanded,\n // then `expandParent` should be set to true\n expandParent = expandParent || !!matchInfo.shouldExpandNodeParents;\n newRecord = copyPropertyRecord(\n record,\n filteredChildren,\n shouldExpandNodeParents\n );\n filteredResultMatches.push({\n id: newRecord.property.name,\n matchesCount: recordMatchesCount,\n });\n } else if (filteredChildren.length !== 0 || forceIncludeItem) {\n // Item is also included if it has at least one matched child or is forcefully included by its parent\n newRecord = copyPropertyRecord(\n record,\n filteredChildren,\n shouldExpandNodeParents\n );\n }\n\n if (newRecord) newMatchedRecords.push(newRecord);\n }\n\n return {\n filteredRecords: newMatchedRecords,\n shouldExpandNodeParents: expandParent,\n matchesCount,\n filteredResultMatches,\n filteredTypes,\n };\n}\n\nfunction copyPropertyCategory(\n propertyCategory: PropertyCategory,\n newChildren: PropertyCategory[],\n expand: boolean\n): PropertyCategory {\n return {\n ...propertyCategory,\n childCategories: newChildren,\n expand,\n };\n}\n\nfunction copyPropertyRecord(\n record: PropertyRecord,\n newChildren: PropertyRecord[],\n autoExpand: boolean\n) {\n const r = record.copyWithNewValue(\n createNewPropertyValue(record.value, newChildren)\n );\n r.autoExpand = autoExpand;\n return r;\n}\n\nfunction createNewPropertyValue(\n value: PropertyValue,\n newChildren: PropertyRecord[]\n): PropertyValue {\n switch (value.valueFormat) {\n case PropertyValueFormat.Primitive:\n return { ...value };\n case PropertyValueFormat.Array:\n return {\n valueFormat: PropertyValueFormat.Array,\n itemsTypeName: value.itemsTypeName,\n items: newChildren,\n };\n case PropertyValueFormat.Struct:\n const members: { [name: string]: PropertyRecord } = {};\n newChildren.forEach((child) => (members[child.property.name] = child));\n return {\n valueFormat: PropertyValueFormat.Struct,\n members,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"FilteringDataProvider.js","sourceRoot":"","sources":["../../../../src/components-react/propertygrid/dataproviders/FilteringDataProvider.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;AAEH,OAAO,iCAAiC,CAAC;AAGzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAQ5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAqCrE;;;GAGG;AACH,MAAM,OAAO,6BAA6B;IASxC,YACU,aAAoC,EACpC,SAAgC;;QADhC,kBAAa,GAAb,aAAa,CAAuB;QACpC,cAAS,GAAT,SAAS,CAAuB;QARnC,kBAAa,GAAG,IAAI,uBAAuB,EAAE,CAAC;QAC7C,0BAAqB,GAC3B,SAAS,CAAC;QAQV,IAAI,CAAC,6BAA6B;YAChC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,WAAW,CAAC,GAAG,EAAE;gBAC9C,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;gBACvC,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC;YAClC,CAAC,CAAC,CAAC;QACL,IAAI,CAAC,2BAA2B;YAC9B,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,WAAW,CAAC,GAAG,EAAE;gBAChD,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;gBACvC,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC;YAClC,CAAC,CAAC,CAAC;IACP,CAAC;IAOD,+CAA+C;IACxC;QALL,IAAI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C;YACvD,WAAW,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;YACvE,OAAO;gBACL,WAAW,EAAE,mBAAmB,CAAC,MAAM;gBACvC,OAAO;aACR,CAAC;IACN,CAAC;AACH,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 PropertyGrid\n */\n\nimport \"../../common/DisposePolyfill.js\";\n\nimport type { PropertyRecord, PropertyValue } from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat } from \"@itwin/appui-abstract\";\nimport type { HighlightInfo } from \"../../common/HighlightingComponentProps.js\";\nimport type { CategoryRecordsDict } from \"../internal/flat-items/MutableGridCategory.js\";\nimport type {\n IPropertyDataProvider,\n PropertyCategory,\n PropertyData,\n} from \"../PropertyDataProvider.js\";\nimport { PropertyDataChangeEvent } from \"../PropertyDataProvider.js\";\nimport type {\n FilteredType,\n IPropertyDataFilterer,\n PropertyDataFilterResult,\n} from \"./filterers/PropertyDataFiltererBase.js\";\n\ninterface FilteredRecords {\n filteredRecords: PropertyRecord[];\n shouldExpandNodeParents: boolean;\n matchesCount: number;\n activeMatch?: HighlightInfo;\n filteredResultMatches: { id: string; matchesCount: number }[];\n filteredTypes: FilteredType[];\n}\n\n/**\n * Data returned by [[FilteringPropertyDataProvider]]\n * @public\n */\nexport interface FilteredPropertyData extends PropertyData {\n /**\n * Shows how many matches were found when filtering data.\n * `undefined` when filterer is not active\n */\n matchesCount?: number;\n\n /**\n * Function used for getting [[HighlightInfo]] by index from all the filtered matches.\n * `undefined` when filterer is not active\n */\n getMatchByIndex?: (index: number) => HighlightInfo | undefined;\n\n /** Types of objects that were used for filtering. */\n filteredTypes?: FilteredType[];\n}\n\n/**\n * [[IPropertyDataProvider]] implementation which filters wrapped provider [[PropertyData]] using passed [[IPropertyDataFilterer]].\n * @public\n */\nexport class FilteringPropertyDataProvider\n implements IPropertyDataProvider, Disposable\n{\n public onDataChanged = new PropertyDataChangeEvent();\n private _filteredPropertyData: Promise<FilteredPropertyData> | undefined =\n undefined;\n private _disposeFilterChangedListener: (...args: any[]) => any;\n private _disposeDataChangedListener: (...args: any[]) => any;\n\n public constructor(\n private _dataProvider: IPropertyDataProvider,\n private _filterer: IPropertyDataFilterer\n ) {\n this._disposeFilterChangedListener =\n this._filterer.onFilterChanged.addListener(() => {\n this._filteredPropertyData = undefined;\n this.onDataChanged.raiseEvent();\n });\n this._disposeDataChangedListener =\n this._dataProvider.onDataChanged.addListener(() => {\n this._filteredPropertyData = undefined;\n this.onDataChanged.raiseEvent();\n });\n }\n\n #dispose() {\n this._disposeDataChangedListener();\n this._disposeFilterChangedListener();\n }\n\n /** Destructor. Must be called to clean up. */\n public [Symbol.dispose]() {\n this.#dispose();\n }\n\n /** @deprecated in 5.5.0. Use `[Symbol.dispose]` instead. */\n public dispose(): void {\n this.#dispose();\n }\n\n public async getData(): Promise<FilteredPropertyData> {\n if (this._filteredPropertyData) {\n return this._filteredPropertyData;\n }\n\n this._filteredPropertyData = this._dataProvider\n .getData()\n .then(async (propertyData) => {\n return this._filterer.isActive\n ? this.filterPropertyData(propertyData)\n : propertyData;\n });\n\n return this._filteredPropertyData;\n }\n\n private async filterPropertyData(propertyData: PropertyData) {\n const { categories, records, label, description } = { ...propertyData };\n const {\n filteredCategories,\n filteredRecords,\n matchesCount,\n filteredResultMatches,\n filteredTypes,\n } = await matchHierarchy(this._filterer, categories, records, undefined);\n\n const uniqueTypes = [...new Set(filteredTypes)];\n const getMatchByIndex = (index: number) => {\n let activeMatch: HighlightInfo | undefined;\n if (index <= 0) return undefined;\n\n let i = 1;\n for (const record of filteredResultMatches) {\n const fullMatchesCount = record.matchesCount;\n if (index < i + fullMatchesCount) {\n activeMatch = {\n highlightedItemIdentifier: record.id,\n highlightIndex: index - i,\n };\n break;\n }\n\n i += fullMatchesCount;\n }\n return activeMatch;\n };\n\n return {\n label,\n description,\n categories: filteredCategories,\n records: filteredRecords,\n reusePropertyDataState: false,\n matchesCount,\n getMatchByIndex,\n filteredTypes: uniqueTypes,\n };\n }\n}\n\nasync function matchHierarchy(\n filterer: IPropertyDataFilterer,\n categories: PropertyCategory[],\n records: CategoryRecordsDict,\n newRecords?: CategoryRecordsDict,\n parentMatchInfo?: PropertyDataFilterResult\n) {\n const newCategories: PropertyCategory[] = [];\n newRecords = newRecords ?? {};\n let matchesCount = 0;\n let allFilteredResultMatches: { id: string; matchesCount: number }[] = [];\n let allFilteredTypes: FilteredType[] = [];\n\n for (const category of categories) {\n const matchInfo = await filterer.categoryMatchesFilter(category, []);\n\n if (matchInfo.matchesFilter) {\n allFilteredResultMatches.push({\n id: category.name,\n matchesCount: matchInfo.matchesCount ?? 0,\n });\n allFilteredTypes = allFilteredTypes.concat(matchInfo.filteredTypes ?? []);\n matchesCount += matchInfo.matchesCount ?? 0;\n }\n\n const childRecords = records[category.name] ?? [];\n const {\n filteredRecords,\n matchesCount: count,\n filteredResultMatches,\n filteredTypes,\n } = await matchRecordHierarchy(filterer, childRecords, []);\n allFilteredResultMatches = allFilteredResultMatches.concat(\n filteredResultMatches\n );\n allFilteredTypes = allFilteredTypes.concat(filteredTypes);\n matchesCount += count;\n\n const parentInfo = parentMatchInfo?.matchesFilter\n ? parentMatchInfo\n : matchInfo;\n\n const childCategories = category.childCategories ?? [];\n const {\n filteredCategories,\n matchesCount: childCount,\n filteredResultMatches: childFilteredResultMatches,\n filteredTypes: childFilteredTypes,\n } = await matchHierarchy(\n filterer,\n childCategories,\n records,\n newRecords,\n parentInfo\n );\n allFilteredResultMatches = allFilteredResultMatches.concat(\n childFilteredResultMatches\n );\n allFilteredTypes = allFilteredTypes.concat(childFilteredTypes);\n matchesCount += childCount;\n\n let expand = !(count === 0 && childCount === 0);\n if (\n matchInfo.matchesFilter ||\n (parentMatchInfo?.matchesFilter &&\n parentMatchInfo.shouldForceIncludeDescendants)\n ) {\n newRecords[category.name] = records[category.name];\n if (matchInfo.matchesFilter) {\n expand = true;\n }\n const newCategory = copyPropertyCategory(\n category,\n filteredCategories,\n expand\n );\n newCategories.push(newCategory);\n }\n\n if (\n (filteredRecords.length !== 0 || filteredCategories.length !== 0) &&\n !matchInfo.matchesFilter &&\n !(\n parentMatchInfo?.shouldExpandNodeParents &&\n parentMatchInfo.matchesFilter\n )\n ) {\n const newCategory = copyPropertyCategory(\n category,\n filteredCategories,\n expand\n );\n newRecords[newCategory.name] = filteredRecords;\n newCategories.push(newCategory);\n }\n }\n\n return {\n filteredCategories: newCategories,\n filteredRecords: newRecords,\n matchesCount,\n filteredResultMatches: allFilteredResultMatches,\n filteredTypes: allFilteredTypes,\n };\n}\n\nasync function matchRecordHierarchy(\n filterer: IPropertyDataFilterer,\n records: PropertyRecord[],\n parents: PropertyRecord[],\n forceIncludeItem: boolean = false\n): Promise<FilteredRecords> {\n const newMatchedRecords: PropertyRecord[] = [];\n let expandParent = false; // property passed back to parent to indicate whether it should be expanded\n let matchesCount = 0;\n let filteredResultMatches: { id: string; matchesCount: number }[] = [];\n let filteredTypes: FilteredType[] = [];\n\n for (const record of records) {\n const matchInfo = await filterer.recordMatchesFilter(record, parents);\n const shouldForceIncludeDescendants =\n forceIncludeItem || matchInfo.shouldForceIncludeDescendants;\n const {\n filteredRecords: filteredChildren,\n shouldExpandNodeParents,\n matchesCount: childrenMatchesCount,\n filteredResultMatches: childrenResultMatches,\n filteredTypes: childrenFilteredTypes,\n } = await matchRecordHierarchy(\n filterer,\n record.getChildrenRecords(),\n [...parents, record],\n shouldForceIncludeDescendants\n );\n filteredResultMatches = filteredResultMatches.concat(childrenResultMatches);\n filteredTypes = [...filteredTypes, ...childrenFilteredTypes];\n matchesCount += childrenMatchesCount;\n // if child hierarchy indicates parents should be expanded, then it should be passed back up to the top parent\n expandParent = expandParent || shouldExpandNodeParents;\n\n let newRecord: PropertyRecord | undefined;\n if (matchInfo.matchesFilter) {\n filteredTypes = [...filteredTypes, ...(matchInfo.filteredTypes ?? [])];\n const recordMatchesCount = matchInfo.matchesCount ?? 0;\n matchesCount += recordMatchesCount;\n // Item is included if it matches filter\n // If at least one matched record from records list needs its parent expanded,\n // then `expandParent` should be set to true\n expandParent = expandParent || !!matchInfo.shouldExpandNodeParents;\n newRecord = copyPropertyRecord(\n record,\n filteredChildren,\n shouldExpandNodeParents\n );\n filteredResultMatches.push({\n id: newRecord.property.name,\n matchesCount: recordMatchesCount,\n });\n } else if (filteredChildren.length !== 0 || forceIncludeItem) {\n // Item is also included if it has at least one matched child or is forcefully included by its parent\n newRecord = copyPropertyRecord(\n record,\n filteredChildren,\n shouldExpandNodeParents\n );\n }\n\n if (newRecord) newMatchedRecords.push(newRecord);\n }\n\n return {\n filteredRecords: newMatchedRecords,\n shouldExpandNodeParents: expandParent,\n matchesCount,\n filteredResultMatches,\n filteredTypes,\n };\n}\n\nfunction copyPropertyCategory(\n propertyCategory: PropertyCategory,\n newChildren: PropertyCategory[],\n expand: boolean\n): PropertyCategory {\n return {\n ...propertyCategory,\n childCategories: newChildren,\n expand,\n };\n}\n\nfunction copyPropertyRecord(\n record: PropertyRecord,\n newChildren: PropertyRecord[],\n autoExpand: boolean\n) {\n const r = record.copyWithNewValue(\n createNewPropertyValue(record.value, newChildren)\n );\n r.autoExpand = autoExpand;\n return r;\n}\n\nfunction createNewPropertyValue(\n value: PropertyValue,\n newChildren: PropertyRecord[]\n): PropertyValue {\n switch (value.valueFormat) {\n case PropertyValueFormat.Primitive:\n return { ...value };\n case PropertyValueFormat.Array:\n return {\n valueFormat: PropertyValueFormat.Array,\n itemsTypeName: value.itemsTypeName,\n items: newChildren,\n };\n case PropertyValueFormat.Struct:\n const members: { [name: string]: PropertyRecord } = {};\n newChildren.forEach((child) => (members[child.property.name] = child));\n return {\n valueFormat: PropertyValueFormat.Struct,\n members,\n };\n }\n}\n"]}
|