import * as React from "react";
import {SimpleGrid, Text, Title, Stack, Center, Switch, Group, Space, Blockquote} from "@mantine/core";
import {PrimitiveRegistry} from "../onion/primitive_delta";
import {mockUuid} from "../onion/test_helpers";
import {newVersionedModel, VersionedModelState} from "./versioned_model";
import {newCorrespondence} from "./correspondence";
import {newManualRenderer, ManualRendererProps} from "./manual_renderer";
import {makeInfoHoverCardIcon} from "./help_icons";
import {MdOutlineDraw} from "react-icons/md";
import {Actionblock, Resultblock} from "./blocks";
export const demo_Editor_description =
<>
Rountangle Editor
Next to this text you can see three columns Rountangle Editor, Deltas,
and State Graph. In the Rountangle Editor, you can create (unnamed) rountangles by
left-clicking on the grey area with the alt-key pressed (see also the small info in the upper right corner
of each canvas).
In this demo, the editable state graph of the "Primitive Delta"-demo is replaced by a Rountangle Editor.
Again, any action in the Rountangle Editor results in a set of primitive deltas (shown in the center) that are applied to the (empty) state graph (on the right).
Note that this state graph is no longer (directly) editable. The current model state is visualized in the Rountangle Editor from which the user interaction originated.
1. Create a rountangle!
In the second column, one composite delta "createRountangle" was created.
In the second tab "Deltas (L0)" of the second column you can see the primitive deltas a "createRountangle" consists of.
The result of an application of all primitive deltas to an empty initial state is shown in the third column "State Graph".
2. Move your created rountangle!
For each movement a new "moveRountangle" composite delta is created that depends on the previous one.
On the level of primitive deltas (L0), you can observe that only the "x" and "y" edges are updated (UPD).
On the State Graph, only the "x" and "y" edges are updated to point to other values.
3. Switch to the "History" tab in the "Deltas" column and trigger some "Undo" operations (below the Rountangle Editor)!
The currently active version has a bold border. All versions are kept.
In the "Delta (L1)" and "Delta (L0)" tabs, the deltas corresponding to the current version are also highlighted.
Feel free to play around with the editor and watch the changes in the other views.
>;
export function getDemoEditor() {
const generateUUID = mockUuid();
const primitiveRegistry = new PrimitiveRegistry();
const commonStuff = {generateUUID, primitiveRegistry};
const cs = newVersionedModel({readonly: true, ...commonStuff});
const {getModalManualRenderer} = newManualRenderer(commonStuff);
// returns functional react component
return function () {
const [csState, setCsState] = React.useState(cs.initialState);
const [manualRendererState, setManualRendererState] = React.useState(null);
const csReducer = cs.getReducer(setCsState);
const csComponents = cs.getReactComponents(csState, {
onUserEdit: (deltas, description) => {
const newVersion = csReducer.createAndGotoNewVersion(deltas, description);
},
onUndoClicked: csReducer.undo,
onRedoClicked: csReducer.redo,
onVersionClicked: csReducer.gotoVersion,
});
const deltaTabs = ["dependencyL1", "dependencyL0", "history"];
const undoButtonHelpText = "Use the Undo/Redo buttons or the History panel to navigate to any version.";
return (
{getModalManualRenderer(manualRendererState)}
Rountangle Editor
{csComponents.rountangleEditor}
{csComponents.undoRedoButtons}
{makeInfoHoverCardIcon(undoButtonHelpText)}
Deltas
{csComponents.makeTabs("dependencyL1", deltaTabs)}
State Graph
{csComponents.graphStateComponent}
);
}
}