import { Slot } from '@blockeditor/global/utils'; import type { Page } from '@blockeditor/store'; import type { FrameBlockModel } from '../../frame-block/frame-model.js'; import { EdgelessBlockModel, type EdgelessModel } from '../../page-block/edgeless/type.js'; import { ElementModel } from '../element-model/base.js'; import { GridManager } from '../grid.js'; import type { SurfaceBlockModel } from '../surface-model.js'; export type ReorderingDirection = 'front' | 'forward' | 'backward' | 'back'; type BaseLayer = { set: Set; elements: Array; /** * fractional indexing range */ indexes: [string, string]; }; export type BlockLayer = BaseLayer & { type: 'block'; /** * The computed DOM z-index used for rendering blocks. * One layer contains multiple blocks, * so we need the array to mark the start and end of the z-index range. */ zIndexes: [number, number]; }; export type CanvasLayer = BaseLayer & { type: 'canvas'; /** * The computed DOM z-index used for rendering this canvas layer. * The canvas layer only contains one DOM element of the canvas, * so we only need one number to mark the z-index. */ zIndexes: number; }; export type Layer = BlockLayer | CanvasLayer; export declare class LayerManager { static INITAL_INDEX: string; static create(page: Page, surface: SurfaceBlockModel): LayerManager; private _disposables; slots: { layerUpdated: Slot; }; canvasElements: ElementModel[]; blocks: EdgelessBlockModel[]; frames: FrameBlockModel[]; layers: Layer[]; canvasLayers: { set: Set; /** * fractional index */ indexes: [string, string]; /** * z-index, used for actual rendering */ zIndexes: number; elements: Array; }[]; blocksGrid: GridManager>; framesGrid: GridManager; canvasGrid: GridManager>; constructor(elements?: EdgelessModel[]); private listen; private _init; private _initLayers; private _insertIntoLayer; private _removeFromLayer; private _buildCanvasLayers; /** * @returns a boolean value to indicate whether the layers have been updated */ private _updateLayer; add(element: EdgelessModel): void; delete(element: EdgelessModel): void; update(element: EdgelessModel, props?: Record): void; getCanvasLayers(): { set: Set>; /** * fractional index */ indexes: [string, string]; /** * z-index, used for actual rendering */ zIndexes: number; elements: ElementModel[]; }[]; generateIndex(elementType: string): string; /** * In some cases, we need to generate a bunch of indexes in advance before acutally adding the elements to the layer manager. * Eg. when importing a template. The `generateIndex` is a function only depends on the current state of the manager. * So we cannot use it because it will always return the same index if the element is not added to manager. * * This function return a index generator that can "remember" the index it generated without actually adding the element to the manager. * * @note The generator cannot work with `group` element. * * @param ignoreRule If true, the generator will not distinguish between `block` and `canvas` elements. * @returns */ createIndexGenerator(ignoreRule?: boolean): (elementType: string) => string; getReorderedIndex(element: EdgelessModel, direction: ReorderingDirection): string; /** * Pass to the `Array.sort` to sort the elements by their index */ compare(a: EdgelessModel, b: EdgelessModel): 1 | 0 | -1; dispose(): void; } export {}; //# sourceMappingURL=layer-manager.d.ts.map