@wordpress/block-library
Version:
Block library for the WordPress editor.
8 lines (7 loc) • 2.32 kB
Source Map (JSON)
{
"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": ";AAGA,SAAS,gBAAgB;AACzB,SAAS,WAAW,cAAc;AAClC,OAAO,gBAAgB;AACvB,SAAS,mBAAmB;AAC5B,SAAS,SAAS,wBAAwB;AAU3B,SAAR,mBAAqC,OAAO,OAAO,eAAgB;AACzE,QAAM,EAAE,wCAAwC,IAC/C,YAAa,gBAAiB;AAC/B,QAAM,uBAAuB,SAAU,MAAM;AAC5C,eAAY,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,sBAAsB,OAAO;AACnC,YAAW,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": []
}