@wordpress/fields 0.42.0 → 0.43.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +8 -0
  3. package/build/actions/duplicate-post.cjs +0 -1
  4. package/build/actions/duplicate-post.cjs.map +2 -2
  5. package/build/actions/reorder-page.cjs +0 -1
  6. package/build/actions/reorder-page.cjs.map +2 -2
  7. package/build/components/media-edit/index.cjs +8 -2
  8. package/build/components/media-edit/index.cjs.map +2 -2
  9. package/build/fields/index.cjs +6 -0
  10. package/build/fields/index.cjs.map +2 -2
  11. package/build/fields/parent/parent-edit.cjs +0 -1
  12. package/build/fields/parent/parent-edit.cjs.map +2 -2
  13. package/build/fields/pattern-description/index.cjs +56 -0
  14. package/build/fields/pattern-description/index.cjs.map +7 -0
  15. package/build/fields/pattern-sync-status/index.cjs +80 -0
  16. package/build/fields/pattern-sync-status/index.cjs.map +7 -0
  17. package/build/fields/slug/slug-edit.cjs +0 -1
  18. package/build/fields/slug/slug-edit.cjs.map +2 -2
  19. package/build/fields/status/index.cjs +3 -0
  20. package/build/fields/status/index.cjs.map +2 -2
  21. package/build/fields/status/status-view.cjs +4 -3
  22. package/build/fields/status/status-view.cjs.map +2 -2
  23. package/build/fields/template/template-edit.cjs +0 -2
  24. package/build/fields/template/template-edit.cjs.map +2 -2
  25. package/build/types.cjs.map +1 -1
  26. package/build-module/actions/duplicate-post.mjs +0 -1
  27. package/build-module/actions/duplicate-post.mjs.map +2 -2
  28. package/build-module/actions/reorder-page.mjs +0 -1
  29. package/build-module/actions/reorder-page.mjs.map +2 -2
  30. package/build-module/components/media-edit/index.mjs +8 -2
  31. package/build-module/components/media-edit/index.mjs.map +2 -2
  32. package/build-module/fields/index.mjs +48 -44
  33. package/build-module/fields/index.mjs.map +2 -2
  34. package/build-module/fields/parent/parent-edit.mjs +0 -1
  35. package/build-module/fields/parent/parent-edit.mjs.map +2 -2
  36. package/build-module/fields/pattern-description/index.mjs +35 -0
  37. package/build-module/fields/pattern-description/index.mjs.map +7 -0
  38. package/build-module/fields/pattern-sync-status/index.mjs +59 -0
  39. package/build-module/fields/pattern-sync-status/index.mjs.map +7 -0
  40. package/build-module/fields/slug/slug-edit.mjs +0 -1
  41. package/build-module/fields/slug/slug-edit.mjs.map +2 -2
  42. package/build-module/fields/status/index.mjs +3 -0
  43. package/build-module/fields/status/index.mjs.map +2 -2
  44. package/build-module/fields/status/status-view.mjs +4 -3
  45. package/build-module/fields/status/status-view.mjs.map +2 -2
  46. package/build-module/fields/template/template-edit.mjs +0 -2
  47. package/build-module/fields/template/template-edit.mjs.map +2 -2
  48. package/build-style/style-rtl.css +7 -3
  49. package/build-style/style.css +7 -3
  50. package/build-types/actions/duplicate-post.d.ts.map +1 -1
  51. package/build-types/actions/reorder-page.d.ts.map +1 -1
  52. package/build-types/actions/reset-post.d.ts.map +1 -1
  53. package/build-types/components/create-template-part-modal/index.d.ts +1 -1
  54. package/build-types/components/create-template-part-modal/index.d.ts.map +1 -1
  55. package/build-types/components/media-edit/index.d.ts +1 -1
  56. package/build-types/components/media-edit/index.d.ts.map +1 -1
  57. package/build-types/fields/index.d.ts +2 -0
  58. package/build-types/fields/index.d.ts.map +1 -1
  59. package/build-types/fields/parent/parent-edit.d.ts +1 -1
  60. package/build-types/fields/parent/parent-edit.d.ts.map +1 -1
  61. package/build-types/fields/password/edit.d.ts +1 -1
  62. package/build-types/fields/password/edit.d.ts.map +1 -1
  63. package/build-types/fields/pattern-description/index.d.ts +14 -0
  64. package/build-types/fields/pattern-description/index.d.ts.map +1 -0
  65. package/build-types/fields/pattern-sync-status/index.d.ts +14 -0
  66. package/build-types/fields/pattern-sync-status/index.d.ts.map +1 -0
  67. package/build-types/fields/post-content-info/post-content-info-view.d.ts +1 -1
  68. package/build-types/fields/post-content-info/post-content-info-view.d.ts.map +1 -1
  69. package/build-types/fields/slug/slug-edit.d.ts.map +1 -1
  70. package/build-types/fields/status/index.d.ts.map +1 -1
  71. package/build-types/fields/status/status-view.d.ts +2 -3
  72. package/build-types/fields/status/status-view.d.ts.map +1 -1
  73. package/build-types/fields/template/template-edit.d.ts.map +1 -1
  74. package/build-types/fields/template-author/view.d.ts +1 -1
  75. package/build-types/fields/template-author/view.d.ts.map +1 -1
  76. package/build-types/fields/title/view.d.ts +1 -1
  77. package/build-types/fields/title/view.d.ts.map +1 -1
  78. package/build-types/stories/index.story.d.ts +4 -3
  79. package/build-types/stories/index.story.d.ts.map +1 -1
  80. package/build-types/types.d.ts +6 -1
  81. package/build-types/types.d.ts.map +1 -1
  82. package/package.json +30 -29
  83. package/src/actions/duplicate-post.tsx +0 -1
  84. package/src/actions/reorder-page.tsx +0 -1
  85. package/src/components/media-edit/index.tsx +25 -19
  86. package/src/components/media-edit/style.scss +0 -2
  87. package/src/fields/index.ts +2 -0
  88. package/src/fields/parent/parent-edit.tsx +0 -1
  89. package/src/fields/pattern-description/index.tsx +44 -0
  90. package/src/fields/pattern-sync-status/index.tsx +76 -0
  91. package/src/fields/slug/slug-edit.tsx +0 -1
  92. package/src/fields/slug/style.scss +1 -1
  93. package/src/fields/status/index.tsx +4 -0
  94. package/src/fields/status/status-view.tsx +5 -3
  95. package/src/fields/template/template-edit.tsx +0 -2
  96. package/src/types.ts +3 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/fields",
