-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathtypes.ts
More file actions
170 lines (135 loc) · 5.49 KB
/
types.ts
File metadata and controls
170 lines (135 loc) · 5.49 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
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;
}
/** Event passed to onEditorUpdate callback */
export type SuperDocEditorUpdateEvent = Parameters<NonNullable<SuperDocConstructorConfig['onEditorUpdate']>>[0];
/** Event passed to onTransaction callback */
export type SuperDocTransactionEvent = Parameters<NonNullable<SuperDocConstructorConfig['onTransaction']>>[0];
/** 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'
| '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 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;
}