notices.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. "store": function() { return /* reexport */ store; }
  42. });
  43. // NAMESPACE OBJECT: ./node_modules/@wordpress/notices/build-module/store/actions.js
  44. var actions_namespaceObject = {};
  45. __webpack_require__.r(actions_namespaceObject);
  46. __webpack_require__.d(actions_namespaceObject, {
  47. "createErrorNotice": function() { return createErrorNotice; },
  48. "createInfoNotice": function() { return createInfoNotice; },
  49. "createNotice": function() { return createNotice; },
  50. "createSuccessNotice": function() { return createSuccessNotice; },
  51. "createWarningNotice": function() { return createWarningNotice; },
  52. "removeNotice": function() { return removeNotice; }
  53. });
  54. // NAMESPACE OBJECT: ./node_modules/@wordpress/notices/build-module/store/selectors.js
  55. var selectors_namespaceObject = {};
  56. __webpack_require__.r(selectors_namespaceObject);
  57. __webpack_require__.d(selectors_namespaceObject, {
  58. "getNotices": function() { return getNotices; }
  59. });
  60. ;// CONCATENATED MODULE: external ["wp","data"]
  61. var external_wp_data_namespaceObject = window["wp"]["data"];
  62. ;// CONCATENATED MODULE: external "lodash"
  63. var external_lodash_namespaceObject = window["lodash"];
  64. ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/utils/on-sub-key.js
  65. /**
  66. * Higher-order reducer creator which creates a combined reducer object, keyed
  67. * by a property on the action object.
  68. *
  69. * @param {string} actionProperty Action property by which to key object.
  70. *
  71. * @return {Function} Higher-order reducer.
  72. */
  73. const onSubKey = actionProperty => reducer => function () {
  74. let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  75. let action = arguments.length > 1 ? arguments[1] : undefined;
  76. // Retrieve subkey from action. Do not track if undefined; useful for cases
  77. // where reducer is scoped by action shape.
  78. const key = action[actionProperty];
  79. if (key === undefined) {
  80. return state;
  81. } // Avoid updating state if unchanged. Note that this also accounts for a
  82. // reducer which returns undefined on a key which is not yet tracked.
  83. const nextKeyState = reducer(state[key], action);
  84. if (nextKeyState === state[key]) {
  85. return state;
  86. }
  87. return { ...state,
  88. [key]: nextKeyState
  89. };
  90. };
  91. /* harmony default export */ var on_sub_key = (onSubKey);
  92. ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/reducer.js
  93. /**
  94. * External dependencies
  95. */
  96. /**
  97. * Internal dependencies
  98. */
  99. /**
  100. * Reducer returning the next notices state. The notices state is an object
  101. * where each key is a context, its value an array of notice objects.
  102. *
  103. * @param {Object} state Current state.
  104. * @param {Object} action Dispatched action.
  105. *
  106. * @return {Object} Updated state.
  107. */
  108. const notices = on_sub_key('context')(function () {
  109. let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  110. let action = arguments.length > 1 ? arguments[1] : undefined;
  111. switch (action.type) {
  112. case 'CREATE_NOTICE':
  113. // Avoid duplicates on ID.
  114. return [...(0,external_lodash_namespaceObject.reject)(state, {
  115. id: action.notice.id
  116. }), action.notice];
  117. case 'REMOVE_NOTICE':
  118. return (0,external_lodash_namespaceObject.reject)(state, {
  119. id: action.id
  120. });
  121. }
  122. return state;
  123. });
  124. /* harmony default export */ var reducer = (notices);
  125. ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/constants.js
  126. /**
  127. * Default context to use for notice grouping when not otherwise specified. Its
  128. * specific value doesn't hold much meaning, but it must be reasonably unique
  129. * and, more importantly, referenced consistently in the store implementation.
  130. *
  131. * @type {string}
  132. */
  133. const DEFAULT_CONTEXT = 'global';
  134. /**
  135. * Default notice status.
  136. *
  137. * @type {string}
  138. */
  139. const DEFAULT_STATUS = 'info';
  140. ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/actions.js
  141. /**
  142. * External dependencies
  143. */
  144. /**
  145. * Internal dependencies
  146. */
  147. /**
  148. * @typedef {Object} WPNoticeAction Object describing a user action option associated with a notice.
  149. *
  150. * @property {string} label Message to use as action label.
  151. * @property {?string} url Optional URL of resource if action incurs
  152. * browser navigation.
  153. * @property {?Function} onClick Optional function to invoke when action is
  154. * triggered by user.
  155. *
  156. */
  157. /**
  158. * Returns an action object used in signalling that a notice is to be created.
  159. *
  160. * @param {string} [status='info'] Notice status.
  161. * @param {string} content Notice message.
  162. * @param {Object} [options] Notice options.
  163. * @param {string} [options.context='global'] Context under which to
  164. * group notice.
  165. * @param {string} [options.id] Identifier for notice.
  166. * Automatically assigned
  167. * if not specified.
  168. * @param {boolean} [options.isDismissible=true] Whether the notice can
  169. * be dismissed by user.
  170. * @param {string} [options.type='default'] Type of notice, one of
  171. * `default`, or `snackbar`.
  172. * @param {boolean} [options.speak=true] Whether the notice
  173. * content should be
  174. * announced to screen
  175. * readers.
  176. * @param {Array<WPNoticeAction>} [options.actions] User actions to be
  177. * presented with notice.
  178. * @param {Object} [options.icon] An icon displayed with the notice.
  179. * @param {boolean} [options.explicitDismiss] Whether the notice includes
  180. * an explict dismiss button and
  181. * can't be dismissed by clicking
  182. * the body of the notice.
  183. * @param {Function} [options.onDismiss] Called when the notice is dismissed.
  184. *
  185. * @return {Object} Action object.
  186. */
  187. function createNotice() {
  188. let status = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_STATUS;
  189. let content = arguments.length > 1 ? arguments[1] : undefined;
  190. let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  191. const {
  192. speak = true,
  193. isDismissible = true,
  194. context = DEFAULT_CONTEXT,
  195. id = (0,external_lodash_namespaceObject.uniqueId)(context),
  196. actions = [],
  197. type = 'default',
  198. __unstableHTML,
  199. icon = null,
  200. explicitDismiss = false,
  201. onDismiss
  202. } = options; // The supported value shape of content is currently limited to plain text
  203. // strings. To avoid setting expectation that e.g. a WPElement could be
  204. // supported, cast to a string.
  205. content = String(content);
  206. return {
  207. type: 'CREATE_NOTICE',
  208. context,
  209. notice: {
  210. id,
  211. status,
  212. content,
  213. spokenMessage: speak ? content : null,
  214. __unstableHTML,
  215. isDismissible,
  216. actions,
  217. type,
  218. icon,
  219. explicitDismiss,
  220. onDismiss
  221. }
  222. };
  223. }
  224. /**
  225. * Returns an action object used in signalling that a success notice is to be
  226. * created. Refer to `createNotice` for options documentation.
  227. *
  228. * @see createNotice
  229. *
  230. * @param {string} content Notice message.
  231. * @param {Object} [options] Optional notice options.
  232. *
  233. * @return {Object} Action object.
  234. */
  235. function createSuccessNotice(content, options) {
  236. return createNotice('success', content, options);
  237. }
  238. /**
  239. * Returns an action object used in signalling that an info notice is to be
  240. * created. Refer to `createNotice` for options documentation.
  241. *
  242. * @see createNotice
  243. *
  244. * @param {string} content Notice message.
  245. * @param {Object} [options] Optional notice options.
  246. *
  247. * @return {Object} Action object.
  248. */
  249. function createInfoNotice(content, options) {
  250. return createNotice('info', content, options);
  251. }
  252. /**
  253. * Returns an action object used in signalling that an error notice is to be
  254. * created. Refer to `createNotice` for options documentation.
  255. *
  256. * @see createNotice
  257. *
  258. * @param {string} content Notice message.
  259. * @param {Object} [options] Optional notice options.
  260. *
  261. * @return {Object} Action object.
  262. */
  263. function createErrorNotice(content, options) {
  264. return createNotice('error', content, options);
  265. }
  266. /**
  267. * Returns an action object used in signalling that a warning notice is to be
  268. * created. Refer to `createNotice` for options documentation.
  269. *
  270. * @see createNotice
  271. *
  272. * @param {string} content Notice message.
  273. * @param {Object} [options] Optional notice options.
  274. *
  275. * @return {Object} Action object.
  276. */
  277. function createWarningNotice(content, options) {
  278. return createNotice('warning', content, options);
  279. }
  280. /**
  281. * Returns an action object used in signalling that a notice is to be removed.
  282. *
  283. * @param {string} id Notice unique identifier.
  284. * @param {string} [context='global'] Optional context (grouping) in which the notice is
  285. * intended to appear. Defaults to default context.
  286. *
  287. * @return {Object} Action object.
  288. */
  289. function removeNotice(id) {
  290. let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_CONTEXT;
  291. return {
  292. type: 'REMOVE_NOTICE',
  293. id,
  294. context
  295. };
  296. }
  297. ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/selectors.js
  298. /**
  299. * Internal dependencies
  300. */
  301. /** @typedef {import('./actions').WPNoticeAction} WPNoticeAction */
  302. /**
  303. * The default empty set of notices to return when there are no notices
  304. * assigned for a given notices context. This can occur if the getNotices
  305. * selector is called without a notice ever having been created for the
  306. * context. A shared value is used to ensure referential equality between
  307. * sequential selector calls, since otherwise `[] !== []`.
  308. *
  309. * @type {Array}
  310. */
  311. const DEFAULT_NOTICES = [];
  312. /**
  313. * @typedef {Object} WPNotice Notice object.
  314. *
  315. * @property {string} id Unique identifier of notice.
  316. * @property {string} status Status of notice, one of `success`,
  317. * `info`, `error`, or `warning`. Defaults
  318. * to `info`.
  319. * @property {string} content Notice message.
  320. * @property {string} spokenMessage Audibly announced message text used by
  321. * assistive technologies.
  322. * @property {string} __unstableHTML Notice message as raw HTML. Intended to
  323. * serve primarily for compatibility of
  324. * server-rendered notices, and SHOULD NOT
  325. * be used for notices. It is subject to
  326. * removal without notice.
  327. * @property {boolean} isDismissible Whether the notice can be dismissed by
  328. * user. Defaults to `true`.
  329. * @property {string} type Type of notice, one of `default`,
  330. * or `snackbar`. Defaults to `default`.
  331. * @property {boolean} speak Whether the notice content should be
  332. * announced to screen readers. Defaults to
  333. * `true`.
  334. * @property {WPNoticeAction[]} actions User actions to present with notice.
  335. *
  336. */
  337. /**
  338. * Returns all notices as an array, optionally for a given context. Defaults to
  339. * the global context.
  340. *
  341. * @param {Object} state Notices state.
  342. * @param {?string} context Optional grouping context.
  343. *
  344. * @return {WPNotice[]} Array of notices.
  345. */
  346. function getNotices(state) {
  347. let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_CONTEXT;
  348. return state[context] || DEFAULT_NOTICES;
  349. }
  350. ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/index.js
  351. /**
  352. * WordPress dependencies
  353. */
  354. /**
  355. * Internal dependencies
  356. */
  357. /**
  358. * Store definition for the notices namespace.
  359. *
  360. * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
  361. *
  362. * @type {Object}
  363. */
  364. const store = (0,external_wp_data_namespaceObject.createReduxStore)('core/notices', {
  365. reducer: reducer,
  366. actions: actions_namespaceObject,
  367. selectors: selectors_namespaceObject
  368. });
  369. (0,external_wp_data_namespaceObject.register)(store);
  370. ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/index.js
  371. (window.wp = window.wp || {}).notices = __webpack_exports__;
  372. /******/ })()
  373. ;