@wordpress/fields 0.24.1-next.ff1cebbba.0 → 0.25.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/build/actions/duplicate-post.js +3 -0
- package/build/actions/duplicate-post.js.map +2 -2
- package/build/actions/reorder-page.js +14 -7
- package/build/actions/reorder-page.js.map +2 -2
- package/build/fields/author/index.js +15 -1
- package/build/fields/author/index.js.map +3 -3
- package/build-module/actions/duplicate-post.js +3 -0
- package/build-module/actions/duplicate-post.js.map +2 -2
- package/build-module/actions/reorder-page.js +15 -8
- package/build-module/actions/reorder-page.js.map +2 -2
- package/build-module/fields/author/index.js +15 -1
- package/build-module/fields/author/index.js.map +2 -2
- package/build-types/actions/duplicate-post.d.ts.map +1 -1
- package/build-types/actions/reorder-page.d.ts.map +1 -1
- package/build-types/fields/author/index.d.ts.map +1 -1
- package/package.json +26 -26
- package/src/actions/duplicate-post.tsx +7 -0
- package/src/actions/reorder-page.tsx +15 -8
- package/src/fields/author/index.tsx +21 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -121,6 +121,9 @@ const duplicatePost = {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("form", { onSubmit: createPage, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: 3, children: [
|
|
124
|
+
item.type === "wp_registered_template" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: (0, import_i18n.__)(
|
|
125
|
+
"You are about to duplicate a bundled template. Changes will not be live until you activate the new template."
|
|
126
|
+
) }),
|
|
124
127
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
125
128
|
import_dataviews.DataForm,
|
|
126
129
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/actions/duplicate-post.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { titleField } from '../fields';\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\nconst fields = [ titleField ];\nconst formDuplicateAction = {\n\tfields: [ 'title' ],\n};\n\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isTemplate =\n\t\t\t\titem.type === 'wp_template' ||\n\t\t\t\titem.type === 'wp_registered_template';\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: isTemplate ? 'publish' : 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: isTemplate ? item.slug : item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type === 'wp_registered_template'\n\t\t\t\t\t\t? 'wp_template'\n\t\t\t\t\t\t: item.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tgetItemTitle( newItem )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t<DataForm\n\t\t\t\t\t\tdata={ item }\n\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\tform={ formDuplicateAction }\n\t\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t...changes,\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\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Duplicate action for BasePost.\n */\nexport default duplicatePost;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { titleField } from '../fields';\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\nconst fields = [ titleField ];\nconst formDuplicateAction = {\n\tfields: [ 'title' ],\n};\n\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isTemplate =\n\t\t\t\titem.type === 'wp_template' ||\n\t\t\t\titem.type === 'wp_registered_template';\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: isTemplate ? 'publish' : 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: isTemplate ? item.slug : item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type === 'wp_registered_template'\n\t\t\t\t\t\t? 'wp_template'\n\t\t\t\t\t\t: item.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tgetItemTitle( newItem )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t{ item.type === 'wp_registered_template' && (\n\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'You are about to duplicate a bundled template. Changes will not be live until you activate the new template.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t\t<DataForm\n\t\t\t\t\t\tdata={ item }\n\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\tform={ formDuplicateAction }\n\t\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t...changes,\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\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Duplicate action for BasePost.\n */\nexport default duplicatePost;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiJM;AA9IN,kBAA4B;AAC5B,uBAAmC;AACnC,kBAAgC;AAChC,qBAAsC;AACtC,qBAAyB;AACzB,uBAAyB;AACzB,wBA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ED;AAAA,QAAC;AAAA;AAAA,UACA,MAAO;AAAA,UACP;AAAA,UACA,MAAO;AAAA,UACP,UAAW,CAAE,YACZ,QAAS,CAAE,UAAY;AAAA,YACtB,GAAG;AAAA,YACH,GAAG;AAAA,UACJ,EAAI;AAAA;AAAA,MAEN;AAAA,MACA,6CAAC,kBAAAC,sBAAA,EAAO,SAAU,GAAI,SAAQ,OAC7B;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,SAAQ;AAAA,YACR,SAAU;AAAA,YACV,uBAAqB;AAAA,YAEnB,8BAAI,QAAS;AAAA;AAAA,QAChB;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,SAAQ;AAAA,YACR,MAAK;AAAA,YACL,QAAS;AAAA,YACT,iBAAgB;AAAA,YAChB,uBAAqB;AAAA,YAEnB,8BAAI,aAAa,cAAe;AAAA;AAAA,QACnC;AAAA,SACD;AAAA,OACD,GACD;AAAA,EAEF;AACD;AAKA,IAAO,yBAAQ;",
|
|
6
6
|
"names": ["coreStore", "noticesStore", "VStack", "HStack"]
|
|
7
7
|
}
|
|
@@ -43,9 +43,14 @@ function ReorderModal({
|
|
|
43
43
|
const orderInput = item.menu_order;
|
|
44
44
|
const { editEntityRecord, saveEditedEntityRecord } = (0, import_data.useDispatch)(import_core_data.store);
|
|
45
45
|
const { createSuccessNotice, createErrorNotice } = (0, import_data.useDispatch)(import_notices.store);
|
|
46
|
+
const { validity, isValid } = (0, import_dataviews.useFormValidity)(
|
|
47
|
+
item,
|
|
48
|
+
fields,
|
|
49
|
+
formOrderAction
|
|
50
|
+
);
|
|
46
51
|
async function onOrder(event) {
|
|
47
52
|
event.preventDefault();
|
|
48
|
-
if (!
|
|
53
|
+
if (!isValid) {
|
|
49
54
|
return;
|
|
50
55
|
}
|
|
51
56
|
try {
|
|
@@ -68,7 +73,6 @@ function ReorderModal({
|
|
|
68
73
|
});
|
|
69
74
|
}
|
|
70
75
|
}
|
|
71
|
-
const isSaveDisabled = !(0, import_dataviews.isItemValid)(item, fields, formOrderAction);
|
|
72
76
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("form", { onSubmit: onOrder, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: "5", children: [
|
|
73
77
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: (0, import_i18n.__)(
|
|
74
78
|
"Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported."
|
|
@@ -79,10 +83,13 @@ function ReorderModal({
|
|
|
79
83
|
data: item,
|
|
80
84
|
fields,
|
|
81
85
|
form: formOrderAction,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
validity,
|
|
87
|
+
onChange: (changes) => {
|
|
88
|
+
return setItem({
|
|
89
|
+
...item,
|
|
90
|
+
...changes
|
|
91
|
+
});
|
|
92
|
+
}
|
|
86
93
|
}
|
|
87
94
|
),
|
|
88
95
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { justify: "right", children: [
|
|
@@ -104,7 +111,7 @@ function ReorderModal({
|
|
|
104
111
|
variant: "primary",
|
|
105
112
|
type: "submit",
|
|
106
113
|
accessibleWhenDisabled: true,
|
|
107
|
-
disabled:
|
|
114
|
+
disabled: !isValid,
|
|
108
115
|
children: (0, import_i18n.__)("Save")
|
|
109
116
|
}
|
|
110
117
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/actions/reorder-page.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm,
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm, useFormValidity } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action, RenderModalProps } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { CoreDataError, BasePost } from '../types';\nimport { orderField } from '../fields';\n\nconst fields = [ orderField ];\nconst formOrderAction = {\n\tfields: [ 'menu_order' ],\n};\n\nfunction ReorderModal( {\n\titems,\n\tcloseModal,\n\tonActionPerformed,\n}: RenderModalProps< BasePost > ) {\n\tconst [ item, setItem ] = useState( items[ 0 ] );\n\tconst orderInput = item.menu_order;\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst { validity, isValid } = useFormValidity(\n\t\titem,\n\t\tfields,\n\t\tformOrderAction\n\t);\n\n\tasync function onOrder( event: React.FormEvent ) {\n\t\tevent.preventDefault();\n\n\t\tif ( ! isValid ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tmenu_order: orderInput,\n\t\t\t} );\n\t\t\tcloseModal?.();\n\t\t\t// Persist edited entity.\n\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tthrowOnError: true,\n\t\t\t} );\n\t\t\tcreateSuccessNotice( __( 'Order updated.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t\tonActionPerformed?.( items );\n\t\t} catch ( error ) {\n\t\t\tconst typedError = error as CoreDataError;\n\t\t\tconst errorMessage =\n\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t? typedError.message\n\t\t\t\t\t: __( 'An error occurred while updating the order' );\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\n\treturn (\n\t\t<form onSubmit={ onOrder }>\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<div>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ item }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ formOrderAction }\n\t\t\t\t\tvalidity={ validity }\n\t\t\t\t\tonChange={ ( changes ) => {\n\t\t\t\t\t\treturn setItem( {\n\t\t\t\t\t\t\t...item,\n\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tdisabled={ ! isValid }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t</form>\n\t);\n}\n\nconst reorderPage: Action< BasePost > = {\n\tid: 'order-pages',\n\tlabel: __( 'Order' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ReorderModal,\n};\n\n/**\n * Reorder action for BasePost.\n */\nexport default reorderPage;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgFI;AA7EJ,kBAA4B;AAC5B,uBAAmC;AACnC,kBAAmB;AACnB,qBAAsC;AACtC,qBAAyB;AACzB,uBAA0C;AAC1C,wBAIO;AAOP,oBAA2B;AAE3B,MAAM,SAAS,CAAE,wBAAW;AAC5B,MAAM,kBAAkB;AAAA,EACvB,QAAQ,CAAE,YAAa;AACxB;AAEA,SAAS,aAAc;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AACD,GAAkC;AACjC,QAAM,CAAE,MAAM,OAAQ,QAAI,yBAAU,MAAO,CAAE,CAAE;AAC/C,QAAM,aAAa,KAAK;AACxB,QAAM,EAAE,kBAAkB,uBAAuB,QAChD,yBAAa,iBAAAA,KAAU;AACxB,QAAM,EAAE,qBAAqB,kBAAkB,QAC9C,yBAAa,eAAAC,KAAa;AAE3B,QAAM,EAAE,UAAU,QAAQ,QAAI;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,iBAAe,QAAS,OAAyB;AAChD,UAAM,eAAe;AAErB,QAAK,CAAE,SAAU;AAChB;AAAA,IACD;AAEA,QAAI;AACH,YAAM,iBAAkB,YAAY,KAAK,MAAM,KAAK,IAAI;AAAA,QACvD,YAAY;AAAA,MACb,CAAE;AACF,mBAAa;AAEb,YAAM,uBAAwB,YAAY,KAAK,MAAM,KAAK,IAAI;AAAA,QAC7D,cAAc;AAAA,MACf,CAAE;AACF,8BAAqB,gBAAI,gBAAiB,GAAG;AAAA,QAC5C,MAAM;AAAA,MACP,CAAE;AACF,0BAAqB,KAAM;AAAA,IAC5B,SAAU,OAAQ;AACjB,YAAM,aAAa;AACnB,YAAM,eACL,WAAW,WAAW,WAAW,SAAS,kBACvC,WAAW,cACX,gBAAI,4CAA6C;AACrD,wBAAmB,cAAc;AAAA,QAChC,MAAM;AAAA,MACP,CAAE;AAAA,IACH;AAAA,EACD;AAEA,SACC,4CAAC,UAAK,UAAW,SAChB,uDAAC,kBAAAC,sBAAA,EAAO,SAAQ,KACf;AAAA,gDAAC,SACE;AAAA,MACD;AAAA,IACD,GACD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP;AAAA,QACA,MAAO;AAAA,QACP;AAAA,QACA,UAAW,CAAE,YAAa;AACzB,iBAAO,QAAS;AAAA,YACf,GAAG;AAAA,YACH,GAAG;AAAA,UACJ,CAAE;AAAA,QACH;AAAA;AAAA,IACD;AAAA,IACA,6CAAC,kBAAAC,sBAAA,EAAO,SAAQ,SACf;AAAA;AAAA,QAAC;AAAA;AAAA,UACA,uBAAqB;AAAA,UACrB,SAAQ;AAAA,UACR,SAAU,MAAM;AACf,yBAAa;AAAA,UACd;AAAA,UAEE,8BAAI,QAAS;AAAA;AAAA,MAChB;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACA,uBAAqB;AAAA,UACrB,SAAQ;AAAA,UACR,MAAK;AAAA,UACL,wBAAsB;AAAA,UACtB,UAAW,CAAE;AAAA,UAEX,8BAAI,MAAO;AAAA;AAAA,MACd;AAAA,OACD;AAAA,KACD,GACD;AAEF;AAEA,MAAM,cAAkC;AAAA,EACvC,IAAI;AAAA,EACJ,WAAO,gBAAI,OAAQ;AAAA,EACnB,WAAY,EAAE,OAAO,GAAI;AACxB,WAAO,WAAW;AAAA,EACnB;AAAA,EACA,mBAAmB;AAAA,EACnB,aAAa;AACd;AAKA,IAAO,uBAAQ;",
|
|
6
6
|
"names": ["coreStore", "noticesStore", "VStack", "HStack"]
|
|
7
7
|
}
|
|
@@ -32,12 +32,26 @@ __export(author_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(author_exports);
|
|
34
34
|
var import_i18n = require("@wordpress/i18n");
|
|
35
|
+
var import_data = require("@wordpress/data");
|
|
36
|
+
var import_core_data = require("@wordpress/core-data");
|
|
35
37
|
var import_author_view = __toESM(require("./author-view"));
|
|
36
38
|
const authorField = {
|
|
37
39
|
label: (0, import_i18n.__)("Author"),
|
|
38
40
|
id: "author",
|
|
39
41
|
type: "integer",
|
|
40
|
-
|
|
42
|
+
getElements: async () => {
|
|
43
|
+
const authors = await (0, import_data.resolveSelect)(import_core_data.store).getEntityRecords(
|
|
44
|
+
"root",
|
|
45
|
+
"user",
|
|
46
|
+
{
|
|
47
|
+
per_page: -1
|
|
48
|
+
}
|
|
49
|
+
) ?? [];
|
|
50
|
+
return authors.map(({ id, name }) => ({
|
|
51
|
+
value: id,
|
|
52
|
+
label: name
|
|
53
|
+
}));
|
|
54
|
+
},
|
|
41
55
|
render: import_author_view.default,
|
|
42
56
|
sort: (a, b, direction) => {
|
|
43
57
|
const nameA = a._embedded?.author?.[0]?.name || "";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/fields/author/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\nimport AuthorView from './author-view';\n\nconst authorField: Field< BasePostWithEmbeddedAuthor > = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\ttype: 'integer',\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBAAmB;
|
|
6
|
-
"names": ["AuthorView"]
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\nimport { resolveSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\nimport AuthorView from './author-view';\n\ninterface Author {\n\tid: number;\n\tname: string;\n}\n\nconst authorField: Field< BasePostWithEmbeddedAuthor > = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\ttype: 'integer',\n\tgetElements: async () => {\n\t\tconst authors: Author[] =\n\t\t\t( await resolveSelect( coreDataStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'user',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t) ) ?? [];\n\t\treturn authors.map( ( { id, name } ) => ( {\n\t\t\tvalue: id,\n\t\t\tlabel: name,\n\t\t} ) );\n\t},\n\trender: AuthorView,\n\tsort: ( a, b, direction ) => {\n\t\tconst nameA = a._embedded?.author?.[ 0 ]?.name || '';\n\t\tconst nameB = b._embedded?.author?.[ 0 ]?.name || '';\n\n\t\treturn direction === 'asc'\n\t\t\t? nameA.localeCompare( nameB )\n\t\t\t: nameB.localeCompare( nameA );\n\t},\n\n\tfilterBy: {\n\t\toperators: [ 'isAny', 'isNone' ],\n\t},\n};\n\n/**\n * Author field for BasePost.\n */\nexport default authorField;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBAAmB;AACnB,kBAA8B;AAC9B,uBAAuC;AAMvC,yBAAuB;AAOvB,MAAM,cAAmD;AAAA,EACxD,WAAO,gBAAI,QAAS;AAAA,EACpB,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,aAAa,YAAY;AACxB,UAAM,UACH,UAAM,2BAAe,iBAAAA,KAAc,EAAE;AAAA,MACtC;AAAA,MACA;AAAA,MACA;AAAA,QACC,UAAU;AAAA,MACX;AAAA,IACD,KAAO,CAAC;AACT,WAAO,QAAQ,IAAK,CAAE,EAAE,IAAI,KAAK,OAAS;AAAA,MACzC,OAAO;AAAA,MACP,OAAO;AAAA,IACR,EAAI;AAAA,EACL;AAAA,EACA,QAAQ,mBAAAC;AAAA,EACR,MAAM,CAAE,GAAG,GAAG,cAAe;AAC5B,UAAM,QAAQ,EAAE,WAAW,SAAU,CAAE,GAAG,QAAQ;AAClD,UAAM,QAAQ,EAAE,WAAW,SAAU,CAAE,GAAG,QAAQ;AAElD,WAAO,cAAc,QAClB,MAAM,cAAe,KAAM,IAC3B,MAAM,cAAe,KAAM;AAAA,EAC/B;AAAA,EAEA,UAAU;AAAA,IACT,WAAW,CAAE,SAAS,QAAS;AAAA,EAChC;AACD;AAKA,IAAO,iBAAQ;",
|
|
6
|
+
"names": ["coreDataStore", "AuthorView"]
|
|
7
7
|
}
|
|
@@ -102,6 +102,9 @@ const duplicatePost = {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
return /* @__PURE__ */ jsx("form", { onSubmit: createPage, children: /* @__PURE__ */ jsxs(VStack, { spacing: 3, children: [
|
|
105
|
+
item.type === "wp_registered_template" && /* @__PURE__ */ jsx("div", { children: __(
|
|
106
|
+
"You are about to duplicate a bundled template. Changes will not be live until you activate the new template."
|
|
107
|
+
) }),
|
|
105
108
|
/* @__PURE__ */ jsx(
|
|
106
109
|
DataForm,
|
|
107
110
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/actions/duplicate-post.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { titleField } from '../fields';\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\nconst fields = [ titleField ];\nconst formDuplicateAction = {\n\tfields: [ 'title' ],\n};\n\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isTemplate =\n\t\t\t\titem.type === 'wp_template' ||\n\t\t\t\titem.type === 'wp_registered_template';\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: isTemplate ? 'publish' : 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: isTemplate ? item.slug : item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type === 'wp_registered_template'\n\t\t\t\t\t\t? 'wp_template'\n\t\t\t\t\t\t: item.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tgetItemTitle( newItem )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t<DataForm\n\t\t\t\t\t\tdata={ item }\n\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\tform={ formDuplicateAction }\n\t\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t...changes,\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\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Duplicate action for BasePost.\n */\nexport default duplicatePost;\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { titleField } from '../fields';\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\nconst fields = [ titleField ];\nconst formDuplicateAction = {\n\tfields: [ 'title' ],\n};\n\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isTemplate =\n\t\t\t\titem.type === 'wp_template' ||\n\t\t\t\titem.type === 'wp_registered_template';\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: isTemplate ? 'publish' : 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: isTemplate ? item.slug : item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type === 'wp_registered_template'\n\t\t\t\t\t\t? 'wp_template'\n\t\t\t\t\t\t: item.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tgetItemTitle( newItem )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t{ item.type === 'wp_registered_template' && (\n\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'You are about to duplicate a bundled template. Changes will not be live until you activate the new template.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t\t<DataForm\n\t\t\t\t\t\tdata={ item }\n\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\tform={ formDuplicateAction }\n\t\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t...changes,\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\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Duplicate action for BasePost.\n */\nexport default duplicatePost;\n"],
|
|
5
|
+
"mappings": "AAiJM,cAiBD,YAjBC;AA9IN,SAAS,mBAAmB;AAC5B,SAAS,SAAS,iBAAiB;AACnC,SAAS,IAAI,SAAS,UAAU;AAChC,SAAS,SAAS,oBAAoB;AACtC,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB;AAAA,EACC;AAAA,EACA,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,OAClB;AAMP,SAAS,kBAAkB;AAE3B,SAAS,oBAAoB;AAE7B,MAAM,SAAS,CAAE,UAAW;AAC5B,MAAM,sBAAsB;AAAA,EAC3B,QAAQ,CAAE,OAAQ;AACnB;AAEA,MAAM,gBAAoC;AAAA,EACzC,IAAI;AAAA,EACJ,OAAO,GAAI,aAAa,cAAe;AAAA,EACvC,WAAY,EAAE,OAAO,GAAI;AACxB,WAAO,WAAW;AAAA,EACnB;AAAA,EACA,mBAAmB;AAAA,EACnB,aAAa,CAAE,EAAE,OAAO,YAAY,kBAAkB,MAAO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YACA,SAAQ;AAAA,YACR,MAAK;AAAA,YACL,QAAS;AAAA,YACT,iBAAgB;AAAA,YAChB,uBAAqB;AAAA,YAEnB,aAAI,aAAa,cAAe;AAAA;AAAA,QACnC;AAAA,SACD;AAAA,OACD,GACD;AAAA,EAEF;AACD;AAKA,IAAO,yBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,7 +4,7 @@ import { store as coreStore } from "@wordpress/core-data";
|
|
|
4
4
|
import { __ } from "@wordpress/i18n";
|
|
5
5
|
import { store as noticesStore } from "@wordpress/notices";
|
|
6
6
|
import { useState } from "@wordpress/element";
|
|
7
|
-
import { DataForm,
|
|
7
|
+
import { DataForm, useFormValidity } from "@wordpress/dataviews";
|
|
8
8
|
import {
|
|
9
9
|
Button,
|
|
10
10
|
__experimentalHStack as HStack,
|
|
@@ -24,9 +24,14 @@ function ReorderModal({
|
|
|
24
24
|
const orderInput = item.menu_order;
|
|
25
25
|
const { editEntityRecord, saveEditedEntityRecord } = useDispatch(coreStore);
|
|
26
26
|
const { createSuccessNotice, createErrorNotice } = useDispatch(noticesStore);
|
|
27
|
+
const { validity, isValid } = useFormValidity(
|
|
28
|
+
item,
|
|
29
|
+
fields,
|
|
30
|
+
formOrderAction
|
|
31
|
+
);
|
|
27
32
|
async function onOrder(event) {
|
|
28
33
|
event.preventDefault();
|
|
29
|
-
if (!
|
|
34
|
+
if (!isValid) {
|
|
30
35
|
return;
|
|
31
36
|
}
|
|
32
37
|
try {
|
|
@@ -49,7 +54,6 @@ function ReorderModal({
|
|
|
49
54
|
});
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
|
-
const isSaveDisabled = !isItemValid(item, fields, formOrderAction);
|
|
53
57
|
return /* @__PURE__ */ jsx("form", { onSubmit: onOrder, children: /* @__PURE__ */ jsxs(VStack, { spacing: "5", children: [
|
|
54
58
|
/* @__PURE__ */ jsx("div", { children: __(
|
|
55
59
|
"Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported."
|
|
@@ -60,10 +64,13 @@ function ReorderModal({
|
|
|
60
64
|
data: item,
|
|
61
65
|
fields,
|
|
62
66
|
form: formOrderAction,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
validity,
|
|
68
|
+
onChange: (changes) => {
|
|
69
|
+
return setItem({
|
|
70
|
+
...item,
|
|
71
|
+
...changes
|
|
72
|
+
});
|
|
73
|
+
}
|
|
67
74
|
}
|
|
68
75
|
),
|
|
69
76
|
/* @__PURE__ */ jsxs(HStack, { justify: "right", children: [
|
|
@@ -85,7 +92,7 @@ function ReorderModal({
|
|
|
85
92
|
variant: "primary",
|
|
86
93
|
type: "submit",
|
|
87
94
|
accessibleWhenDisabled: true,
|
|
88
|
-
disabled:
|
|
95
|
+
disabled: !isValid,
|
|
89
96
|
children: __("Save")
|
|
90
97
|
}
|
|
91
98
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/actions/reorder-page.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm,
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm, useFormValidity } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action, RenderModalProps } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { CoreDataError, BasePost } from '../types';\nimport { orderField } from '../fields';\n\nconst fields = [ orderField ];\nconst formOrderAction = {\n\tfields: [ 'menu_order' ],\n};\n\nfunction ReorderModal( {\n\titems,\n\tcloseModal,\n\tonActionPerformed,\n}: RenderModalProps< BasePost > ) {\n\tconst [ item, setItem ] = useState( items[ 0 ] );\n\tconst orderInput = item.menu_order;\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst { validity, isValid } = useFormValidity(\n\t\titem,\n\t\tfields,\n\t\tformOrderAction\n\t);\n\n\tasync function onOrder( event: React.FormEvent ) {\n\t\tevent.preventDefault();\n\n\t\tif ( ! isValid ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tmenu_order: orderInput,\n\t\t\t} );\n\t\t\tcloseModal?.();\n\t\t\t// Persist edited entity.\n\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tthrowOnError: true,\n\t\t\t} );\n\t\t\tcreateSuccessNotice( __( 'Order updated.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t\tonActionPerformed?.( items );\n\t\t} catch ( error ) {\n\t\t\tconst typedError = error as CoreDataError;\n\t\t\tconst errorMessage =\n\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t? typedError.message\n\t\t\t\t\t: __( 'An error occurred while updating the order' );\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\n\treturn (\n\t\t<form onSubmit={ onOrder }>\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<div>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ item }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ formOrderAction }\n\t\t\t\t\tvalidity={ validity }\n\t\t\t\t\tonChange={ ( changes ) => {\n\t\t\t\t\t\treturn setItem( {\n\t\t\t\t\t\t\t...item,\n\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tdisabled={ ! isValid }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t</form>\n\t);\n}\n\nconst reorderPage: Action< BasePost > = {\n\tid: 'order-pages',\n\tlabel: __( 'Order' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ReorderModal,\n};\n\n/**\n * Reorder action for BasePost.\n */\nexport default reorderPage;\n"],
|
|
5
|
+
"mappings": "AAgFI,cAiBA,YAjBA;AA7EJ,SAAS,mBAAmB;AAC5B,SAAS,SAAS,iBAAiB;AACnC,SAAS,UAAU;AACnB,SAAS,SAAS,oBAAoB;AACtC,SAAS,gBAAgB;AACzB,SAAS,UAAU,uBAAuB;AAC1C;AAAA,EACC;AAAA,EACA,wBAAwB;AAAA,EACxB,wBAAw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UAAW,CAAE,YAAa;AACzB,iBAAO,QAAS;AAAA,YACf,GAAG;AAAA,YACH,GAAG;AAAA,UACJ,CAAE;AAAA,QACH;AAAA;AAAA,IACD;AAAA,IACA,qBAAC,UAAO,SAAQ,SACf;AAAA;AAAA,QAAC;AAAA;AAAA,UACA,uBAAqB;AAAA,UACrB,SAAQ;AAAA,UACR,SAAU,MAAM;AACf,yBAAa;AAAA,UACd;AAAA,UAEE,aAAI,QAAS;AAAA;AAAA,MAChB;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACA,uBAAqB;AAAA,UACrB,SAAQ;AAAA,UACR,MAAK;AAAA,UACL,wBAAsB;AAAA,UACtB,UAAW,CAAE;AAAA,UAEX,aAAI,MAAO;AAAA;AAAA,MACd;AAAA,OACD;AAAA,KACD,GACD;AAEF;AAEA,MAAM,cAAkC;AAAA,EACvC,IAAI;AAAA,EACJ,OAAO,GAAI,OAAQ;AAAA,EACnB,WAAY,EAAE,OAAO,GAAI;AACxB,WAAO,WAAW;AAAA,EACnB;AAAA,EACA,mBAAmB;AAAA,EACnB,aAAa;AACd;AAKA,IAAO,uBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import { __ } from "@wordpress/i18n";
|
|
2
|
+
import { resolveSelect } from "@wordpress/data";
|
|
3
|
+
import { store as coreDataStore } from "@wordpress/core-data";
|
|
2
4
|
import AuthorView from "./author-view";
|
|
3
5
|
const authorField = {
|
|
4
6
|
label: __("Author"),
|
|
5
7
|
id: "author",
|
|
6
8
|
type: "integer",
|
|
7
|
-
|
|
9
|
+
getElements: async () => {
|
|
10
|
+
const authors = await resolveSelect(coreDataStore).getEntityRecords(
|
|
11
|
+
"root",
|
|
12
|
+
"user",
|
|
13
|
+
{
|
|
14
|
+
per_page: -1
|
|
15
|
+
}
|
|
16
|
+
) ?? [];
|
|
17
|
+
return authors.map(({ id, name }) => ({
|
|
18
|
+
value: id,
|
|
19
|
+
label: name
|
|
20
|
+
}));
|
|
21
|
+
},
|
|
8
22
|
render: AuthorView,
|
|
9
23
|
sort: (a, b, direction) => {
|
|
10
24
|
const nameA = a._embedded?.author?.[0]?.name || "";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/fields/author/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\nimport AuthorView from './author-view';\n\nconst authorField: Field< BasePostWithEmbeddedAuthor > = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\ttype: 'integer',\n\
|
|
5
|
-
"mappings": "AAIA,SAAS,UAAU;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\nimport { resolveSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\nimport AuthorView from './author-view';\n\ninterface Author {\n\tid: number;\n\tname: string;\n}\n\nconst authorField: Field< BasePostWithEmbeddedAuthor > = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\ttype: 'integer',\n\tgetElements: async () => {\n\t\tconst authors: Author[] =\n\t\t\t( await resolveSelect( coreDataStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'user',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t) ) ?? [];\n\t\treturn authors.map( ( { id, name } ) => ( {\n\t\t\tvalue: id,\n\t\t\tlabel: name,\n\t\t} ) );\n\t},\n\trender: AuthorView,\n\tsort: ( a, b, direction ) => {\n\t\tconst nameA = a._embedded?.author?.[ 0 ]?.name || '';\n\t\tconst nameB = b._embedded?.author?.[ 0 ]?.name || '';\n\n\t\treturn direction === 'asc'\n\t\t\t? nameA.localeCompare( nameB )\n\t\t\t: nameB.localeCompare( nameA );\n\t},\n\n\tfilterBy: {\n\t\toperators: [ 'isAny', 'isNone' ],\n\t},\n};\n\n/**\n * Author field for BasePost.\n */\nexport default authorField;\n"],
|
|
5
|
+
"mappings": "AAIA,SAAS,UAAU;AACnB,SAAS,qBAAqB;AAC9B,SAAS,SAAS,qBAAqB;AAMvC,OAAO,gBAAgB;AAOvB,MAAM,cAAmD;AAAA,EACxD,OAAO,GAAI,QAAS;AAAA,EACpB,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,aAAa,YAAY;AACxB,UAAM,UACH,MAAM,cAAe,aAAc,EAAE;AAAA,MACtC;AAAA,MACA;AAAA,MACA;AAAA,QACC,UAAU;AAAA,MACX;AAAA,IACD,KAAO,CAAC;AACT,WAAO,QAAQ,IAAK,CAAE,EAAE,IAAI,KAAK,OAAS;AAAA,MACzC,OAAO;AAAA,MACP,OAAO;AAAA,IACR,EAAI;AAAA,EACL;AAAA,EACA,QAAQ;AAAA,EACR,MAAM,CAAE,GAAG,GAAG,cAAe;AAC5B,UAAM,QAAQ,EAAE,WAAW,SAAU,CAAE,GAAG,QAAQ;AAClD,UAAM,QAAQ,EAAE,WAAW,SAAU,CAAE,GAAG,QAAQ;AAElD,WAAO,cAAc,QAClB,MAAM,cAAe,KAAM,IAC3B,MAAM,cAAe,KAAM;AAAA,EAC/B;AAAA,EAEA,UAAU;AAAA,IACT,WAAW,CAAE,SAAS,QAAS;AAAA,EAChC;AACD;AAKA,IAAO,iBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"duplicate-post.d.ts","sourceRoot":"","sources":["../../src/actions/duplicate-post.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAMnD,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,UAAU,CAAC;AAQxD,QAAA,MAAM,aAAa,EAAE,MAAM,CAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"duplicate-post.d.ts","sourceRoot":"","sources":["../../src/actions/duplicate-post.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAMnD,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,UAAU,CAAC;AAQxD,QAAA,MAAM,aAAa,EAAE,MAAM,CAAE,QAAQ,CA4JpC,CAAC;AAEF;;GAEG;AACH,eAAe,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reorder-page.d.ts","sourceRoot":"","sources":["../../src/actions/reorder-page.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,sBAAsB,CAAC;AAErE;;GAEG;AACH,OAAO,KAAK,EAAiB,QAAQ,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"reorder-page.d.ts","sourceRoot":"","sources":["../../src/actions/reorder-page.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,sBAAsB,CAAC;AAErE;;GAEG;AACH,OAAO,KAAK,EAAiB,QAAQ,EAAE,MAAM,UAAU,CAAC;AAuGxD,QAAA,MAAM,WAAW,EAAE,MAAM,CAAE,QAAQ,CAQlC,CAAC;AAEF;;GAEG;AACH,eAAe,WAAW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/author/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/author/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAKlD;;GAEG;AACH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAQ9D,QAAA,MAAM,WAAW,EAAE,KAAK,CAAE,0BAA0B,CA+BnD,CAAC;AAEF;;GAEG;AACH,eAAe,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/fields",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "DataViews is a component that provides an API to render datasets using different types of layouts (table, grid, list, etc.).",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -39,30 +39,30 @@
|
|
|
39
39
|
"src/**/*.scss"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@wordpress/api-fetch": "^7.
|
|
43
|
-
"@wordpress/base-styles": "^6.
|
|
44
|
-
"@wordpress/blob": "^4.
|
|
45
|
-
"@wordpress/block-editor": "^15.
|
|
46
|
-
"@wordpress/blocks": "^15.
|
|
47
|
-
"@wordpress/components": "^30.6.
|
|
48
|
-
"@wordpress/compose": "^7.
|
|
49
|
-
"@wordpress/core-data": "^7.
|
|
50
|
-
"@wordpress/data": "^10.
|
|
51
|
-
"@wordpress/dataviews": "^10.0.
|
|
52
|
-
"@wordpress/date": "^5.
|
|
53
|
-
"@wordpress/element": "^6.
|
|
54
|
-
"@wordpress/hooks": "^4.
|
|
55
|
-
"@wordpress/html-entities": "^4.
|
|
56
|
-
"@wordpress/i18n": "^6.
|
|
57
|
-
"@wordpress/icons": "^11.0.
|
|
58
|
-
"@wordpress/media-utils": "^5.
|
|
59
|
-
"@wordpress/notices": "^5.
|
|
60
|
-
"@wordpress/patterns": "^2.
|
|
61
|
-
"@wordpress/primitives": "^4.
|
|
62
|
-
"@wordpress/private-apis": "^1.
|
|
63
|
-
"@wordpress/router": "^1.
|
|
64
|
-
"@wordpress/url": "^4.
|
|
65
|
-
"@wordpress/warning": "^3.
|
|
42
|
+
"@wordpress/api-fetch": "^7.33.0",
|
|
43
|
+
"@wordpress/base-styles": "^6.9.0",
|
|
44
|
+
"@wordpress/blob": "^4.33.0",
|
|
45
|
+
"@wordpress/block-editor": "^15.6.0",
|
|
46
|
+
"@wordpress/blocks": "^15.6.0",
|
|
47
|
+
"@wordpress/components": "^30.6.0",
|
|
48
|
+
"@wordpress/compose": "^7.33.0",
|
|
49
|
+
"@wordpress/core-data": "^7.33.0",
|
|
50
|
+
"@wordpress/data": "^10.33.0",
|
|
51
|
+
"@wordpress/dataviews": "^10.0.0",
|
|
52
|
+
"@wordpress/date": "^5.33.0",
|
|
53
|
+
"@wordpress/element": "^6.33.0",
|
|
54
|
+
"@wordpress/hooks": "^4.33.0",
|
|
55
|
+
"@wordpress/html-entities": "^4.33.0",
|
|
56
|
+
"@wordpress/i18n": "^6.6.0",
|
|
57
|
+
"@wordpress/icons": "^11.0.0",
|
|
58
|
+
"@wordpress/media-utils": "^5.33.0",
|
|
59
|
+
"@wordpress/notices": "^5.33.0",
|
|
60
|
+
"@wordpress/patterns": "^2.33.0",
|
|
61
|
+
"@wordpress/primitives": "^4.33.0",
|
|
62
|
+
"@wordpress/private-apis": "^1.33.0",
|
|
63
|
+
"@wordpress/router": "^1.33.0",
|
|
64
|
+
"@wordpress/url": "^4.33.0",
|
|
65
|
+
"@wordpress/warning": "^3.33.0",
|
|
66
66
|
"change-case": "4.1.2",
|
|
67
67
|
"client-zip": "^2.4.5",
|
|
68
68
|
"clsx": "2.1.1",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"publishConfig": {
|
|
75
75
|
"access": "public"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "2bbe0d34ab65458468758c48826296d7a753428b"
|
|
78
78
|
}
|
|
@@ -142,6 +142,13 @@ const duplicatePost: Action< BasePost > = {
|
|
|
142
142
|
return (
|
|
143
143
|
<form onSubmit={ createPage }>
|
|
144
144
|
<VStack spacing={ 3 }>
|
|
145
|
+
{ item.type === 'wp_registered_template' && (
|
|
146
|
+
<div>
|
|
147
|
+
{ __(
|
|
148
|
+
'You are about to duplicate a bundled template. Changes will not be live until you activate the new template.'
|
|
149
|
+
) }
|
|
150
|
+
</div>
|
|
151
|
+
) }
|
|
145
152
|
<DataForm
|
|
146
153
|
data={ item }
|
|
147
154
|
fields={ fields }
|
|
@@ -6,7 +6,7 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
7
|
import { store as noticesStore } from '@wordpress/notices';
|
|
8
8
|
import { useState } from '@wordpress/element';
|
|
9
|
-
import { DataForm,
|
|
9
|
+
import { DataForm, useFormValidity } from '@wordpress/dataviews';
|
|
10
10
|
import {
|
|
11
11
|
Button,
|
|
12
12
|
__experimentalHStack as HStack,
|
|
@@ -37,10 +37,16 @@ function ReorderModal( {
|
|
|
37
37
|
const { createSuccessNotice, createErrorNotice } =
|
|
38
38
|
useDispatch( noticesStore );
|
|
39
39
|
|
|
40
|
+
const { validity, isValid } = useFormValidity(
|
|
41
|
+
item,
|
|
42
|
+
fields,
|
|
43
|
+
formOrderAction
|
|
44
|
+
);
|
|
45
|
+
|
|
40
46
|
async function onOrder( event: React.FormEvent ) {
|
|
41
47
|
event.preventDefault();
|
|
42
48
|
|
|
43
|
-
if ( !
|
|
49
|
+
if ( ! isValid ) {
|
|
44
50
|
return;
|
|
45
51
|
}
|
|
46
52
|
|
|
@@ -68,7 +74,7 @@ function ReorderModal( {
|
|
|
68
74
|
} );
|
|
69
75
|
}
|
|
70
76
|
}
|
|
71
|
-
|
|
77
|
+
|
|
72
78
|
return (
|
|
73
79
|
<form onSubmit={ onOrder }>
|
|
74
80
|
<VStack spacing="5">
|
|
@@ -81,12 +87,13 @@ function ReorderModal( {
|
|
|
81
87
|
data={ item }
|
|
82
88
|
fields={ fields }
|
|
83
89
|
form={ formOrderAction }
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
validity={ validity }
|
|
91
|
+
onChange={ ( changes ) => {
|
|
92
|
+
return setItem( {
|
|
86
93
|
...item,
|
|
87
94
|
...changes,
|
|
88
|
-
} )
|
|
89
|
-
}
|
|
95
|
+
} );
|
|
96
|
+
} }
|
|
90
97
|
/>
|
|
91
98
|
<HStack justify="right">
|
|
92
99
|
<Button
|
|
@@ -103,7 +110,7 @@ function ReorderModal( {
|
|
|
103
110
|
variant="primary"
|
|
104
111
|
type="submit"
|
|
105
112
|
accessibleWhenDisabled
|
|
106
|
-
disabled={
|
|
113
|
+
disabled={ ! isValid }
|
|
107
114
|
>
|
|
108
115
|
{ __( 'Save' ) }
|
|
109
116
|
</Button>
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { Field } from '@wordpress/dataviews';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
|
+
import { resolveSelect } from '@wordpress/data';
|
|
7
|
+
import { store as coreDataStore } from '@wordpress/core-data';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Internal dependencies
|
|
@@ -10,11 +12,29 @@ import { __ } from '@wordpress/i18n';
|
|
|
10
12
|
import type { BasePostWithEmbeddedAuthor } from '../../types';
|
|
11
13
|
import AuthorView from './author-view';
|
|
12
14
|
|
|
15
|
+
interface Author {
|
|
16
|
+
id: number;
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
13
20
|
const authorField: Field< BasePostWithEmbeddedAuthor > = {
|
|
14
21
|
label: __( 'Author' ),
|
|
15
22
|
id: 'author',
|
|
16
23
|
type: 'integer',
|
|
17
|
-
|
|
24
|
+
getElements: async () => {
|
|
25
|
+
const authors: Author[] =
|
|
26
|
+
( await resolveSelect( coreDataStore ).getEntityRecords(
|
|
27
|
+
'root',
|
|
28
|
+
'user',
|
|
29
|
+
{
|
|
30
|
+
per_page: -1,
|
|
31
|
+
}
|
|
32
|
+
) ) ?? [];
|
|
33
|
+
return authors.map( ( { id, name } ) => ( {
|
|
34
|
+
value: id,
|
|
35
|
+
label: name,
|
|
36
|
+
} ) );
|
|
37
|
+
},
|
|
18
38
|
render: AuthorView,
|
|
19
39
|
sort: ( a, b, direction ) => {
|
|
20
40
|
const nameA = a._embedded?.author?.[ 0 ]?.name || '';
|