View Source Delta.Op (Delta v0.4.0)

Summary

Types

Stand-in type while attributes is keyed with String.t() instead of Atom.t()

Stand-in type while operators are keyed with String.t() instead of Atom.t()

Stand-in type while operators are keyed with String.t() instead of Atom.t()

Stand-in type while operators are keyed with String.t() instead of Atom.t()

Stand-in type while operators are keyed with String.t() instead of Atom.t()

t()

Functions

A shorthand for new("delete", value, attributes). See new/3.

A shorthand for type?(op, "delete", type). See type?/3.

Gets two embeds' data. An embed is always a one-key map

Returns true if operation has attributes

A shorthand for new("insert", value, attributes). See new/3.

A shorthand for type?(op, "insert", type). See type?/3.

Create a new operation.

A shorthand for new("retain", value, attributes). See new/3.

A shorthand for type?(op, "insert", type). See type?/3.

Returns operation size.

Takes length characters from an operation and returns it together with the remaining part in a tuple.

Returns text size.

Returns true if operation is of type type. Optionally check against more specific value_type.

Types

@type attributes() :: %{required(String.t()) => attributes_val()}

Stand-in type while attributes is keyed with String.t() instead of Atom.t()

@type delete_op() :: %{
  required(delete_key()) => pos_integer(),
  optional(attributes()) => attributes_val()
}

Stand-in type while operators are keyed with String.t() instead of Atom.t()

%{delete: pos_integer()}

@type insert_op() :: %{
  required(insert_key()) => insert_val(),
  optional(attributes()) => attributes_val()
}

Stand-in type while operators are keyed with String.t() instead of Atom.t()

%{insert: String.t() | EmbedHandler.embed(), ...}

@type operation() :: insert_key() | retain_key() | delete_key()

Stand-in type while operators are keyed with String.t() instead of Atom.t()

@type retain_op() :: %{
  required(retain_key()) => retain_val(),
  optional(attributes()) => attributes_val()
}

Stand-in type while operators are keyed with String.t() instead of Atom.t()

%{retain: pos_integer() | EmbedHandler.embed()}

@type t() :: insert_op() | retain_op() | delete_op()

Functions

@spec compose(a :: t(), b :: t()) :: {t() | false, t(), t()}
Link to this function

delete(value, attr \\ false)

View Source
@spec delete(value :: delete_val(), attr :: attributes_val()) :: delete_op()

A shorthand for new("delete", value, attributes). See new/3.

Examples

iex> Op.delete(1, %{"bold" => true})
%{"delete" => 1, "attributes" => %{"bold" => true}}
Link to this function

delete?(op, type \\ nil)

View Source
@spec delete?(op :: t(), type :: any()) :: boolean()

A shorthand for type?(op, "delete", type). See type?/3.

Examples

iex> Op.delete(1) |> Op.delete?()
true
@spec get_embed_data!(map(), map()) :: {any(), any(), any()}

Gets two embeds' data. An embed is always a one-key map

Examples

iex> Op.get_embed_data!(
...>   %{"image" => "https://quilljs.com/assets/images/icon.png"},
...>   %{"image" => "https://quilljs.com/assets/images/icon2.png"}
...> )
{"image", "https://quilljs.com/assets/images/icon.png", "https://quilljs.com/assets/images/icon2.png"}
@spec has_attributes?(any()) :: boolean()

Returns true if operation has attributes

Examples

iex> Op.has_attributes?(%{"insert" => "Hello", "attributes" => %{"bool" => true}})
true

iex> Op.has_attributes?(%{"insert" => "Hello"})
false
Link to this function

insert(value, attr \\ false)

View Source
@spec insert(value :: insert_val(), attr :: attributes_val()) :: insert_op()

A shorthand for new("insert", value, attributes). See new/3.

Examples

iex> Op.insert("Hello", %{"bold" => true})
%{"insert" => "Hello", "attributes" => %{"bold" => true}}
Link to this function

insert?(op, type \\ nil)

View Source
@spec insert?(op :: t(), type :: any()) :: boolean()

A shorthand for type?(op, "insert", type). See type?/3.

Examples

iex> Op.insert("Hello") |> Op.insert?()
true
Link to this function

new(action, value, attr \\ false)

View Source
@spec new(action :: operation(), value :: operation_val(), attr :: attributes_val()) ::
  t()

Create a new operation.

Note that operations are maps, and not structs.

Examples

iex> Op.new("insert", "Hello", %{"bold" => true})
%{"insert" => "Hello", "attributes" => %{"bold" => true}}
Link to this function

retain(value, attr \\ false)

View Source
@spec retain(value :: retain_val(), attr :: attributes_val()) :: retain_op()

A shorthand for new("retain", value, attributes). See new/3.

Examples

iex> Op.retain(1, %{"bold" => true})
%{"retain" => 1, "attributes" => %{"bold" => true}}
Link to this function

retain?(op, type \\ nil)

View Source
@spec retain?(op :: t(), type :: any()) :: boolean()

A shorthand for type?(op, "insert", type). See type?/3.

Examples

iex> Op.retain(1) |> Op.retain?()
true
@spec size(t()) :: non_neg_integer()

Returns operation size.

Examples

iex> Op.insert("Hello") |> Op.size()
5

iex> Op.retain(3) |> Op.size()
3
Link to this function

take(op, length, opts \\ [])

View Source
@spec take(op :: t(), length :: non_neg_integer(), opts :: Keyword.t()) ::
  {t(), t() | boolean()}

Takes length characters from an operation and returns it together with the remaining part in a tuple.

Options

  • :align - when true, allow moving index left if we're likely to split a grapheme otherwise.

Examples

iex> Op.insert("Hello") |> Op.take(3)
{%{"insert" => "Hel"}, %{"insert" => "lo"}}

iex> assert_raise RuntimeError, fn -> Op.insert("🏴󠁧󠁢󠁳󠁣󠁴󠁿") |> Op.take(1) end

iex> Op.insert("🏴󠁧󠁢󠁳󠁣󠁴󠁿") |> Op.take(1, align: true)
{%{"insert" => ""}, %{"insert" => "🏴󠁧󠁢󠁳󠁣󠁴󠁿"}}
@spec text_size(text :: binary()) :: non_neg_integer()

Returns text size.

Examples

iex> Op.text_size("Hello")
5

iex> Op.text_size("🏴󠁧󠁢󠁳󠁣󠁴󠁿")
14
Link to this function

transform(a, b, priority)

View Source
@spec transform(a :: t(), b :: t(), priority :: boolean()) :: {t() | false, t(), t()}
Link to this function

transform(offset, index, op, priority)

View Source
Link to this function

type?(op, action, value_type \\ nil)

View Source
@spec type?(op :: t(), action :: any(), value_type :: any()) :: boolean()

Returns true if operation is of type type. Optionally check against more specific value_type.

Examples

iex> Op.insert("Hello") |> Op.type?("insert")
true

iex> Op.insert("Hello") |> Op.type?("insert", :string)
true

iex> Op.insert("Hello") |> Op.type?("insert", :number)
false

iex> Op.retain(1) |> Op.type?("retain", :number)
true