@financial-times/custom-code-component 2.0.1-alpha.9 → 2.0.1-beta.10
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/CustomCodeComponent.js +7 -0
- package/dist/CustomCodeComponent.js.map +1 -0
- package/dist/custom-element.d.ts +114 -0
- package/dist/{index.js → custom-element.js} +211 -200
- package/dist/custom-element.js.map +1 -0
- package/dist/{webcomponent/src/index.d.ts → index.d.ts} +3 -1
- package/package.json +11 -6
- package/src/custom-code-component.css +11 -0
- package/src/custom-code-component.ts +133 -89
- package/src/environment.ts +31 -40
- package/src/errors.ts +8 -4
- package/src/events.ts +1 -1
- package/src/path.ts +20 -23
- package/dist/index.js.map +0 -1
- package/dist/webcomponent/src/custom-code-component.d.ts +0 -55
- package/dist/webcomponent/src/environment.d.ts +0 -15
- package/dist/webcomponent/src/errors.d.ts +0 -27
- package/dist/webcomponent/src/events.d.ts +0 -10
- package/dist/webcomponent/src/get-trace.d.ts +0 -8
- package/dist/webcomponent/src/logger.d.ts +0 -20
- package/dist/webcomponent/src/path.d.ts +0 -23
- package/dist/webcomponent/src/tracking.d.ts +0 -32
- package/dist/webcomponent/src/util.d.ts +0 -33
- package/dist/webcomponent/test/environment.test.d.ts +0 -1
- package/dist/webcomponent/test/error-handling.test.d.ts +0 -8
- package/dist/webcomponent/test/example.d.ts +0 -11
- package/dist/webcomponent/test/generate-readable-stream.d.ts +0 -8
- package/dist/webcomponent/test/path.test.d.ts +0 -5
- package/dist/webcomponent/test/ssr.test.d.ts +0 -4
- package/dist/webcomponent/test/utils.test.d.ts +0 -1
- package/dist/webcomponent/vite.config.d.ts +0 -2
- package/dist/webcomponent/vitest.config.d.ts +0 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function
|
|
2
|
-
this.listenerMap = [{}, {}], o && this.root(o), this.handle =
|
|
1
|
+
function l(o) {
|
|
2
|
+
this.listenerMap = [{}, {}], o && this.root(o), this.handle = l.prototype.handle.bind(this), this._removedListeners = [];
|
|
3
3
|
}
|
|
4
|
-
|
|
4
|
+
l.prototype.root = function(o) {
|
|
5
5
|
const t = this.listenerMap;
|
|
6
6
|
let e;
|
|
7
7
|
if (this.rootElement) {
|
|
@@ -19,24 +19,24 @@ p.prototype.root = function(o) {
|
|
|
19
19
|
t[0].hasOwnProperty(e) && this.rootElement.addEventListener(e, this.handle, !1);
|
|
20
20
|
return this;
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
l.prototype.captureForType = function(o) {
|
|
23
23
|
return ["blur", "error", "focus", "load", "resize", "scroll"].indexOf(o) !== -1;
|
|
24
24
|
};
|
|
25
|
-
|
|
26
|
-
let
|
|
25
|
+
l.prototype.on = function(o, t, e, n) {
|
|
26
|
+
let r, s, i, c;
|
|
27
27
|
if (!o)
|
|
28
28
|
throw new TypeError("Invalid event type: " + o);
|
|
29
29
|
if (typeof t == "function" && (n = e, e = t, t = null), n === void 0 && (n = this.captureForType(o)), typeof e != "function")
|
|
30
30
|
throw new TypeError("Handler must be a type of Function");
|
|
31
|
-
return
|
|
31
|
+
return r = this.rootElement, s = this.listenerMap[n ? 1 : 0], s[o] || (r && r.addEventListener(o, this.handle, n), s[o] = []), t ? /^[a-z]+$/i.test(t) ? (c = t, i = R) : /^#[a-z0-9\-_]+$/i.test(t) ? (c = t.slice(1), i = k) : (c = t, i = Element.prototype.matches) : (c = null, i = L.bind(this)), s[o].push({
|
|
32
32
|
selector: t,
|
|
33
33
|
handler: e,
|
|
34
34
|
matcher: i,
|
|
35
35
|
matcherParam: c
|
|
36
36
|
}), this;
|
|
37
37
|
};
|
|
38
|
-
|
|
39
|
-
let
|
|
38
|
+
l.prototype.off = function(o, t, e, n) {
|
|
39
|
+
let r, s, i, c, h;
|
|
40
40
|
if (typeof t == "function" && (n = e, e = t, t = null), n === void 0)
|
|
41
41
|
return this.off(o, t, e, !0), this.off(o, t, e, !1), this;
|
|
42
42
|
if (i = this.listenerMap[n ? 1 : 0], !o) {
|
|
@@ -46,18 +46,18 @@ p.prototype.off = function(o, t, e, n) {
|
|
|
46
46
|
}
|
|
47
47
|
if (c = i[o], !c || !c.length)
|
|
48
48
|
return this;
|
|
49
|
-
for (
|
|
50
|
-
|
|
49
|
+
for (r = c.length - 1; r >= 0; r--)
|
|
50
|
+
s = c[r], (!t || t === s.selector) && (!e || e === s.handler) && (this._removedListeners.push(s), c.splice(r, 1));
|
|
51
51
|
return c.length || (delete i[o], this.rootElement && this.rootElement.removeEventListener(o, this.handle, n)), this;
|
|
52
52
|
};
|
|
53
|
-
|
|
53
|
+
l.prototype.handle = function(o) {
|
|
54
54
|
let t, e;
|
|
55
55
|
const n = o.type;
|
|
56
|
-
let
|
|
57
|
-
const
|
|
58
|
-
if (o[
|
|
56
|
+
let r, s, i, c, h = [], a;
|
|
57
|
+
const m = "ftLabsDelegateIgnore";
|
|
58
|
+
if (o[m] === !0)
|
|
59
59
|
return;
|
|
60
|
-
switch (a = o.target, a.nodeType === 3 && (a = a.parentNode), a.correspondingUseElement && (a = a.correspondingUseElement),
|
|
60
|
+
switch (a = o.target, a.nodeType === 3 && (a = a.parentNode), a.correspondingUseElement && (a = a.correspondingUseElement), r = this.rootElement, s = o.eventPhase || (o.target !== o.currentTarget ? 3 : 2), s) {
|
|
61
61
|
case 1:
|
|
62
62
|
h = this.listenerMap[1][n];
|
|
63
63
|
break;
|
|
@@ -72,24 +72,24 @@ p.prototype.handle = function(o) {
|
|
|
72
72
|
for (e = h.length; a && e; ) {
|
|
73
73
|
for (t = 0; t < e && (i = h[t], !!i); t++)
|
|
74
74
|
a.tagName && ["button", "input", "select", "textarea"].indexOf(a.tagName.toLowerCase()) > -1 && a.hasAttribute("disabled") ? u = [] : i.matcher.call(a, i.matcherParam, a) && u.push([o, a, i]);
|
|
75
|
-
if (a ===
|
|
75
|
+
if (a === r || (e = h.length, a = a.parentElement || a.parentNode, a instanceof HTMLDocument))
|
|
76
76
|
break;
|
|
77
77
|
}
|
|
78
|
-
let
|
|
78
|
+
let v;
|
|
79
79
|
for (t = 0; t < u.length; t++)
|
|
80
80
|
if (!(this._removedListeners.indexOf(u[t][2]) > -1) && (c = this.fire.apply(this, u[t]), c === !1)) {
|
|
81
|
-
u[t][0][
|
|
81
|
+
u[t][0][m] = !0, u[t][0].preventDefault(), v = !1;
|
|
82
82
|
break;
|
|
83
83
|
}
|
|
84
|
-
return
|
|
84
|
+
return v;
|
|
85
85
|
};
|
|
86
|
-
|
|
86
|
+
l.prototype.fire = function(o, t, e) {
|
|
87
87
|
return e.handler.call(t, o, t);
|
|
88
88
|
};
|
|
89
|
-
function
|
|
89
|
+
function R(o, t) {
|
|
90
90
|
return o.toLowerCase() === t.tagName.toLowerCase();
|
|
91
91
|
}
|
|
92
|
-
function
|
|
92
|
+
function L(o, t) {
|
|
93
93
|
return this.rootElement === window ? (
|
|
94
94
|
// Match the outer document (dispatched from document)
|
|
95
95
|
t === document || // The <html> element (dispatched from document.body or document.documentElement)
|
|
@@ -97,20 +97,20 @@ function $(o, t) {
|
|
|
97
97
|
t === window
|
|
98
98
|
) : this.rootElement === t;
|
|
99
99
|
}
|
|
100
|
-
function
|
|
100
|
+
function k(o, t) {
|
|
101
101
|
return o === t.id;
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
l.prototype.destroy = function() {
|
|
104
104
|
this.off(), this.root();
|
|
105
105
|
};
|
|
106
|
-
function
|
|
106
|
+
function C(o) {
|
|
107
107
|
return typeof o == "string" ? o.trim() : o;
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function S(o, t) {
|
|
110
110
|
for (const e in o)
|
|
111
111
|
t[e] ? console.warn(`You can't set a custom property called ${e}`) : t[e] = o[e];
|
|
112
112
|
}
|
|
113
|
-
const
|
|
113
|
+
const p = Object.freeze({
|
|
114
114
|
DEBUG: 0,
|
|
115
115
|
INFO: 1,
|
|
116
116
|
WARN: 2,
|
|
@@ -118,37 +118,37 @@ const m = Object.freeze({
|
|
|
118
118
|
TEST: 4,
|
|
119
119
|
DEFAULT: 2
|
|
120
120
|
});
|
|
121
|
-
function
|
|
121
|
+
function $(o) {
|
|
122
122
|
const t = o == null ? void 0 : o.toLowerCase();
|
|
123
|
-
return t === "debug" ?
|
|
123
|
+
return t === "debug" ? p.DEBUG : t === "info" ? p.INFO : t === "warn" ? p.WARN : t === "error" ? p.ERROR : t === "test" ? p.TEST : p.DEFAULT;
|
|
124
124
|
}
|
|
125
|
-
class
|
|
126
|
-
constructor({ level: t =
|
|
127
|
-
level:
|
|
125
|
+
class T {
|
|
126
|
+
constructor({ level: t = p.DEFAULT } = {
|
|
127
|
+
level: p.DEFAULT
|
|
128
128
|
}) {
|
|
129
129
|
this.log = this.debug, this.level = t;
|
|
130
130
|
}
|
|
131
131
|
debug(...t) {
|
|
132
|
-
this.level <=
|
|
132
|
+
this.level <= p.DEBUG && console.info(...t);
|
|
133
133
|
}
|
|
134
134
|
info(...t) {
|
|
135
|
-
this.level <=
|
|
135
|
+
this.level <= p.INFO && console.info(...t);
|
|
136
136
|
}
|
|
137
137
|
warn(...t) {
|
|
138
|
-
this.level <=
|
|
138
|
+
this.level <= p.WARN && console.warn(...t);
|
|
139
139
|
}
|
|
140
140
|
error(...t) {
|
|
141
|
-
this.level <=
|
|
141
|
+
this.level <= p.ERROR && console.error(...t);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
const N = (o, t, e) => {
|
|
145
|
-
const n = Array.from((o == null ? void 0 : o.querySelectorAll(e)) ?? []),
|
|
146
|
-
if (
|
|
145
|
+
const n = Array.from((o == null ? void 0 : o.querySelectorAll(e)) ?? []), r = n.findIndex((s) => s === t);
|
|
146
|
+
if (r !== -1)
|
|
147
147
|
return {
|
|
148
148
|
siblings: n.length,
|
|
149
|
-
position:
|
|
149
|
+
position: r
|
|
150
150
|
};
|
|
151
|
-
},
|
|
151
|
+
}, A = [
|
|
152
152
|
"nodeName",
|
|
153
153
|
"className",
|
|
154
154
|
"id",
|
|
@@ -157,9 +157,9 @@ const N = (o, t, e) => {
|
|
|
157
157
|
"role"
|
|
158
158
|
], O = (o) => {
|
|
159
159
|
const t = {};
|
|
160
|
-
for (const e of
|
|
160
|
+
for (const e of A) {
|
|
161
161
|
const n = o[e] || o.getAttribute(e) || o.hasAttribute(e);
|
|
162
|
-
n !== void 0 && (typeof n == "boolean" ? t[e] = n : t[e] =
|
|
162
|
+
n !== void 0 && (typeof n == "boolean" ? t[e] = n : t[e] = C(n));
|
|
163
163
|
}
|
|
164
164
|
return t;
|
|
165
165
|
}, P = (o) => {
|
|
@@ -172,31 +172,31 @@ const N = (o, t, e) => {
|
|
|
172
172
|
}, x = (o) => {
|
|
173
173
|
const [t, e] = P(o);
|
|
174
174
|
return t ? e : o;
|
|
175
|
-
},
|
|
175
|
+
}, D = (o, t) => (o.filter(
|
|
176
176
|
(e) => e.name.match(/^data-trackable|^data-o-|^aria-/i)
|
|
177
177
|
).forEach((e) => {
|
|
178
178
|
t[e.name] = e.value;
|
|
179
|
-
}), t),
|
|
179
|
+
}), t), I = (o, t, e) => {
|
|
180
180
|
const n = {};
|
|
181
|
-
return e &&
|
|
182
|
-
typeof t[
|
|
183
|
-
}), o.filter((
|
|
184
|
-
n[
|
|
181
|
+
return e && A.forEach((r) => {
|
|
182
|
+
typeof t[r] < "u" && r !== "id" && (n[r] = t[r]);
|
|
183
|
+
}), o.filter((r) => r.name.match(/^data-trackable-context-/i)).forEach((r) => {
|
|
184
|
+
n[r.name.replace("data-trackable-context-", "")] = x(r.value);
|
|
185
185
|
}), n;
|
|
186
186
|
};
|
|
187
|
-
function
|
|
188
|
-
const e = o, n = e != null && e.getAttribute("data-trackable") ? `[data-trackable="${e.getAttribute("data-trackable")}"]` : e == null ? void 0 : e.nodeName,
|
|
187
|
+
function M(o, t) {
|
|
188
|
+
const e = o, n = e != null && e.getAttribute("data-trackable") ? `[data-trackable="${e.getAttribute("data-trackable")}"]` : e == null ? void 0 : e.nodeName, r = [], s = {};
|
|
189
189
|
for (; o && o !== t; ) {
|
|
190
190
|
const i = O(o), c = Array.from(o.attributes);
|
|
191
|
-
let h =
|
|
191
|
+
let h = D(c, i);
|
|
192
192
|
h["data-trackable"] && (h = Object.assign(
|
|
193
193
|
h,
|
|
194
194
|
N(o, e, n)
|
|
195
|
-
)),
|
|
196
|
-
const a =
|
|
197
|
-
|
|
195
|
+
)), r.push(h);
|
|
196
|
+
const a = I(c, i, o === e);
|
|
197
|
+
S(a, s), o = o.parentNode;
|
|
198
198
|
}
|
|
199
|
-
return { trace:
|
|
199
|
+
return { trace: r, customContext: s };
|
|
200
200
|
}
|
|
201
201
|
const U = ["ctrlKey", "altKey", "shiftKey", "metaKey"];
|
|
202
202
|
class F {
|
|
@@ -204,13 +204,13 @@ class F {
|
|
|
204
204
|
id: t = "00000000-0000-0000-0000-000000000000",
|
|
205
205
|
name: e = "ccc-component",
|
|
206
206
|
subtype: n = "interactive",
|
|
207
|
-
teamName:
|
|
208
|
-
shadowRoot:
|
|
207
|
+
teamName: r = "djd",
|
|
208
|
+
shadowRoot: s = null,
|
|
209
209
|
category: i = "cta",
|
|
210
210
|
elements: c = 'a, button, input, [role="button"]',
|
|
211
211
|
logger: h
|
|
212
212
|
}) {
|
|
213
|
-
this.cccId = t, this.cccName = e, this.subtype = n, this.teamName =
|
|
213
|
+
this.cccId = t, this.cccName = e, this.subtype = n, this.teamName = r, this.shadowRoot = s, this.category = i, this.elements = c, this.isInitialised = !1, this.log = h ?? new T();
|
|
214
214
|
}
|
|
215
215
|
// Get properties for the event (as opposed to properties of the clicked element)
|
|
216
216
|
getEventProperties(t) {
|
|
@@ -218,22 +218,22 @@ class F {
|
|
|
218
218
|
for (const n of U)
|
|
219
219
|
if (t[n])
|
|
220
220
|
try {
|
|
221
|
-
e[n] =
|
|
222
|
-
} catch (
|
|
223
|
-
this.log.info(
|
|
221
|
+
e[n] = C(t[n]);
|
|
222
|
+
} catch (r) {
|
|
223
|
+
this.log.info(r);
|
|
224
224
|
}
|
|
225
225
|
return e;
|
|
226
226
|
}
|
|
227
227
|
// Controller for handling click events
|
|
228
228
|
handleClickEvent(t, e) {
|
|
229
|
-
return (n,
|
|
230
|
-
const
|
|
231
|
-
|
|
229
|
+
return (n, r) => {
|
|
230
|
+
const s = this.getEventProperties(n), { trace: i, customContext: c } = M(r, e);
|
|
231
|
+
s.custom = r.dataset && r.dataset.custom ? JSON.parse(r.dataset.custom) : null, s.domPathTokens = i, s.component = {
|
|
232
232
|
id: this.cccId,
|
|
233
233
|
name: this.cccName,
|
|
234
234
|
type: "custom-code-component",
|
|
235
235
|
subtype: this.subtype
|
|
236
|
-
},
|
|
236
|
+
}, s.teamName = this.teamName, s.url = document.URL, S(c, s), s.method = "ftCustomAnalytics", t = { ...t, ...s }, document.body.dispatchEvent(
|
|
237
237
|
new CustomEvent("oTracking.event", {
|
|
238
238
|
detail: t,
|
|
239
239
|
bubbles: !0,
|
|
@@ -272,76 +272,73 @@ class F {
|
|
|
272
272
|
const n = {
|
|
273
273
|
action: "click",
|
|
274
274
|
category: this.category
|
|
275
|
-
},
|
|
276
|
-
|
|
275
|
+
}, r = (e = this.shadowRoot) == null ? void 0 : e.querySelector("[data-component-root]");
|
|
276
|
+
r && new l(r).on(
|
|
277
277
|
"click",
|
|
278
278
|
this.elements,
|
|
279
|
-
this.handleClickEvent(n,
|
|
279
|
+
this.handleClickEvent(n, r),
|
|
280
280
|
!0
|
|
281
281
|
);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
|
-
class
|
|
285
|
+
class f {
|
|
286
286
|
constructor(t) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
)
|
|
290
|
-
this.org = e, this.repo = n, this.component = s, this.versionRange = r;
|
|
287
|
+
this.org = "local", this.repo = "dev";
|
|
288
|
+
const { org: e, repo: n, name: r, versionRange: s } = E(t) ? t : f.fromString(t);
|
|
289
|
+
e && (this.org = e), n && (this.repo = n), this.name = r, this.versionRange = s;
|
|
291
290
|
}
|
|
292
291
|
set path(t) {
|
|
293
|
-
const { org: e, repo: n,
|
|
294
|
-
|
|
295
|
-
) ? t : l.fromString(t);
|
|
296
|
-
this.org = e, this.repo = n, this.component = s, this.versionRange = r;
|
|
292
|
+
const { org: e, repo: n, name: r, versionRange: s } = E(t) ? t : f.fromString(t);
|
|
293
|
+
this.org = e, this.repo = n, this.name = r, this.versionRange = s;
|
|
297
294
|
}
|
|
298
295
|
get path() {
|
|
299
|
-
return `${this.org}/${this.repo}@${this.versionRange}/${this.
|
|
296
|
+
return `${this.org}/${this.repo}@${this.versionRange}/${this.name}`;
|
|
300
297
|
}
|
|
301
298
|
toString() {
|
|
302
299
|
return this.path;
|
|
303
300
|
}
|
|
304
301
|
static fromString(t, e) {
|
|
305
302
|
var c;
|
|
306
|
-
if (!t)
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
throw new f("No version specified");
|
|
311
|
-
const [s, r, i] = t.replace(/@[^\/]+/, "").split("/").reverse();
|
|
312
|
-
return new l({ org: i, repo: r, component: s, versionRange: n });
|
|
303
|
+
if (!t) throw new d("No path specified");
|
|
304
|
+
const [n, r, s] = t.replace(/@[^\/]+/, "").split("/").reverse(), i = e ?? ((c = t.match(/@[^\/]+/)) == null ? void 0 : c.toString().replace("@", "")) ?? "unknown";
|
|
305
|
+
if (r && !i) throw new d("No version specified");
|
|
306
|
+
return new f({ org: s, repo: r, name: n, versionRange: i });
|
|
313
307
|
}
|
|
314
308
|
}
|
|
315
|
-
function
|
|
316
|
-
return typeof o == "object" && o !== null ? "org" in o && "repo" in o && "
|
|
309
|
+
function E(o) {
|
|
310
|
+
return typeof o == "object" && o !== null ? "org" in o && "repo" in o && "name" in o : !1;
|
|
317
311
|
}
|
|
318
|
-
class
|
|
312
|
+
class d extends Error {
|
|
319
313
|
constructor(t, e) {
|
|
320
|
-
var n
|
|
321
|
-
|
|
322
|
-
};
|
|
323
|
-
!e && t ? (n(t), this.component = null) : typeof (e == null ? void 0 : e.component) == "string" ? (n(
|
|
314
|
+
var n;
|
|
315
|
+
!e && t ? (super(t), this.component = null) : typeof (e == null ? void 0 : e.component) == "string" ? (super(
|
|
324
316
|
t ?? `${e.cause ?? "Unknown error"} in ${e.component} imported from ${e.source ?? "an undefined source"}.`
|
|
325
|
-
), this.component =
|
|
326
|
-
t ?? `${e.cause ?? "Unknown error"} in ${e.component.org}/${e.component.repo}/${e.component.
|
|
327
|
-
), this.component = new
|
|
317
|
+
), this.component = f.fromString(e.component)) : E(e == null ? void 0 : e.component) ? (super(
|
|
318
|
+
t ?? `${e.cause ?? "Unknown error"} in ${e.component.org}/${e.component.repo}/${e.component.name}@${e.component.versionRange} imported from ${e.source ?? "an undefined source"}.`
|
|
319
|
+
), this.component = new f(e.component)) : (super(
|
|
328
320
|
`${(e == null ? void 0 : e.cause) ?? "Unknown error"} in unknown component imported from ${(e == null ? void 0 : e.source) ?? "unknown source"}.`
|
|
329
|
-
), this.component = null), this.source = e == null ? void 0 : e.source, Error.captureStackTrace && Error.captureStackTrace(this,
|
|
321
|
+
), this.component = null), this.source = (e == null ? void 0 : e.source) ?? "unknown source", this.errors = [], e != null && e.error && ((n = this.errors) == null || n.push(e == null ? void 0 : e.error)), Error.captureStackTrace && Error.captureStackTrace(this, d), this.name = "CCCError";
|
|
330
322
|
}
|
|
331
323
|
}
|
|
332
|
-
class g extends
|
|
324
|
+
class g extends d {
|
|
333
325
|
constructor(t, e) {
|
|
334
326
|
super(t, { ...e, cause: "Import error" }), this.name = "CCCImportError";
|
|
335
327
|
}
|
|
336
328
|
}
|
|
337
|
-
class
|
|
329
|
+
class _ extends d {
|
|
330
|
+
constructor(t, e) {
|
|
331
|
+
super(t, { ...e, cause: "Render error" }), this.name = "CCCRenderError";
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
class j extends d {
|
|
338
335
|
constructor(t) {
|
|
339
336
|
super(null, { ...t, cause: "Timeout error" }), this.name = "CCCTimeoutError";
|
|
340
337
|
}
|
|
341
338
|
}
|
|
342
|
-
const
|
|
339
|
+
const w = class w extends Event {
|
|
343
340
|
constructor(t, e) {
|
|
344
|
-
super(
|
|
341
|
+
super(w.eventType, {
|
|
345
342
|
bubbles: !0,
|
|
346
343
|
cancelable: !1,
|
|
347
344
|
composed: !0,
|
|
@@ -349,73 +346,62 @@ const R = class A extends Event {
|
|
|
349
346
|
}), this.component = t.component, this.source = t.source;
|
|
350
347
|
}
|
|
351
348
|
};
|
|
352
|
-
|
|
353
|
-
let
|
|
354
|
-
const
|
|
349
|
+
w.eventType = "ccc:connected";
|
|
350
|
+
let b = w;
|
|
351
|
+
const H = (o) => o.replace(
|
|
355
352
|
/[A-Z]+(?![a-z])|[A-Z]/g,
|
|
356
353
|
(t, e) => (e ? "-" : "") + t.toLowerCase()
|
|
357
354
|
);
|
|
358
|
-
function
|
|
359
|
-
return
|
|
355
|
+
function z(o) {
|
|
356
|
+
return y([
|
|
360
357
|
"localhost",
|
|
361
358
|
"local.ft.com",
|
|
362
359
|
/^.*\.apps\.in\.ft\.com$/
|
|
363
360
|
], o);
|
|
364
361
|
}
|
|
365
|
-
function
|
|
366
|
-
return
|
|
362
|
+
function Y() {
|
|
363
|
+
return y([
|
|
367
364
|
"localhost",
|
|
368
365
|
"local.ft.com",
|
|
369
366
|
/^.*\.in\.ft\.com$/
|
|
370
367
|
], window.location.hostname);
|
|
371
368
|
}
|
|
372
|
-
function
|
|
373
|
-
return
|
|
369
|
+
function q() {
|
|
370
|
+
return y([
|
|
374
371
|
"spark.ft.com",
|
|
375
372
|
"spark-staging.ft.com"
|
|
376
373
|
], window.location.host);
|
|
377
374
|
}
|
|
378
|
-
function
|
|
375
|
+
function y(o, t) {
|
|
379
376
|
return t ? o.some((e) => typeof e == "string" ? e === t : e.test(t)) : !1;
|
|
380
377
|
}
|
|
381
|
-
function
|
|
378
|
+
function V(o) {
|
|
382
379
|
if (o === null)
|
|
383
380
|
return;
|
|
384
381
|
let t;
|
|
385
382
|
const e = new URL("http://localhost:5173");
|
|
386
383
|
try {
|
|
387
384
|
if (typeof o == "string") {
|
|
388
|
-
if ((o === "" || o.toLowerCase() === "true") &&
|
|
385
|
+
if ((o === "" || o.toLowerCase() === "true") && Y())
|
|
389
386
|
t = e;
|
|
390
|
-
else if (t = o.startsWith("http://") || o.startsWith("https://") ? new URL(o) : void 0, t && !
|
|
387
|
+
else if (t = o.startsWith("http://") || o.startsWith("https://") ? new URL(o) : void 0, t && !z(t == null ? void 0 : t.hostname))
|
|
391
388
|
throw new Error("Unsafe testing host override");
|
|
392
|
-
} else
|
|
393
|
-
J() && (t = e);
|
|
389
|
+
} else q() && (t = e);
|
|
394
390
|
} catch {
|
|
395
391
|
return t;
|
|
396
392
|
}
|
|
397
393
|
return t;
|
|
398
394
|
}
|
|
399
|
-
async function
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
return new Promise((s) => {
|
|
405
|
-
const r = new WebSocket(`ws://${n}`, "vite-hmr"), i = setTimeout(() => {
|
|
406
|
-
s(r.readyState === WebSocket.OPEN), r.close();
|
|
407
|
-
}, 50);
|
|
408
|
-
r.addEventListener("error", () => {
|
|
409
|
-
clearTimeout(i), r.close(), s(!1);
|
|
410
|
-
}, { once: !0 });
|
|
411
|
-
});
|
|
412
|
-
} catch {
|
|
413
|
-
return Promise.resolve(!1);
|
|
395
|
+
async function J(o, t) {
|
|
396
|
+
return t ? fetch(
|
|
397
|
+
new URL(`src/${o}/config.yaml`, t),
|
|
398
|
+
{
|
|
399
|
+
method: "HEAD"
|
|
414
400
|
}
|
|
415
|
-
|
|
416
|
-
return await t(o == null ? void 0 : o.host);
|
|
401
|
+
).then(() => !0).catch(() => !1) : !1;
|
|
417
402
|
}
|
|
418
|
-
|
|
403
|
+
const W = ":host{width:var(--ccc-root-width, 100%);margin:var(--ccc-root-margin);padding:var(--ccc-root-padding);display:var(--ccc-root-display, block);font-size:var(--ccc-root-fontSize);box-sizing:var(--ccc-root-boxSizing);border:var(--ccc-root-border);grid:var(--ccc-root-grid);line-height:var(--ccc-root-lineHeight)}";
|
|
404
|
+
class K extends HTMLElement {
|
|
419
405
|
constructor() {
|
|
420
406
|
super(), this.mode = "open", this.RESERVED_ATTRS = /* @__PURE__ */ new Set([
|
|
421
407
|
"iframe",
|
|
@@ -431,13 +417,13 @@ class q extends HTMLElement {
|
|
|
431
417
|
try {
|
|
432
418
|
(e = this.tracking) == null || e.init(this.id);
|
|
433
419
|
} catch (n) {
|
|
434
|
-
const
|
|
420
|
+
const r = this.getAttribute("path"), s = this.getAttribute("version");
|
|
435
421
|
this.log.info(
|
|
436
|
-
`Error initialising tracking on <custom-code-component> ${
|
|
422
|
+
`Error initialising tracking on <custom-code-component> ${r}@${s}`
|
|
437
423
|
), this.log.error(n);
|
|
438
424
|
}
|
|
439
|
-
}, this.log = new
|
|
440
|
-
level:
|
|
425
|
+
}, this.log = new T({
|
|
426
|
+
level: $(this.getAttribute("log"))
|
|
441
427
|
});
|
|
442
428
|
const t = HTMLElement.prototype.hasOwnProperty("attachInternals");
|
|
443
429
|
try {
|
|
@@ -449,7 +435,7 @@ class q extends HTMLElement {
|
|
|
449
435
|
async connectedCallback() {
|
|
450
436
|
try {
|
|
451
437
|
const t = this.getAttribute("path"), e = this.getAttribute("version");
|
|
452
|
-
this.component =
|
|
438
|
+
this.component = f.fromString(t, e), this.app = await this.load(), await this.mount(), await this.initTracking();
|
|
453
439
|
} catch (t) {
|
|
454
440
|
t instanceof Error && requestAnimationFrame(() => {
|
|
455
441
|
this.emitError(t);
|
|
@@ -457,19 +443,13 @@ class q extends HTMLElement {
|
|
|
457
443
|
}
|
|
458
444
|
}
|
|
459
445
|
emitError(t) {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
cancelable: !1,
|
|
468
|
-
composed: !0,
|
|
469
|
-
error: t,
|
|
470
|
-
message: t.message
|
|
471
|
-
})
|
|
472
|
-
);
|
|
446
|
+
this.dispatchEvent(new ErrorEvent("ccc:error", {
|
|
447
|
+
bubbles: !0,
|
|
448
|
+
cancelable: !1,
|
|
449
|
+
composed: !0,
|
|
450
|
+
error: t,
|
|
451
|
+
message: t.message
|
|
452
|
+
}));
|
|
473
453
|
}
|
|
474
454
|
disconnectedCallback() {
|
|
475
455
|
const t = this.getAttribute("path");
|
|
@@ -483,65 +463,98 @@ class q extends HTMLElement {
|
|
|
483
463
|
try {
|
|
484
464
|
await t;
|
|
485
465
|
} catch (e) {
|
|
486
|
-
e instanceof Error
|
|
466
|
+
if (e instanceof Error) {
|
|
467
|
+
const n = new _(e.message, {
|
|
468
|
+
error: e,
|
|
469
|
+
component: this.component
|
|
470
|
+
});
|
|
471
|
+
requestAnimationFrame(() => {
|
|
472
|
+
this.emitError(n), this.unmount(n);
|
|
473
|
+
});
|
|
474
|
+
}
|
|
487
475
|
}
|
|
488
476
|
}
|
|
489
477
|
postMessage(t) {
|
|
490
478
|
this.channel.port1.postMessage(t);
|
|
491
479
|
}
|
|
492
480
|
async mount(t) {
|
|
481
|
+
var e, n;
|
|
493
482
|
try {
|
|
494
|
-
if (this.mode = this.getAttribute("shadow-open") == "false" ? "closed" : "open", this.
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
483
|
+
if (this.mode = this.getAttribute("shadow-open") == "false" ? "closed" : "open", this.component) {
|
|
484
|
+
if (this.dispatchEvent(
|
|
485
|
+
new b({
|
|
486
|
+
component: this.component,
|
|
487
|
+
source: this.source
|
|
488
|
+
})
|
|
489
|
+
), this.dataset.cccReady = "true", delete this.dataset.cccError, !this.app)
|
|
490
|
+
throw new Error("CCC mounted without App");
|
|
491
|
+
const r = this.shadowRoot !== null, s = this.shadowRoot ?? this.attachShadow({ mode: this.mode });
|
|
492
|
+
if (!s.querySelector('link[href~="custom-code-component.css"]') && !s.adoptedStyleSheets.length && (window.CCC_LAYOUT_STYLESHEET || (window.CCC_LAYOUT_STYLESHEET = new CSSStyleSheet(), window.CCC_LAYOUT_STYLESHEET.replaceSync(W)), s.adoptedStyleSheets = [window.CCC_LAYOUT_STYLESHEET]), !r) {
|
|
493
|
+
const u = document.createElement("template");
|
|
494
|
+
u.innerHTML = "<div data-component-root><slot></slot></div>", this.appendChild(u), s.appendChild(u.content.cloneNode(!0));
|
|
495
|
+
}
|
|
496
|
+
const i = JSON.parse(this.getAttribute("data-component-props")), c = Object.fromEntries(
|
|
497
|
+
[...this.attributes].filter(
|
|
498
|
+
(u) => !this.RESERVED_ATTRS.has(u.name) && !u.name.startsWith("data-")
|
|
499
|
+
).map((u) => [u.name, u.value])
|
|
500
|
+
);
|
|
501
|
+
this.tracking = new F({
|
|
502
|
+
name: (e = this.component) == null ? void 0 : e.toString(),
|
|
503
|
+
subtype: "interactive",
|
|
504
|
+
teamName: "djd",
|
|
505
|
+
shadowRoot: this.shadowRoot,
|
|
506
|
+
logger: this.log
|
|
507
|
+
}), !i && Object.keys(c).length > 0 && (this.log.warn(
|
|
508
|
+
`CCC ${this.component.toString()}: passing component settings as webcomponent attributes is %cDEPRECATED`,
|
|
509
|
+
"font-weight: bold",
|
|
510
|
+
" and will be removed in v3."
|
|
511
|
+
), this.log.warn(
|
|
512
|
+
"Please use the %cdata-component-props",
|
|
513
|
+
"text-decoration: underline;",
|
|
514
|
+
" attribute instead."
|
|
515
|
+
));
|
|
516
|
+
const { unmount: h, onmessage: a, ready: m } = this.app(
|
|
517
|
+
s,
|
|
518
|
+
{
|
|
519
|
+
...i ?? c,
|
|
520
|
+
data: i ?? c,
|
|
521
|
+
port: this.channel.port2,
|
|
522
|
+
tracking: this.tracking,
|
|
523
|
+
prerendered: !!t,
|
|
524
|
+
children: this.children
|
|
525
|
+
},
|
|
526
|
+
r
|
|
527
|
+
) || {};
|
|
528
|
+
h && (this.onunmount = h), a && (this.onmessage = a), m && this.onready(m);
|
|
529
|
+
}
|
|
530
|
+
} catch (r) {
|
|
525
531
|
throw this.log.info(
|
|
526
|
-
`<custom-code-component> uncaught error during mount from ${this.component.toString()}`
|
|
527
|
-
), this.log.error(
|
|
532
|
+
`<custom-code-component> uncaught error during mount from ${(n = this.component) == null ? void 0 : n.toString()}`
|
|
533
|
+
), this.log.error(r), r;
|
|
528
534
|
}
|
|
529
535
|
}
|
|
530
536
|
// Called in top-level error handler
|
|
531
|
-
// Replace shadow root with
|
|
537
|
+
// Replace shadow root with either <slot> or template[data-component-fallback]
|
|
538
|
+
// slot on failure
|
|
532
539
|
unmount(t) {
|
|
533
|
-
var
|
|
534
|
-
this.onunmount(
|
|
540
|
+
var n;
|
|
541
|
+
this.onunmount(t);
|
|
542
|
+
const e = this.querySelector(
|
|
543
|
+
"template[data-component-fallback]"
|
|
544
|
+
) ?? this.querySelector("template");
|
|
545
|
+
e && ((n = this.shadowRoot) == null || n.replaceChildren(e.content.cloneNode(!0))), this.dataset.cccError || (this.dataset.cccError = H(t.name.replace("CCC", ""))), delete this.dataset.cccReady;
|
|
535
546
|
}
|
|
536
547
|
async load() {
|
|
537
|
-
|
|
538
|
-
|
|
548
|
+
if (!this.component)
|
|
549
|
+
throw new Error("No path found");
|
|
550
|
+
const t = this.getAttribute("path"), e = this.getAttribute("version"), n = Number(this.getAttribute("load-timeout") || 1e4), r = this.getAttribute("test-env"), s = V(r), i = await J(this.component.name, s), c = this.getAttribute("id");
|
|
551
|
+
this.source = i ? `${s == null ? void 0 : s.origin}/src/${this.component.name}/index.jsx?id=${c}` : `https://www.ft.com/__component/${this.component.org}/${this.component.repo}${e ? `@${e}` : "@latest"}/${this.component.name}/${this.component.name}.js?id=${c}`;
|
|
539
552
|
try {
|
|
540
553
|
return await new Promise(
|
|
541
554
|
(h, a) => {
|
|
542
|
-
const
|
|
555
|
+
const m = setTimeout(() => {
|
|
543
556
|
this.log.error("CCC import timeout error"), a(
|
|
544
|
-
new
|
|
557
|
+
new j({
|
|
545
558
|
component: this.component,
|
|
546
559
|
source: this.source
|
|
547
560
|
})
|
|
@@ -554,7 +567,7 @@ class q extends HTMLElement {
|
|
|
554
567
|
/* @vite-ignore */
|
|
555
568
|
).then(({ default: u }) => {
|
|
556
569
|
if (u)
|
|
557
|
-
clearTimeout(
|
|
570
|
+
clearTimeout(m), h(u);
|
|
558
571
|
else
|
|
559
572
|
throw new g(
|
|
560
573
|
"No component renderer default export found",
|
|
@@ -564,7 +577,7 @@ class q extends HTMLElement {
|
|
|
564
577
|
}
|
|
565
578
|
);
|
|
566
579
|
}).catch((u) => {
|
|
567
|
-
clearTimeout(
|
|
580
|
+
clearTimeout(m), this.log.error(u), u instanceof Error && !(u instanceof g) ? a(
|
|
568
581
|
new g(u.message, {
|
|
569
582
|
component: this.component,
|
|
570
583
|
source: this.source
|
|
@@ -572,7 +585,7 @@ class q extends HTMLElement {
|
|
|
572
585
|
) : a(u);
|
|
573
586
|
});
|
|
574
587
|
else
|
|
575
|
-
throw clearTimeout(
|
|
588
|
+
throw clearTimeout(m), new g(`Unable to mount ${t}`, {
|
|
576
589
|
component: this.component,
|
|
577
590
|
source: this.source
|
|
578
591
|
});
|
|
@@ -585,9 +598,7 @@ class q extends HTMLElement {
|
|
|
585
598
|
}
|
|
586
599
|
}
|
|
587
600
|
}
|
|
588
|
-
const B = () => customElements.define("custom-code-component", q);
|
|
589
|
-
customElements && !customElements.get("custom-code-component") && B();
|
|
590
601
|
export {
|
|
591
|
-
|
|
602
|
+
K as FTCustomCodeComponent
|
|
592
603
|
};
|
|
593
|
-
//# sourceMappingURL=
|
|
604
|
+
//# sourceMappingURL=custom-element.js.map
|