fix: prevent asset conflicts between React and Grid.js versions

Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-04-18 17:02:14 +07:00
parent bd9cdac02e
commit e8fbfb14c1
74973 changed files with 6658406 additions and 71 deletions

View File

@@ -0,0 +1,93 @@
/**
* Internal dependencies
*/
import validateNamespace from './validateNamespace.js';
import validateHookName from './validateHookName.js';
/**
* @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 (!validateHookName(hookName)) {
return;
}
if (!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);
}
};
}
export default createAddHook;
//# sourceMappingURL=createAddHook.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,19 @@
/**
* 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 _hooksStore$__current;
const hooksStore = hooks[storeKey];
return (_hooksStore$__current = hooksStore.__current[hooksStore.__current.length - 1]?.name) !== null && _hooksStore$__current !== void 0 ? _hooksStore$__current : null;
};
}
export default createCurrentHook;
//# sourceMappingURL=createCurrentHook.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["createCurrentHook","hooks","storeKey","currentHook","_hooksStore$__current","hooksStore","__current","length","name"],"sources":["@wordpress/hooks/src/createCurrentHook.js"],"sourcesContent":["/**\n * Returns a function which, when invoked, will return the name of the\n * currently running hook, or `null` if no hook of the given type is currently\n * running.\n *\n * @param {import('.').Hooks} hooks Hooks instance.\n * @param {import('.').StoreKey} storeKey\n *\n * @return {() => string | null} Function that returns the current hook name or null.\n */\nfunction createCurrentHook( hooks, storeKey ) {\n\treturn function currentHook() {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\treturn (\n\t\t\thooksStore.__current[ hooksStore.__current.length - 1 ]?.name ??\n\t\t\tnull\n\t\t);\n\t};\n}\n\nexport default createCurrentHook;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,iBAAiBA,CAAEC,KAAK,EAAEC,QAAQ,EAAG;EAC7C,OAAO,SAASC,WAAWA,CAAA,EAAG;IAAA,IAAAC,qBAAA;IAC7B,MAAMC,UAAU,GAAGJ,KAAK,CAAEC,QAAQ,CAAE;IAEpC,QAAAE,qBAAA,GACCC,UAAU,CAACC,SAAS,CAAED,UAAU,CAACC,SAAS,CAACC,MAAM,GAAG,CAAC,CAAE,EAAEC,IAAI,cAAAJ,qBAAA,cAAAA,qBAAA,GAC7D,IAAI;EAEN,CAAC;AACF;AAEA,eAAeJ,iBAAiB","ignoreList":[]}

View File

