@lvce-editor/problems-view 1.26.4 → 1.26.6

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.
@@ -244,6 +244,21 @@ const terminate = () => {
244
244
  globalThis.close();
245
245
  };
246
246
 
247
+ const Item = 0;
248
+ const Expanded = 1;
249
+ const Collapsed = 2;
250
+
251
+ const collapseAll$1 = state => {
252
+ const {
253
+ problems
254
+ } = state;
255
+ const collapsedUris = problems.filter(problem => problem.listItemType !== Item).map(problem => problem.uri);
256
+ return {
257
+ ...state,
258
+ collapsedUris: [...new Set(collapsedUris)]
259
+ };
260
+ };
261
+
247
262
  const normalizeLine = line => {
248
263
  if (line.startsWith('Error: ')) {
249
264
  return line.slice('Error: '.length);
@@ -1596,9 +1611,11 @@ const VirtualDomElements = {
1596
1611
  Video
1597
1612
  };
1598
1613
 
1614
+ const ClientX = 'event.clientX';
1599
1615
  const ClientY = 'event.clientY';
1600
1616
  const DeltaMode = 'event.deltaMode';
1601
1617
  const DeltaY = 'event.deltaY';
1618
+ const TargetName = 'event.target.name';
1602
1619
 
1603
1620
  const Space = 9;
1604
1621
  const PageUp = 10;
@@ -1657,6 +1674,9 @@ const sendMessagePortToEditorWorker$1 = async (port, rpcId) => {
1657
1674
  const command = 'HandleMessagePort.handleMessagePort';
1658
1675
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1659
1676
  };
1677
+ const getFileIcon = async options => {
1678
+ return invoke('IconTheme.getFileIcon', options);
1679
+ };
1660
1680
  const writeClipBoardText$1 = async text => {
1661
1681
  await invoke('ClipBoard.writeText', /* text */text);
1662
1682
  };
@@ -1712,6 +1732,7 @@ const create = (id, uri, x, y, width, height, workspaceUri) => {
1712
1732
  activeUri: '',
1713
1733
  collapsedUris: [],
1714
1734
  deltaY: 0,
1735
+ fileIconCache: {},
1715
1736
  filteredProblems: [],
1716
1737
  filterValue: '',
1717
1738
  finalDeltaY: 0,
@@ -1762,7 +1783,7 @@ const haveSameCollapsedUris = (oldState, newState) => {
1762
1783
  return oldCollapsedUris.length === newCollapsedUris.length && oldCollapsedUris.every((uri, index) => uri === newCollapsedUris[index]);
1763
1784
  };
1764
1785
  const isEqual = (oldState, newState) => {
1765
- return oldState.activeUri === newState.activeUri && haveSameCollapsedUris(oldState, newState) && oldState.focusedIndex === newState.focusedIndex && oldState.height === newState.height && oldState.maxLineY === newState.maxLineY && oldState.minLineY === newState.minLineY && oldState.problems === newState.problems && oldState.filterValue === newState.filterValue && oldState.message === newState.message && oldState.scrollBarActive === newState.scrollBarActive && oldState.scrollBarHeight === newState.scrollBarHeight && oldState.width === newState.width && oldState.viewMode === newState.viewMode;
1786
+ return oldState.activeUri === newState.activeUri && haveSameCollapsedUris(oldState, newState) && oldState.fileIconCache === newState.fileIconCache && oldState.focusedIndex === newState.focusedIndex && oldState.height === newState.height && oldState.maxLineY === newState.maxLineY && oldState.minLineY === newState.minLineY && oldState.problems === newState.problems && oldState.filterValue === newState.filterValue && oldState.message === newState.message && oldState.scrollBarActive === newState.scrollBarActive && oldState.scrollBarHeight === newState.scrollBarHeight && oldState.width === newState.width && oldState.viewMode === newState.viewMode;
1766
1787
  };
1767
1788
 
1768
1789
  const RenderItems = 1;
@@ -1808,10 +1829,6 @@ const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
1808
1829
  return Math.min(Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize), size);
1809
1830
  };
1810
1831
 
1811
- const Item = 0;
1812
- const Expanded = 1;
1813
- const Collapsed = 2;
1814
-
1815
1832
  const getListItemType = (listItemType, isCollapsed) => {
1816
1833
  if (listItemType === Item) {
1817
1834
  return Item;
@@ -2116,6 +2133,48 @@ const getMenuIds = () => {
2116
2133
  return [ProblemsFilter$1];
2117
2134
  };
2118
2135
 
2136
+ const getMissingRequests = (problems, fileIconCache) => {
2137
+ const missingRequests = [];
2138
+ const pendingUris = new Set();
2139
+ for (const problem of problems) {
2140
+ const {
2141
+ fileName,
2142
+ uri
2143
+ } = problem;
2144
+ if (!uri || uri in fileIconCache || pendingUris.has(uri)) {
2145
+ continue;
2146
+ }
2147
+ pendingUris.add(uri);
2148
+ missingRequests.push({
2149
+ name: fileName,
2150
+ uri
2151
+ });
2152
+ }
2153
+ return missingRequests;
2154
+ };
2155
+ const requestFileIcon = name => {
2156
+ if (!name) {
2157
+ return Promise.resolve('');
2158
+ }
2159
+ return getFileIcon({
2160
+ name
2161
+ });
2162
+ };
2163
+ const getFileIcons = async (problems, fileIconCache) => {
2164
+ const missingRequests = getMissingRequests(problems, fileIconCache);
2165
+ if (missingRequests.length === 0) {
2166
+ return fileIconCache;
2167
+ }
2168
+ const icons = await Promise.all(missingRequests.map(request => requestFileIcon(request.name)));
2169
+ const newFileIconCache = {
2170
+ ...fileIconCache
2171
+ };
2172
+ for (let i = 0; i < missingRequests.length; i++) {
2173
+ newFileIconCache[missingRequests[i].uri] = icons[i];
2174
+ }
2175
+ return newFileIconCache;
2176
+ };
2177
+
2119
2178
  const {
2120
2179
  getProblems: getProblems$1,
2121
2180
  getUri} = EditorWorker;
@@ -2227,6 +2286,18 @@ const toProblems = (diagnostics, workspaceUri = '') => {
2227
2286
  return problems;
2228
2287
  };
2229
2288
 
2289
+ const getDiagnosticKey = diagnostic => JSON.stringify([diagnostic.uri, diagnostic.rowIndex, diagnostic.columnIndex, diagnostic.message, diagnostic.source, diagnostic.type, diagnostic.code]);
2290
+ const getUniqueDiagnostics = diagnostics => {
2291
+ const keys = new Set();
2292
+ return diagnostics.filter(diagnostic => {
2293
+ const key = getDiagnosticKey(diagnostic);
2294
+ if (keys.has(key)) {
2295
+ return false;
2296
+ }
2297
+ keys.add(key);
2298
+ return true;
2299
+ });
2300
+ };
2230
2301
  const getProblems = async (workspaceUri, activeUri) => {
2231
2302
  if (!activeUri) {
2232
2303
  return {
@@ -2235,10 +2306,8 @@ const getProblems = async (workspaceUri, activeUri) => {
2235
2306
  };
2236
2307
  }
2237
2308
  try {
2238
- const diagnostics = await getProblems$1();
2239
- const activeDiagnostics = diagnostics.filter(diagnostic => diagnostic.uri === activeUri);
2240
- // @ts-ignore
2241
- const problems = toProblems(activeDiagnostics, workspaceUri);
2309
+ const diagnostics = getUniqueDiagnostics(await getProblems$1());
2310
+ const problems = toProblems(diagnostics, workspaceUri);
2242
2311
  return {
2243
2312
  error: '',
2244
2313
  problems
@@ -2253,15 +2322,18 @@ const getProblems = async (workspaceUri, activeUri) => {
2253
2322
 
2254
2323
  const refreshProblems = async (state, activeUri) => {
2255
2324
  const {
2325
+ fileIconCache,
2256
2326
  workspaceUri
2257
2327
  } = state;
2258
2328
  const {
2259
2329
  error,
2260
2330
  problems
2261
2331
  } = await getProblems(workspaceUri, activeUri);
2332
+ const newFileIconCache = await getFileIcons(problems, fileIconCache);
2262
2333
  return {
2263
2334
  ...state,
2264
2335
  activeUri,
2336
+ fileIconCache: newFileIconCache,
2265
2337
  filteredProblems: problems,
2266
2338
  inputSource: Script,
2267
2339
  listItems: [],
@@ -2389,10 +2461,6 @@ const handleClickAt = (state, eventX, eventY) => {
2389
2461
  };
2390
2462
  };
2391
2463
 
2392
- const handleClickButton = async (state, name) => {
2393
- return state;
2394
- };
2395
-
2396
2464
  const show2 = async (uid, menuId, x, y, args) => {
2397
2465
  await showContextMenu2(uid, menuId, x, y, args);
2398
2466
  };
@@ -2407,6 +2475,35 @@ const handleClickMoreFilters = async (state, eventX, eventY) => {
2407
2475
  return state;
2408
2476
  };
2409
2477
 
2478
+ const viewAsList = state => {
2479
+ return {
2480
+ ...state,
2481
+ viewMode: List
2482
+ };
2483
+ };
2484
+
2485
+ const viewAsTable = state => {
2486
+ return {
2487
+ ...state,
2488
+ viewMode: Table
2489
+ };
2490
+ };
2491
+
2492
+ const handleClickButton = async (state, name, eventX = 0, eventY = 0) => {
2493
+ switch (name) {
2494
+ case 'collapseAll':
2495
+ return collapseAll$1(state);
2496
+ case 'more filters':
2497
+ return handleClickMoreFilters(state, eventX, eventY);
2498
+ case 'viewAsList':
2499
+ return viewAsList(state);
2500
+ case 'viewAsTable':
2501
+ return viewAsTable(state);
2502
+ default:
2503
+ return state;
2504
+ }
2505
+ };
2506
+
2410
2507
  const handleContextMenu = async (state, eventX, eventY) => {
2411
2508
  const {
2412
2509
  uid
@@ -2425,13 +2522,14 @@ const handleFilterInput = (state, value, inputSource = Script) => {
2425
2522
  };
2426
2523
  };
2427
2524
 
2428
- const handleIconThemeChange = state => {
2525
+ const handleIconThemeChange = async state => {
2429
2526
  const {
2430
2527
  problems
2431
2528
  } = state;
2529
+ const fileIconCache = await getFileIcons(problems, {});
2432
2530
  return {
2433
2531
  ...state,
2434
- problems: [...problems]
2532
+ fileIconCache
2435
2533
  };
2436
2534
  };
2437
2535
 
@@ -2578,6 +2676,7 @@ const getSavedViewMode = savedState => {
2578
2676
 
2579
2677
  const loadContent = async (state, savedState) => {
2580
2678
  const {
2679
+ fileIconCache: oldFileIconCache,
2581
2680
  workspaceUri
2582
2681
  } = state;
2583
2682
  const activeUri = await getActiveUri();
@@ -2595,6 +2694,7 @@ const loadContent = async (state, savedState) => {
2595
2694
  };
2596
2695
  }
2597
2696
  const message = getMessage(problems.length);
2697
+ const fileIconCache = await getFileIcons(problems, oldFileIconCache);
2598
2698
  const viewMode = getSavedViewMode(savedState);
2599
2699
  const filterValue = getSavedFilterValue(savedState);
2600
2700
  const collapsedUris = getSavedCollapsedUris(savedState);
@@ -2602,6 +2702,7 @@ const loadContent = async (state, savedState) => {
2602
2702
  ...state,
2603
2703
  activeUri,
2604
2704
  collapsedUris,
2705
+ fileIconCache,
2605
2706
  filteredProblems: problems,
2606
2707
  filterValue,
2607
2708
  inputSource: Script,
@@ -2640,18 +2741,14 @@ const getUniqueIndents = problems => {
2640
2741
  return uniqueIndents;
2641
2742
  };
2642
2743
 
2643
- const getFileNameIcon = file => {
2644
- return '';
2645
- };
2646
-
2647
- const getIcon = uri => {
2744
+ const getIcon = (uri, fileIconCache) => {
2648
2745
  if (!uri) {
2649
2746
  return '';
2650
2747
  }
2651
- return getFileNameIcon();
2748
+ return fileIconCache[uri] || '';
2652
2749
  };
2653
2750
 
2654
- const getVisibleProblems = (problems, collapsedUris, focusedIndex, filterValue, minLineY = 0, maxLineY = Infinity, viewMode = List) => {
2751
+ const getVisibleProblems = (problems, fileIconCache, collapsedUris, focusedIndex, filterValue, minLineY = 0, maxLineY = Infinity, viewMode = List) => {
2655
2752
  array(problems);
2656
2753
  array(collapsedUris);
2657
2754
  number(focusedIndex);
@@ -2666,7 +2763,7 @@ const getVisibleProblems = (problems, collapsedUris, focusedIndex, filterValue,
2666
2763
  visibleItems.push({
2667
2764
  ...problem,
2668
2765
  filterValueLength,
2669
- icon: getIcon(problem.uri),
2766
+ icon: getIcon(problem.uri, fileIconCache),
2670
2767
  isActive: i === focusedIndex,
2671
2768
  isEven: i % 2 === 0
2672
2769
  });
@@ -2678,6 +2775,7 @@ const renderCss = (oldState, newState) => {
2678
2775
  const {
2679
2776
  collapsedUris,
2680
2777
  deltaY,
2778
+ fileIconCache,
2681
2779
  filterValue,
2682
2780
  finalDeltaY,
2683
2781
  focusedIndex,
@@ -2692,7 +2790,7 @@ const renderCss = (oldState, newState) => {
2692
2790
  viewMode,
2693
2791
  width
2694
2792
  } = newState;
2695
- const visibleProblems = getVisibleProblems(problems, collapsedUris, focusedIndex, filterValue, minLineY, maxLineY, viewMode);
2793
+ const visibleProblems = getVisibleProblems(problems, fileIconCache, collapsedUris, focusedIndex, filterValue, minLineY, maxLineY, viewMode);
2696
2794
  const uniqueIndents = getUniqueIndents(visibleProblems);
2697
2795
  const listHeight = getListHeight(height, width, smallWidthBreakPoint, viewMode);
2698
2796
  const scrollBarTop = getScrollBarTop(listHeight, finalDeltaY, deltaY, scrollBarHeight);
@@ -2738,8 +2836,15 @@ const renderCss = (oldState, newState) => {
2738
2836
 
2739
2837
  const Filter$2 = 'filter';
2740
2838
 
2839
+ const getFilterInputName = (inputSource, filterValue) => {
2840
+ if (inputSource === Script && filterValue) {
2841
+ return `${Filter$2}-${encodeURIComponent(filterValue)}`;
2842
+ }
2843
+ return Filter$2;
2844
+ };
2845
+
2741
2846
  const renderFilterValue = (oldState, newState) => {
2742
- return ['Viewlet.setValueByName', Filter$2, newState.filterValue];
2847
+ return ['Viewlet.setValueByName', getFilterInputName(newState.inputSource, newState.filterValue), newState.filterValue];
2743
2848
  };
2744
2849
 
2745
2850
  const Button = 1;
@@ -2791,6 +2896,10 @@ const HandleWheel = 7;
2791
2896
  const HandleScrollBarMove = 8;
2792
2897
  const HandleScrollBarPointerCaptureLost = 9;
2793
2898
  const HandleScrollBarPointerDown = 10;
2899
+ const HandleCollapseAll = 11;
2900
+ const HandleViewAsList = 12;
2901
+ const HandleViewAsTable = 13;
2902
+ const HandleClickButton = 14;
2794
2903
 
2795
2904
  const getIconVirtualDom = (icon, type = Div) => {
2796
2905
  return {
@@ -2801,6 +2910,20 @@ const getIconVirtualDom = (icon, type = Div) => {
2801
2910
  };
2802
2911
  };
2803
2912
 
2913
+ const getOnClick = command => {
2914
+ switch (command) {
2915
+ case 'collapseAll':
2916
+ return HandleCollapseAll;
2917
+ case 'more filters':
2918
+ return HandleClickMoreFilters;
2919
+ case 'viewAsList':
2920
+ return HandleViewAsList;
2921
+ case 'viewAsTable':
2922
+ return HandleViewAsTable;
2923
+ default:
2924
+ return HandleClickButton;
2925
+ }
2926
+ };
2804
2927
  const getActionButtonVirtualDom = action => {
2805
2928
  const {
2806
2929
  command,
@@ -2810,7 +2933,8 @@ const getActionButtonVirtualDom = action => {
2810
2933
  return [{
2811
2934
  childCount: 1,
2812
2935
  className: IconButton,
2813
- 'data-command': command,
2936
+ name: command,
2937
+ onClick: getOnClick(command),
2814
2938
  title: id,
2815
2939
  type: Button$1
2816
2940
  }, getIconVirtualDom(icon)];
@@ -2865,10 +2989,11 @@ const getProblemsFilterVirtualDom = action => {
2865
2989
  childCount: getChildCount(action.badgeText),
2866
2990
  className: Filter$1,
2867
2991
  type: Div
2868
- }, getInputBoxVirtualDom(Filter$2, action.command, action.placeholder || '', action.value), ...getFilterBadgeDom(action.badgeText), ...getActionButtonVirtualDom({
2992
+ }, getInputBoxVirtualDom(action.name || Filter$2, action.command, action.placeholder || '', action.value), ...getFilterBadgeDom(action.badgeText), ...getActionButtonVirtualDom({
2869
2993
  command: 'more filters',
2870
2994
  icon: Filter,
2871
- id: 'more filters'})];
2995
+ id: 'more filters' // TODO use i18n string
2996
+ })];
2872
2997
  };
2873
2998
 
2874
2999
  const messageNode$2 = {
@@ -3189,7 +3314,7 @@ const getScrollBarVirtualDom = (scrollBarHeight, scrollBarActive) => {
3189
3314
 
3190
3315
  const Focusable = 0;
3191
3316
 
3192
- const getProblemsVirtualDom = (activeUri, viewMode, problems, filterValue, isSmall, message, scrollBarHeight = 0, scrollBarActive = false, problemCount = problems.length) => {
3317
+ const getProblemsVirtualDom = (activeUri, viewMode, problems, filterValue, inputSource, isSmall, message, scrollBarHeight = 0, scrollBarActive = false, problemCount = problems.length) => {
3193
3318
  const baseDom = {
3194
3319
  childCount: isSmall ? 2 : 1,
3195
3320
  className: mergeClassNames(Viewlet, Problems),
@@ -3204,6 +3329,7 @@ const getProblemsVirtualDom = (activeUri, viewMode, problems, filterValue, isSma
3204
3329
  const filterDom = isSmall ? getProblemsFilterVirtualDom({
3205
3330
  badgeText: '',
3206
3331
  command: HandleFilterInput,
3332
+ name: getFilterInputName(inputSource, filterValue),
3207
3333
  placeholder: filter(),
3208
3334
  value: filterValue
3209
3335
  }) : [];
@@ -3222,8 +3348,10 @@ const renderItems = (oldState, newState) => {
3222
3348
  const {
3223
3349
  activeUri,
3224
3350
  collapsedUris,
3351
+ fileIconCache,
3225
3352
  filterValue,
3226
3353
  focusedIndex,
3354
+ inputSource,
3227
3355
  maxLineY,
3228
3356
  message,
3229
3357
  minLineY,
@@ -3235,9 +3363,9 @@ const renderItems = (oldState, newState) => {
3235
3363
  width
3236
3364
  } = newState;
3237
3365
  const problemCount = getVisibleProblemCount(problems, collapsedUris, filterValue, viewMode);
3238
- const visible = getVisibleProblems(problems, collapsedUris, focusedIndex, filterValue, minLineY, maxLineY, viewMode);
3366
+ const visible = getVisibleProblems(problems, fileIconCache, collapsedUris, focusedIndex, filterValue, minLineY, maxLineY, viewMode);
3239
3367
  const isSmall = width <= smallWidthBreakPoint;
3240
- const dom = getProblemsVirtualDom(activeUri, viewMode, visible, filterValue, isSmall, message, scrollBarHeight, scrollBarActive, problemCount);
3368
+ const dom = getProblemsVirtualDom(activeUri, viewMode, visible, filterValue, inputSource, isSmall, message, scrollBarHeight, scrollBarActive, problemCount);
3241
3369
  return ['Viewlet.setDom2', dom];
3242
3370
  };
3243
3371
 
@@ -3296,6 +3424,7 @@ const getActionsVirtualDom = actions => {
3296
3424
  const getActions = state => {
3297
3425
  const {
3298
3426
  collapsedUris,
3427
+ fileIconCache,
3299
3428
  filterValue,
3300
3429
  focusedIndex,
3301
3430
  inputSource,
@@ -3304,7 +3433,7 @@ const getActions = state => {
3304
3433
  viewMode,
3305
3434
  width
3306
3435
  } = state;
3307
- const visibleCount = getVisibleProblems(problems, collapsedUris, focusedIndex, filterValue, 0, Infinity, viewMode).length;
3436
+ const visibleCount = getVisibleProblems(problems, fileIconCache, collapsedUris, focusedIndex, filterValue, 0, Infinity, viewMode).length;
3308
3437
  const problemsCount = problems.length;
3309
3438
  const isSmall = width <= smallWidthBreakPoint;
3310
3439
  const actions = [];
@@ -3313,6 +3442,7 @@ const getActions = state => {
3313
3442
  badgeText: visibleCount === problemsCount ? '' : showingOf(visibleCount, problemsCount),
3314
3443
  command: HandleFilterInput,
3315
3444
  id: 'Filter',
3445
+ name: getFilterInputName(inputSource, filterValue),
3316
3446
  placeholder: filter(),
3317
3447
  type: ProblemsFilter,
3318
3448
  value: inputSource === Script ? filterValue : ''
@@ -3370,7 +3500,19 @@ const renderEventListeners = () => {
3370
3500
  params: ['handleClickAt', 'event.clientX', 'event.clientY']
3371
3501
  }, {
3372
3502
  name: HandleClickMoreFilters,
3373
- params: ['handleClickMoreFilters']
3503
+ params: ['handleClickMoreFilters', ClientX, ClientY]
3504
+ }, {
3505
+ name: HandleClickButton,
3506
+ params: ['handleClickButton', TargetName, ClientX, ClientY]
3507
+ }, {
3508
+ name: HandleCollapseAll,
3509
+ params: ['collapseAll']
3510
+ }, {
3511
+ name: HandleViewAsList,
3512
+ params: ['viewAsList']
3513
+ }, {
3514
+ name: HandleViewAsTable,
3515
+ params: ['viewAsTable']
3374
3516
  }, {
3375
3517
  name: HandleWheel,
3376
3518
  params: ['handleWheel', DeltaMode, DeltaY],
@@ -3409,21 +3551,8 @@ const saveState = state => {
3409
3551
  };
3410
3552
  };
3411
3553
 
3412
- const viewAsList = state => {
3413
- return {
3414
- ...state,
3415
- viewMode: List
3416
- };
3417
- };
3418
-
3419
- const viewAsTable = state => {
3420
- return {
3421
- ...state,
3422
- viewMode: Table
3423
- };
3424
- };
3425
-
3426
3554
  const commandMap = {
3555
+ 'Problems.collapseAll': wrapCommand(collapseAll$1),
3427
3556
  'Problems.copyMessage': wrapCommand(copyMessage),
3428
3557
  'Problems.create': create,
3429
3558
  'Problems.diff2': diff2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/problems-view",
3
- "version": "1.26.4",
3
+ "version": "1.26.6",
4
4
  "description": "Problems View Worker",
5
5
  "repository": {
6
6
  "type": "git",