@lvce-editor/renderer-process 21.5.0 → 21.7.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.
@@ -468,10 +468,10 @@ const cache$1 = new Map();
468
468
  const has$1 = listener => {
469
469
  return cache$1.has(listener);
470
470
  };
471
- const set$8 = (listener, value) => {
471
+ const set$1$1 = (listener, value) => {
472
472
  cache$1.set(listener, value);
473
473
  };
474
- const get$9 = listener => {
474
+ const get$1$1 = listener => {
475
475
  return cache$1.get(listener);
476
476
  };
477
477
  const nameAnonymousFunction$1 = (fn, name) => {
@@ -495,9 +495,9 @@ const getWrappedListener$1 = (listener, returnValue) => {
495
495
  ipc.send('Viewlet.executeViewletCommand', uid, ...result);
496
496
  };
497
497
  nameAnonymousFunction$1(wrapped, listener.name);
498
- set$8(listener, wrapped);
498
+ set$1$1(listener, wrapped);
499
499
  }
500
- return get$9(listener);
500
+ return get$1$1(listener);
501
501
  };
502
502
  const getOptions = fn => {
503
503
  if (fn.passive) {
@@ -707,18 +707,15 @@ const replace = ($Element, nodes, eventMap = {}) => {
707
707
  // Create a temporary container to render the new nodes
708
708
  const $Temp = document.createElement('div');
709
709
  renderInternal($Temp, nodes, eventMap, eventMap);
710
- // Replace the current element with the new ones
711
- let $NewElement = $Temp.firstElementChild;
712
- if (!$NewElement) {
713
- // If no element was created (e.g., only text nodes), we need to create a wrapper
714
- // In this case, we create a div and move all children to it
715
- $NewElement = document.createElement('div');
716
- while ($Temp.firstChild) {
717
- $NewElement.append($Temp.firstChild);
718
- }
710
+ // Replace the current element with the new node(s)
711
+ const $NewNode = $Temp.firstChild;
712
+ if (!$NewNode) {
713
+ // No node was created, just remove the old element
714
+ $Element.remove();
715
+ return $Element;
719
716
  }
720
- $Element.replaceWith($NewElement);
721
- return $NewElement;
717
+ $Element.replaceWith($NewNode);
718
+ return $NewNode;
722
719
  };
723
720
  const SetText = 1;
724
721
  const Replace = 2;
@@ -1190,6 +1187,13 @@ const rememberFocus$1 = ($Viewlet, dom, eventMap, uid = 0) => {
1190
1187
  stopIgnore();
1191
1188
  return $Viewlet;
1192
1189
  };
1190
+ const instances = Object.create(null);
1191
+ const get$9 = viewletId => {
1192
+ return instances[viewletId];
1193
+ };
1194
+ const set$8 = (viewletId, instance) => {
1195
+ instances[viewletId] = instance;
1196
+ };
1193
1197
 
1194
1198
  const get$8 = ids => {
1195
1199
  return getFileHandles$1(ids);
@@ -8927,18 +8931,19 @@ const create$3 = (id, uid = id) => {
8927
8931
  if (!module) {
8928
8932
  throw new Error(`module not found: ${id}`);
8929
8933
  }
8930
- if (state$1.instances[id]?.state.$Viewlet.isConnected) {
8931
- state$1.instances[id].state.$Viewlet.remove();
8934
+ const existing = get$9(id);
8935
+ if (existing?.state.$Viewlet.isConnected) {
8936
+ existing.state.$Viewlet.remove();
8932
8937
  }
8933
8938
  const instanceState = module.create();
8934
8939
  set$3(instanceState.$Viewlet, uid);
8935
8940
  if (module.attachEvents) {
8936
8941
  module.attachEvents(instanceState);
8937
8942
  }
8938
- state$1.instances[uid] = {
8943
+ set$8(uid, {
8939
8944
  factory: module,
8940
8945
  state: instanceState
8941
- };
8946
+ });
8942
8947
  };
8943
8948
  const createFunctionalRoot = (id, uid = id, hasFunctionalEvents) => {
8944
8949
  let module = state$1.modules[id];
@@ -8948,16 +8953,17 @@ const createFunctionalRoot = (id, uid = id, hasFunctionalEvents) => {
8948
8953
  if (!module) {
8949
8954
  throw new Error(`module not found: ${id}`);
8950
8955
  }
8951
- if (state$1.instances[id]?.state.$Viewlet.isConnected) {
8952
- state$1.instances[id].state.$Viewlet.remove();
8956
+ const existing = get$9(id);
8957
+ if (existing?.state.$Viewlet.isConnected) {
8958
+ existing.state.$Viewlet.remove();
8953
8959
  }
8954
8960
  const instanceState = {
8955
8961
  $Viewlet: document.createElement('div')
8956
8962
  };
8957
- state$1.instances[uid] = {
8963
+ set$8(uid, {
8958
8964
  factory: module,
8959
8965
  state: instanceState
8960
- };
8966
+ });
8961
8967
  };
8962
8968
  const addKeyBindings = (id, keyBindings) => {
8963
8969
  // @ts-expect-error
@@ -8977,7 +8983,7 @@ const loadModule = async id => {
8977
8983
  };
8978
8984
  const invoke = (viewletId, method, ...args) => {
8979
8985
  string(method);
8980
- const instance = state$1.instances[viewletId];
8986
+ const instance = get$9(viewletId);
8981
8987
  if (!instance?.factory) {
8982
8988
  if (viewletId && method !== 'setActionsDom') {
8983
8989
  warn$1(`cannot execute ${method} viewlet instance ${viewletId} not found`);
@@ -8995,7 +9001,7 @@ const focus$1 = viewletId => {
8995
9001
  // eslint-disable-next-line no-console
8996
9002
  console.trace(`focus ${viewletId}`);
8997
9003
  }
8998
- const instance = state$1.instances[viewletId];
9004
+ const instance = get$9(viewletId);
8999
9005
  if (instance.factory?.setFocused) {
9000
9006
  instance.factory.setFocused(instance.state, true);
9001
9007
  } else if (instance?.factory?.focus) {
@@ -9011,7 +9017,7 @@ const focusElementByName = (viewletId, name) => {
9011
9017
  // eslint-disable-next-line no-console
9012
9018
  console.trace(`focusByName ${viewletId} ${name}`);
9013
9019
  }
9014
- const instance = state$1.instances[viewletId];
9020
+ const instance = get$9(viewletId);
9015
9021
  if (!instance) {
9016
9022
  return;
9017
9023
  }
@@ -9026,7 +9032,7 @@ const focusElementByName = (viewletId, name) => {
9026
9032
  };
9027
9033
  const setElementProperty = (viewletId, name, key, value) => {
9028
9034
  const selector = `[name="${name}"]`;
9029
- const instance = state$1.instances[viewletId];
9035
+ const instance = get$9(viewletId);
9030
9036
  if (!instance) {
9031
9037
  return;
9032
9038
  }
@@ -9055,7 +9061,7 @@ const setCheckBoxValue = (viewletId, name, value) => {
9055
9061
  };
9056
9062
  const setSelectionByName = (viewletId, name, start, end) => {
9057
9063
  const selector = `[name="${name}"]`;
9058
- const instance = state$1.instances[viewletId];
9064
+ const instance = get$9(viewletId);
9059
9065
  if (!instance) {
9060
9066
  return;
9061
9067
  }
@@ -9070,7 +9076,7 @@ const setSelectionByName = (viewletId, name, start, end) => {
9070
9076
  $Element.selectionEnd = end;
9071
9077
  };
9072
9078
  const setUid = (viewletId, uid) => {
9073
- const instance = state$1.instances[viewletId];
9079
+ const instance = get$9(viewletId);
9074
9080
  if (!instance) {
9075
9081
  return;
9076
9082
  }
@@ -9080,7 +9086,7 @@ const setUid = (viewletId, uid) => {
9080
9086
  set$3($Viewlet, uid);
9081
9087
  };
9082
9088
  const focusSelector = (viewletId, selector) => {
9083
- const instance = state$1.instances[viewletId];
9089
+ const instance = get$9(viewletId);
9084
9090
  if (!instance) {
9085
9091
  return;
9086
9092
  }
@@ -9098,7 +9104,7 @@ const focusSelector = (viewletId, selector) => {
9098
9104
  * @deprecated
9099
9105
  */
9100
9106
  const refresh$1 = (viewletId, viewletContext) => {
9101
- const instance = state$1.instances[viewletId];
9107
+ const instance = get$9(viewletId);
9102
9108
  if (instance) {
9103
9109
  instance.factory.refresh(instance.state, viewletContext);
9104
9110
  } else {
@@ -9117,20 +9123,20 @@ const createPlaceholder = (viewletId, parentId, top, left, width, height) => {
9117
9123
  if (isSpecial(viewletId)) {
9118
9124
  $PlaceHolder.id = viewletId;
9119
9125
  }
9120
- const parentInstance = state$1.instances[parentId];
9126
+ const parentInstance = get$9(parentId);
9121
9127
  const $Parent = parentInstance.state.$Viewlet;
9122
9128
  $Parent.append($PlaceHolder);
9123
- state$1.instances[viewletId] = {
9129
+ set$8(viewletId, {
9124
9130
  state: {
9125
9131
  $Viewlet: $PlaceHolder
9126
9132
  }
9127
- };
9133
+ });
9128
9134
  };
9129
9135
  const setDragData = (viewletId, dragData) => {
9130
9136
  set$2(viewletId, dragData);
9131
9137
  };
9132
9138
  const setDom = (viewletId, dom) => {
9133
- const instance = state$1.instances[viewletId];
9139
+ const instance = get$9(viewletId);
9134
9140
  if (!instance) {
9135
9141
  return;
9136
9142
  }
@@ -9143,7 +9149,7 @@ const setDom = (viewletId, dom) => {
9143
9149
  renderInto($Viewlet, dom, Events);
9144
9150
  };
9145
9151
  const setDom2 = (viewletId, dom) => {
9146
- const instance = state$1.instances[viewletId];
9152
+ const instance = get$9(viewletId);
9147
9153
  if (!instance) {
9148
9154
  return;
9149
9155
  }
@@ -9165,10 +9171,16 @@ const setDom2 = (viewletId, dom) => {
9165
9171
  // @ts-ignore
9166
9172
  set$3($NewViewlet, uid);
9167
9173
  }
9168
- instance.state.$Viewlet = $NewViewlet;
9174
+ set$8(viewletId, {
9175
+ ...instance,
9176
+ state: {
9177
+ ...instance.state,
9178
+ $Viewlet: $NewViewlet
9179
+ }
9180
+ });
9169
9181
  };
9170
9182
  const setPatches = (uid, patches) => {
9171
- const instance = state$1.instances[uid];
9183
+ const instance = get$9(uid);
9172
9184
  if (!instance) {
9173
9185
  return;
9174
9186
  }
@@ -9339,10 +9351,7 @@ const sendMultiple = commands => {
9339
9351
  const dispose$3 = id => {
9340
9352
  try {
9341
9353
  number(id);
9342
- const {
9343
- instances
9344
- } = state$1;
9345
- const instance = instances[id];
9354
+ const instance = get$9(id);
9346
9355
  if (!instance) {
9347
9356
  warn$1(`viewlet instance ${id} not found and cannot be disposed`);
9348
9357
  return;
@@ -9353,14 +9362,14 @@ const dispose$3 = id => {
9353
9362
  if (instance.state.$Viewlet?.isConnected) {
9354
9363
  instance.state.$Viewlet.remove();
9355
9364
  }
9356
- delete instances[id];
9365
+ set$8(id, undefined);
9357
9366
  } catch {
9358
9367
  throw new Error(`Failed to dispose ${id}`);
9359
9368
  }
9360
9369
  };
9361
9370
  const handleError$1 = (id, parentId, message) => {
9362
9371
  info(`[viewlet-error] ${id}: ${message}`);
9363
- const instance = state$1.instances[id];
9372
+ const instance = get$9(id);
9364
9373
  if (instance?.state.$Viewlet.isConnected) {
9365
9374
  instance.state.$Viewlet.remove();
9366
9375
  }
@@ -9372,7 +9381,7 @@ const handleError$1 = (id, parentId, message) => {
9372
9381
  instance.state.$Viewlet.textContent = `${message}`;
9373
9382
  }
9374
9383
  // TODO error should bubble up to until highest possible component
9375
- const parentInstance = state$1.instances[parentId];
9384
+ const parentInstance = get$9(parentId);
9376
9385
  if (parentInstance?.factory?.handleError) {
9377
9386
  parentInstance.factory.handleError(instance.state, message);
9378
9387
  }
@@ -9386,9 +9395,9 @@ const appendViewlet = (parentId, childId, focus) => {
9386
9395
  // TODO
9387
9396
  return;
9388
9397
  }
9389
- const parentInstanceState = state$1.instances[parentId]; // TODO must ensure that parent is already created
9398
+ const parentInstanceState = get$9(parentId); // TODO must ensure that parent is already created
9390
9399
  const parentModule = parentInstanceState.factory;
9391
- const childInstance = state$1.instances[childId];
9400
+ const childInstance = get$9(childId);
9392
9401
  if (!childInstance) {
9393
9402
  throw new Error(`child instance ${childId} must be defined to be appended to parent ${parentId}`);
9394
9403
  }
@@ -9407,12 +9416,12 @@ const ariaAnnounce = async message => {
9407
9416
  const append = (parentId, childId, referenceNodes) => {
9408
9417
  number(parentId);
9409
9418
  number(childId);
9410
- const parentInstance = state$1.instances[parentId];
9419
+ const parentInstance = get$9(parentId);
9411
9420
  if (!parentInstance) {
9412
9421
  throw new Error(`cannot append child: instance ${parentId} not found`);
9413
9422
  }
9414
9423
  const $Parent = parentInstance.state.$Viewlet;
9415
- const childInstance = state$1.instances[childId];
9424
+ const childInstance = get$9(childId);
9416
9425
  if (!childInstance) {
9417
9426
  throw new Error(`cannot append child: child instance not found ${childId}`);
9418
9427
  }
@@ -9428,16 +9437,18 @@ const append = (parentId, childId, referenceNodes) => {
9428
9437
  if (id === childId) {
9429
9438
  for (let j = i - 1; j >= 0; j--) {
9430
9439
  const beforeId = referenceNodes[j];
9431
- if (state$1.instances[beforeId]) {
9432
- const $ReferenceNode = state$1.instances[beforeId].state.$Viewlet;
9440
+ const beforeInstance = get$9(beforeId);
9441
+ if (beforeInstance) {
9442
+ const $ReferenceNode = beforeInstance.state.$Viewlet;
9433
9443
  $ReferenceNode.after($Child);
9434
9444
  return;
9435
9445
  }
9436
9446
  }
9437
9447
  for (let j = i + 1; j < referenceNodes.length; j++) {
9438
9448
  const afterId = referenceNodes[j];
9439
- if (state$1.instances[afterId]) {
9440
- const $ReferenceNode = state$1.instances[afterId].state.$Viewlet;
9449
+ const afterInstance = get$9(afterId);
9450
+ if (afterInstance) {
9451
+ const $ReferenceNode = afterInstance.state.$Viewlet;
9441
9452
  $ReferenceNode.before($Child);
9442
9453
  return;
9443
9454
  }
@@ -9453,11 +9464,11 @@ const append = (parentId, childId, referenceNodes) => {
9453
9464
  }
9454
9465
  };
9455
9466
  const replaceChildren = (parentId, childIds) => {
9456
- const parentInstance = state$1.instances[parentId];
9467
+ const parentInstance = get$9(parentId);
9457
9468
  const $Parent = parentInstance.state.$Viewlet;
9458
9469
  const $Fragment = document.createDocumentFragment();
9459
9470
  for (const childId of childIds) {
9460
- const childInstance = state$1.instances[childId];
9471
+ const childInstance = get$9(childId);
9461
9472
  const $Child = childInstance.state.$Viewlet;
9462
9473
  $Fragment.append($Child);
9463
9474
  }
@@ -9465,7 +9476,7 @@ const replaceChildren = (parentId, childIds) => {
9465
9476
  };
9466
9477
  const appendToBody = childId => {
9467
9478
  const $Parent = document.body;
9468
- const childInstance = state$1.instances[childId];
9479
+ const childInstance = get$9(childId);
9469
9480
  const $Child = childInstance.state.$Viewlet;
9470
9481
  $Parent.append($Child);
9471
9482
  };
@@ -9537,7 +9548,7 @@ const executeCommands = commands => {
9537
9548
  }
9538
9549
  };
9539
9550
  const show = id => {
9540
- const instance = state$1.instances[id];
9551
+ const instance = get$9(id);
9541
9552
  const $Viewlet = instance.state.$Viewlet;
9542
9553
  const $Workbench = document.getElementById('Workbench');
9543
9554
  // @ts-expect-error
@@ -9547,7 +9558,7 @@ const show = id => {
9547
9558
  }
9548
9559
  };
9549
9560
  const setBounds$1 = (id, left, top, width, height) => {
9550
- const instance = state$1.instances[id];
9561
+ const instance = get$9(id);
9551
9562
  if (!instance) {
9552
9563
  return;
9553
9564
  }
@@ -9555,7 +9566,7 @@ const setBounds$1 = (id, left, top, width, height) => {
9555
9566
  setBounds$a($Viewlet, left, top, width, height);
9556
9567
  };
9557
9568
  const setProperty = (id, selector, property, value) => {
9558
- const instance = state$1.instances[id];
9569
+ const instance = get$9(id);
9559
9570
  if (!instance) {
9560
9571
  return;
9561
9572
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "21.5.0",
3
+ "version": "21.7.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "renderer-process"