@excalidraw/element 0.18.0-dda3affcb → 0.18.0-dda3affcb-8fc71066d

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.
package/dist/dev/index.js CHANGED
@@ -13533,10 +13533,12 @@ var StoreDelta = class {
13533
13533
  */
13534
13534
  static load({
13535
13535
  id,
13536
- elements: { added, removed, updated }
13536
+ elements: { added, removed, updated },
13537
+ appState: { delta: appStateDelta }
13537
13538
  }) {
13538
13539
  const elements = ElementsDelta.create(added, removed, updated);
13539
- return new this(id, elements, AppStateDelta.empty());
13540
+ const appState = AppStateDelta.create(appStateDelta);
13541
+ return new this(id, elements, appState);
13540
13542
  }
13541
13543
  /**
13542
13544
  * Inverse store delta, creates new instance of `StoreDelta`.
@@ -13547,9 +13549,7 @@ var StoreDelta = class {
13547
13549
  /**
13548
13550
  * Apply the delta to the passed elements and appState, does not modify the snapshot.
13549
13551
  */
13550
- static applyTo(delta, elements, appState, options = {
13551
- excludedProperties: /* @__PURE__ */ new Set()
13552
- }) {
13552
+ static applyTo(delta, elements, appState, options) {
13553
13553
  const [nextElements, elementsContainVisibleChange] = delta.elements.applyTo(
13554
13554
  elements,
13555
13555
  StoreSnapshot.empty().elements,
@@ -14398,9 +14398,9 @@ var Scene = class {
14398
14398
  getFramesIncludingDeleted() {
14399
14399
  return this.frames;
14400
14400
  }
14401
- constructor(elements = null) {
14401
+ constructor(elements = null, options) {
14402
14402
  if (elements) {
14403
- this.replaceAllElements(elements);
14403
+ this.replaceAllElements(elements, options);
14404
14404
  }
14405
14405
  }
14406
14406
  getSelectedElements(opts) {
@@ -14465,10 +14465,12 @@ var Scene = class {
14465
14465
  }
14466
14466
  return didChange;
14467
14467
  }
14468
- replaceAllElements(nextElements) {
14468
+ replaceAllElements(nextElements, options) {
14469
14469
  const _nextElements = toArray(nextElements);
14470
14470
  const nextFrameLikes = [];
14471
- validateIndicesThrottled(_nextElements);
14471
+ if (!options?.skipValidation) {
14472
+ validateIndicesThrottled(_nextElements);
14473
+ }
14472
14474
  this.elements = syncInvalidIndices2(_nextElements);
14473
14475
  this.elementsMap.clear();
14474
14476
  this.elements.forEach((element) => {
@@ -14871,6 +14873,9 @@ var AppStateDelta = class _AppStateDelta {
14871
14873
  constructor(delta) {
14872
14874
  this.delta = delta;
14873
14875
  }
14876
+ static create(delta) {
14877
+ return new _AppStateDelta(delta);
14878
+ }
14874
14879
  static calculate(prevAppState, nextAppState) {
14875
14880
  const delta = Delta.calculate(
14876
14881
  prevAppState,
@@ -15407,9 +15412,7 @@ var ElementsDelta = class _ElementsDelta {
15407
15412
  // redistribute the deltas as `isDeleted` could have been updated
15408
15413
  });
15409
15414
  }
15410
- applyTo(elements, snapshot = StoreSnapshot.empty().elements, options = {
15411
- excludedProperties: /* @__PURE__ */ new Set()
15412
- }) {
15415
+ applyTo(elements, snapshot = StoreSnapshot.empty().elements, options) {
15413
15416
  let nextElements = new Map(elements);
15414
15417
  let changedElements;
15415
15418
  const flags = {
@@ -15420,8 +15423,8 @@ var ElementsDelta = class _ElementsDelta {
15420
15423
  const applyDeltas = _ElementsDelta.createApplier(
15421
15424
  nextElements,
15422
15425
  snapshot,
15423
- options,
15424
- flags
15426
+ flags,
15427
+ options
15425
15428
  );
15426
15429
  const addedElements = applyDeltas(this.added);
15427
15430
  const removedElements = applyDeltas(this.removed);
@@ -15446,9 +15449,9 @@ var ElementsDelta = class _ElementsDelta {
15446
15449
  changedElements,
15447
15450
  flags
15448
15451
  );
15449
- const tempScene = new Scene(nextElements);
15450
- _ElementsDelta.redrawTextBoundingBoxes(tempScene, changedElements);
15451
- _ElementsDelta.redrawBoundArrows(tempScene, changedElements);
15452
+ if (!options?.skipRedraw) {
15453
+ _ElementsDelta.redrawElements(nextElements, changedElements);
15454
+ }
15452
15455
  } catch (e) {
15453
15456
  console.error(
15454
15457
  `Couldn't mutate elements after applying elements change`,
@@ -15489,7 +15492,7 @@ var ElementsDelta = class _ElementsDelta {
15489
15492
  }
15490
15493
  return this;
15491
15494
  }
15492
- static createApplier = (nextElements, snapshot, options, flags) => (deltas) => {
15495
+ static createApplier = (nextElements, snapshot, flags, options) => (deltas) => {
15493
15496
  const getElement = _ElementsDelta.createGetter(
15494
15497
  nextElements,
15495
15498
  snapshot,
@@ -15501,8 +15504,8 @@ var ElementsDelta = class _ElementsDelta {
15501
15504
  const newElement2 = _ElementsDelta.applyDelta(
15502
15505
  element,
15503
15506
  delta,
15504
- options,
15505
- flags
15507
+ flags,
15508
+ options
15506
15509
  );
15507
15510
  nextElements.set(newElement2.id, newElement2);
15508
15511
  acc.set(newElement2.id, newElement2);
@@ -15530,13 +15533,13 @@ var ElementsDelta = class _ElementsDelta {
15530
15533
  }
15531
15534
  return element;
15532
15535
  };
15533
- static applyDelta(element, delta, options, flags) {
15536
+ static applyDelta(element, delta, flags, options) {
15534
15537
  const directlyApplicablePartial = {};
15535
15538
  for (const key of Object.keys(delta.inserted)) {
15536
15539
  if (key === "boundElements") {
15537
15540
  continue;
15538
15541
  }
15539
- if (options.excludedProperties.has(key)) {
15542
+ if (options?.excludedProperties?.has(key)) {
15540
15543
  continue;
15541
15544
  }
15542
15545
  const value = delta.inserted[key];
@@ -15596,8 +15599,9 @@ var ElementsDelta = class _ElementsDelta {
15596
15599
  if (!nextElement) {
15597
15600
  return;
15598
15601
  }
15602
+ const prevElement = prevElements.get(element.id);
15599
15603
  let affectedElement;
15600
- if (prevElements.get(element.id) === nextElement) {
15604
+ if (prevElement === nextElement) {
15601
15605
  affectedElement = newElementWith(
15602
15606
  nextElement,
15603
15607
  updates
@@ -15670,6 +15674,20 @@ var ElementsDelta = class _ElementsDelta {
15670
15674
  );
15671
15675
  BindableElement.rebindAffected(nextElements, nextElement(), updater);
15672
15676
  }
15677
+ static redrawElements(nextElements, changedElements) {
15678
+ try {
15679
+ const tempScene = new Scene(nextElements, { skipValidation: true });
15680
+ _ElementsDelta.redrawTextBoundingBoxes(tempScene, changedElements);
15681
+ _ElementsDelta.redrawBoundArrows(tempScene, changedElements);
15682
+ } catch (e) {
15683
+ console.error(`Couldn't redraw elements`, e);
15684
+ if (isTestEnv8() || isDevEnv7()) {
15685
+ throw e;
15686
+ }
15687
+ } finally {
15688
+ return nextElements;
15689
+ }
15690
+ }
15673
15691
  static redrawTextBoundingBoxes(scene, changed) {
15674
15692
  const elements = scene.getNonDeletedElementsMap();
15675
15693
  const boxesToRedraw = /* @__PURE__ */ new Map();