Skip to content

Commit 8c53d96

Browse files
committed
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core into gh-pages
2 parents 66a1997 + 63323f9 commit 8c53d96

17 files changed

+554
-138
lines changed

demos/tom/Sections.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ export class TraceSection {
6464
}
6565
}
6666

67+
export class PluginSection extends TraceSection {
68+
constructor(name, nodeID, entries = []) {
69+
super(name, entries);
70+
71+
this.nodeID = nodeID;
72+
}
73+
}
74+
6775
export class FunctionSection extends TraceSection {
6876
constructor() {
6977
super(...arguments);

demos/tom/TraceLogParser.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Event, eventTypes } from 'demos/tom/Events.js';
2-
import { FunctionSection, TraceSection } from 'demos/tom/Sections.js';
2+
import { FunctionSection, PluginSection, TraceSection } from 'demos/tom/Sections.js';
33

44
class EarlyReturn {
55
constructor(type) {
@@ -18,7 +18,7 @@ export default class TraceLogParser {
1818
return this.trace._log;
1919
}
2020

21-
/* Parsing primitives */
21+
/*MD ## Parsing primitives MD*/
2222

2323
peek() {
2424
if(this.index < this.log.length) {
@@ -59,7 +59,7 @@ export default class TraceLogParser {
5959
return object.isEarlyReturn && object.type === type;
6060
}
6161

62-
/* Parse methods */
62+
/*MD ## Parse methods MD*/
6363

6464
instantiateEvent(entry) {
6565
const eventClass = eventTypes[entry.__type__];
@@ -128,7 +128,8 @@ export default class TraceLogParser {
128128

129129
parseTraversePlugin(section, higherSections) {
130130
const entry = this.consume();
131-
const plugin = new TraceSection('TraversePlugin:' + entry.data);
131+
const plugin = new PluginSection('TraversePlugin:' + entry.data[0], entry.data[1]);
132+
plugin.position = this.peek().position;
132133

133134
section.addEntry(plugin);
134135

@@ -179,7 +180,7 @@ export default class TraceLogParser {
179180
}
180181

181182
parsePlugin(sections) {
182-
const plugin = new TraceSection(this.consume().data);
183+
const plugin = new PluginSection(...this.consume().data);
183184
sections.push(plugin);
184185
this.defaultParse(plugin, []);
185186
return plugin;

demos/tom/babel-plugin-tracer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ export default function({ types: t }) {
3737

3838
function modifyFunction(name, path, state) {
3939
const body = path.get('body');
40-
body.unshiftContainer('body', t.expressionStatement(callOnTrace('enterFunction', [location(path.node, state), t
41-
.stringLiteral(name)
42-
])));
40+
body.unshiftContainer('body', t.expressionStatement(callOnTrace('enterFunction', [location(path.node, state), t.stringLiteral(name)])));
4341
body.pushContainer('body', t.expressionStatement(callOnTrace('leave', [location(path.node, state)])));
4442
path.traverse(returnVisitor, state);
4543
}
@@ -101,6 +99,8 @@ export default function({ types: t }) {
10199
name = t.stringLiteral(callee.node.name || 'anonymous function');
102100
}
103101

102+
103+
104104
const loc = location(callee.node, this);
105105

106106
const aboutToEnter = callOnTrace('aboutToEnter',

demos/tom/plugin-backup.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ export default function({ types: t }) {
3737

3838
function modifyFunction(name, path, state) {
3939
const body = path.get('body');
40-
body.unshiftContainer('body', t.expressionStatement(callOnTrace('enterFunction', [location(path.node, state), t
41-
.stringLiteral(name)
42-
])));
40+
body.unshiftContainer('body', t.expressionStatement(callOnTrace('enterFunction', [location(path.node, state), t.stringLiteral(name)])));
4341
body.pushContainer('body', t.expressionStatement(callOnTrace('leave', [location(path.node, state)])));
4442
path.traverse(returnVisitor, state);
4543
}
@@ -88,7 +86,6 @@ export default function({ types: t }) {
8886
path.node.alreadyVisited = true;
8987
let callee = path.get('callee');
9088
let name;
91-
debugger
9289

9390
if (t.isMemberExpression(callee)) {
9491
if(callee.node.computed) {

demos/tom/plugin-explorer-worker.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,36 @@ function decorateNodePathTraverse(plugin, trace) {
7676
for (const name in visitors) {
7777
if (typeof visitors[name] === 'function') {
7878
const fn = visitors[name];
79-
newVisitors[name] = function() {
80-
trace.startTraversePlugin(name);
81-
fn(...arguments);
79+
newVisitors[name] = function(path, ...rest) {
80+
trace.startTraversePlugin(name, path.node.traceID);
81+
fn(path, ...rest);
8282
trace.endTraversePlugin(name);
8383
};
8484
} else if (typeof visitors[name] === 'object') {
85-
debugger
85+
const obj = visitors[name];
86+
87+
// Todo: what is if already decorated
88+
if(obj.enter) {
89+
obj.enter = obj.enter.map(fn => function(path, ...rest) {
90+
trace.startTraversePlugin(name, path.node.traceID);
91+
fn(path, ...rest);
92+
trace.endTraversePlugin(name);
93+
})
94+
}
95+
96+
if(obj.exit) {
97+
obj.exit = obj.exit.map(fn => function(path, ...rest) {
98+
trace.startTraversePlugin(name, path.node.traceID);
99+
fn(path, ...rest);
100+
trace.endTraversePlugin(name);
101+
})
102+
}
103+
104+
newVisitors[name] = obj;
86105
}
87106

88107
}
89108

90-
visitors = newVisitors;
91109
oldTraverse.call(this, newVisitors, ...rest);
92110

93111
}
@@ -116,8 +134,8 @@ async function importPlugin(url) {
116134
return modifiedPlugin;
117135
}
118136

119-
function importPlugins(urls) {
120-
return Promise.all(urls.map(url => importPlugin(url)))
137+
function importPlugins(pluginData) {
138+
return Promise.all(pluginData.map(({url, data}) => importPlugin(url)))
121139
.then(plugins => {
122140
let counter = 0;
123141
for (const plugin of plugins) {
@@ -162,16 +180,16 @@ self.onmessage = function(msg) {
162180
return trace.createTraceID();
163181
}
164182

165-
importPlugins(msg.data.urls)
183+
importPlugins(msg.data.pluginData)
166184
.then(function(modules) {
167185
config.plugins = modules;
168186
config.sourceFileName = 'tmpfile.js';
169187
config.sourceMaps = true;
170188

171189
config.wrapPluginVisitorMethod = (pluginAlias, visitorType, callback) => {
172-
return (...args) => {
173-
trace.enterPlugin(pluginAlias);
174-
callback(...args);
190+
return (path, ...rest) => {
191+
trace.enterPlugin(pluginAlias, path.node.traceID);
192+
callback(path, ...rest);
175193
trace.leavePlugin(pluginAlias);
176194
}
177195
};

demos/tom/plugin-load-promise.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default function(source, urls) {
1+
export default function(source, pluginData) {
22
return new Promise((resolve, reject) => {
33
const worker = new Worker('demos/tom/plugin-explorer-worker.js')
44
worker.onmessage = function(msg) {
@@ -9,6 +9,6 @@ export default function(source, urls) {
99
reject(msg);
1010
worker.terminate();
1111
}
12-
worker.postMessage({source, urls})
12+
worker.postMessage({source, pluginData})
1313
})
1414
}

demos/tom/trace.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export default class Trace {
6767
return trace;
6868
}
6969

70-
static async on(source, pluginsUrls) {
71-
const data = await loadPlugin(source, pluginsUrls);
70+
static async on(source, pluginData) {
71+
const data = await loadPlugin(source, pluginData);
7272
const obj = {
7373
locations: data.locations,
7474
oldAST: JSON.parse(data.oldAST),
@@ -140,17 +140,17 @@ export default class Trace {
140140

141141
/*MD ## Plugins MD*/
142142

143-
enterPlugin(name) {
144-
this.log(new Event('enterPlugin', name));
143+
enterPlugin(name, traceID) {
144+
this.log(new Event('enterPlugin', [name, traceID]));
145145
this.pluginRound++;
146146
}
147147

148148
leavePlugin(name) {
149149
this.log(new Event('leavePlugin', name));
150150
}
151151

152-
startTraversePlugin(name) {
153-
this.log(new Event('enterTraversePlugin', name));
152+
startTraversePlugin(name, traceID) {
153+
this.log(new Event('enterTraversePlugin', [name, traceID]));
154154
}
155155

156156
endTraversePlugin(name) {

src/components/tools/file-chooser.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import Morph from 'src/components/widgets/lively-morph.js';
44
import Bindings from "src/client/bindings.js"
55
import {promisedEvent} from "src/client/utils.js"
6+
import ContextMenu from 'src/client/contextmenu.js';
67

78

89
/*MD # File Chooser
@@ -19,7 +20,20 @@ export default class FileChooser extends Morph {
1920
this.registerButtons()
2021

2122
lively.html.registerKeys(this); // automatically installs handler for some methods
22-
this.updateView()
23+
this.updateView();
24+
this.get('#navbar').onContextMenu = evt => this.onContextMenu(evt);
25+
}
26+
27+
// Please overwrite for your use case
28+
getMenuElements() {
29+
return [];
30+
}
31+
32+
onContextMenu(evt) {
33+
const menuElements = this.getMenuElements();
34+
35+
const menu = new ContextMenu(this, menuElements)
36+
menu.openIn(document.body, evt, this)
2337
}
2438

2539
async updateView() {

src/components/tools/lively-container-navbar.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,9 @@ export default class LivelyContainerNavbar extends Morph {
725725
menuElements.push(...[
726726
["new", [
727727
[`directory`, () => this.newDirectory( basePath+ "newdirectory/")],
728-
[`text file`, () => this.newFile(basePath + "newdfile", "md")],
729-
["drawio figure", () => this.newFile(basePath + "newdfile", "drawio")],
728+
[`markdown file`, () => this.newFile(basePath + "newfile", "md")],
729+
[`source file`, () => this.newFile(basePath + "newfile", "js")],
730+
["drawio figure", () => this.newFile(basePath + "newfile", "drawio")],
730731
], "", ''],
731732
])
732733
const menu = new ContextMenu(this, menuElements)
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
{"source":"/src/components/tools/lively-ast-explorer-example-source.js","plugin":"https://lively-kernel.org/lively4/lively4-tom/demos/tom/playground.js","options":{"autoUpdateAST":true,"autoUpdateTransformation":true,"autoExecute":true,"systemJS":false,"autoRunTests":false,"autoSaveWorkspace":false},"pluginSelection":[{"url":"https://lively-kernel.org/lively4/lively4-tom/demos/tom/playground.js"}]}
1+
{
2+
"source": "https://lively-kernel.org/lively4/lively4-tom/src/components/tools/lively-ast-explorer-example-source.js",
3+
"sources": [
4+
"https://lively-kernel.org/lively4/lively4-tom/src/components/tools/lively-ast-explorer-example-source.js"
5+
],
6+
"plugin": "src/client/reactive/babel-plugin-active-expression-rewriting/index.js",
7+
"options": {
8+
"autoUpdateAST": true,
9+
"autoUpdateTransformation": true,
10+
"autoExecute": true,
11+
"systemJS": false,
12+
"autoRunTests": false,
13+
"autoSaveWorkspace": false
14+
},
15+
"pluginSelection": [
16+
{
17+
"url": "demos/tom/plugin-backup.js"
18+
},
19+
{
20+
"url": "src/client/reactive/babel-plugin-active-expression-rewriting/index.js"
21+
}
22+
]
23+
}

0 commit comments

Comments
 (0)