@topol.io/editor 1.0.0-alpha.8 → 2.0.0-alpha.1

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 (37) hide show
  1. package/README.md +89 -110
  2. package/dist/topol-plugin.es.js +122 -249
  3. package/dist/topol-plugin.umd.cjs +1 -0
  4. package/dist/types/src/email-editor/constants.d.ts +3 -3
  5. package/dist/types/src/email-editor/index.d.ts +15 -101
  6. package/dist/types/src/landing-page-editor/index.d.ts +1 -1
  7. package/dist/types/src/landing-page-editor/schemas/contentBlock/contentBlockScheme.d.ts +1 -1
  8. package/dist/types/src/landing-page-editor/schemas/openAI/openAISchema.d.ts +1 -2
  9. package/dist/types/src/landing-page-editor/schemas/pluginOptions/pluginOptionsSchema.d.ts +89 -0
  10. package/dist/types/src/landing-page-editor/schemas/premadeBlock/premadeBlockSchema.d.ts +816 -816
  11. package/dist/types/src/landing-page-editor/schemas/savedBlock/savedBlockApiSchema.d.ts +612 -612
  12. package/dist/types/src/landing-page-editor/schemas/savedBlock/savedBlockSchema.d.ts +816 -816
  13. package/dist/types/src/landing-page-editor/schemas/template/blocks/buttonBlockSchema.d.ts +2 -2
  14. package/dist/types/src/landing-page-editor/schemas/template/blocks/dividerBlockSchema.d.ts +2 -2
  15. package/dist/types/src/landing-page-editor/schemas/template/blocks/imageAnGifBlockSchema.d.ts +6 -6
  16. package/dist/types/src/landing-page-editor/schemas/template/blocks/socialBlockSchema.d.ts +2 -2
  17. package/dist/types/src/landing-page-editor/schemas/template/blocks/spacerBlockSchema.d.ts +2 -2
  18. package/dist/types/src/landing-page-editor/schemas/template/structure/blockSchema.d.ts +92 -92
  19. package/dist/types/src/landing-page-editor/schemas/template/structure/columnSchema.d.ts +94 -94
  20. package/dist/types/src/landing-page-editor/schemas/template/structure/sectionSchema.d.ts +204 -204
  21. package/dist/types/src/landing-page-editor/schemas/templateSchema.d.ts +804 -804
  22. package/dist/types/src/main.d.ts +11 -74
  23. package/dist/types/types/API/API.d.ts +8 -7
  24. package/dist/types/types/Callbacks/ICallbackPayloads.d.ts +19 -22
  25. package/dist/types/types/Callbacks/IEmailCallbacks.d.ts +64 -155
  26. package/dist/types/types/Cloud/ICloudOptions.d.ts +33 -0
  27. package/dist/types/types/ContentBlock/IContentBlockOptions.d.ts +1 -1
  28. package/dist/types/types/IEmailConfig.d.ts +190 -0
  29. package/dist/types/types/IEmailEditorInstance.d.ts +54 -0
  30. package/dist/types/types/ITopolOptions.d.ts +4 -153
  31. package/dist/types/types/ITopolPlugin.d.ts +2 -44
  32. package/dist/types/types/Language/Language.d.ts +1 -1
  33. package/dist/types/types/SavedBlock/ISavedBlock.d.ts +2 -6
  34. package/dist/types/types/Sections/ISections.d.ts +30 -0
  35. package/dist/types/types/landing-page/ILandingPageOptions.d.ts +96 -63
  36. package/package.json +7 -10
  37. package/dist/topol-plugin.umd.js +0 -1
