Added command palette, go event

This commit is contained in:
Logan Allen 2019-03-12 17:47:57 -07:00 committed by Isaac Visintainer
parent 813249b199
commit 8eac489504
13 changed files with 240 additions and 33 deletions

View File

@ -1,9 +1,9 @@
/- *modulo
/+ *server
/= test-page
/= index
/^ octs
/; as-octs:mimes:html
/: /===/app/modulo/index /&html&/!hymn/
/: /===/app/modulo/index /html/
/= modulo-js
/^ octs
/; as-octs:mimes:html
@ -35,6 +35,21 @@
==
==
::
++ session-as-json
|= [cur=(unit [term @]) session=(map term @t) order=(list term)]
^- json
?~ cur
*json
%- pairs:enjs
:~ [%app %s -.u.cur]
[%url %s (~(got by session) -.u.cur)]
:- %list
:- %a
%+ turn order
|= [a=term]
[%s a]
==
::
--
::
|_ [bow=bowl:gall sta=state]
@ -56,17 +71,13 @@
::
++ bound
|= [wir=wire success=? binding=binding:http-server]
~& [%bound success]
[~ this]
::
++ session-as-json
^- json
?~ cur.sta
*json
%- pairs:enjs
:~ [%app %s -.u.cur.sta]
[%url %s (~(got by session.sta) u.cur.sta)]
==
++ peer-applist
|= [pax=path]
^- (quip move _this)
:_ this
[ost.bow %diff %json (session-as-json cur.sta session.sta order.sta)]~
::
++ session-js
^- octs
@ -76,9 +87,17 @@
%- crip
;: weld
(trip 'window.onload = function() {')
"window.ship = '{(trip (rsh 3 1 (crip <our.bow>)))}';"
" window.state = "
(en-json:html session-as-json)
(en-json:html (session-as-json cur.sta session.sta order.sta))
(trip '}();')
%- trip
'''
document.onkeydown = (event) => {
if (!event.metaKey || event.keyCode !== 75) { return; }
window.parent.postMessage("commandPalette", "*");
};
'''
==
:: +poke-handle-http-request: received on a new connection established
::
@ -88,7 +107,6 @@
^- (quip move _this)
::
=+ request-line=(parse-request-line url.request.inbound-request)
~& [%request-line request-line]
=/ name=@t
=+ back-path=(flop site.request-line)
?~ back-path
@ -116,7 +134,7 @@
:~ ^- move
:- ost.bow
:* %http-response
[%start [200 ['content-type' 'text/html']~] [~ test-page] %.y]
[%start [200 ['content-type' 'text/html']~] [~ index] %.y]
==
==
:: +poke-handle-http-cancel: received when a connection was killed
@ -132,7 +150,6 @@
|= bin=term
^- (quip move _this)
=/ url (crip "~{(scow %tas bin)}")
~& [%poke-mod-bind bin]
?: (~(has by session.sta) bin)
[~ this]
:- [`move`[ost.bow %connect / [~ /[url]] bin] ~]
@ -142,12 +159,15 @@
::
order.sta
(weld order.sta ~[bin])
::
cur.sta
?~ cur.sta `[bin 0]
cur.sta
==
::
++ poke-modulo-unbind
|= bin=term
^- (quip move _this)
~& [%poke-mod-unbind bin]
=/ url (crip "~{(scow %tas bin)}")
?. (~(has by session.sta) bin)
[~ this]
@ -171,7 +191,6 @@
++ poke-modulo-command
|= com=command
^- (quip move _this)
~& [%poke-mod-com com]
=/ length (lent order.sta)
?~ cur.sta
[~ this]
@ -180,20 +199,25 @@
=/ new-cur=(unit [term @])
?- -.com
%forward
?: =(length +.u.cur.sta)
?: =((dec length) +.u.cur.sta)
`[(snag 0 order.sta) 0]
=/ ind +(-.u.cur.sta)
=/ ind +(+.u.cur.sta)
`[(snag ind order.sta) ind]
%back
?: =(0 +.u.cur.sta)
=/ ind (dec length)
`[(snag ind order.sta) ind]
=/ ind (dec -.u.cur.sta)
=/ ind (dec +.u.cur.sta)
`[(snag ind order.sta) ind]
%go
=/ ind (find [app.com]~ order.sta)
?~ ind
cur.sta
`[app.com u.ind]
==
:_ this(cur.sta new-cur)
%+ turn (prey:pubsub:userlib /sessions bow)
%+ turn (prey:pubsub:userlib /applist bow)
|= [=bone ^]
[bone %diff %json session-as-json]
[bone %diff %json (session-as-json new-cur session.sta order.sta)]
::
--

28
app/modulo/index.html Normal file
View File

@ -0,0 +1,28 @@
<!doctype html>
<html>
<head>
<script type="application/javascript" src="/~modulo/session.js"></script>
<script type="application/javascript" src="~/channel/channel.js"></script>
<style type="text/css">
.command-palette {
position: relative;
background-color: #f6f6f6;
top:10%;
left:10%;
width: 80%;
border: none;
outline: none;
height: 48px;
font-size: 20px;
line-height: 48px;
}
</style>
</head>
<body>
<div id="frame"></div>
<div id="popup" style="display:hidden;">
<input id="input" class="command-palette" type="text" style="visibility:hidden !important;" />
</div>
<script type="application/javascript" src="/~modulo/script.js"></script>
</body>
</html>

View File

