@wordpress/edit-widgets 6.32.0 → 6.32.1-next.ff1cebbba.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,261 +1,208 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { createSelector, createRegistrySelector } from '@wordpress/data';
5
- import { getWidgetIdFromBlock } from '@wordpress/widgets';
6
- import { store as coreStore } from '@wordpress/core-data';
7
- import { store as blockEditorStore } from '@wordpress/block-editor';
8
-
9
- /**
10
- * Internal dependencies
11
- */
12
- import { buildWidgetsQuery, buildWidgetAreasQuery, buildWidgetAreaPostId, KIND, POST_TYPE, WIDGET_AREA_ENTITY_TYPE } from './utils';
13
- import { STORE_NAME as editWidgetsStoreName } from './constants';
1
+ import { createSelector, createRegistrySelector } from "@wordpress/data";
2
+ import { getWidgetIdFromBlock } from "@wordpress/widgets";
3
+ import { store as coreStore } from "@wordpress/core-data";
4
+ import { store as blockEditorStore } from "@wordpress/block-editor";
5
+ import {
6
+ buildWidgetsQuery,
7
+ buildWidgetAreasQuery,
8
+ buildWidgetAreaPostId,
9
+ KIND,
10
+ POST_TYPE,
11
+ WIDGET_AREA_ENTITY_TYPE
12
+ } from "./utils";
13
+ import { STORE_NAME as editWidgetsStoreName } from "./constants";
14
14
  const EMPTY_INSERTION_POINT = {
15
- rootClientId: undefined,
16
- insertionIndex: undefined
15
+ rootClientId: void 0,
16
+ insertionIndex: void 0
17
17
  };
