Skip to content

Commit

Permalink
Merge pull request #9 from JerryI/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JerryI authored Sep 15, 2024
2 parents 206d58b + b2a3362 commit 990017d
Show file tree
Hide file tree
Showing 46 changed files with 20,776 additions and 69,717 deletions.
Binary file modified .DS_Store
Binary file not shown.
37,649 changes: 2,612 additions & 35,037 deletions dist/kernel.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kernel.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions github-pages/boxes.372a011a.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions github-pages/boxes.372a011a.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion github-pages/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!DOCTYPE html><html><head><title>Playground for testing</title><link rel="stylesheet" href="https://jerryi.github.io/wljs-editor/styles.4e25ce1f.css"><script type="module" src="https://cdn.jsdelivr.net/gh/JerryI/wljs-interpreter@dev/src/interpreter.js"></script><script type="module" src="https://cdn.jsdelivr.net/gh/JerryI/wljs-interpreter@dev/src/core.js"></script><script type="module" src="https://cdn.jsdelivr.net/gh/JerryI/wljs-cells@dev/src/module.js"></script><script type="module" src="https://jerryi.github.io/wljs-editor/kernel.da81e14c.js"></script></head><body style="padding:5rem"> <script type="module">
<!DOCTYPE html><html><head><title>Playground for testing</title><link rel="stylesheet" href="https://jerryi.github.io/wljs-editor/styles.4e25ce1f.css"><script type="module" src="https://cdn.jsdelivr.net/gh/JerryI/wljs-interpreter@dev/src/interpreter.js"></script><script type="module" src="https://cdn.jsdelivr.net/gh/JerryI/wljs-interpreter@dev/src/core.js"></script><script type="module" src="https://cdn.jsdelivr.net/gh/JerryI/wljs-cells@dev/src/module.js"></script><script type="module" src="https://jerryi.github.io/wljs-editor/kernel.9bea77a7.js"></script><script type="module" src="https://jerryi.github.io/wljs-editor/boxes.372a011a.js"></script></head><body style="padding:5rem"> <script type="module">
new window.SupportedCells['codemirror'].view({element: document.body, save:()=>{}}, `n = (*SqB[*)Sqrt[1 - (*FB[*)(((*SpB[*)Power[(*SbB[*)Subscript[\\[Omega](*|*),(*|*)p](*]SbB*)(*|*),(*|*)2](*]SpB*))(*,*)/(*,*)((*SpB[*)Power[((*SbB[*)Subscript[\\[Omega](*|*),(*|*)0](*]SbB*) - \\[Omega])(*|*),(*|*)2](*]SpB*) - I \\[Gamma] \\[Omega]))(*]FB*) ](*]SqB*) `)
</script> </body></html>
21 changes: 21 additions & 0 deletions github-pages/kernel.9bea77a7.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions github-pages/kernel.9bea77a7.js.map

Large diffs are not rendered by default.

