@vouchfor/embeds 0.0.0-experiment.bdda3d0 → 0.0.0-experiment.d900f80
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/es/components/Embed/controllers/fetcher.d.ts +0 -7
- package/dist/es/components/Embed/index.d.ts +2 -2
- package/dist/es/embeds.js +166 -178
- package/dist/es/embeds.js.map +1 -1
- package/dist/iife/embeds.iife.js +154 -231
- package/dist/iife/embeds.iife.js.map +1 -1
- package/package.json +4 -4
- package/src/components/Embed/controllers/fetcher.ts +22 -49
- package/src/components/Embed/index.ts +3 -8
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vouchfor/embeds",
|
3
|
-
"version": "0.0.0-experiment.
|
3
|
+
"version": "0.0.0-experiment.d900f80",
|
4
4
|
"license": "MIT",
|
5
5
|
"author": "Aaron Williams",
|
6
6
|
"main": "dist/es/embeds.js",
|
@@ -26,7 +26,7 @@
|
|
26
26
|
"lint:staged": "lint-staged",
|
27
27
|
"prepublishOnly": "yarn build",
|
28
28
|
"size": "size-limit",
|
29
|
-
"storybook": "yarn prebuild && storybook dev -p
|
29
|
+
"storybook": "yarn prebuild && storybook dev -p 6007",
|
30
30
|
"prebuild": "yarn build:deps && yarn generate:manifest",
|
31
31
|
"test": "true"
|
32
32
|
},
|
@@ -35,8 +35,8 @@
|
|
35
35
|
"**/*.{md,json,yml}": "prettier --write"
|
36
36
|
},
|
37
37
|
"dependencies": {
|
38
|
-
"@lit/task": "1.0.0",
|
39
|
-
"@vouchfor/media-player": "0.0.0-experiment.
|
38
|
+
"@lit/task": "^1.0.0",
|
39
|
+
"@vouchfor/media-player": "0.0.0-experiment.d900f80",
|
40
40
|
"uuid": "^9.0.1"
|
41
41
|
},
|
42
42
|
"peerDependencies": {
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { Task } from '@lit/task';
|
2
2
|
|
3
3
|
import type { Embed, EmbedProps } from '..';
|
4
|
-
import type { TemplateInstance } from '@vouchfor/canvas-video';
|
5
4
|
import type { ReactiveControllerHost } from 'lit';
|
6
5
|
import type { Environment } from '~/utils/env';
|
7
6
|
|
@@ -21,8 +20,6 @@ class FetcherController {
|
|
21
20
|
host: EmbedHost;
|
22
21
|
|
23
22
|
private _fetching = false;
|
24
|
-
private _vouch?: EmbedProps['data'];
|
25
|
-
private _template?: TemplateInstance;
|
26
23
|
|
27
24
|
set fetching(value) {
|
28
25
|
if (this._fetching !== value) {
|
@@ -34,50 +31,22 @@ class FetcherController {
|
|
34
31
|
return this._fetching;
|
35
32
|
}
|
36
33
|
|
37
|
-
|
38
|
-
if (this._vouch !== value) {
|
39
|
-
this._vouch = value;
|
40
|
-
this.host.requestUpdate();
|
41
|
-
}
|
42
|
-
}
|
43
|
-
get vouch() {
|
44
|
-
return this._vouch;
|
45
|
-
}
|
46
|
-
|
47
|
-
set template(value) {
|
48
|
-
if (this._template !== value) {
|
49
|
-
this._template = value;
|
50
|
-
this.host.requestUpdate();
|
51
|
-
}
|
52
|
-
}
|
53
|
-
get template() {
|
54
|
-
return this._template;
|
55
|
-
}
|
56
|
-
|
57
|
-
private async getVouch(env: Environment, apiKey: string, vouchId?: string) {
|
34
|
+
private async getVouch(env: Environment, apiKey: string, vouchId: string) {
|
58
35
|
const { embedApiUrl } = getEnvUrls(env);
|
59
36
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
}).then((response) => response.json());
|
65
|
-
}
|
66
|
-
|
67
|
-
return null;
|
37
|
+
return fetch(`${embedApiUrl}/vouches/${vouchId}`, {
|
38
|
+
method: 'GET',
|
39
|
+
headers: [['X-Api-Key', apiKey]]
|
40
|
+
}).then((response) => response.json());
|
68
41
|
}
|
69
42
|
|
70
|
-
private async getTemplate(env: Environment, apiKey: string, templateId
|
43
|
+
private async getTemplate(env: Environment, apiKey: string, templateId: string) {
|
71
44
|
const { embedApiUrl } = getEnvUrls(env);
|
72
45
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
}).then((response) => response.json());
|
78
|
-
}
|
79
|
-
|
80
|
-
return null;
|
46
|
+
return fetch(`${embedApiUrl}/templates/${templateId}`, {
|
47
|
+
method: 'GET',
|
48
|
+
headers: [['X-Api-Key', apiKey]]
|
49
|
+
}).then((response) => response.json());
|
81
50
|
}
|
82
51
|
|
83
52
|
constructor(host: EmbedHost) {
|
@@ -86,22 +55,26 @@ class FetcherController {
|
|
86
55
|
this.host,
|
87
56
|
async ([env, apiKey, data, vouchId, templateId]: TaskDeps) => {
|
88
57
|
try {
|
89
|
-
|
90
|
-
|
58
|
+
host.vouch = undefined;
|
59
|
+
host.template = undefined;
|
91
60
|
|
92
61
|
if (data) {
|
93
|
-
|
94
|
-
|
95
|
-
|
62
|
+
let template;
|
63
|
+
if (templateId) {
|
64
|
+
this.fetching = true;
|
65
|
+
template = await this.getTemplate(env, apiKey, templateId);
|
66
|
+
}
|
67
|
+
host.vouch = data;
|
68
|
+
host.template = template ?? data?.settings?.template?.instance;
|
96
69
|
} else if (vouchId) {
|
97
70
|
this.fetching = true;
|
98
71
|
|
99
72
|
const [vouch, template] = await Promise.all([
|
100
73
|
this.getVouch(env, apiKey, vouchId),
|
101
|
-
this.getTemplate(env, apiKey, templateId)
|
74
|
+
templateId ? this.getTemplate(env, apiKey, templateId) : null
|
102
75
|
]);
|
103
|
-
|
104
|
-
|
76
|
+
host.vouch = vouch;
|
77
|
+
host.template = template ?? vouch?.settings?.template?.instance;
|
105
78
|
}
|
106
79
|
} finally {
|
107
80
|
this.fetching = false;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { html, LitElement } from 'lit';
|
2
|
-
import { customElement, property } from 'lit/decorators.js';
|
2
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
3
3
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
4
4
|
import { createRef, ref } from 'lit/directives/ref.js';
|
5
5
|
|
@@ -69,13 +69,8 @@ class Embed extends LitElement {
|
|
69
69
|
// @ts-ignore
|
70
70
|
private _trackingController = new TrackingController(this);
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
}
|
75
|
-
|
76
|
-
get template(): TemplateInstance | undefined {
|
77
|
-
return this._fetcherController.template;
|
78
|
-
}
|
72
|
+
@state() vouch: EmbedProps['data'];
|
73
|
+
@state() template: TemplateInstance | undefined;
|
79
74
|
|
80
75
|
get fetching() {
|
81
76
|
return this._fetcherController.fetching;
|