@lvce-editor/quick-pick-worker 4.1.0 → 4.2.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/quickPickWorkerMain.js +111 -20
- package/package.json +1 -1
|
@@ -1290,6 +1290,18 @@ const toCommandId = key => {
|
|
|
1290
1290
|
const create$2 = () => {
|
|
1291
1291
|
const states = Object.create(null);
|
|
1292
1292
|
const commandMapRef = {};
|
|
1293
|
+
const updateState = (uid, updater) => {
|
|
1294
|
+
const current = states[uid];
|
|
1295
|
+
const updatedState = updater(current.newState);
|
|
1296
|
+
if (updatedState !== current.newState) {
|
|
1297
|
+
states[uid] = {
|
|
1298
|
+
newState: updatedState,
|
|
1299
|
+
oldState: current.oldState,
|
|
1300
|
+
scheduledState: updatedState
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
return Promise.resolve(updatedState);
|
|
1304
|
+
};
|
|
1293
1305
|
return {
|
|
1294
1306
|
clear() {
|
|
1295
1307
|
for (const key of Object.keys(states)) {
|
|
@@ -1298,13 +1310,13 @@ const create$2 = () => {
|
|
|
1298
1310
|
},
|
|
1299
1311
|
diff(uid, modules, numbers) {
|
|
1300
1312
|
const {
|
|
1301
|
-
|
|
1302
|
-
|
|
1313
|
+
oldState,
|
|
1314
|
+
scheduledState
|
|
1303
1315
|
} = states[uid];
|
|
1304
1316
|
const diffResult = [];
|
|
1305
1317
|
for (let i = 0; i < modules.length; i++) {
|
|
1306
1318
|
const fn = modules[i];
|
|
1307
|
-
if (!fn(oldState,
|
|
1319
|
+
if (!fn(oldState, scheduledState)) {
|
|
1308
1320
|
diffResult.push(numbers[i]);
|
|
1309
1321
|
}
|
|
1310
1322
|
}
|
|
@@ -1322,19 +1334,28 @@ const create$2 = () => {
|
|
|
1322
1334
|
return ids;
|
|
1323
1335
|
},
|
|
1324
1336
|
getKeys() {
|
|
1325
|
-
return Object.keys(states).map(
|
|
1326
|
-
return Number.parseFloat(key);
|
|
1327
|
-
});
|
|
1337
|
+
return Object.keys(states).map(Number);
|
|
1328
1338
|
},
|
|
1329
1339
|
registerCommands(commandMap) {
|
|
1330
1340
|
Object.assign(commandMapRef, commandMap);
|
|
1331
1341
|
},
|
|
1332
|
-
set(uid, oldState, newState) {
|
|
1342
|
+
set(uid, oldState, newState, scheduledState) {
|
|
1333
1343
|
states[uid] = {
|
|
1334
1344
|
newState,
|
|
1335
|
-
oldState
|
|
1345
|
+
oldState,
|
|
1346
|
+
scheduledState: scheduledState ?? newState
|
|
1336
1347
|
};
|
|
1337
1348
|
},
|
|
1349
|
+
wrapAsyncCommand(fn) {
|
|
1350
|
+
const wrapped = async (uid, ...args) => {
|
|
1351
|
+
const context = {
|
|
1352
|
+
getState: () => states[uid].newState,
|
|
1353
|
+
updateState: updater => updateState(uid, updater)
|
|
1354
|
+
};
|
|
1355
|
+
await fn(context, ...args);
|
|
1356
|
+
};
|
|
1357
|
+
return wrapped;
|
|
1358
|
+
},
|
|
1338
1359
|
wrapCommand(fn) {
|
|
1339
1360
|
const wrapped = async (uid, ...args) => {
|
|
1340
1361
|
const {
|
|
@@ -1352,7 +1373,8 @@ const create$2 = () => {
|
|
|
1352
1373
|
};
|
|
1353
1374
|
states[uid] = {
|
|
1354
1375
|
newState: latestNew,
|
|
1355
|
-
oldState: latestOld.oldState
|
|
1376
|
+
oldState: latestOld.oldState,
|
|
1377
|
+
scheduledState: latestNew
|
|
1356
1378
|
};
|
|
1357
1379
|
};
|
|
1358
1380
|
return wrapped;
|
|
@@ -1389,7 +1411,8 @@ const create$2 = () => {
|
|
|
1389
1411
|
};
|
|
1390
1412
|
states[uid] = {
|
|
1391
1413
|
newState: latestNew,
|
|
1392
|
-
oldState: latestOld.oldState
|
|
1414
|
+
oldState: latestOld.oldState,
|
|
1415
|
+
scheduledState: latestNew
|
|
1393
1416
|
};
|
|
1394
1417
|
return {
|
|
1395
1418
|
error
|
|
@@ -1406,6 +1429,7 @@ const {
|
|
|
1406
1429
|
getCommandIds,
|
|
1407
1430
|
registerCommands,
|
|
1408
1431
|
set: set$1,
|
|
1432
|
+
wrapAsyncCommand,
|
|
1409
1433
|
wrapCommand
|
|
1410
1434
|
} = create$2();
|
|
1411
1435
|
|
|
@@ -3096,6 +3120,10 @@ const getQuickPickSubProviderId = (id, prefix) => {
|
|
|
3096
3120
|
}
|
|
3097
3121
|
};
|
|
3098
3122
|
|
|
3123
|
+
const requestVersions = new Map();
|
|
3124
|
+
const requestVersionGenerator = {
|
|
3125
|
+
value: 0
|
|
3126
|
+
};
|
|
3099
3127
|
const isQuickInput = args => {
|
|
3100
3128
|
const options = args.at(-1);
|
|
3101
3129
|
return options?.mode === 'quickInput';
|
|
@@ -3146,6 +3174,51 @@ const setValue = async (state, newValue) => {
|
|
|
3146
3174
|
value: newValue
|
|
3147
3175
|
};
|
|
3148
3176
|
};
|
|
3177
|
+
const setValueWithContext = async (context, newValue) => {
|
|
3178
|
+
const state = context.getState();
|
|
3179
|
+
if (state.value === newValue) {
|
|
3180
|
+
return;
|
|
3181
|
+
}
|
|
3182
|
+
const requestVersion = ++requestVersionGenerator.value;
|
|
3183
|
+
requestVersions.set(state.uid, requestVersion);
|
|
3184
|
+
const result = await setValue(state, newValue);
|
|
3185
|
+
await context.updateState(latestState => {
|
|
3186
|
+
if (requestVersions.get(latestState.uid) !== requestVersion) {
|
|
3187
|
+
return latestState;
|
|
3188
|
+
}
|
|
3189
|
+
return {
|
|
3190
|
+
...latestState,
|
|
3191
|
+
fileIconCache: result.fileIconCache,
|
|
3192
|
+
finalDeltaY: result.finalDeltaY,
|
|
3193
|
+
focusedIndex: result.focusedIndex,
|
|
3194
|
+
icons: result.icons,
|
|
3195
|
+
inputSource: result.inputSource,
|
|
3196
|
+
items: result.items,
|
|
3197
|
+
picks: result.picks,
|
|
3198
|
+
value: result.value
|
|
3199
|
+
};
|
|
3200
|
+
});
|
|
3201
|
+
if (requestVersions.get(state.uid) === requestVersion) {
|
|
3202
|
+
requestVersions.delete(state.uid);
|
|
3203
|
+
}
|
|
3204
|
+
};
|
|
3205
|
+
|
|
3206
|
+
const handleInputWithContext = async (context, newValue, cursorOffset, inputSource = Script) => {
|
|
3207
|
+
const state = context.getState();
|
|
3208
|
+
if (state.value !== newValue) {
|
|
3209
|
+
await setValueWithContext(context, newValue);
|
|
3210
|
+
}
|
|
3211
|
+
await context.updateState(latestState => {
|
|
3212
|
+
if (latestState.value !== newValue) {
|
|
3213
|
+
return latestState;
|
|
3214
|
+
}
|
|
3215
|
+
return {
|
|
3216
|
+
...latestState,
|
|
3217
|
+
cursorOffset,
|
|
3218
|
+
inputSource
|
|
3219
|
+
};
|
|
3220
|
+
});
|
|
3221
|
+
};
|
|
3149
3222
|
|
|
3150
3223
|
// TODO when user types letters -> no need to query provider again -> just filter existing results
|
|
3151
3224
|
const handleInput = async (state, newValue, cursorOffset, inputSource = Script) => {
|
|
@@ -3388,7 +3461,7 @@ const parseArgs = (subId, args) => {
|
|
|
3388
3461
|
placeholder: last.placeholder ? String(last.placeholder) : ''
|
|
3389
3462
|
};
|
|
3390
3463
|
};
|
|
3391
|
-
const
|
|
3464
|
+
const getLoadedState = async state => {
|
|
3392
3465
|
const {
|
|
3393
3466
|
args,
|
|
3394
3467
|
assetDir,
|
|
@@ -3421,7 +3494,6 @@ const loadContent = async state => {
|
|
|
3421
3494
|
const finalDeltaY = getFinalDeltaY(listHeight, itemHeight, items.length);
|
|
3422
3495
|
const parsedArgs = parseArgs(subId, args);
|
|
3423
3496
|
const finalValue = parsedArgs.initialValue || value;
|
|
3424
|
-
notifyVisible();
|
|
3425
3497
|
return {
|
|
3426
3498
|
...state,
|
|
3427
3499
|
args,
|
|
@@ -3443,6 +3515,30 @@ const loadContent = async state => {
|
|
|
3443
3515
|
value: finalValue
|
|
3444
3516
|
};
|
|
3445
3517
|
};
|
|
3518
|
+
const loadContentWithContext = async context => {
|
|
3519
|
+
const state = context.getState();
|
|
3520
|
+
const loadedState = await getLoadedState(state);
|
|
3521
|
+
await context.updateState(latestState => ({
|
|
3522
|
+
...latestState,
|
|
3523
|
+
cursorOffset: loadedState.cursorOffset,
|
|
3524
|
+
fileIconCache: loadedState.fileIconCache,
|
|
3525
|
+
finalDeltaY: loadedState.finalDeltaY,
|
|
3526
|
+
focused: loadedState.focused,
|
|
3527
|
+
focusedIndex: loadedState.focusedIndex,
|
|
3528
|
+
icons: loadedState.icons,
|
|
3529
|
+
initial: loadedState.initial,
|
|
3530
|
+
inputSource: loadedState.inputSource,
|
|
3531
|
+
items: loadedState.items,
|
|
3532
|
+
maxLineY: loadedState.maxLineY,
|
|
3533
|
+
minLineY: loadedState.minLineY,
|
|
3534
|
+
picks: loadedState.picks,
|
|
3535
|
+
placeholder: loadedState.placeholder,
|
|
3536
|
+
providerId: loadedState.providerId,
|
|
3537
|
+
state: loadedState.state,
|
|
3538
|
+
value: loadedState.value
|
|
3539
|
+
}));
|
|
3540
|
+
notifyVisible();
|
|
3541
|
+
};
|
|
3446
3542
|
|
|
3447
3543
|
const SetCursorOffset = 'setCursorOffset';
|
|
3448
3544
|
const SetFocusedIndex = 'setFocusedIndex';
|
|
@@ -3913,7 +4009,6 @@ const Viewlet = 'Viewlet';
|
|
|
3913
4009
|
|
|
3914
4010
|
const HandleWheel = 'handleWheel';
|
|
3915
4011
|
const HandlePointerDown = 'handlePointerDown';
|
|
3916
|
-
const HandleBeforeInput = 'handleBeforeInput';
|
|
3917
4012
|
const HandleBlur = 'handleBlur';
|
|
3918
4013
|
const HandleFocus = 'handleFocus';
|
|
3919
4014
|
const HandleInput = 'handleInput';
|
|
@@ -3937,7 +4032,6 @@ const getQuickPickInputVirtualDom = (placeholder = '') => {
|
|
|
3937
4032
|
className: InputBox,
|
|
3938
4033
|
inputType: 'text',
|
|
3939
4034
|
name: QuickPickInput,
|
|
3940
|
-
onBeforeInput: HandleBeforeInput,
|
|
3941
4035
|
onBlur: HandleBlur,
|
|
3942
4036
|
onFocus: HandleFocus,
|
|
3943
4037
|
onInput: HandleInput,
|
|
@@ -4231,9 +4325,6 @@ const renderEventListeners = () => {
|
|
|
4231
4325
|
}, {
|
|
4232
4326
|
name: HandleBlur,
|
|
4233
4327
|
params: ['handleBlur']
|
|
4234
|
-
}, {
|
|
4235
|
-
name: HandleBeforeInput,
|
|
4236
|
-
params: ['handleBeforeInput']
|
|
4237
4328
|
}, {
|
|
4238
4329
|
name: HandleInput,
|
|
4239
4330
|
params: ['handleInput', 'event.target.value']
|
|
@@ -4341,21 +4432,21 @@ const commandMap = {
|
|
|
4341
4432
|
'QuickPick.handleBlur': wrapCommand(handleBlur),
|
|
4342
4433
|
'QuickPick.handleClickAt': wrapCommand(handleClickAt),
|
|
4343
4434
|
'QuickPick.handleFocus': wrapCommand(handleFocus),
|
|
4344
|
-
'QuickPick.handleInput':
|
|
4435
|
+
'QuickPick.handleInput': wrapAsyncCommand(handleInputWithContext),
|
|
4345
4436
|
'QuickPick.handleMessagePort': handleMessagePort,
|
|
4346
4437
|
'QuickPick.handleScrollBarPointerDown': wrapCommand(handleScrollBarPointerDown),
|
|
4347
4438
|
'QuickPick.handleScrollBarPointerMove': wrapCommand(handleScrollBarPointerMove),
|
|
4348
4439
|
'QuickPick.handleScrollBarPointerUp': wrapCommand(handleScrollBarPointerUp),
|
|
4349
4440
|
'QuickPick.handleWheel': wrapCommand(handleWheel),
|
|
4350
4441
|
'QuickPick.initialize': initialize,
|
|
4351
|
-
'QuickPick.loadContent':
|
|
4442
|
+
'QuickPick.loadContent': wrapAsyncCommand(loadContentWithContext),
|
|
4352
4443
|
'QuickPick.render2': render2,
|
|
4353
4444
|
'QuickPick.renderEventListeners': renderEventListeners,
|
|
4354
4445
|
'QuickPick.selectCurrentIndex': wrapCommand(selectCurrentIndex),
|
|
4355
4446
|
'QuickPick.selectIndex': wrapCommand(selectIndex),
|
|
4356
4447
|
'QuickPick.selectItem': wrapCommand(selectItem),
|
|
4357
4448
|
'QuickPick.setDeltaY': wrapCommand(setDeltaY),
|
|
4358
|
-
'QuickPick.setValue':
|
|
4449
|
+
'QuickPick.setValue': wrapAsyncCommand(setValueWithContext),
|
|
4359
4450
|
'QuickPick.showQuickInput': showQuickInput,
|
|
4360
4451
|
'QuickPick.showQuickPick': showQuickPick,
|
|
4361
4452
|
'QuickPick.waitUntilVisible': waitUntilVisible
|