@playpilot/tpi 7.1.0 → 7.3.0

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/events.md CHANGED
@@ -9,6 +9,11 @@ All events share a common payload:
9
9
  - `organization_sid`: The sid for the related organization
10
10
  - `domain_sid`: The sid for the related domain
11
11
  - `device`: Basic device info containing the screen type, size, touch, and orientation
12
+ - `type`: "desktop" or "mobile"
13
+ - `width`: Screen width in pixels
14
+ - `height`: Screen height in pixels
15
+ - `touch`: Whether the device uses touch controls or not
16
+ - `orientation`: "landscape-primary", "landscape-secondary", "portrait-primary", "portrait-secondary", or "undefined"
12
17
 
13
18
  Events related to titles share an additional set of data (referred to below as `Title`):
14
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playpilot/tpi",
3
- "version": "7.1.0",
3
+ "version": "7.3.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -3,6 +3,7 @@ import Explore from '../routes/components/Explore/Explore.svelte'
3
3
 
4
4
  export const exploreParentSelector = '[data-playpilot-explore]'
5
5
  export const explorePreConsentSelector = '[data-playpilot-pre-consent-explore]'
6
+ export const exploreCustomStyleId = 'playpilot-explore-custom-style'
6
7
 
7
8
  let exploreInsertedComponent: object | null = null
8
9
 
@@ -19,6 +20,8 @@ export function insertExplore(): void {
19
20
 
20
21
  target.innerHTML = ''
21
22
  exploreInsertedComponent = mount(Explore, { target })
23
+
24
+ insertExploreCustomStyle()
22
25
  }
23
26
 
