@lvce-editor/panel-worker 1.2.0 → 1.4.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.
@@ -653,7 +653,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
653
653
  const errorProperty = getErrorProperty(error, prettyError);
654
654
  return create$1$1(id, errorProperty);
655
655
  };
656
- const create$8 = (message, result) => {
656
+ const create$7 = (message, result) => {
657
657
  return {
658
658
  jsonrpc: Two$1,
659
659
  id: message.id,
@@ -662,7 +662,7 @@ const create$8 = (message, result) => {
662
662
  };
663
663
  const getSuccessResponse = (message, result) => {
664
664
  const resultProperty = result ?? null;
665
- return create$8(message, resultProperty);
665
+ return create$7(message, resultProperty);
666
666
  };
667
667
  const getErrorResponseSimple = (id, error) => {
668
668
  return {
@@ -756,7 +756,7 @@ const handleJsonRpcMessage = async (...args) => {
756
756
 
757
757
  const Two = '2.0';
758
758
 
759
- const create$7 = (method, params) => {
759
+ const create$6 = (method, params) => {
760
760
  return {
761
761
  jsonrpc: Two,
762
762
  method,
@@ -764,7 +764,7 @@ const create$7 = (method, params) => {
764
764
  };
765
765
  };
766
766
 
767
- const create$6 = (id, method, params) => {
767
+ const create$5 = (id, method, params) => {
768
768
  const message = {
769
769
  id,
770
770
  jsonrpc: Two,
@@ -775,12 +775,12 @@ const create$6 = (id, method, params) => {
775
775
  };
776
776
 
777
777
  let id = 0;
778
- const create$5 = () => {
778
+ const create$4 = () => {
779
779
  return ++id;
780
780
  };
781
781
 
782
782
  const registerPromise = map => {
783
- const id = create$5();
783
+ const id = create$4();
784
784
  const {
785
785
  promise,
786
786
  resolve
@@ -798,7 +798,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
798
798
  id,
799
799
  promise
800
800
  } = registerPromise(callbacks);
801
- const message = create$6(id, method, params);
801
+ const message = create$5(id, method, params);
802
802
  if (useSendAndTransfer && ipc.sendAndTransfer) {
803
803
  ipc.sendAndTransfer(message);
804
804
  } else {
@@ -834,7 +834,7 @@ const createRpc = ipc => {
834
834
  * @deprecated
835
835
  */
836
836
  send(method, ...params) {
837
- const message = create$7(method, params);
837
+ const message = create$6(method, params);
838
838
  ipc.send(message);
839
839
  }
840
840
  };
@@ -874,7 +874,7 @@ const listen$1 = async (module, options) => {
874
874
  return ipc;
875
875
  };
876
876
 
877
- const create$4 = async ({
877
+ const create$3 = async ({
878
878
  commandMap
879
879
  }) => {
880
880
  // TODO create a commandMap per rpc instance
@@ -885,6 +885,9 @@ const create$4 = async ({
885
885
  return rpc;
886
886
  };
887
887
 
888
+ const Tab = 'tab';
889
+
890
+ const Button = 1;
888
891
  const Div = 4;
889
892
  const Text = 12;
890
893
  const Reference = 100;
@@ -926,7 +929,7 @@ const remove = id => {
926
929
  };
927
930
 
928
931
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
929
- const create$3 = rpcId => {
932
+ const create$2 = rpcId => {
930
933
  return {
931
934
  async dispose() {
932
935
  const rpc = get$1(rpcId);
@@ -965,13 +968,13 @@ const create$3 = rpcId => {
965
968
  const {
966
969
  invoke,
967
970
  set: set$1
968
- } = create$3(RendererWorker);
971
+ } = create$2(RendererWorker);
969
972
 
970
973
  const toCommandId = key => {
971
974
  const dotIndex = key.indexOf('.');
972
975
  return key.slice(dotIndex + 1);
973
976
  };
974
- const create$2 = () => {
977
+ const create$1 = () => {
975
978
  const states = Object.create(null);
976
979
  const commandMapRef = {};
977
980
  return {
@@ -1063,9 +1066,9 @@ const {
1063
1066
  set,
1064
1067
  wrapCommand,
1065
1068
  wrapGetter
1066
- } = create$2();
1069
+ } = create$1();
1067
1070
 
1068
- const create$1 = (uid, uri, x, y, width, height, platform, assetDir) => {
1071
+ const create = (uid, uri, x, y, width, height, platform, assetDir) => {
1069
1072
  const state = {
1070
1073
  actionsUid: 0,
1071
1074
  assetDir,
@@ -1088,7 +1091,7 @@ const create$1 = (uid, uri, x, y, width, height, platform, assetDir) => {
1088
1091
  };
1089
1092
 
1090
1093
  const isEqual = (oldState, newState) => {
1091
- return oldState.assetDir === newState.assetDir;
1094
+ return oldState.assetDir === newState.assetDir && oldState.initial === newState.initial && oldState.currentViewletId === newState.currentViewletId;
1092
1095
  };
1093
1096
 
1094
1097
  const RenderItems = 4;
@@ -1117,6 +1120,26 @@ const diff2 = uid => {
1117
1120
  return result;
1118
1121
  };
1119
1122
 
1123
+ const handleClickClose = async state => {
1124
+ await invoke('Layout.hidePanel');
1125
+ return state;
1126
+ };
1127
+
1128
+ const handleClickMaximize = async state => {
1129
+ return state;
1130
+ };
1131
+
1132
+ const handleFilterInput = async (state, value) => {
1133
+ object(state);
1134
+ string(value);
1135
+ const {
1136
+ currentViewletId
1137
+ } = state;
1138
+ const fullCommand = `${currentViewletId}.handleFilterInput`;
1139
+ await invoke(fullCommand, value);
1140
+ return state;
1141
+ };
1142
+
1120
1143
  const DebugConsole = 'Debug Console';
1121
1144
  const Output = 'Output';
1122
1145
  const Problems = 'Problems';
@@ -1127,45 +1150,16 @@ const getPanelViews = () => {
1127
1150
  return views;
1128
1151
  };
1129
1152
 
1130
- let idCounter = 0;
1131
- const create = () => {
1132
- idCounter++;
1133
- return idCounter;
1134
- };
1135
-
1136
1153
  const getSavedViewletId = savedState => {
1137
1154
  if (savedState && savedState.currentViewletId) {
1138
1155
  return savedState.currentViewletId || Problems;
1139
1156
  }
1140
1157
  return Problems;
1141
1158
  };
1142
- const loadContent = (state, savedState) => {
1143
- const savedViewletId = getSavedViewletId(savedState);
1144
- const views = getPanelViews();
1145
- const loaded = {
1146
- ...state,
1147
- currentViewletId: savedViewletId,
1148
- views
1149
- };
1150
- return openViewlet(loaded, savedViewletId);
1151
- };
1152
- const setBadgeCount = (state, id, count) => {
1153
- const {
1154
- badgeCounts
1155
- } = state;
1156
- return {
1157
- ...state,
1158
- badgeCounts: {
1159
- ...badgeCounts,
1160
- [id]: count
1161
- }
1162
- };
1163
- };
1164
1159
 
1165
- // export const contentLoaded = (state) => {
1166
- // const commands = []
1167
- // return commands
1168
- // }
1160
+ const createViewlet = async (viewletModuleId, editorUid, tabId, bounds, uri) => {
1161
+ await invoke('Layout.createViewlet', viewletModuleId, editorUid, tabId, bounds, uri);
1162
+ };
1169
1163
 
1170
1164
  const getContentDimensions = dimensions => {
1171
1165
  return {
@@ -1175,63 +1169,33 @@ const getContentDimensions = dimensions => {
1175
1169
  y: dimensions.y + 35
1176
1170
  };
1177
1171
  };
1172
+
1178
1173
  const openViewlet = async (state, id, focus = false) => {
1179
1174
  const childDimensions = getContentDimensions(state);
1180
- const {
1181
- uid
1182
- } = state;
1183
- const childUid = create();
1184
- const commands = await ViewletManager.load({
1185
- append: false,
1186
- args: [],
1187
- focus,
1188
- getModule: ViewletModule.load,
1189
- height: childDimensions.height,
1190
- id,
1191
- parentUid: uid,
1192
- setBounds: false,
1193
- shouldRenderEvents: false,
1194
- show: false,
1195
- type: 0,
1196
- uid: childUid,
1197
- // @ts-ignore
1198
- uri: '',
1199
- width: childDimensions.width,
1200
- x: childDimensions.x,
1201
- y: childDimensions.y
1202
- }, false, true);
1203
- let actionsDom = [];
1204
- let actionsUid = -1;
1205
- if (commands) {
1206
- const actionsDomIndex = commands.findIndex(command => command[2] === 'setActionsDom');
1207
- if (actionsDomIndex !== -1) {
1208
- const actionDomEntry = commands[actionsDomIndex]?.[3];
1209
- if (Array.isArray(actionDomEntry)) {
1210
- actionsDom = actionDomEntry;
1211
- }
1212
- commands.splice(actionsDomIndex, 1);
1213
- }
1214
- const eventsIndex = commands.findIndex(command => command[0] === 'Viewlet.registerEventListeners');
1215
- const events = eventsIndex === -1 ? [] : commands[eventsIndex]?.[2];
1216
- actionsUid = create();
1217
- commands.push(['Viewlet.createFunctionalRoot', id, actionsUid, true], ['Viewlet.registerEventListeners', actionsUid, events], ['Viewlet.setDom2', actionsUid, actionsDom], ['Viewlet.setUid', actionsUid, childUid]);
1218
- await RendererProcess.invoke('Viewlet.sendMultiple', commands);
1219
- }
1175
+ const childUid = Math.random();
1176
+ const tabId = 1234;
1177
+ const actionsUid = Math.random();
1178
+ await createViewlet(id, childUid, tabId, childDimensions, '');
1220
1179
  return {
1221
1180
  ...state,
1222
1181
  actionsUid,
1223
1182
  childUid,
1224
- currentViewletId: id
1183
+ currentViewletId: id,
1184
+ initial: false
1225
1185
  };
1226
1186
  };
1227
- const handleClickClose = async state => {
1228
- await Command.execute('Layout.hidePanel');
1229
- return state;
1230
- };
1231
- const handleClickMaximize = async state => {
1232
- // TODO
1233
- return state;
1187
+
1188
+ const loadContent = (state, savedState) => {
1189
+ const savedViewletId = getSavedViewletId(savedState);
1190
+ const views = getPanelViews();
1191
+ const loaded = {
1192
+ ...state,
1193
+ currentViewletId: savedViewletId,
1194
+ views
1195
+ };
1196
+ return openViewlet(loaded, savedViewletId);
1234
1197
  };
1198
+
1235
1199
  const selectIndex = async (state, index) => {
1236
1200
  await openViewlet(state, state.views[index]);
1237
1201
  return {
@@ -1239,29 +1203,41 @@ const selectIndex = async (state, index) => {
1239
1203
  selectedIndex: index
1240
1204
  };
1241
1205
  };
1206
+
1242
1207
  const selectRaw = async (state, rawIndex) => {
1243
1208
  return selectIndex(state, Number.parseInt(rawIndex, 10));
1244
1209
  };
1210
+
1211
+ const setBadgeCount = (state, id, count) => {
1212
+ const {
1213
+ badgeCounts
1214
+ } = state;
1215
+ return {
1216
+ ...state,
1217
+ badgeCounts: {
1218
+ ...badgeCounts,
1219
+ [id]: count
1220
+ }
1221
+ };
1222
+ };
1223
+
1245
1224
  const toggleView = async (state, name) => {
1246
1225
  const index = state.views.indexOf(name);
1247
1226
  if (index === -1) {
1248
1227
  return state;
1249
1228
  }
1250
1229
  if (name === state.currentViewletId) {
1251
- // await Command.execute('Layout.hidePanel') // TODO
1252
1230
  return state;
1253
1231
  }
1254
1232
  return selectIndex(state, index);
1255
1233
  };
1256
- const handleFilterInput = async (state, value) => {
1257
- object(state);
1258
- string(value);
1259
- const {
1260
- currentViewletId
1261
- } = state;
1262
- const fullCommand = `${currentViewletId}.handleFilterInput`;
1263
- await Command.execute(fullCommand, value);
1264
- return state;
1234
+
1235
+ const text = data => {
1236
+ return {
1237
+ childCount: 0,
1238
+ text: data,
1239
+ type: Text
1240
+ };
1265
1241
  };
1266
1242
 
1267
1243
  const SetText = 1;
@@ -1552,15 +1528,121 @@ const diffTree = (oldNodes, newNodes) => {
1552
1528
  return removeTrailingNavigationPatches(patches);
1553
1529
  };
1554
1530
 
1555
- const getStatusBarVirtualDom = () => {
1556
- const dom = [{
1531
+ const getActionsDom = newState => {
1532
+ const actions = newState.actionsUid || -1;
1533
+ if (actions === -1) {
1534
+ return [{
1535
+ childCount: 0,
1536
+ className: 'Actions',
1537
+ role: 'toolbar',
1538
+ type: Div
1539
+ }];
1540
+ }
1541
+ return [{
1542
+ type: Reference,
1543
+ uid: actions
1544
+ }];
1545
+ };
1546
+
1547
+ const HandleClickClose = 'handleClickClose';
1548
+ const HandleClickMaximize = 'handleClickMaximize';
1549
+ const HandleClickSelectTab = 'HandleClickSelectTab';
1550
+
1551
+ const getGlobalActionsDom = () => {
1552
+ return [{
1553
+ childCount: 2,
1554
+ className: 'PanelToolBar',
1555
+ role: 'toolbar',
1556
+ type: Div
1557
+ }, {
1558
+ ariaLabel: 'Maximize',
1559
+ childCount: 1,
1560
+ className: 'IconButton',
1561
+ onClick: HandleClickMaximize,
1562
+ titleM: 'Maximize',
1563
+ type: Button
1564
+ }, {
1557
1565
  childCount: 0,
1558
- className: 'Panel',
1566
+ className: 'MaskIcon MaskIconChevronUp',
1567
+ type: Div
1568
+ }, {
1569
+ ariaLabel: 'Close',
1570
+ childCount: 1,
1571
+ className: 'IconButton',
1572
+ onClick: HandleClickClose,
1573
+ titleM: 'Close',
1574
+ type: Button
1575
+ }, {
1576
+ childCount: 0,
1577
+ className: 'MaskIcon MaskIconClose',
1559
1578
  type: Div
1560
1579
  }];
1580
+ };
1581
+
1582
+ const Badge = 'Badge';
1583
+ const PanelTab = 'PanelTab';
1584
+ const PanelTabSelected = 'PanelTabSelected';
1585
+
1586
+ const createPanelTab = (tab, badgeCount, isSelected, index) => {
1587
+ const label = tab;
1588
+ let className = PanelTab;
1589
+ if (isSelected) {
1590
+ className += ' ' + PanelTabSelected;
1591
+ }
1592
+ const childCount = badgeCount ? 2 : 1;
1593
+ const tabDom = {
1594
+ ariaSelected: isSelected,
1595
+ childCount,
1596
+ className,
1597
+ 'data-index': index,
1598
+ onClick: HandleClickSelectTab,
1599
+ role: Tab,
1600
+ type: Div
1601
+ };
1602
+ const dom = [tabDom, text(label)];
1603
+ if (badgeCount) {
1604
+ dom.push({
1605
+ childCount: 1,
1606
+ className: Badge,
1607
+ type: Div
1608
+ }, text(' ' + badgeCount));
1609
+ }
1610
+ return dom;
1611
+ };
1612
+ const getPanelTabsVirtualDom = (tabs, selectedIndex, badgeCounts) => {
1613
+ const dom = [];
1614
+ for (let i = 0; i < tabs.length; i++) {
1615
+ const isSelected = i === selectedIndex;
1616
+ const tab = tabs[i];
1617
+ const badgeCount = badgeCounts[tab] || 0;
1618
+ dom.push(...createPanelTab(tab, badgeCount, isSelected, i));
1619
+ }
1561
1620
  return dom;
1562
1621
  };
1563
1622
 
1623
+ const getPanelDom = newState => {
1624
+ const {
1625
+ childUid
1626
+ } = newState;
1627
+ const tabsDom = getPanelTabsVirtualDom(newState.views, newState.selectedIndex, newState.badgeCounts);
1628
+ return [{
1629
+ childCount: 2,
1630
+ className: 'Panel',
1631
+ type: Div
1632
+ }, {
1633
+ childCount: 3,
1634
+ className: 'PanelHeader',
1635
+ type: Div
1636
+ }, {
1637
+ childCount: newState.views.length,
1638
+ className: 'PanelTabs',
1639
+ type: Div
1640
+ }, ...tabsDom, ...getActionsDom(newState), ...getGlobalActionsDom(), {
1641
+ type: Reference,
1642
+ uid: childUid
1643
+ }];
1644
+ };
1645
+
1564
1646
  const renderItems = (oldState, newState) => {
1565
1647
  const {
1566
1648
  initial,
@@ -1569,7 +1651,7 @@ const renderItems = (oldState, newState) => {
1569
1651
  if (initial) {
1570
1652
  return [SetDom2, uid, []];
1571
1653
  }
1572
- const dom = getStatusBarVirtualDom();
1654
+ const dom = getPanelDom(newState);
1573
1655
  return [SetDom2, uid, dom];
1574
1656
  };
1575
1657
 
@@ -1613,10 +1695,6 @@ const render2 = (uid, diffResult) => {
1613
1695
  return commands;
1614
1696
  };
1615
1697
 
1616
- const HandleClickClose = 'handleClickClose';
1617
- const HandleClickMaximize = 'handleClickMaximize';
1618
- const HandleClickSelectTab = 'HandleClickSelectTab';
1619
-
1620
1698
  const renderEventListeners = () => {
1621
1699
  return [{
1622
1700
  name: HandleClickMaximize,
@@ -1631,6 +1709,9 @@ const renderEventListeners = () => {
1631
1709
  };
1632
1710
 
1633
1711
  const resize = async (state, dimensions) => {
1712
+ const {
1713
+ childUid
1714
+ } = state;
1634
1715
  // TODO
1635
1716
  const currentViewletInstance = {};
1636
1717
  const newState = {
@@ -1643,9 +1724,7 @@ const resize = async (state, dimensions) => {
1643
1724
  };
1644
1725
  }
1645
1726
  // @ts-ignore
1646
- const currentViewletUid = currentViewletInstance.state.uid;
1647
- // @ts-ignore
1648
- await invoke('Viewlet.resize', currentViewletUid, dimensions);
1727
+ await invoke('Viewlet.resize', childUid, dimensions);
1649
1728
  return {
1650
1729
  ...newState
1651
1730
  };
@@ -1661,7 +1740,7 @@ const saveState = state => {
1661
1740
  };
1662
1741
 
1663
1742
  const commandMap = {
1664
- 'Panel.create': create$1,
1743
+ 'Panel.create': create,
1665
1744
  'Panel.diff2': diff2,
1666
1745
  'Panel.getCommandIds': getCommandIds,
1667
1746
  'Panel.handleClickClose': wrapCommand(handleClickClose),
@@ -1682,7 +1761,7 @@ const commandMap = {
1682
1761
 
1683
1762
  const listen = async () => {
1684
1763
  registerCommands(commandMap);
1685
- const rpc = await create$4({
1764
+ const rpc = await create$3({
1686
1765
  commandMap: commandMap
1687
1766
  });
1688
1767
  set$1(rpc);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/panel-worker",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Panel Worker",
5
5
  "repository": {
6
6
  "type": "git",