@lvce-editor/panel-worker 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -604,7 +604,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
604
604
  const errorProperty = getErrorProperty(error, prettyError);
605
605
  return create$1$1(id, errorProperty);
606
606
  };
607
- const create$7 = (message, result) => {
607
+ const create$8 = (message, result) => {
608
608
  return {
609
609
  jsonrpc: Two$1,
610
610
  id: message.id,
@@ -613,7 +613,7 @@ const create$7 = (message, result) => {
613
613
  };
614
614
  const getSuccessResponse = (message, result) => {
615
615
  const resultProperty = result ?? null;
616
- return create$7(message, resultProperty);
616
+ return create$8(message, resultProperty);
617
617
  };
618
618
  const getErrorResponseSimple = (id, error) => {
619
619
  return {
@@ -707,7 +707,7 @@ const handleJsonRpcMessage = async (...args) => {
707
707
 
708
708
  const Two = '2.0';
709
709
 
710
- const create$6 = (method, params) => {
710
+ const create$7 = (method, params) => {
711
711
  return {
712
712
  jsonrpc: Two,
713
713
  method,
@@ -715,7 +715,7 @@ const create$6 = (method, params) => {
715
715
  };
716
716
  };
717
717
 
718
- const create$5 = (id, method, params) => {
718
+ const create$6 = (id, method, params) => {
719
719
  const message = {
720
720
  id,
721
721
  jsonrpc: Two,
@@ -726,12 +726,12 @@ const create$5 = (id, method, params) => {
726
726
  };
727
727
 
728
728
  let id = 0;
729
- const create$4 = () => {
729
+ const create$5 = () => {
730
730
  return ++id;
731
731
  };
732
732
 
733
733
  const registerPromise = map => {
734
- const id = create$4();
734
+ const id = create$5();
735
735
  const {
736
736
  promise,
737
737
  resolve
@@ -749,7 +749,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
749
749
  id,
750
750
  promise
751
751
  } = registerPromise(callbacks);
752
- const message = create$5(id, method, params);
752
+ const message = create$6(id, method, params);
753
753
  if (useSendAndTransfer && ipc.sendAndTransfer) {
754
754
  ipc.sendAndTransfer(message);
755
755
  } else {
@@ -785,7 +785,7 @@ const createRpc = ipc => {
785
785
  * @deprecated
786
786
  */
787
787
  send(method, ...params) {
788
- const message = create$6(method, params);
788
+ const message = create$7(method, params);
789
789
  ipc.send(message);
790
790
  }
791
791
  };
@@ -825,7 +825,7 @@ const listen$1 = async (module, options) => {
825
825
  return ipc;
826
826
  };
827
827
 
828
- const create$3 = async ({
828
+ const create$4 = async ({
829
829
  commandMap
830
830
  }) => {
831
831
  // TODO create a commandMap per rpc instance
@@ -877,7 +877,7 @@ const remove = id => {
877
877
  };
878
878
 
879
879
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
880
- const create$2 = rpcId => {
880
+ const create$3 = rpcId => {
881
881
  return {
882
882
  async dispose() {
883
883
  const rpc = get$1(rpcId);
@@ -914,14 +914,15 @@ const create$2 = rpcId => {
914
914
  };
915
915
 
916
916
  const {
917
+ invoke,
917
918
  set: set$1
918
- } = create$2(RendererWorker);
919
+ } = create$3(RendererWorker);
919
920
 
920
921
  const toCommandId = key => {
921
922
  const dotIndex = key.indexOf('.');
922
923
  return key.slice(dotIndex + 1);
923
924
  };
924
- const create$1 = () => {
925
+ const create$2 = () => {
925
926
  const states = Object.create(null);
926
927
  const commandMapRef = {};
927
928
  return {
@@ -1013,21 +1014,26 @@ const {
1013
1014
  set,
1014
1015
  wrapCommand,
1015
1016
  wrapGetter
1016
- } = create$1();
1017
+ } = create$2();
1017
1018
 
1018
- const create = (uid, uri, x, y, width, height, platform, assetDir) => {
1019
+ const create$1 = (uid, uri, x, y, width, height, platform, assetDir) => {
1019
1020
  const state = {
1020
1021
  actionsUid: 0,
1021
1022
  assetDir,
1022
1023
  badgeCounts: {},
1023
1024
  childUid: 0,
1025
+ currentViewletId: '',
1024
1026
  errorCount: 0,
1027
+ height: 0,
1025
1028
  initial: true,
1026
1029
  platform,
1027
1030
  selectedIndex: -1,
1028
1031
  uid,
1029
1032
  views: [],
1030
- warningCount: 0
1033
+ warningCount: 0,
1034
+ width: 0,
1035
+ x: 0,
1036
+ y: 0
1031
1037
  };
1032
1038
  set(uid, state, state);
1033
1039
  };
@@ -1062,12 +1068,99 @@ const diff2 = uid => {
1062
1068
  return result;
1063
1069
  };
1064
1070
 
1065
- const loadContent = async state => {
1071
+ const DebugConsole = 'Debug Console';
1072
+ const Output = 'Output';
1073
+ const Problems = 'Problems';
1074
+ const Terminals = 'Terminals';
1075
+
1076
+ const getPanelViews = () => {
1077
+ const views = [Problems, Output, DebugConsole, Terminals];
1078
+ return views;
1079
+ };
1080
+
1081
+ let idCounter = 0;
1082
+ const create = () => {
1083
+ idCounter++;
1084
+ return idCounter;
1085
+ };
1086
+
1087
+ const getSavedViewletId = savedState => {
1088
+ if (savedState && savedState.currentViewletId) {
1089
+ return savedState.currentViewletId || Problems;
1090
+ }
1091
+ return Problems;
1092
+ };
1093
+ const loadContent = (state, savedState) => {
1094
+ const savedViewletId = getSavedViewletId(savedState);
1095
+ const views = getPanelViews();
1096
+ const loaded = {
1097
+ ...state,
1098
+ currentViewletId: savedViewletId,
1099
+ views
1100
+ };
1101
+ return openViewlet(loaded, savedViewletId);
1102
+ };
1103
+
1104
+ // export const contentLoaded = (state) => {
1105
+ // const commands = []
1106
+ // return commands
1107
+ // }
1108
+
1109
+ const getContentDimensions = dimensions => {
1110
+ return {
1111
+ height: dimensions.height - 35,
1112
+ width: dimensions.width,
1113
+ x: dimensions.x,
1114
+ y: dimensions.y + 35
1115
+ };
1116
+ };
1117
+ const openViewlet = async (state, id, focus = false) => {
1118
+ const childDimensions = getContentDimensions(state);
1119
+ const {
1120
+ uid
1121
+ } = state;
1122
+ const childUid = create();
1123
+ const commands = await ViewletManager.load({
1124
+ append: false,
1125
+ args: [],
1126
+ focus,
1127
+ getModule: ViewletModule.load,
1128
+ height: childDimensions.height,
1129
+ id,
1130
+ parentUid: uid,
1131
+ setBounds: false,
1132
+ shouldRenderEvents: false,
1133
+ show: false,
1134
+ type: 0,
1135
+ uid: childUid,
1136
+ // @ts-ignore
1137
+ uri: '',
1138
+ width: childDimensions.width,
1139
+ x: childDimensions.x,
1140
+ y: childDimensions.y
1141
+ }, false, true);
1142
+ let actionsDom = [];
1143
+ let actionsUid = -1;
1144
+ if (commands) {
1145
+ const actionsDomIndex = commands.findIndex(command => command[2] === 'setActionsDom');
1146
+ if (actionsDomIndex !== -1) {
1147
+ const actionDomEntry = commands[actionsDomIndex]?.[3];
1148
+ if (Array.isArray(actionDomEntry)) {
1149
+ actionsDom = actionDomEntry;
1150
+ }
1151
+ commands.splice(actionsDomIndex, 1);
1152
+ }
1153
+ const eventsIndex = commands.findIndex(command => command[0] === 'Viewlet.registerEventListeners');
1154
+ const events = eventsIndex === -1 ? [] : commands[eventsIndex]?.[2];
1155
+ actionsUid = create();
1156
+ commands.push(['Viewlet.createFunctionalRoot', id, actionsUid, true], ['Viewlet.registerEventListeners', actionsUid, events], ['Viewlet.setDom2', actionsUid, actionsDom], ['Viewlet.setUid', actionsUid, childUid]);
1157
+ await RendererProcess.invoke('Viewlet.sendMultiple', commands);
1158
+ }
1066
1159
  return {
1067
1160
  ...state,
1068
- errorCount: 0,
1069
- initial: false,
1070
- warningCount: 0
1161
+ actionsUid,
1162
+ childUid,
1163
+ currentViewletId: id
1071
1164
  };
1072
1165
  };
1073
1166
 
@@ -1437,21 +1530,38 @@ const renderEventListeners = () => {
1437
1530
  }];
1438
1531
  };
1439
1532
 
1440
- const resize = (state, dimensions) => {
1441
- return {
1533
+ const resize = async (state, dimensions) => {
1534
+ // TODO
1535
+ const currentViewletInstance = {};
1536
+ const newState = {
1442
1537
  ...state,
1443
1538
  ...dimensions
1444
1539
  };
1540
+ if (!currentViewletInstance) {
1541
+ return {
1542
+ ...newState
1543
+ };
1544
+ }
1545
+ // @ts-ignore
1546
+ const currentViewletUid = currentViewletInstance.state.uid;
1547
+ // @ts-ignore
1548
+ await invoke('Viewlet.resize', currentViewletUid, dimensions);
1549
+ return {
1550
+ ...newState
1551
+ };
1445
1552
  };
1446
1553
 
1447
1554
  const saveState = state => {
1555
+ const {
1556
+ currentViewletId
1557
+ } = state;
1448
1558
  return {
1449
- x: 0
1559
+ currentViewletId
1450
1560
  };
1451
1561
  };
1452
1562
 
1453
1563
  const commandMap = {
1454
- 'StatusBar.create': create,
1564
+ 'StatusBar.create': create$1,
1455
1565
  'StatusBar.diff2': diff2,
1456
1566
  'StatusBar.getCommandIds': getCommandIds,
1457
1567
  'StatusBar.loadContent': wrapCommand(loadContent),
@@ -1464,7 +1574,7 @@ const commandMap = {
1464
1574
 
1465
1575
  const listen = async () => {
1466
1576
  registerCommands(commandMap);
1467
- const rpc = await create$3({
1577
+ const rpc = await create$4({
1468
1578
  commandMap: commandMap
1469
1579
  });
1470
1580
  set$1(rpc);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/panel-worker",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Panel Worker",
5
5
  "repository": {
6
6
  "type": "git",