@wordpress/editor 13.18.1-next.5a1d1283.0 → 13.19.1
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 +2 -0
- package/README.md +0 -5
- package/build/components/page-attributes/parent.js +14 -13
- package/build/components/page-attributes/parent.js.map +1 -1
- package/build/components/post-author/combobox.js +1 -0
- package/build/components/post-author/combobox.js.map +1 -1
- package/build/components/post-last-revision/index.js +1 -2
- package/build/components/post-last-revision/index.js.map +1 -1
- package/build/components/post-sync-status/index.js +10 -10
- package/build/components/post-sync-status/index.js.map +1 -1
- package/build/components/post-taxonomies/flat-term-selector.js +9 -0
- package/build/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build/components/post-taxonomies/hierarchical-term-selector.js +19 -5
- package/build/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.js +11 -7
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/store/selectors.js +2 -2
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/page-attributes/parent.js +14 -13
- package/build-module/components/page-attributes/parent.js.map +1 -1
- package/build-module/components/post-author/combobox.js +1 -0
- package/build-module/components/post-author/combobox.js.map +1 -1
- package/build-module/components/post-last-revision/index.js +1 -2
- package/build-module/components/post-last-revision/index.js.map +1 -1
- package/build-module/components/post-sync-status/index.js +10 -10
- package/build-module/components/post-sync-status/index.js.map +1 -1
- package/build-module/components/post-taxonomies/flat-term-selector.js +9 -0
- package/build-module/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build-module/components/post-taxonomies/hierarchical-term-selector.js +19 -5
- package/build-module/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.js +12 -8
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/store/selectors.js +2 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +2 -2
- package/build-style/style.css +2 -2
- package/package.json +31 -31
- package/src/components/page-attributes/parent.js +18 -15
- package/src/components/post-author/combobox.js +1 -0
- package/src/components/post-last-revision/index.js +0 -1
- package/src/components/post-saved-state/test/index.js +3 -1
- package/src/components/post-sync-status/index.js +14 -8
- package/src/components/post-taxonomies/flat-term-selector.js +15 -6
- package/src/components/post-taxonomies/hierarchical-term-selector.js +18 -7
- package/src/components/provider/use-block-editor-settings.js +21 -11
- package/src/store/selectors.js +16 -10
- package/src/store/test/selectors.js +25 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -91,11 +91,6 @@ The following properties (non-exhaustive list) are made available:
|
|
|
91
91
|
- `placeholder: string` - A text hint to be shown to the user when the field
|
|
92
92
|
value is empty, similar to the
|
|
93
93
|
[`input` and `textarea` attribute of the same name](https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/HTML5_updates#The_placeholder_attribute).
|
|
94
|
-
- `multiline: String` - A tag name to use for the tag that should be inserted
|
|
95
|
-
when Enter is pressed. For example: `li` in a list block, and `p` for a
|
|
96
|
-
block that can contain multiple paragraphs. The default is that only inline
|
|
97
|
-
elements are allowed to be used in inserted into the text, effectively
|
|
98
|
-
disabling the behavior of the "Enter" key.
|
|
99
94
|
|
|
100
95
|
Example:
|
|
101
96
|
|
|
@@ -50,10 +50,9 @@ function PageAttributesParent() {
|
|
|
50
50
|
const [fieldValue, setFieldValue] = (0, _element.useState)(false);
|
|
51
51
|
const {
|
|
52
52
|
isHierarchical,
|
|
53
|
-
parentPost,
|
|
54
53
|
parentPostId,
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
parentPostTitle,
|
|
55
|
+
pageItems
|
|
57
56
|
} = (0, _data.useSelect)(select => {
|
|
58
57
|
var _pType$hierarchical;
|
|
59
58
|
const {
|
|
@@ -83,16 +82,14 @@ function PageAttributesParent() {
|
|
|
83
82
|
if (!!fieldValue) {
|
|
84
83
|
query.search = fieldValue;
|
|
85
84
|
}
|
|
85
|
+
const parentPost = pageId ? getEntityRecord('postType', postTypeSlug, pageId) : null;
|
|
86
86
|
return {
|
|
87
87
|
isHierarchical: postIsHierarchical,
|
|
88
88
|
parentPostId: pageId,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
postType: pType
|
|
89
|
+
parentPostTitle: parentPost ? getTitle(parentPost) : '',
|
|
90
|
+
pageItems: postIsHierarchical ? getEntityRecords('postType', postTypeSlug, query) : null
|
|
92
91
|
};
|
|
93
92
|
}, [fieldValue]);
|
|
94
|
-
const parentPageLabel = postType?.labels?.parent_item_colon;
|
|
95
|
-
const pageItems = items || [];
|
|
96
93
|
const parentOptions = (0, _element.useMemo)(() => {
|
|
97
94
|
const getOptionsFromTree = (tree, level = 0) => {
|
|
98
95
|
const mappedNodes = tree.map(treeNode => [{
|
|
@@ -107,6 +104,9 @@ function PageAttributesParent() {
|
|
|
107
104
|
});
|
|
108
105
|
return sortedNodes.flat();
|
|
109
106
|
};
|
|
107
|
+
if (!pageItems) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
110
|
let tree = pageItems.map(item => ({
|
|
111
111
|
id: item.id,
|
|
112
112
|
parent: item.parent,
|
|
@@ -121,15 +121,15 @@ function PageAttributesParent() {
|
|
|
121
121
|
|
|
122
122
|
// Ensure the current parent is in the options list.
|
|
123
123
|
const optsHasParent = opts.find(item => item.value === parentPostId);
|
|
124
|
-
if (
|
|
124
|
+
if (parentPostTitle && !optsHasParent) {
|
|
125
125
|
opts.unshift({
|
|
126
126
|
value: parentPostId,
|
|
127
|
-
label:
|
|
127
|
+
label: parentPostTitle
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
return opts;
|
|
131
|
-
}, [pageItems, fieldValue]);
|
|
132
|
-
if (!isHierarchical
|
|
131
|
+
}, [pageItems, fieldValue, parentPostTitle, parentPostId]);
|
|
132
|
+
if (!isHierarchical) {
|
|
133
133
|
return null;
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
@@ -153,8 +153,9 @@ function PageAttributesParent() {
|
|
|
153
153
|
};
|
|
154
154
|
return (0, _element.createElement)(_components.ComboboxControl, {
|
|
155
155
|
__nextHasNoMarginBottom: true,
|
|
156
|
+
__next40pxDefaultSize: true,
|
|
156
157
|
className: "editor-page-attributes__parent",
|
|
157
|
-
label:
|
|
158
|
+
label: (0, _i18n.__)('Parent'),
|
|
158
159
|
value: parentPostId,
|
|
159
160
|
options: parentOptions,
|
|
160
161
|
onFilterValueChange: (0, _compose.debounce)(handleKeydown, 300),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_removeAccents","_interopRequireDefault","_i18n","_components","_compose","_data","_htmlEntities","_coreData","_terms","_store","getTitle","post","title","rendered","decodeEntities","id","__","getItemPriority","name","searchValue","normalizedName","removeAccents","toLowerCase","normalizedSearch","startsWith","length","Infinity","exports","PageAttributesParent","editPost","useDispatch","editorStore","fieldValue","setFieldValue","useState","isHierarchical","parentPost","parentPostId","items","postType","useSelect","select","_pType$hierarchical","getPostType","getEntityRecords","getEntityRecord","coreStore","getCurrentPostId","getEditedPostAttribute","postTypeSlug","pageId","pType","postId","postIsHierarchical","hierarchical","query","per_page","exclude","parent_exclude","orderby","order","_fields","search","parentPageLabel","labels","parent_item_colon","pageItems","parentOptions","useMemo","getOptionsFromTree","tree","level","mappedNodes","map","treeNode","value","label","repeat","rawName","children","sortedNodes","sort","a","b","priorityA","priorityB","flat","item","parent","buildTermsTree","opts","optsHasParent","find","unshift","handleKeydown","inputValue","handleChange","selectedPostId","createElement","ComboboxControl","__nextHasNoMarginBottom","className","options","onFilterValueChange","debounce","onChange","_default","default"],"sources":["@wordpress/editor/src/components/page-attributes/parent.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { ComboboxControl } from '@wordpress/components';\nimport { debounce } from '@wordpress/compose';\nimport { useState, useMemo } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { buildTermsTree } from '../../utils/terms';\nimport { store as editorStore } from '../../store';\n\nfunction getTitle( post ) {\n\treturn post?.title?.rendered\n\t\t? decodeEntities( post.title.rendered )\n\t\t: `#${ post.id } (${ __( 'no title' ) })`;\n}\n\nexport const getItemPriority = ( name, searchValue ) => {\n\tconst normalizedName = removeAccents( name || '' ).toLowerCase();\n\tconst normalizedSearch = removeAccents( searchValue || '' ).toLowerCase();\n\tif ( normalizedName === normalizedSearch ) {\n\t\treturn 0;\n\t}\n\n\tif ( normalizedName.startsWith( normalizedSearch ) ) {\n\t\treturn normalizedName.length;\n\t}\n\n\treturn Infinity;\n};\n\nexport function PageAttributesParent() {\n\tconst { editPost } = useDispatch( editorStore );\n\tconst [ fieldValue, setFieldValue ] = useState( false );\n\tconst { isHierarchical, parentPost, parentPostId, items, postType } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getPostType, getEntityRecords, getEntityRecord } =\n\t\t\t\t\tselect( coreStore );\n\t\t\t\tconst { getCurrentPostId, getEditedPostAttribute } =\n\t\t\t\t\tselect( editorStore );\n\t\t\t\tconst postTypeSlug = getEditedPostAttribute( 'type' );\n\t\t\t\tconst pageId = getEditedPostAttribute( 'parent' );\n\t\t\t\tconst pType = getPostType( postTypeSlug );\n\t\t\t\tconst postId = getCurrentPostId();\n\t\t\t\tconst postIsHierarchical = pType?.hierarchical ?? false;\n\t\t\t\tconst query = {\n\t\t\t\t\tper_page: 100,\n\t\t\t\t\texclude: postId,\n\t\t\t\t\tparent_exclude: postId,\n\t\t\t\t\torderby: 'menu_order',\n\t\t\t\t\torder: 'asc',\n\t\t\t\t\t_fields: 'id,title,parent',\n\t\t\t\t};\n\n\t\t\t\t// Perform a search when the field is changed.\n\t\t\t\tif ( !! fieldValue ) {\n\t\t\t\t\tquery.search = fieldValue;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tisHierarchical: postIsHierarchical,\n\t\t\t\t\tparentPostId: pageId,\n\t\t\t\t\tparentPost: pageId\n\t\t\t\t\t\t? getEntityRecord( 'postType', postTypeSlug, pageId )\n\t\t\t\t\t\t: null,\n\t\t\t\t\titems: postIsHierarchical\n\t\t\t\t\t\t? getEntityRecords( 'postType', postTypeSlug, query )\n\t\t\t\t\t\t: [],\n\t\t\t\t\tpostType: pType,\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ fieldValue ]\n\t\t);\n\n\tconst parentPageLabel = postType?.labels?.parent_item_colon;\n\tconst pageItems = items || [];\n\n\tconst parentOptions = useMemo( () => {\n\t\tconst getOptionsFromTree = ( tree, level = 0 ) => {\n\t\t\tconst mappedNodes = tree.map( ( treeNode ) => [\n\t\t\t\t{\n\t\t\t\t\tvalue: treeNode.id,\n\t\t\t\t\tlabel:\n\t\t\t\t\t\t'— '.repeat( level ) + decodeEntities( treeNode.name ),\n\t\t\t\t\trawName: treeNode.name,\n\t\t\t\t},\n\t\t\t\t...getOptionsFromTree( treeNode.children || [], level + 1 ),\n\t\t\t] );\n\n\t\t\tconst sortedNodes = mappedNodes.sort( ( [ a ], [ b ] ) => {\n\t\t\t\tconst priorityA = getItemPriority( a.rawName, fieldValue );\n\t\t\t\tconst priorityB = getItemPriority( b.rawName, fieldValue );\n\t\t\t\treturn priorityA >= priorityB ? 1 : -1;\n\t\t\t} );\n\n\t\t\treturn sortedNodes.flat();\n\t\t};\n\n\t\tlet tree = pageItems.map( ( item ) => ( {\n\t\t\tid: item.id,\n\t\t\tparent: item.parent,\n\t\t\tname: getTitle( item ),\n\t\t} ) );\n\n\t\t// Only build a hierarchical tree when not searching.\n\t\tif ( ! fieldValue ) {\n\t\t\ttree = buildTermsTree( tree );\n\t\t}\n\n\t\tconst opts = getOptionsFromTree( tree );\n\n\t\t// Ensure the current parent is in the options list.\n\t\tconst optsHasParent = opts.find(\n\t\t\t( item ) => item.value === parentPostId\n\t\t);\n\t\tif ( parentPost && ! optsHasParent ) {\n\t\t\topts.unshift( {\n\t\t\t\tvalue: parentPostId,\n\t\t\t\tlabel: getTitle( parentPost ),\n\t\t\t} );\n\t\t}\n\t\treturn opts;\n\t}, [ pageItems, fieldValue ] );\n\n\tif ( ! isHierarchical || ! parentPageLabel ) {\n\t\treturn null;\n\t}\n\t/**\n\t * Handle user input.\n\t *\n\t * @param {string} inputValue The current value of the input field.\n\t */\n\tconst handleKeydown = ( inputValue ) => {\n\t\tsetFieldValue( inputValue );\n\t};\n\n\t/**\n\t * Handle author selection.\n\t *\n\t * @param {Object} selectedPostId The selected Author.\n\t */\n\tconst handleChange = ( selectedPostId ) => {\n\t\teditPost( { parent: selectedPostId } );\n\t};\n\n\treturn (\n\t\t<ComboboxControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\tclassName=\"editor-page-attributes__parent\"\n\t\t\tlabel={ parentPageLabel }\n\t\t\tvalue={ parentPostId }\n\t\t\toptions={ parentOptions }\n\t\t\tonFilterValueChange={ debounce( handleKeydown, 300 ) }\n\t\t\tonChange={ handleChange }\n\t\t/>\n\t);\n}\n\nexport default PageAttributesParent;\n"],"mappings":";;;;;;;;AAWA,IAAAA,QAAA,GAAAC,OAAA;AARA,IAAAC,cAAA,GAAAC,sBAAA,CAAAF,OAAA;AAKA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AAEA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,aAAA,GAAAP,OAAA;AACA,IAAAQ,SAAA,GAAAR,OAAA;AAKA,IAAAS,MAAA,GAAAT,OAAA;AACA,IAAAU,MAAA,GAAAV,OAAA;AApBA;AACA;AACA;;AAGA;AACA;AACA;;AASA;AACA;AACA;;AAIA,SAASW,QAAQA,CAAEC,IAAI,EAAG;EACzB,OAAOA,IAAI,EAAEC,KAAK,EAAEC,QAAQ,GACzB,IAAAC,4BAAc,EAAEH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B,CAAE,CAAC;IACJ;IACA,OAAOsD,IAAI;EACZ,CAAC,EAAE,CAAExB,SAAS,EAAElC,UAAU,CAAG,CAAC;EAE9B,IAAK,CAAEG,cAAc,IAAI,CAAE4B,eAAe,EAAG;IAC5C,OAAO,IAAI;EACZ;EACA;AACD;AACA;AACA;AACA;EACC,MAAM+B,aAAa,GAAKC,UAAU,IAAM;IACvC9D,aAAa,CAAE8D,UAAW,CAAC;EAC5B,CAAC;;EAED;AACD;AACA;AACA;AACA;EACC,MAAMC,YAAY,GAAKC,cAAc,IAAM;IAC1CpE,QAAQ,CAAE;MAAE2D,MAAM,EAAES;IAAe,CAAE,CAAC;EACvC,CAAC;EAED,OACC,IAAAnG,QAAA,CAAAoG,aAAA,EAAC/F,WAAA,CAAAgG,eAAe;IACfC,uBAAuB;IACvBC,SAAS,EAAC,gCAAgC;IAC1CzB,KAAK,EAAGb,eAAiB;IACzBY,KAAK,EAAGtC,YAAc;IACtBiE,OAAO,EAAGnC,aAAe;IACzBoC,mBAAmB,EAAG,IAAAC,iBAAQ,EAAEV,aAAa,EAAE,GAAI,CAAG;IACtDW,QAAQ,EAAGT;EAAc,CACzB,CAAC;AAEJ;AAAC,IAAAU,QAAA,GAEc9E,oBAAoB;AAAAD,OAAA,CAAAgF,OAAA,GAAAD,QAAA"}
|
|
1
|
+
{"version":3,"names":["_element","require","_removeAccents","_interopRequireDefault","_i18n","_components","_compose","_data","_htmlEntities","_coreData","_terms","_store","getTitle","post","title","rendered","decodeEntities","id","__","getItemPriority","name","searchValue","normalizedName","removeAccents","toLowerCase","normalizedSearch","startsWith","length","Infinity","exports","PageAttributesParent","editPost","useDispatch","editorStore","fieldValue","setFieldValue","useState","isHierarchical","parentPostId","parentPostTitle","pageItems","useSelect","select","_pType$hierarchical","getPostType","getEntityRecords","getEntityRecord","coreStore","getCurrentPostId","getEditedPostAttribute","postTypeSlug","pageId","pType","postId","postIsHierarchical","hierarchical","query","per_page","exclude","parent_exclude","orderby","order","_fields","search","parentPost","parentOptions","useMemo","getOptionsFromTree","tree","level","mappedNodes","map","treeNode","value","label","repeat","rawName","children","sortedNodes","sort","a","b","priorityA","priorityB","flat","item","parent","buildTermsTree","opts","optsHasParent","find","unshift","handleKeydown","inputValue","handleChange","selectedPostId","createElement","ComboboxControl","__nextHasNoMarginBottom","__next40pxDefaultSize","className","options","onFilterValueChange","debounce","onChange","_default","default"],"sources":["@wordpress/editor/src/components/page-attributes/parent.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { ComboboxControl } from '@wordpress/components';\nimport { debounce } from '@wordpress/compose';\nimport { useState, useMemo } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { buildTermsTree } from '../../utils/terms';\nimport { store as editorStore } from '../../store';\n\nfunction getTitle( post ) {\n\treturn post?.title?.rendered\n\t\t? decodeEntities( post.title.rendered )\n\t\t: `#${ post.id } (${ __( 'no title' ) })`;\n}\n\nexport const getItemPriority = ( name, searchValue ) => {\n\tconst normalizedName = removeAccents( name || '' ).toLowerCase();\n\tconst normalizedSearch = removeAccents( searchValue || '' ).toLowerCase();\n\tif ( normalizedName === normalizedSearch ) {\n\t\treturn 0;\n\t}\n\n\tif ( normalizedName.startsWith( normalizedSearch ) ) {\n\t\treturn normalizedName.length;\n\t}\n\n\treturn Infinity;\n};\n\nexport function PageAttributesParent() {\n\tconst { editPost } = useDispatch( editorStore );\n\tconst [ fieldValue, setFieldValue ] = useState( false );\n\tconst { isHierarchical, parentPostId, parentPostTitle, pageItems } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getPostType, getEntityRecords, getEntityRecord } =\n\t\t\t\t\tselect( coreStore );\n\t\t\t\tconst { getCurrentPostId, getEditedPostAttribute } =\n\t\t\t\t\tselect( editorStore );\n\t\t\t\tconst postTypeSlug = getEditedPostAttribute( 'type' );\n\t\t\t\tconst pageId = getEditedPostAttribute( 'parent' );\n\t\t\t\tconst pType = getPostType( postTypeSlug );\n\t\t\t\tconst postId = getCurrentPostId();\n\t\t\t\tconst postIsHierarchical = pType?.hierarchical ?? false;\n\t\t\t\tconst query = {\n\t\t\t\t\tper_page: 100,\n\t\t\t\t\texclude: postId,\n\t\t\t\t\tparent_exclude: postId,\n\t\t\t\t\torderby: 'menu_order',\n\t\t\t\t\torder: 'asc',\n\t\t\t\t\t_fields: 'id,title,parent',\n\t\t\t\t};\n\n\t\t\t\t// Perform a search when the field is changed.\n\t\t\t\tif ( !! fieldValue ) {\n\t\t\t\t\tquery.search = fieldValue;\n\t\t\t\t}\n\n\t\t\t\tconst parentPost = pageId\n\t\t\t\t\t? getEntityRecord( 'postType', postTypeSlug, pageId )\n\t\t\t\t\t: null;\n\n\t\t\t\treturn {\n\t\t\t\t\tisHierarchical: postIsHierarchical,\n\t\t\t\t\tparentPostId: pageId,\n\t\t\t\t\tparentPostTitle: parentPost ? getTitle( parentPost ) : '',\n\t\t\t\t\tpageItems: postIsHierarchical\n\t\t\t\t\t\t? getEntityRecords( 'postType', postTypeSlug, query )\n\t\t\t\t\t\t: null,\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ fieldValue ]\n\t\t);\n\n\tconst parentOptions = useMemo( () => {\n\t\tconst getOptionsFromTree = ( tree, level = 0 ) => {\n\t\t\tconst mappedNodes = tree.map( ( treeNode ) => [\n\t\t\t\t{\n\t\t\t\t\tvalue: treeNode.id,\n\t\t\t\t\tlabel:\n\t\t\t\t\t\t'— '.repeat( level ) + decodeEntities( treeNode.name ),\n\t\t\t\t\trawName: treeNode.name,\n\t\t\t\t},\n\t\t\t\t...getOptionsFromTree( treeNode.children || [], level + 1 ),\n\t\t\t] );\n\n\t\t\tconst sortedNodes = mappedNodes.sort( ( [ a ], [ b ] ) => {\n\t\t\t\tconst priorityA = getItemPriority( a.rawName, fieldValue );\n\t\t\t\tconst priorityB = getItemPriority( b.rawName, fieldValue );\n\t\t\t\treturn priorityA >= priorityB ? 1 : -1;\n\t\t\t} );\n\n\t\t\treturn sortedNodes.flat();\n\t\t};\n\n\t\tif ( ! pageItems ) {\n\t\t\treturn [];\n\t\t}\n\n\t\tlet tree = pageItems.map( ( item ) => ( {\n\t\t\tid: item.id,\n\t\t\tparent: item.parent,\n\t\t\tname: getTitle( item ),\n\t\t} ) );\n\n\t\t// Only build a hierarchical tree when not searching.\n\t\tif ( ! fieldValue ) {\n\t\t\ttree = buildTermsTree( tree );\n\t\t}\n\n\t\tconst opts = getOptionsFromTree( tree );\n\n\t\t// Ensure the current parent is in the options list.\n\t\tconst optsHasParent = opts.find(\n\t\t\t( item ) => item.value === parentPostId\n\t\t);\n\t\tif ( parentPostTitle && ! optsHasParent ) {\n\t\t\topts.unshift( {\n\t\t\t\tvalue: parentPostId,\n\t\t\t\tlabel: parentPostTitle,\n\t\t\t} );\n\t\t}\n\t\treturn opts;\n\t}, [ pageItems, fieldValue, parentPostTitle, parentPostId ] );\n\n\tif ( ! isHierarchical ) {\n\t\treturn null;\n\t}\n\t/**\n\t * Handle user input.\n\t *\n\t * @param {string} inputValue The current value of the input field.\n\t */\n\tconst handleKeydown = ( inputValue ) => {\n\t\tsetFieldValue( inputValue );\n\t};\n\n\t/**\n\t * Handle author selection.\n\t *\n\t * @param {Object} selectedPostId The selected Author.\n\t */\n\tconst handleChange = ( selectedPostId ) => {\n\t\teditPost( { parent: selectedPostId } );\n\t};\n\n\treturn (\n\t\t<ComboboxControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\t__next40pxDefaultSize\n\t\t\tclassName=\"editor-page-attributes__parent\"\n\t\t\tlabel={ __( 'Parent' ) }\n\t\t\tvalue={ parentPostId }\n\t\t\toptions={ parentOptions }\n\t\t\tonFilterValueChange={ debounce( handleKeydown, 300 ) }\n\t\t\tonChange={ handleChange }\n\t\t/>\n\t);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G;IACtDY,QAAQ,EAAGV;EAAc,CACzB,CAAC;AAEJ;AAAC,IAAAW,QAAA,GAEc3E,oBAAoB;AAAAD,OAAA,CAAA6E,OAAA,GAAAD,QAAA"}
|
|
@@ -104,6 +104,7 @@ function PostAuthorCombobox() {
|
|
|
104
104
|
}
|
|
105
105
|
return (0, _element.createElement)(_components.ComboboxControl, {
|
|
106
106
|
__nextHasNoMarginBottom: true,
|
|
107
|
+
__next40pxDefaultSize: true,
|
|
107
108
|
label: (0, _i18n.__)('Author'),
|
|
108
109
|
options: authorOptions,
|
|
109
110
|
value: authorId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_compose","_data","_i18n","_components","_htmlEntities","_coreData","_store","_constants","PostAuthorCombobox","fieldValue","setFieldValue","useState","authorId","isLoading","authors","postAuthor","useSelect","select","getUser","getUsers","isResolving","coreStore","getEditedPostAttribute","editorStore","author","context","query","AUTHORS_QUERY","search","editPost","useDispatch","authorOptions","useMemo","fetchedAuthors","map","value","id","label","decodeEntities","name","foundAuthor","findIndex","handleSelect","postAuthorId","handleKeydown","inputValue","createElement","ComboboxControl","__nextHasNoMarginBottom","__","options","onFilterValueChange","debounce","onChange","allowReset","_default","exports","default"],"sources":["@wordpress/editor/src/components/post-author/combobox.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { debounce } from '@wordpress/compose';\nimport { useState, useMemo } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ComboboxControl } from '@wordpress/components';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { AUTHORS_QUERY } from './constants';\n\nfunction PostAuthorCombobox() {\n\tconst [ fieldValue, setFieldValue ] = useState();\n\n\tconst { authorId, isLoading, authors, postAuthor } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getUser, getUsers, isResolving } = select( coreStore );\n\t\t\tconst { getEditedPostAttribute } = select( editorStore );\n\t\t\tconst author = getUser( getEditedPostAttribute( 'author' ), {\n\t\t\t\tcontext: 'view',\n\t\t\t} );\n\t\t\tconst query = { ...AUTHORS_QUERY };\n\n\t\t\tif ( fieldValue ) {\n\t\t\t\tquery.search = fieldValue;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tauthorId: getEditedPostAttribute( 'author' ),\n\t\t\t\tpostAuthor: author,\n\t\t\t\tauthors: getUsers( query ),\n\t\t\t\tisLoading: isResolving( 'core', 'getUsers', [ query ] ),\n\t\t\t};\n\t\t},\n\t\t[ fieldValue ]\n\t);\n\tconst { editPost } = useDispatch( editorStore );\n\n\tconst authorOptions = useMemo( () => {\n\t\tconst fetchedAuthors = ( authors ?? [] ).map( ( author ) => {\n\t\t\treturn {\n\t\t\t\tvalue: author.id,\n\t\t\t\tlabel: decodeEntities( author.name ),\n\t\t\t};\n\t\t} );\n\n\t\t// Ensure the current author is included in the dropdown list.\n\t\tconst foundAuthor = fetchedAuthors.findIndex(\n\t\t\t( { value } ) => postAuthor?.id === value\n\t\t);\n\n\t\tif ( foundAuthor < 0 && postAuthor ) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tvalue: postAuthor.id,\n\t\t\t\t\tlabel: decodeEntities( postAuthor.name ),\n\t\t\t\t},\n\t\t\t\t...fetchedAuthors,\n\t\t\t];\n\t\t}\n\n\t\treturn fetchedAuthors;\n\t}, [ authors, postAuthor ] );\n\n\t/**\n\t * Handle author selection.\n\t *\n\t * @param {number} postAuthorId The selected Author.\n\t */\n\tconst handleSelect = ( postAuthorId ) => {\n\t\tif ( ! postAuthorId ) {\n\t\t\treturn;\n\t\t}\n\t\teditPost( { author: postAuthorId } );\n\t};\n\n\t/**\n\t * Handle user input.\n\t *\n\t * @param {string} inputValue The current value of the input field.\n\t */\n\tconst handleKeydown = ( inputValue ) => {\n\t\tsetFieldValue( inputValue );\n\t};\n\n\tif ( ! postAuthor ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<ComboboxControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\tlabel={ __( 'Author' ) }\n\t\t\toptions={ authorOptions }\n\t\t\tvalue={ authorId }\n\t\t\tonFilterValueChange={ debounce( handleKeydown, 300 ) }\n\t\t\tonChange={ handleSelect }\n\t\t\tisLoading={ isLoading }\n\t\t\tallowReset={ false }\n\t\t/>\n\t);\n}\n\nexport default PostAuthorCombobox;\n"],"mappings":";;;;;;AAIA,IAAAA,QAAA,GAAAC,OAAA;AADA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,UAAA,GAAAR,OAAA;AAfA;AACA;AACA;;AASA;AACA;AACA;;AAIA,SAASS,kBAAkBA,CAAA,EAAG;EAC7B,MAAM,CAAEC,UAAU,EAAEC,aAAa,CAAE,GAAG,IAAAC,iBAAQ,EAAC,CAAC;EAEhD,MAAM;IAAEC,QAAQ;IAAEC,SAAS;IAAEC,OAAO;IAAEC;EAAW,CAAC,GAAG,IAAAC,eAAS,EAC3DC,MAAM,IAAM;IACb,MAAM;MAAEC,OAAO;MAAEC,QAAQ;MAAEC;IAAY,CAAC,GAAGH,MAAM,CAAEI,eAAU,CAAC;IAC9D,MAAM;MAAEC;IAAuB,CAAC,GAAGL,MAAM,CAAEM,YAAY,CAAC;IACxD,MAAMC,MAAM,GAAGN,OAAO,CAAEI,sBAAsB,CAAE,QAAS,CAAC,EAAE;MAC3DG,OAAO,EAAE;IACV,CAAE,CAAC;IACH,MAAMC,KAAK,GAAG;MAAE,GAAGC;IAAc,CAAC;IAElC,IAAKlB,UAAU,EAAG;MACjBiB,KAAK,CAACE,MAAM,GAA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CAAE,CAAC;EACrC,CAAC;;EAED;AACD;AACA;AACA;AACA;EACC,MAAMC,aAAa,GAAKC,UAAU,IAAM;IACvCnC,aAAa,CAAEmC,UAAW,CAAC;EAC5B,CAAC;EAED,IAAK,CAAE9B,UAAU,EAAG;IACnB,OAAO,IAAI;EACZ;EAEA,OACC,IAAAjB,QAAA,CAAAgD,aAAA,EAAC3C,WAAA,CAAA4C,eAAe;IACfC,uBAAuB;
|
|
1
|
+
{"version":3,"names":["_element","require","_compose","_data","_i18n","_components","_htmlEntities","_coreData","_store","_constants","PostAuthorCombobox","fieldValue","setFieldValue","useState","authorId","isLoading","authors","postAuthor","useSelect","select","getUser","getUsers","isResolving","coreStore","getEditedPostAttribute","editorStore","author","context","query","AUTHORS_QUERY","search","editPost","useDispatch","authorOptions","useMemo","fetchedAuthors","map","value","id","label","decodeEntities","name","foundAuthor","findIndex","handleSelect","postAuthorId","handleKeydown","inputValue","createElement","ComboboxControl","__nextHasNoMarginBottom","__next40pxDefaultSize","__","options","onFilterValueChange","debounce","onChange","allowReset","_default","exports","default"],"sources":["@wordpress/editor/src/components/post-author/combobox.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { debounce } from '@wordpress/compose';\nimport { useState, useMemo } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ComboboxControl } from '@wordpress/components';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { AUTHORS_QUERY } from './constants';\n\nfunction PostAuthorCombobox() {\n\tconst [ fieldValue, setFieldValue ] = useState();\n\n\tconst { authorId, isLoading, authors, postAuthor } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getUser, getUsers, isResolving } = select( coreStore );\n\t\t\tconst { getEditedPostAttribute } = select( editorStore );\n\t\t\tconst author = getUser( getEditedPostAttribute( 'author' ), {\n\t\t\t\tcontext: 'view',\n\t\t\t} );\n\t\t\tconst query = { ...AUTHORS_QUERY };\n\n\t\t\tif ( fieldValue ) {\n\t\t\t\tquery.search = fieldValue;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tauthorId: getEditedPostAttribute( 'author' ),\n\t\t\t\tpostAuthor: author,\n\t\t\t\tauthors: getUsers( query ),\n\t\t\t\tisLoading: isResolving( 'core', 'getUsers', [ query ] ),\n\t\t\t};\n\t\t},\n\t\t[ fieldValue ]\n\t);\n\tconst { editPost } = useDispatch( editorStore );\n\n\tconst authorOptions = useMemo( () => {\n\t\tconst fetchedAuthors = ( authors ?? [] ).map( ( author ) => {\n\t\t\treturn {\n\t\t\t\tvalue: author.id,\n\t\t\t\tlabel: decodeEntities( author.name ),\n\t\t\t};\n\t\t} );\n\n\t\t// Ensure the current author is included in the dropdown list.\n\t\tconst foundAuthor = fetchedAuthors.findIndex(\n\t\t\t( { value } ) => postAuthor?.id === value\n\t\t);\n\n\t\tif ( foundAuthor < 0 && postAuthor ) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tvalue: postAuthor.id,\n\t\t\t\t\tlabel: decodeEntities( postAuthor.name ),\n\t\t\t\t},\n\t\t\t\t...fetchedAuthors,\n\t\t\t];\n\t\t}\n\n\t\treturn fetchedAuthors;\n\t}, [ authors, postAuthor ] );\n\n\t/**\n\t * Handle author selection.\n\t *\n\t * @param {number} postAuthorId The selected Author.\n\t */\n\tconst handleSelect = ( postAuthorId ) => {\n\t\tif ( ! postAuthorId ) {\n\t\t\treturn;\n\t\t}\n\t\teditPost( { author: postAuthorId } );\n\t};\n\n\t/**\n\t * Handle user input.\n\t *\n\t * @param {string} inputValue The current value of the input field.\n\t */\n\tconst handleKeydown = ( inputValue ) => {\n\t\tsetFieldValue( inputValue );\n\t};\n\n\tif ( ! postAuthor ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<ComboboxControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\t__next40pxDefaultSize\n\t\t\tlabel={ __( 'Author' ) }\n\t\t\toptions={ authorOptions }\n\t\t\tvalue={ authorId }\n\t\t\tonFilterValueChange={ debounce( handleKeydown, 300 ) }\n\t\t\tonChange={ handleSelect }\n\t\t\tisLoading={ isLoading }\n\t\t\tallowReset={ false }\n\t\t/>\n\t);\n}\n\nexport default PostAuthorCombobox;\n"],"mappings":";;;;;;AAIA,IAAAA,QAAA,GAAAC,OAAA;AADA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,UAAA,GAAAR,OAAA;AAfA;AACA;AACA;;AASA;AACA;AACA;;AAIA,SAASS,kBAAkBA,CAAA,EAAG;EAC7B,MAAM,CAAEC,UAAU,EAAEC,aAAa,CAAE,GAAG,IAAAC,iBAAQ,EAAC,CAAC;EAEhD,MAAM;IAAEC,QAAQ;IAAEC,SAAS;IAAEC,OAAO;IAAEC;EAAW,CAAC,GAAG,IAAAC,eAAS,EAC3DC,MAAM,IAAM;IACb,MAAM;MAAEC,OAAO;MAAEC,QAAQ;MAAEC;IAAY,CAAC,GAAGH,MAAM,CAAEI,eAAU,CAAC;IAC9D,MAAM;MAAEC;IAAuB,CAAC,GAAGL,MAAM,CAAEM,YAAY,CAAC;IACxD,MAAMC,MAAM,GAAGN,OAAO,CAAEI,sBAAsB,CAAE,QAAS,CAAC,EAAE;MAC3DG,OAAO,EAAE;IACV,CAAE,CAAC;IACH,MAAMC,KAAK,GAAG;MAAE,GAAGC;IAAc,CAAC;IAElC,IAAKlB,UAAU,EAAG;MACjBiB,KAAK,CAACE,MAAM,GAAGnB,UAAU;IAC1B;IAEA,OAAO;MACNG,QAAQ,EAAEU,sBAAsB,CAAE,QAAS,CAAC;M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U,IAAM;IACvCnC,aAAa,CAAEmC,UAAW,CAAC;EAC5B,CAAC;EAED,IAAK,CAAE9B,UAAU,EAAG;IACnB,OAAO,IAAI;EACZ;EAEA,OACC,IAAAjB,QAAA,CAAAgD,aAAA,EAAC3C,WAAA,CAAA4C,eAAe;IACfC,uBAAuB;IACvBC,qBAAqB;IACrBZ,KAAK,EAAG,IAAAa,QAAE,EAAE,QAAS,CAAG;IACxBC,OAAO,EAAGpB,aAAe;IACzBI,KAAK,EAAGvB,QAAU;IAClBwC,mBAAmB,EAAG,IAAAC,iBAAQ,EAAET,aAAa,EAAE,GAAI,CAAG;IACtDU,QAAQ,EAAGZ,YAAc;IACzB7B,SAAS,EAAGA,SAAW;IACvB0C,UAAU,EAAG;EAAO,CACpB,CAAC;AAEJ;AAAC,IAAAC,QAAA,GAEchD,kBAAkB;AAAAiD,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -37,8 +37,7 @@ function LastRevision() {
|
|
|
37
37
|
}, []);
|
|
38
38
|
return (0, _element.createElement)(_check.default, null, (0, _element.createElement)(_components.Button, {
|
|
39
39
|
href: (0, _url.addQueryArgs)('revision.php', {
|
|
40
|
-
revision: lastRevisionId
|
|
41
|
-
gutenberg: true
|
|
40
|
+
revision: lastRevisionId
|
|
42
41
|
}),
|
|
43
42
|
className: "editor-post-last-revision__title",
|
|
44
43
|
icon: _icons.backup
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_components","_data","_icons","_url","_check","_interopRequireDefault","_store","LastRevision","lastRevisionId","revisionsCount","useSelect","select","getCurrentPostLastRevisionId","getCurrentPostRevisionsCount","editorStore","_element","createElement","default","Button","href","addQueryArgs","revision","
|
|
1
|
+
{"version":3,"names":["_i18n","require","_components","_data","_icons","_url","_check","_interopRequireDefault","_store","LastRevision","lastRevisionId","revisionsCount","useSelect","select","getCurrentPostLastRevisionId","getCurrentPostRevisionsCount","editorStore","_element","createElement","default","Button","href","addQueryArgs","revision","className","icon","backup","sprintf","_n","_default","exports"],"sources":["@wordpress/editor/src/components/post-last-revision/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { sprintf, _n } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { backup } from '@wordpress/icons';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport PostLastRevisionCheck from './check';\nimport { store as editorStore } from '../../store';\n\nfunction LastRevision() {\n\tconst { lastRevisionId, revisionsCount } = useSelect( ( select ) => {\n\t\tconst { getCurrentPostLastRevisionId, getCurrentPostRevisionsCount } =\n\t\t\tselect( editorStore );\n\t\treturn {\n\t\t\tlastRevisionId: getCurrentPostLastRevisionId(),\n\t\t\trevisionsCount: getCurrentPostRevisionsCount(),\n\t\t};\n\t}, [] );\n\n\treturn (\n\t\t<PostLastRevisionCheck>\n\t\t\t<Button\n\t\t\t\thref={ addQueryArgs( 'revision.php', {\n\t\t\t\t\trevision: lastRevisionId,\n\t\t\t\t} ) }\n\t\t\t\tclassName=\"editor-post-last-revision__title\"\n\t\t\t\ticon={ backup }\n\t\t\t>\n\t\t\t\t{ sprintf(\n\t\t\t\t\t/* translators: %d: number of revisions */\n\t\t\t\t\t_n( '%d Revision', '%d Revisions', revisionsCount ),\n\t\t\t\t\trevisionsCount\n\t\t\t\t) }\n\t\t\t</Button>\n\t\t</PostLastRevisionCheck>\n\t);\n}\n\nexport default LastRevision;\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAC,sBAAA,CAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAbA;AACA;AACA;;AAOA;AACA;AACA;;AAIA,SAASQ,YAAYA,CAAA,EAAG;EACvB,MAAM;IAAEC,cAAc;IAAEC;EAAe,CAAC,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IACnE,MAAM;MAAEC,4BAA4B;MAAEC;IAA6B,CAAC,GACnEF,MAAM,CAAEG,YAAY,CAAC;IACtB,OAAO;MACNN,cAAc,EAAEI,4BAA4B,CAAC,CAAC;MAC9CH,cAAc,EAAEI,4BAA4B,CAAC;IAC9C,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,OACC,IAAAE,QAAA,CAAAC,aAAA,EAACZ,MAAA,CAAAa,OAAqB,QACrB,IAAAF,QAAA,CAAAC,aAAA,EAAChB,WAAA,CAAAkB,MAAM;IACNC,IAAI,EAAG,IAAAC,iBAAY,EAAE,cAAc,EAAE;MACpCC,QAAQ,EAAEb;IACX,CAAE,CAAG;IACLc,SAAS,EAAC,kCAAkC;IAC5CC,IAAI,EAAGC;EAAQ,GAEb,IAAAC,aAAO,GACR;EACA,IAAAC,QAAE,EAAE,aAAa,EAAE,cAAc,EAAEjB,cAAe,CAAC,EACnDA,cACD,CACO,CACc,CAAC;AAE1B;AAAC,IAAAkB,QAAA,GAEcpB,YAAY;AAAAqB,OAAA,CAAAX,OAAA,GAAAU,QAAA"}
|
|
@@ -20,29 +20,32 @@ var _lockUnlock = require("../../lock-unlock");
|
|
|
20
20
|
* Internal dependencies
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
+
const {
|
|
24
|
+
ReusableBlocksRenameHint
|
|
25
|
+
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
23
26
|
function PostSyncStatus() {
|
|
24
27
|
const {
|
|
25
28
|
syncStatus,
|
|
26
|
-
postType
|
|
27
|
-
meta
|
|
29
|
+
postType
|
|
28
30
|
} = (0, _data.useSelect)(select => {
|
|
29
31
|
const {
|
|
30
32
|
getEditedPostAttribute
|
|
31
33
|
} = select(_store.store);
|
|
34
|
+
const meta = getEditedPostAttribute('meta');
|
|
35
|
+
|
|
36
|
+
// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead.
|
|
37
|
+
const currentSyncStatus = meta?.wp_pattern_sync_status === 'unsynced' ? 'unsynced' : getEditedPostAttribute('wp_pattern_sync_status');
|
|
32
38
|
return {
|
|
33
|
-
syncStatus:
|
|
34
|
-
meta: getEditedPostAttribute('meta'),
|
|
39
|
+
syncStatus: currentSyncStatus,
|
|
35
40
|
postType: getEditedPostAttribute('type')
|
|
36
41
|
};
|
|
37
42
|
});
|
|
38
43
|
if (postType !== 'wp_block') {
|
|
39
44
|
return null;
|
|
40
45
|
}
|
|
41
|
-
// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead.
|
|
42
|
-
const currentSyncStatus = meta?.wp_pattern_sync_status === 'unsynced' ? 'unsynced' : syncStatus;
|
|
43
46
|
return (0, _element.createElement)(_components.PanelRow, {
|
|
44
47
|
className: "edit-post-sync-status"
|
|
45
|
-
}, (0, _element.createElement)("span", null, (0, _i18n.__)('Sync status')), (0, _element.createElement)("div", null,
|
|
48
|
+
}, (0, _element.createElement)("span", null, (0, _i18n.__)('Sync status')), (0, _element.createElement)("div", null, syncStatus === 'unsynced' ? (0, _i18n.__)('Not synced') : (0, _i18n.__)('Fully synced')));
|
|
46
49
|
}
|
|
47
50
|
function PostSyncStatusModal() {
|
|
48
51
|
const {
|
|
@@ -80,9 +83,6 @@ function PostSyncStatusModal() {
|
|
|
80
83
|
if (postType !== 'wp_block' || !isNewPost) {
|
|
81
84
|
return null;
|
|
82
85
|
}
|
|
83
|
-
const {
|
|
84
|
-
ReusableBlocksRenameHint
|
|
85
|
-
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
86
86
|
return (0, _element.createElement)(_element.Fragment, null, isModalOpen && (0, _element.createElement)(_components.Modal, {
|
|
87
87
|
title: (0, _i18n.__)('Set pattern sync status'),
|
|
88
88
|
onRequestClose: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_data","_i18n","_components","_blockEditor","_store","_lockUnlock","PostSyncStatus","syncStatus","postType","
|
|
1
|
+
{"version":3,"names":["_element","require","_data","_i18n","_components","_blockEditor","_store","_lockUnlock","ReusableBlocksRenameHint","unlock","blockEditorPrivateApis","PostSyncStatus","syncStatus","postType","useSelect","select","getEditedPostAttribute","editorStore","meta","currentSyncStatus","wp_pattern_sync_status","createElement","PanelRow","className","__","PostSyncStatusModal","editPost","useDispatch","isModalOpen","setIsModalOpen","useState","syncType","setSyncType","undefined","isNewPost","isCleanNewPost","useEffect","setSyncStatus","Fragment","Modal","title","onRequestClose","overlayClassName","onSubmit","event","preventDefault","__experimentalVStack","spacing","ToggleControl","label","help","checked","onChange","__experimentalHStack","justify","Button","variant","type"],"sources":["@wordpress/editor/src/components/post-sync-status/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tPanelRow,\n\tModal,\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { useEffect, useState } from '@wordpress/element';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { ReusableBlocksRenameHint } = unlock( blockEditorPrivateApis );\n\nexport default function PostSyncStatus() {\n\tconst { syncStatus, postType } = useSelect( ( select ) => {\n\t\tconst { getEditedPostAttribute } = select( editorStore );\n\t\tconst meta = getEditedPostAttribute( 'meta' );\n\n\t\t// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead.\n\t\tconst currentSyncStatus =\n\t\t\tmeta?.wp_pattern_sync_status === 'unsynced'\n\t\t\t\t? 'unsynced'\n\t\t\t\t: getEditedPostAttribute( 'wp_pattern_sync_status' );\n\n\t\treturn {\n\t\t\tsyncStatus: currentSyncStatus,\n\t\t\tpostType: getEditedPostAttribute( 'type' ),\n\t\t};\n\t} );\n\n\tif ( postType !== 'wp_block' ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PanelRow className=\"edit-post-sync-status\">\n\t\t\t<span>{ __( 'Sync status' ) }</span>\n\t\t\t<div>\n\t\t\t\t{ syncStatus === 'unsynced'\n\t\t\t\t\t? __( 'Not synced' )\n\t\t\t\t\t: __( 'Fully synced' ) }\n\t\t\t</div>\n\t\t</PanelRow>\n\t);\n}\n\nexport function PostSyncStatusModal() {\n\tconst { editPost } = useDispatch( editorStore );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ syncType, setSyncType ] = useState( undefined );\n\n\tconst { postType, isNewPost } = useSelect( ( select ) => {\n\t\tconst { getEditedPostAttribute, isCleanNewPost } =\n\t\t\tselect( editorStore );\n\t\treturn {\n\t\t\tpostType: getEditedPostAttribute( 'type' ),\n\t\t\tisNewPost: isCleanNewPost(),\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( isNewPost && postType === 'wp_block' ) {\n\t\t\tsetIsModalOpen( true );\n\t\t}\n\t\t// We only want the modal to open when the page is first loaded.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [] );\n\n\tconst setSyncStatus = () => {\n\t\teditPost( {\n\t\t\tmeta: {\n\t\t\t\twp_pattern_sync_status: syncType,\n\t\t\t},\n\t\t} );\n\t};\n\n\tif ( postType !== 'wp_block' || ! isNewPost ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Set pattern sync status' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"reusable-blocks-menu-items__convert-modal\"\n\t\t\t\t>\n\t\t\t\t\t<form\n\t\t\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\tsetSyncStatus();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t\t\t<ReusableBlocksRenameHint />\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tlabel={ __( 'Synced' ) }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Editing the pattern will update it anywhere it is used.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tchecked={ ! syncType }\n\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\t\t\t! syncType ? 'unsynced' : undefined\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t\t\t<Button variant=\"primary\" type=\"submit\">\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</HStack>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;AAaA,IAAAA,QAAA,GAAAC,OAAA;AAVA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AASA,IAAAI,YAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AApBA;AACA;AACA;;AAcA;AACA;AACA;;AAIA,MAAM;EAAEO;AAAyB,CAAC,GAAG,IAAAC,kBAAM,EAAEC,wBAAuB,CAAC;AAEtD,SAASC,cAAcA,CAAA,EAAG;EACxC,MAAM;IAAEC,UAAU;IAAEC;EAAS,CAAC,GA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E,EAAE,QAAS,CAAG;IACxB0B,IAAI,EAAG,IAAA1B,QAAE,EACR,yDACD,CAAG;IACH2B,OAAO,EAAG,CAAEpB,QAAU;IACtBqB,QAAQ,EAAGA,CAAA,KAAM;MAChBpB,WAAW,CACV,CAAED,QAAQ,GAAG,UAAU,GAAGE,SAC3B,CAAC;IACF;EAAG,CACH,CAAC,EACF,IAAAjC,QAAA,CAAAqB,aAAA,EAACjB,WAAA,CAAAiD,oBAAM;IAACC,OAAO,EAAC;EAAO,GACtB,IAAAtD,QAAA,CAAAqB,aAAA,EAACjB,WAAA,CAAAmD,MAAM;IAACC,OAAO,EAAC,SAAS;IAACC,IAAI,EAAC;EAAQ,GACpC,IAAAjC,QAAE,EAAE,QAAS,CACR,CACD,CACD,CACH,CACA,CAEP,CAAC;AAEL"}
|
|
@@ -13,6 +13,7 @@ var _data = require("@wordpress/data");
|
|
|
13
13
|
var _coreData = require("@wordpress/core-data");
|
|
14
14
|
var _compose = require("@wordpress/compose");
|
|
15
15
|
var _a11y = require("@wordpress/a11y");
|
|
16
|
+
var _notices = require("@wordpress/notices");
|
|
16
17
|
var _store = require("../../store");
|
|
17
18
|
var _terms = require("../../utils/terms");
|
|
18
19
|
var _mostUsedTerms = _interopRequireDefault(require("./most-used-terms"));
|
|
@@ -119,6 +120,9 @@ function FlatTermSelector({
|
|
|
119
120
|
const {
|
|
120
121
|
saveEntityRecord
|
|
121
122
|
} = (0, _data.useDispatch)(_coreData.store);
|
|
123
|
+
const {
|
|
124
|
+
createErrorNotice
|
|
125
|
+
} = (0, _data.useDispatch)(_notices.store);
|
|
122
126
|
if (!hasAssignAction) {
|
|
123
127
|
return null;
|
|
124
128
|
}
|
|
@@ -167,6 +171,10 @@ function FlatTermSelector({
|
|
|
167
171
|
}))).then(newTerms => {
|
|
168
172
|
const newAvailableTerms = availableTerms.concat(newTerms);
|
|
169
173
|
return onUpdateTerms(termNamesToIds(uniqueTerms, newAvailableTerms));
|
|
174
|
+
}).catch(error => {
|
|
175
|
+
createErrorNotice(error.message, {
|
|
176
|
+
type: 'snackbar'
|
|
177
|
+
});
|
|
170
178
|
});
|
|
171
179
|
}
|
|
172
180
|
function appendTerm(newTerm) {
|
|
@@ -190,6 +198,7 @@ function FlatTermSelector({
|
|
|
190
198
|
const removeTermLabel = (0, _i18n.sprintf)( /* translators: %s: term name. */
|
|
191
199
|
(0, _i18n._x)('Remove %s', 'term'), singularName);
|
|
192
200
|
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.FormTokenField, {
|
|
201
|
+
__next40pxDefaultSize: true,
|
|
193
202
|
value: values,
|
|
194
203
|
suggestions: suggestions,
|
|
195
204
|
onChange: onChange,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_i18n","_components","_data","_coreData","_compose","_a11y","_store","_terms","_mostUsedTerms","_interopRequireDefault","EMPTY_ARRAY","MAX_TERMS_SUGGESTIONS","DEFAULT_QUERY","per_page","_fields","context","isSameTermName","termA","termB","unescapeString","toLowerCase","termNamesToIds","names","terms","map","termName","find","term","name","id","FlatTermSelector","slug","_taxonomy$labels$add_","_taxonomy$labels$sing2","values","setValues","useState","search","setSearch","debouncedSearch","useDebounce","termIds","taxonomy","hasAssignAction","hasCreateAction","hasResolvedTerms","useSelect","select","_post$_links","_post$_links2","getCurrentPost","getEditedPostAttribute","editorStore","getEntityRecords","getTaxonomy","hasFinishedResolution","coreStore","post","_taxonomy","_termIds","rest_base","query","include","join","_links","length","searchResults","useEffect","newValues","suggestions","useMemo","editPost","useDispatch","saveEntityRecord","findOrCreateTerm","newTerm","throwOnError","unescapeTerm","error","code","data","term_id","onUpdateTerms","newTermIds","onChange","termNames","availableTerms","uniqueTerms","reduce","acc","some","n","push","newTermNames","filter","Promise","all","then","newTerms","newAvailableTerms","concat","appendTerm","_taxonomy$labels$sing","includes","defaultName","__","termAddedMessage","sprintf","_x","labels","singular_name","speak","newTermLabel","add_new_item","singularName","termAddedLabel","termRemovedLabel","removeTermLabel","createElement","Fragment","FormTokenField","value","onInputChange","maxSuggestions","label","messages","added","removed","remove","default","onSelect","_default","withFilters","exports"],"sources":["@wordpress/editor/src/components/post-taxonomies/flat-term-selector.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { useEffect, useMemo, useState } from '@wordpress/element';\nimport { FormTokenField, withFilters } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDebounce } from '@wordpress/compose';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { unescapeString, unescapeTerm } from '../../utils/terms';\nimport MostUsedTerms from './most-used-terms';\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation.\n *\n * @type {Array<any>}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Module constants\n */\nconst MAX_TERMS_SUGGESTIONS = 20;\nconst DEFAULT_QUERY = {\n\tper_page: MAX_TERMS_SUGGESTIONS,\n\t_fields: 'id,name',\n\tcontext: 'view',\n};\n\nconst isSameTermName = ( termA, termB ) =>\n\tunescapeString( termA ).toLowerCase() ===\n\tunescapeString( termB ).toLowerCase();\n\nconst termNamesToIds = ( names, terms ) => {\n\treturn names.map(\n\t\t( termName ) =>\n\t\t\tterms.find( ( term ) => isSameTermName( term.name, termName ) ).id\n\t);\n};\n\nexport function FlatTermSelector( { slug } ) {\n\tconst [ values, setValues ] = useState( [] );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 500 );\n\n\tconst {\n\t\tterms,\n\t\ttermIds,\n\t\ttaxonomy,\n\t\thasAssignAction,\n\t\thasCreateAction,\n\t\thasResolvedTerms,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentPost, getEditedPostAttribute } =\n\t\t\t\tselect( editorStore );\n\t\t\tconst { getEntityRecords, getTaxonomy, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst post = getCurrentPost();\n\t\t\tconst _taxonomy = getTaxonomy( slug );\n\t\t\tconst _termIds = _taxonomy\n\t\t\t\t? getEditedPostAttribute( _taxonomy.rest_base )\n\t\t\t\t: EMPTY_ARRAY;\n\n\t\t\tconst query = {\n\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\tinclude: _termIds.join( ',' ),\n\t\t\t\tper_page: -1,\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\thasCreateAction: _taxonomy\n\t\t\t\t\t? post._links?.[\n\t\t\t\t\t\t\t'wp:action-create-' + _taxonomy.rest_base\n\t\t\t\t\t ] ?? false\n\t\t\t\t\t: false,\n\t\t\t\thasAssignAction: _taxonomy\n\t\t\t\t\t? post._links?.[\n\t\t\t\t\t\t\t'wp:action-assign-' + _taxonomy.rest_base\n\t\t\t\t\t ] ?? false\n\t\t\t\t\t: false,\n\t\t\t\ttaxonomy: _taxonomy,\n\t\t\t\ttermIds: _termIds,\n\t\t\t\tterms: _termIds.length\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, query )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t\thasResolvedTerms: hasFinishedResolution( 'getEntityRecords', [\n\t\t\t\t\t'taxonomy',\n\t\t\t\t\tslug,\n\t\t\t\t\tquery,\n\t\t\t\t] ),\n\t\t\t};\n\t\t},\n\t\t[ slug ]\n\t);\n\n\tconst { searchResults } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\n\t\t\treturn {\n\t\t\t\tsearchResults: !! search\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, {\n\t\t\t\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\t\t\t\tsearch,\n\t\t\t\t\t } )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t};\n\t\t},\n\t\t[ search, slug ]\n\t);\n\n\t// Update terms state only after the selectors are resolved.\n\t// We're using this to avoid terms temporarily disappearing on slow networks\n\t// while core data makes REST API requests.\n\tuseEffect( () => {\n\t\tif ( hasResolvedTerms ) {\n\t\t\tconst newValues = ( terms ?? [] ).map( ( term ) =>\n\t\t\t\tunescapeString( term.name )\n\t\t\t);\n\n\t\t\tsetValues( newValues );\n\t\t}\n\t}, [ terms, hasResolvedTerms ] );\n\n\tconst suggestions = useMemo( () => {\n\t\treturn ( searchResults ?? [] ).map( ( term ) =>\n\t\t\tunescapeString( term.name )\n\t\t);\n\t}, [ searchResults ] );\n\n\tconst { editPost } = useDispatch( editorStore );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\n\tif ( ! hasAssignAction ) {\n\t\treturn null;\n\t}\n\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\tconst newTerm = await saveEntityRecord( 'taxonomy', slug, term, {\n\t\t\t\tthrowOnError: true,\n\t\t\t} );\n\t\t\treturn unescapeTerm( newTerm );\n\t\t} catch ( error ) {\n\t\t\tif ( error.code !== 'term_exists' ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tid: error.data.term_id,\n\t\t\t\tname: term.name,\n\t\t\t};\n\t\t}\n\t}\n\n\tfunction onUpdateTerms( newTermIds ) {\n\t\teditPost( { [ taxonomy.rest_base ]: newTermIds } );\n\t}\n\n\tfunction onChange( termNames ) {\n\t\tconst availableTerms = [\n\t\t\t...( terms ?? [] ),\n\t\t\t...( searchResults ?? [] ),\n\t\t];\n\t\tconst uniqueTerms = termNames.reduce( ( acc, name ) => {\n\t\t\tif (\n\t\t\t\t! acc.some( ( n ) => n.toLowerCase() === name.toLowerCase() )\n\t\t\t) {\n\t\t\t\tacc.push( name );\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, [] );\n\n\t\tconst newTermNames = uniqueTerms.filter(\n\t\t\t( termName ) =>\n\t\t\t\t! availableTerms.find( ( term ) =>\n\t\t\t\t\tisSameTermName( term.name, termName )\n\t\t\t\t)\n\t\t);\n\n\t\t// Optimistically update term values.\n\t\t// The selector will always re-fetch terms later.\n\t\tsetValues( uniqueTerms );\n\n\t\tif ( newTermNames.length === 0 ) {\n\t\t\treturn onUpdateTerms(\n\t\t\t\ttermNamesToIds( uniqueTerms, availableTerms )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! hasCreateAction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tPromise.all(\n\t\t\tnewTermNames.map( ( termName ) =>\n\t\t\t\tfindOrCreateTerm( { name: termName } )\n\t\t\t)\n\t\t).then( ( newTerms ) => {\n\t\t\tconst newAvailableTerms = availableTerms.concat( newTerms );\n\t\t\treturn onUpdateTerms(\n\t\t\t\ttermNamesToIds( uniqueTerms, newAvailableTerms )\n\t\t\t);\n\t\t} );\n\t}\n\n\tfunction appendTerm( newTerm ) {\n\t\tif ( termIds.includes( newTerm.id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newTermIds = [ ...termIds, newTerm.id ];\n\t\tconst defaultName = slug === 'post_tag' ? __( 'Tag' ) : __( 'Term' );\n\t\tconst termAddedMessage = sprintf(\n\t\t\t/* translators: %s: term name. */\n\t\t\t_x( '%s added', 'term' ),\n\t\t\ttaxonomy?.labels?.singular_name ?? defaultName\n\t\t);\n\n\t\tspeak( termAddedMessage, 'assertive' );\n\t\tonUpdateTerms( newTermIds );\n\t}\n\n\tconst newTermLabel =\n\t\ttaxonomy?.labels?.add_new_item ??\n\t\t( slug === 'post_tag' ? __( 'Add new tag' ) : __( 'Add new Term' ) );\n\tconst singularName =\n\t\ttaxonomy?.labels?.singular_name ??\n\t\t( slug === 'post_tag' ? __( 'Tag' ) : __( 'Term' ) );\n\tconst termAddedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s added', 'term' ),\n\t\tsingularName\n\t);\n\tconst termRemovedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s removed', 'term' ),\n\t\tsingularName\n\t);\n\tconst removeTermLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( 'Remove %s', 'term' ),\n\t\tsingularName\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<FormTokenField\n\t\t\t\tvalue={ values }\n\t\t\t\tsuggestions={ suggestions }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tonInputChange={ debouncedSearch }\n\t\t\t\tmaxSuggestions={ MAX_TERMS_SUGGESTIONS }\n\t\t\t\tlabel={ newTermLabel }\n\t\t\t\tmessages={ {\n\t\t\t\t\tadded: termAddedLabel,\n\t\t\t\t\tremoved: termRemovedLabel,\n\t\t\t\t\tremove: removeTermLabel,\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t<MostUsedTerms taxonomy={ taxonomy } onSelect={ appendTerm } />\n\t\t</>\n\t);\n}\n\nexport default withFilters( 'editor.PostTaxonomyType' )( FlatTermSelector );\n"],"mappings":";;;;;;;;AAIA,IAAAA,QAAA,GAAAC,OAAA;AADA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,cAAA,GAAAC,sBAAA,CAAAV,OAAA;AAhBA;AACA;AACA;;AASA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMW,WAAW,GAAG,EAAE;;AAEtB;AACA;AACA;AACA,MAAMC,qBAAqB,GAAG,EAAE;AAChC,MAAMC,aAAa,GAAG;EACrBC,QAAQ,EAAEF,qBAAqB;EAC/BG,OAAO,EAAE,SAAS;EAClBC,OAAO,EAAE;AACV,CAAC;AAED,MAAMC,cAAc,GAAGA,CAAEC,KAAK,EAAEC,KAAK,KACpC,IAAAC,qBAAc,EAAEF,KAAM,CAAC,CAACG,WAAW,CAAC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AAME,gBAAgB,GAAG,IAAAT,aAAO,GAC/B;EACA,IAAAC,QAAE,EAAE,YAAY,EAAE,MAAO,CAAC,EAC1BM,YACD,CAAC;EACD,MAAMG,eAAe,GAAG,IAAAV,aAAO,GAC9B;EACA,IAAAC,QAAE,EAAE,WAAW,EAAE,MAAO,CAAC,EACzBM,YACD,CAAC;EAED,OACC,IAAApH,QAAA,CAAAwH,aAAA,EAAAxH,QAAA,CAAAyH,QAAA,QACC,IAAAzH,QAAA,CAAAwH,aAAA,EAACrH,WAAA,CAAAuH,cAAc;IACdC,KAAK,EAAGvF,MAAQ;IAChBmC,WAAW,EAAGA,WAAa;IAC3Be,QAAQ,EAAGA,QAAU;IACrBsC,aAAa,EAAGnF,eAAiB;IACjCoF,cAAc,EAAGhH,qBAAuB;IACxCiH,KAAK,EAAGZ,YAAc;IACtBa,QAAQ,EAAG;MACVC,KAAK,EAAEX,cAAc;MACrBY,OAAO,EAAEX,gBAAgB;MACzBY,MAAM,EAAEX;IACT;EAAG,CACH,CAAC,EACF,IAAAvH,QAAA,CAAAwH,aAAA,EAAC9G,cAAA,CAAAyH,OAAa;IAACvF,QAAQ,EAAGA,QAAU;IAACwF,QAAQ,EAAG7B;EAAY,CAAE,CAC7D,CAAC;AAEL;AAAC,IAAA8B,QAAA,GAEc,IAAAC,uBAAW,EAAE,yBAA0B,CAAC,CAAEtG,gBAAiB,CAAC;AAAAuG,OAAA,CAAAJ,OAAA,GAAAE,QAAA"}
|
|
1
|
+
{"version":3,"names":["_element","require","_i18n","_components","_data","_coreData","_compose","_a11y","_notices","_store","_terms","_mostUsedTerms","_interopRequireDefault","EMPTY_ARRAY","MAX_TERMS_SUGGESTIONS","DEFAULT_QUERY","per_page","_fields","context","isSameTermName","termA","termB","unescapeString","toLowerCase","termNamesToIds","names","terms","map","termName","find","term","name","id","FlatTermSelector","slug","_taxonomy$labels$add_","_taxonomy$labels$sing2","values","setValues","useState","search","setSearch","debouncedSearch","useDebounce","termIds","taxonomy","hasAssignAction","hasCreateAction","hasResolvedTerms","useSelect","select","_post$_links","_post$_links2","getCurrentPost","getEditedPostAttribute","editorStore","getEntityRecords","getTaxonomy","hasFinishedResolution","coreStore","post","_taxonomy","_termIds","rest_base","query","include","join","_links","length","searchResults","useEffect","newValues","suggestions","useMemo","editPost","useDispatch","saveEntityRecord","createErrorNotice","noticesStore","findOrCreateTerm","newTerm","throwOnError","unescapeTerm","error","code","data","term_id","onUpdateTerms","newTermIds","onChange","termNames","availableTerms","uniqueTerms","reduce","acc","some","n","push","newTermNames","filter","Promise","all","then","newTerms","newAvailableTerms","concat","catch","message","type","appendTerm","_taxonomy$labels$sing","includes","defaultName","__","termAddedMessage","sprintf","_x","labels","singular_name","speak","newTermLabel","add_new_item","singularName","termAddedLabel","termRemovedLabel","removeTermLabel","createElement","Fragment","FormTokenField","__next40pxDefaultSize","value","onInputChange","maxSuggestions","label","messages","added","removed","remove","default","onSelect","_default","withFilters","exports"],"sources":["@wordpress/editor/src/components/post-taxonomies/flat-term-selector.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { useEffect, useMemo, useState } from '@wordpress/element';\nimport { FormTokenField, withFilters } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDebounce } from '@wordpress/compose';\nimport { speak } from '@wordpress/a11y';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { unescapeString, unescapeTerm } from '../../utils/terms';\nimport MostUsedTerms from './most-used-terms';\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation.\n *\n * @type {Array<any>}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Module constants\n */\nconst MAX_TERMS_SUGGESTIONS = 20;\nconst DEFAULT_QUERY = {\n\tper_page: MAX_TERMS_SUGGESTIONS,\n\t_fields: 'id,name',\n\tcontext: 'view',\n};\n\nconst isSameTermName = ( termA, termB ) =>\n\tunescapeString( termA ).toLowerCase() ===\n\tunescapeString( termB ).toLowerCase();\n\nconst termNamesToIds = ( names, terms ) => {\n\treturn names.map(\n\t\t( termName ) =>\n\t\t\tterms.find( ( term ) => isSameTermName( term.name, termName ) ).id\n\t);\n};\n\nexport function FlatTermSelector( { slug } ) {\n\tconst [ values, setValues ] = useState( [] );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 500 );\n\n\tconst {\n\t\tterms,\n\t\ttermIds,\n\t\ttaxonomy,\n\t\thasAssignAction,\n\t\thasCreateAction,\n\t\thasResolvedTerms,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentPost, getEditedPostAttribute } =\n\t\t\t\tselect( editorStore );\n\t\t\tconst { getEntityRecords, getTaxonomy, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst post = getCurrentPost();\n\t\t\tconst _taxonomy = getTaxonomy( slug );\n\t\t\tconst _termIds = _taxonomy\n\t\t\t\t? getEditedPostAttribute( _taxonomy.rest_base )\n\t\t\t\t: EMPTY_ARRAY;\n\n\t\t\tconst query = {\n\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\tinclude: _termIds.join( ',' ),\n\t\t\t\tper_page: -1,\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\thasCreateAction: _taxonomy\n\t\t\t\t\t? post._links?.[\n\t\t\t\t\t\t\t'wp:action-create-' + _taxonomy.rest_base\n\t\t\t\t\t ] ?? false\n\t\t\t\t\t: false,\n\t\t\t\thasAssignAction: _taxonomy\n\t\t\t\t\t? post._links?.[\n\t\t\t\t\t\t\t'wp:action-assign-' + _taxonomy.rest_base\n\t\t\t\t\t ] ?? false\n\t\t\t\t\t: false,\n\t\t\t\ttaxonomy: _taxonomy,\n\t\t\t\ttermIds: _termIds,\n\t\t\t\tterms: _termIds.length\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, query )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t\thasResolvedTerms: hasFinishedResolution( 'getEntityRecords', [\n\t\t\t\t\t'taxonomy',\n\t\t\t\t\tslug,\n\t\t\t\t\tquery,\n\t\t\t\t] ),\n\t\t\t};\n\t\t},\n\t\t[ slug ]\n\t);\n\n\tconst { searchResults } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\n\t\t\treturn {\n\t\t\t\tsearchResults: !! search\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, {\n\t\t\t\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\t\t\t\tsearch,\n\t\t\t\t\t } )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t};\n\t\t},\n\t\t[ search, slug ]\n\t);\n\n\t// Update terms state only after the selectors are resolved.\n\t// We're using this to avoid terms temporarily disappearing on slow networks\n\t// while core data makes REST API requests.\n\tuseEffect( () => {\n\t\tif ( hasResolvedTerms ) {\n\t\t\tconst newValues = ( terms ?? [] ).map( ( term ) =>\n\t\t\t\tunescapeString( term.name )\n\t\t\t);\n\n\t\t\tsetValues( newValues );\n\t\t}\n\t}, [ terms, hasResolvedTerms ] );\n\n\tconst suggestions = useMemo( () => {\n\t\treturn ( searchResults ?? [] ).map( ( term ) =>\n\t\t\tunescapeString( term.name )\n\t\t);\n\t}, [ searchResults ] );\n\n\tconst { editPost } = useDispatch( editorStore );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tif ( ! hasAssignAction ) {\n\t\treturn null;\n\t}\n\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\tconst newTerm = await saveEntityRecord( 'taxonomy', slug, term, {\n\t\t\t\tthrowOnError: true,\n\t\t\t} );\n\t\t\treturn unescapeTerm( newTerm );\n\t\t} catch ( error ) {\n\t\t\tif ( error.code !== 'term_exists' ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tid: error.data.term_id,\n\t\t\t\tname: term.name,\n\t\t\t};\n\t\t}\n\t}\n\n\tfunction onUpdateTerms( newTermIds ) {\n\t\teditPost( { [ taxonomy.rest_base ]: newTermIds } );\n\t}\n\n\tfunction onChange( termNames ) {\n\t\tconst availableTerms = [\n\t\t\t...( terms ?? [] ),\n\t\t\t...( searchResults ?? [] ),\n\t\t];\n\t\tconst uniqueTerms = termNames.reduce( ( acc, name ) => {\n\t\t\tif (\n\t\t\t\t! acc.some( ( n ) => n.toLowerCase() === name.toLowerCase() )\n\t\t\t) {\n\t\t\t\tacc.push( name );\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, [] );\n\n\t\tconst newTermNames = uniqueTerms.filter(\n\t\t\t( termName ) =>\n\t\t\t\t! availableTerms.find( ( term ) =>\n\t\t\t\t\tisSameTermName( term.name, termName )\n\t\t\t\t)\n\t\t);\n\n\t\t// Optimistically update term values.\n\t\t// The selector will always re-fetch terms later.\n\t\tsetValues( uniqueTerms );\n\n\t\tif ( newTermNames.length === 0 ) {\n\t\t\treturn onUpdateTerms(\n\t\t\t\ttermNamesToIds( uniqueTerms, availableTerms )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! hasCreateAction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tPromise.all(\n\t\t\tnewTermNames.map( ( termName ) =>\n\t\t\t\tfindOrCreateTerm( { name: termName } )\n\t\t\t)\n\t\t)\n\t\t\t.then( ( newTerms ) => {\n\t\t\t\tconst newAvailableTerms = availableTerms.concat( newTerms );\n\t\t\t\treturn onUpdateTerms(\n\t\t\t\t\ttermNamesToIds( uniqueTerms, newAvailableTerms )\n\t\t\t\t);\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} );\n\t}\n\n\tfunction appendTerm( newTerm ) {\n\t\tif ( termIds.includes( newTerm.id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newTermIds = [ ...termIds, newTerm.id ];\n\t\tconst defaultName = slug === 'post_tag' ? __( 'Tag' ) : __( 'Term' );\n\t\tconst termAddedMessage = sprintf(\n\t\t\t/* translators: %s: term name. */\n\t\t\t_x( '%s added', 'term' ),\n\t\t\ttaxonomy?.labels?.singular_name ?? defaultName\n\t\t);\n\n\t\tspeak( termAddedMessage, 'assertive' );\n\t\tonUpdateTerms( newTermIds );\n\t}\n\n\tconst newTermLabel =\n\t\ttaxonomy?.labels?.add_new_item ??\n\t\t( slug === 'post_tag' ? __( 'Add new tag' ) : __( 'Add new Term' ) );\n\tconst singularName =\n\t\ttaxonomy?.labels?.singular_name ??\n\t\t( slug === 'post_tag' ? __( 'Tag' ) : __( 'Term' ) );\n\tconst termAddedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s added', 'term' ),\n\t\tsingularName\n\t);\n\tconst termRemovedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s removed', 'term' ),\n\t\tsingularName\n\t);\n\tconst removeTermLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( 'Remove %s', 'term' ),\n\t\tsingularName\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<FormTokenField\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tvalue={ values }\n\t\t\t\tsuggestions={ suggestions }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tonInputChange={ debouncedSearch }\n\t\t\t\tmaxSuggestions={ MAX_TERMS_SUGGESTIONS }\n\t\t\t\tlabel={ newTermLabel }\n\t\t\t\tmessages={ {\n\t\t\t\t\tadded: termAddedLabel,\n\t\t\t\t\tremoved: termRemovedLabel,\n\t\t\t\t\tremove: removeTermLabel,\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t<MostUsedTerms taxonomy={ taxonomy } onSelect={ appendTerm } />\n\t\t</>\n\t);\n}\n\nexport default withFilters( 'editor.PostTaxonomyType' )( FlatT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AAA+H,QAAA,QACC,IAAA/H,QAAA,CAAA8H,aAAA,EAAC3H,WAAA,CAAA6H,cAAc;IACdC,qBAAqB;IACrBC,KAAK,EAAG7F,MAAQ;IAChBmC,WAAW,EAAGA,WAAa;IAC3BiB,QAAQ,EAAGA,QAAU;IACrB0C,aAAa,EAAGzF,eAAiB;IACjC0F,cAAc,EAAGtH,qBAAuB;IACxCuH,KAAK,EAAGb,YAAc;IACtBc,QAAQ,EAAG;MACVC,KAAK,EAAEZ,cAAc;MACrBa,OAAO,EAAEZ,gBAAgB;MACzBa,MAAM,EAAEZ;IACT;EAAG,CACH,CAAC,EACF,IAAA7H,QAAA,CAAA8H,aAAA,EAACnH,cAAA,CAAA+H,OAAa;IAAC7F,QAAQ,EAAGA,QAAU;IAAC8F,QAAQ,EAAG9B;EAAY,CAAE,CAC7D,CAAC;AAEL;AAAC,IAAA+B,QAAA,GAEc,IAAAC,uBAAW,EAAE,yBAA0B,CAAC,CAAE5G,gBAAiB,CAAC;AAAA6G,OAAA,CAAAJ,OAAA,GAAAE,QAAA"}
|
|
@@ -10,6 +10,7 @@ exports.getFilterMatcher = getFilterMatcher;
|
|
|
10
10
|
exports.sortBySelected = sortBySelected;
|
|
11
11
|
var _element = require("@wordpress/element");
|
|
12
12
|
var _i18n = require("@wordpress/i18n");
|
|
13
|
+
var _notices = require("@wordpress/notices");
|
|
13
14
|
var _components = require("@wordpress/components");
|
|
14
15
|
var _data = require("@wordpress/data");
|
|
15
16
|
var _compose = require("@wordpress/compose");
|
|
@@ -187,6 +188,9 @@ function HierarchicalTermSelector({
|
|
|
187
188
|
// Remove `terms` from the dependency list to avoid reordering every time
|
|
188
189
|
// checking or unchecking a term.
|
|
189
190
|
[availableTerms]);
|
|
191
|
+
const {
|
|
192
|
+
createErrorNotice
|
|
193
|
+
} = (0, _data.useDispatch)(_notices.store);
|
|
190
194
|
if (!hasAssignAction) {
|
|
191
195
|
return null;
|
|
192
196
|
}
|
|
@@ -198,7 +202,9 @@ function HierarchicalTermSelector({
|
|
|
198
202
|
* @return {Promise} A promise that resolves to save term object.
|
|
199
203
|
*/
|
|
200
204
|
const addTerm = term => {
|
|
201
|
-
return saveEntityRecord('taxonomy', slug, term
|
|
205
|
+
return saveEntityRecord('taxonomy', slug, term, {
|
|
206
|
+
throwOnError: true
|
|
207
|
+
});
|
|
202
208
|
};
|
|
203
209
|
|
|
204
210
|
/**
|
|
@@ -256,10 +262,18 @@ function HierarchicalTermSelector({
|
|
|
256
262
|
return;
|
|
257
263
|
}
|
|
258
264
|
setAdding(true);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
265
|
+
let newTerm;
|
|
266
|
+
try {
|
|
267
|
+
newTerm = await addTerm({
|
|
268
|
+
name: formName,
|
|
269
|
+
parent: formParent ? formParent : undefined
|
|
270
|
+
});
|
|
271
|
+
} catch (error) {
|
|
272
|
+
createErrorNotice(error.message, {
|
|
273
|
+
type: 'snackbar'
|
|
274
|
+
});
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
263
277
|
const defaultName = slug === 'category' ? (0, _i18n.__)('Category') : (0, _i18n.__)('Term');
|
|
264
278
|
const termAddedMessage = (0, _i18n.sprintf)( /* translators: %s: taxonomy name */
|
|
265
279
|
(0, _i18n._x)('%s added', 'term'), (_taxonomy$labels$sing = taxonomy?.labels?.singular_name) !== null && _taxonomy$labels$sing !== void 0 ? _taxonomy$labels$sing : defaultName);
|