UNPKG

@wordpress/block-library

Version:
8 lines (7 loc) 2.39 kB
{ "version": 3, "sources": ["../../src/paragraph/deprecated-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 align attribute, we need to migrate its value\n * to the new style.typography.textAlign attribute.\n *\n * @param {string?} align Align attribute value.\n * @param {Object?} style Style attribute value.\n * @param {(Object) => void} setAttributes Updater function for block attributes.\n */\nexport default function useDeprecatedAlign( align, style, setAttributes ) {\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst updateStyleWithAlign = useEvent( () => {\n\t\tdeprecated( 'align attribute in paragraph block', {\n\t\t\talternative: 'style.typography.textAlign',\n\t\t\tsince: '7.0',\n\t\t} );\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tsetAttributes( {\n\t\t\tstyle: {\n\t\t\t\t...style,\n\t\t\t\ttypography: {\n\t\t\t\t\t...style?.typography,\n\t\t\t\t\ttextAlign: align,\n\t\t\t\t},\n\t\t\t},\n\t\t} );\n\t} );\n\tconst lastUpdatedAlignRef = useRef();\n\tuseEffect( () => {\n\t\tif (\n\t\t\talign === 'full' ||\n\t\t\talign === 'wide' ||\n\t\t\talign === lastUpdatedAlignRef.current\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tlastUpdatedAlignRef.current = align;\n\t\tupdateStyleWithAlign();\n\t}, [ align, updateStyleWithAlign ] );\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAyB;AACzB,qBAAkC;AAClC,wBAAuB;AACvB,kBAA4B;AAC5B,0BAA0C;AAU3B,SAAR,mBAAqC,OAAO,OAAO,eAAgB;AACzE,QAAM,EAAE,wCAAwC,QAC/C,yBAAa,oBAAAA,KAAiB;AAC/B,QAAM,2BAAuB,yBAAU,MAAM;AAC5C,0BAAAC,SAAY,sCAAsC;AAAA,MACjD,aAAa;AAAA,MACb,OAAO;AAAA,IACR,CAAE;AACF,4CAAwC;AACxC,kBAAe;AAAA,MACd,OAAO;AAAA,QACN,GAAG;AAAA,QACH,YAAY;AAAA,UACX,GAAG,OAAO;AAAA,UACV,WAAW;AAAA,QACZ;AAAA,MACD;AAAA,IACD,CAAE;AAAA,EACH,CAAE;AACF,QAAM,0BAAsB,uBAAO;AACnC,gCAAW,MAAM;AAChB,QACC,UAAU,UACV,UAAU,UACV,UAAU,oBAAoB,SAC7B;AACD;AAAA,IACD;AACA,wBAAoB,UAAU;AAC9B,yBAAqB;AAAA,EACtB,GAAG,CAAE,OAAO,oBAAqB,CAAE;AACpC;", "names": ["blockEditorStore", "deprecated"] }