24
27
  export function destroyExplore(): void {
@@ -26,6 +29,8 @@ export function destroyExplore(): void {
26
29
 
27
30
  unmount(exploreInsertedComponent)
28
31
  exploreInsertedComponent = null
32
+
33
+ document.querySelector('#' + exploreCustomStyleId)?.remove()
29
34
  }
30
35
 
31
36
  /**
@@ -37,7 +42,7 @@ export function insertExploreIntoNavigation(): boolean {
37
42
  const config = window.PlayPilotLinkInjections.config
38
43
  if (!config) return false
39
44
 
40
- const { explore_navigation_selector: selector, explore_navigation_label: label, explore_navigation_path: path, explore_navigation_insert_position: insertPosition } = window.PlayPilotLinkInjections.config
45
+ const { explore_navigation_selector: selector, explore_navigation_label: label, explore_navigation_path: path, explore_navigation_insert_position: insertPosition } = config
41
46
  if (!selector) return false
42
47
 
43
48
  // Make sure to remove an element we created if it already exists. Should not be possible under normal circumstances.
@@ -59,3 +64,16 @@ export function insertExploreIntoNavigation(): boolean {
59
64
 
60
65
  return true
61
66
  }
67
+
68
+ function insertExploreCustomStyle(): void {
69
+ const customStyleString = window.PlayPilotLinkInjections.config?.explore_custom_style
70
+
71
+ if (!customStyleString) return
72
+
73
+ const styleElement = document.createElement('style')
74
+
75
+ styleElement.textContent = customStyleString
76
+ styleElement.id = exploreCustomStyleId
77
+
78
+ document.body.appendChild(styleElement)
79
+ }
@@ -100,4 +100,5 @@ export type ConfigResponse = {
100
100
  explore_navigation_path?: string
101
101
  explore_navigation_insert_position?: InsertPosition
102
102
  explore_insert_cta_in_tpi?: boolean
103
+ explore_custom_style?: string
103
104
  }
@@ -10,6 +10,7 @@
10
10
  const { embeddable_url = '', onclose }: Props = $props()
11
11
 
12
12
  const videoId = $derived(getVideoId(embeddable_url))
13
+ const color = window?.getComputedStyle(document.body).getPropertyValue('--playpilot-primary')?.replace('#', '') || 'fa548a'
13
14
 
14
15
  // Gets the YouTube ID from a url, can be a large number of different formats
15
16
  // https://stackoverflow.com/a/54200105/1665157
@@ -23,7 +24,7 @@
23
24
 
24
25
  <div class="overlay" transition:fade={{ duration: 100 }}>
25
26
  {#if videoId}
26
- <iframe width="600" height="338" src="https://www.youtube.com/embed/{videoId}?autoplay=true" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
27
+ <iframe width="600" height="338" src="https://video.playpilot.net/?video_id={videoId}&color={color}&autoplay=true&playsinline=true&controls=play,mute,fullscreen,progress,current-time" title="YouTube video player" frameborder="0" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
27
28
  {:else}
28
29
  Something went wrong
29
30
  {/if}
@@ -16,6 +16,7 @@
16
16
  explore_navigation_selector: 'nav a:last-child',
17
17
  explore_navigation_label: 'Streaming guide',
18
18
  explore_navigation_path: '/explore',
19
+ explore_custom_style: 'main { border: 2px solid white }',
19
20
  },
20
21
  }
21
22
  }
@@ -1,6 +1,7 @@
1
1
  import { describe, it, expect, vi, beforeEach } from 'vitest'
2
- import { destroyExplore, explorePreConsentSelector, insertExplore, insertExploreIntoNavigation } from '$lib/explore'
2
+ import { destroyExplore, exploreCustomStyleId, explorePreConsentSelector, insertExplore, insertExploreIntoNavigation } from '$lib/explore'
3
3
  import { mount, unmount } from 'svelte'
4
+ import { waitFor } from '@testing-library/svelte'
4
5
  vi.mock('svelte', () => ({
5
6
  mount: vi.fn(() => true),
6
7
  unmount: vi.fn(),
@@ -49,6 +50,34 @@ describe('explore.js', () => {
49
50
 
50
51
  expect(document.querySelector(explorePreConsentSelector)).not.toBeTruthy()
51
52
  })
53
+
54
+ it('Should insert custom style tag if config object is given', async () => {
55
+ // @ts-ignore
56
+ window.PlayPilotLinkInjections = {
57
+ config: {
58
+ explore_custom_style: 'main { color: red; }',
59
+ },
60
+ }
61
+
62
+ insertExplore()
63
+
64
+ await waitFor(() => {
65
+ expect(document.querySelector('#' + exploreCustomStyleId)).toBeTruthy()
66
+ })
67
+ })
68
+
69
+ it('Should not insert custom style tag if config value is not given', async () => {
70
+ // @ts-ignore
71
+ window.PlayPilotLinkInjections = {
72
+ config: {
73
+ explore_custom_style: '',
74
+ },
75
+ }
76
+
77
+ insertExplore()
78
+
79
+ expect(document.querySelector('#' + exploreCustomStyleId)).not.toBeTruthy()
80
+ })
52
81
  })
53
82
 
54
83
  describe('destroyExplore', () => {
@@ -64,6 +93,14 @@ describe('explore.js', () => {
64
93
 
65
94
  expect(unmount).toHaveBeenCalled()
66
95
  })
96
+
97
+ it('Should remove custom style tag', () => {
98
+ document.body.innerHTML = `<script id="${exploreCustomStyleId}"></script>`
99
+
100
+ destroyExplore()
101
+
102
+ expect(document.querySelector('#' + exploreCustomStyleId)).not.toBeTruthy()
103
+ })
67
104
  })
68
105
 
69
106
  describe('insertExploreIntoNavigation', () => {
@@ -8,7 +8,7 @@ describe('YouTubeEmbedOverlay.svelte', () => {
8
8
  const { container } = render(YouTubeEmbedOverlay, { embeddable_url: 'youtube.com/watch?v=abc', onclose: () => null })
9
9
 
10
10
  // @ts-ignore
11
- expect(container.querySelector('iframe').src).toBe('https://www.youtube.com/embed/abc?autoplay=true')
11
+ expect(container.querySelector('iframe').src).toBe('https://video.playpilot.net/?video_id=abc&color=fa548a&autoplay=true&playsinline=true&controls=play,mute,fullscreen,progress,current-time')
12
12
  })
13
13
 
14
14
  it('Should render error message if embeddable_url is invalid', () => {
@@ -14,6 +14,7 @@ export default defineConfig(() => ({
14
14
  entryFileNames: 'link-injections.js',
15
15
  },
16
16
  },
17
+ chunkSizeWarningLimit: 10,
17
18
  },
18
19
 
19
20
  resolve: {
package/vite.config.js CHANGED
@@ -17,6 +17,14 @@ export default defineConfig(() => ({
17
17
 
18
18
  test: {
19
19
  environment: 'happy-dom',
20
+ environmentOptions: {
21
+ happyDOM: {
22
+ settings: {
23
+ enableJavaScriptEvaluation: true,
24
+ disableJavaScriptFileLoading: true,
25
+ },
26
+ },
27
+ },
20
28
  include: ['src/**/*.{test,spec}.{js,ts}'],
21
29
  setupFiles: ['src/tests/setup.js'],
22
30
  },