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

Make document currentscript work #1765

Merged
merged 2 commits into from
Feb 2, 2022
Merged

Conversation

dralletje
Copy link
Collaborator

@dralletje dralletje commented Dec 16, 2021

Instead of eval-ing the code from javascript, I now insert a new script element that gets actually executed (so it becomes the document.currentScript). It won't keep currentScript after anything async, but that also doesn't work with normal scripts either, so I think this just raises compatibility a bunch.

Maybe even deprecate naked currentScript in favor of document.currentScript? but I don't care much either way.

Supersedes #1522

@github-actions
Copy link
Contributor

Try this Pull Request!

Open Julia and type:

julia> import Pkg
julia> Pkg.activate(temp=true)
julia> Pkg.add(url="https://github.com/fonsp/Pluto.jl", rev="make-document-currentscript-work")
julia> using Pluto

@fonsp
Copy link
Owner

fonsp commented Dec 20, 2021

Uh oh, I think I wrote some scripts that use currentScript in async stuff

@dralletje
Copy link
Collaborator Author

Yeah so we might first want to deprecate it if we remove it. You can still do let currentScript = window.currentScript.

But this PR doesn't remove currentScript.

@fonsp
Copy link
Owner

fonsp commented Dec 21, 2021

Can you add some comments to the code? It's too difficult :)

Start by copy pasting your PR description into a docstring?

Copy link
Owner

@fonsp fonsp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some comments to the code? It's too difficult :)

Start by copy pasting your PR description into a docstring?

@dralletje dralletje force-pushed the make-document-currentscript-work branch 2 times, most recently from 203e427 to 1c70cfe Compare February 1, 2022 18:35
@dralletje dralletje force-pushed the make-document-currentscript-work branch from 1c70cfe to f7778e8 Compare February 1, 2022 18:36
@dralletje
Copy link
Collaborator Author

@fonsp 😏

@fonsp
Copy link
Owner

fonsp commented Feb 2, 2022

All the crazy things I could come up with still work, awesome!

# ╔═╡ b474a054-846a-11ec-0f51-1b8e8c589aae
using HypertextLiteral

# ╔═╡ 3b09d217-42b9-473c-b98c-bcbbc1c856a4
@htl """
<span>
	<button>click meeee</button>
	<script>
		const span = currentScript.parentElement
		const btn = span.querySelector("button")

		btn.onclick = () => {
			console.log(currentScript, currentScript.parentElement, document.currentScript)
		}
	</script>
</span>


"""

# ╔═╡ 6868ed5d-0ca4-4a1a-be17-e8bde8f0f8ef
zz

# ╔═╡ adbcbc43-c88a-469b-8e8b-49a20706b415
@bind zz @htl """<script>
	let value = 1

	let handler = setInterval(() => {
		value += 1
		currentScript.value = value
		currentScript.dispatchEvent(
			new CustomEvent("input")
		)
	}, 500)

	invalidation.then(() => {
		clearInterval(handler)
	})
	
</script>
"""

@fonsp fonsp merged commit 1704927 into main Feb 2, 2022
@fonsp fonsp deleted the make-document-currentscript-work branch February 2, 2022 21:02
pankgeorg added a commit that referenced this pull request Feb 8, 2022
> Try this release in your browser! _(Available 30 minutes after the release)_
>
> <a href="https://binder.plutojl.org/v0.18.0/"><img alt="Binder logo" src="https://mybinder.org/badge_logo.svg"></a>

