@wordpress/fields 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +12 -0
- package/build/actions/delete-post.js +4 -4
- package/build/actions/delete-post.js.map +1 -1
- package/build/actions/duplicate-post.js +2 -2
- package/build/actions/duplicate-post.js.map +1 -1
- package/build/actions/view-post-revisions.js +1 -1
- package/build/actions/view-post-revisions.js.map +1 -1
- package/build/fields/featured-image/featured-image-edit.js +113 -0
- package/build/fields/featured-image/featured-image-edit.js.map +1 -0
- package/build/fields/featured-image/featured-image-view.js +41 -0
- package/build/fields/featured-image/featured-image-view.js.map +1 -0
- package/build/fields/featured-image/index.js +30 -0
- package/build/fields/featured-image/index.js.map +1 -0
- package/build/fields/index.js +21 -0
- package/build/fields/index.js.map +1 -1
- package/build/fields/parent/index.js +34 -0
- package/build/fields/parent/index.js.map +1 -0
- package/build/fields/parent/parent-edit.js +243 -0
- package/build/fields/parent/parent-edit.js.map +1 -0
- package/build/fields/parent/parent-view.js +39 -0
- package/build/fields/parent/parent-view.js.map +1 -0
- package/build/fields/parent/utils.js +20 -0
- package/build/fields/parent/utils.js.map +1 -0
- package/build/fields/slug/index.js +30 -0
- package/build/fields/slug/index.js.map +1 -0
- package/build/fields/slug/slug-edit.js +132 -0
- package/build/fields/slug/slug-edit.js.map +1 -0
- package/build/fields/slug/slug-view.js +30 -0
- package/build/fields/slug/slug-view.js.map +1 -0
- package/build/mutation/index.js +2 -2
- package/build/mutation/index.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build-module/actions/delete-post.js +5 -5
- package/build-module/actions/delete-post.js.map +1 -1
- package/build-module/actions/duplicate-post.js +2 -2
- package/build-module/actions/duplicate-post.js.map +1 -1
- package/build-module/actions/view-post-revisions.js +1 -1
- package/build-module/actions/view-post-revisions.js.map +1 -1
- package/build-module/fields/featured-image/featured-image-edit.js +105 -0
- package/build-module/fields/featured-image/featured-image-edit.js.map +1 -0
- package/build-module/fields/featured-image/featured-image-view.js +33 -0
- package/build-module/fields/featured-image/featured-image-view.js.map +1 -0
- package/build-module/fields/featured-image/index.js +24 -0
- package/build-module/fields/featured-image/index.js.map +1 -0
- package/build-module/fields/index.js +3 -0
- package/build-module/fields/index.js.map +1 -1
- package/build-module/fields/parent/index.js +28 -0
- package/build-module/fields/parent/index.js.map +1 -0
- package/build-module/fields/parent/parent-edit.js +230 -0
- package/build-module/fields/parent/parent-edit.js.map +1 -0
- package/build-module/fields/parent/parent-view.js +32 -0
- package/build-module/fields/parent/parent-view.js.map +1 -0
- package/build-module/fields/parent/utils.js +14 -0
- package/build-module/fields/parent/utils.js.map +1 -0
- package/build-module/fields/slug/index.js +23 -0
- package/build-module/fields/slug/index.js.map +1 -0
- package/build-module/fields/slug/slug-edit.js +125 -0
- package/build-module/fields/slug/slug-edit.js.map +1 -0
- package/build-module/fields/slug/slug-view.js +24 -0
- package/build-module/fields/slug/slug-view.js.map +1 -0
- package/build-module/mutation/index.js +2 -2
- package/build-module/mutation/index.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-style/styles-rtl.css +134 -0
- package/build-style/styles.css +134 -0
- package/build-types/actions/delete-post.d.ts.map +1 -1
- package/build-types/fields/featured-image/featured-image-edit.d.ts +7 -0
- package/build-types/fields/featured-image/featured-image-edit.d.ts.map +1 -0
- package/build-types/fields/featured-image/featured-image-view.d.ts +7 -0
- package/build-types/fields/featured-image/featured-image-view.d.ts.map +1 -0
- package/build-types/fields/featured-image/index.d.ts +11 -0
- package/build-types/fields/featured-image/index.d.ts.map +1 -0
- package/build-types/fields/index.d.ts +3 -0
- package/build-types/fields/index.d.ts.map +1 -1
- package/build-types/fields/parent/index.d.ts +14 -0
- package/build-types/fields/parent/index.d.ts.map +1 -0
- package/build-types/fields/parent/parent-edit.d.ts +9 -0
- package/build-types/fields/parent/parent-edit.d.ts.map +1 -0
- package/build-types/fields/parent/parent-view.d.ts +7 -0
- package/build-types/fields/parent/parent-view.d.ts.map +1 -0
- package/build-types/fields/parent/utils.d.ts +6 -0
- package/build-types/fields/parent/utils.d.ts.map +1 -0
- package/build-types/fields/slug/index.d.ts +11 -0
- package/build-types/fields/slug/index.d.ts.map +1 -0
- package/build-types/fields/slug/slug-edit.d.ts +8 -0
- package/build-types/fields/slug/slug-edit.d.ts.map +1 -0
- package/build-types/fields/slug/slug-view.d.ts +9 -0
- package/build-types/fields/slug/slug-view.d.ts.map +1 -0
- package/build-types/types.d.ts +2 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +26 -22
- package/src/actions/delete-post.tsx +8 -5
- package/src/actions/duplicate-post.tsx +2 -2
- package/src/actions/view-post-revisions.tsx +1 -1
- package/src/fields/featured-image/featured-image-edit.tsx +122 -0
- package/src/fields/featured-image/featured-image-view.tsx +38 -0
- package/src/fields/featured-image/index.ts +24 -0
- package/src/fields/featured-image/style.scss +95 -0
- package/src/fields/index.ts +3 -0
- package/src/fields/parent/index.ts +27 -0
- package/src/fields/parent/parent-edit.tsx +348 -0
- package/src/fields/parent/parent-view.tsx +33 -0
- package/src/fields/parent/utils.ts +18 -0
- package/src/fields/slug/index.ts +23 -0
- package/src/fields/slug/slug-edit.tsx +156 -0
- package/src/fields/slug/slug-view.tsx +26 -0
- package/src/fields/slug/style.scss +22 -0
- package/src/mutation/index.ts +3 -3
- package/src/styles.scss +1 -0
- package/src/types.ts +2 -0
- package/tsconfig.json +3 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { ComboboxControl, ExternalLink } from '@wordpress/components';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
import { createInterpolateElement, useCallback, useMemo, useState } from '@wordpress/element';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
9
|
+
/**
|
|
10
|
+
* External dependencies
|
|
11
|
+
*/
|
|
12
|
+
import removeAccents from 'remove-accents';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import { debounce } from '@wordpress/compose';
|
|
18
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
19
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
20
|
+
import { getTitleWithFallbackName } from './utils';
|
|
21
|
+
import { filterURLForDisplay } from '@wordpress/url';
|
|
22
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
23
|
+
function buildTermsTree(flatTerms) {
|
|
24
|
+
const flatTermsWithParentAndChildren = flatTerms.map(term => {
|
|
25
|
+
return {
|
|
26
|
+
children: [],
|
|
27
|
+
...term
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// All terms should have a `parent` because we're about to index them by it.
|
|
32
|
+
if (flatTermsWithParentAndChildren.some(({
|
|
33
|
+
parent
|
|
34
|
+
}) => parent === null || parent === undefined)) {
|
|
35
|
+
return flatTermsWithParentAndChildren;
|
|
36
|
+
}
|
|
37
|
+
const termsByParent = flatTermsWithParentAndChildren.reduce((acc, term) => {
|
|
38
|
+
const {
|
|
39
|
+
parent
|
|
40
|
+
} = term;
|
|
41
|
+
if (!acc[parent]) {
|
|
42
|
+
acc[parent] = [];
|
|
43
|
+
}
|
|
44
|
+
acc[parent].push(term);
|
|
45
|
+
return acc;
|
|
46
|
+
}, {});
|
|
47
|
+
const fillWithChildren = terms => {
|
|
48
|
+
return terms.map(term => {
|
|
49
|
+
const children = termsByParent[term.id];
|
|
50
|
+
return {
|
|
51
|
+
...term,
|
|
52
|
+
children: children && children.length ? fillWithChildren(children) : []
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
return fillWithChildren(termsByParent['0'] || []);
|
|
57
|
+
}
|
|
58
|
+
export const getItemPriority = (name, searchValue) => {
|
|
59
|
+
const normalizedName = removeAccents(name || '').toLowerCase();
|
|
60
|
+
const normalizedSearch = removeAccents(searchValue || '').toLowerCase();
|
|
61
|
+
if (normalizedName === normalizedSearch) {
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
if (normalizedName.startsWith(normalizedSearch)) {
|
|
65
|
+
return normalizedName.length;
|
|
66
|
+
}
|
|
67
|
+
return Infinity;
|
|
68
|
+
};
|
|
69
|
+
export function PageAttributesParent({
|
|
70
|
+
data,
|
|
71
|
+
onChangeControl
|
|
72
|
+
}) {
|
|
73
|
+
const [fieldValue, setFieldValue] = useState(null);
|
|
74
|
+
const pageId = data.parent;
|
|
75
|
+
const postId = data.id;
|
|
76
|
+
const postTypeSlug = data.type;
|
|
77
|
+
const {
|
|
78
|
+
parentPostTitle,
|
|
79
|
+
pageItems,
|
|
80
|
+
isHierarchical
|
|
81
|
+
} = useSelect(select => {
|
|
82
|
+
// @ts-expect-error getPostType is not typed
|
|
83
|
+
const {
|
|
84
|
+
getEntityRecord,
|
|
85
|
+
getEntityRecords,
|
|
86
|
+
getPostType
|
|
87
|
+
} = select(coreStore);
|
|
88
|
+
const postTypeInfo = getPostType(postTypeSlug);
|
|
89
|
+
const postIsHierarchical = postTypeInfo?.hierarchical && postTypeInfo.viewable;
|
|
90
|
+
const parentPost = pageId ? getEntityRecord('postType', postTypeSlug, pageId) : null;
|
|
91
|
+
const query = {
|
|
92
|
+
per_page: 100,
|
|
93
|
+
exclude: postId,
|
|
94
|
+
parent_exclude: postId,
|
|
95
|
+
orderby: 'menu_order',
|
|
96
|
+
order: 'asc',
|
|
97
|
+
_fields: 'id,title,parent',
|
|
98
|
+
...(fieldValue !== null && {
|
|
99
|
+
search: fieldValue
|
|
100
|
+
})
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
isHierarchical: postIsHierarchical,
|
|
104
|
+
parentPostTitle: parentPost ? getTitleWithFallbackName(parentPost) : '',
|
|
105
|
+
pageItems: postIsHierarchical ? getEntityRecords('postType', postTypeSlug, query) : null
|
|
106
|
+
};
|
|
107
|
+
}, [fieldValue, pageId, postId, postTypeSlug]);
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* This logic has been copied from https://github.com/WordPress/gutenberg/blob/0249771b519d5646171fb9fae422006c8ab773f2/packages/editor/src/components/page-attributes/parent.js#L106.
|
|
111
|
+
*/
|
|
112
|
+
const parentOptions = useMemo(() => {
|
|
113
|
+
const getOptionsFromTree = (tree, level = 0) => {
|
|
114
|
+
const mappedNodes = tree.map(treeNode => [{
|
|
115
|
+
value: treeNode.id,
|
|
116
|
+
label: '— '.repeat(level) + decodeEntities(treeNode.name),
|
|
117
|
+
rawName: treeNode.name
|
|
118
|
+
}, ...getOptionsFromTree(treeNode.children || [], level + 1)]);
|
|
119
|
+
const sortedNodes = mappedNodes.sort(([a], [b]) => {
|
|
120
|
+
const priorityA = getItemPriority(a.rawName, fieldValue !== null && fieldValue !== void 0 ? fieldValue : '');
|
|
121
|
+
const priorityB = getItemPriority(b.rawName, fieldValue !== null && fieldValue !== void 0 ? fieldValue : '');
|
|
122
|
+
return priorityA >= priorityB ? 1 : -1;
|
|
123
|
+
});
|
|
124
|
+
return sortedNodes.flat();
|
|
125
|
+
};
|
|
126
|
+
if (!pageItems) {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
let tree = pageItems.map(item => {
|
|
130
|
+
var _item$parent;
|
|
131
|
+
return {
|
|
132
|
+
id: item.id,
|
|
133
|
+
parent: (_item$parent = item.parent) !== null && _item$parent !== void 0 ? _item$parent : null,
|
|
134
|
+
name: getTitleWithFallbackName(item)
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Only build a hierarchical tree when not searching.
|
|
139
|
+
if (!fieldValue) {
|
|
140
|
+
tree = buildTermsTree(tree);
|
|
141
|
+
}
|
|
142
|
+
const opts = getOptionsFromTree(tree);
|
|
143
|
+
|
|
144
|
+
// Ensure the current parent is in the options list.
|
|
145
|
+
const optsHasParent = opts.find(item => item.value === pageId);
|
|
146
|
+
if (pageId && parentPostTitle && !optsHasParent) {
|
|
147
|
+
opts.unshift({
|
|
148
|
+
value: pageId,
|
|
149
|
+
label: parentPostTitle,
|
|
150
|
+
rawName: ''
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return opts.map(option => ({
|
|
154
|
+
...option,
|
|
155
|
+
value: option.value.toString()
|
|
156
|
+
}));
|
|
157
|
+
}, [pageItems, fieldValue, parentPostTitle, pageId]);
|
|
158
|
+
if (!isHierarchical) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Handle user input.
|
|
164
|
+
*
|
|
165
|
+
* @param {string} inputValue The current value of the input field.
|
|
166
|
+
*/
|
|
167
|
+
const handleKeydown = inputValue => {
|
|
168
|
+
setFieldValue(inputValue);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Handle author selection.
|
|
173
|
+
*
|
|
174
|
+
* @param {Object} selectedPostId The selected Author.
|
|
175
|
+
*/
|
|
176
|
+
const handleChange = selectedPostId => {
|
|
177
|
+
if (selectedPostId) {
|
|
178
|
+
var _parseInt;
|
|
179
|
+
return onChangeControl((_parseInt = parseInt(selectedPostId, 10)) !== null && _parseInt !== void 0 ? _parseInt : 0);
|
|
180
|
+
}
|
|
181
|
+
onChangeControl(0);
|
|
182
|
+
};
|
|
183
|
+
return /*#__PURE__*/_jsx(ComboboxControl, {
|
|
184
|
+
__nextHasNoMarginBottom: true,
|
|
185
|
+
__next40pxDefaultSize: true,
|
|
186
|
+
label: __('Parent'),
|
|
187
|
+
help: __('Choose a parent page.'),
|
|
188
|
+
value: pageId?.toString(),
|
|
189
|
+
options: parentOptions,
|
|
190
|
+
onFilterValueChange: debounce(value => handleKeydown(value), 300),
|
|
191
|
+
onChange: handleChange,
|
|
192
|
+
hideLabelFromVision: true
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
export const ParentEdit = ({
|
|
196
|
+
data,
|
|
197
|
+
field,
|
|
198
|
+
onChange
|
|
199
|
+
}) => {
|
|
200
|
+
const {
|
|
201
|
+
id
|
|
202
|
+
} = field;
|
|
203
|
+
const homeUrl = useSelect(select => {
|
|
204
|
+
// @ts-expect-error getEntityRecord is not typed with unstableBase as argument.
|
|
205
|
+
return select(coreStore).getEntityRecord('root', '__unstableBase')?.home;
|
|
206
|
+
}, []);
|
|
207
|
+
const onChangeControl = useCallback(newValue => onChange({
|
|
208
|
+
[id]: newValue
|
|
209
|
+
}), [id, onChange]);
|
|
210
|
+
return /*#__PURE__*/_jsx("fieldset", {
|
|
211
|
+
className: "fields-controls__parent",
|
|
212
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
213
|
+
children: [createInterpolateElement(sprintf(/* translators: %1$s The home URL of the WordPress installation without the scheme. */
|
|
214
|
+
__('Child pages inherit characteristics from their parent, such as URL structure. For instance, if "Pricing" is a child of "Services", its URL would be %1$s<wbr />/services<wbr />/pricing.'), filterURLForDisplay(homeUrl).replace(/([/.])/g, '<wbr />$1')), {
|
|
215
|
+
wbr: /*#__PURE__*/_jsx("wbr", {})
|
|
216
|
+
}), /*#__PURE__*/_jsx("p", {
|
|
217
|
+
children: createInterpolateElement(__('They also show up as sub-items in the default navigation menu. <a>Learn more.</a>'), {
|
|
218
|
+
a: /*#__PURE__*/_jsx(ExternalLink, {
|
|
219
|
+
href: __('https://wordpress.org/documentation/article/page-post-settings-sidebar/#page-attributes'),
|
|
220
|
+
children: undefined
|
|
221
|
+
})
|
|
222
|
+
})
|
|
223
|
+
}), /*#__PURE__*/_jsx(PageAttributesParent, {
|
|
224
|
+
data: data,
|
|
225
|
+
onChangeControl: onChangeControl
|
|
226
|
+
})]
|
|
227
|
+
})
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
//# sourceMappingURL=parent-edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ComboboxControl","ExternalLink","useSelect","createInterpolateElement","useCallback","useMemo","useState","store","coreStore","removeAccents","debounce","decodeEntities","__","sprintf","getTitleWithFallbackName","filterURLForDisplay","jsx","_jsx","jsxs","_jsxs","buildTermsTree","flatTerms","flatTermsWithParentAndChildren","map","term","children","some","parent","undefined","termsByParent","reduce","acc","push","fillWithChildren","terms","id","length","getItemPriority","name","searchValue","normalizedName","toLowerCase","normalizedSearch","startsWith","Infinity","PageAttributesParent","data","onChangeControl","fieldValue","setFieldValue","pageId","postId","postTypeSlug","type","parentPostTitle","pageItems","isHierarchical","select","getEntityRecord","getEntityRecords","getPostType","postTypeInfo","postIsHierarchical","hierarchical","viewable","parentPost","query","per_page","exclude","parent_exclude","orderby","order","_fields","search","parentOptions","getOptionsFromTree","tree","level","mappedNodes","treeNode","value","label","repeat","rawName","sortedNodes","sort","a","b","priorityA","priorityB","flat","item","_item$parent","opts","optsHasParent","find","unshift","option","toString","handleKeydown","inputValue","handleChange","selectedPostId","_parseInt","parseInt","__nextHasNoMarginBottom","__next40pxDefaultSize","help","options","onFilterValueChange","onChange","hideLabelFromVision","ParentEdit","field","homeUrl","home","newValue","className","replace","wbr","href"],"sources":["@wordpress/fields/src/fields/parent/parent-edit.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { ComboboxControl, ExternalLink } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tcreateInterpolateElement,\n\tuseCallback,\n\tuseMemo,\n\tuseState,\n} from '@wordpress/element';\n// @ts-ignore\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\n\n/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\n\n/**\n * Internal dependencies\n */\nimport { debounce } from '@wordpress/compose';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __, sprintf } from '@wordpress/i18n';\nimport type { BasePost } from '../../types';\nimport { getTitleWithFallbackName } from './utils';\nimport { filterURLForDisplay } from '@wordpress/url';\n\ntype TreeBase = {\n\tid: number;\n\tname: string;\n\t[ key: string ]: any;\n};\n\ntype TreeWithParent = TreeBase & {\n\tparent: number;\n};\n\ntype TreeWithoutParent = TreeBase & {\n\tparent: null;\n};\n\ntype Tree = TreeWithParent | TreeWithoutParent;\n\nfunction buildTermsTree( flatTerms: Tree[] ) {\n\tconst flatTermsWithParentAndChildren = flatTerms.map( ( term ) => {\n\t\treturn {\n\t\t\tchildren: [],\n\t\t\t...term,\n\t\t};\n\t} );\n\n\t// All terms should have a `parent` because we're about to index them by it.\n\tif (\n\t\tflatTermsWithParentAndChildren.some(\n\t\t\t( { parent } ) => parent === null || parent === undefined\n\t\t)\n\t) {\n\t\treturn flatTermsWithParentAndChildren as TreeWithParent[];\n\t}\n\n\tconst termsByParent = (\n\t\tflatTermsWithParentAndChildren as TreeWithParent[]\n\t ).reduce(\n\t\t( acc, term ) => {\n\t\t\tconst { parent } = term;\n\t\t\tif ( ! acc[ parent ] ) {\n\t\t\t\tacc[ parent ] = [];\n\t\t\t}\n\t\t\tacc[ parent ].push( term );\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record< string, Array< TreeWithParent > >\n\t);\n\n\tconst fillWithChildren = (\n\t\tterms: Array< TreeWithParent >\n\t): Array< TreeWithParent > => {\n\t\treturn terms.map( ( term ) => {\n\t\t\tconst children = termsByParent[ term.id ];\n\t\t\treturn {\n\t\t\t\t...term,\n\t\t\t\tchildren:\n\t\t\t\t\tchildren && children.length\n\t\t\t\t\t\t? fillWithChildren( children )\n\t\t\t\t\t\t: [],\n\t\t\t};\n\t\t} );\n\t};\n\n\treturn fillWithChildren( termsByParent[ '0' ] || [] );\n}\n\nexport const getItemPriority = ( name: string, searchValue: string ) => {\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\tdata,\n\tonChangeControl,\n}: {\n\tdata: BasePost;\n\tonChangeControl: ( newValue: number ) => void;\n} ) {\n\tconst [ fieldValue, setFieldValue ] = useState< null | string >( null );\n\n\tconst pageId = data.parent;\n\tconst postId = data.id;\n\tconst postTypeSlug = data.type;\n\n\tconst { parentPostTitle, pageItems, isHierarchical } = useSelect(\n\t\t( select ) => {\n\t\t\t// @ts-expect-error getPostType is not typed\n\t\t\tconst { getEntityRecord, getEntityRecords, getPostType } =\n\t\t\t\tselect( coreStore );\n\n\t\t\tconst postTypeInfo = getPostType( postTypeSlug );\n\n\t\t\tconst postIsHierarchical =\n\t\t\t\tpostTypeInfo?.hierarchical && postTypeInfo.viewable;\n\n\t\t\tconst parentPost = pageId\n\t\t\t\t? getEntityRecord< BasePost >(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\tpostTypeSlug,\n\t\t\t\t\t\tpageId\n\t\t\t\t )\n\t\t\t\t: null;\n\n\t\t\tconst query = {\n\t\t\t\tper_page: 100,\n\t\t\t\texclude: postId,\n\t\t\t\tparent_exclude: postId,\n\t\t\t\torderby: 'menu_order',\n\t\t\t\torder: 'asc',\n\t\t\t\t_fields: 'id,title,parent',\n\t\t\t\t...( fieldValue !== null && {\n\t\t\t\t\tsearch: fieldValue,\n\t\t\t\t} ),\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\tisHierarchical: postIsHierarchical,\n\t\t\t\tparentPostTitle: parentPost\n\t\t\t\t\t? getTitleWithFallbackName( parentPost )\n\t\t\t\t\t: '',\n\t\t\t\tpageItems: postIsHierarchical\n\t\t\t\t\t? getEntityRecords< BasePost >(\n\t\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t\tpostTypeSlug,\n\t\t\t\t\t\t\tquery\n\t\t\t\t\t )\n\t\t\t\t\t: null,\n\t\t\t};\n\t\t},\n\t\t[ fieldValue, pageId, postId, postTypeSlug ]\n\t);\n\n\t/**\n\t * This logic has been copied from https://github.com/WordPress/gutenberg/blob/0249771b519d5646171fb9fae422006c8ab773f2/packages/editor/src/components/page-attributes/parent.js#L106.\n\t */\n\tconst parentOptions = useMemo( () => {\n\t\tconst getOptionsFromTree = (\n\t\t\ttree: Array< Tree >,\n\t\t\tlevel = 0\n\t\t): Array< {\n\t\t\tvalue: number;\n\t\t\tlabel: string;\n\t\t\trawName: string;\n\t\t} > => {\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(\n\t\t\t\t\ta.rawName,\n\t\t\t\t\tfieldValue ?? ''\n\t\t\t\t);\n\t\t\t\tconst priorityB = getItemPriority(\n\t\t\t\t\tb.rawName,\n\t\t\t\t\tfieldValue ?? ''\n\t\t\t\t);\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 as number,\n\t\t\tparent: item.parent ?? null,\n\t\t\tname: getTitleWithFallbackName( 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( ( item ) => item.value === pageId );\n\t\tif ( pageId && parentPostTitle && ! optsHasParent ) {\n\t\t\topts.unshift( {\n\t\t\t\tvalue: pageId,\n\t\t\t\tlabel: parentPostTitle,\n\t\t\t\trawName: '',\n\t\t\t} );\n\t\t}\n\t\treturn opts.map( ( option ) => ( {\n\t\t\t...option,\n\t\t\tvalue: option.value.toString(),\n\t\t} ) );\n\t}, [ pageItems, fieldValue, parentPostTitle, pageId ] );\n\n\tif ( ! isHierarchical ) {\n\t\treturn null;\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: string ) => {\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: string | null | undefined ) => {\n\t\tif ( selectedPostId ) {\n\t\t\treturn onChangeControl( parseInt( selectedPostId, 10 ) ?? 0 );\n\t\t}\n\n\t\tonChangeControl( 0 );\n\t};\n\n\treturn (\n\t\t<ComboboxControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\t__next40pxDefaultSize\n\t\t\tlabel={ __( 'Parent' ) }\n\t\t\thelp={ __( 'Choose a parent page.' ) }\n\t\t\tvalue={ pageId?.toString() }\n\t\t\toptions={ parentOptions }\n\t\t\tonFilterValueChange={ debounce(\n\t\t\t\t( value: unknown ) => handleKeydown( value as string ),\n\t\t\t\t300\n\t\t\t) }\n\t\t\tonChange={ handleChange }\n\t\t\thideLabelFromVision\n\t\t/>\n\t);\n}\n\nexport const ParentEdit = ( {\n\tdata,\n\tfield,\n\tonChange,\n}: DataFormControlProps< BasePost > ) => {\n\tconst { id } = field;\n\n\tconst homeUrl = useSelect( ( select ) => {\n\t\t// @ts-expect-error getEntityRecord is not typed with unstableBase as argument.\n\t\treturn select( coreStore ).getEntityRecord< {\n\t\t\thome: string;\n\t\t} >( 'root', '__unstableBase' )?.home as string;\n\t}, [] );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue?: number ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\treturn (\n\t\t<fieldset className=\"fields-controls__parent\">\n\t\t\t<div>\n\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %1$s The home URL of the WordPress installation without the scheme. */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Child pages inherit characteristics from their parent, such as URL structure. For instance, if \"Pricing\" is a child of \"Services\", its URL would be %1$s<wbr />/services<wbr />/pricing.'\n\t\t\t\t\t\t),\n\t\t\t\t\t\tfilterURLForDisplay( homeUrl ).replace(\n\t\t\t\t\t\t\t/([/.])/g,\n\t\t\t\t\t\t\t'<wbr />$1'\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\twbr: <wbr />,\n\t\t\t\t\t}\n\t\t\t\t) }\n\t\t\t\t<p>\n\t\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'They also show up as sub-items in the default navigation menu. <a>Learn more.</a>'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ta: (\n\t\t\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\t\t\thref={ __(\n\t\t\t\t\t\t\t\t\t\t'https://wordpress.org/documentation/article/page-post-settings-sidebar/#page-attributes'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\tchildren={ undefined }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t</p>\n\t\t\t\t<PageAttributesParent\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tonChangeControl={ onChangeControl }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</fieldset>\n\t);\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAe,EAAEC,YAAY,QAAQ,uBAAuB;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|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect } from '@wordpress/data';
|
|
5
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { getTitleWithFallbackName } from './utils';
|
|
12
|
+
import { __ } from '@wordpress/i18n';
|
|
13
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
export const ParentView = ({
|
|
15
|
+
item
|
|
16
|
+
}) => {
|
|
17
|
+
const parent = useSelect(select => {
|
|
18
|
+
const {
|
|
19
|
+
getEntityRecord
|
|
20
|
+
} = select(coreStore);
|
|
21
|
+
return item?.parent ? getEntityRecord('postType', item.type, item.parent) : null;
|
|
22
|
+
}, [item.parent, item.type]);
|
|
23
|
+
if (parent) {
|
|
24
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
25
|
+
children: getTitleWithFallbackName(parent)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
29
|
+
children: __('None')
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=parent-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useSelect","store","coreStore","getTitleWithFallbackName","__","Fragment","_Fragment","jsx","_jsx","ParentView","item","parent","select","getEntityRecord","type","children"],"sources":["@wordpress/fields/src/fields/parent/parent-view.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\nimport { getTitleWithFallbackName } from './utils';\nimport { __ } from '@wordpress/i18n';\n\nexport const ParentView = ( {\n\titem,\n}: DataViewRenderFieldProps< BasePost > ) => {\n\tconst parent = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord } = select( coreStore );\n\t\t\treturn item?.parent\n\t\t\t\t? getEntityRecord( 'postType', item.type, item.parent )\n\t\t\t\t: null;\n\t\t},\n\t\t[ item.parent, item.type ]\n\t);\n\n\tif ( parent ) {\n\t\treturn <>{ getTitleWithFallbackName( parent ) }</>;\n\t}\n\n\treturn <>{ __( 'None' ) }</>;\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;;AAGA,SAASC,wBAAwB,QAAQ,SAAS;AAClD,SAASC,EAAE,QAAQ,iBAAiB;AAAC,SAAAC,QAAA,IAAAC,SAAA,EAAAC,GAAA,IAAAC,IAAA;AAErC,OAAO,MAAMC,UAAU,GAAGA,CAAE;EAC3BC;AACqC,CAAC,KAAM;EAC5C,MAAMC,MAAM,GAAGX,SAAS,CACrBY,MAAM,IAAM;IACb,MAAM;MAAEC;IAAgB,CAAC,GAAGD,MAAM,CAAEV,SAAU,CAAC;IAC/C,OAAOQ,IAAI,EAAEC,MAAM,GAChBE,eAAe,CAAE,UAAU,EAAEH,IAAI,CAACI,IAAI,EAAEJ,IAAI,CAACC,MAAO,CAAC,GACrD,IAAI;EACR,CAAC,EACD,CAAED,IAAI,CAACC,MAAM,EAAED,IAAI,CAACI,IAAI,CACzB,CAAC;EAED,IAAKH,MAAM,EAAG;IACb,oBAAOH,IAAA,CAAAF,SAAA;MAAAS,QAAA,EAAIZ,wBAAwB,CAAEQ,MAAO;IAAC,CAAI,CAAC;EACnD;EAEA,oBAAOH,IAAA,CAAAF,SAAA;IAAAS,QAAA,EAAIX,EAAE,CAAE,MAAO;EAAC,CAAI,CAAC;AAC7B,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export function getTitleWithFallbackName(post) {
|
|
12
|
+
return typeof post.title === 'object' && 'rendered' in post.title && post.title.rendered ? decodeEntities(post.title.rendered) : `#${post?.id} (${__('no title')})`;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["decodeEntities","__","getTitleWithFallbackName","post","title","rendered","id"],"sources":["@wordpress/fields/src/fields/parent/utils.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\n\nexport function getTitleWithFallbackName( post: BasePost ) {\n\treturn typeof post.title === 'object' &&\n\t\t'rendered' in post.title &&\n\t\tpost.title.rendered\n\t\t? decodeEntities( post.title.rendered )\n\t\t: `#${ post?.id } (${ __( 'no title' ) })`;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;;AAGA,OAAO,SAASC,wBAAwBA,CAAEC,IAAc,EAAG;EAC1D,OAAO,OAAOA,IAAI,CAACC,KAAK,KAAK,QAAQ,IACpC,UAAU,IAAID,IAAI,CAACC,KAAK,IACxBD,IAAI,CAACC,KAAK,CAACC,QAAQ,GACjBL,cAAc,CAAEG,IAAI,CAACC,KAAK,CAACC,QAAS,CAAC,GACrC,IAAKF,IAAI,EAAEG,EAAE,KAAOL,EAAE,CAAE,UAAW,CAAC,GAAI;AAC5C","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { __ } from '@wordpress/i18n';
|
|
10
|
+
import SlugEdit from './slug-edit';
|
|
11
|
+
import SlugView from './slug-view';
|
|
12
|
+
const slugField = {
|
|
13
|
+
id: 'slug',
|
|
14
|
+
type: 'text',
|
|
15
|
+
label: __('Slug'),
|
|
16
|
+
getValue: ({
|
|
17
|
+
item
|
|
18
|
+
}) => item.slug,
|
|
19
|
+
Edit: SlugEdit,
|
|
20
|
+
render: SlugView
|
|
21
|
+
};
|
|
22
|
+
export default slugField;
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__","SlugEdit","SlugView","slugField","id","type","label","getValue","item","slug","Edit","render"],"sources":["@wordpress/fields/src/fields/slug/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport { __ } from '@wordpress/i18n';\nimport SlugEdit from './slug-edit';\nimport SlugView from './slug-view';\n\nconst slugField: Field< BasePost > = {\n\tid: 'slug',\n\ttype: 'text',\n\tlabel: __( 'Slug' ),\n\tgetValue: ( { item } ) => item.slug,\n\tEdit: SlugEdit,\n\trender: SlugView,\n};\n\nexport default slugField;\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;;AAEA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,OAAOC,QAAQ,MAAM,aAAa;AAClC,OAAOC,QAAQ,MAAM,aAAa;AAElC,MAAMC,SAA4B,GAAG;EACpCC,EAAE,EAAE,MAAM;EACVC,IAAI,EAAE,MAAM;EACZC,KAAK,EAAEN,EAAE,CAAE,MAAO,CAAC;EACnBO,QAAQ,EAAEA,CAAE;IAAEC;EAAK,CAAC,KAAMA,IAAI,CAACC,IAAI;EACnCC,IAAI,EAAET,QAAQ;EACdU,MAAM,EAAET;AACT,CAAC;AAED,eAAeC,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Button, ExternalLink, __experimentalInputControl as InputControl, __experimentalInputControlPrefixWrapper as InputControlPrefixWrapper, __experimentalVStack as VStack } from '@wordpress/components';
|
|
5
|
+
import { copySmall } from '@wordpress/icons';
|
|
6
|
+
import { useCopyToClipboard, useInstanceId } from '@wordpress/compose';
|
|
7
|
+
import { useDispatch } from '@wordpress/data';
|
|
8
|
+
import { useCallback, useEffect, useRef } from '@wordpress/element';
|
|
9
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
10
|
+
import { safeDecodeURIComponent } from '@wordpress/url';
|
|
11
|
+
import { __ } from '@wordpress/i18n';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
17
|
+
const SlugEdit = ({
|
|
18
|
+
field,
|
|
19
|
+
onChange,
|
|
20
|
+
data
|
|
21
|
+
}) => {
|
|
22
|
+
var _field$getValue;
|
|
23
|
+
const {
|
|
24
|
+
id
|
|
25
|
+
} = field;
|
|
26
|
+
const slug = (_field$getValue = field.getValue({
|
|
27
|
+
item: data
|
|
28
|
+
})) !== null && _field$getValue !== void 0 ? _field$getValue : '';
|
|
29
|
+
const permalinkTemplate = data.permalink_template || '';
|
|
30
|
+
const PERMALINK_POSTNAME_REGEX = /%(?:postname|pagename)%/;
|
|
31
|
+
const [prefix, suffix] = permalinkTemplate.split(PERMALINK_POSTNAME_REGEX);
|
|
32
|
+
const permalinkPrefix = prefix;
|
|
33
|
+
const permalinkSuffix = suffix;
|
|
34
|
+
const isEditable = PERMALINK_POSTNAME_REGEX.test(permalinkTemplate);
|
|
35
|
+
const originalSlugRef = useRef(slug);
|
|
36
|
+
const slugToDisplay = slug || originalSlugRef.current;
|
|
37
|
+
const permalink = isEditable ? `${permalinkPrefix}${slugToDisplay}${permalinkSuffix}` : safeDecodeURIComponent(data.link || '');
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (slug && originalSlugRef.current === undefined) {
|
|
40
|
+
originalSlugRef.current = slug;
|
|
41
|
+
}
|
|
42
|
+
}, [slug]);
|
|
43
|
+
const onChangeControl = useCallback(newValue => onChange({
|
|
44
|
+
[id]: newValue
|
|
45
|
+
}), [id, onChange]);
|
|
46
|
+
const {
|
|
47
|
+
createNotice
|
|
48
|
+
} = useDispatch(noticesStore);
|
|
49
|
+
const copyButtonRef = useCopyToClipboard(permalink, () => {
|
|
50
|
+
createNotice('info', __('Copied Permalink to clipboard.'), {
|
|
51
|
+
isDismissible: true,
|
|
52
|
+
type: 'snackbar'
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
const postUrlSlugDescriptionId = 'editor-post-url__slug-description-' + useInstanceId(SlugEdit);
|
|
56
|
+
return /*#__PURE__*/_jsxs("fieldset", {
|
|
57
|
+
className: "fields-controls__slug",
|
|
58
|
+
children: [isEditable && /*#__PURE__*/_jsxs(VStack, {
|
|
59
|
+
children: [/*#__PURE__*/_jsxs(VStack, {
|
|
60
|
+
spacing: "0px",
|
|
61
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
62
|
+
children: __('Customize the last part of the Permalink.')
|
|
63
|
+
}), /*#__PURE__*/_jsx(ExternalLink, {
|
|
64
|
+
href: "https://wordpress.org/documentation/article/page-post-settings-sidebar/#permalink",
|
|
65
|
+
children: __('Learn more')
|
|
66
|
+
})]
|
|
67
|
+
}), /*#__PURE__*/_jsx(InputControl, {
|
|
68
|
+
__next40pxDefaultSize: true,
|
|
69
|
+
prefix: /*#__PURE__*/_jsx(InputControlPrefixWrapper, {
|
|
70
|
+
children: "/"
|
|
71
|
+
}),
|
|
72
|
+
suffix: /*#__PURE__*/_jsx(Button, {
|
|
73
|
+
__next40pxDefaultSize: true,
|
|
74
|
+
icon: copySmall,
|
|
75
|
+
ref: copyButtonRef,
|
|
76
|
+
label: __('Copy')
|
|
77
|
+
}),
|
|
78
|
+
label: __('Link'),
|
|
79
|
+
hideLabelFromVision: true,
|
|
80
|
+
value: slug,
|
|
81
|
+
autoComplete: "off",
|
|
82
|
+
spellCheck: "false",
|
|
83
|
+
type: "text",
|
|
84
|
+
className: "fields-controls__slug-input",
|
|
85
|
+
onChange: newValue => {
|
|
86
|
+
onChangeControl(newValue);
|
|
87
|
+
},
|
|
88
|
+
onBlur: () => {
|
|
89
|
+
if (slug === '') {
|
|
90
|
+
onChangeControl(originalSlugRef.current);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"aria-describedby": postUrlSlugDescriptionId,
|
|
94
|
+
help: /*#__PURE__*/_jsx(_Fragment, {
|
|
95
|
+
children: /*#__PURE__*/_jsxs("p", {
|
|
96
|
+
className: "fields-controls__slug-help",
|
|
97
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
98
|
+
className: "fields-controls__slug-help-visual-label",
|
|
99
|
+
children: __('Permalink:')
|
|
100
|
+
}), /*#__PURE__*/_jsxs(ExternalLink, {
|
|
101
|
+
className: "fields-controls__slug-help-link",
|
|
102
|
+
href: permalink,
|
|
103
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
104
|
+
className: "fields-controls__slug-help-prefix",
|
|
105
|
+
children: permalinkPrefix
|
|
106
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
107
|
+
className: "fields-controls__slug-help-slug",
|
|
108
|
+
children: slugToDisplay
|
|
109
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
110
|
+
className: "fields-controls__slug-help-suffix",
|
|
111
|
+
children: permalinkSuffix
|
|
112
|
+
})]
|
|
113
|
+
})]
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
})]
|
|
117
|
+
}), !isEditable && /*#__PURE__*/_jsx(ExternalLink, {
|
|
118
|
+
className: "fields-controls__slug-help",
|
|
119
|
+
href: permalink,
|
|
120
|
+
children: permalink
|
|
121
|
+
})]
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
export default SlugEdit;
|
|
125
|
+
//# sourceMappingURL=slug-edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Button","ExternalLink","__experimentalInputControl","InputControl","__experimentalInputControlPrefixWrapper","InputControlPrefixWrapper","__experimentalVStack","VStack","copySmall","useCopyToClipboard","useInstanceId","useDispatch","useCallback","useEffect","useRef","store","noticesStore","safeDecodeURIComponent","__","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","SlugEdit","field","onChange","data","_field$getValue","id","slug","getValue","item","permalinkTemplate","permalink_template","PERMALINK_POSTNAME_REGEX","prefix","suffix","split","permalinkPrefix","permalinkSuffix","isEditable","test","originalSlugRef","slugToDisplay","current","permalink","link","undefined","onChangeControl","newValue","createNotice","copyButtonRef","isDismissible","type","postUrlSlugDescriptionId","className","children","spacing","href","__next40pxDefaultSize","icon","ref","label","hideLabelFromVision","value","autoComplete","spellCheck","onBlur","help"],"sources":["@wordpress/fields/src/fields/slug/slug-edit.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tExternalLink,\n\t__experimentalInputControl as InputControl,\n\t__experimentalInputControlPrefixWrapper as InputControlPrefixWrapper,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { copySmall } from '@wordpress/icons';\nimport { useCopyToClipboard, useInstanceId } from '@wordpress/compose';\nimport { useDispatch } from '@wordpress/data';\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { safeDecodeURIComponent } from '@wordpress/url';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\n\nconst SlugEdit = ( {\n\tfield,\n\tonChange,\n\tdata,\n}: DataFormControlProps< BasePost > ) => {\n\tconst { id } = field;\n\n\tconst slug = field.getValue( { item: data } ) ?? '';\n\tconst permalinkTemplate = data.permalink_template || '';\n\tconst PERMALINK_POSTNAME_REGEX = /%(?:postname|pagename)%/;\n\tconst [ prefix, suffix ] = permalinkTemplate.split(\n\t\tPERMALINK_POSTNAME_REGEX\n\t);\n\tconst permalinkPrefix = prefix;\n\tconst permalinkSuffix = suffix;\n\tconst isEditable = PERMALINK_POSTNAME_REGEX.test( permalinkTemplate );\n\tconst originalSlugRef = useRef( slug );\n\tconst slugToDisplay = slug || originalSlugRef.current;\n\tconst permalink = isEditable\n\t\t? `${ permalinkPrefix }${ slugToDisplay }${ permalinkSuffix }`\n\t\t: safeDecodeURIComponent( data.link || '' );\n\n\tuseEffect( () => {\n\t\tif ( slug && originalSlugRef.current === undefined ) {\n\t\t\toriginalSlugRef.current = slug;\n\t\t}\n\t}, [ slug ] );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue?: string ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\tconst { createNotice } = useDispatch( noticesStore );\n\n\tconst copyButtonRef = useCopyToClipboard( permalink, () => {\n\t\tcreateNotice( 'info', __( 'Copied Permalink to clipboard.' ), {\n\t\t\tisDismissible: true,\n\t\t\ttype: 'snackbar',\n\t\t} );\n\t} );\n\n\tconst postUrlSlugDescriptionId =\n\t\t'editor-post-url__slug-description-' + useInstanceId( SlugEdit );\n\n\treturn (\n\t\t<fieldset className=\"fields-controls__slug\">\n\t\t\t{ isEditable && (\n\t\t\t\t<VStack>\n\t\t\t\t\t<VStack spacing=\"0px\">\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Customize the last part of the Permalink.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<ExternalLink href=\"https://wordpress.org/documentation/article/page-post-settings-sidebar/#permalink\">\n\t\t\t\t\t\t\t{ __( 'Learn more' ) }\n\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t</VStack>\n\t\t\t\t\t<InputControl\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tprefix={\n\t\t\t\t\t\t\t<InputControlPrefixWrapper>\n\t\t\t\t\t\t\t\t/\n\t\t\t\t\t\t\t</InputControlPrefixWrapper>\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsuffix={\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\ticon={ copySmall }\n\t\t\t\t\t\t\t\tref={ copyButtonRef }\n\t\t\t\t\t\t\t\tlabel={ __( 'Copy' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlabel={ __( 'Link' ) }\n\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\tvalue={ slug }\n\t\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\t\tspellCheck=\"false\"\n\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\tclassName=\"fields-controls__slug-input\"\n\t\t\t\t\t\tonChange={ ( newValue?: string ) => {\n\t\t\t\t\t\t\tonChangeControl( newValue );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonBlur={ () => {\n\t\t\t\t\t\t\tif ( slug === '' ) {\n\t\t\t\t\t\t\t\tonChangeControl( originalSlugRef.current );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\taria-describedby={ postUrlSlugDescriptionId }\n\t\t\t\t\t\thelp={\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<p className=\"fields-controls__slug-help\">\n\t\t\t\t\t\t\t\t\t<span className=\"fields-controls__slug-help-visual-label\">\n\t\t\t\t\t\t\t\t\t\t{ __( 'Permalink:' ) }\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\t\t\t\tclassName=\"fields-controls__slug-help-link\"\n\t\t\t\t\t\t\t\t\t\thref={ permalink }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<span className=\"fields-controls__slug-help-prefix\">\n\t\t\t\t\t\t\t\t\t\t\t{ permalinkPrefix }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t\t<span className=\"fields-controls__slug-help-slug\">\n\t\t\t\t\t\t\t\t\t\t\t{ slugToDisplay }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t\t<span className=\"fields-controls__slug-help-suffix\">\n\t\t\t\t\t\t\t\t\t\t\t{ permalinkSuffix }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</VStack>\n\t\t\t) }\n\t\t\t{ ! isEditable && (\n\t\t\t\t<ExternalLink\n\t\t\t\t\tclassName=\"fields-controls__slug-help\"\n\t\t\t\t\thref={ permalink }\n\t\t\t\t>\n\t\t\t\t\t{ permalink }\n\t\t\t\t</ExternalLink>\n\t\t\t) }\n\t\t</fieldset>\n\t);\n};\n\nexport default SlugEdit;\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,MAAM,EACNC,YAAY,EACZC,0BAA0B,IAAIC,YAAY,EAC1CC,uCAAuC,IAAIC,yBAAyB,EACpEC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAC9B,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,oBAAoB;AACtE,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ,oBAAoB;AACnE,SAASC,KAAK,IAAIC,YA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}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect, useRef } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const SlugView = ({
|
|
11
|
+
item
|
|
12
|
+
}) => {
|
|
13
|
+
const slug = item.slug;
|
|
14
|
+
const originalSlugRef = useRef(slug);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (slug && originalSlugRef.current === undefined) {
|
|
17
|
+
originalSlugRef.current = slug;
|
|
18
|
+
}
|
|
19
|
+
}, [slug]);
|
|
20
|
+
const slugToDisplay = slug || originalSlugRef.current;
|
|
21
|
+
return `/${slugToDisplay !== null && slugToDisplay !== void 0 ? slugToDisplay : ''}`;
|
|
22
|
+
};
|
|
23
|
+
export default SlugView;
|
|
24
|
+
//# sourceMappingURL=slug-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","SlugView","item","slug","originalSlugRef","current","undefined","slugToDisplay"],"sources":["@wordpress/fields/src/fields/slug/slug-view.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\n\nconst SlugView = ( { item }: { item: BasePost } ) => {\n\tconst slug = item.slug;\n\tconst originalSlugRef = useRef( slug );\n\n\tuseEffect( () => {\n\t\tif ( slug && originalSlugRef.current === undefined ) {\n\t\t\toriginalSlugRef.current = slug;\n\t\t}\n\t}, [ slug ] );\n\n\tconst slugToDisplay = slug || originalSlugRef.current;\n\n\treturn `/${ slugToDisplay ?? '' }`;\n};\n\nexport default SlugView;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,oBAAoB;;AAEtD;AACA;AACA;;AAGA,MAAMC,QAAQ,GAAGA,CAAE;EAAEC;AAAyB,CAAC,KAAM;EACpD,MAAMC,IAAI,GAAGD,IAAI,CAACC,IAAI;EACtB,MAAMC,eAAe,GAAGJ,MAAM,CAAEG,IAAK,CAAC;EAEtCJ,SAAS,CAAE,MAAM;IAChB,IAAKI,IAAI,IAAIC,eAAe,CAACC,OAAO,KAAKC,SAAS,EAAG;MACpDF,eAAe,CAACC,OAAO,GAAGF,IAAI;IAC/B;EACD,CAAC,EAAE,CAAEA,IAAI,CAAG,CAAC;EAEb,MAAMI,aAAa,GAAGJ,IAAI,IAAIC,eAAe,CAACC,OAAO;EAErD,OAAO,IAAKE,aAAa,aAAbA,aAAa,cAAbA,aAAa,GAAI,EAAE,EAAG;AACnC,CAAC;AAED,eAAeN,QAAQ","ignoreList":[]}
|
|
@@ -10,7 +10,7 @@ import { dispatch } from '@wordpress/data';
|
|
|
10
10
|
* Internal dependencies
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
function getErrorMessagesFromPromises(allSettledResults) {
|
|
14
14
|
const errorMessages = new Set();
|
|
15
15
|
// If there was at lease one failure.
|
|
16
16
|
if (allSettledResults.length === 1) {
|
|
@@ -30,7 +30,7 @@ const getErrorMessagesFromPromises = allSettledResults => {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
return errorMessages;
|
|
33
|
-
}
|
|
33
|
+
}
|
|
34
34
|
export const deletePostWithNotices = async (posts, notice, callbacks) => {
|
|
35
35
|
const {
|
|
36
36
|
createSuccessNotice,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["store","noticesStore","coreStore","dispatch","getErrorMessagesFromPromises","allSettledResults","errorMessages","Set","length","typedError","reason","message","add","failedPromises","filter","status","failedPromise","deletePostWithNotices","posts","notice","callbacks","createSuccessNotice","createErrorNotice","deleteEntityRecord","Promise","allSettled","map","post","type","id","force","throwOnError","every","_notice$success$type","successMessage","success","messages","getMessage","getBatchMessage","onActionPerformed","_notice$error$type","errorMessage","error","onActionError","editPostWithNotices","postsWithUpdates","editEntityRecord","saveEditedEntityRecord","originalPost","changes","_notice$success$type2","_notice$error$type2"],"sources":["@wordpress/fields/src/mutation/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { dispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { CoreDataError, Post } from '../types';\n\nconst getErrorMessagesFromPromises = < T >(\n\tallSettledResults: PromiseSettledResult< T >[]\n) => {\n\tconst errorMessages = new Set< string >();\n\t// If there was at lease one failure.\n\tif ( allSettledResults.length === 1 ) {\n\t\tconst typedError = allSettledResults[ 0 ] as {\n\t\t\treason?: CoreDataError;\n\t\t};\n\t\tif ( typedError.reason?.message ) {\n\t\t\terrorMessages.add( typedError.reason.message );\n\t\t}\n\t} else {\n\t\tconst failedPromises = allSettledResults.filter(\n\t\t\t( { status } ) => status === 'rejected'\n\t\t);\n\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\tconst typedError = failedPromise as {\n\t\t\t\treason?: CoreDataError;\n\t\t\t};\n\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\terrorMessages.add( typedError.reason.message );\n\t\t\t}\n\t\t}\n\t}\n\treturn errorMessages;\n};\n\nexport type NoticeSettings< T extends Post > = {\n\tsuccess: {\n\t\tid?: string;\n\t\ttype?: string;\n\t\tmessages: {\n\t\t\tgetMessage: ( posts: T ) => string;\n\t\t\tgetBatchMessage: ( posts: T[] ) => string;\n\t\t};\n\t};\n\terror: {\n\t\tid?: string;\n\t\ttype?: string;\n\t\tmessages: {\n\t\t\tgetMessage: ( errors: Set< string > ) => string;\n\t\t\tgetBatchMessage: ( errors: Set< string > ) => string;\n\t\t};\n\t};\n};\n\nexport const deletePostWithNotices = async < T extends Post >(\n\tposts: T[],\n\tnotice: NoticeSettings< T >,\n\tcallbacks: {\n\t\tonActionPerformed?: ( posts: T[] ) => void;\n\t\tonActionError?: () => void;\n\t}\n) => {\n\tconst { createSuccessNotice, createErrorNotice } = dispatch( noticesStore );\n\tconst { deleteEntityRecord } = dispatch( coreStore );\n\tconst allSettledResults = await Promise.allSettled(\n\t\tposts.map( ( post ) => {\n\t\t\treturn deleteEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpost.type,\n\t\t\t\tpost.id,\n\t\t\t\t{ force: true },\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t} )\n\t);\n\t// If all the promises were fulfilled with success.\n\tif ( allSettledResults.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\tlet successMessage;\n\t\tif ( allSettledResults.length === 1 ) {\n\t\t\tsuccessMessage = notice.success.messages.getMessage( posts[ 0 ] );\n\t\t} else {\n\t\t\tsuccessMessage = notice.success.messages.getBatchMessage( posts );\n\t\t}\n\t\tcreateSuccessNotice( successMessage, {\n\t\t\ttype: notice.success.type ?? 'snackbar',\n\t\t\tid: notice.success.id,\n\t\t} );\n\t\tcallbacks.onActionPerformed?.( posts );\n\t} else {\n\t\tconst errorMessages = getErrorMessagesFromPromises( allSettledResults );\n\t\tlet errorMessage = '';\n\t\tif ( allSettledResults.length === 1 ) {\n\t\t\terrorMessage = notice.error.messages.getMessage( errorMessages );\n\t\t} else {\n\t\t\terrorMessage =\n\t\t\t\tnotice.error.messages.getBatchMessage( errorMessages );\n\t\t}\n\n\t\tcreateErrorNotice( errorMessage, {\n\t\t\ttype: notice.error.type ?? 'snackbar',\n\t\t\tid: notice.error.id,\n\t\t} );\n\t\tcallbacks.onActionError?.();\n\t}\n};\n\nexport const editPostWithNotices = async < T extends Post >(\n\tpostsWithUpdates: {\n\t\toriginalPost: T;\n\t\tchanges: Partial< T >;\n\t}[],\n\tnotice: NoticeSettings< T >,\n\tcallbacks: {\n\t\tonActionPerformed?: ( posts: T[] ) => void;\n\t\tonActionError?: () => void;\n\t}\n) => {\n\tconst { createSuccessNotice, createErrorNotice } = dispatch( noticesStore );\n\tconst { editEntityRecord, saveEditedEntityRecord } = dispatch( coreStore );\n\tawait Promise.allSettled(\n\t\tpostsWithUpdates.map( ( post ) => {\n\t\t\treturn editEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpost.originalPost.type,\n\t\t\t\tpost.originalPost.id,\n\t\t\t\t{\n\t\t\t\t\t...post.changes,\n\t\t\t\t}\n\t\t\t);\n\t\t} )\n\t);\n\tconst allSettledResults = await Promise.allSettled(\n\t\tpostsWithUpdates.map( ( post ) => {\n\t\t\treturn saveEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpost.originalPost.type,\n\t\t\t\tpost.originalPost.id,\n\t\t\t\t{\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t}\n\t\t\t);\n\t\t} )\n\t);\n\t// If all the promises were fulfilled with success.\n\tif ( allSettledResults.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\tlet successMessage;\n\t\tif ( allSettledResults.length === 1 ) {\n\t\t\tsuccessMessage = notice.success.messages.getMessage(\n\t\t\t\tpostsWithUpdates[ 0 ].originalPost\n\t\t\t);\n\t\t} else {\n\t\t\tsuccessMessage = notice.success.messages.getBatchMessage(\n\t\t\t\tpostsWithUpdates.map( ( post ) => post.originalPost )\n\t\t\t);\n\t\t}\n\t\tcreateSuccessNotice( successMessage, {\n\t\t\ttype: notice.success.type ?? 'snackbar',\n\t\t\tid: notice.success.id,\n\t\t} );\n\t\tcallbacks.onActionPerformed?.(\n\t\t\tpostsWithUpdates.map( ( post ) => post.originalPost )\n\t\t);\n\t} else {\n\t\tconst errorMessages = getErrorMessagesFromPromises( allSettledResults );\n\t\tlet errorMessage = '';\n\t\tif ( allSettledResults.length === 1 ) {\n\t\t\terrorMessage = notice.error.messages.getMessage( errorMessages );\n\t\t} else {\n\t\t\terrorMessage =\n\t\t\t\tnotice.error.messages.getBatchMessage( errorMessages );\n\t\t}\n\n\t\tcreateErrorNotice( errorMessage, {\n\t\t\ttype: notice.error.type ?? 'snackbar',\n\t\t\tid: notice.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M,CAACuB,KAAK,CAACb;IAClB,CAAE,CAAC;IACHT,SAAS,CAACuB,aAAa,GAAG,CAAC;EAC5B;AACD,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["store","noticesStore","coreStore","dispatch","getErrorMessagesFromPromises","allSettledResults","errorMessages","Set","length","typedError","reason","message","add","failedPromises","filter","status","failedPromise","deletePostWithNotices","posts","notice","callbacks","createSuccessNotice","createErrorNotice","deleteEntityRecord","Promise","allSettled","map","post","type","id","force","throwOnError","every","_notice$success$type","successMessage","success","messages","getMessage","getBatchMessage","onActionPerformed","_notice$error$type","errorMessage","error","onActionError","editPostWithNotices","postsWithUpdates","editEntityRecord","saveEditedEntityRecord","originalPost","changes","_notice$success$type2","_notice$error$type2"],"sources":["@wordpress/fields/src/mutation/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { dispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { CoreDataError, Post } from '../types';\n\nfunction getErrorMessagesFromPromises< T >(\n\tallSettledResults: PromiseSettledResult< T >[]\n) {\n\tconst errorMessages = new Set< string >();\n\t// If there was at lease one failure.\n\tif ( allSettledResults.length === 1 ) {\n\t\tconst typedError = allSettledResults[ 0 ] as {\n\t\t\treason?: CoreDataError;\n\t\t};\n\t\tif ( typedError.reason?.message ) {\n\t\t\terrorMessages.add( typedError.reason.message );\n\t\t}\n\t} else {\n\t\tconst failedPromises = allSettledResults.filter(\n\t\t\t( { status } ) => status === 'rejected'\n\t\t);\n\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\tconst typedError = failedPromise as {\n\t\t\t\treason?: CoreDataError;\n\t\t\t};\n\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\terrorMessages.add( typedError.reason.message );\n\t\t\t}\n\t\t}\n\t}\n\treturn errorMessages;\n}\n\nexport type NoticeSettings< T extends Post > = {\n\tsuccess: {\n\t\tid?: string;\n\t\ttype?: string;\n\t\tmessages: {\n\t\t\tgetMessage: ( posts: T ) => string;\n\t\t\tgetBatchMessage: ( posts: T[] ) => string;\n\t\t};\n\t};\n\terror: {\n\t\tid?: string;\n\t\ttype?: string;\n\t\tmessages: {\n\t\t\tgetMessage: ( errors: Set< string > ) => string;\n\t\t\tgetBatchMessage: ( errors: Set< string > ) => string;\n\t\t};\n\t};\n};\n\nexport const deletePostWithNotices = async < T extends Post >(\n\tposts: T[],\n\tnotice: NoticeSettings< T >,\n\tcallbacks: {\n\t\tonActionPerformed?: ( posts: T[] ) => void;\n\t\tonActionError?: () => void;\n\t}\n) => {\n\tconst { createSuccessNotice, createErrorNotice } = dispatch( noticesStore );\n\tconst { deleteEntityRecord } = dispatch( coreStore );\n\tconst allSettledResults = await Promise.allSettled(\n\t\tposts.map( ( post ) => {\n\t\t\treturn deleteEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpost.type,\n\t\t\t\tpost.id,\n\t\t\t\t{ force: true },\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t} )\n\t);\n\t// If all the promises were fulfilled with success.\n\tif ( allSettledResults.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\tlet successMessage;\n\t\tif ( allSettledResults.length === 1 ) {\n\t\t\tsuccessMessage = notice.success.messages.getMessage( posts[ 0 ] );\n\t\t} else {\n\t\t\tsuccessMessage = notice.success.messages.getBatchMessage( posts );\n\t\t}\n\t\tcreateSuccessNotice( successMessage, {\n\t\t\ttype: notice.success.type ?? 'snackbar',\n\t\t\tid: notice.success.id,\n\t\t} );\n\t\tcallbacks.onActionPerformed?.( posts );\n\t} else {\n\t\tconst errorMessages = getErrorMessagesFromPromises( allSettledResults );\n\t\tlet errorMessage = '';\n\t\tif ( allSettledResults.length === 1 ) {\n\t\t\terrorMessage = notice.error.messages.getMessage( errorMessages );\n\t\t} else {\n\t\t\terrorMessage =\n\t\t\t\tnotice.error.messages.getBatchMessage( errorMessages );\n\t\t}\n\n\t\tcreateErrorNotice( errorMessage, {\n\t\t\ttype: notice.error.type ?? 'snackbar',\n\t\t\tid: notice.error.id,\n\t\t} );\n\t\tcallbacks.onActionError?.();\n\t}\n};\n\nexport const editPostWithNotices = async < T extends Post >(\n\tpostsWithUpdates: {\n\t\toriginalPost: T;\n\t\tchanges: Partial< T >;\n\t}[],\n\tnotice: NoticeSettings< T >,\n\tcallbacks: {\n\t\tonActionPerformed?: ( posts: T[] ) => void;\n\t\tonActionError?: () => void;\n\t}\n) => {\n\tconst { createSuccessNotice, createErrorNotice } = dispatch( noticesStore );\n\tconst { editEntityRecord, saveEditedEntityRecord } = dispatch( coreStore );\n\tawait Promise.allSettled(\n\t\tpostsWithUpdates.map( ( post ) => {\n\t\t\treturn editEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpost.originalPost.type,\n\t\t\t\tpost.originalPost.id,\n\t\t\t\t{\n\t\t\t\t\t...post.changes,\n\t\t\t\t}\n\t\t\t);\n\t\t} )\n\t);\n\tconst allSettledResults = await Promise.allSettled(\n\t\tpostsWithUpdates.map( ( post ) => {\n\t\t\treturn saveEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpost.originalPost.type,\n\t\t\t\tpost.originalPost.id,\n\t\t\t\t{\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t}\n\t\t\t);\n\t\t} )\n\t);\n\t// If all the promises were fulfilled with success.\n\tif ( allSettledResults.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\tlet successMessage;\n\t\tif ( allSettledResults.length === 1 ) {\n\t\t\tsuccessMessage = notice.success.messages.getMessage(\n\t\t\t\tpostsWithUpdates[ 0 ].originalPost\n\t\t\t);\n\t\t} else {\n\t\t\tsuccessMessage = notice.success.messages.getBatchMessage(\n\t\t\t\tpostsWithUpdates.map( ( post ) => post.originalPost )\n\t\t\t);\n\t\t}\n\t\tcreateSuccessNotice( successMessage, {\n\t\t\ttype: notice.success.type ?? 'snackbar',\n\t\t\tid: notice.success.id,\n\t\t} );\n\t\tcallbacks.onActionPerformed?.(\n\t\t\tpostsWithUpdates.map( ( post ) => post.originalPost )\n\t\t);\n\t} else {\n\t\tconst errorMessages = getErrorMessagesFromPromises( allSettledResults );\n\t\tlet errorMessage = '';\n\t\tif ( allSettledResults.length === 1 ) {\n\t\t\terrorMessage = notice.error.messages.getMessage( errorMessages );\n\t\t} else {\n\t\t\terrorMessage =\n\t\t\t\tnotice.error.messages.getBatchMessage( errorMessages );\n\t\t}\n\n\t\tcreateErrorNotice( errorMessage, {\n\t\t\ttype: notice.error.type ?? 'snackbar',\n\t\t\tid: notice.error.id,\n\t\t} );\n\t\tcallbacks.onActionError?.();\n\t}\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,YAAY,QAAQ,oBAAoB;AAC1D,SAASD,KAAK,IAAIE,SAAS,QAAQ,sBAAsB;AACzD,SAASC,QAAQ,QAAQ,iBAAiB;;AAE1C;AACA;AACA;;AAGA,SAASC,4BAA4BA,CACpCC,iBAA8C,EAC7C;EACD,MAAMC,aAAa,GAAG,IAAIC,GAAG,CAAW,CAAC;EACzC;EACA,IAAKF,iBAAiB,CAACG,MAAM,KAAK,CAAC,EAAG;IACrC,MAAMC,UAAU,GAAGJ,iBAAiB,CAAE,CAAC,CAEtC;IACD,IAAKI,UAAU,CAACC,MAAM,EAAEC,OAAO,EAAG;MACjCL,aAAa,CAACM,GAAG,CAAEH,UAAU,CAACC,MAAM,CAACC,OAAQ,CAAC;IAC/C;EACD,CAAC,MAAM;IACN,MAAME,cAAc,GAAGR,iBAAiB,CAACS,MAAM,CAC9C,CAAE;MAAEC;IAAO,CAAC,KAAMA,MAAM,KAAK,UAC9B,CAAC;IACD,KAAM,MAAMC,aAAa,IAAIH,cAAc,EAAG;MAC7C,MAAMJ,UAAU,GAAGO,aAElB;MACD,IAAKP,UAAU,CAACC,MAAM,EAAEC,OAAO,EAAG;QACjCL,aAAa,CAACM,GAAG,CAAEH,UAAU,CAACC,MAAM,C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C,YAAY,GAAGtB,MAAM,CAACuB,KAAK,CAACN,QAAQ,CAACC,UAAU,CAAE/B,aAAc,CAAC;IACjE,CAAC,MAAM;MACNmC,YAAY,GACXtB,MAAM,CAACuB,KAAK,CAACN,QAAQ,CAACE,eAAe,CAAEhC,aAAc,CAAC;IACxD;IAEAgB,iBAAiB,CAAEmB,YAAY,EAAE;MAChCb,IAAI,GAAAuB,mBAAA,GAAEhC,MAAM,CAACuB,KAAK,CAACd,IAAI,cAAAuB,mBAAA,cAAAA,mBAAA,GAAI,UAAU;MACrCtB,EAAE,EAAEV,MAAM,CAACuB,KAAK,CAACb;IAClB,CAAE,CAAC;IACHT,SAAS,CAACuB,aAAa,GAAG,CAAC;EAC5B;AACD,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/fields/src/types.ts"],"sourcesContent":["type PostStatus =\n\t| 'published'\n\t| 'draft'\n\t| 'pending'\n\t| 'private'\n\t| 'future'\n\t| 'auto-draft'\n\t| 'trash';\n\nexport interface CommonPost {\n\tstatus?: PostStatus;\n\ttitle: string | { rendered: string } | { raw: string };\n\tcontent: string | { raw: string; rendered: string };\n\ttype: string;\n\tid: string | number;\n\tblocks?: Object[];\n\t_links?: Links;\n}\n\ninterface Links {\n\t'predecessor-version'?: { href: string; id: number }[];\n\t'version-history'?: { href: string; count: number }[];\n\t[ key: string ]: { href: string }[] | undefined;\n}\n\nexport interface BasePost extends CommonPost {\n\tcomment_status?: 'open' | 'closed';\n\texcerpt?: string | { raw: string; rendered: string };\n\tmeta?: Record< string, any >;\n\tparent?: number;\n\tpassword?: string;\n\ttemplate?: string;\n\tformat?: string;\n\tfeatured_media?: number;\n\tmenu_order?: number;\n\tping_status?: 'open' | 'closed';\n\tlink?: string;\n}\n\nexport interface Template extends CommonPost {\n\ttype: 'wp_template';\n\tis_custom: boolean;\n\tsource: string;\n\torigin: string;\n\tplugin?: string;\n\thas_theme_file: boolean;\n\tid: string;\n}\n\nexport interface TemplatePart extends CommonPost {\n\ttype: 'wp_template_part';\n\tsource: string;\n\torigin: string;\n\thas_theme_file: boolean;\n\tid: string;\n\tarea: string;\n\tplugin?: string;\n}\n\nexport interface Pattern extends CommonPost {\n\tslug: string;\n\ttitle: { raw: string };\n\twp_pattern_sync_status: string;\n}\n\nexport type Post = Template | TemplatePart | Pattern | BasePost;\n\nexport type PostWithPermissions = Post & {\n\tpermissions: {\n\t\tdelete: boolean;\n\t\tupdate: boolean;\n\t};\n};\n\nexport interface PostType {\n\tslug: string;\n\tviewable: boolean;\n\tsupports?: {\n\t\t'page-attributes'?: boolean;\n\t\ttitle?: boolean;\n\t\trevisions?: boolean;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/fields/src/types.ts"],"sourcesContent":["type PostStatus =\n\t| 'published'\n\t| 'draft'\n\t| 'pending'\n\t| 'private'\n\t| 'future'\n\t| 'auto-draft'\n\t| 'trash';\n\nexport interface CommonPost {\n\tstatus?: PostStatus;\n\ttitle: string | { rendered: string } | { raw: string };\n\tcontent: string | { raw: string; rendered: string };\n\ttype: string;\n\tid: string | number;\n\tblocks?: Object[];\n\t_links?: Links;\n}\n\ninterface Links {\n\t'predecessor-version'?: { href: string; id: number }[];\n\t'version-history'?: { href: string; count: number }[];\n\t[ key: string ]: { href: string }[] | undefined;\n}\n\nexport interface BasePost extends CommonPost {\n\tcomment_status?: 'open' | 'closed';\n\texcerpt?: string | { raw: string; rendered: string };\n\tmeta?: Record< string, any >;\n\tparent?: number;\n\tpassword?: string;\n\ttemplate?: string;\n\tformat?: string;\n\tfeatured_media?: number;\n\tmenu_order?: number;\n\tping_status?: 'open' | 'closed';\n\tlink?: string;\n\tslug?: string;\n\tpermalink_template?: string;\n}\n\nexport interface Template extends CommonPost {\n\ttype: 'wp_template';\n\tis_custom: boolean;\n\tsource: string;\n\torigin: string;\n\tplugin?: string;\n\thas_theme_file: boolean;\n\tid: string;\n}\n\nexport interface TemplatePart extends CommonPost {\n\ttype: 'wp_template_part';\n\tsource: string;\n\torigin: string;\n\thas_theme_file: boolean;\n\tid: string;\n\tarea: string;\n\tplugin?: string;\n}\n\nexport interface Pattern extends CommonPost {\n\tslug: string;\n\ttitle: { raw: string };\n\twp_pattern_sync_status: string;\n}\n\nexport type Post = Template | TemplatePart | Pattern | BasePost;\n\nexport type PostWithPermissions = Post & {\n\tpermissions: {\n\t\tdelete: boolean;\n\t\tupdate: boolean;\n\t};\n};\n\nexport interface PostType {\n\tslug: string;\n\tviewable: boolean;\n\tsupports?: {\n\t\t'page-attributes'?: boolean;\n\t\ttitle?: boolean;\n\t\trevisions?: boolean;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],"mappings":"","ignoreList":[]}
|