@wordpress/edit-widgets 7.0.0 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/build/blocks/widget-area/edit/index.cjs +106 -116
  2. package/build/blocks/widget-area/edit/index.cjs.map +1 -7
  3. package/build/blocks/widget-area/edit/inner-blocks.cjs +44 -62
  4. package/build/blocks/widget-area/edit/inner-blocks.cjs.map +1 -7
  5. package/build/blocks/widget-area/edit/use-is-dragging-within.cjs +41 -53
  6. package/build/blocks/widget-area/edit/use-is-dragging-within.cjs.map +1 -7
  7. package/build/blocks/widget-area/index.cjs +40 -44
  8. package/build/blocks/widget-area/index.cjs.map +1 -7
  9. package/build/components/error-boundary/index.cjs +115 -155
  10. package/build/components/error-boundary/index.cjs.map +1 -7
  11. package/build/components/header/document-tools/index.cjs +80 -115
  12. package/build/components/header/document-tools/index.cjs.map +1 -7
  13. package/build/components/header/index.cjs +77 -80
  14. package/build/components/header/index.cjs.map +1 -7
  15. package/build/components/header/undo-redo/redo.cjs +30 -52
  16. package/build/components/header/undo-redo/redo.cjs.map +1 -7
  17. package/build/components/header/undo-redo/undo.cjs +29 -51
  18. package/build/components/header/undo-redo/undo.cjs.map +1 -7
  19. package/build/components/keyboard-shortcut-help-modal/config.cjs +88 -85
  20. package/build/components/keyboard-shortcut-help-modal/config.cjs.map +1 -7
  21. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs +40 -57
  22. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs.map +1 -7
  23. package/build/components/keyboard-shortcut-help-modal/index.cjs +94 -161
  24. package/build/components/keyboard-shortcut-help-modal/index.cjs.map +1 -7
  25. package/build/components/keyboard-shortcut-help-modal/shortcut.cjs +38 -75
  26. package/build/components/keyboard-shortcut-help-modal/shortcut.cjs.map +1 -7
  27. package/build/components/keyboard-shortcuts/index.cjs +107 -140
  28. package/build/components/keyboard-shortcuts/index.cjs.map +1 -7
  29. package/build/components/layout/index.cjs +65 -74
  30. package/build/components/layout/index.cjs.map +1 -7
  31. package/build/components/layout/interface.cjs +82 -108
  32. package/build/components/layout/interface.cjs.map +1 -7
  33. package/build/components/layout/unsaved-changes-warning.cjs +41 -48
  34. package/build/components/layout/unsaved-changes-warning.cjs.map +1 -7
  35. package/build/components/more-menu/index.cjs +124 -191
  36. package/build/components/more-menu/index.cjs.map +1 -7
  37. package/build/components/more-menu/tools-more-menu-group.cjs +9 -29
  38. package/build/components/more-menu/tools-more-menu-group.cjs.map +1 -7
  39. package/build/components/notices/index.cjs +19 -39
  40. package/build/components/notices/index.cjs.map +1 -7
  41. package/build/components/save-button/index.cjs +31 -58
  42. package/build/components/save-button/index.cjs.map +1 -7
  43. package/build/components/secondary-sidebar/index.cjs +38 -45
  44. package/build/components/secondary-sidebar/index.cjs.map +1 -7
  45. package/build/components/secondary-sidebar/inserter-sidebar.cjs +50 -51
  46. package/build/components/secondary-sidebar/inserter-sidebar.cjs.map +1 -7
  47. package/build/components/secondary-sidebar/list-view-sidebar.cjs +51 -82
  48. package/build/components/secondary-sidebar/list-view-sidebar.cjs.map +1 -7
  49. package/build/components/sidebar/index.cjs +117 -180
  50. package/build/components/sidebar/index.cjs.map +1 -7
  51. package/build/components/sidebar/widget-areas.cjs +43 -85
  52. package/build/components/sidebar/widget-areas.cjs.map +1 -7
  53. package/build/components/welcome-guide/index.cjs +110 -186
  54. package/build/components/welcome-guide/index.cjs.map +1 -7
  55. package/build/components/widget-areas-block-editor-content/index.cjs +59 -64
  56. package/build/components/widget-areas-block-editor-content/index.cjs.map +1 -7
  57. package/build/components/widget-areas-block-editor-provider/index.cjs +105 -140
  58. package/build/components/widget-areas-block-editor-provider/index.cjs.map +1 -7
  59. package/build/constants.cjs +11 -32
  60. package/build/constants.cjs.map +1 -7
  61. package/build/filters/index.cjs +7 -4
  62. package/build/filters/move-to-widget-area.cjs +38 -53
  63. package/build/filters/move-to-widget-area.cjs.map +1 -7
  64. package/build/filters/replace-media-upload.cjs +11 -9
  65. package/build/filters/replace-media-upload.cjs.map +1 -7
  66. package/build/hooks/use-last-selected-widget-area.cjs +28 -49
  67. package/build/hooks/use-last-selected-widget-area.cjs.map +1 -7
  68. package/build/hooks/use-widget-library-insertion-point.cjs +33 -67
  69. package/build/hooks/use-widget-library-insertion-point.cjs.map +1 -7
  70. package/build/index.cjs +96 -97
  71. package/build/index.cjs.map +1 -7
  72. package/build/lock-unlock.cjs +10 -35
  73. package/build/lock-unlock.cjs.map +1 -7
  74. package/build/store/actions.cjs +276 -278
  75. package/build/store/actions.cjs.map +1 -7
  76. package/build/store/constants.cjs +12 -29
  77. package/build/store/constants.cjs.map +1 -7
  78. package/build/store/index.cjs +61 -52
  79. package/build/store/index.cjs.map +1 -7
  80. package/build/store/private-selectors.cjs +11 -32
  81. package/build/store/private-selectors.cjs.map +1 -7
  82. package/build/store/reducer.cjs +107 -88
  83. package/build/store/reducer.cjs.map +1 -7
  84. package/build/store/resolvers.cjs +60 -91
  85. package/build/store/resolvers.cjs.map +1 -7
  86. package/build/store/selectors.cjs +196 -229
  87. package/build/store/selectors.cjs.map +1 -7
  88. package/build/store/transformers.cjs +51 -82
  89. package/build/store/transformers.cjs.map +1 -7
  90. package/build/store/utils.cjs +76 -63
  91. package/build/store/utils.cjs.map +1 -7
  92. package/build-module/blocks/widget-area/edit/index.mjs +82 -94
  93. package/build-module/blocks/widget-area/edit/index.mjs.map +1 -7
  94. package/build-module/blocks/widget-area/edit/inner-blocks.mjs +19 -35
  95. package/build-module/blocks/widget-area/edit/inner-blocks.mjs.map +1 -7
  96. package/build-module/blocks/widget-area/edit/use-is-dragging-within.mjs +36 -33
  97. package/build-module/blocks/widget-area/edit/use-is-dragging-within.mjs.map +1 -7
  98. package/build-module/blocks/widget-area/index.mjs +12 -15
  99. package/build-module/blocks/widget-area/index.mjs.map +1 -7
  100. package/build-module/components/error-boundary/index.mjs +104 -129
  101. package/build-module/components/error-boundary/index.mjs.map +1 -7
  102. package/build-module/components/header/document-tools/index.mjs +51 -84
  103. package/build-module/components/header/document-tools/index.mjs.map +1 -7
  104. package/build-module/components/header/index.mjs +44 -47
  105. package/build-module/components/header/index.mjs.map +1 -7
  106. package/build-module/components/header/undo-redo/redo.mjs +20 -27
  107. package/build-module/components/header/undo-redo/redo.mjs.map +1 -7
  108. package/build-module/components/header/undo-redo/undo.mjs +19 -26
  109. package/build-module/components/header/undo-redo/undo.mjs.map +1 -7
  110. package/build-module/components/keyboard-shortcut-help-modal/config.mjs +83 -61
  111. package/build-module/components/keyboard-shortcut-help-modal/config.mjs.map +1 -7
  112. package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs +19 -33
  113. package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs.map +1 -7
  114. package/build-module/components/keyboard-shortcut-help-modal/index.mjs +67 -136
  115. package/build-module/components/keyboard-shortcut-help-modal/index.mjs.map +1 -7
  116. package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs +32 -54
  117. package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs.map +1 -7
  118. package/build-module/components/keyboard-shortcuts/index.mjs +99 -119
  119. package/build-module/components/keyboard-shortcuts/index.mjs.map +1 -7
  120. package/build-module/components/layout/index.mjs +29 -40
  121. package/build-module/components/layout/index.mjs.map +1 -7
  122. package/build-module/components/layout/interface.mjs +53 -82
  123. package/build-module/components/layout/interface.mjs.map +1 -7
  124. package/build-module/components/layout/unsaved-changes-warning.mjs +35 -27
  125. package/build-module/components/layout/unsaved-changes-warning.mjs.map +1 -7
  126. package/build-module/components/more-menu/index.mjs +94 -162
  127. package/build-module/components/more-menu/index.mjs.map +1 -7
  128. package/build-module/components/more-menu/tools-more-menu-group.mjs +5 -9
  129. package/build-module/components/more-menu/tools-more-menu-group.mjs.map +1 -7
  130. package/build-module/components/notices/index.mjs +12 -17
  131. package/build-module/components/notices/index.mjs.map +1 -7
  132. package/build-module/components/save-button/index.mjs +23 -35
  133. package/build-module/components/save-button/index.mjs.map +1 -7
  134. package/build-module/components/secondary-sidebar/index.mjs +15 -20
  135. package/build-module/components/secondary-sidebar/index.mjs.map +1 -7
  136. package/build-module/components/secondary-sidebar/inserter-sidebar.mjs +27 -25
  137. package/build-module/components/secondary-sidebar/inserter-sidebar.mjs.map +1 -7
  138. package/build-module/components/secondary-sidebar/list-view-sidebar.mjs +39 -55
  139. package/build-module/components/secondary-sidebar/list-view-sidebar.mjs.map +1 -7
  140. package/build-module/components/sidebar/index.mjs +96 -162
  141. package/build-module/components/sidebar/index.mjs.map +1 -7
  142. package/build-module/components/sidebar/widget-areas.mjs +30 -57
  143. package/build-module/components/sidebar/widget-areas.mjs.map +1 -7
  144. package/build-module/components/welcome-guide/index.mjs +103 -164
  145. package/build-module/components/welcome-guide/index.mjs.map +1 -7
  146. package/build-module/components/widget-areas-block-editor-content/index.mjs +34 -44
  147. package/build-module/components/widget-areas-block-editor-content/index.mjs.map +1 -7
  148. package/build-module/components/widget-areas-block-editor-provider/index.mjs +76 -109
  149. package/build-module/components/widget-areas-block-editor-provider/index.mjs.map +1 -7
  150. package/build-module/constants.mjs +5 -7
  151. package/build-module/constants.mjs.map +1 -7
  152. package/build-module/filters/index.mjs +0 -2
  153. package/build-module/filters/move-to-widget-area.mjs +28 -48
  154. package/build-module/filters/move-to-widget-area.mjs.map +1 -7
  155. package/build-module/filters/replace-media-upload.mjs +5 -8
  156. package/build-module/filters/replace-media-upload.mjs.map +1 -7
  157. package/build-module/hooks/use-last-selected-widget-area.mjs +23 -29
  158. package/build-module/hooks/use-last-selected-widget-area.mjs.map +1 -7
  159. package/build-module/hooks/use-widget-library-insertion-point.mjs +28 -47
  160. package/build-module/hooks/use-widget-library-insertion-point.mjs.map +1 -7
  161. package/build-module/index.mjs +62 -79
  162. package/build-module/index.mjs.map +1 -7
  163. package/build-module/lock-unlock.mjs +5 -10
  164. package/build-module/lock-unlock.mjs.map +1 -7
  165. package/build-module/store/actions.mjs +257 -247
  166. package/build-module/store/actions.mjs.map +1 -7
  167. package/build-module/store/constants.mjs +7 -5
  168. package/build-module/store/constants.mjs.map +1 -7
  169. package/build-module/store/index.mjs +18 -16
  170. package/build-module/store/index.mjs.map +1 -7
  171. package/build-module/store/private-selectors.mjs +5 -7
  172. package/build-module/store/private-selectors.mjs.map +1 -7
  173. package/build-module/store/reducer.mjs +95 -58
  174. package/build-module/store/reducer.mjs.map +1 -7
  175. package/build-module/store/resolvers.mjs +52 -71
  176. package/build-module/store/resolvers.mjs.map +1 -7
  177. package/build-module/store/selectors.mjs +178 -199
  178. package/build-module/store/selectors.mjs.map +1 -7
  179. package/build-module/store/transformers.mjs +44 -56
  180. package/build-module/store/transformers.mjs.map +1 -7
  181. package/build-module/store/utils.mjs +64 -32
  182. package/build-module/store/utils.mjs.map +1 -7
  183. package/build-style/style-rtl.css +32 -11
  184. package/build-style/style.css +32 -11
  185. package/package.json +33 -33
  186. package/src/components/error-boundary/index.jsx +2 -2
  187. package/src/components/header/index.jsx +13 -4
  188. package/src/components/header/style.scss +30 -3
  189. package/src/components/keyboard-shortcut-help-modal/shortcut.jsx +1 -0
  190. package/src/components/keyboard-shortcut-help-modal/style.scss +1 -1
  191. package/src/components/layout/style.scss +5 -9
  192. package/src/components/layout/unsaved-changes-warning.js +4 -9
  193. package/src/components/more-menu/index.jsx +0 -1
  194. package/src/components/sidebar/index.jsx +18 -18
  195. package/src/components/welcome-guide/index.jsx +4 -2
  196. package/src/store/actions.js +25 -2
  197. package/src/store/test/actions.jsdom.test.js +230 -0
  198. package/build/filters/index.cjs.map +0 -7
  199. package/build-module/filters/index.mjs.map +0 -7
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/store/constants.js"],
4
- "sourcesContent": ["/**\n * Module Constants\n */\nexport const STORE_NAME = 'core/edit-widgets';\n"],
5
- "mappings": ";AAGO,IAAM,aAAa;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"constants.mjs","names":[],"sources":["../../src/store/constants.js"],"sourcesContent":["/**\n * Module Constants\n */\nexport const STORE_NAME = 'core/edit-widgets';\n"],"mappings":";;;;AAGA,MAAa,aAAa"}
@@ -1,4 +1,3 @@
1
- // packages/edit-widgets/src/store/index.js
2
1
  import apiFetch from "@wordpress/api-fetch";
