@fieldnotes/core 0.17.0 → 0.18.0
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/LICENSE +21 -0
- package/README.md +442 -436
- package/dist/index.cjs +30 -4
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +30 -4
- package/dist/index.js.map +1 -0
- package/package.json +4 -2
package/dist/index.d.cts
CHANGED
|
@@ -411,12 +411,14 @@ declare class HistoryRecorder {
|
|
|
411
411
|
private readonly layerManager?;
|
|
412
412
|
private recording;
|
|
413
413
|
private transaction;
|
|
414
|
+
private generation;
|
|
414
415
|
private updateSnapshots;
|
|
415
416
|
private unsubscribers;
|
|
416
417
|
constructor(store: ElementStore, stack: HistoryStack, layerManager?: LayerManager | undefined);
|
|
417
418
|
pause(): void;
|
|
418
419
|
resume(): void;
|
|
419
420
|
begin(): void;
|
|
421
|
+
get currentTransactionId(): number | null;
|
|
420
422
|
commit(): void;
|
|
421
423
|
rollback(): void;
|
|
422
424
|
destroy(): void;
|
|
@@ -614,6 +616,7 @@ declare class Viewport {
|
|
|
614
616
|
exportImage(options?: ExportImageOptions): Promise<Blob | null>;
|
|
615
617
|
loadState(state: CanvasState): void;
|
|
616
618
|
loadJSON(json: string): void;
|
|
619
|
+
setTool(name: string): void;
|
|
617
620
|
undo(): boolean;
|
|
618
621
|
redo(): boolean;
|
|
619
622
|
addImage(src: string, position: {
|
|
@@ -1209,6 +1212,6 @@ declare class UpdateLayerCommand implements Command {
|
|
|
1209
1212
|
undo(_store: ElementStore): void;
|
|
1210
1213
|
}
|
|
1211
1214
|
|
|
1212
|
-
declare const VERSION = "0.
|
|
1215
|
+
declare const VERSION = "0.18.0";
|
|
1213
1216
|
|
|
1214
|
-
export { type ActiveFormats, AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, CreateLayerCommand, DEFAULT_FONT_SIZE_PRESETS, DEFAULT_NOTE_FONT_SIZE, DoubleTapDetector, type DoubleTapDetectorOptions, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, type ExportImageOptions, type FilterAction, type FilteredEvent, type FilteredUpEvent, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputFilter, InputHandler, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, NoteEditor, type NoteEditorOptions, type NoteElement, NoteTool, type NoteToolOptions, NoteToolbar, PencilTool, type PencilToolOptions, type Point, type PointerState, Quadtree, RemoveElementCommand, RemoveLayerCommand, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type StyledRun, type TemplateElement, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, boundsIntersect, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportState, findBindTarget, findBoundArrows, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isBindable, isNearBezier, parseState, sanitizeNoteHtml, setFontSize, smartSnap, snapPoint, snapToHexCenter, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline, unbindArrow, updateBoundArrow };
|
|
1217
|
+
export { type ActiveFormats, AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, CreateLayerCommand, DEFAULT_FONT_SIZE_PRESETS, DEFAULT_NOTE_FONT_SIZE, DoubleTapDetector, type DoubleTapDetectorOptions, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, type ExportImageOptions, type FilterAction, type FilteredEvent, type FilteredUpEvent, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputFilter, InputHandler, type InputHandlerOptions, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, NoteEditor, type NoteEditorOptions, type NoteElement, NoteTool, type NoteToolOptions, NoteToolbar, PencilTool, type PencilToolOptions, type Point, type PointerState, Quadtree, RemoveElementCommand, RemoveLayerCommand, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type StyledRun, type TemplateElement, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, boundsIntersect, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportState, findBindTarget, findBoundArrows, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isBindable, isNearBezier, parseState, sanitizeNoteHtml, setFontSize, smartSnap, snapPoint, snapToHexCenter, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline, unbindArrow, updateBoundArrow };
|
package/dist/index.d.ts
CHANGED
|
@@ -411,12 +411,14 @@ declare class HistoryRecorder {
|
|
|
411
411
|
private readonly layerManager?;
|
|
412
412
|
private recording;
|
|
413
413
|
private transaction;
|
|
414
|
+
private generation;
|
|
414
415
|
private updateSnapshots;
|
|
415
416
|
private unsubscribers;
|
|
416
417
|
constructor(store: ElementStore, stack: HistoryStack, layerManager?: LayerManager | undefined);
|
|
417
418
|
pause(): void;
|
|
418
419
|
resume(): void;
|
|
419
420
|
begin(): void;
|
|
421
|
+
get currentTransactionId(): number | null;
|
|
420
422
|
commit(): void;
|
|
421
423
|
rollback(): void;
|
|
422
424
|
destroy(): void;
|
|
@@ -614,6 +616,7 @@ declare class Viewport {
|
|
|
614
616
|
exportImage(options?: ExportImageOptions): Promise<Blob | null>;
|
|
615
617
|
loadState(state: CanvasState): void;
|
|
616
618
|
loadJSON(json: string): void;
|
|
619
|
+
setTool(name: string): void;
|
|
617
620
|
undo(): boolean;
|
|
618
621
|
redo(): boolean;
|
|
619
622
|
addImage(src: string, position: {
|
|
@@ -1209,6 +1212,6 @@ declare class UpdateLayerCommand implements Command {
|
|
|
1209
1212
|
undo(_store: ElementStore): void;
|
|
1210
1213
|
}
|
|
1211
1214
|
|
|
1212
|
-
declare const VERSION = "0.
|
|
1215
|
+
declare const VERSION = "0.18.0";
|
|
1213
1216
|
|
|
1214
|
-
export { type ActiveFormats, AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, CreateLayerCommand, DEFAULT_FONT_SIZE_PRESETS, DEFAULT_NOTE_FONT_SIZE, DoubleTapDetector, type DoubleTapDetectorOptions, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, type ExportImageOptions, type FilterAction, type FilteredEvent, type FilteredUpEvent, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputFilter, InputHandler, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, NoteEditor, type NoteEditorOptions, type NoteElement, NoteTool, type NoteToolOptions, NoteToolbar, PencilTool, type PencilToolOptions, type Point, type PointerState, Quadtree, RemoveElementCommand, RemoveLayerCommand, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type StyledRun, type TemplateElement, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, boundsIntersect, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportState, findBindTarget, findBoundArrows, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isBindable, isNearBezier, parseState, sanitizeNoteHtml, setFontSize, smartSnap, snapPoint, snapToHexCenter, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline, unbindArrow, updateBoundArrow };
|
|
1217
|
+
export { type ActiveFormats, AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, CreateLayerCommand, DEFAULT_FONT_SIZE_PRESETS, DEFAULT_NOTE_FONT_SIZE, DoubleTapDetector, type DoubleTapDetectorOptions, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, type ExportImageOptions, type FilterAction, type FilteredEvent, type FilteredUpEvent, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputFilter, InputHandler, type InputHandlerOptions, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, NoteEditor, type NoteEditorOptions, type NoteElement, NoteTool, type NoteToolOptions, NoteToolbar, PencilTool, type PencilToolOptions, type Point, type PointerState, Quadtree, RemoveElementCommand, RemoveLayerCommand, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type StyledRun, type TemplateElement, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, boundsIntersect, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportState, findBindTarget, findBoundArrows, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isBindable, isNearBezier, parseState, sanitizeNoteHtml, setFontSize, smartSnap, snapPoint, snapToHexCenter, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline, unbindArrow, updateBoundArrow };
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,13 @@ var EventBus = class {
|
|
|
15
15
|
this.listeners.get(event)?.delete(listener);
|
|
16
16
|
}
|
|
17
17
|
emit(event, data) {
|
|
18
|
-
this.listeners.get(event)?.forEach((listener) =>
|
|
18
|
+
this.listeners.get(event)?.forEach((listener) => {
|
|
19
|
+
try {
|
|
20
|
+
listener(data);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.error(`[fieldnotes] listener error for "${String(event)}"`, err);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
19
25
|
}
|
|
20
26
|
clear() {
|
|
21
27
|
this.listeners.clear();
|
|
@@ -819,6 +825,7 @@ var KeyboardActions = class {
|
|
|
819
825
|
clipboard = [];
|
|
820
826
|
pasteCount = 0;
|
|
821
827
|
nudgeTimer = null;
|
|
828
|
+
nudgeTxId = null;
|
|
822
829
|
dispose() {
|
|
823
830
|
this.flushPendingNudge();
|
|
824
831
|
}
|
|
@@ -837,7 +844,9 @@ var KeyboardActions = class {
|
|
|
837
844
|
if (sel.tool.selectedIds.length === 0) return false;
|
|
838
845
|
const step = byCell ? sel.ctx.gridSize ?? 10 : 1;
|
|
839
846
|
if (this.nudgeTimer === null) {
|
|
840
|
-
this.deps.getHistoryRecorder()
|
|
847
|
+
const recorder = this.deps.getHistoryRecorder();
|
|
848
|
+
recorder?.begin();
|
|
849
|
+
this.nudgeTxId = recorder?.currentTransactionId ?? null;
|
|
841
850
|
} else {
|
|
842
851
|
clearTimeout(this.nudgeTimer);
|
|
843
852
|
}
|
|
@@ -849,9 +858,14 @@ var KeyboardActions = class {
|
|
|
849
858
|
if (this.nudgeTimer === null) return;
|
|
850
859
|
clearTimeout(this.nudgeTimer);
|
|
851
860
|
this.nudgeTimer = null;
|
|
852
|
-
this.deps.getHistoryRecorder()
|
|
861
|
+
const recorder = this.deps.getHistoryRecorder();
|
|
862
|
+
if (this.nudgeTxId === null || recorder?.currentTransactionId === this.nudgeTxId) {
|
|
863
|
+
recorder?.commit();
|
|
864
|
+
}
|
|
865
|
+
this.nudgeTxId = null;
|
|
853
866
|
}
|
|
854
867
|
deleteSelected() {
|
|
868
|
+
if (this.deps.isToolActive()) return;
|
|
855
869
|
this.flushPendingNudge();
|
|
856
870
|
const sel = this.selectTool();
|
|
857
871
|
if (!sel) return;
|
|
@@ -866,6 +880,7 @@ var KeyboardActions = class {
|
|
|
866
880
|
sel.ctx.requestRender();
|
|
867
881
|
}
|
|
868
882
|
undo() {
|
|
883
|
+
if (this.deps.isToolActive()) return;
|
|
869
884
|
this.flushPendingNudge();
|
|
870
885
|
const ctx = this.deps.getToolContext();
|
|
871
886
|
const stack = this.deps.getHistoryStack();
|
|
@@ -877,6 +892,7 @@ var KeyboardActions = class {
|
|
|
877
892
|
ctx.requestRender();
|
|
878
893
|
}
|
|
879
894
|
redo() {
|
|
895
|
+
if (this.deps.isToolActive()) return;
|
|
880
896
|
this.flushPendingNudge();
|
|
881
897
|
const ctx = this.deps.getToolContext();
|
|
882
898
|
const stack = this.deps.getHistoryStack();
|
|
@@ -950,6 +966,7 @@ var KeyboardActions = class {
|
|
|
950
966
|
this.deps.fitToContent?.();
|
|
951
967
|
}
|
|
952
968
|
zOrder(operation) {
|
|
969
|
+
if (this.deps.isToolActive()) return;
|
|
953
970
|
this.flushPendingNudge();
|
|
954
971
|
const sel = this.selectTool();
|
|
955
972
|
if (!sel) return;
|
|
@@ -3509,6 +3526,7 @@ var HistoryRecorder = class {
|
|
|
3509
3526
|
}
|
|
3510
3527
|
recording = true;
|
|
3511
3528
|
transaction = null;
|
|
3529
|
+
generation = 0;
|
|
3512
3530
|
updateSnapshots = /* @__PURE__ */ new Map();
|
|
3513
3531
|
unsubscribers;
|
|
3514
3532
|
pause() {
|
|
@@ -3523,6 +3541,10 @@ var HistoryRecorder = class {
|
|
|
3523
3541
|
}
|
|
3524
3542
|
this.transaction = [];
|
|
3525
3543
|
this.updateSnapshots.clear();
|
|
3544
|
+
this.generation += 1;
|
|
3545
|
+
}
|
|
3546
|
+
get currentTransactionId() {
|
|
3547
|
+
return this.transaction !== null ? this.generation : null;
|
|
3526
3548
|
}
|
|
3527
3549
|
commit() {
|
|
3528
3550
|
if (!this.transaction) return;
|
|
@@ -4881,6 +4903,9 @@ var Viewport = class {
|
|
|
4881
4903
|
loadJSON(json) {
|
|
4882
4904
|
this.loadState(parseState(json));
|
|
4883
4905
|
}
|
|
4906
|
+
setTool(name) {
|
|
4907
|
+
this.toolManager.setTool(name, this.toolContext);
|
|
4908
|
+
}
|
|
4884
4909
|
undo() {
|
|
4885
4910
|
this.inputHandler.flushPendingHistory();
|
|
4886
4911
|
this.historyRecorder.pause();
|
|
@@ -6919,7 +6944,7 @@ var TemplateTool = class {
|
|
|
6919
6944
|
};
|
|
6920
6945
|
|
|
6921
6946
|
// src/index.ts
|
|
6922
|
-
var VERSION = "0.
|
|
6947
|
+
var VERSION = "0.18.0";
|
|
6923
6948
|
export {
|
|
6924
6949
|
AddElementCommand,
|
|
6925
6950
|
ArrowTool,
|
|
@@ -7006,3 +7031,4 @@ export {
|
|
|
7006
7031
|
unbindArrow,
|
|
7007
7032
|
updateBoundArrow
|
|
7008
7033
|
};
|
|
7034
|
+
//# sourceMappingURL=index.js.map
|