@lvce-editor/extension-detail-view 2.1.0 → 2.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.
@@ -1,3 +1,44 @@
1
+ class AssertionError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = 'AssertionError';
5
+ }
6
+ }
7
+ const getType = value => {
8
+ switch (typeof value) {
9
+ case 'number':
10
+ return 'number';
11
+ case 'function':
12
+ return 'function';
13
+ case 'string':
14
+ return 'string';
15
+ case 'object':
16
+ if (value === null) {
17
+ return 'null';
18
+ }
19
+ if (Array.isArray(value)) {
20
+ return 'array';
21
+ }
22
+ return 'object';
23
+ case 'boolean':
24
+ return 'boolean';
25
+ default:
26
+ return 'unknown';
27
+ }
28
+ };
29
+ const array = value => {
30
+ const type = getType(value);
31
+ if (type !== 'array') {
32
+ throw new AssertionError('expected value to be of type array');
33
+ }
34
+ };
35
+ const string = value => {
36
+ const type = getType(value);
37
+ if (type !== 'string') {
38
+ throw new AssertionError('expected value to be of type string');
39
+ }
40
+ };
41
+
1
42
  const Two = '2.0';
2
43
  const create$4 = (method, params) => {
3
44
  return {
@@ -774,13 +815,18 @@ const handleMessage = event => {
774
815
  return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError, logError, requiresSocket);
775
816
  };
776
817
  const handleIpc = ipc => {
777
- ipc.addEventListener('message', handleMessage);
818
+ if ('addEventListener' in ipc) {
819
+ ipc.addEventListener('message', handleMessage);
820
+ } else if ('on' in ipc) {
821
+ // deprecated
822
+ ipc.on('message', handleMessage);
823
+ }
778
824
  };
779
-
780
- // @ts-ignore
781
- const listen$1 = async () => {
782
- const module = IpcChildWithModuleWorkerAndMessagePort$1;
783
- const rawIpc = await module.listen();
825
+ const listen$1 = async (module, options) => {
826
+ const rawIpc = await module.listen(options);
827
+ if (module.signal) {
828
+ module.signal(rawIpc);
829
+ }
784
830
  const ipc = module.wrap(rawIpc);
785
831
  return ipc;
786
832
  };
@@ -789,7 +835,7 @@ const create = async ({
789
835
  }) => {
790
836
  // TODO create a commandMap per rpc instance
791
837
  register(commandMap);
792
- const ipc = await listen$1();
838
+ const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
793
839
  handleIpc(ipc);
794
840
  const rpc = createRpc(ipc);
795
841
  return rpc;
@@ -801,14 +847,16 @@ const WebWorkerRpcClient = {
801
847
 
802
848
  const Document = 'document';
803
849
 
804
- const HandleReadmeContextMenu = 'handleReadmeContextMenu';
805
-
850
+ const ExtensionDetail = 'ExtensionDetail';
806
851
  const ExtensionDetailDescription = 'ExtensionDetailDescription';
807
852
  const ExtensionDetailHeader = 'ExtensionDetailHeader';
808
853
  const ExtensionDetailHeaderDetails = 'ExtensionDetailHeaderDetails';
809
854
  const ExtensionDetailIcon = 'ExtensionDetailIcon';
810
855
  const ExtensionDetailName = 'ExtensionDetailName';
811
856
  const Markdown = 'Markdown';
857
+ const Viewlet = 'Viewlet';
858
+
859
+ const HandleReadmeContextMenu = 'handleReadmeContextMenu';
812
860
 
813
861
  const Div$1 = 4;
814
862
  const H1$1 = 5;
@@ -886,47 +934,6 @@ const getExtensionDetailHeaderVirtualDom = extensionDetail => {
886
934
 
887
935
  const allowedMarkdownAttributes = ['src', 'id', 'className', 'title', 'alt', 'href', 'target', 'rel'];
888
936
 
889
- class AssertionError extends Error {
890
- constructor(message) {
891
- super(message);
892
- this.name = 'AssertionError';
893
- }
894
- }
895
- const getType = value => {
896
- switch (typeof value) {
897
- case 'number':
898
- return 'number';
899
- case 'function':
900
- return 'function';
901
- case 'string':
902
- return 'string';
903
- case 'object':
904
- if (value === null) {
905
- return 'null';
906
- }
907
- if (Array.isArray(value)) {
908
- return 'array';
909
- }
910
- return 'object';
911
- case 'boolean':
912
- return 'boolean';
913
- default:
914
- return 'unknown';
915
- }
916
- };
917
- const array = value => {
918
- const type = getType(value);
919
- if (type !== 'array') {
920
- throw new AssertionError('expected value to be of type array');
921
- }
922
- };
923
- const string = value => {
924
- const type = getType(value);
925
- if (type !== 'string') {
926
- throw new AssertionError('expected value to be of type string');
927
- }
928
- };
929
-
930
937
  const Div = 'div';
931
938
  const H1 = 'h1';
932
939
  const H2 = 'h2';
@@ -1107,10 +1114,6 @@ const RE_TAG_TEXT = /^[^\s>]+/;
1107
1114
  const RE_ANY_TEXT = /^[^\n]+/;
1108
1115
  const RE_BLOCK_COMMENT_START = /^<!--/;
1109
1116
  const RE_SELF_CLOSING = /^\/>/;
1110
-
1111
- /**
1112
- * @param {string} text
1113
- */
1114
1117
  const tokenizeHtml = text => {
1115
1118
  string(text);
1116
1119
  let state = State.TopLevelContent;
@@ -1391,12 +1394,20 @@ const getVirtualDomChildCount = markdownDom => {
1391
1394
  return stack.length;
1392
1395
  };
1393
1396
 
1397
+ const joinBySpace = (...items) => {
1398
+ return items.join(' ');
1399
+ };
1400
+
1401
+ const mergeClassNames = (...classNames) => {
1402
+ return joinBySpace(...classNames.filter(Boolean));
1403
+ };
1404
+
1394
1405
  const getExtensionDetailVirtualDom = (extensionDetail, sanitizedReadmeHtml) => {
1395
1406
  const markdownDom = getMarkdownVirtualDom(sanitizedReadmeHtml);
1396
1407
  const childCount = getVirtualDomChildCount(markdownDom);
1397
1408
  const dom = [{
1398
1409
  type: Div$1,
1399
- className: 'Viewlet ExtensionDetail',
1410
+ className: mergeClassNames(Viewlet, ExtensionDetail),
1400
1411
  childCount: childCount + 1
1401
1412
  }, ...getExtensionDetailHeaderVirtualDom(extensionDetail), {
1402
1413
  type: Div$1,
@@ -1420,9 +1431,6 @@ const i18nString = (key, placeholders = emptyObject) => {
1420
1431
  return key.replaceAll(RE_PLACEHOLDER, replacer);
1421
1432
  };
1422
1433
 
1423
- /**
1424
- * @enum {string}
1425
- */
1426
1434
  const UiStrings = {
1427
1435
  Copy: 'Copy',
1428
1436
  OpenInNewTab: 'Open in New Tab',
@@ -1432,6 +1440,9 @@ const UiStrings = {
1432
1440
  const copy = () => {
1433
1441
  return i18nString(UiStrings.Copy);
1434
1442
  };
1443
+ const openInNewTab = () => {
1444
+ return i18nString(UiStrings.OpenInNewTab);
1445
+ };
1435
1446
  const openImageInNewTab = () => {
1436
1447
  return i18nString(UiStrings.OpenImageInNewTab);
1437
1448
  };
@@ -1441,40 +1452,47 @@ const saveImageAs = () => {
1441
1452
 
1442
1453
  const None = 0;
1443
1454
 
1444
- const getMenuEntries = props => {
1445
- const menuEntries = [];
1446
- if (props.isLink) {
1447
- menuEntries.push({
1448
- id: 'openInNewTab',
1449
- label: openImageInNewTab(),
1450
- flags: None,
1451
- command: 'Open.openUrl',
1452
- args: [props.url]
1453
- });
1454
- } else if (props.isImage) {
1455
- menuEntries.push({
1456
- id: 'openImageInNewTab',
1457
- label: openImageInNewTab(),
1458
- flags: None,
1459
- command: 'Open.openUrl',
1460
- args: [props.url]
1461
- }, {
1462
- id: 'saveImageAs',
1463
- label: saveImageAs(),
1464
- flags: None,
1465
- command: 'SaveFileAs.saveFileAs',
1466
- args: ['image.png', props.url]
1467
- });
1455
+ const getCopyMenuEntry = () => ({
1456
+ id: 'copy',
1457
+ label: copy(),
1458
+ flags: None,
1459
+ command: 'ClipBoard.execCopy'
1460
+ });
1461
+
1462
+ const getImageMenuEntries = props => {
1463
+ if (!props.isImage) {
1464
+ return [];
1468
1465
  }
1469
- menuEntries.push({
1470
- id: 'copy',
1471
- label: copy(),
1466
+ return [{
1467
+ id: 'openImageInNewTab',
1468
+ label: openImageInNewTab(),
1472
1469
  flags: None,
1473
- command: 'ClipBoard.execCopy'
1474
- });
1475
- return menuEntries;
1470
+ command: 'Open.openUrl',
1471
+ args: [props.url || '']
1472
+ }, {
1473
+ id: 'saveImageAs',
1474
+ label: saveImageAs(),
1475
+ flags: None,
1476
+ command: 'SaveFileAs.saveFileAs',
1477
+ args: ['image.png', props.url || '']
1478
+ }];
1476
1479
  };
1477
1480
 
1481
+ const getLinkMenuEntries = props => {
1482
+ if (!props.isLink) {
1483
+ return [];
1484
+ }
1485
+ return [{
1486
+ id: 'openInNewTab',
1487
+ label: openInNewTab(),
1488
+ flags: None,
1489
+ command: 'Open.openUrl',
1490
+ args: [props.url || '']
1491
+ }];
1492
+ };
1493
+
1494
+ const getMenuEntries = props => [...getLinkMenuEntries(props), ...getImageMenuEntries(props), getCopyMenuEntry()];
1495
+
1478
1496
  const assetDir = '';
1479
1497
 
1480
1498
  const ExtensionDefaultIcon = `${assetDir}/icons/extensionDefaultIcon.png`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-detail-view",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Extension Detail View Worker",
5
5
  "main": "dist/extensionDetailViewWorkerMain.js",
6
6
  "type": "module",