@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 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");
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 [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`;
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 e = await import(
25
+ const o = await import(
23
26
  /* webpackIgnore: true */
24
27
  d
25
28
  /* @vite-ignore */
26
- ), i = JSON.parse(this.getAttribute("data-component-props")), r = Object.fromEntries(
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
- e.default(
35
+ o.default(
33
36
  t.contentDocument,
34
- { ...r, data: i },
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
- e.default(t, { ...r, data: i }, ...this.children);
43
+ o.default(t, { ...p, data: m }, ...this.children);
41
44
  }
42
- } catch (e) {
43
- console.info("<custom-code-component> caught: ", e);
45
+ } catch (o) {
46
+ console.info("<custom-code-component> caught: ", o);
44
47
  }
45
48
  }
46
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/custom-code-component",
3
- "version": "0.0.9",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -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}/${componentName}${
40
+ : `https://www.ft.com/__component/${componentOrg}/${componentRepo}${
39
41
  componentVersionRange ? `@${componentVersionRange}` : "@latest"
40
- }/${componentName}.js`;
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
  }