@financial-times/custom-code-component 2.0.1-beta.12 → 2.0.1-beta.14
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-element.d.ts +7 -3
- package/dist/custom-element.js +219 -141
- package/dist/custom-element.js.map +1 -1
- package/package.json +1 -1
- package/src/custom-code-component.ts +100 -25
- package/src/events.ts +46 -4
- package/src/path.ts +9 -3
package/src/events.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { ComponentPath } from "./path";
|
|
2
2
|
|
|
3
|
-
export class
|
|
4
|
-
static eventType = "ccc:connected";
|
|
5
|
-
|
|
3
|
+
export class CCCEvent extends Event {
|
|
6
4
|
component: ComponentPath;
|
|
7
5
|
source?: string;
|
|
6
|
+
static eventType = "ccc:event";
|
|
8
7
|
|
|
9
8
|
constructor(
|
|
9
|
+
eventType: string = CCCEvent.eventType,
|
|
10
10
|
detail: { component: ComponentPath; source?: string },
|
|
11
11
|
opts?: EventInit
|
|
12
12
|
) {
|
|
13
|
-
super(
|
|
13
|
+
super(eventType, {
|
|
14
14
|
bubbles: true,
|
|
15
15
|
cancelable: false,
|
|
16
16
|
composed: true,
|
|
@@ -20,3 +20,45 @@ export class CCCConnectedEvent extends Event {
|
|
|
20
20
|
this.source = detail.source;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
export class CCCConnectedEvent extends CCCEvent {
|
|
25
|
+
static eventType = "ccc:connected";
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
detail: { component: ComponentPath; source?: string },
|
|
29
|
+
opts?: EventInit
|
|
30
|
+
) {
|
|
31
|
+
super(CCCConnectedEvent.eventType, detail, opts);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class CCCReadyEvent extends CCCEvent {
|
|
36
|
+
static eventType = "ccc:ready";
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
detail: { component: ComponentPath; source?: string },
|
|
40
|
+
opts?: EventInit
|
|
41
|
+
) {
|
|
42
|
+
super(CCCReadyEvent.eventType, detail, opts);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class CCCViewportEvent extends CCCEvent {
|
|
47
|
+
static eventType = "ccc:viewport";
|
|
48
|
+
intersecting = false;
|
|
49
|
+
entry?: IntersectionObserverEntry;
|
|
50
|
+
|
|
51
|
+
constructor(
|
|
52
|
+
detail: {
|
|
53
|
+
component: ComponentPath;
|
|
54
|
+
source?: string;
|
|
55
|
+
intersecting: boolean;
|
|
56
|
+
entry?: IntersectionObserverEntry;
|
|
57
|
+
},
|
|
58
|
+
opts?: EventInit
|
|
59
|
+
) {
|
|
60
|
+
super(CCCViewportEvent.eventType, detail, opts);
|
|
61
|
+
this.intersecting = detail.intersecting;
|
|
62
|
+
this.entry = detail.entry;
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/path.ts
CHANGED
|
@@ -12,7 +12,7 @@ export class ComponentPath {
|
|
|
12
12
|
name: string;
|
|
13
13
|
versionRange: string;
|
|
14
14
|
|
|
15
|
-
constructor(path
|
|
15
|
+
constructor(path?: ComponentPathType | string) {
|
|
16
16
|
const { org, repo, name, versionRange } = isValidComponentPathObject(path)
|
|
17
17
|
? path
|
|
18
18
|
: ComponentPath.fromString(path);
|
|
@@ -36,12 +36,18 @@ export class ComponentPath {
|
|
|
36
36
|
return `${this.org}/${this.repo}@${this.versionRange}/${this.name}`;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
get isValid(): boolean {
|
|
40
|
+
return [this.org, this.repo, this.name].every(
|
|
41
|
+
(value) => value !== "unknown"
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
39
45
|
toString(): string {
|
|
40
46
|
return this.path;
|
|
41
47
|
}
|
|
42
48
|
|
|
43
|
-
static fromString(
|
|
44
|
-
|
|
49
|
+
static fromString(p?: string | null, v?: string | null): ComponentPath {
|
|
50
|
+
const path = p ?? "unknown/unknown/unknown";
|
|
45
51
|
|
|
46
52
|
const [name, repo, org] = path
|
|
47
53
|
.replace(/@[^\/]+/, "")
|