import { type PointerEvent as ReactPointerEvent } from 'react';
import type { FloatingAnchor } from '../components/floating.js';
import type { GraphEdit, GraphSlot, NeedRef, NudgeDirection, StepRef } from '../editing.js';
import type { EditorProblem, RevealTarget } from './editorApi.js';
import type { Box, Point, Store } from './editorPrimitives.js';
import type { GraphEditorStrings } from './editorStrings.js';
/** Pointer-downs on this class drag editor items instead of panning the graph. */
export declare const EDITOR_HANDLE_CLASS = "dag-editor-handle";
/** A node's left circle takes dependencies; its right circle gives them. */
export type PortSide = 'in' | 'out';
export type ConnectPayload = {
kind: 'connect';
from: string[];
side: PortSide;
label: string;
/** The circle dragged from: `node:
`, or `selection`. */
port: string;
/** An end of a connector being moved: its needs go on the drop, and the line starts at its other end. */
replaces?: NeedRef[];
origin?: Point;
};
export type DragPayload =
/** `anchor` lands where the drag drops; the other jobs keep their offsets from it. */
{
kind: 'jobs';
jobs: string[];
label: string;
anchor?: string;
} | {
kind: 'new';
matrix: boolean;
label: string;
} | ConnectPayload | {
kind: 'steps';
steps: StepRef[];
label: string;
};
export type DropTarget =
/** `blocked` when the move would cut a need an expression of a moved job reads. */
{
kind: 'slot';
slot: GraphSlot;
indicator: Box;
blocked?: boolean;
} | {
kind: 'trash';
}
/** `edits` is null when the drop can't connect. */
| {
kind: 'connect';
edits: GraphEdit[] | null;
box: Box;
}
/** Dragged jobs join `into`'s node, taking its needs; `valid` is false when that would loop. */
| {
kind: 'merge';
into: string;
jobs: string[];
valid: boolean;
box: Box;
}
/** Steps land at `index` of `job`; `around` outlines a job whose steps aren't shown, `problem` refuses the drop. */
| {
kind: 'steps';
job: string;
index: number;
indicator: Box;
around?: boolean;
problem?: string;
};
export interface DragView {
payload: DragPayload;
client: Point;
content: Point | null;
origin: Point | null;
target: DropTarget | null;
}
/** A job or step being added: `yml` is the workflow as if `edit` were applied, which the dialog's first save does. */
export interface Addition {
edit: GraphEdit;
yml: string;
}
export type Dialog = {
kind: 'job';
job: string;
addition?: Addition;
} | {
kind: 'step';
job: string;
index: number;
addition?: Addition;
};
export declare const labelsOf: (jobs: string[]) => string;
/** A drawn connector, named by the head jobs of the boxes it joins. */
export interface EdgeSelection {
from: string;
to: string;
}
export interface UiState {
drag: DragView | null;
/** Selected connectors. Jobs, steps and connectors are never selected together. */
edges: EdgeSelection[];
dialog: Dialog | null;
selection: string[];
steps: StepRef[];
problems: EditorProblem[];
/** The box being dragged out on empty space, in content coordinates. */
marquee: Box | null;
}
export declare const NO_SELECTION: string[];
export declare const NO_STEPS: StepRef[];
export declare const NO_EDGES: EdgeSelection[];
export declare const NO_PROBLEMS: EditorProblem[];
export declare const problemsIn: (problems: EditorProblem[], job: string, step?: number) => EditorProblem[];
export declare const sameStep: (a: StepRef, b: StepRef) => boolean;
export type UiStore = Store;
/** The drawn grid of the level being edited; `rows` holds each box's row, `columns` each column's number. */
export interface GraphGrid {
wrapper: HTMLDivElement;
cols: string[][][];
rows: number[][];
columns: number[];
}
/** What the editor asks of the graph's view. */
export interface GraphView {
/** Keeps `job` where it is on screen through the next layout change, rather than refitting. */
hold: (job: string) => void;
}
export interface GraphEditorApi {
store: UiStore;
/** The editor's strings, so what the graph draws for it needn't load them itself. */
t: GraphEditorStrings;
isMatrixJob: (job: string) => boolean;
startDrag: (e: ReactPointerEvent, payload: DragPayload) => void;
openJobMenu: (at: FloatingAnchor, job: string) => void;
openStepMenu: (at: FloatingAnchor, job: string, index: number) => void;
openEdgeMenu: (at: FloatingAnchor, edge: EdgeSelection) => void;
/**
* Selects a connector alone, or with `add` adds it to the selected connectors or takes it out;
* selected jobs or steps give way to it.
*/
selectEdge: (edge: EdgeSelection, add: boolean) => void;
/** Whether an expression reads one of a connector's needs, so it can't be removed or moved. */
edgeInUse: (edge: EdgeSelection) => boolean;
/** Starts moving one end of a connector; `fixed` is its other end, in the graph's own pixels. */
startEdgeEnd: (e: ReactPointerEvent, edge: EdgeSelection, end: 'from' | 'to', fixed: Point) => void;
/** Removes the selected jobs, steps and connectors; false when nothing is selected. */
deleteSelection: () => boolean;
/** Opens the dialog of the one selected job or step, reporting whether there was one. */
editSelection: () => boolean;
addJob: (matrix: boolean) => void;
addStep: (job: string) => void;
editJob: (job: string) => void;
editStep: (job: string, index: number) => void;
registerGrid: (grid: GraphGrid | null) => void;
grid: () => GraphGrid | null;
registerView: (view: GraphView | null) => void;
/** The selected jobs that still exist. */
selected: () => string[];
/** Adds a job to the selected jobs or takes it out; selected steps or connectors give way to it. */
toggleSelected: (job: string) => void;
/** The selected steps that still exist. */
selectedSteps: () => StepRef[];
/** Adds a step to the selected steps or takes it out; selected jobs or connectors give way to it. */
toggleStep: (step: StepRef) => void;
/** Puts the selected jobs or steps on the clipboard, as YAML; null when nothing is selected. */
copySelection: () => string | null;
/** Adds the jobs or steps in `text` near `pointer`; false when `text` holds neither. */
paste: (text: string, pointer: Point | null) => boolean;
/** Moves the selected jobs one slot; false when no jobs are selected. */
nudge: (direction: NudgeDirection) => boolean;
reveal: (target: RevealTarget) => void;
/** Selects a job, or one of its steps, alone. */
focus: (target: {
job: string;
step?: number;
}) => void;
}
export declare const GraphEditorProvider: import("react").Provider;
export declare function useGraphEditor(): GraphEditorApi | null;
export declare function useUi(api: GraphEditorApi | null, select: (state: UiState) => T, fallback: T): T;
export declare function useSelectedEdges(api: GraphEditorApi | null): EdgeSelection[];
export declare const sameEdge: (a: EdgeSelection, b: EdgeSelection) => boolean;
export declare function toContent(wrapper: HTMLElement, client: Point): Point;
export declare function contentBox(wrapper: HTMLElement, el: Element): Box;
/**
* The outline around the selected jobs, in content coordinates: as tall as their rows and
* as wide as their nodes, so its circles sit clear of the nodes' own.
*/
export declare function selectionBounds(wrapper: HTMLElement, jobs: string[]): (Box & {
connectorY: number;
}) | null;