-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathtypes.ts
More file actions
203 lines (166 loc) · 6.89 KB
/
types.ts
File metadata and controls
203 lines (166 loc) · 6.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import type { CSSProperties, ReactNode } from 'react';
import type { SuperDoc, Editor } from 'superdoc';
/**
* Types for @superdoc-dev/react
*
* Core types are extracted from the SuperDoc constructor parameter type,
* ensuring they stay in sync with the superdoc package.
*/
// =============================================================================
// Extract types from SuperDoc constructor (single source of truth)
// =============================================================================
/** SuperDoc constructor config - extracted from superdoc package */
type SuperDocConstructorConfig = ConstructorParameters<typeof SuperDoc>[0];
/** SuperDoc instance type - from superdoc package */
export type SuperDocInstance = InstanceType<typeof SuperDoc>;
/** Document mode - extracted from Config.documentMode */
export type DocumentMode = NonNullable<SuperDocConstructorConfig['documentMode']>;
/** User role - extracted from Config.role */
export type UserRole = NonNullable<SuperDocConstructorConfig['role']>;
/** User object - extracted from Config.user */
export type SuperDocUser = NonNullable<SuperDocConstructorConfig['user']>;
/** Modules configuration - extracted from Config.modules */
export type SuperDocModules = NonNullable<SuperDocConstructorConfig['modules']>;
/** Full SuperDoc config - extracted from constructor */
export type SuperDocConfig = SuperDocConstructorConfig;
// =============================================================================
// Callback Event Types
// =============================================================================
// Re-export Editor type from superdoc
export type { Editor } from 'superdoc';
/** Event passed to onReady callback */
export interface SuperDocReadyEvent {
superdoc: SuperDocInstance;
}
/** Event passed to onEditorCreate callback */
export interface SuperDocEditorCreateEvent {
editor: Editor;
}
/** Surface where an editor event originated. */
export type EditorSurface = 'body' | 'header' | 'footer';
/** Event passed to onEditorUpdate callback. Mirrors superdoc's EditorUpdateEvent. */
export interface SuperDocEditorUpdateEvent {
/** The primary editor associated with the update. For header/footer edits, this is the main body editor. */
editor: Editor;
/** The editor instance that emitted the update. For body edits, this matches `editor`. */
sourceEditor: Editor;
/** The surface where the edit originated. */
surface: EditorSurface;
/** Relationship ID for header/footer edits. */
headerId?: string | null;
/** Header/footer variant (`default`, `first`, `even`, `odd`) when available. */
sectionType?: string | null;
}
/** Event passed to onTransaction callback. Mirrors superdoc's EditorTransactionEvent. */
export interface SuperDocTransactionEvent {
/** The primary editor associated with the transaction. For header/footer edits, this is the main body editor. */
editor: Editor;
/** The editor instance that emitted the transaction. For body edits, this matches `editor`. */
sourceEditor: Editor;
/** The ProseMirror transaction or transaction-like payload emitted by the source editor. */
transaction: any;
/** Time spent applying the transaction, in milliseconds. */
duration?: number;
/** The surface where the transaction originated. */
surface: EditorSurface;
/** Relationship ID for header/footer edits. */
headerId?: string | null;
/** Header/footer variant (`default`, `first`, `even`, `odd`) when available. */
sectionType?: string | null;
}
/** Event passed to onContentError callback */
export interface SuperDocContentErrorEvent {
error: Error;
editor: Editor;
documentId: string;
file: File;
}
/** Event passed to onException callback */
export interface SuperDocExceptionEvent {
error: Error;
editor?: Editor | null;
code?: string;
}
// =============================================================================
// React Component Types
// =============================================================================
/**
* Props managed internally by the React component (not exposed to users).
* - selector: managed by component (creates internal container)
*/
type InternalProps = 'selector';
/**
* Props that are required in core but should be optional in React.
* - documentMode: defaults to 'editing' if not provided
*/
type OptionalInReact = 'documentMode';
/**
* Callback props that are explicitly typed in CallbackProps.
* These are excluded from SuperDocConfig to avoid type conflicts.
*/
type ExplicitCallbackProps =
| 'onReady'
| 'onEditorCreate'
| 'onEditorDestroy'
| 'onEditorUpdate'
| 'onTransaction'
| 'onContentError'
| 'onException';
/**
* Explicitly typed callback props to ensure proper TypeScript inference.
* These override any loosely-typed callbacks from SuperDocConfig.
*/
export interface CallbackProps {
/** Callback when SuperDoc is ready */
onReady?: (event: SuperDocReadyEvent) => void;
/** Callback after an editor is created */
onEditorCreate?: (event: SuperDocEditorCreateEvent) => void;
/** Callback when editor is destroyed */
onEditorDestroy?: () => void;
/** Callback when document content is updated */
onEditorUpdate?: (event: SuperDocEditorUpdateEvent) => void;
/** Callback when a transaction is emitted */
onTransaction?: (event: SuperDocTransactionEvent) => void;
/** Callback when there is a content parsing error */
onContentError?: (event: SuperDocContentErrorEvent) => void;
/** Callback when an exception is thrown */
onException?: (event: SuperDocExceptionEvent) => void;
}
/**
* React-specific props added on top of SuperDocConfig.
*/
interface ReactProps {
/** Optional ID for the editor container. Auto-generated if not provided. */
id?: string;
/** Render function for loading state */
renderLoading?: () => ReactNode;
/** Hide the toolbar container. When true, no toolbar is rendered. @default false */
hideToolbar?: boolean;
/** Enable contained mode for fixed-height container embedding. When true, SuperDoc
* fits within its parent's height and scrolls internally. @default false */
contained?: boolean;
/** Additional CSS class name for the wrapper element */
className?: string;
/** Additional inline styles for the wrapper element */
style?: CSSProperties;
}
/**
* Props for SuperDocEditor component.
*
* Extends SuperDocConfig (minus internal props) with React-specific additions.
* When new props are added to SuperDoc core, they're automatically available here.
*
* Callback props are explicitly typed to ensure proper TypeScript inference.
*/
export interface SuperDocEditorProps
extends Omit<SuperDocConfig, InternalProps | OptionalInReact | ExplicitCallbackProps>,
Partial<Pick<SuperDocConfig, OptionalInReact>>,
CallbackProps,
ReactProps {}
/**
* Ref interface for SuperDocEditor component
*/
export interface SuperDocRef {
/** Get the underlying SuperDoc instance. Returns null if not yet initialized. */
getInstance(): SuperDocInstance | null;
}