@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 2.72 kB
Source Map (JSON)
{"version":3,"file":"embed-video-url-input.mjs","names":["ConfirmDialog","WCNotice"],"sources":["../../../src/cover/edit/embed-video-url-input.jsx"],"sourcesContent":["import { useState } from '@wordpress/element';\nimport {\n\t__experimentalConfirmDialog as ConfirmDialog,\n\tTextControl,\n\tNotice as WCNotice,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { Stack } from '@wordpress/ui';\nimport { isValidVideoEmbedUrl } from '../embed-video-utils';\n\nexport default function EmbedVideoUrlInput( {\n\tonSubmit,\n\tonClose,\n\tinitialUrl = '',\n\tallowedVideoProviders,\n} ) {\n\tconst [ url, setUrl ] = useState( initialUrl );\n\tconst [ error, setError ] = useState( '' );\n\n\tconst handleConfirm = () => {\n\t\tif ( ! url ) {\n\t\t\tsetError( __( 'Please enter a URL.' ) );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! isValidVideoEmbedUrl( url, allowedVideoProviders ) ) {\n\t\t\tsetError(\n\t\t\t\t__(\n\t\t\t\t\t'This URL is not supported. Please enter a valid video link from a supported provider.'\n\t\t\t\t)\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tonSubmit( url );\n\t\tonClose();\n\t};\n\n\treturn (\n\t\t<ConfirmDialog\n\t\t\tisOpen\n\t\t\tonConfirm={ handleConfirm }\n\t\t\tonCancel={ onClose }\n\t\t\tconfirmButtonText={ __( 'Add video' ) }\n\t\t\tsize=\"medium\"\n\t\t>\n\t\t\t<Stack direction=\"column\" gap=\"lg\">\n\t\t\t\t{ error && (\n\t\t\t\t\t<WCNotice status=\"error\" isDismissible={ false }>\n\t\t\t\t\t\t{ error }\n\t\t\t\t\t</WCNotice>\n\t\t\t\t) }\n\t\t\t\t<TextControl\n\t\t\t\t\ttype=\"url\"\n\t\t\t\t\tlabel={ __( 'Video URL' ) }\n\t\t\t\t\tvalue={ url }\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tsetUrl( value );\n\t\t\t\t\t\tsetError( '' );\n\t\t\t\t\t} }\n\t\t\t\t\tplaceholder={ __(\n\t\t\t\t\t\t'Enter YouTube, Vimeo, or other video URL'\n\t\t\t\t\t) }\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'Add a background video to the cover block that will autoplay in a loop.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</Stack>\n\t\t</ConfirmDialog>\n\t);\n}\n"],"mappings":";;;;;;;AAUA,SAAwB,mBAAoB,EAC3C,UACA,SACA,aAAa,IACb,yBACG;CACH,MAAM,CAAE,KAAK,UAAW,SAAU,UAAW;CAC7C,MAAM,CAAE,OAAO,YAAa,SAAU,EAAG;CAEzC,MAAM,sBAAsB;EAC3B,IAAK,CAAE,KAAM;GACZ,SAAU,GAAI,qBAAsB,CAAE;GACtC;EACD;EAEA,IAAK,CAAE,qBAAsB,KAAK,qBAAsB,GAAI;GAC3D,SACC,GACC,uFACD,CACD;GACA;EACD;EAEA,SAAU,GAAI;EACd,QAAQ;CACT;CAEA,OACC,oBAACA,6BAAD;EACC,QAAA;EACA,WAAY;EACZ,UAAW;EACX,mBAAoB,GAAI,WAAY;EACpC,MAAK;EAEL,UAAA,qBAAC,OAAD;GAAO,WAAU;GAAS,KAAI;GAA9B,UAAA,CACG,SACD,oBAACC,QAAD;IAAU,QAAO;IAAQ,eAAgB;IACtC,UAAA;GACO,CAAA,GAEX,oBAAC,aAAD;IACC,MAAK;IACL,OAAQ,GAAI,WAAY;IACxB,OAAQ;IACR,WAAa,UAAW;KACvB,OAAQ,KAAM;KACd,SAAU,EAAG;IACd;IACA,aAAc,GACb,0CACD;IACA,MAAO,GACN,yEACD;GACA,CAAA,CACK;;CACO,CAAA;AAEjB"}