@lvce-editor/editor-worker 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/editorWorkerMain.js +97 -51
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -966,11 +966,11 @@ const setText = (editor, text) => {
|
|
|
966
966
|
};
|
|
967
967
|
|
|
968
968
|
const editors = Object.create(null);
|
|
969
|
-
const get$
|
|
969
|
+
const get$6 = id => {
|
|
970
970
|
number$1(id);
|
|
971
971
|
return editors[id];
|
|
972
972
|
};
|
|
973
|
-
const set$
|
|
973
|
+
const set$6 = (id, oldEditor, newEditor) => {
|
|
974
974
|
number$1(id);
|
|
975
975
|
object(oldEditor);
|
|
976
976
|
object(newEditor);
|
|
@@ -1046,10 +1046,10 @@ const number = value => {
|
|
|
1046
1046
|
const state$1$1 = {
|
|
1047
1047
|
callbacks: Object.create(null)
|
|
1048
1048
|
};
|
|
1049
|
-
const set$
|
|
1049
|
+
const set$5 = (id, fn) => {
|
|
1050
1050
|
state$1$1.callbacks[id] = fn;
|
|
1051
1051
|
};
|
|
1052
|
-
const get$
|
|
1052
|
+
const get$5 = id => {
|
|
1053
1053
|
return state$1$1.callbacks[id];
|
|
1054
1054
|
};
|
|
1055
1055
|
const remove = id => {
|
|
@@ -1083,7 +1083,7 @@ const registerPromise = () => {
|
|
|
1083
1083
|
resolve,
|
|
1084
1084
|
promise
|
|
1085
1085
|
} = withResolvers$2();
|
|
1086
|
-
set$
|
|
1086
|
+
set$5(id, resolve);
|
|
1087
1087
|
return {
|
|
1088
1088
|
id,
|
|
1089
1089
|
promise
|
|
@@ -1091,7 +1091,7 @@ const registerPromise = () => {
|
|
|
1091
1091
|
};
|
|
1092
1092
|
const resolve = (id, args) => {
|
|
1093
1093
|
number(id);
|
|
1094
|
-
const fn = get$
|
|
1094
|
+
const fn = get$5(id);
|
|
1095
1095
|
if (!fn) {
|
|
1096
1096
|
console.log(args);
|
|
1097
1097
|
warn$1(`callback ${id} may already be disposed`);
|
|
@@ -1431,23 +1431,23 @@ const state$8 = {
|
|
|
1431
1431
|
*/
|
|
1432
1432
|
ipc: undefined
|
|
1433
1433
|
};
|
|
1434
|
-
const get$
|
|
1434
|
+
const get$4 = () => {
|
|
1435
1435
|
return state$8.ipc;
|
|
1436
1436
|
};
|
|
1437
|
-
const set$
|
|
1437
|
+
const set$4 = ipc => {
|
|
1438
1438
|
state$8.ipc = ipc;
|
|
1439
1439
|
};
|
|
1440
1440
|
|
|
1441
1441
|
const invoke$4 = (method, ...params) => {
|
|
1442
|
-
const ipc = get$
|
|
1442
|
+
const ipc = get$4();
|
|
1443
1443
|
return invoke$5(ipc, method, ...params);
|
|
1444
1444
|
};
|
|
1445
1445
|
const invokeAndTransfer$1 = async (transfer, method, ...params) => {
|
|
1446
|
-
const ipc = get$
|
|
1446
|
+
const ipc = get$4();
|
|
1447
1447
|
return invokeAndTransfer$2(ipc, transfer, method, ...params);
|
|
1448
1448
|
};
|
|
1449
1449
|
const listen$8 = ipc => {
|
|
1450
|
-
set$
|
|
1450
|
+
set$4(ipc);
|
|
1451
1451
|
};
|
|
1452
1452
|
|
|
1453
1453
|
const invoke$3 = async (method, ...params) => {
|
|
@@ -1821,7 +1821,7 @@ const createEditor = async ({
|
|
|
1821
1821
|
focused: true
|
|
1822
1822
|
};
|
|
1823
1823
|
// console.log({ newEditor })
|
|
1824
|
-
set$
|
|
1824
|
+
set$6(id, emptyEditor, newEditor4);
|
|
1825
1825
|
await invoke$2(TextDocumentSyncFull, uri, id, languageId, content);
|
|
1826
1826
|
};
|
|
1827
1827
|
|
|
@@ -3661,10 +3661,10 @@ const state$4 = {
|
|
|
3661
3661
|
y: 0,
|
|
3662
3662
|
editor: undefined
|
|
3663
3663
|
};
|
|
3664
|
-
const get$
|
|
3664
|
+
const get$3 = () => {
|
|
3665
3665
|
return state$4;
|
|
3666
3666
|
};
|
|
3667
|
-
const set$
|
|
3667
|
+
const set$3 = (editor, timeout, x, y) => {
|
|
3668
3668
|
state$4.editor = editor;
|
|
3669
3669
|
state$4.timeout = timeout;
|
|
3670
3670
|
state$4.x = x;
|
|
@@ -3690,7 +3690,7 @@ const onHoverIdle = async () => {
|
|
|
3690
3690
|
x,
|
|
3691
3691
|
y,
|
|
3692
3692
|
editor
|
|
3693
|
-
} = get$
|
|
3693
|
+
} = get$3();
|
|
3694
3694
|
at(editor, x, y);
|
|
3695
3695
|
await showHover$1();
|
|
3696
3696
|
};
|
|
@@ -3701,12 +3701,12 @@ const handleMouseMove = (editor, x, y) => {
|
|
|
3701
3701
|
if (!editor.hoverEnabled) {
|
|
3702
3702
|
return editor;
|
|
3703
3703
|
}
|
|
3704
|
-
const oldState = get$
|
|
3704
|
+
const oldState = get$3();
|
|
3705
3705
|
if (oldState.timeout !== -1) {
|
|
3706
3706
|
clearTimeout(oldState.timeout);
|
|
3707
3707
|
}
|
|
3708
3708
|
const timeout = setTimeout(onHoverIdle, hoverDelay);
|
|
3709
|
-
set$
|
|
3709
|
+
set$3(editor, timeout, x, y);
|
|
3710
3710
|
return editor;
|
|
3711
3711
|
};
|
|
3712
3712
|
|
|
@@ -5176,7 +5176,7 @@ const setDecorations = (editor, decorations, diagnostics) => {
|
|
|
5176
5176
|
};
|
|
5177
5177
|
|
|
5178
5178
|
const getEditor = editorUid => {
|
|
5179
|
-
const instance = get$
|
|
5179
|
+
const instance = get$6(editorUid);
|
|
5180
5180
|
if (!instance) {
|
|
5181
5181
|
throw new Error(`editor ${editorUid} not found`);
|
|
5182
5182
|
}
|
|
@@ -5236,21 +5236,47 @@ const state$1 = {
|
|
|
5236
5236
|
const has = languageId => {
|
|
5237
5237
|
return languageId in state$1.tokenizers;
|
|
5238
5238
|
};
|
|
5239
|
-
const set$
|
|
5239
|
+
const set$2 = (languageId, tokenizer) => {
|
|
5240
5240
|
state$1.tokenizers[languageId] = tokenizer;
|
|
5241
5241
|
};
|
|
5242
|
-
const get$
|
|
5242
|
+
const get$2 = languageId => {
|
|
5243
5243
|
return state$1.tokenizers[languageId];
|
|
5244
5244
|
};
|
|
5245
5245
|
const isPending = languageId => {
|
|
5246
5246
|
return languageId in state$1.pending;
|
|
5247
5247
|
};
|
|
5248
5248
|
|
|
5249
|
+
let enabled$1 = false;
|
|
5250
|
+
const setEnabled$1 = value => {
|
|
5251
|
+
enabled$1 = value;
|
|
5252
|
+
};
|
|
5253
|
+
const getEnabled$1 = () => {
|
|
5254
|
+
return enabled$1;
|
|
5255
|
+
};
|
|
5256
|
+
|
|
5257
|
+
const {
|
|
5258
|
+
listen: listen$6,
|
|
5259
|
+
invoke: invoke$1
|
|
5260
|
+
} = createRpc(SyntaxHighlightingWorker);
|
|
5261
|
+
|
|
5262
|
+
const tokenMaps = Object.create(null);
|
|
5263
|
+
const set$1 = (languageId, tokenMap) => {
|
|
5264
|
+
tokenMaps[languageId] = tokenMap;
|
|
5265
|
+
};
|
|
5266
|
+
const get$1 = languageId => {
|
|
5267
|
+
return tokenMaps[languageId] || {};
|
|
5268
|
+
};
|
|
5269
|
+
|
|
5249
5270
|
// TODO loadTokenizer should be invoked from renderer worker
|
|
5250
5271
|
const loadTokenizer = async (languageId, tokenizePath) => {
|
|
5251
5272
|
if (!tokenizePath) {
|
|
5252
5273
|
return;
|
|
5253
5274
|
}
|
|
5275
|
+
if (getEnabled$1()) {
|
|
5276
|
+
const tokenMap = await invoke$1('Tokenizer.load', languageId, tokenizePath);
|
|
5277
|
+
set$1(languageId, tokenMap);
|
|
5278
|
+
return;
|
|
5279
|
+
}
|
|
5254
5280
|
try {
|
|
5255
5281
|
// TODO check that tokenizer is valid
|
|
5256
5282
|
// 1. tokenizeLine should be of type function
|
|
@@ -5264,7 +5290,8 @@ const loadTokenizer = async (languageId, tokenizePath) => {
|
|
|
5264
5290
|
console.warn(`tokenizer.TokenMap should be an object in "${tokenizePath}"`);
|
|
5265
5291
|
return;
|
|
5266
5292
|
}
|
|
5267
|
-
set$1(languageId, tokenizer);
|
|
5293
|
+
set$1(languageId, tokenizer.TokenMap);
|
|
5294
|
+
set$2(languageId, tokenizer);
|
|
5268
5295
|
} catch (error) {
|
|
5269
5296
|
// TODO better error handling
|
|
5270
5297
|
console.error(error);
|
|
@@ -5273,7 +5300,7 @@ const loadTokenizer = async (languageId, tokenizePath) => {
|
|
|
5273
5300
|
};
|
|
5274
5301
|
const getTokenizer = languageId => {
|
|
5275
5302
|
if (has(languageId)) {
|
|
5276
|
-
return get$
|
|
5303
|
+
return get$2(languageId);
|
|
5277
5304
|
}
|
|
5278
5305
|
if (isPending(languageId)) {
|
|
5279
5306
|
return TokenizePlainText;
|
|
@@ -6391,19 +6418,19 @@ const getHover = async (editor, offset) => {
|
|
|
6391
6418
|
};
|
|
6392
6419
|
|
|
6393
6420
|
let _ipc;
|
|
6394
|
-
const listen$
|
|
6421
|
+
const listen$5 = async () => {
|
|
6395
6422
|
const ipc = await create$1({
|
|
6396
6423
|
method: RendererProcess
|
|
6397
6424
|
});
|
|
6398
6425
|
handleIpc(ipc);
|
|
6399
6426
|
_ipc = ipc;
|
|
6400
6427
|
};
|
|
6401
|
-
const invoke
|
|
6428
|
+
const invoke = async (method, ...args) => {
|
|
6402
6429
|
return invoke$5(_ipc, method, ...args);
|
|
6403
6430
|
};
|
|
6404
6431
|
|
|
6405
6432
|
const measureTextBlockHeight = (text, fontFamily, fontSize, lineHeight, width) => {
|
|
6406
|
-
return invoke
|
|
6433
|
+
return invoke('MeasureTextBlockHeight.measureTextBlockHeight', text, fontSize, fontFamily, lineHeight, width);
|
|
6407
6434
|
};
|
|
6408
6435
|
|
|
6409
6436
|
const deepCopy = value => {
|
|
@@ -6541,7 +6568,7 @@ const getHoverPositionXy = (editor, rowIndex, wordStart, documentationHeight) =>
|
|
|
6541
6568
|
};
|
|
6542
6569
|
const getEditorHoverInfo = async (editorUid, position) => {
|
|
6543
6570
|
number$1(editorUid);
|
|
6544
|
-
const instance = get$
|
|
6571
|
+
const instance = get$6(editorUid);
|
|
6545
6572
|
const editor = instance.newState;
|
|
6546
6573
|
const {
|
|
6547
6574
|
selections
|
|
@@ -6591,11 +6618,6 @@ const handleBeforeInput = (editor, inputType, data) => {
|
|
|
6591
6618
|
}
|
|
6592
6619
|
};
|
|
6593
6620
|
|
|
6594
|
-
const {
|
|
6595
|
-
listen: listen$5,
|
|
6596
|
-
invoke
|
|
6597
|
-
} = createRpc(SyntaxHighlightingWorker);
|
|
6598
|
-
|
|
6599
6621
|
let enabled = false;
|
|
6600
6622
|
const setEnabled = value => {
|
|
6601
6623
|
enabled = value;
|
|
@@ -6604,11 +6626,14 @@ const getEnabled = () => {
|
|
|
6604
6626
|
return enabled;
|
|
6605
6627
|
};
|
|
6606
6628
|
|
|
6607
|
-
const intialize = async syntaxHighlightingEnabled => {
|
|
6608
|
-
await listen$
|
|
6629
|
+
const intialize = async (syntaxHighlightingEnabled, syncIncremental) => {
|
|
6630
|
+
await listen$5();
|
|
6609
6631
|
if (syntaxHighlightingEnabled) {
|
|
6632
|
+
setEnabled$1(true);
|
|
6633
|
+
await listen$6();
|
|
6634
|
+
}
|
|
6635
|
+
if (syncIncremental) {
|
|
6610
6636
|
setEnabled(true);
|
|
6611
|
-
await listen$5();
|
|
6612
6637
|
}
|
|
6613
6638
|
await listen$7();
|
|
6614
6639
|
};
|
|
@@ -6869,11 +6894,34 @@ const getTokensViewport = (editor, startLineIndex, endLineIndex) => {
|
|
|
6869
6894
|
};
|
|
6870
6895
|
};
|
|
6871
6896
|
|
|
6897
|
+
const sentLines = Object.create(null);
|
|
6898
|
+
|
|
6872
6899
|
// TODO only send changed lines to renderer process instead of all lines in viewport
|
|
6873
|
-
const getTokensViewport2 = (editor, startLineIndex, endLineIndex) => {
|
|
6874
|
-
if (getEnabled()) {
|
|
6900
|
+
const getTokensViewport2 = (editor, startLineIndex, endLineIndex, syncIncremental) => {
|
|
6901
|
+
if (getEnabled$1()) {
|
|
6902
|
+
if (syncIncremental) {
|
|
6903
|
+
const {
|
|
6904
|
+
invalidStartIndex,
|
|
6905
|
+
lines,
|
|
6906
|
+
languageId,
|
|
6907
|
+
id
|
|
6908
|
+
} = editor;
|
|
6909
|
+
let hasLinesToSend = true;
|
|
6910
|
+
let linesToSend = lines;
|
|
6911
|
+
if (sentLines[id] === lines) {
|
|
6912
|
+
hasLinesToSend = false;
|
|
6913
|
+
linesToSend = [];
|
|
6914
|
+
} else {
|
|
6915
|
+
sentLines[id] = lines;
|
|
6916
|
+
}
|
|
6917
|
+
const slimEditor = {
|
|
6918
|
+
languageId,
|
|
6919
|
+
invalidStartIndex
|
|
6920
|
+
};
|
|
6921
|
+
return invoke$1('GetTokensViewport.getTokensViewport', slimEditor, startLineIndex, endLineIndex, hasLinesToSend, id, linesToSend);
|
|
6922
|
+
}
|
|
6875
6923
|
// TODO only send needed lines of text
|
|
6876
|
-
return invoke('GetTokensViewport.getTokensViewport', editor, startLineIndex, endLineIndex);
|
|
6924
|
+
return invoke$1('GetTokensViewport.getTokensViewport', editor, startLineIndex, endLineIndex, true, editor.id, editor.lines);
|
|
6877
6925
|
}
|
|
6878
6926
|
return getTokensViewport(editor, startLineIndex, endLineIndex);
|
|
6879
6927
|
};
|
|
@@ -7063,13 +7111,10 @@ const getLineInfosViewport = (editor, tokens, embeddedResults, minLineY, maxLine
|
|
|
7063
7111
|
const differences = [];
|
|
7064
7112
|
const {
|
|
7065
7113
|
lines,
|
|
7066
|
-
|
|
7067
|
-
|
|
7114
|
+
decorations,
|
|
7115
|
+
languageId
|
|
7068
7116
|
} = editor;
|
|
7069
|
-
const
|
|
7070
|
-
const {
|
|
7071
|
-
TokenMap
|
|
7072
|
-
} = tokenizer;
|
|
7117
|
+
const tokenMap = get$1(languageId);
|
|
7073
7118
|
let offset = minLineOffset;
|
|
7074
7119
|
const tabSize = 2;
|
|
7075
7120
|
for (let i = minLineY; i < maxLineY; i++) {
|
|
@@ -7078,7 +7123,7 @@ const getLineInfosViewport = (editor, tokens, embeddedResults, minLineY, maxLine
|
|
|
7078
7123
|
const {
|
|
7079
7124
|
lineInfo,
|
|
7080
7125
|
difference
|
|
7081
|
-
} = getLineInfo(line, tokens[i - minLineY], embeddedResults, decorations,
|
|
7126
|
+
} = getLineInfo(line, tokens[i - minLineY], embeddedResults, decorations, tokenMap, offset, normalize, tabSize, width, deltaX, averageCharWidth);
|
|
7082
7127
|
result.push(lineInfo);
|
|
7083
7128
|
differences.push(difference);
|
|
7084
7129
|
offset += line.length + 1;
|
|
@@ -7088,7 +7133,7 @@ const getLineInfosViewport = (editor, tokens, embeddedResults, minLineY, maxLine
|
|
|
7088
7133
|
differences
|
|
7089
7134
|
};
|
|
7090
7135
|
};
|
|
7091
|
-
const getVisible = async editor => {
|
|
7136
|
+
const getVisible = async (editor, syncIncremental) => {
|
|
7092
7137
|
// console.log({ editor })
|
|
7093
7138
|
// TODO should separate rendering from business logic somehow
|
|
7094
7139
|
// currently hard to test because need to mock editor height, top, left,
|
|
@@ -7112,7 +7157,7 @@ const getVisible = async editor => {
|
|
|
7112
7157
|
tokens,
|
|
7113
7158
|
tokenizersToLoad,
|
|
7114
7159
|
embeddedResults
|
|
7115
|
-
} = await getTokensViewport2(editor, minLineY, maxLineY);
|
|
7160
|
+
} = await getTokensViewport2(editor, minLineY, maxLineY, syncIncremental);
|
|
7116
7161
|
const minLineOffset = offsetAtSync(editor, minLineY, 0);
|
|
7117
7162
|
const averageCharWidth = charWidth;
|
|
7118
7163
|
const {
|
|
@@ -7312,10 +7357,11 @@ const renderLines = {
|
|
|
7312
7357
|
if (incrementalEdits) {
|
|
7313
7358
|
return [/* method */'setIncrementalEdits', /* incrementalEdits */incrementalEdits];
|
|
7314
7359
|
}
|
|
7360
|
+
const syncIncremental = getEnabled();
|
|
7315
7361
|
const {
|
|
7316
7362
|
textInfos,
|
|
7317
7363
|
differences
|
|
7318
|
-
} = await getVisible(newState);
|
|
7364
|
+
} = await getVisible(newState, syncIncremental);
|
|
7319
7365
|
newState.differences = differences;
|
|
7320
7366
|
const dom = getEditorRowsVirtualDom(textInfos, differences);
|
|
7321
7367
|
return [/* method */'setText', dom];
|
|
@@ -7395,7 +7441,7 @@ const renderGutterInfo = {
|
|
|
7395
7441
|
};
|
|
7396
7442
|
const render = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus, renderDecorations, renderGutterInfo];
|
|
7397
7443
|
const renderEditor = async id => {
|
|
7398
|
-
const instance = get$
|
|
7444
|
+
const instance = get$6(id);
|
|
7399
7445
|
if (!instance) {
|
|
7400
7446
|
return [];
|
|
7401
7447
|
}
|
|
@@ -7409,7 +7455,7 @@ const renderEditor = async id => {
|
|
|
7409
7455
|
commands.push(await item.apply(oldState, newState));
|
|
7410
7456
|
}
|
|
7411
7457
|
}
|
|
7412
|
-
set$
|
|
7458
|
+
set$6(id, newState, newState);
|
|
7413
7459
|
return commands;
|
|
7414
7460
|
};
|
|
7415
7461
|
|
|
@@ -7418,9 +7464,9 @@ const keep = ['ColorPicker.handleSliderPointerDown', 'ColorPicker.handleSliderPo
|
|
|
7418
7464
|
// TODO wrap commands globally, not per editor
|
|
7419
7465
|
// TODO only store editor state in editor worker, not in renderer worker also
|
|
7420
7466
|
const wrapCommand = fn => async (editorUid, ...args) => {
|
|
7421
|
-
const oldInstance = get$
|
|
7467
|
+
const oldInstance = get$6(editorUid);
|
|
7422
7468
|
const newEditor = await fn(oldInstance.newState, ...args);
|
|
7423
|
-
set$
|
|
7469
|
+
set$6(editorUid, oldInstance.newState, newEditor);
|
|
7424
7470
|
// TODO if possible, rendering should be sync
|
|
7425
7471
|
const commands = await renderEditor(editorUid);
|
|
7426
7472
|
newEditor.commands = commands;
|