@topol.io/editor-svelte 1.0.0-alpha.1 → 1.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -103
- package/dist/EmailEditor.svelte +221 -0
- package/dist/EmailEditor.svelte.d.ts +124 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/svelte-internal.d.ts +7 -0
- package/package.json +14 -5
- package/dist/TopolEditor.svelte +0 -87
- package/dist/TopolEditor.svelte.d.ts +0 -49
package/README.md
CHANGED
|
@@ -1,109 +1,55 @@
|
|
|
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-svelte — 1.x alpha
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
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-svelte
|
|
17
|
-
|
|
18
|
-
//or
|
|
19
|
-
|
|
20
|
-
yarn add @topol.io/editor-svelte
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Use in Component
|
|
24
|
-
|
|
25
|
-
In your Svelte component import and add the simplest options.
|
|
26
|
-
|
|
27
|
-
For more options see the docs for [TopolOptions configuration](https://docs.topol.io/reference/topol-options.html)
|
|
28
|
-
|
|
29
|
-
```js
|
|
30
|
-
import { TopolEditor } from '@topol.io/editor-svelte';
|
|
31
|
-
|
|
32
|
-
const customOptions = {
|
|
33
|
-
authorize: {
|
|
34
|
-
apiKey: 'YOUR_API_TOKEN',
|
|
35
|
-
userId: 'some-user-id',
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
```html
|
|
41
|
-
<TopolEditor options="{customOptions}"></TopolEditor>
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Call Topol Plugin actions
|
|
45
|
-
|
|
46
|
-
To call actions to the editor import:
|
|
47
|
-
|
|
48
|
-
```js
|
|
49
|
-
import { TopolPlugin } from '@topol.io/editor-svelte';
|
|
50
|
-
|
|
51
|
-
const save = () => {
|
|
52
|
-
TopolPlugin.save();
|
|
53
|
-
};
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
For more TopolPlugion functions refer to the [TopolPlugin actions](https://www.npmjs.com/package/@topol.io/editor#call-topol-plugin-actions)
|
|
57
|
-
|
|
58
|
-
<br>
|
|
59
|
-
|
|
60
|
-
## Editor Events
|
|
61
|
-
|
|
62
|
-
The callbacks from editor are received as component events.
|
|
63
|
-
|
|
64
|
-
```html
|
|
65
|
-
<TopolEditor
|
|
66
|
-
options="{customOptions}"
|
|
67
|
-
on:onSave="{onSave}"
|
|
68
|
-
></TopolEditor>
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### List of all editor events
|
|
72
|
-
|
|
73
|
-
| Event | Description |
|
|
74
|
-
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
75
|
-
| `@onSave` | Returns object which contains html and json of the template [more info](https://docs.topol.io/guide/callbacks.html#on-save) |
|
|
76
|
-
| `@onSaveAndClose` | Returns object which contains html and json of the template [more info](https://docs.topol.io/guide/callbacks.html#on-save-and-close) |
|
|
77
|
-
| `@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) |
|
|
78
|
-
| `@onOpenFileManager` | When user clicks file manager open [more info](https://docs.topol.io/guide/custom-filemanager.html#onopenfilemanager) |
|
|
79
|
-
| `@onLoaded` | After editor template is loaded using `TopolPlugin.load()` [more info](https://docs.topol.io/guide/callbacks.html#on-loaded) |
|
|
80
|
-
| `@onInit` | When editor inits [more info](https://docs.topol.io/guide/callbacks.html#on-init) |
|
|
81
|
-
| `@onBlockSave` | When user saves block in editor, returns object of type ISavedBlock [more info](https://docs.topol.io/guide/callbacks.html#on-block-save) |
|
|
82
|
-
| `@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) |
|
|
83
|
-
| `@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) |
|
|
84
|
-
| `@onUndoChange` | When user clicks undo button, retunrs number of steps user undone [more info](https://docs.topol.io/guide/callbacks.html#on-undo-change) |
|
|
85
|
-
| `@onRedoChange` | When user clicks redo button, retunrs number of steps user redone [more info](https://docs.topol.io/guide/callbacks.html#on-redo-change) |
|
|
86
|
-
| `@onPreview` | When user switches to preview [more info](https://docs.topol.io/guide/callbacks.html#on-preview) |
|
|
87
|
-
| `@onAlert` | When alert appears in editor [more info](https://docs.topol.io/guide/callbacks.html#on-alert) |
|
|
88
|
-
| `@onClose` | When close is click inside WindowBar [more info](https://docs.topol.io/guide/top-bar.html#window-bar) |
|
|
89
|
-
| `@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) |
|
|
90
|
-
| `@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) |
|
|
91
|
-
| `@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) |
|
|
92
|
-
| `@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) |
|
|
93
|
-
| `@onError` | When an error that cannot be handled happened in the editor [more info](https://docs.topol.io/guide/callbacks.html#onerror) |
|
|
94
|
-
|
|
95
|
-
<br>
|
|
96
|
-
|
|
97
|
-
## TypeScript
|
|
98
|
-
|
|
99
|
-
Topol Editor provides full TypeScript integration and exports all necessary types.
|
|
3
|
+
Svelte 4 wrapper for Email Editor v4, from the 1.x alpha line onward.
|
|
100
4
|
|
|
101
5
|
```svelte
|
|
102
6
|
<script lang="ts">
|
|
103
|
-
import {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
7
|
+
import { EmailEditor, type ISvelteOptions, type IEmailCallbacks } from "@topol.io/editor-svelte";
|
|
8
|
+
const options: ISvelteOptions = {
|
|
9
|
+
authorize: { apiKey: "pk_your-key", userId: "user-123" },
|
|
10
|
+
cloud: { enabled: true },
|
|
11
|
+
};
|
|
12
|
+
const callbacks: IEmailCallbacks = {
|
|
13
|
+
async getNonce() {
|
|
14
|
+
const response = await fetch("/api/topol/nonce", { method: "POST" });
|
|
15
|
+
if (!response.ok) throw new Error("Cloud authorization failed");
|
|
16
|
+
return (await response.json()).nonce;
|
|
17
|
+
},
|
|
18
|
+
};
|
|
108
19
|
</script>
|
|
20
|
+
|
|
21
|
+
<EmailEditor
|
|
22
|
+
{options}
|
|
23
|
+
{callbacks}
|
|
24
|
+
on:onCloudSave={(event) => console.log(event.detail.templateId)}
|
|
25
|
+
on:onEditorError={(event) => console.error(event.detail.message)}
|
|
26
|
+
/>
|
|
109
27
|
```
|
|
28
|
+
|
|
29
|
+
Use the **`callbacks` prop for `getNonce` and async persistence**. Svelte event
|
|
30
|
+
handlers cannot return promises to the editor. Notification events carry the exact
|
|
31
|
+
v4 payload in `event.detail`; for example, `event.detail.code` for language events.
|
|
32
|
+
If both a callback and a listener are present, the callback runs first and its
|
|
33
|
+
result returns to the editor.
|
|
34
|
+
|
|
35
|
+
Use `bind:this={component}` and `component.getEditor()` for async instance methods,
|
|
36
|
+
or listen to `on:ready` for the instance in `event.detail`. `CoreEmailEditor` exposes
|
|
37
|
+
the core v4 factory. The old `ITopolOptions` wrapper-config alias is now
|
|
38
|
+
`ISvelteOptions`; `ITopolOptions` refers to the core `{ config, ...callbacks }` type.
|
|
39
|
+
|
|
40
|
+
`options` contains the v4 configuration (`IEmailConfig`). A `getNonce` callback that
|
|
41
|
+
fetches a fresh `nc_` token from your application's authenticated backend enables
|
|
42
|
+
nonce authentication on its own; Cloud additionally requires it. Never put an `sk_`
|
|
43
|
+
secret in browser code. See the core package README for nonce authentication, Cloud
|
|
44
|
+
feature options, the Countdown block (`enableCountdown`, `countdown`; see the
|
|
45
|
+
[option reference](https://docs.topol.io/email-editor/reference/topol-options#countdown))
|
|
46
|
+
and all v4 renames.
|
|
47
|
+
|
|
48
|
+
Configuration and the presence of callback handlers are captured on mount. Remount
|
|
49
|
+
with a new key to change them; existing callback functions read their latest values.
|
|
50
|
+
`ready` means the iframe has rendered; `onInit` reports editor authentication.
|
|
51
|
+
Set the container's height. Each component owns its own instance and destroys it
|
|
52
|
+
on unmount, including when initialization is still pending.
|
|
53
|
+
|
|
54
|
+
Use `loaderUrl` for an explicit v4 local/preview loader. A numeric `stage` selects
|
|
55
|
+
a PR preview. `TopolEditor` is a deprecated naming alias using the new v4 contract.
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
<script
|
|
2
|
+
context="module"
|
|
3
|
+
|
|
4
|
+
></script>
|
|
5
|
+
|
|
6
|
+
<script>import { createEventDispatcher, onMount, onDestroy, tick } from "svelte";
|
|
7
|
+
import { get_current_component } from "svelte/internal";
|
|
8
|
+
import { EmailEditor as CoreEmailEditor } from "@topol.io/editor";
|
|
9
|
+
export let options;
|
|
10
|
+
export let callbacks = {};
|
|
11
|
+
export let stage = "production";
|
|
12
|
+
export let loaderUrl = void 0;
|
|
13
|
+
let container;
|
|
14
|
+
let editor;
|
|
15
|
+
let disposed = false;
|
|
16
|
+
const component = get_current_component();
|
|
17
|
+
const dispatch = createEventDispatcher();
|
|
18
|
+
export const getEditor = () => editor ?? null;
|
|
19
|
+
const hasHandler = (name) => !!callbacks[name] || !!component.$$.callbacks[name]?.length;
|
|
20
|
+
const reportError = (error) => {
|
|
21
|
+
if (disposed)
|
|
22
|
+
return;
|
|
23
|
+
const payload = { source: "integration", message: error instanceof Error ? error.message : String(error), detail: error };
|
|
24
|
+
if (!hasHandler("onEditorError"))
|
|
25
|
+
console.error("[@topol.io/editor-svelte] EmailEditor failed:", error);
|
|
26
|
+
callbacks.onEditorError?.(payload);
|
|
27
|
+
dispatch("onEditorError", payload);
|
|
28
|
+
};
|
|
29
|
+
onMount(() => {
|
|
30
|
+
const initialize = async () => {
|
|
31
|
+
await tick();
|
|
32
|
+
if (disposed)
|
|
33
|
+
return;
|
|
34
|
+
const hostCallbacks = {
|
|
35
|
+
onSave: hasHandler("onSave") ? (payload) => {
|
|
36
|
+
const result = callbacks.onSave?.(payload);
|
|
37
|
+
dispatch("onSave", payload);
|
|
38
|
+
return result;
|
|
39
|
+
} : void 0,
|
|
40
|
+
onSaveAndClose: hasHandler("onSaveAndClose") ? (payload) => {
|
|
41
|
+
const result = callbacks.onSaveAndClose?.(payload);
|
|
42
|
+
dispatch("onSaveAndClose", payload);
|
|
43
|
+
return result;
|
|
44
|
+
} : void 0,
|
|
45
|
+
onTestSend: hasHandler("onTestSend") ? (payload) => {
|
|
46
|
+
const result = callbacks.onTestSend?.(payload);
|
|
47
|
+
dispatch("onTestSend", payload);
|
|
48
|
+
return result;
|
|
49
|
+
} : void 0,
|
|
50
|
+
onBannerClick: hasHandler("onBannerClick") ? (payload) => {
|
|
51
|
+
const result = callbacks.onBannerClick?.(payload);
|
|
52
|
+
dispatch("onBannerClick", payload);
|
|
53
|
+
return result;
|
|
54
|
+
} : void 0,
|
|
55
|
+
onOpenFileManager: hasHandler("onOpenFileManager") ? () => {
|
|
56
|
+
const result = callbacks.onOpenFileManager?.();
|
|
57
|
+
dispatch("onOpenFileManager");
|
|
58
|
+
return result;
|
|
59
|
+
} : void 0,
|
|
60
|
+
onLoaded: hasHandler("onLoaded") ? () => {
|
|
61
|
+
const result = callbacks.onLoaded?.();
|
|
62
|
+
dispatch("onLoaded");
|
|
63
|
+
return result;
|
|
64
|
+
} : void 0,
|
|
65
|
+
onSavedSectionSave: hasHandler("onSavedSectionSave") ? (payload) => {
|
|
66
|
+
const result = callbacks.onSavedSectionSave?.(payload);
|
|
67
|
+
dispatch("onSavedSectionSave", payload);
|
|
68
|
+
return result;
|
|
69
|
+
} : void 0,
|
|
70
|
+
onSavedSectionRemove: hasHandler("onSavedSectionRemove") ? (payload) => {
|
|
71
|
+
const result = callbacks.onSavedSectionRemove?.(payload);
|
|
72
|
+
dispatch("onSavedSectionRemove", payload);
|
|
73
|
+
return result;
|
|
74
|
+
} : void 0,
|
|
75
|
+
onSavedSectionEdit: hasHandler("onSavedSectionEdit") ? (payload) => {
|
|
76
|
+
const result = callbacks.onSavedSectionEdit?.(payload);
|
|
77
|
+
dispatch("onSavedSectionEdit", payload);
|
|
78
|
+
return result;
|
|
79
|
+
} : void 0,
|
|
80
|
+
onImageDelete: hasHandler("onImageDelete") ? (payload) => {
|
|
81
|
+
const result = callbacks.onImageDelete?.(payload);
|
|
82
|
+
dispatch("onImageDelete", payload);
|
|
83
|
+
return result;
|
|
84
|
+
} : void 0,
|
|
85
|
+
onInit: hasHandler("onInit") ? () => {
|
|
86
|
+
const result = callbacks.onInit?.();
|
|
87
|
+
dispatch("onInit");
|
|
88
|
+
return result;
|
|
89
|
+
} : void 0,
|
|
90
|
+
onUndoChange: hasHandler("onUndoChange") ? (payload) => {
|
|
91
|
+
const result = callbacks.onUndoChange?.(payload);
|
|
92
|
+
dispatch("onUndoChange", payload);
|
|
93
|
+
return result;
|
|
94
|
+
} : void 0,
|
|
95
|
+
onRedoChange: hasHandler("onRedoChange") ? (payload) => {
|
|
96
|
+
const result = callbacks.onRedoChange?.(payload);
|
|
97
|
+
dispatch("onRedoChange", payload);
|
|
98
|
+
return result;
|
|
99
|
+
} : void 0,
|
|
100
|
+
onPreview: hasHandler("onPreview") ? (payload) => {
|
|
101
|
+
const result = callbacks.onPreview?.(payload);
|
|
102
|
+
dispatch("onPreview", payload);
|
|
103
|
+
return result;
|
|
104
|
+
} : void 0,
|
|
105
|
+
onPreviewClose: hasHandler("onPreviewClose") ? () => {
|
|
106
|
+
const result = callbacks.onPreviewClose?.();
|
|
107
|
+
dispatch("onPreviewClose");
|
|
108
|
+
return result;
|
|
109
|
+
} : void 0,
|
|
110
|
+
onAlert: hasHandler("onAlert") ? (payload) => {
|
|
111
|
+
const result = callbacks.onAlert?.(payload);
|
|
112
|
+
dispatch("onAlert", payload);
|
|
113
|
+
return result;
|
|
114
|
+
} : void 0,
|
|
115
|
+
onEditorClose: hasHandler("onEditorClose") ? () => {
|
|
116
|
+
const result = callbacks.onEditorClose?.();
|
|
117
|
+
dispatch("onEditorClose");
|
|
118
|
+
return result;
|
|
119
|
+
} : void 0,
|
|
120
|
+
onEdittedWithoutSaveChanged: hasHandler("onEdittedWithoutSaveChanged") ? (payload) => {
|
|
121
|
+
const result = callbacks.onEdittedWithoutSaveChanged?.(payload);
|
|
122
|
+
dispatch("onEdittedWithoutSaveChanged", payload);
|
|
123
|
+
return result;
|
|
124
|
+
} : void 0,
|
|
125
|
+
onBlocksAndStructuresVisibilityChange: hasHandler("onBlocksAndStructuresVisibilityChange") ? (payload) => {
|
|
126
|
+
const result = callbacks.onBlocksAndStructuresVisibilityChange?.(payload);
|
|
127
|
+
dispatch("onBlocksAndStructuresVisibilityChange", payload);
|
|
128
|
+
return result;
|
|
129
|
+
} : void 0,
|
|
130
|
+
onOpenCustomBlockDialog: hasHandler("onOpenCustomBlockDialog") ? (payload) => {
|
|
131
|
+
const result = callbacks.onOpenCustomBlockDialog?.(payload);
|
|
132
|
+
dispatch("onOpenCustomBlockDialog", payload);
|
|
133
|
+
return result;
|
|
134
|
+
} : void 0,
|
|
135
|
+
onTemplateRename: hasHandler("onTemplateRename") ? (payload) => {
|
|
136
|
+
const result = callbacks.onTemplateRename?.(payload);
|
|
137
|
+
dispatch("onTemplateRename", payload);
|
|
138
|
+
return result;
|
|
139
|
+
} : void 0,
|
|
140
|
+
onTemplateUpdated: hasHandler("onTemplateUpdated") ? () => {
|
|
141
|
+
const result = callbacks.onTemplateUpdated?.();
|
|
142
|
+
dispatch("onTemplateUpdated");
|
|
143
|
+
return result;
|
|
144
|
+
} : void 0,
|
|
145
|
+
updateTestingEmailAddresses: hasHandler("updateTestingEmailAddresses") ? (payload) => {
|
|
146
|
+
const result = callbacks.updateTestingEmailAddresses?.(payload);
|
|
147
|
+
dispatch("updateTestingEmailAddresses", payload);
|
|
148
|
+
return result;
|
|
149
|
+
} : void 0,
|
|
150
|
+
onEditorError: hasHandler("onEditorError") ? (payload) => {
|
|
151
|
+
const result = callbacks.onEditorError?.(payload);
|
|
152
|
+
dispatch("onEditorError", payload);
|
|
153
|
+
return result;
|
|
154
|
+
} : void 0,
|
|
155
|
+
onLanguageCreated: hasHandler("onLanguageCreated") ? (payload) => {
|
|
156
|
+
const result = callbacks.onLanguageCreated?.(payload);
|
|
157
|
+
dispatch("onLanguageCreated", payload);
|
|
158
|
+
return result;
|
|
159
|
+
} : void 0,
|
|
160
|
+
onLanguageDeleted: hasHandler("onLanguageDeleted") ? (payload) => {
|
|
161
|
+
const result = callbacks.onLanguageDeleted?.(payload);
|
|
162
|
+
dispatch("onLanguageDeleted", payload);
|
|
163
|
+
return result;
|
|
164
|
+
} : void 0,
|
|
165
|
+
onLanguageSelected: hasHandler("onLanguageSelected") ? (payload) => {
|
|
166
|
+
const result = callbacks.onLanguageSelected?.(payload);
|
|
167
|
+
dispatch("onLanguageSelected", payload);
|
|
168
|
+
return result;
|
|
169
|
+
} : void 0,
|
|
170
|
+
onPrimaryLanguageChanged: hasHandler("onPrimaryLanguageChanged") ? (payload) => {
|
|
171
|
+
const result = callbacks.onPrimaryLanguageChanged?.(payload);
|
|
172
|
+
dispatch("onPrimaryLanguageChanged", payload);
|
|
173
|
+
return result;
|
|
174
|
+
} : void 0,
|
|
175
|
+
onGetMutations: hasHandler("onGetMutations") ? (payload) => {
|
|
176
|
+
const result = callbacks.onGetMutations?.(payload);
|
|
177
|
+
dispatch("onGetMutations", payload);
|
|
178
|
+
return result;
|
|
179
|
+
} : void 0,
|
|
180
|
+
getNonce: callbacks.getNonce ? () => callbacks.getNonce() : void 0,
|
|
181
|
+
onCloudSave: hasHandler("onCloudSave") ? (payload) => {
|
|
182
|
+
const result = callbacks.onCloudSave?.(payload);
|
|
183
|
+
dispatch("onCloudSave", payload);
|
|
184
|
+
return result;
|
|
185
|
+
} : void 0,
|
|
186
|
+
onCloudTemplateChange: hasHandler("onCloudTemplateChange") ? (payload) => {
|
|
187
|
+
const result = callbacks.onCloudTemplateChange?.(payload);
|
|
188
|
+
dispatch("onCloudTemplateChange", payload);
|
|
189
|
+
return result;
|
|
190
|
+
} : void 0
|
|
191
|
+
};
|
|
192
|
+
const created = await CoreEmailEditor.init({ config: options, ...hostCallbacks }, { stage, loaderUrl });
|
|
193
|
+
if (disposed) {
|
|
194
|
+
await created.destroy();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
editor = created;
|
|
198
|
+
try {
|
|
199
|
+
await created.render(container);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
await created.destroy();
|
|
202
|
+
editor = void 0;
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
if (!disposed)
|
|
206
|
+
dispatch("ready", created);
|
|
207
|
+
};
|
|
208
|
+
void initialize().catch(reportError);
|
|
209
|
+
});
|
|
210
|
+
onDestroy(() => {
|
|
211
|
+
disposed = true;
|
|
212
|
+
const owned = editor;
|
|
213
|
+
editor = void 0;
|
|
214
|
+
void owned?.destroy().catch((error) => console.warn("[@topol.io/editor-svelte] EmailEditor cleanup failed:", error));
|
|
215
|
+
});
|
|
216
|
+
</script>
|
|
217
|
+
|
|
218
|
+
<div
|
|
219
|
+
bind:this={container}
|
|
220
|
+
style="width: 100%; height: 100vh"
|
|
221
|
+
></div>
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { IEmailConfig, IEmailCallbacks } from "@topol.io/editor";
|
|
3
|
+
export type ISvelteOptions = IEmailConfig;
|
|
4
|
+
export type ISvelteEmailEvents = {
|
|
5
|
+
onSave: Parameters<NonNullable<IEmailCallbacks["onSave"]>>[0];
|
|
6
|
+
onSaveAndClose: Parameters<NonNullable<IEmailCallbacks["onSaveAndClose"]>>[0];
|
|
7
|
+
onTestSend: Parameters<NonNullable<IEmailCallbacks["onTestSend"]>>[0];
|
|
8
|
+
onBannerClick: Parameters<NonNullable<IEmailCallbacks["onBannerClick"]>>[0];
|
|
9
|
+
onOpenFileManager: void;
|
|
10
|
+
onLoaded: void;
|
|
11
|
+
onSavedSectionSave: Parameters<NonNullable<IEmailCallbacks["onSavedSectionSave"]>>[0];
|
|
12
|
+
onSavedSectionRemove: Parameters<NonNullable<IEmailCallbacks["onSavedSectionRemove"]>>[0];
|
|
13
|
+
onSavedSectionEdit: Parameters<NonNullable<IEmailCallbacks["onSavedSectionEdit"]>>[0];
|
|
14
|
+
onImageDelete: Parameters<NonNullable<IEmailCallbacks["onImageDelete"]>>[0];
|
|
15
|
+
onInit: void;
|
|
16
|
+
onUndoChange: Parameters<NonNullable<IEmailCallbacks["onUndoChange"]>>[0];
|
|
17
|
+
onRedoChange: Parameters<NonNullable<IEmailCallbacks["onRedoChange"]>>[0];
|
|
18
|
+
onPreview: Parameters<NonNullable<IEmailCallbacks["onPreview"]>>[0];
|
|
19
|
+
onPreviewClose: void;
|
|
20
|
+
onAlert: Parameters<NonNullable<IEmailCallbacks["onAlert"]>>[0];
|
|
21
|
+
onEditorClose: void;
|
|
22
|
+
onEdittedWithoutSaveChanged: Parameters<NonNullable<IEmailCallbacks["onEdittedWithoutSaveChanged"]>>[0];
|
|
23
|
+
onBlocksAndStructuresVisibilityChange: Parameters<NonNullable<IEmailCallbacks["onBlocksAndStructuresVisibilityChange"]>>[0];
|
|
24
|
+
onOpenCustomBlockDialog: Parameters<NonNullable<IEmailCallbacks["onOpenCustomBlockDialog"]>>[0];
|
|
25
|
+
onTemplateRename: Parameters<NonNullable<IEmailCallbacks["onTemplateRename"]>>[0];
|
|
26
|
+
onTemplateUpdated: void;
|
|
27
|
+
updateTestingEmailAddresses: Parameters<NonNullable<IEmailCallbacks["updateTestingEmailAddresses"]>>[0];
|
|
28
|
+
onEditorError: Parameters<NonNullable<IEmailCallbacks["onEditorError"]>>[0];
|
|
29
|
+
onLanguageCreated: Parameters<NonNullable<IEmailCallbacks["onLanguageCreated"]>>[0];
|
|
30
|
+
onLanguageDeleted: Parameters<NonNullable<IEmailCallbacks["onLanguageDeleted"]>>[0];
|
|
31
|
+
onLanguageSelected: Parameters<NonNullable<IEmailCallbacks["onLanguageSelected"]>>[0];
|
|
32
|
+
onPrimaryLanguageChanged: Parameters<NonNullable<IEmailCallbacks["onPrimaryLanguageChanged"]>>[0];
|
|
33
|
+
onGetMutations: Parameters<NonNullable<IEmailCallbacks["onGetMutations"]>>[0];
|
|
34
|
+
onCloudSave: Parameters<NonNullable<IEmailCallbacks["onCloudSave"]>>[0];
|
|
35
|
+
onCloudTemplateChange: Parameters<NonNullable<IEmailCallbacks["onCloudTemplateChange"]>>[0];
|
|
36
|
+
ready: IEmailEditorInstance;
|
|
37
|
+
};
|
|
38
|
+
import type { IEmailEditorInstance, IStage, IErrorData } from "@topol.io/editor";
|
|
39
|
+
declare const __propDef: {
|
|
40
|
+
props: {
|
|
41
|
+
options: ISvelteOptions;
|
|
42
|
+
callbacks?: IEmailCallbacks | undefined;
|
|
43
|
+
stage?: IStage | undefined;
|
|
44
|
+
loaderUrl?: string | undefined;
|
|
45
|
+
getEditor?: (() => IEmailEditorInstance | null) | undefined;
|
|
46
|
+
};
|
|
47
|
+
events: {
|
|
48
|
+
onSave: CustomEvent<import("@topol.io/editor").ISaveData>;
|
|
49
|
+
onSaveAndClose: CustomEvent<import("@topol.io/editor").ISaveData>;
|
|
50
|
+
onTestSend: CustomEvent<import("@topol.io/editor").ISendTestData>;
|
|
51
|
+
onBannerClick: CustomEvent<{
|
|
52
|
+
json: unknown;
|
|
53
|
+
html: unknown;
|
|
54
|
+
}>;
|
|
55
|
+
onOpenFileManager: CustomEvent<void>;
|
|
56
|
+
onLoaded: CustomEvent<void>;
|
|
57
|
+
onSavedSectionSave: CustomEvent<{
|
|
58
|
+
section: import("@topol.io/editor").ISavedBlock;
|
|
59
|
+
}>;
|
|
60
|
+
onSavedSectionRemove: CustomEvent<{
|
|
61
|
+
id: string | number;
|
|
62
|
+
}>;
|
|
63
|
+
onSavedSectionEdit: CustomEvent<{
|
|
64
|
+
id: string | number;
|
|
65
|
+
}>;
|
|
66
|
+
onImageDelete: CustomEvent<{
|
|
67
|
+
items: import("@topol.io/editor").IEmailDeletedItem[];
|
|
68
|
+
}>;
|
|
69
|
+
onInit: CustomEvent<void>;
|
|
70
|
+
onUndoChange: CustomEvent<{
|
|
71
|
+
count: number;
|
|
72
|
+
}>;
|
|
73
|
+
onRedoChange: CustomEvent<{
|
|
74
|
+
count: number;
|
|
75
|
+
}>;
|
|
76
|
+
onPreview: CustomEvent<{
|
|
77
|
+
html: unknown;
|
|
78
|
+
}>;
|
|
79
|
+
onPreviewClose: CustomEvent<void>;
|
|
80
|
+
onAlert: CustomEvent<{
|
|
81
|
+
notification: import("@topol.io/editor").INotification;
|
|
82
|
+
}>;
|
|
83
|
+
onEditorClose: CustomEvent<void>;
|
|
84
|
+
onEdittedWithoutSaveChanged: CustomEvent<{
|
|
85
|
+
value: boolean;
|
|
86
|
+
}>;
|
|
87
|
+
onBlocksAndStructuresVisibilityChange: CustomEvent<{
|
|
88
|
+
value: boolean;
|
|
89
|
+
}>;
|
|
90
|
+
onOpenCustomBlockDialog: CustomEvent<{
|
|
91
|
+
block: unknown;
|
|
92
|
+
}>;
|
|
93
|
+
onTemplateRename: CustomEvent<{
|
|
94
|
+
name: string;
|
|
95
|
+
}>;
|
|
96
|
+
onTemplateUpdated: CustomEvent<void>;
|
|
97
|
+
updateTestingEmailAddresses: CustomEvent<{
|
|
98
|
+
emails: string[];
|
|
99
|
+
}>;
|
|
100
|
+
onEditorError: CustomEvent<IErrorData>;
|
|
101
|
+
onLanguageCreated: CustomEvent<import("@topol.io/editor").ILanguageChangePayload>;
|
|
102
|
+
onLanguageDeleted: CustomEvent<import("@topol.io/editor").ILanguageChangePayload>;
|
|
103
|
+
onLanguageSelected: CustomEvent<{
|
|
104
|
+
code: string;
|
|
105
|
+
}>;
|
|
106
|
+
onPrimaryLanguageChanged: CustomEvent<import("@topol.io/editor").ILanguageChangePayload>;
|
|
107
|
+
onGetMutations: CustomEvent<{
|
|
108
|
+
mutations: import("@topol.io/editor").ILanguageMutation[];
|
|
109
|
+
}>;
|
|
110
|
+
onCloudSave: CustomEvent<import("@topol.io/editor").ICloudSavePayload>;
|
|
111
|
+
onCloudTemplateChange: CustomEvent<import("@topol.io/editor").ICloudTemplateChangePayload>;
|
|
112
|
+
ready: CustomEvent<IEmailEditorInstance>;
|
|
113
|
+
} & {
|
|
114
|
+
[evt: string]: CustomEvent<any>;
|
|
115
|
+
};
|
|
116
|
+
slots: {};
|
|
117
|
+
};
|
|
118
|
+
export type EmailEditorProps = typeof __propDef.props;
|
|
119
|
+
export type EmailEditorEvents = typeof __propDef.events;
|
|
120
|
+
export type EmailEditorSlots = typeof __propDef.slots;
|
|
121
|
+
export default class EmailEditor extends SvelteComponent<EmailEditorProps, EmailEditorEvents, EmailEditorSlots> {
|
|
122
|
+
get getEditor(): () => IEmailEditorInstance | null;
|
|
123
|
+
}
|
|
124
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { default as TopolPlugin } from
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
4
|
-
export type
|
|
1
|
+
export { default as TopolPlugin, EmailEditor as CoreEmailEditor } from "@topol.io/editor";
|
|
2
|
+
export { default as EmailEditor, default as TopolEditor } from "./EmailEditor.svelte";
|
|
3
|
+
export type { ISvelteOptions, ISvelteEmailEvents } from "./EmailEditor.svelte";
|
|
4
|
+
export type * from "@topol.io/editor";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as TopolPlugin } from
|
|
2
|
-
export { default as TopolEditor } from
|
|
1
|
+
export { default as TopolPlugin, EmailEditor as CoreEmailEditor } from "@topol.io/editor";
|
|
2
|
+
export { default as EmailEditor, default as TopolEditor } from "./EmailEditor.svelte";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Svelte 4 exposes no public listener-presence API. Only inspect callback presence;
|
|
2
|
+
// installing an absent onSaveAndClose handler changes the editor's close behavior.
|
|
3
|
+
declare module "svelte/internal" {
|
|
4
|
+
export function get_current_component(): {
|
|
5
|
+
$$: { callbacks: Record<string, unknown[] | undefined> };
|
|
6
|
+
};
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
|
-
"version": "1.0.0-alpha.
|
|
20
|
+
"version": "1.0.0-alpha.10",
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
|
-
"svelte": "./dist/index.js"
|
|
25
|
+
"svelte": "./dist/index.js",
|
|
26
|
+
"default": "./dist/index.js"
|
|
26
27
|
}
|
|
27
28
|
},
|
|
28
29
|
"types": "./dist/index.d.ts",
|
|
@@ -38,16 +39,24 @@
|
|
|
38
39
|
"svelte-check": "^3.6.2",
|
|
39
40
|
"tslib": "^2.6.2",
|
|
40
41
|
"typescript": "^5.2.2",
|
|
41
|
-
"vite": "^5.0.8"
|
|
42
|
+
"vite": "^5.0.8",
|
|
43
|
+
"vitest": "^4.0.16",
|
|
44
|
+
"happy-dom": "^20.0.11"
|
|
42
45
|
},
|
|
43
46
|
"dependencies": {
|
|
44
|
-
"@topol.io/editor": "1.0.0-alpha.
|
|
47
|
+
"@topol.io/editor": "1.0.0-alpha.10"
|
|
45
48
|
},
|
|
46
49
|
"publishConfig": {
|
|
47
50
|
"access": "public"
|
|
48
51
|
},
|
|
49
52
|
"scripts": {
|
|
50
53
|
"dev": "vite",
|
|
51
|
-
"build": "svelte-package"
|
|
54
|
+
"build": "svelte-package",
|
|
55
|
+
"test": "vitest run",
|
|
56
|
+
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
57
|
+
"lint": "oxlint --deny-warnings .",
|
|
58
|
+
"lint:fix": "oxlint --fix --deny-warnings .",
|
|
59
|
+
"format": "oxfmt --write .",
|
|
60
|
+
"format:check": "oxfmt --check ."
|
|
52
61
|
}
|
|
53
62
|
}
|
package/dist/TopolEditor.svelte
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
<script context="module"></script>
|
|
2
|
-
|
|
3
|
-
<script>import { createEventDispatcher, onMount, onDestroy } from "svelte";
|
|
4
|
-
import TopolPlugin from "@topol.io/editor";
|
|
5
|
-
const EDITOR_HTML_ID = "topol-editor-id";
|
|
6
|
-
export let options;
|
|
7
|
-
export let stage = "production";
|
|
8
|
-
const dispatch = createEventDispatcher();
|
|
9
|
-
const mergeOptions = () => {
|
|
10
|
-
const callbacks = {
|
|
11
|
-
onSave(json, html) {
|
|
12
|
-
dispatch("onSave", { json, html });
|
|
13
|
-
},
|
|
14
|
-
onSaveAndClose(json, html) {
|
|
15
|
-
dispatch("onSaveAndClose", { json, html });
|
|
16
|
-
},
|
|
17
|
-
onTestSend(email, json, html) {
|
|
18
|
-
dispatch("onTestSend", { email, json, html });
|
|
19
|
-
},
|
|
20
|
-
onOpenFileManager() {
|
|
21
|
-
dispatch("onOpenFileManager");
|
|
22
|
-
},
|
|
23
|
-
onLoaded() {
|
|
24
|
-
dispatch("onLoaded");
|
|
25
|
-
},
|
|
26
|
-
onBlockSave(block) {
|
|
27
|
-
dispatch("onBlockSave", block);
|
|
28
|
-
},
|
|
29
|
-
onBlockRemove(blockId) {
|
|
30
|
-
dispatch("onBlockRemove", blockId);
|
|
31
|
-
},
|
|
32
|
-
onBlockEdit(blockId) {
|
|
33
|
-
dispatch("onBlockEdit", blockId);
|
|
34
|
-
},
|
|
35
|
-
onInit() {
|
|
36
|
-
dispatch("onInit");
|
|
37
|
-
},
|
|
38
|
-
onUndoChange(count) {
|
|
39
|
-
dispatch("onUndoChange", count);
|
|
40
|
-
},
|
|
41
|
-
onRedoChange(count) {
|
|
42
|
-
dispatch("onRedoChange", count);
|
|
43
|
-
},
|
|
44
|
-
onPreview(html) {
|
|
45
|
-
dispatch("onPreview", html);
|
|
46
|
-
},
|
|
47
|
-
onAlert(notification) {
|
|
48
|
-
dispatch("onAlert", notification);
|
|
49
|
-
},
|
|
50
|
-
onClose() {
|
|
51
|
-
dispatch("onClose");
|
|
52
|
-
},
|
|
53
|
-
// only in free version
|
|
54
|
-
onBannerClick(json, html) {
|
|
55
|
-
dispatch("onBannerClick", { json, html });
|
|
56
|
-
},
|
|
57
|
-
onEdittedWithoutSaveChanged(hasUnsavedChanges) {
|
|
58
|
-
dispatch("onEdittedWithoutSaveChanged", hasUnsavedChanges);
|
|
59
|
-
},
|
|
60
|
-
onOpenCustomBlockDialog(blockContent) {
|
|
61
|
-
dispatch("onOpenCustomBlockDialog", blockContent);
|
|
62
|
-
},
|
|
63
|
-
onTemplateRename(title) {
|
|
64
|
-
dispatch("onTemplateRename", title);
|
|
65
|
-
},
|
|
66
|
-
updateTestingEmailAddresses(emails) {
|
|
67
|
-
dispatch("updateTestingEmailAddresses", emails);
|
|
68
|
-
},
|
|
69
|
-
onError(type, message) {
|
|
70
|
-
dispatch("onError", { type, message });
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
return { id: "#" + EDITOR_HTML_ID, ...options, callbacks: { ...callbacks } };
|
|
74
|
-
};
|
|
75
|
-
onMount(async () => {
|
|
76
|
-
const mergedTopolOptinos = mergeOptions();
|
|
77
|
-
await TopolPlugin.init(mergedTopolOptinos, { stage });
|
|
78
|
-
});
|
|
79
|
-
onDestroy(() => {
|
|
80
|
-
TopolPlugin.destroy();
|
|
81
|
-
});
|
|
82
|
-
</script>
|
|
83
|
-
|
|
84
|
-
<div
|
|
85
|
-
id="{EDITOR_HTML_ID}"
|
|
86
|
-
style="position: absolute; width: 100%; height: 100vh"
|
|
87
|
-
></div>
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
|
-
export type ISvelteOptions = Omit<ITopolOptions, 'id' | 'callbacks'>;
|
|
3
|
-
export type ISaveData = {
|
|
4
|
-
json: unknown;
|
|
5
|
-
html: unknown;
|
|
6
|
-
};
|
|
7
|
-
export type ISendTestData = {
|
|
8
|
-
email: string;
|
|
9
|
-
json: unknown;
|
|
10
|
-
html: unknown;
|
|
11
|
-
};
|
|
12
|
-
import type { ITopolOptions, IStage } from '@topol.io/editor';
|
|
13
|
-
declare const __propDef: {
|
|
14
|
-
props: {
|
|
15
|
-
options: ISvelteOptions;
|
|
16
|
-
stage?: IStage | undefined;
|
|
17
|
-
};
|
|
18
|
-
events: {
|
|
19
|
-
onSave: CustomEvent<any>;
|
|
20
|
-
onSaveAndClose: CustomEvent<any>;
|
|
21
|
-
onTestSend: CustomEvent<any>;
|
|
22
|
-
onOpenFileManager: CustomEvent<any>;
|
|
23
|
-
onLoaded: CustomEvent<any>;
|
|
24
|
-
onBlockSave: CustomEvent<any>;
|
|
25
|
-
onBlockRemove: CustomEvent<any>;
|
|
26
|
-
onBlockEdit: CustomEvent<any>;
|
|
27
|
-
onInit: CustomEvent<any>;
|
|
28
|
-
onUndoChange: CustomEvent<any>;
|
|
29
|
-
onRedoChange: CustomEvent<any>;
|
|
30
|
-
onPreview: CustomEvent<any>;
|
|
31
|
-
onAlert: CustomEvent<any>;
|
|
32
|
-
onClose: CustomEvent<any>;
|
|
33
|
-
onBannerClick: CustomEvent<any>;
|
|
34
|
-
onEdittedWithoutSaveChanged: CustomEvent<any>;
|
|
35
|
-
onOpenCustomBlockDialog: CustomEvent<any>;
|
|
36
|
-
onTemplateRename: CustomEvent<any>;
|
|
37
|
-
updateTestingEmailAddresses: CustomEvent<any>;
|
|
38
|
-
onError: CustomEvent<any>;
|
|
39
|
-
} & {
|
|
40
|
-
[evt: string]: CustomEvent<any>;
|
|
41
|
-
};
|
|
42
|
-
slots: {};
|
|
43
|
-
};
|
|
44
|
-
export type TopolEditorProps = typeof __propDef.props;
|
|
45
|
-
export type TopolEditorEvents = typeof __propDef.events;
|
|
46
|
-
export type TopolEditorSlots = typeof __propDef.slots;
|
|
47
|
-
export default class TopolEditor extends SvelteComponent<TopolEditorProps, TopolEditorEvents, TopolEditorSlots> {
|
|
48
|
-
}
|
|
49
|
-
export {};
|