@wordpress/block-editor 11.3.0 → 11.3.2
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/block-actions/index.js +7 -2
- package/build/components/block-actions/index.js.map +1 -1
- package/build/components/block-inspector/index.js +1 -2
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/iframe/index.js +5 -3
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +15 -4
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/menu.js +4 -1
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inspector-controls-tabs/settings-tab-hint.js +62 -0
- package/build/components/inspector-controls-tabs/settings-tab-hint.js.map +1 -0
- package/build/components/inspector-controls-tabs/settings-tab.js +3 -1
- package/build/components/inspector-controls-tabs/settings-tab.js.map +1 -1
- package/build/components/off-canvas-editor/block-contents.js +3 -1
- package/build/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build/components/off-canvas-editor/index.js +16 -4
- package/build/components/off-canvas-editor/index.js.map +1 -1
- package/build/components/provider/use-block-sync.js +4 -1
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/hooks/position.js +5 -2
- package/build/hooks/position.js.map +1 -1
- package/build/store/defaults.js +12 -0
- package/build/store/defaults.js.map +1 -1
- package/build/store/private-actions.js +1 -1
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +14 -0
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/selectors.js +0 -14
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-actions/index.js +7 -2
- package/build-module/components/block-actions/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +1 -2
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/iframe/index.js +6 -4
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +15 -5
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/menu.js +4 -1
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/settings-tab-hint.js +48 -0
- package/build-module/components/inspector-controls-tabs/settings-tab-hint.js.map +1 -0
- package/build-module/components/inspector-controls-tabs/settings-tab.js +2 -1
- package/build-module/components/inspector-controls-tabs/settings-tab.js.map +1 -1
- package/build-module/components/off-canvas-editor/block-contents.js +2 -1
- package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build-module/components/off-canvas-editor/index.js +16 -4
- package/build-module/components/off-canvas-editor/index.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +4 -1
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/hooks/position.js +5 -2
- package/build-module/hooks/position.js.map +1 -1
- package/build-module/store/defaults.js +12 -0
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/private-actions.js +1 -1
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +12 -0
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/selectors.js +0 -12
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +18 -0
- package/build-style/style.css +18 -0
- package/package.json +31 -30
- package/src/components/block-actions/index.js +9 -0
- package/src/components/block-inspector/index.js +1 -1
- package/src/components/iframe/index.js +8 -2
- package/src/components/inserter/block-patterns-tab.js +30 -6
- package/src/components/inserter/menu.js +8 -1
- package/src/components/inspector-controls-tabs/settings-tab-hint.js +52 -0
- package/src/components/inspector-controls-tabs/settings-tab.js +2 -0
- package/src/components/inspector-controls-tabs/style.scss +20 -0
- package/src/components/off-canvas-editor/block-contents.js +2 -1
- package/src/components/off-canvas-editor/index.js +18 -3
- package/src/components/provider/use-block-sync.js +4 -1
- package/src/hooks/position.js +4 -0
- package/src/store/defaults.js +7 -0
- package/src/store/private-actions.js +4 -1
- package/src/store/private-selectors.js +10 -0
- package/src/store/selectors.js +0 -10
- package/src/store/test/private-selectors.js +29 -1
- package/src/store/test/selectors.js +0 -24
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createElement } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WordPress dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { Button } from '@wordpress/components';
|
|
7
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
8
|
+
import { focus } from '@wordpress/dom';
|
|
9
|
+
import { useRef } from '@wordpress/element';
|
|
10
|
+
import { __ } from '@wordpress/i18n';
|
|
11
|
+
import { close } from '@wordpress/icons';
|
|
12
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
13
|
+
const PREFERENCE_NAME = 'isInspectorControlsTabsHintVisible';
|
|
14
|
+
export default function InspectorControlsTabsHint() {
|
|
15
|
+
const isInspectorControlsTabsHintVisible = useSelect(select => {
|
|
16
|
+
var _select$get;
|
|
17
|
+
|
|
18
|
+
return (_select$get = select(preferencesStore).get('core', PREFERENCE_NAME)) !== null && _select$get !== void 0 ? _select$get : true;
|
|
19
|
+
}, []);
|
|
20
|
+
const ref = useRef();
|
|
21
|
+
const {
|
|
22
|
+
set: setPreference
|
|
23
|
+
} = useDispatch(preferencesStore);
|
|
24
|
+
|
|
25
|
+
if (!isInspectorControlsTabsHintVisible) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return createElement("div", {
|
|
30
|
+
ref: ref,
|
|
31
|
+
className: "block-editor-inspector-controls-tabs__hint"
|
|
32
|
+
}, createElement("div", {
|
|
33
|
+
className: "block-editor-inspector-controls-tabs__hint-content"
|
|
34
|
+
}, __("Looking for other block settings? They've moved to the styles tab.")), createElement(Button, {
|
|
35
|
+
className: "block-editor-inspector-controls-tabs__hint-dismiss",
|
|
36
|
+
icon: close,
|
|
37
|
+
iconSize: "16",
|
|
38
|
+
label: __('Dismiss hint'),
|
|
39
|
+
onClick: () => {
|
|
40
|
+
// Retain focus when dismissing the element.
|
|
41
|
+
const previousElement = focus.tabbable.findPrevious(ref.current);
|
|
42
|
+
previousElement === null || previousElement === void 0 ? void 0 : previousElement.focus();
|
|
43
|
+
setPreference('core', PREFERENCE_NAME, false);
|
|
44
|
+
},
|
|
45
|
+
showTooltip: false
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=settings-tab-hint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inspector-controls-tabs/settings-tab-hint.js"],"names":["Button","useDispatch","useSelect","focus","useRef","__","close","store","preferencesStore","PREFERENCE_NAME","InspectorControlsTabsHint","isInspectorControlsTabsHintVisible","select","get","ref","set","setPreference","previousElement","tabbable","findPrevious","current"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAT,QAAuB,uBAAvB;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,KAAT,QAAsB,gBAAtB;AACA,SAASC,MAAT,QAAuB,oBAAvB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAT,QAAsB,kBAAtB;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,wBAA1C;AAEA,MAAMC,eAAe,GAAG,oCAAxB;AAEA,eAAe,SAASC,yBAAT,GAAqC;AACnD,QAAMC,kCAAkC,GAAGT,SAAS,CACjDU,MAAF;AAAA;;AAAA,0BACCA,MAAM,CAAEJ,gBAAF,CAAN,CAA2BK,GAA3B,CAAgC,MAAhC,EAAwCJ,eAAxC,CADD,qDAC8D,IAD9D;AAAA,GADmD,EAGnD,EAHmD,CAApD;AAMA,QAAMK,GAAG,GAAGV,MAAM,EAAlB;AAEA,QAAM;AAAEW,IAAAA,GAAG,EAAEC;AAAP,MAAyBf,WAAW,CAAEO,gBAAF,CAA1C;;AACA,MAAK,CAAEG,kCAAP,EAA4C;AAC3C,WAAO,IAAP;AACA;;AAED,SACC;AAAK,IAAA,GAAG,EAAGG,GAAX;AAAiB,IAAA,SAAS,EAAC;AAA3B,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGT,EAAE,CACH,oEADG,CADL,CADD,EAMC,cAAC,MAAD;AACC,IAAA,SAAS,EAAC,oDADX;AAEC,IAAA,IAAI,EAAGC,KAFR;AAGC,IAAA,QAAQ,EAAC,IAHV;AAIC,IAAA,KAAK,EAAGD,EAAE,CAAE,cAAF,CAJX;AAKC,IAAA,OAAO,EAAG,MAAM;AACf;AACA,YAAMY,eAAe,GAAGd,KAAK,CAACe,QAAN,CAAeC,YAAf,CACvBL,GAAG,CAACM,OADmB,CAAxB;AAGAH,MAAAA,eAAe,SAAf,IAAAA,eAAe,WAAf,YAAAA,eAAe,CAAEd,KAAjB;AACAa,MAAAA,aAAa,CAAE,MAAF,EAAUP,eAAV,EAA2B,KAA3B,CAAb;AACA,KAZF;AAaC,IAAA,WAAW,EAAG;AAbf,IAND,CADD;AAwBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { focus } from '@wordpress/dom';\nimport { useRef } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { close } from '@wordpress/icons';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\nconst PREFERENCE_NAME = 'isInspectorControlsTabsHintVisible';\n\nexport default function InspectorControlsTabsHint() {\n\tconst isInspectorControlsTabsHintVisible = useSelect(\n\t\t( select ) =>\n\t\t\tselect( preferencesStore ).get( 'core', PREFERENCE_NAME ) ?? true,\n\t\t[]\n\t);\n\n\tconst ref = useRef();\n\n\tconst { set: setPreference } = useDispatch( preferencesStore );\n\tif ( ! isInspectorControlsTabsHintVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div ref={ ref } className=\"block-editor-inspector-controls-tabs__hint\">\n\t\t\t<div className=\"block-editor-inspector-controls-tabs__hint-content\">\n\t\t\t\t{ __(\n\t\t\t\t\t\"Looking for other block settings? They've moved to the styles tab.\"\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t<Button\n\t\t\t\tclassName=\"block-editor-inspector-controls-tabs__hint-dismiss\"\n\t\t\t\ticon={ close }\n\t\t\t\ticonSize=\"16\"\n\t\t\t\tlabel={ __( 'Dismiss hint' ) }\n\t\t\t\tonClick={ () => {\n\t\t\t\t\t// Retain focus when dismissing the element.\n\t\t\t\t\tconst previousElement = focus.tabbable.findPrevious(\n\t\t\t\t\t\tref.current\n\t\t\t\t\t);\n\t\t\t\t\tpreviousElement?.focus();\n\t\t\t\t\tsetPreference( 'core', PREFERENCE_NAME, false );\n\t\t\t\t} }\n\t\t\t\tshowTooltip={ false }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"]}
|
|
@@ -6,12 +6,13 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
6
6
|
import AdvancedControls from './advanced-controls-panel';
|
|
7
7
|
import PositionControls from './position-controls-panel';
|
|
8
8
|
import { default as InspectorControls } from '../inspector-controls';
|
|
9
|
+
import SettingsTabHint from './settings-tab-hint';
|
|
9
10
|
|
|
10
11
|
const SettingsTab = _ref => {
|
|
11
12
|
let {
|
|
12
13
|
showAdvancedControls = false
|
|
13
14
|
} = _ref;
|
|
14
|
-
return createElement(Fragment, null, createElement(InspectorControls.Slot, null), createElement(PositionControls, null), showAdvancedControls && createElement("div", null, createElement(AdvancedControls, null)));
|
|
15
|
+
return createElement(Fragment, null, createElement(InspectorControls.Slot, null), createElement(PositionControls, null), showAdvancedControls && createElement("div", null, createElement(AdvancedControls, null)), createElement(SettingsTabHint, null));
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
export default SettingsTab;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/inspector-controls-tabs/settings-tab.js"],"names":["AdvancedControls","PositionControls","default","InspectorControls","SettingsTab","showAdvancedControls"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,gBAAP,MAA6B,2BAA7B;AACA,OAAOC,gBAAP,MAA6B,2BAA7B;AACA,SAASC,OAAO,IAAIC,iBAApB,QAA6C,uBAA7C;;AAEA,MAAMC,WAAW,GAAG;AAAA,MAAE;AAAEC,IAAAA,oBAAoB,GAAG;AAAzB,GAAF;AAAA,SACnB,8BACC,cAAC,iBAAD,CAAmB,IAAnB,OADD,EAEC,cAAC,gBAAD,OAFD,EAGGA,oBAAoB,IACrB,2BACC,cAAC,gBAAD,OADD,CAJF,CADmB;AAAA,CAApB;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inspector-controls-tabs/settings-tab.js"],"names":["AdvancedControls","PositionControls","default","InspectorControls","SettingsTabHint","SettingsTab","showAdvancedControls"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,gBAAP,MAA6B,2BAA7B;AACA,OAAOC,gBAAP,MAA6B,2BAA7B;AACA,SAASC,OAAO,IAAIC,iBAApB,QAA6C,uBAA7C;AACA,OAAOC,eAAP,MAA4B,qBAA5B;;AAEA,MAAMC,WAAW,GAAG;AAAA,MAAE;AAAEC,IAAAA,oBAAoB,GAAG;AAAzB,GAAF;AAAA,SACnB,8BACC,cAAC,iBAAD,CAAmB,IAAnB,OADD,EAEC,cAAC,gBAAD,OAFD,EAGGA,oBAAoB,IACrB,2BACC,cAAC,gBAAD,OADD,CAJF,EAQC,cAAC,eAAD,OARD,CADmB;AAAA,CAApB;;AAaA,eAAeD,WAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport AdvancedControls from './advanced-controls-panel';\nimport PositionControls from './position-controls-panel';\nimport { default as InspectorControls } from '../inspector-controls';\nimport SettingsTabHint from './settings-tab-hint';\n\nconst SettingsTab = ( { showAdvancedControls = false } ) => (\n\t<>\n\t\t<InspectorControls.Slot />\n\t\t<PositionControls />\n\t\t{ showAdvancedControls && (\n\t\t\t<div>\n\t\t\t\t<AdvancedControls />\n\t\t\t</div>\n\t\t) }\n\t\t<SettingsTabHint />\n\t</>\n);\n\nexport default SettingsTab;\n"]}
|
|
@@ -15,6 +15,7 @@ import { forwardRef, useEffect, useState } from '@wordpress/element';
|
|
|
15
15
|
* Internal dependencies
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
import { unlock } from '../../experiments';
|
|
18
19
|
import ListViewBlockSelectButton from './block-select-button';
|
|
19
20
|
import BlockDraggable from '../block-draggable';
|
|
20
21
|
import { store as blockEditorStore } from '../../store';
|
|
@@ -48,7 +49,7 @@ const ListViewBlockContents = forwardRef((_ref, ref) => {
|
|
|
48
49
|
hasBlockMovingClientId,
|
|
49
50
|
getSelectedBlockClientId,
|
|
50
51
|
getLastInsertedBlocksClientIds
|
|
51
|
-
} = select(blockEditorStore);
|
|
52
|
+
} = unlock(select(blockEditorStore));
|
|
52
53
|
const lastInsertedBlocksClientIds = getLastInsertedBlocksClientIds();
|
|
53
54
|
return {
|
|
54
55
|
blockMovingClientId: hasBlockMovingClientId(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/off-canvas-editor/block-contents.js"],"names":["classnames","useSelect","forwardRef","useEffect","useState","ListViewBlockSelectButton","BlockDraggable","store","blockEditorStore","updateAttributes","LinkUI","useInsertedBlock","BLOCKS_WITH_LINK_UI_SUPPORT","ListViewBlockContents","ref","onClick","onToggleExpanded","block","isSelected","position","siblingBlockCount","level","isExpanded","selectedClientIds","props","clientId","isLinkUIOpen","setIsLinkUIOpen","blockMovingClientId","selectedBlockInBlockEditor","lastInsertedBlockClientId","select","hasBlockMovingClientId","getSelectedBlockClientId","getLastInsertedBlocksClientIds","lastInsertedBlocksClientIds","insertedBlockAttributes","insertedBlockName","setInsertedBlockAttributes","hasExistingLinkValue","id","includes","isBlockMoveTarget","className","draggableClientIds","updatedValue","draggable","onDragStart","onDragEnd"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,UAAT,EAAqBC,SAArB,EAAgCC,QAAhC,QAAgD,oBAAhD;AAEA;AACA;AACA;;AACA,OAAOC,yBAAP,MAAsC,uBAAtC;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,gBAAT,QAAiC,qBAAjC;AACA,SAASC,MAAT,QAAuB,WAAvB;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AAEA,MAAMC,2BAA2B,GAAG,CACnC,sBADmC,EAEnC,yBAFmC,CAApC;AAKA,MAAMC,qBAAqB,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/off-canvas-editor/block-contents.js"],"names":["classnames","useSelect","forwardRef","useEffect","useState","unlock","ListViewBlockSelectButton","BlockDraggable","store","blockEditorStore","updateAttributes","LinkUI","useInsertedBlock","BLOCKS_WITH_LINK_UI_SUPPORT","ListViewBlockContents","ref","onClick","onToggleExpanded","block","isSelected","position","siblingBlockCount","level","isExpanded","selectedClientIds","props","clientId","isLinkUIOpen","setIsLinkUIOpen","blockMovingClientId","selectedBlockInBlockEditor","lastInsertedBlockClientId","select","hasBlockMovingClientId","getSelectedBlockClientId","getLastInsertedBlocksClientIds","lastInsertedBlocksClientIds","insertedBlockAttributes","insertedBlockName","setInsertedBlockAttributes","hasExistingLinkValue","id","includes","isBlockMoveTarget","className","draggableClientIds","updatedValue","draggable","onDragStart","onDragEnd"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,UAAT,EAAqBC,SAArB,EAAgCC,QAAhC,QAAgD,oBAAhD;AAEA;AACA;AACA;;AACA,SAASC,MAAT,QAAuB,mBAAvB;AACA,OAAOC,yBAAP,MAAsC,uBAAtC;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,gBAAT,QAAiC,qBAAjC;AACA,SAASC,MA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AJX;AAKC,MAAA,gBAAgB,EAAGC,gBALpB;AAMC,MAAA,UAAU,EAAGE,UANd;AAOC,MAAA,QAAQ,EAAGC,QAPZ;AAQC,MAAA,iBAAiB,EAAGC,iBARrB;AASC,MAAA,KAAK,EAAGC,KATT;AAUC,MAAA,SAAS,EAAGyB,SAVb;AAWC,MAAA,WAAW,EAAGC,WAXf;AAYC,MAAA,SAAS,EAAGC,SAZb;AAaC,MAAA,UAAU,EAAG1B;AAbd,OAcME,KAdN,EADC;AAAA,GADH,CAjBD,CADD;AAwCA,CAxHsC,CAAxC;AA2HA,eAAeX,qBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { forwardRef, useEffect, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../experiments';\nimport ListViewBlockSelectButton from './block-select-button';\nimport BlockDraggable from '../block-draggable';\nimport { store as blockEditorStore } from '../../store';\nimport { updateAttributes } from './update-attributes';\nimport { LinkUI } from './link-ui';\nimport { useInsertedBlock } from './use-inserted-block';\n\nconst BLOCKS_WITH_LINK_UI_SUPPORT = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\n\nconst ListViewBlockContents = forwardRef(\n\t(\n\t\t{\n\t\t\tonClick,\n\t\t\tonToggleExpanded,\n\t\t\tblock,\n\t\t\tisSelected,\n\t\t\tposition,\n\t\t\tsiblingBlockCount,\n\t\t\tlevel,\n\t\t\tisExpanded,\n\t\t\tselectedClientIds,\n\t\t\t...props\n\t\t},\n\t\tref\n\t) => {\n\t\tconst { clientId } = block;\n\t\tconst [ isLinkUIOpen, setIsLinkUIOpen ] = useState();\n\t\tconst {\n\t\t\tblockMovingClientId,\n\t\t\tselectedBlockInBlockEditor,\n\t\t\tlastInsertedBlockClientId,\n\t\t} = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst {\n\t\t\t\t\thasBlockMovingClientId,\n\t\t\t\t\tgetSelectedBlockClientId,\n\t\t\t\t\tgetLastInsertedBlocksClientIds,\n\t\t\t\t} = unlock( select( blockEditorStore ) );\n\t\t\t\tconst lastInsertedBlocksClientIds =\n\t\t\t\t\tgetLastInsertedBlocksClientIds();\n\t\t\t\treturn {\n\t\t\t\t\tblockMovingClientId: hasBlockMovingClientId(),\n\t\t\t\t\tselectedBlockInBlockEditor: getSelectedBlockClientId(),\n\t\t\t\t\tlastInsertedBlockClientId:\n\t\t\t\t\t\tlastInsertedBlocksClientIds &&\n\t\t\t\t\t\tlastInsertedBlocksClientIds[ 0 ],\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ clientId ]\n\t\t);\n\n\t\tconst {\n\t\t\tinsertedBlockAttributes,\n\t\t\tinsertedBlockName,\n\t\t\tsetInsertedBlockAttributes,\n\t\t} = useInsertedBlock( lastInsertedBlockClientId );\n\n\t\tconst hasExistingLinkValue = insertedBlockAttributes?.id;\n\n\t\tuseEffect( () => {\n\t\t\tif (\n\t\t\t\tclientId === lastInsertedBlockClientId &&\n\t\t\t\tBLOCKS_WITH_LINK_UI_SUPPORT?.includes( insertedBlockName ) &&\n\t\t\t\t! hasExistingLinkValue // don't re-show the Link UI if the block already has a link value.\n\t\t\t) {\n\t\t\t\tsetIsLinkUIOpen( true );\n\t\t\t}\n\t\t}, [\n\t\t\tlastInsertedBlockClientId,\n\t\t\tclientId,\n\t\t\tinsertedBlockName,\n\t\t\thasExistingLinkValue,\n\t\t] );\n\n\t\tconst isBlockMoveTarget =\n\t\t\tblockMovingClientId && selectedBlockInBlockEditor === clientId;\n\n\t\tconst className = classnames( 'block-editor-list-view-block-contents', {\n\t\t\t'is-dropping-before': isBlockMoveTarget,\n\t\t} );\n\n\t\t// Only include all selected blocks if the currently clicked on block\n\t\t// is one of the selected blocks. This ensures that if a user attempts\n\t\t// to drag a block that isn't part of the selection, they're still able\n\t\t// to drag it and rearrange its position.\n\t\tconst draggableClientIds = selectedClientIds.includes( clientId )\n\t\t\t? selectedClientIds\n\t\t\t: [ clientId ];\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ isLinkUIOpen && (\n\t\t\t\t\t<LinkUI\n\t\t\t\t\t\tclientId={ lastInsertedBlockClientId }\n\t\t\t\t\t\tlink={ insertedBlockAttributes }\n\t\t\t\t\t\tonClose={ () => setIsLinkUIOpen( false ) }\n\t\t\t\t\t\thasCreateSuggestion={ false }\n\t\t\t\t\t\tonChange={ ( updatedValue ) => {\n\t\t\t\t\t\t\tupdateAttributes(\n\t\t\t\t\t\t\t\tupdatedValue,\n\t\t\t\t\t\t\t\tsetInsertedBlockAttributes,\n\t\t\t\t\t\t\t\tinsertedBlockAttributes\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tsetIsLinkUIOpen( false );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t<BlockDraggable clientIds={ draggableClientIds }>\n\t\t\t\t\t{ ( { draggable, onDragStart, onDragEnd } ) => (\n\t\t\t\t\t\t<ListViewBlockSelectButton\n\t\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\t\tclassName={ className }\n\t\t\t\t\t\t\tblock={ block }\n\t\t\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\t\t\tonToggleExpanded={ onToggleExpanded }\n\t\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t\t\tposition={ position }\n\t\t\t\t\t\t\tsiblingBlockCount={ siblingBlockCount }\n\t\t\t\t\t\t\tlevel={ level }\n\t\t\t\t\t\t\tdraggable={ draggable }\n\t\t\t\t\t\t\tonDragStart={ onDragStart }\n\t\t\t\t\t\t\tonDragEnd={ onDragEnd }\n\t\t\t\t\t\t\tisExpanded={ isExpanded }\n\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</BlockDraggable>\n\t\t\t</>\n\t\t);\n\t}\n);\n\nexport default ListViewBlockContents;\n"]}
|
|
@@ -43,6 +43,8 @@ export const BLOCK_LIST_ITEM_HEIGHT = 36;
|
|
|
43
43
|
* @param {boolean} props.showBlockMovers Flag to enable block movers
|
|
44
44
|
* @param {boolean} props.isExpanded Flag to determine whether nested levels are expanded by default.
|
|
45
45
|
* @param {Object} props.LeafMoreMenu Optional more menu substitution.
|
|
46
|
+
* @param {string} props.description Optional accessible description for the tree grid component.
|
|
47
|
+
* @param {string} props.onSelect Optional callback to be invoked when a block is selected.
|
|
46
48
|
* @param {Object} ref Forwarded ref
|
|
47
49
|
*/
|
|
48
50
|
|
|
@@ -52,8 +54,13 @@ function OffCanvasEditor(_ref, ref) {
|
|
|
52
54
|
blocks,
|
|
53
55
|
showBlockMovers = false,
|
|
54
56
|
isExpanded = false,
|
|
55
|
-
LeafMoreMenu
|
|
57
|
+
LeafMoreMenu,
|
|
58
|
+
description = __('Block navigation structure'),
|
|
59
|
+
onSelect
|
|
56
60
|
} = _ref;
|
|
61
|
+
const {
|
|
62
|
+
getBlock
|
|
63
|
+
} = useSelect(blockEditorStore);
|
|
57
64
|
const {
|
|
58
65
|
clientIdsTree,
|
|
59
66
|
draggedClientIds,
|
|
@@ -94,7 +101,11 @@ function OffCanvasEditor(_ref, ref) {
|
|
|
94
101
|
const selectEditorBlock = useCallback((event, blockClientId) => {
|
|
95
102
|
updateBlockSelection(event, blockClientId);
|
|
96
103
|
setSelectedTreeId(blockClientId);
|
|
97
|
-
|
|
104
|
+
|
|
105
|
+
if (onSelect) {
|
|
106
|
+
onSelect(getBlock(blockClientId));
|
|
107
|
+
}
|
|
108
|
+
}, [setSelectedTreeId, updateBlockSelection, onSelect, getBlock]);
|
|
98
109
|
useEffect(() => {
|
|
99
110
|
isMounted.current = true;
|
|
100
111
|
}, []); // List View renders a fixed number of items and relies on each having a fixed item height of 36px.
|
|
@@ -164,8 +175,9 @@ function OffCanvasEditor(_ref, ref) {
|
|
|
164
175
|
ref: treeGridRef,
|
|
165
176
|
onCollapseRow: collapseRow,
|
|
166
177
|
onExpandRow: expandRow,
|
|
167
|
-
onFocusRow: focusRow
|
|
168
|
-
|
|
178
|
+
onFocusRow: focusRow // eslint-disable-next-line jsx-a11y/aria-props
|
|
179
|
+
,
|
|
180
|
+
"aria-description": description
|
|
169
181
|
}, createElement(ListViewContext.Provider, {
|
|
170
182
|
value: contextValue
|
|
171
183
|
}, createElement(ListViewBranch, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/off-canvas-editor/index.js"],"names":["useMergeRefs","__experimentalUseFixedWindowList","useFixedWindowList","__experimentalTreeGrid","TreeGrid","__experimentalTreeGridRow","TreeGridRow","__experimentalTreeGridCell","TreeGridCell","AsyncModeProvider","useSelect","useCallback","useEffect","useMemo","useRef","useReducer","forwardRef","__","ListViewBranch","ListViewContext","ListViewDropIndicator","useBlockSelection","useListViewClientIds","useListViewDropZone","useListViewExpandSelectedItem","store","blockEditorStore","expanded","state","action","Array","isArray","clientIds","reduce","newState","id","type","BLOCK_LIST_ITEM_HEIGHT","OffCanvasEditor","ref","blocks","showBlockMovers","isExpanded","LeafMoreMenu","clientIdsTree","draggedClientIds","selectedClientIds","visibleBlockCount","shouldShowInnerBlocks","select","getGlobalBlockCount","getClientIdsOfDescendants","__unstableGetEditorMode","draggedBlockCount","length","updateBlockSelection","expandedState","setExpandedState","dropZoneRef","target","blockDropTarget","elementRef","treeGridRef","isMounted","setSelectedTreeId","firstSelectedBlockClientId","selectEditorBlock","event","blockClientId","current","fixedListWindow","useWindowing","windowOverscan","expand","collapse","expandRow","row","dataset","block","collapseRow","focusRow","startRow","endRow","shiftKey","contextValue","isTreeGridMounted"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,YADD,EAECC,gCAAgC,IAAIC,kBAFrC,QAGO,oBAHP;AAIA,SACCC,sBAAsB,IAAIC,QAD3B,EAECC,yBAAyB,IAAIC,WAF9B,EAGCC,0BAA0B,IAAIC,YAH/B,QAIO,uBAJP;AAKA,SAASC,iBAAT,EAA4BC,SA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FX;AAGC,kBAAalB,EAAE,CAAE,4BAAF,CAHhB;AAIC,IAAA,GAAG,EAAG6C,WAJP;AAKC,IAAA,aAAa,EAAGiB,WALjB;AAMC,IAAA,WAAW,EAAGJ,SANf;AAOC,IAAA,UAAU,EAAGK,QAPd;AAQC,IAAA,oBAAoB,EAAG/D,EAAE,CAAE,4BAAF;AAR1B,KAUC,cAAC,eAAD,CAAiB,QAAjB;AAA0B,IAAA,KAAK,EAAGmE;AAAlC,KACC,cAAC,cAAD;AACC,IAAA,MAAM,EAAGxC,aADV;AAEC,IAAA,WAAW,EAAGsB,iBAFf;AAGC,IAAA,eAAe,EAAGzB,eAHnB;AAIC,IAAA,eAAe,EAAG6B,eAJnB;AAKC,IAAA,iBAAiB,EAAGxB,iBALrB;AAMC,IAAA,UAAU,EAAGJ,UANd;AAOC,IAAA,qBAAqB,EAAGM;AAPzB,IADD,EAUC,cAAC,WAAD;AACC,IAAA,KAAK,EAAG,CADT;AAEC,IAAA,OAAO,EAAG,CAFX;AAGC,IAAA,aAAa,EAAG,CAHjB;AAIC,IAAA,UAAU,EAAG;AAJd,KAMG,CAAEJ,aAAa,CAACU,MAAhB,IACD,cAAC,YAAD;AAAc,IAAA,eAAe;AAA7B,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGrC,EAAE,CACH,wEADG,CADL,CADD,CAPF,CAVD,CAVD,CADD,CALD,CADD;AAgDA;;AAED,eAAeD,UAAU,CAAEsB,eAAF,CAAzB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tuseMergeRefs,\n\t__experimentalUseFixedWindowList as useFixedWindowList,\n} from '@wordpress/compose';\nimport {\n\t__experimentalTreeGrid as TreeGrid,\n\t__experimentalTreeGridRow as TreeGridRow,\n\t__experimentalTreeGridCell as TreeGridCell,\n} from '@wordpress/components';\nimport { AsyncModeProvider, useSelect } from '@wordpress/data';\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseReducer,\n\tforwardRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport ListViewBranch from './branch';\nimport { ListViewContext } from './context';\nimport ListViewDropIndicator from './drop-indicator';\nimport useBlockSelection from './use-block-selection';\nimport useListViewClientIds from './use-list-view-client-ids';\nimport useListViewDropZone from './use-list-view-drop-zone';\nimport useListViewExpandSelectedItem from './use-list-view-expand-selected-item';\nimport { store as blockEditorStore } from '../../store';\n\nconst expanded = ( state, action ) => {\n\tif ( Array.isArray( action.clientIds ) ) {\n\t\treturn {\n\t\t\t...state,\n\t\t\t...action.clientIds.reduce(\n\t\t\t\t( newState, id ) => ( {\n\t\t\t\t\t...newState,\n\t\t\t\t\t[ id ]: action.type === 'expand',\n\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t),\n\t\t};\n\t}\n\treturn state;\n};\n\nexport const BLOCK_LIST_ITEM_HEIGHT = 36;\n\n/**\n * Show a hierarchical list of blocks.\n *\n * @param {Object} props Components props.\n * @param {string} props.id An HTML element id for the root element of ListView.\n * @param {Array} props.blocks Custom subset of block client IDs to be used instead of the default hierarchy.\n * @param {boolean} props.showBlockMovers Flag to enable block movers\n * @param {boolean} props.isExpanded Flag to determine whether nested levels are expanded by default.\n * @param {Object} props.LeafMoreMenu Optional more menu substitution.\n * @param {Object} ref Forwarded ref\n */\nfunction OffCanvasEditor(\n\t{ id, blocks, showBlockMovers = false, isExpanded = false, LeafMoreMenu },\n\tref\n) {\n\tconst { clientIdsTree, draggedClientIds, selectedClientIds } =\n\t\tuseListViewClientIds( blocks );\n\n\tconst { visibleBlockCount, shouldShowInnerBlocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetGlobalBlockCount,\n\t\t\t\tgetClientIdsOfDescendants,\n\t\t\t\t__unstableGetEditorMode,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst draggedBlockCount =\n\t\t\t\tdraggedClientIds?.length > 0\n\t\t\t\t\t? getClientIdsOfDescendants( draggedClientIds ).length + 1\n\t\t\t\t\t: 0;\n\t\t\treturn {\n\t\t\t\tvisibleBlockCount: getGlobalBlockCount() - draggedBlockCount,\n\t\t\t\tshouldShowInnerBlocks: __unstableGetEditorMode() !== 'zoom-out',\n\t\t\t};\n\t\t},\n\t\t[ draggedClientIds ]\n\t);\n\n\tconst { updateBlockSelection } = useBlockSelection();\n\n\tconst [ expandedState, setExpandedState ] = useReducer( expanded, {} );\n\n\tconst { ref: dropZoneRef, target: blockDropTarget } = useListViewDropZone();\n\tconst elementRef = useRef();\n\tconst treeGridRef = useMergeRefs( [ elementRef, dropZoneRef, ref ] );\n\n\tconst isMounted = useRef( false );\n\tconst { setSelectedTreeId } = useListViewExpandSelectedItem( {\n\t\tfirstSelectedBlockClientId: selectedClientIds[ 0 ],\n\t\tsetExpandedState,\n\t} );\n\tconst selectEditorBlock = useCallback(\n\t\t( event, blockClientId ) => {\n\t\t\tupdateBlockSelection( event, blockClientId );\n\t\t\tsetSelectedTreeId( blockClientId );\n\t\t},\n\t\t[ setSelectedTreeId, updateBlockSelection ]\n\t);\n\tuseEffect( () => {\n\t\tisMounted.current = true;\n\t}, [] );\n\n\t// List View renders a fixed number of items and relies on each having a fixed item height of 36px.\n\t// If this value changes, we should also change the itemHeight value set in useFixedWindowList.\n\t// See: https://github.com/WordPress/gutenberg/pull/35230 for additional context.\n\tconst [ fixedListWindow ] = useFixedWindowList(\n\t\telementRef,\n\t\tBLOCK_LIST_ITEM_HEIGHT,\n\t\tvisibleBlockCount,\n\t\t{\n\t\t\tuseWindowing: true,\n\t\t\twindowOverscan: 40,\n\t\t}\n\t);\n\n\tconst expand = useCallback(\n\t\t( blockClientId ) => {\n\t\t\tif ( ! blockClientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetExpandedState( {\n\t\t\t\ttype: 'expand',\n\t\t\t\tclientIds: [ blockClientId ],\n\t\t\t} );\n\t\t},\n\t\t[ setExpandedState ]\n\t);\n\tconst collapse = useCallback(\n\t\t( blockClientId ) => {\n\t\t\tif ( ! blockClientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetExpandedState( {\n\t\t\t\ttype: 'collapse',\n\t\t\t\tclientIds: [ blockClientId ],\n\t\t\t} );\n\t\t},\n\t\t[ setExpandedState ]\n\t);\n\tconst expandRow = useCallback(\n\t\t( row ) => {\n\t\t\texpand( row?.dataset?.block );\n\t\t},\n\t\t[ expand ]\n\t);\n\tconst collapseRow = useCallback(\n\t\t( row ) => {\n\t\t\tcollapse( row?.dataset?.block );\n\t\t},\n\t\t[ collapse ]\n\t);\n\tconst focusRow = useCallback(\n\t\t( event, startRow, endRow ) => {\n\t\t\tif ( event.shiftKey ) {\n\t\t\t\tupdateBlockSelection(\n\t\t\t\t\tevent,\n\t\t\t\t\tstartRow?.dataset?.block,\n\t\t\t\t\tendRow?.dataset?.block\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ updateBlockSelection ]\n\t);\n\n\tconst contextValue = useMemo(\n\t\t() => ( {\n\t\t\tisTreeGridMounted: isMounted.current,\n\t\t\tdraggedClientIds,\n\t\t\texpandedState,\n\t\t\texpand,\n\t\t\tcollapse,\n\t\t\tLeafMoreMenu,\n\t\t} ),\n\t\t[\n\t\t\tisMounted.current,\n\t\t\tdraggedClientIds,\n\t\t\texpandedState,\n\t\t\texpand,\n\t\t\tcollapse,\n\t\t\tLeafMoreMenu,\n\t\t]\n\t);\n\n\treturn (\n\t\t<AsyncModeProvider value={ true }>\n\t\t\t<ListViewDropIndicator\n\t\t\t\tlistViewRef={ elementRef }\n\t\t\t\tblockDropTarget={ blockDropTarget }\n\t\t\t/>\n\t\t\t<div className=\"offcanvas-editor-list-view-tree-wrapper\">\n\t\t\t\t<TreeGrid\n\t\t\t\t\tid={ id }\n\t\t\t\t\tclassName=\"block-editor-list-view-tree\"\n\t\t\t\t\taria-label={ __( 'Block navigation structure' ) }\n\t\t\t\t\tref={ treeGridRef }\n\t\t\t\t\tonCollapseRow={ collapseRow }\n\t\t\t\t\tonExpandRow={ expandRow }\n\t\t\t\t\tonFocusRow={ focusRow }\n\t\t\t\t\tapplicationAriaLabel={ __( 'Block navigation structure' ) }\n\t\t\t\t>\n\t\t\t\t\t<ListViewContext.Provider value={ contextValue }>\n\t\t\t\t\t\t<ListViewBranch\n\t\t\t\t\t\t\tblocks={ clientIdsTree }\n\t\t\t\t\t\t\tselectBlock={ selectEditorBlock }\n\t\t\t\t\t\t\tshowBlockMovers={ showBlockMovers }\n\t\t\t\t\t\t\tfixedListWindow={ fixedListWindow }\n\t\t\t\t\t\t\tselectedClientIds={ selectedClientIds }\n\t\t\t\t\t\t\tisExpanded={ isExpanded }\n\t\t\t\t\t\t\tshouldShowInnerBlocks={ shouldShowInnerBlocks }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<TreeGridRow\n\t\t\t\t\t\t\tlevel={ 1 }\n\t\t\t\t\t\t\tsetSize={ 1 }\n\t\t\t\t\t\t\tpositionInSet={ 1 }\n\t\t\t\t\t\t\tisExpanded={ true }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ ! clientIdsTree.length && (\n\t\t\t\t\t\t\t\t<TreeGridCell withoutGridItem>\n\t\t\t\t\t\t\t\t\t<div className=\"offcanvas-editor-list-view-is-empty\">\n\t\t\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t\t\t'Your menu is currently empty. Add your first menu item to get started.'\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t</TreeGridCell>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</TreeGridRow>\n\t\t\t\t\t</ListViewContext.Provider>\n\t\t\t\t</TreeGrid>\n\t\t\t</div>\n\t\t</AsyncModeProvider>\n\t);\n}\n\nexport default forwardRef( OffCanvasEditor );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/off-canvas-editor/index.js"],"names":["useMergeRefs","__experimentalUseFixedWindowList","useFixedWindowList","__experimentalTreeGrid","TreeGrid","__experimentalTreeGridRow","TreeGridRow","__experimentalTreeGridCell","TreeGridCell","AsyncModeProvider","useSelect","useCallback","useEffect","useMemo","useRef","useReducer","forwardRef","__","ListViewBranch","ListViewContext","ListViewDropIndicator","useBlockSelection","useListViewClientIds","useListViewDropZone","useListViewExpandSelectedItem","store","blockEditorStore","expanded","state","action","Array","isArray","clientIds","reduce","newState","id","type","BLOCK_LIST_ITEM_HEIGHT","OffCanvasEditor","ref","blocks","showBlockMovers","isExpanded","LeafMoreMenu","description","onSelect","getBlock","clientIdsTree","draggedClientIds","selectedClientIds","visibleBlockCount","shouldShowInnerBlocks","select","getGlobalBlockCount","getClientIdsOfDescendants","__unstableGetEditorMode","draggedBlockCount","length","updateBlockSelection","expandedState","setExpandedState","dropZoneRef","target","blockDropTarget","elementRef","treeGridRef","isMounted","setSelectedTreeId","firstSelectedBlockClientId","selectEditorBlock","event","blockClientId","current","fixedListWindow","useWindowing","windowOverscan","expand","collapse","expandRow","row","dataset","block","collapseRow","focusRow","startRow","endRow","shiftKey","contextValue","isTreeGridMounted"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,YADD,EAECC,gCAAgC,IAAIC,kBAFrC,QAGO,oBAHP;AAIA,SACCC,sBAAsB,IAAIC,QAD3B,EAECC,yBAAyB,IAAIC,WAF9B,EAGCC,0BAA0B,IAAIC,YAH/B,QAIO,uBAJP;AAKA,SAASC,iBAAT,EAA4BC,SAA5B,QAA6C,iBAA7C;AACA,SACCC,WADD,EAECC,SAFD,EAGCC,OAHD,EAICC,MAJD,EAKCC,UALD,EAMCC,UAND,QAOO,oBAPP;AAQA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,UAA3B;AACA,SAASC,eAAT,QAAgC,WAAhC;AACA,OAAOC,qBAAP,MAAkC,kBAAlC;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,OAAOC,oBAAP,M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B;AAIC,IAAA,GAAG,EAAGgD,WAJP;AAKC,IAAA,aAAa,EAAGiB,WALjB;AAMC,IAAA,WAAW,EAAGJ,SANf;AAOC,IAAA,UAAU,EAAGK,QAPd,CAQC;AARD;AASC,wBAAmBvC;AATpB,KAWC,cAAC,eAAD,CAAiB,QAAjB;AAA0B,IAAA,KAAK,EAAG2C;AAAlC,KACC,cAAC,cAAD;AACC,IAAA,MAAM,EAAGxC,aADV;AAEC,IAAA,WAAW,EAAGsB,iBAFf;AAGC,IAAA,eAAe,EAAG5B,eAHnB;AAIC,IAAA,eAAe,EAAGgC,eAJnB;AAKC,IAAA,iBAAiB,EAAGxB,iBALrB;AAMC,IAAA,UAAU,EAAGP,UANd;AAOC,IAAA,qBAAqB,EAAGS;AAPzB,IADD,EAUC,cAAC,WAAD;AACC,IAAA,KAAK,EAAG,CADT;AAEC,IAAA,OAAO,EAAG,CAFX;AAGC,IAAA,aAAa,EAAG,CAHjB;AAIC,IAAA,UAAU,EAAG;AAJd,KAMG,CAAEJ,aAAa,CAACU,MAAhB,IACD,cAAC,YAAD;AAAc,IAAA,eAAe;AAA7B,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGxC,EAAE,CACH,wEADG,CADL,CADD,CAPF,CAVD,CAXD,CADD,CALD,CADD;AAiDA;;AAED,eAAeD,UAAU,CAAEsB,eAAF,CAAzB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tuseMergeRefs,\n\t__experimentalUseFixedWindowList as useFixedWindowList,\n} from '@wordpress/compose';\nimport {\n\t__experimentalTreeGrid as TreeGrid,\n\t__experimentalTreeGridRow as TreeGridRow,\n\t__experimentalTreeGridCell as TreeGridCell,\n} from '@wordpress/components';\nimport { AsyncModeProvider, useSelect } from '@wordpress/data';\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseReducer,\n\tforwardRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport ListViewBranch from './branch';\nimport { ListViewContext } from './context';\nimport ListViewDropIndicator from './drop-indicator';\nimport useBlockSelection from './use-block-selection';\nimport useListViewClientIds from './use-list-view-client-ids';\nimport useListViewDropZone from './use-list-view-drop-zone';\nimport useListViewExpandSelectedItem from './use-list-view-expand-selected-item';\nimport { store as blockEditorStore } from '../../store';\n\nconst expanded = ( state, action ) => {\n\tif ( Array.isArray( action.clientIds ) ) {\n\t\treturn {\n\t\t\t...state,\n\t\t\t...action.clientIds.reduce(\n\t\t\t\t( newState, id ) => ( {\n\t\t\t\t\t...newState,\n\t\t\t\t\t[ id ]: action.type === 'expand',\n\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t),\n\t\t};\n\t}\n\treturn state;\n};\n\nexport const BLOCK_LIST_ITEM_HEIGHT = 36;\n\n/**\n * Show a hierarchical list of blocks.\n *\n * @param {Object} props Components props.\n * @param {string} props.id An HTML element id for the root element of ListView.\n * @param {Array} props.blocks Custom subset of block client IDs to be used instead of the default hierarchy.\n * @param {boolean} props.showBlockMovers Flag to enable block movers\n * @param {boolean} props.isExpanded Flag to determine whether nested levels are expanded by default.\n * @param {Object} props.LeafMoreMenu Optional more menu substitution.\n * @param {string} props.description Optional accessible description for the tree grid component.\n * @param {string} props.onSelect Optional callback to be invoked when a block is selected.\n * @param {Object} ref Forwarded ref\n */\nfunction OffCanvasEditor(\n\t{\n\t\tid,\n\t\tblocks,\n\t\tshowBlockMovers = false,\n\t\tisExpanded = false,\n\t\tLeafMoreMenu,\n\t\tdescription = __( 'Block navigation structure' ),\n\t\tonSelect,\n\t},\n\tref\n) {\n\tconst { getBlock } = useSelect( blockEditorStore );\n\tconst { clientIdsTree, draggedClientIds, selectedClientIds } =\n\t\tuseListViewClientIds( blocks );\n\n\tconst { visibleBlockCount, shouldShowInnerBlocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetGlobalBlockCount,\n\t\t\t\tgetClientIdsOfDescendants,\n\t\t\t\t__unstableGetEditorMode,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst draggedBlockCount =\n\t\t\t\tdraggedClientIds?.length > 0\n\t\t\t\t\t? getClientIdsOfDescendants( draggedClientIds ).length + 1\n\t\t\t\t\t: 0;\n\t\t\treturn {\n\t\t\t\tvisibleBlockCount: getGlobalBlockCount() - draggedBlockCount,\n\t\t\t\tshouldShowInnerBlocks: __unstableGetEditorMode() !== 'zoom-out',\n\t\t\t};\n\t\t},\n\t\t[ draggedClientIds ]\n\t);\n\n\tconst { updateBlockSelection } = useBlockSelection();\n\n\tconst [ expandedState, setExpandedState ] = useReducer( expanded, {} );\n\n\tconst { ref: dropZoneRef, target: blockDropTarget } = useListViewDropZone();\n\tconst elementRef = useRef();\n\tconst treeGridRef = useMergeRefs( [ elementRef, dropZoneRef, ref ] );\n\n\tconst isMounted = useRef( false );\n\tconst { setSelectedTreeId } = useListViewExpandSelectedItem( {\n\t\tfirstSelectedBlockClientId: selectedClientIds[ 0 ],\n\t\tsetExpandedState,\n\t} );\n\tconst selectEditorBlock = useCallback(\n\t\t( event, blockClientId ) => {\n\t\t\tupdateBlockSelection( event, blockClientId );\n\t\t\tsetSelectedTreeId( blockClientId );\n\t\t\tif ( onSelect ) {\n\t\t\t\tonSelect( getBlock( blockClientId ) );\n\t\t\t}\n\t\t},\n\t\t[ setSelectedTreeId, updateBlockSelection, onSelect, getBlock ]\n\t);\n\tuseEffect( () => {\n\t\tisMounted.current = true;\n\t}, [] );\n\n\t// List View renders a fixed number of items and relies on each having a fixed item height of 36px.\n\t// If this value changes, we should also change the itemHeight value set in useFixedWindowList.\n\t// See: https://github.com/WordPress/gutenberg/pull/35230 for additional context.\n\tconst [ fixedListWindow ] = useFixedWindowList(\n\t\telementRef,\n\t\tBLOCK_LIST_ITEM_HEIGHT,\n\t\tvisibleBlockCount,\n\t\t{\n\t\t\tuseWindowing: true,\n\t\t\twindowOverscan: 40,\n\t\t}\n\t);\n\n\tconst expand = useCallback(\n\t\t( blockClientId ) => {\n\t\t\tif ( ! blockClientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetExpandedState( {\n\t\t\t\ttype: 'expand',\n\t\t\t\tclientIds: [ blockClientId ],\n\t\t\t} );\n\t\t},\n\t\t[ setExpandedState ]\n\t);\n\tconst collapse = useCallback(\n\t\t( blockClientId ) => {\n\t\t\tif ( ! blockClientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetExpandedState( {\n\t\t\t\ttype: 'collapse',\n\t\t\t\tclientIds: [ blockClientId ],\n\t\t\t} );\n\t\t},\n\t\t[ setExpandedState ]\n\t);\n\tconst expandRow = useCallback(\n\t\t( row ) => {\n\t\t\texpand( row?.dataset?.block );\n\t\t},\n\t\t[ expand ]\n\t);\n\tconst collapseRow = useCallback(\n\t\t( row ) => {\n\t\t\tcollapse( row?.dataset?.block );\n\t\t},\n\t\t[ collapse ]\n\t);\n\tconst focusRow = useCallback(\n\t\t( event, startRow, endRow ) => {\n\t\t\tif ( event.shiftKey ) {\n\t\t\t\tupdateBlockSelection(\n\t\t\t\t\tevent,\n\t\t\t\t\tstartRow?.dataset?.block,\n\t\t\t\t\tendRow?.dataset?.block\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ updateBlockSelection ]\n\t);\n\n\tconst contextValue = useMemo(\n\t\t() => ( {\n\t\t\tisTreeGridMounted: isMounted.current,\n\t\t\tdraggedClientIds,\n\t\t\texpandedState,\n\t\t\texpand,\n\t\t\tcollapse,\n\t\t\tLeafMoreMenu,\n\t\t} ),\n\t\t[\n\t\t\tisMounted.current,\n\t\t\tdraggedClientIds,\n\t\t\texpandedState,\n\t\t\texpand,\n\t\t\tcollapse,\n\t\t\tLeafMoreMenu,\n\t\t]\n\t);\n\n\treturn (\n\t\t<AsyncModeProvider value={ true }>\n\t\t\t<ListViewDropIndicator\n\t\t\t\tlistViewRef={ elementRef }\n\t\t\t\tblockDropTarget={ blockDropTarget }\n\t\t\t/>\n\t\t\t<div className=\"offcanvas-editor-list-view-tree-wrapper\">\n\t\t\t\t<TreeGrid\n\t\t\t\t\tid={ id }\n\t\t\t\t\tclassName=\"block-editor-list-view-tree\"\n\t\t\t\t\taria-label={ __( 'Block navigation structure' ) }\n\t\t\t\t\tref={ treeGridRef }\n\t\t\t\t\tonCollapseRow={ collapseRow }\n\t\t\t\t\tonExpandRow={ expandRow }\n\t\t\t\t\tonFocusRow={ focusRow }\n\t\t\t\t\t// eslint-disable-next-line jsx-a11y/aria-props\n\t\t\t\t\taria-description={ description }\n\t\t\t\t>\n\t\t\t\t\t<ListViewContext.Provider value={ contextValue }>\n\t\t\t\t\t\t<ListViewBranch\n\t\t\t\t\t\t\tblocks={ clientIdsTree }\n\t\t\t\t\t\t\tselectBlock={ selectEditorBlock }\n\t\t\t\t\t\t\tshowBlockMovers={ showBlockMovers }\n\t\t\t\t\t\t\tfixedListWindow={ fixedListWindow }\n\t\t\t\t\t\t\tselectedClientIds={ selectedClientIds }\n\t\t\t\t\t\t\tisExpanded={ isExpanded }\n\t\t\t\t\t\t\tshouldShowInnerBlocks={ shouldShowInnerBlocks }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<TreeGridRow\n\t\t\t\t\t\t\tlevel={ 1 }\n\t\t\t\t\t\t\tsetSize={ 1 }\n\t\t\t\t\t\t\tpositionInSet={ 1 }\n\t\t\t\t\t\t\tisExpanded={ true }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ ! clientIdsTree.length && (\n\t\t\t\t\t\t\t\t<TreeGridCell withoutGridItem>\n\t\t\t\t\t\t\t\t\t<div className=\"offcanvas-editor-list-view-is-empty\">\n\t\t\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t\t\t'Your menu is currently empty. Add your first menu item to get started.'\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t</TreeGridCell>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</TreeGridRow>\n\t\t\t\t\t</ListViewContext.Provider>\n\t\t\t\t</TreeGrid>\n\t\t\t</div>\n\t\t</AsyncModeProvider>\n\t);\n}\n\nexport default forwardRef( OffCanvasEditor );\n"]}
|
|
@@ -241,7 +241,10 @@ export default function useBlockSync(_ref) {
|
|
|
241
241
|
|
|
242
242
|
previousAreBlocksDifferent = areBlocksDifferent;
|
|
243
243
|
});
|
|
244
|
-
return () =>
|
|
244
|
+
return () => {
|
|
245
|
+
subscribed.current = false;
|
|
246
|
+
unsubscribe();
|
|
247
|
+
};
|
|
245
248
|
}, [registry, clientId]);
|
|
246
249
|
}
|
|
247
250
|
//# sourceMappingURL=use-block-sync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/provider/use-block-sync.js"],"names":["useEffect","useRef","useRegistry","useSelect","cloneBlock","store","blockEditorStore","noop","useBlockSync","clientId","value","controlledBlocks","selection","controlledSelection","onChange","onInput","registry","resetBlocks","resetSelection","replaceInnerBlocks","setHasControlledInnerBlocks","__unstableMarkNextChangeAsNotPersistent","dispatch","getBlockName","getBlocks","select","isControlled","areInnerBlocksControlled","pendingChanges","incoming","outgoing","subscribed","setControlledBlocks","batch","storeBlocks","map","block","current","onInputRef","onChangeRef","includes","length","selectionStart","selectionEnd","initialPosition","getSelectionStart","getSelectionEnd","getSelectedBlocksInitialCaretPosition","isLastBlockChangePersistent","__unstableIsLastBlockChangeIgnored","blocks","isPersistent","previousAreBlocksDifferent","unsubscribe","subscribe","isStillControlled","newIsPersistent","newBlocks","areBlocksDifferent","didPersistenceChange","push","updateParent"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,oBAAlC;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,UAAT,QAA2B,mBAA3B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;;AAEA,MAAMC,IAAI,G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A,YAAY,EAAEG,eAAe,EAFnB;AAGVF,YAAAA,eAAe,EACdG,qCAAqC;AAJ5B;AADU,SAAV,CAAZ;AAQA;;AACDK,MAAAA,0BAA0B,GAAGM,kBAA7B;AACA,KApEmB,CAApB;AAsEA,WAAO,MAAML,WAAW,EAAxB;AACA,GAtFQ,EAsFN,CAAErC,QAAF,EAAYP,QAAZ,CAtFM,CAAT;AAuFA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { cloneBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nconst noop = () => {};\n\n/**\n * A function to call when the block value has been updated in the block-editor\n * store.\n *\n * @callback onBlockUpdate\n * @param {Object[]} blocks The updated blocks.\n * @param {Object} options The updated block options, such as selectionStart\n * and selectionEnd.\n */\n\n/**\n * useBlockSync is a side effect which handles bidirectional sync between the\n * block-editor store and a controlling data source which provides blocks. This\n * is most commonly used by the BlockEditorProvider to synchronize the contents\n * of the block-editor store with the root entity, like a post.\n *\n * Another example would be the template part block, which provides blocks from\n * a separate entity data source than a root entity. This hook syncs edits to\n * the template part in the block editor back to the entity and vice-versa.\n *\n * Here are some of its basic functions:\n * - Initalizes the block-editor store for the given clientID to the blocks\n * given via props.\n * - Adds incoming changes (like undo) to the block-editor store.\n * - Adds outgoing changes (like editing content) to the controlling entity,\n * determining if a change should be considered persistent or not.\n * - Handles edge cases and race conditions which occur in those operations.\n * - Ignores changes which happen to other entities (like nested inner block\n * controllers.\n * - Passes selection state from the block-editor store to the controlling entity.\n *\n * @param {Object} props Props for the block sync hook\n * @param {string} props.clientId The client ID of the inner block controller.\n * If none is passed, then it is assumed to be a\n * root controller rather than an inner block\n * controller.\n * @param {Object[]} props.value The control value for the blocks. This value\n * is used to initalize the block-editor store\n * and for resetting the blocks to incoming\n * changes like undo.\n * @param {Object} props.selection The selection state responsible to restore the selection on undo/redo.\n * @param {onBlockUpdate} props.onChange Function to call when a persistent\n * change has been made in the block-editor blocks\n * for the given clientId. For example, after\n * this function is called, an entity is marked\n * dirty because it has changes to save.\n * @param {onBlockUpdate} props.onInput Function to call when a non-persistent\n * change has been made in the block-editor blocks\n * for the given clientId. When this is called,\n * controlling sources do not become dirty.\n */\nexport default function useBlockSync( {\n\tclientId = null,\n\tvalue: controlledBlocks,\n\tselection: controlledSelection,\n\tonChange = noop,\n\tonInput = noop,\n} ) {\n\tconst registry = useRegistry();\n\n\tconst {\n\t\tresetBlocks,\n\t\tresetSelection,\n\t\treplaceInnerBlocks,\n\t\tsetHasControlledInnerBlocks,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t} = registry.dispatch( blockEditorStore );\n\tconst { getBlockName, getBlocks } = registry.select( blockEditorStore );\n\tconst isControlled = useSelect(\n\t\t( select ) => {\n\t\t\treturn (\n\t\t\t\t! clientId ||\n\t\t\t\tselect( blockEditorStore ).areInnerBlocksControlled( clientId )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst pendingChanges = useRef( { incoming: null, outgoing: [] } );\n\tconst subscribed = useRef( false );\n\n\tconst setControlledBlocks = () => {\n\t\tif ( ! controlledBlocks ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We don't need to persist this change because we only replace\n\t\t// controlled inner blocks when the change was caused by an entity,\n\t\t// and so it would already be persisted.\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tif ( clientId ) {\n\t\t\t// It is important to batch here because otherwise,\n\t\t\t// as soon as `setHasControlledInnerBlocks` is called\n\t\t\t// the effect to restore might be triggered\n\t\t\t// before the actual blocks get set properly in state.\n\t\t\tregistry.batch( () => {\n\t\t\t\tsetHasControlledInnerBlocks( clientId, true );\n\t\t\t\tconst storeBlocks = controlledBlocks.map( ( block ) =>\n\t\t\t\t\tcloneBlock( block )\n\t\t\t\t);\n\t\t\t\tif ( subscribed.current ) {\n\t\t\t\t\tpendingChanges.current.incoming = storeBlocks;\n\t\t\t\t}\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\treplaceInnerBlocks( clientId, storeBlocks );\n\t\t\t} );\n\t\t} else {\n\t\t\tif ( subscribed.current ) {\n\t\t\t\tpendingChanges.current.incoming = controlledBlocks;\n\t\t\t}\n\t\t\tresetBlocks( controlledBlocks );\n\t\t}\n\t};\n\n\t// Add a subscription to the block-editor registry to detect when changes\n\t// have been made. This lets us inform the data source of changes. This\n\t// is an effect so that the subscriber can run synchronously without\n\t// waiting for React renders for changes.\n\tconst onInputRef = useRef( onInput );\n\tconst onChangeRef = useRef( onChange );\n\tuseEffect( () => {\n\t\tonInputRef.current = onInput;\n\t\tonChangeRef.current = onChange;\n\t}, [ onInput, onChange ] );\n\n\t// Determine if blocks need to be reset when they change.\n\tuseEffect( () => {\n\t\tif ( pendingChanges.current.outgoing.includes( controlledBlocks ) ) {\n\t\t\t// Skip block reset if the value matches expected outbound sync\n\t\t\t// triggered by this component by a preceding change detection.\n\t\t\t// Only skip if the value matches expectation, since a reset should\n\t\t\t// still occur if the value is modified (not equal by reference),\n\t\t\t// to allow that the consumer may apply modifications to reflect\n\t\t\t// back on the editor.\n\t\t\tif (\n\t\t\t\tpendingChanges.current.outgoing[\n\t\t\t\t\tpendingChanges.current.outgoing.length - 1\n\t\t\t\t] === controlledBlocks\n\t\t\t) {\n\t\t\t\tpendingChanges.current.outgoing = [];\n\t\t\t}\n\t\t} else if ( getBlocks( clientId ) !== controlledBlocks ) {\n\t\t\t// Reset changing value in all other cases than the sync described\n\t\t\t// above. Since this can be reached in an update following an out-\n\t\t\t// bound sync, unset the outbound value to avoid considering it in\n\t\t\t// subsequent renders.\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tsetControlledBlocks();\n\n\t\t\tif ( controlledSelection ) {\n\t\t\t\tresetSelection(\n\t\t\t\t\tcontrolledSelection.selectionStart,\n\t\t\t\t\tcontrolledSelection.selectionEnd,\n\t\t\t\t\tcontrolledSelection.initialPosition\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}, [ controlledBlocks, clientId ] );\n\n\tuseEffect( () => {\n\t\t// When the block becomes uncontrolled, it means its inner state has been reset\n\t\t// we need to take the blocks again from the external value property.\n\t\tif ( ! isControlled ) {\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tsetControlledBlocks();\n\t\t}\n\t}, [ isControlled ] );\n\n\tuseEffect( () => {\n\t\tconst {\n\t\t\tgetSelectionStart,\n\t\t\tgetSelectionEnd,\n\t\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t\tisLastBlockChangePersistent,\n\t\t\t__unstableIsLastBlockChangeIgnored,\n\t\t\tareInnerBlocksControlled,\n\t\t} = registry.select( blockEditorStore );\n\n\t\tlet blocks = getBlocks( clientId );\n\t\tlet isPersistent = isLastBlockChangePersistent();\n\t\tlet previousAreBlocksDifferent = false;\n\n\t\tsubscribed.current = true;\n\t\tconst unsubscribe = registry.subscribe( () => {\n\t\t\t// Sometimes, when changing block lists, lingering subscriptions\n\t\t\t// might trigger before they are cleaned up. If the block for which\n\t\t\t// the subscription runs is no longer in the store, this would clear\n\t\t\t// its parent entity's block list. To avoid this, we bail out if\n\t\t\t// the subscription is triggering for a block (`clientId !== null`)\n\t\t\t// and its block name can't be found because it's not on the list.\n\t\t\t// (`getBlockName( clientId ) === null`).\n\t\t\tif ( clientId !== null && getBlockName( clientId ) === null )\n\t\t\t\treturn;\n\n\t\t\t// When RESET_BLOCKS on parent blocks get called, the controlled blocks\n\t\t\t// can reset to uncontrolled, in these situations, it means we need to populate\n\t\t\t// the blocks again from the external blocks (the value property here)\n\t\t\t// and we should stop triggering onChange\n\t\t\tconst isStillControlled =\n\t\t\t\t! clientId || areInnerBlocksControlled( clientId );\n\t\t\tif ( ! isStillControlled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst newIsPersistent = isLastBlockChangePersistent();\n\t\t\tconst newBlocks = getBlocks( clientId );\n\t\t\tconst areBlocksDifferent = newBlocks !== blocks;\n\t\t\tblocks = newBlocks;\n\n\t\t\tif (\n\t\t\t\tareBlocksDifferent &&\n\t\t\t\t( pendingChanges.current.incoming ||\n\t\t\t\t\t__unstableIsLastBlockChangeIgnored() )\n\t\t\t) {\n\t\t\t\tpendingChanges.current.incoming = null;\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Since we often dispatch an action to mark the previous action as\n\t\t\t// persistent, we need to make sure that the blocks changed on the\n\t\t\t// previous action before committing the change.\n\t\t\tconst didPersistenceChange =\n\t\t\t\tpreviousAreBlocksDifferent &&\n\t\t\t\t! areBlocksDifferent &&\n\t\t\t\tnewIsPersistent &&\n\t\t\t\t! isPersistent;\n\n\t\t\tif ( areBlocksDifferent || didPersistenceChange ) {\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\t// We know that onChange/onInput will update controlledBlocks.\n\t\t\t\t// We need to be aware that it was caused by an outgoing change\n\t\t\t\t// so that we do not treat it as an incoming change later on,\n\t\t\t\t// which would cause a block reset.\n\t\t\t\tpendingChanges.current.outgoing.push( blocks );\n\n\t\t\t\t// Inform the controlling entity that changes have been made to\n\t\t\t\t// the block-editor store they should be aware about.\n\t\t\t\tconst updateParent = isPersistent\n\t\t\t\t\t? onChangeRef.current\n\t\t\t\t\t: onInputRef.current;\n\t\t\t\tupdateParent( blocks, {\n\t\t\t\t\tselection: {\n\t\t\t\t\t\tselectionStart: getSelectionStart(),\n\t\t\t\t\t\tselectionEnd: getSelectionEnd(),\n\t\t\t\t\t\tinitialPosition:\n\t\t\t\t\t\t\tgetSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t\tpreviousAreBlocksDifferent = areBlocksDifferent;\n\t\t} );\n\n\t\treturn () => unsubscribe();\n\t}, [ registry, clientId ] );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/provider/use-block-sync.js"],"names":["useEffect","useRef","useRegistry","useSelect","cloneBlock","store","blockEditorStore","noop","useBlockSync","clientId","value","controlledBlocks","selection","controlledSelection","onChange","onInput","registry","resetBlocks","resetSelection","replaceInnerBlocks","setHasControlledInnerBlocks","__unstableMarkNextChangeAsNotPersistent","dispatch","getBlockName","getBlocks","select","isControlled","areInnerBlocksControlled","pendingChanges","incoming","outgoing","subscribed","setControlledBlocks","batch","storeBlocks","map","block","current","onInputRef","onChangeRef","includes","length","selectionStart","selectionEnd","initialPosition","getSelectionStart","getSelectionEnd","getSelectedBlocksInitialCaretPosition","isLastBlockChangePersistent","__unstableIsLastBlockChangeIgnored","blocks","isPersistent","previousAreBlocksDifferent","unsubscribe","subscribe","isStillControlled","newIsPersistent","newBlocks","areBlocksDifferent","didPersistenceChange","push","updateParent"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,oBAAlC;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,UAAT,QAA2B,mBAA3B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;;AAEA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASC,YAAT,OAMX;AAAA,MANkC;AACrCC,IAAAA,QAAQ,GAAG,IAD0B;AAErCC,IAAAA,KAAK,EAAEC,gBAF8B;AAGrCC,IAAAA,SAAS,EAAEC,mBAH0B;AAIrCC,IAAAA,QAAQ,GAAGP,IAJ0B;AAKrCQ,IAAAA,OAAO,GAAGR;AAL2B,GAMlC;AACH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,kBAAkB,KAChB9B,cAAc,CAACS,OAAf,CAAuBR,QAAvB,IACDoB,kCAAkC,EAFjB,CADnB,EAIE;AACDrB,QAAAA,cAAc,CAACS,OAAf,CAAuBR,QAAvB,GAAkC,IAAlC;AACAsB,QAAAA,YAAY,GAAGK,eAAf;AACA;AACA,OAlC4C,CAoC7C;AACA;AACA;;;AACA,YAAMG,oBAAoB,GACzBP,0BAA0B,IAC1B,CAAEM,kBADF,IAEAF,eAFA,IAGA,CAAEL,YAJH;;AAMA,UAAKO,kBAAkB,IAAIC,oBAA3B,EAAkD;AACjDR,QAAAA,YAAY,GAAGK,eAAf,CADiD,CAEjD;AACA;AACA;AACA;;AACA5B,QAAAA,cAAc,CAACS,OAAf,CAAuBP,QAAvB,CAAgC8B,IAAhC,CAAsCV,MAAtC,EANiD,CAQjD;AACA;;AACA,cAAMW,YAAY,GAAGV,YAAY,GAC9BZ,WAAW,CAACF,OADkB,GAE9BC,UAAU,CAACD,OAFd;AAGAwB,QAAAA,YAAY,CAAEX,MAAF,EAAU;AACrBtC,UAAAA,SAAS,EAAE;AACV8B,YAAAA,cAAc,EAAEG,iBAAiB,EADvB;AAEVF,YAAAA,YAAY,EAAEG,eAAe,EAFnB;AAGVF,YAAAA,eAAe,EACdG,qCAAqC;AAJ5B;AADU,SAAV,CAAZ;AAQA;;AACDK,MAAAA,0BAA0B,GAAGM,kBAA7B;AACA,KApEmB,CAApB;AAsEA,WAAO,MAAM;AACZ3B,MAAAA,UAAU,CAACM,OAAX,GAAqB,KAArB;AACAgB,MAAAA,WAAW;AACX,KAHD;AAIA,GAzFQ,EAyFN,CAAErC,QAAF,EAAYP,QAAZ,CAzFM,CAAT;AA0FA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { cloneBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nconst noop = () => {};\n\n/**\n * A function to call when the block value has been updated in the block-editor\n * store.\n *\n * @callback onBlockUpdate\n * @param {Object[]} blocks The updated blocks.\n * @param {Object} options The updated block options, such as selectionStart\n * and selectionEnd.\n */\n\n/**\n * useBlockSync is a side effect which handles bidirectional sync between the\n * block-editor store and a controlling data source which provides blocks. This\n * is most commonly used by the BlockEditorProvider to synchronize the contents\n * of the block-editor store with the root entity, like a post.\n *\n * Another example would be the template part block, which provides blocks from\n * a separate entity data source than a root entity. This hook syncs edits to\n * the template part in the block editor back to the entity and vice-versa.\n *\n * Here are some of its basic functions:\n * - Initalizes the block-editor store for the given clientID to the blocks\n * given via props.\n * - Adds incoming changes (like undo) to the block-editor store.\n * - Adds outgoing changes (like editing content) to the controlling entity,\n * determining if a change should be considered persistent or not.\n * - Handles edge cases and race conditions which occur in those operations.\n * - Ignores changes which happen to other entities (like nested inner block\n * controllers.\n * - Passes selection state from the block-editor store to the controlling entity.\n *\n * @param {Object} props Props for the block sync hook\n * @param {string} props.clientId The client ID of the inner block controller.\n * If none is passed, then it is assumed to be a\n * root controller rather than an inner block\n * controller.\n * @param {Object[]} props.value The control value for the blocks. This value\n * is used to initalize the block-editor store\n * and for resetting the blocks to incoming\n * changes like undo.\n * @param {Object} props.selection The selection state responsible to restore the selection on undo/redo.\n * @param {onBlockUpdate} props.onChange Function to call when a persistent\n * change has been made in the block-editor blocks\n * for the given clientId. For example, after\n * this function is called, an entity is marked\n * dirty because it has changes to save.\n * @param {onBlockUpdate} props.onInput Function to call when a non-persistent\n * change has been made in the block-editor blocks\n * for the given clientId. When this is called,\n * controlling sources do not become dirty.\n */\nexport default function useBlockSync( {\n\tclientId = null,\n\tvalue: controlledBlocks,\n\tselection: controlledSelection,\n\tonChange = noop,\n\tonInput = noop,\n} ) {\n\tconst registry = useRegistry();\n\n\tconst {\n\t\tresetBlocks,\n\t\tresetSelection,\n\t\treplaceInnerBlocks,\n\t\tsetHasControlledInnerBlocks,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t} = registry.dispatch( blockEditorStore );\n\tconst { getBlockName, getBlocks } = registry.select( blockEditorStore );\n\tconst isControlled = useSelect(\n\t\t( select ) => {\n\t\t\treturn (\n\t\t\t\t! clientId ||\n\t\t\t\tselect( blockEditorStore ).areInnerBlocksControlled( clientId )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst pendingChanges = useRef( { incoming: null, outgoing: [] } );\n\tconst subscribed = useRef( false );\n\n\tconst setControlledBlocks = () => {\n\t\tif ( ! controlledBlocks ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We don't need to persist this change because we only replace\n\t\t// controlled inner blocks when the change was caused by an entity,\n\t\t// and so it would already be persisted.\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tif ( clientId ) {\n\t\t\t// It is important to batch here because otherwise,\n\t\t\t// as soon as `setHasControlledInnerBlocks` is called\n\t\t\t// the effect to restore might be triggered\n\t\t\t// before the actual blocks get set properly in state.\n\t\t\tregistry.batch( () => {\n\t\t\t\tsetHasControlledInnerBlocks( clientId, true );\n\t\t\t\tconst storeBlocks = controlledBlocks.map( ( block ) =>\n\t\t\t\t\tcloneBlock( block )\n\t\t\t\t);\n\t\t\t\tif ( subscribed.current ) {\n\t\t\t\t\tpendingChanges.current.incoming = storeBlocks;\n\t\t\t\t}\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\treplaceInnerBlocks( clientId, storeBlocks );\n\t\t\t} );\n\t\t} else {\n\t\t\tif ( subscribed.current ) {\n\t\t\t\tpendingChanges.current.incoming = controlledBlocks;\n\t\t\t}\n\t\t\tresetBlocks( controlledBlocks );\n\t\t}\n\t};\n\n\t// Add a subscription to the block-editor registry to detect when changes\n\t// have been made. This lets us inform the data source of changes. This\n\t// is an effect so that the subscriber can run synchronously without\n\t// waiting for React renders for changes.\n\tconst onInputRef = useRef( onInput );\n\tconst onChangeRef = useRef( onChange );\n\tuseEffect( () => {\n\t\tonInputRef.current = onInput;\n\t\tonChangeRef.current = onChange;\n\t}, [ onInput, onChange ] );\n\n\t// Determine if blocks need to be reset when they change.\n\tuseEffect( () => {\n\t\tif ( pendingChanges.current.outgoing.includes( controlledBlocks ) ) {\n\t\t\t// Skip block reset if the value matches expected outbound sync\n\t\t\t// triggered by this component by a preceding change detection.\n\t\t\t// Only skip if the value matches expectation, since a reset should\n\t\t\t// still occur if the value is modified (not equal by reference),\n\t\t\t// to allow that the consumer may apply modifications to reflect\n\t\t\t// back on the editor.\n\t\t\tif (\n\t\t\t\tpendingChanges.current.outgoing[\n\t\t\t\t\tpendingChanges.current.outgoing.length - 1\n\t\t\t\t] === controlledBlocks\n\t\t\t) {\n\t\t\t\tpendingChanges.current.outgoing = [];\n\t\t\t}\n\t\t} else if ( getBlocks( clientId ) !== controlledBlocks ) {\n\t\t\t// Reset changing value in all other cases than the sync described\n\t\t\t// above. Since this can be reached in an update following an out-\n\t\t\t// bound sync, unset the outbound value to avoid considering it in\n\t\t\t// subsequent renders.\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tsetControlledBlocks();\n\n\t\t\tif ( controlledSelection ) {\n\t\t\t\tresetSelection(\n\t\t\t\t\tcontrolledSelection.selectionStart,\n\t\t\t\t\tcontrolledSelection.selectionEnd,\n\t\t\t\t\tcontrolledSelection.initialPosition\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}, [ controlledBlocks, clientId ] );\n\n\tuseEffect( () => {\n\t\t// When the block becomes uncontrolled, it means its inner state has been reset\n\t\t// we need to take the blocks again from the external value property.\n\t\tif ( ! isControlled ) {\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tsetControlledBlocks();\n\t\t}\n\t}, [ isControlled ] );\n\n\tuseEffect( () => {\n\t\tconst {\n\t\t\tgetSelectionStart,\n\t\t\tgetSelectionEnd,\n\t\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t\tisLastBlockChangePersistent,\n\t\t\t__unstableIsLastBlockChangeIgnored,\n\t\t\tareInnerBlocksControlled,\n\t\t} = registry.select( blockEditorStore );\n\n\t\tlet blocks = getBlocks( clientId );\n\t\tlet isPersistent = isLastBlockChangePersistent();\n\t\tlet previousAreBlocksDifferent = false;\n\n\t\tsubscribed.current = true;\n\t\tconst unsubscribe = registry.subscribe( () => {\n\t\t\t// Sometimes, when changing block lists, lingering subscriptions\n\t\t\t// might trigger before they are cleaned up. If the block for which\n\t\t\t// the subscription runs is no longer in the store, this would clear\n\t\t\t// its parent entity's block list. To avoid this, we bail out if\n\t\t\t// the subscription is triggering for a block (`clientId !== null`)\n\t\t\t// and its block name can't be found because it's not on the list.\n\t\t\t// (`getBlockName( clientId ) === null`).\n\t\t\tif ( clientId !== null && getBlockName( clientId ) === null )\n\t\t\t\treturn;\n\n\t\t\t// When RESET_BLOCKS on parent blocks get called, the controlled blocks\n\t\t\t// can reset to uncontrolled, in these situations, it means we need to populate\n\t\t\t// the blocks again from the external blocks (the value property here)\n\t\t\t// and we should stop triggering onChange\n\t\t\tconst isStillControlled =\n\t\t\t\t! clientId || areInnerBlocksControlled( clientId );\n\t\t\tif ( ! isStillControlled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst newIsPersistent = isLastBlockChangePersistent();\n\t\t\tconst newBlocks = getBlocks( clientId );\n\t\t\tconst areBlocksDifferent = newBlocks !== blocks;\n\t\t\tblocks = newBlocks;\n\n\t\t\tif (\n\t\t\t\tareBlocksDifferent &&\n\t\t\t\t( pendingChanges.current.incoming ||\n\t\t\t\t\t__unstableIsLastBlockChangeIgnored() )\n\t\t\t) {\n\t\t\t\tpendingChanges.current.incoming = null;\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Since we often dispatch an action to mark the previous action as\n\t\t\t// persistent, we need to make sure that the blocks changed on the\n\t\t\t// previous action before committing the change.\n\t\t\tconst didPersistenceChange =\n\t\t\t\tpreviousAreBlocksDifferent &&\n\t\t\t\t! areBlocksDifferent &&\n\t\t\t\tnewIsPersistent &&\n\t\t\t\t! isPersistent;\n\n\t\t\tif ( areBlocksDifferent || didPersistenceChange ) {\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\t// We know that onChange/onInput will update controlledBlocks.\n\t\t\t\t// We need to be aware that it was caused by an outgoing change\n\t\t\t\t// so that we do not treat it as an incoming change later on,\n\t\t\t\t// which would cause a block reset.\n\t\t\t\tpendingChanges.current.outgoing.push( blocks );\n\n\t\t\t\t// Inform the controlling entity that changes have been made to\n\t\t\t\t// the block-editor store they should be aware about.\n\t\t\t\tconst updateParent = isPersistent\n\t\t\t\t\t? onChangeRef.current\n\t\t\t\t\t: onInputRef.current;\n\t\t\t\tupdateParent( blocks, {\n\t\t\t\t\tselection: {\n\t\t\t\t\t\tselectionStart: getSelectionStart(),\n\t\t\t\t\t\tselectionEnd: getSelectionEnd(),\n\t\t\t\t\t\tinitialPosition:\n\t\t\t\t\t\t\tgetSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t\tpreviousAreBlocksDifferent = areBlocksDifferent;\n\t\t} );\n\n\t\treturn () => {\n\t\t\tsubscribed.current = false;\n\t\t\tunsubscribe();\n\t\t};\n\t}, [ registry, clientId ] );\n}\n"]}
|
|
@@ -320,6 +320,8 @@ export const withInspectorControls = createHigherOrderComponent(BlockEdit => pro
|
|
|
320
320
|
*/
|
|
321
321
|
|
|
322
322
|
export const withPositionStyles = createHigherOrderComponent(BlockListBlock => props => {
|
|
323
|
+
var _attributes$style2, _attributes$style2$po, _attributes$style3, _attributes$style3$po;
|
|
324
|
+
|
|
323
325
|
const {
|
|
324
326
|
name,
|
|
325
327
|
attributes
|
|
@@ -342,8 +344,9 @@ export const withPositionStyles = createHigherOrderComponent(BlockListBlock => p
|
|
|
342
344
|
|
|
343
345
|
|
|
344
346
|
const className = classnames(props === null || props === void 0 ? void 0 : props.className, {
|
|
345
|
-
[`wp-container-${id}`]: allowPositionStyles && !!css
|
|
346
|
-
|
|
347
|
+
[`wp-container-${id}`]: allowPositionStyles && !!css,
|
|
348
|
+
// Only attach a container class if there is generated CSS to be attached.
|
|
349
|
+
[`is-position-${attributes === null || attributes === void 0 ? void 0 : (_attributes$style2 = attributes.style) === null || _attributes$style2 === void 0 ? void 0 : (_attributes$style2$po = _attributes$style2.position) === null || _attributes$style2$po === void 0 ? void 0 : _attributes$style2$po.type}`]: allowPositionStyles && !!css && !!(attributes !== null && attributes !== void 0 && (_attributes$style3 = attributes.style) !== null && _attributes$style3 !== void 0 && (_attributes$style3$po = _attributes$style3.position) !== null && _attributes$style3$po !== void 0 && _attributes$style3$po.type)
|
|
347
350
|
});
|
|
348
351
|
return createElement(Fragment, null, allowPositionStyles && element && !!css && createPortal(createElement("style", null, css), element), createElement(BlockListBlock, _extends({}, props, {
|
|
349
352
|
className: className
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/position.js"],"names":["classnames","__","sprintf","getBlockSupport","hasBlockSupport","BaseControl","CustomSelectControl","createHigherOrderComponent","useInstanceId","useSelect","useContext","useMemo","createPortal","Platform","addFilter","BlockList","useSetting","InspectorControls","cleanEmptyObject","store","blockEditorStore","POSITION_SUPPORT_KEY","OPTION_CLASSNAME","DEFAULT_OPTION","key","value","name","className","STICKY_OPTION","__experimentalHint","FIXED_OPTION","POSITION_SIDES","VALID_POSITION_TYPES","getPositionCSS","selector","style","output","type","positionType","position","includes","forEach","side","undefined","hasStickyPositionSupport","blockType","support","sticky","hasFixedPositionSupport","fixed","hasPositionSupport","hasPositionValue","props","attributes","hasStickyOrFixedPositionValue","resetPosition","setAttributes","top","right","bottom","left","useIsPositionDisabled","blockName","allowFixed","allowSticky","isDisabled","PositionPanel","clientId","hasParents","select","getBlockParents","parents","length","options","availableOptions","push","onChangeType","next","placementValue","newStyle","selectedOption","find","option","web","selectedItem","native","withInspectorControls","BlockEdit","positionSupport","showPositionControls","withPositionStyles","BlockListBlock","hasPositionBlockSupport","allowPositionStyles","id","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CAAElB;AAFJ,KAAF,CAAd,IAGO,EAJR;AAKA,GAvBiC,CAyBlC;;;AACA,QAAMR,SAAS,GAAG3B,UAAU,CAAEoD,KAAF,aAAEA,KAAF,uBAAEA,KAAK,CAAEzB,SAAT,EAAoB;AAC/C,KAAG,gBAAgBmE,EAAI,EAAvB,GAA4BD,mBAAmB,IAAI,CAAC,CAAEK,GADP,CACY;;AADZ,GAApB,CAA5B;AAIA,SACC,8BACGL,mBAAmB,IACpBE,OADC,IAED,CAAC,CAAEG,GAFF,IAGDtF,YAAY,CAAE,6BAASsF,GAAT,CAAF,EAA0BH,OAA1B,CAJd,EAKC,cAAC,cAAD,eAAqB3C,KAArB;AAA6B,IAAA,SAAS,EAAGzB;AAAzC,KALD,CADD;AASA,CAxC0D,CAArD;AA2CPb,SAAS,CACR,uBADQ,EAER,2CAFQ,EAGR4E,kBAHQ,CAAT;AAKA5E,SAAS,CACR,kBADQ,EAER,8CAFQ,EAGRwE,qBAHQ,CAAT","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';\nimport { BaseControl, CustomSelectControl } from '@wordpress/components';\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tuseContext,\n\tuseMemo,\n\tcreatePortal,\n\tPlatform,\n} from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport BlockList from '../components/block-list';\nimport useSetting from '../components/use-setting';\nimport InspectorControls from '../components/inspector-controls';\nimport { cleanEmptyObject } from './utils';\nimport { store as blockEditorStore } from '../store';\n\nconst POSITION_SUPPORT_KEY = 'position';\n\nconst OPTION_CLASSNAME =\n\t'block-editor-hooks__position-selection__select-control__option';\n\nconst DEFAULT_OPTION = {\n\tkey: 'default',\n\tvalue: '',\n\tname: __( 'Default' ),\n\tclassName: OPTION_CLASSNAME,\n};\n\nconst STICKY_OPTION = {\n\tkey: 'sticky',\n\tvalue: 'sticky',\n\tname: __( 'Sticky' ),\n\tclassName: OPTION_CLASSNAME,\n\t__experimentalHint: __(\n\t\t'The block will stick to the top of the window instead of scrolling.'\n\t),\n};\n\nconst FIXED_OPTION = {\n\tkey: 'fixed',\n\tvalue: 'fixed',\n\tname: __( 'Fixed' ),\n\tclassName: OPTION_CLASSNAME,\n\t__experimentalHint: __(\n\t\t'The block will not move when the page is scrolled.'\n\t),\n};\n\nconst POSITION_SIDES = [ 'top', 'right', 'bottom', 'left' ];\nconst VALID_POSITION_TYPES = [ 'sticky', 'fixed' ];\n\n/**\n * Get calculated position CSS.\n *\n * @param {Object} props Component props.\n * @param {string} props.selector Selector to use.\n * @param {Object} props.style Style object.\n * @return {string} The generated CSS rules.\n */\nexport function getPositionCSS( { selector, style } ) {\n\tlet output = '';\n\n\tconst { type: positionType } = style?.position || {};\n\n\tif ( ! VALID_POSITION_TYPES.includes( positionType ) ) {\n\t\treturn output;\n\t}\n\n\toutput += `${ selector } {`;\n\toutput += `position: ${ positionType };`;\n\n\tPOSITION_SIDES.forEach( ( side ) => {\n\t\tif ( style?.position?.[ side ] !== undefined ) {\n\t\t\toutput += `${ side }: ${ style.position[ side ] };`;\n\t\t}\n\t} );\n\n\tif ( positionType === 'sticky' || positionType === 'fixed' ) {\n\t\t// TODO: Replace hard-coded z-index value with a z-index preset approach in theme.json.\n\t\toutput += `z-index: 10`;\n\t}\n\toutput += `}`;\n\n\treturn output;\n}\n\n/**\n * Determines if there is sticky position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasStickyPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.sticky );\n}\n\n/**\n * Determines if there is fixed position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasFixedPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.fixed );\n}\n\n/**\n * Determines if there is position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! support;\n}\n\n/**\n * Checks if there is a current value in the position block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a position value set.\n */\nexport function hasPositionValue( props ) {\n\treturn props.attributes.style?.position?.type !== undefined;\n}\n\n/**\n * Checks if the block is currently set to a sticky or fixed position.\n * This check is helpful for determining how to position block toolbars or other elements.\n *\n * @param {Object} attributes Block attributes.\n * @return {boolean} Whether or not the block is set to a sticky or fixed position.\n */\nexport function hasStickyOrFixedPositionValue( attributes ) {\n\tconst positionType = attributes.style?.position?.type;\n\treturn positionType === 'sticky' || positionType === 'fixed';\n}\n\n/**\n * Resets the position block support attributes. This can be used when disabling\n * the position support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetPosition( { attributes = {}, setAttributes } ) {\n\tconst { style = {} } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: undefined,\n\t\t\t\ttop: undefined,\n\t\t\t\tright: undefined,\n\t\t\t\tbottom: undefined,\n\t\t\t\tleft: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if position settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether padding setting is disabled.\n */\nexport function useIsPositionDisabled( { name: blockName } = {} ) {\n\tconst allowFixed = useSetting( 'position.fixed' );\n\tconst allowSticky = useSetting( 'position.sticky' );\n\tconst isDisabled = ! allowFixed && ! allowSticky;\n\n\treturn ! hasPositionSupport( blockName ) || isDisabled;\n}\n\n/*\n * Position controls rendered in an inspector control panel.\n *\n * @param {Object} props\n *\n * @return {WPElement} Position panel.\n */\nexport function PositionPanel( props ) {\n\tconst {\n\t\tattributes: { style = {} },\n\t\tclientId,\n\t\tname: blockName,\n\t\tsetAttributes,\n\t} = props;\n\n\tconst allowFixed = hasFixedPositionSupport( blockName );\n\tconst allowSticky = hasStickyPositionSupport( blockName );\n\tconst value = style?.position?.type;\n\n\tconst { hasParents } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockParents } = select( blockEditorStore );\n\t\t\tconst parents = getBlockParents( clientId );\n\t\t\treturn {\n\t\t\t\thasParents: parents.length,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst options = useMemo( () => {\n\t\tconst availableOptions = [ DEFAULT_OPTION ];\n\t\t// Only display sticky option if the block has no parents (is at the root of the document),\n\t\t// or if the block already has a sticky position value set.\n\t\tif (\n\t\t\t( allowSticky && ! hasParents ) ||\n\t\t\tvalue === STICKY_OPTION.value\n\t\t) {\n\t\t\tavailableOptions.push( STICKY_OPTION );\n\t\t}\n\t\tif ( allowFixed || value === FIXED_OPTION.value ) {\n\t\t\tavailableOptions.push( FIXED_OPTION );\n\t\t}\n\t\treturn availableOptions;\n\t}, [ allowFixed, allowSticky, hasParents, value ] );\n\n\tconst onChangeType = ( next ) => {\n\t\t// For now, use a hard-coded `0px` value for the position.\n\t\t// `0px` is preferred over `0` as it can be used in `calc()` functions.\n\t\t// In the future, it could be useful to allow for an offset value.\n\t\tconst placementValue = '0px';\n\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: next,\n\t\t\t\ttop:\n\t\t\t\t\tnext === 'sticky' || next === 'fixed'\n\t\t\t\t\t\t? placementValue\n\t\t\t\t\t\t: undefined,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\tconst selectedOption = value\n\t\t? options.find( ( option ) => option.value === value ) || DEFAULT_OPTION\n\t\t: DEFAULT_OPTION;\n\n\t// Only display position controls if there is at least one option to choose from.\n\treturn Platform.select( {\n\t\tweb:\n\t\t\toptions.length > 1 ? (\n\t\t\t\t<InspectorControls group=\"position\">\n\t\t\t\t\t<BaseControl className=\"block-editor-hooks__position-selection\">\n\t\t\t\t\t\t<CustomSelectControl\n\t\t\t\t\t\t\t__nextUnconstrainedWidth\n\t\t\t\t\t\t\t__next36pxDefaultSize\n\t\t\t\t\t\t\tclassName=\"block-editor-hooks__position-selection__select-control\"\n\t\t\t\t\t\t\tlabel={ __( 'Position' ) }\n\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\tdescribedBy={ sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: Currently selected position.\n\t\t\t\t\t\t\t\t__( 'Currently selected position: %s' ),\n\t\t\t\t\t\t\t\tselectedOption.name\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\toptions={ options }\n\t\t\t\t\t\t\tvalue={ selectedOption }\n\t\t\t\t\t\t\t__experimentalShowSelectedHint\n\t\t\t\t\t\t\tonChange={ ( { selectedItem } ) => {\n\t\t\t\t\t\t\t\tonChangeType( selectedItem.value );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tsize={ '__unstable-large' }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BaseControl>\n\t\t\t\t</InspectorControls>\n\t\t\t) : null,\n\t\tnative: null,\n\t} );\n}\n\n/**\n * Override the default edit UI to include position controls.\n *\n * @param {Function} BlockEdit Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withInspectorControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { name: blockName } = props;\n\t\tconst positionSupport = hasBlockSupport(\n\t\t\tblockName,\n\t\t\tPOSITION_SUPPORT_KEY\n\t\t);\n\t\tconst showPositionControls =\n\t\t\tpositionSupport && ! useIsPositionDisabled( props );\n\n\t\treturn [\n\t\t\tshowPositionControls && (\n\t\t\t\t<PositionPanel key=\"position\" { ...props } />\n\t\t\t),\n\t\t\t<BlockEdit key=\"edit\" { ...props } />,\n\t\t];\n\t},\n\t'withInspectorControls'\n);\n\n/**\n * Override the default block element to add the position styles.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withPositionStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst { name, attributes } = props;\n\t\tconst hasPositionBlockSupport = hasBlockSupport(\n\t\t\tname,\n\t\t\tPOSITION_SUPPORT_KEY\n\t\t);\n\t\tconst allowPositionStyles =\n\t\t\thasPositionBlockSupport && ! useIsPositionDisabled( props );\n\n\t\tconst id = useInstanceId( BlockListBlock );\n\t\tconst element = useContext( BlockList.__unstableElementContext );\n\n\t\t// Higher specificity to override defaults in editor UI.\n\t\tconst positionSelector = `.wp-container-${ id }.wp-container-${ id }`;\n\n\t\t// Get CSS string for the current position values.\n\t\tlet css;\n\t\tif ( allowPositionStyles ) {\n\t\t\tcss =\n\t\t\t\tgetPositionCSS( {\n\t\t\t\t\tselector: positionSelector,\n\t\t\t\t\tstyle: attributes?.style,\n\t\t\t\t} ) || '';\n\t\t}\n\n\t\t// Attach a `wp-container-` id-based class name.\n\t\tconst className = classnames( props?.className, {\n\t\t\t[ `wp-container-${ id }` ]: allowPositionStyles && !! css, // Only attach a container class if there is generated CSS to be attached.\n\t\t} );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ allowPositionStyles &&\n\t\t\t\t\telement &&\n\t\t\t\t\t!! css &&\n\t\t\t\t\tcreatePortal( <style>{ css }</style>, element ) }\n\t\t\t\t<BlockListBlock { ...props } className={ className } />\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/editor/position/with-position-styles',\n\twithPositionStyles\n);\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/position/with-inspector-controls',\n\twithInspectorControls\n);\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/position.js"],"names":["classnames","__","sprintf","getBlockSupport","hasBlockSupport","BaseControl","CustomSelectControl","createHigherOrderComponent","useInstanceId","useSelect","useContext","useMemo","createPortal","Platform","addFilter","BlockList","useSetting","InspectorControls","cleanEmptyObject","store","blockEditorStore","POSITION_SUPPORT_KEY","OPTION_CLASSNAME","DEFAULT_OPTION","key","value","name","className","STICKY_OPTION","__experimentalHint","FIXED_OPTION","POSITION_SIDES","VALID_POSITION_TYPES","getPositionCSS","selector","style","output","type","positionType","position","includes","forEach","side","undefined","hasStickyPositionSupport","blockType","support","sticky","hasFixedPositionSupport","fixed","hasPositionSupport","hasPositionValue","props","attributes","hasStickyOrFixedPositionValue","resetPosition","setAttributes","top","right","bottom","left","useIsPositionDisabled","blockName","allowFixed","allowSticky","isDisabled","PositionPanel","clientId","hasParents","select","getBlockParents","parents","length","options","availableOptions","push","onChangeType","next","placementValue","newStyle","selectedOption","find","option","web","selectedItem","native","withInspectorControls","BlockEdit","positionSupport","showPositionControls","withPositionStyles","BlockListBlock","hasPositionBlockSupport","allowPositionStyles","id","element","__unstableElementContext","positionSelector","css"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,eAAT,EAA0BC,eAA1B,QAAiD,mBAAjD;AACA,SAASC,WAAT,EAAsBC,mBAAtB,QAAiD,uBAAjD;AACA,SAASC,0BAAT,EAAqCC,aAArC,QAA0D,oBAA1D;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SACCC,UADD,EAECC,OAFD,EAGCC,YAHD,EAICC,QAJD,QAKO,oBALP;AAMA,SAASC,SAAT,QAA0B,kBAA1B;AAEA;AAC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C,EAAE7C,UAAF,aAAEA,UAAF,qCAAEA,UAAU,CAAElB,KAAd,wEAAE,mBAAmBI,QAArB,kDAAE,sBAA6BF,IAA/B;AAL6C,GAApB,CAA5B;AAQA,SACC,8BACGwD,mBAAmB,IACpBE,OADC,IAED,CAAC,CAAEG,GAFF,IAGDtF,YAAY,CAAE,6BAASsF,GAAT,CAAF,EAA0BH,OAA1B,CAJd,EAKC,cAAC,cAAD,eAAqB3C,KAArB;AAA6B,IAAA,SAAS,EAAGzB;AAAzC,KALD,CADD;AASA,CA5C0D,CAArD;AA+CPb,SAAS,CACR,uBADQ,EAER,2CAFQ,EAGR4E,kBAHQ,CAAT;AAKA5E,SAAS,CACR,kBADQ,EAER,8CAFQ,EAGRwE,qBAHQ,CAAT","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';\nimport { BaseControl, CustomSelectControl } from '@wordpress/components';\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tuseContext,\n\tuseMemo,\n\tcreatePortal,\n\tPlatform,\n} from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport BlockList from '../components/block-list';\nimport useSetting from '../components/use-setting';\nimport InspectorControls from '../components/inspector-controls';\nimport { cleanEmptyObject } from './utils';\nimport { store as blockEditorStore } from '../store';\n\nconst POSITION_SUPPORT_KEY = 'position';\n\nconst OPTION_CLASSNAME =\n\t'block-editor-hooks__position-selection__select-control__option';\n\nconst DEFAULT_OPTION = {\n\tkey: 'default',\n\tvalue: '',\n\tname: __( 'Default' ),\n\tclassName: OPTION_CLASSNAME,\n};\n\nconst STICKY_OPTION = {\n\tkey: 'sticky',\n\tvalue: 'sticky',\n\tname: __( 'Sticky' ),\n\tclassName: OPTION_CLASSNAME,\n\t__experimentalHint: __(\n\t\t'The block will stick to the top of the window instead of scrolling.'\n\t),\n};\n\nconst FIXED_OPTION = {\n\tkey: 'fixed',\n\tvalue: 'fixed',\n\tname: __( 'Fixed' ),\n\tclassName: OPTION_CLASSNAME,\n\t__experimentalHint: __(\n\t\t'The block will not move when the page is scrolled.'\n\t),\n};\n\nconst POSITION_SIDES = [ 'top', 'right', 'bottom', 'left' ];\nconst VALID_POSITION_TYPES = [ 'sticky', 'fixed' ];\n\n/**\n * Get calculated position CSS.\n *\n * @param {Object} props Component props.\n * @param {string} props.selector Selector to use.\n * @param {Object} props.style Style object.\n * @return {string} The generated CSS rules.\n */\nexport function getPositionCSS( { selector, style } ) {\n\tlet output = '';\n\n\tconst { type: positionType } = style?.position || {};\n\n\tif ( ! VALID_POSITION_TYPES.includes( positionType ) ) {\n\t\treturn output;\n\t}\n\n\toutput += `${ selector } {`;\n\toutput += `position: ${ positionType };`;\n\n\tPOSITION_SIDES.forEach( ( side ) => {\n\t\tif ( style?.position?.[ side ] !== undefined ) {\n\t\t\toutput += `${ side }: ${ style.position[ side ] };`;\n\t\t}\n\t} );\n\n\tif ( positionType === 'sticky' || positionType === 'fixed' ) {\n\t\t// TODO: Replace hard-coded z-index value with a z-index preset approach in theme.json.\n\t\toutput += `z-index: 10`;\n\t}\n\toutput += `}`;\n\n\treturn output;\n}\n\n/**\n * Determines if there is sticky position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasStickyPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.sticky );\n}\n\n/**\n * Determines if there is fixed position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasFixedPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.fixed );\n}\n\n/**\n * Determines if there is position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! support;\n}\n\n/**\n * Checks if there is a current value in the position block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a position value set.\n */\nexport function hasPositionValue( props ) {\n\treturn props.attributes.style?.position?.type !== undefined;\n}\n\n/**\n * Checks if the block is currently set to a sticky or fixed position.\n * This check is helpful for determining how to position block toolbars or other elements.\n *\n * @param {Object} attributes Block attributes.\n * @return {boolean} Whether or not the block is set to a sticky or fixed position.\n */\nexport function hasStickyOrFixedPositionValue( attributes ) {\n\tconst positionType = attributes.style?.position?.type;\n\treturn positionType === 'sticky' || positionType === 'fixed';\n}\n\n/**\n * Resets the position block support attributes. This can be used when disabling\n * the position support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetPosition( { attributes = {}, setAttributes } ) {\n\tconst { style = {} } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: undefined,\n\t\t\t\ttop: undefined,\n\t\t\t\tright: undefined,\n\t\t\t\tbottom: undefined,\n\t\t\t\tleft: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if position settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether padding setting is disabled.\n */\nexport function useIsPositionDisabled( { name: blockName } = {} ) {\n\tconst allowFixed = useSetting( 'position.fixed' );\n\tconst allowSticky = useSetting( 'position.sticky' );\n\tconst isDisabled = ! allowFixed && ! allowSticky;\n\n\treturn ! hasPositionSupport( blockName ) || isDisabled;\n}\n\n/*\n * Position controls rendered in an inspector control panel.\n *\n * @param {Object} props\n *\n * @return {WPElement} Position panel.\n */\nexport function PositionPanel( props ) {\n\tconst {\n\t\tattributes: { style = {} },\n\t\tclientId,\n\t\tname: blockName,\n\t\tsetAttributes,\n\t} = props;\n\n\tconst allowFixed = hasFixedPositionSupport( blockName );\n\tconst allowSticky = hasStickyPositionSupport( blockName );\n\tconst value = style?.position?.type;\n\n\tconst { hasParents } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockParents } = select( blockEditorStore );\n\t\t\tconst parents = getBlockParents( clientId );\n\t\t\treturn {\n\t\t\t\thasParents: parents.length,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst options = useMemo( () => {\n\t\tconst availableOptions = [ DEFAULT_OPTION ];\n\t\t// Only display sticky option if the block has no parents (is at the root of the document),\n\t\t// or if the block already has a sticky position value set.\n\t\tif (\n\t\t\t( allowSticky && ! hasParents ) ||\n\t\t\tvalue === STICKY_OPTION.value\n\t\t) {\n\t\t\tavailableOptions.push( STICKY_OPTION );\n\t\t}\n\t\tif ( allowFixed || value === FIXED_OPTION.value ) {\n\t\t\tavailableOptions.push( FIXED_OPTION );\n\t\t}\n\t\treturn availableOptions;\n\t}, [ allowFixed, allowSticky, hasParents, value ] );\n\n\tconst onChangeType = ( next ) => {\n\t\t// For now, use a hard-coded `0px` value for the position.\n\t\t// `0px` is preferred over `0` as it can be used in `calc()` functions.\n\t\t// In the future, it could be useful to allow for an offset value.\n\t\tconst placementValue = '0px';\n\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: next,\n\t\t\t\ttop:\n\t\t\t\t\tnext === 'sticky' || next === 'fixed'\n\t\t\t\t\t\t? placementValue\n\t\t\t\t\t\t: undefined,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\tconst selectedOption = value\n\t\t? options.find( ( option ) => option.value === value ) || DEFAULT_OPTION\n\t\t: DEFAULT_OPTION;\n\n\t// Only display position controls if there is at least one option to choose from.\n\treturn Platform.select( {\n\t\tweb:\n\t\t\toptions.length > 1 ? (\n\t\t\t\t<InspectorControls group=\"position\">\n\t\t\t\t\t<BaseControl className=\"block-editor-hooks__position-selection\">\n\t\t\t\t\t\t<CustomSelectControl\n\t\t\t\t\t\t\t__nextUnconstrainedWidth\n\t\t\t\t\t\t\t__next36pxDefaultSize\n\t\t\t\t\t\t\tclassName=\"block-editor-hooks__position-selection__select-control\"\n\t\t\t\t\t\t\tlabel={ __( 'Position' ) }\n\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\tdescribedBy={ sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: Currently selected position.\n\t\t\t\t\t\t\t\t__( 'Currently selected position: %s' ),\n\t\t\t\t\t\t\t\tselectedOption.name\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\toptions={ options }\n\t\t\t\t\t\t\tvalue={ selectedOption }\n\t\t\t\t\t\t\t__experimentalShowSelectedHint\n\t\t\t\t\t\t\tonChange={ ( { selectedItem } ) => {\n\t\t\t\t\t\t\t\tonChangeType( selectedItem.value );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tsize={ '__unstable-large' }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BaseControl>\n\t\t\t\t</InspectorControls>\n\t\t\t) : null,\n\t\tnative: null,\n\t} );\n}\n\n/**\n * Override the default edit UI to include position controls.\n *\n * @param {Function} BlockEdit Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withInspectorControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { name: blockName } = props;\n\t\tconst positionSupport = hasBlockSupport(\n\t\t\tblockName,\n\t\t\tPOSITION_SUPPORT_KEY\n\t\t);\n\t\tconst showPositionControls =\n\t\t\tpositionSupport && ! useIsPositionDisabled( props );\n\n\t\treturn [\n\t\t\tshowPositionControls && (\n\t\t\t\t<PositionPanel key=\"position\" { ...props } />\n\t\t\t),\n\t\t\t<BlockEdit key=\"edit\" { ...props } />,\n\t\t];\n\t},\n\t'withInspectorControls'\n);\n\n/**\n * Override the default block element to add the position styles.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withPositionStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst { name, attributes } = props;\n\t\tconst hasPositionBlockSupport = hasBlockSupport(\n\t\t\tname,\n\t\t\tPOSITION_SUPPORT_KEY\n\t\t);\n\t\tconst allowPositionStyles =\n\t\t\thasPositionBlockSupport && ! useIsPositionDisabled( props );\n\n\t\tconst id = useInstanceId( BlockListBlock );\n\t\tconst element = useContext( BlockList.__unstableElementContext );\n\n\t\t// Higher specificity to override defaults in editor UI.\n\t\tconst positionSelector = `.wp-container-${ id }.wp-container-${ id }`;\n\n\t\t// Get CSS string for the current position values.\n\t\tlet css;\n\t\tif ( allowPositionStyles ) {\n\t\t\tcss =\n\t\t\t\tgetPositionCSS( {\n\t\t\t\t\tselector: positionSelector,\n\t\t\t\t\tstyle: attributes?.style,\n\t\t\t\t} ) || '';\n\t\t}\n\n\t\t// Attach a `wp-container-` id-based class name.\n\t\tconst className = classnames( props?.className, {\n\t\t\t[ `wp-container-${ id }` ]: allowPositionStyles && !! css, // Only attach a container class if there is generated CSS to be attached.\n\t\t\t[ `is-position-${ attributes?.style?.position?.type }` ]:\n\t\t\t\tallowPositionStyles &&\n\t\t\t\t!! css &&\n\t\t\t\t!! attributes?.style?.position?.type,\n\t\t} );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ allowPositionStyles &&\n\t\t\t\t\telement &&\n\t\t\t\t\t!! css &&\n\t\t\t\t\tcreatePortal( <style>{ css }</style>, element ) }\n\t\t\t\t<BlockListBlock { ...props } className={ className } />\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/editor/position/with-position-styles',\n\twithPositionStyles\n);\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/position/with-inspector-controls',\n\twithInspectorControls\n);\n"]}
|
|
@@ -148,6 +148,18 @@ export const SETTINGS_DEFAULTS = {
|
|
|
148
148
|
__experimentalBlockPatternCategories: [],
|
|
149
149
|
__unstableGalleryWithImageBlocks: false,
|
|
150
150
|
__unstableIsPreviewMode: false,
|
|
151
|
+
// This setting is `private` now with `lock` API.
|
|
152
|
+
blockInspectorAnimation: {
|
|
153
|
+
'core/navigation': {
|
|
154
|
+
enterDirection: 'leftToRight'
|
|
155
|
+
},
|
|
156
|
+
'core/navigation-submenu': {
|
|
157
|
+
enterDirection: 'rightToLeft'
|
|
158
|
+
},
|
|
159
|
+
'core/navigation-link': {
|
|
160
|
+
enterDirection: 'rightToLeft'
|
|
161
|
+
}
|
|
162
|
+
},
|
|
151
163
|
generateAnchors: false,
|
|
152
164
|
// gradients setting is not used anymore now defaults are passed from theme.json on the server and core has its own defaults.
|
|
153
165
|
// The setting is only kept for backward compatibility purposes.
|