@financial-times/custom-code-component 0.0.5 → 0.0.8

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