@wordpress/block-directory 4.11.0 → 4.12.1
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/CHANGELOG.md +2 -0
- package/build/components/block-ratings/index.js +7 -10
- package/build/components/block-ratings/index.js.map +1 -1
- package/build/components/block-ratings/stars.js +3 -4
- package/build/components/block-ratings/stars.js.map +1 -1
- package/build/components/compact-list/index.js +23 -28
- package/build/components/compact-list/index.js.map +1 -1
- package/build/components/downloadable-block-icon/index.js +3 -4
- package/build/components/downloadable-block-icon/index.js.map +1 -1
- package/build/components/downloadable-block-list-item/index.js +18 -23
- package/build/components/downloadable-block-list-item/index.js.map +1 -1
- package/build/components/downloadable-block-notice/index.js +3 -4
- package/build/components/downloadable-block-notice/index.js.map +1 -1
- package/build/components/downloadable-blocks-list/index.js +7 -10
- package/build/components/downloadable-blocks-list/index.js.map +1 -1
- package/build/components/downloadable-blocks-panel/index.js +13 -16
- package/build/components/downloadable-blocks-panel/index.js.map +1 -1
- package/build/components/downloadable-blocks-panel/inserter-panel.js +5 -6
- package/build/components/downloadable-blocks-panel/inserter-panel.js.map +1 -1
- package/build/plugins/get-install-missing/index.js +13 -17
- package/build/plugins/get-install-missing/index.js.map +1 -1
- package/build/plugins/get-install-missing/install-button.js +5 -6
- package/build/plugins/get-install-missing/install-button.js.map +1 -1
- package/build/plugins/inserter-menu-downloadable-blocks-panel/index.js +7 -9
- package/build/plugins/inserter-menu-downloadable-blocks-panel/index.js.map +1 -1
- package/build/plugins/installed-blocks-pre-publish-panel/index.js +2 -2
- package/build/plugins/installed-blocks-pre-publish-panel/index.js.map +1 -1
- package/build/store/actions.js +10 -17
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +6 -15
- package/build/store/reducer.js.map +1 -1
- package/build/store/resolvers.js +4 -9
- package/build/store/resolvers.js.map +1 -1
- package/build/store/selectors.js +4 -4
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils/has-block-type.js +4 -9
- package/build/store/utils/has-block-type.js.map +1 -1
- package/build-module/components/block-ratings/index.js +7 -10
- package/build-module/components/block-ratings/index.js.map +1 -1
- package/build-module/components/block-ratings/stars.js +3 -4
- package/build-module/components/block-ratings/stars.js.map +1 -1
- package/build-module/components/compact-list/index.js +23 -28
- package/build-module/components/compact-list/index.js.map +1 -1
- package/build-module/components/downloadable-block-icon/index.js +3 -4
- package/build-module/components/downloadable-block-icon/index.js.map +1 -1
- package/build-module/components/downloadable-block-list-item/index.js +18 -22
- package/build-module/components/downloadable-block-list-item/index.js.map +1 -1
- package/build-module/components/downloadable-block-notice/index.js +3 -4
- package/build-module/components/downloadable-block-notice/index.js.map +1 -1
- package/build-module/components/downloadable-blocks-list/index.js +7 -9
- package/build-module/components/downloadable-blocks-list/index.js.map +1 -1
- package/build-module/components/downloadable-blocks-panel/index.js +13 -16
- package/build-module/components/downloadable-blocks-panel/index.js.map +1 -1
- package/build-module/components/downloadable-blocks-panel/inserter-panel.js +5 -6
- package/build-module/components/downloadable-blocks-panel/inserter-panel.js.map +1 -1
- package/build-module/plugins/get-install-missing/index.js +13 -16
- package/build-module/plugins/get-install-missing/index.js.map +1 -1
- package/build-module/plugins/get-install-missing/install-button.js +5 -6
- package/build-module/plugins/get-install-missing/install-button.js.map +1 -1
- package/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js +7 -9
- package/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js.map +1 -1
- package/build-module/plugins/installed-blocks-pre-publish-panel/index.js +2 -2
- package/build-module/plugins/installed-blocks-pre-publish-panel/index.js.map +1 -1
- package/build-module/store/actions.js +10 -17
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +6 -15
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/resolvers.js +4 -9
- package/build-module/store/resolvers.js.map +1 -1
- package/build-module/store/selectors.js +4 -4
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils/has-block-type.js +4 -9
- package/build-module/store/utils/has-block-type.js.map +1 -1
- package/package.json +20 -20
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/plugins/get-install-missing/install-button.js"],"names":["InstallButton","attributes","block","clientId","isInstallingBlock","select","blockDirectoryStore","isInstalling","id","installBlockType","replaceBlock","blockEditorStore","then","success","blockType","name","originalBlock","originalContent","innerBlocks","title"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAZA;AACA;AACA;;AAOA;AACA;AACA;AAGe,SAASA,aAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/plugins/get-install-missing/install-button.js"],"names":["InstallButton","attributes","block","clientId","isInstallingBlock","select","blockDirectoryStore","isInstalling","id","installBlockType","replaceBlock","blockEditorStore","then","success","blockType","name","originalBlock","originalContent","innerBlocks","title"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAZA;AACA;AACA;;AAOA;AACA;AACA;AAGe,SAASA,aAAT,CAAwB;AAAEC,EAAAA,UAAF;AAAcC,EAAAA,KAAd;AAAqBC,EAAAA;AAArB,CAAxB,EAA0D;AACxE,QAAMC,iBAAiB,GAAG,qBACvBC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAA8BC,YAA9B,CAA4CL,KAAK,CAACM,EAAlD,CADW,EAEzB,CAAEN,KAAK,CAACM,EAAR,CAFyB,CAA1B;AAIA,QAAM;AAAEC,IAAAA;AAAF,MAAuB,uBAAaH,YAAb,CAA7B;AACA,QAAM;AAAEI,IAAAA;AAAF,MAAmB,uBAAaC,kBAAb,CAAzB;AAEA,SACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAG,MACTF,gBAAgB,CAAEP,KAAF,CAAhB,CAA0BU,IAA1B,CAAkCC,OAAF,IAAe;AAC9C,UAAKA,OAAL,EAAe;AACd,cAAMC,SAAS,GAAG,0BAAcZ,KAAK,CAACa,IAApB,CAAlB;AACA,cAAM,CAAEC,aAAF,IAAoB,mBACzBf,UAAU,CAACgB,eADc,CAA1B;;AAGA,YAAKD,aAAa,IAAIF,SAAtB,EAAkC;AACjCJ,UAAAA,YAAY,CACXP,QADW,EAEX,yBACCW,SAAS,CAACC,IADX,EAECC,aAAa,CAACf,UAFf,EAGCe,aAAa,CAACE,WAHf,CAFW,CAAZ;AAQA;AACD;AACD,KAjBD,CAFF;AAqBC,IAAA,QAAQ,EAAGd,iBArBZ;AAsBC,IAAA,MAAM,EAAGA,iBAtBV;AAuBC,IAAA,OAAO,EAAC;AAvBT,KAyBG;AACD;AACA,gBAAI,YAAJ,CAFC,EAGDF,KAAK,CAACiB,KAHL,CAzBH,CADD;AAiCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { createBlock, getBlockType, parse } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { store as blockDirectoryStore } from '../../store';\n\nexport default function InstallButton( { attributes, block, clientId } ) {\n\tconst isInstallingBlock = useSelect(\n\t\t( select ) => select( blockDirectoryStore ).isInstalling( block.id ),\n\t\t[ block.id ]\n\t);\n\tconst { installBlockType } = useDispatch( blockDirectoryStore );\n\tconst { replaceBlock } = useDispatch( blockEditorStore );\n\n\treturn (\n\t\t<Button\n\t\t\tonClick={ () =>\n\t\t\t\tinstallBlockType( block ).then( ( success ) => {\n\t\t\t\t\tif ( success ) {\n\t\t\t\t\t\tconst blockType = getBlockType( block.name );\n\t\t\t\t\t\tconst [ originalBlock ] = parse(\n\t\t\t\t\t\t\tattributes.originalContent\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( originalBlock && blockType ) {\n\t\t\t\t\t\t\treplaceBlock(\n\t\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t\t\tblockType.name,\n\t\t\t\t\t\t\t\t\toriginalBlock.attributes,\n\t\t\t\t\t\t\t\t\toriginalBlock.innerBlocks\n\t\t\t\t\t\t\t\t)\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\t\t\t}\n\t\t\tdisabled={ isInstallingBlock }\n\t\t\tisBusy={ isInstallingBlock }\n\t\t\tvariant=\"primary\"\n\t\t>\n\t\t\t{ sprintf(\n\t\t\t\t/* translators: %s: block name */\n\t\t\t\t__( 'Install %s' ),\n\t\t\t\tblock.title\n\t\t\t) }\n\t\t</Button>\n\t);\n}\n"]}
|
|
@@ -25,15 +25,13 @@ var _downloadableBlocksPanel = _interopRequireDefault(require("../../components/
|
|
|
25
25
|
function InserterMenuDownloadableBlocksPanel() {
|
|
26
26
|
const [debouncedFilterValue, setFilterValue] = (0, _element.useState)('');
|
|
27
27
|
const debouncedSetFilterValue = (0, _compose.debounce)(setFilterValue, 400);
|
|
28
|
-
return (0, _element.createElement)(_blockEditor.__unstableInserterMenuExtension, null,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} = _ref;
|
|
36
|
-
|
|
28
|
+
return (0, _element.createElement)(_blockEditor.__unstableInserterMenuExtension, null, ({
|
|
29
|
+
onSelect,
|
|
30
|
+
onHover,
|
|
31
|
+
filterValue,
|
|
32
|
+
hasItems,
|
|
33
|
+
rootClientId
|
|
34
|
+
}) => {
|
|
37
35
|
if (debouncedFilterValue !== filterValue) {
|
|
38
36
|
debouncedSetFilterValue(filterValue);
|
|
39
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/plugins/inserter-menu-downloadable-blocks-panel/index.js"],"names":["InserterMenuDownloadableBlocksPanel","debouncedFilterValue","setFilterValue","debouncedSetFilterValue","onSelect","onHover","filterValue","hasItems","rootClientId"],"mappings":";;;;;;;;;AAKA;;AAFA;;AACA;;AAMA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGA,SAASA,mCAAT,GAA+C;AAC9C,QAAM,CAAEC,oBAAF,EAAwBC,cAAxB,IAA2C,uBAAU,EAAV,CAAjD;AACA,QAAMC,uBAAuB,GAAG,uBAAUD,cAAV,EAA0B,GAA1B,CAAhC;AAEA,SACC,4BAAC,4CAAD,QACG,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/plugins/inserter-menu-downloadable-blocks-panel/index.js"],"names":["InserterMenuDownloadableBlocksPanel","debouncedFilterValue","setFilterValue","debouncedSetFilterValue","onSelect","onHover","filterValue","hasItems","rootClientId"],"mappings":";;;;;;;;;AAKA;;AAFA;;AACA;;AAMA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGA,SAASA,mCAAT,GAA+C;AAC9C,QAAM,CAAEC,oBAAF,EAAwBC,cAAxB,IAA2C,uBAAU,EAAV,CAAjD;AACA,QAAMC,uBAAuB,GAAG,uBAAUD,cAAV,EAA0B,GAA1B,CAAhC;AAEA,SACC,4BAAC,4CAAD,QACG,CAAE;AACHE,IAAAA,QADG;AAEHC,IAAAA,OAFG;AAGHC,IAAAA,WAHG;AAIHC,IAAAA,QAJG;AAKHC,IAAAA;AALG,GAAF,KAMK;AACN,QAAKP,oBAAoB,KAAKK,WAA9B,EAA4C;AAC3CH,MAAAA,uBAAuB,CAAEG,WAAF,CAAvB;AACA;;AAED,QAAK,CAAEL,oBAAP,EAA8B;AAC7B,aAAO,IAAP;AACA;;AAED,WACC,4BAAC,gCAAD;AACC,MAAA,QAAQ,EAAGG,QADZ;AAEC,MAAA,OAAO,EAAGC,OAFX;AAGC,MAAA,YAAY,EAAGG,YAHhB;AAIC,MAAA,WAAW,EAAGP,oBAJf;AAKC,MAAA,cAAc,EAAGM,QALlB;AAMC,MAAA,QAAQ,EAAGD,WAAW,KAAKL;AAN5B,MADD;AAUA,GA1BF,CADD;AA8BA;;eAEcD,mC","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __unstableInserterMenuExtension } from '@wordpress/block-editor';\nimport { debounce } from '@wordpress/compose';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport DownloadableBlocksPanel from '../../components/downloadable-blocks-panel';\n\nfunction InserterMenuDownloadableBlocksPanel() {\n\tconst [ debouncedFilterValue, setFilterValue ] = useState( '' );\n\tconst debouncedSetFilterValue = debounce( setFilterValue, 400 );\n\n\treturn (\n\t\t<__unstableInserterMenuExtension>\n\t\t\t{ ( {\n\t\t\t\tonSelect,\n\t\t\t\tonHover,\n\t\t\t\tfilterValue,\n\t\t\t\thasItems,\n\t\t\t\trootClientId,\n\t\t\t} ) => {\n\t\t\t\tif ( debouncedFilterValue !== filterValue ) {\n\t\t\t\t\tdebouncedSetFilterValue( filterValue );\n\t\t\t\t}\n\n\t\t\t\tif ( ! debouncedFilterValue ) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn (\n\t\t\t\t\t<DownloadableBlocksPanel\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\tfilterValue={ debouncedFilterValue }\n\t\t\t\t\t\thasLocalBlocks={ hasItems }\n\t\t\t\t\t\tisTyping={ filterValue !== debouncedFilterValue }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} }\n\t\t</__unstableInserterMenuExtension>\n\t);\n}\n\nexport default InserterMenuDownloadableBlocksPanel;\n"]}
|
|
@@ -19,13 +19,13 @@ var _compactList = _interopRequireDefault(require("../../components/compact-list
|
|
|
19
19
|
|
|
20
20
|
var _store = require("../../store");
|
|
21
21
|
|
|
22
|
-
var _window$wp$editPost
|
|
22
|
+
var _window$wp$editPost;
|
|
23
23
|
|
|
24
24
|
// We shouldn't import the edit-post package directly
|
|
25
25
|
// because it would include the wp-edit-post in all pages loading the block-directory script.
|
|
26
26
|
const {
|
|
27
27
|
PluginPrePublishPanel
|
|
28
|
-
} = (_window$wp$editPost =
|
|
28
|
+
} = (_window$wp$editPost = window?.wp?.editPost) !== null && _window$wp$editPost !== void 0 ? _window$wp$editPost : {};
|
|
29
29
|
|
|
30
30
|
function InstalledBlocksPrePublishPanel() {
|
|
31
31
|
const newBlockTypes = (0, _data.useSelect)(select => select(_store.store).getNewBlockTypes(), []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/plugins/installed-blocks-pre-publish-panel/index.js"],"names":["PluginPrePublishPanel","window","wp","editPost","InstalledBlocksPrePublishPanel","newBlockTypes","select","blockDirectoryStore","getNewBlockTypes","length","blockDefault"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;;;AAEA;AACA;AACA,MAAM;AAAEA,EAAAA;AAAF,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/plugins/installed-blocks-pre-publish-panel/index.js"],"names":["PluginPrePublishPanel","window","wp","editPost","InstalledBlocksPrePublishPanel","newBlockTypes","select","blockDirectoryStore","getNewBlockTypes","length","blockDefault"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;;;AAEA;AACA;AACA,MAAM;AAAEA,EAAAA;AAAF,2BAA4BC,MAAM,EAAEC,EAAR,EAAYC,QAAxC,qEAAoD,EAA1D;;AAEe,SAASC,8BAAT,GAA0C;AACxD,QAAMC,aAAa,GAAG,qBACnBC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAA8BC,gBAA9B,EADO,EAErB,EAFqB,CAAtB;;AAKA,MAAK,CAAEH,aAAa,CAACI,MAArB,EAA8B;AAC7B,WAAO,IAAP;AACA;;AAED,SACC,4BAAC,qBAAD;AACC,IAAA,IAAI,EAAGC,mBADR;AAEC,IAAA,KAAK,EAAG,oBACP;AACA,kBACC,iBADD,EAEC,kBAFD,EAGCL,aAAa,CAACI,MAHf,CAFO,EAOPJ,aAAa,CAACI,MAPP,CAFT;AAWC,IAAA,WAAW,EAAG;AAXf,KAaC;AAAG,IAAA,SAAS,EAAC;AAAb,KACG,cACD,kDADC,EAED,oDAFC,EAGDJ,aAAa,CAACI,MAHb,CADH,CAbD,EAoBC,4BAAC,oBAAD;AAAa,IAAA,KAAK,EAAGJ;AAArB,IApBD,CADD;AAwBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { _n, sprintf } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { blockDefault } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport CompactList from '../../components/compact-list';\nimport { store as blockDirectoryStore } from '../../store';\n\n// We shouldn't import the edit-post package directly\n// because it would include the wp-edit-post in all pages loading the block-directory script.\nconst { PluginPrePublishPanel } = window?.wp?.editPost ?? {};\n\nexport default function InstalledBlocksPrePublishPanel() {\n\tconst newBlockTypes = useSelect(\n\t\t( select ) => select( blockDirectoryStore ).getNewBlockTypes(),\n\t\t[]\n\t);\n\n\tif ( ! newBlockTypes.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PluginPrePublishPanel\n\t\t\ticon={ blockDefault }\n\t\t\ttitle={ sprintf(\n\t\t\t\t// translators: %d: number of blocks (number).\n\t\t\t\t_n(\n\t\t\t\t\t'Added: %d block',\n\t\t\t\t\t'Added: %d blocks',\n\t\t\t\t\tnewBlockTypes.length\n\t\t\t\t),\n\t\t\t\tnewBlockTypes.length\n\t\t\t) }\n\t\t\tinitialOpen={ true }\n\t\t>\n\t\t\t<p className=\"installed-blocks-pre-publish-panel__copy\">\n\t\t\t\t{ _n(\n\t\t\t\t\t'The following block has been added to your site.',\n\t\t\t\t\t'The following blocks have been added to your site.',\n\t\t\t\t\tnewBlockTypes.length\n\t\t\t\t) }\n\t\t\t</p>\n\t\t\t<CompactList items={ newBlockTypes } />\n\t\t</PluginPrePublishPanel>\n\t);\n}\n"]}
|
package/build/store/actions.js
CHANGED
|
@@ -78,11 +78,10 @@ function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
|
|
|
78
78
|
*/
|
|
79
79
|
|
|
80
80
|
|
|
81
|
-
const installBlockType = block => async
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
} = _ref;
|
|
81
|
+
const installBlockType = block => async ({
|
|
82
|
+
registry,
|
|
83
|
+
dispatch
|
|
84
|
+
}) => {
|
|
86
85
|
const {
|
|
87
86
|
id,
|
|
88
87
|
name
|
|
@@ -135,10 +134,7 @@ const installBlockType = block => async _ref => {
|
|
|
135
134
|
}
|
|
136
135
|
|
|
137
136
|
(0, _blocks.unstable__bootstrapServerSideBlockDefinitions)({
|
|
138
|
-
[name]: Object.fromEntries(Object.entries(response).filter(
|
|
139
|
-
let [key] = _ref2;
|
|
140
|
-
return metadataFields.includes(key);
|
|
141
|
-
}))
|
|
137
|
+
[name]: Object.fromEntries(Object.entries(response).filter(([key]) => metadataFields.includes(key)))
|
|
142
138
|
});
|
|
143
139
|
});
|
|
144
140
|
await (0, _loadAssets.loadAssets)();
|
|
@@ -188,12 +184,10 @@ const installBlockType = block => async _ref => {
|
|
|
188
184
|
|
|
189
185
|
exports.installBlockType = installBlockType;
|
|
190
186
|
|
|
191
|
-
const uninstallBlockType = block => async
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
} = _ref3;
|
|
196
|
-
|
|
187
|
+
const uninstallBlockType = block => async ({
|
|
188
|
+
registry,
|
|
189
|
+
dispatch
|
|
190
|
+
}) => {
|
|
197
191
|
try {
|
|
198
192
|
const url = (0, _getPluginUrl.default)(block);
|
|
199
193
|
await (0, _apiFetch.default)({
|
|
@@ -274,8 +268,7 @@ function setIsInstalling(blockId, isInstalling) {
|
|
|
274
268
|
*/
|
|
275
269
|
|
|
276
270
|
|
|
277
|
-
function setErrorNotice(blockId, message) {
|
|
278
|
-
let isFatal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
271
|
+
function setErrorNotice(blockId, message, isFatal = false) {
|
|
279
272
|
return {
|
|
280
273
|
type: 'SET_ERROR_NOTICE',
|
|
281
274
|
blockId,
|
|
@@ -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","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,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,EAAF;AAAMC,IAAAA;AAAN,MAAeJ,KAArB;AACA,MAAIK,OAAO,GAAG,KAAd;AACAH,EAAAA,QAAQ,CAACI,gBAAT,CAA2BH,EAA3B;;AACA,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IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASD,wBAAT,CAAmCC,IAAnC,EAA0C;AAChD,SAAO;AACNvD,IAAAA,IAAI,EAAE,6BADA;AAENuD,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAAS5C,eAAT,CAA0B6C,OAA1B,EAAmCC,YAAnC,EAAkD;AACxD,SAAO;AACNzD,IAAAA,IAAI,EAAE,sBADA;AAENwD,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;AACN7C,IAAAA,IAAI,EAAE,kBADA;AAENwD,IAAAA,OAFM;AAGNZ,IAAAA,OAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;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"]}
|
|
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;;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AAA,OAFM;AAGNZ,IAAAA,OAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;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"]}
|
package/build/store/reducer.js
CHANGED
|
@@ -19,10 +19,7 @@ var _data = require("@wordpress/data");
|
|
|
19
19
|
*
|
|
20
20
|
* @return {Object} Updated state.
|
|
21
21
|
*/
|
|
22
|
-
const downloadableBlocks =
|
|
23
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
24
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
25
|
-
|
|
22
|
+
const downloadableBlocks = (state = {}, action) => {
|
|
26
23
|
switch (action.type) {
|
|
27
24
|
case 'FETCH_DOWNLOADABLE_BLOCKS':
|
|
28
25
|
return { ...state,
|
|
@@ -54,13 +51,10 @@ const downloadableBlocks = function () {
|
|
|
54
51
|
|
|
55
52
|
exports.downloadableBlocks = downloadableBlocks;
|
|
56
53
|
|
|
57
|
-
const blockManagement =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
63
|
-
|
|
54
|
+
const blockManagement = (state = {
|
|
55
|
+
installedBlockTypes: [],
|
|
56
|
+
isInstalling: {}
|
|
57
|
+
}, action) => {
|
|
64
58
|
switch (action.type) {
|
|
65
59
|
case 'ADD_INSTALLED_BLOCK_TYPE':
|
|
66
60
|
return { ...state,
|
|
@@ -94,10 +88,7 @@ const blockManagement = function () {
|
|
|
94
88
|
|
|
95
89
|
exports.blockManagement = blockManagement;
|
|
96
90
|
|
|
97
|
-
const errorNotices =
|
|
98
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
99
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
100
|
-
|
|
91
|
+
const errorNotices = (state = {}, action) => {
|
|
101
92
|
switch (action.type) {
|
|
102
93
|
case 'SET_ERROR_NOTICE':
|
|
103
94
|
return { ...state,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/reducer.js"],"names":["downloadableBlocks","state","action","type","filterValue","isRequesting","results","blockManagement","installedBlockTypes","isInstalling","item","filter","blockType","name","blockId","errorNotices","message","isFatal","restState"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/reducer.js"],"names":["downloadableBlocks","state","action","type","filterValue","isRequesting","results","blockManagement","installedBlockTypes","isInstalling","item","filter","blockType","name","blockId","errorNotices","message","isFatal","restState"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,CAAEC,KAAK,GAAG,EAAV,EAAcC,MAAd,KAA0B;AAC3D,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,2BAAL;AACC,aAAO,EACN,GAAGF,KADG;AAEN,SAAEC,MAAM,CAACE,WAAT,GAAwB;AACvBC,UAAAA,YAAY,EAAE;AADS;AAFlB,OAAP;;AAMD,SAAK,6BAAL;AACC,aAAO,EACN,GAAGJ,KADG;AAEN,SAAEC,MAAM,CAACE,WAAT,GAAwB;AACvBE,UAAAA,OAAO,EAAEJ,MAAM,CAACF,kBADO;AAEvBK,UAAAA,YAAY,EAAE;AAFS;AAFlB,OAAP;AATF;;AAiBA,SAAOJ,KAAP;AACA,CAnBM;AAqBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMM,eAAe,GAAG,CAC9BN,KAAK,GAAG;AACPO,EAAAA,mBAAmB,EAAE,EADd;AAEPC,EAAAA,YAAY,EAAE;AAFP,CADs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C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Reducer returning an array of downloadable blocks.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const downloadableBlocks = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'FETCH_DOWNLOADABLE_BLOCKS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.filterValue ]: {\n\t\t\t\t\tisRequesting: true,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'RECEIVE_DOWNLOADABLE_BLOCKS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.filterValue ]: {\n\t\t\t\t\tresults: action.downloadableBlocks,\n\t\t\t\t\tisRequesting: false,\n\t\t\t\t},\n\t\t\t};\n\t}\n\treturn state;\n};\n\n/**\n * Reducer managing the installation and deletion of blocks.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const blockManagement = (\n\tstate = {\n\t\tinstalledBlockTypes: [],\n\t\tisInstalling: {},\n\t},\n\taction\n) => {\n\tswitch ( action.type ) {\n\t\tcase 'ADD_INSTALLED_BLOCK_TYPE':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tinstalledBlockTypes: [\n\t\t\t\t\t...state.installedBlockTypes,\n\t\t\t\t\taction.item,\n\t\t\t\t],\n\t\t\t};\n\t\tcase 'REMOVE_INSTALLED_BLOCK_TYPE':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tinstalledBlockTypes: state.installedBlockTypes.filter(\n\t\t\t\t\t( blockType ) => blockType.name !== action.item.name\n\t\t\t\t),\n\t\t\t};\n\t\tcase 'SET_INSTALLING_BLOCK':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tisInstalling: {\n\t\t\t\t\t...state.isInstalling,\n\t\t\t\t\t[ action.blockId ]: action.isInstalling,\n\t\t\t\t},\n\t\t\t};\n\t}\n\treturn state;\n};\n\n/**\n * Reducer returning an object of error notices.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const errorNotices = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'SET_ERROR_NOTICE':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.blockId ]: {\n\t\t\t\t\tmessage: action.message,\n\t\t\t\t\tisFatal: action.isFatal,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'CLEAR_ERROR_NOTICE':\n\t\t\tconst { [ action.blockId ]: blockId, ...restState } = state;\n\t\t\treturn restState;\n\t}\n\treturn state;\n};\n\nexport default combineReducers( {\n\tdownloadableBlocks,\n\tblockManagement,\n\terrorNotices,\n} );\n"]}
|
package/build/store/resolvers.js
CHANGED
|
@@ -24,11 +24,9 @@ var _actions = require("./actions");
|
|
|
24
24
|
/**
|
|
25
25
|
* Internal dependencies
|
|
26
26
|
*/
|
|
27
|
-
const getDownloadableBlocks = filterValue => async
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} = _ref;
|
|
31
|
-
|
|
27
|
+
const getDownloadableBlocks = filterValue => async ({
|
|
28
|
+
dispatch
|
|
29
|
+
}) => {
|
|
32
30
|
if (!filterValue) {
|
|
33
31
|
return;
|
|
34
32
|
}
|
|
@@ -38,10 +36,7 @@ const getDownloadableBlocks = filterValue => async _ref => {
|
|
|
38
36
|
const results = await (0, _apiFetch.default)({
|
|
39
37
|
path: `wp/v2/block-directory/search?term=${filterValue}`
|
|
40
38
|
});
|
|
41
|
-
const blocks = results.map(result => Object.fromEntries(Object.entries(result).map(
|
|
42
|
-
let [key, value] = _ref2;
|
|
43
|
-
return [(0, _changeCase.camelCase)(key), value];
|
|
44
|
-
})));
|
|
39
|
+
const blocks = results.map(result => Object.fromEntries(Object.entries(result).map(([key, value]) => [(0, _changeCase.camelCase)(key), value])));
|
|
45
40
|
dispatch((0, _actions.receiveDownloadableBlocks)(blocks, filterValue));
|
|
46
41
|
} catch {}
|
|
47
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/resolvers.js"],"names":["getDownloadableBlocks","filterValue","dispatch","results","path","blocks","map","result","Object","fromEntries","entries","key","value"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAKA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AAGO,MAAMA,qBAAqB,GAC/BC,WAAF,IACA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/resolvers.js"],"names":["getDownloadableBlocks","filterValue","dispatch","results","path","blocks","map","result","Object","fromEntries","entries","key","value"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAKA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AAGO,MAAMA,qBAAqB,GAC/BC,WAAF,IACA,OAAQ;AAAEC,EAAAA;AAAF,CAAR,KAA0B;AACzB,MAAK,CAAED,WAAP,EAAqB;AACpB;AACA;;AAED,MAAI;AACHC,IAAAA,QAAQ,CAAE,sCAAyBD,WAAzB,CAAF,CAAR;AACA,UAAME,OAAO,GAAG,MAAM,uBAAU;AAC/BC,MAAAA,IAAI,EAAG,qCAAqCH,WAAa;AAD1B,KAAV,CAAtB;AAGA,UAAMI,MAAM,GAAGF,OAAO,CAACG,GAAR,CAAeC,MAAF,IAC3BC,MAAM,CAACC,WAAP,CACCD,MAAM,CAACE,OAAP,CAAgBH,MAAhB,EAAyBD,GAAzB,CAA8B,CAAE,CAAEK,GAAF,EAAOC,KAAP,CAAF,KAAsB,CACnD,2BAAWD,GAAX,CADmD,EAEnDC,KAFmD,CAApD,CADD,CADc,CAAf;AASAV,IAAAA,QAAQ,CAAE,wCAA2BG,MAA3B,EAAmCJ,WAAnC,CAAF,CAAR;AACA,GAfD,CAeE,MAAM,CAAE;AACV,CAvBK","sourcesContent":["/**\n * External dependencies\n */\nimport { camelCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { fetchDownloadableBlocks, receiveDownloadableBlocks } from './actions';\n\nexport const getDownloadableBlocks =\n\t( filterValue ) =>\n\tasync ( { dispatch } ) => {\n\t\tif ( ! filterValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tdispatch( fetchDownloadableBlocks( filterValue ) );\n\t\t\tconst results = await apiFetch( {\n\t\t\t\tpath: `wp/v2/block-directory/search?term=${ filterValue }`,\n\t\t\t} );\n\t\t\tconst blocks = results.map( ( result ) =>\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\tObject.entries( result ).map( ( [ key, value ] ) => [\n\t\t\t\t\t\tcamelCase( key ),\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t] )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tdispatch( receiveDownloadableBlocks( blocks, filterValue ) );\n\t\t} catch {}\n\t};\n"]}
|
package/build/store/selectors.js
CHANGED
|
@@ -36,9 +36,9 @@ var _hasBlockType = _interopRequireDefault(require("./utils/has-block-type"));
|
|
|
36
36
|
* @return {boolean} Whether a request is in progress for the blocks list.
|
|
37
37
|
*/
|
|
38
38
|
function isRequestingDownloadableBlocks(state, filterValue) {
|
|
39
|
-
var _state$downloadableBl
|
|
39
|
+
var _state$downloadableBl;
|
|
40
40
|
|
|
41
|
-
return (_state$downloadableBl =
|
|
41
|
+
return (_state$downloadableBl = state.downloadableBlocks[filterValue]?.isRequesting) !== null && _state$downloadableBl !== void 0 ? _state$downloadableBl : false;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* Returns the available uninstalled blocks.
|
|
@@ -51,9 +51,9 @@ function isRequestingDownloadableBlocks(state, filterValue) {
|
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
function getDownloadableBlocks(state, filterValue) {
|
|
54
|
-
var _state$
|
|
54
|
+
var _state$downloadableBl2;
|
|
55
55
|
|
|
56
|
-
return (_state$
|
|
56
|
+
return (_state$downloadableBl2 = state.downloadableBlocks[filterValue]?.results) !== null && _state$downloadableBl2 !== void 0 ? _state$downloadableBl2 : [];
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* Returns the block types that have been installed on the server in this
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/selectors.js"],"names":["isRequestingDownloadableBlocks","state","filterValue","downloadableBlocks","isRequesting","getDownloadableBlocks","results","getInstalledBlockTypes","blockManagement","installedBlockTypes","getNewBlockTypes","select","usedBlockTree","blockEditorStore","getBlocks","filter","blockType","getUnusedBlockTypes","isInstalling","blockId","getErrorNotices","errorNotices","getErrorNoticeForBlock"],"mappings":";;;;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,8BAAT,CAAyCC,KAAzC,EAAgDC,WAAhD,EAA8D;AAAA;;AACpE,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/selectors.js"],"names":["isRequestingDownloadableBlocks","state","filterValue","downloadableBlocks","isRequesting","getDownloadableBlocks","results","getInstalledBlockTypes","blockManagement","installedBlockTypes","getNewBlockTypes","select","usedBlockTree","blockEditorStore","getBlocks","filter","blockType","getUnusedBlockTypes","isInstalling","blockId","getErrorNotices","errorNotices","getErrorNoticeForBlock"],"mappings":";;;;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,8BAAT,CAAyCC,KAAzC,EAAgDC,WAAhD,EAA8D;AAAA;;AACpE,kCAAOD,KAAK,CAACE,kBAAN,CAA0BD,WAA1B,GAAyCE,YAAhD,yEAAgE,KAAhE;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,qB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KAA1B,EAAkC;AACxC,SAAOA,KAAK,CAACoB,YAAb;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,sBAAT,CAAiCrB,KAAjC,EAAwCkB,OAAxC,EAAkD;AACxD,SAAOlB,KAAK,CAACoB,YAAN,CAAoBF,OAApB,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRegistrySelector } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport hasBlockType from './utils/has-block-type';\n\n/**\n * Returns true if application is requesting for downloadable blocks.\n *\n * @param {Object} state Global application state.\n * @param {string} filterValue Search string.\n *\n * @return {boolean} Whether a request is in progress for the blocks list.\n */\nexport function isRequestingDownloadableBlocks( state, filterValue ) {\n\treturn state.downloadableBlocks[ filterValue ]?.isRequesting ?? false;\n}\n\n/**\n * Returns the available uninstalled blocks.\n *\n * @param {Object} state Global application state.\n * @param {string} filterValue Search string.\n *\n * @return {Array} Downloadable blocks.\n */\nexport function getDownloadableBlocks( state, filterValue ) {\n\treturn state.downloadableBlocks[ filterValue ]?.results ?? [];\n}\n\n/**\n * Returns the block types that have been installed on the server in this\n * session.\n *\n * @param {Object} state Global application state.\n *\n * @return {Array} Block type items\n */\nexport function getInstalledBlockTypes( state ) {\n\treturn state.blockManagement.installedBlockTypes;\n}\n\n/**\n * Returns block types that have been installed on the server and used in the\n * current post.\n *\n * @param {Object} state Global application state.\n *\n * @return {Array} Block type items.\n */\nexport const getNewBlockTypes = createRegistrySelector(\n\t( select ) => ( state ) => {\n\t\tconst usedBlockTree = select( blockEditorStore ).getBlocks();\n\t\tconst installedBlockTypes = getInstalledBlockTypes( state );\n\n\t\treturn installedBlockTypes.filter( ( blockType ) =>\n\t\t\thasBlockType( blockType, usedBlockTree )\n\t\t);\n\t}\n);\n\n/**\n * Returns the block types that have been installed on the server but are not\n * used in the current post.\n *\n * @param {Object} state Global application state.\n *\n * @return {Array} Block type items.\n */\nexport const getUnusedBlockTypes = createRegistrySelector(\n\t( select ) => ( state ) => {\n\t\tconst usedBlockTree = select( blockEditorStore ).getBlocks();\n\t\tconst installedBlockTypes = getInstalledBlockTypes( state );\n\n\t\treturn installedBlockTypes.filter(\n\t\t\t( blockType ) => ! hasBlockType( blockType, usedBlockTree )\n\t\t);\n\t}\n);\n\n/**\n * Returns true if a block plugin install is in progress.\n *\n * @param {Object} state Global application state.\n * @param {string} blockId Id of the block.\n *\n * @return {boolean} Whether this block is currently being installed.\n */\nexport function isInstalling( state, blockId ) {\n\treturn state.blockManagement.isInstalling[ blockId ] || false;\n}\n\n/**\n * Returns all block error notices.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} Object with error notices.\n */\nexport function getErrorNotices( state ) {\n\treturn state.errorNotices;\n}\n\n/**\n * Returns the error notice for a given block.\n *\n * @param {Object} state Global application state.\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {string|boolean} The error text, or false if no error.\n */\nexport function getErrorNoticeForBlock( state, blockId ) {\n\treturn state.errorNotices[ blockId ];\n}\n"]}
|
|
@@ -14,19 +14,14 @@ exports.default = hasBlockType;
|
|
|
14
14
|
*
|
|
15
15
|
* @return {boolean} Whether the blockType is found.
|
|
16
16
|
*/
|
|
17
|
-
function hasBlockType(blockType) {
|
|
18
|
-
let blocks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
19
|
-
|
|
17
|
+
function hasBlockType(blockType, blocks = []) {
|
|
20
18
|
if (!blocks.length) {
|
|
21
19
|
return false;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
if (blocks.some(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} = _ref;
|
|
28
|
-
return name === blockType.name;
|
|
29
|
-
})) {
|
|
22
|
+
if (blocks.some(({
|
|
23
|
+
name
|
|
24
|
+
}) => name === blockType.name)) {
|
|
30
25
|
return true;
|
|
31
26
|
}
|
|
32
27
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/utils/has-block-type.js"],"names":["hasBlockType","blockType","blocks","length","some","name","i","innerBlocks"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAT,CAAuBC,SAAvB,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/utils/has-block-type.js"],"names":["hasBlockType","blockType","blocks","length","some","name","i","innerBlocks"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAT,CAAuBC,SAAvB,EAAkCC,MAAM,GAAG,EAA3C,EAAgD;AAC9D,MAAK,CAAEA,MAAM,CAACC,MAAd,EAAuB;AACtB,WAAO,KAAP;AACA;;AACD,MAAKD,MAAM,CAACE,IAAP,CAAa,CAAE;AAAEC,IAAAA;AAAF,GAAF,KAAgBA,IAAI,KAAKJ,SAAS,CAACI,IAAhD,CAAL,EAA8D;AAC7D,WAAO,IAAP;AACA;;AACD,OAAM,IAAIC,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGJ,MAAM,CAACC,MAA5B,EAAoCG,CAAC,EAArC,EAA0C;AACzC,QAAKN,YAAY,CAAEC,SAAF,EAAaC,MAAM,CAAEI,CAAF,CAAN,CAAYC,WAAzB,CAAjB,EAA0D;AACzD,aAAO,IAAP;AACA;AACD;;AAED,SAAO,KAAP;AACA","sourcesContent":["/**\n * Check if a block list contains a specific block type. Recursively searches\n * through `innerBlocks` if they exist.\n *\n * @param {Object} blockType A block object to search for.\n * @param {Object[]} blocks The list of blocks to look through.\n *\n * @return {boolean} Whether the blockType is found.\n */\nexport default function hasBlockType( blockType, blocks = [] ) {\n\tif ( ! blocks.length ) {\n\t\treturn false;\n\t}\n\tif ( blocks.some( ( { name } ) => name === blockType.name ) ) {\n\t\treturn true;\n\t}\n\tfor ( let i = 0; i < blocks.length; i++ ) {\n\t\tif ( hasBlockType( blockType, blocks[ i ].innerBlocks ) ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n"]}
|
|
@@ -4,15 +4,12 @@ import { createElement } from "@wordpress/element";
|
|
|
4
4
|
* Internal dependencies
|
|
5
5
|
*/
|
|
6
6
|
import Stars from './stars';
|
|
7
|
-
export const BlockRatings =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
rating: rating
|
|
15
|
-
}));
|
|
16
|
-
};
|
|
7
|
+
export const BlockRatings = ({
|
|
8
|
+
rating
|
|
9
|
+
}) => createElement("span", {
|
|
10
|
+
className: "block-directory-block-ratings"
|
|
11
|
+
}, createElement(Stars, {
|
|
12
|
+
rating: rating
|
|
13
|
+
}));
|
|
17
14
|
export default BlockRatings;
|
|
18
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/components/block-ratings/index.js"],"names":["Stars","BlockRatings","rating"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,KAAP,MAAkB,SAAlB;AAEA,OAAO,MAAMC,YAAY,GAAG
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/components/block-ratings/index.js"],"names":["Stars","BlockRatings","rating"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,KAAP,MAAkB,SAAlB;AAEA,OAAO,MAAMC,YAAY,GAAG,CAAE;AAAEC,EAAAA;AAAF,CAAF,KAC3B;AAAM,EAAA,SAAS,EAAC;AAAhB,GACC,cAAC,KAAD;AAAO,EAAA,MAAM,EAAGA;AAAhB,EADD,CADM;AAMP,eAAeD,YAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport Stars from './stars';\n\nexport const BlockRatings = ( { rating } ) => (\n\t<span className=\"block-directory-block-ratings\">\n\t\t<Stars rating={ rating } />\n\t</span>\n);\n\nexport default BlockRatings;\n"]}
|
|
@@ -6,10 +6,9 @@ import { createElement } from "@wordpress/element";
|
|
|
6
6
|
import { __, sprintf } from '@wordpress/i18n';
|
|
7
7
|
import { Icon, starEmpty, starFilled, starHalf } from '@wordpress/icons';
|
|
8
8
|
|
|
9
|
-
function Stars(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} = _ref;
|
|
9
|
+
function Stars({
|
|
10
|
+
rating
|
|
11
|
+
}) {
|
|
13
12
|
const stars = Math.round(rating / 0.5) * 0.5;
|
|
14
13
|
const fullStarCount = Math.floor(rating);
|
|
15
14
|
const halfStarCount = Math.ceil(rating - fullStarCount);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/components/block-ratings/stars.js"],"names":["__","sprintf","Icon","starEmpty","starFilled","starHalf","Stars","rating","stars","Math","round","fullStarCount","floor","halfStarCount","ceil","emptyStarCount","Array","from","length","map","_","i"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,IAAT,EAAeC,SAAf,EAA0BC,UAA1B,EAAsCC,QAAtC,QAAsD,kBAAtD;;AAEA,SAASC,KAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/components/block-ratings/stars.js"],"names":["__","sprintf","Icon","starEmpty","starFilled","starHalf","Stars","rating","stars","Math","round","fullStarCount","floor","halfStarCount","ceil","emptyStarCount","Array","from","length","map","_","i"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,IAAT,EAAeC,SAAf,EAA0BC,UAA1B,EAAsCC,QAAtC,QAAsD,kBAAtD;;AAEA,SAASC,KAAT,CAAgB;AAAEC,EAAAA;AAAF,CAAhB,EAA6B;AAC5B,QAAMC,KAAK,GAAGC,IAAI,CAACC,KAAL,CAAYH,MAAM,GAAG,GAArB,IAA6B,GAA3C;AAEA,QAAMI,aAAa,GAAGF,IAAI,CAACG,KAAL,CAAYL,MAAZ,CAAtB;AACA,QAAMM,aAAa,GAAGJ,IAAI,CAACK,IAAL,CAAWP,MAAM,GAAGI,aAApB,CAAtB;AACA,QAAMI,cAAc,GAAG,KAAMJ,aAAa,GAAGE,aAAtB,CAAvB;AAEA,SACC;AACC,kBAAaZ,OAAO;AACnB;AACAD,IAAAA,EAAE,CAAE,mBAAF,CAFiB,EAGnBQ,KAHmB;AADrB,KAOGQ,KAAK,CAACC,IAAN,CAAY;AAAEC,IAAAA,MAAM,EAAEP;AAAV,GAAZ,EAAwCQ,GAAxC,CAA6C,CAAEC,CAAF,EAAKC,CAAL,KAC9C,cAAC,IAAD;AACC,IAAA,GAAG,EAAI,cAAcA,CAAG,EADzB;AAEC,IAAA,SAAS,EAAC,0CAFX;AAGC,IAAA,IAAI,EAAGjB,UAHR;AAIC,IAAA,IAAI,EAAG;AAJR,IADC,CAPH,EAeGY,KAAK,CAACC,IAAN,CAAY;AAAEC,IAAAA,MAAM,EAAEL;AAAV,GAAZ,EAAwCM,GAAxC,CAA6C,CAAEC,CAAF,EAAKC,CAAL,KAC9C,cAAC,IAAD;AACC,IAAA,GAAG,EAAI,cAAcA,CAAG,EADzB;AAEC,IAAA,SAAS,EAAC,+CAFX;AAGC,IAAA,IAAI,EAAGhB,QAHR;AAIC,IAAA,IAAI,EAAG;AAJR,IADC,CAfH,EAuBGW,KAAK,CAACC,IAAN,CAAY;AAAEC,IAAAA,MAAM,EAAEH;AAAV,GAAZ,EAAyCI,GAAzC,CAA8C,CAAEC,CAAF,EAAKC,CAAL,KAC/C,cAAC,IAAD;AACC,IAAA,GAAG,EAAI,eAAeA,CAAG,EAD1B;AAEC,IAAA,SAAS,EAAC,2CAFX;AAGC,IAAA,IAAI,EAAGlB,SAHR;AAIC,IAAA,IAAI,EAAG;AAJR,IADC,CAvBH,CADD;AAkCA;;AAED,eAAeG,KAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Icon, starEmpty, starFilled, starHalf } from '@wordpress/icons';\n\nfunction Stars( { rating } ) {\n\tconst stars = Math.round( rating / 0.5 ) * 0.5;\n\n\tconst fullStarCount = Math.floor( rating );\n\tconst halfStarCount = Math.ceil( rating - fullStarCount );\n\tconst emptyStarCount = 5 - ( fullStarCount + halfStarCount );\n\n\treturn (\n\t\t<span\n\t\t\taria-label={ sprintf(\n\t\t\t\t/* translators: %s: number of stars. */\n\t\t\t\t__( '%s out of 5 stars' ),\n\t\t\t\tstars\n\t\t\t) }\n\t\t>\n\t\t\t{ Array.from( { length: fullStarCount } ).map( ( _, i ) => (\n\t\t\t\t<Icon\n\t\t\t\t\tkey={ `full_stars_${ i }` }\n\t\t\t\t\tclassName=\"block-directory-block-ratings__star-full\"\n\t\t\t\t\ticon={ starFilled }\n\t\t\t\t\tsize={ 16 }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t\t{ Array.from( { length: halfStarCount } ).map( ( _, i ) => (\n\t\t\t\t<Icon\n\t\t\t\t\tkey={ `half_stars_${ i }` }\n\t\t\t\t\tclassName=\"block-directory-block-ratings__star-half-full\"\n\t\t\t\t\ticon={ starHalf }\n\t\t\t\t\tsize={ 16 }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t\t{ Array.from( { length: emptyStarCount } ).map( ( _, i ) => (\n\t\t\t\t<Icon\n\t\t\t\t\tkey={ `empty_stars_${ i }` }\n\t\t\t\t\tclassName=\"block-directory-block-ratings__star-empty\"\n\t\t\t\t\ticon={ starEmpty }\n\t\t\t\t\tsize={ 16 }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</span>\n\t);\n}\n\nexport default Stars;\n"]}
|
|
@@ -9,39 +9,34 @@ import { __, sprintf } from '@wordpress/i18n';
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import DownloadableBlockIcon from '../downloadable-block-icon';
|
|
12
|
-
export default function CompactList(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} = _ref;
|
|
16
|
-
|
|
12
|
+
export default function CompactList({
|
|
13
|
+
items
|
|
14
|
+
}) {
|
|
17
15
|
if (!items.length) {
|
|
18
16
|
return null;
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
return createElement("ul", {
|
|
22
20
|
className: "block-directory-compact-list"
|
|
23
|
-
}, items.map(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
/* translators: %s: Name of the block author. */
|
|
44
|
-
__('By %s'), author))));
|
|
45
|
-
}));
|
|
21
|
+
}, items.map(({
|
|
22
|
+
icon,
|
|
23
|
+
id,
|
|
24
|
+
title,
|
|
25
|
+
author
|
|
26
|
+
}) => createElement("li", {
|
|
27
|
+
key: id,
|
|
28
|
+
className: "block-directory-compact-list__item"
|
|
29
|
+
}, createElement(DownloadableBlockIcon, {
|
|
30
|
+
icon: icon,
|
|
31
|
+
title: title
|
|
32
|
+
}), createElement("div", {
|
|
33
|
+
className: "block-directory-compact-list__item-details"
|
|
34
|
+
}, createElement("div", {
|
|
35
|
+
className: "block-directory-compact-list__item-title"
|
|
36
|
+
}, title), createElement("div", {
|
|
37
|
+
className: "block-directory-compact-list__item-author"
|
|
38
|
+
}, sprintf(
|
|
39
|
+
/* translators: %s: Name of the block author. */
|
|
40
|
+
__('By %s'), author))))));
|
|
46
41
|
}
|
|
47
42
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/components/compact-list/index.js"],"names":["__","sprintf","DownloadableBlockIcon","CompactList","items","length","map","icon","id","title","author"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AAEA;AACA;AACA;;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;AAEA,eAAe,SAASC,WAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/components/compact-list/index.js"],"names":["__","sprintf","DownloadableBlockIcon","CompactList","items","length","map","icon","id","title","author"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AAEA;AACA;AACA;;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;AAEA,eAAe,SAASC,WAAT,CAAsB;AAAEC,EAAAA;AAAF,CAAtB,EAAkC;AAChD,MAAK,CAAEA,KAAK,CAACC,MAAb,EAAsB;AACrB,WAAO,IAAP;AACA;;AAED,SACC;AAAI,IAAA,SAAS,EAAC;AAAd,KACGD,KAAK,CAACE,GAAN,CAAW,CAAE;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,EAAR;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA;AAAnB,GAAF,KACZ;AAAI,IAAA,GAAG,EAAGF,EAAV;AAAe,IAAA,SAAS,EAAC;AAAzB,KACC,cAAC,qBAAD;AAAuB,IAAA,IAAI,EAAGD,IAA9B;AAAqC,IAAA,KAAK,EAAGE;AAA7C,IADD,EAGC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGA,KADH,CADD,EAIC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGR,OAAO;AACR;AACAD,EAAAA,EAAE,CAAE,OAAF,CAFM,EAGRU,MAHQ,CADV,CAJD,CAHD,CADC,CADH,CADD;AAsBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport DownloadableBlockIcon from '../downloadable-block-icon';\n\nexport default function CompactList( { items } ) {\n\tif ( ! items.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<ul className=\"block-directory-compact-list\">\n\t\t\t{ items.map( ( { icon, id, title, author } ) => (\n\t\t\t\t<li key={ id } className=\"block-directory-compact-list__item\">\n\t\t\t\t\t<DownloadableBlockIcon icon={ icon } title={ title } />\n\n\t\t\t\t\t<div className=\"block-directory-compact-list__item-details\">\n\t\t\t\t\t\t<div className=\"block-directory-compact-list__item-title\">\n\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div className=\"block-directory-compact-list__item-author\">\n\t\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t\t/* translators: %s: Name of the block author. */\n\t\t\t\t\t\t\t\t__( 'By %s' ),\n\t\t\t\t\t\t\t\tauthor\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</li>\n\t\t\t) ) }\n\t\t</ul>\n\t);\n}\n"]}
|
|
@@ -5,10 +5,9 @@ import { createElement } from "@wordpress/element";
|
|
|
5
5
|
*/
|
|
6
6
|
import { BlockIcon } from '@wordpress/block-editor';
|
|
7
7
|
|
|
8
|
-
function DownloadableBlockIcon(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} = _ref;
|
|
8
|
+
function DownloadableBlockIcon({
|
|
9
|
+
icon
|
|
10
|
+
}) {
|
|
12
11
|
const className = 'block-directory-downloadable-block-icon';
|
|
13
12
|
return icon.match(/\.(jpeg|jpg|gif|png|svg)(?:\?.*)?$/) !== null ? createElement("img", {
|
|
14
13
|
className: className,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/components/downloadable-block-icon/index.js"],"names":["BlockIcon","DownloadableBlockIcon","icon","className","match"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,yBAA1B;;AAEA,SAASC,qBAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/components/downloadable-block-icon/index.js"],"names":["BlockIcon","DownloadableBlockIcon","icon","className","match"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,yBAA1B;;AAEA,SAASC,qBAAT,CAAgC;AAAEC,EAAAA;AAAF,CAAhC,EAA2C;AAC1C,QAAMC,SAAS,GAAG,yCAAlB;AACA,SAAOD,IAAI,CAACE,KAAL,CAAY,oCAAZ,MAAuD,IAAvD,GACN;AAAK,IAAA,SAAS,EAAGD,SAAjB;AAA6B,IAAA,GAAG,EAAGD,IAAnC;AAA0C,IAAA,GAAG,EAAC;AAA9C,IADM,GAGN,cAAC,SAAD;AAAW,IAAA,SAAS,EAAGC,SAAvB;AAAmC,IAAA,IAAI,EAAGD,IAA1C;AAAiD,IAAA,UAAU;AAA3D,IAHD;AAKA;;AAED,eAAeD,qBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { BlockIcon } from '@wordpress/block-editor';\n\nfunction DownloadableBlockIcon( { icon } ) {\n\tconst className = 'block-directory-downloadable-block-icon';\n\treturn icon.match( /\\.(jpeg|jpg|gif|png|svg)(?:\\?.*)?$/ ) !== null ? (\n\t\t<img className={ className } src={ icon } alt=\"\" />\n\t) : (\n\t\t<BlockIcon className={ className } icon={ icon } showColors />\n\t);\n}\n\nexport default DownloadableBlockIcon;\n"]}
|