add quilljs, create channel for syncing documents

This commit is contained in:
2023-11-24 19:07:52 -05:00
parent 7de2bad456
commit 52a7a64d23
35 changed files with 1092 additions and 250 deletions

View File

@@ -0,0 +1,19 @@
defmodule Poex.Utils.DeltaUtils do
alias Delta.Op
def convert_ops(map) do
ops = Map.get(map, "ops") || []
Enum.map(ops, fn op ->
type = Map.keys(op) |> List.first()
value = Map.get(op, type)
attrs = Map.get(op, "attributes")
case type do
"insert" -> Op.insert(value, attrs)
"delete" -> Op.delete(value)
"retain" -> Op.retain(value, attrs)
end
end)
end
end

View File

@@ -0,0 +1,18 @@
defmodule Poex.Utils do
def atomize_keys(%{__struct__: _} = map), do: map
def atomize_keys(map) when is_map(map),
do:
Map.new(map, fn {k, v} ->
{
atomize_key(k),
atomize_keys(v)
}
end)
def atomize_keys(list) when is_list(list), do: Enum.map(list, &atomize_keys(&1))
def atomize_keys(map), do: map
defp atomize_key(key) when is_bitstring(key), do: String.to_atom(key)
defp atomize_key(key), do: key
end