@excalidraw/element 0.18.0-6d75c4b34 → 0.18.0-7876ee524

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.
Files changed (46) hide show
  1. package/dist/dev/index.js +339 -147
  2. package/dist/dev/index.js.map +3 -3
  3. package/dist/prod/index.js +12 -12
  4. package/dist/types/common/src/constants.d.ts +1 -0
  5. package/dist/types/element/src/Scene.d.ts +6 -2
  6. package/dist/types/element/src/align.d.ts +2 -1
  7. package/dist/types/element/src/delta.d.ts +18 -5
  8. package/dist/types/element/src/distribute.d.ts +2 -1
  9. package/dist/types/element/src/groups.d.ts +1 -0
  10. package/dist/types/element/src/linearElementEditor.d.ts +2 -1
  11. package/dist/types/element/src/store.d.ts +5 -1
  12. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +0 -3
  13. package/dist/types/excalidraw/actions/actionBoundText.d.ts +0 -2
  14. package/dist/types/excalidraw/actions/actionCanvas.d.ts +0 -13
  15. package/dist/types/excalidraw/actions/actionClipboard.d.ts +3 -8
  16. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +0 -1
  17. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +3 -6
  18. package/dist/types/excalidraw/actions/actionElementLink.d.ts +0 -1
  19. package/dist/types/excalidraw/actions/actionElementLock.d.ts +0 -2
  20. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +0 -1
  21. package/dist/types/excalidraw/actions/actionExport.d.ts +0 -9
  22. package/dist/types/excalidraw/actions/actionFinalize.d.ts +2 -3
  23. package/dist/types/excalidraw/actions/actionFrame.d.ts +0 -4
  24. package/dist/types/excalidraw/actions/actionGroup.d.ts +0 -2
  25. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +33 -3
  26. package/dist/types/excalidraw/actions/actionLink.d.ts +0 -1
  27. package/dist/types/excalidraw/actions/actionMenu.d.ts +0 -3
  28. package/dist/types/excalidraw/actions/actionNavigate.d.ts +0 -2
  29. package/dist/types/excalidraw/actions/actionProperties.d.ts +0 -15
  30. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +0 -1
  31. package/dist/types/excalidraw/actions/actionStyles.d.ts +0 -1
  32. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +0 -1
  33. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +0 -1
  34. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +0 -1
  35. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +0 -1
  36. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +0 -1
  37. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +0 -1
  38. package/dist/types/excalidraw/components/Actions.d.ts +0 -4
  39. package/dist/types/excalidraw/components/App.d.ts +4 -3
  40. package/dist/types/excalidraw/components/Ellipsify.d.ts +4 -0
  41. package/dist/types/excalidraw/data/reconcile.d.ts +1 -0
  42. package/dist/types/excalidraw/data/restore.d.ts +6 -1
  43. package/dist/types/excalidraw/index.d.ts +2 -1
  44. package/dist/types/excalidraw/renderer/staticScene.d.ts +4 -1
  45. package/dist/types/excalidraw/types.d.ts +5 -4
  46. package/package.json +3 -3
package/dist/dev/index.js CHANGED
@@ -3825,9 +3825,6 @@ var getTextWidth = (text, font) => {
3825
3825
  return width;
3826
3826
  };
3827
3827
  var getTextHeight = (text, fontSize, lineHeight) => {
3828
- if (text.trim() === "") {
3829
- return 0;
3830
- }
3831
3828
  const lineCount = splitIntoLines(text).length;
3832
3829
  return getLineHeightInPx(fontSize, lineHeight) * lineCount;
3833
3830
  };
