Skip to content

Commit

Permalink
Merge pull request #13 from JerryI/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JerryI authored Nov 29, 2024
2 parents ad8a811 + cff0136 commit d83508f
Show file tree
Hide file tree
Showing 28 changed files with 890 additions and 94 deletions.
Binary file modified .DS_Store
Binary file not shown.
158 changes: 140 additions & 18 deletions dist/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19730,13 +19730,6 @@ const defaultKeymap = /*@__PURE__*/[
{ key: "Mod-/", win: "Alt+/", linux: "Alt+/", run: toggleComment },
{ key: "Alt-A", run: toggleBlockComment }
].concat(standardKeymap);
/**
A binding that binds Tab to [`indentMore`](https://codemirror.net/6/docs/ref/#commands.indentMore) and
Shift-Tab to [`indentLess`](https://codemirror.net/6/docs/ref/#commands.indentLess).
Please see the [Tab example](../../examples/tab/) before using
this.
*/
const indentWithTab = { key: "Tab", run: indentMore, shift: indentLess };

function crelt() {
var elt = arguments[0];
Expand Down Expand Up @@ -28760,21 +28753,73 @@ wolframLanguage.reBuild = (vocabulary) => {
const transferFiles = (list, ev, view, handler) => {
if (list.length == 0) return;
const id = new Date().valueOf();
let count = 0;

view.dom.loadingMark = true;
const originalColor = view.dom.style.background;

let hue = 0;

console.log('Start animation');

const loaderAnimation = setInterval(() => {
view.dom.style.setProperty("background", 'hsl('+hue+'deg 100% 97%)', "important");
hue = hue + 2;
if (hue > 360) hue = 0;
}, 30);
handler.transaction(ev, view, id, list.length);
// server.kernel.emitt('<Event/>', `<|"Id" -> "${id}", "Length" -> ${list.length}|>`, 'Transaction');

for (const file of list) {
readFile(file, (name, result) => {
handler.file(ev, view, id, name, result);
//server.kernel.emitt('id', `<|"Transaction" -> "${id}", "Name" -> "${name}", "Data" -> "${result}"|>`, 'File');
count++;
if (count >= list.length && view.dom) {
if (view.dom.loadingMark) {
view.dom.loadingMark = false;
setTimeout(() => {
view.dom.style.background = originalColor;
clearInterval(loaderAnimation);
console.log('Stop animation');
}, 2000);
}
}
}, () => {
console.warn('Fauilure');
const original = view.dom.style.background;
view.dom.style.background = 'rgb(255 189 189 / 97%)';
let opacity = 97;
const interval = setInterval(() => {
view.dom.style.background = 'rgb(255 189 189 / '+Math.round(opacity)+'%)';
opacity = opacity * 0.95;
}, 30);


clearInterval(loaderAnimation);

setTimeout(() => {
clearInterval(interval);
view.dom.style.background = original;
}, 3000);
});
}

};

function readFile(file, cbk) {
function readFile(file, cbk, fail) {
const reader = new FileReader();

reader.addEventListener('load', (event) => {
let compressedData = base64ArrayBuffer(event.target.result);
const payload = event.target.result;
if (payload.byteLength / 1024 / 1024 > 100) {
alert('Files > 100Mb are not supported for drag and drop');
fail();
return;
//throw 'Files > 15Mb are not supported for drag and drop';
}

let compressedData = base64ArrayBuffer(payload);
//console.log(compressedData);
cbk(file.name, compressedData);
});
Expand Down Expand Up @@ -38486,7 +38531,7 @@ var compactCMEditor$2;
];
}

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


let EditorWidget$3 = class EditorWidget {
Expand Down Expand Up @@ -38542,7 +38587,7 @@ var compactCMEditor$2;
extensions: [
keymap.of([
{ key: "ArrowLeft", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to)
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to && !editor.stringOnly)
if (j - 2 >= 0) {
cols[j-2].editor.dispatch({selection:{anchor:cols[j-2].editor.state.doc.length}});
cols[j-2].editor.focus();
Expand All @@ -38559,7 +38604,7 @@ var compactCMEditor$2;
editor.editorLastCursor = editor.state.selection.ranges[0].to;
} },
{ key: "ArrowRight", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to)
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to && !editor.stringOnly)
if (j + 2 < cols.length) {
cols[j+2].editor.dispatch({selection:{anchor:0}});
cols[j+2].editor.focus();
Expand Down Expand Up @@ -38603,14 +38648,17 @@ var compactCMEditor$2;
cols[j].editor = {
destroy: () => {},
focus: () => {},
dispatch: () => {}
dispatch: () => {},
stringOnly: true
};

const itemDesc = text.match(itemBox);

if (itemDesc) {
if (itemDesc) { //stylize the text
td.innerHTML = itemDesc[1];

//throw(itemDesc);

const decoded = Mma.DecompressDecode(itemDesc[2]);
const json = Mma.toArray(decoded.parts[0]);
const cuid = uuidv4();
Expand Down Expand Up @@ -40083,6 +40131,9 @@ compactWLEditor = (args) => {
doc: args.doc,
extensions: [
keymap.of([
{ key: "Tab", run: function (editor, key) {
return acceptCompletion(editor);
} },
{ key: "Enter", preventDefault: true, run: function (editor, key) {
return true;
} }
Expand Down Expand Up @@ -40133,6 +40184,9 @@ compactWLEditor.state = (args) => {
doc: args.doc,
extensions: [
keymap.of([
{ key: "Tab", run: function (editor, key) {
return acceptCompletion(editor);
} },
{ key: "Enter", preventDefault: true, run: function (editor, key) {
return true;
} }
Expand Down Expand Up @@ -40178,19 +40232,39 @@ compactWLEditor.state = (args) => {
return state;
};

const splitStringIntoChunks = (str, chunkSize) => {
if (!str || chunkSize <= 0) return [];

const chunks = [];
for (let i = 0; i < str.length; i += chunkSize) {
chunks.push(str.slice(i, Math.min(i + chunkSize, str.length)));
}
return chunks;
};

const wlDrop = {
transaction: (ev, view, id, length) => {
console.log(view.dom.ocellref);
selectedEditor = view;
if (view.dom.ocellref) {
const channel = view.dom.ocellref.origin.channel;
server._emitt(channel, `<|"Channel"->"${id}", "Length"->${length}, "CellType"->"wl"|>`, 'Forwarded["CM:DropEvent"]');
}
},

file: (ev, view, id, name, result) => {
console.log(view.dom.ocellref);
//console.log(view.dom.ocellref);
//console.log(result);
if (view.dom.ocellref) {
server.emitt(id, `<|"Data"->"${result}", "Name"->"${name}"|>`, 'File');
//throw result.length;
if (result.length > 5 * 1024 * 1024) {
const chunks = splitStringIntoChunks(result, 5 * 1024 * 1024);
chunks.forEach((chunk, index) => {
server.emitt(id, `<|"Data"->"${chunk}", "Name"->"${name}", "Chunk"->${index+1}, "Chunks"->${chunks.length}|>`, 'Chunk');
});
} else {
server.emitt(id, `<|"Data"->"${result}", "Name"->"${name}"|>`, 'File');
}
}
}
};
Expand All @@ -40207,7 +40281,14 @@ const wlPaste = {
file: (ev, view, id, name, result) => {
console.log(view.dom.ocellref);
if (view.dom.ocellref) {
server.emitt(id, `<|"Data"->"${result}", "Name"->"${name}"|>`, 'File');
if (result.length > 5 * 1024 * 1024) {
const chunks = splitStringIntoChunks(result, 5 * 1024 * 1024);
chunks.forEach((chunk, index) => {
server.emitt(id, `<|"Data"->"${chunk}", "Name"->"${name}", "Chunk"->${index+1}, "Chunks"->${chunks.length}|>`, 'Chunk');
});
} else {
server.emitt(id, `<|"Data"->"${result}", "Name"->"${name}"|>`, 'File');
}
}
}
};
Expand Down Expand Up @@ -40355,7 +40436,12 @@ const EditorExtensions = [

() => search(),

(self, initialLang) => keymap.of([indentWithTab,
(self, initialLang) => keymap.of([
{ key: "Tab", run: function (editor, key) {
const res = acceptCompletion(editor);
if (!res) return indentMore(editor);
return res;
}, shift: indentLess },
{ key: "Backspace", run: function (editor, key) {
if(editor.state.doc.length === 0) { self.origin.remove(); return true; }
} },
Expand Down Expand Up @@ -40550,6 +40636,14 @@ class CodeMirrorCell {
if (options.ReadOnly) {
ext.push(EditorState.readOnly.of(true));
}
//console.warn(options);
if ('Selectable' in options) {
if (!options.Selectable)
ext.push(EditorState.transactionFilter.of((tr) => {
//console.log(tr);
return false;
}));
}

if (options.ForceUpdate) {
env.local.forceUpdate = options.ForceUpdate;
Expand Down Expand Up @@ -40661,7 +40755,11 @@ class CodeMirrorCell {
EditorParameters: EditorParameters,
EditorExtensions: EditorExtensions,
StateField: StateField,
StateEffect: StateEffect,
Decoration: Decoration,
Prec: Prec,
EditorSelection: EditorSelection,
keymap: keymap,
ViewPlugin: ViewPlugin,
WidgetType: WidgetType,
originFacet: originFacet,
Expand Down Expand Up @@ -40759,3 +40857,27 @@ core.FrontEditorSelected = async (args, env) => {
return key;
}
};


class ShellCell {

dispose() {

}

constructor(parent, data) {
this.origin = parent;
const result = document.createElement('div');
result.classList.add(...('flex sc-b max-h-60 text-sm overflow-y-scroll'.split(' ')));
result.style.overflowAnchor = 'auto';
result.style.flexDirection = 'column-reverse';
result.innerText = data;
this.origin.element.appendChild(result);

return this;
}
}

window.SupportedCells['shell'] = {
view: ShellCell
};
2 changes: 1 addition & 1 deletion dist/kernel.min.js

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions libs/priceless-mathematica/src/boxes/gridbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
];
}

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


class EditorWidget {
Expand Down Expand Up @@ -84,7 +84,7 @@ import {
extensions: [
keymap.of([
{ key: "ArrowLeft", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to)
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to && !editor.stringOnly)
if (j - 2 >= 0) {
cols[j-2].editor.dispatch({selection:{anchor:cols[j-2].editor.state.doc.length}});
cols[j-2].editor.focus();
Expand All @@ -101,7 +101,7 @@ import {
editor.editorLastCursor = editor.state.selection.ranges[0].to;
} },
{ key: "ArrowRight", run: function (editor, key) {
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to)
if (editor?.editorLastCursor === editor.state.selection.ranges[0].to && !editor.stringOnly)
if (j + 2 < cols.length) {
cols[j+2].editor.dispatch({selection:{anchor:0}});
cols[j+2].editor.focus();
Expand Down Expand Up @@ -149,14 +149,17 @@ import {
cols[j].editor = {
destroy: () => {},
focus: () => {},
dispatch: () => {}
dispatch: () => {},
stringOnly: true
};

const itemDesc = text.match(itemBox);

if (itemDesc) {
if (itemDesc) { //stylize the text
td.innerHTML = itemDesc[1];

//throw(itemDesc);

const decoded = Mma.DecompressDecode(itemDesc[2]);
const json = Mma.toArray(decoded.parts[0]);
const cuid = uuidv4();
Expand Down
Loading

0 comments on commit d83508f

Please sign in to comment.