@topol.io/editor 1.0.0-alpha.1 → 1.0.0-alpha.10

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.
Files changed (41) hide show
  1. package/README.md +150 -101
  2. package/dist/topol-plugin.es.js +131 -190
  3. package/dist/topol-plugin.umd.cjs +1 -0
  4. package/dist/types/src/core/script-loader.d.ts +15 -0
  5. package/dist/types/src/email-editor/constants.d.ts +3 -3
  6. package/dist/types/src/email-editor/index.d.ts +15 -90
  7. package/dist/types/src/landing-page-editor/index.d.ts +18 -6
  8. package/dist/types/src/landing-page-editor/schemas/contentBlock/contentBlockScheme.d.ts +1 -1
  9. package/dist/types/src/landing-page-editor/schemas/openAI/openAISchema.d.ts +1 -2
  10. package/dist/types/src/landing-page-editor/schemas/pluginOptions/pluginOptionsSchema.d.ts +89 -0
  11. package/dist/types/src/landing-page-editor/schemas/premadeBlock/premadeBlockSchema.d.ts +816 -816
  12. package/dist/types/src/landing-page-editor/schemas/savedBlock/savedBlockApiSchema.d.ts +612 -612
  13. package/dist/types/src/landing-page-editor/schemas/savedBlock/savedBlockSchema.d.ts +816 -816
  14. package/dist/types/src/landing-page-editor/schemas/template/blocks/buttonBlockSchema.d.ts +2 -2
  15. package/dist/types/src/landing-page-editor/schemas/template/blocks/dividerBlockSchema.d.ts +2 -2
  16. package/dist/types/src/landing-page-editor/schemas/template/blocks/imageAnGifBlockSchema.d.ts +6 -6
  17. package/dist/types/src/landing-page-editor/schemas/template/blocks/socialBlockSchema.d.ts +2 -2
  18. package/dist/types/src/landing-page-editor/schemas/template/blocks/spacerBlockSchema.d.ts +2 -2
  19. package/dist/types/src/landing-page-editor/schemas/template/structure/blockSchema.d.ts +92 -92
  20. package/dist/types/src/landing-page-editor/schemas/template/structure/columnSchema.d.ts +94 -94
  21. package/dist/types/src/landing-page-editor/schemas/template/structure/sectionSchema.d.ts +204 -204
  22. package/dist/types/src/landing-page-editor/schemas/templateSchema.d.ts +804 -804
  23. package/dist/types/src/main.d.ts +14 -68
  24. package/dist/types/types/API/API.d.ts +8 -7
  25. package/dist/types/types/Auth/INonceAuthCallbacks.d.ts +9 -0
  26. package/dist/types/types/Callbacks/ICallbackPayloads.d.ts +20 -17
  27. package/dist/types/types/Callbacks/IEmailCallbacks.d.ts +65 -104
  28. package/dist/types/types/Cloud/ICloudOptions.d.ts +32 -0
  29. package/dist/types/types/ContentBlock/IContentBlockOptions.d.ts +1 -1
  30. package/dist/types/types/Countdown/ICountdownOptions.d.ts +48 -0
  31. package/dist/types/types/IEmailConfig.d.ts +199 -0
  32. package/dist/types/types/IEmailEditorInstance.d.ts +54 -0
  33. package/dist/types/types/ITopolOptions.d.ts +4 -120
  34. package/dist/types/types/ITopolPlugin.d.ts +2 -37
  35. package/dist/types/types/Language/Language.d.ts +6 -1
  36. package/dist/types/types/SavedBlock/ISavedBlock.d.ts +2 -6
  37. package/dist/types/types/Sections/ISections.d.ts +30 -0
  38. package/dist/types/types/landing-page/ILandingPageEditorInstance.d.ts +8 -4
  39. package/dist/types/types/landing-page/ILandingPageOptions.d.ts +96 -58
  40. package/package.json +10 -13
  41. package/dist/topol-plugin.umd.js +0 -1
@@ -5,3 +5,18 @@
5
5
  * @returns Promise that resolves when script is loaded
