PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | build/routes/post-edit/route.js +40 -10 23.2.1 → trunk View file →
@@ -57,14 +57,24 @@
57 57 var import_core_data = __toESM(require_core_data());
58 58 var import_html_entities = __toESM(require_html_entities());
59 59 var import_i18n = __toESM(require_i18n());
60 60 import { notFound } from "@wordpress/route";
61 +var TEMPLATE_POST_TYPES = ["wp_template", "wp_template_part"];
62 +function getPostId(params) {
63 + const id = params["*"];
64 + if (!id) {
65 + throw notFound();
66 + }
67 + try {
68 + return decodeURIComponent(id);
69 + } catch {
70 + return id;
71 + }
72 +}
61 73 var route = {
62 - beforeLoad: async ({
63 - params
64 - }) => {
65 - const postId = parseInt(params.id, 10);
66 - if (Number.isNaN(postId)) {
74 + beforeLoad: async ({ params }) => {
75 + const postId = getPostId(params);
76 + if (!TEMPLATE_POST_TYPES.includes(params.type) && !/^\d+$/.test(postId)) {
67 77 throw notFound();
68 78 }
69 79 try {
70 80 const [postType, post] = await Promise.all([
@@ -81,19 +91,21 @@
81 91 } catch {
82 92 throw notFound();
83 93 }
84 94 },
85 - title: async ({
86 - params
87 - }) => {
95 + title: async ({ params }) => {
96 + const postId = getPostId(params);
88 97 const post = await (0, import_data.resolveSelect)(import_core_data.store).getEntityRecord(
89 98 "postType",
90 99 params.type,
91 - params.id
100 + postId
92 101 );
93 102 if (post?.title?.rendered) {
94 103 return (0, import_html_entities.decodeEntities)(post.title.rendered);
95 104 }
105 + if (post?.title?.raw) {
106 + return post.title.raw;
107 + }
96 108 const postType = await (0, import_data.resolveSelect)(import_core_data.store).getPostType(
97 109 params.type
98 110 );
99 111 return postType?.labels?.edit_item || (0, import_i18n.__)("Edit");
@@ -99,12 +111,30 @@
99 111 return postType?.labels?.edit_item || (0, import_i18n.__)("Edit");
100 112 },
101 113 async canvas(context) {
102 114 const { params } = context;
115 + const postId = getPostId(params);
103 116 return {
104 117 postType: params.type,
105 - postId: params.id
118 + postId
106 119 };
120 + },
121 + async loader(context) {
122 + const { params, search } = context;
123 + if (search.selectedBlock) {
124 + (0, import_data.dispatch)(import_core_data.store).editEntityRecord(
125 + "postType",
126 + params.type,
127 + getPostId(params),
128 + {
129 + selection: {
130 + selectionStart: { clientId: search.selectedBlock },
131 + selectionEnd: { clientId: search.selectedBlock }
132 + }
133 + },
134 + { undoIgnore: true }
135 + );
136 + }
107 137 }
108 138 };
109 139 export {
110 140 route