| 1 |
var __create = Object.create; |
| 2 |
var __defProp = Object.defineProperty; |
| 3 |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
| 4 |
var __getOwnPropNames = Object.getOwnPropertyNames; |
| 5 |
var __getProtoOf = Object.getPrototypeOf; |
| 6 |
var __hasOwnProp = Object.prototype.hasOwnProperty; |
| 7 |
var __commonJS = (cb, mod) => function __require() { |
| 8 |
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; |
| 9 |
}; |
| 10 |
var __copyProps = (to, from, except, desc) => { |
| 11 |
if (from && typeof from === "object" || typeof from === "function") { |
| 12 |
for (let key of __getOwnPropNames(from)) |
| 13 |
if (!__hasOwnProp.call(to, key) && key !== except) |
| 14 |
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
| 15 |
} |
| 16 |
return to; |
| 17 |
}; |
| 18 |
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( |
| 19 |
// If the importer is in node compatibility mode or this is not an ESM |
| 20 |
// file that has been converted to a CommonJS file using a Babel- |
| 21 |
// compatible transform (i.e. "__esModule" has not been set), then set |
| 22 |
// "default" to the CommonJS "module.exports" for node compatibility. |
| 23 |
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, |
| 24 |
mod |
| 25 |
)); |
| 26 |
|
| 27 |
// package-external:@wordpress/data |
| 28 |
var require_data = __commonJS({ |
| 29 |
"package-external:@wordpress/data"(exports, module) { |
| 30 |
module.exports = window.wp.data; |
| 31 |
} |
| 32 |
}); |
| 33 |
|
| 34 |
// package-external:@wordpress/core-data |
| 35 |
var require_core_data = __commonJS({ |
| 36 |
"package-external:@wordpress/core-data"(exports, module) { |
| 37 |
module.exports = window.wp.coreData; |
| 38 |
} |
| 39 |
}); |
| 40 |
|
| 41 |
// package-external:@wordpress/html-entities |
| 42 |
var require_html_entities = __commonJS({ |
| 43 |
"package-external:@wordpress/html-entities"(exports, module) { |
| 44 |
module.exports = window.wp.htmlEntities; |
| 45 |
} |
| 46 |
}); |
| 47 |
|
| 48 |
// package-external:@wordpress/i18n |
| 49 |
var require_i18n = __commonJS({ |
| 50 |
"package-external:@wordpress/i18n"(exports, module) { |
| 51 |
module.exports = window.wp.i18n; |
| 52 |
} |
| 53 |
}); |
| 54 |
|
| 55 |
// routes/post-edit/route.ts |
| 56 |
var import_data = __toESM(require_data()); |
| 57 |
var import_core_data = __toESM(require_core_data()); |
| 58 |
var import_html_entities = __toESM(require_html_entities()); |
| 59 |
var import_i18n = __toESM(require_i18n()); |
| 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 |
} |
| 73 |
var route = { |
| 74 |
beforeLoad: async ({ params }) => { |
| 75 |
const postId = getPostId(params); |
| 76 |
if (!TEMPLATE_POST_TYPES.includes(params.type) && !/^\d+$/.test(postId)) { |
| 77 |
throw notFound(); |
| 78 |
} |
| 79 |
try { |
| 80 |
const [postType, post] = await Promise.all([ |
| 81 |
(0, import_data.resolveSelect)(import_core_data.store).getPostType(params.type), |
| 82 |
(0, import_data.resolveSelect)(import_core_data.store).getEntityRecord( |
| 83 |
"postType", |
| 84 |
params.type, |
| 85 |
postId |
| 86 |
) |
| 87 |
]); |
| 88 |
if (!postType || !post) { |
| 89 |
throw notFound(); |
| 90 |
} |
| 91 |
} catch { |
| 92 |
throw notFound(); |
| 93 |
} |
| 94 |
}, |
| 95 |
title: async ({ params }) => { |
| 96 |
const postId = getPostId(params); |
| 97 |
const post = await (0, import_data.resolveSelect)(import_core_data.store).getEntityRecord( |
| 98 |
"postType", |
| 99 |
params.type, |
| 100 |
postId |
| 101 |
); |
| 102 |
if (post?.title?.rendered) { |
| 103 |
return (0, import_html_entities.decodeEntities)(post.title.rendered); |
| 104 |
} |
| 105 |
if (post?.title?.raw) { |
| 106 |
return post.title.raw; |
| 107 |
} |
| 108 |
const postType = await (0, import_data.resolveSelect)(import_core_data.store).getPostType( |
| 109 |
params.type |
| 110 |
); |
| 111 |
return postType?.labels?.edit_item || (0, import_i18n.__)("Edit"); |
| 112 |
}, |
| 113 |
async canvas(context) { |
| 114 |
const { params } = context; |
| 115 |
const postId = getPostId(params); |
| 116 |
return { |
| 117 |
postType: params.type, |
| 118 |
postId |
| 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 |
} |
| 137 |
} |
| 138 |
}; |
| 139 |
export { |
| 140 |
route |
| 141 |
}; |
| 142 |
|