@lvce-editor/renderer-process 21.6.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) {
@@ -1187,6 +1187,13 @@ const rememberFocus$1 = ($Viewlet, dom, eventMap, uid = 0) => {
1187
1187
  stopIgnore();
1188
1188
  return $Viewlet;
1189
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
+ };
1190
1197
 
1191
1198
  const get$8 = ids => {
1192
1199
  return getFileHandles$1(ids);
@@ -8924,18 +8931,19 @@ const create$3 = (id, uid = id) => {
8924
8931
  if (!module) {
8925
8932
  throw new Error(`module not found: ${id}`);
8926
8933
  }
8927
- if (state$1.instances[id]?.state.$Viewlet.isConnected) {
8928
- state$1.instances[id].state.$Viewlet.remove();
8934
+ const existing = get$9(id);
8935
+ if (existing?.state.$Viewlet.isConnected) {
8936
+ existing.state.$Viewlet.remove();
8929
8937
  }
8930
8938
  const instanceState = module.create();
8931
8939
  set$3(instanceState.$Viewlet, uid);
8932
8940
  if (module.attachEvents) {
8933
8941
  module.attachEvents(instanceState);
8934
8942
  }
8935
- state$1.instances[uid] = {
8943
+ set$8(uid, {
8936
8944
  factory: module,
8937
8945
  state: instanceState
8938
- };
8946
+ });
8939
8947
  };
8940
8948
  const createFunctionalRoot = (id, uid = id, hasFunctionalEvents) => {
8941
8949
  let module = state$1.modules[id];
@@ -8945,16 +8953,17 @@ const createFunctionalRoot = (id, uid = id, hasFunctionalEvents) => {
8945
8953
  if (!module) {
8946
8954
  throw new Error(`module not found: ${id}`);
8947
8955
  }
8948
- if (state$1.instances[id]?.state.$Viewlet.isConnected) {
8949
- state$1.instances[id].state.$Viewlet.remove();
8956
+ const existing = get$9(id);
8957
+ if (existing?.state.$Viewlet.isConnected) {
8958
+ existing.state.$Viewlet.remove();
8950
8959
  }
8951
8960
  const instanceState = {
8952
8961
  $Viewlet: document.createElement('div')
8953
8962
  };
8954
- state$1.instances[uid] = {
8963
+ set$8(uid, {
8955
8964
  factory: module,
8956
8965
  state: instanceState
8957
- };
8966
+ });
8958
8967
  };
8959
8968
  const addKeyBindings = (id, keyBindings) => {
8960
8969
  // @ts-expect-error
@@ -8974,7 +8983,7 @@ const loadModule = async id => {
8974
8983
  };
8975
8984
  const invoke = (viewletId, method, ...args) => {
8976
8985
  string(method);
8977
- const instance = state$1.instances[viewletId];
8986
+ const instance = get$9(viewletId);
8978
8987
  if (!instance?.factory) {
8979
8988
  if (viewletId && method !== 'setActionsDom') {
8980
8989
  warn$1(`cannot execute ${method} viewlet instance ${viewletId} not found`);
@@ -8992,7 +9001,7 @@ const focus$1 = viewletId => {
8992
9001
  // eslint-disable-next-line no-console
8993
9002
  console.trace(`focus ${viewletId}`);
8994
9003
  }
8995
- const instance = state$1.instances[viewletId];
9004
+ const instance = get$9(viewletId);
8996
9005
  if (instance.factory?.setFocused) {
8997
9006
  instance.factory.setFocused(instance.state, true);
8998
9007
  } else if (instance?.factory?.focus) {
@@ -9008,7 +9017,7 @@ const focusElementByName = (viewletId, name) => {
9008
9017
  // eslint-disable-next-line no-console
9009
9018
  console.trace(`focusByName ${viewletId} ${name}`);
9010
9019
  }
9011
- const instance = state$1.instances[viewletId];
9020
+ const instance = get$9(viewletId);
9012
9021
  if (!instance) {
9013
9022
  return;
9014
9023
  }
@@ -9023,7 +9032,7 @@ const focusElementByName = (viewletId, name) => {
9023
9032
  };
9024
9033
  const setElementProperty = (viewletId, name, key, value) => {
9025
9034
  const selector = `[name="${name}"]`;
9026
- const instance = state$1.instances[viewletId];
9035
+ const instance = get$9(viewletId);
9027
9036
  if (!instance) {
9028
9037
  return;
9029
9038
  }
@@ -9052,7 +9061,7 @@ const setCheckBoxValue = (viewletId, name, value) => {
9052
9061
  };
9053
9062
  const setSelectionByName = (viewletId, name, start, end) => {
9054
9063
  const selector = `[name="${name}"]`;
9055
- const instance = state$1.instances[viewletId];
9064
+ const instance = get$9(viewletId);
9056
9065
  if (!instance) {
9057
9066
  return;
9058
9067
  }
@@ -9067,7 +9076,7 @@ const setSelectionByName = (viewletId, name, start, end) => {
9067
9076
  $Element.selectionEnd = end;
9068
9077
  };
9069
9078
  const setUid = (viewletId, uid) => {
9070
- const instance = state$1.instances[viewletId];
9079
+ const instance = get$9(viewletId);
9071
9080
  if (!instance) {
9072
9081
  return;
9073
9082
  }
@@ -9077,7 +9086,7 @@ const setUid = (viewletId, uid) => {
9077
9086
  set$3($Viewlet, uid);
9078
9087
  };
9079
9088
  const focusSelector = (viewletId, selector) => {
9080
- const instance = state$1.instances[viewletId];
9089
+ const instance = get$9(viewletId);
9081
9090
  if (!instance) {
9082
9091
  return;
9083
9092
  }
@@ -9095,7 +9104,7 @@ const focusSelector = (viewletId, selector) => {
9095
9104
  * @deprecated
9096
9105
  */
9097
9106
  const refresh$1 = (viewletId, viewletContext) => {
9098
- const instance = state$1.instances[viewletId];
9107
+ const instance = get$9(viewletId);
9099
9108
  if (instance) {
9100
9109
  instance.factory.refresh(instance.state, viewletContext);
9101
9110
  } else {
@@ -9114,20 +9123,20 @@ const createPlaceholder = (viewletId, parentId, top, left, width, height) => {
9114
9123
  if (isSpecial(viewletId)) {
9115
9124
  $PlaceHolder.id = viewletId;
9116
9125
  }
9117
- const parentInstance = state$1.instances[parentId];
9126
+ const parentInstance = get$9(parentId);
9118
9127
  const $Parent = parentInstance.state.$Viewlet;
9119
9128
  $Parent.append($PlaceHolder);
9120
- state$1.instances[viewletId] = {
9129
+ set$8(viewletId, {
9121
9130
  state: {
9122
9131
  $Viewlet: $PlaceHolder
9123
9132
  }
9124
- };
9133
+ });
9125
9134
  };
9126
9135
  const setDragData = (viewletId, dragData) => {
9127
9136
  set$2(viewletId, dragData);
9128
9137
  };
9129
9138
  const setDom = (viewletId, dom) => {
9130
- const instance = state$1.instances[viewletId];
9139
+ const instance = get$9(viewletId);
9131
9140
  if (!instance) {
9132
9141
  return;
9133
9142
  }
@@ -9140,7 +9149,7 @@ const setDom = (viewletId, dom) => {
9140
9149
  renderInto($Viewlet, dom, Events);
9141
9150
  };
9142
9151
  const setDom2 = (viewletId, dom) => {
9143
- const instance = state$1.instances[viewletId];
9152
+ const instance = get$9(viewletId);
9144
9153
  if (!instance) {
9145
9154
  return;
9146
9155
  }
@@ -9162,10 +9171,16 @@ const setDom2 = (viewletId, dom) => {
9162
9171
  // @ts-ignore
9163
9172
  set$3($NewViewlet, uid);
9164
9173
  }
9165
- instance.state.$Viewlet = $NewViewlet;
9174
+ set$8(viewletId, {
9175
+ ...instance,
9176
+ state: {
9177
+ ...instance.state,
9178
+ $Viewlet: $NewViewlet
9179
+ }
9180
+ });
9166
9181
  };
9167
9182
  const setPatches = (uid, patches) => {
9168
- const instance = state$1.instances[uid];
9183
+ const instance = get$9(uid);
9169
9184
  if (!instance) {
9170
9185
  return;
9171
9186
  }
@@ -9336,10 +9351,7 @@ const sendMultiple = commands => {
9336
9351
  const dispose$3 = id => {
9337
9352
  try {
9338
9353
  number(id);
9339
- const {
9340
- instances
9341
- } = state$1;
9342
- const instance = instances[id];
9354
+ const instance = get$9(id);
9343
9355
  if (!instance) {
9344
9356
  warn$1(`viewlet instance ${id} not found and cannot be disposed`);
9345
9357
  return;
@@ -9350,14 +9362,14 @@ const dispose$3 = id => {
9350
9362
  if (instance.state.$Viewlet?.isConnected) {
9351
9363
  instance.state.$Viewlet.remove();
9352
9364
  }
9353
- delete instances[id];
9365
+ set$8(id, undefined);
9354
9366
  } catch {
9355
9367
  throw new Error(`Failed to dispose ${id}`);
9356
9368
  }
9357
9369
  };
9358
9370
  const handleError$1 = (id, parentId, message) => {
9359
9371
  info(`[viewlet-error] ${id}: ${message}`);
9360
- const instance = state$1.instances[id];
9372
+ const instance = get$9(id);
9361
9373
  if (instance?.state.$Viewlet.isConnected) {
9362
9374
  instance.state.$Viewlet.remove();
9363
9375
  }
@@ -9369,7 +9381,7 @@ const handleError$1 = (id, parentId, message) => {
9369
9381
  instance.state.$Viewlet.textContent = `${message}`;
9370
9382
  }
9371
9383
  // TODO error should bubble up to until highest possible component
9372
- const parentInstance = state$1.instances[parentId];
9384
+ const parentInstance = get$9(parentId);
9373
9385
  if (parentInstance?.factory?.handleError) {
9374
9386
  parentInstance.factory.handleError(instance.state, message);
9375
9387
  }
@@ -9383,9 +9395,9 @@ const appendViewlet = (parentId, childId, focus) => {
9383
9395
  // TODO
9384
9396
  return;
9385
9397
  }
9386
- 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
9387
9399
  const parentModule = parentInstanceState.factory;
9388
- const childInstance = state$1.instances[childId];
9400
+ const childInstance = get$9(childId);
9389
9401
  if (!childInstance) {
9390
9402
  throw new Error(`child instance ${childId} must be defined to be appended to parent ${parentId}`);
9391
9403
  }
@@ -9404,12 +9416,12 @@ const ariaAnnounce = async message => {
9404
9416
  const append = (parentId, childId, referenceNodes) => {
9405
9417
  number(parentId);
9406
9418
  number(childId);
9407
- const parentInstance = state$1.instances[parentId];
9419
+ const parentInstance = get$9(parentId);
9408
9420
  if (!parentInstance) {
9409
9421
  throw new Error(`cannot append child: instance ${parentId} not found`);
9410
9422
  }
9411
9423
  const $Parent = parentInstance.state.$Viewlet;
9412
- const childInstance = state$1.instances[childId];
9424
+ const childInstance = get$9(childId);
9413
9425
  if (!childInstance) {
9414
9426
  throw new Error(`cannot append child: child instance not found ${childId}`);
9415
9427
  }
@@ -9425,16 +9437,18 @@ const append = (parentId, childId, referenceNodes) => {
9425
9437
  if (id === childId) {
9426
9438
  for (let j = i - 1; j >= 0; j--) {
9427
9439
  const beforeId = referenceNodes[j];
9428
- if (state$1.instances[beforeId]) {
9429
- const $ReferenceNode = state$1.instances[beforeId].state.$Viewlet;
9440
+ const beforeInstance = get$9(beforeId);
9441
+ if (beforeInstance) {
9442
+ const $ReferenceNode = beforeInstance.state.$Viewlet;
9430
9443
  $ReferenceNode.after($Child);
9431
9444
  return;
9432
9445
  }
9433
9446
  }
9434
9447
  for (let j = i + 1; j < referenceNodes.length; j++) {
9435
9448
  const afterId = referenceNodes[j];
9436
- if (state$1.instances[afterId]) {
9437
- const $ReferenceNode = state$1.instances[afterId].state.$Viewlet;
9449
+ const afterInstance = get$9(afterId);
9450
+ if (afterInstance) {
9451
+ const $ReferenceNode = afterInstance.state.$Viewlet;
9438
9452
  $ReferenceNode.before($Child);
9439
9453
  return;
9440
9454
  }
@@ -9450,11 +9464,11 @@ const append = (parentId, childId, referenceNodes) => {
9450
9464
  }
9451
9465
  };
9452
9466
  const replaceChildren = (parentId, childIds) => {
9453
- const parentInstance = state$1.instances[parentId];
9467
+ const parentInstance = get$9(parentId);
9454
9468
  const $Parent = parentInstance.state.$Viewlet;
9455
9469
  const $Fragment = document.createDocumentFragment();
9456
9470
  for (const childId of childIds) {
9457
- const childInstance = state$1.instances[childId];
9471
+ const childInstance = get$9(childId);
9458
9472
  const $Child = childInstance.state.$Viewlet;
9459
9473
  $Fragment.append($Child);
9460
9474
  }
@@ -9462,7 +9476,7 @@ const replaceChildren = (parentId, childIds) => {
9462
9476
  };
9463
9477
  const appendToBody = childId => {
9464
9478
  const $Parent = document.body;
9465
- const childInstance = state$1.instances[childId];
9479
+ const childInstance = get$9(childId);
9466
9480
  const $Child = childInstance.state.$Viewlet;
9467
9481
  $Parent.append($Child);
9468
9482
  };
@@ -9534,7 +9548,7 @@ const executeCommands = commands => {
9534
9548
  }
9535
9549
  };
9536
9550
  const show = id => {
9537
- const instance = state$1.instances[id];
9551
+ const instance = get$9(id);
9538
9552
  const $Viewlet = instance.state.$Viewlet;
9539
9553
  const $Workbench = document.getElementById('Workbench');
9540
9554
  // @ts-expect-error
@@ -9544,7 +9558,7 @@ const show = id => {
9544
9558
  }
9545
9559
  };
9546
9560
  const setBounds$1 = (id, left, top, width, height) => {
9547
- const instance = state$1.instances[id];
9561
+ const instance = get$9(id);
9548
9562
  if (!instance) {
9549
9563
  return;
9550
9564
  }
@@ -9552,7 +9566,7 @@ const setBounds$1 = (id, left, top, width, height) => {
9552
9566
  setBounds$a($Viewlet, left, top, width, height);
9553
9567
  };
9554
9568
  const setProperty = (id, selector, property, value) => {
9555
- const instance = state$1.instances[id];
9569
+ const instance = get$9(id);
9556
9570
  if (!instance) {
9557
9571
  return;
9558
9572
  }
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.7.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "renderer-process"