@financial-times/custom-code-component 0.0.7 → 0.0.9
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class u extends HTMLElement {
|
|
2
2
|
constructor() {
|
|
3
3
|
super(...arguments), this.RESERVED_ATTRS = /* @__PURE__ */ new Set([
|
|
4
4
|
"iframe",
|
|
@@ -6,25 +6,24 @@ class h extends HTMLElement {
|
|
|
6
6
|
"version",
|
|
7
7
|
"data-component-props",
|
|
8
8
|
"data-asset-type",
|
|
9
|
-
"shadow-open"
|
|
9
|
+
"shadow-open",
|
|
10
|
+
"env"
|
|
10
11
|
]);
|
|
11
12
|
}
|
|
12
13
|
async connectedCallback() {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
var a;
|
|
15
|
+
const n = this.getAttribute("path"), s = this.hasAttribute("shadow-open") ? "open" : "closed", c = this.getAttribute("version"), m = (a = this.getAttribute("env")) == null ? void 0 : a.toLowerCase().startsWith("d");
|
|
16
|
+
if (!n)
|
|
15
17
|
throw new Error(
|
|
16
18
|
"path attribute not specified in <custom-code-component>"
|
|
17
19
|
);
|
|
18
|
-
const [
|
|
19
|
-
// @TODO create component service -- this URL may change!!!
|
|
20
|
-
`https://www.ft.com/__component/${i}/${a}/${c}${s ? `@${s}` : "@latest"}`
|
|
21
|
-
);
|
|
20
|
+
const [o, p, h] = n.split("/").reverse(), d = m ? `http://localhost:5173/src/${o}/index.jsx` : `https://www.ft.com/__component/${h}/${p}/${o}${c ? `@${c}` : "@latest"}/${o}.js`;
|
|
22
21
|
try {
|
|
23
22
|
const e = await import(
|
|
24
23
|
/* webpackIgnore: true */
|
|
25
|
-
|
|
24
|
+
d
|
|
26
25
|
/* @vite-ignore */
|
|
27
|
-
),
|
|
26
|
+
), i = JSON.parse(this.getAttribute("data-component-props")), r = Object.fromEntries(
|
|
28
27
|
[...this.attributes].filter((t) => !this.RESERVED_ATTRS.has(t.name)).map((t) => [t.name, t.value])
|
|
29
28
|
);
|
|
30
29
|
if (this.hasAttribute("iframe")) {
|
|
@@ -32,21 +31,21 @@ class h extends HTMLElement {
|
|
|
32
31
|
t.addEventListener("load", () => {
|
|
33
32
|
e.default(
|
|
34
33
|
t.contentDocument,
|
|
35
|
-
{ ...r, data:
|
|
34
|
+
{ ...r, data: i },
|
|
36
35
|
...this.children
|
|
37
36
|
);
|
|
38
|
-
}), this.attachShadow({ mode:
|
|
37
|
+
}), this.attachShadow({ mode: s }).append(t);
|
|
39
38
|
} else {
|
|
40
|
-
const t = this.attachShadow({ mode:
|
|
41
|
-
e.default(t, { ...r, data:
|
|
39
|
+
const t = this.attachShadow({ mode: s });
|
|
40
|
+
e.default(t, { ...r, data: i }, ...this.children);
|
|
42
41
|
}
|
|
43
42
|
} catch (e) {
|
|
44
43
|
console.info("<custom-code-component> caught: ", e);
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
|
-
const
|
|
49
|
-
customElements && !customElements.get("custom-code-component") &&
|
|
47
|
+
const l = () => customElements.define("custom-code-component", u);
|
|
48
|
+
customElements && !customElements.get("custom-code-component") && l();
|
|
50
49
|
export {
|
|
51
|
-
|
|
50
|
+
l as init
|
|
52
51
|
};
|
package/package.json
CHANGED
|
@@ -13,12 +13,16 @@ class FTCustomCodeComponent extends HTMLElement {
|
|
|
13
13
|
"data-component-props",
|
|
14
14
|
"data-asset-type",
|
|
15
15
|
"shadow-open",
|
|
16
|
+
"env",
|
|
16
17
|
]);
|
|
17
18
|
|
|
18
19
|
async connectedCallback() {
|
|
19
20
|
const path = this.getAttribute("path");
|
|
20
21
|
const mode = this.hasAttribute("shadow-open") ? "open" : "closed";
|
|
21
22
|
const componentVersionRange = this.getAttribute("version");
|
|
23
|
+
const useLocalVersion = this.getAttribute("env")
|
|
24
|
+
?.toLowerCase()
|
|
25
|
+
.startsWith("d");
|
|
22
26
|
|
|
23
27
|
if (!path)
|
|
24
28
|
throw new Error(
|
|
@@ -29,13 +33,11 @@ class FTCustomCodeComponent extends HTMLElement {
|
|
|
29
33
|
.split("/")
|
|
30
34
|
.reverse();
|
|
31
35
|
|
|
32
|
-
const source =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
componentVersionRange ? `@${componentVersionRange}` : "@latest"
|
|
38
|
-
}`;
|
|
36
|
+
const source = useLocalVersion
|
|
37
|
+
? `http://localhost:5173/src/${componentName}/index.jsx`
|
|
38
|
+
: `https://www.ft.com/__component/${componentOrg}/${componentRepo}/${componentName}${
|
|
39
|
+
componentVersionRange ? `@${componentVersionRange}` : "@latest"
|
|
40
|
+
}/${componentName}.js`;
|
|
39
41
|
try {
|
|
40
42
|
const App = await import(
|
|
41
43
|
/* webpackIgnore: true */ source /* @vite-ignore */
|