@topol.io/editor-react 0.0.0-alfa.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +107 -0
- package/dist/topol-editor-react.es.js +327 -0
- package/dist/topol-editor-react.umd.js +12 -0
- package/dist/types/src/TopolEditor.d.ts +23 -0
- package/dist/types/types/IReactTopolOptions.d.ts +33 -0
- package/package.json +52 -0
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.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
|
|
10
|
+
# Documentation
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
Install Editor from NPM using:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @topol.io/editor-react
|
|
17
|
+
|
|
18
|
+
//or
|
|
19
|
+
|
|
20
|
+
yarn add @topol.io/editor-react
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Use in Component
|
|
24
|
+
In your React component import and add the simplest options.
|
|
25
|
+
|
|
26
|
+
For more options see the docs for [TopolOptions configuration](https://topol.io/docs#plugin-configuration)
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import TopolEditor from '@topol.io/editor-react';
|
|
30
|
+
|
|
31
|
+
const customOptions = {
|
|
32
|
+
authorize: {
|
|
33
|
+
apiKey: "YOUR_API_TOKEN",
|
|
34
|
+
userId: "some-user-id",
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```jsx
|
|
41
|
+
<TopolEditor options={customOptions}></TopolEditor>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Call Topol Plugin actions
|
|
46
|
+
To call actions to the editor import:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import { TopolPlugin } from '@topol.io/editor-react';
|
|
50
|
+
|
|
51
|
+
TopolPlugin.save();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### List of all available TopolPlugin actions:
|
|
55
|
+
|
|
56
|
+
| Action | Description |
|
|
57
|
+
| --- | ----------- |
|
|
58
|
+
| `TopolPlugin.save()` | Saves the content of the editor [more info](https://topol.io/docs#plugin-configuration) |
|
|
59
|
+
| `TopolPlugin.load(template`) | Loads the provided template [more info](https://topol.io/docs#save-and-load-options) |
|
|
60
|
+
| `TopolPlugin.togglePreview()` | Toggles editor preview [more info](https://topol.io/docs#preview-mode-on-desktop-and-mobile)|
|
|
61
|
+
| `TopolPlugin.togglePreviewSize()` | Toggles editor preview size |
|
|
62
|
+
| `TopolPlugin.undo()` | Undo change in editor [more info](https://topol.io/docs#redo-and-undo)|
|
|
63
|
+
| `TopolPlugin.redo()` | Redo change in editor [more info](https://topol.io/docs#redo-and-undo)|
|
|
64
|
+
| `TopolPlugin.setSavedBlocks(savedblock: ISavedBlock[])` | Sets the saved blocks [more info](https://topol.io/docs#saved-blocks) |
|
|
65
|
+
| `TopolPlugin.createNotification(notification: INotification)` | Creates editor's notification [more info](https://topol.io/docs#show-custom-notification-in-editor) |
|
|
66
|
+
| `TopolPlugin.changeEmailToMobile()` | Change email to mobile view [more info](https://topol.io/docs#mobile-first-email-template)|
|
|
67
|
+
| `TopolPlugin.changeEmailToDesktop()` | Change email to desktop view [more info](https://topol.io/docs#mobile-first-email-template)|
|
|
68
|
+
| `TopolPlugin.toggleBlocksAndStructuresVisibility()` | Toggle hidden structures visibility for blocks and structures [more info](https://topol.io/docs#mobile-first-email-template)|
|
|
69
|
+
| `TopolPlugin.destroy()` | Destroys the editor initialization [more info](https://topol.io/docs#working-with-js-frameworks) |
|
|
70
|
+
|
|
71
|
+
<br>
|
|
72
|
+
|
|
73
|
+
## Editor Events
|
|
74
|
+
|
|
75
|
+
The callbacks from editor are received as component events.
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
<TopolEditor options={customOptions} onSave={handleOnSave}></TopolEditor>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### List of all editor events
|
|
82
|
+
|
|
83
|
+
| Event | Description |
|
|
84
|
+
| --- | ----------- |
|
|
85
|
+
| `onSave` | Returns object which contains html and json of the template} [more info](https://topol.io/docs#onsave-and-onsaveandclose) |
|
|
86
|
+
| `onSaveAndClose` | Returns object which contains html and json of the template [more info](https://topol.io/docs#onsave-and-onsaveandclose) |
|
|
87
|
+
| `onTestSend` | Returns object which contains email, html and json of the template [more info](https://topol.io/docs#on-test-send) |
|
|
88
|
+
| `onOpenFileManager` | When user clicks file manager open [more info](https://topol.io/docs#custom-file-manager)|
|
|
89
|
+
| `onLoaded` | When editor is fully loaded |
|
|
90
|
+
| `onInit` | When editor inits [more info](https://topol.io/docs#custom-file-manager) |
|
|
91
|
+
| `onBlockSave` | When user saves block in editor, returns object of type ISavedBlock [more info](https://topol.io/docs#saved-blocks) |
|
|
92
|
+
| `onBlockRemove` | When user removes saved block, returns id of saved block to be removed [more info](https://topol.io/docs#saved-blocks) |
|
|
93
|
+
| `onBlockEdit` | When user edits saved block, returns id of saved block to be updated [more info](https://topol.io/docs#saved-blocks) |
|
|
94
|
+
| `onUndoChange` | When user clicks undo button, retunrs number of steps user undone [more info](https://topol.io/docs#redo-and-undo) |
|
|
95
|
+
| `unRedoChange` | When user clicks redo button, retunrs number of steps user redone [more info](https://topol.io/docs#redo-and-undo) |
|
|
96
|
+
| `onPreview` | When user switches to preview |
|
|
97
|
+
| `onAlert` | When alert appears in editor [more info](https://topol.io/docs#show-custom-notification-in-editor)|
|
|
98
|
+
|
|
99
|
+
<br>
|
|
100
|
+
|
|
101
|
+
## TypeScript
|
|
102
|
+
|
|
103
|
+
Topol Editor provides full TypeScript integration and exports all necessary types.
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
import { ITopolOptions, INotification, ISavedBlock } from '@topol.io/editor-react';
|
|
107
|
+
```
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import require$$0, { useEffect } from "react";
|
|
21
|
+
var loadScript = function load(src, opts, cb) {
|
|
22
|
+
var head = document.head || document.getElementsByTagName("head")[0];
|
|
23
|
+
var script = document.createElement("script");
|
|
24
|
+
if (typeof opts === "function") {
|
|
25
|
+
cb = opts;
|
|
26
|
+
opts = {};
|
|
27
|
+
}
|
|
28
|
+
opts = opts || {};
|
|
29
|
+
cb = cb || function() {
|
|
30
|
+
};
|
|
31
|
+
script.type = opts.type || "text/javascript";
|
|
32
|
+
script.charset = opts.charset || "utf8";
|
|
33
|
+
script.async = "async" in opts ? !!opts.async : true;
|
|
34
|
+
script.src = src;
|
|
35
|
+
if (opts.attrs) {
|
|
36
|
+
setAttributes(script, opts.attrs);
|
|
37
|
+
}
|
|
38
|
+
if (opts.text) {
|
|
39
|
+
script.text = "" + opts.text;
|
|
40
|
+
}
|
|
41
|
+
var onend = "onload" in script ? stdOnEnd : ieOnEnd;
|
|
42
|
+
onend(script, cb);
|
|
43
|
+
if (!script.onload) {
|
|
44
|
+
stdOnEnd(script, cb);
|
|
45
|
+
}
|
|
46
|
+
head.appendChild(script);
|
|
47
|
+
};
|
|
48
|
+
function setAttributes(script, attrs) {
|
|
49
|
+
for (var attr in attrs) {
|
|
50
|
+
script.setAttribute(attr, attrs[attr]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function stdOnEnd(script, cb) {
|
|
54
|
+
script.onload = function() {
|
|
55
|
+
this.onerror = this.onload = null;
|
|
56
|
+
cb(null, script);
|
|
57
|
+
};
|
|
58
|
+
script.onerror = function() {
|
|
59
|
+
this.onerror = this.onload = null;
|
|
60
|
+
cb(new Error("Failed to load " + this.src), script);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function ieOnEnd(script, cb) {
|
|
64
|
+
script.onreadystatechange = function() {
|
|
65
|
+
if (this.readyState != "complete" && this.readyState != "loaded")
|
|
66
|
+
return;
|
|
67
|
+
this.onreadystatechange = null;
|
|
68
|
+
cb(null, script);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const TOPOL_URL = "https://d5aoblv5p04cg.cloudfront.net/editor-3/loader/build.js";
|
|
72
|
+
const TOPOL_DEV_URL = "https://d5aoblv5p04cg.cloudfront.net/develop/loader/build.js";
|
|
73
|
+
const TopolPlugin = {
|
|
74
|
+
init: (topolOptions, options) => {
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
const topolURl = (options == null ? void 0 : options.dev) === true ? TOPOL_DEV_URL : TOPOL_URL;
|
|
77
|
+
loadScript(topolURl, (err) => {
|
|
78
|
+
if (err !== null) {
|
|
79
|
+
reject(err);
|
|
80
|
+
}
|
|
81
|
+
window.TopolPlugin.init(topolOptions);
|
|
82
|
+
resolve(true);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
save: () => {
|
|
87
|
+
window.TopolPlugin.save();
|
|
88
|
+
},
|
|
89
|
+
load: (json) => {
|
|
90
|
+
window.TopolPlugin.load(json);
|
|
91
|
+
},
|
|
92
|
+
togglePreview: () => {
|
|
93
|
+
window.TopolPlugin.togglePreview();
|
|
94
|
+
},
|
|
95
|
+
togglePreviewSize: () => {
|
|
96
|
+
window.TopolPlugin.togglePreviewSize();
|
|
97
|
+
},
|
|
98
|
+
chooseFile: (url) => {
|
|
99
|
+
window.TopolPlugin.chooseFile(url);
|
|
100
|
+
},
|
|
101
|
+
undo: () => {
|
|
102
|
+
window.TopolPlugin.undo();
|
|
103
|
+
},
|
|
104
|
+
redo: () => {
|
|
105
|
+
window.TopolPlugin.redo();
|
|
106
|
+
},
|
|
107
|
+
setSavedBlocks: (savedBlocks) => {
|
|
108
|
+
window.TopolPlugin.setSavedBlocks(savedBlocks);
|
|
109
|
+
},
|
|
110
|
+
createNotification: (notification) => {
|
|
111
|
+
window.TopolPlugin.createNotification(notification);
|
|
112
|
+
},
|
|
113
|
+
changeEmailToMobile: () => {
|
|
114
|
+
window.TopolPlugin.changeEmailToMobile();
|
|
115
|
+
},
|
|
116
|
+
changeEmailToDesktop: () => {
|
|
117
|
+
window.TopolPlugin.changeEmailToDesktop();
|
|
118
|
+
},
|
|
119
|
+
toggleBlocksAndStructuresVisibility: () => {
|
|
120
|
+
window.TopolPlugin.toggleBlocksAndStructuresVisibility();
|
|
121
|
+
},
|
|
122
|
+
destroy: () => {
|
|
123
|
+
window.TopolPlugin.destroy();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var jsxRuntime = { exports: {} };
|
|
127
|
+
var reactJsxRuntime_production_min = {};
|
|
128
|
+
/*
|
|
129
|
+
object-assign
|
|
130
|
+
(c) Sindre Sorhus
|
|
131
|
+
@license MIT
|
|
132
|
+
*/
|
|
133
|
+
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
|
134
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
135
|
+
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
|
136
|
+
function toObject(val) {
|
|
137
|
+
if (val === null || val === void 0) {
|
|
138
|
+
throw new TypeError("Object.assign cannot be called with null or undefined");
|
|
139
|
+
}
|
|
140
|
+
return Object(val);
|
|
141
|
+
}
|
|
142
|
+
function shouldUseNative() {
|
|
143
|
+
try {
|
|
144
|
+
if (!Object.assign) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
var test1 = new String("abc");
|
|
148
|
+
test1[5] = "de";
|
|
149
|
+
if (Object.getOwnPropertyNames(test1)[0] === "5") {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
var test2 = {};
|
|
153
|
+
for (var i = 0; i < 10; i++) {
|
|
154
|
+
test2["_" + String.fromCharCode(i)] = i;
|
|
155
|
+
}
|
|
156
|
+
var order2 = Object.getOwnPropertyNames(test2).map(function(n2) {
|
|
157
|
+
return test2[n2];
|
|
158
|
+
});
|
|
159
|
+
if (order2.join("") !== "0123456789") {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
var test3 = {};
|
|
163
|
+
"abcdefghijklmnopqrst".split("").forEach(function(letter) {
|
|
164
|
+
test3[letter] = letter;
|
|
165
|
+
});
|
|
166
|
+
if (Object.keys(Object.assign({}, test3)).join("") !== "abcdefghijklmnopqrst") {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
return true;
|
|
170
|
+
} catch (err) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
shouldUseNative() ? Object.assign : function(target, source) {
|
|
175
|
+
var from;
|
|
176
|
+
var to = toObject(target);
|
|
177
|
+
var symbols;
|
|
178
|
+
for (var s = 1; s < arguments.length; s++) {
|
|
179
|
+
from = Object(arguments[s]);
|
|
180
|
+
for (var key in from) {
|
|
181
|
+
if (hasOwnProperty.call(from, key)) {
|
|
182
|
+
to[key] = from[key];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (getOwnPropertySymbols) {
|
|
186
|
+
symbols = getOwnPropertySymbols(from);
|
|
187
|
+
for (var i = 0; i < symbols.length; i++) {
|
|
188
|
+
if (propIsEnumerable.call(from, symbols[i])) {
|
|
189
|
+
to[symbols[i]] = from[symbols[i]];
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return to;
|
|
195
|
+
};
|
|
196
|
+
/** @license React v17.0.2
|
|
197
|
+
* react-jsx-runtime.production.min.js
|
|
198
|
+
*
|
|
199
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
200
|
+
*
|
|
201
|
+
* This source code is licensed under the MIT license found in the
|
|
202
|
+
* LICENSE file in the root directory of this source tree.
|
|
203
|
+
*/
|
|
204
|
+
var f = require$$0, g = 60103;
|
|
205
|
+
reactJsxRuntime_production_min.Fragment = 60107;
|
|
206
|
+
if (typeof Symbol === "function" && Symbol.for) {
|
|
207
|
+
var h = Symbol.for;
|
|
208
|
+
g = h("react.element");
|
|
209
|
+
reactJsxRuntime_production_min.Fragment = h("react.fragment");
|
|
210
|
+
}
|
|
211
|
+
var m = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, n = Object.prototype.hasOwnProperty, p = { key: true, ref: true, __self: true, __source: true };
|
|
212
|
+
function q(c, a, k) {
|
|
213
|
+
var b, d = {}, e = null, l = null;
|
|
214
|
+
k !== void 0 && (e = "" + k);
|
|
215
|
+
a.key !== void 0 && (e = "" + a.key);
|
|
216
|
+
a.ref !== void 0 && (l = a.ref);
|
|
217
|
+
for (b in a)
|
|
218
|
+
n.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
219
|
+
if (c && c.defaultProps)
|
|
220
|
+
for (b in a = c.defaultProps, a)
|
|
221
|
+
d[b] === void 0 && (d[b] = a[b]);
|
|
222
|
+
return { $$typeof: g, type: c, key: e, ref: l, props: d, _owner: m.current };
|
|
223
|
+
}
|
|
224
|
+
reactJsxRuntime_production_min.jsx = q;
|
|
225
|
+
reactJsxRuntime_production_min.jsxs = q;
|
|
226
|
+
{
|
|
227
|
+
jsxRuntime.exports = reactJsxRuntime_production_min;
|
|
228
|
+
}
|
|
229
|
+
const jsx = jsxRuntime.exports.jsx;
|
|
230
|
+
const EDITOR_HTML_ID = "editor";
|
|
231
|
+
function TopolEditor(props) {
|
|
232
|
+
const mergeOptions = () => {
|
|
233
|
+
const callbacks = {
|
|
234
|
+
onSave(json, html) {
|
|
235
|
+
if (props.onSave !== void 0) {
|
|
236
|
+
props.onSave(json, html);
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
onSaveAndClose(json, html) {
|
|
240
|
+
if (props.onSaveAndClose !== void 0) {
|
|
241
|
+
props.onSaveAndClose(json, html);
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
onTestSend(email, json, html) {
|
|
245
|
+
if (props.onTestSend !== void 0) {
|
|
246
|
+
props.onTestSend(email, json, html);
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
onOpenFileManager() {
|
|
250
|
+
if (props.onOpenFileManager !== void 0) {
|
|
251
|
+
props.onOpenFileManager();
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
onLoaded() {
|
|
255
|
+
if (props.onLoaded !== void 0) {
|
|
256
|
+
props.onLoaded();
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
onBlockSave(block) {
|
|
260
|
+
if (props.onBlockSave !== void 0) {
|
|
261
|
+
props.onBlockSave(block);
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
onBlockRemove(blockId) {
|
|
265
|
+
if (props.onBlockRemove !== void 0) {
|
|
266
|
+
props.onBlockRemove(blockId);
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
onBlockEdit(blockId) {
|
|
270
|
+
if (props.onBlockEdit !== void 0) {
|
|
271
|
+
props.onBlockEdit(blockId);
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
onInit() {
|
|
275
|
+
if (props.onInit !== void 0) {
|
|
276
|
+
props.onInit();
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
onUndoChange(count) {
|
|
280
|
+
if (props.onUndoChange !== void 0) {
|
|
281
|
+
props.onUndoChange(count);
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
onRedoChange(count) {
|
|
285
|
+
if (props.onRedoChange !== void 0) {
|
|
286
|
+
props.onRedoChange(count);
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
onPreview(html) {
|
|
290
|
+
if (props.onPreview !== void 0) {
|
|
291
|
+
props.onPreview(html);
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
onAlert(notification) {
|
|
295
|
+
if (props.onAlert !== void 0) {
|
|
296
|
+
props.onAlert(notification);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
return __spreadProps(__spreadValues({
|
|
301
|
+
id: "#" + EDITOR_HTML_ID
|
|
302
|
+
}, props.options), {
|
|
303
|
+
callbacks: __spreadValues({}, callbacks)
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
useEffect(() => {
|
|
307
|
+
const initializeEditor = async () => {
|
|
308
|
+
const mergedTopolOptinos = mergeOptions();
|
|
309
|
+
await TopolPlugin.init(mergedTopolOptinos, {
|
|
310
|
+
dev: props.dev !== void 0 ? props.dev : false
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
initializeEditor();
|
|
314
|
+
return () => {
|
|
315
|
+
TopolPlugin.destroy();
|
|
316
|
+
};
|
|
317
|
+
}, []);
|
|
318
|
+
return /* @__PURE__ */ jsx("div", {
|
|
319
|
+
id: "editor",
|
|
320
|
+
style: {
|
|
321
|
+
position: "absolute",
|
|
322
|
+
height: "100vh",
|
|
323
|
+
width: "100%"
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
export { TopolPlugin, TopolEditor as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var M=Object.defineProperty,q=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var V=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var P=(l,a,d)=>a in l?M(l,a,{enumerable:!0,configurable:!0,writable:!0,value:d}):l[a]=d,v=(l,a)=>{for(var d in a||(a={}))V.call(a,d)&&P(l,d,a[d]);if(b)for(var d of b(a))$.call(a,d)&&P(l,d,a[d]);return l},T=(l,a)=>q(l,z(a));(function(l,a){typeof exports=="object"&&typeof module!="undefined"?a(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],a):(l=typeof globalThis!="undefined"?globalThis:l||self,a(l["topol-editor-react"]={},l.React))})(this,function(l,a){"use strict";function d(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var S=d(a),j=function(t,o,n){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("script");typeof o=="function"&&(n=o,o={}),o=o||{},n=n||function(){},i.type=o.type||"text/javascript",i.charset=o.charset||"utf8",i.async="async"in o?!!o.async:!0,i.src=t,o.attrs&&_(i,o.attrs),o.text&&(i.text=""+o.text);var u="onload"in i?g:E;u(i,n),i.onload||g(i,n),r.appendChild(i)};function _(e,t){for(var o in t)e.setAttribute(o,t[o])}function g(e,t){e.onload=function(){this.onerror=this.onload=null,t(null,e)},e.onerror=function(){this.onerror=this.onload=null,t(new Error("Failed to load "+this.src),e)}}function E(e,t){e.onreadystatechange=function(){this.readyState!="complete"&&this.readyState!="loaded"||(this.onreadystatechange=null,t(null,e))}}const k="https://d5aoblv5p04cg.cloudfront.net/editor-3/loader/build.js",R="https://d5aoblv5p04cg.cloudfront.net/develop/loader/build.js",s={init:(e,t)=>new Promise((o,n)=>{const r=(t==null?void 0:t.dev)===!0?R:k;j(r,i=>{i!==null&&n(i),window.TopolPlugin.init(e),o(!0)})}),save:()=>{window.TopolPlugin.save()},load:e=>{window.TopolPlugin.load(e)},togglePreview:()=>{window.TopolPlugin.togglePreview()},togglePreviewSize:()=>{window.TopolPlugin.togglePreviewSize()},chooseFile:e=>{window.TopolPlugin.chooseFile(e)},undo:()=>{window.TopolPlugin.undo()},redo:()=>{window.TopolPlugin.redo()},setSavedBlocks:e=>{window.TopolPlugin.setSavedBlocks(e)},createNotification:e=>{window.TopolPlugin.createNotification(e)},changeEmailToMobile:()=>{window.TopolPlugin.changeEmailToMobile()},changeEmailToDesktop:()=>{window.TopolPlugin.changeEmailToDesktop()},toggleBlocksAndStructuresVisibility:()=>{window.TopolPlugin.toggleBlocksAndStructuresVisibility()},destroy:()=>{window.TopolPlugin.destroy()}};var w={exports:{}},c={};/*
|
|
2
|
+
object-assign
|
|
3
|
+
(c) Sindre Sorhus
|
|
4
|
+
@license MIT
|
|
5
|
+
*/var h=Object.getOwnPropertySymbols,B=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;function p(e){if(e==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}function x(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de",Object.getOwnPropertyNames(e)[0]==="5")return!1;for(var t={},o=0;o<10;o++)t["_"+String.fromCharCode(o)]=o;var n=Object.getOwnPropertyNames(t).map(function(i){return t[i]});if(n.join("")!=="0123456789")return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(i){r[i]=i}),Object.keys(Object.assign({},r)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}x();/** @license React v17.0.2
|
|
6
|
+
* react-jsx-runtime.production.min.js
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/var L=S.default,y=60103;if(c.Fragment=60107,typeof Symbol=="function"&&Symbol.for){var m=Symbol.for;y=m("react.element"),c.Fragment=m("react.fragment")}var A=L.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,I=Object.prototype.hasOwnProperty,F={key:!0,ref:!0,__self:!0,__source:!0};function O(e,t,o){var n,r={},i=null,u=null;o!==void 0&&(i=""+o),t.key!==void 0&&(i=""+t.key),t.ref!==void 0&&(u=t.ref);for(n in t)I.call(t,n)&&!F.hasOwnProperty(n)&&(r[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps,t)r[n]===void 0&&(r[n]=t[n]);return{$$typeof:y,type:e,key:i,ref:u,props:r,_owner:A.current}}c.jsx=O,c.jsxs=O,w.exports=c;const N=w.exports.jsx,U="editor";function D(e){const t=()=>{const o={onSave(n,r){e.onSave!==void 0&&e.onSave(n,r)},onSaveAndClose(n,r){e.onSaveAndClose!==void 0&&e.onSaveAndClose(n,r)},onTestSend(n,r,i){e.onTestSend!==void 0&&e.onTestSend(n,r,i)},onOpenFileManager(){e.onOpenFileManager!==void 0&&e.onOpenFileManager()},onLoaded(){e.onLoaded!==void 0&&e.onLoaded()},onBlockSave(n){e.onBlockSave!==void 0&&e.onBlockSave(n)},onBlockRemove(n){e.onBlockRemove!==void 0&&e.onBlockRemove(n)},onBlockEdit(n){e.onBlockEdit!==void 0&&e.onBlockEdit(n)},onInit(){e.onInit!==void 0&&e.onInit()},onUndoChange(n){e.onUndoChange!==void 0&&e.onUndoChange(n)},onRedoChange(n){e.onRedoChange!==void 0&&e.onRedoChange(n)},onPreview(n){e.onPreview!==void 0&&e.onPreview(n)},onAlert(n){e.onAlert!==void 0&&e.onAlert(n)}};return T(v({id:"#"+U},e.options),{callbacks:v({},o)})};return a.useEffect(()=>((async()=>{const n=t();await s.init(n,{dev:e.dev!==void 0?e.dev:!1})})(),()=>{s.destroy()}),[]),N("div",{id:"editor",style:{position:"absolute",height:"100vh",width:"100%"}})}l.TopolPlugin=s,l.default=D,Object.defineProperty(l,"__esModule",{value:!0}),l[Symbol.toStringTag]="Module"});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import TopolPlugin, { INotification, ISavedBlock } from "@topol.io/editor";
|
|
3
|
+
import IReactTopolOptions from '../types/IReactTopolOptions';
|
|
4
|
+
declare type TopolEditorProps = {
|
|
5
|
+
options: IReactTopolOptions;
|
|
6
|
+
dev?: boolean;
|
|
7
|
+
onSave?(json: unknown, html: unknown): void;
|
|
8
|
+
onSaveAndClose?(json: unknown, html: unknown): void;
|
|
9
|
+
onTestSend?(email: string, json: unknown, html: unknown): void;
|
|
10
|
+
onOpenFileManager?(): void;
|
|
11
|
+
onLoaded?(): void;
|
|
12
|
+
onBlockSave?(block: ISavedBlock): void;
|
|
13
|
+
onBlockRemove?(blockId: number): void;
|
|
14
|
+
onBlockEdit?(blockId: number): void;
|
|
15
|
+
onInit?(): void;
|
|
16
|
+
onUndoChange?(count: number): void;
|
|
17
|
+
onRedoChange?(count: number): void;
|
|
18
|
+
onPreview?(html: unknown): void;
|
|
19
|
+
onAlert?(notification: INotification): void;
|
|
20
|
+
};
|
|
21
|
+
export default function TopolEditor(props: TopolEditorProps): JSX.Element;
|
|
22
|
+
export type { IReactTopolOptions, INotification, ISavedBlock };
|
|
23
|
+
export { TopolPlugin };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ISavedBlock, IMergeTagGroup, IContentBlockOptions, ITheme, IAuthHeaderConfig, IFont, IAPI } from "@topol.io/editor";
|
|
2
|
+
export default interface IReactOptions {
|
|
3
|
+
authorize: {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
userId: string | number;
|
|
6
|
+
};
|
|
7
|
+
title?: string;
|
|
8
|
+
removeTopBar?: boolean;
|
|
9
|
+
topBarOptions?: Array<string>;
|
|
10
|
+
mainMenuAlign?: "left" | "right";
|
|
11
|
+
disableAlerts?: boolean;
|
|
12
|
+
customFileManager?: boolean;
|
|
13
|
+
language?: string;
|
|
14
|
+
light?: boolean;
|
|
15
|
+
theme?: ITheme;
|
|
16
|
+
hideSettingsTab?: boolean;
|
|
17
|
+
imageEditor?: boolean;
|
|
18
|
+
premadeBlocks?: unknown | boolean;
|
|
19
|
+
savedBlocks?: Array<ISavedBlock> | boolean;
|
|
20
|
+
mergeTags?: Array<IMergeTagGroup>;
|
|
21
|
+
enableAutosaves?: boolean;
|
|
22
|
+
htmlMinified?: boolean;
|
|
23
|
+
apiAuthorizationHeader?: IAuthHeaderConfig | string;
|
|
24
|
+
contentBlocks?: IContentBlockOptions[];
|
|
25
|
+
api?: IAPI;
|
|
26
|
+
mobileFirstEnabled?: boolean;
|
|
27
|
+
fonts?: Array<IFont>;
|
|
28
|
+
tinyConfig?: unknown;
|
|
29
|
+
fontSizes?: Array<number>;
|
|
30
|
+
colors?: Array<string>;
|
|
31
|
+
googleApiKey?: string;
|
|
32
|
+
role?: "manager" | "editor" | "reader";
|
|
33
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@topol.io/editor-react",
|
|
3
|
+
"description": "Official React package for Topol Editor.",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"plugin",
|
|
6
|
+
"editor",
|
|
7
|
+
"email",
|
|
8
|
+
"topol",
|
|
9
|
+
"topol.io",
|
|
10
|
+
"topol-react",
|
|
11
|
+
"email-react",
|
|
12
|
+
"email templates"
|
|
13
|
+
],
|
|
14
|
+
"version": "0.0.0-alfa.0",
|
|
15
|
+
"author": "Topol.io",
|
|
16
|
+
"homepage": "https://topol.io",
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"main": "./dist/topol-editor-react.es.js",
|
|
22
|
+
"module": "./dist/topol-editor-react.es.js",
|
|
23
|
+
"types": "./dist/types/src/TopolEditor.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"import": "./dist/topol-editor-react.es.js",
|
|
27
|
+
"require": "./dist/topol-editor-react.umd.js",
|
|
28
|
+
"types": "./dist/types/src/TopolEditor.d.ts"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"dev": "vite",
|
|
33
|
+
"build": "vite build && yarn run build:types",
|
|
34
|
+
"build:types": "tsc -p tsconfig.prod.json"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@topol.io/editor": "^0.0.0-alfa.13"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"react": "^17.0.2",
|
|
41
|
+
"react-dom": "^17.0.2",
|
|
42
|
+
"@types/node": "^17.0.16",
|
|
43
|
+
"@types/react": "^17.0.33",
|
|
44
|
+
"@types/react-dom": "^17.0.10",
|
|
45
|
+
"@vitejs/plugin-react": "^1.0.7",
|
|
46
|
+
"typescript": "^4.5.4",
|
|
47
|
+
"vite": "^2.8.0"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|