@wordpress/edit-site 3.0.19 → 3.0.20

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 (110) hide show
  1. package/build/components/block-editor/index.js +1 -1
  2. package/build/components/block-editor/index.js.map +1 -1
  3. package/build/components/block-editor/resizable-editor.js +37 -7
  4. package/build/components/block-editor/resizable-editor.js.map +1 -1
  5. package/build/components/navigation-sidebar/navigation-panel/constants.js +1 -11
  6. package/build/components/navigation-sidebar/navigation-panel/constants.js.map +1 -1
  7. package/build/plugins/site-export.js +1 -1
  8. package/build/plugins/site-export.js.map +1 -1
  9. package/build-module/components/block-editor/index.js +2 -2
  10. package/build-module/components/block-editor/index.js.map +1 -1
  11. package/build-module/components/block-editor/resizable-editor.js +37 -7
  12. package/build-module/components/block-editor/resizable-editor.js.map +1 -1
  13. package/build-module/components/navigation-sidebar/navigation-panel/constants.js +0 -5
  14. package/build-module/components/navigation-sidebar/navigation-panel/constants.js.map +1 -1
  15. package/build-module/plugins/site-export.js +2 -2
  16. package/build-module/plugins/site-export.js.map +1 -1
  17. package/build-style/style-rtl.css +7 -3
  18. package/build-style/style.css +7 -3
  19. package/package.json +8 -8
  20. package/src/components/block-editor/index.js +2 -2
  21. package/src/components/block-editor/resizable-editor.js +52 -12
  22. package/src/components/global-styles/style.scss +2 -1
  23. package/src/components/navigation-sidebar/navigation-panel/constants.js +0 -15
  24. package/src/components/navigation-sidebar/navigation-toggle/style.scss +8 -4
  25. package/src/plugins/site-export.js +2 -2
  26. package/build/components/navigation-sidebar/navigation-panel/content-navigation-item.js +0 -101
  27. package/build/components/navigation-sidebar/navigation-panel/content-navigation-item.js.map +0 -1
  28. package/build/components/navigation-sidebar/navigation-panel/menus/content-categories.js +0 -82
  29. package/build/components/navigation-sidebar/navigation-panel/menus/content-categories.js.map +0 -1
  30. package/build/components/navigation-sidebar/navigation-panel/menus/content-pages.js +0 -82
  31. package/build/components/navigation-sidebar/navigation-panel/menus/content-pages.js.map +0 -1
  32. package/build/components/navigation-sidebar/navigation-panel/menus/content-posts.js +0 -107
  33. package/build/components/navigation-sidebar/navigation-panel/menus/content-posts.js.map +0 -1
  34. package/build/components/navigation-sidebar/navigation-panel/menus/index.js +0 -57
  35. package/build/components/navigation-sidebar/navigation-panel/menus/index.js.map +0 -1
  36. package/build/components/navigation-sidebar/navigation-panel/menus/template-parts-sub.js +0 -48
  37. package/build/components/navigation-sidebar/navigation-panel/menus/template-parts-sub.js.map +0 -1
  38. package/build/components/navigation-sidebar/navigation-panel/menus/template-parts.js +0 -100
  39. package/build/components/navigation-sidebar/navigation-panel/menus/template-parts.js.map +0 -1
  40. package/build/components/navigation-sidebar/navigation-panel/menus/templates-sub.js +0 -62
  41. package/build/components/navigation-sidebar/navigation-panel/menus/templates-sub.js.map +0 -1
  42. package/build/components/navigation-sidebar/navigation-panel/menus/templates.js +0 -143
  43. package/build/components/navigation-sidebar/navigation-panel/menus/templates.js.map +0 -1
  44. package/build/components/navigation-sidebar/navigation-panel/navigation-entity-items.js +0 -76
  45. package/build/components/navigation-sidebar/navigation-panel/navigation-entity-items.js.map +0 -1
  46. package/build/components/navigation-sidebar/navigation-panel/new-template-dropdown.js +0 -125
  47. package/build/components/navigation-sidebar/navigation-panel/new-template-dropdown.js.map +0 -1
  48. package/build/components/navigation-sidebar/navigation-panel/search-results.js +0 -132
  49. package/build/components/navigation-sidebar/navigation-panel/search-results.js.map +0 -1
  50. package/build/components/navigation-sidebar/navigation-panel/template-navigation-item.js +0 -86
  51. package/build/components/navigation-sidebar/navigation-panel/template-navigation-item.js.map +0 -1
  52. package/build/components/navigation-sidebar/navigation-panel/template-preview.js +0 -46
  53. package/build/components/navigation-sidebar/navigation-panel/template-preview.js.map +0 -1
  54. package/build/components/navigation-sidebar/navigation-panel/use-debounced-search.js +0 -47
  55. package/build/components/navigation-sidebar/navigation-panel/use-debounced-search.js.map +0 -1
  56. package/build/components/navigation-sidebar/navigation-panel/utils.js +0 -21
  57. package/build/components/navigation-sidebar/navigation-panel/utils.js.map +0 -1
  58. package/build/utils/get-closest-available-template.js +0 -48
  59. package/build/utils/get-closest-available-template.js.map +0 -1
  60. package/build-module/components/navigation-sidebar/navigation-panel/content-navigation-item.js +0 -86
  61. package/build-module/components/navigation-sidebar/navigation-panel/content-navigation-item.js.map +0 -1
  62. package/build-module/components/navigation-sidebar/navigation-panel/menus/content-categories.js +0 -65
  63. package/build-module/components/navigation-sidebar/navigation-panel/menus/content-categories.js.map +0 -1
  64. package/build-module/components/navigation-sidebar/navigation-panel/menus/content-pages.js +0 -65
  65. package/build-module/components/navigation-sidebar/navigation-panel/menus/content-pages.js.map +0 -1
  66. package/build-module/components/navigation-sidebar/navigation-panel/menus/content-posts.js +0 -90
  67. package/build-module/components/navigation-sidebar/navigation-panel/menus/content-posts.js.map +0 -1
  68. package/build-module/components/navigation-sidebar/navigation-panel/menus/index.js +0 -40
  69. package/build-module/components/navigation-sidebar/navigation-panel/menus/index.js.map +0 -1
  70. package/build-module/components/navigation-sidebar/navigation-panel/menus/template-parts-sub.js +0 -35
  71. package/build-module/components/navigation-sidebar/navigation-panel/menus/template-parts-sub.js.map +0 -1
  72. package/build-module/components/navigation-sidebar/navigation-panel/menus/template-parts.js +0 -84
  73. package/build-module/components/navigation-sidebar/navigation-panel/menus/template-parts.js.map +0 -1
  74. package/build-module/components/navigation-sidebar/navigation-panel/menus/templates-sub.js +0 -50
  75. package/build-module/components/navigation-sidebar/navigation-panel/menus/templates-sub.js.map +0 -1
  76. package/build-module/components/navigation-sidebar/navigation-panel/menus/templates.js +0 -124
  77. package/build-module/components/navigation-sidebar/navigation-panel/menus/templates.js.map +0 -1
  78. package/build-module/components/navigation-sidebar/navigation-panel/navigation-entity-items.js +0 -65
  79. package/build-module/components/navigation-sidebar/navigation-panel/navigation-entity-items.js.map +0 -1
  80. package/build-module/components/navigation-sidebar/navigation-panel/new-template-dropdown.js +0 -106
  81. package/build-module/components/navigation-sidebar/navigation-panel/new-template-dropdown.js.map +0 -1
  82. package/build-module/components/navigation-sidebar/navigation-panel/search-results.js +0 -116
  83. package/build-module/components/navigation-sidebar/navigation-panel/search-results.js.map +0 -1
  84. package/build-module/components/navigation-sidebar/navigation-panel/template-navigation-item.js +0 -71
  85. package/build-module/components/navigation-sidebar/navigation-panel/template-navigation-item.js.map +0 -1
  86. package/build-module/components/navigation-sidebar/navigation-panel/template-preview.js +0 -38
  87. package/build-module/components/navigation-sidebar/navigation-panel/template-preview.js.map +0 -1
  88. package/build-module/components/navigation-sidebar/navigation-panel/use-debounced-search.js +0 -37
  89. package/build-module/components/navigation-sidebar/navigation-panel/use-debounced-search.js.map +0 -1
  90. package/build-module/components/navigation-sidebar/navigation-panel/utils.js +0 -8
  91. package/build-module/components/navigation-sidebar/navigation-panel/utils.js.map +0 -1
  92. package/build-module/utils/get-closest-available-template.js +0 -40
  93. package/build-module/utils/get-closest-available-template.js.map +0 -1
  94. package/src/components/navigation-sidebar/navigation-panel/content-navigation-item.js +0 -89
  95. package/src/components/navigation-sidebar/navigation-panel/menus/content-categories.js +0 -85
  96. package/src/components/navigation-sidebar/navigation-panel/menus/content-pages.js +0 -85
  97. package/src/components/navigation-sidebar/navigation-panel/menus/content-posts.js +0 -117
  98. package/src/components/navigation-sidebar/navigation-panel/menus/index.js +0 -61
  99. package/src/components/navigation-sidebar/navigation-panel/menus/template-parts-sub.js +0 -34
  100. package/src/components/navigation-sidebar/navigation-panel/menus/template-parts.js +0 -94
  101. package/src/components/navigation-sidebar/navigation-panel/menus/templates-sub.js +0 -42
  102. package/src/components/navigation-sidebar/navigation-panel/menus/templates.js +0 -147
  103. package/src/components/navigation-sidebar/navigation-panel/navigation-entity-items.js +0 -53
  104. package/src/components/navigation-sidebar/navigation-panel/new-template-dropdown.js +0 -110
  105. package/src/components/navigation-sidebar/navigation-panel/search-results.js +0 -117
  106. package/src/components/navigation-sidebar/navigation-panel/template-navigation-item.js +0 -83
  107. package/src/components/navigation-sidebar/navigation-panel/template-preview.js +0 -32
  108. package/src/components/navigation-sidebar/navigation-panel/use-debounced-search.js +0 -47
  109. package/src/components/navigation-sidebar/navigation-panel/utils.js +0 -11
  110. package/src/utils/get-closest-available-template.js +0 -31
