@lvce-editor/activity-bar-worker 1.3.0 → 1.5.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.
@@ -969,6 +969,49 @@ const create$1 = (id, uri, x, y, width, height, args, parentUid, platform = 0) =
969
969
  return state;
970
970
  };
971
971
 
972
+ const isEqual$2 = (oldState, newState) => {
973
+ // TODO compute css more optimized
974
+ // maybe only when items change, and even then not
975
+ // always, but only when it affects the css
976
+ return false;
977
+ };
978
+
979
+ const isEqual$1 = (oldState, newState) => {
980
+ return oldState.focused === newState.focused && oldState.focus === newState.focus;
981
+ };
982
+
983
+ const isEqual = (oldState, newState) => {
984
+ return oldState.focusedIndex === newState.focusedIndex && oldState.activityBarItems === newState.activityBarItems;
985
+ };
986
+
987
+ const RenderItems = 4;
988
+ const RenderFocus = 6;
989
+ const RenderFocusContext = 7;
990
+ const RenderCss = 11;
991
+
992
+ const modules = [isEqual, isEqual$1, isEqual$1, isEqual$2];
993
+ const numbers = [RenderItems, RenderFocus, RenderFocusContext, RenderCss];
994
+
995
+ const diff = (oldState, newState) => {
996
+ const diffResult = [];
997
+ for (let i = 0; i < modules.length; i++) {
998
+ const fn = modules[i];
999
+ if (!fn(oldState, newState)) {
1000
+ diffResult.push(numbers[i]);
1001
+ }
1002
+ }
1003
+ return diffResult;
1004
+ };
1005
+
1006
+ const diff2 = uid => {
1007
+ const {
1008
+ oldState,
1009
+ newState
1010
+ } = get$1(uid);
1011
+ const result = diff(oldState, newState);
1012
+ return result;
1013
+ };
1014
+
972
1015
  const List = 1;
973
1016
 
