Grapycal / Grapycal

A graphical and highly interactive programming language
https://www.grapycal.org
BSD 3-Clause "New" or "Revised" License
119 stars 8 forks source link

Editor: In-Node Editor #32

Open eri24816 opened 8 months ago

eri24816 commented 8 months ago

Enable a node to own an in-node editor, for defining composite functions or other purposes.

Expected behavior

When the (outer) node is double clicked, an inner editor opens and shows the containing graph. That can be nested. (不禁止套娃)

Notes

Grapycal should provide an interface to node developers to take use of this feature i.e. make a node to contain a graph.

eri24816 commented 8 months ago

My opinion:

While it's natural to think that the in-node editor represents the definition of the outer node in the form of a composite function, the purpose of in-node editors should not be restricted to that. Instead, it can be one of:

So the API should be general enough to enable all above. My proposal is to make the in-node Editor a control. That way, a node can own multiple in-node editors.

The SObject structure would be: Node - InNodeEditorControl - Editor - (Content of the in-node editor)

secminhr commented 8 months ago

About in-node edtitor

I think it would be more general if we see it as a sub-workspace. That way the full power of workspace can be leveraged and new features, including fixes, will be available automatically.

Providing this feature to node developers as a new component seems reasonable, as it follows our old practice to provide additional functionalities to node, but I suspect that it cannot be implemented as an ordinary component.

About multiple editors on a single node

Though we decided to provide it as a component, I think we should restrict the use of it to 1 editor a node for the following reasons:

  1. Though it is achievable, since we provide it as a component, it complicates the user interaction. If there's at most 1 editor per node, opening the editor can be a single action. If there're many, however, users must identity which to open, which further indicates that user may need to give each editor (in a node) a unique name.
  2. Multiple editors will be useful only when a node wants to have multiple workspaces for different tasks. However, such behaviour can be implemented with nesting, which sub-workspace already provides.

Desired functionalities

About implementation

I believe that figuring out the things that forms a workspace is important. So we should first ask: what are the essential components of a workspace? And how do they interact to provide what we have in a workspace?

eri24816 commented 8 months ago

Agree about the idea.

Let's clarify the terminology of Workspace and Editor first. In the current implementation's logic,

Back to the question: What level of functionality do we want an "in-node editor" have? Should it be an Editor, a WorkspaceObject, or something between?

[*1]: The code for delete is incorrectly placed at Workspace instead of Editor currently. This is to be fixed.

eri24816 commented 8 months ago

My first thought was it should be just an Editor (that's why I named the issue so). But maybe its nicer and more general to treat in-node editors as subgraphs and associate each of them to a .grapycal file, just like Workspace. We have to think up some use cases to decide the answer.

secminhr commented 8 months ago

What about the inspector at right? Is it a part of the main editor?

eri24816 commented 8 months ago

No. It is pure frontend thing

eri24816 commented 8 months ago

It's outside of the editor in the frontend. The editor is the central draggable area. I think the inspector should be global, one per webpage.