import * as React from "react"; import {SimpleGrid, Text, Title, Group, Stack, Button, Space, Textarea, Tabs, HoverCard, ActionIcon, Center} 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"; export function getDemoCorr() { const generateUUID = mockUuid(); const primitiveRegistry = new PrimitiveRegistry(); const commonStuff = {generateUUID, primitiveRegistry}; const as = newVersionedModel({readonly: false, ...commonStuff}); const cs = newVersionedModel({readonly: false, ...commonStuff}); const corr = newCorrespondence({cs, as, ...commonStuff}); // returns functional react component return function() { const [asState, setAsState] = React.useState(as.initialState); const [csState, setCsState] = React.useState(cs.initialState); const [corrState, setCorrState] = React.useState(corr.initialState); const asReducer = as.getReducer(setAsState); const csReducer = cs.getReducer(setCsState); const corrReducer = corr.getReducer(setCorrState, csReducer, asReducer); const csComponents = cs.getReactComponents(csState, { onUserEdit: corrReducer.parse, onUndoClicked: csReducer.undo, onRedoClicked: csReducer.redo, onVersionClicked: csReducer.gotoVersion, }); const corrComponents = corr.getReactComponents(corrState, { onUndoClicked: corrReducer.gotoVersion, onRedoClicked: corrReducer.gotoVersion, onVersionClicked: corrReducer.gotoVersion, }); const asComponents = as.getReactComponents(asState, { onUserEdit: corrReducer.render, onUndoClicked: asReducer.undo, onRedoClicked: asReducer.redo, onVersionClicked: asReducer.gotoVersion, }); const csTabs = ["editor", "state", "history", "dependencyL1", "dependencyL0"]; const corrTabs = ["state", "history", "dependencyL1", "dependencyL0"]; const asTabs = ["state", "history", "dependencyL1", "dependencyL0"]; const makeTabs = (components, defaultTab, tabs) => { return {tabs.map(tab => ({ editor: Editor, state: State, history: History, dependencyL1: Deltas (L1), dependencyL0: Deltas (L0), }[tab]))} {components.graphStateComponent} {components.rountangleEditor} {components.depGraphL1Component} {components.depGraphL0Component} {components.historyComponent} ; } return (<>
Concrete Syntax {makeTabs(csComponents, "editor", csTabs)} {makeTabs(csComponents, "history", csTabs)}
Correspondence {makeTabs(corrComponents, "state", corrTabs)} {makeTabs(corrComponents, "history", corrTabs)}
Abstract Syntax {makeTabs(asComponents, "state", asTabs)} {makeTabs(asComponents, "history", asTabs)}
{corrComponents.undoRedoButtons}
); } }