{"version":3,"file":"actions.cjs","names":["normalizeComplementaryAreaScope","normalizeComplementaryAreaName","preferencesStore"],"sources":["../../src/store/actions.ts"],"sourcesContent":["import type { ThunkArgs } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport {\n\tnormalizeComplementaryAreaScope,\n\tnormalizeComplementaryAreaName,\n} from './deprecated';\nimport type {\n\tCloseModalAction,\n\tOpenModalAction,\n\tSetDefaultComplementaryAreaAction,\n} from './types';\n\n/**\n * Set a default complementary area.\n *\n * @param scope Complementary area scope.\n * @param area  Area identifier.\n *\n * @return Action object.\n */\nexport const setDefaultComplementaryArea = (\n\tscope: string,\n\tarea: string\n): SetDefaultComplementaryAreaAction => {\n\tscope = normalizeComplementaryAreaScope( scope );\n\tarea = normalizeComplementaryAreaName( scope, area );\n\treturn {\n\t\ttype: 'SET_DEFAULT_COMPLEMENTARY_AREA',\n\t\tscope,\n\t\tarea,\n\t};\n};\n\n/**\n * Enable the complementary area.\n *\n * @param scope Complementary area scope.\n * @param area  Area identifier.\n */\nexport const enableComplementaryArea =\n\t( scope: string, area: string ) =>\n\t( { registry, dispatch }: ThunkArgs ) => {\n\t\t// Return early if there's no area.\n\t\tif ( ! area ) {\n\t\t\treturn;\n\t\t}\n\t\tscope = normalizeComplementaryAreaScope( scope );\n\t\tarea = normalizeComplementaryAreaName( scope, area );\n\n\t\tconst isComplementaryAreaVisible = registry\n\t\t\t.select( preferencesStore )\n\t\t\t.get( scope, 'isComplementaryAreaVisible' );\n\n\t\tif ( ! isComplementaryAreaVisible ) {\n\t\t\tregistry\n\t\t\t\t.dispatch( preferencesStore )\n\t\t\t\t.set( scope, 'isComplementaryAreaVisible', true );\n\t\t}\n\n\t\tdispatch( {\n\t\t\ttype: 'ENABLE_COMPLEMENTARY_AREA',\n\t\t\tscope,\n\t\t\tarea,\n\t\t} );\n\t};\n\n/**\n * Disable the complementary area.\n *\n * @param scope Complementary area scope.\n */\nexport const disableComplementaryArea =\n\t( scope: string ) =>\n\t( { registry }: ThunkArgs ) => {\n\t\tscope = normalizeComplementaryAreaScope( scope );\n\t\tconst isComplementaryAreaVisible = registry\n\t\t\t.select( preferencesStore )\n\t\t\t.get( scope, 'isComplementaryAreaVisible' );\n\n\t\tif ( isComplementaryAreaVisible ) {\n\t\t\tregistry\n\t\t\t\t.dispatch( preferencesStore )\n\t\t\t\t.set( scope, 'isComplementaryAreaVisible', false );\n\t\t}\n\t};\n\n/**\n * Pins an item.\n *\n * @param scope Item scope.\n * @param item  Item identifier.\n *\n * @return Action object.\n */\nexport const pinItem =\n\t( scope: string, item: string ) =>\n\t( { registry }: ThunkArgs ) => {\n\t\t// Return early if there's no item.\n\t\tif ( ! item ) {\n\t\t\treturn;\n\t\t}\n\n\t\tscope = normalizeComplementaryAreaScope( scope );\n\t\titem = normalizeComplementaryAreaName( scope, item );\n\t\tconst pinnedItems = registry\n\t\t\t.select( preferencesStore )\n\t\t\t.get( scope, 'pinnedItems' );\n\n\t\t// The item is already pinned, there's nothing to do.\n\t\tif ( pinnedItems?.[ item ] === true ) {\n\t\t\treturn;\n\t\t}\n\n\t\tregistry.dispatch( preferencesStore ).set( scope, 'pinnedItems', {\n\t\t\t...pinnedItems,\n\t\t\t[ item ]: true,\n\t\t} );\n\t};\n\n/**\n * Unpins an item.\n *\n * @param scope Item scope.\n * @param item  Item identifier.\n */\nexport const unpinItem =\n\t( scope: string, item: string ) =>\n\t( { registry }: ThunkArgs ) => {\n\t\t// Return early if there's no item.\n\t\tif ( ! item ) {\n\t\t\treturn;\n\t\t}\n\n\t\tscope = normalizeComplementaryAreaScope( scope );\n\t\titem = normalizeComplementaryAreaName( scope, item );\n\t\tconst pinnedItems = registry\n\t\t\t.select( preferencesStore )\n\t\t\t.get( scope, 'pinnedItems' );\n\n\t\tregistry.dispatch( preferencesStore ).set( scope, 'pinnedItems', {\n\t\t\t...pinnedItems,\n\t\t\t[ item ]: false,\n\t\t} );\n\t};\n\n/**\n * Returns an action object used in signalling that a feature should be toggled.\n *\n * @param scope       The feature scope (e.g. core/edit-post).\n * @param featureName The feature name.\n */\nexport function toggleFeature( scope: string, featureName: string ) {\n\treturn function ( { registry }: ThunkArgs ) {\n\t\tdeprecated( `dispatch( 'core/interface' ).toggleFeature`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `dispatch( 'core/preferences' ).toggle`,\n\t\t} );\n\n\t\tregistry.dispatch( preferencesStore ).toggle( scope, featureName );\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a feature should be set to\n * a true or false value\n *\n * @param scope       The feature scope (e.g. core/edit-post).\n * @param featureName The feature name.\n * @param value       The value to set.\n *\n * @return Action object.\n */\nexport function setFeatureValue(\n\tscope: string,\n\tfeatureName: string,\n\tvalue: boolean\n) {\n\treturn function ( { registry }: ThunkArgs ) {\n\t\tdeprecated( `dispatch( 'core/interface' ).setFeatureValue`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `dispatch( 'core/preferences' ).set`,\n\t\t} );\n\n\t\tregistry\n\t\t\t.dispatch( preferencesStore )\n\t\t\t.set( scope, featureName, !! value );\n\t};\n}\n\n/**\n * Returns an action object used in signalling that defaults should be set for features.\n *\n * @param scope    The feature scope (e.g. core/edit-post).\n * @param defaults A key/value map of feature names to values.\n *\n * @return Action object.\n */\nexport function setFeatureDefaults(\n\tscope: string,\n\tdefaults: Record< string, boolean >\n) {\n\treturn function ( { registry }: ThunkArgs ) {\n\t\tdeprecated( `dispatch( 'core/interface' ).setFeatureDefaults`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `dispatch( 'core/preferences' ).setDefaults`,\n\t\t} );\n\n\t\tregistry.dispatch( preferencesStore ).setDefaults( scope, defaults );\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the user opened a modal.\n *\n * @param name A string that uniquely identifies the modal.\n *\n * @return Action object.\n */\nexport function openModal( name: string ): OpenModalAction {\n\treturn {\n\t\ttype: 'OPEN_MODAL',\n\t\tname,\n\t};\n}\n\n/**\n * Returns an action object signalling that the user closed a modal.\n *\n * @return Action object.\n */\nexport function closeModal(): CloseModalAction {\n\treturn {\n\t\ttype: 'CLOSE_MODAL',\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,+BACZ,OACA,SACuC;CACvC,SAAA,GAAQA,gBAAAA,gCAAAA,CAAiC,KAAM;CAC/C,QAAA,GAAOC,gBAAAA,+BAAAA,CAAgC,OAAO,IAAK;CACnD,OAAO;EACN,MAAM;EACN;EACA;CACD;AACD;;;;;;;AAQA,MAAa,2BACV,OAAe,UACf,EAAE,UAAU,eAA2B;CAExC,IAAK,CAAE,MACN;CAED,SAAA,GAAQD,gBAAAA,gCAAAA,CAAiC,KAAM;CAC/C,QAAA,GAAOC,gBAAAA,+BAAAA,CAAgC,OAAO,IAAK;CAMnD,IAAK,CAJ8B,SACjC,OAAQC,uBAAAA,KAAiB,CAAC,CAC1B,IAAK,OAAO,4BAEkB,GAC/B,SACE,SAAUA,uBAAAA,KAAiB,CAAC,CAC5B,IAAK,OAAO,8BAA8B,IAAK;CAGlD,SAAU;EACT,MAAM;EACN;EACA;CACD,CAAE;AACH;;;;;;AAOD,MAAa,4BACV,WACA,EAAE,eAA2B;CAC9B,SAAA,GAAQF,gBAAAA,gCAAAA,CAAiC,KAAM;CAK/C,IAJmC,SACjC,OAAQE,uBAAAA,KAAiB,CAAC,CAC1B,IAAK,OAAO,4BAEgB,GAC7B,SACE,SAAUA,uBAAAA,KAAiB,CAAC,CAC5B,IAAK,OAAO,8BAA8B,KAAM;AAEpD;;;;;;;;;AAUD,MAAa,WACV,OAAe,UACf,EAAE,eAA2B;CAE9B,IAAK,CAAE,MACN;CAGD,SAAA,GAAQF,gBAAAA,gCAAAA,CAAiC,KAAM;CAC/C,QAAA,GAAOC,gBAAAA,+BAAAA,CAAgC,OAAO,IAAK;CACnD,MAAM,cAAc,SAClB,OAAQC,uBAAAA,KAAiB,CAAC,CAC1B,I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