@lvce-editor/extension-search-view 2.12.0 → 3.1.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.
@@ -436,7 +436,7 @@ const set$2 = (id, fn) => {
436
436
  const get$2 = id => {
437
437
  return callbacks[id];
438
438
  };
439
- const remove$1 = id => {
439
+ const remove = id => {
440
440
  delete callbacks[id];
441
441
  };
442
442
  let id = 0;
@@ -455,7 +455,7 @@ const registerPromise = () => {
455
455
  promise
456
456
  };
457
457
  };
458
- const create$2 = (method, params) => {
458
+ const create$2$1 = (method, params) => {
459
459
  const {
460
460
  id,
461
461
  promise
@@ -613,7 +613,7 @@ const resolve = (id, response) => {
613
613
  return;
614
614
  }
615
615
  fn(response);
616
- remove$1(id);
616
+ remove(id);
617
617
  };
618
618
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
619
619
  const getErrorType = prettyError => {
@@ -747,7 +747,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
747
747
  const {
748
748
  message,
749
749
  promise
750
- } = create$2(method, params);
750
+ } = create$2$1(method, params);
751
751
  if (useSendAndTransfer && ipc.sendAndTransfer) {
752
752
  ipc.sendAndTransfer(message);
753
753
  } else {
@@ -831,7 +831,7 @@ const listen$1 = async (module, options) => {
831
831
  const ipc = module.wrap(rawIpc);
832
832
  return ipc;
833
833
  };
834
- const create$1 = async ({
834
+ const create$2 = async ({
835
835
  commandMap
836
836
  }) => {
837
837
  // TODO create a commandMap per rpc instance
@@ -843,7 +843,7 @@ const create$1 = async ({
843
843
  };
844
844
  const WebWorkerRpcClient = {
845
845
  __proto__: null,
846
- create: create$1
846
+ create: create$2
847
847
  };
848
848
 
849
849
  const handleError = (error, notify = true, prefix = '') => {
@@ -912,7 +912,7 @@ const getListHeight = (itemsLength, itemHeight, maxHeight) => {
912
912
  // TODO optimize this function to return the minimum number
913
913
  // of visible items needed, e.g. when not scrolled 5 items with
914
914
  // 20px fill 100px but when scrolled 6 items are needed
915
- const getNumberOfVisibleItems = (listHeight, itemHeight) => {
915
+ const getNumberOfVisibleItems$1 = (listHeight, itemHeight) => {
916
916
  return Math.ceil(listHeight / itemHeight) + 1;
917
917
  };
918
918
 
@@ -1004,12 +1004,6 @@ const matchesParsedValue = (extension, parsedValue) => {
1004
1004
  const toSorted = (array, compare) => {
1005
1005
  return [...array].sort(compare);
1006
1006
  };
1007
- const isLastIndex = (array, index) => {
1008
- return index === array.length - 1;
1009
- };
1010
- const lastIndex = array => {
1011
- return array.length - 1;
1012
- };
1013
1007
 
1014
1008
  const compareExtension = (extensionA, extensionB) => {
1015
1009
  return extensionA.name.localeCompare(extensionB.name) || extensionA.id.localeCompare(extensionB.id);
@@ -1073,7 +1067,7 @@ const handleInput = async (state, value) => {
1073
1067
  const total = items.length;
1074
1068
  const contentHeight = total * itemHeight;
1075
1069
  const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
1076
- const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
1070
+ const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
1077
1071
  const maxLineY = Math.min(numberOfVisible, total);
1078
1072
  const finalDeltaY = getFinalDeltaY(listHeight, itemHeight, total);
1079
1073
  return {
@@ -1110,19 +1104,33 @@ const closeSuggest = state => {
1110
1104
  return state;
1111
1105
  };
1112
1106
 
1113
- const states = Object.create(null);
1114
- const get$1 = uid => {
1115
- return states[uid];
1116
- };
1117
- const set$1 = (uid, oldState, newState) => {
1118
- states[uid] = {
1119
- oldState,
1120
- newState
1107
+ const create$1 = () => {
1108
+ const states = Object.create(null);
1109
+ return {
1110
+ get(uid) {
1111
+ return states[uid];
1112
+ },
1113
+ set(uid, oldState, newState) {
1114
+ states[uid] = {
1115
+ oldState,
1116
+ newState
1117
+ };
1118
+ },
1119
+ dispose(uid) {
1120
+ delete states[uid];
1121
+ },
1122
+ getKeys() {
1123
+ return Object.keys(states).map(key => {
1124
+ return Number.parseInt(key);
1125
+ });
1126
+ }
1121
1127
  };
1122
1128
  };
1123
- const remove = uid => {
1124
- delete states[uid];
1125
- };
1129
+
1130
+ const {
1131
+ get: get$1,
1132
+ set: set$1,
1133
+ dispose: dispose$1} = create$1();
1126
1134
 
1127
1135
  const create = (id, uri, x, y, width, height, platform, assetDir) => {
1128
1136
  const state = {
@@ -1162,58 +1170,67 @@ const RenderScrollBar = 5;
1162
1170
  const RenderMessage = 6;
1163
1171
  const RenderSearchValue = 7;
1164
1172
 
1165
- const diffType$4 = RenderItems;
1173
+ const diffType$5 = RenderItems;
1166
1174
  const isEqual$5 = (oldState, newState) => {
1167
1175
  return true;
1168
1176
  };
1169
1177
 
1170
- const diffType$3 = RenderHeader;
1178
+ const diffType$4 = RenderHeader;
1171
1179
  const isEqual$4 = (oldState, newState) => {
1172
1180
  return oldState.placeholder === newState.placeholder;
1173
1181
  };
1174
1182
 
1175
- const diffType$2 = RenderItems;
1183
+ const diffType$3 = RenderItems;
1176
1184
  const isEqual$3 = (oldState, newState) => {
1177
1185
  return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.deltaY === newState.deltaY && oldState.focusedIndex === newState.focusedIndex;
1178
1186
  };
1179
1187
 
1180
- const diffType$1 = RenderMessage;
1188
+ const diffType$2 = RenderMessage;
1181
1189
  const isEqual$2 = (oldState, newState) => {
1182
1190
  return oldState.message === newState.message;
1183
1191
  };
1184
1192
 
1185
- const diffType = RenderScrollBar;
1193
+ const diffType$1 = RenderScrollBar;
1186
1194
  const isEqual$1 = (oldState, newState) => {
1187
1195
  return oldState.negativeMargin === newState.negativeMargin && oldState.deltaY === newState.deltaY && oldState.height === newState.height && oldState.finalDeltaY === newState.finalDeltaY && oldState.items.length === newState.items.length && oldState.scrollBarActive === newState.scrollBarActive;
1188
1196
  };
1189
1197
 
1190
- const modules = [isEqual$1, isEqual$2, isEqual$4, isEqual$3, isEqual$5];
1191
- const numbers = [diffType, diffType$1, diffType$3, diffType$2, diffType$4];
1198
+ const User = 1;
1199
+ const Script = 2;
1192
1200
 
1193
- const diff = (oldState, newState) => {
1194
- const diffResult = [];
1195
- for (let i = 0; i < modules.length; i++) {
1196
- const fn = modules[i];
1197
- if (!fn(oldState, newState)) {
1198
- diffResult.push(numbers[i]);
1199
- }
1200
- }
1201
- return diffResult;
1201
+ const diffType = RenderSearchValue;
1202
+ const isEqual = (oldState, newState) => {
1203
+ return newState.inputSource === User || oldState.searchValue === newState.searchValue;
1202
1204
  };
1203
1205
 
1206
+ const modules = [isEqual$1, isEqual$2, isEqual$4, isEqual$3, isEqual$5, isEqual];
1207
+ const numbers = [diffType$1, diffType$2, diffType$4, diffType$3, diffType$5, diffType];
1208
+
1204
1209
  const diff2 = uid => {
1205
1210
  const {
1206
1211
  oldState,
1207
1212
  newState
1208
1213
  } = get$1(uid);
1209
- const diffResult = diff(oldState, newState);
1214
+ const diffResult = [];
1215
+ for (let i = 0; i < modules.length; i++) {
1216
+ const fn = modules[i];
1217
+ if (!fn(oldState, newState)) {
1218
+ diffResult.push(numbers[i]);
1219
+ }
1220
+ }
1210
1221
  return diffResult;
1211
1222
  };
1212
1223
 
1213
1224
  const dispose = uid => {
1214
- remove(uid);
1225
+ dispose$1(uid);
1215
1226
  };
1216
1227
 
1228
+ // TODO optimize this function to return the minimum number
1229
+ // of visible items needed, e.g. when not scrolled 5 items with
1230
+ // 20px fill 100px but when scrolled 6 items are needed
1231
+ const getNumberOfVisibleItems = (listHeight, itemHeight) => {
1232
+ return Math.ceil(listHeight / itemHeight) + 1;
1233
+ };
1217
1234
  const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength) => {
1218
1235
  const newMaxLineY = Math.min(index + 1, itemsLength);
1219
1236
  const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
@@ -1228,7 +1245,6 @@ const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength)
1228
1245
  deltaY: newDeltaY
1229
1246
  };
1230
1247
  };
1231
-
1232
1248
  const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
1233
1249
  const newMinLineY = index;
1234
1250
  const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
@@ -1243,7 +1259,6 @@ const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) =
1243
1259
  deltaY: newDeltaY
1244
1260
  };
1245
1261
  };
1246
-
1247
1262
  const focusIndex = (state, index) => {
1248
1263
  const {
1249
1264
  itemHeight,
@@ -1278,7 +1293,6 @@ const focusIndex = (state, index) => {
1278
1293
  focused: true
1279
1294
  };
1280
1295
  };
1281
-
1282
1296
  const first = () => {
1283
1297
  return 0;
1284
1298
  };
@@ -1288,12 +1302,10 @@ const last = items => {
1288
1302
  const next = (items, index) => {
1289
1303
  return (index + 1) % items.length;
1290
1304
  };
1291
-
1292
1305
  const focusFirst = state => {
1293
1306
  const firstIndex = first();
1294
1307
  return focusIndex(state, firstIndex);
1295
1308
  };
1296
-
1297
1309
  const focusLast = state => {
1298
1310
  const {
1299
1311
  items
@@ -1301,7 +1313,6 @@ const focusLast = state => {
1301
1313
  const lastIndex = last(items);
1302
1314
  return focusIndex(state, lastIndex);
1303
1315
  };
1304
-
1305
1316
  const focusNext = state => {
1306
1317
  const {
1307
1318
  focusedIndex,
@@ -1311,6 +1322,14 @@ const focusNext = state => {
1311
1322
  return focusIndex(state, nextIndex);
1312
1323
  };
1313
1324
 
1325
+ // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
1326
+
1327
+ const isLastIndex = (array, index) => {
1328
+ return index === array.length - 1;
1329
+ };
1330
+ const lastIndex = array => {
1331
+ return array.length - 1;
1332
+ };
1314
1333
  const focusNextPage = state => {
1315
1334
  const {
1316
1335
  focusedIndex,
@@ -1324,7 +1343,6 @@ const focusNextPage = state => {
1324
1343
  const indexNextPage = Math.min(maxLineY + (maxLineY - minLineY) - 2, lastIndex(items));
1325
1344
  return focusIndex(state, indexNextPage);
1326
1345
  };
1327
-
1328
1346
  const focusPreviousPage = state => {
1329
1347
  const {
1330
1348
  focusedIndex,
@@ -1595,7 +1613,7 @@ const setDeltaY = (state, value) => {
1595
1613
  }
1596
1614
  // TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
1597
1615
  const minLineY = Math.floor(newDeltaY / itemHeight);
1598
- const maxLineY = minLineY + getNumberOfVisibleItems(listHeight, itemHeight);
1616
+ const maxLineY = minLineY + getNumberOfVisibleItems$1(listHeight, itemHeight);
1599
1617
  return {
1600
1618
  ...state,
1601
1619
  deltaY: newDeltaY,
@@ -1700,9 +1718,6 @@ const getViewletSize = width => {
1700
1718
  return Large;
1701
1719
  };
1702
1720
 
1703
- const User = 1;
1704
- const Script = 2;
1705
-
1706
1721
  const getRemoteUrl = (extension, platform, assetDir) => {
1707
1722
  if (platform === Remote || platform === Electron) {
1708
1723
  if (extension.builtin) {
@@ -1843,10 +1858,6 @@ const openSuggest = state => {
1843
1858
  return state;
1844
1859
  };
1845
1860
 
1846
- const isEqual = (oldState, newState) => {
1847
- return newState.inputSource === User || oldState.searchValue === newState.searchValue;
1848
- };
1849
-
1850
1861
  const Actions = 'Actions';
1851
1862
  const ExtensionActions = 'ExtensionActions';
1852
1863
  const ExtensionActive = 'ExtensionActive';
@@ -1942,7 +1953,7 @@ const getExtensionHeaderVirtualDom = (placeholder, actions) => {
1942
1953
  }, ...getSearchFieldVirtualDom('extensions', placeholder, 'handleExtensionsInput', actions, [])];
1943
1954
  };
1944
1955
 
1945
- const renderHeader$1 = newState => {
1956
+ const renderHeader = newState => {
1946
1957
  const actions = [{
1947
1958
  type: Button$2,
1948
1959
  title: clearExtensionSearchResults(),
@@ -2236,7 +2247,7 @@ const SetMessage = 'setMessage';
2236
2247
  const SetScrollBar = 'setScrollBar';
2237
2248
  const SetSearchValue = 'setSearchValue';
2238
2249
 
2239
- const renderMessage$1 = newState => {
2250
+ const renderMessage = newState => {
2240
2251
  return [/* method */SetMessage, /* message */newState.message];
2241
2252
  };
2242
2253
 
@@ -2247,7 +2258,7 @@ const position = (x, y) => {
2247
2258
  return `${x}px ${y}px`;
2248
2259
  };
2249
2260
 
2250
- const renderScrollBar$1 = newState => {
2261
+ const renderScrollBar = newState => {
2251
2262
  const listHeight = getListHeight(newState.items.length, newState.itemHeight, newState.height);
2252
2263
  const total = newState.items.length;
2253
2264
  const contentHeight = total * newState.itemHeight;
@@ -2263,55 +2274,6 @@ const renderScrollBar$1 = newState => {
2263
2274
  return [/* method */SetScrollBar, translateString, heightString, className];
2264
2275
  };
2265
2276
 
2266
- const renderExtensions = {
2267
- isEqual: isEqual$3,
2268
- apply(oldState, newState) {
2269
- return renderItems(newState);
2270
- }
2271
- };
2272
- const renderScrollBar = {
2273
- isEqual: isEqual$1,
2274
- apply(oldState, newState) {
2275
- return renderScrollBar$1(newState);
2276
- }
2277
- };
2278
- const renderMessage = {
2279
- isEqual: isEqual$2,
2280
- apply(oldState, newState) {
2281
- return renderMessage$1(newState);
2282
- }
2283
- };
2284
- const renderSearchValue$1 = {
2285
- isEqual: isEqual,
2286
- apply(oldState, newState) {
2287
- return [/* method */SetSearchValue, oldState.searchValue, newState.searchValue];
2288
- }
2289
- };
2290
- const renderHeader = {
2291
- isEqual: isEqual$4,
2292
- apply(oldState, newState) {
2293
- return renderHeader$1(newState);
2294
- }
2295
- };
2296
- const render = [renderScrollBar, renderMessage, renderExtensions, renderHeader, renderSearchValue$1];
2297
- const doRender = (oldState, newState) => {
2298
- const commands = [];
2299
- for (const item of render) {
2300
- if (!item.isEqual(oldState, newState)) {
2301
- commands.push(item.apply(oldState, newState));
2302
- }
2303
- }
2304
- return commands;
2305
- };
2306
-
2307
- const render2 = uid => {
2308
- const {
2309
- oldState,
2310
- newState
2311
- } = get$1(uid);
2312
- return doRender(oldState, newState);
2313
- };
2314
-
2315
2277
  const renderSearchValue = newState => {
2316
2278
  return [/* method */SetSearchValue, '', newState.searchValue];
2317
2279
  };
@@ -2321,13 +2283,13 @@ const getRenderer = diffType => {
2321
2283
  case RenderItems:
2322
2284
  return renderItems;
2323
2285
  case RenderMessage:
2324
- return renderMessage$1;
2286
+ return renderMessage;
2325
2287
  case RenderScrollBar:
2326
- return renderScrollBar$1;
2288
+ return renderScrollBar;
2327
2289
  case RenderSearchValue:
2328
2290
  return renderSearchValue;
2329
2291
  case RenderHeader:
2330
- return renderHeader$1;
2292
+ return renderHeader;
2331
2293
  default:
2332
2294
  throw new Error('unknown renderer');
2333
2295
  }
@@ -2502,11 +2464,7 @@ const commandMap = {
2502
2464
  'SearchExtensions.selectIndex': wrapCommand(selectIndex),
2503
2465
  'SearchExtensions.setDeltaY': wrapCommand(setDeltaY),
2504
2466
  'SearchExtensions.terminate': terminate,
2505
- 'SearchExtensions.toggleSuggest': wrapCommand(toggleSuggest),
2506
- // deprecated
2507
- 'SearchExtensions.diff': diff,
2508
- 'SearchExtensions.render': doRender,
2509
- 'SearchExtensions.render2': render2
2467
+ 'SearchExtensions.toggleSuggest': wrapCommand(toggleSuggest)
2510
2468
  };
2511
2469
 
2512
2470
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-search-view",
3
- "version": "2.12.0",
3
+ "version": "3.1.0",
4
4
  "description": "Extension Search View Worker",
5
5
  "license": "MIT",
6
6
  "author": "Lvce Editor",