Skip to content

Commit 00804a2

Browse files
Merge pull request #5 from JSON-ms/dev
Support for Youtube videos
2 parents 8744ce9 + 9aadad9 commit 00804a2

4 files changed

Lines changed: 89 additions & 24 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@jsonms/demo",
33
"private": true,
44
"type": "module",
5-
"version": "0.1.10",
5+
"version": "0.1.11",
66
"scripts": {
77
"dev": "vite",
88
"build": "run-p type-check \"build-only {@}\" --",

src/components/Carousels.vue

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<v-carousel
44
v-model="slide"
55
:continuous="false"
6-
:show-arrows="false"
7-
:hide-delimiters="data.home.presentation.length <= 1"
6+
:show-arrows="true"
7+
:hide-delimiters="true"
88
hide-delimiter-background
99
height="100%"
1010
>
@@ -22,7 +22,17 @@
2222
v-for="(presentation, presentationIdx) in data.home.presentation"
2323
:key="presentation.hash"
2424
>
25-
<div style="max-width: 66%; margin: 0 auto" class="d-flex flex-column fill-height justify-center align-center text-center">
25+
<div v-if="data.home.presentation[slide].type === 'youtube'" class="youtube-responsive">
26+
<iframe
27+
:src="getYoutubeUrl(presentation)"
28+
title="YouTube video player"
29+
frameborder="0"
30+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; web-share"
31+
referrerpolicy="strict-origin-when-cross-origin"
32+
allowfullscreen
33+
/>
34+
</div>
35+
<div v-else-if="presentation.type === 'text'" style="max-width: 66%; margin: 0 auto" class="d-flex flex-column fill-height justify-center align-center text-center">
2636
<div class="text-h5 text-sm-h4 mt-4">
2737
{{ presentation.title[locale] || 'Undefined' }}
2838
</div>
@@ -45,6 +55,7 @@
4555

4656
<script setup lang="ts">
4757
import {useJsonMs} from "@/plugins/jsonms";
58+
import type {JmsHomePresentationItems} from "@/jms/typings";
4859
4960
const slide = ref(0);
5061
const { data, locale } = useJsonMs();
@@ -63,6 +74,25 @@ const slideColor = computed((): string => {
6374
return data.value.home.presentation[slide.value].color || 'primary';
6475
})
6576
77+
function getYoutubeUrl(presentation: JmsHomePresentationItems) {
78+
if (presentation.youtube) {
79+
const code = getYoutubeCode(presentation.youtube);
80+
return 'https://www.youtube.com/embed/' + code + '?controls=0';
81+
}
82+
}
83+
84+
const getYoutubeCode = (url: string): string | null => {
85+
try {
86+
const u = new URL(url)
87+
if (u.hostname.includes('youtu.be')) return u.pathname.slice(1) || null
88+
if (u.searchParams.has('v')) return u.searchParams.get('v')
89+
if (u.pathname.startsWith('/embed/')) return u.pathname.split('/embed/')[1]
90+
return null
91+
} catch {
92+
return null
93+
}
94+
}
95+
6696
watch(() => slide.value, () => {
6797
if (data.value.home.presentation[slide.value]) {
6898
window.parent.postMessage({
@@ -73,3 +103,16 @@ watch(() => slide.value, () => {
73103
}
74104
})
75105
</script>
106+
107+
<style lang="scss" scoped>
108+
.youtube-responsive iframe {
109+
position: absolute;
110+
inset: 0;
111+
min-width: 100vw;
112+
height: 100vh;
113+
border: 0;
114+
left: 50%;
115+
top: 50%;
116+
transform: translate(-50%, -50%);
117+
}
118+
</style>

src/jms/default.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,46 @@ export const defaultData: JmsData = {
1111
},
1212
"playground": {
1313
"text": null,
14-
"textWithIcon": "This is a default value",
14+
"textWithIcon": null,
15+
"textDefault": "A default value",
1516
"i18nRequired": {
1617
"en-US": "",
1718
"es-MX": ""
1819
},
1920
"i18nTextarea": {
20-
"en-US": "",
21-
"es-MX": ""
21+
"en-US": null,
22+
"es-MX": null
2223
},
24+
"textRules": null,
2325
"i18nRating": null,
2426
"conditionalSwitch": null,
25-
"hiddenField1": null,
26-
"hiddenField2": null,
27+
"hiddenField1": 50,
28+
"hiddenField2": [
29+
25,
30+
75
31+
],
2732
"list": {
2833
"select": null,
2934
"radio": null,
3035
"checkbox": []
3136
},
3237
"arrays": {
3338
"array": [],
34-
"i18nArray": []
39+
"i18nArray": {
40+
"en-US": [],
41+
"es-MX": []
42+
}
3543
},
3644
"files": {
3745
"file": null,
3846
"acceptImages": null,
3947
"multiple": []
4048
},
4149
"markdown": null,
42-
"date": null
50+
"date": null,
51+
"schema": {
52+
"title": "",
53+
"description": null
54+
}
4355
}
4456
}

src/jms/typings.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export type JmsLocaleKey = 'en-US' | 'es-MX'
22

33
export type JmsSectionKey = 'home' | 'playground'
44

5-
export type JmsEnumColors = 'primary' | 'secondary'
5+
export type JmsEnumColors = 'primary' | 'secondary' | 'white'
66

77
export type JmsEnumGender = 'male' | 'female'
88

@@ -27,17 +27,19 @@ export interface JmsFile {
2727
meta: JmsFileMeta
2828
}
2929

30-
export interface JmsHomePresentationItems {
31-
title: JmsLocaleSet<string>
32-
body: JmsLocaleSet<string | null>
33-
cta: JmsLocaleSet<string>
30+
export interface JmsHomePresentationItem {
31+
type: 'text' | 'youtube'
32+
title: JmsLocaleSet<string> | null
33+
youtube: string | null
34+
body: JmsLocaleSet<string | null> | null
35+
cta: JmsLocaleSet<string> | null
3436
color: JmsEnumColors
3537
commands: ('openDrawer' | 'closeDrawer' | 'openAdvanced' | 'closeAdvanced' | 'showData' | 'showSettings' | 'showDocs' | 'setMobile' | 'setDesktop' | 'hideDevice')[]
3638
hash: string
3739
}
3840

3941
export interface JmsHome {
40-
presentation: JmsHomePresentationItems[]
42+
presentation: JmsHomePresentationItem[]
4143
}
4244

4345
export interface JmsPlaygroundList {
@@ -46,22 +48,22 @@ export interface JmsPlaygroundList {
4648
checkbox: JmsEnumGender[]
4749
}
4850

49-
export interface JmsPlaygroundArraysArrayItems {
51+
export interface JmsPlaygroundArraysArrayItem {
5052
firstName: string | null
5153
lastName: string | null
5254
gender: JmsEnumGender | null
5355
picture: JmsFile | null
5456
hash: string
5557
}
5658

57-
export interface JmsPlaygroundArraysI18nArrayItems {
59+
export interface JmsPlaygroundArraysI18nArrayItem {
5860
title: string | null
5961
hash: string
6062
}
6163

6264
export interface JmsPlaygroundArrays {
63-
array: JmsPlaygroundArraysArrayItems[]
64-
i18nArray: JmsLocaleSet<JmsPlaygroundArraysI18nArrayItems[]>
65+
array: JmsPlaygroundArraysArrayItem[]
66+
i18nArray: JmsLocaleSet<JmsPlaygroundArraysI18nArrayItem[]>
6567
}
6668

6769
export interface JmsPlaygroundFiles {
@@ -70,12 +72,19 @@ export interface JmsPlaygroundFiles {
7072
multiple: JmsFile[]
7173
}
7274

75+
export interface JmsPlaygroundSchema {
76+
title: string
77+
description: string | null
78+
}
79+
7380
export interface JmsPlayground {
7481
text: string | null
7582
textWithIcon: string | null
76-
i18nRequired: JmsLocaleSet<string>
77-
i18nTextarea: JmsLocaleSet<string | null>
78-
i18nRating: JmsLocaleSet<number | null>
83+
textDefault: string | null
84+
i18nRequired: JmsLocaleSet<string> | null
85+
i18nTextarea: JmsLocaleSet<string | null> | null
86+
textRules: string | null
87+
i18nRating: JmsLocaleSet<number | null> | null
7988
conditionalSwitch: undefined | null
8089
hiddenField1: number | null
8190
hiddenField2: [number, number] | null
@@ -84,6 +93,7 @@ export interface JmsPlayground {
8493
files: JmsPlaygroundFiles
8594
markdown: string | null
8695
date: Date | null
96+
schema: JmsPlaygroundSchema
8797
}
8898

8999
export interface JmsData {

0 commit comments

Comments
 (0)