Skip to content

Commit 2571a84

Browse files
committed
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core into gh-pages
2 parents 68d673a + 72fccee commit 2571a84

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

demos/markdown/mle-workspaces.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Workspace Example
2+
3+
This is an Example of a workspace embedded in HTML/Markdown that will persist it's code in browser local storage.
4+
<lively-script><script>import focalStorage from 'src/external/focalStorage.js'; import {SocketSingleton} from 'src/components/mle/socket.js'; const idMap = new Map(); const enclosingDiv = <div />; var mle = {}; async function startUp(){ await SocketSingleton.get(); let i = 0; while(await focalStorage.getItem(`markdown_workspace_${i}`)){ await new Pane(i, await focalStorage.getItem(`markdown_workspace_${i}_kind`)).create(); i++; } } class Pane { constructor(id, kind){ if(id !== undefined){ this._id = id; this.kind = kind; } else { this._id = idMap.size; } idMap.set(this.textStorageId, this); } onDoIt() { this.saveText() this.workspace.tryBoundEval(this.workspace.value) } async onReset() { if(this.kind) this.socket = await SocketSingleton.reset(); this.logarea.value = "LOGS"; this.drawarea.innerHTML = ""; } get defaultText() { return "sql`SELECT * FROM students`" } get textStorageId() { return `markdown_workspace_${this._id}` } async loadText() { var loaded = await focalStorage.getItem(this.textStorageId); if (loaded) return loaded; return this.defaultText; } async saveText() { focalStorage.setItem(this.textStorageId, this.workspace.value); focalStorage.setItem(`${this.textStorageId}_kind`, this.kind); } log(s) { this.logarea.value += s + ""; } async create() { // #TODO #META style and pre tags are problematic in Markdown scripts this.kind = this.kind === undefined ? await lively.confirm("MLE Workspace? Ok for yes, Cancel for No.") : this.kind; var style = document.createElement("style"); style.textContent = ` lively-code-mirror { border: 1px solid gray; flex: 4; }`; var buttons = <div> <button click={() => {this.onDoIt()} }>DoIt</button> <button click={() => {this.onReset()} }>reset</button> </div>; this.workspace = await (<lively-code-mirror></lively-code-mirror>); this.workspace.value = await this.loadText(); this.workspace.doitContext = this; this.logarea = <textarea disabled style="flex: 2;"/>; this.logarea.value = "LOGS"; this.drawarea = <div></div>; if(this.kind){ this.workspace.boundEval = async function(s) { this.socket = this.socket || await SocketSingleton.get(); this.socket.emit("test", {id: this.textStorageId, func: "evaluate", parameters: [s]}); const value = await new Promise((res) => { this.socket.on("result", r => { if(!r) return; if(r.id !== this.textStorageId) return; console.log(r.data) res(JSON.parse(r.data)); }); }); this.outData = value; Object.defineProperty(window, `$${this._id}`, {configurable: true, value}); this.log(JSON.stringify(value)); this.saveText(); return {value}; } this.workspace.boundEval = this.workspace.boundEval.bind(this); } enclosingDiv.appendChild( <div style="padding: 10px; width:90%;"> {style} <h4>{this.kind ? "MLE" : "DOM"} Workspace ${this._id}</h4> {buttons} <div style="display: flex;"> {this.workspace} {this.logarea} </div> {this.drawarea} </div> ); } } startUp().then(t => <div> <button click={() => new Pane().create()}>New workspace</button> {enclosingDiv} </div>)</script> </lively-script>

src/client/vivide/scripts/scripts/vivide-script-future-week.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/components/mle/socket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const SocketSingleton = (function() {
99
socket = SocketIO(addr);
1010
// TODO make input
1111
socket.emit('options', {
12-
connectString: '132.145.55.192:1521/MLEEDITOR',
12+
connectString: '127.0.0.1:1521/MLEEDITOR',
1313
user: 'system',
1414
password: 'MY_PASSWORD_123'
1515
});

src/components/widgets/lively-mle-code-editor.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export default class LivelyMleCodeEditor extends Morph {
1313
onDeployButton() {
1414
this.loading = true;
1515
const editor = this.shadowRoot.getElementById("code");
16-
this.socket.emit('save', {
17-
file: editor.getValue()
16+
this._socket.emit('save', {
17+
file: editor.value
1818
});
1919
}
2020

@@ -25,24 +25,24 @@ export default class LivelyMleCodeEditor extends Morph {
2525
}
2626

2727
set socket(v){
28-
this.socket = v;
28+
this._socket = v;
2929
this.loading = true;
30-
this.socket.emit('read');
31-
this.socket.on('failure', m => {
30+
this._socket.emit('read');
31+
this._socket.on('failure', m => {
3232
this.loading = false;
3333
this.shadowRoot.getElementById("result").innerHTML = m;
3434
this.shadowRoot.getElementById("result").className = "notification is-danger";
3535
});
36-
this.socket.on('busy', m => {
36+
this._socket.on('busy', m => {
3737
this.loading = false;
3838
});
39-
this.socket.on('result', (r, status) => {
39+
this._socket.on('result', (r, status) => {
4040
if(status === "read"){
4141
this.loading = false;
4242
this.shadowRoot.getElementById("code").value = r;
4343
}
4444
if (status === "saved") {
45-
this.socket.emit('deploy', {
45+
this._socket.emit('deploy', {
4646
connectionString: '132.145.55.192:1521/MLEEDITOR',
4747
user: 'system',
4848
password: 'MY_PASSWORD_123'

0 commit comments

Comments
 (0)