@wordpress/hooks 3.39.0 → 3.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/createAddHook.js +6 -19
- package/build/createAddHook.js.map +1 -1
- package/build/createCurrentHook.js +0 -3
- package/build/createCurrentHook.js.map +1 -1
- package/build/createDidHook.js +0 -6
- package/build/createDidHook.js.map +1 -1
- package/build/createDoingHook.js +4 -5
- package/build/createDoingHook.js.map +1 -1
- package/build/createHasHook.js +2 -5
- package/build/createHasHook.js.map +1 -1
- package/build/createHooks.js +2 -15
- package/build/createHooks.js.map +1 -1
- package/build/createRemoveHook.js +4 -16
- package/build/createRemoveHook.js.map +1 -1
- package/build/createRunHook.js +4 -14
- package/build/createRunHook.js.map +1 -1
- package/build/index.js +1 -3
- package/build/index.js.map +1 -1
- package/build/validateHookName.js +0 -5
- package/build/validateHookName.js.map +1 -1
- package/build/validateNamespace.js +0 -4
- package/build/validateNamespace.js.map +1 -1
- package/build-module/createAddHook.js +7 -16
- package/build-module/createAddHook.js.map +1 -1
- package/build-module/createCurrentHook.js +0 -2
- package/build-module/createCurrentHook.js.map +1 -1
- package/build-module/createDidHook.js +1 -4
- package/build-module/createDidHook.js.map +1 -1
- package/build-module/createDoingHook.js +4 -4
- package/build-module/createDoingHook.js.map +1 -1
- package/build-module/createHasHook.js +2 -4
- package/build-module/createHasHook.js.map +1 -1
- package/build-module/createHooks.js +3 -5
- package/build-module/createHooks.js.map +1 -1
- package/build-module/createRemoveHook.js +5 -13
- package/build-module/createRemoveHook.js.map +1 -1
- package/build-module/createRunHook.js +4 -13
- package/build-module/createRunHook.js.map +1 -1
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/validateHookName.js +0 -4
- package/build-module/validateHookName.js.map +1 -1
- package/build-module/validateNamespace.js +0 -3
- package/build-module/validateNamespace.js.map +1 -1
- package/build-types/createRunHook.d.ts +2 -2
- package/build-types/createRunHook.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/createRunHook.js +3 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/build/createAddHook.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _validateNamespace = _interopRequireDefault(require("./validateNamespace.js"));
|
|
11
|
-
|
|
12
9
|
var _validateHookName = _interopRequireDefault(require("./validateHookName.js"));
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* Internal dependencies
|
|
16
12
|
*/
|
|
@@ -37,59 +33,52 @@ var _validateHookName = _interopRequireDefault(require("./validateHookName.js"))
|
|
|
37
33
|
function createAddHook(hooks, storeKey) {
|
|
38
34
|
return function addHook(hookName, namespace, callback, priority = 10) {
|
|
39
35
|
const hooksStore = hooks[storeKey];
|
|
40
|
-
|
|
41
36
|
if (!(0, _validateHookName.default)(hookName)) {
|
|
42
37
|
return;
|
|
43
38
|
}
|
|
44
|
-
|
|
45
39
|
if (!(0, _validateNamespace.default)(namespace)) {
|
|
46
40
|
return;
|
|
47
41
|
}
|
|
48
|
-
|
|
49
42
|
if ('function' !== typeof callback) {
|
|
50
43
|
// eslint-disable-next-line no-console
|
|
51
44
|
console.error('The hook callback must be a function.');
|
|
52
45
|
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
46
|
+
}
|
|
55
47
|
|
|
48
|
+
// Validate numeric priority
|
|
56
49
|
if ('number' !== typeof priority) {
|
|
57
50
|
// eslint-disable-next-line no-console
|
|
58
51
|
console.error('If specified, the hook priority must be a number.');
|
|
59
52
|
return;
|
|
60
53
|
}
|
|
61
|
-
|
|
62
54
|
const handler = {
|
|
63
55
|
callback,
|
|
64
56
|
priority,
|
|
65
57
|
namespace
|
|
66
58
|
};
|
|
67
|
-
|
|
68
59
|
if (hooksStore[hookName]) {
|
|
69
60
|
// Find the correct insert index of the new hook.
|
|
70
61
|
const handlers = hooksStore[hookName].handlers;
|
|
71
|
-
/** @type {number} */
|
|
72
62
|
|
|
63
|
+
/** @type {number} */
|
|
73
64
|
let i;
|
|
74
|
-
|
|
75
65
|
for (i = handlers.length; i > 0; i--) {
|
|
76
66
|
if (priority >= handlers[i - 1].priority) {
|
|
77
67
|
break;
|
|
78
68
|
}
|
|
79
69
|
}
|
|
80
|
-
|
|
81
70
|
if (i === handlers.length) {
|
|
82
71
|
// If append, operate via direct assignment.
|
|
83
72
|
handlers[i] = handler;
|
|
84
73
|
} else {
|
|
85
74
|
// Otherwise, insert before index via splice.
|
|
86
75
|
handlers.splice(i, 0, handler);
|
|
87
|
-
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// We may also be currently executing this hook. If the callback
|
|
88
79
|
// we're adding would come after the current callback, there's no
|
|
89
80
|
// problem; otherwise we need to increase the execution index of
|
|
90
81
|
// any other runs by 1 to account for the added element.
|
|
91
|
-
|
|
92
|
-
|
|
93
82
|
hooksStore.__current.forEach(hookInfo => {
|
|
94
83
|
if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
|
|
95
84
|
hookInfo.currentIndex++;
|
|
@@ -102,13 +91,11 @@ function createAddHook(hooks, storeKey) {
|
|
|
102
91
|
runs: 0
|
|
103
92
|
};
|
|
104
93
|
}
|
|
105
|
-
|
|
106
94
|
if (hookName !== 'hookAdded') {
|
|
107
95
|
hooks.doAction('hookAdded', hookName, namespace, callback, priority);
|
|
108
96
|
}
|
|
109
97
|
};
|
|
110
98
|
}
|
|
111
|
-
|
|
112
99
|
var _default = createAddHook;
|
|
113
100
|
exports.default = _default;
|
|
114
101
|
//# sourceMappingURL=createAddHook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_validateNamespace","_interopRequireDefault","require","_validateHookName","createAddHook","hooks","storeKey","addHook","hookName","namespace","callback","priority","hooksStore","validateHookName","validateNamespace","console","error","handler","handlers","i","length","splice","__current","forEach","hookInfo","name","currentIndex","runs","doAction","_default","exports","default"],"sources":["@wordpress/hooks/src/createAddHook.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport validateNamespace from './validateNamespace.js';\nimport validateHookName from './validateHookName.js';\n\n/**\n * @callback AddHook\n *\n * Adds the hook to the appropriate hooks container.\n *\n * @param {string} hookName Name of hook to add\n * @param {string} namespace The unique namespace identifying the callback in the form `vendor/plugin/function`.\n * @param {import('.').Callback} callback Function to call when the hook is run\n * @param {number} [priority=10] Priority of this hook\n */\n\n/**\n * Returns a function which, when invoked, will add a hook.\n *\n * @param {import('.').Hooks} hooks Hooks instance.\n * @param {import('.').StoreKey} storeKey\n *\n * @return {AddHook} Function that adds a new hook.\n */\nfunction createAddHook( hooks, storeKey ) {\n\treturn function addHook( hookName, namespace, callback, priority = 10 ) {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\tif ( ! validateHookName( hookName ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! validateNamespace( namespace ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( 'function' !== typeof callback ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'The hook callback must be a function.' );\n\t\t\treturn;\n\t\t}\n\n\t\t// Validate numeric priority\n\t\tif ( 'number' !== typeof priority ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error(\n\t\t\t\t'If specified, the hook priority must be a number.'\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst handler = { callback, priority, namespace };\n\n\t\tif ( hooksStore[ hookName ] ) {\n\t\t\t// Find the correct insert index of the new hook.\n\t\t\tconst handlers = hooksStore[ hookName ].handlers;\n\n\t\t\t/** @type {number} */\n\t\t\tlet i;\n\t\t\tfor ( i = handlers.length; i > 0; i-- ) {\n\t\t\t\tif ( priority >= handlers[ i - 1 ].priority ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( i === handlers.length ) {\n\t\t\t\t// If append, operate via direct assignment.\n\t\t\t\thandlers[ i ] = handler;\n\t\t\t} else {\n\t\t\t\t// Otherwise, insert before index via splice.\n\t\t\t\thandlers.splice( i, 0, handler );\n\t\t\t}\n\n\t\t\t// We may also be currently executing this hook. If the callback\n\t\t\t// we're adding would come after the current callback, there's no\n\t\t\t// problem; otherwise we need to increase the execution index of\n\t\t\t// any other runs by 1 to account for the added element.\n\t\t\thooksStore.__current.forEach( ( hookInfo ) => {\n\t\t\t\tif (\n\t\t\t\t\thookInfo.name === hookName &&\n\t\t\t\t\thookInfo.currentIndex >= i\n\t\t\t\t) {\n\t\t\t\t\thookInfo.currentIndex++;\n\t\t\t\t}\n\t\t\t} );\n\t\t} else {\n\t\t\t// This is the first hook of its type.\n\t\t\thooksStore[ hookName ] = {\n\t\t\t\thandlers: [ handler ],\n\t\t\t\truns: 0,\n\t\t\t};\n\t\t}\n\n\t\tif ( hookName !== 'hookAdded' ) {\n\t\t\thooks.doAction(\n\t\t\t\t'hookAdded',\n\t\t\t\thookName,\n\t\t\t\tnamespace,\n\t\t\t\tcallback,\n\t\t\t\tpriority\n\t\t\t);\n\t\t}\n\t};\n}\n\nexport default createAddHook;\n"],"mappings":";;;;;;;AAGA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAF,sBAAA,CAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,aAAaA,CAAEC,KAAK,EAAEC,QAAQ,EAAG;EACzC,OAAO,SAASC,OAAOA,CAAEC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1BgB,QAAQ,CAACE,YAAY,IAAIP,CAAC,EACzB;UACDK,QAAQ,CAACE,YAAY,EAAE;QACxB;MACD,CAAE,CAAC;IACJ,CAAC,MAAM;MACN;MACAd,UAAU,CAAEJ,QAAQ,CAAE,GAAG;QACxBU,QAAQ,EAAE,CAAED,OAAO,CAAE;QACrBU,IAAI,EAAE;MACP,CAAC;IACF;IAEA,IAAKnB,QAAQ,KAAK,WAAW,EAAG;MAC/BH,KAAK,CAACuB,QAAQ,CACb,WAAW,EACXpB,QAAQ,EACRC,SAAS,EACTC,QAAQ,EACRC,QACD,CAAC;IACF;EACD,CAAC;AACF;AAAC,IAAAkB,QAAA,GAEczB,aAAa;AAAA0B,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Returns a function which, when invoked, will return the name of the
|
|
10
9
|
* currently running hook, or `null` if no hook of the given type is currently
|
|
@@ -18,12 +17,10 @@ exports.default = void 0;
|
|
|
18
17
|
function createCurrentHook(hooks, storeKey) {
|
|
19
18
|
return function currentHook() {
|
|
20
19
|
var _hooksStore$__current;
|
|
21
|
-
|
|
22
20
|
const hooksStore = hooks[storeKey];
|
|
23
21
|
return (_hooksStore$__current = hooksStore.__current[hooksStore.__current.length - 1]?.name) !== null && _hooksStore$__current !== void 0 ? _hooksStore$__current : null;
|
|
24
22
|
};
|
|
25
23
|
}
|
|
26
|
-
|
|
27
24
|
var _default = createCurrentHook;
|
|
28
25
|
exports.default = _default;
|
|
29
26
|
//# sourceMappingURL=createCurrentHook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createCurrentHook","hooks","storeKey","currentHook","_hooksStore$__current","hooksStore","__current","length","name","_default","exports","default"],"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;AAAC,IAAAK,QAAA,GAEcT,iBAAiB;AAAAU,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
package/build/createDidHook.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _validateHookName = _interopRequireDefault(require("./validateHookName.js"));
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Internal dependencies
|
|
14
11
|
*/
|
|
@@ -35,15 +32,12 @@ var _validateHookName = _interopRequireDefault(require("./validateHookName.js"))
|
|
|
35
32
|
function createDidHook(hooks, storeKey) {
|
|
36
33
|
return function didHook(hookName) {
|
|
37
34
|
const hooksStore = hooks[storeKey];
|
|
38
|
-
|
|
39
35
|
if (!(0, _validateHookName.default)(hookName)) {
|
|
40
36
|
return;
|
|
41
37
|
}
|
|
42
|
-
|
|
43
38
|
return hooksStore[hookName] && hooksStore[hookName].runs ? hooksStore[hookName].runs : 0;
|
|
44
39
|
};
|
|
45
40
|
}
|
|
46
|
-
|
|
47
41
|
var _default = createDidHook;
|
|
48
42
|
exports.default = _default;
|
|
49
43
|
//# sourceMappingURL=createDidHook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_validateHookName","_interopRequireDefault","require","createDidHook","hooks","storeKey","didHook","hookName","hooksStore","validateHookName","runs","_default","exports","default"],"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":";;;;;;;AAGA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;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,CAAE,IAAAI,yBAAgB,EAAEF,QAAS,CAAC,EAAG;MACrC;IACD;IAEA,OAAOC,UAAU,CAAED,QAAQ,CAAE,IAAIC,UAAU,CAAED,QAAQ,CAAE,CAACG,IAAI,GACzDF,UAAU,CAAED,QAAQ,CAAE,CAACG,IAAI,GAC3B,CAAC;EACL,CAAC;AACF;AAAC,IAAAC,QAAA,GAEcR,aAAa;AAAAS,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
package/build/createDoingHook.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* @callback DoingHook
|
|
10
9
|
* Returns whether a hook is currently being executed.
|
|
@@ -27,17 +26,17 @@ exports.default = void 0;
|
|
|
27
26
|
*/
|
|
28
27
|
function createDoingHook(hooks, storeKey) {
|
|
29
28
|
return function doingHook(hookName) {
|
|
30
|
-
const hooksStore = hooks[storeKey];
|
|
29
|
+
const hooksStore = hooks[storeKey];
|
|
31
30
|
|
|
31
|
+
// If the hookName was not passed, check for any current hook.
|
|
32
32
|
if ('undefined' === typeof hookName) {
|
|
33
33
|
return 'undefined' !== typeof hooksStore.__current[0];
|
|
34
|
-
}
|
|
35
|
-
|
|
34
|
+
}
|
|
36
35
|
|
|
36
|
+
// Return the __current hook.
|
|
37
37
|
return hooksStore.__current[0] ? hookName === hooksStore.__current[0].name : false;
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
|
|
41
40
|
var _default = createDoingHook;
|
|
42
41
|
exports.default = _default;
|
|
43
42
|
//# sourceMappingURL=createDoingHook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createDoingHook","hooks","storeKey","doingHook","hookName","hooksStore","__current","name","_default","exports","default"],"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;AAAC,IAAAC,QAAA,GAEcR,eAAe;AAAAS,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
package/build/createHasHook.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* @callback HasHook
|
|
10
9
|
*
|
|
@@ -16,7 +15,6 @@ exports.default = void 0;
|
|
|
16
15
|
*
|
|
17
16
|
* @return {boolean} Whether there are handlers that are attached to the given hook.
|
|
18
17
|
*/
|
|
19
|
-
|
|
20
18
|
/**
|
|
21
19
|
* Returns a function which, when invoked, will return whether any handlers are
|
|
22
20
|
* attached to a particular hook.
|
|
@@ -29,16 +27,15 @@ exports.default = void 0;
|
|
|
29
27
|
*/
|
|
30
28
|
function createHasHook(hooks, storeKey) {
|
|
31
29
|
return function hasHook(hookName, namespace) {
|
|
32
|
-
const hooksStore = hooks[storeKey];
|
|
30
|
+
const hooksStore = hooks[storeKey];
|
|
33
31
|
|
|
32
|
+
// Use the namespace if provided.
|
|
34
33
|
if ('undefined' !== typeof namespace) {
|
|
35
34
|
return hookName in hooksStore && hooksStore[hookName].handlers.some(hook => hook.namespace === namespace);
|
|
36
35
|
}
|
|
37
|
-
|
|
38
36
|
return hookName in hooksStore;
|
|
39
37
|
};
|
|
40
38
|
}
|
|
41
|
-
|
|
42
39
|
var _default = createHasHook;
|
|
43
40
|
exports.default = _default;
|
|
44
41
|
//# sourceMappingURL=createHasHook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createHasHook","hooks","storeKey","hasHook","hookName","namespace","hooksStore","handlers","some","hook","_default","exports","default"],"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;AAAC,IAAAI,QAAA,GAEcV,aAAa;AAAAW,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
package/build/createHooks.js
CHANGED
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = exports._Hooks = void 0;
|
|
9
|
-
|
|
10
8
|
var _createAddHook = _interopRequireDefault(require("./createAddHook"));
|
|
11
|
-
|
|
12
9
|
var _createRemoveHook = _interopRequireDefault(require("./createRemoveHook"));
|
|
13
|
-
|
|
14
10
|
var _createHasHook = _interopRequireDefault(require("./createHasHook"));
|
|
15
|
-
|
|
16
11
|
var _createRunHook = _interopRequireDefault(require("./createRunHook"));
|
|
17
|
-
|
|
18
12
|
var _createCurrentHook = _interopRequireDefault(require("./createCurrentHook"));
|
|
19
|
-
|
|
20
13
|
var _createDoingHook = _interopRequireDefault(require("./createDoingHook"));
|
|
21
|
-
|
|
22
14
|
var _createDidHook = _interopRequireDefault(require("./createDidHook"));
|
|
23
|
-
|
|
24
15
|
/**
|
|
25
16
|
* Internal dependencies
|
|
26
17
|
*/
|
|
@@ -37,8 +28,8 @@ class _Hooks {
|
|
|
37
28
|
/** @type {import('.').Store} actions */
|
|
38
29
|
this.actions = Object.create(null);
|
|
39
30
|
this.actions.__current = [];
|
|
40
|
-
/** @type {import('.').Store} filters */
|
|
41
31
|
|
|
32
|
+
/** @type {import('.').Store} filters */
|
|
42
33
|
this.filters = Object.create(null);
|
|
43
34
|
this.filters.__current = [];
|
|
44
35
|
this.addAction = (0, _createAddHook.default)(this, 'actions');
|
|
@@ -58,8 +49,8 @@ class _Hooks {
|
|
|
58
49
|
this.didAction = (0, _createDidHook.default)(this, 'actions');
|
|
59
50
|
this.didFilter = (0, _createDidHook.default)(this, 'filters');
|
|
60
51
|
}
|
|
61
|
-
|
|
62
52
|
}
|
|
53
|
+
|
|
63
54
|
/** @typedef {_Hooks} Hooks */
|
|
64
55
|
|
|
65
56
|
/**
|
|
@@ -67,14 +58,10 @@ class _Hooks {
|
|
|
67
58
|
*
|
|
68
59
|
* @return {Hooks} A Hooks instance.
|
|
69
60
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
61
|
exports._Hooks = _Hooks;
|
|
73
|
-
|
|
74
62
|
function createHooks() {
|
|
75
63
|
return new _Hooks();
|
|
76
64
|
}
|
|
77
|
-
|
|
78
65
|
var _default = createHooks;
|
|
79
66
|
exports.default = _default;
|
|
80
67
|
//# sourceMappingURL=createHooks.js.map
|
package/build/createHooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_createAddHook","_interopRequireDefault","require","_createRemoveHook","_createHasHook","_createRunHook","_createCurrentHook","_createDoingHook","_createDidHook","_Hooks","constructor","actions","Object","create","__current","filters","addAction","createAddHook","addFilter","removeAction","createRemoveHook","removeFilter","hasAction","createHasHook","hasFilter","removeAllActions","removeAllFilters","doAction","createRunHook","applyFilters","currentAction","createCurrentHook","currentFilter","doingAction","createDoingHook","doingFilter","didAction","createDidHook","didFilter","exports","createHooks","_default","default"],"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":";;;;;;;AAGA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,cAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,cAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,kBAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,gBAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,cAAA,GAAAP,sBAAA,CAAAC,OAAA;AATA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMO,MAAM,CAAC;EACnBC,WAAWA,CAAA,EAAG;IACb;IACA,IAAI,CA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,SAAU,CAAC;IACrD,IAAI,CAACC,WAAW,GAAG,IAAAD,wBAAe,EAAE,IAAI,EAAE,SAAU,CAAC;IACrD,IAAI,CAACE,SAAS,GAAG,IAAAC,sBAAa,EAAE,IAAI,EAAE,SAAU,CAAC;IACjD,IAAI,CAACC,SAAS,GAAG,IAAAD,sBAAa,EAAE,IAAI,EAAE,SAAU,CAAC;EAClD;AACD;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AAJAE,OAAA,CAAA9B,MAAA,GAAAA,MAAA;AAKA,SAAS+B,WAAWA,CAAA,EAAG;EACtB,OAAO,IAAI/B,MAAM,CAAC,CAAC;AACpB;AAAC,IAAAgC,QAAA,GAEcD,WAAW;AAAAD,OAAA,CAAAG,OAAA,GAAAD,QAAA"}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _validateNamespace = _interopRequireDefault(require("./validateNamespace.js"));
|
|
11
|
-
|
|
12
9
|
var _validateHookName = _interopRequireDefault(require("./validateHookName.js"));
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* Internal dependencies
|
|
16
12
|
*/
|
|
@@ -42,22 +38,18 @@ var _validateHookName = _interopRequireDefault(require("./validateHookName.js"))
|
|
|
42
38
|
function createRemoveHook(hooks, storeKey, removeAll = false) {
|
|
43
39
|
return function removeHook(hookName, namespace) {
|
|
44
40
|
const hooksStore = hooks[storeKey];
|
|
45
|
-
|
|
46
41
|
if (!(0, _validateHookName.default)(hookName)) {
|
|
47
42
|
return;
|
|
48
43
|
}
|
|
49
|
-
|
|
50
44
|
if (!removeAll && !(0, _validateNamespace.default)(namespace)) {
|
|
51
45
|
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
46
|
+
}
|
|
54
47
|
|
|
48
|
+
// Bail if no hooks exist by this name.
|
|
55
49
|
if (!hooksStore[hookName]) {
|
|
56
50
|
return 0;
|
|
57
51
|
}
|
|
58
|
-
|
|
59
52
|
let handlersRemoved = 0;
|
|
60
|
-
|
|
61
53
|
if (removeAll) {
|
|
62
54
|
handlersRemoved = hooksStore[hookName].handlers.length;
|
|
63
55
|
hooksStore[hookName] = {
|
|
@@ -67,16 +59,15 @@ function createRemoveHook(hooks, storeKey, removeAll = false) {
|
|
|
67
59
|
} else {
|
|
68
60
|
// Try to find the specified callback to remove.
|
|
69
61
|
const handlers = hooksStore[hookName].handlers;
|
|
70
|
-
|
|
71
62
|
for (let i = handlers.length - 1; i >= 0; i--) {
|
|
72
63
|
if (handlers[i].namespace === namespace) {
|
|
73
64
|
handlers.splice(i, 1);
|
|
74
|
-
handlersRemoved++;
|
|
65
|
+
handlersRemoved++;
|
|
66
|
+
// This callback may also be part of a hook that is
|
|
75
67
|
// currently executing. If the callback we're removing
|
|
76
68
|
// comes after the current callback, there's no problem;
|
|
77
69
|
// otherwise we need to decrease the execution index of any
|
|
78
70
|
// other runs by 1 to account for the removed element.
|
|
79
|
-
|
|
80
71
|
hooksStore.__current.forEach(hookInfo => {
|
|
81
72
|
if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
|
|
82
73
|
hookInfo.currentIndex--;
|
|
@@ -85,15 +76,12 @@ function createRemoveHook(hooks, storeKey, removeAll = false) {
|
|
|
85
76
|
}
|
|
86
77
|
}
|
|
87
78
|
}
|
|
88
|
-
|
|
89
79
|
if (hookName !== 'hookRemoved') {
|
|
90
80
|
hooks.doAction('hookRemoved', hookName, namespace);
|
|
91
81
|
}
|
|
92
|
-
|
|
93
82
|
return handlersRemoved;
|
|
94
83
|
};
|
|
95
84
|
}
|
|
96
|
-
|
|
97
85
|
var _default = createRemoveHook;
|
|
98
86
|
exports.default = _default;
|
|
99
87
|
//# sourceMappingURL=createRemoveHook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_validateNamespace","_interopRequireDefault","require","_validateHookName","createRemoveHook","hooks","storeKey","removeAll","removeHook","hookName","namespace","hooksStore","validateHookName","validateNamespace","handlersRemoved","handlers","length","runs","i","splice","__current","forEach","hookInfo","name","currentIndex","doAction","_default","exports","default"],"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":";;;;;;;AAGA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAF,sBAAA,CAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,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,CAAE,IAAAM,yBAAgB,EAAEH,QAAS,CAAC,EAAG;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B;AAAAuB,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
package/build/createRunHook.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Returns a function which, when invoked, will execute all callbacks
|
|
10
9
|
* registered to a hook of the specified type, optionally returning the final
|
|
@@ -15,59 +14,50 @@ exports.default = void 0;
|
|
|
15
14
|
* @param {boolean} [returnFirstArg=false] Whether each hook callback is expected to
|
|
16
15
|
* return its first argument.
|
|
17
16
|
*
|
|
18
|
-
* @return {(hookName:string, ...args: unknown[]) => unknown} Function that runs hook callbacks.
|
|
17
|
+
* @return {(hookName:string, ...args: unknown[]) => undefined|unknown} Function that runs hook callbacks.
|
|
19
18
|
*/
|
|
20
19
|
function createRunHook(hooks, storeKey, returnFirstArg = false) {
|
|
21
20
|
return function runHooks(hookName, ...args) {
|
|
22
21
|
const hooksStore = hooks[storeKey];
|
|
23
|
-
|
|
24
22
|
if (!hooksStore[hookName]) {
|
|
25
23
|
hooksStore[hookName] = {
|
|
26
24
|
handlers: [],
|
|
27
25
|
runs: 0
|
|
28
26
|
};
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
hooksStore[hookName].runs++;
|
|
32
|
-
const handlers = hooksStore[hookName].handlers;
|
|
29
|
+
const handlers = hooksStore[hookName].handlers;
|
|
33
30
|
|
|
31
|
+
// The following code is stripped from production builds.
|
|
34
32
|
if ('production' !== process.env.NODE_ENV) {
|
|
35
33
|
// Handle any 'all' hooks registered.
|
|
36
34
|
if ('hookAdded' !== hookName && hooksStore.all) {
|
|
37
35
|
handlers.push(...hooksStore.all.handlers);
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
|
-
|
|
41
38
|
if (!handlers || !handlers.length) {
|
|
42
39
|
return returnFirstArg ? args[0] : undefined;
|
|
43
40
|
}
|
|
44
|
-
|
|
45
41
|
const hookInfo = {
|
|
46
42
|
name: hookName,
|
|
47
43
|
currentIndex: 0
|
|
48
44
|
};
|
|
49
|
-
|
|
50
45
|
hooksStore.__current.push(hookInfo);
|
|
51
|
-
|
|
52
46
|
while (hookInfo.currentIndex < handlers.length) {
|
|
53
47
|
const handler = handlers[hookInfo.currentIndex];
|
|
54
48
|
const result = handler.callback.apply(null, args);
|
|
55
|
-
|
|
56
49
|
if (returnFirstArg) {
|
|
57
50
|
args[0] = result;
|
|
58
51
|
}
|
|
59
|
-
|
|
60
52
|
hookInfo.currentIndex++;
|
|
61
53
|
}
|
|
62
|
-
|
|
63
54
|
hooksStore.__current.pop();
|
|
64
|
-
|
|
65
55
|
if (returnFirstArg) {
|
|
66
56
|
return args[0];
|
|
67
57
|
}
|
|
58
|
+
return undefined;
|
|
68
59
|
};
|
|
69
60
|
}
|
|
70
|
-
|
|
71
61
|
var _default = createRunHook;
|
|
72
62
|
exports.default = _default;
|
|
73
63
|
//# sourceMappingURL=createRunHook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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","_default","exports","default"],"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,CAAE;IAEpC,IAAK,CAAEK,UAAU,CAAEF,QAAQ,CAAE,EAAG;MAC/BE,UAAU,CAAEF,QAAQ,CAAE,GAAG;QACxBG,QAAQ,EAAE,EAAE;QAC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build/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -13,9 +12,7 @@ Object.defineProperty(exports, "createHooks", {
|
|
|
13
12
|
}
|
|
14
13
|
});
|
|
15
14
|
exports.removeFilter = exports.removeAllFilters = exports.removeAllActions = exports.removeAction = exports.hasFilter = exports.hasAction = exports.filters = exports.doingFilter = exports.doingAction = exports.doAction = exports.didFilter = exports.didAction = exports.defaultHooks = exports.currentFilter = exports.currentAction = void 0;
|
|
16
|
-
|
|
17
15
|
var _createHooks = _interopRequireDefault(require("./createHooks"));
|
|
18
|
-
|
|
19
16
|
/**
|
|
20
17
|
* Internal dependencies
|
|
21
18
|
*/
|
|
@@ -52,6 +49,7 @@ var _createHooks = _interopRequireDefault(require("./createHooks"));
|
|
|
52
49
|
/**
|
|
53
50
|
* @typedef {import('./createHooks').Hooks} Hooks
|
|
54
51
|
*/
|
|
52
|
+
|
|
55
53
|
const defaultHooks = (0, _createHooks.default)();
|
|
56
54
|
exports.defaultHooks = defaultHooks;
|
|
57
55
|
const {
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_createHooks","_interopRequireDefault","require","defaultHooks","createHooks","exports","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":";;;;;;;;;;;;;;AAGA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;;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;;AAEO,MAAMC,YAAY,GAAG,IAAAC,oBAAW,EAAC,CAAC;AAACC,OAAA,CAAAF,YAAA,GAAAA,YAAA;AAE1C,MAAM;EACLG,SAAS;EACTC,SAAS;EACTC,YAAY;EACZC,YAAY;EACZC,SAAS;EACTC,SAAS;EACTC,gBAAgB;EAChBC,gBAAgB;EAChBC,QAAQ;EACRC,YAAY;EACZC,aAAa;EACbC,aAAa;EAC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