@lvce-editor/extension-detail-view 3.16.0 → 3.18.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.
@@ -430,7 +430,7 @@ const set$2 = (id, fn) => {
430
430
  const get$2 = id => {
431
431
  return callbacks[id];
432
432
  };
433
- const remove = id => {
433
+ const remove$1 = id => {
434
434
  delete callbacks[id];
435
435
  };
436
436
  let id$1 = 0;
@@ -607,7 +607,7 @@ const resolve = (id, response) => {
607
607
  return;
608
608
  }
609
609
  fn(response);
610
- remove(id);
610
+ remove$1(id);
611
611
  };
612
612
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
613
613
  const getErrorType = prettyError => {
@@ -791,6 +791,9 @@ const createRpc = ipc => {
791
791
  },
792
792
  invokeAndTransfer(method, ...params) {
793
793
  return invokeAndTransfer(ipc, method, ...params);
794
+ },
795
+ async dispose() {
796
+ await ipc?.dispose();
794
797
  }
795
798
  };
796
799
  return rpc;
@@ -853,13 +856,17 @@ const create$1 = () => {
853
856
  oldState,
854
857
  newState
855
858
  };
859
+ },
860
+ remove(uid) {
861
+ delete states[uid];
856
862
  }
857
863
  };
858
864
  };
859
865
 
860
866
  const {
861
867
  get: get$1,
862
- set: set$1
868
+ set: set$1,
869
+ remove
863
870
  } = create$1();
864
871
 
865
872
  const create = (uid, uri, width, height, platform, assetDir$1) => {
@@ -882,17 +889,65 @@ const create = (uid, uri, width, height, platform, assetDir$1) => {
882
889
  baseUrl: '',
883
890
  features: [],
884
891
  folderSize: 0,
885
- assetDir: assetDir$1 || assetDir
892
+ assetDir: assetDir$1 || assetDir,
893
+ platform
886
894
  };
887
895
  set$1(uid, state, state);
888
896
  };
889
897
 
898
+ const RenderFocus = 2;
899
+ const RenderItems = 3;
900
+
901
+ const diffType$1 = RenderFocus;
902
+ const isEqual$1 = (oldState, newState) => {
903
+ return oldState === newState;
904
+ };
905
+
906
+ const diffType = RenderItems;
907
+ const isEqual = (oldState, newState) => {
908
+ return oldState === newState;
909
+ };
910
+
911
+ const modules = [isEqual, isEqual$1];
912
+ const numbers = [diffType, diffType$1];
913
+
914
+ const diff = (oldState, newState) => {
915
+ const diffResult = [];
916
+ for (let i = 0; i < modules.length; i++) {
917
+ const fn = modules[i];
918
+ if (!fn(oldState, newState)) {
919
+ diffResult.push(numbers[i]);
920
+ }
921
+ }
922
+ return diffResult;
923
+ };
924
+
925
+ const diff2 = uid => {
926
+ const {
927
+ oldState,
928
+ newState
929
+ } = get$1(uid);
930
+ const diffResult = diff(oldState, newState);
931
+ return diffResult;
932
+ };
933
+
934
+ const dispose = uid => {
935
+ remove(uid);
936
+ };
937
+
938
+ const commandIds = ['getMenuEntries', 'handleClickDisable', 'handleClickSize', 'handleClickUninstall', 'handleFeaturesClick', 'handleIconError', 'handleTabsClick', 'renderEventListeners', 'resize', 'saveState', 'selectTab', 'terminate'];
939
+
940
+ const getCommandIds = () => {
941
+ return commandIds;
942
+ };
943
+
890
944
  const AdditionalDetails = 'AdditionalDetails';
891
945
  const AdditionalDetailsEntry = 'AdditionalDetailsEntry';
892
946
  const AdditionalDetailsTitle = 'AdditionalDetailsTitle';
893
947
  const Aside = 'Aside';
894
948
  const Button$1 = 'Button';
895
949
  const ButtonPrimary = 'ButtonPrimary';
950
+ const DefaultMarkdown = 'DefaultMarkdown';
896
951
  const Categories = 'Categories';
897
952
  const Category = 'Category';
898
953
  const Changelog$1 = 'Changelog';
@@ -916,6 +971,8 @@ const Features$1 = 'Features';
916
971
  const FeaturesList = 'FeaturesList';
917
972
  const FeatureWebView = 'FeatureWebView';
918
973
  const Large$1 = 'Large';
974
+ const Sash = 'Sash';
975
+ const SashVertical = 'SashVertical';
919
976
  const MoreInfo = 'MoreInfo';