18
-
19
- /**
20
- * Returns all API widgets.
21
- *
22
- * @return {Object[]} API List of widgets.
23
- */
24
- export const getWidgets = createRegistrySelector(select => createSelector(() => {
25
- var _widgets$reduce;
26
- const widgets = select(coreStore).getEntityRecords('root', 'widget', buildWidgetsQuery());
27
- return (// Key widgets by their ID.
28
- (_widgets$reduce = widgets?.reduce((allWidgets, widget) => ({
29
- ...allWidgets,
30
- [widget.id]: widget
31
- }), {})) !== null && _widgets$reduce !== void 0 ? _widgets$reduce : {}
32
- );
33
- }, () => [select(coreStore).getEntityRecords('root', 'widget', buildWidgetsQuery())]));
34
-
35
- /**
36
- * Returns API widget data for a particular widget ID.
37
- *
38
- * @param {number} id Widget ID.
39
- *
40
- * @return {Object} API widget data for a particular widget ID.
41
- */
42
- export const getWidget = createRegistrySelector(select => (state, id) => {
43
- const widgets = select(editWidgetsStoreName).getWidgets();
44
- return widgets[id];
45
- });
46
-
47
- /**
48
- * Returns all API widget areas.
49
- *
50
- * @return {Object[]} API List of widget areas.
51
- */
52
- export const getWidgetAreas = createRegistrySelector(select => () => {
18
+ const getWidgets = createRegistrySelector(
19
+ (select) => createSelector(
20
+ () => {
21
+ const widgets = select(coreStore).getEntityRecords(
22
+ "root",
23
+ "widget",
24
+ buildWidgetsQuery()
25
+ );
26
+ return (
27
+ // Key widgets by their ID.
28
+ widgets?.reduce(
29
+ (allWidgets, widget) => ({
30
+ ...allWidgets,
31
+ [widget.id]: widget
32
+ }),
33
+ {}
34
+ ) ?? {}
35
+ );
36
+ },
37
+ () => [
38
+ select(coreStore).getEntityRecords(
39
+ "root",
40
+ "widget",
41
+ buildWidgetsQuery()
42
+ )
43
+ ]
44
+ )
45
+ );
46
+ const getWidget = createRegistrySelector(
47
+ (select) => (state, id) => {
48
+ const widgets = select(editWidgetsStoreName).getWidgets();
49
+ return widgets[id];
50
+ }
51
+ );
52
+ const getWidgetAreas = createRegistrySelector((select) => () => {
53
53
  const query = buildWidgetAreasQuery();
54
- return select(coreStore).getEntityRecords(KIND, WIDGET_AREA_ENTITY_TYPE, query);
55
- });
56
-
57
- /**
58
- * Returns widgetArea containing a block identify by given widgetId
59
- *
60
- * @param {string} widgetId The ID of the widget.
61
- * @return {Object} Containing widget area.
62
- */
63
- export const getWidgetAreaForWidgetId = createRegistrySelector(select => (state, widgetId) => {
64
- const widgetAreas = select(editWidgetsStoreName).getWidgetAreas();
65
- return widgetAreas.find(widgetArea => {
66
- const post = select(coreStore).getEditedEntityRecord(KIND, POST_TYPE, buildWidgetAreaPostId(widgetArea.id));
67
- const blockWidgetIds = post.blocks.map(block => getWidgetIdFromBlock(block));
68
- return blockWidgetIds.includes(widgetId);
69
- });
70
- });
71
-
72
- /**
73
- * Given a child client id, returns the parent widget area block.
74
- *
75
- * @param {string} clientId The client id of a block in a widget area.
76
- *
77
- * @return {WPBlock} The widget area block.
78
- */
79
- export const getParentWidgetAreaBlock = createRegistrySelector(select => (state, clientId) => {
80
- const {
81
- getBlock,
82
- getBlockName,
83
- getBlockParents
84
- } = select(blockEditorStore);
85
- const blockParents = getBlockParents(clientId);
86
- const widgetAreaClientId = blockParents.find(parentClientId => getBlockName(parentClientId) === 'core/widget-area');
87
- return getBlock(widgetAreaClientId);
54
+ return select(coreStore).getEntityRecords(
55
+ KIND,
56
+ WIDGET_AREA_ENTITY_TYPE,
57
+ query
58
+ );
88
59
  });
89
-
90
- /**
91
- * Returns all edited widget area entity records.
92
- *
93
- * @return {Object[]} List of edited widget area entity records.
94
- */
95
- export const getEditedWidgetAreas = createRegistrySelector(select => (state, ids) => {
96
- let widgetAreas = select(editWidgetsStoreName).getWidgetAreas();
97
- if (!widgetAreas) {
98
- return [];
60
+ const getWidgetAreaForWidgetId = createRegistrySelector(
61
+ (select) => (state, widgetId) => {
62
+ const widgetAreas = select(editWidgetsStoreName).getWidgetAreas();
63
+ return widgetAreas.find((widgetArea) => {
64
+ const post = select(coreStore).getEditedEntityRecord(
65
+ KIND,
66
+ POST_TYPE,
67
+ buildWidgetAreaPostId(widgetArea.id)
68
+ );
69
+ const blockWidgetIds = post.blocks.map(
70
+ (block) => getWidgetIdFromBlock(block)
71
+ );
72
+ return blockWidgetIds.includes(widgetId);
73
+ });
99
74
  }
100
- if (ids) {
101
- widgetAreas = widgetAreas.filter(({
102
- id
103
- }) => ids.includes(id));
75
+ );
76
+ const getParentWidgetAreaBlock = createRegistrySelector(
77
+ (select) => (state, clientId) => {
78
+ const { getBlock, getBlockName, getBlockParents } = select(blockEditorStore);
79
+ const blockParents = getBlockParents(clientId);
80
+ const widgetAreaClientId = blockParents.find(
81
+ (parentClientId) => getBlockName(parentClientId) === "core/widget-area"
82
+ );
83
+ return getBlock(widgetAreaClientId);
104
84
  }
105
- return widgetAreas.filter(({
106
- id
107
- }) => select(coreStore).hasEditsForEntityRecord(KIND, POST_TYPE, buildWidgetAreaPostId(id))).map(({
108
- id
109
- }) => select(coreStore).getEditedEntityRecord(KIND, WIDGET_AREA_ENTITY_TYPE, id));
110
- });
111
-
112
- /**
113
- * Returns all blocks representing reference widgets.
114
- *
115
- * @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.
116
- * @return {Array} List of all blocks representing reference widgets
117
- */
118
- export const getReferenceWidgetBlocks = createRegistrySelector(select => (state, referenceWidgetName = null) => {
119
- const results = [];
120
- const widgetAreas = select(editWidgetsStoreName).getWidgetAreas();
121
- for (const _widgetArea of widgetAreas) {
122
- const post = select(coreStore).getEditedEntityRecord(KIND, POST_TYPE, buildWidgetAreaPostId(_widgetArea.id));
123
- for (const block of post.blocks) {
124
- if (block.name === 'core/legacy-widget' && (!referenceWidgetName || block.attributes?.referenceWidgetName === referenceWidgetName)) {
125
- results.push(block);
85
+ );
86
+ const getEditedWidgetAreas = createRegistrySelector(
87
+ (select) => (state, ids) => {
88
+ let widgetAreas = select(editWidgetsStoreName).getWidgetAreas();
89
+ if (!widgetAreas) {
90
+ return [];
91
+ }
92
+ if (ids) {
93
+ widgetAreas = widgetAreas.filter(
94
+ ({ id }) => ids.includes(id)
95
+ );
96
+ }
97
+ return widgetAreas.filter(
98
+ ({ id }) => select(coreStore).hasEditsForEntityRecord(
99
+ KIND,
100
+ POST_TYPE,
101
+ buildWidgetAreaPostId(id)
102
+ )
103
+ ).map(
104
+ ({ id }) => select(coreStore).getEditedEntityRecord(
105
+ KIND,
106
+ WIDGET_AREA_ENTITY_TYPE,
107
+ id
108
+ )
109
+ );
110
+ }
111
+ );
112
+ const getReferenceWidgetBlocks = createRegistrySelector(
113
+ (select) => (state, referenceWidgetName = null) => {
114
+ const results = [];
115
+ const widgetAreas = select(editWidgetsStoreName).getWidgetAreas();
116
+ for (const _widgetArea of widgetAreas) {
117
+ const post = select(coreStore).getEditedEntityRecord(
118
+ KIND,
119
+ POST_TYPE,
120
+ buildWidgetAreaPostId(_widgetArea.id)
121
+ );
122
+ for (const block of post.blocks) {
123
+ if (block.name === "core/legacy-widget" && (!referenceWidgetName || block.attributes?.referenceWidgetName === referenceWidgetName)) {
124
+ results.push(block);
125
+ }
126
126
  }
127
127
  }
128
+ return results;
128
129
  }
129
- return results;
130
- });
131
-
132
- /**
133
- * Returns true if any widget area is currently being saved.
134
- *
135
- * @return {boolean} True if any widget area is currently being saved. False otherwise.
136
- */
137
- export const isSavingWidgetAreas = createRegistrySelector(select => () => {
138
- const widgetAreasIds = select(editWidgetsStoreName).getWidgetAreas()?.map(({
139
- id
140
- }) => id);
130
+ );
131
+ const isSavingWidgetAreas = createRegistrySelector((select) => () => {
132
+ const widgetAreasIds = select(editWidgetsStoreName).getWidgetAreas()?.map(({ id }) => id);
141
133
  if (!widgetAreasIds) {
142
134
  return false;
143
135
  }
144
136
  for (const id of widgetAreasIds) {
145
- const isSaving = select(coreStore).isSavingEntityRecord(KIND, WIDGET_AREA_ENTITY_TYPE, id);
137
+ const isSaving = select(coreStore).isSavingEntityRecord(
138
+ KIND,
139
+ WIDGET_AREA_ENTITY_TYPE,
140
+ id
141
+ );
146
142
  if (isSaving) {
147
143
  return true;
148
144
  }
149
145
  }
150
- const widgetIds = [...Object.keys(select(editWidgetsStoreName).getWidgets()), undefined // account for new widgets without an ID
146
+ const widgetIds = [
147
+ ...Object.keys(select(editWidgetsStoreName).getWidgets()),
148
+ void 0
149
+ // account for new widgets without an ID
151
150
  ];
152
151
  for (const id of widgetIds) {
153
- const isSaving = select(coreStore).isSavingEntityRecord('root', 'widget', id);
152
+ const isSaving = select(coreStore).isSavingEntityRecord(
153
+ "root",
154
+ "widget",
155
+ id
156
+ );
154
157
  if (isSaving) {
155
158
  return true;
156
159
  }
157
160
  }
158
161
  return false;
159
162
  });
160
-
161
- /**
162
- * Gets whether the widget area is opened.
163
- *
164
- * @param {Array} state The open state of the widget areas.
165
- * @param {string} clientId The clientId of the widget area.
166
- *
167
- * @return {boolean} True if the widget area is open.
168
- */
169
- export const getIsWidgetAreaOpen = (state, clientId) => {
170
- const {
171
- widgetAreasOpenState
172
- } = state;
163
+ const getIsWidgetAreaOpen = (state, clientId) => {
164
+ const { widgetAreasOpenState } = state;
173
165
  return !!widgetAreasOpenState[clientId];
174
166
  };
175
-
176
- /**
177
- * Returns true if the inserter is opened.
178
- *
179
- * @param {Object} state Global application state.
180
- *
181
- * @return {boolean} Whether the inserter is opened.
182
- */
183
- export function isInserterOpened(state) {
167
+ function isInserterOpened(state) {
184
168
  return !!state.blockInserterPanel;
185
169
  }
186
-
187
- /**
188
- * Get the insertion point for the inserter.
189
- *
190
- * @param {Object} state Global application state.
191
- *
192
- * @return {Object} The root client ID and index to insert at.
193
- */
194
- export function __experimentalGetInsertionPoint(state) {
195
- if (typeof state.blockInserterPanel === 'boolean') {
170
+ function __experimentalGetInsertionPoint(state) {
171
+ if (typeof state.blockInserterPanel === "boolean") {
196
172
  return EMPTY_INSERTION_POINT;
197
173
  }
198
174
  return state.blockInserterPanel;
199
175
  }
200
-
201
- /**
202
- * Returns true if a block can be inserted into a widget area.
203
- *
204
- * @param {Array} state The open state of the widget areas.
205
- * @param {string} blockName The name of the block being inserted.
206
- *
207
- * @return {boolean} True if the block can be inserted in a widget area.
208
- */
209
- export const canInsertBlockInWidgetArea = createRegistrySelector(select => (state, blockName) => {
210
- // Widget areas are always top-level blocks, which getBlocks will return.
211
- const widgetAreas = select(blockEditorStore).getBlocks();
212
-
213
- // Makes an assumption that a block that can be inserted into one
214
- // widget area can be inserted into any widget area. Uses the first
215
- // widget area for testing whether the block can be inserted.
216
- const [firstWidgetArea] = widgetAreas;
217
- return select(blockEditorStore).canInsertBlockType(blockName, firstWidgetArea.clientId);
218
- });
219
-
220
- /**
221
- * Returns true if the list view is opened.
222
- *
223
- * @param {Object} state Global application state.
224
- *
225
- * @return {boolean} Whether the list view is opened.
226
- */
227
- export function isListViewOpened(state) {
176
+ const canInsertBlockInWidgetArea = createRegistrySelector(
177
+ (select) => (state, blockName) => {
178
+ const widgetAreas = select(blockEditorStore).getBlocks();
179
+ const [firstWidgetArea] = widgetAreas;
180
+ return select(blockEditorStore).canInsertBlockType(
181
+ blockName,
182
+ firstWidgetArea.clientId
183
+ );
184
+ }
185
+ );
186
+ function isListViewOpened(state) {
228
187
  return state.listViewPanel;
229
188
  }
230
-
231
- /**
232
- * Returns whether widget saving is locked.
233
- *
234
- * @param {Object} state Global application state.
235
- *
236
- * @example
237
- * ```jsx
238
- * import { __ } from '@wordpress/i18n';
239
- * import { store as widgetStore } from '@wordpress/edit-widgets';
240
- * import { useSelect } from '@wordpress/data';
241
- *
242
- * const ExampleComponent = () => {
243
- * const isSavingLocked = useSelect(
244
- * ( select ) => select( widgetStore ).isWidgetSavingLocked(),
245
- * []
246
- * );
247
- *
248
- * return isSavingLocked ? (
249
- * <p>{ __( 'Widget saving is locked' ) }</p>
250
- * ) : (
251
- * <p>{ __( 'Widget saving is not locked' ) }</p>
252
- * );
253
- * };
254
- * ```
255
- *
256
- * @return {boolean} Is locked.
257
- */
258
- export function isWidgetSavingLocked(state) {
189
+ function isWidgetSavingLocked(state) {
259
190
  return Object.keys(state.widgetSavingLock).length > 0;
260
191
  }
261
- //# sourceMappingURL=selectors.js.map
192
+ export {
193
+ __experimentalGetInsertionPoint,
194
+ canInsertBlockInWidgetArea,
195
+ getEditedWidgetAreas,
196
+ getIsWidgetAreaOpen,
197
+ getParentWidgetAreaBlock,
198
+ getReferenceWidgetBlocks,
199
+ getWidget,
200
+ getWidgetAreaForWidgetId,
201
+ getWidgetAreas,
202
+ getWidgets,
203
+ isInserterOpened,
204
+ isListViewOpened,
205
+ isSavingWidgetAreas,
206
+ isWidgetSavingLocked
207
+ };
208
+ //# sourceMappingURL=selectors.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["createSelector","createRegistrySelector","getWidgetIdFromBlock","store","coreStore","blockEditorStore","buildWidgetsQuery","buildWidgetAreasQuery","buildWidgetAreaPostId","KIND","POST_TYPE","WIDGET_AREA_ENTITY_TYPE","STORE_NAME","editWidgetsStoreName","EMPTY_INSERTION_POINT","rootClientId","undefined","insertionIndex","getWidgets","select","_widgets$reduce","widgets","getEntityRecords","reduce","allWidgets","widget","id","getWidget","state","getWidgetAreas","query","getWidgetAreaForWidgetId","widgetId","widgetAreas","find","widgetArea","post","getEditedEntityRecord","blockWidgetIds","blocks","map","block","includes","getParentWidgetAreaBlock","clientId","getBlock","getBlockName","getBlockParents","blockParents","widgetAreaClientId","parentClientId","getEditedWidgetAreas","ids","filter","hasEditsForEntityRecord","getReferenceWidgetBlocks","referenceWidgetName","results","_widgetArea","name","attributes","push","isSavingWidgetAreas","widgetAreasIds","isSaving","isSavingEntityRecord","widgetIds","Object","keys","getIsWidgetAreaOpen","widgetAreasOpenState","isInserterOpened","blockInserterPanel","__experimentalGetInsertionPoint","canInsertBlockInWidgetArea","blockName","getBlocks","firstWidgetArea","canInsertBlockType","isListViewOpened","listViewPanel","isWidgetSavingLocked","widgetSavingLock","length"],"sources":["@wordpress/edit-widgets/src/store/selectors.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport {\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\nconst EMPTY_INSERTION_POINT = {\n\trootClientId: undefined,\n\tinsertionIndex: undefined,\n};\n\n/**\n * Returns all API widgets.\n *\n * @return {Object[]} API List of widgets.\n */\nexport const getWidgets = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst widgets = select( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t// Key widgets by their ID.\n\t\t\t\twidgets?.reduce(\n\t\t\t\t\t( allWidgets, widget ) => ( {\n\t\t\t\t\t\t...allWidgets,\n\t\t\t\t\t\t[ widget.id ]: widget,\n\t\t\t\t\t} ),\n\t\t\t\t\t{}\n\t\t\t\t) ?? {}\n\t\t\t);\n\t\t},\n\t\t() => [\n\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t),\n\t\t]\n\t)\n);\n\n/**\n * Returns API widget data for a particular widget ID.\n *\n * @param {number} id Widget ID.\n *\n * @return {Object} API widget data for a particular widget ID.\n */\nexport const getWidget = createRegistrySelector(\n\t( select ) => ( state, id ) => {\n\t\tconst widgets = select( editWidgetsStoreName ).getWidgets();\n\t\treturn widgets[ id ];\n\t}\n);\n\n/**\n * Returns all API widget areas.\n *\n * @return {Object[]} API List of widget areas.\n */\nexport const getWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst query = buildWidgetAreasQuery();\n\treturn select( coreStore ).getEntityRecords(\n\t\tKIND,\n\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\tquery\n\t);\n} );\n\n/**\n * Returns widgetArea containing a block identify by given widgetId\n *\n * @param {string} widgetId The ID of the widget.\n * @return {Object} Containing widget area.\n */\nexport const getWidgetAreaForWidgetId = createRegistrySelector(\n\t( select ) => ( state, widgetId ) => {\n\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\treturn widgetAreas.find( ( widgetArea ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetArea.id )\n\t\t\t);\n\t\t\tconst blockWidgetIds = post.blocks.map( ( block ) =>\n\t\t\t\tgetWidgetIdFromBlock( block )\n\t\t\t);\n\t\t\treturn blockWidgetIds.includes( widgetId );\n\t\t} );\n\t}\n);\n\n/**\n * Given a child client id, returns the parent widget area block.\n *\n * @param {string} clientId The client id of a block in a widget area.\n *\n * @return {WPBlock} The widget area block.\n */\nexport const getParentWidgetAreaBlock = createRegistrySelector(\n\t( select ) => ( state, clientId ) => {\n\t\tconst { getBlock, getBlockName, getBlockParents } =\n\t\t\tselect( blockEditorStore );\n\t\tconst blockParents = getBlockParents( clientId );\n\t\tconst widgetAreaClientId = blockParents.find(\n\t\t\t( parentClientId ) =>\n\t\t\t\tgetBlockName( parentClientId ) === 'core/widget-area'\n\t\t);\n\t\treturn getBlock( widgetAreaClientId );\n\t}\n);\n\n/**\n * Returns all edited widget area entity records.\n *\n * @return {Object[]} List of edited widget area entity records.\n */\nexport const getEditedWidgetAreas = createRegistrySelector(\n\t( select ) => ( state, ids ) => {\n\t\tlet widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\tif ( ! widgetAreas ) {\n\t\t\treturn [];\n\t\t}\n\t\tif ( ids ) {\n\t\t\twidgetAreas = widgetAreas.filter( ( { id } ) =>\n\t\t\t\tids.includes( id )\n\t\t\t);\n\t\t}\n\t\treturn widgetAreas\n\t\t\t.filter( ( { id } ) =>\n\t\t\t\tselect( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( id )\n\t\t\t\t)\n\t\t\t)\n\t\t\t.map( ( { id } ) =>\n\t\t\t\tselect( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tid\n\t\t\t\t)\n\t\t\t);\n\t}\n);\n\n/**\n * Returns all blocks representing reference widgets.\n *\n * @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.\n * @return {Array} List of all blocks representing reference widgets\n */\nexport const getReferenceWidgetBlocks = createRegistrySelector(\n\t( select ) =>\n\t\t( state, referenceWidgetName = null ) => {\n\t\t\tconst results = [];\n\t\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\t\tfor ( const _widgetArea of widgetAreas ) {\n\t\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( _widgetArea.id )\n\t\t\t\t);\n\t\t\t\tfor ( const block of post.blocks ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tblock.name === 'core/legacy-widget' &&\n\t\t\t\t\t\t( ! referenceWidgetName ||\n\t\t\t\t\t\t\tblock.attributes?.referenceWidgetName ===\n\t\t\t\t\t\t\t\treferenceWidgetName )\n\t\t\t\t\t) {\n\t\t\t\t\t\tresults.push( block );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n);\n\n/**\n * Returns true if any widget area is currently being saved.\n *\n * @return {boolean} True if any widget area is currently being saved. False otherwise.\n */\nexport const isSavingWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst widgetAreasIds = select( editWidgetsStoreName )\n\t\t.getWidgetAreas()\n\t\t?.map( ( { id } ) => id );\n\tif ( ! widgetAreasIds ) {\n\t\treturn false;\n\t}\n\n\tfor ( const id of widgetAreasIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tconst widgetIds = [\n\t\t...Object.keys( select( editWidgetsStoreName ).getWidgets() ),\n\t\tundefined, // account for new widgets without an ID\n\t];\n\tfor ( const id of widgetIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\t'root',\n\t\t\t'widget',\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n} );\n\n/**\n * Gets whether the widget area is opened.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} clientId The clientId of the widget area.\n *\n * @return {boolean} True if the widget area is open.\n */\nexport const getIsWidgetAreaOpen = ( state, clientId ) => {\n\tconst { widgetAreasOpenState } = state;\n\treturn !! widgetAreasOpenState[ clientId ];\n};\n\n/**\n * Returns true if the inserter is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the inserter is opened.\n */\nexport function isInserterOpened( state ) {\n\treturn !! state.blockInserterPanel;\n}\n\n/**\n * Get the insertion point for the inserter.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} The root client ID and index to insert at.\n */\nexport function __experimentalGetInsertionPoint( state ) {\n\tif ( typeof state.blockInserterPanel === 'boolean' ) {\n\t\treturn EMPTY_INSERTION_POINT;\n\t}\n\n\treturn state.blockInserterPanel;\n}\n\n/**\n * Returns true if a block can be inserted into a widget area.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} blockName The name of the block being inserted.\n *\n * @return {boolean} True if the block can be inserted in a widget area.\n */\nexport const canInsertBlockInWidgetArea = createRegistrySelector(\n\t( select ) => ( state, blockName ) => {\n\t\t// Widget areas are always top-level blocks, which getBlocks will return.\n\t\tconst widgetAreas = select( blockEditorStore ).getBlocks();\n\n\t\t// Makes an assumption that a block that can be inserted into one\n\t\t// widget area can be inserted into any widget area. Uses the first\n\t\t// widget area for testing whether the block can be inserted.\n\t\tconst [ firstWidgetArea ] = widgetAreas;\n\t\treturn select( blockEditorStore ).canInsertBlockType(\n\t\t\tblockName,\n\t\t\tfirstWidgetArea.clientId\n\t\t);\n\t}\n);\n\n/**\n * Returns true if the list view is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the list view is opened.\n */\nexport function isListViewOpened( state ) {\n\treturn state.listViewPanel;\n}\n\n/**\n * Returns whether widget saving is locked.\n *\n * @param {Object} state Global application state.\n *\n * @example\n * ```jsx\n * import { __ } from '@wordpress/i18n';\n * import { store as widgetStore } from '@wordpress/edit-widgets';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * \tconst isSavingLocked = useSelect(\n * \t\t( select ) => select( widgetStore ).isWidgetSavingLocked(),\n * \t\t[]\n * \t);\n *\n * \treturn isSavingLocked ? (\n * \t\t<p>{ __( 'Widget saving is locked' ) }</p>\n * \t) : (\n * \t\t<p>{ __( 'Widget saving is not locked' ) }</p>\n * \t);\n * };\n * ```\n *\n * @return {boolean} Is locked.\n */\nexport function isWidgetSavingLocked( state ) {\n\treturn Object.keys( state.widgetSavingLock ).length > 0;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAc,EAAEC,sBAAsB,QAAQ,iBAAiB;AACxE,SAASC,oBAAoB,QAAQ,oBAAoB;AACzD,SAASC,KAAK,IAAIC,SAAS,QA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;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAAErD,KAAK,EAAG;EAC7C,OAAOuC,MAAM,CAACC,IAAI,CAAExC,KAAK,CAACsD,gBAAiB,CAAC,CAACC,MAAM,GAAG,CAAC;AACxD","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/store/selectors.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport {\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\nconst EMPTY_INSERTION_POINT = {\n\trootClientId: undefined,\n\tinsertionIndex: undefined,\n};\n\n/**\n * Returns all API widgets.\n *\n * @return {Object[]} API List of widgets.\n */\nexport const getWidgets = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst widgets = select( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t// Key widgets by their ID.\n\t\t\t\twidgets?.reduce(\n\t\t\t\t\t( allWidgets, widget ) => ( {\n\t\t\t\t\t\t...allWidgets,\n\t\t\t\t\t\t[ widget.id ]: widget,\n\t\t\t\t\t} ),\n\t\t\t\t\t{}\n\t\t\t\t) ?? {}\n\t\t\t);\n\t\t},\n\t\t() => [\n\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t),\n\t\t]\n\t)\n);\n\n/**\n * Returns API widget data for a particular widget ID.\n *\n * @param {number} id Widget ID.\n *\n * @return {Object} API widget data for a particular widget ID.\n */\nexport const getWidget = createRegistrySelector(\n\t( select ) => ( state, id ) => {\n\t\tconst widgets = select( editWidgetsStoreName ).getWidgets();\n\t\treturn widgets[ id ];\n\t}\n);\n\n/**\n * Returns all API widget areas.\n *\n * @return {Object[]} API List of widget areas.\n */\nexport const getWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst query = buildWidgetAreasQuery();\n\treturn select( coreStore ).getEntityRecords(\n\t\tKIND,\n\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\tquery\n\t);\n} );\n\n/**\n * Returns widgetArea containing a block identify by given widgetId\n *\n * @param {string} widgetId The ID of the widget.\n * @return {Object} Containing widget area.\n */\nexport const getWidgetAreaForWidgetId = createRegistrySelector(\n\t( select ) => ( state, widgetId ) => {\n\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\treturn widgetAreas.find( ( widgetArea ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetArea.id )\n\t\t\t);\n\t\t\tconst blockWidgetIds = post.blocks.map( ( block ) =>\n\t\t\t\tgetWidgetIdFromBlock( block )\n\t\t\t);\n\t\t\treturn blockWidgetIds.includes( widgetId );\n\t\t} );\n\t}\n);\n\n/**\n * Given a child client id, returns the parent widget area block.\n *\n * @param {string} clientId The client id of a block in a widget area.\n *\n * @return {WPBlock} The widget area block.\n */\nexport const getParentWidgetAreaBlock = createRegistrySelector(\n\t( select ) => ( state, clientId ) => {\n\t\tconst { getBlock, getBlockName, getBlockParents } =\n\t\t\tselect( blockEditorStore );\n\t\tconst blockParents = getBlockParents( clientId );\n\t\tconst widgetAreaClientId = blockParents.find(\n\t\t\t( parentClientId ) =>\n\t\t\t\tgetBlockName( parentClientId ) === 'core/widget-area'\n\t\t);\n\t\treturn getBlock( widgetAreaClientId );\n\t}\n);\n\n/**\n * Returns all edited widget area entity records.\n *\n * @return {Object[]} List of edited widget area entity records.\n */\nexport const getEditedWidgetAreas = createRegistrySelector(\n\t( select ) => ( state, ids ) => {\n\t\tlet widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\tif ( ! widgetAreas ) {\n\t\t\treturn [];\n\t\t}\n\t\tif ( ids ) {\n\t\t\twidgetAreas = widgetAreas.filter( ( { id } ) =>\n\t\t\t\tids.includes( id )\n\t\t\t);\n\t\t}\n\t\treturn widgetAreas\n\t\t\t.filter( ( { id } ) =>\n\t\t\t\tselect( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( id )\n\t\t\t\t)\n\t\t\t)\n\t\t\t.map( ( { id } ) =>\n\t\t\t\tselect( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tid\n\t\t\t\t)\n\t\t\t);\n\t}\n);\n\n/**\n * Returns all blocks representing reference widgets.\n *\n * @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.\n * @return {Array} List of all blocks representing reference widgets\n */\nexport const getReferenceWidgetBlocks = createRegistrySelector(\n\t( select ) =>\n\t\t( state, referenceWidgetName = null ) => {\n\t\t\tconst results = [];\n\t\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\t\tfor ( const _widgetArea of widgetAreas ) {\n\t\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( _widgetArea.id )\n\t\t\t\t);\n\t\t\t\tfor ( const block of post.blocks ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tblock.name === 'core/legacy-widget' &&\n\t\t\t\t\t\t( ! referenceWidgetName ||\n\t\t\t\t\t\t\tblock.attributes?.referenceWidgetName ===\n\t\t\t\t\t\t\t\treferenceWidgetName )\n\t\t\t\t\t) {\n\t\t\t\t\t\tresults.push( block );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n);\n\n/**\n * Returns true if any widget area is currently being saved.\n *\n * @return {boolean} True if any widget area is currently being saved. False otherwise.\n */\nexport const isSavingWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst widgetAreasIds = select( editWidgetsStoreName )\n\t\t.getWidgetAreas()\n\t\t?.map( ( { id } ) => id );\n\tif ( ! widgetAreasIds ) {\n\t\treturn false;\n\t}\n\n\tfor ( const id of widgetAreasIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tconst widgetIds = [\n\t\t...Object.keys( select( editWidgetsStoreName ).getWidgets() ),\n\t\tundefined, // account for new widgets without an ID\n\t];\n\tfor ( const id of widgetIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\t'root',\n\t\t\t'widget',\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n} );\n\n/**\n * Gets whether the widget area is opened.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} clientId The clientId of the widget area.\n *\n * @return {boolean} True if the widget area is open.\n */\nexport const getIsWidgetAreaOpen = ( state, clientId ) => {\n\tconst { widgetAreasOpenState } = state;\n\treturn !! widgetAreasOpenState[ clientId ];\n};\n\n/**\n * Returns true if the inserter is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the inserter is opened.\n */\nexport function isInserterOpened( state ) {\n\treturn !! state.blockInserterPanel;\n}\n\n/**\n * Get the insertion point for the inserter.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} The root client ID and index to insert at.\n */\nexport function __experimentalGetInsertionPoint( state ) {\n\tif ( typeof state.blockInserterPanel === 'boolean' ) {\n\t\treturn EMPTY_INSERTION_POINT;\n\t}\n\n\treturn state.blockInserterPanel;\n}\n\n/**\n * Returns true if a block can be inserted into a widget area.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} blockName The name of the block being inserted.\n *\n * @return {boolean} True if the block can be inserted in a widget area.\n */\nexport const canInsertBlockInWidgetArea = createRegistrySelector(\n\t( select ) => ( state, blockName ) => {\n\t\t// Widget areas are always top-level blocks, which getBlocks will return.\n\t\tconst widgetAreas = select( blockEditorStore ).getBlocks();\n\n\t\t// Makes an assumption that a block that can be inserted into one\n\t\t// widget area can be inserted into any widget area. Uses the first\n\t\t// widget area for testing whether the block can be inserted.\n\t\tconst [ firstWidgetArea ] = widgetAreas;\n\t\treturn select( blockEditorStore ).canInsertBlockType(\n\t\t\tblockName,\n\t\t\tfirstWidgetArea.clientId\n\t\t);\n\t}\n);\n\n/**\n * Returns true if the list view is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the list view is opened.\n */\nexport function isListViewOpened( state ) {\n\treturn state.listViewPanel;\n}\n\n/**\n * Returns whether widget saving is locked.\n *\n * @param {Object} state Global application state.\n *\n * @example\n * ```jsx\n * import { __ } from '@wordpress/i18n';\n * import { store as widgetStore } from '@wordpress/edit-widgets';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * \tconst isSavingLocked = useSelect(\n * \t\t( select ) => select( widgetStore ).isWidgetSavingLocked(),\n * \t\t[]\n * \t);\n *\n * \treturn isSavingLocked ? (\n * \t\t<p>{ __( 'Widget saving is locked' ) }</p>\n * \t) : (\n * \t\t<p>{ __( 'Widget saving is not locked' ) }</p>\n * \t);\n * };\n * ```\n *\n * @return {boolean} Is locked.\n */\nexport function isWidgetSavingLocked( state ) {\n\treturn Object.keys( state.widgetSavingLock ).length > 0;\n}\n"],
5
+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AAY,CAAE,OAAO,cAAe;AAErC,UAAM,cAAc,OAAQ,gBAAiB,EAAE,UAAU;AAKzD,UAAM,CAAE,eAAgB,IAAI;AAC5B,WAAO,OAAQ,gBAAiB,EAAE;AAAA,MACjC;AAAA,MACA,gBAAgB;AAAA,IACjB;AAAA,EACD;AACD;AASO,SAAS,iBAAkB,OAAQ;AACzC,SAAO,MAAM;AACd;AA6BO,SAAS,qBAAsB,OAAQ;AAC7C,SAAO,OAAO,KAAM,MAAM,gBAAiB,EAAE,SAAS;AACvD;",
6
+ "names": []
7
+ }
@@ -1,22 +1,15 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { createBlock, parse, serialize } from '@wordpress/blocks';
5
- import { addWidgetIdToBlock } from '@wordpress/widgets';
6
-
7
- /**
8
- * Converts a widget entity record into a block.
9
- *
10
- * @param {Object} widget The widget entity record.
11
- * @return {Object} a block (converted from the entity record).
12
- */
13
- export function transformWidgetToBlock(widget) {
14
- if (widget.id_base === 'block') {
1
+ import { createBlock, parse, serialize } from "@wordpress/blocks";
2
+ import { addWidgetIdToBlock } from "@wordpress/widgets";
3
+ function transformWidgetToBlock(widget) {
4
+ if (widget.id_base === "block") {
15
5
  const parsedBlocks = parse(widget.instance.raw.content, {
16
6
  __unstableSkipAutop: true
17
7
  });
18
8
  if (!parsedBlocks.length) {
19
- return addWidgetIdToBlock(createBlock('core/paragraph', {}, []), widget.id);
9
+ return addWidgetIdToBlock(
10
+ createBlock("core/paragraph", {}, []),
11
+ widget.id
12
+ );
20
13
  }
21
14
  return addWidgetIdToBlock(parsedBlocks[0], widget.id);
22
15
  }
@@ -31,31 +24,25 @@ export function transformWidgetToBlock(widget) {
31
24
  id: widget.id
32
25
  };
33
26
  }
34
- return addWidgetIdToBlock(createBlock('core/legacy-widget', attributes, []), widget.id);
27
+ return addWidgetIdToBlock(
28
+ createBlock("core/legacy-widget", attributes, []),
29
+ widget.id
30
+ );
35
31
  }
36
-
37
- /**
38
- * Converts a block to a widget entity record.
39
- *
40
- * @param {Object} block The block.
41
- * @param {?Object} relatedWidget A related widget entity record from the API (optional).
42
- * @return {Object} the widget object (converted from block).
43
- */
44
- export function transformBlockToWidget(block, relatedWidget = {}) {
32
+ function transformBlockToWidget(block, relatedWidget = {}) {
45
33
  let widget;
46
- const isValidLegacyWidgetBlock = block.name === 'core/legacy-widget' && (block.attributes.id || block.attributes.instance);
34
+ const isValidLegacyWidgetBlock = block.name === "core/legacy-widget" && (block.attributes.id || block.attributes.instance);
47
35
  if (isValidLegacyWidgetBlock) {
48
- var _block$attributes$id, _block$attributes$idB, _block$attributes$ins;
49
36
  widget = {
50
37
  ...relatedWidget,
51
- id: (_block$attributes$id = block.attributes.id) !== null && _block$attributes$id !== void 0 ? _block$attributes$id : relatedWidget.id,
52
- id_base: (_block$attributes$idB = block.attributes.idBase) !== null && _block$attributes$idB !== void 0 ? _block$attributes$idB : relatedWidget.id_base,
53
- instance: (_block$attributes$ins = block.attributes.instance) !== null && _block$attributes$ins !== void 0 ? _block$attributes$ins : relatedWidget.instance
38
+ id: block.attributes.id ?? relatedWidget.id,
39
+ id_base: block.attributes.idBase ?? relatedWidget.id_base,
40
+ instance: block.attributes.instance ?? relatedWidget.instance
54
41
  };
55
42
  } else {
56
43
  widget = {
57
44
  ...relatedWidget,
58
- id_base: 'block',
45
+ id_base: "block",
59
46
  instance: {
60
47
  raw: {
61
48
  content: serialize(block)
@@ -63,10 +50,12 @@ export function transformBlockToWidget(block, relatedWidget = {}) {
63
50
  }
64
51
  };
65
52
  }
66
-
67
- // Delete read-only properties.
68
53
  delete widget.rendered;
69
54
  delete widget.rendered_form;
70
55
  return widget;
71
56
  }
72
- //# sourceMappingURL=transformers.js.map
57
+ export {
58
+ transformBlockToWidget,
59
+ transformWidgetToBlock
60
+ };
61
+ //# sourceMappingURL=transformers.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["createBlock","parse","serialize","addWidgetIdToBlock","transformWidgetToBlock","widget","id_base","parsedBlocks","instance","raw","content","__unstableSkipAutop","length","id","attributes","_embedded","about","is_multi","idBase","transformBlockToWidget","block","relatedWidget","isValidLegacyWidgetBlock","name","_block$attributes$id","_block$attributes$idB","_block$attributes$ins","rendered","rendered_form"],"sources":["@wordpress/edit-widgets/src/store/transformers.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createBlock, parse, serialize } from '@wordpress/blocks';\nimport { addWidgetIdToBlock } from '@wordpress/widgets';\n\n/**\n * Converts a widget entity record into a block.\n *\n * @param {Object} widget The widget entity record.\n * @return {Object} a block (converted from the entity record).\n */\nexport function transformWidgetToBlock( widget ) {\n\tif ( widget.id_base === 'block' ) {\n\t\tconst parsedBlocks = parse( widget.instance.raw.content, {\n\t\t\t__unstableSkipAutop: true,\n\t\t} );\n\t\tif ( ! parsedBlocks.length ) {\n\t\t\treturn addWidgetIdToBlock(\n\t\t\t\tcreateBlock( 'core/paragraph', {}, [] ),\n\t\t\t\twidget.id\n\t\t\t);\n\t\t}\n\t\treturn addWidgetIdToBlock( parsedBlocks[ 0 ], widget.id );\n\t}\n\n\tlet attributes;\n\tif ( widget._embedded.about[ 0 ].is_multi ) {\n\t\tattributes = {\n\t\t\tidBase: widget.id_base,\n\t\t\tinstance: widget.instance,\n\t\t};\n\t} else {\n\t\tattributes = {\n\t\t\tid: widget.id,\n\t\t};\n\t}\n\n\treturn addWidgetIdToBlock(\n\t\tcreateBlock( 'core/legacy-widget', attributes, [] ),\n\t\twidget.id\n\t);\n}\n\n/**\n * Converts a block to a widget entity record.\n *\n * @param {Object} block The block.\n * @param {?Object} relatedWidget A related widget entity record from the API (optional).\n * @return {Object} the widget object (converted from block).\n */\nexport function transformBlockToWidget( block, relatedWidget = {} ) {\n\tlet widget;\n\n\tconst isValidLegacyWidgetBlock =\n\t\tblock.name === 'core/legacy-widget' &&\n\t\t( block.attributes.id || block.attributes.instance );\n\n\tif ( isValidLegacyWidgetBlock ) {\n\t\twidget = {\n\t\t\t...relatedWidget,\n\t\t\tid: block.attributes.id ?? relatedWidget.id,\n\t\t\tid_base: block.attributes.idBase ?? relatedWidget.id_base,\n\t\t\tinstance: block.attributes.instance ?? relatedWidget.instance,\n\t\t};\n\t} else {\n\t\twidget = {\n\t\t\t...relatedWidget,\n\t\t\tid_base: 'block',\n\t\t\tinstance: {\n\t\t\t\traw: {\n\t\t\t\t\tcontent: serialize( block ),\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\t// Delete read-only properties.\n\tdelete widget.rendered;\n\tdelete widget.rendered_form;\n\n\treturn widget;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,KAAK,EAAEC,SAAS,QAAQ,mBAAmB;AACjE,SAASC,kBAAkB,QAAQ,oBAAoB;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,sBAAsBA,CAAEC,MAAM,EAAG;EAChD,IAAKA,MAAM,CAACC,OAAO,KAAK,OAAO,EAAG;IACjC,MAAMC,YAAY,GAAGN,KAAK,CAAEI,MAAM,CAACG,QAAQ,CAACC,GAAG,CAACC,OAAO,EAAE;MACxDC,mBAAmB,EAAE;IACtB,CAAE,CAAC;IACH,IAAK,CAAEJ,YAAY,CAACK,MAAM,EAAG;MAC5B,OAAOT,kBAAkB,CACxBH,WAAW,CAAE,gBAAgB,EAAE,CAAC,CAAC,EAAE,EAAG,CAAC,EACvCK,MAAM,CAACQ,EACR,CAAC;IACF;IACA,OAAOV,kBAAkB,CAAEI,YAAY,CAAE,CAAC,CAAE,EAAEF,MAAM,CAACQ,EAAG,CAAC;EAC1D;EAEA,IAAIC,UAAU;EACd,IAAKT,MAAM,CAACU,SAAS,CAACC,KAAK,CAAE,CAAC,CAAE,CAACC,QAAQ,EAAG;IAC3CH,UAAU,GAAG;MACZI,MAAM,EAAEb,MAAM,CAACC,OAAO;MACtBE,QAAQ,EAAEH,MAAM,CAACG;IAClB,CAAC;EACF,CAAC,MAAM;IACNM,UAAU,GAAG;MACZD,EAAE,EAAER,MAAM,CA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ources": ["../../src/store/transformers.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createBlock, parse, serialize } from '@wordpress/blocks';\nimport { addWidgetIdToBlock } from '@wordpress/widgets';\n\n/**\n * Converts a widget entity record into a block.\n *\n * @param {Object} widget The widget entity record.\n * @return {Object} a block (converted from the entity record).\n */\nexport function transformWidgetToBlock( widget ) {\n\tif ( widget.id_base === 'block' ) {\n\t\tconst parsedBlocks = parse( widget.instance.raw.content, {\n\t\t\t__unstableSkipAutop: true,\n\t\t} );\n\t\tif ( ! parsedBlocks.length ) {\n\t\t\treturn addWidgetIdToBlock(\n\t\t\t\tcreateBlock( 'core/paragraph', {}, [] ),\n\t\t\t\twidget.id\n\t\t\t);\n\t\t}\n\t\treturn addWidgetIdToBlock( parsedBlocks[ 0 ], widget.id );\n\t}\n\n\tlet attributes;\n\tif ( widget._embedded.about[ 0 ].is_multi ) {\n\t\tattributes = {\n\t\t\tidBase: widget.id_base,\n\t\t\tinstance: widget.instance,\n\t\t};\n\t} else {\n\t\tattributes = {\n\t\t\tid: widget.id,\n\t\t};\n\t}\n\n\treturn addWidgetIdToBlock(\n\t\tcreateBlock( 'core/legacy-widget', attributes, [] ),\n\t\twidget.id\n\t);\n}\n\n/**\n * Converts a block to a widget entity record.\n *\n * @param {Object} block The block.\n * @param {?Object} relatedWidget A related widget entity record from the API (optional).\n * @return {Object} the widget object (converted from block).\n */\nexport function transformBlockToWidget( block, relatedWidget = {} ) {\n\tlet widget;\n\n\tconst isValidLegacyWidgetBlock =\n\t\tblock.name === 'core/legacy-widget' &&\n\t\t( block.attributes.id || block.attributes.instance );\n\n\tif ( isValidLegacyWidgetBlock ) {\n\t\twidget = {\n\t\t\t...relatedWidget,\n\t\t\tid: block.attributes.id ?? relatedWidget.id,\n\t\t\tid_base: block.attributes.idBase ?? relatedWidget.id_base,\n\t\t\tinstance: block.attributes.instance ?? relatedWidget.instance,\n\t\t};\n\t} else {\n\t\twidget = {\n\t\t\t...relatedWidget,\n\t\t\tid_base: 'block',\n\t\t\tinstance: {\n\t\t\t\traw: {\n\t\t\t\t\tcontent: serialize( block ),\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\t// Delete read-only properties.\n\tdelete widget.rendered;\n\tdelete widget.rendered_form;\n\n\treturn widget;\n}\n"],
5
+ "mappings": "AAGA,SAAS,aAAa,OAAO,iBAAiB;AAC9C,SAAS,0BAA0B;AAQ5B,SAAS,uBAAwB,QAAS;AAChD,MAAK,OAAO,YAAY,SAAU;AACjC,UAAM,eAAe,MAAO,OAAO,SAAS,IAAI,SAAS;AAAA,MACxD,qBAAqB;AAAA,IACtB,CAAE;AACF,QAAK,CAAE,aAAa,QAAS;AAC5B,aAAO;AAAA,QACN,YAAa,kBAAkB,CAAC,GAAG,CAAC,CAAE;AAAA,QACtC,OAAO;AAAA,MACR;AAAA,IACD;AACA,WAAO,mBAAoB,aAAc,CAAE,GAAG,OAAO,EAAG;AAAA,EACzD;AAEA,MAAI;AACJ,MAAK,OAAO,UAAU,MAAO,CAAE,EAAE,UAAW;AAC3C,iBAAa;AAAA,MACZ,QAAQ,OAAO;AAAA,MACf,UAAU,OAAO;AAAA,IAClB;AAAA,EACD,OAAO;AACN,iBAAa;AAAA,MACZ,IAAI,OAAO;AAAA,IACZ;AAAA,EACD;AAEA,SAAO;AAAA,IACN,YAAa,sBAAsB,YAAY,CAAC,CAAE;AAAA,IAClD,OAAO;AAAA,EACR;AACD;AASO,SAAS,uBAAwB,OAAO,gBAAgB,CAAC,GAAI;AACnE,MAAI;AAEJ,QAAM,2BACL,MAAM,SAAS,yBACb,MAAM,WAAW,MAAM,MAAM,WAAW;AAE3C,MAAK,0BAA2B;AAC/B,aAAS;AAAA,MACR,GAAG;AAAA,MACH,IAAI,MAAM,WAAW,MAAM,cAAc;AAAA,MACzC,SAAS,MAAM,WAAW,UAAU,cAAc;AAAA,MAClD,UAAU,MAAM,WAAW,YAAY,cAAc;AAAA,IACtD;AAAA,EACD,OAAO;A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