messages listlengths 3 3 |
|---|
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for A single column within a columns block. that allows users to configure: vertical alignment, width, template lock"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/column/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/column\",\n\t\"title\": \"Column\",\n\t\"category\": \"design\",\n\t\"parent\": [ \"core/columns\" ],\n\t\"description\": \"A single column within a columns block.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"verticalAlignment\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"width\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"templateLock\": {\n\t\t\t\"type\": [ \"string\", \"boolean\" ],\n\t\t\t\"enum\": [ \"all\", \"insert\", \"contentOnly\", false ]\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"__experimentalOnEnter\": true,\n\t\t\"anchor\": true,\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"heading\": true,\n\t\t\t\"button\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"shadow\": true,\n\t\t\"spacing\": {\n\t\t\t\"blockGap\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true,\n\t\t\t\t\"blockGap\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"layout\": true,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"allowedBlocks\": true\n\t}\n}\n\n\n// File: packages/block-library/src/column/index.js\n/**\n * WordPress dependencies\n */\nimport { column as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/column/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { verticalAlignment, width } = attributes;\n\n\tconst wrapperClasses = clsx( {\n\t\t[ `is-vertically-aligned-${ verticalAlignment }` ]: verticalAlignment,\n\t} );\n\n\tlet style;\n\n\tif ( width && /\\d/.test( width ) ) {\n\t\t// Numbers are handled for backward compatibility as they can be still provided with templates.\n\t\tlet flexBasis = Number.isFinite( width ) ? width + '%' : width;\n\t\t// In some cases we need to round the width to a shorter float.\n\t\tif ( ! Number.isFinite( width ) && width?.endsWith( '%' ) ) {\n\t\t\tconst multiplier = 1000000000000;\n\t\t\t// Shrink the number back to a reasonable float.\n\t\t\tflexBasis =\n\t\t\t\tMath.round( Number.parseFloat( width ) * multiplier ) /\n\t\t\t\t\tmultiplier +\n\t\t\t\t'%';\n\t\t}\n\t\tstyle = { flexBasis };\n\t}\n\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: wrapperClasses,\n\t\tstyle,\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\n\treturn <div { ...innerBlocksProps } />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Construct a customizable WooCommerce block that allows users to adjust text alignment settings with ease."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-form/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-review-form\",\n\t\"title\": \"Reviews Form\",\n\t\"category\": \"woocommerce\",\n\t\"description\": \"Display a product's reviews form.\",\n\t\"textdomain\": \"woocommerce\",\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\" ],\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"heading\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"textAlign\": \"center\"\n\t\t}\n\t},\n\t\"viewScriptModule\": \"woocommerce/product-review-form\",\n\t\"style\": \"file:../woocommerce/product-review-form-style.css\",\n\t\"editorStyle\": \"file:../woocommerce/product-review-form-editor.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-form/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport {\n\tAlignmentControl,\n\tBlockControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { VisuallyHidden } from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport { __, sprintf } from '@wordpress/i18n';\nimport type { BlockEditProps } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport CommentsForm from './form';\n\nexport default function PostCommentsFormEdit( {\n\tattributes,\n\tcontext,\n\tsetAttributes,\n}: BlockEditProps< {\n\ttextAlign: string;\n} > & {\n\tcontext: { postId: string; postType: string };\n} ) {\n\tconst { textAlign } = attributes;\n\tconst { postId, postType } = context;\n\n\tconst instanceId = useInstanceId( PostCommentsFormEdit );\n\tconst instanceIdDesc = sprintf( 'comments-form-edit-%d-desc', instanceId );\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( 'comment-respond', {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t\t'aria-describedby': instanceIdDesc,\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t<AlignmentControl\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( nextAlign: string ) => {\n\t\t\t\t\t\tsetAttributes( { textAlign: nextAlign } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<CommentsForm postId={ postId } postType={ postType } />\n\t\t\t\t<VisuallyHidden id={ instanceIdDesc }>\n\t\t\t\t\t{ __( 'Reviews form disabled in editor.', 'woocommerce' ) }\n\t\t\t\t</VisuallyHidden>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Add a link to a downloadable file. with these attributes: id, blob, href, and 8 more options"
},
{
"role": "assistant",
"content": "// File: packages/block-library/src/file/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/file\",\n\t\"title\": \"File\",\n\t\"category\": \"media\",\n\t\"description\": \"Add a link to a downloadable file.\",\n\t\"keywords\": [ \"document\", \"pdf\", \"download\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"id\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"blob\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"local\"\n\t\t},\n\t\t\"href\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"fileId\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"a:not([download])\",\n\t\t\t\"attribute\": \"id\"\n\t\t},\n\t\t\"fileName\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"a:not([download])\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"textLinkHref\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"a:not([download])\",\n\t\t\t\"attribute\": \"href\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"textLinkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"a:not([download])\",\n\t\t\t\"attribute\": \"target\"\n\t\t},\n\t\t\"showDownloadButton\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"downloadButtonText\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"a[download]\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"displayPreview\": {\n\t\t\t\"type\": \"boolean\"\n\t\t},\n\t\t\"previewHeight\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 600\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"align\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": true\n\t},\n\t\"editorStyle\": \"wp-block-file-editor\",\n\t\"style\": \"wp-block-file\"\n}\n\n\n// File: packages/block-library/src/file/index.js\n/**\n * WordPress dependencies\n */\nimport { _x, __ } from '@wordpress/i18n';\nimport { file as icon } from '@wordpress/icons';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\thref: 'https://upload.wikimedia.org/wikipedia/commons/d/dd/Armstrong_Small_Step.ogg',\n\t\t\tfileName: _x( 'Armstrong_Small_Step', 'Name of the file' ),\n\t\t},\n\t},\n\ttransforms,\n\tdeprecated,\n\tedit,\n\tsave,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'file',\n\t\t\tlabel: __( 'File' ),\n\t\t\ttype: 'media',\n\t\t\tmapping: {\n\t\t\t\tid: 'id',\n\t\t\t\turl: 'href',\n\t\t\t},\n\t\t\targs: {\n\t\t\t\tallowedTypes: [],\n\t\t\t\tmultiple: false,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: 'fileName',\n\t\t\tlabel: __( 'Filename' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t\t{\n\t\t\tid: 'downloadButtonText',\n\t\t\tlabel: __( 'Button Text' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'file' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/file/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tRichText,\n\tuseBlockProps,\n\t__experimentalGetElementClassName,\n} from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst {\n\t\thref,\n\t\tfileId,\n\t\tfileName,\n\t\ttextLinkHref,\n\t\ttextLinkTarget,\n\t\tshowDownloadButton,\n\t\tdownloadButtonText,\n\t\tdisplayPreview,\n\t\tpreviewHeight,\n\t} = attributes;\n\n\tconst pdfEmbedLabel = RichText.isEmpty( fileName )\n\t\t? 'PDF embed'\n\t\t: // To do: use toPlainText, but we need ensure it's RichTextData. See\n\t\t // https://github.com/WordPress/gutenberg/pull/56710.\n\t\t fileName.toString();\n\n\tconst hasFilename = ! RichText.isEmpty( fileName );\n\n\t// Only output an `aria-describedby` when the element it's referring to is\n\t// actually rendered.\n\tconst describedById = hasFilename ? fileId : undefined;\n\n\treturn (\n\t\thref && (\n\t\t\t<div { ...useBlockProps.save() }>\n\t\t\t\t{ displayPreview && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<object\n\t\t\t\t\t\t\tclassName=\"wp-block-file__embed\"\n\t\t\t\t\t\t\tdata={ href }\n\t\t\t\t\t\t\ttype=\"application/pdf\"\n\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\twidth: '100%',\n\t\t\t\t\t\t\t\theight: `${ previewHeight }px`,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\taria-label={ pdfEmbedLabel }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t\t{ hasFilename && (\n\t\t\t\t\t<a\n\t\t\t\t\t\tid={ describedById }\n\t\t\t\t\t\thref={ textLinkHref }\n\t\t\t\t\t\ttarget={ textLinkTarget }\n\t\t\t\t\t\trel={\n\t\t\t\t\t\t\ttextLinkTarget ? 'noreferrer noopener' : undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<RichText.Content value={ fileName } />\n\t\t\t\t\t</a>\n\t\t\t\t) }\n\t\t\t\t{ showDownloadButton && (\n\t\t\t\t\t<a\n\t\t\t\t\t\thref={ href }\n\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t'wp-block-file__button',\n\t\t\t\t\t\t\t__experimentalGetElementClassName( 'button' )\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tdownload\n\t\t\t\t\t\taria-describedby={ describedById }\n\t\t\t\t\t>\n\t\t\t\t\t\t<RichText.Content value={ downloadButtonText } />\n\t\t\t\t\t</a>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t)\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a custom Gutenberg block that enables users to create an interactive set of call-to-action buttons for engaging website visitors."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/buttons/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/buttons\",\n\t\"title\": \"Buttons\",\n\t\"category\": \"design\",\n\t\"allowedBlocks\": [ \"core/button\" ],\n\t\"description\": \"Prompt visitors to take action with a group of button-style links.\",\n\t\"keywords\": [ \"link\" ],\n\t\"textdomain\": \"default\",\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"__experimentalExposeControlsToChildren\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"blockGap\": [ \"horizontal\", \"vertical\" ],\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"blockGap\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"layout\": {\n\t\t\t\"allowSwitching\": false,\n\t\t\t\"allowInheriting\": false,\n\t\t\t\"default\": {\n\t\t\t\t\"type\": \"flex\"\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"contentRole\": true\n\t},\n\t\"editorStyle\": \"wp-block-buttons-editor\",\n\t\"style\": \"wp-block-buttons\"\n}\n\n\n// File: packages/block-library/src/buttons/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { buttons as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport transforms from './transforms';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tlayout: {\n\t\t\t\ttype: 'flex',\n\t\t\t\tjustifyContent: 'center',\n\t\t\t},\n\t\t},\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/button',\n\t\t\t\tattributes: { text: __( 'Find out more' ) },\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/button',\n\t\t\t\tattributes: { text: __( 'Contact us' ) },\n\t\t\t},\n\t\t],\n\t},\n\tdeprecated,\n\ttransforms,\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/buttons/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes, className } ) {\n\tconst { fontSize, style } = attributes;\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: clsx( className, {\n\t\t\t'has-custom-font-size': fontSize || style?.typography?.fontSize,\n\t\t} ),\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\treturn <div { ...innerBlocksProps } />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a widget block that allows dynamic parent page selection and supports nested configuration."
},
{
"role": "assistant",
"content": "// File: packages/block-library/src/page-list/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/page-list\",\n\t\"title\": \"Page List\",\n\t\"category\": \"widgets\",\n\t\"allowedBlocks\": [ \"core/page-list-item\" ],\n\t\"description\": \"Display a list of all pages.\",\n\t\"keywords\": [ \"menu\", \"navigation\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"parentPageID\": {\n\t\t\t\"type\": \"integer\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"isNested\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"usesContext\": [\n\t\t\"textColor\",\n\t\t\"customTextColor\",\n\t\t\"backgroundColor\",\n\t\t\"customBackgroundColor\",\n\t\t\"overlayTextColor\",\n\t\t\"customOverlayTextColor\",\n\t\t\"overlayBackgroundColor\",\n\t\t\"customOverlayBackgroundColor\",\n\t\t\"fontSize\",\n\t\t\"customFontSize\",\n\t\t\"showSubmenuIcon\",\n\t\t\"style\",\n\t\t\"openSubmenusOnClick\"\n\t],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true,\n\t\t\t\"link\": true,\n\t\t\t\"gradients\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": false,\n\t\t\t\t\"margin\": false\n\t\t\t}\n\t\t},\n\t\t\"contentRole\": true\n\t},\n\t\"editorStyle\": \"wp-block-page-list-editor\",\n\t\"style\": \"wp-block-page-list\"\n}\n\n\n// File: packages/block-library/src/page-list/index.js\n/**\n * WordPress dependencies\n */\nimport { pages } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit.js';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon: pages,\n\texample: {},\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a woocommerce block with customizable lock"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/empty-mini-cart-contents-block/block.json\n{\n\t\"name\": \"woocommerce/empty-mini-cart-contents-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Empty Mini-Cart view\",\n\t\"description\": \"Blocks that are displayed when the Mini-Cart is empty.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false,\n\t\t\"interactivity\": true\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [ \"woocommerce/mini-cart-contents\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/empty-mini-cart-contents-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { useEditorContext } from '@woocommerce/base-context';\n\n/**\n * Internal dependencies\n */\nimport { getMiniCartAllowedBlocks } from '../allowed-blocks';\n\nexport const Edit = (): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst { currentView } = useEditorContext();\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\thidden={\n\t\t\t\tcurrentView !== 'woocommerce/empty-mini-cart-contents-block'\n\t\t\t}\n\t\t>\n\t\t\t<InnerBlocks\n\t\t\t\tallowedBlocks={ getMiniCartAllowedBlocks() }\n\t\t\t\trenderAppender={ InnerBlocks.ButtonBlockAppender }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a WordPress block that implements a pagination control displaying sequential page indicators, incorporating a mid-size range parameter."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/query-pagination-numbers/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/query-pagination-numbers\",\n\t\"title\": \"Page Numbers\",\n\t\"category\": \"theme\",\n\t\"parent\": [ \"core/query-pagination\" ],\n\t\"description\": \"Displays a list of page numbers for pagination.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"midSize\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 2\n\t\t}\n\t},\n\t\"usesContext\": [ \"queryId\", \"query\", \"enhancedPagination\" ],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-query-pagination-numbers-editor\"\n}\n\n\n// File: packages/block-library/src/query-pagination-numbers/index.js\n/**\n * WordPress dependencies\n */\nimport { queryPaginationNumbers as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\texample: {},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a woocommerce block with customizable class name, lock"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/block.json\n{\n\t\"name\": \"woocommerce/cart-order-summary-taxes-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Taxes\",\n\t\"description\": \"Shows the cart taxes row.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/cart-order-summary-totals-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport { PanelBody, ToggleControl } from '@wordpress/components';\nimport { getSetting } from '@woocommerce/settings';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: {\n\t\tclassName: string;\n\t\tshowRateAfterTaxName: boolean;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst { className, showRateAfterTaxName } = attributes;\n\tconst blockProps = useBlockProps();\n\tconst taxesEnabled = getSetting( 'taxesEnabled' ) as boolean;\n\tconst displayItemizedTaxes = getSetting(\n\t\t'displayItemizedTaxes',\n\t\tfalse\n\t) as boolean;\n\tconst displayCartPricesIncludingTax = getSetting(\n\t\t'displayCartPricesIncludingTax',\n\t\tfalse\n\t) as boolean;\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls>\n\t\t\t\t{ taxesEnabled &&\n\t\t\t\t\tdisplayItemizedTaxes &&\n\t\t\t\t\t! displayCartPricesIncludingTax && (\n\t\t\t\t\t\t<PanelBody title={ __( 'Taxes', 'woocommerce' ) }>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t\t\t'Show rate after tax name',\n\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Show the percentage rate alongside each tax line in the summary.',\n\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tchecked={ showRateAfterTaxName }\n\t\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tshowRateAfterTaxName:\n\t\t\t\t\t\t\t\t\t\t\t! showRateAfterTaxName,\n\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</PanelBody>\n\t\t\t\t\t) }\n\t\t\t</InspectorControls>\n\t\t\t<Block\n\t\t\t\tclassName={ className }\n\t\t\t\tshowRateAfterTaxName={ showRateAfterTaxName }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a WordPress block displaying a keyword tag cloud with customizable parameters like tag quantity, taxonomy selection, count visibility, and additional configurable options."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/tag-cloud/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/tag-cloud\",\n\t\"title\": \"Tag Cloud\",\n\t\"category\": \"widgets\",\n\t\"description\": \"A cloud of popular keywords, each sized by how often it appears.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"numberOfTags\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 45,\n\t\t\t\"minimum\": 1,\n\t\t\t\"maximum\": 100\n\t\t},\n\t\t\"taxonomy\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"post_tag\"\n\t\t},\n\t\t\"showTagCounts\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"smallestFontSize\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"8pt\"\n\t\t},\n\t\t\"largestFontSize\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"22pt\"\n\t\t}\n\t},\n\t\"styles\": [\n\t\t{ \"name\": \"default\", \"label\": \"Default\", \"isDefault\": true },\n\t\t{ \"name\": \"outline\", \"label\": \"Outline\" }\n\t],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"align\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalLetterSpacing\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-tag-cloud-editor\"\n}\n\n\n// File: packages/block-library/src/tag-cloud/index.js\n/**\n * WordPress dependencies\n */\nimport { tag as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport transforms from './transforms';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {},\n\tedit,\n\ttransforms,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a text block with customizable content, drop cap, placeholder, direction"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/paragraph/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/paragraph\",\n\t\"title\": \"Paragraph\",\n\t\"category\": \"text\",\n\t\"description\": \"Start with the basic building block of all narrative.\",\n\t\"keywords\": [ \"text\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"content\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"p\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"dropCap\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"placeholder\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"direction\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [ \"ltr\", \"rtl\" ]\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"splitting\": true,\n\t\t\"anchor\": true,\n\t\t\"className\": false,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"textAlign\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalWritingMode\": true,\n\t\t\t\"fitText\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalSelector\": \"p\",\n\t\t\"__unstablePasteTextInline\": true,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-paragraph-editor\",\n\t\"style\": \"wp-block-paragraph\"\n}\n\n\n// File: packages/block-library/src/paragraph/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { paragraph as icon } from '@wordpress/icons';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport variations from './variations';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tcontent: __(\n\t\t\t\t'In a village of La Mancha, the name of which I have no desire to call to mind, there lived not long since one of those gentlemen that keep a lance in the lance-rack, an old buckler, a lean hack, and a greyhound for coursing.'\n\t\t\t),\n\t\t},\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst customName = attributes?.metadata?.name;\n\n\t\tif ( context === 'list-view' && customName ) {\n\t\t\treturn customName;\n\t\t}\n\n\t\tif ( context === 'accessibility' ) {\n\t\t\tif ( customName ) {\n\t\t\t\treturn customName;\n\t\t\t}\n\n\t\t\tconst { content } = attributes;\n\t\t\treturn ! content || content.length === 0 ? __( 'Empty' ) : content;\n\t\t}\n\t},\n\ttransforms,\n\tdeprecated,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\tcontent:\n\t\t\t\t( attributes.content || '' ) +\n\t\t\t\t( attributesToMerge.content || '' ),\n\t\t};\n\t},\n\tedit,\n\tsave,\n\tvariations,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'content',\n\t\t\tlabel: __( 'Content' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'content' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/paragraph/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\nimport { isRTL } from '@wordpress/i18n';\n\nexport default function save( { attributes } ) {\n\tconst { content, dropCap, direction, style } = attributes;\n\tconst textAlign = style?.typography?.textAlign;\n\tconst className = clsx( {\n\t\t'has-drop-cap':\n\t\t\ttextAlign === ( isRTL() ? 'left' : 'right' ) ||\n\t\t\ttextAlign === 'center'\n\t\t\t\t? false\n\t\t\t\t: dropCap,\n\t} );\n\n\treturn (\n\t\t<p { ...useBlockProps.save( { className, dir: direction } ) }>\n\t\t\t<RichText.Content value={ content } />\n\t\t</p>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Contains blocks that display the content of the Mini-Cart. that allows users to configure: lock"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/filled-mini-cart-contents-block/block.json\n{\n\t\"name\": \"woocommerce/filled-mini-cart-contents-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Filled Mini-Cart view\",\n\t\"description\": \"Contains blocks that display the content of the Mini-Cart.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false,\n\t\t\"interactivity\": true\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [ \"woocommerce/mini-cart-contents\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/filled-mini-cart-contents-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport type { TemplateArray } from '@wordpress/blocks';\nimport { EditorProvider, useEditorContext } from '@woocommerce/base-context';\nimport { previewCart } from '@woocommerce/resource-previews';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseForcedLayout,\n\tgetAllowedBlocks,\n} from '../../../../cart-checkout-shared';\n\nexport const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst allowedBlocks = getAllowedBlocks( innerBlockAreas.FILLED_MINI_CART );\n\tconst { currentView } = useEditorContext();\n\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/mini-cart-title-block', {} ],\n\t\t[ 'woocommerce/mini-cart-items-block', {} ],\n\t\t[ 'woocommerce/mini-cart-footer-block', {} ],\n\t].filter( Boolean ) as unknown as TemplateArray;\n\n\tuseForcedLayout( {\n\t\tclientId,\n\t\tregisteredBlocks: allowedBlocks,\n\t\tdefaultTemplate,\n\t} );\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\thidden={\n\t\t\t\tcurrentView !== 'woocommerce/filled-mini-cart-contents-block'\n\t\t\t}\n\t\t>\n\t\t\t<EditorProvider\n\t\t\t\tcurrentView={ currentView }\n\t\t\t\tpreviewData={ { previewCart } }\n\t\t\t>\n\t\t\t\t<InnerBlocks\n\t\t\t\t\ttemplate={ defaultTemplate }\n\t\t\t\t\tallowedBlocks={ allowedBlocks }\n\t\t\t\t\ttemplateLock=\"insert\"\n\t\t\t\t/>\n\t\t\t</EditorProvider>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Design a Gutenberg block for generating dynamic breadcrumb trails that supports flexible settings including taxonomy selection, path separator, home page link, and two extra customization options."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/breadcrumbs/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/breadcrumbs\",\n\t\"title\": \"Breadcrumbs\",\n\t\"__experimental\": true,\n\t\"category\": \"theme\",\n\t\"description\": \"Display a breadcrumb trail for hierarchical post types or based on taxonomy terms.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"prefersTaxonomy\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"separator\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"/\"\n\t\t},\n\t\t\"showHomeItem\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showCurrentItem\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showOnHomePage\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\", \"templateSlug\" ],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": false,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-breadcrumbs\"\n}\n\n\n// File: packages/block-library/src/breadcrumbs/index.js\n/**\n * WordPress dependencies\n */\nimport { breadcrumbs } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon: breadcrumbs,\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a custom WordPress block that renders a real-time Instagram feed preview, allowing configuration through an access token, specified user profile, column arrangement, and three supplementary display options."
},
{
"role": "assistant",
"content": "// File: projects/plugins/jetpack/extensions/blocks/instagram-gallery/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/instagram-gallery\",\n\t\"title\": \"Latest Instagram Posts\",\n\t\"description\": \"Display an automatically updating list of the latest posts from your Instagram feed.\",\n\t\"keywords\": [ \"images\", \"photos\", \"pictures\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"embed\",\n\t\"icon\": \"<svg width='24' height='24' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path d='M12 4.622c2.403 0 2.688.01 3.637.052.877.04 1.354.187 1.67.31.42.163.72.358 1.036.673.315.315.51.615.673 1.035.123.317.27.794.31 1.67.043.95.052 1.235.052 3.638s-.01 2.688-.052 3.637c-.04.877-.187 1.354-.31 1.67-.163.42-.358.72-.673 1.036-.315.315-.615.51-1.035.673-.317.123-.794.27-1.67.31-.95.043-1.234.052-3.638.052s-2.688-.01-3.637-.052c-.877-.04-1.354-.187-1.67-.31-.42-.163-.72-.358-1.036-.673-.315-.315-.51-.615-.673-1.035-.123-.317-.27-.794-.31-1.67-.043-.95-.052-1.235-.052-3.638s.01-2.688.052-3.637c.04-.877.187-1.354.31-1.67.163-.42.358-.72.673-1.036.315-.315.615-.51 1.035-.673.317-.123.794-.27 1.67-.31.95-.043 1.235-.052 3.638-.052M12 3c-2.444 0-2.75.01-3.71.054s-1.613.196-2.185.418c-.592.23-1.094.538-1.594 1.04-.5.5-.807 1-1.037 1.593-.223.572-.375 1.226-.42 2.184C3.01 9.25 3 9.555 3 12s.01 2.75.054 3.71.196 1.613.418 2.186c.23.592.538 1.094 1.038 1.594s1.002.808 1.594 1.038c.572.222 1.227.375 2.185.418.96.044 1.266.054 3.71.054s2.75-.01 3.71-.054 1.613-.196 2.186-.418c.592-.23 1.094-.538 1.594-1.038s.808-1.002 1.038-1.594c.222-.572.375-1.227.418-2.185.044-.96.054-1.266.054-3.71s-.01-2.75-.054-3.71-.196-1.613-.418-2.186c-.23-.592-.538-1.094-1.038-1.594s-1.002-.808-1.594-1.038c-.572-.222-1.227-.375-2.185-.418C14.75 3.01 14.445 3 12 3zm0 4.378c-2.552 0-4.622 2.07-4.622 4.622s2.07 4.622 4.622 4.622 4.622-2.07 4.622-4.622S14.552 7.378 12 7.378zM12 15c-1.657 0-3-1.343-3-3s1.343-3 3-3 3 1.343 3 3-1.343 3-3 3zm4.804-8.884c-.596 0-1.08.484-1.08 1.08s.484 1.08 1.08 1.08c.596 0 1.08-.484 1.08-1.08s-.483-1.08-1.08-1.08z'></path></svg>\",\n\t\"supports\": { \"align\": true, \"html\": false },\n\t\"attributes\": {\n\t\t\"accessToken\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"instagramUser\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"columns\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3,\n\t\t\t\"min\": 1,\n\t\t\t\"max\": 6\n\t\t},\n\t\t\"count\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 9,\n\t\t\t\"min\": 1,\n\t\t\t\"max\": 30\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 10,\n\t\t\t\"min\": 0,\n\t\t\t\"max\": 50\n\t\t},\n\t\t\"isStackedOnMobile\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/instagram-gallery/edit.js\nimport { isCurrentUserConnected } from '@automattic/jetpack-shared-extension-utils';\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { Button, Placeholder, RadioControl, Spinner, withNotices } from '@wordpress/components';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport { isEmpty, isEqual } from 'lodash';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport metadata from './block.json';\nimport { NEW_INSTAGRAM_CONNECTION } from './constants';\nimport InstagramGalleryInspectorControls from './controls';\nimport ImageTransition from './image-transition';\nimport useConnectInstagram from './use-connect-instagram';\nimport useConnectWpcom from './use-connect-wpcom';\nimport useInstagramGallery from './use-instagram-gallery';\nimport './editor.scss';\n\nconst InstagramGalleryEdit = props => {\n\tconst blockProps = useBlockProps();\n\tconst { attributes, isSelected, noticeOperations, noticeUI, setAttributes } = props;\n\tconst { accessToken, align, columns, count, isStackedOnMobile, spacing } = attributes;\n\tuseEffect( () => {\n\t\tconst validatedAttributes = getValidatedAttributes( metadata.attributes, attributes );\n\t\tif ( ! isEqual( validatedAttributes, attributes ) ) {\n\t\t\tsetAttributes( validatedAttributes );\n\t\t}\n\t}, [ attributes, setAttributes ] );\n\n\tconst [ selectedAccount, setSelectedAccount ] = useState( accessToken );\n\tconst { isRequestingWpcomConnectUrl, wpcomConnectUrl } = useConnectWpcom();\n\tconst { images, isLoadingGallery, setImages } = useInstagramGallery( {\n\t\taccessToken,\n\t\tnoticeOperations,\n\t\tsetAttributes,\n\t\tsetSelectedAccount,\n\t} );\n\tconst {\n\t\tconnectToService,\n\t\tdisconnectFromService,\n\t\tisConnecting,\n\t\tisRequestingUserConnections,\n\t\tuserConnections,\n\t} = useConnectInstagram( {\n\t\taccessToken,\n\t\tnoticeOperations,\n\t\tselectedAccount,\n\t\tsetAttributes,\n\t\tsetImages,\n\t\tsetSelectedAccount,\n\t} );\n\n\tconst currentUserConnected = isCurrentUserConnected();\n\tconst unselectedCount = count > images.length ? images.length : count;\n\n\tconst showPlaceholder = ! isLoadingGallery && ( ! accessToken || isEmpty( images ) );\n\tconst showSidebar = ! showPlaceholder;\n\tconst showLoadingSpinner = accessToken && isLoadingGallery && isEmpty( images );\n\tconst showGallery = ! showPlaceholder && ! showLoadingSpinner;\n\n\tconst blockClasses = clsx( blockProps.className, { [ `align${ align }` ]: align } );\n\tconst gridClasses = clsx(\n\t\t'wp-block-jetpack-instagram-gallery__grid',\n\t\t`wp-block-jetpack-instagram-gallery__grid-columns-${ columns }`,\n\t\t{ 'is-stacked-on-mobile': isStackedOnMobile }\n\t);\n\tconst gridStyle = {\n\t\tgridGap: spacing,\n\t\t// Used to only apply padding when stacked in mobile viewport.\n\t\t[ `--latest-instagram-posts-spacing` ]: spacing ? `${ spacing }px` : undefined,\n\t};\n\tconst photoStyle = { padding: spacing }; // Needed so the updates to the grid gap render when changed.\n\n\tconst shouldRenderSidebarNotice = () =>\n\t\tshowSidebar && ! showLoadingSpinner && images.length < count;\n\n\tconst renderImage = index => {\n\t\tif ( images[ index ] ) {\n\t\t\tconst image = images[ index ];\n\t\t\treturn (\n\t\t\t\t<ImageTransition\n\t\t\t\t\talt={ image.title || image.url }\n\t\t\t\t\tsrc={ image.url }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tspacing={ spacing }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<img\n\t\t\t\talt={ __( 'Latest Instagram Posts placeholder', 'jetpack' ) }\n\t\t\t\tsrc=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNMyc2tBwAEOgG/c94mJwAAAABJRU5ErkJggg==\"\n\t\t\t/>\n\t\t);\n\t};\n\n\tconst connectBlockToInstagram = () => {\n\t\tif ( selectedAccount && NEW_INSTAGRAM_CONNECTION !== selectedAccount ) {\n\t\t\tsetAttributes( {\n\t\t\t\taccessToken: selectedAccount,\n\t\t\t\tinstagramUser: userConnections.find( v => v.token === selectedAccount ).username,\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\t\tconnectToService();\n\t};\n\n\tconst renderPlaceholderInstructions = () => {\n\t\tif ( ! currentUserConnected ) {\n\t\t\treturn __( \"First, you'll need to connect your WordPress.com account.\", 'jetpack' );\n\t\t}\n\t\tif ( ! isRequestingUserConnections && ! userConnections.length ) {\n\t\t\treturn __( 'Connect to Instagram to start sharing your images.', 'jetpack' );\n\t\t}\n\t};\n\n\tconst renderInstagramConnection = () => {\n\t\tconst hasUserConnections = userConnections.length > 0;\n\t\tconst radioOptions = [\n\t\t\t...userConnections.map( connection => ( {\n\t\t\t\tlabel: `@${ connection.username }`,\n\t\t\t\tvalue: connection.token,\n\t\t\t} ) ),\n\t\t\t{\n\t\t\t\tlabel: __( 'Add a new account', 'jetpack' ),\n\t\t\t\tvalue: NEW_INSTAGRAM_CONNECTION,\n\t\t\t},\n\t\t];\n\t\tconst isButtonDisabled =\n\t\t\tisConnecting || isRequestingUserConnections || ( hasUserConnections && ! selectedAccount );\n\n\t\treturn (\n\t\t\t<div>\n\t\t\t\t{ hasUserConnections && (\n\t\t\t\t\t<RadioControl\n\t\t\t\t\t\tlabel={ __( 'Select your Instagram account:', 'jetpack' ) }\n\t\t\t\t\t\tonChange={ value => setSelectedAccount( value ) }\n\t\t\t\t\t\toptions={ radioOptions }\n\t\t\t\t\t\tselected={ selectedAccount }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ NEW_INSTAGRAM_CONNECTION === selectedAccount && (\n\t\t\t\t\t<p className=\"wp-block-jetpack-instagram-gallery__new-account-instructions\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'If you are currently logged in to Instagram on this device, you might need to log out of it first.',\n\t\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t) }\n\t\t\t\t<Button disabled={ isButtonDisabled } variant=\"primary\" onClick={ connectBlockToInstagram }>\n\t\t\t\t\t{ isConnecting && __( 'Connecting…', 'jetpack' ) }\n\t\t\t\t\t{ isRequestingUserConnections && __( 'Loading your connections…', 'jetpack' ) }\n\t\t\t\t\t{ ! isConnecting &&\n\t\t\t\t\t\t! isRequestingUserConnections &&\n\t\t\t\t\t\t__( 'Connect to Instagram', 'jetpack' ) }\n\t\t\t\t</Button>\n\t\t\t</div>\n\t\t);\n\t};\n\n\treturn (\n\t\t<div { ...blockProps } className={ blockClasses }>\n\t\t\t{ showPlaceholder && (\n\t\t\t\t<Placeholder\n\t\t\t\t\ticon=\"instagram\"\n\t\t\t\t\tinstructions={ renderPlaceholderInstructions() }\n\t\t\t\t\tlabel={ __( 'Latest Instagram Posts', 'jetpack' ) }\n\t\t\t\t\tnotices={ noticeUI }\n\t\t\t\t>\n\t\t\t\t\t{ currentUserConnected ? (\n\t\t\t\t\t\trenderInstagramConnection()\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tdisabled={ isRequestingWpcomConnectUrl || ! wpcomConnectUrl }\n\t\t\t\t\t\t\thref={ wpcomConnectUrl }\n\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Connect to WordPress.com', 'jetpack' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t</Placeholder>\n\t\t\t) }\n\n\t\t\t{ showLoadingSpinner && (\n\t\t\t\t<div className=\"wp-block-embed is-loading\">\n\t\t\t\t\t<Spinner />\n\t\t\t\t\t<p>{ __( 'Embedding…', 'jetpack' ) }</p>\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ showGallery && (\n\t\t\t\t<div className={ gridClasses } style={ gridStyle }>\n\t\t\t\t\t{ Array.from( Array( isSelected ? count : unselectedCount ), ( _, index ) => (\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName={ clsx( 'wp-block-jetpack-instagram-gallery__grid-post' ) }\n\t\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\t\tstyle={ photoStyle }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ renderImage( index ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) ) }\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ showSidebar && (\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<InstagramGalleryInspectorControls\n\t\t\t\t\t\taccountImageTotal={ images.length }\n\t\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\t\tcurrentUserConnected={ currentUserConnected }\n\t\t\t\t\t\tdisconnectFromService={ disconnectFromService }\n\t\t\t\t\t\tshouldRenderSidebarNotice={ shouldRenderSidebarNotice() }\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t/>\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t</div>\n\t);\n};\n\nexport default withNotices( InstagramGalleryEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/instagram-gallery/save.js\nimport { useBlockProps } from '@wordpress/block-editor';\n\nexport default ( { attributes: { instagramUser } } ) => {\n\tconst blockProps = useBlockProps.save();\n\n\treturn (\n\t\tinstagramUser && (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<a\n\t\t\t\t\thref={ `https://www.instagram.com/${ instagramUser }/` }\n\t\t\t\t\trel=\"noopener noreferrer\"\n\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t>{ `https://www.instagram.com/${ instagramUser }/` }</a>\n\t\t\t</div>\n\t\t)\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a WordPress theme block that allows flexible text alignment configurations."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/term-description/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/term-description\",\n\t\"title\": \"Term Description\",\n\t\"category\": \"theme\",\n\t\"description\": \"Display the description of categories, tags and custom taxonomies when viewing an archive.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"termId\", \"taxonomy\" ],\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t}\n}\n\n\n// File: packages/block-library/src/term-description/index.js\n/**\n * WordPress dependencies\n */\nimport { termDescription as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\texample: {},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Construct a custom block for presenting order cost components, with configurable styling and lock options for enhanced user control."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-totals/block.json\n{\n\t\"name\": \"woocommerce/checkout-order-summary-totals-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Totals\",\n\t\"description\": \"Shows the subtotal, fees, discounts, shipping and taxes.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-order-summary-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-totals/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport type { TemplateArray } from '@wordpress/blocks';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseForcedLayout,\n\tgetAllowedBlocks,\n} from '../../../cart-checkout-shared';\n\nexport const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst allowedBlocks = getAllowedBlocks(\n\t\tinnerBlockAreas.CHECKOUT_ORDER_SUMMARY_TOTALS\n\t);\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/checkout-order-summary-subtotal-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-order-summary-fee-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-order-summary-discount-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-order-summary-shipping-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-order-summary-taxes-block', {}, [] ],\n\t] as TemplateArray;\n\n\tuseForcedLayout( {\n\t\tclientId,\n\t\tregisteredBlocks: allowedBlocks,\n\t\tdefaultTemplate,\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks\n\t\t\t\tallowedBlocks={ allowedBlocks }\n\t\t\t\ttemplate={ defaultTemplate }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Block that displays the cart button when the Mini-Cart has products. with these attributes: lock, cart button label"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-cart-button-block/block.json\n{\n\t\"name\": \"woocommerce/mini-cart-cart-button-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Mini-Cart View Cart Button\",\n\t\"description\": \"Block that displays the cart button when the Mini-Cart has products.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": true,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": false,\n\t\t\t\t\"move\": false\n\t\t\t}\n\t\t},\n\t\t\"cartButtonLabel\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"styles\": [\n\t\t{\n\t\t\t\"name\": \"fill\",\n\t\t\t\"label\": \"Fill\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"outline\",\n\t\t\t\"label\": \"Outline\",\n\t\t\t\"isDefault\": true\n\t\t}\n\t],\n\t\"parent\": [ \"woocommerce/mini-cart-footer-block\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-cart-button-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport EditableButton from '@woocommerce/editor-components/editable-button';\n\n/**\n * Internal dependencies\n */\nimport { defaultCartButtonLabel } from './constants';\nimport { getVariant } from '../utils';\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: {\n\t\tcartButtonLabel: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wc-block-mini-cart__footer-cart',\n\t} );\n\tconst { cartButtonLabel } = attributes;\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<EditableButton\n\t\t\t\tvariant={ getVariant( blockProps.className, 'outlined' ) }\n\t\t\t\tvalue={ cartButtonLabel }\n\t\t\t\tplaceholder={ defaultCartButtonLabel }\n\t\t\t\tonChange={ ( content ) => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\tcartButtonLabel: content,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\tstyle={ blockProps.style }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() }></div>;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a Gutenberg block for showcasing the primary product image, incorporating configurable attributes like product link visibility, sale badge display, badge alignment, and additional customization settings."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/block.json\n{\n\t\"name\": \"woocommerce/product-image\",\n\t\"title\": \"Product Image\",\n\t\"description\": \"Display the main product image.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"attributes\": {\n\t\t\"showProductLink\": { \"type\": \"boolean\", \"default\": true },\n\t\t\"showSaleBadge\": { \"type\": \"boolean\", \"default\": true },\n\t\t\"saleBadgeAlign\": { \"type\": \"string\", \"default\": \"right\" },\n\t\t\"imageSizing\": { \"type\": \"string\", \"default\": \"single\" },\n\t\t\"productId\": { \"type\": \"number\", \"default\": 0 },\n\t\t\"isDescendentOfQueryLoop\": { \"type\": \"boolean\", \"default\": false },\n\t\t\"isDescendentOfSingleProductBlock\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"width\": { \"type\": \"string\" },\n\t\t\"height\": { \"type\": \"string\" },\n\t\t\"scale\": { \"type\": \"string\", \"default\": \"cover\" },\n\t\t\"aspectRatio\": { \"type\": \"string\" }\n\t},\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"html\": false,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"dimensions\": {\n\t\t\t\"aspectRatio\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"email\": true,\n\t\t\"__experimentalSelector\": \".wc-block-components-product-image\"\n\t},\n\t\"ancestor\": [\n\t\t\"woocommerce/all-products\",\n\t\t\"woocommerce/single-product\",\n\t\t\"woocommerce/product-template\",\n\t\t\"core/post-template\"\n\t],\n\t\"usesContext\": [ \"imageId\", \"postId\", \"query\", \"queryId\" ],\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tInspectorControls,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport {\n\tcreateInterpolateElement,\n\tuseEffect,\n\tuseRef,\n} from '@wordpress/element';\nimport { getAdminLink, getSettingWithCoercion } from '@woocommerce/settings';\nimport { useProduct } from '@woocommerce/entities';\nimport { isBoolean } from '@woocommerce/types';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';\nimport {\n\tPanelBody,\n\tToggleControl,\n\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t// @ts-ignore - Ignoring because `__experimentalToggleGroupControl` is not yet in the type definitions.\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t// @ts-ignore - Ignoring because `__experimentalToggleGroupControl` is not yet in the type definitions.\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport { useIsDescendentOfSingleProductBlock } from '../shared/use-is-descendent-of-single-product-block';\nimport { BlockAttributes, ImageSizing } from './types';\nimport { ImageSizeSettings } from './image-size-settings';\n\nconst TEMPLATE = [\n\t[\n\t\t'woocommerce/product-sale-badge',\n\t\t{\n\t\t\talign: 'right',\n\t\t},\n\t],\n];\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n\tcontext,\n\tclientId,\n}: BlockEditProps< BlockAttributes > & { context: Context } ): JSX.Element => {\n\tconst { showProductLink, imageSizing, width, height, scale } = attributes;\n\n\tconst ref = useRef< HTMLDivElement >( null );\n\n\tconst blockProps = useBlockProps();\n\tconst { wasBlockJustInserted, isInProductGallery } = useSelect(\n\t\t( select ) => {\n\t\t\treturn {\n\t\t\t\twasBlockJustInserted:\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t\t\t\t// @ts-expect-error method exists but not typed\n\t\t\t\t\tselect( blockEditorStore ).wasBlockJustInserted( clientId ),\n\t\t\t\tisInProductGallery:\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t\t\t\t// @ts-expect-error method exists but not typed\n\t\t\t\t\tselect( blockEditorStore ).getBlockParentsByBlockName(\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t'woocommerce/product-gallery'\n\t\t\t\t\t).length > 0,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst isDescendentOfQueryLoop = Number.isFinite( context.queryId );\n\tconst { isDescendentOfSingleProductBlock } =\n\t\tuseIsDescendentOfSingleProductBlock( {\n\t\t\tblockClientId: blockProps?.id,\n\t\t} );\n\n\tuseEffect( () => {\n\t\tif ( isDescendentOfQueryLoop || isDescendentOfSingleProductBlock ) {\n\t\t\tsetAttributes( {\n\t\t\t\tisDescendentOfQueryLoop,\n\t\t\t\tisDescendentOfSingleProductBlock,\n\t\t\t\tshowSaleBadge: false,\n\t\t\t} );\n\t\t} else {\n\t\t\tsetAttributes( {\n\t\t\t\tisDescendentOfQueryLoop,\n\t\t\t\tisDescendentOfSingleProductBlock,\n\t\t\t} );\n\t\t}\n\t}, [\n\t\tisDescendentOfQueryLoop,\n\t\tisDescendentOfSingleProductBlock,\n\t\tsetAttributes,\n\t] );\n\n\tconst showAllControls =\n\t\tisDescendentOfQueryLoop || isDescendentOfSingleProductBlock;\n\n\tconst innerBlockProps = useInnerBlocksProps(\n\t\t{\n\t\t\tclassName: 'wc-block-components-product-image__inner-container',\n\t\t},\n\t\t{\n\t\t\tdropZoneElement: ref.current,\n\t\t\ttemplate: wasBlockJustInserted ? TEMPLATE : undefined,\n\t\t}\n\t);\n\n\tconst isBlockTheme = getSettingWithCoercion(\n\t\t'isBlockTheme',\n\t\tfalse,\n\t\tisBoolean\n\t);\n\n\tconst { product, isResolving } = useProduct( context.postId );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ /* Don't show controls in product gallery as we rely on\n\t\t\tcore supports API (aspect ratio setting) */ }\n\t\t\t{ showAllControls && ! isInProductGallery && (\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<ImageSizeSettings\n\t\t\t\t\t\tscale={ scale }\n\t\t\t\t\t\twidth={ width }\n\t\t\t\t\t\theight={ height }\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t/>\n\t\t\t\t\t<PanelBody title={ __( 'Content', 'woocommerce' ) }>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t\t'Link to Product Page',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Links the image to the single product listing.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tchecked={ showProductLink }\n\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tshowProductLink: ! showProductLink,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\t\tlabel={ __( 'Resolution', 'woocommerce' ) }\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\thelp={\n\t\t\t\t\t\t\t\t! isBlockTheme\n\t\t\t\t\t\t\t\t\t? createInterpolateElement(\n\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t'Product image cropping can be modified in the <a>Customizer</a>.',\n\t\t\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\ta: (\n\t\t\t\t\t\t\t\t\t\t\t\t\t// eslint-disable-next-line jsx-a11y/anchor-has-content\n\t\t\t\t\t\t\t\t\t\t\t\t\t<a\n\t\t\t\t\t\t\t\t\t\t\t\t\t\thref={ `${ getAdminLink(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'customize.php'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t) }?autofocus[panel]=woocommerce&autofocus[section]=woocommerce_product_images` }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\trel=\"noopener noreferrer\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t: null\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvalue={ imageSizing }\n\t\t\t\t\t\t\tonChange={ ( value: ImageSizing ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { imageSizing: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue={ ImageSizing.SINGLE }\n\t\t\t\t\t\t\t\tlabel={ __( 'Full Size', 'woocommerce' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue={ ImageSizing.THUMBNAIL }\n\t\t\t\t\t\t\t\tlabel={ __( 'Thumbnail', 'woocommerce' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t\t<Block\n\t\t\t\t{ ...{ ...attributes, ...context } }\n\t\t\t\tisAdmin={ true }\n\t\t\t\tproduct={ product }\n\t\t\t\tisResolving={ isResolving }\n\t\t\t>\n\t\t\t\t{ showAllControls && <div { ...innerBlockProps } /> }\n\t\t\t</Block>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a customizable column block within WordPress that presents cart items and provides locking configuration options."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-items-block/block.json\n{\n\t\"name\": \"woocommerce/cart-items-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Cart Items\",\n\t\"description\": \"Column containing cart items.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/filled-cart-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-items-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { Main } from '@woocommerce/base-components/sidebar-layout';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport type { TemplateArray } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseForcedLayout,\n\tgetAllowedBlocks,\n} from '../../../cart-checkout-shared';\nimport crossSells from '../../../product-collection/collections/cross-sells';\n\ninterface Props {\n\tclientId: string;\n}\n\nexport const Edit = ( { clientId }: Props ): JSX.Element => {\n\tconst blockProps = useBlockProps( { className: 'wc-block-cart__main' } );\n\tconst allowedBlocks = getAllowedBlocks( innerBlockAreas.CART_ITEMS );\n\t// Product collection is used for the Cross-Sells block.\n\t// We don't want to set a parent on the product collection block\n\t// so we add it here manually.\n\tallowedBlocks.push( 'woocommerce/product-collection' );\n\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/cart-line-items-block', {}, [] ],\n\t\t[\n\t\t\t'woocommerce/product-collection',\n\t\t\t{\n\t\t\t\t...crossSells.attributes,\n\t\t\t\tdisplayLayout: {\n\t\t\t\t\t...crossSells.attributes.displayLayout,\n\t\t\t\t\tcolumns: 3,\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\t...crossSells.attributes.query,\n\t\t\t\t\tperPage: 3,\n\t\t\t\t},\n\t\t\t\tcollection: 'woocommerce/product-collection/cross-sells',\n\t\t\t},\n\t\t\tcrossSells.innerBlocks,\n\t\t],\n\t] as unknown as TemplateArray;\n\n\tuseForcedLayout( {\n\t\tclientId,\n\t\tregisteredBlocks: allowedBlocks,\n\t\tdefaultTemplate,\n\t} );\n\treturn (\n\t\t<Main { ...blockProps }>\n\t\t\t<InnerBlocks\n\t\t\t\tallowedBlocks={ allowedBlocks }\n\t\t\t\ttemplate={ defaultTemplate }\n\t\t\t\ttemplateLock={ false }\n\t\t\t\trenderAppender={ InnerBlocks.ButtonBlockAppender }\n\t\t\t/>\n\t\t</Main>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Design a dynamic WordPress block that allows for customizable referencing and content editing to enhance template reusability."
},
{
"role": "assistant",
"content": "// File: packages/block-library/src/block/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/block\",\n\t\"title\": \"Pattern\",\n\t\"category\": \"reusable\",\n\t\"description\": \"Reuse this design across your site.\",\n\t\"keywords\": [ \"reusable\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"ref\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"content\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {}\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"pattern/overrides\": \"content\"\n\t},\n\t\"supports\": {\n\t\t\"customClassName\": false,\n\t\t\"html\": false,\n\t\t\"inserter\": false,\n\t\t\"renaming\": false,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t}\n}\n\n\n// File: packages/block-library/src/block/index.js\n/**\n * WordPress dependencies\n */\nimport { symbol as icon } from '@wordpress/icons';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { select } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport deprecated from './deprecated';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\tdeprecated,\n\tedit,\n\ticon,\n\t__experimentalLabel: ( { ref } ) => {\n\t\tif ( ! ref ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst entity = select( coreStore ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\t'wp_block',\n\t\t\tref\n\t\t);\n\t\tif ( ! entity?.title ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn decodeEntities( entity.title );\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Design a block component that renders a list-based representation of child products in the Grouped Product Selector functionality."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item/block.json\n{\n\t\"name\": \"woocommerce/add-to-cart-with-options-grouped-product-item\",\n\t\"title\": \"Grouped Product: Template (Beta)\",\n\t\"description\": \"A list item template that represents a child product within the Grouped Product Selector block.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"usesContext\": [ \"postId\" ],\n\t\"ancestor\": [\n\t\t\"woocommerce/add-to-cart-with-options-grouped-product-selector\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"supports\": {\n\t\t\"inserter\": false,\n\t\t\"interactivity\": true\n\t},\n\t\"style\": \"file:../woocommerce/add-to-cart-with-options-grouped-product-item-style.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item/edit.tsx\n/**\n * External dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n\t__experimentalUseBlockPreview as useBlockPreview,\n\tBlockContextProvider,\n} from '@wordpress/block-editor';\nimport { BlockInstance, type BlockEditProps } from '@wordpress/blocks';\nimport { withProduct } from '@woocommerce/block-hocs';\nimport {\n\tInnerBlockLayoutContextProvider,\n\tProductDataContextProvider,\n\tuseProductDataContext,\n} from '@woocommerce/shared-context';\nimport { resolveSelect, useSelect } from '@wordpress/data';\nimport type { ProductResponseItem } from '@woocommerce/types';\nimport { productsStore } from '@woocommerce/data';\nimport { isProductResponseItem } from '@woocommerce/entities';\nimport { Spinner } from '@wordpress/components';\nimport { previewProductResponseItems } from '@woocommerce/resource-previews';\n\ninterface Attributes {\n\tclassName?: string;\n}\n\ntype ProductItemWithContextProps = {\n\tattributes: { productId: number };\n\tisLoading?: boolean;\n\tproduct?: ProductResponseItem | null;\n\tblocks: BlockInstance[];\n\tisSelected: boolean;\n\tonSelect(): void;\n};\n\ntype ProductItemProps = {\n\tproduct: ProductResponseItem | null;\n\tblocks: BlockInstance[];\n\tisLoading: boolean;\n\tisSelected: boolean;\n\tonSelect(): void;\n};\n\nconst ProductItem = ( {\n\tproduct,\n\tblocks,\n\tisLoading,\n\tisSelected,\n\tonSelect,\n}: ProductItemProps ) => {\n\tconst blockPreviewProps = useBlockPreview( {\n\t\tblocks,\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{ role: 'listitem' },\n\t\t{ templateLock: 'insert' }\n\t);\n\n\treturn (\n\t\t<ProductDataContextProvider product={ product } isLoading={ isLoading }>\n\t\t\t{ isSelected ? (\n\t\t\t\t<div { ...innerBlocksProps } />\n\t\t\t) : (\n\t\t\t\t<div role=\"listitem\">\n\t\t\t\t\t<div\n\t\t\t\t\t\t{ ...blockPreviewProps }\n\t\t\t\t\t\trole=\"button\"\n\t\t\t\t\t\ttabIndex={ 0 }\n\t\t\t\t\t\tonClick={ onSelect }\n\t\t\t\t\t\tonKeyDown={ ( e ) => {\n\t\t\t\t\t\t\tif ( e.key === 'Enter' || e.key === ' ' ) {\n\t\t\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\t\t\tonSelect();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</ProductDataContextProvider>\n\t);\n};\n\nconst ProductItemWithContext = withProduct(\n\t( {\n\t\tattributes,\n\t\tisLoading = true,\n\t\tproduct = null,\n\t\tblocks,\n\t\tisSelected,\n\t\tonSelect,\n\t}: ProductItemWithContextProps ) => {\n\t\treturn (\n\t\t\t<BlockContextProvider\n\t\t\t\tvalue={ { postId: attributes.productId, postType: 'product' } }\n\t\t\t>\n\t\t\t\t<ProductItem\n\t\t\t\t\tproduct={ product }\n\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\tisLoading={ isLoading }\n\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t/>\n\t\t\t</BlockContextProvider>\n\t\t);\n\t}\n);\n\nexport default function ProductItemTemplateEdit(\n\tprops: BlockEditProps< Attributes >\n) {\n\tconst { clientId } = props;\n\tconst { className } = props.attributes;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName,\n\t} );\n\n\tconst { product, isLoading } = useProductDataContext();\n\tconst [ isLoadingProducts, setIsLoadingProducts ] = useState( true );\n\tconst [ products, setProducts ] = useState< ProductResponseItem[] | null >(\n\t\tnull\n\t);\n\tconst productsLength = products?.length || 0;\n\n\tuseEffect( () => {\n\t\tconst fetchChildProducts = async ( groupedProductIds: number[] ) => {\n\t\t\tif ( ! groupedProductIds || groupedProductIds.length === 0 ) {\n\t\t\t\tsetIsLoadingProducts( false );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tresolveSelect( productsStore )\n\t\t\t\t.getProducts( {\n\t\t\t\t\tinclude: groupedProductIds,\n\t\t\t\t\tper_page: groupedProductIds.length,\n\t\t\t\t\t_fields: [ 'id' ],\n\t\t\t\t} )\n\t\t\t\t.then( ( fetchedProducts ) => {\n\t\t\t\t\tsetProducts( fetchedProducts );\n\t\t\t\t\tsetIsLoadingProducts( false );\n\t\t\t\t} );\n\t\t};\n\n\t\tif ( ! isLoading && product && productsLength === 0 ) {\n\t\t\tif ( isProductResponseItem( product ) ) {\n\t\t\t\tfetchChildProducts( product.grouped_products );\n\t\t\t} else {\n\t\t\t\t// If not editing a specific product, we are editing a template.\n\t\t\t\t// Fetch an existing grouped product so template can be edited.\n\t\t\t\tresolveSelect( productsStore )\n\t\t\t\t\t.getProducts( { type: 'grouped', per_page: 1 } )\n\t\t\t\t\t.then( ( groupedProduct ) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tgroupedProduct.length > 0 &&\n\t\t\t\t\t\t\tgroupedProduct[ 0 ]?.grouped_products?.length > 0\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tfetchChildProducts(\n\t\t\t\t\t\t\t\tgroupedProduct[ 0 ].grouped_products\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// If there are no grouped products, query for any three other products.\n\t\t\t\t\t\t\tresolveSelect( productsStore )\n\t\t\t\t\t\t\t\t.getProducts( {\n\t\t\t\t\t\t\t\t\tper_page: 3,\n\t\t\t\t\t\t\t\t\t_fields: [ 'id' ],\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t.then( ( fetchedProducts ) => {\n\t\t\t\t\t\t\t\t\tif ( fetchedProducts.length > 0 ) {\n\t\t\t\t\t\t\t\t\t\tsetProducts( fetchedProducts );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tsetIsLoadingProducts( false );\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t}, [ isLoading, product, productsLength ] );\n\n\tconst { blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlocks } = select( blockEditorStore );\n\t\t\treturn { blocks: getBlocks( clientId ) };\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst [ selectedProductItem, setSelectedProductItem ] =\n\t\tuseState< number >();\n\n\tif ( isLoading || isLoadingProducts ) {\n\t\treturn <Spinner />;\n\t}\n\n\tconst productList = products\n\t\t? products?.map( ( productItem ) => (\n\t\t\t\t<ProductItemWithContext\n\t\t\t\t\tkey={ productItem.id }\n\t\t\t\t\tattributes={ {\n\t\t\t\t\t\tproductId: productItem.id,\n\t\t\t\t\t} }\n\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\tisSelected={\n\t\t\t\t\t\t( selectedProductItem ?? products[ 0 ]?.id ) ===\n\t\t\t\t\t\tproductItem.id\n\t\t\t\t\t}\n\t\t\t\t\tonSelect={ () => setSelectedProductItem( productItem.id ) }\n\t\t\t\t/>\n\t\t ) )\n\t\t: previewProductResponseItems?.map( ( productItem ) => (\n\t\t\t\t<ProductItem\n\t\t\t\t\tkey={ productItem.id }\n\t\t\t\t\tproduct={ productItem }\n\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\tisLoading={ false }\n\t\t\t\t\tisSelected={\n\t\t\t\t\t\t( selectedProductItem ??\n\t\t\t\t\t\t\tpreviewProductResponseItems[ 0 ]?.id ) ===\n\t\t\t\t\t\tproductItem.id\n\t\t\t\t\t}\n\t\t\t\t\tonSelect={ () => setSelectedProductItem( productItem.id ) }\n\t\t\t\t/>\n\t\t ) );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlockLayoutContextProvider parentName=\"woocommerce/add-to-cart-with-options-grouped-product-item\">\n\t\t\t\t<div role=\"list\">{ productList }</div>\n\t\t\t</InnerBlockLayoutContextProvider>\n\t\t</div>\n\t);\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport default function ProductItemTemplateSave() {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( {\n\t\t...blockProps,\n\t\trole: 'listitem',\n\t} );\n\treturn <div { ...innerBlocksProps } />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Construct a custom block designed to render and showcase the active filtering criteria within the current view."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/active-filters/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"name\": \"woocommerce/product-filter-active\",\n\t\"title\": \"Active Filters\",\n\t\"description\": \"Display the currently active filters.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"ancestor\": [ \"woocommerce/product-filters\" ],\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": false,\n\t\t\t\t\"radius\": false,\n\t\t\t\t\"style\": false,\n\t\t\t\t\"width\": false\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"blockGap\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false,\n\t\t\t\t\"blockGap\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"usesContext\": [ \"activeFilters\" ],\n\t\"viewScriptModule\": \"woocommerce/product-filter-active\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/active-filters/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tBlockContextProvider,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { InitialDisabled } from '../../components/initial-disabled';\nimport { EXCLUDED_BLOCKS } from '../../constants';\nimport { getAllowedBlocks } from '../../utils/get-allowed-blocks';\nimport { filtersPreview } from './constants';\n\nconst Edit = () => {\n\tconst { children, ...innerBlocksProps } = useInnerBlocksProps(\n\t\tuseBlockProps(),\n\t\t{\n\t\t\tallowedBlocks: getAllowedBlocks( EXCLUDED_BLOCKS ),\n\t\t\ttemplate: [\n\t\t\t\t[ 'woocommerce/product-filter-removable-chips' ],\n\t\t\t\t[ 'woocommerce/product-filter-clear-button' ],\n\t\t\t],\n\t\t}\n\t);\n\n\treturn (\n\t\t<div { ...innerBlocksProps }>\n\t\t\t<InitialDisabled>\n\t\t\t\t<BlockContextProvider\n\t\t\t\t\tvalue={ {\n\t\t\t\t\t\tfilterData: {\n\t\t\t\t\t\t\titems: filtersPreview,\n\t\t\t\t\t\t},\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ children }\n\t\t\t\t</BlockContextProvider>\n\t\t\t</InitialDisabled>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/active-filters/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nconst Save = () => {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\treturn <div { ...innerBlocksProps } />;\n};\n\nexport default Save;\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Displays a heading that toggles the accordion panel. that allows users to configure: open by default, title, level, and 2 more options"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/accordion-heading/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/accordion-heading\",\n\t\"title\": \"Accordion Heading\",\n\t\"category\": \"design\",\n\t\"description\": \"Displays a heading that toggles the accordion panel.\",\n\t\"parent\": [ \"core/accordion-item\" ],\n\t\"usesContext\": [\n\t\t\"core/accordion-icon-position\",\n\t\t\"core/accordion-show-icon\",\n\t\t\"core/accordion-heading-level\"\n\t],\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"gradients\": true\n\t\t},\n\t\t\"align\": false,\n\t\t\"interactivity\": true,\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true\n\t\t\t},\n\t\t\t\"__experimentalSkipSerialization\": true,\n\t\t\t\"__experimentalSelector\": \".wp-block-accordion-heading__toggle\"\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"__experimentalSkipSerialization\": [\n\t\t\t\t\"textDecoration\",\n\t\t\t\t\"letterSpacing\"\n\t\t\t],\n\t\t\t\"fontSize\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true,\n\t\t\t\t\"fontFamily\": true\n\t\t\t}\n\t\t},\n\t\t\"shadow\": true,\n\t\t\"visibility\": false,\n\t\t\"lock\": false\n\t},\n\t\"selectors\": {\n\t\t\"typography\": {\n\t\t\t\"letterSpacing\": \".wp-block-accordion-heading .wp-block-accordion-heading__toggle-title\",\n\t\t\t\"textDecoration\": \".wp-block-accordion-heading .wp-block-accordion-heading__toggle-title\"\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"openByDefault\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"title\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \".wp-block-accordion-heading__toggle-title\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"level\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"iconPosition\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [ \"left\", \"right\" ],\n\t\t\t\"default\": \"right\"\n\t\t},\n\t\t\"showIcon\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"textdomain\": \"default\"\n}\n\n\n// File: packages/block-library/src/accordion-heading/index.js\n/**\n * Internal dependencies\n */\nimport edit from './edit';\nimport save from './save';\nimport metadata from './block.json';\nimport initBlock from '../utils/init-block';\nimport icon from './icon';\nimport deprecated from './deprecated';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/accordion-heading/save.js\n/**\n * WordPress dependencies\n */\nimport {\n\tuseBlockProps,\n\t__experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles,\n\tRichText,\n\tgetTypographyClassesAndStyles,\n} from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { level, title, iconPosition, showIcon } = attributes;\n\tconst TagName = 'h' + ( level || 3 );\n\tconst typographyProps = getTypographyClassesAndStyles( attributes );\n\n\tconst blockProps = useBlockProps.save();\n\tconst spacingProps = getSpacingClassesAndStyles( attributes );\n\n\treturn (\n\t\t<TagName { ...blockProps }>\n\t\t\t<button\n\t\t\t\tclassName=\"wp-block-accordion-heading__toggle\"\n\t\t\t\tstyle={ spacingProps.style }\n\t\t\t>\n\t\t\t\t{ showIcon && iconPosition === 'left' && (\n\t\t\t\t\t<span\n\t\t\t\t\t\tclassName=\"wp-block-accordion-heading__toggle-icon\"\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t>\n\t\t\t\t\t\t+\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t\t<RichText.Content\n\t\t\t\t\tclassName=\"wp-block-accordion-heading__toggle-title\"\n\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tletterSpacing: typographyProps.style.letterSpacing,\n\t\t\t\t\t\ttextDecoration: typographyProps.style.textDecoration,\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t\t{ showIcon && iconPosition === 'right' && (\n\t\t\t\t\t<span\n\t\t\t\t\t\tclassName=\"wp-block-accordion-heading__toggle-icon\"\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t>\n\t\t\t\t\t\t+\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t</button>\n\t\t</TagName>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a WordPress block within the Gutenberg editor that enables checkout address input, featuring customizable class name and lock settings for flexible implementation."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-fields-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-fields-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Checkout Fields\",\n\t\"description\": \"Column containing checkout address fields.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-fields-block/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { Main } from '@woocommerce/base-components/sidebar-layout';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport type { TemplateArray } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { useCheckoutBlockContext } from '../../context';\nimport {\n\tuseForcedLayout,\n\tgetAllowedBlocks,\n} from '../../../cart-checkout-shared';\nimport './style.scss';\nimport { AddressFieldControls } from '../../address-field-controls';\n\nexport const Edit = ( {\n\tclientId,\n\tattributes,\n}: {\n\tclientId: string;\n\tattributes: {\n\t\tclassName?: string;\n\t\tisPreview?: boolean;\n\t};\n} ): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( 'wc-block-checkout__main', attributes?.className ),\n\t} );\n\tconst allowedBlocks = getAllowedBlocks( innerBlockAreas.CHECKOUT_FIELDS );\n\n\tconst { showFormStepNumbers } = useCheckoutBlockContext();\n\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/checkout-express-payment-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-contact-information-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-shipping-method-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-pickup-options-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-shipping-address-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-billing-address-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-shipping-methods-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-payment-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-additional-information-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-order-note-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-terms-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-actions-block', {}, [] ],\n\t].filter( Boolean ) as unknown as TemplateArray;\n\n\tuseForcedLayout( {\n\t\tclientId,\n\t\tregisteredBlocks: allowedBlocks,\n\t\tdefaultTemplate,\n\t} );\n\n\treturn (\n\t\t<Main { ...blockProps }>\n\t\t\t<AddressFieldControls />\n\t\t\t<form\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'wc-block-components-form wc-block-checkout__form',\n\t\t\t\t\t{\n\t\t\t\t\t\t'wc-block-checkout__form--with-step-numbers':\n\t\t\t\t\t\t\tshowFormStepNumbers,\n\t\t\t\t\t}\n\t\t\t\t) }\n\t\t\t>\n\t\t\t\t<InnerBlocks\n\t\t\t\t\tallowedBlocks={ allowedBlocks }\n\t\t\t\t\ttemplateLock={ false }\n\t\t\t\t\ttemplate={ defaultTemplate }\n\t\t\t\t\trenderAppender={ InnerBlocks.ButtonBlockAppender }\n\t\t\t\t/>\n\t\t\t</form>\n\t\t</Main>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Display a concise customer order overview block with configurable locking settings for user control."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-order-summary-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Order Summary\",\n\t\"description\": \"Show customers a summary of their order.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-totals-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport type { TemplateArray } from '@wordpress/blocks';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport { TotalsFooterItem } from '@woocommerce/base-components/cart-checkout';\nimport { getCurrencyFromPriceResponse } from '@woocommerce/price-format';\nimport { useStoreCart } from '@woocommerce/base-context/hooks';\nimport { __ } from '@wordpress/i18n';\nimport { useId, useState } from '@wordpress/element';\nimport { Icon } from '@wordpress/components';\nimport { chevronDown, chevronUp } from '@wordpress/icons';\nimport clsx from 'clsx';\nimport { FormattedMonetaryAmount } from '@woocommerce/blocks-components';\nimport { useContainerWidthContext } from '@woocommerce/base-context';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseForcedLayout,\n\tgetAllowedBlocks,\n} from '../../../cart-checkout-shared';\nimport { OrderMetaSlotFill } from './slotfills';\n\nexport const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst { cartTotals } = useStoreCart();\n\tconst totalsCurrency = getCurrencyFromPriceResponse( cartTotals );\n\tconst totalPrice = parseInt( cartTotals.total_price, 10 );\n\tconst allowedBlocks = getAllowedBlocks(\n\t\tinnerBlockAreas.CHECKOUT_ORDER_SUMMARY\n\t);\n\tconst { isLarge } = useContainerWidthContext();\n\tconst [ isOpen, setIsOpen ] = useState( false );\n\tconst ariaControlsId = useId();\n\n\tconst orderSummaryProps = ! isLarge\n\t\t? {\n\t\t\t\trole: 'button',\n\t\t\t\tonClick: () => setIsOpen( ! isOpen ),\n\t\t\t\t'aria-expanded': isOpen,\n\t\t\t\t'aria-controls': ariaControlsId,\n\t\t\t\ttabIndex: 0,\n\t\t\t\tonKeyDown: ( event: React.KeyboardEvent ) => {\n\t\t\t\t\tif ( event.key === 'Enter' || event.key === ' ' ) {\n\t\t\t\t\t\tsetIsOpen( ! isOpen );\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t }\n\t\t: {};\n\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/checkout-order-summary-cart-items-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-order-summary-coupon-form-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-order-summary-totals-block', {}, [] ],\n\t] as TemplateArray;\n\n\tuseForcedLayout( {\n\t\tclientId,\n\t\tregisteredBlocks: allowedBlocks,\n\t\tdefaultTemplate,\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<div\n\t\t\t\tclassName=\"wc-block-components-checkout-order-summary__title\"\n\t\t\t\t{ ...orderSummaryProps }\n\t\t\t>\n\t\t\t\t<p\n\t\t\t\t\tclassName=\"wc-block-components-checkout-order-summary__title-text\"\n\t\t\t\t\trole=\"heading\"\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Order summary', 'woocommerce' ) }\n\t\t\t\t</p>\n\t\t\t\t<FormattedMonetaryAmount\n\t\t\t\t\tcurrency={ totalsCurrency }\n\t\t\t\t\tvalue={ totalPrice }\n\t\t\t\t\tclassName=\"wc-block-components-checkout-order-summary__title-price\"\n\t\t\t\t/>\n\t\t\t\t<span className=\"wc-block-components-checkout-order-summary__title-icon\">\n\t\t\t\t\t<Icon icon={ isOpen ? chevronUp : chevronDown } />\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t\t<div\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'wc-block-components-checkout-order-summary__content',\n\t\t\t\t\t{\n\t\t\t\t\t\t'is-open': isOpen,\n\t\t\t\t\t}\n\t\t\t\t) }\n\t\t\t\tid={ ariaControlsId }\n\t\t\t>\n\t\t\t\t<InnerBlocks\n\t\t\t\t\tallowedBlocks={ allowedBlocks }\n\t\t\t\t\ttemplate={ defaultTemplate }\n\t\t\t\t/>\n\t\t\t\t<div className=\"wc-block-components-totals-wrapper\">\n\t\t\t\t\t<TotalsFooterItem\n\t\t\t\t\t\tcurrency={ totalsCurrency }\n\t\t\t\t\t\tvalues={ cartTotals }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t\t<OrderMetaSlotFill />\n\t\t\t</div>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a text block with customizable show content, summary, name, placeholder"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/details/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/details\",\n\t\"title\": \"Details\",\n\t\"category\": \"text\",\n\t\"description\": \"Hide and show additional content.\",\n\t\"keywords\": [ \"summary\", \"toggle\", \"disclosure\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"showContent\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"summary\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"summary\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"name\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"attribute\": \"name\",\n\t\t\t\"selector\": \".wp-block-details\"\n\t\t},\n\t\t\"placeholder\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"__experimentalOnEnter\": true,\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"anchor\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t},\n\t\t\"html\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"blockGap\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"layout\": {\n\t\t\t\"allowEditing\": false\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"allowedBlocks\": true\n\t},\n\t\"editorStyle\": \"wp-block-details-editor\",\n\t\"style\": \"wp-block-details\"\n}\n\n\n// File: packages/block-library/src/details/index.js\n/**\n * WordPress dependencies\n */\nimport { details as icon } from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tsummary: __( 'La Mancha' ),\n\t\t\tshowContent: true,\n\t\t},\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/paragraph',\n\t\t\t\tattributes: {\n\t\t\t\t\tcontent: __(\n\t\t\t\t\t\t'In a village of La Mancha, the name of which I have no desire to call to mind, there lived not long since one of those gentlemen that keep a lance in the lance-rack, an old buckler, a lean hack, and a greyhound for coursing.'\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst { summary } = attributes;\n\n\t\tconst customName = attributes?.metadata?.name;\n\t\tconst hasSummary = summary?.trim().length > 0;\n\n\t\t// In the list view, use the block's summary as the label.\n\t\t// If the summary is empty, fall back to the default label.\n\t\tif ( context === 'list-view' && ( customName || hasSummary ) ) {\n\t\t\treturn customName || summary;\n\t\t}\n\n\t\tif ( context === 'accessibility' ) {\n\t\t\treturn ! hasSummary\n\t\t\t\t? __( 'Details. Empty.' )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: %s: accessibility text; summary title. */\n\t\t\t\t\t\t__( 'Details. %s' ),\n\t\t\t\t\t\tsummary\n\t\t\t\t );\n\t\t}\n\t},\n\tsave,\n\tedit,\n\ttransforms,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'summary',\n\t\t\tlabel: __( 'Summary' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'summary' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/details/save.js\n/**\n * WordPress dependencies\n */\nimport { RichText, useBlockProps, InnerBlocks } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { name, showContent } = attributes;\n\tconst summary = attributes.summary ? attributes.summary : 'Details';\n\tconst blockProps = useBlockProps.save();\n\n\treturn (\n\t\t<details\n\t\t\t{ ...blockProps }\n\t\t\tname={ name || undefined }\n\t\t\topen={ showContent }\n\t\t>\n\t\t\t<summary>\n\t\t\t\t<RichText.Content value={ summary } />\n\t\t\t</summary>\n\t\t\t<InnerBlocks.Content />\n\t\t</details>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a WordPress theme block featuring flexible text configuration, including alignment, typography, labeling, and four additional customizable parameters."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/post-navigation-link/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-navigation-link\",\n\t\"title\": \"Post Navigation Link\",\n\t\"category\": \"theme\",\n\t\"description\": \"Displays the next or previous post link that is adjacent to the current post.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"type\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"next\"\n\t\t},\n\t\t\"label\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"showTitle\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"linkLabel\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"arrow\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"none\"\n\t\t},\n\t\t\"taxonomy\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postType\" ],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"link\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalWritingMode\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-post-navigation-link\"\n}\n\n\n// File: packages/block-library/src/post-navigation-link/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport variations from './variations';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\tedit,\n\tvariations,\n\texample: {\n\t\tattributes: {\n\t\t\tlabel: __( 'Next post' ),\n\t\t\tarrow: 'arrow',\n\t\t},\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a custom WordPress block enabling product filtering functionality with configurable preview settings for e-commerce page visitors."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-filters\",\n\t\"title\": \"Product Filters\",\n\t\"description\": \"Let shoppers filter products displayed on the page.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": true,\n\t\t\t\"heading\": true,\n\t\t\t\"enableContrastChecker\": false,\n\t\t\t\"button\": true\n\t\t},\n\t\t\"multiple\": true,\n\t\t\"inserter\": true,\n\t\t\"interactivity\": true,\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true\n\t\t},\n\t\t\"layout\": {\n\t\t\t\"default\": {\n\t\t\t\t\"type\": \"flex\",\n\t\t\t\t\"orientation\": \"vertical\",\n\t\t\t\t\"flexWrap\": \"nowrap\",\n\t\t\t\t\"justifyContent\": \"stretch\"\n\t\t\t},\n\t\t\t\"allowEditing\": false\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"blockGap\": true\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"usesContext\": [ \"postId\", \"query\", \"queryId\" ],\n\t\"attributes\": {\n\t\t\"isPreview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"isPreview\": true\n\t\t}\n\t},\n\t\"viewScriptModule\": \"woocommerce/product-filters\",\n\t\"style\": \"file:../woocommerce/product-filters-style.css\",\n\t\"editorStyle\": \"file:../woocommerce/product-filters-editor.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/edit.tsx\n/**\n * External dependencies\n */\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\nimport { BlockEditProps, InnerBlockTemplate } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, close } from '@wordpress/icons';\nimport { useState } from '@wordpress/element';\nimport { filterThreeLines } from '@woocommerce/icons';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\nimport { type BlockAttributes } from './types';\nimport { getProductFiltersCss } from './utils/get-product-filters-css';\n\nconst TEMPLATE: InnerBlockTemplate[] = [\n\t[\n\t\t'core/heading',\n\t\t{\n\t\t\tlevel: 2,\n\t\t\tcontent: __( 'Filters', 'woocommerce' ),\n\t\t\tstyle: {\n\t\t\t\tmargin: { top: '0', bottom: '0' },\n\t\t\t\tspacing: { margin: { top: '0', bottom: '0' } },\n\t\t\t},\n\t\t},\n\t],\n\t[ 'woocommerce/product-filter-active' ],\n\t[ 'woocommerce/product-filter-price' ],\n\t[ 'woocommerce/product-filter-rating' ],\n\t[ 'woocommerce/product-filter-attribute' ],\n\t[ 'woocommerce/product-filter-taxonomy' ],\n\t[ 'woocommerce/product-filter-status' ],\n];\n\nexport const Edit = ( props: BlockEditProps< BlockAttributes > ) => {\n\tconst { attributes } = props;\n\tconst { isPreview } = attributes;\n\tconst [ isOpen, setIsOpen ] = useState( false );\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( 'wc-block-product-filters', {\n\t\t\t'is-overlay-opened': isOpen,\n\t\t} ),\n\t\tstyle: getProductFiltersCss( attributes ),\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ isPreview ? (\n\t\t\t\t<div className=\"wc-block-product-filters__overlay-content\">\n\t\t\t\t\t<InnerBlocks templateLock={ false } template={ TEMPLATE } />\n\t\t\t\t</div>\n\t\t\t) : (\n\t\t\t\t<>\n\t\t\t\t\t<button\n\t\t\t\t\t\tclassName=\"wc-block-product-filters__open-overlay\"\n\t\t\t\t\t\tonClick={ () => setIsOpen( ! isOpen ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={ filterThreeLines } />\n\t\t\t\t\t\t<span>{ __( 'Filter products', 'woocommerce' ) }</span>\n\t\t\t\t\t</button>\n\n\t\t\t\t\t<div className=\"wc-block-product-filters__overlay\">\n\t\t\t\t\t\t<div className=\"wc-block-product-filters__overlay-wrapper\">\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tclassName=\"wc-block-product-filters__overlay-dialog\"\n\t\t\t\t\t\t\t\trole=\"dialog\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<header className=\"wc-block-product-filters__overlay-header\">\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tclassName=\"wc-block-product-filters__close-overlay\"\n\t\t\t\t\t\t\t\t\t\tonClick={ () => setIsOpen( ! isOpen ) }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Close', 'woocommerce' ) }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t\t<Icon icon={ close } />\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t</header>\n\t\t\t\t\t\t\t\t<div className=\"wc-block-product-filters__overlay-content\">\n\t\t\t\t\t\t\t\t\t<InnerBlocks\n\t\t\t\t\t\t\t\t\t\ttemplateLock={ false }\n\t\t\t\t\t\t\t\t\t\ttemplate={ TEMPLATE }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t<footer className=\"wc-block-product-filters__overlay-footer\">\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tclassName=\"wc-block-product-filters__apply wp-block-button__link wp-element-button\"\n\t\t\t\t\t\t\t\t\t\tonClick={ () => setIsOpen( ! isOpen ) }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Apply', 'woocommerce' ) }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t</footer>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</div>\n\t);\n};\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\nimport { type BlockAttributes } from './types';\nimport { getProductFiltersCss } from './utils/get-product-filters-css';\n\nexport const Save = ( {\n\tattributes,\n}: {\n\tattributes: BlockAttributes;\n\tstyle: Record< string, string >;\n} ): JSX.Element => {\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: clsx( 'wc-block-product-filters' ),\n\t\tstyle: getProductFiltersCss( attributes ),\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\treturn <div { ...innerBlocksProps } />;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Content before this block will be shown in the excerpt on your archives page. with these attributes: custom text, no teaser"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/more/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/more\",\n\t\"title\": \"More\",\n\t\"category\": \"design\",\n\t\"description\": \"Content before this block will be shown in the excerpt on your archives page.\",\n\t\"keywords\": [ \"read more\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"customText\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"noTeaser\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"customClassName\": false,\n\t\t\"className\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-more-editor\"\n}\n\n\n// File: packages/block-library/src/more/index.js\n/**\n * WordPress dependencies\n */\nimport { more as icon } from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst customName = attributes?.metadata?.name;\n\n\t\tif ( context === 'list-view' && customName ) {\n\t\t\treturn customName;\n\t\t}\n\n\t\tif ( context === 'accessibility' ) {\n\t\t\treturn attributes.customText;\n\t\t}\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'customText',\n\t\t\tlabel: __( 'Content' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'customText' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/more/save.js\n/**\n * WordPress dependencies\n */\nimport { RawHTML } from '@wordpress/element';\n\nexport default function save( { attributes: { customText, noTeaser } } ) {\n\tconst moreTag = customText ? `<!--more ${ customText }-->` : '<!--more-->';\n\n\tconst noTeaserTag = noTeaser ? '<!--noteaser-->' : '';\n\n\treturn (\n\t\t<RawHTML>\n\t\t\t{ [ moreTag, noTeaserTag ].filter( Boolean ).join( '\\n' ) }\n\t\t</RawHTML>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Gather blocks in a layout container. that allows users to configure: tag name, template lock"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/group/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/group\",\n\t\"title\": \"Group\",\n\t\"category\": \"design\",\n\t\"description\": \"Gather blocks in a layout container.\",\n\t\"keywords\": [ \"container\", \"wrapper\", \"row\", \"section\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"tagName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"div\"\n\t\t},\n\t\t\"templateLock\": {\n\t\t\t\"type\": [ \"string\", \"boolean\" ],\n\t\t\t\"enum\": [ \"all\", \"insert\", \"contentOnly\", false ]\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"__experimentalOnEnter\": true,\n\t\t\"__experimentalOnMerge\": true,\n\t\t\"__experimentalSettings\": true,\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"anchor\": true,\n\t\t\"ariaLabel\": true,\n\t\t\"html\": false,\n\t\t\"background\": {\n\t\t\t\"backgroundImage\": true,\n\t\t\t\"backgroundSize\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"backgroundImage\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"heading\": true,\n\t\t\t\"button\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"shadow\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"padding\": true,\n\t\t\t\"blockGap\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true,\n\t\t\t\t\"blockGap\": true\n\t\t\t}\n\t\t},\n\t\t\"dimensions\": {\n\t\t\t\"minHeight\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"position\": {\n\t\t\t\"sticky\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"layout\": {\n\t\t\t\"allowSizingOnChildren\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"allowedBlocks\": true\n\t},\n\t\"editorStyle\": \"wp-block-group-editor\",\n\t\"style\": \"wp-block-group\"\n}\n\n\n// File: packages/block-library/src/group/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { group as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport variations from './variations';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tlayout: {\n\t\t\t\ttype: 'constrained',\n\t\t\t\tjustifyContent: 'center',\n\t\t\t},\n\t\t\tstyle: {\n\t\t\t\tspacing: {\n\t\t\t\t\tpadding: {\n\t\t\t\t\t\ttop: '4em',\n\t\t\t\t\t\tright: '3em',\n\t\t\t\t\t\tbottom: '4em',\n\t\t\t\t\t\tleft: '3em',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/heading',\n\t\t\t\tattributes: {\n\t\t\t\t\tcontent: __( 'La Mancha' ),\n\t\t\t\t\ttextAlign: 'center',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/paragraph',\n\t\t\t\tattributes: {\n\t\t\t\t\talign: 'center',\n\t\t\t\t\tcontent: __(\n\t\t\t\t\t\t'In a village of La Mancha, the name of which I have no desire to call to mind, there lived not long since one of those gentlemen that keep a lance in the lance-rack, an old buckler, a lean hack, and a greyhound for coursing.'\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/spacer',\n\t\t\t\tattributes: {\n\t\t\t\t\theight: '10px',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/button',\n\t\t\t\tattributes: {\n\t\t\t\t\ttext: __( 'Read more' ),\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tviewportWidth: 600,\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tdeprecated,\n\tvariations,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/group/save.js\n/**\n * WordPress dependencies\n */\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes: { tagName: Tag } } ) {\n\treturn <Tag { ...useInnerBlocksProps.save( useBlockProps.save() ) } />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a Gutenberg block representing a singular list item, incorporating placeholder and content attributes for dynamic customization."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/list-item/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/list-item\",\n\t\"title\": \"List Item\",\n\t\"category\": \"text\",\n\t\"parent\": [ \"core/list\" ],\n\t\"allowedBlocks\": [ \"core/list\" ],\n\t\"description\": \"An individual item within a list.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"placeholder\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"content\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"li\",\n\t\t\t\"role\": \"content\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"className\": false,\n\t\t\"splitting\": true,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"background\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"selectors\": {\n\t\t\"root\": \".wp-block-list > li\",\n\t\t\"border\": \".wp-block-list:not(.wp-block-list .wp-block-list) > li\"\n\t}\n}\n\n\n// File: packages/block-library/src/list-item/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { listItem as icon } from '@wordpress/icons';\nimport { privateApis } from '@wordpress/block-editor';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\t...attributes,\n\t\t\tcontent: attributes.content + attributesToMerge.content,\n\t\t};\n\t},\n\ttransforms,\n\t[ unlock( privateApis ).requiresWrapperOnCopy ]: true,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'content',\n\t\t\tlabel: __( 'Content' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'content' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/list-item/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\treturn (\n\t\t<li { ...useBlockProps.save() }>\n\t\t\t<RichText.Content value={ attributes.content } />\n\t\t\t<InnerBlocks.Content />\n\t\t</li>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a custom Gutenberg block featuring an interactive checkout interface that allows customers to place orders, with options to toggle preview, adjust alignment, and display sequential form step indicators."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/block.json\n{\n\t\"name\": \"woocommerce/checkout\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Checkout\",\n\t\"description\": \"Display a checkout form so your customers can submit orders.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [\n\t\t\"WooCommerce\"\n\t],\n\t\"supports\": {\n\t\t\"align\": [\n\t\t\t\"wide\"\n\t\t],\n\t\t\"html\": false,\n\t\t\"multiple\": false\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"isPreview\": true\n\t\t},\n\t\t\"viewportWidth\": 800\n\t},\n\t\"attributes\": {\n\t\t\"isPreview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false,\n\t\t\t\"save\": false\n\t\t},\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"wide\"\n\t\t},\n\t\t\"showFormStepNumbers\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport {\n\tInnerBlocks,\n\tuseBlockProps,\n\tInspectorControls,\n} from '@wordpress/block-editor';\nimport { SidebarLayout } from '@woocommerce/base-components/sidebar-layout';\nimport { CheckoutProvider, EditorProvider } from '@woocommerce/base-context';\nimport {\n\tpreviewCart,\n\tpreviewSavedPaymentMethods,\n} from '@woocommerce/resource-previews';\nimport { SlotFillProvider } from '@woocommerce/blocks-checkout';\nimport type { TemplateArray } from '@wordpress/blocks';\nimport { useEffect, useRef } from '@wordpress/element';\nimport { getQueryArg } from '@wordpress/url';\nimport { dispatch, select as selectData, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { defaultFields as defaultFieldsSetting } from '@woocommerce/settings';\n\n/**\n * Internal dependencies\n */\nimport './inner-blocks';\nimport './styles/editor.scss';\nimport {\n\taddClassToBody,\n\tBlockSettings,\n\tuseBlockPropsWithLocking,\n} from '../cart-checkout-shared';\nimport '../cart-checkout-shared/sidebar-notices';\nimport { CheckoutBlockContext } from './context';\nimport type { Attributes } from './types';\n\n// This is adds a class to body to signal if the selected block is locked\naddClassToBody();\n\n// Array of allowed block names.\nconst ALLOWED_BLOCKS: string[] = [\n\t'woocommerce/checkout-fields-block',\n\t'woocommerce/checkout-totals-block',\n];\n\nexport const Edit = ( {\n\tclientId,\n\tattributes,\n\tsetAttributes,\n}: {\n\tclientId: string;\n\tattributes: Attributes;\n\tsetAttributes: ( attributes: Record< string, unknown > ) => undefined;\n} ): JSX.Element => {\n\tconst {\n\t\tshowOrderNotes,\n\t\tshowPolicyLinks,\n\t\tshowReturnToCart,\n\t\tshowRateAfterTaxName,\n\t\tcartPageId,\n\t\tisPreview = false,\n\t\tshowFormStepNumbers = false,\n\t\thasDarkControls = false,\n\t} = attributes;\n\n\tconst fieldSettings = useSelect( ( select ) => {\n\t\treturn select(\n\t\t\tcoreStore as unknown as string\n\t\t\t// @ts-expect-error getEditedEntityRecord is not typed in @wordpress/core-data yet.\n\t\t).getEditedEntityRecord( 'root', 'site' ) as Record< string, string >;\n\t}, [] );\n\n\tconst fieldsWithDefaults = {\n\t\tphone: 'optional',\n\t\tcompany: 'hidden',\n\t\taddress_2: 'optional',\n\t} as const;\n\n\tconst defaultFields = {\n\t\t...defaultFieldsSetting,\n\t\t...Object.fromEntries(\n\t\t\tObject.entries( fieldsWithDefaults ).map(\n\t\t\t\t( [ field, defaultValue ] ) => {\n\t\t\t\t\tconst value =\n\t\t\t\t\t\tfieldSettings[\n\t\t\t\t\t\t\t`woocommerce_checkout_${ field }_field`\n\t\t\t\t\t\t] || defaultValue;\n\t\t\t\t\treturn [\n\t\t\t\t\t\tfield,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...defaultFieldsSetting[\n\t\t\t\t\t\t\t\tfield as keyof typeof defaultFieldsSetting\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\trequired: value === 'required',\n\t\t\t\t\t\t\thidden: value === 'hidden',\n\t\t\t\t\t\t},\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t)\n\t\t),\n\t};\n\n\t// This focuses on the block when a certain query param is found. This is used on the link from the task list.\n\tconst focus = useRef( getQueryArg( window.location.href, 'focus' ) );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\tfocus.current === 'checkout' &&\n\t\t\t! selectData( 'core/block-editor' ).hasSelectedBlock()\n\t\t) {\n\t\t\tdispatch( 'core/block-editor' ).selectBlock( clientId );\n\t\t\tdispatch( 'core/interface' ).enableComplementaryArea(\n\t\t\t\t'core/edit-site',\n\t\t\t\t'edit-site/block-inspector'\n\t\t\t);\n\t\t}\n\t}, [ clientId ] );\n\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/checkout-totals-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-fields-block', {}, [] ],\n\t] as TemplateArray;\n\n\tconst blockProps = useBlockPropsWithLocking();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls>\n\t\t\t\t<BlockSettings\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<EditorProvider\n\t\t\t\tisPreview={ !! isPreview }\n\t\t\t\tpreviewData={ {\n\t\t\t\t\tpreviewCart,\n\t\t\t\t\tpreviewSavedPaymentMethods,\n\t\t\t\t\tdefaultFields,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<SlotFillProvider>\n\t\t\t\t\t<CheckoutProvider>\n\t\t\t\t\t\t<SidebarLayout\n\t\t\t\t\t\t\tclassName={ clsx( 'wc-block-checkout', {\n\t\t\t\t\t\t\t\t'has-dark-controls': hasDarkControls,\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<CheckoutBlockContext.Provider\n\t\t\t\t\t\t\t\tvalue={ {\n\t\t\t\t\t\t\t\t\tshowOrderNotes,\n\t\t\t\t\t\t\t\t\tshowPolicyLinks,\n\t\t\t\t\t\t\t\t\tshowReturnToCart,\n\t\t\t\t\t\t\t\t\tcartPageId,\n\t\t\t\t\t\t\t\t\tshowRateAfterTaxName,\n\t\t\t\t\t\t\t\t\tshowFormStepNumbers,\n\t\t\t\t\t\t\t\t\tdefaultFields,\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<InnerBlocks\n\t\t\t\t\t\t\t\t\tallowedBlocks={ ALLOWED_BLOCKS }\n\t\t\t\t\t\t\t\t\ttemplate={ defaultTemplate }\n\t\t\t\t\t\t\t\t\ttemplateLock=\"insert\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</CheckoutBlockContext.Provider>\n\t\t\t\t\t\t</SidebarLayout>\n\t\t\t\t\t</CheckoutProvider>\n\t\t\t\t</SlotFillProvider>\n\t\t\t</EditorProvider>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div\n\t\t\t{ ...useBlockProps.save( {\n\t\t\t\tclassName: 'wc-block-checkout is-loading',\n\t\t\t} ) }\n\t\t>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Display the order confirmation shipping address. that allows users to configure: align"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/shipping-address/block.json\n{\n\t\"name\": \"woocommerce/order-confirmation-shipping-address\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Shipping Address\",\n\t\"description\": \"Display the order confirmation shipping address.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [\n\t\t\"WooCommerce\"\n\t],\n\t\"supports\": {\n\t\t\"multiple\": false,\n\t\t\"align\": [\n\t\t\t\"wide\",\n\t\t\t\"full\"\n\t\t],\n\t\t\"inserter\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"width\": true,\n\t\t\t\t\"color\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"wide\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/shipping-address/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { AdditionalFieldsPlaceholder } from '@woocommerce/base-components/cart-checkout';\nimport { ADDRESS_FORM_FIELDS } from '@woocommerce/block-settings';\n\n/**\n * Internal dependencies\n */\nimport './style.scss';\n\nconst Edit = (): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wc-block-order-confirmation-shipping-address',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<address>\n\t\t\t\tTest address 1<br />\n\t\t\t\tTest address 2<br />\n\t\t\t\tSan Francisco, CA 94110\n\t\t\t\t<br />\n\t\t\t\tUnited States\n\t\t\t\t<AdditionalFieldsPlaceholder\n\t\t\t\t\tadditionalFields={ ADDRESS_FORM_FIELDS }\n\t\t\t\t/>\n\t\t\t</address>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a new Gutenberg block specifically designed to render the cart discount row, implementing a class name and lock feature to support precise customization."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/block.json\n{\n\t\"name\": \"woocommerce/checkout-order-summary-discount-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Discount\",\n\t\"description\": \"Shows the cart discount row.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-order-summary-totals-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\n\nexport const Edit = ( {\n\tattributes,\n}: {\n\tattributes: {\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst { className } = attributes;\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Block className={ className } />\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Design a purpose-built WordPress block that facilitates product sales, service offerings, and donation collection through an integrated on-page solution."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/payments-intro/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/payments-intro\",\n\t\"title\": \"Payments\",\n\t\"description\": \"Sell products and services or receive donations on your website.\",\n\t\"keywords\": [ \"earn\", \"monetize\", \"paid\", \"pay\", \"money\", \"checkout\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"monetize\",\n\t\"icon\": \"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'><path d='M3.25 12a8.75 8.75 0 1117.5 0 8.75 8.75 0 01-17.5 0zM12 4.75a7.25 7.25 0 100 14.5 7.25 7.25 0 000-14.5zm-1.338 4.877c-.314.22-.412.452-.412.623 0 .171.098.403.412.623.312.218.783.377 1.338.377.825 0 1.605.233 2.198.648.59.414 1.052 1.057 1.052 1.852 0 .795-.461 1.438-1.052 1.852-.41.286-.907.486-1.448.582v.316a.75.75 0 01-1.5 0v-.316a3.64 3.64 0 01-1.448-.582c-.59-.414-1.052-1.057-1.052-1.852a.75.75 0 011.5 0c0 .171.098.403.412.623.312.218.783.377 1.338.377s1.026-.159 1.338-.377c.314-.22.412-.452.412-.623 0-.171-.098-.403-.412-.623-.312-.218-.783-.377-1.338-.377-.825 0-1.605-.233-2.198-.648-.59-.414-1.052-1.057-1.052-1.852 0-.795.461-1.438 1.052-1.852a3.64 3.64 0 011.448-.582V7.5a.75.75 0 011.5 0v.316c.54.096 1.039.296 1.448.582.59.414 1.052 1.057 1.052 1.852a.75.75 0 01-1.5 0c0-.171-.098-.403-.412-.623-.312-.218-.783-.377-1.338-.377s-1.026.159-1.338.377z'></path></svg>\",\n\t\"supports\": {\n\t\t\"alignWide\": false,\n\t\t\"className\": true,\n\t\t\"customClassName\": false,\n\t\t\"html\": false,\n\t\t\"reusable\": false\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/payments-intro/edit.js\nimport { InnerBlocks, store as blockEditorStore, useBlockProps } from '@wordpress/block-editor';\nimport { cloneBlock, createBlock, getBlockType, registerBlockVariation } from '@wordpress/blocks';\nimport { Placeholder } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useEffect, useCallback } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport ConnectBanner from '../../shared/components/connect-banner';\nimport useIsUserConnected from '../../shared/use-is-user-connected';\nimport PaymentsIntroBlockPicker from './block-picker';\nimport PaymentsIntroPatternPicker from './pattern-picker';\nimport defaultVariations from './variations';\n\nexport default function JetpackPaymentsIntroEdit( { name, clientId } ) {\n\tconst patternFilter = pattern => pattern.categories?.includes( 'shop' );\n\n\tconst blockProps = useBlockProps();\n\tconst { blockType, hasInnerBlocks, hasPatterns, settings } = useSelect( select => {\n\t\tconst { getBlocks, __experimentalGetAllowedPatterns, getSettings } = select( blockEditorStore );\n\n\t\treturn {\n\t\t\tsettings: getSettings(),\n\t\t\tblockType: getBlockType( name ),\n\t\t\thasInnerBlocks: getBlocks( clientId )?.length > 0,\n\t\t\thasPatterns: __experimentalGetAllowedPatterns?.().filter( patternFilter ).length > 0,\n\t\t};\n\t} );\n\n\tconst isUserConnected = useIsUserConnected();\n\n\tconst { replaceBlock, selectBlock, updateSettings } = useDispatch( blockEditorStore );\n\n\tconst maybeMakeBlockVisible = useCallback(\n\t\tblockName => {\n\t\t\tconst isBlockAllowed =\n\t\t\t\tsettings?.allowedBlockTypes === true || settings?.allowedBlockTypes?.includes( blockName );\n\t\t\tif ( ! isBlockAllowed ) {\n\t\t\t\t// Add the block to the allowed block list before rendering\n\t\t\t\tupdateSettings( {\n\t\t\t\t\t...settings,\n\t\t\t\t\tallowedBlockTypes: [ ...settings.allowedBlockTypes, blockName ],\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ settings, updateSettings ]\n\t);\n\n\tconst setVariation = variation => {\n\t\tconst blockName = variation.name;\n\n\t\tmaybeMakeBlockVisible( blockName );\n\t\treplaceBlock( clientId, createBlock( blockName ) );\n\t\tselectBlock( clientId );\n\t};\n\n\tconst usableVariations = defaultVariations.filter( variation => getBlockType( variation.name ) );\n\n\tuseEffect( () => {\n\t\t// Populate default variation on older versions of WP or GB that don't support variations.\n\t\tif ( ! hasInnerBlocks && ! registerBlockVariation ) {\n\t\t\tsetVariation( usableVariations[ 0 ] );\n\t\t}\n\t} );\n\n\tconst displayVariations = usableVariations.length && registerBlockVariation;\n\n\tlet instructions = __( \"Please select which kind of payment you'd like to add.\", 'jetpack' );\n\tif ( hasPatterns ) {\n\t\tinstructions = __( 'Start by choosing one of our suggested layout patterns.', 'jetpack' );\n\t}\n\n\tlet content;\n\n\tif ( ! isUserConnected ) {\n\t\tcontent = (\n\t\t\t<ConnectBanner\n\t\t\t\tblock=\"Payments\"\n\t\t\t\texplanation={ __(\n\t\t\t\t\t'Connect your WordPress.com account to start using payments blocks.',\n\t\t\t\t\t'jetpack'\n\t\t\t\t) }\n\t\t\t/>\n\t\t);\n\t} else if ( ! hasInnerBlocks && displayVariations ) {\n\t\tcontent = (\n\t\t\t<Placeholder\n\t\t\t\ticon={ blockType?.icon?.src }\n\t\t\t\tlabel={ blockType?.title }\n\t\t\t\tinstructions={ instructions }\n\t\t\t>\n\t\t\t\t{ hasPatterns && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<PaymentsIntroPatternPicker\n\t\t\t\t\t\t\tonBlockPatternSelect={ blocks => replaceBlock( clientId, blocks.map( cloneBlock ) ) }\n\t\t\t\t\t\t\tpatternFilter={ patternFilter }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<p>{ __( 'Or use one of our blocks to create your own.', 'jetpack' ) }</p>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t\t<PaymentsIntroBlockPicker\n\t\t\t\t\tlabel={ __( 'Payment Block list', 'jetpack' ) }\n\t\t\t\t\tvariations={ usableVariations }\n\t\t\t\t\tonSelect={ ( nextVariation = usableVariations[ 0 ] ) => {\n\t\t\t\t\t\tsetVariation( nextVariation );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</Placeholder>\n\t\t);\n\t} else {\n\t\tcontent = <InnerBlocks />;\n\t}\n\n\treturn <div { ...blockProps }>{ content }</div>;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Displays additional information provided by third-party extensions for the current order. that allows users to configure: align, class name"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/additional-information/block.json\n{\n\t\"name\": \"woocommerce/order-confirmation-additional-information\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Additional Information\",\n\t\"description\": \"Displays additional information provided by third-party extensions for the current order.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [\n\t\t\"WooCommerce\"\n\t],\n\t\"supports\": {\n\t\t\"multiple\": false,\n\t\t\"align\": [\n\t\t\t\"wide\",\n\t\t\t\"full\"\n\t\t],\n\t\t\"html\": false,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"width\": true,\n\t\t\t\t\"color\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"wide\"\n\t\t},\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/additional-information/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport './style.scss';\n\nconst Edit = (): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wc-block-order-confirmation-additional-information',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<div className=\"wc-block-order-confirmation-additional-information-placeholder\">\n\t\t\t\t{ __( 'Additional Information for your order', 'woocommerce' ) }\n\t\t\t</div>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Construct a versatile, modifiable block featuring a configurable reference and adaptable content for flexible implementation."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/block/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/block\",\n\t\"title\": \"Pattern\",\n\t\"category\": \"reusable\",\n\t\"description\": \"Reuse this design across your site.\",\n\t\"keywords\": [ \"reusable\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"ref\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"content\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {}\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"pattern/overrides\": \"content\"\n\t},\n\t\"supports\": {\n\t\t\"customClassName\": false,\n\t\t\"html\": false,\n\t\t\"inserter\": false,\n\t\t\"renaming\": false,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t}\n}\n\n\n// File: packages/block-library/src/block/index.js\n/**\n * WordPress dependencies\n */\nimport { symbol as icon } from '@wordpress/icons';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { select } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport deprecated from './deprecated';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\tdeprecated,\n\tedit,\n\ticon,\n\t__experimentalLabel: ( { ref } ) => {\n\t\tif ( ! ref ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst entity = select( coreStore ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\t'wp_block',\n\t\t\tref\n\t\t);\n\t\tif ( ! entity?.title ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn decodeEntities( entity.title );\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Display multiple images in a rich gallery. that allows users to configure: images, ids, short code transforms, and 10 more options"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/gallery/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/gallery\",\n\t\"title\": \"Gallery\",\n\t\"category\": \"media\",\n\t\"allowedBlocks\": [ \"core/image\" ],\n\t\"description\": \"Display multiple images in a rich gallery.\",\n\t\"keywords\": [ \"images\", \"photos\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"images\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": [],\n\t\t\t\"source\": \"query\",\n\t\t\t\"selector\": \".blocks-gallery-item\",\n\t\t\t\"query\": {\n\t\t\t\t\"url\": {\n\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\"selector\": \"img\",\n\t\t\t\t\t\"attribute\": \"src\"\n\t\t\t\t},\n\t\t\t\t\"fullUrl\": {\n\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\"selector\": \"img\",\n\t\t\t\t\t\"attribute\": \"data-full-url\"\n\t\t\t\t},\n\t\t\t\t\"link\": {\n\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\"selector\": \"img\",\n\t\t\t\t\t\"attribute\": \"data-link\"\n\t\t\t\t},\n\t\t\t\t\"alt\": {\n\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\"selector\": \"img\",\n\t\t\t\t\t\"attribute\": \"alt\",\n\t\t\t\t\t\"default\": \"\"\n\t\t\t\t},\n\t\t\t\t\"id\": {\n\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\"selector\": \"img\",\n\t\t\t\t\t\"attribute\": \"data-id\"\n\t\t\t\t},\n\t\t\t\t\"caption\": {\n\t\t\t\t\t\"type\": \"rich-text\",\n\t\t\t\t\t\"source\": \"rich-text\",\n\t\t\t\t\t\"selector\": \".blocks-gallery-item__caption\"\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t\"ids\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"number\"\n\t\t\t},\n\t\t\t\"default\": []\n\t\t},\n\t\t\"shortCodeTransforms\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"object\"\n\t\t\t},\n\t\t\t\"default\": []\n\t\t},\n\t\t\"columns\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"minimum\": 1,\n\t\t\t\"maximum\": 8\n\t\t},\n\t\t\"caption\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \".blocks-gallery-caption\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"imageCrop\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"randomOrder\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"fixedHeight\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"linkTo\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"sizeSlug\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"large\"\n\t\t},\n\t\t\"allowResize\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"aspectRatio\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"auto\"\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"allowResize\": \"allowResize\",\n\t\t\"imageCrop\": \"imageCrop\",\n\t\t\"fixedHeight\": \"fixedHeight\"\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"align\": true,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true\n\t\t\t}\n\t\t},\n\t\t\"html\": false,\n\t\t\"units\": [ \"px\", \"em\", \"rem\", \"vh\", \"vw\" ],\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"blockGap\": [ \"horizontal\", \"vertical\" ],\n\t\t\t\"__experimentalSkipSerialization\": [ \"blockGap\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"blockGap\": true,\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"text\": false,\n\t\t\t\"background\": true,\n\t\t\t\"gradients\": true\n\t\t},\n\t\t\"layout\": {\n\t\t\t\"allowSwitching\": false,\n\t\t\t\"allowInheriting\": false,\n\t\t\t\"allowEditing\": false,\n\t\t\t\"default\": {\n\t\t\t\t\"type\": \"flex\"\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-gallery-editor\",\n\t\"style\": \"wp-block-gallery\"\n}\n\n\n// File: packages/block-library/src/gallery/index.js\n/**\n * WordPress dependencies\n */\nimport { gallery as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tcolumns: 2,\n\t\t},\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/image',\n\t\t\t\tattributes: {\n\t\t\t\t\turl: 'https://s.w.org/images/core/5.3/Glacial_lakes%2C_Bhutan.jpg',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/image',\n\t\t\t\tattributes: {\n\t\t\t\t\turl: 'https://s.w.org/images/core/5.3/Sediment_off_the_Yucatan_Peninsula.jpg',\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/gallery/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tRichText,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\t__experimentalGetElementClassName,\n} from '@wordpress/block-editor';\n\nexport default function saveWithInnerBlocks( { attributes } ) {\n\tconst { caption, columns, imageCrop } = attributes;\n\n\tconst className = clsx( 'has-nested-images', {\n\t\t[ `columns-${ columns }` ]: columns !== undefined,\n\t\t[ `columns-default` ]: columns === undefined,\n\t\t'is-cropped': imageCrop,\n\t} );\n\tconst blockProps = useBlockProps.save( { className } );\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\n\treturn (\n\t\t<figure { ...innerBlocksProps }>\n\t\t\t{ innerBlocksProps.children }\n\t\t\t{ ! RichText.isEmpty( caption ) && (\n\t\t\t\t<RichText.Content\n\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t'blocks-gallery-caption',\n\t\t\t\t\t\t__experimentalGetElementClassName( 'caption' )\n\t\t\t\t\t) }\n\t\t\t\t\tvalue={ caption }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</figure>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a bespoke Gutenberg block to display taxonomy term details, encompassing key elements such as term name, description, and additional attributes."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/term-template/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/term-template\",\n\t\"title\": \"Term Template\",\n\t\"category\": \"theme\",\n\t\"ancestor\": [ \"core/terms-query\" ],\n\t\"description\": \"Contains the block elements used to render a taxonomy term, like the name, description, and more.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"termQuery\" ],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"layout\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"blockGap\": {\n\t\t\t\t\"__experimentalDefault\": \"1.25em\"\n\t\t\t},\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"blockGap\": true,\n\t\t\t\t\"padding\": false,\n\t\t\t\t\"margin\": false\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-term-template\",\n\t\"editorStyle\": \"wp-block-term-template-editor\"\n}\n\n\n// File: packages/block-library/src/term-template/index.js\n/**\n * WordPress dependencies\n */\nimport { layout as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n\texample: {},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/term-template/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function TermTemplateSave() {\n\treturn <InnerBlocks.Content />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Shows the apply coupon form. with these attributes: class name, lock"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-coupon-form/block.json\n{\n\t\"name\": \"woocommerce/cart-order-summary-coupon-form-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Coupon Form\",\n\t\"description\": \"Shows the apply coupon form.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": false,\n\t\t\t\t\"move\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/cart-order-summary-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-coupon-form/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport Noninteractive from '@woocommerce/base-components/noninteractive';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\n\nexport const Edit = ( {\n\tattributes,\n}: {\n\tattributes: {\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst { className } = attributes;\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Noninteractive>\n\t\t\t\t<Block className={ className } />\n\t\t\t</Noninteractive>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a block that Contains the block elements used to render a post, like the title, date, featured image, content or excerpt, and more."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/post-template/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-template\",\n\t\"title\": \"Post Template\",\n\t\"category\": \"theme\",\n\t\"ancestor\": [ \"core/query\" ],\n\t\"description\": \"Contains the block elements used to render a post, like the title, date, featured image, content or excerpt, and more.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [\n\t\t\"queryId\",\n\t\t\"query\",\n\t\t\"displayLayout\",\n\t\t\"templateSlug\",\n\t\t\"previewPostType\",\n\t\t\"enhancedPagination\",\n\t\t\"postType\"\n\t],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"layout\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"blockGap\": {\n\t\t\t\t\"__experimentalDefault\": \"1.25em\"\n\t\t\t},\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"blockGap\": true,\n\t\t\t\t\"padding\": false,\n\t\t\t\t\"margin\": false\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-post-template\",\n\t\"editorStyle\": \"wp-block-post-template-editor\"\n}\n\n\n// File: packages/block-library/src/post-template/index.js\n/**\n * WordPress dependencies\n */\nimport { layout } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon: layout,\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/post-template/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function PostTemplateSave() {\n\treturn <InnerBlocks.Content />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a WordPress block that renders comment text with configurable alignment options within the Gutenberg editor."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/comment-content/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/comment-content\",\n\t\"title\": \"Comment Content\",\n\t\"category\": \"theme\",\n\t\"ancestor\": [ \"core/comment-template\" ],\n\t\"description\": \"Displays the contents of a comment.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"commentId\" ],\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": [ \"horizontal\", \"vertical\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true\n\t\t\t}\n\t\t},\n\t\t\"html\": false\n\t},\n\t\"style\": \"wp-block-comment-content\"\n}\n\n\n// File: packages/block-library/src/comment-content/index.js\n/**\n * WordPress dependencies\n */\nimport { commentContent as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\texample: {},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Displays a paginated navigation to next/previous set of comments, when applicable. with these attributes: pagination arrow"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/comments-pagination/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/comments-pagination\",\n\t\"title\": \"Comments Pagination\",\n\t\"category\": \"theme\",\n\t\"parent\": [ \"core/comments\" ],\n\t\"allowedBlocks\": [\n\t\t\"core/comments-pagination-previous\",\n\t\t\"core/comments-pagination-numbers\",\n\t\t\"core/comments-pagination-next\"\n\t],\n\t\"description\": \"Displays a paginated navigation to next/previous set of comments, when applicable.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"paginationArrow\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"none\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"paginationArrow\": \"none\"\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"comments/paginationArrow\": \"paginationArrow\"\n\t},\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"layout\": {\n\t\t\t\"allowSwitching\": false,\n\t\t\t\"allowInheriting\": false,\n\t\t\t\"default\": {\n\t\t\t\t\"type\": \"flex\"\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-comments-pagination-editor\",\n\t\"style\": \"wp-block-comments-pagination\"\n}\n\n\n// File: packages/block-library/src/comments-pagination/index.js\n/**\n * WordPress dependencies\n */\nimport { queryPagination as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/comments-pagination/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function save() {\n\treturn <InnerBlocks.Content />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Shows the cart shipping row. with these attributes: lock"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/block.json\n{\n\t\"name\": \"woocommerce/cart-order-summary-shipping-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Shipping\",\n\t\"description\": \"Shows the cart shipping row.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/cart-order-summary-totals-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport { PanelBody, ExternalLink } from '@wordpress/components';\nimport { ADMIN_URL } from '@woocommerce/settings';\nimport Noninteractive from '@woocommerce/base-components/noninteractive';\nimport { SHIPPING_ENABLED } from '@woocommerce/block-settings';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\n\nexport const Edit = ( {\n\tattributes,\n}: {\n\tattributes: {\n\t\tclassName: string;\n\t\tlock: {\n\t\t\tmove: boolean;\n\t\t\tremove: boolean;\n\t\t};\n\t};\n} ): JSX.Element => {\n\tconst { className } = attributes;\n\tconst blockProps = useBlockProps();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls>\n\t\t\t\t{ !! SHIPPING_ENABLED && (\n\t\t\t\t\t<PanelBody\n\t\t\t\t\t\ttitle={ __( 'Shipping Calculations', 'woocommerce' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<p className=\"wc-block-checkout__controls-text\">\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Options that control shipping can be managed in your store settings.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping§ion=options` }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Manage shipping options', 'woocommerce' ) }\n\t\t\t\t\t\t</ExternalLink>{ ' ' }\n\t\t\t\t\t</PanelBody>\n\t\t\t\t) }\n\t\t\t</InspectorControls>\n\t\t\t<Noninteractive>\n\t\t\t\t<Block className={ className } />\n\t\t\t</Noninteractive>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a Gutenberg block designed to reveal specific content elements when items are present in the shopping cart, incorporating a lock attribute for controlled visibility."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/filled-cart-block/block.json\n{\n\t\"name\": \"woocommerce/filled-cart-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Filled Cart\",\n\t\"description\": \"Contains blocks that are displayed when the cart contains products.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": [\n\t\t\t\"wide\"\n\t\t],\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/cart\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/filled-cart-block/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport { SidebarLayout } from '@woocommerce/base-components/sidebar-layout';\nimport type { TemplateArray } from '@wordpress/blocks';\nimport { useEditorContext } from '@woocommerce/base-context';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseForcedLayout,\n\tgetAllowedBlocks,\n} from '../../../cart-checkout-shared';\nimport './editor.scss';\nimport { useCartBlockContext } from '../../context';\n\nexport const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst { currentView } = useEditorContext();\n\tconst { hasDarkControls } = useCartBlockContext();\n\tconst allowedBlocks = getAllowedBlocks( innerBlockAreas.FILLED_CART );\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/cart-items-block', {}, [] ],\n\t\t[ 'woocommerce/cart-totals-block', {}, [] ],\n\t] as TemplateArray;\n\n\tuseForcedLayout( {\n\t\tclientId,\n\t\tregisteredBlocks: allowedBlocks,\n\t\tdefaultTemplate,\n\t} );\n\treturn (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\thidden={ currentView !== 'woocommerce/filled-cart-block' }\n\t\t>\n\t\t\t<SidebarLayout\n\t\t\t\tclassName={ clsx( 'wc-block-cart', {\n\t\t\t\t\t'has-dark-controls': hasDarkControls,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<InnerBlocks\n\t\t\t\t\tallowedBlocks={ allowedBlocks }\n\t\t\t\t\ttemplate={ defaultTemplate }\n\t\t\t\t\ttemplateLock=\"insert\"\n\t\t\t\t/>\n\t\t\t</SidebarLayout>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Display a custom date. that allows users to configure: datetime, text align, format, is link"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/post-date/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-date\",\n\t\"title\": \"Date\",\n\t\"category\": \"theme\",\n\t\"description\": \"Display a custom date.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"datetime\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"format\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"isLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false,\n\t\t\t\"role\": \"content\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\", \"queryId\" ],\n\t\"example\": {\n\t\t\"viewportWidth\": 350\n\t},\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t}\n}\n\n\n// File: packages/block-library/src/post-date/index.js\n/**\n * WordPress dependencies\n */\nimport { postDate as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport deprecated from './deprecated';\nimport variations from './variations';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tdeprecated,\n\tvariations,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Collect one-time, monthly, or annually recurring donations. that allows users to configure: currency, one time donation, monthly donation, and 5 more options"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/donations/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/donations\",\n\t\"title\": \"Donations Form\",\n\t\"description\": \"Collect one-time, monthly, or annually recurring donations.\",\n\t\"keywords\": [\n\t\t\"charity\",\n\t\t\"contribution\",\n\t\t\"credit card\",\n\t\t\"debit card\",\n\t\t\"donate\",\n\t\t\"earn\",\n\t\t\"monetize\",\n\t\t\"ecommerce\",\n\t\t\"fundraising\",\n\t\t\"fundraiser\",\n\t\t\"gofundme\",\n\t\t\"money\",\n\t\t\"nonprofit\",\n\t\t\"non-profit\",\n\t\t\"paid\",\n\t\t\"patreon\",\n\t\t\"pay\",\n\t\t\"payments\",\n\t\t\"recurring\",\n\t\t\"stripe\",\n\t\t\"sponsor\",\n\t\t\"square\",\n\t\t\"tipping\",\n\t\t\"venmo\"\n\t],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"monetize\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M16.5 4.5c2.206 0 4 1.794 4 4 0 4.67-5.543 8.94-8.5 11.023C9.043 17.44 3.5 13.17 3.5 8.5c0-2.206 1.794-4 4-4 1.298 0 2.522.638 3.273 1.706L12 7.953l1.227-1.746c.75-1.07 1.975-1.707 3.273-1.707m0-1.5c-1.862 0-3.505.928-4.5 2.344C11.005 3.928 9.362 3 7.5 3 4.462 3 2 5.462 2 8.5c0 5.72 6.5 10.438 10 12.85 3.5-2.412 10-7.13 10-12.85C22 5.462 19.538 3 16.5 3z' /></svg>\",\n\t\"supports\": { \"html\": false },\n\t\"attributes\": {\n\t\t\"currency\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"oneTimeDonation\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"show\": true,\n\t\t\t\t\"planId\": null,\n\t\t\t\t\"amounts\": [ 5, 15, 100 ]\n\t\t\t}\n\t\t},\n\t\t\"monthlyDonation\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"show\": true,\n\t\t\t\t\"planId\": null,\n\t\t\t\t\"amounts\": [ 5, 15, 100 ]\n\t\t\t}\n\t\t},\n\t\t\"annualDonation\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"show\": true,\n\t\t\t\t\"planId\": null,\n\t\t\t\t\"amounts\": [ 5, 15, 100 ]\n\t\t\t}\n\t\t},\n\t\t\"showCustomAmount\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"chooseAmountText\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customAmountText\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"fallbackLinkUrl\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"example\": {}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/donations/edit.js\nimport { Spinner } from '@automattic/jetpack-components';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useState, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport ConnectBanner from '../../shared/components/connect-banner';\nimport { StripeNudge } from '../../shared/components/stripe-nudge';\nimport { SUPPORTED_CURRENCIES } from '../../shared/currencies';\nimport getConnectUrl from '../../shared/get-connect-url';\nimport useIsUserConnected from '../../shared/use-is-user-connected';\nimport { store as membershipProductsStore } from '../../store/membership-products';\nimport { STORE_NAME as MEMBERSHIPS_PRODUCTS_STORE } from '../../store/membership-products/constants';\nimport fetchDefaultProducts from './fetch-default-products';\nimport fetchStatus from './fetch-status';\nimport FirstTimeModal from './first-time-modal';\nimport './first-time-modal.scss';\nimport LoadingError from './loading-error';\nimport Tabs from './tabs';\n\nconst Edit = props => {\n\tconst { attributes, setAttributes } = props;\n\tconst { currency } = attributes;\n\n\tconst blockProps = useBlockProps();\n\tconst [ loadingError, setLoadingError ] = useState( '' );\n\tconst [ products, setProducts ] = useState( [] );\n\tconst [ showFirstTimeModal, setShowFirstTimeModal ] = useState( false );\n\tconst isUserConnected = useIsUserConnected();\n\n\tconst { lockPostSaving, unlockPostSaving } = useDispatch( 'core/editor' );\n\tconst { getEntityRecord, getCurrentUser } = useSelect( 'core' );\n\tconst { editEntityRecord, saveEditedEntityRecord } = useDispatch( 'core' );\n\tconst post = useSelect( select => select( 'core/editor' ).getCurrentPost(), [] );\n\tconst isPostSavingLocked = useSelect(\n\t\tselect => select( 'core/editor' ).isPostSavingLocked(),\n\t\t[]\n\t);\n\n\tconst stripeConnectUrl = useSelect(\n\t\tselect => select( membershipProductsStore ).getConnectUrl() || '',\n\t\t[]\n\t);\n\n\tconst { setConnectUrl, setConnectedAccountDefaultCurrency } = useDispatch(\n\t\tMEMBERSHIPS_PRODUCTS_STORE\n\t);\n\n\tconst stripeDefaultCurrency = useSelect( select =>\n\t\tselect( MEMBERSHIPS_PRODUCTS_STORE ).getConnectedAccountDefaultCurrency()\n\t);\n\n\tuseEffect( () => {\n\t\tif ( ! currency && stripeDefaultCurrency && ! isPostSavingLocked ) {\n\t\t\tconst uppercasedStripeCurrency = stripeDefaultCurrency.toUpperCase();\n\t\t\tconst isCurrencySupported = !! SUPPORTED_CURRENCIES[ uppercasedStripeCurrency ];\n\t\t\tif ( isCurrencySupported ) {\n\t\t\t\t// If no currency is available, default to the stripe one\n\t\t\t\tsetAttributes( { currency: uppercasedStripeCurrency } );\n\t\t\t} else {\n\t\t\t\t// We default to USD\n\t\t\t\tsetAttributes( { currency: 'USD' } );\n\t\t\t}\n\t\t}\n\t}, [ currency, stripeDefaultCurrency, isPostSavingLocked, setAttributes ] );\n\n\tconst apiError = message => {\n\t\tsetLoadingError( message );\n\t};\n\n\tconst hasRequiredProducts = productIdsPerInterval => {\n\t\tconst intervals = Object.keys( productIdsPerInterval );\n\n\t\treturn (\n\t\t\tintervals.includes( 'one-time' ) &&\n\t\t\tintervals.includes( '1 month' ) &&\n\t\t\tintervals.includes( '1 year' )\n\t\t);\n\t};\n\n\t//\n\t// Check if this is the first time using the donations block\n\t//\n\n\t// Add this to preload the user entity\n\tconst currentUser = getCurrentUser();\n\tuseEffect( () => {\n\t\tif ( currentUser?.id ) {\n\t\t\t// Ensure the user entity is loaded\n\t\t\tgetEntityRecord( 'root', 'user', currentUser.id );\n\t\t}\n\t}, [ currentUser?.id, getEntityRecord ] );\n\n\tconst hasDismissedDonationWarning =\n\t\tcurrentUser?.meta?.jetpack_donation_warning_dismissed || false;\n\n\t// Show the modal if the user has not dismissed the warning\n\tuseEffect( () => {\n\t\tif ( currentUser?.id && hasDismissedDonationWarning === false ) {\n\t\t\tsetShowFirstTimeModal( true );\n\t\t}\n\t}, [ currentUser, hasDismissedDonationWarning ] );\n\n\tuseEffect( () => {\n\t\tlockPostSaving( 'donations' );\n\n\t\tconst filterProducts = productList =>\n\t\t\tproductList.reduce(\n\t\t\t\t( filteredProducts, { id, currency: productCurrency, type, interval } ) => {\n\t\t\t\t\tif ( productCurrency === currency && type === 'donation' ) {\n\t\t\t\t\t\tfilteredProducts[ interval ] = id;\n\t\t\t\t\t}\n\t\t\t\t\treturn filteredProducts;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\n\t\tfetchStatus( 'donation' ).then( result => {\n\t\t\tif ( ( ! result && typeof result !== 'object' ) || result.errors ) {\n\t\t\t\tunlockPostSaving( 'donations' );\n\t\t\t\tsetLoadingError( __( 'Could not load data from WordPress.com.', 'jetpack' ) );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetConnectUrl( getConnectUrl( post.id, result.connect_url ) );\n\t\t\tsetConnectedAccountDefaultCurrency(\n\t\t\t\tresult?.connected_account_default_currency?.toUpperCase()\n\t\t\t);\n\n\t\t\tconst filteredProducts = filterProducts( result.products );\n\n\t\t\tif ( hasRequiredProducts( filteredProducts ) ) {\n\t\t\t\tsetProducts( filteredProducts );\n\t\t\t\tunlockPostSaving( 'donations' );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Set fake products when there is no connection to Stripe so users can still try the block in the editor.\n\t\t\tif ( result.connect_url ) {\n\t\t\t\tsetProducts( {\n\t\t\t\t\t'one-time': -1,\n\t\t\t\t\t'1 month': -1,\n\t\t\t\t\t'1 year': -1,\n\t\t\t\t} );\n\t\t\t\tunlockPostSaving( 'donations' );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( currency ) {\n\t\t\t\t// Only create products if we have the correct plan and stripe connection.\n\t\t\t\tfetchDefaultProducts( currency ).then( defaultProducts => {\n\t\t\t\t\tsetProducts( filterProducts( defaultProducts ) );\n\t\t\t\t\tunlockPostSaving( 'donations' );\n\t\t\t\t}, apiError );\n\t\t\t}\n\n\t\t\tunlockPostSaving( 'donations' );\n\t\t}, apiError );\n\t}, [\n\t\tlockPostSaving,\n\t\tcurrency,\n\t\tpost.id,\n\t\tsetConnectUrl,\n\t\tsetConnectedAccountDefaultCurrency,\n\t\tunlockPostSaving,\n\t] );\n\n\tlet content;\n\n\tif ( ! isUserConnected ) {\n\t\tcontent = (\n\t\t\t<ConnectBanner\n\t\t\t\tblock=\"Donations Form\"\n\t\t\t\texplanation={ __( 'Connect your WordPress.com account to enable donations.', 'jetpack' ) }\n\t\t\t/>\n\t\t);\n\t} else if ( loadingError ) {\n\t\tcontent = <LoadingError error={ loadingError } />;\n\t} else if ( stripeConnectUrl ) {\n\t\t// Need to connect Stripe first\n\t\tcontent = <StripeNudge blockName=\"donations\" />;\n\t} else if ( ! currency ) {\n\t\t// Memberships settings are still loading\n\t\tcontent = <Spinner color=\"black\" />;\n\t} else {\n\t\tcontent = <Tabs { ...props } products={ products } />;\n\t}\n\n\t// When the first time modal is closed, update the user meta to mark the donation warning as dismissed\n\tconst handleModalClose = async () => {\n\t\tsetShowFirstTimeModal( false );\n\n\t\tif ( ! currentUser?.id ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'Cannot update user meta: User not loaded' );\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait editEntityRecord( 'root', 'user', currentUser.id, {\n\t\t\t\tmeta: {\n\t\t\t\t\tjetpack_donation_warning_dismissed: true,\n\t\t\t\t},\n\t\t\t} );\n\t\t\tawait saveEditedEntityRecord( 'root', 'user', currentUser.id );\n\t\t} catch ( error ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'Failed to update user meta:', error );\n\t\t}\n\t};\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ content }\n\t\t\t{ showFirstTimeModal && <FirstTimeModal onClose={ handleModalClose } /> }\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n\n\n// File: projects/plugins/jetpack/extensions/blocks/donations/save.js\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\nimport { getDefaultTexts } from './utils';\n\nconst DEFAULT_TEXTS = getDefaultTexts();\n\nconst Save = ( { attributes } ) => {\n\tconst { fallbackLinkUrl, oneTimeDonation, monthlyDonation, annualDonation } = attributes;\n\n\tif (\n\t\t! oneTimeDonation ||\n\t\t! oneTimeDonation.show ||\n\t\t! oneTimeDonation.planId ||\n\t\toneTimeDonation.planId === -1\n\t) {\n\t\treturn null;\n\t}\n\n\tconst blockProps = useBlockProps.save();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<RichText.Content tagName=\"h4\" value={ DEFAULT_TEXTS.oneTimeDonation?.heading } />\n\t\t\t<RichText.Content\n\t\t\t\ttagName=\"p\"\n\t\t\t\tvalue={ oneTimeDonation.extraText ?? DEFAULT_TEXTS.extraText }\n\t\t\t/>\n\t\t\t<RichText.Content\n\t\t\t\ttagName=\"a\"\n\t\t\t\tclassName=\"jetpack-donations-fallback-link\"\n\t\t\t\thref={ fallbackLinkUrl }\n\t\t\t\trel=\"noopener noreferrer noamphtml\"\n\t\t\t\ttarget=\"_blank\"\n\t\t\t\tvalue={ DEFAULT_TEXTS.oneTimeDonation?.buttonText }\n\t\t\t/>\n\t\t\t{ monthlyDonation.show && (\n\t\t\t\t<>\n\t\t\t\t\t<hr className=\"donations__separator\" />\n\t\t\t\t\t<RichText.Content tagName=\"h4\" value={ DEFAULT_TEXTS.monthlyDonation?.heading } />\n\t\t\t\t\t<RichText.Content\n\t\t\t\t\t\ttagName=\"p\"\n\t\t\t\t\t\tvalue={ monthlyDonation.extraText ?? DEFAULT_TEXTS.extraText }\n\t\t\t\t\t/>\n\t\t\t\t\t<RichText.Content\n\t\t\t\t\t\ttagName=\"a\"\n\t\t\t\t\t\tclassName=\"jetpack-donations-fallback-link\"\n\t\t\t\t\t\thref={ fallbackLinkUrl }\n\t\t\t\t\t\trel=\"noopener noreferrer noamphtml\"\n\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\tvalue={ DEFAULT_TEXTS.monthlyDonation?.buttonText }\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ annualDonation.show && (\n\t\t\t\t<>\n\t\t\t\t\t<hr className=\"donations__separator\" />\n\t\t\t\t\t<RichText.Content tagName=\"h4\" value={ DEFAULT_TEXTS.annualDonation?.heading } />\n\t\t\t\t\t<RichText.Content\n\t\t\t\t\t\ttagName=\"p\"\n\t\t\t\t\t\tvalue={ annualDonation.extraText ?? DEFAULT_TEXTS.extraText }\n\t\t\t\t\t/>\n\t\t\t\t\t<RichText.Content\n\t\t\t\t\t\ttagName=\"a\"\n\t\t\t\t\t\tclassName=\"jetpack-donations-fallback-link\"\n\t\t\t\t\t\thref={ fallbackLinkUrl }\n\t\t\t\t\t\trel=\"noopener noreferrer noamphtml\"\n\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\tvalue={ DEFAULT_TEXTS.annualDonation?.buttonText }\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</div>\n\t);\n};\n\nexport default Save;\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a custom Gutenberg block for showcasing product SKUs, incorporating a product ID selector, descendant product visibility toggle, product picker, and two additional configurable parameters."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sku/block.json\n{\n\t\"name\": \"woocommerce/product-sku\",\n\t\"title\": \"Product SKU\",\n\t\"description\": \"Displays the SKU of a product.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"attributes\": {\n\t\t\"productId\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"isDescendantOfAllProducts\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"showProductSelector\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"prefix\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"SKU:\"\n\t\t},\n\t\t\"suffix\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"query\", \"queryId\", \"postId\" ],\n\t\"ancestor\": [\n\t\t\"woocommerce/product-meta\",\n\t\t\"woocommerce/all-products\",\n\t\t\"woocommerce/single-product\",\n\t\t\"woocommerce/product-template\",\n\t\t\"core/post-template\"\n\t],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t}\n\t},\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sku/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport EditProductLink from '@woocommerce/editor-components/edit-product-link';\nimport { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\nimport Block from './block';\nimport type { Attributes } from './types';\nimport { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n\tcontext,\n}: BlockEditProps< Attributes > & { context: Context } ): JSX.Element => {\n\tconst { style, ...blockProps } = useBlockProps( {\n\t\tclassName:\n\t\t\t'wc-block-components-product-sku wp-block-woocommerce-product-sku',\n\t} );\n\tconst blockAttrs = {\n\t\t...attributes,\n\t\t...context,\n\t};\n\tconst isDescendentOfQueryLoop = Number.isFinite( context.queryId );\n\n\tlet { isDescendentOfSingleProductTemplate } =\n\t\tuseIsDescendentOfSingleProductTemplate();\n\n\tif ( isDescendentOfQueryLoop ) {\n\t\tisDescendentOfSingleProductTemplate = false;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<EditProductLink />\n\t\t\t<div\n\t\t\t\t{ ...blockProps }\n\t\t\t\t/**\n\t\t\t\t * If block is a descendant of the All Products block, we don't\n\t\t\t\t * want to apply style here because it will be applied inside\n\t\t\t\t * Block using useColors, useTypography, and useSpacing hooks.\n\t\t\t\t */\n\t\t\t\tstyle={\n\t\t\t\t\tattributes.isDescendantOfAllProducts ? undefined : style\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t<Block\n\t\t\t\t\t{ ...blockAttrs }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tisDescendentOfSingleProductTemplate={\n\t\t\t\t\t\tisDescendentOfSingleProductTemplate\n\t\t\t\t\t}\n\t\t\t\t\tisDescendantOfAllProducts={\n\t\t\t\t\t\tattributes.isDescendantOfAllProducts\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</>\n\t);\n};\n\nexport default Edit;\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a WordPress block using Gutenberg that renders a product's SKU, featuring customizable attributes including product identification, hierarchical product display, selector functionality, and two supplementary options."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sku/block.json\n{\n\t\"name\": \"woocommerce/product-sku\",\n\t\"title\": \"Product SKU\",\n\t\"description\": \"Displays the SKU of a product.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"attributes\": {\n\t\t\"productId\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"isDescendantOfAllProducts\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"showProductSelector\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"prefix\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"SKU:\"\n\t\t},\n\t\t\"suffix\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"query\", \"queryId\", \"postId\" ],\n\t\"ancestor\": [\n\t\t\"woocommerce/product-meta\",\n\t\t\"woocommerce/all-products\",\n\t\t\"woocommerce/single-product\",\n\t\t\"woocommerce/product-template\",\n\t\t\"core/post-template\"\n\t],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t}\n\t},\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sku/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport EditProductLink from '@woocommerce/editor-components/edit-product-link';\nimport { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\nimport Block from './block';\nimport type { Attributes } from './types';\nimport { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n\tcontext,\n}: BlockEditProps< Attributes > & { context: Context } ): JSX.Element => {\n\tconst { style, ...blockProps } = useBlockProps( {\n\t\tclassName:\n\t\t\t'wc-block-components-product-sku wp-block-woocommerce-product-sku',\n\t} );\n\tconst blockAttrs = {\n\t\t...attributes,\n\t\t...context,\n\t};\n\tconst isDescendentOfQueryLoop = Number.isFinite( context.queryId );\n\n\tlet { isDescendentOfSingleProductTemplate } =\n\t\tuseIsDescendentOfSingleProductTemplate();\n\n\tif ( isDescendentOfQueryLoop ) {\n\t\tisDescendentOfSingleProductTemplate = false;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<EditProductLink />\n\t\t\t<div\n\t\t\t\t{ ...blockProps }\n\t\t\t\t/**\n\t\t\t\t * If block is a descendant of the All Products block, we don't\n\t\t\t\t * want to apply style here because it will be applied inside\n\t\t\t\t * Block using useColors, useTypography, and useSpacing hooks.\n\t\t\t\t */\n\t\t\t\tstyle={\n\t\t\t\t\tattributes.isDescendantOfAllProducts ? undefined : style\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t<Block\n\t\t\t\t\t{ ...blockAttrs }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tisDescendentOfSingleProductTemplate={\n\t\t\t\t\t\tisDescendentOfSingleProductTemplate\n\t\t\t\t\t}\n\t\t\t\t\tisDescendantOfAllProducts={\n\t\t\t\t\t\tattributes.isDescendantOfAllProducts\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</>\n\t);\n};\n\nexport default Edit;\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a text block with customizable content"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/preformatted/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/preformatted\",\n\t\"title\": \"Preformatted\",\n\t\"category\": \"text\",\n\t\"description\": \"Add text that respects your spacing and tabs, and also allows styling.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"content\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"pre\",\n\t\t\t\"__unstablePreserveWhiteSpace\": true,\n\t\t\t\"role\": \"content\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"style\": \"wp-block-preformatted\"\n}\n\n\n// File: packages/block-library/src/preformatted/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { preformatted as icon } from '@wordpress/icons';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\t/* eslint-disable @wordpress/i18n-no-collapsible-whitespace */\n\t\t\t// translators: Sample content for the Preformatted block. Can be replaced with a more locale-adequate work.\n\t\t\tcontent: __(\n\t\t\t\t'EXT. XANADU - FAINT DAWN - 1940 (MINIATURE)\\nWindow, very small in the distance, illuminated.\\nAll around this is an almost totally black screen. Now, as the camera moves slowly towards the window which is almost a postage stamp in the frame, other forms appear;'\n\t\t\t),\n\t\t\t/* eslint-enable @wordpress/i18n-no-collapsible-whitespace */\n\t\t},\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\tcontent: attributes.content + '\\n\\n' + attributesToMerge.content,\n\t\t};\n\t},\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'content',\n\t\t\tlabel: __( 'Content' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'content' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/preformatted/save.js\n/**\n * WordPress dependencies\n */\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { content } = attributes;\n\n\treturn (\n\t\t<pre { ...useBlockProps.save() }>\n\t\t\t<RichText.Content value={ content } />\n\t\t</pre>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Display the order confirmation billing section. with these attributes: heading"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/billing-wrapper/block.json\n{\n\t\"name\": \"woocommerce/order-confirmation-billing-wrapper\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Billing Address Section\",\n\t\"description\": \"Display the order confirmation billing section.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [\n\t\t\"WooCommerce\"\n\t],\n\t\"attributes\": {\n\t\t\"heading\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"multiple\": false,\n\t\t\"align\": [\n\t\t\t\"wide\",\n\t\t\t\"full\"\n\t\t],\n\t\t\"html\": false,\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/billing-wrapper/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: {\n\t\theading: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ) => {\n\tconst blockProps = useBlockProps();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks\n\t\t\t\tallowedBlocks={ [ 'core/heading' ] }\n\t\t\t\ttemplate={ [\n\t\t\t\t\t[\n\t\t\t\t\t\t'core/heading',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlevel: 2,\n\t\t\t\t\t\t\tstyle: { typography: { fontSize: '24px' } },\n\t\t\t\t\t\t\tcontent: attributes.heading || '',\n\t\t\t\t\t\t\tonChangeContent: ( value: string ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { heading: value } ),\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\t[\n\t\t\t\t\t\t'woocommerce/order-confirmation-billing-address',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlock: {\n\t\t\t\t\t\t\t\tremove: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t] }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a WooCommerce block that enables flexible configuration through customizable parameters, including query ID, query type, tag name, and six additional configurable options."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-collection/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-collection\",\n\t\"title\": \"Product Collection\",\n\t\"description\": \"Display a collection of products from your store.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [\n\t\t\"WooCommerce\",\n\t\t\"Products (Beta)\",\n\t\t\"all products\",\n\t\t\"by attribute\",\n\t\t\"by category\",\n\t\t\"by tag\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"attributes\": {\n\t\t\"queryId\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"query\": {\n\t\t\t\"type\": \"object\"\n\t\t},\n\t\t\"tagName\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"displayLayout\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"properties\": {\n\t\t\t\t\"type\": {\n\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\"enum\": [ \"flex\", \"list\", \"carousel\" ]\n\t\t\t\t},\n\t\t\t\t\"columns\": {\n\t\t\t\t\t\"type\": \"number\"\n\t\t\t\t},\n\t\t\t\t\"shrinkColumns\": {\n\t\t\t\t\t\"type\": \"boolean\"\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t\"dimensions\": {\n\t\t\t\"type\": \"object\"\n\t\t},\n\t\t\"convertedFromProducts\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"collection\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"hideControls\": {\n\t\t\t\"default\": [],\n\t\t\t\"type\": \"array\"\n\t\t},\n\t\t\"queryContextIncludes\": {\n\t\t\t\"type\": \"array\"\n\t\t},\n\t\t\"forcePageReload\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"__privatePreviewState\": {\n\t\t\t\"type\": \"object\"\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"queryId\": \"queryId\",\n\t\t\"query\": \"query\",\n\t\t\"displayLayout\": \"displayLayout\",\n\t\t\"dimensions\": \"dimensions\",\n\t\t\"queryContextIncludes\": \"queryContextIncludes\",\n\t\t\"collection\": \"collection\",\n\t\t\"__privateProductCollectionPreviewState\": \"__privatePreviewState\"\n\t},\n\t\"usesContext\": [ \"templateSlug\", \"postId\" ],\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"anchor\": true,\n\t\t\"html\": false,\n\t\t\"__experimentalLayout\": true,\n\t\t\"interactivity\": true,\n\t\t\"email\": true\n\t},\n\t\"editorStyle\": \"file:../woocommerce/product-collection-editor.css\",\n\t\"style\": \"file:../woocommerce/product-collection-style.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-collection/save.tsx\n/**\n * External dependencies\n */\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\n\nexport default function QuerySave( { attributes: { tagName: Tag = 'div' } } ) {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\treturn <Tag { ...innerBlocksProps } />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a woocommerce block with customizable text align, show product title, show reviews count, and 2 more options"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-title/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-reviews-title\",\n\t\"title\": \"Reviews Title\",\n\t\"category\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/product-reviews\" ],\n\t\"description\": \"Displays a title with the number of reviews.\",\n\t\"textdomain\": \"woocommerce\",\n\t\"usesContext\": [ \"postId\", \"postType\" ],\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"showProductTitle\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showReviewsCount\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"level\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 2\n\t\t},\n\t\t\"levelOptions\": {\n\t\t\t\"type\": \"array\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": false,\n\t\t\"align\": true,\n\t\t\"html\": false,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true,\n\t\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\t\"__experimentalFontWeight\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-title/index.ts\n/**\n * External dependencies\n */\nimport { registerBlockType } from '@wordpress/blocks';\nimport { title as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport edit from './edit';\nimport './style.scss';\n\n// @ts-expect-error metadata is not typed.\nregisterBlockType( metadata, {\n\tedit,\n\ticon,\n} );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a dynamic pricing block in WordPress that provides flexibility for users to set product details, including ID, query loop relationship, text positioning, and two extra personalization options."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/block.json\n{\n\t\"name\": \"woocommerce/product-price\",\n\t\"title\": \"Product Price\",\n\t\"description\": \"Display the price of a product.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"attributes\": {\n\t\t\"productId\": { \"type\": \"number\", \"default\": 0 },\n\t\t\"isDescendentOfQueryLoop\": { \"type\": \"boolean\", \"default\": false },\n\t\t\"textAlign\": { \"type\": \"string\", \"default\": \"\" },\n\t\t\"isDescendentOfSingleProductTemplate\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isDescendentOfSingleProductBlock\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"usesContext\": [ \"query\", \"queryId\", \"postId\" ],\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"interactivity\": true,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true,\n\t\t\t\"link\": false\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalLetterSpacing\": true\n\t\t},\n\t\t\"__experimentalSelector\": \".wp-block-woocommerce-product-price .wc-block-components-product-price\",\n\t\t\"email\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t}\n\t},\n\t\"ancestor\": [\n\t\t\"woocommerce/all-products\",\n\t\t\"woocommerce/featured-product\",\n\t\t\"woocommerce/single-product\",\n\t\t\"woocommerce/product-template\",\n\t\t\"core/post-template\"\n\t],\n\t\"viewScriptModule\": \"product-price\",\n\t\"style\": \"file:../product-price.css\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tAlignmentToolbar,\n\tBlockControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { useEffect } from '@wordpress/element';\nimport type { BlockAlignment } from '@wordpress/blocks';\nimport { isExperimentalWcRestApiV4Enabled } from '@woocommerce/block-settings';\nimport { useProduct } from '@woocommerce/entities';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';\n\ntype UnsupportedAligments = 'wide' | 'full';\ntype AllowedAlignments = Exclude< BlockAlignment, UnsupportedAligments >;\n\ninterface BlockAttributes {\n\ttextAlign?: AllowedAlignments;\n}\n\ninterface Attributes {\n\ttextAlign: 'left' | 'center' | 'right';\n\tisDescendentOfSingleProduct: boolean;\n\tisDescendentOfSingleProductBlock: boolean;\n\tproductId: number;\n}\n\ninterface Context {\n\tqueryId: number;\n}\n\ninterface Props {\n\tattributes: Attributes;\n\tsetAttributes: (\n\t\tattributes: Partial< BlockAttributes > & Record< string, unknown >\n\t) => void;\n\tcontext: Context;\n}\n\nconst PriceEdit = ( {\n\tattributes,\n\tsetAttributes,\n\tcontext,\n}: Props ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst blockAttrs = {\n\t\t...attributes,\n\t\t...context,\n\t};\n\tconst isDescendentOfQueryLoop = Number.isFinite( context.queryId );\n\n\tlet { isDescendentOfSingleProductTemplate } =\n\t\tuseIsDescendentOfSingleProductTemplate();\n\n\tif ( isDescendentOfQueryLoop ) {\n\t\tisDescendentOfSingleProductTemplate = false;\n\t}\n\n\tuseEffect(\n\t\t() =>\n\t\t\tsetAttributes( {\n\t\t\t\tisDescendentOfQueryLoop,\n\t\t\t\tisDescendentOfSingleProductTemplate,\n\t\t\t} ),\n\t\t[\n\t\t\tisDescendentOfQueryLoop,\n\t\t\tisDescendentOfSingleProductTemplate,\n\t\t\tsetAttributes,\n\t\t]\n\t);\n\n\tconst isExperimentalWcRestApiEnabled = isExperimentalWcRestApiV4Enabled();\n\n\tconst { product } = useProduct( context.postId );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<AlignmentToolbar\n\t\t\t\t\tvalue={ attributes.textAlign }\n\t\t\t\t\tonChange={ ( textAlign: AllowedAlignments ) => {\n\t\t\t\t\t\tsetAttributes( { textAlign } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{\n\t\t\t\t\t// If experimental WC API is not available we must fallback to \"old\" way of fetching product data.\n\t\t\t\t\t// Once it's available everywhere we can remove this fallback.\n\t\t\t\t\tisExperimentalWcRestApiEnabled ? (\n\t\t\t\t\t\t<Block\n\t\t\t\t\t\t\t{ ...blockAttrs }\n\t\t\t\t\t\t\tisAdmin={ true }\n\t\t\t\t\t\t\tproduct={ product }\n\t\t\t\t\t\t\tisExperimentalWcRestApiV4Enabled={\n\t\t\t\t\t\t\t\tisExperimentalWcRestApiEnabled\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<Block\n\t\t\t\t\t\t\t{ ...blockAttrs }\n\t\t\t\t\t\t\tproduct={ undefined }\n\t\t\t\t\t\t\tisAdmin={ false }\n\t\t\t\t\t\t\tisExperimentalWcRestApiV4Enabled={ false }\n\t\t\t\t\t\t/>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t</div>\n\t\t</>\n\t);\n};\n\nexport default PriceEdit;\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a customizable block that empowers users to effortlessly transform plain text by incorporating headings, lists, and link functionalities with intuitive source configuration."
},
{
"role": "assistant",
"content": "// File: projects/plugins/jetpack/extensions/blocks/markdown/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/markdown\",\n\t\"title\": \"Markdown\",\n\t\"description\": \"Add headings, lists, or links to plain text with ease.\",\n\t\"keywords\": [ \"formatting\", \"syntax\", \"markup\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"text\",\n\t\"icon\": \"<svg viewBox='0 0 208 128' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><rect width='198' height='118' x='5' y='5' ry='10' stroke='currentColor' strokeWidth='10' fill='none' /><path d='M30 98v-68h20l20 25 20-25h20v68h-20v-39l-20 25-20-25v39zM155 98l-30-33h20v-35h20v35h20z' />\",\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true,\n\t\t\t\t\"margin\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"attributes\": { \"source\": { \"type\": \"string\" } },\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"source\": \"## ## Try Markdown\\n\\nMarkdown is a text formatting syntax that is converted into HTML. You can _emphasize_ text or **make it strong** with just a few characters.\"\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/markdown/edit.js\nimport { BlockControls, PlainText, useBlockProps } from '@wordpress/block-editor';\nimport { compose } from '@wordpress/compose';\nimport { withDispatch, withSelect } from '@wordpress/data';\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport ToolbarButton from './controls';\nimport MarkdownRenderer from './renderer';\n\n/**\n * Module variables\n */\nconst PANEL_EDITOR = 'editor';\nconst PANEL_PREVIEW = 'preview';\n\nconst MarkdownEdit = ( { attributes, setAttributes, isSelected, removeBlock } ) => {\n\tconst { source } = attributes;\n\tconst isEmpty = ! source || source.trim() === '';\n\n\tconst blockProps = useBlockProps();\n\tconst { className } = blockProps;\n\tconst [ activePanel, setActivePanel ] = useState( PANEL_EDITOR );\n\tconst input = useRef( null );\n\n\tconst onChange = s => setAttributes( { source: s } );\n\tconst onKeyDown = e => {\n\t\t// Remove the block if source is empty and we're pressing the Backspace key\n\t\tif ( e.keyCode === 8 && source === '' ) {\n\t\t\tremoveBlock();\n\t\t\te.preventDefault();\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( isSelected ) {\n\t\t\tif ( activePanel === PANEL_EDITOR ) {\n\t\t\t\tinput?.current.focus();\n\t\t\t}\n\t\t} else if ( activePanel === PANEL_PREVIEW ) {\n\t\t\tsetActivePanel( PANEL_EDITOR );\n\t\t}\n\t}, [ isSelected, activePanel, setActivePanel ] );\n\n\tlet content;\n\n\tif ( ! isSelected && isEmpty ) {\n\t\tcontent = (\n\t\t\t<p className={ `${ className }__placeholder` }>\n\t\t\t\t{ __( 'Write your _Markdown_ **here**…', 'jetpack' ) }\n\t\t\t</p>\n\t\t);\n\t} else {\n\t\tcontent = (\n\t\t\t<div className={ className }>\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<div className=\"components-toolbar\">\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tclassName={ className }\n\t\t\t\t\t\t\tlabel={ __( 'Markdown', 'jetpack' ) }\n\t\t\t\t\t\t\tisPressed={ activePanel === PANEL_EDITOR }\n\t\t\t\t\t\t\tonClick={ () => setActivePanel( PANEL_EDITOR ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tclassName={ className }\n\t\t\t\t\t\t\tlabel={ __( 'Preview', 'jetpack' ) }\n\t\t\t\t\t\t\tisPressed={ activePanel === PANEL_PREVIEW }\n\t\t\t\t\t\t\tonClick={ () => setActivePanel( PANEL_PREVIEW ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</BlockControls>\n\n\t\t\t\t{ activePanel === PANEL_PREVIEW || ! isSelected ? (\n\t\t\t\t\t<MarkdownRenderer className={ `${ className }__preview` } source={ source } />\n\t\t\t\t) : (\n\t\t\t\t\t<PlainText\n\t\t\t\t\t\tclassName={ `${ className }__editor` }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\taria-label={ __( 'Markdown', 'jetpack' ) }\n\t\t\t\t\t\tref={ input }\n\t\t\t\t\t\tvalue={ source }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn <div { ...blockProps }>{ content }</div>;\n};\n\nexport default compose( [\n\twithSelect( select => ( {\n\t\tcurrentBlockId: select( 'core/block-editor' ).getSelectedBlockClientId(),\n\t} ) ),\n\twithDispatch( ( dispatch, { currentBlockId } ) => ( {\n\t\tremoveBlock: () => dispatch( 'core/block-editor' ).removeBlocks( currentBlockId ),\n\t} ) ),\n] )( MarkdownEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/markdown/save.js\nimport { useBlockProps } from '@wordpress/block-editor';\nimport MarkdownRenderer from './renderer';\n\nexport default ( { attributes } ) => {\n\tconst blockProps = useBlockProps.save();\n\n\treturn (\n\t\t<MarkdownRenderer { ...blockProps } source={ attributes.source } attributes={ attributes } />\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Button allowing you to sell products and subscriptions. with these attributes: plan id, plan ids, align, and 3 more options"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/recurring-payments/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/recurring-payments\",\n\t\"title\": \"Payment Button\",\n\t\"description\": \"Button allowing you to sell products and subscriptions.\",\n\t\"keywords\": [\n\t\t\"buy\",\n\t\t\"contribution\",\n\t\t\"commerce\",\n\t\t\"credit card\",\n\t\t\"debit card\",\n\t\t\"donate\",\n\t\t\"Donations\",\n\t\t\"monetize\",\n\t\t\"earn\",\n\t\t\"ecommerce\",\n\t\t\"gofundme\",\n\t\t\"memberships\",\n\t\t\"money\",\n\t\t\"paid\",\n\t\t\"patreon\",\n\t\t\"pay\",\n\t\t\"payments\",\n\t\t\"products\",\n\t\t\"purchase\",\n\t\t\"recurring\",\n\t\t\"sell\",\n\t\t\"shop\",\n\t\t\"stripe\",\n\t\t\"subscribe\",\n\t\t\"subscriptions\",\n\t\t\"sponsor\",\n\t\t\"square\",\n\t\t\"toast\",\n\t\t\"venmo\"\n\t],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"monetize\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M20 4H4c-1.105 0-2 .895-2 2v12c0 1.105.895 2 2 2h16c1.105 0 2-.895 2-2V6c0-1.105-.895-2-2-2zm0 2v2H4V6h16zM4 18v-6h16v6H4zm2-4h7v2H6v-2zm9 0h3v2h-3v-2z'/></svg>\",\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"__experimentalExposeControlsToChildren\": true\n\t},\n\t\"usesContext\": [ \"isPremiumContentChild\" ],\n\t\"providesContext\": {\n\t\t\"jetpack/parentBlockWidth\": \"width\"\n\t},\n\t\"attributes\": {\n\t\t\"planId\": {\n\t\t\t\"type\": \"integer\"\n\t\t},\n\t\t\"planIds\": {\n\t\t\t\"type\": \"array\"\n\t\t},\n\t\t\"align\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"url\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"#\"\n\t\t},\n\t\t\"uniqueId\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"id\"\n\t\t},\n\t\t\"width\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"parent\": [ \"jetpack/payment-buttons\" ]\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/recurring-payments/edit.jsx\nimport { InspectorControls, useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { useEffect, useMemo, useCallback } from '@wordpress/element';\nimport { applyFilters } from '@wordpress/hooks';\nimport ProductManagementControls from '../../shared/components/product-management-controls';\nimport { StripeNudge } from '../../shared/components/stripe-nudge';\nimport { getEditorType, POST_EDITOR } from '../../shared/get-editor-type';\nimport useWidth from '../../shared/use-width';\nimport { WidthPanel } from '../../shared/width-panel';\nimport { getBlockStyles } from './util';\n\n// If we use the name on index.js and the block name changes the events block name will also change.\nconst BLOCK_NAME = 'recurring-payments';\n\nexport default function Edit( { attributes, clientId, setAttributes } ) {\n\tconst { align, planId, planIds, width } = attributes;\n\n\t// planId is a integer, planIds is an array.\n\t// if planIds is set, use it, otherwise use planId. Going forward we should only use planIds.\n\t// This is placed in useMemo to support the useCallback and useEffect hooks below.\n\tconst _planIds = useMemo( () => {\n\t\treturn planIds || ( planId ? [ planId ] : [] );\n\t}, [ planId, planIds ] );\n\n\tconst editorType = getEditorType();\n\tconst postLink = useSelect( select => select( editorStore )?.getCurrentPost()?.link, [] );\n\n\tconst updateSubscriptionPlans = useCallback(\n\t\tnewPlanIds => {\n\t\t\t// verify newPlanIds is a non-empty array.\n\t\t\tif ( ! Array.isArray( newPlanIds ) || 0 === newPlanIds.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// ensure/convert all elements to integers.\n\t\t\tconst validatedPlanIds = newPlanIds\n\t\t\t\t.map( id => parseInt( id, 10 ) )\n\t\t\t\t.filter( id => ! isNaN( id ) );\n\n\t\t\t// if all the elements match the existing planIds, do nothing.\n\t\t\tif (\n\t\t\t\tArray.isArray( _planIds ) &&\n\t\t\t\tvalidatedPlanIds.length === _planIds.length &&\n\t\t\t\tvalidatedPlanIds.every( i => _planIds.includes( i ) )\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst newPlanId = validatedPlanIds.join( '+' );\n\t\t\tconst resolvePaymentUrl = paymentPlanId => {\n\t\t\t\tif ( POST_EDITOR !== editorType || ! postLink ) {\n\t\t\t\t\treturn '#';\n\t\t\t\t}\n\n\t\t\t\tconst postUrl = new URL( postLink );\n\t\t\t\tpostUrl.searchParams.set( 'recurring_payments', paymentPlanId );\n\t\t\t\treturn postUrl.toString();\n\t\t\t};\n\n\t\t\tsetAttributes( {\n\t\t\t\tplanId: null,\n\t\t\t\tplanIds: validatedPlanIds,\n\t\t\t\turl: resolvePaymentUrl( newPlanId ),\n\t\t\t\tuniqueId: `recurring-payments-${ newPlanId }`,\n\t\t\t} );\n\t\t},\n\t\t[ editorType, _planIds, postLink, setAttributes ]\n\t);\n\n\tuseEffect( () => {\n\t\tupdateSubscriptionPlans( _planIds );\n\t}, [ _planIds, updateSubscriptionPlans ] );\n\n\t/**\n\t * Filters the editor settings of the Payment Button block (`jetpack/recurring-payments`).\n\t *\n\t * @param {object} editorSettings - An object with the block settings.\n\t * @param {boolean} editorSettings.showProductManagementControls - Whether the product management block controls should be shown.\n\t * @param {boolean} editorSettings.showStripeNudge - Whether the action to connect to Stripe should be shown.\n\t * @param {string} clientId - Block ID.\n\t */\n\tconst { showProductManagementControls, showStripeNudge } = applyFilters(\n\t\t'jetpack.recurringPayments.editorSettings',\n\t\t{\n\t\t\tshowProductManagementControls: true,\n\t\t\tshowStripeNudge: true,\n\t\t},\n\t\tclientId\n\t);\n\n\tuseWidth( { attributes, setAttributes } );\n\n\tconst blockProps = useBlockProps( { style: getBlockStyles( { width } ) } );\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{},\n\t\t{\n\t\t\ttemplate: [\n\t\t\t\t[\n\t\t\t\t\t'jetpack/button',\n\t\t\t\t\t{\n\t\t\t\t\t\telement: 'a',\n\t\t\t\t\t\tpassthroughAttributes: {\n\t\t\t\t\t\t\tuniqueId: 'uniqueId',\n\t\t\t\t\t\t\turl: 'url',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t],\n\t\t\ttemplateLock: 'all',\n\t\t\ttemplateInsertUpdatesSelection: true,\n\t\t}\n\t);\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ showProductManagementControls && (\n\t\t\t\t<ProductManagementControls\n\t\t\t\t\tblockName={ BLOCK_NAME }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tselectedProductIds={ _planIds }\n\t\t\t\t\tsetSelectedProductIds={ updateSubscriptionPlans }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<InspectorControls>\n\t\t\t\t<WidthPanel\n\t\t\t\t\talign={ align }\n\t\t\t\t\twidth={ width }\n\t\t\t\t\tonChange={ newWidth => setAttributes( { width: newWidth } ) }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t{ showStripeNudge && <StripeNudge blockName={ BLOCK_NAME } /> }\n\t\t\t<div { ...innerBlocksProps } />\n\t\t</div>\n\t);\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/recurring-payments/save.js\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\nimport { getBlockStyles } from './util';\n\nexport default function save( { attributes: { width } } ) {\n\tconst innerBlocksProps = useInnerBlocksProps.save( {\n\t\t...useBlockProps.save(),\n\t\tstyle: getBlockStyles( { width } ),\n\t} );\n\treturn <div { ...innerBlocksProps } />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Design a block specifically for scenarios where no product inventory exists, displaying alternative content when no items are found."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-collection/inner-blocks/no-results/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-collection-no-results\",\n\t\"title\": \"No results\",\n\t\"category\": \"woocommerce\",\n\t\"description\": \"The contents of this block will display when there are no products found.\",\n\t\"textdomain\": \"woocommerce\",\n\t\"keywords\": [ \"Product Collection\" ],\n\t\"usesContext\": [ \"queryId\", \"query\" ],\n\t\"ancestor\": [ \"woocommerce/product-collection\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"align\": true,\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"email\": true\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-collection/inner-blocks/no-results/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { Template } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\nconst TEMPLATE: Template[] = [\n\t[\n\t\t'core/group',\n\t\t{\n\t\t\tlayout: {\n\t\t\t\ttype: 'flex',\n\t\t\t\torientation: 'vertical',\n\t\t\t\tjustifyContent: 'center',\n\t\t\t\tflexWrap: 'wrap',\n\t\t\t},\n\t\t},\n\t\t[\n\t\t\t[\n\t\t\t\t'core/paragraph',\n\t\t\t\t{\n\t\t\t\t\ttextAlign: 'center',\n\t\t\t\t\tfontSize: 'medium',\n\t\t\t\t\tcontent: `<strong>${ __(\n\t\t\t\t\t\t'No results found',\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) }</strong>`,\n\t\t\t\t},\n\t\t\t],\n\t\t\t[\n\t\t\t\t'core/paragraph',\n\t\t\t\t{\n\t\t\t\t\tcontent: `${ __(\n\t\t\t\t\t\t'You can try',\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) } <a href=\"#\" class=\"wc-link-clear-any-filters\">${ __(\n\t\t\t\t\t\t'clearing any filters',\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) }</a> ${ __(\n\t\t\t\t\t\t'or head to our',\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) } <a href=\"#\" class=\"wc-link-stores-home\">${ __(\n\t\t\t\t\t\t\"store's home\",\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) }</a>`,\n\t\t\t\t},\n\t\t\t],\n\t\t],\n\t],\n];\n\nconst Edit = () => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wc-block-product-collection-no-results',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks template={ TEMPLATE } />\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-collection/inner-blocks/no-results/save.tsx\n/**\n * External dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function NoResultsSave() {\n\t// @ts-expect-error: `InnerBlocks.Content` is a component that is typed in WordPress core\n\treturn <InnerBlocks.Content />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a custom Gutenberg block that Displays the description of the selected variation."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-description/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/add-to-cart-with-options-variation-description\",\n\t\"title\": \"Variation Description (Beta)\",\n\t\"description\": \"Displays the description of the selected variation.\",\n\t\"category\": \"woocommerce\",\n\t\"textdomain\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/add-to-cart-with-options\" ],\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"html\": false,\n\t\t\"dimensions\": {\n\t\t\t\"minHeight\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t}\n\t},\n\t\"viewScriptModule\": \"woocommerce/product-elements\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-description/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\n\nexport default function VariationDescriptionEdit() {\n\tconst blockProps = useBlockProps();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<p>\n\t\t\t\t{ __(\n\t\t\t\t\t'This block displays the variation description. When the shopper selects a variation, the description content will automatically appear here.',\n\t\t\t\t\t'woocommerce'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t</div>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Design a WooCommerce custom block with the ability to modify the surrounding tag's HTML element programmatically."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-reviews\",\n\t\"icon\": \"admin-comments\",\n\t\"title\": \"Product Reviews\",\n\t\"description\": \"Display a product's reviews\",\n\t\"category\": \"woocommerce\",\n\t\"textdomain\": \"woocommerce\",\n\t\"attributes\": {\n\t\t\"tagName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"div\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"heading\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\" ],\n\t\"viewScriptModule\": \"woocommerce/product-reviews\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/edit.tsx\n/**\n * External dependencies\n */\nimport { SelectControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useQueryLoopProductContextValidation } from '@woocommerce/base-hooks';\nimport {\n\tInspectorControls,\n\tuseBlockProps,\n\t// @ts-expect-error missing types.\n\tuseInnerBlocksProps,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport TEMPLATE from './template';\nimport { ProductReviewsEditProps } from './types';\nimport { htmlElementMessages } from '../../utils/messages';\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n\tclientId,\n\tcontext,\n}: ProductReviewsEditProps ) => {\n\tconst { tagName: TagName = 'div' } = attributes;\n\tconst blockProps = useBlockProps();\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: TEMPLATE,\n\t} );\n\n\tconst { hasInvalidContext, warningElement } =\n\t\tuseQueryLoopProductContextValidation( {\n\t\t\tclientId,\n\t\t\tpostType: context.postType,\n\t\t\tblockName: __( 'Product Reviews', 'woocommerce' ),\n\t\t} );\n\n\tif ( hasInvalidContext ) {\n\t\treturn warningElement;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ /* @ts-expect-error missing types */ }\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<SelectControl\n\t\t\t\t\t// @ts-expect-error missing types.\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'HTML element', 'woocommerce' ) }\n\t\t\t\t\toptions={ [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Default (<div>)', 'woocommerce' ),\n\t\t\t\t\t\t\tvalue: 'div',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ label: '<section>', value: 'section' },\n\t\t\t\t\t\t{ label: '<aside>', value: 'aside' },\n\t\t\t\t\t] }\n\t\t\t\t\tvalue={ TagName }\n\t\t\t\t\tonChange={ ( value: 'div' | 'section' | 'aside' ) =>\n\t\t\t\t\t\tsetAttributes( { tagName: value } )\n\t\t\t\t\t}\n\t\t\t\t\thelp={ htmlElementMessages[ TagName ] }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<TagName { ...innerBlocksProps } />\n\t\t</>\n\t);\n};\n\nexport default Edit;\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/save.tsx\n/**\n * External dependencies\n */\nimport {\n\t// @ts-expect-error Missing types for this package.\n\tuseInnerBlocksProps,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\n\nexport default function Save( {\n\tattributes: { tagName: Tag = 'div' },\n}: {\n\tattributes: { tagName: string };\n} ) {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\treturn <Tag { ...innerBlocksProps } />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Column containing the cart totals. that allows users to configure: checkbox, text, lock"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-totals-block/block.json\n{\n\t\"name\": \"woocommerce/cart-totals-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Cart Totals\",\n\t\"description\": \"Column containing the cart totals.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"checkbox\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"text\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"required\": false\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/filled-cart-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-totals-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { Sidebar } from '@woocommerce/base-components/sidebar-layout';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport type { TemplateArray } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseForcedLayout,\n\tgetAllowedBlocks,\n} from '../../../cart-checkout-shared';\n\nexport const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {\n\tconst blockProps = useBlockProps( { className: 'wc-block-cart__sidebar' } );\n\tconst allowedBlocks = getAllowedBlocks( innerBlockAreas.CART_TOTALS );\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/cart-order-summary-block', {}, [] ],\n\t\t[ 'woocommerce/cart-express-payment-block', {}, [] ],\n\t\t[ 'woocommerce/proceed-to-checkout-block', {}, [] ],\n\t\t[ 'woocommerce/cart-accepted-payment-methods-block', {}, [] ],\n\t] as TemplateArray;\n\n\tuseForcedLayout( {\n\t\tclientId,\n\t\tregisteredBlocks: allowedBlocks,\n\t\tdefaultTemplate,\n\t} );\n\n\treturn (\n\t\t<Sidebar { ...blockProps }>\n\t\t\t<InnerBlocks\n\t\t\t\tallowedBlocks={ allowedBlocks }\n\t\t\t\ttemplate={ defaultTemplate }\n\t\t\t\ttemplateLock={ false }\n\t\t\t\trenderAppender={ InnerBlocks.ButtonBlockAppender }\n\t\t\t/>\n\t\t</Sidebar>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a woocommerce block with customizable class name, lock"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-subtotal/block.json\n{\n\t\"name\": \"woocommerce/cart-order-summary-subtotal-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Subtotal\",\n\t\"description\": \"Shows the cart subtotal row.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/cart-order-summary-totals-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-subtotal/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\n\nexport const Edit = ( {\n\tattributes,\n}: {\n\tattributes: {\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst { className } = attributes;\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Block className={ className } />\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Displays the next product review's page link. with these attributes: label"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-pagination-next/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-reviews-pagination-next\",\n\t\"title\": \"Reviews Next Page\",\n\t\"category\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/product-reviews-pagination\" ],\n\t\"description\": \"Displays the next product review's page link.\",\n\t\"textdomain\": \"woocommerce\",\n\t\"attributes\": {\n\t\t\"label\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"reviews/paginationArrow\" ],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-pagination-next/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useBlockProps, PlainText } from '@wordpress/block-editor';\nimport { BlockEditProps } from '@wordpress/blocks';\n\nconst arrowMap = {\n\tnone: '',\n\tarrow: '→',\n\tchevron: '»',\n};\n\ntype Props = BlockEditProps< { label: string } > & {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tcontext: { 'reviews/paginationArrow': string };\n};\n\nexport default function Edit( {\n\tattributes: { label },\n\tsetAttributes,\n\tcontext: { 'reviews/paginationArrow': paginationArrow },\n}: Props ) {\n\tconst displayArrow = arrowMap[ paginationArrow as keyof typeof arrowMap ];\n\treturn (\n\t\t<a\n\t\t\thref=\"#reviews-pagination-next-pseudo-link\"\n\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t\t{ ...useBlockProps() }\n\t\t>\n\t\t\t<PlainText\n\t\t\t\t__experimentalVersion={ 2 }\n\t\t\t\ttagName=\"span\"\n\t\t\t\taria-label={ __( 'Newer reviews page link', 'woocommerce' ) }\n\t\t\t\tplaceholder={ __( 'Newer Reviews', 'woocommerce' ) }\n\t\t\t\tvalue={ label }\n\t\t\t\tonChange={ ( newLabel ) =>\n\t\t\t\t\tsetAttributes( { label: newLabel } )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t{ displayArrow && (\n\t\t\t\t<span\n\t\t\t\t\tclassName={ `wp-block-woocommerce-product-reviews-pagination-next-arrow is-arrow-${ paginationArrow }` }\n\t\t\t\t>\n\t\t\t\t\t{ displayArrow }\n\t\t\t\t</span>\n\t\t\t) }\n\t\t</a>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Design a reusable block framework for standardizing attribute properties and options applicable to all variable product types within the WordPress environment."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/attribute/block.json\n{\n\t\"name\": \"woocommerce/add-to-cart-with-options-variation-selector-attribute\",\n\t\"title\": \"Variation Selector: Template (Beta)\",\n\t\"description\": \"A template for attribute name and options that will be applied to all variable products with attributes.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"usesContext\": [ \"postId\" ],\n\t\"ancestor\": [ \"woocommerce/add-to-cart-with-options-variation-selector\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"supports\": {\n\t\t\"inserter\": false,\n\t\t\"interactivity\": true\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/attribute/edit.tsx\n/**\n * External dependencies\n */\nimport { useState } from '@wordpress/element';\nimport {\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n\t__experimentalUseBlockPreview as useBlockPreview,\n} from '@wordpress/block-editor';\nimport { BlockInstance, type BlockEditProps } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tCustomDataProvider,\n\tuseProductDataContext,\n} from '@woocommerce/shared-context';\nimport { isProductResponseItem } from '@woocommerce/entities';\n\n/**\n * Internal dependencies\n */\nimport { DEFAULT_ATTRIBUTES } from './constants';\n\ninterface Attributes {\n\tclassName?: string;\n}\n\ntype AttributeItemProps = {\n\tblocks: BlockInstance[];\n\tisSelected: boolean;\n\tonSelect(): void;\n};\n\nfunction AttributeItem( { blocks, isSelected, onSelect }: AttributeItemProps ) {\n\tconst blockPreviewProps = useBlockPreview( {\n\t\tblocks,\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{ role: 'listitem' },\n\t\t{ templateLock: 'insert' }\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ isSelected ? <div { ...innerBlocksProps } /> : <></> }\n\n\t\t\t<div\n\t\t\t\trole=\"listitem\"\n\t\t\t\tstyle={ { display: isSelected ? 'none' : undefined } }\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\t{ ...blockPreviewProps }\n\t\t\t\t\trole=\"button\"\n\t\t\t\t\ttabIndex={ 0 }\n\t\t\t\t\tonClick={ onSelect }\n\t\t\t\t\tonKeyDown={ onSelect }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default function AttributeItemTemplateEdit(\n\tprops: BlockEditProps< Attributes >\n) {\n\tconst { clientId } = props;\n\tconst { className } = props.attributes;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName,\n\t} );\n\n\tconst { product } = useProductDataContext();\n\n\tconst productAttributes =\n\t\tisProductResponseItem( product ) && product.type === 'variable'\n\t\t\t? product.attributes\n\t\t\t: DEFAULT_ATTRIBUTES;\n\n\tconst { blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlocks } = select( blockEditorStore );\n\t\t\treturn { blocks: getBlocks( clientId ) };\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst [ selectedAttributeItem, setSelectedAttributeItem ] =\n\t\tuseState< number >();\n\n\treturn (\n\t\t<div { ...blockProps } role=\"list\">\n\t\t\t{ productAttributes.map( ( attribute ) => (\n\t\t\t\t<CustomDataProvider\n\t\t\t\t\tkey={ attribute.id }\n\t\t\t\t\tid=\"attribute\"\n\t\t\t\t\tdata={ attribute }\n\t\t\t\t>\n\t\t\t\t\t<AttributeItem\n\t\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\t\tisSelected={\n\t\t\t\t\t\t\t( selectedAttributeItem ||\n\t\t\t\t\t\t\t\tproductAttributes[ 0 ]?.id ) === attribute.id\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonSelect={ () =>\n\t\t\t\t\t\t\tsetSelectedAttributeItem( attribute.id )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</CustomDataProvider>\n\t\t\t) ) }\n\t\t</div>\n\t);\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/attribute/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport default function AttributeItemTemplateSave() {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( {\n\t\t...blockProps,\n\t\trole: 'listitem',\n\t} );\n\treturn <div { ...innerBlocksProps } />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a Gutenberg block designed for form fundamentals, incorporating attributes for type, name, label, and five additional configurable parameters."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/form-input/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"__experimental\": true,\n\t\"name\": \"core/form-input\",\n\t\"title\": \"Input Field\",\n\t\"category\": \"common\",\n\t\"ancestor\": [ \"core/form\" ],\n\t\"description\": \"The basic building block for forms.\",\n\t\"keywords\": [ \"input\", \"form\" ],\n\t\"textdomain\": \"default\",\n\t\"icon\": \"forms\",\n\t\"attributes\": {\n\t\t\"type\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"text\"\n\t\t},\n\t\t\"name\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"label\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"default\": \"Label\",\n\t\t\t\"selector\": \".wp-block-form-input__label-content\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"inlineLabel\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"required\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false,\n\t\t\t\"selector\": \".wp-block-form-input__input\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"attribute\": \"required\"\n\t\t},\n\t\t\"placeholder\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"selector\": \".wp-block-form-input__input\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"attribute\": \"placeholder\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"value\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\",\n\t\t\t\"selector\": \"input\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"attribute\": \"value\"\n\t\t},\n\t\t\"visibilityPermissions\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"all\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"reusable\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": [ \"top\", \"bottom\" ]\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"__experimentalSkipSerialization\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"style\": [ \"wp-block-form-input\" ]\n}\n\n\n// File: packages/block-library/src/form-input/index.js\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport variations from './variations';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\tdeprecated,\n\tedit,\n\tsave,\n\tvariations,\n\texample: {},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/form-input/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport removeAccents from 'remove-accents';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tRichText,\n\tuseBlockProps,\n\t__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,\n\t__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,\n} from '@wordpress/block-editor';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\n\n/**\n * Get the name attribute from a content string.\n *\n * @param {string} content The block content.\n *\n * @return {string} Returns the slug.\n */\nconst getNameFromLabel = ( content ) => {\n\treturn (\n\t\tremoveAccents( stripHTML( content ) )\n\t\t\t// Convert anything that's not a letter or number to a hyphen.\n\t\t\t.replace( /[^\\p{L}\\p{N}]+/gu, '-' )\n\t\t\t// Convert to lowercase\n\t\t\t.toLowerCase()\n\t\t\t// Remove any remaining leading or trailing hyphens.\n\t\t\t.replace( /(^-+)|(-+$)/g, '' )\n\t);\n};\n\nexport default function save( { attributes } ) {\n\tconst { type, name, label, inlineLabel, required, placeholder, value } =\n\t\tattributes;\n\n\tconst borderProps = getBorderClassesAndStyles( attributes );\n\tconst colorProps = getColorClassesAndStyles( attributes );\n\n\tconst inputStyle = {\n\t\t...borderProps.style,\n\t\t...colorProps.style,\n\t};\n\n\tconst inputClasses = clsx(\n\t\t'wp-block-form-input__input',\n\t\tcolorProps.className,\n\t\tborderProps.className\n\t);\n\tconst TagName = type === 'textarea' ? 'textarea' : 'input';\n\n\tconst blockProps = useBlockProps.save();\n\n\t// Note: radio inputs aren't implemented yet.\n\tconst isCheckboxOrRadio = type === 'checkbox' || type === 'radio';\n\n\tif ( 'hidden' === type ) {\n\t\treturn <input type={ type } name={ name } value={ value } />;\n\t}\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ /* eslint-disable jsx-a11y/label-has-associated-control */ }\n\t\t\t<label\n\t\t\t\tclassName={ clsx( 'wp-block-form-input__label', {\n\t\t\t\t\t'is-label-inline': inlineLabel,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ ! isCheckboxOrRadio && (\n\t\t\t\t\t<span className=\"wp-block-form-input__label-content\">\n\t\t\t\t\t\t<RichText.Content value={ label } />\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t\t<TagName\n\t\t\t\t\tclassName={ inputClasses }\n\t\t\t\t\ttype={ 'textarea' === type ? undefined : type }\n\t\t\t\t\tname={ name || getNameFromLabel( label ) }\n\t\t\t\t\trequired={ required }\n\t\t\t\t\taria-required={ required }\n\t\t\t\t\tplaceholder={ placeholder || undefined }\n\t\t\t\t\tstyle={ inputStyle }\n\t\t\t\t/>\n\t\t\t\t{ isCheckboxOrRadio && (\n\t\t\t\t\t<span className=\"wp-block-form-input__label-content\">\n\t\t\t\t\t\t<RichText.Content value={ label } />\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t</label>\n\t\t\t{ /* eslint-enable jsx-a11y/label-has-associated-control */ }\n\t\t</div>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Allow customers to breeze through with quick payment options. with these attributes: show button styles, button height, button border radius, and 2 more options"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-express-payment-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Express Checkout\",\n\t\"description\": \"Allow customers to breeze through with quick payment options.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"showButtonStyles\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"buttonHeight\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"48\"\n\t\t},\n\t\t\"buttonBorderRadius\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"4\"\n\t\t},\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-fields-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { useExpressPaymentMethods } from '@woocommerce/base-context/hooks';\nimport clsx from 'clsx';\nimport { ExpressPaymentControls } from '@woocommerce/blocks/cart-checkout-shared';\nimport type { BlockAttributes } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport './editor.scss';\nimport type { ExpressCheckoutAttributes } from '../../../cart-checkout-shared/types';\nimport { ExpressPaymentContext } from '../../../cart-checkout-shared/payment-methods/express-payment/express-payment-context';\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: ExpressCheckoutAttributes;\n\tsetAttributes: ( attrs: BlockAttributes ) => void;\n} ): JSX.Element | null => {\n\tconst { paymentMethods, isInitialized } = useExpressPaymentMethods();\n\tconst hasExpressPaymentMethods = Object.keys( paymentMethods ).length > 0;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx(\n\t\t\t{\n\t\t\t\t'wp-block-woocommerce-checkout-express-payment-block--has-express-payment-methods':\n\t\t\t\t\thasExpressPaymentMethods,\n\t\t\t},\n\t\t\tattributes?.className\n\t\t),\n\t\tattributes,\n\t} );\n\n\tif ( ! isInitialized || ! hasExpressPaymentMethods ) {\n\t\treturn null;\n\t}\n\n\tconst { buttonHeight, buttonBorderRadius, showButtonStyles } = attributes;\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<ExpressPaymentControls\n\t\t\t\tattributes={ attributes }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t/>\n\t\t\t<ExpressPaymentContext.Provider\n\t\t\t\tvalue={ { showButtonStyles, buttonHeight, buttonBorderRadius } }\n\t\t\t>\n\t\t\t\t<Block />\n\t\t\t</ExpressPaymentContext.Provider>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a woocommerce block with customizable lock"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-payment-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-payment-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Payment Options\",\n\t\"description\": \"Payment options for your store.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-fields-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-payment-block/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { __ } from '@wordpress/i18n';\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { PanelBody, ExternalLink } from '@wordpress/components';\nimport { payment } from '@wordpress/icons';\nimport { ADMIN_URL, getSetting } from '@woocommerce/settings';\nimport ExternalLinkCard from '@woocommerce/editor-components/external-link-card';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport Noninteractive from '@woocommerce/base-components/noninteractive';\nimport { GlobalPaymentMethod } from '@woocommerce/types';\nimport { select } from '@wordpress/data';\nimport { paymentStore } from '@woocommerce/block-data';\nimport { blocksConfig } from '@woocommerce/block-settings';\nimport { trimCharacters, trimWords } from '@woocommerce/utils';\n\n/**\n * Internal dependencies\n */\nimport {\n\tFormStepBlock,\n\tAdditionalFields,\n\tAdditionalFieldsContent,\n} from '../../form-step';\nimport Block from './block';\nimport ConfigurePlaceholder from '../../configure-placeholder';\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: {\n\t\ttitle: string;\n\t\tdescription: string;\n\t\tshowStepNumber: boolean;\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst globalPaymentMethods = getSetting< GlobalPaymentMethod[] >(\n\t\t'globalPaymentMethods'\n\t);\n\tconst incompatiblePaymentMethods =\n\t\tselect( paymentStore ).getIncompatiblePaymentMethods();\n\n\tconst incompatiblePaymentMethodMessage = __(\n\t\t'Incompatible with block-based checkout',\n\t\t'woocommerce'\n\t);\n\tconst wordCountType = blocksConfig.wordCountType;\n\n\treturn (\n\t\t<FormStepBlock\n\t\t\tattributes={ attributes }\n\t\t\tsetAttributes={ setAttributes }\n\t\t\tclassName={ clsx(\n\t\t\t\t'wc-block-checkout__payment-method',\n\t\t\t\tattributes?.className\n\t\t\t) }\n\t\t>\n\t\t\t<InspectorControls>\n\t\t\t\t{ globalPaymentMethods.length > 0 && (\n\t\t\t\t\t<PanelBody title={ __( 'Methods', 'woocommerce' ) }>\n\t\t\t\t\t\t<p className=\"wc-block-checkout__controls-text\">\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'You currently have the following payment integrations active.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t{ globalPaymentMethods.map( ( method ) => {\n\t\t\t\t\t\t\tconst isIncompatible =\n\t\t\t\t\t\t\t\t!! incompatiblePaymentMethods[ method.id ];\n\n\t\t\t\t\t\t\tlet trimmedDescription;\n\n\t\t\t\t\t\t\tif ( wordCountType === 'words' ) {\n\t\t\t\t\t\t\t\ttrimmedDescription = trimWords(\n\t\t\t\t\t\t\t\t\tmethod.description,\n\t\t\t\t\t\t\t\t\t30,\n\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\ttrimmedDescription = trimCharacters(\n\t\t\t\t\t\t\t\t\tmethod.description,\n\t\t\t\t\t\t\t\t\t30,\n\t\t\t\t\t\t\t\t\twordCountType ===\n\t\t\t\t\t\t\t\t\t\t'characters_including_spaces',\n\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<ExternalLinkCard\n\t\t\t\t\t\t\t\t\tkey={ method.id }\n\t\t\t\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=checkout§ion=${ method.id }` }\n\t\t\t\t\t\t\t\t\ttitle={ method.title }\n\t\t\t\t\t\t\t\t\tdescription={ trimmedDescription }\n\t\t\t\t\t\t\t\t\t{ ...( isIncompatible\n\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\twarning:\n\t\t\t\t\t\t\t\t\t\t\t\t\tincompatiblePaymentMethodMessage,\n\t\t\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t\t\t: {} ) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=checkout` }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Manage payment methods', 'woocommerce' ) }\n\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t) }\n\t\t\t</InspectorControls>\n\t\t\t<Noninteractive>\n\t\t\t\t<Block\n\t\t\t\t\tnoPaymentMethods={\n\t\t\t\t\t\t<ConfigurePlaceholder\n\t\t\t\t\t\t\ticon={ payment }\n\t\t\t\t\t\t\tlabel={ __( 'Payment options', 'woocommerce' ) }\n\t\t\t\t\t\t\tdescription={ __(\n\t\t\t\t\t\t\t\t'Your store does not have any payment methods that support the Checkout block. Once you have configured a compatible payment method it will be displayed here.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tbuttonLabel={ __(\n\t\t\t\t\t\t\t\t'Configure Payment Options',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tbuttonHref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=checkout` }\n\t\t\t\t\t\t/>\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</Noninteractive>\n\t\t\t<AdditionalFields block={ innerBlockAreas.PAYMENT_METHODS } />\n\t\t</FormStepBlock>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<AdditionalFieldsContent />\n\t\t</div>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a custom Gutenberg block featuring a mandatory consent mechanism that allows users to review and accept Terms & Conditions and Privacy Policy by implementing a configurable checkbox with class name, text, and optional separator options."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-terms-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-terms-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Terms and Conditions\",\n\t\"description\": \"Ensure that customers agree to your Terms & Conditions and Privacy Policy.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"checkbox\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"text\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"required\": false\n\t\t},\n\t\t\"showSeparator\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-fields-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-terms-block/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tuseBlockProps,\n\tRichText,\n\tInspectorControls,\n} from '@wordpress/block-editor';\nimport { CheckboxControl } from '@woocommerce/blocks-components';\nimport {\n\tPanelBody,\n\tToggleControl,\n\tNotice,\n\tExternalLink,\n} from '@wordpress/components';\nimport { PRIVACY_URL, TERMS_URL } from '@woocommerce/block-settings';\nimport { ADMIN_URL } from '@woocommerce/settings';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\nimport { termsConsentDefaultText, termsCheckboxDefaultText } from './constants';\n\nconst noop = () => undefined;\n\nexport const Edit = ( {\n\tattributes: { checkbox, text, showSeparator },\n\tsetAttributes,\n}: {\n\tattributes: { text: string; checkbox: boolean; showSeparator: boolean };\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ) => {\n\tconst blockProps = useBlockProps();\n\n\tconst defaultText = checkbox\n\t\t? termsCheckboxDefaultText\n\t\t: termsConsentDefaultText;\n\n\tconst currentText = text || defaultText;\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls>\n\t\t\t\t{ /* Show this notice if a terms page or a privacy page is not setup. */ }\n\t\t\t\t{ ( ! TERMS_URL || ! PRIVACY_URL ) && (\n\t\t\t\t\t<Notice\n\t\t\t\t\t\tclassName=\"wc-block-checkout__terms_notice\"\n\t\t\t\t\t\tstatus=\"warning\"\n\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\"Link to your store's Terms and Conditions and Privacy Policy pages by creating pages for them.\",\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<br />\n\t\t\t\t\t\t{ ! TERMS_URL && (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<br />\n\t\t\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=advanced` }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t\t'Setup a Terms and Conditions page',\n\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ ! PRIVACY_URL && (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<br />\n\t\t\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\t\t\thref={ `${ ADMIN_URL }options-privacy.php` }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t\t'Setup a Privacy Policy page',\n\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Notice>\n\t\t\t\t) }\n\t\t\t\t{ /* Show this notice if we have both a terms and privacy pages, but they're not present in the text. */ }\n\t\t\t\t{ TERMS_URL &&\n\t\t\t\t\tPRIVACY_URL &&\n\t\t\t\t\t! (\n\t\t\t\t\t\tcurrentText.includes( TERMS_URL ) &&\n\t\t\t\t\t\tcurrentText.includes( PRIVACY_URL )\n\t\t\t\t\t) && (\n\t\t\t\t\t\t<Notice\n\t\t\t\t\t\t\tclassName=\"wc-block-checkout__terms_notice\"\n\t\t\t\t\t\t\tstatus=\"warning\"\n\t\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\t\tactions={\n\t\t\t\t\t\t\t\ttermsConsentDefaultText !== text\n\t\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tlabel: __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t'Restore default text',\n\t\t\t\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\tonClick: () =>\n\t\t\t\t\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttext: '',\n\t\t\t\t\t\t\t\t\t\t\t\t\t} ),\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t\t\t: []\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t'Ensure you add links to your policy pages in this section.',\n\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t</Notice>\n\t\t\t\t\t) }\n\t\t\t\t<PanelBody title={ __( 'Display options', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Require checkbox', 'woocommerce' ) }\n\t\t\t\t\t\tchecked={ checkbox }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tcheckbox: ! checkbox,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Show separator', 'woocommerce' ) }\n\t\t\t\t\t\tchecked={ showSeparator }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowSeparator: ! showSeparator,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'wc-block-checkout__terms', {\n\t\t\t\t\t'wc-block-checkout__terms--with-separator': showSeparator,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ checkbox ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<div className=\"wc-block-checkout__terms-checkbox-wrapper\">\n\t\t\t\t\t\t\t<CheckboxControl\n\t\t\t\t\t\t\t\tid=\"terms-condition\"\n\t\t\t\t\t\t\t\tchecked={ false }\n\t\t\t\t\t\t\t\tonChange={ noop }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\tvalue={ currentText }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { text: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\t<RichText\n\t\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\t\tvalue={ currentText }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( { text: value } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</div>\n\t);\n};\n\nexport const Save = () => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a WordPress block enabling users to customize date archive display with options for dropdown format, label visibility, post count inclusion, and type selection."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/archives/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/archives\",\n\t\"title\": \"Archives\",\n\t\"category\": \"widgets\",\n\t\"description\": \"Display a date archive of your posts.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"displayAsDropdown\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"showLabel\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showPostCounts\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"type\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"monthly\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t},\n\t\t\"html\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-archives-editor\"\n}\n\n\n// File: packages/block-library/src/archives/index.js\n/**\n * WordPress dependencies\n */\nimport { archive as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {},\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a customizable Gutenberg block that renders hierarchical navigation breadcrumbs, allowing configuration of taxonomy preference, separator style, home link visibility, and two additional display parameters."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/breadcrumbs/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/breadcrumbs\",\n\t\"title\": \"Breadcrumbs\",\n\t\"__experimental\": true,\n\t\"category\": \"theme\",\n\t\"description\": \"Display a breadcrumb trail for hierarchical post types or based on taxonomy terms.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"prefersTaxonomy\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"separator\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"/\"\n\t\t},\n\t\t\"showHomeItem\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showCurrentItem\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showOnHomePage\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\", \"templateSlug\" ],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": false,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-breadcrumbs\"\n}\n\n\n// File: packages/block-library/src/breadcrumbs/index.js\n/**\n * WordPress dependencies\n */\nimport { breadcrumbs } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon: breadcrumbs,\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Implement a Gutenberg block for Block that displays the items counter part of the Mini-Cart Title block."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-title-items-counter-block/block.json\n{\n\t\"name\": \"woocommerce/mini-cart-title-items-counter-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Mini-Cart Title Items Counter\",\n\t\"description\": \"Block that displays the items counter part of the Mini-Cart Title block.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"interactivity\": true\n\t},\n\t\"parent\": [ \"woocommerce/mini-cart-title-block\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-title-items-counter-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { _n, sprintf } from '@wordpress/i18n';\nimport { useStoreCart } from '@woocommerce/base-context';\n\nexport const Edit = (): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst { cartItemsCount } = useStoreCart();\n\n\treturn (\n\t\t<span { ...blockProps }>\n\t\t\t{ sprintf(\n\t\t\t\t/* translators: %d is the count of items in the cart. */\n\t\t\t\t_n( '(%d item)', '(%d items)', cartItemsCount, 'woocommerce' ),\n\t\t\t\tcartItemsCount\n\t\t\t) }\n\t\t</span>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() }></div>;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Display the currently active filters. with these attributes: display style, heading level"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/active-filters/block.json\n{\n\t\"name\": \"woocommerce/active-filters\",\n\t\"title\": \"Active Filters Controls\",\n\t\"description\": \"Display the currently active filters.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": false\n\t\t},\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"inserter\": false,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": false\n\t\t},\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"displayStyle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"list\"\n\t\t},\n\t\t\"headingLevel\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/active-filters/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport BlockTitle from '@woocommerce/editor-components/block-title';\nimport {\n\tDisabled,\n\tPanelBody,\n\twithSpokenMessages,\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport type { Attributes } from './types';\nimport './editor.scss';\nimport { UpgradeNotice } from '../filter-wrapper/upgrade';\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n\tclientId,\n}: BlockEditProps< Attributes > ) => {\n\tconst { className, displayStyle, heading, headingLevel } = attributes;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName,\n\t} );\n\n\tconst getInspectorControls = () => {\n\t\treturn (\n\t\t\t<InspectorControls key=\"inspector\">\n\t\t\t\t<PanelBody>\n\t\t\t\t\t<UpgradeNotice clientId={ clientId } />\n\t\t\t\t</PanelBody>\n\t\t\t\t<PanelBody title={ __( 'Display Settings', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\tlabel={ __( 'Display Style', 'woocommerce' ) }\n\t\t\t\t\t\tisBlock\n\t\t\t\t\t\tvalue={ displayStyle }\n\t\t\t\t\t\tonChange={ ( value: Attributes[ 'displayStyle' ] ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tdisplayStyle: value,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclassName=\"wc-block-active-filter__style-toggle\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"list\"\n\t\t\t\t\t\t\tlabel={ __( 'List', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"chips\"\n\t\t\t\t\t\t\tlabel={ __( 'Chips', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t);\n\t};\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ getInspectorControls() }\n\t\t\t{ heading && (\n\t\t\t\t<BlockTitle\n\t\t\t\t\tclassName=\"wc-block-active-filters__title\"\n\t\t\t\t\theadingLevel={ headingLevel }\n\t\t\t\t\theading={ heading }\n\t\t\t\t\tonChange={ ( value: Attributes[ 'heading' ] ) =>\n\t\t\t\t\t\tsetAttributes( { heading: value } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<Disabled>\n\t\t\t\t<Block attributes={ attributes } isEditor={ true } />\n\t\t\t</Disabled>\n\t\t</div>\n\t);\n};\n\nexport default withSpokenMessages( Edit );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Add a page, link, or another item to your navigation. with these attributes: label, type, description, and 7 more options"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/navigation-link/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/navigation-link\",\n\t\"title\": \"Custom Link\",\n\t\"category\": \"design\",\n\t\"parent\": [ \"core/navigation\" ],\n\t\"allowedBlocks\": [\n\t\t\"core/navigation-link\",\n\t\t\"core/navigation-submenu\",\n\t\t\"core/page-list\"\n\t],\n\t\"description\": \"Add a page, link, or another item to your navigation.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"label\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"type\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"description\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"rel\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"id\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"opensInNewTab\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"url\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"title\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"kind\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"isTopLevelLink\": {\n\t\t\t\"type\": \"boolean\"\n\t\t}\n\t},\n\t\"usesContext\": [\n\t\t\"textColor\",\n\t\t\"customTextColor\",\n\t\t\"backgroundColor\",\n\t\t\"customBackgroundColor\",\n\t\t\"overlayTextColor\",\n\t\t\"customOverlayTextColor\",\n\t\t\"overlayBackgroundColor\",\n\t\t\"customOverlayBackgroundColor\",\n\t\t\"fontSize\",\n\t\t\"customFontSize\",\n\t\t\"showSubmenuIcon\",\n\t\t\"maxNestingLevel\",\n\t\t\"style\"\n\t],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"__experimentalSlashInserter\": true,\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"renaming\": false,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-navigation-link-editor\",\n\t\"style\": \"wp-block-navigation-link\"\n}\n\n\n// File: packages/block-library/src/navigation-link/index.js\n/**\n * WordPress dependencies\n */\nimport { _x, __ } from '@wordpress/i18n';\nimport { customLink as linkIcon } from '@wordpress/icons';\nimport { InnerBlocks } from '@wordpress/block-editor';\nimport { addFilter } from '@wordpress/hooks';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\nimport { enhanceNavigationLinkVariations } from './hooks';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon: linkIcon,\n\n\t__experimentalLabel: ( { label } ) => label,\n\n\tmerge( leftAttributes, { label: rightLabel = '' } ) {\n\t\treturn {\n\t\t\t...leftAttributes,\n\t\t\tlabel: leftAttributes.label + rightLabel,\n\t\t};\n\t},\n\n\tedit,\n\n\tsave,\n\n\texample: {\n\t\tattributes: {\n\t\t\tlabel: _x( 'Example Link', 'navigation link preview example' ),\n\t\t\turl: 'https://example.com',\n\t\t},\n\t},\n\n\tdeprecated: [\n\t\t{\n\t\t\tisEligible( attributes ) {\n\t\t\t\treturn attributes.nofollow;\n\t\t\t},\n\n\t\t\tattributes: {\n\t\t\t\tlabel: {\n\t\t\t\t\ttype: 'string',\n\t\t\t\t},\n\t\t\t\ttype: {\n\t\t\t\t\ttype: 'string',\n\t\t\t\t},\n\t\t\t\tnofollow: {\n\t\t\t\t\ttype: 'boolean',\n\t\t\t\t},\n\t\t\t\tdescription: {\n\t\t\t\t\ttype: 'string',\n\t\t\t\t},\n\t\t\t\tid: {\n\t\t\t\t\ttype: 'number',\n\t\t\t\t},\n\t\t\t\topensInNewTab: {\n\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\tdefault: false,\n\t\t\t\t},\n\t\t\t\turl: {\n\t\t\t\t\ttype: 'string',\n\t\t\t\t},\n\t\t\t},\n\n\t\t\tmigrate( { nofollow, ...rest } ) {\n\t\t\t\treturn {\n\t\t\t\t\trel: nofollow ? 'nofollow' : '',\n\t\t\t\t\t...rest,\n\t\t\t\t};\n\t\t\t},\n\n\t\t\tsave() {\n\t\t\t\treturn <InnerBlocks.Content />;\n\t\t\t},\n\t\t},\n\t],\n\ttransforms,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'label',\n\t\t\tlabel: __( 'Label' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t\t{\n\t\t\tid: 'link',\n\t\t\tlabel: __( 'Link' ),\n\t\t\ttype: 'link',\n\t\t\tmapping: {\n\t\t\t\thref: 'url',\n\t\t\t\trel: 'rel',\n\t\t\t\t// TODO - opens in new tab? id?\n\t\t\t},\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'label' ],\n\t};\n}\n\nexport const init = () => {\n\taddFilter(\n\t\t'blocks.registerBlockType',\n\t\t'core/navigation-link',\n\t\tenhanceNavigationLinkVariations\n\t);\n\n\treturn initBlock( { name, metadata, settings } );\n};\n\n\n// File: packages/block-library/src/navigation-link/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function save() {\n\treturn <InnerBlocks.Content />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a Gutenberg block serving as the core element for form creation, with a comprehensive set of attributes including type, name, label, and five supplementary options."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/form-input/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"__experimental\": true,\n\t\"name\": \"core/form-input\",\n\t\"title\": \"Input Field\",\n\t\"category\": \"common\",\n\t\"ancestor\": [ \"core/form\" ],\n\t\"description\": \"The basic building block for forms.\",\n\t\"keywords\": [ \"input\", \"form\" ],\n\t\"textdomain\": \"default\",\n\t\"icon\": \"forms\",\n\t\"attributes\": {\n\t\t\"type\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"text\"\n\t\t},\n\t\t\"name\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"label\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"default\": \"Label\",\n\t\t\t\"selector\": \".wp-block-form-input__label-content\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"inlineLabel\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"required\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false,\n\t\t\t\"selector\": \".wp-block-form-input__input\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"attribute\": \"required\"\n\t\t},\n\t\t\"placeholder\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"selector\": \".wp-block-form-input__input\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"attribute\": \"placeholder\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"value\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\",\n\t\t\t\"selector\": \"input\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"attribute\": \"value\"\n\t\t},\n\t\t\"visibilityPermissions\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"all\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"reusable\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": [ \"top\", \"bottom\" ]\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"__experimentalSkipSerialization\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"style\": [ \"wp-block-form-input\" ]\n}\n\n\n// File: packages/block-library/src/form-input/index.js\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport variations from './variations';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\tdeprecated,\n\tedit,\n\tsave,\n\tvariations,\n\texample: {},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/form-input/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport removeAccents from 'remove-accents';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tRichText,\n\tuseBlockProps,\n\t__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,\n\t__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,\n} from '@wordpress/block-editor';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\n\n/**\n * Get the name attribute from a content string.\n *\n * @param {string} content The block content.\n *\n * @return {string} Returns the slug.\n */\nconst getNameFromLabel = ( content ) => {\n\treturn (\n\t\tremoveAccents( stripHTML( content ) )\n\t\t\t// Convert anything that's not a letter or number to a hyphen.\n\t\t\t.replace( /[^\\p{L}\\p{N}]+/gu, '-' )\n\t\t\t// Convert to lowercase\n\t\t\t.toLowerCase()\n\t\t\t// Remove any remaining leading or trailing hyphens.\n\t\t\t.replace( /(^-+)|(-+$)/g, '' )\n\t);\n};\n\nexport default function save( { attributes } ) {\n\tconst { type, name, label, inlineLabel, required, placeholder, value } =\n\t\tattributes;\n\n\tconst borderProps = getBorderClassesAndStyles( attributes );\n\tconst colorProps = getColorClassesAndStyles( attributes );\n\n\tconst inputStyle = {\n\t\t...borderProps.style,\n\t\t...colorProps.style,\n\t};\n\n\tconst inputClasses = clsx(\n\t\t'wp-block-form-input__input',\n\t\tcolorProps.className,\n\t\tborderProps.className\n\t);\n\tconst TagName = type === 'textarea' ? 'textarea' : 'input';\n\n\tconst blockProps = useBlockProps.save();\n\n\t// Note: radio inputs aren't implemented yet.\n\tconst isCheckboxOrRadio = type === 'checkbox' || type === 'radio';\n\n\tif ( 'hidden' === type ) {\n\t\treturn <input type={ type } name={ name } value={ value } />;\n\t}\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ /* eslint-disable jsx-a11y/label-has-associated-control */ }\n\t\t\t<label\n\t\t\t\tclassName={ clsx( 'wp-block-form-input__label', {\n\t\t\t\t\t'is-label-inline': inlineLabel,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ ! isCheckboxOrRadio && (\n\t\t\t\t\t<span className=\"wp-block-form-input__label-content\">\n\t\t\t\t\t\t<RichText.Content value={ label } />\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t\t<TagName\n\t\t\t\t\tclassName={ inputClasses }\n\t\t\t\t\ttype={ 'textarea' === type ? undefined : type }\n\t\t\t\t\tname={ name || getNameFromLabel( label ) }\n\t\t\t\t\trequired={ required }\n\t\t\t\t\taria-required={ required }\n\t\t\t\t\tplaceholder={ placeholder || undefined }\n\t\t\t\t\tstyle={ inputStyle }\n\t\t\t\t/>\n\t\t\t\t{ isCheckboxOrRadio && (\n\t\t\t\t\t<span className=\"wp-block-form-input__label-content\">\n\t\t\t\t\t\t<RichText.Content value={ label } />\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t</label>\n\t\t\t{ /* eslint-enable jsx-a11y/label-has-associated-control */ }\n\t\t</div>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a custom Gutenberg block displaying the cart discount row, incorporating a class name and lock attribute for enhanced functionality."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/block.json\n{\n\t\"name\": \"woocommerce/checkout-order-summary-discount-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Discount\",\n\t\"description\": \"Shows the cart discount row.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-order-summary-totals-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\n\nexport const Edit = ( {\n\tattributes,\n}: {\n\tattributes: {\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst { className } = attributes;\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Block className={ className } />\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Design a WordPress block for displaying cart items in a column, enabling user-configurable lock settings."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-items-block/block.json\n{\n\t\"name\": \"woocommerce/cart-items-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Cart Items\",\n\t\"description\": \"Column containing cart items.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/filled-cart-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-items-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { Main } from '@woocommerce/base-components/sidebar-layout';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport type { TemplateArray } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseForcedLayout,\n\tgetAllowedBlocks,\n} from '../../../cart-checkout-shared';\nimport crossSells from '../../../product-collection/collections/cross-sells';\n\ninterface Props {\n\tclientId: string;\n}\n\nexport const Edit = ( { clientId }: Props ): JSX.Element => {\n\tconst blockProps = useBlockProps( { className: 'wc-block-cart__main' } );\n\tconst allowedBlocks = getAllowedBlocks( innerBlockAreas.CART_ITEMS );\n\t// Product collection is used for the Cross-Sells block.\n\t// We don't want to set a parent on the product collection block\n\t// so we add it here manually.\n\tallowedBlocks.push( 'woocommerce/product-collection' );\n\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/cart-line-items-block', {}, [] ],\n\t\t[\n\t\t\t'woocommerce/product-collection',\n\t\t\t{\n\t\t\t\t...crossSells.attributes,\n\t\t\t\tdisplayLayout: {\n\t\t\t\t\t...crossSells.attributes.displayLayout,\n\t\t\t\t\tcolumns: 3,\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\t...crossSells.attributes.query,\n\t\t\t\t\tperPage: 3,\n\t\t\t\t},\n\t\t\t\tcollection: 'woocommerce/product-collection/cross-sells',\n\t\t\t},\n\t\t\tcrossSells.innerBlocks,\n\t\t],\n\t] as unknown as TemplateArray;\n\n\tuseForcedLayout( {\n\t\tclientId,\n\t\tregisteredBlocks: allowedBlocks,\n\t\tdefaultTemplate,\n\t} );\n\treturn (\n\t\t<Main { ...blockProps }>\n\t\t\t<InnerBlocks\n\t\t\t\tallowedBlocks={ allowedBlocks }\n\t\t\t\ttemplate={ defaultTemplate }\n\t\t\t\ttemplateLock={ false }\n\t\t\t\trenderAppender={ InnerBlocks.ButtonBlockAppender }\n\t\t\t/>\n\t\t</Main>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Display a grid of products from your selected categories. with these attributes: columns, rows, align buttons, and 7 more options"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-category/block.json\n{\n\t\"name\": \"woocommerce/product-category\",\n\t\"title\": \"Products by Category\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"Display a grid of products from your selected categories.\",\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": false\n\t\t},\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"inserter\": false\n\t},\n\t\"attributes\": {\n\t\t\"columns\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t},\n\t\t\"rows\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t},\n\t\t\"alignButtons\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"contentVisibility\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"image\": true,\n\t\t\t\t\"title\": true,\n\t\t\t\t\"price\": true,\n\t\t\t\t\"rating\": true,\n\t\t\t\t\"button\": true\n\t\t\t},\n\t\t\t\"properties\": {\n\t\t\t\t\"image\": {\n\t\t\t\t\t\"type\": \"boolean\",\n\t\t\t\t\t\"default\": true\n\t\t\t\t},\n\t\t\t\t\"title\": {\n\t\t\t\t\t\"type\": \"boolean\",\n\t\t\t\t\t\"default\": true\n\t\t\t\t},\n\t\t\t\t\"price\": {\n\t\t\t\t\t\"type\": \"boolean\",\n\t\t\t\t\t\"default\": true\n\t\t\t\t},\n\t\t\t\t\"rating\": {\n\t\t\t\t\t\"type\": \"boolean\",\n\t\t\t\t\t\"default\": true\n\t\t\t\t},\n\t\t\t\t\"button\": {\n\t\t\t\t\t\"type\": \"boolean\",\n\t\t\t\t\t\"default\": true\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t\"categories\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t},\n\t\t\"catOperator\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"any\"\n\t\t},\n\t\t\"isPreview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"stockStatus\": {\n\t\t\t\"type\": \"array\"\n\t\t},\n\t\t\"editMode\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"orderby\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [\n\t\t\t\t\"date\",\n\t\t\t\t\"popularity\",\n\t\t\t\t\"price_asc\",\n\t\t\t\t\"price_desc\",\n\t\t\t\t\"rating\",\n\t\t\t\t\"title\",\n\t\t\t\t\"menu_order\"\n\t\t\t],\n\t\t\t\"default\": \"date\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-category/edit.tsx\n/**\n * External dependencies\n */\nimport { BlockControls, useBlockProps } from '@wordpress/block-editor';\nimport { useState } from '@wordpress/element';\nimport {\n\tDisabled,\n\tToolbarGroup,\n\twithSpokenMessages,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { ProductByCategoryBlock } from './block';\nimport { Attributes, Props } from './types';\nimport { ProductsByCategoryInspectorControls } from './inspector-controls';\nimport { ProductsByCategoryEditMode } from './edit-mode';\n\nconst EditBlock = ( props: Props ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\n\tconst { attributes } = props;\n\n\tconst [ isEditing, setIsEditing ] = useState(\n\t\t! attributes.categories.length\n\t);\n\n\tconst [ changedAttributes, setChangedAttributes ] = useState<\n\t\tPartial< Attributes >\n\t>( {} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup\n\t\t\t\t\tcontrols={ [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ticon: 'edit',\n\t\t\t\t\t\t\ttitle: __(\n\t\t\t\t\t\t\t\t'Edit selected categories',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tonClick: () => setIsEditing( ! isEditing ),\n\t\t\t\t\t\t\tisActive: isEditing,\n\t\t\t\t\t\t},\n\t\t\t\t\t] }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<ProductsByCategoryInspectorControls\n\t\t\t\tisEditing={ isEditing }\n\t\t\t\tsetChangedAttributes={ setChangedAttributes }\n\t\t\t\t{ ...props }\n\t\t\t/>\n\t\t\t{ isEditing ? (\n\t\t\t\t<ProductsByCategoryEditMode\n\t\t\t\t\tisEditing={ isEditing }\n\t\t\t\t\tsetIsEditing={ setIsEditing }\n\t\t\t\t\tchangedAttributes={ changedAttributes }\n\t\t\t\t\tsetChangedAttributes={ setChangedAttributes }\n\t\t\t\t\t{ ...props }\n\t\t\t\t/>\n\t\t\t) : (\n\t\t\t\t<Disabled>\n\t\t\t\t\t<ProductByCategoryBlock { ...props } />\n\t\t\t\t</Disabled>\n\t\t\t) }\n\t\t</div>\n\t);\n};\n\nexport const Edit = withSpokenMessages( EditBlock );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Displays the current category title and lets permitted users edit it. with these attributes: is link, level, link target, and 2 more options"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/category-title/block.json\n{\n\t\"name\": \"woocommerce/category-title\",\n\t\"title\": \"Product Category Title\",\n\t\"description\": \"Displays the current category title and lets permitted users edit it.\",\n\t\"category\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"textdomain\": \"woocommerce\",\n\t\"attributes\": {\n\t\t\"isLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"level\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 2\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"_self\"\n\t\t},\n\t\t\"rel\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": true\n\t\t},\n\t\t\"html\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": true\n\t},\n\t\"usesContext\": [ \"termId\", \"termTaxonomy\" ]\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/category-title/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { PanelBody, ToggleControl, TextControl } from '@wordpress/components';\nimport { store as coreStore, useEntityProp } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\nimport { createElement, forwardRef } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { WP_REST_API_Category } from 'wp-types';\nimport {\n\t// @ts-expect-error AlignmentControl is not exported from @wordpress/block-editor\n\tAlignmentControl,\n\tBlockControls,\n\tInspectorControls,\n\tuseBlockProps,\n\tPlainText,\n\t// @ts-expect-error HeadingLevelDropdown is not exported from @wordpress/block-editor\n\tHeadingLevelDropdown,\n} from '@wordpress/block-editor';\n\ninterface Props {\n\tattributes: {\n\t\tisLink: boolean;\n\t\tlevel: number;\n\t\tlinkTarget: string;\n\t\trel: string;\n\t\ttextAlign?: string;\n\t};\n\tsetAttributes: ( attrs: Partial< Props[ 'attributes' ] > ) => void;\n\tcontext: {\n\t\ttermId?: number;\n\t\ttermTaxonomy?: string;\n\t};\n}\n\n// Helper component to handle dynamic tag names without TypeScript union type issues\nconst ContainerElement = forwardRef<\n\tHTMLElement,\n\tReact.HTMLAttributes< HTMLElement > & {\n\t\ttagName?: string;\n\t\tchildren?: React.ReactNode;\n\t}\n>( ( { tagName, children, ...props }, ref ) => {\n\treturn createElement( tagName as string, { ...props, ref }, children );\n} );\n\nexport default function Edit( { attributes, setAttributes, context }: Props ) {\n\tconst { isLink, level, linkTarget, rel, textAlign } = attributes;\n\tconst TagName = (\n\t\tlevel === 0 ? 'p' : `h${ level }`\n\t) as keyof JSX.IntrinsicElements;\n\n\tconst { termId, termTaxonomy } = context;\n\n\tconst userCanEdit = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! termId ) return false;\n\t\t\t// @ts-expect-error canUser is not typed correctly\n\t\t\t// This use actually reflects the use seen in `core/post-title` block.\n\t\t\treturn select( coreStore ).canUser( 'update', {\n\t\t\t\tkind: 'taxonomy',\n\t\t\t\tname: termTaxonomy || 'product_cat',\n\t\t\t\tid: termId,\n\t\t\t} );\n\t\t},\n\t\t[ termId, termTaxonomy ]\n\t);\n\n\tconst [ rawTitle = '', setTitle, fullTitle ] = useEntityProp(\n\t\t'taxonomy',\n\t\ttermTaxonomy || 'product_cat',\n\t\t'name',\n\t\ttermId ? String( termId ) : undefined\n\t);\n\n\tconst link = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! termId ) return undefined;\n\t\t\tconst record = select(\n\t\t\t\tcoreStore\n\t\t\t).getEntityRecord< WP_REST_API_Category >(\n\t\t\t\t'taxonomy',\n\t\t\t\ttermTaxonomy || 'product_cat',\n\t\t\t\ttermId\n\t\t\t);\n\n\t\t\treturn record?.link;\n\t\t},\n\t\t[ termId, termTaxonomy ]\n\t);\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( { [ `has-text-align-${ textAlign }` ]: textAlign } ),\n\t} );\n\n\tlet titleElement: JSX.Element = createElement(\n\t\tTagName,\n\t\tblockProps,\n\t\t__( 'Category title', 'woocommerce' )\n\t) as JSX.Element;\n\n\tif ( termId ) {\n\t\ttitleElement = userCanEdit ? (\n\t\t\t<PlainText\n\t\t\t\t// @ts-expect-error PlainText component types are not up-to-date\n\t\t\t\ttagName={ TagName }\n\t\t\t\tplaceholder={ __( 'No title', 'woocommerce' ) }\n\t\t\t\tvalue={ rawTitle }\n\t\t\t\tonChange={ ( v ) => setTitle( v ) }\n\t\t\t\t__experimentalVersion={ 2 }\n\t\t\t\t{ ...blockProps }\n\t\t\t/>\n\t\t) : (\n\t\t\t<ContainerElement\n\t\t\t\ttagName={ TagName }\n\t\t\t\t{ ...blockProps }\n\t\t\t\tdangerouslySetInnerHTML={ {\n\t\t\t\t\t__html: fullTitle?.rendered,\n\t\t\t\t} }\n\t\t\t/>\n\t\t);\n\t}\n\n\tif ( isLink && termId ) {\n\t\ttitleElement = userCanEdit ? (\n\t\t\t<ContainerElement tagName={ TagName } { ...blockProps }>\n\t\t\t\t<PlainText\n\t\t\t\t\t// @ts-expect-error PlainText component types are not up-to-date\n\t\t\t\t\ttagName=\"a\"\n\t\t\t\t\thref={ link }\n\t\t\t\t\ttarget={ linkTarget }\n\t\t\t\t\trel={ rel }\n\t\t\t\t\tplaceholder={\n\t\t\t\t\t\t! rawTitle?.length\n\t\t\t\t\t\t\t? __( 'No title', 'woocommerce' )\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t\tvalue={ rawTitle }\n\t\t\t\t\tonChange={ ( v ) => setTitle( v ) }\n\t\t\t\t\t__experimentalVersion={ 2 }\n\t\t\t\t/>\n\t\t\t</ContainerElement>\n\t\t) : (\n\t\t\t<ContainerElement tagName={ TagName } { ...blockProps }>\n\t\t\t\t<a\n\t\t\t\t\thref={ link }\n\t\t\t\t\ttarget={ linkTarget }\n\t\t\t\t\trel={ rel }\n\t\t\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t\t\t\tdangerouslySetInnerHTML={ {\n\t\t\t\t\t\t__html: fullTitle?.rendered,\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</ContainerElement>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ /* @ts-expect-error BlockControls typing */ }\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t<HeadingLevelDropdown\n\t\t\t\t\tvalue={ level }\n\t\t\t\t\tonChange={ ( newLevel: number ) =>\n\t\t\t\t\t\tsetAttributes( { level: newLevel } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<AlignmentControl\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( newTextAlign: string | undefined ) =>\n\t\t\t\t\t\tsetAttributes( { textAlign: newTextAlign || '' } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Settings', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Make title a link', 'woocommerce' ) }\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\t{ isLink && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Open in new tab', 'woocommerce' ) }\n\t\t\t\t\t\t\t\tonChange={ ( v ) =>\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tlinkTarget: v ? '_blank' : '_self',\n\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tchecked={ linkTarget === '_blank' }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Link rel', 'woocommerce' ) }\n\t\t\t\t\t\t\t\tvalue={ rel }\n\t\t\t\t\t\t\t\tonChange={ ( newRel ) =>\n\t\t\t\t\t\t\t\t\tsetAttributes( { rel: newRel } )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t{ titleElement }\n\t\t</>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Give quoted text visual emphasis. \"In quoting others, we cite ourselves.\" — Julio Cortázar that allows users to configure: value, citation, text align"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/quote/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/quote\",\n\t\"title\": \"Quote\",\n\t\"category\": \"text\",\n\t\"description\": \"Give quoted text visual emphasis. \\\"In quoting others, we cite ourselves.\\\" — Julio Cortázar\",\n\t\"keywords\": [ \"blockquote\", \"cite\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"value\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"html\",\n\t\t\t\"selector\": \"blockquote\",\n\t\t\t\"multiline\": \"p\",\n\t\t\t\"default\": \"\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"citation\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"cite\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"align\": [ \"left\", \"right\", \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"background\": {\n\t\t\t\"backgroundImage\": true,\n\t\t\t\"backgroundSize\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"backgroundImage\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"dimensions\": {\n\t\t\t\"minHeight\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"minHeight\": false\n\t\t\t}\n\t\t},\n\t\t\"__experimentalOnEnter\": true,\n\t\t\"__experimentalOnMerge\": true,\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"heading\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"layout\": {\n\t\t\t\"allowEditing\": false\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"blockGap\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"allowedBlocks\": true\n\t},\n\t\"styles\": [\n\t\t{\n\t\t\t\"name\": \"default\",\n\t\t\t\"label\": \"Default\",\n\t\t\t\"isDefault\": true\n\t\t},\n\t\t{ \"name\": \"plain\", \"label\": \"Plain\" }\n\t],\n\t\"editorStyle\": \"wp-block-quote-editor\",\n\t\"style\": \"wp-block-quote\"\n}\n\n\n// File: packages/block-library/src/quote/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { quote as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tcitation: __( 'Julio Cortázar' ),\n\t\t},\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/paragraph',\n\t\t\t\tattributes: {\n\t\t\t\t\tcontent: __( 'In quoting others, we cite ourselves.' ),\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/quote/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { textAlign, citation } = attributes;\n\n\tconst className = clsx( {\n\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t} );\n\n\treturn (\n\t\t<blockquote { ...useBlockProps.save( { className } ) }>\n\t\t\t<InnerBlocks.Content />\n\t\t\t{ ! RichText.isEmpty( citation ) && (\n\t\t\t\t<RichText.Content tagName=\"cite\" value={ citation } />\n\t\t\t) }\n\t\t</blockquote>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a WooCommerce block featuring configurable text alignment options for flexible content positioning."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-form/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-review-form\",\n\t\"title\": \"Reviews Form\",\n\t\"category\": \"woocommerce\",\n\t\"description\": \"Display a product's reviews form.\",\n\t\"textdomain\": \"woocommerce\",\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\" ],\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"heading\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"textAlign\": \"center\"\n\t\t}\n\t},\n\t\"viewScriptModule\": \"woocommerce/product-review-form\",\n\t\"style\": \"file:../woocommerce/product-review-form-style.css\",\n\t\"editorStyle\": \"file:../woocommerce/product-review-form-editor.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-form/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport {\n\tAlignmentControl,\n\tBlockControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { VisuallyHidden } from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport { __, sprintf } from '@wordpress/i18n';\nimport type { BlockEditProps } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport CommentsForm from './form';\n\nexport default function PostCommentsFormEdit( {\n\tattributes,\n\tcontext,\n\tsetAttributes,\n}: BlockEditProps< {\n\ttextAlign: string;\n} > & {\n\tcontext: { postId: string; postType: string };\n} ) {\n\tconst { textAlign } = attributes;\n\tconst { postId, postType } = context;\n\n\tconst instanceId = useInstanceId( PostCommentsFormEdit );\n\tconst instanceIdDesc = sprintf( 'comments-form-edit-%d-desc', instanceId );\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( 'comment-respond', {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t\t'aria-describedby': instanceIdDesc,\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t<AlignmentControl\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( nextAlign: string ) => {\n\t\t\t\t\t\tsetAttributes( { textAlign: nextAlign } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<CommentsForm postId={ postId } postType={ postType } />\n\t\t\t\t<VisuallyHidden id={ instanceIdDesc }>\n\t\t\t\t\t{ __( 'Reviews form disabled in editor.', 'woocommerce' ) }\n\t\t\t\t</VisuallyHidden>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a woocommerce block with customizable thumbnail size, aspect ratio"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-gallery-thumbnails\",\n\t\"title\": \"Thumbnails\",\n\t\"description\": \"Display the Thumbnails of a product.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"usesContext\": [ \"postId\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/product-gallery\" ],\n\t\"attributes\": {\n\t\t\"thumbnailSize\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"25%\"\n\t\t},\n\t\t\"aspectRatio\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"1\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"spacing\": {\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"interactivity\": true\n\t},\n\t\"editorStyle\": \"file:../woocommerce/product-gallery-thumbnails-editor.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/inner-blocks/product-gallery-thumbnails/edit.tsx\n/**\n * External dependencies\n */\nimport { PLACEHOLDER_IMG_SRC } from '@woocommerce/settings';\nimport type { ProductResponseImageItem } from '@woocommerce/types';\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport { useProduct } from '@woocommerce/entities';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport { checkOverflow } from '../../utils';\nimport { ProductGalleryThumbnailsBlockSettings } from './block-settings';\nimport type { ProductGalleryThumbnailsBlockAttributes } from './types';\n\nconst MAX_THUMBNAILS = 10;\n\n/**\n * Prepares product images for display in the gallery thumbnails.\n * Limits the number of images to MAX_THUMBNAILS - no need to load more in editor.\n * Also, extracts src and alt properties from the image object.\n *\n * @param {ProductResponseImageItem[]} productImages - Array of product images from the API response.\n * @return {{ src: string | undefined; alt: string | undefined }[]} Array of prepared image objects containing src and alt properties.\n */\nconst prepareProductImages = (\n\tproductImages: ProductResponseImageItem[]\n): { src: string | undefined; alt: string | undefined }[] => {\n\treturn productImages.slice( 0, MAX_THUMBNAILS ).map( ( image ) => {\n\t\treturn {\n\t\t\tsrc: image?.src,\n\t\t\talt: image?.alt,\n\t\t};\n\t} );\n};\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n\tcontext,\n}: BlockEditProps< ProductGalleryThumbnailsBlockAttributes > & {\n\tcontext: {\n\t\tpostId?: string;\n\t};\n} ) => {\n\tconst { thumbnailSize, aspectRatio } = attributes;\n\n\tconst { product } = useProduct( context.postId );\n\n\tconst productThumbnails =\n\t\tproduct && product.images && product.images.length > 0\n\t\t\t? prepareProductImages( product.images )\n\t\t\t: Array( MAX_THUMBNAILS ).fill( {\n\t\t\t\t\tsrc: PLACEHOLDER_IMG_SRC,\n\t\t\t\t\talt: '',\n\t\t\t } );\n\n\tconst renderThumbnails = productThumbnails.length > 1;\n\n\tconst scrollableRef = useRef< HTMLDivElement >( null );\n\tconst [ overflowState, setOverflowState ] = useState( {\n\t\tbottom: false,\n\t\tright: false,\n\t} );\n\n\tuseEffect( () => {\n\t\tconst scrollableElement = scrollableRef.current;\n\t\tif ( ! scrollableElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Create a ResizeObserver to watch for layout changes\n\t\tconst resizeObserver = new ResizeObserver( () => {\n\t\t\tconst overflow = checkOverflow( scrollableElement );\n\t\t\tsetOverflowState( overflow );\n\t\t} );\n\n\t\t// Observe both the scrollable element and its parent for size changes\n\t\tresizeObserver.observe( scrollableElement );\n\t\tif ( scrollableElement.parentElement ) {\n\t\t\tresizeObserver.observe( scrollableElement.parentElement );\n\t\t}\n\n\t\treturn () => {\n\t\t\tresizeObserver.disconnect();\n\t\t};\n\t}, [ thumbnailSize ] );\n\n\tconst thumbnailSizeValue = Number( thumbnailSize.replace( '%', '' ) );\n\tconst className = clsx( 'wc-block-product-gallery-thumbnails', {\n\t\t'wc-block-product-gallery-thumbnails--overflow-right':\n\t\t\toverflowState.right,\n\t\t'wc-block-product-gallery-thumbnails--overflow-bottom':\n\t\t\toverflowState.bottom,\n\t} );\n\tconst blockProps = useBlockProps( {\n\t\tclassName,\n\t\tstyle: {\n\t\t\t'--wc-block-product-gallery-thumbnails-size': thumbnailSizeValue,\n\t\t},\n\t} );\n\tconst imageStyles: Record< string, string | undefined > = {\n\t\taspectRatio,\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<ProductGalleryThumbnailsBlockSettings\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t{ renderThumbnails && (\n\t\t\t\t<div { ...blockProps }>\n\t\t\t\t\t<div\n\t\t\t\t\t\tref={ scrollableRef }\n\t\t\t\t\t\tclassName=\"wc-block-product-gallery-thumbnails__scrollable\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ productThumbnails.map( ( { src, alt }, index ) => {\n\t\t\t\t\t\t\tconst imageClassName = clsx(\n\t\t\t\t\t\t\t\t'wc-block-product-gallery-thumbnails__thumbnail__image',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'wc-block-product-gallery-thumbnails__thumbnail__image--is-active':\n\t\t\t\t\t\t\t\t\t\tindex === 0,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tclassName=\"wc-block-product-gallery-thumbnails__thumbnail\"\n\t\t\t\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\t\tclassName={ imageClassName }\n\t\t\t\t\t\t\t\t\t\tsrc={ src }\n\t\t\t\t\t\t\t\t\t\talt={ alt }\n\t\t\t\t\t\t\t\t\t\tloading=\"lazy\"\n\t\t\t\t\t\t\t\t\t\tstyle={ imageStyles }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a WordPress block enabling seamless Google Calendar integration with customizable URL and height parameters for user-friendly embedding."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/google-calendar/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/google-calendar\",\n\t\"title\": \"Google Calendar\",\n\t\"description\": \"Embed a Google Calendar.\",\n\t\"keywords\": [ \"events\", \"dates\", \"schedule\", \"appointments\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"embed\",\n\t\"icon\": \"<svg viewBox='0 0 24 23' width='24' height='23' xmlns='http://www.w3.org/2000/svg'><path d='M19.5,23h-15c-2.2,0-4-1.8-4-4V4c0-2.2,1.8-4,4-4h15c2.2,0,4,1.8,4,4v15C23.5,21.2,21.7,23,19.5,23z M4.5,2 c-1.1,0-2,0.9-2,2v15c0,1.1,0.9,2,2,2h15c1.1,0,2-0.9,2-2V4c0-1.1-0.9-2-2-2H4.5z M6.9,3.9L6.9,3.9c0.5,0,0.9,0.4,0.9,0.9V5 c0,0.5-0.4,0.9-0.9,0.9l0,0C6.5,5.9,6.1,5.5,6.1,5V4.7C6.1,4.3,6.5,3.9,6.9,3.9z M17,3.9L17,3.9c0.5,0,0.9,0.4,0.9,0.9V5 c0,0.5-0.4,0.9-0.9,0.9l0,0c-0.5,0-0.9-0.4-0.9-0.9V4.7C16.2,4.3,16.5,3.9,17,3.9z M8.8,17.6c1.8,0,3.2-1,3.2-2.4 c0-1.1-0.7-1.8-1.8-1.9v-0.1c0.9-0.2,1.5-0.9,1.5-1.8c0-1.3-1.2-2.2-2.9-2.2c-1.8,0-2.9,1-3,2.5h1.6c0-0.7,0.6-1.1,1.4-1.1 c0.8,0,1.3,0.4,1.3,1.1c0,0.7-0.5,1.1-1.3,1.1h-1v1.3h1c0.9,0,1.5,0.4,1.5,1.1c0,0.7-0.6,1.2-1.4,1.2c-0.9,0-1.4-0.4-1.5-1.1H5.7 C5.8,16.6,7,17.6,8.8,17.6z M17.6,17.4V9.3h-1.7l-2.1,1.4v1.6l2-1.4h0.1v6.4H17.6z'/></svg>\",\n\t\"supports\": { \"align\": true, \"alignWide\": true, \"html\": false },\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"height\": {\n\t\t\t\"type\": \"integer\",\n\t\t\t\"default\": 600\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"url\": \"https://calendar.google.com/calendar/embed?src=jb4bu80jirp0u11a6niie21pp4%40group.calendar.google.com&ctz=America/New_York\"\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/google-calendar/edit.js\nimport { isWpcomPlatformSite } from '@automattic/jetpack-script-data';\nimport { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils';\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { getBlockDefaultClassName } from '@wordpress/blocks';\nimport { Placeholder, SandBox, Button, ExternalLink, withNotices } from '@wordpress/components';\nimport { compose } from '@wordpress/compose';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __, _x } from '@wordpress/i18n';\nimport { withViewportMatch } from '@wordpress/viewport';\nimport metadata from './block.json';\nimport GoogleCalendarInspectorControls from './controls';\nimport { URL_REGEX, parseEmbed } from './utils';\n\nconst icon = getBlockIconComponent( metadata );\n\nexport function GoogleCalendarEdit( props ) {\n\tconst {\n\t\tattributes: { url, height },\n\t\tisMobile,\n\t\tisSelected,\n\t\tname,\n\t\tnoticeOperations,\n\t\tnoticeUI,\n\t\tsetAttributes,\n\t} = props;\n\n\tconst blockProps = useBlockProps();\n\n\tconst [ editedEmbed, setEditedEmbed ] = useState( url || '' );\n\tconst [ editingUrl, setEditingUrl ] = useState( false );\n\tconst [ interactive, setInteractive ] = useState( false );\n\n\tuseEffect( () => {\n\t\tif ( ! isSelected && interactive ) {\n\t\t\t// We only want to change this when the block is not selected, because changing it when\n\t\t\t// the block becomes selected makes the overlap disappear too early. Hiding the overlay\n\t\t\t// happens on mouseup when the overlay is clicked.\n\t\t\tsetInteractive( false );\n\t\t}\n\t}, [ isSelected, interactive ] );\n\n\tconst hideOverlay = () => {\n\t\t// This is called onMouseUp on the overlay. We can't respond to the `isSelected` prop\n\t\t// changing, because that happens on mouse down, and the overlay immediately disappears,\n\t\t// and the mouse event can end up in the preview content. We can't use onClick on\n\t\t// the overlay to hide it either, because then the editor misses the mouseup event, and\n\t\t// thinks we're multi-selecting blocks.\n\t\tsetInteractive( true );\n\t};\n\n\tconst setErrorNotice = () => {\n\t\tnoticeOperations.removeAllNotices();\n\t\tnoticeOperations.createErrorNotice(\n\t\t\t__(\n\t\t\t\t\"Your calendar couldn't be embedded. Please double check your URL or Embed Code. Please note, you need to use the 'Public URL' or 'Embed Code', the 'Shareable Link' will not work.\",\n\t\t\t\t'jetpack'\n\t\t\t)\n\t\t);\n\t};\n\n\tconst handleEmbed = event => {\n\t\tif ( event ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\n\t\tconst newAttributes = parseEmbed( editedEmbed.trim() );\n\n\t\tif ( ! URL_REGEX.test( newAttributes.url ) ) {\n\t\t\tsetErrorNotice();\n\t\t\treturn;\n\t\t}\n\n\t\tsetAttributes( newAttributes );\n\t\tsetEditingUrl( false );\n\t\tnoticeOperations.removeAllNotices();\n\t};\n\n\tconst getEditForm = formClassName => (\n\t\t<form onSubmit={ handleEmbed } className={ formClassName }>\n\t\t\t<textarea\n\t\t\t\ttype=\"text\"\n\t\t\t\tvalue={ editedEmbed }\n\t\t\t\tclassName=\"components-placeholder__input\"\n\t\t\t\taria-label={ __( 'Google Calendar URL or iframe', 'jetpack' ) }\n\t\t\t\tplaceholder={ __( 'Enter URL or iframe to embed here…', 'jetpack' ) }\n\t\t\t\tonChange={ event => setEditedEmbed( event.target.value ) }\n\t\t\t/>\n\t\t\t<Button variant=\"secondary\" type=\"submit\">\n\t\t\t\t{ _x( 'Embed', 'button label', 'jetpack' ) }\n\t\t\t</Button>\n\t\t</form>\n\t);\n\n\tconst defaultClassName = getBlockDefaultClassName( name );\n\tconst iframeHeight = isMobile ? '300' : height;\n\n\tconst html = `<iframe src=\"${ url }\" style=\"border:0\" scrolling=\"no\" frameborder=\"0\" height=\"${ iframeHeight }\"></iframe>`;\n\n\tconst permissionsLink = (\n\t\t<ExternalLink href=\"https://en.support.wordpress.com/google-calendar/\">\n\t\t\t{ __( 'Enable Permissions for the calendar you want to share', 'jetpack' ) }\n\t\t</ExternalLink>\n\t);\n\n\tconst controls = (\n\t\t<InspectorControls>\n\t\t\t<GoogleCalendarInspectorControls\n\t\t\t\tclassName={ `${ defaultClassName }-embed-form-sidebar` }\n\t\t\t\tembedValue={ editedEmbed }\n\t\t\t\tonChange={ event => setEditedEmbed( event.target.value ) }\n\t\t\t\tonSubmit={ handleEmbed }\n\t\t\t/>\n\t\t</InspectorControls>\n\t);\n\n\tlet content;\n\n\tif ( editingUrl || ! url ) {\n\t\tconst supportLink = isWpcomPlatformSite()\n\t\t\t? 'https://en.support.wordpress.com/wordpress-editor/blocks/google-calendar/'\n\t\t\t: 'https://jetpack.com/support/jetpack-blocks/google-calendar/';\n\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t{ controls }\n\t\t\t\t<Placeholder\n\t\t\t\t\tlabel={ __( 'Google Calendar', 'jetpack' ) }\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tnotices={ noticeUI }\n\t\t\t\t>\n\t\t\t\t\t<ol className={ `${ defaultClassName }-placeholder-instructions` }>\n\t\t\t\t\t\t<li>{ permissionsLink }</li>\n\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t{ __( 'Paste the embed code you copied from your Google Calendar below', 'jetpack' ) }\n\t\t\t\t\t\t</li>\n\t\t\t\t\t</ol>\n\t\t\t\t\t{ getEditForm( `${ defaultClassName }-embed-form-editor` ) }\n\t\t\t\t\t<div className={ `${ defaultClassName }-placeholder-links` }>\n\t\t\t\t\t\t<ExternalLink href={ supportLink }>{ __( 'Learn more', 'jetpack' ) }</ExternalLink>\n\t\t\t\t\t</div>\n\t\t\t\t</Placeholder>\n\t\t\t</>\n\t\t);\n\t} else {\n\t\t// Disabled because the overlay div doesn't actually have a role or functionality\n\t\t// as far as the user is concerned. We're just catching the first click so that\n\t\t// the block can be selected without interacting with the embed preview that the overlay covers.\n\t\t/* eslint-disable jsx-a11y/no-static-element-interactions */\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t{ controls }\n\t\t\t\t<div>\n\t\t\t\t\t<SandBox html={ html } onFocus={ hideOverlay } />\n\t\t\t\t\t{ ! interactive && (\n\t\t\t\t\t\t<div className=\"block-library-embed__interactive-overlay\" onMouseUp={ hideOverlay } />\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn <div { ...blockProps }>{ content }</div>;\n}\n\nexport default compose(\n\twithNotices,\n\twithViewportMatch( { isMobile: '< small' } )\n)( GoogleCalendarEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/google-calendar/save.js\nimport { useBlockProps } from '@wordpress/block-editor';\n\nexport default ( { attributes: { url } } ) => {\n\tconst blockProps = useBlockProps.save();\n\n\treturn (\n\t\t<a { ...blockProps } href={ url }>\n\t\t\t{ url }\n\t\t</a>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a WooCommerce block featuring extensive customization capabilities, including alt text, content alignment, dimming ratio, and 12 additional configurable parameters."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/featured-product/block.json\n{\n\t\"name\": \"woocommerce/featured-product\",\n\t\"title\": \"Featured Product\",\n\t\"description\": \"Highlight a product or variation.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"ariaLabel\": true,\n\t\t\"html\": false,\n\t\t\"filter\": {\n\t\t\t\"duotone\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true\n\t\t\t},\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"width\": true\n\t\t\t},\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"multiple\": true\n\t},\n\t\"attributes\": {\n\t\t\"alt\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"contentAlign\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"center\"\n\t\t},\n\t\t\"dimRatio\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 50\n\t\t},\n\t\t\"focalPoint\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"x\": 0.5,\n\t\t\t\t\"y\": 0.5\n\t\t\t}\n\t\t},\n\t\t\"imageFit\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"none\"\n\t\t},\n\t\t\"hasParallax\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isRepeated\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"mediaId\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"mediaSrc\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"minHeight\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 500\n\t\t},\n\t\t\"linkText\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"Shop now\"\n\t\t},\n\t\t\"overlayColor\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"#000000\"\n\t\t},\n\t\t\"overlayGradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"productId\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"previewProduct\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": null\n\t\t}\n\t},\n\t\"selectors\": {\n\t\t\"filter\": {\n\t\t\t\"duotone\": \".wp-block-woocommerce-featured-product .wc-block-featured-product__background-image\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/featured-product/index.tsx\n/**\n * External dependencies\n */\nimport { Icon, starEmpty } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport './style.scss';\nimport './editor.scss';\nimport Block from './block';\nimport { register } from '../register';\nimport { example } from './example';\nimport deprecated from './deprecated';\nimport metadata from './block.json';\n\nregister( Block, example, metadata, {\n\tdeprecated,\n\ticon: {\n\t\tsrc: (\n\t\t\t<Icon\n\t\t\t\ticon={ starEmpty }\n\t\t\t\tclassName=\"wc-block-editor-components-block-icon\"\n\t\t\t/>\n\t\t),\n\t},\n} );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block component that allows dynamic text labeling with user-configurable options."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/home-link/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/home-link\",\n\t\"category\": \"design\",\n\t\"parent\": [ \"core/navigation\" ],\n\t\"title\": \"Home Link\",\n\t\"description\": \"Create a link that always points to the homepage of the site. Usually not necessary if there is already a site title link present in the header.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"label\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t}\n\t},\n\t\"usesContext\": [\n\t\t\"textColor\",\n\t\t\"customTextColor\",\n\t\t\"backgroundColor\",\n\t\t\"customBackgroundColor\",\n\t\t\"fontSize\",\n\t\t\"customFontSize\",\n\t\t\"style\"\n\t],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-home-link-editor\",\n\t\"style\": \"wp-block-home-link\"\n}\n\n\n// File: packages/block-library/src/home-link/index.js\n/**\n * WordPress dependencies\n */\nimport { _x } from '@wordpress/i18n';\nimport { home } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon: home,\n\n\tedit,\n\n\tsave,\n\n\texample: {\n\t\tattributes: {\n\t\t\tlabel: _x( 'Home Link', 'block example' ),\n\t\t},\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/home-link/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function save() {\n\treturn <InnerBlocks.Content />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Display the average rating of a product with stars that allows users to configure: product id, is descendent of query loop, text align, and 2 more options"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/block.json\n{\n\t\"name\": \"woocommerce/product-rating-stars\",\n\t\"title\": \"Product Rating Stars\",\n\t\"description\": \"Display the average rating of a product with stars\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"attributes\": {\n\t\t\"productId\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"isDescendentOfQueryLoop\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"isDescendentOfSingleProductBlock\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isDescendentOfSingleProductTemplate\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"usesContext\": [ \"query\", \"queryId\", \"postId\" ],\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"inserter\": false,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": false,\n\t\t\t\"link\": false,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"__experimentalSelector\": \".wc-block-components-product-rating\"\n\t},\n\t\"ancestor\": [ \"woocommerce/single-product\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tAlignmentToolbar,\n\tBlockControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport { useEffect } from '@wordpress/element';\nimport { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport { BlockAttributes } from './types';\nimport { useIsDescendentOfSingleProductBlock } from '../shared/use-is-descendent-of-single-product-block';\nimport { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';\n\nconst Edit = (\n\tprops: BlockEditProps< BlockAttributes > & { context: Context }\n): JSX.Element => {\n\tconst { attributes, setAttributes, context } = props;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wp-block-woocommerce-product-rating',\n\t} );\n\tconst blockAttrs = {\n\t\t...attributes,\n\t\t...context,\n\t\tshouldDisplayMockedReviewsWhenProductHasNoReviews: true,\n\t};\n\tconst isDescendentOfQueryLoop = Number.isFinite( context.queryId );\n\tconst { isDescendentOfSingleProductBlock } =\n\t\tuseIsDescendentOfSingleProductBlock( {\n\t\t\tblockClientId: blockProps?.id,\n\t\t} );\n\tlet { isDescendentOfSingleProductTemplate } =\n\t\tuseIsDescendentOfSingleProductTemplate();\n\n\tif ( isDescendentOfQueryLoop || isDescendentOfSingleProductBlock ) {\n\t\tisDescendentOfSingleProductTemplate = false;\n\t}\n\n\tuseEffect( () => {\n\t\tsetAttributes( {\n\t\t\tisDescendentOfQueryLoop,\n\t\t\tisDescendentOfSingleProductBlock,\n\t\t\tisDescendentOfSingleProductTemplate,\n\t\t} );\n\t}, [\n\t\tsetAttributes,\n\t\tisDescendentOfQueryLoop,\n\t\tisDescendentOfSingleProductBlock,\n\t\tisDescendentOfSingleProductTemplate,\n\t] );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<AlignmentToolbar\n\t\t\t\t\tvalue={ attributes.textAlign }\n\t\t\t\t\tonChange={ ( newAlign ) => {\n\t\t\t\t\t\tsetAttributes( { textAlign: newAlign || '' } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Block { ...blockAttrs } />\n\t\t\t</div>\n\t\t</>\n\t);\n};\n\nexport default Edit;\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Display a post's comments count. with these attributes: text align"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/post-comments-count/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-comments-count\",\n\t\"title\": \"Comments Count\",\n\t\"category\": \"theme\",\n\t\"description\": \"Display a post's comments count.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\" ],\n\t\"example\": {\n\t\t\"viewportWidth\": 350\n\t},\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-post-comments-count\"\n}\n\n\n// File: packages/block-library/src/post-comments-count/index.js\n/**\n * WordPress dependencies\n */\nimport { postCommentsCount as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport transforms from './transforms';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\ttransforms,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Shows the cart fee row. that allows users to configure: class name, lock"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-fee/block.json\n{\n\t\"name\": \"woocommerce/checkout-order-summary-fee-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Fees\",\n\t\"description\": \"Shows the cart fee row.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-order-summary-totals-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-fee/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\n\nexport const Edit = ( {\n\tattributes,\n}: {\n\tattributes: {\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst { className } = attributes;\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Block className={ className } />\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a custom Gutenberg block that Add an email address, phone number, and physical address with improved markup for better SEO results."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/contact-info/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/contact-info\",\n\t\"title\": \"Contact Info\",\n\t\"description\": \"Add an email address, phone number, and physical address with improved markup for better SEO results.\",\n\t\"keywords\": [ \"email\", \"phone\", \"address\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M19 5v14H5V5h14m0-2H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7 9c-1.65 0-3-1.35-3-3s1.35-3 3-3 3 1.35 3 3-1.35 3-3 3zm0-4c-.55 0-1 .45-1 1s.45 1 1 1 1-.45 1-1-.45-1-1-1zm6 10H6v-1.53c0-2.5 3.97-3.58 6-3.58s6 1.08 6 3.58V18zm-9.69-2h7.38c-.69-.56-2.38-1.12-3.69-1.12s-3.01.56-3.69 1.12z'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"link\": true,\n\t\t\t\"gradients\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {},\n\t\t\"innerBlocks\": [\n\t\t\t{\n\t\t\t\t\"name\": \"jetpack/email\",\n\t\t\t\t\"attributes\": {\n\t\t\t\t\t\"email\": \"hello@yourjetpack.blog\"\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"name\": \"jetpack/phone\",\n\t\t\t\t\"attributes\": {\n\t\t\t\t\t\"phone\": \"123-456-7890\"\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"name\": \"jetpack/address\",\n\t\t\t\t\"attributes\": {\n\t\t\t\t\t\"address\": \"987 Photon Drive\",\n\t\t\t\t\t\"city\": \"Speedyville\",\n\t\t\t\t\t\"region\": \"CA\",\n\t\t\t\t\t\"postal\": \"12345\",\n\t\t\t\t\t\"country\": \"USA\"\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/contact-info/edit.js\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\nconst ALLOWED_BLOCKS = [\n\t'jetpack/markdown',\n\t'jetpack/address',\n\t'jetpack/email',\n\t'jetpack/phone',\n\t'jetpack/map',\n\t'jetpack/business-hours',\n\t'core/paragraph',\n\t'core/image',\n\t'core/heading',\n\t'core/gallery',\n\t'core/list',\n\t'core/quote',\n\t'core/shortcode',\n\t'core/audio',\n\t'core/code',\n\t'core/cover',\n\t'core/html',\n\t'core/separator',\n\t'core/spacer',\n\t'core/subhead',\n\t'core/video',\n];\n\nconst TEMPLATE = [ [ 'jetpack/email' ], [ 'jetpack/phone' ], [ 'jetpack/address' ] ];\n\nconst ContactInfoEdit = props => {\n\tconst { className, isSelected } = props;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( className, {\n\t\t\t'jetpack-contact-info-block': true,\n\t\t\t'is-selected': isSelected,\n\t\t} ),\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks allowedBlocks={ ALLOWED_BLOCKS } templateLock={ false } template={ TEMPLATE } />\n\t\t</div>\n\t);\n};\n\nexport default ContactInfoEdit;\n\n\n// File: projects/plugins/jetpack/extensions/blocks/contact-info/save.js\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nexport default () => {\n\tconst blockProps = useBlockProps.save();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a WordPress block template defining attribute names and configurations that can be universally applied across variable product attribute sets."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/attribute/block.json\n{\n\t\"name\": \"woocommerce/add-to-cart-with-options-variation-selector-attribute\",\n\t\"title\": \"Variation Selector: Template (Beta)\",\n\t\"description\": \"A template for attribute name and options that will be applied to all variable products with attributes.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"usesContext\": [ \"postId\" ],\n\t\"ancestor\": [ \"woocommerce/add-to-cart-with-options-variation-selector\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"supports\": {\n\t\t\"inserter\": false,\n\t\t\"interactivity\": true\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/attribute/edit.tsx\n/**\n * External dependencies\n */\nimport { useState } from '@wordpress/element';\nimport {\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n\t__experimentalUseBlockPreview as useBlockPreview,\n} from '@wordpress/block-editor';\nimport { BlockInstance, type BlockEditProps } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tCustomDataProvider,\n\tuseProductDataContext,\n} from '@woocommerce/shared-context';\nimport { isProductResponseItem } from '@woocommerce/entities';\n\n/**\n * Internal dependencies\n */\nimport { DEFAULT_ATTRIBUTES } from './constants';\n\ninterface Attributes {\n\tclassName?: string;\n}\n\ntype AttributeItemProps = {\n\tblocks: BlockInstance[];\n\tisSelected: boolean;\n\tonSelect(): void;\n};\n\nfunction AttributeItem( { blocks, isSelected, onSelect }: AttributeItemProps ) {\n\tconst blockPreviewProps = useBlockPreview( {\n\t\tblocks,\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{ role: 'listitem' },\n\t\t{ templateLock: 'insert' }\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ isSelected ? <div { ...innerBlocksProps } /> : <></> }\n\n\t\t\t<div\n\t\t\t\trole=\"listitem\"\n\t\t\t\tstyle={ { display: isSelected ? 'none' : undefined } }\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\t{ ...blockPreviewProps }\n\t\t\t\t\trole=\"button\"\n\t\t\t\t\ttabIndex={ 0 }\n\t\t\t\t\tonClick={ onSelect }\n\t\t\t\t\tonKeyDown={ onSelect }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default function AttributeItemTemplateEdit(\n\tprops: BlockEditProps< Attributes >\n) {\n\tconst { clientId } = props;\n\tconst { className } = props.attributes;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName,\n\t} );\n\n\tconst { product } = useProductDataContext();\n\n\tconst productAttributes =\n\t\tisProductResponseItem( product ) && product.type === 'variable'\n\t\t\t? product.attributes\n\t\t\t: DEFAULT_ATTRIBUTES;\n\n\tconst { blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlocks } = select( blockEditorStore );\n\t\t\treturn { blocks: getBlocks( clientId ) };\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst [ selectedAttributeItem, setSelectedAttributeItem ] =\n\t\tuseState< number >();\n\n\treturn (\n\t\t<div { ...blockProps } role=\"list\">\n\t\t\t{ productAttributes.map( ( attribute ) => (\n\t\t\t\t<CustomDataProvider\n\t\t\t\t\tkey={ attribute.id }\n\t\t\t\t\tid=\"attribute\"\n\t\t\t\t\tdata={ attribute }\n\t\t\t\t>\n\t\t\t\t\t<AttributeItem\n\t\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\t\tisSelected={\n\t\t\t\t\t\t\t( selectedAttributeItem ||\n\t\t\t\t\t\t\t\tproductAttributes[ 0 ]?.id ) === attribute.id\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonSelect={ () =>\n\t\t\t\t\t\t\tsetSelectedAttributeItem( attribute.id )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</CustomDataProvider>\n\t\t\t) ) }\n\t\t</div>\n\t);\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/attribute/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport default function AttributeItemTemplateSave() {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( {\n\t\t...blockProps,\n\t\trole: 'listitem',\n\t} );\n\treturn <div { ...innerBlocksProps } />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a woocommerce block with customizable class name, content, lock"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-heading/block.json\n{\n\t\"name\": \"woocommerce/cart-order-summary-heading-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Heading\",\n\t\"description\": \"Shows the heading row.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"content\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"Cart totals\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": false,\n\t\t\t\t\"move\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/cart-order-summary-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-heading/edit.tsx\n/**\n * External dependencies\n */\nimport { PlainText, useBlockProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: {\n\t\tcontent: string;\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst { content = '', className = '' } = attributes;\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<h2 className={ clsx( className, 'wc-block-cart__totals-title' ) }>\n\t\t\t\t<PlainText\n\t\t\t\t\tclassName={ '' }\n\t\t\t\t\tvalue={ content }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { content: value } )\n\t\t\t\t\t}\n\t\t\t\t\tstyle={ { backgroundColor: 'transparent' } }\n\t\t\t\t/>\n\t\t\t</h2>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a versatile Accordion header block that empowers users to personalize its appearance and behavior through options like initial display, title formatting, heading level, and four extra adjustable attributes."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/inner-blocks/accordion-header/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/accordion-header\",\n\t\"title\": \"Accordion Header\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"Accordion header.\",\n\t\"example\": {},\n\t\"__experimental\": true,\n\t\"parent\": [ \"woocommerce/accordion-item\" ],\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"gradient\": true\n\t\t},\n\t\t\"align\": false,\n\t\t\"border\": true,\n\t\t\"interactivity\": true,\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true,\n\t\t\t\t\"margin\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"textAlign\": true,\n\t\t\t\"fontSize\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true,\n\t\t\t\t\"fontFamily\": true\n\t\t\t}\n\t\t},\n\t\t\"shadow\": true,\n\t\t\"layout\": true\n\t},\n\t\"attributes\": {\n\t\t\"openByDefault\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"title\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"span\"\n\t\t},\n\t\t\"level\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t},\n\t\t\"levelOptions\": {\n\t\t\t\"type\": \"array\"\n\t\t},\n\t\t\"textAlignment\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"left\"\n\t\t},\n\t\t\"icon\": {\n\t\t\t\"type\": [ \"string\", \"boolean\" ],\n\t\t\t\"enum\": [\n\t\t\t\t\"plus\",\n\t\t\t\t\"chevron\",\n\t\t\t\t\"chevronRight\",\n\t\t\t\t\"caret\",\n\t\t\t\t\"circlePlus\",\n\t\t\t\tfalse\n\t\t\t],\n\t\t\t\"default\": \"plus\"\n\t\t},\n\t\t\"iconPosition\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [ \"left\", \"right\" ],\n\t\t\t\"default\": \"right\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/inner-blocks/accordion-header/index.js\n/**\n * External dependencies\n */\nimport { SVG, Path } from '@wordpress/components';\nimport { registerBlockType } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport edit from './edit';\nimport save from './save';\nimport metadata from './block.json';\n\nconst icon = (\n\t<SVG\n\t\twidth=\"24\"\n\t\theight=\"24\"\n\t\tviewBox=\"0 0 24 24\"\n\t\tfill=\"none\"\n\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t>\n\t\t<Path\n\t\t\tfillRule=\"evenodd\"\n\t\t\tclipRule=\"evenodd\"\n\t\t\td=\"M19.5 12.75L9.5 12.75L9.5 11.25L19.5 11.25L19.5 12.75Z\"\n\t\t\tfill=\"currentColor\"\n\t\t/>\n\t\t<Path d=\"M4.5 9.5L8.5 12L4.5 14.5L4.5 9.5Z\" fill=\"currentColor\" />\n\t</SVG>\n);\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\tapiVersion: 3,\n\ticon,\n\texample: {},\n\tedit,\n\tsave,\n};\n\nregisterBlockType( metadata, settings );\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/inner-blocks/accordion-header/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport {\n\tuseBlockProps,\n\t__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,\n\t__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,\n\t__experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles,\n\t__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,\n\tRichText,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport {\n\tcaret,\n\tchevron,\n\tchevronRight,\n\tcirclePlus,\n\tplus,\n} from '../accordion-item/icons';\n\nconst ICONS = {\n\tplus,\n\tcirclePlus,\n\tchevron,\n\tchevronRight,\n\tcaret,\n};\n\nexport default function save( { attributes } ) {\n\tconst { level, title, iconPosition, textAlign, icon } = attributes;\n\tconst TagName = 'h' + level;\n\n\tconst blockProps = useBlockProps.save();\n\tconst borderProps = getBorderClassesAndStyles( attributes );\n\tconst colorProps = getColorClassesAndStyles( attributes );\n\tconst spacingProps = getSpacingClassesAndStyles( attributes );\n\tconst shadowProps = getShadowClassesAndStyles( attributes );\n\n\tconst Icon = ICONS[ icon ];\n\n\treturn (\n\t\t<TagName\n\t\t\t{ ...blockProps }\n\t\t\tclassName={ clsx(\n\t\t\t\tblockProps.className,\n\t\t\t\tcolorProps.className,\n\t\t\t\tborderProps.className,\n\t\t\t\t'accordion-item__heading',\n\t\t\t\t{\n\t\t\t\t\t[ `has-custom-font-size` ]: blockProps?.style?.fontSize,\n\t\t\t\t\t[ `icon-position-left` ]: iconPosition === 'left',\n\t\t\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t\t\t}\n\t\t\t) }\n\t\t\tstyle={ {\n\t\t\t\t...borderProps.style,\n\t\t\t\t...colorProps.style,\n\t\t\t\t...shadowProps.style,\n\t\t\t} }\n\t\t>\n\t\t\t<button\n\t\t\t\tclassName={ clsx( 'accordion-item__toggle' ) }\n\t\t\t\tstyle={ {\n\t\t\t\t\t...spacingProps.style,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<RichText.Content tagName=\"span\" value={ title } />\n\t\t\t\t<span\n\t\t\t\t\tclassName={ clsx( `accordion-item__toggle-icon`, {\n\t\t\t\t\t\t[ `has-icon-${ icon }` ]: icon,\n\t\t\t\t\t} ) }\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t// TO-DO: make this configurable\n\t\t\t\t\t\twidth: `1.2em`,\n\t\t\t\t\t\theight: `1.2em`,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ icon && <Icon width=\"1.2em\" height=\"1.2em\" /> }\n\t\t\t\t</span>\n\t\t\t</button>\n\t\t</TagName>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a woocommerce block with customizable text align"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-content/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-review-content\",\n\t\"title\": \"Review Content\",\n\t\"category\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/product-reviews\" ],\n\t\"description\": \"Displays the contents of a product review.\",\n\t\"textdomain\": \"woocommerce\",\n\t\"usesContext\": [ \"commentId\" ],\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": [ \"horizontal\", \"vertical\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true\n\t\t\t}\n\t\t},\n\t\t\"html\": false\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-content/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { _x } from '@wordpress/i18n';\nimport { RawHTML } from '@wordpress/element';\nimport { Disabled } from '@wordpress/components';\nimport { useEntityProp } from '@wordpress/core-data';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport {\n\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t// @ts-ignore No types for this exist yet.\n\tAlignmentControl,\n\tBlockControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\n\nexport default function Edit( {\n\tsetAttributes,\n\tattributes: { textAlign },\n\tcontext: { commentId },\n}: BlockEditProps< {\n\ttextAlign: string;\n} > & {\n\tcontext: { commentId: number };\n} ) {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t} );\n\n\tconst [ content ] = useEntityProp(\n\t\t'root',\n\t\t'comment',\n\t\t'content',\n\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t// @ts-expect-error - the type of useEntityProp is not correct\n\t\tcommentId\n\t);\n\n\tconst blockControls = (\n\t\t<BlockControls>\n\t\t\t<AlignmentControl\n\t\t\t\tvalue={ textAlign }\n\t\t\t\tonChange={ ( newAlign: string | undefined ) => {\n\t\t\t\t\tif ( newAlign !== undefined ) {\n\t\t\t\t\t\tsetAttributes( { textAlign: newAlign } );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t/>\n\t\t</BlockControls>\n\t);\n\n\tif ( ! commentId || ! content ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ blockControls }\n\t\t\t\t<div { ...blockProps }>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ _x( 'Review Content', 'block title', 'woocommerce' ) }\n\t\t\t\t\t</p>\n\t\t\t\t</div>\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ blockControls }\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Disabled>\n\t\t\t\t\t<RawHTML key=\"html\">{ content.rendered }</RawHTML>\n\t\t\t\t</Disabled>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a woocommerce block with customizable is preview, mini cart icon, add to cart behaviour, and 10 more options"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/block.json\n{\n\t\"name\": \"woocommerce/mini-cart\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Mini-Cart\",\n\t\"icon\": \"miniCartAlt\",\n\t\"description\": \"Display a button for shoppers to quickly view their cart.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"isPreview\": true,\n\t\t\t\"className\": \"wc-block-mini-cart--preview\"\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"isPreview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"miniCartIcon\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"cart\"\n\t\t},\n\t\t\"addToCartBehaviour\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"none\"\n\t\t},\n\t\t\"onCartClickBehaviour\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"open_drawer\"\n\t\t},\n\t\t\"hasHiddenPrice\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"cartAndCheckoutRenderStyle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"hidden\"\n\t\t},\n\t\t\"priceColor\": {\n\t\t\t\"type\": \"object\"\n\t\t},\n\t\t\"priceColorValue\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"iconColor\": {\n\t\t\t\"type\": \"object\"\n\t\t},\n\t\t\"iconColorValue\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"productCountColor\": {\n\t\t\t\"type\": \"object\"\n\t\t},\n\t\t\"productCountColorValue\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"productCountVisibility\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"greater_than_zero\"\n\t\t}\n\t},\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/edit.tsx\n/* eslint-disable @wordpress/no-unsafe-wp-apis */\n/**\n * External dependencies\n */\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { formatPrice } from '@woocommerce/price-format';\nimport {\n\tPanelBody,\n\tExternalLink,\n\tToggleControl,\n\tBaseControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\tRadioControl,\n} from '@wordpress/components';\nimport { getSetting } from '@woocommerce/settings';\nimport { __, isRTL } from '@wordpress/i18n';\nimport Noninteractive from '@woocommerce/base-components/noninteractive';\nimport { isSiteEditorPage } from '@woocommerce/utils';\nimport type { ReactElement } from 'react';\nimport { useRef } from '@wordpress/element';\nimport { cartOutline, bag, bagAlt } from '@woocommerce/icons';\nimport { Icon } from '@wordpress/icons';\nimport { WC_BLOCKS_IMAGE_URL } from '@woocommerce/block-settings';\nimport { ColorPanel } from '@woocommerce/editor-components/color-panel';\nimport type { ColorPaletteOption } from '@woocommerce/editor-components/color-panel/types';\n\n/**\n * Internal dependencies\n */\nimport QuantityBadge from './quantity-badge';\nimport { defaultColorItem } from './utils/defaults';\nimport { migrateAttributesToColorPanel } from './utils/data';\nimport './editor.scss';\nimport { useThemeColors } from '../../shared/hooks/use-theme-colors';\n\nexport interface Attributes {\n\tminiCartIcon: 'cart' | 'bag' | 'bag-alt';\n\taddToCartBehaviour: string;\n\tonCartClickBehaviour: 'navigate_to_checkout' | 'open_drawer';\n\thasHiddenPrice: boolean;\n\tcartAndCheckoutRenderStyle: boolean;\n\tpriceColor: ColorPaletteOption;\n\ticonColor: ColorPaletteOption;\n\tproductCountColor: ColorPaletteOption;\n\tproductCountVisibility: 'always' | 'never' | 'greater_than_zero';\n}\n\ninterface Props {\n\tattributes: Attributes;\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n\tclientId: number;\n\tsetPriceColor: ( colorValue: string | undefined ) => void;\n\tsetIconColor: ( colorValue: string | undefined ) => void;\n\tsetProductCountColor: ( colorValue: string | undefined ) => void;\n}\n\nconst Edit = ( { attributes, setAttributes }: Props ): ReactElement => {\n\tconst {\n\t\tcartAndCheckoutRenderStyle,\n\t\taddToCartBehaviour,\n\t\tonCartClickBehaviour,\n\t\thasHiddenPrice,\n\t\tpriceColor = defaultColorItem,\n\t\ticonColor = defaultColorItem,\n\t\tproductCountColor = defaultColorItem,\n\t\tminiCartIcon,\n\t\tproductCountVisibility,\n\t} = migrateAttributesToColorPanel( attributes );\n\tconst miniCartButtonRef = useRef< HTMLButtonElement >( null );\n\n\tconst miniCartColorAttributes = {\n\t\tpriceColor: {\n\t\t\tlabel: __( 'Price', 'woocommerce' ),\n\t\t\tcontext: 'price-color',\n\t\t},\n\t\ticonColor: {\n\t\t\tlabel: __( 'Icon', 'woocommerce' ),\n\t\t\tcontext: 'icon-color',\n\t\t},\n\t\tproductCountColor: {\n\t\t\tlabel: __( 'Product Count', 'woocommerce' ),\n\t\t\tcontext: 'product-count-color',\n\t\t},\n\t};\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wc-block-mini-cart',\n\t} );\n\n\tconst isSiteEditor = isSiteEditorPage();\n\n\tconst templatePartEditUri = getSetting(\n\t\t'templatePartEditUri',\n\t\t''\n\t) as string;\n\n\t// Apply Mini Cart quantity badge styles based on Site Editor's background and text colors.\n\t// We need to set `span` in the selector so it has more specificity than the CSS.\n\tuseThemeColors(\n\t\t'mini-cart-badge',\n\t\t( { editorBackgroundColor, editorColor } ) => `\n\t\t\tspan:where(.wc-block-mini-cart__badge) {\n\t\t\t\tcolor: ${ editorBackgroundColor };\n\t\t\t\tbackground-color: ${ editorColor };\n\t\t\t}\n\t\t`\n\t);\n\n\tconst productCount =\n\t\tproductCountVisibility === 'never' ||\n\t\tproductCountVisibility === 'always'\n\t\t\t? 0\n\t\t\t: 2;\n\n\tconst productTotal = 0;\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Settings', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"wc-block-editor-mini-cart__cart-icon-toggle\"\n\t\t\t\t\t\tisBlock\n\t\t\t\t\t\tlabel={ __( 'Cart Icon', 'woocommerce' ) }\n\t\t\t\t\t\tvalue={ miniCartIcon }\n\t\t\t\t\t\tonChange={ ( value: 'cart' | 'bag' | 'bag-alt' ) => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tminiCartIcon: value,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue={ 'cart' }\n\t\t\t\t\t\t\tlabel={ <Icon size={ 32 } icon={ cartOutline } /> }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue={ 'bag' }\n\t\t\t\t\t\t\tlabel={ <Icon size={ 32 } icon={ bag } /> }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue={ 'bag-alt' }\n\t\t\t\t\t\t\tlabel={ <Icon size={ 32 } icon={ bagAlt } /> }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t<BaseControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tid=\"wc-block-mini-cart__display-toggle\"\n\t\t\t\t\t\tlabel={ __( 'Display', 'woocommerce' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tlabel={ __( 'Display total price', 'woocommerce' ) }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Toggle to display the total price of products in the shopping cart. If no products have been added, the price will not display.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tchecked={ ! hasHiddenPrice }\n\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\thasHiddenPrice: ! hasHiddenPrice,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BaseControl>\n\t\t\t\t\t<BaseControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tid=\"wc-block-mini-cart__product-count-basecontrol\"\n\t\t\t\t\t\tlabel={ __( 'Show Cart Item Count:', 'woocommerce' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<RadioControl\n\t\t\t\t\t\t\tclassName=\"wc-block-mini-cart__product-count-radiocontrol\"\n\t\t\t\t\t\t\tselected={ productCountVisibility }\n\t\t\t\t\t\t\toptions={ [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: __(\n\t\t\t\t\t\t\t\t\t\t'Always (even if empty)',\n\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\tvalue: 'always',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: __(\n\t\t\t\t\t\t\t\t\t\t'Only if cart has items',\n\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\tvalue: 'greater_than_zero',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: __( 'Never', 'woocommerce' ),\n\t\t\t\t\t\t\t\t\tvalue: 'never',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t] }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'The editor does not display the real count value, but a placeholder to indicate how it will look on the front-end.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tproductCountVisibility: value,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BaseControl>\n\t\t\t\t\t{ isSiteEditor && (\n\t\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tclassName=\"wc-block-editor-mini-cart__render-in-cart-and-checkout-toggle\"\n\t\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t\t'Mini-Cart in cart and checkout pages',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tvalue={ cartAndCheckoutRenderStyle }\n\t\t\t\t\t\t\tonChange={ ( value: boolean ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tcartAndCheckoutRenderStyle: value,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Select how the Mini-Cart behaves in the Cart and Checkout pages. This might affect the header layout.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue={ 'hidden' }\n\t\t\t\t\t\t\t\tlabel={ __( 'Hide', 'woocommerce' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue={ 'removed' }\n\t\t\t\t\t\t\t\tlabel={ __( 'Remove', 'woocommerce' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t) }\n\t\t\t\t</PanelBody>\n\t\t\t\t<PanelBody title={ __( 'Cart Drawer', 'woocommerce' ) }>\n\t\t\t\t\t{ templatePartEditUri && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\tclassName=\"wc-block-editor-mini-cart__drawer-image\"\n\t\t\t\t\t\t\t\tsrc={\n\t\t\t\t\t\t\t\t\tisRTL()\n\t\t\t\t\t\t\t\t\t\t? `${ WC_BLOCKS_IMAGE_URL }blocks/mini-cart/cart-drawer-rtl.svg`\n\t\t\t\t\t\t\t\t\t\t: `${ WC_BLOCKS_IMAGE_URL }blocks/mini-cart/cart-drawer.svg`\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t'When opened, the Mini-Cart drawer gives shoppers quick access to view their selected products and checkout.',\n\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t<p className=\"wc-block-editor-mini-cart__drawer-link\">\n\t\t\t\t\t\t\t\t<ExternalLink href={ templatePartEditUri }>\n\t\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t\t'Edit Mini-Cart Drawer template',\n\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t\t<BaseControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tid=\"wc-block-mini-cart__add-to-cart-behaviour-toggle\"\n\t\t\t\t\t\tlabel={ __( 'Behavior', 'woocommerce' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t\t'Open drawer when adding',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\taddToCartBehaviour: value\n\t\t\t\t\t\t\t\t\t\t? 'open_drawer'\n\t\t\t\t\t\t\t\t\t\t: 'none',\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Toggle to open the Mini-Cart drawer when a shopper adds a product to their cart.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tchecked={ addToCartBehaviour === 'open_drawer' }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t\t'Navigate to checkout when clicking the Mini-Cart, instead of opening the drawer.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tonCartClickBehaviour: value\n\t\t\t\t\t\t\t\t\t\t? 'navigate_to_checkout'\n\t\t\t\t\t\t\t\t\t\t: 'open_drawer',\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Toggle to disable opening the Mini-Cart drawer when clicking the cart icon, and instead navigate to the checkout page.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tchecked={\n\t\t\t\t\t\t\t\tonCartClickBehaviour === 'navigate_to_checkout'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BaseControl>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<ColorPanel\n\t\t\t\tcolorTypes={ miniCartColorAttributes }\n\t\t\t\tminiCartButtonRef={ miniCartButtonRef }\n\t\t\t/>\n\t\t\t<Noninteractive>\n\t\t\t\t<button\n\t\t\t\t\tref={ miniCartButtonRef }\n\t\t\t\t\tclassName=\"wc-block-mini-cart__button\"\n\t\t\t\t>\n\t\t\t\t\t<QuantityBadge\n\t\t\t\t\t\tcount={ productCount }\n\t\t\t\t\t\ticonColor={ iconColor }\n\t\t\t\t\t\tproductCountColor={ productCountColor }\n\t\t\t\t\t\ticon={ miniCartIcon }\n\t\t\t\t\t\tproductCountVisibility={ productCountVisibility }\n\t\t\t\t\t/>\n\t\t\t\t\t{ ! hasHiddenPrice && (\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"wc-block-mini-cart__amount\"\n\t\t\t\t\t\t\tstyle={ { color: priceColor.color } }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ formatPrice( productTotal ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) }\n\t\t\t\t</button>\n\t\t\t</Noninteractive>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Block that displays the 'Your cart' part of the Mini-Cart Title block. that allows users to configure: label"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-title-label-block/block.json\n{\n\t\"name\": \"woocommerce/mini-cart-title-label-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Mini-Cart Title Label\",\n\t\"description\": \"Block that displays the 'Your cart' part of the Mini-Cart Title block.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"label\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"parent\": [ \"woocommerce/mini-cart-title-block\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-title-label-block/edit.tsx\n/**\n * External dependencies\n */\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\n\ninterface Attributes {\n\tattributes: {\n\t\tlabel: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n}\n\nexport const Edit = ( {\n\tattributes: { label },\n\tsetAttributes,\n}: Attributes ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\n\treturn (\n\t\t<span { ...blockProps }>\n\t\t\t<RichText\n\t\t\t\tallowedFormats={ [] }\n\t\t\t\tvalue={ label }\n\t\t\t\tonChange={ ( newLabel ) =>\n\t\t\t\t\tsetAttributes( { label: newLabel } )\n\t\t\t\t}\n\t\t\t/>\n\t\t</span>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() }></div>;\n};\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a WooCommerce product block that allows flexible styling of product element options with user-friendly customization controls."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/attribute-options/block.json\n{\n\t\"name\": \"woocommerce/add-to-cart-with-options-variation-selector-attribute-options\",\n\t\"title\": \"Variation Selector: Attribute Options (Beta)\",\n\t\"description\": \"Display the attribute options associated with a variable product.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"ancestor\": [\n\t\t\"woocommerce/add-to-cart-with-options-variation-selector-attribute\"\n\t],\n\t\"attributes\": {\n\t\t\"optionStyle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [ \"pills\", \"dropdown\" ]\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"supports\": {\n\t\t\"inserter\": false,\n\t\t\"interactivity\": true\n\t},\n\t\"usesContext\": [\n\t\t\"woocommerce/attributeId\",\n\t\t\"woocommerce/attributeName\",\n\t\t\"woocommerce/attributeTerms\"\n\t],\n\t\"style\": \"file:../woocommerce/add-to-cart-with-options-variation-selector-attribute-options-style.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/attribute-options/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { type BlockEditProps } from '@wordpress/blocks';\nimport {\n\tDisabled,\n\tPanelBody,\n\tSelectControl,\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\nimport { useCustomDataContext } from '@woocommerce/shared-context';\nimport type { ProductResponseAttributeItem } from '@woocommerce/types';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport { useThemeColors } from '../../../../shared/hooks/use-theme-colors';\n\ninterface Attributes {\n\tclassName?: string;\n\toptionStyle?: 'pills' | 'dropdown';\n}\n\nfunction Pills( {\n\tid,\n\toptions,\n}: {\n\tid: string;\n\toptions: SelectControl.Option[];\n} ) {\n\treturn (\n\t\t<ul\n\t\t\tid={ id }\n\t\t\tclassName=\"wc-block-add-to-cart-with-options-variation-selector-attribute-options__pills\"\n\t\t>\n\t\t\t{ options.map( ( option, index ) => (\n\t\t\t\t<li\n\t\t\t\t\tkey={ option.value }\n\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t'wc-block-add-to-cart-with-options-variation-selector-attribute-options__pill',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'wc-block-add-to-cart-with-options-variation-selector-attribute-options__pill--selected':\n\t\t\t\t\t\t\t\tindex === 0,\n\t\t\t\t\t\t\t'wc-block-add-to-cart-with-options-variation-selector-attribute-options__pill--disabled':\n\t\t\t\t\t\t\t\toption.disabled,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t>\n\t\t\t\t\t{ option.label }\n\t\t\t\t</li>\n\t\t\t) ) }\n\t\t</ul>\n\t);\n}\n\nexport default function AttributeOptionsEdit(\n\tprops: BlockEditProps< Attributes >\n) {\n\tconst { attributes, setAttributes } = props;\n\tconst { className, optionStyle } = attributes;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName,\n\t} );\n\n\t// Apply selected variation pill styles based on Site Editor's background and text colors.\n\tuseThemeColors(\n\t\t'add-to-cart-with-options-variation-selector-attribute-options',\n\t\t( { editorBackgroundColor, editorColor } ) => `\n\t\t\t:where(.wc-block-add-to-cart-with-options-variation-selector-attribute-options__pill--selected) {\n\t\t\t\t--pill-color: ${ editorBackgroundColor };\n\t\t\t\t--pill-background-color: ${ editorColor };\n\t\t\t}\n\t\t`\n\t);\n\n\tconst { data: attribute } =\n\t\tuseCustomDataContext< ProductResponseAttributeItem >( 'attribute' );\n\n\tif ( ! attribute ) return null;\n\n\tconst options = attribute.terms.map( ( term, index ) => ( {\n\t\tvalue: term.slug,\n\t\tlabel: term.name,\n\t\tdisabled: index > 1 && index === attribute.terms.length - 1,\n\t} ) );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Style', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\tlabel={ __( 'Style', 'woocommerce' ) }\n\t\t\t\t\t\tvalue={ optionStyle ?? 'pills' }\n\t\t\t\t\t\tonChange={ ( newOptionStyle ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnewOptionStyle === 'pills' ||\n\t\t\t\t\t\t\t\tnewOptionStyle === 'dropdown'\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\toptionStyle: newOptionStyle,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisBlock\n\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\tsize=\"__unstable-large\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"pills\"\n\t\t\t\t\t\t\tlabel={ __( 'Pills', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"dropdown\"\n\t\t\t\t\t\t\tlabel={ __( 'Dropdown', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\n\t\t\t<Disabled>\n\t\t\t\t{ optionStyle === 'dropdown' ? (\n\t\t\t\t\t<select\n\t\t\t\t\t\tid={ attribute.taxonomy }\n\t\t\t\t\t\tclassName=\"wc-block-add-to-cart-with-options-variation-selector-attribute-options__dropdown\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ options.map( ( option ) => (\n\t\t\t\t\t\t\t<option key={ option.value } value={ option.value }>\n\t\t\t\t\t\t\t\t{ option.label }\n\t\t\t\t\t\t\t</option>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</select>\n\t\t\t\t) : (\n\t\t\t\t\t<Pills id={ attribute.taxonomy } options={ options } />\n\t\t\t\t) }\n\t\t\t</Disabled>\n\t\t</div>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a WordPress block enabling users to showcase followed websites with customizable display settings including avatar visibility, site description, link behavior, and two additional configurable options."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/blogroll/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/blogroll\",\n\t\"title\": \"Blogroll\",\n\t\"description\": \"Share the sites you follow with your users.\",\n\t\"keywords\": [],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg width='24' height='24' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path d='M4.08691 16.2412H20.0869V14.7412H4.08691V16.2412Z'></path><path d='M4.08691 20.2412H13.0869V18.7412H4.08691V20.2412Z'></path><path fill-rule='evenodd' clip-rule='evenodd' d='M4.08691 8.17871C4.08691 6.00409 5.84979 4.24121 8.02441 4.24121C10.199 4.24121 11.9619 6.00409 11.9619 8.17871C11.9619 10.3533 10.199 12.1162 8.02441 12.1162C5.84979 12.1162 4.08691 10.3533 4.08691 8.17871ZM5.10729 6.71621C5.51231 5.90991 6.2418 5.29471 7.12439 5.04194C6.91534 5.28455 6.73551 5.57108 6.58869 5.88606C6.46938 6.14205 6.36999 6.42056 6.29338 6.71621H5.10729ZM4.85759 7.39121C4.79508 7.64341 4.76191 7.90719 4.76191 8.17871C4.76191 8.45024 4.79508 8.71401 4.85759 8.96621H6.16284C6.12938 8.71126 6.11192 8.44782 6.11192 8.1787C6.11192 7.90956 6.12938 7.64614 6.16284 7.39121H4.85759ZM6.84439 7.39121C6.80693 7.64285 6.78692 7.90651 6.78692 8.1787C6.78692 8.45091 6.80694 8.71459 6.84439 8.96621H9.20444C9.2419 8.71458 9.26192 8.45091 9.26192 8.17873C9.26192 7.90653 9.2419 7.64285 9.20444 7.39121H6.84439ZM9.88599 7.39121C9.91945 7.64615 9.93692 7.90958 9.93692 8.17873C9.93692 8.44786 9.91945 8.71128 9.88599 8.96621H11.1912C11.2537 8.71401 11.2869 8.45024 11.2869 8.17871C11.2869 7.90719 11.2537 7.64341 11.1912 7.39121H9.88599ZM10.9415 6.71621H9.75544C9.67883 6.42057 9.57945 6.14207 9.46014 5.88609C9.31332 5.5711 9.13347 5.28455 8.92441 5.04193C9.80702 5.29469 10.5365 5.9099 10.9415 6.71621ZM9.05465 6.71621H6.99417C7.05245 6.52254 7.12177 6.34014 7.2005 6.17123C7.42342 5.69296 7.71302 5.34019 8.02439 5.13337C8.33578 5.34019 8.6254 5.69297 8.84833 6.17126C8.92706 6.34016 8.99637 6.52255 9.05465 6.71621ZM5.10729 9.64121H6.29339C6.37419 9.95305 6.48034 10.2458 6.6085 10.5132C6.75142 10.8114 6.92452 11.0835 7.12445 11.3155C6.24183 11.0627 5.51232 10.4475 5.10729 9.64121ZM9.05466 9.64121H6.99418C7.05655 9.84847 7.13156 10.0428 7.21721 10.2215C7.43825 10.6827 7.72115 11.0226 8.02446 11.224C8.33582 11.0172 8.62541 10.6645 8.84833 10.1862C8.92706 10.0173 8.99638 9.83488 9.05466 9.64121ZM9.46014 10.4714C9.57945 10.2154 9.67884 9.93686 9.75545 9.64121H10.9415C10.5365 10.4475 9.80703 11.0627 8.92444 11.3155C9.13349 11.0729 9.31332 10.7863 9.46014 10.4714Z'></path></svg>\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"alignWide\": true,\n\t\t\"anchor\": false,\n\t\t\"customClassName\": true,\n\t\t\"className\": true,\n\t\t\"html\": false,\n\t\t\"multiple\": true,\n\t\t\"reusable\": true,\n\t\t\"color\": {\n\t\t\t\"link\": true,\n\t\t\t\"gradients\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"show_avatar\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"show_description\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"open_links_new_window\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"ignore_user_blogs\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"load_placeholders\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"showAvatar\": \"show_avatar\",\n\t\t\"showDescription\": \"show_description\",\n\t\t\"openLinksNewWindow\": \"open_links_new_window\"\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/blogroll/edit.js\nimport { InspectorControls, useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { createBlock } from '@wordpress/blocks';\nimport { PanelBody, ToggleControl, FlexBlock, Spinner, Notice } from '@wordpress/components';\nimport { dispatch } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport ConnectBanner from '../../shared/components/connect-banner';\nimport useIsUserConnected from '../../shared/use-is-user-connected';\nimport BlogrollAppender from './components/blogroll-appender';\nimport useRecommendations from './use-recommendations';\nimport { useSiteRecommendationSync } from './use-site-recommendations';\nimport useSubscriptions from './use-subscriptions';\nimport { createBlockFromRecommendation } from './utils';\nimport './editor.scss';\n\nexport function BlogRollEdit( { className, attributes, setAttributes, clientId } ) {\n\tconst {\n\t\tshow_avatar,\n\t\tshow_description,\n\t\topen_links_new_window,\n\t\tignore_user_blogs,\n\t\tload_placeholders,\n\t} = attributes;\n\n\tconst isUserConnected = useIsUserConnected();\n\n\tconst {\n\t\tisLoading: isLoadingRecommendations,\n\t\trecommendations,\n\t\terrorMessage: recommendationsErrorMessage,\n\t} = useRecommendations( load_placeholders );\n\tconst {\n\t\tisLoading: isLoadingSubscriptions,\n\t\tsubscriptions,\n\t\terrorMessage: subscriptionsErrorMessage,\n\t} = useSubscriptions( {\n\t\tignore_user_blogs,\n\t} );\n\tuseSiteRecommendationSync( { clientId } );\n\tconst { replaceInnerBlocks } = dispatch( 'core/block-editor' );\n\n\tuseEffect( () => {\n\t\tif ( load_placeholders && recommendations.length ) {\n\t\t\tsetAttributes( { load_placeholders: false } );\n\n\t\t\tconst blocks = [\n\t\t\t\tcreateBlock( 'core/heading', { content: __( 'Blogroll', 'jetpack' ), level: 3 } ),\n\t\t\t\t...recommendations.map( createBlockFromRecommendation ),\n\t\t\t];\n\t\t\treplaceInnerBlocks( clientId, blocks );\n\t\t}\n\t}, [ recommendations, load_placeholders, setAttributes, clientId, replaceInnerBlocks ] );\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( className, {\n\t\t\t'hide-avatar': ! show_avatar,\n\t\t\t'hide-description': ! show_description,\n\t\t} ),\n\t} );\n\n\tif ( ! isUserConnected ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<ConnectBanner\n\t\t\t\t\tblock=\"Blogroll\"\n\t\t\t\t\texplanation={ __(\n\t\t\t\t\t\t'Connect your WordPress.com account to use the Blogroll block.',\n\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t}\n\n\tconst errorMessage = recommendationsErrorMessage || subscriptionsErrorMessage;\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks\n\t\t\t\ttemplate={ [ [ 'core/heading', { content: __( 'Blogroll', 'jetpack' ), level: 3 } ] ] }\n\t\t\t\tallowedBlocks={ [ 'jetpack/blogroll-item' ] }\n\t\t\t\trenderAppender={ () =>\n\t\t\t\t\t! isLoadingRecommendations && (\n\t\t\t\t\t\t<BlogrollAppender\n\t\t\t\t\t\t\tisLoading={ isLoadingSubscriptions }\n\t\t\t\t\t\t\tsubscriptions={ subscriptions }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t/>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t/>\n\n\t\t\t{ errorMessage && (\n\t\t\t\t<Notice status=\"error\" isDismissible={ false }>\n\t\t\t\t\t<p>{ errorMessage }</p>\n\t\t\t\t</Notice>\n\t\t\t) }\n\n\t\t\t{ load_placeholders && isLoadingRecommendations && (\n\t\t\t\t<FlexBlock style={ { padding: '30px', textAlign: 'center' } }>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</FlexBlock>\n\t\t\t) }\n\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Settings', 'jetpack' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show avatar', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ !! show_avatar }\n\t\t\t\t\t\tonChange={ () => setAttributes( { show_avatar: ! show_avatar } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show description', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ !! show_description }\n\t\t\t\t\t\tonChange={ () => setAttributes( { show_description: ! show_description } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Open links in a new window', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ !! open_links_new_window }\n\t\t\t\t\t\tonChange={ () => setAttributes( { open_links_new_window: ! open_links_new_window } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Hide my own sites', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ !! ignore_user_blogs }\n\t\t\t\t\t\tonChange={ () => setAttributes( { ignore_user_blogs: ! ignore_user_blogs } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t</div>\n\t);\n}\n\nexport default BlogRollEdit;\n\n\n// File: projects/plugins/jetpack/extensions/blocks/blogroll/save.js\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\nexport function BlogRollSave( { attributes: { show_avatar, show_description }, className } ) {\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: clsx( className, {\n\t\t\t'hide-avatar': ! show_avatar,\n\t\t\t'hide-description': ! show_description,\n\t\t} ),\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n}\n\nexport default BlogRollSave;\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Develop a block for Displays a title with the number of comments. that allows users to configure: text align, show post title, show comments count, and 2 more options"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/comments-title/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/comments-title\",\n\t\"title\": \"Comments Title\",\n\t\"category\": \"theme\",\n\t\"ancestor\": [ \"core/comments\" ],\n\t\"description\": \"Displays a title with the number of comments.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"postId\", \"postType\" ],\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"showPostTitle\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showCommentsCount\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"level\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 2\n\t\t},\n\t\t\"levelOptions\": {\n\t\t\t\"type\": \"array\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": false,\n\t\t\"align\": true,\n\t\t\"html\": false,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true,\n\t\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\t\"__experimentalFontWeight\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t}\n}\n\n\n// File: packages/block-library/src/comments-title/index.js\n/**\n * WordPress dependencies\n */\nimport { title as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport deprecated from './deprecated';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tdeprecated,\n\texample: {},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a embed block with customizable service, label"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/sharing-button/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/sharing-button\",\n\t\"title\": \"Sharing Button\",\n\t\"description\": \"Display a sharing button, allowing users to share your post.\",\n\t\"keywords\": [],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"embed\",\n\t\"parent\": [ \"jetpack/sharing-buttons\" ],\n\t\"attributes\": {\n\t\t\"service\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"label\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"styleType\", \"postId\", \"iconColorValue\", \"iconBackgroundColorValue\" ],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false\n\t},\n\t\"viewScript\": \"file:./view.js\"\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/sharing-button/edit.js\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { Button } from '@wordpress/components';\nimport clsx from 'clsx';\nimport { SocialLogo } from 'social-logos';\nimport { getNameBySite } from './utils';\nimport './style.scss';\n\nconst SharingButtonEdit = ( { attributes, context } ) => {\n\tconst { service, label } = attributes;\n\tconst { styleType, iconColorValue, iconBackgroundColorValue } = context;\n\n\tconst socialLinkName = getNameBySite( service );\n\tconst socialLinkLabel = label ?? socialLinkName;\n\n\tconst sharingButtonClass = clsx(\n\t\t'jetpack-sharing-button__button',\n\t\t'style-' + styleType,\n\t\t'share-' + service\n\t);\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'jetpack-sharing-button__list-item',\n\t} );\n\n\tconst buttonStyle = {\n\t\tcolor: iconColorValue,\n\t\tbackgroundColor: iconBackgroundColorValue,\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<li { ...blockProps }>\n\t\t\t\t<Button className={ sharingButtonClass } style={ buttonStyle }>\n\t\t\t\t\t<SocialLogo icon={ service } size={ 24 } />\n\t\t\t\t\t<span className={ 'jetpack-sharing-button__service-label' }>{ socialLinkLabel }</span>\n\t\t\t\t</Button>\n\t\t\t</li>\n\t\t</>\n\t);\n};\n\nexport default SharingButtonEdit;\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Create a block that Contains the block elements used to display a comment, like the title, date, author, avatar and more."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/comment-template/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/comment-template\",\n\t\"title\": \"Comment Template\",\n\t\"category\": \"design\",\n\t\"parent\": [ \"core/comments\" ],\n\t\"description\": \"Contains the block elements used to display a comment, like the title, date, author, avatar and more.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"postId\" ],\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"html\": false,\n\t\t\"reusable\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"style\": \"wp-block-comment-template\"\n}\n\n\n// File: packages/block-library/src/comment-template/index.js\n/**\n * WordPress dependencies\n */\nimport { layout as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/comment-template/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function CommentTemplateSave() {\n\treturn <InnerBlocks.Content />;\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Construct a flexible theme block in WordPress that allows users to modify link target and text positioning with intuitive configuration options."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/comment-edit-link/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/comment-edit-link\",\n\t\"title\": \"Comment Edit Link\",\n\t\"category\": \"theme\",\n\t\"ancestor\": [ \"core/comment-template\" ],\n\t\"description\": \"Displays a link to edit the comment in the WordPress Dashboard. This link is only visible to users with the edit comment capability.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"commentId\" ],\n\t\"attributes\": {\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"_self\"\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"link\": true,\n\t\t\t\"gradients\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-comment-edit-link\"\n}\n\n\n// File: packages/block-library/src/comment-edit-link/index.js\n/**\n * WordPress dependencies\n */\nimport { commentEditLink as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\texample: {},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Craft a custom Gutenberg block capable of embedding external content from platforms such as Twitter or YouTube, incorporating attributes for URL, caption, type, and four additional configurable parameters."
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/embed/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/embed\",\n\t\"title\": \"Embed\",\n\t\"category\": \"embed\",\n\t\"description\": \"Add a block that displays content pulled from other sites, like Twitter or YouTube.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"caption\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"figcaption\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"type\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"providerNameSlug\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"allowResponsive\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"responsive\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false,\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"previewable\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true,\n\t\t\t\"role\": \"content\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-embed-editor\",\n\t\"style\": \"wp-block-embed\"\n}\n\n\n// File: packages/block-library/src/embed/index.js\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport edit from './edit';\nimport save from './save';\nimport metadata from './block.json';\nimport transforms from './transforms';\nimport variations from './variations';\nimport deprecated from './deprecated';\nimport { embedContentIcon } from './icons';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon: embedContentIcon,\n\tedit,\n\tsave,\n\ttransforms,\n\tvariations,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/embed/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tRichText,\n\tuseBlockProps,\n\t__experimentalGetElementClassName,\n} from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { url, caption, type, providerNameSlug } = attributes;\n\n\tif ( ! url ) {\n\t\treturn null;\n\t}\n\n\tconst className = clsx( 'wp-block-embed', {\n\t\t[ `is-type-${ type }` ]: type,\n\t\t[ `is-provider-${ providerNameSlug }` ]: providerNameSlug,\n\t\t[ `wp-block-embed-${ providerNameSlug }` ]: providerNameSlug,\n\t} );\n\n\treturn (\n\t\t<figure { ...useBlockProps.save( { className } ) }>\n\t\t\t<div className=\"wp-block-embed__wrapper\">\n\t\t\t\t{ `\\n${ url }\\n` /* URL needs to be on its own line. */ }\n\t\t\t</div>\n\t\t\t{ ! RichText.isEmpty( caption ) && (\n\t\t\t\t<RichText.Content\n\t\t\t\t\tclassName={ __experimentalGetElementClassName( 'caption' ) }\n\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\tvalue={ caption }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</figure>\n\t);\n}\n"
}
] |
[
{
"role": "system",
"content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n"
},
{
"role": "user",
"content": "Build a Gutenberg block that Displays the next comment's page link. with these attributes: label"
},
{
"role": "assistant",
"content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/comments-pagination-next/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/comments-pagination-next\",\n\t\"title\": \"Comments Next Page\",\n\t\"category\": \"theme\",\n\t\"parent\": [ \"core/comments-pagination\" ],\n\t\"description\": \"Displays the next comment's page link.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"label\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"comments/paginationArrow\" ],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t}\n}\n\n\n// File: packages/block-library/src/comments-pagination-next/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { queryPaginationNext as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\texample: {\n\t\tattributes: {\n\t\t\tlabel: __( 'Newer Comments' ),\n\t\t},\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.