@lvce-editor/extension-detail-view 3.0.0 → 3.2.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.
@@ -846,19 +846,21 @@ const WebWorkerRpcClient = {
846
846
  create
847
847
  };
848
848
 
849
- const Document = 'document';
850
-
851
849
  const ExtensionDetail = 'ExtensionDetail';
852
850
  const ExtensionDetailDescription = 'ExtensionDetailDescription';
853
851
  const ExtensionDetailHeader = 'ExtensionDetailHeader';
854
852
  const ExtensionDetailHeaderDetails = 'ExtensionDetailHeaderDetails';
853
+ const Changelog$1 = 'Changelog';
854
+ const Features$1 = 'Features';
855
855
  const ExtensionDetailIcon = 'ExtensionDetailIcon';
856
856
  const ExtensionDetailName = 'ExtensionDetailName';
857
+ const ExtensionDetailTab = 'ExtensionDetailTab';
858
+ const ExtensionDetailTabs = 'ExtensionDetailTabs';
859
+ const ExtensionDetailTabSelected = 'ExtensionDetailTabSelected';
857
860
  const Markdown = 'Markdown';
858
861
  const Viewlet = 'Viewlet';
859
862
 
860
- const HandleReadmeContextMenu = 'handleReadmeContextMenu';
861
-
863
+ const Button = 1;
862
864
  const Div$1 = 4;
863
865
  const H1$1 = 5;
864
866
  const Span$1 = 8;
@@ -900,39 +902,22 @@ const text = data => {
900
902
  };
901
903
  };
902
904
 