3
2
  import { createReduxStore, register } from "@wordpress/data";
4
3
  import reducer from "./reducer.mjs";
@@ -8,22 +7,25 @@ import * as actions from "./actions.mjs";
8
7
  import * as privateSelectors from "./private-selectors.mjs";
9
8
  import { STORE_NAME } from "./constants.mjs";
10
9
  import { unlock } from "../lock-unlock.mjs";
11
- var storeConfig = {
12
- reducer,
13
- selectors,
14
- resolvers,
15
- actions
16
- };
17
- var store = createReduxStore(STORE_NAME, storeConfig);
10
+ /**
11
+ * Store definition for the edit widgets namespace.
12
+ *
13
+ * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
14
+ *
15
+ * @type {Object}
16
+ */
17
+ const store = createReduxStore(STORE_NAME, {
18
+ reducer,
19
+ selectors,
20
+ resolvers,
21
+ actions
22
+ });
18
23
  register(store);
19
24
  apiFetch.use(function(options, next) {
20
- if (options.path?.indexOf("/wp/v2/types/widget-area") === 0) {
21
- return Promise.resolve({});
22
- }
23
- return next(options);
25
+ if (options.path?.indexOf("/wp/v2/types/widget-area") === 0) return Promise.resolve({});
26
+ return next(options);
24
27
  });
