LivePanels.Canvas.DragDrop (livepanels v0.1.0)

Copy Markdown View Source

Normalization for LivePanels cross-space drag/drop declarations and payloads.

Drag/drop is explicit opt-in. Items declare the actions they allow and the placement spaces they may target. Browser drop requests use a single payload shape:

%{
  action: :move | :copy | :add,
  target_space: :world | :viewport,
  x: integer,
  y: integer,
  w: pos_integer,
  h: pos_integer,
  anchor: LivePanels.Canvas.Placement.anchor(),
  source_item_id: String.t(), # required for :move and :copy
  source_type: atom() | String.t(), # required for :add
  opts: map()
}

Summary

Functions

Returns the supported drag/drop actions.

Serializes allowed drag/drop actions for HTML data attributes.

Returns true when a drag/drop capability allows an action into a target space.

Returns an empty drag/drop capability declaration.

Normalizes an item drag/drop capability declaration.

Returns the placement spaces that can receive drops.

Serializes allowed drag/drop target spaces for HTML data attributes.

Types

action()

@type action() :: :move | :copy | :add

capability()

@type capability() :: %{actions: [action()], targets: [target()]}

drop()

@type drop() :: %{
  :action => action(),
  :target_space => target(),
  :placement => LivePanels.Canvas.Placement.frame(),
  optional(:source_item_id) => String.t(),
  optional(:source_type) => atom() | String.t(),
  opts: map()
}

target()

@type target() :: LivePanels.Canvas.Placement.space()

Functions

actions()

@spec actions() :: [action()]

Returns the supported drag/drop actions.

actions_attr(capability)

@spec actions_attr(capability() | nil | term()) :: String.t()

Serializes allowed drag/drop actions for HTML data attributes.

allowed?(capability, action, target_space)

@spec allowed?(capability() | nil | term(), action(), target()) :: boolean()

Returns true when a drag/drop capability allows an action into a target space.

empty()

@spec empty() :: capability()

Returns an empty drag/drop capability declaration.

normalize_capability(value)

@spec normalize_capability(term()) :: {:ok, capability() | nil} | {:error, atom()}

Normalizes an item drag/drop capability declaration.

targets()

@spec targets() :: [target()]

Returns the placement spaces that can receive drops.

targets_attr(capability)

@spec targets_attr(capability() | nil | term()) :: String.t()

Serializes allowed drag/drop target spaces for HTML data attributes.