@lvce-editor/about-view 5.0.0 → 5.2.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.
@@ -395,7 +395,7 @@ const set$2 = (id, fn) => {
395
395
  const get$2 = id => {
396
396
  return callbacks[id];
397
397
  };
398
- const remove$1 = id => {
398
+ const remove = id => {
399
399
  delete callbacks[id];
400
400
  };
401
401
  let id = 0;
@@ -414,7 +414,7 @@ const registerPromise = () => {
414
414
  promise
415
415
  };
416
416
  };
417
- const create$2 = (method, params) => {
417
+ const create$2$1 = (method, params) => {
418
418
  const {
419
419
  id,
420
420
  promise
@@ -572,7 +572,7 @@ const resolve = (id, response) => {
572
572
  return;
573
573
  }
574
574
  fn(response);
575
- remove$1(id);
575
+ remove(id);
576
576
  };
577
577
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
578
578
  const getErrorType = prettyError => {
@@ -706,7 +706,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
706
706
  const {
707
707
  message,
708
708
  promise
709
- } = create$2(method, params);
709
+ } = create$2$1(method, params);
710
710
  if (useSendAndTransfer && ipc.sendAndTransfer) {
711
711
  ipc.sendAndTransfer(message);
712
712
  } else {
@@ -756,6 +756,9 @@ const createRpc = ipc => {
756
756
  },
757
757
  invokeAndTransfer(method, ...params) {
758
758
  return invokeAndTransfer(ipc, method, ...params);
759
+ },
760
+ async dispose() {
761
+ await ipc?.dispose();
759
762
  }
760
763
  };
761
764
  return rpc;
@@ -790,7 +793,7 @@ const listen$1 = async (module, options) => {
790
793
  const ipc = module.wrap(rawIpc);
791
794
  return ipc;
792
795
  };
793
- const create$1 = async ({
796
+ const create$2 = async ({
794
797
  commandMap
795
798
  }) => {
796
799
  // TODO create a commandMap per rpc instance
@@ -802,23 +805,42 @@ const create$1 = async ({
802
805
  };
803
806
  const WebWorkerRpcClient = {
804
807
  __proto__: null,
805
- create: create$1
808
+ create: create$2
806
809
  };
807
810
 
808
- const states = Object.create(null);
809
- const get$1 = uid => {
810
- return states[uid];
811
- };
812
- const remove = uid => {
813
- delete states[uid];
814
- };
815
- const set$1 = (uid, oldState, newState) => {
816
- states[uid] = {
817
- oldState,
818
- newState
811
+ const create$1 = () => {
812
+ const states = Object.create(null);
813
+ return {
814
+ get(uid) {
815
+ return states[uid];
816
+ },
817
+ set(uid, oldState, newState) {
818
+ states[uid] = {
819
+ oldState,
820
+ newState
821
+ };
822
+ },
823
+ dispose(uid) {
824
+ delete states[uid];
825
+ },
826
+ getKeys() {
827
+ return Object.keys(states).map(key => {
828
+ return Number.parseInt(key);
829
+ });
830
+ },
831
+ clear() {
832
+ for (const key of Object.keys(states)) {
833
+ delete states[key];
834
+ }
835
+ }
819
836
  };
820
837
  };
821
838
 
839
+ const {
840
+ get: get$1,
841
+ set: set$1,
842
+ dispose: dispose$1} = create$1();
843
+
822
844
  const create = uid => {
823
845
  const state = {
824
846
  uid,
@@ -830,20 +852,26 @@ const create = uid => {
830
852
  };
831
853
 
832
854
  const RenderFocus = 2;
855
+ const RenderFocusContext = 4;
833
856
  const RenderAbout = 3;
834
857
 
835
- const diffType$1 = RenderAbout;
836
- const isEqual$1 = (oldState, newState) => {
858
+ const diffType$2 = RenderAbout;
859
+ const isEqual$2 = (oldState, newState) => {
837
860
  return oldState.productName === newState.productName && JSON.stringify(oldState.lines) === JSON.stringify(newState.lines);
838
861
  };
839
862
 
840
- const diffType = RenderFocus;
863
+ const diffType$1 = RenderFocus;
864
+ const isEqual$1 = (oldState, newState) => {
865
+ return oldState.focusId === newState.focusId;
866
+ };
867
+
868
+ const diffType = RenderFocusContext;
841
869
  const isEqual = (oldState, newState) => {
842
870
  return oldState.focusId === newState.focusId;
843
871
  };
844
872
 
845
- const modules = [isEqual$1, isEqual];
846
- const numbers = [diffType$1, diffType];
873
+ const modules = [isEqual$2, isEqual$1, isEqual];
874
+ const numbers = [diffType$2, diffType$1, diffType];
847
875
 
848
876
  const diff = (oldState, newState) => {
849
877
  const diffResult = [];
@@ -866,7 +894,7 @@ const diff2 = uid => {
866
894
  };
867
895
 
868
896
  const dispose = uid => {
869
- remove(uid);
897
+ dispose$1(uid);
870
898
  };
871
899
 
872
900
  const None = 0;
@@ -983,14 +1011,25 @@ const handleClickCopy = async state => {
983
1011
  return state;
984
1012
  };
985
1013
 
1014
+ const closeWidget = async id => {
1015
+ await invoke('Viewlet.closeWidget', id);
1016
+ };
1017
+
986
1018
  const handleClickOk = async state => {
987
- await invoke('Viewlet.closeWidget', 'About');
1019
+ await closeWidget('About');
988
1020
  return state;
989
1021
  };
990
1022
 
991
1023
  const handleFocusIn = async state => {
1024
+ // TODO remove side effect
992
1025
  await invoke('Focus.setFocus', FocusAbout);
993
- return state;
1026
+ if (state.focusId) {
1027
+ return state;
1028
+ }
1029
+ return {
1030
+ ...state,
1031
+ focusId: Ok$2
1032
+ };
994
1033
  };
995
1034
 
996
1035
  const OneSecondAgo = '1 second ago';
@@ -1413,9 +1452,12 @@ const HandleFocusIn = 'handleFocusIn';
1413
1452
 
1414
1453
  const Button$1 = 1;
1415
1454
  const Div = 4;
1416
- const Text = 12;
1417
1455
  const Br = 55;
1418
1456
 
1457
+ const mergeClassNames = (...classNames) => {
1458
+ return classNames.filter(Boolean).join(' ');
1459
+ };
1460
+ const Text = 12;
1419
1461
  const text = data => {
1420
1462
  return {
1421
1463
  type: Text,
@@ -1449,14 +1491,6 @@ const True = 'true';
1449
1491
  const Button = 'button';
1450
1492
  const Dialog = 'dialog';
1451
1493
 
1452
- const joinBySpace = (...items) => {
1453
- return items.join(' ');
1454
- };
1455
-
1456
- const mergeClassNames = (...classNames) => {
1457
- return joinBySpace(...classNames.filter(Boolean));
1458
- };
1459
-
1460
1494
  const getPrimaryButtonVirtualDom = (message, onClick, name) => {
1461
1495
  return [{
1462
1496
  type: Button$1,
@@ -1483,6 +1517,10 @@ const DialogHeading = 'DialogHeading';
1483
1517
  const Ok = 'Ok';
1484
1518
  const Copy = 'Copy';
1485
1519
 
1520
+ const joinBySpace = (...items) => {
1521
+ return items.join(' ');
1522
+ };
1523
+
1486
1524
  const Focusable = -1;
1487
1525
 
1488
1526
  const getDialogVirtualDom = (content, closeMessage, infoMessage, okMessage, copyMessage, productName) => {
@@ -1569,12 +1607,18 @@ const renderFocus = (oldState, newState) => {
1569
1607
  return ['Viewlet.focusElementByName', name];
1570
1608
  };
1571
1609
 
1610
+ const renderFocusContext = (oldState, newState) => {
1611
+ return ['Viewlet.setFocusContext', FocusAbout];
1612
+ };
1613
+
1572
1614
  const getRenderer = diffType => {
1573
1615
  switch (diffType) {
1574
1616
  case RenderAbout:
1575
1617
  return renderDialog;
1576
1618
  case RenderFocus:
1577
1619
  return renderFocus;
1620
+ case RenderFocusContext:
1621
+ return renderFocusContext;
1578
1622
  default:
1579
1623
  throw new Error('unknown renderer');
1580
1624
  }
@@ -1594,8 +1638,8 @@ const doRender = (uid, diffResult) => {
1594
1638
  oldState,
1595
1639
  newState
1596
1640
  } = get$1(uid);
1597
- const commands = applyRender(oldState, newState, diffResult);
1598
1641
  set$1(uid, newState, newState);
1642
+ const commands = applyRender(oldState, newState, diffResult);
1599
1643
  return commands;
1600
1644
  };
1601
1645
 
@@ -1690,18 +1734,33 @@ const showAbout = async platform => {
1690
1734
  await fn();
1691
1735
  };
1692
1736
 
1737
+ const wrapCommand = fn => {
1738
+ const wrapped = async (uid, ...args) => {
1739
+ const {
1740
+ newState
1741
+ } = get$1(uid);
1742
+ const newerState = await fn(newState, ...args);
1743
+ if (newState === newerState) {
1744
+ return;
1745
+ }
1746
+ const latest = get$1(uid);
1747
+ set$1(uid, latest.oldState, newerState);
1748
+ };
1749
+ return wrapped;
1750
+ };
1751
+
1693
1752
  const commandMap = {
1694
1753
  'About.create': create,
1695
1754
  'About.diff2': diff2,
1696
1755
  'About.dispose': dispose,
1697
- 'About.focusNext': focusNext,
1698
- 'About.focusPrevious': focusPrevious,
1756
+ 'About.focusNext': wrapCommand(focusNext),
1757
+ 'About.focusPrevious': wrapCommand(focusPrevious),
1699
1758
  'About.getCommandIds': getCommandIds,
1700
1759
  'About.getKeyBindings': getKeyBindings,
1701
- 'About.handleClickClose': handleClickClose,
1702
- 'About.handleClickCopy': handleClickCopy,
1703
- 'About.handleClickOk': handleClickOk,
1704
- 'About.handleFocusIn': handleFocusIn,
1760
+ 'About.handleClickClose': wrapCommand(handleClickClose),
1761
+ 'About.handleClickCopy': wrapCommand(handleClickCopy),
1762
+ 'About.handleClickOk': wrapCommand(handleClickOk),
1763
+ 'About.handleFocusIn': wrapCommand(handleFocusIn),
1705
1764
  'About.loadContent2': loadContent2,
1706
1765
  'About.render2': doRender,
1707
1766
  'About.renderEventListeners': renderEventListeners,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/about-view",
3
- "version": "5.0.0",
3
+ "version": "5.2.0",
4
4
  "description": "About View Worker",
5
5
  "keywords": [
6
6
  "about-view"