mirror of
https://github.com/status-im/pluto.git
synced 2025-02-25 08:55:24 +00:00
246 lines
7.3 KiB
HTML
246 lines
7.3 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/codemirror@5.40.2/lib/codemirror.css">
|
|
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
|
|
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
|
|
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/codemirror@5.40.2/lib/codemirror.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/codemirror@5.40.2/mode/clojure/clojure.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/parinfer@3.12.0/parinfer.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/parinfer-codemirror@1.4.2/parinfer-codemirror.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js"></script>
|
|
<script src="https://cdn.rawgit.com/neocotic/qrious/master/dist/qrious.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
const ipfs = new window.Ipfs();
|
|
|
|
async function load(hash) {
|
|
const buffer = await loadIPFS(ipfs, hash);
|
|
return buffer.toString();
|
|
}
|
|
|
|
ipfs.once("ready", async () => {
|
|
let params = (new URL(document.location)).searchParams;
|
|
let hash = params.get("hash") || "QmYoa8CBcYmzm6Kd1NbPNLYQtbwMpwR7YBiywaAyST5gtH";
|
|
const content = await load(hash);
|
|
codeMirror.setValue(content);
|
|
history.replaceState({hash: hash}, null, document.location.href.split('?')[0] + "?hash=" + hash);
|
|
});
|
|
|
|
function extensionLink(hash) {
|
|
return "https://get.status.im/extension/ipfs@" + hash;
|
|
}
|
|
|
|
async function loadIPFS(ipfs, hash) {
|
|
return ipfs.files.cat(hash);
|
|
}
|
|
|
|
async function publish() {
|
|
const content = codeMirror.getValue();
|
|
const filesAdded = await uploadIPFS(ipfs, content);
|
|
const hash = filesAdded[0].hash;
|
|
history.pushState({hash: hash}, null, document.location.href.split('?')[0] + "?hash=" + hash);
|
|
displayQR(extensionLink(hash));
|
|
}
|
|
|
|
function clearErrors() {
|
|
const elErrors = document.getElementById("errors");
|
|
elErrors.innerHTML = '';
|
|
elErrors.className = "";
|
|
}
|
|
|
|
function displayErrors(errors) {
|
|
const elErrors = document.getElementById("errors");
|
|
if (errors == null) {
|
|
elErrors.innerHTML = '<div>No errors</div>';
|
|
elErrors.classList.add("ok");
|
|
} else {
|
|
elErrors.classList.add("errors");
|
|
|
|
let names = errors.map( (error, i) => {
|
|
return [error.type, error.value]
|
|
})
|
|
var s = '<div>Errors</div><ul>';
|
|
names.forEach(function(element) {
|
|
s = s.concat("<li>" + element[0]);
|
|
if (element[1] != null) {
|
|
s = s.concat(":" + JSON.stringify(element[1]));
|
|
}
|
|
s = s.concat("</li>");
|
|
});
|
|
s = s.concat("</ul>")
|
|
elErrors.innerHTML = s;
|
|
}
|
|
}
|
|
|
|
function uploadIPFS(ipfs, s) {
|
|
return ipfs.files.add({path: 'extension.edn',
|
|
content: ipfs.types.Buffer.from(s, 'utf8')})
|
|
}
|
|
|
|
function clearQR() {
|
|
const qel = document.getElementById("qr-wrapper");
|
|
qel.innerHTML = '';
|
|
}
|
|
|
|
function displayQR(s) {
|
|
const qel = document.getElementById("qr-wrapper");
|
|
qel.innerHTML = '<canvas id="qr"></canvas><a href="' + s + '">Universal link</a>';
|
|
new QRious({
|
|
element: document.getElementById('qr'),
|
|
value: s,
|
|
size: 250
|
|
});
|
|
}
|
|
</script>
|
|
<div id="wrapper">
|
|
<main>
|
|
<div id="content"></div>
|
|
<div id="errors"></div>
|
|
</main>
|
|
<aside id="side-column">
|
|
<div id="panel">
|
|
<p>A playground to experiment with extensions and easily publish them on IPFS. Go ahead, modify the default extension on the left side!</p>
|
|
<p>Find more details about building your own extension in this <a href="https://docs.status.im/docs/extensions_tutorial_chat_command.html">tutorial</a></p>
|
|
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" onclick="publish()">Publish</button>
|
|
<div id="qr-wrapper"></div>
|
|
</div>
|
|
<div id="docs">
|
|
<h6>Components</h6>
|
|
<ul>
|
|
<li><code>view</code></li>
|
|
<li><code>text</code></li>
|
|
<li>
|
|
<code>touchable-opacity</code>
|
|
<pre class="inline-args">{:on-press Event}</pre>
|
|
</li>
|
|
<li>
|
|
<code>image</code>
|
|
<pre class="inline-args">{:uri String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>input</code>
|
|
<pre>{:on-change Event
|
|
:placeholder String}</pre></li>
|
|
<li>
|
|
<code>button</code>
|
|
<pre class="inline-args">{:on-click Event}</pre></li>
|
|
<li>
|
|
<code>link</code>
|
|
<pre class="inline-args">{:uri String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>checkbox</code>
|
|
<pre class="inline-args">{:uri String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>checkbox</code>
|
|
<pre class="inline-args">{:on-change Event :checked Bool}</pre>
|
|
</li>
|
|
<li>
|
|
<code>nft-token-viewer</code>
|
|
<pre class="inline-args">{:token String}</pre>
|
|
</li>
|
|
<li><code>transaction-status</code>
|
|
<pre class="inline-args">{:outgoing String :tx-hash String}</pre></li>
|
|
<li><code>asset-selector</code></li>
|
|
<li><code>token-selector</code></li>
|
|
</ul>
|
|
<h6>Queries</h6>
|
|
<ul>
|
|
<li>
|
|
<code>store/get</code>
|
|
<pre class="inline-args">{:key String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>wallet/collectibles</code>
|
|
<pre class="inline-args">{:token String :symbol String}</pre>
|
|
</li>
|
|
</ul>
|
|
<h6>Events</h6>
|
|
<ul>
|
|
<li>
|
|
<code>alert</code>
|
|
<pre class="inline-args">{:value String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>log</code>
|
|
<pre class="inline-args">{:value String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>store/put</code>
|
|
<pre class="inline-args">{:key String :value String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>store/append</code>
|
|
<pre class="inline-args">{:key String :value String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>store/clear</code>
|
|
<pre class="inline-args">{:key String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>http/get</code>
|
|
<pre>{:url String
|
|
:timeout? String
|
|
:on-success Event
|
|
:on-failure? Event}</pre>
|
|
</li>
|
|
<li>
|
|
<code>http/post</code>
|
|
<pre>{:url String
|
|
:body String
|
|
:timeout? String
|
|
:on-success Event
|
|
:on-failure? Event}</pre>
|
|
</li>
|
|
<li>
|
|
<code>ipfs/cat</code>
|
|
<pre>{:hash String
|
|
:on-success Event
|
|
:on-failure? Event}</pre>
|
|
</li>
|
|
<li>
|
|
<code>ethereum/send-transaction</code>
|
|
<pre>{:to String
|
|
:gas? String
|
|
:gas-price? String
|
|
:value? String
|
|
:method? String
|
|
:params? Vector
|
|
:nonce? String
|
|
:on-result? Event}</pre>
|
|
</li>
|
|
<li>
|
|
<code>ethereum/call</code>
|
|
<pre>{:to String
|
|
:method String
|
|
:params? Vector
|
|
:on-result? Event}</pre>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</aside>
|
|
</div>
|
|
<script>
|
|
const codeMirror = CodeMirror(document.getElementById("content"));
|
|
codeMirror.setValue("Loading content ...");
|
|
codeMirror.on("change", function(c, change) {
|
|
clearErrors();
|
|
clearQR();
|
|
const read = pluto.reader.read(codeMirror.getValue());
|
|
const readJS = pluto.js.from_clj(read);
|
|
displayErrors(readJS.errors);
|
|
if (readJS.errors == null) {
|
|
const parsed = pluto.js.parse(read);
|
|
const parsedJS = pluto.js.from_clj(parsed);
|
|
displayErrors(parsedJS.errors);
|
|
}
|
|
});
|
|
parinferCodeMirror.init(codeMirror);
|
|
</script>
|
|
</body>
|
|
</html>
|