920
977
  const MoreInfoEntry = 'MoreInfoEntry';
921
978
  const MoreInfoEntryKey = 'MoreInfoEntryKey';
@@ -1002,6 +1059,92 @@ const getDisplaySize = size => {
1002
1059
  });
1003
1060
  };
1004
1061
 
1062
+ const emptyObject = {};
1063
+ const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1064
+ const i18nString = (key, placeholders = emptyObject) => {
1065
+ if (placeholders === emptyObject) {
1066
+ return key;
1067
+ }
1068
+ const replacer = (match, rest) => {
1069
+ return placeholders[rest];
1070
+ };
1071
+ return key.replaceAll(RE_PLACEHOLDER, replacer);
1072
+ };
1073
+
1074
+ const Commands$1 = 'Commands';
1075
+ const ContentSecurityPolicy = 'ContentSecurityPolicy';
1076
+ const Copy = 'Copy';
1077
+ const Elements = 'Elements';
1078
+ const FileMatch = 'File Match';
1079
+ const Id = 'ID';
1080
+ const JsonValidation$1 = 'Json Validation';
1081
+ const Label = 'Label';
1082
+ const OpenImageInNewTab = 'Open Image in New Tab';
1083
+ const OpenInNewTab = 'Open in New Tab';
1084
+ const ProgrammingLanguages$1 = 'Programming Languages';
1085
+ const SaveImageAs = 'Save Image as';
1086
+ const Schema = 'Schema';
1087
+ const Selector = 'Selector';
1088
+ const Settings$1 = 'Settings';
1089
+ const Theme$1 = 'Theme';
1090
+ const WebViews$1 = 'WebViews';
1091
+ const NotImplemented = 'Not Implemented';
1092
+
1093
+ const copy = () => {
1094
+ return i18nString(Copy);
1095
+ };
1096
+ const openInNewTab = () => {
1097
+ return i18nString(OpenInNewTab);
1098
+ };
1099
+ const label = () => {
1100
+ return i18nString(Label);
1101
+ };
1102
+ const openImageInNewTab = () => {
1103
+ return i18nString(OpenImageInNewTab);
1104
+ };
1105
+ const saveImageAs = () => {
1106
+ return i18nString(SaveImageAs);
1107
+ };
1108
+ const fileMatch = () => {
1109
+ return i18nString(FileMatch);
1110
+ };
1111
+ const schema = () => {
1112
+ return i18nString(Schema);
1113
+ };
1114
+ const theme = () => {
1115
+ return i18nString(Theme$1);
1116
+ };
1117
+ const commands = () => {
1118
+ return i18nString(Commands$1);
1119
+ };
1120
+ const webViews = () => {
1121
+ return i18nString(WebViews$1);
1122
+ };
1123
+ const jsonValidation = () => {
1124
+ return i18nString(JsonValidation$1);
1125
+ };
1126
+ const programmingLanguages = () => {
1127
+ return i18nString(ProgrammingLanguages$1);
1128
+ };
1129
+ const settings = () => {
1130
+ return i18nString(Settings$1);
1131
+ };
1132
+ const id = () => {
1133
+ return i18nString(Id);
1134
+ };
1135
+ const selector = () => {
1136
+ return i18nString(Selector);
1137
+ };
1138
+ const contentSecurityPolicy = () => {
1139
+ return i18nString(ContentSecurityPolicy);
1140
+ };
1141
+ const elements = () => {
1142
+ return i18nString(Elements);
1143
+ };
1144
+ const notImplemented = () => {
1145
+ return i18nString(NotImplemented);
1146
+ };
1147
+
1005
1148
  const A = 53;
1006
1149
  const Button = 1;
1007
1150
  const Div = 4;
@@ -1026,12 +1169,13 @@ const text = data => {
1026
1169
  };
1027
1170
 
1028
1171
  const getChangelogVirtualDom = () => {
1172
+ const notImplemented$1 = notImplemented();
1029
1173
  // TODO set tabpanel role
1030
1174
  return [{
1031
1175
  type: Div,
1032
1176
  className: Changelog$1,
1033
1177
  childCount: 1
1034
- }, text('Not Implemented')];
1178
+ }, text(notImplemented$1)];
1035
1179
  };
1036
1180
 
1037
1181
  const TabList = 'tablist';
@@ -1276,88 +1420,6 @@ const getDetailsVirtualDom = async (sanitizedReadmeHtml, displaySize, extensionI
1276
1420
  return dom;
1277
1421
  };
