/*** * Controls are rendered in the property panel from the property config * Controls are higher order components that update a widgets property */ import { Component } from "react"; import type { EditorTheme } from "components/editorComponents/CodeEditor/EditorConfig"; import type { PropertyPaneControlConfig } from "constants/PropertyControlConstants"; import type { CodeEditorExpected } from "components/editorComponents/CodeEditor"; import type { AdditionalDynamicDataTree } from "utils/autocomplete/customTreeTypeDefCreator"; export type ControlMethods = Record< "canDisplayValueInUI" | "shouldValidateValueOnDynamicPropertyOff", | typeof BaseControl.canDisplayValueInUI | typeof BaseControl.shouldValidateValueOnDynamicPropertyOff >; // eslint-disable-next-line @typescript-eslint/ban-types class BaseControl
extends Component
{
shoudUpdateProperty(propertyValue: unknown) {
return !(
(this.props.propertyValue === undefined &&
propertyValue === this.props.defaultValue) ||
!(this.props.propertyValue !== propertyValue)
);
}
updateProperty(
propertyName: string,
propertyValue: any,
isUpdatedViaKeyboard?: boolean,
) {
if (
this.shoudUpdateProperty(propertyValue) &&
this.props.onPropertyChange
) {
this.props.onPropertyChange(
propertyName,
propertyValue,
isUpdatedViaKeyboard,
);
}
}
deleteProperties(propertyPaths: string[]) {
if (this.props.deleteProperties) {
this.props.deleteProperties(propertyPaths);
}
}
batchUpdatePropertiesWithAssociatedUpdates = (
updates: { propertyName: string; propertyValue: any }[],
) => {
if (this.props.onBatchUpdateWithAssociatedUpdates) {
this.props.onBatchUpdateWithAssociatedUpdates(
updates.filter(({ propertyValue }) =>
this.shoudUpdateProperty(propertyValue),
),
);
}
};
batchUpdateProperties = (updates: Record