@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 5.72 kB
Source Map (JSON)
{"version":3,"file":"edit.cjs","names":["useBlockProps","useToolsPanelDropdownMenuProps","useEntityProp","getDateSettings","InspectorControls","ToolsPanel","__","ToolsPanelItem","DateFormatPicker","ToggleControl","_x","dateI18n","humanTimeDiff"],"sources":["../../src/comment-date/edit.jsx"],"sourcesContent":["import { useEntityProp } from '@wordpress/core-data';\nimport {\n\tdateI18n,\n\thumanTimeDiff,\n\tgetSettings as getDateSettings,\n} from '@wordpress/date';\nimport {\n\tInspectorControls,\n\tuseBlockProps,\n\t__experimentalDateFormatPicker as DateFormatPicker,\n} from '@wordpress/block-editor';\nimport {\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\tToggleControl,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\n/**\n * Renders the `core/comment-date` block on the editor.\n *\n * @param {Object} props React props.\n * @param {Object} props.setAttributes Callback for updating block attributes.\n * @param {Object} props.attributes Block attributes.\n * @param {string} props.attributes.format Format of the date.\n * @param {string} props.attributes.isLink Whether the author name should be linked.\n * @param {Object} props.context Inherited context.\n * @param {string} props.context.commentId The comment ID.\n *\n * @return {React.JSX.Element} React element.\n */\nexport default function Edit( {\n\tattributes: { format, isLink },\n\tcontext: { commentId },\n\tsetAttributes,\n} ) {\n\tconst blockProps = useBlockProps();\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\tlet [ date ] = useEntityProp( 'root', 'comment', 'date', commentId );\n\tconst [ siteFormat = getDateSettings().formats.date ] = useEntityProp(\n\t\t'root',\n\t\t'site',\n\t\t'date_format'\n\t);\n\n\tconst inspectorControls = (\n\t\t<InspectorControls>\n\t\t\t<ToolsPanel\n\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\tresetAll={ () => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\tformat: undefined,\n\t\t\t\t\t\tisLink: true,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t>\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\tlabel={ __( 'Date format' ) }\n\t\t\t\t\thasValue={ () => format !== undefined }\n\t\t\t\t\tonDeselect={ () => setAttributes( { format: undefined } ) }\n\t\t\t\t\tisShownByDefault\n\t\t\t\t>\n\t\t\t\t\t<DateFormatPicker\n\t\t\t\t\t\tformat={ format }\n\t\t\t\t\t\tdefaultFormat={ siteFormat }\n\t\t\t\t\t\tonChange={ ( nextFormat ) =>\n\t\t\t\t\t\t\tsetAttributes( { format: nextFormat } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\tlabel={ __( 'Link to comment' ) }\n\t\t\t\t\thasValue={ () => ! isLink }\n\t\t\t\t\tonDeselect={ () => setAttributes( { isLink: true } ) }\n\t\t\t\t\tisShownByDefault\n\t\t\t\t>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Link to comment' ) }\n\t\t\t\t\t\tonChange={ () => setAttributes( { isLink: ! isLink } ) }\n\t\t\t\t\t\tchecked={ isLink }\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\t\t\t</ToolsPanel>\n\t\t</InspectorControls>\n\t);\n\n\tif ( ! commentId || ! date ) {\n\t\tdate = _x( 'Comment Date', 'block title' );\n\t}\n\n\tlet commentDate =\n\t\tdate instanceof Date ? (\n\t\t\t<time dateTime={ dateI18n( 'c', date ) }>\n\t\t\t\t{ format === 'human-diff'\n\t\t\t\t\t? humanTimeDiff( date )\n\t\t\t\t\t: dateI18n( format || siteFormat, date ) }\n\t\t\t</time>\n\t\t) : (\n\t\t\t<time>{ date }</time>\n\t\t);\n\n\tif ( isLink ) {\n\t\tcommentDate = (\n\t\t\t<a\n\t\t\t\thref=\"#comment-date-pseudo-link\"\n\t\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t\t>\n\t\t\t\t{ commentDate }\n\t\t\t</a>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ inspectorControls }\n\t\t\t<div { ...blockProps }>{ commentDate }</div>\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAwB,KAAM,EAC7B,YAAY,EAAE,QAAQ,UACtB,SAAS,EAAE,aACX,iBACG;CACH,MAAM,cAAA,GAAaA,wBAAAA,cAAAA,CAAc;CACjC,MAAM,qBAAA,GAAoBC,kBAAAA,+BAAAA,CAA+B;CAEzD,IAAI,CAAE,SAAA,GAASC,qBAAAA,cAAAA,CAAe,QAAQ,WAAW,QAAQ,SAAU;CACnE,MAAM,CAAE,cAAA,GAAaC,gBAAAA,YAAAA,CAAgB,CAAC,CAAC,QAAQ,SAAA,GAASD,qBAAAA,cAAAA,CACvD,QACA,QACA,aACD;CAEA,MAAM,oBACL,iBAAA,GAAA,kBAAA,IAAA,CAACE,wBAAAA,mBAAD,EAAA,UACC,iBAAA,GAAA,kBAAA,KAAA,CAACC,sBAAAA,0BAAD;EACC,QAAA,GAAQC,gBAAAA,GAAAA,CAAI,UAAW;EACvB,gBAAiB;GAChB,cAAe;IACd,QAAQ,KAAA;IACR,QAAQ;GACT,CAAE;EACH;EACoB;EARrB,UAAA,CAUC,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,8BAAD;GACC,QAAA,GAAQD,gBAAAA,GAAAA,CAAI,aAAc;GAC1B,gBAAiB,WAAW,KAAA;GAC5B,kBAAmB,cAAe,EAAE,QAAQ,KAAA,EAAU,CAAE;GACxD,kBAAA;GAEA,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACE,wBAAAA,gCAAD;IACU;IACT,eAAgB;IAChB,WAAa,eACZ,cAAe,EAAE,QAAQ,WAAW,CAAE;GAEvC,CAAA;E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