Skip to content

Commit 7f609b5

Browse files
authored
Merge pull request #42 from disberd/small_fixes
2 parents e786e41 + 7b54176 commit 7f609b5

18 files changed

Lines changed: 426 additions & 685 deletions

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
This file contains the changelog for the PlutoExtras package. It follows the [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) format.
44

5+
## [0.7.16] - 2025-09-26
6+
7+
### Fixed
8+
- Fixed problems with `ExtendedTableOfContents` with recent PlutoUI versions, also resolving an issue with `hide-heading` icon not appearing next to the corresponding heading in the ToC.
9+
- Fixed styling issue with `BondsTable` in #19
10+
11+
### Added
12+
- Added possibility of providing any valid object with a `MIME"text/html"` representation as description of the `@NTBond` macro.
13+
- Added the possibility of simplifying application of `PlutoUI.Experimental.transformed_value` to the fields of an `@NTBond` using the `@tv` decorator (see the example notebook for details).
14+
15+
### Changed
16+
- Changed the hiding behavior of the `Popout` container so that it stays displayed if the mouse is hovering over its contents even if not popped out
17+
18+
519
## [0.7.15] - 2025-04-22
620
Changelog was introduced in this version. Only changes w.r.t. version v0.7.14 are listed
721

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
PlutoExtras = "ed5d0301-4775-4676-b788-cf71e66ff8ed"
44

55
[compat]
6-
Documenter = "0.27"
6+
Documenter = "1"

docs/make.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ using Documenter
55
DocMeta.setdocmeta!(PlutoExtras, :DocTestSetup, :(using PlutoExtras); recursive=true)
66

