@wordpress/block-directory 6.0.0 → 6.2.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.
Files changed (106) hide show
  1. package/build/components/auto-block-uninstaller/index.cjs +26 -47
  2. package/build/components/auto-block-uninstaller/index.cjs.map +1 -7
  3. package/build/components/block-ratings/index.cjs +28 -34
  4. package/build/components/block-ratings/index.cjs.map +1 -7
  5. package/build/components/block-ratings/stars.cjs +35 -71
  6. package/build/components/block-ratings/stars.cjs.map +1 -7
  7. package/build/components/compact-list/index.cjs +45 -43
  8. package/build/components/compact-list/index.cjs.map +1 -7
  9. package/build/components/downloadable-block-icon/index.cjs +20 -29
  10. package/build/components/downloadable-block-icon/index.cjs.map +1 -7
  11. package/build/components/downloadable-block-list-item/index.cjs +95 -161
  12. package/build/components/downloadable-block-list-item/index.cjs.map +1 -7
  13. package/build/components/downloadable-block-notice/index.cjs +22 -46
  14. package/build/components/downloadable-block-notice/index.cjs.map +1 -7
  15. package/build/components/downloadable-blocks-list/index.cjs +50 -70
  16. package/build/components/downloadable-blocks-list/index.cjs.map +1 -7
  17. package/build/components/downloadable-blocks-panel/index.cjs +79 -119
  18. package/build/components/downloadable-blocks-panel/index.cjs.map +1 -7
  19. package/build/components/downloadable-blocks-panel/inserter-panel.cjs +37 -61
  20. package/build/components/downloadable-blocks-panel/inserter-panel.cjs.map +1 -7
  21. package/build/components/downloadable-blocks-panel/no-results.cjs +27 -46
  22. package/build/components/downloadable-blocks-panel/no-results.cjs.map +1 -7
  23. package/build/index.cjs +11 -29
  24. package/build/plugins/get-install-missing/index.cjs +80 -122
  25. package/build/plugins/get-install-missing/index.cjs.map +1 -7
  26. package/build/plugins/get-install-missing/install-button.cjs +33 -70
  27. package/build/plugins/get-install-missing/install-button.cjs.map +1 -7
  28. package/build/plugins/index.cjs +45 -45
  29. package/build/plugins/index.cjs.map +1 -7
  30. package/build/plugins/inserter-menu-downloadable-blocks-panel/index.cjs +40 -52
  31. package/build/plugins/inserter-menu-downloadable-blocks-panel/index.cjs.map +1 -7
  32. package/build/plugins/installed-blocks-pre-publish-panel/index.cjs +38 -62
  33. package/build/plugins/installed-blocks-pre-publish-panel/index.cjs.map +1 -7
  34. package/build/store/actions.cjs +233 -205
  35. package/build/store/actions.cjs.map +1 -7
  36. package/build/store/index.cjs +56 -45
  37. package/build/store/index.cjs.map +1 -7
  38. package/build/store/load-assets.cjs +62 -63
  39. package/build/store/load-assets.cjs.map +1 -7
  40. package/build/store/reducer.cjs +90 -101
  41. package/build/store/reducer.cjs.map +1 -7
  42. package/build/store/resolvers.cjs +34 -54
  43. package/build/store/resolvers.cjs.map +1 -7
  44. package/build/store/selectors.cjs +111 -107
  45. package/build/store/selectors.cjs.map +1 -7
  46. package/build/store/utils/get-plugin-url.cjs +19 -32
  47. package/build/store/utils/get-plugin-url.cjs.map +1 -7
  48. package/build-module/components/auto-block-uninstaller/index.mjs +19 -25
  49. package/build-module/components/auto-block-uninstaller/index.mjs.map +1 -7
  50. package/build-module/components/block-ratings/index.mjs +8 -8
  51. package/build-module/components/block-ratings/index.mjs.map +1 -7
  52. package/build-module/components/block-ratings/stars.mjs +28 -49
  53. package/build-module/components/block-ratings/stars.mjs.map +1 -7
  54. package/build-module/components/compact-list/index.mjs +24 -19
  55. package/build-module/components/compact-list/index.mjs.map +1 -7
  56. package/build-module/components/downloadable-block-icon/index.mjs +14 -8
  57. package/build-module/components/downloadable-block-icon/index.mjs.map +1 -7
  58. package/build-module/components/downloadable-block-list-item/index.mjs +64 -130
  59. package/build-module/components/downloadable-block-list-item/index.mjs.map +1 -7
  60. package/build-module/components/downloadable-block-notice/index.mjs +16 -22
  61. package/build-module/components/downloadable-block-notice/index.mjs.map +1 -7
  62. package/build-module/components/downloadable-blocks-list/index.mjs +26 -43
  63. package/build-module/components/downloadable-blocks-list/index.mjs.map +1 -7
  64. package/build-module/components/downloadable-blocks-panel/index.mjs +52 -91
  65. package/build-module/components/downloadable-blocks-panel/index.mjs.map +1 -7
  66. package/build-module/components/downloadable-blocks-panel/inserter-panel.mjs +29 -38
  67. package/build-module/components/downloadable-blocks-panel/inserter-panel.mjs.map +1 -7
  68. package/build-module/components/downloadable-blocks-panel/no-results.mjs +19 -23
  69. package/build-module/components/downloadable-blocks-panel/no-results.mjs.map +1 -7
  70. package/build-module/index.mjs +1 -6
  71. package/build-module/plugins/get-install-missing/index.mjs +55 -98
  72. package/build-module/plugins/get-install-missing/index.mjs.map +1 -7
  73. package/build-module/plugins/get-install-missing/install-button.mjs +25 -47
  74. package/build-module/plugins/get-install-missing/install-button.mjs.map +1 -7
  75. package/build-module/plugins/index.mjs +16 -23
  76. package/build-module/plugins/index.mjs.map +1 -7
  77. package/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.mjs +17 -26
  78. package/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.mjs.map +1 -7
  79. package/build-module/plugins/installed-blocks-pre-publish-panel/index.mjs +15 -36
  80. package/build-module/plugins/installed-blocks-pre-publish-panel/index.mjs.map +1 -7
  81. package/build-module/store/actions.mjs +201 -170
  82. package/build-module/store/actions.mjs.map +1 -7
  83. package/build-module/store/index.mjs +28 -13
  84. package/build-module/store/index.mjs.map +1 -7
  85. package/build-module/store/load-assets.mjs +42 -36
  86. package/build-module/store/load-assets.mjs.map +1 -7
  87. package/build-module/store/reducer.mjs +81 -74
  88. package/build-module/store/reducer.mjs.map +1 -7
  89. package/build-module/store/resolvers.mjs +13 -26
  90. package/build-module/store/resolvers.mjs.map +1 -7
  91. package/build-module/store/selectors.mjs +99 -76
  92. package/build-module/store/selectors.mjs.map +1 -7
  93. package/build-module/store/utils/get-plugin-url.mjs +14 -12
  94. package/build-module/store/utils/get-plugin-url.mjs.map +1 -7
  95. package/build-style/style-rtl.css +6 -12
  96. package/build-style/style.css +6 -12
  97. package/package.json +22 -23
  98. package/src/components/downloadable-block-list-item/style.scss +6 -6
  99. package/src/components/downloadable-block-notice/index.jsx +0 -4
  100. package/build/index.cjs.map +0 -7
  101. package/build/lock-unlock.cjs +0 -36
  102. package/build/lock-unlock.cjs.map +0 -7
  103. package/build-module/index.mjs.map +0 -7
  104. package/build-module/lock-unlock.mjs +0 -11
  105. package/build-module/lock-unlock.mjs.map +0 -7
  106. package/src/lock-unlock.js +0 -7
