Skip to content

Commit

Permalink
Merge pull request #11 from JerryI/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JerryI authored Oct 18, 2024
2 parents 990017d + 51e880e commit 2cd0fd9
Show file tree
Hide file tree
Showing 16 changed files with 1,240 additions and 572 deletions.
Binary file modified .DS_Store
Binary file not shown.
894 changes: 467 additions & 427 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.

190 changes: 116 additions & 74 deletions libs/priceless-mathematica/src/boxes/gridbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
import { BallancedMatchDecorator2, matchArguments } from "./matcher";

import { keymap } from "@codemirror/view";

import { Mma } from "mma-uncompress/src/mma";

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

Expand All @@ -26,7 +28,8 @@ import {
];
}


const itemBox = /"(.+)"\(\*VB\[\*\)\(\*\*\)\(\*\,\*\)\(\*\"([\w:\d=]*)/;


class EditorWidget {

Expand All @@ -43,8 +46,13 @@ import {
if (index % 2 != 0) return arg;
return {...arg, body: matchArguments(arg.body, /\(\*\|\*\)/gm)}
});

if (!Array.isArray(this.args[this.args.length-1].body)) {
this.decorator = this.args.pop();
}

//console.log(this.args);
//console.warn(this.args);
//return;
//return;
const args = this.args;

Expand All @@ -65,77 +73,101 @@ import {
if (j == cols.length-1 && i == this.args.length-1) text = text.slice(0,-2);
if (j == cols.length-1 && i != this.args.length-1) text = text.slice(0,-1);

cols[j].editor = compactCMEditor({
doc: text,
parent: td,
eval: () => {
view.viewState.state.config.eval();
},
update: (upd) => this.applyChanges(upd, i,j),
extensions: [
keymap.of([
{ key: "ArrowLeft", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to)
if (j - 2 >= 0) {
cols[j-2].editor.dispatch({selection:{anchor:cols[j-2].editor.state.doc.length}});
cols[j-2].editor.focus();
editor.editorLastCursor = undefined;
return;
} else {
view.dispatch({selection: {anchor: self.visibleValue.pos}});
view.focus();

editor.editorLastCursor = undefined;
return;
}

editor.editorLastCursor = editor.state.selection.ranges[0].to;
} },
{ key: "ArrowRight", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to)
if (j + 2 < cols.length) {
cols[j+2].editor.dispatch({selection:{anchor:0}});
cols[j+2].editor.focus();
editor.editorLastCursor = undefined;
return;
} else {
//view.focus();
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) {
//if (editor?.editorLastCursor === editor.state.selection.ranges[0].to)
if (i - 2 >= 0) {
args[i-2].body[j].editor.focus();
editor.editorLastCursor = undefined;
return;
} else {
//view.focus();
}

//editor.editorLastCursor = editor.state.selection.ranges[0].to;
} },
{ key: "ArrowDown", run: function (editor, key) {
//if (editor?.editorLastCursor === editor.state.selection.ranges[0].to)
if (i + 2 < args.length) {
args[i+2].body[j].editor.focus();
editor.editorLastCursor = undefined;
return;
} else {
//view.focus();
}

//editor.editorLastCursor = editor.state.selection.ranges[0].to;
} }
])
]
});
if (text.charAt(0) != '"') {
cols[j].editor = compactCMEditor({
doc: text,
parent: td,
eval: () => {
view.viewState.state.config.eval();
},
update: (upd) => this.applyChanges(upd, i,j),
extensions: [
keymap.of([
{ key: "ArrowLeft", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to)
if (j - 2 >= 0) {
cols[j-2].editor.dispatch({selection:{anchor:cols[j-2].editor.state.doc.length}});
cols[j-2].editor.focus();
editor.editorLastCursor = undefined;
return;
} else {
view.dispatch({selection: {anchor: self.visibleValue.pos}});
view.focus();

editor.editorLastCursor = undefined;
return;
}

editor.editorLastCursor = editor.state.selection.ranges[0].to;
} },
{ key: "ArrowRight", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to)
if (j + 2 < cols.length) {
cols[j+2].editor.dispatch({selection:{anchor:0}});
cols[j+2].editor.focus();
editor.editorLastCursor = undefined;
return;
} else {
//view.focus();
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) {
//if (editor?.editorLastCursor === editor.state.selection.ranges[0].to)
if (i - 2 >= 0) {
args[i-2].body[j].editor.focus();
editor.editorLastCursor = undefined;
return;
} else {
//view.focus();
}

//editor.editorLastCursor = editor.state.selection.ranges[0].to;
} },
{ key: "ArrowDown", run: function (editor, key) {
//if (editor?.editorLastCursor === editor.state.selection.ranges[0].to)
if (i + 2 < args.length) {
args[i+2].body[j].editor.focus();
editor.editorLastCursor = undefined;
return;
} else {
//view.focus();
}

//editor.editorLastCursor = editor.state.selection.ranges[0].to;
} }
])
]
});
} else {
cols[j].editor = {
destroy: () => {},
focus: () => {},
dispatch: () => {}
};

const itemDesc = text.match(itemBox);

if (itemDesc) {
td.innerHTML = itemDesc[1];

const decoded = Mma.DecompressDecode(itemDesc[2]);
const json = Mma.toArray(decoded.parts[0]);
const cuid = uuidv4();
let global = {call: cuid};
let env = {global: global, element: td}; //Created in CM6
interpretate(json, env);

} else {
td.innerHTML = text.slice(1,-1);
}
}


