feat: add support for the Web Share Target API (#1100)

Co-authored-by: userquin <userquin@gmail.com>
This commit is contained in:
Horváth Bálint 2023-01-14 21:58:52 +01:00 committed by GitHub
parent a6a825e553
commit bede92404b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 221 additions and 7 deletions

View file

@ -5,12 +5,30 @@ import { getEnv } from '../../config/env'
import { i18n } from '../../config/i18n'
import type { LocaleObject } from '#i18n'
export type LocalizedWebManifest = Record<string, Partial<ManifestOptions>>
// We have to extend the ManifestOptions interface from 'vite-plugin-pwa'
// as that interface doesn't define the share_target field of Web App Manifests.
interface ExtendedManifestOptions extends ManifestOptions {
share_target: {
action: string
method: string
enctype: string
params: {
text: string
url: string
files: [{
name: string
accept: string[]
}]
}
}
}
export type LocalizedWebManifest = Record<string, Partial<ExtendedManifestOptions>>
export const pwaLocales = i18n.locales as LocaleObject[]
type WebManifestEntry = Pick<ManifestOptions, 'name' | 'short_name' | 'description'>
type RequiredWebManifestEntry = Required<WebManifestEntry & Pick<ManifestOptions, 'dir' | 'lang'>>
type WebManifestEntry = Pick<ExtendedManifestOptions, 'name' | 'short_name' | 'description'>
type RequiredWebManifestEntry = Required<WebManifestEntry & Pick<ExtendedManifestOptions, 'dir' | 'lang'>>
export const createI18n = async (): Promise<LocalizedWebManifest> => {
const { env } = await getEnv()
@ -73,6 +91,21 @@ export const createI18n = async (): Promise<LocalizedWebManifest> => {
type: 'image/png',
},
],
share_target: {
action: '/web-share-target',
method: 'POST',
enctype: 'multipart/form-data',
params: {
text: 'text',
url: 'text',
files: [
{
name: 'files',
accept: ['image/*', 'video/*'],
},
],
},
},
}
acc[`${lang}-dark`] = {
scope: '/',
@ -98,6 +131,21 @@ export const createI18n = async (): Promise<LocalizedWebManifest> => {
type: 'image/png',
},
],
share_target: {
action: '/web-share-target',
method: 'POST',
enctype: 'multipart/form-data',
params: {
text: 'text',
url: 'text',
files: [
{
name: 'files',
accept: ['image/*', 'video/*'],
},
],
},
},
}
return acc