77
makedocs(;
8-
modules= Module[],
8+
modules= [PlutoExtras],
99
authors="Alberto Mengali <disberd@gmail.com>",
10-
repo="https://github.com/disberd/PlutoExtras.jl/blob/{commit}{path}#{line}",
10+
repo=Remotes.GitHub("disberd", "PlutoExtras.jl"),
1111
sitename="PlutoExtras.jl",
1212
format=Documenter.HTML(;
1313
prettyurls=get(ENV, "CI", "false") == "true",
1414
edit_link="master",
1515
assets=String[],
1616
),
17+
warnonly = true,
1718
pages=[
1819
"index.md",
1920
"basic_widgets.md",

docs/src/structbond.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The StructBondModule submodule of PlutoExtras defines and exports functionality
55
!!! note
66
The StructBondModule is currently not re-exported by PlutoExtras so it has to be explicitly used with `using PlutoExtras.StructBondModule`
77

8-
Open the [structbond test notebook static html](https://rawcdn.githack.com/disberd/PlutoExtras.jl/0e3153d29d3b112f93507c042a35b8161a3bb661/html_exports/test_bondstable.jl.html) to see the look of the widgets exported.\
8+
Open the [structbond module notebook static html](https://raw.githack.com/disberd/PlutoExtras.jl/assets/html/structbondmodule.html) to see the look of the widgets exported.\
99
Or open the [related notebook](https://github.com/disberd/PlutoExtras.jl/blob/master/test/notebooks/structbondmodule.jl) directy in Pluto to check their functionality in action!
1010
!!! note
1111
The notebook must be run from the original folder (`test/notebooks`) within the `PlutoExtras` package folder to properly load the PlutoExtras package
@@ -37,6 +37,49 @@ The macro simply create a [`StructBond`](@ref) wrapping the desired NamedTuple t
3737
</video>
3838
```
3939

40+
### Transforming the resulting NamedTuple
41+
Since version v0.7.16, it is possible to `PlutoUI.Experimental.transformed_value` to transform the resulting value of the NamedTuple return by the `@NTBond` macro by either providing a third argument to the macro (acting on the full `NamedTuple`) or by using the `@tv` decorator directly when defining the bond for a specific field:
42+
43+
#### Transforming the full NamedTuple
44+
45+
When calling the macro with a third argument, this is interpreted as a function that is used to create a bond transformation using `PlutoUI.Experimental.transformed_value`.
46+
47+
This means that the two expressions below yield the same result:
48+
```julia
49+
@NTBond "WoW" begin
50+
a = ("Description", Slider(1:10))
51+
end x -> x.a + 2
52+
```
53+
and
54+
```julia
55+
PlutoUI.Experimental.transformed_value(x -> x.a + 2, @NTBond "WoW" begin
56+
a = ("Description", Slider(1:10))
57+
end)
58+
```
59+
60+
!!! note
61+
The synthax accepting a function to transformed the resulting NamedTuple also has a convenience shorthand where `_` can be used to represent the original bond value.
62+
63+
The above example could then also be written as:
64+
```julia
65+
@NTBond "WoW" begin
66+
a = ("Description", Slider(1:10))
67+
end _.a + 2
68+
```
69+
70+
#### Transforming a single field
71+
72+
For the use directly at field level, it is sufficient to use the `@tv` decorator in place of the bond widget directly, using the following form and as shown in the image below:
73+
```julia
74+
@tv transform_function widget
75+
```
76+
77+
![@tv decorator](https://raw.githubusercontent.com/disberd/PlutoExtras.jl/assets/imgs/ntbond_transform_fieldbond.png)
78+
79+
!!! note
80+
The `@tv` decorator is not a macro actually defined within PlutoExtras, but is directly parsed during the macro expansion of `@NTBond`.
81+
82+
4083
## StructBondSelect
4184
Sometimes, one wants to create a more complex binding where the number of parameters to control a bond can vary depending on some other variable. The `StructBondSelect` can be of help in some of these cases, by providing a way to select out of a number of arbitrary `StructBonds` (which include `@NTBond`) by using a dropdown to select the one to be displayed and used for generating the `StructBondSelect` widget's output.
4285

@@ -52,7 +95,7 @@ The `description` kwarg can be used to customize the text in the widget containe
5295

5396
```@raw html
5497
<video controls=true>
55-
<source src="https://private-user-images.githubusercontent.com/12846528/435671114-795c3da9-ede1-4f96-a971-038a8ce506c3.mp4?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDUyNDA0ODgsIm5iZiI6MTc0NTI0MDE4OCwicGF0aCI6Ii8xMjg0NjUyOC80MzU2NzExMTQtNzk1YzNkYTktZWRlMS00Zjk2LWE5NzEtMDM4YThjZTUwNmMzLm1wND9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA0MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNDIxVDEyNTYyOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdmMWZmYjJhNTIyNGI5NDFmMDk3ODcxZWU2ZTE3Njk1MGYyZDk2MmQ5ZTI1NzEyNzJlZTZkNjUxMDhkNDI4ODYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.XXQ6NJLqc1MoBVQXY9MNageij2F0DhsEzvQpHSP9F4A" type="video/mp4">
98+
<source src="https://raw.githubusercontent.com/disberd/PlutoExtras.jl/assets/videos/structbond_select_example.mp4" type="video/mp4">
5699
</video>
57100
```
58101

@@ -117,6 +160,7 @@ StructBondModule.@NTBond
117160
StructBondModule.@BondsList
118161
StructBondModule.popoutwrap
119162
StructBondModule.BondTable
163+
StructBondModule.StructBondSelect
120164
```
121165

122166
### Secondary/Advanced

html_exports/test_bondstable.jl.html

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/extended_toc.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function propagate_state(div, state) {
178178
}
179179

180180
// Floating UI functionality
181-
const floating_ui = await import('https://esm.sh/@floating-ui/dom')
181+
const floating_ui = await import('https://esm.sh/@floating-ui/dom@1.7.4')
182182

183183
// Cell attributes modification
184184
function has_cell_attribute(cell_id, attr) {
@@ -374,15 +374,8 @@ function repositionTooltip(e) {
374374
computePosition(ref, tooltip, {
375375
placement: "left",
376376
strategy: "fixed",
377-
middleware: [
378-
offset({
379-
mainAxis: 0, // No offset along the main axis (left/right)
380-
crossAxis: -scrollTop, // Compensate for vertical scroll
381-
alignmentAxis: 0 // No alignment offset
382-
})
383-
]
384377
}).then(pos => {
385-
tooltip.style.top = pos.y + "px"
378+
tooltip.style.top = pos.y - scrollTop + "px"
386379
})
387380
}
388381

@@ -725,7 +718,7 @@ header.addEventListener('click', e => {
725718
})
726719

727720
header.addEventListener('mouseenter', (e) => {
728-
const { computePosition, offset } = floating_ui
721+
const { computePosition } = floating_ui
729722

730723
// Get the scroll container - this is crucial for proper offset calculation
731724
const scrollContainer = document.querySelector('main') || document.documentElement
@@ -734,15 +727,8 @@ header.addEventListener('mouseenter', (e) => {
734727
computePosition(header, header_container, {
735728
placement: "left",
736729
strategy: "fixed",
737-
middleware: [
738-
offset({
739-
mainAxis: 0, // No offset along the main axis (left/right)
740-
crossAxis: -scrollTop, // Compensate for vertical scroll
741-
alignmentAxis: 0 // No alignment offset
742-
})
743-
]
744730
}).then(pos => {
745-
header_container.style.top = pos.y + "px"
731+
header_container.style.top = pos.y - scrollTop + "px"
746732
// header_container.style.left = pos.x + "px"
747733
// header_container.style.right = `calc(1rem + min(80vw, 300px))`
748734
})

src/structbond/basics.jl

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ function typehtml(T::Type)
129129
])
130130
"""
131131
end
132-
togglereactive_container(inner_bond; description = typedescription(T), title = "This generates a struct of type $(nameof(T))")
132+
collapsible_togglereactive_container(inner_bond; description_html = typedescription(T), title = "This generates a struct of type $(nameof(T))")
133133
end
134134

135135
## ToggleReactiveContainer ##
136136
# This is a helperfunction to create a togglereactive container around a bond with collapsible content
137-
function togglereactive_container(inner_bond; description, title, classes = String[])
137+
function collapsible_togglereactive_container(inner_bond; description = "", description_html, title, classes = String[])
138138
ToggleReactiveBond(wrapped() do Child
139139
@htl("""
140140
$(Child(inner_bond))
@@ -144,71 +144,9 @@ function togglereactive_container(inner_bond; description, title, classes = Stri
144144
const header = trc.firstElementChild
145145
const desc = header.querySelector('.description')
146146
desc.setAttribute('title', $title)
147-
148-
// add the collapse button
149-
const collapse_btn = html`<span class='collapse'>`
150-
header.insertAdjacentElement('afterbegin', collapse_btn)
151-
152-
trc.collapse = () => {
153-
trc.classList.toggle('collapsed')
154-
}
155-
156-
collapse_btn.onclick = (e) => trc.collapse()
157-
158147
</script>
159-
<style>
160-
togglereactive-container field-html {
161-
display: contents;
162-
}
163-
togglereactive-container {
164-
display: grid;
165-
grid-template-columns: 1fr minmax(min(50px, 100%), .4fr);
166-
grid-auto-rows: fit-content(40px);
167-
justify-items: center;
168-
align-items: center;
169-
row-gap: 5px;
170-
/* The flex below is needed in some weird cases where the bond is display flex and the child becomes small. */
171-
flex: 1;
172-
}
173-
togglereactive-header {
174-
grid-column: 1 / -1;
175-
display: flex;
176-
}
177-
togglereactive-header > .collapse {
178-
--size: 17px;
179-
display: block;
180-
align-self: stretch;
181-
background-size: var(--size) var(--size);
182-
background-repeat: no-repeat;
183-
background-position: center;
184-
width: var(--size);
185-
filter: var(--image-filters);
186-
background-image: url(https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.5.1/src/svg/chevron-down.svg);
187-
cursor: pointer;
188-
}
189-
togglereactive-container.collapsed > togglereactive-header > .collapse {
190-
background-image: url(https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.5.1/src/svg/chevron-forward.svg);
191-
}
192-
togglereactive-header {
193-
display: flex;
194-
align-items: stretch;
195-
width: 100%;
196-
}
197-
togglereactive-header > .description {
198-
text-align: center;
199-
flex-grow: 1;
200-
font-size: 18px;
201-
font-weight: 600;
202-
}
203-
togglereactive-header > .toggle {
204-
align-self: center
205-
}
206-
togglereactive-container.collapsed togglereactive-header + * {
207-
display: none !important;
208-
}
209-
</style>
210148
""")
211-
end; description, classes)
149+
end; description, description_html, classes = String["collapsible", classes...])
212150
end
213151

214152
### Constructor ###

src/structbond/css/bondslist.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,6 @@ bondslist-container {
8686
align-items: center;
8787
row-gap: 5px;
8888
}
89-
bondstable-container bondslist-container {
89+
bondtable-container bondslist-container {
9090
display: contents;
9191
}

src/structbond/css/popout.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ popout-contents {
1313
padding: 8px;
1414
}
1515
popout-container.popped > popout-contents,
16+
popout-container.contents-hover > popout-contents,
1617
popout-container.header-hover > popout-contents {
1718
display: block;
1819
position: fixed;

src/structbond/css/structbondselect.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ structbond-select > struct-bond.hidden {
88

99
structbond-select,
1010
structbond-select > struct-bond,
11-
structbond-select togglereactive-container {
11+
structbond-select togglereactive-container.collapsible {
1212
display: contents;
1313
}
1414

@@ -20,7 +20,7 @@ structbond-select > .selector .description {
2020
color: var(--pluto-output-color, #404040);
2121
}
2222

23-
structbond-select >struct-bond>togglereactive-container>togglereactive-header {
23+
structbond-select >struct-bond>togglereactive-container.collapsible>togglereactive-header {
2424
display: none;
2525
}
2626

0 commit comments

Comments
 (0)