@lvce-editor/about-view 2.0.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,11 @@
1
- const commands = Object.create(null);
2
- const register = commandMap => {
3
- Object.assign(commands, commandMap);
4
- };
5
- const getCommand = key => {
6
- return commands[key];
7
- };
8
- const execute = (command, ...args) => {
9
- const fn = getCommand(command);
10
- if (!fn) {
11
- throw new Error(`command not found ${command}`);
12
- }
13
- return fn(...args);
14
- };
15
-
16
1
  const Two = '2.0';
2
+ const create$4 = (method, params) => {
3
+ return {
4
+ jsonrpc: Two,
5
+ method,
6
+ params
7
+ };
8
+ };
17
9
  const state = {
18
10
  callbacks: Object.create(null)
19
11
  };
@@ -232,7 +224,7 @@ const getErrorProperty = (error, prettyError) => {
232
224
  }
233
225
  };
234
226
  };
235
- const create$1 = (message, error) => {
227
+ const create$1$1 = (message, error) => {
236
228
  return {
237
229
  jsonrpc: Two,
238
230
  id: message.id,
@@ -243,9 +235,9 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
243
235
  const prettyError = preparePrettyError(error);
244
236
  logError(error, prettyError);
245
237
  const errorProperty = getErrorProperty(error, prettyError);
246
- return create$1(message, errorProperty);
238
+ return create$1$1(message, errorProperty);
247
239
  };
248
- const create$4 = (message, result) => {
240
+ const create = (message, result) => {
249
241
  return {
250
242
  jsonrpc: Two,
251
243
  id: message.id,
@@ -254,7 +246,7 @@ const create$4 = (message, result) => {
254
246
  };
255
247
  const getSuccessResponse = (message, result) => {
256
248
  const resultProperty = result ?? null;
257
- return create$4(message, resultProperty);
249
+ return create(message, resultProperty);
258
250
  };
259
251
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
260
252
  try {
@@ -335,19 +327,64 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
335
327
  message,
336
328
  promise
337
329
  } = create$2(method, params);
338
- {
330
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
331
+ ipc.sendAndTransfer(message);
332
+ } else {
339
333
  ipc.send(message);
340
334
  }
341
335
  const responseMessage = await promise;
342
336
  return unwrapJsonRpcResult(responseMessage);
343
337
  };
338
+ const send = (transport, method, ...params) => {
339
+ const message = create$4(method, params);
340
+ transport.send(message);
341
+ };
344
342
  const invoke = (ipc, method, ...params) => {
345
- return invokeHelper(ipc, method, params);
343
+ return invokeHelper(ipc, method, params, false);
344
+ };
345
+ const invokeAndTransfer = (ipc, method, ...params) => {
346
+ return invokeHelper(ipc, method, params, true);
347
+ };
348
+
349
+ const commands = Object.create(null);
350
+ const register = commandMap => {
351
+ Object.assign(commands, commandMap);
352
+ };
353
+ const getCommand = key => {
354
+ return commands[key];
355
+ };
356
+ const execute = (command, ...args) => {
357
+ const fn = getCommand(command);
358
+ if (!fn) {
359
+ throw new Error(`command not found ${command}`);
360
+ }
361
+ return fn(...args);
346
362
  };
347
363
 
348
364
  const getData$1 = event => {
349
365
  return event.data;
350
366
  };
367
+ const attachEvents = that => {
368
+ const handleMessage = (...args) => {
369
+ const data = that.getData(...args);
370
+ that.dispatchEvent(new MessageEvent('message', {
371
+ data
372
+ }));
373
+ };
374
+ that.onMessage(handleMessage);
375
+ const handleClose = event => {
376
+ that.dispatchEvent(new Event('close'));
377
+ };
378
+ that.onClose(handleClose);
379
+ };
380
+ class Ipc extends EventTarget {
381
+ constructor(rawIpc) {
382
+ super();
383
+ this._rawIpc = rawIpc;
384
+ attachEvents(this);
385
+ }
386
+ }
387
+ const readyMessage = 'ready';
351
388
  const walkValue = (value, transferrables, isTransferrable) => {
352
389
  if (!value) {
353
390
  return;
@@ -398,35 +435,14 @@ const getTransferrables = value => {
398
435
  walkValue(value, transferrables, isTransferrable);
399
436
  return transferrables;
400
437
  };
401
- const attachEvents = that => {
402
- const handleMessage = (...args) => {
403
- const data = that.getData(...args);
404
- that.dispatchEvent(new MessageEvent('message', {
405
- data
406
- }));
407
- };
408
- that.onMessage(handleMessage);
409
- const handleClose = event => {
410
- that.dispatchEvent(new Event('close'));
411
- };
412
- that.onClose(handleClose);
413
- };
414
- class Ipc extends EventTarget {
415
- constructor(rawIpc) {
416
- super();
417
- this._rawIpc = rawIpc;
418
- attachEvents(this);
419
- }
420
- }
421
- const readyMessage = 'ready';
422
- const listen$4 = () => {
438
+ const listen$2 = () => {
423
439
  // @ts-ignore
424
440
  if (typeof WorkerGlobalScope === 'undefined') {
425
441
  throw new TypeError('module is not in web worker scope');
426
442
  }
427
443
  return globalThis;
428
444
  };
429
- const signal$3 = global => {
445
+ const signal$2 = global => {
430
446
  global.postMessage(readyMessage);
431
447
  };
432
448
  class IpcChildWithModuleWorker extends Ipc {
@@ -452,7 +468,7 @@ class IpcChildWithModuleWorker extends Ipc {
452
468
  this._rawIpc.addEventListener('message', callback);
453
469
  }
454
470
  }
455
- const wrap$6 = global => {
471
+ const wrap$5 = global => {
456
472
  return new IpcChildWithModuleWorker(global);
457
473
  };
458
474
  const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
@@ -570,10 +586,10 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
570
586
  };
571
587
  const normalizeLine = line => {
572
588
  if (line.startsWith('Error: ')) {
573
- return line.slice(`Error: `.length);
589
+ return line.slice('Error: '.length);
574
590
  }
575
591
  if (line.startsWith('VError: ')) {
576
- return line.slice(`VError: `.length);
592
+ return line.slice('VError: '.length);
577
593
  }
578
594
  return line;
579
595
  };
@@ -671,10 +687,10 @@ const waitForFirstMessage = async port => {
671
687
  // @ts-ignore
672
688
  return event.data;
673
689
  };
674
- const listen$3 = async () => {
675
- const parentIpcRaw = listen$4();
676
- signal$3(parentIpcRaw);
677
- const parentIpc = wrap$6(parentIpcRaw);
690
+ const listen$1$1 = async () => {
691
+ const parentIpcRaw = listen$2();
692
+ signal$2(parentIpcRaw);
693
+ const parentIpc = wrap$5(parentIpcRaw);
678
694
  const firstMessage = await waitForFirstMessage(parentIpc);
679
695
  if (firstMessage.method !== 'initialize') {
680
696
  throw new IpcError('unexpected first message');
@@ -719,19 +735,28 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
719
735
  this._rawIpc.start();
720
736
  }
721
737
  }
722
- const wrap$5 = port => {
738
+ const wrap$4 = port => {
723
739
  return new IpcChildWithModuleWorkerAndMessagePort(port);
724
740
  };
725
741
  const IpcChildWithModuleWorkerAndMessagePort$1 = {
726
742
  __proto__: null,
727
- listen: listen$3,
728
- wrap: wrap$5
743
+ listen: listen$1$1,
744
+ wrap: wrap$4
729
745
  };
730
746
 
731
747
  const createRpc = ipc => {
732
748
  const rpc = {
749
+ /**
750
+ * @deprecated
751
+ */
752
+ send(method, ...params) {
753
+ send(ipc, method, ...params);
754
+ },
733
755
  invoke(method, ...params) {
734
756
  return invoke(ipc, method, ...params);
757
+ },
758
+ invokeAndTransfer(method, ...params) {
759
+ return invokeAndTransfer(ipc, method, ...params);
735
760
  }
736
761
  };
737
762
  return rpc;
@@ -759,7 +784,7 @@ const listen$1 = async () => {
759
784
  const ipc = module.wrap(rawIpc);
760
785
  return ipc;
761
786
  };
762
- const create = async ({
787
+ const create$1 = async ({
763
788
  commandMap
764
789
  }) => {
765
790
  // TODO create a commandMap per rpc instance
@@ -771,7 +796,7 @@ const create = async ({
771
796
  };
772
797
  const WebWorkerRpcClient = {
773
798
  __proto__: null,
774
- create
799
+ create: create$1
775
800
  };
776
801
 
777
802
  const None = 0;
@@ -1356,6 +1381,17 @@ const closeDialog = () => {
1356
1381
  return i18nString(UiStrings.CloseDialog);
1357
1382
  };
1358
1383
 
1384
+ const getFocusSelector = focusId => {
1385
+ switch (focusId) {
1386
+ case Copy:
1387
+ return '.ButtonPrimary';
1388
+ case Ok:
1389
+ return '.ButtonSecondary';
1390
+ default:
1391
+ return '';
1392
+ }
1393
+ };
1394
+
1359
1395
  const renderDialog = {
1360
1396
  isEqual(oldState, newState) {
1361
1397
  return oldState.productName === newState.productName && oldState.lines === newState.lines;
@@ -1369,16 +1405,6 @@ const renderDialog = {
1369
1405
  return ['Viewlet.setDom2', dom];
1370
1406
  }
1371
1407
  };
1372
- const getFocusSelector = focusId => {
1373
- switch (focusId) {
1374
- case Copy:
1375
- return '.ButtonPrimary';
1376
- case Ok:
1377
- return '.ButtonSecondary';
1378
- default:
1379
- return '';
1380
- }
1381
- };
1382
1408
  const renderFocus = {
1383
1409
  isEqual(oldState, newState) {
1384
1410
  return oldState.focusId === newState.focusId;
@@ -1399,6 +1425,26 @@ const doRender = (oldState, newState) => {
1399
1425
  return commands;
1400
1426
  };
1401
1427
 
1428
+ const renderEventListers = () => {
1429
+ return [{
1430
+ name: HandleClickOk,
1431
+ params: ['handleClickOk']
1432
+ }, {
1433
+ name: HandleClickClose,
1434
+ params: ['handleClickClose']
1435
+ }, {
1436
+ name: HandleClickCopy,
1437
+ params: ['handleClickCopy']
1438
+ }, {
1439
+ name: HandleFocusIn,
1440
+ params: ['handleFocusIn']
1441
+ }, {
1442
+ name: HandleContextMenu,
1443
+ params: [],
1444
+ preventDefault: true
1445
+ }];
1446
+ };
1447
+
1402
1448
  const commandMap = {
1403
1449
  'About.focusNext': focusNext,
1404
1450
  'About.focusPrevious': focusPrevious,
@@ -1406,7 +1452,8 @@ const commandMap = {
1406
1452
  'About.getDetailStringWeb': getDetailStringWeb,
1407
1453
  'About.getVirtualDom': getAboutVirtualDom,
1408
1454
  'About.loadContent': loadContent,
1409
- 'About.render': doRender
1455
+ 'About.render': doRender,
1456
+ 'About.renderEventListeners': renderEventListers
1410
1457
  };
1411
1458
 
1412
1459
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/about-view",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "",
5
5
  "main": "dist/aboutWorkerMain.js",
6
6
  "type": "module",