@lvce-editor/extension-detail-view 3.3.0 → 3.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.
@@ -430,10 +430,10 @@ const create$4 = (method, params) => {
430
430
  };
431
431
  };
432
432
  const callbacks = Object.create(null);
433
- const set$1 = (id, fn) => {
433
+ const set$2 = (id, fn) => {
434
434
  callbacks[id] = fn;
435
435
  };
436
- const get$1 = id => {
436
+ const get$2 = id => {
437
437
  return callbacks[id];
438
438
  };
439
439
  const remove = id => {
@@ -449,13 +449,13 @@ const registerPromise = () => {
449
449
  resolve,
450
450
  promise
451
451
  } = Promise.withResolvers();
452
- set$1(id, resolve);
452
+ set$2(id, resolve);
453
453
  return {
454
454
  id,
455
455
  promise
456
456
  };
457
457
  };
458
- const create$2 = (method, params) => {
458
+ const create$2$1 = (method, params) => {
459
459
  const {
460
460
  id,
461
461
  promise
@@ -606,7 +606,7 @@ const warn = (...args) => {
606
606
  console.warn(...args);
607
607
  };
608
608
  const resolve = (id, response) => {
609
- const fn = get$1(id);
609
+ const fn = get$2(id);
610
610
  if (!fn) {
611
611
  console.log(response);
612
612
  warn(`callback ${id} may already be disposed`);
@@ -645,7 +645,7 @@ const getErrorProperty = (error, prettyError) => {
645
645
  }
646
646
  };
647
647
  };
648
- const create$1 = (message, error) => {
648
+ const create$1$1 = (message, error) => {
649
649
  return {
650
650
  jsonrpc: Two,
651
651
  id: message.id,
@@ -656,7 +656,7 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
656
656
  const prettyError = preparePrettyError(error);
657
657
  logError(error, prettyError);
658
658
  const errorProperty = getErrorProperty(error, prettyError);
659
- return create$1(message, errorProperty);
659
+ return create$1$1(message, errorProperty);
660
660
  };
661
661
  const create$5 = (message, result) => {
662
662
  return {
@@ -747,7 +747,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
747
747
  const {
748
748
  message,
749
749
  promise
750
- } = create$2(method, params);
750
+ } = create$2$1(method, params);
751
751
  if (useSendAndTransfer && ipc.sendAndTransfer) {
752
752
  ipc.sendAndTransfer(message);
753
753
  } else {
@@ -831,7 +831,7 @@ const listen$1 = async (module, options) => {
831
831
  const ipc = module.wrap(rawIpc);
832
832
  return ipc;
833
833
  };
834
- const create = async ({
834
+ const create$2 = async ({
835
835
  commandMap
836
836
  }) => {
837
837
  // TODO create a commandMap per rpc instance
@@ -843,21 +843,80 @@ const create = async ({
843
843
  };
844
844
  const WebWorkerRpcClient = {
845
845
  __proto__: null,
846
- create
846
+ create: create$2
847
847
  };
848
848
 
849
+ const create$1 = () => {
850
+ const states = Object.create(null);
851
+ return {
852
+ get(uid) {
853
+ return states[uid];
854
+ },
855
+ set(uid, oldState, newState) {
856
+ states[uid] = {
857
+ oldState,
858
+ newState
859
+ };
860
+ }
861
+ };
862
+ };
863
+
864
+ const {
865
+ get: get$1,
866
+ set: set$1
867
+ } = create$1();
868
+
869
+ const create = (uid, uri, width, height, platform) => {
870
+ const state = {
871
+ description: '',
872
+ iconSrc: '',
873
+ selectedFeature: '',
874
+ name: '',
875
+ sanitizedReadmeHtml: '',
876
+ selectedTab: '',
877
+ size: 0,
878
+ width,
879
+ uri,
880
+ entries: [],
881
+ secondEntries: [],
882
+ categories: [],
883
+ resources: [],
884
+ selectedFeatureMarkdownDom: '',
885
+ extension: {},
886
+ baseUrl: '',
887
+ features: [],
888
+ folderSize: 0
889
+ };
890
+ set$1(uid, state, state);
891
+ };
892
+
893
+ const AdditionalDetails = 'AdditionalDetails';
894
+ const AdditionalDetailsEntry = 'AdditionalDetailsEntry';
895
+ const AdditionalDetailsTitle = 'AdditionalDetailsTitle';
896
+ const Aside$2 = 'Aside';
897
+ const Categories = 'Categories';
898
+ const Category = 'Category';
899
+ const Changelog$1 = 'Changelog';
849
900
  const ExtensionDetail = 'ExtensionDetail';
850
901
  const ExtensionDetailDescription = 'ExtensionDetailDescription';
851
902
  const ExtensionDetailHeader = 'ExtensionDetailHeader';
852
903
  const ExtensionDetailHeaderDetails = 'ExtensionDetailHeaderDetails';
853
- const Changelog$1 = 'Changelog';
854
- const Features$1 = 'Features';
855
904
  const ExtensionDetailIcon = 'ExtensionDetailIcon';
856
905
  const ExtensionDetailName = 'ExtensionDetailName';
906
+ const ExtensionDetailPanel = 'ExtensionDetailPanel';
857
907
  const ExtensionDetailTab = 'ExtensionDetailTab';
858
908
  const ExtensionDetailTabs = 'ExtensionDetailTabs';
859
909
  const ExtensionDetailTabSelected = 'ExtensionDetailTabSelected';
910
+ const Feature = 'Feature';
911
+ const Features$1 = 'Features';
912
+ const FeaturesList = 'FeaturesList';
860
913
  const Markdown = 'Markdown';
914
+ const MoreInfo = 'MoreInfo';
915
+ const MoreInfoEntry = 'MoreInfoEntry';
916
+ const MoreInfoEntryKey = 'MoreInfoEntryKey';
917
+ const MoreInfoEntryValue = 'MoreInfoEntryValue';
918
+ const Resource = 'Resource';
919
+ const Resources = 'Resources';
861
920
  const Viewlet = 'Viewlet';
862
921
 
863
922
  const Button = 1;
@@ -914,9 +973,98 @@ const getChangelogVirtualDom = () => {
914
973
  const Document = 'document';
915
974
  const TabList = 'tablist';
916
975
  const Tab = 'tab';
976
+ const Panel = 'panel';
917
977
 
918
978
  const HandleReadmeContextMenu = 'handleReadmeContextMenu';
919
979
  const HandleTabsClick = 'handleTabsClick';
980
+ const HandleFeaturesClick = 'handleFeaturesClick';
981
+
982
+ const getAdditionalDetailsEntryVirtualDom = (heading, items, renderer) => {
983
+ return [{
984
+ type: Div$1,
985
+ className: AdditionalDetailsEntry,
986
+ childCount: 2
987
+ }, {
988
+ type: Div$1,
989
+ className: AdditionalDetailsTitle,
990
+ childCount: 1
991
+ }, text(heading), ...renderer(items)];
992
+ };
993
+
994
+ const getCategoryVirtualDom = category => {
995
+ const {
996
+ label
997
+ } = category;
998
+ return [{
999
+ type: Div$1,
1000
+ className: Category,
1001
+ childCount: 1
1002
+ }, text(label)];
1003
+ };
1004
+
1005
+ const getCategoriesDom = categories => {
1006
+ return [{
1007
+ type: Div$1,
1008
+ className: Categories,
1009
+ childCount: categories.length
1010
+ }, ...categories.flatMap(getCategoryVirtualDom)];
1011
+ };
1012
+
1013
+ const getMoreInfoEntryVirtualDom = item => {
1014
+ const {
1015
+ key,
1016
+ value
1017
+ } = item;
1018
+ return [{
1019
+ type: Div$1,
1020
+ className: MoreInfoEntry,
1021
+ childCount: 2
1022
+ }, {
1023
+ type: Div$1,
1024
+ className: MoreInfoEntryKey,
1025
+ childCount: 1
1026
+ }, text(key), {
1027
+ type: Div$1,
1028
+ className: MoreInfoEntryValue,
1029
+ childCount: 1
1030
+ }, text(value)];
1031
+ };
1032
+
1033
+ const getMoreInfoVirtualDom = items => {
1034
+ return [{
1035
+ type: Div$1,
1036
+ className: MoreInfo,
1037
+ childCount: items.length
1038
+ }, ...items.flatMap(getMoreInfoEntryVirtualDom)];
1039
+ };
1040
+
1041
+ const getResourceVirtualDom = resource => {
1042
+ const {
1043
+ label
1044
+ } = resource;
1045
+ return [{
1046
+ // TODO use link with url
1047
+ type: Div$1,
1048
+ className: Resource,
1049
+ childCount: 1
1050
+ }, text(label)];
1051
+ };
1052
+
1053
+ const getResourcesVirtualDom = resources => {
1054
+ return [{
1055
+ type: Div$1,
1056
+ className: Resources,
1057
+ childCount: resources.length
1058
+ }, ...resources.flatMap(getResourceVirtualDom)];
1059
+ };
1060
+
1061
+ const getAdditionalDetailsVirtualDom = (firstHeading, entries, secondHeading, secondEntries, thirdHeading, categories, fourthHeading, resources) => {
1062
+ return [{
1063
+ type: Div$1,
1064
+ className: AdditionalDetails,
1065
+ childCount: 4
1066
+ }, ...getAdditionalDetailsEntryVirtualDom(firstHeading, entries, getMoreInfoVirtualDom), ...getAdditionalDetailsEntryVirtualDom(secondHeading, secondEntries, getMoreInfoVirtualDom), ...getAdditionalDetailsEntryVirtualDom(thirdHeading, categories, getCategoriesDom), ...getAdditionalDetailsEntryVirtualDom(fourthHeading, resources, getResourcesVirtualDom)];
1067
+ };
920
1068
 
921
1069
  const allowedMarkdownAttributes = ['src', 'id', 'className', 'title', 'alt', 'href', 'target', 'rel'];
922
1070
 
@@ -1383,35 +1531,137 @@ const getVirtualDomChildCount = markdownDom => {
1383
1531
  const getDetailsVirtualDom = sanitizedReadmeHtml => {
1384
1532
  const markdownDom = getMarkdownVirtualDom(sanitizedReadmeHtml);
1385
1533
  const childCount = getVirtualDomChildCount(markdownDom);
1534
+ const firstHeading = 'Installation';
1535
+ const entries = [{
1536
+ key: 'Identifier',
1537
+ value: 'abc'
1538
+ }, {
1539
+ key: 'Version',
1540
+ value: '1.9.5'
1541
+ }, {
1542
+ key: 'Last Updated',
1543
+ value: 'n/a'
1544
+ }, {
1545
+ key: 'Size',
1546
+ value: '100kB'
1547
+ }];
1548
+ const secondHeading = 'Marketplace';
1549
+ const secondEntries = [{
1550
+ key: 'Published',
1551
+ value: 'n/a'
1552
+ }, {
1553
+ key: 'Last Released',
1554
+ value: 'n/a'
1555
+ }];
1556
+ const thirdHeading = 'Categories';
1557
+ const categories = [{
1558
+ id: 'themes',
1559
+ label: 'Themes'
1560
+ }];
1561
+ const fourthHeading = 'Resources';
1562
+ const resources = [{
1563
+ label: 'Marketplace',
1564
+ url: '#'
1565
+ }, {
1566
+ label: 'Issues',
1567
+ url: '#'
1568
+ }, {
1569
+ label: 'Repository',
1570
+ url: '#'
1571
+ }, {
1572
+ label: 'License',
1573
+ url: '#'
1574
+ }];
1386
1575
  const dom = [{
1576
+ type: Div$1,
1577
+ className: ExtensionDetailPanel,
1578
+ childCount: 2,
1579
+ role: Panel
1580
+ }, {
1387
1581
  type: Div$1,
1388
1582
  className: Markdown,
1389
1583
  role: Document,
1390
1584
  onContextMenu: HandleReadmeContextMenu,
1391
1585
  childCount
1392
- }, ...markdownDom];
1586
+ }, ...markdownDom, {
1587
+ type: Div$1,
1588
+ className: Aside$2,
1589
+ childCount: 1
1590
+ }, ...getAdditionalDetailsVirtualDom(firstHeading, entries, secondHeading, secondEntries, thirdHeading, categories, fourthHeading, resources)];
1393
1591
  return dom;
1394
1592
  };
1395
1593
 
1396
- const getFeaturesVirtualDom = () => {
1397
- // TODO set tabpanel role
1594
+ const getFeatureListItemVirtualDom = feature => {
1595
+ const {
1596
+ label,
1597
+ selected,
1598
+ id
1599
+ } = feature;
1600
+ const className = selected ? 'Feature FeatureSelected' : Feature;
1601
+ return [{
1602
+ // TODO use role list item or tab
1603
+ type: Button,
1604
+ name: id,
1605
+ className,
1606
+ childCount: 1
1607
+ }, text(label)];
1608
+ };
1609
+
1610
+ const getFeatureListVirtualDom = features => {
1398
1611
  return [{
1612
+ // TODO use either list or tabs role
1399
1613
  type: Div$1,
1400
- className: Features$1,
1614
+ className: FeaturesList,
1615
+ childCount: features.length,
1616
+ onClick: HandleFeaturesClick
1617
+ }, ...features.flatMap(getFeatureListItemVirtualDom)];
1618
+ };
1619
+
1620
+ const getFeatureThemesVirtualDom = themesHtml => {
1621
+ const markdownDom = getMarkdownVirtualDom(themesHtml);
1622
+ const childCount = getVirtualDomChildCount(markdownDom);
1623
+ const heading = 'Themes';
1624
+ return [{
1625
+ type: Div$1,
1626
+ className: 'FeatureTheme',
1627
+ childCount: 2
1628
+ }, {
1629
+ type: H1$1,
1401
1630
  childCount: 1
1402
- }, text('Not Implemented')];
1631
+ }, text(heading), {
1632
+ type: Div$1,
1633
+ className: 'DefaultMarkdown',
1634
+ childCount
1635
+ }, ...markdownDom];
1636
+ };
1637
+
1638
+ const getFeaturesVirtualDom = (features, themesHtml) => {
1639
+ return [{
1640
+ type: Div$1,
1641
+ className: Features$1,
1642
+ childCount: 3
1643
+ }, ...getFeatureListVirtualDom(features), {
1644
+ type: Div$1,
1645
+ className: 'Sash SashVertical',
1646
+ childCount: 0
1647
+ }, ...getFeatureThemesVirtualDom(themesHtml)];
1403
1648
  };
1404
1649
 
1650
+ const Changelog = 'Changelog';
1651
+ const Commands = 'Commands';
1405
1652
  const Details = 'Details';
1406
1653
  const Features = 'Features';
1407
- const Changelog = 'Changelog';
1654
+ const JsonValidation = 'JsonValidation';
1655
+ const ProgrammingLanguages = 'ProgrammingLanguages';
1656
+ const Settings = 'Settings';
1657
+ const Theme = 'Theme';
1408
1658
 
1409
- const getExtensionDetailContentVirtualDom = (sanitizedReadmeHtml, selectedTab) => {
1659
+ const getExtensionDetailContentVirtualDom = (sanitizedReadmeHtml, themesHtml, selectedTab, features) => {
1410
1660
  switch (selectedTab) {
1411
1661
  case Details:
1412
1662
  return getDetailsVirtualDom(sanitizedReadmeHtml);
1413
1663
  case Features:
1414
- return getFeaturesVirtualDom();
1664
+ return getFeaturesVirtualDom(features, themesHtml);
1415
1665
  case Changelog:
1416
1666
  return getChangelogVirtualDom();
1417
1667
  default:
@@ -1452,6 +1702,31 @@ const getExtensionDetailHeaderVirtualDom = extensionDetail => {
1452
1702
  return dom;
1453
1703
  };
1454
1704
 
1705
+ const getFeatures = () => {
1706
+ const features = [{
1707
+ id: Theme,
1708
+ label: 'Theme',
1709
+ selected: true
1710
+ }, {
1711
+ id: Commands,
1712
+ label: 'Commands',
1713
+ selected: false
1714
+ }, {
1715
+ id: JsonValidation,
1716
+ label: 'Json Validation',
1717
+ selected: false
1718
+ }, {
1719
+ id: ProgrammingLanguages,
1720
+ label: 'Programming Languages',
1721
+ selected: false
1722
+ }, {
1723
+ id: Settings,
1724
+ label: 'Settings',
1725
+ selected: false
1726
+ }];
1727
+ return features;
1728
+ };
1729
+
1455
1730
  const getTabs = selectedTab => {
1456
1731
  const tabs = [{
1457
1732
  label: 'Details',
@@ -1477,20 +1752,24 @@ const mergeClassNames = (...classNames) => {
1477
1752
  return joinBySpace(...classNames.filter(Boolean));
1478
1753
  };
1479
1754
 
1755
+ const selectedClassName = mergeClassNames(ExtensionDetailTab, ExtensionDetailTabSelected);
1756
+ const defaultClassName = ExtensionDetailTab;
1480
1757
  const getTabVirtualDom = tab => {
1481
1758
  const {
1482
1759
  label,
1483
1760
  selected,
1484
1761
  name
1485
1762
  } = tab;
1486
- const className = selected ? mergeClassNames(ExtensionDetailTab, ExtensionDetailTabSelected) : ExtensionDetailTab;
1763
+ const className = selected ? selectedClassName : defaultClassName;
1764
+ const ariaSelected = selected ? 'true' : 'false';
1487
1765
  return [{
1488
1766
  type: Button,
1489
1767
  role: Tab,
1490
1768
  name,
1491
1769
  className,
1492
1770
  childCount: 1,
1493
- tabIndex: -1
1771
+ tabIndex: -1,
1772
+ ariaSelected
1494
1773
  }, text(label)];
1495
1774
  };
1496
1775
 
@@ -1505,16 +1784,15 @@ const getTabsVirtualDom = tabs => {
1505
1784
  }, ...tabs.flatMap(getTabVirtualDom)];
1506
1785
  };
1507
1786
 
1508
- const getExtensionDetailVirtualDom = (extensionDetail, sanitizedReadmeHtml, selectedTab) => {
1509
- console.log({
1510
- selectedTab
1511
- });
1787
+ const getExtensionDetailVirtualDom = (extensionDetail, sanitizedReadmeHtml, selectedTab, newState) => {
1788
+ const themesHtml = newState?.selectedFeatureMarkdownDom || '';
1789
+ const features = newState?.features || getFeatures();
1512
1790
  const tabs = getTabs(selectedTab);
1513
1791
  const dom = [{
1514
1792
  type: Div$1,
1515
1793
  className: mergeClassNames(Viewlet, ExtensionDetail),
1516
1794
  childCount: 3
1517
- }, ...getExtensionDetailHeaderVirtualDom(extensionDetail), ...getTabsVirtualDom(tabs), ...getExtensionDetailContentVirtualDom(sanitizedReadmeHtml, selectedTab)];
1795
+ }, ...getExtensionDetailHeaderVirtualDom(extensionDetail), ...getTabsVirtualDom(tabs), ...getExtensionDetailContentVirtualDom(sanitizedReadmeHtml, themesHtml, selectedTab, features)];
1518
1796
  return dom;
1519
1797
  };
1520
1798
 
@@ -1591,6 +1869,33 @@ const getLinkMenuEntries = props => {
1591
1869
 
1592
1870
  const getMenuEntries = props => [...getLinkMenuEntries(props), ...getImageMenuEntries(props), getCopyMenuEntry()];
1593
1871
 
1872
+ const selectFeature = async (state, name) => {
1873
+ const {
1874
+ features
1875
+ } = state;
1876
+ const newFeatures = features.map(feature => {
1877
+ if (feature.id === name) {
1878
+ return {
1879
+ ...feature,
1880
+ selected: true
1881
+ };
1882
+ }
1883
+ return {
1884
+ ...feature,
1885
+ selected: false
1886
+ };
1887
+ });
1888
+ return {
1889
+ ...state,
1890
+ selectedFeature: name,
1891
+ features: newFeatures
1892
+ };
1893
+ };
1894
+
1895
+ const handleClickFeatures = async (state, name) => {
1896
+ return selectFeature(state, name);
1897
+ };
1898
+
1594
1899
  const assetDir = '';
1595
1900
 
1596
1901
  const ExtensionDefaultIcon = `${assetDir}/icons/extensionDefaultIcon.png`;
@@ -1610,153 +1915,56 @@ const handleIconError = state => {
1610
1915
  };
1611
1916
  };
1612
1917
 
1613
- const handleTabsClick = (state, name) => {
1614
- // TODO load the tabs content if needed
1615
- console.log({
1616
- name
1617
- });
1918
+ const selectTabChangelog = async state => {
1618
1919
  return {
1619
1920
  ...state,
1620
- selectedTab: name
1921
+ selectedTab: Changelog
1621
1922
  };
1622
1923
  };
1623
1924
 
1624
- const Web = 1;
1625
- const Electron = 2;
1626
- const Remote = 3;
1627
-
1628
- const isLanguageBasicsExtension = extension => {
1629
- return extension.name && extension.name.startsWith('Language Basics');
1630
- };
1631
- const isThemeExtension = extension => {
1632
- return extension.name && extension.name.endsWith(' Theme');
1633
- };
1634
- const getIcon = (extension, platform) => {
1635
- if (!extension) {
1636
- return ExtensionDefaultIcon;
1637
- }
1638
- if (!extension.path || !extension.icon) {
1639
- if (isLanguageBasicsExtension(extension)) {
1640
- return ExtensionLanguageBasics;
1641
- }
1642
- if (isThemeExtension(extension)) {
1643
- return ExtensionTheme;
1644
- }
1645
- return ExtensionDefaultIcon;
1646
- }
1647
- if (platform === Remote || platform === Electron) {
1648
- if (extension.builtin) {
1649
- return `${assetDir}/extensions/${extension.id}/${extension.icon}`;
1650
- }
1651
- return `/remote/${extension.path}/${extension.icon}`; // TODO support windows paths
1652
- }
1653
- return '';
1654
- };
1655
-
1656
- // TODO handle case when extension is of type number|array|null|string
1657
-
1658
- const getName = extension => {
1659
- if (extension && extension.name) {
1660
- return extension.name;
1661
- }
1662
- if (extension && extension.id) {
1663
- return extension.id;
1664
- }
1665
- return 'n/a';
1666
- };
1667
- const getDescription = extension => {
1668
- if (!extension || !extension.description) {
1669
- return 'n/a';
1670
- }
1671
- return extension.description;
1925
+ const selectTabDefault = async state => {
1926
+ return state;
1672
1927
  };
1673
1928
 
1674
- const RendererWorker = 1;
1675
-
1676
- const rpcs = Object.create(null);
1677
- const set = (id, rpc) => {
1678
- rpcs[id] = rpc;
1679
- };
1680
- const get = id => {
1681
- return rpcs[id];
1682
- };
1683
-
1684
- const invoke = (method, ...params) => {
1685
- const rpc = get(RendererWorker);
1686
- return rpc.invoke(method, ...params);
1929
+ const selectTabDetails = async state => {
1930
+ // TODO load readmo markdown here
1931
+ return {
1932
+ ...state,
1933
+ selectedTab: Details
1934
+ };
1687
1935
  };
1688
1936
 
1689
- const getAllExtensions = async platform => {
1690
- if (platform === Web) {
1691
- return [];
1692
- }
1693
- return invoke('ExtensionManagement.getAllExtensions');
1694
- };
1695
- const getExtension = async (id, platform) => {
1696
- const allExtensions = await getAllExtensions(platform);
1697
- for (const extension of allExtensions) {
1698
- if (extension.id === id) {
1699
- return extension;
1937
+ const getThemeItemMarkdown = (heading, items) => {
1938
+ let markdown = '';
1939
+ if (items.length > 0) {
1940
+ markdown += `### ${heading}`;
1941
+ markdown += '\n\n';
1942
+ for (const item of items) {
1943
+ markdown += `- ${item.label}`;
1944
+ markdown += '\n';
1700
1945
  }
1701
1946
  }
1702
- return undefined;
1947
+ return markdown;
1703
1948
  };
1704
1949
 
1705
- const getRemoteSrc = uri => {
1706
- const src = `/remote${uri}`;
1707
- return src;
1950
+ const getColorThemeMarkdown = themes => {
1951
+ const heading = 'Color Themes';
1952
+ return getThemeItemMarkdown(heading, themes);
1708
1953
  };
1709
-
1710
- const getBaseUrl = (extensionPath, platform) => {
1711
- switch (platform) {
1712
- case Remote:
1713
- case Electron:
1714
- return getRemoteSrc(extensionPath + '/');
1715
- default:
1716
- return extensionPath;
1717
- }
1954
+ const getIconThemeMarkdown = iconThemes => {
1955
+ const heading = 'File Icon Themes';
1956
+ return getThemeItemMarkdown(heading, iconThemes);
1718
1957
  };
1719
-
1720
- const Small = 1;
1721
- const Normal = 2;
1722
- const Large = 3;
1723
-
1724
- const getViewletSize = width => {
1725
- if (width < 180) {
1726
- return Small;
1727
- }
1728
- if (width < 768) {
1729
- return Normal;
1730
- }
1731
- return Large;
1958
+ const getProductIconThemeMarkdown = iconThemes => {
1959
+ const heading = 'Product Icon Themes';
1960
+ return getThemeItemMarkdown(heading, iconThemes);
1732
1961
  };
1733
-
1734
- const readFile = async uri => {
1735
- return invoke('FileSystem.readFile', uri);
1736
- };
1737
-
1738
- const ENOENT = 'ENOENT';
1739
-
1740
- const isEnoentError = error => {
1741
- return error && error.code === ENOENT;
1742
- };
1743
-
1744
- const join = (pathSeparator, ...parts) => {
1745
- return parts.join(pathSeparator);
1746
- };
1747
-
1748
- const loadReadmeContent = async path => {
1749
- try {
1750
- const readmeUrl = join('/', path, 'README.md');
1751
- const readmeContent = await readFile(readmeUrl);
1752
- return readmeContent;
1753
- } catch (error) {
1754
- if (isEnoentError(error)) {
1755
- return '';
1756
- }
1757
- console.error(error);
1758
- return `${error}`;
1759
- }
1962
+ const getThemeMarkdown = (themes, iconThemes, productIconThemes) => {
1963
+ let markdown = '';
1964
+ markdown += getColorThemeMarkdown(themes);
1965
+ markdown += getIconThemeMarkdown(iconThemes);
1966
+ markdown += getProductIconThemeMarkdown(productIconThemes);
1967
+ return markdown;
1760
1968
  };
1761
1969
 
1762
1970
  /**
@@ -4248,7 +4456,204 @@ const renderMarkdown = async (markdown, options = {}) => {
4248
4456
  return html;
4249
4457
  };
4250
4458
 
4251
- const loadContent = async (state, platform) => {
4459
+ const selectTab$1 = async state => {
4460
+ const {
4461
+ extension,
4462
+ baseUrl
4463
+ } = state;
4464
+ const {
4465
+ colorThemes,
4466
+ iconThemes,
4467
+ productIconThemes
4468
+ } = extension;
4469
+ const markdown = getThemeMarkdown(colorThemes || [], iconThemes || [], productIconThemes || []);
4470
+ const rendered = await renderMarkdown(markdown, {
4471
+ baseUrl
4472
+ });
4473
+ return {
4474
+ ...state,
4475
+ selectedTab: Features,
4476
+ selectedFeatureMarkdownDom: rendered
4477
+ };
4478
+ };
4479
+
4480
+ const getSelectTabHandler = selectedTab => {
4481
+ switch (selectedTab) {
4482
+ case Details:
4483
+ return selectTabDetails;
4484
+ case Features:
4485
+ return selectTab$1;
4486
+ case Changelog:
4487
+ return selectTabChangelog;
4488
+ default:
4489
+ return selectTabDefault;
4490
+ }
4491
+ };
4492
+
4493
+ const selectTab = (state, name) => {
4494
+ const fn = getSelectTabHandler(name);
4495
+ return fn(state);
4496
+ };
4497
+
4498
+ const handleTabsClick = (state, name) => {
4499
+ return selectTab(state, name);
4500
+ };
4501
+
4502
+ const isLanguageBasicsExtension = extension => {
4503
+ return extension.name && extension.name.startsWith('Language Basics');
4504
+ };
4505
+
4506
+ const isThemeExtension = extension => {
4507
+ return extension.name && extension.name.endsWith(' Theme');
4508
+ };
4509
+
4510
+ const Web = 1;
4511
+ const Electron = 2;
4512
+ const Remote = 3;
4513
+
4514
+ const getIcon = (extension, platform) => {
4515
+ if (!extension) {
4516
+ return ExtensionDefaultIcon;
4517
+ }
4518
+ if (!extension.path || !extension.icon) {
4519
+ if (isLanguageBasicsExtension(extension)) {
4520
+ return ExtensionLanguageBasics;
4521
+ }
4522
+ if (isThemeExtension(extension)) {
4523
+ return ExtensionTheme;
4524
+ }
4525
+ return ExtensionDefaultIcon;
4526
+ }
4527
+ if (platform === Remote || platform === Electron) {
4528
+ if (extension.builtin) {
4529
+ return `${assetDir}/extensions/${extension.id}/${extension.icon}`;
4530
+ }
4531
+ return `/remote/${extension.path}/${extension.icon}`; // TODO support windows paths
4532
+ }
4533
+ return '';
4534
+ };
4535
+
4536
+ const getDescription = extension => {
4537
+ if (!extension || !extension.description) {
4538
+ return 'n/a';
4539
+ }
4540
+ return extension.description;
4541
+ };
4542
+
4543
+ const getName = extension => {
4544
+ if (extension && extension.name) {
4545
+ return extension.name;
4546
+ }
4547
+ if (extension && extension.id) {
4548
+ return extension.id;
4549
+ }
4550
+ return 'n/a';
4551
+ };
4552
+
4553
+ const RendererWorker = 1;
4554
+
4555
+ const rpcs = Object.create(null);
4556
+ const set = (id, rpc) => {
4557
+ rpcs[id] = rpc;
4558
+ };
4559
+ const get = id => {
4560
+ return rpcs[id];
4561
+ };
4562
+
4563
+ const invoke = (method, ...params) => {
4564
+ const rpc = get(RendererWorker);
4565
+ return rpc.invoke(method, ...params);
4566
+ };
4567
+
4568
+ const getAllExtensions = async platform => {
4569
+ if (platform === Web) {
4570
+ return [];
4571
+ }
4572
+ return invoke('ExtensionManagement.getAllExtensions');
4573
+ };
4574
+ const getExtension = async (id, platform) => {
4575
+ const allExtensions = await getAllExtensions(platform);
4576
+ for (const extension of allExtensions) {
4577
+ if (extension.id === id) {
4578
+ return extension;
4579
+ }
4580
+ }
4581
+ return undefined;
4582
+ };
4583
+
4584
+ const getRemoteSrc = uri => {
4585
+ const src = `/remote${uri}`;
4586
+ return src;
4587
+ };
4588
+
4589
+ const getBaseUrl = (extensionPath, platform) => {
4590
+ switch (platform) {
4591
+ case Remote:
4592
+ case Electron:
4593
+ return getRemoteSrc(extensionPath + '/');
4594
+ default:
4595
+ return extensionPath;
4596
+ }
4597
+ };
4598
+
4599
+ const getFolderSize = async uri => {
4600
+ try {
4601
+ return await invoke('FileSystem.getFolderSize', uri);
4602
+ } catch {
4603
+ return 0;
4604
+ }
4605
+ };
4606
+
4607
+ const getSavedSelectedTab = savedState => {
4608
+ if (savedState && typeof savedState === 'object' && 'selectedTab' in savedState && typeof savedState.selectedTab === 'string') {
4609
+ return savedState.selectedTab;
4610
+ }
4611
+ return Details;
4612
+ };
4613
+
4614
+ const Small = 1;
4615
+ const Normal = 2;
4616
+ const Large = 3;
4617
+
4618
+ const getViewletSize = width => {
4619
+ if (width < 180) {
4620
+ return Small;
4621
+ }
4622
+ if (width < 768) {
4623
+ return Normal;
4624
+ }
4625
+ return Large;
4626
+ };
4627
+
4628
+ const readFile = async uri => {
4629
+ return invoke('FileSystem.readFile', uri);
4630
+ };
4631
+
4632
+ const ENOENT = 'ENOENT';
4633
+
4634
+ const isEnoentError = error => {
4635
+ return error && error.code === ENOENT;
4636
+ };
4637
+
4638
+ const join = (pathSeparator, ...parts) => {
4639
+ return parts.join(pathSeparator);
4640
+ };
4641
+
4642
+ const loadReadmeContent = async path => {
4643
+ try {
4644
+ const readmeUrl = join('/', path, 'README.md');
4645
+ const readmeContent = await readFile(readmeUrl);
4646
+ return readmeContent;
4647
+ } catch (error) {
4648
+ if (isEnoentError(error)) {
4649
+ return '';
4650
+ }
4651
+ console.error(error);
4652
+ return `${error}`;
4653
+ }
4654
+ };
4655
+
4656
+ const loadContent = async (state, platform, savedState) => {
4252
4657
  const {
4253
4658
  uri,
4254
4659
  width
@@ -4256,7 +4661,6 @@ const loadContent = async (state, platform) => {
4256
4661
  const id = uri.slice('extension-detail://'.length);
4257
4662
  const extension = await getExtension(id, platform);
4258
4663
  const readmeContent = await loadReadmeContent(extension.path);
4259
- // @ts-ignore
4260
4664
  const baseUrl = getBaseUrl(extension.path, platform);
4261
4665
  const readmeHtml = await renderMarkdown(readmeContent, {
4262
4666
  baseUrl
@@ -4267,7 +4671,43 @@ const loadContent = async (state, platform) => {
4267
4671
  const description = getDescription(extension);
4268
4672
  const name = getName(extension);
4269
4673
  const size = getViewletSize(width);
4270
- const selectedTab = Details;
4674
+ const selectedTab = getSavedSelectedTab(savedState);
4675
+ const features = getFeatures();
4676
+ const folderSize = await getFolderSize(extension.uri);
4677
+ const entries = [{
4678
+ key: 'Identifier',
4679
+ value: 'abc'
4680
+ }, {
4681
+ key: 'Version',
4682
+ value: '1.9.5'
4683
+ }, {
4684
+ key: 'Last Updated',
4685
+ value: 'n/a'
4686
+ }];
4687
+ const secondEntries = [{
4688
+ key: 'Published',
4689
+ value: 'n/a'
4690
+ }, {
4691
+ key: 'Last Released',
4692
+ value: 'n/a'
4693
+ }];
4694
+ const categories = [{
4695
+ id: 'themes',
4696
+ label: 'Themes'
4697
+ }];
4698
+ const resources = [{
4699
+ label: 'Marketplace',
4700
+ url: '#'
4701
+ }, {
4702
+ label: 'Issues',
4703
+ url: '#'
4704
+ }, {
4705
+ label: 'Repository',
4706
+ url: '#'
4707
+ }, {
4708
+ label: 'License',
4709
+ url: '#'
4710
+ }];
4271
4711
  return {
4272
4712
  ...state,
4273
4713
  selectedTab,
@@ -4275,7 +4715,24 @@ const loadContent = async (state, platform) => {
4275
4715
  iconSrc,
4276
4716
  name,
4277
4717
  description,
4278
- size
4718
+ size,
4719
+ entries,
4720
+ secondEntries,
4721
+ categories,
4722
+ resources,
4723
+ extension,
4724
+ baseUrl,
4725
+ features,
4726
+ folderSize
4727
+ };
4728
+ };
4729
+
4730
+ const saveState = state => {
4731
+ const {
4732
+ selectedTab
4733
+ } = state;
4734
+ return {
4735
+ selectedTab
4279
4736
  };
4280
4737
  };
4281
4738
 
@@ -4284,12 +4741,16 @@ const terminate = () => {
4284
4741
  };
4285
4742
 
4286
4743
  const commandMap = {
4744
+ 'ExtensionDetail.create': create,
4287
4745
  'ExtensionDetail.getMenuEntries': getMenuEntries,
4288
4746
  'ExtensionDetail.getVirtualDom': getExtensionDetailVirtualDom,
4747
+ 'ExtensionDetail.handleFeaturesClick': handleClickFeatures,
4748
+ 'ExtensionDetail.handleIconError': handleIconError,
4749
+ 'ExtensionDetail.handleTabsClick': handleTabsClick,
4289
4750
  'ExtensionDetail.loadContent': loadContent,
4751
+ 'ExtensionDetail.saveState': saveState,
4752
+ 'ExtensionDetail.selectTab': selectTab,
4290
4753
  'ExtensionDetail.terminate': terminate,
4291
- 'ExtensionDetail.handleTabsClick': handleTabsClick,
4292
- 'ExtensionDetail.handleIconError': handleIconError,
4293
4754
  // deprecated
4294
4755
  'HandleIconError.handleIconError': handleIconError,
4295
4756
  'RenderMarkdown.renderMarkdown': renderMarkdown
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-detail-view",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "Extension Detail View Worker",
5
- "main": "dist/extensionDetailViewWorkerMain.js",
6
- "type": "module",
7
5
  "keywords": [],
6
+ "license": "MIT",
8
7
  "author": "Lvce Editor",
9
- "license": "MIT"
8
+ "type": "module",
9
+ "main": "dist/extensionDetailViewWorkerMain.js"
10
10
  }