@lvce-editor/problems-view 1.3.0 → 1.4.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.
@@ -1087,11 +1087,13 @@ const focusIndex = (state, index) => {
1087
1087
  };
1088
1088
 
1089
1089
  const None = 'none';
1090
+ const ToolBar = 'toolbar';
1090
1091
  const Tree$1 = 'tree';
1091
1092
  const TreeItem$1 = 'treeitem';
1092
1093
  const AriaRoles = {
1093
1094
  __proto__: null,
1094
1095
  None,
1096
+ ToolBar,
1095
1097
  Tree: Tree$1,
1096
1098
  TreeItem: TreeItem$1
1097
1099
  };
@@ -1119,7 +1121,7 @@ const KeyCode = {
1119
1121
  const mergeClassNames = (...classNames) => {
1120
1122
  return classNames.filter(Boolean).join(' ');
1121
1123
  };
1122
- const Button = 1;
1124
+ const Button$1 = 1;
1123
1125
  const Div = 4;
1124
1126
  const Input = 6;
1125
1127
  const Span = 8;
@@ -1129,7 +1131,7 @@ const A = 53;
1129
1131
  const VirtualDomElements = {
1130
1132
  __proto__: null,
1131
1133
  A,
1132
- Button,
1134
+ Button: Button$1,
1133
1135
  Div,
1134
1136
  Img,
1135
1137
  Input,
@@ -1261,6 +1263,35 @@ const handleArrowRight = state => {
1261
1263
  };
1262
1264
  };
1263
1265
 
1266
+ const getListIndex = (eventX, eventY, x, y, deltaY, itemHeight) => {
1267
+ const relativeY = eventY - y + deltaY;
1268
+ const index = Math.floor(relativeY / itemHeight);
1269
+ return index;
1270
+ };
1271
+
1272
+ const handleClickAt = (state, eventX, eventY) => {
1273
+ const {
1274
+ problems,
1275
+ x,
1276
+ y,
1277
+ itemHeight
1278
+ } = state;
1279
+
1280
+ // TODO use functional focus rendering
1281
+ // Focus.setFocus(FocusKey.Problems)
1282
+ if (problems.length === 0) {
1283
+ return focusIndex(state, -1);
1284
+ }
1285
+ const index = getListIndex(eventX, eventY, x, y, 0, itemHeight);
1286
+ if (index > problems.length) {
1287
+ return focusIndex(state, -1);
1288
+ }
1289
+ return {
1290
+ ...state,
1291
+ focusedIndex: index
1292
+ };
1293
+ };
1294
+
1264
1295
  const handleContextMenu = async (state, eventX, eventY) => {
1265
1296
  // @ts-ignore
1266
1297
  // await ContextMenu.show(eventX, eventY, MenuEntryId.Problems)
@@ -1304,7 +1335,11 @@ const Message$1 = 'Message';
1304
1335
  const NoProblemsDetected = 'No problems have been detected in the workspace.';
1305
1336
  const NoResultsFoundWithProvidedFilterCriteria = 'No results found with provided filter criteria.';
1306
1337
  const ProblemsDetected = 'Some problems have been detected in the workspace.';
1338
+ const ShowingOfItems = 'Showing {PH1} of {PH2} ';
1307
1339
  const Source = 'Source';
1340
+ const CollapseAll$1 = 'Collapse All';
1341
+ const ViewAsTable = 'View as Table';
1342
+ const ViewAsList = 'View as List';
1308
1343
 
1309
1344
  const noProblemsDetected = () => {
1310
1345
  return i18nString(NoProblemsDetected);
@@ -1336,12 +1371,27 @@ const file = () => {
1336
1371
  const filter = () => {
1337
1372
  return i18nString(Filter$3);
1338
1373
  };
1374
+ const showingOf = (visibleCount, totalCount) => {
1375
+ return i18nString(ShowingOfItems, {
1376
+ PH1: visibleCount,
1377
+ PH2: totalCount
1378
+ });
1379
+ };
1339
1380
  const source = () => {
1340
1381
  return i18nString(Source);
1341
1382
  };
1342
1383
  const noResultsFoundWithProvidedFilterCriteria = () => {
1343
1384
  return i18nString(NoResultsFoundWithProvidedFilterCriteria);
1344
1385
  };
1386
+ const collapseAll = () => {
1387
+ return i18nString(CollapseAll$1);
1388
+ };
1389
+ const viewAsList$1 = () => {
1390
+ return i18nString(ViewAsList);
1391
+ };
1392
+ const viewAsTable$1 = () => {
1393
+ return i18nString(ViewAsTable);
1394
+ };
1345
1395
 
1346
1396
  const getSavedViewMode = savedState => {
1347
1397
  if (savedState && typeof savedState.viewMode === 'number') {
@@ -1383,13 +1433,18 @@ const loadContent = async (state, savedState) => {
1383
1433
  };
1384
1434
  };
1385
1435
 
1436
+ const Button = 1;
1437
+ const ProblemsFilter = 4;
1438
+
1386
1439
  const Chevron = 'Chevron';
1387
1440
  const FileIcon = 'FileIcon';
1388
1441
  const Filter$2 = 'Filter';
1442
+ const FilterBadge = 'FilterBadge';
1389
1443
  const Highlight = 'Highlight';
1390
1444
  const IconButton = 'IconButton';
1391
1445
  const InputBox = 'InputBox';
1392
1446
  const Label = 'Label';
1447
+ const Actions = 'Actions';
1393
1448
  const LabelDetail = 'LabelDetail';
1394
1449
  const Message = 'Message';
1395
1450
  const MessageAction = 'MessageAction';
@@ -1442,7 +1497,10 @@ const getActionButtonVirtualDom = action => {
1442
1497
 
1443
1498
  const Filter$1 = 'filter';
1444
1499
 
1500
+ const CollapseAll = 'CollapseAll';
1445
1501
  const Filter = 'Filter';
1502
+ const ListFlat = 'ListFlat';
1503
+ const ListTree = 'ListTree';
1446
1504
 
1447
1505
  const getProblemsFilterVirtualDom = action => {
1448
1506
  // TODO avoid mutation
@@ -1462,6 +1520,15 @@ const getProblemsFilterVirtualDom = action => {
1462
1520
  name: Filter$1,
1463
1521
  value: action.value
1464
1522
  });
1523
+ if (action.badgeText) {
1524
+ // @ts-ignore
1525
+ dom[0].childCount++;
1526
+ dom.push({
1527
+ type: VirtualDomElements.Div,
1528
+ className: FilterBadge,
1529
+ childCount: 1
1530
+ }, text(action.badgeText));
1531
+ }
1465
1532
  // @ts-ignore
1466
1533
  dom[0].childCount++;
1467
1534
  dom.push(...getActionButtonVirtualDom({
@@ -1790,6 +1857,7 @@ const getProblemsVirtualDom = (viewMode, problems, filterValue, isSmall) => {
1790
1857
  dom[0].childCount++;
1791
1858
  dom.push(...getProblemsFilterVirtualDom({
1792
1859
  command: HandleFilterInput,
1860
+ badgeText: '',
1793
1861
  placeholder: filter(),
1794
1862
  value: ''
1795
1863
  }));
@@ -1905,16 +1973,85 @@ const render2 = (uid, diffResult) => {
1905
1973
  return commands;
1906
1974
  };
1907
1975
 
1908
- const renderActions = () => {
1976
+ const getActionVirtualDom = action => {
1977
+ switch (action.type) {
1978
+ case Button:
1979
+ return getActionButtonVirtualDom(action);
1980
+ case ProblemsFilter:
1981
+ return getProblemsFilterVirtualDom(action);
1982
+ default:
1983
+ return [];
1984
+ }
1985
+ };
1986
+
1987
+ const getActionsVirtualDom = actions => {
1909
1988
  return [{
1910
1989
  type: VirtualDomElements.Div,
1911
- childCount: 1
1912
- }, text('not implemented')];
1990
+ className: Actions,
1991
+ role: AriaRoles.ToolBar,
1992
+ childCount: actions.length
1993
+ }, ...actions.flatMap(getActionVirtualDom)];
1994
+ };
1995
+
1996
+ const getActions = state => {
1997
+ const visibleCount = getVisibleProblems(state.problems, state.collapsedUris, state.focusedIndex, state.filterValue).length;
1998
+ const problemsCount = state.problems.length;
1999
+ const isSmall = state.width <= state.smallWidthBreakPoint;
2000
+ const actions = [];
2001
+ if (!isSmall) {
2002
+ actions.push({
2003
+ type: ProblemsFilter,
2004
+ id: 'Filter',
2005
+ command: HandleFilterInput,
2006
+ badgeText: visibleCount === problemsCount ? '' : showingOf(visibleCount, problemsCount),
2007
+ placeholder: filter(),
2008
+ value: state.inputSource === Script ? state.filterValue : ''
2009
+ });
2010
+ }
2011
+ if (state.viewMode === Table) {
2012
+ actions.push({
2013
+ type: Button,
2014
+ id: viewAsList$1(),
2015
+ command: 'viewAsList',
2016
+ icon: ListTree
2017
+ });
2018
+ } else {
2019
+ actions.push({
2020
+ type: Button,
2021
+ id: collapseAll(),
2022
+ command: 'collapseAll',
2023
+ icon: CollapseAll
2024
+ }, {
2025
+ type: Button,
2026
+ id: viewAsTable$1(),
2027
+ command: 'viewAsTable',
2028
+ icon: ListFlat
2029
+ });
2030
+ }
2031
+ return actions;
2032
+ };
2033
+
2034
+ const renderActions = newState => {
2035
+ const actions = getActions(newState);
2036
+ const dom = getActionsVirtualDom(actions);
2037
+ return dom;
1913
2038
  };
1914
2039
 
1915
2040
  const renderEventListeners = () => {
1916
- // TODO
1917
- return [];
2041
+ return [{
2042
+ name: HandleBlur,
2043
+ params: ['handleBlur']
2044
+ }, {
2045
+ name: HandleContextMenu,
2046
+ params: ['handleContextMenu', 'event.clientX', 'event.clientY'],
2047
+ preventDefault: true
2048
+ }, {
2049
+ name: HandleFilterInput,
2050
+ params: ['handleFilterInput', 'event.target.value']
2051
+ }, {
2052
+ name: HandleClearFilterClick,
2053
+ params: ['clearFilter']
2054
+ }];
1918
2055
  };
1919
2056
 
1920
2057
  const resize = (state, dimensions) => {
@@ -1970,7 +2107,8 @@ const commandMap = {
1970
2107
  'Problems.handleIconThemeChange': handleIconThemeChange,
1971
2108
  'Problems.handleContextMenu': handleContextMenu,
1972
2109
  'Problems.viewAsTable': viewAsTable,
1973
- 'Problems.viewAsList': viewAsList
2110
+ 'Problems.viewAsList': viewAsList,
2111
+ 'Problems.handleClickAt': wrapCommand(handleClickAt)
1974
2112
  };
1975
2113
 
1976
2114
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/problems-view",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Problems View Worker",
5
5
  "repository": {
6
6
  "type": "git",