@pexelize/react-editor 1.0.4 → 2.0.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,250 @@
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>;
25
64
  }
26
65
  interface MergeTag {
27
66
  name: string;
28
67
  value: string;
29
68
  sample?: string;
30
69
  }
31
- interface DisplayCondition {
32
- id: string;
33
- label: string;
34
- description?: string;
35
- condition: Record<string, any>;
70
+ interface MergeTagGroup {
71
+ name: string;
72
+ mergeTags: (MergeTag | MergeTagGroup)[];
73
+ }
74
+ interface SpecialLink {
75
+ name: string;
76
+ href: string;
77
+ target?: "_blank" | "_self" | "_parent" | "_top";
78
+ }
79
+ interface SpecialLinkGroup {
80
+ name: string;
81
+ specialLinks: SpecialLink[];
36
82
  }
37
83
  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;
84
+ theme?: ThemeMode | object;
85
+ accentColor?: string;
86
+ sidePanel?: {
87
+ tabs?: {
88
+ content?: {
89
+ visible?: boolean;
90
+ };
91
+ modules?: {
92
+ visible?: boolean;
93
+ };
94
+ styles?: {
95
+ visible?: boolean;
96
+ };
47
97
  };
98
+ dock?: "left" | "right";
99
+ width?: number;
100
+ collapsible?: boolean;
48
101
  };
49
- features?: Record<string, boolean>;
50
102
  }
51
103
  interface ToolsConfig {
52
- enabled?: string[];
53
- disabled?: string[];
104
+ [toolName: string]: {
105
+ enabled?: boolean;
106
+ position?: number;
107
+ properties?: Record<string, {
108
+ value?: unknown;
109
+ editable?: boolean;
110
+ }>;
111
+ } | undefined;
54
112
  }
55
113
  interface FeaturesConfig {
56
114
  preview?: boolean;
57
115
  undoRedo?: boolean;
116
+ responsiveDesign?: boolean;
58
117
  imageEditor?: boolean;
59
- userUploads?: boolean;
60
118
  stockImages?: boolean;
119
+ userUploads?: boolean;
61
120
  }
