@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 4.31 kB
Source Map (JSON)
{"version":3,"file":"transforms.mjs","names":[],"sources":["../../src/video/transforms.js"],"sourcesContent":["import { createBlobURL, isBlobURL } from '@wordpress/blob';\nimport { createBlock } from '@wordpress/blocks';\n\nconst transforms = {\n\tfrom: [\n\t\t{\n\t\t\ttype: 'files',\n\t\t\tisMatch( files ) {\n\t\t\t\treturn (\n\t\t\t\t\tfiles.length === 1 &&\n\t\t\t\t\tfiles[ 0 ].type.indexOf( 'video/' ) === 0\n\t\t\t\t);\n\t\t\t},\n\t\t\ttransform( files ) {\n\t\t\t\tconst file = files[ 0 ];\n\t\t\t\t// We don't need to upload the media directly here\n\t\t\t\t// It's already done as part of the `componentDidMount`\n\t\t\t\t// in the video block\n\t\t\t\tconst block = createBlock( 'core/video', {\n\t\t\t\t\tblob: createBlobURL( file ),\n\t\t\t\t} );\n\t\t\t\treturn block;\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\ttype: 'shortcode',\n\t\t\ttag: 'video',\n\t\t\tattributes: {\n\t\t\t\tsrc: {\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tshortcode: ( {\n\t\t\t\t\t\tnamed: { src, mp4, m4v, webm, ogv, flv },\n\t\t\t\t\t} ) => {\n\t\t\t\t\t\treturn src || mp4 || m4v || webm || ogv || flv;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tposter: {\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tshortcode: ( { named: { poster } } ) => {\n\t\t\t\t\t\treturn poster;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tloop: {\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tshortcode: ( { named: { loop } } ) => {\n\t\t\t\t\t\treturn loop;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tautoplay: {\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tshortcode: ( { named: { autoplay } } ) => {\n\t\t\t\t\t\treturn autoplay;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tpreload: {\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tshortcode: ( { named: { preload } } ) => {\n\t\t\t\t\t\treturn preload;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\ttype: 'raw',\n\t\t\tisMatch: ( node ) =>\n\t\t\t\tnode.nodeName === 'P' &&\n\t\t\t\tnode.children.length === 1 &&\n\t\t\t\tnode.firstChild.nodeName === 'VIDEO',\n\t\t\ttransform: ( node ) => {\n\t\t\t\tconst videoElement = node.firstChild;\n\t\t\t\tconst attributes = {\n\t\t\t\t\tautoplay: videoElement.hasAttribute( 'autoplay' )\n\t\t\t\t\t\t? true\n\t\t\t\t\t\t: undefined,\n\t\t\t\t\tcontrols: videoElement.hasAttribute( 'controls' )\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: false,\n\t\t\t\t\tloop: videoElement.hasAttribute( 'loop' )\n\t\t\t\t\t\t? true\n\t\t\t\t\t\t: undefined,\n\t\t\t\t\tmuted: videoElement.hasAttribute( 'muted' )\n\t\t\t\t\t\t? true\n\t\t\t\t\t\t: undefined,\n\t\t\t\t\tpreload:\n\t\t\t\t\t\tvideoElement.getAttribute( 'preload' ) || undefined,\n\t\t\t\t\tplaysInline: videoElement.hasAttribute( 'playsinline' )\n\t\t\t\t\t\t? true\n\t\t\t\t\t\t: undefined,\n\t\t\t\t\tposter: videoElement.getAttribute( 'poster' ) || undefined,\n\t\t\t\t\tsrc: videoElement.getAttribute( 'src' ) || undefined,\n\t\t\t\t};\n\t\t\t\tif ( isBlobURL( attributes.src ) ) {\n\t\t\t\t\tattributes.blob = attributes.src;\n\t\t\t\t\tdelete attributes.src;\n\t\t\t\t}\n\t\t\t\treturn createBlock( 'core/video', attributes );\n\t\t\t},\n\t\t},\n\t],\n};\n\nexport default transforms;\n"],"mappings":";;;AAGA,MAAM,aAAa,EAClB,MAAM;CACL;EACC,MAAM;EACN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