UNPKG

@wordpress/block-library

Version:
8 lines (7 loc) 2.34 kB
{ "version": 3, "sources": ["../../src/utils/deprecated-text-align-attributes.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { 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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAyB;AACzB,qBAAkC;AAClC,wBAAuB;AACvB,kBAA4B;AAC5B,0BAA0C;AAQ3B,SAAR,uBAAyC,OAAQ;AACvD,QAAM,EAAE,MAAM,YAAY,cAAc,IAAI;AAC5C,QAAM,EAAE,UAAU,IAAI;AACtB,QAAM,EAAE,wCAAwC,QAC/C,yBAAa,oBAAAA,KAAiB;AAC/B,QAAM,2BAAuB,yBAAU,MAAM;AAC5C,0BAAAC,SAAY,0BAA2B,IAAK,IAAI;AAAA,MAC/C,aAAa;AAAA,MACb,OAAO;AAAA,IACR,CAAE;AACF,4CAAwC;AACxC,kBAAe,CAAE,iBAAmB;AAAA,MACnC,OAAO;AAAA,QACN,GAAG,YAAY;AAAA,QACf,YAAY;AAAA,UACX,GAAG,YAAY,OAAO;AAAA,UACtB;AAAA,QACD;AAAA,MACD;AAAA,IACD,EAAI;AAAA,EACL,CAAE;AACF,QAAM,0BAAsB,uBAAO;AACnC,gCAAW,MAAM;AAChB,QAAK,cAAc,oBAAoB,SAAU;AAChD;AAAA,IACD;AACA,wBAAoB,UAAU;AAC9B,yBAAqB;AAAA,EACtB,GAAG,CAAE,WAAW,oBAAqB,CAAE;AACxC;", "names": ["blockEditorStore", "deprecated"] }