@@ -1,147 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { map, find } from 'lodash';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import {
10
- __experimentalNavigationItem as NavigationItem,
11
- __experimentalNavigationMenu as NavigationMenu,
12
- } from '@wordpress/components';
13
- import { useSelect } from '@wordpress/data';
14
- import { __ } from '@wordpress/i18n';
15
- import { useState, useCallback, useMemo } from '@wordpress/element';
16
- import { store as coreStore } from '@wordpress/core-data';
17
-
18
- /**
19
- * Internal dependencies
20
- */
21
- import {
22
- MENU_ROOT,
23
- MENU_TEMPLATES,
24
- MENU_TEMPLATES_GENERAL,
25
- MENU_TEMPLATES_PAGES,
26
- MENU_TEMPLATES_POSTS,
27
- MENU_TEMPLATES_UNUSED,
28
- } from '../constants';
29
- import NewTemplateDropdown from '../new-template-dropdown';
30
- import TemplateNavigationItem from '../template-navigation-item';
31
- import SearchResults from '../search-results';
32
- import TemplatesSubMenu from './templates-sub';
33
- import {
34
- getTemplatesLocationMap,
35
- getUnusedTemplates,
36
- } from '../template-hierarchy';
37
-
38
- export default function TemplatesMenu() {
39
- const [ search, setSearch ] = useState( '' );
40
- const onSearch = useCallback( ( value ) => {
41
- setSearch( value );
42
- } );
43
-
44
- const { templates, showOnFront } = useSelect( ( select ) => {
45
- const { getEntityRecords, getEditedEntityRecord } = select( coreStore );
46
- return {
47
- templates: getEntityRecords( 'postType', 'wp_template' ),
48
- showOnFront: getEditedEntityRecord( 'root', 'site' ).show_on_front,
49
- };
50
- }, [] );
51
-
52
- const templatesWithLocation = useMemo( () => {
53
- if ( ! templates ) {
54
- return null;
55
- }
56
-
57
- const unusedTemplates = getUnusedTemplates( templates, showOnFront );
58
- const templateLocations = getTemplatesLocationMap( templates );
59
-
60
- return templates.map( ( template ) => ( {
61
- template,
62
- location: find( unusedTemplates, { slug: template.slug } )
63
- ? MENU_TEMPLATES_UNUSED
64
- : templateLocations[ template.slug ],
65
- } ) );
66
- }, [ templates ] );
67
-
68
- const topLevelTemplates = useMemo(
69
- () =>
70
- templatesWithLocation
71
- ?.filter( ( { location } ) => location === MENU_TEMPLATES )
72
- ?.map( ( { template } ) => template ) ?? [],
73
- [ templatesWithLocation ]
74
- );
75
-
76
- return (
77
- <NavigationMenu
78
- menu={ MENU_TEMPLATES }
79
- title={ __( 'Templates' ) }
80
- titleAction={ <NewTemplateDropdown /> }
81
- parentMenu={ MENU_ROOT }
82
- hasSearch={ true }
83
- onSearch={ onSearch }
84
- search={ search }
85
- >
86
- { search && (
87
- <SearchResults items={ templates } search={ search } />
88
- ) }
89
-
90
- { ! search && (
91
- <>
92
- { map( topLevelTemplates, ( template ) => (
93
- <TemplateNavigationItem
94
- item={ template }
95
- key={ `wp_template-${ template.id }` }
96
- />
97
- ) ) }
98
- <NavigationItem
99
- navigateToMenu={ MENU_TEMPLATES_POSTS }
100
- title={ __( 'Post templates' ) }
101
- hideIfTargetMenuEmpty
102
- />
103
- <NavigationItem
104
- navigateToMenu={ MENU_TEMPLATES_PAGES }
105
- title={ __( 'Page templates' ) }
106
- hideIfTargetMenuEmpty
107
- />
108
- <NavigationItem
109
- navigateToMenu={ MENU_TEMPLATES_GENERAL }
110
- title={ __( 'General templates' ) }
111
- hideIfTargetMenuEmpty
112
- />
113
- <NavigationItem
114
- navigateToMenu={ MENU_TEMPLATES_UNUSED }
115
- title={ __( 'Unused templates' ) }
116
- hideIfTargetMenuEmpty
117
- />
118
- </>
119
- ) }
120
-
121
- { ! search && templates === null && (
122
- <NavigationItem title={ __( 'Loading…' ) } isText />
123
- ) }
124
-
125
- <TemplatesSubMenu
126
- menu={ MENU_TEMPLATES_POSTS }
127
- title={ __( 'Post templates' ) }
128
- templates={ templatesWithLocation }
129
- />
130
- <TemplatesSubMenu
131
- menu={ MENU_TEMPLATES_PAGES }
132
- title={ __( 'Page templates' ) }
133
- templates={ templatesWithLocation }
134
- />
135
- <TemplatesSubMenu
136
- menu={ MENU_TEMPLATES_GENERAL }
137
- title={ __( 'General templates' ) }
138
- templates={ templatesWithLocation }
139
- />
140
- <TemplatesSubMenu
141
- menu={ MENU_TEMPLATES_UNUSED }
142
- title={ __( 'Unused templates' ) }
143
- templates={ templatesWithLocation }
144
- />
145
- </NavigationMenu>
146
- );
147
- }
@@ -1,53 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useDispatch, useSelect } from '@wordpress/data';
5
- import { __experimentalNavigationItem as NavigationItem } from '@wordpress/components';
6
- import { getPathAndQueryString } from '@wordpress/url';
7
- import { store as coreStore } from '@wordpress/core-data';
8
-
9
- /**
10
- * Internal dependencies
11
- */
12
- import { store as editSiteStore } from '../../../store';
13
-
14
- const getEntityTitle = ( kind, entity ) =>
15
- 'taxonomy' === kind ? entity.name : entity?.title?.rendered;
16
-
17
- export default function NavigationEntityItems( { kind, name, query = {} } ) {
18
- const entities = useSelect(
19
- ( select ) => select( coreStore ).getEntityRecords( kind, name, query ),
20
- [ kind, name, query ]
21
- );
22
-
23
- const { setPage } = useDispatch( editSiteStore );
24
-
25
- if ( ! entities ) {
26
- return null;
27
- }
28
-
29
- const onActivateItem = ( { type, slug, link, id } ) => {
30
- setPage( {
31
- type,
32
- slug,
33
- path: getPathAndQueryString( link ),
34
- context: {
35
- postType: type,
36
- postId: id,
37
- },
38
- } );
39
- };
40
-
41
- return entities.map( ( entity ) => {
42
- const key = `content-${ getPathAndQueryString( entity.link ) }`;
43
-
44
- return (
45
- <NavigationItem
46
- key={ key }
47
- item={ key }
48
- title={ getEntityTitle( kind, entity ) }
49
- onClick={ () => onActivateItem( entity ) }
50
- />
51
- );
52
- } );
53
- }
@@ -1,110 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { filter, find, includes, map } from 'lodash';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import {
10
- DropdownMenu,
11
- MenuGroup,
12
- MenuItem,
13
- NavigableMenu,
14
- } from '@wordpress/components';
15
- import { useDispatch, useSelect } from '@wordpress/data';
16
- import { __ } from '@wordpress/i18n';
17
- import { Icon, plus } from '@wordpress/icons';
18
- import { store as editorStore } from '@wordpress/editor';
19
- import { store as coreStore } from '@wordpress/core-data';
20
-
21
- /**
22
- * Internal dependencies
23
- */
24
- import getClosestAvailableTemplate from '../../../utils/get-closest-available-template';
25
- import { TEMPLATES_NEW_OPTIONS } from './constants';
26
- import { store as editSiteStore } from '../../../store';
27
-
28
- export default function NewTemplateDropdown() {
29
- const { defaultTemplateTypes, templates } = useSelect( ( select ) => {
30
- const {
31
- __experimentalGetDefaultTemplateTypes: getDefaultTemplateTypes,
32
- } = select( editorStore );
33
- const templateEntities = select( coreStore ).getEntityRecords(
34
- 'postType',
35
- 'wp_template'
36
- );
37
- return {
38
- defaultTemplateTypes: getDefaultTemplateTypes(),
39
- templates: templateEntities,
40
- };
41
- }, [] );
42
- const { addTemplate } = useDispatch( editSiteStore );
43
-
44
- const createTemplate = ( slug ) => {
45
- const closestAvailableTemplate = getClosestAvailableTemplate(
46
- slug,
47
- templates
48
- );
49
- const { title, description } = find( defaultTemplateTypes, { slug } );
50
- addTemplate( {
51
- content: closestAvailableTemplate.content.raw,
52
- excerpt: description,
53
- // Slugs need to be strings, so this is for template `404`
54
- slug: slug.toString(),
55
- status: 'publish',
56
- title,
57
- } );
58
- };
59
-
60
- const existingTemplateSlugs = map( templates, 'slug' );
61
-
62
- const missingTemplates = filter(
63
- defaultTemplateTypes,
64
- ( template ) =>
65
- includes( TEMPLATES_NEW_OPTIONS, template.slug ) &&
66
- ! includes( existingTemplateSlugs, template.slug )
67
- );
68
-
69
- if ( ! missingTemplates.length ) {
70
- return null;
71
- }
72
-
73
- return (
74
- <DropdownMenu
75
- className="edit-site-navigation-panel__new-template-dropdown"
76
- icon={ null }
77
- label={ __( 'Add Template' ) }
78
- popoverProps={ {
79
- noArrow: false,
80
- } }
81
- toggleProps={ {
82
- children: <Icon icon={ plus } />,
83
- isSmall: true,
84
- variant: 'tertiary',
85
- } }
86
- >
87
- { ( { onClose } ) => (
88
- <NavigableMenu className="edit-site-navigation-panel__new-template-popover">
89
- <MenuGroup label={ __( 'Add Template' ) }>
90
- { map(
91
- missingTemplates,
92
- ( { title, description, slug } ) => (
93
- <MenuItem
94
- info={ description }
95
- key={ slug }
96
- onClick={ () => {
97
- createTemplate( slug );
98
- onClose();
99
- } }
100
- >
101
- { title }
102
- </MenuItem>
103
- )
104
- ) }
105
- </MenuGroup>
106
- </NavigableMenu>
107
- ) }
108
- </DropdownMenu>
109
- );
110
- }
@@ -1,117 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { map, sortBy, keyBy } from 'lodash';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { useMemo } from '@wordpress/element';
10
- import { __experimentalNavigationGroup as NavigationGroup } from '@wordpress/components';
11
- import { __ } from '@wordpress/i18n';
12
-
13
- /**
14
- * Internal dependencies
15
- */
16
- import { normalizedSearch } from './utils';
17
- import { useSelect } from '@wordpress/data';
18
- import { store as editorStore } from '@wordpress/editor';
19
- import TemplateNavigationItem from './template-navigation-item';
20
- import ContentNavigationItem from './content-navigation-item';
21
-
22
- export default function SearchResults( { items, search, disableFilter } ) {
23
- let itemType = null;
24
- if ( items?.length > 0 ) {
25
- if ( items[ 0 ].taxonomy ) {
26
- itemType = 'taxonomy';
27
- } else {
28
- itemType = items[ 0 ].type;
29
- }
30
- }
31
-
32
- const itemInfos = useSelect(
33
- ( select ) => {
34
- if ( itemType === null || items === null ) {
35
- return [];
36
- }
37
-
38
- if ( itemType === 'wp_template' ) {
39
- const {
40
- __experimentalGetTemplateInfo: getTemplateInfo,
41
- } = select( editorStore );
42
-
43
- return items.map( ( item ) => ( {
44
- slug: item.slug,
45
- ...getTemplateInfo( item ),
46
- } ) );
47
- }
48
-
49
- if ( itemType === 'taxonomy' ) {
50
- return items.map( ( item ) => ( {
51
- slug: item.slug,
52
- title: item.name,
53
- description: item.description,
54
- } ) );
55
- }
56
-
57
- return items.map( ( item ) => ( {
58
- slug: item.slug,
59
- title: item.title?.rendered,
60
- description: item.excerpt?.rendered,
61
- } ) );
62
- },
63
- [ items, itemType ]
64
- );
65
- const itemInfosMap = useMemo( () => keyBy( itemInfos, 'slug' ), [
66
- itemInfos,
67
- ] );
68
-
69
- const itemsFiltered = useMemo( () => {
70
- if ( items === null || search.length === 0 ) {
71
- return [];
72
- }
73
-
74
- if ( disableFilter ) {
75
- return items;
76
- }
77
-
78
- return items.filter( ( { slug } ) => {
79
- const { title, description } = itemInfosMap[ slug ];
80
-
81
- return (
82
- normalizedSearch( slug, search ) ||
83
- normalizedSearch( title, search ) ||
84
- normalizedSearch( description, search )
85
- );
86
- } );
87
- }, [ items, itemInfos, search ] );
88
-
89
- const itemsSorted = useMemo( () => {
90
- if ( ! itemsFiltered ) {
91
- return [];
92
- }
93
-
94
- return sortBy( itemsFiltered, [
95
- ( { slug } ) => {
96
- const { title } = itemInfosMap[ slug ];
97
- return ! normalizedSearch( title, search );
98
- },
99
- ] );
100
- }, [ itemsFiltered, search ] );
101
-
102
- const ItemComponent =
103
- itemType === 'wp_template' || itemType === 'wp_template_part'
104
- ? TemplateNavigationItem
105
- : ContentNavigationItem;
106
-
107
- return (
108
- <NavigationGroup title={ __( 'Search results' ) }>
109
- { map( itemsSorted, ( item ) => (
110
- <ItemComponent
111
- item={ item }
112
- key={ `${ item.taxonomy || item.type }-${ item.id }` }
113
- />
114
- ) ) }
115
- </NavigationGroup>
116
- );
117
- }
@@ -1,83 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import {
5
- Button,
6
- __experimentalNavigationItem as NavigationItem,
7
- } from '@wordpress/components';
8
- import { useDispatch, useSelect } from '@wordpress/data';
9
- import { useState } from '@wordpress/element';
10
- import { __ } from '@wordpress/i18n';
11
- import { store as editorStore } from '@wordpress/editor';
12
-
13
- /**
14
- * Internal dependencies
15
- */
16
- import TemplatePreview from './template-preview';
17
- import { NavigationPanelPreviewFill } from '../index';
18
- import { store as editSiteStore } from '../../../store';
19
-
20
- export default function TemplateNavigationItem( { item } ) {
21
- const { title, description } = useSelect(
22
- ( select ) =>
23
- 'wp_template' === item.type
24
- ? select( editorStore ).__experimentalGetTemplateInfo( item )
25
- : {
26
- title: item?.title?.rendered || item?.slug,
27
- description: '',
28
- },
29
- []
30
- );
31
- const {
32
- setTemplate,
33
- setTemplatePart,
34
- setIsNavigationPanelOpened,
35
- } = useDispatch( editSiteStore );
36
- const [ isPreviewVisible, setIsPreviewVisible ] = useState( false );
37
-
38
- if ( ! item ) {
39
- return null;
40
- }
41
-
42
- const onActivateItem = () => {
43
- if ( 'wp_template' === item.type ) {
44
- setTemplate( item.id, item.slug );
45
- } else {
46
- setTemplatePart( item.id );
47
- }
48
- setIsNavigationPanelOpened( false );
49
- };
50
-
51
- return (
52
- <NavigationItem
53
- className="edit-site-navigation-panel__template-item"
54
- item={ `${ item.type }-${ item.id }` }
55
- >
56
- <Button
57
- onClick={ onActivateItem }
58
- onMouseEnter={ () => setIsPreviewVisible( true ) }
59
- onMouseLeave={ () => setIsPreviewVisible( false ) }
60
- >
61
- <span className="edit-site-navigation-panel__info-wrapper">
62
- <div className="edit-site-navigation-panel__template-item-title">
63
- { 'draft' === item.status && (
64
- <em>{ __( '[Draft]' ) }</em>
65
- ) }
66
- { title }
67
- </div>
68
- { description && (
69
- <div className="edit-site-navigation-panel__template-item-description">
70
- { description }
71
- </div>
72
- ) }
73
- </span>
74
- </Button>
75
-
76
- { isPreviewVisible && (
77
- <NavigationPanelPreviewFill>
78
- <TemplatePreview rawContent={ item.content.raw } />
79
- </NavigationPanelPreviewFill>
80
- ) }
81
- </NavigationItem>
82
- );
83
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { parse } from '@wordpress/blocks';
5
- import { BlockPreview, BlockContextProvider } from '@wordpress/block-editor';
6
- import { useMemo } from '@wordpress/element';
7
-
8
- export default function TemplatePreview( { rawContent, blockContext } ) {
9
- const blocks = useMemo( () => ( rawContent ? parse( rawContent ) : [] ), [
10
- rawContent,
11
- ] );
12
-
13
- if ( ! blocks || blocks.length === 0 ) {
14
- return null;
15
- }
16
-
17
- if ( blockContext ) {
18
- return (
19
- <div className="edit-site-navigation-panel__preview">
20
- <BlockContextProvider value={ blockContext }>
21
- <BlockPreview blocks={ blocks } viewportWidth={ 1200 } />
22
- </BlockContextProvider>
23
- </div>
24
- );
25
- }
26
-
27
- return (
28
- <div className="edit-site-navigation-panel__preview">
29
- <BlockPreview blocks={ blocks } viewportWidth={ 1200 } />
30
- </div>
31
- );
32
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { debounce } from 'lodash';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { useState, useCallback, useEffect } from '@wordpress/element';
10
-
11
- /**
12
- * Internal dependencies
13
- */
14
- import { SEARCH_DEBOUNCE_IN_MS } from './constants';
15
-
16
- export default function useDebouncedSearch() {
17
- // The value used by the NavigationMenu to control the input field.
18
- const [ search, setSearch ] = useState( '' );
19
- // The value used to actually perform the search query.
20
- const [ searchQuery, setSearchQuery ] = useState( '' );
21
- const [ isDebouncing, setIsDebouncing ] = useState( false );
22
-
23
- useEffect( () => {
24
- setIsDebouncing( false );
25
- }, [ searchQuery ] );
26
-
27
- const debouncedSetSearchQuery = useCallback(
28
- debounce( setSearchQuery, SEARCH_DEBOUNCE_IN_MS ),
29
- [ setSearchQuery ]
30
- );
31
-
32
- const onSearch = useCallback(
33
- ( value ) => {
34
- setSearch( value );
35
- debouncedSetSearchQuery( value );
36
- setIsDebouncing( true );
37
- },
38
- [ setSearch, setIsDebouncing, debouncedSetSearchQuery ]
39
- );
40
-
41
- return {
42
- search,
43
- searchQuery,
44
- isDebouncing,
45
- onSearch,
46
- };
47
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { deburr } from 'lodash';
5
-
6
- // @see packages/block-editor/src/components/inserter/search-items.js
7
- export const normalizeInput = ( input ) =>
8
- deburr( input ).replace( /^\//, '' ).toLowerCase();
9
-
10
- export const normalizedSearch = ( title, search ) =>
11
- -1 !== normalizeInput( title ).indexOf( normalizeInput( search ) );
@@ -1,31 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { find } from 'lodash';
5
-
6
- export default function getClosestAvailableTemplate( slug, templates ) {
7
- const template = find( templates, { slug } );
8
- if ( template ) {
9
- return template;
10
- }
11
-
12
- switch ( slug ) {
13
- case 'single':
14
- case 'page':
15
- return getClosestAvailableTemplate( 'singular', templates );
16
- case 'author':
17
- case 'category':
18
- case 'taxonomy':
19
- case 'date':
20
- case 'tag':
21
- return getClosestAvailableTemplate( 'archive', templates );
22
- case 'front-page':
23
- return getClosestAvailableTemplate( 'home', templates );
24
- case 'attachment':
25
- return getClosestAvailableTemplate( 'single', templates );
26
- case 'privacy-policy':
27
- return getClosestAvailableTemplate( 'page', templates );
28
- }
29
-
30
- return find( templates, { slug: 'index' } );
31
- }