wip
This commit is contained in:
Vendored
+416
-559
@@ -1,9 +1,386 @@
|
||||
/******/ (() => { // webpackBootstrap
|
||||
/******/ "use strict";
|
||||
/******/ // The require scope
|
||||
/******/ var __webpack_require__ = {};
|
||||
/******/ var __webpack_modules__ = ({
|
||||
|
||||
/***/ 507:
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
|
||||
// EXPORTS
|
||||
__webpack_require__.d(__webpack_exports__, {
|
||||
A: () => (/* binding */ createHooks_default)
|
||||
});
|
||||
|
||||
// UNUSED EXPORTS: _Hooks
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/validateNamespace.js
|
||||
function validateNamespace(namespace) {
|
||||
if ("string" !== typeof namespace || "" === namespace) {
|
||||
console.error("The namespace must be a non-empty string.");
|
||||
return false;
|
||||
}
|
||||
if (!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(namespace)) {
|
||||
console.error(
|
||||
"The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
var validateNamespace_default = validateNamespace;
|
||||
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/validateHookName.js
|
||||
function validateHookName(hookName) {
|
||||
if ("string" !== typeof hookName || "" === hookName) {
|
||||
console.error("The hook name must be a non-empty string.");
|
||||
return false;
|
||||
}
|
||||
if (/^__/.test(hookName)) {
|
||||
console.error("The hook name cannot begin with `__`.");
|
||||
return false;
|
||||
}
|
||||
if (!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(hookName)) {
|
||||
console.error(
|
||||
"The hook name can only contain numbers, letters, dashes, periods and underscores."
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
var validateHookName_default = validateHookName;
|
||||
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createAddHook.js
|
||||
|
||||
|
||||
function createAddHook(hooks, storeKey) {
|
||||
return function addHook(hookName, namespace, callback, priority = 10) {
|
||||
const hooksStore = hooks[storeKey];
|
||||
if (!validateHookName_default(hookName)) {
|
||||
return;
|
||||
}
|
||||
if (!validateNamespace_default(namespace)) {
|
||||
return;
|
||||
}
|
||||
if ("function" !== typeof callback) {
|
||||
console.error("The hook callback must be a function.");
|
||||
return;
|
||||
}
|
||||
if ("number" !== typeof priority) {
|
||||
console.error(
|
||||
"If specified, the hook priority must be a number."
|
||||
);
|
||||
return;
|
||||
}
|
||||
const handler = { callback, priority, namespace };
|
||||
if (hooksStore[hookName]) {
|
||||
const handlers = hooksStore[hookName].handlers;
|
||||
let i;
|
||||
for (i = handlers.length; i > 0; i--) {
|
||||
if (priority >= handlers[i - 1].priority) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i === handlers.length) {
|
||||
handlers[i] = handler;
|
||||
} else {
|
||||
handlers.splice(i, 0, handler);
|
||||
}
|
||||
hooksStore.__current.forEach((hookInfo) => {
|
||||
if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
|
||||
hookInfo.currentIndex++;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
hooksStore[hookName] = {
|
||||
handlers: [handler],
|
||||
runs: 0
|
||||
};
|
||||
}
|
||||
if (hookName !== "hookAdded") {
|
||||
hooks.doAction(
|
||||
"hookAdded",
|
||||
hookName,
|
||||
namespace,
|
||||
callback,
|
||||
priority
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
var createAddHook_default = createAddHook;
|
||||
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createRemoveHook.js
|
||||
|
||||
|
||||
function createRemoveHook(hooks, storeKey, removeAll = false) {
|
||||
return function removeHook(hookName, namespace) {
|
||||
const hooksStore = hooks[storeKey];
|
||||
if (!validateHookName_default(hookName)) {
|
||||
return;
|
||||
}
|
||||
if (!removeAll && !validateNamespace_default(namespace)) {
|
||||
return;
|
||||
}
|
||||
if (!hooksStore[hookName]) {
|
||||
return 0;
|
||||
}
|
||||
let handlersRemoved = 0;
|
||||
if (removeAll) {
|
||||
handlersRemoved = hooksStore[hookName].handlers.length;
|
||||
hooksStore[hookName] = {
|
||||
runs: hooksStore[hookName].runs,
|
||||
handlers: []
|
||||
};
|
||||
} else {
|
||||
const handlers = hooksStore[hookName].handlers;
|
||||
for (let i = handlers.length - 1; i >= 0; i--) {
|
||||
if (handlers[i].namespace === namespace) {
|
||||
handlers.splice(i, 1);
|
||||
handlersRemoved++;
|
||||
hooksStore.__current.forEach((hookInfo) => {
|
||||
if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
|
||||
hookInfo.currentIndex--;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hookName !== "hookRemoved") {
|
||||
hooks.doAction("hookRemoved", hookName, namespace);
|
||||
}
|
||||
return handlersRemoved;
|
||||
};
|
||||
}
|
||||
var createRemoveHook_default = createRemoveHook;
|
||||
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createHasHook.js
|
||||
function createHasHook(hooks, storeKey) {
|
||||
return function hasHook(hookName, namespace) {
|
||||
const hooksStore = hooks[storeKey];
|
||||
if ("undefined" !== typeof namespace) {
|
||||
return hookName in hooksStore && hooksStore[hookName].handlers.some(
|
||||
(hook) => hook.namespace === namespace
|
||||
);
|
||||
}
|
||||
return hookName in hooksStore;
|
||||
};
|
||||
}
|
||||
var createHasHook_default = createHasHook;
|
||||
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createRunHook.js
|
||||
function createRunHook(hooks, storeKey, returnFirstArg, async) {
|
||||
return function runHook(hookName, ...args) {
|
||||
const hooksStore = hooks[storeKey];
|
||||
if (!hooksStore[hookName]) {
|
||||
hooksStore[hookName] = {
|
||||
handlers: [],
|
||||
runs: 0
|
||||
};
|
||||
}
|
||||
hooksStore[hookName].runs++;
|
||||
const handlers = hooksStore[hookName].handlers;
|
||||
if (false) {}
|
||||
if (!handlers || !handlers.length) {
|
||||
return returnFirstArg ? args[0] : void 0;
|
||||
}
|
||||
const hookInfo = {
|
||||
name: hookName,
|
||||
currentIndex: 0
|
||||
};
|
||||
async function asyncRunner() {
|
||||
try {
|
||||
hooksStore.__current.add(hookInfo);
|
||||
let result = returnFirstArg ? args[0] : void 0;
|
||||
while (hookInfo.currentIndex < handlers.length) {
|
||||
const handler = handlers[hookInfo.currentIndex];
|
||||
result = await handler.callback.apply(null, args);
|
||||
if (returnFirstArg) {
|
||||
args[0] = result;
|
||||
}
|
||||
hookInfo.currentIndex++;
|
||||
}
|
||||
return returnFirstArg ? result : void 0;
|
||||
} finally {
|
||||
hooksStore.__current.delete(hookInfo);
|
||||
}
|
||||
}
|
||||
function syncRunner() {
|
||||
try {
|
||||
hooksStore.__current.add(hookInfo);
|
||||
let result = returnFirstArg ? args[0] : void 0;
|
||||
while (hookInfo.currentIndex < handlers.length) {
|
||||
const handler = handlers[hookInfo.currentIndex];
|
||||
result = handler.callback.apply(null, args);
|
||||
if (returnFirstArg) {
|
||||
args[0] = result;
|
||||
}
|
||||
hookInfo.currentIndex++;
|
||||
}
|
||||
return returnFirstArg ? result : void 0;
|
||||
} finally {
|
||||
hooksStore.__current.delete(hookInfo);
|
||||
}
|
||||
}
|
||||
return (async ? asyncRunner : syncRunner)();
|
||||
};
|
||||
}
|
||||
var createRunHook_default = createRunHook;
|
||||
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createCurrentHook.js
|
||||
function createCurrentHook(hooks, storeKey) {
|
||||
return function currentHook() {
|
||||
const hooksStore = hooks[storeKey];
|
||||
const currentArray = Array.from(hooksStore.__current);
|
||||
return currentArray.at(-1)?.name ?? null;
|
||||
};
|
||||
}
|
||||
var createCurrentHook_default = createCurrentHook;
|
||||
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createDoingHook.js
|
||||
function createDoingHook(hooks, storeKey) {
|
||||
return function doingHook(hookName) {
|
||||
const hooksStore = hooks[storeKey];
|
||||
if ("undefined" === typeof hookName) {
|
||||
return hooksStore.__current.size > 0;
|
||||
}
|
||||
return Array.from(hooksStore.__current).some(
|
||||
(hook) => hook.name === hookName
|
||||
);
|
||||
};
|
||||
}
|
||||
var createDoingHook_default = createDoingHook;
|
||||
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createDidHook.js
|
||||
|
||||
function createDidHook(hooks, storeKey) {
|
||||
return function didHook(hookName) {
|
||||
const hooksStore = hooks[storeKey];
|
||||
if (!validateHookName_default(hookName)) {
|
||||
return;
|
||||
}
|
||||
return hooksStore[hookName] && hooksStore[hookName].runs ? hooksStore[hookName].runs : 0;
|
||||
};
|
||||
}
|
||||
var createDidHook_default = createDidHook;
|
||||
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createHooks.js
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class _Hooks {
|
||||
actions;
|
||||
filters;
|
||||
addAction;
|
||||
addFilter;
|
||||
removeAction;
|
||||
removeFilter;
|
||||
hasAction;
|
||||
hasFilter;
|
||||
removeAllActions;
|
||||
removeAllFilters;
|
||||
doAction;
|
||||
doActionAsync;
|
||||
applyFilters;
|
||||
applyFiltersAsync;
|
||||
currentAction;
|
||||
currentFilter;
|
||||
doingAction;
|
||||
doingFilter;
|
||||
didAction;
|
||||
didFilter;
|
||||
constructor() {
|
||||
this.actions = /* @__PURE__ */ Object.create(null);
|
||||
this.actions.__current = /* @__PURE__ */ new Set();
|
||||
this.filters = /* @__PURE__ */ Object.create(null);
|
||||
this.filters.__current = /* @__PURE__ */ new Set();
|
||||
this.addAction = createAddHook_default(this, "actions");
|
||||
this.addFilter = createAddHook_default(this, "filters");
|
||||
this.removeAction = createRemoveHook_default(this, "actions");
|
||||
this.removeFilter = createRemoveHook_default(this, "filters");
|
||||
this.hasAction = createHasHook_default(this, "actions");
|
||||
this.hasFilter = createHasHook_default(this, "filters");
|
||||
this.removeAllActions = createRemoveHook_default(this, "actions", true);
|
||||
this.removeAllFilters = createRemoveHook_default(this, "filters", true);
|
||||
this.doAction = createRunHook_default(this, "actions", false, false);
|
||||
this.doActionAsync = createRunHook_default(this, "actions", false, true);
|
||||
this.applyFilters = createRunHook_default(this, "filters", true, false);
|
||||
this.applyFiltersAsync = createRunHook_default(this, "filters", true, true);
|
||||
this.currentAction = createCurrentHook_default(this, "actions");
|
||||
this.currentFilter = createCurrentHook_default(this, "filters");
|
||||
this.doingAction = createDoingHook_default(this, "actions");
|
||||
this.doingFilter = createDoingHook_default(this, "filters");
|
||||
this.didAction = createDidHook_default(this, "actions");
|
||||
this.didFilter = createDidHook_default(this, "filters");
|
||||
}
|
||||
}
|
||||
function createHooks() {
|
||||
return new _Hooks();
|
||||
}
|
||||
var createHooks_default = createHooks;
|
||||
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 8770:
|
||||
/***/ (() => {
|
||||
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
/******/ });
|
||||
/************************************************************************/
|
||||
/******/ // The module cache
|
||||
/******/ var __webpack_module_cache__ = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/ // Check if module is in cache
|
||||
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
||||
/******/ if (cachedModule !== undefined) {
|
||||
/******/ return cachedModule.exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = __webpack_module_cache__[moduleId] = {
|
||||
/******/ // no module.id needed
|
||||
/******/ // no module.loaded needed
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/************************************************************************/
|
||||
/******/ /* webpack/runtime/compat get default export */
|
||||
/******/ (() => {
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = (module) => {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ () => (module['default']) :
|
||||
/******/ () => (module);
|
||||
/******/ __webpack_require__.d(getter, { a: getter });
|
||||
/******/ return getter;
|
||||
/******/ };
|
||||
/******/ })();
|
||||
/******/
|
||||
/******/ /* webpack/runtime/define property getters */
|
||||
/******/ (() => {
|
||||
/******/ // define getter functions for harmony exports
|
||||
@@ -34,565 +411,43 @@
|
||||
/******/
|
||||
/************************************************************************/
|
||||
var __webpack_exports__ = {};
|
||||
// ESM COMPAT FLAG
|
||||
// This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
|
||||
(() => {
|
||||
"use strict";
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
|
||||
// EXPORTS
|
||||
__webpack_require__.d(__webpack_exports__, {
|
||||
actions: () => (/* binding */ actions),
|
||||
addAction: () => (/* binding */ addAction),
|
||||
addFilter: () => (/* binding */ addFilter),
|
||||
applyFilters: () => (/* binding */ applyFilters),
|
||||
applyFiltersAsync: () => (/* binding */ applyFiltersAsync),
|
||||
createHooks: () => (/* reexport */ build_module_createHooks),
|
||||
currentAction: () => (/* binding */ currentAction),
|
||||
currentFilter: () => (/* binding */ currentFilter),
|
||||
defaultHooks: () => (/* binding */ defaultHooks),
|
||||
didAction: () => (/* binding */ didAction),
|
||||
didFilter: () => (/* binding */ didFilter),
|
||||
doAction: () => (/* binding */ doAction),
|
||||
doActionAsync: () => (/* binding */ doActionAsync),
|
||||
doingAction: () => (/* binding */ doingAction),
|
||||
doingFilter: () => (/* binding */ doingFilter),
|
||||
filters: () => (/* binding */ filters),
|
||||
hasAction: () => (/* binding */ hasAction),
|
||||
hasFilter: () => (/* binding */ hasFilter),
|
||||
removeAction: () => (/* binding */ removeAction),
|
||||
removeAllActions: () => (/* binding */ removeAllActions),
|
||||
removeAllFilters: () => (/* binding */ removeAllFilters),
|
||||
removeFilter: () => (/* binding */ removeFilter)
|
||||
});
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/validateNamespace.js
|
||||
/**
|
||||
* Validate a namespace string.
|
||||
*
|
||||
* @param {string} namespace The namespace to validate - should take the form
|
||||
* `vendor/plugin/function`.
|
||||
*
|
||||
* @return {boolean} Whether the namespace is valid.
|
||||
*/
|
||||
function validateNamespace(namespace) {
|
||||
if ('string' !== typeof namespace || '' === namespace) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('The namespace must be a non-empty string.');
|
||||
return false;
|
||||
}
|
||||
if (!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(namespace)) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('The namespace can only contain numbers, letters, dashes, periods, underscores and slashes.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/* harmony default export */ const build_module_validateNamespace = (validateNamespace);
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/validateHookName.js
|
||||
/**
|
||||
* Validate a hookName string.
|
||||
*
|
||||
* @param {string} hookName The hook name to validate. Should be a non empty string containing
|
||||
* only numbers, letters, dashes, periods and underscores. Also,
|
||||
* the hook name cannot begin with `__`.
|
||||
*
|
||||
* @return {boolean} Whether the hook name is valid.
|
||||
*/
|
||||
function validateHookName(hookName) {
|
||||
if ('string' !== typeof hookName || '' === hookName) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('The hook name must be a non-empty string.');
|
||||
return false;
|
||||
}
|
||||
if (/^__/.test(hookName)) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('The hook name cannot begin with `__`.');
|
||||
return false;
|
||||
}
|
||||
if (!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(hookName)) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('The hook name can only contain numbers, letters, dashes, periods and underscores.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/* harmony default export */ const build_module_validateHookName = (validateHookName);
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createAddHook.js
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ actions: () => (/* binding */ actions),
|
||||
/* harmony export */ addAction: () => (/* binding */ addAction),
|
||||
/* harmony export */ addFilter: () => (/* binding */ addFilter),
|
||||
/* harmony export */ applyFilters: () => (/* binding */ applyFilters),
|
||||
/* harmony export */ applyFiltersAsync: () => (/* binding */ applyFiltersAsync),
|
||||
/* harmony export */ createHooks: () => (/* reexport safe */ _createHooks__WEBPACK_IMPORTED_MODULE_1__.A),
|
||||
/* harmony export */ currentAction: () => (/* binding */ currentAction),
|
||||
/* harmony export */ currentFilter: () => (/* binding */ currentFilter),
|
||||
/* harmony export */ defaultHooks: () => (/* binding */ defaultHooks),
|
||||
/* harmony export */ didAction: () => (/* binding */ didAction),
|
||||
/* harmony export */ didFilter: () => (/* binding */ didFilter),
|
||||
/* harmony export */ doAction: () => (/* binding */ doAction),
|
||||
/* harmony export */ doActionAsync: () => (/* binding */ doActionAsync),
|
||||
/* harmony export */ doingAction: () => (/* binding */ doingAction),
|
||||
/* harmony export */ doingFilter: () => (/* binding */ doingFilter),
|
||||
/* harmony export */ filters: () => (/* binding */ filters),
|
||||
/* harmony export */ hasAction: () => (/* binding */ hasAction),
|
||||
/* harmony export */ hasFilter: () => (/* binding */ hasFilter),
|
||||
/* harmony export */ removeAction: () => (/* binding */ removeAction),
|
||||
/* harmony export */ removeAllActions: () => (/* binding */ removeAllActions),
|
||||
/* harmony export */ removeAllFilters: () => (/* binding */ removeAllFilters),
|
||||
/* harmony export */ removeFilter: () => (/* binding */ removeFilter)
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var _createHooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(507);
|
||||
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8770);
|
||||
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_types__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};
|
||||
/* harmony reexport (unknown) */ for(const __WEBPACK_IMPORT_KEY__ in _types__WEBPACK_IMPORTED_MODULE_0__) if(["default","actions","addAction","addFilter","applyFilters","applyFiltersAsync","createHooks","currentAction","currentFilter","defaultHooks","didAction","didFilter","doAction","doActionAsync","doingAction","doingFilter","filters","hasAction","hasFilter","removeAction","removeAllActions","removeAllFilters","removeFilter"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = () => _types__WEBPACK_IMPORTED_MODULE_0__[__WEBPACK_IMPORT_KEY__]
|
||||
/* harmony reexport (unknown) */ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @callback AddHook
|
||||
*
|
||||
* Adds the hook to the appropriate hooks container.
|
||||
*
|
||||
* @param {string} hookName Name of hook to add
|
||||
* @param {string} namespace The unique namespace identifying the callback in the form `vendor/plugin/function`.
|
||||
* @param {import('.').Callback} callback Function to call when the hook is run
|
||||
* @param {number} [priority=10] Priority of this hook
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a function which, when invoked, will add a hook.
|
||||
*
|
||||
* @param {import('.').Hooks} hooks Hooks instance.
|
||||
* @param {import('.').StoreKey} storeKey
|
||||
*
|
||||
* @return {AddHook} Function that adds a new hook.
|
||||
*/
|
||||
function createAddHook(hooks, storeKey) {
|
||||
return function addHook(hookName, namespace, callback, priority = 10) {
|
||||
const hooksStore = hooks[storeKey];
|
||||
if (!build_module_validateHookName(hookName)) {
|
||||
return;
|
||||
}
|
||||
if (!build_module_validateNamespace(namespace)) {
|
||||
return;
|
||||
}
|
||||
if ('function' !== typeof callback) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('The hook callback must be a function.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate numeric priority
|
||||
if ('number' !== typeof priority) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('If specified, the hook priority must be a number.');
|
||||
return;
|
||||
}
|
||||
const handler = {
|
||||
callback,
|
||||
priority,
|
||||
namespace
|
||||
};
|
||||
if (hooksStore[hookName]) {
|
||||
// Find the correct insert index of the new hook.
|
||||
const handlers = hooksStore[hookName].handlers;
|
||||
|
||||
/** @type {number} */
|
||||
let i;
|
||||
for (i = handlers.length; i > 0; i--) {
|
||||
if (priority >= handlers[i - 1].priority) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i === handlers.length) {
|
||||
// If append, operate via direct assignment.
|
||||
handlers[i] = handler;
|
||||
} else {
|
||||
// Otherwise, insert before index via splice.
|
||||
handlers.splice(i, 0, handler);
|
||||
}
|
||||
|
||||
// We may also be currently executing this hook. If the callback
|
||||
// we're adding would come after the current callback, there's no
|
||||
// problem; otherwise we need to increase the execution index of
|
||||
// any other runs by 1 to account for the added element.
|
||||
hooksStore.__current.forEach(hookInfo => {
|
||||
if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
|
||||
hookInfo.currentIndex++;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// This is the first hook of its type.
|
||||
hooksStore[hookName] = {
|
||||
handlers: [handler],
|
||||
runs: 0
|
||||
};
|
||||
}
|
||||
if (hookName !== 'hookAdded') {
|
||||
hooks.doAction('hookAdded', hookName, namespace, callback, priority);
|
||||
}
|
||||
};
|
||||
}
|
||||
/* harmony default export */ const build_module_createAddHook = (createAddHook);
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createRemoveHook.js
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @callback RemoveHook
|
||||
* Removes the specified callback (or all callbacks) from the hook with a given hookName
|
||||
* and namespace.
|
||||
*
|
||||
* @param {string} hookName The name of the hook to modify.
|
||||
* @param {string} namespace The unique namespace identifying the callback in the
|
||||
* form `vendor/plugin/function`.
|
||||
*
|
||||
* @return {number | undefined} The number of callbacks removed.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a function which, when invoked, will remove a specified hook or all
|
||||
* hooks by the given name.
|
||||
*
|
||||
* @param {import('.').Hooks} hooks Hooks instance.
|
||||
* @param {import('.').StoreKey} storeKey
|
||||
* @param {boolean} [removeAll=false] Whether to remove all callbacks for a hookName,
|
||||
* without regard to namespace. Used to create
|
||||
* `removeAll*` functions.
|
||||
*
|
||||
* @return {RemoveHook} Function that removes hooks.
|
||||
*/
|
||||
function createRemoveHook(hooks, storeKey, removeAll = false) {
|
||||
return function removeHook(hookName, namespace) {
|
||||
const hooksStore = hooks[storeKey];
|
||||
if (!build_module_validateHookName(hookName)) {
|
||||
return;
|
||||
}
|
||||
if (!removeAll && !build_module_validateNamespace(namespace)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail if no hooks exist by this name.
|
||||
if (!hooksStore[hookName]) {
|
||||
return 0;
|
||||
}
|
||||
let handlersRemoved = 0;
|
||||
if (removeAll) {
|
||||
handlersRemoved = hooksStore[hookName].handlers.length;
|
||||
hooksStore[hookName] = {
|
||||
runs: hooksStore[hookName].runs,
|
||||
handlers: []
|
||||
};
|
||||
} else {
|
||||
// Try to find the specified callback to remove.
|
||||
const handlers = hooksStore[hookName].handlers;
|
||||
for (let i = handlers.length - 1; i >= 0; i--) {
|
||||
if (handlers[i].namespace === namespace) {
|
||||
handlers.splice(i, 1);
|
||||
handlersRemoved++;
|
||||
// This callback may also be part of a hook that is
|
||||
// currently executing. If the callback we're removing
|
||||
// comes after the current callback, there's no problem;
|
||||
// otherwise we need to decrease the execution index of any
|
||||
// other runs by 1 to account for the removed element.
|
||||
hooksStore.__current.forEach(hookInfo => {
|
||||
if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
|
||||
hookInfo.currentIndex--;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hookName !== 'hookRemoved') {
|
||||
hooks.doAction('hookRemoved', hookName, namespace);
|
||||
}
|
||||
return handlersRemoved;
|
||||
};
|
||||
}
|
||||
/* harmony default export */ const build_module_createRemoveHook = (createRemoveHook);
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createHasHook.js
|
||||
/**
|
||||
* @callback HasHook
|
||||
*
|
||||
* Returns whether any handlers are attached for the given hookName and optional namespace.
|
||||
*
|
||||
* @param {string} hookName The name of the hook to check for.
|
||||
* @param {string} [namespace] Optional. The unique namespace identifying the callback
|
||||
* in the form `vendor/plugin/function`.
|
||||
*
|
||||
* @return {boolean} Whether there are handlers that are attached to the given hook.
|
||||
*/
|
||||
/**
|
||||
* Returns a function which, when invoked, will return whether any handlers are
|
||||
* attached to a particular hook.
|
||||
*
|
||||
* @param {import('.').Hooks} hooks Hooks instance.
|
||||
* @param {import('.').StoreKey} storeKey
|
||||
*
|
||||
* @return {HasHook} Function that returns whether any handlers are
|
||||
* attached to a particular hook and optional namespace.
|
||||
*/
|
||||
function createHasHook(hooks, storeKey) {
|
||||
return function hasHook(hookName, namespace) {
|
||||
const hooksStore = hooks[storeKey];
|
||||
|
||||
// Use the namespace if provided.
|
||||
if ('undefined' !== typeof namespace) {
|
||||
return hookName in hooksStore && hooksStore[hookName].handlers.some(hook => hook.namespace === namespace);
|
||||
}
|
||||
return hookName in hooksStore;
|
||||
};
|
||||
}
|
||||
/* harmony default export */ const build_module_createHasHook = (createHasHook);
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createRunHook.js
|
||||
/**
|
||||
* Returns a function which, when invoked, will execute all callbacks
|
||||
* registered to a hook of the specified type, optionally returning the final
|
||||
* value of the call chain.
|
||||
*
|
||||
* @param {import('.').Hooks} hooks Hooks instance.
|
||||
* @param {import('.').StoreKey} storeKey
|
||||
* @param {boolean} returnFirstArg Whether each hook callback is expected to return its first argument.
|
||||
* @param {boolean} async Whether the hook callback should be run asynchronously
|
||||
*
|
||||
* @return {(hookName:string, ...args: unknown[]) => undefined|unknown} Function that runs hook callbacks.
|
||||
*/
|
||||
function createRunHook(hooks, storeKey, returnFirstArg, async) {
|
||||
return function runHook(hookName, ...args) {
|
||||
const hooksStore = hooks[storeKey];
|
||||
if (!hooksStore[hookName]) {
|
||||
hooksStore[hookName] = {
|
||||
handlers: [],
|
||||
runs: 0
|
||||
};
|
||||
}
|
||||
hooksStore[hookName].runs++;
|
||||
const handlers = hooksStore[hookName].handlers;
|
||||
|
||||
// The following code is stripped from production builds.
|
||||
if (false) {}
|
||||
if (!handlers || !handlers.length) {
|
||||
return returnFirstArg ? args[0] : undefined;
|
||||
}
|
||||
const hookInfo = {
|
||||
name: hookName,
|
||||
currentIndex: 0
|
||||
};
|
||||
async function asyncRunner() {
|
||||
try {
|
||||
hooksStore.__current.add(hookInfo);
|
||||
let result = returnFirstArg ? args[0] : undefined;
|
||||
while (hookInfo.currentIndex < handlers.length) {
|
||||
const handler = handlers[hookInfo.currentIndex];
|
||||
result = await handler.callback.apply(null, args);
|
||||
if (returnFirstArg) {
|
||||
args[0] = result;
|
||||
}
|
||||
hookInfo.currentIndex++;
|
||||
}
|
||||
return returnFirstArg ? result : undefined;
|
||||
} finally {
|
||||
hooksStore.__current.delete(hookInfo);
|
||||
}
|
||||
}
|
||||
function syncRunner() {
|
||||
try {
|
||||
hooksStore.__current.add(hookInfo);
|
||||
let result = returnFirstArg ? args[0] : undefined;
|
||||
while (hookInfo.currentIndex < handlers.length) {
|
||||
const handler = handlers[hookInfo.currentIndex];
|
||||
result = handler.callback.apply(null, args);
|
||||
if (returnFirstArg) {
|
||||
args[0] = result;
|
||||
}
|
||||
hookInfo.currentIndex++;
|
||||
}
|
||||
return returnFirstArg ? result : undefined;
|
||||
} finally {
|
||||
hooksStore.__current.delete(hookInfo);
|
||||
}
|
||||
}
|
||||
return (async ? asyncRunner : syncRunner)();
|
||||
};
|
||||
}
|
||||
/* harmony default export */ const build_module_createRunHook = (createRunHook);
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createCurrentHook.js
|
||||
/**
|
||||
* Returns a function which, when invoked, will return the name of the
|
||||
* currently running hook, or `null` if no hook of the given type is currently
|
||||
* running.
|
||||
*
|
||||
* @param {import('.').Hooks} hooks Hooks instance.
|
||||
* @param {import('.').StoreKey} storeKey
|
||||
*
|
||||
* @return {() => string | null} Function that returns the current hook name or null.
|
||||
*/
|
||||
function createCurrentHook(hooks, storeKey) {
|
||||
return function currentHook() {
|
||||
var _currentArray$at$name;
|
||||
const hooksStore = hooks[storeKey];
|
||||
const currentArray = Array.from(hooksStore.__current);
|
||||
return (_currentArray$at$name = currentArray.at(-1)?.name) !== null && _currentArray$at$name !== void 0 ? _currentArray$at$name : null;
|
||||
};
|
||||
}
|
||||
/* harmony default export */ const build_module_createCurrentHook = (createCurrentHook);
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createDoingHook.js
|
||||
/**
|
||||
* @callback DoingHook
|
||||
* Returns whether a hook is currently being executed.
|
||||
*
|
||||
* @param {string} [hookName] The name of the hook to check for. If
|
||||
* omitted, will check for any hook being executed.
|
||||
*
|
||||
* @return {boolean} Whether the hook is being executed.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a function which, when invoked, will return whether a hook is
|
||||
* currently being executed.
|
||||
*
|
||||
* @param {import('.').Hooks} hooks Hooks instance.
|
||||
* @param {import('.').StoreKey} storeKey
|
||||
*
|
||||
* @return {DoingHook} Function that returns whether a hook is currently
|
||||
* being executed.
|
||||
*/
|
||||
function createDoingHook(hooks, storeKey) {
|
||||
return function doingHook(hookName) {
|
||||
const hooksStore = hooks[storeKey];
|
||||
|
||||
// If the hookName was not passed, check for any current hook.
|
||||
if ('undefined' === typeof hookName) {
|
||||
return hooksStore.__current.size > 0;
|
||||
}
|
||||
|
||||
// Find if the `hookName` hook is in `__current`.
|
||||
return Array.from(hooksStore.__current).some(hook => hook.name === hookName);
|
||||
};
|
||||
}
|
||||
/* harmony default export */ const build_module_createDoingHook = (createDoingHook);
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createDidHook.js
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @callback DidHook
|
||||
*
|
||||
* Returns the number of times an action has been fired.
|
||||
*
|
||||
* @param {string} hookName The hook name to check.
|
||||
*
|
||||
* @return {number | undefined} The number of times the hook has run.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a function which, when invoked, will return the number of times a
|
||||
* hook has been called.
|
||||
*
|
||||
* @param {import('.').Hooks} hooks Hooks instance.
|
||||
* @param {import('.').StoreKey} storeKey
|
||||
*
|
||||
* @return {DidHook} Function that returns a hook's call count.
|
||||
*/
|
||||
function createDidHook(hooks, storeKey) {
|
||||
return function didHook(hookName) {
|
||||
const hooksStore = hooks[storeKey];
|
||||
if (!build_module_validateHookName(hookName)) {
|
||||
return;
|
||||
}
|
||||
return hooksStore[hookName] && hooksStore[hookName].runs ? hooksStore[hookName].runs : 0;
|
||||
};
|
||||
}
|
||||
/* harmony default export */ const build_module_createDidHook = (createDidHook);
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/createHooks.js
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Internal class for constructing hooks. Use `createHooks()` function
|
||||
*
|
||||
* Note, it is necessary to expose this class to make its type public.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
class _Hooks {
|
||||
constructor() {
|
||||
/** @type {import('.').Store} actions */
|
||||
this.actions = Object.create(null);
|
||||
this.actions.__current = new Set();
|
||||
|
||||
/** @type {import('.').Store} filters */
|
||||
this.filters = Object.create(null);
|
||||
this.filters.__current = new Set();
|
||||
this.addAction = build_module_createAddHook(this, 'actions');
|
||||
this.addFilter = build_module_createAddHook(this, 'filters');
|
||||
this.removeAction = build_module_createRemoveHook(this, 'actions');
|
||||
this.removeFilter = build_module_createRemoveHook(this, 'filters');
|
||||
this.hasAction = build_module_createHasHook(this, 'actions');
|
||||
this.hasFilter = build_module_createHasHook(this, 'filters');
|
||||
this.removeAllActions = build_module_createRemoveHook(this, 'actions', true);
|
||||
this.removeAllFilters = build_module_createRemoveHook(this, 'filters', true);
|
||||
this.doAction = build_module_createRunHook(this, 'actions', false, false);
|
||||
this.doActionAsync = build_module_createRunHook(this, 'actions', false, true);
|
||||
this.applyFilters = build_module_createRunHook(this, 'filters', true, false);
|
||||
this.applyFiltersAsync = build_module_createRunHook(this, 'filters', true, true);
|
||||
this.currentAction = build_module_createCurrentHook(this, 'actions');
|
||||
this.currentFilter = build_module_createCurrentHook(this, 'filters');
|
||||
this.doingAction = build_module_createDoingHook(this, 'actions');
|
||||
this.doingFilter = build_module_createDoingHook(this, 'filters');
|
||||
this.didAction = build_module_createDidHook(this, 'actions');
|
||||
this.didFilter = build_module_createDidHook(this, 'filters');
|
||||
}
|
||||
}
|
||||
|
||||
/** @typedef {_Hooks} Hooks */
|
||||
|
||||
/**
|
||||
* Returns an instance of the hooks object.
|
||||
*
|
||||
* @return {Hooks} A Hooks instance.
|
||||
*/
|
||||
function createHooks() {
|
||||
return new _Hooks();
|
||||
}
|
||||
/* harmony default export */ const build_module_createHooks = (createHooks);
|
||||
|
||||
;// ./node_modules/@wordpress/hooks/build-module/index.js
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
|
||||
|
||||
/** @typedef {(...args: any[])=>any} Callback */
|
||||
|
||||
/**
|
||||
* @typedef Handler
|
||||
* @property {Callback} callback The callback
|
||||
* @property {string} namespace The namespace
|
||||
* @property {number} priority The namespace
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef Hook
|
||||
* @property {Handler[]} handlers Array of handlers
|
||||
* @property {number} runs Run counter
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef Current
|
||||
* @property {string} name Hook name
|
||||
* @property {number} currentIndex The index
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Record<string, Hook> & {__current: Set<Current>}} Store
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {'actions' | 'filters'} StoreKey
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('./createHooks').Hooks} Hooks
|
||||
*/
|
||||
|
||||
const defaultHooks = build_module_createHooks();
|
||||
const defaultHooks = (0,_createHooks__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .A)();
|
||||
const {
|
||||
addAction,
|
||||
addFilter,
|
||||
@@ -617,6 +472,8 @@ const {
|
||||
} = defaultHooks;
|
||||
|
||||
|
||||
})();
|
||||
|
||||
(window.wp = window.wp || {}).hooks = __webpack_exports__;
|
||||
/******/ })()
|
||||
;
|
||||
Reference in New Issue
Block a user