6
6
  */
7
7
  export declare function loadScriptWithFallback(url: string, fallbackUrl?: string): Promise<void>;
8
+ /**
9
+ * Loads a script at most once per page.
10
+ *
11
+ * - If `isReady()` already reports the global the script defines, resolves immediately
12
+ * without touching the DOM (the script was loaded by a previous init() call or by the host page).
13
+ * - If a load for the same URL is already in flight, returns the same promise so concurrent
14
+ * init() calls (e.g. React StrictMode double-invoking effects) share one `<script>` tag.
15
+ * - If the host page already has a `<script src="url">` tag that hasn't finished loading,
16
+ * waits for it instead of injecting a duplicate.
17
+ * - A failed load is not cached, so the next call retries.
18
+ *
19
+ * @param url - Script URL
20
+ * @param isReady - Returns true once the global the script defines is available
21
+ */
22
+ export declare function loadScriptOnce(url: string, isReady: () => boolean): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  export declare const EMAIL_EDITOR_URLS: {
2
- readonly production: string;
3
- readonly dev: string;
4
- readonly staging: string;
2
+ readonly production: any;
3
+ readonly dev: any;
4
+ readonly staging: any;
5
5
  };
6
6
  export declare const EMAIL_EDITOR_PREVIEW_URL_PATTERN = "https://d10h8ga60f7b91.cloudfront.net/preview-app-{stage}/loader/build.js";
7
7
  export declare const EMAIL_EDITOR_HTML_ID = "topol-editor";
@@ -1,97 +1,22 @@
1
1
  import type ITopolOptions from "../../types/ITopolOptions";
2
- import type ITopolPlugin from "../../types/ITopolPlugin";
3
- import type INotification from "../../types/Notification/INotification";
4
- import type ISavedBlock from "../../types/SavedBlock/ISavedBlock";
5
- import { Stage } from "../../types/Stage";
2
+ import type IEmailEditorInstance from "../../types/IEmailEditorInstance";
3
+ import type { Stage } from "../../types/Stage";
4
+ export interface IEmailEditorPluginOptions {
5
+ stage?: Stage;
6
+ /** Explicit v4 loader URL, e.g. a deployed preview or local build. One URL per page; never falls back on failure. */
7
+ loaderUrl?: string;
8
+ }
9
+ type IRawEmailEditorInstance = Omit<IEmailEditorInstance, "destroy"> & {
10
+ close(): Promise<void>;
11
+ };
12
+ type IEmailEditorFactory = (options: ITopolOptions) => IRawEmailEditorInstance;
6
13
  declare global {
7
14
  interface Window {
8
- TopolPlugin: ITopolPlugin;
15
+ TopolEmailEditor: IEmailEditorFactory;
9
16
  }
10
17
  }
