@lvce-editor/quick-pick-worker 1.1.0 → 2.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/quickPickWorkerMain.js +157 -148
- 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;
|
|
@@ -2029,8 +2037,7 @@ const handleBeforeInput = (state, inputType, data, selectionStart, selectionEnd)
|
|
|
2029
2037
|
};
|
|
2030
2038
|
|
|
2031
2039
|
const handleBlur = async state => {
|
|
2032
|
-
|
|
2033
|
-
// await CloseWidget.closeWidget(state.uid)
|
|
2040
|
+
await closeWidget(state.uid);
|
|
2034
2041
|
return state;
|
|
2035
2042
|
};
|
|
2036
2043
|
|
|
@@ -3160,6 +3167,7 @@ const loadContent = async state => {
|
|
|
3160
3167
|
focused: true,
|
|
3161
3168
|
focusedIndex: 0,
|
|
3162
3169
|
icons,
|
|
3170
|
+
initial: false,
|
|
3163
3171
|
inputSource: Script,
|
|
3164
3172
|
items,
|
|
3165
3173
|
maxLineY,
|
|
@@ -3179,141 +3187,27 @@ const executeCallback = id => {
|
|
|
3179
3187
|
fn();
|
|
3180
3188
|
};
|
|
3181
3189
|
|
|
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
3190
|
const SetCursorOffset = 'setCursorOffset';
|
|
3299
3191
|
const SetFocusedIndex = 'setFocusedIndex';
|
|
3300
3192
|
const SetItemsHeight = 'setItemsHeight';
|
|
3301
3193
|
|
|
3302
|
-
const renderCursorOffset = newState => {
|
|
3194
|
+
const renderCursorOffset = (_oldState, newState) => {
|
|
3303
3195
|
return ['Viewlet.send', newState.uid, /* method */SetCursorOffset, /* cursorOffset */newState.cursorOffset];
|
|
3304
3196
|
};
|
|
3305
3197
|
|
|
3306
3198
|
const QuickPickInput = 'QuickPickInput';
|
|
3307
3199
|
|
|
3308
|
-
const renderFocus =
|
|
3200
|
+
const renderFocus = (_oldState, _newState) => {
|
|
3309
3201
|
return ['Viewlet.focusElementByName', QuickPickInput];
|
|
3310
3202
|
};
|
|
3311
3203
|
|
|
3312
|
-
const renderFocusedIndex = newState => {
|
|
3313
|
-
|
|
3204
|
+
const renderFocusedIndex = (oldState, newState) => {
|
|
3205
|
+
const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
|
|
3206
|
+
const newFocusedIndex = newState.focusedIndex - newState.minLineY;
|
|
3207
|
+
return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */oldFocusedIndex, /* newFocusedIndex */newFocusedIndex];
|
|
3314
3208
|
};
|
|
3315
3209
|
|
|
3316
|
-
const renderHeight = newState => {
|
|
3210
|
+
const renderHeight = (_oldState, newState) => {
|
|
3317
3211
|
const {
|
|
3318
3212
|
height,
|
|
3319
3213
|
uid
|
|
@@ -3324,13 +3218,6 @@ const renderHeight = newState => {
|
|
|
3324
3218
|
return ['Viewlet.send', uid, /* method */SetItemsHeight, /* height */height];
|
|
3325
3219
|
};
|
|
3326
3220
|
|
|
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
3221
|
const mergeClassNames = (...classNames) => {
|
|
3335
3222
|
return classNames.filter(Boolean).join(' ');
|
|
3336
3223
|
};
|
|
@@ -3638,6 +3525,122 @@ const diffTree = (oldNodes, newNodes) => {
|
|
|
3638
3525
|
return removeTrailingNavigationPatches(patches);
|
|
3639
3526
|
};
|
|
3640
3527
|
|
|
3528
|
+
const getVisible$1 = (items, minLineY, maxLineY, icons) => {
|
|
3529
|
+
const range = items.slice(minLineY, maxLineY);
|
|
3530
|
+
const protoVisibleItems = range.map((item, index) => {
|
|
3531
|
+
return {
|
|
3532
|
+
...item,
|
|
3533
|
+
fileIcon: icons[index]
|
|
3534
|
+
};
|
|
3535
|
+
});
|
|
3536
|
+
return protoVisibleItems;
|
|
3537
|
+
};
|
|
3538
|
+
|
|
3539
|
+
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
3540
|
+
if (size >= contentSize) {
|
|
3541
|
+
return 0;
|
|
3542
|
+
}
|
|
3543
|
+
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
3544
|
+
};
|
|
3545
|
+
|
|
3546
|
+
const emptyHighlightSections = [];
|
|
3547
|
+
|
|
3548
|
+
const getHighlightSections = (highlights, label) => {
|
|
3549
|
+
if (highlights.length === 0) {
|
|
3550
|
+
return emptyHighlightSections;
|
|
3551
|
+
}
|
|
3552
|
+
const sections = [];
|
|
3553
|
+
let position = 0;
|
|
3554
|
+
for (let i = 0; i < highlights.length; i += 2) {
|
|
3555
|
+
const highlightStart = highlights[i];
|
|
3556
|
+
const highlightEnd = highlights[i + 1];
|
|
3557
|
+
if (position < highlightStart) {
|
|
3558
|
+
const beforeText = label.slice(position, highlightStart);
|
|
3559
|
+
sections.push({
|
|
3560
|
+
highlighted: false,
|
|
3561
|
+
text: beforeText
|
|
3562
|
+
});
|
|
3563
|
+
}
|
|
3564
|
+
const highlightText = label.slice(highlightStart, highlightEnd);
|
|
3565
|
+
sections.push({
|
|
3566
|
+
highlighted: true,
|
|
3567
|
+
text: highlightText
|
|
3568
|
+
});
|
|
3569
|
+
position = highlightEnd;
|
|
3570
|
+
}
|
|
3571
|
+
if (position < label.length) {
|
|
3572
|
+
const afterText = label.slice(position);
|
|
3573
|
+
sections.push({
|
|
3574
|
+
highlighted: false,
|
|
3575
|
+
text: afterText
|
|
3576
|
+
});
|
|
3577
|
+
}
|
|
3578
|
+
return sections;
|
|
3579
|
+
};
|
|
3580
|
+
|
|
3581
|
+
const getVisible = (setSize, protoVisibleItems, minLineY, focusedIndex) => {
|
|
3582
|
+
const visibleItems = protoVisibleItems.map((visibleItem, i) => {
|
|
3583
|
+
const highlights = visibleItem.matches.slice(1);
|
|
3584
|
+
const sections = getHighlightSections(highlights, visibleItem.label);
|
|
3585
|
+
return {
|
|
3586
|
+
...visibleItem,
|
|
3587
|
+
highlights: sections,
|
|
3588
|
+
isActive: i === focusedIndex,
|
|
3589
|
+
posInSet: minLineY + i + 1,
|
|
3590
|
+
setSize
|
|
3591
|
+
};
|
|
3592
|
+
});
|
|
3593
|
+
return visibleItems;
|
|
3594
|
+
};
|
|
3595
|
+
|
|
3596
|
+
const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
|
|
3597
|
+
const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
|
|
3598
|
+
return scrollBarOffset;
|
|
3599
|
+
};
|
|
3600
|
+
const getScrollBarY = getScrollBarOffset;
|
|
3601
|
+
|
|
3602
|
+
const createQuickPickViewModel = (oldState, newState) => {
|
|
3603
|
+
const {
|
|
3604
|
+
cursorOffset,
|
|
3605
|
+
deltaY,
|
|
3606
|
+
finalDeltaY,
|
|
3607
|
+
focused,
|
|
3608
|
+
focusedIndex,
|
|
3609
|
+
headerHeight,
|
|
3610
|
+
height,
|
|
3611
|
+
icons,
|
|
3612
|
+
itemHeight,
|
|
3613
|
+
items,
|
|
3614
|
+
maxLineY,
|
|
3615
|
+
minimumSliderSize,
|
|
3616
|
+
minLineY,
|
|
3617
|
+
uid,
|
|
3618
|
+
value
|
|
3619
|
+
} = newState;
|
|
3620
|
+
const protoVisibleItems = getVisible$1(items, minLineY, maxLineY, icons);
|
|
3621
|
+
const visibleItems = getVisible(items.length, protoVisibleItems, minLineY, focusedIndex);
|
|
3622
|
+
const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
|
|
3623
|
+
const newFocusedIndex = focusedIndex - minLineY;
|
|
3624
|
+
const itemCount = items.length;
|
|
3625
|
+
const listHeight = getListHeight(itemCount, itemHeight, height);
|
|
3626
|
+
const contentHeight = itemCount * itemHeight;
|
|
3627
|
+
const scrollBarHeight = getScrollBarSize(listHeight, contentHeight, minimumSliderSize);
|
|
3628
|
+
const scrollBarY = getScrollBarY(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
|
|
3629
|
+
const roundedScrollBarY = Math.round(scrollBarY);
|
|
3630
|
+
return {
|
|
3631
|
+
cursorOffset,
|
|
3632
|
+
focused,
|
|
3633
|
+
height,
|
|
3634
|
+
newFocusedIndex,
|
|
3635
|
+
oldFocusedIndex,
|
|
3636
|
+
scrollBarHeight,
|
|
3637
|
+
scrollBarTop: roundedScrollBarY,
|
|
3638
|
+
uid,
|
|
3639
|
+
value,
|
|
3640
|
+
visibleItems
|
|
3641
|
+
};
|
|
3642
|
+
};
|
|
3643
|
+
|
|
3641
3644
|
const ComboBox = 'combobox';
|
|
3642
3645
|
const ListBox = 'listbox';
|
|
3643
3646
|
const None = 'none';
|
|
@@ -3858,24 +3861,31 @@ const getQuickPickVirtualDom = (visibleItems, scrollBarHeight, scrollBarTop) =>
|
|
|
3858
3861
|
}, ...getQuickPickItemsVirtualDom(visibleItems), ...getScrollBarVirtualDom(scrollBarHeight, scrollBarTop)];
|
|
3859
3862
|
};
|
|
3860
3863
|
|
|
3861
|
-
const
|
|
3864
|
+
const renderItemsDom = state => {
|
|
3865
|
+
const viewModel = createQuickPickViewModel(state, state);
|
|
3862
3866
|
const {
|
|
3863
3867
|
scrollBarHeight,
|
|
3864
3868
|
scrollBarTop,
|
|
3865
3869
|
visibleItems
|
|
3866
|
-
} =
|
|
3867
|
-
|
|
3870
|
+
} = viewModel;
|
|
3871
|
+
return getQuickPickVirtualDom(visibleItems, scrollBarHeight, scrollBarTop);
|
|
3872
|
+
};
|
|
3873
|
+
const renderItems = (_oldState, newState) => {
|
|
3874
|
+
const dom = renderItemsDom(newState);
|
|
3868
3875
|
return [SetDom2, dom];
|
|
3869
3876
|
};
|
|
3870
3877
|
|
|
3871
|
-
const renderIncremental = newState => {
|
|
3872
|
-
const oldDom =
|
|
3873
|
-
const newDom =
|
|
3878
|
+
const renderIncremental = (oldState, newState) => {
|
|
3879
|
+
const oldDom = renderItemsDom(oldState);
|
|
3880
|
+
const newDom = renderItemsDom(newState);
|
|
3881
|
+
if (oldState.initial) {
|
|
3882
|
+
return [SetDom2, newDom];
|
|
3883
|
+
}
|
|
3874
3884
|
const patches = diffTree(oldDom, newDom);
|
|
3875
3885
|
return [SetPatches, newState.uid, patches];
|
|
3876
3886
|
};
|
|
3877
3887
|
|
|
3878
|
-
const renderValue = newState => {
|
|
3888
|
+
const renderValue = (_oldState, newState) => {
|
|
3879
3889
|
return ['Viewlet.setValueByName', QuickPickInput, /* value */newState.value];
|
|
3880
3890
|
};
|
|
3881
3891
|
|
|
@@ -3902,7 +3912,6 @@ const getRenderer = diffType => {
|
|
|
3902
3912
|
|
|
3903
3913
|
const applyRender = (oldState, newState, diffResult) => {
|
|
3904
3914
|
const commands = [];
|
|
3905
|
-
const viewModel = createQuickPickViewModel(oldState, newState);
|
|
3906
3915
|
for (const item of diffResult) {
|
|
3907
3916
|
if (item === Height) {
|
|
3908
3917
|
continue;
|
|
@@ -3911,7 +3920,7 @@ const applyRender = (oldState, newState, diffResult) => {
|
|
|
3911
3920
|
continue;
|
|
3912
3921
|
}
|
|
3913
3922
|
const fn = getRenderer(item);
|
|
3914
|
-
commands.push(fn(
|
|
3923
|
+
commands.push(fn(oldState, newState));
|
|
3915
3924
|
}
|
|
3916
3925
|
return commands;
|
|
3917
3926
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/quick-pick-worker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.1.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
|
}
|