@lvce-editor/about-view 4.17.0 → 5.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.
@@ -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
@@ -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 {
@@ -790,7 +790,7 @@ const listen$1 = async (module, options) => {
790
790
  const ipc = module.wrap(rawIpc);
791
791
  return ipc;
792
792
  };
793
- const create$1 = async ({
793
+ const create$2 = async ({
794
794
  commandMap
795
795
  }) => {
796
796
  // TODO create a commandMap per rpc instance
@@ -802,20 +802,42 @@ const create$1 = async ({
802
802
  };
803
803
  const WebWorkerRpcClient = {
804
804
  __proto__: null,
805
- create: create$1
805
+ create: create$2
806
806
  };
807
807
 
808
- const states = Object.create(null);
809
- const get$1 = uid => {
810
- return states[uid];
811
- };
812
- const set$1 = (uid, oldState, newState) => {
813
- states[uid] = {
814
- oldState,
815
- newState
808
+ const create$1 = () => {
809
+ const states = Object.create(null);
810
+ return {
811
+ get(uid) {
812
+ return states[uid];
813
+ },
814
+ set(uid, oldState, newState) {
815
+ states[uid] = {
816
+ oldState,
817
+ newState
818
+ };
819
+ },
820
+ dispose(uid) {
821
+ delete states[uid];
822
+ },
823
+ getKeys() {
824
+ return Object.keys(states).map(key => {
825
+ return Number.parseInt(key);
826
+ });
827
+ },
828
+ clear() {
829
+ for (const key of Object.keys(states)) {
830
+ delete states[key];
831
+ }
832
+ }
816
833
  };
817
834
  };
818
835
 
836
+ const {
837
+ get: get$1,
838
+ set: set$1,
839
+ dispose: dispose$1} = create$1();
840
+
819
841
  const create = uid => {
820
842
  const state = {
821
843
  uid,
@@ -827,20 +849,26 @@ const create = uid => {
827
849
  };
828
850
 
829
851
  const RenderFocus = 2;
852
+ const RenderFocusContext = 4;
830
853
  const RenderAbout = 3;
831
854
 
832
- const diffType$1 = RenderAbout;
833
- const isEqual$1 = (oldState, newState) => {
855
+ const diffType$2 = RenderAbout;
856
+ const isEqual$2 = (oldState, newState) => {
834
857
  return oldState.productName === newState.productName && JSON.stringify(oldState.lines) === JSON.stringify(newState.lines);
835
858
  };
836
859
 
837
- const diffType = RenderFocus;
860
+ const diffType$1 = RenderFocus;
861
+ const isEqual$1 = (oldState, newState) => {
862
+ return oldState.focusId === newState.focusId;
863
+ };
864
+
865
+ const diffType = RenderFocusContext;
838
866
  const isEqual = (oldState, newState) => {
839
867
  return oldState.focusId === newState.focusId;
840
868
  };
841
869
 
842
- const modules = [isEqual$1, isEqual];
843
- const numbers = [diffType$1, diffType];
870
+ const modules = [isEqual$2, isEqual$1, isEqual];
871
+ const numbers = [diffType$2, diffType$1, diffType];
844
872
 
845
873
  const diff = (oldState, newState) => {
846
874
  const diffResult = [];
@@ -862,6 +890,10 @@ const diff2 = uid => {
862
890
  return diffResult;
863
891
  };
864
892
 
893
+ const dispose = uid => {
894
+ dispose$1(uid);
895
+ };
896
+
865
897
  const None = 0;
866
898
  const Ok$2 = 1;
867
899
  const Copy$2 = 2;
@@ -908,6 +940,95 @@ const focusPrevious = state => {
908
940
  };
909
941
  };
910
942
 
943
+ const commandIds = ['handleClickClose', 'handleClickOk', 'handleClickCopy', 'handleFocusIn', 'focusNext', 'focusPrevious'];
944
+ const getCommandIds = () => {
945
+ return commandIds;
946
+ };
947
+
948
+ const Tab = 2;
949
+ const Escape = 8;
950
+
951
+ const Shift = 1 << 10 >>> 0;
952
+
953
+ const FocusAbout = 4;
954
+
955
+ const getKeyBindings = () => {
956
+ return [{
957
+ key: Escape,
958
+ command: 'About.handleClickClose',
959
+ when: FocusAbout
960
+ }, {
961
+ key: Tab,
962
+ command: 'About.focusNext',
963
+ when: FocusAbout
964
+ }, {
965
+ key: Tab | Shift,
966
+ command: 'About.focusPrevious',
967
+ when: FocusAbout
968
+ }];
969
+ };
970
+
971
+ const RendererWorker = 1;
972
+
973
+ const rpcs = Object.create(null);
974
+ const set = (id, rpc) => {
975
+ rpcs[id] = rpc;
976
+ };
977
+ const get = id => {
978
+ return rpcs[id];
979
+ };
980
+
981
+ const invoke = (method, ...params) => {
982
+ const rpc = get(RendererWorker);
983
+ // @ts-ignore
984
+ return rpc.invoke(method, ...params);
985
+ };
986
+
987
+ const handleClickClose = async state => {
988
+ await invoke('Viewlet.closeWidget', 'About');
989
+ return state;
990
+ };
991
+
992
+ const writeText = async text => {
993
+ await invoke('ClipBoard.writeText', /* text */text);
994
+ };
995
+
996
+ const NewLine = '\n';
997
+
998
+ const joinLines = lines => {
999
+ return lines.join(NewLine);
1000
+ };
1001
+
1002
+ const handleClickCopy = async state => {
1003
+ const {
1004
+ lines
1005
+ } = state;
1006
+ const message = joinLines(lines);
1007
+ await writeText(message);
1008
+ return state;
1009
+ };
1010
+
1011
+ const closeWidget = async id => {
1012
+ await invoke('Viewlet.closeWidget', id);
1013
+ };
1014
+
1015
+ const handleClickOk = async state => {
1016
+ await closeWidget('About');
1017
+ return state;
1018
+ };
1019
+
1020
+ const handleFocusIn = async state => {
1021
+ // TODO remove side effect
1022
+ await invoke('Focus.setFocus', FocusAbout);
1023
+ if (state.focusId) {
1024
+ return state;
1025
+ }
1026
+ return {
1027
+ ...state,
1028
+ focusId: Ok$2
1029
+ };
1030
+ };
1031
+
911
1032
  const OneSecondAgo = '1 second ago';
912
1033
  const SomeSecondsAgo = '{PH1} seconds ago';
913
1034
  const OneMinuteAgo = '1 minute ago';
@@ -1192,26 +1313,8 @@ const formatAboutDate = (isoDate, now) => {
1192
1313
  return `${isoDate} (${ago})`;
1193
1314
  };
1194
1315
 
1195
- const NewLine = '\n';
1196
-
1197
- const joinLines = lines => {
1198
- return lines.join(NewLine);
1199
- };
1200
-
1201
- const RendererWorker = 1;
1202
-
1203
- const rpcs = Object.create(null);
1204
- const set = (id, rpc) => {
1205
- rpcs[id] = rpc;
1206
- };
1207
- const get = id => {
1208
- return rpcs[id];
1209
- };
1210
-
1211
- const invoke = (method, ...params) => {
1212
- const rpc = get(RendererWorker);
1213
- // @ts-ignore
1214
- return rpc.invoke(method, ...params);
1316
+ const getBrowser = () => {
1317
+ return `${navigator.userAgent}`;
1215
1318
  };
1216
1319
 
1217
1320
  const version = '0.0.0-dev';
@@ -1255,18 +1358,6 @@ const Process = {
1255
1358
  version
1256
1359
  };
1257
1360
 
1258
- const getDetailString = async () => {
1259
- const [electronVersion, nodeVersion, chromeVersion, version, commit, v8Version, date] = await Promise.all([getElectronVersion(), getNodeVersion(), getChromeVersion(), getVersion(), getCommit(), getV8Version(), getDate()]);
1260
- const now = Date.now();
1261
- const formattedDate = formatAboutDate(date, now);
1262
- const lines = [`Version: ${version}`, `Commit: ${commit}`, `Date: ${formattedDate}`, `Electron: ${electronVersion}`, `Chromium: ${chromeVersion}`, `Node: ${nodeVersion}`, `V8: ${v8Version}`];
1263
- return joinLines(lines);
1264
- };
1265
-
1266
- const getBrowser = () => {
1267
- return `${navigator.userAgent}`;
1268
- };
1269
-
1270
1361
  const getDetailStringWeb = () => {
1271
1362
  const {
1272
1363
  date,
@@ -1280,6 +1371,57 @@ const getDetailStringWeb = () => {
1280
1371
  return lines;
1281
1372
  };
1282
1373
 
1374
+ const loadContent2 = uid => {
1375
+ const lines = getDetailStringWeb();
1376
+ const {
1377
+ oldState
1378
+ } = get$1(uid);
1379
+ const newState = {
1380
+ ...oldState,
1381
+ productName: productNameLong$1,
1382
+ lines,
1383
+ focusId: Ok$2
1384
+ };
1385
+ set$1(uid, oldState, newState);
1386
+ };
1387
+
1388
+ const Ok$1 = 'Ok';
1389
+ const Copy$1 = 'Copy';
1390
+ const Info$1 = 'Info';
1391
+ const CloseDialog = 'Close Dialog';
1392
+
1393
+ const ok = () => {
1394
+ return i18nString(Ok$1);
1395
+ };
1396
+ const copy = () => {
1397
+ return i18nString(Copy$1);
1398
+ };
1399
+ const info = () => {
1400
+ return i18nString(Info$1);
1401
+ };
1402
+ const closeDialog = () => {
1403
+ return i18nString(CloseDialog);
1404
+ };
1405
+
1406
+ const createViewModel = state => {
1407
+ const okMessage = ok();
1408
+ const copyMessage = copy();
1409
+ const closeMessage = closeDialog();
1410
+ const infoMessage = info();
1411
+ const {
1412
+ productName,
1413
+ lines
1414
+ } = state;
1415
+ return {
1416
+ productName,
1417
+ lines,
1418
+ closeMessage,
1419
+ okMessage,
1420
+ copyMessage,
1421
+ infoMessage
1422
+ };
1423
+ };
1424
+
1283
1425
  const Button$2 = 'Button';
1284
1426
  const ButtonPrimary = 'ButtonPrimary';
1285
1427
  const ButtonSecondary = 'ButtonSecondary';
@@ -1307,9 +1449,12 @@ const HandleFocusIn = 'handleFocusIn';
1307
1449
 
1308
1450
  const Button$1 = 1;
1309
1451
  const Div = 4;
1310
- const Text = 12;
1311
1452
  const Br = 55;
1312
1453
 
1454
+ const mergeClassNames = (...classNames) => {
1455
+ return classNames.filter(Boolean).join(' ');
1456
+ };
1457
+ const Text = 12;
1313
1458
  const text = data => {
1314
1459
  return {
1315
1460
  type: Text,
@@ -1343,14 +1488,6 @@ const True = 'true';
1343
1488
  const Button = 'button';
1344
1489
  const Dialog = 'dialog';
1345
1490
 
1346
- const joinBySpace = (...items) => {
1347
- return items.join(' ');
1348
- };
1349
-
1350
- const mergeClassNames = (...classNames) => {
1351
- return joinBySpace(...classNames.filter(Boolean));
1352
- };
1353
-
1354
1491
  const getPrimaryButtonVirtualDom = (message, onClick, name) => {
1355
1492
  return [{
1356
1493
  type: Button$1,
@@ -1374,8 +1511,12 @@ const getSecondaryButtonVirtualDom = (message, onClick, name) => {
1374
1511
  const DialogIcon = 'DialogIcon';
1375
1512
  const DialogHeading = 'DialogHeading';
1376
1513
 
1377
- const Ok$1 = 'Ok';
1378
- const Copy$1 = 'Copy';
1514
+ const Ok = 'Ok';
1515
+ const Copy = 'Copy';
1516
+
1517
+ const joinBySpace = (...items) => {
1518
+ return items.join(' ');
1519
+ };
1379
1520
 
1380
1521
  const Focusable = -1;
1381
1522
 
@@ -1427,7 +1568,7 @@ const getDialogVirtualDom = (content, closeMessage, infoMessage, okMessage, copy
1427
1568
  type: Div,
1428
1569
  className: DialogButtonsRow,
1429
1570
  childCount: 2
1430
- }, ...getSecondaryButtonVirtualDom(okMessage, HandleClickOk, Ok$1), ...getPrimaryButtonVirtualDom(copyMessage, HandleClickCopy, Copy$1)];
1571
+ }, ...getSecondaryButtonVirtualDom(okMessage, HandleClickOk, Ok), ...getPrimaryButtonVirtualDom(copyMessage, HandleClickCopy, Copy)];
1431
1572
  return dom;
1432
1573
  };
1433
1574
 
@@ -1441,123 +1582,6 @@ const getAboutVirtualDom = (productName, lines, closeMessage, okMessage, copyMes
1441
1582
  }, ...getDialogVirtualDom(content, closeMessage, infoMessage, okMessage, copyMessage, productName)];
1442
1583
  };
1443
1584
 
1444
- const commandIds = ['handleClickClose', 'handleClickOk', 'handleClickCopy', 'handleFocusIn', 'focusNext', 'focusPrevious'];
1445
- const getCommandIds = () => {
1446
- return commandIds;
1447
- };
1448
-
1449
- const Tab = 2;
1450
- const Escape = 8;
1451
-
1452
- const Shift = 1 << 10 >>> 0;
1453
-
1454
- const FocusAbout = 4;
1455
-
1456
- const getKeyBindings = () => {
1457
- return [{
1458
- key: Escape,
1459
- command: 'About.handleClickClose',
1460
- when: FocusAbout
1461
- }, {
1462
- key: Tab,
1463
- command: 'About.focusNext',
1464
- when: FocusAbout
1465
- }, {
1466
- key: Tab | Shift,
1467
- command: 'About.focusPrevious',
1468
- when: FocusAbout
1469
- }];
1470
- };
1471
-
1472
- const handleClickClose = async state => {
1473
- await invoke('Viewlet.closeWidget', 'About');
1474
- return state;
1475
- };
1476
-
1477
- const writeText = async text => {
1478
- await invoke('ClipBoard.writeText', /* text */text);
1479
- };
1480
-
1481
- const handleClickCopy = async state => {
1482
- const {
1483
- lines
1484
- } = state;
1485
- const message = joinLines(lines);
1486
- await writeText(message);
1487
- return state;
1488
- };
1489
-
1490
- const handleClickOk = async state => {
1491
- await invoke('Viewlet.closeWidget', 'About');
1492
- return state;
1493
- };
1494
-
1495
- const handleFocusIn = async state => {
1496
- await invoke('Focus.setFocus', FocusAbout);
1497
- return state;
1498
- };
1499
-
1500
- const loadContent2 = uid => {
1501
- const lines = getDetailStringWeb();
1502
- const {
1503
- oldState
1504
- } = get$1(uid);
1505
- const newState = {
1506
- ...oldState,
1507
- productName: productNameLong$1,
1508
- lines,
1509
- focusId: Ok$2
1510
- };
1511
- set$1(uid, oldState, newState);
1512
- };
1513
-
1514
- const loadContent = state => {
1515
- const lines = getDetailStringWeb();
1516
- return {
1517
- ...state,
1518
- productName: productNameLong$1,
1519
- lines,
1520
- focusId: Ok$2
1521
- };
1522
- };
1523
-
1524
- const Ok = 'Ok';
1525
- const Copy = 'Copy';
1526
- const Info$1 = 'Info';
1527
- const CloseDialog = 'Close Dialog';
1528
-
1529
- const ok = () => {
1530
- return i18nString(Ok);
1531
- };
1532
- const copy = () => {
1533
- return i18nString(Copy);
1534
- };
1535
- const info = () => {
1536
- return i18nString(Info$1);
1537
- };
1538
- const closeDialog = () => {
1539
- return i18nString(CloseDialog);
1540
- };
1541
-
1542
- const createViewModel = state => {
1543
- const okMessage = ok();
1544
- const copyMessage = copy();
1545
- const closeMessage = closeDialog();
1546
- const infoMessage = info();
1547
- const {
1548
- productName,
1549
- lines
1550
- } = state;
1551
- return {
1552
- productName,
1553
- lines,
1554
- closeMessage,
1555
- okMessage,
1556
- copyMessage,
1557
- infoMessage
1558
- };
1559
- };
1560
-
1561
1585
  const renderDialog = (oldState, newState) => {
1562
1586
  const viewModel = createViewModel(newState);
1563
1587
  const dom = getAboutVirtualDom(viewModel.productName, viewModel.lines, viewModel.closeMessage, viewModel.okMessage, viewModel.copyMessage, viewModel.infoMessage);
@@ -1567,9 +1591,9 @@ const renderDialog = (oldState, newState) => {
1567
1591
  const getFocusSelector = focusId => {
1568
1592
  switch (focusId) {
1569
1593
  case Copy$2:
1570
- return Copy$1;
1594
+ return Copy;
1571
1595
  case Ok$2:
1572
- return Ok$1;
1596
+ return Ok;
1573
1597
  default:
1574
1598
  return '';
1575
1599
  }
@@ -1580,12 +1604,18 @@ const renderFocus = (oldState, newState) => {
1580
1604
  return ['Viewlet.focusElementByName', name];
1581
1605
  };
1582
1606
 
1607
+ const renderFocusContext = (oldState, newState) => {
1608
+ return ['Viewlet.setFocusContext', FocusAbout];
1609
+ };
1610
+
1583
1611
  const getRenderer = diffType => {
1584
1612
  switch (diffType) {
1585
1613
  case RenderAbout:
1586
1614
  return renderDialog;
1587
1615
  case RenderFocus:
1588
1616
  return renderFocus;
1617
+ case RenderFocusContext:
1618
+ return renderFocusContext;
1589
1619
  default:
1590
1620
  throw new Error('unknown renderer');
1591
1621
  }
@@ -1600,21 +1630,16 @@ const applyRender = (oldState, newState, diffResult) => {
1600
1630
  return commands;
1601
1631
  };
1602
1632
 
1603
- const doRender$1 = (uid, diffResult) => {
1633
+ const doRender = (uid, diffResult) => {
1604
1634
  const {
1605
1635
  oldState,
1606
1636
  newState
1607
1637
  } = get$1(uid);
1608
- const commands = applyRender(oldState, newState, diffResult);
1609
1638
  set$1(uid, newState, newState);
1639
+ const commands = applyRender(oldState, newState, diffResult);
1610
1640
  return commands;
1611
1641
  };
1612
1642
 
1613
- const doRender = (oldState, newState) => {
1614
- const diffResult = diff(oldState, newState);
1615
- return applyRender(oldState, newState, diffResult);
1616
- };
1617
-
1618
1643
  const renderEventListeners = () => {
1619
1644
  return [{
1620
1645
  name: HandleClickOk,
@@ -1665,6 +1690,14 @@ const showMessageBox = async options => {
1665
1690
 
1666
1691
  const Info = 'info';
1667
1692
 
1693
+ const getDetailString = async () => {
1694
+ const [electronVersion, nodeVersion, chromeVersion, version, commit, v8Version, date] = await Promise.all([getElectronVersion(), getNodeVersion(), getChromeVersion(), getVersion(), getCommit(), getV8Version(), getDate()]);
1695
+ const now = Date.now();
1696
+ const formattedDate = formatAboutDate(date, now);
1697
+ const lines = [`Version: ${version}`, `Commit: ${commit}`, `Date: ${formattedDate}`, `Electron: ${electronVersion}`, `Chromium: ${chromeVersion}`, `Node: ${nodeVersion}`, `V8: ${v8Version}`];
1698
+ return joinLines(lines);
1699
+ };
1700
+
1668
1701
  const showAboutElectron = async () => {
1669
1702
  const windowId = await getWindowId();
1670
1703
  const detail = await getDetailString();
@@ -1698,29 +1731,37 @@ const showAbout = async platform => {
1698
1731
  await fn();
1699
1732
  };
1700
1733
 
1734
+ const wrapCommand = fn => {
1735
+ const wrapped = async (uid, ...args) => {
1736
+ const {
1737
+ newState
1738
+ } = get$1(uid);
1739
+ const newerState = await fn(newState, ...args);
1740
+ if (newState === newerState) {
1741
+ return;
1742
+ }
1743
+ set$1(uid, newState, newerState);
1744
+ };
1745
+ return wrapped;
1746
+ };
1747
+
1701
1748
  const commandMap = {
1702
1749
  'About.create': create,
1703
1750
  'About.diff2': diff2,
1704
- 'About.focusNext': focusNext,
1705
- 'About.focusPrevious': focusPrevious,
1751
+ 'About.dispose': dispose,
1752
+ 'About.focusNext': wrapCommand(focusNext),
1753
+ 'About.focusPrevious': wrapCommand(focusPrevious),
1706
1754
  'About.getCommandIds': getCommandIds,
1707
1755
  'About.getKeyBindings': getKeyBindings,
1708
- 'About.handleClickClose': handleClickClose,
1709
- 'About.handleClickCopy': handleClickCopy,
1756
+ 'About.handleClickClose': wrapCommand(handleClickClose),
1757
+ 'About.handleClickCopy': wrapCommand(handleClickCopy),
1758
+ 'About.handleClickOk': wrapCommand(handleClickOk),
1759
+ 'About.handleFocusIn': wrapCommand(handleFocusIn),
1710
1760
  'About.loadContent2': loadContent2,
1711
- 'About.handleClickOk': handleClickOk,
1712
- 'About.handleFocusIn': handleFocusIn,
1713
- 'About.render2': doRender$1,
1761
+ 'About.render2': doRender,
1714
1762
  'About.renderEventListeners': renderEventListeners,
1715
1763
  'About.showAbout': showAbout,
1716
- 'About.showAboutElectron': showAboutElectron,
1717
- // deprecated
1718
- 'About.loadContent': loadContent,
1719
- 'About.diff': diff,
1720
- 'About.render': doRender,
1721
- 'About.getVirtualDom': getAboutVirtualDom,
1722
- 'About.getDetailString': getDetailString,
1723
- 'About.getDetailStringWeb': getDetailStringWeb
1764
+ 'About.showAboutElectron': showAboutElectron
1724
1765
  };
1725
1766
 
1726
1767
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/about-view",
3
- "version": "4.17.0",
3
+ "version": "5.1.0",
4
4
  "description": "About View Worker",
5
5
  "keywords": [
6
6
  "about-view"