@wordpress/block-editor
Version:
8 lines (7 loc) • 6.13 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/provider/index.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { useEffect, useMemo } from '@wordpress/element';\nimport { SlotFillProvider } from '@wordpress/components';\nimport {\n\tMediaUploadProvider,\n\tstore as uploadStore,\n} from '@wordpress/upload-media';\n\n/**\n * Internal dependencies\n */\nimport withRegistryProvider from './with-registry-provider';\nimport useBlockSync from './use-block-sync';\nimport { store as blockEditorStore } from '../../store';\nimport { BlockRefsProvider } from './block-refs-provider';\nimport { unlock } from '../../lock-unlock';\nimport KeyboardShortcuts from '../keyboard-shortcuts';\nimport useMediaUploadSettings from './use-media-upload-settings';\n\n/** @typedef {import('@wordpress/data').WPDataRegistry} WPDataRegistry */\n\nconst noop = () => {};\n\n/**\n * Upload a media file when the file upload button is activated\n * or when adding a file to the editor via drag & drop.\n *\n * @param {WPDataRegistry} registry\n * @param {Object} $3 Parameters object passed to the function.\n * @param {Array} $3.allowedTypes Array with the types of media that can be uploaded, if unset all types are allowed.\n * @param {Object} $3.additionalData Additional data to include in the request.\n * @param {Array<File>} $3.filesList List of files.\n * @param {Function} $3.onError Function called when an error happens.\n * @param {Function} $3.onFileChange Function called each time a file or a temporary representation of the file is available.\n * @param {Function} $3.onSuccess Function called once a file has completely finished uploading, including thumbnails.\n * @param {Function} $3.onBatchSuccess Function called once all files in a group have completely finished uploading, including thumbnails.\n */\nfunction mediaUpload(\n\tregistry,\n\t{\n\t\tallowedTypes,\n\t\tadditionalData = {},\n\t\tfilesList,\n\t\tonError = noop,\n\t\tonFileChange,\n\t\tonSuccess,\n\t\tonBatchSuccess,\n\t}\n) {\n\tvoid registry.dispatch( uploadStore ).addItems( {\n\t\tfiles: filesList,\n\t\tonChange: onFileChange,\n\t\tonSuccess,\n\t\tonBatchSuccess,\n\t\tonError: ( { message } ) => onError( message ),\n\t\tadditionalData,\n\t\tallowedTypes,\n\t} );\n}\n\nexport const ExperimentalBlockEditorProvider = withRegistryProvider(\n\t( props ) => {\n\t\tconst {\n\t\t\tsettings: _settings,\n\t\t\tregistry,\n\t\t\tstripExperimentalSettings = false,\n\t\t} = props;\n\n\t\tconst mediaUploadSettings = useMediaUploadSettings( _settings );\n\n\t\tlet settings = _settings;\n\n\t\tif ( window.__experimentalMediaProcessing && _settings.mediaUpload ) {\n\t\t\t// Create a new variable so that the original props.settings.mediaUpload is not modified.\n\t\t\tsettings = useMemo(\n\t\t\t\t() => ( {\n\t\t\t\t\t..._settings,\n\t\t\t\t\tmediaUpload: mediaUpload.bind( null, registry ),\n\t\t\t\t} ),\n\t\t\t\t[ _settings, registry ]\n\t\t\t);\n\t\t}\n\n\t\tconst { __experimentalUpdateSettings } = unlock(\n\t\t\tuseDispatch( blockEditorStore )\n\t\t);\n\t\tuseEffect( () => {\n\t\t\t__experimentalUpdateSettings(\n\t\t\t\t{\n\t\t\t\t\t...settings,\n\t\t\t\t\t__internalIsInitialized: true,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tstripExperimentalSettings,\n\t\t\t\t\treset: true,\n\t\t\t\t}\n\t\t\t);\n\t\t}, [\n\t\t\tsettings,\n\t\t\tstripExperimentalSettings,\n\t\t\t__experimentalUpdateSettings,\n\t\t] );\n\n\t\t// Syncs the entity provider with changes in the block-editor store.\n\t\tuseBlockSync( props );\n\n\t\tconst children = (\n\t\t\t<SlotFillProvider passthrough>\n\t\t\t\t{ ! settings?.isPreviewMode && <KeyboardShortcuts.Register /> }\n\t\t\t\t<BlockRefsProvider>{ props.children }</BlockRefsProvider>\n\t\t\t</SlotFillProvider>\n\t\t);\n\n\t\tif ( window.__experimentalMediaProcessing ) {\n\t\t\treturn (\n\t\t\t\t<MediaUploadProvider\n\t\t\t\t\tsettings={ mediaUploadSettings }\n\t\t\t\t\tuseSubRegistry={ false }\n\t\t\t\t>\n\t\t\t\t\t{ children }\n\t\t\t\t</MediaUploadProvider>\n\t\t\t);\n\t\t}\n\n\t\treturn children;\n\t}\n);\n\nexport const BlockEditorProvider = ( props ) => {\n\treturn (\n\t\t<ExperimentalBlockEditorProvider { ...props } stripExperimentalSettings>\n\t\t\t{ props.children }\n\t\t</ExperimentalBlockEditorProvider>\n\t);\n};\n\nexport default BlockEditorProvider;\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAC5B,qBAAmC;AACnC,wBAAiC;AACjC,0BAGO;AAKP,oCAAiC;AACjC,4BAAyB;AACzB,mBAA0C;AAC1C,iCAAkC;AAClC,yBAAuB;AACvB,gCAA8B;AAC9B,uCAAmC;AA0FhC;AAtFH,IAAM,OAAO,MAAM;AAAC;AAgBpB,SAAS,YACR,UACA;AAAA,EACC;AAAA,EACA,iBAAiB,CAAC;AAAA,EAClB;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA;AACD,GACC;AACD,OAAK,SAAS,SAAU,oBAAAA,KAAY,EAAE,SAAU;AAAA,IAC/C,OAAO;AAAA,IACP,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,SAAS,CAAE,EAAE,QAAQ,MAAO,QAAS,OAAQ;AAAA,IAC7C;AAAA,IACA;AAAA,EACD,CAAE;AACH;AAEO,IAAM,sCAAkC,8BAAAC;AAAA,EAC9C,CAAE,UAAW;AACZ,UAAM;AAAA,MACL,UAAU;AAAA,MACV;AAAA,MACA,4BAA4B;AAAA,IAC7B,IAAI;AAEJ,UAAM,0BAAsB,iCAAAC,SAAwB,SAAU;AAE9D,QAAI,WAAW;AAEf,QAAK,OAAO,iCAAiC,UAAU,aAAc;AAEpE,qBAAW;AAAA,QACV,OAAQ;AAAA,UACP,GAAG;AAAA,UACH,aAAa,YAAY,KAAM,MAAM,QAAS;AAAA,QAC/C;AAAA,QACA,CAAE,WAAW,QAAS;AAAA,MACvB;AAAA,IACD;AAEA,UAA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