@wordpress/fields 0.24.0 → 0.24.1-next.ff1cebbba.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/README.md +1 -1
- package/build/actions/delete-post.js +168 -117
- package/build/actions/delete-post.js.map +7 -1
- package/build/actions/duplicate-pattern.js +42 -43
- package/build/actions/duplicate-pattern.js.map +7 -1
- package/build/actions/duplicate-post.js +104 -93
- package/build/actions/duplicate-post.js.map +7 -1
- package/build/actions/duplicate-template-part.js +71 -63
- package/build/actions/duplicate-template-part.js.map +7 -1
- package/build/actions/export-pattern.js +60 -45
- package/build/actions/export-pattern.js.map +7 -1
- package/build/actions/index.js +71 -94
- package/build/actions/index.js.map +7 -1
- package/build/actions/permanently-delete-post.js +161 -132
- package/build/actions/permanently-delete-post.js.map +7 -1
- package/build/actions/rename-post.js +77 -83
- package/build/actions/rename-post.js.map +7 -1
- package/build/actions/reorder-page.js +76 -73
- package/build/actions/reorder-page.js.map +7 -1
- package/build/actions/reset-post.js +214 -165
- package/build/actions/reset-post.js.map +7 -1
- package/build/actions/restore-post.js +91 -75
- package/build/actions/restore-post.js.map +7 -1
- package/build/actions/trash-post.js +167 -127
- package/build/actions/trash-post.js.map +7 -1
- package/build/actions/utils.js +48 -41
- package/build/actions/utils.js.map +7 -1
- package/build/actions/view-post-revisions.js +39 -35
- package/build/actions/view-post-revisions.js.map +7 -1
- package/build/actions/view-post.js +31 -28
- package/build/actions/view-post.js.map +7 -1
- package/build/components/create-template-part-modal/index.js +213 -169
- package/build/components/create-template-part-modal/index.js.map +7 -1
- package/build/components/create-template-part-modal/utils.js +48 -48
- package/build/components/create-template-part-modal/utils.js.map +7 -1
- package/build/fields/author/author-view.js +63 -69
- package/build/fields/author/author-view.js.map +7 -1
- package/build/fields/author/index.js +43 -29
- package/build/fields/author/index.js.map +7 -1
- package/build/fields/comment-status/index.js +42 -32
- package/build/fields/comment-status/index.js.map +7 -1
- package/build/fields/date/date-view.js +84 -58
- package/build/fields/date/date-view.js.map +7 -1
- package/build/fields/date/index.js +39 -25
- package/build/fields/date/index.js.map +7 -1
- package/build/fields/discussion/index.js +36 -32
- package/build/fields/discussion/index.js.map +7 -1
- package/build/fields/featured-image/featured-image-edit.js +115 -97
- package/build/fields/featured-image/featured-image-edit.js.map +7 -1
- package/build/fields/featured-image/featured-image-view.js +41 -34
- package/build/fields/featured-image/featured-image-view.js.map +7 -1
- package/build/fields/featured-image/index.js +31 -26
- package/build/fields/featured-image/index.js.map +7 -1
- package/build/fields/index.js +83 -118
- package/build/fields/index.js.map +7 -1
- package/build/fields/order/index.js +28 -23
- package/build/fields/order/index.js.map +7 -1
- package/build/fields/page-title/index.js +42 -30
- package/build/fields/page-title/index.js.map +7 -1
- package/build/fields/page-title/view.js +38 -41
- package/build/fields/page-title/view.js.map +7 -1
- package/build/fields/parent/index.js +31 -26
- package/build/fields/parent/index.js.map +7 -1
- package/build/fields/parent/parent-edit.js +200 -168
- package/build/fields/parent/parent-edit.js.map +7 -1
- package/build/fields/parent/parent-view.js +40 -31
- package/build/fields/parent/parent-view.js.map +7 -1
- package/build/fields/parent/utils.js +29 -16
- package/build/fields/parent/utils.js.map +7 -1
- package/build/fields/password/edit.js +67 -53
- package/build/fields/password/edit.js.map +7 -1
- package/build/fields/password/index.js +40 -26
- package/build/fields/password/index.js.map +7 -1
- package/build/fields/pattern-title/index.js +42 -30
- package/build/fields/pattern-title/index.js.map +7 -1
- package/build/fields/pattern-title/view.js +43 -41
- package/build/fields/pattern-title/view.js.map +7 -1
- package/build/fields/ping-status/index.js +66 -47
- package/build/fields/ping-status/index.js.map +7 -1
- package/build/fields/slug/index.js +41 -27
- package/build/fields/slug/index.js.map +7 -1
- package/build/fields/slug/slug-edit.js +116 -107
- package/build/fields/slug/slug-edit.js.map +7 -1
- package/build/fields/slug/slug-view.js +30 -23
- package/build/fields/slug/slug-view.js.map +7 -1
- package/build/fields/slug/utils.js +32 -20
- package/build/fields/slug/utils.js.map +7 -1
- package/build/fields/status/index.js +43 -29
- package/build/fields/status/index.js.map +7 -1
- package/build/fields/status/status-elements.js +58 -44
- package/build/fields/status/status-elements.js.map +7 -1
- package/build/fields/status/status-view.js +42 -36
- package/build/fields/status/status-view.js.map +7 -1
- package/build/fields/template/index.js +29 -24
- package/build/fields/template/index.js.map +7 -1
- package/build/fields/template/template-edit.js +167 -142
- package/build/fields/template/template-edit.js.map +7 -1
- package/build/fields/template-title/index.js +42 -30
- package/build/fields/template-title/index.js.map +7 -1
- package/build/fields/title/index.js +42 -32
- package/build/fields/title/index.js.map +7 -1
- package/build/fields/title/view.js +57 -39
- package/build/fields/title/view.js.map +7 -1
- package/build/index.js +39 -36
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/mutation/index.js +91 -76
- package/build/mutation/index.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build-module/actions/delete-post.js +155 -107
- package/build-module/actions/delete-post.js.map +7 -1
- package/build-module/actions/duplicate-pattern.js +24 -36
- package/build-module/actions/duplicate-pattern.js.map +7 -1
- package/build-module/actions/duplicate-post.js +87 -84
- package/build-module/actions/duplicate-post.js.map +7 -1
- package/build-module/actions/duplicate-template-part.js +51 -58
- package/build-module/actions/duplicate-template-part.js.map +7 -1
- package/build-module/actions/export-pattern.js +40 -39
- package/build-module/actions/export-pattern.js.map +7 -1
- package/build-module/actions/index.js +29 -14
- package/build-module/actions/index.js.map +7 -1
- package/build-module/actions/permanently-delete-post.js +146 -125
- package/build-module/actions/permanently-delete-post.js.map +7 -1
- package/build-module/actions/rename-post.js +63 -77
- package/build-module/actions/rename-post.js.map +7 -1
- package/build-module/actions/reorder-page.js +58 -65
- package/build-module/actions/reorder-page.js.map +7 -1
- package/build-module/actions/reset-post.js +185 -152
- package/build-module/actions/reset-post.js.map +7 -1
- package/build-module/actions/restore-post.js +72 -68
- package/build-module/actions/restore-post.js.map +7 -1
- package/build-module/actions/trash-post.js +152 -119
- package/build-module/actions/trash-post.js.map +7 -1
- package/build-module/actions/utils.js +23 -34
- package/build-module/actions/utils.js.map +7 -1
- package/build-module/actions/view-post-revisions.js +21 -31
- package/build-module/actions/view-post-revisions.js.map +7 -1
- package/build-module/actions/view-post.js +12 -23
- package/build-module/actions/view-post.js.map +7 -1
- package/build-module/components/create-template-part-modal/index.js +201 -154
- package/build-module/components/create-template-part-modal/index.js.map +7 -1
- package/build-module/components/create-template-part-modal/utils.js +26 -43
- package/build-module/components/create-template-part-modal/utils.js.map +7 -1
- package/build-module/fields/author/author-view.js +34 -62
- package/build-module/fields/author/author-view.js.map +7 -1
- package/build-module/fields/author/index.js +14 -24
- package/build-module/fields/author/index.js.map +7 -1
- package/build-module/fields/comment-status/index.js +24 -29
- package/build-module/fields/comment-status/index.js.map +7 -1
- package/build-module/fields/date/date-view.js +66 -53
- package/build-module/fields/date/date-view.js.map +7 -1
- package/build-module/fields/date/index.js +10 -20
- package/build-module/fields/date/index.js.map +7 -1
- package/build-module/fields/discussion/index.js +18 -29
- package/build-module/fields/discussion/index.js.map +7 -1
- package/build-module/fields/featured-image/featured-image-edit.js +93 -90
- package/build-module/fields/featured-image/featured-image-edit.js.map +7 -1
- package/build-module/fields/featured-image/featured-image-view.js +20 -29
- package/build-module/fields/featured-image/featured-image-view.js.map +7 -1
- package/build-module/fields/featured-image/index.js +11 -21
- package/build-module/fields/featured-image/index.js.map +7 -1
- package/build-module/fields/index.js +35 -17
- package/build-module/fields/index.js.map +7 -1
- package/build-module/fields/order/index.js +10 -20
- package/build-module/fields/order/index.js.map +7 -1
- package/build-module/fields/page-title/index.js +13 -25
- package/build-module/fields/page-title/index.js.map +7 -1
- package/build-module/fields/page-title/view.js +20 -37
- package/build-module/fields/page-title/view.js.map +7 -1
- package/build-module/fields/parent/index.js +11 -21
- package/build-module/fields/parent/index.js.map +7 -1
- package/build-module/fields/parent/parent-edit.js +172 -160
- package/build-module/fields/parent/parent-edit.js.map +7 -1
- package/build-module/fields/parent/parent-view.js +19 -27
- package/build-module/fields/parent/parent-view.js.map +7 -1
- package/build-module/fields/parent/utils.js +8 -13
- package/build-module/fields/parent/utils.js.map +7 -1
- package/build-module/fields/password/edit.js +53 -48
- package/build-module/fields/password/edit.js.map +7 -1
- package/build-module/fields/password/index.js +11 -21
- package/build-module/fields/password/index.js.map +7 -1
- package/build-module/fields/pattern-title/index.js +13 -25
- package/build-module/fields/pattern-title/index.js.map +7 -1
- package/build-module/fields/pattern-title/view.js +21 -34
- package/build-module/fields/pattern-title/view.js.map +7 -1
- package/build-module/fields/ping-status/index.js +48 -43
- package/build-module/fields/ping-status/index.js.map +7 -1
- package/build-module/fields/slug/index.js +11 -21
- package/build-module/fields/slug/index.js.map +7 -1
- package/build-module/fields/slug/slug-edit.js +101 -100
- package/build-module/fields/slug/slug-edit.js.map +7 -1
- package/build-module/fields/slug/slug-view.js +9 -16
- package/build-module/fields/slug/slug-view.js.map +7 -1
- package/build-module/fields/slug/utils.js +9 -13
- package/build-module/fields/slug/utils.js.map +7 -1
- package/build-module/fields/status/index.js +13 -23
- package/build-module/fields/status/index.js.map +7 -1
- package/build-module/fields/status/status-elements.js +47 -40
- package/build-module/fields/status/status-elements.js.map +7 -1
- package/build-module/fields/status/status-view.js +14 -31
- package/build-module/fields/status/status-view.js.map +7 -1
- package/build-module/fields/template/index.js +10 -18
- package/build-module/fields/template/index.js.map +7 -1
- package/build-module/fields/template/template-edit.js +147 -130
- package/build-module/fields/template/template-edit.js.map +7 -1
- package/build-module/fields/template-title/index.js +13 -25
- package/build-module/fields/template-title/index.js.map +7 -1
- package/build-module/fields/title/index.js +13 -27
- package/build-module/fields/title/index.js.map +7 -1
- package/build-module/fields/title/view.js +25 -32
- package/build-module/fields/title/view.js.map +7 -1
- package/build-module/index.js +7 -4
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/mutation/index.js +70 -72
- package/build-module/mutation/index.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/build-style/style-rtl.css +4 -139
- package/build-style/style.css +4 -139
- package/build-types/fields/author/author-view.d.ts.map +1 -1
- package/build-types/fields/discussion/index.d.ts.map +1 -1
- package/build-types/fields/featured-image/featured-image-edit.d.ts +2 -2
- package/build-types/fields/featured-image/featured-image-edit.d.ts.map +1 -1
- package/build-types/fields/featured-image/featured-image-view.d.ts +5 -2
- package/build-types/fields/featured-image/featured-image-view.d.ts.map +1 -1
- package/build-types/fields/featured-image/index.d.ts +3 -3
- package/build-types/fields/featured-image/index.d.ts.map +1 -1
- package/build-types/types.d.ts +18 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +34 -27
- package/src/components/create-template-part-modal/style.scss +4 -0
- package/src/fields/author/author-view.tsx +3 -17
- package/src/fields/discussion/index.tsx +1 -0
- package/src/fields/featured-image/featured-image-edit.tsx +2 -2
- package/src/fields/featured-image/featured-image-view.tsx +3 -15
- package/src/fields/featured-image/index.ts +3 -3
- package/src/fields/featured-image/style.scss +3 -0
- package/src/fields/template/style.scss +4 -0
- package/src/fields/title/style.scss +1 -1
- package/src/style.scss +9 -8
- package/src/types.ts +18 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/index.native.js +0 -2
- package/build/index.native.js.map +0 -1
- package/build-module/index.native.js +0 -2
- package/build-module/index.native.js.map +0 -1
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/fields/template/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport type { BasePost } from '../../types';\nimport { TemplateEdit } from './template-edit';\n\nconst templateField: Field< BasePost > = {\n\tid: 'template',\n\ttype: 'text',\n\tlabel: __( 'Template' ),\n\tEdit: TemplateEdit,\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\n/**\n * Template field for BasePost.\n */\nexport default templateField;\n"],
|
|
5
|
+
"mappings": "AAQA,SAAS,UAAU;AAEnB,SAAS,oBAAoB;AAE7B,MAAM,gBAAmC;AAAA,EACxC,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO,GAAI,UAAW;AAAA,EACtB,MAAM;AAAA,EACN,eAAe;AAAA,EACf,UAAU;AACX;AAKA,IAAO,mBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,63 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { unlock } from '../../lock-unlock';
|
|
20
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo, useState } from "@wordpress/element";
|
|
3
|
+
import { parse } from "@wordpress/blocks";
|
|
4
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
5
|
+
import { __experimentalBlockPatternsList as BlockPatternsList } from "@wordpress/block-editor";
|
|
6
|
+
import {
|
|
7
|
+
Button,
|
|
8
|
+
Dropdown,
|
|
9
|
+
MenuGroup,
|
|
10
|
+
MenuItem,
|
|
11
|
+
Modal
|
|
12
|
+
} from "@wordpress/components";
|
|
13
|
+
import { useAsyncList } from "@wordpress/compose";
|
|
14
|
+
import { useSelect } from "@wordpress/data";
|
|
15
|
+
import { decodeEntities } from "@wordpress/html-entities";
|
|
16
|
+
import { __ } from "@wordpress/i18n";
|
|
17
|
+
import { getItemTitle } from "../../actions/utils";
|
|
18
|
+
import { unlock } from "../../lock-unlock";
|
|
21
19
|
const EMPTY_ARRAY = [];
|
|
22
|
-
|
|
20
|
+
const TemplateEdit = ({
|
|
23
21
|
data,
|
|
24
22
|
field,
|
|
25
23
|
onChange
|
|
26
24
|
}) => {
|
|
27
|
-
const {
|
|
28
|
-
id
|
|
29
|
-
} = field;
|
|
25
|
+
const { id } = field;
|
|
30
26
|
const postType = data.type;
|
|
31
|
-
const postId = typeof data.id ===
|
|
27
|
+
const postId = typeof data.id === "number" ? data.id : parseInt(data.id, 10);
|
|
32
28
|
const slug = data.slug;
|
|
33
|
-
const {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
getHomePage,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
29
|
+
const { canSwitchTemplate, templates } = useSelect(
|
|
30
|
+
(select) => {
|
|
31
|
+
const allTemplates = select(coreStore).getEntityRecords(
|
|
32
|
+
"postType",
|
|
33
|
+
"wp_template",
|
|
34
|
+
{
|
|
35
|
+
per_page: -1,
|
|
36
|
+
post_type: postType
|
|
37
|
+
}
|
|
38
|
+
) ?? EMPTY_ARRAY;
|
|
39
|
+
const { getHomePage, getPostsPageId } = unlock(
|
|
40
|
+
select(coreStore)
|
|
41
|
+
);
|
|
42
|
+
const isPostsPage = getPostsPageId() === +postId;
|
|
43
|
+
const isFrontPage = postType === "page" && getHomePage()?.postId === +postId;
|
|
44
|
+
const allowSwitchingTemplate = !isPostsPage && !isFrontPage;
|
|
45
|
+
return {
|
|
46
|
+
templates: allTemplates,
|
|
47
|
+
canSwitchTemplate: allowSwitchingTemplate
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
[postId, postType]
|
|
51
|
+
);
|
|
54
52
|
const templatesAsPatterns = useMemo(() => {
|
|
55
53
|
if (!canSwitchTemplate) {
|
|
56
54
|
return [];
|
|
57
55
|
}
|
|
58
|
-
return templates.filter(
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
return templates.filter(
|
|
57
|
+
(template) => template.is_custom && template.slug !== data.template && // Skip empty templates.
|
|
58
|
+
!!template.content.raw
|
|
59
|
+
).map((template) => ({
|
|
61
60
|
name: template.slug,
|
|
62
61
|
blocks: parse(template.content.raw),
|
|
63
62
|
title: decodeEntities(template.title.rendered),
|
|
@@ -65,87 +64,105 @@ export const TemplateEdit = ({
|
|
|
65
64
|
}));
|
|
66
65
|
}, [canSwitchTemplate, data.template, templates]);
|
|
67
66
|
const shownTemplates = useAsyncList(templatesAsPatterns);
|
|
68
|
-
const value = field.getValue({
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const currentTemplate = useSelect(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
67
|
+
const value = field.getValue({ item: data });
|
|
68
|
+
const foundTemplate = templates.find(
|
|
69
|
+
(template) => template.slug === value
|
|
70
|
+
);
|
|
71
|
+
const currentTemplate = useSelect(
|
|
72
|
+
(select) => {
|
|
73
|
+
if (foundTemplate) {
|
|
74
|
+
return foundTemplate;
|
|
75
|
+
}
|
|
76
|
+
let slugToCheck;
|
|
77
|
+
if (slug) {
|
|
78
|
+
slugToCheck = postType === "page" ? `${postType}-${slug}` : `single-${postType}-${slug}`;
|
|
79
|
+
} else {
|
|
80
|
+
slugToCheck = postType === "page" ? "page" : `single-${postType}`;
|
|
81
|
+
}
|
|
82
|
+
if (postType) {
|
|
83
|
+
const templateId = select(coreStore).getDefaultTemplateId({
|
|
84
|
+
slug: slugToCheck
|
|
85
|
+
});
|
|
86
|
+
return select(coreStore).getEntityRecord(
|
|
87
|
+
"postType",
|
|
88
|
+
"wp_template",
|
|
89
|
+
templateId
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
[foundTemplate, postType, slug]
|
|
94
|
+
);
|
|
93
95
|
const [showModal, setShowModal] = useState(false);
|
|
94
|
-
const onChangeControl = useCallback(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
onToggle
|
|
114
|
-
}) => /*#__PURE__*/_jsxs(MenuGroup, {
|
|
115
|
-
children: [/*#__PURE__*/_jsx(MenuItem, {
|
|
116
|
-
onClick: () => {
|
|
117
|
-
setShowModal(true);
|
|
118
|
-
onToggle();
|
|
119
|
-
},
|
|
120
|
-
children: __('Change template')
|
|
121
|
-
}),
|
|
122
|
-
// The default template in a post is indicated by an empty string
|
|
123
|
-
value !== '' && /*#__PURE__*/_jsx(MenuItem, {
|
|
124
|
-
onClick: () => {
|
|
125
|
-
onChangeControl('');
|
|
126
|
-
onToggle();
|
|
127
|
-
},
|
|
128
|
-
children: __('Use default template')
|
|
129
|
-
})]
|
|
130
|
-
})
|
|
131
|
-
}), showModal && /*#__PURE__*/_jsx(Modal, {
|
|
132
|
-
title: __('Choose a template'),
|
|
133
|
-
onRequestClose: () => setShowModal(false),
|
|
134
|
-
overlayClassName: "fields-controls__template-modal",
|
|
135
|
-
isFullScreen: true,
|
|
136
|
-
children: /*#__PURE__*/_jsx("div", {
|
|
137
|
-
className: "fields-controls__template-content",
|
|
138
|
-
children: /*#__PURE__*/_jsx(BlockPatternsList, {
|
|
139
|
-
label: __('Templates'),
|
|
140
|
-
blockPatterns: templatesAsPatterns,
|
|
141
|
-
shownPatterns: shownTemplates,
|
|
142
|
-
onClickPattern: template => {
|
|
143
|
-
onChangeControl(template.name);
|
|
144
|
-
setShowModal(false);
|
|
96
|
+
const onChangeControl = useCallback(
|
|
97
|
+
(newValue) => onChange({
|
|
98
|
+
[id]: newValue
|
|
99
|
+
}),
|
|
100
|
+
[id, onChange]
|
|
101
|
+
);
|
|
102
|
+
return /* @__PURE__ */ jsxs("fieldset", { className: "fields-controls__template", children: [
|
|
103
|
+
/* @__PURE__ */ jsx(
|
|
104
|
+
Dropdown,
|
|
105
|
+
{
|
|
106
|
+
popoverProps: { placement: "bottom-start" },
|
|
107
|
+
renderToggle: ({ onToggle }) => /* @__PURE__ */ jsx(
|
|
108
|
+
Button,
|
|
109
|
+
{
|
|
110
|
+
__next40pxDefaultSize: true,
|
|
111
|
+
variant: "tertiary",
|
|
112
|
+
size: "compact",
|
|
113
|
+
onClick: onToggle,
|
|
114
|
+
children: currentTemplate ? getItemTitle(currentTemplate) : ""
|
|
145
115
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
116
|
+
),
|
|
117
|
+
renderContent: ({ onToggle }) => /* @__PURE__ */ jsxs(MenuGroup, { children: [
|
|
118
|
+
/* @__PURE__ */ jsx(
|
|
119
|
+
MenuItem,
|
|
120
|
+
{
|
|
121
|
+
onClick: () => {
|
|
122
|
+
setShowModal(true);
|
|
123
|
+
onToggle();
|
|
124
|
+
},
|
|
125
|
+
children: __("Change template")
|
|
126
|
+
}
|
|
127
|
+
),
|
|
128
|
+
// The default template in a post is indicated by an empty string
|
|
129
|
+
value !== "" && /* @__PURE__ */ jsx(
|
|
130
|
+
MenuItem,
|
|
131
|
+
{
|
|
132
|
+
onClick: () => {
|
|
133
|
+
onChangeControl("");
|
|
134
|
+
onToggle();
|
|
135
|
+
},
|
|
136
|
+
children: __("Use default template")
|
|
137
|
+
}
|
|
138
|
+
)
|
|
139
|
+
] })
|
|
140
|
+
}
|
|
141
|
+
),
|
|
142
|
+
showModal && /* @__PURE__ */ jsx(
|
|
143
|
+
Modal,
|
|
144
|
+
{
|
|
145
|
+
title: __("Choose a template"),
|
|
146
|
+
onRequestClose: () => setShowModal(false),
|
|
147
|
+
overlayClassName: "fields-controls__template-modal",
|
|
148
|
+
isFullScreen: true,
|
|
149
|
+
children: /* @__PURE__ */ jsx("div", { className: "fields-controls__template-content", children: /* @__PURE__ */ jsx(
|
|
150
|
+
BlockPatternsList,
|
|
151
|
+
{
|
|
152
|
+
label: __("Templates"),
|
|
153
|
+
blockPatterns: templatesAsPatterns,
|
|
154
|
+
shownPatterns: shownTemplates,
|
|
155
|
+
onClickPattern: (template) => {
|
|
156
|
+
onChangeControl(template.name);
|
|
157
|
+
setShowModal(false);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
) })
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
] });
|
|
164
|
+
};
|
|
165
|
+
export {
|
|
166
|
+
TemplateEdit
|
|
150
167
|
};
|
|
151
|
-
//# sourceMappingURL=template-edit.js.map
|
|
168
|
+
//# sourceMappingURL=template-edit.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useMemo","useState","parse","store","coreStore","__experimentalBlockPatternsList","BlockPatternsList","Button","Dropdown","MenuGroup","MenuItem","Modal","useAsyncList","useSelect","decodeEntities","__","getItemTitle","unlock","jsx","_jsx","jsxs","_jsxs","EMPTY_ARRAY","TemplateEdit","data","field","onChange","id","postType","type","postId","parseInt","slug","canSwitchTemplate","templates","select","_select$getEntityReco","allTemplates","getEntityRecords","per_page","post_type","getHomePage","getPostsPageId","isPostsPage","isFrontPage","allowSwitchingTemplate","templatesAsPatterns","filter","template","is_custom","content","raw","map","name","blocks","title","rendered","shownTemplates","value","getValue","item","foundTemplate","find","currentTemplate","slugToCheck","templateId","getDefaultTemplateId","getEntityRecord","showModal","setShowModal","onChangeControl","newValue","className","children","popoverProps","placement","renderToggle","onToggle","__next40pxDefaultSize","variant","size","onClick","renderContent","onRequestClose","overlayClassName","isFullScreen","label","blockPatterns","shownPatterns","onClickPattern"],"sources":["@wordpress/fields/src/fields/template/template-edit.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo, useState } from '@wordpress/element';\n// @ts-ignore\nimport { parse } from '@wordpress/blocks';\nimport type { WpTemplate } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\n// @ts-expect-error block-editor is not typed correctly.\nimport { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';\nimport {\n\tButton,\n\tDropdown,\n\tMenuGroup,\n\tMenuItem,\n\tModal,\n} from '@wordpress/components';\nimport { useAsyncList } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { getItemTitle } from '../../actions/utils';\nimport type { BasePost } from '../../types';\nimport { unlock } from '../../lock-unlock';\n\nconst EMPTY_ARRAY: [] = [];\n\nexport const TemplateEdit = ( {\n\tdata,\n\tfield,\n\tonChange,\n}: DataFormControlProps< BasePost > ) => {\n\tconst { id } = field;\n\tconst postType = data.type;\n\tconst postId =\n\t\ttypeof data.id === 'number' ? data.id : parseInt( data.id, 10 );\n\tconst slug = data.slug;\n\n\tconst { canSwitchTemplate, templates } = useSelect(\n\t\t( select ) => {\n\t\t\tconst allTemplates =\n\t\t\t\tselect( coreStore ).getEntityRecords< WpTemplate >(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template',\n\t\t\t\t\t{\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t\tpost_type: postType,\n\t\t\t\t\t}\n\t\t\t\t) ?? EMPTY_ARRAY;\n\n\t\t\tconst { getHomePage, getPostsPageId } = unlock(\n\t\t\t\tselect( coreStore )\n\t\t\t);\n\n\t\t\tconst isPostsPage = getPostsPageId() === +postId;\n\t\t\tconst isFrontPage =\n\t\t\t\tpostType === 'page' && getHomePage()?.postId === +postId;\n\n\t\t\tconst allowSwitchingTemplate = ! isPostsPage && ! isFrontPage;\n\n\t\t\treturn {\n\t\t\t\ttemplates: allTemplates,\n\t\t\t\tcanSwitchTemplate: allowSwitchingTemplate,\n\t\t\t};\n\t\t},\n\t\t[ postId, postType ]\n\t);\n\n\tconst templatesAsPatterns = useMemo( () => {\n\t\tif ( ! canSwitchTemplate ) {\n\t\t\treturn [];\n\t\t}\n\t\treturn templates\n\t\t\t.filter(\n\t\t\t\t( template ) =>\n\t\t\t\t\ttemplate.is_custom &&\n\t\t\t\t\ttemplate.slug !== data.template &&\n\t\t\t\t\t// Skip empty templates.\n\t\t\t\t\t!! template.content.raw\n\t\t\t)\n\t\t\t.map( ( template ) => ( {\n\t\t\t\tname: template.slug,\n\t\t\t\tblocks: parse( template.content.raw ),\n\t\t\t\ttitle: decodeEntities( template.title.rendered ),\n\t\t\t\tid: template.id,\n\t\t\t} ) );\n\t}, [ canSwitchTemplate, data.template, templates ] );\n\n\tconst shownTemplates = useAsyncList( templatesAsPatterns );\n\n\tconst value = field.getValue( { item: data } );\n\tconst foundTemplate = templates.find(\n\t\t( template ) => template.slug === value\n\t);\n\n\tconst currentTemplate = useSelect(\n\t\t( select ) => {\n\t\t\tif ( foundTemplate ) {\n\t\t\t\treturn foundTemplate;\n\t\t\t}\n\n\t\t\tlet slugToCheck;\n\t\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t\t// through template hierarchy.\n\t\t\tif ( slug ) {\n\t\t\t\tslugToCheck =\n\t\t\t\t\tpostType === 'page'\n\t\t\t\t\t\t? `${ postType }-${ slug }`\n\t\t\t\t\t\t: `single-${ postType }-${ slug }`;\n\t\t\t} else {\n\t\t\t\tslugToCheck =\n\t\t\t\t\tpostType === 'page' ? 'page' : `single-${ postType }`;\n\t\t\t}\n\n\t\t\tif ( postType ) {\n\t\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\t\tslug: slugToCheck,\n\t\t\t\t} );\n\n\t\t\t\treturn select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template',\n\t\t\t\t\ttemplateId\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ foundTemplate, postType, slug ]\n\t);\n\n\tconst [ showModal, setShowModal ] = useState( false );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\treturn (\n\t\t<fieldset className=\"fields-controls__template\">\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ { placement: 'bottom-start' } }\n\t\t\t\trenderToggle={ ( { onToggle } ) => (\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ currentTemplate\n\t\t\t\t\t\t\t? getItemTitle( currentTemplate )\n\t\t\t\t\t\t\t: '' }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t\trenderContent={ ( { onToggle } ) => (\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowModal( true );\n\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Change template' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// The default template in a post is indicated by an empty string\n\t\t\t\t\t\t\tvalue !== '' && (\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonChangeControl( '' );\n\t\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Use default template' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t) }\n\t\t\t/>\n\t\t\t{ showModal && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Choose a template' ) }\n\t\t\t\t\tonRequestClose={ () => setShowModal( false ) }\n\t\t\t\t\toverlayClassName=\"fields-controls__template-modal\"\n\t\t\t\t\tisFullScreen\n\t\t\t\t>\n\t\t\t\t\t<div className=\"fields-controls__template-content\">\n\t\t\t\t\t\t<BlockPatternsList\n\t\t\t\t\t\t\tlabel={ __( 'Templates' ) }\n\t\t\t\t\t\t\tblockPatterns={ templatesAsPatterns }\n\t\t\t\t\t\t\tshownPatterns={ shownTemplates }\n\t\t\t\t\t\t\tonClickPattern={ (\n\t\t\t\t\t\t\t\ttemplate: ( typeof templatesAsPatterns )[ 0 ]\n\t\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\t\tonChangeControl( template.name );\n\t\t\t\t\t\t\t\tsetShowModal( false );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</fieldset>\n\t);\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;AACnE;AACA,SAASC,KAAK,QAAQ,mBAAmB;AAEzC,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AAGzD;AACA;AACA;AACA;AACA,SAASC,+BAA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;EAAA,CACQ,CAAC;AAEb,CAAC","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/fields/template/template-edit.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo, useState } from '@wordpress/element';\n// @ts-ignore\nimport { parse } from '@wordpress/blocks';\nimport type { WpTemplate } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\n// @ts-expect-error block-editor is not typed correctly.\nimport { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';\nimport {\n\tButton,\n\tDropdown,\n\tMenuGroup,\n\tMenuItem,\n\tModal,\n} from '@wordpress/components';\nimport { useAsyncList } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { getItemTitle } from '../../actions/utils';\nimport type { BasePost } from '../../types';\nimport { unlock } from '../../lock-unlock';\n\nconst EMPTY_ARRAY: [] = [];\n\nexport const TemplateEdit = ( {\n\tdata,\n\tfield,\n\tonChange,\n}: DataFormControlProps< BasePost > ) => {\n\tconst { id } = field;\n\tconst postType = data.type;\n\tconst postId =\n\t\ttypeof data.id === 'number' ? data.id : parseInt( data.id, 10 );\n\tconst slug = data.slug;\n\n\tconst { canSwitchTemplate, templates } = useSelect(\n\t\t( select ) => {\n\t\t\tconst allTemplates =\n\t\t\t\tselect( coreStore ).getEntityRecords< WpTemplate >(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template',\n\t\t\t\t\t{\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t\tpost_type: postType,\n\t\t\t\t\t}\n\t\t\t\t) ?? EMPTY_ARRAY;\n\n\t\t\tconst { getHomePage, getPostsPageId } = unlock(\n\t\t\t\tselect( coreStore )\n\t\t\t);\n\n\t\t\tconst isPostsPage = getPostsPageId() === +postId;\n\t\t\tconst isFrontPage =\n\t\t\t\tpostType === 'page' && getHomePage()?.postId === +postId;\n\n\t\t\tconst allowSwitchingTemplate = ! isPostsPage && ! isFrontPage;\n\n\t\t\treturn {\n\t\t\t\ttemplates: allTemplates,\n\t\t\t\tcanSwitchTemplate: allowSwitchingTemplate,\n\t\t\t};\n\t\t},\n\t\t[ postId, postType ]\n\t);\n\n\tconst templatesAsPatterns = useMemo( () => {\n\t\tif ( ! canSwitchTemplate ) {\n\t\t\treturn [];\n\t\t}\n\t\treturn templates\n\t\t\t.filter(\n\t\t\t\t( template ) =>\n\t\t\t\t\ttemplate.is_custom &&\n\t\t\t\t\ttemplate.slug !== data.template &&\n\t\t\t\t\t// Skip empty templates.\n\t\t\t\t\t!! template.content.raw\n\t\t\t)\n\t\t\t.map( ( template ) => ( {\n\t\t\t\tname: template.slug,\n\t\t\t\tblocks: parse( template.content.raw ),\n\t\t\t\ttitle: decodeEntities( template.title.rendered ),\n\t\t\t\tid: template.id,\n\t\t\t} ) );\n\t}, [ canSwitchTemplate, data.template, templates ] );\n\n\tconst shownTemplates = useAsyncList( templatesAsPatterns );\n\n\tconst value = field.getValue( { item: data } );\n\tconst foundTemplate = templates.find(\n\t\t( template ) => template.slug === value\n\t);\n\n\tconst currentTemplate = useSelect(\n\t\t( select ) => {\n\t\t\tif ( foundTemplate ) {\n\t\t\t\treturn foundTemplate;\n\t\t\t}\n\n\t\t\tlet slugToCheck;\n\t\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t\t// through template hierarchy.\n\t\t\tif ( slug ) {\n\t\t\t\tslugToCheck =\n\t\t\t\t\tpostType === 'page'\n\t\t\t\t\t\t? `${ postType }-${ slug }`\n\t\t\t\t\t\t: `single-${ postType }-${ slug }`;\n\t\t\t} else {\n\t\t\t\tslugToCheck =\n\t\t\t\t\tpostType === 'page' ? 'page' : `single-${ postType }`;\n\t\t\t}\n\n\t\t\tif ( postType ) {\n\t\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\t\tslug: slugToCheck,\n\t\t\t\t} );\n\n\t\t\t\treturn select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template',\n\t\t\t\t\ttemplateId\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ foundTemplate, postType, slug ]\n\t);\n\n\tconst [ showModal, setShowModal ] = useState( false );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\treturn (\n\t\t<fieldset className=\"fields-controls__template\">\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ { placement: 'bottom-start' } }\n\t\t\t\trenderToggle={ ( { onToggle } ) => (\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ currentTemplate\n\t\t\t\t\t\t\t? getItemTitle( currentTemplate )\n\t\t\t\t\t\t\t: '' }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t\trenderContent={ ( { onToggle } ) => (\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowModal( true );\n\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Change template' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// The default template in a post is indicated by an empty string\n\t\t\t\t\t\t\tvalue !== '' && (\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonChangeControl( '' );\n\t\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Use default template' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t) }\n\t\t\t/>\n\t\t\t{ showModal && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Choose a template' ) }\n\t\t\t\t\tonRequestClose={ () => setShowModal( false ) }\n\t\t\t\t\toverlayClassName=\"fields-controls__template-modal\"\n\t\t\t\t\tisFullScreen\n\t\t\t\t>\n\t\t\t\t\t<div className=\"fields-controls__template-content\">\n\t\t\t\t\t\t<BlockPatternsList\n\t\t\t\t\t\t\tlabel={ __( 'Templates' ) }\n\t\t\t\t\t\t\tblockPatterns={ templatesAsPatterns }\n\t\t\t\t\t\t\tshownPatterns={ shownTemplates }\n\t\t\t\t\t\t\tonClickPattern={ (\n\t\t\t\t\t\t\t\ttemplate: ( typeof templatesAsPatterns )[ 0 ]\n\t\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\t\tonChangeControl( template.name );\n\t\t\t\t\t\t\t\tsetShowModal( false );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</fieldset>\n\t);\n};\n"],
|
|
5
|
+
"mappings": "AAuJK,cAYA,YAZA;AApJL,SAAS,aAAa,SAAS,gBAAgB;AAE/C,SAAS,aAAa;AAEtB,SAAS,SAAS,iBAAiB;AAOnC,SAAS,mCAAmC,yBAAyB;AACrE;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,oBAAoB;A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AAgB,CAAE,EAAE,SAAS,MAC5B,qBAAC,aACA;AAAA;AAAA,YAAC;AAAA;AAAA,cACA,SAAU,MAAM;AACf,6BAAc,IAAK;AACnB,yBAAS;AAAA,cACV;AAAA,cAEE,aAAI,iBAAkB;AAAA;AAAA,UACzB;AAAA;AAAA,UAGC,UAAU,MACT;AAAA,YAAC;AAAA;AAAA,cACA,SAAU,MAAM;AACf,gCAAiB,EAAG;AACpB,yBAAS;AAAA,cACV;AAAA,cAEE,aAAI,sBAAuB;AAAA;AAAA,UAC9B;AAAA,WAGH;AAAA;AAAA,IAEF;AAAA,IACE,aACD;AAAA,MAAC;AAAA;AAAA,QACA,OAAQ,GAAI,mBAAoB;AAAA,QAChC,gBAAiB,MAAM,aAAc,KAAM;AAAA,QAC3C,kBAAiB;AAAA,QACjB,cAAY;AAAA,QAEZ,8BAAC,SAAI,WAAU,qCACd;AAAA,UAAC;AAAA;AAAA,YACA,OAAQ,GAAI,WAAY;AAAA,YACxB,eAAgB;AAAA,YAChB,eAAgB;AAAA,YAChB,gBAAiB,CAChB,aACI;AACJ,8BAAiB,SAAS,IAAK;AAC/B,2BAAc,KAAM;AAAA,YACrB;AAAA;AAAA,QACD,GACD;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,31 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { __ } from '@wordpress/i18n';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { getItemTitle } from '../../actions/utils';
|
|
12
|
-
import TitleView from '../title/view';
|
|
1
|
+
import { __ } from "@wordpress/i18n";
|
|
2
|
+
import { getItemTitle } from "../../actions/utils";
|
|
3
|
+
import TitleView from "../title/view";
|
|
13
4
|
const templateTitleField = {
|
|
14
|
-
type:
|
|
15
|
-
label: __(
|
|
16
|
-
placeholder: __(
|
|
17
|
-
id:
|
|
18
|
-
getValue: ({
|
|
19
|
-
item
|
|
20
|
-
}) => getItemTitle(item),
|
|
5
|
+
type: "text",
|
|
6
|
+
label: __("Template"),
|
|
7
|
+
placeholder: __("No title"),
|
|
8
|
+
id: "title",
|
|
9
|
+
getValue: ({ item }) => getItemTitle(item),
|
|
21
10
|
render: TitleView,
|
|
22
11
|
enableHiding: false,
|
|
23
12
|
enableGlobalSearch: true,
|
|
24
13
|
filterBy: false
|
|
25
14
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
//# sourceMappingURL=index.js.map
|
|
15
|
+
var template_title_default = templateTitleField;
|
|
16
|
+
export {
|
|
17
|
+
template_title_default as default
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/fields/template-title/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { Template } from '../../types';\nimport { getItemTitle } from '../../actions/utils';\nimport TitleView from '../title/view';\n\nconst templateTitleField: Field< Template > = {\n\ttype: 'text',\n\tlabel: __( 'Template' ),\n\tplaceholder: __( 'No title' ),\n\tid: 'title',\n\tgetValue: ( { item } ) => getItemTitle( item ),\n\trender: TitleView,\n\tenableHiding: false,\n\tenableGlobalSearch: true,\n\tfilterBy: false,\n};\n\n/**\n * Title for the template entity.\n */\nexport default templateTitleField;\n"],
|
|
5
|
+
"mappings": "AAIA,SAAS,UAAU;AAMnB,SAAS,oBAAoB;AAC7B,OAAO,eAAe;AAEtB,MAAM,qBAAwC;AAAA,EAC7C,MAAM;AAAA,EACN,OAAO,GAAI,UAAW;AAAA,EACtB,aAAa,GAAI,UAAW;AAAA,EAC5B,IAAI;AAAA,EACJ,UAAU,CAAE,EAAE,KAAK,MAAO,aAAc,IAAK;AAAA,EAC7C,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,oBAAoB;AAAA,EACpB,UAAU;AACX;AAKA,IAAO,yBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,33 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { __ } from '@wordpress/i18n';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { getItemTitle } from '../../actions/utils';
|
|
12
|
-
import TitleView from './view';
|
|
1
|
+
import { __ } from "@wordpress/i18n";
|
|
2
|
+
import { getItemTitle } from "../../actions/utils";
|
|
3
|
+
import TitleView from "./view";
|
|
13
4
|
const titleField = {
|
|
14
|
-
type:
|
|
15
|
-
id:
|
|
16
|
-
label: __(
|
|
17
|
-
placeholder: __(
|
|
18
|
-
getValue: ({
|
|
19
|
-
item
|
|
20
|
-
}) => getItemTitle(item),
|
|
5
|
+
type: "text",
|
|
6
|
+
id: "title",
|
|
7
|
+
label: __("Title"),
|
|
8
|
+
placeholder: __("No title"),
|
|
9
|
+
getValue: ({ item }) => getItemTitle(item),
|
|
21
10
|
render: TitleView,
|
|
22
11
|
enableHiding: true,
|
|
23
12
|
enableGlobalSearch: true,
|
|
24
13
|
filterBy: false
|
|
25
14
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*/
|
|
32
|
-
export default titleField;
|
|
33
|
-
//# sourceMappingURL=index.js.map
|
|
15
|
+
var title_default = titleField;
|
|
16
|
+
export {
|
|
17
|
+
title_default as default
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/fields/title/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { CommonPost } from '../../types';\nimport { getItemTitle } from '../../actions/utils';\nimport TitleView from './view';\n\nconst titleField: Field< CommonPost > = {\n\ttype: 'text',\n\tid: 'title',\n\tlabel: __( 'Title' ),\n\tplaceholder: __( 'No title' ),\n\tgetValue: ( { item } ) => getItemTitle( item ),\n\trender: TitleView,\n\tenableHiding: true,\n\tenableGlobalSearch: true,\n\tfilterBy: false,\n};\n\n/**\n * Title for the any entity with a `title` property.\n * For patterns, pages or templates you should use the respective field\n * because there are some differences in the rendering, labels, etc.\n */\nexport default titleField;\n"],
|
|
5
|
+
"mappings": "AAIA,SAAS,UAAU;AAMnB,SAAS,oBAAoB;AAC7B,OAAO,eAAe;AAEtB,MAAM,aAAkC;AAAA,EACvC,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,OAAO,GAAI,OAAQ;AAAA,EACnB,aAAa,GAAI,UAAW;AAAA,EAC5B,UAAU,CAAE,EAAE,KAAK,MAAO,aAAc,IAAK;AAAA,EAC7C,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,oBAAoB;AAAA,EACpB,UAAU;AACX;AAOA,IAAO,gBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,39 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
import { __experimentalHStack as HStack } from '@wordpress/components';
|
|
9
|
-
import { __ } from '@wordpress/i18n';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { getItemTitle } from '../../actions/utils';
|
|
16
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
-
export function BaseTitleView({
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { __experimentalHStack as HStack } from "@wordpress/components";
|
|
4
|
+
import { __ } from "@wordpress/i18n";
|
|
5
|
+
import { getItemTitle } from "../../actions/utils";
|
|
6
|
+
function BaseTitleView({
|
|
18
7
|
item,
|
|
19
8
|
className,
|
|
20
9
|
children
|
|
21
10
|
}) {
|
|
22
11
|
const renderedTitle = getItemTitle(item);
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
return /* @__PURE__ */ jsxs(
|
|
13
|
+
HStack,
|
|
14
|
+
{
|
|
15
|
+
className: clsx("fields-field__title", className),
|
|
16
|
+
alignment: "center",
|
|
17
|
+
justify: "flex-start",
|
|
18
|
+
children: [
|
|
19
|
+
/* @__PURE__ */ jsx("span", { children: renderedTitle || __("(no title)") }),
|
|
20
|
+
children
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
);
|
|
31
24
|
}
|
|
32
|
-
|
|
33
|
-
item
|
|
34
|
-
}) {
|
|
35
|
-
return /*#__PURE__*/_jsx(BaseTitleView, {
|
|
36
|
-
item: item
|
|
37
|
-
});
|
|
25
|
+
function TitleView({ item }) {
|
|
26
|
+
return /* @__PURE__ */ jsx(BaseTitleView, { item });
|
|
38
27
|
}
|
|
39
|
-
|
|
28
|
+
export {
|
|
29
|
+
BaseTitleView,
|
|
30
|
+
TitleView as default
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=view.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/fields/title/view.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { ReactNode } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { __experimentalHStack as HStack } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { CommonPost } from '../../types';\nimport { getItemTitle } from '../../actions/utils';\n\nexport function BaseTitleView( {\n\titem,\n\tclassName,\n\tchildren,\n}: {\n\titem: CommonPost;\n\tclassName?: string;\n\tchildren?: ReactNode;\n} ) {\n\tconst renderedTitle = getItemTitle( item );\n\treturn (\n\t\t<HStack\n\t\t\tclassName={ clsx( 'fields-field__title', className ) }\n\t\t\talignment=\"center\"\n\t\t\tjustify=\"flex-start\"\n\t\t>\n\t\t\t<span>{ renderedTitle || __( '(no title)' ) }</span>\n\t\t\t{ children }\n\t\t</HStack>\n\t);\n}\n\nexport default function TitleView( { item }: { item: CommonPost } ) {\n\treturn <BaseTitleView item={ item } />;\n}\n"],
|
|
5
|
+
"mappings": "AA6BE,SAKC,KALD;AA1BF,OAAO,UAAU;AAMjB,SAAS,wBAAwB,cAAc;AAC/C,SAAS,UAAU;AAMnB,SAAS,oBAAoB;AAEtB,SAAS,cAAe;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACD,GAII;AACH,QAAM,gBAAgB,aAAc,IAAK;AACzC,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAY,KAAM,uBAAuB,SAAU;AAAA,MACnD,WAAU;AAAA,MACV,SAAQ;AAAA,MAER;AAAA,4BAAC,UAAO,2BAAiB,GAAI,YAAa,GAAG;AAAA,QAC3C;AAAA;AAAA;AAAA,EACH;AAEF;AAEe,SAAR,UAA4B,EAAE,KAAK,GAA0B;AACnE,SAAO,oBAAC,iBAAc,MAAc;AACrC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export * from "./fields";
|
|
2
|
+
export * from "./actions";
|
|
3
|
+
import { default as default2 } from "./components/create-template-part-modal";
|
|
4
|
+
export {
|
|
5
|
+
default2 as CreateTemplatePartModal
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './fields';\nexport * from './actions';\nexport { default as CreateTemplatePartModal } from './components/create-template-part-modal';\nexport type { BasePostWithEmbeddedAuthor, BasePost, PostType } from './types';\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,SAAoB,WAAXA,gBAA0C;",
|
|
6
|
+
"names": ["default"]
|
|
7
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from "@wordpress/private-apis";
|
|
2
|
+
const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
|
|
3
|
+
"I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
|
|
4
|
+
"@wordpress/fields"
|
|
5
|
+
);
|
|
6
|
+
export {
|
|
6
7
|
lock,
|
|
7
8
|
unlock
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=lock-unlock.js.map
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=lock-unlock.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lock-unlock.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/fields'\n\t);\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,wDAAwD;AAC1D,MAAM,EAAE,MAAM,OAAO,IAC3B;AAAA,EACC;AAAA,EACA;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|