@lvce-editor/panel-worker 1.3.0 → 1.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.
@@ -1091,7 +1091,7 @@ const create = (uid, uri, x, y, width, height, platform, assetDir) => {
1091
1091
  };
1092
1092
 
1093
1093
  const isEqual = (oldState, newState) => {
1094
- return oldState.assetDir === newState.assetDir;
1094
+ return oldState.assetDir === newState.assetDir && oldState.initial === newState.initial && oldState.currentViewletId === newState.currentViewletId && oldState.selectedIndex === newState.selectedIndex && oldState.views === newState.views;
1095
1095
  };
1096
1096
 
1097
1097
  const RenderItems = 4;
@@ -1120,8 +1120,28 @@ const diff2 = uid => {
1120
1120
  return result;
1121
1121
  };
1122
1122
 
1123
- const createViewlet = async (viewletModuleId, editorUid, tabId, bounds, uri) => {
1124
- await invoke('Layout.createViewlet', viewletModuleId, editorUid, tabId, bounds, uri);
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 handleBlur = async state => {
1133
+ return state;
1134
+ };
1135
+
1136
+ const handleFilterInput = async (state, value) => {
1137
+ object(state);
1138
+ string(value);
1139
+ const {
1140
+ currentViewletId
1141
+ } = state;
1142
+ const fullCommand = `${currentViewletId}.handleFilterInput`;
1143
+ await invoke(fullCommand, value);
1144
+ return state;
1125
1145
  };
1126
1146
 
1127
1147
  const DebugConsole = 'Debug Console';
@@ -1140,33 +1160,10 @@ const getSavedViewletId = savedState => {
1140
1160
  }
1141
1161
  return Problems;
1142
1162
  };
1143
- const loadContent = (state, savedState) => {
1144
- const savedViewletId = getSavedViewletId(savedState);
1145
- const views = getPanelViews();
1146
- const loaded = {
1147
- ...state,
1148
- currentViewletId: savedViewletId,
1149
- views
1150
- };
1151
- return openViewlet(loaded, savedViewletId);
1152
- };
1153
- const setBadgeCount = (state, id, count) => {
1154
- const {
1155
- badgeCounts
1156
- } = state;
1157
- return {
1158
- ...state,
1159
- badgeCounts: {
1160
- ...badgeCounts,
1161
- [id]: count
1162
- }
1163
- };
1164
- };
1165
1163
 
1166
- // export const contentLoaded = (state) => {
1167
- // const commands = []
1168
- // return commands
1169
- // }
1164
+ const createViewlet = async (viewletModuleId, editorUid, tabId, bounds, uri) => {
1165
+ await invoke('Layout.createViewlet', viewletModuleId, editorUid, tabId, bounds, uri);
1166
+ };
1170
1167
 
