@financial-times/custom-code-component 1.8.7 → 1.9.1

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 d extends HTMLElement {
2
2
  constructor() {
3
3
  super(...arguments), this.RESERVED_ATTRS = /* @__PURE__ */ new Set([
4
4
  "iframe",
@@ -12,57 +12,62 @@ class l extends HTMLElement {
12
12
  ]), this.unmount = (t) => {
13
13
  }, this.channel = new MessageChannel();
14
14
  }
15
- static get observedAttributes() {
16
- return ["path", "version", "env", "data-component-props"];
17
- }
18
15
  async mount() {
19
16
  var c;
20
17
  if (!this.app)
21
18
  throw new Error("CCC mounted without App");
22
- const t = this.shadowRoot ?? this.attachShadow({ mode: this.mode }), o = this.app, u = JSON.parse(this.getAttribute("data-component-props")), m = Object.fromEntries(
23
- [...this.attributes].filter((r) => !this.RESERVED_ATTRS.has(r.name)).map((r) => [r.name, r.value])
19
+ const t = this.shadowRoot ?? this.attachShadow({ mode: this.mode }), e = this.app, h = JSON.parse(this.getAttribute("data-component-props")), u = Object.fromEntries(
20
+ [...this.attributes].filter((s) => !this.RESERVED_ATTRS.has(s.name)).map((s) => [s.name, s.value])
24
21
  );
25
22
  (c = this.shadowRoot) == null || c.replaceChildren();
26
- const { unmount: s, onmessage: n } = o(
23
+ const { unmount: o, onmessage: r } = e(
27
24
  t,
28
- { ...m, data: u, port: this.channel.port2 },
25
+ { ...u, data: h, port: this.channel.port2 },
29
26
  ...this.children
30
27
  ) || {};
31
- s && (this.unmount = s), n && (this.onmessage = n);
28
+ o && (this.unmount = o), r && (this.onmessage = r);
32
29
  }
33
30
  async connectedCallback() {
34
- var r;
35
- const t = this.getAttribute("path"), o = this.getAttribute("version"), u = this.getAttribute("load-timeout") ?? 2e3, m = (r = this.getAttribute("env")) == null ? void 0 : r.toLowerCase().startsWith("d");
31
+ var s;
32
+ const t = this.getAttribute("path"), e = this.getAttribute("version"), h = this.getAttribute("load-timeout") ?? 2e3, u = (s = this.getAttribute("env")) == null ? void 0 : s.toLowerCase().startsWith("d");
36
33
  if (!t)
37
34
  throw new Error(
38
35
  "path attribute not specified in <custom-code-component>"
39
36
  );
40
- const [s, n, c] = t.split("/").reverse();
41
- if (!(!s || !n || !c)) {
42
- this.source = m ? `http://localhost:5173/src/${s}/index.jsx` : `https://www.ft.com/__component/${c}/${n}${o ? `@${o}` : "@latest"}/${s}/${s}.js`;
37
+ const [o, r, c] = t.split("/").reverse();
38
+ if (!(!o || !r || !c)) {
39
+ this.source = u ? `http://localhost:5173/src/${o}/index.jsx` : `https://www.ft.com/__component/${c}/${r}${e ? `@${e}` : "@latest"}/${o}/${o}.js`;
43
40
  try {
44
- this.app = await new Promise((e, p) => {
45
- const d = setTimeout(
46
- () => p(new i("CCC import timeout")),
47
- Number(u)
48
- );
41
+ this.app = await new Promise((n, m) => {
42
+ const p = setTimeout(() => {
43
+ this.dispatchEvent(
44
+ new CustomEvent("ccc-timeout", {
45
+ bubbles: !0,
46
+ cancelable: !0,
47
+ detail: {
48
+ component: `${t}@${e}`,
49
+ source: this.source
50
+ }
51
+ })
52
+ ), this.dataset.cccError = "import-timeout", delete this.dataset.cccReady;
53
+ }, Number(h));
49
54
  import(
50
55
  /* webpackIgnore: true */
51
56
  this.source
52
57
  /* @vite-ignore */
53
58
  ).then(({ default: a }) => {
54
59
  if (a)
55
- clearTimeout(d), e(a);
60
+ clearTimeout(p), n(a);
56
61
  else
57
- throw new h(
62
+ throw new i(
58
63
  "No component renderer default export found"
59
64
  );
60
- }).catch((a) => p(new h(a)));
65
+ }).catch((a) => m(new i(a)));
61
66
  });
62
- } catch (e) {
67
+ } catch (n) {
63
68
  console.error(
64
- `<custom-code-component> error during import from ${t}@${o}`
65
- ), delete this.dataset.cccReady, e instanceof i ? this.dataset.cccError = "import-timeout" : this.dataset.cccError = "import-failure", this.dispatchEvent(new ErrorEvent("error", e)), console.error(e);
69
+ `<custom-code-component> error during import from ${t}@${e}`
70
+ ), delete this.dataset.cccReady, this.dataset.cccError = "import-failure", this.dispatchEvent(new ErrorEvent("error", n)), console.error(n);
66
71
  return;
67
72
  }
68
73
  try {
@@ -71,21 +76,18 @@ class l extends HTMLElement {
71
76
  bubbles: !0,
72
77
  cancelable: !0,
73
78
  detail: {
74
- component: `${t}@${o}`,
79
+ component: `${t}@${e}`,
75
80
  source: this.source
76
81
  }
77
82
  })
78
83
  ), this.dataset.cccReady = "true", delete this.dataset.cccError;
79
- } catch (e) {
84
+ } catch (n) {
80
85
  console.info(
81
- `<custom-code-component> uncaught error during mount from ${t}@${o}`
82
- ), console.error(e), this.dispatchEvent(new ErrorEvent("error", e)), this.dataset.cccError = "mount-error", delete this.dataset.cccReady;
86
+ `<custom-code-component> uncaught error during mount from ${t}@${e}`
87
+ ), console.error(n), this.dispatchEvent(new ErrorEvent("error", n)), this.dataset.cccError = "mount-error", delete this.dataset.cccReady;
83
88
  }
84
89
  }
85
90
  }
86
- attributeChangedCallback() {
87
- this.mount();
88
- }
89
91
  disconnectedCallback() {
90
92
  const t = this.getAttribute("path");
91
93
  console.info(`<custom-code-component:${t}> disconnected`), typeof this.unmount == "function" && this.unmount();
@@ -97,18 +99,13 @@ class l extends HTMLElement {
97
99
  this.channel.port1.postMessage(t);
98
100
  }
99
101
  }
100
- const E = () => customElements.define("custom-code-component", l);
101
- customElements && !customElements.get("custom-code-component") && E();
102
+ const l = () => customElements.define("custom-code-component", d);
103
+ customElements && !customElements.get("custom-code-component") && l();
102
104
  class i extends Error {
103
105
  constructor(...t) {
104
- super(...t), Error.captureStackTrace && Error.captureStackTrace(this, i), this.name = "CCCImportTimeoutError";
105
- }
106
- }
107
- class h extends Error {
108
- constructor(...t) {
109
- super(...t), Error.captureStackTrace && Error.captureStackTrace(this, h), this.name = "CCCImportError";
106
+ super(...t), Error.captureStackTrace && Error.captureStackTrace(this, i), this.name = "CCCImportError";
110
107
  }
111
108
  }
112
109
  export {
113
- E as init
110
+ l as init
114
111
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/custom-code-component",
3
- "version": "1.8.7",
3
+ "version": "1.9.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -21,10 +21,6 @@ class FTCustomCodeComponent extends HTMLElement {
21
21
  "load-timeout",
22
22
  ]);
23
23
 
24
- static get observedAttributes() {
25
- return ["path", "version", "env", "data-component-props"];
26
- }
27
-
28
24
  source: string;
29
25
 
30
26
  async mount() {
@@ -87,10 +83,20 @@ class FTCustomCodeComponent extends HTMLElement {
87
83
 
88
84
  try {
89
85
  this.app = await new Promise((resolve, reject) => {
90
- const to = setTimeout(
91
- () => reject(new CCCTimeoutError("CCC import timeout")),
92
- Number(timeout)
93
- );
86
+ const to = setTimeout(() => {
87
+ this.dispatchEvent(
88
+ new CustomEvent("ccc-timeout", {
89
+ bubbles: true,
90
+ cancelable: true,
91
+ detail: {
92
+ component: `${path}@${componentVersionRange}`,
93
+ source: this.source,
94
+ },
95
+ })
96
+ );
97
+ this.dataset.cccError = "import-timeout";
98
+ delete this.dataset.cccReady;
99
+ }, Number(timeout));
94
100
  import(/* webpackIgnore: true */ this.source /* @vite-ignore */)
95
101
  .then(({ default: componentRenderFunction }) => {
96
102
  if (componentRenderFunction) {
@@ -109,12 +115,7 @@ class FTCustomCodeComponent extends HTMLElement {
109
115
  );
110
116
 
111
117
  delete this.dataset.cccReady;
112
-
113
- if (e instanceof CCCTimeoutError) {
114
- this.dataset.cccError = "import-timeout";
115
- } else {
116
- this.dataset.cccError = "import-failure";
117
- }
118
+ this.dataset.cccError = "import-failure";
118
119
 
119
120
  this.dispatchEvent(new ErrorEvent("error", e));
120
121
  console.error(e);
@@ -154,10 +155,6 @@ class FTCustomCodeComponent extends HTMLElement {
154
155
  }
155
156
  }
156
157
 
157
- attributeChangedCallback() {
158
- this.mount();
159
- }
160
-
161
158
  disconnectedCallback() {
162
159
  const path = this.getAttribute("path");
163
160
  console.info(`<custom-code-component:${path}> disconnected`);
@@ -195,20 +192,6 @@ export interface CustomCodeComponent extends ContentTree.Node {
195
192
  } | { children?: CustomCodeComponent | Array<CustomCodeComponent> };
196
193
  }
197
194
 
198
- class CCCTimeoutError extends Error {
199
- constructor(...params) {
200
- // Pass remaining arguments (including vendor specific ones) to parent constructor
201
- super(...params);
202
-
203
- // Maintains proper stack trace for where our error was thrown (only available on V8)
204
- if (Error.captureStackTrace) {
205
- Error.captureStackTrace(this, CCCTimeoutError);
206
- }
207
-
208
- this.name = "CCCImportTimeoutError";
209
- }
210
- }
211
-
212
195
  class CCCImportError extends Error {
213
196
  constructor(...params) {
214
197
  // Pass remaining arguments (including vendor specific ones) to parent constructor