@lvce-editor/activity-bar-worker 1.13.0 → 1.15.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.
@@ -1242,6 +1242,14 @@ const handleSideBarHidden = state => {
1242
1242
  };
1243
1243
  };
1244
1244
 
1245
+ const Tab = 1;
1246
+ const Button = 1 << 1;
1247
+ const Progress = 1 << 2;
1248
+ const Enabled = 1 << 3;
1249
+ const Selected = 1 << 4;
1250
+ const Focused = 1 << 5;
1251
+ const MarginTop = 1 << 6;
1252
+
1245
1253
  const findIndex = (activityBarItems, id) => {
1246
1254
  for (let i = 0; i < activityBarItems.length; i++) {
1247
1255
  if (activityBarItems[i].id === id) {
@@ -1251,12 +1259,17 @@ const findIndex = (activityBarItems, id) => {
1251
1259
  return -1;
1252
1260
  };
1253
1261
 
1262
+ const setFlag = (item, flag, enabled) => {
1263
+ return {
1264
+ ...item,
1265
+ flags: enabled ? item.flags | flag : item.flags & ~flag
1266
+ };
1267
+ };
1268
+
1254
1269
  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
- };
1270
+ return items.map((item, index) => {
1271
+ const isSelected = index === selectedIndex;
1272
+ return setFlag(item, Selected, isSelected);
1260
1273
  });
1261
1274
  };
1262
1275
  const handleSideBarViewletChange = (state, id, ...args) => {
@@ -1264,7 +1277,7 @@ const handleSideBarViewletChange = (state, id, ...args) => {
1264
1277
  activityBarItems
1265
1278
  } = state;
1266
1279
  const index = findIndex(activityBarItems, id);
1267
- const newActivityBarItems = getNewItems(activityBarItems);
1280
+ const newActivityBarItems = getNewItems(activityBarItems, index);
1268
1281
  return {
1269
1282
  ...state,
1270
1283
  selectedIndex: index,
@@ -1273,14 +1286,6 @@ const handleSideBarViewletChange = (state, id, ...args) => {
1273
1286
  };
1274
1287
  };
1275
1288
 
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
1289
  const emptyObject = {};
1285
1290
  const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1286
1291
  const i18nString = (key, placeholders = emptyObject) => {
@@ -1630,6 +1635,19 @@ const saveState = state => {
1630
1635
  };
1631
1636
  };
1632
1637
 
1638
+ const isEnabled = activityBarItem => {
1639
+ return activityBarItem.enabled;
1640
+ };
1641
+ const toggleActivityBarItem = async (state, item) => {
1642
+ const activityBarItem = state.activityBarItems.find(activityBarItem => activityBarItem.id === item.label);
1643
+ // @ts-ignore
1644
+ activityBarItem.enabled = !activityBarItem.enabled;
1645
+ return {
1646
+ ...state,
1647
+ activityBarItems: state.activityBarItems.filter(isEnabled)
1648
+ };
1649
+ };
1650
+
1633
1651
  const commandMap = {
1634
1652
  'ActivityBar.create': create,
1635
1653
  'ActivityBar.diff2': diff2,
@@ -1642,17 +1660,18 @@ const commandMap = {
1642
1660
  'ActivityBar.getCommandIds': getCommandIds,
1643
1661
  'ActivityBar.getKeyBindings': getKeyBindings,
1644
1662
  'ActivityBar.handleBlur': wrapCommand(handleBlur),
1645
- 'ActivityBar.handleResize': wrapCommand(handleResize),
1646
1663
  'ActivityBar.handleClick': wrapCommand(handleClick),
1664
+ 'ActivityBar.handleClickIndex': wrapCommand(handleClickIndex),
1647
1665
  'ActivityBar.handleContextMenu': wrapCommand(handleContextMenu),
1666
+ 'ActivityBar.handleResize': wrapCommand(handleResize),
1648
1667
  'ActivityBar.handleSideBarHidden': wrapCommand(handleSideBarHidden),
1649
- 'ActivityBar.handleClickIndex': wrapCommand(handleClickIndex),
1650
1668
  'ActivityBar.handleSideBarViewletChange': wrapCommand(handleSideBarViewletChange),
1651
1669
  'ActivityBar.loadContent': wrapCommand(loadContent),
1652
1670
  'ActivityBar.render2': render2,
1653
1671
  'ActivityBar.renderEventListeners': renderEventListeners,
1654
1672
  'ActivityBar.saveState': wrapGetter(saveState),
1655
- 'ActivityBar.terminate': terminate
1673
+ 'ActivityBar.terminate': terminate,
1674
+ 'ActivityBar.toggleActivityBarItem': wrapCommand(toggleActivityBarItem)
1656
1675
  };
1657
1676
 
1658
1677
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/activity-bar-worker",
3
- "version": "1.13.0",
3
+ "version": "1.15.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",