View Source Delta.Op (Delta v0.4.1)
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()
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()}
Functions
@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}}
A shorthand for type?(op, "delete", type)
. See type?/3
.
Examples
iex> Op.delete(1) |> Op.delete?()
true
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"}
Returns true if operation has attributes
Examples
iex> Op.has_attributes?(%{"insert" => "Hello", "attributes" => %{"bool" => true}})
true
iex> Op.has_attributes?(%{"insert" => "Hello"})
false
@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}}
A shorthand for type?(op, "insert", type)
. See type?/3
.
Examples
iex> Op.insert("Hello") |> Op.insert?()
true
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}}
@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}}
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
Takes length
characters from an operation and returns it together with the
remaining part in a tuple.
Options
:align
- whentrue
, 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
@spec transform(non_neg_integer(), non_neg_integer(), t(), boolean()) :: {non_neg_integer(), non_neg_integer()}
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