@wordpress/editor 14.42.0 → 14.43.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 +2 -0
- package/build/components/collaborators-overlay/cursor-registry.cjs +86 -0
- package/build/components/collaborators-overlay/cursor-registry.cjs.map +7 -0
- package/build/components/collaborators-overlay/index.cjs +7 -2
- package/build/components/collaborators-overlay/index.cjs.map +2 -2
- package/build/components/collaborators-overlay/overlay-iframe-styles.cjs +1 -1
- package/build/components/collaborators-overlay/overlay-iframe-styles.cjs.map +2 -2
- package/build/components/collaborators-overlay/overlay.cjs +31 -1
- package/build/components/collaborators-overlay/overlay.cjs.map +2 -2
- package/build/components/collaborators-presence/index.cjs +14 -4
- package/build/components/collaborators-presence/index.cjs.map +2 -2
- package/build/components/collaborators-presence/list.cjs +20 -4
- package/build/components/collaborators-presence/list.cjs.map +2 -2
- package/build/components/post-card-panel/index.cjs +4 -15
- package/build/components/post-card-panel/index.cjs.map +2 -2
- package/build/components/post-content-information/index.cjs +10 -13
- package/build/components/post-content-information/index.cjs.map +2 -2
- package/build/components/post-revisions-panel/index.cjs +164 -0
- package/build/components/post-revisions-panel/index.cjs.map +7 -0
- package/build/components/post-revisions-preview/revisions-slider.cjs +24 -5
- package/build/components/post-revisions-preview/revisions-slider.cjs.map +2 -2
- package/build/components/post-template/create-new-template-modal.cjs +39 -46
- package/build/components/post-template/create-new-template-modal.cjs.map +2 -2
- package/build/components/post-template/hooks.cjs +52 -6
- package/build/components/post-template/hooks.cjs.map +2 -2
- package/build/components/post-template/swap-template-button.cjs +31 -20
- package/build/components/post-template/swap-template-button.cjs.map +2 -2
- package/build/components/preferences-modal/index.cjs +35 -27
- package/build/components/preferences-modal/index.cjs.map +2 -2
- package/build/components/revision-block-diff/index.cjs +9 -32
- package/build/components/revision-block-diff/index.cjs.map +3 -3
- package/build/components/revision-diff-panel/index.cjs +68 -0
- package/build/components/revision-diff-panel/index.cjs.map +7 -0
- package/build/components/revision-fields-diff/index.cjs +96 -0
- package/build/components/revision-fields-diff/index.cjs.map +7 -0
- package/build/components/sidebar/dataform-post-summary.cjs +8 -53
- package/build/components/sidebar/dataform-post-summary.cjs.map +2 -2
- package/build/components/sidebar/index.cjs +25 -22
- package/build/components/sidebar/index.cjs.map +3 -3
- package/build/components/sidebar/post-revision-summary.cjs +74 -0
- package/build/components/sidebar/post-revision-summary.cjs.map +7 -0
- package/build/components/sidebar/post-summary.cjs +35 -42
- package/build/components/sidebar/post-summary.cjs.map +3 -3
- package/build/components/style-book/index.cjs +4 -3
- package/build/components/style-book/index.cjs.map +2 -2
- package/build/components/sync-connection-error-modal/index.cjs +2 -2
- package/build/components/sync-connection-error-modal/index.cjs.map +1 -1
- package/build/components/template-actions-panel/block-theme-content.cjs +188 -0
- package/build/components/template-actions-panel/block-theme-content.cjs.map +7 -0
- package/build/components/template-actions-panel/classic-theme-content.cjs +159 -0
- package/build/components/template-actions-panel/classic-theme-content.cjs.map +7 -0
- package/build/components/template-actions-panel/index.cjs +59 -0
- package/build/components/template-actions-panel/index.cjs.map +7 -0
- package/build/dataviews/store/private-actions.cjs +2 -0
- package/build/dataviews/store/private-actions.cjs.map +2 -2
- package/build/store/private-actions.cjs +21 -2
- package/build/store/private-actions.cjs.map +2 -2
- package/build/store/private-selectors.cjs +40 -15
- package/build/store/private-selectors.cjs.map +2 -2
- package/build-module/components/collaborators-overlay/cursor-registry.mjs +61 -0
- package/build-module/components/collaborators-overlay/cursor-registry.mjs.map +7 -0
- package/build-module/components/collaborators-overlay/index.mjs +7 -2
- package/build-module/components/collaborators-overlay/index.mjs.map +2 -2
- package/build-module/components/collaborators-overlay/overlay-iframe-styles.mjs +1 -1
- package/build-module/components/collaborators-overlay/overlay-iframe-styles.mjs.map +2 -2
- package/build-module/components/collaborators-overlay/overlay.mjs +32 -2
- package/build-module/components/collaborators-overlay/overlay.mjs.map +2 -2
- package/build-module/components/collaborators-presence/index.mjs +14 -4
- package/build-module/components/collaborators-presence/index.mjs.map +2 -2
- package/build-module/components/collaborators-presence/list.mjs +20 -4
- package/build-module/components/collaborators-presence/list.mjs.map +2 -2
- package/build-module/components/post-card-panel/index.mjs +6 -17
- package/build-module/components/post-card-panel/index.mjs.map +2 -2
- package/build-module/components/post-content-information/index.mjs +6 -13
- package/build-module/components/post-content-information/index.mjs.map +2 -2
- package/build-module/components/post-revisions-panel/index.mjs +139 -0
- package/build-module/components/post-revisions-panel/index.mjs.map +7 -0
- package/build-module/components/post-revisions-preview/revisions-slider.mjs +24 -5
- package/build-module/components/post-revisions-preview/revisions-slider.mjs.map +2 -2
- package/build-module/components/post-template/create-new-template-modal.mjs +39 -46
- package/build-module/components/post-template/create-new-template-modal.mjs.map +2 -2
- package/build-module/components/post-template/hooks.mjs +53 -7
- package/build-module/components/post-template/hooks.mjs.map +2 -2
- package/build-module/components/post-template/swap-template-button.mjs +27 -20
- package/build-module/components/post-template/swap-template-button.mjs.map +2 -2
- package/build-module/components/preferences-modal/index.mjs +35 -27
- package/build-module/components/preferences-modal/index.mjs.map +2 -2
- package/build-module/components/revision-block-diff/index.mjs +9 -32
- package/build-module/components/revision-block-diff/index.mjs.map +2 -2
- package/build-module/components/revision-diff-panel/index.mjs +37 -0
- package/build-module/components/revision-diff-panel/index.mjs.map +7 -0
- package/build-module/components/revision-fields-diff/index.mjs +65 -0
- package/build-module/components/revision-fields-diff/index.mjs.map +7 -0
- package/build-module/components/sidebar/dataform-post-summary.mjs +8 -53
- package/build-module/components/sidebar/dataform-post-summary.mjs.map +2 -2
- package/build-module/components/sidebar/index.mjs +25 -22
- package/build-module/components/sidebar/index.mjs.map +2 -2
- package/build-module/components/sidebar/post-revision-summary.mjs +43 -0
- package/build-module/components/sidebar/post-revision-summary.mjs.map +7 -0
- package/build-module/components/sidebar/post-summary.mjs +31 -42
- package/build-module/components/sidebar/post-summary.mjs.map +2 -2
- package/build-module/components/style-book/index.mjs +4 -3
- package/build-module/components/style-book/index.mjs.map +2 -2
- package/build-module/components/sync-connection-error-modal/index.mjs +2 -2
- package/build-module/components/sync-connection-error-modal/index.mjs.map +1 -1
- package/build-module/components/template-actions-panel/block-theme-content.mjs +167 -0
- package/build-module/components/template-actions-panel/block-theme-content.mjs.map +7 -0
- package/build-module/components/template-actions-panel/classic-theme-content.mjs +138 -0
- package/build-module/components/template-actions-panel/classic-theme-content.mjs.map +7 -0
- package/build-module/components/template-actions-panel/index.mjs +28 -0
- package/build-module/components/template-actions-panel/index.mjs.map +7 -0
- package/build-module/dataviews/store/private-actions.mjs +5 -1
- package/build-module/dataviews/store/private-actions.mjs.map +2 -2
- package/build-module/store/private-actions.mjs +21 -2
- package/build-module/store/private-actions.mjs.map +2 -2
- package/build-module/store/private-selectors.mjs +40 -15
- package/build-module/store/private-selectors.mjs.map +2 -2
- package/build-style/style-rtl.css +111 -42
- package/build-style/style.css +111 -42
- package/build-types/components/collaborators-overlay/cursor-registry.d.ts +36 -0
- package/build-types/components/collaborators-overlay/cursor-registry.d.ts.map +1 -0
- package/build-types/components/collaborators-overlay/index.d.ts +7 -4
- package/build-types/components/collaborators-overlay/index.d.ts.map +1 -1
- package/build-types/components/collaborators-overlay/overlay-iframe-styles.d.ts +1 -1
- package/build-types/components/collaborators-overlay/overlay-iframe-styles.d.ts.map +1 -1
- package/build-types/components/collaborators-overlay/overlay.d.ts +4 -1
- package/build-types/components/collaborators-overlay/overlay.d.ts.map +1 -1
- package/build-types/components/collaborators-presence/index.d.ts.map +1 -1
- package/build-types/components/collaborators-presence/list.d.ts +4 -1
- package/build-types/components/collaborators-presence/list.d.ts.map +1 -1
- package/build-types/components/post-card-panel/index.d.ts.map +1 -1
- package/build-types/components/post-content-information/index.d.ts +4 -1
- package/build-types/components/post-content-information/index.d.ts.map +1 -1
- package/build-types/components/post-revisions-panel/index.d.ts +2 -0
- package/build-types/components/post-revisions-panel/index.d.ts.map +1 -0
- package/build-types/components/post-revisions-preview/revisions-slider.d.ts.map +1 -1
- package/build-types/components/post-template/create-new-template-modal.d.ts.map +1 -1
- package/build-types/components/post-template/hooks.d.ts +1 -1
- package/build-types/components/post-template/hooks.d.ts.map +1 -1
- package/build-types/components/post-template/swap-template-button.d.ts +4 -0
- package/build-types/components/post-template/swap-template-button.d.ts.map +1 -1
- package/build-types/components/revision-block-diff/index.d.ts.map +1 -1
- package/build-types/components/revision-diff-panel/index.d.ts +14 -0
- package/build-types/components/revision-diff-panel/index.d.ts.map +1 -0
- package/build-types/components/revision-fields-diff/index.d.ts +6 -0
- package/build-types/components/revision-fields-diff/index.d.ts.map +1 -0
- package/build-types/components/sidebar/dataform-post-summary.d.ts.map +1 -1
- package/build-types/components/sidebar/index.d.ts.map +1 -1
- package/build-types/components/sidebar/post-revision-summary.d.ts +2 -0
- package/build-types/components/sidebar/post-revision-summary.d.ts.map +1 -0
- package/build-types/components/sidebar/post-summary.d.ts +3 -0
- package/build-types/components/sidebar/post-summary.d.ts.map +1 -1
- package/build-types/components/style-book/index.d.ts +2 -1
- package/build-types/components/style-book/index.d.ts.map +1 -1
- package/build-types/components/template-actions-panel/block-theme-content.d.ts +2 -0
- package/build-types/components/template-actions-panel/block-theme-content.d.ts.map +1 -0
- package/build-types/components/template-actions-panel/classic-theme-content.d.ts +2 -0
- package/build-types/components/template-actions-panel/classic-theme-content.d.ts.map +1 -0
- package/build-types/components/template-actions-panel/index.d.ts +2 -0
- package/build-types/components/template-actions-panel/index.d.ts.map +1 -0
- package/build-types/dataviews/store/private-actions.d.ts.map +1 -1
- package/build-types/store/private-actions.d.ts.map +1 -1
- package/build-types/store/private-selectors.d.ts.map +1 -1
- package/package.json +45 -44
- package/src/components/collaborators-overlay/cursor-registry.ts +96 -0
- package/src/components/collaborators-overlay/index.tsx +12 -4
- package/src/components/collaborators-overlay/overlay-iframe-styles.ts +1 -1
- package/src/components/collaborators-overlay/overlay.tsx +45 -1
- package/src/components/collaborators-presence/index.tsx +9 -1
- package/src/components/collaborators-presence/list.tsx +25 -1
- package/src/components/post-card-panel/index.js +7 -21
- package/src/components/post-content-information/index.js +5 -16
- package/src/components/post-revisions-panel/index.js +151 -0
- package/src/components/post-revisions-panel/style.scss +16 -0
- package/src/components/post-revisions-preview/revisions-slider.js +29 -7
- package/src/components/post-template/create-new-template-modal.js +1 -4
- package/src/components/post-template/hooks.js +65 -9
- package/src/components/post-template/style.scss +0 -6
- package/src/components/post-template/swap-template-button.js +30 -21
- package/src/components/preferences-modal/index.js +37 -25
- package/src/components/revision-block-diff/index.js +8 -43
- package/src/components/revision-diff-panel/index.js +59 -0
- package/src/components/revision-fields-diff/index.js +91 -0
- package/src/components/sidebar/dataform-post-summary.js +8 -55
- package/src/components/sidebar/index.js +33 -22
- package/src/components/sidebar/post-revision-summary.js +50 -0
- package/src/components/sidebar/post-summary.js +22 -40
- package/src/components/sidebar/style.scss +7 -0
- package/src/components/style-book/index.js +4 -2
- package/src/components/sync-connection-error-modal/index.tsx +2 -2
- package/src/components/template-actions-panel/block-theme-content.js +196 -0
- package/src/components/template-actions-panel/classic-theme-content.js +170 -0
- package/src/components/template-actions-panel/index.js +32 -0
- package/src/components/template-actions-panel/style.scss +39 -0
- package/src/dataviews/store/private-actions.ts +6 -0
- package/src/store/private-actions.js +24 -3
- package/src/store/private-selectors.js +46 -16
- package/src/style.scss +3 -1
- /package/src/components/{revision-block-diff → revision-diff-panel}/style.scss +0 -0
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// packages/editor/src/components/post-content-information/index.js
|
|
21
21
|
var post_content_information_exports = {};
|
|
22
22
|
__export(post_content_information_exports, {
|
|
23
|
+
PostContentInformationUI: () => PostContentInformationUI,
|
|
23
24
|
default: () => PostContentInformation
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(post_content_information_exports);
|
|
@@ -30,21 +31,12 @@ var import_wordcount = require("@wordpress/wordcount");
|
|
|
30
31
|
var import_element = require("@wordpress/element");
|
|
31
32
|
var import_core_data = require("@wordpress/core-data");
|
|
32
33
|
var import_store = require("../../store/index.cjs");
|
|
33
|
-
var import_lock_unlock = require("../../lock-unlock.cjs");
|
|
34
34
|
var import_constants = require("../../store/constants.cjs");
|
|
35
35
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
36
|
var AVERAGE_READING_RATE = 189;
|
|
37
37
|
function PostContentInformation() {
|
|
38
|
-
const
|
|
38
|
+
const postContent = (0, import_data.useSelect)((select) => {
|
|
39
39
|
const { getEditedPostAttribute, getCurrentPostType, getCurrentPostId } = select(import_store.store);
|
|
40
|
-
const { getCurrentRevision, isRevisionsMode } = (0, import_lock_unlock.unlock)(
|
|
41
|
-
select(import_store.store)
|
|
42
|
-
);
|
|
43
|
-
if (isRevisionsMode()) {
|
|
44
|
-
return {
|
|
45
|
-
postContent: getCurrentRevision()?.content?.raw
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
40
|
const { canUser } = select(import_core_data.store);
|
|
49
41
|
const { getEntityRecord } = select(import_core_data.store);
|
|
50
42
|
const siteSettings = canUser("read", {
|
|
@@ -57,10 +49,11 @@ function PostContentInformation() {
|
|
|
57
49
|
const showPostContentInfo = !isPostsPage && ![import_constants.TEMPLATE_POST_TYPE, import_constants.TEMPLATE_PART_POST_TYPE].includes(
|
|
58
50
|
postType
|
|
59
51
|
);
|
|
60
|
-
return
|
|
61
|
-
postContent: showPostContentInfo && getEditedPostAttribute("content")
|
|
62
|
-
};
|
|
52
|
+
return showPostContentInfo && getEditedPostAttribute("content");
|
|
63
53
|
}, []);
|
|
54
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PostContentInformationUI, { postContent });
|
|
55
|
+
}
|
|
56
|
+
function PostContentInformationUI({ postContent }) {
|
|
64
57
|
const wordCountType = (0, import_i18n._x)("words", "Word count type. Do not translate!");
|
|
65
58
|
const wordsCounted = (0, import_element.useMemo)(
|
|
66
59
|
() => postContent ? (0, import_wordcount.count)(postContent, wordCountType) : 0,
|
|
@@ -87,4 +80,8 @@ function PostContentInformation() {
|
|
|
87
80
|
minutesText
|
|
88
81
|
) }) });
|
|
89
82
|
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
PostContentInformationUI
|
|
86
|
+
});
|
|
90
87
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/post-content-information/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __experimentalText as Text } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { __, _x, _n, sprintf } from '@wordpress/i18n';\nimport { count as wordCount } from '@wordpress/wordcount';\nimport { useMemo } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAA2C;AAC3C,kBAA0B;AAC1B,kBAAoC;AACpC,uBAAmC;AACnC,qBAAwB;AACxB,uBAAmC;AAKnC,mBAAqC;AACrC,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __experimentalText as Text } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { __, _x, _n, sprintf } from '@wordpress/i18n';\nimport { count as wordCount } from '@wordpress/wordcount';\nimport { useMemo } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport {\n\tTEMPLATE_POST_TYPE,\n\tTEMPLATE_PART_POST_TYPE,\n} from '../../store/constants';\n\n// Taken from packages/editor/src/components/time-to-read/index.js.\nconst AVERAGE_READING_RATE = 189;\n\n// This component renders the wordcount and reading time for the post.\nexport default function PostContentInformation() {\n\tconst postContent = useSelect( ( select ) => {\n\t\tconst { getEditedPostAttribute, getCurrentPostType, getCurrentPostId } =\n\t\t\tselect( editorStore );\n\t\tconst { canUser } = select( coreStore );\n\t\tconst { getEntityRecord } = select( coreStore );\n\t\tconst siteSettings = canUser( 'read', {\n\t\t\tkind: 'root',\n\t\t\tname: 'site',\n\t\t} )\n\t\t\t? getEntityRecord( 'root', 'site' )\n\t\t\t: undefined;\n\t\tconst postType = getCurrentPostType();\n\t\tconst _id = getCurrentPostId();\n\t\tconst isPostsPage = +_id === siteSettings?.page_for_posts;\n\t\tconst showPostContentInfo =\n\t\t\t! isPostsPage &&\n\t\t\t! [ TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE ].includes(\n\t\t\t\tpostType\n\t\t\t);\n\t\treturn showPostContentInfo && getEditedPostAttribute( 'content' );\n\t}, [] );\n\treturn <PostContentInformationUI postContent={ postContent } />;\n}\n\nexport function PostContentInformationUI( { postContent } ) {\n\t/*\n\t * translators: If your word count is based on single characters (e.g. East Asian characters),\n\t * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.\n\t * Do not translate into your own language.\n\t */\n\tconst wordCountType = _x( 'words', 'Word count type. Do not translate!' );\n\tconst wordsCounted = useMemo(\n\t\t() => ( postContent ? wordCount( postContent, wordCountType ) : 0 ),\n\t\t[ postContent, wordCountType ]\n\t);\n\tif ( ! wordsCounted ) {\n\t\treturn null;\n\t}\n\tconst readingTime = Math.round( wordsCounted / AVERAGE_READING_RATE );\n\tconst wordsCountText = sprintf(\n\t\t// translators: %s: the number of words in the post.\n\t\t_n( '%s word', '%s words', wordsCounted ),\n\t\twordsCounted.toLocaleString()\n\t);\n\tconst minutesText =\n\t\treadingTime <= 1\n\t\t\t? __( '1 minute' )\n\t\t\t: sprintf(\n\t\t\t\t\t/* translators: %s: the number of minutes to read the post. */\n\t\t\t\t\t_n( '%s minute', '%s minutes', readingTime ),\n\t\t\t\t\treadingTime.toLocaleString()\n\t\t\t );\n\treturn (\n\t\t<div className=\"editor-post-content-information\">\n\t\t\t<Text>\n\t\t\t\t{ sprintf(\n\t\t\t\t\t/* translators: 1: How many words a post has. 2: the number of minutes to read the post (e.g. 130 words, 2 minutes read time.) */\n\t\t\t\t\t__( '%1$s, %2$s read time.' ),\n\t\t\t\t\twordsCountText,\n\t\t\t\t\tminutesText\n\t\t\t\t) }\n\t\t\t</Text>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAA2C;AAC3C,kBAA0B;AAC1B,kBAAoC;AACpC,uBAAmC;AACnC,qBAAwB;AACxB,uBAAmC;AAKnC,mBAAqC;AACrC,uBAGO;AA4BC;AAzBR,IAAM,uBAAuB;AAGd,SAAR,yBAA0C;AAChD,QAAM,kBAAc,uBAAW,CAAE,WAAY;AAC5C,UAAM,EAAE,wBAAwB,oBAAoB,iBAAiB,IACpE,OAAQ,aAAAA,KAAY;AACrB,UAAM,EAAE,QAAQ,IAAI,OAAQ,iBAAAC,KAAU;AACtC,UAAM,EAAE,gBAAgB,IAAI,OAAQ,iBAAAA,KAAU;AAC9C,UAAM,eAAe,QAAS,QAAQ;AAAA,MACrC,MAAM;AAAA,MACN,MAAM;AAAA,IACP,CAAE,IACC,gBAAiB,QAAQ,MAAO,IAChC;AACH,UAAM,WAAW,mBAAmB;AACpC,UAAM,MAAM,iBAAiB;AAC7B,UAAM,cAAc,CAAC,QAAQ,cAAc;AAC3C,UAAM,sBACL,CAAE,eACF,CAAE,CAAE,qCAAoB,wCAAwB,EAAE;AAAA,MACjD;AAAA,IACD;AACD,WAAO,uBAAuB,uBAAwB,SAAU;AAAA,EACjE,GAAG,CAAC,CAAE;AACN,SAAO,4CAAC,4BAAyB,aAA4B;AAC9D;AAEO,SAAS,yBAA0B,EAAE,YAAY,GAAI;AAM3D,QAAM,oBAAgB,gBAAI,SAAS,oCAAqC;AACxE,QAAM,mBAAe;AAAA,IACpB,MAAQ,kBAAc,iBAAAC,OAAW,aAAa,aAAc,IAAI;AAAA,IAChE,CAAE,aAAa,aAAc;AAAA,EAC9B;AACA,MAAK,CAAE,cAAe;AACrB,WAAO;AAAA,EACR;AACA,QAAM,cAAc,KAAK,MAAO,eAAe,oBAAqB;AACpE,QAAM,qBAAiB;AAAA;AAAA,QAEtB,gBAAI,WAAW,YAAY,YAAa;AAAA,IACxC,aAAa,eAAe;AAAA,EAC7B;AACA,QAAM,cACL,eAAe,QACZ,gBAAI,UAAW,QACf;AAAA;AAAA,QAEA,gBAAI,aAAa,cAAc,WAAY;AAAA,IAC3C,YAAY,eAAe;AAAA,EAC3B;AACJ,SACC,4CAAC,SAAI,WAAU,mCACd,sDAAC,kBAAAC,oBAAA,EACE;AAAA;AAAA,QAED,gBAAI,uBAAwB;AAAA,IAC5B;AAAA,IACA;AAAA,EACD,GACD,GACD;AAEF;",
|
|
6
6
|
"names": ["editorStore", "coreStore", "wordCount", "Text"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/editor/src/components/post-revisions-panel/index.js
|
|
31
|
+
var post_revisions_panel_exports = {};
|
|
32
|
+
__export(post_revisions_panel_exports, {
|
|
33
|
+
default: () => PostRevisionsPanel
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(post_revisions_panel_exports);
|
|
36
|
+
var import_components = require("@wordpress/components");
|
|
37
|
+
var import_core_data = require("@wordpress/core-data");
|
|
38
|
+
var import_dataviews = require("@wordpress/dataviews");
|
|
39
|
+
var import_date = require("@wordpress/date");
|
|
40
|
+
var import_data = require("@wordpress/data");
|
|
41
|
+
var import_i18n = require("@wordpress/i18n");
|
|
42
|
+
var import_fields = require("@wordpress/fields");
|
|
43
|
+
var import_check = __toESM(require("../post-last-revision/check.cjs"));
|
|
44
|
+
var import_store = require("../../store/index.cjs");
|
|
45
|
+
var import_lock_unlock = require("../../lock-unlock.cjs");
|
|
46
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
47
|
+
var { Badge } = (0, import_lock_unlock.unlock)(import_components.privateApis);
|
|
48
|
+
var DAY_IN_MILLISECONDS = 864e5;
|
|
49
|
+
var EMPTY_ARRAY = [];
|
|
50
|
+
var REVISIONS_QUERY = {
|
|
51
|
+
per_page: 3,
|
|
52
|
+
orderby: "date",
|
|
53
|
+
order: "desc",
|
|
54
|
+
context: "embed",
|
|
55
|
+
_fields: "id,date,author"
|
|
56
|
+
};
|
|
57
|
+
var defaultLayouts = { activity: {} };
|
|
58
|
+
var view = {
|
|
59
|
+
type: "activity",
|
|
60
|
+
titleField: "date",
|
|
61
|
+
fields: ["author"],
|
|
62
|
+
layout: {
|
|
63
|
+
density: "compact"
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var fields = [
|
|
67
|
+
{
|
|
68
|
+
id: "date",
|
|
69
|
+
label: (0, import_i18n.__)("Date"),
|
|
70
|
+
render: ({ item }) => {
|
|
71
|
+
const dateNowInMs = (0, import_date.getDate)(null).getTime();
|
|
72
|
+
const date = (0, import_date.getDate)(item.date ?? null);
|
|
73
|
+
const displayDate = dateNowInMs - date.getTime() > DAY_IN_MILLISECONDS ? (0, import_date.dateI18n)(
|
|
74
|
+
(0, import_date.getSettings)().formats.datetimeAbbreviated,
|
|
75
|
+
date
|
|
76
|
+
) : (0, import_date.humanTimeDiff)(date);
|
|
77
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
78
|
+
"time",
|
|
79
|
+
{
|
|
80
|
+
className: "editor-post-revisions-panel__revision-date",
|
|
81
|
+
dateTime: item.date,
|
|
82
|
+
children: displayDate
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
},
|
|
86
|
+
enableSorting: false,
|
|
87
|
+
enableHiding: false
|
|
88
|
+
},
|
|
89
|
+
import_fields.authorField
|
|
90
|
+
];
|
|
91
|
+
var noop = () => {
|
|
92
|
+
};
|
|
93
|
+
var paginationInfo = {};
|
|
94
|
+
function PostRevisionsPanelContent() {
|
|
95
|
+
const { setCurrentRevisionId } = (0, import_lock_unlock.unlock)((0, import_data.useDispatch)(import_store.store));
|
|
96
|
+
const { revisionsCount, revisions, isLoading, lastRevisionId } = (0, import_data.useSelect)(
|
|
97
|
+
(select) => {
|
|
98
|
+
const { getCurrentPostId, getCurrentPostType } = select(import_store.store);
|
|
99
|
+
const {
|
|
100
|
+
getCurrentPostRevisionsCount,
|
|
101
|
+
getCurrentPostLastRevisionId
|
|
102
|
+
} = select(import_store.store);
|
|
103
|
+
const { getRevisions, isResolving } = select(import_core_data.store);
|
|
104
|
+
const query = [
|
|
105
|
+
"postType",
|
|
106
|
+
getCurrentPostType(),
|
|
107
|
+
getCurrentPostId(),
|
|
108
|
+
REVISIONS_QUERY
|
|
109
|
+
];
|
|
110
|
+
const _revisions = getRevisions(...query);
|
|
111
|
+
return {
|
|
112
|
+
revisionsCount: getCurrentPostRevisionsCount(),
|
|
113
|
+
lastRevisionId: getCurrentPostLastRevisionId(),
|
|
114
|
+
revisions: _revisions,
|
|
115
|
+
isLoading: isResolving("getRevisions", query)
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
[]
|
|
119
|
+
);
|
|
120
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
121
|
+
import_components.PanelBody,
|
|
122
|
+
{
|
|
123
|
+
title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { justify: "space-between", align: "center", as: "span", children: [
|
|
124
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: (0, import_i18n.__)("Revisions") }),
|
|
125
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { className: "editor-post-revisions-panel__revisions-count", children: revisionsCount })
|
|
126
|
+
] }),
|
|
127
|
+
initialOpen: false,
|
|
128
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { className: "editor-post-revisions-panel", children: [
|
|
129
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
130
|
+
import_dataviews.DataViews,
|
|
131
|
+
{
|
|
132
|
+
view,
|
|
133
|
+
onChangeView: noop,
|
|
134
|
+
fields,
|
|
135
|
+
data: revisions || EMPTY_ARRAY,
|
|
136
|
+
isLoading,
|
|
137
|
+
paginationInfo,
|
|
138
|
+
defaultLayouts,
|
|
139
|
+
getItemId: (item) => item.id,
|
|
140
|
+
isItemClickable: () => true,
|
|
141
|
+
onClickItem: (item) => {
|
|
142
|
+
setCurrentRevisionId(item.id);
|
|
143
|
+
},
|
|
144
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dataviews.DataViews.Layout, {})
|
|
145
|
+
}
|
|
146
|
+
),
|
|
147
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
148
|
+
import_components.Button,
|
|
149
|
+
{
|
|
150
|
+
className: "editor-post-revisions-panel__view-all",
|
|
151
|
+
__next40pxDefaultSize: true,
|
|
152
|
+
variant: "secondary",
|
|
153
|
+
onClick: () => setCurrentRevisionId(lastRevisionId),
|
|
154
|
+
children: (0, import_i18n.__)("View all revisions")
|
|
155
|
+
}
|
|
156
|
+
)
|
|
157
|
+
] })
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
function PostRevisionsPanel() {
|
|
162
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_check.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PostRevisionsPanelContent, {}) });
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/post-revisions-panel/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tPanelBody,\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { DataViews } from '@wordpress/dataviews';\nimport { dateI18n, getDate, humanTimeDiff, getSettings } from '@wordpress/date';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { authorField } from '@wordpress/fields';\n\n/**\n * Internal dependencies\n */\nimport PostLastRevisionCheck from '../post-last-revision/check';\nimport { store as editorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { Badge } = unlock( componentsPrivateApis );\nconst DAY_IN_MILLISECONDS = 86400000;\nconst EMPTY_ARRAY = [];\n\nconst REVISIONS_QUERY = {\n\tper_page: 3,\n\torderby: 'date',\n\torder: 'desc',\n\tcontext: 'embed',\n\t_fields: 'id,date,author',\n};\nconst defaultLayouts = { activity: {} };\nconst view = {\n\ttype: 'activity',\n\ttitleField: 'date',\n\tfields: [ 'author' ],\n\tlayout: {\n\t\tdensity: 'compact',\n\t},\n};\nconst fields = [\n\t{\n\t\tid: 'date',\n\t\tlabel: __( 'Date' ),\n\t\trender: ( { item } ) => {\n\t\t\tconst dateNowInMs = getDate( null ).getTime();\n\t\t\tconst date = getDate( item.date ?? null );\n\t\t\tconst displayDate =\n\t\t\t\tdateNowInMs - date.getTime() > DAY_IN_MILLISECONDS\n\t\t\t\t\t? dateI18n(\n\t\t\t\t\t\t\tgetSettings().formats.datetimeAbbreviated,\n\t\t\t\t\t\t\tdate\n\t\t\t\t\t )\n\t\t\t\t\t: humanTimeDiff( date );\n\t\t\treturn (\n\t\t\t\t<time\n\t\t\t\t\tclassName=\"editor-post-revisions-panel__revision-date\"\n\t\t\t\t\tdateTime={ item.date }\n\t\t\t\t>\n\t\t\t\t\t{ displayDate }\n\t\t\t\t</time>\n\t\t\t);\n\t\t},\n\t\tenableSorting: false,\n\t\tenableHiding: false,\n\t},\n\tauthorField,\n];\nconst noop = () => {};\nconst paginationInfo = {};\n\nfunction PostRevisionsPanelContent() {\n\tconst { setCurrentRevisionId } = unlock( useDispatch( editorStore ) );\n\tconst { revisionsCount, revisions, isLoading, lastRevisionId } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentPostId, getCurrentPostType } =\n\t\t\t\tselect( editorStore );\n\t\t\tconst {\n\t\t\t\tgetCurrentPostRevisionsCount,\n\t\t\t\tgetCurrentPostLastRevisionId,\n\t\t\t} = select( editorStore );\n\t\t\tconst { getRevisions, isResolving } = select( coreStore );\n\t\t\tconst query = [\n\t\t\t\t'postType',\n\t\t\t\tgetCurrentPostType(),\n\t\t\t\tgetCurrentPostId(),\n\t\t\t\tREVISIONS_QUERY,\n\t\t\t];\n\t\t\tconst _revisions = getRevisions( ...query );\n\t\t\treturn {\n\t\t\t\trevisionsCount: getCurrentPostRevisionsCount(),\n\t\t\t\tlastRevisionId: getCurrentPostLastRevisionId(),\n\t\t\t\trevisions: _revisions,\n\t\t\t\tisLoading: isResolving( 'getRevisions', query ),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\treturn (\n\t\t<PanelBody\n\t\t\ttitle={\n\t\t\t\t<HStack justify=\"space-between\" align=\"center\" as=\"span\">\n\t\t\t\t\t<span>{ __( 'Revisions' ) }</span>\n\t\t\t\t\t<Badge className=\"editor-post-revisions-panel__revisions-count\">\n\t\t\t\t\t\t{ revisionsCount }\n\t\t\t\t\t</Badge>\n\t\t\t\t</HStack>\n\t\t\t}\n\t\t\tinitialOpen={ false }\n\t\t>\n\t\t\t<VStack className=\"editor-post-revisions-panel\">\n\t\t\t\t<DataViews\n\t\t\t\t\tview={ view }\n\t\t\t\t\tonChangeView={ noop }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tdata={ revisions || EMPTY_ARRAY }\n\t\t\t\t\tisLoading={ isLoading }\n\t\t\t\t\tpaginationInfo={ paginationInfo }\n\t\t\t\t\tdefaultLayouts={ defaultLayouts }\n\t\t\t\t\tgetItemId={ ( item ) => item.id }\n\t\t\t\t\tisItemClickable={ () => true }\n\t\t\t\t\tonClickItem={ ( item ) => {\n\t\t\t\t\t\tsetCurrentRevisionId( item.id );\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<DataViews.Layout />\n\t\t\t\t</DataViews>\n\t\t\t\t<Button\n\t\t\t\t\tclassName=\"editor-post-revisions-panel__view-all\"\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\tonClick={ () => setCurrentRevisionId( lastRevisionId ) }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'View all revisions' ) }\n\t\t\t\t</Button>\n\t\t\t</VStack>\n\t\t</PanelBody>\n\t);\n}\n\nexport default function PostRevisionsPanel() {\n\treturn (\n\t\t<PostLastRevisionCheck>\n\t\t\t<PostRevisionsPanelContent />\n\t\t</PostLastRevisionCheck>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAMO;AACP,uBAAmC;AACnC,uBAA0B;AAC1B,kBAA8D;AAC9D,kBAAuC;AACvC,kBAAmB;AACnB,oBAA4B;AAK5B,mBAAkC;AAClC,mBAAqC;AACrC,yBAAuB;AAqCnB;AAnCJ,IAAM,EAAE,MAAM,QAAI,2BAAQ,kBAAAA,WAAsB;AAChD,IAAM,sBAAsB;AAC5B,IAAM,cAAc,CAAC;AAErB,IAAM,kBAAkB;AAAA,EACvB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS;AACV;AACA,IAAM,iBAAiB,EAAE,UAAU,CAAC,EAAE;AACtC,IAAM,OAAO;AAAA,EACZ,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,QAAQ,CAAE,QAAS;AAAA,EACnB,QAAQ;AAAA,IACP,SAAS;AAAA,EACV;AACD;AACA,IAAM,SAAS;AAAA,EACd;AAAA,IACC,IAAI;AAAA,IACJ,WAAO,gBAAI,MAAO;AAAA,IAClB,QAAQ,CAAE,EAAE,KAAK,MAAO;AACvB,YAAM,kBAAc,qBAAS,IAAK,EAAE,QAAQ;AAC5C,YAAM,WAAO,qBAAS,KAAK,QAAQ,IAAK;AACxC,YAAM,cACL,cAAc,KAAK,QAAQ,IAAI,0BAC5B;AAAA,YACA,yBAAY,EAAE,QAAQ;AAAA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AAAA,YACA,cAAe;AAAA,YACf;AAAA,YACA,MAAO,aAAa;AAAA,YACpB;AAAA,YACA;AAAA,YACA;AAAA,YACA,WAAY,CAAE,SAAU,KAAK;AAAA,YAC7B,iBAAkB,MAAM;AAAA,YACxB,aAAc,CAAE,SAAU;AACzB,mCAAsB,KAAK,EAAG;AAAA,YAC/B;AAAA,YAEA,sDAAC,2BAAU,QAAV,EAAiB;AAAA;AAAA,QACnB;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,uBAAqB;AAAA,YACrB,SAAQ;AAAA,YACR,SAAU,MAAM,qBAAsB,cAAe;AAAA,YAEnD,8BAAI,oBAAqB;AAAA;AAAA,QAC5B;AAAA,SACD;AAAA;AAAA,EACD;AAEF;AAEe,SAAR,qBAAsC;AAC5C,SACC,4CAAC,aAAAC,SAAA,EACA,sDAAC,6BAA0B,GAC5B;AAEF;",
|
|
6
|
+
"names": ["componentsPrivateApis", "editorStore", "coreStore", "HStack", "VStack", "PostLastRevisionCheck"]
|
|
7
|
+
}
|
|
@@ -43,10 +43,23 @@ function RevisionsSlider() {
|
|
|
43
43
|
return {};
|
|
44
44
|
}
|
|
45
45
|
const entityConfig = getEntityConfig("postType", postType);
|
|
46
|
+
const _revisionKey = entityConfig?.revisionKey || "id";
|
|
46
47
|
const query = {
|
|
47
48
|
per_page: -1,
|
|
48
49
|
context: "edit",
|
|
49
|
-
_fields:
|
|
50
|
+
_fields: [
|
|
51
|
+
.../* @__PURE__ */ new Set([
|
|
52
|
+
"id",
|
|
53
|
+
"date",
|
|
54
|
+
"modified",
|
|
55
|
+
"author",
|
|
56
|
+
"meta",
|
|
57
|
+
"title.raw",
|
|
58
|
+
"excerpt.raw",
|
|
59
|
+
"content.raw",
|
|
60
|
+
_revisionKey
|
|
61
|
+
])
|
|
62
|
+
].join()
|
|
50
63
|
};
|
|
51
64
|
return {
|
|
52
65
|
revisions: getRevisions("postType", postType, postId, query),
|
|
@@ -59,15 +72,18 @@ function RevisionsSlider() {
|
|
|
59
72
|
currentRevisionId: (0, import_lock_unlock.unlock)(
|
|
60
73
|
select(import_store.store)
|
|
61
74
|
).getCurrentRevisionId(),
|
|
62
|
-
revisionKey:
|
|
75
|
+
revisionKey: _revisionKey
|
|
63
76
|
};
|
|
64
77
|
},
|
|
65
78
|
[]
|
|
66
79
|
);
|
|
67
80
|
const { setCurrentRevisionId } = (0, import_lock_unlock.unlock)((0, import_data.useDispatch)(import_store.store));
|
|
81
|
+
const revisionDateField = revisionKey === "wp_id" ? "modified" : "date";
|
|
68
82
|
const sortedRevisions = (0, import_element.useMemo)(() => {
|
|
69
|
-
return revisions?.slice().sort(
|
|
70
|
-
|
|
83
|
+
return revisions?.slice().sort(
|
|
84
|
+
(a, b) => new Date(a[revisionDateField]) - new Date(b[revisionDateField])
|
|
85
|
+
) ?? [];
|
|
86
|
+
}, [revisions, revisionDateField]);
|
|
71
87
|
const selectedIndex = sortedRevisions.findIndex(
|
|
72
88
|
(r) => r[revisionKey] === currentRevisionId
|
|
73
89
|
);
|
|
@@ -83,7 +99,10 @@ function RevisionsSlider() {
|
|
|
83
99
|
if (!revision) {
|
|
84
100
|
return index;
|
|
85
101
|
}
|
|
86
|
-
return (0, import_date.dateI18n)(
|
|
102
|
+
return (0, import_date.dateI18n)(
|
|
103
|
+
dateSettings.formats.datetime,
|
|
104
|
+
revision[revisionDateField]
|
|
105
|
+
);
|
|
87
106
|
};
|
|
88
107
|
if (isLoading) {
|
|
89
108
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Spinner, {});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/post-revisions-preview/revisions-slider.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { RangeControl, Spinner } from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { dateI18n, getSettings as getDateSettings } from '@wordpress/date';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Slider component for navigating revisions.\n *\n * @return {React.JSX.Element} The revisions slider component.\n */\nfunction RevisionsSlider() {\n\tconst { revisions, isLoading, currentRevisionId, revisionKey } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentPostId, getCurrentPostType } =\n\t\t\t\tselect( editorStore );\n\t\t\tconst { getRevisions, isResolving, getEntityConfig } =\n\t\t\t\tselect( coreStore );\n\n\t\t\tconst postId = getCurrentPostId();\n\t\t\tconst postType = getCurrentPostType();\n\n\t\t\tif ( ! postId || ! postType ) {\n\t\t\t\treturn {};\n\t\t\t}\n\n\t\t\tconst entityConfig = getEntityConfig( 'postType', postType );\n\t\t\tconst query = {\n\t\t\t\tper_page: -1,\n\t\t\t\tcontext: 'edit',\n\t\t\t\t_fields
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAwB;AACxB,kBAAuC;AACvC,wBAAsC;AACtC,uBAAmC;AACnC,kBAAmB;AACnB,kBAAyD;AAKzD,mBAAqC;AACrC,yBAAuB;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { RangeControl, Spinner } from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { dateI18n, getSettings as getDateSettings } from '@wordpress/date';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Slider component for navigating revisions.\n *\n * @return {React.JSX.Element} The revisions slider component.\n */\nfunction RevisionsSlider() {\n\tconst { revisions, isLoading, currentRevisionId, revisionKey } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentPostId, getCurrentPostType } =\n\t\t\t\tselect( editorStore );\n\t\t\tconst { getRevisions, isResolving, getEntityConfig } =\n\t\t\t\tselect( coreStore );\n\n\t\t\tconst postId = getCurrentPostId();\n\t\t\tconst postType = getCurrentPostType();\n\n\t\t\tif ( ! postId || ! postType ) {\n\t\t\t\treturn {};\n\t\t\t}\n\n\t\t\tconst entityConfig = getEntityConfig( 'postType', postType );\n\t\t\tconst _revisionKey = entityConfig?.revisionKey || 'id';\n\t\t\tconst query = {\n\t\t\t\tper_page: -1,\n\t\t\t\tcontext: 'edit',\n\t\t\t\t_fields: [\n\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t'id',\n\t\t\t\t\t\t'date',\n\t\t\t\t\t\t'modified',\n\t\t\t\t\t\t'author',\n\t\t\t\t\t\t'meta',\n\t\t\t\t\t\t'title.raw',\n\t\t\t\t\t\t'excerpt.raw',\n\t\t\t\t\t\t'content.raw',\n\t\t\t\t\t\t_revisionKey,\n\t\t\t\t\t] ),\n\t\t\t\t].join(),\n\t\t\t};\n\t\t\treturn {\n\t\t\t\trevisions: getRevisions( 'postType', postType, postId, query ),\n\t\t\t\tisLoading: isResolving( 'getRevisions', [\n\t\t\t\t\t'postType',\n\t\t\t\t\tpostType,\n\t\t\t\t\tpostId,\n\t\t\t\t\tquery,\n\t\t\t\t] ),\n\t\t\t\tcurrentRevisionId: unlock(\n\t\t\t\t\tselect( editorStore )\n\t\t\t\t).getCurrentRevisionId(),\n\t\t\t\trevisionKey: _revisionKey,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { setCurrentRevisionId } = unlock( useDispatch( editorStore ) );\n\n\t// Template revisions use the template REST API format, which exposes\n\t// 'modified' instead of 'date'.\n\tconst revisionDateField = revisionKey === 'wp_id' ? 'modified' : 'date';\n\n\tconst sortedRevisions = useMemo( () => {\n\t\treturn (\n\t\t\trevisions\n\t\t\t\t?.slice()\n\t\t\t\t.sort(\n\t\t\t\t\t( a, b ) =>\n\t\t\t\t\t\tnew Date( a[ revisionDateField ] ) -\n\t\t\t\t\t\tnew Date( b[ revisionDateField ] )\n\t\t\t\t) ?? []\n\t\t);\n\t}, [ revisions, revisionDateField ] );\n\n\tconst selectedIndex = sortedRevisions.findIndex(\n\t\t( r ) => r[ revisionKey ] === currentRevisionId\n\t);\n\n\tconst handleSliderChange = ( index ) => {\n\t\tconst revision = sortedRevisions[ index ];\n\t\tif ( revision ) {\n\t\t\tsetCurrentRevisionId( revision[ revisionKey ] );\n\t\t}\n\t};\n\n\t// Format date for tooltip.\n\tconst dateSettings = getDateSettings();\n\tconst renderTooltipContent = ( index ) => {\n\t\tconst revision = sortedRevisions[ index ];\n\t\tif ( ! revision ) {\n\t\t\treturn index;\n\t\t}\n\t\treturn dateI18n(\n\t\t\tdateSettings.formats.datetime,\n\t\t\trevision[ revisionDateField ]\n\t\t);\n\t};\n\n\tif ( isLoading ) {\n\t\treturn <Spinner />;\n\t}\n\n\tif ( ! sortedRevisions.length ) {\n\t\treturn (\n\t\t\t<span className=\"editor-revisions-header__no-revisions\">\n\t\t\t\t{ __( 'No revisions found.' ) }\n\t\t\t</span>\n\t\t);\n\t}\n\n\tif ( sortedRevisions.length === 1 ) {\n\t\treturn (\n\t\t\t<span className=\"editor-revisions-header__no-revisions\">\n\t\t\t\t{ __( 'Only one revision found.' ) }\n\t\t\t</span>\n\t\t);\n\t}\n\n\treturn (\n\t\t<RangeControl\n\t\t\t__next40pxDefaultSize\n\t\t\tclassName=\"editor-revisions-header__slider\"\n\t\t\thideLabelFromVision\n\t\t\tlabel={ __( 'Revision' ) }\n\t\t\tmax={ sortedRevisions.length - 1 }\n\t\t\tmin={ 0 }\n\t\t\tmarks\n\t\t\tonChange={ handleSliderChange }\n\t\t\trenderTooltipContent={ renderTooltipContent }\n\t\t\tvalue={ selectedIndex }\n\t\t\twithInputField={ false }\n\t\t/>\n\t);\n}\n\nexport default RevisionsSlider;\n"],
|
|
5
|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AA;AAAA,EAClB;AAEF;AAEA,IAAO,2BAAQ;",
|
|
6
6
|
"names": ["editorStore", "coreStore", "getDateSettings"]
|
|
7
7
|
}
|
|
@@ -110,52 +110,45 @@ function CreateNewTemplateModal({ onClose }) {
|
|
|
110
110
|
focusOnMount: "firstContentElement",
|
|
111
111
|
size: "small",
|
|
112
112
|
overlayClassName: "editor-post-template__create-template-modal",
|
|
113
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
children: (0, import_i18n.__)("Create")
|
|
153
|
-
}
|
|
154
|
-
)
|
|
155
|
-
] })
|
|
156
|
-
] })
|
|
157
|
-
}
|
|
158
|
-
)
|
|
113
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("form", { onSubmit: submit, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: "3", children: [
|
|
114
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
115
|
+
import_components.TextControl,
|
|
116
|
+
{
|
|
117
|
+
__next40pxDefaultSize: true,
|
|
118
|
+
label: (0, import_i18n.__)("Name"),
|
|
119
|
+
value: title,
|
|
120
|
+
onChange: setTitle,
|
|
121
|
+
placeholder: DEFAULT_TITLE,
|
|
122
|
+
disabled: isBusy,
|
|
123
|
+
help: (0, import_i18n.__)(
|
|
124
|
+
// eslint-disable-next-line no-restricted-syntax -- 'sidebar' is a common web design term for layouts
|
|
125
|
+
'Describe the template, e.g. "Post with sidebar". A custom template can be manually applied to any post or page.'
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
),
|
|
129
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { justify: "right", children: [
|
|
130
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
131
|
+
import_components.Button,
|
|
132
|
+
{
|
|
133
|
+
__next40pxDefaultSize: true,
|
|
134
|
+
variant: "tertiary",
|
|
135
|
+
onClick: cancel,
|
|
136
|
+
children: (0, import_i18n.__)("Cancel")
|
|
137
|
+
}
|
|
138
|
+
),
|
|
139
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
140
|
+
import_components.Button,
|
|
141
|
+
{
|
|
142
|
+
__next40pxDefaultSize: true,
|
|
143
|
+
variant: "primary",
|
|
144
|
+
type: "submit",
|
|
145
|
+
isBusy,
|
|
146
|
+
"aria-disabled": isBusy,
|
|
147
|
+
children: (0, import_i18n.__)("Create")
|
|
148
|
+
}
|
|
149
|
+
)
|
|
150
|
+
] })
|
|
151
|
+
] }) })
|
|
159
152
|
}
|
|
160
153
|
);
|
|
161
154
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/post-template/create-new-template-modal.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { serialize, createBlock } from '@wordpress/blocks';\nimport {\n\tModal,\n\tTextControl,\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport { store as editorStore } from '../../store';\n\nconst DEFAULT_TITLE = __( 'Custom Template' );\n\nexport default function CreateNewTemplateModal( { onClose } ) {\n\tconst { defaultBlockTemplate, onNavigateToEntityRecord } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditorSettings, getCurrentTemplateId } =\n\t\t\t\tselect( editorStore );\n\t\t\treturn {\n\t\t\t\tdefaultBlockTemplate: getEditorSettings().defaultBlockTemplate,\n\t\t\t\tonNavigateToEntityRecord:\n\t\t\t\t\tgetEditorSettings().onNavigateToEntityRecord,\n\t\t\t\tgetTemplateId: getCurrentTemplateId,\n\t\t\t};\n\t\t}\n\t);\n\n\tconst { createTemplate } = unlock( useDispatch( editorStore ) );\n\n\tconst [ title, setTitle ] = useState( '' );\n\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\n\tconst cancel = () => {\n\t\tsetTitle( '' );\n\t\tonClose();\n\t};\n\n\tconst submit = async ( event ) => {\n\t\tevent.preventDefault();\n\n\t\tif ( isBusy ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsBusy( true );\n\n\t\tconst newTemplateContent =\n\t\t\tdefaultBlockTemplate ??\n\t\t\tserialize( [\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/group',\n\t\t\t\t\t{\n\t\t\t\t\t\ttagName: 'header',\n\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock( 'core/site-title' ),\n\t\t\t\t\t\tcreateBlock( 'core/site-tagline' ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t\tcreateBlock( 'core/separator' ),\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/group',\n\t\t\t\t\t{\n\t\t\t\t\t\ttagName: 'main',\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t'core/group',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t[ createBlock( 'core/post-title' ) ]\n\t\t\t\t\t\t),\n\t\t\t\t\t\tcreateBlock( 'core/post-content', {\n\t\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t\t} ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t] );\n\n\t\tconst newTemplate = await createTemplate( {\n\t\t\tslug: kebabCase( title || DEFAULT_TITLE ) || 'wp-custom-template',\n\t\t\tcontent: newTemplateContent,\n\t\t\ttitle: title || DEFAULT_TITLE,\n\t\t\tstatus: 'publish',\n\t\t} );\n\n\t\tsetIsBusy( false );\n\t\tonNavigateToEntityRecord( {\n\t\t\tpostId: newTemplate.id,\n\t\t\tpostType: 'wp_template',\n\t\t} );\n\t\tcancel();\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Create custom template' ) }\n\t\t\tonRequestClose={ cancel }\n\t\t\tfocusOnMount=\"firstContentElement\"\n\t\t\tsize=\"small\"\n\t\t\toverlayClassName=\"editor-post-template__create-template-modal\"\n\t\t>\n\t\t\t<form
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAuC;AAKvC,kBAAuC;AACvC,qBAAyB;AACzB,oBAAuC;AACvC,wBAMO;AACP,kBAAmB;AAKnB,yBAAuB;AACvB,mBAAqC;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { serialize, createBlock } from '@wordpress/blocks';\nimport {\n\tModal,\n\tTextControl,\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport { store as editorStore } from '../../store';\n\nconst DEFAULT_TITLE = __( 'Custom Template' );\n\nexport default function CreateNewTemplateModal( { onClose } ) {\n\tconst { defaultBlockTemplate, onNavigateToEntityRecord } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditorSettings, getCurrentTemplateId } =\n\t\t\t\tselect( editorStore );\n\t\t\treturn {\n\t\t\t\tdefaultBlockTemplate: getEditorSettings().defaultBlockTemplate,\n\t\t\t\tonNavigateToEntityRecord:\n\t\t\t\t\tgetEditorSettings().onNavigateToEntityRecord,\n\t\t\t\tgetTemplateId: getCurrentTemplateId,\n\t\t\t};\n\t\t}\n\t);\n\n\tconst { createTemplate } = unlock( useDispatch( editorStore ) );\n\n\tconst [ title, setTitle ] = useState( '' );\n\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\n\tconst cancel = () => {\n\t\tsetTitle( '' );\n\t\tonClose();\n\t};\n\n\tconst submit = async ( event ) => {\n\t\tevent.preventDefault();\n\n\t\tif ( isBusy ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsBusy( true );\n\n\t\tconst newTemplateContent =\n\t\t\tdefaultBlockTemplate ??\n\t\t\tserialize( [\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/group',\n\t\t\t\t\t{\n\t\t\t\t\t\ttagName: 'header',\n\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock( 'core/site-title' ),\n\t\t\t\t\t\tcreateBlock( 'core/site-tagline' ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t\tcreateBlock( 'core/separator' ),\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/group',\n\t\t\t\t\t{\n\t\t\t\t\t\ttagName: 'main',\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t'core/group',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t[ createBlock( 'core/post-title' ) ]\n\t\t\t\t\t\t),\n\t\t\t\t\t\tcreateBlock( 'core/post-content', {\n\t\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t\t} ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t] );\n\n\t\tconst newTemplate = await createTemplate( {\n\t\t\tslug: kebabCase( title || DEFAULT_TITLE ) || 'wp-custom-template',\n\t\t\tcontent: newTemplateContent,\n\t\t\ttitle: title || DEFAULT_TITLE,\n\t\t\tstatus: 'publish',\n\t\t} );\n\n\t\tsetIsBusy( false );\n\t\tonNavigateToEntityRecord( {\n\t\t\tpostId: newTemplate.id,\n\t\t\tpostType: 'wp_template',\n\t\t} );\n\t\tcancel();\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Create custom template' ) }\n\t\t\tonRequestClose={ cancel }\n\t\t\tfocusOnMount=\"firstContentElement\"\n\t\t\tsize=\"small\"\n\t\t\toverlayClassName=\"editor-post-template__create-template-modal\"\n\t\t>\n\t\t\t<form onSubmit={ submit }>\n\t\t\t\t<VStack spacing=\"3\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ DEFAULT_TITLE }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t// eslint-disable-next-line no-restricted-syntax -- 'sidebar' is a common web design term for layouts\n\t\t\t\t\t\t\t'Describe the template, e.g. \"Post with sidebar\". A custom template can be manually applied to any post or page.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ cancel }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\t\taria-disabled={ isBusy }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAuC;AAKvC,kBAAuC;AACvC,qBAAyB;AACzB,oBAAuC;AACvC,wBAMO;AACP,kBAAmB;AAKnB,yBAAuB;AACvB,mBAAqC;AAkGhC;AAhGL,IAAM,oBAAgB,gBAAI,iBAAkB;AAE7B,SAAR,uBAAyC,EAAE,QAAQ,GAAI;AAC7D,QAAM,EAAE,sBAAsB,yBAAyB,QAAI;AAAA,IAC1D,CAAE,WAAY;AACb,YAAM,EAAE,mBAAmB,qBAAqB,IAC/C,OAAQ,aAAAA,KAAY;AACrB,aAAO;AAAA,QACN,sBAAsB,kBAAkB,EAAE;AAAA,QAC1C,0BACC,kBAAkB,EAAE;AAAA,QACrB,eAAe;AAAA,MAChB;AAAA,IACD;AAAA,EACD;AAEA,QAAM,EAAE,eAAe,QAAI,+BAAQ,yBAAa,aAAAA,KAAY,CAAE;AAE9D,QAAM,CAAE,OAAO,QAAS,QAAI,yBAAU,EAAG;AAEzC,QAAM,CAAE,QAAQ,SAAU,QAAI,yBAAU,KAAM;AAE9C,QAAM,SAAS,MAA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AA,YACA,uBAAqB;AAAA,YACrB,WAAQ,gBAAI,MAAO;AAAA,YACnB,OAAQ;AAAA,YACR,UAAW;AAAA,YACX,aAAc;AAAA,YACd,UAAW;AAAA,YACX,UAAO;AAAA;AAAA,cAEN;AAAA,YACD;AAAA;AAAA,QACD;AAAA,QACA,6CAAC,kBAAAC,sBAAA,EAAO,SAAQ,SACf;AAAA;AAAA,YAAC;AAAA;AAAA,cACA,uBAAqB;AAAA,cACrB,SAAQ;AAAA,cACR,SAAU;AAAA,cAER,8BAAI,QAAS;AAAA;AAAA,UAChB;AAAA,UAEA;AAAA,YAAC;AAAA;AAAA,cACA,uBAAqB;AAAA,cACrB,SAAQ;AAAA,cACR,MAAK;AAAA,cACL;AAAA,cACA,iBAAgB;AAAA,cAEd,8BAAI,QAAS;AAAA;AAAA,UAChB;AAAA,WACD;AAAA,SACD,GACD;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": ["editorStore", "kebabCase", "VStack", "HStack"]
|
|
7
7
|
}
|
|
@@ -30,6 +30,7 @@ module.exports = __toCommonJS(hooks_exports);
|
|
|
30
30
|
var import_data = require("@wordpress/data");
|
|
31
31
|
var import_element = require("@wordpress/element");
|
|
32
32
|
var import_core_data = require("@wordpress/core-data");
|
|
33
|
+
var import_i18n = require("@wordpress/i18n");
|
|
33
34
|
var import_store = require("../../store/index.cjs");
|
|
34
35
|
function useEditedPostContext() {
|
|
35
36
|
return (0, import_data.useSelect)((select) => {
|
|
@@ -71,16 +72,61 @@ function useTemplates(postType) {
|
|
|
71
72
|
[postType]
|
|
72
73
|
);
|
|
73
74
|
}
|
|
74
|
-
function useAvailableTemplates(
|
|
75
|
+
function useAvailableTemplates() {
|
|
76
|
+
const { postType, postId } = useEditedPostContext();
|
|
77
|
+
const [postSlug] = (0, import_core_data.useEntityProp)("postType", postType, "slug", postId);
|
|
75
78
|
const currentTemplateSlug = useCurrentTemplateSlug();
|
|
76
79
|
const allowSwitchingTemplate = useAllowSwitchingTemplates();
|
|
77
80
|
const templates = useTemplates(postType);
|
|
81
|
+
const defaultTemplate = (0, import_data.useSelect)(
|
|
82
|
+
(select) => {
|
|
83
|
+
if (!window?.__experimentalDataFormInspector) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
if (!currentTemplateSlug) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const { getDefaultTemplateId, getEntityRecord } = select(import_core_data.store);
|
|
90
|
+
let slug;
|
|
91
|
+
if (postSlug) {
|
|
92
|
+
slug = postType === "page" ? `${postType}-${postSlug}` : `single-${postType}-${postSlug}`;
|
|
93
|
+
} else {
|
|
94
|
+
slug = postType === "page" ? "page" : `single-${postType}`;
|
|
95
|
+
}
|
|
96
|
+
const templateId = getDefaultTemplateId({ slug });
|
|
97
|
+
if (!templateId) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return getEntityRecord("postType", "wp_template", templateId);
|
|
101
|
+
},
|
|
102
|
+
[currentTemplateSlug, postSlug, postType]
|
|
103
|
+
);
|
|
78
104
|
return (0, import_element.useMemo)(
|
|
79
|
-
() => allowSwitchingTemplate &&
|
|
80
|
-
(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
105
|
+
() => allowSwitchingTemplate && [
|
|
106
|
+
...(templates || []).filter(
|
|
107
|
+
(template) => template.is_custom && template.slug !== currentTemplateSlug && !!template.content.raw
|
|
108
|
+
// Skip empty templates.
|
|
109
|
+
),
|
|
110
|
+
defaultTemplate && {
|
|
111
|
+
...defaultTemplate,
|
|
112
|
+
title: {
|
|
113
|
+
rendered: (0, import_i18n.sprintf)(
|
|
114
|
+
// translators: %s: Template name
|
|
115
|
+
(0, import_i18n.__)("%s (default)"),
|
|
116
|
+
defaultTemplate.title.rendered
|
|
117
|
+
)
|
|
118
|
+
},
|
|
119
|
+
// That's extra custom prop in order to update to an empty template
|
|
120
|
+
// when we select the default template.
|
|
121
|
+
isDefault: true
|
|
122
|
+
}
|
|
123
|
+
].filter(Boolean),
|
|
124
|
+
[
|
|
125
|
+
templates,
|
|
126
|
+
defaultTemplate,
|
|
127
|
+
currentTemplateSlug,
|
|
128
|
+
allowSwitchingTemplate
|
|
129
|
+
]
|
|
84
130
|
);
|
|
85
131
|
}
|
|
86
132
|
function usePostTemplatePanelMode() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/post-template/hooks.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport function useEditedPostContext() {\n\treturn useSelect( ( select ) => {\n\t\tconst { getCurrentPostId, getCurrentPostType } = select( editorStore );\n\t\treturn {\n\t\t\tpostId: getCurrentPostId(),\n\t\t\tpostType: getCurrentPostType(),\n\t\t};\n\t}, [] );\n}\nexport function useAllowSwitchingTemplates() {\n\tconst { postType, postId } = useEditedPostContext();\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser, getEntityRecord, getEntityRecords } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst siteSettings = canUser( 'read', {\n\t\t\t\tkind: 'root',\n\t\t\t\tname: 'site',\n\t\t\t} )\n\t\t\t\t? getEntityRecord( 'root', 'site' )\n\t\t\t\t: undefined;\n\n\t\t\tconst isPostsPage = +postId === siteSettings?.page_for_posts;\n\t\t\tconst isFrontPage =\n\t\t\t\tpostType === 'page' && +postId === siteSettings?.page_on_front;\n\t\t\t// If current page is set front page or posts page, we also need\n\t\t\t// to check if the current theme has a template for it. If not\n\t\t\tconst templates = isFrontPage\n\t\t\t\t? getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t } )\n\t\t\t\t: [];\n\t\t\tconst hasFrontPage =\n\t\t\t\tisFrontPage &&\n\t\t\t\t!! templates?.some( ( { slug } ) => slug === 'front-page' );\n\t\t\treturn ! isPostsPage && ! hasFrontPage;\n\t\t},\n\t\t[ postId, postType ]\n\t);\n}\n\nfunction useTemplates( postType ) {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t\tpost_type: postType,\n\t\t\t\t// We look at the combined templates for now (old endpoint)\n\t\t\t\t// because posts only accept slugs for templates, not IDs.\n\t\t\t} ),\n\t\t[ postType ]\n\t);\n}\n\nexport function useAvailableTemplates( postType )
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAC1B,qBAAwB;AACxB,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\nimport { useEntityProp, store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport function useEditedPostContext() {\n\treturn useSelect( ( select ) => {\n\t\tconst { getCurrentPostId, getCurrentPostType } = select( editorStore );\n\t\treturn {\n\t\t\tpostId: getCurrentPostId(),\n\t\t\tpostType: getCurrentPostType(),\n\t\t};\n\t}, [] );\n}\nexport function useAllowSwitchingTemplates() {\n\tconst { postType, postId } = useEditedPostContext();\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser, getEntityRecord, getEntityRecords } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst siteSettings = canUser( 'read', {\n\t\t\t\tkind: 'root',\n\t\t\t\tname: 'site',\n\t\t\t} )\n\t\t\t\t? getEntityRecord( 'root', 'site' )\n\t\t\t\t: undefined;\n\n\t\t\tconst isPostsPage = +postId === siteSettings?.page_for_posts;\n\t\t\tconst isFrontPage =\n\t\t\t\tpostType === 'page' && +postId === siteSettings?.page_on_front;\n\t\t\t// If current page is set front page or posts page, we also need\n\t\t\t// to check if the current theme has a template for it. If not\n\t\t\tconst templates = isFrontPage\n\t\t\t\t? getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t } )\n\t\t\t\t: [];\n\t\t\tconst hasFrontPage =\n\t\t\t\tisFrontPage &&\n\t\t\t\t!! templates?.some( ( { slug } ) => slug === 'front-page' );\n\t\t\treturn ! isPostsPage && ! hasFrontPage;\n\t\t},\n\t\t[ postId, postType ]\n\t);\n}\n\nfunction useTemplates( postType ) {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t\tpost_type: postType,\n\t\t\t\t// We look at the combined templates for now (old endpoint)\n\t\t\t\t// because posts only accept slugs for templates, not IDs.\n\t\t\t} ),\n\t\t[ postType ]\n\t);\n}\n\nexport function useAvailableTemplates() {\n\tconst { postType, postId } = useEditedPostContext();\n\tconst [ postSlug ] = useEntityProp( 'postType', postType, 'slug', postId );\n\tconst currentTemplateSlug = useCurrentTemplateSlug();\n\tconst allowSwitchingTemplate = useAllowSwitchingTemplates();\n\tconst templates = useTemplates( postType );\n\t// Add the default template to the available ones. We don't care about\n\t// possible assignment to postspage/homepage because it's guarded by\n\t// `allowSwitchingTemplate` above.\n\tconst defaultTemplate = useSelect(\n\t\t( select ) => {\n\t\t\t// Only append the default template if the experiment is enabled.\n\t\t\tif ( ! window?.__experimentalDataFormInspector ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\t// If the default template is already assigned, no need\n\t\t\t// to add it to the available templates.\n\t\t\tif ( ! currentTemplateSlug ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst { getDefaultTemplateId, getEntityRecord } =\n\t\t\t\tselect( coreStore );\n\t\t\tlet slug;\n\t\t\tif ( postSlug ) {\n\t\t\t\tslug =\n\t\t\t\t\tpostType === 'page'\n\t\t\t\t\t\t? `${ postType }-${ postSlug }`\n\t\t\t\t\t\t: `single-${ postType }-${ postSlug }`;\n\t\t\t} else {\n\t\t\t\tslug = postType === 'page' ? 'page' : `single-${ postType }`;\n\t\t\t}\n\t\t\tconst templateId = getDefaultTemplateId( { slug } );\n\t\t\tif ( ! templateId ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn getEntityRecord( 'postType', 'wp_template', templateId );\n\t\t},\n\t\t[ currentTemplateSlug, postSlug, postType ]\n\t);\n\treturn useMemo(\n\t\t() =>\n\t\t\tallowSwitchingTemplate &&\n\t\t\t[\n\t\t\t\t...( templates || [] ).filter(\n\t\t\t\t\t( template ) =>\n\t\t\t\t\t\ttemplate.is_custom &&\n\t\t\t\t\t\ttemplate.slug !== currentTemplateSlug &&\n\t\t\t\t\t\t!! template.content.raw // Skip empty templates.\n\t\t\t\t),\n\t\t\t\tdefaultTemplate && {\n\t\t\t\t\t...defaultTemplate,\n\t\t\t\t\ttitle: {\n\t\t\t\t\t\trendered: sprintf(\n\t\t\t\t\t\t\t// translators: %s: Template name\n\t\t\t\t\t\t\t__( '%s (default)' ),\n\t\t\t\t\t\t\tdefaultTemplate.title.rendered\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\t// That's extra custom prop in order to update to an empty template\n\t\t\t\t\t// when we select the default template.\n\t\t\t\t\tisDefault: true,\n\t\t\t\t},\n\t\t\t].filter( Boolean ),\n\t\t[\n\t\t\ttemplates,\n\t\t\tdefaultTemplate,\n\t\t\tcurrentTemplateSlug,\n\t\t\tallowSwitchingTemplate,\n\t\t]\n\t);\n}\n\nexport function usePostTemplatePanelMode() {\n\treturn useSelect( ( select ) => {\n\t\tconst { getEditorSettings, getCurrentTemplateId, getCurrentPostType } =\n\t\t\tselect( editorStore );\n\t\tconst { getPostType, canUser } = select( coreStore );\n\t\tconst postTypeSlug = getCurrentPostType();\n\t\tconst postType = getPostType( postTypeSlug );\n\t\tconst settings = getEditorSettings();\n\t\tconst isBlockTheme = settings.__unstableIsBlockBasedTheme;\n\t\tconst hasTemplates =\n\t\t\t!! settings.availableTemplates &&\n\t\t\tObject.keys( settings.availableTemplates ).length > 0;\n\t\tlet isVisible;\n\t\tif ( ! postType?.viewable ) {\n\t\t\tisVisible = false;\n\t\t} else if ( hasTemplates ) {\n\t\t\tisVisible = true;\n\t\t} else if ( ! settings.supportsTemplateMode ) {\n\t\t\tisVisible = false;\n\t\t} else {\n\t\t\tisVisible =\n\t\t\t\tcanUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_template',\n\t\t\t\t} ) ?? false;\n\t\t}\n\t\tconst canViewTemplates = isVisible\n\t\t\t? !! canUser( 'read', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_template',\n\t\t\t } )\n\t\t\t: false;\n\t\tif ( ( ! isBlockTheme || ! canViewTemplates ) && isVisible ) {\n\t\t\treturn 'classic';\n\t\t}\n\t\tif ( isBlockTheme && !! getCurrentTemplateId() ) {\n\t\t\treturn 'block-theme';\n\t\t}\n\t\treturn null;\n\t}, [] );\n}\n\nexport function useCurrentTemplateSlug() {\n\tconst { postType, postId } = useEditedPostContext();\n\tconst templates = useTemplates( postType );\n\tconst entityTemplate = useSelect(\n\t\t( select ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\tpostId\n\t\t\t);\n\t\t\treturn post?.template;\n\t\t},\n\t\t[ postType, postId ]\n\t);\n\n\tif ( ! entityTemplate ) {\n\t\treturn;\n\t}\n\t// If a page has a `template` set and is not included in the list\n\t// of the theme's templates, do not return it, in order to resolve\n\t// to the current theme's default template.\n\treturn templates?.find( ( template ) => template.slug === entityTemplate )\n\t\t?.slug;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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