25
28
  unlock(store).registerPrivateSelectors(privateSelectors);
26
- export {
27
- store
28
- };
29
- //# sourceMappingURL=index.mjs.map
29
+ export { store };
30
+
31
+ //# sourceMappingURL=index.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/store/index.js"],
4
- "sourcesContent": ["import apiFetch from '@wordpress/api-fetch';\nimport { createReduxStore, register } from '@wordpress/data';\nimport reducer from './reducer';\nimport * as resolvers from './resolvers';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as privateSelectors from './private-selectors';\nimport { STORE_NAME } from './constants';\nimport { unlock } from '../lock-unlock';\n\n/**\n * Block editor data store configuration.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#register\n *\n * @type {Object}\n */\nconst storeConfig = {\n\treducer,\n\tselectors,\n\tresolvers,\n\tactions,\n};\n\n/**\n * Store definition for the edit widgets namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig );\nregister( store );\n\n// This package uses a few in-memory post types as wrappers for convenience.\n// This middleware prevents any network requests related to these types as they are\n// bound to fail anyway.\napiFetch.use( function ( options, next ) {\n\tif ( options.path?.indexOf( '/wp/v2/types/widget-area' ) === 0 ) {\n\t\treturn Promise.resolve( {} );\n\t}\n\n\treturn next( options );\n} );\n\nunlock( store ).registerPrivateSelectors( privateSelectors );\n"],
5
- "mappings": ";AAAA,OAAO,cAAc;AACrB,SAAS,kBAAkB,gBAAgB;AAC3C,OAAO,aAAa;AACpB,YAAY,eAAe;AAC3B,YAAY,eAAe;AAC3B,YAAY,aAAa;AACzB,YAAY,sBAAsB;AAClC,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AASvB,IAAM,cAAc;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AASO,IAAM,QAAQ,iBAAkB,YAAY,WAAY;AAC/D,SAAU,KAAM;AAKhB,SAAS,IAAK,SAAW,SAAS,MAAO;AACxC,MAAK,QAAQ,MAAM,QAAS,0BAA2B,MAAM,GAAI;AAChE,WAAO,QAAQ,QAAS,CAAC,CAAE;AAAA,EAC5B;AAEA,SAAO,KAAM,OAAQ;AACtB,CAAE;AAEF,OAAQ,KAAM,EAAE,yBAA0B,gBAAiB;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/store/index.js"],"sourcesContent":["import apiFetch from '@wordpress/api-fetch';\nimport { createReduxStore, register } from '@wordpress/data';\nimport reducer from './reducer';\nimport * as resolvers from './resolvers';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as privateSelectors from './private-selectors';\nimport { STORE_NAME } from './constants';\nimport { unlock } from '../lock-unlock';\n\n/**\n * Block editor data store configuration.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#register\n *\n * @type {Object}\n */\nconst storeConfig = {\n\treducer,\n\tselectors,\n\tresolvers,\n\tactions,\n};\n\n/**\n * Store definition for the edit widgets namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig );\nregister( store );\n\n// This package uses a few in-memory post types as wrappers for convenience.\n// This middleware prevents any network requests related to these types as they are\n// bound to fail anyway.\napiFetch.use( function ( options, next ) {\n\tif ( options.path?.indexOf( '/wp/v2/types/widget-area' ) === 0 ) {\n\t\treturn Promise.resolve( {} );\n\t}\n\n\treturn next( options );\n} );\n\nunlock( store ).registerPrivateSelectors( privateSelectors );\n"],"mappings":";;;;;;;;;;;;;;;;AA+BA,MAAa,QAAQ,iBAAkB,YAAY;CAblD;CACA;CACA;CACA;AAUkD,CAAY;AAC/D,SAAU,KAAM;AAKhB,SAAS,IAAK,SAAW,SAAS,MAAO;CACxC,IAAK,QAAQ,MAAM,QAAS,0BAA2B,MAAM,GAC5D,OAAO,QAAQ,QAAS,CAAC,CAAE;CAG5B,OAAO,KAAM,OAAQ;AACtB,CAAE;AAEF,OAAQ,KAAM,CAAC,CAAC,yBAA0B,gBAAiB"}
@@ -1,12 +1,10 @@
1
1
  // packages/edit-widgets/src/store/private-selectors.js
