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