@fieldnotes/core 0.18.0 → 0.20.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/dist/index.d.cts CHANGED
@@ -432,12 +432,25 @@ declare class HistoryRecorder {
432
432
  private flushUpdateSnapshots;
433
433
  }
434
434
 
435
+ type ShortcutBindings = Record<string, string | string[] | null>;
436
+ interface ShortcutOptions {
437
+ scope?: 'focus' | 'window';
438
+ bindings?: ShortcutBindings;
439
+ }
440
+ interface ShortcutsApi {
441
+ rebind(action: string, bindings: string | string[] | null): void;
442
+ disable(action: string): void;
443
+ reset(action?: string): void;
444
+ getBindings(): Record<string, string[]>;
445
+ }
446
+
435
447
  interface InputHandlerOptions {
436
448
  toolManager?: ToolManager;
437
449
  toolContext?: ToolContext;
438
450
  historyRecorder?: HistoryRecorder;
439
451
  historyStack?: HistoryStack;
440
452
  fitToContent?: () => void;
453
+ shortcuts?: ShortcutOptions;
441
454
  }
442
455
  declare class InputHandler {
443
456
  private readonly element;
@@ -458,9 +471,12 @@ declare class InputHandler {
458
471
  private deferredDown;
459
472
  private readonly abortController;
460
473
  private readonly actions;
474
+ private readonly shortcutMap;
475
+ private readonly scope;
461
476
  constructor(element: HTMLElement, camera: Camera, options?: InputHandlerOptions);
462
477
  setToolManager(toolManager: ToolManager, toolContext: ToolContext): void;
463
478
  flushPendingHistory(): void;
479
+ get shortcuts(): ShortcutsApi;
464
480
  destroy(): void;
465
481
  private bind;
466
482
  private onWheel;
@@ -469,6 +485,7 @@ declare class InputHandler {
469
485
  private onPointerUp;
470
486
  private onKeyDown;
471
487
  private onKeyUp;
488
+ private runAction;
472
489
  private startPinch;
473
490
  private handlePinchMove;
474
491
  private getPinchPoints;
@@ -479,6 +496,8 @@ declare class InputHandler {
479
496
  private dispatchToolMove;
480
497
  private dispatchToolHover;
481
498
  private dispatchToolUp;
499
+ private isInScope;
500
+ private focusSelf;
482
501
  private cancelToolIfActive;
483
502
  }
484
503
 
@@ -569,6 +588,8 @@ interface ViewportOptions {
569
588
  background?: BackgroundOptions;
570
589
  fontSizePresets?: FontSizePreset[];
571
590
  toolbar?: boolean;
591
+ placeholder?: string;
592
+ shortcuts?: ShortcutOptions;
572
593
  onHtmlElementMount?: (elementId: string, domId: string | undefined, container: HTMLDivElement) => void;
573
594
  onDrop?: (event: DragEvent, worldPosition: {
574
595
  x: number;
@@ -617,6 +638,7 @@ declare class Viewport {
617
638
  loadState(state: CanvasState): void;
618
639
  loadJSON(json: string): void;
619
640
  setTool(name: string): void;
641
+ get shortcuts(): ShortcutsApi;
620
642
  undo(): boolean;
621
643
  redo(): boolean;
622
644
  addImage(src: string, position: {
@@ -703,6 +725,7 @@ declare class ElementRenderer {
703
725
  interface NoteEditorOptions {
704
726
  fontSizePresets?: FontSizePreset[];
705
727
  toolbar?: boolean;
728
+ placeholder?: string;
706
729
  }
707
730
  declare class NoteEditor {
708
731
  private editingId;
@@ -710,9 +733,11 @@ declare class NoteEditor {
710
733
  private blurHandler;
711
734
  private keyHandler;
712
735
  private pointerHandler;
736
+ private inputHandler;
713
737
  private pendingEditId;
714
738
  private onStopCallback;
715
739
  private toolbar;
740
+ private readonly placeholder;
716
741
  constructor(options?: NoteEditorOptions);
717
742
  get isEditing(): boolean;
718
743
  get editingElementId(): string | null;
@@ -735,6 +760,7 @@ interface StyledRun extends RunStyle {
735
760
  text: string;
736
761
  }
737
762
  declare function sanitizeNoteHtml(html: string): string;
763
+ declare function isNoteContentEmpty(html: string): boolean;
738
764
 
739
765
  interface ActiveFormats {
740
766
  bold: boolean;
@@ -964,6 +990,7 @@ declare class SelectTool implements Tool {
964
990
  private pendingSingleSelectId;
965
991
  private hasDragged;
966
992
  private resizeAspectRatio;
993
+ private hoveredId;
967
994
  get selectedIds(): string[];
968
995
  setSelection(ids: string[]): void;
969
996
  get isMarqueeActive(): boolean;
@@ -978,6 +1005,7 @@ declare class SelectTool implements Tool {
978
1005
  private updateArrowsBoundTo;
979
1006
  nudgeSelection(dx: number, dy: number, ctx: ToolContext): boolean;
980
1007
  private updateHoverCursor;
1008
+ private setHovered;
981
1009
  private handleResize;
982
1010
  private hitTestResizeHandle;
983
1011
  private getHandlePositions;
@@ -1212,6 +1240,6 @@ declare class UpdateLayerCommand implements Command {
1212
1240
  undo(_store: ElementStore): void;
1213
1241
  }
1214
1242
 
1215
- declare const VERSION = "0.18.0";
1243
+ declare const VERSION = "0.20.0";
1216
1244
 
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 };
1245
+ 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 ShortcutBindings, type ShortcutOptions, type ShortcutsApi, 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, isNoteContentEmpty, parseState, sanitizeNoteHtml, setFontSize, smartSnap, snapPoint, snapToHexCenter, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline, unbindArrow, updateBoundArrow };
package/dist/index.d.ts CHANGED
@@ -432,12 +432,25 @@ declare class HistoryRecorder {
432
432
  private flushUpdateSnapshots;
433
433
  }
434
434
 
435
+ type ShortcutBindings = Record<string, string | string[] | null>;
436
+ interface ShortcutOptions {
437
+ scope?: 'focus' | 'window';
438
+ bindings?: ShortcutBindings;
439
+ }
440
+ interface ShortcutsApi {
441
+ rebind(action: string, bindings: string | string[] | null): void;
442
+ disable(action: string): void;
443
+ reset(action?: string): void;
444
+ getBindings(): Record<string, string[]>;
445
+ }
446
+
435
447
  interface InputHandlerOptions {
436
448
  toolManager?: ToolManager;
437
449
  toolContext?: ToolContext;
438
450
  historyRecorder?: HistoryRecorder;
439
451
  historyStack?: HistoryStack;
440
452
  fitToContent?: () => void;
453
+ shortcuts?: ShortcutOptions;
441
454
  }
442
455
  declare class InputHandler {
443
456
  private readonly element;
@@ -458,9 +471,12 @@ declare class InputHandler {
458
471
  private deferredDown;
459
472
  private readonly abortController;
460
473
  private readonly actions;
474
+ private readonly shortcutMap;
475
+ private readonly scope;
461
476
  constructor(element: HTMLElement, camera: Camera, options?: InputHandlerOptions);
462
477
  setToolManager(toolManager: ToolManager, toolContext: ToolContext): void;
463
478
  flushPendingHistory(): void;
479
+ get shortcuts(): ShortcutsApi;
464
480
  destroy(): void;
465
481
  private bind;
466
482
  private onWheel;
@@ -469,6 +485,7 @@ declare class InputHandler {
469
485
  private onPointerUp;
470
486
  private onKeyDown;
471
487
  private onKeyUp;
488
+ private runAction;
472
489
  private startPinch;
473
490
  private handlePinchMove;
474
491
  private getPinchPoints;
@@ -479,6 +496,8 @@ declare class InputHandler {
479
496
  private dispatchToolMove;
480
497
  private dispatchToolHover;
481
498
  private dispatchToolUp;
499
+ private isInScope;
500
+ private focusSelf;
482
501
  private cancelToolIfActive;
483
502
  }
484
503
 
@@ -569,6 +588,8 @@ interface ViewportOptions {
569
588
  background?: BackgroundOptions;
570
589
  fontSizePresets?: FontSizePreset[];
571
590
  toolbar?: boolean;
591
+ placeholder?: string;
592
+ shortcuts?: ShortcutOptions;
572
593
  onHtmlElementMount?: (elementId: string, domId: string | undefined, container: HTMLDivElement) => void;
573
594
  onDrop?: (event: DragEvent, worldPosition: {
574
595
  x: number;
@@ -617,6 +638,7 @@ declare class Viewport {
617
638
  loadState(state: CanvasState): void;
618
639
  loadJSON(json: string): void;
619
640
  setTool(name: string): void;
641
+ get shortcuts(): ShortcutsApi;
620
642
  undo(): boolean;
621
643
  redo(): boolean;
622
644
  addImage(src: string, position: {
@@ -703,6 +725,7 @@ declare class ElementRenderer {
703
725
  interface NoteEditorOptions {
704
726
  fontSizePresets?: FontSizePreset[];
705
727
  toolbar?: boolean;
728
+ placeholder?: string;
706
729
  }
707
730
  declare class NoteEditor {
708
731
  private editingId;
@@ -710,9 +733,11 @@ declare class NoteEditor {
710
733
  private blurHandler;
711
734
  private keyHandler;
712
735
  private pointerHandler;
736
+ private inputHandler;
713
737
  private pendingEditId;
714
738
  private onStopCallback;
715
739
  private toolbar;
740
+ private readonly placeholder;
716
741
  constructor(options?: NoteEditorOptions);
717
742
  get isEditing(): boolean;
718
743
  get editingElementId(): string | null;
@@ -735,6 +760,7 @@ interface StyledRun extends RunStyle {
735
760
  text: string;
736
761
  }
737
762
  declare function sanitizeNoteHtml(html: string): string;
763
+ declare function isNoteContentEmpty(html: string): boolean;
738
764
 
739
765
  interface ActiveFormats {
740
766
  bold: boolean;
@@ -964,6 +990,7 @@ declare class SelectTool implements Tool {
964
990
  private pendingSingleSelectId;
965
991
  private hasDragged;
966
992
  private resizeAspectRatio;
993
+ private hoveredId;
967
994
  get selectedIds(): string[];
968
995
  setSelection(ids: string[]): void;
969
996
  get isMarqueeActive(): boolean;
@@ -978,6 +1005,7 @@ declare class SelectTool implements Tool {
978
1005
  private updateArrowsBoundTo;
979
1006
  nudgeSelection(dx: number, dy: number, ctx: ToolContext): boolean;
980
1007
  private updateHoverCursor;
1008
+ private setHovered;
981
1009
  private handleResize;
982
1010
  private hitTestResizeHandle;
983
1011
  private getHandlePositions;
@@ -1212,6 +1240,6 @@ declare class UpdateLayerCommand implements Command {
1212
1240
  undo(_store: ElementStore): void;
1213
1241
  }
1214
1242
 
1215
- declare const VERSION = "0.18.0";
1243
+ declare const VERSION = "0.20.0";
1216
1244
 
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 };
1245
+ 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 ShortcutBindings, type ShortcutOptions, type ShortcutsApi, 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, isNoteContentEmpty, parseState, sanitizeNoteHtml, setFontSize, smartSnap, snapPoint, snapToHexCenter, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline, unbindArrow, updateBoundArrow };