@wordpress/edit-site 7.3.2-next.v.202608281122.0 → 7.4.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.
- package/CHANGELOG.md +17 -1
- package/build/components/add-new-template/add-custom-template-modal-content.cjs +3 -1
- package/build/components/add-new-template/add-custom-template-modal-content.cjs.map +2 -2
- package/build/components/add-new-template/index.cjs +6 -4
- package/build/components/add-new-template/index.cjs.map +2 -2
- package/build/components/add-new-template/utils.cjs +84 -9
- package/build/components/add-new-template/utils.cjs.map +2 -2
- package/build/components/dataviews-actions/index.cjs +2 -55
- package/build/components/dataviews-actions/index.cjs.map +3 -3
- package/build/components/layout/index.cjs +2 -2
- package/build/components/layout/index.cjs.map +2 -2
- package/build/components/more-menu/welcome-guide-menu-item.cjs +10 -2
- package/build/components/more-menu/welcome-guide-menu-item.cjs.map +3 -3
- package/build/components/page-templates/fields.cjs +2 -126
- package/build/components/page-templates/fields.cjs.map +3 -3
- package/build/components/page-templates/index.cjs +46 -230
- package/build/components/page-templates/index.cjs.map +3 -3
- package/build/components/post-list/index.cjs +7 -17
- package/build/components/post-list/index.cjs.map +2 -2
- package/build/components/sidebar-global-styles/index.cjs +2 -2
- package/build/components/sidebar-global-styles/index.cjs.map +2 -2
- package/build/components/sidebar-identity/index.cjs +17 -22
- package/build/components/sidebar-identity/index.cjs.map +2 -2
- package/build/components/sidebar-navigation-item/index.cjs +1 -8
- package/build/components/sidebar-navigation-item/index.cjs.map +2 -2
- package/build/components/sidebar-navigation-screen-templates-browse/content.cjs +34 -72
- package/build/components/sidebar-navigation-screen-templates-browse/content.cjs.map +3 -3
- package/build/components/sidebar-navigation-screen-templates-browse/index.cjs +1 -2
- package/build/components/sidebar-navigation-screen-templates-browse/index.cjs.map +3 -3
- package/build/components/site-editor-routes/templates.cjs +2 -4
- package/build/components/site-editor-routes/templates.cjs.map +3 -3
- package/build/index.cjs +0 -1
- package/build/index.cjs.map +2 -2
- package/build-module/components/add-new-template/add-custom-template-modal-content.mjs +3 -1
- package/build-module/components/add-new-template/add-custom-template-modal-content.mjs.map +2 -2
- package/build-module/components/add-new-template/index.mjs +7 -4
- package/build-module/components/add-new-template/index.mjs.map +2 -2
- package/build-module/components/add-new-template/utils.mjs +84 -9
- package/build-module/components/add-new-template/utils.mjs.map +2 -2
- package/build-module/components/dataviews-actions/index.mjs +1 -53
- package/build-module/components/dataviews-actions/index.mjs.map +2 -2
- package/build-module/components/layout/index.mjs +2 -2
- package/build-module/components/layout/index.mjs.map +2 -2
- package/build-module/components/more-menu/welcome-guide-menu-item.mjs +10 -2
- package/build-module/components/more-menu/welcome-guide-menu-item.mjs.map +2 -2
- package/build-module/components/page-templates/fields.mjs +3 -129
- package/build-module/components/page-templates/fields.mjs.map +3 -3
- package/build-module/components/page-templates/index.mjs +52 -253
- package/build-module/components/page-templates/index.mjs.map +2 -2
- package/build-module/components/post-list/index.mjs +8 -18
- package/build-module/components/post-list/index.mjs.map +2 -2
- package/build-module/components/sidebar-global-styles/index.mjs +2 -2
- package/build-module/components/sidebar-global-styles/index.mjs.map +2 -2
- package/build-module/components/sidebar-identity/index.mjs +17 -22
- package/build-module/components/sidebar-identity/index.mjs.map +2 -2
- package/build-module/components/sidebar-navigation-item/index.mjs +1 -8
- package/build-module/components/sidebar-navigation-item/index.mjs.map +2 -2
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.mjs +42 -75
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.mjs.map +2 -2
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.mjs +1 -2
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.mjs.map +2 -2
- package/build-module/components/site-editor-routes/templates.mjs +2 -4
- package/build-module/components/site-editor-routes/templates.mjs.map +2 -2
- package/build-module/index.mjs +0 -1
- package/build-module/index.mjs.map +2 -2
- package/build-style/style-rtl.css +38 -81
- package/build-style/style.css +38 -81
- package/package.json +41 -38
- package/src/components/add-new-template/add-custom-template-modal-content.jsx +3 -1
- package/src/components/add-new-template/index.jsx +9 -4
- package/src/components/add-new-template/style.scss +8 -21
- package/src/components/add-new-template/utils.js +118 -9
- package/src/components/dataviews-actions/index.js +0 -61
- package/src/components/layout/index.jsx +5 -2
- package/src/components/more-menu/welcome-guide-menu-item.jsx +8 -3
- package/src/components/page-templates/fields.jsx +2 -146
- package/src/components/page-templates/index.jsx +30 -256
- package/src/components/post-list/index.jsx +7 -20
- package/src/components/sidebar-global-styles/index.jsx +7 -5
- package/src/components/sidebar-global-styles/style.scss +6 -0
- package/src/components/sidebar-identity/index.jsx +23 -19
- package/src/components/sidebar-identity/style.scss +7 -0
- package/src/components/sidebar-navigation-item/index.jsx +1 -7
- package/src/components/sidebar-navigation-screen-templates-browse/content.jsx +45 -80
- package/src/components/sidebar-navigation-screen-templates-browse/index.jsx +1 -8
- package/src/components/site-editor-routes/templates.jsx +2 -19
- package/src/components/welcome-guide/style.scss +1 -1
- package/src/index.jsx +0 -1
- package/src/style.scss +1 -1
- package/src/utils/test/get-filtered-template-parts.js +1 -0
- package/build/components/add-new-template-legacy/add-custom-generic-template-modal-content.cjs +0 -107
- package/build/components/add-new-template-legacy/add-custom-generic-template-modal-content.cjs.map +0 -7
- package/build/components/add-new-template-legacy/add-custom-template-modal-content.cjs +0 -327
- package/build/components/add-new-template-legacy/add-custom-template-modal-content.cjs.map +0 -7
- package/build/components/add-new-template-legacy/index.cjs +0 -390
- package/build/components/add-new-template-legacy/index.cjs.map +0 -7
- package/build/components/add-new-template-legacy/utils.cjs +0 -623
- package/build/components/add-new-template-legacy/utils.cjs.map +0 -7
- package/build/components/page-templates/hooks.cjs +0 -94
- package/build/components/page-templates/hooks.cjs.map +0 -7
- package/build/components/page-templates/index-legacy.cjs +0 -167
- package/build/components/page-templates/index-legacy.cjs.map +0 -7
- package/build/components/page-templates/view-utils.cjs +0 -79
- package/build/components/page-templates/view-utils.cjs.map +0 -7
- package/build/components/sidebar-navigation-screen-templates-browse/content-legacy.cjs +0 -78
- package/build/components/sidebar-navigation-screen-templates-browse/content-legacy.cjs.map +0 -7
- package/build-module/components/add-new-template-legacy/add-custom-generic-template-modal-content.mjs +0 -91
- package/build-module/components/add-new-template-legacy/add-custom-generic-template-modal-content.mjs.map +0 -7
- package/build-module/components/add-new-template-legacy/add-custom-template-modal-content.mjs +0 -315
- package/build-module/components/add-new-template-legacy/add-custom-template-modal-content.mjs.map +0 -7
- package/build-module/components/add-new-template-legacy/index.mjs +0 -391
- package/build-module/components/add-new-template-legacy/index.mjs.map +0 -7
- package/build-module/components/add-new-template-legacy/utils.mjs +0 -592
- package/build-module/components/add-new-template-legacy/utils.mjs.map +0 -7
- package/build-module/components/page-templates/hooks.mjs +0 -74
- package/build-module/components/page-templates/hooks.mjs.map +0 -7
- package/build-module/components/page-templates/index-legacy.mjs +0 -136
- package/build-module/components/page-templates/index-legacy.mjs.map +0 -7
- package/build-module/components/page-templates/view-utils.mjs +0 -52
- package/build-module/components/page-templates/view-utils.mjs.map +0 -7
- package/build-module/components/sidebar-navigation-screen-templates-browse/content-legacy.mjs +0 -52
- package/build-module/components/sidebar-navigation-screen-templates-browse/content-legacy.mjs.map +0 -7
- package/src/components/add-new-template-legacy/add-custom-generic-template-modal-content.jsx +0 -85
- package/src/components/add-new-template-legacy/add-custom-template-modal-content.jsx +0 -306
- package/src/components/add-new-template-legacy/index.jsx +0 -440
- package/src/components/add-new-template-legacy/utils.js +0 -757
- package/src/components/page-templates/hooks.js +0 -93
- package/src/components/page-templates/index-legacy.jsx +0 -143
- package/src/components/page-templates/view-utils.js +0 -50
- package/src/components/sidebar-navigation-screen-templates-browse/content-legacy.jsx +0 -52
- package/src/components/sidebar-navigation-screen-templates-browse/style.scss +0 -6
|
@@ -197,6 +197,7 @@ export function usePostTypeArchiveMenuItems() {
|
|
|
197
197
|
|
|
198
198
|
export const usePostTypeMenuItems = ( onClickMenuItem ) => {
|
|
199
199
|
const publicPostTypes = usePublicPostTypes();
|
|
200
|
+
const existingTemplates = useExistingTemplates();
|
|
200
201
|
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
201
202
|
// We need to keep track of naming conflicts. If a conflict
|
|
202
203
|
// occurs, we need to add slug.
|
|
@@ -236,6 +237,9 @@ export const usePostTypeMenuItems = ( onClickMenuItem ) => {
|
|
|
236
237
|
[ publicPostTypes ]
|
|
237
238
|
);
|
|
238
239
|
const postTypesInfo = useEntitiesInfo( 'postType', templatePrefixes );
|
|
240
|
+
const existingTemplateSlugs = ( existingTemplates || [] ).map(
|
|
241
|
+
( { slug } ) => slug
|
|
242
|
+
);
|
|
239
243
|
const menuItems = ( publicPostTypes || [] ).reduce(
|
|
240
244
|
( accumulator, postType ) => {
|
|
241
245
|
const { slug, labels, icon } = postType;
|
|
@@ -246,6 +250,8 @@ export const usePostTypeMenuItems = ( onClickMenuItem ) => {
|
|
|
246
250
|
const defaultTemplateType = defaultTemplateTypes?.find(
|
|
247
251
|
( { slug: _slug } ) => _slug === generalTemplateSlug
|
|
248
252
|
);
|
|
253
|
+
const hasGeneralTemplate =
|
|
254
|
+
existingTemplateSlugs?.includes( generalTemplateSlug );
|
|
249
255
|
const _needsUniqueIdentifier = needsUniqueIdentifier( postType );
|
|
250
256
|
let menuItemTitle =
|
|
251
257
|
labels.template_name ||
|
|
@@ -326,12 +332,14 @@ export const usePostTypeMenuItems = ( onClickMenuItem ) => {
|
|
|
326
332
|
},
|
|
327
333
|
},
|
|
328
334
|
labels,
|
|
335
|
+
hasGeneralTemplate,
|
|
329
336
|
template,
|
|
330
337
|
} );
|
|
331
338
|
};
|
|
332
339
|
}
|
|
333
|
-
// We don't need to add the menu item if there are no
|
|
334
|
-
|
|
340
|
+
// We don't need to add the menu item if there are no
|
|
341
|
+
// entities and the general template exists.
|
|
342
|
+
if ( ! hasGeneralTemplate || hasEntities ) {
|
|
335
343
|
accumulator.push( menuItem );
|
|
336
344
|
}
|
|
337
345
|
return accumulator;
|
|
@@ -564,11 +572,7 @@ export function useAuthorMenuItem( onClickMenuItem ) {
|
|
|
564
572
|
suggestion.slug
|
|
565
573
|
);
|
|
566
574
|
return {
|
|
567
|
-
title:
|
|
568
|
-
// translators: %s: Name of the author e.g: "Admin".
|
|
569
|
-
__( 'Author: %s' ),
|
|
570
|
-
suggestion.name
|
|
571
|
-
),
|
|
575
|
+
title: templateSlug,
|
|
572
576
|
slug: templateSlug,
|
|
573
577
|
templatePrefix: 'author',
|
|
574
578
|
};
|
|
@@ -590,6 +594,91 @@ export function useAuthorMenuItem( onClickMenuItem ) {
|
|
|
590
594
|
}
|
|
591
595
|
}
|
|
592
596
|
|
|
597
|
+
/**
|
|
598
|
+
* Helper hook that filters all the existing templates by the given
|
|
599
|
+
* object with the entity's slug as key and the template prefix as value.
|
|
600
|
+
*
|
|
601
|
+
* Example:
|
|
602
|
+
* `existingTemplates` is: [ { slug: 'tag-apple' }, { slug: 'page-about' }, { slug: 'tag' } ]
|
|
603
|
+
* `templatePrefixes` is: { post_tag: 'tag' }
|
|
604
|
+
* It will return: { post_tag: ['apple'] }
|
|
605
|
+
*
|
|
606
|
+
* Note: We append the `-` to the given template prefix in this function for our checks.
|
|
607
|
+
*
|
|
608
|
+
* @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
|
|
609
|
+
* @return {Record<string,string[]>} An object with the entity's slug as key and an array with the existing template slugs as value.
|
|
610
|
+
*/
|
|
611
|
+
const useExistingTemplateSlugs = ( templatePrefixes ) => {
|
|
612
|
+
const existingTemplates = useExistingTemplates();
|
|
613
|
+
const existingSlugs = useMemo( () => {
|
|
614
|
+
return Object.entries( templatePrefixes || {} ).reduce(
|
|
615
|
+
( accumulator, [ slug, prefix ] ) => {
|
|
616
|
+
const slugsWithTemplates = ( existingTemplates || [] ).reduce(
|
|
617
|
+
( _accumulator, existingTemplate ) => {
|
|
618
|
+
const _prefix = `${ prefix }-`;
|
|
619
|
+
if ( existingTemplate.slug.startsWith( _prefix ) ) {
|
|
620
|
+
_accumulator.push(
|
|
621
|
+
existingTemplate.slug.substring(
|
|
622
|
+
_prefix.length
|
|
623
|
+
)
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
return _accumulator;
|
|
627
|
+
},
|
|
628
|
+
[]
|
|
629
|
+
);
|
|
630
|
+
if ( slugsWithTemplates.length ) {
|
|
631
|
+
accumulator[ slug ] = slugsWithTemplates;
|
|
632
|
+
}
|
|
633
|
+
return accumulator;
|
|
634
|
+
},
|
|
635
|
+
{}
|
|
636
|
+
);
|
|
637
|
+
}, [ templatePrefixes, existingTemplates ] );
|
|
638
|
+
return existingSlugs;
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Helper hook that finds the existing records with an associated template,
|
|
643
|
+
* as they need to be excluded from the template suggestions.
|
|
644
|
+
*
|
|
645
|
+
* @param {string} entityName The entity's name.
|
|
646
|
+
* @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
|
|
647
|
+
* @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.
|
|
648
|
+
* @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the existing records as value.
|
|
649
|
+
*/
|
|
650
|
+
const useTemplatesToExclude = (
|
|
651
|
+
entityName,
|
|
652
|
+
templatePrefixes,
|
|
653
|
+
additionalQueryParameters = {}
|
|
654
|
+
) => {
|
|
655
|
+
const slugsToExcludePerEntity =
|
|
656
|
+
useExistingTemplateSlugs( templatePrefixes );
|
|
657
|
+
const recordsToExcludePerEntity = useSelect(
|
|
658
|
+
( select ) => {
|
|
659
|
+
return Object.entries( slugsToExcludePerEntity || {} ).reduce(
|
|
660
|
+
( accumulator, [ slug, slugsWithTemplates ] ) => {
|
|
661
|
+
const entitiesWithTemplates = select(
|
|
662
|
+
coreStore
|
|
663
|
+
).getEntityRecords( entityName, slug, {
|
|
664
|
+
_fields: 'id',
|
|
665
|
+
context: 'view',
|
|
666
|
+
slug: slugsWithTemplates,
|
|
667
|
+
...additionalQueryParameters[ slug ],
|
|
668
|
+
} );
|
|
669
|
+
if ( entitiesWithTemplates?.length ) {
|
|
670
|
+
accumulator[ slug ] = entitiesWithTemplates;
|
|
671
|
+
}
|
|
672
|
+
return accumulator;
|
|
673
|
+
},
|
|
674
|
+
{}
|
|
675
|
+
);
|
|
676
|
+
},
|
|
677
|
+
[ slugsToExcludePerEntity ]
|
|
678
|
+
);
|
|
679
|
+
return recordsToExcludePerEntity;
|
|
680
|
+
};
|
|
681
|
+
|
|
593
682
|
/**
|
|
594
683
|
* Helper hook that returns information about an entity having
|
|
595
684
|
* records that we can create a specific template for.
|
|
@@ -610,10 +699,19 @@ const useEntitiesInfo = (
|
|
|
610
699
|
templatePrefixes,
|
|
611
700
|
additionalQueryParameters = EMPTY_OBJECT
|
|
612
701
|
) => {
|
|
702
|
+
const recordsToExcludePerEntity = useTemplatesToExclude(
|
|
703
|
+
entityName,
|
|
704
|
+
templatePrefixes,
|
|
705
|
+
additionalQueryParameters
|
|
706
|
+
);
|
|
613
707
|
const entitiesHasRecords = useSelect(
|
|
614
708
|
( select ) => {
|
|
615
709
|
return Object.keys( templatePrefixes || {} ).reduce(
|
|
616
710
|
( accumulator, slug ) => {
|
|
711
|
+
const existingEntitiesIds =
|
|
712
|
+
recordsToExcludePerEntity?.[ slug ]?.map(
|
|
713
|
+
( { id } ) => id
|
|
714
|
+
) || [];
|
|
617
715
|
const records = select( coreStore ).getEntityRecords(
|
|
618
716
|
entityName,
|
|
619
717
|
slug,
|
|
@@ -621,6 +719,7 @@ const useEntitiesInfo = (
|
|
|
621
719
|
per_page: 1,
|
|
622
720
|
_fields: 'id',
|
|
623
721
|
context: 'view',
|
|
722
|
+
exclude: existingEntitiesIds,
|
|
624
723
|
...additionalQueryParameters[ slug ],
|
|
625
724
|
}
|
|
626
725
|
);
|
|
@@ -631,18 +730,28 @@ const useEntitiesInfo = (
|
|
|
631
730
|
{}
|
|
632
731
|
);
|
|
633
732
|
},
|
|
634
|
-
[
|
|
733
|
+
[
|
|
734
|
+
templatePrefixes,
|
|
735
|
+
recordsToExcludePerEntity,
|
|
736
|
+
entityName,
|
|
737
|
+
additionalQueryParameters,
|
|
738
|
+
]
|
|
635
739
|
);
|
|
636
740
|
const entitiesInfo = useMemo( () => {
|
|
637
741
|
return Object.keys( templatePrefixes || {} ).reduce(
|
|
638
742
|
( accumulator, slug ) => {
|
|
743
|
+
const existingEntitiesIds =
|
|
744
|
+
recordsToExcludePerEntity?.[ slug ]?.map(
|
|
745
|
+
( { id } ) => id
|
|
746
|
+
) || [];
|
|
639
747
|
accumulator[ slug ] = {
|
|
640
748
|
hasEntities: entitiesHasRecords[ slug ],
|
|
749
|
+
existingEntitiesIds,
|
|
641
750
|
};
|
|
642
751
|
return accumulator;
|
|
643
752
|
},
|
|
644
753
|
{}
|
|
645
754
|
);
|
|
646
|
-
}, [ templatePrefixes, entitiesHasRecords ] );
|
|
755
|
+
}, [ templatePrefixes, recordsToExcludePerEntity, entitiesHasRecords ] );
|
|
647
756
|
return entitiesInfo;
|
|
648
757
|
};
|
|
@@ -2,73 +2,12 @@ import { __ } from '@wordpress/i18n';
|
|
|
2
2
|
import { pencil, drawerRight } from '@wordpress/icons';
|
|
3
3
|
import { useMemo } from '@wordpress/element';
|
|
4
4
|
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
5
|
-
import { useDispatch, useSelect } from '@wordpress/data';
|
|
6
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
7
5
|
import { addQueryArgs } from '@wordpress/url';
|
|
8
6
|
import { PATTERN_TYPES } from '../../utils/constants';
|
|
9
7
|
import { unlock } from '../../lock-unlock';
|
|
10
8
|
|
|
11
9
|
const { useLocation, useHistory } = unlock( routerPrivateApis );
|
|
12
10
|
|
|
13
|
-
export const useSetActiveTemplateAction = () => {
|
|
14
|
-
const activeTheme = useSelect( ( select ) =>
|
|
15
|
-
select( coreStore ).getCurrentTheme()
|
|
16
|
-
);
|
|
17
|
-
const { getEntityRecord } = useSelect( coreStore );
|
|
18
|
-
const { editEntityRecord, saveEditedEntityRecord } =
|
|
19
|
-
useDispatch( coreStore );
|
|
20
|
-
return useMemo(
|
|
21
|
-
() => ( {
|
|
22
|
-
id: 'set-active-template',
|
|
23
|
-
label( items ) {
|
|
24
|
-
return items.some( ( item ) => item._isActive )
|
|
25
|
-
? __( 'Deactivate' )
|
|
26
|
-
: __( 'Activate' );
|
|
27
|
-
},
|
|
28
|
-
isPrimary: true,
|
|
29
|
-
icon: pencil,
|
|
30
|
-
isEligible( item ) {
|
|
31
|
-
if ( item.theme !== activeTheme.stylesheet ) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// If it's not a created template but a registered template,
|
|
36
|
-
// only allow activating (so when it's inactive).
|
|
37
|
-
if ( typeof item.id !== 'number' ) {
|
|
38
|
-
return item._isActive === false;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return true;
|
|
42
|
-
},
|
|
43
|
-
async callback( items ) {
|
|
44
|
-
const deactivate = items.some( ( item ) => item._isActive );
|
|
45
|
-
// current active templates
|
|
46
|
-
const activeTemplates = {
|
|
47
|
-
...( ( await getEntityRecord( 'root', 'site' )
|
|
48
|
-
.active_templates ) ?? {} ),
|
|
49
|
-
};
|
|
50
|
-
for ( const item of items ) {
|
|
51
|
-
if ( deactivate ) {
|
|
52
|
-
delete activeTemplates[ item.slug ];
|
|
53
|
-
} else {
|
|
54
|
-
activeTemplates[ item.slug ] = item.id;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
await editEntityRecord( 'root', 'site', undefined, {
|
|
58
|
-
active_templates: activeTemplates,
|
|
59
|
-
} );
|
|
60
|
-
await saveEditedEntityRecord( 'root', 'site' );
|
|
61
|
-
},
|
|
62
|
-
} ),
|
|
63
|
-
[
|
|
64
|
-
editEntityRecord,
|
|
65
|
-
saveEditedEntityRecord,
|
|
66
|
-
getEntityRecord,
|
|
67
|
-
activeTheme,
|
|
68
|
-
]
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
11
|
export const useEditPostAction = () => {
|
|
73
12
|
const history = useHistory();
|
|
74
13
|
return useMemo(
|
|
@@ -41,7 +41,8 @@ const { useLocation } = unlock( routerPrivateApis );
|
|
|
41
41
|
const { useStyle, UploadProgressSnackbar } = unlock( editorPrivateApis );
|
|
42
42
|
|
|
43
43
|
const ANIMATION_DURATION = 0.3;
|
|
44
|
-
|
|
44
|
+
// Reset to the default background color.
|
|
45
|
+
const CONTENT_COLOR = { background: '#fcfcfc' };
|
|
45
46
|
|
|
46
47
|
function Layout() {
|
|
47
48
|
const { query, name: routeKey, areas, widths } = useLocation();
|
|
@@ -321,7 +322,9 @@ export default function LayoutWithGlobalStylesProvider( props ) {
|
|
|
321
322
|
} }
|
|
322
323
|
>
|
|
323
324
|
<ThemeProvider color={ themeColors }>
|
|
324
|
-
<
|
|
325
|
+
<ErrorBoundary>
|
|
326
|
+
<Layout { ...props } />
|
|
327
|
+
</ErrorBoundary>
|
|
325
328
|
</ThemeProvider>
|
|
326
329
|
</ThemeProvider>
|
|
327
330
|
</Tooltip.Provider>
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { __ } from '@wordpress/i18n';
|
|
2
2
|
import { useDispatch } from '@wordpress/data';
|
|
3
|
-
import {
|
|
3
|
+
import { privateApis as editorPrivateApis } from '@wordpress/editor';
|
|
4
4
|
import { store as preferencesStore } from '@wordpress/preferences';
|
|
5
|
+
import { unlock } from '../../lock-unlock';
|
|
6
|
+
|
|
7
|
+
const { MoreMenuItem } = unlock( editorPrivateApis );
|
|
5
8
|
|
|
6
9
|
export default function WelcomeGuideMenuItem() {
|
|
7
10
|
const { toggle } = useDispatch( preferencesStore );
|
|
8
11
|
|
|
9
12
|
return (
|
|
10
|
-
<
|
|
13
|
+
<MoreMenuItem
|
|
14
|
+
onClick={ () => toggle( 'core/edit-site', 'welcomeGuide' ) }
|
|
15
|
+
>
|
|
11
16
|
{ __( 'Welcome Guide' ) }
|
|
12
|
-
</
|
|
17
|
+
</MoreMenuItem>
|
|
13
18
|
);
|
|
14
19
|
}
|
|
@@ -1,52 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
Icon as WCIcon,
|
|
4
|
-
__experimentalHStack as HStack,
|
|
5
|
-
privateApis as componentsPrivateApis,
|
|
6
|
-
} from '@wordpress/components';
|
|
7
|
-
import { __, _x } from '@wordpress/i18n';
|
|
8
|
-
import { useState, useMemo } from '@wordpress/element';
|
|
9
|
-
import { decodeEntities } from '@wordpress/html-entities';
|
|
1
|
+
import { __ } from '@wordpress/i18n';
|
|
2
|
+
import { useMemo } from '@wordpress/element';
|
|
10
3
|
import { parse } from '@wordpress/blocks';
|
|
11
4
|
import { BlockPreview } from '@wordpress/block-editor';
|
|
12
5
|
import {
|
|
13
6
|
EditorProvider,
|
|
14
7
|
privateApis as editorPrivateApis,
|
|
15
8
|
} from '@wordpress/editor';
|
|
16
|
-
import {
|
|
17
|
-
privateApis as corePrivateApis,
|
|
18
|
-
store as coreStore,
|
|
19
|
-
} from '@wordpress/core-data';
|
|
20
|
-
import { useSelect } from '@wordpress/data';
|
|
21
|
-
import { useAddedBy } from './hooks';
|
|
22
|
-
import { useDefaultTemplateTypes } from '../add-new-template/utils';
|
|
23
9
|
import usePatternSettings from '../page-patterns/use-pattern-settings';
|
|
24
10
|
import { unlock } from '../../lock-unlock';
|
|
25
11
|
|
|
26
|
-
const { Badge: WCBadge } = unlock( componentsPrivateApis );
|
|
27
|
-
const { useEntityRecordsWithPermissions } = unlock( corePrivateApis );
|
|
28
12
|
const { useStyle } = unlock( editorPrivateApis );
|
|
29
13
|
|
|
30
|
-
function useAllDefaultTemplateTypes() {
|
|
31
|
-
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
32
|
-
const { records: staticRecords } = useEntityRecordsWithPermissions(
|
|
33
|
-
'root',
|
|
34
|
-
'registeredTemplate'
|
|
35
|
-
);
|
|
36
|
-
return [
|
|
37
|
-
...defaultTemplateTypes,
|
|
38
|
-
...staticRecords
|
|
39
|
-
?.filter( ( record ) => ! record.is_custom )
|
|
40
|
-
.map( ( record ) => {
|
|
41
|
-
return {
|
|
42
|
-
slug: record.slug,
|
|
43
|
-
title: record.title.rendered,
|
|
44
|
-
description: record.description,
|
|
45
|
-
};
|
|
46
|
-
} ),
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
14
|
function PreviewField( { item } ) {
|
|
51
15
|
const settings = usePatternSettings();
|
|
52
16
|
const backgroundColor = useStyle( 'color.background' ) ?? 'white';
|
|
@@ -85,111 +49,3 @@ export const previewField = {
|
|
|
85
49
|
render: PreviewField,
|
|
86
50
|
enableSorting: false,
|
|
87
51
|
};
|
|
88
|
-
|
|
89
|
-
export const descriptionField = {
|
|
90
|
-
label: __( 'Description' ),
|
|
91
|
-
id: 'description',
|
|
92
|
-
render: window?.__experimentalTemplateActivate
|
|
93
|
-
? function RenderDescription( { item } ) {
|
|
94
|
-
const defaultTemplateTypes = useAllDefaultTemplateTypes();
|
|
95
|
-
const defaultTemplateType = defaultTemplateTypes.find(
|
|
96
|
-
( type ) => type.slug === item.slug
|
|
97
|
-
);
|
|
98
|
-
return item.description
|
|
99
|
-
? decodeEntities( item.description )
|
|
100
|
-
: defaultTemplateType?.description;
|
|
101
|
-
}
|
|
102
|
-
: ( { item } ) => {
|
|
103
|
-
return item.description && decodeEntities( item.description );
|
|
104
|
-
},
|
|
105
|
-
enableSorting: false,
|
|
106
|
-
enableGlobalSearch: true,
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
function AuthorField( { item } ) {
|
|
110
|
-
const [ isImageLoaded, setIsImageLoaded ] = useState( false );
|
|
111
|
-
const { text, icon, imageUrl } = useAddedBy( item.type, item.id );
|
|
112
|
-
|
|
113
|
-
return (
|
|
114
|
-
<HStack alignment="left" spacing={ 0 }>
|
|
115
|
-
{ imageUrl && (
|
|
116
|
-
<div
|
|
117
|
-
className={ clsx( 'fields-controls__author-avatar', {
|
|
118
|
-
'is-loaded': isImageLoaded,
|
|
119
|
-
} ) }
|
|
120
|
-
>
|
|
121
|
-
<img
|
|
122
|
-
onLoad={ () => setIsImageLoaded( true ) }
|
|
123
|
-
alt=""
|
|
124
|
-
src={ imageUrl }
|
|
125
|
-
/>
|
|
126
|
-
</div>
|
|
127
|
-
) }
|
|
128
|
-
{ ! imageUrl && (
|
|
129
|
-
<div className="fields-controls__author-icon">
|
|
130
|
-
<WCIcon icon={ icon } />
|
|
131
|
-
</div>
|
|
132
|
-
) }
|
|
133
|
-
<span className="fields-controls__author-name">{ text }</span>
|
|
134
|
-
</HStack>
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export const authorField = {
|
|
139
|
-
label: __( 'Author' ),
|
|
140
|
-
id: 'author',
|
|
141
|
-
getValue: ( { item } ) => item.author_text ?? item.author,
|
|
142
|
-
render: AuthorField,
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export const activeField = {
|
|
146
|
-
label: __( 'Status' ),
|
|
147
|
-
id: 'active',
|
|
148
|
-
type: 'boolean',
|
|
149
|
-
getValue: ( { item } ) => item._isActive,
|
|
150
|
-
render: function Render( { item } ) {
|
|
151
|
-
const activeLabel = item._isCustom
|
|
152
|
-
? _x( 'Active when used', 'template' )
|
|
153
|
-
: _x( 'Active', 'template' );
|
|
154
|
-
const activeIntent = item._isCustom ? 'info' : 'success';
|
|
155
|
-
const isActive = item._isActive;
|
|
156
|
-
return (
|
|
157
|
-
<WCBadge intent={ isActive ? activeIntent : 'default' }>
|
|
158
|
-
{ isActive ? activeLabel : _x( 'Inactive', 'template' ) }
|
|
159
|
-
</WCBadge>
|
|
160
|
-
);
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
export const useThemeField = () => {
|
|
165
|
-
const activeTheme = useSelect( ( select ) =>
|
|
166
|
-
select( coreStore ).getCurrentTheme()
|
|
167
|
-
);
|
|
168
|
-
return useMemo(
|
|
169
|
-
() => ( {
|
|
170
|
-
label: __( 'Compatible Theme' ),
|
|
171
|
-
id: 'theme',
|
|
172
|
-
getValue: ( { item } ) => item.theme,
|
|
173
|
-
render: function Render( { item } ) {
|
|
174
|
-
if ( item.theme === activeTheme.stylesheet ) {
|
|
175
|
-
return <WCBadge intent="success">{ item.theme }</WCBadge>;
|
|
176
|
-
}
|
|
177
|
-
return <WCBadge intent="error">{ item.theme }</WCBadge>;
|
|
178
|
-
},
|
|
179
|
-
} ),
|
|
180
|
-
[ activeTheme ]
|
|
181
|
-
);
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
export const slugField = {
|
|
185
|
-
label: __( 'Template Type' ),
|
|
186
|
-
id: 'slug',
|
|
187
|
-
getValue: ( { item } ) => item.slug,
|
|
188
|
-
render: function Render( { item } ) {
|
|
189
|
-
const defaultTemplateTypes = useAllDefaultTemplateTypes();
|
|
190
|
-
const defaultTemplateType = defaultTemplateTypes.find(
|
|
191
|
-
( type ) => type.slug === item.slug
|
|
192
|
-
);
|
|
193
|
-
return defaultTemplateType?.title || _x( 'Custom', 'template type' );
|
|
194
|
-
},
|
|
195
|
-
};
|