@lvce-editor/extension-search-view 6.3.0 → 7.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.
@@ -456,7 +456,7 @@ const getFirstEvent = (eventEmitter, eventMap) => {
456
456
  return promise;
457
457
  };
458
458
  const Message$1 = 3;
459
- const create$5$1 = async ({
459
+ const create$5 = async ({
460
460
  isMessagePortOpen,
461
461
  messagePort
462
462
  }) => {
@@ -507,61 +507,19 @@ const wrap$5 = messagePort => {
507
507
  };
508
508
  const IpcParentWithMessagePort$1 = {
509
509
  __proto__: null,
510
- create: create$5$1,
510
+ create: create$5,
511
511
  signal: signal$1,
512
512
  wrap: wrap$5
513
513
  };
514
514
 
515
- const Two = '2.0';
516
- const create$4$1 = (method, params) => {
517
- return {
518
- jsonrpc: Two,
519
- method,
520
- params
521
- };
522
- };
515
+ const Two$1 = '2.0';
523
516
  const callbacks = Object.create(null);
524
- const set$6 = (id, fn) => {
525
- callbacks[id] = fn;
526
- };
527
517
  const get$2 = id => {
528
518
  return callbacks[id];
529
519
  };
530
- const remove = id => {
520
+ const remove$1 = id => {
531
521
  delete callbacks[id];
532
522
  };
533
- let id$1 = 0;
534
- const create$3$1 = () => {
535
- return ++id$1;
536
- };
537
- const registerPromise = () => {
538
- const id = create$3$1();
539
- const {
540
- resolve,
541
- promise
542
- } = Promise.withResolvers();
543
- set$6(id, resolve);
544
- return {
545
- id,
546
- promise
547
- };
548
- };
549
- const create$2$1 = (method, params) => {
550
- const {
551
- id,
552
- promise
553
- } = registerPromise();
554
- const message = {
555
- jsonrpc: Two,
556
- method,
557
- params,
558
- id
559
- };
560
- return {
561
- message,
562
- promise
563
- };
564
- };
565
523
  class JsonRpcError extends Error {
566
524
  constructor(message) {
567
525
  super(message);
@@ -712,7 +670,7 @@ const resolve = (id, response) => {
712
670
  return;
713
671
  }
714
672
  fn(response);
715
- remove(id);
673
+ remove$1(id);
716
674
  };
717
675
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
718
676
  const getErrorType = prettyError => {
@@ -755,9 +713,9 @@ const getErrorProperty = (error, prettyError) => {
755
713
  }
756
714
  };
757
715
  };
758
- const create$1$1 = (id, error) => {
716
+ const create$1$2 = (id, error) => {
759
717
  return {
760
- jsonrpc: Two,
718
+ jsonrpc: Two$1,
761
719
  id,
762
720
  error
763
721
  };
@@ -766,22 +724,22 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
766
724
  const prettyError = preparePrettyError(error);
767
725
  logError(error, prettyError);
768
726
  const errorProperty = getErrorProperty(error, prettyError);
769
- return create$1$1(id, errorProperty);
727
+ return create$1$2(id, errorProperty);
770
728
  };
771
- const create$6 = (message, result) => {
729
+ const create$3 = (message, result) => {
772
730
  return {
773
- jsonrpc: Two,
731
+ jsonrpc: Two$1,
774
732
  id: message.id,
775
733
  result: result ?? null
776
734
  };
777
735
  };
778
736
  const getSuccessResponse = (message, result) => {
779
737
  const resultProperty = result ?? null;
780
- return create$6(message, resultProperty);
738
+ return create$3(message, resultProperty);
781
739
  };
782
740
  const getErrorResponseSimple = (id, error) => {
783
741
  return {
784
- jsonrpc: Two,
742
+ jsonrpc: Two$1,
785
743
  id,
786
744
  error: {
787
745
  code: Custom,
@@ -868,29 +826,6 @@ const handleJsonRpcMessage = async (...args) => {
868
826
  }
869
827
  throw new JsonRpcError('unexpected message');
870
828
  };
871
- const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
872
- const {
873
- message,
874
- promise
875
- } = create$2$1(method, params);
876
- if (useSendAndTransfer && ipc.sendAndTransfer) {
877
- ipc.sendAndTransfer(message);
878
- } else {
879
- ipc.send(message);
880
- }
881
- const responseMessage = await promise;
882
- return unwrapJsonRpcResult(responseMessage);
883
- };
884
- const send = (transport, method, ...params) => {
885
- const message = create$4$1(method, params);
886
- transport.send(message);
887
- };
888
- const invoke$3 = (ipc, method, ...params) => {
889
- return invokeHelper(ipc, method, params, false);
890
- };
891
- const invokeAndTransfer$2 = (ipc, method, ...params) => {
892
- return invokeHelper(ipc, method, params, true);
893
- };
894
829
 
895
830
  class CommandNotFoundError extends Error {
896
831
  constructor(command) {
@@ -913,24 +848,87 @@ const execute = (command, ...args) => {
913
848
  return fn(...args);
914
849
  };
915
850
 
851
+ const Two = '2.0';
852
+ const create$s = (method, params) => {
853
+ return {
854
+ jsonrpc: Two,
855
+ method,
856
+ params
857
+ };
858
+ };
859
+ const create$r = (id, method, params) => {
860
+ const message = {
861
+ id,
862
+ jsonrpc: Two,
863
+ method,
864
+ params
865
+ };
866
+ return message;
867
+ };
868
+ let id$1 = 0;
869
+ const create$q = () => {
870
+ return ++id$1;
871
+ };
872
+
873
+ /* eslint-disable n/no-unsupported-features/es-syntax */
874
+
875
+ const registerPromise = map => {
876
+ const id = create$q();
877
+ const {
878
+ promise,
879
+ resolve
880
+ } = Promise.withResolvers();
881
+ map[id] = resolve;
882
+ return {
883
+ id,
884
+ promise
885
+ };
886
+ };
887
+
888
+ // @ts-ignore
889
+ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
890
+ const {
891
+ id,
892
+ promise
893
+ } = registerPromise(callbacks);
894
+ const message = create$r(id, method, params);
895
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
896
+ ipc.sendAndTransfer(message);
897
+ } else {
898
+ ipc.send(message);
899
+ }
900
+ const responseMessage = await promise;
901
+ return unwrapJsonRpcResult(responseMessage);
902
+ };
916
903
  const createRpc = ipc => {
904
+ const callbacks = Object.create(null);
905
+ ipc._resolve = (id, response) => {
906
+ const fn = callbacks[id];
907
+ if (!fn) {
908
+ console.warn(`callback ${id} may already be disposed`);
909
+ return;
910
+ }
911
+ fn(response);
912
+ delete callbacks[id];
913
+ };
917
914
  const rpc = {
915
+ async dispose() {
916
+ await ipc?.dispose();
917
+ },
918
+ invoke(method, ...params) {
919
+ return invokeHelper(callbacks, ipc, method, params, false);
920
+ },
921
+ invokeAndTransfer(method, ...params) {
922
+ return invokeHelper(callbacks, ipc, method, params, true);
923
+ },
918
924
  // @ts-ignore
919
925
  ipc,
920
926
  /**
921
927
  * @deprecated
922
928
  */
923
929
  send(method, ...params) {
924
- send(ipc, method, ...params);
925
- },
926
- invoke(method, ...params) {
927
- return invoke$3(ipc, method, ...params);
928
- },
929
- invokeAndTransfer(method, ...params) {
930
- return invokeAndTransfer$2(ipc, method, ...params);
931
- },
932
- async dispose() {
933
- await ipc?.dispose();
930
+ const message = create$s(method, params);
931
+ ipc.send(message);
934
932
  }
935
933
  };
936
934
  return rpc;
@@ -947,7 +945,7 @@ const logError = () => {
947
945
  const handleMessage = event => {
948
946
  const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
949
947
  const actualExecute = event?.target?.execute || execute;
950
- return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
948
+ return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
951
949
  };
952
950
  const handleIpc = ipc => {
953
951
  if ('addEventListener' in ipc) {
@@ -965,15 +963,16 @@ const listen$1 = async (module, options) => {
965
963
  const ipc = module.wrap(rawIpc);
966
964
  return ipc;
967
965
  };
968
- const create$5 = async ({
966
+ const create$4 = async ({
969
967
  commandMap,
968
+ isMessagePortOpen = true,
970
969
  messagePort
971
970
  }) => {
972
971
  // TODO create a commandMap per rpc instance
973
972
  register(commandMap);
974
973
  const rawIpc = await IpcParentWithMessagePort$1.create({
975
- messagePort,
976
- isMessagePortOpen: true
974
+ isMessagePortOpen,
975
+ messagePort
977
976
  });
978
977
  const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
979
978
  handleIpc(ipc);
@@ -981,8 +980,9 @@ const create$5 = async ({
981
980
  messagePort.start();
982
981
  return rpc;
983
982
  };
984
- const create$3 = async ({
983
+ const create$2$1 = async ({
985
984
  commandMap,
985
+ isMessagePortOpen,
986
986
  send
987
987
  }) => {
988
988
  const {
@@ -990,16 +990,17 @@ const create$3 = async ({
990
990
  port2
991
991
  } = new MessageChannel();
992
992
  await send(port1);
993
- return create$5({
993
+ return create$4({
994
994
  commandMap,
995
+ isMessagePortOpen,
995
996
  messagePort: port2
996
997
  });
997
998
  };
998
999
  const TransferMessagePortRpcParent = {
999
1000
  __proto__: null,
1000
- create: create$3
1001
+ create: create$2$1
1001
1002
  };
1002
- const create$4 = async ({
1003
+ const create$1$1 = async ({
1003
1004
  commandMap
1004
1005
  }) => {
1005
1006
  // TODO create a commandMap per rpc instance
@@ -1011,7 +1012,7 @@ const create$4 = async ({
1011
1012
  };
1012
1013
  const WebWorkerRpcClient = {
1013
1014
  __proto__: null,
1014
- create: create$4
1015
+ create: create$1$1
1015
1016
  };
1016
1017
  const createMockRpc = ({
1017
1018
  commandMap
@@ -1026,14 +1027,22 @@ const createMockRpc = ({
1026
1027
  return command(...params);
1027
1028
  };
1028
1029
  const mockRpc = {
1030
+ invocations,
1029
1031
  invoke,
1030
- invokeAndTransfer: invoke,
1031
- invocations
1032
+ invokeAndTransfer: invoke
1032
1033
  };
1033
1034
  return mockRpc;
1034
1035
  };
1035
1036
 
1036
- const Button$2 = 'event.button';
1037
+ const None$3 = 'none';
1038
+
1039
+ const Button$2 = 1;
1040
+ const Div = 4;
1041
+ const Input$1 = 6;
1042
+ const Text = 12;
1043
+ const Img = 17;
1044
+
1045
+ const Button$1 = 'event.button';
1037
1046
  const ClientX = 'event.clientX';
1038
1047
  const ClientY = 'event.clientY';
1039
1048
  const DeltaMode = 'event.deltaMode';
@@ -1045,11 +1054,15 @@ const Script$1 = 2;
1045
1054
  const ManageExtension = 8;
1046
1055
  const ExtensionSearchFilter = 95;
1047
1056
 
1057
+ const LeftClick = 0;
1058
+
1048
1059
  const ExtensionHostWorker = 44;
1049
1060
  const ExtensionManagementWorker = 9006;
1050
1061
  const RendererWorker = 1;
1051
1062
 
1052
1063
  const FocusSelector = 'Viewlet.focusSelector';
1064
+ const SetDom2 = 'Viewlet.setDom2';
1065
+ const SetPatches = 'Viewlet.setPatches';
1053
1066
 
1054
1067
  const rpcs = Object.create(null);
1055
1068
  const set$5 = (id, rpc) => {
@@ -1058,7 +1071,11 @@ const set$5 = (id, rpc) => {
1058
1071
  const get$1 = id => {
1059
1072
  return rpcs[id];
1060
1073
  };
1074
+ const remove = id => {
1075
+ delete rpcs[id];
1076
+ };
1061
1077
 
1078
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
1062
1079
  const create$2 = rpcId => {
1063
1080
  return {
1064
1081
  async dispose() {
@@ -1077,6 +1094,18 @@ const create$2 = rpcId => {
1077
1094
  // @ts-ignore
1078
1095
  return rpc.invokeAndTransfer(method, ...params);
1079
1096
  },
1097
+ registerMockRpc(commandMap) {
1098
+ const mockRpc = createMockRpc({
1099
+ commandMap
1100
+ });
1101
+ set$5(rpcId, mockRpc);
1102
+ // @ts-ignore
1103
+ mockRpc[Symbol.dispose] = () => {
1104
+ remove(rpcId);
1105
+ };
1106
+ // @ts-ignore
1107
+ return mockRpc;
1108
+ },
1080
1109
  set(rpc) {
1081
1110
  set$5(rpcId, rpc);
1082
1111
  }
@@ -1087,6 +1116,7 @@ const {
1087
1116
  dispose: dispose$2,
1088
1117
  invoke: invoke$2,
1089
1118
  invokeAndTransfer: invokeAndTransfer$1,
1119
+ registerMockRpc,
1090
1120
  set: set$4
1091
1121
  } = create$2(ExtensionHostWorker);
1092
1122
  const executeReferenceProvider = async (id, offset) => {
@@ -1101,12 +1131,9 @@ const getRuntimeStatus = async extensionId => {
1101
1131
  // @ts-ignore
1102
1132
  return invoke$2('ExtensionHost.getRuntimeStatus', extensionId);
1103
1133
  };
1104
- const registerMockRpc = commandMap => {
1105
- const mockRpc = createMockRpc({
1106
- commandMap
1107
- });
1108
- set$4(mockRpc);
1109
- return mockRpc;
1134
+ const getEnabledOutputProviderIds = async () => {
1135
+ const channels = await invoke$2('Output.getEnabledProviders');
1136
+ return channels;
1110
1137
  };
1111
1138
 
1112
1139
  const ExtensionHost = {
@@ -1114,6 +1141,7 @@ const ExtensionHost = {
1114
1141
  dispose: dispose$2,
1115
1142
  executeFileReferenceProvider,
1116
1143
  executeReferenceProvider,
1144
+ getEnabledOutputProviderIds,
1117
1145
  getRuntimeStatus,
1118
1146
  invoke: invoke$2,
1119
1147
  invokeAndTransfer: invokeAndTransfer$1,
@@ -1238,8 +1266,8 @@ const terminate = () => {
1238
1266
  globalThis.close();
1239
1267
  };
1240
1268
 
1241
- const None$3 = 0;
1242
- const Input$1 = 1;
1269
+ const None$2 = 0;
1270
+ const Input = 1;
1243
1271
  const List$2 = 2;
1244
1272
 
1245
1273
  const handleError = async (error, notify = true, prefix = '') => {
@@ -1399,7 +1427,7 @@ const getFinalDeltaY = (height, itemHeight, itemsLength) => {
1399
1427
  return finalDeltaY;
1400
1428
  };
1401
1429
 
1402
- const Button$1 = 1;
1430
+ const Button = 1;
1403
1431
 
1404
1432
  const HandleClearSearchResults = 1;
1405
1433
  const HandleClickFilter = 2;
@@ -1429,13 +1457,13 @@ const getInputActions = hasValue => {
1429
1457
  icon: `MaskIcon${ClearAll}`,
1430
1458
  onClick: HandleClearSearchResults,
1431
1459
  title: clearExtensionSearchResults(),
1432
- type: Button$1
1460
+ type: Button
1433
1461
  }, {
1434
1462
  enabled: true,
1435
1463
  icon: `MaskIcon${Filter}`,
1436
1464
  onClick: HandleClickFilter,
1437
1465
  title: filter(),
1438
- type: Button$1
1466
+ type: Button
1439
1467
  }];
1440
1468
  return actions;
1441
1469
  };
@@ -1617,7 +1645,7 @@ const handleChange = async (state, update) => {
1617
1645
  ...update
1618
1646
  };
1619
1647
  try {
1620
- const value = fullNewState.searchValue;
1648
+ const value = fullNewState.searchValue.trim();
1621
1649
  const {
1622
1650
  inputSource
1623
1651
  } = fullNewState;
@@ -1641,7 +1669,7 @@ const handleChange = async (state, update) => {
1641
1669
  allExtensions,
1642
1670
  deltaY: 0,
1643
1671
  finalDeltaY: 0,
1644
- focus: Input$1,
1672
+ focus: Input,
1645
1673
  inputActions,
1646
1674
  inputSource,
1647
1675
  items,
@@ -1693,7 +1721,7 @@ const handleChange = async (state, update) => {
1693
1721
  const clearSearchResults = state => {
1694
1722
  return handleChange(state, {
1695
1723
  ...state,
1696
- focus: Input$1,
1724
+ focus: Input,
1697
1725
  inputSource: Script$1,
1698
1726
  searchValue: ''
1699
1727
  });
@@ -1800,6 +1828,7 @@ const create = (id, uri, x, y, width, height, platform, assetDir) => {
1800
1828
  handleOffset: 0,
1801
1829
  headerHeight: 41,
1802
1830
  height,
1831
+ initial: true,
1803
1832
  inputActions: [],
1804
1833
  inputSource: 0,
1805
1834
  itemHeight: 72,
@@ -1850,9 +1879,10 @@ const RenderScrollBar = 5;
1850
1879
  const RenderMessage = 6;
1851
1880
  const RenderSearchValue = 7;
1852
1881
  const RenderFocusContext = 8;
1882
+ const RenderIncremental = 9;
1853
1883
 
1854
1884
  const modules = [isEqual$1, isEqual$2, isEqual, isEqual$2];
1855
- const numbers = [RenderItems, RenderFocus, RenderSearchValue, RenderFocusContext];
1885
+ const numbers = [RenderIncremental, RenderFocus, RenderSearchValue, RenderFocusContext];
1856
1886
 
1857
1887
  const diff2 = uid => {
1858
1888
  return diff(uid, modules, numbers);
@@ -2037,12 +2067,12 @@ const getActions = () => {
2037
2067
  command: '',
2038
2068
  icon: Refresh,
2039
2069
  id: refresh(),
2040
- type: Button$1
2070
+ type: Button
2041
2071
  }, {
2042
2072
  command: '',
2043
2073
  icon: Ellipsis,
2044
2074
  id: viewsAndMoreActions(),
2045
- type: Button$1
2075
+ type: Button
2046
2076
  }];
2047
2077
  };
2048
2078
 
@@ -2105,18 +2135,18 @@ const getKeyBindings = () => {
2105
2135
  };
2106
2136
 
2107
2137
  const Separator = 1;
2108
- const None$2 = 0;
2138
+ const None$1 = 0;
2109
2139
  const SubMenu = 4;
2110
2140
 
2111
2141
  const getMenuEntries = () => {
2112
2142
  return [{
2113
2143
  command: 'SearchExtensions.enable',
2114
- flags: None$2,
2144
+ flags: None$1,
2115
2145
  id: 'enable',
2116
2146
  label: enable()
2117
2147
  }, {
2118
2148
  command: 'SearchExtensions.enableWorkspace',
2119
- flags: None$2,
2149
+ flags: None$1,
2120
2150
  id: 'enableWorkspace',
2121
2151
  label: enableWorkspace()
2122
2152
  }, {
@@ -2126,12 +2156,12 @@ const getMenuEntries = () => {
2126
2156
  label: ''
2127
2157
  }, {
2128
2158
  command: 'SearchExtensions.disable',
2129
- flags: None$2,
2159
+ flags: None$1,
2130
2160
  id: 'disable',
2131
2161
  label: disable()
2132
2162
  }, {
2133
2163
  command: 'SearchExtensions.disableWorkspace',
2134
- flags: None$2,
2164
+ flags: None$1,
2135
2165
  id: 'disableWorkspace',
2136
2166
  label: disableWorkspace()
2137
2167
  }, {
@@ -2141,17 +2171,17 @@ const getMenuEntries = () => {
2141
2171
  label: ''
2142
2172
  }, {
2143
2173
  command: 'SearchExtensions.installAnotherVersion',
2144
- flags: None$2,
2174
+ flags: None$1,
2145
2175
  id: 'installAnotherVersion',
2146
2176
  label: installAnotherVersion()
2147
2177
  }, {
2148
2178
  command: 'Extensions.copyExtensionInfo',
2149
- flags: None$2,
2179
+ flags: None$1,
2150
2180
  id: 'copy',
2151
2181
  label: copy()
2152
2182
  }, {
2153
2183
  command: 'Extensions.copyExtensionId',
2154
- flags: None$2,
2184
+ flags: None$1,
2155
2185
  id: 'copyExtensionId',
2156
2186
  label: copyExtensionId$1()
2157
2187
  }];
@@ -2160,27 +2190,27 @@ const getMenuEntries = () => {
2160
2190
  const getMenuEntriesFilter = () => {
2161
2191
  return [{
2162
2192
  command: 'SearchExtensions.filterByFeatured',
2163
- flags: None$2,
2193
+ flags: None$1,
2164
2194
  id: 'filterByFeatured',
2165
2195
  label: featured()
2166
2196
  }, {
2167
2197
  command: 'SearchExtensions.filterByMcpServers',
2168
- flags: None$2,
2198
+ flags: None$1,
2169
2199
  id: 'filterByMcpServers',
2170
2200
  label: mcpServers()
2171
2201
  }, {
2172
2202
  command: 'SearchExtensions.filterByMostPopular',
2173
- flags: None$2,
2203
+ flags: None$1,
2174
2204
  id: 'filterByMostPopular',
2175
2205
  label: mostPopular()
2176
2206
  }, {
2177
2207
  command: 'SearchExtensions.filterByRecentlyPublished',
2178
- flags: None$2,
2208
+ flags: None$1,
2179
2209
  id: 'filterByRecentlyPublished',
2180
2210
  label: recentlyPublished()
2181
2211
  }, {
2182
2212
  command: 'SearchExtensions.filterByRecommended',
2183
- flags: None$2,
2213
+ flags: None$1,
2184
2214
  id: 'filterByRecommended',
2185
2215
  label: recommended()
2186
2216
  }, {
@@ -2195,32 +2225,32 @@ const getMenuEntriesFilter = () => {
2195
2225
  label: category()
2196
2226
  }, {
2197
2227
  command: 'SearchExtensions.filterByInstalled',
2198
- flags: None$2,
2228
+ flags: None$1,
2199
2229
  id: 'filterByInstalled',
2200
2230
  label: installed()
2201
2231
  }, {
2202
2232
  command: 'SearchExtensions.filterByUpdates',
2203
- flags: None$2,
2233
+ flags: None$1,
2204
2234
  id: 'filterByUpdates',
2205
2235
  label: updates()
2206
2236
  }, {
2207
2237
  command: 'SearchExtensions.filterByBuiltin',
2208
- flags: None$2,
2238
+ flags: None$1,
2209
2239
  id: 'filterByBuiltin',
2210
2240
  label: builtIn()
2211
2241
  }, {
2212
2242
  command: 'SearchExtensions.filterByEnabled',
2213
- flags: None$2,
2243
+ flags: None$1,
2214
2244
  id: 'filterByEnabled',
2215
2245
  label: enabled()
2216
2246
  }, {
2217
2247
  command: 'SearchExtensions.filterByDisabled',
2218
- flags: None$2,
2248
+ flags: None$1,
2219
2249
  id: 'filterByDisabled',
2220
2250
  label: disabled()
2221
2251
  }, {
2222
2252
  command: 'SearchExtensions.filterByWorkspaceUnsupported',
2223
- flags: None$2,
2253
+ flags: None$1,
2224
2254
  id: 'filterByWorkspaceUnsupported',
2225
2255
  label: workspaceUnsupported()
2226
2256
  }, {
@@ -2255,7 +2285,7 @@ const getMenuIds = () => {
2255
2285
  const handleBlur = state => {
2256
2286
  return {
2257
2287
  ...state,
2258
- focus: None$3
2288
+ focus: None$2
2259
2289
  };
2260
2290
  };
2261
2291
 
@@ -2291,28 +2321,295 @@ const handleClick = async (state, index) => {
2291
2321
  return newState;
2292
2322
  };
2293
2323
 
2294
- const None$1 = 'none';
2295
-
2296
- const Button = 1;
2297
- const Div = 4;
2298
- const Input = 6;
2299
- const Text = 12;
2300
- const Img = 17;
2301
-
2302
- const LeftClick = 0;
2303
-
2304
2324
  const mergeClassNames = (...classNames) => {
2305
2325
  return classNames.filter(Boolean).join(' ');
2306
2326
  };
2307
2327
 
2308
2328
  const text = data => {
2309
2329
  return {
2310
- type: Text,
2330
+ childCount: 0,
2311
2331
  text: data,
2312
- childCount: 0
2332
+ type: Text
2333
+ };
2334
+ };
2335
+
2336
+ const SetText = 1;
2337
+ const Replace = 2;
2338
+ const SetAttribute = 3;
2339
+ const RemoveAttribute = 4;
2340
+ const Add = 6;
2341
+ const NavigateChild = 7;
2342
+ const NavigateParent = 8;
2343
+ const RemoveChild = 9;
2344
+ const NavigateSibling = 10;
2345
+
2346
+ const isKey = key => {
2347
+ return key !== 'type' && key !== 'childCount';
2348
+ };
2349
+
2350
+ const getKeys = node => {
2351
+ const keys = Object.keys(node).filter(isKey);
2352
+ return keys;
2353
+ };
2354
+
2355
+ const arrayToTree = nodes => {
2356
+ const result = [];
2357
+ let i = 0;
2358
+ while (i < nodes.length) {
2359
+ const node = nodes[i];
2360
+ const {
2361
+ children,
2362
+ nodesConsumed
2363
+ } = getChildrenWithCount(nodes, i + 1, node.childCount || 0);
2364
+ result.push({
2365
+ node,
2366
+ children
2367
+ });
2368
+ i += 1 + nodesConsumed;
2369
+ }
2370
+ return result;
2371
+ };
2372
+ const getChildrenWithCount = (nodes, startIndex, childCount) => {
2373
+ if (childCount === 0) {
2374
+ return {
2375
+ children: [],
2376
+ nodesConsumed: 0
2377
+ };
2378
+ }
2379
+ const children = [];
2380
+ let i = startIndex;
2381
+ let remaining = childCount;
2382
+ let totalConsumed = 0;
2383
+ while (remaining > 0 && i < nodes.length) {
2384
+ const node = nodes[i];
2385
+ const nodeChildCount = node.childCount || 0;
2386
+ const {
2387
+ children: nodeChildren,
2388
+ nodesConsumed
2389
+ } = getChildrenWithCount(nodes, i + 1, nodeChildCount);
2390
+ children.push({
2391
+ node,
2392
+ children: nodeChildren
2393
+ });
2394
+ const nodeSize = 1 + nodesConsumed;
2395
+ i += nodeSize;
2396
+ totalConsumed += nodeSize;
2397
+ remaining--;
2398
+ }
2399
+ return {
2400
+ children,
2401
+ nodesConsumed: totalConsumed
2313
2402
  };
2314
2403
  };
2315
2404
 
2405
+ const compareNodes = (oldNode, newNode) => {
2406
+ const patches = [];
2407
+ // Check if node type changed - return null to signal incompatible nodes
2408
+ // (caller should handle this with a Replace operation)
2409
+ if (oldNode.type !== newNode.type) {
2410
+ return null;
2411
+ }
2412
+ // Handle text nodes
2413
+ if (oldNode.type === Text && newNode.type === Text) {
2414
+ if (oldNode.text !== newNode.text) {
2415
+ patches.push({
2416
+ type: SetText,
2417
+ value: newNode.text
2418
+ });
2419
+ }
2420
+ return patches;
2421
+ }
2422
+ // Compare attributes
2423
+ const oldKeys = getKeys(oldNode);
2424
+ const newKeys = getKeys(newNode);
2425
+ // Check for attribute changes
2426
+ for (const key of newKeys) {
2427
+ if (oldNode[key] !== newNode[key]) {
2428
+ patches.push({
2429
+ type: SetAttribute,
2430
+ key,
2431
+ value: newNode[key]
2432
+ });
2433
+ }
2434
+ }
2435
+ // Check for removed attributes
2436
+ for (const key of oldKeys) {
2437
+ if (!(key in newNode)) {
2438
+ patches.push({
2439
+ type: RemoveAttribute,
2440
+ key
2441
+ });
2442
+ }
2443
+ }
2444
+ return patches;
2445
+ };
2446
+
2447
+ const treeToArray = node => {
2448
+ const result = [node.node];
2449
+ for (const child of node.children) {
2450
+ result.push(...treeToArray(child));
2451
+ }
2452
+ return result;
2453
+ };
2454
+
2455
+ const diffChildren = (oldChildren, newChildren, patches) => {
2456
+ const maxLength = Math.max(oldChildren.length, newChildren.length);
2457
+ // Track where we are: -1 means at parent, >= 0 means at child index
2458
+ let currentChildIndex = -1;
2459
+ // Collect indices of children to remove (we'll add these patches at the end in reverse order)
2460
+ const indicesToRemove = [];
2461
+ for (let i = 0; i < maxLength; i++) {
2462
+ const oldNode = oldChildren[i];
2463
+ const newNode = newChildren[i];
2464
+ if (!oldNode && !newNode) {
2465
+ continue;
2466
+ }
2467
+ if (!oldNode) {
2468
+ // Add new node - we should be at the parent
2469
+ if (currentChildIndex >= 0) {
2470
+ // Navigate back to parent
2471
+ patches.push({
2472
+ type: NavigateParent
2473
+ });
2474
+ currentChildIndex = -1;
2475
+ }
2476
+ // Flatten the entire subtree so renderInternal can handle it
2477
+ const flatNodes = treeToArray(newNode);
2478
+ patches.push({
2479
+ type: Add,
2480
+ nodes: flatNodes
2481
+ });
2482
+ } else if (newNode) {
2483
+ // Compare nodes to see if we need any patches
2484
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2485
+ // If nodePatches is null, the node types are incompatible - need to replace
2486
+ if (nodePatches === null) {
2487
+ // Navigate to this child
2488
+ if (currentChildIndex === -1) {
2489
+ patches.push({
2490
+ type: NavigateChild,
2491
+ index: i
2492
+ });
2493
+ currentChildIndex = i;
2494
+ } else if (currentChildIndex !== i) {
2495
+ patches.push({
2496
+ type: NavigateSibling,
2497
+ index: i
2498
+ });
2499
+ currentChildIndex = i;
2500
+ }
2501
+ // Replace the entire subtree
2502
+ const flatNodes = treeToArray(newNode);
2503
+ patches.push({
2504
+ type: Replace,
2505
+ nodes: flatNodes
2506
+ });
2507
+ // After replace, we're at the new element (same position)
2508
+ continue;
2509
+ }
2510
+ // Check if we need to recurse into children
2511
+ const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
2512
+ // Only navigate to this element if we need to do something
2513
+ if (nodePatches.length > 0 || hasChildrenToCompare) {
2514
+ // Navigate to this child if not already there
2515
+ if (currentChildIndex === -1) {
2516
+ patches.push({
2517
+ type: NavigateChild,
2518
+ index: i
2519
+ });
2520
+ currentChildIndex = i;
2521
+ } else if (currentChildIndex !== i) {
2522
+ patches.push({
2523
+ type: NavigateSibling,
2524
+ index: i
2525
+ });
2526
+ currentChildIndex = i;
2527
+ }
2528
+ // Apply node patches (these apply to the current element, not children)
2529
+ if (nodePatches.length > 0) {
2530
+ patches.push(...nodePatches);
2531
+ }
2532
+ // Compare children recursively
2533
+ if (hasChildrenToCompare) {
2534
+ diffChildren(oldNode.children, newNode.children, patches);
2535
+ }
2536
+ }
2537
+ } else {
2538
+ // Remove old node - collect the index for later removal
2539
+ indicesToRemove.push(i);
2540
+ }
2541
+ }
2542
+ // Navigate back to parent if we ended at a child
2543
+ if (currentChildIndex >= 0) {
2544
+ patches.push({
2545
+ type: NavigateParent
2546
+ });
2547
+ currentChildIndex = -1;
2548
+ }
2549
+ // Add remove patches in reverse order (highest index first)
2550
+ // This ensures indices remain valid as we remove
2551
+ for (let j = indicesToRemove.length - 1; j >= 0; j--) {
2552
+ patches.push({
2553
+ type: RemoveChild,
2554
+ index: indicesToRemove[j]
2555
+ });
2556
+ }
2557
+ };
2558
+ const diffTrees = (oldTree, newTree, patches, path) => {
2559
+ // At the root level (path.length === 0), we're already AT the element
2560
+ // So we compare the root node directly, then compare its children
2561
+ if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
2562
+ const oldNode = oldTree[0];
2563
+ const newNode = newTree[0];
2564
+ // Compare root nodes
2565
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2566
+ // If nodePatches is null, the root node types are incompatible - need to replace
2567
+ if (nodePatches === null) {
2568
+ const flatNodes = treeToArray(newNode);
2569
+ patches.push({
2570
+ type: Replace,
2571
+ nodes: flatNodes
2572
+ });
2573
+ return;
2574
+ }
2575
+ if (nodePatches.length > 0) {
2576
+ patches.push(...nodePatches);
2577
+ }
2578
+ // Compare children
2579
+ if (oldNode.children.length > 0 || newNode.children.length > 0) {
2580
+ diffChildren(oldNode.children, newNode.children, patches);
2581
+ }
2582
+ } else {
2583
+ // Non-root level or multiple root elements - use the regular comparison
2584
+ diffChildren(oldTree, newTree, patches);
2585
+ }
2586
+ };
2587
+
2588
+ const removeTrailingNavigationPatches = patches => {
2589
+ // Find the last non-navigation patch
2590
+ let lastNonNavigationIndex = -1;
2591
+ for (let i = patches.length - 1; i >= 0; i--) {
2592
+ const patch = patches[i];
2593
+ if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling) {
2594
+ lastNonNavigationIndex = i;
2595
+ break;
2596
+ }
2597
+ }
2598
+ // Return patches up to and including the last non-navigation patch
2599
+ return lastNonNavigationIndex === -1 ? [] : patches.slice(0, lastNonNavigationIndex + 1);
2600
+ };
2601
+
2602
+ const diffTree = (oldNodes, newNodes) => {
2603
+ // Step 1: Convert flat arrays to tree structures
2604
+ const oldTree = arrayToTree(oldNodes);
2605
+ const newTree = arrayToTree(newNodes);
2606
+ // Step 3: Compare the trees
2607
+ const patches = [];
2608
+ diffTrees(oldTree, newTree, patches, []);
2609
+ // Remove trailing navigation patches since they serve no purpose
2610
+ return removeTrailingNavigationPatches(patches);
2611
+ };
2612
+
2316
2613
  const getListIndex = (eventX, eventY, x, y, deltaY, itemHeight, headerHeight) => {
2317
2614
  const relativeDeltaY = deltaY % itemHeight;
2318
2615
  const relativeY = eventY - y - headerHeight + relativeDeltaY;
@@ -2809,6 +3106,7 @@ const loadContent = async (state, savedState) => {
2809
3106
  ...state,
2810
3107
  allExtensions: normalized,
2811
3108
  deltaY,
3109
+ initial: false,
2812
3110
  inputSource: Script,
2813
3111
  size
2814
3112
  }, searchValue, Script);
@@ -2823,7 +3121,7 @@ const Extensions$1 = 'extensions';
2823
3121
 
2824
3122
  const getSelector = focus => {
2825
3123
  switch (focus) {
2826
- case Input$1:
3124
+ case Input:
2827
3125
  return `[name="${Extensions$1}"]`;
2828
3126
  case List$2:
2829
3127
  return '.ListItems';
@@ -2847,7 +3145,7 @@ const renderFocusContext = newState => {
2847
3145
  const {
2848
3146
  uid
2849
3147
  } = newState;
2850
- if (newState.focus === Input$1) {
3148
+ if (newState.focus === Input) {
2851
3149
  return ['Viewlet.setFocusContext', uid, FocusExtensionsInput];
2852
3150
  }
2853
3151
  if (newState.focus === List$2) {
@@ -2911,7 +3209,7 @@ const getSearchFieldButtonVirtualDom = button => {
2911
3209
  onClick,
2912
3210
  tabIndex: 0,
2913
3211
  title,
2914
- type: Button
3212
+ type: Button$2
2915
3213
  }, {
2916
3214
  childCount: 0,
2917
3215
  className: mergeClassNames(MaskIcon, icon),
@@ -2938,7 +3236,7 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
2938
3236
  onInput,
2939
3237
  placeholder,
2940
3238
  spellcheck: false,
2941
- type: Input
3239
+ type: Input$1
2942
3240
  }, {
2943
3241
  childCount: insideButtons.length,
2944
3242
  className: SearchFieldButtons,
@@ -3179,14 +3477,29 @@ const getExtensionsViewVirtualDom = state => {
3179
3477
  ariaLive: 'polite',
3180
3478
  childCount: 2,
3181
3479
  className: mergeClassNames(Viewlet, Extensions),
3182
- role: None$1,
3480
+ role: None$3,
3183
3481
  type: Div
3184
3482
  }, ...getExtensionHeaderVirtualDom(placeholder, inputActions), ...getContentVirtualDom(visibleExtensions, message, scrollBarHeight, scrollBarY, focusOutline)];
3185
3483
  };
3186
3484
 
3187
3485
  const renderItems2 = newState => {
3486
+ const {
3487
+ initial,
3488
+ uid
3489
+ } = newState;
3490
+ if (initial) {
3491
+ return [SetDom2, uid, []];
3492
+ }
3188
3493
  const dom = getExtensionsViewVirtualDom(newState);
3189
- return ['Viewlet.setDom2', newState.uid, dom];
3494
+ return [SetDom2, uid, dom];
3495
+ };
3496
+
3497
+ // TODO cache rendered dom so that it can be used for dom diffing
3498
+ const renderIncremental = (newState, oldState) => {
3499
+ const oldDom = renderItems2(oldState)[2];
3500
+ const newDom = renderItems2(newState)[2];
3501
+ const patches = diffTree(oldDom, newDom);
3502
+ return [SetPatches, newState.uid, patches];
3190
3503
  };
3191
3504
 
3192
3505
  const SetMessage = 'setMessage';
@@ -3224,6 +3537,8 @@ const getRenderer = diffType => {
3224
3537
  return renderFocusContext;
3225
3538
  case RenderHeader:
3226
3539
  return renderHeader;
3540
+ case RenderIncremental:
3541
+ return renderIncremental;
3227
3542
  case RenderItems:
3228
3543
  return renderItems2;
3229
3544
  case RenderMessage:
@@ -3274,13 +3589,13 @@ const getActionButtonVirtualDom = action => {
3274
3589
  childCount: 1,
3275
3590
  className: IconButton,
3276
3591
  title: id,
3277
- type: Button
3592
+ type: Button$2
3278
3593
  }, getIconVirtualDom(icon)];
3279
3594
  };
3280
3595
 
3281
3596
  const getActionVirtualDom = action => {
3282
3597
  switch (action.type) {
3283
- case Button$1:
3598
+ case Button:
3284
3599
  return getActionButtonVirtualDom(action);
3285
3600
  default:
3286
3601
  return [];
@@ -3312,7 +3627,7 @@ const renderActions = uid => {
3312
3627
  const renderEventListeners = () => {
3313
3628
  return [{
3314
3629
  name: HandleContextMenu,
3315
- params: ['handleContextMenu', Button$2, ClientX, ClientY],
3630
+ params: ['handleContextMenu', Button$1, ClientX, ClientY],
3316
3631
  preventDefault: true
3317
3632
  }, {
3318
3633
  name: HandleHeaderContextMenu,
@@ -3320,7 +3635,7 @@ const renderEventListeners = () => {
3320
3635
  preventDefault: true
3321
3636
  }, {
3322
3637
  name: HandlePointerDown,
3323
- params: ['handleClickAt', Button$2, ClientX, ClientY],
3638
+ params: ['handleClickAt', Button$1, ClientX, ClientY],
3324
3639
  preventDefault: true
3325
3640
  }, {
3326
3641
  name: HandleScrollBarPointerDown,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-search-view",
3
- "version": "6.3.0",
3
+ "version": "7.0.0",
4
4
  "description": "Extension Search View Worker",
5
5
  "repository": {
6
6
  "type": "git",