@elementor/wp-media 4.0.0-607 → 4.0.0-619
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/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/hooks/use-wp-media-frame.ts +15 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -165,10 +165,23 @@ function handleExtensions(frame, mediaTypes) {
|
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
var imageExtensions = ["avif", "bmp", "gif", "ico", "jpe", "jpeg", "jpg", "png", "webp"];
|
|
168
|
+
var videoExtensions = ["mp4", "webm", "ogg", "mov", "m4v", "avi", "wmv", "mpg", "mpeg", "3gp", "3g2"];
|
|
168
169
|
function getMimeTypes(mediaTypes) {
|
|
169
170
|
const mimeTypesPerType = {
|
|
170
171
|
image: imageExtensions.map((extension) => `image/${extension}`),
|
|
171
|
-
svg: ["image/svg+xml"]
|
|
172
|
+
svg: ["image/svg+xml"],
|
|
173
|
+
video: [
|
|
174
|
+
"video/mp4",
|
|
175
|
+
"video/webm",
|
|
176
|
+
"video/ogg",
|
|
177
|
+
"video/quicktime",
|
|
178
|
+
"video/x-m4v",
|
|
179
|
+
"video/avi",
|
|
180
|
+
"video/x-ms-wmv",
|
|
181
|
+
"video/mpeg",
|
|
182
|
+
"video/3gpp",
|
|
183
|
+
"video/3gpp2"
|
|
184
|
+
]
|
|
172
185
|
};
|
|
173
186
|
return mediaTypes.reduce((prev, currentType) => {
|
|
174
187
|
return prev.concat(mimeTypesPerType[currentType]);
|
|
@@ -177,7 +190,8 @@ function getMimeTypes(mediaTypes) {
|
|
|
177
190
|
function getExtensions(mediaTypes) {
|
|
178
191
|
const extensionsPerType = {
|
|
179
192
|
image: imageExtensions,
|
|
180
|
-
svg: ["svg"]
|
|
193
|
+
svg: ["svg"],
|
|
194
|
+
video: videoExtensions
|
|
181
195
|
};
|
|
182
196
|
const extensions = mediaTypes.reduce((prev, currentType) => {
|
|
183
197
|
return prev.concat(extensionsPerType[currentType]);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/hooks/use-wp-media-attachment.ts","../src/errors.ts","../src/media.ts","../src/normalize.ts","../src/get-media-attachment.ts","../src/hooks/use-wp-media-frame.ts","../src/wp-plupload-settings.ts"],"sourcesContent":["export type { Attachment } from './types/attachment';\nexport type { OpenOptions, MediaType } from './hooks/use-wp-media-frame';\n\nexport { default as useWpMediaAttachment } from './hooks/use-wp-media-attachment';\nexport { default as useWpMediaFrame } from './hooks/use-wp-media-frame';\n\nexport { getMediaAttachment } from './get-media-attachment';\n","import { useQuery } from '@elementor/query';\n\nimport { getMediaAttachment } from '../get-media-attachment';\n\nexport default function useWpMediaAttachment( id: number | null ) {\n\treturn useQuery( {\n\t\tqueryKey: [ 'wp-attachment', id ],\n\t\tqueryFn: () => getMediaAttachment( { id } ),\n\t\tenabled: !! id,\n\t} );\n}\n","import { createError } from '@elementor/utils';\n\nexport const WpMediaNotAvailableError = createError( {\n\tcode: 'wp_media_not_available',\n\tmessage: '`wp.media` is not available, make sure the `media-models` handle is set in the dependencies array',\n} );\n\nexport const WpPluploadSettingsNotAvailableError = createError( {\n\tcode: 'wp_plupload_settings_not_available',\n\tmessage: '`_wpPluploadSettings` is not available, make sure a wp media uploader is open',\n} );\n","import { WpMediaNotAvailableError } from './errors';\nimport { type WpMediaWindow } from './types/wp-media';\n\nconst wpMediaWindow = window as unknown as WpMediaWindow;\n\nexport default () => {\n\tif ( ! wpMediaWindow.wp?.media ) {\n\t\tthrow new WpMediaNotAvailableError();\n\t}\n\n\treturn wpMediaWindow.wp.media;\n};\n","import { type Attachment } from './types/attachment';\nimport { type WpAttachmentJSON } from './types/wp-media';\n\nexport default function normalize( attachment: WpAttachmentJSON ): Attachment {\n\tconst { filesizeInBytes, filesizeHumanReadable, author, authorName, ...rest } = attachment;\n\n\treturn {\n\t\t...rest,\n\t\tfilesize: {\n\t\t\tinBytes: filesizeInBytes,\n\t\t\thumanReadable: filesizeHumanReadable,\n\t\t},\n\t\tauthor: {\n\t\t\tid: parseInt( author ),\n\t\t\tname: authorName,\n\t\t},\n\t};\n}\n","import media from './media';\nimport normalize from './normalize';\n\nexport async function getMediaAttachment( { id }: { id: number | null } ) {\n\tif ( ! id ) {\n\t\treturn null;\n\t}\n\n\tconst model = media().attachment( id );\n\tconst wpAttachment = model.toJSON();\n\n\tconst isFetched = 'url' in wpAttachment;\n\n\tif ( isFetched ) {\n\t\treturn normalize( wpAttachment );\n\t}\n\n\ttry {\n\t\treturn normalize( await model.fetch() );\n\t} catch {\n\t\treturn null;\n\t}\n}\n","import { useEffect, useRef } from 'react';\n\nimport media from '../media';\nimport normalize from '../normalize';\nimport { type Attachment } from '../types/attachment';\nimport { type MediaFrame } from '../types/wp-media';\nimport wpPluploadSettings from '../wp-plupload-settings';\n\nexport type OpenOptions = {\n\tmode?: 'upload' | 'browse';\n};\n\nexport type MediaType = 'image' | 'svg';\n\ntype Options = {\n\tmediaTypes: MediaType[];\n\ttitle?: string;\n} & (\n\t| {\n\t\t\tmultiple: true;\n\t\t\tselected: Array< number | null >;\n\t\t\tonSelect: ( val: Attachment[] ) => void;\n\t }\n\t| {\n\t\t\tmultiple: false;\n\t\t\tselected: number | null;\n\t\t\tonSelect: ( val: Attachment ) => void;\n\t }\n);\n\nexport default function useWpMediaFrame( options: Options ) {\n\tconst frame = useRef< MediaFrame >();\n\n\tconst open = ( openOptions: OpenOptions = {} ) => {\n\t\tcleanupFrame( frame.current );\n\n\t\tframe.current = createFrame( { ...options, ...openOptions } );\n\n\t\tframe.current?.open();\n\t};\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tcleanupFrame( frame.current );\n\t\t};\n\t}, [] );\n\n\treturn {\n\t\topen,\n\t};\n}\n\nfunction createFrame( { onSelect, multiple, mediaTypes, selected, title, mode = 'browse' }: Options & OpenOptions ) {\n\tconst frame: MediaFrame = media()( {\n\t\ttitle,\n\t\tmultiple,\n\t\tlibrary: {\n\t\t\ttype: getMimeTypes( mediaTypes ),\n\t\t},\n\t} )\n\t\t.on( 'open', () => {\n\t\t\tsetTypeCaller( frame );\n\t\t\tapplyMode( frame, mode );\n\t\t\tapplySelection( frame, selected );\n\t\t} )\n\t\t.on( 'close', () => cleanupFrame( frame ) )\n\t\t.on( 'insert select', () => select( frame, multiple, onSelect ) );\n\n\thandleExtensions( frame, mediaTypes );\n\n\treturn frame;\n}\n\nfunction cleanupFrame( frame?: MediaFrame ) {\n\tframe?.detach();\n\tframe?.remove();\n}\n\nfunction applyMode( frame: MediaFrame, mode: OpenOptions[ 'mode' ] = 'browse' ) {\n\tframe.content.mode( mode );\n}\n\nfunction applySelection( frame: MediaFrame, selected: number | null | Array< number | null > ) {\n\tconst selectedAttachments = ( typeof selected === 'number' ? [ selected ] : selected )\n\t\t?.filter( ( id ) => !! id )\n\t\t.map( ( id ) => media().attachment( id as number ) );\n\n\tframe\n\t\t.state()\n\t\t.get( 'selection' )\n\t\t.set( selectedAttachments || [] );\n}\n\nfunction select( frame: MediaFrame, multiple: boolean, onSelect: Options[ 'onSelect' ] ) {\n\tconst attachments = frame.state().get( 'selection' ).toJSON().map( normalize );\n\n\tconst onSelectFn = onSelect as ( val: Attachment | Attachment[] ) => void;\n\n\tonSelectFn( multiple ? attachments : attachments[ 0 ] );\n}\n\nfunction setTypeCaller( frame: MediaFrame ) {\n\tframe.uploader.uploader.param( 'uploadTypeCaller', 'elementor-wp-media-upload' );\n}\n\nfunction handleExtensions( frame: MediaFrame, mediaTypes: MediaType[] ) {\n\tconst defaultExtensions = wpPluploadSettings().defaults.filters.mime_types?.[ 0 ]?.extensions;\n\n\t// Set extensions by media types\n\tframe.on( 'ready', () => {\n\t\twpPluploadSettings().defaults.filters.mime_types = [ { extensions: getExtensions( mediaTypes ) } ];\n\t} );\n\n\t// Restore default upload extensions\n\tframe.on( 'close', () => {\n\t\twpPluploadSettings().defaults.filters.mime_types = defaultExtensions\n\t\t\t? [ { extensions: defaultExtensions } ]\n\t\t\t: [];\n\t} );\n}\n\nconst imageExtensions = [ 'avif', 'bmp', 'gif', 'ico', 'jpe', 'jpeg', 'jpg', 'png', 'webp' ];\n\nfunction getMimeTypes( mediaTypes: MediaType[] ) {\n\tconst mimeTypesPerType: Record< MediaType, string[] > = {\n\t\timage: imageExtensions.map( ( extension ) => `image/${ extension }` ),\n\t\tsvg: [ 'image/svg+xml' ],\n\t};\n\n\treturn mediaTypes.reduce( ( prev, currentType ) => {\n\t\treturn prev.concat( mimeTypesPerType[ currentType ] );\n\t}, [] as string[] );\n}\n\nfunction getExtensions( mediaTypes: MediaType[] ) {\n\tconst extensionsPerType: Record< MediaType, string[] > = {\n\t\timage: imageExtensions,\n\t\tsvg: [ 'svg' ],\n\t};\n\n\tconst extensions = mediaTypes.reduce( ( prev, currentType ) => {\n\t\treturn prev.concat( extensionsPerType[ currentType ] );\n\t}, [] as string[] );\n\n\treturn extensions.join( ',' );\n}\n","import { WpPluploadSettingsNotAvailableError } from './errors';\nimport { type WpPluploadSettingsWindow } from './types/plupload';\n\nconst wpPluploadSettingsWindow = window as unknown as WpPluploadSettingsWindow;\n\nexport default () => {\n\tif ( ! wpPluploadSettingsWindow._wpPluploadSettings ) {\n\t\tthrow new WpPluploadSettingsNotAvailableError();\n\t}\n\n\treturn wpPluploadSettingsWindow._wpPluploadSettings;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyB;;;ACAzB,mBAA4B;AAErB,IAAM,+BAA2B,0BAAa;AAAA,EACpD,MAAM;AAAA,EACN,SAAS;AACV,CAAE;AAEK,IAAM,0CAAsC,0BAAa;AAAA,EAC/D,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}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/hooks/use-wp-media-attachment.ts","../src/errors.ts","../src/media.ts","../src/normalize.ts","../src/get-media-attachment.ts","../src/hooks/use-wp-media-frame.ts","../src/wp-plupload-settings.ts"],"sourcesContent":["export type { Attachment } from './types/attachment';\nexport type { OpenOptions, MediaType } from './hooks/use-wp-media-frame';\n\nexport { default as useWpMediaAttachment } from './hooks/use-wp-media-attachment';\nexport { default as useWpMediaFrame } from './hooks/use-wp-media-frame';\n\nexport { getMediaAttachment } from './get-media-attachment';\n","import { useQuery } from '@elementor/query';\n\nimport { getMediaAttachment } from '../get-media-attachment';\n\nexport default function useWpMediaAttachment( id: number | null ) {\n\treturn useQuery( {\n\t\tqueryKey: [ 'wp-attachment', id ],\n\t\tqueryFn: () => getMediaAttachment( { id } ),\n\t\tenabled: !! id,\n\t} );\n}\n","import { createError } from '@elementor/utils';\n\nexport const WpMediaNotAvailableError = createError( {\n\tcode: 'wp_media_not_available',\n\tmessage: '`wp.media` is not available, make sure the `media-models` handle is set in the dependencies array',\n} );\n\nexport const WpPluploadSettingsNotAvailableError = createError( {\n\tcode: 'wp_plupload_settings_not_available',\n\tmessage: '`_wpPluploadSettings` is not available, make sure a wp media uploader is open',\n} );\n","import { WpMediaNotAvailableError } from './errors';\nimport { type WpMediaWindow } from './types/wp-media';\n\nconst wpMediaWindow = window as unknown as WpMediaWindow;\n\nexport default () => {\n\tif ( ! wpMediaWindow.wp?.media ) {\n\t\tthrow new WpMediaNotAvailableError();\n\t}\n\n\treturn wpMediaWindow.wp.media;\n};\n","import { type Attachment } from './types/attachment';\nimport { type WpAttachmentJSON } from './types/wp-media';\n\nexport default function normalize( attachment: WpAttachmentJSON ): Attachment {\n\tconst { filesizeInBytes, filesizeHumanReadable, author, authorName, ...rest } = attachment;\n\n\treturn {\n\t\t...rest,\n\t\tfilesize: {\n\t\t\tinBytes: filesizeInBytes,\n\t\t\thumanReadable: filesizeHumanReadable,\n\t\t},\n\t\tauthor: {\n\t\t\tid: parseInt( author ),\n\t\t\tname: authorName,\n\t\t},\n\t};\n}\n","import media from './media';\nimport normalize from './normalize';\n\nexport async function getMediaAttachment( { id }: { id: number | null } ) {\n\tif ( ! id ) {\n\t\treturn null;\n\t}\n\n\tconst model = media().attachment( id );\n\tconst wpAttachment = model.toJSON();\n\n\tconst isFetched = 'url' in wpAttachment;\n\n\tif ( isFetched ) {\n\t\treturn normalize( wpAttachment );\n\t}\n\n\ttry {\n\t\treturn normalize( await model.fetch() );\n\t} catch {\n\t\treturn null;\n\t}\n}\n","import { useEffect, useRef } from 'react';\n\nimport media from '../media';\nimport normalize from '../normalize';\nimport { type Attachment } from '../types/attachment';\nimport { type MediaFrame } from '../types/wp-media';\nimport wpPluploadSettings from '../wp-plupload-settings';\n\nexport type OpenOptions = {\n\tmode?: 'upload' | 'browse';\n};\n\nexport type MediaType = 'image' | 'svg' | 'video';\n\ntype Options = {\n\tmediaTypes: MediaType[];\n\ttitle?: string;\n} & (\n\t| {\n\t\t\tmultiple: true;\n\t\t\tselected: Array< number | null >;\n\t\t\tonSelect: ( val: Attachment[] ) => void;\n\t }\n\t| {\n\t\t\tmultiple: false;\n\t\t\tselected: number | null;\n\t\t\tonSelect: ( val: Attachment ) => void;\n\t }\n);\n\nexport default function useWpMediaFrame( options: Options ) {\n\tconst frame = useRef< MediaFrame >();\n\n\tconst open = ( openOptions: OpenOptions = {} ) => {\n\t\tcleanupFrame( frame.current );\n\n\t\tframe.current = createFrame( { ...options, ...openOptions } );\n\n\t\tframe.current?.open();\n\t};\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tcleanupFrame( frame.current );\n\t\t};\n\t}, [] );\n\n\treturn {\n\t\topen,\n\t};\n}\n\nfunction createFrame( { onSelect, multiple, mediaTypes, selected, title, mode = 'browse' }: Options & OpenOptions ) {\n\tconst frame: MediaFrame = media()( {\n\t\ttitle,\n\t\tmultiple,\n\t\tlibrary: {\n\t\t\ttype: getMimeTypes( mediaTypes ),\n\t\t},\n\t} )\n\t\t.on( 'open', () => {\n\t\t\tsetTypeCaller( frame );\n\t\t\tapplyMode( frame, mode );\n\t\t\tapplySelection( frame, selected );\n\t\t} )\n\t\t.on( 'close', () => cleanupFrame( frame ) )\n\t\t.on( 'insert select', () => select( frame, multiple, onSelect ) );\n\n\thandleExtensions( frame, mediaTypes );\n\n\treturn frame;\n}\n\nfunction cleanupFrame( frame?: MediaFrame ) {\n\tframe?.detach();\n\tframe?.remove();\n}\n\nfunction applyMode( frame: MediaFrame, mode: OpenOptions[ 'mode' ] = 'browse' ) {\n\tframe.content.mode( mode );\n}\n\nfunction applySelection( frame: MediaFrame, selected: number | null | Array< number | null > ) {\n\tconst selectedAttachments = ( typeof selected === 'number' ? [ selected ] : selected )\n\t\t?.filter( ( id ) => !! id )\n\t\t.map( ( id ) => media().attachment( id as number ) );\n\n\tframe\n\t\t.state()\n\t\t.get( 'selection' )\n\t\t.set( selectedAttachments || [] );\n}\n\nfunction select( frame: MediaFrame, multiple: boolean, onSelect: Options[ 'onSelect' ] ) {\n\tconst attachments = frame.state().get( 'selection' ).toJSON().map( normalize );\n\n\tconst onSelectFn = onSelect as ( val: Attachment | Attachment[] ) => void;\n\n\tonSelectFn( multiple ? attachments : attachments[ 0 ] );\n}\n\nfunction setTypeCaller( frame: MediaFrame ) {\n\tframe.uploader.uploader.param( 'uploadTypeCaller', 'elementor-wp-media-upload' );\n}\n\nfunction handleExtensions( frame: MediaFrame, mediaTypes: MediaType[] ) {\n\tconst defaultExtensions = wpPluploadSettings().defaults.filters.mime_types?.[ 0 ]?.extensions;\n\n\t// Set extensions by media types\n\tframe.on( 'ready', () => {\n\t\twpPluploadSettings().defaults.filters.mime_types = [ { extensions: getExtensions( mediaTypes ) } ];\n\t} );\n\n\t// Restore default upload extensions\n\tframe.on( 'close', () => {\n\t\twpPluploadSettings().defaults.filters.mime_types = defaultExtensions\n\t\t\t? [ { extensions: defaultExtensions } ]\n\t\t\t: [];\n\t} );\n}\n\nconst imageExtensions = [ 'avif', 'bmp', 'gif', 'ico', 'jpe', 'jpeg', 'jpg', 'png', 'webp' ];\nconst videoExtensions = [ 'mp4', 'webm', 'ogg', 'mov', 'm4v', 'avi', 'wmv', 'mpg', 'mpeg', '3gp', '3g2' ];\n\nfunction getMimeTypes( mediaTypes: MediaType[] ) {\n\tconst mimeTypesPerType: Record< MediaType, string[] > = {\n\t\timage: imageExtensions.map( ( extension ) => `image/${ extension }` ),\n\t\tsvg: [ 'image/svg+xml' ],\n\t\tvideo: [\n\t\t\t'video/mp4',\n\t\t\t'video/webm',\n\t\t\t'video/ogg',\n\t\t\t'video/quicktime',\n\t\t\t'video/x-m4v',\n\t\t\t'video/avi',\n\t\t\t'video/x-ms-wmv',\n\t\t\t'video/mpeg',\n\t\t\t'video/3gpp',\n\t\t\t'video/3gpp2',\n\t\t],\n\t};\n\n\treturn mediaTypes.reduce( ( prev, currentType ) => {\n\t\treturn prev.concat( mimeTypesPerType[ currentType ] );\n\t}, [] as string[] );\n}\n\nfunction getExtensions( mediaTypes: MediaType[] ) {\n\tconst extensionsPerType: Record< MediaType, string[] > = {\n\t\timage: imageExtensions,\n\t\tsvg: [ 'svg' ],\n\t\tvideo: videoExtensions,\n\t};\n\n\tconst extensions = mediaTypes.reduce( ( prev, currentType ) => {\n\t\treturn prev.concat( extensionsPerType[ currentType ] );\n\t}, [] as string[] );\n\n\treturn extensions.join( ',' );\n}\n","import { WpPluploadSettingsNotAvailableError } from './errors';\nimport { type WpPluploadSettingsWindow } from './types/plupload';\n\nconst wpPluploadSettingsWindow = window as unknown as WpPluploadSettingsWindow;\n\nexport default () => {\n\tif ( ! wpPluploadSettingsWindow._wpPluploadSettings ) {\n\t\tthrow new WpPluploadSettingsNotAvailableError();\n\t}\n\n\treturn wpPluploadSettingsWindow._wpPluploadSettings;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyB;;;ACAz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AClD,WAAO,KAAK,OAAQ,iBAAkB,WAAY,CAAE;AAAA,EACrD,GAAG,CAAC,CAAc;AACnB;AAEA,SAAS,cAAe,YAA0B;AACjD,QAAM,oBAAmD;AAAA,IACxD,OAAO;AAAA,IACP,KAAK,CAAE,KAAM;AAAA,IACb,OAAO;AAAA,EACR;AAEA,QAAM,aAAa,WAAW,OAAQ,CAAE,MAAM,gBAAiB;AAC9D,WAAO,KAAK,OAAQ,kBAAmB,WAAY,CAAE;AAAA,EACtD,GAAG,CAAC,CAAc;AAElB,SAAO,WAAW,KAAM,GAAI;AAC7B;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -137,10 +137,23 @@ function handleExtensions(frame, mediaTypes) {
|
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
139
|
var imageExtensions = ["avif", "bmp", "gif", "ico", "jpe", "jpeg", "jpg", "png", "webp"];
|
|
140
|
+
var videoExtensions = ["mp4", "webm", "ogg", "mov", "m4v", "avi", "wmv", "mpg", "mpeg", "3gp", "3g2"];
|
|
140
141
|
function getMimeTypes(mediaTypes) {
|
|
141
142
|
const mimeTypesPerType = {
|
|
142
143
|
image: imageExtensions.map((extension) => `image/${extension}`),
|
|
143
|
-
svg: ["image/svg+xml"]
|
|
144
|
+
svg: ["image/svg+xml"],
|
|
145
|
+
video: [
|
|
146
|
+
"video/mp4",
|
|
147
|
+
"video/webm",
|
|
148
|
+
"video/ogg",
|
|
149
|
+
"video/quicktime",
|
|
150
|
+
"video/x-m4v",
|
|
151
|
+
"video/avi",
|
|
152
|
+
"video/x-ms-wmv",
|
|
153
|
+
"video/mpeg",
|
|
154
|
+
"video/3gpp",
|
|
155
|
+
"video/3gpp2"
|
|
156
|
+
]
|
|
144
157
|
};
|
|
145
158
|
return mediaTypes.reduce((prev, currentType) => {
|
|
146
159
|
return prev.concat(mimeTypesPerType[currentType]);
|
|
@@ -149,7 +162,8 @@ function getMimeTypes(mediaTypes) {
|
|
|
149
162
|
function getExtensions(mediaTypes) {
|
|
150
163
|
const extensionsPerType = {
|
|
151
164
|
image: imageExtensions,
|
|
152
|
-
svg: ["svg"]
|
|
165
|
+
svg: ["svg"],
|
|
166
|
+
video: videoExtensions
|
|
153
167
|
};
|
|
154
168
|
const extensions = mediaTypes.reduce((prev, currentType) => {
|
|
155
169
|
return prev.concat(extensionsPerType[currentType]);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-wp-media-attachment.ts","../src/errors.ts","../src/media.ts","../src/normalize.ts","../src/get-media-attachment.ts","../src/hooks/use-wp-media-frame.ts","../src/wp-plupload-settings.ts"],"sourcesContent":["import { useQuery } from '@elementor/query';\n\nimport { getMediaAttachment } from '../get-media-attachment';\n\nexport default function useWpMediaAttachment( id: number | null ) {\n\treturn useQuery( {\n\t\tqueryKey: [ 'wp-attachment', id ],\n\t\tqueryFn: () => getMediaAttachment( { id } ),\n\t\tenabled: !! id,\n\t} );\n}\n","import { createError } from '@elementor/utils';\n\nexport const WpMediaNotAvailableError = createError( {\n\tcode: 'wp_media_not_available',\n\tmessage: '`wp.media` is not available, make sure the `media-models` handle is set in the dependencies array',\n} );\n\nexport const WpPluploadSettingsNotAvailableError = createError( {\n\tcode: 'wp_plupload_settings_not_available',\n\tmessage: '`_wpPluploadSettings` is not available, make sure a wp media uploader is open',\n} );\n","import { WpMediaNotAvailableError } from './errors';\nimport { type WpMediaWindow } from './types/wp-media';\n\nconst wpMediaWindow = window as unknown as WpMediaWindow;\n\nexport default () => {\n\tif ( ! wpMediaWindow.wp?.media ) {\n\t\tthrow new WpMediaNotAvailableError();\n\t}\n\n\treturn wpMediaWindow.wp.media;\n};\n","import { type Attachment } from './types/attachment';\nimport { type WpAttachmentJSON } from './types/wp-media';\n\nexport default function normalize( attachment: WpAttachmentJSON ): Attachment {\n\tconst { filesizeInBytes, filesizeHumanReadable, author, authorName, ...rest } = attachment;\n\n\treturn {\n\t\t...rest,\n\t\tfilesize: {\n\t\t\tinBytes: filesizeInBytes,\n\t\t\thumanReadable: filesizeHumanReadable,\n\t\t},\n\t\tauthor: {\n\t\t\tid: parseInt( author ),\n\t\t\tname: authorName,\n\t\t},\n\t};\n}\n","import media from './media';\nimport normalize from './normalize';\n\nexport async function getMediaAttachment( { id }: { id: number | null } ) {\n\tif ( ! id ) {\n\t\treturn null;\n\t}\n\n\tconst model = media().attachment( id );\n\tconst wpAttachment = model.toJSON();\n\n\tconst isFetched = 'url' in wpAttachment;\n\n\tif ( isFetched ) {\n\t\treturn normalize( wpAttachment );\n\t}\n\n\ttry {\n\t\treturn normalize( await model.fetch() );\n\t} catch {\n\t\treturn null;\n\t}\n}\n","import { useEffect, useRef } from 'react';\n\nimport media from '../media';\nimport normalize from '../normalize';\nimport { type Attachment } from '../types/attachment';\nimport { type MediaFrame } from '../types/wp-media';\nimport wpPluploadSettings from '../wp-plupload-settings';\n\nexport type OpenOptions = {\n\tmode?: 'upload' | 'browse';\n};\n\nexport type MediaType = 'image' | 'svg';\n\ntype Options = {\n\tmediaTypes: MediaType[];\n\ttitle?: string;\n} & (\n\t| {\n\t\t\tmultiple: true;\n\t\t\tselected: Array< number | null >;\n\t\t\tonSelect: ( val: Attachment[] ) => void;\n\t }\n\t| {\n\t\t\tmultiple: false;\n\t\t\tselected: number | null;\n\t\t\tonSelect: ( val: Attachment ) => void;\n\t }\n);\n\nexport default function useWpMediaFrame( options: Options ) {\n\tconst frame = useRef< MediaFrame >();\n\n\tconst open = ( openOptions: OpenOptions = {} ) => {\n\t\tcleanupFrame( frame.current );\n\n\t\tframe.current = createFrame( { ...options, ...openOptions } );\n\n\t\tframe.current?.open();\n\t};\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tcleanupFrame( frame.current );\n\t\t};\n\t}, [] );\n\n\treturn {\n\t\topen,\n\t};\n}\n\nfunction createFrame( { onSelect, multiple, mediaTypes, selected, title, mode = 'browse' }: Options & OpenOptions ) {\n\tconst frame: MediaFrame = media()( {\n\t\ttitle,\n\t\tmultiple,\n\t\tlibrary: {\n\t\t\ttype: getMimeTypes( mediaTypes ),\n\t\t},\n\t} )\n\t\t.on( 'open', () => {\n\t\t\tsetTypeCaller( frame );\n\t\t\tapplyMode( frame, mode );\n\t\t\tapplySelection( frame, selected );\n\t\t} )\n\t\t.on( 'close', () => cleanupFrame( frame ) )\n\t\t.on( 'insert select', () => select( frame, multiple, onSelect ) );\n\n\thandleExtensions( frame, mediaTypes );\n\n\treturn frame;\n}\n\nfunction cleanupFrame( frame?: MediaFrame ) {\n\tframe?.detach();\n\tframe?.remove();\n}\n\nfunction applyMode( frame: MediaFrame, mode: OpenOptions[ 'mode' ] = 'browse' ) {\n\tframe.content.mode( mode );\n}\n\nfunction applySelection( frame: MediaFrame, selected: number | null | Array< number | null > ) {\n\tconst selectedAttachments = ( typeof selected === 'number' ? [ selected ] : selected )\n\t\t?.filter( ( id ) => !! id )\n\t\t.map( ( id ) => media().attachment( id as number ) );\n\n\tframe\n\t\t.state()\n\t\t.get( 'selection' )\n\t\t.set( selectedAttachments || [] );\n}\n\nfunction select( frame: MediaFrame, multiple: boolean, onSelect: Options[ 'onSelect' ] ) {\n\tconst attachments = frame.state().get( 'selection' ).toJSON().map( normalize );\n\n\tconst onSelectFn = onSelect as ( val: Attachment | Attachment[] ) => void;\n\n\tonSelectFn( multiple ? attachments : attachments[ 0 ] );\n}\n\nfunction setTypeCaller( frame: MediaFrame ) {\n\tframe.uploader.uploader.param( 'uploadTypeCaller', 'elementor-wp-media-upload' );\n}\n\nfunction handleExtensions( frame: MediaFrame, mediaTypes: MediaType[] ) {\n\tconst defaultExtensions = wpPluploadSettings().defaults.filters.mime_types?.[ 0 ]?.extensions;\n\n\t// Set extensions by media types\n\tframe.on( 'ready', () => {\n\t\twpPluploadSettings().defaults.filters.mime_types = [ { extensions: getExtensions( mediaTypes ) } ];\n\t} );\n\n\t// Restore default upload extensions\n\tframe.on( 'close', () => {\n\t\twpPluploadSettings().defaults.filters.mime_types = defaultExtensions\n\t\t\t? [ { extensions: defaultExtensions } ]\n\t\t\t: [];\n\t} );\n}\n\nconst imageExtensions = [ 'avif', 'bmp', 'gif', 'ico', 'jpe', 'jpeg', 'jpg', 'png', 'webp' ];\n\nfunction getMimeTypes( mediaTypes: MediaType[] ) {\n\tconst mimeTypesPerType: Record< MediaType, string[] > = {\n\t\timage: imageExtensions.map( ( extension ) => `image/${ extension }` ),\n\t\tsvg: [ 'image/svg+xml' ],\n\t};\n\n\treturn mediaTypes.reduce( ( prev, currentType ) => {\n\t\treturn prev.concat( mimeTypesPerType[ currentType ] );\n\t}, [] as string[] );\n}\n\nfunction getExtensions( mediaTypes: MediaType[] ) {\n\tconst extensionsPerType: Record< MediaType, string[] > = {\n\t\timage: imageExtensions,\n\t\tsvg: [ 'svg' ],\n\t};\n\n\tconst extensions = mediaTypes.reduce( ( prev, currentType ) => {\n\t\treturn prev.concat( extensionsPerType[ currentType ] );\n\t}, [] as string[] );\n\n\treturn extensions.join( ',' );\n}\n","import { WpPluploadSettingsNotAvailableError } from './errors';\nimport { type WpPluploadSettingsWindow } from './types/plupload';\n\nconst wpPluploadSettingsWindow = window as unknown as WpPluploadSettingsWindow;\n\nexport default () => {\n\tif ( ! wpPluploadSettingsWindow._wpPluploadSettings ) {\n\t\tthrow new WpPluploadSettingsNotAvailableError();\n\t}\n\n\treturn wpPluploadSettingsWindow._wpPluploadSettings;\n};\n"],"mappings":";AAAA,SAAS,gBAAgB;;;ACAzB,SAAS,mBAAmB;AAErB,IAAM,2BAA2B,YAAa;AAAA,EACpD,MAAM;AAAA,EACN,SAAS;AACV,CAAE;AAEK,IAAM,sCAAsC,YAAa;AAAA,EAC/D,MAAM;AAAA,EACN,SAAS;AACV,CAAE;;;ACPF,IAAM,gBAAgB;AAEtB,IAAO,gBAAQ,MAAM;AACpB,MAAK,CAAE,cAAc,IAAI,OAAQ;AAChC,UAAM,IAAI,yBAAyB;AAAA,EACpC;AAEA,SAAO,cAAc,GAAG;AACzB;;;ACR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AAO,oBAAoB,2BAA4B;AAChF;AAEA,SAAS,iBAAkB,OAAmB,YAA0B;AACvE,QAAM,oBAAoB,6BAAmB,EAAE,SAAS,QAAQ,aAAc,CAAE,GAAG;AAGnF,QAAM,GAAI,SAAS,MAAM;AACxB,iCAAmB,EAAE,SAAS,QAAQ,aAAa,CAAE,EAAE,YAAY,cAAe,UAAW,EAAE,CAAE;AAAA,EAClG,CAAE;AAGF,QAAM,GAAI,SAAS,MAAM;AACxB,iCAAmB,EAAE,SAAS,QAAQ,aAAa,oBAChD,CAAE,EAAE,YAAY,kBAAkB,CAAE,IACpC,CAAC;AAAA,EACL,CAAE;AACH;AAEA,IAAM,kBAAkB,CAAE,QAAQ,OAAO,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,MAAO;AAE3F,SAAS,aAAc,YAA0B;AAChD,QAAM,mBAAkD;AAAA,IACvD,OAAO,gBAAgB,IAAK,CAAE,cAAe,SAAU,SAAU,EAAG;AAAA,IACpE,KAAK,CAAE,eAAgB;AAAA,EACxB;AAEA,SAAO,WAAW,OAAQ,CAAE,MAAM,gBAAiB;AAClD,WAAO,KAAK,OAAQ,iBAAkB,WAAY,CAAE;AAAA,EACrD,GAAG,CAAC,CAAc;AACnB;AAEA,SAAS,cAAe,YAA0B;AACjD,QAAM,oBAAmD;AAAA,IACxD,OAAO;AAAA,IACP,KAAK,CAAE,KAAM;AAAA,EACd;AAEA,QAAM,aAAa,WAAW,OAAQ,CAAE,MAAM,gBAAiB;AAC9D,WAAO,KAAK,OAAQ,kBAAmB,WAAY,CAAE;AAAA,EACtD,GAAG,CAAC,CAAc;AAElB,SAAO,WAAW,KAAM,GAAI;AAC7B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-wp-media-attachment.ts","../src/errors.ts","../src/media.ts","../src/normalize.ts","../src/get-media-attachment.ts","../src/hooks/use-wp-media-frame.ts","../src/wp-plupload-settings.ts"],"sourcesContent":["import { useQuery } from '@elementor/query';\n\nimport { getMediaAttachment } from '../get-media-attachment';\n\nexport default function useWpMediaAttachment( id: number | null ) {\n\treturn useQuery( {\n\t\tqueryKey: [ 'wp-attachment', id ],\n\t\tqueryFn: () => getMediaAttachment( { id } ),\n\t\tenabled: !! id,\n\t} );\n}\n","import { createError } from '@elementor/utils';\n\nexport const WpMediaNotAvailableError = createError( {\n\tcode: 'wp_media_not_available',\n\tmessage: '`wp.media` is not available, make sure the `media-models` handle is set in the dependencies array',\n} );\n\nexport const WpPluploadSettingsNotAvailableError = createError( {\n\tcode: 'wp_plupload_settings_not_available',\n\tmessage: '`_wpPluploadSettings` is not available, make sure a wp media uploader is open',\n} );\n","import { WpMediaNotAvailableError } from './errors';\nimport { type WpMediaWindow } from './types/wp-media';\n\nconst wpMediaWindow = window as unknown as WpMediaWindow;\n\nexport default () => {\n\tif ( ! wpMediaWindow.wp?.media ) {\n\t\tthrow new WpMediaNotAvailableError();\n\t}\n\n\treturn wpMediaWindow.wp.media;\n};\n","import { type Attachment } from './types/attachment';\nimport { type WpAttachmentJSON } from './types/wp-media';\n\nexport default function normalize( attachment: WpAttachmentJSON ): Attachment {\n\tconst { filesizeInBytes, filesizeHumanReadable, author, authorName, ...rest } = attachment;\n\n\treturn {\n\t\t...rest,\n\t\tfilesize: {\n\t\t\tinBytes: filesizeInBytes,\n\t\t\thumanReadable: filesizeHumanReadable,\n\t\t},\n\t\tauthor: {\n\t\t\tid: parseInt( author ),\n\t\t\tname: authorName,\n\t\t},\n\t};\n}\n","import media from './media';\nimport normalize from './normalize';\n\nexport async function getMediaAttachment( { id }: { id: number | null } ) {\n\tif ( ! id ) {\n\t\treturn null;\n\t}\n\n\tconst model = media().attachment( id );\n\tconst wpAttachment = model.toJSON();\n\n\tconst isFetched = 'url' in wpAttachment;\n\n\tif ( isFetched ) {\n\t\treturn normalize( wpAttachment );\n\t}\n\n\ttry {\n\t\treturn normalize( await model.fetch() );\n\t} catch {\n\t\treturn null;\n\t}\n}\n","import { useEffect, useRef } from 'react';\n\nimport media from '../media';\nimport normalize from '../normalize';\nimport { type Attachment } from '../types/attachment';\nimport { type MediaFrame } from '../types/wp-media';\nimport wpPluploadSettings from '../wp-plupload-settings';\n\nexport type OpenOptions = {\n\tmode?: 'upload' | 'browse';\n};\n\nexport type MediaType = 'image' | 'svg' | 'video';\n\ntype Options = {\n\tmediaTypes: MediaType[];\n\ttitle?: string;\n} & (\n\t| {\n\t\t\tmultiple: true;\n\t\t\tselected: Array< number | null >;\n\t\t\tonSelect: ( val: Attachment[] ) => void;\n\t }\n\t| {\n\t\t\tmultiple: false;\n\t\t\tselected: number | null;\n\t\t\tonSelect: ( val: Attachment ) => void;\n\t }\n);\n\nexport default function useWpMediaFrame( options: Options ) {\n\tconst frame = useRef< MediaFrame >();\n\n\tconst open = ( openOptions: OpenOptions = {} ) => {\n\t\tcleanupFrame( frame.current );\n\n\t\tframe.current = createFrame( { ...options, ...openOptions } );\n\n\t\tframe.current?.open();\n\t};\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tcleanupFrame( frame.current );\n\t\t};\n\t}, [] );\n\n\treturn {\n\t\topen,\n\t};\n}\n\nfunction createFrame( { onSelect, multiple, mediaTypes, selected, title, mode = 'browse' }: Options & OpenOptions ) {\n\tconst frame: MediaFrame = media()( {\n\t\ttitle,\n\t\tmultiple,\n\t\tlibrary: {\n\t\t\ttype: getMimeTypes( mediaTypes ),\n\t\t},\n\t} )\n\t\t.on( 'open', () => {\n\t\t\tsetTypeCaller( frame );\n\t\t\tapplyMode( frame, mode );\n\t\t\tapplySelection( frame, selected );\n\t\t} )\n\t\t.on( 'close', () => cleanupFrame( frame ) )\n\t\t.on( 'insert select', () => select( frame, multiple, onSelect ) );\n\n\thandleExtensions( frame, mediaTypes );\n\n\treturn frame;\n}\n\nfunction cleanupFrame( frame?: MediaFrame ) {\n\tframe?.detach();\n\tframe?.remove();\n}\n\nfunction applyMode( frame: MediaFrame, mode: OpenOptions[ 'mode' ] = 'browse' ) {\n\tframe.content.mode( mode );\n}\n\nfunction applySelection( frame: MediaFrame, selected: number | null | Array< number | null > ) {\n\tconst selectedAttachments = ( typeof selected === 'number' ? [ selected ] : selected )\n\t\t?.filter( ( id ) => !! id )\n\t\t.map( ( id ) => media().attachment( id as number ) );\n\n\tframe\n\t\t.state()\n\t\t.get( 'selection' )\n\t\t.set( selectedAttachments || [] );\n}\n\nfunction select( frame: MediaFrame, multiple: boolean, onSelect: Options[ 'onSelect' ] ) {\n\tconst attachments = frame.state().get( 'selection' ).toJSON().map( normalize );\n\n\tconst onSelectFn = onSelect as ( val: Attachment | Attachment[] ) => void;\n\n\tonSelectFn( multiple ? attachments : attachments[ 0 ] );\n}\n\nfunction setTypeCaller( frame: MediaFrame ) {\n\tframe.uploader.uploader.param( 'uploadTypeCaller', 'elementor-wp-media-upload' );\n}\n\nfunction handleExtensions( frame: MediaFrame, mediaTypes: MediaType[] ) {\n\tconst defaultExtensions = wpPluploadSettings().defaults.filters.mime_types?.[ 0 ]?.extensions;\n\n\t// Set extensions by media types\n\tframe.on( 'ready', () => {\n\t\twpPluploadSettings().defaults.filters.mime_types = [ { extensions: getExtensions( mediaTypes ) } ];\n\t} );\n\n\t// Restore default upload extensions\n\tframe.on( 'close', () => {\n\t\twpPluploadSettings().defaults.filters.mime_types = defaultExtensions\n\t\t\t? [ { extensions: defaultExtensions } ]\n\t\t\t: [];\n\t} );\n}\n\nconst imageExtensions = [ 'avif', 'bmp', 'gif', 'ico', 'jpe', 'jpeg', 'jpg', 'png', 'webp' ];\nconst videoExtensions = [ 'mp4', 'webm', 'ogg', 'mov', 'm4v', 'avi', 'wmv', 'mpg', 'mpeg', '3gp', '3g2' ];\n\nfunction getMimeTypes( mediaTypes: MediaType[] ) {\n\tconst mimeTypesPerType: Record< MediaType, string[] > = {\n\t\timage: imageExtensions.map( ( extension ) => `image/${ extension }` ),\n\t\tsvg: [ 'image/svg+xml' ],\n\t\tvideo: [\n\t\t\t'video/mp4',\n\t\t\t'video/webm',\n\t\t\t'video/ogg',\n\t\t\t'video/quicktime',\n\t\t\t'video/x-m4v',\n\t\t\t'video/avi',\n\t\t\t'video/x-ms-wmv',\n\t\t\t'video/mpeg',\n\t\t\t'video/3gpp',\n\t\t\t'video/3gpp2',\n\t\t],\n\t};\n\n\treturn mediaTypes.reduce( ( prev, currentType ) => {\n\t\treturn prev.concat( mimeTypesPerType[ currentType ] );\n\t}, [] as string[] );\n}\n\nfunction getExtensions( mediaTypes: MediaType[] ) {\n\tconst extensionsPerType: Record< MediaType, string[] > = {\n\t\timage: imageExtensions,\n\t\tsvg: [ 'svg' ],\n\t\tvideo: videoExtensions,\n\t};\n\n\tconst extensions = mediaTypes.reduce( ( prev, currentType ) => {\n\t\treturn prev.concat( extensionsPerType[ currentType ] );\n\t}, [] as string[] );\n\n\treturn extensions.join( ',' );\n}\n","import { WpPluploadSettingsNotAvailableError } from './errors';\nimport { type WpPluploadSettingsWindow } from './types/plupload';\n\nconst wpPluploadSettingsWindow = window as unknown as WpPluploadSettingsWindow;\n\nexport default () => {\n\tif ( ! wpPluploadSettingsWindow._wpPluploadSettings ) {\n\t\tthrow new WpPluploadSettingsNotAvailableError();\n\t}\n\n\treturn wpPluploadSettingsWindow._wpPluploadSettings;\n};\n"],"mappings":";AAAA,SAAS,gBAAgB;;;ACAzB,SAAS,mBAAmB;AAErB,IAAM,2BAA2B,YAAa;AAAA,EACpD,MAAM;AAAA,EACN,SAAS;AACV,CAAE;AAEK,IAAM,sCAAsC,YAAa;AAAA,EAC/D,MAAM;AAAA,EACN,SAAS;AACV,CAAE;;;ACPF,IAAM,gBAAgB;AAEtB,IAAO,gBAAQ,MAAM;AACpB,MAAK,CAAE,cAAc,IAAI,OAAQ;AAChC,UAAM,IAAI,yBAAyB;AAAA,EACpC;AAEA,SAAO,cAAc,GAAG;AACzB;;;ACRe,SAAR,UAA4B,YAA2C;AAC7E,QAAM,EAAE,iBAAiB,uBAAuB,QAAQ,YAAY,GAAG,KAAK,IAAI;AAEhF,SAAO;AAAA,IACN,G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|
|
2
2
|
"name": "@elementor/wp-media",
|
|
3
3
|
"description": "An adapter for WordPress' media utils",
|
|
4
|
-
"version": "4.0.0-
|
|
4
|
+
"version": "4.0.0-619",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/query": "4.0.0-
|
|
44
|
-
"@elementor/utils": "4.0.0-
|
|
43
|
+
"@elementor/query": "4.0.0-619",
|
|
44
|
+
"@elementor/utils": "4.0.0-619"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": "^18.3.1"
|
|
@@ -10,7 +10,7 @@ export type OpenOptions = {
|
|
|
10
10
|
mode?: 'upload' | 'browse';
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export type MediaType = 'image' | 'svg';
|
|
13
|
+
export type MediaType = 'image' | 'svg' | 'video';
|
|
14
14
|
|
|
15
15
|
type Options = {
|
|
16
16
|
mediaTypes: MediaType[];
|
|
@@ -120,11 +120,24 @@ function handleExtensions( frame: MediaFrame, mediaTypes: MediaType[] ) {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
const imageExtensions = [ 'avif', 'bmp', 'gif', 'ico', 'jpe', 'jpeg', 'jpg', 'png', 'webp' ];
|
|
123
|
+
const videoExtensions = [ 'mp4', 'webm', 'ogg', 'mov', 'm4v', 'avi', 'wmv', 'mpg', 'mpeg', '3gp', '3g2' ];
|
|
123
124
|
|
|
124
125
|
function getMimeTypes( mediaTypes: MediaType[] ) {
|
|
125
126
|
const mimeTypesPerType: Record< MediaType, string[] > = {
|
|
126
127
|
image: imageExtensions.map( ( extension ) => `image/${ extension }` ),
|
|
127
128
|
svg: [ 'image/svg+xml' ],
|
|
129
|
+
video: [
|
|
130
|
+
'video/mp4',
|
|
131
|
+
'video/webm',
|
|
132
|
+
'video/ogg',
|
|
133
|
+
'video/quicktime',
|
|
134
|
+
'video/x-m4v',
|
|
135
|
+
'video/avi',
|
|
136
|
+
'video/x-ms-wmv',
|
|
137
|
+
'video/mpeg',
|
|
138
|
+
'video/3gpp',
|
|
139
|
+
'video/3gpp2',
|
|
140
|
+
],
|
|
128
141
|
};
|
|
129
142
|
|
|
130
143
|
return mediaTypes.reduce( ( prev, currentType ) => {
|
|
@@ -136,6 +149,7 @@ function getExtensions( mediaTypes: MediaType[] ) {
|
|
|
136
149
|
const extensionsPerType: Record< MediaType, string[] > = {
|
|
137
150
|
image: imageExtensions,
|
|
138
151
|
svg: [ 'svg' ],
|
|
152
|
+
video: videoExtensions,
|
|
139
153
|
};
|
|
140
154
|
|
|
141
155
|
const extensions = mediaTypes.reduce( ( prev, currentType ) => {
|