@wordpress/block-library 7.0.1 → 7.0.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/README.md +16 -0
- package/build/button/edit.native.js +2 -2
- package/build/button/edit.native.js.map +1 -1
- package/build/columns/index.js +12 -0
- package/build/columns/index.js.map +1 -1
- package/build/comment-author-avatar/edit.js +17 -4
- package/build/comment-author-avatar/edit.js.map +1 -1
- package/build/comment-template/edit.js +94 -36
- package/build/comment-template/edit.js.map +1 -1
- package/build/comment-template/hooks.js +175 -0
- package/build/comment-template/hooks.js.map +1 -0
- package/build/comment-template/index.js +1 -1
- package/build/comment-template/util.js.map +1 -1
- package/build/comments-pagination-next/index.js +1 -1
- package/build/comments-pagination-numbers/index.js +1 -1
- package/build/comments-query-loop/edit/comments-inspector-controls.js +20 -9
- package/build/comments-query-loop/edit/comments-inspector-controls.js.map +1 -1
- package/build/comments-query-loop/edit.js +1 -19
- package/build/comments-query-loop/edit.js.map +1 -1
- package/build/comments-query-loop/index.js +5 -0
- package/build/comments-query-loop/index.js.map +1 -1
- package/build/cover/edit.js +21 -22
- package/build/cover/edit.js.map +1 -1
- package/build/cover/edit.native.js +7 -5
- package/build/cover/edit.native.js.map +1 -1
- package/build/cover/overlay-color-settings.native.js +4 -3
- package/build/cover/overlay-color-settings.native.js.map +1 -1
- package/build/cover/transforms.js +4 -2
- package/build/cover/transforms.js.map +1 -1
- package/build/group/index.js +1 -0
- package/build/group/index.js.map +1 -1
- package/build/heading/edit.js +14 -2
- package/build/heading/edit.js.map +1 -1
- package/build/image/deprecated.js +89 -5
- package/build/image/deprecated.js.map +1 -1
- package/build/image/save.js +0 -7
- package/build/image/save.js.map +1 -1
- package/build/latest-posts/edit.js +1 -0
- package/build/latest-posts/edit.js.map +1 -1
- package/build/navigation/edit/index.js +17 -15
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/navigation-menu-selector.js +44 -27
- package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build/navigation/edit/placeholder/index.js +8 -22
- package/build/navigation/edit/placeholder/index.js.map +1 -1
- package/build/navigation/use-navigation-menu.js +6 -6
- package/build/navigation/use-navigation-menu.js.map +1 -1
- package/build/navigation-submenu/edit.js +41 -9
- package/build/navigation-submenu/edit.js.map +1 -1
- package/build/page-list/edit.js +11 -17
- package/build/page-list/edit.js.map +1 -1
- package/build/social-links/deprecated.js +1 -62
- package/build/social-links/deprecated.js.map +1 -1
- package/build/template-part/edit/index.js +36 -64
- package/build/template-part/edit/index.js.map +1 -1
- package/build/template-part/edit/placeholder.js +64 -0
- package/build/template-part/edit/placeholder.js.map +1 -0
- package/build/template-part/edit/selection-modal.js +103 -0
- package/build/template-part/edit/selection-modal.js.map +1 -0
- package/build/template-part/edit/title-modal.js +54 -0
- package/build/template-part/edit/title-modal.js.map +1 -0
- package/build/template-part/edit/utils/hooks.js +156 -0
- package/build/template-part/edit/utils/hooks.js.map +1 -0
- package/build/template-part/index.js +3 -1
- package/build/template-part/index.js.map +1 -1
- package/build-module/button/edit.native.js +4 -4
- package/build-module/button/edit.native.js.map +1 -1
- package/build-module/columns/index.js +12 -0
- package/build-module/columns/index.js.map +1 -1
- package/build-module/comment-author-avatar/edit.js +18 -6
- package/build-module/comment-author-avatar/edit.js.map +1 -1
- package/build-module/comment-template/edit.js +95 -37
- package/build-module/comment-template/edit.js.map +1 -1
- package/build-module/comment-template/hooks.js +156 -0
- package/build-module/comment-template/hooks.js.map +1 -0
- package/build-module/comment-template/index.js +1 -1
- package/build-module/comment-template/util.js.map +1 -1
- package/build-module/comments-pagination-next/index.js +1 -1
- package/build-module/comments-pagination-numbers/index.js +1 -1
- package/build-module/comments-query-loop/edit/comments-inspector-controls.js +20 -9
- package/build-module/comments-query-loop/edit/comments-inspector-controls.js.map +1 -1
- package/build-module/comments-query-loop/edit.js +2 -19
- package/build-module/comments-query-loop/edit.js.map +1 -1
- package/build-module/comments-query-loop/index.js +5 -0
- package/build-module/comments-query-loop/index.js.map +1 -1
- package/build-module/cover/edit.js +23 -24
- package/build-module/cover/edit.js.map +1 -1
- package/build-module/cover/edit.native.js +10 -8
- package/build-module/cover/edit.native.js.map +1 -1
- package/build-module/cover/overlay-color-settings.native.js +4 -4
- package/build-module/cover/overlay-color-settings.native.js.map +1 -1
- package/build-module/cover/transforms.js +4 -2
- package/build-module/cover/transforms.js.map +1 -1
- package/build-module/group/index.js +1 -0
- package/build-module/group/index.js.map +1 -1
- package/build-module/heading/edit.js +15 -3
- package/build-module/heading/edit.js.map +1 -1
- package/build-module/image/deprecated.js +90 -7
- package/build-module/image/deprecated.js.map +1 -1
- package/build-module/image/save.js +0 -7
- package/build-module/image/save.js.map +1 -1
- package/build-module/latest-posts/edit.js +1 -0
- package/build-module/latest-posts/edit.js.map +1 -1
- package/build-module/navigation/edit/index.js +17 -15
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/navigation-menu-selector.js +45 -27
- package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build-module/navigation/edit/placeholder/index.js +8 -21
- package/build-module/navigation/edit/placeholder/index.js.map +1 -1
- package/build-module/navigation/use-navigation-menu.js +6 -6
- package/build-module/navigation/use-navigation-menu.js.map +1 -1
- package/build-module/navigation-submenu/edit.js +41 -10
- package/build-module/navigation-submenu/edit.js.map +1 -1
- package/build-module/page-list/edit.js +12 -18
- package/build-module/page-list/edit.js.map +1 -1
- package/build-module/social-links/deprecated.js +1 -62
- package/build-module/social-links/deprecated.js.map +1 -1
- package/build-module/template-part/edit/index.js +37 -65
- package/build-module/template-part/edit/index.js.map +1 -1
- package/build-module/template-part/edit/placeholder.js +52 -0
- package/build-module/template-part/edit/placeholder.js.map +1 -0
- package/build-module/template-part/edit/selection-modal.js +89 -0
- package/build-module/template-part/edit/selection-modal.js.map +1 -0
- package/build-module/template-part/edit/title-modal.js +46 -0
- package/build-module/template-part/edit/title-modal.js.map +1 -0
- package/build-module/template-part/edit/utils/hooks.js +135 -0
- package/build-module/template-part/edit/utils/hooks.js.map +1 -0
- package/build-module/template-part/index.js +2 -1
- package/build-module/template-part/index.js.map +1 -1
- package/build-style/comment-author-avatar/editor-rtl.css +83 -0
- package/build-style/comment-author-avatar/editor.css +83 -0
- package/build-style/cover/style-rtl.css +4 -0
- package/build-style/cover/style.css +4 -0
- package/build-style/editor-rtl.css +27 -81
- package/build-style/editor.css +27 -81
- package/build-style/image/editor-rtl.css +0 -16
- package/build-style/image/editor.css +0 -16
- package/build-style/image/style-rtl.css +2 -0
- package/build-style/image/style.css +2 -0
- package/build-style/navigation/style-rtl.css +14 -3
- package/build-style/navigation/style.css +14 -3
- package/build-style/page-list/editor-rtl.css +0 -9
- package/build-style/page-list/editor.css +0 -9
- package/build-style/style-rtl.css +20 -3
- package/build-style/style.css +20 -3
- package/build-style/template-part/editor-rtl.css +19 -56
- package/build-style/template-part/editor.css +19 -56
- package/package.json +15 -15
- package/src/archives/index.php +1 -1
- package/src/button/edit.native.js +3 -3
- package/src/columns/block.json +12 -0
- package/src/comment-author-avatar/edit.js +13 -8
- package/src/comment-author-avatar/editor.scss +7 -0
- package/src/comment-template/block.json +7 -1
- package/src/comment-template/edit.js +102 -40
- package/src/comment-template/hooks.js +151 -0
- package/src/comment-template/index.php +8 -0
- package/src/comment-template/util.js +1 -0
- package/src/comments-pagination-next/block.json +8 -1
- package/src/comments-pagination-next/index.php +6 -8
- package/src/comments-pagination-numbers/block.json +7 -1
- package/src/comments-pagination-numbers/index.php +3 -10
- package/src/comments-query-loop/block.json +5 -0
- package/src/comments-query-loop/edit/comments-inspector-controls.js +22 -4
- package/src/comments-query-loop/edit.js +1 -16
- package/src/cover/edit.js +15 -28
- package/src/cover/edit.native.js +15 -7
- package/src/cover/overlay-color-settings.native.js +3 -4
- package/src/cover/style.scss +4 -0
- package/src/cover/transforms.js +2 -0
- package/src/editor.scss +1 -0
- package/src/gallery/index.php +1 -8
- package/src/group/block.json +1 -0
- package/src/heading/edit.js +18 -5
- package/src/home-link/index.php +1 -19
- package/src/image/deprecated.js +105 -1
- package/src/image/editor.scss +0 -18
- package/src/image/save.js +0 -8
- package/src/image/style.scss +3 -0
- package/src/image/test/edit.native.js +0 -10
- package/src/latest-posts/edit.js +1 -0
- package/src/latest-posts/index.php +1 -1
- package/src/navigation/edit/index.js +25 -26
- package/src/navigation/edit/navigation-menu-selector.js +73 -28
- package/src/navigation/edit/placeholder/index.js +8 -32
- package/src/navigation/index.php +4 -4
- package/src/navigation/style.scss +22 -3
- package/src/navigation/use-navigation-menu.js +6 -6
- package/src/navigation-link/index.php +3 -22
- package/src/navigation-submenu/edit.js +50 -12
- package/src/navigation-submenu/index.php +3 -21
- package/src/page-list/edit.js +21 -25
- package/src/page-list/editor.scss +0 -10
- package/src/page-list/index.php +4 -4
- package/src/post-navigation-link/index.php +3 -3
- package/src/search/index.php +6 -3
- package/src/site-logo/index.php +1 -1
- package/src/social-links/deprecated.js +0 -59
- package/src/template-part/edit/index.js +61 -71
- package/src/template-part/edit/placeholder.js +78 -0
- package/src/template-part/edit/selection-modal.js +115 -0
- package/src/template-part/edit/title-modal.js +59 -0
- package/src/template-part/edit/utils/hooks.js +158 -0
- package/src/template-part/editor.scss +16 -74
- package/src/template-part/index.js +4 -1
- package/build/navigation/edit/existing-menus-options.js +0 -62
- package/build/navigation/edit/existing-menus-options.js.map +0 -1
- package/build/template-part/edit/placeholder/index.js +0 -141
- package/build/template-part/edit/placeholder/index.js.map +0 -1
- package/build/template-part/edit/placeholder/patterns-setup.js +0 -100
- package/build/template-part/edit/placeholder/patterns-setup.js.map +0 -1
- package/build/template-part/edit/selection/index.js +0 -45
- package/build/template-part/edit/selection/index.js.map +0 -1
- package/build/template-part/edit/selection/template-part-previews.js +0 -317
- package/build/template-part/edit/selection/template-part-previews.js.map +0 -1
- package/build-module/navigation/edit/existing-menus-options.js +0 -53
- package/build-module/navigation/edit/existing-menus-options.js.map +0 -1
- package/build-module/template-part/edit/placeholder/index.js +0 -124
- package/build-module/template-part/edit/placeholder/index.js.map +0 -1
- package/build-module/template-part/edit/placeholder/patterns-setup.js +0 -91
- package/build-module/template-part/edit/placeholder/patterns-setup.js.map +0 -1
- package/build-module/template-part/edit/selection/index.js +0 -35
- package/build-module/template-part/edit/selection/index.js.map +0 -1
- package/build-module/template-part/edit/selection/template-part-previews.js +0 -298
- package/build-module/template-part/edit/selection/template-part-previews.js.map +0 -1
- package/src/navigation/edit/existing-menus-options.js +0 -70
- package/src/template-part/edit/placeholder/index.js +0 -172
- package/src/template-part/edit/placeholder/patterns-setup.js +0 -124
- package/src/template-part/edit/selection/index.js +0 -37
- package/src/template-part/edit/selection/template-part-previews.js +0 -372
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* WordPress dependencies
|
|
5
|
-
*/
|
|
6
|
-
import { __experimentalBlockPatternSetup as BlockPatternSetup } from '@wordpress/block-editor';
|
|
7
|
-
import { useEffect, useState } from '@wordpress/element';
|
|
8
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
9
|
-
import { TextControl, Flex, FlexItem, Button, Modal, Placeholder } from '@wordpress/components';
|
|
10
|
-
export default function PatternsSetup(_ref) {
|
|
11
|
-
let {
|
|
12
|
-
area,
|
|
13
|
-
areaLabel,
|
|
14
|
-
areaIcon,
|
|
15
|
-
clientId,
|
|
16
|
-
onCreate,
|
|
17
|
-
resetPlaceholder
|
|
18
|
-
} = _ref;
|
|
19
|
-
const blockNameWithArea = area ? `core/template-part/${area}` : 'core/template-part'; // Restructure onCreate to set the blocks on local state.
|
|
20
|
-
// Add modal to confirm title and trigger onCreate.
|
|
21
|
-
|
|
22
|
-
const [title, setTitle] = useState(__('Untitled Template Part'));
|
|
23
|
-
const [startingBlocks, setStartingBlocks] = useState([]);
|
|
24
|
-
const [isTitleStep, setIsTitleStep] = useState(false);
|
|
25
|
-
|
|
26
|
-
const selectPattern = selectedPattern => {
|
|
27
|
-
setStartingBlocks(selectedPattern);
|
|
28
|
-
setIsTitleStep(true);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const submitForCreation = event => {
|
|
32
|
-
event.preventDefault();
|
|
33
|
-
onCreate(startingBlocks, title);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
return createElement(Fragment, null, createElement(BlockPatternSetup, {
|
|
37
|
-
clientId: clientId,
|
|
38
|
-
startBlankComponent: createElement(StartBlankComponent, {
|
|
39
|
-
setTitleStep: setIsTitleStep,
|
|
40
|
-
areaLabel: areaLabel,
|
|
41
|
-
areaIcon: areaIcon
|
|
42
|
-
}),
|
|
43
|
-
onBlockPatternSelect: selectPattern,
|
|
44
|
-
filterPatternsFn: pattern => {
|
|
45
|
-
var _pattern$blockTypes, _pattern$blockTypes$s;
|
|
46
|
-
|
|
47
|
-
return pattern === null || pattern === void 0 ? void 0 : (_pattern$blockTypes = pattern.blockTypes) === null || _pattern$blockTypes === void 0 ? void 0 : (_pattern$blockTypes$s = _pattern$blockTypes.some) === null || _pattern$blockTypes$s === void 0 ? void 0 : _pattern$blockTypes$s.call(_pattern$blockTypes, blockType => blockType === blockNameWithArea);
|
|
48
|
-
}
|
|
49
|
-
}), isTitleStep && createElement(Modal, {
|
|
50
|
-
title: sprintf( // Translators: %s as template part area title ("Header", "Footer", etc.).
|
|
51
|
-
__('Name and create your new %s'), areaLabel.toLowerCase()),
|
|
52
|
-
closeLabel: __('Cancel'),
|
|
53
|
-
onRequestClose: resetPlaceholder,
|
|
54
|
-
overlayClassName: "wp-block-template-part__placeholder-create-new__title-form"
|
|
55
|
-
}, createElement("form", {
|
|
56
|
-
onSubmit: submitForCreation
|
|
57
|
-
}, createElement(TextControl, {
|
|
58
|
-
label: __('Name'),
|
|
59
|
-
value: title,
|
|
60
|
-
onChange: setTitle
|
|
61
|
-
}), createElement(Flex, {
|
|
62
|
-
className: "wp-block-template-part__placeholder-create-new__title-form-actions",
|
|
63
|
-
justify: "flex-end"
|
|
64
|
-
}, createElement(FlexItem, null, createElement(Button, {
|
|
65
|
-
variant: "secondary",
|
|
66
|
-
onClick: resetPlaceholder
|
|
67
|
-
}, __('Cancel'))), createElement(FlexItem, null, createElement(Button, {
|
|
68
|
-
variant: "primary",
|
|
69
|
-
type: "submit",
|
|
70
|
-
disabled: !title.length,
|
|
71
|
-
"aria-disabled": !title.length
|
|
72
|
-
}, __('Create')))))));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function StartBlankComponent(_ref2) {
|
|
76
|
-
let {
|
|
77
|
-
setTitleStep,
|
|
78
|
-
areaLabel,
|
|
79
|
-
areaIcon
|
|
80
|
-
} = _ref2;
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
setTitleStep(true);
|
|
83
|
-
}, []);
|
|
84
|
-
return createElement(Placeholder, {
|
|
85
|
-
label: areaLabel,
|
|
86
|
-
icon: areaIcon,
|
|
87
|
-
instructions: sprintf( // Translators: %s as template part area title ("Header", "Footer", "Template Part", etc.).
|
|
88
|
-
__('Creating your new %s…'), areaLabel.toLowerCase())
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=patterns-setup.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/template-part/edit/placeholder/patterns-setup.js"],"names":["__experimentalBlockPatternSetup","BlockPatternSetup","useEffect","useState","__","sprintf","TextControl","Flex","FlexItem","Button","Modal","Placeholder","PatternsSetup","area","areaLabel","areaIcon","clientId","onCreate","resetPlaceholder","blockNameWithArea","title","setTitle","startingBlocks","setStartingBlocks","isTitleStep","setIsTitleStep","selectPattern","selectedPattern","submitForCreation","event","preventDefault","pattern","blockTypes","some","blockType","toLowerCase","length","StartBlankComponent","setTitleStep"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,+BAA+B,IAAIC,iBAA5C,QAAqE,yBAArE;AACA,SAASC,SAAT,EAAoBC,QAApB,QAAoC,oBAApC;AACA,SAASC,EAAT,EAAaC,OA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AAT;AAGA,SACC,cAAC,WAAD;AACC,IAAA,KAAK,EAAGxB,SADT;AAEC,IAAA,IAAI,EAAGC,QAFR;AAGC,IAAA,YAAY,EAAGV,OAAO,EACrB;AACAD,IAAAA,EAAE,CAAE,uBAAF,CAFmB,EAGrBU,SAAS,CAACqB,WAAV,EAHqB;AAHvB,IADD;AAWA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __experimentalBlockPatternSetup as BlockPatternSetup } from '@wordpress/block-editor';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tTextControl,\n\tFlex,\n\tFlexItem,\n\tButton,\n\tModal,\n\tPlaceholder,\n} from '@wordpress/components';\n\nexport default function PatternsSetup( {\n\tarea,\n\tareaLabel,\n\tareaIcon,\n\tclientId,\n\tonCreate,\n\tresetPlaceholder,\n} ) {\n\tconst blockNameWithArea = area\n\t\t? `core/template-part/${ area }`\n\t\t: 'core/template-part';\n\n\t// Restructure onCreate to set the blocks on local state.\n\t// Add modal to confirm title and trigger onCreate.\n\tconst [ title, setTitle ] = useState( __( 'Untitled Template Part' ) );\n\tconst [ startingBlocks, setStartingBlocks ] = useState( [] );\n\tconst [ isTitleStep, setIsTitleStep ] = useState( false );\n\n\tconst selectPattern = ( selectedPattern ) => {\n\t\tsetStartingBlocks( selectedPattern );\n\t\tsetIsTitleStep( true );\n\t};\n\n\tconst submitForCreation = ( event ) => {\n\t\tevent.preventDefault();\n\t\tonCreate( startingBlocks, title );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<BlockPatternSetup\n\t\t\t\tclientId={ clientId }\n\t\t\t\tstartBlankComponent={\n\t\t\t\t\t<StartBlankComponent\n\t\t\t\t\t\tsetTitleStep={ setIsTitleStep }\n\t\t\t\t\t\tareaLabel={ areaLabel }\n\t\t\t\t\t\tareaIcon={ areaIcon }\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t\tonBlockPatternSelect={ selectPattern }\n\t\t\t\tfilterPatternsFn={ ( pattern ) =>\n\t\t\t\t\tpattern?.blockTypes?.some?.(\n\t\t\t\t\t\t( blockType ) => blockType === blockNameWithArea\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t/>\n\t\t\t{ isTitleStep && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ sprintf(\n\t\t\t\t\t\t// Translators: %s as template part area title (\"Header\", \"Footer\", etc.).\n\t\t\t\t\t\t__( 'Name and create your new %s' ),\n\t\t\t\t\t\tareaLabel.toLowerCase()\n\t\t\t\t\t) }\n\t\t\t\t\tcloseLabel={ __( 'Cancel' ) }\n\t\t\t\t\tonRequestClose={ resetPlaceholder }\n\t\t\t\t\toverlayClassName=\"wp-block-template-part__placeholder-create-new__title-form\"\n\t\t\t\t>\n\t\t\t\t\t<form onSubmit={ submitForCreation }>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Flex\n\t\t\t\t\t\t\tclassName=\"wp-block-template-part__placeholder-create-new__title-form-actions\"\n\t\t\t\t\t\t\tjustify=\"flex-end\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t\tonClick={ resetPlaceholder }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\t\tdisabled={ ! title.length }\n\t\t\t\t\t\t\t\t\taria-disabled={ ! title.length }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction StartBlankComponent( { setTitleStep, areaLabel, areaIcon } ) {\n\tuseEffect( () => {\n\t\tsetTitleStep( true );\n\t}, [] );\n\treturn (\n\t\t<Placeholder\n\t\t\tlabel={ areaLabel }\n\t\t\ticon={ areaIcon }\n\t\t\tinstructions={ sprintf(\n\t\t\t\t// Translators: %s as template part area title (\"Header\", \"Footer\", \"Template Part\", etc.).\n\t\t\t\t__( 'Creating your new %s…' ),\n\t\t\t\tareaLabel.toLowerCase()\n\t\t\t) }\n\t\t/>\n\t);\n}\n"]}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* WordPress dependencies
|
|
5
|
-
*/
|
|
6
|
-
import { SearchControl } from '@wordpress/components';
|
|
7
|
-
import { useState } from '@wordpress/element';
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import TemplatePartPreviews from './template-part-previews';
|
|
13
|
-
export default function TemplatePartSelection(_ref) {
|
|
14
|
-
let {
|
|
15
|
-
setAttributes,
|
|
16
|
-
onClose,
|
|
17
|
-
area,
|
|
18
|
-
templatePartId = null
|
|
19
|
-
} = _ref;
|
|
20
|
-
const [filterValue, setFilterValue] = useState('');
|
|
21
|
-
return createElement("div", null, createElement(SearchControl, {
|
|
22
|
-
value: filterValue,
|
|
23
|
-
onChange: setFilterValue,
|
|
24
|
-
className: "wp-block-template-part__selection-preview-search-form"
|
|
25
|
-
}), createElement("div", {
|
|
26
|
-
className: "wp-block-template-part__selection-preview-container"
|
|
27
|
-
}, createElement(TemplatePartPreviews, {
|
|
28
|
-
setAttributes: setAttributes,
|
|
29
|
-
filterValue: filterValue,
|
|
30
|
-
onClose: onClose,
|
|
31
|
-
area: area,
|
|
32
|
-
templatePartId: templatePartId
|
|
33
|
-
})));
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/template-part/edit/selection/index.js"],"names":["SearchControl","useState","TemplatePartPreviews","TemplatePartSelection","setAttributes","onClose","area","templatePartId","filterValue","setFilterValue"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,aAAT,QAA8B,uBAA9B;AACA,SAASC,QAAT,QAAyB,oBAAzB;AAEA;AACA;AACA;;AACA,OAAOC,oBAAP,MAAiC,0BAAjC;AAEA,eAAe,SAASC,qBAAT,OAKX;AAAA,MAL2C;AAC9CC,IAAAA,aAD8C;AAE9CC,IAAAA,OAF8C;AAG9CC,IAAAA,IAH8C;AAI9CC,IAAAA,cAAc,GAAG;AAJ6B,GAK3C;AACH,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkCR,QAAQ,CAAE,EAAF,CAAhD;AACA,SACC,2BACC,cAAC,aAAD;AACC,IAAA,KAAK,EAAGO,WADT;AAEC,IAAA,QAAQ,EAAGC,cAFZ;AAGC,IAAA,SAAS,EAAC;AAHX,IADD,EAMC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,cAAC,oBAAD;AACC,IAAA,aAAa,EAAGL,aADjB;AAEC,IAAA,WAAW,EAAGI,WAFf;AAGC,IAAA,OAAO,EAAGH,OAHX;AAIC,IAAA,IAAI,EAAGC,IAJR;AAKC,IAAA,cAAc,EAAGC;AALlB,IADD,CAND,CADD;AAkBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { SearchControl } from '@wordpress/components';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport TemplatePartPreviews from './template-part-previews';\n\nexport default function TemplatePartSelection( {\n\tsetAttributes,\n\tonClose,\n\tarea,\n\ttemplatePartId = null,\n} ) {\n\tconst [ filterValue, setFilterValue ] = useState( '' );\n\treturn (\n\t\t<div>\n\t\t\t<SearchControl\n\t\t\t\tvalue={ filterValue }\n\t\t\t\tonChange={ setFilterValue }\n\t\t\t\tclassName=\"wp-block-template-part__selection-preview-search-form\"\n\t\t\t/>\n\t\t\t<div className=\"wp-block-template-part__selection-preview-container\">\n\t\t\t\t<TemplatePartPreviews\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tfilterValue={ filterValue }\n\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\tarea={ area }\n\t\t\t\t\ttemplatePartId={ templatePartId }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"]}
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import { createElement, Fragment } from "@wordpress/element";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* External dependencies
|
|
6
|
-
*/
|
|
7
|
-
import { groupBy, deburr, flatten } from 'lodash';
|
|
8
|
-
/**
|
|
9
|
-
* WordPress dependencies
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
13
|
-
import { parse } from '@wordpress/blocks';
|
|
14
|
-
import { useMemo, useCallback } from '@wordpress/element';
|
|
15
|
-
import { ENTER, SPACE } from '@wordpress/keycodes';
|
|
16
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
17
|
-
import { BlockPreview } from '@wordpress/block-editor';
|
|
18
|
-
import { __unstableComposite as Composite, __unstableCompositeItem as CompositeItem, Icon, __unstableUseCompositeState as useCompositeState } from '@wordpress/components';
|
|
19
|
-
import { useAsyncList } from '@wordpress/compose';
|
|
20
|
-
import { store as noticesStore } from '@wordpress/notices';
|
|
21
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
22
|
-
/**
|
|
23
|
-
* Internal dependencies
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import { createTemplatePartId } from '../utils/create-template-part-id';
|
|
27
|
-
|
|
28
|
-
function getAreaGroupTitle(areaLabel) {
|
|
29
|
-
return sprintf( // Translators: %s for the area the template part is assigned to (Header, Footer, General, etc.)
|
|
30
|
-
__('Area: %s'), areaLabel);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function PreviewPlaceholder() {
|
|
34
|
-
return createElement("div", {
|
|
35
|
-
className: "wp-block-template-part__selection-preview-item is-placeholder",
|
|
36
|
-
tabIndex: 0
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function TemplatePartItem(_ref) {
|
|
41
|
-
let {
|
|
42
|
-
templatePart,
|
|
43
|
-
setAttributes,
|
|
44
|
-
onClose,
|
|
45
|
-
composite
|
|
46
|
-
} = _ref;
|
|
47
|
-
const {
|
|
48
|
-
slug,
|
|
49
|
-
theme,
|
|
50
|
-
title: {
|
|
51
|
-
rendered: title
|
|
52
|
-
}
|
|
53
|
-
} = templatePart; // The 'raw' property is not defined for a brief period in the save cycle.
|
|
54
|
-
// The fallback prevents an error in the parse function while saving.
|
|
55
|
-
|
|
56
|
-
const content = templatePart.content.raw || '';
|
|
57
|
-
const blocks = useMemo(() => parse(content), [content]);
|
|
58
|
-
const {
|
|
59
|
-
createSuccessNotice
|
|
60
|
-
} = useDispatch(noticesStore);
|
|
61
|
-
const onClick = useCallback(() => {
|
|
62
|
-
setAttributes({
|
|
63
|
-
slug,
|
|
64
|
-
theme,
|
|
65
|
-
area: undefined
|
|
66
|
-
});
|
|
67
|
-
createSuccessNotice(sprintf(
|
|
68
|
-
/* translators: %s: template part title. */
|
|
69
|
-
__('Template Part "%s" inserted.'), title || slug), {
|
|
70
|
-
type: 'snackbar'
|
|
71
|
-
});
|
|
72
|
-
onClose();
|
|
73
|
-
}, [slug, theme]);
|
|
74
|
-
return createElement(CompositeItem, _extends({
|
|
75
|
-
as: "div",
|
|
76
|
-
className: "wp-block-template-part__selection-preview-item",
|
|
77
|
-
role: "option",
|
|
78
|
-
onClick: onClick,
|
|
79
|
-
onKeyDown: event => {
|
|
80
|
-
if (ENTER === event.keyCode || SPACE === event.keyCode) {
|
|
81
|
-
onClick();
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
tabIndex: 0,
|
|
85
|
-
"aria-label": title || slug
|
|
86
|
-
}, composite), createElement(BlockPreview, {
|
|
87
|
-
blocks: blocks
|
|
88
|
-
}), createElement("div", {
|
|
89
|
-
className: "wp-block-template-part__selection-preview-item-title"
|
|
90
|
-
}, title || slug));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function PanelGroup(_ref2) {
|
|
94
|
-
let {
|
|
95
|
-
title,
|
|
96
|
-
icon,
|
|
97
|
-
children
|
|
98
|
-
} = _ref2;
|
|
99
|
-
return createElement(Fragment, null, createElement("div", {
|
|
100
|
-
className: "wp-block-template-part__selection-panel-group-header"
|
|
101
|
-
}, createElement("span", {
|
|
102
|
-
className: "wp-block-template-part__selection-panel-group-title"
|
|
103
|
-
}, title), createElement(Icon, {
|
|
104
|
-
icon: icon
|
|
105
|
-
})), createElement("div", {
|
|
106
|
-
className: "wp-block-template-part__selection-panel-group-content"
|
|
107
|
-
}, children));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function TemplatePartsByArea(_ref3) {
|
|
111
|
-
let {
|
|
112
|
-
templateParts,
|
|
113
|
-
setAttributes,
|
|
114
|
-
onClose,
|
|
115
|
-
composite,
|
|
116
|
-
area = 'uncategorized',
|
|
117
|
-
labelsByArea
|
|
118
|
-
} = _ref3;
|
|
119
|
-
const {
|
|
120
|
-
templatePartsByArea,
|
|
121
|
-
templatePartsToShow
|
|
122
|
-
} = useMemo(() => {
|
|
123
|
-
const _templatePartsToShow = templateParts.filter(templatePart => 'uncategorized' === area || templatePart.area === area) || [];
|
|
124
|
-
|
|
125
|
-
const _templatePartsByArea = Object.values(groupBy(_templatePartsToShow, 'area'));
|
|
126
|
-
|
|
127
|
-
const orderedTemplatePartsToShow = flatten(_templatePartsToShow);
|
|
128
|
-
return {
|
|
129
|
-
templatePartsByArea: _templatePartsByArea,
|
|
130
|
-
templatePartsToShow: orderedTemplatePartsToShow
|
|
131
|
-
};
|
|
132
|
-
}, [templateParts, area]);
|
|
133
|
-
const currentShownTPs = useAsyncList(templatePartsToShow);
|
|
134
|
-
|
|
135
|
-
if (!templatePartsToShow.length) {
|
|
136
|
-
return createElement(PanelGroup, {
|
|
137
|
-
title: getAreaGroupTitle(labelsByArea[area] || labelsByArea.uncategorized)
|
|
138
|
-
}, sprintf( // Translators: %s for the template part variation ("Header", "Footer", "Template Part").
|
|
139
|
-
__('There is no other %s available. If you are looking for another type of template part, try searching for it using the input above.'), area && area !== 'uncategorized' ? labelsByArea[area] || area : __('Template Part')));
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return templatePartsByArea.map(templatePartList => {
|
|
143
|
-
return createElement(PanelGroup, {
|
|
144
|
-
key: templatePartList[0].area,
|
|
145
|
-
title: getAreaGroupTitle(labelsByArea[templatePartList[0].area] || labelsByArea.uncategorized)
|
|
146
|
-
}, templatePartList.map(templatePart => {
|
|
147
|
-
return currentShownTPs.includes(templatePart) ? createElement(TemplatePartItem, {
|
|
148
|
-
key: templatePart.id,
|
|
149
|
-
templatePart: templatePart,
|
|
150
|
-
setAttributes: setAttributes,
|
|
151
|
-
onClose: onClose,
|
|
152
|
-
composite: composite
|
|
153
|
-
}) : createElement(PreviewPlaceholder, {
|
|
154
|
-
key: templatePart.id
|
|
155
|
-
});
|
|
156
|
-
}));
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function TemplatePartSearchResults(_ref4) {
|
|
161
|
-
let {
|
|
162
|
-
templateParts,
|
|
163
|
-
setAttributes,
|
|
164
|
-
filterValue,
|
|
165
|
-
onClose,
|
|
166
|
-
composite,
|
|
167
|
-
labelsByArea
|
|
168
|
-
} = _ref4;
|
|
169
|
-
const {
|
|
170
|
-
filteredTPs,
|
|
171
|
-
groupedResults
|
|
172
|
-
} = useMemo(() => {
|
|
173
|
-
// Filter based on value.
|
|
174
|
-
// Remove diacritics and convert to lowercase to normalize.
|
|
175
|
-
const normalizedFilterValue = deburr(filterValue).toLowerCase();
|
|
176
|
-
const searchResults = templateParts.filter(_ref5 => {
|
|
177
|
-
let {
|
|
178
|
-
title: {
|
|
179
|
-
rendered: title
|
|
180
|
-
},
|
|
181
|
-
area
|
|
182
|
-
} = _ref5;
|
|
183
|
-
return deburr(title).toLowerCase().includes(normalizedFilterValue) || // Since diacritics can be used in theme names, remove them for the comparison.
|
|
184
|
-
deburr(labelsByArea[area]).toLowerCase().includes(normalizedFilterValue);
|
|
185
|
-
}); // Order based on value location.
|
|
186
|
-
|
|
187
|
-
searchResults.sort((a, b) => {
|
|
188
|
-
// First prioritize index found in title.
|
|
189
|
-
// Deburr for diacritics.
|
|
190
|
-
const indexInTitleA = deburr(a.title.rendered).toLowerCase().indexOf(normalizedFilterValue);
|
|
191
|
-
const indexInTitleB = deburr(b.title.rendered).toLowerCase().indexOf(normalizedFilterValue);
|
|
192
|
-
|
|
193
|
-
if (indexInTitleA !== -1 && indexInTitleB !== -1) {
|
|
194
|
-
return indexInTitleA - indexInTitleB;
|
|
195
|
-
} else if (indexInTitleA !== -1) {
|
|
196
|
-
return -1;
|
|
197
|
-
} else if (indexInTitleB !== -1) {
|
|
198
|
-
return 1;
|
|
199
|
-
} // Second prioritize index found in area.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return deburr(labelsByArea[a.area]).toLowerCase().indexOf(normalizedFilterValue) - deburr(labelsByArea[b.area]).toLowerCase().indexOf(normalizedFilterValue);
|
|
203
|
-
}); // Group filtered results together if their neighbors share the same area.
|
|
204
|
-
// This helps not show redundant panel groups side by side in the results.
|
|
205
|
-
|
|
206
|
-
const _groupedResults = [];
|
|
207
|
-
|
|
208
|
-
for (let i = 0; i < searchResults.length; i++) {
|
|
209
|
-
if (i !== 0 && searchResults[i].area === searchResults[i - 1].area) {
|
|
210
|
-
_groupedResults[_groupedResults.length - 1].push(searchResults[i]);
|
|
211
|
-
} else {
|
|
212
|
-
_groupedResults.push([searchResults[i]]);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return {
|
|
217
|
-
filteredTPs: searchResults,
|
|
218
|
-
groupedResults: _groupedResults
|
|
219
|
-
};
|
|
220
|
-
}, [filterValue, templateParts]);
|
|
221
|
-
const currentShownTPs = useAsyncList(filteredTPs);
|
|
222
|
-
return groupedResults.map(group => createElement(PanelGroup, {
|
|
223
|
-
key: group[0].id,
|
|
224
|
-
title: getAreaGroupTitle(labelsByArea[group[0].area] || labelsByArea.uncategorized)
|
|
225
|
-
}, group.map(templatePart => currentShownTPs.includes(templatePart) ? createElement(TemplatePartItem, {
|
|
226
|
-
key: templatePart.id,
|
|
227
|
-
templatePart: templatePart,
|
|
228
|
-
setAttributes: setAttributes,
|
|
229
|
-
onClose: onClose,
|
|
230
|
-
composite: composite
|
|
231
|
-
}) : createElement(PreviewPlaceholder, {
|
|
232
|
-
key: templatePart.id
|
|
233
|
-
}))));
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export default function TemplatePartPreviews(_ref6) {
|
|
237
|
-
let {
|
|
238
|
-
setAttributes,
|
|
239
|
-
filterValue,
|
|
240
|
-
onClose,
|
|
241
|
-
area,
|
|
242
|
-
templatePartId
|
|
243
|
-
} = _ref6;
|
|
244
|
-
const composite = useCompositeState();
|
|
245
|
-
const {
|
|
246
|
-
templateParts,
|
|
247
|
-
labelsByArea
|
|
248
|
-
} = useSelect(select => {
|
|
249
|
-
const _templateParts = (select(coreStore).getEntityRecords('postType', 'wp_template_part', {
|
|
250
|
-
per_page: -1
|
|
251
|
-
}) || []).filter(templatePart => createTemplatePartId(templatePart.theme, templatePart.slug) !== templatePartId); // FIXME: @wordpress/block-library should not depend on @wordpress/editor.
|
|
252
|
-
// Blocks can be loaded into a *non-post* block editor.
|
|
253
|
-
// eslint-disable-next-line @wordpress/data-no-store-string-literals
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const definedAreas = select('core/editor').__experimentalGetDefaultTemplatePartAreas();
|
|
257
|
-
|
|
258
|
-
const _labelsByArea = {};
|
|
259
|
-
definedAreas.forEach(item => {
|
|
260
|
-
_labelsByArea[item.area] = item.label;
|
|
261
|
-
});
|
|
262
|
-
return {
|
|
263
|
-
templateParts: _templateParts,
|
|
264
|
-
labelsByArea: _labelsByArea
|
|
265
|
-
};
|
|
266
|
-
}, []);
|
|
267
|
-
|
|
268
|
-
if (!templateParts || !templateParts.length) {
|
|
269
|
-
return createElement(PanelGroup, null, __('There are no existing template parts to select.'));
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (filterValue) {
|
|
273
|
-
return createElement(Composite, _extends({}, composite, {
|
|
274
|
-
role: "listbox",
|
|
275
|
-
"aria-label": __('List of template parts')
|
|
276
|
-
}), createElement(TemplatePartSearchResults, {
|
|
277
|
-
templateParts: templateParts,
|
|
278
|
-
setAttributes: setAttributes,
|
|
279
|
-
filterValue: filterValue,
|
|
280
|
-
onClose: onClose,
|
|
281
|
-
composite: composite,
|
|
282
|
-
labelsByArea: labelsByArea
|
|
283
|
-
}));
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
return createElement(Composite, _extends({}, composite, {
|
|
287
|
-
role: "listbox",
|
|
288
|
-
"aria-label": __('List of template parts')
|
|
289
|
-
}), createElement(TemplatePartsByArea, {
|
|
290
|
-
templateParts: templateParts,
|
|
291
|
-
setAttributes: setAttributes,
|
|
292
|
-
onClose: onClose,
|
|
293
|
-
composite: composite,
|
|
294
|
-
area: area,
|
|
295
|
-
labelsByArea: labelsByArea
|
|
296
|
-
}));
|
|
297
|
-
}
|
|
298
|
-
//# sourceMappingURL=template-part-previews.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/template-part/edit/selection/template-part-previews.js"],"names":["groupBy","deburr","flatten","useSelect","useDispatch","parse","useMemo","useCallback","ENTER","SPACE","__","sprintf","BlockPreview","__unstableComposite","Composite","__unstableCompositeItem","CompositeItem","Icon","__unstableUseCompositeState","useCompositeState","useAsyncList","store","noticesStore","coreStore","createTemplatePartId","getAreaGroupTitle","areaLabel","PreviewPlaceholder","TemplatePartItem","templatePart","setAttributes","onClose","composite","slug","theme","title","rendered","content","raw","blocks","createSuccessNotice","onClick","area","undefined","type","event","keyCode","PanelGroup","icon","children","TemplatePartsByArea","templateParts","labelsByArea","templatePartsByArea","templatePartsToShow","_templatePartsToShow","filter","_templatePartsByArea","Object","values","orderedTemplatePartsToShow","currentShownTPs","length","uncategorized","map","templatePartList","includes","id","TemplatePartSearchResults","filterValue","filteredTPs","groupedResults","normalizedFilterValue","toLowerCase","searchResults","sort","a","b","indexInTitleA","indexOf","indexInTitleB","_groupedResults","i","push","group","TemplatePartPreviews","templatePartId","select","_templateParts","getEntityRecords","per_page","definedAreas","__experimentalGetDefaultTemplatePartAreas","_labelsByArea","forEach","item","label"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,MAAlB,EAA0BC,OAA1B,QAAyC,QAAzC;AAEA;AACA;AACA;;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAT,QAAsB,mBAAtB;AACA,SAASC,OAAT,EAAkBC,WAAlB,QAAqC,oBAArC;AACA,SAASC,KAAT,EAAgBC,KAAhB,QAA6B,qBAA7B;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,YAAT,QAA6B,yBAA7B;AACA,SACCC,mBAAmB,IAAIC,SADxB,EAECC,uBAAuB,IAAIC,aAF5B,EAGCC,IAHD,EAICC,2BAA2B,IAAIC,iBAJhC,QAKO,uBALP;AAMA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASC,KAAK,IAAIC,YAAlB,QAAsC,oBAAtC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;AACC,IAAA,aAAa,EAAGyC,aADjB;AAEC,IAAA,aAAa,EAAGrB,aAFjB;AAGC,IAAA,OAAO,EAAGC,OAHX;AAIC,IAAA,SAAS,EAAGC,SAJb;AAKC,IAAA,IAAI,EAAGU,IALR;AAMC,IAAA,YAAY,EAAGU;AANhB,IALD,CADD;AAgBA","sourcesContent":["/**\n * External dependencies\n */\nimport { groupBy, deburr, flatten } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { parse } from '@wordpress/blocks';\nimport { useMemo, useCallback } from '@wordpress/element';\nimport { ENTER, SPACE } from '@wordpress/keycodes';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { BlockPreview } from '@wordpress/block-editor';\nimport {\n\t__unstableComposite as Composite,\n\t__unstableCompositeItem as CompositeItem,\n\tIcon,\n\t__unstableUseCompositeState as useCompositeState,\n} from '@wordpress/components';\nimport { useAsyncList } from '@wordpress/compose';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { createTemplatePartId } from '../utils/create-template-part-id';\n\nfunction getAreaGroupTitle( areaLabel ) {\n\treturn sprintf(\n\t\t// Translators: %s for the area the template part is assigned to (Header, Footer, General, etc.)\n\t\t__( 'Area: %s' ),\n\t\tareaLabel\n\t);\n}\nfunction PreviewPlaceholder() {\n\treturn (\n\t\t<div\n\t\t\tclassName=\"wp-block-template-part__selection-preview-item is-placeholder\"\n\t\t\ttabIndex={ 0 }\n\t\t/>\n\t);\n}\n\nfunction TemplatePartItem( {\n\ttemplatePart,\n\tsetAttributes,\n\tonClose,\n\tcomposite,\n} ) {\n\tconst {\n\t\tslug,\n\t\ttheme,\n\t\ttitle: { rendered: title },\n\t} = templatePart;\n\t// The 'raw' property is not defined for a brief period in the save cycle.\n\t// The fallback prevents an error in the parse function while saving.\n\tconst content = templatePart.content.raw || '';\n\tconst blocks = useMemo( () => parse( content ), [ content ] );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tconst onClick = useCallback( () => {\n\t\tsetAttributes( { slug, theme, area: undefined } );\n\t\tcreateSuccessNotice(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %s: template part title. */\n\t\t\t\t__( 'Template Part \"%s\" inserted.' ),\n\t\t\t\ttitle || slug\n\t\t\t),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t\tonClose();\n\t}, [ slug, theme ] );\n\n\treturn (\n\t\t<CompositeItem\n\t\t\tas=\"div\"\n\t\t\tclassName=\"wp-block-template-part__selection-preview-item\"\n\t\t\trole=\"option\"\n\t\t\tonClick={ onClick }\n\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\tif ( ENTER === event.keyCode || SPACE === event.keyCode ) {\n\t\t\t\t\tonClick();\n\t\t\t\t}\n\t\t\t} }\n\t\t\ttabIndex={ 0 }\n\t\t\taria-label={ title || slug }\n\t\t\t{ ...composite }\n\t\t>\n\t\t\t<BlockPreview blocks={ blocks } />\n\t\t\t<div className=\"wp-block-template-part__selection-preview-item-title\">\n\t\t\t\t{ title || slug }\n\t\t\t</div>\n\t\t</CompositeItem>\n\t);\n}\n\nfunction PanelGroup( { title, icon, children } ) {\n\treturn (\n\t\t<>\n\t\t\t<div className=\"wp-block-template-part__selection-panel-group-header\">\n\t\t\t\t<span className=\"wp-block-template-part__selection-panel-group-title\">\n\t\t\t\t\t{ title }\n\t\t\t\t</span>\n\t\t\t\t<Icon icon={ icon } />\n\t\t\t</div>\n\t\t\t<div className=\"wp-block-template-part__selection-panel-group-content\">\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nfunction TemplatePartsByArea( {\n\ttemplateParts,\n\tsetAttributes,\n\tonClose,\n\tcomposite,\n\tarea = 'uncategorized',\n\tlabelsByArea,\n} ) {\n\tconst { templatePartsByArea, templatePartsToShow } = useMemo( () => {\n\t\tconst _templatePartsToShow =\n\t\t\ttemplateParts.filter(\n\t\t\t\t( templatePart ) =>\n\t\t\t\t\t'uncategorized' === area || templatePart.area === area\n\t\t\t) || [];\n\t\tconst _templatePartsByArea = Object.values(\n\t\t\tgroupBy( _templatePartsToShow, 'area' )\n\t\t);\n\t\tconst orderedTemplatePartsToShow = flatten( _templatePartsToShow );\n\t\treturn {\n\t\t\ttemplatePartsByArea: _templatePartsByArea,\n\t\t\ttemplatePartsToShow: orderedTemplatePartsToShow,\n\t\t};\n\t}, [ templateParts, area ] );\n\n\tconst currentShownTPs = useAsyncList( templatePartsToShow );\n\n\tif ( ! templatePartsToShow.length ) {\n\t\treturn (\n\t\t\t<PanelGroup\n\t\t\t\ttitle={ getAreaGroupTitle(\n\t\t\t\t\tlabelsByArea[ area ] || labelsByArea.uncategorized\n\t\t\t\t) }\n\t\t\t>\n\t\t\t\t{ sprintf(\n\t\t\t\t\t// Translators: %s for the template part variation (\"Header\", \"Footer\", \"Template Part\").\n\t\t\t\t\t__(\n\t\t\t\t\t\t'There is no other %s available. If you are looking for another type of template part, try searching for it using the input above.'\n\t\t\t\t\t),\n\t\t\t\t\tarea && area !== 'uncategorized'\n\t\t\t\t\t\t? labelsByArea[ area ] || area\n\t\t\t\t\t\t: __( 'Template Part' )\n\t\t\t\t) }\n\t\t\t</PanelGroup>\n\t\t);\n\t}\n\n\treturn templatePartsByArea.map( ( templatePartList ) => {\n\t\treturn (\n\t\t\t<PanelGroup\n\t\t\t\tkey={ templatePartList[ 0 ].area }\n\t\t\t\ttitle={ getAreaGroupTitle(\n\t\t\t\t\tlabelsByArea[ templatePartList[ 0 ].area ] ||\n\t\t\t\t\t\tlabelsByArea.uncategorized\n\t\t\t\t) }\n\t\t\t>\n\t\t\t\t{ templatePartList.map( ( templatePart ) => {\n\t\t\t\t\treturn currentShownTPs.includes( templatePart ) ? (\n\t\t\t\t\t\t<TemplatePartItem\n\t\t\t\t\t\t\tkey={ templatePart.id }\n\t\t\t\t\t\t\ttemplatePart={ templatePart }\n\t\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<PreviewPlaceholder key={ templatePart.id } />\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</PanelGroup>\n\t\t);\n\t} );\n}\n\nfunction TemplatePartSearchResults( {\n\ttemplateParts,\n\tsetAttributes,\n\tfilterValue,\n\tonClose,\n\tcomposite,\n\tlabelsByArea,\n} ) {\n\tconst { filteredTPs, groupedResults } = useMemo( () => {\n\t\t// Filter based on value.\n\t\t// Remove diacritics and convert to lowercase to normalize.\n\t\tconst normalizedFilterValue = deburr( filterValue ).toLowerCase();\n\t\tconst searchResults = templateParts.filter(\n\t\t\t( { title: { rendered: title }, area } ) =>\n\t\t\t\tdeburr( title )\n\t\t\t\t\t.toLowerCase()\n\t\t\t\t\t.includes( normalizedFilterValue ) ||\n\t\t\t\t// Since diacritics can be used in theme names, remove them for the comparison.\n\t\t\t\tdeburr( labelsByArea[ area ] )\n\t\t\t\t\t.toLowerCase()\n\t\t\t\t\t.includes( normalizedFilterValue )\n\t\t);\n\t\t// Order based on value location.\n\t\tsearchResults.sort( ( a, b ) => {\n\t\t\t// First prioritize index found in title.\n\t\t\t// Deburr for diacritics.\n\t\t\tconst indexInTitleA = deburr( a.title.rendered )\n\t\t\t\t.toLowerCase()\n\t\t\t\t.indexOf( normalizedFilterValue );\n\t\t\tconst indexInTitleB = deburr( b.title.rendered )\n\t\t\t\t.toLowerCase()\n\t\t\t\t.indexOf( normalizedFilterValue );\n\t\t\tif ( indexInTitleA !== -1 && indexInTitleB !== -1 ) {\n\t\t\t\treturn indexInTitleA - indexInTitleB;\n\t\t\t} else if ( indexInTitleA !== -1 ) {\n\t\t\t\treturn -1;\n\t\t\t} else if ( indexInTitleB !== -1 ) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\t// Second prioritize index found in area.\n\t\t\treturn (\n\t\t\t\tdeburr( labelsByArea[ a.area ] )\n\t\t\t\t\t.toLowerCase()\n\t\t\t\t\t.indexOf( normalizedFilterValue ) -\n\t\t\t\tdeburr( labelsByArea[ b.area ] )\n\t\t\t\t\t.toLowerCase()\n\t\t\t\t\t.indexOf( normalizedFilterValue )\n\t\t\t);\n\t\t} );\n\t\t// Group filtered results together if their neighbors share the same area.\n\t\t// This helps not show redundant panel groups side by side in the results.\n\t\tconst _groupedResults = [];\n\t\tfor ( let i = 0; i < searchResults.length; i++ ) {\n\t\t\tif (\n\t\t\t\ti !== 0 &&\n\t\t\t\tsearchResults[ i ].area === searchResults[ i - 1 ].area\n\t\t\t) {\n\t\t\t\t_groupedResults[ _groupedResults.length - 1 ].push(\n\t\t\t\t\tsearchResults[ i ]\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t_groupedResults.push( [ searchResults[ i ] ] );\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tfilteredTPs: searchResults,\n\t\t\tgroupedResults: _groupedResults,\n\t\t};\n\t}, [ filterValue, templateParts ] );\n\n\tconst currentShownTPs = useAsyncList( filteredTPs );\n\n\treturn groupedResults.map( ( group ) => (\n\t\t<PanelGroup\n\t\t\tkey={ group[ 0 ].id }\n\t\t\ttitle={ getAreaGroupTitle(\n\t\t\t\tlabelsByArea[ group[ 0 ].area ] || labelsByArea.uncategorized\n\t\t\t) }\n\t\t>\n\t\t\t{ group.map( ( templatePart ) =>\n\t\t\t\tcurrentShownTPs.includes( templatePart ) ? (\n\t\t\t\t\t<TemplatePartItem\n\t\t\t\t\t\tkey={ templatePart.id }\n\t\t\t\t\t\ttemplatePart={ templatePart }\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t/>\n\t\t\t\t) : (\n\t\t\t\t\t<PreviewPlaceholder key={ templatePart.id } />\n\t\t\t\t)\n\t\t\t) }\n\t\t</PanelGroup>\n\t) );\n}\n\nexport default function TemplatePartPreviews( {\n\tsetAttributes,\n\tfilterValue,\n\tonClose,\n\tarea,\n\ttemplatePartId,\n} ) {\n\tconst composite = useCompositeState();\n\n\tconst { templateParts, labelsByArea } = useSelect( ( select ) => {\n\t\tconst _templateParts = (\n\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t) || []\n\t\t).filter(\n\t\t\t( templatePart ) =>\n\t\t\t\tcreateTemplatePartId(\n\t\t\t\t\ttemplatePart.theme,\n\t\t\t\t\ttemplatePart.slug\n\t\t\t\t) !== templatePartId\n\t\t);\n\n\t\t// FIXME: @wordpress/block-library should not depend on @wordpress/editor.\n\t\t// Blocks can be loaded into a *non-post* block editor.\n\t\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\t\tconst definedAreas = select(\n\t\t\t'core/editor'\n\t\t).__experimentalGetDefaultTemplatePartAreas();\n\t\tconst _labelsByArea = {};\n\t\tdefinedAreas.forEach( ( item ) => {\n\t\t\t_labelsByArea[ item.area ] = item.label;\n\t\t} );\n\n\t\treturn {\n\t\t\ttemplateParts: _templateParts,\n\t\t\tlabelsByArea: _labelsByArea,\n\t\t};\n\t}, [] );\n\n\tif ( ! templateParts || ! templateParts.length ) {\n\t\treturn (\n\t\t\t<PanelGroup>\n\t\t\t\t{ __( 'There are no existing template parts to select.' ) }\n\t\t\t</PanelGroup>\n\t\t);\n\t}\n\n\tif ( filterValue ) {\n\t\treturn (\n\t\t\t<Composite\n\t\t\t\t{ ...composite }\n\t\t\t\trole=\"listbox\"\n\t\t\t\taria-label={ __( 'List of template parts' ) }\n\t\t\t>\n\t\t\t\t<TemplatePartSearchResults\n\t\t\t\t\ttemplateParts={ templateParts }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tfilterValue={ filterValue }\n\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\tlabelsByArea={ labelsByArea }\n\t\t\t\t/>\n\t\t\t</Composite>\n\t\t);\n\t}\n\n\treturn (\n\t\t<Composite\n\t\t\t{ ...composite }\n\t\t\trole=\"listbox\"\n\t\t\taria-label={ __( 'List of template parts' ) }\n\t\t>\n\t\t\t<TemplatePartsByArea\n\t\t\t\ttemplateParts={ templateParts }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\tonClose={ onClose }\n\t\t\t\tcomposite={ composite }\n\t\t\t\tarea={ area }\n\t\t\t\tlabelsByArea={ labelsByArea }\n\t\t\t/>\n\t\t</Composite>\n\t);\n}\n"]}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { MenuGroup, MenuItem } from '@wordpress/components';
|
|
5
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
6
|
-
import { decodeEntities } from '@wordpress/html-entities';
|
|
7
|
-
|
|
8
|
-
const ExistingMenusOptions = ( {
|
|
9
|
-
showNavigationMenus,
|
|
10
|
-
showClassicMenus = false,
|
|
11
|
-
navigationMenus,
|
|
12
|
-
classicMenus,
|
|
13
|
-
onSelectNavigationMenu,
|
|
14
|
-
onSelectClassicMenu,
|
|
15
|
-
actionLabel,
|
|
16
|
-
} ) => {
|
|
17
|
-
const hasNavigationMenus = !! navigationMenus?.length;
|
|
18
|
-
const hasClassicMenus = !! classicMenus?.length;
|
|
19
|
-
|
|
20
|
-
/* translators: %s: The name of a menu. */
|
|
21
|
-
const createActionLabel = __( "Create from '%s'" );
|
|
22
|
-
|
|
23
|
-
actionLabel = actionLabel || createActionLabel;
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<>
|
|
27
|
-
{ showNavigationMenus && hasNavigationMenus && (
|
|
28
|
-
<MenuGroup label={ __( 'Menus' ) }>
|
|
29
|
-
{ navigationMenus.map( ( menu ) => {
|
|
30
|
-
const label = decodeEntities( menu.title.rendered );
|
|
31
|
-
return (
|
|
32
|
-
<MenuItem
|
|
33
|
-
onClick={ () => {
|
|
34
|
-
onSelectNavigationMenu( menu );
|
|
35
|
-
} }
|
|
36
|
-
key={ menu.id }
|
|
37
|
-
aria-label={ sprintf( actionLabel, label ) }
|
|
38
|
-
>
|
|
39
|
-
{ label }
|
|
40
|
-
</MenuItem>
|
|
41
|
-
);
|
|
42
|
-
} ) }
|
|
43
|
-
</MenuGroup>
|
|
44
|
-
) }
|
|
45
|
-
{ showClassicMenus && hasClassicMenus && (
|
|
46
|
-
<MenuGroup label={ __( 'Classic Menus' ) }>
|
|
47
|
-
{ classicMenus.map( ( menu ) => {
|
|
48
|
-
const label = decodeEntities( menu.name );
|
|
49
|
-
return (
|
|
50
|
-
<MenuItem
|
|
51
|
-
onClick={ () => {
|
|
52
|
-
onSelectClassicMenu( menu );
|
|
53
|
-
} }
|
|
54
|
-
key={ menu.id }
|
|
55
|
-
aria-label={ sprintf(
|
|
56
|
-
createActionLabel,
|
|
57
|
-
label
|
|
58
|
-
) }
|
|
59
|
-
>
|
|
60
|
-
{ label }
|
|
61
|
-
</MenuItem>
|
|
62
|
-
);
|
|
63
|
-
} ) }
|
|
64
|
-
</MenuGroup>
|
|
65
|
-
) }
|
|
66
|
-
</>
|
|
67
|
-
);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export default ExistingMenusOptions;
|