@lvce-editor/extension-detail-view 6.3.0 → 6.4.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,21 +4147,40 @@ 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();
4183
+ const licenseLink = getLicenseLink(extension);
4147
4184
  // TODO hide marketplace link for builtin extensions
4148
4185
  return [{
4149
4186
  icon: 'LinkExternal',
@@ -4299,6 +4336,7 @@ const loadContent = async (state, platform, savedState, isTest = false) => {
4299
4336
  const padding = getPadding(width);
4300
4337
  const sideBarWidth = getSideBarWidth(width);
4301
4338
  const showSideBar = sideBarWidth > 0;
4339
+ const linkProtectionEnabled = await getLinkProtectionEnabled();
4302
4340
  return {
4303
4341
  ...state,
4304
4342
  badge,
@@ -4322,6 +4360,7 @@ const loadContent = async (state, platform, savedState, isTest = false) => {
4322
4360
  hasReadme,
4323
4361
  iconSrc,
4324
4362
  installationEntries,
4363
+ linkProtectionEnabled,
4325
4364
  locationHost,
4326
4365
  locationProtocol,
4327
4366
  marketplaceEntries,
@@ -4389,9 +4428,17 @@ const handleImageContextMenu = async (state, eventX, eventY) => {
4389
4428
  return state;
4390
4429
  };
4391
4430
 
4431
+ const openExternalElectron = async uri => {
4432
+ await openExternal$1(uri);
4433
+ };
4434
+ const openExternalWeb = async uri => {
4435
+ await openUrl(uri);
4436
+ };
4392
4437
  const openExternal = async (uri, platform) => {
4393
- if (platform === Electron$1) ; else {
4394
- await openUrl(uri);
4438
+ if (platform === Electron$1) {
4439
+ await openExternalElectron(uri);
4440
+ } else {
4441
+ await openExternalWeb(uri);
4395
4442
  }
4396
4443
  };
4397
4444
 
@@ -4409,7 +4456,7 @@ const handleReadmeLinkClick = async (linkProtectionEnabled, platform, href) => {
4409
4456
  return;
4410
4457
  };
4411
4458
 
4412
- const isExternalLink = href => {
4459
+ const isExternalLink$1 = href => {
4413
4460
  return href.startsWith('http://') || href.startsWith('https://');
4414
4461
  };
4415
4462
  const handleReadmeClick = async (state, nodeName, href) => {
@@ -4417,7 +4464,7 @@ const handleReadmeClick = async (state, nodeName, href) => {
4417
4464
  linkProtectionEnabled,
4418
4465
  platform
4419
4466
  } = state;
4420
- if (!href || !isExternalLink(href)) {
4467
+ if (!href || !isExternalLink$1(href)) {
4421
4468
  return state;
4422
4469
  }
4423
4470
  // TODO what to do about relative links? open them in editor?
@@ -4440,6 +4487,21 @@ const handleReadmeContextMenu = async (state, x, y, nodeName, href) => {
4440
4487
  return state;
4441
4488
  };
4442
4489
 
4490
+ const isExternalLink = href => {
4491
+ return href.startsWith('http://') || href.startsWith('https://');
4492
+ };
4493
+ const handleResourceLinkClick = async (state, href) => {
4494
+ const {
4495
+ linkProtectionEnabled,
4496
+ platform
4497
+ } = state;
4498
+ if (!href || !isExternalLink(href)) {
4499
+ return state;
4500
+ }
4501
+ await handleReadmeLinkClick(linkProtectionEnabled, platform, href);
4502
+ return state;
4503
+ };
4504
+
4443
4505
  const handleScroll = (state, scrollTop, scrollSource = Script) => {
4444
4506
  const newScrollTop = Math.max(0, scrollTop);
4445
4507
  return {
@@ -4911,6 +4973,7 @@ const getResourceLinkVirtualDom = resource => {
4911
4973
  childCount: 1 + iconDomCount,
4912
4974
  className: Resource,
4913
4975
  href: url,
4976
+ onClick: HandleResourceLinkClick,
4914
4977
  rel: 'noopener noreferrer',
4915
4978
  target: '_blank',
4916
4979
  type: A
@@ -5381,6 +5444,10 @@ const renderEventListeners = () => {
5381
5444
  name: HandleReadmeClick,
5382
5445
  params: ['handleReadmeClick', 'event.target.nodeName', TargetHref],
5383
5446
  preventDefault: true
5447
+ }, {
5448
+ name: HandleResourceLinkClick,
5449
+ params: ['handleResourceLinkClick', TargetHref],
5450
+ preventDefault: true
5384
5451
  }, {
5385
5452
  name: HandleClickUninstall,
5386
5453
  params: ['handleClickUninstall']
@@ -5457,6 +5524,7 @@ const commandMap = {
5457
5524
  'ExtensionDetail.handleImageContextMenu': wrapCommand(handleImageContextMenu),
5458
5525
  'ExtensionDetail.handleReadmeClick': wrapCommand(handleReadmeClick),
5459
5526
  'ExtensionDetail.handleReadmeContextMenu': wrapCommand(handleReadmeContextMenu),
5527
+ 'ExtensionDetail.handleResourceLinkClick': wrapCommand(handleResourceLinkClick),
5460
5528
  'ExtensionDetail.handleScroll': wrapCommand(handleScroll),
5461
5529
  'ExtensionDetail.handleSelectionChange': wrapCommand(handleSelectionChange),
5462
5530
  '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.4.0",
4
4
  "description": "Extension Detail View Worker",
5
5
  "repository": {
6
6
  "type": "git",