2
2
  function getListViewToggleRef(state) {
3
- return state.listViewToggleRef;
3
+ return state.listViewToggleRef;
4
4
  }
5
5
  function getInserterSidebarToggleRef(state) {
6
- return state.inserterSidebarToggleRef;
6
+ return state.inserterSidebarToggleRef;
7
7
  }
8
- export {
9
- getInserterSidebarToggleRef,
10
- getListViewToggleRef
11
- };
12
- //# sourceMappingURL=private-selectors.mjs.map
8
+ export { getInserterSidebarToggleRef, getListViewToggleRef };
9
+
10
+ //# sourceMappingURL=private-selectors.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/store/private-selectors.js"],
4
- "sourcesContent": ["export function getListViewToggleRef( state ) {\n\treturn state.listViewToggleRef;\n}\n\nexport function getInserterSidebarToggleRef( state ) {\n\treturn state.inserterSidebarToggleRef;\n}\n"],
5
- "mappings": ";AAAO,SAAS,qBAAsB,OAAQ;AAC7C,SAAO,MAAM;AACd;AAEO,SAAS,4BAA6B,OAAQ;AACpD,SAAO,MAAM;AACd;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"private-selectors.mjs","names":[],"sources":["../../src/store/private-selectors.js"],"sourcesContent":["export function getListViewToggleRef( state ) {\n\treturn state.listViewToggleRef;\n}\n\nexport function getInserterSidebarToggleRef( state ) {\n\treturn state.inserterSidebarToggleRef;\n}\n"],"mappings":";AAAA,SAAgB,qBAAsB,OAAQ;CAC7C,OAAO,MAAM;AACd;AAEA,SAAgB,4BAA6B,OAAQ;CACpD,OAAO,MAAM;AACd"}
@@ -1,73 +1,110 @@
1
- // packages/edit-widgets/src/store/reducer.js
2
1
  import { combineReducers } from "@wordpress/data";
2
+ // packages/edit-widgets/src/store/reducer.js
3
+ /**
4
+ * Controls the open state of the widget areas.
5
+ *
6
+ * @param {Object} state Redux state.
7
+ * @param {Object} action Redux action.
8
+ *
9
+ * @return {Array} Updated state.
10
+ */
3
11
  function widgetAreasOpenState(state = {}, action) {
4
- const { type } = action;
5
- switch (type) {
6
- case "SET_WIDGET_AREAS_OPEN_STATE": {
7
- return action.widgetAreasOpenState;
8
- }
9
- case "SET_IS_WIDGET_AREA_OPEN": {
10
- const { clientId, isOpen } = action;
11
- return {
12
- ...state,
13
- [clientId]: isOpen
14
- };
15
- }
16
- default: {
17
- return state;
18
- }
19
- }
12
+ const { type } = action;
13
+ switch (type) {
14
+ case "SET_WIDGET_AREAS_OPEN_STATE": return action.widgetAreasOpenState;
15
+ case "SET_IS_WIDGET_AREA_OPEN": {
16
+ const { clientId, isOpen } = action;
17
+ return {
18
+ ...state,
19
+ [clientId]: isOpen
20
+ };
21
+ }
22
+ default: return state;
23
+ }
20
24
  }
25
+ /**
26
+ * Reducer to set the block inserter panel open or closed.
27
+ *
28
+ * Note: this reducer interacts with the list view panel reducer
29
+ * to make sure that only one of the two panels is open at the same time.
30
+ *
31
+ * @param {Object} state Current state.
32
+ * @param {Object} action Dispatched action.
33
+ */
21
34
  function blockInserterPanel(state = false, action) {
22
- switch (action.type) {
23
- case "SET_IS_LIST_VIEW_OPENED":
24
- return action.isOpen ? false : state;
25
- case "SET_IS_INSERTER_OPENED":
26
- return action.value;
27
- }
28
- return state;
35
+ switch (action.type) {
36
+ case "SET_IS_LIST_VIEW_OPENED": return action.isOpen ? false : state;
37
+ case "SET_IS_INSERTER_OPENED": return action.value;
38
+ }
39
+ return state;
29
40
  }
41
+ /**
42
+ * Reducer to set the list view panel open or closed.
43
+ *
44
+ * Note: this reducer interacts with the inserter panel reducer
45
+ * to make sure that only one of the two panels is open at the same time.
46
+ *
47
+ * @param {Object} state Current state.
48
+ * @param {Object} action Dispatched action.
49
+ */
30
50
  function listViewPanel(state = false, action) {
31
- switch (action.type) {
32
- case "SET_IS_INSERTER_OPENED":
33
- return action.value ? false : state;
34
- case "SET_IS_LIST_VIEW_OPENED":
35
- return action.isOpen;
36
- }
37
- return state;
51
+ switch (action.type) {
52
+ case "SET_IS_INSERTER_OPENED": return action.value ? false : state;
53
+ case "SET_IS_LIST_VIEW_OPENED": return action.isOpen;
54
+ }
55
+ return state;
38
56
  }
