@topol.io/editor 0.0.0-alfa.3 → 0.0.0-alfa.7

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 2022 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 CHANGED
@@ -1 +1,88 @@
1
- # Topol Plugin NPM package
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
17
+
18
+ //or
19
+
20
+ yarn add @topol.io/editor
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ Add HTML element Editor will load to
26
+
27
+ ```html
28
+ <div id="app" style="position: absolute; width: 100%; height: 100%"></div>
29
+ ```
30
+
31
+ In your JS or TS file import TopolPlugin, initialize the editor, as an ID provide the id you defined the HTML, in this example its `app`
32
+
33
+ For more options see the docs for [TopolOptions configuration](https://topol.io/docs#plugin-configuration)
34
+
35
+ ```js
36
+ import TopolPlugin from "@topol.io/editor";
37
+
38
+ const TOPOL_OPTIONS = {
39
+ id: "#app",
40
+ authorize: {
41
+ apiKey: "YOUR_API_TOKEN",
42
+ userId: "some-user-id",
43
+ },
44
+ callbacks: {
45
+ onSave(json, html) {},
46
+ },
47
+ };
48
+
49
+ TopolPlugin.init(TOPOL_OPTIONS);
50
+ ```
51
+
52
+ ## Call Topol Plugin actions
53
+
54
+ To call actions to the editor import:
55
+
56
+ ```js
57
+ import { TopolPlugin } from "@topol.io/editor";
58
+
59
+ TopolPlugin.save();
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://topol.io/docs#plugin-configuration) |
67
+ | `TopolPlugin.load(template`) | Loads the provided template [more info](https://topol.io/docs#save-and-load-options) |
68
+ | `TopolPlugin.togglePreview()` | Toggles editor preview [more info](https://topol.io/docs#preview-mode-on-desktop-and-mobile) |
69
+ | `TopolPlugin.togglePreviewSize()` | Toggles editor preview size |
70
+ | `TopolPlugin.undo()` | Undo change in editor [more info](https://topol.io/docs#redo-and-undo) |
71
+ | `TopolPlugin.redo()` | Redo change in editor [more info](https://topol.io/docs#redo-and-undo) |
72
+ | `TopolPlugin.setSavedBlocks(savedblock: ISavedBlock[])` | Sets the saved blocks [more info](https://topol.io/docs#saved-blocks) |
73
+ | `TopolPlugin.createNotification(notification: INotification)` | Creates editor's notification [more info](https://topol.io/docs#show-custom-notification-in-editor) |
74
+ | `TopolPlugin.changeEmailToMobile()` | Change email to mobile view [more info](https://topol.io/docs#mobile-first-email-template) |
75
+ | `TopolPlugin.changeEmailToDesktop()` | Change email to desktop view [more info](https://topol.io/docs#mobile-first-email-template) |
76
+ | `TopolPlugin.toggleBlocksAndStructuresVisibility()` | Toggle hidden structures visibility for blocks and structures [more info](https://topol.io/docs#mobile-first-email-template) |
77
+ | `TopolPlugin.destroy()` | Destroys the editor initialization [more info](https://topol.io/docs#working-with-js-frameworks) |
78
+
79
+ <br>
80
+
81
+ <br>
82
+ ## TypeScript
83
+
84
+ Topol Editor provides full TypeScript integration and exports all necessary types.
85
+
86
+ ```ts
87
+ import { ITopolOptions, INotification, ISavedBlock } from "@topol.io/editor";
88
+ ```
@@ -49,8 +49,8 @@ function ieOnEnd(script, cb) {
49
49
  };
50
50
  }
51
51
  const TOPOL_URL = "https://d5aoblv5p04cg.cloudfront.net/editor-3/loader/build.js";
52
- const createTopolPlugin = (options) => {
53
- const init = () => {
52
+ const TopolPlugin = {
53
+ init: (options) => {
54
54
  return new Promise((resolve, reject) => {
55
55
  loadScript(TOPOL_URL, (err) => {
56
56
  if (err !== null) {
@@ -60,61 +60,45 @@ const createTopolPlugin = (options) => {
60
60
  resolve(true);
61
61
  });
62
62
  });
63
- };
64
- const save = () => {
63
+ },
64
+ save: () => {
65
65
  window.TopolPlugin.save();
66
- };
67
- const load2 = (json) => {
66
+ },
67
+ load: (json) => {
68
68
  window.TopolPlugin.load(json);
69
- };
70
- const togglePreview = () => {
69
+ },
70
+ togglePreview: () => {
71
71
  window.TopolPlugin.togglePreview();
72
- };
73
- const togglePreviewSize = () => {
72
+ },
73
+ togglePreviewSize: () => {
74
74
  window.TopolPlugin.togglePreviewSize();
75
- };
76
- const chooseFile = (url) => {
75
+ },
76
+ chooseFile: (url) => {
77
77
  window.TopolPlugin.chooseFile(url);
78
- };
79
- const undo = () => {
78
+ },
79
+ undo: () => {
80
80
  window.TopolPlugin.undo();
81
- };
82
- const redo = () => {
81
+ },
82
+ redo: () => {
83
83
  window.TopolPlugin.redo();
84
- };
85
- const setSavedBlocks = (savedBlocks) => {
84
+ },
85
+ setSavedBlocks: (savedBlocks) => {
86
86
  window.TopolPlugin.setSavedBlocks(savedBlocks);
87
- };
88
- const createNotification = (notification) => {
87
+ },
88
+ createNotification: (notification) => {
89
89
  window.TopolPlugin.createNotification(notification);
90
- };
91
- const changeEmailToMobile = () => {
90
+ },
91
+ changeEmailToMobile: () => {
92
92
  window.TopolPlugin.changeEmailToMobile();
93
- };
94
- const changeEmailToDesktop = () => {
93
+ },
94
+ changeEmailToDesktop: () => {
95
95
  window.TopolPlugin.changeEmailToDesktop();
96
- };
97
- const toggleBlocksAndStructuresVisibility = () => {
96
+ },
97
+ toggleBlocksAndStructuresVisibility: () => {
98
98
  window.TopolPlugin.toggleBlocksAndStructuresVisibility();
99
- };
100
- const destroy = () => {
99
+ },
100
+ destroy: () => {
101
101
  window.TopolPlugin.destroy();
102
- };
103
- return {
104
- init,
105
- save,
106
- load: load2,
107
- togglePreview,
108
- togglePreviewSize,
109
- chooseFile,
110
- undo,
111
- redo,
112
- setSavedBlocks,
113
- createNotification,
114
- changeEmailToMobile,
115
- changeEmailToDesktop,
116
- toggleBlocksAndStructuresVisibility,
117
- destroy
118
- };
102
+ }
119
103
  };
120
- export { createTopolPlugin as default };
104
+ export { TopolPlugin as default };
@@ -1 +1 @@
1
- (function(d,a){typeof exports=="object"&&typeof module!="undefined"?module.exports=a():typeof define=="function"&&define.amd?define(a):(d=typeof globalThis!="undefined"?globalThis:d||self,d["topol-plugin"]=a())})(this,function(){"use strict";var d=function(i,o,l){var r=document.head||document.getElementsByTagName("head")[0],n=document.createElement("script");typeof o=="function"&&(l=o,o={}),o=o||{},l=l||function(){},n.type=o.type||"text/javascript",n.charset=o.charset||"utf8",n.async="async"in o?!!o.async:!0,n.src=i,o.attrs&&a(n,o.attrs),o.text&&(n.text=""+o.text);var s="onload"in n?c:g;s(n,l),n.onload||c(n,l),r.appendChild(n)};function a(e,i){for(var o in i)e.setAttribute(o,i[o])}function c(e,i){e.onload=function(){this.onerror=this.onload=null,i(null,e)},e.onerror=function(){this.onerror=this.onload=null,i(new Error("Failed to load "+this.src),e)}}function g(e,i){e.onreadystatechange=function(){this.readyState!="complete"&&this.readyState!="loaded"||(this.onreadystatechange=null,i(null,e))}}const w="https://d5aoblv5p04cg.cloudfront.net/editor-3/loader/build.js";return e=>({init:()=>new Promise((t,f)=>{d(w,u=>{u!==null&&f(u),window.TopolPlugin.init(e),t(!0)})}),save:()=>{window.TopolPlugin.save()},load:t=>{window.TopolPlugin.load(t)},togglePreview:()=>{window.TopolPlugin.togglePreview()},togglePreviewSize:()=>{window.TopolPlugin.togglePreviewSize()},chooseFile:t=>{window.TopolPlugin.chooseFile(t)},undo:()=>{window.TopolPlugin.undo()},redo:()=>{window.TopolPlugin.redo()},setSavedBlocks:t=>{window.TopolPlugin.setSavedBlocks(t)},createNotification:t=>{window.TopolPlugin.createNotification(t)},changeEmailToMobile:()=>{window.TopolPlugin.changeEmailToMobile()},changeEmailToDesktop:()=>{window.TopolPlugin.changeEmailToDesktop()},toggleBlocksAndStructuresVisibility:()=>{window.TopolPlugin.toggleBlocksAndStructuresVisibility()},destroy:()=>{window.TopolPlugin.destroy()}})});
1
+ (function(l,d){typeof exports=="object"&&typeof module!="undefined"?module.exports=d():typeof define=="function"&&define.amd?define(d):(l=typeof globalThis!="undefined"?globalThis:l||self,l["topol-plugin"]=d())})(this,function(){"use strict";var l=function(n,e,t){var c=document.head||document.getElementsByTagName("head")[0],i=document.createElement("script");typeof e=="function"&&(t=e,e={}),e=e||{},t=t||function(){},i.type=e.type||"text/javascript",i.charset=e.charset||"utf8",i.async="async"in e?!!e.async:!0,i.src=n,e.attrs&&d(i,e.attrs),e.text&&(i.text=""+e.text);var s="onload"in i?u:a;s(i,t),i.onload||u(i,t),c.appendChild(i)};function d(o,n){for(var e in n)o.setAttribute(e,n[e])}function u(o,n){o.onload=function(){this.onerror=this.onload=null,n(null,o)},o.onerror=function(){this.onerror=this.onload=null,n(new Error("Failed to load "+this.src),o)}}function a(o,n){o.onreadystatechange=function(){this.readyState!="complete"&&this.readyState!="loaded"||(this.onreadystatechange=null,n(null,o))}}const r="https://d5aoblv5p04cg.cloudfront.net/editor-3/loader/build.js";return{init:o=>new Promise((n,e)=>{l(r,t=>{t!==null&&e(t),window.TopolPlugin.init(o),n(!0)})}),save:()=>{window.TopolPlugin.save()},load:o=>{window.TopolPlugin.load(o)},togglePreview:()=>{window.TopolPlugin.togglePreview()},togglePreviewSize:()=>{window.TopolPlugin.togglePreviewSize()},chooseFile:o=>{window.TopolPlugin.chooseFile(o)},undo:()=>{window.TopolPlugin.undo()},redo:()=>{window.TopolPlugin.redo()},setSavedBlocks:o=>{window.TopolPlugin.setSavedBlocks(o)},createNotification:o=>{window.TopolPlugin.createNotification(o)},changeEmailToMobile:()=>{window.TopolPlugin.changeEmailToMobile()},changeEmailToDesktop:()=>{window.TopolPlugin.changeEmailToDesktop()},toggleBlocksAndStructuresVisibility:()=>{window.TopolPlugin.toggleBlocksAndStructuresVisibility()},destroy:()=>{window.TopolPlugin.destroy()}}});
@@ -7,8 +7,8 @@ declare global {
7
7
  TopolPlugin: ITopolPlugin;
8
8
  }
9
9
  }
10
- declare const createTopolPlugin: (options: ITopolOptions) => {
11
- init: () => Promise<boolean | string>;
10
+ declare const TopolPlugin: {
11
+ init: (options: ITopolOptions) => Promise<boolean | string>;
12
12
  save: () => void;
13
13
  load: (json: unknown) => void;
14
14
  togglePreview: () => void;
@@ -23,4 +23,7 @@ declare const createTopolPlugin: (options: ITopolOptions) => {
23
23
  toggleBlocksAndStructuresVisibility: () => void;
24
24
  destroy: () => void;
25
25
  };
26
- export default createTopolPlugin;
26
+ export default TopolPlugin;
27
+ export type { ITopolOptions };
28
+ export type { INotification };
29
+ export type { ISavedBlock };
package/package.json CHANGED
@@ -1,21 +1,33 @@
1
1
  {
2
2
  "name": "@topol.io/editor",
3
- "version": "0.0.0-alfa.3",
3
+ "description": "Official package for Topol Editor",
4
+ "keywords": [
5
+ "plugin",
6
+ "editor",
7
+ "email",
8
+ "topol",
9
+ "topol.io",
10
+ "email templates"
11
+ ],
12
+ "author": "Topol.io",
13
+ "homepage": "https://topol.io",
14
+ "license": "Apache-2.0",
15
+ "version": "0.0.0-alfa.7",
4
16
  "files": [
5
17
  "dist"
6
18
  ],
7
19
  "module": "./dist/topol-plugin.es.js",
8
- "types": "./dist/src/main.d.ts",
20
+ "types": "./dist/types/src/main.d.ts",
9
21
  "exports": {
10
22
  ".": {
11
23
  "import": "./dist/topol-plugin.es.js",
12
24
  "require": "./dist/topol-plugin.umd.js",
13
- "types": "./dist/src/main.d.ts"
25
+ "types": "./dist/types/src/main.d.ts"
14
26
  }
15
27
  },
16
28
  "scripts": {
17
29
  "dev": "vite",
18
- "build": "vite build",
30
+ "build": "vite build && tsc",
19
31
  "lint": "eslint --config '.eslintrc.js' ./**/*.ts --fix",
20
32
  "format": "prettier --write .",
21
33
  "build:types": "tsc"