|
@@ -19,6 +19,7 @@ import {
|
|
|
} from "../d3graph/reducers/history_graph";
|
|
|
|
|
|
import * as helpText from "./help_text";
|
|
|
+import {MergeView} from "./merge_view";
|
|
|
|
|
|
import {D3Graph, emptyGraph, defaultGraphForces} from "../d3graph/d3graph";
|
|
|
import {RountangleEditor} from "../rountangleEditor/RountangleEditor";
|
|
@@ -46,6 +47,7 @@ interface VersionedModelCallbacks {
|
|
|
onUndoClicked?: (parentVersion: Version, deltaToUndo: Delta) => void;
|
|
|
onRedoClicked?: (childVersion: Version, deltaToRedo: Delta) => void;
|
|
|
onVersionClicked?: (Version) => void;
|
|
|
+ onMerge?: (outputs: Version[]) => void;
|
|
|
}
|
|
|
|
|
|
// Basically everything we need to construct the React components for:
|
|
@@ -85,13 +87,7 @@ export function newVersionedModel({readonly}) {
|
|
|
|
|
|
// Create and add a new version, and its deltas, without changing the current version
|
|
|
const addDeltasAndVersion = (deltas: PrimitiveDelta[], description: string, parentHash: Buffer) => {
|
|
|
- let composite;
|
|
|
- // try {
|
|
|
- composite = compositeLevel.createComposite(deltas, description);
|
|
|
- // } catch(e) {
|
|
|
-
|
|
|
- // return;
|
|
|
- // }
|
|
|
+ const composite = compositeLevel.createComposite(deltas, description);
|
|
|
|
|
|
const parentVersion = versionRegistry.lookupOptional(parentHash);
|
|
|
if (parentVersion !== undefined) {
|
|
@@ -99,7 +95,7 @@ export function newVersionedModel({readonly}) {
|
|
|
|
|
|
setState(({historyGraph, deltaGraphL1, deltaGraphL0, ...rest}) => {
|
|
|
return {
|
|
|
- // add new version to history graph + highlight the new version as the current version:
|
|
|
+ // add new version to history graph:
|
|
|
historyGraph: historyGraphReducer(historyGraph, {type: 'addVersion', version: newVersion}),
|
|
|
// add the composite delta to the L1-graph + highlight it as 'active':
|
|
|
deltaGraphL1: composite.deltas.length > 0 ? deltaGraphReducer(deltaGraphL1, {type: 'addDelta', delta: composite, active: false}) : deltaGraphL1, // never add an empty composite
|
|
@@ -119,6 +115,15 @@ export function newVersionedModel({readonly}) {
|
|
|
gotoVersion(newVersion);
|
|
|
return newVersion;
|
|
|
};
|
|
|
+ const appendVersion = (version: Version) => {
|
|
|
+ setState(({historyGraph, ...rest}) => {
|
|
|
+ return {
|
|
|
+ // add new version to history graph:
|
|
|
+ historyGraph: historyGraphReducer(historyGraph, {type: 'addVersion', version}),
|
|
|
+ ...rest,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
// helper
|
|
|
const setGraph = callback =>
|
|
@@ -148,7 +153,9 @@ export function newVersionedModel({readonly}) {
|
|
|
currentVersion = parentVersion;
|
|
|
setState(({historyGraph: prevHistoryGraph, version: prevVersion, ...rest}) => ({
|
|
|
version: parentVersion,
|
|
|
- historyGraph: historyGraphReducer(prevHistoryGraph, {type: 'setCurrentVersion', prev: prevVersion, new: parentVersion}),
|
|
|
+ historyGraph: historyGraphReducer(historyGraphReducer(prevHistoryGraph,
|
|
|
+ {type: 'highlightVersion', version: prevVersion, bold: false}),
|
|
|
+ {type: 'highlightVersion', version: parentVersion, bold: true}),
|
|
|
...rest,
|
|
|
}));
|
|
|
};
|
|
@@ -157,7 +164,9 @@ export function newVersionedModel({readonly}) {
|
|
|
currentVersion = childVersion;
|
|
|
setState(({historyGraph: prevHistoryGraph, version: prevVersion, ...rest}) => ({
|
|
|
version: childVersion,
|
|
|
- historyGraph: historyGraphReducer(prevHistoryGraph, {type: 'setCurrentVersion', prev: prevVersion, new: childVersion}),
|
|
|
+ historyGraph: historyGraphReducer(historyGraphReducer(prevHistoryGraph,
|
|
|
+ {type: 'highlightVersion', version: prevVersion, bold: false}),
|
|
|
+ {type: 'highlightVersion', version: childVersion, bold: true}),
|
|
|
...rest,
|
|
|
}));
|
|
|
};
|
|
@@ -177,7 +186,9 @@ export function newVersionedModel({readonly}) {
|
|
|
currentVersion = chosenVersion;
|
|
|
setState(({historyGraph, version: oldVersion, ...rest}) => ({
|
|
|
version: chosenVersion,
|
|
|
- historyGraph: historyGraphReducer(historyGraph, {type: 'setCurrentVersion', prev: oldVersion, new: chosenVersion}),
|
|
|
+ historyGraph: historyGraphReducer(historyGraphReducer(historyGraph,
|
|
|
+ {type: 'highlightVersion', version: oldVersion, bold: false}),
|
|
|
+ {type: 'highlightVersion', version: chosenVersion, bold: true}),
|
|
|
...rest,
|
|
|
}));
|
|
|
};
|
|
@@ -186,6 +197,7 @@ export function newVersionedModel({readonly}) {
|
|
|
addDeltasAndVersion,
|
|
|
gotoVersion,
|
|
|
createAndGotoNewVersion,
|
|
|
+ appendVersion,
|
|
|
undo,
|
|
|
redo,
|
|
|
};
|
|
@@ -218,6 +230,13 @@ export function newVersionedModel({readonly}) {
|
|
|
mouseUpHandler={(e, {x, y}, node) => node ? callbacks.onVersionClicked?.(node.obj) : undefined} />
|
|
|
</InfoHoverCardOverlay>;
|
|
|
|
|
|
+ const historyComponentWithMerge = <MergeView
|
|
|
+ history={state.historyGraph}
|
|
|
+ forces={defaultGraphForces}
|
|
|
+ versionRegistry={versionRegistry}
|
|
|
+ onMerge={outputs => callbacks.onMerge?.(outputs)}
|
|
|
+ onGoto={version => callbacks.onVersionClicked?.(version)} />
|
|
|
+
|
|
|
const rountangleEditor = <InfoHoverCardOverlay contents={helpText.rountangleEditor}>
|
|
|
<RountangleEditor
|
|
|
graph={state.graph}
|
|
@@ -316,6 +335,7 @@ export function newVersionedModel({readonly}) {
|
|
|
deltaGraphL1Component,
|
|
|
deltaGraphL0Component,
|
|
|
historyComponent,
|
|
|
+ historyComponentWithMerge,
|
|
|
undoButton,
|
|
|
redoButton,
|
|
|
undoRedoButtons,
|
|
@@ -328,6 +348,7 @@ export function newVersionedModel({readonly}) {
|
|
|
return {
|
|
|
initialState,
|
|
|
graphState,
|
|
|
+ versionRegistry,
|
|
|
getCurrentVersion,
|
|
|
getReducer,
|
|
|
getReactComponents,
|