@lvce-editor/about-view 5.11.0 → 6.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.
@@ -378,7 +378,7 @@ const create$4 = (method, params) => {
378
378
  };
379
379
  };
380
380
  const callbacks = Object.create(null);
381
- const set$2 = (id, fn) => {
381
+ const set$3 = (id, fn) => {
382
382
  callbacks[id] = fn;
383
383
  };
384
384
  const get$2 = id => {
@@ -397,7 +397,7 @@ const registerPromise = () => {
397
397
  resolve,
398
398
  promise
399
399
  } = Promise.withResolvers();
400
- set$2(id, resolve);
400
+ set$3(id, resolve);
401
401
  return {
402
402
  id,
403
403
  promise
@@ -477,7 +477,8 @@ const splitLines = lines => {
477
477
  return lines.split(NewLine$1);
478
478
  };
479
479
  const getCurrentStack = () => {
480
- const currentStack = joinLines$1(splitLines(new Error().stack || '').slice(2));
480
+ const stackLinesToSkip = 3;
481
+ const currentStack = joinLines$1(splitLines(new Error().stack || '').slice(stackLinesToSkip));
481
482
  return currentStack;
482
483
  };
483
484
  const getNewLineIndex = (string, startIndex = undefined) => {
@@ -741,13 +742,19 @@ const send = (transport, method, ...params) => {
741
742
  const message = create$4(method, params);
742
743
  transport.send(message);
743
744
  };
744
- const invoke = (ipc, method, ...params) => {
745
+ const invoke$1 = (ipc, method, ...params) => {
745
746
  return invokeHelper(ipc, method, params, false);
746
747
  };
747
748
  const invokeAndTransfer = (ipc, method, ...params) => {
748
749
  return invokeHelper(ipc, method, params, true);
749
750
  };
750
751
 
752
+ class CommandNotFoundError extends Error {
753
+ constructor(command) {
754
+ super(`Command not found ${command}`);
755
+ this.name = 'CommandNotFoundError';
756
+ }
757
+ }
751
758
  const commands = Object.create(null);
752
759
  const register = commandMap => {
753
760
  Object.assign(commands, commandMap);
@@ -758,7 +765,7 @@ const getCommand = key => {
758
765
  const execute = (command, ...args) => {
759
766
  const fn = getCommand(command);
760
767
  if (!fn) {
761
- throw new Error(`command not found ${command}`);
768
+ throw new CommandNotFoundError(command);
762
769
  }
763
770
  return fn(...args);
764
771
  };
@@ -774,7 +781,7 @@ const createRpc = ipc => {
774
781
  send(ipc, method, ...params);
775
782
  },
776
783
  invoke(method, ...params) {
777
- return invoke(ipc, method, ...params);
784
+ return invoke$1(ipc, method, ...params);
778
785
  },
779
786
  invokeAndTransfer(method, ...params) {
780
787
  return invokeAndTransfer(ipc, method, ...params);
@@ -830,8 +837,91 @@ const WebWorkerRpcClient = {
830
837
  create: create$3
831
838
  };
832
839
 
833
- const create$2 = () => {
840
+ const Button$2 = 1;
841
+ const Div = 4;
842
+ const Text = 12;
843
+ const Br = 55;
844
+
845
+ const Tab = 2;
846
+ const Escape = 8;
847
+
848
+ const Shift = 1 << 10 >>> 0;
849
+
850
+ const RendererWorker = 1;
851
+
852
+ const rpcs = Object.create(null);
853
+ const set$2 = (id, rpc) => {
854
+ rpcs[id] = rpc;
855
+ };
856
+ const get$1 = id => {
857
+ return rpcs[id];
858
+ };
859
+
860
+ const create$2 = rpcId => {
861
+ return {
862
+ // @ts-ignore
863
+ invoke(method, ...params) {
864
+ const rpc = get$1(rpcId);
865
+ // @ts-ignore
866
+ return rpc.invoke(method, ...params);
867
+ },
868
+ // @ts-ignore
869
+ invokeAndTransfer(method, ...params) {
870
+ const rpc = get$1(rpcId);
871
+ // @ts-ignore
872
+ return rpc.invokeAndTransfer(method, ...params);
873
+ },
874
+ set(rpc) {
875
+ set$2(rpcId, rpc);
876
+ },
877
+ async dispose() {
878
+ const rpc = get$1(rpcId);
879
+ await rpc.dispose();
880
+ }
881
+ };
882
+ };
883
+
884
+ const {
885
+ invoke,
886
+ set: set$1} = create$2(RendererWorker);
887
+ const getElectronVersion$1 = async () => {
888
+ return invoke('Process.getElectronVersion');
889
+ };
890
+ const getNodeVersion$1 = async () => {
891
+ return invoke('Process.getNodeVersion');
892
+ };
893
+ const getChromeVersion$1 = async () => {
894
+ return invoke('Process.getChromeVersion');
895
+ };
896
+ const getV8Version$1 = async () => {
897
+ return invoke('Process.getV8Version');
898
+ };
899
+ const setFocus = key => {
900
+ return invoke('Focus.setFocus', key);
901
+ };
902
+ const closeWidget$1 = async widgetId => {
903
+ return invoke('Viewlet.closeWidget', widgetId);
904
+ };
905
+ const writeClipBoardText = async text => {
906
+ await invoke('ClipBoard.writeText', /* text */text);
907
+ };
908
+ const showMessageBox$1 = async options => {
909
+ return invoke('ElectronDialog.showMessageBox', options);
910
+ };
911
+ const openWidget = async name => {
912
+ await invoke('Viewlet.openWidget', name);
913
+ };
914
+ const getWindowId$1 = async () => {
915
+ return invoke('GetWindowId.getWindowId');
916
+ };
917
+
918
+ const toCommandId = key => {
919
+ const dotIndex = key.indexOf('.');
920
+ return key.slice(dotIndex + 1);
921
+ };
922
+ const create$1 = () => {
834
923
  const states = Object.create(null);
924
+ const commandMapRef = {};
835
925
  return {
836
926
  get(uid) {
837
927
  return states[uid];
@@ -872,6 +962,15 @@ const create$2 = () => {
872
962
  };
873
963
  return wrapped;
874
964
  },
965
+ wrapGetter(fn) {
966
+ const wrapped = (uid, ...args) => {
967
+ const {
968
+ newState
969
+ } = states[uid];
970
+ return fn(newState, ...args);
971
+ };
972
+ return wrapped;
973
+ },
875
974
  diff(uid, modules, numbers) {
876
975
  const {
877
976
  oldState,
@@ -885,25 +984,35 @@ const create$2 = () => {
885
984
  }
886
985
  }
887
986
  return diffResult;
987
+ },
988
+ getCommandIds() {
989
+ const keys = Object.keys(commandMapRef);
990
+ const ids = keys.map(toCommandId);
991
+ return ids;
992
+ },
993
+ registerCommands(commandMap) {
994
+ Object.assign(commandMapRef, commandMap);
888
995
  }
889
996
  };
890
997
  };
891
998
 
892
999
  const {
893
- get: get$1,
894
- set: set$1,
1000
+ get,
1001
+ set,
895
1002
  dispose: dispose$1,
896
- wrapCommand
897
- } = create$2();
1003
+ wrapCommand,
1004
+ registerCommands,
1005
+ getCommandIds
1006
+ } = create$1();
898
1007
 
899
- const create$1 = uid => {
1008
+ const create = uid => {
900
1009
  const state = {
901
1010
  uid,
902
1011
  focusId: 0,
903
1012
  lines: [],
904
1013
  productName: ''
905
1014
  };
906
- set$1(uid, state, state);
1015
+ set(uid, state, state);
907
1016
  };
908
1017
 
909
1018
  const RenderFocus = 2;
@@ -943,7 +1052,7 @@ const diff2 = uid => {
943
1052
  const {
944
1053
  oldState,
945
1054
  newState
946
- } = get$1(uid);
1055
+ } = get(uid);
947
1056
  const diffResult = diff(oldState, newState);
948
1057
  return diffResult;
949
1058
  };
@@ -998,34 +1107,10 @@ const focusPrevious = state => {
998
1107
  };
999
1108
  };
1000
1109
 
1001
- const commandIds = ['dispose', 'focusNext', 'focusPrevious', 'handleClickButton', 'handleClickClose', 'handleClickCopy', 'handleClickOk', 'handleFocusIn'];
1002
-
1003
- const getCommandIds = () => {
1004
- return commandIds;
1005
- };
1006
-
1007
- const Tab = 2;
1008
- const Escape = 8;
1009
- const KeyCode = {
1010
- __proto__: null,
1011
- Escape,
1012
- Tab};
1013
- const Shift = 1 << 10 >>> 0;
1014
- const KeyModifier = {
1015
- __proto__: null,
1016
- Shift};
1017
1110
  const mergeClassNames = (...classNames) => {
1018
1111
  return classNames.filter(Boolean).join(' ');
1019
1112
  };
1020
- const Button$2 = 1;
1021
- const Div = 4;
1022
- const Text = 12;
1023
- const Br = 55;
1024
- const VirtualDomElements = {
1025
- __proto__: null,
1026
- Br,
1027
- Button: Button$2,
1028
- Div};
1113
+
1029
1114
  const text = data => {
1030
1115
  return {
1031
1116
  type: Text,
@@ -1038,134 +1123,21 @@ const FocusAbout = 4;
1038
1123
 
1039
1124
  const getKeyBindings = () => {
1040
1125
  return [{
1041
- key: KeyCode.Escape,
1126
+ key: Escape,
1042
1127
  command: 'About.handleClickClose',
1043
1128
  when: FocusAbout
1044
1129
  }, {
1045
- key: KeyCode.Tab,
1130
+ key: Tab,
1046
1131
  command: 'About.focusNext',
1047
1132
  when: FocusAbout
1048
1133
  }, {
1049
- key: KeyCode.Tab | KeyModifier.Shift,
1134
+ key: Tab | Shift,
1050
1135
  command: 'About.focusPrevious',
1051
1136
  when: FocusAbout
1052
1137
  }];
1053
1138
  };
1054
1139
 
1055
- const rpcs = Object.create(null);
1056
- const set$g = (id, rpc) => {
1057
- rpcs[id] = rpc;
1058
- };
1059
- const get = id => {
1060
- return rpcs[id];
1061
- };
1062
-
1063
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
1064
-
1065
- const create = rpcId => {
1066
- return {
1067
- // @ts-ignore
1068
- invoke(method, ...params) {
1069
- const rpc = get(rpcId);
1070
- // @ts-ignore
1071
- return rpc.invoke(method, ...params);
1072
- },
1073
- // @ts-ignore
1074
- invokeAndTransfer(method, ...params) {
1075
- const rpc = get(rpcId);
1076
- // @ts-ignore
1077
- return rpc.invokeAndTransfer(method, ...params);
1078
- },
1079
- set(rpc) {
1080
- set$g(rpcId, rpc);
1081
- },
1082
- async dispose() {
1083
- const rpc = get(rpcId);
1084
- await rpc.dispose();
1085
- }
1086
- };
1087
- };
1088
- const RendererWorker$1 = 1;
1089
- const {
1090
- invoke: invoke$4,
1091
- set: set$3} = create(RendererWorker$1);
1092
- const getElectronVersion$2 = async () => {
1093
- return invoke$4('Process.getElectronVersion');
1094
- };
1095
- const getNodeVersion$2 = async () => {
1096
- return invoke$4('Process.getNodeVersion');
1097
- };
1098
- const getChromeVersion$2 = async () => {
1099
- return invoke$4('Process.getChromeVersion');
1100
- };
1101
- const getV8Version$2 = async () => {
1102
- return invoke$4('Process.getV8Version');
1103
- };
1104
- const setFocus$1 = key => {
1105
- return invoke$4('Focus.setFocus', key);
1106
- };
1107
- const closeWidget$2 = async widgetId => {
1108
- return invoke$4('Viewlet.closeWidget', widgetId);
1109
- };
1110
- const writeClipBoardText$1 = async text => {
1111
- await invoke$4('ClipBoard.writeText', /* text */text);
1112
- };
1113
- const showMessageBox$2 = async options => {
1114
- return invoke$4('ElectronDialog.showMessageBox', options);
1115
- };
1116
- const openWidget$1 = async name => {
1117
- await invoke$4('Viewlet.openWidget', name);
1118
- };
1119
- const getWindowId$2 = async () => {
1120
- return invoke$4('GetWindowId.getWindowId');
1121
- };
1122
- const RendererWorker$2 = {
1123
- __proto__: null,
1124
- closeWidget: closeWidget$2,
1125
- getChromeVersion: getChromeVersion$2,
1126
- getElectronVersion: getElectronVersion$2,
1127
- getNodeVersion: getNodeVersion$2,
1128
- getV8Version: getV8Version$2,
1129
- getWindowId: getWindowId$2,
1130
- openWidget: openWidget$1,
1131
- set: set$3,
1132
- setFocus: setFocus$1,
1133
- showMessageBox: showMessageBox$2,
1134
- writeClipBoardText: writeClipBoardText$1
1135
- };
1136
-
1137
- const {
1138
- closeWidget: closeWidget$1,
1139
- getChromeVersion: getChromeVersion$1,
1140
- getElectronVersion: getElectronVersion$1,
1141
- getNodeVersion: getNodeVersion$1,
1142
- getV8Version: getV8Version$1,
1143
- getWindowId: getWindowId$1,
1144
- openWidget,
1145
- set,
1146
- setFocus,
1147
- showMessageBox: showMessageBox$1,
1148
- writeClipBoardText
1149
- } = RendererWorker$2;
1150
-
1151
- const RendererWorker = {
1152
- __proto__: null,
1153
- closeWidget: closeWidget$1,
1154
- getChromeVersion: getChromeVersion$1,
1155
- getElectronVersion: getElectronVersion$1,
1156
- getNodeVersion: getNodeVersion$1,
1157
- getV8Version: getV8Version$1,
1158
- getWindowId: getWindowId$1,
1159
- openWidget,
1160
- set,
1161
- setFocus,
1162
- showMessageBox: showMessageBox$1,
1163
- writeClipBoardText
1164
- };
1165
-
1166
- const {
1167
- closeWidget
1168
- } = RendererWorker;
1140
+ const closeWidget = closeWidget$1;
1169
1141
 
1170
1142
  const About$1 = 'About';
1171
1143
 
@@ -1528,24 +1500,16 @@ const getBrowser = () => {
1528
1500
  const version = '0.0.0-dev';
1529
1501
  const commit = 'unknown commit';
1530
1502
  const date = '';
1531
- const {
1532
- getElectronVersion
1533
- } = RendererWorker;
1534
- const {
1535
- getNodeVersion
1536
- } = RendererWorker;
1537
- const {
1538
- getChromeVersion
1539
- } = RendererWorker;
1503
+ const getElectronVersion = getElectronVersion$1;
1504
+ const getNodeVersion = getNodeVersion$1;
1505
+ const getChromeVersion = getChromeVersion$1;
1540
1506
  const getVersion = () => {
1541
1507
  return version;
1542
1508
  };
1543
1509
  const getCommit = () => {
1544
1510
  return commit;
1545
1511
  };
1546
- const {
1547
- getV8Version
1548
- } = RendererWorker;
1512
+ const getV8Version = getV8Version$1;
1549
1513
  const getDate = () => {
1550
1514
  return date;
1551
1515
  };
@@ -1583,14 +1547,14 @@ const loadContent2 = uid => {
1583
1547
  const lines = getDetailStringWeb();
1584
1548
  const {
1585
1549
  oldState
1586
- } = get$1(uid);
1550
+ } = get(uid);
1587
1551
  const newState = {
1588
1552
  ...oldState,
1589
1553
  productName: productNameLong$1,
1590
1554
  lines,
1591
1555
  focusId: Ok$2
1592
1556
  };
1593
- set$1(uid, oldState, newState);
1557
+ set(uid, oldState, newState);
1594
1558
  };
1595
1559
 
1596
1560
  const Ok = 'Ok';
@@ -1655,7 +1619,7 @@ const HandleContextMenu = 5;
1655
1619
  const HandleFocusIn = 6;
1656
1620
 
1657
1621
  const br = {
1658
- type: VirtualDomElements.Br,
1622
+ type: Br,
1659
1623
  childCount: 0
1660
1624
  };
1661
1625
  const renderLine = (line, index) => {
@@ -1667,7 +1631,7 @@ const renderLine = (line, index) => {
1667
1631
 
1668
1632
  const getAboutContentVirtualDom = lines => {
1669
1633
  const dom = [{
1670
- type: VirtualDomElements.Div,
1634
+ type: Div,
1671
1635
  className: DialogMessage,
1672
1636
  childCount: lines.length * 2 - 1
1673
1637
  }, ...lines.flatMap(renderLine)];
@@ -1681,7 +1645,7 @@ const Dialog = 'dialog';
1681
1645
 
1682
1646
  const getPrimaryButtonVirtualDom = (message, name) => {
1683
1647
  return [{
1684
- type: VirtualDomElements.Button,
1648
+ type: Button$2,
1685
1649
  className: mergeClassNames(Button$1, ButtonPrimary),
1686
1650
  onClick: HandleClickButton,
1687
1651
  childCount: 1,
@@ -1691,7 +1655,7 @@ const getPrimaryButtonVirtualDom = (message, name) => {
1691
1655
 
1692
1656
  const getSecondaryButtonVirtualDom = (message, name) => {
1693
1657
  return [{
1694
- type: VirtualDomElements.Button,
1658
+ type: Button$2,
1695
1659
  className: mergeClassNames(Button$1, ButtonSecondary),
1696
1660
  onClick: HandleClickButton,
1697
1661
  childCount: 1,
@@ -1710,7 +1674,7 @@ const Focusable = -1;
1710
1674
 
1711
1675
  const getDialogVirtualDom = (content, closeMessage, infoMessage, okMessage, copyMessage, productName) => {
1712
1676
  const dom = [{
1713
- type: VirtualDomElements.Div,
1677
+ type: Div,
1714
1678
  className: DialogContent,
1715
1679
  tabIndex: Focusable,
1716
1680
  role: Dialog,
@@ -1719,41 +1683,41 @@ const getDialogVirtualDom = (content, closeMessage, infoMessage, okMessage, copy
1719
1683
  onFocusIn: HandleFocusIn,
1720
1684
  childCount: 3
1721
1685
  }, {
1722
- type: VirtualDomElements.Div,
1686
+ type: Div,
1723
1687
  className: DialogToolBarRow,
1724
1688
  childCount: 1
1725
1689
  }, {
1726
- type: VirtualDomElements.Div,
1690
+ type: Div,
1727
1691
  className: DialogClose,
1728
1692
  ariaLabel: closeMessage,
1729
1693
  role: Button,
1730
1694
  onClick: HandleClickClose,
1731
1695
  childCount: 1
1732
1696
  }, {
1733
- type: VirtualDomElements.Div,
1697
+ type: Div,
1734
1698
  className: mergeClassNames(MaskIcon, MaskIconClose),
1735
1699
  childCount: 0
1736
1700
  }, {
1737
- type: VirtualDomElements.Div,
1701
+ type: Div,
1738
1702
  className: DialogMessageRow,
1739
1703
  childCount: 2
1740
1704
  }, {
1741
- type: VirtualDomElements.Div,
1705
+ type: Div,
1742
1706
  className: mergeClassNames(DialogIcon$1, DialogInfoIcon, MaskIcon, MaskIconInfo),
1743
1707
  id: DialogIcon,
1744
1708
  ariaLabel: infoMessage,
1745
1709
  childCount: 0
1746
1710
  }, {
1747
- type: VirtualDomElements.Div,
1711
+ type: Div,
1748
1712
  className: DialogContentRight,
1749
1713
  childCount: 2
1750
1714
  }, {
1751
- type: VirtualDomElements.Div,
1715
+ type: Div,
1752
1716
  id: DialogHeading,
1753
1717
  className: DialogHeading$1,
1754
1718
  childCount: 1
1755
1719
  }, text(productName), ...content, {
1756
- type: VirtualDomElements.Div,
1720
+ type: Div,
1757
1721
  className: DialogButtonsRow,
1758
1722
  childCount: 2
1759
1723
  }, ...getSecondaryButtonVirtualDom(okMessage, Ok$1), ...getPrimaryButtonVirtualDom(copyMessage, Copy$1)];
@@ -1763,7 +1727,7 @@ const getDialogVirtualDom = (content, closeMessage, infoMessage, okMessage, copy
1763
1727
  const getAboutVirtualDom = (productName, lines, closeMessage, okMessage, copyMessage, infoMessage) => {
1764
1728
  const content = getAboutContentVirtualDom(lines);
1765
1729
  return [{
1766
- type: VirtualDomElements.Div,
1730
+ type: Div,
1767
1731
  className: mergeClassNames(Viewlet, About),
1768
1732
  onContextMenu: HandleContextMenu,
1769
1733
  childCount: 1
@@ -1822,8 +1786,8 @@ const doRender = (uid, diffResult) => {
1822
1786
  const {
1823
1787
  oldState,
1824
1788
  newState
1825
- } = get$1(uid);
1826
- set$1(uid, newState, newState);
1789
+ } = get(uid);
1790
+ set(uid, newState, newState);
1827
1791
  const commands = applyRender(oldState, newState, diffResult);
1828
1792
  return commands;
1829
1793
  };
@@ -1851,9 +1815,7 @@ const showAboutDefault = async () => {
1851
1815
  await openWidget(About$1);
1852
1816
  };
1853
1817
 
1854
- const {
1855
- getWindowId
1856
- } = RendererWorker;
1818
+ const getWindowId = getWindowId$1;
1857
1819
 
1858
1820
  const productNameLong = 'Lvce Editor - OSS';
1859
1821
  const getProductNameLong = () => {
@@ -1915,7 +1877,7 @@ const showAbout = async platform => {
1915
1877
  };
1916
1878
 
1917
1879
  const commandMap = {
1918
- 'About.create': create$1,
1880
+ 'About.create': create,
1919
1881
  'About.diff2': diff2,
1920
1882
  'About.dispose': dispose,
1921
1883
  'About.focusNext': wrapCommand(focusNext),
@@ -1935,10 +1897,11 @@ const commandMap = {
1935
1897
  };
1936
1898
 
1937
1899
  const listen = async () => {
1900
+ registerCommands(commandMap);
1938
1901
  const rpc = await WebWorkerRpcClient.create({
1939
1902
  commandMap: commandMap
1940
1903
  });
1941
- set(rpc);
1904
+ set$1(rpc);
1942
1905
  };
1943
1906
 
1944
1907
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/about-view",
3
- "version": "5.11.0",
3
+ "version": "6.0.0",
4
4
  "description": "About View Worker",
5
5
  "keywords": [
6
6
  "about-view"