Skip to content

Commit

Permalink
Merge branch 'main' into WithIOContext-layer
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Jul 18, 2023
2 parents 0183682 + f6556f9 commit eb13f57
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/Builtins.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### A Pluto.jl notebook ###
# v0.19.18
# v0.19.25

using Markdown
using InteractiveUtils
Expand Down Expand Up @@ -112,7 +112,8 @@ end

# ╔═║ db3aefaa-9539-4c46-ad9b-83763f9ef624
# Like `argmin` in Julia 1.7
argmin_compat(f,xs) = xs[findmin(Iterators.map(f,xs))[2]]
# based on Compat.jl
argmin_compat(f,xs) = mapfoldl(x -> (f(x), x), ((a1,a2),(b1,b2)) -> a1 > b1 ? (b1,b2) : (a1,a2), xs)[2]

# ╔═║ 97fc914b-005f-4b4d-80cb-23016d589609
function closest(values::AbstractVector{<:Real}, x::Real)
Expand Down Expand Up @@ -833,7 +834,7 @@ begin
end

# ╔═║ f21db694-2acb-417d-9f4d-0d2400aa067e
subarrays(x) = (
subarrays(x::Vector) = (
x[collect(I)]
for I in Iterators.product(Iterators.repeated([true,false],length(x))...) |> collect |> vec
)
Expand Down Expand Up @@ -1317,7 +1318,7 @@ begin
Bonds.initial_value(select::MultiSelect{BT,DT}) where {BT,DT} =
ismissing(select.default) ? BT[] : select.default
Bonds.possible_values(select::MultiSelect) =
subarrays((string(i) for i in 1:length(select.options)))
subarrays(map(string, 1:length(select.options)))

function Bonds.transform_value(select::MultiSelect{BT,DT}, val_from_js) where {BT,DT}
# val_from_js will be a vector of Strings, but let's allow Integers as well, there's no harm in that
Expand Down Expand Up @@ -1973,8 +1974,8 @@ export Slider, NumberField, Button, LabelButton, CounterButton, CheckBox, TextFi
# ╠═69a94f6a-420a-4587-bbad-1219a390862d
# ╠═d9522557-07e6-4a51-ae92-3abe7a7d2732
# β•Ÿβ”€cc80b7eb-ca09-41ca-8015-933591378437
# β•Ÿβ”€38a7533e-7b0f-4c55-ade5-5a8d879d14c7
# β•Ÿβ”€f21db694-2acb-417d-9f4d-0d2400aa067e
# ╠═38a7533e-7b0f-4c55-ade5-5a8d879d14c7
# ╠═f21db694-2acb-417d-9f4d-0d2400aa067e
# ╠═4d8ea460-ff2b-4e92-966e-89e76d4806af
# ╠═78473a2f-0a64-4aa5-a60a-94031a4167b8
# ╠═43f86637-9f0b-480c-826a-bbf583e44646
Expand Down
11 changes: 9 additions & 2 deletions src/MultiCheckBox.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### A Pluto.jl notebook ###
# v0.19.12
# v0.19.25

using Markdown
using InteractiveUtils
Expand Down Expand Up @@ -295,7 +295,7 @@ begin
Bonds.initial_value(select::MultiCheckBox{BT,DT}) where {BT,DT} =
ismissing(select.default) ? BT[] : select.default
Bonds.possible_values(select::MultiCheckBox) =
subarrays((string(i) for i in 1:length(select.options)))
subarrays(map(string, 1:length(select.options)))

function Bonds.transform_value(select::MultiCheckBox{BT,DT}, val_from_js) where {BT,DT}
# val_from_js will be a vector of Strings, but let's allow Integers as well, there's no harm in that
Expand Down Expand Up @@ -384,6 +384,12 @@ MultiCheckBox(["🐰 &&\\a \$\$", "🐱" , "🐡", "🐘", "🦝", "🐿️" , "
snacks
╠═║ =#

# ╔═║ 7db1539d-0a36-4446-abdb-d8d7e6aaaee1
# ╠═║ skip_as_script = true
#=╠═║
Bonds.possible_values(MultiCheckBox([1,2,3])) |> collect
╠═║ =#

# ╔═║ Cell order:
# β•Ÿβ”€a8c1e0d2-3604-4e1d-a87c-c8f5b86b79ed
# ╠═8bfaf4c8-557d-433e-a228-aac493746efc
Expand All @@ -404,3 +410,4 @@ snacks
# ╠═b65c67ec-b79f-4f0e-85e6-78ff22b279d4
# ╠═430e2c1a-832f-11eb-024a-13e3989fd7c2
# ╠═c38de38d-e900-4309-a9f6-1392af2f245b
# ╠═7db1539d-0a36-4446-abdb-d8d7e6aaaee1
21 changes: 20 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,26 @@ transform(el, x) = AbstractPlutoDingetjes.Bonds.transform_value(el, x)
@test default(el) |> isempty
@test default(el) isa Vector{Function}
end


expected = Set([
["1", "2", "3"],
["1", "2"],
["1", "3"],
["2", "3"],
["1"],
["2"],
["3"],
[],
])

el = MultiSelect(["🐱", true, "🐡"])
ps = Set(AbstractPlutoDingetjes.Bonds.possible_values(el))
@test ps == expected

el = MultiCheckBox(["🐱", true, "🐡"])
ps = Set(AbstractPlutoDingetjes.Bonds.possible_values(el))
@test ps == expected

el = MultiCheckBox(
["🐱" => "🐝", "🐡" => "🦝", "🐱" => "🐿️"];
default=["🐱", "🐱"]
Expand Down

0 comments on commit eb13f57

Please sign in to comment.