@wordpress/fields 0.25.0 → 0.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +2 -2
- package/src/actions/duplicate-post.tsx +21 -13
- package/src/actions/reorder-page.tsx +38 -22
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -6,24 +6,39 @@ 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, useFormValidity } 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, RenderModalProps } from '@wordpress/dataviews';
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
17
|
* Internal dependencies
|
|
19
18
|
*/
|
|
20
19
|
import type { CoreDataError, BasePost } from '../types';
|
|
21
|
-
import { orderField } from '../fields';
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
interface RenderModalProps< Item > {
|
|
22
|
+
items: Item[];
|
|
23
|
+
closeModal?: () => void;
|
|
24
|
+
onActionPerformed?: ( items: Item[] ) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface Action< Item > {
|
|
28
|
+
id: string;
|
|
29
|
+
label: string;
|
|
30
|
+
isEligible?: ( item: Item ) => boolean;
|
|
31
|
+
modalFocusOnMount?: string;
|
|
32
|
+
RenderModal: ( props: RenderModalProps< Item > ) => JSX.Element;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function isItemValid( item: BasePost ): boolean {
|
|
36
|
+
return (
|
|
37
|
+
typeof item.menu_order === 'number' &&
|
|
38
|
+
Number.isInteger( item.menu_order ) &&
|
|
39
|
+
item.menu_order > 0
|
|
40
|
+
);
|
|
41
|
+
}
|
|
27
42
|
|
|
28
43
|
function ReorderModal( {
|
|
29
44
|
items,
|
|
@@ -31,17 +46,12 @@ function ReorderModal( {
|
|
|
31
46
|
onActionPerformed,
|
|
32
47
|
}: RenderModalProps< BasePost > ) {
|
|
33
48
|
const [ item, setItem ] = useState( items[ 0 ] );
|
|
34
|
-
const orderInput = item.menu_order;
|
|
35
49
|
const { editEntityRecord, saveEditedEntityRecord } =
|
|
36
50
|
useDispatch( coreStore );
|
|
37
51
|
const { createSuccessNotice, createErrorNotice } =
|
|
38
52
|
useDispatch( noticesStore );
|
|
39
53
|
|
|
40
|
-
const
|
|
41
|
-
item,
|
|
42
|
-
fields,
|
|
43
|
-
formOrderAction
|
|
44
|
-
);
|
|
54
|
+
const isValid = isItemValid( item );
|
|
45
55
|
|
|
46
56
|
async function onOrder( event: React.FormEvent ) {
|
|
47
57
|
event.preventDefault();
|
|
@@ -52,7 +62,7 @@ function ReorderModal( {
|
|
|
52
62
|
|
|
53
63
|
try {
|
|
54
64
|
await editEntityRecord( 'postType', item.type, item.id, {
|
|
55
|
-
menu_order:
|
|
65
|
+
menu_order: item.menu_order,
|
|
56
66
|
} );
|
|
57
67
|
closeModal?.();
|
|
58
68
|
// Persist edited entity.
|
|
@@ -83,15 +93,21 @@ function ReorderModal( {
|
|
|
83
93
|
'Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.'
|
|
84
94
|
) }
|
|
85
95
|
</div>
|
|
86
|
-
<
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
<InputControl
|
|
97
|
+
__next40pxDefaultSize
|
|
98
|
+
label={ __( 'Order' ) }
|
|
99
|
+
type="number"
|
|
100
|
+
value={
|
|
101
|
+
typeof item.menu_order === 'number' &&
|
|
102
|
+
Number.isInteger( item.menu_order )
|
|
103
|
+
? String( item.menu_order )
|
|
104
|
+
: ''
|
|
105
|
+
}
|
|
106
|
+
onChange={ ( value ) => {
|
|
107
|
+
const parsed = parseInt( value as string, 10 ); // absorbs '' and undefined
|
|
108
|
+
setItem( {
|
|
93
109
|
...item,
|
|
94
|
-
|
|
110
|
+
menu_order: isNaN( parsed ) ? undefined : parsed,
|
|
95
111
|
} );
|
|
96
112
|
} }
|
|
97
113
|
/>
|