@wordpress/block-directory 4.20.0 → 4.21.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.
- package/CHANGELOG.md +2 -0
- package/build/components/downloadable-block-list-item/index.js +25 -18
- package/build/components/downloadable-block-list-item/index.js.map +1 -1
- package/build/components/downloadable-blocks-list/index.js +8 -3
- package/build/components/downloadable-blocks-list/index.js.map +1 -1
- package/build/components/downloadable-blocks-panel/index.js +15 -8
- package/build/components/downloadable-blocks-panel/index.js.map +1 -1
- package/build/lock-unlock.js +18 -0
- package/build/lock-unlock.js.map +1 -0
- package/build-module/components/downloadable-block-list-item/index.js +24 -18
- package/build-module/components/downloadable-block-list-item/index.js.map +1 -1
- package/build-module/components/downloadable-blocks-list/index.js +8 -3
- package/build-module/components/downloadable-blocks-list/index.js.map +1 -1
- package/build-module/components/downloadable-blocks-panel/index.js +15 -8
- package/build-module/components/downloadable-blocks-panel/index.js.map +1 -1
- package/build-module/lock-unlock.js +9 -0
- package/build-module/lock-unlock.js.map +1 -0
- package/package.json +21 -20
- package/src/components/downloadable-block-list-item/index.js +25 -18
- package/src/components/downloadable-blocks-list/index.js +6 -6
- package/src/components/downloadable-blocks-panel/index.js +20 -8
- package/src/lock-unlock.js +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -16,6 +16,7 @@ var _blockRatings = _interopRequireDefault(require("../block-ratings"));
|
|
|
16
16
|
var _downloadableBlockIcon = _interopRequireDefault(require("../downloadable-block-icon"));
|
|
17
17
|
var _downloadableBlockNotice = _interopRequireDefault(require("../downloadable-block-notice"));
|
|
18
18
|
var _store = require("../../store");
|
|
19
|
+
var _lockUnlock = require("../../lock-unlock");
|
|
19
20
|
/**
|
|
20
21
|
* WordPress dependencies
|
|
21
22
|
*/
|
|
@@ -24,6 +25,10 @@ var _store = require("../../store");
|
|
|
24
25
|
* Internal dependencies
|
|
25
26
|
*/
|
|
26
27
|
|
|
28
|
+
const {
|
|
29
|
+
CompositeItemV2: CompositeItem
|
|
30
|
+
} = (0, _lockUnlock.unlock)(_components.privateApis);
|
|
31
|
+
|
|
27
32
|
// Return the appropriate block item label, given the block data and status.
|
|
28
33
|
function getDownloadableBlockLabel({
|
|
29
34
|
title,
|
|
@@ -93,25 +98,27 @@ function DownloadableBlockListItem({
|
|
|
93
98
|
} else if (isInstalling) {
|
|
94
99
|
statusText = (0, _i18n.__)('Installing…');
|
|
95
100
|
}
|
|
96
|
-
return (0, _react.createElement)(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
event
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
101
|
+
return (0, _react.createElement)(CompositeItem, {
|
|
102
|
+
render: (0, _react.createElement)(_components.Button, {
|
|
103
|
+
__experimentalIsFocusable: true,
|
|
104
|
+
type: "button",
|
|
105
|
+
role: "option",
|
|
106
|
+
className: "block-directory-downloadable-block-list-item",
|
|
107
|
+
isBusy: isInstalling,
|
|
108
|
+
onClick: event => {
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
onClick();
|
|
111
|
+
},
|
|
112
|
+
label: getDownloadableBlockLabel(item, {
|
|
113
|
+
hasNotice,
|
|
114
|
+
isInstalled,
|
|
115
|
+
isInstalling
|
|
116
|
+
}),
|
|
117
|
+
showTooltip: true,
|
|
118
|
+
tooltipPosition: "top center"
|
|
112
119
|
}),
|
|
113
|
-
|
|
114
|
-
|
|
120
|
+
store: composite,
|
|
121
|
+
disabled: isInstalling || !isInstallable
|
|
115
122
|
}, (0, _react.createElement)("div", {
|
|
116
123
|
className: "block-directory-downloadable-block-list-item__icon"
|
|
117
124
|
}, (0, _react.createElement)(_downloadableBlockIcon.default, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_components","_element","_htmlEntities","_blocks","_data","_blockRatings","_interopRequireDefault","_downloadableBlockIcon","_downloadableBlockNotice","_store","getDownloadableBlockLabel","title","rating","ratingCount","hasNotice","isInstalled","isInstalling","stars","Math","round","sprintf","decodeEntities","_n","DownloadableBlockListItem","composite","item","onClick","author","description","icon","getBlockType","name","isInstallable","useSelect","select","getErrorNoticeForBlock","isBlockInstalling","blockDirectoryStore","notice","id","hasFatal","isFatal","statusText","__","_react","createElement","__unstableCompositeItem","__experimentalIsFocusable","role","as","Button","className","event","preventDefault","isBusy","disabled","label","showTooltip","tooltipPosition","default","Spinner","createInterpolateElement","span","block","Fragment","VisuallyHidden","_default","exports"],"sources":["@wordpress/block-directory/src/components/downloadable-block-list-item/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tSpinner,\n\tVisuallyHidden,\n\t__unstableCompositeItem as CompositeItem,\n} from '@wordpress/components';\nimport { createInterpolateElement } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { getBlockType } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport BlockRatings from '../block-ratings';\nimport DownloadableBlockIcon from '../downloadable-block-icon';\nimport DownloadableBlockNotice from '../downloadable-block-notice';\nimport { store as blockDirectoryStore } from '../../store';\n\n// Return the appropriate block item label, given the block data and status.\nfunction getDownloadableBlockLabel(\n\t{ title, rating, ratingCount },\n\t{ hasNotice, isInstalled, isInstalling }\n) {\n\tconst stars = Math.round( rating / 0.5 ) * 0.5;\n\n\tif ( ! isInstalled && hasNotice ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Retry installing %s.', decodeEntities( title ) );\n\t}\n\n\tif ( isInstalled ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Add %s.', decodeEntities( title ) );\n\t}\n\n\tif ( isInstalling ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Installing %s.', decodeEntities( title ) );\n\t}\n\n\t// No ratings yet, just use the title.\n\tif ( ratingCount < 1 ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Install %s.', decodeEntities( title ) );\n\t}\n\n\treturn sprintf(\n\t\t/* translators: %1$s: block title, %2$s: average rating, %3$s: total ratings count. */\n\t\t_n(\n\t\t\t'Install %1$s. %2$s stars with %3$s review.',\n\t\t\t'Install %1$s. %2$s stars with %3$s reviews.',\n\t\t\tratingCount\n\t\t),\n\t\tdecodeEntities( title ),\n\t\tstars,\n\t\tratingCount\n\t);\n}\n\nfunction DownloadableBlockListItem( { composite, item, onClick } ) {\n\tconst { author, description, icon, rating, title } = item;\n\t// getBlockType returns a block object if this block exists, or null if not.\n\tconst isInstalled = !! getBlockType( item.name );\n\n\tconst { hasNotice, isInstalling, isInstallable } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getErrorNoticeForBlock, isInstalling: isBlockInstalling } =\n\t\t\t\tselect( blockDirectoryStore );\n\t\t\tconst notice = getErrorNoticeForBlock( item.id );\n\t\t\tconst hasFatal = notice && notice.isFatal;\n\t\t\treturn {\n\t\t\t\thasNotice: !! notice,\n\t\t\t\tisInstalling: isBlockInstalling( item.id ),\n\t\t\t\tisInstallable: ! hasFatal,\n\t\t\t};\n\t\t},\n\t\t[ item ]\n\t);\n\n\tlet statusText = '';\n\tif ( isInstalled ) {\n\t\tstatusText = __( 'Installed!' );\n\t} else if ( isInstalling ) {\n\t\tstatusText = __( 'Installing…' );\n\t}\n\n\treturn (\n\t\t<CompositeItem\n\t\t\t__experimentalIsFocusable\n\t\t\trole=\"option\"\n\t\t\tas={ Button }\n\t\t\t{ ...composite }\n\t\t\tclassName=\"block-directory-downloadable-block-list-item\"\n\t\t\tonClick={ ( event ) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tonClick();\n\t\t\t} }\n\t\t\tisBusy={ isInstalling }\n\t\t\tdisabled={ isInstalling || ! isInstallable }\n\t\t\tlabel={ getDownloadableBlockLabel( item, {\n\t\t\t\thasNotice,\n\t\t\t\tisInstalled,\n\t\t\t\tisInstalling,\n\t\t\t} ) }\n\t\t\tshowTooltip={ true }\n\t\t\ttooltipPosition=\"top center\"\n\t\t>\n\t\t\t<div className=\"block-directory-downloadable-block-list-item__icon\">\n\t\t\t\t<DownloadableBlockIcon icon={ icon } title={ title } />\n\t\t\t\t{ isInstalling ? (\n\t\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__spinner\">\n\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t</span>\n\t\t\t\t) : (\n\t\t\t\t\t<BlockRatings rating={ rating } />\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t<span className=\"block-directory-downloadable-block-list-item__details\">\n\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__title\">\n\t\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t/* translators: %1$s: block title, %2$s: author name. */\n\t\t\t\t\t\t\t__( '%1$s <span>by %2$s</span>' ),\n\t\t\t\t\t\t\tdecodeEntities( title ),\n\t\t\t\t\t\t\tauthor\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tspan: (\n\t\t\t\t\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__author\" />\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</span>\n\t\t\t\t{ hasNotice ? (\n\t\t\t\t\t<DownloadableBlockNotice block={ item } />\n\t\t\t\t) : (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__desc\">\n\t\t\t\t\t\t\t{ !! statusText\n\t\t\t\t\t\t\t\t? statusText\n\t\t\t\t\t\t\t\t: decodeEntities( description ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t{ isInstallable &&\n\t\t\t\t\t\t\t! ( isInstalled || isInstalling ) && (\n\t\t\t\t\t\t\t\t<VisuallyHidden>\n\t\t\t\t\t\t\t\t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AAM,CAAC,EACvBgB,MACD,CAAC,EACD;IACCmC,IAAI,EACH,IAAAlB,MAAA,CAAAC,aAAA;MAAMM,SAAS,EAAC;IAAsD,CAAE;EAE1E,CACD,CACK,CAAC,EACLrC,SAAS,GACV,IAAA8B,MAAA,CAAAC,aAAA,EAACrC,wBAAA,CAAAmD,OAAuB;IAACI,KAAK,EAAGtC;EAAM,CAAE,CAAC,GAE1C,IAAAmB,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAoB,QAAA,QACC,IAAApB,MAAA,CAAAC,aAAA;IAAMM,SAAS,EAAC;EAAoD,GACjE,CAAC,CAAET,UAAU,GACZA,UAAU,GACV,IAAArB,4BAAc,EAAEO,WAAY,CAC1B,CAAC,EACLI,aAAa,IACd,EAAIjB,WAAW,IAAIC,YAAY,CAAE,IAChC,IAAA4B,MAAA,CAAAC,aAAA,EAAC7C,WAAA,CAAAiE,cAAc,QACZ,IAAAtB,QAAE,EAAE,eAAgB,CACP,CAEjB,CAEE,CACQ,CAAC;AAElB;AAAC,IAAAuB,QAAA,GAEc3C,yBAAyB;AAAA4C,OAAA,CAAAR,OAAA,GAAAO,QAAA"}
|
|
1
|
+
{"version":3,"names":["_i18n","require","_components","_element","_htmlEntities","_blocks","_data","_blockRatings","_interopRequireDefault","_downloadableBlockIcon","_downloadableBlockNotice","_store","_lockUnlock","CompositeItemV2","CompositeItem","unlock","componentsPrivateApis","getDownloadableBlockLabel","title","rating","ratingCount","hasNotice","isInstalled","isInstalling","stars","Math","round","sprintf","decodeEntities","_n","DownloadableBlockListItem","composite","item","onClick","author","description","icon","getBlockType","name","isInstallable","useSelect","select","getErrorNoticeForBlock","isBlockInstalling","blockDirectoryStore","notice","id","hasFatal","isFatal","statusText","__","_react","createElement","render","Button","__experimentalIsFocusable","type","role","className","isBusy","event","preventDefault","label","showTooltip","tooltipPosition","store","disabled","default","Spinner","createInterpolateElement","span","block","Fragment","VisuallyHidden","_default","exports"],"sources":["@wordpress/block-directory/src/components/downloadable-block-list-item/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tSpinner,\n\tVisuallyHidden,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { createInterpolateElement } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { getBlockType } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport BlockRatings from '../block-ratings';\nimport DownloadableBlockIcon from '../downloadable-block-icon';\nimport DownloadableBlockNotice from '../downloadable-block-notice';\nimport { store as blockDirectoryStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { CompositeItemV2: CompositeItem } = unlock( componentsPrivateApis );\n\n// Return the appropriate block item label, given the block data and status.\nfunction getDownloadableBlockLabel(\n\t{ title, rating, ratingCount },\n\t{ hasNotice, isInstalled, isInstalling }\n) {\n\tconst stars = Math.round( rating / 0.5 ) * 0.5;\n\n\tif ( ! isInstalled && hasNotice ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Retry installing %s.', decodeEntities( title ) );\n\t}\n\n\tif ( isInstalled ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Add %s.', decodeEntities( title ) );\n\t}\n\n\tif ( isInstalling ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Installing %s.', decodeEntities( title ) );\n\t}\n\n\t// No ratings yet, just use the title.\n\tif ( ratingCount < 1 ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Install %s.', decodeEntities( title ) );\n\t}\n\n\treturn sprintf(\n\t\t/* translators: %1$s: block title, %2$s: average rating, %3$s: total ratings count. */\n\t\t_n(\n\t\t\t'Install %1$s. %2$s stars with %3$s review.',\n\t\t\t'Install %1$s. %2$s stars with %3$s reviews.',\n\t\t\tratingCount\n\t\t),\n\t\tdecodeEntities( title ),\n\t\tstars,\n\t\tratingCount\n\t);\n}\n\nfunction DownloadableBlockListItem( { composite, item, onClick } ) {\n\tconst { author, description, icon, rating, title } = item;\n\t// getBlockType returns a block object if this block exists, or null if not.\n\tconst isInstalled = !! getBlockType( item.name );\n\n\tconst { hasNotice, isInstalling, isInstallable } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getErrorNoticeForBlock, isInstalling: isBlockInstalling } =\n\t\t\t\tselect( blockDirectoryStore );\n\t\t\tconst notice = getErrorNoticeForBlock( item.id );\n\t\t\tconst hasFatal = notice && notice.isFatal;\n\t\t\treturn {\n\t\t\t\thasNotice: !! notice,\n\t\t\t\tisInstalling: isBlockInstalling( item.id ),\n\t\t\t\tisInstallable: ! hasFatal,\n\t\t\t};\n\t\t},\n\t\t[ item ]\n\t);\n\n\tlet statusText = '';\n\tif ( isInstalled ) {\n\t\tstatusText = __( 'Installed!' );\n\t} else if ( isInstalling ) {\n\t\tstatusText = __( 'Installing…' );\n\t}\n\n\treturn (\n\t\t<CompositeItem\n\t\t\trender={\n\t\t\t\t<Button\n\t\t\t\t\t__experimentalIsFocusable\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\trole=\"option\"\n\t\t\t\t\tclassName=\"block-directory-downloadable-block-list-item\"\n\t\t\t\t\tisBusy={ isInstalling }\n\t\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tonClick();\n\t\t\t\t\t} }\n\t\t\t\t\tlabel={ getDownloadableBlockLabel( item, {\n\t\t\t\t\t\thasNotice,\n\t\t\t\t\t\tisInstalled,\n\t\t\t\t\t\tisInstalling,\n\t\t\t\t\t} ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\ttooltipPosition=\"top center\"\n\t\t\t\t/>\n\t\t\t}\n\t\t\tstore={ composite }\n\t\t\tdisabled={ isInstalling || ! isInstallable }\n\t\t>\n\t\t\t<div className=\"block-directory-downloadable-block-list-item__icon\">\n\t\t\t\t<DownloadableBlockIcon icon={ icon } title={ title } />\n\t\t\t\t{ isInstalling ? (\n\t\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__spinner\">\n\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t</span>\n\t\t\t\t) : (\n\t\t\t\t\t<BlockRatings rating={ rating } />\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t<span className=\"block-directory-downloadable-block-list-item__details\">\n\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__title\">\n\t\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t/* translators: %1$s: block title, %2$s: author name. */\n\t\t\t\t\t\t\t__( '%1$s <span>by %2$s</span>' ),\n\t\t\t\t\t\t\tdecodeEntities( title ),\n\t\t\t\t\t\t\tauthor\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tspan: (\n\t\t\t\t\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__author\" />\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</span>\n\t\t\t\t{ hasNotice ? (\n\t\t\t\t\t<DownloadableBlockNotice block={ item } />\n\t\t\t\t) : (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__desc\">\n\t\t\t\t\t\t\t{ !! statusText\n\t\t\t\t\t\t\t\t? statusText\n\t\t\t\t\t\t\t\t: decodeEntities( description ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t{ isInstallable &&\n\t\t\t\t\t\t\t! ( isInstalled || isInstalling ) && (\n\t\t\t\t\t\t\t\t<VisuallyHidden>\n\t\t\t\t\t\t\t\t\t{ __( 'Install block' ) }\n\t\t\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</span>\n\t\t</CompositeItem>\n\t);\n}\n\nexport default DownloadableBlockListItem;\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC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CoC,IAAI,EACH,IAAAnB,MAAA,CAAAC,aAAA;MAAMM,SAAS,EAAC;IAAsD,CAAE;EAE1E,CACD,CACK,CAAC,EACLrC,SAAS,GACV,IAAA8B,MAAA,CAAAC,aAAA,EAAC1C,wBAAA,CAAAyD,OAAuB;IAACI,KAAK,EAAGvC;EAAM,CAAE,CAAC,GAE1C,IAAAmB,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAqB,QAAA,QACC,IAAArB,MAAA,CAAAC,aAAA;IAAMM,SAAS,EAAC;EAAoD,GACjE,CAAC,CAAET,UAAU,GACZA,UAAU,GACV,IAAArB,4BAAc,EAAEO,WAAY,CAC1B,CAAC,EACLI,aAAa,IACd,EAAIjB,WAAW,IAAIC,YAAY,CAAE,IAChC,IAAA4B,MAAA,CAAAC,aAAA,EAAClD,WAAA,CAAAuE,cAAc,QACZ,IAAAvB,QAAE,EAAE,eAAgB,CACP,CAEjB,CAEE,CACQ,CAAC;AAElB;AAAC,IAAAwB,QAAA,GAEc5C,yBAAyB;AAAA6C,OAAA,CAAAR,OAAA,GAAAO,QAAA"}
|
|
@@ -12,6 +12,7 @@ var _blocks = require("@wordpress/blocks");
|
|
|
12
12
|
var _data = require("@wordpress/data");
|
|
13
13
|
var _downloadableBlockListItem = _interopRequireDefault(require("../downloadable-block-list-item"));
|
|
14
14
|
var _store = require("../../store");
|
|
15
|
+
var _lockUnlock = require("../../lock-unlock");
|
|
15
16
|
/**
|
|
16
17
|
* WordPress dependencies
|
|
17
18
|
*/
|
|
@@ -20,21 +21,25 @@ var _store = require("../../store");
|
|
|
20
21
|
* Internal dependencies
|
|
21
22
|
*/
|
|
22
23
|
|
|
24
|
+
const {
|
|
25
|
+
CompositeV2: Composite,
|
|
26
|
+
useCompositeStoreV2: useCompositeStore
|
|
27
|
+
} = (0, _lockUnlock.unlock)(_components.privateApis);
|
|
23
28
|
const noop = () => {};
|
|
24
29
|
function DownloadableBlocksList({
|
|
25
30
|
items,
|
|
26
31
|
onHover = noop,
|
|
27
32
|
onSelect
|
|
28
33
|
}) {
|
|
29
|
-
const composite = (
|
|
34
|
+
const composite = useCompositeStore();
|
|
30
35
|
const {
|
|
31
36
|
installBlockType
|
|
32
37
|
} = (0, _data.useDispatch)(_store.store);
|
|
33
38
|
if (!items.length) {
|
|
34
39
|
return null;
|
|
35
40
|
}
|
|
36
|
-
return (0, _react.createElement)(
|
|
37
|
-
|
|
41
|
+
return (0, _react.createElement)(Composite, {
|
|
42
|
+
store: composite,
|
|
38
43
|
role: "listbox",
|
|
39
44
|
className: "block-directory-downloadable-blocks-list",
|
|
40
45
|
"aria-label": (0, _i18n.__)('Blocks available for install')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_components","_blocks","_data","_downloadableBlockListItem","_interopRequireDefault","_store","noop","DownloadableBlocksList","items","onHover","onSelect","composite","
|
|
1
|
+
{"version":3,"names":["_i18n","require","_components","_blocks","_data","_downloadableBlockListItem","_interopRequireDefault","_store","_lockUnlock","CompositeV2","Composite","useCompositeStoreV2","useCompositeStore","unlock","componentsPrivateApis","noop","DownloadableBlocksList","items","onHover","onSelect","composite","installBlockType","useDispatch","blockDirectoryStore","length","_react","createElement","store","role","className","__","map","item","default","key","id","onClick","getBlockType","name","then","success","_default","exports"],"sources":["@wordpress/block-directory/src/components/downloadable-blocks-list/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { privateApis as componentsPrivateApis } from '@wordpress/components';\nimport { getBlockType } from '@wordpress/blocks';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport DownloadableBlockListItem from '../downloadable-block-list-item';\nimport { store as blockDirectoryStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { CompositeV2: Composite, useCompositeStoreV2: useCompositeStore } =\n\tunlock( componentsPrivateApis );\nconst noop = () => {};\n\nfunction DownloadableBlocksList( { items, onHover = noop, onSelect } ) {\n\tconst composite = useCompositeStore();\n\tconst { installBlockType } = useDispatch( blockDirectoryStore );\n\n\tif ( ! items.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Composite\n\t\t\tstore={ composite }\n\t\t\trole=\"listbox\"\n\t\t\tclassName=\"block-directory-downloadable-blocks-list\"\n\t\t\taria-label={ __( 'Blocks available for install' ) }\n\t\t>\n\t\t\t{ items.map( ( item ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<DownloadableBlockListItem\n\t\t\t\t\t\tkey={ item.id }\n\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t// Check if the block is registered (`getBlockType`\n\t\t\t\t\t\t\t// will return an object). If so, insert the block.\n\t\t\t\t\t\t\t// This prevents installing existing plugins.\n\t\t\t\t\t\t\tif ( getBlockType( item.name ) ) {\n\t\t\t\t\t\t\t\tonSelect( item );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tinstallBlockType( item ).then( ( success ) => {\n\t\t\t\t\t\t\t\t\tif ( success ) {\n\t\t\t\t\t\t\t\t\t\tonSelect( item );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonHover( null );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</Composite>\n\t);\n}\n\nexport default DownloadableBlocksList;\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,0BAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAbA;AACA;AACA;;AAMA;AACA;AACA;;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AE,CACQ,CAAC;AAEd;AAAC,IAAAS,QAAA,GAEczB,sBAAsB;AAAA0B,OAAA,CAAAT,OAAA,GAAAQ,QAAA"}
|
|
@@ -9,9 +9,9 @@ var _react = require("react");
|
|
|
9
9
|
var _i18n = require("@wordpress/i18n");
|
|
10
10
|
var _components = require("@wordpress/components");
|
|
11
11
|
var _compose = require("@wordpress/compose");
|
|
12
|
-
var _blockEditor = require("@wordpress/block-editor");
|
|
13
12
|
var _coreData = require("@wordpress/core-data");
|
|
14
13
|
var _data = require("@wordpress/data");
|
|
14
|
+
var _blocks = require("@wordpress/blocks");
|
|
15
15
|
var _downloadableBlocksList = _interopRequireDefault(require("../downloadable-blocks-list"));
|
|
16
16
|
var _inserterPanel = _interopRequireDefault(require("./inserter-panel"));
|
|
17
17
|
var _noResults = _interopRequireDefault(require("./no-results"));
|
|
@@ -59,20 +59,27 @@ function DownloadableBlocksPanel({
|
|
|
59
59
|
})) : !hasLocalBlocks && (0, _react.createElement)(_noResults.default, null);
|
|
60
60
|
}
|
|
61
61
|
var _default = (0, _compose.compose)([(0, _data.withSelect)((select, {
|
|
62
|
-
filterValue
|
|
63
|
-
rootClientId = null
|
|
62
|
+
filterValue
|
|
64
63
|
}) => {
|
|
65
64
|
const {
|
|
66
65
|
getDownloadableBlocks,
|
|
67
|
-
isRequestingDownloadableBlocks
|
|
66
|
+
isRequestingDownloadableBlocks,
|
|
67
|
+
getInstalledBlockTypes
|
|
68
68
|
} = select(_store.store);
|
|
69
|
-
const {
|
|
70
|
-
canInsertBlockType
|
|
71
|
-
} = select(_blockEditor.store);
|
|
72
69
|
const hasPermission = select(_coreData.store).canUser('read', 'block-directory/search');
|
|
73
70
|
function getInstallableBlocks(term) {
|
|
74
71
|
const downloadableBlocks = getDownloadableBlocks(term);
|
|
75
|
-
const
|
|
72
|
+
const installedBlockTypes = getInstalledBlockTypes();
|
|
73
|
+
// Filter out blocks that are already installed.
|
|
74
|
+
const installableBlocks = downloadableBlocks.filter(block => {
|
|
75
|
+
// Check if the block has just been installed, in which case it
|
|
76
|
+
// should still show in the list to avoid suddenly disappearing.
|
|
77
|
+
// `installedBlockTypes` only returns blocks stored in state
|
|
78
|
+
// immediately after installation, not all installed blocks.
|
|
79
|
+
const isJustInstalled = !!installedBlockTypes.find(blockType => blockType.name === block.name);
|
|
80
|
+
const isPreviouslyInstalled = (0, _blocks.getBlockType)(block.name);
|
|
81
|
+
return isJustInstalled || !isPreviouslyInstalled;
|
|
82
|
+
});
|
|
76
83
|
if (downloadableBlocks.length === installableBlocks.length) {
|
|
77
84
|
return downloadableBlocks;
|
|
78
85
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_components","_compose","
|
|
1
|
+
{"version":3,"names":["_i18n","require","_components","_compose","_coreData","_data","_blocks","_downloadableBlocksList","_interopRequireDefault","_inserterPanel","_noResults","_store","EMPTY_ARRAY","DownloadableBlocksPanel","downloadableItems","onSelect","onHover","hasLocalBlocks","hasPermission","isLoading","isTyping","_react","createElement","Fragment","className","__","Spinner","default","length","items","_default","compose","withSelect","select","filterValue","getDownloadableBlocks","isRequestingDownloadableBlocks","getInstalledBlockTypes","blockDirectoryStore","coreStore","canUser","getInstallableBlocks","term","downloadableBlocks","installedBlockTypes","installableBlocks","filter","block","isJustInstalled","find","blockType","name","isPreviouslyInstalled","getBlockType","exports"],"sources":["@wordpress/block-directory/src/components/downloadable-blocks-panel/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Spinner } from '@wordpress/components';\nimport { compose } from '@wordpress/compose';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { withSelect } from '@wordpress/data';\nimport { getBlockType } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport DownloadableBlocksList from '../downloadable-blocks-list';\nimport DownloadableBlocksInserterPanel from './inserter-panel';\nimport DownloadableBlocksNoResults from './no-results';\nimport { store as blockDirectoryStore } from '../../store';\n\nconst EMPTY_ARRAY = [];\n\nfunction DownloadableBlocksPanel( {\n\tdownloadableItems,\n\tonSelect,\n\tonHover,\n\thasLocalBlocks,\n\thasPermission,\n\tisLoading,\n\tisTyping,\n} ) {\n\tif ( typeof hasPermission === 'undefined' || isLoading || isTyping ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ hasPermission && ! hasLocalBlocks && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<p className=\"block-directory-downloadable-blocks-panel__no-local\">\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'No results available from your installed blocks.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t<div className=\"block-editor-inserter__quick-inserter-separator\" />\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t\t<div className=\"block-directory-downloadable-blocks-panel has-blocks-loading\">\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t</>\n\t\t);\n\t}\n\n\tif ( false === hasPermission ) {\n\t\tif ( ! hasLocalBlocks ) {\n\t\t\treturn <DownloadableBlocksNoResults />;\n\t\t}\n\n\t\treturn null;\n\t}\n\n\treturn !! downloadableItems.length ? (\n\t\t<DownloadableBlocksInserterPanel\n\t\t\tdownloadableItems={ downloadableItems }\n\t\t\thasLocalBlocks={ hasLocalBlocks }\n\t\t>\n\t\t\t<DownloadableBlocksList\n\t\t\t\titems={ downloadableItems }\n\t\t\t\tonSelect={ onSelect }\n\t\t\t\tonHover={ onHover }\n\t\t\t/>\n\t\t</DownloadableBlocksInserterPanel>\n\t) : (\n\t\t! hasLocalBlocks && <DownloadableBlocksNoResults />\n\t);\n}\n\nexport default compose( [\n\twithSelect( ( select, { filterValue } ) => {\n\t\tconst {\n\t\t\tgetDownloadableBlocks,\n\t\t\tisRequestingDownloadableBlocks,\n\t\t\tgetInstalledBlockTypes,\n\t\t} = select( blockDirectoryStore );\n\n\t\tconst hasPermission = select( coreStore ).canUser(\n\t\t\t'read',\n\t\t\t'block-directory/search'\n\t\t);\n\n\t\tfunction getInstallableBlocks( term ) {\n\t\t\tconst downloadableBlocks = getDownloadableBlocks( term );\n\t\t\tconst installedBlockTypes = getInstalledBlockTypes();\n\t\t\t// Filter out blocks that are already installed.\n\t\t\tconst installableBlocks = downloadableBlocks.filter( ( block ) => {\n\t\t\t\t// Check if the block has just been installed, in which case it\n\t\t\t\t// should still show in the list to avoid suddenly disappearing.\n\t\t\t\t// `installedBlockTypes` only returns blocks stored in state\n\t\t\t\t// immediately after installation, not all installed blocks.\n\t\t\t\tconst isJustInstalled = !! installedBlockTypes.find(\n\t\t\t\t\t( blockType ) => blockType.name === block.name\n\t\t\t\t);\n\t\t\t\tconst isPreviouslyInstalled = getBlockType( block.name );\n\t\t\t\treturn isJustInstalled || ! isPreviouslyInstalled;\n\t\t\t} );\n\n\t\t\tif ( downloadableBlocks.length === installableBlocks.length ) {\n\t\t\t\treturn downloadableBlocks;\n\t\t\t}\n\t\t\treturn installableBlocks;\n\t\t}\n\n\t\tlet downloadableItems = hasPermission\n\t\t\t? getInstallableBlocks( filterValue )\n\t\t\t: [];\n\n\t\tif ( downloadableItems.length === 0 ) {\n\t\t\tdownloadableItems = EMPTY_ARRAY;\n\t\t}\n\n\t\tconst isLoading = isRequestingDownloadableBlocks( filterValue );\n\n\t\treturn {\n\t\t\tdownloadableItems,\n\t\t\thasPermission,\n\t\t\tisLoading,\n\t\t};\n\t} ),\n] )( DownloadableBlocksPanel );\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAKA,IAAAM,uBAAA,GAAAC,sBAAA,CAAAP,OAAA;AACA,IAAAQ,cAAA,GAAAD,sBAAA,CAAAP,OAAA;AACA,IAAAS,UAAA,GAAAF,sB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CAAC,EAAG;IACrCd,iBAAiB,GAAGF,WAAW;EAChC;EAEA,MAAMO,SAAS,GAAGiB,8BAA8B,CAAEF,WAAY,CAAC;EAE/D,OAAO;IACNpB,iBAAiB;IACjBI,aAAa;IACbC;EACD,CAAC;AACF,CAAE,CAAC,CACF,CAAC,CAAEN,uBAAwB,CAAC;AAAAyC,OAAA,CAAA3B,OAAA,GAAAG,QAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.unlock = exports.lock = void 0;
|
|
7
|
+
var _privateApis = require("@wordpress/private-apis");
|
|
8
|
+
/**
|
|
9
|
+
* WordPress dependencies
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
lock,
|
|
14
|
+
unlock
|
|
15
|
+
} = (0, _privateApis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', '@wordpress/block-directory');
|
|
16
|
+
exports.unlock = unlock;
|
|
17
|
+
exports.lock = lock;
|
|
18
|
+
//# sourceMappingURL=lock-unlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_privateApis","require","lock","unlock","__dangerousOptInToUnstableAPIsOnlyForCoreModules","exports"],"sources":["@wordpress/block-directory/src/lock-unlock.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.',\n\t\t'@wordpress/block-directory'\n\t);\n"],"mappings":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGO,MAAM;EAAEC,IAAI;EAAEC;AAAO,CAAC,GAC5B,IAAAC,6DAAgD,EAC/C,iHAAiH,EACjH,4BACD,CAAC;AAACC,OAAA,CAAAF,MAAA,GAAAA,MAAA;AAAAE,OAAA,CAAAH,IAAA,GAAAA,IAAA"}
|
|
@@ -3,7 +3,7 @@ import { createElement, Fragment } from "react";
|
|
|
3
3
|
* WordPress dependencies
|
|
4
4
|
*/
|
|
5
5
|
import { __, _n, sprintf } from '@wordpress/i18n';
|
|
6
|
-
import { Button, Spinner, VisuallyHidden,
|
|
6
|
+
import { Button, Spinner, VisuallyHidden, privateApis as componentsPrivateApis } from '@wordpress/components';
|
|
7
7
|
import { createInterpolateElement } from '@wordpress/element';
|
|
8
8
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
9
9
|
import { getBlockType } from '@wordpress/blocks';
|
|
@@ -16,6 +16,10 @@ import BlockRatings from '../block-ratings';
|
|
|
16
16
|
import DownloadableBlockIcon from '../downloadable-block-icon';
|
|
17
17
|
import DownloadableBlockNotice from '../downloadable-block-notice';
|
|
18
18
|
import { store as blockDirectoryStore } from '../../store';
|
|
19
|
+
import { unlock } from '../../lock-unlock';
|
|
20
|
+
const {
|
|
21
|
+
CompositeItemV2: CompositeItem
|
|
22
|
+
} = unlock(componentsPrivateApis);
|
|
19
23
|
|
|
20
24
|
// Return the appropriate block item label, given the block data and status.
|
|
21
25
|
function getDownloadableBlockLabel({
|
|
@@ -87,24 +91,26 @@ function DownloadableBlockListItem({
|
|
|
87
91
|
statusText = __('Installing…');
|
|
88
92
|
}
|
|
89
93
|
return createElement(CompositeItem, {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
event
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
94
|
+
render: createElement(Button, {
|
|
95
|
+
__experimentalIsFocusable: true,
|
|
96
|
+
type: "button",
|
|
97
|
+
role: "option",
|
|
98
|
+
className: "block-directory-downloadable-block-list-item",
|
|
99
|
+
isBusy: isInstalling,
|
|
100
|
+
onClick: event => {
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
onClick();
|
|
103
|
+
},
|
|
104
|
+
label: getDownloadableBlockLabel(item, {
|
|
105
|
+
hasNotice,
|
|
106
|
+
isInstalled,
|
|
107
|
+
isInstalling
|
|
108
|
+
}),
|
|
109
|
+
showTooltip: true,
|
|
110
|
+
tooltipPosition: "top center"
|
|
105
111
|
}),
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
store: composite,
|
|
113
|
+
disabled: isInstalling || !isInstallable
|
|
108
114
|
}, createElement("div", {
|
|
109
115
|
className: "block-directory-downloadable-block-list-item__icon"
|
|
110
116
|
}, createElement(DownloadableBlockIcon, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","_n","sprintf","Button","Spinner","VisuallyHidden","
|
|
1
|
+
{"version":3,"names":["__","_n","sprintf","Button","Spinner","VisuallyHidden","privateApis","componentsPrivateApis","createInterpolateElement","decodeEntities","getBlockType","useSelect","BlockRatings","DownloadableBlockIcon","DownloadableBlockNotice","store","blockDirectoryStore","unlock","CompositeItemV2","CompositeItem","getDownloadableBlockLabel","title","rating","ratingCount","hasNotice","isInstalled","isInstalling","stars","Math","round","DownloadableBlockListItem","composite","item","onClick","author","description","icon","name","isInstallable","select","getErrorNoticeForBlock","isBlockInstalling","notice","id","hasFatal","isFatal","statusText","createElement","render","__experimentalIsFocusable","type","role","className","isBusy","event","preventDefault","label","showTooltip","tooltipPosition","disabled","span","block","Fragment"],"sources":["@wordpress/block-directory/src/components/downloadable-block-list-item/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tSpinner,\n\tVisuallyHidden,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { createInterpolateElement } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { getBlockType } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport BlockRatings from '../block-ratings';\nimport DownloadableBlockIcon from '../downloadable-block-icon';\nimport DownloadableBlockNotice from '../downloadable-block-notice';\nimport { store as blockDirectoryStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { CompositeItemV2: CompositeItem } = unlock( componentsPrivateApis );\n\n// Return the appropriate block item label, given the block data and status.\nfunction getDownloadableBlockLabel(\n\t{ title, rating, ratingCount },\n\t{ hasNotice, isInstalled, isInstalling }\n) {\n\tconst stars = Math.round( rating / 0.5 ) * 0.5;\n\n\tif ( ! isInstalled && hasNotice ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Retry installing %s.', decodeEntities( title ) );\n\t}\n\n\tif ( isInstalled ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Add %s.', decodeEntities( title ) );\n\t}\n\n\tif ( isInstalling ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Installing %s.', decodeEntities( title ) );\n\t}\n\n\t// No ratings yet, just use the title.\n\tif ( ratingCount < 1 ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Install %s.', decodeEntities( title ) );\n\t}\n\n\treturn sprintf(\n\t\t/* translators: %1$s: block title, %2$s: average rating, %3$s: total ratings count. */\n\t\t_n(\n\t\t\t'Install %1$s. %2$s stars with %3$s review.',\n\t\t\t'Install %1$s. %2$s stars with %3$s reviews.',\n\t\t\tratingCount\n\t\t),\n\t\tdecodeEntities( title ),\n\t\tstars,\n\t\tratingCount\n\t);\n}\n\nfunction DownloadableBlockListItem( { composite, item, onClick } ) {\n\tconst { author, description, icon, rating, title } = item;\n\t// getBlockType returns a block object if this block exists, or null if not.\n\tconst isInstalled = !! getBlockType( item.name );\n\n\tconst { hasNotice, isInstalling, isInstallable } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getErrorNoticeForBlock, isInstalling: isBlockInstalling } =\n\t\t\t\tselect( blockDirectoryStore );\n\t\t\tconst notice = getErrorNoticeForBlock( item.id );\n\t\t\tconst hasFatal = notice && notice.isFatal;\n\t\t\treturn {\n\t\t\t\thasNotice: !! notice,\n\t\t\t\tisInstalling: isBlockInstalling( item.id ),\n\t\t\t\tisInstallable: ! hasFatal,\n\t\t\t};\n\t\t},\n\t\t[ item ]\n\t);\n\n\tlet statusText = '';\n\tif ( isInstalled ) {\n\t\tstatusText = __( 'Installed!' );\n\t} else if ( isInstalling ) {\n\t\tstatusText = __( 'Installing…' );\n\t}\n\n\treturn (\n\t\t<CompositeItem\n\t\t\trender={\n\t\t\t\t<Button\n\t\t\t\t\t__experimentalIsFocusable\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\trole=\"option\"\n\t\t\t\t\tclassName=\"block-directory-downloadable-block-list-item\"\n\t\t\t\t\tisBusy={ isInstalling }\n\t\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tonClick();\n\t\t\t\t\t} }\n\t\t\t\t\tlabel={ getDownloadableBlockLabel( item, {\n\t\t\t\t\t\thasNotice,\n\t\t\t\t\t\tisInstalled,\n\t\t\t\t\t\tisInstalling,\n\t\t\t\t\t} ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\ttooltipPosition=\"top center\"\n\t\t\t\t/>\n\t\t\t}\n\t\t\tstore={ composite }\n\t\t\tdisabled={ isInstalling || ! isInstallable }\n\t\t>\n\t\t\t<div className=\"block-directory-downloadable-block-list-item__icon\">\n\t\t\t\t<DownloadableBlockIcon icon={ icon } title={ title } />\n\t\t\t\t{ isInstalling ? (\n\t\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__spinner\">\n\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t</span>\n\t\t\t\t) : (\n\t\t\t\t\t<BlockRatings rating={ rating } />\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t<span className=\"block-directory-downloadable-block-list-item__details\">\n\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__title\">\n\t\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t/* translators: %1$s: block title, %2$s: author name. */\n\t\t\t\t\t\t\t__( '%1$s <span>by %2$s</span>' ),\n\t\t\t\t\t\t\tdecodeEntities( title ),\n\t\t\t\t\t\t\tauthor\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tspan: (\n\t\t\t\t\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__author\" />\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</span>\n\t\t\t\t{ hasNotice ? (\n\t\t\t\t\t<DownloadableBlockNotice block={ item } />\n\t\t\t\t) : (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__desc\">\n\t\t\t\t\t\t\t{ !! statusText\n\t\t\t\t\t\t\t\t? statusText\n\t\t\t\t\t\t\t\t: decodeEntities( description ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t{ isInstallable &&\n\t\t\t\t\t\t\t! ( isInstalled || isInstalling ) && (\n\t\t\t\t\t\t\t\t<VisuallyHidden>\n\t\t\t\t\t\t\t\t\t{ __( 'Install block' ) }\n\t\t\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</span>\n\t\t</CompositeItem>\n\t);\n}\n\nexport default DownloadableBlockListItem;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,EAAEC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AACjD,SACCC,MAAM,EACNC,OAAO,EACPC,cAAc,EACdC,WAAW,IAAIC,qBAAqB,QAC9B,uBAAuB;AAC9B,SAASC,wBAAwB,QAAQ,oBAAoB;AAC7D,SAASC,cAAc,QAAQ,0BAA0B;AACz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@ import { createElement } from "react";
|
|
|
3
3
|
* WordPress dependencies
|
|
4
4
|
*/
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
|
-
import {
|
|
6
|
+
import { privateApis as componentsPrivateApis } from '@wordpress/components';
|
|
7
7
|
import { getBlockType } from '@wordpress/blocks';
|
|
8
8
|
import { useDispatch } from '@wordpress/data';
|
|
9
9
|
|
|
@@ -12,13 +12,18 @@ import { useDispatch } from '@wordpress/data';
|
|
|
12
12
|
*/
|
|
13
13
|
import DownloadableBlockListItem from '../downloadable-block-list-item';
|
|
14
14
|
import { store as blockDirectoryStore } from '../../store';
|
|
15
|
+
import { unlock } from '../../lock-unlock';
|
|
16
|
+
const {
|
|
17
|
+
CompositeV2: Composite,
|
|
18
|
+
useCompositeStoreV2: useCompositeStore
|
|
19
|
+
} = unlock(componentsPrivateApis);
|
|
15
20
|
const noop = () => {};
|
|
16
21
|
function DownloadableBlocksList({
|
|
17
22
|
items,
|
|
18
23
|
onHover = noop,
|
|
19
24
|
onSelect
|
|
20
25
|
}) {
|
|
21
|
-
const composite =
|
|
26
|
+
const composite = useCompositeStore();
|
|
22
27
|
const {
|
|
23
28
|
installBlockType
|
|
24
29
|
} = useDispatch(blockDirectoryStore);
|
|
@@ -26,7 +31,7 @@ function DownloadableBlocksList({
|
|
|
26
31
|
return null;
|
|
27
32
|
}
|
|
28
33
|
return createElement(Composite, {
|
|
29
|
-
|
|
34
|
+
store: composite,
|
|
30
35
|
role: "listbox",
|
|
31
36
|
className: "block-directory-downloadable-blocks-list",
|
|
32
37
|
"aria-label": __('Blocks available for install')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","
|
|
1
|
+
{"version":3,"names":["__","privateApis","componentsPrivateApis","getBlockType","useDispatch","DownloadableBlockListItem","store","blockDirectoryStore","unlock","CompositeV2","Composite","useCompositeStoreV2","useCompositeStore","noop","DownloadableBlocksList","items","onHover","onSelect","composite","installBlockType","length","createElement","role","className","map","item","key","id","onClick","name","then","success"],"sources":["@wordpress/block-directory/src/components/downloadable-blocks-list/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { privateApis as componentsPrivateApis } from '@wordpress/components';\nimport { getBlockType } from '@wordpress/blocks';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport DownloadableBlockListItem from '../downloadable-block-list-item';\nimport { store as blockDirectoryStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { CompositeV2: Composite, useCompositeStoreV2: useCompositeStore } =\n\tunlock( componentsPrivateApis );\nconst noop = () => {};\n\nfunction DownloadableBlocksList( { items, onHover = noop, onSelect } ) {\n\tconst composite = useCompositeStore();\n\tconst { installBlockType } = useDispatch( blockDirectoryStore );\n\n\tif ( ! items.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Composite\n\t\t\tstore={ composite }\n\t\t\trole=\"listbox\"\n\t\t\tclassName=\"block-directory-downloadable-blocks-list\"\n\t\t\taria-label={ __( 'Blocks available for install' ) }\n\t\t>\n\t\t\t{ items.map( ( item ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<DownloadableBlockListItem\n\t\t\t\t\t\tkey={ item.id }\n\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t// Check if the block is registered (`getBlockType`\n\t\t\t\t\t\t\t// will return an object). If so, insert the block.\n\t\t\t\t\t\t\t// This prevents installing existing plugins.\n\t\t\t\t\t\t\tif ( getBlockType( item.name ) ) {\n\t\t\t\t\t\t\t\tonSelect( item );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tinstallBlockType( item ).then( ( success ) => {\n\t\t\t\t\t\t\t\t\tif ( success ) {\n\t\t\t\t\t\t\t\t\t\tonSelect( item );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonHover( null );\n\t\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ACf;QACA;QACA;QACA,IAAKzB,YAAY,CAAEsB,IAAI,CAACI,IAAK,CAAC,EAAG;UAChCZ,QAAQ,CAAEQ,IAAK,CAAC;QACjB,CAAC,MAAM;UACNN,gBAAgB,CAAEM,IAAK,CAAC,CAACK,IAAI,CAAIC,OAAO,IAAM;YAC7C,IAAKA,OAAO,EAAG;cACdd,QAAQ,CAAEQ,IAAK,CAAC;YACjB;UACD,CAAE,CAAC;QACJ;QACAT,OAAO,CAAE,IAAK,CAAC;MAChB,CAAG;MACHA,OAAO,EAAGA,OAAS;MACnBS,IAAI,EAAGA;IAAM,CACb,CAAC;EAEJ,CAAE,CACQ,CAAC;AAEd;AAEA,eAAeX,sBAAsB"}
|
|
@@ -5,9 +5,9 @@ import { createElement, Fragment } from "react";
|
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
6
|
import { Spinner } from '@wordpress/components';
|
|
7
7
|
import { compose } from '@wordpress/compose';
|
|
8
|
-
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
9
8
|
import { store as coreStore } from '@wordpress/core-data';
|
|
10
9
|
import { withSelect } from '@wordpress/data';
|
|
10
|
+
import { getBlockType } from '@wordpress/blocks';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Internal dependencies
|
|
@@ -51,20 +51,27 @@ function DownloadableBlocksPanel({
|
|
|
51
51
|
})) : !hasLocalBlocks && createElement(DownloadableBlocksNoResults, null);
|
|
52
52
|
}
|
|
53
53
|
export default compose([withSelect((select, {
|
|
54
|
-
filterValue
|
|
55
|
-
rootClientId = null
|
|
54
|
+
filterValue
|
|
56
55
|
}) => {
|
|
57
56
|
const {
|
|
58
57
|
getDownloadableBlocks,
|
|
59
|
-
isRequestingDownloadableBlocks
|
|
58
|
+
isRequestingDownloadableBlocks,
|
|
59
|
+
getInstalledBlockTypes
|
|
60
60
|
} = select(blockDirectoryStore);
|
|
61
|
-
const {
|
|
62
|
-
canInsertBlockType
|
|
63
|
-
} = select(blockEditorStore);
|
|
64
61
|
const hasPermission = select(coreStore).canUser('read', 'block-directory/search');
|
|
65
62
|
function getInstallableBlocks(term) {
|
|
66
63
|
const downloadableBlocks = getDownloadableBlocks(term);
|
|
67
|
-
const
|
|
64
|
+
const installedBlockTypes = getInstalledBlockTypes();
|
|
65
|
+
// Filter out blocks that are already installed.
|
|
66
|
+
const installableBlocks = downloadableBlocks.filter(block => {
|
|
67
|
+
// Check if the block has just been installed, in which case it
|
|
68
|
+
// should still show in the list to avoid suddenly disappearing.
|
|
69
|
+
// `installedBlockTypes` only returns blocks stored in state
|
|
70
|
+
// immediately after installation, not all installed blocks.
|
|
71
|
+
const isJustInstalled = !!installedBlockTypes.find(blockType => blockType.name === block.name);
|
|
72
|
+
const isPreviouslyInstalled = getBlockType(block.name);
|
|
73
|
+
return isJustInstalled || !isPreviouslyInstalled;
|
|
74
|
+
});
|
|
68
75
|
if (downloadableBlocks.length === installableBlocks.length) {
|
|
69
76
|
return downloadableBlocks;
|
|
70
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","Spinner","compose","store","
|
|
1
|
+
{"version":3,"names":["__","Spinner","compose","store","coreStore","withSelect","getBlockType","DownloadableBlocksList","DownloadableBlocksInserterPanel","DownloadableBlocksNoResults","blockDirectoryStore","EMPTY_ARRAY","DownloadableBlocksPanel","downloadableItems","onSelect","onHover","hasLocalBlocks","hasPermission","isLoading","isTyping","createElement","Fragment","className","length","items","select","filterValue","getDownloadableBlocks","isRequestingDownloadableBlocks","getInstalledBlockTypes","canUser","getInstallableBlocks","term","downloadableBlocks","installedBlockTypes","installableBlocks","filter","block","isJustInstalled","find","blockType","name","isPreviouslyInstalled"],"sources":["@wordpress/block-directory/src/components/downloadable-blocks-panel/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Spinner } from '@wordpress/components';\nimport { compose } from '@wordpress/compose';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { withSelect } from '@wordpress/data';\nimport { getBlockType } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport DownloadableBlocksList from '../downloadable-blocks-list';\nimport DownloadableBlocksInserterPanel from './inserter-panel';\nimport DownloadableBlocksNoResults from './no-results';\nimport { store as blockDirectoryStore } from '../../store';\n\nconst EMPTY_ARRAY = [];\n\nfunction DownloadableBlocksPanel( {\n\tdownloadableItems,\n\tonSelect,\n\tonHover,\n\thasLocalBlocks,\n\thasPermission,\n\tisLoading,\n\tisTyping,\n} ) {\n\tif ( typeof hasPermission === 'undefined' || isLoading || isTyping ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ hasPermission && ! hasLocalBlocks && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<p className=\"block-directory-downloadable-blocks-panel__no-local\">\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'No results available from your installed blocks.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t<div className=\"block-editor-inserter__quick-inserter-separator\" />\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t\t<div className=\"block-directory-downloadable-blocks-panel has-blocks-loading\">\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t</>\n\t\t);\n\t}\n\n\tif ( false === hasPermission ) {\n\t\tif ( ! hasLocalBlocks ) {\n\t\t\treturn <DownloadableBlocksNoResults />;\n\t\t}\n\n\t\treturn null;\n\t}\n\n\treturn !! downloadableItems.length ? (\n\t\t<DownloadableBlocksInserterPanel\n\t\t\tdownloadableItems={ downloadableItems }\n\t\t\thasLocalBlocks={ hasLocalBlocks }\n\t\t>\n\t\t\t<DownloadableBlocksList\n\t\t\t\titems={ downloadableItems }\n\t\t\t\tonSelect={ onSelect }\n\t\t\t\tonHover={ onHover }\n\t\t\t/>\n\t\t</DownloadableBlocksInserterPanel>\n\t) : (\n\t\t! hasLocalBlocks && <DownloadableBlocksNoResults />\n\t);\n}\n\nexport default compose( [\n\twithSelect( ( select, { filterValue } ) => {\n\t\tconst {\n\t\t\tgetDownloadableBlocks,\n\t\t\tisRequestingDownloadableBlocks,\n\t\t\tgetInstalledBlockTypes,\n\t\t} = select( blockDirectoryStore );\n\n\t\tconst hasPermission = select( coreStore ).canUser(\n\t\t\t'read',\n\t\t\t'block-directory/search'\n\t\t);\n\n\t\tfunction getInstallableBlocks( term ) {\n\t\t\tconst downloadableBlocks = getDownloadableBlocks( term );\n\t\t\tconst installedBlockTypes = getInstalledBlockTypes();\n\t\t\t// Filter out blocks that are already installed.\n\t\t\tconst installableBlocks = downloadableBlocks.filter( ( block ) => {\n\t\t\t\t// Check if the block has just been installed, in which case it\n\t\t\t\t// should still show in the list to avoid suddenly disappearing.\n\t\t\t\t// `installedBlockTypes` only returns blocks stored in state\n\t\t\t\t// immediately after installation, not all installed blocks.\n\t\t\t\tconst isJustInstalled = !! installedBlockTypes.find(\n\t\t\t\t\t( blockType ) => blockType.name === block.name\n\t\t\t\t);\n\t\t\t\tconst isPreviouslyInstalled = getBlockType( block.name );\n\t\t\t\treturn isJustInstalled || ! isPreviouslyInstalled;\n\t\t\t} );\n\n\t\t\tif ( downloadableBlocks.length === installableBlocks.length ) {\n\t\t\t\treturn downloadableBlocks;\n\t\t\t}\n\t\t\treturn installableBlocks;\n\t\t}\n\n\t\tlet downloadableItems = hasPermission\n\t\t\t? getInstallableBlocks( filterValue )\n\t\t\t: [];\n\n\t\tif ( downloadableItems.length === 0 ) {\n\t\t\tdownloadableItems = EMPTY_ARRAY;\n\t\t}\n\n\t\tconst isLoading = isRequestingDownloadableBlocks( filterValue );\n\n\t\treturn {\n\t\t\tdownloadableItems,\n\t\t\thasPermission,\n\t\t\tisLoading,\n\t\t};\n\t} ),\n] )( DownloadableBlocksPanel );\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,OAAO,QAAQ,uBAAuB;AAC/C,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SA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BI,aAAa;IACbC;EACD,CAAC;AACF,CAAE,CAAC,CACF,CAAC,CAAEN,uBAAwB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
|
|
5
|
+
export const {
|
|
6
|
+
lock,
|
|
7
|
+
unlock
|
|
8
|
+
} = __dangerousOptInToUnstableAPIsOnlyForCoreModules('I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', '@wordpress/block-directory');
|
|
9
|
+
//# sourceMappingURL=lock-unlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","lock","unlock"],"sources":["@wordpress/block-directory/src/lock-unlock.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.',\n\t\t'@wordpress/block-directory'\n\t);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gDAAgD,QAAQ,yBAAyB;AAE1F,OAAO,MAAM;EAAEC,IAAI;EAAEC;AAAO,CAAC,GAC5BF,gDAAgD,CAC/C,iHAAiH,EACjH,4BACD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-directory",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.21.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,24 +26,25 @@
|
|
|
26
26
|
"react-native": "src/index",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@babel/runtime": "^7.16.0",
|
|
29
|
-
"@wordpress/a11y": "^3.
|
|
30
|
-
"@wordpress/api-fetch": "^6.
|
|
31
|
-
"@wordpress/block-editor": "^12.
|
|
32
|
-
"@wordpress/blocks": "^12.
|
|
33
|
-
"@wordpress/components": "^25.
|
|
34
|
-
"@wordpress/compose": "^6.
|
|
35
|
-
"@wordpress/core-data": "^6.
|
|
36
|
-
"@wordpress/data": "^9.
|
|
37
|
-
"@wordpress/edit-post": "^7.
|
|
38
|
-
"@wordpress/editor": "^13.
|
|
39
|
-
"@wordpress/element": "^5.
|
|
40
|
-
"@wordpress/hooks": "^3.
|
|
41
|
-
"@wordpress/html-entities": "^3.
|
|
42
|
-
"@wordpress/i18n": "^4.
|
|
43
|
-
"@wordpress/icons": "^9.
|
|
44
|
-
"@wordpress/notices": "^4.
|
|
45
|
-
"@wordpress/plugins": "^6.
|
|
46
|
-
"@wordpress/
|
|
29
|
+
"@wordpress/a11y": "^3.44.0",
|
|
30
|
+
"@wordpress/api-fetch": "^6.41.0",
|
|
31
|
+
"@wordpress/block-editor": "^12.12.0",
|
|
32
|
+
"@wordpress/blocks": "^12.21.0",
|
|
33
|
+
"@wordpress/components": "^25.10.0",
|
|
34
|
+
"@wordpress/compose": "^6.21.0",
|
|
35
|
+
"@wordpress/core-data": "^6.21.0",
|
|
36
|
+
"@wordpress/data": "^9.14.0",
|
|
37
|
+
"@wordpress/edit-post": "^7.21.0",
|
|
38
|
+
"@wordpress/editor": "^13.21.0",
|
|
39
|
+
"@wordpress/element": "^5.21.0",
|
|
40
|
+
"@wordpress/hooks": "^3.44.0",
|
|
41
|
+
"@wordpress/html-entities": "^3.44.0",
|
|
42
|
+
"@wordpress/i18n": "^4.44.0",
|
|
43
|
+
"@wordpress/icons": "^9.35.0",
|
|
44
|
+
"@wordpress/notices": "^4.12.0",
|
|
45
|
+
"@wordpress/plugins": "^6.12.0",
|
|
46
|
+
"@wordpress/private-apis": "^0.26.0",
|
|
47
|
+
"@wordpress/url": "^3.45.0",
|
|
47
48
|
"change-case": "^4.1.2"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
@@ -53,5 +54,5 @@
|
|
|
53
54
|
"publishConfig": {
|
|
54
55
|
"access": "public"
|
|
55
56
|
},
|
|
56
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "f83bb1a71e8fa416131b81a9f282a72a1dc6c694"
|
|
57
58
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
Button,
|
|
7
7
|
Spinner,
|
|
8
8
|
VisuallyHidden,
|
|
9
|
-
|
|
9
|
+
privateApis as componentsPrivateApis,
|
|
10
10
|
} from '@wordpress/components';
|
|
11
11
|
import { createInterpolateElement } from '@wordpress/element';
|
|
12
12
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
@@ -20,6 +20,9 @@ import BlockRatings from '../block-ratings';
|
|
|
20
20
|
import DownloadableBlockIcon from '../downloadable-block-icon';
|
|
21
21
|
import DownloadableBlockNotice from '../downloadable-block-notice';
|
|
22
22
|
import { store as blockDirectoryStore } from '../../store';
|
|
23
|
+
import { unlock } from '../../lock-unlock';
|
|
24
|
+
|
|
25
|
+
const { CompositeItemV2: CompositeItem } = unlock( componentsPrivateApis );
|
|
23
26
|
|
|
24
27
|
// Return the appropriate block item label, given the block data and status.
|
|
25
28
|
function getDownloadableBlockLabel(
|
|
@@ -91,24 +94,28 @@ function DownloadableBlockListItem( { composite, item, onClick } ) {
|
|
|
91
94
|
|
|
92
95
|
return (
|
|
93
96
|
<CompositeItem
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
97
|
+
render={
|
|
98
|
+
<Button
|
|
99
|
+
__experimentalIsFocusable
|
|
100
|
+
type="button"
|
|
101
|
+
role="option"
|
|
102
|
+
className="block-directory-downloadable-block-list-item"
|
|
103
|
+
isBusy={ isInstalling }
|
|
104
|
+
onClick={ ( event ) => {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
onClick();
|
|
107
|
+
} }
|
|
108
|
+
label={ getDownloadableBlockLabel( item, {
|
|
109
|
+
hasNotice,
|
|
110
|
+
isInstalled,
|
|
111
|
+
isInstalling,
|
|
112
|
+
} ) }
|
|
113
|
+
showTooltip
|
|
114
|
+
tooltipPosition="top center"
|
|
115
|
+
/>
|
|
116
|
+
}
|
|
117
|
+
store={ composite }
|
|
104
118
|
disabled={ isInstalling || ! isInstallable }
|
|
105
|
-
label={ getDownloadableBlockLabel( item, {
|
|
106
|
-
hasNotice,
|
|
107
|
-
isInstalled,
|
|
108
|
-
isInstalling,
|
|
109
|
-
} ) }
|
|
110
|
-
showTooltip={ true }
|
|
111
|
-
tooltipPosition="top center"
|
|
112
119
|
>
|
|
113
120
|
<div className="block-directory-downloadable-block-list-item__icon">
|
|
114
121
|
<DownloadableBlockIcon icon={ icon } title={ title } />
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
|
-
import {
|
|
6
|
-
__unstableComposite as Composite,
|
|
7
|
-
__unstableUseCompositeState as useCompositeState,
|
|
8
|
-
} from '@wordpress/components';
|
|
5
|
+
import { privateApis as componentsPrivateApis } from '@wordpress/components';
|
|
9
6
|
import { getBlockType } from '@wordpress/blocks';
|
|
10
7
|
import { useDispatch } from '@wordpress/data';
|
|
11
8
|
|
|
@@ -14,11 +11,14 @@ import { useDispatch } from '@wordpress/data';
|
|
|
14
11
|
*/
|
|
15
12
|
import DownloadableBlockListItem from '../downloadable-block-list-item';
|
|
16
13
|
import { store as blockDirectoryStore } from '../../store';
|
|
14
|
+
import { unlock } from '../../lock-unlock';
|
|
17
15
|
|
|
16
|
+
const { CompositeV2: Composite, useCompositeStoreV2: useCompositeStore } =
|
|
17
|
+
unlock( componentsPrivateApis );
|
|
18
18
|
const noop = () => {};
|
|
19
19
|
|
|
20
20
|
function DownloadableBlocksList( { items, onHover = noop, onSelect } ) {
|
|
21
|
-
const composite =
|
|
21
|
+
const composite = useCompositeStore();
|
|
22
22
|
const { installBlockType } = useDispatch( blockDirectoryStore );
|
|
23
23
|
|
|
24
24
|
if ( ! items.length ) {
|
|
@@ -27,7 +27,7 @@ function DownloadableBlocksList( { items, onHover = noop, onSelect } ) {
|
|
|
27
27
|
|
|
28
28
|
return (
|
|
29
29
|
<Composite
|
|
30
|
-
{
|
|
30
|
+
store={ composite }
|
|
31
31
|
role="listbox"
|
|
32
32
|
className="block-directory-downloadable-blocks-list"
|
|
33
33
|
aria-label={ __( 'Blocks available for install' ) }
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import { Spinner } from '@wordpress/components';
|
|
6
6
|
import { compose } from '@wordpress/compose';
|
|
7
|
-
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
8
7
|
import { store as coreStore } from '@wordpress/core-data';
|
|
9
8
|
import { withSelect } from '@wordpress/data';
|
|
9
|
+
import { getBlockType } from '@wordpress/blocks';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Internal dependencies
|
|
@@ -72,10 +72,12 @@ function DownloadableBlocksPanel( {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export default compose( [
|
|
75
|
-
withSelect( ( select, { filterValue
|
|
76
|
-
const {
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
withSelect( ( select, { filterValue } ) => {
|
|
76
|
+
const {
|
|
77
|
+
getDownloadableBlocks,
|
|
78
|
+
isRequestingDownloadableBlocks,
|
|
79
|
+
getInstalledBlockTypes,
|
|
80
|
+
} = select( blockDirectoryStore );
|
|
79
81
|
|
|
80
82
|
const hasPermission = select( coreStore ).canUser(
|
|
81
83
|
'read',
|
|
@@ -84,9 +86,19 @@ export default compose( [
|
|
|
84
86
|
|
|
85
87
|
function getInstallableBlocks( term ) {
|
|
86
88
|
const downloadableBlocks = getDownloadableBlocks( term );
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
)
|
|
89
|
+
const installedBlockTypes = getInstalledBlockTypes();
|
|
90
|
+
// Filter out blocks that are already installed.
|
|
91
|
+
const installableBlocks = downloadableBlocks.filter( ( block ) => {
|
|
92
|
+
// Check if the block has just been installed, in which case it
|
|
93
|
+
// should still show in the list to avoid suddenly disappearing.
|
|
94
|
+
// `installedBlockTypes` only returns blocks stored in state
|
|
95
|
+
// immediately after installation, not all installed blocks.
|
|
96
|
+
const isJustInstalled = !! installedBlockTypes.find(
|
|
97
|
+
( blockType ) => blockType.name === block.name
|
|
98
|
+
);
|
|
99
|
+
const isPreviouslyInstalled = getBlockType( block.name );
|
|
100
|
+
return isJustInstalled || ! isPreviouslyInstalled;
|
|
101
|
+
} );
|
|
90
102
|
|
|
91
103
|
if ( downloadableBlocks.length === installableBlocks.length ) {
|
|
92
104
|
return downloadableBlocks;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
|
|
5
|
+
|
|
6
|
+
export const { lock, unlock } =
|
|
7
|
+
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
|
|
8
|
+
'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.',
|
|
9
|
+
'@wordpress/block-directory'
|
|
10
|
+
);
|