You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

593 lines
20 KiB

1 year ago
  1. /******/ (function() { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ // The require scope
  4. /******/ var __webpack_require__ = {};
  5. /******/
  6. /************************************************************************/
  7. /******/ /* webpack/runtime/define property getters */
  8. /******/ !function() {
  9. /******/ // define getter functions for harmony exports
  10. /******/ __webpack_require__.d = function(exports, definition) {
  11. /******/ for(var key in definition) {
  12. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  13. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  14. /******/ }
  15. /******/ }
  16. /******/ };
  17. /******/ }();
  18. /******/
  19. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  20. /******/ !function() {
  21. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  22. /******/ }();
  23. /******/
  24. /******/ /* webpack/runtime/make namespace object */
  25. /******/ !function() {
  26. /******/ // define __esModule on exports
  27. /******/ __webpack_require__.r = function(exports) {
  28. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  29. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  30. /******/ }
  31. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  32. /******/ };
  33. /******/ }();
  34. /******/
  35. /************************************************************************/
  36. var __webpack_exports__ = {};
  37. // ESM COMPAT FLAG
  38. __webpack_require__.r(__webpack_exports__);
  39. // EXPORTS
  40. __webpack_require__.d(__webpack_exports__, {
  41. actions: function() { return /* binding */ actions; },
  42. addAction: function() { return /* binding */ addAction; },
  43. addFilter: function() { return /* binding */ addFilter; },
  44. applyFilters: function() { return /* binding */ applyFilters; },
  45. createHooks: function() { return /* reexport */ build_module_createHooks; },
  46. currentAction: function() { return /* binding */ currentAction; },
  47. currentFilter: function() { return /* binding */ currentFilter; },
  48. defaultHooks: function() { return /* binding */ defaultHooks; },
  49. didAction: function() { return /* binding */ didAction; },
  50. didFilter: function() { return /* binding */ didFilter; },
  51. doAction: function() { return /* binding */ doAction; },
  52. doingAction: function() { return /* binding */ doingAction; },
  53. doingFilter: function() { return /* binding */ doingFilter; },
  54. filters: function() { return /* binding */ filters; },
  55. hasAction: function() { return /* binding */ hasAction; },
  56. hasFilter: function() { return /* binding */ hasFilter; },
  57. removeAction: function() { return /* binding */ removeAction; },
  58. removeAllActions: function() { return /* binding */ removeAllActions; },
  59. removeAllFilters: function() { return /* binding */ removeAllFilters; },
  60. removeFilter: function() { return /* binding */ removeFilter; }
  61. });
  62. ;// CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/validateNamespace.js
  63. /**
  64. * Validate a namespace string.
  65. *
  66. * @param {string} namespace The namespace to validate - should take the form
  67. * `vendor/plugin/function`.
  68. *
  69. * @return {boolean} Whether the namespace is valid.
  70. */
  71. function validateNamespace(namespace) {
  72. if ('string' !== typeof namespace || '' === namespace) {
  73. // eslint-disable-next-line no-console
  74. console.error('The namespace must be a non-empty string.');
  75. return false;
  76. }
  77. if (!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(namespace)) {
  78. // eslint-disable-next-line no-console
  79. console.error('The namespace can only contain numbers, letters, dashes, periods, underscores and slashes.');
  80. return false;
  81. }
  82. return true;
  83. }
  84. /* harmony default export */ var build_module_validateNamespace = (validateNamespace);
  85. ;// CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/validateHookName.js
  86. /**
  87. * Validate a hookName string.
  88. *
  89. * @param {string} hookName The hook name to validate. Should be a non empty string containing
  90. * only numbers, letters, dashes, periods and underscores. Also,
  91. * the hook name cannot begin with `__`.
  92. *
  93. * @return {boolean} Whether the hook name is valid.
  94. */
  95. function validateHookName(hookName) {
  96. if ('string' !== typeof hookName || '' === hookName) {
  97. // eslint-disable-next-line no-console
  98. console.error('The hook name must be a non-empty string.');
  99. return false;
  100. }
  101. if (/^__/.test(hookName)) {
  102. // eslint-disable-next-line no-console
  103. console.error('The hook name cannot begin with `__`.');
  104. return false;
  105. }
  106. if (!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(hookName)) {
  107. // eslint-disable-next-line no-console
  108. console.error('The hook name can only contain numbers, letters, dashes, periods and underscores.');
  109. return false;
  110. }
  111. return true;
  112. }
  113. /* harmony default export */ var build_module_validateHookName = (validateHookName);
  114. ;// CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createAddHook.js
  115. /**
  116. * Internal dependencies
  117. */
  118. /**
  119. * @callback AddHook
  120. *
  121. * Adds the hook to the appropriate hooks container.
  122. *
  123. * @param {string} hookName Name of hook to add
  124. * @param {string} namespace The unique namespace identifying the callback in the form `vendor/plugin/function`.
  125. * @param {import('.').Callback} callback Function to call when the hook is run
  126. * @param {number} [priority=10] Priority of this hook
  127. */
  128. /**
  129. * Returns a function which, when invoked, will add a hook.
  130. *
  131. * @param {import('.').Hooks} hooks Hooks instance.
  132. * @param {import('.').StoreKey} storeKey
  133. *
  134. * @return {AddHook} Function that adds a new hook.
  135. */
  136. function createAddHook(hooks, storeKey) {
  137. return function addHook(hookName, namespace, callback, priority = 10) {
  138. const hooksStore = hooks[storeKey];
  139. if (!build_module_validateHookName(hookName)) {
  140. return;
  141. }
  142. if (!build_module_validateNamespace(namespace)) {
  143. return;
  144. }
  145. if ('function' !== typeof callback) {
  146. // eslint-disable-next-line no-console
  147. console.error('The hook callback must be a function.');
  148. return;
  149. }
  150. // Validate numeric priority
  151. if ('number' !== typeof priority) {
  152. // eslint-disable-next-line no-console
  153. console.error('If specified, the hook priority must be a number.');
  154. return;
  155. }
  156. const handler = {
  157. callback,
  158. priority,
  159. namespace
  160. };
  161. if (hooksStore[hookName]) {
  162. // Find the correct insert index of the new hook.
  163. const handlers = hooksStore[hookName].handlers;
  164. /** @type {number} */
  165. let i;
  166. for (i = handlers.length; i > 0; i--) {
  167. if (priority >= handlers[i - 1].priority) {
  168. break;
  169. }
  170. }
  171. if (i === handlers.length) {
  172. // If append, operate via direct assignment.
  173. handlers[i] = handler;
  174. } else {
  175. // Otherwise, insert before index via splice.
  176. handlers.splice(i, 0, handler);
  177. }
  178. // We may also be currently executing this hook. If the callback
  179. // we're adding would come after the current callback, there's no
  180. // problem; otherwise we need to increase the execution index of
  181. // any other runs by 1 to account for the added element.
  182. hooksStore.__current.forEach(hookInfo => {
  183. if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
  184. hookInfo.currentIndex++;
  185. }
  186. });
  187. } else {
  188. // This is the first hook of its type.
  189. hooksStore[hookName] = {
  190. handlers: [handler],
  191. runs: 0
  192. };
  193. }
  194. if (hookName !== 'hookAdded') {
  195. hooks.doAction('hookAdded', hookName, namespace, callback, priority);
  196. }
  197. };
  198. }
  199. /* harmony default export */ var build_module_createAddHook = (createAddHook);
  200. ;// CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createRemoveHook.js
  201. /**
  202. * Internal dependencies
  203. */
  204. /**
  205. * @callback RemoveHook
  206. * Removes the specified callback (or all callbacks) from the hook with a given hookName
  207. * and namespace.
  208. *
  209. * @param {string} hookName The name of the hook to modify.
  210. * @param {string} namespace The unique namespace identifying the callback in the
  211. * form `vendor/plugin/function`.
  212. *
  213. * @return {number | undefined} The number of callbacks removed.
  214. */
  215. /**
  216. * Returns a function which, when invoked, will remove a specified hook or all
  217. * hooks by the given name.
  218. *
  219. * @param {import('.').Hooks} hooks Hooks instance.
  220. * @param {import('.').StoreKey} storeKey
  221. * @param {boolean} [removeAll=false] Whether to remove all callbacks for a hookName,
  222. * without regard to namespace. Used to create
  223. * `removeAll*` functions.
  224. *
  225. * @return {RemoveHook} Function that removes hooks.
  226. */
  227. function createRemoveHook(hooks, storeKey, removeAll = false) {
  228. return function removeHook(hookName, namespace) {
  229. const hooksStore = hooks[storeKey];
  230. if (!build_module_validateHookName(hookName)) {
  231. return;
  232. }
  233. if (!removeAll && !build_module_validateNamespace(namespace)) {
  234. return;
  235. }
  236. // Bail if no hooks exist by this name.
  237. if (!hooksStore[hookName]) {
  238. return 0;
  239. }
  240. let handlersRemoved = 0;
  241. if (removeAll) {
  242. handlersRemoved = hooksStore[hookName].handlers.length;
  243. hooksStore[hookName] = {
  244. runs: hooksStore[hookName].runs,
  245. handlers: []
  246. };
  247. } else {
  248. // Try to find the specified callback to remove.
  249. const handlers = hooksStore[hookName].handlers;
  250. for (let i = handlers.length - 1; i >= 0; i--) {
  251. if (handlers[i].namespace === namespace) {
  252. handlers.splice(i, 1);
  253. handlersRemoved++;
  254. // This callback may also be part of a hook that is
  255. // currently executing. If the callback we're removing
  256. // comes after the current callback, there's no problem;
  257. // otherwise we need to decrease the execution index of any
  258. // other runs by 1 to account for the removed element.
  259. hooksStore.__current.forEach(hookInfo => {
  260. if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
  261. hookInfo.currentIndex--;
  262. }
  263. });
  264. }
  265. }
  266. }
  267. if (hookName !== 'hookRemoved') {
  268. hooks.doAction('hookRemoved', hookName, namespace);
  269. }
  270. return handlersRemoved;
  271. };
  272. }
  273. /* harmony default export */ var build_module_createRemoveHook = (createRemoveHook);
  274. ;// CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createHasHook.js
  275. /**
  276. * @callback HasHook
  277. *
  278. * Returns whether any handlers are attached for the given hookName and optional namespace.
  279. *
  280. * @param {string} hookName The name of the hook to check for.
  281. * @param {string} [namespace] Optional. The unique namespace identifying the callback
  282. * in the form `vendor/plugin/function`.
  283. *
  284. * @return {boolean} Whether there are handlers that are attached to the given hook.
  285. */
  286. /**
  287. * Returns a function which, when invoked, will return whether any handlers are
  288. * attached to a particular hook.
  289. *
  290. * @param {import('.').Hooks} hooks Hooks instance.
  291. * @param {import('.').StoreKey} storeKey
  292. *
  293. * @return {HasHook} Function that returns whether any handlers are
  294. * attached to a particular hook and optional namespace.
  295. */
  296. function createHasHook(hooks, storeKey) {
  297. return function hasHook(hookName, namespace) {
  298. const hooksStore = hooks[storeKey];
  299. // Use the namespace if provided.
  300. if ('undefined' !== typeof namespace) {
  301. return hookName in hooksStore && hooksStore[hookName].handlers.some(hook => hook.namespace === namespace);
  302. }
  303. return hookName in hooksStore;
  304. };
  305. }
  306. /* harmony default export */ var build_module_createHasHook = (createHasHook);
  307. ;// CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createRunHook.js
  308. /**
  309. * Returns a function which, when invoked, will execute all callbacks
  310. * registered to a hook of the specified type, optionally returning the final
  311. * value of the call chain.
  312. *
  313. * @param {import('.').Hooks} hooks Hooks instance.
  314. * @param {import('.').StoreKey} storeKey
  315. * @param {boolean} [returnFirstArg=false] Whether each hook callback is expected to
  316. * return its first argument.
  317. *
  318. * @return {(hookName:string, ...args: unknown[]) => undefined|unknown} Function that runs hook callbacks.
  319. */
  320. function createRunHook(hooks, storeKey, returnFirstArg = false) {
  321. return function runHooks(hookName, ...args) {
  322. const hooksStore = hooks[storeKey];
  323. if (!hooksStore[hookName]) {
  324. hooksStore[hookName] = {
  325. handlers: [],
  326. runs: 0
  327. };
  328. }
  329. hooksStore[hookName].runs++;
  330. const handlers = hooksStore[hookName].handlers;
  331. // The following code is stripped from production builds.
  332. if (false) {}
  333. if (!handlers || !handlers.length) {
  334. return returnFirstArg ? args[0] : undefined;
  335. }
  336. const hookInfo = {
  337. name: hookName,
  338. currentIndex: 0
  339. };
  340. hooksStore.__current.push(hookInfo);
  341. while (hookInfo.currentIndex < handlers.length) {
  342. const handler = handlers[hookInfo.currentIndex];
  343. const result = handler.callback.apply(null, args);
  344. if (returnFirstArg) {
  345. args[0] = result;
  346. }
  347. hookInfo.currentIndex++;
  348. }
  349. hooksStore.__current.pop();
  350. if (returnFirstArg) {
  351. return args[0];
  352. }
  353. return undefined;
  354. };
  355. }
  356. /* harmony default export */ var build_module_createRunHook = (createRunHook);
  357. ;// CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createCurrentHook.js
  358. /**
  359. * Returns a function which, when invoked, will return the name of the
  360. * currently running hook, or `null` if no hook of the given type is currently
  361. * running.
  362. *
  363. * @param {import('.').Hooks} hooks Hooks instance.
  364. * @param {import('.').StoreKey} storeKey
  365. *
  366. * @return {() => string | null} Function that returns the current hook name or null.
  367. */
  368. function createCurrentHook(hooks, storeKey) {
  369. return function currentHook() {
  370. var _hooksStore$__current;
  371. const hooksStore = hooks[storeKey];
  372. return (_hooksStore$__current = hooksStore.__current[hooksStore.__current.length - 1]?.name) !== null && _hooksStore$__current !== void 0 ? _hooksStore$__current : null;
  373. };
  374. }
  375. /* harmony default export */ var build_module_createCurrentHook = (createCurrentHook);
  376. ;// CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createDoingHook.js
  377. /**
  378. * @callback DoingHook
  379. * Returns whether a hook is currently being executed.
  380. *
  381. * @param {string} [hookName] The name of the hook to check for. If
  382. * omitted, will check for any hook being executed.
  383. *
  384. * @return {boolean} Whether the hook is being executed.
  385. */
  386. /**
  387. * Returns a function which, when invoked, will return whether a hook is
  388. * currently being executed.
  389. *
  390. * @param {import('.').Hooks} hooks Hooks instance.
  391. * @param {import('.').StoreKey} storeKey
  392. *
  393. * @return {DoingHook} Function that returns whether a hook is currently
  394. * being executed.
  395. */
  396. function createDoingHook(hooks, storeKey) {
  397. return function doingHook(hookName) {
  398. const hooksStore = hooks[storeKey];
  399. // If the hookName was not passed, check for any current hook.
  400. if ('undefined' === typeof hookName) {
  401. return 'undefined' !== typeof hooksStore.__current[0];
  402. }
  403. // Return the __current hook.
  404. return hooksStore.__current[0] ? hookName === hooksStore.__current[0].name : false;
  405. };
  406. }
  407. /* harmony default export */ var build_module_createDoingHook = (createDoingHook);
  408. ;// CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createDidHook.js
  409. /**
  410. * Internal dependencies
  411. */
  412. /**
  413. * @callback DidHook
  414. *
  415. * Returns the number of times an action has been fired.
  416. *
  417. * @param {string} hookName The hook name to check.
  418. *
  419. * @return {number | undefined} The number of times the hook has run.
  420. */
  421. /**
  422. * Returns a function which, when invoked, will return the number of times a
  423. * hook has been called.
  424. *
  425. * @param {import('.').Hooks} hooks Hooks instance.
  426. * @param {import('.').StoreKey} storeKey
  427. *
  428. * @return {DidHook} Function that returns a hook's call count.
  429. */
  430. function createDidHook(hooks, storeKey) {
  431. return function didHook(hookName) {
  432. const hooksStore = hooks[storeKey];
  433. if (!build_module_validateHookName(hookName)) {
  434. return;
  435. }
  436. return hooksStore[hookName] && hooksStore[hookName].runs ? hooksStore[hookName].runs : 0;
  437. };
  438. }
  439. /* harmony default export */ var build_module_createDidHook = (createDidHook);
  440. ;// CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/createHooks.js
  441. /**
  442. * Internal dependencies
  443. */
  444. /**
  445. * Internal class for constructing hooks. Use `createHooks()` function
  446. *
  447. * Note, it is necessary to expose this class to make its type public.
  448. *
  449. * @private
  450. */
  451. class _Hooks {
  452. constructor() {
  453. /** @type {import('.').Store} actions */
  454. this.actions = Object.create(null);
  455. this.actions.__current = [];
  456. /** @type {import('.').Store} filters */
  457. this.filters = Object.create(null);
  458. this.filters.__current = [];
  459. this.addAction = build_module_createAddHook(this, 'actions');
  460. this.addFilter = build_module_createAddHook(this, 'filters');
  461. this.removeAction = build_module_createRemoveHook(this, 'actions');
  462. this.removeFilter = build_module_createRemoveHook(this, 'filters');
  463. this.hasAction = build_module_createHasHook(this, 'actions');
  464. this.hasFilter = build_module_createHasHook(this, 'filters');
  465. this.removeAllActions = build_module_createRemoveHook(this, 'actions', true);
  466. this.removeAllFilters = build_module_createRemoveHook(this, 'filters', true);
  467. this.doAction = build_module_createRunHook(this, 'actions');
  468. this.applyFilters = build_module_createRunHook(this, 'filters', true);
  469. this.currentAction = build_module_createCurrentHook(this, 'actions');
  470. this.currentFilter = build_module_createCurrentHook(this, 'filters');
  471. this.doingAction = build_module_createDoingHook(this, 'actions');
  472. this.doingFilter = build_module_createDoingHook(this, 'filters');
  473. this.didAction = build_module_createDidHook(this, 'actions');
  474. this.didFilter = build_module_createDidHook(this, 'filters');
  475. }
  476. }
  477. /** @typedef {_Hooks} Hooks */
  478. /**
  479. * Returns an instance of the hooks object.
  480. *
  481. * @return {Hooks} A Hooks instance.
  482. */
  483. function createHooks() {
  484. return new _Hooks();
  485. }
  486. /* harmony default export */ var build_module_createHooks = (createHooks);
  487. ;// CONCATENATED MODULE: ./node_modules/@wordpress/hooks/build-module/index.js
  488. /**
  489. * Internal dependencies
  490. */
  491. /** @typedef {(...args: any[])=>any} Callback */
  492. /**
  493. * @typedef Handler
  494. * @property {Callback} callback The callback
  495. * @property {string} namespace The namespace
  496. * @property {number} priority The namespace
  497. */
  498. /**
  499. * @typedef Hook
  500. * @property {Handler[]} handlers Array of handlers
  501. * @property {number} runs Run counter
  502. */
  503. /**
  504. * @typedef Current
  505. * @property {string} name Hook name
  506. * @property {number} currentIndex The index
  507. */
  508. /**
  509. * @typedef {Record<string, Hook> & {__current: Current[]}} Store
  510. */
  511. /**
  512. * @typedef {'actions' | 'filters'} StoreKey
  513. */
  514. /**
  515. * @typedef {import('./createHooks').Hooks} Hooks
  516. */
  517. const defaultHooks = build_module_createHooks();
  518. const {
  519. addAction,
  520. addFilter,
  521. removeAction,
  522. removeFilter,
  523. hasAction,
  524. hasFilter,
  525. removeAllActions,
  526. removeAllFilters,
  527. doAction,
  528. applyFilters,
  529. currentAction,
  530. currentFilter,
  531. doingAction,
  532. doingFilter,
  533. didAction,
  534. didFilter,
  535. actions,
  536. filters
  537. } = defaultHooks;
  538. (window.wp = window.wp || {}).hooks = __webpack_exports__;
  539. /******/ })()
  540. ;