Skip to content

Commit 41b8ef2

Browse files
committed
knot copz viewer
SQUASHED: AUTO-COMMIT-src-client-reactive-babel-plugin-polymorphic-identifiers-playground.js,AUTO-COMMIT-templates-knot-copy-viewer.html,AUTO-COMMIT-templates-knot-copy-viewer.js,
1 parent a63044e commit 41b8ef2

File tree

3 files changed

+120
-1
lines changed

3 files changed

+120
-1
lines changed
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
here we go....
1+
'pi'
2+
import { PIScheme } from 'polymorphic-identifiers';
3+
class fourtyTwo extends PIScheme {
4+
read() {
5+
return 42;
6+
}
7+
}
8+
9+
fourtyTwo``

templates/knot-copy-viewer.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<template id="knot-copy-viewer" >
2+
<style data-src="/src/external/font-awesome/css/font-awesome.css"></style>
3+
<style data-src="/templates/livelystyle.css"></style>
4+
<style>
5+
:host {
6+
7+
}
8+
#content,#editor{
9+
height: 50%;
10+
}
11+
#content {
12+
background-color: lightgray;
13+
overflow-y: scroll;
14+
}
15+
li:hover {
16+
background-color: green;
17+
}
18+
li:focus, li:focus-within{
19+
background-color: red;
20+
border: 3px solid red;
21+
}
22+
</style>
23+
<button id="plusButton">plus</button>
24+
<button id="minusButton">minus</button>
25+
<div id="content">
26+
<slot id="list"></slot>
27+
</div>
28+
<lively-code-mirror id="editor" wrapmode="true"></lively-code-mirror>
29+
</template>
30+

templates/knot-copy-viewer.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
"enable aexpr";
2+
3+
import Morph from 'src/components/widgets/lively-morph.js';
4+
import loadDropbox, { Graph } from 'src/client/triples/triples.js';
5+
import MultiSelection from 'src/client/vivide/multiselection.js';
6+
import {copyTextToClipboard} from 'utils';
7+
8+
export default class KnotCopyViewer extends Morph {
9+
get multiSelection() {
10+
return this._multiSelection = this._multiSelection ||
11+
new MultiSelection(this);
12+
}
13+
14+
async initialize() {
15+
this.windowTitle = "KnotCopyViewer";
16+
this.registerButtons()
17+
18+
lively.html.registerKeys(this); // automatically installs handler for some methods
19+
20+
21+
22+
await this.loadGraph()
23+
}
24+
25+
get list(){
26+
return this.get("#list")
27+
}
28+
29+
async loadGraph() {
30+
let graph = await Graph.getInstance();
31+
32+
graph.knots
33+
.filter(knot => knot.url.endsWith("md")&&!knot.label().startsWith("Research-Diary"))
34+
.forEach((knot, index) => {
35+
let listItem = <li tabindex="0"></li>;
36+
listItem.innerHTML = knot.label();
37+
listItem.setAttribute("tabindex", "0");
38+
listItem.addEventListener("focus", async () => {
39+
this.showKnot(knot, listItem);
40+
});
41+
listItem.addEventListener("keydown", async () => {
42+
lively.notify('fooo')
43+
});
44+
this.appendChild(listItem);
45+
});
46+
}
47+
48+
showKnot(knot, item){
49+
this.knot=knot;
50+
this.item=item;
51+
let editorComp = this.get('#editor');
52+
editorComp.value = knot.content;
53+
copyTextToClipboard(`${knot.content}
54+
55+
`)
56+
lively.notify(knot.label())
57+
}
58+
59+
// this method is autmatically registered through the ``registerKeys`` method
60+
onKeyDown(evt) {
61+
lively.notify("Key Down!" + evt.charCode)
62+
}
63+
64+
// this method is automatically registered as handler through ``registerButtons``
65+
onPlusButton() {
66+
this.get("#textField").value = parseFloat(this.get("#textField").value) + 1
67+
}
68+
69+
onMinusButton() {
70+
this.get("#textField").value = parseFloat(this.get("#textField").value) - 1
71+
}
72+
73+
/* Lively-specific API */
74+
75+
76+
livelyMigrate(other) {
77+
// whenever a component is replaced with a newer version during development
78+
// this method is called on the new object during migration, but before initialization
79+
//this.someJavaScriptProperty = other.someJavaScriptProperty
80+
}
81+
}

0 commit comments

Comments
 (0)