**Generate your own binder links using [pluto-on-binder.glitch.me](https://pluto-on-binder.glitch.me/)!**

[Diff since v0.17.7](v0.17.7...v0.18.0)

**Merged pull requests:**
- Make document currentscript work (#1765) (@dralletje)
- don't count logs messages multiple times for pluto-logs width (#1843) (@Pangoraw)
- Pattern matching system for lezer code (#1849) (@dralletje)
- minor fix: Tables integration caused method ambiguation for Union{}[] (#1851) (@16bitmood)
- Fix #1852, relocatable changes for sysimage usage. (#1853) (@MichaelHatherly)
- Re-enable parseMixed (#1855) (@pankgeorg)
- DOI in REAMDE for citation (#1864) (@rikhuijzer)
- Use pkgdir instead of pathof (#1867) (@rikhuijzer)
- Hide banner in CI (#1868) (@rikhuijzer)
- Server-side events as configuration (#1871) (@ctrekker)
- fix is_stdlib() for nightly and enable nightly tests (#1874) (@Pangoraw)
- Awesome! Line wrapping! (#1876) (@dralletje)
- respect maxlog keyword for logs, fixes #1858 (#1877) (@Pangoraw)
- allow .. as an identifier, fixes #1875 (#1878) (@Pangoraw)
- Server start event (#1882) (@ctrekker)
- Julia 1.6 minimum (#1885) (@fonsp)
- New heuristic to skip intermediate bond values (#1892) (@fonsp)
- Send queued bond changes when last script finishes (#1898) (@fonsp)

**Closed issues:**
- Pkg.jl will corrupt itself on Windows (#671)
- Failure creating JuMP DenseAxisArray (#806)
- Frontend tests fail too often (#1234)
- Open multiple notebooks at start and without browser (#1278)
- Segmentation faults on Julia 1.7 M1 (#1722)
- Table of content overlaps text in static HTML (#1770)
- Pluto hangs when cell contains `(md" ", md"$t")` (#1800)
- Cell drag drop broken in Linux Chrome v97 (#1809)
- Tables integration causes method ambiguities for `pluto_showable` (#1815)
- Segfault with CSV, SQLite, tables (M1) (#1842)
- Use RelocatableFolders.jl instead of project_relative_dir to allow sysimages (#1852)
- Logging doesn't respect `maxlog` (#1858)
- TOC in dark mode is still light when aside (#1860)
- ProgressLogging: suppressed logging in Turing.jl (#1862)
- Cannot update to version 0.17.7 (#1869)
- Stdlib packages marked as not found (#1872)
- EllipsisNotation.jl (`randn((10,10))[1, ..]`) does not work (#1875)
- Too many intermediate bond values (#1891)
pankgeorg added a commit that referenced this pull request Feb 8, 2022
> Try this release in your browser! _(Available 30 minutes after the release)_
>
> <a href="https://binder.plutojl.org/v0.18.0/"><img alt="Binder logo" src="https://mybinder.org/badge_logo.svg"></a>

**Generate your own binder links using [pluto-on-binder.glitch.me](https://pluto-on-binder.glitch.me/)!**

[Diff since v0.17.7](v0.17.7...v0.18.0)

**Merged pull requests:**
- Make document currentscript work (#1765) (@dralletje)
- don't count logs messages multiple times for pluto-logs width (#1843) (@Pangoraw)
- Pattern matching system for lezer code (#1849) (@dralletje)
- minor fix: Tables integration caused method ambiguation for Union{}[] (#1851) (@16bitmood)
- Fix #1852, relocatable changes for sysimage usage. (#1853) (@MichaelHatherly)
- Re-enable parseMixed (#1855) (@pankgeorg)
- DOI in REAMDE for citation (#1864) (@rikhuijzer)
- Use pkgdir instead of pathof (#1867) (@rikhuijzer)
- Hide banner in CI (#1868) (@rikhuijzer)
- Server-side events as configuration (#1871) (@ctrekker)
- fix is_stdlib() for nightly and enable nightly tests (#1874) (@Pangoraw)
- Awesome! Line wrapping! (#1876) (@dralletje)
- respect maxlog keyword for logs, fixes #1858 (#1877) (@Pangoraw)
- allow .. as an identifier, fixes #1875 (#1878) (@Pangoraw)
- Server start event (#1882) (@ctrekker)
- Julia 1.6 minimum (#1885) (@fonsp)
- New heuristic to skip intermediate bond values (#1892) (@fonsp)
- Send queued bond changes when last script finishes (#1898) (@fonsp)

**Closed issues:**
- Pkg.jl will corrupt itself on Windows (#671)
- Failure creating JuMP DenseAxisArray (#806)
- Frontend tests fail too often (#1234)
- Open multiple notebooks at start and without browser (#1278)
- Segmentation faults on Julia 1.7 M1 (#1722)
- Table of content overlaps text in static HTML (#1770)
- Pluto hangs when cell contains `(md" ", md"$t")` (#1800)
- Cell drag drop broken in Linux Chrome v97 (#1809)
- Tables integration causes method ambiguities for `pluto_showable` (#1815)
- Segfault with CSV, SQLite, tables (M1) (#1842)
- Use RelocatableFolders.jl instead of project_relative_dir to allow sysimages (#1852)
- Logging doesn't respect `maxlog` (#1858)
- TOC in dark mode is still light when aside (#1860)
- ProgressLogging: suppressed logging in Turing.jl (#1862)
- Cannot update to version 0.17.7 (#1869)
- Stdlib packages marked as not found (#1872)
- EllipsisNotation.jl (`randn((10,10))[1, ..]`) does not work (#1875)
- Too many intermediate bond values (#1891)
@cjdoris
Copy link
Contributor

cjdoris commented Feb 17, 2022

@dralletje Thanks so much for this! Can confirm that PythonCall objects (such as Altair plots) now display correctly in Pluto 0.18.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants