import { Canvas } from '../../interfaces/canvas'; import { Point } from '../../util/canvas-util'; import { DagaConnection, DagaNode } from '../converters/daga-model'; import { DiagramNodeGeometry } from '../model/diagram-node'; import { ValueSet } from '../property/value'; import { CollabTimestamp } from './primitives'; /** * An action taken by a local or remote user. * * The action can performed on its creator's device, serialized * and deserialized to reach remote users' devices, and performed * on remote users' devices. * @private */ export interface CollabAction { /** * Performs this action on the diagram. * * Note: Local Actions should call `canvas.collabEngine.doCollaboratively(collabAction)`, **not** this method directly. * * CollabAction `do()` methods must follow the rules of operation-based CRDT messages: * If two users concurrently create CollabActions (possibly of different types) on the same diagram, then performing the actions on a future diagram state _in either order_ must result in the same diagram state. */ do(): void; /** * Serializes this action, converting it to a JSON form. * * To deserialize, use the *static* deserialize method on the same class. */ serialize(): CollabActionSerialized; } /** * @private */ export type CollabActionSerialized = AddNodeSerialized | AddSectionSerialized | ApplyLayoutSerialized | MoveSerialized | SetGeometrySerialized | SetParentSerialized | AddConnectionSerialized | EditFieldSerialized | UpdateValuesSerialized | SetSelfRemovedSerialized | PasteSerialized; /** * @private */ export type AddNodeSerialized = { type: 'addNode'; id: string; typeId: string; coords: Point; parentId?: string; label?: string; values?: { [key: string]: unknown; }; }; /** * Collaborative action which consists of adding a node. * @private * @see AddNodeAction */ export declare class AddNodeCollabAction implements CollabAction { readonly canvas: Canvas; readonly id: string; readonly typeId: string; readonly coords: Point; readonly parentId?: string | undefined; readonly label?: string | undefined; readonly values?: { [key: string]: unknown; } | undefined; constructor(canvas: Canvas, id: string, typeId: string, coords: Point, parentId?: string | undefined, label?: string | undefined, values?: { [key: string]: unknown; } | undefined); do(): void; serialize(): AddNodeSerialized; static deserialize(canvas: Canvas, serialized: AddNodeSerialized): AddNodeCollabAction; } /** * @private */ export type AddSectionSerialized = { type: 'addSection'; nodeId: string; copyColumnIndex: number | undefined; copyRowIndex: number | undefined; removeColumnIndex: number | undefined; removeRowIndex: number | undefined; timestamp: CollabTimestamp; }; /** * Collaborative action which consists of adding or removing sections in a node. * @private * @see AddNodeAction */ export declare class AddSectionCollabAction implements CollabAction { readonly canvas: Canvas; readonly nodeId: string; readonly copyColumnIndex: number | undefined; readonly copyRowIndex: number | undefined; readonly removeColumnIndex: number | undefined; readonly removeRowIndex: number | undefined; readonly timestamp: CollabTimestamp; constructor(canvas: Canvas, nodeId: string, copyColumnIndex: number | undefined, copyRowIndex: number | undefined, removeColumnIndex: number | undefined, removeRowIndex: number | undefined, timestamp: CollabTimestamp); do(): void; serialize(): AddSectionSerialized; static deserialize(canvas: Canvas, serialized: AddSectionSerialized): AddSectionCollabAction; } /** * @private */ export type ApplyLayoutSerialized = { type: 'applyLayout'; to: { [key: string]: Point; }; timestamp: CollabTimestamp; }; /** * Collaborative which consists of applying a layout to the diagram which can change the location of several nodes. * @private * @see ApplyLayoutAction */ export declare class ApplyLayoutCollabAction implements CollabAction { readonly canvas: Canvas; readonly to: { [key: string]: Point; }; readonly timestamp: CollabTimestamp; constructor(canvas: Canvas, to: { [key: string]: Point; }, timestamp: CollabTimestamp); do(): void; serialize(): ApplyLayoutSerialized; static deserialize(canvas: Canvas, serialized: ApplyLayoutSerialized): ApplyLayoutCollabAction; } /** * @private */ export type MoveSerialized = { type: 'move'; nodeIds: string[]; delta: Point; timestamp: CollabTimestamp; }; /** * Collaborative which consists of changing the coordinates of diagram elements by a fixed amount. * @private * @see MoveAction */ export declare class MoveCollabAction implements CollabAction { readonly canvas: Canvas; readonly nodeIds: string[]; readonly delta: Point; readonly timestamp: CollabTimestamp; constructor(canvas: Canvas, nodeIds: string[], delta: Point, timestamp: CollabTimestamp); do(): void; serialize(): MoveSerialized; static deserialize(canvas: Canvas, serialized: MoveSerialized): MoveCollabAction; } /** * @private */ export type SetGeometrySerialized = { type: 'setGeometry'; nodeId: string; to: DiagramNodeGeometry; timestamp: CollabTimestamp; }; /** * Collaborative action which consists of changing a node's geometry: moving, stretching, or stretching sections. * @private * @see SetGeometryAction */ export declare class SetGeometryCollabAction implements CollabAction { readonly canvas: Canvas; readonly nodeId: string; readonly to: DiagramNodeGeometry; readonly timestamp: CollabTimestamp; constructor(canvas: Canvas, nodeId: string, to: DiagramNodeGeometry, timestamp: CollabTimestamp); do(): void; serialize(): SetGeometrySerialized; static deserialize(canvas: Canvas, serialized: SetGeometrySerialized): SetGeometryCollabAction; } /** * @private */ export type SetParentSerialized = { type: 'setParent'; childId: string; parentId: string | undefined; childGeometry: DiagramNodeGeometry; timestamp: CollabTimestamp; }; /** * Collaborative action which consists of setting a node's parent. * @private * @see SetParentAction */ export declare class SetParentCollabAction implements CollabAction { readonly canvas: Canvas; readonly childId: string; readonly parentId: string | undefined; readonly childGeometry: DiagramNodeGeometry; readonly timestamp: CollabTimestamp; constructor(canvas: Canvas, childId: string, parentId: string | undefined, childGeometry: DiagramNodeGeometry, timestamp: CollabTimestamp); do(): void; serialize(): SetParentSerialized; static deserialize(canvas: Canvas, serialized: SetParentSerialized): SetParentCollabAction; } /** * @private */ export type AddConnectionSerialized = { type: 'addConnection'; id: string; typeId: string; startId: string; endId: string; }; /** * Collaborative action which consists of adding a connection. * @private * @see AddConnectionAction */ export declare class AddConnectionCollabAction implements CollabAction { readonly canvas: Canvas; readonly id: string; readonly typeId: string; readonly startId: string; readonly endId: string; constructor(canvas: Canvas, id: string, typeId: string, startId: string, endId: string); do(): void; serialize(): AddConnectionSerialized; static deserialize(canvas: Canvas, serialized: AddConnectionSerialized): AddConnectionCollabAction; } /** * @private */ export type EditFieldSerialized = { type: 'editField'; fieldId: string; to: string; timestamp: CollabTimestamp; }; /** * Collaborative action which consists of editing the text of a field. * @private * @see EditFieldAction */ export declare class EditFieldCollabAction implements CollabAction { readonly canvas: Canvas; readonly fieldId: string; readonly to: string; readonly timestamp: CollabTimestamp; constructor(canvas: Canvas, fieldId: string, to: string, timestamp: CollabTimestamp); do(): void; serialize(): EditFieldSerialized; static deserialize(canvas: Canvas, serialized: EditFieldSerialized): EditFieldCollabAction; } /** * @private */ export type UpdateValuesSerialized = { type: 'updateValues'; id: string | undefined; to: { [key: string]: unknown; }; timestamp: CollabTimestamp; }; /** * Collaborative action which consists of editing the values of a value set. * @private * @see UpdateValuesAction */ export declare class UpdateValuesCollabAction implements CollabAction { readonly canvas: Canvas; readonly id: string | undefined; readonly to: { [key: string]: unknown; }; readonly timestamp: CollabTimestamp; constructor(canvas: Canvas, id: string | undefined, to: { [key: string]: unknown; }, timestamp: CollabTimestamp); getValueSet(): ValueSet | undefined; do(): void; serialize(): UpdateValuesSerialized; static deserialize(canvas: Canvas, serialized: UpdateValuesSerialized): UpdateValuesCollabAction; } /** * @private */ export type SetSelfRemovedSerialized = { type: 'setSelfRemoved'; nodeIds: string[]; sectionIds: string[]; portIds: string[]; connectionIds: string[]; fieldIds: string[]; removed: boolean; timestamp: CollabTimestamp; }; /** * Collaborative action which consists of removing or un-removing elements. * * Specifically, the action sets the `selfRemoved` field for elements that are * explicitly removed/unremoved. This causes the `removed` fields for those elements * and their transitive dependents to update automatically. * For example, self-removing a node also removes all of its sections/connections/etc. * * @private * @see RemoveAction */ export declare class SetSelfRemovedCollabAction implements CollabAction { #private; readonly canvas: Canvas; readonly nodeIds: string[]; readonly sectionIds: string[]; readonly portIds: string[]; readonly connectionIds: string[]; readonly fieldIds: string[]; readonly selfRemoved: boolean; readonly timestamp: CollabTimestamp; constructor(canvas: Canvas, nodeIds: string[], sectionIds: string[], portIds: string[], connectionIds: string[], fieldIds: string[], selfRemoved: boolean, timestamp: CollabTimestamp); do(): void; serialize(): CollabActionSerialized; static deserialize(canvas: Canvas, serialized: SetSelfRemovedSerialized): SetSelfRemovedCollabAction; } /** * @private */ export type PasteSerialized = { type: 'paste'; readonly nodes: DagaNode[]; readonly connections: DagaConnection[]; }; /** * Collaborative action which consists of pasting elements from an external source into a diagram. * * @private * @see PasteAction */ export declare class PasteCollabAction implements CollabAction { readonly canvas: Canvas; readonly nodes: DagaNode[]; readonly connections: DagaConnection[]; constructor(canvas: Canvas, nodes: DagaNode[], connections: DagaConnection[]); do(): void; serialize(): CollabActionSerialized; static deserialize(canvas: Canvas, serialized: PasteSerialized): PasteCollabAction; }