@lvce-editor/problems-view 1.34.2 → 1.36.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.
@@ -1437,7 +1437,7 @@ const create$1 = rpcId => {
1437
1437
  };
1438
1438
  };
1439
1439
 
1440
- const None$1 = 'none';
1440
+ const None$2 = 'none';
1441
1441
  const ToolBar = 'toolbar';
1442
1442
  const Tree = 'tree';
1443
1443
  const TreeItem = 'treeitem';
@@ -1749,7 +1749,7 @@ const {
1749
1749
  wrapGetter
1750
1750
  } = create$a();
1751
1751
 
1752
- const None = 0;
1752
+ const None$1 = 0;
1753
1753
  const Table = 1;
1754
1754
  const List = 2;
1755
1755
 
@@ -1780,7 +1780,7 @@ const create = (id, uri, x, y, width, height, workspaceUri) => {
1780
1780
  showWarnings: true,
1781
1781
  smallWidthBreakPoint: 650,
1782
1782
  uid: id,
1783
- viewMode: None,
1783
+ viewMode: None$1,
1784
1784
  width,
1785
1785
  workspaceUri,
1786
1786
  x,
@@ -1833,7 +1833,7 @@ const diff = (oldState, newState) => {
1833
1833
  const FilterHeight = 24;
1834
1834
  const TableHeaderHeight = 22;
1835
1835
  const getListTopOffset = (width, smallWidthBreakPoint, viewMode) => {
1836
- const filterHeight = viewMode !== None && width <= smallWidthBreakPoint ? FilterHeight : 0;
1836
+ const filterHeight = viewMode !== None$1 && width <= smallWidthBreakPoint ? FilterHeight : 0;
1837
1837
  const tableHeaderHeight = viewMode === Table ? TableHeaderHeight : 0;
1838
1838
  return filterHeight + tableHeaderHeight;
1839
1839
  };
@@ -1855,9 +1855,6 @@ const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
1855
1855
  return Math.min(Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize), size);
1856
1856
  };
1857
1857
 
