@playpilot/tpi 8.35.0-beta.1 → 8.35.1
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/editorial.mount.js +10 -11
- package/dist/link-injections.js +2 -2
- package/dist/mount.css +1 -0
- package/dist/mount.js +8 -9
- package/package.json +1 -1
- package/src/main.ts +24 -3
- package/src/tests/main.test.js +2 -1
- package/vite._mount.config.js +1 -3
package/package.json
CHANGED
package/src/main.ts
CHANGED
|
@@ -83,17 +83,38 @@ window.PlayPilotLinkInjections ||= {
|
|
|
83
83
|
},
|
|
84
84
|
|
|
85
85
|
mount(): void {
|
|
86
|
+
const scriptId = 'playpilot-mount'
|
|
87
|
+
const styleId = 'playpilot-mount-style'
|
|
88
|
+
|
|
89
|
+
const ondoubleload = (event: Event): void => {
|
|
90
|
+
if (!event.target) return
|
|
91
|
+
|
|
92
|
+
(event.target as HTMLElement).dataset.loaded = 'true'
|
|
93
|
+
|
|
94
|
+
if (document.getElementById(scriptId)?.dataset.loaded !== 'true' || document.getElementById(styleId)?.dataset.loaded !== 'true') return
|
|
95
|
+
|
|
96
|
+
window.PlayPilotMount?.mount()
|
|
97
|
+
}
|
|
98
|
+
|
|
86
99
|
const shouldLoadEditorial = isEditorialModeEnabled() || getAuthToken()
|
|
87
100
|
|
|
88
101
|
const script = document.createElement('script')
|
|
89
|
-
|
|
90
|
-
script.id = 'playpilot-mount'
|
|
102
|
+
script.id = scriptId
|
|
91
103
|
script.src = `${cdnBaseUrl}/dist/${shouldLoadEditorial ? 'editorial.' : ''}mount.js`
|
|
92
104
|
// script.src = './dist/mount.js' // Use me during development of this script
|
|
105
|
+
script.defer = true
|
|
106
|
+
script.onload = ondoubleload
|
|
93
107
|
|
|
94
|
-
|
|
108
|
+
const style = document.createElement('link')
|
|
109
|
+
style.id = styleId
|
|
110
|
+
style.rel = 'stylesheet'
|
|
111
|
+
style.type = 'text/css'
|
|
112
|
+
style.href = `${cdnBaseUrl}/dist/mount.css`
|
|
113
|
+
// style.href = './dist/mount.css' // Use me during development of this script
|
|
114
|
+
style.onload = ondoubleload
|
|
95
115
|
|
|
96
116
|
document.body.appendChild(script)
|
|
117
|
+
document.head.appendChild(style)
|
|
97
118
|
},
|
|
98
119
|
}
|
|
99
120
|
|
package/src/tests/main.test.js
CHANGED
|
@@ -113,10 +113,11 @@ describe('main.ts', () => {
|
|
|
113
113
|
})
|
|
114
114
|
|
|
115
115
|
describe('mount', () => {
|
|
116
|
-
it('Should insert script
|
|
116
|
+
it('Should insert both script and style tags', () => {
|
|
117
117
|
window.PlayPilotLinkInjections.mount()
|
|
118
118
|
|
|
119
119
|
expect(document.querySelector('script#playpilot-mount')).toBeTruthy()
|
|
120
|
+
expect(document.querySelector('link#playpilot-mount-style')).toBeTruthy()
|
|
120
121
|
})
|
|
121
122
|
|
|
122
123
|
it('Should insert script tag with editorial mode if editiorial mode is enabled', () => {
|
package/vite._mount.config.js
CHANGED
|
@@ -2,7 +2,6 @@ import path from 'path'
|
|
|
2
2
|
import * as dotenv from 'dotenv'
|
|
3
3
|
import { defineConfig } from 'vitest/config'
|
|
4
4
|
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
|
5
|
-
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
|
|
6
5
|
import packageJson from './package.json'
|
|
7
6
|
|
|
8
7
|
dotenv.config({ path: '.env' })
|
|
@@ -13,7 +12,6 @@ export default defineConfig(({ mode }) => {
|
|
|
13
12
|
return {
|
|
14
13
|
plugins: [
|
|
15
14
|
svelte(),
|
|
16
|
-
cssInjectedByJsPlugin(),
|
|
17
15
|
injectEnvVariables,
|
|
18
16
|
],
|
|
19
17
|
|
|
@@ -22,9 +20,9 @@ export default defineConfig(({ mode }) => {
|
|
|
22
20
|
rollupOptions: {
|
|
23
21
|
input: './src/mount.ts',
|
|
24
22
|
output: {
|
|
25
|
-
format: 'iife',
|
|
26
23
|
name: 'PlayPilotMount',
|
|
27
24
|
entryFileNames: isEditiorial ? 'editorial.mount.js' : 'mount.js',
|
|
25
|
+
assetFileNames: (assetInfo) => assetInfo.name,
|
|
28
26
|
},
|
|
29
27
|
},
|
|
30
28
|
},
|