@lvce-editor/activity-bar-worker 1.4.0 → 1.6.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.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # activity-bar-worker
1
+ # Activity Bar Worker
2
2
 
3
- Activity Bar Worker
3
+ > WebWorker for the Activity Bar functionality in Lvce Editor.
@@ -981,7 +981,7 @@ const isEqual$1 = (oldState, newState) => {
981
981
  };
982
982
 
983
983
  const isEqual = (oldState, newState) => {
984
- return oldState.focusedIndex === newState.focusedIndex;
984
+ return oldState.focusedIndex === newState.focusedIndex && oldState.activityBarItems === newState.activityBarItems;
985
985
  };
986
986
 
987
987
  const RenderItems = 4;
@@ -1054,6 +1054,11 @@ const focusNone = state => {
1054
1054
  return focusIndex(state, -1);
1055
1055
  };
1056
1056
 
1057
+ const Button$1 = 'button';
1058
+ const None = 'none';
1059
+ const Tab$1 = 'tab';
1060
+ const ToolBar = 'toolbar';
1061
+
1057
1062
  const Enter = 3;
1058
1063
  const Space = 9;
1059
1064
  const PageUp = 10;
@@ -1581,12 +1586,125 @@ const handleSideBarViewletChange = (state, id, ...args) => {
1581
1586
  };
1582
1587
  };
1583
1588
 
1589
+ const Tab = 1;
1590
+ const Button = 1 << 1;
1591
+ const Progress = 1 << 2;
1592
+ const Enabled = 1 << 3;
1593
+ const Selected = 1 << 4;
1594
+ const Focused = 1 << 5;
1595
+ const MarginTop = 1 << 6;
1596
+
1597
+ const emptyObject = {};
1598
+ const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1599
+ const i18nString = (key, placeholders = emptyObject) => {
1600
+ if (placeholders === emptyObject) {
1601
+ return key;
1602
+ }
1603
+ const replacer = (match, rest) => {
1604
+ return placeholders[rest];
1605
+ };
1606
+ return key.replaceAll(RE_PLACEHOLDER, replacer);
1607
+ };
1608
+
1609
+ const Explorer$1 = 'Explorer';
1610
+ const Search$2 = 'Search';
1611
+ const SourceControl$2 = 'Source Control';
1612
+ const RunAndDebug$1 = 'Run and Debug';
1613
+ const Extensions$2 = 'Extensions';
1614
+ const Settings = 'Settings';
1615
+ const ActivityBar$2 = 'Activity Bar';
1616
+
1617
+ const explorer = () => {
1618
+ return i18nString(Explorer$1);
1619
+ };
1620
+ const search = () => {
1621
+ return i18nString(Search$2);
1622
+ };
1623
+ const sourceControl = () => {
1624
+ return i18nString(SourceControl$2);
1625
+ };
1626
+ const runAndDebug = () => {
1627
+ return i18nString(RunAndDebug$1);
1628
+ };
1629
+ const extensions = () => {
1630
+ return i18nString(Extensions$2);
1631
+ };
1632
+ const settings = () => {
1633
+ return i18nString(Settings);
1634
+ };
1635
+ const activityBar = () => {
1636
+ return i18nString(ActivityBar$2);
1637
+ };
1638
+
1639
+ const DebugAlt2 = 'DebugAlt2';
1640
+ const Extensions$1 = 'Extensions';
1641
+ const Files = 'Files';
1642
+ const Search$1 = 'Search';
1643
+ const SettingsGear = 'SettingsGear';
1644
+ const SourceControl$1 = 'SourceControl';
1645
+
1646
+ const Explorer = 'Explorer';
1647
+ const Extensions = 'Extensions';
1648
+ const RunAndDebug = 'Run And Debug';
1649
+ const Search = 'Search';
1650
+ const SourceControl = 'Source Control';
1651
+
1652
+ const getActivityBarItems = () => {
1653
+ return [
1654
+ // Top
1655
+ {
1656
+ id: Explorer,
1657
+ title: explorer(),
1658
+ icon: Files,
1659
+ flags: Tab | Enabled,
1660
+ keyShortcuts: 'Control+Shift+E'
1661
+ }, {
1662
+ id: Search,
1663
+ title: search(),
1664
+ icon: Search$1,
1665
+ flags: Tab | Enabled,
1666
+ keyShortcuts: 'Control+Shift+F'
1667
+ }, {
1668
+ id: SourceControl,
1669
+ title: sourceControl(),
1670
+ icon: SourceControl$1,
1671
+ flags: Tab | Enabled,
1672
+ keyShortcuts: 'Control+Shift+G'
1673
+ }, {
1674
+ id: RunAndDebug,
1675
+ title: runAndDebug(),
1676
+ icon: DebugAlt2,
1677
+ flags: Tab | Enabled,
1678
+ keyShortcuts: 'Control+Shift+D'
1679
+ }, {
1680
+ id: Extensions,
1681
+ title: extensions(),
1682
+ icon: Extensions$1,
1683
+ flags: Tab | Enabled,
1684
+ keyShortcuts: 'Control+Shift+X'
1685
+ },
1686
+ // Bottom
1687
+ {
1688
+ id: 'Settings',
1689
+ title: settings(),
1690
+ icon: SettingsGear,
1691
+ flags: Button | Enabled | MarginTop,
1692
+ keyShortcuts: ''
1693
+ }];
1694
+ };
1695
+
1584
1696
  const loadContent = async (state, savedState) => {
1697
+ const items = getActivityBarItems();
1585
1698
  return {
1586
- ...state
1699
+ ...state,
1700
+ activityBarItems: items
1587
1701
  };
1588
1702
  };
