import { Fun, type Optional } from '@ephox/katamari'; import type { SimRange, SugarElement } from '@ephox/sugar'; import type { Bounds } from '../../alien/Boxes'; import type { AlloyComponent } from '../../api/component/ComponentApi'; import type { Bubble } from '../layout/Bubble'; import type { AnchorBox, AnchorLayout, PlacerResult } from '../layout/LayoutTypes'; import type { OriginAdt } from '../layout/Origins'; import type { Transition } from '../view/Transitions'; // doPlace(component, origin, anchoring, placeeState, posConfig, placee, lastPlacement, transition); export type AnchorPlacement = ( comp: AlloyComponent, origin: OriginAdt, anchoring: Anchoring, getBounds: Optional<() => Bounds>, placee: AlloyComponent, lastPlacement: Optional, transition: Optional ) => PlacerResult; export interface CommonAnchorSpec { type: string; } export type AnchorSpec = SelectionAnchorSpec | HotspotAnchorSpec | SubmenuAnchorSpec | MakeshiftAnchorSpec | NodeAnchorSpec; export interface AnchorDetail { placement: (comp: AlloyComponent, anchor: D, origin: OriginAdt) => Optional; } export type MaxHeightFunction = (elem: SugarElement, available: number) => void; export type MaxWidthFunction = (elem: SugarElement, available: number) => void; export interface AnchorOverrides { maxHeightFunction?: MaxHeightFunction; maxWidthFunction?: MaxWidthFunction; } export interface LayoutsDetail { onLtr: (elem: SugarElement) => AnchorLayout[]; onRtl: (elem: SugarElement) => AnchorLayout[]; onBottomLtr: Optional<(elem: SugarElement) => AnchorLayout[]>; onBottomRtl: Optional<(elem: SugarElement) => AnchorLayout[]>; } export interface HasLayoutAnchor { layouts: Optional; } export interface Layouts { onLtr: (elem: SugarElement) => AnchorLayout[]; onRtl: (elem: SugarElement) => AnchorLayout[]; onBottomLtr?: (elem: SugarElement) => AnchorLayout[]; onBottomRtl?: (elem: SugarElement) => AnchorLayout[]; } export interface HasLayoutAnchorSpec { layouts?: Layouts; } export interface SelectionTableCellRange { firstCell: SugarElement; lastCell: SugarElement; } export interface SelectionAnchorSpec extends CommonAnchorSpec, HasLayoutAnchorSpec { type: 'selection'; getSelection?: () => Optional; root: SugarElement; bubble?: Bubble; overrides?: AnchorOverrides; showAbove?: boolean; } export interface SelectionAnchor extends AnchorDetail, HasLayoutAnchor { getSelection: Optional<() => Optional>; root: SugarElement; bubble: Optional; overrides: AnchorOverrides; showAbove: boolean; } export interface NodeAnchorSpec extends CommonAnchorSpec, HasLayoutAnchorSpec { type: 'node'; node: Optional>; root: SugarElement; bubble?: Bubble; overrides?: AnchorOverrides; showAbove?: boolean; } export interface NodeAnchor extends AnchorDetail, HasLayoutAnchor { node: Optional>; root: SugarElement; bubble: Optional; overrides: AnchorOverrides; showAbove: boolean; } export interface HotspotAnchorSpec extends CommonAnchorSpec, HasLayoutAnchorSpec { type: 'hotspot'; hotspot: AlloyComponent; bubble?: Bubble; overrides?: AnchorOverrides; } export interface HotspotAnchor extends AnchorDetail, HasLayoutAnchor { hotspot: AlloyComponent; bubble: Optional; overrides: AnchorOverrides; } export interface SubmenuAnchorSpec extends CommonAnchorSpec, HasLayoutAnchorSpec { type: 'submenu'; overrides?: AnchorOverrides; item: AlloyComponent; } export interface SubmenuAnchor extends AnchorDetail, HasLayoutAnchor { item: AlloyComponent; overrides: AnchorOverrides; } export interface MakeshiftAnchorSpec extends CommonAnchorSpec, HasLayoutAnchorSpec { type: 'makeshift'; x: number; y: number; height?: number; width?: number; bubble?: Bubble; overrides?: AnchorOverrides; } export interface MakeshiftAnchor extends AnchorDetail, HasLayoutAnchor { x: number; y: number; height: number; width: number; bubble: Bubble; overrides: AnchorOverrides; } export interface Anchoring { anchorBox: AnchorBox; bubble: Bubble; overrides: AnchorOverrides; layouts: AnchorLayout[]; } const nu: (spec: Anchoring) => Anchoring = Fun.identity; export { nu };