@financial-times/custom-code-component 1.1.1 → 1.1.2

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