@lvce-editor/activity-bar-worker 1.14.0 → 1.16.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.
@@ -1251,20 +1251,34 @@ const findIndex = (activityBarItems, id) => {
1251
1251
  return -1;
1252
1252
  };
1253
1253
 
1254
- const getNewItems = (items, selectedIndex) => {
1255
- return items.map(item => {
1256
- return {
1257
- ...item
1258
- // TODO set selected property if it matches the selected index
1259
- };
1254
+ const Tab = 1;
1255
+ const Button = 1 << 1;
1256
+ const Progress = 1 << 2;
1257
+ const Enabled = 1 << 3;
1258
+ const Selected = 1 << 4;
1259
+ const Focused = 1 << 5;
1260
+ const MarginTop = 1 << 6;
1261
+
1262
+ const setFlag = (item, flag, enabled) => {
1263
+ return {
1264
+ ...item,
1265
+ flags: enabled ? item.flags | flag : item.flags & ~flag
1266
+ };
1267
+ };
1268
+
1269
+ const markSelected = (items, selectedIndex) => {
1270
+ return items.map((item, index) => {
1271
+ const isSelected = index === selectedIndex;
1272
+ return setFlag(item, Selected, isSelected);
1260
1273
  });
1261
1274
  };
1275
+
1262
1276
  const handleSideBarViewletChange = (state, id, ...args) => {
1263
1277
  const {
1264
1278
  activityBarItems
1265
1279
  } = state;
1266
1280
  const index = findIndex(activityBarItems, id);
1267
- const newActivityBarItems = getNewItems(activityBarItems);
1281
+ const newActivityBarItems = markSelected(activityBarItems, index);
1268
1282
  return {
1269
1283
  ...state,
1270
1284
  selectedIndex: index,
@@ -1273,14 +1287,6 @@ const handleSideBarViewletChange = (state, id, ...args) => {
1273
1287
  };
1274
1288
  };
1275
1289
 
1276
- const Tab = 1;
1277
- const Button = 1 << 1;
1278
- const Progress = 1 << 2;
1279
- const Enabled = 1 << 3;
1280
- const Selected = 1 << 4;
1281
- const Focused = 1 << 5;
1282
- const MarginTop = 1 << 6;
1283
-
1284
1290
  const emptyObject = {};
1285
1291
  const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1286
1292
  const i18nString = (key, placeholders = emptyObject) => {
@@ -1382,11 +1388,14 @@ const getActivityBarItems = () => {
1382
1388
 
1383
1389
  const loadContent = async (state, savedState) => {
1384
1390
  const items = getActivityBarItems();
1391
+ const explorerIndex = 0;
1392
+ const itemsWithSelected = markSelected(items, explorerIndex);
1385
1393
  return {
1386
1394
  ...state,
1387
- activityBarItems: items,
1395
+ activityBarItems: itemsWithSelected,
1388
1396
  sideBarVisible: true,
1389
- currentViewletId: Explorer
1397
+ currentViewletId: Explorer,
1398
+ selectedIndex: explorerIndex
1390
1399
  };
1391
1400
  };
1392
1401
 
@@ -1623,10 +1632,25 @@ const renderEventListeners = () => {
1623
1632
 
1624
1633
  const saveState = state => {
1625
1634
  const {
1626
- uid
1635
+ uid,
1636
+ currentViewletId
1627
1637
  } = state;
1628
1638
  return {
1629
- uid
1639
+ uid,
1640
+ currentViewletId
1641
+ };
1642
+ };
1643
+
1644
+ const isEnabled = activityBarItem => {
1645
+ return activityBarItem.enabled;
1646
+ };
1647
+ const toggleActivityBarItem = async (state, item) => {
1648
+ const activityBarItem = state.activityBarItems.find(activityBarItem => activityBarItem.id === item.label);
1649
+ // @ts-ignore
1650
+ activityBarItem.enabled = !activityBarItem.enabled;
1651
+ return {
1652
+ ...state,
1653
+ activityBarItems: state.activityBarItems.filter(isEnabled)
1630
1654
  };
1631
1655
  };
1632
1656
 
@@ -1642,17 +1666,18 @@ const commandMap = {
1642
1666
  'ActivityBar.getCommandIds': getCommandIds,
1643
1667
  'ActivityBar.getKeyBindings': getKeyBindings,
1644
1668
  'ActivityBar.handleBlur': wrapCommand(handleBlur),
1645
- 'ActivityBar.handleResize': wrapCommand(handleResize),
1646
1669
  'ActivityBar.handleClick': wrapCommand(handleClick),
1670
+ 'ActivityBar.handleClickIndex': wrapCommand(handleClickIndex),
1647
1671
  'ActivityBar.handleContextMenu': wrapCommand(handleContextMenu),
1672
+ 'ActivityBar.handleResize': wrapCommand(handleResize),
1648
1673
  'ActivityBar.handleSideBarHidden': wrapCommand(handleSideBarHidden),
1649
- 'ActivityBar.handleClickIndex': wrapCommand(handleClickIndex),
1650
1674
  'ActivityBar.handleSideBarViewletChange': wrapCommand(handleSideBarViewletChange),
1651
1675
  'ActivityBar.loadContent': wrapCommand(loadContent),
1652
1676
  'ActivityBar.render2': render2,
1653
1677
  'ActivityBar.renderEventListeners': renderEventListeners,
1654
1678
  'ActivityBar.saveState': wrapGetter(saveState),
1655
- 'ActivityBar.terminate': terminate
1679
+ 'ActivityBar.terminate': terminate,
1680
+ 'ActivityBar.toggleActivityBarItem': wrapCommand(toggleActivityBarItem)
1656
1681
  };
1657
1682
 
1658
1683
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/activity-bar-worker",
3
- "version": "1.14.0",
3
+ "version": "1.16.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",