@wordpress/edit-site 4.14.5 → 4.14.7

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.
@@ -253,29 +253,10 @@ export const usePostTypeMenuItems = ( onClickMenuItem ) => {
253
253
  };
254
254
  },
255
255
  getSpecificTemplate: ( suggestion ) => {
256
- let title = sprintf(
257
- // 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 and %2$s is the name of the post, e.g. "Page: Hello".
258
- __( '%1$s: %2$s' ),
259
- labels.singular_name,
260
- suggestion.name
261
- );
262
- const description = sprintf(
263
- // translators: Represents the description of a user's custom template in the Site Editor, e.g. "Template for Page: Hello"
264
- __( 'Template for %1$s' ),
265
- title
266
- );
267
- if ( _needsUniqueIdentifier ) {
268
- title = sprintf(
269
- // translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the template title and %2$s is the slug of the post type, e.g. "Project: Hello (project_type)"
270
- __( '%1$s (%2$s)' ),
271
- title,
272
- slug
273
- );
274
- }
256
+ const templateSlug = `${ templatePrefixes[ slug ] }-${ suggestion.slug }`;
275
257
  return {
276
- title,
277
- description,
278
- slug: `${ templatePrefixes[ slug ] }-${ suggestion.slug }`,
258
+ title: templateSlug,
259
+ slug: templateSlug,
279
260
  templatePrefix: templatePrefixes[ slug ],
280
261
  };
281
262
  },
@@ -417,29 +398,10 @@ export const useTaxonomiesMenuItems = ( onClickMenuItem ) => {
417
398
  };
418
399
  },
419
400
  getSpecificTemplate: ( suggestion ) => {
420
- let title = sprintf(
421
- // translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a taxonomy and %2$s is the name of the term, e.g. "Category: shoes".
422
- __( '%1$s: %2$s' ),
423
- labels.singular_name,
424
- suggestion.name
425
- );
426
- const description = sprintf(
427
- // translators: Represents the description of a user's custom template in the Site Editor, e.g. "Template for Category: shoes"
428
- __( 'Template for %1$s' ),
429
- title
430
- );
431
- if ( _needsUniqueIdentifier ) {
432
- title = sprintf(
433
- // translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the template title and %2$s is the slug of the taxonomy, e.g. "Category: shoes (product_tag)"
434
- __( '%1$s (%2$s)' ),
435
- title,
436
- slug
437
- );
438
- }
401
+ const templateSlug = `${ templatePrefixes[ slug ] }-${ suggestion.slug }`;
439
402
  return {
440
- title,
441
- description,
442
- slug: `${ templatePrefixes[ slug ] }-${ suggestion.slug }`,
403
+ title: templateSlug,
404
+ slug: templateSlug,
443
405
  templatePrefix: templatePrefixes[ slug ],
444
406
  };
445
407
  },
@@ -480,26 +442,6 @@ export const useTaxonomiesMenuItems = ( onClickMenuItem ) => {
480
442
  return taxonomiesMenuItems;
481
443
  };
482
444
 
483
- function useAuthorNeedsUniqueIndentifier() {
484
- const authors = useSelect(
485
- ( select ) =>
486
- select( coreStore ).getUsers( { who: 'authors', per_page: -1 } ),
487
- []
488
- );
489
- const authorsCountByName = useMemo( () => {
490
- return ( authors || [] ).reduce( ( authorsCount, { name } ) => {
491
- authorsCount[ name ] = ( authorsCount[ name ] || 0 ) + 1;
492
- return authorsCount;
493
- }, {} );
494
- }, [ authors ] );
495
- return useCallback(
496
- ( name ) => {
497
- return authorsCountByName[ name ] > 1;
498
- },
499
- [ authorsCountByName ]
500
- );
501
- }
502
-
503
445
  const USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX = { user: 'author' };
504
446
  const USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS = { user: { who: 'authors' } };
505
447
  export function useAuthorMenuItem( onClickMenuItem ) {
@@ -510,7 +452,6 @@ export function useAuthorMenuItem( onClickMenuItem ) {
510
452
  USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX,
511
453
  USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS
512
454
  );
513
- const authorNeedsUniqueId = useAuthorNeedsUniqueIndentifier();
514
455
  let authorMenuItem = defaultTemplateTypes?.find(
515
456
  ( { slug } ) => slug === 'author'
516
457
  );
@@ -542,30 +483,10 @@ export function useAuthorMenuItem( onClickMenuItem ) {
542
483
  };
543
484
  },
