Skip to content

Commit 2c6a4df

Browse files
committed
new openMarkdown tools
SQUASHED: AUTO-COMMIT-doc-files-changesgraph.md,AUTO-COMMIT-doc-journal-2020-09-01.md-graph-markdown.png,AUTO-COMMIT-doc-journal-2020-09-01.md-graph-tool.png,AUTO-COMMIT-doc-journal-2020-09-01.md-index.md,AUTO-COMMIT-src-client-lively.js,AUTO-COMMIT-src-client-viewnav.js,AUTO-COMMIT-src-components-tools-lively-sync.html,AUTO-COMMIT-src-components-tools-lively-sync.js,AUTO-COMMIT-src-components-widgets-lively-markdown.js,AUTO-COMMIT-src-components-widgets-lively-script.js,
1 parent f1658a8 commit 2c6a4df

File tree

10 files changed

+132
-26
lines changed

10 files changed

+132
-26
lines changed

doc/files/changesgraph.md

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<!-- used as a #Tool by lively-sync -->
2+
13
<div>
24
limit <input id="limit"> url <input style="width:500px" id="url" value=""><br>
35
</div>
@@ -9,6 +11,8 @@ limit <input id="limit"> url <input style="width:500px" id="url" value=""><br>
911
import AnsiColorFilter from "src/external/ansi-to-html.js"
1012
import ViewNav from 'src/client/viewnav.js'
1113

14+
var markdownComp = lively.query(this, "lively-markdown")
15+
1216

1317
class ChangesGraph {
1418

@@ -17,20 +21,36 @@ limit <input id="limit"> url <input style="width:500px" id="url" value=""><br>
1721
element.addEventListener("change", function(evt) {
1822
update(this.value)
1923
})
24+
2025
}
2126

2227
static query(query) {
2328
return lively.query(this.ctx, query)
2429
}
2530

