@wordpress/customize-widgets 1.0.18 → 1.0.21
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/components/customize-widgets/index.js +4 -2
- package/build/components/customize-widgets/index.js.map +1 -1
- package/build/components/error-boundary/index.js +67 -0
- package/build/components/error-boundary/index.js.map +1 -0
- package/build/components/inserter/index.js +11 -0
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/use-inserter.js +21 -10
- package/build/components/inserter/use-inserter.js.map +1 -1
- package/build/components/more-menu/index.js +1 -1
- package/build/components/more-menu/index.js.map +1 -1
- package/build/components/sidebar-block-editor/index.js +1 -1
- package/build/components/sidebar-block-editor/index.js.map +1 -1
- package/build/controls/inserter-outer-section.js +25 -13
- package/build/controls/inserter-outer-section.js.map +1 -1
- package/build/controls/sidebar-control.js +9 -1
- package/build/controls/sidebar-control.js.map +1 -1
- package/build/controls/sidebar-section.js +3 -1
- package/build/controls/sidebar-section.js.map +1 -1
- package/build/store/actions.js +21 -0
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +17 -0
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +33 -0
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/customize-widgets/index.js +3 -2
- package/build-module/components/customize-widgets/index.js.map +1 -1
- package/build-module/components/error-boundary/index.js +56 -0
- package/build-module/components/error-boundary/index.js.map +1 -0
- package/build-module/components/inserter/index.js +9 -0
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/use-inserter.js +20 -11
- package/build-module/components/inserter/use-inserter.js.map +1 -1
- package/build-module/components/more-menu/index.js +1 -1
- package/build-module/components/more-menu/index.js.map +1 -1
- package/build-module/components/sidebar-block-editor/index.js +1 -1
- package/build-module/components/sidebar-block-editor/index.js.map +1 -1
- package/build-module/controls/inserter-outer-section.js +22 -12
- package/build-module/controls/inserter-outer-section.js.map +1 -1
- package/build-module/controls/sidebar-control.js +7 -1
- package/build-module/controls/sidebar-control.js.map +1 -1
- package/build-module/controls/sidebar-section.js +3 -1
- package/build-module/controls/sidebar-section.js.map +1 -1
- package/build-module/store/actions.js +19 -0
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +17 -0
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +29 -0
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +18 -18
- package/src/components/customize-widgets/index.js +10 -7
- package/src/components/error-boundary/index.js +50 -0
- package/src/components/inserter/index.js +13 -0
- package/src/components/inserter/use-inserter.js +21 -12
- package/src/components/more-menu/index.js +1 -1
- package/src/components/sidebar-block-editor/index.js +1 -0
- package/src/controls/inserter-outer-section.js +29 -12
- package/src/controls/sidebar-control.js +9 -1
- package/src/controls/sidebar-section.js +1 -1
- package/src/store/actions.js +19 -0
- package/src/store/reducer.js +15 -0
- package/src/store/selectors.js +23 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/customize-widgets/src/controls/sidebar-section.js"],"names":["__","getInspectorSection","getInspectorSectionId","sidebarId","getSidebarSection","wp","customize","window","SidebarSection","Section","ready","InspectorSection","inspector","id","title","parentSection","customizeAction","params","join","section","add","contentContainer","classList","hasSubSectionOpened","expanded","onChangeExpanded","_args","controls","args","completeCallback","forEach","control","onChangeSectionExpanded","manualTransition","addClass","removeClass","closest","one"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,OAAOC,mBAAP,MAAgC,qBAAhC;;AAEA,MAAMC,qBAAqB,GAAKC,SAAF,IAC5B,qBAAqBA,SAAW,EADlC;;AAGA,eAAe,SAASC,iBAAT,GAA6B;AAC3C,QAAM;AACLC,IAAAA,EAAE,EAAE;AAAEC,MAAAA;AAAF;AADC,MAEFC,MAFJ;AAIA,SAAO,MAAMC,cAAN,SAA6BF,SAAS,CAACG,OAAvC,CAA+C;AACrDC,IAAAA,KAAK,GAAG;AACP,YAAMC,gBAAgB,GAAGV,mBAAmB,EAA5C;AACA,WAAKW,SAAL,GAAiB,IAAID,gBAAJ,CAChBT,qBAAqB,CAAE,KAAKW,EAAP,CADL,EAEhB;AACCC,QAAAA,KAAK,EAAEd,EAAE,CAAE,gBAAF,CADV;AAECe,QAAAA,aAAa,EAAE,IAFhB;AAGCC,QAAAA,eAAe,EAAE,CAChBhB,EAAE,CAAE,aAAF,CADc,EAEhBA,EAAE,CAAE,SAAF,CAFc,EAGhB,KAAKiB,MAAL,CAAYH,KAHI,EAIfI,IAJe,CAIT,KAJS;AAHlB,OAFgB,CAAjB;AAYAZ,MAAAA,SAAS,CAACa,OAAV,CAAkBC,GAAlB,CAAuB,KAAKR,SAA5B;AACA,WAAKS,gBAAL,CAAuB,CAAvB,EAA2BC,SAA3B,CAAqCF,GAArC,CACC,oCADD;AAGA;;AACDG,IAAAA,mBAAmB,GAAG;AACrB,aAAO,KAAKX,SAAL,CAAeY,QAAf,EAAP;AACA;;AACDC,IAAAA,gBAAgB,CAAED,QAAF,EAAYE,KAAZ,EAAoB;AACnC,YAAMC,QAAQ,GAAG,KAAKA,QAAL,EAAjB;AACA,YAAMC,IAAI,GAAG,EACZ,GAAGF,KADS;;AAEZG,QAAAA,gBAAgB,GAAG;AAAA;;AAClBF,UAAAA,QAAQ,CAACG,OAAT,CAAoBC,OAAF,IAAe;
|
|
1
|
+
{"version":3,"sources":["@wordpress/customize-widgets/src/controls/sidebar-section.js"],"names":["__","getInspectorSection","getInspectorSectionId","sidebarId","getSidebarSection","wp","customize","window","SidebarSection","Section","ready","InspectorSection","inspector","id","title","parentSection","customizeAction","params","join","section","add","contentContainer","classList","hasSubSectionOpened","expanded","onChangeExpanded","_args","controls","args","completeCallback","forEach","control","onChangeSectionExpanded","manualTransition","addClass","removeClass","closest","one"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,OAAOC,mBAAP,MAAgC,qBAAhC;;AAEA,MAAMC,qBAAqB,GAAKC,SAAF,IAC5B,qBAAqBA,SAAW,EADlC;;AAGA,eAAe,SAASC,iBAAT,GAA6B;AAC3C,QAAM;AACLC,IAAAA,EAAE,EAAE;AAAEC,MAAAA;AAAF;AADC,MAEFC,MAFJ;AAIA,SAAO,MAAMC,cAAN,SAA6BF,SAAS,CAACG,OAAvC,CAA+C;AACrDC,IAAAA,KAAK,GAAG;AACP,YAAMC,gBAAgB,GAAGV,mBAAmB,EAA5C;AACA,WAAKW,SAAL,GAAiB,IAAID,gBAAJ,CAChBT,qBAAqB,CAAE,KAAKW,EAAP,CADL,EAEhB;AACCC,QAAAA,KAAK,EAAEd,EAAE,CAAE,gBAAF,CADV;AAECe,QAAAA,aAAa,EAAE,IAFhB;AAGCC,QAAAA,eAAe,EAAE,CAChBhB,EAAE,CAAE,aAAF,CADc,EAEhBA,EAAE,CAAE,SAAF,CAFc,EAGhB,KAAKiB,MAAL,CAAYH,KAHI,EAIfI,IAJe,CAIT,KAJS;AAHlB,OAFgB,CAAjB;AAYAZ,MAAAA,SAAS,CAACa,OAAV,CAAkBC,GAAlB,CAAuB,KAAKR,SAA5B;AACA,WAAKS,gBAAL,CAAuB,CAAvB,EAA2BC,SAA3B,CAAqCF,GAArC,CACC,oCADD;AAGA;;AACDG,IAAAA,mBAAmB,GAAG;AACrB,aAAO,KAAKX,SAAL,CAAeY,QAAf,EAAP;AACA;;AACDC,IAAAA,gBAAgB,CAAED,QAAF,EAAYE,KAAZ,EAAoB;AACnC,YAAMC,QAAQ,GAAG,KAAKA,QAAL,EAAjB;AACA,YAAMC,IAAI,GAAG,EACZ,GAAGF,KADS;;AAEZG,QAAAA,gBAAgB,GAAG;AAAA;;AAClBF,UAAAA,QAAQ,CAACG,OAAT,CAAoBC,OAAF,IAAe;AAAA;;AAChC,qCAAAA,OAAO,CAACC,uBAAR,qFAAAD,OAAO,EAA4BP,QAA5B,EAAsCI,IAAtC,CAAP;AACA,WAFD;AAGA,mCAAAF,KAAK,CAACG,gBAAN,qFAAAH,KAAK;AACL;;AAPW,OAAb;;AAUA,UAAKE,IAAI,CAACK,gBAAV,EAA6B;AAC5B,YAAKT,QAAL,EAAgB;AACf,eAAKH,gBAAL,CAAsBa,QAAtB,CAAgC,CAAE,MAAF,EAAU,MAAV,CAAhC;AACA,eAAKb,gBAAL,CAAsBc,WAAtB,CAAmC,qBAAnC;AACA,eAAKd,gBAAL,CACEe,OADF,CACW,kBADX,EAEEF,QAFF,CAEY,cAFZ;AAGA,eAAKb,gBAAL,CAAsBgB,GAAtB,CAA2B,eAA3B,EAA4C,MAAM;AACjD,iBAAKhB,gBAAL,CAAsBc,WAAtB,CAAmC,MAAnC;AACAP,YAAAA,IAAI,CAACC,gBAAL;AACA,WAHD;AAIA,SAVD,MAUO;AACN,eAAKR,gBAAL,CAAsBa,QAAtB,CAAgC,CAC/B,MAD+B,EAE/B,qBAF+B,CAAhC;AAIA,eAAKb,gBAAL,CACEe,OADF,CACW,kBADX,EAEEF,QAFF,CAEY,cAFZ;AAGA,eAAKb,gBAAL,CAAsBc,WAAtB,CAAmC,MAAnC;AACA,eAAKd,gBAAL,CAAsBgB,GAAtB,CAA2B,eAA3B,EAA4C,MAAM;AACjD,iBAAKhB,gBAAL,CAAsBc,WAAtB,CAAmC,MAAnC;AACAP,YAAAA,IAAI,CAACC,gBAAL;AACA,WAHD;AAIA;AACD,OAzBD,MAyBO;AACN,cAAMJ,gBAAN,CAAwBD,QAAxB,EAAkCI,IAAlC;AACA;AACD;;AA/DoD,GAAtD;AAiEA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport getInspectorSection from './inspector-section';\n\nconst getInspectorSectionId = ( sidebarId ) =>\n\t`widgets-inspector-${ sidebarId }`;\n\nexport default function getSidebarSection() {\n\tconst {\n\t\twp: { customize },\n\t} = window;\n\n\treturn class SidebarSection extends customize.Section {\n\t\tready() {\n\t\t\tconst InspectorSection = getInspectorSection();\n\t\t\tthis.inspector = new InspectorSection(\n\t\t\t\tgetInspectorSectionId( this.id ),\n\t\t\t\t{\n\t\t\t\t\ttitle: __( 'Block Settings' ),\n\t\t\t\t\tparentSection: this,\n\t\t\t\t\tcustomizeAction: [\n\t\t\t\t\t\t__( 'Customizing' ),\n\t\t\t\t\t\t__( 'Widgets' ),\n\t\t\t\t\t\tthis.params.title,\n\t\t\t\t\t].join( ' ▸ ' ),\n\t\t\t\t}\n\t\t\t);\n\t\t\tcustomize.section.add( this.inspector );\n\t\t\tthis.contentContainer[ 0 ].classList.add(\n\t\t\t\t'customize-widgets__sidebar-section'\n\t\t\t);\n\t\t}\n\t\thasSubSectionOpened() {\n\t\t\treturn this.inspector.expanded();\n\t\t}\n\t\tonChangeExpanded( expanded, _args ) {\n\t\t\tconst controls = this.controls();\n\t\t\tconst args = {\n\t\t\t\t..._args,\n\t\t\t\tcompleteCallback() {\n\t\t\t\t\tcontrols.forEach( ( control ) => {\n\t\t\t\t\t\tcontrol.onChangeSectionExpanded?.( expanded, args );\n\t\t\t\t\t} );\n\t\t\t\t\t_args.completeCallback?.();\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tif ( args.manualTransition ) {\n\t\t\t\tif ( expanded ) {\n\t\t\t\t\tthis.contentContainer.addClass( [ 'busy', 'open' ] );\n\t\t\t\t\tthis.contentContainer.removeClass( 'is-sub-section-open' );\n\t\t\t\t\tthis.contentContainer\n\t\t\t\t\t\t.closest( '.wp-full-overlay' )\n\t\t\t\t\t\t.addClass( 'section-open' );\n\t\t\t\t\tthis.contentContainer.one( 'transitionend', () => {\n\t\t\t\t\t\tthis.contentContainer.removeClass( 'busy' );\n\t\t\t\t\t\targs.completeCallback();\n\t\t\t\t\t} );\n\t\t\t\t} else {\n\t\t\t\t\tthis.contentContainer.addClass( [\n\t\t\t\t\t\t'busy',\n\t\t\t\t\t\t'is-sub-section-open',\n\t\t\t\t\t] );\n\t\t\t\t\tthis.contentContainer\n\t\t\t\t\t\t.closest( '.wp-full-overlay' )\n\t\t\t\t\t\t.addClass( 'section-open' );\n\t\t\t\t\tthis.contentContainer.removeClass( 'open' );\n\t\t\t\t\tthis.contentContainer.one( 'transitionend', () => {\n\t\t\t\t\t\tthis.contentContainer.removeClass( 'busy' );\n\t\t\t\t\t\targs.completeCallback();\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tsuper.onChangeExpanded( expanded, args );\n\t\t\t}\n\t\t}\n\t};\n}\n"]}
|
|
@@ -15,4 +15,23 @@ export function __unstableToggleFeature(feature) {
|
|
|
15
15
|
feature
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns an action object used to open/close the inserter.
|
|
20
|
+
*
|
|
21
|
+
* @param {boolean|Object} value Whether the inserter should be
|
|
22
|
+
* opened (true) or closed (false).
|
|
23
|
+
* To specify an insertion point,
|
|
24
|
+
* use an object.
|
|
25
|
+
* @param {string} value.rootClientId The root client ID to insert at.
|
|
26
|
+
* @param {number} value.insertionIndex The index to insert at.
|
|
27
|
+
*
|
|
28
|
+
* @return {Object} Action object.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
export function setIsInserterOpened(value) {
|
|
32
|
+
return {
|
|
33
|
+
type: 'SET_IS_INSERTER_OPENED',
|
|
34
|
+
value
|
|
35
|
+
};
|
|
36
|
+
}
|
|
18
37
|
//# sourceMappingURL=actions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/customize-widgets/src/store/actions.js"],"names":["__unstableToggleFeature","feature","type"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,uBAAT,CAAkCC,OAAlC,EAA4C;AAClD,SAAO;AACNC,IAAAA,IAAI,EAAE,gBADA;AAEND,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * Returns an action object used to toggle a feature flag.\n *\n * This function is unstable, as it is mostly copied from the edit-post\n * package. Editor features and preferences have a lot of scope for\n * being generalized and refactored.\n *\n * @param {string} feature Feature name.\n *\n * @return {Object} Action object.\n */\nexport function __unstableToggleFeature( feature ) {\n\treturn {\n\t\ttype: 'TOGGLE_FEATURE',\n\t\tfeature,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/customize-widgets/src/store/actions.js"],"names":["__unstableToggleFeature","feature","type","setIsInserterOpened","value"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,uBAAT,CAAkCC,OAAlC,EAA4C;AAClD,SAAO;AACNC,IAAAA,IAAI,EAAE,gBADA;AAEND,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,mBAAT,CAA8BC,KAA9B,EAAsC;AAC5C,SAAO;AACNF,IAAAA,IAAI,EAAE,wBADA;AAENE,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * Returns an action object used to toggle a feature flag.\n *\n * This function is unstable, as it is mostly copied from the edit-post\n * package. Editor features and preferences have a lot of scope for\n * being generalized and refactored.\n *\n * @param {string} feature Feature name.\n *\n * @return {Object} Action object.\n */\nexport function __unstableToggleFeature( feature ) {\n\treturn {\n\t\ttype: 'TOGGLE_FEATURE',\n\t\tfeature,\n\t};\n}\n\n/**\n * Returns an action object used to open/close the inserter.\n *\n * @param {boolean|Object} value Whether the inserter should be\n * opened (true) or closed (false).\n * To specify an insertion point,\n * use an object.\n * @param {string} value.rootClientId The root client ID to insert at.\n * @param {number} value.insertionIndex The index to insert at.\n *\n * @return {Object} Action object.\n */\nexport function setIsInserterOpened( value ) {\n\treturn {\n\t\ttype: 'SET_IS_INSERTER_OPENED',\n\t\tvalue,\n\t};\n}\n"]}
|
|
@@ -24,6 +24,22 @@ import { PREFERENCES_DEFAULTS } from './defaults';
|
|
|
24
24
|
const createWithInitialState = initialState => reducer => {
|
|
25
25
|
return (state = initialState, action) => reducer(state, action);
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Reducer tracking whether the inserter is open.
|
|
29
|
+
*
|
|
30
|
+
* @param {boolean|Object} state
|
|
31
|
+
* @param {Object} action
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
function blockInserterPanel(state = false, action) {
|
|
36
|
+
switch (action.type) {
|
|
37
|
+
case 'SET_IS_INSERTER_OPENED':
|
|
38
|
+
return action.value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return state;
|
|
42
|
+
}
|
|
27
43
|
/**
|
|
28
44
|
* Reducer returning the user preferences.
|
|
29
45
|
*
|
|
@@ -47,6 +63,7 @@ export const preferences = flow([combineReducers, createWithInitialState(PREFERE
|
|
|
47
63
|
|
|
48
64
|
});
|
|
49
65
|
export default combineReducers({
|
|
66
|
+
blockInserterPanel,
|
|
50
67
|
preferences
|
|
51
68
|
});
|
|
52
69
|
//# sourceMappingURL=reducer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/customize-widgets/src/store/reducer.js"],"names":["flow","combineReducers","PREFERENCES_DEFAULTS","createWithInitialState","initialState","reducer","state","action","
|
|
1
|
+
{"version":3,"sources":["@wordpress/customize-widgets/src/store/reducer.js"],"names":["flow","combineReducers","PREFERENCES_DEFAULTS","createWithInitialState","initialState","reducer","state","action","blockInserterPanel","type","value","preferences","features","feature"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,QAArB;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,iBAAhC;AAEA;AACA;AACA;;AACA,SAASC,oBAAT,QAAqC,YAArC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAKC,YAAF,IAAsBC,OAAF,IAAe;AACjE,SAAO,CAAEC,KAAK,GAAGF,YAAV,EAAwBG,MAAxB,KAAoCF,OAAO,CAAEC,KAAF,EAASC,MAAT,CAAlD;AACA,CAFD;AAIA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,kBAAT,CAA6BF,KAAK,GAAG,KAArC,EAA4CC,MAA5C,EAAqD;AACpD,UAASA,MAAM,CAACE,IAAhB;AACC,SAAK,wBAAL;AACC,aAAOF,MAAM,CAACG,KAAd;AAFF;;AAIA,SAAOJ,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,MAAMK,WAAW,GAAGX,IAAI,CAAE,CAChCC,eADgC,EAEhCE,sBAAsB,CAAED,oBAAF,CAFU,CAAF,CAAJ,CAGtB;AACJU,EAAAA,QAAQ,CAAEN,KAAF,EAASC,MAAT,EAAkB;AACzB,QAAKA,MAAM,CAACE,IAAP,KAAgB,gBAArB,EAAwC;AACvC,aAAO,EACN,GAAGH,KADG;AAEN,SAAEC,MAAM,CAACM,OAAT,GAAoB,CAAEP,KAAK,CAAEC,MAAM,CAACM,OAAT;AAFrB,OAAP;AAIA;;AAED,WAAOP,KAAP;AACA;;AAVG,CAHsB,CAApB;AAgBP,eAAeL,eAAe,CAAE;AAC/BO,EAAAA,kBAD+B;AAE/BG,EAAAA;AAF+B,CAAF,CAA9B","sourcesContent":["/**\n * External dependencies\n */\nimport { flow } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { PREFERENCES_DEFAULTS } from './defaults';\n\n/**\n * Higher-order reducer creator which provides the given initial state for the\n * original reducer.\n *\n * @param {*} initialState Initial state to provide to reducer.\n *\n * @return {Function} Higher-order reducer.\n */\nconst createWithInitialState = ( initialState ) => ( reducer ) => {\n\treturn ( state = initialState, action ) => reducer( state, action );\n};\n\n/**\n * Reducer tracking whether the inserter is open.\n *\n * @param {boolean|Object} state\n * @param {Object} action\n */\nfunction blockInserterPanel( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IS_INSERTER_OPENED':\n\t\t\treturn action.value;\n\t}\n\treturn state;\n}\n\n/**\n * Reducer returning the user preferences.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const preferences = flow( [\n\tcombineReducers,\n\tcreateWithInitialState( PREFERENCES_DEFAULTS ),\n] )( {\n\tfeatures( state, action ) {\n\t\tif ( action.type === 'TOGGLE_FEATURE' ) {\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.feature ]: ! state[ action.feature ],\n\t\t\t};\n\t\t}\n\n\t\treturn state;\n\t},\n} );\n\nexport default combineReducers( {\n\tblockInserterPanel,\n\tpreferences,\n} );\n"]}
|
|
@@ -18,4 +18,33 @@ import { get } from 'lodash';
|
|
|
18
18
|
export function __unstableIsFeatureActive(state, feature) {
|
|
19
19
|
return get(state.preferences.features, [feature], false);
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns true if the inserter is opened.
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} state Global application state.
|
|
25
|
+
*
|
|
26
|
+
* @return {boolean} Whether the inserter is opened.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
export function isInserterOpened(state) {
|
|
30
|
+
return !!state.blockInserterPanel;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get the insertion point for the inserter.
|
|
34
|
+
*
|
|
35
|
+
* @param {Object} state Global application state.
|
|
36
|
+
*
|
|
37
|
+
* @return {Object} The root client ID and index to insert at.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
export function __experimentalGetInsertionPoint(state) {
|
|
41
|
+
const {
|
|
42
|
+
rootClientId,
|
|
43
|
+
insertionIndex
|
|
44
|
+
} = state.blockInserterPanel;
|
|
45
|
+
return {
|
|
46
|
+
rootClientId,
|
|
47
|
+
insertionIndex
|
|
48
|
+
};
|
|
49
|
+
}
|
|
21
50
|
//# sourceMappingURL=selectors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/customize-widgets/src/store/selectors.js"],"names":["get","__unstableIsFeatureActive","state","feature","preferences","features"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,yBAAT,CAAoCC,KAApC,EAA2CC,OAA3C,EAAqD;AAC3D,SAAOH,GAAG,CAAEE,KAAK,CAACE,WAAN,CAAkBC,QAApB,EAA8B,CAAEF,OAAF,CAA9B,EAA2C,KAA3C,CAAV;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * Returns whether the given feature is enabled or not.\n *\n * This function is unstable, as it is mostly copied from the edit-post\n * package. Editor features and preferences have a lot of scope for\n * being generalized and refactored.\n *\n * @param {Object} state Global application state.\n * @param {string} feature Feature slug.\n *\n * @return {boolean} Is active.\n */\nexport function __unstableIsFeatureActive( state, feature ) {\n\treturn get( state.preferences.features, [ feature ], false );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/customize-widgets/src/store/selectors.js"],"names":["get","__unstableIsFeatureActive","state","feature","preferences","features","isInserterOpened","blockInserterPanel","__experimentalGetInsertionPoint","rootClientId","insertionIndex"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,yBAAT,CAAoCC,KAApC,EAA2CC,OAA3C,EAAqD;AAC3D,SAAOH,GAAG,CAAEE,KAAK,CAACE,WAAN,CAAkBC,QAApB,EAA8B,CAAEF,OAAF,CAA9B,EAA2C,KAA3C,CAAV;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,gBAAT,CAA2BJ,KAA3B,EAAmC;AACzC,SAAO,CAAC,CAAEA,KAAK,CAACK,kBAAhB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,+BAAT,CAA0CN,KAA1C,EAAkD;AACxD,QAAM;AAAEO,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAAmCR,KAAK,CAACK,kBAA/C;AACA,SAAO;AAAEE,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,GAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * Returns whether the given feature is enabled or not.\n *\n * This function is unstable, as it is mostly copied from the edit-post\n * package. Editor features and preferences have a lot of scope for\n * being generalized and refactored.\n *\n * @param {Object} state Global application state.\n * @param {string} feature Feature slug.\n *\n * @return {boolean} Is active.\n */\nexport function __unstableIsFeatureActive( state, feature ) {\n\treturn get( state.preferences.features, [ feature ], false );\n}\n\n/**\n * Returns true if the inserter is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the inserter is opened.\n */\nexport function isInserterOpened( state ) {\n\treturn !! state.blockInserterPanel;\n}\n\n/**\n * Get the insertion point for the inserter.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} The root client ID and index to insert at.\n */\nexport function __experimentalGetInsertionPoint( state ) {\n\tconst { rootClientId, insertionIndex } = state.blockInserterPanel;\n\treturn { rootClientId, insertionIndex };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/customize-widgets",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"description": "Widgets blocks in Customizer Module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -24,29 +24,29 @@
|
|
|
24
24
|
"react-native": "src/index",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.11.2",
|
|
27
|
-
"@wordpress/a11y": "^3.1.
|
|
28
|
-
"@wordpress/block-editor": "^6.1.
|
|
29
|
-
"@wordpress/block-library": "^3.2.
|
|
30
|
-
"@wordpress/blocks": "^9.1.
|
|
31
|
-
"@wordpress/components": "^14.1.
|
|
32
|
-
"@wordpress/compose": "^4.1.
|
|
33
|
-
"@wordpress/core-data": "^3.1.
|
|
34
|
-
"@wordpress/data": "^5.1.
|
|
35
|
-
"@wordpress/dom": "^3.1.
|
|
36
|
-
"@wordpress/element": "^3.1.
|
|
27
|
+
"@wordpress/a11y": "^3.1.2",
|
|
28
|
+
"@wordpress/block-editor": "^6.1.15",
|
|
29
|
+
"@wordpress/block-library": "^3.2.20",
|
|
30
|
+
"@wordpress/blocks": "^9.1.8",
|
|
31
|
+
"@wordpress/components": "^14.1.11",
|
|
32
|
+
"@wordpress/compose": "^4.1.6",
|
|
33
|
+
"@wordpress/core-data": "^3.1.13",
|
|
34
|
+
"@wordpress/data": "^5.1.6",
|
|
35
|
+
"@wordpress/dom": "^3.1.5",
|
|
36
|
+
"@wordpress/element": "^3.1.2",
|
|
37
37
|
"@wordpress/hooks": "^3.1.1",
|
|
38
|
-
"@wordpress/i18n": "^4.1.
|
|
39
|
-
"@wordpress/icons": "^4.0.
|
|
38
|
+
"@wordpress/i18n": "^4.1.2",
|
|
39
|
+
"@wordpress/icons": "^4.0.3",
|
|
40
40
|
"@wordpress/is-shallow-equal": "^4.1.1",
|
|
41
|
-
"@wordpress/keyboard-shortcuts": "^2.1.
|
|
42
|
-
"@wordpress/keycodes": "^3.1.
|
|
43
|
-
"@wordpress/media-utils": "^2.1.
|
|
44
|
-
"@wordpress/widgets": "^1.1.
|
|
41
|
+
"@wordpress/keyboard-shortcuts": "^2.1.7",
|
|
42
|
+
"@wordpress/keycodes": "^3.1.2",
|
|
43
|
+
"@wordpress/media-utils": "^2.1.3",
|
|
44
|
+
"@wordpress/widgets": "^1.1.20",
|
|
45
45
|
"classnames": "^2.2.6",
|
|
46
46
|
"lodash": "^4.17.21"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "6464883c6c546233543a1ee01428059dee3560fc"
|
|
52
52
|
}
|
|
@@ -7,6 +7,7 @@ import { SlotFillProvider, Popover } from '@wordpress/components';
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
+
import ErrorBoundary from '../error-boundary';
|
|
10
11
|
import SidebarBlockEditor from '../sidebar-block-editor';
|
|
11
12
|
import FocusControl from '../focus-control';
|
|
12
13
|
import SidebarControls from '../sidebar-controls';
|
|
@@ -42,13 +43,15 @@ export default function CustomizeWidgets( {
|
|
|
42
43
|
const activeSidebar =
|
|
43
44
|
activeSidebarControl &&
|
|
44
45
|
createPortal(
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
<ErrorBoundary>
|
|
47
|
+
<SidebarBlockEditor
|
|
48
|
+
key={ activeSidebarControl.id }
|
|
49
|
+
blockEditorSettings={ blockEditorSettings }
|
|
50
|
+
sidebar={ activeSidebarControl.sidebarAdapter }
|
|
51
|
+
inserter={ activeSidebarControl.inserter }
|
|
52
|
+
inspector={ activeSidebarControl.inspector }
|
|
53
|
+
/>
|
|
54
|
+
</ErrorBoundary>,
|
|
52
55
|
activeSidebarControl.container[ 0 ]
|
|
53
56
|
);
|
|
54
57
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Component } from '@wordpress/element';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
import { Button } from '@wordpress/components';
|
|
7
|
+
import { Warning } from '@wordpress/block-editor';
|
|
8
|
+
import { useCopyToClipboard } from '@wordpress/compose';
|
|
9
|
+
|
|
10
|
+
function CopyButton( { text, children } ) {
|
|
11
|
+
const ref = useCopyToClipboard( text );
|
|
12
|
+
return (
|
|
13
|
+
<Button variant="secondary" ref={ ref }>
|
|
14
|
+
{ children }
|
|
15
|
+
</Button>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default class ErrorBoundary extends Component {
|
|
20
|
+
constructor() {
|
|
21
|
+
super( ...arguments );
|
|
22
|
+
this.state = {
|
|
23
|
+
error: null,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
componentDidCatch( error ) {
|
|
28
|
+
this.setState( { error } );
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
render() {
|
|
32
|
+
const { error } = this.state;
|
|
33
|
+
if ( ! error ) {
|
|
34
|
+
return this.props.children;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Warning
|
|
39
|
+
className="customize-widgets-error-boundary"
|
|
40
|
+
actions={ [
|
|
41
|
+
<CopyButton key="copy-error" text={ error.stack }>
|
|
42
|
+
{ __( 'Copy Error' ) }
|
|
43
|
+
</CopyButton>,
|
|
44
|
+
] }
|
|
45
|
+
>
|
|
46
|
+
{ __( 'The editor has encountered an unexpected error.' ) }
|
|
47
|
+
</Warning>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -5,13 +5,22 @@ import { __ } from '@wordpress/i18n';
|
|
|
5
5
|
import { __experimentalLibrary as Library } from '@wordpress/block-editor';
|
|
6
6
|
import { Button } from '@wordpress/components';
|
|
7
7
|
import { useInstanceId } from '@wordpress/compose';
|
|
8
|
+
import { useSelect } from '@wordpress/data';
|
|
8
9
|
import { closeSmall } from '@wordpress/icons';
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { store as customizeWidgetsStore } from '../../store';
|
|
15
|
+
|
|
10
16
|
function Inserter( { setIsOpened } ) {
|
|
11
17
|
const inserterTitleId = useInstanceId(
|
|
12
18
|
Inserter,
|
|
13
19
|
'customize-widget-layout__inserter-panel-title'
|
|
14
20
|
);
|
|
21
|
+
const insertionPoint = useSelect( ( select ) =>
|
|
22
|
+
select( customizeWidgetsStore ).__experimentalGetInsertionPoint()
|
|
23
|
+
);
|
|
15
24
|
|
|
16
25
|
return (
|
|
17
26
|
<div
|
|
@@ -34,6 +43,10 @@ function Inserter( { setIsOpened } ) {
|
|
|
34
43
|
</div>
|
|
35
44
|
<div className="customize-widgets-layout__inserter-panel-content">
|
|
36
45
|
<Library
|
|
46
|
+
rootClientId={ insertionPoint.rootClientId }
|
|
47
|
+
__experimentalInsertionIndex={
|
|
48
|
+
insertionPoint.insertionIndex
|
|
49
|
+
}
|
|
37
50
|
showInserterHelpPanel
|
|
38
51
|
onSelect={ () => setIsOpened( false ) }
|
|
39
52
|
/>
|
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { useEffect, useCallback } from '@wordpress/element';
|
|
5
|
+
import { useSelect, useDispatch, select as selectStore } from '@wordpress/data';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { store as customizeWidgetsStore } from '../../store';
|
|
5
11
|
|
|
6
12
|
export default function useInserter( inserter ) {
|
|
7
|
-
const
|
|
8
|
-
(
|
|
13
|
+
const isInserterOpened = useSelect( ( select ) =>
|
|
14
|
+
select( customizeWidgetsStore ).isInserterOpened()
|
|
9
15
|
);
|
|
16
|
+
const { setIsInserterOpened } = useDispatch( customizeWidgetsStore );
|
|
10
17
|
|
|
11
18
|
useEffect( () => {
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
if ( isInserterOpened ) {
|
|
20
|
+
inserter.open();
|
|
21
|
+
} else {
|
|
22
|
+
inserter.close();
|
|
23
|
+
}
|
|
24
|
+
}, [ inserter, isInserterOpened ] );
|
|
14
25
|
|
|
15
26
|
return [
|
|
16
27
|
isInserterOpened,
|
|
@@ -18,16 +29,14 @@ export default function useInserter( inserter ) {
|
|
|
18
29
|
( updater ) => {
|
|
19
30
|
let isOpen = updater;
|
|
20
31
|
if ( typeof updater === 'function' ) {
|
|
21
|
-
isOpen = updater(
|
|
32
|
+
isOpen = updater(
|
|
33
|
+
selectStore( customizeWidgetsStore ).isInserterOpened()
|
|
34
|
+
);
|
|
22
35
|
}
|
|
23
36
|
|
|
24
|
-
|
|
25
|
-
inserter.open();
|
|
26
|
-
} else {
|
|
27
|
-
inserter.close();
|
|
28
|
-
}
|
|
37
|
+
setIsInserterOpened( isOpen );
|
|
29
38
|
},
|
|
30
|
-
[
|
|
39
|
+
[ setIsInserterOpened ]
|
|
31
40
|
),
|
|
32
41
|
];
|
|
33
42
|
}
|
|
@@ -87,7 +87,7 @@ export default function MoreMenu() {
|
|
|
87
87
|
role="menuitem"
|
|
88
88
|
icon={ external }
|
|
89
89
|
href={ __(
|
|
90
|
-
'https://wordpress.org/support/article/
|
|
90
|
+
'https://wordpress.org/support/article/block-based-widgets-editor/'
|
|
91
91
|
) }
|
|
92
92
|
target="_blank"
|
|
93
93
|
rel="noopener noreferrer"
|
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { ESCAPE } from '@wordpress/keycodes';
|
|
5
5
|
import { focus } from '@wordpress/dom';
|
|
6
|
+
import { dispatch } from '@wordpress/data';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { store as customizeWidgetsStore } from '../store';
|
|
6
12
|
|
|
7
13
|
export default function getInserterOuterSection() {
|
|
8
14
|
const {
|
|
@@ -52,12 +58,13 @@ export default function getInserterOuterSection() {
|
|
|
52
58
|
'keydown',
|
|
53
59
|
( event ) => {
|
|
54
60
|
if (
|
|
55
|
-
this.
|
|
61
|
+
this.expanded() &&
|
|
56
62
|
( event.keyCode === ESCAPE || event.code === 'Escape' )
|
|
57
63
|
) {
|
|
58
64
|
event.stopPropagation();
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
dispatch( customizeWidgetsStore ).setIsInserterOpened(
|
|
66
|
+
false
|
|
67
|
+
);
|
|
61
68
|
}
|
|
62
69
|
},
|
|
63
70
|
// Use capture mode to make this run before other event listeners.
|
|
@@ -65,20 +72,28 @@ export default function getInserterOuterSection() {
|
|
|
65
72
|
);
|
|
66
73
|
|
|
67
74
|
this.contentContainer.addClass( 'widgets-inserter' );
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
|
|
76
|
+
// Set a flag if the state is being changed from open() or close().
|
|
77
|
+
// Don't propagate the event if it's an internal action to prevent infinite loop.
|
|
78
|
+
this.isFromInternalAction = false;
|
|
79
|
+
this.expanded.bind( () => {
|
|
80
|
+
if ( ! this.isFromInternalAction ) {
|
|
81
|
+
// Propagate the event to React to sync the state.
|
|
82
|
+
dispatch( customizeWidgetsStore ).setIsInserterOpened(
|
|
83
|
+
this.expanded()
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
this.isFromInternalAction = false;
|
|
87
|
+
} );
|
|
75
88
|
}
|
|
76
89
|
open() {
|
|
77
|
-
if ( ! this.
|
|
90
|
+
if ( ! this.expanded() ) {
|
|
78
91
|
const contentContainer = this.contentContainer[ 0 ];
|
|
79
92
|
this.activeElementBeforeExpanded =
|
|
80
93
|
contentContainer.ownerDocument.activeElement;
|
|
81
94
|
|
|
95
|
+
this.isFromInternalAction = true;
|
|
96
|
+
|
|
82
97
|
this.expand( {
|
|
83
98
|
completeCallback() {
|
|
84
99
|
// We have to do this in a "completeCallback" or else the elements will not yet be visible/tabbable.
|
|
@@ -95,11 +110,13 @@ export default function getInserterOuterSection() {
|
|
|
95
110
|
}
|
|
96
111
|
}
|
|
97
112
|
close() {
|
|
98
|
-
if ( this.
|
|
113
|
+
if ( this.expanded() ) {
|
|
99
114
|
const contentContainer = this.contentContainer[ 0 ];
|
|
100
115
|
const activeElement =
|
|
101
116
|
contentContainer.ownerDocument.activeElement;
|
|
102
117
|
|
|
118
|
+
this.isFromInternalAction = true;
|
|
119
|
+
|
|
103
120
|
this.collapse( {
|
|
104
121
|
completeCallback() {
|
|
105
122
|
// Return back the focus when closing the inserter.
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { dispatch } from '@wordpress/data';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* Internal dependencies
|
|
3
8
|
*/
|
|
4
9
|
import SidebarAdapter from '../components/sidebar-block-editor/sidebar-adapter';
|
|
5
10
|
import getInserterOuterSection from './inserter-outer-section';
|
|
11
|
+
import { store as customizeWidgetsStore } from '../store';
|
|
6
12
|
|
|
7
13
|
const getInserterId = ( controlId ) => `widgets-inserter-${ controlId }`;
|
|
8
14
|
|
|
@@ -45,7 +51,9 @@ export default function getSidebarControl() {
|
|
|
45
51
|
if ( ! args.unchanged ) {
|
|
46
52
|
// Close the inserter when the section collapses.
|
|
47
53
|
if ( ! expanded ) {
|
|
48
|
-
|
|
54
|
+
dispatch( customizeWidgetsStore ).setIsInserterOpened(
|
|
55
|
+
false
|
|
56
|
+
);
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
this.subscribers.forEach( ( subscriber ) =>
|
|
@@ -45,7 +45,7 @@ export default function getSidebarSection() {
|
|
|
45
45
|
..._args,
|
|
46
46
|
completeCallback() {
|
|
47
47
|
controls.forEach( ( control ) => {
|
|
48
|
-
control.onChangeSectionExpanded( expanded, args );
|
|
48
|
+
control.onChangeSectionExpanded?.( expanded, args );
|
|
49
49
|
} );
|
|
50
50
|
_args.completeCallback?.();
|
|
51
51
|
},
|
package/src/store/actions.js
CHANGED
|
@@ -15,3 +15,22 @@ export function __unstableToggleFeature( feature ) {
|
|
|
15
15
|
feature,
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Returns an action object used to open/close the inserter.
|
|
21
|
+
*
|
|
22
|
+
* @param {boolean|Object} value Whether the inserter should be
|
|
23
|
+
* opened (true) or closed (false).
|
|
24
|
+
* To specify an insertion point,
|
|
25
|
+
* use an object.
|
|
26
|
+
* @param {string} value.rootClientId The root client ID to insert at.
|
|
27
|
+
* @param {number} value.insertionIndex The index to insert at.
|
|
28
|
+
*
|
|
29
|
+
* @return {Object} Action object.
|
|
30
|
+
*/
|
|
31
|
+
export function setIsInserterOpened( value ) {
|
|
32
|
+
return {
|
|
33
|
+
type: 'SET_IS_INSERTER_OPENED',
|
|
34
|
+
value,
|
|
35
|
+
};
|
|
36
|
+
}
|
package/src/store/reducer.js
CHANGED
|
@@ -25,6 +25,20 @@ const createWithInitialState = ( initialState ) => ( reducer ) => {
|
|
|
25
25
|
return ( state = initialState, action ) => reducer( state, action );
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Reducer tracking whether the inserter is open.
|
|
30
|
+
*
|
|
31
|
+
* @param {boolean|Object} state
|
|
32
|
+
* @param {Object} action
|
|
33
|
+
*/
|
|
34
|
+
function blockInserterPanel( state = false, action ) {
|
|
35
|
+
switch ( action.type ) {
|
|
36
|
+
case 'SET_IS_INSERTER_OPENED':
|
|
37
|
+
return action.value;
|
|
38
|
+
}
|
|
39
|
+
return state;
|
|
40
|
+
}
|
|
41
|
+
|
|
28
42
|
/**
|
|
29
43
|
* Reducer returning the user preferences.
|
|
30
44
|
*
|
|
@@ -50,5 +64,6 @@ export const preferences = flow( [
|
|
|
50
64
|
} );
|
|
51
65
|
|
|
52
66
|
export default combineReducers( {
|
|
67
|
+
blockInserterPanel,
|
|
53
68
|
preferences,
|
|
54
69
|
} );
|
package/src/store/selectors.js
CHANGED
|
@@ -18,3 +18,26 @@ import { get } from 'lodash';
|
|
|
18
18
|
export function __unstableIsFeatureActive( state, feature ) {
|
|
19
19
|
return get( state.preferences.features, [ feature ], false );
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns true if the inserter is opened.
|
|
24
|
+
*
|
|
25
|
+
* @param {Object} state Global application state.
|
|
26
|
+
*
|
|
27
|
+
* @return {boolean} Whether the inserter is opened.
|
|
28
|
+
*/
|
|
29
|
+
export function isInserterOpened( state ) {
|
|
30
|
+
return !! state.blockInserterPanel;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get the insertion point for the inserter.
|
|
35
|
+
*
|
|
36
|
+
* @param {Object} state Global application state.
|
|
37
|
+
*
|
|
38
|
+
* @return {Object} The root client ID and index to insert at.
|
|
39
|
+
*/
|
|
40
|
+
export function __experimentalGetInsertionPoint( state ) {
|
|
41
|
+
const { rootClientId, insertionIndex } = state.blockInserterPanel;
|
|
42
|
+
return { rootClientId, insertionIndex };
|
|
43
|
+
}
|