@topol.io/editor 1.0.0-alpha.9 → 1.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.
Files changed (72) hide show
  1. package/README.md +160 -97
  2. package/dist/index.js +171 -0
  3. package/dist/types/src/email-editor/index.d.ts +16 -102
  4. package/dist/types/src/landing-page-editor/constants.d.ts +1 -1
  5. package/dist/types/src/landing-page-editor/index.d.ts +10 -5
  6. package/dist/types/src/landing-page-editor/schemas/api/apiSchema.d.ts +5 -11
  7. package/dist/types/src/landing-page-editor/schemas/contentBlock/contentBlockScheme.d.ts +34 -18
  8. package/dist/types/src/landing-page-editor/schemas/language/languageSchema.d.ts +1 -1
  9. package/dist/types/src/landing-page-editor/schemas/mjmlStore/mjmlStoreSchema.d.ts +8 -6
  10. package/dist/types/src/landing-page-editor/schemas/notification/notificationSchema.d.ts +0 -1
  11. package/dist/types/src/landing-page-editor/schemas/openAI/openAISchema.d.ts +1 -2
  12. package/dist/types/src/landing-page-editor/schemas/pluginOptions/pluginOptionsSchema.d.ts +65 -21
  13. package/dist/types/src/landing-page-editor/schemas/premadeSection/premadeSectionSchema.d.ts +30 -0
  14. package/dist/types/src/landing-page-editor/schemas/template/blocks/buttonBlockSchema.d.ts +687 -5
  15. package/dist/types/src/landing-page-editor/schemas/template/blocks/carouselBlockSchema.d.ts +9 -2
  16. package/dist/types/src/landing-page-editor/schemas/template/blocks/dividerBlockSchema.d.ts +11 -3
  17. package/dist/types/src/landing-page-editor/schemas/template/blocks/formBlockSchema.d.ts +1069 -0
  18. package/dist/types/src/landing-page-editor/schemas/template/blocks/imageAnGifBlockSchema.d.ts +35 -19
  19. package/dist/types/src/landing-page-editor/schemas/template/blocks/rawBlockSchema.d.ts +9 -1
  20. package/dist/types/src/landing-page-editor/schemas/template/blocks/socialBlockSchema.d.ts +11 -3
  21. package/dist/types/src/landing-page-editor/schemas/template/blocks/spacerBlockSchema.d.ts +18 -10
  22. package/dist/types/src/landing-page-editor/schemas/template/blocks/textBlockSchema.d.ts +9 -1
  23. package/dist/types/src/landing-page-editor/schemas/template/blocks/videoBlockSchema.d.ts +9 -1
  24. package/dist/types/src/landing-page-editor/schemas/template/commonSchema.d.ts +28 -8
  25. package/dist/types/src/landing-page-editor/schemas/template/navbarBlocks/navbarCTASchema.d.ts +335 -0
  26. package/dist/types/src/landing-page-editor/schemas/template/navbarBlocks/navbarHamburgerSchema.d.ts +1109 -0
  27. package/dist/types/src/landing-page-editor/schemas/template/navbarBlocks/navbarLogoSchema.d.ts +252 -0
  28. package/dist/types/src/landing-page-editor/schemas/template/navbarBlocks/navbarMenuSchema.d.ts +1209 -0
  29. package/dist/types/src/landing-page-editor/schemas/template/settingsSchema.d.ts +4058 -546
  30. package/dist/types/src/landing-page-editor/schemas/template/structure/blockSchema.d.ts +5007 -2328
  31. package/dist/types/src/landing-page-editor/schemas/template/structure/columnSchema.d.ts +5501 -2412
  32. package/dist/types/src/landing-page-editor/schemas/template/structure/navbarSchema.d.ts +4394 -0
  33. package/dist/types/src/landing-page-editor/schemas/template/structure/rowSchema.d.ts +11094 -0
  34. package/dist/types/src/landing-page-editor/schemas/template/structure/sectionSchema.d.ts +8602 -3337
  35. package/dist/types/src/landing-page-editor/schemas/template/styleSchema.d.ts +55 -44
  36. package/dist/types/src/landing-page-editor/schemas/templateSchema.d.ts +34865 -48464
  37. package/dist/types/src/landing-page-editor/schemas/templateSettings/templateSettingsSchema.d.ts +4304 -794
  38. package/dist/types/src/landing-page-editor/schemas/theme/themeSchema.d.ts +6 -1
  39. package/dist/types/src/landing-page-editor/schemas/utils/cssValue.d.ts +21 -0
  40. package/dist/types/src/landing-page-editor/schemas/utils/transformBorder.d.ts +10 -5
  41. package/dist/types/src/main.d.ts +28 -108
  42. package/dist/types/types/API/API.d.ts +8 -9
  43. package/dist/types/types/APIBlocks/APIBlocks.d.ts +9 -0
  44. package/dist/types/types/Auth/IAuthorize.d.ts +6 -0
  45. package/dist/types/types/Auth/INonceAuthCallbacks.d.ts +10 -0
  46. package/dist/types/types/Callbacks/ICallbackPayloads.d.ts +27 -23
  47. package/dist/types/types/Callbacks/IEmailCallbacks.d.ts +73 -155
  48. package/dist/types/types/Cloud/ICloudOptions.d.ts +32 -0
  49. package/dist/types/types/ContentBlock/IContentBlockOptions.d.ts +1 -1
  50. package/dist/types/types/Countdown/ICountdownOptions.d.ts +48 -0
  51. package/dist/types/types/{ITopolOptions.d.ts → IEmailConfig.d.ts} +80 -28
  52. package/dist/types/types/IEmailEditorInstance.d.ts +64 -0
  53. package/dist/types/types/IEmailOptions.d.ts +7 -0
  54. package/dist/types/types/Language/Language.d.ts +1 -1
  55. package/dist/types/types/MergeTag/IMergeTag.d.ts +18 -0
  56. package/dist/types/types/Notification/INotification.d.ts +2 -1
  57. package/dist/types/types/Sections/ISections.d.ts +41 -0
  58. package/dist/types/types/Shortcuts/EditorShortcut.d.ts +4 -0
  59. package/dist/types/types/Theme/ITheme.d.ts +12 -2
  60. package/dist/types/types/landing-page/ILandingPageEditorInstance.d.ts +65 -5
  61. package/dist/types/types/landing-page/ILandingPageOptions.d.ts +15 -12
  62. package/logo.svg +1 -0
  63. package/package.json +11 -13
  64. package/dist/topol-plugin.es.js +0 -277
  65. package/dist/topol-plugin.umd.js +0 -1
  66. package/dist/types/src/landing-page-editor/schemas/helpdesk/helpdeskSchema.d.ts +0 -8
  67. package/dist/types/src/landing-page-editor/schemas/premadeBlock/premadeBlockSchema.d.ts +0 -59750
  68. package/dist/types/src/landing-page-editor/schemas/savedBlock/savedBlockApiSchema.d.ts +0 -44831
  69. package/dist/types/src/landing-page-editor/schemas/savedBlock/savedBlockSchema.d.ts +0 -59725
  70. package/dist/types/src/landing-page-editor/schemas/template/blocks/index.d.ts +0 -12
  71. package/dist/types/types/ITopolPlugin.d.ts +0 -44
  72. package/dist/types/types/SavedBlock/ISavedBlock.d.ts +0 -6
package/README.md CHANGED
@@ -1,121 +1,184 @@
1
+ <p align="center">
1
2
  <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
+ <img src="https://cdn.jsdelivr.net/npm/@topol.io/editor@1/logo.svg" alt="Topol" width="235" height="60">
3
4
  </a>
5
+ </p>
4
6
 
5
- ---
7
+ # @topol.io/editor
6
8
 
7
- Easy and quick! Drag and drop HTML editor and builder for beautiful responsive email templates.
9
+ `1.x` targets **Email Editor v4**. Coming from `0.3` or a 1.x alpha before `1.0.0-alpha.10`,
10
+ see [Migrating from 0.3 or an early 1.x alpha](#migrating-from-03-or-an-early-1x-alpha).
8
11
 
9
- # Documentation
10
-
11
- ## Installation
12
-
13
- Install Editor from NPM using:
14
-
15
- ```sh
16
- npm install @topol.io/editor
17
-
18
- //or
12
+ ```ts
13
+ import { EmailEditor } from "@topol.io/editor";
19
14
 
20
- yarn add @topol.io/editor
15
+ const editor = await EmailEditor.init({
16
+ config: {
17
+ authorize: { apiKey: "your-api-key", entityId: "user-123" },
18
+ },
19
+ async onSave({ json, html, mutations, syncedSections }) {
20
+ // Await your own backend's persistence here. A rejection shows a save error.
21
+ console.log(json, html, mutations, syncedSections);
22
+ },
23
+ onEditorError({ source, message, detail }) {
24
+ console.error(source, message, detail);
25
+ },
26
+ });
27
+ await editor.render("#editor"); // Container must exist and have a height.
28
+ // onInit reports successful editor authentication; render only mounts the iframe.
29
+ await editor.load(templateJson);
30
+ await editor.save({ langCode: "en" });
31
+ await editor.destroy(); // When closing/unmounting, not immediately after render.
21
32
  ```
22
33
 
23
- ## Usage
34
+ Every `init` creates an independent instance. Host methods return promises, including
35
+ `getMutations()`, which resolves to `{ code, primary }[]`. Use instance methods for
36
+ `setSavedSections`, `refreshSyncedSections`, `setMergeTags`, `translateLanguage(code,
37
+ sourceCode?)`, `translateAllLanguages`, and other editor actions.
38
+
39
+ ## Nonce authentication
24
40
 
25
- Add HTML element Editor will load to
41
+ Passing a `getNonce` callback switches authentication from the public key alone to
42
+ short-lived `nc_` nonces minted on your backend from the `sk_` secret. Nothing else
43
+ changes: templates, autosaves, images, comments and sections keep using your own
44
+ `api.*` endpoints and callbacks. There is no separate option; the presence of the
45
+ callback enables it.
26
46
 
27
- ```html
28
- <div id="app" style="position: absolute; width: 100%; height: 100%"></div>
47
+ ```ts
48
+ const editor = await EmailEditor.init({
49
+ config: { authorize: { apiKey: "pk_your-public-key", entityId: "user-123" } },
50
+ async getNonce() {
51
+ // Your backend calls Topol's POST /auth/nonce with the sk_ secret and this entityId.
52
+ const response = await fetch("/api/topol/nonce", { method: "POST" });
53
+ if (!response.ok) throw new Error("Could not mint a Topol nonce");
54
+ return (await response.json()).nonce; // A fresh nc_ token.
55
+ },
56
+ });
29
57
  ```
30
58
 
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`
59
+ The editor refreshes the nonce before it expires and retries once on a rejected
60
+ nonce. A first nonce that cannot be obtained
61
+ reports `onEditorError` with `source: "authorize"`; a later refresh failure reports
62
+ `source: "nonceAuth"` while the editor keeps working on the last valid nonce.
32
63
 
33
- For more options see the docs for [TopolOptions configuration](https://docs.topol.io/reference/topol-options.html)
64
+ <!-- Hidden until Topol Cloud and the Countdown block are public.
34
65
 
35
- ```js
36
- import TopolPlugin from "@topol.io/editor";
66
+ ## Topol Cloud
37
67
 
38
- const TOPOL_OPTIONS = {
39
- id: "#app",
40
- authorize: {
41
- apiKey: "YOUR_API_TOKEN",
42
- userId: "some-user-id",
68
+ ```ts
69
+ const editor = await EmailEditor.init({
70
+ config: {
71
+ authorize: { apiKey: "pk_your-public-key", entityId: "user-123" },
72
+ cloud: { enabled: true, templateId: 123, features: { images: false } },
43
73
  },
44
- callbacks: {
45
- onSave(json, html) {},
74
+ async getNonce() {
75
+ // Your authenticated backend mints a nonce for this public key and user.
76
+ const response = await fetch("/api/topol/nonce", { method: "POST" });
77
+ if (!response.ok) throw new Error("Could not authorize Topol Cloud");
78
+ const { nonce } = await response.json();
79
+ return nonce; // A fresh nc_ token. Keep sk_ secrets on the server.
46
80
  },
47
- };
48
-
49
- TopolPlugin.init(TOPOL_OPTIONS);
81
+ onCloudSave({ templateId, name, langCode }) {
82
+ console.log("Stored in Cloud:", templateId, name, langCode);
83
+ },
84
+ onCloudTemplateChange({ type, templateId, name, folderId }) {
85
+ console.log(type, templateId, name, folderId);
86
+ },
87
+ });
88
+ await editor.render("#editor");
50
89
  ```
51
90
 
52
- ## Call Topol Plugin actions
53
-
54
- To call actions to the editor import:
91
+ Enabling Cloud activates templates, autosaves, images, comments, sections,
92
+ multilanguage, and test-send. Set a feature to `false` to use external behavior.
93
+ Omit `cloud.templateId` to start in the Cloud template browser. Cloud requires the
94
+ `getNonce` callback from nonce authentication above; `init` rejects without it. The
95
+ editor handles nonce refresh, persistence, and its Cloud recovery UI; this package
96
+ supplies the host bridge.
55
97
 
56
- ```js
57
- import { TopolPlugin } from "@topol.io/editor";
98
+ ## Countdown block
58
99
 
59
- TopolPlugin.save();
60
- ```
61
-
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
90
-
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.
100
+ The Countdown block is a paid add-on rolled out per user. It appears only when the
101
+ add-on flag your backend put into the editor nonce is set, and it needs `templateId`.
102
+ The optional `countdown` object adapts the block to your email service provider:
118
103
 
119
104
  ```ts
120
- import { ITopolOptions, INotification, ISavedBlock } from "@topol.io/editor";
105
+ const editor = await EmailEditor.init({
106
+ config: {
107
+ authorize: { apiKey: "pk_your-public-key", entityId: "user-123" },
108
+ templateId: 123,
109
+ countdown: {
110
+ defaultColors: { background: "#ffffff", digits: "#000000", accent: "#2b66b3" },
111
+ styleThumbnailBase: "https://cdn.example.com/countdown-styles",
112
+ mergeTag: "*|CONTACT_ID|*",
113
+ dateMergeTags: [{ label: "From send", value: "*|SEND_DATE+{seconds}|*" }],
114
+ },
115
+ },
116
+ async getNonce() {
117
+ /* ... */
118
+ },
119
+ });
121
120
  ```
121
+
122
+ - `defaultColors` — palette of newly created countdowns; any subset of `background`,
123
+ `digits`, `labels`, `accent` as hex colors (`#RGB`, `#RRGGBB`, `#RRGGBBAA`). Unset
124
+ colors keep the editor defaults.
125
+ - `styleThumbnailBase` — base URL of your own style thumbnails; the editor loads
126
+ `{base}/{style}.gif` for each of the ten styles.
127
+ - `mergeTag` — merge tag identifying the recipient of an evergreen countdown, stored
128
+ in the template as part of the countdown image URL (`?key={tag}`). Prefer a stable
129
+ contact ID over the email address. At most 100 characters, no quotes. Unset = the
130
+ recipient's email address in the syntax of `emailServiceProvider`.
131
+ - `dateMergeTags` — merge tags that can supply the end date of a dynamic countdown
132
+ (for automations); without them the editor does not offer the dynamic type.
133
+ `{seconds}` in a `value` is replaced with the countdown length the user sets. The
134
+ value goes into the URL verbatim: at most 200 characters, no quotes, `<`, `>` or `&`.
135
+
136
+ The types are exported as `ICountdownOptions`, `ICountdownDefaultColors` and
137
+ `ICountdownDateMergeTag`. Details and the ESP requirements are in the
138
+ [option reference](https://docs.topol.io/email-editor/reference/topol-options#countdown).
139
+
140
+ -->
141
+
142
+ ## Loader selection
143
+
144
+ The default is `https://v4.email-assets.topol.io/loader/build.js`.
145
+ Build-time overrides use `VITE_TOPOL_V4_URL`, `VITE_TOPOL_V4_DEV_URL`, and
146
+ `VITE_TOPOL_V4_STAGING_URL`; old `VITE_TOPOL_URL` values are ignored to prevent
147
+ accidentally bundling a v3 loader.
148
+ Pass `{ loaderUrl: 'https://your-preview/loader/build.js' }` as the second argument
149
+ to `init` to select a local or preview v4 loader. Explicit URLs never fall back.
150
+ Numeric stages still select PR previews; loader failures fall back to v4 production
151
+ only before a runtime has been initialized. Each page supports one loader URL;
152
+ switching environments requires a page reload, even after destroying all instances.
153
+ Let `EmailEditor.init` insert custom loader scripts. Host-inserted scripts with unknown
154
+ lifecycle are rejected immediately; an already available production runtime can be reused.
155
+ These runtime conflicts reject without falling back to another environment.
156
+ `dev` and `staging` use the v4 release loader unless their build-time
157
+ `VITE_TOPOL_V4_DEV_URL` / `VITE_TOPOL_V4_STAGING_URL` overrides are configured.
158
+ The upstream local loader uses its host page's origin for the iframe: serve/proxy
159
+ the editor at that origin, or build a loader with an explicit iframe URL.
160
+
161
+ ## Migrating from 0.3 or an early 1.x alpha
162
+
163
+ - `init({ id, authorize, callbacks })` → `init({ config: { authorize }, ...callbacks })`, then `instance.render(container)`.
164
+ - Singleton methods → methods on the returned instance. `save('en')` → `save({ langCode: 'en' })`.
165
+ - All callbacks receive zero arguments or one object. `onSave(json, html)` → `onSave({ json, html })`.
166
+ - `onClose` → `onEditorClose`; `onError(type, message, responseBody)` → `onEditorError({ source, message, detail })`.
167
+ - `savedBlocks` / `setSavedBlocks` → `savedSections` / `setSavedSections`.
168
+ - `onBlockSave/Remove/Edit` → `onSavedSectionSave/Remove/Edit` with `{ section }` / `{ id }` payloads.
169
+ - `premadeBlocks` → `premadeSections`; replace `premadeBlocksNoOverwrite` with `{ blocks, override }`.
170
+ - `syncedRowsEnable` / `refreshSyncedRows` → `syncedSectionsEnabled` / `refreshSyncedSections`.
171
+ - `api.SAVED_BLOCKS` → `api.SAVED_SECTIONS`; `api.SYNCED_ROWS` is removed. Legacy SAVE/LOAD/PREVIEW and singular autosave endpoints are removed.
172
+ - Language mutations and `defaultTemplateSettings.langs` use `code`, not `key`.
173
+ - `topBarOptions` → `hideTopbarControls` (a list of controls to hide).
174
+ - `authorize.userId` → `authorize.entityId`, which must be a non-negative integer or match `[A-Za-z0-9_-]+`. `userId` is no longer read.
175
+ - `hideControlPanel` / `showControlPanelExpand` / `toggleControlPanel()` → `hideSelectionPanel` / `hideSelectionPanelExpand` (inverted) / `toggleSelectionPanel()`. The old names are removed.
176
+
177
+ The `TopolPlugin` alias and the default export are removed; import the named `EmailEditor`.
178
+ The packages are ESM-only: the UMD build and its `window.TopolPlugin` global are gone, and
179
+ `require()` needs Node 20.19+ / 22.12+.
180
+ `LandingPageEditor` retains its loader. Every instance method returns a Promise;
181
+ `save()` settles once the save has finished, including your `onSave` Promise, and
182
+ rejects with `err.code === "SAVE_IN_PROGRESS"` while another save runs. Pass `getNonce`
183
+ next to the other callbacks to turn nonce authentication on, and `{ loaderUrl }` as the
184
+ second argument of `init()` to load a preview or local build (one loader URL per page).
package/dist/index.js ADDED
@@ -0,0 +1,171 @@
1
+ function T(e) {
2
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
3
+ }
4
+ var _ = function(t, o, n) {
5
+ var i = document.head || document.getElementsByTagName("head")[0], r = document.createElement("script");
6
+ typeof o == "function" && (n = o, o = {}), o = o || {}, n = n || function() {
7
+ }, r.type = o.type || "text/javascript", r.charset = o.charset || "utf8", r.async = "async" in o ? !!o.async : !0, r.src = t, o.attrs && A(r, o.attrs), o.text && (r.text = "" + o.text);
8
+ var d = "onload" in r ? p : S;
9
+ d(r, n), r.onload || p(r, n), i.appendChild(r);
10
+ };
11
+ function A(e, t) {
12
+ for (var o in t)
13
+ e.setAttribute(o, t[o]);
14
+ }
15
+ function p(e, t) {
16
+ e.onload = function() {
17
+ this.onerror = this.onload = null, t(null, e);
18
+ }, e.onerror = function() {
19
+ this.onerror = this.onload = null, t(new Error("Failed to load " + this.src), e);
20
+ };
21
+ }
22
+ function S(e, t) {
23
+ e.onreadystatechange = function() {
24
+ this.readyState != "complete" && this.readyState != "loaded" || (this.onreadystatechange = null, t(null, e));
25
+ };
26
+ }
27
+ const N = /* @__PURE__ */ T(_), f = /* @__PURE__ */ new Map();
28
+ function I(e, t) {
29
+ if (t())
30
+ return Promise.resolve();
31
+ const o = f.get(e);
32
+ if (o)
33
+ return o;
34
+ const n = new Promise((i, r) => {
35
+ const d = typeof document < "u" ? U(e) : null;
36
+ if (d) {
37
+ const a = () => {
38
+ l(), i();
39
+ }, s = () => {
40
+ l(), d.remove(), r(new Error(`Failed to load script: ${e}`));
41
+ }, l = () => {
42
+ d.removeEventListener("load", a), d.removeEventListener("error", s);
43
+ };
44
+ d.addEventListener("load", a), d.addEventListener("error", s);
45
+ return;
46
+ }
47
+ N(e, (a) => {
48
+ var s;
49
+ a !== null ? ((s = U(e)) == null || s.remove(), r(a)) : i();
50
+ });
51
+ }).finally(() => {
52
+ f.delete(e);
53
+ });
54
+ return f.set(e, n), n;
55
+ }
56
+ function U(e) {
57
+ const t = document.getElementsByTagName("script");
58
+ for (let o = 0; o < t.length; o++)
59
+ if (t[o].src === new URL(e, document.baseURI).href)
60
+ return t[o];
61
+ return null;
62
+ }
63
+ const w = "https://v4.email-assets.topol.io/loader/build.js", u = {
64
+ production: w,
65
+ dev: w,
66
+ staging: w
67
+ }, C = "https://d10h8ga60f7b91.cloudfront.net/preview-app-{stage}/loader/build.js";
68
+ class h extends Error {
69
+ }
70
+ let c, R = Promise.resolve();
71
+ function D(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 t = (e == null ? void 0 : e.stage) ?? "production", n = typeof t == "number" || /^\d+$/.test(t) ? C.replace("{stage}", String(t)) : u[t];
78
+ if (!n)
79
+ throw new Error(`[@topol.io/editor] Unsupported stage "${t}". Use a supported stage or loaderUrl.`);
80
+ return n;
81
+ }
82
+ function j(e, t) {
83
+ const o = R.then(async () => {
84
+ try {
85
+ return await L(e);
86
+ } catch (n) {
87
+ if (n instanceof h || t === void 0)
88
+ throw n;
89
+ const i = await L(t);
90
+ return c == null || c.urls.add(new URL(e, document.baseURI).href), i;
91
+ }
92
+ });
93
+ return R = o.catch(() => {
94
+ }), o;
95
+ }
96
+ async function L(e) {
97
+ const t = new URL(e, document.baseURI).href;
98
+ if (c) {
99
+ if (c.urls.has(t))
100
+ return c.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 o = t === new URL(u.production, document.baseURI).href && typeof window.TopolEmailEditor == "function";
104
+ if (!o && (typeof window.TopolEmailEditor == "function" || Array.from(document.scripts).some((i) => i.src === t)))
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 I(e, () => o), typeof window.TopolEmailEditor != "function") {
107
+ for (const i of Array.from(document.scripts))
108
+ i.src === t && i.remove();
109
+ throw new Error("[@topol.io/editor] The loader did not define window.TopolEmailEditor. Use an editor v4 loader.");
110
+ }
111
+ const n = window.TopolEmailEditor;
112
+ return c = { urls: /* @__PURE__ */ new Set([t]), factory: n }, n;
113
+ }
114
+ const O = {
115
+ async init(e, t) {
116
+ var g, v;
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 (!((g = e == null ? void 0 : e.config) != null && g.authorize))
120
+ throw new Error("[@topol.io/editor] Editor v4 requires { config: { authorize, ... }, onSave, ... }. See docs/MIGRATION-editor-v4.md.");
121
+ const o = e.config.authorize.entityId;
122
+ if (typeof o == "string" ? !/^[A-Za-z0-9_-]+$/.test(o) : typeof o != "number" || !Number.isInteger(o) || o < 0)
123
+ throw new Error("[@topol.io/editor] authorize.entityId must be a URL-safe string or a non-negative integer.");
124
+ if ((v = e.config.cloud) != null && v.enabled && typeof e.getNonce != "function")
125
+ throw new Error("[@topol.io/editor] cloud.enabled requires nonce authentication: pass a top-level getNonce callback returning Promise<string>.");
126
+ const n = D(t), i = (t == null ? void 0 : t.loaderUrl) === void 0 && n !== u.production ? u.production : void 0, r = await j(n, i), { onClose: d, onError: a, ...s } = e, l = r(s);
127
+ let P;
128
+ return Object.assign(l, {
129
+ destroy: () => P ?? (P = Promise.resolve().then(() => l.close()))
130
+ });
131
+ }
132
+ }, b = "https://v1.page-assets.topol.io/loader/build.js";
133
+ function m() {
134
+ return typeof window < "u" && typeof window.LandingPageEditor == "function";
135
+ }
136
+ let E;
137
+ function y(e) {
138
+ return typeof document < "u" ? new URL(e, document.baseURI).href : e;
139
+ }
140
+ function z(e) {
141
+ if (e !== void 0 && !e.trim())
142
+ throw new Error("[@topol.io/editor] loaderUrl must not be empty.");
143
+ const t = e ?? b;
144
+ if (!m())
145
+ return E = void 0, t;
146
+ if ((E ?? y(b)) !== y(t))
147
+ throw new Error("[@topol.io/editor] The Landing Page Editor supports one loader URL per page. Reload the page to switch environments.");
148
+ return t;
149
+ }
150
+ const x = {
151
+ /**
152
+ * Inits Landing Page Editor.
153
+ *
154
+ * @param options - Configuration options for the editor
155
+ * @param pluginOptions - Plugin options: an explicit `loaderUrl`
156
+ * @returns Promise that resolves with the editor instance
157
+ */
158
+ init: async (e, t) => {
159
+ var a;
160
+ const o = z(t == null ? void 0 : t.loaderUrl);
161
+ if (await I(o, m), !m())
162
+ throw new Error("[@topol.io/editor] The Landing Page Editor loader loaded but window.LandingPageEditor is not defined.");
163
+ E = y(o);
164
+ const { onClose: n, ...i } = e, r = window.LandingPageEditor(i), d = ((a = r.destroy) == null ? void 0 : a.bind(r)) ?? (() => r.close());
165
+ return r.destroy = () => d(), r;
166
+ }
167
+ };
168
+ export {
169
+ O as EmailEditor,
170
+ x as LandingPageEditor
171
+ };
@@ -1,108 +1,22 @@
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";
1
+ import type IEmailOptions from "../../types/IEmailOptions";
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: IEmailOptions) => 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: (lang?: string) => 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
- updateOptions: (options: Partial<ITopolOptions>) => void;
84
- /** Toggle the AI chat feature */
85
- toggleChatAI: () => void;
86
- /** Toggle the autosaves feature */
87
- toggleAutosaves: () => void;
88
- /** Toggle the comments panel */
89
- toggleComments: () => void;
90
- /** Create a new language variant */
91
- createLanguage: (lang: string) => void;
92
- /** Set the primary language */
93
- setPrimaryLanguage: (lang: string) => void;
94
- /** Delete a language variant */
95
- deleteLanguage: (lang: string) => void;
96
- /** Select/switch to a language */
97
- selectLanguage: (lang: string) => void;
98
- /** Get the list of mutations */
99
- getMutations: () => void;
100
- /** Toggle the control panel visibility */
101
- toggleControlPanel: () => void;
102
- /** Update the editor template with new JSON data */
103
- updateTemplate: (json: unknown, options?: {
104
- skipSnapshot?: boolean;
105
- }) => void;
106
- /** Toggle dark mode for the editor */
107
- toggleDarkMode: () => void;
20
+ init(options: IEmailOptions, pluginOptions?: IEmailEditorPluginOptions): Promise<IEmailEditorInstance>;
108
21
  };
22
+ export {};
@@ -1 +1 @@
1
- export declare const LANDING_PAGE_EDITOR_URL = "https://v1.page-assets.topol.io/topol-lpe.js";
1
+ export declare const LANDING_PAGE_EDITOR_URL = "https://v1.page-assets.topol.io/loader/build.js";
@@ -2,7 +2,7 @@ import type ILandingPageOptions from "../../types/landing-page/ILandingPageOptio
2
2
  import type ILandingPageEditorInstance from "../../types/landing-page/ILandingPageEditorInstance";
3
3
  import { Stage } from "../../types/Stage";
4
4
  /**
5
- * Raw zoid component instance created by the CDN runtime (topol-lpe.js).
5
+ * Raw zoid component instance created by the CDN loader (loader/build.js).
6
6
  * It exposes close() rather than destroy(); init() aliases the latter.
7
7
  */
8
8
  type RawLandingPageEditorInstance = Omit<ILandingPageEditorInstance, "destroy"> & {
@@ -15,12 +15,17 @@ declare global {
15
15
  LandingPageEditor: LandingPageEditorFactory;
16
16
  }
17
17
  }
18
- export interface LandingPageEditorPluginOptions {
18
+ export interface ILandingPageEditorPluginOptions {
19
19
  /**
20
20
  * Stage/environment to use. Currently only 'production' is supported for LPE.
21
21
  * This is reserved for future staging/dev URL support.
22
22
  */
23
23
  stage?: Stage;
24
+ /**
25
+ * Explicit loader URL, e.g. a deployed preview or a local build. One loader URL per page:
26
+ * a second `init()` with a different URL rejects until the page is reloaded.
27
+ */
28
+ loaderUrl?: string;
24
29
  }
25
30
  /**
26
31
  * Landing Page Editor - Create landing pages with drag-and-drop editing.
@@ -38,7 +43,7 @@ export interface LandingPageEditorPluginOptions {
38
43
  *
39
44
  * const editor = await LandingPageEditor.init({
40
45
  * config: {
41
- * authorize: { apiKey: 'your-key', userId: 'user-123' },
46
+ * authorize: { apiKey: 'your-key', entityId: 'user-123' },
42
47
  * },
43
48
  * onSave({ json, html }) { console.log('Saved:', json, html); },
44
49
  * onLoaded() { console.log('Template loaded'); }
@@ -59,9 +64,9 @@ export declare const LandingPageEditor: {
59
64
  * Inits Landing Page Editor.
60
65
  *
61
66
  * @param options - Configuration options for the editor
62
- * @param pluginOptions - Plugin options (reserved for future staging/dev URL support)
67
+ * @param pluginOptions - Plugin options: an explicit `loaderUrl`
63
68
  * @returns Promise that resolves with the editor instance
64
69
  */
65
- init: (options: ILandingPageOptions, pluginOptions?: LandingPageEditorPluginOptions) => Promise<ILandingPageEditorInstance>;
70
+ init: (options: ILandingPageOptions, pluginOptions?: ILandingPageEditorPluginOptions) => Promise<ILandingPageEditorInstance>;
66
71
  };
67
72
  export {};