@topol.io/editor-svelte 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2024 Ecomail s.r.o.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ <a href="https://topol.io" target="_blank">
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>
4
+
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://topol.io/docs#plugin-configuration)
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
+ ### List of all available TopolPlugin actions:
57
+
58
+ | Action | Description |
59
+ | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
60
+ | `TopolPlugin.save()` | Saves the content of the editor [more info](https://topol.io/docs#plugin-configuration) |
61
+ | `TopolPlugin.load(template)` | Loads the provided template [more info](https://topol.io/docs#save-and-load-options) |
62
+ | `TopolPlugin.togglePreview()` | Toggles editor preview [more info](https://topol.io/docs#preview-mode-on-desktop-and-mobile) |
63
+ | `TopolPlugin.togglePreviewSize()` | Toggles editor preview size |
64
+ | `TopolPlugin.undo()` | Undo change in editor [more info](https://topol.io/docs#redo-and-undo) |
65
+ | `TopolPlugin.redo()` | Redo change in editor [more info](https://topol.io/docs#redo-and-undo) |
66
+ | `TopolPlugin.setSavedBlocks(savedblock: ISavedBlock[])` | Sets the saved blocks [more info](https://topol.io/docs#saved-blocks) |
67
+ | `TopolPlugin.createNotification(notification: INotification)` | Creates editor's notification [more info](https://topol.io/docs#show-custom-notification-in-editor) |
68
+ | `TopolPlugin.changeEmailToMobile()` | Change email to mobile view [more info](https://topol.io/docs#mobile-first-email-template) |
69
+ | `TopolPlugin.changeEmailToDesktop()` | Change email to desktop view [more info](https://topol.io/docs#mobile-first-email-template) |
70
+ | `TopolPlugin.toggleBlocksAndStructuresVisibility()` | Toggle hidden structures visibility for blocks and structures [more info](https://topol.io/docs#mobile-first-email-template) |
71
+ | `TopolPlugin.destroy()` | Destroys the editor initialization [more info](https://topol.io/docs#working-with-js-frameworks) |
72
+
73
+ <br>
74
+
75
+ ## Editor Events
76
+
77
+ The callbacks from editor are received as component events.
78
+
79
+ ```html
80
+ <TopolEditor
81
+ options="{customOptions}"
82
+ on:onSave="{onSave}"
83
+ ></TopolEditor>
84
+ ```
85
+
86
+ ### List of all editor events
87
+
88
+ | Event | Description |
89
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------------- |
90
+ | `@onSave` | Returns object which contains html and json of the template} [more info](https://topol.io/docs#onsave-and-onsaveandclose) |
91
+ | `@onSaveAndClose` | Returns object which contains html and json of the template [more info](https://topol.io/docs#onsave-and-onsaveandclose) |
92
+ | `@onTestSend` | Returns object which contains email, html and json of the template [more info](https://topol.io/docs#on-test-send) |
93
+ | `@onOpenFileManager` | When user clicks file manager open [more info](https://topol.io/docs#custom-file-manager) |
94
+ | `@onLoaded` | After editor template is loaded using `TopolPlugin.load()` |
95
+ | `@onInit` | When editor inits [more info](https://topol.io/docs#custom-file-manager) |
96
+ | `@onBlockSave` | When user saves block in editor, returns object of type ISavedBlock [more info](https://topol.io/docs#saved-blocks) |
97
+ | `@onBlockRemove` | When user removes saved block, returns id of saved block to be removed [more info](https://topol.io/docs#saved-blocks) |
98
+ | `@onBlockEdit` | When user edits saved block, returns id of saved block to be updated [more info](https://topol.io/docs#saved-blocks) |
99
+ | `@onUndoChange` | When user clicks undo button, retunrs number of steps user undone [more info](https://topol.io/docs#redo-and-undo) |
100
+ | `@unRedoChange` | When user clicks redo button, retunrs number of steps user redone [more info](https://topol.io/docs#redo-and-undo) |
101
+ | `@onPreview` | When user switches to preview |
102
+ | `@onAlert` | When alert appears in editor [more info](https://topol.io/docs#show-custom-notification-in-editor) |
103
+ | `@onClose` | When close is click inside WindowBar [more info](https://topol.io/docs#window-bar) |
104
+
105
+ <br>
106
+
107
+ ## TypeScript
108
+
109
+ Topol Editor provides full TypeScript integration and exports all necessary types.
110
+
111
+ ```svelte
112
+ <script lang="ts">
113
+ import {
114
+ ITopolOptions,
115
+ INotification,
116
+ ISavedBlock,
117
+ } from '@topol.io/editor-svelte';
118
+ </script>
119
+ ```
@@ -0,0 +1,75 @@
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
+ //@ts-expect-error
54
+ onBannerClick(json, html) {
55
+ dispatch("onBannerClick", { json, html });
56
+ },
57
+ onEdittedWithoutSaveChanged(hasUnsavedChanges) {
58
+ dispatch("onEdittedWithoutSaveChanged", hasUnsavedChanges);
59
+ }
60
+ };
61
+ return { id: "#" + EDITOR_HTML_ID, ...options, callbacks: { ...callbacks } };
62
+ };
63
+ onMount(async () => {
64
+ const mergedTopolOptinos = mergeOptions();
65
+ await TopolPlugin.init(mergedTopolOptinos, { stage });
66
+ });
67
+ onDestroy(() => {
68
+ TopolPlugin.destroy();
69
+ });
70
+ </script>
71
+
72
+ <div
73
+ id="{EDITOR_HTML_ID}"
74
+ style="position: absolute; width: 100%; height: 100vh"
75
+ ></div>
@@ -0,0 +1,45 @@
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
+ } & {
36
+ [evt: string]: CustomEvent<any>;
37
+ };
38
+ slots: {};
39
+ };
40
+ export type TopolEditorProps = typeof __propDef.props;
41
+ export type TopolEditorEvents = typeof __propDef.events;
42
+ export type TopolEditorSlots = typeof __propDef.slots;
43
+ export default class TopolEditor extends SvelteComponent<TopolEditorProps, TopolEditorEvents, TopolEditorSlots> {
44
+ }
45
+ export {};
@@ -0,0 +1,4 @@
1
+ export { default as TopolPlugin } from '@topol.io/editor';
2
+ export type { INotification, IStage, ISavedBlock } from '@topol.io/editor';
3
+ export { default as TopolEditor } from './TopolEditor.svelte';
4
+ export type { ISvelteOptions as ITopolOptions } from './TopolEditor.svelte';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default as TopolPlugin } from '@topol.io/editor';
2
+ export { default as TopolEditor } from './TopolEditor.svelte';
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@topol.io/editor-svelte",
3
+ "description": "Official Svelte package for Topol Editor.",
4
+ "keywords": [
5
+ "plugin",
6
+ "editor",
7
+ "email",
8
+ "topol",
9
+ "topol.io",
10
+ "topol-svelte",
11
+ "email-svelte",
12
+ "email templates"
13
+ ],
14
+ "author": "Topol.io",
15
+ "homepage": "https://topol.io",
16
+ "license": "Apache-2.0",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "version": "0.0.1",
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "svelte": "./dist/index.js"
26
+ }
27
+ },
28
+ "types": "./dist/index.d.ts",
29
+ "svelte": "./dist/index.js",
30
+ "peerDependencies": {
31
+ "svelte": "^4.2.8"
32
+ },
33
+ "devDependencies": {
34
+ "@sveltejs/package": "^2.2.5",
35
+ "@sveltejs/vite-plugin-svelte": "^3.0.1",
36
+ "@tsconfig/svelte": "^5.0.2",
37
+ "svelte": "^4.2.8",
38
+ "svelte-check": "^3.6.2",
39
+ "tslib": "^2.6.2",
40
+ "typescript": "^5.2.2",
41
+ "vite": "^5.0.8"
42
+ },
43
+ "dependencies": {
44
+ "@topol.io/editor": "0.0.1"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "scripts": {
50
+ "dev": "vite",
51
+ "build": "svelte-package"
52
+ }
53
+ }