@wordpress/notices 3.9.0 → 3.12.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 +3 -8
- 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/utils/on-sub-key.js.map +1 -1
- package/build-module/store/actions.js +2 -6
- 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/utils/on-sub-key.js.map +1 -1
- package/package.json +4 -5
- package/src/store/actions.js +3 -6
- package/src/store/reducer.js +2 -7
- 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
|
*
|
@@ -63,6 +57,7 @@ var _constants = require("./constants");
|
|
63
57
|
*
|
64
58
|
* @return {Object} Action object.
|
65
59
|
*/
|
60
|
+
|
66
61
|
function createNotice() {
|
67
62
|
let status = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.DEFAULT_STATUS;
|
68
63
|
let content = arguments.length > 1 ? arguments[1] : undefined;
|
@@ -71,7 +66,7 @@ function createNotice() {
|
|
71
66
|
speak = true,
|
72
67
|
isDismissible = true,
|
73
68
|
context = _constants.DEFAULT_CONTEXT,
|
74
|
-
id =
|
69
|
+
id = `${context}${++uniqueId}`,
|
75
70
|
actions = [],
|
76
71
|
type = 'default',
|
77
72
|
__unstableHTML,
|
@@ -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;;
|
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;;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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kB,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 * 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 {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 = `${ 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 * @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"]}
|
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"]}
|
@@ -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
|
*
|
@@ -57,7 +53,7 @@ export function createNotice() {
|
|
57
53
|
speak = true,
|
58
54
|
isDismissible = true,
|
59
55
|
context = DEFAULT_CONTEXT,
|
60
|
-
id = uniqueId
|
56
|
+
id = `${context}${++uniqueId}`,
|
61
57
|
actions = [],
|
62
58
|
type = 'default',
|
63
59
|
__unstableHTML,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/notices/src/store/actions.js"],"names":["
|
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;A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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,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 {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 = `${ 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 * @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,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"]}
|
@@ -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.12.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.12.0",
|
30
|
+
"@wordpress/data": "^6.12.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": "a80eeb62ec7cb1418b9915c277e084a29d6665e3"
|
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
|
*
|
@@ -54,7 +51,7 @@ export function createNotice( status = DEFAULT_STATUS, content, options = {} ) {
|
|
54
51
|
speak = true,
|
55
52
|
isDismissible = true,
|
56
53
|
context = DEFAULT_CONTEXT,
|
57
|
-
id =
|
54
|
+
id = `${ context }${ ++uniqueId }`,
|
58
55
|
actions = [],
|
59
56
|
type = 'default',
|
60
57
|
__unstableHTML,
|
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;
|
@@ -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;
|