974
1017
  const focus = state => {
@@ -1011,13 +1054,10 @@ const focusNone = state => {
1011
1054
  return focusIndex(state, -1);
1012
1055
  };
1013
1056
 
1014
- const Button = 'event.button';
1015
- const ClientX = 'event.clientX';
1016
- const ClientY = 'event.clientY';
1017
- const CtrlKey = 'event.ctrlKey';
1018
- const DeltaMode = 'event.deltaMode';
1019
- const DeltaY = 'event.deltaY';
1020
- const TargetValue = 'event.target.value';
1057
+ const Button$1 = 'button';
1058
+ const None = 'none';
1059
+ const Tab$1 = 'tab';
1060
+ const ToolBar = 'toolbar';
1021
1061
 
1022
1062
  const Enter = 3;
1023
1063
  const Space = 9;
@@ -1033,7 +1073,11 @@ const LeftClick = 0;
1033
1073
  const DebugWorker = 55;
1034
1074
  const RendererWorker$1 = 1;
1035
1075
 
1076
+ const SetDom2 = 'Viewlet.setDom2';
1077
+ const SetFocusContext = 'Viewlet.setFocusContext';
1078
+
1036
1079
  const FocusActivityBar = 5;
1080
+ const FocusExplorer = 13;
1037
1081
 
1038
1082
  const getKeyBindings$1 = () => {
1039
1083
  return [{
@@ -1521,6 +1565,10 @@ const handleClick = async (state, button, index, x, y) => {
1521
1565
  }
1522
1566
  };
1523
1567
 
1568
+ const handleResize = state => {
1569
+ return state;
1570
+ };
1571
+
1524
1572
  const findIndex = (activityBarItems, id) => {
1525
1573
  for (let i = 0; i < activityBarItems.length; i++) {
1526
1574
  if (activityBarItems[i].id === id) {
@@ -1538,106 +1586,317 @@ const handleSideBarViewletChange = (state, id, ...args) => {
1538
1586
  };
1539
1587
  };
1540
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
+
1541
1696
  const loadContent = async (state, savedState) => {
1697
+ const items = getActivityBarItems();
1542
1698
  return {
1543
- ...state
1699
+ ...state,
1700
+ activityBarItems: items
1544
1701
  };
1545
1702
  };
1546
1703
 
1704
+ const renderCss = (oldState, newState) => {
1705
+ return [];
1706
+ };
1707
+
1708
+ const renderFocusContext = (oldState, newState) => {
1709
+ if (newState.focus === List) {
1710
+ return [SetFocusContext, newState.uid, FocusExplorer];
1711
+ }
1712
+ return [];
1713
+ };
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
+
1852
+ const renderItems = (oldState, newState) => {
1853
+ const {
1854
+ uid,
1855
+ activityBarItems
1856
+ } = newState;
1857
+ const dom = getActivityBarVirtualDom(activityBarItems);
1858
+ return [SetDom2, uid, dom];
1859
+ };
1860
+
1861
+ const getRenderer = diffType => {
1862
+ switch (diffType) {
1863
+ case RenderItems:
1864
+ return renderItems;
1865
+ case RenderFocusContext:
1866
+ return renderFocusContext;
1867
+ case RenderFocus:
1868
+ return renderFocusContext;
1869
+ case RenderCss:
1870
+ return renderCss;
1871
+ default:
1872
+ throw new Error('unknown renderer');
1873
+ }
1874
+ };
1875
+
1547
1876
  const applyRender = (oldState, newState, diffResult) => {
1548
1877
  const commands = [];
1878
+ for (const item of diffResult) {
1879
+ const fn = getRenderer(item);
1880
+ const result = fn(oldState, newState);
1881
+ if (result.length > 0) {
1882
+ commands.push(result);
1883
+ }
1884
+ }
1549
1885
  return commands;
1550
1886
  };
1551
1887
 
1552
1888
  const render2 = (uid, diffResult) => {
1553
1889
  const {
1890
+ oldState,
1554
1891
  newState
1555
1892
  } = get$1(uid);
1556
1893
  set$3(uid, newState, newState);
1557
- const commands = applyRender();
1894
+ const commands = applyRender(oldState, newState, diffResult);
1558
1895
  return commands;
1559
1896
  };
1560
1897
 
1561
- const HandleClick = 1;
1562
- const HandleClickOpenFolder = 2;
1563
- const HandleContextMenu = 3;
1564
- const HandleDragLeave = 4;
1565
- const HandleDragOver = 5;
1566
- const HandleDrop = 6;
1567
- const HandleEditingInput = 7;
1568
- const HandleInputBlur = 8;
1569
- const HandleInputClick = 9;
1570
- const HandleListBlur = 11;
1571
- const HandleListFocus = 12;
1572
- const HandlePointerDown = 14;
1573
- const HandleWheel = 15;
1574
- const HandleDragStart = 17;
1575
-
1576
1898
  const renderEventListeners = () => {
1577
- return [{
1578
- name: HandleInputBlur,
1579
- params: ['handleInputBlur']
1580
- },
1581
- // {
1582
- // name: DomEventListenersFunctions.HandleInputKeyDown,
1583
- // params: ['handleInputKeyDown'],
1584
- // stopPropagation: true, // TODO find a way to do this without stopPropagation
1585
- // },
1586
- // {
1587
- // name: DomEventListenersFunctions.HandleListKeyDown,
1588
- // params: ['handleKeyDown', 'event.key'],
1589
- // preventDefault: true,
1590
- // },
1591
- {
1592
- name: HandleListFocus,
1593
- params: ['handleFocus', 'event.isTrusted', 'event.target.className']
1594
- }, {
1595
- name: HandleListBlur,
1596
- params: ['handleBlur']
1597
- }, {
1598
- name: HandleClick,
1599
- params: ['handleClickAt', 'event.defaultPrevented', Button, CtrlKey, 'event.shiftKey', ClientX, ClientY],
1600
- preventDefault: true
1601
- }, {
1602
- name: HandleInputClick,
1603
- params: ['handleInputClick'],
1604
- preventDefault: true
1605
- }, {
1606
- name: HandleClickOpenFolder,
1607
- params: ['handleClickOpenFolder'],
1608
- preventDefault: true
1609
- }, {
1610
- name: HandlePointerDown,
1611
- params: ['handlePointerDown', Button, ClientX, ClientY]
1612
- // preventDefault: true,
1613
- }, {
1614
- name: HandleEditingInput,
1615
- params: ['updateEditingValue', TargetValue]
1616
- }, {
1617
- name: HandleContextMenu,
1618
- params: ['handleContextMenu', Button, ClientX, ClientY],
1619
- preventDefault: true
1620
- }, {
1621
- name: HandleWheel,
1622
- params: ['handleWheel', DeltaMode, DeltaY],
1623
- passive: true
1624
- }, {
1625
- name: HandleDragOver,
1626
- params: ['handleDragOver', ClientX, ClientY],
1627
- preventDefault: true
1628
- }, {
1629
- name: HandleDrop,
1630
- params: ['handleDrop', ClientX, ClientY, 'event.dataTransfer.files2', 'event.dataTransfer.files'],
1631
- preventDefault: true
1632
- }, {
1633
- name: HandleDragLeave,
1634
- params: ['handleDragLeave']
1635
- }, {
1636
- name: HandleDragStart,
1637
- params: ['handleDragStart'],
1638
- // @ts-ignore
1639
- dragEffect: 'copyMove'
1640
- }];
1899
+ return [];
1641
1900
  };
1642
1901
 
1643
1902
  const saveState = state => {
@@ -1650,23 +1909,25 @@ const saveState = state => {
1650
1909
  };
1651
1910
 
1652
1911
  const commandMap = {
1912
+ 'ActivityBar.create': create$1,
1913
+ 'ActivityBar.diff2': diff2,
1653
1914
  'ActivityBar.focus': wrapCommand(focus),
1654
1915
  'ActivityBar.focusFirst': wrapCommand(focusFirst),
1655
1916
  'ActivityBar.focusIndex': wrapCommand(focusIndex),
1656
- 'ActivityBar.loadContent': wrapCommand(loadContent),
1657
1917
  'ActivityBar.focusLast': wrapCommand(focusLast),
1658
1918
  'ActivityBar.focusNext': wrapCommand(focusNext),
1659
- 'ActivityBar.handleBlur': wrapCommand(handleBlur),
1660
1919
  'ActivityBar.focusNone': wrapCommand(focusNone),
1661
- 'ActivityBar.handleSideBarViewletChange': wrapCommand(handleSideBarViewletChange),
1920
+ 'ActivityBar.getCommandIds': getCommandIds,
1662
1921
  'ActivityBar.getKeyBindings': getKeyBindings$1,
1922
+ 'ActivityBar.handleBlur': wrapCommand(handleBlur),
1923
+ 'ActivityBar.handleResize': wrapCommand(handleResize),
1663
1924
  'ActivityBar.handleClick': wrapCommand(handleClick),
1664
- 'ActivityBar.getCommandIds': getCommandIds,
1925
+ 'ActivityBar.handleSideBarViewletChange': wrapCommand(handleSideBarViewletChange),
1926
+ 'ActivityBar.loadContent': wrapCommand(loadContent),
1665
1927
  'ActivityBar.render2': render2,
1666
1928
  'ActivityBar.renderEventListeners': renderEventListeners,
1667
1929
  'ActivityBar.saveState': wrapGetter(saveState),
1668
- 'ActivityBar.terminate': terminate,
1669
- 'ActivityBar.create': create$1
1930
+ 'ActivityBar.terminate': terminate
1670
1931
  };
1671
1932
 
1672
1933
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/activity-bar-worker",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",