11
- export interface EmailEditorPluginOptions {
12
- stage?: Stage;
13
- }
14
- /**
15
- * Email Editor - Create rich email templates with drag-and-drop editing.
16
- *
17
- * This is the main Email Editor integration that loads the Topol Email Editor
18
- * into your application.
19
- *
20
- * @example
21
- * ```typescript
22
- * import { EmailEditor } from '@topol.io/editor';
23
- *
24
- * await EmailEditor.init({
25
- * id: '#editor',
26
- * authorize: { apiKey: 'your-key', userId: 'user-123' },
27
- * callbacks: {
28
- * onSave(json, html) { console.log('Saved:', json); }
29
- * }
30
- * });
31
- * ```
32
- */
18
+ /** Editor v4. init creates an instance; render mounts it; onInit reports successful editor authentication. */
33
19
  export declare const EmailEditor: {
34
- /**
35
- * Initialize the Email Editor.
36
- * @param topolOptions - Configuration options for the editor
37
- * @param options - Plugin options including stage selection
38
- * @returns Promise that resolves to true when the editor is ready
39
- */
40
- init: (topolOptions: ITopolOptions, options?: EmailEditorPluginOptions) => Promise<boolean | string>;
41
- /** Trigger the save callback with current editor content */
42
- save: () => void;
43
- /** Load a template JSON into the editor */
44
- load: (json: unknown) => void;
45
- /** Toggle the preview mode */
46
- togglePreview: () => void;
47
- /** Toggle between desktop and mobile preview sizes */
48
- togglePreviewSize: () => void;
49
- /** Select a file from the custom file manager */
50
- chooseFile: (url: string) => void;
51
- /** Undo the last action */
52
- undo: () => void;
53
- /** Redo the last undone action */
54
- redo: () => void;
55
- /** Destroy the editor instance and clean up resources */
56
- destroy: () => void;
57
- /** Update the list of saved/reusable blocks */
58
- setSavedBlocks: (savedBlocks: ISavedBlock[]) => void;
59
- /** Set custom HTML for the preview */
60
- setPreviewHTML: (html: unknown) => void;
61
- /** Display a notification in the editor */
62
- createNotification: (notification: INotification) => void;
63
- /** Set the list of active collaboration members */
64
- setActiveMembers: (activeMembers: string[]) => void;
65
- /** Switch to mobile view */
66
- changeEmailToMobile: () => void;
67
- /** Switch to desktop view */
68
- changeEmailToDesktop: () => void;
69
- /** Toggle visibility of hidden blocks and structures */
70
- toggleBlocksAndStructuresVisibility: () => void;
71
- /** Update the content of a custom block */
72
- updateCustomBlockContent: (content: string) => void;
73
- /** Refresh comments/conversations */
74
- refreshComments: (key: string) => void;
75
- /** Refresh synced rows */
76
- refreshSyncedRows: () => void;
77
- /** Open the premade templates selection modal */
78
- openPremadeTemplatesSelection: () => void;
79
- /** Update the API authorization header */
80
- updateApiAuthorizationHeader: (newHeader: string | Record<string, string>) => void;
81
- /** Set the template name/title */
82
- setTemplateName: (name: string) => void;
83
- /** Toggle the AI chat feature */
84
- toggleChatAI: () => void;
85
- /** Toggle the autosaves feature */
86
- toggleAutosaves: () => void;
87
- /** Toggle the comments panel */
88
- toggleComments: () => void;
89
- /** Create a new language variant */
90
- createLanguage: (lang: string) => void;
91
- /** Set the primary language */
92
- setPrimaryLanguage: (lang: string) => void;
93
- /** Delete a language variant */
94
- deleteLanguage: (lang: string) => void;
95
- /** Select/switch to a language */
96
- selectLanguage: (lang: string) => void;
20
+ init(options: ITopolOptions, pluginOptions?: IEmailEditorPluginOptions): Promise<IEmailEditorInstance>;
97
21
  };
22
+ export {};
@@ -1,7 +1,15 @@
1
1
  import type ILandingPageOptions from "../../types/landing-page/ILandingPageOptions";
2
2
  import type ILandingPageEditorInstance from "../../types/landing-page/ILandingPageEditorInstance";
3
3
  import { Stage } from "../../types/Stage";
