UNPKG

@wordpress/block-library

Version:
1 lines • 2.24 kB
{"version":3,"file":"deprecated-text-align-attributes.cjs","names":["useDispatch","blockEditorStore","useEvent","useRef"],"sources":["../../src/utils/deprecated-text-align-attributes.js"],"sourcesContent":["import { useEvent } from '@wordpress/compose';\nimport { useEffect, useRef } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport { useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * If a plugin is still using the old textAlign attribute, we need to migrate its value\n * to the new style.typography.textAlign attribute.\n *\n * @param {Object} props Block props.\n */\nexport default function useDeprecatedTextAlign( props ) {\n\tconst { name, attributes, setAttributes } = props;\n\tconst { textAlign } = attributes;\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst updateStyleWithAlign = useEvent( () => {\n\t\tdeprecated( `textAlign attribute in ${ name }`, {\n\t\t\talternative: 'style.typography.textAlign',\n\t\t\tsince: '7.0',\n\t\t} );\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tsetAttributes( ( currentAttr ) => ( {\n\t\t\tstyle: {\n\t\t\t\t...currentAttr.style,\n\t\t\t\ttypography: {\n\t\t\t\t\t...currentAttr.style?.typography,\n\t\t\t\t\ttextAlign,\n\t\t\t\t},\n\t\t\t},\n\t\t} ) );\n\t} );\n\tconst lastUpdatedAlignRef = useRef();\n\tuseEffect( () => {\n\t\tif ( textAlign === lastUpdatedAlignRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tlastUpdatedAlignRef.current = textAlign;\n\t\tupdateStyleWithAlign();\n\t}, [ textAlign, updateStyleWithAlign ] );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,SAAwB,uBAAwB,OAAQ;CACvD,MAAM,EAAE,MAAM,YAAY,kBAAkB;CAC5C,MAAM,EAAE,cAAc;CACtB,MAAM,EAAE,6CAAA,GACPA,gBAAAA,YAAAA,CAAaC,wBAAAA,KAAiB;CAC/B,MAAM,wBAAA,GAAuBC,mBAAAA,SAAAA,OAAgB;EAC5C,CAAA,GAAA,sBAAA,QAAA,CAAY,0BAA2B,QAAS;GAC/C,aAAa;GACb,OAAO;EACR,CAAE;EACF,wCAAwC;EACxC,eAAiB,iBAAmB,EACnC,OAAO;GACN,GAAG,YAAY;GACf,YAAY;IACX,GAAG,YAAY,OAAO;IACtB;GACD;EACD,EACD,EAAI;CACL,CAAE;CACF,MAAM,uBAAA,GAAsBC,mBAAAA,OAAAA,CAAO;CACnC,CAAA,GAAA,mBAAA,UAAA,OAAiB;EAChB,IAAK,cAAc,oBAAoB,SACtC;EAED,oBAAoB,UAAU;EAC9B,qBAAqB;CACtB,GAAG,CAAE,WAAW,oBAAqB,CAAE;AACxC"}