1278
1422
 
1279
- const emptyObject = {};
1280
- const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1281
- const i18nString = (key, placeholders = emptyObject) => {
1282
- if (placeholders === emptyObject) {
1283
- return key;
1284
- }
1285
- const replacer = (match, rest) => {
1286
- return placeholders[rest];
1287
- };
1288
- return key.replaceAll(RE_PLACEHOLDER, replacer);
1289
- };
1290
-
1291
- const Commands$1 = 'Commands';
1292
- const ContentSecurityPolicy = 'ContentSecurityPolicy';
1293
- const Copy = 'Copy';
1294
- const Elements = 'Elements';
1295
- const FileMatch = 'File Match';
1296
- const Id = 'ID';
1297
- const JsonValidation$1 = 'Json Validation';
1298
- const Label = 'Label';
1299
- const OpenImageInNewTab = 'Open Image in New Tab';
1300
- const OpenInNewTab = 'Open in New Tab';
1301
- const ProgrammingLanguages$1 = 'Programming Languages';
1302
- const SaveImageAs = 'Save Image as';
1303
- const Schema = 'Schema';
1304
- const Selector = 'Selector';
1305
- const Settings$1 = 'Settings';
1306
- const Theme$1 = 'Theme';
1307
- const WebViews$1 = 'WebViews';
1308
-
1309
- const copy = () => {
1310
- return i18nString(Copy);
1311
- };
1312
- const openInNewTab = () => {
1313
- return i18nString(OpenInNewTab);
1314
- };
1315
- const label = () => {
1316
- return i18nString(Label);
1317
- };
1318
- const openImageInNewTab = () => {
1319
- return i18nString(OpenImageInNewTab);
1320
- };
1321
- const saveImageAs = () => {
1322
- return i18nString(SaveImageAs);
1323
- };
1324
- const fileMatch = () => {
1325
- return i18nString(FileMatch);
1326
- };
1327
- const schema = () => {
1328
- return i18nString(Schema);
1329
- };
1330
- const theme = () => {
1331
- return i18nString(Theme$1);
1332
- };
1333
- const commands = () => {
1334
- return i18nString(Commands$1);
1335
- };
1336
- const webViews = () => {
1337
- return i18nString(WebViews$1);
1338
- };
1339
- const jsonValidation = () => {
1340
- return i18nString(JsonValidation$1);
1341
- };
1342
- const programmingLanguages = () => {
1343
- return i18nString(ProgrammingLanguages$1);
1344
- };
1345
- const settings = () => {
1346
- return i18nString(Settings$1);
1347
- };
1348
- const id = () => {
1349
- return i18nString(Id);
1350
- };
1351
- const selector = () => {
1352
- return i18nString(Selector);
1353
- };
1354
- const contentSecurityPolicy = () => {
1355
- return i18nString(ContentSecurityPolicy);
1356
- };
1357
- const elements = () => {
1358
- return i18nString(Elements);
1359
- };
1360
-
1361
1423
  const Text = 1;
1362
1424
  const Code = 2;
1363
1425
 
@@ -1593,7 +1655,7 @@ const getFeatureThemesVirtualDom = async themesHtml => {
1593
1655
  childCount: 2
1594
1656
  }, ...getFeatureContentHeadingVirtualDom(heading), {
1595
1657
  type: Div,
1596
- className: 'DefaultMarkdown',
1658
+ className: DefaultMarkdown,
1597
1659
  childCount
1598
1660
  }, ...markdownDom];
1599
1661
  };
@@ -1719,6 +1781,14 @@ const getFeatureListVirtualDom = features => {
1719
1781
  }, ...features.flatMap(getFeatureListItemVirtualDom)];
1720
1782
  };
1721
1783
 
