initial
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __commonJS = (cb, mod) => function __require() {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
|
||||
// package-external:@wordpress/api-fetch
|
||||
var require_api_fetch = __commonJS({
|
||||
"package-external:@wordpress/api-fetch"(exports, module) {
|
||||
module.exports = window.wp.apiFetch;
|
||||
}
|
||||
});
|
||||
|
||||
// package-external:@wordpress/url
|
||||
var require_url = __commonJS({
|
||||
"package-external:@wordpress/url"(exports, module) {
|
||||
module.exports = window.wp.url;
|
||||
}
|
||||
});
|
||||
|
||||
// packages/core-abilities/build-module/index.mjs
|
||||
var import_api_fetch = __toESM(require_api_fetch(), 1);
|
||||
var import_url = __toESM(require_url(), 1);
|
||||
import { registerAbility, registerAbilityCategory } from "@wordpress/abilities";
|
||||
var API_BASE = "/wp-abilities/v1";
|
||||
var ABILITIES_ENDPOINT = `${API_BASE}/abilities`;
|
||||
var CATEGORIES_ENDPOINT = `${API_BASE}/categories`;
|
||||
function createServerCallback(ability) {
|
||||
return async (input) => {
|
||||
let method = "POST";
|
||||
if (!!ability.meta?.annotations?.readonly) {
|
||||
method = "GET";
|
||||
} else if (!!ability.meta?.annotations?.destructive && !!ability.meta?.annotations?.idempotent) {
|
||||
method = "DELETE";
|
||||
}
|
||||
let path = `${ABILITIES_ENDPOINT}/${ability.name}/run`;
|
||||
const options = {
|
||||
method
|
||||
};
|
||||
if (["GET", "DELETE"].includes(method) && input !== null && input !== void 0) {
|
||||
path = (0, import_url.addQueryArgs)(path, { input });
|
||||
} else if (method === "POST" && input !== null && input !== void 0) {
|
||||
options.data = { input };
|
||||
}
|
||||
return (0, import_api_fetch.default)({
|
||||
path,
|
||||
...options
|
||||
});
|
||||
};
|
||||
}
|
||||
async function initializeCategories() {
|
||||
try {
|
||||
const categories = await (0, import_api_fetch.default)({
|
||||
path: (0, import_url.addQueryArgs)(CATEGORIES_ENDPOINT, {
|
||||
per_page: -1,
|
||||
context: "edit"
|
||||
})
|
||||
});
|
||||
if (categories && Array.isArray(categories)) {
|
||||
for (const category of categories) {
|
||||
registerAbilityCategory(category.slug, {
|
||||
label: category.label,
|
||||
description: category.description,
|
||||
meta: {
|
||||
annotations: { serverRegistered: true }
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch ability categories:", error);
|
||||
}
|
||||
}
|
||||
async function initializeAbilities() {
|
||||
try {
|
||||
const abilities = await (0, import_api_fetch.default)({
|
||||
path: (0, import_url.addQueryArgs)(ABILITIES_ENDPOINT, {
|
||||
per_page: -1,
|
||||
context: "edit"
|
||||
})
|
||||
});
|
||||
if (abilities && Array.isArray(abilities)) {
|
||||
for (const ability of abilities) {
|
||||
registerAbility({
|
||||
...ability,
|
||||
callback: createServerCallback(ability),
|
||||
meta: {
|
||||
annotations: {
|
||||
...ability.meta?.annotations,
|
||||
serverRegistered: true
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch abilities:", error);
|
||||
}
|
||||
}
|
||||
async function initialize() {
|
||||
await initializeCategories();
|
||||
await initializeAbilities();
|
||||
}
|
||||
var ready = initialize();
|
||||
export {
|
||||
ready
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array('wp-api-fetch', 'wp-url'), 'module_dependencies' => array(array('id' => '@wordpress/abilities', 'import' => 'static')), 'version' => '012760fd849397dd0031');
|
||||
@@ -0,0 +1 @@
|
||||
var E=Object.create;var s=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var c=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var b=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of u(t))!w.call(e,a)&&a!==i&&s(e,a,{get:()=>t[a],enumerable:!(r=A(t,a))||r.enumerable});return e};var l=(e,t,i)=>(i=e!=null?E(v(e)):{},b(t||!e||!e.__esModule?s(i,"default",{value:e,enumerable:!0}):i,e));var f=c((C,d)=>{d.exports=window.wp.apiFetch});var y=c((D,p)=>{p.exports=window.wp.url});var o=l(f(),1),n=l(y(),1);import{registerAbility as h,registerAbilityCategory as T}from"@wordpress/abilities";var m="/wp-abilities/v1",g=`${m}/abilities`,I=`${m}/categories`;function S(e){return async t=>{let i="POST";e.meta?.annotations?.readonly?i="GET":e.meta?.annotations?.destructive&&e.meta?.annotations?.idempotent&&(i="DELETE");let r=`${g}/${e.name}/run`,a={method:i};return["GET","DELETE"].includes(i)&&t!==null&&t!==void 0?r=(0,n.addQueryArgs)(r,{input:t}):i==="POST"&&t!==null&&t!==void 0&&(a.data={input:t}),(0,o.default)({path:r,...a})}}async function x(){try{let e=await(0,o.default)({path:(0,n.addQueryArgs)(I,{per_page:-1,context:"edit"})});if(e&&Array.isArray(e))for(let t of e)T(t.slug,{label:t.label,description:t.description,meta:{annotations:{serverRegistered:!0}}})}catch(e){console.error("Failed to fetch ability categories:",e)}}async function O(){try{let e=await(0,o.default)({path:(0,n.addQueryArgs)(g,{per_page:-1,context:"edit"})});if(e&&Array.isArray(e))for(let t of e)h({...t,callback:S(t),meta:{annotations:{...t.meta?.annotations,serverRegistered:!0}}})}catch(e){console.error("Failed to fetch abilities:",e)}}async function P(){await x(),await O()}var N=P();export{N as ready};
|
||||
Reference in New Issue
Block a user