Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support toggling smart cell editor visibility #467

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/kino/js/live/context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ defmodule Kino.JS.Live.Context do
## Options
* `:editor` - note that the smart cell must be initialized with an
editor during on init. Supported options: `:source`, `:intellisense_node`.
editor during init. Supported options: `:source`, `:intellisense_node`,
`:visible`
"""
@spec reconfigure_smart_cell(t(), keyword()) :: t()
Expand Down
5 changes: 5 additions & 0 deletions lib/kino/smart_cell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ defmodule Kino.SmartCell do
This is only applicable when `:language` is Elixir. Defaults to
`nil`
* `:visible` - whether the editor is shown. Altering this option
with `Kino.JS.Live.Context.reconfigure_smart_cell/2` allows the
editor to be shown or hidden, depending on the smart cell state.
Defaults to `true`
Note that you can programmatically reconfigure some of these options
later using `Kino.JS.Live.Context.reconfigure_smart_cell/2`.
Expand Down
8 changes: 5 additions & 3 deletions lib/kino/smart_cell/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ defmodule Kino.SmartCell.Server do
source: editor_opts[:source] || legacy_source,
language: editor_opts[:language],
placement: editor_opts[:placement],
intellisense_node: editor_opts[:intellisense_node]
intellisense_node: editor_opts[:intellisense_node],
visible: editor_opts[:visible]
}
end

Expand Down Expand Up @@ -61,7 +62,7 @@ defmodule Kino.SmartCell.Server do
" Make sure to enable smart cell editor during init"
end

Keyword.validate!(editor_opts, [:source, :intellisense_node])
Keyword.validate!(editor_opts, [:source, :intellisense_node, :visible])
end

put_in(ctx.__private__.smart_cell[:reconfigure_options], opts)
Expand Down Expand Up @@ -138,7 +139,8 @@ defmodule Kino.SmartCell.Server do
language: nil,
intellisense_node: nil,
placement: :bottom,
default_source: ""
default_source: "",
visible: true
])

unless editor_opts[:placement] in [:top, :bottom] do
Expand Down
Loading