3
- "version": "0.42.0",
3
+ "version": "0.43.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",
@@ -47,39 +47,40 @@
47
47
  ],
48
48
  "dependencies": {
49
49
  "@react-spring/web": "^9.4.5",
50
- "@wordpress/api-fetch": "^7.50.0",
51
- "@wordpress/base-styles": "^10.2.0",
52
- "@wordpress/blob": "^4.50.0",
53
- "@wordpress/blocks": "^15.23.0",
54
- "@wordpress/components": "^36.1.0",
55
- "@wordpress/compose": "^8.3.0",
56
- "@wordpress/core-data": "^7.50.0",
57
- "@wordpress/data": "^10.50.0",
58
- "@wordpress/dataviews": "^17.1.0",
59
- "@wordpress/date": "^5.50.0",
60
- "@wordpress/element": "^8.2.0",
61
- "@wordpress/hooks": "^4.50.0",
62
- "@wordpress/html-entities": "^4.50.0",
63
- "@wordpress/i18n": "^6.23.0",
64
- "@wordpress/icons": "^15.1.0",
65
- "@wordpress/media-utils": "^5.50.0",
66
- "@wordpress/notices": "^5.50.0",
67
- "@wordpress/patterns": "^2.50.0",
68
- "@wordpress/primitives": "^4.50.0",
69
- "@wordpress/private-apis": "^1.50.0",
70
- "@wordpress/router": "^1.50.0",
71
- "@wordpress/ui": "^0.17.0",
72
- "@wordpress/url": "^4.50.0",
73
- "@wordpress/warning": "^3.50.0",
74
- "@wordpress/wordcount": "^4.50.0",
50
+ "@wordpress/a11y": "^4.51.0",
51
+ "@wordpress/api-fetch": "^7.51.0",
52
+ "@wordpress/base-styles": "^11.0.0",
53
+ "@wordpress/blob": "^4.51.0",
54
+ "@wordpress/blocks": "^15.24.0",
55
+ "@wordpress/components": "^37.0.0",
56
+ "@wordpress/compose": "^8.4.0",
57
+ "@wordpress/core-data": "^7.51.0",
58
+ "@wordpress/data": "^10.51.0",
59
+ "@wordpress/dataviews": "^17.2.0",
60
+ "@wordpress/date": "^5.51.0",
61
+ "@wordpress/element": "^8.3.0",
62
+ "@wordpress/hooks": "^4.51.0",
63
+ "@wordpress/html-entities": "^4.51.0",
64
+ "@wordpress/i18n": "^6.24.0",
65
+ "@wordpress/icons": "^15.2.0",
66
+ "@wordpress/media-utils": "^5.51.0",
67
+ "@wordpress/notices": "^5.51.0",
68
+ "@wordpress/patterns": "^2.51.0",
69
+ "@wordpress/primitives": "^4.51.0",
70
+ "@wordpress/private-apis": "^1.51.0",
71
+ "@wordpress/router": "^1.51.0",
72
+ "@wordpress/ui": "^0.18.0",
73
+ "@wordpress/url": "^4.51.0",
74
+ "@wordpress/warning": "^3.51.0",
75
+ "@wordpress/wordcount": "^4.51.0",
75
76
  "change-case": "^4.1.2",
76
77
  "client-zip": "^2.4.5",
77
78
  "clsx": "^2.1.1",
78
79
  "remove-accents": "^0.5.0"
79
80
  },