62
- interface UserInfo {
63
- id?: string;
64
- name?: string;
65
- email?: string;
66
- }
67
- interface SecurityConfig {
68
- allowedOrigins?: string[];
121
+ interface AIConfig {
122
+ mode?: "pexelize" | "external" | "disabled";
123
+ features?: {
124
+ imageGeneration?: {
125
+ enabled?: boolean;
126
+ };
127
+ altText?: {
128
+ enabled?: boolean;
129
+ };
130
+ smartHeading?: {
131
+ enabled?: boolean;
132
+ };
133
+ smartText?: {
134
+ enabled?: boolean;
135
+ };
136
+ smartButton?: {
137
+ enabled?: boolean;
138
+ };
139
+ imageSearch?: {
140
+ enabled?: boolean;
141
+ };
142
+ copilot?: {
143
+ enabled?: boolean;
144
+ };
145
+ };
69
146
  }
70
- interface EditorState {
71
- isReady: boolean;
72
- isDirty: boolean;
73
- canUndo: boolean;
74
- canRedo: boolean;
147
+ interface ExportHtmlData {
148
+ html: string;
149
+ design: DesignJson;
150
+ chunks?: {
151
+ css: string;
152
+ js: string;
153
+ body: string;
154
+ };
75
155
  }
76
- type DisplayMode = 'email' | 'web' | 'popup' | 'document';
77
- type ThemeMode = 'light' | 'dark' | 'pexelize-light' | 'pexelize-dark';
78
156
  type ImageUploadCallback = (file: File, done: (result: {
79
- progress: number;
80
157
  url?: string;
158
+ error?: string;
81
159
  }) => 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: {
89
- 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 */
160
+ 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";
161
+ interface PexelizeConfig {
162
+ containerId: string;
163
+ editorId: number | string;
164
+ apiKey: string;
165
+ templateId?: string;
166
+ design?: DesignJson | null;
167
+ editorMode?: EditorMode;
102
168
  locale?: string;
103
- /** Visual customization */
169
+ mergeTags?: (MergeTag | MergeTagGroup)[];
170
+ specialLinks?: (SpecialLink | SpecialLinkGroup)[];
104
171
  appearance?: AppearanceConfig;
105
- /** Enable/disable tools */
106
172
  tools?: ToolsConfig;
107
- /** Feature toggles */
108
173
  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 */
174
+ ai?: AIConfig;
175
+ editor?: {
176
+ contentType?: "page" | "module";
177
+ minRows?: number;
178
+ maxRows?: number | null;
179
+ };
180
+ callbacks?: {
181
+ image?: ImageUploadCallback;
182
+ };
183
+ }
184
+ interface PexelizeSDK {
185
+ init(config: PexelizeConfig): void;
186
+ destroy(): void;
187
+ isReady(): boolean;
188
+ loadDesign(design: DesignJson, options?: {
189
+ preserveHistory?: boolean;
190
+ }): void;
191
+ loadBlank(): void;
192
+ saveDesign(callback: (design: DesignJson) => void): void;
193
+ getDesign(): Promise<DesignJson>;
194
+ exportHtml(callback: (data: ExportHtmlData) => void): void;
195
+ exportHtmlAsync(): Promise<ExportHtmlData>;
196
+ setMergeTags(tags: (MergeTag | MergeTagGroup)[]): void;
197
+ setAppearance(config: AppearanceConfig): void;
198
+ undo(): void;
199
+ redo(): void;
200
+ showPreview(): void;
201
+ hidePreview(): void;
202
+ addEventListener<T = unknown>(event: EditorEventName, callback: (data: T) => void): () => void;
203
+ removeEventListener<T = unknown>(event: EditorEventName, callback: (data: T) => void): void;
204
+ }
205
+
206
+ /**
207
+ * @pexelize/react-editor
208
+ * React wrapper for the Pexelize Editor SDK
209
+ */
210
+
211
+ declare global {
212
+ interface Window {
213
+ pexelize?: PexelizeSDK;
214
+ }
215
+ }
216
+ interface PexelizeEditorRef {
217
+ editor: PexelizeSDK | null;
218
+ isReady: () => boolean;
219
+ }
220
+ type EditorContentType = "page" | "module";
221
+ interface PexelizeEditorProps {
222
+ editorId: number | string;
223
+ apiKey: string;
224
+ templateId?: string;
225
+ design?: DesignJson | ModuleData | null;
226
+ editorMode?: EditorMode;
227
+ contentType?: EditorContentType;
228
+ ai?: PexelizeConfig["ai"];
229
+ height?: string | number;
230
+ options?: Omit<PexelizeConfig, "containerId" | "editorId" | "apiKey">;
126
231
  className?: string;
127
- /** Inline styles */
128
232
  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 */
233
+ minHeight?: string | number;
234
+ onReady?: (editor: PexelizeSDK) => void;
235
+ onLoad?: () => void;
138
236
  onChange?: (data: {
139
237
  design: DesignJson;
140
- changes?: unknown;
141
- }) => void;
142
- /** Called when content is modified */
143
- onContentModified?: (data: {
144
- type: string;
145
- value: unknown;
146
- element: unknown;
147
- }) => void;
148
- /** Called when an element is selected */
149
- onSelect?: (data: {
150
- element: unknown;
151
238
  type: string;
152
239
  }) => 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;
161
- }
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;
240
+ onError?: (error: Error) => void;
190
241
  }
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
242
  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;
243
+ declare function usePexelizeEditor(): {
244
+ ref: React.RefObject<PexelizeEditorRef>;
245
+ editor: PexelizeSDK | null;
256
246
  isReady: boolean;
257
- isLoading: boolean;
258
- error: string | null;
259
247
  };
260
248
 
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 };
249
+ export { PexelizeEditor, PexelizeEditor as default, usePexelizeEditor };
250
+ export type { AIConfig, AppearanceConfig, BodyValues, ColumnData, ColumnValues, ContentData, DesignJson, EditorContentType, EditorEventName, EditorMode, ExportHtmlData, FeaturesConfig, ImageUploadCallback, LinkStyle, MergeTag, MergeTagGroup, ModuleData, PexelizeConfig, PexelizeEditorProps, PexelizeEditorRef, PexelizeSDK, RowData, RowValues, SpecialLink, SpecialLinkGroup, ThemeMode, ToolsConfig, ViewMode };