@lvce-editor/about-view 7.8.0 → 7.10.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.
@@ -3,9 +3,18 @@ const toCommandId = key => {
3
3
  return key.slice(dotIndex + 1);
4
4
  };
5
5
  const create$a = () => {
6
+ const commandQueues = new Map();
7
+ const generations = Object.create(null);
6
8
  const states = Object.create(null);
7
9
  const commandMapRef = {};
8
- const updateState = (uid, updater) => {
10
+ const getGeneration = uid => generations[uid] || 0;
11
+ const isCurrentGeneration = (uid, generation) => {
12
+ return states[uid] !== undefined && getGeneration(uid) === generation;
13
+ };
14
+ const updateState = (uid, generation, fallbackState, updater) => {
15
+ if (!isCurrentGeneration(uid, generation)) {
16
+ return Promise.resolve(fallbackState);
17
+ }
9
18
  const current = states[uid];
10
19
  const updatedState = updater(current.newState);
11
20
  if (updatedState !== current.newState) {
@@ -17,8 +26,44 @@ const create$a = () => {
17
26
  }
18
27
  return Promise.resolve(updatedState);
19
28
  };
29
+ const createAsyncCommandContext = (uid, generation) => {
30
+ let latestState = states[uid].newState;
31
+ return {
32
+ getState: () => {
33
+ if (isCurrentGeneration(uid, generation)) {
34
+ latestState = states[uid].newState;
35
+ }
36
+ return latestState;
37
+ },
38
+ updateState: async updater => {
39
+ latestState = await updateState(uid, generation, latestState, updater);
40
+ return latestState;
41
+ }
42
+ };
43
+ };
44
+ const enqueueCommand = async (uid, command) => {
45
+ const previous = commandQueues.get(uid) || Promise.resolve();
46
+ const run = async () => {
47
+ try {
48
+ await previous;
49
+ } catch {
50
+ // The previous caller receives its error; later commands must still run.
51
+ }
52
+ await command();
53
+ };
54
+ const current = run();
55
+ commandQueues.set(uid, current);
56
+ try {
57
+ await current;
58
+ } finally {
59
+ if (commandQueues.get(uid) === current) {
60
+ commandQueues.delete(uid);
61
+ }
62
+ }
63
+ };
20
64
  return {
21
65
  clear() {
66
+ commandQueues.clear();
22
67
  for (const key of Object.keys(states)) {
23
68
  delete states[key];
24
69
  }
@@ -38,6 +83,7 @@ const create$a = () => {
38
83
  return diffResult;
39
84
  },
40
85
  dispose(uid) {
86
+ commandQueues.delete(uid);
41
87
  delete states[uid];
42
88
  },
43
89
  get(uid) {
@@ -55,6 +101,10 @@ const create$a = () => {
55
101
  Object.assign(commandMapRef, commandMap);
56
102
  },
57
103
  set(uid, oldState, newState, scheduledState) {
104
+ const current = states[uid];
105
+ if (!current || oldState === newState && newState !== current.newState) {
106
+ generations[uid] = getGeneration(uid) + 1;
107
+ }
58
108
  states[uid] = {
59
109
  newState,
60
110
  oldState,
@@ -63,16 +113,15 @@ const create$a = () => {
63
113
  },
64
114
  wrapAsyncCommand(fn) {
65
115
  const wrapped = async (uid, ...args) => {
66
- const context = {
67
- getState: () => states[uid].newState,
68
- updateState: updater => updateState(uid, updater)
69
- };
116
+ const generation = getGeneration(uid);
117
+ const context = createAsyncCommandContext(uid, generation);
70
118
  await fn(context, ...args);
71
119
  };
72
120
  return wrapped;
73
121
  },
74
122
  wrapCommand(fn) {
75
123
  const wrapped = async (uid, ...args) => {
124
+ const generation = getGeneration(uid);
76
125
  const {
77
126
  newState,
78
127
  oldState
@@ -81,6 +130,9 @@ const create$a = () => {
81
130
  if (oldState === newerState || newState === newerState) {
82
131
  return;
83
132
  }
133
+ if (!isCurrentGeneration(uid, generation)) {
134
+ return;
135
+ }
84
136
  const latestOld = states[uid];
85
137
  const latestNew = {
86
138
  ...latestOld.newState,
@@ -105,6 +157,7 @@ const create$a = () => {
105
157
  },
106
158
  wrapLoadContent(fn) {
107
159
  const wrapped = async (uid, ...args) => {
160
+ const generation = getGeneration(uid);
108
161
  const {
109
162
  newState,
110
163
  oldState
@@ -119,6 +172,11 @@ const create$a = () => {
119
172
  error
120
173
  };
121
174
  }
175
+ if (!isCurrentGeneration(uid, generation)) {
176
+ return {
177
+ error
178
+ };
179
+ }
122
180
  const latestOld = states[uid];
123
181
  const latestNew = {
124
182
  ...latestOld.newState,
@@ -134,6 +192,51 @@ const create$a = () => {
134
192
  };
135
193
  };
136
194
  return wrapped;
195
+ },
196
+ wrapSerialAsyncCommand(fn) {
197
+ const wrapped = async (uid, ...args) => {
198
+ await enqueueCommand(uid, async () => {
199
+ if (!states[uid]) {
200
+ return;
201
+ }
202
+ const generation = getGeneration(uid);
203
+ const context = createAsyncCommandContext(uid, generation);
204
+ await fn(context, ...args);
205
+ });
206
+ };
207
+ return wrapped;
208
+ },
209
+ wrapSerialCommand(fn) {
210
+ const wrapped = async (uid, ...args) => {
211
+ await enqueueCommand(uid, async () => {
212
+ if (!states[uid]) {
213
+ return;
214
+ }
215
+ const generation = getGeneration(uid);
216
+ const {
217
+ newState,
218
+ oldState
219
+ } = states[uid];
220
+ const newerState = await fn(newState, ...args);
221
+ if (oldState === newerState || newState === newerState) {
222
+ return;
223
+ }
224
+ if (!isCurrentGeneration(uid, generation)) {
225
+ return;
226
+ }
227
+ const latestOld = states[uid];
228
+ const latestNew = {
229
+ ...latestOld.newState,
230
+ ...newerState
231
+ };
232
+ states[uid] = {
233
+ newState: latestNew,
234
+ oldState: latestOld.oldState,
235
+ scheduledState: latestNew
236
+ };
237
+ });
238
+ };
239
+ return wrapped;
137
240
  }
138
241
  };
139
242
  };
@@ -251,7 +354,7 @@ const focusPrevious = state => {
251
354
  };
252
355
 
253
356
  const Audio = 0;
254
- const Button$2 = 1;
357
+ const Button$1 = 1;
255
358
  const Col = 2;
256
359
  const ColGroup = 3;
257
360
  const Div = 4;
@@ -342,7 +445,7 @@ const VirtualDomElements = {
342
445
  Audio,
343
446
  BlockQuote,
344
447
  Br,
345
- Button: Button$2,
448
+ Button: Button$1,
346
449
  Canvas,
347
450
  Circle,
348
451
  Cite,
@@ -427,7 +530,7 @@ const Escape = 8;
427
530
  const Shift = 1 << 10 >>> 0;
428
531
 
429
532
  const FileSystemWorker = 209;
430
- const RendererWorker = 1;
533
+ const RendererWorker$1 = 1;
431
534
 
432
535
  const mergeClassNames = (...classNames) => {
433
536
  return classNames.filter(Boolean).join(' ');
@@ -1006,7 +1109,10 @@ const constructError = (message, type, name) => {
1006
1109
  if (ErrorConstructor === Error) {
1007
1110
  const error = new Error(message);
1008
1111
  if (name && name !== 'VError') {
1009
- error.name = name;
1112
+ Object.defineProperty(error, 'name', {
1113
+ configurable: true,
1114
+ value: name
1115
+ });
1010
1116
  }
1011
1117
  return error;
1012
1118
  }
@@ -1037,31 +1143,45 @@ const getParentStack = error => {
1037
1143
  };
1038
1144
  const MethodNotFound = -32601;
1039
1145
  const Custom = -32001;
1146
+ const setStack = (error, stack) => {
1147
+ const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
1148
+ if (descriptor) {
1149
+ if (!descriptor.configurable && !descriptor.writable) {
1150
+ return;
1151
+ }
1152
+ if (!descriptor.configurable && descriptor.writable) {
1153
+ error.stack = stack;
1154
+ return;
1155
+ }
1156
+ }
1157
+ Object.defineProperty(error, 'stack', {
1158
+ configurable: true,
1159
+ value: stack,
1160
+ writable: true
1161
+ });
1162
+ };
1040
1163
  const restoreExistingError = (error, currentStack) => {
1041
1164
  if (typeof error.stack === 'string') {
1042
- error.stack = error.stack + NewLine$1 + currentStack;
1165
+ setStack(error, `${error.stack}${NewLine$1}${currentStack}`);
1043
1166
  }
1044
1167
  return error;
1045
1168
  };
1046
1169
  const restoreMethodNotFoundError = (error, currentStack) => {
1047
1170
  const restoredError = new JsonRpcError(error.message);
1048
1171
  const parentStack = getParentStack(error);
1049
- restoredError.stack = parentStack + NewLine$1 + currentStack;
1172
+ setStack(restoredError, `${parentStack}${NewLine$1}${currentStack}`);
1050
1173
  return restoredError;
1051
1174
  };
1052
1175
  const restoreStackFromData = (restoredError, error, currentStack) => {
1053
1176
  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;
1177
+ setStack(restoredError, `${error.data.type}: ${error.message}${NewLine$1}${error.data.stack}${NewLine$1}${currentStack}`);
1055
1178
  return;
1056
1179
  }
1057
1180
  if (error.data.stack) {
1058
- restoredError.stack = error.data.stack;
1181
+ setStack(restoredError, error.data.stack);
1059
1182
  }
1060
1183
  };
1061
1184
  const applyDataProperties = (restoredError, error) => {
1062
- if (!error.data) {
1063
- return;
1064
- }
1065
1185
  restoreStackFromData(restoredError, error, getCurrentStack());
1066
1186
  if (error.data.codeFrame) {
1067
1187
  // @ts-ignore
@@ -1082,7 +1202,7 @@ const applyDirectProperties = (restoredError, error) => {
1082
1202
  const indexNewLine = getNewLineIndex(lowerStack);
1083
1203
  const parentStack = getParentStack(error);
1084
1204
  // @ts-ignore
1085
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
1205
+ setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
1086
1206
  }
1087
1207
  if (error.codeFrame) {
1088
1208
  // @ts-ignore
@@ -1579,7 +1699,7 @@ const {
1579
1699
  invoke,
1580
1700
  invokeAndTransfer,
1581
1701
  set
1582
- } = create(RendererWorker);
1702
+ } = create(RendererWorker$1);
1583
1703
  const getElectronVersion$1 = async () => {
1584
1704
  return invoke('Process.getElectronVersion');
1585
1705
  };
@@ -1615,7 +1735,27 @@ const getWindowId$1 = async () => {
1615
1735
  return invoke('GetWindowId.getWindowId');
1616
1736
  };
1617
1737
 
1618
- const closeWidget = closeWidget$1;
1738
+ const RendererWorker = {
1739
+ __proto__: null,
1740
+ closeWidget: closeWidget$1,
1741
+ getChromeVersion: getChromeVersion$1,
1742
+ getElectronVersion: getElectronVersion$1,
1743
+ getNodeVersion: getNodeVersion$1,
1744
+ getV8Version: getV8Version$1,
1745
+ getWindowId: getWindowId$1,
1746
+ invoke,
1747
+ invokeAndTransfer,
1748
+ openWidget,
1749
+ sendMessagePortToFileSystemWorker,
1750
+ set,
1751
+ setFocus,
1752
+ showMessageBox: showMessageBox$1,
1753
+ writeClipBoardText
1754
+ };
1755
+
1756
+ const {
1757
+ closeWidget
1758
+ } = RendererWorker;
1619
1759
 
1620
1760
  const About$1 = 'About';
1621
1761
 
@@ -1678,7 +1818,10 @@ const handleFocusIn = async context => {
1678
1818
  // TODO remove side effect
1679
1819
  await setFocus(FocusAbout);
1680
1820
  await context.updateState(state => {
1681
- if (state.focusId) {
1821
+ const {
1822
+ focusId
1823
+ } = state;
1824
+ if (focusId) {
1682
1825
  return state;
1683
1826
  }
1684
1827
  return {
@@ -1997,7 +2140,6 @@ const getString = (config, key) => {
1997
2140
  const loadConfig = async () => {
1998
2141
  const configJsonPath = await getConfigJsonPath();
1999
2142
  // FileSystemWorker.readFile is a custom RPC that already returns a string.
2000
- // eslint-disable-next-line unicorn/consistent-json-file-read
2001
2143
  const content = await readFile(configJsonPath);
2002
2144
  const config = JSON.parse(content);
2003
2145
  return {
@@ -2055,7 +2197,7 @@ const createViewModel = state => {
2055
2197
  };
2056
2198
  };
2057
2199
 
2058
- const Button$1 = 'Button';
2200
+ const Button = 'Button';
2059
2201
  const ButtonPrimary = 'ButtonPrimary';
2060
2202
  const ButtonSecondary = 'ButtonSecondary';
2061
2203
  const DialogButtonsRow = 'DialogButtonsRow';
@@ -2101,26 +2243,25 @@ const getAboutContentVirtualDom = lines => {
2101
2243
 
2102
2244
  const True = 'true';
2103
2245
 
2104
- const Button = 'button';
2105
2246
  const Dialog = 'dialog';
2106
2247
 
2107
2248
  const getPrimaryButtonVirtualDom = (message, name) => {
2108
2249
  return [{
2109
2250
  childCount: 1,
2110
- className: mergeClassNames(Button$1, ButtonPrimary),
2251
+ className: mergeClassNames(Button, ButtonPrimary),
2111
2252
  name,
2112
2253
  onClick: HandleClickButton,
2113
- type: Button$2
2254
+ type: Button$1
2114
2255
  }, text(message)];
2115
2256
  };
2116
2257
 
2117
2258
  const getSecondaryButtonVirtualDom = (message, name) => {
2118
2259
  return [{
2119
2260
  childCount: 1,
2120
- className: mergeClassNames(Button$1, ButtonSecondary),
2261
+ className: mergeClassNames(Button, ButtonSecondary),
2121
2262
  name,
2122
2263
  onClick: HandleClickButton,
2123
- type: Button$2
2264
+ type: Button$1
2124
2265
  }, text(message)];
2125
2266
  };
2126
2267
 
@@ -2152,8 +2293,7 @@ const getDialogVirtualDom = (content, closeMessage, infoMessage, okMessage, copy
2152
2293
  childCount: 1,
2153
2294
  className: DialogClose,
2154
2295
  onClick: HandleClickClose,
2155
- role: Button,
2156
- type: Div
2296
+ type: Button$1
2157
2297
  }, {
2158
2298
  childCount: 0,
2159
2299
  className: mergeClassNames(MaskIcon, MaskIconClose),
@@ -2225,7 +2365,7 @@ const renderFocus = (oldState, newState) => {
2225
2365
  };
2226
2366
 
2227
2367
  const renderFocusContext = (oldState, newState) => {
2228
- return ['Viewlet.setFocusContext', FocusAbout];
2368
+ return ['Viewlet.setFocusContext', newState.uid, FocusAbout];
2229
2369
  };
2230
2370
 
2231
2371
  const getRenderer = diffType => {
@@ -2283,7 +2423,9 @@ const showAboutDefault = async () => {
2283
2423
  await openWidget(About$1);
2284
2424
  };
2285
2425
 
2286
- const getWindowId = getWindowId$1;
2426
+ const {
2427
+ getWindowId
2428
+ } = RendererWorker;
2287
2429
 
2288
2430
  const showMessageBox = async options => {
2289
2431
  const windowId = await getWindowId();
@@ -2296,10 +2438,18 @@ const showMessageBox = async options => {
2296
2438
 
2297
2439
  const Info = 'info';
2298
2440
 
2299
- const getElectronVersion = getElectronVersion$1;
2300
- const getNodeVersion = getNodeVersion$1;
2301
- const getChromeVersion = getChromeVersion$1;
2302
- const getV8Version = getV8Version$1;
2441
+ const {
2442
+ getElectronVersion
2443
+ } = RendererWorker;
2444
+ const {
2445
+ getNodeVersion
2446
+ } = RendererWorker;
2447
+ const {
2448
+ getChromeVersion
2449
+ } = RendererWorker;
2450
+ const {
2451
+ getV8Version
2452
+ } = RendererWorker;
2303
2453
 
2304
2454
  const getDetailString = async config => {
2305
2455
  const [electronVersion, nodeVersion, chromeVersion, v8Version] = await Promise.all([getElectronVersion(), getNodeVersion(), getChromeVersion(), getV8Version()]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/about-view",
3
- "version": "7.8.0",
3
+ "version": "7.10.0",
4
4
  "description": "About View Worker",
5
5
  "keywords": [
6
6
  "about-view"