@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 4.15 kB
Source Map (JSON)
{"version":3,"file":"deprecated.mjs","names":[],"sources":["../../src/block/deprecated.js"],"sourcesContent":["const isObject = ( obj ) =>\n\ttypeof obj === 'object' && ! Array.isArray( obj ) && obj !== null;\n\n// v2: Migrate to a more condensed version of the 'content' attribute attribute.\nconst v2 = {\n\tattributes: {\n\t\tref: {\n\t\t\ttype: 'number',\n\t\t},\n\t\tcontent: {\n\t\t\ttype: 'object',\n\t\t},\n\t},\n\tsupports: {\n\t\tcustomClassName: false,\n\t\thtml: false,\n\t\tinserter: false,\n\t\trenaming: false,\n\t},\n\t// Force this deprecation to run whenever there's a values sub-property that's an object.\n\t//\n\t// This could fail in the future if a block ever has binding to a `values` attribute.\n\t// Some extra protection is added to ensure `values` is an object, but this only reduces\n\t// the likelihood, it doesn't solve it completely.\n\tisEligible( { content } ) {\n\t\treturn (\n\t\t\t!! content &&\n\t\t\tObject.keys( content ).every(\n\t\t\t\t( contentKey ) =>\n\t\t\t\t\tcontent[ contentKey ].values &&\n\t\t\t\t\tisObject( content[ contentKey ].values )\n\t\t\t)\n\t\t);\n\t},\n\t/*\n\t * Old attribute format:\n\t * content: {\n\t * \"V98q_x\": {\n\t * \t \t\t// The attribute values are now stored as a 'values' sub-property.\n\t * values: { content: 'My content value' },\n\t * \t // ... additional metadata, like the block name can be stored here.\n\t * }\n\t * }\n\t *\n\t * New attribute format:\n\t * content: {\n\t * \"V98q_x\": {\n\t * content: 'My content value',\n\t * }\n\t * }\n\t */\n\tmigrate( attributes ) {\n\t\tconst { content, ...retainedAttributes } = attributes;\n\n\t\tif ( content && Object.keys( content ).length ) {\n\t\t\tconst updatedContent = { ...content };\n\n\t\t\tfor ( const contentKey in content ) {\n\t\t\t\tupdatedContent[ contentKey ] = content[ contentKey ].values;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...retainedAttributes,\n\t\t\t\tcontent: updatedContent,\n\t\t\t};\n\t\t}\n\n\t\treturn attributes;\n\t},\n};\n\n// v1: Rename the `overrides` attribute to the `content` attribute.\nconst v1 = {\n\tattributes: {\n\t\tref: {\n\t\t\ttype: 'number',\n\t\t},\n\t\toverrides: {\n\t\t\ttype: 'object',\n\t\t},\n\t},\n\tsupports: {\n\t\tcustomClassName: false,\n\t\thtml: false,\n\t\tinserter: false,\n\t\trenaming: false,\n\t},\n\t// Force this deprecation to run whenever there's an `overrides` object.\n\tisEligible( { overrides } ) {\n\t\treturn !! overrides;\n\t},\n\t/*\n\t * Old attribute format:\n\t * overrides: {\n\t * // An key is an id that represents a block.\n\t * // The values are the attribute values of the block.\n\t * \"V98q_x\": { content: 'My content value' }\n\t * }\n\t *\n\t * New attribute format:\n\t * content: {\n\t * \"V98q_x\": { content: 'My content value' }\n\t * }\n\t *\n\t */\n\tmigrate( attributes ) {\n\t\tconst { overrides, ...retainedAttributes } = attributes;\n\n\t\tconst content = {};\n\n\t\tObject.keys( overrides ).forEach( ( id ) => {\n\t\t\tcontent[ id ] = overrides[ id ];\n\t\t} );\n\n\t\treturn {\n\t\t\t...retainedAttributes,\n\t\t\tcontent,\n\t\t};\n\t},\n};\n\nexport default [ v2, v1 ];\n"],"mappings":";AAAA,MAAM,YAAa,QAClB,OAAO,QAAQ,YAAY,CAAE,MAAM,QAAS,GAAI,KAAK,QAAQ;AAwH9D,IAAA,qBAAe,CAAE;CApHhB,YAAY;EACX,KAAK,EACJ,MAAM,SACP;EACA,SAAS,EACR,MAAM,SACP;CACD;CACA,UAAU;EACT,iBAAiB;EACjB,MAAM;EACN,UAAU;EACV,UAAU;CACX;CAMA,WAAY,EAAE,WAAY;EACzB,OACC,CAAC,CAAE,WACH,OAAO,KAAM,OAAQ,CAAC,CAAC,OACpB,eACD,QAAS,WAAY,CAAC,UACtB,SAAU,QAAS,WAAY,CAAC,MAAO,CACzC;CAEF;CAkBA,QAAS,YAAa;EACrB,MAAM,EAAE,SAAS,GAAG,uBAAuB;EAE3C,IAAK,WAAW,OAAO,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