@lvce-editor/about-view 7.6.0 → 7.8.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.
@@ -5,6 +5,18 @@ const toCommandId = key => {
5
5
  const create$a = () => {
6
6
  const states = Object.create(null);
7
7
  const commandMapRef = {};
8
+ const updateState = (uid, updater) => {
9
+ const current = states[uid];
10
+ const updatedState = updater(current.newState);
11
+ if (updatedState !== current.newState) {
12
+ states[uid] = {
13
+ newState: updatedState,
14
+ oldState: current.oldState,
15
+ scheduledState: updatedState
16
+ };
17
+ }
18
+ return Promise.resolve(updatedState);
19
+ };
8
20
  return {
9
21
  clear() {
10
22
  for (const key of Object.keys(states)) {
@@ -49,6 +61,16 @@ const create$a = () => {
49
61
  scheduledState: scheduledState ?? newState
50
62
  };
51
63
  },
64
+ wrapAsyncCommand(fn) {
65
+ const wrapped = async (uid, ...args) => {
66
+ const context = {
67
+ getState: () => states[uid].newState,
68
+ updateState: updater => updateState(uid, updater)
69
+ };
70
+ await fn(context, ...args);
71
+ };
72
+ return wrapped;
73
+ },
52
74
  wrapCommand(fn) {
53
75
  const wrapped = async (uid, ...args) => {
54
76
  const {
@@ -122,16 +144,16 @@ const {
122
144
  getCommandIds,
123
145
  registerCommands,
124
146
  set: set$3,
147
+ wrapAsyncCommand,
125
148
  wrapCommand
126
149
  } = create$a();
127
150
 
128
- const create$9 = (uid, useNewLoadConfig = false) => {
151
+ const create$9 = uid => {
129
152
  const state = {
130
153
  focusId: 0,
131
154
  lines: [],
132
155
  productName: '',
133
- uid,
134
- useNewLoadConfig
156
+ uid
135
157
  };
136
158
  set$3(uid, state, state);
137
159
  };
@@ -228,10 +250,174 @@ const focusPrevious = state => {
228
250
  };
229
251
  };
230
252
 
253
+ const Audio = 0;
231
254
  const Button$2 = 1;
255
+ const Col = 2;
256
+ const ColGroup = 3;
232
257
  const Div = 4;
258
+ const H1 = 5;
259
+ const Input = 6;
260
+ const Kbd = 7;
261
+ const Span = 8;
262
+ const Table = 9;
263
+ const TBody = 10;
264
+ const Td = 11;
233
265
  const Text = 12;
266
+ const Th = 13;
267
+ const THead = 14;
268
+ const Tr = 15;
269
+ const I = 16;
270
+ const Img = 17;
271
+ const Root = 0;
272
+ const Ins = 20;
273
+ const Del = 21;
274
+ const H2 = 22;
275
+ const H3 = 23;
276
+ const H4 = 24;
277
+ const H5 = 25;
278
+ const H6 = 26;
279
+ const Article = 27;
280
+ const Aside = 28;
281
+ const Footer = 29;
282
+ const Header = 30;
283
+ const Nav = 40;
284
+ const Section = 41;
285
+ const Search = 42;
286
+ const Dd = 43;
287
+ const Dl = 44;
288
+ const Figcaption = 45;
289
+ const Figure = 46;
290
+ const Hr = 47;
291
+ const Li = 48;
292
+ const Ol = 49;
293
+ const P = 50;
294
+ const Pre = 51;
295
+ const A = 53;
296
+ const Abbr = 54;
234
297
  const Br = 55;
298
+ const Cite = 56;
299
+ const Data = 57;
300
+ const Time = 58;
301
+ const Tfoot = 59;
302
+ const Ul = 60;
303
+ const Video = 61;
304
+ const TextArea = 62;
305
+ const Select = 63;
306
+ const Option = 64;
307
+ const Code = 65;
308
+ const Label = 66;
309
+ const Dt = 67;
310
+ const Iframe = 68;
311
+ const Main = 69;
312
+ const Strong = 70;
313
+ const Em = 71;
314
+ const Style = 72;
315
+ const Html = 73;
316
+ const Head = 74;
317
+ const Title = 75;
318
+ const Meta = 76;
319
+ const Canvas = 77;
320
+ const Form = 78;
321
+ const BlockQuote = 79;
322
+ const Quote = 80;
323
+ const Circle = 81;
324
+ const Defs = 82;
325
+ const Ellipse = 83;
326
+ const G = 84;
327
+ const Line = 85;
328
+ const Path = 86;
329
+ const Polygon = 87;
330
+ const Polyline = 88;
331
+ const Rect = 89;
332
+ const Svg = 90;
333
+ const Use = 91;
334
+ const Reference = 100;
335
+
336
+ const VirtualDomElements = {
337
+ __proto__: null,
338
+ A,
339
+ Abbr,
340
+ Article,
341
+ Aside,
342
+ Audio,
343
+ BlockQuote,
344
+ Br,
345
+ Button: Button$2,
346
+ Canvas,
347
+ Circle,
348
+ Cite,
349
+ Code,
350
+ Col,
351
+ ColGroup,
352
+ Data,
353
+ Dd,
354
+ Defs,
355
+ Del,
356
+ Div,
357
+ Dl,
358
+ Dt,
359
+ Ellipse,
360
+ Em,
361
+ Figcaption,
362
+ Figure,
363
+ Footer,
364
+ Form,
365
+ G,
366
+ H1,
367
+ H2,
368
+ H3,
369
+ H4,
370
+ H5,
371
+ H6,
372
+ Head,
373
+ Header,
374
+ Hr,
375
+ Html,
376
+ I,
377
+ Iframe,
378
+ Img,
379
+ Input,
380
+ Ins,
381
+ Kbd,
382
+ Label,
383
+ Li,
384
+ Line,
385
+ Main,
386
+ Meta,
387
+ Nav,
388
+ Ol,
389
+ Option,
390
+ P,
391
+ Path,
392
+ Polygon,
393
+ Polyline,
394
+ Pre,
395
+ Quote,
396
+ Rect,
397
+ Reference,
398
+ Root,
399
+ Search,
400
+ Section,
401
+ Select,
402
+ Span,
403
+ Strong,
404
+ Style,
405
+ Svg,
406
+ TBody,
407
+ THead,
408
+ Table,
409
+ Td,
410
+ Text,
411
+ TextArea,
412
+ Tfoot,
413
+ Th,
414
+ Time,
415
+ Title,
416
+ Tr,
417
+ Ul,
418
+ Use,
419
+ Video
420
+ };
235
421
 
236
422
  const TargetName = 'event.target.name';
237
423
 
@@ -255,6 +441,8 @@ const text = data => {
255
441
  };
256
442
  };
257
443
 
444
+ new Set(Object.values(VirtualDomElements));
445
+
258
446
  const FocusAbout = 4;
259
447
 
260
448
  const getKeyBindings = () => {
@@ -371,7 +559,6 @@ const walkValue = (value, transferrables, isTransferrable) => {
371
559
  for (const property of Object.values(value)) {
372
560
  walkValue(property, transferrables, isTransferrable);
373
561
  }
374
- return;
375
562
  }
376
563
  };
377
564
  const getTransferrables = value => {
@@ -525,7 +712,14 @@ class IpcError extends VError {
525
712
  const cause = new Error(message);
526
713
  // @ts-ignore
527
714
  cause.code = code;
528
- cause.stack = stack;
715
+ if (stack) {
716
+ Object.defineProperty(cause, 'stack', {
717
+ configurable: true,
718
+ enumerable: false,
719
+ value: stack,
720
+ writable: true
721
+ });
722
+ }
529
723
  super(cause, betterMessage);
530
724
  } else {
531
725
  super(betterMessage);
@@ -829,8 +1023,10 @@ const getCurrentStack = () => {
829
1023
  const currentStack = joinLines$1(splitLines(new Error().stack || '').slice(stackLinesToSkip));
830
1024
  return currentStack;
831
1025
  };
832
- const getNewLineIndex = (string, startIndex = undefined) => {
833
- return string.indexOf(NewLine$1, startIndex);
1026
+ const getNewLineIndex = (string, startIndex) => {
1027
+ {
1028
+ return string.indexOf(NewLine$1);
1029
+ }
834
1030
  };
835
1031
  const getParentStack = error => {
836
1032
  let parentStack = error.stack || error.data || error.message || '';
@@ -841,55 +1037,77 @@ const getParentStack = error => {
841
1037
  };
842
1038
  const MethodNotFound = -32601;
843
1039
  const Custom = -32001;
1040
+ const restoreExistingError = (error, currentStack) => {
1041
+ if (typeof error.stack === 'string') {
1042
+ error.stack = error.stack + NewLine$1 + currentStack;
1043
+ }
1044
+ return error;
1045
+ };
1046
+ const restoreMethodNotFoundError = (error, currentStack) => {
1047
+ const restoredError = new JsonRpcError(error.message);
1048
+ const parentStack = getParentStack(error);
1049
+ restoredError.stack = parentStack + NewLine$1 + currentStack;
1050
+ return restoredError;
1051
+ };
1052
+ const restoreStackFromData = (restoredError, error, currentStack) => {
1053
+ if (error.data.stack && error.data.type && error.message) {
1054
+ restoredError.stack = error.data.type + ': ' + error.message + NewLine$1 + error.data.stack + NewLine$1 + currentStack;
1055
+ return;
1056
+ }
1057
+ if (error.data.stack) {
1058
+ restoredError.stack = error.data.stack;
1059
+ }
1060
+ };
1061
+ const applyDataProperties = (restoredError, error) => {
1062
+ if (!error.data) {
1063
+ return;
1064
+ }
1065
+ restoreStackFromData(restoredError, error, getCurrentStack());
1066
+ if (error.data.codeFrame) {
1067
+ // @ts-ignore
1068
+ restoredError.codeFrame = error.data.codeFrame;
1069
+ }
1070
+ if (error.data.code) {
1071
+ // @ts-ignore
1072
+ restoredError.code = error.data.code;
1073
+ }
1074
+ if (error.data.type) {
1075
+ // @ts-ignore
1076
+ restoredError.name = error.data.type;
1077
+ }
1078
+ };
1079
+ const applyDirectProperties = (restoredError, error) => {
1080
+ if (error.stack) {
1081
+ const lowerStack = restoredError.stack || '';
1082
+ const indexNewLine = getNewLineIndex(lowerStack);
1083
+ const parentStack = getParentStack(error);
1084
+ // @ts-ignore
1085
+ restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
1086
+ }
1087
+ if (error.codeFrame) {
1088
+ // @ts-ignore
1089
+ restoredError.codeFrame = error.codeFrame;
1090
+ }
1091
+ };
1092
+ const restoreMessageError = (error, _currentStack) => {
1093
+ const restoredError = constructError(error.message, error.type, error.name);
1094
+ if (error.data) {
1095
+ applyDataProperties(restoredError, error);
1096
+ } else {
1097
+ applyDirectProperties(restoredError, error);
1098
+ }
1099
+ return restoredError;
1100
+ };
844
1101
  const restoreJsonRpcError = error => {
845
1102
  const currentStack = getCurrentStack();
846
1103
  if (error && error instanceof Error) {
847
- if (typeof error.stack === 'string') {
848
- error.stack = error.stack + NewLine$1 + currentStack;
849
- }
850
- return error;
1104
+ return restoreExistingError(error, currentStack);
851
1105
  }
852
1106
  if (error && error.code && error.code === MethodNotFound) {
853
- const restoredError = new JsonRpcError(error.message);
854
- const parentStack = getParentStack(error);
855
- restoredError.stack = parentStack + NewLine$1 + currentStack;
856
- return restoredError;
1107
+ return restoreMethodNotFoundError(error, currentStack);
857
1108
  }
858
1109
  if (error && error.message) {
859
- const restoredError = constructError(error.message, error.type, error.name);
860
- if (error.data) {
861
- if (error.data.stack && error.data.type && error.message) {
862
- restoredError.stack = error.data.type + ': ' + error.message + NewLine$1 + error.data.stack + NewLine$1 + currentStack;
863
- } else if (error.data.stack) {
864
- restoredError.stack = error.data.stack;
865
- }
866
- if (error.data.codeFrame) {
867
- // @ts-ignore
868
- restoredError.codeFrame = error.data.codeFrame;
869
- }
870
- if (error.data.code) {
871
- // @ts-ignore
872
- restoredError.code = error.data.code;
873
- }
874
- if (error.data.type) {
875
- // @ts-ignore
876
- restoredError.name = error.data.type;
877
- }
878
- } else {
879
- if (error.stack) {
880
- const lowerStack = restoredError.stack || '';
881
- // @ts-ignore
882
- const indexNewLine = getNewLineIndex(lowerStack);
883
- const parentStack = getParentStack(error);
884
- // @ts-ignore
885
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
886
- }
887
- if (error.codeFrame) {
888
- // @ts-ignore
889
- restoredError.codeFrame = error.codeFrame;
890
- }
891
- }
892
- return restoredError;
1110
+ return restoreMessageError(error);
893
1111
  }
894
1112
  if (typeof error === 'string') {
895
1113
  return new Error(`JsonRpc Error: ${error}`);
@@ -1456,22 +1674,20 @@ const handleClickButton = async (state, name) => {
1456
1674
  }
1457
1675
  };
1458
1676
 
1459
- const handleFocusIn = async state => {
1677
+ const handleFocusIn = async context => {
1460
1678
  // TODO remove side effect
1461
1679
  await setFocus(FocusAbout);
1462
- if (state.focusId) {
1463
- return state;
1464
- }
1465
- return {
1466
- ...state,
1467
- focusId: Ok$2
1468
- };
1680
+ await context.updateState(state => {
1681
+ if (state.focusId) {
1682
+ return state;
1683
+ }
1684
+ return {
1685
+ ...state,
1686
+ focusId: Ok$2
1687
+ };
1688
+ });
1469
1689
  };
1470
1690
 
1471
- const commit = 'unknown commit';
1472
-
1473
- const commitDate = '';
1474
-
1475
1691
  const OneSecondAgo = '1 second ago';
1476
1692
  const SomeSecondsAgo = '{PH1} seconds ago';
1477
1693
  const OneMinuteAgo = '1 minute ago';
@@ -1502,15 +1718,15 @@ const InOneYear = 'in 1 year';
1502
1718
  const InSomeYears = 'in {PH1} years';
1503
1719
 
1504
1720
  const emptyObject = {};
1505
- const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1506
1721
  const i18nString = (key, placeholders = emptyObject) => {
1507
1722
  if (placeholders === emptyObject) {
1508
1723
  return key;
1509
1724
  }
1510
- const replacer = (match, rest) => {
1511
- return placeholders[rest];
1512
- };
1513
- return key.replaceAll(RE_PLACEHOLDER, replacer);
1725
+ let result = key;
1726
+ for (const [placeholder, replacement] of Object.entries(placeholders)) {
1727
+ result = result.split(`{${placeholder}}`).join(String(replacement));
1728
+ }
1729
+ return result;
1514
1730
  };
1515
1731
 
1516
1732
  // based on https://github.com/microsoft/vscode/blob/bd782eb059e133d3a20fdb446b8feb0010a278ad/src/vs/base/common/date.ts (License MIT)
@@ -1759,13 +1975,11 @@ const getBrowser = () => {
1759
1975
  return navigator.userAgent;
1760
1976
  };
1761
1977
 
1762
- const version = '0.0.0-dev';
1763
-
1764
- const getDetailStringWeb = () => {
1978
+ const getDetailStringWeb = config => {
1765
1979
  const now = Date.now();
1766
- const formattedDate = formatAboutDate(commitDate, now);
1980
+ const formattedDate = formatAboutDate(config.date, now);
1767
1981
  const browser = getBrowser();
1768
- const lines = [`Version: ${version}`, `Commit: ${commit}`, `Date: ${formattedDate}`, `Browser: ${browser}`];
1982
+ const lines = [`Version: ${config.version}`, `Commit: ${config.commit}`, `Date: ${formattedDate}`, `Browser: ${browser}`];
1769
1983
  return lines;
1770
1984
  };
1771
1985
 
@@ -1780,7 +1994,7 @@ const getString = (config, key) => {
1780
1994
  }
1781
1995
  return value;
1782
1996
  };
1783
- const loadConfig = async _state => {
1997
+ const loadConfig = async () => {
1784
1998
  const configJsonPath = await getConfigJsonPath();
1785
1999
  // FileSystemWorker.readFile is a custom RPC that already returns a string.
1786
2000
  // eslint-disable-next-line unicorn/consistent-json-file-read
@@ -1794,37 +2008,14 @@ const loadConfig = async _state => {
1794
2008
  };
1795
2009
  };
1796
2010
 
1797
- const getContentFromConfig = async state => {
1798
- const now = Date.now();
1799
- try {
1800
- const config = await loadConfig(state);
1801
- const resolvedVersion = config.version || version;
1802
- const resolvedCommit = config.commit || commit;
1803
- const resolvedDate = config.date || commitDate;
1804
- const formattedDate = formatAboutDate(resolvedDate, now);
1805
- const browser = getBrowser();
1806
- return {
1807
- lines: [`Version: ${resolvedVersion}`, `Commit: ${resolvedCommit}`, `Date: ${formattedDate}`, `Browser: ${browser}`],
1808
- productName: config.productName || state.productName
1809
- };
1810
- } catch {
1811
- return {
1812
- lines: getDetailStringWeb(),
1813
- productName: state.productName
1814
- };
1815
- }
1816
- };
1817
- const loadContent2 = async state => {
1818
- const content = state.useNewLoadConfig ? await getContentFromConfig(state) : {
1819
- lines: getDetailStringWeb(),
1820
- productName: state.productName
1821
- };
1822
- return {
2011
+ const loadContent2 = async context => {
2012
+ const config = await loadConfig();
2013
+ await context.updateState(state => ({
1823
2014
  ...state,
1824
2015
  focusId: Ok$2,
1825
- lines: content.lines,
1826
- productName: content.productName
1827
- };
2016
+ lines: getDetailStringWeb(config),
2017
+ productName: config.productName
2018
+ }));
1828
2019
  };
1829
2020
 
1830
2021
  const Ok = 'Ok';
@@ -2005,8 +2196,15 @@ const getAboutVirtualDom = (productName, lines, closeMessage, okMessage, copyMes
2005
2196
  };
2006
2197
 
2007
2198
  const renderDialog = (oldState, newState) => {
2008
- const viewModel = createViewModel(newState);
2009
- const dom = getAboutVirtualDom(viewModel.productName, viewModel.lines, viewModel.closeMessage, viewModel.okMessage, viewModel.copyMessage, viewModel.infoMessage);
2199
+ const {
2200
+ closeMessage,
2201
+ copyMessage,
2202
+ infoMessage,
2203
+ lines,
2204
+ okMessage,
2205
+ productName
2206
+ } = createViewModel(newState);
2207
+ const dom = getAboutVirtualDom(productName, lines, closeMessage, okMessage, copyMessage, infoMessage);
2010
2208
  return ['Viewlet.setDom2', dom];
2011
2209
  };
2012
2210
 
@@ -2101,34 +2299,22 @@ const Info = 'info';
2101
2299
  const getElectronVersion = getElectronVersion$1;
2102
2300
  const getNodeVersion = getNodeVersion$1;
2103
2301
  const getChromeVersion = getChromeVersion$1;
2104
- const getVersion = async () => {
2105
- return version;
2106
- };
2107
- const getCommit = async () => {
2108
- return commit;
2109
- };
2110
2302
  const getV8Version = getV8Version$1;
2111
- const getDate = () => {
2112
- return commitDate;
2113
- };
2114
2303
 
2115
- /* eslint-disable @typescript-eslint/await-thenable */
2116
- const getDetailString = async () => {
2117
- const [electronVersion, nodeVersion, chromeVersion, version, commit, v8Version, date] = await Promise.all([getElectronVersion(), getNodeVersion(), getChromeVersion(), getVersion(), getCommit(), getV8Version(), getDate()]);
2304
+ const getDetailString = async config => {
2305
+ const [electronVersion, nodeVersion, chromeVersion, v8Version] = await Promise.all([getElectronVersion(), getNodeVersion(), getChromeVersion(), getV8Version()]);
2118
2306
  const now = Date.now();
2119
- const formattedDate = formatAboutDate(date, now);
2120
- const lines = [`Version: ${version}`, `Commit: ${commit}`, `Date: ${formattedDate}`, `Electron: ${electronVersion}`, `Chromium: ${chromeVersion}`, `Node: ${nodeVersion}`, `V8: ${v8Version}`];
2307
+ const formattedDate = formatAboutDate(config.date, now);
2308
+ const lines = [`Version: ${config.version}`, `Commit: ${config.commit}`, `Date: ${formattedDate}`, `Electron: ${electronVersion}`, `Chromium: ${chromeVersion}`, `Node: ${nodeVersion}`, `V8: ${v8Version}`];
2121
2309
  return joinLines(lines);
2122
2310
  };
2123
2311
 
2124
- const getProductName = async () => {
2125
- const config = await loadConfig();
2126
- return config.productName;
2127
- };
2128
2312
  const showAboutElectron = async () => {
2129
- const windowId = await getWindowId();
2130
- const detail = await getDetailString();
2131
- const productName = await getProductName();
2313
+ const [windowId, config] = await Promise.all([getWindowId(), loadConfig()]);
2314
+ const detail = await getDetailString(config);
2315
+ const {
2316
+ productName
2317
+ } = config;
2132
2318
  const options = {
2133
2319
  buttons: [copy(), ok()],
2134
2320
  detail,
@@ -2171,8 +2357,8 @@ const commandMap = {
2171
2357
  'About.handleClickClose': wrapCommand(handleClickClose),
2172
2358
  'About.handleClickCopy': wrapCommand(handleClickCopy),
2173
2359
  'About.handleClickOk': wrapCommand(handleClickOk),
2174
- 'About.handleFocusIn': wrapCommand(handleFocusIn),
2175
- 'About.loadContent2': wrapCommand(loadContent2),
2360
+ 'About.handleFocusIn': wrapAsyncCommand(handleFocusIn),
2361
+ 'About.loadContent2': wrapAsyncCommand(loadContent2),
2176
2362
  'About.render2': doRender,
2177
2363
  'About.renderEventListeners': renderEventListeners,
2178
2364
  'About.showAbout': showAbout,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/about-view",
3
- "version": "7.6.0",
3
+ "version": "7.8.0",
4
4
  "description": "About View Worker",
5
5
  "keywords": [
6
6
  "about-view"