@wordpress/edit-site 4.10.0 → 4.11.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 (69) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/add-new-template/add-custom-template-modal.js +22 -42
  3. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
  4. package/build/components/add-new-template/new-template.js +17 -20
  5. package/build/components/add-new-template/new-template.js.map +1 -1
  6. package/build/components/add-new-template/utils.js +366 -239
  7. package/build/components/add-new-template/utils.js.map +1 -1
  8. package/build/components/block-editor/index.js +1 -3
  9. package/build/components/block-editor/index.js.map +1 -1
  10. package/build/components/global-styles/dimensions-panel.js +183 -13
  11. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  12. package/build/components/global-styles/hooks.js +1 -1
  13. package/build/components/global-styles/hooks.js.map +1 -1
  14. package/build/components/global-styles/use-global-styles-output.js +95 -17
  15. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  16. package/build/components/global-styles/utils.js +31 -0
  17. package/build/components/global-styles/utils.js.map +1 -1
  18. package/build/components/header/index.js +7 -6
  19. package/build/components/header/index.js.map +1 -1
  20. package/build/hooks/index.js +2 -0
  21. package/build/hooks/index.js.map +1 -1
  22. package/build/hooks/template-part-edit.js +86 -0
  23. package/build/hooks/template-part-edit.js.map +1 -0
  24. package/build-module/components/add-new-template/add-custom-template-modal.js +23 -43
  25. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  26. package/build-module/components/add-new-template/new-template.js +18 -21
  27. package/build-module/components/add-new-template/new-template.js.map +1 -1
  28. package/build-module/components/add-new-template/utils.js +365 -227
  29. package/build-module/components/add-new-template/utils.js.map +1 -1
  30. package/build-module/components/block-editor/index.js +1 -2
  31. package/build-module/components/block-editor/index.js.map +1 -1
  32. package/build-module/components/global-styles/dimensions-panel.js +183 -14
  33. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  34. package/build-module/components/global-styles/hooks.js +1 -1
  35. package/build-module/components/global-styles/hooks.js.map +1 -1
  36. package/build-module/components/global-styles/use-global-styles-output.js +94 -22
  37. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  38. package/build-module/components/global-styles/utils.js +29 -0
  39. package/build-module/components/global-styles/utils.js.map +1 -1
  40. package/build-module/components/header/index.js +8 -6
  41. package/build-module/components/header/index.js.map +1 -1
  42. package/build-module/hooks/index.js +1 -0
  43. package/build-module/hooks/index.js.map +1 -1
  44. package/build-module/hooks/template-part-edit.js +67 -0
  45. package/build-module/hooks/template-part-edit.js.map +1 -0
  46. package/build-style/style-rtl.css +25 -25
  47. package/build-style/style.css +25 -25
  48. package/package.json +29 -29
  49. package/src/components/add-new-template/add-custom-template-modal.js +27 -45
  50. package/src/components/add-new-template/new-template.js +27 -64
  51. package/src/components/add-new-template/style.scss +20 -8
  52. package/src/components/add-new-template/utils.js +398 -229
  53. package/src/components/block-editor/index.js +0 -2
  54. package/src/components/global-styles/dimensions-panel.js +207 -14
  55. package/src/components/global-styles/hooks.js +2 -0
  56. package/src/components/global-styles/test/use-global-styles-output.js +64 -1
  57. package/src/components/global-styles/use-global-styles-output.js +100 -8
  58. package/src/components/global-styles/utils.js +31 -0
  59. package/src/components/header/index.js +9 -10
  60. package/src/components/header/style.scss +5 -3
  61. package/src/components/sidebar/style.scss +4 -0
  62. package/src/hooks/index.js +1 -0
  63. package/src/hooks/template-part-edit.js +82 -0
  64. package/src/style.scss +0 -1
  65. package/build/components/edit-template-part-menu-button/index.js +0 -90
  66. package/build/components/edit-template-part-menu-button/index.js.map +0 -1
  67. package/build-module/components/edit-template-part-menu-button/index.js +0 -72
  68. package/build-module/components/edit-template-part-menu-button/index.js.map +0 -1
  69. package/src/components/edit-template-part-menu-button/index.js +0 -82
