import React from "react"; import { observable, makeObservable } from "mobx"; import { observer } from "mobx-react"; import { Icon } from "eez-studio-ui/icon"; import { findPropertyByNameInClassInfo, PropertyProps, getObjectPropertyDisplayName } from "project-editor/core/object"; import { ProjectContext } from "project-editor/project/context"; import { Property } from "./Property"; import { PropertyGrid } from "./index"; import { propertyCollapsedStore } from "./PropertyCollapsedStore"; import { getNumModifications } from "project-editor/store"; import classNames from "classnames"; export const EmbeddedPropertyGrid = observer( class EmbeddedPropertyGrid extends React.Component { static contextType = ProjectContext; declare context: React.ContextType; collapsed = true; toggleCollapsed = () => { propertyCollapsedStore.toggleColapsed( this.props.objects[0], this.props.propertyInfo ); }; updateObject = (propertyValues: Object) => { this.context.undoManager.setCombineCommands(true); this.props.objects.forEach(object => { object = (object as any)[this.props.propertyInfo.name]; this.context.updateObject(object, propertyValues); }); this.context.undoManager.setCombineCommands(false); }; constructor(props: PropertyProps) { super(props); makeObservable(this, { collapsed: observable }); } render() { const { objects, propertyInfo } = this.props; if (!propertyInfo.propertyGridCollapsable) { return (
(object as any)[propertyInfo.name] )} />
); } const collapsed = propertyCollapsedStore.isCollapsed( this.props.objects[0], this.props.propertyInfo ); if (collapsed) { if (propertyInfo.propertyGridCollapsableDefaultPropertyName) { const defaultPropertyInfo = findPropertyByNameInClassInfo( propertyInfo.typeClass!.classInfo, propertyInfo.propertyGridCollapsableDefaultPropertyName )!; return ( (object as any)[propertyInfo.name] )} updateObject={this.updateObject} readOnly={this.props.readOnly} /> ); } else { return (
{getObjectPropertyDisplayName( objects[0], propertyInfo )}
); } } const numModifications = getNumModifications({ ...this.props, objects: objects.map( object => (object as any)[propertyInfo.name] ) }); return (
0 })} > {getObjectPropertyDisplayName( objects[0], propertyInfo )} {numModifications > 0 && ` (${numModifications})`}
(object as any)[propertyInfo.name] )} />
); } } );