1784
+ const joinBySpace = (...items) => {
1785
+ return items.join(' ');
1786
+ };
1787
+
1788
+ const mergeClassNames = (...classNames) => {
1789
+ return joinBySpace(...classNames.filter(Boolean));
1790
+ };
1791
+
1722
1792
  const getFeaturesVirtualDom = async (features, themesHtml, selectedFeature, extension) => {
1723
1793
  if (features.length === 0) {
1724
1794
  return [{
@@ -1733,7 +1803,7 @@ const getFeaturesVirtualDom = async (features, themesHtml, selectedFeature, exte
1733
1803
  childCount: 3
1734
1804
  }, ...getFeatureListVirtualDom(features), {
1735
1805
  type: Div,
1736
- className: 'Sash SashVertical',
1806
+ className: mergeClassNames(Sash, SashVertical),
1737
1807
  childCount: 0
1738
1808
  }, ...(await getFeatureContentVirtualDom(features, themesHtml, selectedFeature, extension))];
1739
1809
  };
@@ -1861,14 +1931,6 @@ const getTabs = selectedTab => {
1861
1931
  return tabs;
1862
1932
  };
1863
1933
 
1864
- const joinBySpace = (...items) => {
1865
- return items.join(' ');
1866
- };
1867
-
1868
- const mergeClassNames = (...classNames) => {
1869
- return joinBySpace(...classNames.filter(Boolean));
1870
- };
1871
-
1872
1934
  const selectedClassName = mergeClassNames(ExtensionDetailTab, ExtensionDetailTabSelected);
1873
1935
  const defaultClassName = ExtensionDetailTab;
1874
1936
  const getTabVirtualDom = tab => {
@@ -2277,20 +2339,6 @@ const getFolderSize = async uri => {
2277
2339
  }
2278
2340
  };
2279
2341
 
2280
- const getSavedSelectedFeature = savedState => {
2281
- if (savedState && typeof savedState === 'object' && 'selectedFeature' in savedState && typeof savedState.selectedFeature === 'string') {
2282
- return savedState.selectedFeature;
2283
- }
2284
- return Details;
2285
- };
2286
-
2287
- const getSavedSelectedTab = savedState => {
2288
- if (savedState && typeof savedState === 'object' && 'selectedTab' in savedState && typeof savedState.selectedTab === 'string') {
2289
- return savedState.selectedTab;
2290
- }
2291
- return Details;
2292
- };
2293
-
2294
2342
  const readFile = async uri => {
2295
2343
  return invoke('FileSystem.readFile', uri);
2296
2344
  };
@@ -2314,11 +2362,34 @@ const loadReadmeContent = async path => {
2314
2362
  if (isEnoentError(error)) {
2315
2363
  return '';
2316
2364
  }
2317
- console.error(error);
2365
+ console.error(new VError(error, 'Failed to load Readme content'));
2318
2366
  return `${error}`;
2319
2367
  }
2320
2368
  };
2321
2369
 
2370
+ const getSavedSelectedFeature = savedState => {
2371
+ if (savedState && typeof savedState === 'object' && 'selectedFeature' in savedState && typeof savedState.selectedFeature === 'string') {
2372
+ return savedState.selectedFeature;
2373
+ }
2374
+ return Details;
2375
+ };
2376
+
2377
+ const getSavedSelectedTab = savedState => {
2378
+ if (savedState && typeof savedState === 'object' && 'selectedTab' in savedState && typeof savedState.selectedTab === 'string') {
2379
+ return savedState.selectedTab;
2380
+ }
2381
+ return Details;
2382
+ };
2383
+
2384
+ const restoreState = savedState => {
2385
+ const selectedTab = getSavedSelectedTab(savedState);
2386
+ const selectedFeature = getSavedSelectedFeature(savedState);
2387
+ return {
2388
+ selectedFeature,
2389
+ selectedTab
2390
+ };
2391
+ };
2392
+
2322
2393
  const loadContent = async (state, platform, savedState) => {
2323
2394
  const {
2324
2395
  uri,
@@ -2338,8 +2409,10 @@ const loadContent = async (state, platform, savedState) => {
2338
2409
  const description = getDescription(extension);
2339
2410
  const name = getName(extension);
2340
2411
  const size = getViewletSize(width);
2341
- const selectedTab = getSavedSelectedTab(savedState);
2342
- const selectedFeature = getSavedSelectedFeature(savedState);
2412
+ const {
2413
+ selectedFeature,
2414
+ selectedTab
2415
+ } = restoreState(savedState);
2343
2416
  const features = getFeatures(selectedFeature, extension);
2344
2417
  const folderSize = await getFolderSize(extension.uri);
2345
2418
  const entries = [{
@@ -2395,6 +2468,49 @@ const loadContent = async (state, platform, savedState) => {
2395
2468
  };
2396
2469
  };
2397
2470
 
2471
+ const loadContent2 = async (state, savedState) => {
2472
+ return loadContent(state, state.platform, savedState);
2473
+ };
2474
+
2475
+ const renderDom = async (oldState, newState) => {
2476
+ const dom = await getExtensionDetailVirtualDom(newState, newState.sanitizedReadmeHtml, newState.selectedTab, newState);
2477
+ return ['Viewlet.setDom2', dom];
2478
+ };
2479
+
2480
+ const renderFocus = async (oldState, newState) => {
2481
+ return ['Viewlet.focusElementByName', ''];
2482
+ };
2483
+
2484
+ const getRenderer = diffType => {
2485
+ switch (diffType) {
2486
+ case RenderItems:
2487
+ return renderDom;
2488
+ case RenderFocus:
2489
+ return renderFocus;
2490
+ default:
2491
+ throw new Error('unknown renderer');
2492
+ }
2493
+ };
2494
+
2495
+ const applyRender = async (oldState, newState, diffResult) => {
2496
+ const commands = [];
2497
+ for (const item of diffResult) {
2498
+ const fn = getRenderer(item);
2499
+ commands.push(await fn(oldState, newState));
2500
+ }
2501
+ return commands;
2502
+ };
2503
+
2504
+ const render2 = async (uid, diffResult) => {
2505
+ const {
2506
+ oldState,
2507
+ newState
2508
+ } = get$1(uid);
2509
+ set$1(uid, oldState, newState);
2510
+ const commands = await applyRender(oldState, newState, diffResult);
2511
+ return commands;
2512
+ };
2513
+
2398
2514
  const renderEventListeners = () => {
2399
2515
  return [{
2400
2516
  name: HandleIconError,
@@ -2447,37 +2563,41 @@ const terminate = () => {
2447
2563
 
2448
2564
  const wrapCommand = fn => {
2449
2565
  const wrapped = async (uid, ...args) => {
2450
- if (typeof uid === 'number') {
2451
- const {
2452
- newState
2453
- } = get$1(uid);
2454
- const newerState = await fn(newState, ...args);
2455
- set$1(uid, newState, newerState);
2456
- } else {
2457
- // deprecated
2458
- const newerState = await fn(uid, ...args);
2459
- return newerState;
2566
+ const {
2567
+ newState
2568
+ } = get$1(uid);
2569
+ const newerState = await fn(newState, ...args);
2570
+ if (newState === newerState) {
2571
+ return;
2460
2572
  }
2573
+ const latest = get$1(uid);
2574
+ set$1(uid, latest.oldState, newerState);
2461
2575
  };
2462
2576
  return wrapped;
2463
2577
  };
2464
2578
 
2465
2579
  const commandMap = {
2466
2580
  'ExtensionDetail.create': create,
2581
+ 'ExtensionDetail.diff2': diff2,
2582
+ 'ExtensionDetail.dispose': dispose,
2583
+ 'ExtensionDetail.getCommandIds': getCommandIds,
2467
2584
  'ExtensionDetail.getMenuEntries': getMenuEntries,
2468
- 'ExtensionDetail.getVirtualDom2': getExtensionDetailVirtualDom2,
2469
2585
  'ExtensionDetail.handleClickDisable': wrapCommand(handleClickDisable),
2470
2586
  'ExtensionDetail.handleClickSize': wrapCommand(handleClickSize),
2471
2587
  'ExtensionDetail.handleClickUninstall': wrapCommand(handleClickUninstall),
2472
2588
  'ExtensionDetail.handleFeaturesClick': wrapCommand(handleClickFeatures),
2473
2589
  'ExtensionDetail.handleIconError': wrapCommand(handleIconError),
2474
2590
  'ExtensionDetail.handleTabsClick': wrapCommand(handleTabsClick),
2475
- 'ExtensionDetail.loadContent': wrapCommand(loadContent),
2591
+ 'ExtensionDetail.loadContent2': wrapCommand(loadContent2),
2592
+ 'ExtensionDetail.render2': render2,
2476
2593
  'ExtensionDetail.renderEventListeners': renderEventListeners,
2477
2594
  'ExtensionDetail.resize': resize,
2478
2595
  'ExtensionDetail.saveState': saveState,
2479
2596
  'ExtensionDetail.selectTab': wrapCommand(selectTab),
2480
- 'ExtensionDetail.terminate': terminate
2597
+ 'ExtensionDetail.terminate': terminate,
2598
+ // deprecated
2599
+ 'ExtensionDetail.getVirtualDom2': getExtensionDetailVirtualDom2,
2600
+ 'ExtensionDetail.loadContent': wrapCommand(loadContent)
2481
2601
  };
2482
2602
 
2483
2603
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-detail-view",
3
- "version": "3.16.0",
3
+ "version": "3.18.0",
4
4
  "description": "Extension Detail View Worker",
5
5
  "license": "MIT",
6
6
  "author": "Lvce Editor",