@financial-times/custom-code-component 0.0.7 → 0.0.9

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 h extends HTMLElement {
1
+ class u extends HTMLElement {
2
2
  constructor() {
3
3
  super(...arguments), this.RESERVED_ATTRS = /* @__PURE__ */ new Set([
4
4
  "iframe",
@@ -6,25 +6,24 @@ class h extends HTMLElement {
6
6
  "version",
7
7
  "data-component-props",
8
8
  "data-asset-type",
9
- "shadow-open"
9
+ "shadow-open",
10
+ "env"
10
11
  ]);
11
12
  }
12
13
  async connectedCallback() {
13
- const o = this.getAttribute("path"), n = this.hasAttribute("shadow-open") ? "open" : "closed", s = this.getAttribute("version");
14
- if (!o)
14
+ var a;
15
+ const n = this.getAttribute("path"), s = this.hasAttribute("shadow-open") ? "open" : "closed", c = this.getAttribute("version"), m = (a = this.getAttribute("env")) == null ? void 0 : a.toLowerCase().startsWith("d");
16
+ if (!n)
15
17
  throw new Error(
16
18
  "path attribute not specified in <custom-code-component>"
17
19
  );
18
- const [c, a, i] = o.split("/").reverse(), p = !i || a === "ccc-sdk" ? `http://localhost:5173/src/${c}/index.jsx` : (
19
- // @TODO create component service -- this URL may change!!!
20
- `https://www.ft.com/__component/${i}/${a}/${c}${s ? `@${s}` : "@latest"}`
21
- );
20
+ const [o, p, h] = n.split("/").reverse(), d = m ? `http://localhost:5173/src/${o}/index.jsx` : `https://www.ft.com/__component/${h}/${p}/${o}${c ? `@${c}` : "@latest"}/${o}.js`;
22
21
  try {
23
22
  const e = await import(
24
23
  /* webpackIgnore: true */
25
- p
24
+ d
26
25
  /* @vite-ignore */
27
- ), m = JSON.parse(this.getAttribute("data-component-props")), r = Object.fromEntries(
26
+ ), i = JSON.parse(this.getAttribute("data-component-props")), r = Object.fromEntries(
28
27
  [...this.attributes].filter((t) => !this.RESERVED_ATTRS.has(t.name)).map((t) => [t.name, t.value])
29
28
  );
30
29
  if (this.hasAttribute("iframe")) {
@@ -32,21 +31,21 @@ class h extends HTMLElement {
32
31
  t.addEventListener("load", () => {
33
32
  e.default(
34
33
  t.contentDocument,
35
- { ...r, data: m },
34
+ { ...r, data: i },
36
35
  ...this.children
37
36
  );
38
- }), this.attachShadow({ mode: n }).append(t);
37
+ }), this.attachShadow({ mode: s }).append(t);
39
38
  } else {
40
- const t = this.attachShadow({ mode: n });
41
- e.default(t, { ...r, data: m }, ...this.children);
39
+ const t = this.attachShadow({ mode: s });
40
+ e.default(t, { ...r, data: i }, ...this.children);
42
41
  }
43
42
  } catch (e) {
44
43
  console.info("<custom-code-component> caught: ", e);
45
44
  }
46
45
  }
47
46
  }
48
- const d = () => customElements.define("custom-code-component", h);
49
- customElements && !customElements.get("custom-code-component") && d();
47
+ const l = () => customElements.define("custom-code-component", u);
48
+ customElements && !customElements.get("custom-code-component") && l();
50
49
  export {
51
- d as init
50
+ l as init
52
51
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/custom-code-component",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -13,12 +13,16 @@ class FTCustomCodeComponent extends HTMLElement {
13
13
  "data-component-props",
14
14
  "data-asset-type",
15
15
  "shadow-open",
16
+ "env",
16
17
  ]);
17
18
 
18
19
  async connectedCallback() {
19
20
  const path = this.getAttribute("path");
20
21
  const mode = this.hasAttribute("shadow-open") ? "open" : "closed";
21
22
  const componentVersionRange = this.getAttribute("version");
23
+ const useLocalVersion = this.getAttribute("env")
24
+ ?.toLowerCase()
25
+ .startsWith("d");
22
26
 
23
27
  if (!path)
24
28
  throw new Error(
@@ -29,13 +33,11 @@ class FTCustomCodeComponent extends HTMLElement {
29
33
  .split("/")
30
34
  .reverse();
31
35
 
32
- const source =
33
- !componentOrg || componentRepo === "ccc-sdk"
34
- ? `http://localhost:5173/src/${componentName}/index.jsx`
35
- : // @TODO create component service -- this URL may change!!!
36
- `https://www.ft.com/__component/${componentOrg}/${componentRepo}/${componentName}${
37
- componentVersionRange ? `@${componentVersionRange}` : "@latest"
38
- }`;
36
+ const source = useLocalVersion
37
+ ? `http://localhost:5173/src/${componentName}/index.jsx`
38
+ : `https://www.ft.com/__component/${componentOrg}/${componentRepo}/${componentName}${
39
+ componentVersionRange ? `@${componentVersionRange}` : "@latest"
40
+ }/${componentName}.js`;
39
41
  try {
40
42
  const App = await import(
41
43
  /* webpackIgnore: true */ source /* @vite-ignore */