@focusbc/bbs-lib 0.0.17 → 0.0.19
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/browser/bbs-lib.js +128 -18
- package/dist/browser/bbs-lib.js.map +4 -4
- package/dist/overlay/map-overlay.d.ts +16 -1
- package/dist/overlay/map-overlay.d.ts.map +1 -1
- package/dist/overlay/map-overlay.js +78 -18
- package/dist/overlay/map-overlay.js.map +1 -1
- package/dist/overlay/shape-history.d.ts +18 -0
- package/dist/overlay/shape-history.d.ts.map +1 -0
- package/dist/overlay/shape-history.js +53 -0
- package/dist/overlay/shape-history.js.map +1 -0
- package/dist/types/events.d.ts +4 -0
- package/dist/types/events.d.ts.map +1 -1
- package/package.json +2 -2
- package/readme.md +16 -0
package/dist/browser/bbs-lib.js
CHANGED
|
@@ -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) {
|
|
@@ -82075,29 +82165,46 @@ var MapOverlay = class _MapOverlay {
|
|
|
82075
82165
|
this.applyViewState({ ...this._viewState, bearing: _MapOverlay.convertHeading(heading) });
|
|
82076
82166
|
this._headingChangedEvent.emit(heading);
|
|
82077
82167
|
}
|
|
82168
|
+
// Registers a Deck onAfterRender handler, or clears it when undefined.
|
|
82169
|
+
setAfterRenderCallback(handler) {
|
|
82170
|
+
this._deck.setProps(handler ? { onAfterRender: () => handler() } : { onAfterRender: void 0 });
|
|
82171
|
+
}
|
|
82172
|
+
// Forces Deck to redraw; use after attaching an after-render callback so the quiet-period wait can start.
|
|
82173
|
+
forceRedraw(clearRedrawFlags = true) {
|
|
82174
|
+
;
|
|
82175
|
+
this._deck.redraw?.(clearRedrawFlags);
|
|
82176
|
+
}
|
|
82078
82177
|
getShapes() {
|
|
82079
82178
|
return this._shapes;
|
|
82080
82179
|
}
|
|
82081
82180
|
setShapes(shapes, onValidationErrors) {
|
|
82082
|
-
|
|
82083
|
-
|
|
82084
|
-
|
|
82085
|
-
|
|
82086
|
-
|
|
82087
|
-
|
|
82088
|
-
|
|
82089
|
-
|
|
82090
|
-
|
|
82091
|
-
|
|
82092
|
-
this.
|
|
82093
|
-
|
|
82094
|
-
|
|
82181
|
+
this.applyShapes(shapes, { recordHistory: true, onValidationErrors });
|
|
82182
|
+
}
|
|
82183
|
+
resetShapeHistory() {
|
|
82184
|
+
this._shapeHistory.reset(this._shapes);
|
|
82185
|
+
this.emitHistoryChanged();
|
|
82186
|
+
}
|
|
82187
|
+
canUndo() {
|
|
82188
|
+
return this._shapeHistory.canUndo();
|
|
82189
|
+
}
|
|
82190
|
+
canRedo() {
|
|
82191
|
+
return this._shapeHistory.canRedo();
|
|
82192
|
+
}
|
|
82193
|
+
undo() {
|
|
82194
|
+
const snapshot = this._shapeHistory.undo();
|
|
82195
|
+
if (!snapshot) {
|
|
82196
|
+
return this._shapes;
|
|
82095
82197
|
}
|
|
82096
|
-
this.
|
|
82097
|
-
this.
|
|
82098
|
-
|
|
82099
|
-
|
|
82198
|
+
this.applyShapes(snapshot, { recordHistory: false });
|
|
82199
|
+
return this._shapes;
|
|
82200
|
+
}
|
|
82201
|
+
redo() {
|
|
82202
|
+
const snapshot = this._shapeHistory.redo();
|
|
82203
|
+
if (!snapshot) {
|
|
82204
|
+
return this._shapes;
|
|
82100
82205
|
}
|
|
82206
|
+
this.applyShapes(snapshot, { recordHistory: false });
|
|
82207
|
+
return this._shapes;
|
|
82101
82208
|
}
|
|
82102
82209
|
getSelectedShapeIds() {
|
|
82103
82210
|
return this._selectedShapeIds;
|
|
@@ -82211,6 +82318,9 @@ var MapOverlay = class _MapOverlay {
|
|
|
82211
82318
|
shapesChanged() {
|
|
82212
82319
|
return this._shapesChangedEvent;
|
|
82213
82320
|
}
|
|
82321
|
+
historyChanged() {
|
|
82322
|
+
return this._historyChangedEvent;
|
|
82323
|
+
}
|
|
82214
82324
|
click() {
|
|
82215
82325
|
return this._clickEvent;
|
|
82216
82326
|
}
|