@lvce-editor/renderer-process 21.6.0 → 21.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.
@@ -289,8 +289,10 @@ const Option$1 = 64;
289
289
  const Code$1 = 65;
290
290
  const Label$1 = 66;
291
291
  const Dt$1 = 67;
292
+ const Reference$1 = 100;
292
293
  const VirtualDomElements$1 = {
293
294
  __proto__: null,
295
+ Reference: Reference$1,
294
296
  Text: Text$1};
295
297
  const getElementTag$1 = type => {
296
298
  switch (type) {
@@ -413,6 +415,13 @@ const ElementTagMap = {
413
415
  const {
414
416
  getElementTag
415
417
  } = ElementTagMap;
418
+ const instances = Object.create(null);
419
+ const get$1$1 = viewletId => {
420
+ return instances[viewletId];
421
+ };
422
+ const set$1$1 = (viewletId, instance) => {
423
+ instances[viewletId] = instance;
424
+ };
416
425
  const getEventListenerOptions$1 = (eventName, value) => {
417
426
  if (value.passive) {
418
427
  return {
@@ -634,7 +643,8 @@ const setProps = ($Element, props, eventMap, newEventMap) => {
634
643
  }
635
644
  };
636
645
  const {
637
- Text: Text$2} = VirtualDomElements$1;
646
+ Text: Text$2,
647
+ Reference} = VirtualDomElements$1;
638
648
  const renderDomTextNode = element => {
639
649
  return document.createTextNode(element.text);
640
650
  };
@@ -644,8 +654,15 @@ const renderDomElement = (element, eventMap, newEventMap) => {
644
654
  setProps($Element, element, eventMap, newEventMap);
645
655
  return $Element;
646
656
  };
657
+ const renderReferenceNode = element => {
658
+ const instance = get$1$1(element.uid);
659
+ const $Node = instance.state.$Viewlet;
660
+ return $Node;
661
+ };
647
662
  const render$1 = (element, eventMap, newEventMap) => {
648
663
  switch (element.type) {
664
+ case Reference:
665
+ return renderReferenceNode(element);
649
666
  case Text$2:
650
667
  return renderDomTextNode(element);
651
668
  default:
@@ -1927,7 +1944,7 @@ const getFirstEvent = (eventEmitter, eventMap) => {
1927
1944
  return promise;
1928
1945
  };
1929
1946
  const Message$1 = 3;
1930
- const create$5$1 = async ({
1947
+ const create$5$2 = async ({
1931
1948
  isMessagePortOpen,
1932
1949
  messagePort
1933
1950
  }) => {
@@ -1978,7 +1995,7 @@ const wrap$5 = messagePort => {
1978
1995
  };
1979
1996
  const IpcParentWithMessagePort$1 = {
1980
1997
  __proto__: null,
1981
- create: create$5$1,
1998
+ create: create$5$2,
1982
1999
  signal: signal$1,
1983
2000
  wrap: wrap$5
1984
2001
  };
@@ -2423,14 +2440,14 @@ const execute = (command, ...args) => {
2423
2440
  };
2424
2441
 
2425
2442
  const Two = '2.0';
2426
- const create$s$1 = (method, params) => {
2443
+ const create$t$1 = (method, params) => {
2427
2444
  return {
2428
2445
  jsonrpc: Two,
2429
2446
  method,
2430
2447
  params
2431
2448
  };
2432
2449
  };
2433
- const create$r$1 = (id, method, params) => {
2450
+ const create$s$1 = (id, method, params) => {
2434
2451
  const message = {
2435
2452
  id,
2436
2453
  jsonrpc: Two,
@@ -2440,14 +2457,14 @@ const create$r$1 = (id, method, params) => {
2440
2457
  return message;
2441
2458
  };
2442
2459
  let id = 0;
2443
- const create$q$1 = () => {
2460
+ const create$r$1 = () => {
2444
2461
  return ++id;
2445
2462
  };
2446
2463
 
2447
2464
  /* eslint-disable n/no-unsupported-features/es-syntax */
2448
2465
 
2449
2466
  const registerPromise = map => {
2450
- const id = create$q$1();
2467
+ const id = create$r$1();
2451
2468
  const {
2452
2469
  promise,
2453
2470
  resolve
@@ -2465,7 +2482,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
2465
2482
  id,
2466
2483
  promise
2467
2484
  } = registerPromise(callbacks);
2468
- const message = create$r$1(id, method, params);
2485
+ const message = create$s$1(id, method, params);
2469
2486
  if (useSendAndTransfer && ipc.sendAndTransfer) {
2470
2487
  ipc.sendAndTransfer(message);
2471
2488
  } else {
@@ -2501,7 +2518,7 @@ const createRpc = ipc => {
2501
2518
  * @deprecated
2502
2519
  */
2503
2520
  send(method, ...params) {
2504
- const message = create$s$1(method, params);
2521
+ const message = create$t$1(method, params);
2505
2522
  ipc.send(message);
2506
2523
  }
2507
2524
  };
@@ -2537,7 +2554,7 @@ const unhandleIpc = ipc => {
2537
2554
  ipc.onmessage = null;
2538
2555
  }
2539
2556
  };
2540
- const create$l$1 = async ({
2557
+ const create$m$1 = async ({
2541
2558
  commandMap,
2542
2559
  window
2543
2560
  }) => {
@@ -2550,12 +2567,12 @@ const create$l$1 = async ({
2550
2567
  };
2551
2568
  const ElectronWindowRpcClient = {
2552
2569
  __proto__: null,
2553
- create: create$l$1
2570
+ create: create$m$1
2554
2571
  };
2555
2572
  const isWorker = value => {
2556
2573
  return value instanceof Worker;
2557
2574
  };
2558
- const create$b$1 = async ({
2575
+ const create$c$1 = async ({
2559
2576
  commandMap,
2560
2577
  name,
2561
2578
  url
@@ -2576,9 +2593,9 @@ const create$b$1 = async ({
2576
2593
  };
2577
2594
  const ModuleWorkerRpcParent = {
2578
2595
  __proto__: null,
2579
- create: create$b$1
2596
+ create: create$c$1
2580
2597
  };
2581
- const create$a$1 = async ({
2598
+ const create$b$1 = async ({
2582
2599
  commandMap,
2583
2600
  name,
2584
2601
  port,
@@ -2602,9 +2619,9 @@ const create$a$1 = async ({
2602
2619
  };
2603
2620
  const ModuleWorkerWithMessagePortRpcParent = {
2604
2621
  __proto__: null,
2605
- create: create$a$1
2622
+ create: create$b$1
2606
2623
  };
2607
- const create$4$1 = async ({
2624
+ const create$5$1 = async ({
2608
2625
  commandMap,
2609
2626
  isMessagePortOpen = true,
2610
2627
  messagePort
@@ -2621,18 +2638,18 @@ const create$4$1 = async ({
2621
2638
  messagePort.start();
2622
2639
  return rpc;
2623
2640
  };
2624
- const create$3$1 = async ({
2641
+ const create$4$1 = async ({
2625
2642
  commandMap,
2626
2643
  messagePort
2627
2644
  }) => {
2628
- return create$4$1({
2645
+ return create$5$1({
2629
2646
  commandMap,
2630
2647
  messagePort
2631
2648
  });
2632
2649
  };
2633
2650
  const PlainMessagePortRpcParent = {
2634
2651
  __proto__: null,
2635
- create: create$3$1
2652
+ create: create$4$1
2636
2653
  };
2637
2654
 
2638
2655
  // TODO add test
@@ -7651,13 +7668,6 @@ const ViewletOutput = {
7651
7668
  setText
7652
7669
  };
7653
7670
 
7654
- const state$1 = {
7655
- currentPanelView: undefined,
7656
- currentSideBarView: undefined,
7657
- instances: Object.create(null),
7658
- modules: Object.create(null)
7659
- };
7660
-
7661
7671
  const handleClickClose = event => {
7662
7672
  const uid = fromEvent(event);
7663
7673
  hidePanel(uid);
@@ -7804,8 +7814,7 @@ const setActionsDom$1 = (state, actions, childUid) => {
7804
7814
  const {
7805
7815
  $PanelActions
7806
7816
  } = state;
7807
- const instances = state$1.instances;
7808
- const instance = instances[childUid];
7817
+ const instance = get$1$1(childUid);
7809
7818
  if (!instance) {
7810
7819
  throw new Error(`child instance not found`);
7811
7820
  }
@@ -8919,23 +8928,30 @@ const load$1 = moduleId => {
8919
8928
  }
8920
8929
  };
8921
8930
 
8931
+ const state$1 = {
8932
+ currentPanelView: undefined,
8933
+ currentSideBarView: undefined,
8934
+ modules: Object.create(null)
8935
+ };
8936
+
8922
8937
  const create$3 = (id, uid = id) => {
8923
8938
  const module = state$1.modules[id];
8924
8939
  if (!module) {
8925
8940
  throw new Error(`module not found: ${id}`);
8926
8941
  }
8927
- if (state$1.instances[id]?.state.$Viewlet.isConnected) {
8928
- state$1.instances[id].state.$Viewlet.remove();
8942
+ const existing = get$1$1(id);
8943
+ if (existing?.state.$Viewlet.isConnected) {
8944
+ existing.state.$Viewlet.remove();
8929
8945
  }
8930
8946
  const instanceState = module.create();
8931
8947
  set$3(instanceState.$Viewlet, uid);
8932
8948
  if (module.attachEvents) {
8933
8949
  module.attachEvents(instanceState);
8934
8950
  }
8935
- state$1.instances[uid] = {
8951
+ set$1$1(uid, {
8936
8952
  factory: module,
8937
8953
  state: instanceState
8938
- };
8954
+ });
8939
8955
  };
8940
8956
  const createFunctionalRoot = (id, uid = id, hasFunctionalEvents) => {
8941
8957
  let module = state$1.modules[id];
@@ -8945,16 +8961,17 @@ const createFunctionalRoot = (id, uid = id, hasFunctionalEvents) => {
8945
8961
  if (!module) {
8946
8962
  throw new Error(`module not found: ${id}`);
8947
8963
  }
8948
- if (state$1.instances[id]?.state.$Viewlet.isConnected) {
8949
- state$1.instances[id].state.$Viewlet.remove();
8964
+ const existing = get$1$1(id);
8965
+ if (existing?.state.$Viewlet.isConnected) {
8966
+ existing.state.$Viewlet.remove();
8950
8967
  }
8951
8968
  const instanceState = {
8952
8969
  $Viewlet: document.createElement('div')
8953
8970
  };
8954
- state$1.instances[uid] = {
8971
+ set$1$1(uid, {
8955
8972
  factory: module,
8956
8973
  state: instanceState
8957
- };
8974
+ });
8958
8975
  };
8959
8976
  const addKeyBindings = (id, keyBindings) => {
8960
8977
  // @ts-expect-error
@@ -8974,7 +8991,7 @@ const loadModule = async id => {
8974
8991
  };
8975
8992
  const invoke = (viewletId, method, ...args) => {
8976
8993
  string(method);
8977
- const instance = state$1.instances[viewletId];
8994
+ const instance = get$1$1(viewletId);
8978
8995
  if (!instance?.factory) {
8979
8996
  if (viewletId && method !== 'setActionsDom') {
8980
8997
  warn$1(`cannot execute ${method} viewlet instance ${viewletId} not found`);
@@ -8992,7 +9009,7 @@ const focus$1 = viewletId => {
8992
9009
  // eslint-disable-next-line no-console
8993
9010
  console.trace(`focus ${viewletId}`);
8994
9011
  }
8995
- const instance = state$1.instances[viewletId];
9012
+ const instance = get$1$1(viewletId);
8996
9013
  if (instance.factory?.setFocused) {
8997
9014
  instance.factory.setFocused(instance.state, true);
8998
9015
  } else if (instance?.factory?.focus) {
@@ -9008,7 +9025,7 @@ const focusElementByName = (viewletId, name) => {
9008
9025
  // eslint-disable-next-line no-console
9009
9026
  console.trace(`focusByName ${viewletId} ${name}`);
9010
9027
  }
9011
- const instance = state$1.instances[viewletId];
9028
+ const instance = get$1$1(viewletId);
9012
9029
  if (!instance) {
9013
9030
  return;
9014
9031
  }
@@ -9023,7 +9040,7 @@ const focusElementByName = (viewletId, name) => {
9023
9040
  };
9024
9041
  const setElementProperty = (viewletId, name, key, value) => {
9025
9042
  const selector = `[name="${name}"]`;
9026
- const instance = state$1.instances[viewletId];
9043
+ const instance = get$1$1(viewletId);
9027
9044
  if (!instance) {
9028
9045
  return;
9029
9046
  }
@@ -9052,7 +9069,7 @@ const setCheckBoxValue = (viewletId, name, value) => {
9052
9069
  };
9053
9070
  const setSelectionByName = (viewletId, name, start, end) => {
9054
9071
  const selector = `[name="${name}"]`;
9055
- const instance = state$1.instances[viewletId];
9072
+ const instance = get$1$1(viewletId);
9056
9073
  if (!instance) {
9057
9074
  return;
9058
9075
  }
@@ -9067,7 +9084,7 @@ const setSelectionByName = (viewletId, name, start, end) => {
9067
9084
  $Element.selectionEnd = end;
9068
9085
  };
9069
9086
  const setUid = (viewletId, uid) => {
9070
- const instance = state$1.instances[viewletId];
9087
+ const instance = get$1$1(viewletId);
9071
9088
  if (!instance) {
9072
9089
  return;
9073
9090
  }
@@ -9077,7 +9094,7 @@ const setUid = (viewletId, uid) => {
9077
9094
  set$3($Viewlet, uid);
9078
9095
  };
9079
9096
  const focusSelector = (viewletId, selector) => {
9080
- const instance = state$1.instances[viewletId];
9097
+ const instance = get$1$1(viewletId);
9081
9098
  if (!instance) {
9082
9099
  return;
9083
9100
  }
@@ -9095,7 +9112,7 @@ const focusSelector = (viewletId, selector) => {
9095
9112
  * @deprecated
9096
9113
  */
9097
9114
  const refresh$1 = (viewletId, viewletContext) => {
9098
- const instance = state$1.instances[viewletId];
9115
+ const instance = get$1$1(viewletId);
9099
9116
  if (instance) {
9100
9117
  instance.factory.refresh(instance.state, viewletContext);
9101
9118
  } else {
@@ -9114,20 +9131,20 @@ const createPlaceholder = (viewletId, parentId, top, left, width, height) => {
9114
9131
  if (isSpecial(viewletId)) {
9115
9132
  $PlaceHolder.id = viewletId;
9116
9133
  }
9117
- const parentInstance = state$1.instances[parentId];
9134
+ const parentInstance = get$1$1(parentId);
9118
9135
  const $Parent = parentInstance.state.$Viewlet;
9119
9136
  $Parent.append($PlaceHolder);
9120
- state$1.instances[viewletId] = {
9137
+ set$1$1(viewletId, {
9121
9138
  state: {
9122
9139
  $Viewlet: $PlaceHolder
9123
9140
  }
9124
- };
9141
+ });
9125
9142
  };
9126
9143
  const setDragData = (viewletId, dragData) => {
9127
9144
  set$2(viewletId, dragData);
9128
9145
  };
9129
9146
  const setDom = (viewletId, dom) => {
9130
- const instance = state$1.instances[viewletId];
9147
+ const instance = get$1$1(viewletId);
9131
9148
  if (!instance) {
9132
9149
  return;
9133
9150
  }
@@ -9140,7 +9157,7 @@ const setDom = (viewletId, dom) => {
9140
9157
  renderInto($Viewlet, dom, Events);
9141
9158
  };
9142
9159
  const setDom2 = (viewletId, dom) => {
9143
- const instance = state$1.instances[viewletId];
9160
+ const instance = get$1$1(viewletId);
9144
9161
  if (!instance) {
9145
9162
  return;
9146
9163
  }
@@ -9162,10 +9179,16 @@ const setDom2 = (viewletId, dom) => {
9162
9179
  // @ts-ignore
9163
9180
  set$3($NewViewlet, uid);
9164
9181
  }
9165
- instance.state.$Viewlet = $NewViewlet;
9182
+ set$1$1(viewletId, {
9183
+ ...instance,
9184
+ state: {
9185
+ ...instance.state,
9186
+ $Viewlet: $NewViewlet
9187
+ }
9188
+ });
9166
9189
  };
9167
9190
  const setPatches = (uid, patches) => {
9168
- const instance = state$1.instances[uid];
9191
+ const instance = get$1$1(uid);
9169
9192
  if (!instance) {
9170
9193
  return;
9171
9194
  }
@@ -9336,10 +9359,7 @@ const sendMultiple = commands => {
9336
9359
  const dispose$3 = id => {
9337
9360
  try {
9338
9361
  number(id);
9339
- const {
9340
- instances
9341
- } = state$1;
9342
- const instance = instances[id];
9362
+ const instance = get$1$1(id);
9343
9363
  if (!instance) {
9344
9364
  warn$1(`viewlet instance ${id} not found and cannot be disposed`);
9345
9365
  return;
@@ -9350,14 +9370,14 @@ const dispose$3 = id => {
9350
9370
  if (instance.state.$Viewlet?.isConnected) {
9351
9371
  instance.state.$Viewlet.remove();
9352
9372
  }
9353
- delete instances[id];
9373
+ set$1$1(id, undefined);
9354
9374
  } catch {
9355
9375
  throw new Error(`Failed to dispose ${id}`);
9356
9376
  }
9357
9377
  };
9358
9378
  const handleError$1 = (id, parentId, message) => {
9359
9379
  info(`[viewlet-error] ${id}: ${message}`);
9360
- const instance = state$1.instances[id];
9380
+ const instance = get$1$1(id);
9361
9381
  if (instance?.state.$Viewlet.isConnected) {
9362
9382
  instance.state.$Viewlet.remove();
9363
9383
  }
@@ -9369,7 +9389,7 @@ const handleError$1 = (id, parentId, message) => {
9369
9389
  instance.state.$Viewlet.textContent = `${message}`;
9370
9390
  }
9371
9391
  // TODO error should bubble up to until highest possible component
9372
- const parentInstance = state$1.instances[parentId];
9392
+ const parentInstance = get$1$1(parentId);
9373
9393
  if (parentInstance?.factory?.handleError) {
9374
9394
  parentInstance.factory.handleError(instance.state, message);
9375
9395
  }
@@ -9383,9 +9403,9 @@ const appendViewlet = (parentId, childId, focus) => {
9383
9403
  // TODO
9384
9404
  return;
9385
9405
  }
9386
- const parentInstanceState = state$1.instances[parentId]; // TODO must ensure that parent is already created
9406
+ const parentInstanceState = get$1$1(parentId); // TODO must ensure that parent is already created
9387
9407
  const parentModule = parentInstanceState.factory;
9388
- const childInstance = state$1.instances[childId];
9408
+ const childInstance = get$1$1(childId);
9389
9409
  if (!childInstance) {
9390
9410
  throw new Error(`child instance ${childId} must be defined to be appended to parent ${parentId}`);
9391
9411
  }
@@ -9404,12 +9424,12 @@ const ariaAnnounce = async message => {
9404
9424
  const append = (parentId, childId, referenceNodes) => {
9405
9425
  number(parentId);
9406
9426
  number(childId);
9407
- const parentInstance = state$1.instances[parentId];
9427
+ const parentInstance = get$1$1(parentId);
9408
9428
  if (!parentInstance) {
9409
9429
  throw new Error(`cannot append child: instance ${parentId} not found`);
9410
9430
  }
9411
9431
  const $Parent = parentInstance.state.$Viewlet;
9412
- const childInstance = state$1.instances[childId];
9432
+ const childInstance = get$1$1(childId);
9413
9433
  if (!childInstance) {
9414
9434
  throw new Error(`cannot append child: child instance not found ${childId}`);
9415
9435
  }
@@ -9425,16 +9445,18 @@ const append = (parentId, childId, referenceNodes) => {
9425
9445
  if (id === childId) {
9426
9446
  for (let j = i - 1; j >= 0; j--) {
9427
9447
  const beforeId = referenceNodes[j];
9428
- if (state$1.instances[beforeId]) {
9429
- const $ReferenceNode = state$1.instances[beforeId].state.$Viewlet;
9448
+ const beforeInstance = get$1$1(beforeId);
9449
+ if (beforeInstance) {
9450
+ const $ReferenceNode = beforeInstance.state.$Viewlet;
9430
9451
  $ReferenceNode.after($Child);
9431
9452
  return;
9432
9453
  }
9433
9454
  }
9434
9455
  for (let j = i + 1; j < referenceNodes.length; j++) {
9435
9456
  const afterId = referenceNodes[j];
9436
- if (state$1.instances[afterId]) {
9437
- const $ReferenceNode = state$1.instances[afterId].state.$Viewlet;
9457
+ const afterInstance = get$1$1(afterId);
9458
+ if (afterInstance) {
9459
+ const $ReferenceNode = afterInstance.state.$Viewlet;
9438
9460
  $ReferenceNode.before($Child);
9439
9461
  return;
9440
9462
  }
@@ -9450,11 +9472,11 @@ const append = (parentId, childId, referenceNodes) => {
9450
9472
  }
9451
9473
  };
9452
9474
  const replaceChildren = (parentId, childIds) => {
9453
- const parentInstance = state$1.instances[parentId];
9475
+ const parentInstance = get$1$1(parentId);
9454
9476
  const $Parent = parentInstance.state.$Viewlet;
9455
9477
  const $Fragment = document.createDocumentFragment();
9456
9478
  for (const childId of childIds) {
9457
- const childInstance = state$1.instances[childId];
9479
+ const childInstance = get$1$1(childId);
9458
9480
  const $Child = childInstance.state.$Viewlet;
9459
9481
  $Fragment.append($Child);
9460
9482
  }
@@ -9462,7 +9484,7 @@ const replaceChildren = (parentId, childIds) => {
9462
9484
  };
9463
9485
  const appendToBody = childId => {
9464
9486
  const $Parent = document.body;
9465
- const childInstance = state$1.instances[childId];
9487
+ const childInstance = get$1$1(childId);
9466
9488
  const $Child = childInstance.state.$Viewlet;
9467
9489
  $Parent.append($Child);
9468
9490
  };
@@ -9534,7 +9556,7 @@ const executeCommands = commands => {
9534
9556
  }
9535
9557
  };
9536
9558
  const show = id => {
9537
- const instance = state$1.instances[id];
9559
+ const instance = get$1$1(id);
9538
9560
  const $Viewlet = instance.state.$Viewlet;
9539
9561
  const $Workbench = document.getElementById('Workbench');
9540
9562
  // @ts-expect-error
@@ -9544,7 +9566,7 @@ const show = id => {
9544
9566
  }
9545
9567
  };
9546
9568
  const setBounds$1 = (id, left, top, width, height) => {
9547
- const instance = state$1.instances[id];
9569
+ const instance = get$1$1(id);
9548
9570
  if (!instance) {
9549
9571
  return;
9550
9572
  }
@@ -9552,7 +9574,7 @@ const setBounds$1 = (id, left, top, width, height) => {
9552
9574
  setBounds$a($Viewlet, left, top, width, height);
9553
9575
  };
9554
9576
  const setProperty = (id, selector, property, value) => {
9555
- const instance = state$1.instances[id];
9577
+ const instance = get$1$1(id);
9556
9578
  if (!instance) {
9557
9579
  return;
9558
9580
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "21.6.0",
3
+ "version": "21.8.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "renderer-process"