@flowscape-ui/core-sdk 1.0.5 → 1.0.7

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
@@ -346,6 +346,7 @@ interface BaseNodeOptions {
346
346
  y?: number;
347
347
  width?: number;
348
348
  height?: number;
349
+ rotation?: number;
349
350
  }
350
351
  declare abstract class BaseNode<T extends Konva.Node = Konva.Node> implements NodeHandle<T> {
351
352
  protected konvaNode: T;
@@ -445,6 +446,12 @@ interface CoreEvents {
445
446
  'plugin:added': [pluginName: string];
446
447
  /** Plugin was removed */
447
448
  'plugin:removed': [pluginName: string];
449
+ /** Persistence restore failed */
450
+ 'persistence:restore:error': [{
451
+ error: string;
452
+ }];
453
+ /** Persistence restore completed */
454
+ 'persistence:restore:done': [];
448
455
  /** Stage was resized */
449
456
  'stage:resized': [{
450
457
  width: number;
@@ -526,6 +533,36 @@ interface EllipseNodeOptions extends BaseNodeOptions {
526
533
  strokeWidth?: number;
527
534
  }
528
535
 
536
+ interface FrameOptions {
537
+ x: number;
538
+ y: number;
539
+ width: number;
540
+ height: number;
541
+ background?: string;
542
+ label?: string;
543
+ labelColor?: string;
544
+ labelHoverColor?: string;
545
+ template?: string;
546
+ draggable?: boolean;
547
+ id?: string;
548
+ name?: string;
549
+ }
550
+
551
+ type FrameNodeOptions = FrameOptions & BaseNodeOptions;
552
+ declare class FrameNode extends BaseNode<Konva.Group> {
553
+ private _rect;
554
+ private _contentGroup;
555
+ private _container;
556
+ constructor(options: FrameNodeOptions);
557
+ getRect(): Konva.Rect;
558
+ getContentGroup(): Konva.Group;
559
+ /**
560
+ * Resize visual frame area without affecting child nodes.
561
+ * Updates rect size and clipping container.
562
+ */
563
+ resize(width: number, height: number): void;
564
+ }
565
+
529
566
  interface MediaPlaceholderOptions {
530
567
  text: string;
531
568
  textColor: string;
@@ -895,9 +932,12 @@ declare class NodeManager {
895
932
  private _nodes;
896
933
  private _stage;
897
934
  private _eventBus;
935
+ private _frameLabels;
936
+ private _selectedFrame;
898
937
  private _batchDrawScheduled;
899
938
  private _listCache;
900
939
  private _listCacheInvalidated;
940
+ private _hadFrameInLastMultiSelection;
901
941
  constructor(stage: Konva.Stage, eventBus: EventBus<CoreEvents>);
902
942
  get layer(): Konva.Layer;
903
943
  get world(): Konva.Group;
@@ -917,6 +957,7 @@ declare class NodeManager {
917
957
  addSvg(options: SvgNodeOptions): SvgNodeHandle;
918
958
  addVideo(options: VideoNodeOptions): VideoNodeHandle;
919
959
  addGif(options: GifNodeOptions): GifNodeHandle;
960
+ addFrame(options: FrameNodeOptions): FrameNode;
920
961
  remove(node: BaseNode): void;
921
962
  findById(id: string): BaseNode | undefined;
922
963
  list(): BaseNode[];
@@ -925,6 +966,14 @@ declare class NodeManager {
925
966
  * CRITICAL OPTIMIZATION: group multiple node additions
926
967
  */
927
968
  private _scheduleBatchDraw;
969
+ private _listFrames;
970
+ private _attachFrameAutogroupHandlers;
971
+ /**
972
+ * Обновить позицию overlay label над соответствующими фреймами
973
+ * (используется при создании и drag фреймов)
974
+ */
975
+ private _updateFrameLabelsPosition;
976
+ private _enforceFrameDraggableInvariant;
928
977
  }
929
978
 
930
979
  interface LODLevel {
@@ -1265,6 +1314,10 @@ declare class CoreEngine {
1265
1314
  * Enable or disable auto-resize
1266
1315
  */
1267
1316
  setAutoResize(enabled: boolean): void;
1317
+ /**
1318
+ * Show the canvas container after persistence restore completes
1319
+ */
1320
+ showContainer(): void;
1268
1321
  }
1269
1322
 
1270
1323
  /**
@@ -1397,6 +1450,8 @@ declare class AreaSelectionPlugin extends Plugin {
1397
1450
  constructor(options?: AreaSelectionPluginOptions);
1398
1451
  protected onAttach(core: CoreEngine): void;
1399
1452
  protected onDetach(core: CoreEngine): void;
1453
+ /** Проверить, что прямоугольник `inner` полностью содержится внутри `outer`. */
1454
+ private _rectContains;
1400
1455
  private _startAutoPanLoop;
1401
1456
  private _stopAutoPanLoop;
1402
1457
  private _finalizeArea;
@@ -1737,6 +1792,198 @@ declare class NodeHotkeysPlugin extends Plugin {
1737
1792
  private _syncGroupZIndex;
1738
1793
  }
1739
1794
 
1795
+ /**
1796
+ * IndexedDB storage service for canvas persistence.
1797
+ * Handles storage of canvas state and blob files (images, videos, etc.)
1798
+ */
1799
+ interface StoredCanvasState {
1800
+ id: string;
1801
+ state: string;
1802
+ updatedAt: number;
1803
+ }
1804
+ interface StoredBlob {
1805
+ id: string;
1806
+ blob: Blob;
1807
+ mimeType: string;
1808
+ originalUrl?: string | undefined;
1809
+ }
1810
+ declare class PersistenceStorage {
1811
+ private _dbName;
1812
+ private _db;
1813
+ private _dbPromise;
1814
+ constructor(_dbName?: string);
1815
+ /**
1816
+ * Initialize IndexedDB connection
1817
+ */
1818
+ init(): Promise<void>;
1819
+ private _openDatabase;
1820
+ private _getDb;
1821
+ /**
1822
+ * Save canvas state to IndexedDB
1823
+ */
1824
+ saveCanvasState(id: string, state: string): Promise<void>;
1825
+ /**
1826
+ * Load canvas state from IndexedDB
1827
+ */
1828
+ loadCanvasState(id: string): Promise<StoredCanvasState | null>;
1829
+ /**
1830
+ * Delete canvas state from IndexedDB
1831
+ */
1832
+ deleteCanvasState(id: string): Promise<void>;
1833
+ /**
1834
+ * List all canvas states
1835
+ */
1836
+ listCanvasStates(): Promise<StoredCanvasState[]>;
1837
+ /**
1838
+ * Save blob to IndexedDB
1839
+ */
1840
+ saveBlob(id: string, blob: Blob, originalUrl?: string): Promise<void>;
1841
+ /**
1842
+ * Load blob from IndexedDB
1843
+ */
1844
+ loadBlob(id: string): Promise<StoredBlob | null>;
1845
+ /**
1846
+ * Delete blob from IndexedDB
1847
+ */
1848
+ deleteBlob(id: string): Promise<void>;
1849
+ /**
1850
+ * Load multiple blobs by IDs
1851
+ */
1852
+ loadBlobs(ids: string[]): Promise<Map<string, StoredBlob>>;
1853
+ /**
1854
+ * Save multiple blobs
1855
+ */
1856
+ saveBlobs(blobs: Map<string, {
1857
+ blob: Blob;
1858
+ originalUrl?: string;
1859
+ }>): Promise<void>;
1860
+ /**
1861
+ * List all blob IDs
1862
+ */
1863
+ listBlobIds(): Promise<string[]>;
1864
+ /**
1865
+ * Clear all blobs not referenced in the given set
1866
+ */
1867
+ cleanupUnusedBlobs(usedBlobIds: Set<string>): Promise<number>;
1868
+ /**
1869
+ * Clear all data (canvas states and blobs)
1870
+ */
1871
+ clearAll(): Promise<void>;
1872
+ /**
1873
+ * Close database connection
1874
+ */
1875
+ close(): void;
1876
+ /**
1877
+ * Delete the entire database
1878
+ */
1879
+ deleteDatabase(): Promise<void>;
1880
+ }
1881
+
1882
+ /**
1883
+ * PersistencePlugin - Auto-saves canvas state to IndexedDB on any change.
1884
+ * Restores state on page reload. Supports export/import to JSON with embedded blobs.
1885
+ */
1886
+
1887
+ interface PersistencePluginOptions {
1888
+ /** Unique ID for this canvas (default: 'default') */
1889
+ canvasId?: string;
1890
+ /** Debounce delay in ms before saving (default: 300) */
1891
+ debounceMs?: number;
1892
+ /** Auto-restore on attach (default: true) */
1893
+ autoRestore?: boolean;
1894
+ /** Custom IndexedDB database name */
1895
+ dbName?: string;
1896
+ /** Enable debug logging */
1897
+ debug?: boolean;
1898
+ }
1899
+ declare class PersistencePlugin extends Plugin {
1900
+ private _core;
1901
+ private _storage;
1902
+ private _canvasId;
1903
+ private _debounceMs;
1904
+ private _autoRestore;
1905
+ private _debug;
1906
+ private _saveTimer;
1907
+ private _isRestoring;
1908
+ private _blobUrls;
1909
+ private _initialized;
1910
+ /** Maps original blob URLs to stored blob IDs */
1911
+ private _blobUrlToId;
1912
+ constructor(options?: PersistencePluginOptions);
1913
+ protected onAttach(core: CoreEngine): void;
1914
+ protected onDetach(core: CoreEngine): void;
1915
+ private _initialize;
1916
+ private _subscribeToEvents;
1917
+ private _unsubscribeFromEvents;
1918
+ private _onNodeCreated;
1919
+ private _onNodeChange;
1920
+ private _onClipboardPaste;
1921
+ /**
1922
+ * Capture blob data from a media node if it has a blob URL
1923
+ */
1924
+ private _captureBlobFromNode;
1925
+ private _onNodeTransformed;
1926
+ private _onCameraChange;
1927
+ private _onKonvaDragEnd;
1928
+ private _onKonvaTransformEnd;
1929
+ private _onTextChange;
1930
+ /**
1931
+ * Subscribe to textChange events for all existing TextNodes
1932
+ */
1933
+ private _subscribeToTextNodes;
1934
+ private _scheduleSave;
1935
+ private _cancelPendingSave;
1936
+ /**
1937
+ * Save current canvas state to IndexedDB
1938
+ */
1939
+ save(): Promise<void>;
1940
+ /**
1941
+ * Restore canvas state from IndexedDB
1942
+ */
1943
+ restore(): Promise<boolean>;
1944
+ /**
1945
+ * Clear saved state from IndexedDB
1946
+ */
1947
+ clear(): Promise<void>;
1948
+ /**
1949
+ * Export canvas to JSON string with embedded blobs
1950
+ */
1951
+ exportToJSON(): Promise<string>;
1952
+ /**
1953
+ * Import canvas from JSON string with embedded blobs
1954
+ */
1955
+ importFromJSON(json: string): void;
1956
+ /**
1957
+ * Download canvas as JSON file
1958
+ */
1959
+ downloadJSON(filename?: string): Promise<void>;
1960
+ /**
1961
+ * Upload and import canvas from JSON file
1962
+ */
1963
+ uploadJSON(): Promise<void>;
1964
+ /**
1965
+ * Check if there is saved state
1966
+ */
1967
+ hasSavedState(): Promise<boolean>;
1968
+ /**
1969
+ * Get storage instance for advanced usage
1970
+ */
1971
+ getStorage(): PersistenceStorage;
1972
+ /**
1973
+ * Get canvas ID
1974
+ */
1975
+ getCanvasId(): string;
1976
+ /**
1977
+ * Set canvas ID (will trigger restore if autoRestore is enabled)
1978
+ */
1979
+ setCanvasId(id: string): Promise<void>;
1980
+ private _log;
1981
+ /**
1982
+ * Capture blob URLs from all nodes that haven't been captured yet
1983
+ */
1984
+ private _captureAllBlobUrls;
1985
+ }
1986
+
1740
1987
  interface RulerGuidesPluginOptions {
1741
1988
  guideColor?: string;
1742
1989
  activeColor?: string;
@@ -2155,6 +2402,10 @@ declare class SelectionPlugin extends Plugin {
2155
2402
  private _prevStageDraggableBeforeRotate;
2156
2403
  private _worldSyncRafId;
2157
2404
  private _onCameraZoomEvent;
2405
+ private _onFrameChildrenChangedBound;
2406
+ private _onFrameLabelClickedBound;
2407
+ private _onFrameLabelDragStartBound;
2408
+ private _onFrameLabelDragEndBound;
2158
2409
  private _hoverTr;
2159
2410
  private _isPointerDown;
2160
2411
  private _autoPanRafId;
@@ -2171,6 +2422,13 @@ declare class SelectionPlugin extends Plugin {
2171
2422
  private _tempMultiInitialTransforms;
2172
2423
  private _tempMultiGroup;
2173
2424
  private _tempOverlay;
2425
+ /**
2426
+ * Public readonly access to the currently selected BaseNode
2427
+ * (or null if there is no selection). Mutable selection logic
2428
+ * still lives inside SelectionPlugin; this method is used only
2429
+ * for safe inspection from other plugins.
2430
+ */
2431
+ getSelected(): BaseNode | null;
2174
2432
  getMultiGroupController(): MultiGroupController;
2175
2433
  private _multiCtrl;
2176
2434
  private _startAutoPanLoop;
@@ -2188,6 +2446,18 @@ declare class SelectionPlugin extends Plugin {
2188
2446
  private _uiUpdateDebounce;
2189
2447
  constructor(options?: SelectionPluginOptions);
2190
2448
  setOptions(patch: Partial<SelectionPluginOptions>): void;
2449
+ /**
2450
+ * Select a single node from area (lasso) selection, without creating temp-multi.
2451
+ * Used by AreaSelectionPlugin so that single-node selection (including FrameNode)
2452
+ * reuses the same transformer and resize logic as обычный клик.
2453
+ */
2454
+ selectSingleFromArea(node: BaseNode): void;
2455
+ /**
2456
+ * Clear current selection (single + temp-multi) when starting lasso
2457
+ * in special cases (e.g. inside FrameNode background) to mirror
2458
+ * behavior of clicking on empty space in world.
2459
+ */
2460
+ clearSelectionFromAreaLasso(): void;
2191
2461
  protected onAttach(core: CoreEngine): void;
2192
2462
  protected onDetach(core: CoreEngine): void;
2193
2463
  private _onMouseDown;
@@ -2213,10 +2483,26 @@ declare class SelectionPlugin extends Plugin {
2213
2483
  private _ensureTempMulti;
2214
2484
  private _destroyTempMultiOverlayOnly;
2215
2485
  private _destroyTempMulti;
2486
+ /**
2487
+ * FRAME-SPECIFIC: автогруппировка для временной multi-группы.
2488
+ * Для каждой ноды из tempMultiSet повторяет логику
2489
+ * NodeManager._attachFrameAutogroupHandlers:
2490
+ * - если нода была внутри FrameNode и вышла за его пределы, возвращаем её в world;
2491
+ * - если нода была в world и её центр оказался внутри фрейма, переносим в contentGroup.
2492
+ * Поведение вне FrameNode остаётся без изменений.
2493
+ */
2494
+ private _autogroupTempMultiInFrames;
2216
2495
  private _commitTempMultiToGroup;
2217
2496
  private _tryUngroupSelectedGroup;
2218
2497
  private _ensureHoverTr;
2219
2498
  private _destroyHoverTr;
2499
+ /**
2500
+ * Frame-specific selectability rules for direct clicks/hover:
2501
+ * - If the owning BaseNode is a FrameNode and it has at least one child inside contentGroup,
2502
+ * the frame is not directly selectable/hoverable (selection only via lasso).
2503
+ * - Empty frames and all other nodes remain selectable.
2504
+ */
2505
+ private _isSelectableByFrameRules;
2220
2506
  private _onHoverMoveThrottled;
2221
2507
  private _onHoverMove;
2222
2508
  private _onHoverDown;
@@ -2382,6 +2668,53 @@ declare class TextAutoTrimAddon extends NodeAddon<TextNode> {
2382
2668
  private normalize;
2383
2669
  }
2384
2670
 
2671
+ /**
2672
+ * Canvas serialization/deserialization utility.
2673
+ * Handles conversion of canvas state to/from JSON format with blob extraction.
2674
+ */
2675
+
2676
+ interface SerializedNode {
2677
+ id: string;
2678
+ type: string;
2679
+ attrs: Record<string, unknown>;
2680
+ zIndex: number;
2681
+ blobId?: string;
2682
+ children?: SerializedNode[];
2683
+ parentFrameId?: string;
2684
+ }
2685
+ interface SerializedCamera {
2686
+ x: number;
2687
+ y: number;
2688
+ scale: number;
2689
+ }
2690
+ interface SerializedCanvas {
2691
+ version: number;
2692
+ timestamp: number;
2693
+ nodes: SerializedNode[];
2694
+ camera: SerializedCamera;
2695
+ blobIds: string[];
2696
+ }
2697
+ interface ExtractedBlob {
2698
+ id: string;
2699
+ blob: Blob;
2700
+ originalUrl: string;
2701
+ }
2702
+ interface DeserializeOptions {
2703
+ blobUrls?: Map<string, string>;
2704
+ clearExisting?: boolean;
2705
+ }
2706
+ interface SerializeOptions {
2707
+ /** Pre-existing mapping of blob URLs to blob IDs (from captured blobs) */
2708
+ blobUrlToId?: Map<string, string>;
2709
+ }
2710
+ declare function serializeCanvas(core: CoreEngine, options?: SerializeOptions): SerializedCanvas;
2711
+ declare function extractBlobs(core: CoreEngine): Promise<Map<string, ExtractedBlob>>;
2712
+ declare function deserializeCanvas(core: CoreEngine, state: SerializedCanvas, options?: DeserializeOptions): void;
2713
+ declare function exportCanvasToJSON(core: CoreEngine): Promise<string>;
2714
+ declare function importCanvasFromJSON(core: CoreEngine, json: string, options?: Omit<DeserializeOptions, 'blobUrls'>): void;
2715
+ declare function createBlobUrlMap(state: SerializedCanvas, storedBlobs: Map<string, Blob>): Map<string, string>;
2716
+ declare function revokeBlobUrls(blobUrls: Map<string, string>): void;
2717
+
2385
2718
  /**
2386
2719
  * DebounceHelper - utility for debouncing (delayed execution)
2387
2720
  *
@@ -2463,4 +2796,13 @@ declare class ThrottleHelper {
2463
2796
  getThrottle(): number;
2464
2797
  }
2465
2798
 
2466
- export { type ArcNodeHandle, type ArcNodeOptions, AreaSelectionPlugin, type AreaSelectionPluginOptions, type ArrowNodeHandle, type ArrowNodeOptions, type BaseNodeOptions, type CameraHotkeysOptions, CameraHotkeysPlugin, CameraManager, type CircleNodeHandle, type CircleNodeOptions, ContentFromClipboardPlugin, type ContentFromClipboardPluginOptions, CoreEngine, type CoreEngineOptions, type CoreEvents, DebounceHelper, type EllipseNodeHandle, type EllipseNodeOptions, EventBus, type GifNodeHandle, type GifNodeOptions, GridPlugin, type GridPluginOptions, type GroupNodeHandle, type GroupNodeOptions, type HistoryAction, HistoryManager, HistoryPlugin, type HistoryPluginOptions, ImageHoverFilterAddon, type ImageNodeHandle, type ImageNodeOptions, type ImageSource, type KonvaArc, type KonvaArrow, type KonvaCircle, type KonvaEllipse, type KonvaGroup, type KonvaGroupConfig, type KonvaImage, type KonvaLayer, type KonvaNode, type KonvaNodeConfig, type KonvaRegularPolygon, type KonvaRing, type KonvaShape, type KonvaStage, type KonvaStar, type KonvaText, type LogoOptions, LogoPlugin, MediaPlaceholder, type MediaPlaceholderOptions, NodeAddon, NodeAddons, type NodeAddonsHandle, type NodeHandle, type NodeHotkeysOptions, NodeHotkeysPlugin, NodeManager, PluginAddon, Plugins, type RegularPolygonNodeHandle, type RegularPolygonNodeOptions, type RingNodeHandle, type RingNodeOptions, RulerGuidesAddon, RulerGuidesPlugin, type RulerGuidesPluginOptions, RulerHighlightAddon, RulerHighlightPlugin, type RulerHighlightPluginOptions, RulerManagerAddon, RulerManagerPlugin, type RulerManagerPluginOptions, RulerPlugin, type RulerPluginOptions, SelectionPlugin, type SelectionPluginOptions, ShapeHoverHighlightAddon, type ShapeNodeHandle, type ShapeNodeOptions, type StarNodeHandle, type StarNodeOptions, type SvgNodeHandle, type SvgNodeOptions, TextAutoTrimAddon, type TextNodeHandle, type TextNodeOptions, ThrottleHelper, type VideoNodeHandle, type VideoNodeOptions, VideoOverlayAddon, type VideoOverlayAddonOptions, VisualGuidesPlugin, type VisualGuidesPluginOptions };
2799
+ declare const frameTemplates: {
2800
+ readonly desktopFrame: {
2801
+ width: number;
2802
+ height: number;
2803
+ template: string;
2804
+ label: string;
2805
+ };
2806
+ };
2807
+
2808
+ export { type ArcNodeHandle, type ArcNodeOptions, AreaSelectionPlugin, type AreaSelectionPluginOptions, type ArrowNodeHandle, type ArrowNodeOptions, type BaseNodeOptions, type CameraHotkeysOptions, CameraHotkeysPlugin, CameraManager, type CircleNodeHandle, type CircleNodeOptions, ContentFromClipboardPlugin, type ContentFromClipboardPluginOptions, CoreEngine, type CoreEngineOptions, type CoreEvents, DebounceHelper, type DeserializeOptions, type EllipseNodeHandle, type EllipseNodeOptions, EventBus, type ExtractedBlob, FrameNode, type FrameNodeOptions, type FrameOptions, type GifNodeHandle, type GifNodeOptions, GridPlugin, type GridPluginOptions, type GroupNodeHandle, type GroupNodeOptions, type HistoryAction, HistoryManager, HistoryPlugin, type HistoryPluginOptions, ImageHoverFilterAddon, type ImageNodeHandle, type ImageNodeOptions, type ImageSource, type KonvaArc, type KonvaArrow, type KonvaCircle, type KonvaEllipse, type KonvaGroup, type KonvaGroupConfig, type KonvaImage, type KonvaLayer, type KonvaNode, type KonvaNodeConfig, type KonvaRegularPolygon, type KonvaRing, type KonvaShape, type KonvaStage, type KonvaStar, type KonvaText, type LogoOptions, LogoPlugin, MediaPlaceholder, type MediaPlaceholderOptions, NodeAddon, NodeAddons, type NodeAddonsHandle, type NodeHandle, type NodeHotkeysOptions, NodeHotkeysPlugin, NodeManager, PersistencePlugin, type PersistencePluginOptions, PersistenceStorage, PluginAddon, Plugins, type RegularPolygonNodeHandle, type RegularPolygonNodeOptions, type RingNodeHandle, type RingNodeOptions, RulerGuidesAddon, RulerGuidesPlugin, type RulerGuidesPluginOptions, RulerHighlightAddon, RulerHighlightPlugin, type RulerHighlightPluginOptions, RulerManagerAddon, RulerManagerPlugin, type RulerManagerPluginOptions, RulerPlugin, type RulerPluginOptions, SelectionPlugin, type SelectionPluginOptions, type SerializeOptions, type SerializedCamera, type SerializedCanvas, type SerializedNode, ShapeHoverHighlightAddon, type ShapeNodeHandle, type ShapeNodeOptions, type StarNodeHandle, type StarNodeOptions, type StoredBlob, type StoredCanvasState, type SvgNodeHandle, type SvgNodeOptions, TextAutoTrimAddon, type TextNodeHandle, type TextNodeOptions, ThrottleHelper, type VideoNodeHandle, type VideoNodeOptions, VideoOverlayAddon, type VideoOverlayAddonOptions, VisualGuidesPlugin, type VisualGuidesPluginOptions, createBlobUrlMap, deserializeCanvas, exportCanvasToJSON, extractBlobs, frameTemplates, importCanvasFromJSON, revokeBlobUrls, serializeCanvas };