@focusbc/bbs-lib 0.0.17 → 0.0.18

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.
@@ -77546,6 +77546,7 @@ var TransformMode = class extends CompositeMode {
77546
77546
  if (pickedEditHandle || pickedTransformGuideBboxOutline || pickedSelectedObject) {
77547
77547
  event.cancelPan();
77548
77548
  }
77549
+ const isRotateHandle = pickedEditHandle?.properties?.editHandleType === "rotate";
77549
77550
  this._modes.forEach((mode) => {
77550
77551
  if (mode instanceof TranslateMode) {
77551
77552
  translateMode = mode;
@@ -77556,7 +77557,7 @@ var TransformMode = class extends CompositeMode {
77556
77557
  filteredModes.push(mode);
77557
77558
  }
77558
77559
  });
77559
- if (translateMode && scaleMode && !scaleMode.isEditHandleSelected()) {
77560
+ if (translateMode && scaleMode && !scaleMode.isEditHandleSelected() && !isRotateHandle) {
77560
77561
  filteredModes.push(translateMode);
77561
77562
  }
77562
77563
  filteredModes.filter(Boolean).forEach((mode) => mode.handleStartDragging(event, props));
@@ -81767,6 +81768,56 @@ var OverlayStaticLayerBuilder = class {
81767
81768
  }
81768
81769
  };
81769
81770
 
81771
+ // src/overlay/shape-history.ts
81772
+ var MAX_HISTORY_DEPTH = 50;
81773
+ var ShapeHistory = class {
81774
+ constructor() {
81775
+ this.stack = [[]];
81776
+ this.index = 0;
81777
+ }
81778
+ reset(shapes) {
81779
+ this.stack = [this.clone(shapes)];
81780
+ this.index = 0;
81781
+ }
81782
+ push(shapes) {
81783
+ if (this.deepEqual(shapes, this.stack[this.index])) {
81784
+ return;
81785
+ }
81786
+ this.stack = this.stack.slice(0, this.index + 1);
81787
+ this.stack.push(this.clone(shapes));
81788
+ if (this.stack.length > MAX_HISTORY_DEPTH) {
81789
+ this.stack.shift();
81790
+ }
81791
+ this.index = this.stack.length - 1;
81792
+ }
81793
+ canUndo() {
81794
+ return this.index > 0;
81795
+ }
81796
+ canRedo() {
81797
+ return this.index < this.stack.length - 1;
81798
+ }
81799
+ undo() {
81800
+ if (!this.canUndo()) {
81801
+ return null;
81802
+ }
81803
+ this.index -= 1;
81804
+ return this.clone(this.stack[this.index]);
81805
+ }
81806
+ redo() {
81807
+ if (!this.canRedo()) {
81808
+ return null;
81809
+ }
81810
+ this.index += 1;
81811
+ return this.clone(this.stack[this.index]);
81812
+ }
81813
+ clone(shapes) {
81814
+ return structuredClone(shapes);
81815
+ }
81816
+ deepEqual(a2, b2) {
81817
+ return JSON.stringify(a2) === JSON.stringify(b2);
81818
+ }
81819
+ };
81820
+
81770
81821
  // src/overlay/map-overlay.ts
81771
81822
  var DEFAULT_ZOOM = 18;
81772
81823
  var MAX_ZOOM = 26;
@@ -81806,12 +81857,14 @@ var MapOverlay = class _MapOverlay {
81806
81857
  this._shapes = [];
81807
81858
  this._selectedShapeIds = [];
81808
81859
  this._editMode = false;
81860
+ this._shapeHistory = new ShapeHistory();
81809
81861
  // Events
81810
81862
  this._initializedEvent = new Event3();
81811
81863
  this._headingChangedEvent = new Event3();
81812
81864
  this._zoomChangedEvent = new Event3();
81813
81865
  this._centerChangedEvent = new Event3();
81814
81866
  this._shapesChangedEvent = new Event3();
81867
+ this._historyChangedEvent = new Event3();
81815
81868
  this._clickEvent = new Event3();
81816
81869
  this._doubleClickEvent = new Event3();
81817
81870
  this._rightClickEvent = new Event3();
@@ -81970,11 +82023,47 @@ var MapOverlay = class _MapOverlay {
81970
82023
  const updated = MapObjectToShapeInstanceMapper.map(original, objects, action.editType);
81971
82024
  this._shapes = this._shapes.map((shape) => shape.id === groupId ? updated : shape);
81972
82025
  }
82026
+ this._shapeHistory.push(this._shapes);
82027
+ this.emitHistoryChanged();
81973
82028
  this._shapesChangedEvent.emit(this._shapes);
81974
82029
  if (["scaling", "stretch", "rotated"].includes(action.editType)) {
81975
82030
  this.rebuildLayers();
81976
82031
  }
81977
82032
  }
82033
+ emitHistoryChanged() {
82034
+ this._historyChangedEvent.emit({
82035
+ canUndo: this._shapeHistory.canUndo(),
82036
+ canRedo: this._shapeHistory.canRedo()
82037
+ });
82038
+ }
82039
+ /**
82040
+ * Validate and apply a shape snapshot, optionally recording it in history.
82041
+ */
82042
+ applyShapes(shapes, options) {
82043
+ const newShapes = [];
82044
+ const validationErrors = [];
82045
+ for (const shape of shapes) {
82046
+ const result = this.validateShape(shape);
82047
+ if (result.ok) {
82048
+ newShapes.push(shape);
82049
+ } else {
82050
+ validationErrors.push(result);
82051
+ }
82052
+ }
82053
+ this._shapes = newShapes;
82054
+ if (this._selectedShapeIds.length > 0) {
82055
+ this._selectedShapeIds = this._selectedShapeIds.filter((id) => this._shapes.some((s2) => s2.id === id));
82056
+ }
82057
+ if (options.recordHistory) {
82058
+ this._shapeHistory.push(this._shapes);
82059
+ }
82060
+ this.emitHistoryChanged();
82061
+ this._shapesChangedEvent.emit(this._shapes);
82062
+ this.rebuildLayers();
82063
+ if (validationErrors.length > 0) {
82064
+ options.onValidationErrors?.(validationErrors);
82065
+ }
82066
+ }
81978
82067
  static convertHeading(heading) {
81979
82068
  heading = heading % 360;
81980
82069
  return (360 - heading) % 360;
@@ -82009,6 +82098,7 @@ var MapOverlay = class _MapOverlay {
82009
82098
  bearing: _MapOverlay.convertHeading(heading)
82010
82099
  };
82011
82100
  this._deck.setProps({ viewState: this._viewState });
82101
+ this.resetShapeHistory();
82012
82102
  this.rebuildLayers();
82013
82103
  }
82014
82104
  setEdit(edit) {
@@ -82079,25 +82169,33 @@ var MapOverlay = class _MapOverlay {
82079
82169
  return this._shapes;
82080
82170
  }
82081
82171
  setShapes(shapes, onValidationErrors) {
82082
- const newShapes = [];
82083
- const validationErrors = [];
82084
- for (const shape of shapes) {
82085
- const result = this.validateShape(shape);
82086
- if (result.ok) {
82087
- newShapes.push(shape);
82088
- } else {
82089
- validationErrors.push(result);
82090
- }
82091
- }
82092
- this._shapes = newShapes;
82093
- if (this._selectedShapeIds.length > 0) {
82094
- this._selectedShapeIds = this._selectedShapeIds.filter((id) => this._shapes.some((s2) => s2.id === id));
82172
+ this.applyShapes(shapes, { recordHistory: true, onValidationErrors });
82173
+ }
82174
+ resetShapeHistory() {
82175
+ this._shapeHistory.reset(this._shapes);
82176
+ this.emitHistoryChanged();
82177
+ }
82178
+ canUndo() {
82179
+ return this._shapeHistory.canUndo();
82180
+ }
82181
+ canRedo() {
82182
+ return this._shapeHistory.canRedo();
82183
+ }
82184
+ undo() {
82185
+ const snapshot = this._shapeHistory.undo();
82186
+ if (!snapshot) {
82187
+ return this._shapes;
82095
82188
  }
82096
- this._shapesChangedEvent.emit(this._shapes);
82097
- this.rebuildLayers();
82098
- if (validationErrors.length > 0) {
82099
- onValidationErrors(validationErrors);
82189
+ this.applyShapes(snapshot, { recordHistory: false });
82190
+ return this._shapes;
82191
+ }
82192
+ redo() {
82193
+ const snapshot = this._shapeHistory.redo();
82194
+ if (!snapshot) {
82195
+ return this._shapes;
82100
82196
  }
82197
+ this.applyShapes(snapshot, { recordHistory: false });
82198
+ return this._shapes;
82101
82199
  }
82102
82200
  getSelectedShapeIds() {
82103
82201
  return this._selectedShapeIds;
@@ -82211,6 +82309,9 @@ var MapOverlay = class _MapOverlay {
82211
82309
  shapesChanged() {
82212
82310
  return this._shapesChangedEvent;
82213
82311
  }
82312
+ historyChanged() {
82313
+ return this._historyChangedEvent;
82314
+ }
82214
82315
  click() {
82215
82316
  return this._clickEvent;
82216
82317
  }