1 /******/ (function() { // webpackBootstrap |
1 /******/ (() => { // webpackBootstrap |
2 /******/ "use strict"; |
2 /******/ "use strict"; |
3 /******/ // The require scope |
3 /******/ // The require scope |
4 /******/ var __webpack_require__ = {}; |
4 /******/ var __webpack_require__ = {}; |
5 /******/ |
5 /******/ |
6 /************************************************************************/ |
6 /************************************************************************/ |
7 /******/ /* webpack/runtime/define property getters */ |
7 /******/ /* webpack/runtime/define property getters */ |
8 /******/ !function() { |
8 /******/ (() => { |
9 /******/ // define getter functions for harmony exports |
9 /******/ // define getter functions for harmony exports |
10 /******/ __webpack_require__.d = function(exports, definition) { |
10 /******/ __webpack_require__.d = (exports, definition) => { |
11 /******/ for(var key in definition) { |
11 /******/ for(var key in definition) { |
12 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
12 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
13 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
13 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
14 /******/ } |
14 /******/ } |
15 /******/ } |
15 /******/ } |
16 /******/ }; |
16 /******/ }; |
17 /******/ }(); |
17 /******/ })(); |
18 /******/ |
18 /******/ |
19 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
19 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
20 /******/ !function() { |
20 /******/ (() => { |
21 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
21 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
22 /******/ }(); |
22 /******/ })(); |
23 /******/ |
23 /******/ |
24 /******/ /* webpack/runtime/make namespace object */ |
24 /******/ /* webpack/runtime/make namespace object */ |
25 /******/ !function() { |
25 /******/ (() => { |
26 /******/ // define __esModule on exports |
26 /******/ // define __esModule on exports |
27 /******/ __webpack_require__.r = function(exports) { |
27 /******/ __webpack_require__.r = (exports) => { |
28 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
28 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
29 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
29 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
30 /******/ } |
30 /******/ } |
31 /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
31 /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
32 /******/ }; |
32 /******/ }; |
33 /******/ }(); |
33 /******/ })(); |
34 /******/ |
34 /******/ |
35 /************************************************************************/ |
35 /************************************************************************/ |
36 var __webpack_exports__ = {}; |
36 var __webpack_exports__ = {}; |
37 // ESM COMPAT FLAG |
37 // ESM COMPAT FLAG |
38 __webpack_require__.r(__webpack_exports__); |
38 __webpack_require__.r(__webpack_exports__); |
39 |
39 |
40 // EXPORTS |
40 // EXPORTS |
41 __webpack_require__.d(__webpack_exports__, { |
41 __webpack_require__.d(__webpack_exports__, { |
42 "store": function() { return /* reexport */ store; } |
42 store: () => (/* reexport */ store) |
43 }); |
43 }); |
44 |
44 |
45 // NAMESPACE OBJECT: ./node_modules/@wordpress/notices/build-module/store/actions.js |
45 // NAMESPACE OBJECT: ./node_modules/@wordpress/notices/build-module/store/actions.js |
46 var actions_namespaceObject = {}; |
46 var actions_namespaceObject = {}; |
47 __webpack_require__.r(actions_namespaceObject); |
47 __webpack_require__.r(actions_namespaceObject); |
48 __webpack_require__.d(actions_namespaceObject, { |
48 __webpack_require__.d(actions_namespaceObject, { |
49 "createErrorNotice": function() { return createErrorNotice; }, |
49 createErrorNotice: () => (createErrorNotice), |
50 "createInfoNotice": function() { return createInfoNotice; }, |
50 createInfoNotice: () => (createInfoNotice), |
51 "createNotice": function() { return createNotice; }, |
51 createNotice: () => (createNotice), |
52 "createSuccessNotice": function() { return createSuccessNotice; }, |
52 createSuccessNotice: () => (createSuccessNotice), |
53 "createWarningNotice": function() { return createWarningNotice; }, |
53 createWarningNotice: () => (createWarningNotice), |
54 "removeNotice": function() { return removeNotice; } |
54 removeAllNotices: () => (removeAllNotices), |
|
55 removeNotice: () => (removeNotice), |
|
56 removeNotices: () => (removeNotices) |
55 }); |
57 }); |
56 |
58 |
57 // NAMESPACE OBJECT: ./node_modules/@wordpress/notices/build-module/store/selectors.js |
59 // NAMESPACE OBJECT: ./node_modules/@wordpress/notices/build-module/store/selectors.js |
58 var selectors_namespaceObject = {}; |
60 var selectors_namespaceObject = {}; |
59 __webpack_require__.r(selectors_namespaceObject); |
61 __webpack_require__.r(selectors_namespaceObject); |
60 __webpack_require__.d(selectors_namespaceObject, { |
62 __webpack_require__.d(selectors_namespaceObject, { |
61 "getNotices": function() { return getNotices; } |
63 getNotices: () => (getNotices) |
62 }); |
64 }); |
63 |
65 |
64 ;// CONCATENATED MODULE: external ["wp","data"] |
66 ;// CONCATENATED MODULE: external ["wp","data"] |
65 var external_wp_data_namespaceObject = window["wp"]["data"]; |
67 const external_wp_data_namespaceObject = window["wp"]["data"]; |
66 ;// CONCATENATED MODULE: external "lodash" |
|
67 var external_lodash_namespaceObject = window["lodash"]; |
|
68 ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/utils/on-sub-key.js |
68 ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/utils/on-sub-key.js |
69 /** |
69 /** |
70 * Higher-order reducer creator which creates a combined reducer object, keyed |
70 * Higher-order reducer creator which creates a combined reducer object, keyed |
71 * by a property on the action object. |
71 * by a property on the action object. |
72 * |
72 * |
73 * @param {string} actionProperty Action property by which to key object. |
73 * @param {string} actionProperty Action property by which to key object. |
74 * |
74 * |
75 * @return {Function} Higher-order reducer. |
75 * @return {Function} Higher-order reducer. |
76 */ |
76 */ |
77 const onSubKey = actionProperty => reducer => function () { |
77 const onSubKey = actionProperty => reducer => (state = {}, action) => { |
78 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
79 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
80 // Retrieve subkey from action. Do not track if undefined; useful for cases |
78 // Retrieve subkey from action. Do not track if undefined; useful for cases |
81 // where reducer is scoped by action shape. |
79 // where reducer is scoped by action shape. |
82 const key = action[actionProperty]; |
80 const key = action[actionProperty]; |
83 |
|
84 if (key === undefined) { |
81 if (key === undefined) { |
85 return state; |
82 return state; |
86 } // Avoid updating state if unchanged. Note that this also accounts for a |
83 } |
|
84 |
|
85 // Avoid updating state if unchanged. Note that this also accounts for a |
87 // reducer which returns undefined on a key which is not yet tracked. |
86 // reducer which returns undefined on a key which is not yet tracked. |
88 |
|
89 |
|
90 const nextKeyState = reducer(state[key], action); |
87 const nextKeyState = reducer(state[key], action); |
91 |
|
92 if (nextKeyState === state[key]) { |
88 if (nextKeyState === state[key]) { |
93 return state; |
89 return state; |
94 } |
90 } |
95 |
91 return { |
96 return { ...state, |
92 ...state, |
97 [key]: nextKeyState |
93 [key]: nextKeyState |
98 }; |
94 }; |
99 }; |
95 }; |
100 /* harmony default export */ var on_sub_key = (onSubKey); |
96 /* harmony default export */ const on_sub_key = (onSubKey); |
101 |
97 |
102 ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/reducer.js |
98 ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/reducer.js |
103 /** |
|
104 * External dependencies |
|
105 */ |
|
106 |
|
107 /** |
99 /** |
108 * Internal dependencies |
100 * Internal dependencies |
109 */ |
101 */ |
110 |
102 |
111 |
103 |
116 * @param {Object} state Current state. |
108 * @param {Object} state Current state. |
117 * @param {Object} action Dispatched action. |
109 * @param {Object} action Dispatched action. |
118 * |
110 * |
119 * @return {Object} Updated state. |
111 * @return {Object} Updated state. |
120 */ |
112 */ |
121 |
113 const notices = on_sub_key('context')((state = [], action) => { |
122 const notices = on_sub_key('context')(function () { |
|
123 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; |
|
124 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
125 |
|
126 switch (action.type) { |
114 switch (action.type) { |
127 case 'CREATE_NOTICE': |
115 case 'CREATE_NOTICE': |
128 // Avoid duplicates on ID. |
116 // Avoid duplicates on ID. |
129 return [...(0,external_lodash_namespaceObject.reject)(state, { |
117 return [...state.filter(({ |
130 id: action.notice.id |
118 id |
131 }), action.notice]; |
119 }) => id !== action.notice.id), action.notice]; |
132 |
|
133 case 'REMOVE_NOTICE': |
120 case 'REMOVE_NOTICE': |
134 return (0,external_lodash_namespaceObject.reject)(state, { |
121 return state.filter(({ |
135 id: action.id |
122 id |
136 }); |
123 }) => id !== action.id); |
|
124 case 'REMOVE_NOTICES': |
|
125 return state.filter(({ |
|
126 id |
|
127 }) => !action.ids.includes(id)); |
|
128 case 'REMOVE_ALL_NOTICES': |
|
129 return state.filter(({ |
|
130 type |
|
131 }) => type !== action.noticeType); |
137 } |
132 } |
138 |
|
139 return state; |
133 return state; |
140 }); |
134 }); |
141 /* harmony default export */ var reducer = (notices); |
135 /* harmony default export */ const reducer = (notices); |
142 |
136 |
143 ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/constants.js |
137 ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/constants.js |
144 /** |
138 /** |
145 * Default context to use for notice grouping when not otherwise specified. Its |
139 * Default context to use for notice grouping when not otherwise specified. Its |
146 * specific value doesn't hold much meaning, but it must be reasonably unique |
140 * specific value doesn't hold much meaning, but it must be reasonably unique |
147 * and, more importantly, referenced consistently in the store implementation. |
141 * and, more importantly, referenced consistently in the store implementation. |
148 * |
142 * |
149 * @type {string} |
143 * @type {string} |
150 */ |
144 */ |
151 const DEFAULT_CONTEXT = 'global'; |
145 const DEFAULT_CONTEXT = 'global'; |
|
146 |
152 /** |
147 /** |
153 * Default notice status. |
148 * Default notice status. |
154 * |
149 * |
155 * @type {string} |
150 * @type {string} |
156 */ |
151 */ |
157 |
|
158 const DEFAULT_STATUS = 'info'; |
152 const DEFAULT_STATUS = 'info'; |
159 |
153 |
160 ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/actions.js |
154 ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/actions.js |
161 /** |
|
162 * External dependencies |
|
163 */ |
|
164 |
|
165 /** |
155 /** |
166 * Internal dependencies |
156 * Internal dependencies |
167 */ |
157 */ |
168 |
158 |
169 |
159 |
197 * content should be |
188 * content should be |
198 * announced to screen |
189 * announced to screen |
199 * readers. |
190 * readers. |
200 * @param {Array<WPNoticeAction>} [options.actions] User actions to be |
191 * @param {Array<WPNoticeAction>} [options.actions] User actions to be |
201 * presented with notice. |
192 * presented with notice. |
202 * @param {Object} [options.icon] An icon displayed with the notice. |
193 * @param {string} [options.icon] An icon displayed with the notice. |
|
194 * Only used when type is set to `snackbar`. |
203 * @param {boolean} [options.explicitDismiss] Whether the notice includes |
195 * @param {boolean} [options.explicitDismiss] Whether the notice includes |
204 * an explict dismiss button and |
196 * an explicit dismiss button and |
205 * can't be dismissed by clicking |
197 * can't be dismissed by clicking |
206 * the body of the notice. |
198 * the body of the notice. Only applies |
|
199 * when type is set to `snackbar`. |
207 * @param {Function} [options.onDismiss] Called when the notice is dismissed. |
200 * @param {Function} [options.onDismiss] Called when the notice is dismissed. |
208 * |
201 * |
|
202 * @example |
|
203 * ```js |
|
204 * import { __ } from '@wordpress/i18n'; |
|
205 * import { useDispatch } from '@wordpress/data'; |
|
206 * import { store as noticesStore } from '@wordpress/notices'; |
|
207 * import { Button } from '@wordpress/components'; |
|
208 * |
|
209 * const ExampleComponent = () => { |
|
210 * const { createNotice } = useDispatch( noticesStore ); |
|
211 * return ( |
|
212 * <Button |
|
213 * onClick={ () => createNotice( 'success', __( 'Notice message' ) ) } |
|
214 * > |
|
215 * { __( 'Generate a success notice!' ) } |
|
216 * </Button> |
|
217 * ); |
|
218 * }; |
|
219 * ``` |
|
220 * |
209 * @return {Object} Action object. |
221 * @return {Object} Action object. |
210 */ |
222 */ |
211 |
223 function createNotice(status = DEFAULT_STATUS, content, options = {}) { |
212 function createNotice() { |
|
213 let status = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_STATUS; |
|
214 let content = arguments.length > 1 ? arguments[1] : undefined; |
|
215 let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
|
216 const { |
224 const { |
217 speak = true, |
225 speak = true, |
218 isDismissible = true, |
226 isDismissible = true, |
219 context = DEFAULT_CONTEXT, |
227 context = DEFAULT_CONTEXT, |
220 id = (0,external_lodash_namespaceObject.uniqueId)(context), |
228 id = `${context}${++uniqueId}`, |
221 actions = [], |
229 actions = [], |
222 type = 'default', |
230 type = 'default', |
223 __unstableHTML, |
231 __unstableHTML, |
224 icon = null, |
232 icon = null, |
225 explicitDismiss = false, |
233 explicitDismiss = false, |
226 onDismiss |
234 onDismiss |
227 } = options; // The supported value shape of content is currently limited to plain text |
235 } = options; |
228 // strings. To avoid setting expectation that e.g. a WPElement could be |
236 |
|
237 // The supported value shape of content is currently limited to plain text |
|
238 // strings. To avoid setting expectation that e.g. a React Element could be |
229 // supported, cast to a string. |
239 // supported, cast to a string. |
230 |
|
231 content = String(content); |
240 content = String(content); |
232 return { |
241 return { |
233 type: 'CREATE_NOTICE', |
242 type: 'CREATE_NOTICE', |
234 context, |
243 context, |
235 notice: { |
244 notice: { |
245 explicitDismiss, |
254 explicitDismiss, |
246 onDismiss |
255 onDismiss |
247 } |
256 } |
248 }; |
257 }; |
249 } |
258 } |
|
259 |
250 /** |
260 /** |
251 * Returns an action object used in signalling that a success notice is to be |
261 * Returns an action object used in signalling that a success notice is to be |
252 * created. Refer to `createNotice` for options documentation. |
262 * created. Refer to `createNotice` for options documentation. |
253 * |
263 * |
254 * @see createNotice |
264 * @see createNotice |
255 * |
265 * |
256 * @param {string} content Notice message. |
266 * @param {string} content Notice message. |
257 * @param {Object} [options] Optional notice options. |
267 * @param {Object} [options] Optional notice options. |
258 * |
268 * |
|
269 * @example |
|
270 * ```js |
|
271 * import { __ } from '@wordpress/i18n'; |
|
272 * import { useDispatch } from '@wordpress/data'; |
|
273 * import { store as noticesStore } from '@wordpress/notices'; |
|
274 * import { Button } from '@wordpress/components'; |
|
275 * |
|
276 * const ExampleComponent = () => { |
|
277 * const { createSuccessNotice } = useDispatch( noticesStore ); |
|
278 * return ( |
|
279 * <Button |
|
280 * onClick={ () => |
|
281 * createSuccessNotice( __( 'Success!' ), { |
|
282 * type: 'snackbar', |
|
283 * icon: '🔥', |
|
284 * } ) |
|
285 * } |
|
286 * > |
|
287 * { __( 'Generate a snackbar success notice!' ) } |
|
288 * </Button> |
|
289 * ); |
|
290 * }; |
|
291 * ``` |
|
292 * |
259 * @return {Object} Action object. |
293 * @return {Object} Action object. |
260 */ |
294 */ |
261 |
|
262 function createSuccessNotice(content, options) { |
295 function createSuccessNotice(content, options) { |
263 return createNotice('success', content, options); |
296 return createNotice('success', content, options); |
264 } |
297 } |
|
298 |
265 /** |
299 /** |
266 * Returns an action object used in signalling that an info notice is to be |
300 * Returns an action object used in signalling that an info notice is to be |
267 * created. Refer to `createNotice` for options documentation. |
301 * created. Refer to `createNotice` for options documentation. |
268 * |
302 * |
269 * @see createNotice |
303 * @see createNotice |
270 * |
304 * |
271 * @param {string} content Notice message. |
305 * @param {string} content Notice message. |
272 * @param {Object} [options] Optional notice options. |
306 * @param {Object} [options] Optional notice options. |
273 * |
307 * |
|
308 * @example |
|
309 * ```js |
|
310 * import { __ } from '@wordpress/i18n'; |
|
311 * import { useDispatch } from '@wordpress/data'; |
|
312 * import { store as noticesStore } from '@wordpress/notices'; |
|
313 * import { Button } from '@wordpress/components'; |
|
314 * |
|
315 * const ExampleComponent = () => { |
|
316 * const { createInfoNotice } = useDispatch( noticesStore ); |
|
317 * return ( |
|
318 * <Button |
|
319 * onClick={ () => |
|
320 * createInfoNotice( __( 'Something happened!' ), { |
|
321 * isDismissible: false, |
|
322 * } ) |
|
323 * } |
|
324 * > |
|
325 * { __( 'Generate a notice that cannot be dismissed.' ) } |
|
326 * </Button> |
|
327 * ); |
|
328 * }; |
|
329 *``` |
|
330 * |
274 * @return {Object} Action object. |
331 * @return {Object} Action object. |
275 */ |
332 */ |
276 |
|
277 function createInfoNotice(content, options) { |
333 function createInfoNotice(content, options) { |
278 return createNotice('info', content, options); |
334 return createNotice('info', content, options); |
279 } |
335 } |
|
336 |
280 /** |
337 /** |
281 * Returns an action object used in signalling that an error notice is to be |
338 * Returns an action object used in signalling that an error notice is to be |
282 * created. Refer to `createNotice` for options documentation. |
339 * created. Refer to `createNotice` for options documentation. |
283 * |
340 * |
284 * @see createNotice |
341 * @see createNotice |
285 * |
342 * |
286 * @param {string} content Notice message. |
343 * @param {string} content Notice message. |
287 * @param {Object} [options] Optional notice options. |
344 * @param {Object} [options] Optional notice options. |
288 * |
345 * |
|
346 * @example |
|
347 * ```js |
|
348 * import { __ } from '@wordpress/i18n'; |
|
349 * import { useDispatch } from '@wordpress/data'; |
|
350 * import { store as noticesStore } from '@wordpress/notices'; |
|
351 * import { Button } from '@wordpress/components'; |
|
352 * |
|
353 * const ExampleComponent = () => { |
|
354 * const { createErrorNotice } = useDispatch( noticesStore ); |
|
355 * return ( |
|
356 * <Button |
|
357 * onClick={ () => |
|
358 * createErrorNotice( __( 'An error occurred!' ), { |
|
359 * type: 'snackbar', |
|
360 * explicitDismiss: true, |
|
361 * } ) |
|
362 * } |
|
363 * > |
|
364 * { __( |
|
365 * 'Generate an snackbar error notice with explicit dismiss button.' |
|
366 * ) } |
|
367 * </Button> |
|
368 * ); |
|
369 * }; |
|
370 * ``` |
|
371 * |
289 * @return {Object} Action object. |
372 * @return {Object} Action object. |
290 */ |
373 */ |
291 |
|
292 function createErrorNotice(content, options) { |
374 function createErrorNotice(content, options) { |
293 return createNotice('error', content, options); |
375 return createNotice('error', content, options); |
294 } |
376 } |
|
377 |
295 /** |
378 /** |
296 * Returns an action object used in signalling that a warning notice is to be |
379 * Returns an action object used in signalling that a warning notice is to be |
297 * created. Refer to `createNotice` for options documentation. |
380 * created. Refer to `createNotice` for options documentation. |
298 * |
381 * |
299 * @see createNotice |
382 * @see createNotice |
300 * |
383 * |
301 * @param {string} content Notice message. |
384 * @param {string} content Notice message. |
302 * @param {Object} [options] Optional notice options. |
385 * @param {Object} [options] Optional notice options. |
303 * |
386 * |
|
387 * @example |
|
388 * ```js |
|
389 * import { __ } from '@wordpress/i18n'; |
|
390 * import { useDispatch } from '@wordpress/data'; |
|
391 * import { store as noticesStore } from '@wordpress/notices'; |
|
392 * import { Button } from '@wordpress/components'; |
|
393 * |
|
394 * const ExampleComponent = () => { |
|
395 * const { createWarningNotice, createInfoNotice } = useDispatch( noticesStore ); |
|
396 * return ( |
|
397 * <Button |
|
398 * onClick={ () => |
|
399 * createWarningNotice( __( 'Warning!' ), { |
|
400 * onDismiss: () => { |
|
401 * createInfoNotice( |
|
402 * __( 'The warning has been dismissed!' ) |
|
403 * ); |
|
404 * }, |
|
405 * } ) |
|
406 * } |
|
407 * > |
|
408 * { __( 'Generates a warning notice with onDismiss callback' ) } |
|
409 * </Button> |
|
410 * ); |
|
411 * }; |
|
412 * ``` |
|
413 * |
304 * @return {Object} Action object. |
414 * @return {Object} Action object. |
305 */ |
415 */ |
306 |
|
307 function createWarningNotice(content, options) { |
416 function createWarningNotice(content, options) { |
308 return createNotice('warning', content, options); |
417 return createNotice('warning', content, options); |
309 } |
418 } |
|
419 |
310 /** |
420 /** |
311 * Returns an action object used in signalling that a notice is to be removed. |
421 * Returns an action object used in signalling that a notice is to be removed. |
312 * |
422 * |
313 * @param {string} id Notice unique identifier. |
423 * @param {string} id Notice unique identifier. |
314 * @param {string} [context='global'] Optional context (grouping) in which the notice is |
424 * @param {string} [context='global'] Optional context (grouping) in which the notice is |
315 * intended to appear. Defaults to default context. |
425 * intended to appear. Defaults to default context. |
316 * |
426 * |
|
427 * @example |
|
428 * ```js |
|
429 * import { __ } from '@wordpress/i18n'; |
|
430 * import { useDispatch } from '@wordpress/data'; |
|
431 * import { store as noticesStore } from '@wordpress/notices'; |
|
432 * import { Button } from '@wordpress/components'; |
|
433 * |
|
434 * const ExampleComponent = () => { |
|
435 * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() ); |
|
436 * const { createWarningNotice, removeNotice } = useDispatch( noticesStore ); |
|
437 * |
|
438 * return ( |
|
439 * <> |
|
440 * <Button |
|
441 * onClick={ () => |
|
442 * createWarningNotice( __( 'Warning!' ), { |
|
443 * isDismissible: false, |
|
444 * } ) |
|
445 * } |
|
446 * > |
|
447 * { __( 'Generate a notice' ) } |
|
448 * </Button> |
|
449 * { notices.length > 0 && ( |
|
450 * <Button onClick={ () => removeNotice( notices[ 0 ].id ) }> |
|
451 * { __( 'Remove the notice' ) } |
|
452 * </Button> |
|
453 * ) } |
|
454 * </> |
|
455 * ); |
|
456 *}; |
|
457 * ``` |
|
458 * |
317 * @return {Object} Action object. |
459 * @return {Object} Action object. |
318 */ |
460 */ |
319 |
461 function removeNotice(id, context = DEFAULT_CONTEXT) { |
320 function removeNotice(id) { |
|
321 let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_CONTEXT; |
|
322 return { |
462 return { |
323 type: 'REMOVE_NOTICE', |
463 type: 'REMOVE_NOTICE', |
324 id, |
464 id, |
325 context |
465 context |
326 }; |
466 }; |
327 } |
467 } |
328 |
468 |
|
469 /** |
|
470 * Removes all notices from a given context. Defaults to the default context. |
|
471 * |
|
472 * @param {string} noticeType The context to remove all notices from. |
|
473 * @param {string} context The context to remove all notices from. |
|
474 * |
|
475 * @example |
|
476 * ```js |
|
477 * import { __ } from '@wordpress/i18n'; |
|
478 * import { useDispatch, useSelect } from '@wordpress/data'; |
|
479 * import { store as noticesStore } from '@wordpress/notices'; |
|
480 * import { Button } from '@wordpress/components'; |
|
481 * |
|
482 * export const ExampleComponent = () => { |
|
483 * const notices = useSelect( ( select ) => |
|
484 * select( noticesStore ).getNotices() |
|
485 * ); |
|
486 * const { removeAllNotices } = useDispatch( noticesStore ); |
|
487 * return ( |
|
488 * <> |
|
489 * <ul> |
|
490 * { notices.map( ( notice ) => ( |
|
491 * <li key={ notice.id }>{ notice.content }</li> |
|
492 * ) ) } |
|
493 * </ul> |
|
494 * <Button |
|
495 * onClick={ () => |
|
496 * removeAllNotices() |
|
497 * } |
|
498 * > |
|
499 * { __( 'Clear all notices', 'woo-gutenberg-products-block' ) } |
|
500 * </Button> |
|
501 * <Button |
|
502 * onClick={ () => |
|
503 * removeAllNotices( 'snackbar' ) |
|
504 * } |
|
505 * > |
|
506 * { __( 'Clear all snackbar notices', 'woo-gutenberg-products-block' ) } |
|
507 * </Button> |
|
508 * </> |
|
509 * ); |
|
510 * }; |
|
511 * ``` |
|
512 * |
|
513 * @return {Object} Action object. |
|
514 */ |
|
515 function removeAllNotices(noticeType = 'default', context = DEFAULT_CONTEXT) { |
|
516 return { |
|
517 type: 'REMOVE_ALL_NOTICES', |
|
518 noticeType, |
|
519 context |
|
520 }; |
|
521 } |
|
522 |
|
523 /** |
|
524 * Returns an action object used in signalling that several notices are to be removed. |
|
525 * |
|
526 * @param {string[]} ids List of unique notice identifiers. |
|
527 * @param {string} [context='global'] Optional context (grouping) in which the notices are |
|
528 * intended to appear. Defaults to default context. |
|
529 * @example |
|
530 * ```js |
|
531 * import { __ } from '@wordpress/i18n'; |
|
532 * import { useDispatch, useSelect } from '@wordpress/data'; |
|
533 * import { store as noticesStore } from '@wordpress/notices'; |
|
534 * import { Button } from '@wordpress/components'; |
|
535 * |
|
536 * const ExampleComponent = () => { |
|
537 * const notices = useSelect( ( select ) => |
|
538 * select( noticesStore ).getNotices() |
|
539 * ); |
|
540 * const { removeNotices } = useDispatch( noticesStore ); |
|
541 * return ( |
|
542 * <> |
|
543 * <ul> |
|
544 * { notices.map( ( notice ) => ( |
|
545 * <li key={ notice.id }>{ notice.content }</li> |
|
546 * ) ) } |
|
547 * </ul> |
|
548 * <Button |
|
549 * onClick={ () => |
|
550 * removeNotices( notices.map( ( { id } ) => id ) ) |
|
551 * } |
|
552 * > |
|
553 * { __( 'Clear all notices' ) } |
|
554 * </Button> |
|
555 * </> |
|
556 * ); |
|
557 * }; |
|
558 * ``` |
|
559 * @return {Object} Action object. |
|
560 */ |
|
561 function removeNotices(ids, context = DEFAULT_CONTEXT) { |
|
562 return { |
|
563 type: 'REMOVE_NOTICES', |
|
564 ids, |
|
565 context |
|
566 }; |
|
567 } |
|
568 |
329 ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/selectors.js |
569 ;// CONCATENATED MODULE: ./node_modules/@wordpress/notices/build-module/store/selectors.js |
330 /** |
570 /** |
331 * Internal dependencies |
571 * Internal dependencies |
332 */ |
572 */ |
|
573 |
333 |
574 |
334 /** @typedef {import('./actions').WPNoticeAction} WPNoticeAction */ |
575 /** @typedef {import('./actions').WPNoticeAction} WPNoticeAction */ |
335 |
576 |
336 /** |
577 /** |
337 * The default empty set of notices to return when there are no notices |
578 * The default empty set of notices to return when there are no notices |