@lvce-editor/extension-detail-view 6.3.0 → 6.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.
@@ -681,7 +681,7 @@ const existsJson = async schemaUrl => {
681
681
  }
682
682
  };
683
683
 
684
- const isExternalLink$1 = schema => {
684
+ const isExternalLink$2 = schema => {
685
685
  return schema.startsWith('http://') || schema.startsWith('https://');
686
686
  };
687
687
  const hasWhitespace = value => {
@@ -728,7 +728,7 @@ const getSchemaLinkUrl = (schema, extensionUri) => {
728
728
  if (trimmed !== schema) {
729
729
  return '';
730
730
  }
731
- if (isExternalLink$1(schema)) {
731
+ if (isExternalLink$2(schema)) {
732
732
  return isValidHttpUrl(schema) ? schema : '';
733
733
  }
734
734
  if (!isValidRelativePath(schema)) {
@@ -1022,7 +1022,7 @@ const TargetName = 'event.target.name';
1022
1022
  const Script$1 = 2;
1023
1023
 
1024
1024
  const ExtensionDetailReadme = 20;
1025
- const ExtensionDetailIconContextMenu$3 = 4091;
1025
+ const ExtensionDetailIconContextMenu$2 = 4091;
1026
1026
 
1027
1027
  const None$2 = 0;
1028
1028
 
@@ -2316,6 +2316,9 @@ const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
2316
2316
  const command = 'Extensions.handleMessagePort';
2317
2317
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
2318
2318
  };
2319
+ const getPreference = async key => {
2320
+ return await invoke$1('Preferences.get', key);
2321
+ };
2319
2322
  const getAllExtensions$1 = async () => {
2320
2323
  return invoke$1('ExtensionManagement.getAllExtensions');
2321
2324
  };
@@ -2338,6 +2341,10 @@ const setExtensionsSearchValue = async searchValue => {
2338
2341
  // @ts-ignore
2339
2342
  return invoke$1('Extensions.handleInput', searchValue, Script$1);
2340
2343
  };
2344
+ const openExternal$1 = async uri => {
2345
+ // @ts-ignore
2346
+ await invoke$1('Open.openExternal', uri);
2347
+ };
2341
2348
  const openUrl = async uri => {
2342
2349
  // @ts-ignore
2343
2350
  await invoke$1('Open.openUrl', uri);
@@ -2544,6 +2551,7 @@ const HandleAdditionalDetailContextMenu = 15;
2544
2551
  const HandleReadmeClick = 16;
2545
2552
  const HandleSelectionChange = 17;
2546
2553
  const HandleTabFocus = 18;
2554
+ const HandleResourceLinkClick = 19;
2547
2555
 
2548
2556
  const ActivationEvents = 'ActivationEvents';
2549
2557
  const Changelog = 'Changelog';
@@ -3060,6 +3068,9 @@ const readFileAsBlob = async uri => {
3060
3068
  };
3061
3069
 
3062
3070
  const getImageCopyUrl = (iconSrc, locationProtocol, locationHost) => {
3071
+ if (!iconSrc) {
3072
+ return '';
3073
+ }
3063
3074
  const prefix = `${locationProtocol}//${locationHost}`;
3064
3075
  const absoluteIconSrc = `${prefix}${iconSrc}`;
3065
3076
  return absoluteIconSrc;
@@ -3084,6 +3095,9 @@ const copyImageUrl = async state => {
3084
3095
  locationProtocol
3085
3096
  } = state;
3086
3097
  const absoluteIconSrc = getImageCopyUrl(iconSrc, locationProtocol, locationHost);
3098
+ if (!absoluteIconSrc) {
3099
+ return state;
3100
+ }
3087
3101
  await writeText(absoluteIconSrc);
3088
3102
  return state;
3089
3103
  };
@@ -3281,7 +3295,7 @@ const getMenuEntriesImage = (state, props) => {
3281
3295
  };
3282
3296
 
3283
3297
  const getMenuEntries2 = (state, props) => {
3284
- if (props.menuId === ExtensionDetailIconContextMenu$3) {
3298
+ if (props.menuId === ExtensionDetailIconContextMenu$2) {
3285
3299
  return getMenuEntriesImage();
3286
3300
  }
3287
3301
  if (props.menuId === ExtensionDetailReadme && props.href) {
@@ -3351,7 +3365,6 @@ const getLinkMenuEntries = props => {
3351
3365
 
3352
3366
  const getMenuEntries = props => [...getLinkMenuEntries(props), ...getImageMenuEntries(props), getCopyMenuEntry()];
3353
3367
 
3354
- const ExtensionDetailIconContextMenu$2 = 4091;
3355
3368
  const getMenuIds = () => {
3356
3369
  return [ExtensionDetailReadme, ExtensionDetailIconContextMenu$2];
3357
3370
  };
@@ -3671,6 +3684,15 @@ const getExtensionIdFromUri = uri => {
3671
3684
  return id;
3672
3685
  };
3673
3686
 
3687
+ const getLinkProtectionEnabled = async () => {
3688
+ try {
3689
+ const setting = await getPreference('application.linkProtectionEnabled');
3690
+ return setting === true || setting === 'true';
3691
+ } catch {
3692
+ return false;
3693
+ }
3694
+ };
3695
+
3674
3696
  const interpolate = (value, inMin, inMax, outMin, outMax) => {
3675
3697
  const clamped = Math.min(Math.max(value, inMin), inMax);
3676
3698
  const ratio = (clamped - inMin) / (inMax - inMin);
@@ -4039,6 +4061,7 @@ const supportsFileSize = uri => {
4039
4061
  }
4040
4062
  return true;
4041
4063
  };
4064
+
4042
4065
  const getFolderSize = async uri => {
4043
4066
  if (!uri) {
4044
4067
  throw new VError(`uri is required`);
@@ -4098,11 +4121,6 @@ const getMarketplaceEntries = isBuiltin => {
4098
4121
  }];
4099
4122
  };
4100
4123
 
4101
- const getLicenseLink = extension => {
4102
- // TODO
4103
- return '#';
4104
- };
4105
-
4106
4124
  const ensureValidLink = link => {
4107
4125
  if (!link) {
4108
4126
  return '';
@@ -4129,39 +4147,62 @@ const getRepositoryLink = extension => {
4129
4147
  const validLink = ensureValidLink(raw);
4130
4148
  return validLink;
4131
4149
  };
4150
+
4151
+ const isGitHubRepository$1 = url => {
4152
+ return url.startsWith('https://github.com/');
4153
+ };
4132
4154
  const getIssuesLink = extension => {
4133
4155
  const repositoryLink = getRepositoryLink(extension);
4134
4156
  if (!repositoryLink) {
4135
4157
  return '';
4136
4158
  }
4137
- if (repositoryLink && repositoryLink.startsWith('https://github.com')) {
4159
+ if (isGitHubRepository$1(repositoryLink)) {
4138
4160
  return `${repositoryLink}/issues`;
4139
4161
  }
4140
4162
  return '';
4141
4163
  };
4142
4164
 
4165
+ const isGitHubRepository = url => {
4166
+ return url.startsWith('https://github.com/');
4167
+ };
4168
+ const getLicenseLink = extension => {
4169
+ const repositoryLink = getRepositoryLink(extension);
4170
+ if (!repositoryLink) {
4171
+ return '#';
4172
+ }
4173
+ if (isGitHubRepository(repositoryLink)) {
4174
+ const normalizedLink = repositoryLink.replace(/\/+$/, '');
4175
+ return `${normalizedLink}/blob/main/license.md`;
4176
+ }
4177
+ return '#';
4178
+ };
4179
+
4143
4180
  const getResources = (isBuiltin, extension) => {
4144
4181
  const repositoryLink = getRepositoryLink(extension);
4145
4182
  const issueLink = getIssuesLink(extension);
4146
- const licenseLink = getLicenseLink();
4147
- // TODO hide marketplace link for builtin extensions
4148
- return [{
4183
+ const licenseLink = getLicenseLink(extension);
4184
+ const rawResources = [{
4185
+ enabled: !isBuiltin,
4149
4186
  icon: 'LinkExternal',
4150
4187
  label: marketplace(),
4151
4188
  url: '#'
4152
4189
  }, {
4190
+ enabled: true,
4153
4191
  icon: 'LinkExternal',
4154
4192
  label: issues(),
4155
4193
  url: issueLink
4156
4194
  }, {
4195
+ enabled: true,
4157
4196
  icon: 'Repo',
4158
4197
  label: repository(),
4159
4198
  url: repositoryLink
4160
4199
  }, {
4200
+ enabled: true,
4161
4201
  icon: 'LinkExternal',
4162
4202
  label: license(),
4163
4203
  url: licenseLink
4164
4204
  }];
4205
+ return rawResources.filter(resource => resource.enabled);
4165
4206
  };
4166
4207
 
4167
4208
  const loadSideBarContent = async (extensionId, extensionVersion, extensionUri, isBuiltin, extension, showSizeLink) => {
@@ -4261,6 +4302,7 @@ const loadContent = async (state, platform, savedState, isTest = false) => {
4261
4302
  const [hasReadme, hasChangelog] = await Promise.all([existsFile(readmeUrl), existsFile(changelogUrl)]);
4262
4303
  const readmeContent = hasReadme ? await loadReadmeContent(readmeUrl) : noReadmeFound();
4263
4304
  const baseUrl = getBaseUrl(extension.path, platform);
4305
+ // TODO maybe pass these as arguments also
4264
4306
  const locationProtocol = location.protocol;
4265
4307
  const locationHost = location.host;
4266
4308
  const readmeHtml = await renderMarkdown(readmeContent, {
@@ -4299,6 +4341,7 @@ const loadContent = async (state, platform, savedState, isTest = false) => {
4299
4341
  const padding = getPadding(width);
4300
4342
  const sideBarWidth = getSideBarWidth(width);
4301
4343
  const showSideBar = sideBarWidth > 0;
4344
+ const linkProtectionEnabled = await getLinkProtectionEnabled();
4302
4345
  return {
4303
4346
  ...state,
4304
4347
  badge,
@@ -4322,6 +4365,7 @@ const loadContent = async (state, platform, savedState, isTest = false) => {
4322
4365
  hasReadme,
4323
4366
  iconSrc,
4324
4367
  installationEntries,
4368
+ linkProtectionEnabled,
4325
4369
  locationHost,
4326
4370
  locationProtocol,
4327
4371
  marketplaceEntries,
@@ -4389,9 +4433,17 @@ const handleImageContextMenu = async (state, eventX, eventY) => {
4389
4433
  return state;
4390
4434
  };
4391
4435
 
4436
+ const openExternalElectron = async uri => {
4437
+ await openExternal$1(uri);
4438
+ };
4439
+ const openExternalWeb = async uri => {
4440
+ await openUrl(uri);
4441
+ };
4392
4442
  const openExternal = async (uri, platform) => {
4393
- if (platform === Electron$1) ; else {
4394
- await openUrl(uri);
4443
+ if (platform === Electron$1) {
4444
+ await openExternalElectron(uri);
4445
+ } else {
4446
+ await openExternalWeb(uri);
4395
4447
  }
4396
4448
  };
4397
4449
 
@@ -4409,7 +4461,7 @@ const handleReadmeLinkClick = async (linkProtectionEnabled, platform, href) => {
4409
4461
  return;
4410
4462
  };
4411
4463
 
4412
- const isExternalLink = href => {
4464
+ const isExternalLink$1 = href => {
4413
4465
  return href.startsWith('http://') || href.startsWith('https://');
4414
4466
  };
4415
4467
  const handleReadmeClick = async (state, nodeName, href) => {
@@ -4417,7 +4469,7 @@ const handleReadmeClick = async (state, nodeName, href) => {
4417
4469
  linkProtectionEnabled,
4418
4470
  platform
4419
4471
  } = state;
4420
- if (!href || !isExternalLink(href)) {
4472
+ if (!href || !isExternalLink$1(href)) {
4421
4473
  return state;
4422
4474
  }
4423
4475
  // TODO what to do about relative links? open them in editor?
@@ -4440,6 +4492,21 @@ const handleReadmeContextMenu = async (state, x, y, nodeName, href) => {
4440
4492
  return state;
4441
4493
  };
4442
4494
 
4495
+ const isExternalLink = href => {
4496
+ return href.startsWith('http://') || href.startsWith('https://');
4497
+ };
4498
+ const handleResourceLinkClick = async (state, href) => {
4499
+ const {
4500
+ linkProtectionEnabled,
4501
+ platform
4502
+ } = state;
4503
+ if (!href || !isExternalLink(href)) {
4504
+ return state;
4505
+ }
4506
+ await handleReadmeLinkClick(linkProtectionEnabled, platform, href);
4507
+ return state;
4508
+ };
4509
+
4443
4510
  const handleScroll = (state, scrollTop, scrollSource = Script) => {
4444
4511
  const newScrollTop = Math.max(0, scrollTop);
4445
4512
  return {
@@ -4911,6 +4978,7 @@ const getResourceLinkVirtualDom = resource => {
4911
4978
  childCount: 1 + iconDomCount,
4912
4979
  className: Resource,
4913
4980
  href: url,
4981
+ onClick: HandleResourceLinkClick,
4914
4982
  rel: 'noopener noreferrer',
4915
4983
  target: '_blank',
4916
4984
  type: A
@@ -5381,6 +5449,10 @@ const renderEventListeners = () => {
5381
5449
  name: HandleReadmeClick,
5382
5450
  params: ['handleReadmeClick', 'event.target.nodeName', TargetHref],
5383
5451
  preventDefault: true
5452
+ }, {
5453
+ name: HandleResourceLinkClick,
5454
+ params: ['handleResourceLinkClick', TargetHref],
5455
+ preventDefault: true
5384
5456
  }, {
5385
5457
  name: HandleClickUninstall,
5386
5458
  params: ['handleClickUninstall']
@@ -5457,6 +5529,7 @@ const commandMap = {
5457
5529
  'ExtensionDetail.handleImageContextMenu': wrapCommand(handleImageContextMenu),
5458
5530
  'ExtensionDetail.handleReadmeClick': wrapCommand(handleReadmeClick),
5459
5531
  'ExtensionDetail.handleReadmeContextMenu': wrapCommand(handleReadmeContextMenu),
5532
+ 'ExtensionDetail.handleResourceLinkClick': wrapCommand(handleResourceLinkClick),
5460
5533
  'ExtensionDetail.handleScroll': wrapCommand(handleScroll),
5461
5534
  'ExtensionDetail.handleSelectionChange': wrapCommand(handleSelectionChange),
5462
5535
  'ExtensionDetail.handleTabFocus': wrapCommand(handleTabFocus),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-detail-view",
3
- "version": "6.3.0",
3
+ "version": "6.5.0",
4
4
  "description": "Extension Detail View Worker",
5
5
  "repository": {
6
6
  "type": "git",