@wordpress/edit-widgets 6.32.0 → 6.32.1-next.b8c8708f3.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 (202) hide show
  1. package/build/blocks/widget-area/block.json +26 -0
  2. package/build/blocks/widget-area/edit/index.js +94 -87
  3. package/build/blocks/widget-area/edit/index.js.map +7 -1
  4. package/build/blocks/widget-area/edit/inner-blocks.js +68 -50
  5. package/build/blocks/widget-area/edit/inner-blocks.js.map +7 -1
  6. package/build/blocks/widget-area/edit/use-is-dragging-within.js +34 -40
  7. package/build/blocks/widget-area/edit/use-is-dragging-within.js.map +7 -1
  8. package/build/blocks/widget-area/index.js +49 -52
  9. package/build/blocks/widget-area/index.js.map +7 -1
  10. package/build/components/error-boundary/index.js +49 -51
  11. package/build/components/error-boundary/index.js.map +7 -1
  12. package/build/components/header/document-tools/index.js +104 -74
  13. package/build/components/header/document-tools/index.js.map +7 -1
  14. package/build/components/header/index.js +81 -62
  15. package/build/components/header/index.js.map +7 -1
  16. package/build/components/header/undo-redo/redo.js +50 -38
  17. package/build/components/header/undo-redo/redo.js.map +7 -1
  18. package/build/components/header/undo-redo/undo.js +49 -37
  19. package/build/components/header/undo-redo/undo.js.map +7 -1
  20. package/build/components/keyboard-shortcut-help-modal/config.js +74 -71
  21. package/build/components/keyboard-shortcut-help-modal/config.js.map +7 -1
  22. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +61 -44
  23. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +7 -1
  24. package/build/components/keyboard-shortcut-help-modal/index.js +154 -103
  25. package/build/components/keyboard-shortcut-help-modal/index.js.map +7 -1
  26. package/build/components/keyboard-shortcut-help-modal/shortcut.js +74 -56
  27. package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +7 -1
  28. package/build/components/keyboard-shortcuts/index.js +89 -82
  29. package/build/components/keyboard-shortcuts/index.js.map +7 -1
  30. package/build/components/layout/index.js +75 -49
  31. package/build/components/layout/index.js.map +7 -1
  32. package/build/components/layout/interface.js +89 -75
  33. package/build/components/layout/interface.js.map +7 -1
  34. package/build/components/layout/unsaved-changes-warning.js +35 -42
  35. package/build/components/layout/unsaved-changes-warning.js.map +7 -1
  36. package/build/components/more-menu/index.js +189 -108
  37. package/build/components/more-menu/index.js.map +7 -1
  38. package/build/components/more-menu/tools-more-menu-group.js +29 -23
  39. package/build/components/more-menu/tools-more-menu-group.js.map +7 -1
  40. package/build/components/notices/index.js +62 -48
  41. package/build/components/notices/index.js.map +7 -1
  42. package/build/components/save-button/index.js +55 -47
  43. package/build/components/save-button/index.js.map +7 -1
  44. package/build/components/secondary-sidebar/index.js +41 -34
  45. package/build/components/secondary-sidebar/index.js.map +7 -1
  46. package/build/components/secondary-sidebar/inserter-sidebar.js +55 -46
  47. package/build/components/secondary-sidebar/inserter-sidebar.js.map +7 -1
  48. package/build/components/secondary-sidebar/list-view-sidebar.js +76 -67
  49. package/build/components/secondary-sidebar/list-view-sidebar.js.map +7 -1
  50. package/build/components/sidebar/index.js +149 -138
  51. package/build/components/sidebar/index.js.map +7 -1
  52. package/build/components/sidebar/widget-areas.js +73 -57
  53. package/build/components/sidebar/widget-areas.js.map +7 -1
  54. package/build/components/welcome-guide/index.js +182 -137
  55. package/build/components/welcome-guide/index.js.map +7 -1
  56. package/build/components/widget-areas-block-editor-content/index.js +64 -43
  57. package/build/components/widget-areas-block-editor-content/index.js.map +7 -1
  58. package/build/components/widget-areas-block-editor-provider/index.js +115 -92
  59. package/build/components/widget-areas-block-editor-provider/index.js.map +7 -1
  60. package/build/constants.js +30 -8
  61. package/build/constants.js.map +7 -1
  62. package/build/filters/index.js +3 -5
  63. package/build/filters/index.js.map +7 -1
  64. package/build/filters/move-to-widget-area.js +52 -59
  65. package/build/filters/move-to-widget-area.js.map +7 -1
  66. package/build/filters/replace-media-upload.js +9 -11
  67. package/build/filters/replace-media-upload.js.map +7 -1
  68. package/build/hooks/use-last-selected-widget-area.js +38 -44
  69. package/build/hooks/use-last-selected-widget-area.js.map +7 -1
  70. package/build/hooks/use-widget-library-insertion-point.js +60 -55
  71. package/build/hooks/use-widget-library-insertion-point.js.map +7 -1
  72. package/build/index.js +86 -93
  73. package/build/index.js.map +7 -1
  74. package/build/lock-unlock.js +31 -15
  75. package/build/lock-unlock.js.map +7 -1
  76. package/build/store/actions.js +181 -313
  77. package/build/store/actions.js.map +7 -1
  78. package/build/store/constants.js +27 -10
  79. package/build/store/constants.js.map +7 -1
  80. package/build/store/index.js +51 -51
  81. package/build/store/index.js.map +7 -1
  82. package/build/store/private-selectors.js +28 -7
  83. package/build/store/private-selectors.js.map +7 -1
  84. package/build/store/reducer.js +65 -118
  85. package/build/store/reducer.js.map +7 -1
  86. package/build/store/resolvers.js +64 -63
  87. package/build/store/resolvers.js.map +7 -1
  88. package/build/store/selectors.js +194 -231
  89. package/build/store/selectors.js.map +7 -1
  90. package/build/store/transformers.js +47 -41
  91. package/build/store/transformers.js.map +7 -1
  92. package/build/store/utils.js +47 -70
  93. package/build/store/utils.js.map +7 -1
  94. package/build-module/blocks/widget-area/block.json +26 -0
  95. package/build-module/blocks/widget-area/edit/index.js +63 -75
  96. package/build-module/blocks/widget-area/edit/index.js.map +7 -1
  97. package/build-module/blocks/widget-area/edit/inner-blocks.js +38 -41
  98. package/build-module/blocks/widget-area/edit/inner-blocks.js.map +7 -1
  99. package/build-module/blocks/widget-area/edit/use-is-dragging-within.js +14 -33
  100. package/build-module/blocks/widget-area/edit/use-is-dragging-within.js.map +7 -1
  101. package/build-module/blocks/widget-area/index.js +14 -46
  102. package/build-module/blocks/widget-area/index.js.map +7 -1
  103. package/build-module/components/error-boundary/index.js +30 -43
  104. package/build-module/components/error-boundary/index.js.map +7 -1
  105. package/build-module/components/header/document-tools/index.js +75 -66
  106. package/build-module/components/header/document-tools/index.js.map +7 -1
  107. package/build-module/components/header/index.js +52 -54
  108. package/build-module/components/header/index.js.map +7 -1
  109. package/build-module/components/header/undo-redo/redo.js +32 -32
  110. package/build-module/components/header/undo-redo/redo.js.map +7 -1
  111. package/build-module/components/header/undo-redo/undo.js +31 -31
  112. package/build-module/components/header/undo-redo/undo.js.map +7 -1
  113. package/build-module/components/keyboard-shortcut-help-modal/config.js +62 -75
  114. package/build-module/components/keyboard-shortcut-help-modal/config.js.map +7 -1
  115. package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +33 -37
  116. package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +7 -1
  117. package/build-module/components/keyboard-shortcut-help-modal/index.js +130 -97
  118. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +7 -1
  119. package/build-module/components/keyboard-shortcut-help-modal/shortcut.js +56 -50
  120. package/build-module/components/keyboard-shortcut-help-modal/shortcut.js.map +7 -1
  121. package/build-module/components/keyboard-shortcuts/index.js +73 -75
  122. package/build-module/components/keyboard-shortcuts/index.js.map +7 -1
  123. package/build-module/components/layout/index.js +46 -41
  124. package/build-module/components/layout/index.js.map +7 -1
  125. package/build-module/components/layout/interface.js +63 -66
  126. package/build-module/components/layout/interface.js.map +7 -1
  127. package/build-module/components/layout/unsaved-changes-warning.js +17 -37
  128. package/build-module/components/layout/unsaved-changes-warning.js.map +7 -1
  129. package/build-module/components/more-menu/index.js +167 -102
  130. package/build-module/components/more-menu/index.js.map +7 -1
  131. package/build-module/components/more-menu/tools-more-menu-group.js +11 -17
  132. package/build-module/components/more-menu/tools-more-menu-group.js.map +7 -1
  133. package/build-module/components/notices/index.js +43 -42
  134. package/build-module/components/notices/index.js.map +7 -1
  135. package/build-module/components/save-button/index.js +37 -41
  136. package/build-module/components/save-button/index.js.map +7 -1
  137. package/build-module/components/secondary-sidebar/index.js +14 -27
  138. package/build-module/components/secondary-sidebar/index.js.map +7 -1
  139. package/build-module/components/secondary-sidebar/inserter-sidebar.js +26 -38
  140. package/build-module/components/secondary-sidebar/inserter-sidebar.js.map +7 -1
  141. package/build-module/components/secondary-sidebar/list-view-sidebar.js +57 -60
  142. package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +7 -1
  143. package/build-module/components/sidebar/index.js +129 -127
  144. package/build-module/components/sidebar/index.js.map +7 -1
  145. package/build-module/components/sidebar/widget-areas.js +53 -49
  146. package/build-module/components/sidebar/widget-areas.js.map +7 -1
  147. package/build-module/components/welcome-guide/index.js +165 -132
  148. package/build-module/components/welcome-guide/index.js.map +7 -1
  149. package/build-module/components/widget-areas-block-editor-content/index.js +43 -36
  150. package/build-module/components/widget-areas-block-editor-content/index.js.map +7 -1
  151. package/build-module/components/widget-areas-block-editor-provider/index.js +85 -83
  152. package/build-module/components/widget-areas-block-editor-provider/index.js.map +7 -1
  153. package/build-module/constants.js +7 -3
  154. package/build-module/constants.js.map +7 -1
  155. package/build-module/filters/index.js +3 -6
  156. package/build-module/filters/index.js.map +7 -1
  157. package/build-module/filters/move-to-widget-area.js +52 -57
  158. package/build-module/filters/move-to-widget-area.js.map +7 -1
  159. package/build-module/filters/replace-media-upload.js +8 -7
  160. package/build-module/filters/replace-media-upload.js.map +7 -1
  161. package/build-module/hooks/use-last-selected-widget-area.js +20 -39
  162. package/build-module/hooks/use-last-selected-widget-area.js.map +7 -1
  163. package/build-module/hooks/use-widget-library-insertion-point.js +42 -49
  164. package/build-module/hooks/use-widget-library-insertion-point.js.map +7 -1
  165. package/build-module/index.js +60 -72
  166. package/build-module/index.js.map +7 -1
  167. package/build-module/lock-unlock.js +8 -7
  168. package/build-module/lock-unlock.js.map +7 -1
  169. package/build-module/store/actions.js +153 -293
  170. package/build-module/store/actions.js.map +7 -1
  171. package/build-module/store/constants.js +5 -5
  172. package/build-module/store/constants.js.map +7 -1
  173. package/build-module/store/index.js +16 -40
  174. package/build-module/store/index.js.map +7 -1
  175. package/build-module/store/private-selectors.js +7 -3
  176. package/build-module/store/private-selectors.js.map +7 -1
  177. package/build-module/store/reducer.js +42 -111
  178. package/build-module/store/reducer.js.map +7 -1
  179. package/build-module/store/resolvers.js +43 -51
  180. package/build-module/store/resolvers.js.map +7 -1
  181. package/build-module/store/selectors.js +171 -224
  182. package/build-module/store/selectors.js.map +7 -1
  183. package/build-module/store/transformers.js +23 -34
  184. package/build-module/store/transformers.js.map +7 -1
  185. package/build-module/store/utils.js +22 -63
  186. package/build-module/store/utils.js.map +7 -1
  187. package/build-style/style-rtl.css +216 -88
  188. package/build-style/style.css +216 -88
  189. package/package.json +36 -29
  190. package/src/blocks/widget-area/editor.scss +3 -0
  191. package/src/components/customizer-edit-widgets-initializer/style.scss +3 -0
  192. package/src/components/error-boundary/style.scss +2 -0
  193. package/src/components/header/style.scss +5 -0
  194. package/src/components/keyboard-shortcut-help-modal/style.scss +2 -0
  195. package/src/components/layout/style.scss +3 -0
  196. package/src/components/more-menu/style.scss +2 -0
  197. package/src/components/notices/style.scss +3 -0
  198. package/src/components/secondary-sidebar/style.scss +4 -0
  199. package/src/components/sidebar/style.scss +2 -0
  200. package/src/components/welcome-guide/style.scss +2 -0
  201. package/src/components/widget-areas-block-editor-content/style.scss +2 -0
  202. package/src/style.scss +16 -13
