@wordpress/editor 13.22.0 → 13.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/build/components/entities-saved-states/index.js +15 -1
- package/build/components/entities-saved-states/index.js.map +1 -1
- package/build/components/index.js +32 -0
- package/build/components/index.js.map +1 -1
- package/build/components/page-attributes/order.js +1 -0
- package/build/components/page-attributes/order.js.map +1 -1
- package/build/components/post-author/panel.js +24 -0
- package/build/components/post-author/panel.js.map +1 -0
- package/build/components/post-featured-image/index.js +3 -1
- package/build/components/post-featured-image/index.js.map +1 -1
- package/build/components/post-panel-row/index.js +36 -0
- package/build/components/post-panel-row/index.js.map +1 -0
- package/build/components/post-saved-state/index.js +21 -16
- package/build/components/post-saved-state/index.js.map +1 -1
- package/build/components/post-schedule/panel.js +67 -0
- package/build/components/post-schedule/panel.js.map +1 -0
- package/build/components/post-sync-status/index.js +9 -5
- package/build/components/post-sync-status/index.js.map +1 -1
- package/build/components/post-title/constants.js +11 -0
- package/build/components/post-title/constants.js.map +1 -0
- package/build/components/post-title/index.js +61 -90
- package/build/components/post-title/index.js.map +1 -1
- package/build/components/post-title/index.native.js +1 -1
- package/build/components/post-title/index.native.js.map +1 -1
- package/build/components/post-title/post-title-raw.js +92 -0
- package/build/components/post-title/post-title-raw.js.map +1 -0
- package/build/components/post-title/use-post-title-focus.js +64 -0
- package/build/components/post-title/use-post-title-focus.js.map +1 -0
- package/build/components/post-title/use-post-title.js +41 -0
- package/build/components/post-title/use-post-title.js.map +1 -0
- package/build/components/post-url/panel.js +70 -0
- package/build/components/post-url/panel.js.map +1 -0
- package/build/components/provider/constants.js +9 -0
- package/build/components/provider/constants.js.map +1 -0
- package/build/components/provider/disable-non-page-content-blocks.js +63 -0
- package/build/components/provider/disable-non-page-content-blocks.js.map +1 -0
- package/build/components/provider/index.js +126 -14
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.js +22 -17
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.native.js +2 -2
- package/build/components/provider/use-block-editor-settings.native.js.map +1 -1
- package/build/private-apis.js +7 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +23 -2
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +10 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +16 -2
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/entities-saved-states/index.js +16 -2
- package/build-module/components/entities-saved-states/index.js.map +1 -1
- package/build-module/components/index.js +4 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/page-attributes/order.js +1 -0
- package/build-module/components/page-attributes/order.js.map +1 -1
- package/build-module/components/post-author/panel.js +14 -0
- package/build-module/components/post-author/panel.js.map +1 -0
- package/build-module/components/post-featured-image/index.js +3 -1
- package/build-module/components/post-featured-image/index.js.map +1 -1
- package/build-module/components/post-panel-row/index.js +27 -0
- package/build-module/components/post-panel-row/index.js.map +1 -0
- package/build-module/components/post-saved-state/index.js +22 -17
- package/build-module/components/post-saved-state/index.js.map +1 -1
- package/build-module/components/post-schedule/panel.js +59 -0
- package/build-module/components/post-schedule/panel.js.map +1 -0
- package/build-module/components/post-sync-status/index.js +10 -7
- package/build-module/components/post-sync-status/index.js.map +1 -1
- package/build-module/components/post-title/constants.js +3 -0
- package/build-module/components/post-title/constants.js.map +1 -0
- package/build-module/components/post-title/index.js +62 -92
- package/build-module/components/post-title/index.js.map +1 -1
- package/build-module/components/post-title/index.native.js +3 -3
- package/build-module/components/post-title/index.native.js.map +1 -1
- package/build-module/components/post-title/post-title-raw.js +83 -0
- package/build-module/components/post-title/post-title-raw.js.map +1 -0
- package/build-module/components/post-title/use-post-title-focus.js +57 -0
- package/build-module/components/post-title/use-post-title-focus.js.map +1 -0
- package/build-module/components/post-title/use-post-title.js +33 -0
- package/build-module/components/post-title/use-post-title.js.map +1 -0
- package/build-module/components/post-url/panel.js +62 -0
- package/build-module/components/post-url/panel.js.map +1 -0
- package/build-module/components/provider/constants.js +2 -0
- package/build-module/components/provider/constants.js.map +1 -0
- package/build-module/components/provider/disable-non-page-content-blocks.js +56 -0
- package/build-module/components/provider/disable-non-page-content-blocks.js.map +1 -0
- package/build-module/components/provider/index.js +127 -15
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.js +22 -17
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.native.js +2 -2
- package/build-module/components/provider/use-block-editor-settings.native.js.map +1 -1
- package/build-module/private-apis.js +6 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +21 -0
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +9 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +11 -0
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +70 -10
- package/build-style/style.css +70 -10
- package/package.json +31 -31
- package/src/components/entities-saved-states/index.js +16 -1
- package/src/components/index.js +4 -0
- package/src/components/page-attributes/order.js +1 -0
- package/src/components/post-author/panel.js +18 -0
- package/src/components/post-author/style.scss +7 -0
- package/src/components/post-featured-image/index.js +3 -1
- package/src/components/post-panel-row/index.js +26 -0
- package/src/components/post-panel-row/style.scss +21 -0
- package/src/components/post-saved-state/index.js +46 -37
- package/src/components/post-schedule/panel.js +65 -0
- package/src/components/post-schedule/style.scss +23 -0
- package/src/components/post-sync-status/index.js +10 -8
- package/src/components/post-sync-status/style.scss +3 -18
- package/src/components/post-title/constants.js +4 -0
- package/src/components/post-title/index.js +56 -88
- package/src/components/post-title/index.native.js +4 -8
- package/src/components/post-title/post-title-raw.js +82 -0
- package/src/components/post-title/style.scss +5 -0
- package/src/components/post-title/use-post-title-focus.js +50 -0
- package/src/components/post-title/use-post-title.js +25 -0
- package/src/components/post-url/panel.js +60 -0
- package/src/components/post-url/style.scss +19 -0
- package/src/components/provider/README.md +37 -0
- package/src/components/provider/constants.js +5 -0
- package/src/components/provider/disable-non-page-content-blocks.js +55 -0
- package/src/components/provider/index.js +200 -14
- package/src/components/provider/use-block-editor-settings.js +54 -35
- package/src/components/provider/use-block-editor-settings.native.js +2 -2
- package/src/private-apis.js +6 -0
- package/src/store/actions.js +21 -0
- package/src/store/reducer.js +10 -0
- package/src/store/selectors.js +11 -0
- package/src/style.scss +4 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
|
+
var _components = require("@wordpress/components");
|
|
11
|
+
var _i18n = require("@wordpress/i18n");
|
|
12
|
+
var _htmlEntities = require("@wordpress/html-entities");
|
|
13
|
+
var _data = require("@wordpress/data");
|
|
14
|
+
var _blockEditor = require("@wordpress/block-editor");
|
|
15
|
+
var _element = require("@wordpress/element");
|
|
16
|
+
var _constants = require("./constants");
|
|
17
|
+
var _usePostTitleFocus = _interopRequireDefault(require("./use-post-title-focus"));
|
|
18
|
+
var _usePostTitle = _interopRequireDefault(require("./use-post-title"));
|
|
19
|
+
/**
|
|
20
|
+
* External dependencies
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* WordPress dependencies
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Internal dependencies
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
function PostTitleRaw(_, forwardedRef) {
|
|
32
|
+
const {
|
|
33
|
+
placeholder,
|
|
34
|
+
hasFixedToolbar
|
|
35
|
+
} = (0, _data.useSelect)(select => {
|
|
36
|
+
const {
|
|
37
|
+
getSettings
|
|
38
|
+
} = select(_blockEditor.store);
|
|
39
|
+
const {
|
|
40
|
+
titlePlaceholder,
|
|
41
|
+
hasFixedToolbar: _hasFixedToolbar
|
|
42
|
+
} = getSettings();
|
|
43
|
+
return {
|
|
44
|
+
placeholder: titlePlaceholder,
|
|
45
|
+
hasFixedToolbar: _hasFixedToolbar
|
|
46
|
+
};
|
|
47
|
+
}, []);
|
|
48
|
+
const [isSelected, setIsSelected] = (0, _element.useState)(false);
|
|
49
|
+
const {
|
|
50
|
+
title,
|
|
51
|
+
setTitle: onUpdate
|
|
52
|
+
} = (0, _usePostTitle.default)();
|
|
53
|
+
const {
|
|
54
|
+
ref: focusRef
|
|
55
|
+
} = (0, _usePostTitleFocus.default)(forwardedRef);
|
|
56
|
+
function onChange(value) {
|
|
57
|
+
onUpdate(value.replace(_constants.REGEXP_NEWLINES, ' '));
|
|
58
|
+
}
|
|
59
|
+
function onSelect() {
|
|
60
|
+
setIsSelected(true);
|
|
61
|
+
}
|
|
62
|
+
function onUnselect() {
|
|
63
|
+
setIsSelected(false);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The wp-block className is important for editor styles.
|
|
67
|
+
// This same block is used in both the visual and the code editor.
|
|
68
|
+
const className = (0, _classnames.default)(_constants.DEFAULT_CLASSNAMES, {
|
|
69
|
+
'is-selected': isSelected,
|
|
70
|
+
'has-fixed-toolbar': hasFixedToolbar,
|
|
71
|
+
'is-raw-text': true
|
|
72
|
+
});
|
|
73
|
+
const decodedPlaceholder = (0, _htmlEntities.decodeEntities)(placeholder) || (0, _i18n.__)('Add title');
|
|
74
|
+
return (0, _react.createElement)(_components.TextareaControl, {
|
|
75
|
+
ref: focusRef,
|
|
76
|
+
value: title,
|
|
77
|
+
onChange: onChange,
|
|
78
|
+
onFocus: onSelect,
|
|
79
|
+
onBlur: onUnselect,
|
|
80
|
+
label: placeholder,
|
|
81
|
+
className: className,
|
|
82
|
+
placeholder: decodedPlaceholder,
|
|
83
|
+
hideLabelFromVision: true,
|
|
84
|
+
autoComplete: "off",
|
|
85
|
+
dir: "auto",
|
|
86
|
+
rows: 1,
|
|
87
|
+
__nextHasNoMarginBottom: true
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
var _default = (0, _element.forwardRef)(PostTitleRaw);
|
|
91
|
+
exports.default = _default;
|
|
92
|
+
//# sourceMappingURL=post-title-raw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_classnames","_interopRequireDefault","require","_components","_i18n","_htmlEntities","_data","_blockEditor","_element","_constants","_usePostTitleFocus","_usePostTitle","PostTitleRaw","_","forwardedRef","placeholder","hasFixedToolbar","useSelect","select","getSettings","blockEditorStore","titlePlaceholder","_hasFixedToolbar","isSelected","setIsSelected","useState","title","setTitle","onUpdate","usePostTitle","ref","focusRef","usePostTitleFocus","onChange","value","replace","REGEXP_NEWLINES","onSelect","onUnselect","className","classnames","DEFAULT_CLASSNAMES","decodedPlaceholder","decodeEntities","__","_react","createElement","TextareaControl","onFocus","onBlur","label","hideLabelFromVision","autoComplete","dir","rows","__nextHasNoMarginBottom","_default","forwardRef","exports","default"],"sources":["@wordpress/editor/src/components/post-title/post-title-raw.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { TextareaControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { DEFAULT_CLASSNAMES, REGEXP_NEWLINES } from './constants';\nimport usePostTitleFocus from './use-post-title-focus';\nimport usePostTitle from './use-post-title';\n\nfunction PostTitleRaw( _, forwardedRef ) {\n\tconst { placeholder, hasFixedToolbar } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst { titlePlaceholder, hasFixedToolbar: _hasFixedToolbar } =\n\t\t\tgetSettings();\n\n\t\treturn {\n\t\t\tplaceholder: titlePlaceholder,\n\t\t\thasFixedToolbar: _hasFixedToolbar,\n\t\t};\n\t}, [] );\n\n\tconst [ isSelected, setIsSelected ] = useState( false );\n\n\tconst { title, setTitle: onUpdate } = usePostTitle();\n\tconst { ref: focusRef } = usePostTitleFocus( forwardedRef );\n\n\tfunction onChange( value ) {\n\t\tonUpdate( value.replace( REGEXP_NEWLINES, ' ' ) );\n\t}\n\n\tfunction onSelect() {\n\t\tsetIsSelected( true );\n\t}\n\n\tfunction onUnselect() {\n\t\tsetIsSelected( false );\n\t}\n\n\t// The wp-block className is important for editor styles.\n\t// This same block is used in both the visual and the code editor.\n\tconst className = classnames( DEFAULT_CLASSNAMES, {\n\t\t'is-selected': isSelected,\n\t\t'has-fixed-toolbar': hasFixedToolbar,\n\t\t'is-raw-text': true,\n\t} );\n\n\tconst decodedPlaceholder =\n\t\tdecodeEntities( placeholder ) || __( 'Add title' );\n\n\treturn (\n\t\t<TextareaControl\n\t\t\tref={ focusRef }\n\t\t\tvalue={ title }\n\t\t\tonChange={ onChange }\n\t\t\tonFocus={ onSelect }\n\t\t\tonBlur={ onUnselect }\n\t\t\tlabel={ placeholder }\n\t\t\tclassName={ className }\n\t\t\tplaceholder={ decodedPlaceholder }\n\t\t\thideLabelFromVision={ true }\n\t\t\tautoComplete=\"off\"\n\t\t\tdir=\"auto\"\n\t\t\trows={ 1 }\n\t\t\t__nextHasNoMarginBottom\n\t\t/>\n\t);\n}\n\nexport default forwardRef( PostTitleRaw );\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAKA,IAAAO,UAAA,GAAAP,OAAA;AACA,IAAAQ,kBAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,aAAA,GAAAV,sBAAA,CAAAC,OAAA;AApBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;;AAKA,SAASU,YAAYA,CAAEC,CAAC,EAAEC,YAAY,EAAG;EACxC,MAAM;IAAEC,WAAW;IAAEC;EAAgB,CAAC,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IACjE,MAAM;MAAEC;IAAY,CAAC,GAAGD,MAAM,CAAEE,kBAAiB,CAAC;IAClD,MAAM;MAAEC,gBAAgB;MAAEL,eAAe,EAAEM;IAAiB,CAAC,GAC5DH,WAAW,CAAC,CAAC;IAEd,OAAO;MACNJ,WAAW,EAAEM,gBAAgB;MAC7BL,eAAe,EAAEM;IAClB,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,MAAM,CAAEC,UAAU,EAAEC,aAAa,CAAE,GAAG,IAAAC,iBAAQ,EAAE,KAAM,CAAC;EAEvD,MAAM;IAAEC,KAAK;IAAEC,QAAQ,EAAEC;EAAS,CAAC,GAAG,IAAAC,qBAAY,EAAC,CAAC;EACpD,MAAM;IAAEC,GAAG,EAAEC;EAAS,CAAC,GAAG,IAAAC,0BAAiB,EAAElB,YAAa,CAAC;EAE3D,SAASmB,QAAQA,CAAEC,KAAK,EAAG;IAC1BN,QAAQ,CAAEM,KAAK,CAACC,OAAO,CAAEC,0BAAe,EAAE,GAAI,CAAE,CAAC;EAClD;EAEA,SAASC,QAAQA,CAAA,EAAG;IACnBb,aAAa,CAAE,IAAK,CAAC;EACtB;EAEA,SAASc,UAAUA,CAAA,EAAG;IACrBd,aAAa,CAAE,KAAM,CAAC;EACvB;;EAEA;EACA;EACA,MAAMe,SAAS,GAAG,IAAAC,mBAAU,EAAEC,6BAAkB,EAAE;IACjD,aAAa,EAAElB,UAAU;IACzB,mBAAmB,EAAEP,eAAe;IACpC,aAAa,EAAE;EAChB,CAAE,CAAC;EAEH,MAAM0B,kBAAkB,GACvB,IAAAC,4BAAc,EAAE5B,WAAY,CAAC,IAAI,IAAA6B,QAAE,EAAE,WAAY,CAAC;EAEnD,OACC,IAAAC,MAAA,CAAAC,aAAA,EAAC3C,WAAA,CAAA4C,eAAe;IACfjB,GAAG,EAAGC,QAAU;IAChBG,KAAK,EAAGR,KAAO;IACfO,QAAQ,EAAGA,QAAU;IACrBe,OAAO,EAAGX,QAAU;IACpBY,MAAM,EAAGX,UAAY;IACrBY,KAAK,EAAGnC,WAAa;IACrBwB,SAAS,EAAGA,SAAW;IACvBxB,WAAW,EAAG2B,kBAAoB;IAClCS,mBAAmB,EAAG,IAAM;IAC5BC,YAAY,EAAC,KAAK;IAClBC,GAAG,EAAC,MAAM;IACVC,IAAI,EAAG,CAAG;IACVC,uBAAuB;EAAA,CACvB,CAAC;AAEJ;AAAC,IAAAC,QAAA,GAEc,IAAAC,mBAAU,EAAE7C,YAAa,CAAC;AAAA8C,OAAA,CAAAC,OAAA,GAAAH,QAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = usePostTitleFocus;
|
|
7
|
+
var _element = require("@wordpress/element");
|
|
8
|
+
var _data = require("@wordpress/data");
|
|
9
|
+
var _store = require("../../store");
|
|
10
|
+
/**
|
|
11
|
+
* WordPress dependencies
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
function usePostTitleFocus(forwardedRef) {
|
|
19
|
+
const ref = (0, _element.useRef)();
|
|
20
|
+
const {
|
|
21
|
+
isCleanNewPost
|
|
22
|
+
} = (0, _data.useSelect)(select => {
|
|
23
|
+
const {
|
|
24
|
+
isCleanNewPost: _isCleanNewPost
|
|
25
|
+
} = select(_store.store);
|
|
26
|
+
return {
|
|
27
|
+
isCleanNewPost: _isCleanNewPost()
|
|
28
|
+
};
|
|
29
|
+
}, []);
|
|
30
|
+
(0, _element.useImperativeHandle)(forwardedRef, () => ({
|
|
31
|
+
focus: () => {
|
|
32
|
+
ref?.current?.focus();
|
|
33
|
+
}
|
|
34
|
+
}));
|
|
35
|
+
(0, _element.useEffect)(() => {
|
|
36
|
+
if (!ref.current) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const {
|
|
40
|
+
defaultView
|
|
41
|
+
} = ref.current.ownerDocument;
|
|
42
|
+
const {
|
|
43
|
+
name,
|
|
44
|
+
parent
|
|
45
|
+
} = defaultView;
|
|
46
|
+
const ownerDocument = name === 'editor-canvas' ? parent.document : defaultView.document;
|
|
47
|
+
const {
|
|
48
|
+
activeElement,
|
|
49
|
+
body
|
|
50
|
+
} = ownerDocument;
|
|
51
|
+
|
|
52
|
+
// Only autofocus the title when the post is entirely empty. This should
|
|
53
|
+
// only happen for a new post, which means we focus the title on new
|
|
54
|
+
// post so the author can start typing right away, without needing to
|
|
55
|
+
// click anything.
|
|
56
|
+
if (isCleanNewPost && (!activeElement || body === activeElement)) {
|
|
57
|
+
ref.current.focus();
|
|
58
|
+
}
|
|
59
|
+
}, [isCleanNewPost]);
|
|
60
|
+
return {
|
|
61
|
+
ref
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=use-post-title-focus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_element","require","_data","_store","usePostTitleFocus","forwardedRef","ref","useRef","isCleanNewPost","useSelect","select","_isCleanNewPost","editorStore","useImperativeHandle","focus","current","useEffect","defaultView","ownerDocument","name","parent","document","activeElement","body"],"sources":["@wordpress/editor/src/components/post-title/use-post-title-focus.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useImperativeHandle, useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function usePostTitleFocus( forwardedRef ) {\n\tconst ref = useRef();\n\n\tconst { isCleanNewPost } = useSelect( ( select ) => {\n\t\tconst { isCleanNewPost: _isCleanNewPost } = select( editorStore );\n\n\t\treturn {\n\t\t\tisCleanNewPost: _isCleanNewPost(),\n\t\t};\n\t}, [] );\n\n\tuseImperativeHandle( forwardedRef, () => ( {\n\t\tfocus: () => {\n\t\t\tref?.current?.focus();\n\t\t},\n\t} ) );\n\n\tuseEffect( () => {\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { defaultView } = ref.current.ownerDocument;\n\t\tconst { name, parent } = defaultView;\n\t\tconst ownerDocument =\n\t\t\tname === 'editor-canvas' ? parent.document : defaultView.document;\n\t\tconst { activeElement, body } = ownerDocument;\n\n\t\t// Only autofocus the title when the post is entirely empty. This should\n\t\t// only happen for a new post, which means we focus the title on new\n\t\t// post so the author can start typing right away, without needing to\n\t\t// click anything.\n\t\tif ( isCleanNewPost && ( ! activeElement || body === activeElement ) ) {\n\t\t\tref.current.focus();\n\t\t}\n\t}, [ isCleanNewPost ] );\n\n\treturn { ref };\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGe,SAASG,iBAAiBA,CAAEC,YAAY,EAAG;EACzD,MAAMC,GAAG,GAAG,IAAAC,eAAM,EAAC,CAAC;EAEpB,MAAM;IAAEC;EAAe,CAAC,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IACnD,MAAM;MAAEF,cAAc,EAAEG;IAAgB,CAAC,GAAGD,MAAM,CAAEE,YAAY,CAAC;IAEjE,OAAO;MACNJ,cAAc,EAAEG,eAAe,CAAC;IACjC,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,IAAAE,4BAAmB,EAAER,YAAY,EAAE,OAAQ;IAC1CS,KAAK,EAAEA,CAAA,KAAM;MACZR,GAAG,EAAES,OAAO,EAAED,KAAK,CAAC,CAAC;IACtB;EACD,CAAC,CAAG,CAAC;EAEL,IAAAE,kBAAS,EAAE,MAAM;IAChB,IAAK,CAAEV,GAAG,CAACS,OAAO,EAAG;MACpB;IACD;IAEA,MAAM;MAAEE;IAAY,CAAC,GAAGX,GAAG,CAACS,OAAO,CAACG,aAAa;IACjD,MAAM;MAAEC,IAAI;MAAEC;IAAO,CAAC,GAAGH,WAAW;IACpC,MAAMC,aAAa,GAClBC,IAAI,KAAK,eAAe,GAAGC,MAAM,CAACC,QAAQ,GAAGJ,WAAW,CAACI,QAAQ;IAClE,MAAM;MAAEC,aAAa;MAAEC;IAAK,CAAC,GAAGL,aAAa;;IAE7C;IACA;IACA;IACA;IACA,IAAKV,cAAc,KAAM,CAAEc,aAAa,IAAIC,IAAI,KAAKD,aAAa,CAAE,EAAG;MACtEhB,GAAG,CAACS,OAAO,CAACD,KAAK,CAAC,CAAC;IACpB;EACD,CAAC,EAAE,CAAEN,cAAc,CAAG,CAAC;EAEvB,OAAO;IAAEF;EAAI,CAAC;AACf"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = usePostTitle;
|
|
7
|
+
var _data = require("@wordpress/data");
|
|
8
|
+
var _store = require("../../store");
|
|
9
|
+
/**
|
|
10
|
+
* WordPress dependencies
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
function usePostTitle() {
|
|
18
|
+
const {
|
|
19
|
+
editPost
|
|
20
|
+
} = (0, _data.useDispatch)(_store.store);
|
|
21
|
+
const {
|
|
22
|
+
title
|
|
23
|
+
} = (0, _data.useSelect)(select => {
|
|
24
|
+
const {
|
|
25
|
+
getEditedPostAttribute
|
|
26
|
+
} = select(_store.store);
|
|
27
|
+
return {
|
|
28
|
+
title: getEditedPostAttribute('title')
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
|
+
function updateTitle(newTitle) {
|
|
32
|
+
editPost({
|
|
33
|
+
title: newTitle
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
title,
|
|
38
|
+
setTitle: updateTitle
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=use-post-title.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_data","require","_store","usePostTitle","editPost","useDispatch","editorStore","title","useSelect","select","getEditedPostAttribute","updateTitle","newTitle","setTitle"],"sources":["@wordpress/editor/src/components/post-title/use-post-title.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function usePostTitle() {\n\tconst { editPost } = useDispatch( editorStore );\n\tconst { title } = useSelect( ( select ) => {\n\t\tconst { getEditedPostAttribute } = select( editorStore );\n\n\t\treturn {\n\t\t\ttitle: getEditedPostAttribute( 'title' ),\n\t\t};\n\t}, [] );\n\n\tfunction updateTitle( newTitle ) {\n\t\teditPost( { title: newTitle } );\n\t}\n\n\treturn { title, setTitle: updateTitle };\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAD,OAAA;AAPA;AACA;AACA;;AAEA;AACA;AACA;;AAGe,SAASE,YAAYA,CAAA,EAAG;EACtC,MAAM;IAAEC;EAAS,CAAC,GAAG,IAAAC,iBAAW,EAAEC,YAAY,CAAC;EAC/C,MAAM;IAAEC;EAAM,CAAC,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IAC1C,MAAM;MAAEC;IAAuB,CAAC,GAAGD,MAAM,CAAEH,YAAY,CAAC;IAExD,OAAO;MACNC,KAAK,EAAEG,sBAAsB,CAAE,OAAQ;IACxC,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,SAASC,WAAWA,CAAEC,QAAQ,EAAG;IAChCR,QAAQ,CAAE;MAAEG,KAAK,EAAEK;IAAS,CAAE,CAAC;EAChC;EAEA,OAAO;IAAEL,KAAK;IAAEM,QAAQ,EAAEF;EAAY,CAAC;AACxC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = PostURLPanel;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _element = require("@wordpress/element");
|
|
10
|
+
var _components = require("@wordpress/components");
|
|
11
|
+
var _i18n = require("@wordpress/i18n");
|
|
12
|
+
var _check = _interopRequireDefault(require("./check"));
|
|
13
|
+
var _index = _interopRequireDefault(require("./index"));
|
|
14
|
+
var _label = require("./label");
|
|
15
|
+
var _postPanelRow = _interopRequireDefault(require("../post-panel-row"));
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function PostURLPanel() {
|
|
25
|
+
// Use internal state instead of a ref to make sure that the component
|
|
26
|
+
// re-renders when the popover's anchor updates.
|
|
27
|
+
const [popoverAnchor, setPopoverAnchor] = (0, _element.useState)(null);
|
|
28
|
+
// Memoize popoverProps to avoid returning a new object every time.
|
|
29
|
+
const popoverProps = (0, _element.useMemo)(() => ({
|
|
30
|
+
anchor: popoverAnchor,
|
|
31
|
+
placement: 'bottom-end'
|
|
32
|
+
}), [popoverAnchor]);
|
|
33
|
+
return (0, _react.createElement)(_check.default, null, (0, _react.createElement)(_postPanelRow.default, {
|
|
34
|
+
label: (0, _i18n.__)('URL'),
|
|
35
|
+
ref: setPopoverAnchor
|
|
36
|
+
}, (0, _react.createElement)(_components.Dropdown, {
|
|
37
|
+
popoverProps: popoverProps,
|
|
38
|
+
className: "editor-post-url__panel-dropdown",
|
|
39
|
+
contentClassName: "editor-post-url__panel-dialog",
|
|
40
|
+
focusOnMount: true,
|
|
41
|
+
renderToggle: ({
|
|
42
|
+
isOpen,
|
|
43
|
+
onToggle
|
|
44
|
+
}) => (0, _react.createElement)(PostURLToggle, {
|
|
45
|
+
isOpen: isOpen,
|
|
46
|
+
onClick: onToggle
|
|
47
|
+
}),
|
|
48
|
+
renderContent: ({
|
|
49
|
+
onClose
|
|
50
|
+
}) => (0, _react.createElement)(_index.default, {
|
|
51
|
+
onClose: onClose
|
|
52
|
+
})
|
|
53
|
+
})));
|
|
54
|
+
}
|
|
55
|
+
function PostURLToggle({
|
|
56
|
+
isOpen,
|
|
57
|
+
onClick
|
|
58
|
+
}) {
|
|
59
|
+
const label = (0, _label.usePostURLLabel)();
|
|
60
|
+
return (0, _react.createElement)(_components.Button, {
|
|
61
|
+
className: "editor-post-url__panel-toggle",
|
|
62
|
+
variant: "tertiary",
|
|
63
|
+
"aria-expanded": isOpen
|
|
64
|
+
// translators: %s: Current post URL.
|
|
65
|
+
,
|
|
66
|
+
"aria-label": (0, _i18n.sprintf)((0, _i18n.__)('Change URL: %s'), label),
|
|
67
|
+
onClick: onClick
|
|
68
|
+
}, label);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=panel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_element","require","_components","_i18n","_check","_interopRequireDefault","_index","_label","_postPanelRow","PostURLPanel","popoverAnchor","setPopoverAnchor","useState","popoverProps","useMemo","anchor","placement","_react","createElement","default","label","__","ref","Dropdown","className","contentClassName","focusOnMount","renderToggle","isOpen","onToggle","PostURLToggle","onClick","renderContent","onClose","usePostURLLabel","Button","variant","sprintf"],"sources":["@wordpress/editor/src/components/post-url/panel.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useState } from '@wordpress/element';\nimport { Dropdown, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport PostURLCheck from './check';\nimport PostURL from './index';\nimport { usePostURLLabel } from './label';\nimport PostPanelRow from '../post-panel-row';\n\nexport default function PostURLPanel() {\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( { anchor: popoverAnchor, placement: 'bottom-end' } ),\n\t\t[ popoverAnchor ]\n\t);\n\n\treturn (\n\t\t<PostURLCheck>\n\t\t\t<PostPanelRow label={ __( 'URL' ) } ref={ setPopoverAnchor }>\n\t\t\t\t<Dropdown\n\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t\tclassName=\"editor-post-url__panel-dropdown\"\n\t\t\t\t\tcontentClassName=\"editor-post-url__panel-dialog\"\n\t\t\t\t\tfocusOnMount\n\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t<PostURLToggle isOpen={ isOpen } onClick={ onToggle } />\n\t\t\t\t\t) }\n\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t<PostURL onClose={ onClose } />\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</PostPanelRow>\n\t\t</PostURLCheck>\n\t);\n}\n\nfunction PostURLToggle( { isOpen, onClick } ) {\n\tconst label = usePostURLLabel();\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"editor-post-url__panel-toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\t// translators: %s: Current post URL.\n\t\t\taria-label={ sprintf( __( 'Change URL: %s' ), label ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAKA,IAAAG,MAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAD,sBAAA,CAAAJ,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,aAAA,GAAAH,sBAAA,CAAAJ,OAAA;AAbA;AACA;AACA;;AAKA;AACA;AACA;;AAMe,SAASQ,YAAYA,CAAA,EAAG;EACtC;EACA;EACA,MAAM,CAAEC,aAAa,EAAEC,gBAAgB,CAAE,GAAG,IAAAC,iBAAQ,EAAE,IAAK,CAAC;EAC5D;EACA,MAAMC,YAAY,GAAG,IAAAC,gBAAO,EAC3B,OAAQ;IAAEC,MAAM,EAAEL,aAAa;IAAEM,SAAS,EAAE;EAAa,CAAC,CAAE,EAC5D,CAAEN,aAAa,CAChB,CAAC;EAED,OACC,IAAAO,MAAA,CAAAC,aAAA,EAACd,MAAA,CAAAe,OAAY,QACZ,IAAAF,MAAA,CAAAC,aAAA,EAACV,aAAA,CAAAW,OAAY;IAACC,KAAK,EAAG,IAAAC,QAAE,EAAE,KAAM,CAAG;IAACC,GAAG,EAAGX;EAAkB,GAC3D,IAAAM,MAAA,CAAAC,aAAA,EAAChB,WAAA,CAAAqB,QAAQ;IACRV,YAAY,EAAGA,YAAc;IAC7BW,SAAS,EAAC,iCAAiC;IAC3CC,gBAAgB,EAAC,+BAA+B;IAChDC,YAAY;IACZC,YAAY,EAAGA,CAAE;MAAEC,MAAM;MAAEC;IAAS,CAAC,KACpC,IAAAZ,MAAA,CAAAC,aAAA,EAACY,aAAa;MAACF,MAAM,EAAGA,MAAQ;MAACG,OAAO,EAAGF;IAAU,CAAE,CACrD;IACHG,aAAa,EAAGA,CAAE;MAAEC;IAAQ,CAAC,KAC5B,IAAAhB,MAAA,CAAAC,aAAA,EAACZ,MAAA,CAAAa,OAAO;MAACc,OAAO,EAAGA;IAAS,CAAE;EAC5B,CACH,CACY,CACD,CAAC;AAEjB;AAEA,SAASH,aAAaA,CAAE;EAAEF,MAAM;EAAEG;AAAQ,CAAC,EAAG;EAC7C,MAAMX,KAAK,GAAG,IAAAc,sBAAe,EAAC,CAAC;EAC/B,OACC,IAAAjB,MAAA,CAAAC,aAAA,EAAChB,WAAA,CAAAiC,MAAM;IACNX,SAAS,EAAC,+BAA+B;IACzCY,OAAO,EAAC,UAAU;IAClB,iBAAgBR;IAChB;IAAA;IACA,cAAa,IAAAS,aAAO,EAAE,IAAAhB,QAAE,EAAE,gBAAiB,CAAC,EAAED,KAAM,CAAG;IACvDW,OAAO,EAAGA;EAAS,GAEjBX,KACK,CAAC;AAEX"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PAGE_CONTENT_BLOCK_TYPES = void 0;
|
|
7
|
+
const PAGE_CONTENT_BLOCK_TYPES = ['core/post-title', 'core/post-featured-image', 'core/post-content'];
|
|
8
|
+
exports.PAGE_CONTENT_BLOCK_TYPES = PAGE_CONTENT_BLOCK_TYPES;
|
|
9
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["PAGE_CONTENT_BLOCK_TYPES","exports"],"sources":["@wordpress/editor/src/components/provider/constants.js"],"sourcesContent":["export const PAGE_CONTENT_BLOCK_TYPES = [\n\t'core/post-title',\n\t'core/post-featured-image',\n\t'core/post-content',\n];\n"],"mappings":";;;;;;AAAO,MAAMA,wBAAwB,GAAG,CACvC,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,CACnB;AAACC,OAAA,CAAAD,wBAAA,GAAAA,wBAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = DisableNonPageContentBlocks;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _data = require("@wordpress/data");
|
|
9
|
+
var _blockEditor = require("@wordpress/block-editor");
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
11
|
+
var _constants = require("./constants");
|
|
12
|
+
/**
|
|
13
|
+
* WordPress dependencies
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function DisableBlock({
|
|
21
|
+
clientId
|
|
22
|
+
}) {
|
|
23
|
+
const isDescendentOfQueryLoop = (0, _data.useSelect)(select => {
|
|
24
|
+
const {
|
|
25
|
+
getBlockParentsByBlockName
|
|
26
|
+
} = select(_blockEditor.store);
|
|
27
|
+
return getBlockParentsByBlockName(clientId, 'core/query').length !== 0;
|
|
28
|
+
}, [clientId]);
|
|
29
|
+
const mode = isDescendentOfQueryLoop ? undefined : 'contentOnly';
|
|
30
|
+
const {
|
|
31
|
+
setBlockEditingMode,
|
|
32
|
+
unsetBlockEditingMode
|
|
33
|
+
} = (0, _data.useDispatch)(_blockEditor.store);
|
|
34
|
+
(0, _element.useEffect)(() => {
|
|
35
|
+
if (mode) {
|
|
36
|
+
setBlockEditingMode(clientId, mode);
|
|
37
|
+
return () => {
|
|
38
|
+
unsetBlockEditingMode(clientId);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}, [clientId, mode, setBlockEditingMode, unsetBlockEditingMode]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Component that when rendered, makes it so that the site editor allows only
|
|
46
|
+
* page content to be edited.
|
|
47
|
+
*/
|
|
48
|
+
function DisableNonPageContentBlocks() {
|
|
49
|
+
(0, _blockEditor.useBlockEditingMode)('disabled');
|
|
50
|
+
const clientIds = (0, _data.useSelect)(select => {
|
|
51
|
+
const {
|
|
52
|
+
__experimentalGetGlobalBlocksByName
|
|
53
|
+
} = select(_blockEditor.store);
|
|
54
|
+
return __experimentalGetGlobalBlocksByName(_constants.PAGE_CONTENT_BLOCK_TYPES);
|
|
55
|
+
}, []);
|
|
56
|
+
return clientIds.map(clientId => {
|
|
57
|
+
return (0, _react.createElement)(DisableBlock, {
|
|
58
|
+
key: clientId,
|
|
59
|
+
clientId: clientId
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=disable-non-page-content-blocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_data","require","_blockEditor","_element","_constants","DisableBlock","clientId","isDescendentOfQueryLoop","useSelect","select","getBlockParentsByBlockName","blockEditorStore","length","mode","undefined","setBlockEditingMode","unsetBlockEditingMode","useDispatch","useEffect","DisableNonPageContentBlocks","useBlockEditingMode","clientIds","__experimentalGetGlobalBlocksByName","PAGE_CONTENT_BLOCK_TYPES","map","_react","createElement","key"],"sources":["@wordpress/editor/src/components/provider/disable-non-page-content-blocks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseBlockEditingMode,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { PAGE_CONTENT_BLOCK_TYPES } from './constants';\n\nfunction DisableBlock( { clientId } ) {\n\tconst isDescendentOfQueryLoop = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockParentsByBlockName } = select( blockEditorStore );\n\t\t\treturn (\n\t\t\t\tgetBlockParentsByBlockName( clientId, 'core/query' ).length !==\n\t\t\t\t0\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\tconst mode = isDescendentOfQueryLoop ? undefined : 'contentOnly';\n\tconst { setBlockEditingMode, unsetBlockEditingMode } =\n\t\tuseDispatch( blockEditorStore );\n\tuseEffect( () => {\n\t\tif ( mode ) {\n\t\t\tsetBlockEditingMode( clientId, mode );\n\t\t\treturn () => {\n\t\t\t\tunsetBlockEditingMode( clientId );\n\t\t\t};\n\t\t}\n\t}, [ clientId, mode, setBlockEditingMode, unsetBlockEditingMode ] );\n}\n\n/**\n * Component that when rendered, makes it so that the site editor allows only\n * page content to be edited.\n */\nexport default function DisableNonPageContentBlocks() {\n\tuseBlockEditingMode( 'disabled' );\n\tconst clientIds = useSelect( ( select ) => {\n\t\tconst { __experimentalGetGlobalBlocksByName } =\n\t\t\tselect( blockEditorStore );\n\t\treturn __experimentalGetGlobalBlocksByName( PAGE_CONTENT_BLOCK_TYPES );\n\t}, [] );\n\n\treturn clientIds.map( ( clientId ) => {\n\t\treturn <DisableBlock key={ clientId } clientId={ clientId } />;\n\t} );\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAIA,IAAAE,QAAA,GAAAF,OAAA;AAKA,IAAAG,UAAA,GAAAH,OAAA;AAbA;AACA;AACA;;AAQA;AACA;AACA;;AAGA,SAASI,YAAYA,CAAE;EAAEC;AAAS,CAAC,EAAG;EACrC,MAAMC,uBAAuB,GAAG,IAAAC,eAAS,EACtCC,MAAM,IAAM;IACb,MAAM;MAAEC;IAA2B,CAAC,GAAGD,MAAM,CAAEE,kBAAiB,CAAC;IACjE,OACCD,0BAA0B,CAAEJ,QAAQ,EAAE,YAAa,CAAC,CAACM,MAAM,KAC3D,CAAC;EAEH,CAAC,EACD,CAAEN,QAAQ,CACX,CAAC;EACD,MAAMO,IAAI,GAAGN,uBAAuB,GAAGO,SAAS,GAAG,aAAa;EAChE,MAAM;IAAEC,mBAAmB;IAAEC;EAAsB,CAAC,GACnD,IAAAC,iBAAW,EAAEN,kBAAiB,CAAC;EAChC,IAAAO,kBAAS,EAAE,MAAM;IAChB,IAAKL,IAAI,EAAG;MACXE,mBAAmB,CAAET,QAAQ,EAAEO,IAAK,CAAC;MACrC,OAAO,MAAM;QACZG,qBAAqB,CAAEV,QAAS,CAAC;MAClC,CAAC;IACF;EACD,CAAC,EAAE,CAAEA,QAAQ,EAAEO,IAAI,EAAEE,mBAAmB,EAAEC,qBAAqB,CAAG,CAAC;AACpE;;AAEA;AACA;AACA;AACA;AACe,SAASG,2BAA2BA,CAAA,EAAG;EACrD,IAAAC,gCAAmB,EAAE,UAAW,CAAC;EACjC,MAAMC,SAAS,GAAG,IAAAb,eAAS,EAAIC,MAAM,IAAM;IAC1C,MAAM;MAAEa;IAAoC,CAAC,GAC5Cb,MAAM,CAAEE,kBAAiB,CAAC;IAC3B,OAAOW,mCAAmC,CAAEC,mCAAyB,CAAC;EACvE,CAAC,EAAE,EAAG,CAAC;EAEP,OAAOF,SAAS,CAACG,GAAG,CAAIlB,QAAQ,IAAM;IACrC,OAAO,IAAAmB,MAAA,CAAAC,aAAA,EAACrB,YAAY;MAACsB,GAAG,EAAGrB,QAAU;MAACA,QAAQ,EAAGA;IAAU,CAAE,CAAC;EAC/D,CAAE,CAAC;AACJ"}
|
|
@@ -14,10 +14,13 @@ var _coreData = require("@wordpress/core-data");
|
|
|
14
14
|
var _blockEditor = require("@wordpress/block-editor");
|
|
15
15
|
var _notices = require("@wordpress/notices");
|
|
16
16
|
var _patterns = require("@wordpress/patterns");
|
|
17
|
+
var _blocks = require("@wordpress/blocks");
|
|
17
18
|
var _withRegistryProvider = _interopRequireDefault(require("./with-registry-provider"));
|
|
18
19
|
var _store = require("../../store");
|
|
19
20
|
var _useBlockEditorSettings = _interopRequireDefault(require("./use-block-editor-settings"));
|
|
20
21
|
var _lockUnlock = require("../../lock-unlock");
|
|
22
|
+
var _disableNonPageContentBlocks = _interopRequireDefault(require("./disable-non-page-content-blocks"));
|
|
23
|
+
var _constants = require("./constants");
|
|
21
24
|
/**
|
|
22
25
|
* WordPress dependencies
|
|
23
26
|
*/
|
|
@@ -32,24 +35,135 @@ const {
|
|
|
32
35
|
const {
|
|
33
36
|
PatternsMenuItems
|
|
34
37
|
} = (0, _lockUnlock.unlock)(_patterns.privateApis);
|
|
38
|
+
const noop = () => {};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* For the Navigation block editor, we need to force the block editor to contentOnly for that block.
|
|
42
|
+
*
|
|
43
|
+
* Set block editing mode to contentOnly when entering Navigation focus mode.
|
|
44
|
+
* this ensures that non-content controls on the block will be hidden and thus
|
|
45
|
+
* the user can focus on editing the Navigation Menu content only.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} navigationBlockClientId ClientId.
|
|
48
|
+
*/
|
|
49
|
+
function useForceFocusModeForNavigation(navigationBlockClientId) {
|
|
50
|
+
const {
|
|
51
|
+
setBlockEditingMode,
|
|
52
|
+
unsetBlockEditingMode
|
|
53
|
+
} = (0, _data.useDispatch)(_blockEditor.store);
|
|
54
|
+
(0, _element.useEffect)(() => {
|
|
55
|
+
if (!navigationBlockClientId) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
setBlockEditingMode(navigationBlockClientId, 'contentOnly');
|
|
59
|
+
return () => {
|
|
60
|
+
unsetBlockEditingMode(navigationBlockClientId);
|
|
61
|
+
};
|
|
62
|
+
}, [navigationBlockClientId, unsetBlockEditingMode, setBlockEditingMode]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Helper method to extract the post content block types from a template.
|
|
67
|
+
*
|
|
68
|
+
* @param {Array} blocks Template blocks.
|
|
69
|
+
*
|
|
70
|
+
* @return {Array} Flattened object.
|
|
71
|
+
*/
|
|
72
|
+
function extractPageContentBlockTypesFromTemplateBlocks(blocks) {
|
|
73
|
+
const result = [];
|
|
74
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
75
|
+
// Since the Query Block could contain PAGE_CONTENT_BLOCK_TYPES block types,
|
|
76
|
+
// we skip it because we only want to render stand-alone page content blocks in the block list.
|
|
77
|
+
if (blocks[i].name === 'core/query') {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (_constants.PAGE_CONTENT_BLOCK_TYPES.includes(blocks[i].name)) {
|
|
81
|
+
result.push((0, _blocks.createBlock)(blocks[i].name));
|
|
82
|
+
}
|
|
83
|
+
if (blocks[i].innerBlocks.length) {
|
|
84
|
+
result.push(...extractPageContentBlockTypesFromTemplateBlocks(blocks[i].innerBlocks));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Depending on the post, template and template mode,
|
|
92
|
+
* returns the appropriate blocks and change handlers for the block editor provider.
|
|
93
|
+
*
|
|
94
|
+
* @param {Array} post Block list.
|
|
95
|
+
* @param {boolean} template Whether the page content has focus (and the surrounding template is inert). If `true` return page content blocks. Default `false`.
|
|
96
|
+
* @param {string} mode Rendering mode.
|
|
97
|
+
* @return {Array} Block editor props.
|
|
98
|
+
*/
|
|
99
|
+
function useBlockEditorProps(post, template, mode) {
|
|
100
|
+
const rootLevelPost = mode === 'post-only' || !template ? 'post' : 'template';
|
|
101
|
+
const [postBlocks, onInput, onChange] = (0, _coreData.useEntityBlockEditor)('postType', post.type, {
|
|
102
|
+
id: post.id
|
|
103
|
+
});
|
|
104
|
+
const [templateBlocks, onInputTemplate, onChangeTemplate] = (0, _coreData.useEntityBlockEditor)('postType', template?.type, {
|
|
105
|
+
id: template?.id
|
|
106
|
+
});
|
|
107
|
+
const blocks = (0, _element.useMemo)(() => {
|
|
108
|
+
if (post.type === 'wp_navigation') {
|
|
109
|
+
return [(0, _blocks.createBlock)('core/navigation', {
|
|
110
|
+
ref: post.id,
|
|
111
|
+
// As the parent editor is locked with `templateLock`, the template locking
|
|
112
|
+
// must be explicitly "unset" on the block itself to allow the user to modify
|
|
113
|
+
// the block's content.
|
|
114
|
+
templateLock: false
|
|
115
|
+
})];
|
|
116
|
+
}
|
|
117
|
+
if (mode === 'post-only') {
|
|
118
|
+
const postContentBlocks = extractPageContentBlockTypesFromTemplateBlocks(templateBlocks);
|
|
119
|
+
return [(0, _blocks.createBlock)('core/group', {
|
|
120
|
+
layout: {
|
|
121
|
+
type: 'constrained'
|
|
122
|
+
},
|
|
123
|
+
style: {
|
|
124
|
+
spacing: {
|
|
125
|
+
margin: {
|
|
126
|
+
top: '4em' // Mimics the post editor.
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}, postContentBlocks.length ? postContentBlocks : [(0, _blocks.createBlock)('core/post-title'), (0, _blocks.createBlock)('core/post-content')])];
|
|
131
|
+
}
|
|
132
|
+
if (rootLevelPost === 'template') {
|
|
133
|
+
return templateBlocks;
|
|
134
|
+
}
|
|
135
|
+
return postBlocks;
|
|
136
|
+
}, [templateBlocks, postBlocks, rootLevelPost, post.type, post.id, mode]);
|
|
137
|
+
const disableRootLevelChanges = !!template && mode === 'template-locked' || post.type === 'wp_navigation' || mode === 'post-only';
|
|
138
|
+
const navigationBlockClientId = post.type === 'wp_navigation' && blocks && blocks[0]?.clientId;
|
|
139
|
+
useForceFocusModeForNavigation(navigationBlockClientId);
|
|
140
|
+
if (disableRootLevelChanges) {
|
|
141
|
+
return [blocks, noop, noop];
|
|
142
|
+
}
|
|
143
|
+
return [blocks, rootLevelPost === 'post' ? onInput : onInputTemplate, rootLevelPost === 'post' ? onChange : onChangeTemplate];
|
|
144
|
+
}
|
|
35
145
|
const ExperimentalEditorProvider = (0, _withRegistryProvider.default)(({
|
|
36
|
-
__unstableTemplate,
|
|
37
146
|
post,
|
|
38
147
|
settings,
|
|
39
148
|
recovery,
|
|
40
149
|
initialEdits,
|
|
41
150
|
children,
|
|
42
|
-
BlockEditorProviderComponent = ExperimentalBlockEditorProvider
|
|
151
|
+
BlockEditorProviderComponent = ExperimentalBlockEditorProvider,
|
|
152
|
+
__unstableTemplate: template
|
|
43
153
|
}) => {
|
|
154
|
+
const mode = (0, _data.useSelect)(select => select(_store.store).getRenderingMode(), []);
|
|
155
|
+
const shouldRenderTemplate = !!template && mode !== 'post-only';
|
|
156
|
+
const rootLevelPost = shouldRenderTemplate ? template : post;
|
|
44
157
|
const defaultBlockContext = (0, _element.useMemo)(() => {
|
|
45
|
-
|
|
46
|
-
return {};
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
158
|
+
const postContext = rootLevelPost.type !== 'wp_template' || shouldRenderTemplate && mode !== 'template-only' ? {
|
|
49
159
|
postId: post.id,
|
|
50
160
|
postType: post.type
|
|
161
|
+
} : {};
|
|
162
|
+
return {
|
|
163
|
+
...postContext,
|
|
164
|
+
templateSlug: rootLevelPost.type === 'wp_template' ? rootLevelPost.slug : undefined
|
|
51
165
|
};
|
|
52
|
-
}, [post.id, post.type]);
|
|
166
|
+
}, [mode, post.id, post.type, rootLevelPost.type, rootLevelPost?.slug, shouldRenderTemplate]);
|
|
53
167
|
const {
|
|
54
168
|
editorSettings,
|
|
55
169
|
selection,
|
|
@@ -69,11 +183,9 @@ const ExperimentalEditorProvider = (0, _withRegistryProvider.default)(({
|
|
|
69
183
|
const {
|
|
70
184
|
id,
|
|
71
185
|
type
|
|
72
|
-
} =
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
const blockEditorSettings = (0, _useBlockEditorSettings.default)(editorSettings, !!__unstableTemplate);
|
|
186
|
+
} = rootLevelPost;
|
|
187
|
+
const blockEditorSettings = (0, _useBlockEditorSettings.default)(editorSettings, type, id);
|
|
188
|
+
const [blocks, onInput, onChange] = useBlockEditorProps(post, template, mode);
|
|
77
189
|
const {
|
|
78
190
|
updatePostLock,
|
|
79
191
|
setupEditor,
|
|
@@ -110,7 +222,7 @@ const ExperimentalEditorProvider = (0, _withRegistryProvider.default)(({
|
|
|
110
222
|
// Synchronize the editor settings as they change.
|
|
111
223
|
(0, _element.useEffect)(() => {
|
|
112
224
|
updateEditorSettings(settings);
|
|
113
|
-
}, [settings]);
|
|
225
|
+
}, [settings, updateEditorSettings]);
|
|
114
226
|
if (!isReady) {
|
|
115
227
|
return null;
|
|
116
228
|
}
|
|
@@ -130,7 +242,7 @@ const ExperimentalEditorProvider = (0, _withRegistryProvider.default)(({
|
|
|
130
242
|
selection: selection,
|
|
131
243
|
settings: blockEditorSettings,
|
|
132
244
|
useSubRegistry: false
|
|
133
|
-
}, children, (0, _react.createElement)(PatternsMenuItems, null)))));
|
|
245
|
+
}, children, (0, _react.createElement)(PatternsMenuItems, null), ['post-only', 'template-locked'].includes(mode) && (0, _react.createElement)(_disableNonPageContentBlocks.default, null)))));
|
|
134
246
|
});
|
|
135
247
|
exports.ExperimentalEditorProvider = ExperimentalEditorProvider;
|
|
136
248
|
function EditorProvider(props) {
|