57
+ /**
58
+ * This reducer does nothing aside initializing a ref to the list view toggle.
59
+ * We will have a unique ref per "editor" instance.
60
+ *
61
+ * @param {Object} state
62
+ * @return {Object} Reference to the list view toggle button.
63
+ */
39
64
  function listViewToggleRef(state = { current: null }) {
40
- return state;
65
+ return state;
41
66
  }
67
+ /**
68
+ * This reducer does nothing aside initializing a ref to the inserter sidebar toggle.
69
+ * We will have a unique ref per "editor" instance.
70
+ *
71
+ * @param {Object} state
72
+ * @return {Object} Reference to the inserter sidebar toggle button.
73
+ */
42
74
  function inserterSidebarToggleRef(state = { current: null }) {
43
- return state;
75
+ return state;
44
76
  }
77
+ /**
78
+ * Widget saving lock.
79
+ *
80
+ * When widget saving is locked, the widget cannot be updated.
81
+ *
82
+ * @param {Object} state Current state.
83
+ * @param {Object} action Dispatched action.
84
+ *
85
+ * @return {Object} Updated state.
86
+ */
45
87
  function widgetSavingLock(state = {}, action) {
46
- switch (action.type) {
47
- case "LOCK_WIDGET_SAVING":
48
- return { ...state, [action.lockName]: true };
49
- case "UNLOCK_WIDGET_SAVING": {
50
- const { [action.lockName]: removedLockName, ...restState } = state;
51
- return restState;
52
- }
53
- }
54
- return state;
88
+ switch (action.type) {
89
+ case "LOCK_WIDGET_SAVING": return {
90
+ ...state,
91
+ [action.lockName]: true
92
+ };
93
+ case "UNLOCK_WIDGET_SAVING": {
94
+ const { [action.lockName]: removedLockName, ...restState } = state;
95
+ return restState;
96
+ }
97
+ }
98
+ return state;
55
99
  }
56
100
  var reducer_default = combineReducers({
57
- blockInserterPanel,
58
- inserterSidebarToggleRef,
59
- listViewPanel,
60
- listViewToggleRef,
61
- widgetAreasOpenState,
62
- widgetSavingLock
101
+ blockInserterPanel,
102
+ inserterSidebarToggleRef,
103
+ listViewPanel,
104
+ listViewToggleRef,
105
+ widgetAreasOpenState,
106
+ widgetSavingLock
63
107
  });