@@ -1,91 +1,92 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var resolvers_exports = {};
19
+ __export(resolvers_exports, {
20
+ getWidgetAreas: () => getWidgetAreas,
21
+ getWidgets: () => getWidgets
5
22
  });
6
- exports.getWidgets = exports.getWidgetAreas = void 0;
7
- var _blocks = require("@wordpress/blocks");
8
- var _coreData = require("@wordpress/core-data");
9
- var _actions = require("./actions");
10
- var _utils = require("./utils");
11
- var _transformers = require("./transformers");
12
- /**
13
- * WordPress dependencies
14
- */
15
-
16
- /**
17
- * Internal dependencies
18
- */
19
-
20
- /**
21
- * Creates a "stub" widgets post reflecting all available widget areas. The
22
- * post is meant as a convenient to only exists in runtime and should never be saved. It
23
- * enables a convenient way of editing the widgets by using a regular post editor.
24
- *
25
- * Fetches all widgets from all widgets aras, converts them into blocks, and hydrates a new post with them.
26
- *
27
- * @return {Function} An action creator.
28
- */
29
- const getWidgetAreas = () => async ({
30
- dispatch,
31
- registry
32
- }) => {
33
- const query = (0, _utils.buildWidgetAreasQuery)();
34
- const widgetAreas = await registry.resolveSelect(_coreData.store).getEntityRecords(_utils.KIND, _utils.WIDGET_AREA_ENTITY_TYPE, query);
23
+ module.exports = __toCommonJS(resolvers_exports);
24
+ var import_blocks = require("@wordpress/blocks");
25
+ var import_core_data = require("@wordpress/core-data");
26
+ var import_actions = require("./actions");
27
+ var import_utils = require("./utils");
28
+ var import_transformers = require("./transformers");
29
+ const getWidgetAreas = () => async ({ dispatch, registry }) => {
30
+ const query = (0, import_utils.buildWidgetAreasQuery)();
31
+ const widgetAreas = await registry.resolveSelect(import_core_data.store).getEntityRecords(import_utils.KIND, import_utils.WIDGET_AREA_ENTITY_TYPE, query);
35
32
  const widgetAreaBlocks = [];
36
33
  const sortedWidgetAreas = widgetAreas.sort((a, b) => {
37
- if (a.id === 'wp_inactive_widgets') {
34
+ if (a.id === "wp_inactive_widgets") {
38
35
  return 1;
39
36
  }
40
- if (b.id === 'wp_inactive_widgets') {
37
+ if (b.id === "wp_inactive_widgets") {
41
38
  return -1;
42
39
  }
43
40
  return 0;
44
41
  });
45
42
  for (const widgetArea of sortedWidgetAreas) {
46
- widgetAreaBlocks.push((0, _blocks.createBlock)('core/widget-area', {
47
- id: widgetArea.id,
48
- name: widgetArea.name
49
- }));
43
+ widgetAreaBlocks.push(
44
+ (0, import_blocks.createBlock)("core/widget-area", {
45
+ id: widgetArea.id,
46
+ name: widgetArea.name
47
+ })
48
+ );
50
49
  if (!widgetArea.widgets.length) {
51
- // If this widget area has no widgets, it won't get a post setup by
52
- // the getWidgets resolver.
53
- dispatch((0, _actions.persistStubPost)((0, _utils.buildWidgetAreaPostId)(widgetArea.id), []));
50
+ dispatch(
51
+ (0, import_actions.persistStubPost)(
52
+ (0, import_utils.buildWidgetAreaPostId)(widgetArea.id),
53
+ []
54
+ )
55
+ );
54
56
  }
55
57
  }
56
58
  const widgetAreasOpenState = {};
57
59
  widgetAreaBlocks.forEach((widgetAreaBlock, index) => {
58
- // Defaults to open the first widget area.
59
60
  widgetAreasOpenState[widgetAreaBlock.clientId] = index === 0;
60
61
  });
61
- dispatch((0, _actions.setWidgetAreasOpenState)(widgetAreasOpenState));
62
- dispatch((0, _actions.persistStubPost)((0, _utils.buildWidgetAreasPostId)(), widgetAreaBlocks));
62
+ dispatch((0, import_actions.setWidgetAreasOpenState)(widgetAreasOpenState));
63
+ dispatch(
64
+ (0, import_actions.persistStubPost)((0, import_utils.buildWidgetAreasPostId)(), widgetAreaBlocks)
65
+ );
63
66
  };
64
-
65
- /**
66
- * Fetches all widgets from all widgets ares, and groups them by widget area Id.
67
- *
68
- * @return {Function} An action creator.
69
- */
70
- exports.getWidgetAreas = getWidgetAreas;
71
- const getWidgets = () => async ({
72
- dispatch,
73
- registry
74
- }) => {
75
- const query = (0, _utils.buildWidgetsQuery)();
76
- const widgets = await registry.resolveSelect(_coreData.store).getEntityRecords('root', 'widget', query);
67
+ const getWidgets = () => async ({ dispatch, registry }) => {
68
+ const query = (0, import_utils.buildWidgetsQuery)();
69
+ const widgets = await registry.resolveSelect(import_core_data.store).getEntityRecords("root", "widget", query);
77
70
  const groupedBySidebar = {};
78
71
  for (const widget of widgets) {
79
- const block = (0, _transformers.transformWidgetToBlock)(widget);
72
+ const block = (0, import_transformers.transformWidgetToBlock)(widget);
80
73
  groupedBySidebar[widget.sidebar] = groupedBySidebar[widget.sidebar] || [];
81
74
  groupedBySidebar[widget.sidebar].push(block);
82
75
  }
83
76
  for (const sidebarId in groupedBySidebar) {
84
77
  if (groupedBySidebar.hasOwnProperty(sidebarId)) {
85
- // Persist the actual post containing the widget block
86
- dispatch((0, _actions.persistStubPost)((0, _utils.buildWidgetAreaPostId)(sidebarId), groupedBySidebar[sidebarId]));
78
+ dispatch(
79
+ (0, import_actions.persistStubPost)(
80
+ (0, import_utils.buildWidgetAreaPostId)(sidebarId),
81
+ groupedBySidebar[sidebarId]
82
+ )
83
+ );
87
84
  }
88
85
  }
89
86
  };
90
- exports.getWidgets = getWidgets;
91
- //# sourceMappingURL=resolvers.js.map
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ getWidgetAreas,
90
+ getWidgets
91
+ });
92
+ //# sourceMappingURL=resolvers.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_blocks","require","_coreData","_actions","_utils","_transformers","getWidgetAreas","dispatch","registry","query","buildWidgetAreasQuery","widgetAreas","resolveSelect","coreStore","getEntityRecords","KIND","WIDGET_AREA_ENTITY_TYPE","widgetAreaBlocks","sortedWidgetAreas","sort","a","b","id","widgetArea","push","createBlock","name","widgets","length","persistStubPost","buildWidgetAreaPostId","widgetAreasOpenState","forEach","widgetAreaBlock","index","clientId","setWidgetAreasOpenState","buildWidgetAreasPostId","exports","getWidgets","buildWidgetsQuery","groupedBySidebar","widget","block","transformWidgetToBlock","sidebar","sidebarId","hasOwnProperty"],"sources":["@wordpress/edit-widgets/src/store/resolvers.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { persistStubPost, setWidgetAreasOpenState } from './actions';\nimport {\n\tKIND,\n\tWIDGET_AREA_ENTITY_TYPE,\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tbuildWidgetAreasPostId,\n} from './utils';\nimport { transformWidgetToBlock } from './transformers';\n\n/**\n * Creates a \"stub\" widgets post reflecting all available widget areas. The\n * post is meant as a convenient to only exists in runtime and should never be saved. It\n * enables a convenient way of editing the widgets by using a regular post editor.\n *\n * Fetches all widgets from all widgets aras, converts them into blocks, and hydrates a new post with them.\n *\n * @return {Function} An action creator.\n */\nexport const getWidgetAreas =\n\t() =>\n\tasync ( { dispatch, registry } ) => {\n\t\tconst query = buildWidgetAreasQuery();\n\t\tconst widgetAreas = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecords( KIND, WIDGET_AREA_ENTITY_TYPE, query );\n\n\t\tconst widgetAreaBlocks = [];\n\t\tconst sortedWidgetAreas = widgetAreas.sort( ( a, b ) => {\n\t\t\tif ( a.id === 'wp_inactive_widgets' ) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tif ( b.id === 'wp_inactive_widgets' ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 0;\n\t\t} );\n\t\tfor ( const widgetArea of sortedWidgetAreas ) {\n\t\t\twidgetAreaBlocks.push(\n\t\t\t\tcreateBlock( 'core/widget-area', {\n\t\t\t\t\tid: widgetArea.id,\n\t\t\t\t\tname: widgetArea.name,\n\t\t\t\t} )\n\t\t\t);\n\n\t\t\tif ( ! widgetArea.widgets.length ) {\n\t\t\t\t// If this widget area has no widgets, it won't get a post setup by\n\t\t\t\t// the getWidgets resolver.\n\t\t\t\tdispatch(\n\t\t\t\t\tpersistStubPost(\n\t\t\t\t\t\tbuildWidgetAreaPostId( widgetArea.id ),\n\t\t\t\t\t\t[]\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst widgetAreasOpenState = {};\n\t\twidgetAreaBlocks.forEach( ( widgetAreaBlock, index ) => {\n\t\t\t// Defaults to open the first widget area.\n\t\t\twidgetAreasOpenState[ widgetAreaBlock.clientId ] = index === 0;\n\t\t} );\n\t\tdispatch( setWidgetAreasOpenState( widgetAreasOpenState ) );\n\n\t\tdispatch(\n\t\t\tpersistStubPost( buildWidgetAreasPostId(), widgetAreaBlocks )\n\t\t);\n\t};\n\n/**\n * Fetches all widgets from all widgets ares, and groups them by widget area Id.\n *\n * @return {Function} An action creator.\n */\nexport const getWidgets =\n\t() =>\n\tasync ( { dispatch, registry } ) => {\n\t\tconst query = buildWidgetsQuery();\n\t\tconst widgets = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecords( 'root', 'widget', query );\n\n\t\tconst groupedBySidebar = {};\n\n\t\tfor ( const widget of widgets ) {\n\t\t\tconst block = transformWidgetToBlock( widget );\n\t\t\tgroupedBySidebar[ widget.sidebar ] =\n\t\t\t\tgroupedBySidebar[ widget.sidebar ] || [];\n\t\t\tgroupedBySidebar[ widget.sidebar ].push( block );\n\t\t}\n\n\t\tfor ( const sidebarId in groupedBySidebar ) {\n\t\t\tif ( groupedBySidebar.hasOwnProperty( sidebarId ) ) {\n\t\t\t\t// Persist the actual post containing the widget block\n\t\t\t\tdispatch(\n\t\t\t\t\tpersistStubPost(\n\t\t\t\t\t\tbuildWidgetAreaPostId( sidebarId ),\n\t\t\t\t\t\tgroupedBySidebar[ sidebarId ]\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t};\n"],"mappings":"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","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/store/resolvers.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { persistStubPost, setWidgetAreasOpenState } from './actions';\nimport {\n\tKIND,\n\tWIDGET_AREA_ENTITY_TYPE,\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tbuildWidgetAreasPostId,\n} from './utils';\nimport { transformWidgetToBlock } from './transformers';\n\n/**\n * Creates a \"stub\" widgets post reflecting all available widget areas. The\n * post is meant as a convenient to only exists in runtime and should never be saved. It\n * enables a convenient way of editing the widgets by using a regular post editor.\n *\n * Fetches all widgets from all widgets aras, converts them into blocks, and hydrates a new post with them.\n *\n * @return {Function} An action creator.\n */\nexport const getWidgetAreas =\n\t() =>\n\tasync ( { dispatch, registry } ) => {\n\t\tconst query = buildWidgetAreasQuery();\n\t\tconst widgetAreas = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecords( KIND, WIDGET_AREA_ENTITY_TYPE, query );\n\n\t\tconst widgetAreaBlocks = [];\n\t\tconst sortedWidgetAreas = widgetAreas.sort( ( a, b ) => {\n\t\t\tif ( a.id === 'wp_inactive_widgets' ) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tif ( b.id === 'wp_inactive_widgets' ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 0;\n\t\t} );\n\t\tfor ( const widgetArea of sortedWidgetAreas ) {\n\t\t\twidgetAreaBlocks.push(\n\t\t\t\tcreateBlock( 'core/widget-area', {\n\t\t\t\t\tid: widgetArea.id,\n\t\t\t\t\tname: widgetArea.name,\n\t\t\t\t} )\n\t\t\t);\n\n\t\t\tif ( ! widgetArea.widgets.length ) {\n\t\t\t\t// If this widget area has no widgets, it won't get a post setup by\n\t\t\t\t// the getWidgets resolver.\n\t\t\t\tdispatch(\n\t\t\t\t\tpersistStubPost(\n\t\t\t\t\t\tbuildWidgetAreaPostId( widgetArea.id ),\n\t\t\t\t\t\t[]\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst widgetAreasOpenState = {};\n\t\twidgetAreaBlocks.forEach( ( widgetAreaBlock, index ) => {\n\t\t\t// Defaults to open the first widget area.\n\t\t\twidgetAreasOpenState[ widgetAreaBlock.clientId ] = index === 0;\n\t\t} );\n\t\tdispatch( setWidgetAreasOpenState( widgetAreasOpenState ) );\n\n\t\tdispatch(\n\t\t\tpersistStubPost( buildWidgetAreasPostId(), widgetAreaBlocks )\n\t\t);\n\t};\n\n/**\n * Fetches all widgets from all widgets ares, and groups them by widget area Id.\n *\n * @return {Function} An action creator.\n */\nexport const getWidgets =\n\t() =>\n\tasync ( { dispatch, registry } ) => {\n\t\tconst query = buildWidgetsQuery();\n\t\tconst widgets = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecords( 'root', 'widget', query );\n\n\t\tconst groupedBySidebar = {};\n\n\t\tfor ( const widget of widgets ) {\n\t\t\tconst block = transformWidgetToBlock( widget );\n\t\t\tgroupedBySidebar[ widget.sidebar ] =\n\t\t\t\tgroupedBySidebar[ widget.sidebar ] || [];\n\t\t\tgroupedBySidebar[ widget.sidebar ].push( block );\n\t\t}\n\n\t\tfor ( const sidebarId in groupedBySidebar ) {\n\t\t\tif ( groupedBySidebar.hasOwnProperty( sidebarId ) ) {\n\t\t\t\t// Persist the actual post containing the widget block\n\t\t\t\tdispatch(\n\t\t\t\t\tpersistStubPost(\n\t\t\t\t\t\tbuildWidgetAreaPostId( sidebarId ),\n\t\t\t\t\t\tgroupedBySidebar[ sidebarId ]\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA4B;AAC5B,uBAAmC;AAKnC,qBAAyD;AACzD,mBAOO;AACP,0BAAuC;AAWhC,MAAM,iBACZ,MACA,OAAQ,EAAE,UAAU,SAAS,MAAO;AACnC,QAAM,YAAQ,oCAAsB;AACpC,QAAM,cAAc,MAAM,SACxB,cAAe,iBAAAA,KAAU,EACzB,iBAAkB,mBAAM,sCAAyB,KAAM;AAEzD,QAAM,mBAAmB,CAAC;AAC1B,QAAM,oBAAoB,YAAY,KAAM,CAAE,GAAG,MAAO;AACvD,QAAK,EAAE,OAAO,uBAAwB;AACrC,aAAO;AAAA,IACR;AACA,QAAK,EAAE,OAAO,uBAAwB;AACrC,aAAO;AAAA,IACR;AACA,WAAO;AAAA,EACR,CAAE;AACF,aAAY,cAAc,mBAAoB;AAC7C,qBAAiB;AAAA,UAChB,2BAAa,oBAAoB;AAAA,QAChC,IAAI,WAAW;AAAA,QACf,MAAM,WAAW;AAAA,MAClB,CAAE;AAAA,IACH;AAEA,QAAK,CAAE,WAAW,QAAQ,QAAS;AAGlC;AAAA,YACC;AAAA,cACC,oCAAuB,WAAW,EAAG;AAAA,UACrC,CAAC;AAAA,QACF;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,QAAM,uBAAuB,CAAC;AAC9B,mBAAiB,QAAS,CAAE,iBAAiB,UAAW;AAEvD,yBAAsB,gBAAgB,QAAS,IAAI,UAAU;AAAA,EAC9D,CAAE;AACF,eAAU,wCAAyB,oBAAqB,CAAE;AAE1D;AAAA,QACC,oCAAiB,qCAAuB,GAAG,gBAAiB;AAAA,EAC7D;AACD;AAOM,MAAM,aACZ,MACA,OAAQ,EAAE,UAAU,SAAS,MAAO;AACnC,QAAM,YAAQ,gCAAkB;AAChC,QAAM,UAAU,MAAM,SACpB,cAAe,iBAAAA,KAAU,EACzB,iBAAkB,QAAQ,UAAU,KAAM;AAE5C,QAAM,mBAAmB,CAAC;AAE1B,aAAY,UAAU,SAAU;AAC/B,UAAM,YAAQ,4CAAwB,MAAO;AAC7C,qBAAkB,OAAO,OAAQ,IAChC,iBAAkB,OAAO,OAAQ,KAAK,CAAC;AACxC,qBAAkB,OAAO,OAAQ,EAAE,KAAM,KAAM;AAAA,EAChD;AAEA,aAAY,aAAa,kBAAmB;AAC3C,QAAK,iBAAiB,eAAgB,SAAU,GAAI;AAEnD;AAAA,YACC;AAAA,cACC,oCAAuB,SAAU;AAAA,UACjC,iBAAkB,SAAU;AAAA,QAC7B;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;",
6
+ "names": ["coreStore"]
7
+ }
@@ -1,274 +1,237 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var selectors_exports = {};
19
+ __export(selectors_exports, {
20
+ __experimentalGetInsertionPoint: () => __experimentalGetInsertionPoint,
21
+ canInsertBlockInWidgetArea: () => canInsertBlockInWidgetArea,
22
+ getEditedWidgetAreas: () => getEditedWidgetAreas,
23
+ getIsWidgetAreaOpen: () => getIsWidgetAreaOpen,
24
+ getParentWidgetAreaBlock: () => getParentWidgetAreaBlock,
25
+ getReferenceWidgetBlocks: () => getReferenceWidgetBlocks,
26
+ getWidget: () => getWidget,
27
+ getWidgetAreaForWidgetId: () => getWidgetAreaForWidgetId,
28
+ getWidgetAreas: () => getWidgetAreas,
29
+ getWidgets: () => getWidgets,
30
+ isInserterOpened: () => isInserterOpened,
31
+ isListViewOpened: () => isListViewOpened,
32
+ isSavingWidgetAreas: () => isSavingWidgetAreas,
33
+ isWidgetSavingLocked: () => isWidgetSavingLocked
5
34
  });
6
- exports.__experimentalGetInsertionPoint = __experimentalGetInsertionPoint;
7
- exports.getWidgets = exports.getWidgetAreas = exports.getWidgetAreaForWidgetId = exports.getWidget = exports.getReferenceWidgetBlocks = exports.getParentWidgetAreaBlock = exports.getIsWidgetAreaOpen = exports.getEditedWidgetAreas = exports.canInsertBlockInWidgetArea = void 0;
8
- exports.isInserterOpened = isInserterOpened;
9
- exports.isListViewOpened = isListViewOpened;
10
- exports.isSavingWidgetAreas = void 0;
11
- exports.isWidgetSavingLocked = isWidgetSavingLocked;
12
- var _data = require("@wordpress/data");
13
- var _widgets = require("@wordpress/widgets");
14
- var _coreData = require("@wordpress/core-data");
15
- var _blockEditor = require("@wordpress/block-editor");
16
- var _utils = require("./utils");
17
- var _constants = require("./constants");
18
- /**
19
- * WordPress dependencies
20
- */
21
-
22
- /**
23
- * Internal dependencies
24
- */
25
-
35
+ module.exports = __toCommonJS(selectors_exports);
36
+ var import_data = require("@wordpress/data");
37
+ var import_widgets = require("@wordpress/widgets");
38
+ var import_core_data = require("@wordpress/core-data");
39
+ var import_block_editor = require("@wordpress/block-editor");
40
+ var import_utils = require("./utils");
41
+ var import_constants = require("./constants");
26
42
  const EMPTY_INSERTION_POINT = {
27
- rootClientId: undefined,
28
- insertionIndex: undefined
43
+ rootClientId: void 0,
44
+ insertionIndex: void 0
29
45
  };
30
-
31
- /**
32
- * Returns all API widgets.
33
- *
34
- * @return {Object[]} API List of widgets.
35
- */
36
- const getWidgets = exports.getWidgets = (0, _data.createRegistrySelector)(select => (0, _data.createSelector)(() => {
37
- var _widgets$reduce;
38
- const widgets = select(_coreData.store).getEntityRecords('root', 'widget', (0, _utils.buildWidgetsQuery)());
39
- return (// Key widgets by their ID.
40
- (_widgets$reduce = widgets?.reduce((allWidgets, widget) => ({
41
- ...allWidgets,
42
- [widget.id]: widget
43
- }), {})) !== null && _widgets$reduce !== void 0 ? _widgets$reduce : {}
46
+ const getWidgets = (0, import_data.createRegistrySelector)(
47
+ (select) => (0, import_data.createSelector)(
48
+ () => {
49
+ const widgets = select(import_core_data.store).getEntityRecords(
50
+ "root",
51
+ "widget",
52
+ (0, import_utils.buildWidgetsQuery)()
53
+ );
54
+ return (
55
+ // Key widgets by their ID.
56
+ widgets?.reduce(
57
+ (allWidgets, widget) => ({
58
+ ...allWidgets,
59
+ [widget.id]: widget
60
+ }),
61
+ {}
62
+ ) ?? {}
63
+ );
64
+ },
65
+ () => [
66
+ select(import_core_data.store).getEntityRecords(
67
+ "root",
68
+ "widget",
69
+ (0, import_utils.buildWidgetsQuery)()
70
+ )
71
+ ]
72
+ )
73
+ );
74
+ const getWidget = (0, import_data.createRegistrySelector)(
75
+ (select) => (state, id) => {
76
+ const widgets = select(import_constants.STORE_NAME).getWidgets();
77
+ return widgets[id];
78
+ }
79
+ );
80
+ const getWidgetAreas = (0, import_data.createRegistrySelector)((select) => () => {
81
+ const query = (0, import_utils.buildWidgetAreasQuery)();
82
+ return select(import_core_data.store).getEntityRecords(
83
+ import_utils.KIND,
84
+ import_utils.WIDGET_AREA_ENTITY_TYPE,
85
+ query
44
86
  );
45
- }, () => [select(_coreData.store).getEntityRecords('root', 'widget', (0, _utils.buildWidgetsQuery)())]));
46
-
47
- /**
48
- * Returns API widget data for a particular widget ID.
49
- *
50
- * @param {number} id Widget ID.
51
- *
52
- * @return {Object} API widget data for a particular widget ID.
53
- */
54
- const getWidget = exports.getWidget = (0, _data.createRegistrySelector)(select => (state, id) => {
55
- const widgets = select(_constants.STORE_NAME).getWidgets();
56
- return widgets[id];
57
- });
58
-
59
- /**
60
- * Returns all API widget areas.
61
- *
62
- * @return {Object[]} API List of widget areas.
63
- */
64
- const getWidgetAreas = exports.getWidgetAreas = (0, _data.createRegistrySelector)(select => () => {
65
- const query = (0, _utils.buildWidgetAreasQuery)();
66
- return select(_coreData.store).getEntityRecords(_utils.KIND, _utils.WIDGET_AREA_ENTITY_TYPE, query);
67
87
  });
68
-
69
- /**
70
- * Returns widgetArea containing a block identify by given widgetId
71
- *
72
- * @param {string} widgetId The ID of the widget.
73
- * @return {Object} Containing widget area.
74
- */
75
- const getWidgetAreaForWidgetId = exports.getWidgetAreaForWidgetId = (0, _data.createRegistrySelector)(select => (state, widgetId) => {
76
- const widgetAreas = select(_constants.STORE_NAME).getWidgetAreas();
77
- return widgetAreas.find(widgetArea => {
78
- const post = select(_coreData.store).getEditedEntityRecord(_utils.KIND, _utils.POST_TYPE, (0, _utils.buildWidgetAreaPostId)(widgetArea.id));
79
- const blockWidgetIds = post.blocks.map(block => (0, _widgets.getWidgetIdFromBlock)(block));
80
- return blockWidgetIds.includes(widgetId);
81
- });
82
- });
83
-
84
- /**
85
- * Given a child client id, returns the parent widget area block.
86
- *
87
- * @param {string} clientId The client id of a block in a widget area.
88
- *
89
- * @return {WPBlock} The widget area block.
90
- */
91
- const getParentWidgetAreaBlock = exports.getParentWidgetAreaBlock = (0, _data.createRegistrySelector)(select => (state, clientId) => {
92
- const {
93
- getBlock,
94
- getBlockName,
95
- getBlockParents
96
- } = select(_blockEditor.store);
97
- const blockParents = getBlockParents(clientId);
98
- const widgetAreaClientId = blockParents.find(parentClientId => getBlockName(parentClientId) === 'core/widget-area');
99
- return getBlock(widgetAreaClientId);
100
- });
101
-
102
- /**
103
- * Returns all edited widget area entity records.
104
- *
105
- * @return {Object[]} List of edited widget area entity records.
106
- */
107
- const getEditedWidgetAreas = exports.getEditedWidgetAreas = (0, _data.createRegistrySelector)(select => (state, ids) => {
108
- let widgetAreas = select(_constants.STORE_NAME).getWidgetAreas();
109
- if (!widgetAreas) {
110
- return [];
88
+ const getWidgetAreaForWidgetId = (0, import_data.createRegistrySelector)(
89
+ (select) => (state, widgetId) => {
90
+ const widgetAreas = select(import_constants.STORE_NAME).getWidgetAreas();
91
+ return widgetAreas.find((widgetArea) => {
92
+ const post = select(import_core_data.store).getEditedEntityRecord(
93
+ import_utils.KIND,
94
+ import_utils.POST_TYPE,
95
+ (0, import_utils.buildWidgetAreaPostId)(widgetArea.id)
96
+ );
97
+ const blockWidgetIds = post.blocks.map(
98
+ (block) => (0, import_widgets.getWidgetIdFromBlock)(block)
99
+ );
100
+ return blockWidgetIds.includes(widgetId);
101
+ });
111
102
  }
112
- if (ids) {
113
- widgetAreas = widgetAreas.filter(({
114
- id
115
- }) => ids.includes(id));
103
+ );
104
+ const getParentWidgetAreaBlock = (0, import_data.createRegistrySelector)(
105
+ (select) => (state, clientId) => {
106
+ const { getBlock, getBlockName, getBlockParents } = select(import_block_editor.store);
107
+ const blockParents = getBlockParents(clientId);
108
+ const widgetAreaClientId = blockParents.find(
109
+ (parentClientId) => getBlockName(parentClientId) === "core/widget-area"
110
+ );
111
+ return getBlock(widgetAreaClientId);
116
112
  }
117
- return widgetAreas.filter(({
118
- id
119
- }) => select(_coreData.store).hasEditsForEntityRecord(_utils.KIND, _utils.POST_TYPE, (0, _utils.buildWidgetAreaPostId)(id))).map(({
120
- id
121
- }) => select(_coreData.store).getEditedEntityRecord(_utils.KIND, _utils.WIDGET_AREA_ENTITY_TYPE, id));
122
- });
123
-
124
- /**
125
- * Returns all blocks representing reference widgets.
126
- *
127
- * @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.
128
- * @return {Array} List of all blocks representing reference widgets
129
- */
130
- const getReferenceWidgetBlocks = exports.getReferenceWidgetBlocks = (0, _data.createRegistrySelector)(select => (state, referenceWidgetName = null) => {
131
- const results = [];
132
- const widgetAreas = select(_constants.STORE_NAME).getWidgetAreas();
133
- for (const _widgetArea of widgetAreas) {
134
- const post = select(_coreData.store).getEditedEntityRecord(_utils.KIND, _utils.POST_TYPE, (0, _utils.buildWidgetAreaPostId)(_widgetArea.id));
135
- for (const block of post.blocks) {
136
- if (block.name === 'core/legacy-widget' && (!referenceWidgetName || block.attributes?.referenceWidgetName === referenceWidgetName)) {
137
- results.push(block);
113
+ );
114
+ const getEditedWidgetAreas = (0, import_data.createRegistrySelector)(
115
+ (select) => (state, ids) => {
116
+ let widgetAreas = select(import_constants.STORE_NAME).getWidgetAreas();
117
+ if (!widgetAreas) {
118
+ return [];
119
+ }
120
+ if (ids) {
121
+ widgetAreas = widgetAreas.filter(
122
+ ({ id }) => ids.includes(id)
123
+ );
124
+ }
125
+ return widgetAreas.filter(
126
+ ({ id }) => select(import_core_data.store).hasEditsForEntityRecord(
127
+ import_utils.KIND,
128
+ import_utils.POST_TYPE,
129
+ (0, import_utils.buildWidgetAreaPostId)(id)
130
+ )
131
+ ).map(
132
+ ({ id }) => select(import_core_data.store).getEditedEntityRecord(
133
+ import_utils.KIND,
134
+ import_utils.WIDGET_AREA_ENTITY_TYPE,
135
+ id
136
+ )
137
+ );
138
+ }
139
+ );
140
+ const getReferenceWidgetBlocks = (0, import_data.createRegistrySelector)(
141
+ (select) => (state, referenceWidgetName = null) => {
142
+ const results = [];
143
+ const widgetAreas = select(import_constants.STORE_NAME).getWidgetAreas();
144
+ for (const _widgetArea of widgetAreas) {
145
+ const post = select(import_core_data.store).getEditedEntityRecord(
146
+ import_utils.KIND,
147
+ import_utils.POST_TYPE,
148
+ (0, import_utils.buildWidgetAreaPostId)(_widgetArea.id)
149
+ );
150
+ for (const block of post.blocks) {
151
+ if (block.name === "core/legacy-widget" && (!referenceWidgetName || block.attributes?.referenceWidgetName === referenceWidgetName)) {
152
+ results.push(block);
153
+ }
138
154
  }
139
155
  }
156
+ return results;
140
157
  }
141
- return results;
142
- });
143
-
144
- /**
145
- * Returns true if any widget area is currently being saved.
146
- *
147
- * @return {boolean} True if any widget area is currently being saved. False otherwise.
148
- */
149
- const isSavingWidgetAreas = exports.isSavingWidgetAreas = (0, _data.createRegistrySelector)(select => () => {
150
- const widgetAreasIds = select(_constants.STORE_NAME).getWidgetAreas()?.map(({
151
- id
152
- }) => id);
158
+ );
159
+ const isSavingWidgetAreas = (0, import_data.createRegistrySelector)((select) => () => {
160
+ const widgetAreasIds = select(import_constants.STORE_NAME).getWidgetAreas()?.map(({ id }) => id);
153
161
  if (!widgetAreasIds) {
154
162
  return false;
155
163
  }
156
164
  for (const id of widgetAreasIds) {
157
- const isSaving = select(_coreData.store).isSavingEntityRecord(_utils.KIND, _utils.WIDGET_AREA_ENTITY_TYPE, id);
165
+ const isSaving = select(import_core_data.store).isSavingEntityRecord(
166
+ import_utils.KIND,
167
+ import_utils.WIDGET_AREA_ENTITY_TYPE,
168
+ id
169
+ );
158
170
  if (isSaving) {
159
171
  return true;
160
172
  }
161
173
  }
162
- const widgetIds = [...Object.keys(select(_constants.STORE_NAME).getWidgets()), undefined // account for new widgets without an ID
174
+ const widgetIds = [
175
+ ...Object.keys(select(import_constants.STORE_NAME).getWidgets()),
176
+ void 0
177
+ // account for new widgets without an ID
163
178
  ];
164
179
  for (const id of widgetIds) {
165
- const isSaving = select(_coreData.store).isSavingEntityRecord('root', 'widget', id);
180
+ const isSaving = select(import_core_data.store).isSavingEntityRecord(
181
+ "root",
182
+ "widget",
183
+ id
184
+ );
166
185
  if (isSaving) {
167
186
  return true;
168
187
  }
169
188
  }
170
189
  return false;
171
190
  });
172
-
173
- /**
174
- * Gets whether the widget area is opened.
175
- *
176
- * @param {Array} state The open state of the widget areas.
177
- * @param {string} clientId The clientId of the widget area.
178
- *
179
- * @return {boolean} True if the widget area is open.
180
- */
181
191
  const getIsWidgetAreaOpen = (state, clientId) => {
182
- const {
183
- widgetAreasOpenState
184
- } = state;
192
+ const { widgetAreasOpenState } = state;
185
193
  return !!widgetAreasOpenState[clientId];
186
194
  };
187
-
188
- /**
189
- * Returns true if the inserter is opened.
190
- *
191
- * @param {Object} state Global application state.
192
- *
193
- * @return {boolean} Whether the inserter is opened.
194
- */
195
- exports.getIsWidgetAreaOpen = getIsWidgetAreaOpen;
196
195
  function isInserterOpened(state) {
197
196
  return !!state.blockInserterPanel;
198
197
  }
199
-
200
- /**
201
- * Get the insertion point for the inserter.
202
- *
203
- * @param {Object} state Global application state.
204
- *
205
- * @return {Object} The root client ID and index to insert at.
206
- */
207
198
  function __experimentalGetInsertionPoint(state) {
208
- if (typeof state.blockInserterPanel === 'boolean') {
199
+ if (typeof state.blockInserterPanel === "boolean") {
209
200
  return EMPTY_INSERTION_POINT;
210
201
  }
211
202
  return state.blockInserterPanel;
212
203
  }
213
-
214
- /**
215
- * Returns true if a block can be inserted into a widget area.
216
- *
217
- * @param {Array} state The open state of the widget areas.
218
- * @param {string} blockName The name of the block being inserted.
219
- *
220
- * @return {boolean} True if the block can be inserted in a widget area.
221
- */
222
- const canInsertBlockInWidgetArea = exports.canInsertBlockInWidgetArea = (0, _data.createRegistrySelector)(select => (state, blockName) => {
223
- // Widget areas are always top-level blocks, which getBlocks will return.
224
- const widgetAreas = select(_blockEditor.store).getBlocks();
225
-
226
- // Makes an assumption that a block that can be inserted into one
227
- // widget area can be inserted into any widget area. Uses the first
228
- // widget area for testing whether the block can be inserted.
229
- const [firstWidgetArea] = widgetAreas;
230
- return select(_blockEditor.store).canInsertBlockType(blockName, firstWidgetArea.clientId);
231
- });
232
-
233
- /**
234
- * Returns true if the list view is opened.
235
- *
236
- * @param {Object} state Global application state.
237
- *
238
- * @return {boolean} Whether the list view is opened.
239
- */
204
+ const canInsertBlockInWidgetArea = (0, import_data.createRegistrySelector)(
205
+ (select) => (state, blockName) => {
206
+ const widgetAreas = select(import_block_editor.store).getBlocks();
207
+ const [firstWidgetArea] = widgetAreas;
208
+ return select(import_block_editor.store).canInsertBlockType(
209
+ blockName,
210
+ firstWidgetArea.clientId
211
+ );
212
+ }
213
+ );
240
214
  function isListViewOpened(state) {
241
215
  return state.listViewPanel;
242
216
  }
243
-
244
- /**
245
- * Returns whether widget saving is locked.
246
- *
247
- * @param {Object} state Global application state.
248
- *
249
- * @example
250
- * ```jsx
251
- * import { __ } from '@wordpress/i18n';
252
- * import { store as widgetStore } from '@wordpress/edit-widgets';
253
- * import { useSelect } from '@wordpress/data';
254
- *
255
- * const ExampleComponent = () => {
256
- * const isSavingLocked = useSelect(
257
- * ( select ) => select( widgetStore ).isWidgetSavingLocked(),
258
- * []
259
- * );
260
- *
261
- * return isSavingLocked ? (
262
- * <p>{ __( 'Widget saving is locked' ) }</p>
263
- * ) : (
264
- * <p>{ __( 'Widget saving is not locked' ) }</p>
265
- * );
266
- * };
267
- * ```
268
- *
269
- * @return {boolean} Is locked.
270
- */
271
217
  function isWidgetSavingLocked(state) {
272
218
  return Object.keys(state.widgetSavingLock).length > 0;
273
219
  }
274
- //# sourceMappingURL=selectors.js.map
220
+ // Annotate the CommonJS export names for ESM import in node:
221
+ 0 && (module.exports = {
222
+ __experimentalGetInsertionPoint,
223
+ canInsertBlockInWidgetArea,
224
+ getEditedWidgetAreas,
225
+ getIsWidgetAreaOpen,
226
+ getParentWidgetAreaBlock,
227
+ getReferenceWidgetBlocks,
228
+ getWidget,
229
+ getWidgetAreaForWidgetId,
230
+ getWidgetAreas,
231
+ getWidgets,
232
+ isInserterOpened,
233
+ isListViewOpened,
234
+ isSavingWidgetAreas,
235
+ isWidgetSavingLocked
236
+ });
237
+ //# sourceMappingURL=selectors.js.map