@glyphlab/diagram-react 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts ADDED
@@ -0,0 +1,192 @@
1
+ import { DiagramController, Size, Bounds, Selection, NodeHighlight, EdgeHighlight, Highlights, LinkStatus, EdgeState, GroupState, MetaState, NodeState, DiagramFile } from '@glyphlab/diagram-core';
2
+ export { COLOR_PRESETS, colorCss, colorLabel } from '@glyphlab/diagram-core';
3
+ import * as react from 'react';
4
+ import { CSSProperties, ReactNode } from 'react';
5
+ import { StoreApi } from 'zustand/vanilla';
6
+
7
+ declare function addNodeAt(controller: DiagramController, x: number, y: number, laneId?: string, onError?: (message: string) => void): string | undefined;
8
+ declare function addGroupAt(controller: DiagramController, x: number, y: number): string | undefined;
9
+ declare function deleteNode(controller: DiagramController, id: string): void;
10
+ declare function deleteGroup(controller: DiagramController, id: string): void;
11
+ declare function deleteEdge(controller: DiagramController, id: string): void;
12
+
13
+ declare function ArrowHeads({ id, colors }: {
14
+ id: string;
15
+ colors: (string | undefined)[];
16
+ }): react.JSX.Element;
17
+
18
+ declare const MIN_SCALE = 0.2;
19
+ declare const MAX_SCALE = 2;
20
+ interface ViewportState {
21
+ x: number;
22
+ y: number;
23
+ scale: number;
24
+ panning: boolean;
25
+ setPanning: (panning: boolean) => void;
26
+ setPosition: (x: number, y: number) => void;
27
+ panBy: (dx: number, dy: number) => void;
28
+ zoomAround: (factor: number, cx: number, cy: number) => void;
29
+ fit: (size: Size, bounds: Bounds) => void;
30
+ reset: (size: Size, bounds: Bounds) => void;
31
+ }
32
+ interface SelectionState {
33
+ selection: Selection | null;
34
+ select: (selection: Selection) => void;
35
+ clearSelection: () => void;
36
+ }
37
+ interface EditState {
38
+ node: {
39
+ id: string;
40
+ field: 'title' | 'body';
41
+ } | null;
42
+ edge: string | null;
43
+ group: string | null;
44
+ editNode: (id: string, field: 'title' | 'body') => void;
45
+ editEdge: (id: string) => void;
46
+ editGroup: (id: string) => void;
47
+ end: () => void;
48
+ }
49
+ interface ConnectState {
50
+ hovered: string | null;
51
+ source: string | null;
52
+ side: 'n' | 'e' | 's' | 'w';
53
+ cursor: {
54
+ x: number;
55
+ y: number;
56
+ } | null;
57
+ target: string | null;
58
+ hover: (id: string) => void;
59
+ leave: () => void;
60
+ start: (source: string, side: ConnectState['side'], cursor: {
61
+ x: number;
62
+ y: number;
63
+ }) => void;
64
+ move: (cursor: {
65
+ x: number;
66
+ y: number;
67
+ }, target: string | null) => void;
68
+ end: () => void;
69
+ }
70
+ interface HighlightState {
71
+ nodes: Record<string, NodeHighlight>;
72
+ edges: Record<string, EdgeHighlight>;
73
+ dimmed: boolean;
74
+ set: (highlights: Highlights) => void;
75
+ clear: () => void;
76
+ }
77
+ interface CanvasUi {
78
+ viewport: StoreApi<ViewportState>;
79
+ selection: StoreApi<SelectionState>;
80
+ edit: StoreApi<EditState>;
81
+ connect: StoreApi<ConnectState>;
82
+ highlight: StoreApi<HighlightState>;
83
+ }
84
+ declare const createCanvasUi: () => CanvasUi;
85
+
86
+ interface DiagramInstance {
87
+ readonly uid: string;
88
+ readonly controller: DiagramController;
89
+ readonly ui: CanvasUi;
90
+ readonly surface: {
91
+ el: HTMLElement | null;
92
+ };
93
+ dispose(): void;
94
+ }
95
+ declare function createDiagramInstance(controller: DiagramController): DiagramInstance;
96
+
97
+ declare function connectNodes(instance: DiagramInstance, from: string, to: string): void;
98
+
99
+ declare function layerStyle(color: string | undefined): CSSProperties;
100
+ declare function edgeStyle(color: string | undefined): CSSProperties | undefined;
101
+
102
+ declare function ColorControl(): react.JSX.Element | null;
103
+
104
+ interface NodeLinkState {
105
+ status: LinkStatus;
106
+ detail?: string;
107
+ count?: number;
108
+ }
109
+ declare function LinkBadge({ title, state, onOpen }: {
110
+ title: string;
111
+ state: NodeLinkState | undefined;
112
+ onOpen?: () => void;
113
+ }): react.JSX.Element | null;
114
+
115
+ interface DiagramSlots {
116
+ renderMarkdown?: (source: string) => ReactNode;
117
+ openNodeContent?: (id: string, section?: 'decisions' | 'code') => void;
118
+ useLinkState?: (id: string) => NodeLinkState | undefined;
119
+ }
120
+ declare const useDiagram: () => DiagramInstance;
121
+ declare const useSlots: () => DiagramSlots;
122
+ declare const useNodes: <T>(selector: (state: NodeState) => T) => T;
123
+ declare const useEdges: <T>(selector: (state: EdgeState) => T) => T;
124
+ declare const useGroups: <T>(selector: (state: GroupState) => T) => T;
125
+ declare const useMeta: <T>(selector: (state: MetaState) => T) => T;
126
+ declare const useViewport: <T>(selector: (state: ViewportState) => T) => T;
127
+ declare const useSelection: <T>(selector: (state: SelectionState) => T) => T;
128
+ declare const useEditing: <T>(selector: (state: EditState) => T) => T;
129
+ declare const useConnecting: <T>(selector: (state: ConnectState) => T) => T;
130
+ declare const useHighlights: <T>(selector: (state: HighlightState) => T) => T;
131
+ declare function bindStore<S>(api: StoreApi<S>): {
132
+ (): S;
133
+ <T>(selector: (state: S) => T): T;
134
+ } & StoreApi<S>;
135
+
136
+ declare function DiagramProvider({ instance, slots, children }: {
137
+ instance: DiagramInstance;
138
+ slots?: DiagramSlots;
139
+ children: ReactNode;
140
+ }): react.JSX.Element;
141
+
142
+ declare function DiagramCanvas({ title, designKey, empty: emptyMessage }: {
143
+ title: string;
144
+ designKey?: string | number;
145
+ empty?: ReactNode;
146
+ }): react.JSX.Element;
147
+
148
+ declare const DiagramEdge: react.MemoExoticComponent<({ id }: {
149
+ id: string;
150
+ }) => react.JSX.Element | null>;
151
+
152
+ declare const DiagramGroup: react.MemoExoticComponent<({ id }: {
153
+ id: string;
154
+ }) => react.JSX.Element | null>;
155
+
156
+ declare const DiagramNode: react.MemoExoticComponent<({ id }: {
157
+ id: string;
158
+ }) => react.JSX.Element | null>;
159
+
160
+ declare function DiagramToolbar({ title }: {
161
+ title: string;
162
+ }): react.JSX.Element;
163
+
164
+ declare function EdgeStyleControl(): react.JSX.Element | null;
165
+
166
+ interface DiagramViewerConfig {
167
+ diagram: DiagramFile;
168
+ highlights?: Highlights;
169
+ focus?: boolean;
170
+ renderMarkdown?: (source: string) => ReactNode;
171
+ openNodeContent?: (id: string, section?: 'decisions' | 'code') => void;
172
+ linkStates?: Record<string, NodeLinkState>;
173
+ movableNodes?: boolean;
174
+ }
175
+ declare function DiagramViewer({ config }: {
176
+ config: DiagramViewerConfig;
177
+ }): react.JSX.Element;
178
+
179
+ declare const EdgeLabel: react.MemoExoticComponent<({ id }: {
180
+ id: string;
181
+ }) => react.JSX.Element | null>;
182
+
183
+ interface ZoomControlsConfig {
184
+ onZoom: (factor: number) => void;
185
+ onFit: () => void;
186
+ }
187
+ declare function ZoomControls({ config }: {
188
+ config: ZoomControlsConfig;
189
+ }): react.JSX.Element;
190
+
191
+ export { ArrowHeads, ColorControl, DiagramCanvas, DiagramEdge, DiagramGroup, DiagramNode, DiagramProvider, DiagramToolbar, DiagramViewer, EdgeLabel, EdgeStyleControl, LinkBadge, MAX_SCALE, MIN_SCALE, ZoomControls, addGroupAt, addNodeAt, bindStore, connectNodes, createCanvasUi, createDiagramInstance, deleteEdge, deleteGroup, deleteNode, edgeStyle, layerStyle, useConnecting, useDiagram, useEdges, useEditing, useGroups, useHighlights, useMeta, useNodes, useSelection, useSlots, useViewport };
192
+ export type { CanvasUi, ConnectState, DiagramInstance, DiagramSlots, DiagramViewerConfig, EditState, HighlightState, NodeLinkState, SelectionState, ViewportState };