@ -1,6 +1,56 @@
let iframe = document.createElement('iframe');
iframe.setAttribute('src', window.state.url);
iframe.setAttribute('width', '100%;');
iframe.setAttribute('height', '100%;');
iframe.setAttribute('style', 'border-style: none !important;');
document.body.appendChild(iframe);
function setFrame() {
let iframe = document.createElement('iframe');
iframe.setAttribute('src', window.state.url);
iframe.setAttribute('width', '100%;');
iframe.setAttribute('height', '100%;');
iframe.setAttribute('style', 'border-style: none !important;');
let inner = document.getElementById("frame");
inner.innerHTML = "";
inner.appendChild(iframe);
iframe.focus();
}
function doSub() {
window.urb.subscribe(window.ship, "modulo", "/applist",
(err) => {
console.log(err);
},
(event) => {
console.log(event);
window.state = event;
setFrame();
},
() => {
doSub();
}
);
}
window.addEventListener("message", (event) => {
let popup = document.getElementById("popup");
let input = document.getElementById("input");
popup.style = "position:absolute; left: 0; top: 0; display:block; width: 100%; height: 100%; margin: 0 0; background-color:white;";
input.style = "";
input.addEventListener("keyup", (e) => {
if (e.keyCode !== 13) { return; }
window.urb.poke(window.ship, "modulo", "modulo-command",
{
go: input.value
},
(json) => {
console.log(json);
},
(err) => {
console.log(err);
}
);
});
});
setFrame();
doSub();

View File

@ -2,7 +2,12 @@
/= index
/^ octs
/; as-octs:mimes:html
/: /===/app/subapp/index /&html&/!hymn/
/: /===/app/subapp/index /html/
/= script
/^ octs
/; as-octs:mimes:html
/: /===/app/subapp/script /js/
::
|%
:: +move: output effect
@ -45,6 +50,21 @@
%- (require-authorization ost.bol move this)
|= =inbound-request:http-server
^- (quip move _this)
=+ request-line=(parse-request-line url.request.inbound-request)
=/ name=@t
=+ back-path=(flop site.request-line)
?~ back-path
'World'
i.back-path
::
?: =(name 'script')
:_ this
:~ ^- move
:- ost.bol
:* %http-response
[%start [200 ['content-type' 'application/javascript']~] [~ script] %.y]
==
==
:_ this
:~ ^- move
:- ost.bol

11
app/subapp/index.html Normal file
View File

@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<script type="application/javascript" src="~/channel/channel.js"></script>
<script type="application/javascript" src="/~modulo/session.js"></script>
<script type="application/javascript" src="/~subapp/script.js"></script>
</head>
<body>
<p>Jimmy</p>
</body>
</html>

1
app/subapp/script.js Normal file
View File

@ -0,0 +1 @@
console.log("subapp");

View File

@ -2,7 +2,12 @@
/= index
/^ octs
/; as-octs:mimes:html
/: /===/app/subapp1/index /&html&/!hymn/
/: /===/app/subapp1/index /html/
/= script
/^ octs
/; as-octs:mimes:html
/: /===/app/subapp1/script /js/
::
|%
:: +move: output effect
@ -45,6 +50,21 @@
%- (require-authorization ost.bol move this)
|= =inbound-request:http-server
^- (quip move _this)
=+ request-line=(parse-request-line url.request.inbound-request)
=/ name=@t
=+ back-path=(flop site.request-line)
?~ back-path
'World'
i.back-path
::
?: =(name 'script')
:_ this
:~ ^- move
:- ost.bol
:* %http-response
[%start [200 ['content-type' 'application/javascript']~] [~ script] %.y]
==
==
:_ this
:~ ^- move
:- ost.bol

11
app/subapp1/index.html Normal file
View File

@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<script type="application/javascript" src="~/channel/channel.js"></script>
<script type="application/javascript" src="/~modulo/session.js"></script>
<script type="application/javascript" src="/~subapp1/script.js"></script>
</head>
<body>
<p>Is Great</p>
</body>
</html>

1
app/subapp1/script.js Normal file
View File

@ -0,0 +1 @@
console.log("subapp1");

35
lib/http.hoon Normal file
View File

@ -0,0 +1,35 @@
::
:::: /hoon/http/lib
::
::
::
/? 310
::
=, mimes:html
=, html
|%
++ request
$: domain/(list cord)
end-point/path
req-type/$?($get {$post p/json})
headers/math:eyre
queries/quay:eyre
==
++ send
|= {ost/bone pour-path/wire params/request}
:^ ost %them pour-path
`(unit hiss:eyre)`[~ (request-to-hiss params)]
::
++ request-to-hiss
|= request ^- hiss:eyre
=- ~& hiss=- -
:- ^- parsed-url/purl:eyre
:+ :+ security=%.y
port=~
host=[%.y [path=domain]]
endpoint=[extensions=~ point=end-point] :: ++pork,
q-strings=queries :: ++quay
?@ req-type
[%get headers ~]
[%post headers ~ (as-octt:mimes:html (en-json p.req-type))]
--

View File

@ -1,7 +1,14 @@
/- *modulo
=, format
|_ com=command
++ grab
|%
++ noun command
++ json
%- of:dejs
:~ forward+ul:dejs
back+ul:dejs
go+(su:dejs sym)
==
--
--

View File

@ -2,5 +2,6 @@
+$ command
$% [%forward ~]
[%back ~]
[%go app=term]
==
--

View File

@ -627,9 +627,7 @@
}
};
export function newChannel() {
return new Channel;
}
window.urb = new Channel();
'''
:: +format-ud-as-integer: prints a number for consumption outside urbit
::