plugin updates

This commit is contained in:
Tony Volpe
2024-11-15 13:53:04 -05:00
parent 1293d604ca
commit 0238f0c4ca
2009 changed files with 163492 additions and 89543 deletions

View File

@@ -43,6 +43,7 @@ __webpack_require__.d(__webpack_exports__, {
addAction: () => (/* binding */ addAction),
addFilter: () => (/* binding */ addFilter),
applyFilters: () => (/* binding */ applyFilters),
applyFiltersAsync: () => (/* binding */ applyFiltersAsync),
createHooks: () => (/* reexport */ build_module_createHooks),
currentAction: () => (/* binding */ currentAction),
currentFilter: () => (/* binding */ currentFilter),
@@ -50,6 +51,7 @@ __webpack_require__.d(__webpack_exports__, {
didAction: () => (/* binding */ didAction),
didFilter: () => (/* binding */ didFilter),
doAction: () => (/* binding */ doAction),
doActionAsync: () => (/* binding */ doActionAsync),
doingAction: () => (/* binding */ doingAction),
doingFilter: () => (/* binding */ doingFilter),
filters: () => (/* binding */ filters),
@@ -330,15 +332,15 @@ function createHasHook(hooks, storeKey) {
* 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('.').Hooks} hooks Hooks instance.
* @param {import('.').StoreKey} storeKey
* @param {boolean} [returnFirstArg=false] Whether each hook callback is expected to
* return its first argument.
* @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 = false) {
return function runHooks(hookName, ...args) {
function createRunHook(hooks, storeKey, returnFirstArg, async) {
return function runHook(hookName, ...args) {
const hooksStore = hooks[storeKey];
if (!hooksStore[hookName]) {
hooksStore[hookName] = {
@@ -358,20 +360,41 @@ function createRunHook(hooks, storeKey, returnFirstArg = false) {
name: hookName,
currentIndex: 0
};
hooksStore.__current.push(hookInfo);
while (hookInfo.currentIndex < handlers.length) {
const handler = handlers[hookInfo.currentIndex];
const result = handler.callback.apply(null, args);
if (returnFirstArg) {
args[0] = result;
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);
}
hookInfo.currentIndex++;
}
hooksStore.__current.pop();
if (returnFirstArg) {
return args[0];
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 undefined;
return (async ? asyncRunner : syncRunner)();
};
}
/* harmony default export */ const build_module_createRunHook = (createRunHook);
@@ -389,9 +412,10 @@ function createRunHook(hooks, storeKey, returnFirstArg = false) {
*/
function createCurrentHook(hooks, storeKey) {
return function currentHook() {
var _hooksStore$__current;
var _currentArray$at$name;
const hooksStore = hooks[storeKey];
return (_hooksStore$__current = hooksStore.__current[hooksStore.__current.length - 1]?.name) !== null && _hooksStore$__current !== void 0 ? _hooksStore$__current : null;
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);
@@ -423,11 +447,11 @@ function createDoingHook(hooks, storeKey) {
// If the hookName was not passed, check for any current hook.
if ('undefined' === typeof hookName) {
return 'undefined' !== typeof hooksStore.__current[0];
return hooksStore.__current.size > 0;
}
// Return the __current hook.
return hooksStore.__current[0] ? hookName === hooksStore.__current[0].name : false;
// 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);
@@ -491,11 +515,11 @@ class _Hooks {
constructor() {
/** @type {import('.').Store} actions */
this.actions = Object.create(null);
this.actions.__current = [];
this.actions.__current = new Set();
/** @type {import('.').Store} filters */
this.filters = Object.create(null);
this.filters.__current = [];
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');
@@ -504,8 +528,10 @@ class _Hooks {
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');
this.applyFilters = build_module_createRunHook(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');
@@ -555,7 +581,7 @@ function createHooks() {
*/
/**
* @typedef {Record<string, Hook> & {__current: Current[]}} Store
* @typedef {Record<string, Hook> & {__current: Set<Current>}} Store
*/
/**
@@ -577,7 +603,9 @@ const {
removeAllActions,
removeAllFilters,
doAction,
doActionAsync,
applyFilters,
applyFiltersAsync,
currentAction,
currentFilter,
doingAction,