@wordpress/fields 0.25.0 → 0.25.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/actions/duplicate-post.js +7 -12
- package/build/actions/duplicate-post.js.map +3 -3
- package/build/actions/reorder-page.js +14 -21
- package/build/actions/reorder-page.js.map +3 -3
- package/build-module/actions/duplicate-post.js +9 -13
- package/build-module/actions/duplicate-post.js.map +2 -2
- package/build-module/actions/reorder-page.js +16 -22
- package/build-module/actions/reorder-page.js.map +2 -2
- package/build-types/actions/duplicate-post.d.ts +15 -1
- package/build-types/actions/duplicate-post.d.ts.map +1 -1
- package/build-types/actions/reorder-page.d.ts +12 -1
- package/build-types/actions/reorder-page.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/actions/duplicate-post.tsx +21 -13
- package/src/actions/reorder-page.tsx +38 -22
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -27,14 +27,8 @@ var import_core_data = require("@wordpress/core-data");
|
|
|
27
27
|
var import_i18n = require("@wordpress/i18n");
|
|
28
28
|
var import_notices = require("@wordpress/notices");
|
|
29
29
|
var import_element = require("@wordpress/element");
|
|
30
|
-
var import_dataviews = require("@wordpress/dataviews");
|
|
31
30
|
var import_components = require("@wordpress/components");
|
|
32
|
-
var import_fields = require("../fields");
|
|
33
31
|
var import_utils = require("./utils");
|
|
34
|
-
const fields = [import_fields.titleField];
|
|
35
|
-
const formDuplicateAction = {
|
|
36
|
-
fields: ["title"]
|
|
37
|
-
};
|
|
38
32
|
const duplicatePost = {
|
|
39
33
|
id: "duplicate-post",
|
|
40
34
|
label: (0, import_i18n._x)("Duplicate", "action label"),
|
|
@@ -125,14 +119,15 @@ const duplicatePost = {
|
|
|
125
119
|
"You are about to duplicate a bundled template. Changes will not be live until you activate the new template."
|
|
126
120
|
) }),
|
|
127
121
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
128
|
-
|
|
122
|
+
import_components.__experimentalInputControl,
|
|
129
123
|
{
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
124
|
+
__next40pxDefaultSize: true,
|
|
125
|
+
label: (0, import_i18n.__)("Title"),
|
|
126
|
+
placeholder: (0, import_i18n.__)("No title"),
|
|
127
|
+
value: (0, import_utils.getItemTitle)(item),
|
|
128
|
+
onChange: (value) => setItem((prev) => ({
|
|
134
129
|
...prev,
|
|
135
|
-
|
|
130
|
+
title: value || (0, import_i18n.__)("No title")
|
|
136
131
|
}))
|
|
137
132
|
}
|
|
138
133
|
),
|
|
@@ -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 {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
6
|
-
"names": ["coreStore", "noticesStore", "VStack", "HStack"]
|
|
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 {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\t__experimentalInputControl as InputControl,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\ninterface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\ninterface Action< Item > {\n\tid: string;\n\tlabel: string;\n\tisEligible?: ( item: Item ) => boolean;\n\tmodalFocusOnMount?: string;\n\tRenderModal: ( props: RenderModalProps< Item > ) => JSX.Element;\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<InputControl\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Title' ) }\n\t\t\t\t\t\tplaceholder={ __( 'No title' ) }\n\t\t\t\t\t\tvalue={ getItemTitle( item ) }\n\t\t\t\t\t\tonChange={ ( value ) =>\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\ttitle: value || __( 'No title' ),\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;AAwJM;AArJN,kBAA4B;AAC5B,uBAAmC;AACnC,kBAAgC;AAChC,qBAAsC;AACtC,qBAAyB;AACzB,wBAKO;AAMP,mBAA6B;AAgB7B,MAAM,gBAAoC;AAAA,EACzC,IAAI;AAAA,EACJ,WAAO,gBAAI,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;AAC5D,UAAM,CAAE,MAAM,OAAQ,QAAI,yBAAsB;AAAA,MAC/C,GAAG,MAAO,CAAE;AAAA,MACZ,WAAO;AAAA;AAAA,YAEN,gBAAI,aAAa,MAAO;AAAA,YACxB,2BAAc,MAAO,CAAE,CAAE;AAAA,MAC1B;AAAA,IACD,CAAE;AAEF,UAAM,CAAE,gBAAgB,iBAAkB,QAAI,yBAAU,KAAM;AAC9D,UAAM,EAAE,iBAAiB,QAAI,yBAAa,iBAAAA,KAAU;AACpD,UAAM,EAAE,qBAAqB,kBAAkB,QAC9C,yBAAa,eAAAC,KAAa;AAE3B,mBAAe,WAAY,OAAyB;AACnD,YAAM,eAAe;AAErB,UAAK,gBAAiB;AACrB;AAAA,MACD;AAEA,YAAM,aACL,KAAK,SAAS,iBACd,KAAK,SAAS;AAEf,YAAM,gBAAgB;AAAA,QACrB,QAAQ,aAAa,YAAY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L,WAAW,WAAW,WAAW,SAAS,kBACvC,WAAW,cACX,gBAAI,+CAAgD;AAExD,0BAAmB,cAAc;AAAA,UAChC,MAAM;AAAA,QACP,CAAE;AAAA,MACH,UAAE;AACD,0BAAmB,KAAM;AACzB,qBAAa;AAAA,MACd;AAAA,IACD;AAEA,WACC,4CAAC,UAAK,UAAW,YAChB,uDAAC,kBAAAC,sBAAA,EAAO,SAAU,GACf;AAAA,WAAK,SAAS,4BACf,4CAAC,SACE;AAAA,QACD;AAAA,MACD,GACD;AAAA,MAED;AAAA,QAAC,kBAAAC;AAAA,QAAA;AAAA,UACA,uBAAqB;AAAA,UACrB,WAAQ,gBAAI,OAAQ;AAAA,UACpB,iBAAc,gBAAI,UAAW;AAAA,UAC7B,WAAQ,2BAAc,IAAK;AAAA,UAC3B,UAAW,CAAE,UACZ,QAAS,CAAE,UAAY;AAAA,YACtB,GAAG;AAAA,YACH,OAAO,aAAS,gBAAI,UAAW;AAAA,UAChC,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
|
+
"names": ["coreStore", "noticesStore", "VStack", "InputControl", "HStack"]
|
|
7
7
|
}
|
|
@@ -27,27 +27,19 @@ var import_core_data = require("@wordpress/core-data");
|
|
|
27
27
|
var import_i18n = require("@wordpress/i18n");
|
|
28
28
|
var import_notices = require("@wordpress/notices");
|
|
29
29
|
var import_element = require("@wordpress/element");
|
|
30
|
-
var import_dataviews = require("@wordpress/dataviews");
|
|
31
30
|
var import_components = require("@wordpress/components");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
fields: ["menu_order"]
|
|
36
|
-
};
|
|
31
|
+
function isItemValid(item) {
|
|
32
|
+
return typeof item.menu_order === "number" && Number.isInteger(item.menu_order) && item.menu_order > 0;
|
|
33
|
+
}
|
|
37
34
|
function ReorderModal({
|
|
38
35
|
items,
|
|
39
36
|
closeModal,
|
|
40
37
|
onActionPerformed
|
|
41
38
|
}) {
|
|
42
39
|
const [item, setItem] = (0, import_element.useState)(items[0]);
|
|
43
|
-
const orderInput = item.menu_order;
|
|
44
40
|
const { editEntityRecord, saveEditedEntityRecord } = (0, import_data.useDispatch)(import_core_data.store);
|
|
45
41
|
const { createSuccessNotice, createErrorNotice } = (0, import_data.useDispatch)(import_notices.store);
|
|
46
|
-
const
|
|
47
|
-
item,
|
|
48
|
-
fields,
|
|
49
|
-
formOrderAction
|
|
50
|
-
);
|
|
42
|
+
const isValid = isItemValid(item);
|
|
51
43
|
async function onOrder(event) {
|
|
52
44
|
event.preventDefault();
|
|
53
45
|
if (!isValid) {
|
|
@@ -55,7 +47,7 @@ function ReorderModal({
|
|
|
55
47
|
}
|
|
56
48
|
try {
|
|
57
49
|
await editEntityRecord("postType", item.type, item.id, {
|
|
58
|
-
menu_order:
|
|
50
|
+
menu_order: item.menu_order
|
|
59
51
|
});
|
|
60
52
|
closeModal?.();
|
|
61
53
|
await saveEditedEntityRecord("postType", item.type, item.id, {
|
|
@@ -78,16 +70,17 @@ function ReorderModal({
|
|
|
78
70
|
"Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported."
|
|
79
71
|
) }),
|
|
80
72
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
81
|
-
|
|
73
|
+
import_components.__experimentalInputControl,
|
|
82
74
|
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
onChange: (
|
|
88
|
-
|
|
75
|
+
__next40pxDefaultSize: true,
|
|
76
|
+
label: (0, import_i18n.__)("Order"),
|
|
77
|
+
type: "number",
|
|
78
|
+
value: typeof item.menu_order === "number" && Number.isInteger(item.menu_order) ? String(item.menu_order) : "",
|
|
79
|
+
onChange: (value) => {
|
|
80
|
+
const parsed = parseInt(value, 10);
|
|
81
|
+
setItem({
|
|
89
82
|
...item,
|
|
90
|
-
|
|
83
|
+
menu_order: isNaN(parsed) ? void 0 : parsed
|
|
91
84
|
});
|
|
92
85
|
}
|
|
93
86
|
}
|
|
@@ -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 {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
6
|
-
"names": ["coreStore", "noticesStore", "VStack", "HStack"]
|
|
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 {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\t__experimentalInputControl as InputControl,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type { CoreDataError, BasePost } from '../types';\n\ninterface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\ninterface Action< Item > {\n\tid: string;\n\tlabel: string;\n\tisEligible?: ( item: Item ) => boolean;\n\tmodalFocusOnMount?: string;\n\tRenderModal: ( props: RenderModalProps< Item > ) => JSX.Element;\n}\n\nfunction isItemValid( item: BasePost ): boolean {\n\treturn (\n\t\ttypeof item.menu_order === 'number' &&\n\t\tNumber.isInteger( item.menu_order ) &&\n\t\titem.menu_order > 0\n\t);\n}\n\nfunction ReorderModal( {\n\titems,\n\tcloseModal,\n\tonActionPerformed,\n}: RenderModalProps< BasePost > ) {\n\tconst [ item, setItem ] = useState( items[ 0 ] );\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst isValid = isItemValid( item );\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: item.menu_order,\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<InputControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Order' ) }\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tvalue={\n\t\t\t\t\t\ttypeof item.menu_order === 'number' &&\n\t\t\t\t\t\tNumber.isInteger( item.menu_order )\n\t\t\t\t\t\t\t? String( item.menu_order )\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t}\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tconst parsed = parseInt( value as string, 10 ); // absorbs '' and undefined\n\t\t\t\t\t\tsetItem( {\n\t\t\t\t\t\t\t...item,\n\t\t\t\t\t\t\tmenu_order: isNaN( parsed ) ? undefined : parsed,\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;AA0FI;AAvFJ,kBAA4B;AAC5B,uBAAmC;AACnC,kBAAmB;AACnB,qBAAsC;AACtC,qBAAyB;AACzB,wBAKO;AAqBP,SAAS,YAAa,MAA0B;AAC/C,SACC,OAAO,KAAK,eAAe,YAC3B,OAAO,UAAW,KAAK,UAAW,KAClC,KAAK,aAAa;AAEpB;AAEA,SAAS,aAAc;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AACD,GAAkC;AACjC,QAAM,CAAE,MAAM,OAAQ,QAAI,yBAAU,MAAO,CAAE,CAAE;AAC/C,QAAM,EAAE,kBAAkB,uBAAuB,QAChD,yBAAa,iBAAAA,KAAU;AACxB,QAAM,EAAE,qBAAqB,kBAAkB,QAC9C,yBAAa,eAAAC,KAAa;AAE3B,QAAM,UAAU,YAAa,IAAK;AAElC,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,KAAK;AAAA,MAClB,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,kBAAAC;AAAA,MAAA;AAAA,QACA,uBAAqB;AAAA,QACrB,WAAQ,gBAAI,OAAQ;AAAA,QACpB,MAAK;AAAA,QACL,OACC,OAAO,KAAK,eAAe,YAC3B,OAAO,UAAW,KAAK,UAAW,IAC/B,OAAQ,KAAK,UAAW,IACxB;AAAA,QAEJ,UAAW,CAAE,UAAW;AACvB,gBAAM,SAAS,SAAU,OAAiB,EAAG;AAC7C,kBAAS;AAAA,YACR,GAAG;AAAA,YACH,YAAY,MAAO,MAAO,IAAI,SAAY;AAAA,UAC3C,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
|
+
"names": ["coreStore", "noticesStore", "VStack", "InputControl", "HStack"]
|
|
7
7
|
}
|
|
@@ -4,18 +4,13 @@ import { store as coreStore } from "@wordpress/core-data";
|
|
|
4
4
|
import { __, sprintf, _x } from "@wordpress/i18n";
|
|
5
5
|
import { store as noticesStore } from "@wordpress/notices";
|
|
6
6
|
import { useState } from "@wordpress/element";
|
|
7
|
-
import { DataForm } from "@wordpress/dataviews";
|
|
8
7
|
import {
|
|
9
8
|
Button,
|
|
10
9
|
__experimentalHStack as HStack,
|
|
11
|
-
__experimentalVStack as VStack
|
|
10
|
+
__experimentalVStack as VStack,
|
|
11
|
+
__experimentalInputControl as InputControl
|
|
12
12
|
} from "@wordpress/components";
|
|
13
|
-
import { titleField } from "../fields";
|
|
14
13
|
import { getItemTitle } from "./utils";
|
|
15
|
-
const fields = [titleField];
|
|
16
|
-
const formDuplicateAction = {
|
|
17
|
-
fields: ["title"]
|
|
18
|
-
};
|
|
19
14
|
const duplicatePost = {
|
|
20
15
|
id: "duplicate-post",
|
|
21
16
|
label: _x("Duplicate", "action label"),
|
|
@@ -106,14 +101,15 @@ const duplicatePost = {
|
|
|
106
101
|
"You are about to duplicate a bundled template. Changes will not be live until you activate the new template."
|
|
107
102
|
) }),
|
|
108
103
|
/* @__PURE__ */ jsx(
|
|
109
|
-
|
|
104
|
+
InputControl,
|
|
110
105
|
{
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
106
|
+
__next40pxDefaultSize: true,
|
|
107
|
+
label: __("Title"),
|
|
108
|
+
placeholder: __("No title"),
|
|
109
|
+
value: getItemTitle(item),
|
|
110
|
+
onChange: (value) => setItem((prev) => ({
|
|
115
111
|
...prev,
|
|
116
|
-
|
|
112
|
+
title: value || __("No title")
|
|
117
113
|
}))
|
|
118
114
|
}
|
|
119
115
|
),
|
|
@@ -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 {
|
|
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 {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\t__experimentalInputControl as InputControl,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\ninterface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\ninterface Action< Item > {\n\tid: string;\n\tlabel: string;\n\tisEligible?: ( item: Item ) => boolean;\n\tmodalFocusOnMount?: string;\n\tRenderModal: ( props: RenderModalProps< Item > ) => JSX.Element;\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<InputControl\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Title' ) }\n\t\t\t\t\t\tplaceholder={ __( 'No title' ) }\n\t\t\t\t\t\tvalue={ getItemTitle( item ) }\n\t\t\t\t\t\tonChange={ ( value ) =>\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\ttitle: value || __( 'No title' ),\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": "AAwJM,cAkBD,YAlBC;AArJN,SAAS,mBAAmB;AAC5B,SAAS,SAAS,iBAAiB;AACnC,SAAS,IAAI,SAAS,UAAU;AAChC,SAAS,SAAS,oBAAoB;AACtC,SAAS,gBAAgB;AACzB;AAAA,EACC;AAAA,EACA,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,EACxB,8BAA8B;AAAA,OACxB;AAMP,SAAS,oBAAoB;AAgB7B,MAAM,gBAAoC;AAAA,EACzC,IAAI;AAAA,EACJ,OAAO,GAAI,aAAa,cAAe;AAAA,EACv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A;AAAA,MAEN;AAAA,MACA,qBAAC,UAAO,SAAU,GAAI,SAAQ,OAC7B;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,SAAQ;AAAA,YACR,SAAU;AAAA,YACV,uBAAqB;AAAA,YAEnB,aAAI,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,aAAI,aAAa,cAAe;AAAA;AAAA,QACnC;AAAA,SACD;AAAA,OACD,GACD;AAAA,EAEF;AACD;AAKA,IAAO,yBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,31 +4,24 @@ 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, useFormValidity } from "@wordpress/dataviews";
|
|
8
7
|
import {
|
|
9
8
|
Button,
|
|
10
9
|
__experimentalHStack as HStack,
|
|
11
|
-
__experimentalVStack as VStack
|
|
10
|
+
__experimentalVStack as VStack,
|
|
11
|
+
__experimentalInputControl as InputControl
|
|
12
12
|
} from "@wordpress/components";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
fields: ["menu_order"]
|
|
17
|
-
};
|
|
13
|
+
function isItemValid(item) {
|
|
14
|
+
return typeof item.menu_order === "number" && Number.isInteger(item.menu_order) && item.menu_order > 0;
|
|
15
|
+
}
|
|
18
16
|
function ReorderModal({
|
|
19
17
|
items,
|
|
20
18
|
closeModal,
|
|
21
19
|
onActionPerformed
|
|
22
20
|
}) {
|
|
23
21
|
const [item, setItem] = useState(items[0]);
|
|
24
|
-
const orderInput = item.menu_order;
|
|
25
22
|
const { editEntityRecord, saveEditedEntityRecord } = useDispatch(coreStore);
|
|
26
23
|
const { createSuccessNotice, createErrorNotice } = useDispatch(noticesStore);
|
|
27
|
-
const
|
|
28
|
-
item,
|
|
29
|
-
fields,
|
|
30
|
-
formOrderAction
|
|
31
|
-
);
|
|
24
|
+
const isValid = isItemValid(item);
|
|
32
25
|
async function onOrder(event) {
|
|
33
26
|
event.preventDefault();
|
|
34
27
|
if (!isValid) {
|
|
@@ -36,7 +29,7 @@ function ReorderModal({
|
|
|
36
29
|
}
|
|
37
30
|
try {
|
|
38
31
|
await editEntityRecord("postType", item.type, item.id, {
|
|
39
|
-
menu_order:
|
|
32
|
+
menu_order: item.menu_order
|
|
40
33
|
});
|
|
41
34
|
closeModal?.();
|
|
42
35
|
await saveEditedEntityRecord("postType", item.type, item.id, {
|
|
@@ -59,16 +52,17 @@ function ReorderModal({
|
|
|
59
52
|
"Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported."
|
|
60
53
|
) }),
|
|
61
54
|
/* @__PURE__ */ jsx(
|
|
62
|
-
|
|
55
|
+
InputControl,
|
|
63
56
|
{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
onChange: (
|
|
69
|
-
|
|
57
|
+
__next40pxDefaultSize: true,
|
|
58
|
+
label: __("Order"),
|
|
59
|
+
type: "number",
|
|
60
|
+
value: typeof item.menu_order === "number" && Number.isInteger(item.menu_order) ? String(item.menu_order) : "",
|
|
61
|
+
onChange: (value) => {
|
|
62
|
+
const parsed = parseInt(value, 10);
|
|
63
|
+
setItem({
|
|
70
64
|
...item,
|
|
71
|
-
|
|
65
|
+
menu_order: isNaN(parsed) ? void 0 : parsed
|
|
72
66
|
});
|
|
73
67
|
}
|
|
74
68
|
}
|
|
@@ -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 {
|
|
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 {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\t__experimentalInputControl as InputControl,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type { CoreDataError, BasePost } from '../types';\n\ninterface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\ninterface Action< Item > {\n\tid: string;\n\tlabel: string;\n\tisEligible?: ( item: Item ) => boolean;\n\tmodalFocusOnMount?: string;\n\tRenderModal: ( props: RenderModalProps< Item > ) => JSX.Element;\n}\n\nfunction isItemValid( item: BasePost ): boolean {\n\treturn (\n\t\ttypeof item.menu_order === 'number' &&\n\t\tNumber.isInteger( item.menu_order ) &&\n\t\titem.menu_order > 0\n\t);\n}\n\nfunction ReorderModal( {\n\titems,\n\tcloseModal,\n\tonActionPerformed,\n}: RenderModalProps< BasePost > ) {\n\tconst [ item, setItem ] = useState( items[ 0 ] );\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst isValid = isItemValid( item );\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: item.menu_order,\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<InputControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Order' ) }\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tvalue={\n\t\t\t\t\t\ttypeof item.menu_order === 'number' &&\n\t\t\t\t\t\tNumber.isInteger( item.menu_order )\n\t\t\t\t\t\t\t? String( item.menu_order )\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t}\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tconst parsed = parseInt( value as string, 10 ); // absorbs '' and undefined\n\t\t\t\t\t\tsetItem( {\n\t\t\t\t\t\t\t...item,\n\t\t\t\t\t\t\tmenu_order: isNaN( parsed ) ? undefined : parsed,\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": "AA0FI,cAuBA,YAvBA;AAvFJ,SAAS,mBAAmB;AAC5B,SAAS,SAAS,iBAAiB;AACnC,SAAS,UAAU;AACnB,SAAS,SAAS,oBAAoB;AACtC,SAAS,gBAAgB;AACzB;AAAA,EACC;AAAA,EACA,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,EACxB,8BAA8B;AAAA,OACxB;AAqBP,SAAS,YAAa,MAA0B;AAC/C,SACC,OAAO,KAAK,eAAe,YAC3B,OAAO,UAAW,KAAK,UAAW,KAClC,KAAK,aAAa;AAEpB;AAEA,SAAS,aAAc;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AACD,GAAkC;AACjC,QAAM,CAAE,MAAM,OAAQ,IAAI,SAAU,MAAO,CAAE,CAAE;AAC/C,QAAM,EAAE,kBAAkB,uBAAuB,IAChD,YAAa,SAAU;AACxB,QAAM,EAAE,qBAAqB,kBAAkB,IAC9C,YAAa,YAAa;AAE3B,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AAA,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,5 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
2
4
|
import type { BasePost } from '../types';
|
|
5
|
+
interface RenderModalProps<Item> {
|
|
6
|
+
items: Item[];
|
|
7
|
+
closeModal?: () => void;
|
|
8
|
+
onActionPerformed?: (items: Item[]) => void;
|
|
9
|
+
}
|
|
10
|
+
interface Action<Item> {
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
isEligible?: (item: Item) => boolean;
|
|
14
|
+
modalFocusOnMount?: string;
|
|
15
|
+
RenderModal: (props: RenderModalProps<Item>) => JSX.Element;
|
|
16
|
+
}
|
|
3
17
|
declare const duplicatePost: Action<BasePost>;
|
|
4
18
|
/**
|
|
5
19
|
* Duplicate action for BasePost.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"duplicate-post.d.ts","sourceRoot":"","sources":["../../src/actions/duplicate-post.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"duplicate-post.d.ts","sourceRoot":"","sources":["../../src/actions/duplicate-post.tsx"],"names":[],"mappings":"AAeA;;GAEG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,UAAU,CAAC;AAGxD,UAAU,gBAAgB,CAAE,IAAI;IAC/B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,iBAAiB,CAAC,EAAE,CAAE,KAAK,EAAE,IAAI,EAAE,KAAM,IAAI,CAAC;CAC9C;AAED,UAAU,MAAM,CAAE,IAAI;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,CAAE,IAAI,EAAE,IAAI,KAAM,OAAO,CAAC;IACvC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,EAAE,CAAE,KAAK,EAAE,gBAAgB,CAAE,IAAI,CAAE,KAAM,GAAG,CAAC,OAAO,CAAC;CAChE;AAED,QAAA,MAAM,aAAa,EAAE,MAAM,CAAE,QAAQ,CA6JpC,CAAC;AAEF;;GAEG;AACH,eAAe,aAAa,CAAC"}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import type { Action } from '@wordpress/dataviews';
|
|
2
1
|
/**
|
|
3
2
|
* Internal dependencies
|
|
4
3
|
*/
|
|
5
4
|
import type { BasePost } from '../types';
|
|
5
|
+
interface RenderModalProps<Item> {
|
|
6
|
+
items: Item[];
|
|
7
|
+
closeModal?: () => void;
|
|
8
|
+
onActionPerformed?: (items: Item[]) => void;
|
|
9
|
+
}
|
|
10
|
+
interface Action<Item> {
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
isEligible?: (item: Item) => boolean;
|
|
14
|
+
modalFocusOnMount?: string;
|
|
15
|
+
RenderModal: (props: RenderModalProps<Item>) => JSX.Element;
|
|
16
|
+
}
|
|
6
17
|
declare const reorderPage: Action<BasePost>;
|
|
7
18
|
/**
|
|
8
19
|
* Reorder action for BasePost.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reorder-page.d.ts","sourceRoot":"","sources":["../../src/actions/reorder-page.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reorder-page.d.ts","sourceRoot":"","sources":["../../src/actions/reorder-page.tsx"],"names":[],"mappings":"AAeA;;GAEG;AACH,OAAO,KAAK,EAAiB,QAAQ,EAAE,MAAM,UAAU,CAAC;AAExD,UAAU,gBAAgB,CAAE,IAAI;IAC/B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,iBAAiB,CAAC,EAAE,CAAE,KAAK,EAAE,IAAI,EAAE,KAAM,IAAI,CAAC;CAC9C;AAED,UAAU,MAAM,CAAE,IAAI;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,CAAE,IAAI,EAAE,IAAI,KAAM,OAAO,CAAC;IACvC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,EAAE,CAAE,KAAK,EAAE,gBAAgB,CAAE,IAAI,CAAE,KAAM,GAAG,CAAC,OAAO,CAAC;CAChE;AA0GD,QAAA,MAAM,WAAW,EAAE,MAAM,CAAE,QAAQ,CAQlC,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.25.
|
|
3
|
+
"version": "0.25.2",
|
|
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",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@wordpress/compose": "^7.33.0",
|
|
49
49
|
"@wordpress/core-data": "^7.33.0",
|
|
50
50
|
"@wordpress/data": "^10.33.0",
|
|
51
|
-
"@wordpress/dataviews": "^10.
|
|
51
|
+
"@wordpress/dataviews": "^10.1.0",
|
|
52
52
|
"@wordpress/date": "^5.33.0",
|
|
53
53
|
"@wordpress/element": "^6.33.0",
|
|
54
54
|
"@wordpress/hooks": "^4.33.0",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"publishConfig": {
|
|
75
75
|
"access": "public"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "2a8c29e6550fa1a246bfce534fbcc545d035a9a7"
|
|
78
78
|
}
|
|
@@ -6,25 +6,32 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
6
6
|
import { __, sprintf, _x } from '@wordpress/i18n';
|
|
7
7
|
import { store as noticesStore } from '@wordpress/notices';
|
|
8
8
|
import { useState } from '@wordpress/element';
|
|
9
|
-
import { DataForm } from '@wordpress/dataviews';
|
|
10
9
|
import {
|
|
11
10
|
Button,
|
|
12
11
|
__experimentalHStack as HStack,
|
|
13
12
|
__experimentalVStack as VStack,
|
|
13
|
+
__experimentalInputControl as InputControl,
|
|
14
14
|
} from '@wordpress/components';
|
|
15
|
-
import type { Action } from '@wordpress/dataviews';
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
17
|
* Internal dependencies
|
|
19
18
|
*/
|
|
20
|
-
import { titleField } from '../fields';
|
|
21
19
|
import type { BasePost, CoreDataError } from '../types';
|
|
22
20
|
import { getItemTitle } from './utils';
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
interface RenderModalProps< Item > {
|
|
23
|
+
items: Item[];
|
|
24
|
+
closeModal?: () => void;
|
|
25
|
+
onActionPerformed?: ( items: Item[] ) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface Action< Item > {
|
|
29
|
+
id: string;
|
|
30
|
+
label: string;
|
|
31
|
+
isEligible?: ( item: Item ) => boolean;
|
|
32
|
+
modalFocusOnMount?: string;
|
|
33
|
+
RenderModal: ( props: RenderModalProps< Item > ) => JSX.Element;
|
|
34
|
+
}
|
|
28
35
|
|
|
29
36
|
const duplicatePost: Action< BasePost > = {
|
|
30
37
|
id: 'duplicate-post',
|
|
@@ -149,14 +156,15 @@ const duplicatePost: Action< BasePost > = {
|
|
|
149
156
|
) }
|
|
150
157
|
</div>
|
|
151
158
|
) }
|
|
152
|
-
<
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
159
|
+
<InputControl
|
|
160
|
+
__next40pxDefaultSize
|
|
161
|
+
label={ __( 'Title' ) }
|
|
162
|
+
placeholder={ __( 'No title' ) }
|
|
163
|
+
value={ getItemTitle( item ) }
|
|
164
|
+
onChange={ ( value ) =>
|
|
157
165
|
setItem( ( prev ) => ( {
|
|
158
166
|
...prev,
|
|
159
|
-
|
|
167
|
+
title: value || __( 'No title' ),
|
|
160
168
|
} ) )
|
|
161
169
|
}
|
|
162
170
|
/>
|