@colegium_dev/vue3-unlayer-embed 1.0.15 → 1.1.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/dist/index.d.ts
CHANGED
|
@@ -39,6 +39,13 @@ message: string;
|
|
|
39
39
|
unlayerIframe: HTMLIFrameElement;
|
|
40
40
|
}, HTMLDivElement>;
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Monta el editor completo de Unlayer (iframe `?module=informes`) dentro de `container` y
|
|
44
|
+
* devuelve un objeto con la misma API que `window.unlayer`. Las llamadas hechas antes de que
|
|
45
|
+
* el iframe esté listo se encolan y se envían en orden.
|
|
46
|
+
*/
|
|
47
|
+
export declare function mountUnlayerIframe(container: HTMLElement, options?: UnlayerIframeOptions): UnlayerProxy;
|
|
48
|
+
|
|
42
49
|
declare type TemplateConfig = {
|
|
43
50
|
form: Array<TemplateContentForm>;
|
|
44
51
|
design: object;
|
|
@@ -55,4 +62,27 @@ declare type TemplateContentForm = {
|
|
|
55
62
|
value: string;
|
|
56
63
|
};
|
|
57
64
|
|
|
65
|
+
export declare type UnlayerIframeOptions = {
|
|
66
|
+
/** URL del iframe publicado. Por defecto, producción. */
|
|
67
|
+
iframeUrl?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Prefijos de `type` de los mensajes propios que se reenvían entre la app y Unlayer
|
|
70
|
+
* (p. ej. `['gzd']` para los `postMessage` de los `customJS` de Informes).
|
|
71
|
+
*/
|
|
72
|
+
relayPrefixes?: string[];
|
|
73
|
+
/** El iframe rechazó el dominio de la app o no pudo cargar Unlayer. */
|
|
74
|
+
onDenied?: (message: string) => void;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Sustituto de `window.unlayer`: cualquier método (`init`, `loadDesign`, `exportHtml`,
|
|
79
|
+
* `addEventListener`, `registerCallback`…) se ejecuta en el Unlayer del iframe.
|
|
80
|
+
* Los métodos no devuelven valor: los resultados llegan por callback, como en Unlayer.
|
|
81
|
+
*/
|
|
82
|
+
export declare type UnlayerProxy = {
|
|
83
|
+
[method: string]: (...args: any[]) => void;
|
|
84
|
+
/** Destruye el editor y quita el iframe. */
|
|
85
|
+
destroy: () => void;
|
|
86
|
+
};
|
|
87
|
+
|
|
58
88
|
export { }
|
|
@@ -1,127 +1,204 @@
|
|
|
1
|
-
import { watch as
|
|
2
|
-
function
|
|
3
|
-
return
|
|
1
|
+
import { watch as S, getCurrentScope as T, onScopeDispose as x, computed as A, toValue as M, unref as L, defineComponent as O, ref as P, onMounted as v, createElementBlock as R, openBlock as U, createElementVNode as _, toRaw as I } from "vue";
|
|
2
|
+
function W(n) {
|
|
3
|
+
return T() ? (x(n), !0) : !1;
|
|
4
4
|
}
|
|
5
|
-
const
|
|
5
|
+
const D = typeof window < "u" && typeof document < "u";
|
|
6
6
|
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
|
|
7
|
-
const
|
|
8
|
-
function
|
|
9
|
-
return Array.isArray(
|
|
7
|
+
const F = Object.prototype.toString, B = (n) => F.call(n) === "[object Object]";
|
|
8
|
+
function j(n) {
|
|
9
|
+
return Array.isArray(n) ? n : [n];
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
function G(n, a, l) {
|
|
12
|
+
return S(
|
|
13
|
+
n,
|
|
14
|
+
a,
|
|
15
15
|
{
|
|
16
|
-
...
|
|
16
|
+
...l,
|
|
17
17
|
immediate: !0
|
|
18
18
|
}
|
|
19
19
|
);
|
|
20
20
|
}
|
|
21
|
-
const N =
|
|
22
|
-
function
|
|
23
|
-
var
|
|
24
|
-
const
|
|
25
|
-
return (
|
|
21
|
+
const N = D ? window : void 0;
|
|
22
|
+
function $(n) {
|
|
23
|
+
var a;
|
|
24
|
+
const l = M(n);
|
|
25
|
+
return (a = l == null ? void 0 : l.$el) != null ? a : l;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
const
|
|
32
|
-
return
|
|
33
|
-
}),
|
|
27
|
+
function V(...n) {
|
|
28
|
+
const a = [], l = () => {
|
|
29
|
+
a.forEach((o) => o()), a.length = 0;
|
|
30
|
+
}, p = (o, e, t, s) => (o.addEventListener(e, t, s), () => o.removeEventListener(e, t, s)), f = A(() => {
|
|
31
|
+
const o = j(M(n[0])).filter((e) => e != null);
|
|
32
|
+
return o.every((e) => typeof e != "string") ? o : void 0;
|
|
33
|
+
}), u = G(
|
|
34
34
|
() => {
|
|
35
|
-
var
|
|
35
|
+
var o, e;
|
|
36
36
|
return [
|
|
37
|
-
(
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
(e = (o = f.value) == null ? void 0 : o.map((t) => $(t))) != null ? e : [N].filter((t) => t != null),
|
|
38
|
+
j(M(f.value ? n[1] : n[0])),
|
|
39
|
+
j(L(f.value ? n[2] : n[1])),
|
|
40
40
|
// @ts-expect-error - TypeScript gets the correct types, but somehow still complains
|
|
41
|
-
|
|
41
|
+
M(f.value ? n[3] : n[2])
|
|
42
42
|
];
|
|
43
43
|
},
|
|
44
|
-
([
|
|
45
|
-
if (
|
|
44
|
+
([o, e, t, s]) => {
|
|
45
|
+
if (l(), !(o != null && o.length) || !(e != null && e.length) || !(t != null && t.length))
|
|
46
46
|
return;
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
...
|
|
50
|
-
(
|
|
51
|
-
(
|
|
47
|
+
const m = B(s) ? { ...s } : s;
|
|
48
|
+
a.push(
|
|
49
|
+
...o.flatMap(
|
|
50
|
+
(h) => e.flatMap(
|
|
51
|
+
(y) => t.map((w) => p(h, y, w, m))
|
|
52
52
|
)
|
|
53
53
|
)
|
|
54
54
|
);
|
|
55
55
|
},
|
|
56
56
|
{ flush: "post" }
|
|
57
|
-
),
|
|
58
|
-
|
|
57
|
+
), d = () => {
|
|
58
|
+
u(), l();
|
|
59
59
|
};
|
|
60
|
-
return
|
|
60
|
+
return W(l), d;
|
|
61
61
|
}
|
|
62
|
-
const
|
|
62
|
+
const z = { class: "flex flex-col w-full h-full" }, q = ["src"], X = /* @__PURE__ */ O({
|
|
63
63
|
__name: "App",
|
|
64
64
|
props: {
|
|
65
65
|
iframeUrl: { default: () => "https://cdn2.colegium.com/production/unlayer/index.html" },
|
|
66
66
|
module: {}
|
|
67
67
|
},
|
|
68
68
|
emits: ["load", "ready", "onSuccess", "onError"],
|
|
69
|
-
setup(
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
return
|
|
73
|
-
}),
|
|
74
|
-
|
|
75
|
-
function
|
|
76
|
-
const
|
|
77
|
-
|
|
69
|
+
setup(n, { expose: a, emit: l }) {
|
|
70
|
+
const p = l, f = A(() => {
|
|
71
|
+
const c = new URL(n.iframeUrl, window.location.href);
|
|
72
|
+
return n.module && c.searchParams.set("module", n.module), c.searchParams.set("v", `${(/* @__PURE__ */ new Date()).getTime()}`), c.toString();
|
|
73
|
+
}), u = P(), d = P(), o = P(null);
|
|
74
|
+
V(window, "message", s);
|
|
75
|
+
function e() {
|
|
76
|
+
const c = new MessageChannel();
|
|
77
|
+
u.value = c;
|
|
78
78
|
}
|
|
79
|
-
function
|
|
80
|
-
const { port1:
|
|
81
|
-
|
|
79
|
+
function t() {
|
|
80
|
+
const { port1: c } = u.value;
|
|
81
|
+
d.value = c, d.value.onmessage = h;
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
"ready" in
|
|
83
|
+
function s({ data: c }) {
|
|
84
|
+
"ready" in c && p("ready");
|
|
85
85
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
86
|
+
function m() {
|
|
87
|
+
p("load"), t();
|
|
88
88
|
}
|
|
89
|
-
function
|
|
90
|
-
const { data:
|
|
91
|
-
if (
|
|
92
|
-
const { template:
|
|
93
|
-
|
|
89
|
+
function h(c) {
|
|
90
|
+
const { data: g } = c;
|
|
91
|
+
if (g.status == "success") {
|
|
92
|
+
const { template: i, originalTemplate: r, html: b } = g;
|
|
93
|
+
p("onSuccess", { template: i, originalTemplate: r, html: b });
|
|
94
94
|
} else {
|
|
95
|
-
const { message:
|
|
96
|
-
|
|
95
|
+
const { message: i } = g;
|
|
96
|
+
p("onError", { message: i });
|
|
97
97
|
}
|
|
98
|
-
|
|
98
|
+
e(), t();
|
|
99
99
|
}
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
}, w = (
|
|
103
|
-
|
|
100
|
+
const y = () => {
|
|
101
|
+
E("GET");
|
|
102
|
+
}, w = (c) => {
|
|
103
|
+
E("PUT", { template: I(c) }), e(), t();
|
|
104
104
|
};
|
|
105
|
-
function
|
|
106
|
-
var
|
|
107
|
-
(
|
|
105
|
+
function E(c, g = {}) {
|
|
106
|
+
var i, r;
|
|
107
|
+
(r = (i = o.value) == null ? void 0 : i.contentWindow) == null || r.postMessage({ type: c, ...g }, "*", [u.value.port2]);
|
|
108
108
|
}
|
|
109
|
-
return
|
|
110
|
-
|
|
109
|
+
return v(() => e()), a({ getTemplateDesign: y, setTemplateDesign: w }), (c, g) => (U(), R("div", z, [
|
|
110
|
+
_("iframe", {
|
|
111
111
|
class: "w-full h-full overflow-hidden",
|
|
112
112
|
style: { width: "100%", height: "100%" },
|
|
113
113
|
ref_key: "unlayerIframe",
|
|
114
|
-
ref:
|
|
114
|
+
ref: o,
|
|
115
115
|
frameborder: "0",
|
|
116
116
|
loading: "lazy",
|
|
117
117
|
"no-referrer": "",
|
|
118
118
|
title: "Colegium Unlayer Embed",
|
|
119
|
-
src:
|
|
120
|
-
onLoad:
|
|
121
|
-
}, null, 40,
|
|
119
|
+
src: L(f),
|
|
120
|
+
onLoad: m
|
|
121
|
+
}, null, 40, q)
|
|
122
122
|
]));
|
|
123
123
|
}
|
|
124
|
-
})
|
|
124
|
+
}), k = "clg-unlayer-bridge", H = (n) => !!n && typeof n == "object" && typeof n.__clgFnRef == "number", C = (n) => {
|
|
125
|
+
if (!n || typeof n != "object") return !1;
|
|
126
|
+
const a = Object.getPrototypeOf(n);
|
|
127
|
+
return a === Object.prototype || a === null;
|
|
128
|
+
};
|
|
129
|
+
function J(n) {
|
|
130
|
+
return !!n && typeof n == "object" && n.canal === k;
|
|
131
|
+
}
|
|
132
|
+
function K(n) {
|
|
133
|
+
let a = 1;
|
|
134
|
+
const l = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
|
|
135
|
+
function u(e) {
|
|
136
|
+
if (typeof e == "function") {
|
|
137
|
+
let t = l.get(e);
|
|
138
|
+
return t || (t = a++, l.set(e, t), p.set(t, e)), { __clgFnRef: t };
|
|
139
|
+
}
|
|
140
|
+
if (Array.isArray(e)) return e.map(u);
|
|
141
|
+
if (C(e)) {
|
|
142
|
+
const t = {};
|
|
143
|
+
for (const [s, m] of Object.entries(e)) t[s] = u(m);
|
|
144
|
+
return t;
|
|
145
|
+
}
|
|
146
|
+
return e;
|
|
147
|
+
}
|
|
148
|
+
function d(e) {
|
|
149
|
+
if (H(e)) {
|
|
150
|
+
const t = e.__clgFnRef;
|
|
151
|
+
let s = f.get(t);
|
|
152
|
+
return s || (s = (...m) => n(t, m.map(u)), f.set(t, s)), s;
|
|
153
|
+
}
|
|
154
|
+
if (Array.isArray(e)) return e.map(d);
|
|
155
|
+
if (C(e)) {
|
|
156
|
+
const t = {};
|
|
157
|
+
for (const [s, m] of Object.entries(e)) t[s] = d(m);
|
|
158
|
+
return t;
|
|
159
|
+
}
|
|
160
|
+
return e;
|
|
161
|
+
}
|
|
162
|
+
function o(e, t) {
|
|
163
|
+
const s = p.get(e);
|
|
164
|
+
s && s(...t.map(d));
|
|
165
|
+
}
|
|
166
|
+
return { codificar: u, decodificar: d, invocarLocal: o };
|
|
167
|
+
}
|
|
168
|
+
function Y(n, a = {}) {
|
|
169
|
+
const { iframeUrl: l = "https://cdn2.colegium.com/production/unlayer/index.html", relayPrefixes: p = [], onDenied: f } = a, u = new URL(l, window.location.href);
|
|
170
|
+
u.searchParams.set("module", "informes"), u.searchParams.set("v", `${Date.now()}`);
|
|
171
|
+
const d = u.origin, o = document.createElement("iframe");
|
|
172
|
+
o.src = u.toString(), o.title = "Colegium Unlayer Editor", o.setAttribute("frameborder", "0"), o.style.cssText = "width:100%;height:100%;border:0;display:block;", n.appendChild(o);
|
|
173
|
+
let e = !1, t = !1;
|
|
174
|
+
const s = [], m = K((i, r) => y({ canal: k, kind: "invoke", ref: i, args: r }));
|
|
175
|
+
function h(i) {
|
|
176
|
+
var r;
|
|
177
|
+
(r = o.contentWindow) == null || r.postMessage(i, d);
|
|
178
|
+
}
|
|
179
|
+
function y(i) {
|
|
180
|
+
t || (e ? h(i) : s.push(i));
|
|
181
|
+
}
|
|
182
|
+
function w(i) {
|
|
183
|
+
if (i.source !== o.contentWindow || i.origin !== d || !J(i.data)) return;
|
|
184
|
+
const r = i.data;
|
|
185
|
+
r.kind === "hello" ? (e = !0, h({ canal: k, kind: "setup", relayPrefixes: p }), s.splice(0).forEach(h)) : r.kind === "invoke" ? m.invocarLocal(r.ref, r.args ?? []) : r.kind === "denied" && (f ? f(r.message) : console.error("[unlayer-embed]", r.message));
|
|
186
|
+
}
|
|
187
|
+
window.addEventListener("message", w);
|
|
188
|
+
const E = (i) => (...r) => y({ canal: k, kind: "call", method: i, args: r.map(m.codificar) });
|
|
189
|
+
function c() {
|
|
190
|
+
t || (e && h({ canal: k, kind: "call", method: "destroy", args: [] }), t = !0, s.length = 0, window.removeEventListener("message", w), o.remove());
|
|
191
|
+
}
|
|
192
|
+
const g = /* @__PURE__ */ new Map([["destroy", c]]);
|
|
193
|
+
return new Proxy({}, {
|
|
194
|
+
get(i, r) {
|
|
195
|
+
if (typeof r != "string" || r === "then") return;
|
|
196
|
+
let b = g.get(r);
|
|
197
|
+
return b || (b = E(r), g.set(r, b)), b;
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
125
201
|
export {
|
|
126
|
-
|
|
202
|
+
X as ClgTemplateBuilder,
|
|
203
|
+
Y as mountUnlayerIframe
|
|
127
204
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(h,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],i):(h=typeof globalThis<"u"?globalThis:h||self,i(h["@colegium/vue3-unlayer-embed"]={},h.Vue))})(this,function(h,i){"use strict";function S(n){return i.getCurrentScope()?(i.onScopeDispose(n),!0):!1}const C=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const A=Object.prototype.toString,L=n=>A.call(n)==="[object Object]";function j(n){return Array.isArray(n)?n:[n]}function O(n,l,f){return i.watch(n,l,{...f,immediate:!0})}const x=C?window:void 0;function U(n){var l;const f=i.toValue(n);return(l=f==null?void 0:f.$el)!=null?l:f}function I(...n){const l=[],f=()=>{l.forEach(o=>o()),l.length=0},g=(o,e,t,s)=>(o.addEventListener(e,t,s),()=>o.removeEventListener(e,t,s)),d=i.computed(()=>{const o=j(i.toValue(n[0])).filter(e=>e!=null);return o.every(e=>typeof e!="string")?o:void 0}),u=O(()=>{var o,e;return[(e=(o=d.value)==null?void 0:o.map(t=>U(t)))!=null?e:[x].filter(t=>t!=null),j(i.toValue(d.value?n[1]:n[0])),j(i.unref(d.value?n[2]:n[1])),i.toValue(d.value?n[3]:n[2])]},([o,e,t,s])=>{if(f(),!(o!=null&&o.length)||!(e!=null&&e.length)||!(t!=null&&t.length))return;const p=L(s)?{...s}:s;l.push(...o.flatMap(b=>e.flatMap(w=>t.map(k=>g(b,w,k,p)))))},{flush:"post"}),m=()=>{u(),f()};return S(f),m}const R={class:"flex flex-col w-full h-full"},_=["src"],W=i.defineComponent({__name:"App",props:{iframeUrl:{default:()=>"https://cdn2.colegium.com/production/unlayer/index.html"},module:{}},emits:["load","ready","onSuccess","onError"],setup(n,{expose:l,emit:f}){const g=f,d=i.computed(()=>{const a=new URL(n.iframeUrl,window.location.href);return n.module&&a.searchParams.set("module",n.module),a.searchParams.set("v",`${new Date().getTime()}`),a.toString()}),u=i.ref(),m=i.ref(),o=i.ref(null);I(window,"message",s);function e(){const a=new MessageChannel;u.value=a}function t(){const{port1:a}=u.value;m.value=a,m.value.onmessage=b}function s({data:a}){"ready"in a&&g("ready")}function p(){g("load"),t()}function b(a){const{data:y}=a;if(y.status=="success"){const{template:c,originalTemplate:r,html:E}=y;g("onSuccess",{template:c,originalTemplate:r,html:E})}else{const{message:c}=y;g("onError",{message:c})}e(),t()}const w=()=>{P("GET")},k=a=>{P("PUT",{template:i.toRaw(a)}),e(),t()};function P(a,y={}){var c,r;(r=(c=o.value)==null?void 0:c.contentWindow)==null||r.postMessage({type:a,...y},"*",[u.value.port2])}return i.onMounted(()=>e()),l({getTemplateDesign:w,setTemplateDesign:k}),(a,y)=>(i.openBlock(),i.createElementBlock("div",R,[i.createElementVNode("iframe",{class:"w-full h-full overflow-hidden",style:{width:"100%",height:"100%"},ref_key:"unlayerIframe",ref:o,frameborder:"0",loading:"lazy","no-referrer":"",title:"Colegium Unlayer Embed",src:i.unref(d),onLoad:p},null,40,_)]))}}),M="clg-unlayer-bridge",D=n=>!!n&&typeof n=="object"&&typeof n.__clgFnRef=="number",T=n=>{if(!n||typeof n!="object")return!1;const l=Object.getPrototypeOf(n);return l===Object.prototype||l===null};function F(n){return!!n&&typeof n=="object"&&n.canal===M}function V(n){let l=1;const f=new WeakMap,g=new Map,d=new Map;function u(e){if(typeof e=="function"){let t=f.get(e);return t||(t=l++,f.set(e,t),g.set(t,e)),{__clgFnRef:t}}if(Array.isArray(e))return e.map(u);if(T(e)){const t={};for(const[s,p]of Object.entries(e))t[s]=u(p);return t}return e}function m(e){if(D(e)){const t=e.__clgFnRef;let s=d.get(t);return s||(s=(...p)=>n(t,p.map(u)),d.set(t,s)),s}if(Array.isArray(e))return e.map(m);if(T(e)){const t={};for(const[s,p]of Object.entries(e))t[s]=m(p);return t}return e}function o(e,t){const s=g.get(e);s&&s(...t.map(m))}return{codificar:u,decodificar:m,invocarLocal:o}}function B(n,l={}){const{iframeUrl:f="https://cdn2.colegium.com/production/unlayer/index.html",relayPrefixes:g=[],onDenied:d}=l,u=new URL(f,window.location.href);u.searchParams.set("module","informes"),u.searchParams.set("v",`${Date.now()}`);const m=u.origin,o=document.createElement("iframe");o.src=u.toString(),o.title="Colegium Unlayer Editor",o.setAttribute("frameborder","0"),o.style.cssText="width:100%;height:100%;border:0;display:block;",n.appendChild(o);let e=!1,t=!1;const s=[],p=V((c,r)=>w({canal:M,kind:"invoke",ref:c,args:r}));function b(c){var r;(r=o.contentWindow)==null||r.postMessage(c,m)}function w(c){t||(e?b(c):s.push(c))}function k(c){if(c.source!==o.contentWindow||c.origin!==m||!F(c.data))return;const r=c.data;r.kind==="hello"?(e=!0,b({canal:M,kind:"setup",relayPrefixes:g}),s.splice(0).forEach(b)):r.kind==="invoke"?p.invocarLocal(r.ref,r.args??[]):r.kind==="denied"&&(d?d(r.message):console.error("[unlayer-embed]",r.message))}window.addEventListener("message",k);const P=c=>(...r)=>w({canal:M,kind:"call",method:c,args:r.map(p.codificar)});function a(){t||(e&&b({canal:M,kind:"call",method:"destroy",args:[]}),t=!0,s.length=0,window.removeEventListener("message",k),o.remove())}const y=new Map([["destroy",a]]);return new Proxy({},{get(c,r){if(typeof r!="string"||r==="then")return;let E=y.get(r);return E||(E=P(r),y.set(r,E)),E}})}h.ClgTemplateBuilder=W,h.mountUnlayerIframe=B,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|