1589
1703
 
1704
+ const renderCss = (oldState, newState) => {
1705
+ return [];
1706
+ };
1707
+
1590
1708
  const renderFocusContext = (oldState, newState) => {
1591
1709
  if (newState.focus === List) {
1592
1710
  return [SetFocusContext, newState.uid, FocusExplorer];
@@ -1594,8 +1712,150 @@ const renderFocusContext = (oldState, newState) => {
1594
1712
  return [];
1595
1713
  };
1596
1714
 
1715
+ const mergeClassNames = (...classNames) => {
1716
+ return classNames.filter(Boolean).join(' ');
1717
+ };
1718
+
1719
+ const Vertical = 'vertical';
1720
+
1721
+ const ActivityBar$1 = 'ActivityBar';
1722
+ const ActivityBarItem = 'ActivityBarItem';
1723
+ const ActivityBarItemNested = 'ActivityBarItemNested';
1724
+ const ActivityBarItemSelected = 'ActivityBarItemSelected';
1725
+ const Badge = 'Badge';
1726
+ const BadgeContent = 'BadgeContent';
1727
+ const FocusOutline = 'FocusOutline';
1728
+ const Icon = 'Icon';
1729
+ const MarginTopAuto = 'MarginTopAuto';
1730
+ const Viewlet = 'Viewlet';
1731
+
1732
+ const HandleBlur = 'handleBlur';
1733
+ const HandleContextMenu = 'handleContextMenu';
1734
+ const HandleFocus = 'handleFocus';
1735
+ const HandleMouseDown = 'handleMouseDown';
1736
+
1737
+ const ActivityBar = 'ActivityBar';
1738
+
1739
+ const Div = 4;
1740
+
1741
+ const getIconVirtualDom = (icon, type = Div) => {
1742
+ return {
1743
+ type,
1744
+ className: `MaskIcon MaskIcon${icon}`,
1745
+ role: None,
1746
+ childCount: 0
1747
+ };
1748
+ };
1749
+
1750
+ const getAriaSelected = (isTab, isSelected) => {
1751
+ if (!isTab) {
1752
+ return undefined;
1753
+ }
1754
+ return Boolean(isSelected);
1755
+ };
1756
+ const createActivityBarItem = item => {
1757
+ const {
1758
+ flags,
1759
+ title,
1760
+ icon
1761
+ } = item;
1762
+ const isTab = flags & Tab;
1763
+ const isSelected = flags & Selected;
1764
+ const isFocused = flags & Focused;
1765
+ const isProgress = flags & Progress;
1766
+ const role = isTab ? Tab$1 : Button$1;
1767
+ const ariaSelected = getAriaSelected(isTab, isSelected);
1768
+ const marginTop = flags & MarginTop;
1769
+ let className = ActivityBarItem;
1770
+ if (isFocused) {
1771
+ className += ' ' + FocusOutline;
1772
+ }
1773
+ if (marginTop) {
1774
+ className += ' ' + MarginTopAuto;
1775
+ }
1776
+ if (isSelected) {
1777
+ className += ' ' + ActivityBarItemSelected;
1778
+ return [{
1779
+ type: Div,
1780
+ className,
1781
+ ariaLabel: '',
1782
+ title,
1783
+ role,
1784
+ ariaSelected,
1785
+ childCount: 1
1786
+ }, getIconVirtualDom(icon)];
1787
+ }
1788
+
1789
+ // TODO support progress on selected activity bar item
1790
+ if (isProgress) {
1791
+ className += ' ' + ActivityBarItemNested;
1792
+ return [{
1793
+ type: Div,
1794
+ className,
1795
+ ariaLabel: '',
1796
+ title,
1797
+ role,
1798
+ ariaSelected,
1799
+ childCount: 2
1800
+ }, {
1801
+ type: Div,
1802
+ className: Icon,
1803
+ role: None,
1804
+ childCount: 0,
1805
+ maskImage: icon
1806
+ }, {
1807
+ type: Div,
1808
+ className: Badge,
1809
+ childCount: 1
1810
+ }, {
1811
+ type: Div,
1812
+ className: BadgeContent,
1813
+ childCount: 1
1814
+ }, {
1815
+ type: Div,
1816
+ className: Icon,
1817
+ maskImage: 'Progress'
1818
+ }];
1819
+ }
1820
+ return [{
1821
+ type: Div,
1822
+ className: `${className} Icon${icon}`,
1823
+ ariaLabel: '',
1824
+ title,
1825
+ role,
1826
+ ariaSelected,
1827
+ childCount: 0
1828
+ }];
1829
+ };
1830
+ const getVirtualDom = visibleItems => {
1831
+ const dom = visibleItems.flatMap(createActivityBarItem);
1832
+ return dom;
1833
+ };
1834
+
1835
+ const getActivityBarVirtualDom = visibleItems => {
1836
+ return [{
1837
+ type: Div,
1838
+ id: ActivityBar,
1839
+ className: mergeClassNames(Viewlet, ActivityBar$1),
1840
+ role: ToolBar,
1841
+ ariaRoleDescription: activityBar(),
1842
+ ariaOrientation: Vertical,
1843
+ tabIndex: 0,
1844
+ onMouseDown: HandleMouseDown,
1845
+ onContextMenu: HandleContextMenu,
1846
+ onFocus: HandleFocus,
1847
+ onBlur: HandleBlur,
1848
+ childCount: visibleItems.length
1849
+ }, ...getVirtualDom(visibleItems)];
1850
+ };
1851
+
1597
1852
  const renderItems = (oldState, newState) => {
1598
- return [SetDom2, []];
1853
+ const {
1854
+ uid,
1855
+ activityBarItems
1856
+ } = newState;
1857
+ const dom = getActivityBarVirtualDom(activityBarItems);
1858
+ return [SetDom2, uid, dom];
1599
1859
  };
1600
1860
 
1601
1861
  const getRenderer = diffType => {
@@ -1604,6 +1864,10 @@ const getRenderer = diffType => {
1604
1864
  return renderItems;
1605
1865
  case RenderFocusContext:
1606
1866
  return renderFocusContext;
1867
+ case RenderFocus:
1868
+ return renderFocusContext;
1869
+ case RenderCss:
1870
+ return renderCss;
1607
1871
  default:
1608
1872
  throw new Error('unknown renderer');
1609
1873
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/activity-bar-worker",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",