@lvce-editor/embeds-worker 3.0.0 → 4.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.
package/README.md CHANGED
@@ -1 +1,16 @@
1
- # embeds-worker
1
+ # Embeds Worker
2
+
3
+ Web Worker for the embeds functionality in LVCE Editor.
4
+
5
+ ## Contributing
6
+
7
+ ```sh
8
+ git clone git@github.com:lvce-editor/embeds-worker.git &&
9
+ cd embeds-worker &&
10
+ npm ci &&
11
+ npm test
12
+ ```
13
+
14
+ ## Gitpod
15
+
16
+ [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/lvce-editor/embeds)
@@ -472,7 +472,7 @@ const create$4 = (method, params) => {
472
472
  };
473
473
  };
474
474
  const callbacks = Object.create(null);
475
- const set$3 = (id, fn) => {
475
+ const set$2 = (id, fn) => {
476
476
  callbacks[id] = fn;
477
477
  };
478
478
  const get$1 = id => {
@@ -491,7 +491,7 @@ const registerPromise = () => {
491
491
  resolve,
492
492
  promise
493
493
  } = Promise.withResolvers();
494
- set$3(id, resolve);
494
+ set$2(id, resolve);
495
495
  return {
496
496
  id,
497
497
  promise
@@ -667,6 +667,17 @@ const getErrorType = prettyError => {
667
667
  }
668
668
  return undefined;
669
669
  };
670
+ const isAlreadyStack = line => {
671
+ return line.trim().startsWith('at ');
672
+ };
673
+ const getStack = prettyError => {
674
+ const stackString = prettyError.stack || '';
675
+ const newLineIndex = stackString.indexOf('\n');
676
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
677
+ return stackString.slice(newLineIndex + 1);
678
+ }
679
+ return stackString;
680
+ };
670
681
  const getErrorProperty = (error, prettyError) => {
671
682
  if (error && error.code === E_COMMAND_NOT_FOUND) {
672
683
  return {
@@ -679,7 +690,7 @@ const getErrorProperty = (error, prettyError) => {
679
690
  code: Custom,
680
691
  message: prettyError.message,
681
692
  data: {
682
- stack: prettyError.stack,
693
+ stack: getStack(prettyError),
683
694
  codeFrame: prettyError.codeFrame,
684
695
  type: getErrorType(prettyError),
685
696
  code: prettyError.code,
@@ -802,7 +813,7 @@ const send = (transport, method, ...params) => {
802
813
  const message = create$4(method, params);
803
814
  transport.send(message);
804
815
  };
805
- const invoke$3 = (ipc, method, ...params) => {
816
+ const invoke$2 = (ipc, method, ...params) => {
806
817
  return invokeHelper(ipc, method, params, false);
807
818
  };
808
819
  const invokeAndTransfer$1 = (ipc, method, ...params) => {
@@ -835,7 +846,7 @@ const createRpc = ipc => {
835
846
  send(ipc, method, ...params);
836
847
  },
837
848
  invoke(method, ...params) {
838
- return invoke$3(ipc, method, ...params);
849
+ return invoke$2(ipc, method, ...params);
839
850
  },
840
851
  invokeAndTransfer(method, ...params) {
841
852
  return invokeAndTransfer$1(ipc, method, ...params);
@@ -912,7 +923,7 @@ const WebWorkerRpcClient = {
912
923
  };
913
924
 
914
925
  const rpcs = Object.create(null);
915
- const set$7 = (id, rpc) => {
926
+ const set$a = (id, rpc) => {
916
927
  rpcs[id] = rpc;
917
928
  };
918
929
  const get = id => {
@@ -936,46 +947,46 @@ const create = rpcId => {
936
947
  return rpc.invokeAndTransfer(method, ...params);
937
948
  },
938
949
  set(rpc) {
939
- set$7(rpcId, rpc);
950
+ set$a(rpcId, rpc);
940
951
  }
941
952
  };
942
953
  };
943
- const MainProcess$1 = -5;
944
954
  const RendererWorker$1 = 1;
955
+ const EmbedsProcess$1 = 207;
945
956
  const {
946
- invoke: invoke$5,
947
- set: set$5
948
- } = create(MainProcess$1);
957
+ invoke: invoke$8,
958
+ set: set$8
959
+ } = create(EmbedsProcess$1);
949
960
  const EmbedsProcess = {
950
961
  __proto__: null,
951
- invoke: invoke$5,
952
- set: set$5
962
+ invoke: invoke$8,
963
+ set: set$8
953
964
  };
954
965
  const {
955
- invoke: invoke$2,
956
- invokeAndTransfer: invokeAndTransfer$2,
957
- set: set$2
966
+ invoke: invoke$5,
967
+ invokeAndTransfer: invokeAndTransfer$5,
968
+ set: set$5
958
969
  } = create(RendererWorker$1);
959
970
  const RendererWorker = {
960
971
  __proto__: null,
961
- invoke: invoke$2,
962
- invokeAndTransfer: invokeAndTransfer$2,
963
- set: set$2
972
+ invoke: invoke$5,
973
+ invokeAndTransfer: invokeAndTransfer$5,
974
+ set: set$5
964
975
  };
965
976
 
966
977
  const {
967
978
  set: set$1,
968
979
  invoke: invoke$1} = EmbedsProcess;
969
980
 
981
+ const ERR_ABORTED = 'ERR_ABORTED';
982
+ const ERR_FAILED = 'ERR_FAILED';
983
+
970
984
  const {
971
985
  invoke,
972
986
  set,
973
987
  invokeAndTransfer
974
988
  } = RendererWorker;
975
989
 
976
- const ERR_ABORTED = 'ERR_ABORTED';
977
- const ERR_FAILED = 'ERR_FAILED';
978
-
979
990
  const createWebContentsView = async (restoreId, fallThroughKeyBindings) => {
980
991
  // @ts-ignore
981
992
  const id = await invoke$1('ElectronWebContentsView.createWebContentsView', restoreId, fallThroughKeyBindings);
@@ -985,7 +996,6 @@ const disposeWebContentsView = id => {
985
996
  return invoke$1('ElectronWebContentsView.disposeWebContentsView', id);
986
997
  };
987
998
  const resizeWebContentsView = (id, x, y, width, height) => {
988
- // @ts-ignore
989
999
  return invoke$1('ElectronWebContentsView.resizeBrowserView', id, x, y, width, height);
990
1000
  };
991
1001
  const setIframeSrcFallback = async (id, error) => {
@@ -993,12 +1003,10 @@ const setIframeSrcFallback = async (id, error) => {
993
1003
  code,
994
1004
  message
995
1005
  } = error;
996
- // @ts-ignore
997
1006
  await invoke$1('ElectronWebContentsView.setIframeSrcFallback', id, code, message);
998
1007
  };
999
1008
  const setIframeSrc = async (id, iframeSrc) => {
1000
1009
  try {
1001
- // @ts-ignore
1002
1010
  await invoke$1('ElectronWebContentsView.setIframeSrc', id, iframeSrc);
1003
1011
  } catch (error) {
1004
1012
  console.log({
@@ -1006,11 +1014,13 @@ const setIframeSrc = async (id, iframeSrc) => {
1006
1014
  });
1007
1015
  // TODO send error back to embeds worker,
1008
1016
  // embeds worker decides how to handle error
1017
+
1009
1018
  // @ts-ignore
1010
1019
  if (error && error.code === ERR_ABORTED) {
1011
1020
  console.info(`[embeds worker] navigation to ${iframeSrc} aborted`);
1012
1021
  return;
1013
1022
  }
1023
+
1014
1024
  // @ts-ignore
1015
1025
  if (error && error.code === ERR_FAILED) {
1016
1026
  console.info(`[embeds worker] navigation to ${iframeSrc} canceled`);
@@ -1025,63 +1035,49 @@ const setIframeSrc = async (id, iframeSrc) => {
1025
1035
  }
1026
1036
  };
1027
1037
  const focus = id => {
1028
- // @ts-ignore
1029
1038
  return invoke$1('ElectronWebContentsView.focus', id);
1030
1039
  };
1031
1040
  const openDevtools = id => {
1032
- // @ts-ignore
1033
1041
  return invoke$1('ElectronWebContentsView.openDevtools', id);
1034
1042
  };
1035
1043
  const reload = id => {
1036
- // @ts-ignore
1037
1044
  return invoke$1('ElectronWebContentsView.reload', id);
1038
1045
  };
1039
1046
  const show = id => {
1040
- // @ts-ignore
1041
1047
  return invoke$1('ElectronWebContentsView.show', id);
1042
1048
  };
1043
1049
  const hide = id => {
1044
- // @ts-ignore
1045
1050
  return invoke$1('ElectronWebContentsView.hide', id);
1046
1051
  };
1047
1052
  const forward = id => {
1048
- // @ts-ignore
1049
1053
  return invoke$1('ElectronWebContentsView.forward', id);
1050
1054
  };
1051
1055
  const backward = id => {
1052
- // @ts-ignore
1053
1056
  return invoke$1('ElectronWebContentsView.backward', id);
1054
1057
  };
1055
1058
  const getDomTree = id => {
1056
- // @ts-ignore
1057
1059
  return invoke$1('ElectronWebContentsView.getDomTree', id);
1058
1060
  };
1059
1061
  const insertCss = (id, css) => {
1060
- // @ts-ignore
1061
1062
  return invoke$1('ElectronWebContentsView.insertCss', id, css);
1062
1063
  };
1063
1064
  const insertJavaScript = (id, code) => {
1064
- // @ts-ignore
1065
1065
  return invoke$1('ElectronWebContentsView.insertJavaScript', id, code);
1066
1066
  };
1067
1067
  const cancelNavigation = id => {
1068
- // @ts-ignore
1069
1068
  return invoke$1('ElectronWebContentsView.cancelNavigation', id);
1070
1069
  };
1071
1070
  const inspectElement = (id, x, y) => {
1072
- // @ts-ignore
1073
1071
  return invoke$1('ElectronWebContentsView.inspectElement', id, x, y);
1074
1072
  };
1075
1073
  const copyImageAt = (id, x, y) => {
1076
- // @ts-ignore
1077
1074
  return invoke$1('ElectronWebContentsView.copyImageAt', id, x, y);
1078
1075
  };
1079
- const setFallthroughKeyBindings = (id, fallthroughKeybindings) => {
1076
+ const setFallthroughKeyBindings = async (id, fallthroughKeybindings) => {
1080
1077
  // TODO
1081
1078
  // return EmbedsProcess.invoke('ElectronWebContentsView.setFallthroughKeyBindings', id, fallthroughKeybindings)
1082
1079
  };
1083
1080
  const getStats = (id, fallthroughKeybindings) => {
1084
- // @ts-ignore
1085
1081
  return invoke$1('ElectronWebContentsView.getStats', id, fallthroughKeybindings);
1086
1082
  };
1087
1083
  const forwardEvent = key => (id, ...args) => {
@@ -1093,7 +1089,7 @@ const handleWillNavigate = forwardEvent('ElectronBrowserView.handleWillNavigate'
1093
1089
  const handleContextMenu = forwardEvent('ElectronBrowserView.handleContextMenu');
1094
1090
 
1095
1091
  const exit = () => {
1096
- self.close();
1092
+ globalThis.close();
1097
1093
  };
1098
1094
 
1099
1095
  const getPortTuple = () => {
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@lvce-editor/embeds-worker",
3
- "version": "3.0.0",
4
- "description": "",
5
- "main": "dist/embedsWorkerMain.js",
3
+ "version": "4.0.0",
4
+ "description": "Web Worker to manage electron webcontent views in Lvce Editor",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git@github.com:lvce-editor/embeds-worker.git"
8
+ },
9
+ "license": "MIT",
10
+ "author": "Lvce Editor",
6
11
  "type": "module",
7
- "keywords": [],
8
- "author": "",
9
- "license": "MIT"
12
+ "main": "dist/embedsWorkerMain.js"
10
13
  }