@lvce-editor/text-search-worker 3.0.0 → 3.1.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/textSearchWorkerMain.js +178 -100
- package/package.json +1 -1
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
const commands = Object.create(null);
|
|
2
|
-
const register = commandMap => {
|
|
3
|
-
Object.assign(commands, commandMap);
|
|
4
|
-
};
|
|
5
|
-
const getCommand = key => {
|
|
6
|
-
return commands[key];
|
|
7
|
-
};
|
|
8
|
-
const execute = (command, ...args) => {
|
|
9
|
-
const fn = getCommand(command);
|
|
10
|
-
if (!fn) {
|
|
11
|
-
throw new Error(`command not found ${command}`);
|
|
12
|
-
}
|
|
13
|
-
return fn(...args);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
1
|
const Two = '2.0';
|
|
2
|
+
const create$4 = (method, params) => {
|
|
3
|
+
return {
|
|
4
|
+
jsonrpc: Two,
|
|
5
|
+
method,
|
|
6
|
+
params
|
|
7
|
+
};
|
|
8
|
+
};
|
|
17
9
|
const state$2 = {
|
|
18
10
|
callbacks: Object.create(null)
|
|
19
11
|
};
|
|
@@ -55,7 +47,7 @@ const resolve = (id, response) => {
|
|
|
55
47
|
fn(response);
|
|
56
48
|
remove$1(id);
|
|
57
49
|
};
|
|
58
|
-
const create$2
|
|
50
|
+
const create$2 = (method, params) => {
|
|
59
51
|
const {
|
|
60
52
|
id,
|
|
61
53
|
promise
|
|
@@ -232,7 +224,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
232
224
|
}
|
|
233
225
|
};
|
|
234
226
|
};
|
|
235
|
-
const create$1$
|
|
227
|
+
const create$1$2 = (message, error) => {
|
|
236
228
|
return {
|
|
237
229
|
jsonrpc: Two,
|
|
238
230
|
id: message.id,
|
|
@@ -243,9 +235,9 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
|
243
235
|
const prettyError = preparePrettyError(error);
|
|
244
236
|
logError(error, prettyError);
|
|
245
237
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
246
|
-
return create$1$
|
|
238
|
+
return create$1$2(message, errorProperty);
|
|
247
239
|
};
|
|
248
|
-
const create$
|
|
240
|
+
const create$5 = (message, result) => {
|
|
249
241
|
return {
|
|
250
242
|
jsonrpc: Two,
|
|
251
243
|
id: message.id,
|
|
@@ -254,7 +246,7 @@ const create$4 = (message, result) => {
|
|
|
254
246
|
};
|
|
255
247
|
const getSuccessResponse = (message, result) => {
|
|
256
248
|
const resultProperty = result ?? null;
|
|
257
|
-
return create$
|
|
249
|
+
return create$5(message, resultProperty);
|
|
258
250
|
};
|
|
259
251
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
260
252
|
try {
|
|
@@ -334,20 +326,65 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
334
326
|
const {
|
|
335
327
|
message,
|
|
336
328
|
promise
|
|
337
|
-
} = create$2
|
|
338
|
-
{
|
|
329
|
+
} = create$2(method, params);
|
|
330
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
331
|
+
ipc.sendAndTransfer(message);
|
|
332
|
+
} else {
|
|
339
333
|
ipc.send(message);
|
|
340
334
|
}
|
|
341
335
|
const responseMessage = await promise;
|
|
342
336
|
return unwrapJsonRpcResult(responseMessage);
|
|
343
337
|
};
|
|
338
|
+
const send = (transport, method, ...params) => {
|
|
339
|
+
const message = create$4(method, params);
|
|
340
|
+
transport.send(message);
|
|
341
|
+
};
|
|
344
342
|
const invoke$2 = (ipc, method, ...params) => {
|
|
345
|
-
return invokeHelper(ipc, method, params);
|
|
343
|
+
return invokeHelper(ipc, method, params, false);
|
|
344
|
+
};
|
|
345
|
+
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
346
|
+
return invokeHelper(ipc, method, params, true);
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const commands = Object.create(null);
|
|
350
|
+
const register = commandMap => {
|
|
351
|
+
Object.assign(commands, commandMap);
|
|
352
|
+
};
|
|
353
|
+
const getCommand = key => {
|
|
354
|
+
return commands[key];
|
|
355
|
+
};
|
|
356
|
+
const execute = (command, ...args) => {
|
|
357
|
+
const fn = getCommand(command);
|
|
358
|
+
if (!fn) {
|
|
359
|
+
throw new Error(`command not found ${command}`);
|
|
360
|
+
}
|
|
361
|
+
return fn(...args);
|
|
346
362
|
};
|
|
347
363
|
|
|
348
364
|
const getData$1 = event => {
|
|
349
365
|
return event.data;
|
|
350
366
|
};
|
|
367
|
+
const attachEvents = that => {
|
|
368
|
+
const handleMessage = (...args) => {
|
|
369
|
+
const data = that.getData(...args);
|
|
370
|
+
that.dispatchEvent(new MessageEvent('message', {
|
|
371
|
+
data
|
|
372
|
+
}));
|
|
373
|
+
};
|
|
374
|
+
that.onMessage(handleMessage);
|
|
375
|
+
const handleClose = event => {
|
|
376
|
+
that.dispatchEvent(new Event('close'));
|
|
377
|
+
};
|
|
378
|
+
that.onClose(handleClose);
|
|
379
|
+
};
|
|
380
|
+
class Ipc extends EventTarget {
|
|
381
|
+
constructor(rawIpc) {
|
|
382
|
+
super();
|
|
383
|
+
this._rawIpc = rawIpc;
|
|
384
|
+
attachEvents(this);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
const readyMessage = 'ready';
|
|
351
388
|
const walkValue = (value, transferrables, isTransferrable) => {
|
|
352
389
|
if (!value) {
|
|
353
390
|
return;
|
|
@@ -398,35 +435,14 @@ const getTransferrables = value => {
|
|
|
398
435
|
walkValue(value, transferrables, isTransferrable);
|
|
399
436
|
return transferrables;
|
|
400
437
|
};
|
|
401
|
-
const
|
|
402
|
-
const handleMessage = (...args) => {
|
|
403
|
-
const data = that.getData(...args);
|
|
404
|
-
that.dispatchEvent(new MessageEvent('message', {
|
|
405
|
-
data
|
|
406
|
-
}));
|
|
407
|
-
};
|
|
408
|
-
that.onMessage(handleMessage);
|
|
409
|
-
const handleClose = event => {
|
|
410
|
-
that.dispatchEvent(new Event('close'));
|
|
411
|
-
};
|
|
412
|
-
that.onClose(handleClose);
|
|
413
|
-
};
|
|
414
|
-
class Ipc extends EventTarget {
|
|
415
|
-
constructor(rawIpc) {
|
|
416
|
-
super();
|
|
417
|
-
this._rawIpc = rawIpc;
|
|
418
|
-
attachEvents(this);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
const readyMessage = 'ready';
|
|
422
|
-
const listen$4 = () => {
|
|
438
|
+
const listen$2 = () => {
|
|
423
439
|
// @ts-ignore
|
|
424
440
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
425
441
|
throw new TypeError('module is not in web worker scope');
|
|
426
442
|
}
|
|
427
443
|
return globalThis;
|
|
428
444
|
};
|
|
429
|
-
const signal$
|
|
445
|
+
const signal$2 = global => {
|
|
430
446
|
global.postMessage(readyMessage);
|
|
431
447
|
};
|
|
432
448
|
class IpcChildWithModuleWorker extends Ipc {
|
|
@@ -452,7 +468,7 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
452
468
|
this._rawIpc.addEventListener('message', callback);
|
|
453
469
|
}
|
|
454
470
|
}
|
|
455
|
-
const wrap$
|
|
471
|
+
const wrap$5 = global => {
|
|
456
472
|
return new IpcChildWithModuleWorker(global);
|
|
457
473
|
};
|
|
458
474
|
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
@@ -570,10 +586,10 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
570
586
|
};
|
|
571
587
|
const normalizeLine$1 = line => {
|
|
572
588
|
if (line.startsWith('Error: ')) {
|
|
573
|
-
return line.slice(
|
|
589
|
+
return line.slice('Error: '.length);
|
|
574
590
|
}
|
|
575
591
|
if (line.startsWith('VError: ')) {
|
|
576
|
-
return line.slice(
|
|
592
|
+
return line.slice('VError: '.length);
|
|
577
593
|
}
|
|
578
594
|
return line;
|
|
579
595
|
};
|
|
@@ -671,10 +687,10 @@ const waitForFirstMessage = async port => {
|
|
|
671
687
|
// @ts-ignore
|
|
672
688
|
return event.data;
|
|
673
689
|
};
|
|
674
|
-
const listen$
|
|
675
|
-
const parentIpcRaw = listen$
|
|
676
|
-
signal$
|
|
677
|
-
const parentIpc = wrap$
|
|
690
|
+
const listen$1$1 = async () => {
|
|
691
|
+
const parentIpcRaw = listen$2();
|
|
692
|
+
signal$2(parentIpcRaw);
|
|
693
|
+
const parentIpc = wrap$5(parentIpcRaw);
|
|
678
694
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
679
695
|
if (firstMessage.method !== 'initialize') {
|
|
680
696
|
throw new IpcError('unexpected first message');
|
|
@@ -719,19 +735,28 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
|
719
735
|
this._rawIpc.start();
|
|
720
736
|
}
|
|
721
737
|
}
|
|
722
|
-
const wrap$
|
|
738
|
+
const wrap$4 = port => {
|
|
723
739
|
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
724
740
|
};
|
|
725
741
|
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
726
742
|
__proto__: null,
|
|
727
|
-
listen: listen$
|
|
728
|
-
wrap: wrap$
|
|
743
|
+
listen: listen$1$1,
|
|
744
|
+
wrap: wrap$4
|
|
729
745
|
};
|
|
730
746
|
|
|
731
747
|
const createRpc = ipc => {
|
|
732
748
|
const rpc = {
|
|
749
|
+
/**
|
|
750
|
+
* @deprecated
|
|
751
|
+
*/
|
|
752
|
+
send(method, ...params) {
|
|
753
|
+
send(ipc, method, ...params);
|
|
754
|
+
},
|
|
733
755
|
invoke(method, ...params) {
|
|
734
756
|
return invoke$2(ipc, method, ...params);
|
|
757
|
+
},
|
|
758
|
+
invokeAndTransfer(method, ...params) {
|
|
759
|
+
return invokeAndTransfer(ipc, method, ...params);
|
|
735
760
|
}
|
|
736
761
|
};
|
|
737
762
|
return rpc;
|
|
@@ -759,7 +784,7 @@ const listen$1 = async () => {
|
|
|
759
784
|
const ipc = module.wrap(rawIpc);
|
|
760
785
|
return ipc;
|
|
761
786
|
};
|
|
762
|
-
const create$
|
|
787
|
+
const create$1$1 = async ({
|
|
763
788
|
commandMap
|
|
764
789
|
}) => {
|
|
765
790
|
// TODO create a commandMap per rpc instance
|
|
@@ -771,7 +796,7 @@ const create$2 = async ({
|
|
|
771
796
|
};
|
|
772
797
|
const WebWorkerRpcClient = {
|
|
773
798
|
__proto__: null,
|
|
774
|
-
create: create$
|
|
799
|
+
create: create$1$1
|
|
775
800
|
};
|
|
776
801
|
|
|
777
802
|
const clearSearchResults$1 = state => {
|
|
@@ -903,7 +928,8 @@ const create = (uid, x, y, width, height, workspacePath, assetDir) => {
|
|
|
903
928
|
focused: false,
|
|
904
929
|
focusedIndex: -1,
|
|
905
930
|
handleOffset: 0,
|
|
906
|
-
focusSource: User
|
|
931
|
+
focusSource: User,
|
|
932
|
+
preserveCase: false
|
|
907
933
|
};
|
|
908
934
|
set(uid, state, state);
|
|
909
935
|
return state;
|
|
@@ -2635,6 +2661,13 @@ const handleInput = (state, value, inputSource = Script) => {
|
|
|
2635
2661
|
});
|
|
2636
2662
|
};
|
|
2637
2663
|
|
|
2664
|
+
const handleReplaceInput = (state, value, inputSource = Script) => {
|
|
2665
|
+
return handleUpdate(state, {
|
|
2666
|
+
replacement: value,
|
|
2667
|
+
inputSource
|
|
2668
|
+
});
|
|
2669
|
+
};
|
|
2670
|
+
|
|
2638
2671
|
const first = () => {
|
|
2639
2672
|
return 0;
|
|
2640
2673
|
};
|
|
@@ -3061,46 +3094,6 @@ const doRender = uid => {
|
|
|
3061
3094
|
return commands;
|
|
3062
3095
|
};
|
|
3063
3096
|
|
|
3064
|
-
const getReplaceAllConfirmText = (matchCount, fileCount, replacement) => {
|
|
3065
|
-
if (matchCount === 1) {
|
|
3066
|
-
if (replacement) {
|
|
3067
|
-
return confirmReplaceOneOccurrenceInOneFile(replacement);
|
|
3068
|
-
}
|
|
3069
|
-
return confirmReplaceOneOccurrenceInOneFileNoValue();
|
|
3070
|
-
}
|
|
3071
|
-
if (fileCount === 1) {
|
|
3072
|
-
if (replacement) {
|
|
3073
|
-
return confirmReplaceManyOccurrencesInOneFile(matchCount, replacement);
|
|
3074
|
-
}
|
|
3075
|
-
return confirmReplaceManyOccurrencesInOneFileNoValue(matchCount);
|
|
3076
|
-
}
|
|
3077
|
-
if (replacement) {
|
|
3078
|
-
return confirmReplaceManyOccurrencesInManyFiles(matchCount, fileCount, replacement);
|
|
3079
|
-
}
|
|
3080
|
-
return confirmReplaceManyOccurrencesInManyFilesNoValue(matchCount, fileCount);
|
|
3081
|
-
};
|
|
3082
|
-
|
|
3083
|
-
const replaceAllAndPrompt = async (workspacePath, items, replacement, matchCount, fileCount) => {
|
|
3084
|
-
string(workspacePath);
|
|
3085
|
-
array(items);
|
|
3086
|
-
string(replacement);
|
|
3087
|
-
number(matchCount);
|
|
3088
|
-
number(fileCount);
|
|
3089
|
-
const confirmTitle = replaceAll$1();
|
|
3090
|
-
const confirmAccept = replace();
|
|
3091
|
-
const confirmText = getReplaceAllConfirmText(matchCount, fileCount, replacement);
|
|
3092
|
-
const shouldReplace = await invoke$1('ConfirmPrompt.prompt', confirmText, {
|
|
3093
|
-
title: confirmTitle,
|
|
3094
|
-
confirmMessage: confirmAccept
|
|
3095
|
-
});
|
|
3096
|
-
if (!shouldReplace) {
|
|
3097
|
-
return false;
|
|
3098
|
-
}
|
|
3099
|
-
// TODO
|
|
3100
|
-
// await TextSearchReplaceAll.replaceAll(workspacePath, items, replacement)
|
|
3101
|
-
return true;
|
|
3102
|
-
};
|
|
3103
|
-
|
|
3104
3097
|
const getBulkReplacementEdits = (workspacePath, matches) => {
|
|
3105
3098
|
string(workspacePath);
|
|
3106
3099
|
array(matches);
|
|
@@ -3141,6 +3134,46 @@ const replaceAll = async (workspacePath, items, replacement) => {
|
|
|
3141
3134
|
await invoke$1('BulkReplacement.applyBulkReplacement', files, ranges, replacement);
|
|
3142
3135
|
};
|
|
3143
3136
|
|
|
3137
|
+
const getReplaceAllConfirmText = (matchCount, fileCount, replacement) => {
|
|
3138
|
+
if (matchCount === 1) {
|
|
3139
|
+
if (replacement) {
|
|
3140
|
+
return confirmReplaceOneOccurrenceInOneFile(replacement);
|
|
3141
|
+
}
|
|
3142
|
+
return confirmReplaceOneOccurrenceInOneFileNoValue();
|
|
3143
|
+
}
|
|
3144
|
+
if (fileCount === 1) {
|
|
3145
|
+
if (replacement) {
|
|
3146
|
+
return confirmReplaceManyOccurrencesInOneFile(matchCount, replacement);
|
|
3147
|
+
}
|
|
3148
|
+
return confirmReplaceManyOccurrencesInOneFileNoValue(matchCount);
|
|
3149
|
+
}
|
|
3150
|
+
if (replacement) {
|
|
3151
|
+
return confirmReplaceManyOccurrencesInManyFiles(matchCount, fileCount, replacement);
|
|
3152
|
+
}
|
|
3153
|
+
return confirmReplaceManyOccurrencesInManyFilesNoValue(matchCount, fileCount);
|
|
3154
|
+
};
|
|
3155
|
+
|
|
3156
|
+
const replaceAllAndPrompt = async (workspacePath, items, replacement, matchCount, fileCount) => {
|
|
3157
|
+
string(workspacePath);
|
|
3158
|
+
array(items);
|
|
3159
|
+
string(replacement);
|
|
3160
|
+
number(matchCount);
|
|
3161
|
+
number(fileCount);
|
|
3162
|
+
const confirmTitle = replaceAll$1();
|
|
3163
|
+
const confirmAccept = replace();
|
|
3164
|
+
const confirmText = getReplaceAllConfirmText(matchCount, fileCount, replacement);
|
|
3165
|
+
const shouldReplace = await invoke$1('ConfirmPrompt.prompt', confirmText, {
|
|
3166
|
+
title: confirmTitle,
|
|
3167
|
+
confirmMessage: confirmAccept
|
|
3168
|
+
});
|
|
3169
|
+
if (!shouldReplace) {
|
|
3170
|
+
return false;
|
|
3171
|
+
}
|
|
3172
|
+
// TODO
|
|
3173
|
+
// await TextSearchReplaceAll.replaceAll(workspacePath, items, replacement)
|
|
3174
|
+
return true;
|
|
3175
|
+
};
|
|
3176
|
+
|
|
3144
3177
|
const saveState = uid => {
|
|
3145
3178
|
const {
|
|
3146
3179
|
newState
|
|
@@ -3264,6 +3297,36 @@ const submit = state => {
|
|
|
3264
3297
|
});
|
|
3265
3298
|
};
|
|
3266
3299
|
|
|
3300
|
+
const toggleMatchCase = state => {
|
|
3301
|
+
const {
|
|
3302
|
+
matchCase
|
|
3303
|
+
} = state;
|
|
3304
|
+
return {
|
|
3305
|
+
...state,
|
|
3306
|
+
matchCase: !matchCase
|
|
3307
|
+
};
|
|
3308
|
+
};
|
|
3309
|
+
|
|
3310
|
+
const toggleMatchWholeWord = state => {
|
|
3311
|
+
const {
|
|
3312
|
+
matchWholeWord
|
|
3313
|
+
} = state;
|
|
3314
|
+
return {
|
|
3315
|
+
...state,
|
|
3316
|
+
matchWholeWord: !matchWholeWord
|
|
3317
|
+
};
|
|
3318
|
+
};
|
|
3319
|
+
|
|
3320
|
+
const togglePreserveCase = state => {
|
|
3321
|
+
const {
|
|
3322
|
+
preserveCase
|
|
3323
|
+
} = state;
|
|
3324
|
+
return {
|
|
3325
|
+
...state,
|
|
3326
|
+
preserveCase: !preserveCase
|
|
3327
|
+
};
|
|
3328
|
+
};
|
|
3329
|
+
|
|
3267
3330
|
const toggleReplace = state => {
|
|
3268
3331
|
const {
|
|
3269
3332
|
replaceExpanded
|
|
@@ -3274,6 +3337,16 @@ const toggleReplace = state => {
|
|
|
3274
3337
|
};
|
|
3275
3338
|
};
|
|
3276
3339
|
|
|
3340
|
+
const toggleUseRegularExpression = state => {
|
|
3341
|
+
const {
|
|
3342
|
+
useRegularExpression
|
|
3343
|
+
} = state;
|
|
3344
|
+
return {
|
|
3345
|
+
...state,
|
|
3346
|
+
useRegularExpression: !useRegularExpression
|
|
3347
|
+
};
|
|
3348
|
+
};
|
|
3349
|
+
|
|
3277
3350
|
const Keyboard = -1;
|
|
3278
3351
|
|
|
3279
3352
|
const show = async (x, y, id, ...args) => {
|
|
@@ -3350,16 +3423,21 @@ const commandMap = {
|
|
|
3350
3423
|
'TextSearch.handleFocusIn': wrapCommand(handleFocusIn),
|
|
3351
3424
|
'TextSearch.handleIconThemeChange': wrapCommand(handleIconThemeChange),
|
|
3352
3425
|
'TextSearch.handleInput': wrapCommand(handleInput),
|
|
3426
|
+
'TextSearch.handleReplaceInput': wrapCommand(handleReplaceInput),
|
|
3353
3427
|
'TextSearch.handleScrollBarCaptureLost': wrapCommand(handleScrollBarCaptureLost),
|
|
3354
3428
|
'TextSearch.handleScrollBarClick': wrapCommand(handleScrollBarClick),
|
|
3355
3429
|
'TextSearch.handleScrollBarMove': wrapCommand(handleScrollBarMove),
|
|
3356
3430
|
'TextSearch.handleWheel': wrapCommand(handleWheel),
|
|
3357
3431
|
'TextSearch.loadContent': wrapCommand(loadContent),
|
|
3358
3432
|
'TextSearch.refresh': wrapCommand(refresh),
|
|
3359
|
-
'TextSearch.replaceAllAndPrompt': wrapCommand(replaceAllAndPrompt),
|
|
3360
3433
|
'TextSearch.replaceAll': wrapCommand(replaceAll),
|
|
3434
|
+
'TextSearch.replaceAllAndPrompt': wrapCommand(replaceAllAndPrompt),
|
|
3361
3435
|
'TextSearch.submit': wrapCommand(submit),
|
|
3436
|
+
'TextSearch.toggleMatchCase': wrapCommand(toggleMatchCase),
|
|
3437
|
+
'TextSearch.toggleMatchWholeWord': wrapCommand(toggleMatchWholeWord),
|
|
3438
|
+
'TextSearch.togglePreserveCase': wrapCommand(togglePreserveCase),
|
|
3362
3439
|
'TextSearch.toggleReplace': wrapCommand(toggleReplace),
|
|
3440
|
+
'TextSearch.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression),
|
|
3363
3441
|
// not wrapped
|
|
3364
3442
|
'TextSearch.create': create,
|
|
3365
3443
|
'TextSearch.render': doRender,
|