@pexelize/react-editor 1.0.5 → 2.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/dist/index.d.ts CHANGED
@@ -1,264 +1,300 @@
1
1
  import React from 'react';
2
2
 
3
3
  /**
4
- * Pexelize Editor React Component
5
- *
6
- * A React wrapper for the Pexelize Editor SDK.
7
- * SDK is loaded from jsDelivr CDN automatically.
4
+ * Pexelize React Editor Types
5
+ * Minimal type definitions for the React wrapper
8
6
  */
9
-
7
+ type EditorMode = "email" | "web" | "popup" | "document";
8
+ type ThemeMode = "light" | "dark" | "auto" | "pexelize-light" | "pexelize-dark";
9
+ type ViewMode = "desktop" | "tablet" | "mobile";
10
10
  interface DesignJson {
11
11
  body: {
12
- rows: any[];
13
- values: Record<string, any>;
12
+ rows: RowData[];
13
+ values: BodyValues;
14
14
  };
15
15
  schemaVersion?: number;
16
16
  }
17
- interface ExportHtmlData {
18
- html: string;
19
- design: DesignJson;
20
- chunks?: {
21
- css: string;
22
- js: string;
23
- body: string;
17
+ interface BodyValues {
18
+ backgroundColor?: string;
19
+ contentWidth?: string;
20
+ textColor?: string;
21
+ fontFamily?: {
22
+ label: string;
23
+ value: string;
24
24
  };
25
+ linkStyle?: LinkStyle;
26
+ preheaderText?: string;
27
+ [key: string]: unknown;
28
+ }
29
+ interface RowData {
30
+ cells: number[];
31
+ columns: ColumnData[];
32
+ values: RowValues;
33
+ }
34
+ interface RowValues {
35
+ padding?: string;
36
+ backgroundColor?: string;
37
+ [key: string]: unknown;
38
+ }
39
+ interface ColumnData {
40
+ contents: ContentData[];
41
+ values: ColumnValues;
42
+ }
43
+ interface ColumnValues {
44
+ backgroundColor?: string;
45
+ padding?: string;
46
+ [key: string]: unknown;
47
+ }
48
+ interface ContentData {
49
+ type: string;
50
+ values: Record<string, unknown>;
51
+ }
52
+ interface LinkStyle {
53
+ body?: boolean;
54
+ inherit?: boolean;
55
+ linkColor?: string;
56
+ linkHoverColor?: string;
57
+ linkUnderline?: boolean;
58
+ linkHoverUnderline?: boolean;
59
+ }
60
+ interface ModuleData {
61
+ cells: number[];
62
+ columns: ColumnData[];
63
+ values: Record<string, unknown>;
64
+ }
65
+ interface Module {
66
+ /** Unique identifier */
67
+ id: string;
68
+ /** Display name */
69
+ name: string;
70
+ /** Category for grouping */
71
+ category: string;
72
+ /** Module mode - "email" or "web" (editor compatibility) */
73
+ mode: "email" | "web";
74
+ /** Module type - "standard" or "synced" (sync behavior) */
75
+ type: "standard" | "synced";
76
+ /** Module thumbnail URL */
77
+ thumbnail?: string | null;
78
+ /** Module data (row structure) */
79
+ data?: ModuleData | Record<string, unknown>;
25
80
  }
26
81
  interface MergeTag {
27
82
  name: string;
28
83
  value: string;
29
84
  sample?: string;
30
85
  }
31
- interface DisplayCondition {
32
- id: string;
33
- label: string;
34
- description?: string;
35
- condition: Record<string, any>;
86
+ interface MergeTagGroup {
87
+ name: string;
88
+ mergeTags: (MergeTag | MergeTagGroup)[];
89
+ }
90
+ interface SpecialLink {
91
+ name: string;
92
+ href: string;
93
+ target?: "_blank" | "_self" | "_parent" | "_top";
94
+ }
95
+ interface SpecialLinkGroup {
96
+ name: string;
97
+ specialLinks: SpecialLink[];
36
98
  }
37
99
  interface AppearanceConfig {
38
- theme?: 'light' | 'dark' | 'pexelize-light' | 'pexelize-dark';
39
- panels?: {
40
- tools?: {
41
- dock?: 'left' | 'right';
42
- collapsible?: boolean;
43
- };
44
- properties?: {
45
- dock?: 'left' | 'right';
46
- collapsible?: boolean;
100
+ theme?: ThemeMode | object;
101
+ accentColor?: string;
102
+ sidePanel?: {
103
+ tabs?: {
104
+ content?: {
105
+ visible?: boolean;
106
+ };
107
+ modules?: {
108
+ visible?: boolean;
109
+ };
110
+ styles?: {
111
+ visible?: boolean;
112
+ };
47
113
  };
114
+ dock?: "left" | "right";
115
+ width?: number;
116
+ collapsible?: boolean;
48
117
  };
49
- features?: Record<string, boolean>;
50
118
  }
51
119
  interface ToolsConfig {
52
- enabled?: string[];
53
- disabled?: string[];
120
+ [toolName: string]: {
121
+ enabled?: boolean;
122
+ position?: number;
123
+ properties?: Record<string, {
124
+ value?: unknown;
125
+ editable?: boolean;
126
+ }>;
127
+ } | undefined;
128
+ }
129
+ interface ModuleFeaturesConfig {
130
+ /** Enable save row as module button */
131
+ saveRowAsModule?: boolean;
54
132
  }
55
133
  interface FeaturesConfig {
56
134
  preview?: boolean;
57
135
  undoRedo?: boolean;
136
+ responsiveDesign?: boolean;
58
137
  imageEditor?: boolean;
59
- userUploads?: boolean;
60
138
  stockImages?: boolean;
139
+ userUploads?: boolean;
140
+ /** Module features configuration */
141
+ modules?: boolean | ModuleFeaturesConfig;
61
142
  }
62
- interface UserInfo {
63
- id?: string;
64
- name?: string;
65
- email?: string;
66
- }
67
- interface SecurityConfig {
68
- allowedOrigins?: string[];
143
+ interface AIConfig {
144
+ mode?: "pexelize" | "external" | "disabled";
145
+ features?: {
146
+ imageGeneration?: {
147
+ enabled?: boolean;
148
+ };
149
+ altText?: {
150
+ enabled?: boolean;
151
+ };
152
+ smartHeading?: {
153
+ enabled?: boolean;
154
+ };
155
+ smartText?: {
156
+ enabled?: boolean;
157
+ };
158
+ smartButton?: {
159
+ enabled?: boolean;
160
+ };
161
+ imageSearch?: {
162
+ enabled?: boolean;
163
+ };
164
+ copilot?: {
165
+ enabled?: boolean;
166
+ };
167
+ };
69
168
  }
70
- interface EditorState {
71
- isReady: boolean;
72
- isDirty: boolean;
73
- canUndo: boolean;
74
- canRedo: boolean;
169
+ interface ExportHtmlData {
170
+ html: string;
171
+ design: DesignJson;
172
+ chunks?: {
173
+ css: string;
174
+ js: string;
175
+ body: string;
176
+ };
75
177
  }
76
- type DisplayMode = 'email' | 'web' | 'popup' | 'document';
77
- type ThemeMode = 'light' | 'dark' | 'pexelize-light' | 'pexelize-dark';
78
178
  type ImageUploadCallback = (file: File, done: (result: {
79
- progress: number;
80
179
  url?: string;
180
+ error?: string;
81
181
  }) => void) => void;
82
- type LinkClickCallback = (data: {
83
- link: string;
84
- type: string;
85
- }, done: (result: {
86
- link: string;
87
- }) => void) => void;
88
- type SaveCallback = (design: DesignJson, done: (result: {
182
+ interface ModuleSaveData {
183
+ /** Module name (entered by user) */
184
+ name: string;
185
+ /** Module category (entered by user) */
186
+ category: string;
187
+ /** Module type - "standard" or "synced" (selected by user) */
188
+ type: "standard" | "synced";
189
+ /** Module mode - "email" or "web" (determined by editor mode) */
190
+ mode: "email" | "web";
191
+ /** The nested row JSON data with columns and contents */
192
+ data: unknown;
193
+ /** Pre-rendered HTML content */
194
+ html: string;
195
+ /** Schema version of the design */
196
+ schemaVersion: number;
197
+ }
198
+ interface ModuleSaveResult {
199
+ /** Whether the save was successful */
89
200
  success: boolean;
90
- }) => void) => void;
91
- /**
92
- * Props for the PexelizeEditor component
93
- */
94
- interface PexelizeEditorProps {
95
- /** Editor display mode */
96
- displayMode?: DisplayMode;
97
- /** Also accepts editorMode for compatibility */
98
- editorMode?: DisplayMode;
99
- /** Project identifier */
100
- projectId?: number | string;
101
- /** UI language */
201
+ /** Error message if save failed */
202
+ error?: string;
203
+ /** The saved module ID (if applicable) */
204
+ moduleId?: string;
205
+ }
206
+ type ModuleSaveCallback = (data: ModuleSaveData, done?: (result: ModuleSaveResult) => void) => void;
207
+ type EditorEventName = "editor:ready" | "design:loaded" | "design:updated" | "design:saved" | "content:modified" | "content:added" | "content:deleted" | "row:selected" | "row:unselected" | "column:selected" | "column:unselected" | "content:selected" | "content:unselected" | "preview:shown" | "preview:hidden" | "image:uploaded" | "image:error" | "save";
208
+ interface PexelizeConfig {
209
+ containerId: string;
210
+ editorId: number | string;
211
+ apiKey: string;
212
+ templateId?: string;
213
+ design?: DesignJson | null;
214
+ editorMode?: EditorMode;
102
215
  locale?: string;
103
- /** Visual customization */
216
+ mergeTags?: (MergeTag | MergeTagGroup)[];
217
+ specialLinks?: (SpecialLink | SpecialLinkGroup)[];
104
218
  appearance?: AppearanceConfig;
105
- /** Enable/disable tools */
106
219
  tools?: ToolsConfig;
107
- /** Feature toggles */
108
220
  features?: FeaturesConfig;
109
- /** User information */
110
- user?: UserInfo;
111
- /** Security settings */
112
- security?: SecurityConfig;
113
- /** Editor source URL (overrides CDN default) */
114
- editorUrl?: string;
115
- /** SDK CDN URL (overrides default) */
116
- sdkUrl?: string;
117
- /** Minimum height for the editor */
118
- minHeight?: string | number;
119
- /** Initial design to load */
120
- design?: DesignJson;
121
- /** Merge tags for personalization */
122
- mergeTags?: MergeTag[];
123
- /** Display conditions for dynamic content */
124
- displayConditions?: DisplayCondition[];
125
- /** Custom CSS class name */
221
+ ai?: AIConfig;
222
+ /** Modules to display in the modules panel */
223
+ modules?: Module[];
224
+ editor?: {
225
+ contentType?: "page" | "module";
226
+ minRows?: number;
227
+ maxRows?: number | null;
228
+ };
229
+ callbacks?: {
230
+ image?: ImageUploadCallback;
231
+ onModuleSave?: ModuleSaveCallback;
232
+ };
233
+ }
234
+ interface PexelizeSDK {
235
+ init(config: PexelizeConfig): void;
236
+ destroy(): void;
237
+ isReady(): boolean;
238
+ loadDesign(design: DesignJson, options?: {
239
+ preserveHistory?: boolean;
240
+ }): void;
241
+ loadBlank(): void;
242
+ saveDesign(callback: (design: DesignJson) => void): void;
243
+ getDesign(): Promise<DesignJson>;
244
+ exportHtml(callback: (data: ExportHtmlData) => void): void;
245
+ exportHtmlAsync(): Promise<ExportHtmlData>;
246
+ setMergeTags(tags: (MergeTag | MergeTagGroup)[]): void;
247
+ setAppearance(config: AppearanceConfig): void;
248
+ undo(): void;
249
+ redo(): void;
250
+ showPreview(): void;
251
+ hidePreview(): void;
252
+ addEventListener<T = unknown>(event: EditorEventName, callback: (data: T) => void): () => void;
253
+ removeEventListener<T = unknown>(event: EditorEventName, callback: (data: T) => void): void;
254
+ }
255
+
256
+ /**
257
+ * @pexelize/react-editor
258
+ * React wrapper for the Pexelize Editor SDK
259
+ */
260
+
261
+ declare global {
262
+ interface Window {
263
+ pexelize?: PexelizeSDK;
264
+ }
265
+ }
266
+ interface PexelizeEditorRef {
267
+ editor: PexelizeSDK | null;
268
+ isReady: () => boolean;
269
+ }
270
+ type EditorContentType = "page" | "module";
271
+ interface PexelizeEditorProps {
272
+ editorId: number | string;
273
+ apiKey: string;
274
+ templateId?: string;
275
+ design?: DesignJson | ModuleData | null;
276
+ editorMode?: EditorMode;
277
+ contentType?: EditorContentType;
278
+ ai?: PexelizeConfig["ai"];
279
+ height?: string | number;
280
+ options?: Omit<PexelizeConfig, "containerId" | "editorId" | "apiKey">;
126
281
  className?: string;
127
- /** Inline styles */
128
282
  style?: React.CSSProperties;
129
- /** Height of the editor */
130
- height?: string | number;
131
- /** Called when the editor is ready */
132
- onReady?: () => void;
133
- /** Called when the design is loaded */
134
- onLoad?: (data: {
135
- design: DesignJson;
136
- }) => void;
137
- /** Called when the design changes */
283
+ minHeight?: string | number;
284
+ onReady?: (editor: PexelizeSDK) => void;
285
+ onLoad?: () => void;
138
286
  onChange?: (data: {
139
287
  design: DesignJson;
140
- changes?: unknown;
141
- }) => void;
142
- /** Called when content is modified */
143
- onContentModified?: (data: {
144
288
  type: string;
145
- value: unknown;
146
- element: unknown;
147
289
  }) => void;
148
- /** Called when an element is selected */
149
- onSelect?: (data: {
150
- element: unknown;
151
- type: string;
152
- }) => void;
153
- /** Called when an element is deselected */
154
- onDeselect?: () => void;
155
- /** Image upload handler */
156
- onImage?: ImageUploadCallback;
157
- /** Link click handler */
158
- onLinkClick?: LinkClickCallback;
159
- /** Save handler */
160
- onSave?: SaveCallback;
290
+ onError?: (error: Error) => void;
161
291
  }
162
- /**
163
- * Ref handle for the PexelizeEditor component
164
- */
165
- interface PexelizeEditorRef {
166
- /** Load a design */
167
- loadDesign: (design: DesignJson) => void;
168
- /** Load a blank design */
169
- loadBlank: () => void;
170
- /** Save/get the current design */
171
- saveDesign: (callback: (design: DesignJson) => void) => void;
172
- /** Get the current design (Promise-based) */
173
- getDesign: () => Promise<DesignJson>;
174
- /** Export as HTML */
175
- exportHtml: (callback: (data: ExportHtmlData) => void) => void;
176
- /** Export as HTML (Promise-based) */
177
- exportHtmlAsync: () => Promise<ExportHtmlData>;
178
- /** Trigger save */
179
- save: () => void;
180
- /** Perform undo */
181
- undo: () => void;
182
- /** Perform redo */
183
- redo: () => void;
184
- /** Get editor state */
185
- getState: () => Promise<EditorState>;
186
- /** Check if editor is ready */
187
- isReady: () => boolean;
188
- /** Access the raw SDK instance */
189
- getSdk: () => any;
190
- }
191
- /**
192
- * PexelizeEditor React Component
193
- *
194
- * @example
195
- * ```tsx
196
- * import { PexelizeEditor, PexelizeEditorRef } from '@pexelize/react-editor';
197
- *
198
- * function MyEditor() {
199
- * const editorRef = useRef<PexelizeEditorRef>(null);
200
- *
201
- * const handleSave = () => {
202
- * editorRef.current?.saveDesign((design) => {
203
- * console.log('Design:', design);
204
- * });
205
- * };
206
- *
207
- * return (
208
- * <div>
209
- * <button onClick={handleSave}>Save</button>
210
- * <PexelizeEditor
211
- * ref={editorRef}
212
- * editorMode="email"
213
- * onReady={() => console.log('Ready!')}
214
- * onChange={({ design }) => console.log('Changed:', design)}
215
- * />
216
- * </div>
217
- * );
218
- * }
219
- * ```
220
- */
221
292
  declare const PexelizeEditor: React.ForwardRefExoticComponent<PexelizeEditorProps & React.RefAttributes<PexelizeEditorRef>>;
222
- interface UsePexelizeSDKConfig {
223
- containerId: string;
224
- editorMode?: DisplayMode;
225
- displayMode?: DisplayMode;
226
- [key: string]: any;
227
- }
228
- /**
229
- * Hook to use the Pexelize SDK directly
230
- *
231
- * @example
232
- * ```tsx
233
- * function MyComponent() {
234
- * const { sdk, isReady, error } = usePexelizeSDK({
235
- * containerId: 'my-editor',
236
- * editorMode: 'email',
237
- * });
238
- *
239
- * const handleExport = () => {
240
- * if (isReady && sdk) {
241
- * sdk.exportHtml((data) => console.log(data.html));
242
- * }
243
- * };
244
- *
245
- * return (
246
- * <div>
247
- * <div id="my-editor" style={{ height: '600px' }} />
248
- * <button onClick={handleExport} disabled={!isReady}>Export</button>
249
- * </div>
250
- * );
251
- * }
252
- * ```
253
- */
254
- declare function usePexelizeSDK(config: UsePexelizeSDKConfig): {
255
- sdk: any;
293
+ declare function usePexelizeEditor(): {
294
+ ref: React.RefObject<PexelizeEditorRef>;
295
+ editor: PexelizeSDK | null;
256
296
  isReady: boolean;
257
- isLoading: boolean;
258
- error: string | null;
259
297
  };
260
298
 
261
- declare const PEXELIZE_SDK_CDN = "https://sdk.pexelize.com/latest/pexelize-sdk.min.js";
262
-
263
- export { PEXELIZE_SDK_CDN, PexelizeEditor, PexelizeEditor as default, usePexelizeSDK };
264
- export type { AppearanceConfig, DesignJson, DisplayCondition, DisplayMode, EditorState, ExportHtmlData, FeaturesConfig, ImageUploadCallback, LinkClickCallback, MergeTag, PexelizeEditorProps, PexelizeEditorRef, SaveCallback, SecurityConfig, ThemeMode, ToolsConfig, UsePexelizeSDKConfig, UserInfo };
299
+ export { PexelizeEditor, PexelizeEditor as default, usePexelizeEditor };
300
+ export type { AIConfig, AppearanceConfig, BodyValues, ColumnData, ColumnValues, ContentData, DesignJson, EditorContentType, EditorEventName, EditorMode, ExportHtmlData, FeaturesConfig, ImageUploadCallback, LinkStyle, MergeTag, MergeTagGroup, Module, ModuleData, ModuleFeaturesConfig, ModuleSaveCallback, ModuleSaveData, ModuleSaveResult, PexelizeConfig, PexelizeEditorProps, PexelizeEditorRef, PexelizeSDK, RowData, RowValues, SpecialLink, SpecialLinkGroup, ThemeMode, ToolsConfig, ViewMode };