Skip to content

feat: add XMLEditor #1

@ca-d

Description

@ca-d

Add an XMLEditor class which internally uses our handleEdit function in order to provide:

  • a transact method used to transact new Edits by calling handleEdit while recording that edit in
  • an undo stack "past" containing already transacted Edits,
  • a redo stack "future" containing already undone Edits,
  • an undo method which moves the most recent past edit to the top of the future stack, transacting the undo edit and returning the new most recent transaction record, if any,
  • a redo method which moves the next future edit in line to the top of the past stack, transacting the redo edit and returning the new most recent transaction record,
  • a canUndo boolean property indicating presence of past edits to undo,
  • a canRedo boolean property indicating presence of future edits to redo,
  • and a way to add and remove "transacted" callbacks, which it calls passing the new most recent transaction record whenever edit, undo, or redo have been called, so that users may be notified of transactions.

Apart from the Edit to commit, the edit method should also allow the user to specify an optional string title for the transaction, and to indicate by optional boolean flag whether to squash the current transaction onto the last committed transaction, rolling them into a single undo entry and updating the title if given.

Given our EditV2 class and the types

// Transaction intent in flight
export interface Transaction<Change> {
  change: Change;
  title?: string;
  squash?: boolean;
}
// record of committed Transaction
export interface TransactionRecord<Change> {
  changes: Change[];
  title?: string;
  txID: number;
}
export type TransactedCallback<Change> = (txRecord: TransactionRecord<Change>) => void;
export interface Transactor<Change> {
  transact(tx: Transaction<Change>): TransactionRecord<Change>; // May throw - duck!
  undo(): TransactionRecord<Change> | undefined;
  redo(): TransactionRecord<Change>;
  canUndo: boolean;
  canRedo: boolean;
  past: TransactionRecord[];
  future: TransactionRecord[];
  addTransactedCallback(txCallback: TransactedCallback): void;
  removeTransactedCallback(txCallback: TransactedCallback): void;
}

our class should implement

export class XMLEditor implements Transactor<EditV2>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions