@topol.io/editor 1.0.0-alpha.1 → 1.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +153 -101
- package/dist/topol-plugin.es.js +146 -191
- package/dist/topol-plugin.umd.cjs +1 -0
- package/dist/types/src/core/script-loader.d.ts +15 -0
- package/dist/types/src/email-editor/constants.d.ts +3 -3
- package/dist/types/src/email-editor/index.d.ts +16 -91
- package/dist/types/src/landing-page-editor/constants.d.ts +1 -1
- package/dist/types/src/landing-page-editor/index.d.ts +27 -10
- package/dist/types/src/landing-page-editor/schemas/api/apiSchema.d.ts +5 -10
- package/dist/types/src/landing-page-editor/schemas/contentBlock/contentBlockScheme.d.ts +34 -18
- package/dist/types/src/landing-page-editor/schemas/language/languageSchema.d.ts +1 -1
- package/dist/types/src/landing-page-editor/schemas/mjmlStore/mjmlStoreSchema.d.ts +8 -6
- package/dist/types/src/landing-page-editor/schemas/notification/notificationSchema.d.ts +0 -1
- package/dist/types/src/landing-page-editor/schemas/openAI/openAISchema.d.ts +1 -2
- package/dist/types/src/landing-page-editor/schemas/pluginOptions/pluginOptionsSchema.d.ts +153 -17
- package/dist/types/src/landing-page-editor/schemas/premadeSection/premadeSectionSchema.d.ts +30 -0
- package/dist/types/src/landing-page-editor/schemas/template/blocks/buttonBlockSchema.d.ts +687 -5
- package/dist/types/src/landing-page-editor/schemas/template/blocks/carouselBlockSchema.d.ts +9 -2
- package/dist/types/src/landing-page-editor/schemas/template/blocks/dividerBlockSchema.d.ts +11 -3
- package/dist/types/src/landing-page-editor/schemas/template/blocks/formBlockSchema.d.ts +1069 -0
- package/dist/types/src/landing-page-editor/schemas/template/blocks/imageAnGifBlockSchema.d.ts +35 -19
- package/dist/types/src/landing-page-editor/schemas/template/blocks/rawBlockSchema.d.ts +9 -1
- package/dist/types/src/landing-page-editor/schemas/template/blocks/socialBlockSchema.d.ts +11 -3
- package/dist/types/src/landing-page-editor/schemas/template/blocks/spacerBlockSchema.d.ts +18 -10
- package/dist/types/src/landing-page-editor/schemas/template/blocks/textBlockSchema.d.ts +9 -1
- package/dist/types/src/landing-page-editor/schemas/template/blocks/videoBlockSchema.d.ts +9 -1
- package/dist/types/src/landing-page-editor/schemas/template/commonSchema.d.ts +28 -8
- package/dist/types/src/landing-page-editor/schemas/template/navbarBlocks/navbarCTASchema.d.ts +335 -0
- package/dist/types/src/landing-page-editor/schemas/template/navbarBlocks/navbarHamburgerSchema.d.ts +1109 -0
- package/dist/types/src/landing-page-editor/schemas/template/navbarBlocks/navbarLogoSchema.d.ts +252 -0
- package/dist/types/src/landing-page-editor/schemas/template/navbarBlocks/navbarMenuSchema.d.ts +1209 -0
- package/dist/types/src/landing-page-editor/schemas/template/settingsSchema.d.ts +4058 -546
- package/dist/types/src/landing-page-editor/schemas/template/structure/blockSchema.d.ts +5007 -2328
- package/dist/types/src/landing-page-editor/schemas/template/structure/columnSchema.d.ts +5501 -2412
- package/dist/types/src/landing-page-editor/schemas/template/structure/navbarSchema.d.ts +4394 -0
- package/dist/types/src/landing-page-editor/schemas/template/structure/rowSchema.d.ts +11094 -0
- package/dist/types/src/landing-page-editor/schemas/template/structure/sectionSchema.d.ts +8602 -3337
- package/dist/types/src/landing-page-editor/schemas/template/styleSchema.d.ts +55 -44
- package/dist/types/src/landing-page-editor/schemas/templateSchema.d.ts +34865 -48464
- package/dist/types/src/landing-page-editor/schemas/templateSettings/templateSettingsSchema.d.ts +4305 -794
- package/dist/types/src/landing-page-editor/schemas/theme/themeSchema.d.ts +6 -1
- package/dist/types/src/landing-page-editor/schemas/utils/cssValue.d.ts +21 -0
- package/dist/types/src/landing-page-editor/schemas/utils/transformBorder.d.ts +10 -5
- package/dist/types/src/main.d.ts +28 -101
- package/dist/types/types/API/API.d.ts +10 -9
- package/dist/types/types/APIBlocks/APIBlocks.d.ts +11 -0
- package/dist/types/types/Auth/IAuthorize.d.ts +18 -0
- package/dist/types/types/Auth/INonceAuthCallbacks.d.ts +10 -0
- package/dist/types/types/Callbacks/ICallbackPayloads.d.ts +28 -18
- package/dist/types/types/Callbacks/IEmailCallbacks.d.ts +85 -104
- package/dist/types/types/Cloud/ICloudOptions.d.ts +32 -0
- package/dist/types/types/ContentBlock/IContentBlockOptions.d.ts +1 -1
- package/dist/types/types/Countdown/ICountdownOptions.d.ts +48 -0
- package/dist/types/types/IEmailConfig.d.ts +225 -0
- package/dist/types/types/IEmailEditorInstance.d.ts +68 -0
- package/dist/types/types/IEmailOptions.d.ts +7 -0
- package/dist/types/types/Language/Language.d.ts +6 -1
- package/dist/types/types/MergeTag/IMergeTag.d.ts +18 -0
- package/dist/types/types/Notification/INotification.d.ts +2 -1
- package/dist/types/types/Sections/ISections.d.ts +41 -0
- package/dist/types/types/Shortcuts/EditorShortcut.d.ts +4 -0
- package/dist/types/types/Theme/ITheme.d.ts +12 -2
- package/dist/types/types/landing-page/ILandingPageEditorInstance.d.ts +73 -9
- package/dist/types/types/landing-page/ILandingPageOptions.d.ts +110 -62
- package/package.json +10 -13
- package/dist/topol-plugin.umd.js +0 -1
- package/dist/types/src/landing-page-editor/schemas/helpdesk/helpdeskSchema.d.ts +0 -8
- package/dist/types/src/landing-page-editor/schemas/premadeBlock/premadeBlockSchema.d.ts +0 -59750
- package/dist/types/src/landing-page-editor/schemas/savedBlock/savedBlockApiSchema.d.ts +0 -44831
- package/dist/types/src/landing-page-editor/schemas/savedBlock/savedBlockSchema.d.ts +0 -59725
- package/dist/types/src/landing-page-editor/schemas/template/blocks/index.d.ts +0 -12
- package/dist/types/types/ITopolOptions.d.ts +0 -123
- package/dist/types/types/ITopolPlugin.d.ts +0 -37
- package/dist/types/types/SavedBlock/ISavedBlock.d.ts +0 -6
package/README.md
CHANGED
|
@@ -1,121 +1,173 @@
|
|
|
1
|
-
|
|
2
|
-
<img src="https://storage.googleapis.com/topolio17326/plugin-assets/6320/17326/topol-with-bg.png" alt="Tailwind CSS" width="400" height="120">
|
|
3
|
-
</a>
|
|
1
|
+
# @topol.io/editor — 1.x alpha
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
The 1.x alpha line targets **Email Editor v4** from `1.0.0-alpha.10`. Earlier 1.x
|
|
4
|
+
alphas targeted v3; see [Migration from earlier 1.x alphas](#migration-from-earlier-1x-alphas).
|
|
6
5
|
|
|
7
|
-
|
|
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
|
|
6
|
+
```ts
|
|
7
|
+
import { EmailEditor } from "@topol.io/editor";
|
|
19
8
|
|
|
20
|
-
|
|
9
|
+
const editor = await EmailEditor.init({
|
|
10
|
+
config: {
|
|
11
|
+
authorize: { apiKey: "your-api-key", entityId: "user-123" },
|
|
12
|
+
},
|
|
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);
|
|
16
|
+
},
|
|
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.
|
|
21
26
|
```
|
|
22
27
|
|
|
23
|
-
|
|
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.
|
|
24
32
|
|
|
25
|
-
|
|
33
|
+
## Nonce authentication
|
|
26
34
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
Passing a `getNonce` callback switches authentication from the public key alone to
|
|
36
|
+
short-lived `nc_` nonces minted on your backend from the `sk_` secret. Nothing else
|
|
37
|
+
changes: templates, autosaves, images, comments and sections keep using your own
|
|
38
|
+
`api.*` endpoints and callbacks. There is no separate option; the presence of the
|
|
39
|
+
callback enables it. Topol Cloud is built on top of it and requires the callback.
|
|
30
40
|
|
|
31
|
-
|
|
41
|
+
```ts
|
|
42
|
+
const editor = await EmailEditor.init({
|
|
43
|
+
config: { authorize: { apiKey: "pk_your-public-key", entityId: "user-123" } },
|
|
44
|
+
async getNonce() {
|
|
45
|
+
// Your backend calls Topol's POST /auth/nonce with the sk_ secret and this entityId.
|
|
46
|
+
const response = await fetch("/api/topol/nonce", { method: "POST" });
|
|
47
|
+
if (!response.ok) throw new Error("Could not mint a Topol nonce");
|
|
48
|
+
return (await response.json()).nonce; // A fresh nc_ token.
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
```
|
|
32
52
|
|
|
33
|
-
|
|
53
|
+
The editor refreshes the nonce before it expires and retries once on a rejected
|
|
54
|
+
nonce. A first nonce that cannot be obtained, or `cloud.enabled` without `getNonce`,
|
|
55
|
+
reports `onEditorError` with `source: "authorize"`; a later refresh failure reports
|
|
56
|
+
`source: "nonceAuth"` while the editor keeps working on the last valid nonce.
|
|
34
57
|
|
|
35
|
-
|
|
36
|
-
import TopolPlugin from "@topol.io/editor";
|
|
58
|
+
## Topol Cloud
|
|
37
59
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
apiKey: "
|
|
42
|
-
|
|
60
|
+
```ts
|
|
61
|
+
const editor = await EmailEditor.init({
|
|
62
|
+
config: {
|
|
63
|
+
authorize: { apiKey: "pk_your-public-key", entityId: "user-123" },
|
|
64
|
+
cloud: { enabled: true, templateId: 123, features: { images: false } },
|
|
43
65
|
},
|
|
44
|
-
|
|
45
|
-
|
|
66
|
+
async getNonce() {
|
|
67
|
+
// Your authenticated backend mints a nonce for this public key and user.
|
|
68
|
+
const response = await fetch("/api/topol/nonce", { method: "POST" });
|
|
69
|
+
if (!response.ok) throw new Error("Could not authorize Topol Cloud");
|
|
70
|
+
const { nonce } = await response.json();
|
|
71
|
+
return nonce; // A fresh nc_ token. Keep sk_ secrets on the server.
|
|
46
72
|
},
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
73
|
+
onCloudSave({ templateId, name, langCode }) {
|
|
74
|
+
console.log("Stored in Cloud:", templateId, name, langCode);
|
|
75
|
+
},
|
|
76
|
+
onCloudTemplateChange({ type, templateId, name, folderId }) {
|
|
77
|
+
console.log(type, templateId, name, folderId);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
await editor.render("#editor");
|
|
50
81
|
```
|
|
51
82
|
|
|
52
|
-
|
|
83
|
+
Enabling Cloud activates templates, autosaves, images, comments, sections,
|
|
84
|
+
multilanguage, and test-send. Set a feature to `false` to use external behavior.
|
|
85
|
+
Omit `cloud.templateId` to start in the Cloud template browser. Cloud requires the
|
|
86
|
+
`getNonce` callback from nonce authentication above; `init` rejects without it. The
|
|
87
|
+
editor handles nonce refresh, persistence, and its Cloud recovery UI; this package
|
|
88
|
+
supplies the host bridge.
|
|
53
89
|
|
|
54
|
-
|
|
90
|
+
## Countdown block
|
|
55
91
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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.
|
|
92
|
+
The Countdown block is a paid add-on rolled out per user. It appears only when the
|
|
93
|
+
add-on flag your backend put into the editor nonce is set, and it needs `templateId`.
|
|
94
|
+
The optional `countdown` object adapts the block to your email service provider:
|
|
118
95
|
|
|
119
96
|
```ts
|
|
120
|
-
|
|
97
|
+
const editor = await EmailEditor.init({
|
|
98
|
+
config: {
|
|
99
|
+
authorize: { apiKey: "pk_your-public-key", entityId: "user-123" },
|
|
100
|
+
templateId: 123,
|
|
101
|
+
countdown: {
|
|
102
|
+
defaultColors: { background: "#ffffff", digits: "#000000", accent: "#2b66b3" },
|
|
103
|
+
styleThumbnailBase: "https://cdn.example.com/countdown-styles",
|
|
104
|
+
mergeTag: "*|CONTACT_ID|*",
|
|
105
|
+
dateMergeTags: [{ label: "From send", value: "*|SEND_DATE+{seconds}|*" }],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
async getNonce() {
|
|
109
|
+
/* ... */
|
|
110
|
+
},
|
|
111
|
+
});
|
|
121
112
|
```
|
|
113
|
+
|
|
114
|
+
- `defaultColors` — palette of newly created countdowns; any subset of `background`,
|
|
115
|
+
`digits`, `labels`, `accent` as hex colors (`#RGB`, `#RRGGBB`, `#RRGGBBAA`). Unset
|
|
116
|
+
colors keep the editor defaults.
|
|
117
|
+
- `styleThumbnailBase` — base URL of your own style thumbnails; the editor loads
|
|
118
|
+
`{base}/{style}.gif` for each of the ten styles.
|
|
119
|
+
- `mergeTag` — merge tag identifying the recipient of an evergreen countdown, stored
|
|
120
|
+
in the template as part of the countdown image URL (`?key={tag}`). Prefer a stable
|
|
121
|
+
contact ID over the email address. At most 100 characters, no quotes. Unset = the
|
|
122
|
+
recipient's email address in the syntax of `emailServiceProvider`.
|
|
123
|
+
- `dateMergeTags` — merge tags that can supply the end date of a dynamic countdown
|
|
124
|
+
(for automations); without them the editor does not offer the dynamic type.
|
|
125
|
+
`{seconds}` in a `value` is replaced with the countdown length the user sets. The
|
|
126
|
+
value goes into the URL verbatim: at most 200 characters, no quotes, `<`, `>` or `&`.
|
|
127
|
+
|
|
128
|
+
The types are exported as `ICountdownOptions`, `ICountdownDefaultColors` and
|
|
129
|
+
`ICountdownDateMergeTag`. Details and the ESP requirements are in the
|
|
130
|
+
[option reference](https://docs.topol.io/email-editor/reference/topol-options#countdown).
|
|
131
|
+
|
|
132
|
+
## Loader selection
|
|
133
|
+
|
|
134
|
+
The default is `https://v4.email-assets.topol.io/loader/build.js`.
|
|
135
|
+
Build-time overrides use `VITE_TOPOL_V4_URL`, `VITE_TOPOL_V4_DEV_URL`, and
|
|
136
|
+
`VITE_TOPOL_V4_STAGING_URL`; old `VITE_TOPOL_URL` values are ignored to prevent
|
|
137
|
+
accidentally bundling a v3 loader.
|
|
138
|
+
Pass `{ loaderUrl: 'https://your-preview/loader/build.js' }` as the second argument
|
|
139
|
+
to `init` to select a local or preview v4 loader. Explicit URLs never fall back.
|
|
140
|
+
Numeric stages still select PR previews; loader failures fall back to v4 production
|
|
141
|
+
only before a runtime has been initialized. Each page supports one loader URL;
|
|
142
|
+
switching environments requires a page reload, even after destroying all instances.
|
|
143
|
+
Let `EmailEditor.init` insert custom loader scripts. Host-inserted scripts with unknown
|
|
144
|
+
lifecycle are rejected immediately; an already available production runtime can be reused.
|
|
145
|
+
These runtime conflicts reject without falling back to another environment.
|
|
146
|
+
`dev` and `staging` use the v4 release loader unless their build-time
|
|
147
|
+
`VITE_TOPOL_V4_DEV_URL` / `VITE_TOPOL_V4_STAGING_URL` overrides are configured.
|
|
148
|
+
The upstream local loader uses its host page's origin for the iframe: serve/proxy
|
|
149
|
+
the editor at that origin, or build a loader with an explicit iframe URL.
|
|
150
|
+
|
|
151
|
+
## Migration from earlier 1.x alphas
|
|
152
|
+
|
|
153
|
+
- `init({ id, authorize, callbacks })` → `init({ config: { authorize }, ...callbacks })`, then `instance.render(container)`.
|
|
154
|
+
- Singleton methods → methods on the returned instance. `save('en')` → `save({ langCode: 'en' })`.
|
|
155
|
+
- All callbacks receive zero arguments or one object. `onSave(json, html)` → `onSave({ json, html })`.
|
|
156
|
+
- `onClose` → `onEditorClose`; `onError(type, message, responseBody)` → `onEditorError({ source, message, detail })`.
|
|
157
|
+
- `savedBlocks` / `setSavedBlocks` → `savedSections` / `setSavedSections`.
|
|
158
|
+
- `onBlockSave/Remove/Edit` → `onSavedSectionSave/Remove/Edit` with `{ section }` / `{ id }` payloads.
|
|
159
|
+
- `premadeBlocks` → `premadeSections`; replace `premadeBlocksNoOverwrite` with `{ blocks, override }`.
|
|
160
|
+
- `syncedRowsEnable` / `refreshSyncedRows` → `syncedSectionsEnabled` / `refreshSyncedSections`.
|
|
161
|
+
- `api.SAVED_BLOCKS` → `api.SAVED_SECTIONS`; `api.SYNCED_ROWS` is removed. Legacy SAVE/LOAD/PREVIEW and singular autosave endpoints are removed.
|
|
162
|
+
- Language mutations and `defaultTemplateSettings.langs` use `code`, not `key`.
|
|
163
|
+
- `topBarOptions` → `hideTopbarControls` (a list of controls to hide).
|
|
164
|
+
- `authorize.userId` → `authorize.entityId`, which must be a non-negative integer or match `[A-Za-z0-9_-]+`. `userId` still works as a deprecated alias.
|
|
165
|
+
- `hideControlPanel` / `showControlPanelExpand` / `toggleControlPanel()` → `hideSelectionPanel` / `hideSelectionPanelExpand` (inverted) / `toggleSelectionPanel()`. The old names still work as deprecated aliases.
|
|
166
|
+
|
|
167
|
+
The `TopolPlugin` alias and the default export are removed; import the named `EmailEditor`.
|
|
168
|
+
`LandingPageEditor` retains its loader. Every instance method returns a Promise;
|
|
169
|
+
`save()` settles once the save has finished, including your `onSave` Promise, and
|
|
170
|
+
rejects with `err.code === "SAVE_IN_PROGRESS"` while another save runs. Pass `getNonce`
|
|
171
|
+
next to the other callbacks to turn nonce authentication on, and `{ loaderUrl }` as the
|
|
172
|
+
second argument of `init()` to load a preview or local build (one loader URL per page). Its Cloud
|
|
173
|
+
integration is not enabled by these email-specific changes.
|
package/dist/topol-plugin.es.js
CHANGED
|
@@ -1,216 +1,171 @@
|
|
|
1
|
-
function
|
|
1
|
+
function T(e) {
|
|
2
2
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
3
3
|
}
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
typeof o == "function" && (
|
|
7
|
-
},
|
|
8
|
-
var
|
|
9
|
-
r
|
|
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
10
|
};
|
|
11
|
-
function
|
|
12
|
-
for (var o in
|
|
13
|
-
e.setAttribute(o,
|
|
11
|
+
function A(e, t) {
|
|
12
|
+
for (var o in t)
|
|
13
|
+
e.setAttribute(o, t[o]);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function p(e, t) {
|
|
16
16
|
e.onload = function() {
|
|
17
|
-
this.onerror = this.onload = null,
|
|
17
|
+
this.onerror = this.onload = null, t(null, e);
|
|
18
18
|
}, e.onerror = function() {
|
|
19
|
-
this.onerror = this.onload = null,
|
|
19
|
+
this.onerror = this.onload = null, t(new Error("Failed to load " + this.src), e);
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function S(e, t) {
|
|
23
23
|
e.onreadystatechange = function() {
|
|
24
|
-
this.readyState != "complete" && this.readyState != "loaded" || (this.onreadystatechange = null,
|
|
24
|
+
this.readyState != "complete" && this.readyState != "loaded" || (this.onreadystatechange = null, t(null, e));
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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 z(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;
|
|
44
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;
|
|
45
81
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
82
|
+
function D(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
|
+
}
|
|
55
92
|
});
|
|
93
|
+
return R = o.catch(() => {
|
|
94
|
+
}), o;
|
|
56
95
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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 ?? e.config.authorize.userId;
|
|
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 = z(t), i = (t == null ? void 0 : t.loaderUrl) === void 0 && n !== u.production ? u.production : void 0, r = await D(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()))
|
|
78
130
|
});
|
|
79
|
-
}),
|
|
80
|
-
/** Trigger the save callback with current editor content */
|
|
81
|
-
save: () => {
|
|
82
|
-
window.TopolPlugin.save();
|
|
83
|
-
},
|
|
84
|
-
/** Load a template JSON into the editor */
|
|
85
|
-
load: (e) => {
|
|
86
|
-
window.TopolPlugin.load(e);
|
|
87
|
-
},
|
|
88
|
-
/** Toggle the preview mode */
|
|
89
|
-
togglePreview: () => {
|
|
90
|
-
window.TopolPlugin.togglePreview();
|
|
91
|
-
},
|
|
92
|
-
/** Toggle between desktop and mobile preview sizes */
|
|
93
|
-
togglePreviewSize: () => {
|
|
94
|
-
window.TopolPlugin.togglePreviewSize();
|
|
95
|
-
},
|
|
96
|
-
/** Select a file from the custom file manager */
|
|
97
|
-
chooseFile: (e) => {
|
|
98
|
-
window.TopolPlugin.chooseFile(e);
|
|
99
|
-
},
|
|
100
|
-
/** Undo the last action */
|
|
101
|
-
undo: () => {
|
|
102
|
-
window.TopolPlugin.undo();
|
|
103
|
-
},
|
|
104
|
-
/** Redo the last undone action */
|
|
105
|
-
redo: () => {
|
|
106
|
-
window.TopolPlugin.redo();
|
|
107
|
-
},
|
|
108
|
-
/** Destroy the editor instance and clean up resources */
|
|
109
|
-
destroy: () => {
|
|
110
|
-
window.TopolPlugin.destroy();
|
|
111
|
-
},
|
|
112
|
-
/** Update the list of saved/reusable blocks */
|
|
113
|
-
setSavedBlocks: (e) => {
|
|
114
|
-
window.TopolPlugin.setSavedBlocks(e);
|
|
115
|
-
},
|
|
116
|
-
/** Set custom HTML for the preview */
|
|
117
|
-
setPreviewHTML: (e) => {
|
|
118
|
-
window.TopolPlugin.setPreviewHTML(e);
|
|
119
|
-
},
|
|
120
|
-
/** Display a notification in the editor */
|
|
121
|
-
createNotification: (e) => {
|
|
122
|
-
window.TopolPlugin.createNotification(e);
|
|
123
|
-
},
|
|
124
|
-
/** Set the list of active collaboration members */
|
|
125
|
-
setActiveMembers: (e) => {
|
|
126
|
-
window.TopolPlugin.setActiveMembers(e);
|
|
127
|
-
},
|
|
128
|
-
/** Switch to mobile view */
|
|
129
|
-
changeEmailToMobile: () => {
|
|
130
|
-
window.TopolPlugin.changeEmailToMobile();
|
|
131
|
-
},
|
|
132
|
-
/** Switch to desktop view */
|
|
133
|
-
changeEmailToDesktop: () => {
|
|
134
|
-
window.TopolPlugin.changeEmailToDesktop();
|
|
135
|
-
},
|
|
136
|
-
/** Toggle visibility of hidden blocks and structures */
|
|
137
|
-
toggleBlocksAndStructuresVisibility: () => {
|
|
138
|
-
window.TopolPlugin.toggleBlocksAndStructuresVisibility();
|
|
139
|
-
},
|
|
140
|
-
/** Update the content of a custom block */
|
|
141
|
-
updateCustomBlockContent: (e) => {
|
|
142
|
-
window.TopolPlugin.updateCustomBlockContent(e);
|
|
143
|
-
},
|
|
144
|
-
/** Refresh comments/conversations */
|
|
145
|
-
refreshComments: (e) => {
|
|
146
|
-
window.TopolPlugin.refreshComments(e);
|
|
147
|
-
},
|
|
148
|
-
/** Refresh synced rows */
|
|
149
|
-
refreshSyncedRows: () => {
|
|
150
|
-
window.TopolPlugin.refreshSyncedRows();
|
|
151
|
-
},
|
|
152
|
-
/** Open the premade templates selection modal */
|
|
153
|
-
openPremadeTemplatesSelection: () => {
|
|
154
|
-
window.TopolPlugin.openPremadeTemplatesSelection();
|
|
155
|
-
},
|
|
156
|
-
/** Update the API authorization header */
|
|
157
|
-
updateApiAuthorizationHeader: (e) => {
|
|
158
|
-
window.TopolPlugin.updateApiAuthorizationHeader(e);
|
|
159
|
-
},
|
|
160
|
-
/** Set the template name/title */
|
|
161
|
-
setTemplateName: (e) => {
|
|
162
|
-
window.TopolPlugin.setTemplateName(e);
|
|
163
|
-
},
|
|
164
|
-
/** Toggle the AI chat feature */
|
|
165
|
-
toggleChatAI: () => {
|
|
166
|
-
window.TopolPlugin.toggleChatAI();
|
|
167
|
-
},
|
|
168
|
-
/** Toggle the autosaves feature */
|
|
169
|
-
toggleAutosaves: () => {
|
|
170
|
-
window.TopolPlugin.toggleAutosaves();
|
|
171
|
-
},
|
|
172
|
-
/** Toggle the comments panel */
|
|
173
|
-
toggleComments: () => {
|
|
174
|
-
window.TopolPlugin.toggleComments();
|
|
175
|
-
},
|
|
176
|
-
/** Create a new language variant */
|
|
177
|
-
createLanguage: (e) => {
|
|
178
|
-
window.TopolPlugin.createLanguage(e);
|
|
179
|
-
},
|
|
180
|
-
/** Set the primary language */
|
|
181
|
-
setPrimaryLanguage: (e) => {
|
|
182
|
-
window.TopolPlugin.setPrimaryLanguage(e);
|
|
183
|
-
},
|
|
184
|
-
/** Delete a language variant */
|
|
185
|
-
deleteLanguage: (e) => {
|
|
186
|
-
window.TopolPlugin.deleteLanguage(e);
|
|
187
|
-
},
|
|
188
|
-
/** Select/switch to a language */
|
|
189
|
-
selectLanguage: (e) => {
|
|
190
|
-
window.TopolPlugin.selectLanguage(e);
|
|
191
131
|
}
|
|
192
|
-
},
|
|
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 j(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 = {
|
|
193
151
|
/**
|
|
194
152
|
* Inits Landing Page Editor.
|
|
195
153
|
*
|
|
196
154
|
* @param options - Configuration options for the editor
|
|
197
|
-
* @param pluginOptions - Plugin options
|
|
155
|
+
* @param pluginOptions - Plugin options: an explicit `loaderUrl`
|
|
198
156
|
* @returns Promise that resolves with the editor instance
|
|
199
157
|
*/
|
|
200
|
-
init: (e,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}, v = m;
|
|
158
|
+
init: async (e, t) => {
|
|
159
|
+
var a;
|
|
160
|
+
const o = j(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
|
+
};
|
|
211
168
|
export {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
v as TopolPlugin,
|
|
215
|
-
v as default
|
|
169
|
+
O as EmailEditor,
|
|
170
|
+
x as LandingPageEditor
|
|
216
171
|
};
|