80
81
  "peerDependencies": {
81
- "@types/react": "^18.3.27",
82
- "react": "^18.0.0"
82
+ "@types/react": "^18 || ^19",
83
+ "react": "^18 || ^19"
83
84
  },
84
85
  "peerDependenciesMeta": {
85
86
  "@types/react": {
@@ -89,5 +90,5 @@
89
90
  "publishConfig": {
90
91
  "access": "public"
91
92
  },
92
- "gitHead": "fee6e24e8e63d36f6bbcf487c193461e9bd79753"
93
+ "gitHead": "e9a74f9c14095a34398ecd4d1f7a908e55051205"
93
94
  }
@@ -153,7 +153,6 @@ const duplicatePost: Action< BasePost > = {
153
153
  </div>
154
154
  ) }
155
155
  <InputControl
156
- __next40pxDefaultSize
157
156
  label={ __( 'Title' ) }
158
157
  placeholder={ __( 'No title' ) }
159
158
  value={ getItemTitle( item ) }
@@ -93,7 +93,6 @@ function ReorderModal( {
93
93
  ) }
94
94
  </div>
95
95
  <InputControl
96
- __next40pxDefaultSize
97
96
  label={ __( 'Order' ) }
98
97
  type="number"
99
98
  value={
@@ -41,6 +41,7 @@ import {
41
41
  chevronRight,
42
42
  } from '@wordpress/icons';
43
43
  import { VisuallyHidden, Tooltip } from '@wordpress/ui';
44
+ import { speak } from '@wordpress/a11y';
44
45
  import {
45
46
  MediaUpload,
46
47
  uploadMedia,
@@ -838,6 +839,13 @@ export default function MediaEdit< Item >( {
838
839
  setCustomValidity( undefined );
839
840
  }
840
841
  }, [ isTouched, field.isValid, validity ] );
842
+
843
+ useEffect( () => {
844
+ if ( isTouched && customValidity?.message ) {
845
+ speak( customValidity.message );
846
+ }
847
+ }, [ isTouched, customValidity?.message ] );
848
+
841
849
  const onBlur = useCallback(
842
850
  ( event: React.FocusEvent< HTMLElement > ) => {
843
851
  if ( isTouched ) {
@@ -961,25 +969,23 @@ export default function MediaEdit< Item >( {
961
969
  />
962
970
  </VisuallyHidden>
963
971
  { customValidity && (
964
- <div aria-live="polite">
965
- <p
966
- className={ clsx(
967
- 'components-validated-control__indicator',
968
- {
969
- 'is-invalid': customValidity.type === 'invalid',
970
- 'is-valid': customValidity.type === 'valid',
971
- }
972
- ) }
973
- >
974
- <WCIcon
975
- className="components-validated-control__indicator-icon"
976
- icon={ errorIcon }
977
- size={ 16 }
978
- fill="currentColor"
979
- />
980
- { customValidity.message }
981
- </p>
982
- </div>
972
+ <p
973
+ className={ clsx(
974
+ 'components-validated-control__indicator',
975
+ {
976
+ 'is-invalid': customValidity.type === 'invalid',
977
+ 'is-valid': customValidity.type === 'valid',
978
+ }
979
+ ) }
980
+ >
981
+ <WCIcon
982
+ className="components-validated-control__indicator-icon"
983
+ icon={ errorIcon }
984
+ size={ 16 }
985
+ fill="currentColor"
986
+ />
987
+ { customValidity.message }
988
+ </p>
983
989
  ) }
984
990
  </div>
985
991
  );
@@ -35,7 +35,6 @@ fieldset.fields__media-edit {
35
35
  line-height: 1.5;
36
36
  }
37
37
 
38
- /* stylelint-disable-next-line property-no-unknown -- '@container' not globally permitted */
39
38
  container-type: inline-size;
40
39
 
41
40
  .fields__media-edit-compact-group {
@@ -264,7 +263,6 @@ fieldset.fields__media-edit {
264
263
  // Auto-fill columns based on minimum item width
265
264
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
266
265
 
267
- /* stylelint-disable-next-line property-no-unknown -- '@container' not globally permitted */
268
266
  @container (max-width: 500px) {
269
267
  grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
270
268
  }
@@ -3,6 +3,8 @@ export { default as titleField } from './title';
3
3
  export { default as pageTitleField } from './page-title';
4
4
  export { default as templateTitleField } from './template-title';
5
5
  export { default as patternTitleField } from './pattern-title';
6
+ export { default as patternDescriptionField } from './pattern-description';
7
+ export { default as patternSyncStatusField } from './pattern-sync-status';
6
8
  export { default as orderField } from './order';
7
9
  export { default as featuredImageField } from './featured-image';
8
10
  export { default as templateField } from './template';
@@ -261,7 +261,6 @@ export function PageAttributesParent( {
261
261
 
262
262
  return (
263
263
  <ComboboxControl
264
- __next40pxDefaultSize
265
264
  label={ __( 'Parent' ) }
266
265
  help={ __( 'Choose a parent page.' ) }
267
266
  value={ pageId?.toString() }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+ import { decodeEntities } from '@wordpress/html-entities';
6
+ import { __ } from '@wordpress/i18n';
7
+ import { Text } from '@wordpress/ui';
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import type { Pattern } from '../../types';
13
+
14
+ function getPatternDescription( item: Pattern ) {
15
+ if ( typeof item.excerpt === 'string' ) {
16
+ return decodeEntities( item.excerpt );
17
+ }
18
+ return decodeEntities( item.excerpt?.raw || '' );
19
+ }
20
+
21
+ const patternDescriptionField: Field< Pattern > = {
22
+ id: 'excerpt',
23
+ type: 'text',
24
+ label: __( 'Description' ),
25
+ placeholder: __( 'Add a description' ),
26
+ getValue: ( { item } ) => getPatternDescription( item ),
27
+ render: ( { item } ) => {
28
+ const description = getPatternDescription( item );
29
+ return description ? <Text>{ description }</Text> : null;
30
+ },
31
+ Edit: {
32
+ control: 'textarea',
33
+ rows: 4,
34
+ },
35
+ enableSorting: false,
36
+ enableHiding: false,
37
+ filterBy: false,
38
+ enableGlobalSearch: true,
39
+ };
40
+
41
+ /**
42
+ * Description field for patterns.
43
+ */
44
+ export default patternDescriptionField;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+ import { __, _x } from '@wordpress/i18n';
6
+ // @ts-ignore
7
+ import { privateApis as patternPrivateApis } from '@wordpress/patterns';
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import type { Pattern } from '../../types';
13
+ import { unlock } from '../../lock-unlock';
14
+
15
+ const { PATTERN_SYNC_TYPES, PATTERN_TYPES } = unlock( patternPrivateApis );
16
+
17
+ const SYNC_STATUS_FILTERS = [
18
+ {
19
+ value: PATTERN_SYNC_TYPES.full,
20
+ label: _x( 'Synced', 'pattern (singular)' ),
21
+ description: __( 'Patterns that are kept in sync across the site.' ),
22
+ },
23
+ {
24
+ value: PATTERN_SYNC_TYPES.unsynced,
25
+ label: _x( 'Not synced', 'pattern (singular)' ),
26
+ description: __(
27
+ 'Patterns that can be changed freely without affecting the site.'
28
+ ),
29
+ },
30
+ ];
31
+
32
+ function getPatternSyncStatus( item: Pattern ) {
33
+ if ( item.type && item.type !== PATTERN_TYPES.user ) {
34
+ return PATTERN_SYNC_TYPES.unsynced;
35
+ }
36
+ // When a pattern is first created directly from the post editor
37
+ // (`post-new.php?post_type=wp_block`), the top-level sync status is not
38
+ // set yet, so fall back to the meta value.
39
+ if ( item.meta?.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced ) {
40
+ return PATTERN_SYNC_TYPES.unsynced;
41
+ }
42
+ return item.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full;
43
+ }
44
+
45
+ const patternSyncStatusField: Field< Pattern > = {
46
+ id: 'sync-status',
47
+ type: 'text',
48
+ label: __( 'Sync status' ),
49
+ readOnly: true,
50
+ enableSorting: false,
51
+ enableHiding: true,
52
+ elements: SYNC_STATUS_FILTERS,
53
+ filterBy: {
54
+ operators: [ 'is' ],
55
+ isPrimary: true,
56
+ },
57
+ render: ( { item } ) => {
58
+ const syncStatus = getPatternSyncStatus( item );
59
+ return (
60
+ <span
61
+ className={ `fields-field__pattern-sync-status fields-field__pattern-sync-status-${ syncStatus }` }
62
+ >
63
+ {
64
+ SYNC_STATUS_FILTERS.find(
65
+ ( { value } ) => value === syncStatus
66
+ )?.label
67
+ }
68
+ </span>
69
+ );
70
+ },
71
+ };
72
+
73
+ /**
74
+ * Sync status field for patterns.
75
+ */
76
+ export default patternSyncStatusField;
@@ -87,7 +87,6 @@ const SlugEdit = ( {
87
87
  </ExternalLink>
88
88
  </VStack>
89
89
  <InputControl
90
- __next40pxDefaultSize
91
90
  prefix={
92
91
  <InputControlPrefixWrapper>
93
92
  /
@@ -21,7 +21,7 @@
21
21
  flex-direction: column;
22
22
 
23
23
  .fields-controls__slug-help-slug {
24
- font-weight: 600;
24
+ font-weight: var(--wpds-typography-font-weight-emphasis);
25
25
  }
26
26
  }
27
27
  }
@@ -18,6 +18,10 @@ const statusField: Field< BasePost > = {
18
18
  id: 'status',
19
19
  type: 'text',
20
20
  elements: STATUSES,
21
+ // An auto-draft is a draft that hasn't been saved yet, so treat it as
22
+ // one for display, selection, and filtering.
23
+ getValue: ( { item } ) =>
24
+ item.status === 'auto-draft' ? 'draft' : item.status,
21
25
  render: StatusView,
22
26
  Edit: 'radio',
23
27
  enableSorting: false,
@@ -5,6 +5,7 @@ import {
5
5
  __experimentalHStack as HStack,
6
6
  Icon as WCIcon,
7
7
  } from '@wordpress/components';
8
+ import type { DataViewRenderFieldProps } from '@wordpress/dataviews';
8
9
 
9
10
  /**
10
11
  * Internal dependencies
@@ -12,9 +13,10 @@ import {
12
13
  import type { BasePost } from '../../types';
13
14
  import STATUSES from './status-elements';
14
15
 
15
- function StatusView( { item }: { item: BasePost } ) {
16
- const status = STATUSES.find( ( { value } ) => value === item.status );
17
- const label = status?.label || item.status;
16
+ function StatusView( { item, field }: DataViewRenderFieldProps< BasePost > ) {
17
+ const currentStatus = field.getValue( { item } );
18
+ const status = STATUSES.find( ( { value } ) => value === currentStatus );
19
+ const label = status?.label || currentStatus;
18
20
  const icon = status?.icon;
19
21
  return (
20
22
  <HStack alignment="left" spacing={ 0 }>
@@ -61,7 +61,6 @@ function ClassicTemplateEdit( {
61
61
  );
62
62
  return (
63
63
  <SelectControl
64
- __next40pxDefaultSize
65
64
  label={ __( 'Template' ) }
66
65
  hideLabelFromVision
67
66
  value={ value }
@@ -126,7 +125,6 @@ function BlockThemeTemplateEdit( {
126
125
  }, [ templates, defaultTemplateLabel ] );
127
126
  return (
128
127
  <SelectControl
129
- __next40pxDefaultSize
130
128
  label={ __( 'Template' ) }
131
129
  hideLabelFromVision
132
130
  value={ value }
package/src/types.ts CHANGED
@@ -119,7 +119,9 @@ export interface TemplatePart extends CommonPost, TemplateAuthorFields {
119
119
  export interface Pattern extends CommonPost {
120
120
  slug: string;
121
121
  title: { raw: string };
122
- wp_pattern_sync_status: string;
122
+ excerpt?: string | { raw: string; rendered: string };
123
+ meta?: Record< string, any >;
124
+ wp_pattern_sync_status?: string;
123
125
  }
124
126
 
125
127
  export interface SiteSettings {