903
- const getExtensionDetailHeaderVirtualDom = extensionDetail => {
904
- const {
905
- name,
906
- iconSrc,
907
- description
908
- } = extensionDetail;
909
- const dom = [{
910
- type: Div$1,
911
- className: ExtensionDetailHeader,
912
- childCount: 2
913
- }, {
914
- type: Img$1,
915
- className: ExtensionDetailIcon,
916
- alt: '',
917
- draggable: false,
918
- childCount: 0,
919
- src: iconSrc
920
- }, {
921
- type: Div$1,
922
- className: ExtensionDetailHeaderDetails,
923
- childCount: 2
924
- }, {
925
- type: Div$1,
926
- className: ExtensionDetailName,
927
- childCount: 1
928
- }, text(name), {
905
+ const getChangelogVirtualDom = () => {
906
+ // TODO set tabpanel role
907
+ return [{
929
908
  type: Div$1,
930
- className: ExtensionDetailDescription,
909
+ className: Changelog$1,
931
910
  childCount: 1
932
- }, text(description)];
933
- return dom;
911
+ }, text('Not Implemented')];
934
912
  };
935
913
 
914
+ const Document = 'document';
915
+ const TabList = 'tablist';
916
+ const Tab = 'tab';
917
+
918
+ const HandleReadmeContextMenu = 'handleReadmeContextMenu';
919
+ const HandleTabsClick = 'handleTabsClick';
920
+
936
921
  const allowedMarkdownAttributes = ['src', 'id', 'className', 'title', 'alt', 'href', 'target', 'rel'];
937
922
 
938
923
  const Div = 'div';
@@ -1395,6 +1380,95 @@ const getVirtualDomChildCount = markdownDom => {
1395
1380
  return stack.length;
1396
1381
  };
1397
1382
 
1383
+ const getDetailsVirtualDom = sanitizedReadmeHtml => {
1384
+ const markdownDom = getMarkdownVirtualDom(sanitizedReadmeHtml);
1385
+ const childCount = getVirtualDomChildCount(markdownDom);
1386
+ const dom = [{
1387
+ type: Div$1,
1388
+ className: Markdown,
1389
+ role: Document,
1390
+ onContextMenu: HandleReadmeContextMenu,
1391
+ childCount
1392
+ }, ...markdownDom];
1393
+ return dom;
1394
+ };
1395
+
1396
+ const getFeaturesVirtualDom = () => {
1397
+ // TODO set tabpanel role
1398
+ return [{
1399
+ type: Div$1,
1400
+ className: Features$1,
1401
+ childCount: 1
1402
+ }, text('Not Implemented')];
1403
+ };
1404
+
1405
+ const Details = 'Details';
1406
+ const Features = 'Features';
1407
+ const Changelog = 'Changelog';
1408
+
1409
+ const getExtensionDetailContentVirtualDom = (sanitizedReadmeHtml, selectedTab) => {
1410
+ switch (selectedTab) {
1411
+ case Details:
1412
+ return getDetailsVirtualDom(sanitizedReadmeHtml);
1413
+ case Features:
1414
+ return getFeaturesVirtualDom();
1415
+ case Changelog:
1416
+ return getChangelogVirtualDom();
1417
+ default:
1418
+ return [];
1419
+ }
1420
+ };
1421
+
1422
+ const getExtensionDetailHeaderVirtualDom = extensionDetail => {
1423
+ const {
1424
+ name,
1425
+ iconSrc,
1426
+ description
1427
+ } = extensionDetail;
1428
+ const dom = [{
1429
+ type: Div$1,
1430
+ className: ExtensionDetailHeader,
1431
+ childCount: 2
1432
+ }, {
1433
+ type: Img$1,
1434
+ className: ExtensionDetailIcon,
1435
+ alt: '',
1436
+ draggable: false,
1437
+ childCount: 0,
1438
+ src: iconSrc
1439
+ }, {
1440
+ type: Div$1,
1441
+ className: ExtensionDetailHeaderDetails,
1442
+ childCount: 2
1443
+ }, {
1444
+ type: Div$1,
1445
+ className: ExtensionDetailName,
1446
+ childCount: 1
1447
+ }, text(name), {
1448
+ type: Div$1,
1449
+ className: ExtensionDetailDescription,
1450
+ childCount: 1
1451
+ }, text(description)];
1452
+ return dom;
1453
+ };
1454
+
1455
+ const getTabs = selectedTab => {
1456
+ const tabs = [{
1457
+ label: 'Details',
1458
+ name: Details,
1459
+ selected: selectedTab === Details
1460
+ }, {
1461
+ label: 'Features',
1462
+ name: Features,
1463
+ selected: selectedTab === Features
1464
+ }, {
1465
+ label: 'Changelog',
1466
+ name: Changelog,
1467
+ selected: selectedTab === Changelog
1468
+ }];
1469
+ return tabs;
1470
+ };
1471
+
1398
1472
  const joinBySpace = (...items) => {
1399
1473
  return items.join(' ');
1400
1474
  };
@@ -1403,20 +1477,41 @@ const mergeClassNames = (...classNames) => {
1403
1477
  return joinBySpace(...classNames.filter(Boolean));
1404
1478
  };
1405
1479
 
1406
- const getExtensionDetailVirtualDom = (extensionDetail, sanitizedReadmeHtml) => {
1407
- const markdownDom = getMarkdownVirtualDom(sanitizedReadmeHtml);
1408
- const childCount = getVirtualDomChildCount(markdownDom);
1480
+ const getTabVirtualDom = tab => {
1481
+ const {
1482
+ label,
1483
+ selected,
1484
+ name
1485
+ } = tab;
1486
+ const className = selected ? mergeClassNames(ExtensionDetailTab, ExtensionDetailTabSelected) : ExtensionDetailTab;
1487
+ return [{
1488
+ type: Button,
1489
+ role: Tab,
1490
+ name,
1491
+ className,
1492
+ childCount: 1,
1493
+ tabIndex: -1
1494
+ }, text(label)];
1495
+ };
1496
+
1497
+ const getTabsVirtualDom = tabs => {
1498
+ return [{
1499
+ type: Div$1,
1500
+ className: ExtensionDetailTabs,
1501
+ childCount: tabs.length,
1502
+ role: TabList,
1503
+ onClick: HandleTabsClick,
1504
+ tabIndex: 0
1505
+ }, ...tabs.flatMap(getTabVirtualDom)];
1506
+ };
1507
+
1508
+ const getExtensionDetailVirtualDom = (extensionDetail, sanitizedReadmeHtml, selectedTab) => {
1509
+ const tabs = getTabs(selectedTab);
1409
1510
  const dom = [{
1410
1511
  type: Div$1,
1411
1512
  className: mergeClassNames(Viewlet, ExtensionDetail),
1412
- childCount: childCount + 1
1413
- }, ...getExtensionDetailHeaderVirtualDom(extensionDetail), {
1414
- type: Div$1,
1415
- className: Markdown,
1416
- role: Document,
1417
- onContextMenu: HandleReadmeContextMenu,
1418
- childCount
1419
- }, ...markdownDom];
1513
+ childCount: 3
1514
+ }, ...getExtensionDetailHeaderVirtualDom(extensionDetail), ...getTabsVirtualDom(tabs), ...getExtensionDetailContentVirtualDom(sanitizedReadmeHtml, selectedTab)];
1420
1515
  return dom;
1421
1516
  };
