@lvce-editor/iframe-worker 6.3.0 → 6.5.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.
@@ -61,7 +61,7 @@ class AssertionError extends Error {
61
61
  }
62
62
  }
63
63
  const Object$1 = 1;
64
- const Number = 2;
64
+ const Number$1 = 2;
65
65
  const Array$1 = 3;
66
66
  const String = 4;
67
67
  const Boolean = 5;
@@ -71,7 +71,7 @@ const Unknown = 8;
71
71
  const getType = value => {
72
72
  switch (typeof value) {
73
73
  case 'number':
74
- return Number;
74
+ return Number$1;
75
75
  case 'function':
76
76
  return Function;
77
77
  case 'string':
@@ -98,10 +98,16 @@ const object = value => {
98
98
  };
99
99
  const number = value => {
100
100
  const type = getType(value);
101
- if (type !== Number) {
101
+ if (type !== Number$1) {
102
102
  throw new AssertionError('expected value to be of type number');
103
103
  }
104
104
  };
105
+ const string = value => {
106
+ const type = getType(value);
107
+ if (type !== String) {
108
+ throw new AssertionError('expected value to be of type string');
109
+ }
110
+ };
105
111
 
106
112
  const isMessagePort = value => {
107
113
  return value && value instanceof MessagePort;
@@ -231,8 +237,8 @@ const getModuleNotFoundError = stderr => {
231
237
  const messageIndex = lines.findIndex(isModuleNotFoundMessage);
232
238
  const message = lines[messageIndex];
233
239
  return {
234
- message,
235
- code: ERR_MODULE_NOT_FOUND
240
+ code: ERR_MODULE_NOT_FOUND,
241
+ message
236
242
  };
237
243
  };
238
244
  const isModuleNotFoundError = stderr => {
@@ -255,14 +261,14 @@ const isUnhelpfulNativeModuleError = stderr => {
255
261
  const getNativeModuleErrorMessage = stderr => {
256
262
  const message = getMessageCodeBlock(stderr);
257
263
  return {
258
- message: `Incompatible native node module: ${message}`,
259
- code: E_INCOMPATIBLE_NATIVE_MODULE
264
+ code: E_INCOMPATIBLE_NATIVE_MODULE,
265
+ message: `Incompatible native node module: ${message}`
260
266
  };
261
267
  };
262
268
  const getModuleSyntaxError = () => {
263
269
  return {
264
- message: `ES Modules are not supported in electron`,
265
- code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
270
+ code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
271
+ message: `ES Modules are not supported in electron`
266
272
  };
267
273
  };
268
274
  const getHelpfulChildProcessError = (stdout, stderr) => {
@@ -281,8 +287,8 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
281
287
  rest
282
288
  } = getDetails(lines);
283
289
  return {
284
- message: actualMessage,
285
290
  code: '',
291
+ message: actualMessage,
286
292
  stack: rest
287
293
  };
288
294
  };
@@ -292,8 +298,8 @@ class IpcError extends VError {
292
298
  if (stdout || stderr) {
293
299
  // @ts-ignore
294
300
  const {
295
- message,
296
301
  code,
302
+ message,
297
303
  stack
298
304
  } = getHelpfulChildProcessError(stdout, stderr);
299
305
  const cause = new Error(message);
@@ -354,8 +360,8 @@ const wrap$f = global => {
354
360
  };
355
361
  const waitForFirstMessage = async port => {
356
362
  const {
357
- resolve,
358
- promise
363
+ promise,
364
+ resolve
359
365
  } = Promise.withResolvers();
360
366
  port.addEventListener('message', resolve, {
361
367
  once: true
@@ -375,8 +381,8 @@ const listen$6 = async () => {
375
381
  const type = firstMessage.params[0];
376
382
  if (type === 'message-port') {
377
383
  parentIpc.send({
378
- jsonrpc: '2.0',
379
384
  id: firstMessage.id,
385
+ jsonrpc: '2.0',
380
386
  result: null
381
387
  });
382
388
  parentIpc.dispose();
@@ -433,8 +439,8 @@ const removeListener = (emitter, type, callback) => {
433
439
  };
434
440
  const getFirstEvent = (eventEmitter, eventMap) => {
435
441
  const {
436
- resolve,
437
- promise
442
+ promise,
443
+ resolve
438
444
  } = Promise.withResolvers();
439
445
  const listenerMap = Object.create(null);
440
446
  const cleanup = value => {
@@ -446,8 +452,8 @@ const getFirstEvent = (eventEmitter, eventMap) => {
446
452
  for (const [event, type] of Object.entries(eventMap)) {
447
453
  const listener = event => {
448
454
  cleanup({
449
- type,
450
- event
455
+ event,
456
+ type
451
457
  });
452
458
  };
453
459
  addListener(eventEmitter, event, listener);
@@ -457,8 +463,8 @@ const getFirstEvent = (eventEmitter, eventMap) => {
457
463
  };
458
464
  const Message$1 = 3;
459
465
  const create$5$1 = async ({
460
- messagePort,
461
- isMessagePortOpen
466
+ isMessagePortOpen,
467
+ messagePort
462
468
  }) => {
463
469
  if (!isMessagePort(messagePort)) {
464
470
  throw new IpcError('port must be of type MessagePort');
@@ -471,8 +477,8 @@ const create$5$1 = async ({
471
477
  });
472
478
  messagePort.start();
473
479
  const {
474
- type,
475
- event
480
+ event,
481
+ type
476
482
  } = await eventPromise;
477
483
  if (type !== Message$1) {
478
484
  throw new IpcError('Failed to wait for ipc message');
@@ -512,56 +518,14 @@ const IpcParentWithMessagePort$1 = {
512
518
  wrap: wrap$5
513
519
  };
514
520
 
515
- const Two = '2.0';
516
- const create$4$1 = (method, params) => {
517
- return {
518
- jsonrpc: Two,
519
- method,
520
- params
521
- };
522
- };
521
+ const Two$1 = '2.0';
523
522
  const callbacks = Object.create(null);
524
- const set$4 = (id, fn) => {
525
- callbacks[id] = fn;
526
- };
527
- const get$2 = id => {
523
+ const get$3 = id => {
528
524
  return callbacks[id];
529
525
  };
530
- const remove$1 = id => {
526
+ const remove$2 = id => {
531
527
  delete callbacks[id];
532
528
  };
533
- let id = 0;
534
- const create$3$1 = () => {
535
- return ++id;
536
- };
537
- const registerPromise = () => {
538
- const id = create$3$1();
539
- const {
540
- resolve,
541
- promise
542
- } = Promise.withResolvers();
543
- set$4(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
529
  class JsonRpcError extends Error {
566
530
  constructor(message) {
567
531
  super(message);
@@ -705,14 +669,14 @@ const warn = (...args) => {
705
669
  console.warn(...args);
706
670
  };
707
671
  const resolve = (id, response) => {
708
- const fn = get$2(id);
672
+ const fn = get$3(id);
709
673
  if (!fn) {
710
674
  console.log(response);
711
675
  warn(`callback ${id} may already be disposed`);
712
676
  return;
713
677
  }
714
678
  fn(response);
715
- remove$1(id);
679
+ remove$2(id);
716
680
  };
717
681
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
718
682
  const getErrorType = prettyError => {
@@ -757,7 +721,7 @@ const getErrorProperty = (error, prettyError) => {
757
721
  };
758
722
  const create$1$1 = (id, error) => {
759
723
  return {
760
- jsonrpc: Two,
724
+ jsonrpc: Two$1,
761
725
  id,
762
726
  error
763
727
  };
@@ -768,20 +732,20 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
768
732
  const errorProperty = getErrorProperty(error, prettyError);
769
733
  return create$1$1(id, errorProperty);
770
734
  };
771
- const create$7 = (message, result) => {
735
+ const create$6 = (message, result) => {
772
736
  return {
773
- jsonrpc: Two,
737
+ jsonrpc: Two$1,
774
738
  id: message.id,
775
739
  result: result ?? null
776
740
  };
777
741
  };
778
742
  const getSuccessResponse = (message, result) => {
779
743
  const resultProperty = result ?? null;
780
- return create$7(message, resultProperty);
744
+ return create$6(message, resultProperty);
781
745
  };
782
746
  const getErrorResponseSimple = (id, error) => {
783
747
  return {
784
- jsonrpc: Two,
748
+ jsonrpc: Two$1,
785
749
  id,
786
750
  error: {
787
751
  code: Custom,
@@ -868,29 +832,6 @@ const handleJsonRpcMessage = async (...args) => {
868
832
  }
869
833
  throw new JsonRpcError('unexpected message');
870
834
  };
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$5 = (ipc, method, ...params) => {
889
- return invokeHelper(ipc, method, params, false);
890
- };
891
- const invokeAndTransfer$3 = (ipc, method, ...params) => {
892
- return invokeHelper(ipc, method, params, true);
893
- };
894
835
 
895
836
  class CommandNotFoundError extends Error {
896
837
  constructor(command) {
@@ -913,24 +854,87 @@ const execute = (command, ...args) => {
913
854
  return fn(...args);
914
855
  };
915
856
 
857
+ const Two = '2.0';
858
+ const create$t = (method, params) => {
859
+ return {
860
+ jsonrpc: Two,
861
+ method,
862
+ params
863
+ };
864
+ };
865
+ const create$s = (id, method, params) => {
866
+ const message = {
867
+ id,
868
+ jsonrpc: Two,
869
+ method,
870
+ params
871
+ };
872
+ return message;
873
+ };
874
+ let id = 0;
875
+ const create$r = () => {
876
+ return ++id;
877
+ };
878
+
879
+ /* eslint-disable n/no-unsupported-features/es-syntax */
880
+
881
+ const registerPromise = map => {
882
+ const id = create$r();
883
+ const {
884
+ promise,
885
+ resolve
886
+ } = Promise.withResolvers();
887
+ map[id] = resolve;
888
+ return {
889
+ id,
890
+ promise
891
+ };
892
+ };
893
+
894
+ // @ts-ignore
895
+ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
896
+ const {
897
+ id,
898
+ promise
899
+ } = registerPromise(callbacks);
900
+ const message = create$s(id, method, params);
901
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
902
+ ipc.sendAndTransfer(message);
903
+ } else {
904
+ ipc.send(message);
905
+ }
906
+ const responseMessage = await promise;
907
+ return unwrapJsonRpcResult(responseMessage);
908
+ };
916
909
  const createRpc = ipc => {
910
+ const callbacks = Object.create(null);
911
+ ipc._resolve = (id, response) => {
912
+ const fn = callbacks[id];
913
+ if (!fn) {
914
+ console.warn(`callback ${id} may already be disposed`);
915
+ return;
916
+ }
917
+ fn(response);
918
+ delete callbacks[id];
919
+ };
917
920
  const rpc = {
921
+ async dispose() {
922
+ await ipc?.dispose();
923
+ },
924
+ invoke(method, ...params) {
925
+ return invokeHelper(callbacks, ipc, method, params, false);
926
+ },
927
+ invokeAndTransfer(method, ...params) {
928
+ return invokeHelper(callbacks, ipc, method, params, true);
929
+ },
918
930
  // @ts-ignore
919
931
  ipc,
920
932
  /**
921
933
  * @deprecated
922
934
  */
923
935
  send(method, ...params) {
924
- send(ipc, method, ...params);
925
- },
926
- invoke(method, ...params) {
927
- return invoke$5(ipc, method, ...params);
928
- },
929
- invokeAndTransfer(method, ...params) {
930
- return invokeAndTransfer$3(ipc, method, ...params);
931
- },
932
- async dispose() {
933
- await ipc?.dispose();
936
+ const message = create$t(method, params);
937
+ ipc.send(message);
934
938
  }
935
939
  };
936
940
  return rpc;
@@ -947,7 +951,7 @@ const logError = () => {
947
951
  const handleMessage = event => {
948
952
  const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
949
953
  const actualExecute = event?.target?.execute || execute;
950
- return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
954
+ return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
951
955
  };
952
956
  const handleIpc = ipc => {
953
957
  if ('addEventListener' in ipc) {
@@ -967,14 +971,14 @@ const listen$1 = async (module, options) => {
967
971
  };
968
972
  const create$e = async ({
969
973
  commandMap,
970
- messagePort,
971
- isMessagePortOpen
974
+ isMessagePortOpen,
975
+ messagePort
972
976
  }) => {
973
977
  // TODO create a commandMap per rpc instance
974
978
  register$4(commandMap);
975
979
  const rawIpc = await IpcParentWithMessagePort$1.create({
976
- messagePort,
977
- isMessagePortOpen
980
+ isMessagePortOpen,
981
+ messagePort
978
982
  });
979
983
  const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
980
984
  handleIpc(ipc);
@@ -987,13 +991,14 @@ const MessagePortRpcParent = {
987
991
  };
988
992
  const create$5 = async ({
989
993
  commandMap,
994
+ isMessagePortOpen = true,
990
995
  messagePort
991
996
  }) => {
992
997
  // TODO create a commandMap per rpc instance
993
998
  register$4(commandMap);
994
999
  const rawIpc = await IpcParentWithMessagePort$1.create({
995
- messagePort,
996
- isMessagePortOpen: true
1000
+ isMessagePortOpen,
1001
+ messagePort
997
1002
  });
998
1003
  const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
999
1004
  handleIpc(ipc);
@@ -1014,8 +1019,9 @@ const PlainMessagePortRpcParent = {
1014
1019
  __proto__: null,
1015
1020
  create: create$4
1016
1021
  };
1017
- const create$3 = async ({
1022
+ const create$3$1 = async ({
1018
1023
  commandMap,
1024
+ isMessagePortOpen,
1019
1025
  send
1020
1026
  }) => {
1021
1027
  const {
@@ -1025,14 +1031,15 @@ const create$3 = async ({
1025
1031
  await send(port1);
1026
1032
  return create$5({
1027
1033
  commandMap,
1034
+ isMessagePortOpen,
1028
1035
  messagePort: port2
1029
1036
  });
1030
1037
  };
1031
1038
  const TransferMessagePortRpcParent = {
1032
1039
  __proto__: null,
1033
- create: create$3
1040
+ create: create$3$1
1034
1041
  };
1035
- const create$6 = async ({
1042
+ const create$2$1 = async ({
1036
1043
  commandMap
1037
1044
  }) => {
1038
1045
  // TODO create a commandMap per rpc instance
@@ -1044,7 +1051,7 @@ const create$6 = async ({
1044
1051
  };
1045
1052
  const WebWorkerRpcClient = {
1046
1053
  __proto__: null,
1047
- create: create$6
1054
+ create: create$2$1
1048
1055
  };
1049
1056
  const createMockRpc = ({
1050
1057
  commandMap
@@ -1059,50 +1066,65 @@ const createMockRpc = ({
1059
1066
  return command(...params);
1060
1067
  };
1061
1068
  const mockRpc = {
1069
+ invocations,
1062
1070
  invoke,
1063
- invokeAndTransfer: invoke,
1064
- invocations
1071
+ invokeAndTransfer: invoke
1065
1072
  };
1066
1073
  return mockRpc;
1067
1074
  };
1068
1075
 
1069
- const Script = 2;
1076
+ const Div = 4;
1077
+ const Iframe = 68;
1070
1078
 
1071
- const DebugWorker = 55;
1072
1079
  const ExtensionHostWorker = 44;
1073
1080
  const RendererWorker$1 = 1;
1074
1081
 
1082
+ const SetDom2 = 'Viewlet.setDom2';
1083
+
1075
1084
  const rpcs$1 = Object.create(null);
1076
- const set$3 = (id, rpc) => {
1077
- if (rpcs$1[id]) {
1078
- throw new Error(`rpc with id ${id} is already registered`);
1079
- }
1085
+ const set$4 = (id, rpc) => {
1080
1086
  rpcs$1[id] = rpc;
1081
1087
  };
1082
- const get$1 = id => {
1088
+ const get$2 = id => {
1083
1089
  return rpcs$1[id];
1084
1090
  };
1091
+ const remove$1 = id => {
1092
+ delete rpcs$1[id];
1093
+ };
1085
1094
 
1086
- const create$2 = rpcId => {
1095
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
1096
+ const create$3 = rpcId => {
1087
1097
  return {
1088
1098
  async dispose() {
1089
- const rpc = get$1(rpcId);
1099
+ const rpc = get$2(rpcId);
1090
1100
  await rpc.dispose();
1091
1101
  },
1092
1102
  // @ts-ignore
1093
1103
  invoke(method, ...params) {
1094
- const rpc = get$1(rpcId);
1104
+ const rpc = get$2(rpcId);
1095
1105
  // @ts-ignore
1096
1106
  return rpc.invoke(method, ...params);
1097
1107
  },
1098
1108
  // @ts-ignore
1099
1109
  invokeAndTransfer(method, ...params) {
1100
- const rpc = get$1(rpcId);
1110
+ const rpc = get$2(rpcId);
1101
1111
  // @ts-ignore
1102
1112
  return rpc.invokeAndTransfer(method, ...params);
1103
1113
  },
1114
+ registerMockRpc(commandMap) {
1115
+ const mockRpc = createMockRpc({
1116
+ commandMap
1117
+ });
1118
+ set$4(rpcId, mockRpc);
1119
+ // @ts-ignore
1120
+ mockRpc[Symbol.dispose] = () => {
1121
+ remove$1(rpcId);
1122
+ };
1123
+ // @ts-ignore
1124
+ return mockRpc;
1125
+ },
1104
1126
  set(rpc) {
1105
- set$3(rpcId, rpc);
1127
+ set$4(rpcId, rpc);
1106
1128
  }
1107
1129
  };
1108
1130
  };
@@ -1110,419 +1132,25 @@ const create$2 = rpcId => {
1110
1132
  const {
1111
1133
  invoke: invoke$4,
1112
1134
  invokeAndTransfer: invokeAndTransfer$2,
1113
- set: set$2
1114
- } = create$2(ExtensionHostWorker);
1135
+ set: set$3
1136
+ } = create$3(ExtensionHostWorker);
1115
1137
 
1116
1138
  const {
1117
- dispose,
1118
1139
  invoke: invoke$3,
1119
1140
  invokeAndTransfer: invokeAndTransfer$1,
1120
- set: set$1
1121
- } = create$2(RendererWorker$1);
1122
- const searchFileHtml = async uri => {
1123
- return invoke$3('ExtensionHost.searchFileWithHtml', uri);
1124
- };
1125
- const getFilePathElectron = async file => {
1126
- return invoke$3('FileSystemHandle.getFilePathElectron', file);
1127
- };
1128
- /**
1129
- * @deprecated
1130
- */
1131
- const showContextMenu = async (x, y, id, ...args) => {
1132
- return invoke$3('ContextMenu.show', x, y, id, ...args);
1133
- };
1134
- const showContextMenu2 = async (uid, menuId, x, y, args) => {
1135
- number(uid);
1136
- number(menuId);
1137
- number(x);
1138
- number(y);
1139
- // @ts-ignore
1140
- await invoke$3('ContextMenu.show2', uid, menuId, x, y, args);
1141
- };
1142
- const getElectronVersion = async () => {
1143
- return invoke$3('Process.getElectronVersion');
1144
- };
1145
- const applyBulkReplacement = async bulkEdits => {
1146
- await invoke$3('BulkReplacement.applyBulkReplacement', bulkEdits);
1147
- };
1148
- const setColorTheme = async id => {
1149
- // @ts-ignore
1150
- return invoke$3(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
1151
- };
1152
- const getNodeVersion = async () => {
1153
- return invoke$3('Process.getNodeVersion');
1154
- };
1155
- const getChromeVersion = async () => {
1156
- return invoke$3('Process.getChromeVersion');
1157
- };
1158
- const getV8Version = async () => {
1159
- return invoke$3('Process.getV8Version');
1160
- };
1161
- const getFileHandles = async fileIds => {
1162
- const files = await invoke$3('FileSystemHandle.getFileHandles', fileIds);
1163
- return files;
1164
- };
1165
- const setWorkspacePath = async path => {
1166
- await invoke$3('Workspace.setPath', path);
1167
- };
1168
- const registerWebViewInterceptor = async (id, port) => {
1169
- await invokeAndTransfer$1('WebView.registerInterceptor', id, port);
1170
- };
1171
- const unregisterWebViewInterceptor = async id => {
1172
- await invoke$3('WebView.unregisterInterceptor', id);
1173
- };
1174
- const sendMessagePortToEditorWorker = async (port, rpcId) => {
1175
- const command = 'HandleMessagePort.handleMessagePort';
1176
- // @ts-ignore
1177
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1178
- };
1179
- const sendMessagePortToErrorWorker = async (port, rpcId) => {
1180
- const command = 'Errors.handleMessagePort';
1181
- // @ts-ignore
1182
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1183
- };
1184
- const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
1185
- const command = 'Markdown.handleMessagePort';
1186
- // @ts-ignore
1187
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
1188
- };
1189
- const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
1190
- const command = 'IconTheme.handleMessagePort';
1191
- // @ts-ignore
1192
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
1193
- };
1194
- const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1195
- const command = 'FileSystem.handleMessagePort';
1196
- // @ts-ignore
1197
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1198
- };
1199
- const readFile$1 = async uri => {
1200
- return invoke$3('FileSystem.readFile', uri);
1201
- };
1202
- const getWebViewSecret = async key => {
1203
- // @ts-ignore
1204
- return invoke$3('WebView.getSecret', key);
1205
- };
1206
- const setWebViewPort = async (uid, port, origin, portType) => {
1207
- return invokeAndTransfer$1('WebView.setPort', uid, port, origin, portType);
1208
- };
1209
- const setFocus = key => {
1210
- return invoke$3('Focus.setFocus', key);
1211
- };
1212
- const getFileIcon = async options => {
1213
- return invoke$3('IconTheme.getFileIcon', options);
1214
- };
1215
- const getColorThemeNames = async () => {
1216
- return invoke$3('ColorTheme.getColorThemeNames');
1217
- };
1218
- const disableExtension = async id => {
1219
- // @ts-ignore
1220
- return invoke$3('ExtensionManagement.disable', id);
1221
- };
1222
- const enableExtension = async id => {
1223
- // @ts-ignore
1224
- return invoke$3('ExtensionManagement.enable', id);
1225
- };
1226
- const handleDebugChange = async params => {
1227
- // @ts-ignore
1228
- return invoke$3('Run And Debug.handleChange', params);
1229
- };
1230
- const getFolderIcon = async options => {
1231
- return invoke$3('IconTheme.getFolderIcon', options);
1232
- };
1233
- const handleWorkspaceRefresh = async () => {
1234
- return invoke$3('Layout.handleWorkspaceRefresh');
1235
- };
1236
- const closeWidget = async widgetId => {
1237
- return invoke$3('Viewlet.closeWidget', widgetId);
1238
- };
1141
+ set: set$2
1142
+ } = create$3(RendererWorker$1);
1239
1143
  const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1240
1144
  const command = 'HandleMessagePort.handleMessagePort2';
1241
1145
  await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1242
1146
  };
1243
- const sendMessagePortToSearchProcess = async port => {
1244
- await invokeAndTransfer$1('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
1245
- };
1246
- const confirm = async (message, options) => {
1247
- // @ts-ignore
1248
- const result = await invoke$3('ConfirmPrompt.prompt', message, options);
1249
- return result;
1250
- };
1251
- const getRecentlyOpened = async () => {
1252
- return invoke$3(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1253
- };
1254
- const getKeyBindings = async () => {
1255
- return invoke$3('KeyBindingsInitial.getKeyBindings');
1256
- };
1257
- const writeClipBoardText = async text => {
1258
- await invoke$3('ClipBoard.writeText', /* text */text);
1259
- };
1260
- const readClipBoardText = async () => {
1261
- return invoke$3('ClipBoard.readText');
1262
- };
1263
- const writeClipBoardImage = async blob => {
1264
- // @ts-ignore
1265
- await invoke$3('ClipBoard.writeImage', /* text */blob);
1266
- };
1267
- const searchFileMemory = async uri => {
1268
- // @ts-ignore
1269
- return invoke$3('ExtensionHost.searchFileWithMemory', uri);
1270
- };
1271
- const searchFileFetch = async uri => {
1272
- return invoke$3('ExtensionHost.searchFileWithFetch', uri);
1273
- };
1274
- const showMessageBox = async options => {
1275
- return invoke$3('ElectronDialog.showMessageBox', options);
1276
- };
1277
- const handleDebugResumed = async params => {
1278
- await invoke$3('Run And Debug.handleResumed', params);
1279
- };
1280
- const openWidget = async name => {
1281
- await invoke$3('Viewlet.openWidget', name);
1282
- };
1283
- const getIcons = async requests => {
1284
- const icons = await invoke$3('IconTheme.getIcons', requests);
1285
- return icons;
1286
- };
1287
- const activateByEvent = event => {
1288
- return invoke$3('ExtensionHostManagement.activateByEvent', event);
1289
- };
1290
- const setAdditionalFocus = focusKey => {
1291
- // @ts-ignore
1292
- return invoke$3('Focus.setAdditionalFocus', focusKey);
1293
- };
1294
- const getActiveEditorId = () => {
1295
- // @ts-ignore
1296
- return invoke$3('GetActiveEditor.getActiveEditorId');
1297
- };
1298
- const getWorkspacePath = () => {
1299
- return invoke$3('Workspace.getPath');
1300
- };
1301
- const sendMessagePortToRendererProcess = async port => {
1302
- const command = 'HandleMessagePort.handleMessagePort';
1303
- // @ts-ignore
1304
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
1305
- };
1306
- const sendMessagePortToTextMeasurementWorker = async port => {
1307
- const command = 'TextMeasurement.handleMessagePort';
1308
- // @ts-ignore
1309
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToTextMeasurementWorker', port, command, 0);
1310
- };
1311
- const sendMessagePortToSourceControlWorker = async port => {
1312
- const command = 'SourceControl.handleMessagePort';
1313
- // @ts-ignore
1314
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToSourceControlWorker', port, command, 0);
1315
- };
1316
- const sendMessagePortToSharedProcess = async port => {
1317
- const command = 'HandleElectronMessagePort.handleElectronMessagePort';
1318
- // @ts-ignore
1319
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, 0);
1320
- };
1321
- const sendMessagePortToFileSystemProcess = async (port, rpcId) => {
1322
- const command = 'HandleMessagePortForFileSystemProcess.handleMessagePortForFileSystemProcess';
1323
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, rpcId);
1324
- };
1325
- const sendMessagePortToIframeWorker = async (port, rpcId) => {
1326
- const command = 'Iframes.handleMessagePort';
1327
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToIframeWorker', port, command, rpcId);
1328
- };
1329
- const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
1330
- const command = 'Extensions.handleMessagePort';
1331
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
1332
- };
1333
- const getPreference = async key => {
1334
- return await invoke$3('Preferences.get', key);
1335
- };
1336
- const getAllExtensions = async () => {
1337
- return invoke$3('ExtensionManagement.getAllExtensions');
1338
- };
1339
- const rerenderEditor = async key => {
1340
- // @ts-ignore
1341
- return invoke$3('Editor.rerender', key);
1342
- };
1343
- const handleDebugPaused = async params => {
1344
- await invoke$3('Run And Debug.handlePaused', params);
1345
- };
1346
- const openUri = async (uri, focus, options) => {
1347
- await invoke$3('Main.openUri', uri, focus, options);
1348
- };
1349
- const sendMessagePortToSyntaxHighlightingWorker = async port => {
1350
- await invokeAndTransfer$1(
1351
- // @ts-ignore
1352
- 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
1353
- };
1354
- const handleDebugScriptParsed = async script => {
1355
- await invoke$3('Run And Debug.handleScriptParsed', script);
1356
- };
1357
- const getWindowId = async () => {
1358
- return invoke$3('GetWindowId.getWindowId');
1359
- };
1360
- const getBlob = async uri => {
1361
- // @ts-ignore
1362
- return invoke$3('FileSystem.getBlob', uri);
1363
- };
1364
- const getExtensionCommands = async () => {
1365
- return invoke$3('ExtensionHost.getCommands');
1366
- };
1367
- const showErrorDialog = async errorInfo => {
1368
- // @ts-ignore
1369
- await invoke$3('ErrorHandling.showErrorDialog', errorInfo);
1370
- };
1371
- const getFolderSize = async uri => {
1372
- // @ts-ignore
1373
- return await invoke$3('FileSystem.getFolderSize', uri);
1374
- };
1375
- const getExtension = async id => {
1376
- // @ts-ignore
1377
- return invoke$3('ExtensionManagement.getExtension', id);
1378
- };
1379
- const getMarkdownDom = async html => {
1380
- // @ts-ignore
1381
- return invoke$3('Markdown.getVirtualDom', html);
1382
- };
1383
- const renderMarkdown = async (markdown, options) => {
1384
- // @ts-ignore
1385
- return invoke$3('Markdown.renderMarkdown', markdown, options);
1386
- };
1387
- const openNativeFolder = async uri => {
1388
- // @ts-ignore
1389
- await invoke$3('OpenNativeFolder.openNativeFolder', uri);
1390
- };
1391
- const uninstallExtension = async id => {
1392
- return invoke$3('ExtensionManagement.uninstall', id);
1393
- };
1394
- const installExtension = async id => {
1395
- // @ts-ignore
1396
- return invoke$3('ExtensionManagement.install', id);
1397
- };
1398
- const openExtensionSearch = async () => {
1399
- // @ts-ignore
1400
- return invoke$3('SideBar.openViewlet', 'Extensions');
1401
- };
1402
- const setExtensionsSearchValue = async searchValue => {
1403
- // @ts-ignore
1404
- return invoke$3('Extensions.handleInput', searchValue, Script);
1405
- };
1406
- const openExternal = async uri => {
1407
- // @ts-ignore
1408
- await invoke$3('Open.openExternal', uri);
1409
- };
1410
- const openUrl = async uri => {
1411
- // @ts-ignore
1412
- await invoke$3('Open.openUrl', uri);
1413
- };
1414
- const getAllPreferences = async () => {
1415
- // @ts-ignore
1416
- return invoke$3('Preferences.getAll');
1417
- };
1418
- const showSaveFilePicker = async () => {
1419
- // @ts-ignore
1420
- return invoke$3('FilePicker.showSaveFilePicker');
1421
- };
1422
- const getLogsDir = async () => {
1423
- // @ts-ignore
1424
- return invoke$3('PlatformPaths.getLogsDir');
1425
- };
1426
- const measureTextBlockHeight = async (actualInput, fontFamily, fontSize, lineHeightPx, width) => {
1427
- return invoke$3(`MeasureTextHeight.measureTextBlockHeight`, actualInput, fontFamily, fontSize, lineHeightPx, width);
1428
- };
1429
- const registerMockRpc = commandMap => {
1430
- const mockRpc = createMockRpc({
1431
- commandMap
1432
- });
1433
- set$1(mockRpc);
1434
- return mockRpc;
1435
- };
1436
1147
 
1437
1148
  const RendererWorker = {
1438
1149
  __proto__: null,
1439
- activateByEvent,
1440
- applyBulkReplacement,
1441
- closeWidget,
1442
- confirm,
1443
- disableExtension,
1444
- dispose,
1445
- enableExtension,
1446
- getActiveEditorId,
1447
- getAllExtensions,
1448
- getAllPreferences,
1449
- getBlob,
1450
- getChromeVersion,
1451
- getColorThemeNames,
1452
- getElectronVersion,
1453
- getExtension,
1454
- getExtensionCommands,
1455
- getFileHandles,
1456
- getFileIcon,
1457
- getFilePathElectron,
1458
- getFolderIcon,
1459
- getFolderSize,
1460
- getIcons,
1461
- getKeyBindings,
1462
- getLogsDir,
1463
- getMarkdownDom,
1464
- getNodeVersion,
1465
- getPreference,
1466
- getRecentlyOpened,
1467
- getV8Version,
1468
- getWebViewSecret,
1469
- getWindowId,
1470
- getWorkspacePath,
1471
- handleDebugChange,
1472
- handleDebugPaused,
1473
- handleDebugResumed,
1474
- handleDebugScriptParsed,
1475
- handleWorkspaceRefresh,
1476
- installExtension,
1477
1150
  invoke: invoke$3,
1478
1151
  invokeAndTransfer: invokeAndTransfer$1,
1479
- measureTextBlockHeight,
1480
- openExtensionSearch,
1481
- openExternal,
1482
- openNativeFolder,
1483
- openUri,
1484
- openUrl,
1485
- openWidget,
1486
- readClipBoardText,
1487
- readFile: readFile$1,
1488
- registerMockRpc,
1489
- registerWebViewInterceptor,
1490
- renderMarkdown,
1491
- rerenderEditor,
1492
- searchFileFetch,
1493
- searchFileHtml,
1494
- searchFileMemory,
1495
- sendMessagePortToEditorWorker,
1496
- sendMessagePortToErrorWorker,
1497
1152
  sendMessagePortToExtensionHostWorker,
1498
- sendMessagePortToExtensionManagementWorker,
1499
- sendMessagePortToFileSystemProcess,
1500
- sendMessagePortToFileSystemWorker,
1501
- sendMessagePortToIconThemeWorker,
1502
- sendMessagePortToIframeWorker,
1503
- sendMessagePortToMarkdownWorker,
1504
- sendMessagePortToRendererProcess,
1505
- sendMessagePortToSearchProcess,
1506
- sendMessagePortToSharedProcess,
1507
- sendMessagePortToSourceControlWorker,
1508
- sendMessagePortToSyntaxHighlightingWorker,
1509
- sendMessagePortToTextMeasurementWorker,
1510
- set: set$1,
1511
- setAdditionalFocus,
1512
- setColorTheme,
1513
- setExtensionsSearchValue,
1514
- setFocus,
1515
- setWebViewPort,
1516
- setWorkspacePath,
1517
- showContextMenu,
1518
- showContextMenu2,
1519
- showErrorDialog,
1520
- showMessageBox,
1521
- showSaveFilePicker,
1522
- uninstallExtension,
1523
- unregisterWebViewInterceptor,
1524
- writeClipBoardImage,
1525
- writeClipBoardText
1153
+ set: set$2
1526
1154
  };
1527
1155
 
1528
1156
  const getCredentialLess = locationHost => {
@@ -1837,7 +1465,7 @@ const getWebViewTitle = webView => {
1837
1465
  const state = {
1838
1466
  id: 0
1839
1467
  };
1840
- const create$1 = () => {
1468
+ const create$2 = () => {
1841
1469
  return ++state.id;
1842
1470
  };
1843
1471
 
@@ -1877,7 +1505,7 @@ const invoke = async (method, ...params) => {
1877
1505
  const registerProtocol = async () => {
1878
1506
  await invoke('WebViewServer.registerProtocol');
1879
1507
  };
1880
- const create = async (previewServerId, useNewWebViewHandler) => {
1508
+ const create$1 = async (previewServerId, useNewWebViewHandler) => {
1881
1509
  await invoke('WebViewServer.create', previewServerId, useNewWebViewHandler);
1882
1510
  };
1883
1511
  const start = async (previewServerId, webViewPort) => {
@@ -1895,7 +1523,7 @@ const setHandler = async (previewServerId, frameAncestors, webViewRoot, contentS
1895
1523
 
1896
1524
  const register$3 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, webViewId, remotePathPrefix, useNewWebViewHandler) => {
1897
1525
  await registerProtocol();
1898
- await create(previewServerId, useNewWebViewHandler); // TODO move this up
1526
+ await create$1(previewServerId, useNewWebViewHandler); // TODO move this up
1899
1527
 
1900
1528
  // TODO send info to electron which domain maps to which webview root.
1901
1529
  // for example, video-preview maps to domain lvce-oss-webview://video-preview
@@ -1911,7 +1539,7 @@ const register$2 = async (previewServerId, webViewPort, frameAncestors, webViewR
1911
1539
  // TODO pass webview root, so that only these resources can be accessed
1912
1540
  // TODO pass csp configuration to server
1913
1541
  // TODO pass coop / coep configuration to server
1914
- await create(previewServerId, useNewWebViewHandler); // TODO move this up
1542
+ await create$1(previewServerId, useNewWebViewHandler); // TODO move this up
1915
1543
  await start(previewServerId, webViewPort); // TODO move this up
1916
1544
  await (useNewWebViewHandler ? setInfo2({
1917
1545
  contentSecurityPolicy: csp,
@@ -1993,7 +1621,7 @@ const create2 = async ({
1993
1621
  port1,
1994
1622
  port2
1995
1623
  } = getPortTuple();
1996
- const portId = create$1();
1624
+ const portId = create$2();
1997
1625
  const remotePathPrefix = '/remote';
1998
1626
  await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix);
1999
1627
  await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
@@ -2079,10 +1707,10 @@ const getProtocol = uri => {
2079
1707
  };
2080
1708
 
2081
1709
  const rpcs = Object.create(null);
2082
- const set = (id, rpc) => {
1710
+ const set$1 = (id, rpc) => {
2083
1711
  rpcs[id] = rpc;
2084
1712
  };
2085
- const get = id => {
1713
+ const get$1 = id => {
2086
1714
  return rpcs[id];
2087
1715
  };
2088
1716
  const getAll$1 = () => {
@@ -2098,7 +1726,7 @@ const getAll$1 = () => {
2098
1726
 
2099
1727
  const getRemoteUrlForWebView = async options => {
2100
1728
  object(options);
2101
- const webView = get(options.id);
1729
+ const webView = get$1(options.id);
2102
1730
  object(webView);
2103
1731
  const rpcPromise = createWebViewConnection(webView.webViewUid, webView.origin);
2104
1732
  const blobPromise = invoke$3('FileSystem.getBlob', options.uri);
@@ -2222,7 +1850,7 @@ const createWebWorkerRpc2 = async (rpcInfo, webView, savedState, uri, portId, we
2222
1850
  webViewId: webView.id,
2223
1851
  webViewUid
2224
1852
  };
2225
- set(portId, webViewInfo);
1853
+ set$1(portId, webViewInfo);
2226
1854
 
2227
1855
  // TODO this connection might not be needed
2228
1856
  await createWebViewConnection(webViewUid, origin);
@@ -2286,7 +1914,7 @@ const createWebViewRpc$1 = async (rpcInfo, webView, savedState, uri, portId, web
2286
1914
  webViewId: webView.id,
2287
1915
  webViewUid
2288
1916
  };
2289
- set(portId, webViewInfo);
1917
+ set$1(portId, webViewInfo);
2290
1918
  await rpc.invoke('LoadFile.loadFile', rpcInfo.url);
2291
1919
 
2292
1920
  // TODO this connection might not be needed
@@ -2397,7 +2025,7 @@ const create3 = async ({
2397
2025
 
2398
2026
  // TODO remove this
2399
2027
  await invoke$2('ExtensionHostManagement.activateByEvent', `onWebView:${webViewId}`);
2400
- const portId = create$1();
2028
+ const portId = create$2();
2401
2029
  const remotePathPrefix = '/remote';
2402
2030
  await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix, useNewWebViewHandler);
2403
2031
  await createAndLoadWebView(id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
@@ -2426,6 +2054,137 @@ const create3 = async ({
2426
2054
  };
2427
2055
  };
2428
2056
 
2057
+ const toCommandId = key => {
2058
+ const dotIndex = key.indexOf('.');
2059
+ return key.slice(dotIndex + 1);
2060
+ };
2061
+ const create = () => {
2062
+ const states = Object.create(null);
2063
+ const commandMapRef = {};
2064
+ return {
2065
+ clear() {
2066
+ for (const key of Object.keys(states)) {
2067
+ delete states[key];
2068
+ }
2069
+ },
2070
+ diff(uid, modules, numbers) {
2071
+ const {
2072
+ newState,
2073
+ oldState
2074
+ } = states[uid];
2075
+ const diffResult = [];
2076
+ for (let i = 0; i < modules.length; i++) {
2077
+ const fn = modules[i];
2078
+ if (!fn(oldState, newState)) {
2079
+ diffResult.push(numbers[i]);
2080
+ }
2081
+ }
2082
+ return diffResult;
2083
+ },
2084
+ dispose(uid) {
2085
+ delete states[uid];
2086
+ },
2087
+ get(uid) {
2088
+ return states[uid];
2089
+ },
2090
+ getCommandIds() {
2091
+ const keys = Object.keys(commandMapRef);
2092
+ const ids = keys.map(toCommandId);
2093
+ return ids;
2094
+ },
2095
+ getKeys() {
2096
+ return Object.keys(states).map(key => {
2097
+ return Number.parseInt(key);
2098
+ });
2099
+ },
2100
+ registerCommands(commandMap) {
2101
+ Object.assign(commandMapRef, commandMap);
2102
+ },
2103
+ set(uid, oldState, newState) {
2104
+ states[uid] = {
2105
+ newState,
2106
+ oldState
2107
+ };
2108
+ },
2109
+ wrapCommand(fn) {
2110
+ const wrapped = async (uid, ...args) => {
2111
+ const {
2112
+ newState,
2113
+ oldState
2114
+ } = states[uid];
2115
+ const newerState = await fn(newState, ...args);
2116
+ if (oldState === newerState || newState === newerState) {
2117
+ return;
2118
+ }
2119
+ const latestOld = states[uid];
2120
+ const latestNew = {
2121
+ ...latestOld.newState,
2122
+ ...newerState
2123
+ };
2124
+ states[uid] = {
2125
+ newState: latestNew,
2126
+ oldState: latestOld.oldState
2127
+ };
2128
+ };
2129
+ return wrapped;
2130
+ },
2131
+ wrapGetter(fn) {
2132
+ const wrapped = (uid, ...args) => {
2133
+ const {
2134
+ newState
2135
+ } = states[uid];
2136
+ return fn(newState, ...args);
2137
+ };
2138
+ return wrapped;
2139
+ }
2140
+ };
2141
+ };
2142
+
2143
+ const {
2144
+ diff,
2145
+ get,
2146
+ getCommandIds,
2147
+ set,
2148
+ wrapCommand} = create();
2149
+
2150
+ const create4 = (id, uri, x, y, width, height, platform, assetDir) => {
2151
+ number(platform);
2152
+ string(assetDir);
2153
+ const state = {
2154
+ assetDir,
2155
+ credentialless: true,
2156
+ csp: '',
2157
+ height,
2158
+ id,
2159
+ iframeSrc: '',
2160
+ origin: '',
2161
+ platform,
2162
+ portId: 0,
2163
+ previewServerId: 1,
2164
+ sandbox: [],
2165
+ srcDoc: '',
2166
+ uri,
2167
+ webViewScheme: '',
2168
+ width,
2169
+ x: x - 1,
2170
+ y
2171
+ };
2172
+ set(state.id, state, state);
2173
+ };
2174
+
2175
+ const isEqual = (oldState, newState) => {
2176
+ return oldState === newState;
2177
+ };
2178
+
2179
+ const RenderItems = 1;
2180
+
2181
+ const modules = [isEqual];
2182
+ const numbers = [RenderItems];
2183
+
2184
+ const diff2 = uid => {
2185
+ return diff(uid, modules, numbers);
2186
+ };
2187
+
2429
2188
  const executeCommand = (method, ...params) => {
2430
2189
  // @ts-ignore
2431
2190
  return invoke$2('ExecuteExternalCommand.executeExternalCommand', method, ...params);
@@ -2455,7 +2214,7 @@ const handleMessagePort2 = async (port, rpcId) => {
2455
2214
  messagePort: port
2456
2215
  });
2457
2216
  if (rpcId) {
2458
- set$3(rpcId, rpc);
2217
+ set$4(rpcId, rpc);
2459
2218
  }
2460
2219
  };
2461
2220
 
@@ -2467,7 +2226,83 @@ const initialize = async platform => {
2467
2226
  await sendMessagePortToExtensionHostWorker(port, 0);
2468
2227
  }
2469
2228
  });
2470
- set$2(rpc);
2229
+ set$3(rpc);
2230
+ };
2231
+
2232
+ const loadContent = async (state, savedState) => {
2233
+ // @ts-ignore
2234
+ const {
2235
+ assetDir,
2236
+ id,
2237
+ platform,
2238
+ uri,
2239
+ webViewScheme
2240
+ } = state;
2241
+ await invoke$4('WebView.create3', {
2242
+ assetDir,
2243
+ id,
2244
+ platform,
2245
+ uri,
2246
+ useNewWebViewHandler: true,
2247
+ webViewScheme
2248
+ });
2249
+
2250
+ // TODO get iframe src
2251
+ // TODO load webview props and register protocol
2252
+ return {
2253
+ ...state
2254
+ };
2255
+ };
2256
+
2257
+ const renderItems = (oldState, newState) => {
2258
+ const {
2259
+ id
2260
+ } = newState;
2261
+ const dom = [{
2262
+ childCount: 1,
2263
+ type: Div
2264
+ }, {
2265
+ childCount: 0,
2266
+ src: 'https://example.com',
2267
+ // @ts-ignore
2268
+ type: Iframe
2269
+ }];
2270
+ return [SetDom2, id, dom];
2271
+ };
2272
+
2273
+ const getRenderer = diffType => {
2274
+ switch (diffType) {
2275
+ case RenderItems:
2276
+ return renderItems;
2277
+ default:
2278
+ throw new Error('unknown renderer');
2279
+ }
2280
+ };
2281
+
2282
+ const applyRender = (oldState, newState, diffResult) => {
2283
+ const commands = [];
2284
+ for (const item of diffResult) {
2285
+ const fn = getRenderer(item);
2286
+ const result = fn(oldState, newState);
2287
+ if (result.length > 0) {
2288
+ commands.push(result);
2289
+ }
2290
+ }
2291
+ return commands;
2292
+ };
2293
+
2294
+ const render2 = (uid, diffResult) => {
2295
+ const {
2296
+ newState,
2297
+ oldState
2298
+ } = get(uid);
2299
+ set(uid, newState, newState);
2300
+ const commands = applyRender(oldState, newState, diffResult);
2301
+ return commands;
2302
+ };
2303
+
2304
+ const renderEventListeners = () => {
2305
+ return [];
2471
2306
  };
2472
2307
 
2473
2308
  const saveState = async () => {
@@ -2500,19 +2335,29 @@ const commandMap = {
2500
2335
  'Iframes.initialize': initialize,
2501
2336
  'WebView.create2': create2,
2502
2337
  'WebView.create3': create3,
2338
+ 'WebView.create4': create4,
2339
+ 'WebView.diff2': diff2,
2503
2340
  'WebView.executeExternalCommand': executeCommand,
2341
+ 'WebView.getCommandIds': getCommandIds,
2504
2342
  'WebView.getSecret': getSecret,
2505
2343
  'WebView.getWebViewInfo': getWebViewInfo,
2344
+ 'WebView.loadContent': wrapCommand(loadContent),
2506
2345
  'WebView.registerInterceptor': registerInterceptor,
2346
+ 'WebView.render2': render2,
2347
+ 'WebView.renderEventListeners': renderEventListeners,
2507
2348
  'WebView.saveState': saveState,
2508
2349
  'WebView.unregisterInterceptor': unregisterInterceptor
2509
2350
  };
2510
2351
 
2511
- const listen = async () => {
2352
+ const initializeRendererWorker = async () => {
2512
2353
  const rpc = await WebWorkerRpcClient.create({
2513
2354
  commandMap: commandMap
2514
2355
  });
2515
- set$1(rpc);
2356
+ set$2(rpc);
2357
+ };
2358
+
2359
+ const listen = async () => {
2360
+ await initializeRendererWorker();
2516
2361
  };
2517
2362
 
2518
2363
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/iframe-worker",
3
- "version": "6.3.0",
3
+ "version": "6.5.0",
4
4
  "description": "Web Worker to manage creation and lifecycle of iframes in Lvce Editor",
5
5
  "keywords": [
6
6
  "iframe"