1171
1168
  const getContentDimensions = dimensions => {
1172
1169
  return {
@@ -1177,39 +1174,32 @@ const getContentDimensions = dimensions => {
1177
1174
  };
1178
1175
  };
1179
1176
 
1180
- // TODO
1181
- // export const getChildren = (state) => {
1182
- // const { currentViewletId } = state
1183
- // return [
1184
- // {
1185
- // id: currentViewletId,
1186
- // ...getContentDimensions(state),
1187
- // },
1188
- // ]
1189
- // }
1190
-
1191
1177
  const openViewlet = async (state, id, focus = false) => {
1192
1178
  const childDimensions = getContentDimensions(state);
1193
1179
  const childUid = Math.random();
1194
1180
  const tabId = 1234;
1195
- // TODO get the actions uid somehow
1196
1181
  const actionsUid = Math.random();
1197
1182
  await createViewlet(id, childUid, tabId, childDimensions, '');
1198
1183
  return {
1199
1184
  ...state,
1200
1185
  actionsUid,
1201
1186
  childUid,
1202
- currentViewletId: id
1187
+ currentViewletId: id,
1188
+ initial: false
1203
1189
  };
1204
1190
  };
1205
- const handleClickClose = async state => {
1206
- await invoke('Layout.hidePanel');
1207
- return state;
1208
- };
1209
- const handleClickMaximize = async state => {
1210
- // TODO
1211
- return state;
1191
+
1192
+ const loadContent = (state, savedState) => {
1193
+ const savedViewletId = getSavedViewletId(savedState);
1194
+ const views = getPanelViews();
1195
+ const loaded = {
1196
+ ...state,
1197
+ currentViewletId: savedViewletId,
1198
+ views
1199
+ };
1200
+ return openViewlet(loaded, savedViewletId);
1212
1201
  };
1202
+
1213
1203
  const selectIndex = async (state, index) => {
1214
1204
  await openViewlet(state, state.views[index]);
1215
1205
  return {
@@ -1217,30 +1207,34 @@ const selectIndex = async (state, index) => {
1217
1207
  selectedIndex: index
1218
1208
  };
1219
1209
  };
1210
+
1220
1211
  const selectRaw = async (state, rawIndex) => {
1221
1212
  return selectIndex(state, Number.parseInt(rawIndex, 10));
1222
1213
  };
1214
+
1215
+ const setBadgeCount = (state, id, count) => {
1216
+ const {
1217
+ badgeCounts
1218
+ } = state;
1219
+ return {
1220
+ ...state,
1221
+ badgeCounts: {
1222
+ ...badgeCounts,
1223
+ [id]: count
1224
+ }
1225
+ };
1226
+ };
1227
+
1223
1228
  const toggleView = async (state, name) => {
1224
1229
  const index = state.views.indexOf(name);
1225
1230
  if (index === -1) {
1226
1231
  return state;
1227
1232
  }
1228
1233
  if (name === state.currentViewletId) {
1229
- // await Command.execute('Layout.hidePanel') // TODO
1230
1234
  return state;
1231
1235
  }
1232
1236
  return selectIndex(state, index);
1233
1237
  };
1234
- const handleFilterInput = async (state, value) => {
1235
- object(state);
1236
- string(value);
1237
- const {
1238
- currentViewletId
1239
- } = state;
1240
- const fullCommand = `${currentViewletId}.handleFilterInput`;
1241
- await invoke(fullCommand, value);
1242
- return state;
1243
- };
1244
1238
 
1245
1239
  const text = data => {
1246
1240
  return {
@@ -1538,12 +1532,25 @@ const diffTree = (oldNodes, newNodes) => {
1538
1532
  return removeTrailingNavigationPatches(patches);
1539
1533
  };
1540
1534
 
1535
+ const Badge = 'Badge';
1536
+ const PanelTab = 'PanelTab';
1537
+ const PanelTabSelected = 'PanelTabSelected';
1538
+ const Panel = 'Panel';
1539
+ const PanelHeader = 'PanelHeader';
1540
+ const PanelTabs = 'PanelTabs';
1541
+ const PanelToolBar = 'PanelToolBar';
1542
+ const IconButton = 'IconButton';
1543
+ const MaskIcon = 'MaskIcon';
1544
+ const MaskIconChevronUp = 'MaskIconChevronUp';
1545
+ const MaskIconClose = 'MaskIconClose';
1546
+ const Actions = 'Actions';
1547
+
1541
1548
  const getActionsDom = newState => {
1542
1549
  const actions = newState.actionsUid || -1;
1543
1550
  if (actions === -1) {
1544
1551
  return [{
1545
1552
  childCount: 0,
1546
- className: 'Actions',
1553
+ className: Actions,
1547
1554
  role: 'toolbar',
1548
1555
  type: Div
1549
1556
  }];
@@ -1558,41 +1565,59 @@ const HandleClickClose = 'handleClickClose';
1558
1565
  const HandleClickMaximize = 'handleClickMaximize';
1559
1566
  const HandleClickSelectTab = 'HandleClickSelectTab';
1560
1567
 
1568
+ const emptyObject = {};
1569
+ const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1570
+ const i18nString = (key, placeholders = emptyObject) => {
1571
+ if (placeholders === emptyObject) {
1572
+ return key;
1573
+ }
1574
+ const replacer = (match, rest) => {
1575
+ return placeholders[rest];
1576
+ };
1577
+ return key.replaceAll(RE_PLACEHOLDER, replacer);
1578
+ };
1579
+
1580
+ const Maximize = 'Maximize';
1581
+ const Close = 'Close';
1582
+
1583
+ const maximize = () => {
1584
+ return i18nString(Maximize);
1585
+ };
1586
+ const close = () => {
1587
+ return i18nString(Close);
1588
+ };
1589
+
1561
1590
  const getGlobalActionsDom = () => {
1562
1591
  return [{
1563
1592
  childCount: 2,
1564
- className: 'PanelToolBar',
1593
+ className: PanelToolBar,
1565
1594
  role: 'toolbar',
1566
1595
  type: Div
1567
1596
  }, {
1568
- ariaLabel: 'Maximize',
1597
+ ariaLabel: maximize(),
1569
1598
  childCount: 1,
1570
- className: 'IconButton',
1599
+ className: IconButton,
1571
1600
  onClick: HandleClickMaximize,
1572
- titleM: 'Maximize',
1601
+ title: maximize(),
1573
1602
  type: Button
1574
1603
  }, {
1575
1604
  childCount: 0,
1576
- className: 'MaskIcon MaskIconChevronUp',
1605
+ className: `${MaskIcon} ${MaskIconChevronUp}`,
1577
1606
  type: Div
1578
1607
  }, {
1579
- ariaLabel: 'Close',
1608
+ ariaLabel: close(),
1580
1609
  childCount: 1,
1581
- className: 'IconButton',
1610
+ className: IconButton,
1582
1611
  onClick: HandleClickClose,
1583
- titleM: 'Close',
1612
+ title: close(),
1584
1613
  type: Button
1585
1614
  }, {
1586
1615
  childCount: 0,
1587
- className: 'MaskIcon MaskIconClose',
1616
+ className: `${MaskIcon} ${MaskIconClose}`,
1588
1617
  type: Div
1589
1618
  }];
1590
1619
  };
1591
1620
 
1592
- const Badge = 'Badge';
1593
- const PanelTab = 'PanelTab';
1594
- const PanelTabSelected = 'PanelTabSelected';
1595
-
1596
1621
  const createPanelTab = (tab, badgeCount, isSelected, index) => {
1597
1622
  const label = tab;
1598
1623
  let className = PanelTab;
@@ -1637,15 +1662,15 @@ const getPanelDom = newState => {
1637
1662
  const tabsDom = getPanelTabsVirtualDom(newState.views, newState.selectedIndex, newState.badgeCounts);
1638
1663
  return [{
1639
1664
  childCount: 2,
1640
- className: 'Panel',
1665
+ className: Panel,
1641
1666
  type: Div
1642
1667
  }, {
1643
1668
  childCount: 3,
1644
- className: 'PanelHeader',
1669
+ className: PanelHeader,
1645
1670
  type: Div
1646
1671
  }, {
1647
1672
  childCount: newState.views.length,
1648
- className: 'PanelTabs',
1673
+ className: PanelTabs,
1649
1674
  type: Div
1650
1675
  }, ...tabsDom, ...getActionsDom(newState), ...getGlobalActionsDom(), {
1651
1676
  type: Reference,
@@ -1753,6 +1778,7 @@ const commandMap = {
1753
1778
  'Panel.create': create,
1754
1779
  'Panel.diff2': diff2,
1755
1780
  'Panel.getCommandIds': getCommandIds,
1781
+ 'Panel.handleBlur': wrapCommand(handleBlur),
1756
1782
  'Panel.handleClickClose': wrapCommand(handleClickClose),
1757
1783
  'Panel.handleClickMaximize': wrapCommand(handleClickMaximize),
1758
1784
  'Panel.handleFilterInput': wrapCommand(handleFilterInput),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/panel-worker",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "Panel Worker",
5
5
  "repository": {
6
6
  "type": "git",