UNPKG

@sheetxl/models

Version:

Models - A Headless javascript spreadsheet library.

138 lines 5.36 kB
import { Bounds, Point, CellRangeCoords, SetOptions } from "@sheetxl/common"; import { ISharedResource, ISharedPersister, SharedResourceJSON } from "../resource"; import { ChangeSet } from "../transaction"; import { AnchorType } from '../anchor'; import { AbstractAnchoredItem, AnchoredItemOptions, AnchoredItemTransactionState, AnchoredItemTransactionInputs } from "../anchor/AnchoredItem"; import { ICopyableDrawingModel, DrawingJSON, DrawingAnchorJSON, IDrawingModel, IDrawingContainer } from './IDrawingModel'; interface DrawingOffsets { tl: Point; br: Point; } export interface DrawingTransactionState extends AnchoredItemTransactionState { name?: string; description?: string; hidden?: boolean; rotation?: number; lockAspectRatio?: boolean; offsets?: DrawingOffsets; } interface DrawingTransactionInputs extends AnchoredItemTransactionInputs { } /** * Options for adding a drawing object to a drawing container. */ export interface AnchoredDrawingOptions<J extends DrawingJSON = DrawingJSON> extends AnchoredItemOptions { /** * The type of the drawing */ type: string; /** * The initial JSON to load the drawing from. */ jsonAnchor?: DrawingAnchorJSON<J>; /** * If provided the drawing will be added to the resource manager. */ resource?: ISharedResource; /** * from resourceId */ fromResourceId?: (resourceId: number) => ISharedResource; /** * Useful for load/save/copying */ beginPersistResource(): ISharedPersister<SharedResourceJSON>; /** * Returns the bounds of a range of cells. * @param range */ getBoundsFromRange(range: CellRangeCoords): Bounds; /** * Returns an anchor for the given bounds. */ getRangeFromBounds(bounds: Bounds): CellRangeCoords; /** * Move drawing to the back in the zIndex. */ moveToBackOnContainer?: () => void; /** * Move drawing backward one layer in the zIndex. */ moveBackwardOnContainer?: () => void; /** * Move drawing to the font in the zIndex. */ moveToFrontOnContainer?: () => void; /** * Move drawing forward one layer in the zIndex. */ moveForwardOnContainer?: () => void; /** * Return the z-index for the current Drawing. */ getZIndex?: () => number; /** * Return the maximum bounds of the container. If not defined the container will be unbounded. * @returns */ getMaxBounds?: () => Bounds; /** * Notify drawing it's zIndex has been updated from the container. * @param callback */ setContainerZIndexCallback(callback: () => void): void; /** * Allow for the default lock aspect ratio to be overwritten. */ defaultLockAspectRatio?: boolean; } export declare abstract class AbstractDrawing<J extends DrawingJSON = DrawingJSON, STATE extends DrawingTransactionState = DrawingTransactionState> extends AbstractAnchoredItem<STATE> implements ICopyableDrawingModel<J> { static instanceCounter: number; private _type; private _uuid; private _boundsCache; private _optionsDrawing; constructor(options: AnchoredDrawingOptions<J>); protected onRecordChange(_change: ChangeSet<STATE, DrawingTransactionInputs>): void; copyTo(destination: IDrawingContainer, bounds: Bounds): IDrawingModel<J>; get isCopyableDrawing(): true; getCopyableDrawings(bounds: Bounds): ICopyableDrawingModel[]; setName(name: string): void; getName(): string; setDescription(description: string): void; getDescription(): string; setHidden(hidden: boolean): void; isHidden(): boolean; setLockAspectRatio(lockAspectRatio: boolean): void; isLockAspectRatio(): boolean; setRotation(rotation: number): void; getRotation(): number; moveToBack(): void; moveBackward(): void; moveToFront(): void; moveForward(): void; get zIndex(): number; protected _updateTransactionState(description?: string, updateState?: Partial<STATE>, //(prevState: STATE) => STATE, updaterInputs?: (prevInputs: any) => any): void; setBounds(bounds: Partial<Bounds>, options?: SetOptions): void; private _updateDrawingLocation; private _calcAbsoluteBounds; getBounds(): Bounds; setAnchorType?(anchorType: AnchorType): void; protected _processAnchorOnContainerShift(after: CellRangeCoords, before: CellRangeCoords, intersect: CellRangeCoords, isColumnShift: boolean, shiftAmount: number): CellRangeCoords | void; protected _invalidateBounds(): void; protected _processAnchorOnContainerResize(): void; notifyAnchorUpdate(anchor?: CellRangeCoords): void; notifyAnyChanges(): void; notifyBoundsChange(): void; protected abstract _drawingTypeDescription(): string; protected abstract _toDrawingJSON(_toResourceId?: (resource: ISharedResource) => number): J; protected abstract _fromDrawingJSON(drawing: DrawingJSON, _fromResourceId?: (id: number) => ISharedResource): void; protected _fromJSON(json: DrawingAnchorJSON<J>, fromResourceId?: (id: number) => ISharedResource): void; toJSON(toResourceId?: (resource: ISharedResource) => number): DrawingAnchorJSON<J>; get type(): string; get uuid(): string; get isDrawing(): true; } export {}; //# sourceMappingURL=DrawingModel.d.ts.map