@@ -1,73 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ // \0rolldown/runtime.js
1
7
  var __create = Object.create;
2
8
  var __defProp = Object.defineProperty;
3
9
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
10
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
11
  var __getProtoOf = Object.getPrototypeOf;
6
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
13
  var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
+ key = keys[i];
16
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: ((k) => from[k]).bind(null, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
18
22
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+ let _wordpress_i18n = require("@wordpress/i18n");
28
+ let _wordpress_data = require("@wordpress/data");
29
+ let _wordpress_editor = require("@wordpress/editor");
30
+ let ______components_compact_list_index_jsx = require("../../components/compact-list/index.cjs");
31
+ ______components_compact_list_index_jsx = __toESM(______components_compact_list_index_jsx);
32
+ let ______store_index_js = require("../../store/index.cjs");
33
+ let react_jsx_runtime = require("react/jsx-runtime");
29
34
  // packages/block-directory/src/plugins/installed-blocks-pre-publish-panel/index.jsx
30
- var installed_blocks_pre_publish_panel_exports = {};
31
- __export(installed_blocks_pre_publish_panel_exports, {
32
- default: () => InstalledBlocksPrePublishPanel
33
- });
34
- module.exports = __toCommonJS(installed_blocks_pre_publish_panel_exports);
35
- var import_i18n = require("@wordpress/i18n");
36
- var import_data = require("@wordpress/data");
37
- var import_editor = require("@wordpress/editor");
38
- var import_compact_list = __toESM(require("../../components/compact-list/index.cjs"));
39
- var import_store = require("../../store/index.cjs");
40
- var import_jsx_runtime = require("react/jsx-runtime");
41
35
  function InstalledBlocksPrePublishPanel() {
42
- const newBlockTypes = (0, import_data.useSelect)(
43
- (select) => select(import_store.store).getNewBlockTypes(),
44
- []
45
- );
46
- if (!newBlockTypes.length) {
47
- return null;
48
- }
49
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
50
- import_editor.PluginPrePublishPanel,
51
- {
52
- title: (0, import_i18n.sprintf)(
53
- // translators: %d: number of blocks (number).
54
- (0, import_i18n._n)(
55
- "Added: %d block",
56
- "Added: %d blocks",
57
- newBlockTypes.length
58
- ),
59
- newBlockTypes.length
60
- ),
61
- initialOpen: true,
62
- children: [
63
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "installed-blocks-pre-publish-panel__copy", children: (0, import_i18n._n)(
64
- "The following block has been added to your site.",
65
- "The following blocks have been added to your site.",
66
- newBlockTypes.length
67
- ) }),
68
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_compact_list.default, { items: newBlockTypes })
69
- ]
70
- }
71
- );
36
+ const newBlockTypes = (0, _wordpress_data.useSelect)((select) => select(______store_index_js.store).getNewBlockTypes(), []);
37
+ if (!newBlockTypes.length) return null;
38
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_editor.PluginPrePublishPanel, {
39
+ title: (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n._n)("Added: %d block", "Added: %d blocks", newBlockTypes.length), newBlockTypes.length),
40
+ initialOpen: true,
41
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
42
+ className: "installed-blocks-pre-publish-panel__copy",
43
+ children: (0, _wordpress_i18n._n)("The following block has been added to your site.", "The following blocks have been added to your site.", newBlockTypes.length)
44
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(______components_compact_list_index_jsx.default, { items: newBlockTypes })]
45
+ });
72
46
  }
