mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-06 04:54:29 +08:00
Handle missing debounce only from old output (#2261)
This commit is contained in:
parent
f0ca13c88a
commit
1bb0005f20
3 changed files with 28 additions and 29 deletions
|
@ -2889,34 +2889,22 @@ defmodule Livebook.Session do
|
|||
# attributes that are missing.
|
||||
defp normalize_runtime_output(output)
|
||||
|
||||
defp normalize_runtime_output(%{type: :input, attrs: attrs} = output)
|
||||
when attrs.type in [:text, :textarea, :password, :number, :url, :range, :color] and
|
||||
not is_map_key(attrs, :debounce) do
|
||||
default =
|
||||
case attrs.type do
|
||||
:range -> 250
|
||||
_other -> :blur
|
||||
end
|
||||
|
||||
put_in(output.attrs[:debounce], default)
|
||||
|> normalize_runtime_output()
|
||||
end
|
||||
|
||||
# Traverse composite outputs
|
||||
|
||||
defp normalize_runtime_output(output) when output.type in [:frame, :tabs, :grid] do
|
||||
outputs = Enum.map(output.outputs, &normalize_runtime_output/1)
|
||||
%{output | outputs: outputs}
|
||||
end
|
||||
# defp normalize_runtime_output(output) when output.type in [:frame, :tabs, :grid] do
|
||||
# outputs = Enum.map(output.outputs, &normalize_runtime_output/1)
|
||||
# %{output | outputs: outputs}
|
||||
# end
|
||||
|
||||
defp normalize_runtime_output(%{type: :frame_update} = output) do
|
||||
{update_type, new_outputs} = output.update
|
||||
new_outputs = Enum.map(new_outputs, &normalize_runtime_output/1)
|
||||
%{output | update: {update_type, new_outputs}}
|
||||
end
|
||||
# defp normalize_runtime_output(%{type: :frame_update} = output) do
|
||||
# {update_type, new_outputs} = output.update
|
||||
# new_outputs = Enum.map(new_outputs, &normalize_runtime_output/1)
|
||||
# %{output | update: {update_type, new_outputs}}
|
||||
# end
|
||||
|
||||
defp normalize_runtime_output(output) when is_map(output), do: output
|
||||
|
||||
# TODO: Remove this when Kino v0.10.0 is a long time in the past.
|
||||
# Rewrite tuples to maps for backward compatibility with Kino <= 0.10.0
|
||||
|
||||
defp normalize_runtime_output(:ignored) do
|
||||
|
@ -3000,12 +2988,23 @@ defmodule Livebook.Session do
|
|||
end
|
||||
|
||||
defp normalize_runtime_output({:input, attrs}) do
|
||||
{fields, attrs} = Map.split(attrs, [:ref, :id, :destination])
|
||||
{fields, %{type: type} = attrs} = Map.split(attrs, [:ref, :id, :destination])
|
||||
|
||||
attrs =
|
||||
case attrs.type do
|
||||
:textarea -> Map.put_new(attrs, :monospace, false)
|
||||
_other -> attrs
|
||||
cond do
|
||||
type in [:textarea] ->
|
||||
attrs
|
||||
|> Map.put_new(:monospace, false)
|
||||
|> Map.put_new(:debounce, :blur)
|
||||
|
||||
type in [:text, :password, :number, :url, :color] ->
|
||||
Map.put_new(attrs, :debounce, :blur)
|
||||
|
||||
type in [:range] ->
|
||||
Map.put_new(attrs, :debounce, 250)
|
||||
|
||||
true ->
|
||||
attrs
|
||||
end
|
||||
|
||||
Map.merge(fields, %{type: :input, attrs: attrs})
|
||||
|
|
|
@ -189,7 +189,7 @@ defmodule LivebookWeb.AppSessionLiveTest do
|
|||
ref: "ref1",
|
||||
id: "input1",
|
||||
destination: test,
|
||||
attrs: %{type: :number, default: 1, label: "Name"}
|
||||
attrs: %{type: :number, default: 1, label: "Name", debounce: :blur}
|
||||
}
|
||||
|
||||
notebook = %{
|
||||
|
|
|
@ -490,7 +490,7 @@ defmodule LivebookWeb.SessionLiveTest do
|
|||
ref: "ref1",
|
||||
id: "input1",
|
||||
destination: test,
|
||||
attrs: %{type: :number, default: 1, label: "Name"}
|
||||
attrs: %{type: :number, default: 1, label: "Name", debounce: :blur}
|
||||
}
|
||||
|
||||
Session.subscribe(session.id)
|
||||
|
@ -746,7 +746,7 @@ defmodule LivebookWeb.SessionLiveTest do
|
|||
ref: "ref1",
|
||||
id: "input1",
|
||||
destination: test,
|
||||
attrs: %{type: :number, default: 1, label: "Name"}
|
||||
attrs: %{type: :number, default: 1, label: "Name", debounce: :blur}
|
||||
}
|
||||
|
||||
Session.subscribe(session.id)
|
||||
|
|
Loading…
Add table
Reference in a new issue