@wordpress/fields 0.24.1-next.ff1cebbba.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/fields",
3
- "version": "0.24.1-next.ff1cebbba.0",
3
+ "version": "0.25.1",
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.32.1-next.ff1cebbba.0",
43
- "@wordpress/base-styles": "^6.8.1-next.ff1cebbba.0",
44
- "@wordpress/blob": "^4.32.1-next.ff1cebbba.0",
45
- "@wordpress/block-editor": "^15.5.1-next.ff1cebbba.0",
46
- "@wordpress/blocks": "^15.5.1-next.ff1cebbba.0",
47
- "@wordpress/components": "^30.6.1-next.ff1cebbba.0",
48
- "@wordpress/compose": "^7.32.1-next.ff1cebbba.0",
49
- "@wordpress/core-data": "^7.32.1-next.ff1cebbba.0",
50
- "@wordpress/data": "^10.32.1-next.ff1cebbba.0",
51
- "@wordpress/dataviews": "^10.0.1-next.ff1cebbba.0",
52
- "@wordpress/date": "^5.32.1-next.ff1cebbba.0",
53
- "@wordpress/element": "^6.32.1-next.ff1cebbba.0",
54
- "@wordpress/hooks": "^4.32.1-next.ff1cebbba.0",
55
- "@wordpress/html-entities": "^4.32.1-next.ff1cebbba.0",
56
- "@wordpress/i18n": "^6.5.1-next.ff1cebbba.0",
57
- "@wordpress/icons": "^11.0.1-next.ff1cebbba.0",
58
- "@wordpress/media-utils": "^5.32.1-next.ff1cebbba.0",
59
- "@wordpress/notices": "^5.32.1-next.ff1cebbba.0",
60
- "@wordpress/patterns": "^2.32.1-next.ff1cebbba.0",
61
- "@wordpress/primitives": "^4.32.1-next.ff1cebbba.0",
62
- "@wordpress/private-apis": "^1.32.1-next.ff1cebbba.0",
63
- "@wordpress/router": "^1.32.1-next.ff1cebbba.0",
64
- "@wordpress/url": "^4.32.1-next.ff1cebbba.0",
65
- "@wordpress/warning": "^3.32.1-next.ff1cebbba.0",
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": "c5b659710aff01d40d2eb97b211eb2cec9c07d3b"
77
+ "gitHead": "0eca9b157f332afd4d1a53c62bd862ae9a159c57"
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
- const fields = [ titleField ];
25
- const formDuplicateAction = {
26
- fields: [ 'title' ],
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',
@@ -142,14 +149,22 @@ const duplicatePost: Action< BasePost > = {
142
149
  return (
143
150
  <form onSubmit={ createPage }>
144
151
  <VStack spacing={ 3 }>
145
- <DataForm
146
- data={ item }
147
- fields={ fields }
148
- form={ formDuplicateAction }
149
- onChange={ ( changes ) =>
152
+ { item.type === 'wp_registered_template' && (
153
+ <div>
154
+ { __(
155
+ 'You are about to duplicate a bundled template. Changes will not be live until you activate the new template.'
156
+ ) }
157
+ </div>
158
+ ) }
159
+ <InputControl
160
+ __next40pxDefaultSize
161
+ label={ __( 'Title' ) }
162
+ placeholder={ __( 'No title' ) }
163
+ value={ getItemTitle( item ) }
164
+ onChange={ ( value ) =>
150
165
  setItem( ( prev ) => ( {
151
166
  ...prev,
152
- ...changes,
167
+ title: value || __( 'No title' ),
153
168
  } ) )
154
169
  }
155
170
  />
@@ -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, isItemValid } 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
- const fields = [ orderField ];
24
- const formOrderAction = {
25
- fields: [ 'menu_order' ],
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,22 +46,23 @@ 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
 
54
+ const isValid = isItemValid( item );
55
+
40
56
  async function onOrder( event: React.FormEvent ) {
41
57
  event.preventDefault();
42
58
 
43
- if ( ! isItemValid( item, fields, formOrderAction ) ) {
59
+ if ( ! isValid ) {
44
60
  return;
45
61
  }
46
62
 
47
63
  try {
48
64
  await editEntityRecord( 'postType', item.type, item.id, {
49
- menu_order: orderInput,
65
+ menu_order: item.menu_order,
50
66
  } );
51
67
  closeModal?.();
52
68
  // Persist edited entity.
@@ -68,7 +84,7 @@ function ReorderModal( {
68
84
  } );
69
85
  }
70
86
  }
71
- const isSaveDisabled = ! isItemValid( item, fields, formOrderAction );
87
+
72
88
  return (
73
89
  <form onSubmit={ onOrder }>
74
90
  <VStack spacing="5">
@@ -77,16 +93,23 @@ function ReorderModal( {
77
93
  'Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.'
78
94
  ) }
79
95
  </div>
80
- <DataForm
81
- data={ item }
82
- fields={ fields }
83
- form={ formOrderAction }
84
- onChange={ ( changes ) =>
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
85
108
  setItem( {
86
109
  ...item,
87
- ...changes,
88
- } )
89
- }
110
+ menu_order: isNaN( parsed ) ? undefined : parsed,
111
+ } );
112
+ } }
90
113
  />
91
114
  <HStack justify="right">
92
115
  <Button
@@ -103,7 +126,7 @@ function ReorderModal( {
103
126
  variant="primary"
104
127
  type="submit"
105
128
  accessibleWhenDisabled
106
- disabled={ isSaveDisabled }
129
+ disabled={ ! isValid }
107
130
  >
108
131
  { __( 'Save' ) }
109
132
  </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
- elements: [],
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 || '';