Skip to content

Commit

Permalink
types(Graph, Cell, Element, Link): add JSON and BaseJSON types
Browse files Browse the repository at this point in the history
  • Loading branch information
zbynekstara committed Jan 10, 2025
1 parent 12b0c32 commit 3ab568a
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions packages/joint-core/types/joint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ export namespace dia {
strict?: boolean;
}

type BaseJSON = {
cells: Array<Element.BaseJSON | Link.BaseJSON>;
[key: string]: any;
}

type JSON = {
cells: Array<Element.JSON | Link.JSON>;
[key: string]: any;
}

type SearchByKey = 'bbox' | PositionName;

interface FindUnderElementOptions extends FindInAreaOptions, FindAtPointOptions {
Expand Down Expand Up @@ -256,9 +266,9 @@ export namespace dia {

getCommonAncestor(...cells: Cell[]): Element | undefined;

toJSON(opt?: { cellAttributes?: dia.Cell.ExportOptions }): any;
toJSON(opt?: { cellAttributes?: dia.Cell.ExportOptions }): Graph.JSON;

fromJSON(json: any, opt?: S): this;
fromJSON(json: Graph.BaseJSON, opt?: S): this;

clear(opt?: { [key: string]: any }): this;

Expand Down Expand Up @@ -343,13 +353,16 @@ export namespace dia {
interface Attributes extends GenericAttributes<Selectors> {
}

type JSON<K extends Selectors = Selectors, T extends GenericAttributes<K> = GenericAttributes<K>> = T & {
type BaseJSON<K extends Selectors = Selectors, T extends GenericAttributes<K> = GenericAttributes<K>> = T & {
[attribute in keyof T]: T[attribute];
} & {
id: ID;
type: string;
};

type JSON<K extends Selectors = Selectors, T extends GenericAttributes<K> = GenericAttributes<K>> = BaseJSON<K, T> & {
id: ID;
};

interface Constructor<T extends mvc.Model> {
new(opt?: { id?: ID, [key: string]: any }): T;
define(type: string, defaults?: any, protoProps?: any, staticProps?: any): dia.Cell.Constructor<T>;
Expand Down Expand Up @@ -560,6 +573,10 @@ export namespace dia {
interface Attributes extends GenericAttributes<Cell.Selectors> {
}

type BaseJSON<K extends Cell.Selectors = Cell.Selectors, T extends GenericAttributes<K> = GenericAttributes<K>> = Cell.BaseJSON<K, T>;

type JSON<K extends Cell.Selectors = Cell.Selectors, T extends GenericAttributes<K> = GenericAttributes<K>> = Cell.JSON<K, T>;

type PortPositionCallback = (ports: Port[], bbox: g.Rect) => dia.Point[];

interface PortPositionJSON {
Expand Down Expand Up @@ -692,12 +709,17 @@ export namespace dia {
priority?: boolean;
}

interface EndJSON extends EndCellArgs {
id?: Cell.ID;
x?: number;
y?: number;
interface EndCellJSON extends EndCellArgs {
id: Cell.ID;
}

interface EndPointJSON extends EndCellArgs {
x: number;
y: number;
}

type EndJSON = EndCellJSON | EndPointJSON;

interface GenericAttributes<T> extends Cell.GenericAttributes<T> {
source?: EndJSON;
target?: EndJSON;
Expand All @@ -721,6 +743,10 @@ export namespace dia {
interface Attributes extends Cell.GenericAttributes<LinkSelectors> {
}

type BaseJSON<K extends LinkSelectors = LinkSelectors, T extends GenericAttributes<K> = GenericAttributes<K>> = Cell.BaseJSON<K, T>;

type JSON<K extends LinkSelectors = LinkSelectors, T extends GenericAttributes<K> = GenericAttributes<K>> = Cell.JSON<K, T>;

interface LabelPosition {
distance?: number; // optional for default labels
offset?: number | { x: number, y: number };
Expand Down

0 comments on commit 3ab568a

Please sign in to comment.