Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Oct 2, 2024
1 parent 5923cd7 commit 0b7c28d
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 31 deletions.
1 change: 1 addition & 0 deletions packages/eez-studio-ui/_stylesheets/project-editor.less
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,7 @@

.title-enclosure {
overflow: hidden;
min-width: 0px;

svg {
fill-opacity: 30%;
Expand Down
8 changes: 8 additions & 0 deletions packages/project-editor/flow/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4061,6 +4061,14 @@ function renderActionComponent(
{executionStateInfo}
<span className="title-text">{getLabel(actionNode)}</span>
</div>
{actionNode instanceof
ProjectEditor.CommentActionComponentClass &&
actionNode.collapsed && (
<Icon
icon="material:arrow_drop_down"
style={{ opacity: 0.5 }}
/>
)}
{seqOutputIndex != -1 && (
<ComponentOutputSpan
componentOutput={actionNode.outputs[seqOutputIndex]}
Expand Down
97 changes: 68 additions & 29 deletions packages/project-editor/flow/components/actions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4031,22 +4031,37 @@ export class CommentActionComponent extends ActionComponent {
static classInfo = makeDerivedClassInfo(ActionComponent.classInfo, {
flowComponentId: COMPONENT_TYPE_COMMENT_ACTION,

label: () => "",
label: (object: CommentActionComponent) => object.description,

properties: [
{
name: "text",
type: PropertyType.String,
hideInPropertyGrid: true,
hideInDocumentation: "all"
},
{
name: "collapsed",
type: PropertyType.Boolean,
hideInPropertyGrid: true,
hideInDocumentation: "none"
},
{
name: "expandedWidth",
type: PropertyType.Number,
hideInPropertyGrid: true,
hideInDocumentation: "none"
}
],
beforeLoadHook: (
object: CommentActionComponent,
jsObject: Partial<CommentActionComponent>
) => {
if (jsObject.description) {
delete jsObject.description;
if (jsObject.collapsed == undefined) {
jsObject.collapsed = false;
}
if (jsObject.expandedWidth == undefined) {
jsObject.expandedWidth = jsObject.width;
}
},
icon: (
Expand All @@ -4063,37 +4078,59 @@ export class CommentActionComponent extends ActionComponent {
left: 0,
top: 0,
width: 435,
height: 134
height: 134,
collapsed: false
},
open: (object: CommentActionComponent) => {
const collapsed = !object.collapsed;

if (collapsed) {
ProjectEditor.getProjectStore(object).updateObject(object, {
collapsed: !object.collapsed,
expandedWidth: object.width
});
} else {
ProjectEditor.getProjectStore(object).updateObject(object, {
collapsed: !object.collapsed,
width: object.expandedWidth
});
}
}
});

text: string;
collapsed: boolean;
expandedWidth: number;

override makeEditable() {
super.makeEditable();

makeObservable(this, {
text: observable
text: observable,
collapsed: observable,
expandedWidth: observable
});
}

get autoSize(): AutoSize {
return "height";
return this.collapsed ? "both" : "height";
}

getResizeHandlers(): IResizeHandler[] | undefined | false {
return [
{
x: 0,
y: 50,
type: "w-resize"
},
{
x: 100,
y: 50,
type: "e-resize"
}
];
return this.collapsed
? []
: [
{
x: 0,
y: 50,
type: "w-resize"
},
{
x: 100,
y: 50,
type: "e-resize"
}
];
}

getClassName(flowContext: IFlowContext) {
Expand All @@ -4105,17 +4142,19 @@ export class CommentActionComponent extends ActionComponent {

getBody(flowContext: IFlowContext): React.ReactNode {
return (
<TrixEditor
component={this}
flowContext={flowContext}
value={this.text}
setValue={action((value: string) => {
const projectStore = getProjectStore(this);
projectStore.updateObject(this, {
text: value
});
})}
></TrixEditor>
!this.collapsed && (
<TrixEditor
component={this}
flowContext={flowContext}
value={this.text}
setValue={action((value: string) => {
const projectStore = getProjectStore(this);
projectStore.updateObject(this, {
text: value
});
})}
></TrixEditor>
)
);
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/project-editor/flow/editor/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ export const ComponentEnclosure = observer(
// component description
component instanceof
ProjectEditor.ActionComponentClass &&
!(
component instanceof
ProjectEditor.CommentActionComponentClass
) &&
component.description &&
flowContext.projectStore.uiStateStore
.showComponentDescriptions &&
Expand Down
4 changes: 3 additions & 1 deletion packages/project-editor/project-editor-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import { getObjectVariableTypeFromType } from "project-editor/features/variable/
// ACTIONS
import {
OutputActionComponent,
CallActionActionComponent
CallActionActionComponent,
CommentActionComponent
} from "project-editor/flow/components/actions";
import "project-editor/flow/components/actions/execute-command";
import "project-editor/flow/components/actions/stream";
Expand Down Expand Up @@ -174,6 +175,7 @@ export async function createProjectEditor(
ActionClass: Action,
ComponentClass: Component,
ActionComponentClass: ActionComponent,
CommentActionComponentClass: CommentActionComponent,
WidgetClass: Widget,
ConnectionLineClass: ConnectionLine,
UserWidgetWidgetClass: UserWidgetWidget,
Expand Down
4 changes: 3 additions & 1 deletion packages/project-editor/project-editor-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ import type { browseGlyph } from "project-editor/features/font/FontEditor";
import type { Variable } from "project-editor/features/variable/variable";
import type {
OutputActionComponent,
CallActionActionComponent
CallActionActionComponent,
CommentActionComponent
} from "project-editor/flow/components/actions";
import type {
ContainerWidget,
Expand Down Expand Up @@ -123,6 +124,7 @@ export interface IProjectEditor {
ActionClass: typeof Action;
ComponentClass: typeof Component;
ActionComponentClass: typeof ActionComponent;
CommentActionComponentClass: typeof CommentActionComponent;
WidgetClass: typeof Widget;
ConnectionLineClass: typeof ConnectionLine;
UserWidgetWidgetClass: typeof UserWidgetWidget;
Expand Down

0 comments on commit 0b7c28d

Please sign in to comment.