@wordpress/block-directory 3.16.0 → 3.16.1-next.4d3b314fd5.0

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.
@@ -113,7 +113,7 @@ const ModifiedWarning = _ref2 => {
113
113
  actions.push((0, _element.createElement)(_components.Button, {
114
114
  key: "convert",
115
115
  onClick: convertToHTML,
116
- variant: "link"
116
+ variant: "tertiary"
117
117
  }, (0, _i18n.__)('Keep as HTML')));
118
118
  }
119
119
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-directory/src/plugins/get-install-missing/index.js"],"names":["getInstallMissing","OriginalComponent","props","originalName","attributes","block","hasPermission","select","getDownloadableBlocks","blockDirectoryStore","blocks","filter","name","coreStore","canUser","length","ModifiedWarning","originalBlock","originalUndelimitedContent","clientId","replaceBlock","blockEditorStore","convertToHTML","content","hasContent","hasHTMLBlock","canInsertBlockType","getBlockRootClientId","messageHTML","title","actions","push"],"mappings":";;;;;;;;;AAMA;;;;AAHA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AASA;;AACA;;AAnBA;AACA;AACA;;AAaA;AACA;AACA;AAIA,MAAMA,iBAAiB,GAAKC,iBAAF,IAA2BC,KAAF,IAAa;AAC/D,QAAM;AAAEC,IAAAA;AAAF,MAAmBD,KAAK,CAACE,UAA/B,CAD+D,CAE/D;AACA;;AACA,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAA2B,qBAC9BC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA;AAAF,QAA4BD,MAAM,CAAEE,YAAF,CAAxC;AACA,UAAMC,MAAM,GAAGF,qBAAqB,CACnC,WAAWL,YADwB,CAArB,CAEbQ,MAFa,CAEL;AAAA,UAAE;AAAEC,QAAAA;AAAF,OAAF;AAAA,aAAgBT,YAAY,KAAKS,IAAjC;AAAA,KAFK,CAAf;AAGA,WAAO;AACNN,MAAAA,aAAa,EAAEC,MAAM,CAAEM,eAAF,CAAN,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AOA,QAAM2B,OAAO,GAAG,CACf,4BAAC,sBAAD;AACC,IAAA,GAAG,EAAC,SADL;AAEC,IAAA,KAAK,EAAGb,aAFT;AAGC,IAAA,UAAU,EAAGf,KAAK,CAACE,UAHpB;AAIC,IAAA,QAAQ,EAAGF,KAAK,CAACiB;AAJlB,IADe,CAAhB;;AASA,MAAKK,UAAU,IAAIC,YAAnB,EAAkC;AACjCG,IAAAA,WAAW,GAAG;AACb;AACA,kBACC,iJADD,CAFa,EAKbX,aAAa,CAACY,KAAd,IAAuB1B,YALV,CAAd;AAOA2B,IAAAA,OAAO,CAACC,IAAR,CACC,4BAAC,kBAAD;AAAQ,MAAA,GAAG,EAAC,SAAZ;AAAsB,MAAA,OAAO,EAAGT,aAAhC;AAAgD,MAAA,OAAO,EAAC;AAAxD,OACG,cAAI,cAAJ,CADH,CADD;AAKA;;AAED,SACC,mCAAU,iCAAV,EACC,4BAAC,oBAAD;AAAS,IAAA,OAAO,EAAGQ;AAAnB,KAA+BF,WAA/B,CADD,EAEC,4BAAC,gBAAD,QAAWV,0BAAX,CAFD,CADD;AAMA,CAhED;;eAkEelB,iB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { createBlock } from '@wordpress/blocks';\nimport { RawHTML } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tWarning,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport InstallButton from './install-button';\nimport { store as blockDirectoryStore } from '../../store';\n\nconst getInstallMissing = ( OriginalComponent ) => ( props ) => {\n\tconst { originalName } = props.attributes;\n\t// Disable reason: This is a valid component, but it's mistaken for a callback.\n\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\tconst { block, hasPermission } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getDownloadableBlocks } = select( blockDirectoryStore );\n\t\t\tconst blocks = getDownloadableBlocks(\n\t\t\t\t'block:' + originalName\n\t\t\t).filter( ( { name } ) => originalName === name );\n\t\t\treturn {\n\t\t\t\thasPermission: select( coreStore ).canUser(\n\t\t\t\t\t'read',\n\t\t\t\t\t'block-directory/search'\n\t\t\t\t),\n\t\t\t\tblock: blocks.length && blocks[ 0 ],\n\t\t\t};\n\t\t},\n\t\t[ originalName ]\n\t);\n\n\t// The user can't install blocks, or the block isn't available for download.\n\tif ( ! hasPermission || ! block ) {\n\t\treturn <OriginalComponent { ...props } />;\n\t}\n\n\treturn <ModifiedWarning { ...props } originalBlock={ block } />;\n};\n\nconst ModifiedWarning = ( { originalBlock, ...props } ) => {\n\tconst { originalName, originalUndelimitedContent, clientId } =\n\t\tprops.attributes;\n\tconst { replaceBlock } = useDispatch( blockEditorStore );\n\tconst convertToHTML = () => {\n\t\treplaceBlock(\n\t\t\tprops.clientId,\n\t\t\tcreateBlock( 'core/html', {\n\t\t\t\tcontent: originalUndelimitedContent,\n\t\t\t} )\n\t\t);\n\t};\n\n\tconst hasContent = !! originalUndelimitedContent;\n\tconst hasHTMLBlock = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canInsertBlockType, getBlockRootClientId } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn canInsertBlockType(\n\t\t\t\t'core/html',\n\t\t\t\tgetBlockRootClientId( clientId )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tlet messageHTML = sprintf(\n\t\t/* translators: %s: block name */\n\t\t__(\n\t\t\t'Your site doesn’t include support for the %s block. You can try installing the block or remove it entirely.'\n\t\t),\n\t\toriginalBlock.title || originalName\n\t);\n\tconst actions = [\n\t\t<InstallButton\n\t\t\tkey=\"install\"\n\t\t\tblock={ originalBlock }\n\t\t\tattributes={ props.attributes }\n\t\t\tclientId={ props.clientId }\n\t\t/>,\n\t];\n\n\tif ( hasContent && hasHTMLBlock ) {\n\t\tmessageHTML = sprintf(\n\t\t\t/* translators: %s: block name */\n\t\t\t__(\n\t\t\t\t'Your site doesn’t include support for the %s block. You can try installing the block, convert it to a Custom HTML block, or remove it entirely.'\n\t\t\t),\n\t\t\toriginalBlock.title || originalName\n\t\t);\n\t\tactions.push(\n\t\t\t<Button key=\"convert\" onClick={ convertToHTML } variant=\"link\">\n\t\t\t\t{ __( 'Keep as HTML' ) }\n\t\t\t</Button>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div { ...useBlockProps() }>\n\t\t\t<Warning actions={ actions }>{ messageHTML }</Warning>\n\t\t\t<RawHTML>{ originalUndelimitedContent }</RawHTML>\n\t\t</div>\n\t);\n};\n\nexport default getInstallMissing;\n"]}
1
+ {"version":3,"sources":["@wordpress/block-directory/src/plugins/get-install-missing/index.js"],"names":["getInstallMissing","OriginalComponent","props","originalName","attributes","block","hasPermission","select","getDownloadableBlocks","blockDirectoryStore","blocks","filter","name","coreStore","canUser","length","ModifiedWarning","originalBlock","originalUndelimitedContent","clientId","replaceBlock","blockEditorStore","convertToHTML","content","hasContent","hasHTMLBlock","canInsertBlockType","getBlockRootClientId","messageHTML","title","actions","push"],"mappings":";;;;;;;;;AAMA;;;;AAHA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AASA;;AACA;;AAnBA;AACA;AACA;;AAaA;AACA;AACA;AAIA,MAAMA,iBAAiB,GAAKC,iBAAF,IAA2BC,KAAF,IAAa;AAC/D,QAAM;AAAEC,IAAAA;AAAF,MAAmBD,KAAK,CAACE,UAA/B,CAD+D,CAE/D;AACA;;AACA,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAA2B,qBAC9BC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA;AAAF,QAA4BD,MAAM,CAAEE,YAAF,CAAxC;AACA,UAAMC,MAAM,GAAGF,qBAAqB,CACnC,WAAWL,YADwB,CAArB,CAEbQ,MAFa,CAEL;AAAA,UAAE;AAAEC,QAAAA;AAAF,OAAF;AAAA,aAAgBT,Y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A,MAAIS,WAAW,GAAG;AACjB;AACA,gBACC,6GADD,CAFiB,EAKjBX,aAAa,CAACY,KAAd,IAAuB1B,YALN,CAAlB;AAOA,QAAM2B,OAAO,GAAG,CACf,4BAAC,sBAAD;AACC,IAAA,GAAG,EAAC,SADL;AAEC,IAAA,KAAK,EAAGb,aAFT;AAGC,IAAA,UAAU,EAAGf,KAAK,CAACE,UAHpB;AAIC,IAAA,QAAQ,EAAGF,KAAK,CAACiB;AAJlB,IADe,CAAhB;;AASA,MAAKK,UAAU,IAAIC,YAAnB,EAAkC;AACjCG,IAAAA,WAAW,GAAG;AACb;AACA,kBACC,iJADD,CAFa,EAKbX,aAAa,CAACY,KAAd,IAAuB1B,YALV,CAAd;AAOA2B,IAAAA,OAAO,CAACC,IAAR,CACC,4BAAC,kBAAD;AAAQ,MAAA,GAAG,EAAC,SAAZ;AAAsB,MAAA,OAAO,EAAGT,aAAhC;AAAgD,MAAA,OAAO,EAAC;AAAxD,OACG,cAAI,cAAJ,CADH,CADD;AAKA;;AAED,SACC,mCAAU,iCAAV,EACC,4BAAC,oBAAD;AAAS,IAAA,OAAO,EAAGQ;AAAnB,KAA+BF,WAA/B,CADD,EAEC,4BAAC,gBAAD,QAAWV,0BAAX,CAFD,CADD;AAMA,CAhED;;eAkEelB,iB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { createBlock } from '@wordpress/blocks';\nimport { RawHTML } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tWarning,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport InstallButton from './install-button';\nimport { store as blockDirectoryStore } from '../../store';\n\nconst getInstallMissing = ( OriginalComponent ) => ( props ) => {\n\tconst { originalName } = props.attributes;\n\t// Disable reason: This is a valid component, but it's mistaken for a callback.\n\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\tconst { block, hasPermission } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getDownloadableBlocks } = select( blockDirectoryStore );\n\t\t\tconst blocks = getDownloadableBlocks(\n\t\t\t\t'block:' + originalName\n\t\t\t).filter( ( { name } ) => originalName === name );\n\t\t\treturn {\n\t\t\t\thasPermission: select( coreStore ).canUser(\n\t\t\t\t\t'read',\n\t\t\t\t\t'block-directory/search'\n\t\t\t\t),\n\t\t\t\tblock: blocks.length && blocks[ 0 ],\n\t\t\t};\n\t\t},\n\t\t[ originalName ]\n\t);\n\n\t// The user can't install blocks, or the block isn't available for download.\n\tif ( ! hasPermission || ! block ) {\n\t\treturn <OriginalComponent { ...props } />;\n\t}\n\n\treturn <ModifiedWarning { ...props } originalBlock={ block } />;\n};\n\nconst ModifiedWarning = ( { originalBlock, ...props } ) => {\n\tconst { originalName, originalUndelimitedContent, clientId } =\n\t\tprops.attributes;\n\tconst { replaceBlock } = useDispatch( blockEditorStore );\n\tconst convertToHTML = () => {\n\t\treplaceBlock(\n\t\t\tprops.clientId,\n\t\t\tcreateBlock( 'core/html', {\n\t\t\t\tcontent: originalUndelimitedContent,\n\t\t\t} )\n\t\t);\n\t};\n\n\tconst hasContent = !! originalUndelimitedContent;\n\tconst hasHTMLBlock = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canInsertBlockType, getBlockRootClientId } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn canInsertBlockType(\n\t\t\t\t'core/html',\n\t\t\t\tgetBlockRootClientId( clientId )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tlet messageHTML = sprintf(\n\t\t/* translators: %s: block name */\n\t\t__(\n\t\t\t'Your site doesn’t include support for the %s block. You can try installing the block or remove it entirely.'\n\t\t),\n\t\toriginalBlock.title || originalName\n\t);\n\tconst actions = [\n\t\t<InstallButton\n\t\t\tkey=\"install\"\n\t\t\tblock={ originalBlock }\n\t\t\tattributes={ props.attributes }\n\t\t\tclientId={ props.clientId }\n\t\t/>,\n\t];\n\n\tif ( hasContent && hasHTMLBlock ) {\n\t\tmessageHTML = sprintf(\n\t\t\t/* translators: %s: block name */\n\t\t\t__(\n\t\t\t\t'Your site doesn’t include support for the %s block. You can try installing the block, convert it to a Custom HTML block, or remove it entirely.'\n\t\t\t),\n\t\t\toriginalBlock.title || originalName\n\t\t);\n\t\tactions.push(\n\t\t\t<Button key=\"convert\" onClick={ convertToHTML } variant=\"tertiary\">\n\t\t\t\t{ __( 'Keep as HTML' ) }\n\t\t\t</Button>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div { ...useBlockProps() }>\n\t\t\t<Warning actions={ actions }>{ messageHTML }</Warning>\n\t\t\t<RawHTML>{ originalUndelimitedContent }</RawHTML>\n\t\t</div>\n\t);\n};\n\nexport default getInstallMissing;\n"]}
@@ -15,8 +15,6 @@ exports.setErrorNotice = setErrorNotice;
15
15
  exports.setIsInstalling = setIsInstalling;
