UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 2.14 kB
{ "version": 3, "sources": ["../../../src/components/rich-text/with-deprecations.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { forwardRef } from '@wordpress/element';\nimport { children as childrenSource } from '@wordpress/blocks';\nimport { __unstableCreateElement } from '@wordpress/rich-text';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport RichTextMultiline from './multiline';\n\nexport function withDeprecations( Component ) {\n\treturn forwardRef( ( props, ref ) => {\n\t\tlet value = props.value;\n\t\tlet onChange = props.onChange;\n\n\t\t// Handle deprecated format.\n\t\tif ( Array.isArray( value ) ) {\n\t\t\tdeprecated( 'wp.blockEditor.RichText value prop as children type', {\n\t\t\t\tsince: '6.1',\n\t\t\t\tversion: '6.3',\n\t\t\t\talternative: 'value prop as string',\n\t\t\t\tlink: 'https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields/',\n\t\t\t} );\n\n\t\t\tvalue = childrenSource.toHTML( props.value );\n\t\t\tonChange = ( newValue ) =>\n\t\t\t\tprops.onChange(\n\t\t\t\t\tchildrenSource.fromDOM(\n\t\t\t\t\t\t__unstableCreateElement( document, newValue ).childNodes\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t}\n\n\t\tconst NewComponent = props.multiline ? RichTextMultiline : Component;\n\n\t\treturn (\n\t\t\t<NewComponent\n\t\t\t\t{ ...props }\n\t\t\t\tvalue={ value }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tref={ ref }\n\t\t\t/>\n\t\t);\n\t} );\n}\n"], "mappings": ";AAGA,SAAS,kBAAkB;AAC3B,SAAS,YAAY,sBAAsB;AAC3C,SAAS,+BAA+B;AACxC,OAAO,gBAAgB;AAKvB,OAAO,uBAAuB;AA4B3B;AA1BI,SAAS,iBAAkB,WAAY;AAC7C,SAAO,WAAY,CAAE,OAAO,QAAS;AACpC,QAAI,QAAQ,MAAM;AAClB,QAAI,WAAW,MAAM;AAGrB,QAAK,MAAM,QAAS,KAAM,GAAI;AAC7B,iBAAY,uDAAuD;AAAA,QAClE,OAAO;AAAA,QACP,SAAS;AAAA,QACT,aAAa;AAAA,QACb,MAAM;AAAA,MACP,CAAE;AAEF,cAAQ,eAAe,OAAQ,MAAM,KAAM;AAC3C,iBAAW,CAAE,aACZ,MAAM;AAAA,QACL,eAAe;AAAA,UACd,wBAAyB,UAAU,QAAS,EAAE;AAAA,QAC/C;AAAA,MACD;AAAA,IACF;AAEA,UAAM,eAAe,MAAM,YAAY,oBAAoB;AAE3D,WACC;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,EAEF,CAAE;AACH;", "names": [] }