@lvce-editor/extension-detail-view 4.10.0 → 4.11.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.
@@ -319,7 +319,9 @@ const Dt = 67;
319
319
 
320
320
  const ClientX = 'event.clientX';
321
321
  const ClientY = 'event.clientY';
322
+ const TargetHref = 'event.target.href';
322
323
  const TargetName = 'event.target.name';
324
+ const TargetSrc = 'event.target.src';
323
325
 
324
326
  const DebugWorker = 55;
325
327
  const ExtensionHostWorker = 44;
@@ -618,7 +620,7 @@ const getCommandsVirtualDom = state => {
618
620
  return getFeatureCommandsVirtualDom(state.commands);
619
621
  };
620
622
 
621
- const isExternalLink = schema => {
623
+ const isExternalLink$1 = schema => {
622
624
  return schema.startsWith('http://') || schema.startsWith('https://');
623
625
  };
624
626
  const hasWhitespace = value => {
@@ -665,7 +667,7 @@ const getSchemaLinkUrl = (schema, extensionUri) => {
665
667
  if (trimmed !== schema) {
666
668
  return '';
667
669
  }
668
- if (isExternalLink(schema)) {
670
+ if (isExternalLink$1(schema)) {
669
671
  return isValidHttpUrl(schema) ? schema : '';
670
672
  }
671
673
  if (!isValidRelativePath(schema)) {
@@ -2692,6 +2694,7 @@ const HandleReadmeContextMenu = 12;
2692
2694
  const HandleReadmeScroll = 13;
2693
2695
  const HandleTabsClick = 14;
2694
2696
  const HandleAdditionalDetailContextMenu = 15;
2697
+ const HandleReadmeClick = 16;
2695
2698
 
2696
2699
  const ActivationEvents = 'ActivationEvents';
2697
2700
  const Changelog = 'Changelog';
@@ -2741,7 +2744,8 @@ const getMarkdownVirtualDom = async (html, options) => {
2741
2744
  return [{
2742
2745
  ...firstNode,
2743
2746
  onScroll: HandleReadmeScroll,
2744
- childCount: firstNode.childCount + 1
2747
+ childCount: firstNode.childCount + 1,
2748
+ onClick: HandleReadmeClick
2745
2749
  }, ...extraDom, ...rest];
2746
2750
  }
2747
2751
  return dom;
@@ -2780,25 +2784,34 @@ const getThemeMarkdown = (themes, iconThemes, productIconThemes) => {
2780
2784
  return markdown;
2781
2785
  };
2782
2786
 
2787
+ const padBytes = bytes => {
2788
+ return bytes.toString(16).padStart(2, '0');
2789
+ };
2790
+ const hash = async content => {
2791
+ const sourceBytes = new TextEncoder().encode(content);
2792
+ const digest = await crypto.subtle.digest('SHA-256', sourceBytes);
2793
+ const resultBytes = [...new Uint8Array(digest)];
2794
+ return resultBytes.map(padBytes).join('');
2795
+ };
2796
+
2783
2797
  const supportsNormalCacheKey = locationProtocol => {
2784
2798
  return locationProtocol === 'http:' || locationProtocol === 'https:';
2785
2799
  };
2786
2800
 
2787
- const getMarkdownCacheKey = (hash, locationProtocol) => {
2788
- if (supportsNormalCacheKey(locationProtocol)) {
2801
+ const getMarkdownCacheHash = async (markdown, options) => {
2802
+ const stringifiedOptions = JSON.stringify(options);
2803
+ const contents = `${markdown}:${stringifiedOptions}`;
2804
+ return hash(contents);
2805
+ };
2806
+ const getMarkdownCacheKey = async (markdown, options) => {
2807
+ const hash = await getMarkdownCacheHash(markdown, options);
2808
+ if (supportsNormalCacheKey(options.locationProtocol)) {
2789
2809
  return `/markdown/${hash}`;
2790
2810
  }
2791
2811
  // workaround for electron bug
2792
2812
  return `https://-/markdown/${hash}`;
2793
2813
  };
2794
2814
 
2795
- const hash = async content => {
2796
- const sourceBytes = new TextEncoder().encode(content);
2797
- const digest = await crypto.subtle.digest('SHA-256', sourceBytes);
2798
- const resultBytes = [...new Uint8Array(digest)];
2799
- return resultBytes.map(x => x.toString(16).padStart(2, '0')).join('');
2800
- };
2801
-
2802
2815
  // TODO pass application name from renderer worker to not hardcode it
2803
2816
  const bucketName = 'markdown-cache';
2804
2817
  const cachedCaches = Object.create(null);
@@ -2857,8 +2870,7 @@ const set$3 = async (key, value) => {
2857
2870
  };
2858
2871
 
2859
2872
  const renderMarkdownCached = async (markdown, options) => {
2860
- const markdownHash = await hash(markdown); // TODO hash options also
2861
- const cacheKey = getMarkdownCacheKey(markdownHash, options.locationProtocol);
2873
+ const cacheKey = await getMarkdownCacheKey(markdown, options);
2862
2874
  const hasItem = await has(cacheKey);
2863
2875
  if (hasItem) {
2864
2876
  const value = await get$1(cacheKey);
@@ -3682,6 +3694,20 @@ const handleImageContextMenu = async (state, eventX, eventY) => {
3682
3694
  return state;
3683
3695
  };
3684
3696
 
3697
+ const isExternalLink = href => {
3698
+ return href.startsWith('http://') || href.startsWith('https://');
3699
+ };
3700
+ const handleReadmeClick = async (state, nodeName, href) => {
3701
+ if (!href || !isExternalLink(href)) {
3702
+ return state;
3703
+ }
3704
+ // TODO what to do about relative links? open them in editor?
3705
+ // TODO what to do about mail links?
3706
+ await openUrl$2(href);
3707
+ // TODO check node name and href
3708
+ return state;
3709
+ };
3710
+
3685
3711
  const handleScroll = (state, scrollTop, scrollSource = Script) => {
3686
3712
  const newScrollTop = Math.max(0, scrollTop);
3687
3713
  return {
@@ -4719,6 +4745,14 @@ const getAdditionalDetailsVirtualDom = (showAdditionalDetails, firstHeading, ent
4719
4745
  }, ...getAdditionalDetailsEntryVirtualDom(firstHeading, entries, getMoreInfoVirtualDom), ...getAdditionalDetailsEntryVirtualDom(secondHeading, secondEntries, getMoreInfoVirtualDom), ...getAdditionalDetailsEntryVirtualDom(thirdHeading, categories, getCategoriesDom), ...getAdditionalDetailsEntryVirtualDom(fourthHeading, resources, getResourcesVirtualDom)];
4720
4746
  };
4721
4747
 
4748
+ const getNoReadmeVirtualDom = () => {
4749
+ return [{
4750
+ type: Div,
4751
+ childCount: 1,
4752
+ className: Markdown
4753
+ }, text(noReadmeFound())];
4754
+ };
4755
+
4722
4756
  const getChildCount = (additionalDetails, scrollToTopEnabled) => {
4723
4757
  let count = 1;
4724
4758
  if (additionalDetails) {
@@ -4733,11 +4767,7 @@ const getDetailsVirtualDom = (sanitizedReadmeHtml, width, scrollToTopButtonEnabl
4733
4767
  const fourthHeading = resources();
4734
4768
  const showAdditionalDetails = showSideBar;
4735
4769
  const childCount = getChildCount(showAdditionalDetails);
4736
- const contentDom = hasReadme ? sanitizedReadmeHtml : [{
4737
- type: Div,
4738
- childCount: 1,
4739
- className: Markdown
4740
- }, text(noReadmeFound())];
4770
+ const contentDom = hasReadme ? sanitizedReadmeHtml : getNoReadmeVirtualDom();
4741
4771
  const dom = [{
4742
4772
  type: Div,
4743
4773
  className: ExtensionDetailPanel,
@@ -5072,7 +5102,7 @@ const renderEventListeners = () => {
5072
5102
  params: ['handleIconError']
5073
5103
  }, {
5074
5104
  name: HandleReadmeContextMenu,
5075
- params: ['handleReadmeContextMenu', ClientX, ClientY, 'event.target.href', 'event.target.src']
5105
+ params: ['handleReadmeContextMenu', ClientX, ClientY, TargetHref, TargetSrc]
5076
5106
  }, {
5077
5107
  name: HandleImageContextMenu,
5078
5108
  params: ['handleImageContextMenu', ClientX, ClientY],
@@ -5100,6 +5130,10 @@ const renderEventListeners = () => {
5100
5130
  }, {
5101
5131
  name: HandleClickSettings,
5102
5132
  params: ['handleClickSettings']
5133
+ }, {
5134
+ name: HandleReadmeClick,
5135
+ params: ['handleReadmeClick', 'event.target.nodeName', 'event.target.href'],
5136
+ preventDefault: true
5103
5137
  }, {
5104
5138
  name: HandleClickUninstall,
5105
5139
  params: ['handleClickUninstall']
@@ -5162,6 +5196,7 @@ const commandMap = {
5162
5196
  'ExtensionDetail.handleImageContextMenu': wrapCommand(handleImageContextMenu),
5163
5197
  'ExtensionDetail.handleScroll': wrapCommand(handleScroll),
5164
5198
  'ExtensionDetail.handleTabsClick': wrapCommand(handleTabsClick),
5199
+ 'ExtensionDetail.handleReadmeClick': wrapCommand(handleReadmeClick),
5165
5200
  'ExtensionDetail.handleWheel': wrapCommand(handleScroll),
5166
5201
  // deprecated
5167
5202
  'ExtensionDetail.initialize': initialize,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-detail-view",
3
- "version": "4.10.0",
3
+ "version": "4.11.0",
4
4
  "description": "Extension Detail View Worker",
5
5
  "repository": {
6
6
  "type": "git",