@financial-times/custom-code-component 1.0.7 → 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.
|
@@ -8,11 +8,12 @@ class l extends HTMLElement {
|
|
|
8
8
|
"data-asset-type",
|
|
9
9
|
"shadow-open",
|
|
10
10
|
"env"
|
|
11
|
-
])
|
|
11
|
+
]), this.unmount = () => {
|
|
12
|
+
};
|
|
12
13
|
}
|
|
13
14
|
async connectedCallback() {
|
|
14
15
|
var m;
|
|
15
|
-
const e = this.getAttribute("path"), c = this.hasAttribute("shadow-open") ? "open" : "closed", a = this.getAttribute("version"),
|
|
16
|
+
const e = this.getAttribute("path"), c = this.hasAttribute("shadow-open") ? "open" : "closed", a = this.getAttribute("version"), p = (m = this.getAttribute("env")) == null ? void 0 : m.toLowerCase().startsWith("d");
|
|
16
17
|
if (!e)
|
|
17
18
|
throw new Error(
|
|
18
19
|
"path attribute not specified in <custom-code-component>"
|
|
@@ -20,13 +21,13 @@ class l extends HTMLElement {
|
|
|
20
21
|
const [n, i, r] = e.split("/").reverse();
|
|
21
22
|
if (!n || !i || !r)
|
|
22
23
|
return;
|
|
23
|
-
const
|
|
24
|
+
const d = p ? `http://localhost:5173/src/${n}/index.jsx` : `https://www.ft.com/__component/${r}/${i}${a ? `@${a}` : "@latest"}/${n}/${n}.js`;
|
|
24
25
|
try {
|
|
25
26
|
const s = await import(
|
|
26
27
|
/* webpackIgnore: true */
|
|
27
|
-
|
|
28
|
+
d
|
|
28
29
|
/* @vite-ignore */
|
|
29
|
-
),
|
|
30
|
+
), h = JSON.parse(this.getAttribute("data-component-props")), u = Object.fromEntries(
|
|
30
31
|
[...this.attributes].filter((t) => !this.RESERVED_ATTRS.has(t.name)).map((t) => [t.name, t.value])
|
|
31
32
|
);
|
|
32
33
|
if (this.hasAttribute("iframe")) {
|
|
@@ -34,18 +35,18 @@ class l extends HTMLElement {
|
|
|
34
35
|
t.addEventListener("load", () => {
|
|
35
36
|
const o = s.default(
|
|
36
37
|
t.contentDocument,
|
|
37
|
-
{ ...
|
|
38
|
+
{ ...u, data: h },
|
|
38
39
|
...this.children
|
|
39
40
|
);
|
|
40
|
-
o && (this.
|
|
41
|
+
o && (this.unmount = o);
|
|
41
42
|
}), this.attachShadow({ mode: c }).append(t);
|
|
42
43
|
} else {
|
|
43
44
|
const t = this.attachShadow({ mode: c }), o = await s.default(
|
|
44
45
|
t,
|
|
45
|
-
{ ...
|
|
46
|
+
{ ...u, data: h },
|
|
46
47
|
...this.children
|
|
47
48
|
);
|
|
48
|
-
o && (this.
|
|
49
|
+
o && (this.unmount = o);
|
|
49
50
|
}
|
|
50
51
|
} catch (s) {
|
|
51
52
|
console.info(`<custom-code-component> uncaught error from ${e}: `, s);
|
|
@@ -53,7 +54,7 @@ class l extends HTMLElement {
|
|
|
53
54
|
}
|
|
54
55
|
async disconnectedCallback() {
|
|
55
56
|
const e = this.getAttribute("path");
|
|
56
|
-
console.info(`<custom-code-component:${e}> disconnected`);
|
|
57
|
+
console.info(`<custom-code-component:${e}> disconnected`), this.unmount();
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
const f = () => customElements.define("custom-code-component", l);
|
package/package.json
CHANGED
|
@@ -16,6 +16,8 @@ class FTCustomCodeComponent extends HTMLElement {
|
|
|
16
16
|
"env",
|
|
17
17
|
]);
|
|
18
18
|
|
|
19
|
+
unmount = () => {};
|
|
20
|
+
|
|
19
21
|
async connectedCallback() {
|
|
20
22
|
const path = this.getAttribute("path");
|
|
21
23
|
const mode = this.hasAttribute("shadow-open") ? "open" : "closed";
|
|
@@ -64,7 +66,7 @@ class FTCustomCodeComponent extends HTMLElement {
|
|
|
64
66
|
...this.children
|
|
65
67
|
);
|
|
66
68
|
|
|
67
|
-
if (unmount) this.
|
|
69
|
+
if (unmount) this.unmount = unmount;
|
|
68
70
|
});
|
|
69
71
|
|
|
70
72
|
this.attachShadow({ mode }).append(mountPoint);
|
|
@@ -77,7 +79,7 @@ class FTCustomCodeComponent extends HTMLElement {
|
|
|
77
79
|
...this.children
|
|
78
80
|
);
|
|
79
81
|
|
|
80
|
-
if (unmount) this.
|
|
82
|
+
if (unmount) this.unmount = unmount;
|
|
81
83
|
}
|
|
82
84
|
} catch (e) {
|
|
83
85
|
console.info(`<custom-code-component> uncaught error from ${path}: `, e);
|
|
@@ -87,6 +89,7 @@ class FTCustomCodeComponent extends HTMLElement {
|
|
|
87
89
|
async disconnectedCallback() {
|
|
88
90
|
const path = this.getAttribute("path");
|
|
89
91
|
console.info(`<custom-code-component:${path}> disconnected`);
|
|
92
|
+
this.unmount();
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
|