73
- //# sourceMappingURL=index.cjs.map
47
+ exports.default = InstalledBlocksPrePublishPanel;
48
+
49
+ //# sourceMappingURL=index.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/plugins/installed-blocks-pre-publish-panel/index.jsx"],
4
- "sourcesContent": ["import { _n, sprintf } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { PluginPrePublishPanel } from '@wordpress/editor';\nimport CompactList from '../../components/compact-list';\nimport { store as blockDirectoryStore } from '../../store';\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\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\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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA4B;AAC5B,kBAA0B;AAC1B,oBAAsC;AACtC,0BAAwB;AACxB,mBAA6C;AAa3C;AAXa,SAAR,iCAAkD;AACxD,QAAM,oBAAgB;AAAA,IACrB,CAAE,WAAY,OAAQ,aAAAA,KAAoB,EAAE,iBAAiB;AAAA,IAC7D,CAAC;AAAA,EACF;AAEA,MAAK,CAAE,cAAc,QAAS;AAC7B,WAAO;AAAA,EACR;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAQ;AAAA;AAAA,YAEP;AAAA,UACC;AAAA,UACA;AAAA,UACA,cAAc;AAAA,QACf;AAAA,QACA,cAAc;AAAA,MACf;AAAA,MACA,aAAW;AAAA,MAEX;AAAA,oDAAC,OAAE,WAAU,4CACV;AAAA,UACD;AAAA,UACA;AAAA,UACA,cAAc;AAAA,QACf,GACD;AAAA,QACA,4CAAC,oBAAAC,SAAA,EAAY,OAAQ,eAAgB;AAAA;AAAA;AAAA,EACtC;AAEF;",
6
- "names": ["blockDirectoryStore", "CompactList"]
7
- }
1
+ {"version":3,"file":"index.cjs","names":["useSelect","blockDirectoryStore","PluginPrePublishPanel","sprintf","_n","CompactList"],"sources":["../../../src/plugins/installed-blocks-pre-publish-panel/index.jsx"],"sourcesContent":["import { _n, sprintf } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { PluginPrePublishPanel } from '@wordpress/editor';\nimport CompactList from '../../components/compact-list';\nimport { store as blockDirectoryStore } from '../../store';\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\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\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,SAAwB,iCAAiC;CACxD,MAAM,iBAAA,GAAgBA,gBAAAA,UAAAA,EACnB,WAAY,OAAQC,qBAAAA,KAAoB,CAAC,CAAC,iBAAiB,GAC7D,CAAC,CACF;CAEA,IAAK,CAAE,cAAc,QACpB,OAAO;CAGR,OACC,iBAAA,GAAA,kBAAA,KAAA,CAACC,kBAAAA,uBAAD;EACC,QAAA,GAAQC,gBAAAA,QAAAA,EAAAA,GAEPC,gBAAAA,GAAAA,CACC,mBACA,oBACA,cAAc,MACf,GACA,cAAc,MACf;EACA,aAAA;EAVD,UAAA,CAYC,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;GAAG,WAAU;GACVA,WAAAA,GAAAA,gBAAAA,GAAAA,CACD,oDACA,sDACA,cAAc,MACf;EACE,CAAA,GACH,iBAAA,GAAA,kBAAA,IAAA,CAACC,wCAAAA,SAAD,EAAa,OAAQ,cAAiB,CAAA,CAChB;;AAEzB"}
@@ -1,230 +1,258 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ // \0rolldown/runtime.js
1
7
  var __create = Object.create;
2
8
  var __defProp = Object.defineProperty;
3
9
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
10
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
11
  var __getProtoOf = Object.getPrototypeOf;
6
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
13
  var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
+ key = keys[i];
16
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: ((k) => from[k]).bind(null, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
18
22
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+ let _wordpress_blocks = require("@wordpress/blocks");
28
+ let _wordpress_i18n = require("@wordpress/i18n");
29
+ let _wordpress_api_fetch = require("@wordpress/api-fetch");
30
+ _wordpress_api_fetch = __toESM(_wordpress_api_fetch);
31
+ let _wordpress_notices = require("@wordpress/notices");
32
+ let _wordpress_url = require("@wordpress/url");
33
+ let __load_assets_js = require("./load-assets.cjs");
34
+ let __utils_get_plugin_url_js = require("./utils/get-plugin-url.cjs");
35
+ __utils_get_plugin_url_js = __toESM(__utils_get_plugin_url_js);
29
36
  // packages/block-directory/src/store/actions.js
30
- var actions_exports = {};
31
- __export(actions_exports, {
32
- addInstalledBlockType: () => addInstalledBlockType,
33
- clearErrorNotice: () => clearErrorNotice,
34
- fetchDownloadableBlocks: () => fetchDownloadableBlocks,
35
- installBlockType: () => installBlockType,
36
- receiveDownloadableBlocks: () => receiveDownloadableBlocks,
37
- removeInstalledBlockType: () => removeInstalledBlockType,
38
- setErrorNotice: () => setErrorNotice,
39
- setIsInstalling: () => setIsInstalling,
40
- uninstallBlockType: () => uninstallBlockType
41
- });
42
- module.exports = __toCommonJS(actions_exports);
43
- var import_blocks = require("@wordpress/blocks");
44
- var import_i18n = require("@wordpress/i18n");
45
- var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
46
- var import_notices = require("@wordpress/notices");
47
- var import_url = require("@wordpress/url");
48
- var import_load_assets = require("./load-assets.cjs");
49
- var import_get_plugin_url = __toESM(require("./utils/get-plugin-url.cjs"));
37
+ /**
38
+ * Returns an action object used in signalling that the downloadable blocks
39
+ * have been requested and are loading.
40
+ *
41
+ * @param {string} filterValue Search string.
42
+ *
43
+ * @return {Object} Action object.
44
+ */
50
45
  function fetchDownloadableBlocks(filterValue) {
51
- return { type: "FETCH_DOWNLOADABLE_BLOCKS", filterValue };
46
+ return {
47
+ type: "FETCH_DOWNLOADABLE_BLOCKS",
48
+ filterValue
49
+ };
52
50
  }
51
+ /**
52
+ * Returns an action object used in signalling that the downloadable blocks
53
+ * have been updated.
54
+ *
55
+ * @param {Array} downloadableBlocks Downloadable blocks.
56
+ * @param {string} filterValue Search string.
57
+ *
58
+ * @return {Object} Action object.
59
+ */
53
60
  function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
54
- return {
55
- type: "RECEIVE_DOWNLOADABLE_BLOCKS",
56
- downloadableBlocks,
57
- filterValue
58
- };
61
+ return {
62
+ type: "RECEIVE_DOWNLOADABLE_BLOCKS",
63
+ downloadableBlocks,
64
+ filterValue
65
+ };
59
66
  }
60
- var installBlockType = (block) => async ({ registry, dispatch }) => {
61
- const { id, name } = block;
62
- let success = false;
63
- dispatch.clearErrorNotice(id);
64
- try {
65
- dispatch.setIsInstalling(id, true);
66
- const url = (0, import_get_plugin_url.default)(block);
67
- let links = {};
68
- if (url) {
69
- await (0, import_api_fetch.default)({
70
- method: "PUT",
71
- url,
72
- data: { status: "active" }
73
- });
74
- } else {
75
- const response = await (0, import_api_fetch.default)({
76
- method: "POST",
77
- path: "wp/v2/plugins",
78
- data: { slug: id, status: "active" }
79
- });
80
- links = response._links;
81
- }
82
- dispatch.addInstalledBlockType({
83
- ...block,
84
- links: { ...block.links, ...links }
85
- });
86
- const metadataFields = [
87
- "api_version",
88
- "title",
89
- "category",
90
- "parent",
91
- "ancestor",
92
- "icon",
93
- "description",
94
- "keywords",
95
- "attributes",
96
- "provides_context",
97
- "uses_context",
98
- "selectors",
99
- "supports",
100
- "styles",
101
- "example",
102
- "variations",
103
- "allowed_blocks",
104
- "block_hooks"
105
- ];
106
- await (0, import_api_fetch.default)({
107
- path: (0, import_url.addQueryArgs)(`/wp/v2/block-types/${name}`, {
108
- _fields: metadataFields
109
- })
110
- }).catch(() => {
111
- }).then((response) => {
112
- if (!response) {
113
- return;
114
- }
115
- (0, import_blocks.unstable__bootstrapServerSideBlockDefinitions)({
116
- [name]: Object.fromEntries(
117
- Object.entries(response).filter(
118
- ([key]) => metadataFields.includes(key)
119
- )
120
- )
121
- });
122
- });
123
- await (0, import_load_assets.loadAssets)();
124
- const registeredBlocks = registry.select(import_blocks.store).getBlockTypes();
125
- if (!registeredBlocks.some((i) => i.name === name)) {
126
- throw new Error(
127
- (0, import_i18n.__)("Error registering block. Try reloading the page.")
128
- );
129
- }
130
- registry.dispatch(import_notices.store).createInfoNotice(
131
- (0, import_i18n.sprintf)(
132
- // translators: %s is the block title.
133
- (0, import_i18n.__)("Block %s installed and added."),
134
- block.title
135
- ),
136
- {
137
- speak: true,
138
- type: "snackbar"
139
- }
140
- );
141
- success = true;
142
- } catch (error) {
143
- let message = error.message || (0, import_i18n.__)("An error occurred.");
144
- let isFatal = error instanceof Error;
145
- const fatalAPIErrors = {
146
- folder_exists: (0, import_i18n.__)(
147
- "This block is already installed. Try reloading the page."
148
- ),
149
- unable_to_connect_to_filesystem: (0, import_i18n.__)(
150
- "Error installing block. You can reload the page and try again."
151
- )
152
- };
153
- if (fatalAPIErrors[error.code]) {
154
- isFatal = true;
155
- message = fatalAPIErrors[error.code];
156
- }
157
- dispatch.setErrorNotice(id, message, isFatal);
158
- registry.dispatch(import_notices.store).createErrorNotice(message, {
159
- speak: true,
160
- isDismissible: true
161
- });
162
- }
163
- dispatch.setIsInstalling(id, false);
164
- return success;
67
+ /**
68
+ * Action triggered to install a block plugin.
69
+ *
70
+ * @param {Object} block The block item returned by search.
71
+ *
72
+ * @return {boolean} Whether the block was successfully installed & loaded.
73
+ */
74
+ const installBlockType = (block) => async ({ registry, dispatch }) => {
75
+ const { id, name } = block;
76
+ let success = false;
77
+ dispatch.clearErrorNotice(id);
78
+ try {
79
+ dispatch.setIsInstalling(id, true);
80
+ const url = (0, __utils_get_plugin_url_js.default)(block);
81
+ let links = {};
82
+ if (url) await (0, _wordpress_api_fetch.default)({
83
+ method: "PUT",
84
+ url,
85
+ data: { status: "active" }
86
+ });
87
+ else links = (await (0, _wordpress_api_fetch.default)({
88
+ method: "POST",
89
+ path: "wp/v2/plugins",
90
+ data: {
91
+ slug: id,
92
+ status: "active"
93
+ }
94
+ }))._links;
95
+ dispatch.addInstalledBlockType({
96
+ ...block,
97
+ links: {
98
+ ...block.links,
99
+ ...links
100
+ }
101
+ });
102
+ const metadataFields = [
103
+ "api_version",
104
+ "title",
105
+ "category",
106
+ "parent",
107
+ "ancestor",
108
+ "icon",
109
+ "description",
110
+ "keywords",
111
+ "attributes",
112
+ "provides_context",
113
+ "uses_context",
114
+ "selectors",
115
+ "supports",
116
+ "styles",
117
+ "example",
118
+ "variations",
119
+ "allowed_blocks",
120
+ "block_hooks"
121
+ ];
122
+ await (0, _wordpress_api_fetch.default)({ path: (0, _wordpress_url.addQueryArgs)(`/wp/v2/block-types/${name}`, { _fields: metadataFields }) }).catch(() => {}).then((response) => {
123
+ if (!response) return;
124
+ (0, _wordpress_blocks.unstable__bootstrapServerSideBlockDefinitions)({ [name]: Object.fromEntries(Object.entries(response).filter(([key]) => metadataFields.includes(key))) });
125
+ });
126
+ await (0, __load_assets_js.loadAssets)();
127
+ if (!registry.select(_wordpress_blocks.store).getBlockTypes().some((i) => i.name === name)) throw new Error((0, _wordpress_i18n.__)("Error registering block. Try reloading the page."));
128
+ registry.dispatch(_wordpress_notices.store).createInfoNotice((0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Block %s installed and added."), block.title), {
129
+ speak: true,
130
+ type: "snackbar"
131
+ });
132
+ success = true;
133
+ } catch (error) {
134
+ let message = error.message || (0, _wordpress_i18n.__)("An error occurred.");
135
+ let isFatal = error instanceof Error;
136
+ const fatalAPIErrors = {
137
+ folder_exists: (0, _wordpress_i18n.__)("This block is already installed. Try reloading the page."),
138
+ unable_to_connect_to_filesystem: (0, _wordpress_i18n.__)("Error installing block. You can reload the page and try again.")
139
+ };
140
+ if (fatalAPIErrors[error.code]) {
141
+ isFatal = true;
142
+ message = fatalAPIErrors[error.code];
143
+ }
144
+ dispatch.setErrorNotice(id, message, isFatal);
145
+ registry.dispatch(_wordpress_notices.store).createErrorNotice(message, {
146
+ speak: true,
147
+ isDismissible: true
148
+ });
149
+ }
150
+ dispatch.setIsInstalling(id, false);
151
+ return success;
165
152
  };
166
- var uninstallBlockType = (block) => async ({ registry, dispatch }) => {
167
- try {
168
- const url = (0, import_get_plugin_url.default)(block);
169
- await (0, import_api_fetch.default)({
170
- method: "PUT",
171
- url,
172
- data: { status: "inactive" }
173
- });
174
- await (0, import_api_fetch.default)({
175
- method: "DELETE",
176
- url
177
- });
178
- dispatch.removeInstalledBlockType(block);
179
- } catch (error) {
180
- registry.dispatch(import_notices.store).createErrorNotice(
181
- error.message || (0, import_i18n.__)("An error occurred.")
182
- );
183
- }
153
+ /**
154
+ * Action triggered to uninstall a block plugin.
155
+ *
156
+ * @param {Object} block The blockType object.
157
+ */
158
+ const uninstallBlockType = (block) => async ({ registry, dispatch }) => {
159
+ try {
160
+ const url = (0, __utils_get_plugin_url_js.default)(block);
161
+ await (0, _wordpress_api_fetch.default)({
162
+ method: "PUT",
163
+ url,
164
+ data: { status: "inactive" }
165
+ });
166
+ await (0, _wordpress_api_fetch.default)({
167
+ method: "DELETE",
168
+ url
169
+ });
170
+ dispatch.removeInstalledBlockType(block);
171
+ } catch (error) {
172
+ registry.dispatch(_wordpress_notices.store).createErrorNotice(error.message || (0, _wordpress_i18n.__)("An error occurred."));
173
+ }
184
174
  };
175
+ /**
176
+ * Returns an action object used to add a block type to the "newly installed"
177
+ * tracking list.
178
+ *
179
+ * @param {Object} item The block item with the block id and name.
180
+ *
181
+ * @return {Object} Action object.
182
+ */
185
183
  function addInstalledBlockType(item) {
186
- return {
187
- type: "ADD_INSTALLED_BLOCK_TYPE",
188
- item
189
- };
184
+ return {
185
+ type: "ADD_INSTALLED_BLOCK_TYPE",
186
+ item
187
+ };
190
188
  }
189
+ /**
190
+ * Returns an action object used to remove a block type from the "newly installed"
191
+ * tracking list.
192
+ *
193
+ * @param {string} item The block item with the block id and name.
194
+ *
195
+ * @return {Object} Action object.
196
+ */
191
197
  function removeInstalledBlockType(item) {
192
- return {
193
- type: "REMOVE_INSTALLED_BLOCK_TYPE",
194
- item
195
- };
198
+ return {
199
+ type: "REMOVE_INSTALLED_BLOCK_TYPE",
200
+ item
201
+ };
196
202
  }
203
+ /**
204
+ * Returns an action object used to indicate install in progress.
205
+ *
206
+ * @param {string} blockId
207
+ * @param {boolean} isInstalling
208
+ *
209
+ * @return {Object} Action object.
210
+ */
197
211
  function setIsInstalling(blockId, isInstalling) {
198
- return {
199
- type: "SET_INSTALLING_BLOCK",
200
- blockId,
201
- isInstalling
202
- };
212
+ return {
213
+ type: "SET_INSTALLING_BLOCK",
214
+ blockId,
215
+ isInstalling
216
+ };
203
217
  }
218
+ /**
219
+ * Sets an error notice to be displayed to the user for a given block.
220
+ *
221
+ * @param {string} blockId The ID of the block plugin. eg: my-block
222
+ * @param {string} message The message shown in the notice.
223
+ * @param {boolean} isFatal Whether the user can recover from the error.
224
+ *
225
+ * @return {Object} Action object.
226
+ */
204
227
  function setErrorNotice(blockId, message, isFatal = false) {
205
- return {
206
- type: "SET_ERROR_NOTICE",
207
- blockId,
208
- message,
209
- isFatal
210
- };
228
+ return {
229
+ type: "SET_ERROR_NOTICE",
230
+ blockId,
231
+ message,
232
+ isFatal
233
+ };
211
234
  }
235
+ /**
236
+ * Sets the error notice to empty for specific block.
237
+ *
238
+ * @param {string} blockId The ID of the block plugin. eg: my-block
239
+ *
240
+ * @return {Object} Action object.
241
+ */
212
242
  function clearErrorNotice(blockId) {
213
- return {
214
- type: "CLEAR_ERROR_NOTICE",
215
- blockId
216
- };
243
+ return {
244
+ type: "CLEAR_ERROR_NOTICE",
245
+ blockId
246
+ };
217
247
  }
218
- // Annotate the CommonJS export names for ESM import in node:
219
- 0 && (module.exports = {
220
- addInstalledBlockType,
221
- clearErrorNotice,
222
- fetchDownloadableBlocks,
223
- installBlockType,
224
- receiveDownloadableBlocks,
225
- removeInstalledBlockType,
226
- setErrorNotice,
227
- setIsInstalling,
228
- uninstallBlockType
229
- });
230
- //# sourceMappingURL=actions.cjs.map
248
+ exports.addInstalledBlockType = addInstalledBlockType;
249
+ exports.clearErrorNotice = clearErrorNotice;
250
+ exports.fetchDownloadableBlocks = fetchDownloadableBlocks;
251
+ exports.installBlockType = installBlockType;
252
+ exports.receiveDownloadableBlocks = receiveDownloadableBlocks;
253
+ exports.removeInstalledBlockType = removeInstalledBlockType;
254
+ exports.setErrorNotice = setErrorNotice;
255
+ exports.setIsInstalling = setIsInstalling;
256
+ exports.uninstallBlockType = uninstallBlockType;
257
+
258
+ //# sourceMappingURL=actions.cjs.map