package/README.md CHANGED
@@ -1,121 +1,100 @@
1
- <a href="https://topol.io" target="_blank">
2
- <svg width="391" height="100" viewBox="0 0 391 100" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M198.658 24.5069C194.15 21.9659 188.894 20.6954 182.903 20.6954C176.911 20.6954 171.655 21.9659 167.103 24.5069C162.561 27.0478 159.024 30.5918 156.525 35.161C154.003 39.7192 152.765 45.024 152.765 51.0755C152.765 57.1269 154.014 62.376 156.558 66.9341C159.08 71.5034 162.617 75.0474 167.136 77.5883C171.678 80.1293 176.922 81.3998 182.914 81.3998C188.906 81.3998 194.116 80.1293 198.635 77.5883C203.177 75.0474 206.703 71.5034 209.224 66.9341C211.746 62.376 213.018 57.0824 213.018 51.0755C213.018 45.0685 211.746 39.7192 209.224 35.161C206.703 30.5918 203.177 27.0478 198.658 24.5069ZM198.011 60.604C196.593 63.3233 194.585 65.4296 192.008 66.9119C189.43 68.4052 186.395 69.1519 182.914 69.1519C179.432 69.1519 176.386 68.4052 173.798 66.9119C171.209 65.4296 169.2 63.3233 167.772 60.604C166.344 57.8848 165.641 54.7086 165.641 51.0755C165.641 47.4423 166.344 44.2216 167.772 41.5134C169.2 38.8165 171.198 36.699 173.775 35.2056C176.353 33.7011 179.399 32.9433 182.914 32.9433C186.428 32.9433 189.43 33.7011 192.008 35.2056C194.585 36.699 196.593 38.8165 198.011 41.5134C199.439 44.2216 200.153 47.3978 200.153 51.0755C200.153 54.7532 199.439 57.8959 198.011 60.604ZM332.387 24.5069C327.879 21.9659 322.635 20.6954 316.643 20.6954C310.651 20.6954 305.384 21.9659 300.843 24.5069C296.291 27.0478 292.753 30.5918 290.254 35.161C287.744 39.7192 286.494 45.024 286.494 51.0755C286.494 57.1269 287.755 62.376 290.288 66.9341C292.809 71.5034 296.335 75.0474 300.876 77.5883C305.407 80.1293 310.651 81.3998 316.654 81.3998C322.657 81.3998 327.834 80.1293 332.376 77.5883C336.906 75.0474 340.432 71.5034 342.953 66.9341C345.475 62.376 346.747 57.0824 346.747 51.0755C346.747 45.0685 345.475 39.7192 342.953 35.161C340.432 30.5918 336.906 27.0478 332.387 24.5069ZM331.751 60.604C330.323 63.3233 328.325 65.4296 325.748 66.9119C323.159 68.4052 320.124 69.1519 316.654 69.1519C313.184 69.1519 310.126 68.4052 307.527 66.9119C304.938 65.4296 302.93 63.3233 301.501 60.604C300.084 57.8848 299.37 54.7086 299.37 51.0755C299.37 47.4423 300.084 44.2216 301.501 41.5134C302.93 38.8165 304.927 36.699 307.504 35.2056C310.082 33.7011 313.139 32.9433 316.654 32.9433C320.169 32.9433 323.159 33.7011 325.748 35.2056C328.325 36.699 330.323 38.8165 331.751 41.5134C333.168 44.2216 333.882 47.3978 333.882 51.0755C333.882 54.7532 333.168 57.8959 331.751 60.604ZM267.971 24.44C263.798 21.9436 258.889 20.6954 253.276 20.6954C248.043 20.6954 243.591 21.8656 239.942 24.1837C236.963 26.0782 234.575 28.7195 232.768 32.0517V21.8767H219.3V100H232.768V69.464C234.575 72.7962 236.952 75.4263 239.942 77.3208C243.591 79.6612 248.043 80.8091 253.276 80.8091C258.889 80.8091 263.798 79.5609 267.971 77.0311C272.156 74.5236 275.414 71.0019 277.757 66.4772C280.1 61.9637 281.283 56.7034 281.283 50.7188C281.283 44.7342 280.1 39.474 277.757 34.9604C275.414 30.4358 272.145 26.9252 267.971 24.44ZM266.186 60.1137C264.736 62.7995 262.694 64.8724 260.072 66.3435C257.449 67.8257 254.359 68.5612 250.81 68.5612C247.262 68.5612 244.171 67.8257 241.549 66.3435C238.916 64.8724 236.874 62.7995 235.435 60.1137C233.984 57.439 233.248 54.3185 233.248 50.7411C233.248 47.1637 233.973 43.9987 235.435 41.3351C236.874 38.6827 238.916 36.6098 241.549 35.1499C244.171 33.6788 247.262 32.9544 250.81 32.9544C254.359 32.9544 257.483 33.69 260.094 35.1499C262.705 36.6098 264.724 38.6827 266.186 41.3574C267.626 44.0321 268.362 47.1526 268.362 50.7411C268.362 54.3297 267.637 57.4501 266.186 60.1137ZM391 66.7781V80.2407H366.408V66.7781H391ZM366.397 0V66.7781H352.918V0H366.397ZM127.38 21.7096H149.607V35.1722H127.38V66.7893H113.79V0H127.38V21.7096ZM127.38 66.7781H147.152V80.2407H127.38V66.7781ZM80.3379 66.8004V80.263H60.2534V66.8004H80.3379ZM0 66.8004H20.0845V80.263H0V66.8004ZM0.0223161 50.1727V30.1126H20.0845V50.1727H0.0223161ZM60.2534 50.1727V30.1126H20.0845V13.4849H60.2534V30.1126H80.3044V50.1727H60.2534ZM20.0845 50.1727H60.2534V66.8004H20.0845V50.1727ZM0 13.4738V0.0222891H20.0845V13.4849L0 13.4738ZM80.3379 13.4738H60.2534V0.0222891H80.3379V13.4738Z" fill="black"/></svg>
3
- </a>
1
+ # @topol.io/editor — v2 alpha
4
2
 
5
- ---
3
+ Integration packages 2.x target **Email Editor v4**. The 1.x alpha line targets v3.
4
+ This branch prepares `2.0.0-alpha.0` locally; it has not been published.
6
5
 
