@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.
- package/build/blocks/widget-area/edit/index.cjs +106 -116
- package/build/blocks/widget-area/edit/index.cjs.map +1 -7
- package/build/blocks/widget-area/edit/inner-blocks.cjs +44 -62
- package/build/blocks/widget-area/edit/inner-blocks.cjs.map +1 -7
- package/build/blocks/widget-area/edit/use-is-dragging-within.cjs +41 -53
- package/build/blocks/widget-area/edit/use-is-dragging-within.cjs.map +1 -7
- package/build/blocks/widget-area/index.cjs +40 -44
- package/build/blocks/widget-area/index.cjs.map +1 -7
- package/build/components/error-boundary/index.cjs +115 -155
- package/build/components/error-boundary/index.cjs.map +1 -7
- package/build/components/header/document-tools/index.cjs +80 -115
- package/build/components/header/document-tools/index.cjs.map +1 -7
- package/build/components/header/index.cjs +77 -80
- package/build/components/header/index.cjs.map +1 -7
- package/build/components/header/undo-redo/redo.cjs +30 -52
- package/build/components/header/undo-redo/redo.cjs.map +1 -7
- package/build/components/header/undo-redo/undo.cjs +29 -51
- package/build/components/header/undo-redo/undo.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/config.cjs +88 -85
- package/build/components/keyboard-shortcut-help-modal/config.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs +40 -57
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/index.cjs +94 -161
- package/build/components/keyboard-shortcut-help-modal/index.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs +38 -75
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs.map +1 -7
- package/build/components/keyboard-shortcuts/index.cjs +107 -140
- package/build/components/keyboard-shortcuts/index.cjs.map +1 -7
- package/build/components/layout/index.cjs +65 -74
- package/build/components/layout/index.cjs.map +1 -7
- package/build/components/layout/interface.cjs +82 -108
- package/build/components/layout/interface.cjs.map +1 -7
- package/build/components/layout/unsaved-changes-warning.cjs +41 -48
- package/build/components/layout/unsaved-changes-warning.cjs.map +1 -7
- package/build/components/more-menu/index.cjs +124 -191
- package/build/components/more-menu/index.cjs.map +1 -7
- package/build/components/more-menu/tools-more-menu-group.cjs +9 -29
- package/build/components/more-menu/tools-more-menu-group.cjs.map +1 -7
- package/build/components/notices/index.cjs +19 -39
- package/build/components/notices/index.cjs.map +1 -7
- package/build/components/save-button/index.cjs +31 -58
- package/build/components/save-button/index.cjs.map +1 -7
- package/build/components/secondary-sidebar/index.cjs +38 -45
- package/build/components/secondary-sidebar/index.cjs.map +1 -7
- package/build/components/secondary-sidebar/inserter-sidebar.cjs +50 -51
- package/build/components/secondary-sidebar/inserter-sidebar.cjs.map +1 -7
- package/build/components/secondary-sidebar/list-view-sidebar.cjs +51 -82
- package/build/components/secondary-sidebar/list-view-sidebar.cjs.map +1 -7
- package/build/components/sidebar/index.cjs +117 -180
- package/build/components/sidebar/index.cjs.map +1 -7
- package/build/components/sidebar/widget-areas.cjs +43 -85
- package/build/components/sidebar/widget-areas.cjs.map +1 -7
- package/build/components/welcome-guide/index.cjs +110 -186
- package/build/components/welcome-guide/index.cjs.map +1 -7
- package/build/components/widget-areas-block-editor-content/index.cjs +59 -64
- package/build/components/widget-areas-block-editor-content/index.cjs.map +1 -7
- package/build/components/widget-areas-block-editor-provider/index.cjs +105 -140
- package/build/components/widget-areas-block-editor-provider/index.cjs.map +1 -7
- package/build/constants.cjs +11 -32
- package/build/constants.cjs.map +1 -7
- package/build/filters/index.cjs +7 -4
- package/build/filters/move-to-widget-area.cjs +38 -53
- package/build/filters/move-to-widget-area.cjs.map +1 -7
- package/build/filters/replace-media-upload.cjs +11 -9
- package/build/filters/replace-media-upload.cjs.map +1 -7
- package/build/hooks/use-last-selected-widget-area.cjs +28 -49
- package/build/hooks/use-last-selected-widget-area.cjs.map +1 -7
- package/build/hooks/use-widget-library-insertion-point.cjs +33 -67
- package/build/hooks/use-widget-library-insertion-point.cjs.map +1 -7
- package/build/index.cjs +96 -97
- package/build/index.cjs.map +1 -7
- package/build/lock-unlock.cjs +10 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/store/actions.cjs +276 -278
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +12 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +61 -52
- package/build/store/index.cjs.map +1 -7
- package/build/store/private-selectors.cjs +11 -32
- package/build/store/private-selectors.cjs.map +1 -7
- package/build/store/reducer.cjs +107 -88
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/resolvers.cjs +60 -91
- package/build/store/resolvers.cjs.map +1 -7
- package/build/store/selectors.cjs +196 -229
- package/build/store/selectors.cjs.map +1 -7
- package/build/store/transformers.cjs +51 -82
- package/build/store/transformers.cjs.map +1 -7
- package/build/store/utils.cjs +76 -63
- package/build/store/utils.cjs.map +1 -7
- package/build-module/blocks/widget-area/edit/index.mjs +82 -94
- package/build-module/blocks/widget-area/edit/index.mjs.map +1 -7
- package/build-module/blocks/widget-area/edit/inner-blocks.mjs +19 -35
- package/build-module/blocks/widget-area/edit/inner-blocks.mjs.map +1 -7
- package/build-module/blocks/widget-area/edit/use-is-dragging-within.mjs +36 -33
- package/build-module/blocks/widget-area/edit/use-is-dragging-within.mjs.map +1 -7
- package/build-module/blocks/widget-area/index.mjs +12 -15
- package/build-module/blocks/widget-area/index.mjs.map +1 -7
- package/build-module/components/error-boundary/index.mjs +104 -129
- package/build-module/components/error-boundary/index.mjs.map +1 -7
- package/build-module/components/header/document-tools/index.mjs +51 -84
- package/build-module/components/header/document-tools/index.mjs.map +1 -7
- package/build-module/components/header/index.mjs +44 -47
- package/build-module/components/header/index.mjs.map +1 -7
- package/build-module/components/header/undo-redo/redo.mjs +20 -27
- package/build-module/components/header/undo-redo/redo.mjs.map +1 -7
- package/build-module/components/header/undo-redo/undo.mjs +19 -26
- package/build-module/components/header/undo-redo/undo.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/config.mjs +83 -61
- package/build-module/components/keyboard-shortcut-help-modal/config.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs +19 -33
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/index.mjs +67 -136
- package/build-module/components/keyboard-shortcut-help-modal/index.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs +32 -54
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs.map +1 -7
- package/build-module/components/keyboard-shortcuts/index.mjs +99 -119
- package/build-module/components/keyboard-shortcuts/index.mjs.map +1 -7
- package/build-module/components/layout/index.mjs +29 -40
- package/build-module/components/layout/index.mjs.map +1 -7
- package/build-module/components/layout/interface.mjs +53 -82
- package/build-module/components/layout/interface.mjs.map +1 -7
- package/build-module/components/layout/unsaved-changes-warning.mjs +35 -27
- package/build-module/components/layout/unsaved-changes-warning.mjs.map +1 -7
- package/build-module/components/more-menu/index.mjs +94 -162
- package/build-module/components/more-menu/index.mjs.map +1 -7
- package/build-module/components/more-menu/tools-more-menu-group.mjs +5 -9
- package/build-module/components/more-menu/tools-more-menu-group.mjs.map +1 -7
- package/build-module/components/notices/index.mjs +12 -17
- package/build-module/components/notices/index.mjs.map +1 -7
- package/build-module/components/save-button/index.mjs +23 -35
- package/build-module/components/save-button/index.mjs.map +1 -7
- package/build-module/components/secondary-sidebar/index.mjs +15 -20
- package/build-module/components/secondary-sidebar/index.mjs.map +1 -7
- package/build-module/components/secondary-sidebar/inserter-sidebar.mjs +27 -25
- package/build-module/components/secondary-sidebar/inserter-sidebar.mjs.map +1 -7
- package/build-module/components/secondary-sidebar/list-view-sidebar.mjs +39 -55
- package/build-module/components/secondary-sidebar/list-view-sidebar.mjs.map +1 -7
- package/build-module/components/sidebar/index.mjs +96 -162
- package/build-module/components/sidebar/index.mjs.map +1 -7
- package/build-module/components/sidebar/widget-areas.mjs +30 -57
- package/build-module/components/sidebar/widget-areas.mjs.map +1 -7
- package/build-module/components/welcome-guide/index.mjs +103 -164
- package/build-module/components/welcome-guide/index.mjs.map +1 -7
- package/build-module/components/widget-areas-block-editor-content/index.mjs +34 -44
- package/build-module/components/widget-areas-block-editor-content/index.mjs.map +1 -7
- package/build-module/components/widget-areas-block-editor-provider/index.mjs +76 -109
- package/build-module/components/widget-areas-block-editor-provider/index.mjs.map +1 -7
- package/build-module/constants.mjs +5 -7
- package/build-module/constants.mjs.map +1 -7
- package/build-module/filters/index.mjs +0 -2
- package/build-module/filters/move-to-widget-area.mjs +28 -48
- package/build-module/filters/move-to-widget-area.mjs.map +1 -7
- package/build-module/filters/replace-media-upload.mjs +5 -8
- package/build-module/filters/replace-media-upload.mjs.map +1 -7
- package/build-module/hooks/use-last-selected-widget-area.mjs +23 -29
- package/build-module/hooks/use-last-selected-widget-area.mjs.map +1 -7
- package/build-module/hooks/use-widget-library-insertion-point.mjs +28 -47
- package/build-module/hooks/use-widget-library-insertion-point.mjs.map +1 -7
- package/build-module/index.mjs +62 -79
- package/build-module/index.mjs.map +1 -7
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/store/actions.mjs +257 -247
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +7 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +18 -16
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/private-selectors.mjs +5 -7
- package/build-module/store/private-selectors.mjs.map +1 -7
- package/build-module/store/reducer.mjs +95 -58
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/resolvers.mjs +52 -71
- package/build-module/store/resolvers.mjs.map +1 -7
- package/build-module/store/selectors.mjs +178 -199
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/store/transformers.mjs +44 -56
- package/build-module/store/transformers.mjs.map +1 -7
- package/build-module/store/utils.mjs +64 -32
- package/build-module/store/utils.mjs.map +1 -7
- package/build-style/style-rtl.css +32 -11
- package/build-style/style.css +32 -11
- package/package.json +33 -33
- package/src/components/error-boundary/index.jsx +2 -2
- package/src/components/header/index.jsx +13 -4
- package/src/components/header/style.scss +30 -3
- package/src/components/keyboard-shortcut-help-modal/shortcut.jsx +1 -0
- package/src/components/keyboard-shortcut-help-modal/style.scss +1 -1
- package/src/components/layout/style.scss +5 -9
- package/src/components/layout/unsaved-changes-warning.js +4 -9
- package/src/components/more-menu/index.jsx +0 -1
- package/src/components/sidebar/index.jsx +18 -18
- package/src/components/welcome-guide/index.jsx +4 -2
- package/src/store/actions.js +25 -2
- package/src/store/test/actions.jsdom.test.js +230 -0
- package/build/filters/index.cjs.map +0 -7
- 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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3
|
+
return state.listViewToggleRef;
|
|
4
4
|
}
|
|
5
5
|
function getInserterSidebarToggleRef(state) {
|
|
6
|
-
|
|
6
|
+
return state.inserterSidebarToggleRef;
|
|
7
7
|
}
|
|
8
|
-
export {
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
101
|
+
blockInserterPanel,
|
|
102
|
+
inserterSidebarToggleRef,
|
|
103
|
+
listViewPanel,
|
|
104
|
+
listViewToggleRef,
|
|
105
|
+
widgetAreasOpenState,
|
|
106
|
+
widgetSavingLock
|
|
63
107
|
});
|
|
64
|
-
export {
|
|
65
|
-
|
|
66
|
-
|
|
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
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
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"}
|