UNPKG

@wordpress/editor

Version:
8 lines (7 loc) 3.08 kB
{ "version": 3, "sources": ["../../../../src/components/collab-sidebar/rich-text-control/format-edit.tsx"], "sourcesContent": ["import type { ComponentType, MutableRefObject } from 'react';\nimport { getActiveFormat, getActiveObject } from '@wordpress/rich-text';\nimport type { RichTextValue } from '@wordpress/rich-text';\n\n/*\n * The registered format type settings, as stored by\n * `@wordpress/rich-text`'s format registry. Only the members this\n * component consumes are typed; `edit` receives the props assembled\n * below, which vary per format type.\n */\ntype FormatSettings = {\n\tname: string;\n\tedit?: ComponentType< any >;\n};\n\ntype ActiveFormat = {\n\ttype: string;\n\tattributes?: Record< string, string >;\n};\n\ntype EditProps = {\n\tonChange: ( value: RichTextValue ) => void;\n\tonFocus: () => void;\n\tvalue: RichTextValue;\n\tforwardedRef: MutableRefObject< HTMLElement | undefined >;\n\tisVisible: boolean;\n};\n\nconst EMPTY_CONTEXT = {};\n\nfunction Edit( {\n\tonChange,\n\tonFocus,\n\tvalue,\n\tforwardedRef,\n\tsettings,\n\tisVisible,\n}: EditProps & { settings: FormatSettings } ) {\n\tconst { name, edit: EditFunction } = settings;\n\n\tif ( ! EditFunction ) {\n\t\treturn null;\n\t}\n\n\tconst activeFormat = getActiveFormat( value, name ) as\n\t\t| ActiveFormat\n\t\t| undefined;\n\tconst isActive = activeFormat !== undefined;\n\tconst activeObject = getActiveObject( value ) as ActiveFormat | undefined;\n\tconst isObjectActive =\n\t\tactiveObject !== undefined && activeObject.type === name;\n\n\treturn (\n\t\t<EditFunction\n\t\t\tkey={ name }\n\t\t\tisActive={ isActive }\n\t\t\tisVisible={ isVisible }\n\t\t\tactiveAttributes={ isActive ? activeFormat.attributes || {} : {} }\n\t\t\tisObjectActive={ isObjectActive }\n\t\t\tactiveObjectAttributes={\n\t\t\t\tisObjectActive ? activeObject.attributes || {} : {}\n\t\t\t}\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tonFocus={ onFocus }\n\t\t\tcontentRef={ forwardedRef }\n\t\t\tcontext={ EMPTY_CONTEXT }\n\t\t/>\n\t);\n}\n\nexport default function FormatEdit( {\n\tformatTypes,\n\t...props\n}: EditProps & { formatTypes: FormatSettings[] } ) {\n\treturn formatTypes.map( ( settings ) => (\n\t\t<Edit settings={ settings } { ...props } key={ settings.name } />\n\t) );\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAiD;AAoD/C;AAuBA;AAhDF,IAAM,gBAAgB,CAAC;AAEvB,SAAS,KAAM;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAA8C;AAC7C,QAAM,EAAE,MAAM,MAAM,aAAa,IAAI;AAErC,MAAK,CAAE,cAAe;AACrB,WAAO;AAAA,EACR;AAEA,QAAM,mBAAe,kCAAiB,OAAO,IAAK;AAGlD,QAAM,WAAW,iBAAiB;AAClC,QAAM,mBAAe,kCAAiB,KAAM;AAC5C,QAAM,iBACL,iBAAiB,UAAa,aAAa,SAAS;AAErD,SACC;AAAA,IAAC;AAAA;AAAA,MAEA;AAAA,MACA;AAAA,MACA,kBAAmB,WAAW,aAAa,cAAc,CAAC,IAAI,CAAC;AAAA,MAC/D;AAAA,MACA,wBACC,iBAAiB,aAAa,cAAc,CAAC,IAAI,CAAC;AAAA,MAEnD;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAa;AAAA,MACb,SAAU;AAAA;AAAA,IAZJ;AAAA,EAaP;AAEF;AAEe,SAAR,WAA6B;AAAA,EACnC;AAAA,EACA,GAAG;AACJ,GAAmD;AAClD,SAAO,YAAY,IAAK,CAAE,aACzB,gDAAC,QAAK,UAAwB,GAAG,OAAQ,KAAM,SAAS,MAAO,CAC9D;AACH;", "names": [] }