//remove unnecesary
Expand All @@ -146,7 +178,17 @@ import {
tbody.appendChild(tr);
}

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

if (this.decorator) {
//console.log(this.decorator);
const decoded = Mma.DecompressDecode(this.decorator.body.slice(2,-2));
const json = Mma.toArray(decoded.parts[0]);
const cuid = uuidv4();
let global = {call: cuid, EditorWidget: self};
let env = {global: global, element: tbody}; //Created in CM6
this.interpretated = interpretate(json, env);
}


}
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wljs-editor",
"version": "1.0.9",
"version": "1.1.9",
"description": "WLJS Code editor",
"scripts": {
"build": "node --max-old-space-size=8192 ./node_modules/.bin/rollup --config rollup.config.mjs",
Expand All @@ -24,7 +24,7 @@
"src/frontsubmit.js",
"src/dir.js",
"src/metamarkers.js",
"src/rasterize.js"
"src/misc.js"
],
"frontend": [
"src/FrontendObject.wl",
Expand All @@ -38,11 +38,11 @@
"src/Notifications.wl",
"src/Autocomplete.wl",
"src/ContextMenu.wl",
"src/FileUpload.wl"
"src/FileUpload.wl",
"src/FrontendRuntime.wl"
],
"kernel": [
"src/FrontendObject.wl",
"src/FrontendObjectExtensions.wl",
"src/EditorKernel.wl",
"src/StandardForm.wl",
"src/Boxes.wl",
Expand All @@ -56,7 +56,9 @@
"src/NotificationsKernel.wl",
"src/MetaMarkersKernel.wl",
"src/AutocompleteKernel.wl",
"src/RasterizeKernel.wl"
"src/RasterizeKernel.wl",
"src/System.wl",
"src/FrontendRuntimeKernel.wl"
],
"styles": "src/styles.css",
"priority": -10,
Expand Down
7 changes: 3 additions & 4 deletions src/AutocompleteDefaults.wl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{<|"label" -> "ToExpression", "type" -> "keyword",
{<|"label"->"Drop", "type"->"keyword", "info"->"Drop[list, n] gives list with its first n elements dropped."|>, <|"label"->"NotebookDirectory", "type"->"keyword", "info"->"NotebookDirectory[] returns a path to a directory of the current notebook"|>, <|"label"->"EvaluationCell", "type"->"keyword", "info"->"EvaluationCell[] returns a reference to the current input cell"|>, <|"label"->"SystemOpen", "type"->"keyword", "info"->"SystemOpen[path_String | _File | _URL] opens a path using system call"|>, <|"label" -> "Annotation", "type" -> "keyword",
"info" -> "Annotation[expr, data] annotates arbitary expression with data (invisible on output). Annotation[edge_, key_->value_] annotates edge of a graph"|>, <|"label" -> "Integrate", "type" -> "keyword", "info" -> "Integrate[f[x], x] gives the indefinite integral. Integrate[f[x], {x, min, max}] gives the definite integral..."|>, <|"label" -> "TableForm", "type" -> "keyword", "info" -> "TableForm[expr_List] formats list of lists as table"|>, <|"label" -> "Item", "type" -> "keyword", "info" -> "Use it inside Grid, TableForm to color or stylize font of expression. Accepts the same options as Style[]"|>, <|"label" -> "ToExpression", "type" -> "keyword",
"info" -> "gives the expression obtained by interpreting strings as Wolfram \
Language input"|>, <|"label" -> "MakeBoxes", "type" -> "keyword",
"info" -> "MakeBoxes[expr,form] is the low-level function used to convert \
Expand Down Expand Up @@ -11850,9 +11851,7 @@ that would be obtained if symbols in it were replaced by "|>,
of points in a mirror normal to the "|>, <|"label" -> "ReflectionTransform",
"type" -> "keyword", "info" -> "ReflectionTransform[v] gives a \
TransformationFunction that represents a reflection in a mirror throu"|>,
<|"label" -> "Refresh", "type" -> "keyword", "info" -> "Refresh[expr, opts] \
represents an object whose value in a Dynamic should be refreshed at times \
speci"|>, <|"label" -> "RefreshRate", "type" -> "keyword",
<|"label" -> "Refresh", "type" -> "keyword", "info" -> "Refresh[expr_, interval] creates a dynamic widget, which reevalues expr every interval (in seconds or Quantity[]). Refresh[expr_, ev_EventObject] is updated by external event object ev"|>, <|"label" -> "RefreshRate", "type" -> "keyword",
"info" -> "RefreshRate is an option to Animate and related functions which \
specifies the refresh rate for frame"|>, <|"label" -> "Region",
"type" -> "keyword", "info" -> "Region[reg] represents a geometric \
Expand Down
Loading

0 comments on commit 2cd0fd9

Please sign in to comment.