1422
1517
 
@@ -1432,23 +1527,22 @@ const i18nString = (key, placeholders = emptyObject) => {
1432
1527
  return key.replaceAll(RE_PLACEHOLDER, replacer);
1433
1528
  };
1434
1529
 
1435
- const UiStrings = {
1436
- Copy: 'Copy',
1437
- OpenInNewTab: 'Open in New Tab',
1438
- OpenImageInNewTab: 'Open Image in New Tab',
1439
- SaveImageAs: 'Save Image as'
1440
- };
1530
+ const Copy = 'Copy';
1531
+ const OpenInNewTab = 'Open in New Tab';
1532
+ const OpenImageInNewTab = 'Open Image in New Tab';
1533
+ const SaveImageAs = 'Save Image as';
1534
+
1441
1535
  const copy = () => {
1442
- return i18nString(UiStrings.Copy);
1536
+ return i18nString(Copy);
1443
1537
  };
1444
1538
  const openInNewTab = () => {
1445
- return i18nString(UiStrings.OpenInNewTab);
1539
+ return i18nString(OpenInNewTab);
1446
1540
  };
1447
1541
  const openImageInNewTab = () => {
1448
- return i18nString(UiStrings.OpenImageInNewTab);
1542
+ return i18nString(OpenImageInNewTab);
1449
1543
  };
1450
1544
  const saveImageAs = () => {
1451
- return i18nString(UiStrings.SaveImageAs);
1545
+ return i18nString(SaveImageAs);
1452
1546
  };
1453
1547
 
1454
1548
  const None = 0;
@@ -4159,8 +4253,10 @@ const loadContent = async (state, platform) => {
4159
4253
  const description = getDescription(extension);
4160
4254
  const name = getName(extension);
4161
4255
  const size = getViewletSize(width);
4256
+ const selectedTab = Details;
4162
4257
  return {
4163
4258
  ...state,
4259
+ selectedTab,
4164
4260
  sanitizedReadmeHtml: normalizedReadmeHtml,
4165
4261
  iconSrc,
4166
4262
  name,
@@ -4169,12 +4265,28 @@ const loadContent = async (state, platform) => {
4169
4265
  };
4170
4266
  };
4171
4267
 
4268
+ const handleTabsClick = (state, name) => {
4269
+ // TODO load the tabs content if needed
4270
+ return {
4271
+ ...state,
4272
+ selectedTab: name
4273
+ };
4274
+ };
4275
+
4276
+ const terminate = () => {
4277
+ globalThis.close();
4278
+ };
4279
+
4172
4280
  const commandMap = {
4173
- 'RenderMarkdown.renderMarkdown': renderMarkdown,
4174
- 'HandleIconError.handleIconError': handleIconError,
4175
- 'ExtensionDetail.loadContent': loadContent,
4176
4281
  'ExtensionDetail.getMenuEntries': getMenuEntries,
4177
- 'ExtensionDetail.getVirtualDom': getExtensionDetailVirtualDom
4282
+ 'ExtensionDetail.getVirtualDom': getExtensionDetailVirtualDom,
4283
+ 'ExtensionDetail.loadContent': loadContent,
4284
+ 'ExtensionDetail.terminate': terminate,
4285
+ 'ExtensionDetail.handleTabsClick': handleTabsClick,
4286
+ 'ExtensionDetail.handleIconError': handleIconError,
4287
+ // deprecated
4288
+ 'HandleIconError.handleIconError': handleIconError,
4289
+ 'RenderMarkdown.renderMarkdown': renderMarkdown
4178
4290
  };
4179
4291
 
4180
4292
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-detail-view",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "Extension Detail View Worker",
5
5
  "main": "dist/extensionDetailViewWorkerMain.js",
6
6
  "type": "module",