1858
- const Error$1 = 'error';
1859
- const Warning = 'warning';
1860
-
1861
1858
  const getListItemType = (listItemType, isCollapsed) => {
1862
1859
  if (listItemType === Item) {
1863
1860
  return Item;
@@ -1875,11 +1872,18 @@ const matchesFilterValue = (string, filterValueLower) => {
1875
1872
  return 0;
1876
1873
  };
1877
1874
 
1875
+ const None = 0;
1876
+ const Error$2 = 1;
1877
+ const Warning$1 = 2;
1878
+ const Spelling = 3;
1879
+ const Info = 4;
1880
+ const Other = 5;
1881
+
1878
1882
  const matchesSeverity = (problem, showErrors, showWarnings, showInfos) => {
1879
1883
  switch (problem.type) {
1880
- case Error$1:
1884
+ case Error$2:
1881
1885
  return showErrors;
1882
- case Warning:
1886
+ case Warning$1:
1883
1887
  return showWarnings;
1884
1888
  default:
1885
1889
  return showInfos;
@@ -1990,6 +1994,10 @@ const focusIndex = (state, index) => {
1990
1994
  };
1991
1995
  };
1992
1996
 
1997
+ const getComponentState = uid => {
1998
+ return get(uid).newState;
1999
+ };
2000
+
1993
2001
  const mergeClassNames = (...classNames) => {
1994
2002
  return classNames.filter(Boolean).join(' ');
1995
2003
  };
@@ -2185,6 +2193,9 @@ const getMenuIds = () => {
2185
2193
  return [ProblemsFilter$1];
2186
2194
  };
2187
2195
 
2196
+ const Error$1 = 'error';
2197
+ const Warning = 'warning';
2198
+
2188
2199
  const {
2189
2200
  getProblems: getProblems$1,
2190
2201
  getUri} = EditorWorker;
@@ -2192,9 +2203,21 @@ const getDiagnostics = editorId => {
2192
2203
  return invoke$3('Editor.getDiagnostics', editorId);
2193
2204
  };
2194
2205
 
2195
- const leadingSlashesRegex = /^\/+/;
2196
- const trailingSlashRegex = /\/$/;
2197
- const windowsDrivePathRegex = /^\/[a-z]:\//i;
2206
+ const getProblemType = type => {
2207
+ switch (type) {
2208
+ case Error$1:
2209
+ return Error$2;
2210
+ case Warning:
2211
+ return Warning$1;
2212
+ case 'info':
2213
+ return Info;
2214
+ case 'spelling':
2215
+ return Spelling;
2216
+ default:
2217
+ return type ? Other : Error$2;
2218
+ }
2219
+ };
2220
+
2198
2221
  const toProblem = (diagnostic, index) => {
2199
2222
  const {
2200
2223
  code,
@@ -2214,31 +2237,13 @@ const toProblem = (diagnostic, index) => {
2214
2237
  listItemType: Item,
2215
2238
  message: message || '',
2216
2239
  posInSet: index,
2217
- relativePath: '',
2218
2240
  rowIndex: rowIndex || 0,
2219
2241
  setSize: 1,
2220
2242
  source: source || '',
2221
- type: type || 'error',
2243
+ type: getProblemType(type),
2222
2244
  uri
2223
2245
  };
2224
2246
  };
2225
- const normalizeFileUri = uri => {
2226
- const normalizedUri = uri.startsWith('file://') ? uri.slice('file://'.length) : uri;
2227
- return windowsDrivePathRegex.test(normalizedUri) ? normalizedUri.slice(1) : normalizedUri;
2228
- };
2229
- const getRelativeParentUri = (uri, workspaceUri) => {
2230
- const normalizedUri = normalizeFileUri(uri);
2231
- const normalizedWorkspaceUri = normalizeFileUri(workspaceUri).replace(trailingSlashRegex, '');
2232
- const slashIndex = normalizedUri.lastIndexOf('/');
2233
- const parentUri = normalizedUri.slice(0, slashIndex);
2234
- if (parentUri === normalizedWorkspaceUri) {
2235
- return '';
2236
- }
2237
- if (normalizedWorkspaceUri && parentUri.startsWith(`${normalizedWorkspaceUri}/`)) {
2238
- return parentUri.slice(normalizedWorkspaceUri.length + 1);
2239
- }
2240
- return parentUri.replace(leadingSlashesRegex, '');
2241
- };
2242
2247
  const getFileName = uri => {
2243
2248
  const slashIndex = uri.lastIndexOf('/');
2244
2249
  return uri.slice(slashIndex + 1);
@@ -2253,16 +2258,15 @@ const toRelatedProblem = (relatedInformation, diagnostic, index, setSize) => {
2253
2258
  listItemType: Item,
2254
2259
  message: relatedInformation.message || '',
2255
2260
  posInSet: index,
2256
- relativePath: '',
2257
2261
  rowIndex: relatedInformation.rowIndex || 0,
2258
2262
  setSize,
2259
2263
  source: getFileName(relatedInformation.uri),
2260
2264
  targetUri: relatedInformation.uri,
2261
- type: diagnostic.type || 'error',
2265
+ type: getProblemType(diagnostic.type),
2262
2266
  uri: diagnostic.uri
2263
2267
  };
2264
2268
  };
2265
- const toProblems = (diagnostics, workspaceUri = '') => {
2269
+ const toProblems = diagnostics => {
2266
2270
  const problems = [];
2267
2271
  let problem = {
2268
2272
  code: '',
@@ -2273,11 +2277,10 @@ const toProblems = (diagnostics, workspaceUri = '') => {
2273
2277
  listItemType: 0,
2274
2278
  message: '',
2275
2279
  posInSet: 0,
2276
- relativePath: '',
2277
2280
  rowIndex: 0,
2278
2281
  setSize: 0,
2279
2282
  source: '',
2280
- type: '',
2283
+ type: None,
2281
2284
  uri: ''
2282
2285
  };
2283
2286
  let relativeIndex = 0;
@@ -2296,11 +2299,10 @@ const toProblems = (diagnostics, workspaceUri = '') => {
2296
2299
  listItemType: Expanded,
2297
2300
  message: '',
2298
2301
  posInSet: relativeIndex,
2299
- relativePath: '',
2300
2302
  rowIndex: 0,
2301
2303
  setSize: 123,
2302
2304
  source: '',
2303
- type: '',
2305
+ type: None,
2304
2306
  uri: diagnostic.uri
2305
2307
  };
2306
2308
  problems.push(problem);
@@ -2312,13 +2314,8 @@ const toProblems = (diagnostics, workspaceUri = '') => {
2312
2314
  }
2313
2315
  }
2314
2316
  for (const problem of problems) {
2315
- // TODO maybe rename property, this should be the relative path of the parent folder of the file
2316
- // @ts-ignore
2317
2317
  const displayUri = problem.targetUri || problem.uri;
2318
- problem.relativePath = getRelativeParentUri(displayUri, workspaceUri);
2319
- // @ts-ignore
2320
2318
  problem.fileName = getFileName(displayUri);
2321
- // problem.uri = problem.uri // TODO
2322
2319
  }
2323
2320
  return problems;
2324
2321
  };
@@ -2335,7 +2332,7 @@ const getUniqueDiagnostics = diagnostics => {
2335
2332
  return true;
2336
2333
  });
2337
2334
  };
2338
- const getProblems = async (workspaceUri, activeUri) => {
2335
+ const getProblems = async activeUri => {
2339
2336
  if (!activeUri) {
2340
2337
  return {
2341
2338
  error: '',
@@ -2344,7 +2341,7 @@ const getProblems = async (workspaceUri, activeUri) => {
2344
2341
  }
2345
2342
  try {
2346
2343
  const diagnostics = getUniqueDiagnostics(await getProblems$1());
2347
- const problems = toProblems(diagnostics, workspaceUri);
2344
+ const problems = toProblems(diagnostics);
2348
2345
  return {
2349
2346
  error: '',
2350
2347
  problems
@@ -2432,13 +2429,12 @@ const getFileIcons = async (problems, fileIconCache) => {
2432
2429
 
2433
2430
  const refreshProblems = async (state, activeUri) => {
2434
2431
  const {
2435
- fileIconCache,
2436
- workspaceUri
2432
+ fileIconCache
2437
2433
  } = state;
2438
2434
  const {
2439
2435
  error,
2440
2436
  problems
2441
- } = await getProblems(workspaceUri, activeUri);
2437
+ } = await getProblems(activeUri);
2442
2438
  const newFileIconCache = await getFileIcons(problems, fileIconCache);
2443
2439
  return {
2444
2440
  ...state,
@@ -2934,7 +2930,7 @@ const loadContent = async (state, savedState) => {
2934
2930
  const {
2935
2931
  error,
2936
2932
  problems
2937
- } = await getProblems(workspaceUri, activeUri);
2933
+ } = await getProblems(activeUri);
2938
2934
  if (error) {
2939
2935
  return {
2940
2936
  ...state,
@@ -3132,7 +3128,7 @@ const getIconVirtualDom = (icon, type = Div) => {
3132
3128
  return {
3133
3129
  childCount: 0,
3134
3130
  className: mergeClassNames('MaskIcon', `MaskIcon${icon}`),
3135
- role: None$1,
3131
+ role: None$2,
3136
3132
  type
3137
3133
  };
3138
3134
  };
@@ -3270,7 +3266,7 @@ const getFileIconVirtualDom = icon => {
3270
3266
  alt: '',
3271
3267
  childCount: 0,
3272
3268
  className: FileIcon,
3273
- role: None$1,
3269
+ role: None$2,
3274
3270
  src: icon,
3275
3271
  type: Img
3276
3272
  };
@@ -3287,7 +3283,7 @@ const errorIconNode = {
3287
3283
  type: Div
3288
3284
  };
3289
3285
  const getProblemsIconVirtualDom = type => {
3290
- if (type === Warning) {
3286
+ if (type === Warning$1) {
3291
3287
  return warningIconNode;
3292
3288
  }
3293
3289
  return errorIconNode;
@@ -3306,6 +3302,34 @@ const getProblemSourceDetail = (source, code) => {
3306
3302
  return message;
3307
3303
  };
3308
3304
 
3305
+ const leadingSlashesRegex = /^\/+/;
3306
+ const trailingSlashRegex = /\/$/;
3307
+ const schemeRootRegex = /^[a-z][a-z\d+.-]*:\/\/$/i;
3308
+ const windowsDrivePathRegex = /^\/[a-z]:\//i;
3309
+ const normalizeFileUri = uri => {
3310
+ const normalizedUri = uri.startsWith('file://') ? uri.slice('file://'.length) : uri;
3311
+ return windowsDrivePathRegex.test(normalizedUri) ? normalizedUri.slice(1) : normalizedUri;
3312
+ };
3313
+ const getRelativeParentUri = (uri, workspaceUri) => {
3314
+ const normalizedUri = normalizeFileUri(uri);
3315
+ const normalizedWorkspaceUri = normalizeFileUri(workspaceUri).replace(trailingSlashRegex, '');
3316
+ const slashIndex = normalizedUri.lastIndexOf('/');
3317
+ if (slashIndex === -1) {
3318
+ return '';
3319
+ }
3320
+ const parentUri = normalizedUri.slice(0, slashIndex);
3321
+ if (schemeRootRegex.test(parentUri)) {
3322
+ return '';
3323
+ }
3324
+ if (parentUri === normalizedWorkspaceUri) {
3325
+ return '';
3326
+ }
3327
+ if (normalizedWorkspaceUri && parentUri.startsWith(`${normalizedWorkspaceUri}/`)) {
3328
+ return parentUri.slice(normalizedWorkspaceUri.length + 1);
3329
+ }
3330
+ return parentUri.replace(leadingSlashesRegex, '');
3331
+ };
3332
+
3309
3333
  const labelNode = {
3310
3334
  childCount: 1,
3311
3335
  className: Label,
@@ -3326,7 +3350,7 @@ const problemAtNode = {
3326
3350
  className: ProblemAt,
3327
3351
  type: Span
3328
3352
  };
3329
- const getProblemVirtualDom = problem => {
3353
+ const getProblemVirtualDom = (problem, workspaceUri = '') => {
3330
3354
  const {
3331
3355
  code,
3332
3356
  columnIndex,
@@ -3340,7 +3364,6 @@ const getProblemVirtualDom = problem => {
3340
3364
  message,
3341
3365
  messageMatchIndex,
3342
3366
  posInSet,
3343
- relativePath,
3344
3367
  rowIndex,
3345
3368
  setSize,
3346
3369
  source,
@@ -3369,7 +3392,7 @@ const getProblemVirtualDom = problem => {
3369
3392
  ...labelNode,
3370
3393
  'data-uri': uri,
3371
3394
  onClick: HandleFileNameClick
3372
- }, text(fileName), labelDetailNode, text(relativePath), ...getBadgeVirtualDom(ProblemBadge, problem.count)];
3395
+ }, text(fileName), labelDetailNode, text(getRelativeParentUri(uri, workspaceUri)), ...getBadgeVirtualDom(ProblemBadge, problem.count)];
3373
3396
  }
3374
3397
  const lineColumn = atLineColumn(rowIndex + 1, columnIndex + 1);
3375
3398
  const label = {
@@ -3403,7 +3426,7 @@ const getProblemVirtualDom = problem => {
3403
3426
  return dom;
3404
3427
  };
3405
3428
 
3406
- const getProblemsListVirtualDom = problems => {
3429
+ const getProblemsListVirtualDom = (problems, workspaceUri = '') => {
3407
3430
  const dom = [{
3408
3431
  ariaLabel: 'Problems Tree',
3409
3432
  // TODO use i18n string
@@ -3411,7 +3434,7 @@ const getProblemsListVirtualDom = problems => {
3411
3434
  className: ProblemsList,
3412
3435
  role: Tree,
3413
3436
  type: Div
3414
- }, ...problems.flatMap(getProblemVirtualDom)];
3437
+ }, ...problems.flatMap(problem => getProblemVirtualDom(problem, workspaceUri))];
3415
3438
  return dom;
3416
3439
  };
3417
3440
 
@@ -3510,7 +3533,7 @@ const messageNode = {
3510
3533
  className: Message,
3511
3534
  type: Div
3512
3535
  };
3513
- const getProblemsVirtualDom$1 = (viewMode, problems, filterValue, message, problemCount = problems.length) => {
3536
+ const getProblemsVirtualDom$1 = (viewMode, problems, filterValue, message, problemCount = problems.length, workspaceUri = '') => {
3514
3537
  if (problemCount === 0 && message) {
3515
3538
  return [messageNode, text(message)];
3516
3539
  }
@@ -3523,7 +3546,7 @@ const getProblemsVirtualDom$1 = (viewMode, problems, filterValue, message, probl
3523
3546
  if (viewMode === Table) {
3524
3547
  return getProblemsTableVirtualDom(problems);
3525
3548
  }
3526
- return getProblemsListVirtualDom(problems);
3549
+ return getProblemsListVirtualDom(problems, workspaceUri);
3527
3550
  };
3528
3551
 
3529
3552
  const scrollBarNode = {
@@ -3545,7 +3568,7 @@ const getScrollBarVirtualDom = (scrollBarHeight, scrollBarActive) => {
3545
3568
 
3546
3569
  const Focusable = 0;
3547
3570
 
3548
- const getProblemsVirtualDom = (activeUri, viewMode, problems, filterValue, inputSource, isSmall, message, scrollBarHeight = 0, scrollBarActive = false, problemCount = problems.length) => {
3571
+ const getProblemsVirtualDom = (activeUri, viewMode, problems, filterValue, inputSource, isSmall, message, scrollBarHeight = 0, scrollBarActive = false, problemCount = problems.length, workspaceUri = '') => {
3549
3572
  const baseDom = {
3550
3573
  childCount: isSmall ? 2 : 1,
3551
3574
  className: mergeClassNames(Viewlet, Problems),
@@ -3564,7 +3587,7 @@ const getProblemsVirtualDom = (activeUri, viewMode, problems, filterValue, input
3564
3587
  placeholder: filter(),
3565
3588
  value: filterValue
3566
3589
  }) : [];
3567
- const itemsDom = getProblemsVirtualDom$1(viewMode, problems, filterValue, message, problemCount);
3590
+ const itemsDom = getProblemsVirtualDom$1(viewMode, problems, filterValue, message, problemCount, workspaceUri);
3568
3591
  const scrollBarDom = getScrollBarVirtualDom(scrollBarHeight, scrollBarActive);
3569
3592
  const contentClassName = viewMode === Table ? mergeClassNames(ProblemsContent, ProblemsContentTable) : ProblemsContent;
3570
3593
  const contentDom = {
@@ -3594,12 +3617,13 @@ const renderItems = (oldState, newState) => {
3594
3617
  showWarnings,
3595
3618
  smallWidthBreakPoint,
3596
3619
  viewMode,
3597
- width
3620
+ width,
3621
+ workspaceUri
3598
3622
  } = newState;
3599
3623
  const problemCount = getVisibleProblemCount(problems, collapsedUris, filterValue, viewMode, showErrors, showWarnings, showInfos);
3600
3624
  const visible = getVisibleProblems(problems, fileIconCache, collapsedUris, focusedIndex, filterValue, minLineY, maxLineY, viewMode, showErrors, showWarnings, showInfos);
3601
3625
  const isSmall = width <= smallWidthBreakPoint;
3602
- const dom = getProblemsVirtualDom(activeUri, viewMode, visible, filterValue, inputSource, isSmall, message, scrollBarHeight, scrollBarActive, problemCount);
3626
+ const dom = getProblemsVirtualDom(activeUri, viewMode, visible, filterValue, inputSource, isSmall, message, scrollBarHeight, scrollBarActive, problemCount, workspaceUri);
3603
3627
  return ['Viewlet.setDom2', newState.uid, dom];
3604
3628
  };
3605
3629
 
@@ -3801,6 +3825,23 @@ const saveState = state => {
3801
3825
  };
3802
3826
  };
3803
3827
 
3828
+ const applyComponentState = (currentState, state) => {
3829
+ if (!state || typeof state !== 'object' || Array.isArray(state)) {
3830
+ throw new TypeError('Problems state must be an object');
3831
+ }
3832
+ const {
3833
+ uid
3834
+ } = state;
3835
+ const {
3836
+ uid: currentUid
3837
+ } = currentState;
3838
+ if (uid !== currentUid) {
3839
+ throw new Error(`Problems state uid must remain ${currentUid}`);
3840
+ }
3841
+ return state;
3842
+ };
3843
+ const setComponentState = wrapCommand(applyComponentState);
3844
+
3804
3845
  const toggleFileGroup = (state, uri) => {
3805
3846
  const {
3806
3847
  collapsedUris
@@ -3850,6 +3891,7 @@ const commandMap = {
3850
3891
  'Problems.diff2': diff2,
3851
3892
  'Problems.focusIndex': wrapCommand(focusIndex),
3852
3893
  'Problems.getCommandIds': getCommandIds,
3894
+ 'Problems.getComponentState': getComponentState,
3853
3895
  'Problems.getKeyBindings': getKeyBindings,
3854
3896
  'Problems.getMenuEntries2': wrapGetter(getMenuEntries2),
3855
3897
  'Problems.getMenuIds': getMenuIds,
@@ -3878,6 +3920,7 @@ const commandMap = {
3878
3920
  'Problems.renderEventListeners': renderEventListeners,
3879
3921
  'Problems.resize': resize,
3880
3922
  'Problems.saveState': wrapGetter(saveState),
3923
+ 'Problems.setComponentState': setComponentState,
3881
3924
  'Problems.terminate': terminate,
3882
3925
  'Problems.toggleFileGroup': wrapCommand(toggleFileGroup),
3883
3926
  'Problems.toggleShowErrors': wrapCommand(toggleShowErrors),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/problems-view",
3
- "version": "1.34.2",
3
+ "version": "1.36.0",
4
4
  "description": "Problems View Worker",
5
5
  "repository": {
6
6
  "type": "git",