@@ -11,7 +11,6 @@ import {
11
11
  SearchControl,
12
12
  TextHighlight,
13
13
  __experimentalText as Text,
14
- __experimentalHeading as Heading,
15
14
  __unstableComposite as Composite,
16
15
  __unstableUseCompositeState as useCompositeState,
17
16
  __unstableCompositeItem as CompositeItem,
@@ -26,34 +25,6 @@ import { mapToIHasNameAndId } from './utils';
26
25
 
27
26
  const EMPTY_ARRAY = [];
28
27
 
29
- function selectSuggestion( suggestion, onSelect, entityForSuggestions ) {
30
- const {
31
- labels,
32
- slug,
33
- config: { templateSlug, templatePrefix },
34
- } = entityForSuggestions;
35
- const title = sprintf(
36
- // translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a post type or taxonomy and %2$s is the name of the post or term, e.g. "Post: Hello, WordPress", "Category: shoes"
37
- __( '%1$s: %2$s' ),
38
- labels.singular_name,
39
- suggestion.name
40
- );
41
- let newTemplateSlug = `${ templateSlug || slug }-${ suggestion.slug }`;
42
- if ( templatePrefix ) {
43
- newTemplateSlug = templatePrefix + newTemplateSlug;
44
- }
45
- const newTemplate = {
46
- title,
47
- description: sprintf(
48
- // translators: Represents the description of a user's custom template in the Site Editor, e.g. "Template for Post: Hello, WordPress"
49
- __( 'Template for %1$s' ),
50
- title
51
- ),
52
- slug: newTemplateSlug,
53
- };
54
- onSelect( newTemplate );
55
- }
56
-
57
28
  function SuggestionListItem( {
58
29
  suggestion,
59
30
  search,
@@ -70,7 +41,11 @@ function SuggestionListItem( {
70
41
  { ...composite }
71
42
  className={ baseCssClass }
72
43
  onClick={ () =>
73
- selectSuggestion( suggestion, onSelect, entityForSuggestions )
44
+ onSelect(
45
+ entityForSuggestions.config.getSpecificTemplate(
46
+ suggestion
47
+ )
48
+ )
74
49
  }
75
50
  >
76
51
  <span className={ `${ baseCssClass }__title` }>
@@ -98,18 +73,16 @@ function useDebouncedInput() {
98
73
  }
99
74
 
100
75
  function useSearchSuggestions( entityForSuggestions, search ) {
101
- const { config, postsToExclude } = entityForSuggestions;
76
+ const { config } = entityForSuggestions;
102
77
  const query = useMemo(
103
78
  () => ( {
104
79
  order: 'asc',
105
- _fields: 'id,name,title,slug,link',
106
80
  context: 'view',
107
81
  search,
108
- orderBy: config.getOrderBy( { search } ),
109
- exclude: postsToExclude,
110
82
  per_page: search ? 20 : 10,
83
+ ...config.queryArgs( search ),
111
84
  } ),
112
- [ search, config, postsToExclude ]
85
+ [ search, config ]
113
86
  );
114
87
  const { records: searchResults, hasResolved: searchHasResolved } =
115
88
  useEntityRecords(
@@ -145,19 +118,26 @@ function SuggestionList( { entityForSuggestions, onSelect } ) {
145
118
  debouncedSearch
146
119
  );
147
120
  const { labels } = entityForSuggestions;
121
+ const [ showSearchControl, setShowSearchControl ] = useState( false );
122
+ if ( ! showSearchControl && suggestions?.length > 9 ) {
123
+ setShowSearchControl( true );
124
+ }
148
125
  return (
149
126
  <>
150
- <SearchControl
151
- onChange={ setSearch }
152
- value={ search }
153
- label={ labels.search_items }
154
- placeholder={ labels.search_items }
155
- />
127
+ { showSearchControl && (
128
+ <SearchControl
129
+ onChange={ setSearch }
130
+ value={ search }
131
+ label={ labels.search_items }
132
+ placeholder={ labels.search_items }
133
+ />
134
+ ) }
156
135
  { !! suggestions?.length && (
157
136
  <Composite
158
137
  { ...composite }
159
138
  role="listbox"
160
139
  className="edit-site-custom-template-modal__suggestions_list"
140
+ aria-label={ __( 'Suggestions list' ) }
161
141
  >
162
142
  { suggestions.map( ( suggestion ) => (
163
143
  <SuggestionListItem
@@ -210,15 +190,16 @@ function AddCustomTemplateModal( { onClose, onSelect, entityForSuggestions } ) {
210
190
  >
211
191
  <FlexItem
212
192
  isBlock
193
+ as={ Button }
213
194
  onClick={ () => {
214
195
  const { slug, title, description } =
215
196
  entityForSuggestions.template;
216
197
  onSelect( { slug, title, description } );
217
198
  } }
218
199
  >
219
- <Heading level={ 5 }>
200
+ <Text as="span" weight={ 600 }>
220
201
  { entityForSuggestions.labels.all_items }
221
- </Heading>
202
+ </Text>
222
203
  <Text as="span">
223
204
  {
224
205
  // translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.
@@ -228,13 +209,14 @@ function AddCustomTemplateModal( { onClose, onSelect, entityForSuggestions } ) {
228
209
  </FlexItem>
229
210
  <FlexItem
230
211
  isBlock
212
+ as={ Button }
231
213
  onClick={ () => {
232
214
  setShowSearchEntities( true );
233
215
  } }
234
216
  >
235
- <Heading level={ 5 }>
217
+ <Text as="span" weight={ 600 }>
236
218
  { entityForSuggestions.labels.singular_name }
237
- </Heading>
219
+ </Text>
238
220
  <Text as="span">
239
221
  {
240
222
  // translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.
@@ -36,13 +36,8 @@ import AddCustomTemplateModal from './add-custom-template-modal';
36
36
  import {
37
37
  useExistingTemplates,
38
38
  useDefaultTemplateTypes,
39
- entitiesConfig,
40
- usePostTypes,
41
- usePostTypePage,
42
- useTaxonomies,
43
- useTaxonomyCategory,
44
- useTaxonomyTag,
45
- useExtraTemplates,
39
+ useTaxonomiesMenuItems,
40
+ usePostTypeMenuItems,
46
41
  } from './utils';
47
42
  import AddCustomGenericTemplateModal from './add-custom-generic-template-modal';
48
43
  import { useHistory } from '../routes';
@@ -225,19 +220,11 @@ function useMissingTemplates(
225
220
  setEntityForSuggestions,
226
221
  setShowCustomTemplateModal
227
222
  ) {
228
- const postTypes = usePostTypes();
229
- const pagePostType = usePostTypePage();
230
- const taxonomies = useTaxonomies();
231
- const categoryTaxonomy = useTaxonomyCategory();
232
- const tagTaxonomy = useTaxonomyTag();
233
-
234
223
  const existingTemplates = useExistingTemplates();
235
224
  const defaultTemplateTypes = useDefaultTemplateTypes();
236
-
237
225
  const existingTemplateSlugs = ( existingTemplates || [] ).map(
238
226
  ( { slug } ) => slug
239
227
  );
240
-
241
228
  const missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(
242
229
  ( template ) =>
243
230
  DEFAULT_TEMPLATE_SLUGS.includes( template.slug ) &&
@@ -247,49 +234,35 @@ function useMissingTemplates(
247
234
  setShowCustomTemplateModal( true );
248
235
  setEntityForSuggestions( _entityForSuggestions );
249
236
  };
250
- // TODO: find better names for these variables. `useExtraTemplates` returns an array of items.
251
- const categoryMenuItem = useExtraTemplates(
252
- categoryTaxonomy,
253
- entitiesConfig.category,
254
- onClickMenuItem
255
- );
256
- const tagMenuItem = useExtraTemplates(
257
- tagTaxonomy,
258
- entitiesConfig.tag,
259
- onClickMenuItem
260
- );
261
- const pageMenuItem = useExtraTemplates(
262
- pagePostType,
263
- entitiesConfig.page,
264
- onClickMenuItem
265
- );
266
237
  // We need to replace existing default template types with
267
238
  // the create specific template functionality. The original
268
239
  // info (title, description, etc.) is preserved in the
269
- // `useExtraTemplates` hook.
240
+ // used hooks.
270
241
  const enhancedMissingDefaultTemplateTypes = [ ...missingDefaultTemplates ];
271
- [ categoryMenuItem, tagMenuItem, pageMenuItem ].forEach( ( menuItem ) => {
272
- if ( ! menuItem?.length ) {
273
- return;
274
- }
275
- const matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(
276
- ( template ) => template.slug === menuItem[ 0 ].slug
277
- );
278
- // Some default template types might have been filtered above from
279
- // `missingDefaultTemplates` because they only check for the general
280
- // template. So here we either replace or append the item, augmented
281
- // with the check if it has available specific item to create a
282
- // template for.
283
- if ( matchIndex > -1 ) {
284
- enhancedMissingDefaultTemplateTypes.splice(
285
- matchIndex,
286
- 1,
287
- menuItem[ 0 ]
242
+ const { defaultTaxonomiesMenuItems, taxonomiesMenuItems } =
243
+ useTaxonomiesMenuItems( onClickMenuItem );
244
+ const { defaultPostTypesMenuItems, postTypesMenuItems } =
245
+ usePostTypeMenuItems( onClickMenuItem );
246
+ [ ...defaultTaxonomiesMenuItems, ...defaultPostTypesMenuItems ].forEach(
247
+ ( menuItem ) => {
248
+ if ( ! menuItem ) {
249
+ return;
250
+ }
251
+ const matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(
252
+ ( template ) => template.slug === menuItem.slug
288
253
  );
289
- } else {
290
- enhancedMissingDefaultTemplateTypes.push( menuItem[ 0 ] );
254
+ // Some default template types might have been filtered above from
255
+ // `missingDefaultTemplates` because they only check for the general
256
+ // template. So here we either replace or append the item, augmented
257
+ // with the check if it has available specific item to create a
258
+ // template for.
259
+ if ( matchIndex > -1 ) {
260
+ enhancedMissingDefaultTemplateTypes[ matchIndex ] = menuItem;
261
+ } else {
262
+ enhancedMissingDefaultTemplateTypes.push( menuItem );
263
+ }
291
264
  }
292
- } );
265
+ );
293
266
  // Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.
294
267
  enhancedMissingDefaultTemplateTypes?.sort( ( template1, template2 ) => {
295
268
  return (
@@ -297,20 +270,10 @@ function useMissingTemplates(
297
270
  DEFAULT_TEMPLATE_SLUGS.indexOf( template2.slug )
298
271
  );
299
272
  } );
300
- const extraPostTypeTemplates = useExtraTemplates(
301
- postTypes,
302
- entitiesConfig.postType,
303
- onClickMenuItem
304
- );
305
- const extraTaxonomyTemplates = useExtraTemplates(
306
- taxonomies,
307
- entitiesConfig.taxonomy,
308
- onClickMenuItem
309
- );
310
273
  const missingTemplates = [
311
274
  ...enhancedMissingDefaultTemplateTypes,
312
- ...extraPostTypeTemplates,
313
- ...extraTaxonomyTemplates,
275
+ ...postTypesMenuItems,
276
+ ...taxonomiesMenuItems,
314
277
  ];
315
278
  return missingTemplates;
316
279
  }
@@ -12,33 +12,45 @@
12
12
 
13
13
  .edit-site-custom-template-modal {
14
14
  &__contents {
15
- > div {
16
- text-align: center;
17
- cursor: pointer;
15
+ > .components-button {
18
16
  padding: $grid-unit-30;
19
- border: 1px solid $gray-300;
17
+ box-shadow: inset 0 0 0 $border-width $gray-600;
20
18
  border-radius: $radius-block-ui;
21
19
  width: 256px;
20
+ height: auto;
22
21
  display: flex;
23
22
  flex-direction: column;
24
23
  gap: $grid-unit;
25
- align-items: center;
26
- justify-content: center;
24
+
25
+ // Show the boundary of the button, in High Contrast Mode.
26
+ outline: 1px solid transparent;
27
+
28
+ span:first-child {
29
+ color: $gray-900;
30
+ }
27
31
 
28
32
  span {
29
33
  color: $gray-700;
30
34
  }
31
35
 
32
36
  &:hover {
33
- border-color: var(--wp-admin-theme-color);
37
+ color: var(--wp-admin-theme-color-darker-10);
38
+ box-shadow: inset 0 0 0 $border-width var(--wp-admin-theme-color-darker-10);
34
39
 
35
- h5 {
40
+ span:first-child {
36
41
  color: var(--wp-admin-theme-color);
37
42
  }
38
43
  }
39
44
 
40
45
  &:focus {
41
46
  box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
47
+
48
+ // Windows High Contrast mode will show this outline, but not the box-shadow.
49
+ outline: 3px solid transparent;
50
+
51
+ span:first-child {
52
+ color: var(--wp-admin-theme-color);
53
+ }
42
54
  }
43
55
  }
44
56
  }