16
16
  exports.uninstallBlockType = void 0;
17
17
 
18
- var _lodash = require("lodash");
19
-
20
18
  var _blocks = require("@wordpress/blocks");
21
19
 
22
20
  var _i18n = require("@wordpress/i18n");
@@ -31,10 +29,6 @@ var _loadAssets = require("./load-assets");
31
29
 
32
30
  var _getPluginUrl = _interopRequireDefault(require("./utils/get-plugin-url"));
33
31
 
34
- /**
35
- * External dependencies
36
- */
37
-
38
32
  /**
39
33
  * WordPress dependencies
40
34
  */
@@ -141,7 +135,10 @@ const installBlockType = block => async _ref => {
141
135
  }
142
136
 
143
137
  (0, _blocks.unstable__bootstrapServerSideBlockDefinitions)({
144
- [name]: (0, _lodash.pick)(response, metadataFields)
138
+ [name]: Object.fromEntries(Object.entries(response).filter(_ref2 => {
139
+ let [key] = _ref2;
140
+ return metadataFields.includes(key);
141
+ }))
145
142
  });
146
143
  });
147
144
  await (0, _loadAssets.loadAssets)();
@@ -191,11 +188,11 @@ const installBlockType = block => async _ref => {
191
188
 
192
189
  exports.installBlockType = installBlockType;
193
190
 
194
- const uninstallBlockType = block => async _ref2 => {
191
+ const uninstallBlockType = block => async _ref3 => {
195
192
  let {
196
193
  registry,
197
194
  dispatch
198
- } = _ref2;
195
+ } = _ref3;
199
196
 
200
197
  try {
201
198
  const url = (0, _getPluginUrl.default)(block);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","name","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","metadataFields","_fields","catch","then","registeredBlocks","select","blocksStore","getBlockTypes","some","i","Error","noticesStore","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":";;;;;;;;;;;;;;;;;AAGA;;AAKA;;AAIA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AArBA;AACA;AACA;;AAGA;AACA;AACA;;AAUA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,uBAAT,CAAkCC,WAAlC,EAAgD;AACtD,SAAO;AAAEC,IAAAA,IAAI,EAAE,2BAAR;AAAqCD,IAAAA;AAArC,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,yBAAT,CAAoCC,kBAApC,EAAwDH,WAAxD,EAAsE;AAC5E,SAAO;AACNC,IAAAA,IAAI,EAAE,6BADA;AAENE,IAAAA,kBAFM;AAGNH,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMI,gBAAgB,GAC1BC,KAAF,IACA,cAAoC;AAAA,MAA5B;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAA4B;AACnC,QAAM;AAAEC,IAAAA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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASD,wBAAT,CAAmCC,IAAnC,EAA0C;AAChD,SAAO;AACNjD,IAAAA,IAAI,EAAE,6BADA;AAENiD,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAAStC,eAAT,CAA0BuC,OAA1B,EAAmCC,YAAnC,EAAkD;AACxD,SAAO;AACNnD,IAAAA,IAAI,EAAE,sBADA;AAENkD,IAAAA,OAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASP,cAAT,CAAyBM,OAAzB,EAAkCZ,OAAlC,EAA6D;AAAA,MAAlBC,OAAkB,uEAAR,KAAQ;AACnE,SAAO;AACNvC,IAAAA,IAAI,EAAE,kBADA;AAENkD,IAAAA,OAFM;AAGNZ,IAAAA,OAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAAS7B,gBAAT,CAA2BwC,OAA3B,EAAqC;AAC3C,SAAO;AACNlD,IAAAA,IAAI,EAAE,oBADA;AAENkD,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { pick } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tstore as blocksStore,\n\tunstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase\n} from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './load-assets';\nimport getPluginUrl from './utils/get-plugin-url';\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been requested and are loading.\n *\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function fetchDownloadableBlocks( filterValue ) {\n\treturn { type: 'FETCH_DOWNLOADABLE_BLOCKS', filterValue };\n}\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been updated.\n *\n * @param {Array} downloadableBlocks Downloadable blocks.\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function receiveDownloadableBlocks( downloadableBlocks, filterValue ) {\n\treturn {\n\t\ttype: 'RECEIVE_DOWNLOADABLE_BLOCKS',\n\t\tdownloadableBlocks,\n\t\tfilterValue,\n\t};\n}\n\n/**\n * Action triggered to install a block plugin.\n *\n * @param {Object} block The block item returned by search.\n *\n * @return {boolean} Whether the block was successfully installed & loaded.\n */\nexport const installBlockType =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\tconst { id, name } = block;\n\t\tlet success = false;\n\t\tdispatch.clearErrorNotice( id );\n\t\ttry {\n\t\t\tdispatch.setIsInstalling( id, true );\n\n\t\t\t// If we have a wp:plugin link, the plugin is installed but inactive.\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tlet links = {};\n\t\t\tif ( url ) {\n\t\t\t\tawait apiFetch( {\n\t\t\t\t\tmethod: 'PUT',\n\t\t\t\t\turl,\n\t\t\t\t\tdata: { status: 'active' },\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tconst response = await apiFetch( {\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\t\tdata: { slug: id, status: 'active' },\n\t\t\t\t} );\n\t\t\t\t// Add the `self` link for newly-installed blocks.\n\t\t\t\tlinks = response._links;\n\t\t\t}\n\n\t\t\tdispatch.addInstalledBlockType( {\n\t\t\t\t...block,\n\t\t\t\tlinks: { ...block.links, ...links },\n\t\t\t} );\n\n\t\t\t// Ensures that the block metadata is propagated to the editor when registered on the server.\n\t\t\tconst metadataFields = [\n\t\t\t\t'api_version',\n\t\t\t\t'title',\n\t\t\t\t'category',\n\t\t\t\t'parent',\n\t\t\t\t'icon',\n\t\t\t\t'description',\n\t\t\t\t'keywords',\n\t\t\t\t'attributes',\n\t\t\t\t'provides_context',\n\t\t\t\t'uses_context',\n\t\t\t\t'supports',\n\t\t\t\t'styles',\n\t\t\t\t'example',\n\t\t\t\t'variations',\n\t\t\t];\n\t\t\tawait apiFetch( {\n\t\t\t\tpath: addQueryArgs( `/wp/v2/block-types/${ name }`, {\n\t\t\t\t\t_fields: metadataFields,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t// Ignore when the block is not registered on the server.\n\t\t\t\t.catch( () => {} )\n\t\t\t\t.then( ( response ) => {\n\t\t\t\t\tif ( ! response ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tunstable__bootstrapServerSideBlockDefinitions( {\n\t\t\t\t\t\t[ name ]: pick( response, metadataFields ),\n\t\t\t\t\t} );\n\t\t\t\t} );\n\n\t\t\tawait loadAssets();\n\t\t\tconst registeredBlocks = registry\n\t\t\t\t.select( blocksStore )\n\t\t\t\t.getBlockTypes();\n\t\t\tif ( ! registeredBlocks.some( ( i ) => i.name === name ) ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tregistry.dispatch( noticesStore ).createInfoNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s is the block title.\n\t\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\t\tblock.title\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\tspeak: true,\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t\tsuccess = true;\n\t\t} catch ( error ) {\n\t\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t\t// Errors we throw are fatal.\n\t\t\tlet isFatal = error instanceof Error;\n\n\t\t\t// Specific API errors that are fatal.\n\t\t\tconst fatalAPIErrors = {\n\t\t\t\tfolder_exists: __(\n\t\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t\t),\n\t\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t\t),\n\t\t\t};\n\n\t\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\t\tisFatal = true;\n\t\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t\t}\n\n\t\t\tdispatch.setErrorNotice( id, message, isFatal );\n\t\t\tregistry.dispatch( noticesStore ).createErrorNotice( message, {\n\t\t\t\tspeak: true,\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t}\n\t\tdispatch.setIsInstalling( id, false );\n\t\treturn success;\n\t};\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport const uninstallBlockType =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\ttry {\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl,\n\t\t\t\tdata: { status: 'inactive' },\n\t\t\t} );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\turl,\n\t\t\t} );\n\t\t\tdispatch.removeInstalledBlockType( block );\n\t\t} catch ( error ) {\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createErrorNotice(\n\t\t\t\t\terror.message || __( 'An error occurred.' )\n\t\t\t\t);\n\t\t}\n\t};\n\n/**\n * Returns an action object used to add a block type to the \"newly installed\"\n * tracking list.\n *\n * @param {Object} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function addInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'ADD_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to remove a block type from the \"newly installed\"\n * tracking list.\n *\n * @param {string} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function removeInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'REMOVE_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to indicate install in progress.\n *\n * @param {string} blockId\n * @param {boolean} isInstalling\n *\n * @return {Object} Action object.\n */\nexport function setIsInstalling( blockId, isInstalling ) {\n\treturn {\n\t\ttype: 'SET_INSTALLING_BLOCK',\n\t\tblockId,\n\t\tisInstalling,\n\t};\n}\n\n/**\n * Sets an error notice to be displayed to the user for a given block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n * @param {string} message The message shown in the notice.\n * @param {boolean} isFatal Whether the user can recover from the error.\n *\n * @return {Object} Action object.\n */\nexport function setErrorNotice( blockId, message, isFatal = false ) {\n\treturn {\n\t\ttype: 'SET_ERROR_NOTICE',\n\t\tblockId,\n\t\tmessage,\n\t\tisFatal,\n\t};\n}\n\n/**\n * Sets the error notice to empty for specific block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {Object} Action object.\n */\nexport function clearErrorNotice( blockId ) {\n\treturn {\n\t\ttype: 'CLEAR_ERROR_NOTICE',\n\t\tblockId,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","name","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","metadataFields","_fields","catch","then","Object","fromEntries","entries","filter","key","includes","registeredBlocks","select","blocksStore","getBlockTypes","some","i","Error","noticesStore","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":";;;;;;;;;;;;;;;;;AAGA;;AAIA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAhBA;AACA;AACA;;AAUA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,uBAAT,CAA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;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASnC,gBAAT,CAA2B8C,OAA3B,EAAqC;AAC3C,SAAO;AACNxD,IAAAA,IAAI,EAAE,oBADA;AAENwD,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tstore as blocksStore,\n\tunstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase\n} from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './load-assets';\nimport getPluginUrl from './utils/get-plugin-url';\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been requested and are loading.\n *\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function fetchDownloadableBlocks( filterValue ) {\n\treturn { type: 'FETCH_DOWNLOADABLE_BLOCKS', filterValue };\n}\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been updated.\n *\n * @param {Array} downloadableBlocks Downloadable blocks.\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function receiveDownloadableBlocks( downloadableBlocks, filterValue ) {\n\treturn {\n\t\ttype: 'RECEIVE_DOWNLOADABLE_BLOCKS',\n\t\tdownloadableBlocks,\n\t\tfilterValue,\n\t};\n}\n\n/**\n * Action triggered to install a block plugin.\n *\n * @param {Object} block The block item returned by search.\n *\n * @return {boolean} Whether the block was successfully installed & loaded.\n */\nexport const installBlockType =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\tconst { id, name } = block;\n\t\tlet success = false;\n\t\tdispatch.clearErrorNotice( id );\n\t\ttry {\n\t\t\tdispatch.setIsInstalling( id, true );\n\n\t\t\t// If we have a wp:plugin link, the plugin is installed but inactive.\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tlet links = {};\n\t\t\tif ( url ) {\n\t\t\t\tawait apiFetch( {\n\t\t\t\t\tmethod: 'PUT',\n\t\t\t\t\turl,\n\t\t\t\t\tdata: { status: 'active' },\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tconst response = await apiFetch( {\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\t\tdata: { slug: id, status: 'active' },\n\t\t\t\t} );\n\t\t\t\t// Add the `self` link for newly-installed blocks.\n\t\t\t\tlinks = response._links;\n\t\t\t}\n\n\t\t\tdispatch.addInstalledBlockType( {\n\t\t\t\t...block,\n\t\t\t\tlinks: { ...block.links, ...links },\n\t\t\t} );\n\n\t\t\t// Ensures that the block metadata is propagated to the editor when registered on the server.\n\t\t\tconst metadataFields = [\n\t\t\t\t'api_version',\n\t\t\t\t'title',\n\t\t\t\t'category',\n\t\t\t\t'parent',\n\t\t\t\t'icon',\n\t\t\t\t'description',\n\t\t\t\t'keywords',\n\t\t\t\t'attributes',\n\t\t\t\t'provides_context',\n\t\t\t\t'uses_context',\n\t\t\t\t'supports',\n\t\t\t\t'styles',\n\t\t\t\t'example',\n\t\t\t\t'variations',\n\t\t\t];\n\t\t\tawait apiFetch( {\n\t\t\t\tpath: addQueryArgs( `/wp/v2/block-types/${ name }`, {\n\t\t\t\t\t_fields: metadataFields,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t// Ignore when the block is not registered on the server.\n\t\t\t\t.catch( () => {} )\n\t\t\t\t.then( ( response ) => {\n\t\t\t\t\tif ( ! response ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tunstable__bootstrapServerSideBlockDefinitions( {\n\t\t\t\t\t\t[ name ]: Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries( response ).filter( ( [ key ] ) =>\n\t\t\t\t\t\t\t\tmetadataFields.includes( key )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t} );\n\t\t\t\t} );\n\n\t\t\tawait loadAssets();\n\t\t\tconst registeredBlocks = registry\n\t\t\t\t.select( blocksStore )\n\t\t\t\t.getBlockTypes();\n\t\t\tif ( ! registeredBlocks.some( ( i ) => i.name === name ) ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tregistry.dispatch( noticesStore ).createInfoNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s is the block title.\n\t\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\t\tblock.title\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\tspeak: true,\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t\tsuccess = true;\n\t\t} catch ( error ) {\n\t\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t\t// Errors we throw are fatal.\n\t\t\tlet isFatal = error instanceof Error;\n\n\t\t\t// Specific API errors that are fatal.\n\t\t\tconst fatalAPIErrors = {\n\t\t\t\tfolder_exists: __(\n\t\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t\t),\n\t\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t\t),\n\t\t\t};\n\n\t\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\t\tisFatal = true;\n\t\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t\t}\n\n\t\t\tdispatch.setErrorNotice( id, message, isFatal );\n\t\t\tregistry.dispatch( noticesStore ).createErrorNotice( message, {\n\t\t\t\tspeak: true,\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t}\n\t\tdispatch.setIsInstalling( id, false );\n\t\treturn success;\n\t};\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport const uninstallBlockType =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\ttry {\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl,\n\t\t\t\tdata: { status: 'inactive' },\n\t\t\t} );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\turl,\n\t\t\t} );\n\t\t\tdispatch.removeInstalledBlockType( block );\n\t\t} catch ( error ) {\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createErrorNotice(\n\t\t\t\t\terror.message || __( 'An error occurred.' )\n\t\t\t\t);\n\t\t}\n\t};\n\n/**\n * Returns an action object used to add a block type to the \"newly installed\"\n * tracking list.\n *\n * @param {Object} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function addInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'ADD_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to remove a block type from the \"newly installed\"\n * tracking list.\n *\n * @param {string} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function removeInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'REMOVE_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to indicate install in progress.\n *\n * @param {string} blockId\n * @param {boolean} isInstalling\n *\n * @return {Object} Action object.\n */\nexport function setIsInstalling( blockId, isInstalling ) {\n\treturn {\n\t\ttype: 'SET_INSTALLING_BLOCK',\n\t\tblockId,\n\t\tisInstalling,\n\t};\n}\n\n/**\n * Sets an error notice to be displayed to the user for a given block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n * @param {string} message The message shown in the notice.\n * @param {boolean} isFatal Whether the user can recover from the error.\n *\n * @return {Object} Action object.\n */\nexport function setErrorNotice( blockId, message, isFatal = false ) {\n\treturn {\n\t\ttype: 'SET_ERROR_NOTICE',\n\t\tblockId,\n\t\tmessage,\n\t\tisFatal,\n\t};\n}\n\n/**\n * Sets the error notice to empty for specific block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {Object} Action object.\n */\nexport function clearErrorNotice( blockId ) {\n\treturn {\n\t\ttype: 'CLEAR_ERROR_NOTICE',\n\t\tblockId,\n\t};\n}\n"]}
@@ -97,7 +97,7 @@ const ModifiedWarning = _ref2 => {
97
97
  actions.push(createElement(Button, {
98
98
  key: "convert",
99
99
  onClick: convertToHTML,
100
- variant: "link"
100
+ variant: "tertiary"
101
101
  }, __('Keep as HTML')));
102
102
  }
103
103
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-directory/src/plugins/get-install-missing/index.js"],"names":["__","sprintf","Button","createBlock","RawHTML","useDispatch","useSelect","store","coreStore","Warning","useBlockProps","blockEditorStore","InstallButton","blockDirectoryStore","getInstallMissing","OriginalComponent","props","originalName","attributes","block","hasPermission","select","getDownloadableBlocks","blocks","filter","name","canUser","length","ModifiedWarning","originalBlock","originalUndelimitedContent","clientId","replaceBlock","convertToHTML","content","hasContent","hasHTMLBlock","canInsertBlockType","getBlockRootClientId","messageHTML","title","actions","push"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,MAAT,QAAuB,uBAAvB;AACA,SAASC,WAAT,QAA4B,mBAA5B;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SACCC,OADD,EAECC,aAFD,EAGCH,KAAK,IAAII,gBAHV,QAIO,yBAJP;AAMA;AACA;AACA;;AACA,OAAOC,aAAP,MAA0B,kBAA1B;AACA,SAASL,KAAK,IAAIM,mBAAlB,QAA6C,aAA7C;;AAEA,MAAMC,iBAAiB,GAAKC,iBAAF,IAA2BC,KAAF,IAAa;AAC/D,QAAM;AAAEC,IAAAA;AAAF,MAAmBD,KAAK,CAACE,UAA/B,CAD+D,CAE/D;AACA;;AACA,QAAM;AAAE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AAC,CAAEL,0BAAtB;AACA,QAAMM,YAAY,GAAG9B,SAAS,CAC3Be,MAAF,IAAc;AACb,UAAM;AAAEgB,MAAAA,kBAAF;AAAsBC,MAAAA;AAAtB,QACLjB,MAAM,CAAEV,gBAAF,CADP;AAGA,WAAO0B,kBAAkB,CACxB,WADwB,EAExBC,oBAAoB,CAAEP,QAAF,CAFI,CAAzB;AAIA,GAT4B,EAU7B,CAAEA,QAAF,CAV6B,CAA9B;AAaA,MAAIQ,WAAW,GAAGtC,OAAO;AACxB;AACAD,EAAAA,EAAE,CACD,6GADC,CAFsB,EAKxB6B,aAAa,CAACW,KAAd,IAAuBvB,YALC,CAAzB;AAOA,QAAMwB,OAAO,GAAG,CACf,cAAC,aAAD;AACC,IAAA,GAAG,EAAC,SADL;AAEC,IAAA,KAAK,EAAGZ,aAFT;AAGC,IAAA,UAAU,EAAGb,KAAK,CAACE,UAHpB;AAIC,IAAA,QAAQ,EAAGF,KAAK,CAACe;AAJlB,IADe,CAAhB;;AASA,MAAKI,UAAU,IAAIC,YAAnB,EAAkC;AACjCG,IAAAA,WAAW,GAAGtC,OAAO;AACpB;AACAD,IAAAA,EAAE,CACD,iJADC,CAFkB,EAKpB6B,aAAa,CAACW,KAAd,IAAuBvB,YALH,CAArB;AAOAwB,IAAAA,OAAO,CAACC,IAAR,CACC,cAAC,MAAD;AAAQ,MAAA,GAAG,EAAC,SAAZ;AAAsB,MAAA,OAAO,EAAGT,aAAhC;AAAgD,MAAA,OAAO,EAAC;AAAxD,OACGjC,EAAE,CAAE,cAAF,CADL,CADD;AAKA;;AAED,SACC,qBAAUU,aAAa,EAAvB,EACC,cAAC,OAAD;AAAS,IAAA,OAAO,EAAG+B;AAAnB,KAA+BF,WAA/B,CADD,EAEC,cAAC,OAAD,QAAWT,0BAAX,CAFD,CADD;AAMA,CAhED;;AAkEA,eAAehB,iBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { createBlock } from '@wordpress/blocks';\nimport { RawHTML } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tWarning,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport InstallButton from './install-button';\nimport { store as blockDirectoryStore } from '../../store';\n\nconst getInstallMissing = ( OriginalComponent ) => ( props ) => {\n\tconst { originalName } = props.attributes;\n\t// Disable reason: This is a valid component, but it's mistaken for a callback.\n\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\tconst { block, hasPermission } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getDownloadableBlocks } = select( blockDirectoryStore );\n\t\t\tconst blocks = getDownloadableBlocks(\n\t\t\t\t'block:' + originalName\n\t\t\t).filter( ( { name } ) => originalName === name );\n\t\t\treturn {\n\t\t\t\thasPermission: select( coreStore ).canUser(\n\t\t\t\t\t'read',\n\t\t\t\t\t'block-directory/search'\n\t\t\t\t),\n\t\t\t\tblock: blocks.length && blocks[ 0 ],\n\t\t\t};\n\t\t},\n\t\t[ originalName ]\n\t);\n\n\t// The user can't install blocks, or the block isn't available for download.\n\tif ( ! hasPermission || ! block ) {\n\t\treturn <OriginalComponent { ...props } />;\n\t}\n\n\treturn <ModifiedWarning { ...props } originalBlock={ block } />;\n};\n\nconst ModifiedWarning = ( { originalBlock, ...props } ) => {\n\tconst { originalName, originalUndelimitedContent, clientId } =\n\t\tprops.attributes;\n\tconst { replaceBlock } = useDispatch( blockEditorStore );\n\tconst convertToHTML = () => {\n\t\treplaceBlock(\n\t\t\tprops.clientId,\n\t\t\tcreateBlock( 'core/html', {\n\t\t\t\tcontent: originalUndelimitedContent,\n\t\t\t} )\n\t\t);\n\t};\n\n\tconst hasContent = !! originalUndelimitedContent;\n\tconst hasHTMLBlock = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canInsertBlockType, getBlockRootClientId } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn canInsertBlockType(\n\t\t\t\t'core/html',\n\t\t\t\tgetBlockRootClientId( clientId )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tlet messageHTML = sprintf(\n\t\t/* translators: %s: block name */\n\t\t__(\n\t\t\t'Your site doesn’t include support for the %s block. You can try installing the block or remove it entirely.'\n\t\t),\n\t\toriginalBlock.title || originalName\n\t);\n\tconst actions = [\n\t\t<InstallButton\n\t\t\tkey=\"install\"\n\t\t\tblock={ originalBlock }\n\t\t\tattributes={ props.attributes }\n\t\t\tclientId={ props.clientId }\n\t\t/>,\n\t];\n\n\tif ( hasContent && hasHTMLBlock ) {\n\t\tmessageHTML = sprintf(\n\t\t\t/* translators: %s: block name */\n\t\t\t__(\n\t\t\t\t'Your site doesn’t include support for the %s block. You can try installing the block, convert it to a Custom HTML block, or remove it entirely.'\n\t\t\t),\n\t\t\toriginalBlock.title || originalName\n\t\t);\n\t\tactions.push(\n\t\t\t<Button key=\"convert\" onClick={ convertToHTML } variant=\"link\">\n\t\t\t\t{ __( 'Keep as HTML' ) }\n\t\t\t</Button>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div { ...useBlockProps() }>\n\t\t\t<Warning actions={ actions }>{ messageHTML }</Warning>\n\t\t\t<RawHTML>{ originalUndelimitedContent }</RawHTML>\n\t\t</div>\n\t);\n};\n\nexport default getInstallMissing;\n"]}
1
+ {"version":3,"sources":["@wordpress/block-directory/src/plugins/get-install-missing/index.js"],"names":["__","sprintf","Button","createBlock","RawHTML","useDispatch","useSelect","store","coreStore","Warning","useBlockProps","blockEditorStore","InstallButton","blockDirectoryStore","getInstallMissing","OriginalComponent","props","originalName","attributes","block","hasPermission","select","getDownloadableBlocks","blocks","filter","name","canUser","length","ModifiedWarning","originalBlock","originalUndelimitedContent","clientId","replaceBlock","convertToHTML","content","hasContent","hasHTMLBlock","canInsertBlockType","getBlockRootClientId","messageHTML","title","actions","push"],"mappings":";;;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kC;AACjCG,IAAAA,WAAW,GAAGtC,OAAO;AACpB;AACAD,IAAAA,EAAE,CACD,iJADC,CAFkB,EAKpB6B,aAAa,CAACW,KAAd,IAAuBvB,YALH,CAArB;AAOAwB,IAAAA,OAAO,CAACC,IAAR,CACC,cAAC,MAAD;AAAQ,MAAA,GAAG,EAAC,SAAZ;AAAsB,MAAA,OAAO,EAAGT,aAAhC;AAAgD,MAAA,OAAO,EAAC;AAAxD,OACGjC,EAAE,CAAE,cAAF,CADL,CADD;AAKA;;AAED,SACC,qBAAUU,aAAa,EAAvB,EACC,cAAC,OAAD;AAAS,IAAA,OAAO,EAAG+B;AAAnB,KAA+BF,WAA/B,CADD,EAEC,cAAC,OAAD,QAAWT,0BAAX,CAFD,CADD;AAMA,CAhED;;AAkEA,eAAehB,iBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { createBlock } from '@wordpress/blocks';\nimport { RawHTML } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tWarning,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport InstallButton from './install-button';\nimport { store as blockDirectoryStore } from '../../store';\n\nconst getInstallMissing = ( OriginalComponent ) => ( props ) => {\n\tconst { originalName } = props.attributes;\n\t// Disable reason: This is a valid component, but it's mistaken for a callback.\n\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\tconst { block, hasPermission } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getDownloadableBlocks } = select( blockDirectoryStore );\n\t\t\tconst blocks = getDownloadableBlocks(\n\t\t\t\t'block:' + originalName\n\t\t\t).filter( ( { name } ) => originalName === name );\n\t\t\treturn {\n\t\t\t\thasPermission: select( coreStore ).canUser(\n\t\t\t\t\t'read',\n\t\t\t\t\t'block-directory/search'\n\t\t\t\t),\n\t\t\t\tblock: blocks.length && blocks[ 0 ],\n\t\t\t};\n\t\t},\n\t\t[ originalName ]\n\t);\n\n\t// The user can't install blocks, or the block isn't available for download.\n\tif ( ! hasPermission || ! block ) {\n\t\treturn <OriginalComponent { ...props } />;\n\t}\n\n\treturn <ModifiedWarning { ...props } originalBlock={ block } />;\n};\n\nconst ModifiedWarning = ( { originalBlock, ...props } ) => {\n\tconst { originalName, originalUndelimitedContent, clientId } =\n\t\tprops.attributes;\n\tconst { replaceBlock } = useDispatch( blockEditorStore );\n\tconst convertToHTML = () => {\n\t\treplaceBlock(\n\t\t\tprops.clientId,\n\t\t\tcreateBlock( 'core/html', {\n\t\t\t\tcontent: originalUndelimitedContent,\n\t\t\t} )\n\t\t);\n\t};\n\n\tconst hasContent = !! originalUndelimitedContent;\n\tconst hasHTMLBlock = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canInsertBlockType, getBlockRootClientId } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn canInsertBlockType(\n\t\t\t\t'core/html',\n\t\t\t\tgetBlockRootClientId( clientId )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tlet messageHTML = sprintf(\n\t\t/* translators: %s: block name */\n\t\t__(\n\t\t\t'Your site doesn’t include support for the %s block. You can try installing the block or remove it entirely.'\n\t\t),\n\t\toriginalBlock.title || originalName\n\t);\n\tconst actions = [\n\t\t<InstallButton\n\t\t\tkey=\"install\"\n\t\t\tblock={ originalBlock }\n\t\t\tattributes={ props.attributes }\n\t\t\tclientId={ props.clientId }\n\t\t/>,\n\t];\n\n\tif ( hasContent && hasHTMLBlock ) {\n\t\tmessageHTML = sprintf(\n\t\t\t/* translators: %s: block name */\n\t\t\t__(\n\t\t\t\t'Your site doesn’t include support for the %s block. You can try installing the block, convert it to a Custom HTML block, or remove it entirely.'\n\t\t\t),\n\t\t\toriginalBlock.title || originalName\n\t\t);\n\t\tactions.push(\n\t\t\t<Button key=\"convert\" onClick={ convertToHTML } variant=\"tertiary\">\n\t\t\t\t{ __( 'Keep as HTML' ) }\n\t\t\t</Button>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div { ...useBlockProps() }>\n\t\t\t<Warning actions={ actions }>{ messageHTML }</Warning>\n\t\t\t<RawHTML>{ originalUndelimitedContent }</RawHTML>\n\t\t</div>\n\t);\n};\n\nexport default getInstallMissing;\n"]}
@@ -1,11 +1,6 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { pick } from 'lodash';
5
1
  /**
6
2
  * WordPress dependencies
7
3
  */