@@ -8130,7 +8127,8 @@ var LinearElementEditor = class _LinearElementEditor {
8130
8127
  segmentMidPointHoveredCoords;
8131
8128
  elbowed;
8132
8129
  customLineAngle;
8133
- constructor(element, elementsMap) {
8130
+ isEditing;
8131
+ constructor(element, elementsMap, isEditing = false) {
8134
8132
  this.elementId = element.id;
8135
8133
  if (!pointsEqual6(element.points[0], pointFrom8(0, 0))) {
8136
8134
  console.error("Linear element is not normalized", Error().stack);
@@ -8161,6 +8159,7 @@ var LinearElementEditor = class _LinearElementEditor {
8161
8159
  this.segmentMidPointHoveredCoords = null;
8162
8160
  this.elbowed = isElbowArrow(element) && element.elbowed;
8163
8161
  this.customLineAngle = null;
8162
+ this.isEditing = isEditing;
8164
8163
  }
8165
8164
  // ---------------------------------------------------------------------------
8166
8165
  // static methods
@@ -8178,11 +8177,11 @@ var LinearElementEditor = class _LinearElementEditor {
8178
8177
  return null;
8179
8178
  }
8180
8179
  static handleBoxSelection(event, appState, setState, elementsMap) {
8181
- if (!appState.editingLinearElement || !appState.selectionElement) {
8180
+ if (!appState.selectedLinearElement?.isEditing || !appState.selectionElement) {
8182
8181
  return false;
8183
8182
  }
8184
- const { editingLinearElement } = appState;
8185
- const { selectedPointsIndices, elementId } = editingLinearElement;
8183
+ const { selectedLinearElement } = appState;
8184
+ const { selectedPointsIndices, elementId } = selectedLinearElement;
8186
8185
  const element = _LinearElementEditor.getElement(elementId, elementsMap);
8187
8186
  if (!element) {
8188
8187
  return false;
@@ -8204,8 +8203,8 @@ var LinearElementEditor = class _LinearElementEditor {
8204
8203
  return true;
8205
8204
  });
8206
8205
  setState({
8207
- editingLinearElement: {
8208
- ...editingLinearElement,
8206
+ selectedLinearElement: {
8207
+ ...selectedLinearElement,
8209
8208
  selectedPointsIndices: nextSelectedPoints.length ? nextSelectedPoints : null
8210
8209
  }
8211
8210
  });
@@ -8359,7 +8358,6 @@ var LinearElementEditor = class _LinearElementEditor {
8359
8358
  };
8360
8359
  return {
8361
8360
  ...app.state,
8362
- editingLinearElement: app.state.editingLinearElement ? newLinearElementEditor : null,
8363
8361
  selectedLinearElement: newLinearElementEditor,
8364
8362
  suggestedBindings
8365
8363
  };
@@ -8443,7 +8441,7 @@ var LinearElementEditor = class _LinearElementEditor {
8443
8441
  }
8444
8442
  static getEditorMidPoints = (element, elementsMap, appState) => {
8445
8443
  const boundText = getBoundTextElement(element, elementsMap);
8446
- if (!isElbowArrow(element) && !appState.editingLinearElement && element.points.length > 2 && !boundText) {
8444
+ if (!isElbowArrow(element) && !appState.selectedLinearElement?.isEditing && element.points.length > 2 && !boundText) {
8447
8445
  return [];
8448
8446
  }
8449
8447
  const points = _LinearElementEditor.getPointsGlobalCoordinates(
@@ -8493,7 +8491,7 @@ var LinearElementEditor = class _LinearElementEditor {
8493
8491
  element,
8494
8492
  elementsMap
8495
8493
  );
8496
- if (points.length >= 3 && !appState.editingLinearElement && !isElbowArrow(element)) {
8494
+ if (points.length >= 3 && !appState.selectedLinearElement?.isEditing && !isElbowArrow(element)) {
8497
8495
  return null;
8498
8496
  }
8499
8497
  const threshold = (_LinearElementEditor.POINT_HANDLE_SIZE + 1) / appState.zoom.value;
@@ -8633,7 +8631,7 @@ var LinearElementEditor = class _LinearElementEditor {
8633
8631
  segmentMidpoint,
8634
8632
  elementsMap
8635
8633
  );
8636
- } else if (event.altKey && appState.editingLinearElement) {
8634
+ } else if (event.altKey && appState.selectedLinearElement?.isEditing) {
8637
8635
  if (linearElementEditor.lastUncommittedPoint == null) {
8638
8636
  scene.mutateElement(element, {
8639
8637
  points: [
@@ -8743,14 +8741,14 @@ var LinearElementEditor = class _LinearElementEditor {
8743
8741
  }
8744
8742
  static handlePointerMove(event, scenePointerX, scenePointerY, app) {
8745
8743
  const appState = app.state;
8746
- if (!appState.editingLinearElement) {
8744
+ if (!appState.selectedLinearElement?.isEditing) {
8747
8745
  return null;
8748
8746
  }
8749
- const { elementId, lastUncommittedPoint } = appState.editingLinearElement;
8747
+ const { elementId, lastUncommittedPoint } = appState.selectedLinearElement;
8750
8748
  const elementsMap = app.scene.getNonDeletedElementsMap();
8751
8749
  const element = _LinearElementEditor.getElement(elementId, elementsMap);
8752
8750
  if (!element) {
8753
- return appState.editingLinearElement;
8751
+ return appState.selectedLinearElement;
8754
8752
  }
8755
8753
  const { points } = element;
8756
8754
  const lastPoint = points[points.length - 1];
@@ -8758,10 +8756,10 @@ var LinearElementEditor = class _LinearElementEditor {
8758
8756
  if (lastPoint === lastUncommittedPoint) {
8759
8757
  _LinearElementEditor.deletePoints(element, app, [points.length - 1]);
8760
8758
  }
8761
- return {
8762
- ...appState.editingLinearElement,
8759
+ return appState.selectedLinearElement?.lastUncommittedPoint ? {
8760
+ ...appState.selectedLinearElement,
8763
8761
  lastUncommittedPoint: null
8764
- };
8762
+ } : appState.selectedLinearElement;
8765
8763
  }
8766
8764
  let newPoint;
8767
8765
  if (shouldRotateWithDiscreteAngle(event) && points.length >= 2) {
@@ -8781,8 +8779,8 @@ var LinearElementEditor = class _LinearElementEditor {
8781
8779
  newPoint = _LinearElementEditor.createPointAt(
8782
8780
  element,
8783
8781
  elementsMap,
8784
- scenePointerX - appState.editingLinearElement.pointerOffset.x,
8785
- scenePointerY - appState.editingLinearElement.pointerOffset.y,
8782
+ scenePointerX - appState.selectedLinearElement.pointerOffset.x,
8783
+ scenePointerY - appState.selectedLinearElement.pointerOffset.y,
8786
8784
  event[KEYS2.CTRL_OR_CMD] || isElbowArrow(element) ? null : app.getEffectiveGridSize()
8787
8785
  );
8788
8786
  }
@@ -8803,7 +8801,7 @@ var LinearElementEditor = class _LinearElementEditor {
8803
8801
  _LinearElementEditor.addPoints(element, app.scene, [newPoint]);
8804
8802
  }
8805
8803
  return {
8806
- ...appState.editingLinearElement,
8804
+ ...appState.selectedLinearElement,
8807
8805
  lastUncommittedPoint: element.points[element.points.length - 1]
8808
8806
  };
8809
8807
  }
@@ -8909,11 +8907,11 @@ var LinearElementEditor = class _LinearElementEditor {
8909
8907
  // ---------------------------------------------------------------------------
8910
8908
  static duplicateSelectedPoints(appState, scene) {
8911
8909
  invariant6(
8912
- appState.editingLinearElement,
8910
+ appState.selectedLinearElement?.isEditing,
8913
8911
  "Not currently editing a linear element"
8914
8912
  );
8915
8913
  const elementsMap = scene.getNonDeletedElementsMap();
8916
- const { selectedPointsIndices, elementId } = appState.editingLinearElement;
8914
+ const { selectedPointsIndices, elementId } = appState.selectedLinearElement;
8917
8915
  const element = _LinearElementEditor.getElement(elementId, elementsMap);
8918
8916
  invariant6(
8919
8917
  element,
@@ -8960,14 +8958,14 @@ var LinearElementEditor = class _LinearElementEditor {
8960
8958
  }
8961
8959
  return {
8962
8960
  ...appState,
8963
- editingLinearElement: {
8964
- ...appState.editingLinearElement,
8961
+ selectedLinearElement: {
8962
+ ...appState.selectedLinearElement,
8965
8963
  selectedPointsIndices: nextSelectedIndices
8966
8964
  }
8967
8965
  };
8968
8966
  }
8969
8967
  static deletePoints(element, app, pointIndices) {
8970
- const isUncommittedPoint = app.state.editingLinearElement?.lastUncommittedPoint === element.points[element.points.length - 1];
8968
+ const isUncommittedPoint = app.state.selectedLinearElement?.isEditing && app.state.selectedLinearElement?.lastUncommittedPoint === element.points[element.points.length - 1];
8971
8969
  const nextPoints = element.points.filter((_, idx) => {
8972
8970
  return !pointIndices.includes(idx);
8973
8971
  });
@@ -9076,7 +9074,7 @@ var LinearElementEditor = class _LinearElementEditor {
9076
9074
  pointFrom8(origin.x, origin.y),
9077
9075
  pointFrom8(pointerCoords.x, pointerCoords.y)
9078
9076
  );
9079
- if (!appState.editingLinearElement && dist < DRAGGING_THRESHOLD / appState.zoom.value) {
9077
+ if (!appState.selectedLinearElement?.isEditing && dist < DRAGGING_THRESHOLD / appState.zoom.value) {
9080
9078
  return false;
9081
9079
  }
9082
9080
  return true;
@@ -9829,6 +9827,55 @@ var getNewGroupIdsForDuplication = (groupIds, editingGroupId, mapper) => {
9829
9827
  }
9830
9828
  return copy;
9831
9829
  };
9830
+ var getSelectedElementsByGroup = (selectedElements, elementsMap, appState) => {
9831
+ const selectedGroupIds = getSelectedGroupIds(appState);
9832
+ const unboundElements = selectedElements.filter(
9833
+ (element) => !isBoundToContainer(element)
9834
+ );
9835
+ const groups = /* @__PURE__ */ new Map();
9836
+ const elements = /* @__PURE__ */ new Map();
9837
+ const addToElementsMap = (element) => {
9838
+ const currentElementMembers = elements.get(element.id) || [];
9839
+ const boundTextElement = getBoundTextElement(element, elementsMap);
9840
+ if (boundTextElement) {
9841
+ currentElementMembers.push(boundTextElement);
9842
+ }
9843
+ elements.set(element.id, [...currentElementMembers, element]);
9844
+ };
9845
+ const addToGroupsMap = (element, groupId) => {
9846
+ const currentGroupMembers = groups.get(groupId) || [];
9847
+ const boundTextElement = getBoundTextElement(element, elementsMap);
9848
+ if (boundTextElement) {
9849
+ currentGroupMembers.push(boundTextElement);
9850
+ }
9851
+ groups.set(groupId, [...currentGroupMembers, element]);
9852
+ };
9853
+ const handleSingleSelectedGroupCase = (element, selectedGroupId) => {
9854
+ const indexOfSelectedGroupId = element.groupIds.indexOf(selectedGroupId, 0);
9855
+ const nestedGroupCount = element.groupIds.slice(
9856
+ 0,
9857
+ indexOfSelectedGroupId
9858
+ ).length;
9859
+ return nestedGroupCount > 0 ? addToGroupsMap(element, element.groupIds[indexOfSelectedGroupId - 1]) : addToElementsMap(element);
9860
+ };
9861
+ const isAllInSameGroup = selectedElements.every(
9862
+ (element) => isSelectedViaGroup(appState, element)
9863
+ );
9864
+ unboundElements.forEach((element) => {
9865
+ const selectedGroupId = getSelectedGroupIdForElement(
9866
+ element,
9867
+ appState.selectedGroupIds
9868
+ );
9869
+ if (!selectedGroupId) {
9870
+ addToElementsMap(element);
9871
+ } else if (selectedGroupIds.length === 1 && isAllInSameGroup) {
9872
+ handleSingleSelectedGroupCase(element, selectedGroupId);
9873
+ } else {
9874
+ addToGroupsMap(element, selectedGroupId);
9875
+ }
9876
+ });
9877
+ return Array.from(groups.values()).concat(Array.from(elements.values()));
9878
+ };
9832
9879
 
9833
9880
  // src/selection.ts
9834
9881
  var excludeElementsInFramesFromSelection = (selectedElements) => {
@@ -10516,6 +10563,11 @@ var getCanvasPadding = (element) => {
10516
10563
  return element.strokeWidth * 12;
10517
10564
  case "text":
10518
10565
  return element.fontSize / 2;
10566
+ case "arrow":
10567
+ if (element.endArrowhead || element.endArrowhead) {
10568
+ return 40;
10569
+ }
10570
+ return 20;
10519
10571
  default:
10520
10572
  return 20;
10521
10573
  }
@@ -12745,11 +12797,11 @@ var getNormalizedDimensions = (element) => {
12745
12797
 
12746
12798
  // src/align.ts
12747
12799
  init_define_import_meta_env();
12748
- var alignElements = (selectedElements, alignment, scene) => {
12749
- const elementsMap = scene.getNonDeletedElementsMap();
12750
- const groups = getMaximumGroups(
12800
+ var alignElements = (selectedElements, alignment, scene, appState) => {
12801
+ const groups = getSelectedElementsByGroup(
12751
12802
  selectedElements,
12752
- elementsMap
12803
+ scene.getNonDeletedElementsMap(),
12804
+ appState
12753
12805
  );
12754
12806
  const selectionBoundingBox = getCommonBoundingBox(selectedElements);
12755
12807
  return groups.flatMap((group) => {
@@ -13185,8 +13237,9 @@ var Store = class {
13185
13237
  constructor(app) {
13186
13238
  this.app = app;
13187
13239
  }
13188
- // internally used by history
13240
+ // for internal use by history
13189
13241
  onDurableIncrementEmitter = new Emitter();
13242
+ // for public use as part of onIncrement API
13190
13243
  onStoreIncrementEmitter = new Emitter();
13191
13244
  scheduledMacroActions = /* @__PURE__ */ new Set();
13192
13245
  scheduledMicroActions = [];
@@ -13480,10 +13533,20 @@ var StoreDelta = class {
13480
13533
  */
13481
13534
  static load({
13482
13535
  id,
13483
- elements: { added, removed, updated }
13536
+ elements: { added, removed, updated },
13537
+ appState: { delta: appStateDelta }
13484
13538
  }) {
13485
13539
  const elements = ElementsDelta.create(added, removed, updated);
13486
- return new this(id, elements, AppStateDelta.empty());
13540
+ const appState = AppStateDelta.create(appStateDelta);
13541
+ return new this(id, elements, appState);
13542
+ }
13543
+ /**
13544
+ * Squash the passed delta into the current instance.
13545
+ */
13546
+ squash(delta) {
13547
+ this.elements.squash(delta.elements);
13548
+ this.appState.squash(delta.appState);
13549
+ return this;
13487
13550
  }
13488
13551
  /**
13489
13552
  * Inverse store delta, creates new instance of `StoreDelta`.
@@ -13494,9 +13557,7 @@ var StoreDelta = class {
13494
13557
  /**
13495
13558
  * Apply the delta to the passed elements and appState, does not modify the snapshot.
13496
13559
  */
13497
- static applyTo(delta, elements, appState, options = {
13498
- excludedProperties: /* @__PURE__ */ new Set()
13499
- }) {
13560
+ static applyTo(delta, elements, appState, options) {
13500
13561
  const [nextElements, elementsContainVisibleChange] = delta.elements.applyTo(
13501
13562
  elements,
13502
13563
  StoreSnapshot.empty().elements,
@@ -13762,8 +13823,7 @@ var getDefaultObservedAppState = () => {
13762
13823
  viewBackgroundColor: COLOR_PALETTE2.white,
13763
13824
  selectedElementIds: {},
13764
13825
  selectedGroupIds: {},
13765
- editingLinearElementId: null,
13766
- selectedLinearElementId: null,
13826
+ selectedLinearElement: null,
13767
13827
  croppingElementId: null,
13768
13828
  activeLockedId: null,
13769
13829
  lockedMultiSelections: {}
@@ -13779,10 +13839,10 @@ var getObservedAppState = (appState) => {
13779
13839
  croppingElementId: appState.croppingElementId,
13780
13840
  activeLockedId: appState.activeLockedId,
13781
13841
  lockedMultiSelections: appState.lockedMultiSelections,
13782
- editingLinearElementId: appState.editingLinearElement?.elementId ?? // prefer app state, as it's likely newer
13783
- appState.editingLinearElementId ?? // fallback to observed app state, as it's likely older coming from a previous snapshot
13784
- null,
13785
- selectedLinearElementId: appState.selectedLinearElement?.elementId ?? appState.selectedLinearElementId ?? null
13842
+ selectedLinearElement: appState.selectedLinearElement ? {
13843
+ elementId: appState.selectedLinearElement.elementId,
13844
+ isEditing: !!appState.selectedLinearElement.isEditing
13845
+ } : null
13786
13846
  };
13787
13847
  Reflect.defineProperty(observedAppState, hiddenObservedAppStateProp, {
13788
13848
  value: true,
@@ -14346,9 +14406,9 @@ var Scene = class {
14346
14406
  getFramesIncludingDeleted() {
14347
14407
  return this.frames;
14348
14408
  }
14349
- constructor(elements = null) {
14409
+ constructor(elements = null, options) {
14350
14410
  if (elements) {
14351
- this.replaceAllElements(elements);
14411
+ this.replaceAllElements(elements, options);
14352
14412
  }
14353
14413
  }
14354
14414
  getSelectedElements(opts) {
@@ -14413,10 +14473,12 @@ var Scene = class {
14413
14473
  }
14414
14474
  return didChange;
14415
14475
  }
14416
- replaceAllElements(nextElements) {
14476
+ replaceAllElements(nextElements, options) {
14417
14477
  const _nextElements = toArray(nextElements);
14418
14478
  const nextFrameLikes = [];
14419
- validateIndicesThrottled(_nextElements);
14479
+ if (!options?.skipValidation) {
14480
+ validateIndicesThrottled(_nextElements);
14481
+ }
14420
14482
  this.elements = syncInvalidIndices2(_nextElements);
14421
14483
  this.elementsMap.clear();
14422
14484
  this.elements.forEach((element) => {
@@ -14586,12 +14648,21 @@ var Delta = class _Delta {
14586
14648
  static isEmpty(delta) {
14587
14649
  return !Object.keys(delta.deleted).length && !Object.keys(delta.inserted).length;
14588
14650
  }
14651
+ /**
14652
+ * Merges two deltas into a new one.
14653
+ */
14654
+ static merge(delta1, delta2, delta3) {
14655
+ return _Delta.create(
14656
+ { ...delta1.deleted, ...delta2.deleted, ...delta3?.deleted ?? {} },
14657
+ { ...delta1.inserted, ...delta2.inserted, ...delta3?.inserted ?? {} }
14658
+ );
14659
+ }
14589
14660
  /**
14590
14661
  * Merges deleted and inserted object partials.
14591
14662
  */
14592
14663
  static mergeObjects(prev, added, removed) {
14593
14664
  const cloned = { ...prev };
14594
- for (const key of Object.keys(removed)) {
14665
+ for (const key of Object.keys(removed ?? {})) {
14595
14666
  delete cloned[key];
14596
14667
  }
14597
14668
  return { ...cloned, ...added };
@@ -14810,6 +14881,9 @@ var AppStateDelta = class _AppStateDelta {
14810
14881
  constructor(delta) {
14811
14882
  this.delta = delta;
14812
14883
  }
14884
+ static create(delta) {
14885
+ return new _AppStateDelta(delta);
14886
+ }
14813
14887
  static calculate(prevAppState, nextAppState) {
14814
14888
  const delta = Delta.calculate(
14815
14889
  prevAppState,
@@ -14831,50 +14905,71 @@ var AppStateDelta = class _AppStateDelta {
14831
14905
  const inversedDelta = Delta.create(this.delta.inserted, this.delta.deleted);
14832
14906
  return new _AppStateDelta(inversedDelta);
14833
14907
  }
14908
+ squash(delta) {
14909
+ const mergedDeletedSelectedElementIds = Delta.mergeObjects(
14910
+ this.delta.deleted.selectedElementIds ?? {},
14911
+ delta.delta.deleted.selectedElementIds ?? {}
14912
+ );
14913
+ const mergedInsertedSelectedElementIds = Delta.mergeObjects(
14914
+ this.delta.inserted.selectedElementIds ?? {},
14915
+ delta.delta.inserted.selectedElementIds ?? {}
14916
+ );
14917
+ const mergedInsertedSelectedGroupIds = Delta.mergeObjects(
14918
+ this.delta.inserted.selectedGroupIds ?? {},
14919
+ delta.delta.inserted.selectedGroupIds ?? {}
14920
+ );
14921
+ const mergedDeletedSelectedGroupIds = Delta.mergeObjects(
14922
+ this.delta.deleted.selectedGroupIds ?? {},
14923
+ delta.delta.deleted.selectedGroupIds ?? {}
14924
+ );
14925
+ const mergedDelta = Delta.create(
14926
+ {
14927
+ selectedElementIds: mergedDeletedSelectedElementIds,
14928
+ selectedGroupIds: mergedDeletedSelectedGroupIds
14929
+ },
14930
+ {
14931
+ selectedElementIds: mergedInsertedSelectedElementIds,
14932
+ selectedGroupIds: mergedInsertedSelectedGroupIds
14933
+ }
14934
+ );
14935
+ this.delta = Delta.merge(this.delta, delta.delta, mergedDelta);
14936
+ return this;
14937
+ }
14834
14938
  applyTo(appState, nextElements) {
14835
14939
  try {
14836
14940
  const {
14837
- selectedElementIds: removedSelectedElementIds = {},
14838
- selectedGroupIds: removedSelectedGroupIds = {}
14941
+ selectedElementIds: deletedSelectedElementIds = {},
14942
+ selectedGroupIds: deletedSelectedGroupIds = {}
14839
14943
  } = this.delta.deleted;
14840
14944
  const {
14841
- selectedElementIds: addedSelectedElementIds = {},
14842
- selectedGroupIds: addedSelectedGroupIds = {},
14843
- selectedLinearElementId,
14844
- editingLinearElementId,
14945
+ selectedElementIds: insertedSelectedElementIds = {},
14946
+ selectedGroupIds: insertedSelectedGroupIds = {},
14947
+ selectedLinearElement: insertedSelectedLinearElement,
14845
14948
  ...directlyApplicablePartial
14846
14949
  } = this.delta.inserted;
14847
14950
  const mergedSelectedElementIds = Delta.mergeObjects(
14848
14951
  appState.selectedElementIds,
14849
- addedSelectedElementIds,
14850
- removedSelectedElementIds
14952
+ insertedSelectedElementIds,
14953
+ deletedSelectedElementIds
14851
14954
  );
14852
14955
  const mergedSelectedGroupIds = Delta.mergeObjects(
14853
14956
  appState.selectedGroupIds,
14854
- addedSelectedGroupIds,
14855
- removedSelectedGroupIds
14957
+ insertedSelectedGroupIds,
14958
+ deletedSelectedGroupIds
14856
14959
  );
14857
- const selectedLinearElement = selectedLinearElementId && nextElements.has(selectedLinearElementId) ? new LinearElementEditor(
14858
- nextElements.get(
14859
- selectedLinearElementId
14860
- ),
14861
- nextElements
14862
- ) : null;
14863
- const editingLinearElement = editingLinearElementId && nextElements.has(editingLinearElementId) ? new LinearElementEditor(
14960
+ const selectedLinearElement = insertedSelectedLinearElement && nextElements.has(insertedSelectedLinearElement.elementId) ? new LinearElementEditor(
14864
14961
  nextElements.get(
14865
- editingLinearElementId
14962
+ insertedSelectedLinearElement.elementId
14866
14963
  ),
14867
- nextElements
14964
+ nextElements,
14965
+ insertedSelectedLinearElement.isEditing
14868
14966
  ) : null;
14869
14967
  const nextAppState = {
14870
14968
  ...appState,
14871
14969
  ...directlyApplicablePartial,
14872
14970
  selectedElementIds: mergedSelectedElementIds,
14873
14971
  selectedGroupIds: mergedSelectedGroupIds,
14874
- selectedLinearElement: typeof selectedLinearElementId !== "undefined" ? selectedLinearElement : appState.selectedLinearElement,
14875
- // otherwise assign what we had before
14876
- editingLinearElement: typeof editingLinearElementId !== "undefined" ? editingLinearElement : appState.editingLinearElement
14877
- // otherwise assign what we had before
14972
+ selectedLinearElement: typeof insertedSelectedLinearElement !== "undefined" ? selectedLinearElement : appState.selectedLinearElement
14878
14973
  };
14879
14974
  const constainsVisibleChanges = this.filterInvisibleChanges(
14880
14975
  appState,
@@ -14964,57 +15059,44 @@ var AppStateDelta = class _AppStateDelta {
14964
15059
  nextAppState[key] = null;
14965
15060
  }
14966
15061
  break;
14967
- case "selectedLinearElementId":
14968
- case "editingLinearElementId":
14969
- const appStateKey = _AppStateDelta.convertToAppStateKey(key);
14970
- const linearElement = nextAppState[appStateKey];
14971
- if (!linearElement) {
15062
+ case "selectedLinearElement":
15063
+ const nextLinearElement = nextAppState[key];
15064
+ if (!nextLinearElement) {
14972
15065
  visibleDifferenceFlag.value = true;
14973
15066
  } else {
14974
- const element = nextElements.get(linearElement.elementId);
15067
+ const element = nextElements.get(nextLinearElement.elementId);
14975
15068
  if (element && !element.isDeleted) {
14976
15069
  visibleDifferenceFlag.value = true;
14977
15070
  } else {
14978
- nextAppState[appStateKey] = null;
15071
+ nextAppState[key] = null;
14979
15072
  }
14980
15073
  }
14981
15074
  break;
14982
- case "lockedMultiSelections": {
15075
+ case "lockedMultiSelections":
14983
15076
  const prevLockedUnits = prevAppState[key] || {};
14984
15077
  const nextLockedUnits = nextAppState[key] || {};
14985
15078
  if (!isShallowEqual2(prevLockedUnits, nextLockedUnits)) {
14986
15079
  visibleDifferenceFlag.value = true;
14987
15080
  }
14988
15081
  break;
14989
- }
14990
- case "activeLockedId": {
15082
+ case "activeLockedId":
14991
15083
  const prevHitLockedId = prevAppState[key] || null;
14992
15084
  const nextHitLockedId = nextAppState[key] || null;
14993
15085
  if (prevHitLockedId !== nextHitLockedId) {
14994
15086
  visibleDifferenceFlag.value = true;
14995
15087
  }
14996
15088
  break;
14997
- }
14998
- default: {
15089
+ default:
14999
15090
  assertNever4(
15000
15091
  key,
15001
15092
  `Unknown ObservedElementsAppState's key "${key}"`,
15002
15093
  true
15003
15094
  );
15004
- }
15005
15095
  }
15006
15096
  }
15007
15097
  }
15008
15098
  return visibleDifferenceFlag.value;
15009
15099
  }
15010
- static convertToAppStateKey(key) {
15011
- switch (key) {
15012
- case "selectedLinearElementId":
15013
- return "selectedLinearElement";
15014
- case "editingLinearElementId":
15015
- return "editingLinearElement";
15016
- }
15017
- }
15018
15100
  static filterSelectedElements(selectedElementIds, elements, visibleDifferenceFlag) {
15019
15101
  const ids = Object.keys(selectedElementIds);
15020
15102
  if (!ids.length) {
@@ -15053,8 +15135,7 @@ var AppStateDelta = class _AppStateDelta {
15053
15135
  editingGroupId,
15054
15136
  selectedGroupIds,
15055
15137
  selectedElementIds,
15056
- editingLinearElementId,
15057
- selectedLinearElementId,
15138
+ selectedLinearElement,
15058
15139
  croppingElementId,
15059
15140
  lockedMultiSelections,
15060
15141
  activeLockedId,
@@ -15179,9 +15260,13 @@ var ElementsDelta = class _ElementsDelta {
15179
15260
  Number.isInteger(deleted.version) && Number.isInteger(inserted.version) && // versions should be positive, zero included
15180
15261
  deleted.version >= 0 && inserted.version >= 0 && // versions should never be the same
15181
15262
  deleted.version !== inserted.version);
15263
+ static satisfiesUniqueInvariants = (elementsDelta, id) => {
15264
+ const { added, removed, updated } = elementsDelta;
15265
+ return [added[id], removed[id], updated[id]].filter(Boolean).length === 1;
15266
+ };
15182
15267
  static validate(elementsDelta, type, satifiesSpecialInvariants) {
15183
15268
  for (const [id, delta] of Object.entries(elementsDelta[type])) {
15184
- if (!this.satisfiesCommmonInvariants(delta) || !satifiesSpecialInvariants(delta)) {
15269
+ if (!this.satisfiesCommmonInvariants(delta) || !this.satisfiesUniqueInvariants(elementsDelta, id) || !satifiesSpecialInvariants(delta)) {
15185
15270
  console.error(
15186
15271
  `Broken invariant for "${type}" delta, element "${id}", delta:`,
15187
15272
  delta
@@ -15208,7 +15293,7 @@ var ElementsDelta = class _ElementsDelta {
15208
15293
  for (const prevElement of prevElements.values()) {
15209
15294
  const nextElement = nextElements.get(prevElement.id);
15210
15295
  if (!nextElement) {
15211
- const deleted = { ...prevElement, isDeleted: false };
15296
+ const deleted = { ...prevElement };
15212
15297
  const inserted = {
15213
15298
  isDeleted: true,
15214
15299
  version: prevElement.version + 1,
@@ -15219,7 +15304,9 @@ var ElementsDelta = class _ElementsDelta {
15219
15304
  inserted,
15220
15305
  _ElementsDelta.stripIrrelevantProps
15221
15306
  );
15222
- removed[prevElement.id] = delta;
15307
+ if (!prevElement.isDeleted) {
15308
+ removed[prevElement.id] = delta;
15309
+ }
15223
15310
  }
15224
15311
  }
15225
15312
  for (const nextElement of nextElements.values()) {
@@ -15231,15 +15318,16 @@ var ElementsDelta = class _ElementsDelta {
15231
15318
  versionNonce: randomInteger4()
15232
15319
  };
15233
15320
  const inserted = {
15234
- ...nextElement,
15235
- isDeleted: false
15321
+ ...nextElement
15236
15322
  };
15237
15323
  const delta = Delta.create(
15238
15324
  deleted,
15239
15325
  inserted,
15240
15326
  _ElementsDelta.stripIrrelevantProps
15241
15327
  );
15242
- added[nextElement.id] = delta;
15328
+ if (!nextElement.isDeleted) {
15329
+ added[nextElement.id] = delta;
15330
+ }
15243
15331
  continue;
15244
15332
  }
15245
15333
  if (prevElement.versionNonce !== nextElement.versionNonce) {
@@ -15260,7 +15348,11 @@ var ElementsDelta = class _ElementsDelta {
15260
15348
  }
15261
15349
  continue;
15262
15350
  }
15263
- if (!Delta.isEmpty(delta)) {
15351
+ const strippedDeleted = _ElementsDelta.stripVersionProps(delta.deleted);
15352
+ const strippedInserted = _ElementsDelta.stripVersionProps(
15353
+ delta.inserted
15354
+ );
15355
+ if (Delta.isInnerDifferent(strippedDeleted, strippedInserted, true)) {
15264
15356
  updated[nextElement.id] = delta;
15265
15357
  }
15266
15358
  }
@@ -15273,8 +15365,8 @@ var ElementsDelta = class _ElementsDelta {
15273
15365
  inverse() {
15274
15366
  const inverseInternal = (deltas) => {
15275
15367
  const inversedDeltas = {};
15276
- for (const [id, delta] of Object.entries(deltas)) {
15277
- inversedDeltas[id] = Delta.create(delta.inserted, delta.deleted);
15368
+ for (const [id, { inserted, deleted }] of Object.entries(deltas)) {
15369
+ inversedDeltas[id] = Delta.create({ ...inserted }, { ...deleted });
15278
15370
  }
15279
15371
  return inversedDeltas;
15280
15372
  };
@@ -15338,7 +15430,13 @@ var ElementsDelta = class _ElementsDelta {
15338
15430
  } else {
15339
15431
  latestDelta = delta;
15340
15432
  }
15341
- if (Delta.isInnerDifferent(latestDelta.deleted, latestDelta.inserted)) {
15433
+ const strippedDeleted = _ElementsDelta.stripVersionProps(
15434
+ latestDelta.deleted
15435
+ );
15436
+ const strippedInserted = _ElementsDelta.stripVersionProps(
15437
+ latestDelta.inserted
15438
+ );
15439
+ if (Delta.isInnerDifferent(strippedDeleted, strippedInserted)) {
15342
15440
  modifiedDeltas[id] = latestDelta;
15343
15441
  }
15344
15442
  }
@@ -15352,26 +15450,30 @@ var ElementsDelta = class _ElementsDelta {
15352
15450
  // redistribute the deltas as `isDeleted` could have been updated
15353
15451
  });
15354
15452
  }
15355
- applyTo(elements, snapshot = StoreSnapshot.empty().elements, options = {
15356
- excludedProperties: /* @__PURE__ */ new Set()
15357
- }) {
15453
+ applyTo(elements, snapshot = StoreSnapshot.empty().elements, options) {
15358
15454
  let nextElements = new Map(elements);
15359
15455
  let changedElements;
15360
15456
  const flags = {
15361
15457
  containsVisibleDifference: false,
15362
- containsZindexDifference: false
15458
+ containsZindexDifference: false,
15459
+ applyDirection: void 0
15363
15460
  };
15364
15461
  try {
15365
15462
  const applyDeltas = _ElementsDelta.createApplier(
15463
+ elements,
15366
15464
  nextElements,
15367
15465
  snapshot,
15368
- options,
15369
- flags
15466
+ flags,
15467
+ options
15370
15468
  );
15371
15469
  const addedElements = applyDeltas(this.added);
15372
15470
  const removedElements = applyDeltas(this.removed);
15373
15471
  const updatedElements = applyDeltas(this.updated);
15374
- const affectedElements = this.resolveConflicts(elements, nextElements);
15472
+ const affectedElements = this.resolveConflicts(
15473
+ elements,
15474
+ nextElements,
15475
+ flags.applyDirection
15476
+ );
15375
15477
  changedElements = new Map([
15376
15478
  ...addedElements,
15377
15479
  ...removedElements,
@@ -15391,9 +15493,7 @@ var ElementsDelta = class _ElementsDelta {
15391
15493
  changedElements,
15392
15494
  flags
15393
15495
  );
15394
- const tempScene = new Scene(nextElements);
15395
- _ElementsDelta.redrawTextBoundingBoxes(tempScene, changedElements);
15396
- _ElementsDelta.redrawBoundArrows(tempScene, changedElements);
15496
+ _ElementsDelta.redrawElements(nextElements, changedElements);
15397
15497
  } catch (e) {
15398
15498
  console.error(
15399
15499
  `Couldn't mutate elements after applying elements change`,
@@ -15406,7 +15506,72 @@ var ElementsDelta = class _ElementsDelta {
15406
15506
  return [nextElements, flags.containsVisibleDifference];
15407
15507
  }
15408
15508
  }
15409
- static createApplier = (nextElements, snapshot, options, flags) => (deltas) => {
15509
+ squash(delta) {
15510
+ const { added, removed, updated } = delta;
15511
+ function mergeBoundElements(prevDelta, nextDelta) {
15512
+ const mergedDeletedBoundElements = Delta.mergeArrays(
15513
+ prevDelta.deleted.boundElements ?? [],
15514
+ nextDelta.deleted.boundElements ?? [],
15515
+ void 0,
15516
+ (x) => x.id
15517
+ ) ?? [];
15518
+ const mergedInsertedBoundElements = Delta.mergeArrays(
15519
+ prevDelta.inserted.boundElements ?? [],
15520
+ nextDelta.inserted.boundElements ?? [],
15521
+ void 0,
15522
+ (x) => x.id
15523
+ ) ?? [];
15524
+ return Delta.create(
15525
+ {
15526
+ boundElements: mergedDeletedBoundElements
15527
+ },
15528
+ {
15529
+ boundElements: mergedInsertedBoundElements
15530
+ }
15531
+ );
15532
+ }
15533
+ for (const [id, nextDelta] of Object.entries(added)) {
15534
+ const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
15535
+ if (!prevDelta) {
15536
+ this.added[id] = nextDelta;
15537
+ } else {
15538
+ const mergedDelta = mergeBoundElements(prevDelta, nextDelta);
15539
+ this.added[id] = Delta.merge(prevDelta, nextDelta, mergedDelta);
15540
+ }
15541
+ }
15542
+ for (const [id, nextDelta] of Object.entries(removed)) {
15543
+ const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
15544
+ if (!prevDelta) {
15545
+ this.removed[id] = nextDelta;
15546
+ } else {
15547
+ const mergedDelta = mergeBoundElements(prevDelta, nextDelta);
15548
+ this.removed[id] = Delta.merge(prevDelta, nextDelta, mergedDelta);
15549
+ }
15550
+ }
15551
+ for (const [id, nextDelta] of Object.entries(updated)) {
15552
+ const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
15553
+ if (!prevDelta) {
15554
+ this.updated[id] = nextDelta;
15555
+ } else {
15556
+ const mergedDelta = mergeBoundElements(prevDelta, nextDelta);
15557
+ this.updated[id] = Delta.merge(prevDelta, nextDelta, mergedDelta);
15558
+ if (prevDelta === this.added[id]) {
15559
+ this.added[id] = nextDelta;
15560
+ } else if (prevDelta === this.removed[id]) {
15561
+ this.removed[id] = nextDelta;
15562
+ } else {
15563
+ this.updated[id] = nextDelta;
15564
+ }
15565
+ }
15566
+ }
15567
+ if (isTestEnv8() || isDevEnv7()) {
15568
+ _ElementsDelta.validate(this, "added", _ElementsDelta.satisfiesAddition);
15569
+ _ElementsDelta.validate(this, "removed", _ElementsDelta.satisfiesRemoval);
15570
+ _ElementsDelta.validate(this, "updated", _ElementsDelta.satisfiesUpdate);
15571
+ }
15572
+ return this;
15573
+ }
15574
+ static createApplier = (prevElements, nextElements, snapshot, flags, options) => (deltas) => {
15410
15575
  const getElement = _ElementsDelta.createGetter(
15411
15576
  nextElements,
15412
15577
  snapshot,
@@ -15415,14 +15580,20 @@ var ElementsDelta = class _ElementsDelta {
15415
15580
  return Object.entries(deltas).reduce((acc, [id, delta]) => {
15416
15581
  const element = getElement(id, delta.inserted);
15417
15582
  if (element) {
15418
- const newElement2 = _ElementsDelta.applyDelta(
15583
+ const nextElement = _ElementsDelta.applyDelta(
15419
15584
  element,
15420
15585
  delta,
15421
- options,
15422
- flags
15586
+ flags,
15587
+ options
15423
15588
  );
15424
- nextElements.set(newElement2.id, newElement2);
15425
- acc.set(newElement2.id, newElement2);
15589
+ nextElements.set(nextElement.id, nextElement);
15590
+ acc.set(nextElement.id, nextElement);
15591
+ if (!flags.applyDirection) {
15592
+ const prevElement = prevElements.get(id);
15593
+ if (prevElement) {
15594
+ flags.applyDirection = prevElement.version > nextElement.version ? "backward" : "forward";
15595
+ }
15596
+ }
15426
15597
  }
15427
15598
  return acc;
15428
15599
  }, /* @__PURE__ */ new Map());
@@ -15447,13 +15618,13 @@ var ElementsDelta = class _ElementsDelta {
15447
15618
  }
15448
15619
  return element;
15449
15620
  };
15450
- static applyDelta(element, delta, options, flags) {
15621
+ static applyDelta(element, delta, flags, options) {
15451
15622
  const directlyApplicablePartial = {};
15452
15623
  for (const key of Object.keys(delta.inserted)) {
15453
15624
  if (key === "boundElements") {
15454
15625
  continue;
15455
15626
  }
15456
- if (options.excludedProperties.has(key)) {
15627
+ if (options?.excludedProperties?.has(key)) {
15457
15628
  continue;
15458
15629
  }
15459
15630
  const value = delta.inserted[key];
@@ -15481,7 +15652,7 @@ var ElementsDelta = class _ElementsDelta {
15481
15652
  if (!flags.containsZindexDifference) {
15482
15653
  flags.containsZindexDifference = delta.deleted.index !== delta.inserted.index;
15483
15654
  }
15484
- return newElementWith(element, directlyApplicablePartial);
15655
+ return newElementWith(element, directlyApplicablePartial, true);
15485
15656
  }
15486
15657
  /**
15487
15658
  * Check for visible changes regardless of whether they were removed, added or updated.
@@ -15506,25 +15677,32 @@ var ElementsDelta = class _ElementsDelta {
15506
15677
  *
15507
15678
  * @returns all elements affected by the conflict resolution
15508
15679
  */
15509
- resolveConflicts(prevElements, nextElements) {
15680
+ resolveConflicts(prevElements, nextElements, applyDirection = "forward") {
15510
15681
  const nextAffectedElements = /* @__PURE__ */ new Map();
15511
15682
  const updater = (element, updates) => {
15512
15683
  const nextElement = nextElements.get(element.id);
15513
15684
  if (!nextElement) {
15514
15685
  return;
15515
15686
  }
15687
+ const prevElement = prevElements.get(element.id);
15688
+ const nextVersion = applyDirection === "forward" ? nextElement.version + 1 : nextElement.version - 1;
15689
+ const elementUpdates = updates;
15516
15690
  let affectedElement;
15517
- if (prevElements.get(element.id) === nextElement) {
15691
+ if (prevElement === nextElement) {
15518
15692
  affectedElement = newElementWith(
15519
15693
  nextElement,
15520
- updates
15694
+ {
15695
+ ...elementUpdates,
15696
+ version: nextVersion
15697
+ },
15698
+ true
15521
15699
  );
15522
15700
  } else {
15523
- affectedElement = mutateElement(
15524
- nextElement,
15525
- nextElements,
15526
- updates
15527
- );
15701
+ affectedElement = mutateElement(nextElement, nextElements, {
15702
+ ...elementUpdates,
15703
+ // don't modify the version further, if it's already different
15704
+ version: prevElement?.version !== nextElement.version ? nextElement.version : nextVersion
15705
+ });
15528
15706
  }
15529
15707
  nextAffectedElements.set(affectedElement.id, affectedElement);
15530
15708
  nextElements.set(affectedElement.id, affectedElement);
@@ -15549,19 +15727,10 @@ var ElementsDelta = class _ElementsDelta {
15549
15727
  const prevAffectedElements = new Map(
15550
15728
  Array.from(prevElements).filter(([id]) => nextAffectedElements.has(id))
15551
15729
  );
15552
- const { added, removed, updated } = _ElementsDelta.calculate(
15553
- prevAffectedElements,
15554
- nextAffectedElements
15730
+ this.squash(
15731
+ // technically we could do better here if perf. would become an issue
15732
+ _ElementsDelta.calculate(prevAffectedElements, nextAffectedElements)
15555
15733
  );
15556
- for (const [id, delta] of Object.entries(added)) {
15557
- this.added[id] = delta;
15558
- }
15559
- for (const [id, delta] of Object.entries(removed)) {
15560
- this.removed[id] = delta;
15561
- }
15562
- for (const [id, delta] of Object.entries(updated)) {
15563
- this.updated[id] = delta;
15564
- }
15565
15734
  return nextAffectedElements;
15566
15735
  }
15567
15736
  /**
@@ -15596,6 +15765,20 @@ var ElementsDelta = class _ElementsDelta {
15596
15765
  );
15597
15766
  BindableElement.rebindAffected(nextElements, nextElement(), updater);
15598
15767
  }
15768
+ static redrawElements(nextElements, changedElements) {
15769
+ try {
15770
+ const tempScene = new Scene(nextElements, { skipValidation: true });
15771
+ _ElementsDelta.redrawTextBoundingBoxes(tempScene, changedElements);
15772
+ _ElementsDelta.redrawBoundArrows(tempScene, changedElements);
15773
+ } catch (e) {
15774
+ console.error(`Couldn't redraw elements`, e);
15775
+ if (isTestEnv8() || isDevEnv7()) {
15776
+ throw e;
15777
+ }
15778
+ } finally {
15779
+ return nextElements;
15780
+ }
15781
+ }
15599
15782
  static redrawTextBoundingBoxes(scene, changed) {
15600
15783
  const elements = scene.getNonDeletedElementsMap();
15601
15784
  const boxesToRedraw = /* @__PURE__ */ new Map();
@@ -15684,14 +15867,22 @@ var ElementsDelta = class _ElementsDelta {
15684
15867
  const { id, updated, ...strippedPartial } = partial;
15685
15868
  return strippedPartial;
15686
15869
  }
15870
+ static stripVersionProps(partial) {
15871
+ const { version, versionNonce, ...strippedPartial } = partial;
15872
+ return strippedPartial;
15873
+ }
15687
15874
  };
15688
15875
 
15689
15876
  // src/distribute.ts
15690
15877
  init_define_import_meta_env();
15691
- var distributeElements = (selectedElements, elementsMap, distribution) => {
15878
+ var distributeElements = (selectedElements, elementsMap, distribution, appState) => {
15692
15879
  const [start, mid, end, extent] = distribution.axis === "x" ? ["minX", "midX", "maxX", "width"] : ["minY", "midY", "maxY", "height"];
15693
15880
  const bounds = getCommonBoundingBox(selectedElements);
15694
- const groups = getMaximumGroups(selectedElements, elementsMap).map((group) => [group, getCommonBoundingBox(group)]).sort((a2, b2) => a2[1][mid] - b2[1][mid]);
15881
+ const groups = getSelectedElementsByGroup(
15882
+ selectedElements,
15883
+ elementsMap,
15884
+ appState
15885
+ ).map((group) => [group, getCommonBoundingBox(group)]).sort((a2, b2) => a2[1][mid] - b2[1][mid]);
15695
15886
  let span = 0;
15696
15887
  for (const group of groups) {
15697
15888
  span += group[1][extent];
@@ -18403,7 +18594,7 @@ var getTransformHandles = (element, zoom, elementsMap, pointerType = "mouse", om
18403
18594
  );
18404
18595
  };
18405
18596
  var shouldShowBoundingBox = (elements, appState) => {
18406
- if (appState.editingLinearElement) {
18597
+ if (appState.selectedLinearElement?.isEditing) {
18407
18598
  return false;
18408
18599
  }
18409
18600
  if (elements.length > 1) {
@@ -19151,6 +19342,7 @@ export {
19151
19342
  getRootElements,
19152
19343
  getSceneVersion,
19153
19344
  getSelectedElements,
19345
+ getSelectedElementsByGroup,
19154
19346
  getSelectedGroupForElement,
19155
19347
  getSelectedGroupIdForElement,
19156
19348
  getSelectedGroupIds,