@financial-times/custom-code-component 1.0.0 → 1.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/custom-code-component",
3
- "version": "1.0.0",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -11,14 +11,14 @@
11
11
  "scripts": {
12
12
  "dev": "vite",
13
13
  "build": "vite build",
14
- "prepublishOnly": "npm run build"
14
+ "prepublishOnly": "npm run build",
15
+ "test": "echo \"No custom-code-component tests\" && exit 0"
15
16
  },
16
17
  "devDependencies": {
17
18
  "@financial-times/content-tree": "github:financial-times/content-tree",
18
19
  "@vitejs/plugin-react": "^4.0.4",
19
20
  "eslint": "^8.47.0",
20
21
  "eslint-plugin-react": "^7.33.1",
21
- "prettier": "^3.0.1",
22
22
  "react-dom16": "npm:react-dom@^16.14.0",
23
23
  "react16": "npm:react@^16.14.0",
24
24
  "typescript": "^5.2.2",
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @file
3
- * Main component definition for g-react-loader
3
+ * Main component definition for custom-code-component
4
4
  */
5
5
 
6
6
  import { ContentTree } from "@financial-times/content-tree";
@@ -39,7 +39,7 @@ class FTCustomCodeComponent extends HTMLElement {
39
39
  ? `http://localhost:5173/src/${componentName}/index.jsx`
40
40
  : `https://www.ft.com/__component/${componentOrg}/${componentRepo}${
41
41
  componentVersionRange ? `@${componentVersionRange}` : "@latest"
42
- }/${componentName}/${componentName}`;
42
+ }/${componentName}/${componentName}.js`;
43
43
 
44
44
  try {
45
45
  const App = await import(
@@ -72,14 +72,16 @@ class FTCustomCodeComponent extends HTMLElement {
72
72
  App.default(shadowRoot, { ...extraProps, data }, ...this.children);
73
73
  }
74
74
  } catch (e) {
75
- console.info("<custom-code-component> caught: ", e);
75
+ console.info(`<custom-code-component> uncaught error from ${path}: `, e);
76
76
  }
77
77
  }
78
78
  }
79
79
 
80
+ // Register the custom element
80
81
  export const init = () =>
81
82
  customElements.define("custom-code-component", FTCustomCodeComponent);
82
83
 
84
+ // Allows module to be imported multiple times but custom element only registered once
83
85
  if (customElements && !customElements.get("custom-code-component")) init();
84
86
 
85
87
  export interface CustomCodeComponent extends ContentTree.Node {
@@ -87,8 +89,12 @@ export interface CustomCodeComponent extends ContentTree.Node {
87
89
  path: string;
88
90
  versionRange: string;
89
91
  altText: string;
90
- timestamp?: string;
92
+ lastModified: string;
91
93
  fallbackImage?: ContentTree.Image;
92
- attributes?: Array<[string, string]>;
93
- children?: Array<ContentTree.Node | CustomCodeComponent>;
94
+ displayFallbackText: boolean;
95
+ layout: "in-line" | "mid-grid" | "full-grid" | "full-bleed";
96
+ /* prettier-ignore */
97
+ attributes: {
98
+ [key: string]: string | boolean | undefined;
99
+ } | { children?: CustomCodeComponent | Array<CustomCodeComponent> };
94
100
  }
@@ -0,0 +1,67 @@
1
+ <?xml version="1.0"?>
2
+
3
+ <xs:schema
4
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
5
+ xmlns:sch="http://purl.oclc.org/dsdl/schematron"
6
+ >
7
+ <xs:complexType name="CustomCodeComponent">
8
+ <xs:sequence minOccurs="0">
9
+ <xs:element
10
+ name="custom-code-component"
11
+ type="CustomCodeComponent"
12
+ maxOccurs="unbounded"
13
+ />
14
+ </xs:sequence>
15
+ <xs:attribute
16
+ name="path"
17
+ type="xs:anyURI"
18
+ use="required"
19
+ />
20
+ <xs:attribute
21
+ name="versionRange"
22
+ type="xs:string"
23
+ use="required"
24
+ />
25
+ <xs:attribute
26
+ name="altText"
27
+ type="xs:string"
28
+ use="required"
29
+ />
30
+ <xs:attribute
31
+ name="lastModifiedTimestamp"
32
+ type="xs:string"
33
+ use="required"
34
+ />
35
+ <xs:attribute
36
+ name="fallbackImageURL"
37
+ type="xs:string"
38
+ />
39
+ <xs:attribute
40
+ name="displayFallbackText"
41
+ type="xs:boolean"
42
+ default="false"
43
+ />
44
+ <xs:attribute
45
+ name="layout"
46
+ default="in-line"
47
+ >
48
+ <xs:simpleType>
49
+ <xs:restriction base="xs:string">
50
+ <xs:enumeration value="in-line" />
51
+ <xs:enumeration value="mid-grid" />
52
+ <xs:enumeration value="full-grid" />
53
+ <xs:enumeration value="full-bleed" />
54
+ </xs:restriction>
55
+ </xs:simpleType>
56
+ </xs:attribute>
57
+ <xs:attribute
58
+ name="attributes"
59
+ type="xs:string"
60
+ default="{}"
61
+ />
62
+ </xs:complexType>
63
+ <xs:element
64
+ name="custom-code-component"
65
+ type="CustomCodeComponent"
66
+ />
67
+ </xs:schema>
@@ -0,0 +1,21 @@
1
+ <?xml-model href="../src/custom-code-component.xsd"?>
2
+
3
+ <custom-code-component
4
+ path="Financial-Times/awesome-component"
5
+ versionRange="^0.3.5"
6
+ altText="awesome component"
7
+ lastModifiedTimestamp="2024-01-26T03:25Z"
8
+ fallbackImageURL="https://picsum.photos/200/300"
9
+ layout="in-line"
10
+ attributes='{"test": "data"}'
11
+ >
12
+ <custom-code-component
13
+ path="Financial-Times/awesome-child-component"
14
+ versionRange="^0.3.5"
15
+ altText="awesome child component"
16
+ lastModifiedTimestamp="2024-01-26T03:25Z"
17
+ fallbackImageURL="https://picsum.photos/100/100"
18
+ displayFallbackText="true"
19
+ attributes='{"test2": "data2"}'
20
+ />
21
+ </custom-code-component>
@@ -1,44 +0,0 @@
1
- version: 2.1
2
-
3
- orbs:
4
- node: circleci/node@5.1.0
5
- doppler-circleci: ft-circleci-orbs/doppler-circleci@1.3
6
-
7
- references:
8
- default_container_config: &default_container_config
9
- executor:
10
- name: node/default
11
- tag: 'lts'
12
-
13
- only_version_tags: &only_version_tags
14
- tags:
15
- only: /^v.*/
16
- branches:
17
- ignore: /.*/
18
-
19
- jobs:
20
- build:
21
- <<: *default_container_config
22
- steps:
23
- - checkout
24
- - doppler-circleci/install
25
- - doppler-circleci/load_secrets:
26
- doppler_token: DOPPLER_TOKEN_VS_COMPONENTS
27
- - run:
28
- name: Install dependencies
29
- command: npm install
30
- - run:
31
- name: Publish package
32
- command: |
33
- npm set @Financial-Times:registry=https://npm.pkg.github.com/
34
- npm set //npm.pkg.github.com/:_authToken=${GPR_WRITE_AUTH_TOKEN}
35
- npm publish
36
-
37
- workflows:
38
- build-and-release:
39
- jobs:
40
- - build:
41
- context:
42
- - djd-starter-kit-s3-deployment # context is named the same in both orgs
43
- filters:
44
- <<: *only_version_tags
@@ -1 +0,0 @@
1
- * @Financial-Times/visual-data-journalism-admins
@@ -1,16 +0,0 @@
1
- /**
2
- * @file
3
- * Main component definition for g-react-loader
4
- */
5
- import { ContentTree } from "@financial-times/content-tree";
6
- export declare const init: () => void;
7
- export interface CustomCodeComponent extends ContentTree.Node {
8
- type: "CustomCodeComponent";
9
- path: string;
10
- versionRange: string;
11
- altText: string;
12
- timestamp?: string;
13
- fallbackImage?: ContentTree.Image;
14
- attributes?: Array<[string, string]>;
15
- children?: Array<ContentTree.Node | CustomCodeComponent>;
16
- }
@@ -1,54 +0,0 @@
1
- class u extends HTMLElement {
2
- constructor() {
3
- super(...arguments), this.RESERVED_ATTRS = /* @__PURE__ */ new Set([
4
- "iframe",
5
- "path",
6
- "version",
7
- "data-component-props",
8
- "data-asset-type",
9
- "shadow-open",
10
- "env"
11
- ]);
12
- }
13
- async connectedCallback() {
14
- var r;
15
- const n = this.getAttribute("path"), s = this.hasAttribute("shadow-open") ? "open" : "closed", c = this.getAttribute("version"), h = (r = this.getAttribute("env")) == null ? void 0 : r.toLowerCase().startsWith("d");
16
- if (!n)
17
- throw new Error(
18
- "path attribute not specified in <custom-code-component>"
19
- );
20
- const [e, a, i] = n.split("/").reverse();
21
- if (!e || !a || !i)
22
- return;
23
- const d = h ? `http://localhost:5173/src/${e}/index.jsx` : `https://www.ft.com/__component/${i}/${a}${c ? `@${c}` : "@latest"}/${e}/${e}`;
24
- try {
25
- const o = await import(
26
- /* webpackIgnore: true */
27
- d
28
- /* @vite-ignore */
29
- ), m = JSON.parse(this.getAttribute("data-component-props")), p = Object.fromEntries(
30
- [...this.attributes].filter((t) => !this.RESERVED_ATTRS.has(t.name)).map((t) => [t.name, t.value])
31
- );
32
- if (this.hasAttribute("iframe")) {
33
- const t = document.createElement("iframe");
34
- t.addEventListener("load", () => {
35
- o.default(
36
- t.contentDocument,
37
- { ...p, data: m },
38
- ...this.children
39
- );
40
- }), this.attachShadow({ mode: s }).append(t);
41
- } else {
42
- const t = this.attachShadow({ mode: s });
43
- o.default(t, { ...p, data: m }, ...this.children);
44
- }
45
- } catch (o) {
46
- console.info("<custom-code-component> caught: ", o);
47
- }
48
- }
49
- }
50
- const l = () => customElements.define("custom-code-component", u);
51
- customElements && !customElements.get("custom-code-component") && l();
52
- export {
53
- l as init
54
- };