@financial-times/custom-code-component 0.0.9 → 1.0.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.
|
@@ -11,5 +11,6 @@ export interface CustomCodeComponent extends ContentTree.Node {
|
|
|
11
11
|
altText: string;
|
|
12
12
|
timestamp?: string;
|
|
13
13
|
fallbackImage?: ContentTree.Image;
|
|
14
|
-
attributes?: [string, string]
|
|
14
|
+
attributes?: Array<[string, string]>;
|
|
15
|
+
children?: Array<ContentTree.Node | CustomCodeComponent>;
|
|
15
16
|
}
|
|
@@ -11,36 +11,39 @@ class u extends HTMLElement {
|
|
|
11
11
|
]);
|
|
12
12
|
}
|
|
13
13
|
async connectedCallback() {
|
|
14
|
-
var
|
|
15
|
-
const n = this.getAttribute("path"), s = this.hasAttribute("shadow-open") ? "open" : "closed", c = this.getAttribute("version"),
|
|
14
|
+
var r;
|
|
15
|
+
const n = this.getAttribute("path"), s = this.hasAttribute("shadow-open") ? "open" : "closed", c = this.getAttribute("version"), h = (r = this.getAttribute("env")) == null ? void 0 : r.toLowerCase().startsWith("d");
|
|
16
16
|
if (!n)
|
|
17
17
|
throw new Error(
|
|
18
18
|
"path attribute not specified in <custom-code-component>"
|
|
19
19
|
);
|
|
20
|
-
const [
|
|
20
|
+
const [e, a, i] = n.split("/").reverse();
|
|
21
|
+
if (!e || !a || !i)
|
|
22
|
+
return;
|
|
23
|
+
const d = h ? `http://localhost:5173/src/${e}/index.jsx` : `https://www.ft.com/__component/${i}/${a}${c ? `@${c}` : "@latest"}/${e}/${e}`;
|
|
21
24
|
try {
|
|
22
|
-
const
|
|
25
|
+
const o = await import(
|
|
23
26
|
/* webpackIgnore: true */
|
|
24
27
|
d
|
|
25
28
|
/* @vite-ignore */
|
|
26
|
-
),
|
|
29
|
+
), m = JSON.parse(this.getAttribute("data-component-props")), p = Object.fromEntries(
|
|
27
30
|
[...this.attributes].filter((t) => !this.RESERVED_ATTRS.has(t.name)).map((t) => [t.name, t.value])
|
|
28
31
|
);
|
|
29
32
|
if (this.hasAttribute("iframe")) {
|
|
30
33
|
const t = document.createElement("iframe");
|
|
31
34
|
t.addEventListener("load", () => {
|
|
32
|
-
|
|
35
|
+
o.default(
|
|
33
36
|
t.contentDocument,
|
|
34
|
-
{ ...
|
|
37
|
+
{ ...p, data: m },
|
|
35
38
|
...this.children
|
|
36
39
|
);
|
|
37
40
|
}), this.attachShadow({ mode: s }).append(t);
|
|
38
41
|
} else {
|
|
39
42
|
const t = this.attachShadow({ mode: s });
|
|
40
|
-
|
|
43
|
+
o.default(t, { ...p, data: m }, ...this.children);
|
|
41
44
|
}
|
|
42
|
-
} catch (
|
|
43
|
-
console.info("<custom-code-component> caught: ",
|
|
45
|
+
} catch (o) {
|
|
46
|
+
console.info("<custom-code-component> caught: ", o);
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
}
|
package/package.json
CHANGED
|
@@ -33,11 +33,14 @@ class FTCustomCodeComponent extends HTMLElement {
|
|
|
33
33
|
.split("/")
|
|
34
34
|
.reverse();
|
|
35
35
|
|
|
36
|
+
if (!componentName || !componentRepo || !componentOrg) return;
|
|
37
|
+
|
|
36
38
|
const source = useLocalVersion
|
|
37
39
|
? `http://localhost:5173/src/${componentName}/index.jsx`
|
|
38
|
-
: `https://www.ft.com/__component/${componentOrg}/${componentRepo}
|
|
40
|
+
: `https://www.ft.com/__component/${componentOrg}/${componentRepo}${
|
|
39
41
|
componentVersionRange ? `@${componentVersionRange}` : "@latest"
|
|
40
|
-
}/${componentName}
|
|
42
|
+
}/${componentName}/${componentName}`;
|
|
43
|
+
|
|
41
44
|
try {
|
|
42
45
|
const App = await import(
|
|
43
46
|
/* webpackIgnore: true */ source /* @vite-ignore */
|
|
@@ -86,5 +89,6 @@ export interface CustomCodeComponent extends ContentTree.Node {
|
|
|
86
89
|
altText: string;
|
|
87
90
|
timestamp?: string;
|
|
88
91
|
fallbackImage?: ContentTree.Image;
|
|
89
|
-
attributes?: [string, string]
|
|
92
|
+
attributes?: Array<[string, string]>;
|
|
93
|
+
children?: Array<ContentTree.Node | CustomCodeComponent>;
|
|
90
94
|
}
|