[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/ -> notices.js.map (source)

   1  {
   2    "version": 3,
   3    "sources": ["package-external:@wordpress/data", "../../../packages/notices/src/store/index.js", "../../../packages/notices/src/store/utils/on-sub-key.js", "../../../packages/notices/src/store/reducer.js", "../../../packages/notices/src/store/constants.js", "../../../packages/notices/src/store/actions.js", "../../../packages/notices/src/store/selectors.js"],
   4    "sourcesContent": ["module.exports = window.wp.data;", "/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\n\n/**\n * Store definition for the notices namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( 'core/notices', {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\n", "/**\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", "/**\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\n\t\tcase 'REMOVE_NOTICES':\n\t\t\treturn state.filter( ( { id } ) => ! action.ids.includes( id ) );\n\n\t\tcase 'REMOVE_ALL_NOTICES':\n\t\t\treturn state.filter( ( { type } ) => type !== action.noticeType );\n\t}\n\n\treturn state;\n} );\n\nexport default notices;\n", "/**\n * Default context to use for notice grouping when not otherwise specified. Its\n * specific value doesn't hold much meaning, but it must be reasonably unique\n * and, more importantly, referenced consistently in the store implementation.\n *\n * @type {string}\n */\nexport const DEFAULT_CONTEXT = 'global';\n\n/**\n * Default notice status.\n *\n * @type {string}\n */\nexport const DEFAULT_STATUS = 'info';\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\nlet uniqueId = 0;\n\n/**\n * Returns an action object used in signalling that a notice is to be created.\n *\n * @param {string|undefined}      status                       Notice status (\"info\" if undefined is passed).\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 React Element 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: '\uD83D\uDD25',\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 a 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\n/**\n * Removes all notices from a given context. Defaults to the default context.\n *\n * @param {string} noticeType The context to remove all notices from.\n * @param {string} context    The context to remove all notices from.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch, useSelect } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * export const ExampleComponent = () => {\n * \tconst notices = useSelect( ( select ) =>\n * \t\tselect( noticesStore ).getNotices()\n * \t);\n * \tconst { removeAllNotices } = useDispatch( noticesStore );\n * \treturn (\n * \t\t<>\n * \t\t\t<ul>\n * \t\t\t\t{ notices.map( ( notice ) => (\n * \t\t\t\t\t<li key={ notice.id }>{ notice.content }</li>\n * \t\t\t\t) ) }\n * \t\t\t</ul>\n * \t\t\t<Button\n * \t\t\t\tonClick={ () =>\n * \t\t\t\t\tremoveAllNotices()\n * \t\t\t\t}\n * \t\t\t>\n * \t\t\t\t{ __( 'Clear all notices', 'woo-gutenberg-products-block' ) }\n * \t\t\t</Button>\n * \t\t\t<Button\n * \t\t\t\tonClick={ () =>\n * \t\t\t\t\tremoveAllNotices( 'snackbar' )\n * \t\t\t\t}\n * \t\t\t>\n * \t\t\t\t{ __( 'Clear all snackbar notices', 'woo-gutenberg-products-block' ) }\n * \t\t\t</Button>\n * \t\t</>\n * \t);\n * };\n * ```\n *\n * @return {Object} \t   Action object.\n */\nexport function removeAllNotices(\n\tnoticeType = 'default',\n\tcontext = DEFAULT_CONTEXT\n) {\n\treturn {\n\t\ttype: 'REMOVE_ALL_NOTICES',\n\t\tnoticeType,\n\t\tcontext,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that several notices are to be removed.\n *\n * @param {string[]} ids                List of unique notice identifiers.\n * @param {string}   [context='global'] Optional context (grouping) in which the notices are\n *                                      intended to appear. Defaults to default context.\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch, useSelect } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * \tconst notices = useSelect( ( select ) =>\n * \t\tselect( noticesStore ).getNotices()\n * \t);\n * \tconst { removeNotices } = useDispatch( noticesStore );\n * \treturn (\n * \t\t<>\n * \t\t\t<ul>\n * \t\t\t\t{ notices.map( ( notice ) => (\n * \t\t\t\t\t<li key={ notice.id }>{ notice.content }</li>\n * \t\t\t\t) ) }\n * \t\t\t</ul>\n * \t\t\t<Button\n * \t\t\t\tonClick={ () =>\n * \t\t\t\t\tremoveNotices( notices.map( ( { id } ) => id ) )\n * \t\t\t\t}\n * \t\t\t>\n * \t\t\t\t{ __( 'Clear all notices' ) }\n * \t\t\t</Button>\n * \t\t</>\n * \t);\n * };\n * ```\n * @return {Object} Action object.\n */\nexport function removeNotices( ids, context = DEFAULT_CONTEXT ) {\n\treturn {\n\t\ttype: 'REMOVE_NOTICES',\n\t\tids,\n\t\tcontext,\n\t};\n}\n", "/**\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 * 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"],
   5    "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,aAAO,UAAU,OAAO,GAAG;AAAA;AAAA;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