31+
static get url() {
32+
if (!this._url)
33+
this.url = "https://lively-kernel.org/lively4/lively4-jens/src/client/"
34+
return this._url
35+
}
36+
37+
static set url(url) {
38+
this._url = url
39+
this.query("input#url").value = url
40+
}
41+
42+
2643
static async create(ctx) {
44+
2745
this.ctx = ctx
46+
var parameters = markdownComp.parameters
47+
if (parameters.url) {
48+
this.url = parameters.url
49+
}
50+
2851
var dmp = new diff.diff_match_patch();
2952
var baseUrl = lively4url + "/"
30-
// var url = "https://lively-kernel.org/lively4/lively4-jens/src/client/auth-dropbox.js"
31-
var url = "https://lively-kernel.org/lively4/lively4-jens/src/client/"
32-
33-
this.query("input#url").value = url
53+
var url = this.url
3454
var limitElement = this.query("input#limit")
3555

3656
limitElement.value = 200
@@ -43,16 +63,14 @@ limit <input id="limit"> url <input style="width:500px" id="url" value=""><br>
4363

4464

4565
var limit = Number(limitElement.value)
46-
limitElement.addEventListener("change", function(evt) {
47-
limit = Number(this.value)
48-
updateTable() // on Enter
49-
//}
66+
limitElement.addEventListener("change", (evt) => {
67+
limit = Number(limitElement.value)
68+
this.updateTable() // on Enter
5069
});
5170

52-
urlElement.addEventListener("change", function(evt) {
53-
url = this.value
54-
updateTable() // on Enter
55-
//}
71+
urlElement.addEventListener("change", (evt) => {
72+
url = urlElement.value
73+
this.updateTable() // on Enter
5674
});
5775

5876
var data
@@ -124,7 +142,7 @@ limit <input id="limit"> url <input style="width:500px" id="url" value=""><br>
124142
// addEdge(shortCut, path.last)
125143
}
126144

127-
var updateTable = async () => {
145+
this.updateTable = async () => {
128146

129147
details.innerHTML = ""
130148

@@ -198,10 +216,10 @@ limit <input id="limit"> url <input style="width:500px" id="url" value=""><br>
198216
tanglingParents.forEach(ea => {
199217
var path = findConnectingPath(ea)
200218
if (path) {
201-
console.log("FOUND " + path)
219+
// console.log("FOUND " + path)
202220
addShortPath(path)
203221
} else {
204-
console.log("nothing found for" + ea)
222+
// console.log("nothing found for" + ea)
205223
}
206224
})
207225

@@ -262,16 +280,16 @@ limit <input id="limit"> url <input style="width:500px" id="url" value=""><br>
262280
let delta = pos.subPt(panePos)
263281
pane.scrollLeft = delta.x - lively.getExtent(pane).y / 2
264282
pane.scrollTop = delta.y - 100
265-
lively.notify("scroll to: " + delta )
283+
// lively.notify("scroll to: " + delta )
266284

267285
} else {
268-
lively.notify("no pane to scroll into...")
286+
// lively.notify("no pane to scroll into...")
269287
}
270288
})
271289
}
272290

273291
var details = <div id="details"></div>
274-
updateTable()
292+
this.updateTable()
275293

276294
var style = document.createElement("style")
277295
style.textContent = `
@@ -296,8 +314,8 @@ limit <input id="limit"> url <input style="width:500px" id="url" value=""><br>
296314

297315

298316
graphviz.style.display = "inline-block" // so it takes the width of children and not parent
299-
300-
pane = <div id="root" style="z-index: -1; position: absolute; top: 0px; left: 0px; overflow-x: auto; overflow-y: scroll; width: calc(100% - 0px); height: calc(100% - 0px);">
317+
// z-index: -1;
318+
pane = <div id="root" style="position: absolute; top: 20px; left: 0px; overflow-x: auto; overflow-y: scroll; width: calc(100% - 0px); height: calc(100% - 20px);">
301319
{style}
302320
<div style="height: 20px"></div>
303321
<h2>Change Graph</h2>
@@ -328,9 +346,12 @@ limit <input id="limit"> url <input style="width:500px" id="url" value=""><br>
328346
}
329347
}, true)
330348

331-
332349
return pane
333350
}
334351
}
352+
353+
markdownComp.ChangesGraph = ChangesGraph // expose it?
354+
355+
335356
ChangesGraph.create(this)
336357
</script>
279 KB
Loading
260 KB
Loading

doc/journal/2020-09-01.md/index.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## 2020-09-01 #LiveProgrammingLoop
2+
*Author: @JensLincke*
3+
4+
```javascript
5+
var lastWindow;
6+
7+
(async () => {
8+
if (lastWindow) lastWindow.remove(); // #LiveProgrammingLoop
9+
var comp = await lively.openComponentInWindow("lively-markdown")
10+
11+
var src = `# hello
12+
This works:
13+
14+
<script>
15+
import moment from "src/external/moment.js";
16+
17+
18+
moment("1981-06-10").toString()
19+
20+
</script>
21+
`
22+
23+
comp.setContent(src)
24+
lastWindow = comp.parentElement
25+
})()
26+
```
27+
28+
## Turning Wiki-pages into Tools (#PaperIdea)
29+
30+
We used markdown pages to prototype tools and visualizations a lot. But to use it, one had to navigate to that specific page and interact with the tool there. A good and working example of the setup are these journal pages and their index page that allows to create new entries. But markdown pages are not easy to integrate into a workflow with other tools. E.g. using the git graph visualization tool directly from our sync tools is not possible.
31+
32+
![](graph-markdown.png)
33+
34+
With our new `openMarkdown` feature this can now be done.
35+
36+
```javascript
37+
lively.openMarkdown(lively4url + "/doc/files/changesgraph.md",
38+
"Change Graph", {url:"https://lively-kernel.org/lively4/lively4-jens/"})
39+
```
40+
41+
This method opens a markdown page directly into it's own window without using the container/browser. The JavaScript world can interact with the markdown with in two ways:
42+
43+
1. Parameters can be passed (here the `url`) and be read by the scripts inside
44+
2. The `openMarkdown` awaits the execution of all scripts and the resolving of all promised parameters. That way one can wait on active content in the markdown and use it further.
45+
46+
As an example, we added a button to the repository sync tool.
47+
48+
![](graph-tool.png)

src/client/lively.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,18 @@ export default class Lively {
15811581
});
15821582
}
15831583

1584+
static async openMarkdown(url, title="Markdown", parameters={}) {
1585+
var comp = await lively.openComponentInWindow("lively-markdown", undefined, pt(1000,800))
1586+
var src = await fetch(url).then(r => r.text())
1587+
comp.parameters = parameters
1588+
comp.setContent(src)
1589+
comp.parentElement.setAttribute("title", title)
1590+
await comp.evaluated
1591+
1592+
return comp
1593+
}
1594+
1595+
15841596
static get(query) {
15851597
return document.querySelector(query)
15861598
}

src/client/viewnav.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ export default class ViewNav {
6060
if (!evt.ctrlKey || evt.button != 0)
6161
return;
6262

63-
64-
debugger
6563
this.targetContainer = evt.composedPath().find(ea => {
6664
return ea.tagName == "LIVELY-CONTAINER"
6765
})

src/components/tools/lively-sync.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
<button class="repo" id="squashButton">squash</button>
156156
<!-- <button class="repo" id="resolveButton">resolve</button> -->
157157
<button class="repo" id="changelogButton">log</button>
158+
<button class="repo" id="changesgraphButton">graph</button>
158159
<button class="repo" id="npmInstallButton">npm install</button>
159160
<button class="repo" id="npmTestButton">npm test</button>
160161
<!-- <button class="repo" id="resetButton">reset</button> -->

src/components/tools/lively-sync.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ export default class Sync extends Morph {
300300
this.gitControl("graph");
301301
}
302302

303+
onChangesgraphButton() {
304+
lively.openMarkdown(lively4url + "/doc/files/changesgraph.md",
305+
"Change Graph", {url: this.getServerURL() + "/" + this.getRepository() + "/"})
306+
}
307+
303308
onCommitButton() {
304309
// return lively.notify("Commit is not implemented yet")
305310
this.gitControl("commit");

src/components/widgets/lively-markdown.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ import FileIndex from 'src/client/fileindex.js'
3131

3232
export default class LivelyMarkdown extends Morph {
3333
async initialize() {
34+
35+
// all scripts are evaluated
36+
this.evaluated = new Promise(resolve => {
37+
this.resolveEvaluated = resolve
38+
})
3439
this.windowTitle = "LivelyMarkdown";
3540
this.registerButtons();
36-
41+
this.parameters = {}
3742

3843
this.updateView().then(() => {
3944
if (this.getAttribute("mode") == "presentation") {
@@ -172,6 +177,13 @@ export default class LivelyMarkdown extends Morph {
172177

173178
await components.loadUnresolved(root, true, "lively-markdown.js", true);
174179
await persistence.initLivelyObject(root)
180+
181+
// for using markdown content as tools
182+
var allScripts = lively.queryAll(root, "lively-script")
183+
var allPromises = allScripts.map(ea => ea.evaluated)
184+
await Promise.all(allPromises)
185+
// lively.notify("[markdown] scripts evaluated: " + allScripts.length + "promises: " + allPromises)
186+
this.resolveEvaluated()
175187
}
176188

177189
async updateView() {

src/components/widgets/lively-script.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export default class LivelyScript extends Morph {
2424

2525

2626
async initialize() {
27-
27+
this.evaluated = new Promise(resolve => {
28+
this.resolveEvaluated = resolve
29+
})
2830
}
2931

3032

@@ -54,6 +56,13 @@ export default class LivelyScript extends Morph {
5456
} else {
5557
this.get("#result").innerHTML = ""
5658
}
59+
if (this.resolveEvaluated) {
60+
// lively.notify("[script] evaluated " + this)
61+
this.resolveEvaluated()
62+
this.resolveEvaluated = null // don't do it twice...
63+
} else {
64+
console.log("[script] evaluated AGAIN" )
65+
}
5766
}
5867

5968

@@ -104,7 +113,7 @@ export default class LivelyScript extends Morph {
104113
// console.log("wait on last: " + last)
105114
await last
106115
}
107-
console.log("" + this.id + ">>boundEval " + "targetModule: " + targetModule + "\n exec: \"" + str + '"', )
116+
// console.log("" + this.id + ">>boundEval " + "targetModule: " + targetModule + "\n exec: \"" + str + '"', )
108117
var myPromisedResult = boundEval(str, this, targetModule)
109118
myPromisedResult.then(() => {
110119
var first = currentScriptPromises.shift()

0 commit comments

Comments
 (0)