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

[WIP] Enormous rework of (mostly frontend) code. #211

Merged
merged 27 commits into from
Nov 5, 2018
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
de54b5a
Enormous rework of (mostly frontend) code.
twavv Oct 4, 2018
1f8406d
Fix js_str interpolation broken by changing JSON.lower(::JSString) an…
twavv Oct 4, 2018
5205045
Add Blink integration (though broken?).
twavv Oct 5, 2018
5108948
Fix Blink, allow strings to be rendered as children of nodes/scopes.
twavv Oct 5, 2018
64564af
Implement SystemJS resource loading (partially).
twavv Oct 5, 2018
1e1a273
Implement IFrames.
twavv Oct 7, 2018
8768afd
Remove JSExpr from test dependencies.
twavv Oct 7, 2018
16d6f18
Restructure frontend code as monorepo.
twavv Oct 8, 2018
6238632
Fix @js_str macro.
twavv Oct 10, 2018
8a132c9
+Jupyter notebook integration, better (not yet quite working) Interac…
twavv Oct 10, 2018
6c232be
Rename data to schema, allow node extensibility.
twavv Oct 10, 2018
42f8ee4
Add ObservableNode, modify context binding.
twavv Oct 13, 2018
25178d3
Working WebIO! :party:
twavv Oct 14, 2018
03e13bc
Add installation of nbextension to build.
twavv Oct 14, 2018
5e19fdd
Add rel/type/media attributes to link tags when importing CSS.
twavv Oct 14, 2018
366b819
Check in optimized versions of providers.
twavv Oct 14, 2018
d55c8d7
Add interactbulma hack.
twavv Oct 14, 2018
3449c3d
Stability fix in Juptyer, general cleanup.
twavv Oct 15, 2018
bbda73e
Use global scope resolution of observables.
twavv Oct 19, 2018
7cc2d59
Jupyter notebook is stable! :party:
twavv Oct 19, 2018
ea3a590
Delete old WebIO frontend code.
twavv Oct 19, 2018
6bde538
Respect systemjs_options.
twavv Oct 20, 2018
5776c56
Render scopes within observables.
twavv Oct 28, 2018
3ada5c4
Implement observable reconciliation.
twavv Oct 28, 2018
8b5b6de
Stability improvements, render widgets within observables, perform _s…
twavv Nov 1, 2018
c009505
Fix issue with importsLoaded handler.
twavv Nov 4, 2018
557c4a0
Merge upstream into branch.
twavv Nov 4, 2018
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
Prev Previous commit
Next Next commit
Fix js_str interpolation broken by changing JSON.lower(::JSString) an…
…d cleanup some other ugliness.
twavv committed Oct 4, 2018
commit 1f8406d60fec45c8a6ff1548186bb31831ade505
34 changes: 11 additions & 23 deletions src/node.jl
Original file line number Diff line number Diff line change
@@ -93,26 +93,21 @@ function JSON.lower(n::Node)
"type" => "node",
"nodeType" => nodetype(n),
"instanceArgs" => JSON.lower(n.instanceof),
"children" => map!(renderPreferScopeJSON,
"children" => map!(render_internal,
Vector{Any}(undef, length(children(n))),
children(n)),
"props" => props(n),
)
return result
end

## TODO -- optimize
function escapeHTML(i::String)
# Refer to http://stackoverflow.com/a/7382028/3822752 for spec. links
o = replace(i, "&" => "&")
o = replace(o, "\"" => """)
o = replace(o, "'" => "'")
o = replace(o, "<" => "&lt;")
o = replace(o, ">" => "&gt;")
return o
end

function escapeJSONForScriptTag(s::String)
"""
Escape characters for a "safe" representation of JSON.
In particular, we escape '/' characters to avoid the presence of "</" (and
especially "</script>") which cause the browser to break out of the current
<script /> tag.
"""
function escape_json(s::String)
# Replace all "/" with "\/"'s.
# This prevents the browser from interpreting "</" as a close tag; since
# everything within the string is JSON, any appearances of "/" should be
@@ -121,24 +116,17 @@ function escapeJSONForScriptTag(s::String)
return replace(s, "/" => "\\/")
end

escape_json(x::Any) = escape_json(JSON.json(x))

function Base.show(io::IO, m::MIME"text/html", x::Node)
# write(io, "<div class='display:none'></div>" *
# """<unsafe-script style='display:none'>
# WebIO.mount(this.previousSibling,""")
# # NOTE: do NOT add space between </div> and <unsafe-script>
# write(io, sprint(s->jsexpr(s, x)))
# write(io, ")</unsafe-script>")
println("=== Base.show(::IO, text/html, ::Node)")
println("=== Base.show: Node: $x")
jsrepr = jsexpr(x)
println("===jsexpr(Node): $jsrepr")
write(
io,
"""
<div class=\"webio-connected\"><script defer>
WebIO.mount(
document.currentScript.parentElement,
$(escapeJSONForScriptTag(JSON.json(x))),
$(escape_json(x)),
)
</script></div>
"""
13 changes: 5 additions & 8 deletions src/render.jl
Original file line number Diff line number Diff line change
@@ -77,20 +77,17 @@ end
htmlstring(val::AbstractString) = val

# TODO: this is awkward
function renderPreferScopeJSON(child)
println("renderPreferScopeJSON(::Any/$(typeof(child)))")
function render_internal(child)
render(child)
end
function renderPreferScopeJSON(child::Observable)
warn("renderPreferScopeJSON(::$(typeof(child)))")
function render_internal(child::Observable)
# show(STDOUT, "text/plain", stacktrace())
renderPreferScopeJSON(observable_to_scope(child))
render_internal(observable_to_scope(child))
end
function renderPreferScopeJSON(child::Node)
println("renderPreferScopeJSON(::$(typeof(child)))")
function render_internal(child::Node)
return JSON.lower(child)
end
renderPreferScopeJSON(child::Scope) = renderPreferScopeJSON(node(child, child.dom))
render_internal(child::Scope) = render_internal(node(child, child.dom))

function observable_to_scope(obs::Observable)

13 changes: 11 additions & 2 deletions src/syntax.jl
Original file line number Diff line number Diff line change
@@ -75,9 +75,18 @@ function str_interpolate(s, i0 = firstindex(s))
strs
end

"""
Generate a js_str representation for an object.
"""
function js_str_repr end
js_str_repr(io, x::Any) = jsexpr(io, x)
js_str_repr(io, x::String) = print(io, x)
js_str_repr(io, x::JSString) = print(io, x.s)

macro js_str(s)
writes = [x isa String ? :(print(io, $(esc(x)))) : :(jsexpr(io, $(esc(x))))
for x in str_interpolate(s)]
writes = [:(js_str_repr(io, $(esc(x)))) for x in str_interpolate(s)]
# writes = [x isa String ? :(print(io, $(esc(x)))) : :(jsexpr(io, $(esc(x))))
# for x in str_interpolate(s)]

:(JSString(sprint() do io
$(writes...)