544
485
  getSpecificTemplate: ( suggestion ) => {
545
- const needsUniqueId = authorNeedsUniqueId(
546
- suggestion.name
547
- );
548
- const title = needsUniqueId
549
- ? sprintf(
550
- // translators: %1$s: Represents the name of an author e.g: "Jorge", %2$s: Represents the slug of an author e.g: "author-jorge-slug".
551
- __( 'Author: %1$s (%2$s)' ),
552
- suggestion.name,
553
- suggestion.slug
554
- )
555
- : sprintf(
556
- // translators: %s: Represents the name of an author e.g: "Jorge".
557
- __( 'Author: %s' ),
558
- suggestion.name
559
- );
560
- const description = sprintf(
561
- // translators: %s: Represents the name of an author e.g: "Jorge".
562
- __( 'Template for Author: %s' ),
563
- suggestion.name
564
- );
486
+ const templateSlug = `author-${ suggestion.slug }`;
565
487
  return {
566
- title,
567
- description,
568
- slug: `author-${ suggestion.slug }`,
488
+ title: templateSlug,
489
+ slug: templateSlug,
569
490
  templatePrefix: 'author',
570
491
  };
571
492
  },
@@ -57,38 +57,14 @@ function ResizableEditor( { enableResizing, settings, children, ...props } ) {
57
57
 
58
58
  useEffect(
59
59
  function autoResizeIframeHeight() {
60
- const iframe = iframeRef.current;
61
-
62
- if ( ! iframe || ! enableResizing ) {
60
+ if ( ! iframeRef.current || ! enableResizing ) {
63
61
  return;
64
62
  }
65
63
 
66
- let timeoutId = null;
67
-
68
- function resizeHeight() {
69
- if ( ! timeoutId ) {
70
- // Throttle the updates on timeout. This code previously
71
- // used `requestAnimationFrame`, but that seems to not
72
- // always work before an iframe is ready.
73
- timeoutId = iframe.contentWindow.setTimeout( () => {
74
- const { readyState } = iframe.contentDocument;
75
-
76
- // Continue deferring the timeout until the document is ready.
77
- // Only then will it have a height.
78
- if (
79
- readyState !== 'interactive' &&
80
- readyState !== 'complete'
81
- ) {
82
- resizeHeight();
83
- return;
84
- }
85
-
86
- setHeight( iframe.contentDocument.body.scrollHeight );
87
- timeoutId = null;
88
-
89
- // 30 frames per second.
90
- }, 1000 / 30 );
91
- }
64
+ const iframe = iframeRef.current;
65
+
66
+ function setFrameHeight() {
67
+ setHeight( iframe.contentDocument.body.scrollHeight );
92
68
  }
93
69
 
94
70
  let resizeObserver;
@@ -97,28 +73,23 @@ function ResizableEditor( { enableResizing, settings, children, ...props } ) {
97
73
  resizeObserver?.disconnect();
98
74
 
99
75
  resizeObserver = new iframe.contentWindow.ResizeObserver(
100
- resizeHeight
76
+ setFrameHeight
101
77
  );
102
78
 
103
79
  // Observe the body, since the `html` element seems to always
104
80
  // have a height of `100%`.
105
81
  resizeObserver.observe( iframe.contentDocument.body );
106
-
107
- resizeHeight();
82
+ setFrameHeight();
108
83
  }
109
84
 
110
- // This is only required in Firefox for some unknown reasons.
111
85
  iframe.addEventListener( 'load', registerObserver );
112
- // This is required in Chrome and Safari.
113
- registerObserver();
114
86
 
115
87
  return () => {
116
- iframe.contentWindow?.clearTimeout( timeoutId );
117
88
  resizeObserver?.disconnect();
118
89
  iframe.removeEventListener( 'load', registerObserver );
119
90
  };
120
91
  },
121
- [ enableResizing ]
92
+ [ enableResizing, iframeRef.current ]
122
93
  );
123
94
 
124
95
  const resizeWidthBy = useCallback( ( deltaPixels ) => {