@wordpress/notices 3.10.0 → 3.13.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 +6 -0
- package/build/store/actions.js +159 -11
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +10 -10
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +18 -0
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils/on-sub-key.js.map +1 -1
- package/build-module/store/actions.js +158 -9
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +10 -9
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +18 -0
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils/on-sub-key.js.map +1 -1
- package/package.json +4 -5
- package/src/store/actions.js +159 -9
- package/src/store/reducer.js +2 -7
- package/src/store/selectors.js +18 -0
- package/src/store/utils/on-sub-key.js +20 -20
package/CHANGELOG.md
CHANGED
package/build/store/actions.js
CHANGED
@@ -10,14 +10,8 @@ exports.createSuccessNotice = createSuccessNotice;
|
|
10
10
|
exports.createWarningNotice = createWarningNotice;
|
11
11
|
exports.removeNotice = removeNotice;
|
12
12
|
|
13
|
-
var _lodash = require("lodash");
|
14
|
-
|
15
13
|
var _constants = require("./constants");
|
16
14
|
|
17
|
-
/**
|
18
|
-
* External dependencies
|
19
|
-
*/
|
20
|
-
|
21
15
|
/**
|
22
16
|
* Internal dependencies
|
23
17
|
*/
|
@@ -32,7 +26,7 @@ var _constants = require("./constants");
|
|
32
26
|
* triggered by user.
|
33
27
|
*
|
34
28
|
*/
|
35
|
-
|
29
|
+
let uniqueId = 0;
|
36
30
|
/**
|
37
31
|
* Returns an action object used in signalling that a notice is to be created.
|
38
32
|
*
|
@@ -54,15 +48,37 @@ var _constants = require("./constants");
|
|
54
48
|
* readers.
|
55
49
|
* @param {Array<WPNoticeAction>} [options.actions] User actions to be
|
56
50
|
* presented with notice.
|
57
|
-
* @param {
|
51
|
+
* @param {string} [options.icon] An icon displayed with the notice.
|
52
|
+
* Only used when type is set to `snackbar`.
|
58
53
|
* @param {boolean} [options.explicitDismiss] Whether the notice includes
|
59
|
-
* an
|
54
|
+
* an explicit dismiss button and
|
60
55
|
* can't be dismissed by clicking
|
61
|
-
* the body of the notice.
|
56
|
+
* the body of the notice. Only applies
|
57
|
+
* when type is set to `snackbar`.
|
62
58
|
* @param {Function} [options.onDismiss] Called when the notice is dismissed.
|
63
59
|
*
|
60
|
+
* @example
|
61
|
+
* ```js
|
62
|
+
* import { __ } from '@wordpress/i18n';
|
63
|
+
* import { useDispatch } from '@wordpress/data';
|
64
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
65
|
+
* import { Button } from '@wordpress/components';
|
66
|
+
*
|
67
|
+
* const ExampleComponent = () => {
|
68
|
+
* const { createNotice } = useDispatch( noticesStore );
|
69
|
+
* return (
|
70
|
+
* <Button
|
71
|
+
* onClick={ () => createNotice( 'success', __( 'Notice message' ) ) }
|
72
|
+
* >
|
73
|
+
* { __( 'Generate a success notice!' ) }
|
74
|
+
* </Button>
|
75
|
+
* );
|
76
|
+
* };
|
77
|
+
* ```
|
78
|
+
*
|
64
79
|
* @return {Object} Action object.
|
65
80
|
*/
|
81
|
+
|
66
82
|
function createNotice() {
|
67
83
|
let status = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.DEFAULT_STATUS;
|
68
84
|
let content = arguments.length > 1 ? arguments[1] : undefined;
|
@@ -71,7 +87,7 @@ function createNotice() {
|
|
71
87
|
speak = true,
|
72
88
|
isDismissible = true,
|
73
89
|
context = _constants.DEFAULT_CONTEXT,
|
74
|
-
id =
|
90
|
+
id = `${context}${++uniqueId}`,
|
75
91
|
actions = [],
|
76
92
|
type = 'default',
|
77
93
|
__unstableHTML,
|
@@ -110,6 +126,30 @@ function createNotice() {
|
|
110
126
|
* @param {string} content Notice message.
|
111
127
|
* @param {Object} [options] Optional notice options.
|
112
128
|
*
|
129
|
+
* @example
|
130
|
+
* ```js
|
131
|
+
* import { __ } from '@wordpress/i18n';
|
132
|
+
* import { useDispatch } from '@wordpress/data';
|
133
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
134
|
+
* import { Button } from '@wordpress/components';
|
135
|
+
*
|
136
|
+
* const ExampleComponent = () => {
|
137
|
+
* const { createSuccessNotice } = useDispatch( noticesStore );
|
138
|
+
* return (
|
139
|
+
* <Button
|
140
|
+
* onClick={ () =>
|
141
|
+
* createSuccessNotice( __( 'Success!' ), {
|
142
|
+
* type: 'snackbar',
|
143
|
+
* icon: '🔥',
|
144
|
+
* } )
|
145
|
+
* }
|
146
|
+
* >
|
147
|
+
* { __( 'Generate a snackbar success notice!' ) }
|
148
|
+
* </Button>
|
149
|
+
* );
|
150
|
+
* };
|
151
|
+
* ```
|
152
|
+
*
|
113
153
|
* @return {Object} Action object.
|
114
154
|
*/
|
115
155
|
|
@@ -126,6 +166,29 @@ function createSuccessNotice(content, options) {
|
|
126
166
|
* @param {string} content Notice message.
|
127
167
|
* @param {Object} [options] Optional notice options.
|
128
168
|
*
|
169
|
+
* @example
|
170
|
+
* ```js
|
171
|
+
* import { __ } from '@wordpress/i18n';
|
172
|
+
* import { useDispatch } from '@wordpress/data';
|
173
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
174
|
+
* import { Button } from '@wordpress/components';
|
175
|
+
*
|
176
|
+
* const ExampleComponent = () => {
|
177
|
+
* const { createInfoNotice } = useDispatch( noticesStore );
|
178
|
+
* return (
|
179
|
+
* <Button
|
180
|
+
* onClick={ () =>
|
181
|
+
* createInfoNotice( __( 'Something happened!' ), {
|
182
|
+
* isDismissible: false,
|
183
|
+
* } )
|
184
|
+
* }
|
185
|
+
* >
|
186
|
+
* { __( 'Generate a notice that cannot be dismissed.' ) }
|
187
|
+
* </Button>
|
188
|
+
* );
|
189
|
+
* };
|
190
|
+
*```
|
191
|
+
*
|
129
192
|
* @return {Object} Action object.
|
130
193
|
*/
|
131
194
|
|
@@ -142,6 +205,32 @@ function createInfoNotice(content, options) {
|
|
142
205
|
* @param {string} content Notice message.
|
143
206
|
* @param {Object} [options] Optional notice options.
|
144
207
|
*
|
208
|
+
* @example
|
209
|
+
* ```js
|
210
|
+
* import { __ } from '@wordpress/i18n';
|
211
|
+
* import { useDispatch } from '@wordpress/data';
|
212
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
213
|
+
* import { Button } from '@wordpress/components';
|
214
|
+
*
|
215
|
+
* const ExampleComponent = () => {
|
216
|
+
* const { createErrorNotice } = useDispatch( noticesStore );
|
217
|
+
* return (
|
218
|
+
* <Button
|
219
|
+
* onClick={ () =>
|
220
|
+
* createErrorNotice( __( 'An error occurred!' ), {
|
221
|
+
* type: 'snackbar',
|
222
|
+
* explicitDismiss: true,
|
223
|
+
* } )
|
224
|
+
* }
|
225
|
+
* >
|
226
|
+
* { __(
|
227
|
+
* 'Generate an snackbar error notice with explicit dismiss button.'
|
228
|
+
* ) }
|
229
|
+
* </Button>
|
230
|
+
* );
|
231
|
+
* };
|
232
|
+
* ```
|
233
|
+
*
|
145
234
|
* @return {Object} Action object.
|
146
235
|
*/
|
147
236
|
|
@@ -158,6 +247,33 @@ function createErrorNotice(content, options) {
|
|
158
247
|
* @param {string} content Notice message.
|
159
248
|
* @param {Object} [options] Optional notice options.
|
160
249
|
*
|
250
|
+
* @example
|
251
|
+
* ```js
|
252
|
+
* import { __ } from '@wordpress/i18n';
|
253
|
+
* import { useDispatch } from '@wordpress/data';
|
254
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
255
|
+
* import { Button } from '@wordpress/components';
|
256
|
+
*
|
257
|
+
* const ExampleComponent = () => {
|
258
|
+
* const { createWarningNotice, createInfoNotice } = useDispatch( noticesStore );
|
259
|
+
* return (
|
260
|
+
* <Button
|
261
|
+
* onClick={ () =>
|
262
|
+
* createWarningNotice( __( 'Warning!' ), {
|
263
|
+
* onDismiss: () => {
|
264
|
+
* createInfoNotice(
|
265
|
+
* __( 'The warning has been dismissed!' )
|
266
|
+
* );
|
267
|
+
* },
|
268
|
+
* } )
|
269
|
+
* }
|
270
|
+
* >
|
271
|
+
* { __( 'Generates a warning notice with onDismiss callback' ) }
|
272
|
+
* </Button>
|
273
|
+
* );
|
274
|
+
* };
|
275
|
+
* ```
|
276
|
+
*
|
161
277
|
* @return {Object} Action object.
|
162
278
|
*/
|
163
279
|
|
@@ -172,6 +288,38 @@ function createWarningNotice(content, options) {
|
|
172
288
|
* @param {string} [context='global'] Optional context (grouping) in which the notice is
|
173
289
|
* intended to appear. Defaults to default context.
|
174
290
|
*
|
291
|
+
* @example
|
292
|
+
* ```js
|
293
|
+
* import { __ } from '@wordpress/i18n';
|
294
|
+
* import { useDispatch } from '@wordpress/data';
|
295
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
296
|
+
* import { Button } from '@wordpress/components';
|
297
|
+
*
|
298
|
+
* const ExampleComponent = () => {
|
299
|
+
* const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );
|
300
|
+
* const { createWarningNotice, removeNotice } = useDispatch( noticesStore );
|
301
|
+
*
|
302
|
+
* return (
|
303
|
+
* <>
|
304
|
+
* <Button
|
305
|
+
* onClick={ () =>
|
306
|
+
* createWarningNotice( __( 'Warning!' ), {
|
307
|
+
* isDismissible: false,
|
308
|
+
* } )
|
309
|
+
* }
|
310
|
+
* >
|
311
|
+
* { __( 'Generate a notice' ) }
|
312
|
+
* </Button>
|
313
|
+
* { notices.length > 0 && (
|
314
|
+
* <Button onClick={ () => removeNotice( notices[ 0 ].id ) }>
|
315
|
+
* { __( 'Remove the notice' ) }
|
316
|
+
* </Button>
|
317
|
+
* ) }
|
318
|
+
* </>
|
319
|
+
* );
|
320
|
+
*};
|
321
|
+
* ```
|
322
|
+
*
|
175
323
|
* @return {Object} Action object.
|
176
324
|
*/
|
177
325
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/notices/src/store/actions.js"],"names":["createNotice","status","DEFAULT_STATUS","content","options","speak","isDismissible","context","DEFAULT_CONTEXT","id","actions","type","__unstableHTML","icon","explicitDismiss","onDismiss","String","notice","spokenMessage","createSuccessNotice","createInfoNotice","createErrorNotice","createWarningNotice","removeNotice"],"mappings":";;;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAT,GAAwE;AAAA,MAAjDC,MAAiD,uEAAxCC,yBAAwC;AAAA,MAAxBC,OAAwB;AAAA,MAAfC,OAAe,uEAAL,EAAK;AAC9E,QAAM;AACLC,IAAAA,KAAK,GAAG,IADH;AAELC,IAAAA,aAAa,GAAG,IAFX;AAGLC,IAAAA,OAAO,GAAGC,0BAHL;AAILC,IAAAA,EAAE,GAAG,sBAAUF,OAAV,CAJA;AAKLG,IAAAA,OAAO,GAAG,EALL;AAMLC,IAAAA,IAAI,GAAG,SANF;AAOLC,IAAAA,cAPK;AAQLC,IAAAA,IAAI,GAAG,IARF;AASLC,IAAAA,eAAe,GAAG,KATb;AAULC,IAAAA;AAVK,MAWFX,OAXJ,CAD8E,CAc9E;AACA;AACA;;AACAD,EAAAA,OAAO,GAAGa,MAAM,CAAEb,OAAF,CAAhB;AAEA,SAAO;AACNQ,IAAAA,IAAI,EAAE,eADA;AAENJ,IAAAA,OAFM;AAGNU,IAAAA,MAAM,EAAE;AACPR,MAAAA,EADO;AAEPR,MAAAA,MAFO;AAGPE,MAAAA,OAHO;AAIPe,MAAAA,aAAa,EAAEb,KAAK,GAAGF,OAAH,GAAa,IAJ1B;AAKPS,MAAAA,cALO;AAMPN,MAAAA,aANO;AAOPI,MAAAA,OAPO;AAQPC,MAAAA,IARO;AASPE,MAAAA,IATO;AAUPC,MAAAA,eAVO;AAWPC,MAAAA;AAXO;AAHF,GAAP;AAiBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,mBAAT,CAA8BhB,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOJ,YAAY,CAAE,SAAF,EAAaG,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASgB,gBAAT,CAA2BjB,OAA3B,EAAoCC,OAApC,EAA8C;AACpD,SAAOJ,YAAY,CAAE,MAAF,EAAUG,OAAV,EAAmBC,OAAnB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASiB,iBAAT,CAA4BlB,OAA5B,EAAqCC,OAArC,EAA+C;AACrD,SAAOJ,YAAY,CAAE,OAAF,EAAWG,OAAX,EAAoBC,OAApB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASkB,mBAAT,CAA8BnB,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOJ,YAAY,CAAE,SAAF,EAAaG,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASmB,YAAT,CAAuBd,EAAvB,EAAuD;AAAA,MAA5BF,OAA4B,uEAAlBC,0BAAkB;AAC7D,SAAO;AACNG,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,EAFM;AAGNF,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\n * External dependencies\n */\nimport { uniqueId } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';\n\n/**\n * @typedef {Object} WPNoticeAction Object describing a user action option associated with a notice.\n *\n * @property {string} label Message to use as action label.\n * @property {?string} url Optional URL of resource if action incurs\n * browser navigation.\n * @property {?Function} onClick Optional function to invoke when action is\n * triggered by user.\n *\n */\n\n/**\n * Returns an action object used in signalling that a notice is to be created.\n *\n * @param {string} [status='info'] Notice status.\n * @param {string} content Notice message.\n * @param {Object} [options] Notice options.\n * @param {string} [options.context='global'] Context under which to\n * group notice.\n * @param {string} [options.id] Identifier for notice.\n * Automatically assigned\n * if not specified.\n * @param {boolean} [options.isDismissible=true] Whether the notice can\n * be dismissed by user.\n * @param {string} [options.type='default'] Type of notice, one of\n * `default`, or `snackbar`.\n * @param {boolean} [options.speak=true] Whether the notice\n * content should be\n * announced to screen\n * readers.\n * @param {Array<WPNoticeAction>} [options.actions] User actions to be\n * presented with notice.\n * @param {Object} [options.icon] An icon displayed with the notice.\n * @param {boolean} [options.explicitDismiss] Whether the notice includes\n * an explict dismiss button and\n * can't be dismissed by clicking\n * the body of the notice.\n * @param {Function} [options.onDismiss] Called when the notice is dismissed.\n *\n * @return {Object} Action object.\n */\nexport function createNotice( status = DEFAULT_STATUS, content, options = {} ) {\n\tconst {\n\t\tspeak = true,\n\t\tisDismissible = true,\n\t\tcontext = DEFAULT_CONTEXT,\n\t\tid = uniqueId( context ),\n\t\tactions = [],\n\t\ttype = 'default',\n\t\t__unstableHTML,\n\t\ticon = null,\n\t\texplicitDismiss = false,\n\t\tonDismiss,\n\t} = options;\n\n\t// The supported value shape of content is currently limited to plain text\n\t// strings. To avoid setting expectation that e.g. a WPElement could be\n\t// supported, cast to a string.\n\tcontent = String( content );\n\n\treturn {\n\t\ttype: 'CREATE_NOTICE',\n\t\tcontext,\n\t\tnotice: {\n\t\t\tid,\n\t\t\tstatus,\n\t\t\tcontent,\n\t\t\tspokenMessage: speak ? content : null,\n\t\t\t__unstableHTML,\n\t\t\tisDismissible,\n\t\t\tactions,\n\t\t\ttype,\n\t\t\ticon,\n\t\t\texplicitDismiss,\n\t\t\tonDismiss,\n\t\t},\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a success notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createSuccessNotice( content, options ) {\n\treturn createNotice( 'success', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an info notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createInfoNotice( content, options ) {\n\treturn createNotice( 'info', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an error notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createErrorNotice( content, options ) {\n\treturn createNotice( 'error', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a warning notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createWarningNotice( content, options ) {\n\treturn createNotice( 'warning', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a notice is to be removed.\n *\n * @param {string} id Notice unique identifier.\n * @param {string} [context='global'] Optional context (grouping) in which the notice is\n * intended to appear. Defaults to default context.\n *\n * @return {Object} Action object.\n */\nexport function removeNotice( id, context = DEFAULT_CONTEXT ) {\n\treturn {\n\t\ttype: 'REMOVE_NOTICE',\n\t\tid,\n\t\tcontext,\n\t};\n}\n"]}
|
1
|
+
{"version":3,"sources":["@wordpress/notices/src/store/actions.js"],"names":["uniqueId","createNotice","status","DEFAULT_STATUS","content","options","speak","isDismissible","context","DEFAULT_CONTEXT","id","actions","type","__unstableHTML","icon","explicitDismiss","onDismiss","String","notice","spokenMessage","createSuccessNotice","createInfoNotice","createErrorNotice","createWarningNotice","removeNotice"],"mappings":";;;;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,IAAIA,QAAQ,GAAG,CAAf;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,YAAT,GAAwE;AAAA,MAAjDC,MAAiD,uEAAxCC,yBAAwC;AAAA,MAAxBC,OAAwB;AAAA,MAAfC,OAAe,uEAAL,EAAK;AAC9E,QAAM;AACLC,IAAAA,KAAK,GAAG,IADH;AAELC,IAAAA,aAAa,GAAG,IAFX;AAGLC,IAAAA,OAAO,GAAGC,0BAHL;AAILC,IAAAA,EAAE,GAAI,GAAGF,OAAS,GAAG,EAAER,QAAU,EAJ5B;AAKLW,IAAAA,OAAO,GAAG,EALL;AAMLC,IAAAA,IAAI,GAAG,SANF;AAOLC,IAAAA,cAPK;AAQLC,IAAAA,IAAI,GAAG,IARF;AASLC,IAAAA,eAAe,GAAG,KATb;AAULC,IAAAA;AAVK,MAWFX,OAXJ,CAD8E,CAc9E;AACA;AACA;;AACAD,EAAAA,OAAO,GAAGa,MAAM,CAAEb,OAAF,CAAhB;AAEA,SAAO;AACNQ,IAAAA,IAAI,EAAE,eADA;AAENJ,IAAAA,OAFM;AAGNU,IAAAA,MAAM,EAAE;AACPR,MAAAA,EADO;AAEPR,MAAAA,MAFO;AAGPE,MAAAA,OAHO;AAIPe,MAAAA,aAAa,EAAEb,KAAK,GAAGF,OAAH,GAAa,IAJ1B;AAKPS,MAAAA,cALO;AAMPN,MAAAA,aANO;AAOPI,MAAAA,OAPO;AAQPC,MAAAA,IARO;AASPE,MAAAA,IATO;AAUPC,MAAAA,eAVO;AAWPC,MAAAA;AAXO;AAHF,GAAP;AAiBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,mBAAT,CAA8BhB,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOJ,YAAY,CAAE,SAAF,EAAaG,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASgB,gBAAT,CAA2BjB,OAA3B,EAAoCC,OAApC,EAA8C;AACpD,SAAOJ,YAAY,CAAE,MAAF,EAAUG,OAAV,EAAmBC,OAAnB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASiB,iBAAT,CAA4BlB,OAA5B,EAAqCC,OAArC,EAA+C;AACrD,SAAOJ,YAAY,CAAE,OAAF,EAAWG,OAAX,EAAoBC,OAApB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASkB,mBAAT,CAA8BnB,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOJ,YAAY,CAAE,SAAF,EAAaG,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASmB,YAAT,CAAuBd,EAAvB,EAAuD;AAAA,MAA5BF,OAA4B,uEAAlBC,0BAAkB;AAC7D,SAAO;AACNG,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,EAFM;AAGNF,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';\n\n/**\n * @typedef {Object} WPNoticeAction Object describing a user action option associated with a notice.\n *\n * @property {string} label Message to use as action label.\n * @property {?string} url Optional URL of resource if action incurs\n * browser navigation.\n * @property {?Function} onClick Optional function to invoke when action is\n * triggered by user.\n *\n */\n\nlet uniqueId = 0;\n\n/**\n * Returns an action object used in signalling that a notice is to be created.\n *\n * @param {string} [status='info'] Notice status.\n * @param {string} content Notice message.\n * @param {Object} [options] Notice options.\n * @param {string} [options.context='global'] Context under which to\n * group notice.\n * @param {string} [options.id] Identifier for notice.\n * Automatically assigned\n * if not specified.\n * @param {boolean} [options.isDismissible=true] Whether the notice can\n * be dismissed by user.\n * @param {string} [options.type='default'] Type of notice, one of\n * `default`, or `snackbar`.\n * @param {boolean} [options.speak=true] Whether the notice\n * content should be\n * announced to screen\n * readers.\n * @param {Array<WPNoticeAction>} [options.actions] User actions to be\n * presented with notice.\n * @param {string} [options.icon] An icon displayed with the notice.\n * Only used when type is set to `snackbar`.\n * @param {boolean} [options.explicitDismiss] Whether the notice includes\n * an explicit dismiss button and\n * can't be dismissed by clicking\n * the body of the notice. Only applies\n * when type is set to `snackbar`.\n * @param {Function} [options.onDismiss] Called when the notice is dismissed.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () => createNotice( 'success', __( 'Notice message' ) ) }\n * >\n * { __( 'Generate a success notice!' ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createNotice( status = DEFAULT_STATUS, content, options = {} ) {\n\tconst {\n\t\tspeak = true,\n\t\tisDismissible = true,\n\t\tcontext = DEFAULT_CONTEXT,\n\t\tid = `${ context }${ ++uniqueId }`,\n\t\tactions = [],\n\t\ttype = 'default',\n\t\t__unstableHTML,\n\t\ticon = null,\n\t\texplicitDismiss = false,\n\t\tonDismiss,\n\t} = options;\n\n\t// The supported value shape of content is currently limited to plain text\n\t// strings. To avoid setting expectation that e.g. a WPElement could be\n\t// supported, cast to a string.\n\tcontent = String( content );\n\n\treturn {\n\t\ttype: 'CREATE_NOTICE',\n\t\tcontext,\n\t\tnotice: {\n\t\t\tid,\n\t\t\tstatus,\n\t\t\tcontent,\n\t\t\tspokenMessage: speak ? content : null,\n\t\t\t__unstableHTML,\n\t\t\tisDismissible,\n\t\t\tactions,\n\t\t\ttype,\n\t\t\ticon,\n\t\t\texplicitDismiss,\n\t\t\tonDismiss,\n\t\t},\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a success notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createSuccessNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createSuccessNotice( __( 'Success!' ), {\n * type: 'snackbar',\n * icon: '🔥',\n * } )\n * }\n * >\n * { __( 'Generate a snackbar success notice!' ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createSuccessNotice( content, options ) {\n\treturn createNotice( 'success', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an info notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createInfoNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createInfoNotice( __( 'Something happened!' ), {\n * isDismissible: false,\n * } )\n * }\n * >\n * { __( 'Generate a notice that cannot be dismissed.' ) }\n * </Button>\n * );\n * };\n *```\n *\n * @return {Object} Action object.\n */\nexport function createInfoNotice( content, options ) {\n\treturn createNotice( 'info', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an error notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createErrorNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createErrorNotice( __( 'An error occurred!' ), {\n * type: 'snackbar',\n * explicitDismiss: true,\n * } )\n * }\n * >\n * { __(\n * 'Generate an snackbar error notice with explicit dismiss button.'\n * ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createErrorNotice( content, options ) {\n\treturn createNotice( 'error', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a warning notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createWarningNotice, createInfoNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createWarningNotice( __( 'Warning!' ), {\n * onDismiss: () => {\n * createInfoNotice(\n * __( 'The warning has been dismissed!' )\n * );\n * },\n * } )\n * }\n * >\n * { __( 'Generates a warning notice with onDismiss callback' ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createWarningNotice( content, options ) {\n\treturn createNotice( 'warning', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a notice is to be removed.\n *\n * @param {string} id Notice unique identifier.\n * @param {string} [context='global'] Optional context (grouping) in which the notice is\n * intended to appear. Defaults to default context.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );\n * const { createWarningNotice, removeNotice } = useDispatch( noticesStore );\n *\n * return (\n * <>\n * <Button\n * onClick={ () =>\n * createWarningNotice( __( 'Warning!' ), {\n * isDismissible: false,\n * } )\n * }\n * >\n * { __( 'Generate a notice' ) }\n * </Button>\n * { notices.length > 0 && (\n * <Button onClick={ () => removeNotice( notices[ 0 ].id ) }>\n * { __( 'Remove the notice' ) }\n * </Button>\n * ) }\n * </>\n * );\n *};\n * ```\n *\n * @return {Object} Action object.\n */\nexport function removeNotice( id, context = DEFAULT_CONTEXT ) {\n\treturn {\n\t\ttype: 'REMOVE_NOTICE',\n\t\tid,\n\t\tcontext,\n\t};\n}\n"]}
|
package/build/store/reducer.js
CHANGED
@@ -7,14 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
});
|
8
8
|
exports.default = void 0;
|
9
9
|
|
10
|
-
var _lodash = require("lodash");
|
11
|
-
|
12
10
|
var _onSubKey = _interopRequireDefault(require("./utils/on-sub-key"));
|
13
11
|
|
14
|
-
/**
|
15
|
-
* External dependencies
|
16
|
-
*/
|
17
|
-
|
18
12
|
/**
|
19
13
|
* Internal dependencies
|
20
14
|
*/
|
@@ -35,13 +29,19 @@ const notices = (0, _onSubKey.default)('context')(function () {
|
|
35
29
|
switch (action.type) {
|
36
30
|
case 'CREATE_NOTICE':
|
37
31
|
// Avoid duplicates on ID.
|
38
|
-
return [...
|
39
|
-
|
32
|
+
return [...state.filter(_ref => {
|
33
|
+
let {
|
34
|
+
id
|
35
|
+
} = _ref;
|
36
|
+
return id !== action.notice.id;
|
40
37
|
}), action.notice];
|
41
38
|
|
42
39
|
case 'REMOVE_NOTICE':
|
43
|
-
return
|
44
|
-
|
40
|
+
return state.filter(_ref2 => {
|
41
|
+
let {
|
42
|
+
id
|
43
|
+
} = _ref2;
|
44
|
+
return id !== action.id;
|
45
45
|
});
|
46
46
|
}
|
47
47
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/notices/src/store/reducer.js"],"names":["notices","state","action","type","id","notice"],"mappings":";;;;;;;;;AAGA;;
|
1
|
+
{"version":3,"sources":["@wordpress/notices/src/store/reducer.js"],"names":["notices","state","action","type","filter","id","notice"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,OAAO,GAAG,uBAAU,SAAV,EAAuB,YAA0B;AAAA,MAAxBC,KAAwB,uEAAhB,EAAgB;AAAA,MAAZC,MAAY;;AAChE,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,eAAL;AACC;AACA,aAAO,CACN,GAAGF,KAAK,CAACG,MAAN,CAAc;AAAA,YAAE;AAAEC,UAAAA;AAAF,SAAF;AAAA,eAAcA,EAAE,KAAKH,MAAM,CAACI,MAAP,CAAcD,EAAnC;AAAA,OAAd,CADG,EAENH,MAAM,CAACI,MAFD,CAAP;;AAKD,SAAK,eAAL;AACC,aAAOL,KAAK,CAACG,MAAN,CAAc;AAAA,YAAE;AAAEC,UAAAA;AAAF,SAAF;AAAA,eAAcA,EAAE,KAAKH,MAAM,CAACG,EAA5B;AAAA,OAAd,CAAP;AATF;;AAYA,SAAOJ,KAAP;AACA,CAde,CAAhB;eAgBeD,O","sourcesContent":["/**\n * Internal dependencies\n */\nimport onSubKey from './utils/on-sub-key';\n\n/**\n * Reducer returning the next notices state. The notices state is an object\n * where each key is a context, its value an array of notice objects.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nconst notices = onSubKey( 'context' )( ( state = [], action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'CREATE_NOTICE':\n\t\t\t// Avoid duplicates on ID.\n\t\t\treturn [\n\t\t\t\t...state.filter( ( { id } ) => id !== action.notice.id ),\n\t\t\t\taction.notice,\n\t\t\t];\n\n\t\tcase 'REMOVE_NOTICE':\n\t\t\treturn state.filter( ( { id } ) => id !== action.id );\n\t}\n\n\treturn state;\n} );\n\nexport default notices;\n"]}
|
package/build/store/selectors.js
CHANGED
@@ -56,6 +56,24 @@ const DEFAULT_NOTICES = [];
|
|
56
56
|
* @param {Object} state Notices state.
|
57
57
|
* @param {?string} context Optional grouping context.
|
58
58
|
*
|
59
|
+
* @example
|
60
|
+
*
|
61
|
+
*```js
|
62
|
+
* import { useSelect } from '@wordpress/data';
|
63
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
64
|
+
*
|
65
|
+
* const ExampleComponent = () => {
|
66
|
+
* const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );
|
67
|
+
* return (
|
68
|
+
* <ul>
|
69
|
+
* { notices.map( ( notice ) => (
|
70
|
+
* <li key={ notice.ID }>{ notice.content }</li>
|
71
|
+
* ) ) }
|
72
|
+
* </ul>
|
73
|
+
* )
|
74
|
+
* };
|
75
|
+
*```
|
76
|
+
*
|
59
77
|
* @return {WPNotice[]} Array of notices.
|
60
78
|
*/
|
61
79
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/notices/src/store/selectors.js"],"names":["DEFAULT_NOTICES","getNotices","state","context","DEFAULT_CONTEXT"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAG,EAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,UAAT,CAAqBC,KAArB,EAAwD;AAAA,MAA5BC,OAA4B,uEAAlBC,0BAAkB;AAC9D,SAAOF,KAAK,CAAEC,OAAF,CAAL,IAAoBH,eAA3B;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT } from './constants';\n\n/** @typedef {import('./actions').WPNoticeAction} WPNoticeAction */\n\n/**\n * The default empty set of notices to return when there are no notices\n * assigned for a given notices context. This can occur if the getNotices\n * selector is called without a notice ever having been created for the\n * context. A shared value is used to ensure referential equality between\n * sequential selector calls, since otherwise `[] !== []`.\n *\n * @type {Array}\n */\nconst DEFAULT_NOTICES = [];\n\n/**\n * @typedef {Object} WPNotice Notice object.\n *\n * @property {string} id Unique identifier of notice.\n * @property {string} status Status of notice, one of `success`,\n * `info`, `error`, or `warning`. Defaults\n * to `info`.\n * @property {string} content Notice message.\n * @property {string} spokenMessage Audibly announced message text used by\n * assistive technologies.\n * @property {string} __unstableHTML Notice message as raw HTML. Intended to\n * serve primarily for compatibility of\n * server-rendered notices, and SHOULD NOT\n * be used for notices. It is subject to\n * removal without notice.\n * @property {boolean} isDismissible Whether the notice can be dismissed by\n * user. Defaults to `true`.\n * @property {string} type Type of notice, one of `default`,\n * or `snackbar`. Defaults to `default`.\n * @property {boolean} speak Whether the notice content should be\n * announced to screen readers. Defaults to\n * `true`.\n * @property {WPNoticeAction[]} actions User actions to present with notice.\n *\n */\n\n/**\n * Returns all notices as an array, optionally for a given context. Defaults to\n * the global context.\n *\n * @param {Object} state Notices state.\n * @param {?string} context Optional grouping context.\n *\n * @return {WPNotice[]} Array of notices.\n */\nexport function getNotices( state, context = DEFAULT_CONTEXT ) {\n\treturn state[ context ] || DEFAULT_NOTICES;\n}\n"]}
|
1
|
+
{"version":3,"sources":["@wordpress/notices/src/store/selectors.js"],"names":["DEFAULT_NOTICES","getNotices","state","context","DEFAULT_CONTEXT"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAG,EAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,UAAT,CAAqBC,KAArB,EAAwD;AAAA,MAA5BC,OAA4B,uEAAlBC,0BAAkB;AAC9D,SAAOF,KAAK,CAAEC,OAAF,CAAL,IAAoBH,eAA3B;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT } from './constants';\n\n/** @typedef {import('./actions').WPNoticeAction} WPNoticeAction */\n\n/**\n * The default empty set of notices to return when there are no notices\n * assigned for a given notices context. This can occur if the getNotices\n * selector is called without a notice ever having been created for the\n * context. A shared value is used to ensure referential equality between\n * sequential selector calls, since otherwise `[] !== []`.\n *\n * @type {Array}\n */\nconst DEFAULT_NOTICES = [];\n\n/**\n * @typedef {Object} WPNotice Notice object.\n *\n * @property {string} id Unique identifier of notice.\n * @property {string} status Status of notice, one of `success`,\n * `info`, `error`, or `warning`. Defaults\n * to `info`.\n * @property {string} content Notice message.\n * @property {string} spokenMessage Audibly announced message text used by\n * assistive technologies.\n * @property {string} __unstableHTML Notice message as raw HTML. Intended to\n * serve primarily for compatibility of\n * server-rendered notices, and SHOULD NOT\n * be used for notices. It is subject to\n * removal without notice.\n * @property {boolean} isDismissible Whether the notice can be dismissed by\n * user. Defaults to `true`.\n * @property {string} type Type of notice, one of `default`,\n * or `snackbar`. Defaults to `default`.\n * @property {boolean} speak Whether the notice content should be\n * announced to screen readers. Defaults to\n * `true`.\n * @property {WPNoticeAction[]} actions User actions to present with notice.\n *\n */\n\n/**\n * Returns all notices as an array, optionally for a given context. Defaults to\n * the global context.\n *\n * @param {Object} state Notices state.\n * @param {?string} context Optional grouping context.\n *\n * @example\n *\n *```js\n * import { useSelect } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n *\n * const ExampleComponent = () => {\n * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );\n * return (\n * <ul>\n * { notices.map( ( notice ) => (\n * <li key={ notice.ID }>{ notice.content }</li>\n * ) ) }\n * </ul>\n * )\n * };\n *```\n *\n * @return {WPNotice[]} Array of notices.\n */\nexport function getNotices( state, context = DEFAULT_CONTEXT ) {\n\treturn state[ context ] || DEFAULT_NOTICES;\n}\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/notices/src/store/utils/on-sub-key.js"],"names":["onSubKey","actionProperty","reducer","state","action","key","undefined","nextKeyState"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,
|
1
|
+
{"version":3,"sources":["@wordpress/notices/src/store/utils/on-sub-key.js"],"names":["onSubKey","actionProperty","reducer","state","action","key","undefined","nextKeyState"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,GAClBC,cAAF,IACEC,OAAF,IACA,YAA0B;AAAA,MAAxBC,KAAwB,uEAAhB,EAAgB;AAAA,MAAZC,MAAY;AACzB;AACA;AACA,QAAMC,GAAG,GAAGD,MAAM,CAAEH,cAAF,CAAlB;;AACA,MAAKI,GAAG,KAAKC,SAAb,EAAyB;AACxB,WAAOH,KAAP;AACA,GANwB,CAQzB;AACA;;;AACA,QAAMI,YAAY,GAAGL,OAAO,CAAEC,KAAK,CAAEE,GAAF,CAAP,EAAgBD,MAAhB,CAA5B;;AACA,MAAKG,YAAY,KAAKJ,KAAK,CAAEE,GAAF,CAA3B,EAAqC;AACpC,WAAOF,KAAP;AACA;;AAED,SAAO,EACN,GAAGA,KADG;AAEN,KAAEE,GAAF,GAASE;AAFH,GAAP;AAIA,CAtBK;;;eAwBQP,Q","sourcesContent":["/**\n * Higher-order reducer creator which creates a combined reducer object, keyed\n * by a property on the action object.\n *\n * @param {string} actionProperty Action property by which to key object.\n *\n * @return {Function} Higher-order reducer.\n */\nexport const onSubKey =\n\t( actionProperty ) =>\n\t( reducer ) =>\n\t( state = {}, action ) => {\n\t\t// Retrieve subkey from action. Do not track if undefined; useful for cases\n\t\t// where reducer is scoped by action shape.\n\t\tconst key = action[ actionProperty ];\n\t\tif ( key === undefined ) {\n\t\t\treturn state;\n\t\t}\n\n\t\t// Avoid updating state if unchanged. Note that this also accounts for a\n\t\t// reducer which returns undefined on a key which is not yet tracked.\n\t\tconst nextKeyState = reducer( state[ key ], action );\n\t\tif ( nextKeyState === state[ key ] ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ key ]: nextKeyState,\n\t\t};\n\t};\n\nexport default onSubKey;\n"]}
|
@@ -1,11 +1,6 @@
|
|
1
|
-
/**
|
2
|
-
* External dependencies
|
3
|
-
*/
|
4
|
-
import { uniqueId } from 'lodash';
|
5
1
|
/**
|
6
2
|
* Internal dependencies
|
7
3
|
*/
|
8
|
-
|
9
4
|
import { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';
|
10
5
|
/**
|
11
6
|
* @typedef {Object} WPNoticeAction Object describing a user action option associated with a notice.
|
@@ -18,6 +13,7 @@ import { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';
|
|
18
13
|
*
|
19
14
|
*/
|
20
15
|
|
16
|
+
let uniqueId = 0;
|
21
17
|
/**
|
22
18
|
* Returns an action object used in signalling that a notice is to be created.
|
23
19
|
*
|
@@ -39,13 +35,34 @@ import { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';
|
|
39
35
|
* readers.
|
40
36
|
* @param {Array<WPNoticeAction>} [options.actions] User actions to be
|
41
37
|
* presented with notice.
|
42
|
-
* @param {
|
38
|
+
* @param {string} [options.icon] An icon displayed with the notice.
|
39
|
+
* Only used when type is set to `snackbar`.
|
43
40
|
* @param {boolean} [options.explicitDismiss] Whether the notice includes
|
44
|
-
* an
|
41
|
+
* an explicit dismiss button and
|
45
42
|
* can't be dismissed by clicking
|
46
|
-
* the body of the notice.
|
43
|
+
* the body of the notice. Only applies
|
44
|
+
* when type is set to `snackbar`.
|
47
45
|
* @param {Function} [options.onDismiss] Called when the notice is dismissed.
|
48
46
|
*
|
47
|
+
* @example
|
48
|
+
* ```js
|
49
|
+
* import { __ } from '@wordpress/i18n';
|
50
|
+
* import { useDispatch } from '@wordpress/data';
|
51
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
52
|
+
* import { Button } from '@wordpress/components';
|
53
|
+
*
|
54
|
+
* const ExampleComponent = () => {
|
55
|
+
* const { createNotice } = useDispatch( noticesStore );
|
56
|
+
* return (
|
57
|
+
* <Button
|
58
|
+
* onClick={ () => createNotice( 'success', __( 'Notice message' ) ) }
|
59
|
+
* >
|
60
|
+
* { __( 'Generate a success notice!' ) }
|
61
|
+
* </Button>
|
62
|
+
* );
|
63
|
+
* };
|
64
|
+
* ```
|
65
|
+
*
|
49
66
|
* @return {Object} Action object.
|
50
67
|
*/
|
51
68
|
|
@@ -57,7 +74,7 @@ export function createNotice() {
|
|
57
74
|
speak = true,
|
58
75
|
isDismissible = true,
|
59
76
|
context = DEFAULT_CONTEXT,
|
60
|
-
id = uniqueId
|
77
|
+
id = `${context}${++uniqueId}`,
|
61
78
|
actions = [],
|
62
79
|
type = 'default',
|
63
80
|
__unstableHTML,
|
@@ -96,6 +113,30 @@ export function createNotice() {
|
|
96
113
|
* @param {string} content Notice message.
|
97
114
|
* @param {Object} [options] Optional notice options.
|
98
115
|
*
|
116
|
+
* @example
|
117
|
+
* ```js
|
118
|
+
* import { __ } from '@wordpress/i18n';
|
119
|
+
* import { useDispatch } from '@wordpress/data';
|
120
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
121
|
+
* import { Button } from '@wordpress/components';
|
122
|
+
*
|
123
|
+
* const ExampleComponent = () => {
|
124
|
+
* const { createSuccessNotice } = useDispatch( noticesStore );
|
125
|
+
* return (
|
126
|
+
* <Button
|
127
|
+
* onClick={ () =>
|
128
|
+
* createSuccessNotice( __( 'Success!' ), {
|
129
|
+
* type: 'snackbar',
|
130
|
+
* icon: '🔥',
|
131
|
+
* } )
|
132
|
+
* }
|
133
|
+
* >
|
134
|
+
* { __( 'Generate a snackbar success notice!' ) }
|
135
|
+
* </Button>
|
136
|
+
* );
|
137
|
+
* };
|
138
|
+
* ```
|
139
|
+
*
|
99
140
|
* @return {Object} Action object.
|
100
141
|
*/
|
101
142
|
|
@@ -111,6 +152,29 @@ export function createSuccessNotice(content, options) {
|
|
111
152
|
* @param {string} content Notice message.
|
112
153
|
* @param {Object} [options] Optional notice options.
|
113
154
|
*
|
155
|
+
* @example
|
156
|
+
* ```js
|
157
|
+
* import { __ } from '@wordpress/i18n';
|
158
|
+
* import { useDispatch } from '@wordpress/data';
|
159
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
160
|
+
* import { Button } from '@wordpress/components';
|
161
|
+
*
|
162
|
+
* const ExampleComponent = () => {
|
163
|
+
* const { createInfoNotice } = useDispatch( noticesStore );
|
164
|
+
* return (
|
165
|
+
* <Button
|
166
|
+
* onClick={ () =>
|
167
|
+
* createInfoNotice( __( 'Something happened!' ), {
|
168
|
+
* isDismissible: false,
|
169
|
+
* } )
|
170
|
+
* }
|
171
|
+
* >
|
172
|
+
* { __( 'Generate a notice that cannot be dismissed.' ) }
|
173
|
+
* </Button>
|
174
|
+
* );
|
175
|
+
* };
|
176
|
+
*```
|
177
|
+
*
|
114
178
|
* @return {Object} Action object.
|
115
179
|
*/
|
116
180
|
|
@@ -126,6 +190,32 @@ export function createInfoNotice(content, options) {
|
|
126
190
|
* @param {string} content Notice message.
|
127
191
|
* @param {Object} [options] Optional notice options.
|
128
192
|
*
|
193
|
+
* @example
|
194
|
+
* ```js
|
195
|
+
* import { __ } from '@wordpress/i18n';
|
196
|
+
* import { useDispatch } from '@wordpress/data';
|
197
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
198
|
+
* import { Button } from '@wordpress/components';
|
199
|
+
*
|
200
|
+
* const ExampleComponent = () => {
|
201
|
+
* const { createErrorNotice } = useDispatch( noticesStore );
|
202
|
+
* return (
|
203
|
+
* <Button
|
204
|
+
* onClick={ () =>
|
205
|
+
* createErrorNotice( __( 'An error occurred!' ), {
|
206
|
+
* type: 'snackbar',
|
207
|
+
* explicitDismiss: true,
|
208
|
+
* } )
|
209
|
+
* }
|
210
|
+
* >
|
211
|
+
* { __(
|
212
|
+
* 'Generate an snackbar error notice with explicit dismiss button.'
|
213
|
+
* ) }
|
214
|
+
* </Button>
|
215
|
+
* );
|
216
|
+
* };
|
217
|
+
* ```
|
218
|
+
*
|
129
219
|
* @return {Object} Action object.
|
130
220
|
*/
|
131
221
|
|
@@ -141,6 +231,33 @@ export function createErrorNotice(content, options) {
|
|
141
231
|
* @param {string} content Notice message.
|
142
232
|
* @param {Object} [options] Optional notice options.
|
143
233
|
*
|
234
|
+
* @example
|
235
|
+
* ```js
|
236
|
+
* import { __ } from '@wordpress/i18n';
|
237
|
+
* import { useDispatch } from '@wordpress/data';
|
238
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
239
|
+
* import { Button } from '@wordpress/components';
|
240
|
+
*
|
241
|
+
* const ExampleComponent = () => {
|
242
|
+
* const { createWarningNotice, createInfoNotice } = useDispatch( noticesStore );
|
243
|
+
* return (
|
244
|
+
* <Button
|
245
|
+
* onClick={ () =>
|
246
|
+
* createWarningNotice( __( 'Warning!' ), {
|
247
|
+
* onDismiss: () => {
|
248
|
+
* createInfoNotice(
|
249
|
+
* __( 'The warning has been dismissed!' )
|
250
|
+
* );
|
251
|
+
* },
|
252
|
+
* } )
|
253
|
+
* }
|
254
|
+
* >
|
255
|
+
* { __( 'Generates a warning notice with onDismiss callback' ) }
|
256
|
+
* </Button>
|
257
|
+
* );
|
258
|
+
* };
|
259
|
+
* ```
|
260
|
+
*
|
144
261
|
* @return {Object} Action object.
|
145
262
|
*/
|
146
263
|
|
@@ -154,6 +271,38 @@ export function createWarningNotice(content, options) {
|
|
154
271
|
* @param {string} [context='global'] Optional context (grouping) in which the notice is
|
155
272
|
* intended to appear. Defaults to default context.
|
156
273
|
*
|
274
|
+
* @example
|
275
|
+
* ```js
|
276
|
+
* import { __ } from '@wordpress/i18n';
|
277
|
+
* import { useDispatch } from '@wordpress/data';
|
278
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
279
|
+
* import { Button } from '@wordpress/components';
|
280
|
+
*
|
281
|
+
* const ExampleComponent = () => {
|
282
|
+
* const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );
|
283
|
+
* const { createWarningNotice, removeNotice } = useDispatch( noticesStore );
|
284
|
+
*
|
285
|
+
* return (
|
286
|
+
* <>
|
287
|
+
* <Button
|
288
|
+
* onClick={ () =>
|
289
|
+
* createWarningNotice( __( 'Warning!' ), {
|
290
|
+
* isDismissible: false,
|
291
|
+
* } )
|
292
|
+
* }
|
293
|
+
* >
|
294
|
+
* { __( 'Generate a notice' ) }
|
295
|
+
* </Button>
|
296
|
+
* { notices.length > 0 && (
|
297
|
+
* <Button onClick={ () => removeNotice( notices[ 0 ].id ) }>
|
298
|
+
* { __( 'Remove the notice' ) }
|
299
|
+
* </Button>
|
300
|
+
* ) }
|
301
|
+
* </>
|
302
|
+
* );
|
303
|
+
*};
|
304
|
+
* ```
|
305
|
+
*
|
157
306
|
* @return {Object} Action object.
|
158
307
|
*/
|
159
308
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/notices/src/store/actions.js"],"names":["uniqueId","DEFAULT_CONTEXT","DEFAULT_STATUS","createNotice","status","content","options","speak","isDismissible","context","id","actions","type","__unstableHTML","icon","explicitDismiss","onDismiss","String","notice","spokenMessage","createSuccessNotice","createInfoNotice","createErrorNotice","createWarningNotice","removeNotice"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAT,QAAyB,QAAzB;AAEA;AACA;AACA;;AACA,SAASC,eAAT,EAA0BC,cAA1B,QAAgD,aAAhD;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,GAAwE;AAAA,MAAjDC,MAAiD,uEAAxCF,cAAwC;AAAA,MAAxBG,OAAwB;AAAA,MAAfC,OAAe,uEAAL,EAAK;AAC9E,QAAM;AACLC,IAAAA,KAAK,GAAG,IADH;AAELC,IAAAA,aAAa,GAAG,IAFX;AAGLC,IAAAA,OAAO,GAAGR,eAHL;AAILS,IAAAA,EAAE,GAAGV,QAAQ,CAAES,OAAF,CAJR;AAKLE,IAAAA,OAAO,GAAG,EALL;AAMLC,IAAAA,IAAI,GAAG,SANF;AAOLC,IAAAA,cAPK;AAQLC,IAAAA,IAAI,GAAG,IARF;AASLC,IAAAA,eAAe,GAAG,KATb;AAULC,IAAAA;AAVK,MAWFV,OAXJ,CAD8E,CAc9E;AACA;AACA;;AACAD,EAAAA,OAAO,GAAGY,MAAM,CAAEZ,OAAF,CAAhB;AAEA,SAAO;AACNO,IAAAA,IAAI,EAAE,eADA;AAENH,IAAAA,OAFM;AAGNS,IAAAA,MAAM,EAAE;AACPR,MAAAA,EADO;AAEPN,MAAAA,MAFO;AAGPC,MAAAA,OAHO;AAIPc,MAAAA,aAAa,EAAEZ,KAAK,GAAGF,OAAH,GAAa,IAJ1B;AAKPQ,MAAAA,cALO;AAMPL,MAAAA,aANO;AAOPG,MAAAA,OAPO;AAQPC,MAAAA,IARO;AASPE,MAAAA,IATO;AAUPC,MAAAA,eAVO;AAWPC,MAAAA;AAXO;AAHF,GAAP;AAiBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,mBAAT,CAA8Bf,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOH,YAAY,CAAE,SAAF,EAAaE,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASe,gBAAT,CAA2BhB,OAA3B,EAAoCC,OAApC,EAA8C;AACpD,SAAOH,YAAY,CAAE,MAAF,EAAUE,OAAV,EAAmBC,OAAnB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASgB,iBAAT,CAA4BjB,OAA5B,EAAqCC,OAArC,EAA+C;AACrD,SAAOH,YAAY,CAAE,OAAF,EAAWE,OAAX,EAAoBC,OAApB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASiB,mBAAT,CAA8BlB,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOH,YAAY,CAAE,SAAF,EAAaE,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkB,YAAT,CAAuBd,EAAvB,EAAuD;AAAA,MAA5BD,OAA4B,uEAAlBR,eAAkB;AAC7D,SAAO;AACNW,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,EAFM;AAGND,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\n * External dependencies\n */\nimport { uniqueId } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';\n\n/**\n * @typedef {Object} WPNoticeAction Object describing a user action option associated with a notice.\n *\n * @property {string} label Message to use as action label.\n * @property {?string} url Optional URL of resource if action incurs\n * browser navigation.\n * @property {?Function} onClick Optional function to invoke when action is\n * triggered by user.\n *\n */\n\n/**\n * Returns an action object used in signalling that a notice is to be created.\n *\n * @param {string} [status='info'] Notice status.\n * @param {string} content Notice message.\n * @param {Object} [options] Notice options.\n * @param {string} [options.context='global'] Context under which to\n * group notice.\n * @param {string} [options.id] Identifier for notice.\n * Automatically assigned\n * if not specified.\n * @param {boolean} [options.isDismissible=true] Whether the notice can\n * be dismissed by user.\n * @param {string} [options.type='default'] Type of notice, one of\n * `default`, or `snackbar`.\n * @param {boolean} [options.speak=true] Whether the notice\n * content should be\n * announced to screen\n * readers.\n * @param {Array<WPNoticeAction>} [options.actions] User actions to be\n * presented with notice.\n * @param {Object} [options.icon] An icon displayed with the notice.\n * @param {boolean} [options.explicitDismiss] Whether the notice includes\n * an explict dismiss button and\n * can't be dismissed by clicking\n * the body of the notice.\n * @param {Function} [options.onDismiss] Called when the notice is dismissed.\n *\n * @return {Object} Action object.\n */\nexport function createNotice( status = DEFAULT_STATUS, content, options = {} ) {\n\tconst {\n\t\tspeak = true,\n\t\tisDismissible = true,\n\t\tcontext = DEFAULT_CONTEXT,\n\t\tid = uniqueId( context ),\n\t\tactions = [],\n\t\ttype = 'default',\n\t\t__unstableHTML,\n\t\ticon = null,\n\t\texplicitDismiss = false,\n\t\tonDismiss,\n\t} = options;\n\n\t// The supported value shape of content is currently limited to plain text\n\t// strings. To avoid setting expectation that e.g. a WPElement could be\n\t// supported, cast to a string.\n\tcontent = String( content );\n\n\treturn {\n\t\ttype: 'CREATE_NOTICE',\n\t\tcontext,\n\t\tnotice: {\n\t\t\tid,\n\t\t\tstatus,\n\t\t\tcontent,\n\t\t\tspokenMessage: speak ? content : null,\n\t\t\t__unstableHTML,\n\t\t\tisDismissible,\n\t\t\tactions,\n\t\t\ttype,\n\t\t\ticon,\n\t\t\texplicitDismiss,\n\t\t\tonDismiss,\n\t\t},\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a success notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createSuccessNotice( content, options ) {\n\treturn createNotice( 'success', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an info notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createInfoNotice( content, options ) {\n\treturn createNotice( 'info', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an error notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createErrorNotice( content, options ) {\n\treturn createNotice( 'error', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a warning notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createWarningNotice( content, options ) {\n\treturn createNotice( 'warning', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a notice is to be removed.\n *\n * @param {string} id Notice unique identifier.\n * @param {string} [context='global'] Optional context (grouping) in which the notice is\n * intended to appear. Defaults to default context.\n *\n * @return {Object} Action object.\n */\nexport function removeNotice( id, context = DEFAULT_CONTEXT ) {\n\treturn {\n\t\ttype: 'REMOVE_NOTICE',\n\t\tid,\n\t\tcontext,\n\t};\n}\n"]}
|
1
|
+
{"version":3,"sources":["@wordpress/notices/src/store/actions.js"],"names":["DEFAULT_CONTEXT","DEFAULT_STATUS","uniqueId","createNotice","status","content","options","speak","isDismissible","context","id","actions","type","__unstableHTML","icon","explicitDismiss","onDismiss","String","notice","spokenMessage","createSuccessNotice","createInfoNotice","createErrorNotice","createWarningNotice","removeNotice"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,EAA0BC,cAA1B,QAAgD,aAAhD;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAIC,QAAQ,GAAG,CAAf;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,GAAwE;AAAA,MAAjDC,MAAiD,uEAAxCH,cAAwC;AAAA,MAAxBI,OAAwB;AAAA,MAAfC,OAAe,uEAAL,EAAK;AAC9E,QAAM;AACLC,IAAAA,KAAK,GAAG,IADH;AAELC,IAAAA,aAAa,GAAG,IAFX;AAGLC,IAAAA,OAAO,GAAGT,eAHL;AAILU,IAAAA,EAAE,GAAI,GAAGD,OAAS,GAAG,EAAEP,QAAU,EAJ5B;AAKLS,IAAAA,OAAO,GAAG,EALL;AAMLC,IAAAA,IAAI,GAAG,SANF;AAOLC,IAAAA,cAPK;AAQLC,IAAAA,IAAI,GAAG,IARF;AASLC,IAAAA,eAAe,GAAG,KATb;AAULC,IAAAA;AAVK,MAWFV,OAXJ,CAD8E,CAc9E;AACA;AACA;;AACAD,EAAAA,OAAO,GAAGY,MAAM,CAAEZ,OAAF,CAAhB;AAEA,SAAO;AACNO,IAAAA,IAAI,EAAE,eADA;AAENH,IAAAA,OAFM;AAGNS,IAAAA,MAAM,EAAE;AACPR,MAAAA,EADO;AAEPN,MAAAA,MAFO;AAGPC,MAAAA,OAHO;AAIPc,MAAAA,aAAa,EAAEZ,KAAK,GAAGF,OAAH,GAAa,IAJ1B;AAKPQ,MAAAA,cALO;AAMPL,MAAAA,aANO;AAOPG,MAAAA,OAPO;AAQPC,MAAAA,IARO;AASPE,MAAAA,IATO;AAUPC,MAAAA,eAVO;AAWPC,MAAAA;AAXO;AAHF,GAAP;AAiBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,mBAAT,CAA8Bf,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOH,YAAY,CAAE,SAAF,EAAaE,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASe,gBAAT,CAA2BhB,OAA3B,EAAoCC,OAApC,EAA8C;AACpD,SAAOH,YAAY,CAAE,MAAF,EAAUE,OAAV,EAAmBC,OAAnB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASgB,iBAAT,CAA4BjB,OAA5B,EAAqCC,OAArC,EAA+C;AACrD,SAAOH,YAAY,CAAE,OAAF,EAAWE,OAAX,EAAoBC,OAApB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASiB,mBAAT,CAA8BlB,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOH,YAAY,CAAE,SAAF,EAAaE,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkB,YAAT,CAAuBd,EAAvB,EAAuD;AAAA,MAA5BD,OAA4B,uEAAlBT,eAAkB;AAC7D,SAAO;AACNY,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,EAFM;AAGND,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';\n\n/**\n * @typedef {Object} WPNoticeAction Object describing a user action option associated with a notice.\n *\n * @property {string} label Message to use as action label.\n * @property {?string} url Optional URL of resource if action incurs\n * browser navigation.\n * @property {?Function} onClick Optional function to invoke when action is\n * triggered by user.\n *\n */\n\nlet uniqueId = 0;\n\n/**\n * Returns an action object used in signalling that a notice is to be created.\n *\n * @param {string} [status='info'] Notice status.\n * @param {string} content Notice message.\n * @param {Object} [options] Notice options.\n * @param {string} [options.context='global'] Context under which to\n * group notice.\n * @param {string} [options.id] Identifier for notice.\n * Automatically assigned\n * if not specified.\n * @param {boolean} [options.isDismissible=true] Whether the notice can\n * be dismissed by user.\n * @param {string} [options.type='default'] Type of notice, one of\n * `default`, or `snackbar`.\n * @param {boolean} [options.speak=true] Whether the notice\n * content should be\n * announced to screen\n * readers.\n * @param {Array<WPNoticeAction>} [options.actions] User actions to be\n * presented with notice.\n * @param {string} [options.icon] An icon displayed with the notice.\n * Only used when type is set to `snackbar`.\n * @param {boolean} [options.explicitDismiss] Whether the notice includes\n * an explicit dismiss button and\n * can't be dismissed by clicking\n * the body of the notice. Only applies\n * when type is set to `snackbar`.\n * @param {Function} [options.onDismiss] Called when the notice is dismissed.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () => createNotice( 'success', __( 'Notice message' ) ) }\n * >\n * { __( 'Generate a success notice!' ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createNotice( status = DEFAULT_STATUS, content, options = {} ) {\n\tconst {\n\t\tspeak = true,\n\t\tisDismissible = true,\n\t\tcontext = DEFAULT_CONTEXT,\n\t\tid = `${ context }${ ++uniqueId }`,\n\t\tactions = [],\n\t\ttype = 'default',\n\t\t__unstableHTML,\n\t\ticon = null,\n\t\texplicitDismiss = false,\n\t\tonDismiss,\n\t} = options;\n\n\t// The supported value shape of content is currently limited to plain text\n\t// strings. To avoid setting expectation that e.g. a WPElement could be\n\t// supported, cast to a string.\n\tcontent = String( content );\n\n\treturn {\n\t\ttype: 'CREATE_NOTICE',\n\t\tcontext,\n\t\tnotice: {\n\t\t\tid,\n\t\t\tstatus,\n\t\t\tcontent,\n\t\t\tspokenMessage: speak ? content : null,\n\t\t\t__unstableHTML,\n\t\t\tisDismissible,\n\t\t\tactions,\n\t\t\ttype,\n\t\t\ticon,\n\t\t\texplicitDismiss,\n\t\t\tonDismiss,\n\t\t},\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a success notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createSuccessNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createSuccessNotice( __( 'Success!' ), {\n * type: 'snackbar',\n * icon: '🔥',\n * } )\n * }\n * >\n * { __( 'Generate a snackbar success notice!' ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createSuccessNotice( content, options ) {\n\treturn createNotice( 'success', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an info notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createInfoNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createInfoNotice( __( 'Something happened!' ), {\n * isDismissible: false,\n * } )\n * }\n * >\n * { __( 'Generate a notice that cannot be dismissed.' ) }\n * </Button>\n * );\n * };\n *```\n *\n * @return {Object} Action object.\n */\nexport function createInfoNotice( content, options ) {\n\treturn createNotice( 'info', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an error notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createErrorNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createErrorNotice( __( 'An error occurred!' ), {\n * type: 'snackbar',\n * explicitDismiss: true,\n * } )\n * }\n * >\n * { __(\n * 'Generate an snackbar error notice with explicit dismiss button.'\n * ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createErrorNotice( content, options ) {\n\treturn createNotice( 'error', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a warning notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createWarningNotice, createInfoNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createWarningNotice( __( 'Warning!' ), {\n * onDismiss: () => {\n * createInfoNotice(\n * __( 'The warning has been dismissed!' )\n * );\n * },\n * } )\n * }\n * >\n * { __( 'Generates a warning notice with onDismiss callback' ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createWarningNotice( content, options ) {\n\treturn createNotice( 'warning', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a notice is to be removed.\n *\n * @param {string} id Notice unique identifier.\n * @param {string} [context='global'] Optional context (grouping) in which the notice is\n * intended to appear. Defaults to default context.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );\n * const { createWarningNotice, removeNotice } = useDispatch( noticesStore );\n *\n * return (\n * <>\n * <Button\n * onClick={ () =>\n * createWarningNotice( __( 'Warning!' ), {\n * isDismissible: false,\n * } )\n * }\n * >\n * { __( 'Generate a notice' ) }\n * </Button>\n * { notices.length > 0 && (\n * <Button onClick={ () => removeNotice( notices[ 0 ].id ) }>\n * { __( 'Remove the notice' ) }\n * </Button>\n * ) }\n * </>\n * );\n *};\n * ```\n *\n * @return {Object} Action object.\n */\nexport function removeNotice( id, context = DEFAULT_CONTEXT ) {\n\treturn {\n\t\ttype: 'REMOVE_NOTICE',\n\t\tid,\n\t\tcontext,\n\t};\n}\n"]}
|
@@ -1,11 +1,6 @@
|
|
1
|
-
/**
|
2
|
-
* External dependencies
|
3
|
-
*/
|
4
|
-
import { reject } from 'lodash';
|
5
1
|
/**
|
6
2
|
* Internal dependencies
|
7
3
|
*/
|
8
|
-
|
9
4
|
import onSubKey from './utils/on-sub-key';
|
10
5
|
/**
|
11
6
|
* Reducer returning the next notices state. The notices state is an object
|
@@ -24,13 +19,19 @@ const notices = onSubKey('context')(function () {
|
|
24
19
|
switch (action.type) {
|
25
20
|
case 'CREATE_NOTICE':
|
26
21
|
// Avoid duplicates on ID.
|
27
|
-
return [...
|
28
|
-
|
22
|
+
return [...state.filter(_ref => {
|
23
|
+
let {
|
24
|
+
id
|
25
|
+
} = _ref;
|
26
|
+
return id !== action.notice.id;
|
29
27
|
}), action.notice];
|
30
28
|
|
31
29
|
case 'REMOVE_NOTICE':
|
32
|
-
return
|
33
|
-
|
30
|
+
return state.filter(_ref2 => {
|
31
|
+
let {
|
32
|
+
id
|
33
|
+
} = _ref2;
|
34
|
+
return id !== action.id;
|
34
35
|
});
|
35
36
|
}
|
36
37
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/notices/src/store/reducer.js"],"names":["
|
1
|
+
{"version":3,"sources":["@wordpress/notices/src/store/reducer.js"],"names":["onSubKey","notices","state","action","type","filter","id","notice"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,oBAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,OAAO,GAAGD,QAAQ,CAAE,SAAF,CAAR,CAAuB,YAA0B;AAAA,MAAxBE,KAAwB,uEAAhB,EAAgB;AAAA,MAAZC,MAAY;;AAChE,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,eAAL;AACC;AACA,aAAO,CACN,GAAGF,KAAK,CAACG,MAAN,CAAc;AAAA,YAAE;AAAEC,UAAAA;AAAF,SAAF;AAAA,eAAcA,EAAE,KAAKH,MAAM,CAACI,MAAP,CAAcD,EAAnC;AAAA,OAAd,CADG,EAENH,MAAM,CAACI,MAFD,CAAP;;AAKD,SAAK,eAAL;AACC,aAAOL,KAAK,CAACG,MAAN,CAAc;AAAA,YAAE;AAAEC,UAAAA;AAAF,SAAF;AAAA,eAAcA,EAAE,KAAKH,MAAM,CAACG,EAA5B;AAAA,OAAd,CAAP;AATF;;AAYA,SAAOJ,KAAP;AACA,CAde,CAAhB;AAgBA,eAAeD,OAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport onSubKey from './utils/on-sub-key';\n\n/**\n * Reducer returning the next notices state. The notices state is an object\n * where each key is a context, its value an array of notice objects.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nconst notices = onSubKey( 'context' )( ( state = [], action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'CREATE_NOTICE':\n\t\t\t// Avoid duplicates on ID.\n\t\t\treturn [\n\t\t\t\t...state.filter( ( { id } ) => id !== action.notice.id ),\n\t\t\t\taction.notice,\n\t\t\t];\n\n\t\tcase 'REMOVE_NOTICE':\n\t\t\treturn state.filter( ( { id } ) => id !== action.id );\n\t}\n\n\treturn state;\n} );\n\nexport default notices;\n"]}
|
@@ -48,6 +48,24 @@ const DEFAULT_NOTICES = [];
|
|
48
48
|
* @param {Object} state Notices state.
|
49
49
|
* @param {?string} context Optional grouping context.
|
50
50
|
*
|
51
|
+
* @example
|
52
|
+
*
|
53
|
+
*```js
|
54
|
+
* import { useSelect } from '@wordpress/data';
|
55
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
56
|
+
*
|
57
|
+
* const ExampleComponent = () => {
|
58
|
+
* const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );
|
59
|
+
* return (
|
60
|
+
* <ul>
|
61
|
+
* { notices.map( ( notice ) => (
|
62
|
+
* <li key={ notice.ID }>{ notice.content }</li>
|
63
|
+
* ) ) }
|
64
|
+
* </ul>
|
65
|
+
* )
|
66
|
+
* };
|
67
|
+
*```
|
68
|
+
*
|
51
69
|
* @return {WPNotice[]} Array of notices.
|
52
70
|
*/
|
53
71
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/notices/src/store/selectors.js"],"names":["DEFAULT_CONTEXT","DEFAULT_NOTICES","getNotices","state","context"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,aAAhC;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,eAAe,GAAG,EAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,CAAqBC,KAArB,EAAwD;AAAA,MAA5BC,OAA4B,uEAAlBJ,eAAkB;AAC9D,SAAOG,KAAK,CAAEC,OAAF,CAAL,IAAoBH,eAA3B;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT } from './constants';\n\n/** @typedef {import('./actions').WPNoticeAction} WPNoticeAction */\n\n/**\n * The default empty set of notices to return when there are no notices\n * assigned for a given notices context. This can occur if the getNotices\n * selector is called without a notice ever having been created for the\n * context. A shared value is used to ensure referential equality between\n * sequential selector calls, since otherwise `[] !== []`.\n *\n * @type {Array}\n */\nconst DEFAULT_NOTICES = [];\n\n/**\n * @typedef {Object} WPNotice Notice object.\n *\n * @property {string} id Unique identifier of notice.\n * @property {string} status Status of notice, one of `success`,\n * `info`, `error`, or `warning`. Defaults\n * to `info`.\n * @property {string} content Notice message.\n * @property {string} spokenMessage Audibly announced message text used by\n * assistive technologies.\n * @property {string} __unstableHTML Notice message as raw HTML. Intended to\n * serve primarily for compatibility of\n * server-rendered notices, and SHOULD NOT\n * be used for notices. It is subject to\n * removal without notice.\n * @property {boolean} isDismissible Whether the notice can be dismissed by\n * user. Defaults to `true`.\n * @property {string} type Type of notice, one of `default`,\n * or `snackbar`. Defaults to `default`.\n * @property {boolean} speak Whether the notice content should be\n * announced to screen readers. Defaults to\n * `true`.\n * @property {WPNoticeAction[]} actions User actions to present with notice.\n *\n */\n\n/**\n * Returns all notices as an array, optionally for a given context. Defaults to\n * the global context.\n *\n * @param {Object} state Notices state.\n * @param {?string} context Optional grouping context.\n *\n * @return {WPNotice[]} Array of notices.\n */\nexport function getNotices( state, context = DEFAULT_CONTEXT ) {\n\treturn state[ context ] || DEFAULT_NOTICES;\n}\n"]}
|
1
|
+
{"version":3,"sources":["@wordpress/notices/src/store/selectors.js"],"names":["DEFAULT_CONTEXT","DEFAULT_NOTICES","getNotices","state","context"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,aAAhC;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,eAAe,GAAG,EAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,CAAqBC,KAArB,EAAwD;AAAA,MAA5BC,OAA4B,uEAAlBJ,eAAkB;AAC9D,SAAOG,KAAK,CAAEC,OAAF,CAAL,IAAoBH,eAA3B;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT } from './constants';\n\n/** @typedef {import('./actions').WPNoticeAction} WPNoticeAction */\n\n/**\n * The default empty set of notices to return when there are no notices\n * assigned for a given notices context. This can occur if the getNotices\n * selector is called without a notice ever having been created for the\n * context. A shared value is used to ensure referential equality between\n * sequential selector calls, since otherwise `[] !== []`.\n *\n * @type {Array}\n */\nconst DEFAULT_NOTICES = [];\n\n/**\n * @typedef {Object} WPNotice Notice object.\n *\n * @property {string} id Unique identifier of notice.\n * @property {string} status Status of notice, one of `success`,\n * `info`, `error`, or `warning`. Defaults\n * to `info`.\n * @property {string} content Notice message.\n * @property {string} spokenMessage Audibly announced message text used by\n * assistive technologies.\n * @property {string} __unstableHTML Notice message as raw HTML. Intended to\n * serve primarily for compatibility of\n * server-rendered notices, and SHOULD NOT\n * be used for notices. It is subject to\n * removal without notice.\n * @property {boolean} isDismissible Whether the notice can be dismissed by\n * user. Defaults to `true`.\n * @property {string} type Type of notice, one of `default`,\n * or `snackbar`. Defaults to `default`.\n * @property {boolean} speak Whether the notice content should be\n * announced to screen readers. Defaults to\n * `true`.\n * @property {WPNoticeAction[]} actions User actions to present with notice.\n *\n */\n\n/**\n * Returns all notices as an array, optionally for a given context. Defaults to\n * the global context.\n *\n * @param {Object} state Notices state.\n * @param {?string} context Optional grouping context.\n *\n * @example\n *\n *```js\n * import { useSelect } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n *\n * const ExampleComponent = () => {\n * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );\n * return (\n * <ul>\n * { notices.map( ( notice ) => (\n * <li key={ notice.ID }>{ notice.content }</li>\n * ) ) }\n * </ul>\n * )\n * };\n *```\n *\n * @return {WPNotice[]} Array of notices.\n */\nexport function getNotices( state, context = DEFAULT_CONTEXT ) {\n\treturn state[ context ] || DEFAULT_NOTICES;\n}\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/notices/src/store/utils/on-sub-key.js"],"names":["onSubKey","actionProperty","reducer","state","action","key","undefined","nextKeyState"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,QAAQ,
|
1
|
+
{"version":3,"sources":["@wordpress/notices/src/store/utils/on-sub-key.js"],"names":["onSubKey","actionProperty","reducer","state","action","key","undefined","nextKeyState"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,QAAQ,GAClBC,cAAF,IACEC,OAAF,IACA,YAA0B;AAAA,MAAxBC,KAAwB,uEAAhB,EAAgB;AAAA,MAAZC,MAAY;AACzB;AACA;AACA,QAAMC,GAAG,GAAGD,MAAM,CAAEH,cAAF,CAAlB;;AACA,MAAKI,GAAG,KAAKC,SAAb,EAAyB;AACxB,WAAOH,KAAP;AACA,GANwB,CAQzB;AACA;;;AACA,QAAMI,YAAY,GAAGL,OAAO,CAAEC,KAAK,CAAEE,GAAF,CAAP,EAAgBD,MAAhB,CAA5B;;AACA,MAAKG,YAAY,KAAKJ,KAAK,CAAEE,GAAF,CAA3B,EAAqC;AACpC,WAAOF,KAAP;AACA;;AAED,SAAO,EACN,GAAGA,KADG;AAEN,KAAEE,GAAF,GAASE;AAFH,GAAP;AAIA,CAtBK;AAwBP,eAAeP,QAAf","sourcesContent":["/**\n * Higher-order reducer creator which creates a combined reducer object, keyed\n * by a property on the action object.\n *\n * @param {string} actionProperty Action property by which to key object.\n *\n * @return {Function} Higher-order reducer.\n */\nexport const onSubKey =\n\t( actionProperty ) =>\n\t( reducer ) =>\n\t( state = {}, action ) => {\n\t\t// Retrieve subkey from action. Do not track if undefined; useful for cases\n\t\t// where reducer is scoped by action shape.\n\t\tconst key = action[ actionProperty ];\n\t\tif ( key === undefined ) {\n\t\t\treturn state;\n\t\t}\n\n\t\t// Avoid updating state if unchanged. Note that this also accounts for a\n\t\t// reducer which returns undefined on a key which is not yet tracked.\n\t\tconst nextKeyState = reducer( state[ key ], action );\n\t\tif ( nextKeyState === state[ key ] ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ key ]: nextKeyState,\n\t\t};\n\t};\n\nexport default onSubKey;\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@wordpress/notices",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.13.0",
|
4
4
|
"description": "State management for notices.",
|
5
5
|
"author": "The WordPress Contributors",
|
6
6
|
"license": "GPL-2.0-or-later",
|
@@ -26,9 +26,8 @@
|
|
26
26
|
"react-native": "src/index",
|
27
27
|
"dependencies": {
|
28
28
|
"@babel/runtime": "^7.16.0",
|
29
|
-
"@wordpress/a11y": "^3.
|
30
|
-
"@wordpress/data": "^6.
|
31
|
-
"lodash": "^4.17.21"
|
29
|
+
"@wordpress/a11y": "^3.13.0",
|
30
|
+
"@wordpress/data": "^6.13.0"
|
32
31
|
},
|
33
32
|
"peerDependencies": {
|
34
33
|
"react": "^17.0.0"
|
@@ -36,5 +35,5 @@
|
|
36
35
|
"publishConfig": {
|
37
36
|
"access": "public"
|
38
37
|
},
|
39
|
-
"gitHead": "
|
38
|
+
"gitHead": "9d9d33bbdf317a4381b8ca1713e43bb50df653b3"
|
40
39
|
}
|
package/src/store/actions.js
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
/**
|
2
|
-
* External dependencies
|
3
|
-
*/
|
4
|
-
import { uniqueId } from 'lodash';
|
5
|
-
|
6
1
|
/**
|
7
2
|
* Internal dependencies
|
8
3
|
*/
|
@@ -19,6 +14,8 @@ import { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';
|
|
19
14
|
*
|
20
15
|
*/
|
21
16
|
|
17
|
+
let uniqueId = 0;
|
18
|
+
|
22
19
|
/**
|
23
20
|
* Returns an action object used in signalling that a notice is to be created.
|
24
21
|
*
|
@@ -40,13 +37,34 @@ import { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';
|
|
40
37
|
* readers.
|
41
38
|
* @param {Array<WPNoticeAction>} [options.actions] User actions to be
|
42
39
|
* presented with notice.
|
43
|
-
* @param {
|
40
|
+
* @param {string} [options.icon] An icon displayed with the notice.
|
41
|
+
* Only used when type is set to `snackbar`.
|
44
42
|
* @param {boolean} [options.explicitDismiss] Whether the notice includes
|
45
|
-
* an
|
43
|
+
* an explicit dismiss button and
|
46
44
|
* can't be dismissed by clicking
|
47
|
-
* the body of the notice.
|
45
|
+
* the body of the notice. Only applies
|
46
|
+
* when type is set to `snackbar`.
|
48
47
|
* @param {Function} [options.onDismiss] Called when the notice is dismissed.
|
49
48
|
*
|
49
|
+
* @example
|
50
|
+
* ```js
|
51
|
+
* import { __ } from '@wordpress/i18n';
|
52
|
+
* import { useDispatch } from '@wordpress/data';
|
53
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
54
|
+
* import { Button } from '@wordpress/components';
|
55
|
+
*
|
56
|
+
* const ExampleComponent = () => {
|
57
|
+
* const { createNotice } = useDispatch( noticesStore );
|
58
|
+
* return (
|
59
|
+
* <Button
|
60
|
+
* onClick={ () => createNotice( 'success', __( 'Notice message' ) ) }
|
61
|
+
* >
|
62
|
+
* { __( 'Generate a success notice!' ) }
|
63
|
+
* </Button>
|
64
|
+
* );
|
65
|
+
* };
|
66
|
+
* ```
|
67
|
+
*
|
50
68
|
* @return {Object} Action object.
|
51
69
|
*/
|
52
70
|
export function createNotice( status = DEFAULT_STATUS, content, options = {} ) {
|
@@ -54,7 +72,7 @@ export function createNotice( status = DEFAULT_STATUS, content, options = {} ) {
|
|
54
72
|
speak = true,
|
55
73
|
isDismissible = true,
|
56
74
|
context = DEFAULT_CONTEXT,
|
57
|
-
id =
|
75
|
+
id = `${ context }${ ++uniqueId }`,
|
58
76
|
actions = [],
|
59
77
|
type = 'default',
|
60
78
|
__unstableHTML,
|
@@ -96,6 +114,30 @@ export function createNotice( status = DEFAULT_STATUS, content, options = {} ) {
|
|
96
114
|
* @param {string} content Notice message.
|
97
115
|
* @param {Object} [options] Optional notice options.
|
98
116
|
*
|
117
|
+
* @example
|
118
|
+
* ```js
|
119
|
+
* import { __ } from '@wordpress/i18n';
|
120
|
+
* import { useDispatch } from '@wordpress/data';
|
121
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
122
|
+
* import { Button } from '@wordpress/components';
|
123
|
+
*
|
124
|
+
* const ExampleComponent = () => {
|
125
|
+
* const { createSuccessNotice } = useDispatch( noticesStore );
|
126
|
+
* return (
|
127
|
+
* <Button
|
128
|
+
* onClick={ () =>
|
129
|
+
* createSuccessNotice( __( 'Success!' ), {
|
130
|
+
* type: 'snackbar',
|
131
|
+
* icon: '🔥',
|
132
|
+
* } )
|
133
|
+
* }
|
134
|
+
* >
|
135
|
+
* { __( 'Generate a snackbar success notice!' ) }
|
136
|
+
* </Button>
|
137
|
+
* );
|
138
|
+
* };
|
139
|
+
* ```
|
140
|
+
*
|
99
141
|
* @return {Object} Action object.
|
100
142
|
*/
|
101
143
|
export function createSuccessNotice( content, options ) {
|
@@ -111,6 +153,29 @@ export function createSuccessNotice( content, options ) {
|
|
111
153
|
* @param {string} content Notice message.
|
112
154
|
* @param {Object} [options] Optional notice options.
|
113
155
|
*
|
156
|
+
* @example
|
157
|
+
* ```js
|
158
|
+
* import { __ } from '@wordpress/i18n';
|
159
|
+
* import { useDispatch } from '@wordpress/data';
|
160
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
161
|
+
* import { Button } from '@wordpress/components';
|
162
|
+
*
|
163
|
+
* const ExampleComponent = () => {
|
164
|
+
* const { createInfoNotice } = useDispatch( noticesStore );
|
165
|
+
* return (
|
166
|
+
* <Button
|
167
|
+
* onClick={ () =>
|
168
|
+
* createInfoNotice( __( 'Something happened!' ), {
|
169
|
+
* isDismissible: false,
|
170
|
+
* } )
|
171
|
+
* }
|
172
|
+
* >
|
173
|
+
* { __( 'Generate a notice that cannot be dismissed.' ) }
|
174
|
+
* </Button>
|
175
|
+
* );
|
176
|
+
* };
|
177
|
+
*```
|
178
|
+
*
|
114
179
|
* @return {Object} Action object.
|
115
180
|
*/
|
116
181
|
export function createInfoNotice( content, options ) {
|
@@ -126,6 +191,32 @@ export function createInfoNotice( content, options ) {
|
|
126
191
|
* @param {string} content Notice message.
|
127
192
|
* @param {Object} [options] Optional notice options.
|
128
193
|
*
|
194
|
+
* @example
|
195
|
+
* ```js
|
196
|
+
* import { __ } from '@wordpress/i18n';
|
197
|
+
* import { useDispatch } from '@wordpress/data';
|
198
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
199
|
+
* import { Button } from '@wordpress/components';
|
200
|
+
*
|
201
|
+
* const ExampleComponent = () => {
|
202
|
+
* const { createErrorNotice } = useDispatch( noticesStore );
|
203
|
+
* return (
|
204
|
+
* <Button
|
205
|
+
* onClick={ () =>
|
206
|
+
* createErrorNotice( __( 'An error occurred!' ), {
|
207
|
+
* type: 'snackbar',
|
208
|
+
* explicitDismiss: true,
|
209
|
+
* } )
|
210
|
+
* }
|
211
|
+
* >
|
212
|
+
* { __(
|
213
|
+
* 'Generate an snackbar error notice with explicit dismiss button.'
|
214
|
+
* ) }
|
215
|
+
* </Button>
|
216
|
+
* );
|
217
|
+
* };
|
218
|
+
* ```
|
219
|
+
*
|
129
220
|
* @return {Object} Action object.
|
130
221
|
*/
|
131
222
|
export function createErrorNotice( content, options ) {
|
@@ -141,6 +232,33 @@ export function createErrorNotice( content, options ) {
|
|
141
232
|
* @param {string} content Notice message.
|
142
233
|
* @param {Object} [options] Optional notice options.
|
143
234
|
*
|
235
|
+
* @example
|
236
|
+
* ```js
|
237
|
+
* import { __ } from '@wordpress/i18n';
|
238
|
+
* import { useDispatch } from '@wordpress/data';
|
239
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
240
|
+
* import { Button } from '@wordpress/components';
|
241
|
+
*
|
242
|
+
* const ExampleComponent = () => {
|
243
|
+
* const { createWarningNotice, createInfoNotice } = useDispatch( noticesStore );
|
244
|
+
* return (
|
245
|
+
* <Button
|
246
|
+
* onClick={ () =>
|
247
|
+
* createWarningNotice( __( 'Warning!' ), {
|
248
|
+
* onDismiss: () => {
|
249
|
+
* createInfoNotice(
|
250
|
+
* __( 'The warning has been dismissed!' )
|
251
|
+
* );
|
252
|
+
* },
|
253
|
+
* } )
|
254
|
+
* }
|
255
|
+
* >
|
256
|
+
* { __( 'Generates a warning notice with onDismiss callback' ) }
|
257
|
+
* </Button>
|
258
|
+
* );
|
259
|
+
* };
|
260
|
+
* ```
|
261
|
+
*
|
144
262
|
* @return {Object} Action object.
|
145
263
|
*/
|
146
264
|
export function createWarningNotice( content, options ) {
|
@@ -154,6 +272,38 @@ export function createWarningNotice( content, options ) {
|
|
154
272
|
* @param {string} [context='global'] Optional context (grouping) in which the notice is
|
155
273
|
* intended to appear. Defaults to default context.
|
156
274
|
*
|
275
|
+
* @example
|
276
|
+
* ```js
|
277
|
+
* import { __ } from '@wordpress/i18n';
|
278
|
+
* import { useDispatch } from '@wordpress/data';
|
279
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
280
|
+
* import { Button } from '@wordpress/components';
|
281
|
+
*
|
282
|
+
* const ExampleComponent = () => {
|
283
|
+
* const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );
|
284
|
+
* const { createWarningNotice, removeNotice } = useDispatch( noticesStore );
|
285
|
+
*
|
286
|
+
* return (
|
287
|
+
* <>
|
288
|
+
* <Button
|
289
|
+
* onClick={ () =>
|
290
|
+
* createWarningNotice( __( 'Warning!' ), {
|
291
|
+
* isDismissible: false,
|
292
|
+
* } )
|
293
|
+
* }
|
294
|
+
* >
|
295
|
+
* { __( 'Generate a notice' ) }
|
296
|
+
* </Button>
|
297
|
+
* { notices.length > 0 && (
|
298
|
+
* <Button onClick={ () => removeNotice( notices[ 0 ].id ) }>
|
299
|
+
* { __( 'Remove the notice' ) }
|
300
|
+
* </Button>
|
301
|
+
* ) }
|
302
|
+
* </>
|
303
|
+
* );
|
304
|
+
*};
|
305
|
+
* ```
|
306
|
+
*
|
157
307
|
* @return {Object} Action object.
|
158
308
|
*/
|
159
309
|
export function removeNotice( id, context = DEFAULT_CONTEXT ) {
|
package/src/store/reducer.js
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
/**
|
2
|
-
* External dependencies
|
3
|
-
*/
|
4
|
-
import { reject } from 'lodash';
|
5
|
-
|
6
1
|
/**
|
7
2
|
* Internal dependencies
|
8
3
|
*/
|
@@ -22,12 +17,12 @@ const notices = onSubKey( 'context' )( ( state = [], action ) => {
|
|
22
17
|
case 'CREATE_NOTICE':
|
23
18
|
// Avoid duplicates on ID.
|
24
19
|
return [
|
25
|
-
...
|
20
|
+
...state.filter( ( { id } ) => id !== action.notice.id ),
|
26
21
|
action.notice,
|
27
22
|
];
|
28
23
|
|
29
24
|
case 'REMOVE_NOTICE':
|
30
|
-
return
|
25
|
+
return state.filter( ( { id } ) => id !== action.id );
|
31
26
|
}
|
32
27
|
|
33
28
|
return state;
|
package/src/store/selectors.js
CHANGED
@@ -49,6 +49,24 @@ const DEFAULT_NOTICES = [];
|
|
49
49
|
* @param {Object} state Notices state.
|
50
50
|
* @param {?string} context Optional grouping context.
|
51
51
|
*
|
52
|
+
* @example
|
53
|
+
*
|
54
|
+
*```js
|
55
|
+
* import { useSelect } from '@wordpress/data';
|
56
|
+
* import { store as noticesStore } from '@wordpress/notices';
|
57
|
+
*
|
58
|
+
* const ExampleComponent = () => {
|
59
|
+
* const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );
|
60
|
+
* return (
|
61
|
+
* <ul>
|
62
|
+
* { notices.map( ( notice ) => (
|
63
|
+
* <li key={ notice.ID }>{ notice.content }</li>
|
64
|
+
* ) ) }
|
65
|
+
* </ul>
|
66
|
+
* )
|
67
|
+
* };
|
68
|
+
*```
|
69
|
+
*
|
52
70
|
* @return {WPNotice[]} Array of notices.
|
53
71
|
*/
|
54
72
|
export function getNotices( state, context = DEFAULT_CONTEXT ) {
|
@@ -6,28 +6,28 @@
|
|
6
6
|
*
|
7
7
|
* @return {Function} Higher-order reducer.
|
8
8
|
*/
|
9
|
-
export const onSubKey =
|
10
|
-
|
11
|
-
|
12
|
-
) => {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
export const onSubKey =
|
10
|
+
( actionProperty ) =>
|
11
|
+
( reducer ) =>
|
12
|
+
( state = {}, action ) => {
|
13
|
+
// Retrieve subkey from action. Do not track if undefined; useful for cases
|
14
|
+
// where reducer is scoped by action shape.
|
15
|
+
const key = action[ actionProperty ];
|
16
|
+
if ( key === undefined ) {
|
17
|
+
return state;
|
18
|
+
}
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
// Avoid updating state if unchanged. Note that this also accounts for a
|
21
|
+
// reducer which returns undefined on a key which is not yet tracked.
|
22
|
+
const nextKeyState = reducer( state[ key ], action );
|
23
|
+
if ( nextKeyState === state[ key ] ) {
|
24
|
+
return state;
|
25
|
+
}
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
return {
|
28
|
+
...state,
|
29
|
+
[ key ]: nextKeyState,
|
30
|
+
};
|
30
31
|
};
|
31
|
-
};
|
32
32
|
|
33
33
|
export default onSubKey;
|