@wordpress/fields 0.42.0 → 0.42.1-next.v.202607070741.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 (42) hide show
  1. package/README.md +8 -0
  2. package/build/fields/index.cjs +6 -0
  3. package/build/fields/index.cjs.map +2 -2
  4. package/build/fields/parent/parent-edit.cjs +0 -1
  5. package/build/fields/parent/parent-edit.cjs.map +2 -2
  6. package/build/fields/pattern-description/index.cjs +56 -0
  7. package/build/fields/pattern-description/index.cjs.map +7 -0
  8. package/build/fields/pattern-sync-status/index.cjs +80 -0
  9. package/build/fields/pattern-sync-status/index.cjs.map +7 -0
  10. package/build/fields/template/template-edit.cjs +0 -2
  11. package/build/fields/template/template-edit.cjs.map +2 -2
  12. package/build/types.cjs.map +1 -1
  13. package/build-module/fields/index.mjs +48 -44
  14. package/build-module/fields/index.mjs.map +2 -2
  15. package/build-module/fields/parent/parent-edit.mjs +0 -1
  16. package/build-module/fields/parent/parent-edit.mjs.map +2 -2
  17. package/build-module/fields/pattern-description/index.mjs +35 -0
  18. package/build-module/fields/pattern-description/index.mjs.map +7 -0
  19. package/build-module/fields/pattern-sync-status/index.mjs +59 -0
  20. package/build-module/fields/pattern-sync-status/index.mjs.map +7 -0
  21. package/build-module/fields/template/template-edit.mjs +0 -2
  22. package/build-module/fields/template/template-edit.mjs.map +2 -2
  23. package/build-style/style-rtl.css +6 -2
  24. package/build-style/style.css +6 -2
  25. package/build-types/fields/index.d.ts +2 -0
  26. package/build-types/fields/index.d.ts.map +1 -1
  27. package/build-types/fields/parent/parent-edit.d.ts.map +1 -1
  28. package/build-types/fields/pattern-description/index.d.ts +14 -0
  29. package/build-types/fields/pattern-description/index.d.ts.map +1 -0
  30. package/build-types/fields/pattern-sync-status/index.d.ts +14 -0
  31. package/build-types/fields/pattern-sync-status/index.d.ts.map +1 -0
  32. package/build-types/fields/template/template-edit.d.ts.map +1 -1
  33. package/build-types/types.d.ts +6 -1
  34. package/build-types/types.d.ts.map +1 -1
  35. package/package.json +27 -27
  36. package/src/components/media-edit/style.scss +0 -2
  37. package/src/fields/index.ts +2 -0
  38. package/src/fields/parent/parent-edit.tsx +0 -1
  39. package/src/fields/pattern-description/index.tsx +44 -0
  40. package/src/fields/pattern-sync-status/index.tsx +76 -0
  41. package/src/fields/template/template-edit.tsx +0 -2
  42. package/src/types.ts +3 -1
@@ -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;
@@ -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 {