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
gutenberg / build / routes / media-editor / route.js

route.js in Gutenberg trunk, at build/routes/media-editor/route.js

104 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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/core-data
28 var require_core_data = __commonJS({
29 "package-external:@wordpress/core-data"(exports, module) {
30 module.exports = window.wp.coreData;
31 }
32 });
33
34 // package-external:@wordpress/data
35 var require_data = __commonJS({
36 "package-external:@wordpress/data"(exports, module) {
37 module.exports = window.wp.data;
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/media-editor/route.ts
56 var import_core_data = __toESM(require_core_data());
57 var import_data = __toESM(require_data());
58 var import_html_entities = __toESM(require_html_entities());
59 var import_i18n = __toESM(require_i18n());
60 import { notFound } from "@wordpress/route";
61 function getAttachmentId(id) {
62 const attachmentId = parseInt(id, 10);
63 if (Number.isNaN(attachmentId) || attachmentId <= 0) {
64 throw notFound();
65 }
66 return attachmentId;
67 }
68 function getAttachmentTitle(attachment) {
69 const title = typeof attachment.title === "string" ? attachment.title : attachment.title?.rendered || attachment.title?.raw;
70 return title ? (0, import_html_entities.decodeEntities)(title) : (0, import_i18n.__)("Edit media");
71 }
72 var route = {
73 beforeLoad: async ({ params }) => {
74 if (!window?.__experimentalMediaEditor) {
75 throw notFound();
76 }
77 const attachmentId = getAttachmentId(params.id);
78 try {
79 const attachment = await (0, import_data.resolveSelect)(import_core_data.store).getEntityRecord(
80 "postType",
81 "attachment",
82 attachmentId
83 );
84 if (!attachment) {
85 throw notFound();
86 }
87 } catch {
88 throw notFound();
89 }
90 },
91 title: async ({ params }) => {
92 const attachmentId = getAttachmentId(params.id);
93 const attachment = await (0, import_data.resolveSelect)(import_core_data.store).getEntityRecord(
94 "postType",
95 "attachment",
96 attachmentId
97 );
98 return attachment ? getAttachmentTitle(attachment) : (0, import_i18n.__)("Edit media");
99 }
100 };
101 export {
102 route
103 };
104