@@ -0,0 +1,35 @@
/**
* Internal dependencies
*/
import validateHookName from './validateHookName.js';
/**
* @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 (!validateHookName(hookName)) {
return;
}
return hooksStore[hookName] && hooksStore[hookName].runs ? hooksStore[hookName].runs : 0;
};
}
export default createDidHook;
//# sourceMappingURL=createDidHook.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["validateHookName","createDidHook","hooks","storeKey","didHook","hookName","hooksStore","runs"],"sources":["@wordpress/hooks/src/createDidHook.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport validateHookName from './validateHookName.js';\n\n/**\n * @callback DidHook\n *\n * Returns the number of times an action has been fired.\n *\n * @param {string} hookName The hook name to check.\n *\n * @return {number | undefined} The number of times the hook has run.\n */\n\n/**\n * Returns a function which, when invoked, will return the number of times a\n * hook has been called.\n *\n * @param {import('.').Hooks} hooks Hooks instance.\n * @param {import('.').StoreKey} storeKey\n *\n * @return {DidHook} Function that returns a hook's call count.\n */\nfunction createDidHook( hooks, storeKey ) {\n\treturn function didHook( hookName ) {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\tif ( ! validateHookName( hookName ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn hooksStore[ hookName ] && hooksStore[ hookName ].runs\n\t\t\t? hooksStore[ hookName ].runs\n\t\t\t: 0;\n\t};\n}\n\nexport default createDidHook;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,gBAAgB,MAAM,uBAAuB;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,aAAaA,CAAEC,KAAK,EAAEC,QAAQ,EAAG;EACzC,OAAO,SAASC,OAAOA,CAAEC,QAAQ,EAAG;IACnC,MAAMC,UAAU,GAAGJ,KAAK,CAAEC,QAAQ,CAAE;IAEpC,IAAK,CAAEH,gBAAgB,CAAEK,QAAS,CAAC,EAAG;MACrC;IACD;IAEA,OAAOC,UAAU,CAAED,QAAQ,CAAE,IAAIC,UAAU,CAAED,QAAQ,CAAE,CAACE,IAAI,GACzDD,UAAU,CAAED,QAAQ,CAAE,CAACE,IAAI,GAC3B,CAAC;EACL,CAAC;AACF;AAEA,eAAeN,aAAa","ignoreList":[]}

View File

@@ -0,0 +1,35 @@
/**
* @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 'undefined' !== typeof hooksStore.__current[0];
}
// Return the __current hook.
return hooksStore.__current[0] ? hookName === hooksStore.__current[0].name : false;
};
}
export default createDoingHook;
//# sourceMappingURL=createDoingHook.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["createDoingHook","hooks","storeKey","doingHook","hookName","hooksStore","__current","name"],"sources":["@wordpress/hooks/src/createDoingHook.js"],"sourcesContent":["/**\n * @callback DoingHook\n * Returns whether a hook is currently being executed.\n *\n * @param {string} [hookName] The name of the hook to check for. If\n * omitted, will check for any hook being executed.\n *\n * @return {boolean} Whether the hook is being executed.\n */\n\n/**\n * Returns a function which, when invoked, will return whether a hook is\n * currently being executed.\n *\n * @param {import('.').Hooks} hooks Hooks instance.\n * @param {import('.').StoreKey} storeKey\n *\n * @return {DoingHook} Function that returns whether a hook is currently\n * being executed.\n */\nfunction createDoingHook( hooks, storeKey ) {\n\treturn function doingHook( hookName ) {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\t// If the hookName was not passed, check for any current hook.\n\t\tif ( 'undefined' === typeof hookName ) {\n\t\t\treturn 'undefined' !== typeof hooksStore.__current[ 0 ];\n\t\t}\n\n\t\t// Return the __current hook.\n\t\treturn hooksStore.__current[ 0 ]\n\t\t\t? hookName === hooksStore.__current[ 0 ].name\n\t\t\t: false;\n\t};\n}\n\nexport default createDoingHook;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,eAAeA,CAAEC,KAAK,EAAEC,QAAQ,EAAG;EAC3C,OAAO,SAASC,SAASA,CAAEC,QAAQ,EAAG;IACrC,MAAMC,UAAU,GAAGJ,KAAK,CAAEC,QAAQ,CAAE;;IAEpC;IACA,IAAK,WAAW,KAAK,OAAOE,QAAQ,EAAG;MACtC,OAAO,WAAW,KAAK,OAAOC,UAAU,CAACC,SAAS,CAAE,CAAC,CAAE;IACxD;;IAEA;IACA,OAAOD,UAAU,CAACC,SAAS,CAAE,CAAC,CAAE,GAC7BF,QAAQ,KAAKC,UAAU,CAACC,SAAS,CAAE,CAAC,CAAE,CAACC,IAAI,GAC3C,KAAK;EACT,CAAC;AACF;AAEA,eAAeP,eAAe","ignoreList":[]}

View File

@@ -0,0 +1,34 @@
/**
* @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;
};
}
export default createHasHook;
//# sourceMappingURL=createHasHook.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["createHasHook","hooks","storeKey","hasHook","hookName","namespace","hooksStore","handlers","some","hook"],"sources":["@wordpress/hooks/src/createHasHook.js"],"sourcesContent":["/**\n * @callback HasHook\n *\n * Returns whether any handlers are attached for the given hookName and optional namespace.\n *\n * @param {string} hookName The name of the hook to check for.\n * @param {string} [namespace] Optional. The unique namespace identifying the callback\n * in the form `vendor/plugin/function`.\n *\n * @return {boolean} Whether there are handlers that are attached to the given hook.\n */\n/**\n * Returns a function which, when invoked, will return whether any handlers are\n * attached to a particular hook.\n *\n * @param {import('.').Hooks} hooks Hooks instance.\n * @param {import('.').StoreKey} storeKey\n *\n * @return {HasHook} Function that returns whether any handlers are\n * attached to a particular hook and optional namespace.\n */\nfunction createHasHook( hooks, storeKey ) {\n\treturn function hasHook( hookName, namespace ) {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\t// Use the namespace if provided.\n\t\tif ( 'undefined' !== typeof namespace ) {\n\t\t\treturn (\n\t\t\t\thookName in hooksStore &&\n\t\t\t\thooksStore[ hookName ].handlers.some(\n\t\t\t\t\t( hook ) => hook.namespace === namespace\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn hookName in hooksStore;\n\t};\n}\n\nexport default createHasHook;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAaA,CAAEC,KAAK,EAAEC,QAAQ,EAAG;EACzC,OAAO,SAASC,OAAOA,CAAEC,QAAQ,EAAEC,SAAS,EAAG;IAC9C,MAAMC,UAAU,GAAGL,KAAK,CAAEC,QAAQ,CAAE;;IAEpC;IACA,IAAK,WAAW,KAAK,OAAOG,SAAS,EAAG;MACvC,OACCD,QAAQ,IAAIE,UAAU,IACtBA,UAAU,CAAEF,QAAQ,CAAE,CAACG,QAAQ,CAACC,IAAI,CACjCC,IAAI,IAAMA,IAAI,CAACJ,SAAS,KAAKA,SAChC,CAAC;IAEH;IAEA,OAAOD,QAAQ,IAAIE,UAAU;EAC9B,CAAC;AACF;AAEA,eAAeN,aAAa","ignoreList":[]}

View File

@@ -0,0 +1,58 @@
/**
* Internal dependencies
*/
import createAddHook from './createAddHook';
import createRemoveHook from './createRemoveHook';
import createHasHook from './createHasHook';
import createRunHook from './createRunHook';
import createCurrentHook from './createCurrentHook';
import createDoingHook from './createDoingHook';
import createDidHook from './createDidHook';
/**
* Internal class for constructing hooks. Use `createHooks()` function
*
* Note, it is necessary to expose this class to make its type public.
*
* @private
*/
export class _Hooks {
constructor() {
/** @type {import('.').Store} actions */
this.actions = Object.create(null);
this.actions.__current = [];
/** @type {import('.').Store} filters */
this.filters = Object.create(null);
this.filters.__current = [];
this.addAction = createAddHook(this, 'actions');
this.addFilter = createAddHook(this, 'filters');
this.removeAction = createRemoveHook(this, 'actions');
this.removeFilter = createRemoveHook(this, 'filters');
this.hasAction = createHasHook(this, 'actions');
this.hasFilter = createHasHook(this, 'filters');
this.removeAllActions = createRemoveHook(this, 'actions', true);
this.removeAllFilters = createRemoveHook(this, 'filters', true);
this.doAction = createRunHook(this, 'actions');
this.applyFilters = createRunHook(this, 'filters', true);
this.currentAction = createCurrentHook(this, 'actions');
this.currentFilter = createCurrentHook(this, 'filters');
this.doingAction = createDoingHook(this, 'actions');
this.doingFilter = createDoingHook(this, 'filters');
this.didAction = createDidHook(this, 'actions');
this.didFilter = createDidHook(this, 'filters');
}
}
/** @typedef {_Hooks} Hooks */
/**
* Returns an instance of the hooks object.
*
* @return {Hooks} A Hooks instance.
*/
function createHooks() {
return new _Hooks();
}
export default createHooks;
//# sourceMappingURL=createHooks.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["createAddHook","createRemoveHook","createHasHook","createRunHook","createCurrentHook","createDoingHook","createDidHook","_Hooks","constructor","actions","Object","create","__current","filters","addAction","addFilter","removeAction","removeFilter","hasAction","hasFilter","removeAllActions","removeAllFilters","doAction","applyFilters","currentAction","currentFilter","doingAction","doingFilter","didAction","didFilter","createHooks"],"sources":["@wordpress/hooks/src/createHooks.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport createAddHook from './createAddHook';\nimport createRemoveHook from './createRemoveHook';\nimport createHasHook from './createHasHook';\nimport createRunHook from './createRunHook';\nimport createCurrentHook from './createCurrentHook';\nimport createDoingHook from './createDoingHook';\nimport createDidHook from './createDidHook';\n\n/**\n * Internal class for constructing hooks. Use `createHooks()` function\n *\n * Note, it is necessary to expose this class to make its type public.\n *\n * @private\n */\nexport class _Hooks {\n\tconstructor() {\n\t\t/** @type {import('.').Store} actions */\n\t\tthis.actions = Object.create( null );\n\t\tthis.actions.__current = [];\n\n\t\t/** @type {import('.').Store} filters */\n\t\tthis.filters = Object.create( null );\n\t\tthis.filters.__current = [];\n\n\t\tthis.addAction = createAddHook( this, 'actions' );\n\t\tthis.addFilter = createAddHook( this, 'filters' );\n\t\tthis.removeAction = createRemoveHook( this, 'actions' );\n\t\tthis.removeFilter = createRemoveHook( this, 'filters' );\n\t\tthis.hasAction = createHasHook( this, 'actions' );\n\t\tthis.hasFilter = createHasHook( this, 'filters' );\n\t\tthis.removeAllActions = createRemoveHook( this, 'actions', true );\n\t\tthis.removeAllFilters = createRemoveHook( this, 'filters', true );\n\t\tthis.doAction = createRunHook( this, 'actions' );\n\t\tthis.applyFilters = createRunHook( this, 'filters', true );\n\t\tthis.currentAction = createCurrentHook( this, 'actions' );\n\t\tthis.currentFilter = createCurrentHook( this, 'filters' );\n\t\tthis.doingAction = createDoingHook( this, 'actions' );\n\t\tthis.doingFilter = createDoingHook( this, 'filters' );\n\t\tthis.didAction = createDidHook( this, 'actions' );\n\t\tthis.didFilter = createDidHook( this, 'filters' );\n\t}\n}\n\n/** @typedef {_Hooks} Hooks */\n\n/**\n * Returns an instance of the hooks object.\n *\n * @return {Hooks} A Hooks instance.\n */\nfunction createHooks() {\n\treturn new _Hooks();\n}\n\nexport default createHooks;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAa,MAAM,iBAAiB;AAC3C,OAAOC,gBAAgB,MAAM,oBAAoB;AACjD,OAAOC,aAAa,MAAM,iBAAiB;AAC3C,OAAOC,aAAa,MAAM,iBAAiB;AAC3C,OAAOC,iBAAiB,MAAM,qBAAqB;AACnD,OAAOC,eAAe,MAAM,mBAAmB;AAC/C,OAAOC,aAAa,MAAM,iBAAiB;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,MAAM,CAAC;EACnBC,WAAWA,CAAA,EAAG;IACb;IACA,IAAI,CAACC,OAAO,GAAGC,MAAM,CAACC,MAAM,CAAE,IAAK,CAAC;IACpC,IAAI,CAACF,OAAO,CAACG,SAAS,GAAG,EAAE;;IAE3B;IACA,IAAI,CAACC,OAAO,GAAGH,MAAM,CAACC,MA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,CAAC;EAClD;AACD;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASwB,WAAWA,CAAA,EAAG;EACtB,OAAO,IAAIvB,MAAM,CAAC,CAAC;AACpB;AAEA,eAAeuB,WAAW","ignoreList":[]}

View File

@@ -0,0 +1,79 @@
/**
* Internal dependencies
*/
import validateNamespace from './validateNamespace.js';
import validateHookName from './validateHookName.js';
/**
* @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 (!validateHookName(hookName)) {
return;
}
if (!removeAll && !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;
};
}
export default createRemoveHook;
//# sourceMappingURL=createRemoveHook.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["validateNamespace","validateHookName","createRemoveHook","hooks","storeKey","removeAll","removeHook","hookName","namespace","hooksStore","handlersRemoved","handlers","length","runs","i","splice","__current","forEach","hookInfo","name","currentIndex","doAction"],"sources":["@wordpress/hooks/src/createRemoveHook.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport validateNamespace from './validateNamespace.js';\nimport validateHookName from './validateHookName.js';\n\n/**\n * @callback RemoveHook\n * Removes the specified callback (or all callbacks) from the hook with a given hookName\n * and namespace.\n *\n * @param {string} hookName The name of the hook to modify.\n * @param {string} namespace The unique namespace identifying the callback in the\n * form `vendor/plugin/function`.\n *\n * @return {number | undefined} The number of callbacks removed.\n */\n\n/**\n * Returns a function which, when invoked, will remove a specified hook or all\n * hooks by the given name.\n *\n * @param {import('.').Hooks} hooks Hooks instance.\n * @param {import('.').StoreKey} storeKey\n * @param {boolean} [removeAll=false] Whether to remove all callbacks for a hookName,\n * without regard to namespace. Used to create\n * `removeAll*` functions.\n *\n * @return {RemoveHook} Function that removes hooks.\n */\nfunction createRemoveHook( hooks, storeKey, removeAll = false ) {\n\treturn function removeHook( hookName, namespace ) {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\tif ( ! validateHookName( hookName ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! removeAll && ! validateNamespace( namespace ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Bail if no hooks exist by this name.\n\t\tif ( ! hooksStore[ hookName ] ) {\n\t\t\treturn 0;\n\t\t}\n\n\t\tlet handlersRemoved = 0;\n\n\t\tif ( removeAll ) {\n\t\t\thandlersRemoved = hooksStore[ hookName ].handlers.length;\n\t\t\thooksStore[ hookName ] = {\n\t\t\t\truns: hooksStore[ hookName ].runs,\n\t\t\t\thandlers: [],\n\t\t\t};\n\t\t} else {\n\t\t\t// Try to find the specified callback to remove.\n\t\t\tconst handlers = hooksStore[ hookName ].handlers;\n\t\t\tfor ( let i = handlers.length - 1; i >= 0; i-- ) {\n\t\t\t\tif ( handlers[ i ].namespace === namespace ) {\n\t\t\t\t\thandlers.splice( i, 1 );\n\t\t\t\t\thandlersRemoved++;\n\t\t\t\t\t// This callback may also be part of a hook that is\n\t\t\t\t\t// currently executing. If the callback we're removing\n\t\t\t\t\t// comes after the current callback, there's no problem;\n\t\t\t\t\t// otherwise we need to decrease the execution index of any\n\t\t\t\t\t// other runs by 1 to account for the removed element.\n\t\t\t\t\thooksStore.__current.forEach( ( hookInfo ) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\thookInfo.name === hookName &&\n\t\t\t\t\t\t\thookInfo.currentIndex >= i\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\thookInfo.currentIndex--;\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif ( hookName !== 'hookRemoved' ) {\n\t\t\thooks.doAction( 'hookRemoved', hookName, namespace );\n\t\t}\n\n\t\treturn handlersRemoved;\n\t};\n}\n\nexport default createRemoveHook;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,iBAAiB,MAAM,wBAAwB;AACtD,OAAOC,gBAAgB,MAAM,uBAAuB;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,gBAAgBA,CAAEC,KAAK,EAAEC,QAAQ,EAAEC,SAAS,GAAG,KAAK,EAAG;EAC/D,OAAO,SAASC,UAAUA,CAAEC,QAAQ,EAAEC,SAAS,EAAG;IACjD,MAAMC,UAAU,GAAGN,KAAK,CAAEC,QAAQ,CAAE;IAEpC,IAAK,CAAEH,gBAAgB,CAAEM,QAAS,CAAC,EAAG;MACrC;IACD;IAEA,IAAK,CAAEF,S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oked, 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=false] Whether each hook callback is expected to
* return its first argument.
*
* @return {(hookName:string, ...args: unknown[]) => undefined|unknown} Function that runs hook callbacks.
*/
function createRunHook(hooks, storeKey, returnFirstArg = false) {
return function runHooks(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 ('production' !== process.env.NODE_ENV) {
// Handle any 'all' hooks registered.
if ('hookAdded' !== hookName && hooksStore.all) {
handlers.push(...hooksStore.all.handlers);
}
}
if (!handlers || !handlers.length) {
return returnFirstArg ? args[0] : undefined;
}
const hookInfo = {
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;
}
hookInfo.currentIndex++;
}
hooksStore.__current.pop();
if (returnFirstArg) {
return args[0];
}
return undefined;
};
}
export default createRunHook;
//# sourceMappingURL=createRunHook.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["createRunHook","hooks","storeKey","returnFirstArg","runHooks","hookName","args","hooksStore","handlers","runs","process","env","NODE_ENV","all","push","length","undefined","hookInfo","name","currentIndex","__current","handler","result","callback","apply","pop"],"sources":["@wordpress/hooks/src/createRunHook.js"],"sourcesContent":["/**\n * Returns a function which, when invoked, will execute all callbacks\n * registered to a hook of the specified type, optionally returning the final\n * value of the call chain.\n *\n * @param {import('.').Hooks} hooks Hooks instance.\n * @param {import('.').StoreKey} storeKey\n * @param {boolean} [returnFirstArg=false] Whether each hook callback is expected to\n * return its first argument.\n *\n * @return {(hookName:string, ...args: unknown[]) => undefined|unknown} Function that runs hook callbacks.\n */\nfunction createRunHook( hooks, storeKey, returnFirstArg = false ) {\n\treturn function runHooks( hookName, ...args ) {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\tif ( ! hooksStore[ hookName ] ) {\n\t\t\thooksStore[ hookName ] = {\n\t\t\t\thandlers: [],\n\t\t\t\truns: 0,\n\t\t\t};\n\t\t}\n\n\t\thooksStore[ hookName ].runs++;\n\n\t\tconst handlers = hooksStore[ hookName ].handlers;\n\n\t\t// The following code is stripped from production builds.\n\t\tif ( 'production' !== process.env.NODE_ENV ) {\n\t\t\t// Handle any 'all' hooks registered.\n\t\t\tif ( 'hookAdded' !== hookName && hooksStore.all ) {\n\t\t\t\thandlers.push( ...hooksStore.all.handlers );\n\t\t\t}\n\t\t}\n\n\t\tif ( ! handlers || ! handlers.length ) {\n\t\t\treturn returnFirstArg ? args[ 0 ] : undefined;\n\t\t}\n\n\t\tconst hookInfo = {\n\t\t\tname: hookName,\n\t\t\tcurrentIndex: 0,\n\t\t};\n\n\t\thooksStore.__current.push( hookInfo );\n\n\t\twhile ( hookInfo.currentIndex < handlers.length ) {\n\t\t\tconst handler = handlers[ hookInfo.currentIndex ];\n\n\t\t\tconst result = handler.callback.apply( null, args );\n\t\t\tif ( returnFirstArg ) {\n\t\t\t\targs[ 0 ] = result;\n\t\t\t}\n\n\t\t\thookInfo.currentIndex++;\n\t\t}\n\n\t\thooksStore.__current.pop();\n\n\t\tif ( returnFirstArg ) {\n\t\t\treturn args[ 0 ];\n\t\t}\n\n\t\treturn undefined;\n\t};\n}\n\nexport default createRunHook;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAaA,CAAEC,KAAK,EAAEC,QAAQ,EAAEC,cAAc,GAAG,KAAK,EAAG;EACjE,OAAO,SAASC,QAAQA,CAAEC,QAAQ,EAAE,GAAGC,IAAI,EAAG;IAC7C,MAAMC,UAAU,GAAGN,KAAK,CAAEC,QAAQ,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AAE;IACjB;IAEA,OAAOU,SAAS;EACjB,CAAC;AACF;AAEA,eAAehB,aAAa","ignoreList":[]}

61
node_modules/@wordpress/hooks/build-module/index.js generated vendored Normal file
View File

@@ -0,0 +1,61 @@
/**
* Internal dependencies
*/
import createHooks from './createHooks';
/** @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: Current[]}} Store
*/
/**
* @typedef {'actions' | 'filters'} StoreKey
*/
/**
* @typedef {import('./createHooks').Hooks} Hooks
*/
export const defaultHooks = createHooks();
const {
addAction,
addFilter,
removeAction,
removeFilter,
hasAction,
hasFilter,
removeAllActions,
removeAllFilters,
doAction,
applyFilters,
currentAction,
currentFilter,
doingAction,
doingFilter,
didAction,
didFilter,
actions,
filters
} = defaultHooks;
export { createHooks, addAction, addFilter, removeAction, removeFilter, hasAction, hasFilter, removeAllActions, removeAllFilters, doAction, applyFilters, currentAction, currentFilter, doingAction, doingFilter, didAction, didFilter, actions, filters };
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["createHooks","defaultHooks","addAction","addFilter","removeAction","removeFilter","hasAction","hasFilter","removeAllActions","removeAllFilters","doAction","applyFilters","currentAction","currentFilter","doingAction","doingFilter","didAction","didFilter","actions","filters"],"sources":["@wordpress/hooks/src/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport createHooks from './createHooks';\n\n/** @typedef {(...args: any[])=>any} Callback */\n\n/**\n * @typedef Handler\n * @property {Callback} callback The callback\n * @property {string} namespace The namespace\n * @property {number} priority The namespace\n */\n\n/**\n * @typedef Hook\n * @property {Handler[]} handlers Array of handlers\n * @property {number} runs Run counter\n */\n\n/**\n * @typedef Current\n * @property {string} name Hook name\n * @property {number} currentIndex The index\n */\n\n/**\n * @typedef {Record<string, Hook> & {__current: Current[]}} Store\n */\n\n/**\n * @typedef {'actions' | 'filters'} StoreKey\n */\n\n/**\n * @typedef {import('./createHooks').Hooks} Hooks\n */\n\nexport const defaultHooks = createHooks();\n\nconst {\n\taddAction,\n\taddFilter,\n\tremoveAction,\n\tremoveFilter,\n\thasAction,\n\thasFilter,\n\tremoveAllActions,\n\tremoveAllFilters,\n\tdoAction,\n\tapplyFilters,\n\tcurrentAction,\n\tcurrentFilter,\n\tdoingAction,\n\tdoingFilter,\n\tdidAction,\n\tdidFilter,\n\tactions,\n\tfilters,\n} = defaultHooks;\n\nexport {\n\tcreateHooks,\n\taddAction,\n\taddFilter,\n\tremoveAction,\n\tremoveFilter,\n\thasAction,\n\thasFilter,\n\tremoveAllActions,\n\tremoveAllFilters,\n\tdoAction,\n\tapplyFilters,\n\tcurrentAction,\n\tcurrentFilter,\n\tdoingAction,\n\tdoingFilter,\n\tdidAction,\n\tdidFilter,\n\tactions,\n\tfilters,\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAW,MAAM,eAAe;;AAEvC;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,OAAO,MAAMC,YAAY,GAAGD,WAAW,CAAC,CAAC;AAEzC,MAAM;EACLE,SAAS;EACTC,SAAS;EACTC,YAAY;EACZC,YAAY;EACZC,SAAS;EACTC,SAAS;EACTC,gBAAgB;EAChBC,gBAAgB;EAChBC,QAAQ;EACRC,YAAY;EACZC,aAAa;EACbC,aAAa;EACbC,WAAW;EACXC,WAAW;EACXC,SAAS;EACTC,SAAS;EACTC,OAAO;EACPC;AACD,CAAC,GAAGlB,YAAY;AAEhB,SACCD,WAAW,EACXE,SAAS,EACTC,SAAS,EACTC,YAAY,EACZC,YAAY,EACZC,SAAS,EACTC,SAAS,EACTC,gBAAgB,EAChBC,gBAAgB,EAChBC,QAAQ,EACRC,YAAY,EACZC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,WAAW,EACXC,SAAS,EACTC,SAAS,EACTC,OAAO,EACPC,OAAO","ignoreList":[]}

View File

@@ -0,0 +1,29 @@
/**
* 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;
}
export default validateHookName;
//# sourceMappingURL=validateHookName.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["validateHookName","hookName","console","error","test"],"sources":["@wordpress/hooks/src/validateHookName.js"],"sourcesContent":["/**\n * Validate a hookName string.\n *\n * @param {string} hookName The hook name to validate. Should be a non empty string containing\n * only numbers, letters, dashes, periods and underscores. Also,\n * the hook name cannot begin with `__`.\n *\n * @return {boolean} Whether the hook name is valid.\n */\nfunction validateHookName( hookName ) {\n\tif ( 'string' !== typeof hookName || '' === hookName ) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error( 'The hook name must be a non-empty string.' );\n\t\treturn false;\n\t}\n\n\tif ( /^__/.test( hookName ) ) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error( 'The hook name cannot begin with `__`.' );\n\t\treturn false;\n\t}\n\n\tif ( ! /^[a-zA-Z][a-zA-Z0-9_.-]*$/.test( hookName ) ) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error(\n\t\t\t'The hook name can only contain numbers, letters, dashes, periods and underscores.'\n\t\t);\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nexport default validateHookName;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,gBAAgBA,CAAEC,QAAQ,EAAG;EACrC,IAAK,QAAQ,KAAK,OAAOA,QAAQ,IAAI,EAAE,KAAKA,QAAQ,EAAG;IACtD;IACAC,OAAO,CAACC,KAAK,CAAE,2CAA4C,CAAC;IAC5D,OAAO,KAAK;EACb;EAEA,IAAK,KAAK,CAACC,IAAI,CAAEH,QAAS,CAAC,EAAG;IAC7B;IACAC,OAAO,CAACC,KAAK,CAAE,uCAAwC,CAAC;IACxD,OAAO,KAAK;EACb;EAEA,IAAK,CAAE,2BAA2B,CAACC,IAAI,CAAEH,QAAS,CAAC,EAAG;IACrD;IACAC,OAAO,CAACC,KAAK,CACZ,mFACD,CAAC;IACD,OAAO,KAAK;EACb;EAEA,OAAO,IAAI;AACZ;AAEA,eAAeH,gBAAgB","ignoreList":[]}

View File

@@ -0,0 +1,23 @@
/**
* 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;
}
export default validateNamespace;
//# sourceMappingURL=validateNamespace.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["validateNamespace","namespace","console","error","test"],"sources":["@wordpress/hooks/src/validateNamespace.js"],"sourcesContent":["/**\n * Validate a namespace string.\n *\n * @param {string} namespace The namespace to validate - should take the form\n * `vendor/plugin/function`.\n *\n * @return {boolean} Whether the namespace is valid.\n */\nfunction validateNamespace( namespace ) {\n\tif ( 'string' !== typeof namespace || '' === namespace ) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error( 'The namespace must be a non-empty string.' );\n\t\treturn false;\n\t}\n\n\tif ( ! /^[a-zA-Z][a-zA-Z0-9_.\\-\\/]*$/.test( namespace ) ) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error(\n\t\t\t'The namespace can only contain numbers, letters, dashes, periods, underscores and slashes.'\n\t\t);\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nexport default validateNamespace;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,iBAAiBA,CAAEC,SAAS,EAAG;EACvC,IAAK,QAAQ,KAAK,OAAOA,SAAS,IAAI,EAAE,KAAKA,SAAS,EAAG;IACxD;IACAC,OAAO,CAACC,KAAK,CAAE,2CAA4C,CAAC;IAC5D,OAAO,KAAK;EACb;EAEA,IAAK,CAAE,8BAA8B,CAACC,IAAI,CAAEH,SAAU,CAAC,EAAG;IACzD;IACAC,OAAO,CAACC,KAAK,CACZ,4FACD,CAAC;IACD,OAAO,KAAK;EACb;EAEA,OAAO,IAAI;AACZ;AAEA,eAAeH,iBAAiB","ignoreList":[]}