4
- type LandingPageEditorFactory = (options: ILandingPageOptions) => ILandingPageEditorInstance;
4
+ /**
5
+ * Raw zoid component instance created by the CDN runtime (topol-lpe.js).
6
+ * It exposes close() rather than destroy(); init() aliases the latter.
7
+ */
8
+ type RawLandingPageEditorInstance = Omit<ILandingPageEditorInstance, "destroy"> & {
9
+ close(): Promise<void>;
10
+ destroy?(): Promise<void>;
11
+ };
12
+ type LandingPageEditorFactory = (options: ILandingPageOptions) => RawLandingPageEditorInstance;
5
13
  declare global {
6
14
  interface Window {
7
15
  LandingPageEditor: LandingPageEditorFactory;
@@ -20,6 +28,10 @@ export interface LandingPageEditorPluginOptions {
20
28
  * This integration loads the Topol Landing Page Editor into your application.
21
29
  * Unlike the Email Editor, this creates an instance that you can interact with.
22
30
  *
31
+ * The runtime script is injected at most once per page; subsequent init() calls
32
+ * reuse the already-loaded runtime, so opening the editor repeatedly (or React StrictMode
33
+ * double-mounting) does not inject duplicate script tags.
34
+ *
23
35
  * @example
24
36
  * ```typescript
25
37
  * import { LandingPageEditor } from '@topol.io/editor';
@@ -28,18 +40,18 @@ export interface LandingPageEditorPluginOptions {
28
40
  * config: {
29
41
  * authorize: { apiKey: 'your-key', userId: 'user-123' },
30
42
  * },
31
- * onSave(json, html) { console.log('Saved:', json, html); },
32
- * onLoaded() { console.log('Editor loaded'); }
43
+ * onSave({ json, html }) { console.log('Saved:', json, html); },
44
+ * onLoaded() { console.log('Template loaded'); }
33
45
  * });
34
46
  *
35
- * // Render the editor into a container
36
- * editor.render('#landing-page-editor');
47
+ * // Render the editor into a container (resolves once the iframe is rendered)
48
+ * await editor.render('#landing-page-editor');
37
49
  *
38
50
  * // Optionally load a template
39
51
  * editor.load(templateJson);
40
52
  *
41
53
  * // Clean up when done
42
- * editor.destroy();
54
+ * await editor.destroy();
43
55
  * ```
44
56
  */
45
57
  export declare const LandingPageEditor: {
@@ -228,9 +228,9 @@ export declare const ButtonStyleAttributesSchema: z.ZodRecord<z.ZodUnion<[z.ZodE
228
228
  validatorErrorMessage: z.ZodOptional<z.ZodString>;
229
229
  }, z.core.$strip>, z.ZodAny]>>;
230
230
  export declare const ImageAttributesSchema: z.ZodRecord<z.ZodUnion<[z.ZodEnum<{
231
+ title: "title";
231
232
  src: "src";
232
233
  transform: "transform";
233
- title: "title";
234
234
  filter: "filter";
235
235
  display: "display";
236
236
  width: "width";
@@ -1,7 +1,6 @@
1
1
  import { z } from "zod";
2
- declare const OpenAIMessageSchema: z.ZodObject<{
2
+ export declare const OpenAIMessageSchema: z.ZodObject<{
3
3
  role: z.ZodString;
4
4
  content: z.ZodString;
5
5
  }, z.core.$strip>;
6
6
  export type IOpenAIMessage = z.infer<typeof OpenAIMessageSchema>;
7
- export {};
@@ -77,5 +77,94 @@ export interface IPluginOptions {
77
77
  windowBar?: string[];
78
78
  }
79
79
  export type IPluginOptionsPartial = Omit<IPluginOptions, "authorize" | "callbacks">;
80
+ /** A file or folder deleted in the built-in file manager (`onImageDelete`). */
81
+ export declare const DeletedItemSchema: z.ZodObject<{
82
+ name: z.ZodString;
83
+ type: z.ZodUnion<readonly [z.ZodLiteral<"file">, z.ZodLiteral<"folder">]>;
84
+ path: z.ZodString;
85
+ url: z.ZodOptional<z.ZodString>;
86
+ key: z.ZodNullable<z.ZodString>;
87
+ }, z.core.$strip>;
88
+ /** Payload of `onSave` and `onSaveAndClose`. */
89
+ export declare const SavePayloadSchema: z.ZodObject<{
90
+ json: z.ZodJSONSchema;
91
+ html: z.ZodString;
92
+ }, z.core.$strip>;
93
+ /**
94
+ * Host callbacks — top-level zoid props of `LandingPageEditor({ config, onSave, ... })`.
95
+ *
96
+ * Convention: every callback receives at most one argument — a payload object with named
97
+ * properties, so payloads can grow without breaking host integrations. Zero-payload
98
+ * callbacks receive nothing.
99
+ *
100
+ * `onEditorClose` / `onEditorError` are named so because zoid reserves `onClose` / `onError`
101
+ * for its own lifecycle (those never reach the child).
102
+ */
103
+ export declare const HostCallbacksSchema: z.ZodObject<{
104
+ onSave: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [z.ZodObject<{
105
+ json: z.ZodJSONSchema;
106
+ html: z.ZodString;
107
+ }, z.core.$strip>], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>>;
108
+ onSaveAndClose: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [z.ZodObject<{
109
+ json: z.ZodJSONSchema;
110
+ html: z.ZodString;
111
+ }, z.core.$strip>], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>>;
112
+ onOpenFileManager: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [], null>, z.ZodVoid>>;
113
+ onImageDelete: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [z.ZodObject<{
114
+ items: z.ZodArray<z.ZodObject<{
115
+ name: z.ZodString;
116
+ type: z.ZodUnion<readonly [z.ZodLiteral<"file">, z.ZodLiteral<"folder">]>;
117
+ path: z.ZodString;
118
+ url: z.ZodOptional<z.ZodString>;
119
+ key: z.ZodNullable<z.ZodString>;
120
+ }, z.core.$strip>>;
121
+ }, z.core.$strip>], null>, z.ZodVoid>>;
122
+ onLoaded: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [], null>, z.ZodVoid>>;
123
+ onInit: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [], null>, z.ZodVoid>>;
124
+ onUndoChange: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [z.ZodObject<{
125
+ count: z.ZodNumber;
126
+ }, z.core.$strip>], null>, z.ZodVoid>>;
127
+ onRedoChange: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [z.ZodObject<{
128
+ count: z.ZodNumber;
129
+ }, z.core.$strip>], null>, z.ZodVoid>>;
130
+ onPreview: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [z.ZodObject<{
131
+ html: z.ZodString;
132
+ }, z.core.$strip>], null>, z.ZodVoid>>;
133
+ onPreviewClose: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [], null>, z.ZodVoid>>;
134
+ onAlert: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [z.ZodObject<{
135
+ notification: z.ZodObject<{
136
+ title: z.ZodOptional<z.ZodString>;
137
+ text: z.ZodString;
138
+ expectSideEffect: z.ZodOptional<z.ZodBoolean>;
139
+ persistent: z.ZodOptional<z.ZodBoolean>;
140
+ type: z.ZodEnum<{
141
+ info: "info";
142
+ error: "error";
143
+ success: "success";
144
+ }>;
145
+ extarnalUse: z.ZodOptional<z.ZodBoolean>;
146
+ id: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
147
+ }, z.core.$strip>;
148
+ }, z.core.$strip>], null>, z.ZodVoid>>;
149
+ onEditorClose: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>>;
150
+ onEdittedWithoutSaveChanged: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [z.ZodObject<{
151
+ value: z.ZodBoolean;
152
+ }, z.core.$strip>], null>, z.ZodVoid>>;
153
+ onOpenCustomBlockDialog: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [z.ZodObject<{
154
+ block: z.ZodUnknown;
155
+ }, z.core.$strip>], null>, z.ZodVoid>>;
156
+ onTemplateRename: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [z.ZodObject<{
157
+ name: z.ZodString;
158
+ }, z.core.$strip>], null>, z.ZodVoid>>;
159
+ onEditorError: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [z.ZodObject<{
160
+ source: z.ZodString;
161
+ message: z.ZodString;
162
+ detail: z.ZodOptional<z.ZodUnknown>;
163
+ }, z.core.$strip>], null>, z.ZodVoid>>;
164
+ }, z.core.$strip>;
165
+ export type IHostCallbacks = z.infer<typeof HostCallbacksSchema>;
166
+ export type ISavePayload = z.infer<typeof SavePayloadSchema>;
167
+ export type IDeletedItem = z.infer<typeof DeletedItemSchema>;
168
+ /** Everything zoid sets on `window.xprops`: `config`, the host callbacks and zoid's child helpers. */
80
169
  export declare const XpropsSchema: z.ZodTypeAny;
81
170
  export type IXprops = z.infer<typeof XpropsSchema>;