diff --git a/playground/pages/index.vue b/playground/pages/index.vue index 618e299d..7d419c38 100644 --- a/playground/pages/index.vue +++ b/playground/pages/index.vue @@ -34,6 +34,14 @@ const thirdParties = [ name: 'Segment', path: '/third-parties/segment', }, + { + name: 'Vimeo', + path: '/third-parties/vimeo', + }, + { + name: 'Vimeo component', + path: '/third-parties/vimeo-component', + }, ] const features = [ diff --git a/playground/pages/third-parties/vimeo-component.vue b/playground/pages/third-parties/vimeo-component.vue new file mode 100644 index 00000000..c5e56670 --- /dev/null +++ b/playground/pages/third-parties/vimeo-component.vue @@ -0,0 +1,16 @@ + + + \ No newline at end of file diff --git a/playground/pages/third-parties/vimeo.vue b/playground/pages/third-parties/vimeo.vue new file mode 100644 index 00000000..155301ab --- /dev/null +++ b/playground/pages/third-parties/vimeo.vue @@ -0,0 +1,20 @@ + + + \ No newline at end of file diff --git a/src/module.ts b/src/module.ts index 10a3f941..a128f9eb 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1,5 +1,6 @@ import { addBuildPlugin, + addComponentsDir, addImports, addImportsDir, addPlugin, @@ -106,6 +107,10 @@ export default defineNuxtModule({ resolve('./runtime/composables'), ]) + addComponentsDir({ + path: resolve('./runtime/components') + }) + nuxt.hooks.hook('modules:done', async () => { let registry: RegistryScripts = [ { @@ -148,6 +153,11 @@ export default defineNuxtModule({ }) }, }, + { + name: 'useScriptVimeo', + from: resolve('./runtime/registry/vimeo'), + key: 'vimeo', + }, { name: 'useScriptIntercom', from: resolve('./runtime/registry/intercom'), diff --git a/src/runtime/components/VimeoEmbed.vue b/src/runtime/components/VimeoEmbed.vue new file mode 100644 index 00000000..ddedbebd --- /dev/null +++ b/src/runtime/components/VimeoEmbed.vue @@ -0,0 +1,162 @@ + + + diff --git a/src/runtime/registry/vimeo.ts b/src/runtime/registry/vimeo.ts new file mode 100644 index 00000000..35b15439 --- /dev/null +++ b/src/runtime/registry/vimeo.ts @@ -0,0 +1,40 @@ +import { type Input, object, string } from 'valibot' +import { useScript } from '#imports' +import type { NuxtUseScriptOptions } from '#nuxt-scripts' + +export interface VimeoScriptApi { + Player: any +} + +export const VimeoScriptOptions = object({}) + +export type VimeoPlayer = ((...params: any[]) => void) | undefined + +export type VimeoScriptInput = Input + +declare global { + interface Window { + Vimeo: VimeoScriptApi + } +} + +export function useScriptVimeo(options?: VimeoScriptInput, _scriptOptions?: Omit, 'beforeInit' | 'use'>) { + const scriptOptions: NuxtUseScriptOptions = _scriptOptions || {} + + return useScript({ + key: 'vimeo', + src: 'https://player.vimeo.com/api/player.js', + ...options, + }, { + ...scriptOptions, + use: () => { + let Player: VimeoPlayer + if (import.meta.client) { + Player = function (...params: any[]) { + return new window.Vimeo.Player(...params) + } + } + return { Player } + }, + }) +}