PluginProbe
Gutenberg / 22.9.0
Gutenberg v22.9.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 12.6.0 7.4.0 All 402 releases
gutenberg / build / modules / core-abilities / index.js

index.js in Gutenberg 22.9.0, at build/modules/core-abilities/index.js

126 lines 4.2 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/api-fetch
28 var require_api_fetch = __commonJS({
29 "package-external:@wordpress/api-fetch"(exports, module) {
30 module.exports = window.wp.apiFetch;
31 }
32 });
33
34 // package-external:@wordpress/url
35 var require_url = __commonJS({
36 "package-external:@wordpress/url"(exports, module) {
37 module.exports = window.wp.url;
38 }
39 });
40
41 // packages/core-abilities/build-module/index.mjs
42 var import_api_fetch = __toESM(require_api_fetch(), 1);
43 var import_url = __toESM(require_url(), 1);
44 import { registerAbility, registerAbilityCategory } from "@wordpress/abilities";
45 var API_BASE = "/wp-abilities/v1";
46 var ABILITIES_ENDPOINT = `${API_BASE}/abilities`;
47 var CATEGORIES_ENDPOINT = `${API_BASE}/categories`;
48 function createServerCallback(ability) {
49 return async (input) => {
50 let method = "POST";
51 if (!!ability.meta?.annotations?.readonly) {
52 method = "GET";
53 } else if (!!ability.meta?.annotations?.destructive && !!ability.meta?.annotations?.idempotent) {
54 method = "DELETE";
55 }
56 let path = `${ABILITIES_ENDPOINT}/${ability.name}/run`;
57 const options = {
58 method
59 };
60 if (["GET", "DELETE"].includes(method) && input !== null && input !== void 0) {
61 path = (0, import_url.addQueryArgs)(path, { input });
62 } else if (method === "POST" && input !== null && input !== void 0) {
63 options.data = { input };
64 }
65 return (0, import_api_fetch.default)({
66 path,
67 ...options
68 });
69 };
70 }
71 async function initializeCategories() {
72 try {
73 const categories = await (0, import_api_fetch.default)({
74 path: (0, import_url.addQueryArgs)(CATEGORIES_ENDPOINT, {
75 per_page: -1,
76 context: "edit"
77 })
78 });
79 if (categories && Array.isArray(categories)) {
80 for (const category of categories) {
81 registerAbilityCategory(category.slug, {
82 label: category.label,
83 description: category.description,
84 meta: {
85 annotations: { serverRegistered: true }
86 }
87 });
88 }
89 }
90 } catch (error) {
91 console.error("Failed to fetch ability categories:", error);
92 }
93 }
94 async function initializeAbilities() {
95 try {
96 const abilities = await (0, import_api_fetch.default)({
97 path: (0, import_url.addQueryArgs)(ABILITIES_ENDPOINT, {
98 per_page: -1,
99 context: "edit"
100 })
101 });
102 if (abilities && Array.isArray(abilities)) {
103 for (const ability of abilities) {
104 registerAbility({
105 ...ability,
106 callback: createServerCallback(ability),
107 meta: {
108 annotations: {
109 ...ability.meta?.annotations,
110 serverRegistered: true
111 }
112 }
113 });
114 }
115 }
116 } catch (error) {
117 console.error("Failed to fetch abilities:", error);
118 }
119 }
120 async function initialize() {
121 await initializeCategories();
122 await initializeAbilities();
123 }
124 initialize();
125 //# sourceMappingURL=index.js.map
126