LivePanels.Canvas.History (livepanels v0.1.0)

Copy Markdown View Source

Actor-scoped undo/redo history projection returned by LivePanels.Canvas.Read.history/1.

Applications may inspect this struct for read-only UI state such as enabling undo and redo controls. This module also owns the socket-first and transaction-first history command helpers.

Summary

Types

Opaque versioned history effect captured while reducers build a patch entry.

Opaque history effect capture options.

Opaque versioned history patch entry.

Opaque side of a versioned history patch entry.

t()

First argument accepted by history command helpers.

Functions

Returns whether the current history projection has an entry to redo.

Returns whether the current history projection has an entry to undo.

Summarizes the layout impact of one history entry for app-owned activity UI.

Reapplies history and returns the command result.

Reapplies the next entry in the current actor's canvas history.

Returns the number of redo entries in a history projection.

Returns redo entries in next-first order.

Rewinds history and returns the command result.

Rewinds the current actor's canvas history.

Returns the number of undo entries in a history projection.

Returns undo entries in newest-first order.

Types

command_result()

@type command_result() :: LivePanels.Canvas.Command.result()

effect()

@type effect() :: map()

Opaque versioned history effect captured while reducers build a patch entry.

effect_capture()

@type effect_capture() :: map()

Opaque history effect capture options.

entry()

@type entry() :: patch()

entry_delta()

@type entry_delta() :: %{
  item_delta: integer(),
  item_total: non_neg_integer(),
  connector_delta: integer(),
  connector_total: non_neg_integer(),
  changed_items: non_neg_integer()
}

patch()

@type patch() :: map()

Opaque versioned history patch entry.

History entries are tagged maps using internal keys such as :__livepanels_history_patch__. Host code should use helper functions such as entry_delta/1, undo_entries/1, and redo_entries/1 instead of depending on the serialized map shape.

patch_side()

@type patch_side() :: map()

Opaque side of a versioned history patch entry.

socket()

@type socket() :: Phoenix.LiveView.Socket.t()

t()

@type t() :: %LivePanels.Canvas.History{future: [entry()], past: [entry()]}

target()

@type target() :: LivePanels.Canvas.command_target()

First argument accepted by history command helpers.

Pass a LiveView socket for a standalone command, or a LivePanels.Canvas.Transaction context inside LivePanels.Canvas.transaction/2.

Functions

can_redo?(history)

@spec can_redo?(t() | term()) :: boolean()

Returns whether the current history projection has an entry to redo.

can_undo?(history)

@spec can_undo?(t() | term()) :: boolean()

Returns whether the current history projection has an entry to undo.

entry_delta(entry)

@spec entry_delta(entry() | map()) :: entry_delta()

Summarizes the layout impact of one history entry for app-owned activity UI.

redo(target)

@spec redo(target()) :: command_result()

Reapplies history and returns the command result.

redo!(target)

@spec redo!(target()) :: target()

Reapplies the next entry in the current actor's canvas history.

redo_count(history)

@spec redo_count(t() | term()) :: non_neg_integer()

Returns the number of redo entries in a history projection.

redo_entries(history)

@spec redo_entries(t() | term()) :: [entry()]

Returns redo entries in next-first order.

undo(target)

@spec undo(target()) :: command_result()

Rewinds history and returns the command result.

undo!(target)

@spec undo!(target()) :: target()

Rewinds the current actor's canvas history.

undo_count(history)

@spec undo_count(t() | term()) :: non_neg_integer()

Returns the number of undo entries in a history projection.

undo_entries(history)

@spec undo_entries(t() | term()) :: [entry()]

Returns undo entries in newest-first order.