@lvce-editor/file-search-worker 7.5.0 → 7.6.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.
@@ -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,14 @@ const create$b = rpcId => {
207
204
  };
208
205
  };
209
206
 
207
+ const EditorWorker = 99;
208
+ const RendererWorker = 1;
209
+
210
+ const SetDom2 = 'Viewlet.setDom2';
211
+ const SetPatches = 'Viewlet.setPatches';
212
+
213
+ const FocusQuickPickInput = 20;
214
+
210
215
  const {
211
216
  invoke: invoke$2,
212
217
  set: set$2
@@ -273,42 +278,68 @@ const create$a = () => {
273
278
  const states = Object.create(null);
274
279
  const commandMapRef = {};
275
280
  return {
276
- get(uid) {
277
- return states[uid];
281
+ clear() {
282
+ for (const key of Object.keys(states)) {
283
+ delete states[key];
284
+ }
278
285
  },
279
- set(uid, oldState, newState) {
280
- states[uid] = {
281
- oldState,
282
- newState
283
- };
286
+ diff(uid, modules, numbers) {
287
+ const {
288
+ newState,
289
+ oldState
290
+ } = states[uid];
291
+ const diffResult = [];
292
+ for (let i = 0; i < modules.length; i++) {
293
+ const fn = modules[i];
294
+ if (!fn(oldState, newState)) {
295
+ diffResult.push(numbers[i]);
296
+ }
297
+ }
298
+ return diffResult;
284
299
  },
285
300
  dispose(uid) {
286
301
  delete states[uid];
287
302
  },
303
+ get(uid) {
304
+ return states[uid];
305
+ },
306
+ getCommandIds() {
307
+ const keys = Object.keys(commandMapRef);
308
+ const ids = keys.map(toCommandId);
309
+ return ids;
310
+ },
288
311
  getKeys() {
289
312
  return Object.keys(states).map(key => {
290
- return Number.parseInt(key);
313
+ return Number.parseFloat(key);
291
314
  });
292
315
  },
293
- clear() {
294
- for (const key of Object.keys(states)) {
295
- delete states[key];
296
- }
316
+ registerCommands(commandMap) {
317
+ Object.assign(commandMapRef, commandMap);
318
+ },
319
+ set(uid, oldState, newState) {
320
+ states[uid] = {
321
+ newState,
322
+ oldState
323
+ };
297
324
  },
298
325
  wrapCommand(fn) {
299
326
  const wrapped = async (uid, ...args) => {
300
327
  const {
301
- oldState,
302
- newState
328
+ newState,
329
+ oldState
303
330
  } = states[uid];
304
331
  const newerState = await fn(newState, ...args);
305
332
  if (oldState === newerState || newState === newerState) {
306
333
  return;
307
334
  }
308
- const latest = states[uid];
335
+ const latestOld = states[uid];
336
+ const latestNew = {
337
+ ...latestOld.newState,
338
+ ...newerState
339
+ };
309
340
  states[uid] = {
310
- oldState: latest.oldState,
311
- newState: newerState
341
+ newState: latestNew,
342
+ oldState: latestOld.oldState
312
343
  };
313
344
  };
314
345
  return wrapped;
@@ -322,27 +353,36 @@ const create$a = () => {
322
353
  };
323
354
  return wrapped;
324
355
  },
325
- diff(uid, modules, numbers) {
326
- const {
327
- oldState,
328
- newState
329
- } = states[uid];
330
- const diffResult = [];
331
- for (let i = 0; i < modules.length; i++) {
332
- const fn = modules[i];
333
- if (!fn(oldState, newState)) {
334
- diffResult.push(numbers[i]);
356
+ wrapLoadContent(fn) {
357
+ const wrapped = async (uid, ...args) => {
358
+ const {
359
+ newState,
360
+ oldState
361
+ } = states[uid];
362
+ const result = await fn(newState, ...args);
363
+ const {
364
+ error,
365
+ state
366
+ } = result;
367
+ if (oldState === state || newState === state) {
368
+ return {
369
+ error
370
+ };
335
371
  }
336
- }
337
- return diffResult;
338
- },
339
- getCommandIds() {
340
- const keys = Object.keys(commandMapRef);
341
- const ids = keys.map(toCommandId);
342
- return ids;
343
- },
344
- registerCommands(commandMap) {
345
- Object.assign(commandMapRef, commandMap);
372
+ const latestOld = states[uid];
373
+ const latestNew = {
374
+ ...latestOld.newState,
375
+ ...state
376
+ };
377
+ states[uid] = {
378
+ newState: latestNew,
379
+ oldState: latestOld.oldState
380
+ };
381
+ return {
382
+ error
383
+ };
384
+ };
385
+ return wrapped;
346
386
  }
347
387
  };
348
388
  };
@@ -428,6 +468,7 @@ const create$8 = (uid, uri, listItemHeight, x, y, width, height, platform, args,
428
468
  cursorOffset: 0,
429
469
  height: 300,
430
470
  icons: [],
471
+ initial: true,
431
472
  maxVisibleItems: 12,
432
473
  picks: [],
433
474
  recentPickIds: Object.create(null),
@@ -465,22 +506,18 @@ const RenderCursorOffset = 7;
465
506
  const RenderFocusedIndex = 8;
466
507
  const Height = 9;
467
508
 
468
- const diffType$4 = RenderFocus;
469
509
  const isEqual$4 = (oldState, newState) => {
470
510
  return oldState.focused === newState.focused;
471
511
  };
472
512
 
473
- const diffType$3 = RenderFocusedIndex;
474
513
  const isEqual$3 = (oldState, newState) => {
475
514
  return oldState.focusedIndex === newState.focusedIndex;
476
515
  };
477
516
 
478
- const diffType$2 = Height;
479
517
  const isEqual$2 = (oldState, newState) => {
480
518
  return oldState.items.length === newState.items.length;
481
519
  };
482
520
 
483
- const diffType$1 = RenderItems;
484
521
  const isEqual$1 = (oldState, newState) => {
485
522
  return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex;
486
523
  };
@@ -491,7 +528,7 @@ const isEqual = (oldState, newState) => {
491
528
  };
492
529
 
493
530
  const modules = [isEqual$2, isEqual$1, isEqual, isEqual$3, isEqual$4];
494
- const numbers = [diffType$2, diffType$1, diffType, diffType$3, diffType$4];
531
+ const numbers = [Height, RenderItems, diffType, RenderFocusedIndex, RenderFocus];
495
532
 
496
533
  const diff = (oldState, newState) => {
497
534
  const diffResult = [];
@@ -735,17 +772,6 @@ const focusPrevious = state => {
735
772
  return focusIndex(state, previousIndex);
736
773
  };
737
774
 
738
- const Div = 4;
739
- const Input = 6;
740
- const Span = 8;
741
- const Text = 12;
742
- const Img = 17;
743
-
744
- const SetDom2 = 'Viewlet.setDom2';
745
- const SetPatches = 'Viewlet.setPatches';
746
-
747
- const FocusQuickPickInput = 20;
748
-
749
775
  const Enter = 3;
750
776
  const Escape = 8;
751
777
  const PageUp = 10;
@@ -3135,6 +3161,7 @@ const loadContent = async state => {
3135
3161
  focused: true,
3136
3162
  focusedIndex: 0,
3137
3163
  icons,
3164
+ initial: false,
3138
3165
  inputSource: Script,
3139
3166
  items,
3140
3167
  maxLineY,
@@ -3154,141 +3181,27 @@ const executeCallback = id => {
3154
3181
  fn();
3155
3182
  };
3156
3183
 
3157
- const getVisible$1 = (items, minLineY, maxLineY, icons) => {
3158
- const range = items.slice(minLineY, maxLineY);
3159
- const protoVisibleItems = range.map((item, index) => {
3160
- return {
3161
- ...item,
3162
- fileIcon: icons[index]
3163
- };
3164
- });
3165
- return protoVisibleItems;
3166
- };
3167
-
3168
- const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
3169
- if (size >= contentSize) {
3170
- return 0;
3171
- }
3172
- return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
3173
- };
3174
-
3175
- const emptyHighlightSections = [];
3176
-
3177
- const getHighlightSections = (highlights, label) => {
3178
- if (highlights.length === 0) {
3179
- return emptyHighlightSections;
3180
- }
3181
- const sections = [];
3182
- let position = 0;
3183
- for (let i = 0; i < highlights.length; i += 2) {
3184
- const highlightStart = highlights[i];
3185
- const highlightEnd = highlights[i + 1];
3186
- if (position < highlightStart) {
3187
- const beforeText = label.slice(position, highlightStart);
3188
- sections.push({
3189
- highlighted: false,
3190
- text: beforeText
3191
- });
3192
- }
3193
- const highlightText = label.slice(highlightStart, highlightEnd);
3194
- sections.push({
3195
- highlighted: true,
3196
- text: highlightText
3197
- });
3198
- position = highlightEnd;
3199
- }
3200
- if (position < label.length) {
3201
- const afterText = label.slice(position);
3202
- sections.push({
3203
- highlighted: false,
3204
- text: afterText
3205
- });
3206
- }
3207
- return sections;
3208
- };
3209
-
3210
- const getVisible = (setSize, protoVisibleItems, minLineY, focusedIndex) => {
3211
- const visibleItems = protoVisibleItems.map((visibleItem, i) => {
3212
- const highlights = visibleItem.matches.slice(1);
3213
- const sections = getHighlightSections(highlights, visibleItem.label);
3214
- return {
3215
- ...visibleItem,
3216
- highlights: sections,
3217
- isActive: i === focusedIndex,
3218
- posInSet: minLineY + i + 1,
3219
- setSize
3220
- };
3221
- });
3222
- return visibleItems;
3223
- };
3224
-
3225
- const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
3226
- const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
3227
- return scrollBarOffset;
3228
- };
3229
- const getScrollBarY = getScrollBarOffset;
3230
-
3231
- const createQuickPickViewModel = (oldState, newState) => {
3232
- const {
3233
- cursorOffset,
3234
- deltaY,
3235
- finalDeltaY,
3236
- focused,
3237
- focusedIndex,
3238
- headerHeight,
3239
- height,
3240
- icons,
3241
- itemHeight,
3242
- items,
3243
- maxLineY,
3244
- minimumSliderSize,
3245
- minLineY,
3246
- uid,
3247
- value
3248
- } = newState;
3249
- const protoVisibleItems = getVisible$1(items, minLineY, maxLineY, icons);
3250
- const visibleItems = getVisible(items.length, protoVisibleItems, minLineY, focusedIndex);
3251
- const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
3252
- const newFocusedIndex = focusedIndex - minLineY;
3253
- const itemCount = items.length;
3254
- const listHeight = getListHeight(itemCount, itemHeight, height);
3255
- const contentHeight = itemCount * itemHeight;
3256
- const scrollBarHeight = getScrollBarSize(listHeight, contentHeight, minimumSliderSize);
3257
- const scrollBarY = getScrollBarY(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
3258
- const roundedScrollBarY = Math.round(scrollBarY);
3259
- return {
3260
- cursorOffset,
3261
- focused,
3262
- height,
3263
- newFocusedIndex,
3264
- oldFocusedIndex,
3265
- scrollBarHeight,
3266
- scrollBarTop: roundedScrollBarY,
3267
- uid,
3268
- value,
3269
- visibleItems
3270
- };
3271
- };
3272
-
3273
3184
  const SetCursorOffset = 'setCursorOffset';
3274
3185
  const SetFocusedIndex = 'setFocusedIndex';
3275
3186
  const SetItemsHeight = 'setItemsHeight';
3276
3187
 
3277
- const renderCursorOffset = newState => {
3188
+ const renderCursorOffset = (_oldState, newState) => {
3278
3189
  return ['Viewlet.send', newState.uid, /* method */SetCursorOffset, /* cursorOffset */newState.cursorOffset];
3279
3190
  };
3280
3191
 
3281
3192
  const QuickPickInput = 'QuickPickInput';
3282
3193
 
3283
- const renderFocus = newState => {
3194
+ const renderFocus = (_oldState, _newState) => {
3284
3195
  return ['Viewlet.focusElementByName', QuickPickInput];
3285
3196
  };
3286
3197
 
3287
- const renderFocusedIndex = newState => {
3288
- return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */newState.oldFocusedIndex, /* newFocusedIndex */newState.newFocusedIndex];
3198
+ const renderFocusedIndex = (oldState, newState) => {
3199
+ const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
3200
+ const newFocusedIndex = newState.focusedIndex - newState.minLineY;
3201
+ return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */oldFocusedIndex, /* newFocusedIndex */newFocusedIndex];
3289
3202
  };
3290
3203
 
3291
- const renderHeight = newState => {
3204
+ const renderHeight = (_oldState, newState) => {
3292
3205
  const {
3293
3206
  height,
3294
3207
  uid
@@ -3299,6 +3212,13 @@ const renderHeight = newState => {
3299
3212
  return ['Viewlet.send', uid, /* method */SetItemsHeight, /* height */height];
3300
3213
  };
3301
3214
 
3215
+ const Div = 4;
3216
+ const Input = 6;
3217
+ const Span = 8;
3218
+ const Text = 12;
3219
+ const Img = 17;
3220
+ const Reference = 100;
3221
+
3302
3222
  const mergeClassNames = (...classNames) => {
3303
3223
  return classNames.filter(Boolean).join(' ');
3304
3224
  };
@@ -3327,6 +3247,7 @@ const NavigateChild = 7;
3327
3247
  const NavigateParent = 8;
3328
3248
  const RemoveChild = 9;
3329
3249
  const NavigateSibling = 10;
3250
+ const SetReferenceNodeUid = 11;
3330
3251
 
3331
3252
  const isKey = key => {
3332
3253
  return key !== 'type' && key !== 'childCount';
@@ -3394,6 +3315,16 @@ const compareNodes = (oldNode, newNode) => {
3394
3315
  if (oldNode.type !== newNode.type) {
3395
3316
  return null;
3396
3317
  }
3318
+ // Handle reference nodes - special handling for uid changes
3319
+ if (oldNode.type === Reference) {
3320
+ if (oldNode.uid !== newNode.uid) {
3321
+ patches.push({
3322
+ type: SetReferenceNodeUid,
3323
+ uid: newNode.uid
3324
+ });
3325
+ }
3326
+ return patches;
3327
+ }
3397
3328
  // Handle text nodes
3398
3329
  if (oldNode.type === Text && newNode.type === Text) {
3399
3330
  if (oldNode.text !== newNode.text) {
@@ -3595,6 +3526,120 @@ const diffTree = (oldNodes, newNodes) => {
3595
3526
  return removeTrailingNavigationPatches(patches);
3596
3527
  };
3597
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 = 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 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
+ scrollBarHeight,
3636
+ scrollBarTop: roundedScrollBarY,
3637
+ uid,
3638
+ value,
3639
+ visibleItems
3640
+ };
3641
+ };
3642
+
3598
3643
  const ComboBox = 'combobox';
3599
3644
  const ListBox = 'listbox';
3600
3645
  const None = 'none';
@@ -3815,24 +3860,32 @@ const getQuickPickVirtualDom = (visibleItems, scrollBarHeight, scrollBarTop) =>
3815
3860
  }, ...getQuickPickItemsVirtualDom(visibleItems), ...getScrollBarVirtualDom(scrollBarHeight, scrollBarTop)];
3816
3861
  };
3817
3862
 
3818
- const renderItems = newState => {
3863
+ const getItemsDom = newState => {
3864
+ const viewModel = createQuickPickViewModel(newState);
3819
3865
  const {
3820
3866
  scrollBarHeight,
3821
3867
  scrollBarTop,
3822
3868
  visibleItems
3823
- } = newState;
3869
+ } = viewModel;
3824
3870
  const dom = getQuickPickVirtualDom(visibleItems, scrollBarHeight, scrollBarTop);
3871
+ return dom;
3872
+ };
3873
+ const renderItems = (_oldState, newState) => {
3874
+ const dom = getItemsDom(newState);
3825
3875
  return [SetDom2, dom];
3826
3876
  };
3827
3877
 
3828
- const renderIncremental = newState => {
3829
- const oldDom = renderItems(newState)[1];
3830
- const newDom = renderItems(newState)[1];
3878
+ const renderIncremental = (oldState, newState) => {
3879
+ const oldDom = getItemsDom(oldState);
3880
+ const newDom = getItemsDom(newState);
3881
+ if (oldState.initial) {
3882
+ return [SetDom2, newState.uid, newDom];
3883
+ }
3831
3884
  const patches = diffTree(oldDom, newDom);
3832
3885
  return [SetPatches, newState.uid, patches];
3833
3886
  };
3834
3887
 
3835
- const renderValue = newState => {
3888
+ const renderValue = (_oldState, newState) => {
3836
3889
  return ['Viewlet.setValueByName', QuickPickInput, /* value */newState.value];
3837
3890
  };
3838
3891
 
@@ -3859,7 +3912,6 @@ const getRenderer = diffType => {
3859
3912
 
3860
3913
  const applyRender = (oldState, newState, diffResult) => {
3861
3914
  const commands = [];
3862
- const viewModel = createQuickPickViewModel(oldState, newState);
3863
3915
  for (const item of diffResult) {
3864
3916
  if (item === Height) {
3865
3917
  continue;
@@ -3868,7 +3920,7 @@ const applyRender = (oldState, newState, diffResult) => {
3868
3920
  continue;
3869
3921
  }
3870
3922
  const fn = getRenderer(item);
3871
- commands.push(fn(viewModel));
3923
+ commands.push(fn(oldState, newState));
3872
3924
  }
3873
3925
  return commands;
3874
3926
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-search-worker",
3
- "version": "7.5.0",
3
+ "version": "7.6.0",
4
4
  "keywords": [
5
5
  "text-search"
6
6
  ],
@@ -11,8 +11,5 @@
11
11
  "license": "MIT",
12
12
  "author": "Lvce Editor",
13
13
  "type": "module",
14
- "main": "dist/fileSearchWorkerMain.js",
15
- "dependencies": {
16
- "@lvce-editor/constants": "^2.9.0"
17
- }
14
+ "main": "dist/fileSearchWorkerMain.js"
18
15
  }