64
- export {
65
- blockInserterPanel,
66
- reducer_default as default,
67
- inserterSidebarToggleRef,
68
- listViewPanel,
69
- listViewToggleRef,
70
- widgetAreasOpenState,
71
- widgetSavingLock
72
- };
73
- //# sourceMappingURL=reducer.mjs.map
108
+ export { blockInserterPanel, reducer_default as default, inserterSidebarToggleRef, listViewPanel, listViewToggleRef, widgetAreasOpenState, widgetSavingLock };
109
+
110
+ //# sourceMappingURL=reducer.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/store/reducer.js"],
4
- "sourcesContent": ["import { combineReducers } from '@wordpress/data';\n\n/**\n * Controls the open state of the widget areas.\n *\n * @param {Object} state Redux state.\n * @param {Object} action Redux action.\n *\n * @return {Array} Updated state.\n */\nexport function widgetAreasOpenState( state = {}, action ) {\n\tconst { type } = action;\n\tswitch ( type ) {\n\t\tcase 'SET_WIDGET_AREAS_OPEN_STATE': {\n\t\t\treturn action.widgetAreasOpenState;\n\t\t}\n\t\tcase 'SET_IS_WIDGET_AREA_OPEN': {\n\t\t\tconst { clientId, isOpen } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ clientId ]: isOpen,\n\t\t\t};\n\t\t}\n\t\tdefault: {\n\t\t\treturn state;\n\t\t}\n\t}\n}\n\n/**\n * Reducer to set the block inserter panel open or closed.\n *\n * Note: this reducer interacts with the list view panel reducer\n * to make sure that only one of the two panels is open at the same time.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n */\nexport function blockInserterPanel( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IS_LIST_VIEW_OPENED':\n\t\t\treturn action.isOpen ? false : state;\n\t\tcase 'SET_IS_INSERTER_OPENED':\n\t\t\treturn action.value;\n\t}\n\treturn state;\n}\n\n/**\n * Reducer to set the list view panel open or closed.\n *\n * Note: this reducer interacts with the inserter panel reducer\n * to make sure that only one of the two panels is open at the same time.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n */\nexport function listViewPanel( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IS_INSERTER_OPENED':\n\t\t\treturn action.value ? false : state;\n\t\tcase 'SET_IS_LIST_VIEW_OPENED':\n\t\t\treturn action.isOpen;\n\t}\n\treturn state;\n}\n\n/**\n * This reducer does nothing aside initializing a ref to the list view toggle.\n * We will have a unique ref per \"editor\" instance.\n *\n * @param {Object} state\n * @return {Object} Reference to the list view toggle button.\n */\nexport function listViewToggleRef( state = { current: null } ) {\n\treturn state;\n}\n\n/**\n * This reducer does nothing aside initializing a ref to the inserter sidebar toggle.\n * We will have a unique ref per \"editor\" instance.\n *\n * @param {Object} state\n * @return {Object} Reference to the inserter sidebar toggle button.\n */\nexport function inserterSidebarToggleRef( state = { current: null } ) {\n\treturn state;\n}\n\n/**\n * Widget saving lock.\n *\n * When widget saving is locked, the widget cannot be updated.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function widgetSavingLock( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'LOCK_WIDGET_SAVING':\n\t\t\treturn { ...state, [ action.lockName ]: true };\n\n\t\tcase 'UNLOCK_WIDGET_SAVING': {\n\t\t\tconst { [ action.lockName ]: removedLockName, ...restState } =\n\t\t\t\tstate;\n\t\t\treturn restState;\n\t\t}\n\t}\n\n\treturn state;\n}\n\nexport default combineReducers( {\n\tblockInserterPanel,\n\tinserterSidebarToggleRef,\n\tlistViewPanel,\n\tlistViewToggleRef,\n\twidgetAreasOpenState,\n\twidgetSavingLock,\n} );\n"],
5
- "mappings": ";AAAA,SAAS,uBAAuB;AAUzB,SAAS,qBAAsB,QAAQ,CAAC,GAAG,QAAS;AAC1D,QAAM,EAAE,KAAK,IAAI;AACjB,UAAS,MAAO;AAAA,IACf,KAAK,+BAA+B;AACnC,aAAO,OAAO;AAAA,IACf;AAAA,IACA,KAAK,2BAA2B;AAC/B,YAAM,EAAE,UAAU,OAAO,IAAI;AAC7B,aAAO;AAAA,QACN,GAAG;AAAA,QACH,CAAE,QAAS,GAAG;AAAA,MACf;AAAA,IACD;AAAA,IACA,SAAS;AACR,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAWO,SAAS,mBAAoB,QAAQ,OAAO,QAAS;AAC3D,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AACJ,aAAO,OAAO,SAAS,QAAQ;AAAA,IAChC,KAAK;AACJ,aAAO,OAAO;AAAA,EAChB;AACA,SAAO;AACR;AAWO,SAAS,cAAe,QAAQ,OAAO,QAAS;AACtD,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AACJ,aAAO,OAAO,QAAQ,QAAQ;AAAA,IAC/B,KAAK;AACJ,aAAO,OAAO;AAAA,EAChB;AACA,SAAO;AACR;AASO,SAAS,kBAAmB,QAAQ,EAAE,SAAS,KAAK,GAAI;AAC9D,SAAO;AACR;AASO,SAAS,yBAA0B,QAAQ,EAAE,SAAS,KAAK,GAAI;AACrE,SAAO;AACR;AAYO,SAAS,iBAAkB,QAAQ,CAAC,GAAG,QAAS;AACtD,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AACJ,aAAO,EAAE,GAAG,OAAO,CAAE,OAAO,QAAS,GAAG,KAAK;AAAA,IAE9C,KAAK,wBAAwB;AAC5B,YAAM,EAAE,CAAE,OAAO,QAAS,GAAG,iBAAiB,GAAG,UAAU,IAC1D;AACD,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR;AAEA,IAAO,kBAAQ,gBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAE;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"reducer.mjs","names":[],"sources":["../../src/store/reducer.js"],"sourcesContent":["import { combineReducers } from '@wordpress/data';\n\n/**\n * Controls the open state of the widget areas.\n *\n * @param {Object} state Redux state.\n * @param {Object} action Redux action.\n *\n * @return {Array} Updated state.\n */\nexport function widgetAreasOpenState( state = {}, action ) {\n\tconst { type } = action;\n\tswitch ( type ) {\n\t\tcase 'SET_WIDGET_AREAS_OPEN_STATE': {\n\t\t\treturn action.widgetAreasOpenState;\n\t\t}\n\t\tcase 'SET_IS_WIDGET_AREA_OPEN': {\n\t\t\tconst { clientId, isOpen } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ clientId ]: isOpen,\n\t\t\t};\n\t\t}\n\t\tdefault: {\n\t\t\treturn state;\n\t\t}\n\t}\n}\n\n/**\n * Reducer to set the block inserter panel open or closed.\n *\n * Note: this reducer interacts with the list view panel reducer\n * to make sure that only one of the two panels is open at the same time.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n */\nexport function blockInserterPanel( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IS_LIST_VIEW_OPENED':\n\t\t\treturn action.isOpen ? false : state;\n\t\tcase 'SET_IS_INSERTER_OPENED':\n\t\t\treturn action.value;\n\t}\n\treturn state;\n}\n\n/**\n * Reducer to set the list view panel open or closed.\n *\n * Note: this reducer interacts with the inserter panel reducer\n * to make sure that only one of the two panels is open at the same time.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n */\nexport function listViewPanel( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IS_INSERTER_OPENED':\n\t\t\treturn action.value ? false : state;\n\t\tcase 'SET_IS_LIST_VIEW_OPENED':\n\t\t\treturn action.isOpen;\n\t}\n\treturn state;\n}\n\n/**\n * This reducer does nothing aside initializing a ref to the list view toggle.\n * We will have a unique ref per \"editor\" instance.\n *\n * @param {Object} state\n * @return {Object} Reference to the list view toggle button.\n */\nexport function listViewToggleRef( state = { current: null } ) {\n\treturn state;\n}\n\n/**\n * This reducer does nothing aside initializing a ref to the inserter sidebar toggle.\n * We will have a unique ref per \"editor\" instance.\n *\n * @param {Object} state\n * @return {Object} Reference to the inserter sidebar toggle button.\n */\nexport function inserterSidebarToggleRef( state = { current: null } ) {\n\treturn state;\n}\n\n/**\n * Widget saving lock.\n *\n * When widget saving is locked, the widget cannot be updated.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function widgetSavingLock( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'LOCK_WIDGET_SAVING':\n\t\t\treturn { ...state, [ action.lockName ]: true };\n\n\t\tcase 'UNLOCK_WIDGET_SAVING': {\n\t\t\tconst { [ action.lockName ]: removedLockName, ...restState } =\n\t\t\t\tstate;\n\t\t\treturn restState;\n\t\t}\n\t}\n\n\treturn state;\n}\n\nexport default combineReducers( {\n\tblockInserterPanel,\n\tinserterSidebarToggleRef,\n\tlistViewPanel,\n\tlistViewToggleRef,\n\twidgetAreasOpenState,\n\twidgetSavingLock,\n} );\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,qBAAsB,QAAQ,CAAC,GAAG,QAAS;CAC1D,MAAM,EAAE,SAAS;CACjB,QAAS,MAAT;EACC,KAAK,+BACJ,OAAO,OAAO;EAEf,KAAK,2BAA2B;GAC/B,MAAM,EAAE,UAAU,WAAW;GAC7B,OAAO;IACN,GAAG;KACD,WAAY;GACf;EACD;EACA,SACC,OAAO;CAET;AACD;;;;;;;;;;AAWA,SAAgB,mBAAoB,QAAQ,OAAO,QAAS;CAC3D,QAAS,OAAO,MAAhB;EACC,KAAK,2BACJ,OAAO,OAAO,SAAS,QAAQ;EAChC,KAAK,0BACJ,OAAO,OAAO;CAChB;CACA,OAAO;AACR;;;;;;;;;;AAWA,SAAgB,cAAe,QAAQ,OAAO,QAAS;CACtD,QAAS,OAAO,MAAhB;EACC,KAAK,0BACJ,OAAO,OAAO,QAAQ,QAAQ;EAC/B,KAAK,2BACJ,OAAO,OAAO;CAChB;CACA,OAAO;AACR;;;;;;;;AASA,SAAgB,kBAAmB,QAAQ,EAAE,SAAS,KAAK,GAAI;CAC9D,OAAO;AACR;;;;;;;;AASA,SAAgB,yBAA0B,QAAQ,EAAE,SAAS,KAAK,GAAI;CACrE,OAAO;AACR;;;;;;;;;;;AAYA,SAAgB,iBAAkB,QAAQ,CAAC,GAAG,QAAS;CACtD,QAAS,OAAO,MAAhB;EACC,KAAK,sBACJ,OAAO;GAAE,GAAG;IAAS,OAAO,WAAY;EAAK;EAE9C,KAAK,wBAAwB;GAC5B,MAAM,GAAI,OAAO,WAAY,iBAAiB,GAAG,cAChD;GACD,OAAO;EACR;CACD;CAEA,OAAO;AACR;AAEA,IAAA,kBAAe,gBAAiB;CAC/B;CACA;CACA;CACA;CACA;CACA;AACD,CAAE"}
@@ -1,76 +1,57 @@
1
- // packages/edit-widgets/src/store/resolvers.js
2
1
  import { createBlock } from "@wordpress/blocks";
3
- import { store as coreStore } from "@wordpress/core-data";
2
+ import { store } from "@wordpress/core-data";
4
3
  import { persistStubPost, setWidgetAreasOpenState } from "./actions.mjs";
5
- import {
6
- KIND,
7
- WIDGET_AREA_ENTITY_TYPE,
8
- buildWidgetsQuery,
9
- buildWidgetAreasQuery,
10
- buildWidgetAreaPostId,
11
- buildWidgetAreasPostId
12
- } from "./utils.mjs";
4
+ import { KIND, WIDGET_AREA_ENTITY_TYPE, buildWidgetAreaPostId, buildWidgetAreasPostId, buildWidgetAreasQuery, buildWidgetsQuery } from "./utils.mjs";
13
5
  import { transformWidgetToBlock } from "./transformers.mjs";
14
- var getWidgetAreas = () => async ({ dispatch, registry }) => {
15
- const query = buildWidgetAreasQuery();
16
- const widgetAreas = await registry.resolveSelect(coreStore).getEntityRecords(KIND, WIDGET_AREA_ENTITY_TYPE, query);
17
- const widgetAreaBlocks = [];
18
- const sortedWidgetAreas = widgetAreas.sort((a, b) => {
19
- if (a.id === "wp_inactive_widgets") {
20
- return 1;
21
- }
22
- if (b.id === "wp_inactive_widgets") {
23
- return -1;
24
- }
25
- return 0;
26
- });
27
- for (const widgetArea of sortedWidgetAreas) {
28
- widgetAreaBlocks.push(
29
- createBlock("core/widget-area", {
30
- id: widgetArea.id,
31
- name: widgetArea.name
32
- })
33
- );
34
- if (!widgetArea.widgets.length) {
35
- dispatch(
36
- persistStubPost(
37
- buildWidgetAreaPostId(widgetArea.id),
38
- []
39
- )
40
- );
41
- }
42
- }
43
- const widgetAreasOpenState = {};
44
- widgetAreaBlocks.forEach((widgetAreaBlock, index) => {
45
- widgetAreasOpenState[widgetAreaBlock.clientId] = index === 0;
46
- });
47
- dispatch(setWidgetAreasOpenState(widgetAreasOpenState));
48
- dispatch(
49
- persistStubPost(buildWidgetAreasPostId(), widgetAreaBlocks)
50
- );
51
- };
52
- var getWidgets = () => async ({ dispatch, registry }) => {
53
- const query = buildWidgetsQuery();
54
- const widgets = await registry.resolveSelect(coreStore).getEntityRecords("root", "widget", query);
55
- const groupedBySidebar = {};
56
- for (const widget of widgets) {
57
- const block = transformWidgetToBlock(widget);
58
- groupedBySidebar[widget.sidebar] = groupedBySidebar[widget.sidebar] || [];
59
- groupedBySidebar[widget.sidebar].push(block);
60
- }
61
- for (const sidebarId in groupedBySidebar) {
62
- if (groupedBySidebar.hasOwnProperty(sidebarId)) {
63
- dispatch(
64
- persistStubPost(
65
- buildWidgetAreaPostId(sidebarId),
66
- groupedBySidebar[sidebarId]
67
- )
68
- );
69
- }
70
- }
6
+ // packages/edit-widgets/src/store/resolvers.js
7
+ /**
8
+ * Creates a "stub" widgets post reflecting all available widget areas. The
9
+ * post is meant as a convenient to only exists in runtime and should never be saved. It
10
+ * enables a convenient way of editing the widgets by using a regular post editor.
11
+ *
12
+ * Fetches all widgets from all widgets aras, converts them into blocks, and hydrates a new post with them.
13
+ *
14
+ * @return {Function} An action creator.
15
+ */
16
+ const getWidgetAreas = () => async ({ dispatch, registry }) => {
17
+ const query = buildWidgetAreasQuery();
18
+ const widgetAreas = await registry.resolveSelect(store).getEntityRecords(KIND, WIDGET_AREA_ENTITY_TYPE, query);
19
+ const widgetAreaBlocks = [];
20
+ const sortedWidgetAreas = widgetAreas.sort((a, b) => {
21
+ if (a.id === "wp_inactive_widgets") return 1;
22
+ if (b.id === "wp_inactive_widgets") return -1;
23
+ return 0;
24
+ });
25
+ for (const widgetArea of sortedWidgetAreas) {
26
+ widgetAreaBlocks.push(createBlock("core/widget-area", {
27
+ id: widgetArea.id,
28
+ name: widgetArea.name
29
+ }));
30
+ if (!widgetArea.widgets.length) dispatch(persistStubPost(buildWidgetAreaPostId(widgetArea.id), []));
31
+ }
32
+ const widgetAreasOpenState = {};
33
+ widgetAreaBlocks.forEach((widgetAreaBlock, index) => {
34
+ widgetAreasOpenState[widgetAreaBlock.clientId] = index === 0;
35
+ });
36
+ dispatch(setWidgetAreasOpenState(widgetAreasOpenState));
37
+ dispatch(persistStubPost(buildWidgetAreasPostId(), widgetAreaBlocks));
71
38
  };