Binary file added libs/.DS_Store
Binary file not shown.
Binary file added libs/priceless-mathematica/src/.DS_Store
Binary file not shown.
26 changes: 25 additions & 1 deletion libs/priceless-mathematica/src/boxes/boxbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ export function BoxBoxWidget(viewEditor) {
class EditorWidget {

constructor(visibleValue, view, span, ref) {
return this._construct(visibleValue, view, span, ref);
}

_construct(visibleValue, view, span, ref) {
this.view = view;
this.span = span;
this.visibleValue = visibleValue;

this.args = matchArguments(visibleValue.str, /\(\*,\*\)/gm);
Expand Down Expand Up @@ -106,6 +111,7 @@ class EditorWidget {
}
};
const aa = document.createElement('span');
this.aa;
aa.onkeydown = function(e) {
// User hits enter key and is not holding shift
if (e.keyCode === 13) {
Expand Down Expand Up @@ -183,16 +189,34 @@ class EditorWidget {
const data = '('+this.prolog.string+update+this.epilog.string+')';
const changes = {from: relative + args[0].from, to: relative + args[0].from + args[0].length, insert: data};

//update imprint
this.visibleValue.str = this.visibleValue.str.substring(0, args[0].from).concat(data, this.visibleValue.str.substring(args[0].from + args[0].length));

const delta = data.length - args[0].length
args[0].length = data.length;
this.visibleValue.length = this.visibleValue.length + delta;


this.view.dispatch({changes: changes});
}

update(visibleValue) {
//console.log('Update instance: new ranges & arguments');

if (this.visibleValue.str != visibleValue.str) {
console.warn('Out of sync');
console.log('recreating InstanceWidget');

this.destroy();

//HARD RESET
this.span.replaceChildren();

this._construct(visibleValue, this.view, this.span);


return;
}

this.visibleValue.pos = visibleValue.pos;
this.visibleValue.argsPos = visibleValue.argsPos;
}
Expand Down
115 changes: 115 additions & 0 deletions libs/priceless-mathematica/src/boxes/fractionbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ class EditorWidget {
const data = '(('+update+')';
const changes = {from: relative + args[0].from, to: relative + args[0].from + args[0].length, insert: data};

//update an imprint
this.visibleValue.str = this.visibleValue.str.substring(0, args[0].from).concat(data, this.visibleValue.str.substring(args[0].from + args[0].length));

//shift other positions
const delta = data.length - args[0].length;

Expand All @@ -239,6 +242,9 @@ class EditorWidget {
const data = '('+update+'))';

const changes = {from: relative + args[2].from, to: relative + args[2].from + args[2].length, insert: data};
//update an imprint
this.visibleValue.str = this.visibleValue.str.substring(0, args[2].from).concat(data, this.visibleValue.str.substring(args[2].from + args[2].length));


//shift other positions
const delta = (data.length - args[2].length);
Expand All @@ -257,6 +263,115 @@ class EditorWidget {

update(visibleValue, placeholder) {
//console.log('Update instance: new ranges & arguments');

if (this.visibleValue.str != visibleValue.str) {
console.warn('Out of sync');
const self = this;
const view = this.view;
this.visibleValue = visibleValue;

//rematch all
this.args = matchArguments(visibleValue.str, /\(\*,\*\)/gm);

//console.log(visibleValue);

console.log('recreating InstanceWidget');

let topState, bottomState;

topState = compactCMEditor.state({
doc: self.args[0].body.slice(2,-1),
update: (upd) => self.applyChanges(upd, 0),
eval: () => {
view.viewState.state.config.eval();
},
extensions: [
keymap.of([
{ key: "ArrowLeft", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to) {
//const range = self.placeholder.placeholder.placeholder;
console.log(self.visibleValue.pos);
//if (self.visibleValue.pos == 0) return;

view.dispatch({selection: {anchor: self.visibleValue.pos}});
view.focus();
editor.editorLastCursor = undefined;
return;
} else {
editor.editorLastCursor = editor.state.selection.ranges[0].to;
}

} },
{ key: "ArrowRight", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to) {
self.bottomEditor.dispatch({selection: {anchor: 0}});
self.bottomEditor.focus();
editor.editorLastCursor = undefined;
return;
}
editor.editorLastCursor = editor.state.selection.ranges[0].to;
} },
{ key: "ArrowDown", run: function (editor, key) {
self.bottomEditor.focus();
editor.editorLastCursor = undefined;
} }
])
]
});

bottomState = compactCMEditor.state({
doc: self.args[2].body.slice(1,-2),

update: (upd) => self.applyChanges(upd, 2),
eval: () => {
self.view.viewState.state.config.eval();
},
extensions: [
keymap.of([
{ key: "ArrowLeft", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to) {
//const range = self.placeholder.placeholder.placeholder;
self.topEditor.dispatch({selection: {anchor: self.topEditor.state.doc.length}});
self.topEditor.focus();
editor.editorLastCursor = undefined;
return;
} else {
editor.editorLastCursor = editor.state.selection.ranges[0].to;
}

} },
{ key: "ArrowRight", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to) {

view.dispatch({selection: {anchor: self.visibleValue.pos + self.visibleValue.length}});
view.focus();


editor.editorLastCursor = undefined;
return;
}
editor.editorLastCursor = editor.state.selection.ranges[0].to;
} },
{ key: "ArrowUp", run: function (editor, key) {
self.topEditor.focus();
editor.editorLastCursor = undefined;
} }
])
]
});

this.topEditor.setState(topState);
this.bottomEditor.setState(bottomState);

console.log(self);

self.args[0].length = self.args[0].body.length;
self.args[2].length = self.args[2].body.length;

return;
}


