@lvce-editor/problems-view 1.2.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.
@@ -1013,6 +1013,7 @@ const copyMessage = async state => {
1013
1013
  };
1014
1014
 
1015
1015
  const User = 1;
1016
+ const Script = 2;
1016
1017
 
1017
1018
  const {
1018
1019
  get,
@@ -1022,6 +1023,7 @@ const {
1022
1023
 
1023
1024
  const None$1 = 0;
1024
1025
  const Table = 1;
1026
+ const List = 2;
1025
1027
 
1026
1028
  const create = (id, uri, x, y, width, height, args, parentUid) => {
1027
1029
  const state = {
@@ -1085,11 +1087,13 @@ const focusIndex = (state, index) => {
1085
1087
  };
1086
1088
 
1087
1089
  const None = 'none';
1090
+ const ToolBar = 'toolbar';
1088
1091
  const Tree$1 = 'tree';
1089
1092
  const TreeItem$1 = 'treeitem';
1090
1093
  const AriaRoles = {
1091
1094
  __proto__: null,
1092
1095
  None,
1096
+ ToolBar,
1093
1097
  Tree: Tree$1,
1094
1098
  TreeItem: TreeItem$1
1095
1099
  };
@@ -1117,7 +1121,7 @@ const KeyCode = {
1117
1121
  const mergeClassNames = (...classNames) => {
1118
1122
  return classNames.filter(Boolean).join(' ');
1119
1123
  };
1120
- const Button = 1;
1124
+ const Button$1 = 1;
1121
1125
  const Div = 4;
1122
1126
  const Input = 6;
1123
1127
  const Span = 8;
@@ -1127,7 +1131,7 @@ const A = 53;
1127
1131
  const VirtualDomElements = {
1128
1132
  __proto__: null,
1129
1133
  A,
1130
- Button,
1134
+ Button: Button$1,
1131
1135
  Div,
1132
1136
  Img,
1133
1137
  Input,
@@ -1259,19 +1263,190 @@ const handleArrowRight = state => {
1259
1263
  };
1260
1264
  };
1261
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
+
1295
+ const handleContextMenu = async (state, eventX, eventY) => {
1296
+ // @ts-ignore
1297
+ // await ContextMenu.show(eventX, eventY, MenuEntryId.Problems)
1298
+ return state;
1299
+ };
1300
+
1301
+ const handleIconThemeChange = state => {
1302
+ return {
1303
+ ...state,
1304
+ problems: [...state.problems]
1305
+ };
1306
+ };
1307
+
1262
1308
  const initialize = async () => {
1263
1309
  // TODO create connection to editor worker
1264
1310
  };
1265
1311
 
1312
+ const getProblems = async state => {
1313
+ // TODO ask editor worker for problems
1314
+ return [];
1315
+ };
1316
+
1317
+ const emptyObject = {};
1318
+ const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1319
+ const i18nString = (key, placeholders = emptyObject) => {
1320
+ if (placeholders === emptyObject) {
1321
+ return key;
1322
+ }
1323
+ const replacer = (match, rest) => {
1324
+ return placeholders[rest];
1325
+ };
1326
+ return key.replaceAll(RE_PLACEHOLDER, replacer);
1327
+ };
1328
+
1329
+ const ClearFilters = 'Clear Filters';
1330
+ const Code = 'Code';
1331
+ const File = 'File';
1332
+ const Filter$3 = 'Filter';
1333
+ const LineColumn = '[Ln {PH1}, Col {PH2}]';
1334
+ const Message$1 = 'Message';
1335
+ const NoProblemsDetected = 'No problems have been detected in the workspace.';
1336
+ const NoResultsFoundWithProvidedFilterCriteria = 'No results found with provided filter criteria.';
1337
+ const ProblemsDetected = 'Some problems have been detected in the workspace.';
1338
+ const ShowingOfItems = 'Showing {PH1} of {PH2} ';
1339
+ const Source = 'Source';
1340
+ const CollapseAll$1 = 'Collapse All';
1341
+ const ViewAsTable = 'View as Table';
1342
+ const ViewAsList = 'View as List';
1343
+
1344
+ const noProblemsDetected = () => {
1345
+ return i18nString(NoProblemsDetected);
1346
+ };
1347
+ const getMessage = problemsCount => {
1348
+ if (problemsCount === 0) {
1349
+ return i18nString(NoProblemsDetected);
1350
+ }
1351
+ return i18nString(ProblemsDetected);
1352
+ };
1353
+ const atLineColumn = (line, column) => {
1354
+ return i18nString(LineColumn, {
1355
+ PH1: line,
1356
+ PH2: column
1357
+ });
1358
+ };
1359
+ const clearFilter = () => {
1360
+ return i18nString(ClearFilters);
1361
+ };
1362
+ const code = () => {
1363
+ return i18nString(Code);
1364
+ };
1365
+ const message = () => {
1366
+ return i18nString(Message$1);
1367
+ };
1368
+ const file = () => {
1369
+ return i18nString(File);
1370
+ };
1371
+ const filter = () => {
1372
+ return i18nString(Filter$3);
1373
+ };
1374
+ const showingOf = (visibleCount, totalCount) => {
1375
+ return i18nString(ShowingOfItems, {
1376
+ PH1: visibleCount,
1377
+ PH2: totalCount
1378
+ });
1379
+ };
1380
+ const source = () => {
1381
+ return i18nString(Source);
1382
+ };
1383
+ const noResultsFoundWithProvidedFilterCriteria = () => {
1384
+ return i18nString(NoResultsFoundWithProvidedFilterCriteria);
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
+ };
1395
+
1396
+ const getSavedViewMode = savedState => {
1397
+ if (savedState && typeof savedState.viewMode === 'number') {
1398
+ return savedState.viewMode;
1399
+ }
1400
+ return List;
1401
+ };
1402
+ const getSavedFilterValue = savedState => {
1403
+ if (savedState && typeof savedState.filterValue === 'string') {
1404
+ return savedState.filterValue;
1405
+ }
1406
+ return '';
1407
+ };
1408
+ const isString = value => {
1409
+ return typeof value === 'string';
1410
+ };
1411
+ const getSavedCollapsedUris = savedState => {
1412
+ if (savedState && savedState.collapsedUris && Array.isArray(savedState.collapsedUris) && savedState.collapsedUris.every(isString)) {
1413
+ return savedState.collapsedUris;
1414
+ }
1415
+ return [];
1416
+ };
1417
+ const loadContent = async (state, savedState) => {
1418
+ const problems = await getProblems();
1419
+ const message = getMessage(problems.length);
1420
+ const viewMode = getSavedViewMode(savedState);
1421
+ const filterValue = getSavedFilterValue(savedState);
1422
+ const collapsedUris = getSavedCollapsedUris(savedState);
1423
+ return {
1424
+ ...state,
1425
+ problems,
1426
+ message,
1427
+ viewMode,
1428
+ filterValue,
1429
+ inputSource: Script,
1430
+ filteredProblems: problems,
1431
+ listItems: [],
1432
+ collapsedUris
1433
+ };
1434
+ };
1435
+
1436
+ const Button = 1;
1437
+ const ProblemsFilter = 4;
1438
+
1266
1439
  const Chevron = 'Chevron';
1267
1440
  const FileIcon = 'FileIcon';
1268
- const Filter$3 = 'Filter';
1441
+ const Filter$2 = 'Filter';
1442
+ const FilterBadge = 'FilterBadge';
1269
1443
  const Highlight = 'Highlight';
1270
1444
  const IconButton = 'IconButton';
1271
1445
  const InputBox = 'InputBox';
1272
1446
  const Label = 'Label';
1447
+ const Actions = 'Actions';
1273
1448
  const LabelDetail = 'LabelDetail';
1274
- const Message$1 = 'Message';
1449
+ const Message = 'Message';
1275
1450
  const MessageAction = 'MessageAction';
1276
1451
  const Problem = 'Problem';
1277
1452
  const ProblemAt = 'ProblemAt';
@@ -1320,16 +1495,19 @@ const getActionButtonVirtualDom = action => {
1320
1495
  }, getIconVirtualDom(icon)];
1321
1496
  };
1322
1497
 
1323
- const Filter$2 = 'filter';
1498
+ const Filter$1 = 'filter';
1324
1499
 
1325
- const Filter$1 = 'Filter';
1500
+ const CollapseAll = 'CollapseAll';
1501
+ const Filter = 'Filter';
1502
+ const ListFlat = 'ListFlat';
1503
+ const ListTree = 'ListTree';
1326
1504
 
1327
1505
  const getProblemsFilterVirtualDom = action => {
1328
1506
  // TODO avoid mutation
1329
1507
  const dom = [];
1330
1508
  dom.push({
1331
1509
  type: VirtualDomElements.Div,
1332
- className: Filter$3,
1510
+ className: Filter$2,
1333
1511
  childCount: 1
1334
1512
  }, {
1335
1513
  type: VirtualDomElements.Input,
@@ -1339,14 +1517,23 @@ const getProblemsFilterVirtualDom = action => {
1339
1517
  autocorrect: 'off',
1340
1518
  placeholder: action.placeholder,
1341
1519
  onInput: action.command,
1342
- name: Filter$2,
1520
+ name: Filter$1,
1343
1521
  value: action.value
1344
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
+ }
1345
1532
  // @ts-ignore
1346
1533
  dom[0].childCount++;
1347
1534
  dom.push(...getActionButtonVirtualDom({
1348
1535
  id: 'more filters',
1349
- icon: Filter$1,
1536
+ icon: Filter,
1350
1537
  command: 'more filters'
1351
1538
  }));
1352
1539
  return dom;
@@ -1421,59 +1608,6 @@ const getTreeItemIndent = depth => {
1421
1608
  return `${depth * defaultIndent}rem`;
1422
1609
  };
1423
1610
 
1424
- const emptyObject = {};
1425
- const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1426
- const i18nString = (key, placeholders = emptyObject) => {
1427
- if (placeholders === emptyObject) {
1428
- return key;
1429
- }
1430
- const replacer = (match, rest) => {
1431
- return placeholders[rest];
1432
- };
1433
- return key.replaceAll(RE_PLACEHOLDER, replacer);
1434
- };
1435
-
1436
- const ClearFilters = 'Clear Filters';
1437
- const Code = 'Code';
1438
- const File = 'File';
1439
- const Filter = 'Filter';
1440
- const LineColumn = '[Ln {PH1}, Col {PH2}]';
1441
- const Message = 'Message';
1442
- const NoProblemsDetected = 'No problems have been detected in the workspace.';
1443
- const NoResultsFoundWithProvidedFilterCriteria = 'No results found with provided filter criteria.';
1444
- const Source = 'Source';
1445
-
1446
- const noProblemsDetected = () => {
1447
- return i18nString(NoProblemsDetected);
1448
- };
1449
- const atLineColumn = (line, column) => {
1450
- return i18nString(LineColumn, {
1451
- PH1: line,
1452
- PH2: column
1453
- });
1454
- };
1455
- const clearFilter = () => {
1456
- return i18nString(ClearFilters);
1457
- };
1458
- const code = () => {
1459
- return i18nString(Code);
1460
- };
1461
- const message = () => {
1462
- return i18nString(Message);
1463
- };
1464
- const file = () => {
1465
- return i18nString(File);
1466
- };
1467
- const filter = () => {
1468
- return i18nString(Filter);
1469
- };
1470
- const source = () => {
1471
- return i18nString(Source);
1472
- };
1473
- const noResultsFoundWithProvidedFilterCriteria = () => {
1474
- return i18nString(NoResultsFoundWithProvidedFilterCriteria);
1475
- };
1476
-
1477
1611
  const getProblemVirtualDom = problem => {
1478
1612
  const {
1479
1613
  message,
@@ -1573,7 +1707,7 @@ const getProblemsNoProblemsFoundVirtualDom = filterValue => {
1573
1707
  const dom = [];
1574
1708
  dom.push({
1575
1709
  type: VirtualDomElements.Div,
1576
- className: Message$1,
1710
+ className: Message,
1577
1711
  childCount: 1
1578
1712
  });
1579
1713
  if (filterValue) {
@@ -1723,6 +1857,7 @@ const getProblemsVirtualDom = (viewMode, problems, filterValue, isSmall) => {
1723
1857
  dom[0].childCount++;
1724
1858
  dom.push(...getProblemsFilterVirtualDom({
1725
1859
  command: HandleFilterInput,
1860
+ badgeText: '',
1726
1861
  placeholder: filter(),
1727
1862
  value: ''
1728
1863
  }));
@@ -1838,6 +1973,87 @@ const render2 = (uid, diffResult) => {
1838
1973
  return commands;
1839
1974
  };
1840
1975
 
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 => {
1988
+ return [{
1989
+ type: VirtualDomElements.Div,
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;
2038
+ };
2039
+
2040
+ const renderEventListeners = () => {
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
+ }];
2055
+ };
2056
+
1841
2057
  const resize = (state, dimensions) => {
1842
2058
  return {
1843
2059
  ...state,
@@ -1858,8 +2074,23 @@ const saveState = state => {
1858
2074
  };
1859
2075
  };
1860
2076
 
2077
+ const viewAsList = state => {
2078
+ return {
2079
+ ...state,
2080
+ viewMode: List
2081
+ };
2082
+ };
2083
+
2084
+ const viewAsTable = state => {
2085
+ return {
2086
+ ...state,
2087
+ viewMode: Table
2088
+ };
2089
+ };
2090
+
1861
2091
  const commandMap = {
1862
2092
  'Problems.copyMessage': copyMessage,
2093
+ 'Problems.renderEventListeners': renderEventListeners,
1863
2094
  'Problems.create': create,
1864
2095
  'Problems.diff2': diff2,
1865
2096
  'Problems.focusIndex': focusIndex,
@@ -1867,10 +2098,17 @@ const commandMap = {
1867
2098
  'Problems.handleArrowLeft': wrapCommand(handleArrowLeft),
1868
2099
  'Problems.handleArrowRight': wrapCommand(handleArrowRight),
1869
2100
  'Problems.initialize': initialize,
2101
+ 'Problems.loadContent': wrapCommand(loadContent),
1870
2102
  'Problems.render2': render2,
2103
+ 'Problems.renderActions': renderActions,
1871
2104
  'Problems.resize': resize,
1872
2105
  'Problems.saveState': saveState,
1873
- 'Problems.terminate': terminate
2106
+ 'Problems.terminate': terminate,
2107
+ 'Problems.handleIconThemeChange': handleIconThemeChange,
2108
+ 'Problems.handleContextMenu': handleContextMenu,
2109
+ 'Problems.viewAsTable': viewAsTable,
2110
+ 'Problems.viewAsList': viewAsList,
2111
+ 'Problems.handleClickAt': wrapCommand(handleClickAt)
1874
2112
  };
1875
2113
 
1876
2114
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/problems-view",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Problems View Worker",
5
5
  "repository": {
6
6
  "type": "git",