@lvce-editor/extension-search-view 2.11.0 → 3.0.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 = id => {
439
+ const remove$1 = id => {
440
440
  delete callbacks[id];
441
441
  };
442
442
  let id = 0;
@@ -613,7 +613,7 @@ const resolve = (id, response) => {
613
613
  return;
614
614
  }
615
615
  fn(response);
616
- remove(id);
616
+ remove$1(id);
617
617
  };
618
618
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
619
619
  const getErrorType = prettyError => {
@@ -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 {
@@ -1120,6 +1114,9 @@ const set$1 = (uid, oldState, newState) => {
1120
1114
  newState
1121
1115
  };
1122
1116
  };
1117
+ const remove = uid => {
1118
+ delete states[uid];
1119
+ };
1123
1120
 
1124
1121
  const create = (id, uri, x, y, width, height, platform, assetDir) => {
1125
1122
  const state = {
@@ -1157,34 +1154,35 @@ const RenderHeader = 1;
1157
1154
  const RenderItems = 4;
1158
1155
  const RenderScrollBar = 5;
1159
1156
  const RenderMessage = 6;
1157
+ const RenderSearchValue = 7;
1160
1158
 
1161
1159
  const diffType$4 = RenderItems;
1162
- const isEqual$5 = (oldState, newState) => {
1160
+ const isEqual$4 = (oldState, newState) => {
1163
1161
  return true;
1164
1162
  };
1165
1163
 
1166
1164
  const diffType$3 = RenderHeader;
1167
- const isEqual$4 = (oldState, newState) => {
1165
+ const isEqual$3 = (oldState, newState) => {
1168
1166
  return oldState.placeholder === newState.placeholder;
1169
1167
  };
1170
1168
 
1171
1169
  const diffType$2 = RenderItems;
1172
- const isEqual$3 = (oldState, newState) => {
1170
+ const isEqual$2 = (oldState, newState) => {
1173
1171
  return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.deltaY === newState.deltaY && oldState.focusedIndex === newState.focusedIndex;
1174
1172
  };
1175
1173
 
1176
1174
  const diffType$1 = RenderMessage;
1177
- const isEqual$2 = (oldState, newState) => {
1175
+ const isEqual$1 = (oldState, newState) => {
1178
1176
  return oldState.message === newState.message;
1179
1177
  };
1180
1178
 
1181
1179
  const diffType = RenderScrollBar;
1182
- const isEqual$1 = (oldState, newState) => {
1180
+ const isEqual = (oldState, newState) => {
1183
1181
  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;
1184
1182
  };
1185
1183
 
1186
- const modules = [isEqual$5, isEqual$1, isEqual$2, isEqual$4, isEqual$3];
1187
- const numbers = [diffType$4, diffType, diffType$1, diffType$3, diffType$2];
1184
+ const modules = [isEqual, isEqual$1, isEqual$3, isEqual$2, isEqual$4];
1185
+ const numbers = [diffType, diffType$1, diffType$3, diffType$2, diffType$4];
1188
1186
 
1189
1187
  const diff = (oldState, newState) => {
1190
1188
  const diffResult = [];
@@ -1197,6 +1195,25 @@ const diff = (oldState, newState) => {
1197
1195
  return diffResult;
1198
1196
  };
1199
1197
 
1198
+ const diff2 = uid => {
1199
+ const {
1200
+ oldState,
1201
+ newState
1202
+ } = get$1(uid);
1203
+ const diffResult = diff(oldState, newState);
1204
+ return diffResult;
1205
+ };
1206
+
1207
+ const dispose = uid => {
1208
+ remove(uid);
1209
+ };
1210
+
1211
+ // TODO optimize this function to return the minimum number
1212
+ // of visible items needed, e.g. when not scrolled 5 items with
1213
+ // 20px fill 100px but when scrolled 6 items are needed
1214
+ const getNumberOfVisibleItems = (listHeight, itemHeight) => {
1215
+ return Math.ceil(listHeight / itemHeight) + 1;
1216
+ };
1200
1217
  const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength) => {
1201
1218
  const newMaxLineY = Math.min(index + 1, itemsLength);
1202
1219
  const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
@@ -1211,7 +1228,6 @@ const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength)
1211
1228
  deltaY: newDeltaY
1212
1229
  };
1213
1230
  };
1214
-
1215
1231
  const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
1216
1232
  const newMinLineY = index;
1217
1233
  const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
@@ -1226,7 +1242,6 @@ const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) =
1226
1242
  deltaY: newDeltaY
1227
1243
  };
1228
1244
  };
1229
-
1230
1245
  const focusIndex = (state, index) => {
1231
1246
  const {
1232
1247
  itemHeight,
@@ -1261,7 +1276,6 @@ const focusIndex = (state, index) => {
1261
1276
  focused: true
1262
1277
  };
1263
1278
  };
1264
-
1265
1279
  const first = () => {
1266
1280
  return 0;
1267
1281
  };
@@ -1271,12 +1285,10 @@ const last = items => {
1271
1285
  const next = (items, index) => {
1272
1286
  return (index + 1) % items.length;
1273
1287
  };
1274
-
1275
1288
  const focusFirst = state => {
1276
1289
  const firstIndex = first();
1277
1290
  return focusIndex(state, firstIndex);
1278
1291
  };
1279
-
1280
1292
  const focusLast = state => {
1281
1293
  const {
1282
1294
  items
@@ -1284,7 +1296,6 @@ const focusLast = state => {
1284
1296
  const lastIndex = last(items);
1285
1297
  return focusIndex(state, lastIndex);
1286
1298
  };
1287
-
1288
1299
  const focusNext = state => {
1289
1300
  const {
1290
1301
  focusedIndex,
@@ -1294,6 +1305,14 @@ const focusNext = state => {
1294
1305
  return focusIndex(state, nextIndex);
1295
1306
  };
1296
1307
 
1308
+ // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
1309
+
1310
+ const isLastIndex = (array, index) => {
1311
+ return index === array.length - 1;
1312
+ };
1313
+ const lastIndex = array => {
1314
+ return array.length - 1;
1315
+ };
1297
1316
  const focusNextPage = state => {
1298
1317
  const {
1299
1318
  focusedIndex,
@@ -1307,7 +1326,6 @@ const focusNextPage = state => {
1307
1326
  const indexNextPage = Math.min(maxLineY + (maxLineY - minLineY) - 2, lastIndex(items));
1308
1327
  return focusIndex(state, indexNextPage);
1309
1328
  };
1310
-
1311
1329
  const focusPreviousPage = state => {
1312
1330
  const {
1313
1331
  focusedIndex,
@@ -1578,7 +1596,7 @@ const setDeltaY = (state, value) => {
1578
1596
  }
1579
1597
  // TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
1580
1598
  const minLineY = Math.floor(newDeltaY / itemHeight);
1581
- const maxLineY = minLineY + getNumberOfVisibleItems(listHeight, itemHeight);
1599
+ const maxLineY = minLineY + getNumberOfVisibleItems$1(listHeight, itemHeight);
1582
1600
  return {
1583
1601
  ...state,
1584
1602
  deltaY: newDeltaY,
@@ -1683,7 +1701,6 @@ const getViewletSize = width => {
1683
1701
  return Large;
1684
1702
  };
1685
1703
 
1686
- const User = 1;
1687
1704
  const Script = 2;
1688
1705
 
1689
1706
  const getRemoteUrl = (extension, platform, assetDir) => {
@@ -1826,10 +1843,6 @@ const openSuggest = state => {
1826
1843
  return state;
1827
1844
  };
1828
1845
 
1829
- const isEqual = (oldState, newState) => {
1830
- return newState.inputSource === User || oldState.searchValue === newState.searchValue;
1831
- };
1832
-
1833
1846
  const Actions = 'Actions';
1834
1847
  const ExtensionActions = 'ExtensionActions';
1835
1848
  const ExtensionActive = 'ExtensionActive';
@@ -1925,7 +1938,7 @@ const getExtensionHeaderVirtualDom = (placeholder, actions) => {
1925
1938
  }, ...getSearchFieldVirtualDom('extensions', placeholder, 'handleExtensionsInput', actions, [])];
1926
1939
  };
1927
1940
 
1928
- const renderHeader$1 = newState => {
1941
+ const renderHeader = newState => {
1929
1942
  const actions = [{
1930
1943
  type: Button$2,
1931
1944
  title: clearExtensionSearchResults(),
@@ -2219,7 +2232,7 @@ const SetMessage = 'setMessage';
2219
2232
  const SetScrollBar = 'setScrollBar';
2220
2233
  const SetSearchValue = 'setSearchValue';
2221
2234
 
2222
- const renderMessage$1 = newState => {
2235
+ const renderMessage = newState => {
2223
2236
  return [/* method */SetMessage, /* message */newState.message];
2224
2237
  };
2225
2238
 
@@ -2230,7 +2243,7 @@ const position = (x, y) => {
2230
2243
  return `${x}px ${y}px`;
2231
2244
  };
2232
2245
 
2233
- const renderScrollBar$1 = newState => {
2246
+ const renderScrollBar = newState => {
2234
2247
  const listHeight = getListHeight(newState.items.length, newState.itemHeight, newState.height);
2235
2248
  const total = newState.items.length;
2236
2249
  const contentHeight = total * newState.itemHeight;
@@ -2246,53 +2259,44 @@ const renderScrollBar$1 = newState => {
2246
2259
  return [/* method */SetScrollBar, translateString, heightString, className];
2247
2260
  };
2248
2261
 
2249
- const renderExtensions = {
2250
- isEqual: isEqual$3,
2251
- apply(oldState, newState) {
2252
- return renderItems(newState);
2253
- }
2254
- };
2255
- const renderScrollBar = {
2256
- isEqual: isEqual$1,
2257
- apply(oldState, newState) {
2258
- return renderScrollBar$1(newState);
2259
- }
2260
- };
2261
- const renderMessage = {
2262
- isEqual: isEqual$2,
2263
- apply(oldState, newState) {
2264
- return renderMessage$1(newState);
2265
- }
2266
- };
2267
- const renderSearchValue = {
2268
- isEqual: isEqual,
2269
- apply(oldState, newState) {
2270
- return [/* method */SetSearchValue, oldState.searchValue, newState.searchValue];
2271
- }
2262
+ const renderSearchValue = newState => {
2263
+ return [/* method */SetSearchValue, '', newState.searchValue];
2272
2264
  };
2273
- const renderHeader = {
2274
- isEqual: isEqual$4,
2275
- apply(oldState, newState) {
2276
- return renderHeader$1(newState);
2265
+
2266
+ const getRenderer = diffType => {
2267
+ switch (diffType) {
2268
+ case RenderItems:
2269
+ return renderItems;
2270
+ case RenderMessage:
2271
+ return renderMessage;
2272
+ case RenderScrollBar:
2273
+ return renderScrollBar;
2274
+ case RenderSearchValue:
2275
+ return renderSearchValue;
2276
+ case RenderHeader:
2277
+ return renderHeader;
2278
+ default:
2279
+ throw new Error('unknown renderer');
2277
2280
  }
2278
2281
  };
2279
- const render = [renderScrollBar, renderMessage, renderExtensions, renderHeader, renderSearchValue];
2280
- const doRender = (oldState, newState) => {
2282
+
2283
+ const applyRender = (oldState, newState, diffResult) => {
2281
2284
  const commands = [];
2282
- for (const item of render) {
2283
- if (!item.isEqual(oldState, newState)) {
2284
- commands.push(item.apply(oldState, newState));
2285
- }
2285
+ for (const item of diffResult) {
2286
+ const fn = getRenderer(item);
2287
+ commands.push(fn(newState));
2286
2288
  }
2287
2289
  return commands;
2288
2290
  };
2289
2291
 
2290
- const render2 = uid => {
2292
+ const render3 = (uid, diffResult) => {
2291
2293
  const {
2292
2294
  oldState,
2293
2295
  newState
2294
2296
  } = get$1(uid);
2295
- return doRender(oldState, newState);
2297
+ set$1(uid, newState, newState);
2298
+ const commands = applyRender(oldState, newState, diffResult);
2299
+ return commands;
2296
2300
  };
2297
2301
 
2298
2302
  const getIconVirtualDom = (icon, type = Div$1) => {
@@ -2406,9 +2410,9 @@ const commandMap = {
2406
2410
  'SearchExtensions.clearSearchResults': wrapCommand(clearSearchResults),
2407
2411
  'SearchExtensions.closeSuggest': wrapCommand(closeSuggest),
2408
2412
  'SearchExtensions.create': create,
2409
- 'SearchExtensions.diff': diff,
2413
+ 'SearchExtensions.diff2': diff2,
2414
+ 'SearchExtensions.dispose': dispose,
2410
2415
  'SearchExtensions.focusFirst': wrapCommand(focusFirst),
2411
- 'SearchExtensions.terminate': terminate,
2412
2416
  'SearchExtensions.focusIndex': wrapCommand(focusIndex),
2413
2417
  'SearchExtensions.focusLast': wrapCommand(focusLast),
2414
2418
  'SearchExtensions.focusNext': wrapCommand(focusNext),
@@ -2436,8 +2440,7 @@ const commandMap = {
2436
2440
  'SearchExtensions.handleWheel': wrapCommand(handleWheel),
2437
2441
  'SearchExtensions.loadContent': loadContent,
2438
2442
  'SearchExtensions.openSuggest': wrapCommand(openSuggest),
2439
- 'SearchExtensions.render': doRender,
2440
- 'SearchExtensions.render2': render2,
2443
+ 'SearchExtensions.render3': render3,
2441
2444
  'SearchExtensions.renderActions': renderActions,
2442
2445
  'SearchExtensions.renderEventListeners': renderEventListeners,
2443
2446
  'SearchExtensions.saveState': saveState,
@@ -2445,6 +2448,7 @@ const commandMap = {
2445
2448
  'SearchExtensions.searchExtensions': searchExtensions,
2446
2449
  'SearchExtensions.selectIndex': wrapCommand(selectIndex),
2447
2450
  'SearchExtensions.setDeltaY': wrapCommand(setDeltaY),
2451
+ 'SearchExtensions.terminate': terminate,
2448
2452
  'SearchExtensions.toggleSuggest': wrapCommand(toggleSuggest)
2449
2453
  };
2450
2454
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-search-view",
3
- "version": "2.11.0",
3
+ "version": "3.0.0",
4
4
  "description": "Extension Search View Worker",
5
5
  "license": "MIT",
6
6
  "author": "Lvce Editor",