@lvce-editor/quick-pick-worker 1.1.0 → 2.0.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 +156 -146
- package/package.json +2 -5
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
const EditorWorker = 99;
|
|
2
|
-
const RendererWorker = 1;
|
|
3
|
-
|
|
4
1
|
const normalizeLine = line => {
|
|
5
2
|
if (line.startsWith('Error: ')) {
|
|
6
3
|
return line.slice('Error: '.length);
|
|
@@ -207,6 +204,21 @@ const create$b = rpcId => {
|
|
|
207
204
|
};
|
|
208
205
|
};
|
|
209
206
|
|
|
207
|
+
const Div = 4;
|
|
208
|
+
const Input = 6;
|
|
209
|
+
const Span = 8;
|
|
210
|
+
const Text = 12;
|
|
211
|
+
const Img = 17;
|
|
212
|
+
const Reference = 100;
|
|
213
|
+
|
|
214
|
+
const EditorWorker = 99;
|
|
215
|
+
const RendererWorker = 1;
|
|
216
|
+
|
|
217
|
+
const SetDom2 = 'Viewlet.setDom2';
|
|
218
|
+
const SetPatches = 'Viewlet.setPatches';
|
|
219
|
+
|
|
220
|
+
const FocusQuickPickInput = 20;
|
|
221
|
+
|
|
210
222
|
const {
|
|
211
223
|
invoke: invoke$2,
|
|
212
224
|
set: set$2
|
|
@@ -463,6 +475,7 @@ const create$8 = (uid, uri, listItemHeight, x, y, width, height, platform, args,
|
|
|
463
475
|
cursorOffset: 0,
|
|
464
476
|
height: 300,
|
|
465
477
|
icons: [],
|
|
478
|
+
initial: true,
|
|
466
479
|
maxVisibleItems: 12,
|
|
467
480
|
picks: [],
|
|
468
481
|
recentPickIds: Object.create(null),
|
|
@@ -522,7 +535,7 @@ const isEqual = (oldState, newState) => {
|
|
|
522
535
|
};
|
|
523
536
|
|
|
524
537
|
const modules = [isEqual$2, isEqual$1, isEqual, isEqual$3, isEqual$4];
|
|
525
|
-
const numbers = [Height,
|
|
538
|
+
const numbers = [Height, RenderIncremental, diffType, RenderFocusedIndex, RenderFocus];
|
|
526
539
|
|
|
527
540
|
const diff = (oldState, newState) => {
|
|
528
541
|
const diffResult = [];
|
|
@@ -766,11 +779,6 @@ const focusPrevious = state => {
|
|
|
766
779
|
return focusIndex(state, previousIndex);
|
|
767
780
|
};
|
|
768
781
|
|
|
769
|
-
const SetDom2 = 'Viewlet.setDom2';
|
|
770
|
-
const SetPatches = 'Viewlet.setPatches';
|
|
771
|
-
|
|
772
|
-
const FocusQuickPickInput = 20;
|
|
773
|
-
|
|
774
782
|
const Enter = 3;
|
|
775
783
|
const Escape = 8;
|
|
776
784
|
const PageUp = 10;
|
|
@@ -3160,6 +3168,7 @@ const loadContent = async state => {
|
|
|
3160
3168
|
focused: true,
|
|
3161
3169
|
focusedIndex: 0,
|
|
3162
3170
|
icons,
|
|
3171
|
+
initial: false,
|
|
3163
3172
|
inputSource: Script,
|
|
3164
3173
|
items,
|
|
3165
3174
|
maxLineY,
|
|
@@ -3179,141 +3188,27 @@ const executeCallback = id => {
|
|
|
3179
3188
|
fn();
|
|
3180
3189
|
};
|
|
3181
3190
|
|
|
3182
|
-
const getVisible$1 = (items, minLineY, maxLineY, icons) => {
|
|
3183
|
-
const range = items.slice(minLineY, maxLineY);
|
|
3184
|
-
const protoVisibleItems = range.map((item, index) => {
|
|
3185
|
-
return {
|
|
3186
|
-
...item,
|
|
3187
|
-
fileIcon: icons[index]
|
|
3188
|
-
};
|
|
3189
|
-
});
|
|
3190
|
-
return protoVisibleItems;
|
|
3191
|
-
};
|
|
3192
|
-
|
|
3193
|
-
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
3194
|
-
if (size >= contentSize) {
|
|
3195
|
-
return 0;
|
|
3196
|
-
}
|
|
3197
|
-
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
3198
|
-
};
|
|
3199
|
-
|
|
3200
|
-
const emptyHighlightSections = [];
|
|
3201
|
-
|
|
3202
|
-
const getHighlightSections = (highlights, label) => {
|
|
3203
|
-
if (highlights.length === 0) {
|
|
3204
|
-
return emptyHighlightSections;
|
|
3205
|
-
}
|
|
3206
|
-
const sections = [];
|
|
3207
|
-
let position = 0;
|
|
3208
|
-
for (let i = 0; i < highlights.length; i += 2) {
|
|
3209
|
-
const highlightStart = highlights[i];
|
|
3210
|
-
const highlightEnd = highlights[i + 1];
|
|
3211
|
-
if (position < highlightStart) {
|
|
3212
|
-
const beforeText = label.slice(position, highlightStart);
|
|
3213
|
-
sections.push({
|
|
3214
|
-
highlighted: false,
|
|
3215
|
-
text: beforeText
|
|
3216
|
-
});
|
|
3217
|
-
}
|
|
3218
|
-
const highlightText = label.slice(highlightStart, highlightEnd);
|
|
3219
|
-
sections.push({
|
|
3220
|
-
highlighted: true,
|
|
3221
|
-
text: highlightText
|
|
3222
|
-
});
|
|
3223
|
-
position = highlightEnd;
|
|
3224
|
-
}
|
|
3225
|
-
if (position < label.length) {
|
|
3226
|
-
const afterText = label.slice(position);
|
|
3227
|
-
sections.push({
|
|
3228
|
-
highlighted: false,
|
|
3229
|
-
text: afterText
|
|
3230
|
-
});
|
|
3231
|
-
}
|
|
3232
|
-
return sections;
|
|
3233
|
-
};
|
|
3234
|
-
|
|
3235
|
-
const getVisible = (setSize, protoVisibleItems, minLineY, focusedIndex) => {
|
|
3236
|
-
const visibleItems = protoVisibleItems.map((visibleItem, i) => {
|
|
3237
|
-
const highlights = visibleItem.matches.slice(1);
|
|
3238
|
-
const sections = getHighlightSections(highlights, visibleItem.label);
|
|
3239
|
-
return {
|
|
3240
|
-
...visibleItem,
|
|
3241
|
-
highlights: sections,
|
|
3242
|
-
isActive: i === focusedIndex,
|
|
3243
|
-
posInSet: minLineY + i + 1,
|
|
3244
|
-
setSize
|
|
3245
|
-
};
|
|
3246
|
-
});
|
|
3247
|
-
return visibleItems;
|
|
3248
|
-
};
|
|
3249
|
-
|
|
3250
|
-
const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
|
|
3251
|
-
const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
|
|
3252
|
-
return scrollBarOffset;
|
|
3253
|
-
};
|
|
3254
|
-
const getScrollBarY = getScrollBarOffset;
|
|
3255
|
-
|
|
3256
|
-
const createQuickPickViewModel = (oldState, newState) => {
|
|
3257
|
-
const {
|
|
3258
|
-
cursorOffset,
|
|
3259
|
-
deltaY,
|
|
3260
|
-
finalDeltaY,
|
|
3261
|
-
focused,
|
|
3262
|
-
focusedIndex,
|
|
3263
|
-
headerHeight,
|
|
3264
|
-
height,
|
|
3265
|
-
icons,
|
|
3266
|
-
itemHeight,
|
|
3267
|
-
items,
|
|
3268
|
-
maxLineY,
|
|
3269
|
-
minimumSliderSize,
|
|
3270
|
-
minLineY,
|
|
3271
|
-
uid,
|
|
3272
|
-
value
|
|
3273
|
-
} = newState;
|
|
3274
|
-
const protoVisibleItems = getVisible$1(items, minLineY, maxLineY, icons);
|
|
3275
|
-
const visibleItems = getVisible(items.length, protoVisibleItems, minLineY, focusedIndex);
|
|
3276
|
-
const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
|
|
3277
|
-
const newFocusedIndex = focusedIndex - minLineY;
|
|
3278
|
-
const itemCount = items.length;
|
|
3279
|
-
const listHeight = getListHeight(itemCount, itemHeight, height);
|
|
3280
|
-
const contentHeight = itemCount * itemHeight;
|
|
3281
|
-
const scrollBarHeight = getScrollBarSize(listHeight, contentHeight, minimumSliderSize);
|
|
3282
|
-
const scrollBarY = getScrollBarY(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
|
|
3283
|
-
const roundedScrollBarY = Math.round(scrollBarY);
|
|
3284
|
-
return {
|
|
3285
|
-
cursorOffset,
|
|
3286
|
-
focused,
|
|
3287
|
-
height,
|
|
3288
|
-
newFocusedIndex,
|
|
3289
|
-
oldFocusedIndex,
|
|
3290
|
-
scrollBarHeight,
|
|
3291
|
-
scrollBarTop: roundedScrollBarY,
|
|
3292
|
-
uid,
|
|
3293
|
-
value,
|
|
3294
|
-
visibleItems
|
|
3295
|
-
};
|
|
3296
|
-
};
|
|
3297
|
-
|
|
3298
3191
|
const SetCursorOffset = 'setCursorOffset';
|
|
3299
3192
|
const SetFocusedIndex = 'setFocusedIndex';
|
|
3300
3193
|
const SetItemsHeight = 'setItemsHeight';
|
|
3301
3194
|
|
|
3302
|
-
const renderCursorOffset = newState => {
|
|
3195
|
+
const renderCursorOffset = (_oldState, newState) => {
|
|
3303
3196
|
return ['Viewlet.send', newState.uid, /* method */SetCursorOffset, /* cursorOffset */newState.cursorOffset];
|
|
3304
3197
|
};
|
|
3305
3198
|
|
|
3306
3199
|
const QuickPickInput = 'QuickPickInput';
|
|
3307
3200
|
|
|
3308
|
-
const renderFocus =
|
|
3201
|
+
const renderFocus = (_oldState, _newState) => {
|
|
3309
3202
|
return ['Viewlet.focusElementByName', QuickPickInput];
|
|
3310
3203
|
};
|
|
3311
3204
|
|
|
3312
|
-
const renderFocusedIndex = newState => {
|
|
3313
|
-
|
|
3205
|
+
const renderFocusedIndex = (oldState, newState) => {
|
|
3206
|
+
const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
|
|
3207
|
+
const newFocusedIndex = newState.focusedIndex - newState.minLineY;
|
|
3208
|
+
return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */oldFocusedIndex, /* newFocusedIndex */newFocusedIndex];
|
|
3314
3209
|
};
|
|
3315
3210
|
|
|
3316
|
-
const renderHeight = newState => {
|
|
3211
|
+
const renderHeight = (_oldState, newState) => {
|
|
3317
3212
|
const {
|
|
3318
3213
|
height,
|
|
3319
3214
|
uid
|
|
@@ -3324,13 +3219,6 @@ const renderHeight = newState => {
|
|
|
3324
3219
|
return ['Viewlet.send', uid, /* method */SetItemsHeight, /* height */height];
|
|
3325
3220
|
};
|
|
3326
3221
|
|
|
3327
|
-
const Div = 4;
|
|
3328
|
-
const Input = 6;
|
|
3329
|
-
const Span = 8;
|
|
3330
|
-
const Text = 12;
|
|
3331
|
-
const Img = 17;
|
|
3332
|
-
const Reference = 100;
|
|
3333
|
-
|
|
3334
3222
|
const mergeClassNames = (...classNames) => {
|
|
3335
3223
|
return classNames.filter(Boolean).join(' ');
|
|
3336
3224
|
};
|
|
@@ -3638,6 +3526,122 @@ const diffTree = (oldNodes, newNodes) => {
|
|
|
3638
3526
|
return removeTrailingNavigationPatches(patches);
|
|
3639
3527
|
};
|
|
3640
3528
|
|
|
3529
|
+
const getVisible$1 = (items, minLineY, maxLineY, icons) => {
|
|
3530
|
+
const range = items.slice(minLineY, maxLineY);
|
|
3531
|
+
const protoVisibleItems = range.map((item, index) => {
|
|
3532
|
+
return {
|
|
3533
|
+
...item,
|
|
3534
|
+
fileIcon: icons[index]
|
|
3535
|
+
};
|
|
3536
|
+
});
|
|
3537
|
+
return protoVisibleItems;
|
|
3538
|
+
};
|
|
3539
|
+
|
|
3540
|
+
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
3541
|
+
if (size >= contentSize) {
|
|
3542
|
+
return 0;
|
|
3543
|
+
}
|
|
3544
|
+
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
3545
|
+
};
|
|
3546
|
+
|
|
3547
|
+
const emptyHighlightSections = [];
|
|
3548
|
+
|
|
3549
|
+
const getHighlightSections = (highlights, label) => {
|
|
3550
|
+
if (highlights.length === 0) {
|
|
3551
|
+
return emptyHighlightSections;
|
|
3552
|
+
}
|
|
3553
|
+
const sections = [];
|
|
3554
|
+
let position = 0;
|
|
3555
|
+
for (let i = 0; i < highlights.length; i += 2) {
|
|
3556
|
+
const highlightStart = highlights[i];
|
|
3557
|
+
const highlightEnd = highlights[i + 1];
|
|
3558
|
+
if (position < highlightStart) {
|
|
3559
|
+
const beforeText = label.slice(position, highlightStart);
|
|
3560
|
+
sections.push({
|
|
3561
|
+
highlighted: false,
|
|
3562
|
+
text: beforeText
|
|
3563
|
+
});
|
|
3564
|
+
}
|
|
3565
|
+
const highlightText = label.slice(highlightStart, highlightEnd);
|
|
3566
|
+
sections.push({
|
|
3567
|
+
highlighted: true,
|
|
3568
|
+
text: highlightText
|
|
3569
|
+
});
|
|
3570
|
+
position = highlightEnd;
|
|
3571
|
+
}
|
|
3572
|
+
if (position < label.length) {
|
|
3573
|
+
const afterText = label.slice(position);
|
|
3574
|
+
sections.push({
|
|
3575
|
+
highlighted: false,
|
|
3576
|
+
text: afterText
|
|
3577
|
+
});
|
|
3578
|
+
}
|
|
3579
|
+
return sections;
|
|
3580
|
+
};
|
|
3581
|
+
|
|
3582
|
+
const getVisible = (setSize, protoVisibleItems, minLineY, focusedIndex) => {
|
|
3583
|
+
const visibleItems = protoVisibleItems.map((visibleItem, i) => {
|
|
3584
|
+
const highlights = visibleItem.matches.slice(1);
|
|
3585
|
+
const sections = getHighlightSections(highlights, visibleItem.label);
|
|
3586
|
+
return {
|
|
3587
|
+
...visibleItem,
|
|
3588
|
+
highlights: sections,
|
|
3589
|
+
isActive: i === focusedIndex,
|
|
3590
|
+
posInSet: minLineY + i + 1,
|
|
3591
|
+
setSize
|
|
3592
|
+
};
|
|
3593
|
+
});
|
|
3594
|
+
return visibleItems;
|
|
3595
|
+
};
|
|
3596
|
+
|
|
3597
|
+
const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
|
|
3598
|
+
const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
|
|
3599
|
+
return scrollBarOffset;
|
|
3600
|
+
};
|
|
3601
|
+
const getScrollBarY = getScrollBarOffset;
|
|
3602
|
+
|
|
3603
|
+
const createQuickPickViewModel = (oldState, newState) => {
|
|
3604
|
+
const {
|
|
3605
|
+
cursorOffset,
|
|
3606
|
+
deltaY,
|
|
3607
|
+
finalDeltaY,
|
|
3608
|
+
focused,
|
|
3609
|
+
focusedIndex,
|
|
3610
|
+
headerHeight,
|
|
3611
|
+
height,
|
|
3612
|
+
icons,
|
|
3613
|
+
itemHeight,
|
|
3614
|
+
items,
|
|
3615
|
+
maxLineY,
|
|
3616
|
+
minimumSliderSize,
|
|
3617
|
+
minLineY,
|
|
3618
|
+
uid,
|
|
3619
|
+
value
|
|
3620
|
+
} = newState;
|
|
3621
|
+
const protoVisibleItems = getVisible$1(items, minLineY, maxLineY, icons);
|
|
3622
|
+
const visibleItems = getVisible(items.length, protoVisibleItems, minLineY, focusedIndex);
|
|
3623
|
+
const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
|
|
3624
|
+
const newFocusedIndex = focusedIndex - minLineY;
|
|
3625
|
+
const itemCount = items.length;
|
|
3626
|
+
const listHeight = getListHeight(itemCount, itemHeight, height);
|
|
3627
|
+
const contentHeight = itemCount * itemHeight;
|
|
3628
|
+
const scrollBarHeight = getScrollBarSize(listHeight, contentHeight, minimumSliderSize);
|
|
3629
|
+
const scrollBarY = getScrollBarY(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
|
|
3630
|
+
const roundedScrollBarY = Math.round(scrollBarY);
|
|
3631
|
+
return {
|
|
3632
|
+
cursorOffset,
|
|
3633
|
+
focused,
|
|
3634
|
+
height,
|
|
3635
|
+
newFocusedIndex,
|
|
3636
|
+
oldFocusedIndex,
|
|
3637
|
+
scrollBarHeight,
|
|
3638
|
+
scrollBarTop: roundedScrollBarY,
|
|
3639
|
+
uid,
|
|
3640
|
+
value,
|
|
3641
|
+
visibleItems
|
|
3642
|
+
};
|
|
3643
|
+
};
|
|
3644
|
+
|
|
3641
3645
|
const ComboBox = 'combobox';
|
|
3642
3646
|
const ListBox = 'listbox';
|
|
3643
3647
|
const None = 'none';
|
|
@@ -3858,24 +3862,31 @@ const getQuickPickVirtualDom = (visibleItems, scrollBarHeight, scrollBarTop) =>
|
|
|
3858
3862
|
}, ...getQuickPickItemsVirtualDom(visibleItems), ...getScrollBarVirtualDom(scrollBarHeight, scrollBarTop)];
|
|
3859
3863
|
};
|
|
3860
3864
|
|
|
3861
|
-
const
|
|
3865
|
+
const renderItemsDom = state => {
|
|
3866
|
+
const viewModel = createQuickPickViewModel(state, state);
|
|
3862
3867
|
const {
|
|
3863
3868
|
scrollBarHeight,
|
|
3864
3869
|
scrollBarTop,
|
|
3865
3870
|
visibleItems
|
|
3866
|
-
} =
|
|
3867
|
-
|
|
3871
|
+
} = viewModel;
|
|
3872
|
+
return getQuickPickVirtualDom(visibleItems, scrollBarHeight, scrollBarTop);
|
|
3873
|
+
};
|
|
3874
|
+
const renderItems = (_oldState, newState) => {
|
|
3875
|
+
const dom = renderItemsDom(newState);
|
|
3868
3876
|
return [SetDom2, dom];
|
|
3869
3877
|
};
|
|
3870
3878
|
|
|
3871
|
-
const renderIncremental = newState => {
|
|
3872
|
-
const oldDom =
|
|
3873
|
-
const newDom =
|
|
3879
|
+
const renderIncremental = (oldState, newState) => {
|
|
3880
|
+
const oldDom = renderItemsDom(oldState);
|
|
3881
|
+
const newDom = renderItemsDom(newState);
|
|
3882
|
+
if (oldState.initial) {
|
|
3883
|
+
return [SetDom2, newDom];
|
|
3884
|
+
}
|
|
3874
3885
|
const patches = diffTree(oldDom, newDom);
|
|
3875
3886
|
return [SetPatches, newState.uid, patches];
|
|
3876
3887
|
};
|
|
3877
3888
|
|
|
3878
|
-
const renderValue = newState => {
|
|
3889
|
+
const renderValue = (_oldState, newState) => {
|
|
3879
3890
|
return ['Viewlet.setValueByName', QuickPickInput, /* value */newState.value];
|
|
3880
3891
|
};
|
|
3881
3892
|
|
|
@@ -3902,7 +3913,6 @@ const getRenderer = diffType => {
|
|
|
3902
3913
|
|
|
3903
3914
|
const applyRender = (oldState, newState, diffResult) => {
|
|
3904
3915
|
const commands = [];
|
|
3905
|
-
const viewModel = createQuickPickViewModel(oldState, newState);
|
|
3906
3916
|
for (const item of diffResult) {
|
|
3907
3917
|
if (item === Height) {
|
|
3908
3918
|
continue;
|
|
@@ -3911,7 +3921,7 @@ const applyRender = (oldState, newState, diffResult) => {
|
|
|
3911
3921
|
continue;
|
|
3912
3922
|
}
|
|
3913
3923
|
const fn = getRenderer(item);
|
|
3914
|
-
commands.push(fn(
|
|
3924
|
+
commands.push(fn(oldState, newState));
|
|
3915
3925
|
}
|
|
3916
3926
|
return commands;
|
|
3917
3927
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/quick-pick-worker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/lvce-editor/quick-pick-worker.git"
|
|
@@ -8,8 +8,5 @@
|
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"author": "Lvce Editor",
|
|
10
10
|
"type": "module",
|
|
11
|
-
"main": "dist/quickPickWorkerMain.js"
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"@lvce-editor/constants": "^4.0.0"
|
|
14
|
-
}
|
|
11
|
+
"main": "dist/quickPickWorkerMain.js"
|
|
15
12
|
}
|