@salesforcedevs/dw-components 1.3.261 → 1.3.265

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/lwc.config.json CHANGED
@@ -6,6 +6,7 @@
6
6
  "expose": [
7
7
  "dw/blogsGrid",
8
8
  "dw/videoGrid",
9
+ "dw/youtubeVideoGrid",
9
10
  "dw/browseTrials",
10
11
  "dw/cardBlogPostProvider",
11
12
  "dw/cardPodcastEpisodeProvider",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dw-components",
3
- "version": "1.3.261",
3
+ "version": "1.3.265",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -10,11 +10,13 @@
10
10
  "access": "public"
11
11
  },
12
12
  "dependencies": {
13
+ "@types/youtube-player": "^5.5.11",
13
14
  "classnames": "^2.2.6",
14
15
  "lodash.clonedeep": "^4.5.0",
15
16
  "lodash.orderby": "^4.6.0",
16
17
  "lodash.uniqby": "^4.7.0",
17
- "query-string": "^7.1.3"
18
+ "query-string": "^7.1.3",
19
+ "youtube-player": "^5.6.0"
18
20
  },
19
21
  "devDependencies": {
20
22
  "@types/classnames": "^2.2.10",
@@ -24,5 +26,5 @@
24
26
  "@types/setimmediate": "^1.0.2",
25
27
  "setimmediate": "^1.0.5"
26
28
  },
27
- "gitHead": "8f326de081fbbef38ac44074ed4f54190e6416c1"
29
+ "gitHead": "840b94133684a800cbdc7432f9df4d69a15cc0e9"
28
30
  }
@@ -0,0 +1,8 @@
1
+ export type VideoData = {
2
+ id: string;
3
+ iframeTitle: string;
4
+ title: string;
5
+ body?: string;
6
+ src: string;
7
+ date?: string;
8
+ };
@@ -0,0 +1,14 @@
1
+ @import "dxHelpers/reset";
2
+ @import "dxHelpers/text";
3
+
4
+ h3 {
5
+ margin: var(--dx-g-spacing-md) 0;
6
+ }
7
+
8
+ p {
9
+ margin-bottom: var(--dx-g-spacing-md);
10
+ }
11
+
12
+ .video-container iframe {
13
+ border-radius: 16px;
14
+ }
@@ -0,0 +1,24 @@
1
+ <template>
2
+ <dx-grid columns="dynamic">
3
+ <template for:each={videosData} for:item="videoData">
4
+ <div class="video-container" key={videoData.id}>
5
+ <iframe
6
+ id={videoData.id}
7
+ src={videoData.src}
8
+ width={width}
9
+ height={height}
10
+ title={videoData.iframeTitle}
11
+ allowfullscreen
12
+ ></iframe>
13
+ <h3 lwc:if={videoData.title} class="dx-text-display-6">
14
+ {videoData.title}
15
+ </h3>
16
+ <p lwc:if={videoData.body}>{videoData.body}</p>
17
+ <dx-formatted-date-time
18
+ lwc:if={videoData.date}
19
+ value={videoData.date}
20
+ ></dx-formatted-date-time>
21
+ </div>
22
+ </template>
23
+ </dx-grid>
24
+ </template>
@@ -0,0 +1,66 @@
1
+ import { api, LightningElement } from "lwc";
2
+ import YoutubePlayer from "youtube-player";
3
+ import { VideoData } from "./types";
4
+
5
+ const PLAYING = 1;
6
+
7
+ export default class YoutubeVideoGrid extends LightningElement {
8
+ @api width = 382;
9
+ @api height = 215;
10
+
11
+ @api
12
+ get videosData(): Array<VideoData> {
13
+ return this._videosData;
14
+ }
15
+
16
+ set videosData(value: string | Array<VideoData>) {
17
+ if (typeof value === "string") {
18
+ try {
19
+ this._videosData = JSON.parse(value) as Array<VideoData>;
20
+ } catch (error) {
21
+ console.error("Error parsing cards data:", error);
22
+ this._videosData = [];
23
+ }
24
+ } else {
25
+ this._videosData = value;
26
+ }
27
+ }
28
+
29
+ private _videosData: Array<VideoData> = [];
30
+ private players: any = [];
31
+ private _hasRendered = false;
32
+
33
+ private pauseAllExceptCurrent(id: any) {
34
+ this.players.forEach((currentPlayer: any) => {
35
+ if (currentPlayer.id !== id) {
36
+ currentPlayer.player.pauseVideo();
37
+ }
38
+ });
39
+ }
40
+
41
+ renderedCallback() {
42
+ if (this._hasRendered) {
43
+ return;
44
+ }
45
+
46
+ const iframeEls = this.template.querySelectorAll("iframe");
47
+
48
+ iframeEls.forEach((el, index) => {
49
+ // The YoutubePlayer package is a wrapper around the Youtube embedded API without the need for script tags (which aren't allowed in LWC templates)
50
+ // https://developers.google.com/youtube/iframe_api_reference
51
+ const player = YoutubePlayer(el);
52
+
53
+ this.players.push({ id: index, player });
54
+
55
+ // Listener for state change events (play, pause, etc).
56
+ player.on("stateChange", (event: any) => {
57
+ if (event.data === PLAYING) {
58
+ // Pause all other players when a new one starts playing.
59
+ this.pauseAllExceptCurrent(index);
60
+ }
61
+ });
62
+ });
63
+
64
+ this._hasRendered = true;
65
+ }
66
+ }