8
-
9
4
  import { store as blocksStore, unstable__bootstrapServerSideBlockDefinitions // eslint-disable-line camelcase
10
5
  } from '@wordpress/blocks';
11
6
  import { __, sprintf } from '@wordpress/i18n';
@@ -115,7 +110,10 @@ export const installBlockType = block => async _ref => {
115
110
  }
116
111
 
117
112
  unstable__bootstrapServerSideBlockDefinitions({
118
- [name]: pick(response, metadataFields)
113
+ [name]: Object.fromEntries(Object.entries(response).filter(_ref2 => {
114
+ let [key] = _ref2;
115
+ return metadataFields.includes(key);
116
+ }))
119
117
  });
120
118
  });
121
119
  await loadAssets();
@@ -163,11 +161,11 @@ export const installBlockType = block => async _ref => {
163
161
  * @param {Object} block The blockType object.
164
162
  */
165
163
 
166
- export const uninstallBlockType = block => async _ref2 => {
164
+ export const uninstallBlockType = block => async _ref3 => {
167
165
  let {
168
166
  registry,
169
167
  dispatch
170
- } = _ref2;
168
+ } = _ref3;
171
169
 
172
170
  try {
173
171
  const url = getPluginUrl(block);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["pick","store","blocksStore","unstable__bootstrapServerSideBlockDefinitions","__","sprintf","apiFetch","noticesStore","addQueryArgs","loadAssets","getPluginUrl","fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","name","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","metadataFields","_fields","catch","then","registeredBlocks","select","getBlockTypes","some","i","Error","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,QAArB;AAEA;AACA;AACA;;AACA,SACCC,KAAK,IAAIC,WADV,EAECC,6CAFD,CAEgD;AAFhD,OAGO,mBAHP;AAIA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AACA,SAASL,KAAK,IAAIM,YAAlB,QAAsC,oBAAtC;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,eAA3B;AACA,OAAOC,YAAP,MAAyB,wBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,uBAAT,CAAkCC,WAAlC,EAAgD;AACtD,SAAO;AAAEC,IAAAA,IAAI,EAAE,2BAAR;AAAqCD,IAAAA;AAArC,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,yBAAT,CAAoCC,kBAApC,EAAwDH,WAAxD,EAAsE;AAC5E,SAAO;AACNC,IAAAA,IAAI,EAAE,6BADA;AAENE,IAAAA,kBAFM;AAGNH,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMI,gBAAgB,GAC1BC,KAAF,IACA,cAAoC;AAAA,MAA5B;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAA4B;AACnC,QAAM;AAAEC,IAAAA,EAAF;AAAMC,IAAAA;AAAN,MAAeJ,KAArB;AACA,MAAIK,OAAO,GAAG,KAAd;AACAH,EAAAA,QAAQ,CAACI,gBAAT,CAA2BH,EAA3B;;AACA,MAAI;AACHD,IAAA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0BADA;AAEN+C,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASD,wBAAT,CAAmCC,IAAnC,EAA0C;AAChD,SAAO;AACN/C,IAAAA,IAAI,EAAE,6BADA;AAEN+C,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASpC,eAAT,CAA0BqC,OAA1B,EAAmCC,YAAnC,EAAkD;AACxD,SAAO;AACNjD,IAAAA,IAAI,EAAE,sBADA;AAENgD,IAAAA,OAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASP,cAAT,CAAyBM,OAAzB,EAAkCZ,OAAlC,EAA6D;AAAA,MAAlBC,OAAkB,uEAAR,KAAQ;AACnE,SAAO;AACNrC,IAAAA,IAAI,EAAE,kBADA;AAENgD,IAAAA,OAFM;AAGNZ,IAAAA,OAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAS3B,gBAAT,CAA2BsC,OAA3B,EAAqC;AAC3C,SAAO;AACNhD,IAAAA,IAAI,EAAE,oBADA;AAENgD,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { pick } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tstore as blocksStore,\n\tunstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase\n} from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './load-assets';\nimport getPluginUrl from './utils/get-plugin-url';\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been requested and are loading.\n *\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function fetchDownloadableBlocks( filterValue ) {\n\treturn { type: 'FETCH_DOWNLOADABLE_BLOCKS', filterValue };\n}\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been updated.\n *\n * @param {Array} downloadableBlocks Downloadable blocks.\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function receiveDownloadableBlocks( downloadableBlocks, filterValue ) {\n\treturn {\n\t\ttype: 'RECEIVE_DOWNLOADABLE_BLOCKS',\n\t\tdownloadableBlocks,\n\t\tfilterValue,\n\t};\n}\n\n/**\n * Action triggered to install a block plugin.\n *\n * @param {Object} block The block item returned by search.\n *\n * @return {boolean} Whether the block was successfully installed & loaded.\n */\nexport const installBlockType =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\tconst { id, name } = block;\n\t\tlet success = false;\n\t\tdispatch.clearErrorNotice( id );\n\t\ttry {\n\t\t\tdispatch.setIsInstalling( id, true );\n\n\t\t\t// If we have a wp:plugin link, the plugin is installed but inactive.\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tlet links = {};\n\t\t\tif ( url ) {\n\t\t\t\tawait apiFetch( {\n\t\t\t\t\tmethod: 'PUT',\n\t\t\t\t\turl,\n\t\t\t\t\tdata: { status: 'active' },\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tconst response = await apiFetch( {\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\t\tdata: { slug: id, status: 'active' },\n\t\t\t\t} );\n\t\t\t\t// Add the `self` link for newly-installed blocks.\n\t\t\t\tlinks = response._links;\n\t\t\t}\n\n\t\t\tdispatch.addInstalledBlockType( {\n\t\t\t\t...block,\n\t\t\t\tlinks: { ...block.links, ...links },\n\t\t\t} );\n\n\t\t\t// Ensures that the block metadata is propagated to the editor when registered on the server.\n\t\t\tconst metadataFields = [\n\t\t\t\t'api_version',\n\t\t\t\t'title',\n\t\t\t\t'category',\n\t\t\t\t'parent',\n\t\t\t\t'icon',\n\t\t\t\t'description',\n\t\t\t\t'keywords',\n\t\t\t\t'attributes',\n\t\t\t\t'provides_context',\n\t\t\t\t'uses_context',\n\t\t\t\t'supports',\n\t\t\t\t'styles',\n\t\t\t\t'example',\n\t\t\t\t'variations',\n\t\t\t];\n\t\t\tawait apiFetch( {\n\t\t\t\tpath: addQueryArgs( `/wp/v2/block-types/${ name }`, {\n\t\t\t\t\t_fields: metadataFields,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t// Ignore when the block is not registered on the server.\n\t\t\t\t.catch( () => {} )\n\t\t\t\t.then( ( response ) => {\n\t\t\t\t\tif ( ! response ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tunstable__bootstrapServerSideBlockDefinitions( {\n\t\t\t\t\t\t[ name ]: pick( response, metadataFields ),\n\t\t\t\t\t} );\n\t\t\t\t} );\n\n\t\t\tawait loadAssets();\n\t\t\tconst registeredBlocks = registry\n\t\t\t\t.select( blocksStore )\n\t\t\t\t.getBlockTypes();\n\t\t\tif ( ! registeredBlocks.some( ( i ) => i.name === name ) ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tregistry.dispatch( noticesStore ).createInfoNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s is the block title.\n\t\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\t\tblock.title\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\tspeak: true,\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t\tsuccess = true;\n\t\t} catch ( error ) {\n\t\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t\t// Errors we throw are fatal.\n\t\t\tlet isFatal = error instanceof Error;\n\n\t\t\t// Specific API errors that are fatal.\n\t\t\tconst fatalAPIErrors = {\n\t\t\t\tfolder_exists: __(\n\t\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t\t),\n\t\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t\t),\n\t\t\t};\n\n\t\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\t\tisFatal = true;\n\t\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t\t}\n\n\t\t\tdispatch.setErrorNotice( id, message, isFatal );\n\t\t\tregistry.dispatch( noticesStore ).createErrorNotice( message, {\n\t\t\t\tspeak: true,\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t}\n\t\tdispatch.setIsInstalling( id, false );\n\t\treturn success;\n\t};\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport const uninstallBlockType =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\ttry {\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl,\n\t\t\t\tdata: { status: 'inactive' },\n\t\t\t} );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\turl,\n\t\t\t} );\n\t\t\tdispatch.removeInstalledBlockType( block );\n\t\t} catch ( error ) {\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createErrorNotice(\n\t\t\t\t\terror.message || __( 'An error occurred.' )\n\t\t\t\t);\n\t\t}\n\t};\n\n/**\n * Returns an action object used to add a block type to the \"newly installed\"\n * tracking list.\n *\n * @param {Object} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function addInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'ADD_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to remove a block type from the \"newly installed\"\n * tracking list.\n *\n * @param {string} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function removeInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'REMOVE_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to indicate install in progress.\n *\n * @param {string} blockId\n * @param {boolean} isInstalling\n *\n * @return {Object} Action object.\n */\nexport function setIsInstalling( blockId, isInstalling ) {\n\treturn {\n\t\ttype: 'SET_INSTALLING_BLOCK',\n\t\tblockId,\n\t\tisInstalling,\n\t};\n}\n\n/**\n * Sets an error notice to be displayed to the user for a given block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n * @param {string} message The message shown in the notice.\n * @param {boolean} isFatal Whether the user can recover from the error.\n *\n * @return {Object} Action object.\n */\nexport function setErrorNotice( blockId, message, isFatal = false ) {\n\treturn {\n\t\ttype: 'SET_ERROR_NOTICE',\n\t\tblockId,\n\t\tmessage,\n\t\tisFatal,\n\t};\n}\n\n/**\n * Sets the error notice to empty for specific block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {Object} Action object.\n */\nexport function clearErrorNotice( blockId ) {\n\treturn {\n\t\ttype: 'CLEAR_ERROR_NOTICE',\n\t\tblockId,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["store","blocksStore","unstable__bootstrapServerSideBlockDefinitions","__","sprintf","apiFetch","noticesStore","addQueryArgs","loadAssets","getPluginUrl","fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","name","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","metadataFields","_fields","catch","then","Object","fromEntries","entries","filter","key","includes","registeredBlocks","select","getBlockTypes","some","i","Error","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,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AASD,wBAAT,CAAmCC,IAAnC,EAA0C;AAChD,SAAO;AACNrD,IAAAA,IAAI,EAAE,6BADA;AAENqD,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAS1C,eAAT,CAA0B2C,OAA1B,EAAmCC,YAAnC,EAAkD;AACxD,SAAO;AACNvD,IAAAA,IAAI,EAAE,sBADA;AAENsD,IAAAA,OAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASP,cAAT,CAAyBM,OAAzB,EAAkCZ,OAAlC,EAA6D;AAAA,MAAlBC,OAAkB,uEAAR,KAAQ;AACnE,SAAO;AACN3C,IAAAA,IAAI,EAAE,kBADA;AAENsD,IAAAA,OAFM;AAGNZ,IAAAA,OAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASjC,gBAAT,CAA2B4C,OAA3B,EAAqC;AAC3C,SAAO;AACNtD,IAAAA,IAAI,EAAE,oBADA;AAENsD,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tstore as blocksStore,\n\tunstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase\n} from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './load-assets';\nimport getPluginUrl from './utils/get-plugin-url';\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been requested and are loading.\n *\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function fetchDownloadableBlocks( filterValue ) {\n\treturn { type: 'FETCH_DOWNLOADABLE_BLOCKS', filterValue };\n}\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been updated.\n *\n * @param {Array} downloadableBlocks Downloadable blocks.\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function receiveDownloadableBlocks( downloadableBlocks, filterValue ) {\n\treturn {\n\t\ttype: 'RECEIVE_DOWNLOADABLE_BLOCKS',\n\t\tdownloadableBlocks,\n\t\tfilterValue,\n\t};\n}\n\n/**\n * Action triggered to install a block plugin.\n *\n * @param {Object} block The block item returned by search.\n *\n * @return {boolean} Whether the block was successfully installed & loaded.\n */\nexport const installBlockType =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\tconst { id, name } = block;\n\t\tlet success = false;\n\t\tdispatch.clearErrorNotice( id );\n\t\ttry {\n\t\t\tdispatch.setIsInstalling( id, true );\n\n\t\t\t// If we have a wp:plugin link, the plugin is installed but inactive.\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tlet links = {};\n\t\t\tif ( url ) {\n\t\t\t\tawait apiFetch( {\n\t\t\t\t\tmethod: 'PUT',\n\t\t\t\t\turl,\n\t\t\t\t\tdata: { status: 'active' },\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tconst response = await apiFetch( {\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\t\tdata: { slug: id, status: 'active' },\n\t\t\t\t} );\n\t\t\t\t// Add the `self` link for newly-installed blocks.\n\t\t\t\tlinks = response._links;\n\t\t\t}\n\n\t\t\tdispatch.addInstalledBlockType( {\n\t\t\t\t...block,\n\t\t\t\tlinks: { ...block.links, ...links },\n\t\t\t} );\n\n\t\t\t// Ensures that the block metadata is propagated to the editor when registered on the server.\n\t\t\tconst metadataFields = [\n\t\t\t\t'api_version',\n\t\t\t\t'title',\n\t\t\t\t'category',\n\t\t\t\t'parent',\n\t\t\t\t'icon',\n\t\t\t\t'description',\n\t\t\t\t'keywords',\n\t\t\t\t'attributes',\n\t\t\t\t'provides_context',\n\t\t\t\t'uses_context',\n\t\t\t\t'supports',\n\t\t\t\t'styles',\n\t\t\t\t'example',\n\t\t\t\t'variations',\n\t\t\t];\n\t\t\tawait apiFetch( {\n\t\t\t\tpath: addQueryArgs( `/wp/v2/block-types/${ name }`, {\n\t\t\t\t\t_fields: metadataFields,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t// Ignore when the block is not registered on the server.\n\t\t\t\t.catch( () => {} )\n\t\t\t\t.then( ( response ) => {\n\t\t\t\t\tif ( ! response ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tunstable__bootstrapServerSideBlockDefinitions( {\n\t\t\t\t\t\t[ name ]: Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries( response ).filter( ( [ key ] ) =>\n\t\t\t\t\t\t\t\tmetadataFields.includes( key )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t} );\n\t\t\t\t} );\n\n\t\t\tawait loadAssets();\n\t\t\tconst registeredBlocks = registry\n\t\t\t\t.select( blocksStore )\n\t\t\t\t.getBlockTypes();\n\t\t\tif ( ! registeredBlocks.some( ( i ) => i.name === name ) ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tregistry.dispatch( noticesStore ).createInfoNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s is the block title.\n\t\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\t\tblock.title\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\tspeak: true,\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t\tsuccess = true;\n\t\t} catch ( error ) {\n\t\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t\t// Errors we throw are fatal.\n\t\t\tlet isFatal = error instanceof Error;\n\n\t\t\t// Specific API errors that are fatal.\n\t\t\tconst fatalAPIErrors = {\n\t\t\t\tfolder_exists: __(\n\t\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t\t),\n\t\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t\t),\n\t\t\t};\n\n\t\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\t\tisFatal = true;\n\t\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t\t}\n\n\t\t\tdispatch.setErrorNotice( id, message, isFatal );\n\t\t\tregistry.dispatch( noticesStore ).createErrorNotice( message, {\n\t\t\t\tspeak: true,\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t}\n\t\tdispatch.setIsInstalling( id, false );\n\t\treturn success;\n\t};\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport const uninstallBlockType =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\ttry {\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl,\n\t\t\t\tdata: { status: 'inactive' },\n\t\t\t} );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\turl,\n\t\t\t} );\n\t\t\tdispatch.removeInstalledBlockType( block );\n\t\t} catch ( error ) {\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createErrorNotice(\n\t\t\t\t\terror.message || __( 'An error occurred.' )\n\t\t\t\t);\n\t\t}\n\t};\n\n/**\n * Returns an action object used to add a block type to the \"newly installed\"\n * tracking list.\n *\n * @param {Object} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function addInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'ADD_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to remove a block type from the \"newly installed\"\n * tracking list.\n *\n * @param {string} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function removeInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'REMOVE_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to indicate install in progress.\n *\n * @param {string} blockId\n * @param {boolean} isInstalling\n *\n * @return {Object} Action object.\n */\nexport function setIsInstalling( blockId, isInstalling ) {\n\treturn {\n\t\ttype: 'SET_INSTALLING_BLOCK',\n\t\tblockId,\n\t\tisInstalling,\n\t};\n}\n\n/**\n * Sets an error notice to be displayed to the user for a given block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n * @param {string} message The message shown in the notice.\n * @param {boolean} isFatal Whether the user can recover from the error.\n *\n * @return {Object} Action object.\n */\nexport function setErrorNotice( blockId, message, isFatal = false ) {\n\treturn {\n\t\ttype: 'SET_ERROR_NOTICE',\n\t\tblockId,\n\t\tmessage,\n\t\tisFatal,\n\t};\n}\n\n/**\n * Sets the error notice to empty for specific block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {Object} Action object.\n */\nexport function clearErrorNotice( blockId ) {\n\treturn {\n\t\ttype: 'CLEAR_ERROR_NOTICE',\n\t\tblockId,\n\t};\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/block-directory",
3
- "version": "3.16.0",
3
+ "version": "3.16.1-next.4d3b314fd5.0",
4
4
  "description": "Extend editor with block directory features to search, download and install blocks.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,26 +26,25 @@
26
26
  "react-native": "src/index",
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.16.0",
29
- "@wordpress/a11y": "^3.18.0",
30
- "@wordpress/api-fetch": "^6.15.0",
31
- "@wordpress/block-editor": "^10.1.0",
32
- "@wordpress/blocks": "^11.17.0",
33
- "@wordpress/components": "^21.1.0",
34
- "@wordpress/compose": "^5.16.0",
35
- "@wordpress/core-data": "^5.1.0",
36
- "@wordpress/data": "^7.2.0",
37
- "@wordpress/edit-post": "^6.15.0",
38
- "@wordpress/editor": "^12.17.0",
39
- "@wordpress/element": "^4.16.0",
40
- "@wordpress/hooks": "^3.18.0",
41
- "@wordpress/html-entities": "^3.18.0",
42
- "@wordpress/i18n": "^4.18.0",
43
- "@wordpress/icons": "^9.9.0",
44
- "@wordpress/notices": "^3.18.0",
45
- "@wordpress/plugins": "^4.16.0",
46
- "@wordpress/url": "^3.19.0",
47
- "change-case": "^4.1.2",
48
- "lodash": "^4.17.21"
29
+ "@wordpress/a11y": "^3.18.1-next.4d3b314fd5.0",
30
+ "@wordpress/api-fetch": "^6.15.1-next.4d3b314fd5.0",
31
+ "@wordpress/block-editor": "^10.1.1-next.4d3b314fd5.0",
32
+ "@wordpress/blocks": "^11.18.1-next.4d3b314fd5.0",
33
+ "@wordpress/components": "^21.1.2-next.4d3b314fd5.0",
34
+ "@wordpress/compose": "^5.16.1-next.4d3b314fd5.0",
35
+ "@wordpress/core-data": "^5.1.1-next.4d3b314fd5.0",
36
+ "@wordpress/data": "^7.2.1-next.4d3b314fd5.0",
37
+ "@wordpress/edit-post": "^6.15.1-next.4d3b314fd5.0",
38
+ "@wordpress/editor": "^12.17.1-next.4d3b314fd5.0",
39
+ "@wordpress/element": "^4.16.1-next.4d3b314fd5.0",
40
+ "@wordpress/hooks": "^3.18.1-next.4d3b314fd5.0",
41
+ "@wordpress/html-entities": "^3.18.1-next.4d3b314fd5.0",
42
+ "@wordpress/i18n": "^4.18.1-next.4d3b314fd5.0",
43
+ "@wordpress/icons": "^9.9.1-next.4d3b314fd5.0",
44
+ "@wordpress/notices": "^3.18.1-next.4d3b314fd5.0",
45
+ "@wordpress/plugins": "^4.16.1-next.4d3b314fd5.0",
46
+ "@wordpress/url": "^3.19.1-next.4d3b314fd5.0",
47
+ "change-case": "^4.1.2"
49
48
  },
50
49
  "peerDependencies": {
51
50
  "react": "^17.0.0",
@@ -54,5 +53,5 @@
54
53
  "publishConfig": {
55
54
  "access": "public"
56
55
  },
57
- "gitHead": "23e136283fa1d3b8d9d8b33869f871ad5eb77726"
56
+ "gitHead": "25054766423cb49d959eb656c2533530073ff5c2"
58
57
  }
@@ -100,7 +100,7 @@ const ModifiedWarning = ( { originalBlock, ...props } ) => {
100
100
  originalBlock.title || originalName
101
101
  );
102
102
  actions.push(
103
- <Button key="convert" onClick={ convertToHTML } variant="link">
103
+ <Button key="convert" onClick={ convertToHTML } variant="tertiary">
104
104
  { __( 'Keep as HTML' ) }
105
105
  </Button>
106
106
  );
@@ -1,8 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { pick } from 'lodash';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
@@ -119,7 +114,11 @@ export const installBlockType =
119
114
  return;
120
115
  }
121
116
  unstable__bootstrapServerSideBlockDefinitions( {
122
- [ name ]: pick( response, metadataFields ),
117
+ [ name ]: Object.fromEntries(
118
+ Object.entries( response ).filter( ( [ key ] ) =>
119
+ metadataFields.includes( key )
120
+ )
121
+ ),
123
122
  } );
124
123
  } );
125
124