@topol.io/editor 1.0.0-alpha.6 → 1.0.0-alpha.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/dist/topol-plugin.es.js +79 -45
- package/dist/topol-plugin.umd.js +1 -1
- package/dist/types/src/core/script-loader.d.ts +15 -0
- package/dist/types/src/landing-page-editor/index.d.ts +17 -5
- package/dist/types/types/landing-page/ILandingPageEditorInstance.d.ts +8 -4
- package/dist/types/types/landing-page/ILandingPageOptions.d.ts +5 -1
- package/package.json +1 -1
package/dist/topol-plugin.es.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
function
|
|
1
|
+
function f(o) {
|
|
2
2
|
return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
|
|
3
3
|
}
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var P = function(t, e, i) {
|
|
5
|
+
var r = document.head || document.getElementsByTagName("head")[0], n = document.createElement("script");
|
|
6
6
|
typeof e == "function" && (i = e, e = {}), e = e || {}, i = i || function() {
|
|
7
|
-
}, n.type = e.type || "text/javascript", n.charset = e.charset || "utf8", n.async = "async" in e ? !!e.async : !0, n.src = t, e.attrs &&
|
|
8
|
-
var
|
|
9
|
-
|
|
7
|
+
}, n.type = e.type || "text/javascript", n.charset = e.charset || "utf8", n.async = "async" in e ? !!e.async : !0, n.src = t, e.attrs && m(n, e.attrs), e.text && (n.text = "" + e.text);
|
|
8
|
+
var l = "onload" in n ? w : E;
|
|
9
|
+
l(n, i), n.onload || w(n, i), r.appendChild(n);
|
|
10
10
|
};
|
|
11
|
-
function
|
|
11
|
+
function m(o, t) {
|
|
12
12
|
for (var e in t)
|
|
13
13
|
o.setAttribute(e, t[e]);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function w(o, t) {
|
|
16
16
|
o.onload = function() {
|
|
17
17
|
this.onerror = this.onload = null, t(null, o);
|
|
18
18
|
}, o.onerror = function() {
|
|
19
19
|
this.onerror = this.onload = null, t(new Error("Failed to load " + this.src), o);
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function E(o, t) {
|
|
23
23
|
o.onreadystatechange = function() {
|
|
24
24
|
this.readyState != "complete" && this.readyState != "loaded" || (this.onreadystatechange = null, t(null, o));
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
const
|
|
28
|
-
var
|
|
29
|
-
const
|
|
30
|
-
production:
|
|
31
|
-
dev:
|
|
32
|
-
staging:
|
|
33
|
-
},
|
|
34
|
-
function
|
|
27
|
+
const g = /* @__PURE__ */ f(P);
|
|
28
|
+
var u = { BASE_URL: "/", MODE: "production", DEV: !1, PROD: !0, SSR: !1 };
|
|
29
|
+
const h = "https://v3.email-assets.topol.io/loader/build.js", L = "https://v3.develop.email-assets.topol.io/loader/build.js", v = "https://v3.develop.email-assets.topol.io/loader/build.js", a = {
|
|
30
|
+
production: u.VITE_TOPOL_URL || h,
|
|
31
|
+
dev: u.VITE_TOPOL_DEV_URL || L,
|
|
32
|
+
staging: u.VITE_TOPOL_STAGING_URL || v
|
|
33
|
+
}, y = "https://d10h8ga60f7b91.cloudfront.net/preview-app-{stage}/loader/build.js";
|
|
34
|
+
function _(o) {
|
|
35
35
|
switch (o) {
|
|
36
36
|
case "dev":
|
|
37
37
|
return a.dev;
|
|
@@ -40,11 +40,11 @@ function h(o) {
|
|
|
40
40
|
case "production":
|
|
41
41
|
return a.production;
|
|
42
42
|
default:
|
|
43
|
-
return
|
|
43
|
+
return y.replace("{stage}", String(o));
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
const t =
|
|
46
|
+
function S(o = "production") {
|
|
47
|
+
const t = _(o);
|
|
48
48
|
if (!t) {
|
|
49
49
|
if (a.production)
|
|
50
50
|
return console.error(`[@topol.io/editor] No loader URL resolved for stage "${o}"; falling back to the production loader.`), a.production;
|
|
@@ -52,9 +52,9 @@ function E(o = "production") {
|
|
|
52
52
|
}
|
|
53
53
|
return t;
|
|
54
54
|
}
|
|
55
|
-
async function
|
|
55
|
+
async function A(o) {
|
|
56
56
|
return new Promise((t, e) => {
|
|
57
|
-
|
|
57
|
+
g(a.production, (i) => {
|
|
58
58
|
if (i !== null) {
|
|
59
59
|
e(i);
|
|
60
60
|
return;
|
|
@@ -63,7 +63,7 @@ async function v(o) {
|
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
|
-
const
|
|
66
|
+
const R = {
|
|
67
67
|
/**
|
|
68
68
|
* Initialize the Email Editor.
|
|
69
69
|
* @param topolOptions - Configuration options for the editor
|
|
@@ -71,14 +71,14 @@ const L = {
|
|
|
71
71
|
* @returns Promise that resolves to true when the editor is ready
|
|
72
72
|
*/
|
|
73
73
|
init: (o, t) => new Promise((e, i) => {
|
|
74
|
-
const
|
|
75
|
-
|
|
74
|
+
const r = S(t == null ? void 0 : t.stage);
|
|
75
|
+
g(r, async (n) => {
|
|
76
76
|
if (n !== null) {
|
|
77
|
-
if (
|
|
77
|
+
if (r !== a.production)
|
|
78
78
|
try {
|
|
79
|
-
return await
|
|
80
|
-
} catch (
|
|
81
|
-
i(
|
|
79
|
+
return await A(o), e(!0);
|
|
80
|
+
} catch (l) {
|
|
81
|
+
i(l);
|
|
82
82
|
}
|
|
83
83
|
i(n);
|
|
84
84
|
return;
|
|
@@ -215,7 +215,45 @@ const L = {
|
|
|
215
215
|
toggleDarkMode: () => {
|
|
216
216
|
window.TopolPlugin.toggleDarkMode();
|
|
217
217
|
}
|
|
218
|
-
},
|
|
218
|
+
}, O = "https://v1.page-assets.topol.io/topol-lpe.js", s = /* @__PURE__ */ new Map();
|
|
219
|
+
function D(o, t) {
|
|
220
|
+
if (t())
|
|
221
|
+
return Promise.resolve();
|
|
222
|
+
const e = s.get(o);
|
|
223
|
+
if (e)
|
|
224
|
+
return e;
|
|
225
|
+
const i = new Promise((r, n) => {
|
|
226
|
+
const l = typeof document < "u" ? U(o) : null;
|
|
227
|
+
if (l) {
|
|
228
|
+
const d = () => {
|
|
229
|
+
p(), r();
|
|
230
|
+
}, c = () => {
|
|
231
|
+
p(), n(new Error(`Failed to load script: ${o}`));
|
|
232
|
+
}, p = () => {
|
|
233
|
+
l.removeEventListener("load", d), l.removeEventListener("error", c);
|
|
234
|
+
};
|
|
235
|
+
l.addEventListener("load", d), l.addEventListener("error", c);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
g(o, (d) => {
|
|
239
|
+
d !== null ? n(d) : r();
|
|
240
|
+
});
|
|
241
|
+
}).finally(() => {
|
|
242
|
+
s.delete(o);
|
|
243
|
+
});
|
|
244
|
+
return s.set(o, i), i;
|
|
245
|
+
}
|
|
246
|
+
function U(o) {
|
|
247
|
+
const t = document.getElementsByTagName("script");
|
|
248
|
+
for (let e = 0; e < t.length; e++)
|
|
249
|
+
if (t[e].src === o)
|
|
250
|
+
return t[e];
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
function T() {
|
|
254
|
+
return typeof window < "u" && typeof window.LandingPageEditor == "function";
|
|
255
|
+
}
|
|
256
|
+
const C = {
|
|
219
257
|
/**
|
|
220
258
|
* Inits Landing Page Editor.
|
|
221
259
|
*
|
|
@@ -223,20 +261,16 @@ const L = {
|
|
|
223
261
|
* @param pluginOptions - Plugin options (reserved for future staging/dev URL support)
|
|
224
262
|
* @returns Promise that resolves with the editor instance
|
|
225
263
|
*/
|
|
226
|
-
init: (o, t) =>
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
e(n);
|
|
234
|
-
});
|
|
235
|
-
})
|
|
236
|
-
}, y = L;
|
|
264
|
+
init: async (o, t) => {
|
|
265
|
+
if (await D(O, T), !T())
|
|
266
|
+
throw new Error("[@topol.io/editor] topol-lpe.js loaded but window.LandingPageEditor is not defined.");
|
|
267
|
+
const e = window.LandingPageEditor(o);
|
|
268
|
+
return e.destroy ?? (e.destroy = () => e.close()), e;
|
|
269
|
+
}
|
|
270
|
+
}, I = R;
|
|
237
271
|
export {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
272
|
+
R as EmailEditor,
|
|
273
|
+
C as LandingPageEditor,
|
|
274
|
+
I as TopolPlugin,
|
|
275
|
+
I as default
|
|
242
276
|
};
|
package/dist/topol-plugin.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,
|
|
1
|
+
(function(l,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(l=typeof globalThis<"u"?globalThis:l||self,u(l["topol-plugin"]={}))})(this,function(l){"use strict";function u(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var L=function(n,o,i){var d=document.head||document.getElementsByTagName("head")[0],t=document.createElement("script");typeof o=="function"&&(i=o,o={}),o=o||{},i=i||function(){},t.type=o.type||"text/javascript",t.charset=o.charset||"utf8",t.async="async"in o?!!o.async:!0,t.src=n,o.attrs&&h(t,o.attrs),o.text&&(t.text=""+o.text);var r="onload"in t?w:v;r(t,i),t.onload||w(t,i),d.appendChild(t)};function h(e,n){for(var o in n)e.setAttribute(o,n[o])}function w(e,n){e.onload=function(){this.onerror=this.onload=null,n(null,e)},e.onerror=function(){this.onerror=this.onload=null,n(new Error("Failed to load "+this.src),e)}}function v(e,n){e.onreadystatechange=function(){this.readyState!="complete"&&this.readyState!="loaded"||(this.onreadystatechange=null,n(null,e))}}const g=u(L);var c={BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1};const a={production:c.VITE_TOPOL_URL||"https://v3.email-assets.topol.io/loader/build.js",dev:c.VITE_TOPOL_DEV_URL||"https://v3.develop.email-assets.topol.io/loader/build.js",staging:c.VITE_TOPOL_STAGING_URL||"https://v3.develop.email-assets.topol.io/loader/build.js"},_="https://d10h8ga60f7b91.cloudfront.net/preview-app-{stage}/loader/build.js";function y(e){switch(e){case"dev":return a.dev;case"staging":return a.staging;case"production":return a.production;default:return _.replace("{stage}",String(e))}}function A(e="production"){const n=y(e);if(!n){if(a.production)return console.error(`[@topol.io/editor] No loader URL resolved for stage "${e}"; falling back to the production loader.`),a.production;throw new Error(`[@topol.io/editor] Could not resolve a loader URL for stage "${e}". The editor cannot be loaded.`)}return n}async function S(e){return new Promise((n,o)=>{g(a.production,i=>{if(i!==null){o(i);return}window.TopolPlugin.init(e),n(!0)})})}const f={init:(e,n)=>new Promise((o,i)=>{const d=A(n==null?void 0:n.stage);g(d,async t=>{if(t!==null){if(d!==a.production)try{return await S(e),o(!0)}catch(r){i(r)}i(t);return}window.TopolPlugin.init(e),o(!0)})}),save:e=>{window.TopolPlugin.save(e)},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()},destroy:()=>{window.TopolPlugin.destroy()},setSavedBlocks:e=>{window.TopolPlugin.setSavedBlocks(e)},setPreviewHTML:e=>{window.TopolPlugin.setPreviewHTML(e)},createNotification:e=>{window.TopolPlugin.createNotification(e)},setActiveMembers:e=>{window.TopolPlugin.setActiveMembers(e)},changeEmailToMobile:()=>{window.TopolPlugin.changeEmailToMobile()},changeEmailToDesktop:()=>{window.TopolPlugin.changeEmailToDesktop()},toggleBlocksAndStructuresVisibility:()=>{window.TopolPlugin.toggleBlocksAndStructuresVisibility()},updateCustomBlockContent:e=>{window.TopolPlugin.updateCustomBlockContent(e)},refreshComments:e=>{window.TopolPlugin.refreshComments(e)},refreshSyncedRows:()=>{window.TopolPlugin.refreshSyncedRows()},openPremadeTemplatesSelection:()=>{window.TopolPlugin.openPremadeTemplatesSelection()},updateApiAuthorizationHeader:e=>{window.TopolPlugin.updateApiAuthorizationHeader(e)},setTemplateName:e=>{window.TopolPlugin.setTemplateName(e)},updateOptions:e=>{window.TopolPlugin.updateOptions(e)},toggleChatAI:()=>{window.TopolPlugin.toggleChatAI()},toggleAutosaves:()=>{window.TopolPlugin.toggleAutosaves()},toggleComments:()=>{window.TopolPlugin.toggleComments()},createLanguage:e=>{window.TopolPlugin.createLanguage(e)},setPrimaryLanguage:e=>{window.TopolPlugin.setPrimaryLanguage(e)},deleteLanguage:e=>{window.TopolPlugin.deleteLanguage(e)},selectLanguage:e=>{window.TopolPlugin.selectLanguage(e)},getMutations:()=>window.TopolPlugin.getMutations(),toggleControlPanel:()=>{window.TopolPlugin.toggleControlPanel()},updateTemplate:(e,n)=>{window.TopolPlugin.updateTemplate(e,n)},toggleDarkMode:()=>{window.TopolPlugin.toggleDarkMode()}},R="https://v1.page-assets.topol.io/topol-lpe.js",p=new Map;function U(e,n){if(n())return Promise.resolve();const o=p.get(e);if(o)return o;const i=new Promise((d,t)=>{const r=typeof document<"u"?D(e):null;if(r){const s=()=>{E(),d()},m=()=>{E(),t(new Error(`Failed to load script: ${e}`))},E=()=>{r.removeEventListener("load",s),r.removeEventListener("error",m)};r.addEventListener("load",s),r.addEventListener("error",m);return}g(e,s=>{s!==null?t(s):d()})}).finally(()=>{p.delete(e)});return p.set(e,i),i}function D(e){const n=document.getElementsByTagName("script");for(let o=0;o<n.length;o++)if(n[o].src===e)return n[o];return null}function T(){return typeof window<"u"&&typeof window.LandingPageEditor=="function"}const O={init:async(e,n)=>{if(await U(R,T),!T())throw new Error("[@topol.io/editor] topol-lpe.js loaded but window.LandingPageEditor is not defined.");const o=window.LandingPageEditor(e);return o.destroy??(o.destroy=()=>o.close()),o}},P=f;l.EmailEditor=f,l.LandingPageEditor=O,l.TopolPlugin=P,l.default=P,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -5,3 +5,18 @@
|
|
|
5
5
|
* @returns Promise that resolves when script is loaded
|
|
6
6
|
*/
|
|
7
7
|
export declare function loadScriptWithFallback(url: string, fallbackUrl?: string): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Loads a script at most once per page.
|
|
10
|
+
*
|
|
11
|
+
* - If `isReady()` already reports the global the script defines, resolves immediately
|
|
12
|
+
* without touching the DOM (the script was loaded by a previous init() call or by the host page).
|
|
13
|
+
* - If a load for the same URL is already in flight, returns the same promise so concurrent
|
|
14
|
+
* init() calls (e.g. React StrictMode double-invoking effects) share one `<script>` tag.
|
|
15
|
+
* - If the host page already has a `<script src="url">` tag that hasn't finished loading,
|
|
16
|
+
* waits for it instead of injecting a duplicate.
|
|
17
|
+
* - A failed load is not cached, so the next call retries.
|
|
18
|
+
*
|
|
19
|
+
* @param url - Script URL
|
|
20
|
+
* @param isReady - Returns true once the global the script defines is available
|
|
21
|
+
*/
|
|
22
|
+
export declare function loadScriptOnce(url: string, isReady: () => boolean): Promise<void>;
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import type ILandingPageOptions from "../../types/landing-page/ILandingPageOptions";
|
|
2
2
|
import type ILandingPageEditorInstance from "../../types/landing-page/ILandingPageEditorInstance";
|
|
3
3
|
import { Stage } from "../../types/Stage";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Raw zoid component instance created by the CDN runtime (topol-lpe.js).
|
|
6
|
+
* It exposes close() rather than destroy(); init() aliases the latter.
|
|
7
|
+
*/
|
|
8
|
+
type RawLandingPageEditorInstance = Omit<ILandingPageEditorInstance, "destroy"> & {
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
destroy?(): Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
type LandingPageEditorFactory = (options: ILandingPageOptions) => RawLandingPageEditorInstance;
|
|
5
13
|
declare global {
|
|
6
14
|
interface Window {
|
|
7
15
|
LandingPageEditor: LandingPageEditorFactory;
|
|
@@ -20,6 +28,10 @@ export interface LandingPageEditorPluginOptions {
|
|
|
20
28
|
* This integration loads the Topol Landing Page Editor into your application.
|
|
21
29
|
* Unlike the Email Editor, this creates an instance that you can interact with.
|
|
22
30
|
*
|
|
31
|
+
* The runtime script is injected at most once per page; subsequent init() calls
|
|
32
|
+
* reuse the already-loaded runtime, so opening the editor repeatedly (or React StrictMode
|
|
33
|
+
* double-mounting) does not inject duplicate script tags.
|
|
34
|
+
*
|
|
23
35
|
* @example
|
|
24
36
|
* ```typescript
|
|
25
37
|
* import { LandingPageEditor } from '@topol.io/editor';
|
|
@@ -29,17 +41,17 @@ export interface LandingPageEditorPluginOptions {
|
|
|
29
41
|
* authorize: { apiKey: 'your-key', userId: 'user-123' },
|
|
30
42
|
* },
|
|
31
43
|
* onSave(json, html) { console.log('Saved:', json, html); },
|
|
32
|
-
* onLoaded() { console.log('
|
|
44
|
+
* onLoaded() { console.log('Template loaded'); }
|
|
33
45
|
* });
|
|
34
46
|
*
|
|
35
|
-
* // Render the editor into a container
|
|
36
|
-
* editor.render('#landing-page-editor');
|
|
47
|
+
* // Render the editor into a container (resolves once the iframe is rendered)
|
|
48
|
+
* await editor.render('#landing-page-editor');
|
|
37
49
|
*
|
|
38
50
|
* // Optionally load a template
|
|
39
51
|
* editor.load(templateJson);
|
|
40
52
|
*
|
|
41
53
|
* // Clean up when done
|
|
42
|
-
* editor.destroy();
|
|
54
|
+
* await editor.destroy();
|
|
43
55
|
* ```
|
|
44
56
|
*/
|
|
45
57
|
export declare const LandingPageEditor: {
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Instance of the Landing Page Editor returned by
|
|
2
|
+
* Instance of the Landing Page Editor returned by LandingPageEditor.init().
|
|
3
3
|
*/
|
|
4
4
|
export default interface ILandingPageEditorInstance {
|
|
5
5
|
/**
|
|
6
6
|
* Render the editor into a container element.
|
|
7
|
-
*
|
|
7
|
+
*
|
|
8
|
+
* The returned promise resolves once the editor iframe has been rendered and
|
|
9
|
+
* rejects if the container cannot be found or the instance was destroyed meanwhile.
|
|
10
|
+
*
|
|
11
|
+
* @param container - CSS selector for the container element (e.g., "#landing-page-editor") or the element itself
|
|
8
12
|
*/
|
|
9
|
-
render(
|
|
13
|
+
render(container: string | HTMLElement): Promise<void>;
|
|
10
14
|
/**
|
|
11
15
|
* Load a template into the editor.
|
|
12
16
|
* @param template - The template data (JSON structure)
|
|
@@ -19,5 +23,5 @@ export default interface ILandingPageEditorInstance {
|
|
|
19
23
|
/**
|
|
20
24
|
* Destroy the editor instance and clean up resources.
|
|
21
25
|
*/
|
|
22
|
-
destroy(): void
|
|
26
|
+
destroy(): Promise<void>;
|
|
23
27
|
}
|
|
@@ -22,7 +22,11 @@ export interface ILandingPageCallbacks {
|
|
|
22
22
|
*/
|
|
23
23
|
onSaveAndClose?(json: unknown, html: unknown): void;
|
|
24
24
|
/**
|
|
25
|
-
* Called
|
|
25
|
+
* Called after a template has been loaded into the editor via `load()`.
|
|
26
|
+
*
|
|
27
|
+
* Note: this is NOT an "editor ready" signal. The runtime does not currently emit a
|
|
28
|
+
* separate ready event; `render()` resolving is the closest equivalent, and `load()`
|
|
29
|
+
* can be called as soon as `render()` resolves.
|
|
26
30
|
*/
|
|
27
31
|
onLoaded?(): void;
|
|
28
32
|
/**
|