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

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 l extends HTMLElement {
1
+ class f extends HTMLElement {
2
2
  constructor() {
3
3
  super(...arguments), this.RESERVED_ATTRS = /* @__PURE__ */ new Set([
4
4
  "iframe",
@@ -15,8 +15,8 @@ class l extends HTMLElement {
15
15
  return ["path", "version", "env", "data-component-props"];
16
16
  }
17
17
  async mount() {
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");
18
+ var a, r, m;
19
+ const e = this.getAttribute("path"), s = this.getAttribute("version"), d = (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>"
@@ -24,29 +24,29 @@ class l extends HTMLElement {
24
24
  const [o, c, i] = e.split("/").reverse();
25
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}/${c}${s ? `@${s}` : "@latest"}/${o}/${o}.js`;
27
+ const l = d ? `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
- d
31
+ l
32
32
  /* @vite-ignore */
33
- ), m = JSON.parse(this.getAttribute("data-component-props")), u = Object.fromEntries(
33
+ ), h = 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
- if (this.hasAttribute("iframe")) {
36
+ if ((r = this.shadowRoot) == null || r.replaceChildren(), this.hasAttribute("iframe")) {
37
37
  const t = document.createElement("iframe");
38
38
  t.addEventListener("load", () => {
39
- const h = n.default(
39
+ const p = n.default(
40
40
  t.contentDocument,
41
- { ...u, data: m },
41
+ { ...u, data: h },
42
42
  ...this.children
43
43
  );
44
- h && (this.unmount = h);
45
- }), (r = this.shadowRoot) == null || r.append(t);
44
+ p && (this.unmount = p);
45
+ }), (m = this.shadowRoot) == null || m.append(t);
46
46
  } else
47
47
  this.unmount = await n.default(
48
48
  this.shadowRoot,
49
- { ...u, data: m },
49
+ { ...u, data: h },
50
50
  ...this.children
51
51
  );
52
52
  } catch (n) {
@@ -65,8 +65,8 @@ class l extends HTMLElement {
65
65
  console.info(`<custom-code-component:${e}> disconnected`), typeof this.unmount == "function" && this.unmount();
66
66
  }
67
67
  }
68
- const f = () => customElements.define("custom-code-component", l);
69
- customElements && !customElements.get("custom-code-component") && f();
68
+ const b = () => customElements.define("custom-code-component", f);
69
+ customElements && !customElements.get("custom-code-component") && b();
70
70
  export {
71
- f as init
71
+ b as init
72
72
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/custom-code-component",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -59,6 +59,9 @@ class FTCustomCodeComponent extends HTMLElement {
59
59
  .map((attribute) => [attribute.name, attribute.value])
60
60
  );
61
61
 
62
+ // Clear old children
63
+ this.shadowRoot?.replaceChildren();
64
+
62
65
  if (this.hasAttribute("iframe")) {
63
66
  const mountPoint = document.createElement("iframe");
64
67