@focusbc/bbs-lib 0.0.16 → 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));
@@ -81377,6 +81378,7 @@ var OverlayDynamicLayerBuilder = class {
81377
81378
  labelObjects,
81378
81379
  mode: this._edit ? ModeType.TRANSFORM : ModeType.VIEW,
81379
81380
  pickable: true,
81381
+ pickingRadius: 5,
81380
81382
  modeConfig: {
81381
81383
  onSelect: (result) => {
81382
81384
  this._onSelect(result);
@@ -81766,6 +81768,56 @@ var OverlayStaticLayerBuilder = class {
81766
81768
  }
81767
81769
  };
81768
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
+
81769
81821
  // src/overlay/map-overlay.ts
81770
81822
  var DEFAULT_ZOOM = 18;
81771
81823
  var MAX_ZOOM = 26;
@@ -81805,12 +81857,14 @@ var MapOverlay = class _MapOverlay {
81805
81857
  this._shapes = [];
81806
81858
  this._selectedShapeIds = [];
81807
81859
  this._editMode = false;
81860
+ this._shapeHistory = new ShapeHistory();
81808
81861
  // Events
81809
81862
  this._initializedEvent = new Event3();
81810
81863
  this._headingChangedEvent = new Event3();
81811
81864
  this._zoomChangedEvent = new Event3();
81812
81865
  this._centerChangedEvent = new Event3();
81813
81866
  this._shapesChangedEvent = new Event3();
81867
+ this._historyChangedEvent = new Event3();
81814
81868
  this._clickEvent = new Event3();
81815
81869
  this._doubleClickEvent = new Event3();
81816
81870
  this._rightClickEvent = new Event3();
@@ -81969,11 +82023,47 @@ var MapOverlay = class _MapOverlay {
81969
82023
  const updated = MapObjectToShapeInstanceMapper.map(original, objects, action.editType);
81970
82024
  this._shapes = this._shapes.map((shape) => shape.id === groupId ? updated : shape);
81971
82025
  }
82026
+ this._shapeHistory.push(this._shapes);
82027
+ this.emitHistoryChanged();
81972
82028
  this._shapesChangedEvent.emit(this._shapes);
81973
82029
  if (["scaling", "stretch", "rotated"].includes(action.editType)) {
81974
82030
  this.rebuildLayers();
81975
82031
  }
81976
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
+ }
81977
82067
  static convertHeading(heading) {
81978
82068
  heading = heading % 360;
81979
82069
  return (360 - heading) % 360;
@@ -82008,6 +82098,7 @@ var MapOverlay = class _MapOverlay {
82008
82098
  bearing: _MapOverlay.convertHeading(heading)
82009
82099
  };
82010
82100
  this._deck.setProps({ viewState: this._viewState });
82101
+ this.resetShapeHistory();
82011
82102
  this.rebuildLayers();
82012
82103
  }
82013
82104
  setEdit(edit) {
@@ -82078,25 +82169,33 @@ var MapOverlay = class _MapOverlay {
82078
82169
  return this._shapes;
82079
82170
  }
82080
82171
  setShapes(shapes, onValidationErrors) {
82081
- const newShapes = [];
82082
- const validationErrors = [];
82083
- for (const shape of shapes) {
82084
- const result = this.validateShape(shape);
82085
- if (result.ok) {
82086
- newShapes.push(shape);
82087
- } else {
82088
- validationErrors.push(result);
82089
- }
82090
- }
82091
- this._shapes = newShapes;
82092
- if (this._selectedShapeIds.length > 0) {
82093
- 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;
82094
82188
  }
82095
- this._shapesChangedEvent.emit(this._shapes);
82096
- this.rebuildLayers();
82097
- if (validationErrors.length > 0) {
82098
- 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;
82099
82196
  }
82197
+ this.applyShapes(snapshot, { recordHistory: false });
82198
+ return this._shapes;
82100
82199
  }
82101
82200
  getSelectedShapeIds() {
82102
82201
  return this._selectedShapeIds;
@@ -82210,6 +82309,9 @@ var MapOverlay = class _MapOverlay {
82210
82309
  shapesChanged() {
82211
82310
  return this._shapesChangedEvent;
82212
82311
  }
82312
+ historyChanged() {
82313
+ return this._historyChangedEvent;
82314
+ }
82213
82315
  click() {
82214
82316
  return this._clickEvent;
82215
82317
  }