72
- export {
73
- getWidgetAreas,
74
- getWidgets
39
+ /**
40
+ * Fetches all widgets from all widgets ares, and groups them by widget area Id.
41
+ *
42
+ * @return {Function} An action creator.
43
+ */
44
+ const getWidgets = () => async ({ dispatch, registry }) => {
45
+ const query = buildWidgetsQuery();
46
+ const widgets = await registry.resolveSelect(store).getEntityRecords("root", "widget", query);
47
+ const groupedBySidebar = {};
48
+ for (const widget of widgets) {
49
+ const block = transformWidgetToBlock(widget);
50
+ groupedBySidebar[widget.sidebar] = groupedBySidebar[widget.sidebar] || [];
51
+ groupedBySidebar[widget.sidebar].push(block);
52
+ }
53
+ for (const sidebarId in groupedBySidebar) if (groupedBySidebar.hasOwnProperty(sidebarId)) dispatch(persistStubPost(buildWidgetAreaPostId(sidebarId), groupedBySidebar[sidebarId]));
75
54
  };
76
- //# sourceMappingURL=resolvers.mjs.map
55
+ export { getWidgetAreas, getWidgets };
56
+
57
+ //# sourceMappingURL=resolvers.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/store/resolvers.js"],
4
- "sourcesContent": ["import { createBlock } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\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,SAAS,mBAAmB;AAC5B,SAAS,SAAS,iBAAiB;AACnC,SAAS,iBAAiB,+BAA+B;AACzD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,8BAA8B;AAWhC,IAAM,iBACZ,MACA,OAAQ,EAAE,UAAU,SAAS,MAAO;AACnC,QAAM,QAAQ,sBAAsB;AACpC,QAAM,cAAc,MAAM,SACxB,cAAe,SAAU,EACzB,iBAAkB,MAAM,yBAAyB,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,MAChB,YAAa,oBAAoB;AAAA,QAChC,IAAI,WAAW;AAAA,QACf,MAAM,WAAW;AAAA,MAClB,CAAE;AAAA,IACH;AAEA,QAAK,CAAE,WAAW,QAAQ,QAAS;AAGlC;AAAA,QACC;AAAA,UACC,sBAAuB,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,WAAU,wBAAyB,oBAAqB,CAAE;AAE1D;AAAA,IACC,gBAAiB,uBAAuB,GAAG,gBAAiB;AAAA,EAC7D;AACD;AAOM,IAAM,aACZ,MACA,OAAQ,EAAE,UAAU,SAAS,MAAO;AACnC,QAAM,QAAQ,kBAAkB;AAChC,QAAM,UAAU,MAAM,SACpB,cAAe,SAAU,EACzB,iBAAkB,QAAQ,UAAU,KAAM;AAE5C,QAAM,mBAAmB,CAAC;AAE1B,aAAY,UAAU,SAAU;AAC/B,UAAM,QAAQ,uBAAwB,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,QACC;AAAA,UACC,sBAAuB,SAAU;AAAA,UACjC,iBAAkB,SAAU;AAAA,QAC7B;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"resolvers.mjs","names":["coreStore"],"sources":["../../src/store/resolvers.js"],"sourcesContent":["import { createBlock } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\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":";;;;;;;;;;;;;;;AAsBA,MAAa,uBAEZ,OAAQ,EAAE,UAAU,eAAgB;CACnC,MAAM,QAAQ,sBAAsB;CACpC,MAAM,cAAc,MAAM,SACxB,cAAeA,KAAU,CAAC,CAC1B,iBAAkB,MAAM,yBAAyB,KAAM;CAEzD,MAAM,mBAAmB,CAAC;CAC1B,MAAM,oBAAoB,YAAY,MAAQ,GAAG,MAAO;EACvD,IAAK,EAAE,OAAO,uBACb,OAAO;EAER,IAAK,EAAE,OAAO,uBACb,OAAO;EAER,OAAO;CACR,CAAE;CACF,KAAM,MAAM,cAAc,mBAAoB;EAC7C,iBAAiB,KAChB,YAAa,oBAAoB;GAChC,IAAI,WAAW;GACf,MAAM,WAAW;EAClB,CAAE,CACH;EAEA,IAAK,CAAE,WAAW,QAAQ,QAGzB,SACC,gBACC,sBAAuB,WAAW,EAAG,GACrC,CAAC,CACF,CACD;CAEF;CAEA,MAAM,uBAAuB,CAAC;CAC9B,iBAAiB,SAAW,iBAAiB,UAAW;EAEvD,qBAAsB,gBAAgB,YAAa,UAAU;CAC9D,CAAE;CACF,SAAU,wBAAyB,oBAAqB,CAAE;CAE1D,SACC,gBAAiB,uBAAuB,GAAG,gBAAiB,CAC7D;AACD;;;;;;AAOD,MAAa,mBAEZ,OAAQ,EAAE,UAAU,eAAgB;CACnC,MAAM,QAAQ,kBAAkB;CAChC,MAAM,UAAU,MAAM,SACpB,cAAeA,KAAU,CAAC,CAC1B,iBAAkB,QAAQ,UAAU,KAAM;CAE5C,MAAM,mBAAmB,CAAC;CAE1B,KAAM,MAAM,UAAU,SAAU;EAC/B,MAAM,QAAQ,uBAAwB,MAAO;EAC7C,iBAAkB,OAAO,WACxB,iBAAkB,OAAO,YAAa,CAAC;EACxC,iBAAkB,OAAO,QAAS,CAAC,KAAM,KAAM;CAChD;CAEA,KAAM,MAAM,aAAa,kBACxB,IAAK,iBAAiB,eAAgB,SAAU,GAE/C,SACC,gBACC,sBAAuB,SAAU,GACjC,iBAAkB,UACnB,CACD;AAGH"}