this.visibleValue.pos = visibleValue.pos;
this.placeholder = placeholder;
this.visibleValue.argsPos = visibleValue.argsPos;
Expand Down
3 changes: 2 additions & 1 deletion libs/priceless-mathematica/src/boxes/gridbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ import {
parent[j].length = text.length;


console.log(changes);
//console.log(changes);
//console.log(this.args);

this.view.dispatch({changes: changes});
Expand All @@ -198,6 +198,7 @@ import {

update(visibleValue) {
//console.log('Update instance: new ranges & arguments');
console.log('We cant verify if changes were applied from the widget itself!');
this.visibleValue.pos = visibleValue.pos;
this.visibleValue.argsPos = visibleValue.argsPos;
//this.visibleValue.args = visibleValue.args;
Expand Down
8 changes: 6 additions & 2 deletions libs/priceless-mathematica/src/boxes/matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,14 @@ var BallancedMatchDecorator2 = /** @class */ (function () {
changeTo = Math.max(to, changeTo);
}
});
if (update.viewportChanged || changeTo - changeFrom > 1000)
if (update.viewportChanged || changeTo - changeFrom > 1000) {
//console.log('createDeco');
return this.createDeco(update.view);
if (changeTo > -1)
}
if (changeTo > -1) {
//console.log('updatRanges');
return this.updateRange(update.view, deco.map(update.changes), changeFrom, changeTo);
}
return deco;
};
BallancedMatchDecorator2.prototype.updateRange = function (view, deco, updateFrom, updateTo) {
Expand Down
55 changes: 55 additions & 0 deletions libs/priceless-mathematica/src/boxes/sqrtbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
} from "@codemirror/view";
import { isCursorInside } from "./utils";

import {EditorState} from "@codemirror/state";

import { BallancedMatchDecorator2 } from "./matcher";

import { keymap } from "@codemirror/view";
Expand Down Expand Up @@ -58,6 +60,7 @@ import {
this.view = view;
this.visibleValue = visibleValue;
const self = this;
this.sliceRanges = sliceRanges;

this.length = visibleValue.str.length;

Expand Down Expand Up @@ -123,13 +126,64 @@ import {
const delta = (data.length + 6) - this.length;
this.length = this.length + delta;
this.visibleValue.length = this.visibleValue.length + delta;
this.visibleValue.str = "Sqrt["+data+"]"; //save internally

this.view.dispatch({changes: changes});
}


update(visibleValue) {
//console.log('Update instance: new ranges & arguments');
if (this.visibleValue.str != visibleValue.str) {
console.warn('Out of sync');

//if changes occured outside the widget
//rebuild an entire thing

this.visibleValue = visibleValue;
const sliceRanges = this.sliceRanges;
const editor = this.editor;
const self = this;
const view = this.view;


this.length = visibleValue.str.length;

const newState = compactCMEditor.state({
doc: visibleValue.str.slice(...sliceRanges),
update: (upd) => self.applyChanges(upd),
eval: () => {
view.viewState.state.config.eval();
},
extensions: [
keymap.of([
{ key: "ArrowRight", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to) {
view.dispatch({selection: {anchor: self.visibleValue.pos + self.visibleValue.length}});
view.focus();

editor.editorLastCursor = undefined;
return;
}
editor.editorLastCursor = editor.state.selection.ranges[0].to;
} },
{ key: "ArrowLeft", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to) {
view.dispatch({selection: {anchor: self.visibleValue.pos}});
view.focus();
editor.editorLastCursor = undefined;
return;
}
editor.editorLastCursor = editor.state.selection.ranges[0].to;
} }
])
]
});

editor.setState(newState);
return;
}

this.visibleValue.pos = visibleValue.pos;
this.visibleValue.argsPos = visibleValue.argsPos;
//this.visibleValue.args = visibleValue.args;
Expand Down Expand Up @@ -241,6 +295,7 @@ import {
update(update) {
//console.log('update Deco');
//console.log(this.disposable );
//console.warn(update);
this.placeholder = matcher(this.disposable, update).updateDeco(
update,
this.placeholder
Expand Down
Loading

0 comments on commit 990017d

Please sign in to comment.