{
  "version": 3,
  "sources": ["../../src/store/selectors.js"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\n\n/**\n * Returns all the available format types.\n *\n * @param {Object} state Data state.\n *\n * @example\n * ```js\n * import { __, sprintf } from '@wordpress/i18n';\n * import { store as richTextStore } from '@wordpress/rich-text';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n *    const { getFormatTypes } = useSelect(\n *        ( select ) => select( richTextStore ),\n *        []\n *    );\n *\n *    const availableFormats = getFormatTypes();\n *\n *    return availableFormats ? (\n *        <ul>\n *            { availableFormats?.map( ( format ) => (\n *                <li>{ format.name }</li>\n *           ) ) }\n *        </ul>\n *    ) : (\n *        __( 'No Formats available' )\n *    );\n * };\n * ```\n *\n * @return {Array} Format types.\n */\nexport const getFormatTypes = createSelector(\n\t( state ) => Object.values( state.formatTypes ),\n\t( state ) => [ state.formatTypes ]\n);\n\n/**\n * Returns a format type by name.\n *\n * @param {Object} state Data state.\n * @param {string} name  Format type name.\n *\n * @example\n * ```js\n * import { __, sprintf } from '@wordpress/i18n';\n * import { store as richTextStore } from '@wordpress/rich-text';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n *    const { getFormatType } = useSelect(\n *        ( select ) => select( richTextStore ),\n *        []\n *    );\n *\n *    const boldFormat = getFormatType( 'core/bold' );\n *\n *    return boldFormat ? (\n *        <ul>\n *            { Object.entries( boldFormat )?.map( ( [ key, value ] ) => (\n *                <li>\n *                    { key } : { value }\n *                </li>\n *           ) ) }\n *       </ul>\n *    ) : (\n *        __( 'Not Found' )\n *    ;\n * };\n * ```\n *\n * @return {?Object} Format type.\n */\nexport function getFormatType( state, name ) {\n\treturn state.formatTypes[ name ];\n}\n\n/**\n * Gets the format type, if any, that can handle a bare element (without a\n * data-format-type attribute), given the tag name of this element.\n *\n * @param {Object} state              Data state.\n * @param {string} bareElementTagName The tag name of the element to find a\n *                                    format type for.\n *\n * @example\n * ```js\n * import { __, sprintf } from '@wordpress/i18n';\n * import { store as richTextStore } from '@wordpress/rich-text';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n *    const { getFormatTypeForBareElement } = useSelect(\n *        ( select ) => select( richTextStore ),\n *        []\n *    );\n *\n *    const format = getFormatTypeForBareElement( 'strong' );\n *\n *    return format && <p>{ sprintf( __( 'Format name: %s' ), format.name ) }</p>;\n * }\n * ```\n *\n * @return {?Object} Format type.\n */\nexport function getFormatTypeForBareElement( state, bareElementTagName ) {\n\tconst formatTypes = getFormatTypes( state );\n\treturn (\n\t\tformatTypes.find( ( { className, tagName } ) => {\n\t\t\treturn className === null && bareElementTagName === tagName;\n\t\t} ) ||\n\t\tformatTypes.find( ( { className, tagName } ) => {\n\t\t\treturn className === null && '*' === tagName;\n\t\t} )\n\t);\n}\n\n/**\n * Gets the format type, if any, that can handle an element, given its classes.\n *\n * @param {Object} state            Data state.\n * @param {string} elementClassName The classes of the element to find a format\n *                                  type for.\n *\n * @example\n * ```js\n * import { __, sprintf } from '@wordpress/i18n';\n * import { store as richTextStore } from '@wordpress/rich-text';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n *    const { getFormatTypeForClassName } = useSelect(\n *        ( select ) => select( richTextStore ),\n *        []\n *    );\n *\n *    const format = getFormatTypeForClassName( 'has-inline-color' );\n *\n *    return format && <p>{ sprintf( __( 'Format name: %s' ), format.name ) }</p>;\n * };\n * ```\n *\n * @return {?Object} Format type.\n */\nexport function getFormatTypeForClassName( state, elementClassName ) {\n\treturn getFormatTypes( state ).find( ( { className } ) => {\n\t\tif ( className === null ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn ` ${ elementClassName } `.indexOf( ` ${ className } ` ) >= 0;\n\t} );\n}\n"],
  "mappings": ";AAGA,SAAS,sBAAsB;AAmCxB,IAAM,iBAAiB;AAAA,EAC7B,CAAE,UAAW,OAAO,OAAQ,MAAM,WAAY;AAAA,EAC9C,CAAE,UAAW,CAAE,MAAM,WAAY;AAClC;AAsCO,SAAS,cAAe,OAAO,MAAO;AAC5C,SAAO,MAAM,YAAa,IAAK;AAChC;AA8BO,SAAS,4BAA6B,OAAO,oBAAqB;AACxE,QAAM,cAAc,eAAgB,KAAM;AAC1C,SACC,YAAY,KAAM,CAAE,EAAE,WAAW,QAAQ,MAAO;AAC/C,WAAO,cAAc,QAAQ,uBAAuB;AAAA,EACrD,CAAE,KACF,YAAY,KAAM,CAAE,EAAE,WAAW,QAAQ,MAAO;AAC/C,WAAO,cAAc,QAAQ,QAAQ;AAAA,EACtC,CAAE;AAEJ;AA6BO,SAAS,0BAA2B,OAAO,kBAAmB;AACpE,SAAO,eAAgB,KAAM,EAAE,KAAM,CAAE,EAAE,UAAU,MAAO;AACzD,QAAK,cAAc,MAAO;AACzB,aAAO;AAAA,IACR;AAEA,WAAO,IAAK,gBAAiB,IAAI,QAAS,IAAK,SAAU,GAAI,KAAK;AAAA,EACnE,CAAE;AACH;",
  "names": []
}