7
- Easy and quick! Drag and drop HTML editor and builder for beautiful responsive email templates.
8
-
9
- # Documentation
10
-
11
- ## Installation
12
-
13
- Install Editor from NPM using:
14
-
15
- ```sh
16
- npm install @topol.io/editor
17
-
18
- //or
19
-
20
- yarn add @topol.io/editor
21
- ```
22
-
23
- ## Usage
24
-
25
- Add HTML element Editor will load to
26
-
27
- ```html
28
- <div id="app" style="position: absolute; width: 100%; height: 100%"></div>
29
- ```
30
-
31
- In your JS or TS file import TopolPlugin, initialize the editor, as an ID provide the id you defined the HTML, in this example its `app`
32
-
33
- For more options see the docs for [TopolOptions configuration](https://docs.topol.io/reference/topol-options.html)
34
-
35
- ```js
36
- import TopolPlugin from "@topol.io/editor";
6
+ ```ts
7
+ import { EmailEditor } from "@topol.io/editor";
37
8
 
38
- const TOPOL_OPTIONS = {
39
- id: "#app",
40
- authorize: {
41
- apiKey: "YOUR_API_TOKEN",
42
- userId: "some-user-id",
9
+ const editor = await EmailEditor.init({
10
+ config: {
11
+ authorize: { apiKey: "your-api-key", userId: "user-123" },
43
12
  },
44
- callbacks: {
45
- onSave(json, html) {},
13
+ async onSave({ json, html, mutations, syncedSections }) {
14
+ // Await your own backend's persistence here. A rejection shows a save error.
15
+ console.log(json, html, mutations, syncedSections);
46
16
  },
47
- };
48
-
49
- TopolPlugin.init(TOPOL_OPTIONS);
50
- ```
51
-
52
- ## Call Topol Plugin actions
53
-
54
- To call actions to the editor import:
55
-
56
- ```js
57
- import { TopolPlugin } from "@topol.io/editor";
58
-
59
- TopolPlugin.save();
17
+ onEditorError({ source, message, detail }) {
18
+ console.error(source, message, detail);
19
+ },
20
+ });
21
+ await editor.render("#editor"); // Container must exist and have a height.
22
+ // onInit reports successful editor authentication; render only mounts the iframe.
23
+ await editor.load(templateJson);
24
+ await editor.save({ langCode: "en" });
25
+ await editor.destroy(); // When closing/unmounting, not immediately after render.
60
26
  ```
61
27
 
62
- ### List of all available TopolPlugin actions:
63
-
64
- | Action | Description |
65
- | --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
66
- | `TopolPlugin.save()` | Saves the content of the editor [more info](https://docs.topol.io/guide/how-to-use-custom-topbar.html#save-and-saveandclose) |
67
- | `TopolPlugin.load(template)` | Loads the provided template [more info](https://docs.topol.io/guide/how-to-load-and-save-template.html#loading-template) |
68
- | `TopolPlugin.togglePreview()` | Toggles editor preview [more info](https://docs.topol.io/guide/how-to-use-custom-topbar.html#changing-preview-mode) |
69
- | `TopolPlugin.togglePreviewSize()` | Toggles editor preview size [more info](https://docs.topol.io/guide/how-to-use-custom-topbar.html#changing-preview-mode) |
70
- | `TopolPlugin.undo()` | Undo change in editor [more info](https://docs.topol.io/guide/how-to-use-custom-topbar.html#undo-and-redo) |
71
- | `TopolPlugin.redo()` | Redo change in editor [more info](https://docs.topol.io/guide/how-to-use-custom-topbar.html#undo-and-redo) |
72
- | `TopolPlugin.setSavedBlocks(savedblock: ISavedBlock[])` | Sets the saved blocks [more info](https://docs.topol.io/guide/saved-blocks.html) |
73
- | `TopolPlugin.createNotification(notification: INotification)` | Creates editor's notification [more info](https://docs.topol.io/guide/custom-notifications.html) |
74
- | `TopolPlugin.changeEmailToMobile()` | Change email to mobile view [more info](https://docs.topol.io/guide/mobile-first.html#mobile-first-email-template) |
75
- | `TopolPlugin.changeEmailToDesktop()` | Change email to desktop view [more info](https://docs.topol.io/guide/mobile-first.html#mobile-first-email-template) |
76
- | `TopolPlugin.toggleBlocksAndStructuresVisibility()` | Toggle hidden structures visibility for blocks and structures [more info](https://docs.topol.io/guide/mobile-first.html#mobile-first-email-template) |
77
- | `TopolPlugin.destroy()` | Destroys the editor initialization |
78
- | `TopolPlugin.chooseFile()` | Chooses the file if image block is active [more info](https://docs.topol.io/guide/custom-filemanager.html#choosefile) |
79
- | `TopolPlugin.openPremadeTemplatesSelection()` | Opens the premade templates modal pick [more info](https://docs.topol.io/guide/premade-templates-in-editor.html) |
80
- | `TopolPlugin.refreshComments(key: string)` | Refreshes the conversation [more info](https://docs.topol.io/guide/comments.html#refreshcomments) |
81
- | `TopolPlugin.setActiveMembers(activeMemers: string[])` | Sets the active members |
82
- | `TopolPlugin.setTemplateName(name: string)` | Sets the name of template [more info](https://docs.topol.io/guide/rename-template.html) |
83
- | `TopolPlugin.updateApiAuthorizationHeader(newHeader: string \| Record<string, string>)` | Refreshes the authorization tokens [more info](https://docs.topol.io/guide/security.html#refresh-token) |
84
- | `TopolPlugin.updateCustomBlockContent(content: string)` | Refreshes the authorization tokens [more info](https://docs.topol.io/guide/custom-block.html#inserting-custom-html-in-custom-dialog-component) |
85
- | `TopolPlugin.setMergeTags(mergeTags: Array<IMergeTagGroup \| IMergeTag>)` | Sets new array of merge tags. [more info](https://docs.topol.io/guide/merge-tags.html#update-merge-tags) |
86
-
87
- <br>
88
-
89
- ### List of all editor callbacks
28
+ Every `init` creates an independent instance. Host methods return promises, including
29
+ `getMutations()`, which resolves to `{ code, primary }[]`. Use instance methods for
30
+ `setSavedSections`, `refreshSyncedSections`, `setMergeTags`, `translateLanguage(code,
31
+ sourceCode?)`, `translateAllLanguages`, and other editor actions.
90
32
 
91
- | Event | Description |
92
- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
93
- | `onSave` | Returns object which contains html and json of the template [more info](https://docs.topol.io/guide/callbacks.html#on-save) |
94
- | `onSaveAndClose` | Returns object which contains html and json of the template [more info](https://docs.topol.io/guide/callbacks.html#on-save-and-close) |
95
- | `onTestSend` | Returns object which contains email, html and json of the template [more info](https://docs.topol.io/guide/callbacks.html#on-test-email-send) |
96
- | `onOpenFileManager` | When user clicks file manager open [more info](https://docs.topol.io/guide/custom-filemanager.html#onopenfilemanager) |
97
- | `onLoaded` | After editor template is loaded using `TopolPlugin.load()` [more info](https://docs.topol.io/guide/callbacks.html#on-loaded) |
98
- | `onInit` | When editor inits [more info](https://docs.topol.io/guide/callbacks.html#on-init) |
99
- | `onBlockSave` | When user saves block in editor, returns object of type ISavedBlock [more info](https://docs.topol.io/guide/callbacks.html#on-block-save) |
100
- | `onBlockRemove` | When user removes saved block, returns id of saved block to be removed [more info](https://docs.topol.io/guide/callbacks.html#on-block-remove) |
101
- | `onBlockEdit` | When user edits saved block, returns id of saved block to be updated [more info](https://docs.topol.io/guide/callbacks.html#on-block-edit) |
102
- | `onUndoChange` | When user clicks undo button, retunrs number of steps user undone [more info](https://docs.topol.io/guide/callbacks.html#on-undo-change) |
103
- | `onRedoChange` | When user clicks redo button, retunrs number of steps user redone [more info](https://docs.topol.io/guide/callbacks.html#on-redo-change) |
104
- | `onPreview` | When user switches to preview [more info](https://docs.topol.io/guide/callbacks.html#on-preview) |
105
- | `onAlert` | When alert appears in editor [more info](https://docs.topol.io/guide/callbacks.html#on-alert) |
106
- | `onClose` | When close is click inside WindowBar [more info](https://docs.topol.io/guide/top-bar.html#window-bar) |
107
- | `onEdittedWithoutSaveChanged` | When user is about to leave an editor with unsaved changes [more info](https://docs.topol.io/guide/disable-before-leaving-modal.html#before-exit-modal-when-user-has-unsaved-changes) |
108
- | `onOpenCustomBlockDialog` | When user clicks on the open dialog in custom block [more info](https://docs.topol.io/guide/custom-block.html#inserting-custom-html-in-custom-dialog-component) |
109
- | `onTemplateRename` | When user clicks on the pencil icon next to the template name [more info](https://docs.topol.io/guide/rename-template.html#rename-template) |
110
- | `updateTestingEmailAddresses` | When user edits the email list in preview [more info](https://docs.topol.io/guide/sending-a-test-email.html#managing-saving-emails-yourself) |
111
- | `onError` | When an error that cannot be handled happened in the editor [more info](https://docs.topol.io/guide/callbacks.html#onerror) |
112
-
113
- <br>
114
-
115
- ## TypeScript
116
-
117
- Topol Editor provides full TypeScript integration and exports all necessary types.
33
+ ## Topol Cloud
118
34
 
119
35
  ```ts
120
- import { ITopolOptions, INotification, ISavedBlock } from "@topol.io/editor";
36
+ const editor = await EmailEditor.init({
37
+ config: {
38
+ authorize: { apiKey: "pk_your-public-key", userId: "user-123" },
39
+ cloud: { enabled: true, templateId: 123, features: { images: false } },
40
+ },
41
+ async getNonce() {
42
+ // Your authenticated backend mints a nonce for this public key and user.
43
+ const response = await fetch("/api/topol/nonce", { method: "POST" });
44
+ if (!response.ok) throw new Error("Could not authorize Topol Cloud");
45
+ const { nonce } = await response.json();
46
+ return nonce; // A fresh nc_ token. Keep sk_ secrets on the server.
47
+ },
48
+ onCloudSave({ templateId, name, langCode }) {
49
+ console.log("Stored in Cloud:", templateId, name, langCode);
50
+ },
51
+ onCloudTemplateChange({ type, templateId, name, folderId }) {
52
+ console.log(type, templateId, name, folderId);
53
+ },
54
+ });
55
+ await editor.render("#editor");
121
56
  ```
57
+
58
+ Enabling Cloud activates templates, autosaves, images, comments, sections,
59
+ multilanguage, and test-send. Set a feature to `false` to use external behavior.
60
+ Omit `cloud.templateId` to start in the Cloud template browser. The editor handles
61
+ nonce refresh, persistence, and its Cloud recovery UI; this package supplies the
62
+ host bridge. Your application must implement the nonce endpoint above.
63
+
64
+ ## Loader selection
65
+
66
+ The default is `https://v4.email-assets.topol.io/loader/build.js`.
67
+ Build-time overrides use `VITE_TOPOL_V4_URL`, `VITE_TOPOL_V4_DEV_URL`, and
68
+ `VITE_TOPOL_V4_STAGING_URL`; old `VITE_TOPOL_URL` values are ignored to prevent
69
+ accidentally bundling a v3 loader.
70
+ Pass `{ loaderUrl: 'https://your-preview/loader/build.js' }` as the second argument
71
+ to `init` to select a local or preview v4 loader. Explicit URLs never fall back.
72
+ Numeric stages still select PR previews; loader failures fall back to v4 production
73
+ only before a runtime has been initialized. Each page supports one loader URL;
74
+ switching environments requires a page reload, even after destroying all instances.
75
+ Let `EmailEditor.init` insert custom loader scripts. Host-inserted scripts with unknown
76
+ lifecycle are rejected immediately; an already available production runtime can be reused.
77
+ These runtime conflicts reject without falling back to another environment.
78
+ `dev` and `staging` use the v4 release loader unless their build-time
79
+ `VITE_TOPOL_V4_DEV_URL` / `VITE_TOPOL_V4_STAGING_URL` overrides are configured.
80
+ The upstream local loader uses its host page's origin for the iframe: serve/proxy
81
+ the editor at that origin, or build a loader with an explicit iframe URL.
82
+
83
+ ## Migration from 1.x alpha
84
+
85
+ - `init({ id, authorize, callbacks })` → `init({ config: { authorize }, ...callbacks })`, then `instance.render(container)`.
86
+ - Singleton methods → methods on the returned instance. `save('en')` → `save({ langCode: 'en' })`.
87
+ - All callbacks receive zero arguments or one object. `onSave(json, html)` → `onSave({ json, html })`.
88
+ - `onClose` → `onEditorClose`; `onError(type, message, responseBody)` → `onEditorError({ source, message, detail })`.
89
+ - `savedBlocks` / `setSavedBlocks` → `savedSections` / `setSavedSections`.
90
+ - `onBlockSave/Remove/Edit` → `onSavedSectionSave/Remove/Edit` with `{ section }` / `{ id }` payloads.
91
+ - `premadeBlocks` → `premadeSections`; replace `premadeBlocksNoOverwrite` with `{ blocks, override }`.
92
+ - `syncedRowsEnable` / `refreshSyncedRows` → `syncedSectionsEnabled` / `refreshSyncedSections`.
93
+ - `api.SAVED_BLOCKS` → `api.SAVED_SECTIONS`; `api.SYNCED_ROWS` is removed. Legacy SAVE/LOAD/PREVIEW and singular autosave endpoints are removed.
94
+ - Language mutations and `defaultTemplateSettings.langs` use `code`, not `key`.
95
+ - `topBarOptions` → `hideTopbarControls` (a list of controls to hide).
96
+ - `authorize.userId` must be a non-negative integer or match `[A-Za-z0-9_-]+`.
97
+
98
+ `TopolPlugin` remains a naming alias for the new EmailEditor API, not a v3 adapter.
99
+ `LandingPageEditor` retains its existing API and loader. Its Cloud integration is
100
+ not enabled by these email-specific changes.
@@ -1,259 +1,139 @@
1
- function T(e) {
1
+ function P(e) {
2
2
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
3
3
  }
4
- var P = function(n, o, t) {
5
- var r = document.head || document.getElementsByTagName("head")[0], i = document.createElement("script");
6
- typeof o == "function" && (t = o, o = {}), o = o || {}, t = t || function() {
7
- }, i.type = o.type || "text/javascript", i.charset = o.charset || "utf8", i.async = "async" in o ? !!o.async : !0, i.src = n, o.attrs && m(i, o.attrs), o.text && (i.text = "" + o.text);
8
- var l = "onload" in i ? p : E;
9
- l(i, t), i.onload || p(i, t), r.appendChild(i);
4
+ var I = function(o, t, r) {
5
+ var n = document.head || document.getElementsByTagName("head")[0], i = document.createElement("script");
6
+ typeof t == "function" && (r = t, t = {}), t = t || {}, r = r || function() {
7
+ }, i.type = t.type || "text/javascript", i.charset = t.charset || "utf8", i.async = "async" in t ? !!t.async : !0, i.src = o, t.attrs && T(i, t.attrs), t.text && (i.text = "" + t.text);
8
+ var a = "onload" in i ? g : b;
9
+ a(i, r), i.onload || g(i, r), n.appendChild(i);
10
10
  };
11
- function m(e, n) {
12
- for (var o in n)
13
- e.setAttribute(o, n[o]);
11
+ function T(e, o) {
12
+ for (var t in o)
13
+ e.setAttribute(t, o[t]);
14
14
  }
15
- function p(e, n) {
15
+ function g(e, o) {
16
16
  e.onload = function() {
17
- this.onerror = this.onload = null, n(null, e);
17
+ this.onerror = this.onload = null, o(null, e);
18
18
  }, e.onerror = function() {
19
- this.onerror = this.onload = null, n(new Error("Failed to load " + this.src), e);
19
+ this.onerror = this.onload = null, o(new Error("Failed to load " + this.src), e);
20
20
  };
21
21
  }
22
- function E(e, n) {
22
+ function b(e, o) {
23
23
  e.onreadystatechange = function() {
24
- this.readyState != "complete" && this.readyState != "loaded" || (this.onreadystatechange = null, n(null, e));
24
+ this.readyState != "complete" && this.readyState != "loaded" || (this.onreadystatechange = null, o(null, e));
25
25
  };
26
26
  }
27
- const g = /* @__PURE__ */ T(P);
28
- var u = { BASE_URL: "/", MODE: "production", DEV: !1, PROD: !0, SSR: !1 };
29
- const h = "https://v3.email-assets.topol.io/loader/build.js", L = "https://v3.develop.email-assets.topol.io/loader/build.js", v = "https://v3.develop.email-assets.topol.io/loader/build.js", a = {
30
- production: u.VITE_TOPOL_URL || h,
31
- dev: u.VITE_TOPOL_DEV_URL || L,
32
- staging: u.VITE_TOPOL_STAGING_URL || v
33
- }, y = "https://d10h8ga60f7b91.cloudfront.net/preview-app-{stage}/loader/build.js";
34
- function _(e) {
35
- switch (e) {
36
- case "dev":
37
- return a.dev;
38
- case "staging":
39
- return a.staging;
40
- case "production":
41
- return a.production;
42
- default:
43
- return y.replace("{stage}", String(e));
44
- }
45
- }
46
- function S(e = "production") {
47
- const n = _(e);
48
- if (!n) {
49
- if (a.production)
50
- return console.error(`[@topol.io/editor] No loader URL resolved for stage "${e}"; falling back to the production loader.`), a.production;
51
- throw new Error(`[@topol.io/editor] Could not resolve a loader URL for stage "${e}". The editor cannot be loaded.`);
52
- }
53
- return n;
54
- }
55
- async function A(e) {
56
- return new Promise((n, o) => {
57
- g(a.production, (t) => {
58
- if (t !== null) {
59
- o(t);
60
- return;
61
- }
62
- window.TopolPlugin.init(e), n(!0);
63
- });
64
- });
65
- }
66
- const R = {
67
- /**
68
- * Initialize the Email Editor.
69
- * @param topolOptions - Configuration options for the editor
70
- * @param options - Plugin options including stage selection
71
- * @returns Promise that resolves to true when the editor is ready
72
- */
73
- init: (e, n) => new Promise((o, t) => {
74
- const r = S(n == null ? void 0 : n.stage);
75
- g(r, async (i) => {
76
- if (i !== null) {
77
- if (r !== a.production)
78
- try {
79
- return await A(e), o(!0);
80
- } catch (l) {
81
- t(l);
82
- }
83
- t(i);
84
- return;
85
- }
86
- window.TopolPlugin.init(e), o(!0);
87
- });
88
- }),
89
- /** Trigger the save callback with current editor content */
90
- save: (e) => {
91
- window.TopolPlugin.save(e);
92
- },
93
- /** Load a template JSON into the editor */
94
- load: (e) => {
95
- window.TopolPlugin.load(e);
96
- },
97
- /** Toggle the preview mode */
98
- togglePreview: () => {
99
- window.TopolPlugin.togglePreview();
100
- },
101
- /** Toggle between desktop and mobile preview sizes */
102
- togglePreviewSize: () => {
103
- window.TopolPlugin.togglePreviewSize();
104
- },
105
- /** Select a file from the custom file manager */
106
- chooseFile: (e) => {
107
- window.TopolPlugin.chooseFile(e);
108
- },
109
- /** Undo the last action */
110
- undo: () => {
111
- window.TopolPlugin.undo();
112
- },
113
- /** Redo the last undone action */
114
- redo: () => {
115
- window.TopolPlugin.redo();
116
- },
117
- /** Destroy the editor instance and clean up resources */
118
- destroy: () => {
119
- window.TopolPlugin.destroy();
120
- },
121
- /** Update the list of saved/reusable blocks */
122
- setSavedBlocks: (e) => {
123
- window.TopolPlugin.setSavedBlocks(e);
124
- },
125
- /** Set custom HTML for the preview */
126
- setPreviewHTML: (e) => {
127
- window.TopolPlugin.setPreviewHTML(e);
128
- },
129
- /** Display a notification in the editor */
130
- createNotification: (e) => {
131
- window.TopolPlugin.createNotification(e);
132
- },
133
- /** Set the list of active collaboration members */
134
- setActiveMembers: (e) => {
135
- window.TopolPlugin.setActiveMembers(e);
136
- },
137
- /** Switch to mobile view */
138
- changeEmailToMobile: () => {
139
- window.TopolPlugin.changeEmailToMobile();
140
- },
141
- /** Switch to desktop view */
142
- changeEmailToDesktop: () => {
143
- window.TopolPlugin.changeEmailToDesktop();
144
- },
145
- /** Toggle visibility of hidden blocks and structures */
146
- toggleBlocksAndStructuresVisibility: () => {
147
- window.TopolPlugin.toggleBlocksAndStructuresVisibility();
148
- },
149
- /** Update the content of a custom block */
150
- updateCustomBlockContent: (e) => {
151
- window.TopolPlugin.updateCustomBlockContent(e);
152
- },
153
- /** Refresh comments/conversations */
154
- refreshComments: (e) => {
155
- window.TopolPlugin.refreshComments(e);
156
- },
157
- /** Refresh synced rows */
158
- refreshSyncedRows: () => {
159
- window.TopolPlugin.refreshSyncedRows();
160
- },
161
- /** Open the premade templates selection modal */
162
- openPremadeTemplatesSelection: () => {
163
- window.TopolPlugin.openPremadeTemplatesSelection();
164
- },
165
- /** Update the API authorization header */
166
- updateApiAuthorizationHeader: (e) => {
167
- window.TopolPlugin.updateApiAuthorizationHeader(e);
168
- },
169
- /** Set the template name/title */
170
- setTemplateName: (e) => {
171
- window.TopolPlugin.setTemplateName(e);
172
- },
173
- updateOptions: (e) => {
174
- window.TopolPlugin.updateOptions(e);
175
- },
176
- /** Toggle the AI chat feature */
177
- toggleChatAI: () => {
178
- window.TopolPlugin.toggleChatAI();
179
- },
180
- /** Toggle the autosaves feature */
181
- toggleAutosaves: () => {
182
- window.TopolPlugin.toggleAutosaves();
183
- },
184
- /** Toggle the comments panel */
185
- toggleComments: () => {
186
- window.TopolPlugin.toggleComments();
187
- },
188
- /** Create a new language variant */
189
- createLanguage: (e) => {
190
- window.TopolPlugin.createLanguage(e);
191
- },
192
- /** Set the primary language */
193
- setPrimaryLanguage: (e) => {
194
- window.TopolPlugin.setPrimaryLanguage(e);
195
- },
196
- /** Delete a language variant */
197
- deleteLanguage: (e) => {
198
- window.TopolPlugin.deleteLanguage(e);
199
- },
200
- /** Select/switch to a language */
201
- selectLanguage: (e) => {
202
- window.TopolPlugin.selectLanguage(e);
203
- },
204
- /** Get the list of mutations */
205
- getMutations: () => window.TopolPlugin.getMutations(),
206
- /** Toggle the control panel visibility */
207
- toggleControlPanel: () => {
208
- window.TopolPlugin.toggleControlPanel();
209
- },
210
- /** Update the editor template with new JSON data */
211
- updateTemplate: (e, n) => {
212
- window.TopolPlugin.updateTemplate(e, n);
213
- },
214
- /** Toggle dark mode for the editor */
215
- toggleDarkMode: () => {
216
- window.TopolPlugin.toggleDarkMode();
217
- }
218
- }, O = "https://v1.page-assets.topol.io/topol-lpe.js", s = /* @__PURE__ */ new Map();
219
- function D(e, n) {
220
- if (n())
27
+ const _ = /* @__PURE__ */ P(I), f = /* @__PURE__ */ new Map();
28
+ function U(e, o) {
29
+ if (o())
221
30
  return Promise.resolve();
222
- const o = s.get(e);
223
- if (o)
224
- return o;
225
- const t = new Promise((r, i) => {
226
- const l = typeof document < "u" ? U(e) : null;
227
- if (l) {
228
- const d = () => {
229
- w(), r();
31
+ const t = f.get(e);
32
+ if (t)
33
+ return t;
34
+ const r = new Promise((n, i) => {
35
+ const a = typeof document < "u" ? p(e) : null;
36
+ if (a) {
37
+ const l = () => {
38
+ c(), n();
39
+ }, d = () => {
40
+ c(), a.remove(), i(new Error(`Failed to load script: ${e}`));
230
41
  }, c = () => {
231
- w(), i(new Error(`Failed to load script: ${e}`));
232
- }, w = () => {
233
- l.removeEventListener("load", d), l.removeEventListener("error", c);
42
+ a.removeEventListener("load", l), a.removeEventListener("error", d);
234
43
  };
235
- l.addEventListener("load", d), l.addEventListener("error", c);
44
+ a.addEventListener("load", l), a.addEventListener("error", d);
236
45
  return;
237
46
  }
238
- g(e, (d) => {
239
- d !== null ? i(d) : r();
47
+ _(e, (l) => {
48
+ var d;
49
+ l !== null ? ((d = p(e)) == null || d.remove(), i(l)) : n();
240
50
  });
241
51
  }).finally(() => {
242
- s.delete(e);
52
+ f.delete(e);
243
53
  });
244
- return s.set(e, t), t;
54
+ return f.set(e, r), r;
245
55
  }
246
- function U(e) {
247
- const n = document.getElementsByTagName("script");
248
- for (let o = 0; o < n.length; o++)
249
- if (n[o].src === e)
250
- return n[o];
56
+ function p(e) {
57
+ const o = document.getElementsByTagName("script");
58
+ for (let t = 0; t < o.length; t++)
59
+ if (o[t].src === new URL(e, document.baseURI).href)
60
+ return o[t];
251
61
  return null;
252
62
  }
253
- function f() {
254
- return typeof window < "u" && typeof window.LandingPageEditor == "function";
63
+ const w = "https://v4.email-assets.topol.io/loader/build.js", u = {
64
+ production: w,
65
+ dev: w,
66
+ staging: w
67
+ }, A = "https://d10h8ga60f7b91.cloudfront.net/preview-app-{stage}/loader/build.js";
68
+ class h extends Error {
69
+ }
70
+ let s, y = Promise.resolve();
71
+ function S(e) {
72
+ if ((e == null ? void 0 : e.loaderUrl) !== void 0) {
73
+ if (!e.loaderUrl.trim())
74
+ throw new Error("[@topol.io/editor] loaderUrl must not be empty.");
75
+ return e.loaderUrl;
76
+ }
77
+ const o = (e == null ? void 0 : e.stage) ?? "production", r = typeof o == "number" || /^\d+$/.test(o) ? A.replace("{stage}", String(o)) : u[o];
78
+ if (!r)
79
+ throw new Error(`[@topol.io/editor] Unsupported stage "${o}". Use a supported stage or loaderUrl.`);
80
+ return r;
81
+ }
82
+ function O(e, o) {
83
+ const t = y.then(async () => {
84
+ try {
85
+ return await v(e);
86
+ } catch (r) {
87
+ if (r instanceof h || o === void 0)
88
+ throw r;
89
+ const n = await v(o);
90
+ return s == null || s.urls.add(new URL(e, document.baseURI).href), n;
91
+ }
92
+ });
93
+ return y = t.catch(() => {
94
+ }), t;
95
+ }
96
+ async function v(e) {
97
+ const o = new URL(e, document.baseURI).href;
98
+ if (s) {
99
+ if (s.urls.has(o))
100
+ return s.factory;
101
+ throw new h("[@topol.io/editor] Editor v4 supports one loader URL per page. Reload the page to switch environments.");
102
+ }
103
+ const t = o === new URL(u.production, document.baseURI).href && typeof window.TopolEmailEditor == "function";
104
+ if (!t && (typeof window.TopolEmailEditor == "function" || Array.from(document.scripts).some((n) => n.src === o)))
105
+ throw new h("[@topol.io/editor] Cannot initialize from a host-provided loader with unknown lifecycle. Remove the script, reload the page, and let EmailEditor.init load the requested URL.");
106
+ if (await U(e, () => t), typeof window.TopolEmailEditor != "function") {
107
+ for (const n of Array.from(document.scripts))
108
+ n.src === o && n.remove();
109
+ throw new Error("[@topol.io/editor] The loader did not define window.TopolEmailEditor. Use an editor v4 loader.");
110
+ }
111
+ const r = window.TopolEmailEditor;
112
+ return s = { urls: /* @__PURE__ */ new Set([o]), factory: r }, r;
255
113
  }
256
114
  const C = {
115
+ async init(e, o) {
116
+ var m, E;
117
+ if (typeof window > "u" || typeof document > "u")
118
+ throw new Error("[@topol.io/editor] EmailEditor.init requires a browser. Call it after mounting.");
119
+ if (!((m = e == null ? void 0 : e.config) != null && m.authorize))
120
+ throw new Error("[@topol.io/editor] Editor v4 requires { config: { authorize, ... }, onSave, ... }. See the v2 migration guide.");
121
+ const t = e.config.authorize.userId;
122
+ if (typeof t == "string" ? !/^[A-Za-z0-9_-]+$/.test(t) : !Number.isInteger(t) || t < 0)
123
+ throw new Error("[@topol.io/editor] authorize.userId must be a URL-safe string or a non-negative integer.");
124
+ if ((E = e.config.cloud) != null && E.enabled && typeof e.getNonce != "function")
125
+ throw new Error("[@topol.io/editor] Cloud mode requires a top-level getNonce callback returning Promise<string>.");
126
+ const r = S(o), n = (o == null ? void 0 : o.loaderUrl) === void 0 && r !== u.production ? u.production : void 0, i = await O(r, n), { onClose: a, onError: l, ...d } = e, c = i(d);
127
+ let L;
128
+ return Object.assign(c, {
129
+ destroy: () => L ?? (L = Promise.resolve().then(() => c.close()))
130
+ });
131
+ }
132
+ }, N = "https://v1.page-assets.topol.io/topol-lpe.js";
133
+ function R() {
134
+ return typeof window < "u" && typeof window.LandingPageEditor == "function";
135
+ }
136
+ const j = {
257
137
  /**
258
138
  * Inits Landing Page Editor.
259
139
  *
@@ -261,24 +141,17 @@ const C = {
261
141
  * @param pluginOptions - Plugin options (reserved for future staging/dev URL support)
262
142
  * @returns Promise that resolves with the editor instance
263
143
  */
264
- init: async (e, n) => {
265
- var i;
266
- if (await D(O, f), !f())
144
+ init: async (e, o) => {
145
+ var a;
146
+ if (await U(N, R), !R())
267
147
  throw new Error("[@topol.io/editor] topol-lpe.js loaded but window.LandingPageEditor is not defined.");
268
- let o = !1;
269
- const t = window.LandingPageEditor({
270
- ...e,
271
- onClose() {
272
- var l;
273
- o || (l = e.onClose) == null || l.call(e);
274
- }
275
- }), r = ((i = t.destroy) == null ? void 0 : i.bind(t)) ?? (() => t.close());
276
- return t.destroy = () => (o = !0, r()), t;
148
+ const { onClose: t, ...r } = e, n = window.LandingPageEditor(r), i = ((a = n.destroy) == null ? void 0 : a.bind(n)) ?? (() => n.close());
149
+ return n.destroy = () => i(), n;
277
150
  }
278
- }, I = R;
151
+ }, D = C;
279
152
  export {
280
- R as EmailEditor,
281
- C as LandingPageEditor,
282
- I as TopolPlugin,
283
- I as default
153
+ C as EmailEditor,
154
+ j as LandingPageEditor,
155
+ D as TopolPlugin,
156
+ D as default
284
157
  };
@@ -0,0 +1 @@
1
+ (function(a,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(a=typeof globalThis<"u"?globalThis:a||self,u(a.TopolPlugin={}))})(this,function(a){"use strict";function u(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var _=function(o,t,n){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("script");typeof t=="function"&&(n=t,t={}),t=t||{},n=n||function(){},i.type=t.type||"text/javascript",i.charset=t.charset||"utf8",i.async="async"in t?!!t.async:!0,i.src=o,t.attrs&&I(i,t.attrs),t.text&&(i.text=""+t.text);var d="onload"in i?g:S;d(i,n),i.onload||g(i,n),r.appendChild(i)};function I(e,o){for(var t in o)e.setAttribute(t,o[t])}function g(e,o){e.onload=function(){this.onerror=this.onload=null,o(null,e)},e.onerror=function(){this.onerror=this.onload=null,o(new Error("Failed to load "+this.src),e)}}function S(e,o){e.onreadystatechange=function(){this.readyState!="complete"&&this.readyState!="loaded"||(this.onreadystatechange=null,o(null,e))}}const A=u(_),m=new Map;function p(e,o){if(o())return Promise.resolve();const t=m.get(e);if(t)return t;const n=new Promise((r,i)=>{const d=typeof document<"u"?y(e):null;if(d){const c=()=>{f(),r()},l=()=>{f(),d.remove(),i(new Error(`Failed to load script: ${e}`))},f=()=>{d.removeEventListener("load",c),d.removeEventListener("error",l)};d.addEventListener("load",c),d.addEventListener("error",l);return}A(e,c=>{var l;c!==null?((l=y(e))==null||l.remove(),i(c)):r()})}).finally(()=>{m.delete(e)});return m.set(e,n),n}function y(e){const o=document.getElementsByTagName("script");for(let t=0;t<o.length;t++)if(o[t].src===new URL(e,document.baseURI).href)return o[t];return null}const h="https://v4.email-assets.topol.io/loader/build.js",w={production:h,dev:h,staging:h},O="https://d10h8ga60f7b91.cloudfront.net/preview-app-{stage}/loader/build.js";class E extends Error{}let s,v=Promise.resolve();function j(e){if((e==null?void 0:e.loaderUrl)!==void 0){if(!e.loaderUrl.trim())throw new Error("[@topol.io/editor] loaderUrl must not be empty.");return e.loaderUrl}const o=(e==null?void 0:e.stage)??"production",n=typeof o=="number"||/^\d+$/.test(o)?O.replace("{stage}",String(o)):w[o];if(!n)throw new Error(`[@topol.io/editor] Unsupported stage "${o}". Use a supported stage or loaderUrl.`);return n}function C(e,o){const t=v.then(async()=>{try{return await R(e)}catch(n){if(n instanceof E||o===void 0)throw n;const r=await R(o);return s==null||s.urls.add(new URL(e,document.baseURI).href),r}});return v=t.catch(()=>{}),t}async function R(e){const o=new URL(e,document.baseURI).href;if(s){if(s.urls.has(o))return s.factory;throw new E("[@topol.io/editor] Editor v4 supports one loader URL per page. Reload the page to switch environments.")}const t=o===new URL(w.production,document.baseURI).href&&typeof window.TopolEmailEditor=="function";if(!t&&(typeof window.TopolEmailEditor=="function"||Array.from(document.scripts).some(r=>r.src===o)))throw new E("[@topol.io/editor] Cannot initialize from a host-provided loader with unknown lifecycle. Remove the script, reload the page, and let EmailEditor.init load the requested URL.");if(await p(e,()=>t),typeof window.TopolEmailEditor!="function"){for(const r of Array.from(document.scripts))r.src===o&&r.remove();throw new Error("[@topol.io/editor] The loader did not define window.TopolEmailEditor. Use an editor v4 loader.")}const n=window.TopolEmailEditor;return s={urls:new Set([o]),factory:n},n}const U={async init(e,o){var T,b;if(typeof window>"u"||typeof document>"u")throw new Error("[@topol.io/editor] EmailEditor.init requires a browser. Call it after mounting.");if(!((T=e==null?void 0:e.config)!=null&&T.authorize))throw new Error("[@topol.io/editor] Editor v4 requires { config: { authorize, ... }, onSave, ... }. See the v2 migration guide.");const t=e.config.authorize.userId;if(typeof t=="string"?!/^[A-Za-z0-9_-]+$/.test(t):!Number.isInteger(t)||t<0)throw new Error("[@topol.io/editor] authorize.userId must be a URL-safe string or a non-negative integer.");if((b=e.config.cloud)!=null&&b.enabled&&typeof e.getNonce!="function")throw new Error("[@topol.io/editor] Cloud mode requires a top-level getNonce callback returning Promise<string>.");const n=j(o),r=(o==null?void 0:o.loaderUrl)===void 0&&n!==w.production?w.production:void 0,i=await C(n,r),{onClose:d,onError:c,...l}=e,f=i(l);let z;return Object.assign(f,{destroy:()=>z??(z=Promise.resolve().then(()=>f.close()))})}},N="https://v1.page-assets.topol.io/topol-lpe.js";function L(){return typeof window<"u"&&typeof window.LandingPageEditor=="function"}const D={init:async(e,o)=>{var d;if(await p(N,L),!L())throw new Error("[@topol.io/editor] topol-lpe.js loaded but window.LandingPageEditor is not defined.");const{onClose:t,...n}=e,r=window.LandingPageEditor(n),i=((d=r.destroy)==null?void 0:d.bind(r))??(()=>r.close());return r.destroy=()=>i(),r}},P=U;a.EmailEditor=U,a.LandingPageEditor=D,a.TopolPlugin=P,a.default=P,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -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";