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