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": "Build a Gutenberg block that Contains blocks that are displayed when the cart is empty. 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/empty-cart-block/block.json\n{\n\t\"name\": \"woocommerce/empty-cart-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Empty Cart\",\n\t\"description\": \"Contains blocks that are displayed when the cart is empty.\",\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/empty-cart-block/edit.tsx\n/**\n * External dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport type { TemplateArray } from '@wordpress/blocks';\nimport { useEditorContext } from '@woocommerce/base-context';\nimport { SHOP_URL } from '@woocommerce/block-settings';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseForcedLayout,\n\tgetAllowedBlocks,\n} from '../../../cart-checkout-shared';\n\nconst browseStoreTemplate = SHOP_URL\n\t? [\n\t\t\t'core/paragraph',\n\t\t\t{\n\t\t\t\talign: 'center',\n\t\t\t\tcontent: sprintf(\n\t\t\t\t\t/* translators: %s is the link to the store product directory. */\n\t\t\t\t\t__( '<a href=\"%s\">Browse store</a>', 'woocommerce' ),\n\t\t\t\t\tSHOP_URL\n\t\t\t\t),\n\t\t\t\tdropCap: false,\n\t\t\t},\n\t ]\n\t: null;\n\nconst defaultTemplate = [\n\t[\n\t\t'core/heading',\n\t\t{\n\t\t\ttextAlign: 'center',\n\t\t\tcontent: __( 'Your cart is currently empty!', 'woocommerce' ),\n\t\t\tlevel: 2,\n\t\t\tclassName: 'with-empty-cart-icon wc-block-cart__empty-cart__title',\n\t\t},\n\t],\n\tbrowseStoreTemplate,\n\t[\n\t\t'core/separator',\n\t\t{\n\t\t\tclassName: 'is-style-dots',\n\t\t},\n\t],\n\t[\n\t\t'core/heading',\n\t\t{\n\t\t\ttextAlign: 'center',\n\t\t\tcontent: __( 'New in store', 'woocommerce' ),\n\t\t\tlevel: 2,\n\t\t},\n\t],\n\t[\n\t\t'woocommerce/product-new',\n\t\t{\n\t\t\tcolumns: 4,\n\t\t\trows: 1,\n\t\t},\n\t],\n].filter( Boolean ) as unknown as TemplateArray;\n\nexport const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst { currentView } = useEditorContext();\n\tconst allowedBlocks = getAllowedBlocks( innerBlockAreas.EMPTY_CART );\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={ currentView !== 'woocommerce/empty-cart-block' }\n\t\t>\n\t\t\t<InnerBlocks\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</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": "Construct a flexible block component enabling users to input and customize a specific web link within their 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: projects/plugins/jetpack/extensions/blocks/nextdoor/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/nextdoor\",\n\t\"title\": \"Nextdoor\",\n\t\"description\": \"Embed a Nextdoor post for your neighbors on your blog.\",\n\t\"keywords\": [ \"neighbor\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg height='24' width='24' viewBox='0 0 130 130' xmlns='http://www.w3.org/2000/svg'><g><path d='M64.25 3.531c-31.144.337-57.596 24.22-60.469 55.907-3.064 33.799 21.857 63.685 55.657 66.75 33.799 3.064 63.685-21.857 66.75-55.657 3.064-33.8-21.857-63.686-55.657-66.75a62.075 62.075 0 00-6.281-.25zm3.938 34.907C82.468 38.438 93.5 48.58 93.5 61.5v27c0 .685-.565 1.25-1.25 1.25H80.906a1.267 1.267 0 01-1.25-1.25V63.375c0-5.58-4.309-11.938-11.469-11.938-7.47 0-11.468 6.358-11.468 11.938V88.5c0 .685-.565 1.25-1.25 1.25H44.125c-.68 0-1.219-.57-1.219-1.25V64.156c0-.74-.529-1.364-1.25-1.531-13.13-2.93-15.115-10.285-15.375-21.125-.005-.332.142-.67.375-.906.233-.237.543-.375.875-.375l11.688.062c.66.01 1.187.529 1.218 1.188.13 4.44.438 9.406 4.438 9.406.83 0 1.443-1.179 1.813-1.719 4.41-6.48 12.28-10.718 21.5-10.718z'/></g></svg>\",\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"alignWide\": true,\n\t\t\"html\": false\n\t},\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/nextdoor/edit.js\nimport { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { getBlockDefaultClassName } from '@wordpress/blocks';\nimport { SandBox, Button, Placeholder, withNotices } from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __, _x } from '@wordpress/i18n';\nimport './editor.scss';\nimport { isEqual } from 'lodash';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport metadata from './block.json';\nimport NextdoorControls from './controls';\nimport { parseUrl } from './utils';\n\nconst icon = getBlockIconComponent( metadata );\n\nexport function NextdoorEdit( {\n\tattributes,\n\tclientId,\n\tname,\n\tnoticeOperations,\n\tnoticeUI,\n\tsetAttributes,\n} ) {\n\tconst blockProps = useBlockProps();\n\tconst defaultClassName = getBlockDefaultClassName( name );\n\tconst validatedAttributes = getValidatedAttributes( metadata.attributes, attributes );\n\n\tif ( ! isEqual( validatedAttributes, attributes ) ) {\n\t\tsetAttributes( validatedAttributes );\n\t}\n\n\tconst { url } = validatedAttributes;\n\tconst [ iframeUrl, setIframeUrl ] = useState( url ? parseUrl( url ) : null );\n\n\tconst [ nextdoorShareUrl, setNextdoorShareUrl ] = useState( iframeUrl );\n\n\tconst setErrorNotice = () => {\n\t\tnoticeOperations.removeAllNotices();\n\t\tnoticeOperations.createErrorNotice(\n\t\t\t__(\n\t\t\t\t\"Your Nextdoor post couldn't be embedded. Please double check the URL or code.\",\n\t\t\t\t'jetpack'\n\t\t\t)\n\t\t);\n\t};\n\n\tconst onFormSubmit = event => {\n\t\tif ( ! event ) {\n\t\t\tsetIframeUrl( null );\n\t\t\tsetErrorNotice();\n\t\t\treturn;\n\t\t}\n\t\tevent.preventDefault();\n\n\t\tif ( ! nextdoorShareUrl ) {\n\t\t\tsetIframeUrl( null );\n\t\t\tsetErrorNotice();\n\t\t\treturn;\n\t\t}\n\n\t\tconst embedUrl = parseUrl( nextdoorShareUrl );\n\n\t\tif ( ! embedUrl ) {\n\t\t\tsetIframeUrl( null );\n\t\t\tsetErrorNotice();\n\t\t\treturn;\n\t\t}\n\n\t\tsetIframeUrl( embedUrl );\n\t\tsetAttributes( { url: embedUrl } );\n\t};\n\n\tconst blockPlaceholder = (\n\t\t<Placeholder\n\t\t\tlabel={ __( 'Nextdoor', 'jetpack' ) }\n\t\t\tinstructions={ __( 'Enter the URL of your Nextdoor post to share below.', 'jetpack' ) }\n\t\t\ticon={ icon }\n\t\t\tnotices={ noticeUI }\n\t\t>\n\t\t\t<form onSubmit={ onFormSubmit }>\n\t\t\t\t<input\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\tid=\"nextdoorShareUrl\"\n\t\t\t\t\tonChange={ event => setNextdoorShareUrl( event.target.value ) }\n\t\t\t\t\tplaceholder={ __( 'Nextdoor post URL', 'jetpack' ) }\n\t\t\t\t\tvalue={ nextdoorShareUrl || '' }\n\t\t\t\t\tclassName=\"components-placeholder__input\"\n\t\t\t\t/>\n\t\t\t\t<div>\n\t\t\t\t\t<Button variant=\"secondary\" type=\"submit\">\n\t\t\t\t\t\t{ _x( 'Embed', 'button label', 'jetpack' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</div>\n\t\t\t</form>\n\t\t</Placeholder>\n\t);\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<NextdoorControls\n\t\t\t\t{ ...{ defaultClassName, nextdoorShareUrl, onFormSubmit, setNextdoorShareUrl } }\n\t\t\t/>\n\t\t\t{ iframeUrl ? (\n\t\t\t\t<BlockPreview\n\t\t\t\t\tdefaultClassName={ defaultClassName }\n\t\t\t\t\tiframeUrl={ iframeUrl }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t/>\n\t\t\t) : (\n\t\t\t\tblockPlaceholder\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nconst BlockPreview = ( { defaultClassName, iframeUrl, clientId } ) => {\n\tconst html = `\n\t\t<script>\n\t\t\twindow.addEventListener( 'message', function ( event ) {\n\t\t\t\tif ( ! event.origin.startsWith( 'https://nextdoor' ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tvar iframe = document.getElementById( 'nextdoor-embed-${ clientId }' );\n\t\t\t\tif ( event.source !== iframe.contentWindow ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tiframe.setAttribute( 'height', event.data.height );\n\t\t\t\tvar clientBoundingRect = document.body.getBoundingClientRect();\n\t\t\t\twindow.parent.postMessage( { action: 'resize', width: clientBoundingRect.width, height: clientBoundingRect.height }, '*' );\n\t\t\t} );\n\t\t</script>\n\t\t<iframe id=\"nextdoor-embed-${ clientId }\" width=\"100%\" height=\"200\" frameBorder=\"0\" src=\"${ iframeUrl }\" title=\"${ __(\n\t\t\t'Nextdoor',\n\t\t\t'jetpack'\n\t\t) }\" />\n\t\t`;\n\n\treturn (\n\t\t<>\n\t\t\t<div className={ `${ defaultClassName }-overlay` }></div>\n\t\t\t<SandBox html={ html } />\n\t\t</>\n\t);\n};\n\nexport default withNotices( NextdoorEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/nextdoor/save.js\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save() {\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": "Create a widgets block with customizable month, year"
},
{
"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/calendar/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/calendar\",\n\t\"title\": \"Calendar\",\n\t\"category\": \"widgets\",\n\t\"description\": \"A calendar of your site’s posts.\",\n\t\"keywords\": [ \"posts\", \"archive\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"month\": {\n\t\t\t\"type\": \"integer\"\n\t\t},\n\t\t\"year\": {\n\t\t\t\"type\": \"integer\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalSkipSerialization\": [ \"text\", \"background\" ],\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\t\"__experimentalSelector\": \"table, th\"\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\"__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-calendar\"\n}\n\n\n// File: packages/block-library/src/calendar/index.js\n/**\n * WordPress dependencies\n */\nimport { calendar 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;\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": "Build a flexible post taxonomy block enabling users to personalize term display through text alignment, separator style, and two supplementary 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/post-terms/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-terms\",\n\t\"title\": \"Post Terms\",\n\t\"category\": \"theme\",\n\t\"description\": \"Post terms.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"term\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"separator\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \", \"\n\t\t},\n\t\t\"prefix\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"suffix\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\",\n\t\t\t\"role\": \"content\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\" ],\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\t\"style\": \"wp-block-post-terms\"\n}\n\n\n// File: packages/block-library/src/post-terms/index.js\n/**\n * WordPress dependencies\n */\nimport { postCategories as icon } from '@wordpress/icons';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport enhanceVariations from './hooks';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n};\n\nexport const init = () => {\n\taddFilter(\n\t\t'blocks.registerBlockType',\n\t\t'core/template-part',\n\t\tenhanceVariations\n\t);\n\n\treturn initBlock( { name, metadata, settings } );\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 configurable typography, alignment, heading hierarchy, and three additional customization 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/query-title/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/query-title\",\n\t\"title\": \"Query Title\",\n\t\"category\": \"theme\",\n\t\"description\": \"Display the query title.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"type\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"level\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 1\n\t\t},\n\t\t\"levelOptions\": {\n\t\t\t\"type\": \"array\"\n\t\t},\n\t\t\"showPrefix\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showSearchTerm\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"type\": \"search\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"query\" ],\n\t\"supports\": {\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\"__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\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": 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-query-title\"\n}\n\n\n// File: packages/block-library/src/query-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 variations from './variations';\nimport deprecated from './deprecated';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tvariations,\n\tdeprecated,\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 Gutenberg block that reveals a sale badge for products on promotion, incorporating attributes for product ID, query loop descent, single product block context, and single product template positioning."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/block.json\n{\n\t\"name\": \"woocommerce/product-sale-badge\",\n\t\"title\": \"On-Sale Badge\",\n\t\"description\": \"Displays an on-sale badge if the product is on-sale.\",\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\"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\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"html\": false,\n\t\t\"align\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"background\": true,\n\t\t\t\"link\": false,\n\t\t\t\"__experimentalSkipSerialization\": 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\"__experimentalSkipSerialization\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": 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\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"email\": true,\n\t\t\"__experimentalSelector\": \".wc-block-components-product-sale-badge\"\n\t},\n\t\"ancestor\": [\n\t\t\"woocommerce/single-product\",\n\t\t\"woocommerce/product-template\",\n\t\t\"core/post-template\",\n\t\t\"woocommerce/product-gallery\"\n\t],\n\t\"usesContext\": [ \"query\", \"queryId\", \"postId\" ],\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"example\": {},\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/sale-badge/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport type { BlockAttributes } from './types';\nimport { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';\n\nconst Edit = ( {\n\tattributes,\n\tcontext,\n}: BlockEditProps< BlockAttributes > & { context: Context } ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\n\t// Remove the `style` prop from the block props to avoid passing it to the wrapper div.\n\tconst { style, ...wrapperProps } = blockProps;\n\tconst { isDescendentOfSingleProductTemplate } =\n\t\tuseIsDescendentOfSingleProductTemplate();\n\n\tconst blockAttrs = {\n\t\t...attributes,\n\t\t...context,\n\t};\n\n\treturn (\n\t\t<div { ...wrapperProps }>\n\t\t\t<Block\n\t\t\t\t{ ...blockAttrs }\n\t\t\t\tisDescendentOfSingleProductTemplate={\n\t\t\t\t\tisDescendentOfSingleProductTemplate\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": "Build a WooCommerce block featuring configurable settings including lock mechanism, cart page identification, return to cart visibility, and additional customizable parameters."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-actions-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Actions\",\n\t\"description\": \"Allow customers to place 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\t\"move\": true\n\t\t\t}\n\t\t},\n\t\t\"cartPageId\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"showReturnToCart\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"priceSeparator\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"·\"\n\t\t}\n\t},\n\t\"parent\": [ \"woocommerce/checkout-fields-block\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport PageSelector from '@woocommerce/editor-components/page-selector';\nimport { PanelBody, ToggleControl, TextControl } from '@wordpress/components';\nimport { CHECKOUT_PAGE_ID } from '@woocommerce/block-settings';\nimport {\n\tPlaceOrderButton,\n\tReturnToCartButton,\n} from '@woocommerce/base-components/cart-checkout';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport { BlockAttributes } from './block';\nimport { defaultReturnToCartButtonLabel } from './constants';\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: BlockAttributes;\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst {\n\t\tcartPageId = 0,\n\t\tshowReturnToCart = false,\n\t\tplaceOrderButtonLabel,\n\t\treturnToCartButtonLabel,\n\t} = attributes;\n\tconst { current: savedCartPageId } = useRef( cartPageId );\n\tconst currentPostId = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! savedCartPageId ) {\n\t\t\t\tconst store = select( 'core/editor' );\n\t\t\t\treturn store.getCurrentPostId();\n\t\t\t}\n\t\t\treturn savedCartPageId;\n\t\t},\n\t\t[ savedCartPageId ]\n\t);\n\n\tconst showPrice = blockProps.className.includes( 'is-style-with-price' );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Options', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t'Show a \"Return to Cart\" link',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Recommended to enable only if there is no Cart link in the header.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ showReturnToCart }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowReturnToCart: ! showReturnToCart,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\n\t\t\t\t\t{ showPrice && (\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __( 'Price separator', 'woocommerce' ) }\n\t\t\t\t\t\t\tid=\"price-separator\"\n\t\t\t\t\t\t\tvalue={ attributes.priceSeparator }\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\tpriceSeparator: 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) }\n\t\t\t\t</PanelBody>\n\n\t\t\t\t{ showReturnToCart &&\n\t\t\t\t\t! (\n\t\t\t\t\t\tcurrentPostId === CHECKOUT_PAGE_ID &&\n\t\t\t\t\t\tsavedCartPageId === 0\n\t\t\t\t\t) && (\n\t\t\t\t\t\t<PageSelector\n\t\t\t\t\t\t\tpageId={ cartPageId }\n\t\t\t\t\t\t\tsetPageId={ ( id: number ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { cartPageId: id } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlabels={ {\n\t\t\t\t\t\t\t\ttitle: __(\n\t\t\t\t\t\t\t\t\t'Return to Cart button',\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\tdefault: __(\n\t\t\t\t\t\t\t\t\t'WooCommerce Cart Page',\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} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t</InspectorControls>\n\t\t\t<div className=\"wc-block-checkout__actions\">\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( 'wc-block-checkout__actions_row', {\n\t\t\t\t\t\t'wc-block-checkout__actions_row--justify-flex-end':\n\t\t\t\t\t\t\t! showReturnToCart,\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t{ showReturnToCart && (\n\t\t\t\t\t\t<ReturnToCartButton element=\"span\">\n\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\tmultiline={ false }\n\t\t\t\t\t\t\t\tallowedFormats={ [] }\n\t\t\t\t\t\t\t\tvalue={ returnToCartButtonLabel }\n\t\t\t\t\t\t\t\tplaceholder={ defaultReturnToCartButtonLabel }\n\t\t\t\t\t\t\t\tonChange={ ( content ) => {\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\treturnToCartButtonLabel: content,\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</ReturnToCartButton>\n\t\t\t\t\t) }\n\t\t\t\t\t<PlaceOrderButton\n\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\tmultiline={ false }\n\t\t\t\t\t\t\t\tallowedFormats={ [] }\n\t\t\t\t\t\t\t\tvalue={ placeOrderButtonLabel }\n\t\t\t\t\t\t\t\tonChange={ ( content ) => {\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tplaceOrderButtonLabel: content,\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}\n\t\t\t\t\t\tfullWidth={ ! showReturnToCart }\n\t\t\t\t\t\tshowPrice={ showPrice }\n\t\t\t\t\t\tpriceSeparator={ attributes.priceSeparator }\n\t\t\t\t\t/>\n\t\t\t\t</div>\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": "Create a WordPress block that facilitates gathering customer contact information, providing flexible control over data entry and access restrictions."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-contact-information-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-contact-information-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Contact Information\",\n\t\"description\": \"Collect your customer's contact information.\",\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-contact-information-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 { ADMIN_URL } from '@woocommerce/settings';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport Noninteractive from '@woocommerce/base-components/noninteractive';\n\n/**\n * Internal dependencies\n */\nimport {\n\tFormStepBlock,\n\tAdditionalFields,\n\tAdditionalFieldsContent,\n} from '../../form-step';\nimport Block from './block';\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\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__contact-fields',\n\t\t\t\tattributes?.className\n\t\t\t) }\n\t\t>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody\n\t\t\t\t\ttitle={ __(\n\t\t\t\t\t\t'Account creation and guest checkout',\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) }\n\t\t\t\t>\n\t\t\t\t\t<p className=\"wc-block-checkout__controls-text\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Account creation and guest checkout settings can be managed in your store settings.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=account` }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Manage account settings', 'woocommerce' ) }\n\t\t\t\t\t</ExternalLink>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<Noninteractive>\n\t\t\t\t<Block />\n\t\t\t</Noninteractive>\n\t\t\t<AdditionalFields block={ innerBlockAreas.CONTACT_INFORMATION } />\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": "Create a WordPress block enabling product image and media display with interactive features like hover zoom and full-screen view when clicked."
},
{
"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/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-gallery\",\n\t\"title\": \"Product Gallery (Beta)\",\n\t\"description\": \"Showcase your products relevant images and media.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"interactivity\": true,\n\t\t\"layout\": {\n\t\t\t\"default\": {\n\t\t\t\t\"type\": \"flex\",\n\t\t\t\t\"flexWrap\": \"nowrap\",\n\t\t\t\t\"orientation\": \"horizontal\"\n\t\t\t},\n\t\t\t\"allowOrientation\": true,\n\t\t\t\"allowEditing\": true,\n\t\t\t\"allowJustification\": false\n\t\t},\n\t\t\"email\": true\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"usesContext\": [ \"postId\" ],\n\t\"providesContext\": {\n\t\t\"hoverZoom\": \"hoverZoom\",\n\t\t\"fullScreenOnClick\": \"fullScreenOnClick\"\n\t},\n\t\"ancestor\": [ \"woocommerce/single-product\" ],\n\t\"attributes\": {\n\t\t\"hoverZoom\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"fullScreenOnClick\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"viewScript\": \"wc-product-gallery-frontend\",\n\t\"example\": {},\n\t\"viewScriptModule\": \"woocommerce/product-gallery\",\n\t\"style\": \"file:../woocommerce/product-gallery-style.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tInnerBlocks,\n\tInspectorControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { BlockEditProps, InnerBlockTemplate } from '@wordpress/blocks';\nimport { withProductDataContext } from '@woocommerce/shared-hocs';\n\n/**\n * Internal dependencies\n */\nimport { ProductGalleryBlockSettings } from './block-settings/index';\nimport type { ProductGalleryBlockAttributes } from './types';\n\nconst TEMPLATE: InnerBlockTemplate[] = [\n\t[ 'woocommerce/product-gallery-thumbnails' ],\n\t[\n\t\t'woocommerce/product-gallery-large-image',\n\t\t{},\n\t\t[\n\t\t\t[\n\t\t\t\t'woocommerce/product-image',\n\t\t\t\t{\n\t\t\t\t\tshowProductLink: false,\n\t\t\t\t\tshowSaleBadge: false,\n\t\t\t\t},\n\t\t\t],\n\t\t\t[\n\t\t\t\t'woocommerce/product-sale-badge',\n\t\t\t\t{\n\t\t\t\t\talign: 'right',\n\t\t\t\t},\n\t\t\t],\n\t\t\t[ 'woocommerce/product-gallery-large-image-next-previous' ],\n\t\t],\n\t],\n];\n\nexport const Edit = withProductDataContext(\n\t( {\n\t\tattributes,\n\t\tsetAttributes,\n\t}: BlockEditProps< ProductGalleryBlockAttributes > ) => {\n\t\tconst blockProps = useBlockProps( {\n\t\t\tclassName: 'wc-block-product-gallery',\n\t\t} );\n\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<ProductGalleryBlockSettings\n\t\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t/>\n\t\t\t\t</InspectorControls>\n\t\t\t\t<InnerBlocks\n\t\t\t\t\tallowedBlocks={ [\n\t\t\t\t\t\t'woocommerce/product-gallery-large-image',\n\t\t\t\t\t\t'woocommerce/product-gallery-thumbnails',\n\t\t\t\t\t] }\n\t\t\t\t\ttemplate={ TEMPLATE }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n);\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport const Save = () => {\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: 'wc-block-product-gallery',\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": "Create a theme block with customizable tag name"
},
{
"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-content/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-content\",\n\t\"title\": \"Content\",\n\t\"category\": \"theme\",\n\t\"description\": \"Displays the contents of a post or page.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"postId\", \"postType\", \"queryId\" ],\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\"example\": {\n\t\t\"viewportWidth\": 350\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"layout\": true,\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\"dimensions\": {\n\t\t\t\"minHeight\": true\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\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\"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\": false,\n\t\t\t\t\"text\": 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\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-post-content\",\n\t\"editorStyle\": \"wp-block-post-content-editor\"\n}\n\n\n// File: packages/block-library/src/post-content/index.js\n/**\n * WordPress dependencies\n */\nimport { postContent 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};\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 block that Limit access to the content below this block to chosen subscribers."
},
{
"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/paywall/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/paywall\",\n\t\"title\": \"Paywall\",\n\t\"description\": \"Limit access to the content below this block to chosen subscribers.\",\n\t\"keywords\": [\n\t\t\"earn\",\n\t\t\"monetize\",\n\t\t\"more\",\n\t\t\"email\",\n\t\t\"follow\",\n\t\t\"gated\",\n\t\t\"memberships\",\n\t\t\"newsletter\",\n\t\t\"signin\",\n\t\t\"subscribe\",\n\t\t\"subscription\",\n\t\t\"subscriptions\"\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='M4 16.7134L20 16.7134V15.106H4V16.7134Z' /><path d='M16 21H20V19.3925H16V21Z' /><path d='M14 21H10V19.3925H14V21Z' /><path d='M4 21H8V19.3925H4V21Z' /><path d='M11.471 6.37162C11.2294 6.55286 11.1538 6.74395 11.1538 6.88519C11.1538 7.02644 11.2294 7.21752 11.471 7.39877C11.7108 7.57865 12.0728 7.70953 12.5 7.70953C13.1349 7.70953 13.7344 7.90158 14.1907 8.24382C14.6451 8.5847 15 9.11491 15 9.77039C15 10.4259 14.6451 10.9561 14.1907 11.297C13.8758 11.5331 13.4928 11.6978 13.0769 11.7771V12.0373C13.0769 12.3788 12.8186 12.6556 12.5 12.6556C12.1814 12.6556 11.9231 12.3788 11.9231 12.0373V11.7771C11.5072 11.6978 11.1242 11.5331 10.8093 11.297C10.3549 10.9561 10 10.4259 10 9.77039C10 9.42893 10.2583 9.15213 10.5769 9.15213C10.8955 9.15213 11.1538 9.42893 11.1538 9.77039C11.1538 9.91163 11.2294 10.1027 11.471 10.284C11.7108 10.4638 12.0728 10.5947 12.5 10.5947C12.9272 10.5947 13.2892 10.4638 13.529 10.284C13.7706 10.1027 13.8462 9.91163 13.8462 9.77039C13.8462 9.62914 13.7706 9.43806 13.529 9.25681C13.2892 9.07693 12.9272 8.94605 12.5 8.94605C11.8651 8.94605 11.2656 8.754 10.8093 8.41176C10.3549 8.07089 10 7.54067 10 6.88519C10 6.22971 10.3549 5.6995 10.8093 5.35863C11.1242 5.12246 11.5072 4.95781 11.9231 4.87844V4.61826C11.9231 4.2768 12.1814 4 12.5 4C12.8186 4 13.0769 4.2768 13.0769 4.61826V4.87844C13.4928 4.95781 13.8758 5.12246 14.1907 5.35863C14.6451 5.6995 15 6.22971 15 6.88519C15 7.22665 14.7417 7.50345 14.4231 7.50345C14.1045 7.50345 13.8462 7.22665 13.8462 6.88519C13.8462 6.74395 13.7706 6.55286 13.529 6.37162C13.2892 6.19174 12.9272 6.06085 12.5 6.06085C12.0728 6.06085 11.7108 6.19174 11.471 6.37162Z' /></svg>\",\n\t\"supports\": {\n\t\t\"customClassName\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false\n\t},\n\t\"parent\": [ \"core/post-content\" ]\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/paywall/edit.js\nimport './editor.scss';\nimport { JetpackEditorPanelLogo } from '@automattic/jetpack-shared-extension-utils/components';\nimport { BlockControls, InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { MenuGroup, MenuItem, PanelBody, ToolbarDropdownMenu } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { arrowDown, Icon, people, check } from '@wordpress/icons';\nimport ConnectBanner from '../../shared/components/connect-banner';\nimport PlansSetupDialog from '../../shared/components/plans-setup-dialog';\nimport { accessOptions } from '../../shared/memberships/constants';\nimport { useAccessLevel } from '../../shared/memberships/edit';\nimport { NewsletterAccessRadioButtons, useSetAccess } from '../../shared/memberships/settings';\nimport useIsUserConnected from '../../shared/use-is-user-connected';\n\nfunction PaywallEdit() {\n\tconst blockProps = useBlockProps();\n\tconst postType = useSelect( select => select( editorStore ).getCurrentPostType(), [] );\n\tconst accessLevel = useAccessLevel( postType );\n\tconst isUserConnected = useIsUserConnected();\n\tconst setAccess = useSetAccess();\n\n\t// Add cleanup effect to reset access level when paywall is removed\n\tuseEffect( () => {\n\t\t// This function will run when the component unmounts\n\t\treturn () => {\n\t\t\t// Reset access level to \"everybody\" when the paywall block is removed\n\t\t\tsetAccess( accessOptions.everybody.key );\n\t\t};\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [] );\n\n\tconst { stripeConnectUrl, hasTierPlans } = useSelect( select => {\n\t\tconst { getNewsletterTierProducts, getConnectUrl } = select( 'jetpack/membership-products' );\n\t\treturn {\n\t\t\tstripeConnectUrl: getConnectUrl(),\n\t\t\thasTierPlans: getNewsletterTierProducts()?.length !== 0,\n\t\t};\n\t} );\n\n\tconst [ showDialog, setShowDialog ] = useState( false );\n\tconst closeDialog = () => setShowDialog( false );\n\n\tuseEffect( () => {\n\t\tif ( ! accessLevel || accessLevel === accessOptions.everybody.key ) {\n\t\t\tsetAccess( accessOptions.subscribers.key );\n\t\t}\n\t}, [ accessLevel, setAccess ] );\n\n\tfunction selectAccess( value ) {\n\t\tif ( accessOptions.paid_subscribers.key === value && ( stripeConnectUrl || ! hasTierPlans ) ) {\n\t\t\tsetShowDialog( true );\n\t\t\treturn;\n\t\t}\n\t\tsetAccess( value );\n\t}\n\n\tif ( ! isUserConnected ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<ConnectBanner\n\t\t\t\t\tblock=\"Paywall\"\n\t\t\t\t\texplanation={ __(\n\t\t\t\t\t\t'Connect your WordPress.com account to enable a paywall for your site.',\n\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst getText = key => {\n\t\tswitch ( key ) {\n\t\t\tcase accessOptions.subscribers.key:\n\t\t\t\treturn __( 'Subscriber-only content below', 'jetpack' );\n\t\t\tcase accessOptions.paid_subscribers.key:\n\t\t\t\treturn __( 'Paid content below this line', 'jetpack' );\n\t\t\tdefault:\n\t\t\t\treturn __( 'Paywall', 'jetpack' );\n\t\t}\n\t};\n\n\tconst getLabel = key => {\n\t\tswitch ( key ) {\n\t\t\tcase accessOptions.paid_subscribers.key:\n\t\t\t\treturn accessOptions.paid_subscribers.label;\n\t\t\tdefault:\n\t\t\t\treturn accessOptions.subscribers.label;\n\t\t}\n\t};\n\n\tconst text = getText( accessLevel );\n\n\tlet _accessLevel = accessLevel ?? accessOptions.subscribers.key;\n\tif ( _accessLevel === accessOptions.everybody.key ) {\n\t\t_accessLevel = accessOptions.subscribers.key;\n\t}\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<div className=\"wp-block-jetpack-paywall-block\">\n\t\t\t\t<span>\n\t\t\t\t\t{ text }\n\t\t\t\t\t<Icon icon={ arrowDown } size={ 16 } />\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t\t<BlockControls __experimentalShareWithChildBlocks group=\"block\">\n\t\t\t\t<ToolbarDropdownMenu\n\t\t\t\t\tclassName=\"product-management-control-toolbar__dropdown-button\"\n\t\t\t\t\ticon={ people }\n\t\t\t\t\ttext={ getLabel( accessLevel ) }\n\t\t\t\t>\n\t\t\t\t\t{ ( { onClose: closeDropdown } ) => (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tselectAccess( accessOptions.subscribers.key );\n\t\t\t\t\t\t\t\t\t\tcloseDropdown();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tisSelected={ accessLevel === accessOptions.subscribers.key }\n\t\t\t\t\t\t\t\t\ticon={ accessLevel === accessOptions.subscribers.key && check }\n\t\t\t\t\t\t\t\t\ticonPosition=\"right\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ getLabel( accessOptions.subscribers.key ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tselectAccess( accessOptions.paid_subscribers.key );\n\t\t\t\t\t\t\t\t\t\tcloseDropdown();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tisSelected={ accessLevel === accessOptions.paid_subscribers.key }\n\t\t\t\t\t\t\t\t\ticon={ accessLevel === accessOptions.paid_subscribers.key && check }\n\t\t\t\t\t\t\t\t\ticonPosition=\"right\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ getLabel( accessOptions.paid_subscribers.key ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</ToolbarDropdownMenu>\n\t\t\t</BlockControls>\n\t\t\t<PlansSetupDialog closeDialog={ closeDialog } showDialog={ showDialog } />\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody\n\t\t\t\t\tclassName=\"jetpack-subscribe-newsletters-panel\"\n\t\t\t\t\ttitle={ __( 'Content access', 'jetpack' ) }\n\t\t\t\t\ticon={ <JetpackEditorPanelLogo /> }\n\t\t\t\t\tinitialOpen={ true }\n\t\t\t\t>\n\t\t\t\t\t<NewsletterAccessRadioButtons\n\t\t\t\t\t\tisEditorPanel={ true }\n\t\t\t\t\t\taccessLevel={ _accessLevel }\n\t\t\t\t\t\tstripeConnectUrl={ stripeConnectUrl }\n\t\t\t\t\t\thasTierPlans={ hasTierPlans }\n\t\t\t\t\t\tpostHasPaywallBlock={ 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 PaywallEdit;\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 designed to integrate Eventbrite event information and ticketing functionality, incorporating parameters for URL, event identification, and visual styling."
},
{
"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/eventbrite/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/eventbrite\",\n\t\"title\": \"Eventbrite Checkout\",\n\t\"description\": \"Embed Eventbrite event details and ticket checkout.\",\n\t\"keywords\": [ \"events\", \"tickets\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"embed\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M18.041,3.931L5.959,3C4.325,3,3,4.325,3,5.959v12.083C3,19.675,4.325,21,5.959,21l12.083-0.931C19.699,19.983,21,18.744,21,17.11V6.89C21,5.256,19.741,4.027,18.041,3.931zM16.933,8.17c-0.082,0.215-0.192,0.432-0.378,0.551c-0.188,0.122-0.489,0.132-0.799,0.132c-1.521,0-3.062-0.048-4.607-0.048c-0.152,0.708-0.304,1.416-0.451,2.128c0.932-0.004,1.873,0.005,2.81,0.005c0.726,0,1.462-0.069,1.586,0.525c0.04,0.189-0.001,0.426-0.052,0.615c-0.105,0.38-0.258,0.676-0.625,0.783c-0.185,0.054-0.408,0.058-0.646,0.058c-1.145,0-2.345,0.017-3.493,0.02c-0.169,0.772-0.328,1.553-0.489,2.333c1.57-0.005,3.067-0.041,4.633-0.058c0.627-0.007,1.085,0.194,1.009,0.85c-0.031,0.262-0.098,0.497-0.211,0.725c-0.102,0.208-0.248,0.376-0.488,0.452c-0.237,0.075-0.541,0.064-0.862,0.078c-0.304,0.014-0.614,0.008-0.924,0.016c-0.309,0.009-0.619,0.022-0.919,0.022c-1.253,0-2.429,0.08-3.683,0.073c-0.603-0.004-1.014-0.249-1.124-0.757c-0.059-0.273-0.018-0.58,0.036-0.841c0.541-2.592,1.083-5.176,1.629-7.763c0.056-0.265,0.114-0.511,0.225-0.714C9.279,7.051,9.534,6.834,9.9,6.735c0.368-0.099,0.883-0.047,1.344-0.047c0.305,0,0.612,0.008,0.914,0.016c0.925,0.026,1.817,0.03,2.747,0.053c0.304,0.007,0.615,0.016,0.915,0.016c0.621,0,1.17,0.073,1.245,0.614C17.104,7.675,17.014,7.954,16.933,8.17z'/></svg>\",\n\t\"supports\": { \"html\": false, \"align\": true },\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"eventId\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"style\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"inline\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"url\": \"https://www.eventbrite.com/e/test-event-tickets-123456789\",\n\t\t\t\"eventId\": 123456789,\n\t\t\t\"style\": \"modal\"\n\t\t},\n\t\t\"innerBlocks\": [\n\t\t\t{\n\t\t\t\t\"name\": \"jetpack/button\",\n\t\t\t\t\"attributes\": {\n\t\t\t\t\t\"element\": \"a\",\n\t\t\t\t\t\"text\": \"Register\",\n\t\t\t\t\t\"uniqueId\": \"eventbrite-widget-id\"\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/eventbrite/edit.js\nimport { BlockControls, InnerBlocks, useBlockProps } from '@wordpress/block-editor';\nimport { Button, withNotices } from '@wordpress/components';\nimport { useCallback, useEffect, useState } from '@wordpress/element';\nimport { __, _x } from '@wordpress/i18n';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport testEmbedUrl from '../../shared/test-embed-url';\nimport metadata from './block.json';\nimport { EVENTBRITE_EXAMPLE_URL, URL_REGEX } from './constants';\nimport { ToolbarControls, InspectorControls } from './controls';\nimport EmbedForm from './form';\nimport Loader from './loader';\nimport InlinePreview from './preview';\nimport { convertToLink, eventIdFromUrl, normalizeUrlInput } from './utils';\n\nimport './editor.scss';\n\nconst innerButtonBlock = {\n\tname: 'jetpack/button',\n\tattributes: {\n\t\telement: 'a',\n\t\ttext: _x( 'Register', 'verb: e.g. register for an event.', 'jetpack' ),\n\t\tuniqueId: 'eventbrite-widget-id',\n\t},\n};\n\nexport const EventbriteEdit = props => {\n\tconst { attributes, noticeOperations, onReplace, setAttributes } = props;\n\tconst { url, style } = attributes;\n\n\tconst blockProps = useBlockProps();\n\tconst [ editingUrl, setEditingUrl ] = useState( false );\n\tconst [ editedUrl, setEditedUrl ] = useState( attributes.url || '' );\n\tconst [ isResolvingUrl, setIsResolvingUrl ] = useState( false );\n\n\tconst cannotEmbed = ! isResolvingUrl && url && ! URL_REGEX.test( url );\n\n\tconst setErrorNotice = useCallback( () => {\n\t\tnoticeOperations.removeAllNotices();\n\t\tnoticeOperations.createErrorNotice(\n\t\t\t<>\n\t\t\t\t{ __( 'Sorry, this content could not be embedded.', 'jetpack' ) }{ ' ' }\n\t\t\t\t<Button variant=\"link\" onClick={ () => convertToLink( editedUrl, onReplace ) }>\n\t\t\t\t\t{ _x( 'Convert block to link', 'button label', 'jetpack' ) }\n\t\t\t\t</Button>\n\t\t\t</>\n\t\t);\n\t}, [ noticeOperations, onReplace, editedUrl ] );\n\n\tconst setUrl = useCallback(\n\t\tstr => {\n\t\t\tif ( ! str || EVENTBRITE_EXAMPLE_URL === str || 'modal' === style ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst eventId = eventIdFromUrl( str );\n\n\t\t\tif ( ! eventId ) {\n\t\t\t\tsetErrorNotice();\n\t\t\t} else {\n\t\t\t\tconst newAttributes = {\n\t\t\t\t\teventId,\n\t\t\t\t\turl: str,\n\t\t\t\t};\n\n\t\t\t\ttestEmbedUrl( newAttributes.url, setIsResolvingUrl )\n\t\t\t\t\t.then( resolvedUrl => {\n\t\t\t\t\t\tconst newValidatedAttributes = getValidatedAttributes( metadata.attributes, {\n\t\t\t\t\t\t\t...newAttributes,\n\t\t\t\t\t\t\turl: resolvedUrl,\n\t\t\t\t\t\t} );\n\t\t\t\t\t\tsetAttributes( newValidatedAttributes );\n\t\t\t\t\t\tsetEditedUrl( resolvedUrl );\n\t\t\t\t\t\tnoticeOperations.removeAllNotices();\n\t\t\t\t\t} )\n\t\t\t\t\t.catch( () => {\n\t\t\t\t\t\tsetAttributes( { eventId: undefined, url: undefined } );\n\t\t\t\t\t\tsetErrorNotice();\n\t\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ style, noticeOperations, setErrorNotice, setAttributes, setEditedUrl, setIsResolvingUrl ]\n\t);\n\n\tuseEffect( () => {\n\t\tsetUrl( url );\n\t}, [ url, setUrl ] );\n\n\tlet content;\n\n\tif ( isResolvingUrl ) {\n\t\tcontent = <Loader />;\n\t} else if ( editingUrl || ! url || cannotEmbed ) {\n\t\tcontent = (\n\t\t\t<EmbedForm\n\t\t\t\t{ ...props }\n\t\t\t\teditedUrl={ editedUrl }\n\t\t\t\tonChange={ e => setEditedUrl( e.target.value ) }\n\t\t\t\tonSubmit={ e => {\n\t\t\t\t\tif ( e ) {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t}\n\n\t\t\t\t\tsetUrl( normalizeUrlInput( editedUrl ) );\n\t\t\t\t\tsetEditingUrl( false );\n\t\t\t\t} }\n\t\t\t/>\n\t\t);\n\t} else {\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t<InspectorControls { ...props } />\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<ToolbarControls setEditingUrl={ setEditingUrl } />\n\t\t\t\t</BlockControls>\n\t\t\t\t{ style === 'modal' ? (\n\t\t\t\t\t<InnerBlocks\n\t\t\t\t\t\ttemplate={ [ [ innerButtonBlock.name, innerButtonBlock.attributes ] ] }\n\t\t\t\t\t\ttemplateLock=\"all\"\n\t\t\t\t\t/>\n\t\t\t\t) : (\n\t\t\t\t\t<InlinePreview { ...props } />\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn <div { ...blockProps }>{ content }</div>;\n};\n\nexport default withNotices( EventbriteEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/eventbrite/save.js\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { eventId, style, url } = attributes;\n\n\tif ( ! eventId ) {\n\t\treturn;\n\t}\n\n\tlet content;\n\n\tif ( style === 'modal' ) {\n\t\tcontent = <InnerBlocks.Content />;\n\t} else if ( url ) {\n\t\tcontent = (\n\t\t\t<a className=\"eventbrite__direct-link\" href={ url }>\n\t\t\t\t{ url }\n\t\t\t</a>\n\t\t);\n\t}\n\n\tconst blockProps = useBlockProps.save();\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": "Build a Gutenberg block that Display a grid of your all-time best selling products. with these attributes: columns, rows, align buttons, 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: plugins/woocommerce/client/blocks/assets/js/blocks/product-best-sellers/block.json\n{\n\t\"name\": \"woocommerce/product-best-sellers\",\n\t\"title\": \"Best Selling Products\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"Display a grid of your all-time best selling products.\",\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\": \"popularity\"\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-best-sellers/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { ProductBestSellersBlock } from './block';\nimport { Props } from './types';\n\nexport const Edit = ( props: unknown & Props ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<ProductBestSellersBlock { ...props } />\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 align, class name"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/totals/block.json\n{\n\t\"name\": \"woocommerce/order-confirmation-totals\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Order Totals\",\n\t\"description\": \"Display the items purchased and order totals.\",\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\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": 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\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": 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}\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\t\"__experimentalBorder\": {\n\t\t\t\"color\": 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\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalSelector\": \".wp-block-woocommerce-order-confirmation-totals table\"\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/totals/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { Disabled } from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { formatPrice } from '@woocommerce/price-format';\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-totals',\n\t} );\n\n\tconst {\n\t\tborderBottomColor,\n\t\tborderLeftColor,\n\t\tborderRightColor,\n\t\tborderTopColor,\n\t\tborderWidth,\n\t} = blockProps.style;\n\n\tconst borderStyles = {\n\t\tborderBottomColor,\n\t\tborderLeftColor,\n\t\tborderRightColor,\n\t\tborderTopColor,\n\t\tborderWidth,\n\t} as React.CSSProperties;\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Disabled>\n\t\t\t\t<table\n\t\t\t\t\tstyle={ borderStyles }\n\t\t\t\t\tcellSpacing=\"0\"\n\t\t\t\t\tclassName=\"wc-block-order-confirmation-totals__table\"\n\t\t\t\t>\n\t\t\t\t\t<thead>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th className=\"wc-block-order-confirmation-totals__product\">\n\t\t\t\t\t\t\t\t{ __( 'Product', 'woocommerce' ) }\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t\t<th className=\"wc-block-order-confirmation-totals__total\">\n\t\t\t\t\t\t\t\t{ __( 'Total', 'woocommerce' ) }\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody>\n\t\t\t\t\t\t<tr className=\"woocommerce-table__line-item order_item\">\n\t\t\t\t\t\t\t<th\n\t\t\t\t\t\t\t\tscope=\"row\"\n\t\t\t\t\t\t\t\tclassName=\"wc-block-order-confirmation-totals__product\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<a href=\"#link\">\n\t\t\t\t\t\t\t\t\t{ _x(\n\t\t\t\t\t\t\t\t\t\t'Test Product',\n\t\t\t\t\t\t\t\t\t\t'sample product name',\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</a>\n\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t<strong className=\"product-quantity\">\n\t\t\t\t\t\t\t\t\t× 2\n\t\t\t\t\t\t\t\t</strong>\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t\t<td className=\"wc-block-order-confirmation-totals__total\">\n\t\t\t\t\t\t\t\t{ formatPrice( 2000 ) }\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr className=\"woocommerce-table__line-item order_item\">\n\t\t\t\t\t\t\t<th\n\t\t\t\t\t\t\t\tscope=\"row\"\n\t\t\t\t\t\t\t\tclassName=\"wc-block-order-confirmation-totals__product\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<a href=\"#link\">\n\t\t\t\t\t\t\t\t\t{ _x(\n\t\t\t\t\t\t\t\t\t\t'Test Product',\n\t\t\t\t\t\t\t\t\t\t'sample product name',\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</a>\n\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t<strong className=\"product-quantity\">\n\t\t\t\t\t\t\t\t\t× 2\n\t\t\t\t\t\t\t\t</strong>\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t\t<td className=\"wc-block-order-confirmation-totals__total\">\n\t\t\t\t\t\t\t\t{ formatPrice( 2000 ) }\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</tbody>\n\t\t\t\t\t<tfoot>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th\n\t\t\t\t\t\t\t\tclassName=\"wc-block-order-confirmation-totals__label\"\n\t\t\t\t\t\t\t\tscope=\"row\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Total', 'woocommerce' ) }\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t\t<td className=\"wc-block-order-confirmation-totals__total\">\n\t\t\t\t\t\t\t\t{ formatPrice( 4000 ) }\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</tfoot>\n\t\t\t\t</table>\n\t\t\t</Disabled>\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 woocommerce block with customizable class name, show counts, min rating, is preview"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/rating-filter/block.json\n{\n\t\"name\": \"woocommerce/product-filter-rating\",\n\t\"title\": \"Rating Filter\",\n\t\"description\": \"Enable customers to filter the product collection by rating.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [],\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"color\": {\n\t\t\t\"background\": false,\n\t\t\t\"text\": true\n\t\t}\n\t},\n\t\"ancestor\": [ \"woocommerce/product-filters\" ],\n\t\"usesContext\": [ \"query\", \"filterParams\" ],\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"showCounts\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"minRating\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"0\"\n\t\t},\n\t\t\"isPreview\": {\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/product-filters/inner-blocks/rating-filter/edit.tsx\n/**\n * External dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport {\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tBlockContextProvider,\n} from '@wordpress/block-editor';\nimport {\n\tuseQueryStateByKey,\n\tuseQueryStateByContext,\n\tuseCollectionData,\n} from '@woocommerce/base-context/hooks';\nimport { getSettingWithCoercion } from '@woocommerce/settings';\nimport { isBoolean } from '@woocommerce/types';\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { withSpokenMessages } from '@wordpress/components';\nimport type { BlockEditProps } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { previewOptions } from './preview';\nimport { getActiveFilters } from './utils';\nimport { Inspector } from './components/inspector';\nimport { getAllowedBlocks } from '../../utils/get-allowed-blocks';\nimport { EXCLUDED_BLOCKS } from '../../constants';\nimport { Notice } from '../../components/notice';\nimport type { Attributes } from './types';\nimport { InitialDisabled } from '../../components/initial-disabled';\nimport RatingStars from './components/rating-stars';\n\nconst RatingFilterEdit = ( props: BlockEditProps< Attributes > ) => {\n\tconst { attributes, setAttributes, clientId } = props;\n\n\tconst { isPreview, showCounts, minRating } = attributes;\n\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[\n\t\t\t\t\t'core/heading',\n\t\t\t\t\t{\n\t\t\t\t\t\tlevel: 3,\n\t\t\t\t\t\tcontent: __( 'Rating', 'woocommerce' ),\n\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\tspacing: {\n\t\t\t\t\t\t\t\tmargin: {\n\t\t\t\t\t\t\t\t\tbottom: '0.625rem',\n\t\t\t\t\t\t\t\t\ttop: '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},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\t[ 'woocommerce/product-filter-checkbox-list' ],\n\t\t\t],\n\t\t}\n\t);\n\n\tconst [ queryState ] = useQueryStateByContext();\n\n\tconst { data: collectionFilters, isLoading: filteredCountsLoading } =\n\t\tuseCollectionData( {\n\t\t\tqueryRating: true,\n\t\t\tqueryState,\n\t\t\tisEditor: true,\n\t\t} );\n\n\tconst [ displayedOptions, setDisplayedOptions ] = useState(\n\t\tisPreview ? previewOptions : []\n\t);\n\n\tconst isLoading =\n\t\t! isPreview && filteredCountsLoading && displayedOptions.length === 0;\n\n\tconst initialFilters = useMemo(\n\t\t() => getActiveFilters( 'rating_filter' ),\n\t\t[]\n\t);\n\n\tconst [ productRatingsQuery ] = useQueryStateByKey(\n\t\t'rating',\n\t\tinitialFilters\n\t);\n\n\t/**\n\t * Compare intersection of all ratings\n\t * and filtered counts to get a list of options to display.\n\t */\n\tuseEffect( () => {\n\t\tif ( filteredCountsLoading || isPreview ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\t! collectionFilters?.rating_counts ||\n\t\t\tcollectionFilters?.rating_counts?.length === 0\n\t\t) {\n\t\t\tsetDisplayedOptions( previewOptions );\n\t\t\treturn;\n\t\t}\n\n\t\tconst minimumRating =\n\t\t\ttypeof minRating === 'string' ? parseFloat( minRating ) : 0;\n\n\t\t/*\n\t\t * Process the ratings counts:\n\t\t * - Sort the ratings in descending order\n\t\t * Todo: consider to handle this in the API request\n\t\t * - Filter out ratings below the minimum rating\n\t\t * - Map the ratings to the format expected by the filter component\n\t\t */\n\t\tconst productsRating = collectionFilters?.rating_counts?.length\n\t\t\t? collectionFilters.rating_counts\n\t\t\t\t\t.sort( ( a, b ) => b.rating - a.rating )\n\t\t\t\t\t.filter( ( { rating } ) => rating >= minimumRating )\n\t\t\t\t\t.map( ( { rating, count }, index ) => ( {\n\t\t\t\t\t\tlabel: <RatingStars key={ rating } stars={ rating } />,\n\t\t\t\t\t\tariaLabel: sprintf(\n\t\t\t\t\t\t\t/* translators: %d: rating value. Example: Rated 4 out of 5. */\n\t\t\t\t\t\t\t__( 'Rated %d out of 5', 'woocommerce' ),\n\t\t\t\t\t\t\trating\n\t\t\t\t\t\t),\n\t\t\t\t\t\tvalue: rating?.toString(),\n\t\t\t\t\t\tselected: index === 0,\n\t\t\t\t\t\tcount,\n\t\t\t\t\t} ) )\n\t\t\t: [];\n\n\t\tsetDisplayedOptions( productsRating );\n\t}, [\n\t\tshowCounts,\n\t\tisPreview,\n\t\tcollectionFilters,\n\t\tfilteredCountsLoading,\n\t\tproductRatingsQuery,\n\t\tminRating,\n\t] );\n\n\tif ( ! filteredCountsLoading && displayedOptions.length === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst hasFilterableProducts = getSettingWithCoercion(\n\t\t'hasFilterableProducts',\n\t\tfalse,\n\t\tisBoolean\n\t);\n\n\tif ( ! hasFilterableProducts ) {\n\t\treturn null;\n\t}\n\n\tconst showNoProductsNotice =\n\t\t! filteredCountsLoading && ! collectionFilters.rating_counts?.length;\n\n\treturn (\n\t\t<>\n\t\t\t<Inspector\n\t\t\t\tclientId={ clientId }\n\t\t\t\tattributes={ attributes }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t/>\n\n\t\t\t<div { ...innerBlocksProps }>\n\t\t\t\t<InitialDisabled>\n\t\t\t\t\t{ showNoProductsNotice && (\n\t\t\t\t\t\t<Notice>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\"Your store doesn't have any products with ratings yet. This filter option will display when a product receives a review.\",\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</Notice>\n\t\t\t\t\t) }\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={ clsx( {\n\t\t\t\t\t\t\t'is-loading': isLoading,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<BlockContextProvider\n\t\t\t\t\t\t\tvalue={ {\n\t\t\t\t\t\t\t\tfilterData: {\n\t\t\t\t\t\t\t\t\titems: displayedOptions,\n\t\t\t\t\t\t\t\t\tisLoading,\n\t\t\t\t\t\t\t\t\tshowCounts,\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\t{ children }\n\t\t\t\t\t\t</BlockContextProvider>\n\t\t\t\t\t</div>\n\t\t\t\t</InitialDisabled>\n\t\t\t</div>\n\t\t</>\n\t);\n};\n\nexport default withSpokenMessages( RatingFilterEdit );\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/rating-filter/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": "Create a woocommerce block with customizable pagination arrow"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-pagination/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-reviews-pagination\",\n\t\"title\": \"Reviews Pagination\",\n\t\"category\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/product-reviews\" ],\n\t\"allowedBlocks\": [\n\t\t\"woocommerce/product-reviews-pagination-previous\",\n\t\t\"woocommerce/product-reviews-pagination-numbers\",\n\t\t\"woocommerce/product-reviews-pagination-next\"\n\t],\n\t\"description\": \"Displays a paginated navigation to next/previous set of product reviews, when applicable.\",\n\t\"textdomain\": \"woocommerce\",\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\"reviews/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}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-pagination/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { PanelBody } from '@wordpress/components';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport {\n\tInspectorControls,\n\tuseBlockProps,\n\t// @ts-expect-error useInnerBlocksProps is not exported from @wordpress/block-editor\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n\tWarning,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { ReviewsPaginationArrowControls } from './reviews-pagination-arrow-controls';\nimport './editor.scss';\n\nconst TEMPLATE = [\n\t[ 'woocommerce/product-reviews-pagination-previous' ],\n\t[ 'woocommerce/product-reviews-pagination-numbers' ],\n\t[ 'woocommerce/product-reviews-pagination-next' ],\n];\n\ntype Props = BlockEditProps< { paginationArrow: string | number | undefined } >;\n\nexport default function Edit( {\n\tattributes: { paginationArrow },\n\tsetAttributes,\n\tclientId,\n}: Props ) {\n\tconst hasNextPreviousBlocks = useSelect(\n\t\t( select ) => {\n\t\t\t// TODO: remove the @ts-expect-error comment and typecast for innerBlock once we upgrade @wordpress/block-editor types version.\n\t\t\t// @ts-expect-error We're using an outdated types of `@wordpress/block-editor`, so the property 'getBlocks' does not exist on type returned by select.\n\t\t\tconst { getBlocks } = select( blockEditorStore );\n\t\t\tconst innerBlocks = getBlocks( clientId );\n\t\t\t/**\n\t\t\t * Show the `paginationArrow` control only if a\n\t\t\t * Product Reviews Pagination Next or Product Reviews Pagination Previous\n\t\t\t * block exists.\n\t\t\t */\n\t\t\treturn innerBlocks?.find( ( innerBlock: { name: string } ) => {\n\t\t\t\treturn [\n\t\t\t\t\t'woocommerce/product-reviews-pagination-previous',\n\t\t\t\t\t'woocommerce/product-reviews-pagination-next',\n\t\t\t\t].includes( innerBlock.name );\n\t\t\t} );\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst blockProps = useBlockProps();\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: TEMPLATE,\n\t} );\n\n\t// Get the Discussion settings\n\tconst pageComments = useSelect( ( select ) => {\n\t\t// @ts-expect-error We're using an outdated types of `@wordpress/block-editor`, so the property 'getSettings' does not exist on type returned by select.\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst { __experimentalDiscussionSettings } = getSettings();\n\t\treturn __experimentalDiscussionSettings?.pageComments;\n\t}, [] );\n\n\t// If paging comments is not enabled in the Discussion Settings then hide the pagination\n\t// controls. We don't want to remove them from the template so that when the user enables\n\t// paging comments, the controls will be visible.\n\tif ( ! pageComments ) {\n\t\treturn (\n\t\t\t<Warning>\n\t\t\t\t{ __(\n\t\t\t\t\t'Product Reviews Pagination block: paging comments is disabled in the Discussion Settings',\n\t\t\t\t\t'woocommerce'\n\t\t\t\t) }\n\t\t\t</Warning>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ hasNextPreviousBlocks && (\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<PanelBody title={ __( 'Settings', 'woocommerce' ) }>\n\t\t\t\t\t\t<ReviewsPaginationArrowControls\n\t\t\t\t\t\t\tvalue={ paginationArrow }\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\tpaginationArrow: 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</PanelBody>\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t\t<div { ...innerBlocksProps } />\n\t\t</>\n\t);\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-pagination/save.tsx\n/**\n * External 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 Shows the subtotal, fees, discounts, shipping and taxes. 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/cart/inner-blocks/cart-order-summary-totals/block.json\n{\n\t\"name\": \"woocommerce/cart-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/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-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.CART_ORDER_SUMMARY_TOTALS\n\t);\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/cart-order-summary-subtotal-block', {}, [] ],\n\t\t[ 'woocommerce/cart-order-summary-fee-block', {}, [] ],\n\t\t[ 'woocommerce/cart-order-summary-discount-block', {}, [] ],\n\t\t[ 'woocommerce/cart-order-summary-shipping-block', {}, [] ],\n\t\t[ 'woocommerce/cart-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 Display the order confirmation shipping 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/shipping-wrapper/block.json\n{\n\t\"name\": \"woocommerce/order-confirmation-shipping-wrapper\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Shipping Address Section\",\n\t\"description\": \"Display the order confirmation shipping 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\t\"default\": \"Shipping\"\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/shipping-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-shipping-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": "Build a Gutenberg block that Display a list of related posts. with these attributes: post layout, display author, display date, 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/related-posts/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/related-posts\",\n\t\"title\": \"Related Posts\",\n\t\"description\": \"Display a list of related posts.\",\n\t\"keywords\": [ \"similar content\", \"linked\", \"connected\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"embed\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='m19.5,3.5H3.5v4.94s.01,6,.01,6v4s-.01,0-.01,0v1h15.97v-.06h.05l-.02-15.88Zm-11,1v3.94s-3.99,0-3.99,0v-3.94s3.99,0,3.99,0Zm.01,4.94v4h-4v-4h4Zm-3.99,9v-4s3.99,0,3.99,0v4s-3.99,0-3.99,0Zm13.98-13.94v3.94s-8.99,0-8.99,0v-3.94s8.99,0,8.99,0Zm.01,4.94v4h-9v-4h9Zm-8.99,9v-4s8.99,0,8.99,0v4s-8.99,0-8.99,0Z'/></svg>\",\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": 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\"__experimentalFontFamily\": true,\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true\n\t\t},\n\t\t\"align\": [ \"wide\", \"full\" ]\n\t},\n\t\"attributes\": {\n\t\t\"postLayout\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"grid\"\n\t\t},\n\t\t\"displayAuthor\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"displayDate\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"displayThumbnails\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"displayContext\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"postsToShow\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"postLayout\": \"grid\",\n\t\t\t\"displayAuthor\": false,\n\t\t\t\"displayDate\": true,\n\t\t\t\"displayThumbnails\": true,\n\t\t\t\"displayContext\": false,\n\t\t\t\"postsToShow\": 2\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/related-posts/edit.js\nimport { useModuleStatus } from '@automattic/jetpack-shared-extension-utils';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tInnerBlocks,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { Path, SVG } from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport { LoadingPostsGrid } from '../../shared/components/loading-posts-grid';\nimport { getEditorType, SITE_EDITOR } from '../../shared/get-editor-type';\nimport metadata from './block.json';\nimport { RelatedPostsBlockControls, RelatedPostsInspectorControls } from './controls';\nimport { useRelatedPosts } from './hooks/use-related-posts';\nimport { useRelatedPostsStatus } from './hooks/use-status-toggle';\nimport { InactiveRelatedPostsPlaceholder } from './inactive-placeholder';\nimport './editor.scss';\n\nconst featureName = metadata.name.replace( 'jetpack/', '' );\n\nexport const MAX_POSTS_TO_SHOW = 6;\n\nfunction PlaceholderPostEdit( props ) {\n\treturn (\n\t\t<div\n\t\t\tclassName=\"jp-related-posts-i2__post\"\n\t\t\tid={ props.id }\n\t\t\taria-labelledby={ props.id + '-heading' }\n\t\t>\n\t\t\t<strong id={ props.id + '-heading' } className=\"jp-related-posts-i2__post-link\">\n\t\t\t\t{ props.isInSiteEditor\n\t\t\t\t\t? __(\n\t\t\t\t\t\t\t'Preview unavailable in site editor. The post title will appear normally on your site.',\n\t\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t )\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\"Preview unavailable: you haven't published enough posts with similar content.\",\n\t\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t ) }\n\t\t\t</strong>\n\t\t\t{ props.displayThumbnails && (\n\t\t\t\t<figure\n\t\t\t\t\tclassName=\"jp-related-posts-i2__post-image-placeholder\"\n\t\t\t\t\taria-label={ __( 'Placeholder image', 'jetpack' ) }\n\t\t\t\t>\n\t\t\t\t\t<SVG\n\t\t\t\t\t\tclassName=\"jp-related-posts-i2__post-image-placeholder-square\"\n\t\t\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t\t\t\twidth=\"100%\"\n\t\t\t\t\t\theight=\"100%\"\n\t\t\t\t\t\tviewBox=\"0 0 350 200\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<title>{ __( 'Grey square', 'jetpack' ) }</title>\n\t\t\t\t\t\t<Path d=\"M0 0h350v200H0z\" fill=\"#8B8B96\" fillOpacity=\".1\" />\n\t\t\t\t\t</SVG>\n\t\t\t\t\t<SVG\n\t\t\t\t\t\tclassName=\"jp-related-posts-i2__post-image-placeholder-icon\"\n\t\t\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t\t\t\twidth=\"24\"\n\t\t\t\t\t\theight=\"24\"\n\t\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<title>{ __( 'Icon for image', 'jetpack' ) }</title>\n\t\t\t\t\t\t<Path fill=\"none\" d=\"M0 0h24v24H0V0z\" />\n\t\t\t\t\t\t<Path d=\"M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-4.86 8.86l-3 3.87L9 13.14 6 17h12l-3.86-5.14z\" />\n\t\t\t\t\t</SVG>\n\t\t\t\t</figure>\n\t\t\t) }\n\n\t\t\t{ props.displayDate && (\n\t\t\t\t<div className=\"jp-related-posts-i2__post-date has-small-font-size\">\n\t\t\t\t\t{ __( 'August 3, 2025', 'jetpack' ) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ props.displayAuthor && (\n\t\t\t\t<div className=\"jp-related-posts-i2__post-author has-small-font-size\">\n\t\t\t\t\t{ __( 'by John Doe', 'jetpack' ) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ props.displayContext && (\n\t\t\t\t<div className=\"jp-related-posts-i2__post-context has-small-font-size\">\n\t\t\t\t\t{ __( 'In “Uncategorized”', 'jetpack' ) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nfunction RelatedPostsEditItem( props ) {\n\tconst contextText = props.post?.block_context?.text || '';\n\tconst contextLink = props.post?.block_context?.link || '';\n\tconst contextHasText = contextText !== '';\n\tconst contextHasLink = contextLink !== '';\n\treturn (\n\t\t<div\n\t\t\tclassName=\"jp-related-posts-i2__post\"\n\t\t\tid={ props.id }\n\t\t\taria-labelledby={ props.id + '-heading' }\n\t\t>\n\t\t\t<a\n\t\t\t\tclassName=\"jp-related-posts-i2__post-link\"\n\t\t\t\tid={ props.id + '-heading' }\n\t\t\t\thref={ props.post.url }\n\t\t\t\trel=\"nofollow noopener noreferrer\"\n\t\t\t\ttarget=\"_blank\"\n\t\t\t>\n\t\t\t\t{ props.post.title }\n\t\t\t</a>\n\t\t\t{ props.displayThumbnails && props.post.img && props.post.img.src && (\n\t\t\t\t<a\n\t\t\t\t\tclassName=\"jp-related-posts-i2__post-img-link\"\n\t\t\t\t\thref={ props.post.url }\n\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\trel=\"nofollow noopener noreferrer\"\n\t\t\t\t>\n\t\t\t\t\t<img\n\t\t\t\t\t\tclassName=\"jp-related-posts-i2__post-img\"\n\t\t\t\t\t\tsrc={ props.post.img.src }\n\t\t\t\t\t\talt={ props.post.title }\n\t\t\t\t\t/>\n\t\t\t\t</a>\n\t\t\t) }\n\t\t\t{ props.displayDate && (\n\t\t\t\t<div className=\"jp-related-posts-i2__post-date has-small-font-size\">\n\t\t\t\t\t{ props.post.date }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ props.displayAuthor && (\n\t\t\t\t<div className=\"jp-related-posts-i2__post-author has-small-font-size\">\n\t\t\t\t\t{ props.post.author }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ props.displayContext && contextHasText && (\n\t\t\t\t<div className=\"jp-related-posts-i2__post-context has-small-font-size\">\n\t\t\t\t\t{ contextHasLink && <a href={ contextLink }>{ contextText }</a> }\n\t\t\t\t\t{ contextHasLink === false && contextText }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nfunction RelatedPostsPreviewRows( props ) {\n\tconst className = 'jp-related-posts-i2__row';\n\n\tlet topRowEnd = 0;\n\tconst displayLowerRow = props.posts.length > 3;\n\n\tswitch ( props.posts.length ) {\n\t\tcase 2:\n\t\tcase 4:\n\t\tcase 5:\n\t\t\ttopRowEnd = 2;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\ttopRowEnd = 3;\n\t\t\tbreak;\n\t}\n\n\treturn (\n\t\t<div>\n\t\t\t<div className={ className } data-post-count={ props.posts.slice( 0, topRowEnd ).length }>\n\t\t\t\t{ props.posts.slice( 0, topRowEnd ) }\n\t\t\t</div>\n\t\t\t{ displayLowerRow && (\n\t\t\t\t<div className={ className } data-post-count={ props.posts.slice( topRowEnd ).length }>\n\t\t\t\t\t{ props.posts.slice( topRowEnd ) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nexport default function RelatedPostsEdit( { attributes, setAttributes } ) {\n\tconst { displayAuthor, displayContext, displayDate, displayThumbnails, postLayout, postsToShow } =\n\t\tattributes;\n\n\tconst blockProps = useBlockProps();\n\t// Related Posts can be controlled by a module on self-hosted sites.\n\tconst { isLoadingModules, isChangingStatus, isModuleActive, changeStatus } =\n\t\tuseModuleStatus( featureName );\n\t// They can also be toggled via an option on WordPress.com Simple.\n\tconst { isEnabled, enable, isFetchingStatus, isUpdatingStatus } = useRelatedPostsStatus();\n\n\tconst isChangingRelatedPostsStatus = isChangingStatus || isUpdatingStatus;\n\n\tconst { posts, isLoading: isLoadingRelatedPosts } = useRelatedPosts( isEnabled );\n\n\tconst isInSiteEditor = SITE_EDITOR === getEditorType();\n\n\tconst { instanceId } = useInstanceId( RelatedPostsEdit );\n\n\tlet content;\n\n\tif ( isLoadingModules || isFetchingStatus || isLoadingRelatedPosts ) {\n\t\tcontent = <LoadingPostsGrid />;\n\t} else if ( ! isModuleActive || ! isEnabled ) {\n\t\tcontent = (\n\t\t\t<InactiveRelatedPostsPlaceholder\n\t\t\t\tchangeStatus={ changeStatus }\n\t\t\t\tisLoading={ isChangingRelatedPostsStatus }\n\t\t\t\tenable={ enable }\n\t\t\t/>\n\t\t);\n\t} else {\n\t\t// To prevent the block from crashing, we need to limit ourselves to the\n\t\t// posts returned by the backend - so if we want 6 posts, but only 3 are\n\t\t// returned, we need to limit ourselves to those 3 and fill in the rest\n\t\t// with placeholders.\n\t\t//\n\t\t// Also, if the site does not have sufficient posts to display related ones\n\t\t// (minimum 10 posts), we also use this code block to fill in the\n\t\t// placeholders.\n\t\tconst previewClassName = 'jp-relatedposts-i2';\n\t\tconst displayPosts = [];\n\t\tfor ( let i = 0; i < postsToShow; i++ ) {\n\t\t\tif ( posts[ i ] ) {\n\t\t\t\tdisplayPosts.push(\n\t\t\t\t\t<RelatedPostsEditItem\n\t\t\t\t\t\tid={ `related-posts-${ instanceId }-post-${ i }` }\n\t\t\t\t\t\tkey={ previewClassName + '-' + i }\n\t\t\t\t\t\tpost={ posts[ i ] }\n\t\t\t\t\t\tdisplayThumbnails={ displayThumbnails }\n\t\t\t\t\t\tdisplayDate={ displayDate }\n\t\t\t\t\t\tdisplayContext={ displayContext }\n\t\t\t\t\t\tdisplayAuthor={ displayAuthor }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tdisplayPosts.push(\n\t\t\t\t\t<PlaceholderPostEdit\n\t\t\t\t\t\tid={ `related-posts-${ instanceId }-post-${ i }` }\n\t\t\t\t\t\tkey={ 'related-post-placeholder-' + i }\n\t\t\t\t\t\tdisplayThumbnails={ displayThumbnails }\n\t\t\t\t\t\tdisplayDate={ displayDate }\n\t\t\t\t\t\tdisplayContext={ displayContext }\n\t\t\t\t\t\tisInSiteEditor={ isInSiteEditor }\n\t\t\t\t\t\tdisplayAuthor={ displayAuthor }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<RelatedPostsInspectorControls\n\t\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t/>\n\t\t\t\t</InspectorControls>\n\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<RelatedPostsBlockControls attributes={ attributes } setAttributes={ setAttributes } />\n\t\t\t\t</BlockControls>\n\n\t\t\t\t<div id={ `related-posts-${ instanceId }` }>\n\t\t\t\t\t<InnerBlocks\n\t\t\t\t\t\tallowedBlocks={ [ 'core/heading' ] }\n\t\t\t\t\t\ttemplate={ [ [ 'core/heading', { placeholder: __( 'Add a headline', 'jetpack' ) } ] ] }\n\t\t\t\t\t/>\n\t\t\t\t\t<div className={ previewClassName } data-layout={ postLayout }>\n\t\t\t\t\t\t<RelatedPostsPreviewRows posts={ displayPosts } />\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</>\n\t\t);\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": "Create a woocommerce-product-elements block with customizable product id, is descendent of query loop, is descendent of single product template, and 6 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/atomic/blocks/product-elements/summary/block.json\n{\n\t\"name\": \"woocommerce/product-summary\",\n\t\"icon\": \"page\",\n\t\"title\": \"Product Summary\",\n\t\"description\": \"Display a short description about 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\"isDescendentOfQueryLoop\": {\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\t\"isDescendentOfSingleProductBlock\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\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\"showDescriptionIfEmpty\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"showLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"summaryLength\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"linkText\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"supports\": {\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},\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\"textAlign\": 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\"__experimentalSelector\": \".wc-block-components-product-summary\"\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\"usesContext\": [ \"query\", \"queryId\", \"postId\" ],\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/summary/index.ts\n/**\n * External dependencies\n */\nimport type { BlockAttributes } from '@wordpress/blocks';\nimport { registerProductBlockType } from '@woocommerce/atomic-utils';\nimport { isEmptyObject } from '@woocommerce/types';\n\n/**\n * Internal dependencies\n */\nimport edit from './edit';\nimport { BLOCK_ICON as icon } from './constants';\nimport save from '../save';\nimport metadata from './block.json';\nimport './upgrade';\n\nconst deprecated = [\n\t{\n\t\tsave,\n\t\tmigrate: ( attributes: BlockAttributes ) => {\n\t\t\t// We don't deprecate attributes, but adding new ones.\n\t\t\t// For backwards compatibility, some new attributes require\n\t\t\t// different defaults than new ones.\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\tshowDescriptionIfEmpty: true,\n\t\t\t\tsummaryLength: 150,\n\t\t\t};\n\t\t},\n\t\tisEligible: ( attributes: BlockAttributes ) =>\n\t\t\tisEmptyObject( attributes ),\n\t},\n];\n\nconst blockConfig = {\n\t...metadata,\n\n\ticon: { src: icon },\n\tdeprecated,\n\tedit,\n\tsave,\n};\n\nregisterProductBlockType( blockConfig, {\n\tisAvailableOnPostEditor: true,\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 WordPress block to Display a product’s SKU, categories, tags, 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: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/product-meta/block.json\n{\n\t\"name\": \"woocommerce/product-meta\",\n\t\"title\": \"Product Meta\",\n\t\"icon\": \"product\",\n\t\"description\": \"Display a product’s SKU, categories, tags, and more.\",\n\t\"category\": \"woocommerce-product-elements\",\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},\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"usesContext\": [ \"postId\", \"postType\", \"queryId\" ],\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/product-meta/edit.tsx\n/**\n * External dependencies\n */\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\nimport { InnerBlockTemplate } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\n\nconst Edit = () => {\n\tconst TEMPLATE: InnerBlockTemplate[] = [\n\t\t[\n\t\t\t'core/group',\n\t\t\t{ layout: { type: 'flex', flexWrap: 'nowrap' } },\n\t\t\t[\n\t\t\t\t[ 'woocommerce/product-sku' ],\n\t\t\t\t[\n\t\t\t\t\t'core/post-terms',\n\t\t\t\t\t{\n\t\t\t\t\t\tprefix: __( 'Category: ', 'woocommerce' ),\n\t\t\t\t\t\tterm: 'product_cat',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\t[\n\t\t\t\t\t'core/post-terms',\n\t\t\t\t\t{\n\t\t\t\t\t\tprefix: __( 'Tags: ', 'woocommerce' ),\n\t\t\t\t\t\tterm: 'product_tag',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t],\n\t\t],\n\t];\n\tconst blockProps = useBlockProps();\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/atomic/blocks/product-elements/product-meta/save.tsx\n/**\n * External dependencies\n */\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nconst Save = () => {\n\tconst blockProps = useBlockProps.save();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ /* @ts-expect-error: `InnerBlocks.Content` is a component that is typed in WordPress core*/ }\n\t\t\t<InnerBlocks.Content />\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": "Develop a block for Shows the Cross-Sells products. that allows users to configure: columns, 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-cross-sells-products/block.json\n{\n\t\"name\": \"woocommerce/cart-cross-sells-products-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Cart Cross-Sells Products\",\n\t\"description\": \"Shows the Cross-Sells 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\": false,\n\t\t\"lock\": false,\n\t\t\"email\": true\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\"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-cross-sells-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-cross-sells-products/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { PanelBody, RangeControl } from '@wordpress/components';\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport { getSetting } from '@woocommerce/settings';\nimport Noninteractive from '@woocommerce/base-components/noninteractive';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport './editor.scss';\n\ninterface Attributes {\n\tclassName?: string;\n\tcolumns: number;\n}\n\ninterface Props {\n\tattributes: Attributes;\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n}\n\nexport const Edit = ( { attributes, setAttributes }: Props ): JSX.Element => {\n\tconst { className, columns } = attributes;\n\tconst blockProps = useBlockProps();\n\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<RangeControl\n\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t'Cross-Sells products to show',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tvalue={ columns }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( { columns: value } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmin={ getSetting( 'minColumns', 1 ) }\n\t\t\t\t\t\tmax={ getSetting( 'maxColumns', 6 ) }\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<Noninteractive>\n\t\t\t\t<Block columns={ columns } 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": "Build a Gutenberg block that Display mathematical notation using LaTeX. with these attributes: latex, math m l"
},
{
"role": "assistant",
"content": "// File: packages/block-library/src/math/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/math\",\n\t\"title\": \"Math\",\n\t\"category\": \"text\",\n\t\"description\": \"Display mathematical notation using LaTeX.\",\n\t\"keywords\": [ \"equation\", \"formula\", \"latex\", \"mathematics\" ],\n\t\"textdomain\": \"default\",\n\t\"supports\": {\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\"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\"__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\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"latex\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"mathML\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"html\",\n\t\t\t\"selector\": \"math\"\n\t\t}\n\t}\n}\n\n\n// File: packages/block-library/src/math/index.js\n/**\n * WordPress dependencies\n */\nimport { math as icon } from '@wordpress/icons';\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 deprecated from './deprecated';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tlatex: 'x = \\\\frac{-b \\\\pm \\\\sqrt{b^2-4ac}}{2a}',\n\t\t\tmathML: '<semantics><mrow><mi>x</mi><mo>=</mo><mfrac><mrow><mo lspace=\"0em\" rspace=\"0em\">−</mo><mi>b</mi><mo>±</mo><msqrt><mrow><msup><mi>b</mi><mn>2</mn></msup><mo>−</mo><mn>4</mn><mi>a</mi><mi>c</mi></mrow></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></mrow><annotation encoding=\"application/x-tex\">x = \\\\frac{-b \\\\pm \\\\sqrt{b^2-4ac}}{2a}</annotation></semantics>',\n\t\t},\n\t\tviewportWidth: 300,\n\t},\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/math/save.js\n/**\n * WordPress dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { latex, mathML } = attributes;\n\n\tif ( ! latex ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<math\n\t\t\t\tdisplay=\"block\"\n\t\t\t\tdangerouslySetInnerHTML={ { __html: mathML } }\n\t\t\t/>\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 theme block with customizable 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/query-pagination-previous/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/query-pagination-previous\",\n\t\"title\": \"Previous Page\",\n\t\"category\": \"theme\",\n\t\"parent\": [ \"core/query-pagination\" ],\n\t\"description\": \"Displays the previous posts 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\": [\n\t\t\"queryId\",\n\t\t\"query\",\n\t\t\"paginationArrow\",\n\t\t\"showLabel\",\n\t\t\"enhancedPagination\"\n\t],\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/query-pagination-previous/index.js\n/**\n * WordPress dependencies\n */\nimport { queryPaginationPrevious 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};\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 Add custom HTML code and preview it as you edit. that allows users to configure: content"
},
{
"role": "assistant",
"content": "// File: packages/block-library/src/html/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/html\",\n\t\"title\": \"Custom HTML\",\n\t\"category\": \"widgets\",\n\t\"description\": \"Add custom HTML code and preview it as you edit.\",\n\t\"keywords\": [ \"embed\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"content\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"raw\",\n\t\t\t\"role\": \"content\"\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\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-html-editor\"\n}\n\n\n// File: packages/block-library/src/html/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { html as icon } from '@wordpress/icons';\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';\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'<marquee>' +\n\t\t\t\t__( 'Welcome to the wonderful world of blocks…' ) +\n\t\t\t\t'</marquee>',\n\t\t},\n\t},\n\tedit,\n\tsave,\n\ttransforms,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/html/save.js\n/**\n * WordPress dependencies\n */\nimport { RawHTML } from '@wordpress/element';\n\nexport default function save( { attributes } ) {\n\treturn <RawHTML>{ attributes.content }</RawHTML>;\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 align, columns, content visibility, and 4 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/handpicked-products/block.json\n{\n\t\"name\": \"woocommerce/handpicked-products\",\n\t\"title\": \"Hand-picked Products\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"Handpicked Products\", \"WooCommerce\" ],\n\t\"description\": \"Display a selection of hand-picked products in a grid.\",\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\"align\": {\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},\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\"image\": 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\"title\": 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\"price\": 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\"rating\": 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\"button\": true\n\t\t\t\t}\n\t\t\t}\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\t\"products\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\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\"isPreview\": {\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/handpicked-products/edit.tsx\n/**\n * External dependencies\n */\nimport { BlockControls, useBlockProps } from '@wordpress/block-editor';\nimport {\n\tToolbarGroup,\n\tDisabled,\n\twithSpokenMessages,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n/**\n * Internal dependencies\n */\nimport './editor.scss';\nimport { Props } from './types';\nimport { HandpickedProductsInspectorControls } from './inspector-controls';\nimport { HandpickedProductsEditMode } from './edit-mode';\nimport { HandpickedProductsBlock } from './block';\n\nexport const EditBlock = ( props: Props ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\n\tconst {\n\t\tattributes: { products },\n\t} = props;\n\n\tconst [ isEditing, setIsEditing ] = useState( ! products.length );\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 products',\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<HandpickedProductsInspectorControls { ...props } />\n\t\t\t{ isEditing ? (\n\t\t\t\t<HandpickedProductsEditMode\n\t\t\t\t\tisEditing={ isEditing }\n\t\t\t\t\tsetIsEditing={ setIsEditing }\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<HandpickedProductsBlock { ...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": "Craft a custom Gutenberg block to showcase the Mini-Cart block's title, incorporating the specified lock attributes."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-title-block/block.json\n{\n\t\"name\": \"woocommerce/mini-cart-title-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Mini-Cart Title\",\n\t\"description\": \"Block that displays the title of the Mini-Cart 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\": false\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": 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\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [ \"woocommerce/filled-mini-cart-contents-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-block/edit.tsx\n/**\n * External dependencies\n */\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nexport const Edit = (): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wc-block-mini-cart__title',\n\t} );\n\n\tconst TEMPLATE = [\n\t\t[ 'woocommerce/mini-cart-title-label-block', {} ],\n\t\t[ 'woocommerce/mini-cart-title-items-counter-block', {} ],\n\t];\n\n\treturn (\n\t\t<h2 { ...blockProps }>\n\t\t\t<InnerBlocks\n\t\t\t\tallowedBlocks={ [\n\t\t\t\t\t'woocommerce/mini-cart-title-label-block',\n\t\t\t\t\t'woocommerce/mini-cart-title-items-counter-block',\n\t\t\t\t] }\n\t\t\t\ttemplate={ TEMPLATE }\n\t\t\t\ttemplateLock=\"all\"\n\t\t\t/>\n\t\t</h2>\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 theme block with customizable text align, display as range, display mode, average reading speed"
},
{
"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-time-to-read/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-time-to-read\",\n\t\"title\": \"Time to Read\",\n\t\"category\": \"theme\",\n\t\"description\": \"Show minutes required to finish reading the post. Can also show a word count.\",\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\"displayAsRange\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"displayMode\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"time\"\n\t\t},\n\t\t\"averageReadingSpeed\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 189\n\t\t}\n\t},\n\t\"supports\": {\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\"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\"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}\n\n\n// File: packages/block-library/src/post-time-to-read/index.js\n/**\n * WordPress dependencies\n */\nimport { timeToRead 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 variations from './variations';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tvariations,\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": "Develop a block for Display the downloadable products section. that allows users to configure: heading"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/downloads-wrapper/block.json\n{\n\t\"name\": \"woocommerce/order-confirmation-downloads-wrapper\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Downloads Section\",\n\t\"description\": \"Display the downloadable products 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/downloads-wrapper/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { getSetting } from '@woocommerce/settings';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\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\tconst hasDownloadableProducts = getSetting(\n\t\t'storeHasDownloadableProducts'\n\t);\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\tclassName={ clsx( blockProps.className, {\n\t\t\t\t'store-has-downloads': hasDownloadableProducts,\n\t\t\t} ) }\n\t\t>\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-downloads',\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 flexible Gutenberg block that enables numerical ratings across different content types, featuring configurable attributes including rating scale, visual color, and three supplementary options."
},
{
"role": "assistant",
"content": "// File: projects/plugins/jetpack/extensions/blocks/rating-star/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/rating-star\",\n\t\"title\": \"Star Rating\",\n\t\"description\": \"Rate movies, books, songs, recipes — anything you can put a number on.\",\n\t\"keywords\": [ \"star\", \"rating\", \"review\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"widgets\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M22 9.24l-7.19-.62L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21 12 17.27 18.18 21l-1.63-7.03L22 9.24zM12 15.4V6.1l1.71 4.04 4.38.38-3.32 2.88 1 4.28L12 15.4z'/></svg>\",\n\t\"supports\": {\n\t\t\"html\": false\n\t},\n\t\"styles\": [\n\t\t{\n\t\t\t\"name\": \"filled\",\n\t\t\t\"label\": \"Filled\",\n\t\t\t\"isDefault\": true\n\t\t},\n\t\t{\n\t\t\t\"name\": \"outlined\",\n\t\t\t\"label\": \"Outlined\"\n\t\t}\n\t],\n\t\"attributes\": {\n\t\t\"rating\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 1\n\t\t},\n\t\t\"maxRating\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 5\n\t\t},\n\t\t\"color\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"ratingStyle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"star\"\n\t\t},\n\t\t\"className\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"left\"\n\t\t}\n\t},\n\t\"example\": {}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/rating-star/edit.js\nimport {\n\tAlignmentToolbar,\n\tBlockControls,\n\tInspectorControls,\n\tPanelColorSettings,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { PanelBody, RangeControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\nexport const Rating = ( { id, setRating, children } ) => {\n\tconst setNewRating = newRating => () => setRating( newRating );\n\tconst maybeSetNewRating =\n\t\tnewRating =>\n\t\t( { code } ) =>\n\t\t\tcode === 'Enter' ? setRating( newRating ) : null;\n\n\treturn (\n\t\t<span\n\t\t\tclassName=\"jetpack-ratings-button\"\n\t\t\ttabIndex={ 0 }\n\t\t\trole=\"button\"\n\t\t\tonKeyDown={ maybeSetNewRating( id ) }\n\t\t\tonClick={ setNewRating( id ) }\n\t\t>\n\t\t\t{ children }\n\t\t</span>\n\t);\n};\n\nexport default Symbol =>\n\tfunction ( { setAttributes, attributes: { align, color, rating, maxRating } } ) {\n\t\tconst blockProps = useBlockProps();\n\n\t\tconst setNewMaxRating = newMaxRating => setAttributes( { maxRating: newMaxRating } );\n\t\tconst setNewColor = newColor => setAttributes( { color: newColor } );\n\t\tconst setNewRating = newRating => {\n\t\t\tif ( newRating === rating ) {\n\t\t\t\t// Same number clicked twice.\n\t\t\t\t// Check if a half rating.\n\t\t\t\tif ( Math.ceil( rating ) === rating ) {\n\t\t\t\t\t// Whole number.\n\t\t\t\t\tnewRating = newRating - 0.5;\n\t\t\t\t}\n\t\t\t} else if ( rating === 0.5 && newRating === 1 ) {\n\t\t\t\t// Clicking the 0.5 star updates to 0 stars.\n\t\t\t\tnewRating = 0;\n\t\t\t}\n\n\t\t\tsetAttributes( { rating: newRating } );\n\t\t};\n\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<AlignmentToolbar\n\t\t\t\t\t\tvalue={ align }\n\t\t\t\t\t\tonChange={ nextAlign => setAttributes( { align: nextAlign } ) }\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t\t<div style={ { textAlign: align } }>\n\t\t\t\t\t{ Array.from( Array( Math.ceil( maxRating ) ), ( _, i ) => i + 1 ).map( position => (\n\t\t\t\t\t\t<Rating key={ position } id={ position } setRating={ setNewRating }>\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t<Symbol\n\t\t\t\t\t\t\t\t\tclassName={ rating >= position - 0.5 ? null : 'is-rating-unfilled' }\n\t\t\t\t\t\t\t\t\tcolor={ color }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t<Symbol\n\t\t\t\t\t\t\t\t\tclassName={ rating >= position ? null : 'is-rating-unfilled' }\n\t\t\t\t\t\t\t\t\tcolor={ color }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</Rating>\n\t\t\t\t\t) ) }\n\t\t\t\t</div>\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<PanelBody title={ __( 'Settings', 'jetpack' ) }>\n\t\t\t\t\t\t<RangeControl\n\t\t\t\t\t\t\tlabel={ __( 'Highest rating', 'jetpack' ) }\n\t\t\t\t\t\t\tvalue={ maxRating }\n\t\t\t\t\t\t\tonChange={ setNewMaxRating }\n\t\t\t\t\t\t\tmin={ 2 }\n\t\t\t\t\t\t\tmax={ 10 }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t\t<PanelColorSettings\n\t\t\t\t\t\ttitle={ __( 'Color', 'jetpack' ) }\n\t\t\t\t\t\tinitialOpen\n\t\t\t\t\t\tcolorSettings={ [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: color,\n\t\t\t\t\t\t\t\tonChange: setNewColor,\n\t\t\t\t\t\t\t\tlabel: __( 'Color', 'jetpack' ),\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</InspectorControls>\n\t\t\t</div>\n\t\t);\n\t};\n\n\n// File: projects/plugins/jetpack/extensions/blocks/rating-star/save.js\nimport { useBlockProps } from '@wordpress/block-editor';\n\n// This is a dynamic block, meaning that its content is created on the server.\n// This function is only to provide a fallback in case the block is deactivated\n// or there is any problem with the render_callback in the server.\n//\n// Note that, unlike the normal ratings block, here we render as many symbols\n// as the rating, not as the maxRating. This is for consistency: some symbols (star)\n// have filled and stroke UTF-8 equivalents but other symbols don't (dollar, chilli).\n// We can't provide the full styled experience using UTF-8, so we optimize\n// for consistency.\nexport default fallbackSymbol =>\n\tfunction ( { attributes: { align, rating, color } } ) {\n\t\tconst blockProps = useBlockProps.save();\n\n\t\treturn (\n\t\t\t<figure { ...blockProps } style={ { textAlign: align } }>\n\t\t\t\t{ Array.from( Array( Math.ceil( rating ) ), ( _, i ) => i + 1 ).map( position => (\n\t\t\t\t\t<span key={ position } style={ { color } }>\n\t\t\t\t\t\t{ fallbackSymbol }\n\t\t\t\t\t</span>\n\t\t\t\t) ) }\n\t\t\t</figure>\n\t\t);\n\t};\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 helps customers navigate store layouts and parent page relationships, featuring configurable typography and alignment settings for improved user experience."
},
{
"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/breadcrumbs/block.json\n{\n\t\"name\": \"woocommerce/breadcrumbs\",\n\t\"title\": \"Store Breadcrumbs\",\n\t\"description\": \"Enable customers to keep track of their location within the store and navigate back to parent pages.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"attributes\": {\n\t\t\"contentJustification\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"fontSize\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"small\"\n\t\t},\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"wide\"\n\t\t}\n\t},\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\"color\": {\n\t\t\t\"background\": false,\n\t\t\t\"link\": true\n\t\t},\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\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalFontWeight\": 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},\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/breadcrumbs/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { Disabled } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\nexport interface Attributes {\n\tclassName?: string;\n}\n\nconst Edit = () => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'woocommerce wc-block-breadcrumbs',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Disabled>\n\t\t\t\t<a href=\"/\">{ __( 'Breadcrumbs', 'woocommerce' ) }</a>\n\t\t\t\t{ __( ' / Navigation / Path', 'woocommerce' ) }\n\t\t\t</Disabled>\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": "Craft a customizable WordPress block enabling the collection of customer contact details with configurable locking mechanisms."
},
{
"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-contact-information-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-contact-information-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Contact Information\",\n\t\"description\": \"Collect your customer's contact information.\",\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-contact-information-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 { ADMIN_URL } from '@woocommerce/settings';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport Noninteractive from '@woocommerce/base-components/noninteractive';\n\n/**\n * Internal dependencies\n */\nimport {\n\tFormStepBlock,\n\tAdditionalFields,\n\tAdditionalFieldsContent,\n} from '../../form-step';\nimport Block from './block';\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\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__contact-fields',\n\t\t\t\tattributes?.className\n\t\t\t) }\n\t\t>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody\n\t\t\t\t\ttitle={ __(\n\t\t\t\t\t\t'Account creation and guest checkout',\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) }\n\t\t\t\t>\n\t\t\t\t\t<p className=\"wc-block-checkout__controls-text\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Account creation and guest checkout settings can be managed in your store settings.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=account` }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Manage account settings', 'woocommerce' ) }\n\t\t\t\t\t</ExternalLink>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<Noninteractive>\n\t\t\t\t<Block />\n\t\t\t</Noninteractive>\n\t\t\t<AdditionalFields block={ innerBlockAreas.CONTACT_INFORMATION } />\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": "Design a customizable theme block with the ability to dynamically modify and personalize comment identification 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-comment/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"__experimental\": \"fse\",\n\t\"name\": \"core/post-comment\",\n\t\"title\": \"Comment (deprecated)\",\n\t\"category\": \"theme\",\n\t\"allowedBlocks\": [\n\t\t\"core/avatar\",\n\t\t\"core/comment-author-name\",\n\t\t\"core/comment-content\",\n\t\t\"core/comment-date\",\n\t\t\"core/comment-edit-link\",\n\t\t\"core/comment-reply-link\"\n\t],\n\t\"description\": \"This block is deprecated. Please use the Comments block instead.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"commentId\": {\n\t\t\t\"type\": \"number\"\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"commentId\": \"commentId\"\n\t},\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"inserter\": 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/post-comment/index.js\n/**\n * WordPress dependencies\n */\nimport { comment 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/post-comment/save.js\n/**\n * WordPress dependencies\n */\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save() {\n\tconst blockProps = useBlockProps.save();\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 This block is deprecated. Please use the Avatar block instead. with these attributes: width, height"
},
{
"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-author-avatar/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"__experimental\": \"fse\",\n\t\"name\": \"core/comment-author-avatar\",\n\t\"title\": \"Comment Author Avatar (deprecated)\",\n\t\"category\": \"theme\",\n\t\"ancestor\": [ \"core/comment-template\" ],\n\t\"description\": \"This block is deprecated. Please use the Avatar block instead.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"width\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 96\n\t\t},\n\t\t\"height\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 96\n\t\t}\n\t},\n\t\"usesContext\": [ \"commentId\" ],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"inserter\": false,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"color\": true,\n\t\t\t\"style\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"background\": 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\"__experimentalSkipSerialization\": true,\n\t\t\t\"margin\": true,\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}\n\n\n// File: packages/block-library/src/comment-author-avatar/index.js\n/**\n * WordPress dependencies\n */\nimport { commentAuthorAvatar 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};\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 block for rendering cart shipping information with integrated user-configurable lock settings within the WordPress environment."
},
{
"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-shipping/block.json\n{\n\t\"name\": \"woocommerce/checkout-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/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-shipping/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} ): JSX.Element => {\n\tconst { className } = attributes;\n\tconst blockProps = useBlockProps();\n\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": "Build a Gutenberg block that Create structured content in rows and columns to display information. with these attributes: has fixed layout, caption, head, 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/table/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/table\",\n\t\"title\": \"Table\",\n\t\"category\": \"text\",\n\t\"description\": \"Create structured content in rows and columns to display information.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"hasFixedLayout\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\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\"head\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": [],\n\t\t\t\"source\": \"query\",\n\t\t\t\"selector\": \"thead tr\",\n\t\t\t\"query\": {\n\t\t\t\t\"cells\": {\n\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\"default\": [],\n\t\t\t\t\t\"source\": \"query\",\n\t\t\t\t\t\"selector\": \"td,th\",\n\t\t\t\t\t\"query\": {\n\t\t\t\t\t\t\"content\": {\n\t\t\t\t\t\t\t\"type\": \"rich-text\",\n\t\t\t\t\t\t\t\"source\": \"rich-text\",\n\t\t\t\t\t\t\t\"role\": \"content\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"tag\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"default\": \"td\",\n\t\t\t\t\t\t\t\"source\": \"tag\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"scope\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\t\t\"attribute\": \"scope\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"align\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\t\t\"attribute\": \"data-align\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"colspan\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\t\t\"attribute\": \"colspan\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"rowspan\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\t\t\"attribute\": \"rowspan\"\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\t\"body\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": [],\n\t\t\t\"source\": \"query\",\n\t\t\t\"selector\": \"tbody tr\",\n\t\t\t\"query\": {\n\t\t\t\t\"cells\": {\n\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\"default\": [],\n\t\t\t\t\t\"source\": \"query\",\n\t\t\t\t\t\"selector\": \"td,th\",\n\t\t\t\t\t\"query\": {\n\t\t\t\t\t\t\"content\": {\n\t\t\t\t\t\t\t\"type\": \"rich-text\",\n\t\t\t\t\t\t\t\"source\": \"rich-text\",\n\t\t\t\t\t\t\t\"role\": \"content\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"tag\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"default\": \"td\",\n\t\t\t\t\t\t\t\"source\": \"tag\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"scope\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\t\t\"attribute\": \"scope\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"align\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\t\t\"attribute\": \"data-align\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"colspan\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\t\t\"attribute\": \"colspan\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"rowspan\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\t\t\"attribute\": \"rowspan\"\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\t\"foot\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": [],\n\t\t\t\"source\": \"query\",\n\t\t\t\"selector\": \"tfoot tr\",\n\t\t\t\"query\": {\n\t\t\t\t\"cells\": {\n\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\"default\": [],\n\t\t\t\t\t\"source\": \"query\",\n\t\t\t\t\t\"selector\": \"td,th\",\n\t\t\t\t\t\"query\": {\n\t\t\t\t\t\t\"content\": {\n\t\t\t\t\t\t\t\"type\": \"rich-text\",\n\t\t\t\t\t\t\t\"source\": \"rich-text\",\n\t\t\t\t\t\t\t\"role\": \"content\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"tag\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"default\": \"td\",\n\t\t\t\t\t\t\t\"source\": \"tag\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"scope\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\t\t\"attribute\": \"scope\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"align\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\t\t\"attribute\": \"data-align\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"colspan\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\t\t\"attribute\": \"colspan\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"rowspan\": {\n\t\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\t\t\"attribute\": \"rowspan\"\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\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"align\": true,\n\t\t\"color\": {\n\t\t\t\"__experimentalSkipSerialization\": 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}\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\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": 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\"__experimentalSkipSerialization\": true,\n\t\t\t\"color\": 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\"style\": true,\n\t\t\t\t\"width\": 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-table > table\",\n\t\t\"spacing\": \".wp-block-table\"\n\t},\n\t\"styles\": [\n\t\t{\n\t\t\t\"name\": \"regular\",\n\t\t\t\"label\": \"Default\",\n\t\t\t\"isDefault\": true\n\t\t},\n\t\t{ \"name\": \"stripes\", \"label\": \"Stripes\" }\n\t],\n\t\"editorStyle\": \"wp-block-table-editor\",\n\t\"style\": \"wp-block-table\"\n}\n\n\n// File: packages/block-library/src/table/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { blockTable 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\thead: [\n\t\t\t\t{\n\t\t\t\t\tcells: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: __( 'Version' ),\n\t\t\t\t\t\t\ttag: 'th',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: __( 'Jazz Musician' ),\n\t\t\t\t\t\t\ttag: 'th',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: __( 'Release Date' ),\n\t\t\t\t\t\t\ttag: 'th',\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\tbody: [\n\t\t\t\t{\n\t\t\t\t\tcells: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: '5.2',\n\t\t\t\t\t\t\ttag: 'td',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: __( 'Jaco Pastorius' ),\n\t\t\t\t\t\t\ttag: 'td',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: __( 'May 7, 2019' ),\n\t\t\t\t\t\t\ttag: 'td',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcells: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: '5.1',\n\t\t\t\t\t\t\ttag: 'td',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: __( 'Betty Carter' ),\n\t\t\t\t\t\t\ttag: 'td',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: __( 'February 21, 2019' ),\n\t\t\t\t\t\t\ttag: 'td',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcells: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: '5.0',\n\t\t\t\t\t\t\ttag: 'td',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: __( 'Bebo Valdés' ),\n\t\t\t\t\t\t\ttag: 'td',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: __( 'December 6, 2018' ),\n\t\t\t\t\t\t\ttag: 'td',\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\tviewportWidth: 450,\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/table/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tRichText,\n\tuseBlockProps,\n\t__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,\n\t__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,\n\t__experimentalGetElementClassName,\n} from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { hasFixedLayout, head, body, foot, caption } = attributes;\n\tconst isEmpty = ! head.length && ! body.length && ! foot.length;\n\n\tif ( isEmpty ) {\n\t\treturn null;\n\t}\n\n\tconst colorProps = getColorClassesAndStyles( attributes );\n\tconst borderProps = getBorderClassesAndStyles( attributes );\n\n\tconst classes = clsx( colorProps.className, borderProps.className, {\n\t\t'has-fixed-layout': hasFixedLayout,\n\t} );\n\n\tconst hasCaption = ! RichText.isEmpty( caption );\n\n\tconst Section = ( { type, rows } ) => {\n\t\tif ( ! rows.length ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst Tag = `t${ type }`;\n\n\t\treturn (\n\t\t\t<Tag>\n\t\t\t\t{ rows.map( ( { cells }, rowIndex ) => (\n\t\t\t\t\t<tr key={ rowIndex }>\n\t\t\t\t\t\t{ cells.map(\n\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\tcontent,\n\t\t\t\t\t\t\t\t\ttag,\n\t\t\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t\t\t\talign,\n\t\t\t\t\t\t\t\t\tcolspan,\n\t\t\t\t\t\t\t\t\trowspan,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tcellIndex\n\t\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\t\tconst cellClasses = clsx( {\n\t\t\t\t\t\t\t\t\t[ `has-text-align-${ align }` ]: align,\n\t\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<RichText.Content\n\t\t\t\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\t\t\t\tcellClasses\n\t\t\t\t\t\t\t\t\t\t\t\t? cellClasses\n\t\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tdata-align={ align }\n\t\t\t\t\t\t\t\t\t\ttagName={ tag }\n\t\t\t\t\t\t\t\t\t\tvalue={ content }\n\t\t\t\t\t\t\t\t\t\tkey={ cellIndex }\n\t\t\t\t\t\t\t\t\t\tscope={\n\t\t\t\t\t\t\t\t\t\t\ttag === 'th' ? scope : undefined\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tcolSpan={ colspan }\n\t\t\t\t\t\t\t\t\t\trowSpan={ rowspan }\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) }\n\t\t\t\t\t</tr>\n\t\t\t\t) ) }\n\t\t\t</Tag>\n\t\t);\n\t};\n\n\treturn (\n\t\t<figure { ...useBlockProps.save() }>\n\t\t\t<table\n\t\t\t\tclassName={ classes === '' ? undefined : classes }\n\t\t\t\tstyle={ { ...colorProps.style, ...borderProps.style } }\n\t\t\t>\n\t\t\t\t<Section type=\"head\" rows={ head } />\n\t\t\t\t<Section type=\"body\" rows={ body } />\n\t\t\t\t<Section type=\"foot\" rows={ foot } />\n\t\t\t</table>\n\t\t\t{ hasCaption && (\n\t\t\t\t<RichText.Content\n\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\tvalue={ caption }\n\t\t\t\t\tclassName={ __experimentalGetElementClassName( '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": "Create a custom WordPress block that lets users effortlessly insert and adjust Google Calendar displays by specifying the calendar's web address and visual dimensions."
},
{
"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 block for Displays the rating of a product review. that allows users to configure: 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-rating/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-review-rating\",\n\t\"title\": \"Review Rating\",\n\t\"category\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/product-reviews\" ],\n\t\"description\": \"Displays the rating 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\"interactivity\": {\n\t\t\t\"clientNavigation\": 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}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-rating/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tAlignmentToolbar,\n\tBlockControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport { REVIEWS_STORE_NAME } from '@woocommerce/data';\n\nexport default function Edit( {\n\t// commentId is the ID of the review.\n\tcontext: { commentId: reviewId },\n\tattributes,\n\tsetAttributes,\n}: BlockEditProps< {\n\ttextAlign: string;\n} > & {\n\tcontext: { commentId: string };\n} ) {\n\tconst { textAlign } = attributes;\n\tconst className = clsx( 'wc-block-product-review-rating', {\n\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t} );\n\tconst blockProps = useBlockProps( {\n\t\tclassName,\n\t} );\n\tconst rating = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getReview } = select( REVIEWS_STORE_NAME );\n\t\t\tconst review = reviewId ? getReview( Number( reviewId ) ) : null;\n\t\t\treturn review?.rating ?? 4;\n\t\t},\n\t\t[ reviewId ]\n\t);\n\n\tconst starStyle = {\n\t\twidth: ( rating / 5 ) * 100 + '%',\n\t};\n\n\tconst ratingText = sprintf(\n\t\t/* translators: %f is referring to the average rating value */\n\t\t__( 'Rated %f out of 5', 'woocommerce' ),\n\t\trating\n\t);\n\n\tconst ratingHTML = {\n\t\t__html: sprintf(\n\t\t\t/* translators: %s is the rating value wrapped in HTML strong tags. */\n\t\t\t__( 'Rated %s out of 5', 'woocommerce' ),\n\t\t\tsprintf( '<strong class=\"rating\">%f</strong>', rating )\n\t\t),\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<div\n\t\t\t\t\tclassName=\"wc-block-product-review-rating__stars\"\n\t\t\t\t\trole=\"img\"\n\t\t\t\t\taria-label={ ratingText }\n\t\t\t\t>\n\t\t\t\t\t<span\n\t\t\t\t\t\tstyle={ starStyle }\n\t\t\t\t\t\tdangerouslySetInnerHTML={ ratingHTML }\n\t\t\t\t\t/>\n\t\t\t\t</div>\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 Gutenberg block to showcase dynamically refreshed Instagram post thumbnails, incorporating configuration settings for authentication, user selection, grid layout, and additional customization parameters."
},
{
"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": "Build a Gutenberg block that Enable customers to change the sorting order of the products. with these attributes: font size, use label"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/catalog-sorting/block.json\n{\n\t\"name\": \"woocommerce/catalog-sorting\",\n\t\"title\": \"Catalog Sorting\",\n\t\"description\": \"Enable customers to change the sorting order of the products.\",\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\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": false\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"fontSize\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"small\"\n\t\t},\n\t\t\"useLabel\": {\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/catalog-sorting/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport { Disabled, PanelBody, ToggleControl } from '@wordpress/components';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BlockAttributes } from './types';\n\nconst CatalogSorting = ( {\n\tuseLabel,\n}: Pick< BlockAttributes, 'useLabel' > ) => {\n\treturn (\n\t\t<>\n\t\t\t{ useLabel ? (\n\t\t\t\t<>\n\t\t\t\t\t<label\n\t\t\t\t\t\tclassName=\"orderby-label\"\n\t\t\t\t\t\thtmlFor=\"woocommerce-orderby\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Sort by', 'woocommerce' ) }\n\t\t\t\t\t</label>\n\t\t\t\t\t<select className=\"orderby\" id=\"woocommerce-orderby\">\n\t\t\t\t\t\t<option>{ __( 'Default', 'woocommerce' ) }</option>\n\t\t\t\t\t</select>\n\t\t\t\t</>\n\t\t\t) : (\n\t\t\t\t<select className=\"orderby\">\n\t\t\t\t\t<option>{ __( 'Default sorting', 'woocommerce' ) }</option>\n\t\t\t\t</select>\n\t\t\t) }\n\t\t</>\n\t);\n};\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: BlockEditProps< BlockAttributes > ) => {\n\tconst { useLabel } = attributes;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'woocommerce wc-block-catalog-sorting',\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Accessibility', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show visual label', 'woocommerce' ) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Displays \"Sort by\" text before the dropdown menu to improve clarity and accessibility.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ useLabel }\n\t\t\t\t\t\tonChange={ ( isChecked ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tuseLabel: isChecked,\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 { ...blockProps }>\n\t\t\t\t<Disabled>\n\t\t\t\t\t<CatalogSorting useLabel={ useLabel } />\n\t\t\t\t</Disabled>\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": "Implement a flexible text component allowing dynamic content, source attribution, and text alignment options within a WordPress 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: packages/block-library/src/pullquote/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/pullquote\",\n\t\"title\": \"Pullquote (deprecated)\",\n\t\"category\": \"text\",\n\t\"description\": \"This block is deprecated. Please use the Quote block instead.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"value\": {\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\"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\"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\"background\": 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\"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\"inserter\": 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\"__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\"__experimentalStyle\": {\n\t\t\t\"typography\": {\n\t\t\t\t\"fontSize\": \"1.5em\",\n\t\t\t\t\"lineHeight\": \"1.6\"\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-pullquote-editor\",\n\t\"style\": \"wp-block-pullquote\"\n}\n\n\n// File: packages/block-library/src/pullquote/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { pullquote 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\tvalue:\n\t\t\t\t// translators: Quote serving as example for the Pullquote block. Attributed to Matt Mullenweg.\n\t\t\t\t__(\n\t\t\t\t\t'One of the hardest things to do in technology is disrupt yourself.'\n\t\t\t\t),\n\t\t\tcitation: __( 'Matt Mullenweg' ),\n\t\t},\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'value',\n\t\t\tlabel: __( 'Content' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t\t{\n\t\t\tid: 'citation',\n\t\t\tlabel: __( 'Citation' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'value' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/pullquote/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { textAlign, citation, value } = attributes;\n\tconst shouldShowCitation = ! RichText.isEmpty( citation );\n\n\treturn (\n\t\t<figure\n\t\t\t{ ...useBlockProps.save( {\n\t\t\t\tclassName: clsx( {\n\t\t\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t\t\t} ),\n\t\t\t} ) }\n\t\t>\n\t\t\t<blockquote>\n\t\t\t\t<RichText.Content tagName=\"p\" value={ value } />\n\t\t\t\t{ shouldShowCitation && (\n\t\t\t\t\t<RichText.Content tagName=\"cite\" value={ citation } />\n\t\t\t\t) }\n\t\t\t</blockquote>\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": "Create a media block with customizable image before, image after, caption, orientation"
},
{
"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/image-compare/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/image-compare\",\n\t\"title\": \"Image Compare\",\n\t\"description\": \"Compare two images with a slider. Works best with images of the same size.\",\n\t\"keywords\": [ \"juxtapose\", \"photos\", \"pictures\", \"side by side\", \"slider\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"media\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M21 4h-6v1.5h6c.3 0 .5.2.5.5v.4l-3.6 3.5L15 8.1v1.8l2.6 1.7c.1.1.3.1.4.1.2 0 .4-.1.5-.2l3-2.9V18c0 .3-.2.5-.5.5h-6V20h6c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zM1 6v12c0 1.1.9 2 2 2h10.5V4H3c-1.1 0-2 .9-2 2zm11 12.5H3c-.3 0-.5-.2-.5-.5v-1.4L5 14.7l1.5-1.1.1-.1 3 1.9c.1.1.3.1.4.1.2 0 .4-.1.5-.2L12 14v4.5zm0-6.6l-2.1 2L7 12c-.1-.1-.3-.1-.4-.1h-.1c-.1 0-.3.1-.4.1l-1.1.9-2.5 1.8V6c0-.3.2-.5.5-.5h9v6.4z'/></svg>\",\n\t\"supports\": { \"align\": [ \"wide\", \"full\" ] },\n\t\"attributes\": {\n\t\t\"imageBefore\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {}\n\t\t},\n\t\t\"imageAfter\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {}\n\t\t},\n\t\t\"caption\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"orientation\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"horizontal\"\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/image-compare/edit.js\nimport { InspectorControls, RichText, useBlockProps } from '@wordpress/block-editor';\nimport { Placeholder } from '@wordpress/components';\nimport { useResizeObserver } from '@wordpress/compose';\nimport { useLayoutEffect, useRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { photonizedImgProps } from '../tiled-gallery/utils';\nimport ImageCompareControls from './controls';\nimport ImgUpload from './img-upload';\nimport useDebounce from './use-debounce';\nimport './editor.scss';\nimport './view.js';\n\n/* global juxtapose */\n\nconst Edit = ( { attributes, clientId, isSelected, setAttributes } ) => {\n\tconst { align, imageBefore, imageAfter, caption, orientation } = attributes;\n\n\tconst blockProps = useBlockProps();\n\tconst juxtaposeRef = useRef( undefined );\n\tconst [ containerWidth, setContainerWidth ] = useState( 0 );\n\n\t// Let's look for resize so we can trigger the thing.\n\tconst setElement = useResizeObserver(\n\t\tresizeObserverEntries => {\n\t\t\tconst width = resizeObserverEntries[ 0 ]?.contentRect.width;\n\t\t\tif ( width ) {\n\t\t\t\tsetContainerWidth( width );\n\t\t\t}\n\t\t},\n\t\t{ box: 'border-box' }\n\t);\n\n\tuseDebounce(\n\t\tsz => {\n\t\t\tif ( sz > 0 ) {\n\t\t\t\tif ( typeof juxtapose !== 'undefined' && juxtapose.sliders ) {\n\t\t\t\t\t// only update for *this* slide\n\t\t\t\t\tjuxtapose.sliders.forEach( elem => {\n\t\t\t\t\t\tconst parentElem = elem.wrapper.parentElement;\n\t\t\t\t\t\tif ( parentElem.id === clientId ) {\n\t\t\t\t\t\t\telem.optimizeWrapper( sz );\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\t200,\n\t\tcontainerWidth\n\t);\n\n\t// Initial state if attributes already set or not.\n\t// If both images are set, add juxtapose class, which is picked up by the library.\n\tconst isComplete = imageBefore && imageBefore.url && imageAfter && imageAfter.url;\n\tconst classes = isComplete ? 'image-compare__comparison juxtapose' : 'image-compare__placeholder';\n\n\t// Watching for changes to key variables to trigger scan.\n\tuseLayoutEffect( () => {\n\t\tif ( imageBefore.url && imageAfter.url && typeof juxtapose !== 'undefined' ) {\n\t\t\tif ( juxtaposeRef.current ) {\n\t\t\t\tsetElement( juxtaposeRef.current );\n\t\t\t\tjuxtapose.makeSlider( juxtaposeRef?.current );\n\t\t\t}\n\t\t}\n\t}, [ align, imageBefore, imageAfter, orientation, setElement ] );\n\n\treturn (\n\t\t<figure { ...blockProps } id={ clientId }>\n\t\t\t<InspectorControls key=\"controls\">\n\t\t\t\t<ImageCompareControls { ...{ attributes, setAttributes } } />\n\t\t\t</InspectorControls>\n\t\t\t<div ref={ juxtaposeRef } className={ classes } data-mode={ orientation || 'horizontal' }>\n\t\t\t\t<Placeholder label={ null }>\n\t\t\t\t\t<div className=\"image-compare__image-before\">\n\t\t\t\t\t\t<ImgUpload\n\t\t\t\t\t\t\timage={ {\n\t\t\t\t\t\t\t\tid: imageBefore.id,\n\t\t\t\t\t\t\t\turl: imageBefore.url,\n\t\t\t\t\t\t\t\talt: imageBefore.alt,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tplaceHolderLabel={ __( 'Image before', 'jetpack' ) }\n\t\t\t\t\t\t\tonChange={ img => {\n\t\t\t\t\t\t\t\tif ( img.media_type === 'image' || img.type === 'image' ) {\n\t\t\t\t\t\t\t\t\tconst { src } = photonizedImgProps( img );\n\t\t\t\t\t\t\t\t\tconst { alt, id, media_details } = img;\n\t\t\t\t\t\t\t\t\tconst width = media_details?.width ?? img.width;\n\t\t\t\t\t\t\t\t\tconst height = media_details?.height ?? img.height;\n\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\timageBefore: {\n\t\t\t\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\t\t\turl: src ? src : img.url,\n\t\t\t\t\t\t\t\t\t\t\talt,\n\t\t\t\t\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\t\t\t\t\theight,\n\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}\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\t<div className=\"image-compare__image-after\">\n\t\t\t\t\t\t<ImgUpload\n\t\t\t\t\t\t\timage={ {\n\t\t\t\t\t\t\t\tid: imageAfter.id,\n\t\t\t\t\t\t\t\turl: imageAfter.url,\n\t\t\t\t\t\t\t\talt: imageAfter.alt,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tplaceHolderLabel={ __( 'Image after', 'jetpack' ) }\n\t\t\t\t\t\t\tonChange={ img => {\n\t\t\t\t\t\t\t\tif ( img.media_type === 'image' || img.type === 'image' ) {\n\t\t\t\t\t\t\t\t\tconst { src } = photonizedImgProps( img );\n\t\t\t\t\t\t\t\t\tconst { alt, id, media_details } = img;\n\t\t\t\t\t\t\t\t\tconst width = media_details?.width ?? img.width;\n\t\t\t\t\t\t\t\t\tconst height = media_details?.height ?? img.height;\n\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\timageAfter: {\n\t\t\t\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\t\t\turl: src ? src : img.url,\n\t\t\t\t\t\t\t\t\t\t\talt,\n\t\t\t\t\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\t\t\t\t\theight,\n\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}\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</Placeholder>\n\t\t\t</div>\n\t\t\t{ ( ! RichText.isEmpty( caption ) ||\n\t\t\t\t( isSelected && imageBefore.url && imageAfter.url ) ) && (\n\t\t\t\t<RichText\n\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\tplaceholder={ __( 'Write caption', 'jetpack' ) }\n\t\t\t\t\tvalue={ caption }\n\t\t\t\t\tonChange={ value => setAttributes( { caption: value } ) }\n\t\t\t\t\tinlineToolbar\n\t\t\t\t/>\n\t\t\t) }\n\t\t</figure>\n\t);\n};\n\nexport default Edit;\n\n\n// File: projects/plugins/jetpack/extensions/blocks/image-compare/save.js\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\n\nconst save = ( { attributes } ) => {\n\tconst blockProps = useBlockProps.save();\n\tconst { imageBefore, imageAfter, caption, orientation } = attributes;\n\n\treturn (\n\t\t<figure { ...blockProps }>\n\t\t\t<div className=\"juxtapose\" data-mode={ orientation || 'horizontal' }>\n\t\t\t\t<img\n\t\t\t\t\tid={ imageBefore.id }\n\t\t\t\t\tsrc={ imageBefore.url }\n\t\t\t\t\talt={ imageBefore.alt }\n\t\t\t\t\twidth={ imageBefore.width }\n\t\t\t\t\theight={ imageBefore.height }\n\t\t\t\t\tclassName=\"image-compare__image-before\"\n\t\t\t\t/>\n\t\t\t\t<img\n\t\t\t\t\tid={ imageAfter.id }\n\t\t\t\t\tsrc={ imageAfter.url }\n\t\t\t\t\talt={ imageAfter.alt }\n\t\t\t\t\twidth={ imageAfter.width }\n\t\t\t\t\theight={ imageAfter.height }\n\t\t\t\t\tclassName=\"image-compare__image-after\"\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t{ ! RichText.isEmpty( caption ) && (\n\t\t\t\t<RichText.Content tagName=\"figcaption\" value={ caption } />\n\t\t\t) }\n\t\t</figure>\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": "Build a Gutenberg block that Displays the post count of a taxonomy term. with these attributes: bracket type"
},
{
"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-count/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/term-count\",\n\t\"title\": \"Term Count\",\n\t\"category\": \"theme\",\n\t\"description\": \"Displays the post count of a taxonomy term.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"termId\", \"taxonomy\" ],\n\t\"attributes\": {\n\t\t\"bracketType\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [ \"none\", \"round\", \"square\", \"curly\", \"angle\" ],\n\t\t\t\"default\": \"round\"\n\t\t}\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\"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\"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-term-count\"\n}\n\n\n// File: packages/block-library/src/term-count/index.js\n/**\n * WordPress dependencies\n */\nimport { termCount 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\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": "Develop a revenue-generating WordPress block that allows flexible URL customization for monetization purposes."
},
{
"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/tock/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/tock\",\n\t\"title\": \"Tock\",\n\t\"description\": \"Reserve a table at your restaurant with Tock.\",\n\t\"keywords\": [ \"booking\", \"reservation\", \"restaurant\" ],\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='M10 15.619C6.84915 15.619 4.28572 13.0542 4.28572 9.90176C4.28572 7.24269 6.10957 5.00183 8.57143 4.36551V0C3.72557 0.693782 0 4.86162 0 9.90176C0 15.4274 4.47715 19.9069 10 19.9069C12.2461 19.9069 14.3193 19.1658 15.9887 17.9148L12.9003 14.825C12.0494 15.3287 11.0581 15.619 10 15.619 M15.7135 9.90176C15.7135 10.9604 15.4233 11.9522 14.9199 12.8035L18.0082 15.8935C19.2585 14.2232 19.9992 12.149 19.9992 9.90176C19.9992 4.86162 16.2736 0.693782 11.4277 0V4.36551C13.8896 5.00183 15.7135 7.24269 15.7135 9.90176'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"html\": false,\n\t\t\"multiple\": false\n\t},\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"url\": \"roister\"\n\t\t},\n\t\t\"viewportWidth\": 250\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/tock/edit.js\nimport { useBlockProps, BlockControls } from '@wordpress/block-editor';\nimport {\n\tSandBox,\n\tTextControl,\n\tToolbarGroup,\n\tToolbarButton,\n\tButton,\n\tBaseControl,\n\tDropdown,\n} from '@wordpress/components';\nimport {\n\tcreateInterpolateElement,\n\tuseCallback,\n\tuseEffect,\n\tuseState,\n\tuseRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { keyboardReturn } from '@wordpress/icons';\nimport { ENTER, ESCAPE } from '@wordpress/keycodes';\n\nimport './editor.scss';\n\nconst UrlDropdown = ( { tockUrl, setEditedUrl, setUrl, cancel } ) => {\n\tconst firstRender = useRef( true );\n\tconst committedChanges = useRef( false );\n\tconst handleSubmitOrCancel = ( event, onClose ) => {\n\t\tconst { keyCode } = event;\n\n\t\tif (\n\t\t\tkeyCode === ENTER &&\n\t\t\t'' !== tockUrl // Disallow submitting empty values.\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t\tcommitChanges( onClose );\n\t\t}\n\n\t\tif ( keyCode === ESCAPE ) {\n\t\t\tevent.preventDefault();\n\t\t\tcancel();\n\t\t\tonClose();\n\t\t}\n\t};\n\n\tconst commitChanges = close => {\n\t\tsetUrl();\n\t\tcommittedChanges.current = true;\n\t\tclose();\n\t};\n\n\treturn (\n\t\t<ToolbarGroup>\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tvariant: 'toolbar',\n\t\t\t\t} }\n\t\t\t\tonClose={ () =>\n\t\t\t\t\tcommittedChanges.current ? ( committedChanges.current = false ) : cancel()\n\t\t\t\t}\n\t\t\t\tplacement=\"bottom-start\"\n\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => {\n\t\t\t\t\tif ( firstRender.current && ! isOpen && ! tockUrl ) {\n\t\t\t\t\t\tfirstRender.current = false;\n\t\t\t\t\t\tonToggle();\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tclassName=\"components-toolbar__control\"\n\t\t\t\t\t\t\tlabel={ __( 'Edit Tock business name', 'jetpack' ) }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\tisOpen && cancel();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Edit', 'jetpack' ) }\n\t\t\t\t\t\t</ToolbarButton>\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t<BaseControl\n\t\t\t\t\t\tclassName=\"jetpack-tock-url-settings\"\n\t\t\t\t\t\thelp={ createInterpolateElement(\n\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t'The Tock business can be found in the URL of your public Tock page. For example: www.exploretock.com/<b>myname</b>',\n\t\t\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tb: <strong />,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t>\n\t\t\t\t\t\t<div className=\"jetpack-tock-url-input-wrapper\">\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\tplaceholder={ __( 'Add Tock business name', 'jetpack' ) }\n\t\t\t\t\t\t\t\tonChange={ setEditedUrl }\n\t\t\t\t\t\t\t\tvalue={ tockUrl }\n\t\t\t\t\t\t\t\tonKeyDownCapture={ event => handleSubmitOrCancel( event, onClose ) }\n\t\t\t\t\t\t\t\tclassName=\"jetpack-tock-url-input\"\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<div className=\"jetpack-tock-url-input-action\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Submit', 'jetpack' ) }\n\t\t\t\t\t\t\t\t\ticon={ keyboardReturn }\n\t\t\t\t\t\t\t\t\tclassName=\"jetpack-tock-url-input-submit\"\n\t\t\t\t\t\t\t\t\tonClick={ () => commitChanges( onClose ) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</BaseControl>\n\t\t\t\t) }\n\t\t\t/>\n\t\t</ToolbarGroup>\n\t);\n};\n\nconst TockPreview = ( { url, popoverAnchor } ) => {\n\tconst html = `\n\t\t<div id=\"Tock_widget_container\" data-tock-display-mode=\"Button\" data-tock-color-mode=\"Blue\" data-tock-locale=\"en-us\" data-tock-timezone=\"America/New_York\" style=\"display:inline-block;\"></div>\n\t\t<script src=\"https://www.exploretock.com/tock.js\" async></script>\n\t\t<script>\n\t\t\t!function(t,o){if(!t.tock){var e=t.tock=function(){e.callMethod?\n\t\t\t e.callMethod.apply(e,arguments):e.queue.push(arguments)};t._tock||(t._tock=e),\n\t\t\t e.push=e,e.loaded=!0,e.version='1.0',e.queue=[];}}(window,document);\n\t\t\ttock('init', '${ url }');\n\t\t</script>\n\t`;\n\n\treturn (\n\t\t<div ref={ popoverAnchor }>\n\t\t\t{\n\t\t\t\t// Related to this bug (https://github.com/WordPress/gutenberg/issues/16831), the\n\t\t\t\t// `SandBox` component won't rerun the scripts correctly when the injected `html` prop changes.\n\t\t\t\t// To work around that, we change the key of the component to force a new one render\n\t\t\t }\n\t\t\t<SandBox html={ html } key={ `tock-${ url }` } />\n\t\t\t{ /* Use an overlay to prevent interactivity with the preview, since the preview does not always resize correctly. */ }\n\t\t\t<div className=\"block-library-embed__interactive-overlay\" />\n\t\t</div>\n\t);\n};\n\nexport default function TockBlockEdit( { attributes, setAttributes, isSelected } ) {\n\tconst tockUrl = attributes.url ?? '';\n\tconst [ editedUrl, setEditedUrl ] = useState( tockUrl );\n\n\tconst setUrl = () => {\n\t\tconst newUrl = editedUrl.replace( /.*exploretock.com\\//, '' );\n\t\tsetEditedUrl( newUrl );\n\t\tsetAttributes( { url: newUrl } );\n\t};\n\n\tconst cancel = useCallback( () => {\n\t\tsetEditedUrl( tockUrl );\n\t}, [ tockUrl ] );\n\n\tuseEffect( () => {\n\t\tif ( ! isSelected ) {\n\t\t\tcancel();\n\t\t}\n\t}, [ isSelected, cancel ] );\n\n\treturn (\n\t\t<div { ...useBlockProps() }>\n\t\t\t<BlockControls>\n\t\t\t\t<UrlDropdown\n\t\t\t\t\ttockUrl={ editedUrl }\n\t\t\t\t\tsetEditedUrl={ setEditedUrl }\n\t\t\t\t\tsetUrl={ setUrl }\n\t\t\t\t\tcancel={ cancel }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<TockPreview url={ tockUrl } />\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": "Construct a flexible podcast playback block that empowers users to select and stream episodes, offering extensive customization through settings like source URL, episode filtering, display limits, and multiple advanced 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/podcast-player/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/podcast-player\",\n\t\"title\": \"Podcast Player\",\n\t\"description\": \"Select and play episodes from a single podcast.\",\n\t\"keywords\": [ \"audio\", \"embed\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"embed\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='m22,6h-5v8.18c-.31-.11-.65-.18-1-.18-1.66,0-3,1.34-3,3s1.34,3,3,3,3-1.34,3-3v-9h3v-2h0Zm-7,0H3v2h12v-2h0Zm0,4H3v2h12v-2h0Zm-4,4H3v2h8v-2h0Zm4,3c0-.55.45-1,1-1s1,.45,1,1-.45,1-1,1-1-.45-1-1Z' /></svg>\",\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true\n\t\t},\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},\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"selectedEpisodes\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t},\n\t\t\"itemsToShow\": {\n\t\t\t\"type\": \"integer\",\n\t\t\t\"default\": 5\n\t\t},\n\t\t\"showCoverArt\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showEpisodeTitle\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showEpisodeDescription\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"primaryColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customPrimaryColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"hexPrimaryColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"secondaryColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customSecondaryColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"hexSecondaryColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"backgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"hexBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"exampleFeedData\": {\n\t\t\t\"type\": \"object\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"customPrimaryColor\": \"GREEN\",\n\t\t\t\"hexPrimaryColor\": \"GREEN\",\n\t\t\t\"exampleFeedData\": {\n\t\t\t\t\"title\": \"Jetpack Example Podcast\",\n\t\t\t\t\"link\": \"https://jetpack.com\",\n\t\t\t\t\"cover\": \"https://jetpackme.files.wordpress.com/2020/05/jetpack-example-podcast-cover.png?w=160\",\n\t\t\t\t\"tracks\": [\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": \"3\",\n\t\t\t\t\t\t\"title\": \"3. Our third episode\",\n\t\t\t\t\t\t\"duration\": \"14:58\"\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": \"2\",\n\t\t\t\t\t\t\"title\": \"2. Interview with a special guest\",\n\t\t\t\t\t\t\"duration\": \"19:17\"\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": \"1\",\n\t\t\t\t\t\t\"title\": \"1. Welcome to Example Podcast\",\n\t\t\t\t\t\t\"duration\": \"11:25\"\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/podcast-player/edit.js\nimport { isWpcomPlatformSite } from '@automattic/jetpack-script-data';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\twithColors,\n\tPanelColorSettings,\n\tContrastChecker,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { createBlock } from '@wordpress/blocks';\nimport {\n\tButton,\n\tExternalLink,\n\tPanelBody,\n\tPlaceholder,\n\tRangeControl,\n\tTextControl,\n\tToolbarButton,\n\tToolbarGroup,\n\twithNotices,\n\tToggleControl,\n\tSpinner,\n\tComboboxControl,\n} from '@wordpress/components';\nimport { compose, withInstanceId } from '@wordpress/compose';\nimport { withDispatch } from '@wordpress/data';\nimport { useCallback, useEffect, useState, useRef, useReducer, useMemo } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { isURL, prependHTTP } from '@wordpress/url';\nimport debugFactory from 'debug';\nimport { debounce } from 'lodash';\nimport { applyFallbackStyles } from '../../shared/apply-fallback-styles';\nimport { maybeCopyElementsToSiteEditorContext } from '../../shared/block-editor-asset-loader';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport { fetchPodcastFeed, fetchTrackQuantity } from './api';\nimport metadata from './block.json';\nimport PodcastPlayer from './components/podcast-player';\nimport { PODCAST_FEED, EMBED_BLOCK } from './constants';\nimport { queueMusic } from './icons/';\nimport { podcastPlayerReducer, actions } from './state';\nimport { makeCancellable } from './utils';\n\nimport './editor.scss';\n\nconst DEFAULT_MIN_ITEMS = 1;\nconst debug = debugFactory( 'jetpack:podcast-player:edit' );\nconst noop = () => {};\n\n// Support page link.\nconst supportUrl = isWpcomPlatformSite()\n\t? 'http://en.support.wordpress.com/wordpress-editor/blocks/podcast-player-block/'\n\t: 'https://jetpack.com/support/jetpack-blocks/podcast-player-block/';\n\nconst PodcastPlayerEdit = ( {\n\tinstanceId,\n\tattributes,\n\tsetAttributes,\n\tnoticeOperations: { createErrorNotice, removeAllNotices },\n\tnoticeUI,\n\tprimaryColor: primaryColorProp,\n\tsetPrimaryColor,\n\tsecondaryColor: secondaryColorProp,\n\tsetSecondaryColor,\n\tfallbackTextColor,\n\tbackgroundColor: backgroundColorProp,\n\tsetBackgroundColor,\n\tfallbackBackgroundColor,\n\tisSelected,\n\treplaceWithEmbedBlock,\n} ) => {\n\t// Validated attributes.\n\tconst validatedAttributes = getValidatedAttributes( metadata.attributes, attributes );\n\tconst {\n\t\turl,\n\t\tselectedEpisodes,\n\t\titemsToShow,\n\t\tshowCoverArt,\n\t\tshowEpisodeTitle,\n\t\tshowEpisodeDescription,\n\t\texampleFeedData,\n\t} = validatedAttributes;\n\n\tconst playerId = `jetpack-podcast-player-block-${ instanceId }`;\n\n\tconst blockProps = useBlockProps();\n\tconst [ hasMigratedStyles, setHasMigratedStyles ] = useState( false );\n\tconst [ defaultMaxItems, setDefaultMaxItems ] = useState( 10 );\n\n\t// State.\n\tconst cancellableFetch = useRef( undefined );\n\tconst [ { selectedGuid, checkUrl, ...state }, dispatch ] = useReducer( podcastPlayerReducer, {\n\t\teditedUrl: url || '',\n\t\tisEditing: ! url && ! exampleFeedData,\n\t\tisLoading: false,\n\t\tfeedData: exampleFeedData || {},\n\t\tisInteractive: false,\n\t\tselectedGuid: selectedEpisodes?.[ 0 ]?.guid,\n\t\tcheckUrl: url || '',\n\t} );\n\n\tconst fetchFeed = useMemo(\n\t\t() =>\n\t\t\tdebounce( requestParams => {\n\t\t\t\tdispatch( { type: actions.START_FETCH } );\n\t\t\t\tcancellableFetch.current?.cancel();\n\t\t\t\tcancellableFetch.current = makeCancellable(\n\t\t\t\t\tfetchPodcastFeed( { ...requestParams, fetchEpisodeOptions: true } )\n\t\t\t\t);\n\n\t\t\t\tcancellableFetch.current.promise.then(\n\t\t\t\t\tresponse => {\n\t\t\t\t\t\tremoveAllNotices();\n\t\t\t\t\t\tif ( response?.isCanceled ) {\n\t\t\t\t\t\t\tdebug( 'Block was unmounted during fetch', response );\n\t\t\t\t\t\t\treturn; // bail if canceled to avoid setting state\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Check what type of response we got and act accordingly.\n\t\t\t\t\t\tswitch ( response?.type ) {\n\t\t\t\t\t\t\tcase PODCAST_FEED:\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\turl: requestParams.url,\n\t\t\t\t\t\t\t\t\tselectedEpisodes: requestParams.guids.map( guid => ( { guid } ) ),\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\treturn dispatch( { type: actions.FEED_RECEIVED, payload: response.data } );\n\t\t\t\t\t\t\tcase EMBED_BLOCK:\n\t\t\t\t\t\t\t\treturn replaceWithEmbedBlock();\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\terror => {\n\t\t\t\t\t\tif ( error?.isCanceled ) {\n\t\t\t\t\t\t\tdebug( 'Block was unmounted during fetch', error );\n\t\t\t\t\t\t\treturn; // bail if canceled to avoid setting state\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Show error and allow to edit URL.\n\t\t\t\t\t\tdebug( 'feed error', error );\n\t\t\t\t\t\tremoveAllNotices();\n\t\t\t\t\t\tcreateErrorNotice(\n\t\t\t\t\t\t\t// Error messages already come localized.\n\t\t\t\t\t\t\terror.message ||\n\t\t\t\t\t\t\t\t// Fallback to a generic message.\n\t\t\t\t\t\t\t\t__( \"Your podcast couldn't be embedded. Please double check your URL.\", 'jetpack' )\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdispatch( { type: actions.START_EDITING } );\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}, 300 ),\n\t\t[ replaceWithEmbedBlock, setAttributes, createErrorNotice, removeAllNotices ]\n\t);\n\n\t// Call once on mount or unmount (the return callback).\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tcancellableFetch?.current?.cancel?.();\n\t\t};\n\t}, [] );\n\n\t// The Podcast player audio element requires wpmedialement styles.\n\t// These aren't available in the Site Editor context, so we have to copy them in.\n\tconst podCastPlayerRef = useCallback(\n\t\tnode => {\n\t\t\tif ( node !== null && ! hasMigratedStyles ) {\n\t\t\t\tmaybeCopyElementsToSiteEditorContext(\n\t\t\t\t\t[ 'link#mediaelement-css', 'link#wp-mediaelement-css' ],\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tsetHasMigratedStyles( true );\n\t\t\t}\n\t\t},\n\t\t[ hasMigratedStyles ]\n\t);\n\n\t// Load RSS feed initially and when the feed or selected episode changes.\n\tuseEffect( () => {\n\t\t// Don't do anything if no url is set.\n\t\tif ( '' === checkUrl ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfetchFeed( {\n\t\t\turl: checkUrl,\n\t\t\tguids: selectedGuid ? [ selectedGuid ] : [],\n\t\t} );\n\n\t\treturn () => cancellableFetch?.current?.cancel?.();\n\t}, [ fetchFeed, checkUrl, selectedGuid ] );\n\n\t// Retrieve tracks quantity to fetch; the jetpack_podcast_helper_tracks_quantity filter value.\n\tuseEffect( () => {\n\t\tfetchTrackQuantity().then( response => {\n\t\t\tsetDefaultMaxItems( response );\n\t\t} );\n\t}, [] );\n\n\t// Make sure itemsToShow is 1 when we have a selected episode\n\tuseEffect( () => {\n\t\tif ( selectedGuid && 1 !== itemsToShow ) {\n\t\t\tsetAttributes( { itemsToShow: 1 } );\n\t\t}\n\t}, [ selectedGuid, itemsToShow, setAttributes ] );\n\n\t// Bring back the overlay after block gets deselected.\n\tuseEffect( () => {\n\t\tif ( ! isSelected && state.isInteractive ) {\n\t\t\tdispatch( { type: actions.PREVENT_INTERACTIONS } );\n\t\t}\n\t}, [ isSelected, state.isInteractive ] );\n\n\t/**\n\t * Check if the current URL of the Podcast RSS feed is valid. If so, set the\n\t * block attribute and changes the edition mode. This function is bound to the\n\t * onSubmit event for the form.\n\t *\n\t * @param {object} event - Form on submit event object.\n\t */\n\tconst checkPodcastLink = event => {\n\t\tevent.preventDefault();\n\n\t\tif ( '' === state.editedUrl ) {\n\t\t\treturn;\n\t\t}\n\n\t\t/*\n\t\t * Ensure URL has `http` appended to it (if it doesn't already) before we\n\t\t * accept it as the entered URL.\n\t\t */\n\t\tconst prependedURL = prependHTTP( state.editedUrl );\n\n\t\tif ( ! isURL( prependedURL ) ) {\n\t\t\tcreateErrorNotice(\n\t\t\t\t__( \"Your podcast couldn't be embedded. Please double check your URL.\", 'jetpack' )\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\t/*\n\t\t * Short-circuit feed fetching if we tried before, use useEffect otherwise.\n\t\t * @see {@link https://github.com/Automattic/jetpack/pull/15213}\n\t\t */\n\t\tif ( prependedURL === checkUrl ) {\n\t\t\t// Reset the feedData, so that we display the spinner.\n\t\t\tdispatch( { type: actions.CLEAR_FEED } );\n\t\t\tfetchFeed( {\n\t\t\t\turl: checkUrl,\n\t\t\t\tguids: selectedEpisodes[ 0 ]?.guid ? [ selectedEpisodes[ 0 ].guid ] : [],\n\t\t\t} );\n\t\t} else {\n\t\t\tdispatch( { type: actions.CHECK_URL, payload: prependedURL } );\n\t\t}\n\n\t\t/*\n\t\t * Also update the temporary `input` value in order that clicking `Replace`\n\t\t * in the UI will show the \"corrected\" version of the URL (ie: with `http`\n\t\t * prepended if it wasn't originally present).\n\t\t */\n\t\tdispatch( { type: actions.FINISH_EDITING, payload: prependedURL } );\n\t};\n\n\tlet content;\n\n\tif ( state.isEditing ) {\n\t\tcontent = (\n\t\t\t<Placeholder\n\t\t\t\ticon={ queueMusic }\n\t\t\t\tlabel={ __( 'Podcast Player', 'jetpack' ) }\n\t\t\t\tinstructions={ __( 'Enter your podcast RSS feed URL.', 'jetpack' ) }\n\t\t\t\tclassName={ 'jetpack-podcast-player__placeholder' }\n\t\t\t>\n\t\t\t\t<form onSubmit={ checkPodcastLink }>\n\t\t\t\t\t{ noticeUI }\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\tinputMode=\"url\"\n\t\t\t\t\t\tplaceholder={ __( 'Enter URL here…', 'jetpack' ) }\n\t\t\t\t\t\tvalue={ state.editedUrl }\n\t\t\t\t\t\tclassName={ 'components-placeholder__input' }\n\t\t\t\t\t\tonChange={ editedUrl => dispatch( { type: actions.EDIT_URL, payload: editedUrl } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t<Button variant=\"primary\" type=\"submit\">\n\t\t\t\t\t\t{ __( 'Embed', 'jetpack' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</form>\n\t\t\t\t<div className=\"components-placeholder__learn-more\">\n\t\t\t\t\t<ExternalLink href={ supportUrl }>\n\t\t\t\t\t\t{ __( 'Learn more about embeds', 'jetpack' ) }\n\t\t\t\t\t</ExternalLink>\n\t\t\t\t</div>\n\t\t\t</Placeholder>\n\t\t);\n\t}\n\n\t// With no tracks data, this is either the first load or the URL has changed\n\t// and we need the data to refresh before displaying the other controls.\n\telse if ( ! state.feedData.tracks?.length ) {\n\t\tcontent = (\n\t\t\t<Placeholder\n\t\t\t\ticon={ queueMusic }\n\t\t\t\tlabel={ __( 'Podcast Player', 'jetpack' ) }\n\t\t\t\tinstructions={ __( 'Loading podcast feed…', 'jetpack' ) }\n\t\t\t>\n\t\t\t\t<Spinner />\n\t\t\t</Placeholder>\n\t\t);\n\t} else {\n\t\tconst createColorChangeHandler = ( colorAttr, handler ) => color => {\n\t\t\tsetAttributes( { [ colorAttr ]: color } );\n\t\t\thandler( color );\n\t\t};\n\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\taria-label={ __( 'Edit Podcast Feed URL', 'jetpack' ) }\n\t\t\t\t\t\t\tonClick={ () => dispatch( { type: actions.START_EDITING } ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Replace', 'jetpack' ) }\n\t\t\t\t\t\t</ToolbarButton>\n\t\t\t\t\t</ToolbarGroup>\n\t\t\t\t</BlockControls>\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<PanelBody title={ __( 'Podcast settings', 'jetpack' ) }>\n\t\t\t\t\t\t{ ( ComboboxControl || 0 === selectedEpisodes.length ) && (\n\t\t\t\t\t\t\t<RangeControl\n\t\t\t\t\t\t\t\tlabel={ __( 'Number of items', 'jetpack' ) }\n\t\t\t\t\t\t\t\tvalue={ itemsToShow }\n\t\t\t\t\t\t\t\tonChange={ value => setAttributes( { itemsToShow: selectedGuid ? 1 : value } ) }\n\t\t\t\t\t\t\t\tmin={ DEFAULT_MIN_ITEMS }\n\t\t\t\t\t\t\t\tmax={ defaultMaxItems }\n\t\t\t\t\t\t\t\trequired\n\t\t\t\t\t\t\t\tdisabled={ !! selectedGuid }\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ ComboboxControl && (\n\t\t\t\t\t\t\t<ComboboxControl\n\t\t\t\t\t\t\t\tclassName=\"jetpack-podcast-player__episode-selector\"\n\t\t\t\t\t\t\t\tvalue={ selectedGuid }\n\t\t\t\t\t\t\t\tonChange={ guid => dispatch( { type: actions.SELECT_EPISODE, payload: guid } ) }\n\t\t\t\t\t\t\t\toptions={ state.feedData.options || [] }\n\t\t\t\t\t\t\t\tlabel={ __( 'Episode', 'jetpack' ) }\n\t\t\t\t\t\t\t\tonFilterValueChange={ noop }\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __( 'Show Cover Art', 'jetpack' ) }\n\t\t\t\t\t\t\tchecked={ showCoverArt }\n\t\t\t\t\t\t\tonChange={ value => setAttributes( { showCoverArt: value } ) }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __( 'Show Episode Title', 'jetpack' ) }\n\t\t\t\t\t\t\tchecked={ showEpisodeTitle }\n\t\t\t\t\t\t\tonChange={ value => setAttributes( { showEpisodeTitle: value } ) }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __( 'Show Episode Description', 'jetpack' ) }\n\t\t\t\t\t\t\tchecked={ showEpisodeDescription }\n\t\t\t\t\t\t\tonChange={ value => setAttributes( { showEpisodeDescription: value } ) }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t\t<PanelColorSettings\n\t\t\t\t\t\ttitle={ __( 'Color Settings', 'jetpack' ) }\n\t\t\t\t\t\tcolorSettings={ [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: primaryColorProp.color,\n\t\t\t\t\t\t\t\tonChange: createColorChangeHandler( 'hexPrimaryColor', setPrimaryColor ),\n\t\t\t\t\t\t\t\tlabel: __( 'Primary Color', 'jetpack' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: secondaryColorProp.color,\n\t\t\t\t\t\t\t\tonChange: createColorChangeHandler( 'hexSecondaryColor', setSecondaryColor ),\n\t\t\t\t\t\t\t\tlabel: __( 'Secondary Color', 'jetpack' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: backgroundColorProp.color,\n\t\t\t\t\t\t\t\tonChange: createColorChangeHandler( 'hexBackgroundColor', setBackgroundColor ),\n\t\t\t\t\t\t\t\tlabel: __( 'Background Color', 'jetpack' ),\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<ContrastChecker\n\t\t\t\t\t\t\tisLargeText={ false }\n\t\t\t\t\t\t\ttextColor={ secondaryColorProp.color }\n\t\t\t\t\t\t\tbackgroundColor={ backgroundColorProp.color }\n\t\t\t\t\t\t\tfallbackBackgroundColor={ fallbackBackgroundColor }\n\t\t\t\t\t\t\tfallbackTextColor={ fallbackTextColor }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PanelColorSettings>\n\t\t\t\t</InspectorControls>\n\n\t\t\t\t<div id={ playerId } ref={ podCastPlayerRef }>\n\t\t\t\t\t<PodcastPlayer\n\t\t\t\t\t\tplayerId={ playerId }\n\t\t\t\t\t\tattributes={ validatedAttributes }\n\t\t\t\t\t\ttracks={ state.feedData.tracks }\n\t\t\t\t\t\tcover={ state.feedData.cover }\n\t\t\t\t\t\ttitle={ state.feedData.title }\n\t\t\t\t\t\tlink={ state.feedData.link }\n\t\t\t\t\t/>\n\t\t\t\t\t{ /*\n\t\t\t\t\t * Disabled because the overlay div doesn't actually have a role or\n\t\t\t\t\t * functionality as far as the user is concerned. We're just catching\n\t\t\t\t\t * the first click so that the block can be selected without\n\t\t\t\t\t * interacting with the embed preview that the overlay covers.\n\t\t\t\t\t */ }\n\t\t\t\t\t{ /* eslint-disable jsx-a11y/no-static-element-interactions */ }\n\t\t\t\t\t{ ! state.isInteractive && ! state.isLoading && (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName=\"jetpack-podcast-player__interactive-overlay\"\n\t\t\t\t\t\t\tonMouseUp={ () => dispatch( { type: actions.MAKE_INTERACTIVE } ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ /* eslint-enable jsx-a11y/no-static-element-interactions */ }\n\t\t\t\t\t{ state.isLoading && (\n\t\t\t\t\t\t<div className=\"jetpack-podcast-player__loading-overlay\">\n\t\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t\t</div>\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\twithDispatch( ( dispatch, { clientId, attributes } ) => {\n\t\treturn {\n\t\t\treplaceWithEmbedBlock() {\n\t\t\t\tdispatch( 'core/block-editor' ).replaceBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\tcreateBlock( 'core/embed', {\n\t\t\t\t\t\turl: attributes.url,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t} ),\n\twithColors( 'backgroundColor', { primaryColor: 'color' }, { secondaryColor: 'color' } ),\n\twithNotices,\n\twithInstanceId,\n\tapplyFallbackStyles,\n] )( PodcastPlayerEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/podcast-player/save.js\nimport { useBlockProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\nexport default function save( { attributes } ) {\n\tconst { url } = attributes;\n\tif ( ! url || url === '' ) {\n\t\treturn;\n\t}\n\n\tconst blockProps = useBlockProps.save();\n\treturn (\n\t\t<a\n\t\t\t{ ...blockProps }\n\t\t\tclassName={ clsx( blockProps.className, 'jetpack-podcast-player__direct-link' ) }\n\t\t\thref={ url }\n\t\t>\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": "Create a WooCommerce block that provides users the ability to refine product grid results through price range selection, offering extensive customization like class assignment, input field visibility, and inline input preferences."
},
{
"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/price-filter/block.json\n{\n\t\"name\": \"woocommerce/price-filter\",\n\t\"title\": \"Filter by Price Controls\",\n\t\"description\": \"Enable customers to filter the product grid by choosing a price range.\",\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\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": false\n\t\t},\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\"showInputFields\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"inlineInput\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"showFilterButton\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\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/price-filter/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { getAdminLink } from '@woocommerce/settings';\nimport { blocksConfig } from '@woocommerce/block-settings';\nimport BlockTitle from '@woocommerce/editor-components/block-title';\nimport { Icon, currencyDollar, external } from '@wordpress/icons';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport {\n\tPlaceholder,\n\tDisabled,\n\tPanelBody,\n\tToggleControl,\n\tButton,\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 './editor.scss';\nimport type { Attributes } from './types';\nimport { UpgradeNotice } from '../filter-wrapper/upgrade';\n\nexport default function ( {\n\tattributes,\n\tsetAttributes,\n\tclientId,\n}: BlockEditProps< Attributes > ) {\n\tconst {\n\t\theading,\n\t\theadingLevel,\n\t\tshowInputFields,\n\t\tinlineInput,\n\t\tshowFilterButton,\n\t} = attributes;\n\n\tconst blockProps = useBlockProps();\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={ __( 'Settings', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\tlabel={ __( 'Price Range Selector', 'woocommerce' ) }\n\t\t\t\t\t\tisBlock\n\t\t\t\t\t\tvalue={ showInputFields ? 'editable' : 'text' }\n\t\t\t\t\t\tonChange={ ( value: string ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowInputFields: value === 'editable',\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclassName=\"wc-block-price-filter__price-range-toggle\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"editable\"\n\t\t\t\t\t\t\tlabel={ __( 'Editable', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"text\"\n\t\t\t\t\t\t\tlabel={ __( 'Text', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t{ showInputFields && (\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __( 'Inline input fields', 'woocommerce' ) }\n\t\t\t\t\t\t\tchecked={ inlineInput }\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\tinlineInput: ! inlineInput,\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'Show input fields inline with the slider.',\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) }\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t\"Show 'Apply filters' button\",\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Products will update when the button is clicked.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ showFilterButton }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowFilterButton: ! showFilterButton,\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);\n\t};\n\n\tconst noProductsPlaceholder = () => (\n\t\t<Placeholder\n\t\t\tclassName=\"wc-block-price-slider\"\n\t\t\ticon={ <Icon icon={ currencyDollar } /> }\n\t\t\tlabel={ __( 'Filter by Price', 'woocommerce' ) }\n\t\t\tinstructions={ __(\n\t\t\t\t'Display a slider to filter products in your store by price.',\n\t\t\t\t'woocommerce'\n\t\t\t) }\n\t\t>\n\t\t\t<p>\n\t\t\t\t{ __(\n\t\t\t\t\t'To filter your products by price you first need to assign prices to your products.',\n\t\t\t\t\t'woocommerce'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t\t<Button\n\t\t\t\tclassName=\"wc-block-price-slider__add-product-button\"\n\t\t\t\tvariant=\"secondary\"\n\t\t\t\thref={ getAdminLink( 'post-new.php?post_type=product' ) }\n\t\t\t\ttarget=\"_top\"\n\t\t\t>\n\t\t\t\t{ __( 'Add new product', 'woocommerce' ) + ' ' }\n\t\t\t\t<Icon icon={ external } />\n\t\t\t</Button>\n\t\t\t<Button\n\t\t\t\tclassName=\"wc-block-price-slider__read_more_button\"\n\t\t\t\tvariant=\"tertiary\"\n\t\t\t\thref=\"https://woocommerce.com/document/managing-products/\"\n\t\t\t\ttarget=\"_blank\"\n\t\t\t>\n\t\t\t\t{ __( 'Learn more', 'woocommerce' ) }\n\t\t\t</Button>\n\t\t</Placeholder>\n\t);\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ blocksConfig.productCount === 0 ? (\n\t\t\t\tnoProductsPlaceholder()\n\t\t\t) : (\n\t\t\t\t<>\n\t\t\t\t\t{ getInspectorControls() }\n\t\t\t\t\t{ heading && (\n\t\t\t\t\t\t<BlockTitle\n\t\t\t\t\t\t\tclassName=\"wc-block-price-filter__title\"\n\t\t\t\t\t\t\theadingLevel={ headingLevel }\n\t\t\t\t\t\t\theading={ heading }\n\t\t\t\t\t\t\tonChange={ ( value: string ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { heading: 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<Disabled>\n\t\t\t\t\t\t<Block attributes={ attributes } isEditor={ true } />\n\t\t\t\t\t</Disabled>\n\t\t\t\t</>\n\t\t\t) }\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 personalized WordPress block for showcasing taxonomy term information, integrating core components like the term's title, descriptive text, and supplementary details."
},
{
"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": "Craft a custom Gutenberg block to render page number navigation with configurable mid-range pagination 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: 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": "Develop a block for The author biography. that allows users to configure: 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-author-biography/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-author-biography\",\n\t\"title\": \"Author Biography\",\n\t\"category\": \"theme\",\n\t\"description\": \"The author biography.\",\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\": [ \"postType\", \"postId\" ],\n\t\"example\": {\n\t\t\"viewportWidth\": 350\n\t},\n\t\"supports\": {\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\"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-post-author-biography\"\n}\n\n\n// File: packages/block-library/src/post-author-biography/index.js\n/**\n * WordPress dependencies\n */\nimport { postAuthor 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};\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 is preview, product id"
},
{
"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/single-product/block.json\n{\n\t\"name\": \"woocommerce/single-product\",\n\t\"icon\": \"info\",\n\t\"title\": \"Product\",\n\t\"description\": \"Display a single product of your choice with full control over its presentation.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\", \"single product\" ],\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"align\": [ \"wide\", \"full\" ]\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\"productId\": {\n\t\t\t\"type\": \"number\"\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\"usesContext\": [ \"postId\", \"postType\", \"queryId\" ],\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/single-product/save.tsx\n/**\n * External dependencies\n */\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nconst Save = () => {\n\t// We add the `woocommerce` class to the wrapper to apply WooCommerce styles to the block.\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: 'woocommerce',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ /* @ts-expect-error: `InnerBlocks.Content` is a component that is typed in WordPress core*/ }\n\t\t\t<InnerBlocks.Content />\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": "Create a embed block with customizable style type, size, icon color, 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/sharing-buttons/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/sharing-buttons\",\n\t\"title\": \"Sharing Buttons\",\n\t\"description\": \"Give your readers the ability to easily share your content with X, Facebook, Tumblr, LinkedIn, and a host of other services to help spread your message across the web.\",\n\t\"keywords\": [\n\t\t\"sharing\",\n\t\t\"social\",\n\t\t\"bluesky\",\n\t\t\"twitter\",\n\t\t\"x\",\n\t\t\"linkedin\",\n\t\t\"facebook\",\n\t\t\"mastodon\",\n\t\t\"tumblr\",\n\t\t\"threads\",\n\t\t\"whatsapp\",\n\t\t\"telegram\",\n\t\t\"pinterest\",\n\t\t\"pocket\",\n\t\t\"reddit\",\n\t\t\"nextdoor\",\n\t\t\"print\",\n\t\t\"email\"\n\t],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"embed\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path d='M9 11.8l6.1-4.5c.1.4.4.7.9.7h2c.6 0 1-.4 1-1V5c0-.6-.4-1-1-1h-2c-.6 0-1 .4-1 1v.4l-6.4 4.8c-.2-.1-.4-.2-.6-.2H6c-.6 0-1 .4-1 1v2c0 .6.4 1 1 1h2c.2 0 .4-.1.6-.2l6.4 4.8v.4c0 .6.4 1 1 1h2c.6 0 1-.4 1-1v-2c0-.6-.4-1-1-1h-2c-.5 0-.8.3-.9.7L9 12.2v-.4z' /></svg>\",\n\t\"attributes\": {\n\t\t\"styleType\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"icon-text\",\n\t\t\t\"validValues\": [ \"icon-text\", \"icon\", \"text\", \"official\" ]\n\t\t},\n\t\t\"size\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"has-normal-icon-size\",\n\t\t\t\"validValues\": [\n\t\t\t\t\"has-small-icon-size\",\n\t\t\t\t\"has-normal-icon-size\",\n\t\t\t\t\"has-large-icon-size\",\n\t\t\t\t\"has-huge-icon-size\"\n\t\t\t]\n\t\t},\n\t\t\"iconColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customIconColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"iconColorValue\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"iconBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customIconBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"iconBackgroundColorValue\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"styleType\": \"styleType\",\n\t\t\"iconColor\": \"iconColor\",\n\t\t\"iconColorValue\": \"iconColorValue\",\n\t\t\"iconBackgroundColor\": \"iconBackgroundColor\",\n\t\t\"iconBackgroundColorValue\": \"iconBackgroundColorValue\"\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"left\", \"center\", \"right\" ],\n\t\t\"anchor\": true,\n\t\t\"__experimentalExposeControlsToChildren\": true,\n\t\t\"layout\": {\n\t\t\t\"allowSwitching\": false,\n\t\t\t\"allowInheriting\": false,\n\t\t\t\"allowVerticalAlignment\": false,\n\t\t\t\"default\": {\n\t\t\t\t\"type\": \"flex\"\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"enableContrastChecker\": true,\n\t\t\t\"background\": true,\n\t\t\t\"gradients\": true,\n\t\t\t\"customGradient\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": false\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"blockGap\": [ \"horizontal\", \"vertical\" ],\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"units\": [ \"px\", \"em\", \"rem\", \"vh\", \"vw\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"blockGap\": true,\n\t\t\t\t\"margin\": true,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"innerBlocks\": [\n\t\t\t{\n\t\t\t\t\"name\": \"jetpack/sharing-button\",\n\t\t\t\t\"attributes\": {\n\t\t\t\t\t\"service\": \"facebook\"\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"name\": \"jetpack/sharing-button\",\n\t\t\t\t\"attributes\": {\n\t\t\t\t\t\"service\": \"x\"\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"name\": \"jetpack/sharing-button\",\n\t\t\t\t\"attributes\": {\n\t\t\t\t\t\"service\": \"mastodon\"\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t},\n\t\"viewScript\": \"file:./view.js\",\n\t\"style\": \"file:./view.css\"\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/sharing-buttons/edit.js\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\nimport './style.scss';\nimport clsx from 'clsx';\nimport SharingButtonsBlockControls from './components/block-controls';\nimport SharingButtonsInspectorControls from './components/inspector-controls';\n\nconst ALLOWED_BLOCKS = [ 'jetpack/sharing-button' ];\n\nfunction SharingButtonsEdit( props ) {\n\tconst { attributes } = props;\n\tconst { size } = attributes;\n\n\tconst SharingButtonsPlaceholder = (\n\t\t<li>{ __( 'Click plus to add a Sharing Button', 'jetpack' ) }</li>\n\t);\n\n\tconst className = clsx( size, 'jetpack-sharing-buttons__services-list' );\n\n\tconst blockProps = useBlockProps( { className } );\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\tallowedBlocks: ALLOWED_BLOCKS,\n\t\tplaceholder: SharingButtonsPlaceholder,\n\t\ttemplateLock: false,\n\t\torientation: attributes.layout?.orientation ?? 'horizontal',\n\t\tsharingEventsAdded: true,\n\t\t__experimentalAppenderTagName: 'li',\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<SharingButtonsBlockControls { ...props } />\n\t\t\t<SharingButtonsInspectorControls { ...props } />\n\t\t\t<ul { ...innerBlocksProps } />\n\t\t</>\n\t);\n}\n\nexport default SharingButtonsEdit;\n\n\n// File: projects/plugins/jetpack/extensions/blocks/sharing-buttons/save.js\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\nexport default function save( { attributes } ) {\n\tconst { size } = attributes;\n\tconst className = clsx( size, 'jetpack-sharing-buttons__services-list' );\n\tconst id = 'jetpack-sharing-serivces-list';\n\tconst blockProps = useBlockProps.save( { className } );\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\n\treturn <ul { ...innerBlocksProps } id={ id } />;\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 with selected tags. with these attributes: columns, rows, align buttons, and 6 more options"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-tag/block.json\n{\n\t\"name\": \"woocommerce/product-tag\",\n\t\"title\": \"Products by Tag\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"Display a grid of products with selected tags.\",\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\"tags\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t},\n\t\t\"tagOperator\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"any\"\n\t\t},\n\t\t\"orderby\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"date\"\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},\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-tag/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport './editor.scss';\nimport type { ProductsByTagBlockProps } from './types';\n\nexport const Edit = ( props: ProductsByTagBlockProps ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Block { ...props } />\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 Displays a foldable layout that groups content in collapsible sections. that allows users to configure: icon position, show icon, autoclose, 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/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/accordion\",\n\t\"title\": \"Accordion\",\n\t\"category\": \"design\",\n\t\"description\": \"Displays a foldable layout that groups content in collapsible sections.\",\n\t\"example\": {},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"html\": false,\n\t\t\"align\": [ \"wide\", \"full\" ],\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\"background\": true,\n\t\t\t\"gradients\": 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\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"blockGap\": true\n\t\t},\n\t\t\"shadow\": true,\n\t\t\"layout\": true,\n\t\t\"ariaLabel\": true,\n\t\t\"interactivity\": 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\"contentRole\": true\n\t},\n\t\"attributes\": {\n\t\t\"iconPosition\": {\n\t\t\t\"type\": \"string\",\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\t\"autoclose\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"headingLevel\": {\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},\n\t\"providesContext\": {\n\t\t\"core/accordion-icon-position\": \"iconPosition\",\n\t\t\"core/accordion-show-icon\": \"showIcon\",\n\t\t\"core/accordion-heading-level\": \"headingLevel\"\n\t},\n\t\"allowedBlocks\": [ \"core/accordion-item\" ],\n\t\"textdomain\": \"default\",\n\t\"viewScriptModule\": \"@wordpress/block-library/accordion/view\"\n}\n\n\n// File: packages/block-library/src/accordion/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\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';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/accordion-item',\n\t\t\t\tinnerBlocks: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'core/accordion-heading',\n\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\ttitle: __(\n\t\t\t\t\t\t\t\t'Lorem ipsum dolor sit amet, consectetur.'\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\t{\n\t\t\t\tname: 'core/accordion-item',\n\t\t\t\tinnerBlocks: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'core/accordion-heading',\n\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\ttitle: __(\n\t\t\t\t\t\t\t\t'Suspendisse commodo lacus, interdum et.'\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],\n\t},\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/accordion/save.js\n/**\n * WordPress dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport default function save() {\n\tconst blockProps = useBlockProps.save( {\n\t\trole: 'group',\n\t} );\n\treturn <div { ...useInnerBlocksProps.save( blockProps ) } />;\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 versatile WooCommerce block with comprehensive customization capabilities, allowing users to modify query specifications, tag attributes, and multiple extended 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/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": "Craft a Gutenberg block displaying cart fee details, incorporating class name and lock attributes for 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/cart/inner-blocks/cart-order-summary-fee/block.json\n{\n\t\"name\": \"woocommerce/cart-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/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-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 widget block featuring customizable elements including label, visibility toggle, placeholder, 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/search/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/search\",\n\t\"title\": \"Search\",\n\t\"category\": \"widgets\",\n\t\"description\": \"Help visitors find your content.\",\n\t\"keywords\": [ \"find\" ],\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\"showLabel\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"placeholder\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"width\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"widthUnit\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"buttonText\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"buttonPosition\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"button-outside\"\n\t\t},\n\t\t\"buttonUseIcon\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"query\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {}\n\t\t},\n\t\t\"isSearchFieldHidden\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"left\", \"center\", \"right\" ],\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"__experimentalSkipSerialization\": 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\"interactivity\": true,\n\t\t\"typography\": {\n\t\t\t\"__experimentalSkipSerialization\": true,\n\t\t\t\"__experimentalSelector\": \".wp-block-search__label, .wp-block-search__input, .wp-block-search__button\",\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\"__experimentalSkipSerialization\": 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},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"html\": false\n\t},\n\t\"editorStyle\": \"wp-block-search-editor\",\n\t\"style\": \"wp-block-search\"\n}\n\n\n// File: packages/block-library/src/search/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { search 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 metadata from './block.json';\nimport edit from './edit';\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: { buttonText: __( 'Search' ), label: __( 'Search' ) },\n\t\tviewportWidth: 400,\n\t},\n\tvariations,\n\tedit,\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\tshownByDefault: true,\n\t\t},\n\t\t{\n\t\t\tid: 'buttonText',\n\t\t\tlabel: __( 'Button text' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t\t{\n\t\t\tid: 'placeholder',\n\t\t\tlabel: __( 'Placeholder' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'label' ],\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": "Build a Gutenberg block that Displays the name of the author of the comment. with these attributes: is link, link target, 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/comment-author-name/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/comment-author-name\",\n\t\"title\": \"Comment Author Name\",\n\t\"category\": \"theme\",\n\t\"ancestor\": [ \"core/comment-template\" ],\n\t\"description\": \"Displays the name of the author of the comment.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"isLink\": {\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\t\"default\": \"_self\"\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"commentId\" ],\n\t\"supports\": {\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\"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\"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-author-name\"\n}\n\n\n// File: packages/block-library/src/comment-author-name/index.js\n/**\n * WordPress dependencies\n */\nimport { commentAuthorName 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": "Develop a block for Displays a link to reply to a comment. that allows users to configure: 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/comment-reply-link/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/comment-reply-link\",\n\t\"title\": \"Comment Reply Link\",\n\t\"category\": \"theme\",\n\t\"ancestor\": [ \"core/comment-template\" ],\n\t\"description\": \"Displays a link to reply to 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\"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\"__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},\n\t\"style\": \"wp-block-comment-reply-link\"\n}\n\n\n// File: packages/block-library/src/comment-reply-link/index.js\n/**\n * WordPress dependencies\n */\nimport { commentReplyLink 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\tedit,\n\ticon,\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": "Develop a custom Gutenberg block that Display footnotes added to the page."
},
{
"role": "assistant",
"content": "// File: packages/block-library/src/footnotes/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/footnotes\",\n\t\"title\": \"Footnotes\",\n\t\"category\": \"text\",\n\t\"description\": \"Display footnotes added to the page.\",\n\t\"keywords\": [ \"references\" ],\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"postId\", \"postType\" ],\n\t\"supports\": {\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\": false,\n\t\t\t\t\"width\": false,\n\t\t\t\t\"style\": false\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"link\": true,\n\t\t\t\"text\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"link\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\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\"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\"__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\"__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-footnotes\"\n}\n\n\n// File: packages/block-library/src/footnotes/index.js\n/**\n * WordPress dependencies\n */\nimport { formatListNumbered as icon } from '@wordpress/icons';\nimport { registerFormatType } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport edit from './edit';\nimport metadata from './block.json';\nimport { formatName, format } from './format';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n};\n\nexport const init = () => {\n\tregisterFormatType( formatName, format );\n\tinitBlock( { name, metadata, settings } );\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 embed block with customizable book number, class, custom title, and 15 more options"
},
{
"role": "assistant",
"content": "// File: projects/plugins/jetpack/extensions/blocks/goodreads/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/goodreads\",\n\t\"title\": \"Goodreads\",\n\t\"description\": \"Features books from the shelves of your Goodreads account.\",\n\t\"keywords\": [ \"book\", \"read\", \"author\" ],\n\t\"version\": \"1.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"embed\",\n\t\"icon\": \"<svg height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg' aria-hidden='true' focusable='false'><path d='M19.525 15.977V.49h-2.059v2.906h-.064c-.211-.455-.481-.891-.842-1.307-.36-.412-.767-.777-1.232-1.094-.466-.314-.962-.561-1.519-.736C13.256.09 12.669 0 12.038 0c-1.21 0-2.3.225-3.246.67-.947.447-1.743 1.057-2.385 1.83-.642.773-1.133 1.676-1.47 2.711-.336 1.037-.506 2.129-.506 3.283 0 1.199.141 2.326.425 3.382.286 1.057.737 1.976 1.368 2.762.631.78 1.412 1.397 2.375 1.833.961.436 2.119.661 3.471.661 1.248 0 2.33-.315 3.262-.946s1.638-1.473 2.119-2.525h.061v2.284c0 2.044-.421 3.607-1.264 4.705-.84 1.081-2.224 1.638-4.146 1.638-.572 0-1.128-.061-1.669-.181-.542-.12-1.036-.315-1.487-.57-.437-.271-.827-.601-1.143-1.038-.316-.435-.526-.961-.632-1.593H5.064c.067.887.315 1.654.737 2.3.424.646.961 1.172 1.602 1.593.641.406 1.367.706 2.172.902.811.194 1.639.3 2.494.3 1.383 0 2.541-.195 3.486-.555.947-.376 1.714-.902 2.301-1.608.601-.708 1.021-1.549 1.293-2.556.27-1.007.42-2.134.42-3.367l-.044.062zm-7.484-.557c-.955 0-1.784-.189-2.479-.571-.697-.38-1.277-.882-1.732-1.503-.467-.621-.797-1.332-1.022-2.139s-.332-1.633-.332-2.484c0-.871.105-1.725.301-2.563.21-.84.54-1.587.992-2.24.451-.652 1.037-1.182 1.728-1.584s1.533-.605 2.51-.605 1.803.209 2.495.621c.676.415 1.247.959 1.683 1.634.436.677.751 1.429.947 2.255.195.826.285 1.656.285 2.482 0 .852-.12 1.678-.345 2.484-.226.807-.572 1.518-1.038 2.139-.465.621-1.021 1.123-1.698 1.503-.676.382-1.458.571-2.359.571h.064z'></path></svg>\",\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"align\": true\n\t},\n\t\"attributes\": {\n\t\t\"bookNumber\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"5\"\n\t\t},\n\t\t\"class\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customTitle\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"goodreadsId\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"id\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"link\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"orderOption\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"d\"\n\t\t},\n\t\t\"shelfOption\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"read\"\n\t\t},\n\t\t\"showAuthor\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showCover\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showRating\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showReview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"showTags\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"showTitle\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"sortOption\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"date_added\"\n\t\t},\n\t\t\"style\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"default\"\n\t\t},\n\t\t\"userInput\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"widgetId\": {\n\t\t\t\"type\": \"number\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"goodreadsId\": 1176283\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/goodreads/edit.js\nimport { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils';\nimport { BlockControls, InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { Placeholder, SandBox, Button, Spinner, withNotices } from '@wordpress/components';\nimport { useState, useEffect, useRef } from '@wordpress/element';\nimport { __, _x } from '@wordpress/i18n';\nimport metadata from './block.json';\nimport { GoodreadsBlockControls, GoodreadsInspectorControls } from './controls';\nimport useFetchGoodreadsData from './hooks/use-fetch-goodreads-data';\nimport { createGoodreadsEmbedLink } from './utils';\n\nconst GoodreadsEdit = props => {\n\tconst { attributes, className, noticeOperations, noticeUI, setAttributes } = props;\n\tconst [ userInput, setUserInput ] = useState( '' );\n\tconst [ url, setUrl ] = useState( '' );\n\tconst [ isResolvingUrl, setIsResolvingUrl ] = useState( false );\n\tconst prevPropsRef = useRef( null );\n\tconst blockProps = useBlockProps();\n\n\tconst { isFetchingData, goodreadsUserId, isError } = useFetchGoodreadsData( url );\n\n\tuseEffect( () => {\n\t\tif ( isFetchingData ) {\n\t\t\tsetIsResolvingUrl( true );\n\t\t}\n\n\t\tif ( ! isFetchingData ) {\n\t\t\tsetIsResolvingUrl( false );\n\n\t\t\tif ( isError ) {\n\t\t\t\tsetAttributes( { widgetId: undefined, goodreadsId: undefined, link: undefined } );\n\t\t\t\tsetErrorNotice();\n\t\t\t}\n\n\t\t\t// Applies when transforming from Legacy Widget,\n\t\t\t// in which case goodreadsId is already known.\n\t\t\tif ( attributes.goodreadsId ) {\n\t\t\t\tsetRequestLink();\n\t\t\t}\n\n\t\t\tif ( goodreadsUserId && ! isError ) {\n\t\t\t\tsetAttributes( { goodreadsId: goodreadsUserId } );\n\t\t\t\tsetRequestLink();\n\t\t\t}\n\t\t}\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [ goodreadsUserId, isFetchingData, isResolvingUrl, isError, setAttributes ] );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\tprevPropsRef.current &&\n\t\t\tattributes.goodreadsId &&\n\t\t\tattributes.widgetId === prevPropsRef.current.attributes.widgetId\n\t\t) {\n\t\t\tsetRequestLink();\n\t\t}\n\t\tprevPropsRef.current = props;\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [ props, attributes.goodreadsId, attributes.widgetId ] );\n\n\tconst setErrorNotice = () => {\n\t\tnoticeOperations.removeAllNotices();\n\t\tnoticeOperations.createErrorNotice(\n\t\t\t<>{ __( 'Sorry, this content could not be embedded.', 'jetpack' ) }</>\n\t\t);\n\t};\n\n\tconst setRequestLink = () => {\n\t\tconst selector = attributes.style === 'grid' ? 'gr_grid_widget_' : 'gr_custom_widget_';\n\t\tsetAttributes( {\n\t\t\twidgetId: Math.floor( Math.random() * 9999999 ),\n\t\t\tlink: createGoodreadsEmbedLink( { attributes } ),\n\t\t\tid: selector + attributes.widgetId,\n\t\t} );\n\t};\n\n\tconst submitForm = event => {\n\t\tif ( event ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\n\t\tsetUrl( userInput );\n\t\tsetIsResolvingUrl( true );\n\t};\n\n\tconst renderLoading = () => {\n\t\treturn (\n\t\t\t<div className=\"wp-block-embed is-loading\">\n\t\t\t\t<Spinner />\n\t\t\t\t<p>{ __( 'Embedding…', 'jetpack' ) }</p>\n\t\t\t</div>\n\t\t);\n\t};\n\n\tconst renderEditEmbed = () => {\n\t\treturn (\n\t\t\t<div className={ className }>\n\t\t\t\t<Placeholder\n\t\t\t\t\tlabel={ __( 'Goodreads', 'jetpack' ) }\n\t\t\t\t\tinstructions={ __( 'Paste a link to a Goodreads profile.', 'jetpack' ) }\n\t\t\t\t\ticon={ getBlockIconComponent( metadata ) }\n\t\t\t\t\tnotices={ noticeUI }\n\t\t\t\t>\n\t\t\t\t\t<form onSubmit={ submitForm }>\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\ttype=\"url\"\n\t\t\t\t\t\t\tvalue={ userInput }\n\t\t\t\t\t\t\tclassName=\"components-placeholder__input\"\n\t\t\t\t\t\t\taria-label={ __( 'Goodreads profile URL', 'jetpack' ) }\n\t\t\t\t\t\t\tplaceholder={ __( 'Enter a Goodreads profile URL to embed here…', 'jetpack' ) }\n\t\t\t\t\t\t\tonChange={ event => setUserInput( event.target.value ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Button variant=\"secondary\" type=\"submit\">\n\t\t\t\t\t\t\t{ _x( 'Embed', 'submit button label', 'jetpack' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</form>\n\t\t\t\t</Placeholder>\n\t\t\t</div>\n\t\t);\n\t};\n\n\tconst renderInlinePreview = () => {\n\t\tconst { link, id } = attributes;\n\n\t\tconst html = `\n\t\t<style> [class^=gr_custom_container_] { border: 1px solid gray; border-radius: 10px; margin: auto; padding: 0 5px 10px 5px; background-color: #fff; color: #000; width: 300px; } [class^=gr_custom_header_] { border-bottom: 1px solid gray; width: 100%; padding: 10px 0; margin: auto; text-align: center; font-size: 120%; } [class^=gr_custom_each_container_] { width: 100%; clear: both; margin: auto; overflow: auto; padding-bottom: 4px; border-bottom: 1px solid #aaa; } [class^=gr_custom_each_container_] { width: 100%; clear: both; margin-bottom: 10px; overflow: auto; padding-bottom: 4px; border-bottom: 1px solid #aaa; } [class^=gr_custom_book_container_] { overflow: hidden; height: 60px; float: left; margin-right: 6px; width: 39px; } [class^=gr_custom_author_] { font-size: 10px; } [class^=gr_custom_tags_] { font-size: 10px; color: gray; } [class^=gr_custom_rating_] { float: right; } [class^=gr_grid_book_container] { float: left; width: 98px; height: 160px; padding: 0 0; overflow: hidden; } [class^=gr_grid_book_container] img { height: 100%; width: 100%; } a { text-decoration: none; } a:hover { text-decoration: underline; } img { max-width: 100%; }</style>\n\t\t<script src=\"${ link }\"></script>\n \t<div id=\"${ id }\"></div>\n \t`;\n\n\t\treturn (\n\t\t\t<div className={ className }>\n\t\t\t\t<SandBox title=\"Goodreads\" html={ html } />\n\t\t\t\t<div className=\"block-library-embed__interactive-overlay\" />\n\t\t\t</div>\n\t\t);\n\t};\n\n\tlet content;\n\n\tif ( isResolvingUrl ) {\n\t\tcontent = renderLoading();\n\t} else if ( attributes.goodreadsId ) {\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<GoodreadsInspectorControls attributes={ attributes } setAttributes={ setAttributes } />\n\t\t\t\t</InspectorControls>\n\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<GoodreadsBlockControls attributes={ attributes } setAttributes={ setAttributes } />\n\t\t\t\t</BlockControls>\n\n\t\t\t\t{ renderInlinePreview() }\n\t\t\t</>\n\t\t);\n\t} else {\n\t\tcontent = renderEditEmbed();\n\t}\n\n\treturn <div { ...blockProps }>{ content }</div>;\n};\n\nexport default withNotices( GoodreadsEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/goodreads/save.js\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save() {\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 block for Earn income by adding high quality ads to your post. that allows users to configure: align, format, hide mobile"
},
{
"role": "assistant",
"content": "// File: projects/plugins/jetpack/extensions/blocks/wordads/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/wordads\",\n\t\"title\": \"Ad\",\n\t\"description\": \"Earn income by adding high quality ads to your post.\",\n\t\"keywords\": [ \"ads\", \"WordAds\", \"advertisement\" ],\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='M12,8H4A2,2 0 0,0 2,10V14A2,2 0 0,0 4,16H5V20A1,1 0 0,0 6,21H8A1,1 0 0,0 9,20V16H12L17,20V4L12,8M15,15.6L13,14H4V10H13L15,8.4V15.6M21.5,12C21.5,13.71 20.54,15.26 19,16V8C20.53,8.75 21.5,10.3 21.5,12Z'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": [ \"left\", \"center\", \"right\" ],\n\t\t\"alignWide\": false,\n\t\t\"className\": false,\n\t\t\"customClassName\": false,\n\t\t\"html\": false,\n\t\t\"reusable\": false\n\t},\n\t\"attributes\": {\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"center\"\n\t\t},\n\t\t\"format\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"mrec\"\n\t\t},\n\t\t\"hideMobile\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"example\": {}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/wordads/edit.js\nimport { ThemeProvider } from '@automattic/jetpack-components';\nimport { useModuleStatus } from '@automattic/jetpack-shared-extension-utils';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { WordAdsPlaceholder } from './components/jetpack-wordads-placeholder';\nimport { WordAdsSkeletonLoader } from './components/jetpack-wordads-skeleton-loader';\nimport { AD_FORMATS } from './constants';\nimport AdControls from './controls';\nimport wideSkyscraperExample from './example_160x600.png';\nimport rectangleExample from './example_300x250.png';\nimport mobileLeaderboardExample from './example_320x50.png';\nimport leaderboardExample from './example_728x90.png';\n\nimport './editor.scss';\n\nconst WordAdsEdit = ( { attributes, setAttributes } ) => {\n\tconst blockProps = useBlockProps();\n\tconst { format } = attributes;\n\tconst { isLoadingModules, isChangingStatus, isModuleActive, changeStatus } =\n\t\tuseModuleStatus( 'wordads' );\n\tconst selectedFormatObject = AD_FORMATS.find( ( { tag } ) => tag === format );\n\n\tconst getExampleAd = formatting => {\n\t\tswitch ( formatting ) {\n\t\t\tcase 'leaderboard':\n\t\t\t\treturn leaderboardExample;\n\t\t\tcase 'mobile_leaderboard':\n\t\t\t\treturn mobileLeaderboardExample;\n\t\t\tcase `wideskyscraper`:\n\t\t\t\treturn wideSkyscraperExample;\n\t\t\tdefault:\n\t\t\t\treturn rectangleExample;\n\t\t}\n\t};\n\n\tlet content;\n\n\tif ( ! isModuleActive ) {\n\t\tif ( isLoadingModules ) {\n\t\t\tcontent = (\n\t\t\t\t<ThemeProvider>\n\t\t\t\t\t<WordAdsSkeletonLoader />\n\t\t\t\t</ThemeProvider>\n\t\t\t);\n\t\t} else {\n\t\t\tcontent = (\n\t\t\t\t<WordAdsPlaceholder\n\t\t\t\t\tchangeStatus={ changeStatus }\n\t\t\t\t\tisModuleActive={ isModuleActive }\n\t\t\t\t\tisLoading={ isChangingStatus }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\t} else {\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t<AdControls { ...{ attributes, setAttributes } } />\n\t\t\t\t<div className={ `wp-block-jetpack-wordads jetpack-wordads-${ format }` }>\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"jetpack-wordads__ad\"\n\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\twidth: selectedFormatObject.width,\n\t\t\t\t\t\t\theight: selectedFormatObject.height,\n\t\t\t\t\t\t\tbackgroundImage: `url( ${ getExampleAd( format ) } )`,\n\t\t\t\t\t\t\tbackgroundSize: 'cover',\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\treturn <div { ...blockProps }>{ content }</div>;\n};\n\nexport default WordAdsEdit;\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 growth-oriented block allowing personalized labeling and statistical presentation with adaptable visualization 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: projects/plugins/jetpack/extensions/blocks/blog-stats/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/blog-stats\",\n\t\"title\": \"Blog Stats\",\n\t\"description\": \"Show a stats counter for your blog.\",\n\t\"keywords\": [ \"views\", \"hits\", \"analytics\", \"counter\", \"visitors\" ],\n\t\"version\": \"1.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg xmlns='http://www.w3.org/2000/svg' height='24' viewBox='0 -960 960 960' width='24'><path d='M160-200h160v-320H160v320Zm240 0h160v-560H400v560Zm240 0h160v-240H640v240ZM80-120v-480h240v-240h320v320h240v400H80Z'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"alignWide\": true,\n\t\t\"html\": false,\n\t\t\"multiple\": true,\n\t\t\"reusable\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": 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\"__experimentalFontFamily\": true,\n\t\t\t\"fontSize\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"label\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"statsData\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"views\"\n\t\t},\n\t\t\"statsOption\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"site\"\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/blog-stats/edit.js\nimport { useModuleStatus } from '@automattic/jetpack-shared-extension-utils';\nimport { formatNumber } from '@automattic/number-formatters';\nimport apiFetch from '@wordpress/api-fetch';\nimport { InspectorControls, RichText, useBlockProps } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __, _n } from '@wordpress/i18n';\nimport { BlogStatsInspectorControls } from './controls';\nimport { InactiveStatsPlaceholder } from './inactive-placeholder';\n\nfunction BlogStatsEdit( { attributes, className, setAttributes } ) {\n\tconst { isLoadingModules, isChangingStatus, isModuleActive, changeStatus } =\n\t\tuseModuleStatus( 'stats' );\n\tconst { label, statsData, statsOption } = attributes;\n\tconst [ blogViews, setBlogViews ] = useState( null );\n\tconst [ blogVisitors, setBlogVisitors ] = useState();\n\tconst [ postViews, setPostViews ] = useState();\n\tconst blockProps = useBlockProps();\n\n\tconst blogStats = statsData === 'views' ? blogViews : blogVisitors;\n\tconst stats = statsOption === 'post' ? postViews : blogStats;\n\n\tconst postId = useSelect( select => select( 'core/editor' ).getCurrentPostId(), [] );\n\n\tuseEffect( () => {\n\t\tif ( isModuleActive ) {\n\t\t\tapiFetch( {\n\t\t\t\tpath: Number.isInteger( postId )\n\t\t\t\t\t? `/wpcom/v2/blog-stats?post_id=${ postId }`\n\t\t\t\t\t: '/wpcom/v2/blog-stats',\n\t\t\t} ).then( response => {\n\t\t\t\tsetBlogViews( response[ 'blog-views' ] );\n\t\t\t\tsetBlogVisitors( response[ 'blog-visitors' ] );\n\n\t\t\t\t// Display \"12,345\" as an obvious placeholder when we have no Post ID.\n\t\t\t\t// Applies to widgets, FSE templates etc.\n\t\t\t\tsetPostViews( Number.isInteger( postId ) ? response[ 'post-views' ] : '12345' );\n\t\t\t} );\n\t\t}\n\t}, [ postId, isModuleActive ] );\n\n\t// We don't collect visitor data for individual posts.\n\tuseEffect( () => {\n\t\tif ( statsData === 'visitors' ) {\n\t\t\tsetAttributes( { statsOption: 'site' } );\n\t\t}\n\t}, [ statsData, setAttributes ] );\n\n\tif ( ! isModuleActive && ! isLoadingModules ) {\n\t\treturn (\n\t\t\t<InactiveStatsPlaceholder\n\t\t\t\tclassName={ className }\n\t\t\t\tchangeStatus={ changeStatus }\n\t\t\t\tisLoading={ isChangingStatus }\n\t\t\t/>\n\t\t);\n\t}\n\n\tconst visitorsPlaceholder =\n\t\t/* Translators: Number of visitors */\n\t\t_n( 'visitor', 'visitors', parseInt( stats ), 'jetpack', 0 );\n\n\tconst viewsPlaceholder =\n\t\t/* Translators: Number of views */\n\t\t_n( 'hit', 'hits', parseInt( stats ), 'jetpack', 0 );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls>\n\t\t\t\t<BlogStatsInspectorControls attributes={ attributes } setAttributes={ setAttributes } />\n\t\t\t</InspectorControls>\n\n\t\t\t<div className={ className }>\n\t\t\t\t{ isLoadingModules || blogViews === null ? (\n\t\t\t\t\t<p className=\"jetpack-blog-stats__loading\">{ __( 'Loading stats…', 'jetpack' ) }</p>\n\t\t\t\t) : (\n\t\t\t\t\t<p>\n\t\t\t\t\t\t<span>{ formatNumber( stats ) } </span>\n\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\t\t\tplaceholder={ statsData === 'visitors' ? visitorsPlaceholder : viewsPlaceholder }\n\t\t\t\t\t\t\tvalue={ label }\n\t\t\t\t\t\t\tallowedFormats={ [ 'core/bold', 'core/italic', 'core/link' ] }\n\t\t\t\t\t\t\tonChange={ newLabel => setAttributes( { label: newLabel } ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</p>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default BlogStatsEdit;\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 Render additional fields in the 'Additional information' location. with these attributes: 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-additional-information-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-additional-information-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Additional information\",\n\t\"description\": \"Render additional fields in the 'Additional information' location.\",\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\": 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-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-additional-information-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { FormStepBlock } from '@woocommerce/blocks/checkout/form-step';\nimport clsx from 'clsx';\nimport { ORDER_FORM_KEYS } from '@woocommerce/block-settings';\nimport { useCheckoutAddress } from '@woocommerce/base-context';\nimport { useFormFields } from '@woocommerce/base-components/cart-checkout';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\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} ) => {\n\tconst { defaultFields } = useCheckoutAddress();\n\tconst formFields = useFormFields( ORDER_FORM_KEYS, defaultFields, 'order' );\n\tif (\n\t\tformFields.length === 0 ||\n\t\tformFields.every( ( field ) => !! field.hidden )\n\t) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<FormStepBlock\n\t\t\tsetAttributes={ setAttributes }\n\t\t\tattributes={ attributes }\n\t\t\tclassName={ clsx(\n\t\t\t\t'wc-block-checkout__additional-information-fields',\n\t\t\t\tattributes?.className\n\t\t\t) }\n\t\t>\n\t\t\t<Block />\n\t\t</FormStepBlock>\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 Contains the hidden or revealed content beneath the heading. with these attributes: template lock, open by default, is selected"
},
{
"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-panel/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/accordion-panel\",\n\t\"title\": \"Accordion Panel\",\n\t\"category\": \"design\",\n\t\"description\": \"Contains the hidden or revealed content beneath the heading.\",\n\t\"parent\": [ \"core/accordion-item\" ],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"gradients\": true\n\t\t},\n\t\t\"interactivity\": true,\n\t\t\"spacing\": {\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\"__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\"shadow\": true,\n\t\t\"layout\": {\n\t\t\t\"allowEditing\": false\n\t\t},\n\t\t\"visibility\": false,\n\t\t\"contentRole\": true,\n\t\t\"allowedBlocks\": true,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"templateLock\": {\n\t\t\t\"type\": [ \"string\", \"boolean\" ],\n\t\t\t\"enum\": [ \"all\", \"insert\", \"contentOnly\", false ],\n\t\t\t\"default\": false\n\t\t},\n\t\t\"openByDefault\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isSelected\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"textdomain\": \"default\",\n\t\"style\": \"wp-block-accordion-panel\"\n}\n\n\n// File: packages/block-library/src/accordion-panel/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';\n\nconst { name } = metadata;\n\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/accordion-panel/save.js\n/**\n * WordPress dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport default function save() {\n\tconst blockProps = useBlockProps.save( {\n\t\trole: 'region',\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": "Design a custom WordPress block for product visualization that empowers users to customize image interactions, including zoom-on-hover and expandable full-screen mode."
},
{
"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/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-gallery\",\n\t\"title\": \"Product Gallery (Beta)\",\n\t\"description\": \"Showcase your products relevant images and media.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"interactivity\": true,\n\t\t\"layout\": {\n\t\t\t\"default\": {\n\t\t\t\t\"type\": \"flex\",\n\t\t\t\t\"flexWrap\": \"nowrap\",\n\t\t\t\t\"orientation\": \"horizontal\"\n\t\t\t},\n\t\t\t\"allowOrientation\": true,\n\t\t\t\"allowEditing\": true,\n\t\t\t\"allowJustification\": false\n\t\t},\n\t\t\"email\": true\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"usesContext\": [ \"postId\" ],\n\t\"providesContext\": {\n\t\t\"hoverZoom\": \"hoverZoom\",\n\t\t\"fullScreenOnClick\": \"fullScreenOnClick\"\n\t},\n\t\"ancestor\": [ \"woocommerce/single-product\" ],\n\t\"attributes\": {\n\t\t\"hoverZoom\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"fullScreenOnClick\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"viewScript\": \"wc-product-gallery-frontend\",\n\t\"example\": {},\n\t\"viewScriptModule\": \"woocommerce/product-gallery\",\n\t\"style\": \"file:../woocommerce/product-gallery-style.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tInnerBlocks,\n\tInspectorControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { BlockEditProps, InnerBlockTemplate } from '@wordpress/blocks';\nimport { withProductDataContext } from '@woocommerce/shared-hocs';\n\n/**\n * Internal dependencies\n */\nimport { ProductGalleryBlockSettings } from './block-settings/index';\nimport type { ProductGalleryBlockAttributes } from './types';\n\nconst TEMPLATE: InnerBlockTemplate[] = [\n\t[ 'woocommerce/product-gallery-thumbnails' ],\n\t[\n\t\t'woocommerce/product-gallery-large-image',\n\t\t{},\n\t\t[\n\t\t\t[\n\t\t\t\t'woocommerce/product-image',\n\t\t\t\t{\n\t\t\t\t\tshowProductLink: false,\n\t\t\t\t\tshowSaleBadge: false,\n\t\t\t\t},\n\t\t\t],\n\t\t\t[\n\t\t\t\t'woocommerce/product-sale-badge',\n\t\t\t\t{\n\t\t\t\t\talign: 'right',\n\t\t\t\t},\n\t\t\t],\n\t\t\t[ 'woocommerce/product-gallery-large-image-next-previous' ],\n\t\t],\n\t],\n];\n\nexport const Edit = withProductDataContext(\n\t( {\n\t\tattributes,\n\t\tsetAttributes,\n\t}: BlockEditProps< ProductGalleryBlockAttributes > ) => {\n\t\tconst blockProps = useBlockProps( {\n\t\t\tclassName: 'wc-block-product-gallery',\n\t\t} );\n\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<ProductGalleryBlockSettings\n\t\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t/>\n\t\t\t\t</InspectorControls>\n\t\t\t\t<InnerBlocks\n\t\t\t\t\tallowedBlocks={ [\n\t\t\t\t\t\t'woocommerce/product-gallery-large-image',\n\t\t\t\t\t\t'woocommerce/product-gallery-thumbnails',\n\t\t\t\t\t] }\n\t\t\t\t\ttemplate={ TEMPLATE }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n);\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport const Save = () => {\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: 'wc-block-product-gallery',\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": "Create a woocommerce-product-elements block with customizable heading level, show product link, link target, and 2 more options"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/title/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-title\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Product Title\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"description\": \"Display the title of a product.\",\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": false\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\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalFontFamily\": 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\": false,\n\t\t\t\"gradients\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"__experimentalSelector\": \".wc-block-components-product-title\"\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"attributes\": {\n\t\t\"headingLevel\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 2\n\t\t},\n\t\t\"showProductLink\": {\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\"productId\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"align\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"ancestor\": [ \"woocommerce/all-products\" ]\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/title/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Disabled, PanelBody, ToggleControl } from '@wordpress/components';\nimport {\n\tInspectorControls,\n\tBlockControls,\n\tAlignmentToolbar,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport HeadingToolbar from '@woocommerce/editor-components/heading-toolbar';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport { Attributes } from './types';\nimport './editor.scss';\n\ninterface Props {\n\tattributes: Attributes;\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n}\n\nconst TitleEdit = ( { attributes, setAttributes }: Props ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst { headingLevel, showProductLink, align, linkTarget } = attributes;\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<BlockControls>\n\t\t\t\t<HeadingToolbar\n\t\t\t\t\tisCollapsed={ true }\n\t\t\t\t\tminLevel={ 1 }\n\t\t\t\t\tmaxLevel={ 7 }\n\t\t\t\t\tselectedLevel={ headingLevel }\n\t\t\t\t\tonChange={ ( newLevel: number ) =>\n\t\t\t\t\t\tsetAttributes( { headingLevel: newLevel } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<AlignmentToolbar\n\t\t\t\t\tvalue={ align }\n\t\t\t\t\tonChange={ ( newAlign ) => {\n\t\t\t\t\t\tsetAttributes( { align: newAlign } );\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={ __( 'Link settings', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Make title a link', 'woocommerce' ) }\n\t\t\t\t\t\tchecked={ showProductLink }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowProductLink: ! showProductLink,\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{ showProductLink && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tlabel={ __( 'Open in new tab', 'woocommerce' ) }\n\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tlinkTarget: value ? '_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</>\n\t\t\t\t\t) }\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<Disabled>\n\t\t\t\t<Block { ...attributes } />\n\t\t\t</Disabled>\n\t\t</div>\n\t);\n};\n\nexport default TitleEdit;\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/title/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\ntype Props = {\n\tattributes: Record< string, unknown > & {\n\t\tclassName?: string;\n\t};\n};\n\nexport const Save = ( { attributes }: Props ): JSX.Element => {\n\treturn (\n\t\t<div\n\t\t\t{ ...useBlockProps.save( {\n\t\t\t\tclassName: clsx( 'is-loading', attributes.className ),\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": "Build a Gutenberg block that Show customers a summary of their order. 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-block/block.json\n{\n\t\"name\": \"woocommerce/cart-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\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/cart-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-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 { __ } from '@wordpress/i18n';\nimport { TotalsFooterItem } from '@woocommerce/base-components/cart-checkout';\nimport { getCurrencyFromPriceResponse } from '@woocommerce/price-format';\nimport { useStoreCart } from '@woocommerce/base-context/hooks';\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 allowedBlocks = getAllowedBlocks(\n\t\tinnerBlockAreas.CART_ORDER_SUMMARY\n\t);\n\tconst defaultTemplate = [\n\t\t[\n\t\t\t'woocommerce/cart-order-summary-heading-block',\n\t\t\t{\n\t\t\t\tcontent: __( 'Cart totals', 'woocommerce' ),\n\t\t\t},\n\t\t\t[],\n\t\t],\n\t\t[ 'woocommerce/cart-order-summary-coupon-form-block', {}, [] ],\n\t\t[ 'woocommerce/cart-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<InnerBlocks\n\t\t\t\tallowedBlocks={ allowedBlocks }\n\t\t\t\ttemplate={ defaultTemplate }\n\t\t\t/>\n\t\t\t<div className=\"wc-block-components-totals-wrapper\">\n\t\t\t\t<TotalsFooterItem\n\t\t\t\t\tcurrency={ totalsCurrency }\n\t\t\t\t\tvalues={ cartTotals }\n\t\t\t\t\tisEstimate={ true }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t{ /* do I put an totals wrapper here? */ }\n\t\t\t<OrderMetaSlotFill />\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 Enable customers to filter the product grid by selecting one or more attributes, such as color. with these attributes: attribute id, show counts, query type, 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: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/attribute-filter/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"name\": \"woocommerce/product-filter-attribute\",\n\t\"title\": \"Attribute Filter\",\n\t\"description\": \"Enable customers to filter the product grid by selecting one or more attributes, such as color.\",\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\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"text\": 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\"__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\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": 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\": true,\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\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},\n\t\"usesContext\": [ \"query\", \"filterParams\" ],\n\t\"attributes\": {\n\t\t\"attributeId\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"showCounts\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"queryType\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"or\"\n\t\t},\n\t\t\"displayStyle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"woocommerce/product-filter-checkbox-list\"\n\t\t},\n\t\t\"selectType\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"multiple\"\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\"sortOrder\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"count-desc\"\n\t\t},\n\t\t\"hideEmpty\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\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\"style\": \"woocommerce/product-filter-attribute-view-style\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/attribute-filter/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tuseCollection,\n\tuseCollectionData,\n} from '@woocommerce/base-context/hooks';\nimport {\n\tAttributeSetting,\n\tAttributeTerm,\n\tobjectHasProp,\n} from '@woocommerce/types';\nimport {\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tBlockContextProvider,\n} from '@wordpress/block-editor';\nimport { withSpokenMessages } from '@wordpress/components';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { getSetting } from '@woocommerce/settings';\n\n/**\n * Internal dependencies\n */\nimport { Inspector } from './inspector';\nimport { attributeOptionsPreview } from './constants';\nimport './style.scss';\nimport { EditProps, isAttributeCounts } from './types';\nimport { getAttributeFromId } from './utils';\nimport { getAllowedBlocks } from '../../utils/get-allowed-blocks';\nimport { EXCLUDED_BLOCKS } from '../../constants';\nimport { FilterOptionItem } from '../../types';\nimport { InitialDisabled } from '../../components/initial-disabled';\nimport { Notice } from '../../components/notice';\nimport { sortFilterOptions } from '../../utils/sort-filter-options';\n\nconst ATTRIBUTES = getSetting< AttributeSetting[] >( 'attributes', [] );\n\nconst Edit = ( props: EditProps ) => {\n\tconst { attributes: blockAttributes } = props;\n\n\tconst {\n\t\tattributeId,\n\t\tqueryType,\n\t\tisPreview,\n\t\tdisplayStyle,\n\t\tshowCounts,\n\t\tsortOrder,\n\t\thideEmpty,\n\t} = blockAttributes;\n\n\tconst attributeObject = getAttributeFromId( attributeId );\n\n\tconst [ attributeOptions, setAttributeOptions ] = useState<\n\t\tFilterOptionItem[]\n\t>( [] );\n\tconst [ isOptionsLoading, setIsOptionsLoading ] =\n\t\tuseState< boolean >( true );\n\n\tconst { results: attributeTerms, isLoading: isTermsLoading } =\n\t\tuseCollection< AttributeTerm >( {\n\t\t\tnamespace: '/wc/store/v1',\n\t\t\tresourceName: 'products/attributes/terms',\n\t\t\tresourceValues: [ attributeObject?.id || 0 ],\n\t\t\tshouldSelect: !! attributeObject?.id,\n\t\t\tquery: { orderby: 'menu_order', hide_empty: hideEmpty },\n\t\t} );\n\n\tconst { data: filteredCounts, isLoading: isFilterCountsLoading } =\n\t\tuseCollectionData( {\n\t\t\tqueryAttribute: {\n\t\t\t\ttaxonomy: attributeObject?.taxonomy || '',\n\t\t\t\tqueryType,\n\t\t\t},\n\t\t\tqueryState: {},\n\t\t\tisEditor: true,\n\t\t} );\n\n\tuseEffect( () => {\n\t\tif ( isTermsLoading || isFilterCountsLoading ) return;\n\n\t\tconst termIdHasProducts =\n\t\t\tobjectHasProp( filteredCounts, 'attribute_counts' ) &&\n\t\t\tisAttributeCounts( filteredCounts.attribute_counts )\n\t\t\t\t? filteredCounts.attribute_counts.map( ( term ) => term.term )\n\t\t\t\t: [];\n\n\t\tif ( termIdHasProducts.length === 0 && hideEmpty ) {\n\t\t\tsetAttributeOptions( [] );\n\t\t} else {\n\t\t\tconst filteredOptions = attributeTerms\n\t\t\t\t.filter( ( term ) => {\n\t\t\t\t\tif ( hideEmpty )\n\t\t\t\t\t\treturn termIdHasProducts.includes( term.id );\n\t\t\t\t\treturn true;\n\t\t\t\t} )\n\t\t\t\t.map( ( term, index ) => ( {\n\t\t\t\t\tlabel: term.name,\n\t\t\t\t\tvalue: term.id.toString(),\n\t\t\t\t\tselected: index === 0,\n\t\t\t\t\tcount: term.count,\n\t\t\t\t} ) );\n\n\t\t\tsetAttributeOptions(\n\t\t\t\tsortFilterOptions( filteredOptions, sortOrder )\n\t\t\t);\n\t\t}\n\n\t\tsetIsOptionsLoading( false );\n\t}, [\n\t\tshowCounts,\n\t\tattributeTerms,\n\t\tfilteredCounts,\n\t\tsortOrder,\n\t\thideEmpty,\n\t\tisTermsLoading,\n\t\tisFilterCountsLoading,\n\t\tattributeObject,\n\t] );\n\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[\n\t\t\t\t\t'core/heading',\n\t\t\t\t\t{\n\t\t\t\t\t\tlevel: 3,\n\t\t\t\t\t\tcontent:\n\t\t\t\t\t\t\tattributeObject?.label ||\n\t\t\t\t\t\t\t__( 'Attribute', 'woocommerce' ),\n\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\tspacing: {\n\t\t\t\t\t\t\t\tmargin: {\n\t\t\t\t\t\t\t\t\tbottom: '0.625rem',\n\t\t\t\t\t\t\t\t\ttop: '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},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\t[ displayStyle ],\n\t\t\t],\n\t\t}\n\t);\n\n\tconst isLoading =\n\t\tisTermsLoading || isFilterCountsLoading || isOptionsLoading;\n\n\tif ( Object.keys( ATTRIBUTES ).length === 0 )\n\t\treturn (\n\t\t\t<div { ...innerBlocksProps }>\n\t\t\t\t<Inspector { ...props } />\n\t\t\t\t<Notice>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\"Attributes are needed for filtering your products. You haven't created any attributes yet.\",\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t</Notice>\n\t\t\t</div>\n\t\t);\n\n\tif ( ! attributeId || ! attributeObject )\n\t\treturn (\n\t\t\t<div { ...innerBlocksProps }>\n\t\t\t\t<Inspector { ...props } />\n\t\t\t\t<Notice>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Please select an attribute to use this filter!',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t</Notice>\n\t\t\t</div>\n\t\t);\n\n\tif ( ! isLoading && attributeTerms.length === 0 )\n\t\treturn (\n\t\t\t<div { ...innerBlocksProps }>\n\t\t\t\t<Inspector { ...props } />\n\t\t\t\t<Notice>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'There are no products with the selected attributes.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t</Notice>\n\t\t\t</div>\n\t\t);\n\n\treturn (\n\t\t<div { ...innerBlocksProps }>\n\t\t\t<Inspector { ...props } />\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:\n\t\t\t\t\t\t\t\tattributeOptions.length === 0 && isPreview\n\t\t\t\t\t\t\t\t\t? attributeOptionsPreview\n\t\t\t\t\t\t\t\t\t: attributeOptions,\n\t\t\t\t\t\t\tisLoading,\n\t\t\t\t\t\t\tshowCounts,\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 withSpokenMessages( Edit );\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/attribute-filter/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": "Design a flexible theme block in WordPress that allows adjustable text properties, including type, alignment, level, plus three extra user-defined 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/query-title/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/query-title\",\n\t\"title\": \"Query Title\",\n\t\"category\": \"theme\",\n\t\"description\": \"Display the query title.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"type\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"level\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 1\n\t\t},\n\t\t\"levelOptions\": {\n\t\t\t\"type\": \"array\"\n\t\t},\n\t\t\"showPrefix\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showSearchTerm\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"type\": \"search\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"query\" ],\n\t\"supports\": {\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\"__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\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": 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-query-title\"\n}\n\n\n// File: packages/block-library/src/query-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 variations from './variations';\nimport deprecated from './deprecated';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tvariations,\n\tdeprecated,\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 Display your most popular content. with these attributes: layout, display author, display date, and 5 more options"
},
{
"role": "assistant",
"content": "// File: projects/plugins/jetpack/extensions/blocks/top-posts/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/top-posts\",\n\t\"title\": \"Top Posts & Pages\",\n\t\"description\": \"Display your most popular content.\",\n\t\"keywords\": [ \"ranking\", \"views\", \"trending\", \"popular\" ],\n\t\"version\": \"1.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"embed\",\n\t\"icon\": \"<svg xmlns='http://www.w3.org/2000/svg' height='24px' viewBox='0 0 24 24' width='24px'><rect fill='none' height='24' width='24'/><path d='M19,5h-2V3H7v2H5C3.9,5,3,5.9,3,7v1c0,2.55,1.92,4.63,4.39,4.94c0.63,1.5,1.98,2.63,3.61,2.96V19H7v2h10v-2h-4v-3.1 c1.63-0.33,2.98-1.46,3.61-2.96C19.08,12.63,21,10.55,21,8V7C21,5.9,20.1,5,19,5z M5,8V7h2v3.82C5.84,10.4,5,9.3,5,8z M19,8 c0,1.3-0.84,2.4-2,2.82V7h2V8z'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"multiple\": true,\n\t\t\"reusable\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": 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\"__experimentalFontFamily\": true,\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"layout\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"grid\"\n\t\t},\n\t\t\"displayAuthor\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"displayDate\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"displayThumbnail\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"displayContext\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"period\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"7\"\n\t\t},\n\t\t\"postsToShow\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t},\n\t\t\"postTypes\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"post\": true,\n\t\t\t\t\"page\": true\n\t\t\t}\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/top-posts/edit.js\nimport { useModuleStatus } from '@automattic/jetpack-shared-extension-utils';\nimport apiFetch from '@wordpress/api-fetch';\nimport { BlockControls, InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { useState, useEffect } from '@wordpress/element';\nimport clsx from 'clsx';\nimport { LoadingPostsGrid } from '../../shared/components/loading-posts-grid';\nimport { TopPostsBlockControls, TopPostsInspectorControls } from './controls';\nimport { InactiveStatsPlaceholder } from './inactive-placeholder';\nimport './style.scss';\nimport './editor.scss';\n\nfunction TopPostsPreviewItem( props ) {\n\treturn (\n\t\t<div className=\"jetpack-top-posts-item\">\n\t\t\t{ props.displayThumbnail && props.thumbnail && (\n\t\t\t\t<a className=\"jetpack-top-posts-thumbnail-link\">\n\t\t\t\t\t<img\n\t\t\t\t\t\tclassName=\"jetpack-top-posts-thumbnail\"\n\t\t\t\t\t\tsrc={ props.thumbnail }\n\t\t\t\t\t\talt={ props.title }\n\t\t\t\t\t\trel=\"nofollow noopener noreferrer\"\n\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t/>\n\t\t\t\t</a>\n\t\t\t) }\n\t\t\t{ props.displayThumbnail && ! props.thumbnail && (\n\t\t\t\t<a className=\"jetpack-top-posts-thumbnail-link\">\n\t\t\t\t\t<div className=\"jetpack-top-posts-mock-thumbnail\"></div>\n\t\t\t\t</a>\n\t\t\t) }\n\t\t\t<span className=\"jetpack-top-posts-title\">\n\t\t\t\t<a>{ props.title }</a>\n\t\t\t</span>\n\t\t\t{ props.displayDate && (\n\t\t\t\t<span className=\"jetpack-top-posts-date has-small-font-size\">{ props.date }</span>\n\t\t\t) }\n\t\t\t{ props.displayAuthor && (\n\t\t\t\t<span className=\"jetpack-top-posts-author has-small-font-size\">{ props.author }</span>\n\t\t\t) }\n\t\t\t{ props.displayContext && props.context && (\n\t\t\t\t<span className=\"jetpack-top-posts-context has-small-font-size\">\n\t\t\t\t\t<a>{ props.context[ 0 ].cat_name }</a>\n\t\t\t\t</span>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nfunction TopPostsEdit( { attributes, setAttributes } ) {\n\tconst { isLoadingModules, isChangingStatus, isModuleActive, changeStatus } =\n\t\tuseModuleStatus( 'stats' );\n\tconst blockProps = useBlockProps();\n\tconst { className } = blockProps;\n\n\tconst [ postsData, setPostsData ] = useState();\n\tconst [ postsToDisplay, setPostsToDisplay ] = useState();\n\tconst [ postTypesData, setPostTypesData ] = useState();\n\tconst [ toggleAttributes, setToggleAttributes ] = useState( {} );\n\n\tconst {\n\t\tdisplayAuthor,\n\t\tdisplayContext,\n\t\tdisplayDate,\n\t\tdisplayThumbnail,\n\t\tlayout,\n\t\tperiod,\n\t\tpostsToShow,\n\t\tpostTypes,\n\t} = attributes;\n\n\tuseEffect( () => {\n\t\tapiFetch( { path: `/wpcom/v2/post-types` } ).then( response => {\n\t\t\tsetPostTypesData( response );\n\t\t\tresponse.forEach( type => {\n\t\t\t\tif ( postTypes && postTypes[ type.id ] ) {\n\t\t\t\t\tsetToggleAttributes( prevToggleAttributes => ( {\n\t\t\t\t\t\t...prevToggleAttributes,\n\t\t\t\t\t\t[ type.id ]: true,\n\t\t\t\t\t} ) );\n\t\t\t\t}\n\t\t\t} );\n\t\t} );\n\t}, [ postTypes ] );\n\n\tuseEffect( () => {\n\t\tif ( isModuleActive ) {\n\t\t\tapiFetch( {\n\t\t\t\tpath: `/wpcom/v2/top-posts?period=${ period }`,\n\t\t\t} ).then( response => {\n\t\t\t\tsetPostsData( response );\n\t\t\t} );\n\t\t}\n\t}, [ period, isModuleActive ] );\n\n\tuseEffect( () => {\n\t\tconst data = postsData;\n\n\t\tif ( ! data ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newPosts = [];\n\t\tfor ( let i = 0; newPosts.length !== postsToShow; i++ ) {\n\t\t\tif ( data[ i ] && postTypes[ data[ i ].type ] ) {\n\t\t\t\tnewPosts.push(\n\t\t\t\t\t<TopPostsPreviewItem\n\t\t\t\t\t\tkey={ 'jetpack-top-posts-' + data[ i ].id }\n\t\t\t\t\t\ttitle={ data[ i ].title }\n\t\t\t\t\t\tdate={ data[ i ].date }\n\t\t\t\t\t\tauthor={ data[ i ].author }\n\t\t\t\t\t\tthumbnail={ data[ i ].thumbnail }\n\t\t\t\t\t\tcontext={ data[ i ].context }\n\t\t\t\t\t\tdisplayDate={ displayDate }\n\t\t\t\t\t\tdisplayAuthor={ displayAuthor }\n\t\t\t\t\t\tdisplayThumbnail={ displayThumbnail }\n\t\t\t\t\t\tdisplayContext={ displayContext }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Out of posts.\n\t\t\tif ( ! data[ i ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tsetPostsToDisplay( newPosts );\n\t}, [\n\t\tdisplayAuthor,\n\t\tdisplayContext,\n\t\tdisplayDate,\n\t\tdisplayThumbnail,\n\t\tpostsData,\n\t\tpostTypes,\n\t\tpostsToShow,\n\t\tsetPostsToDisplay,\n\t] );\n\n\tlet content;\n\n\tif ( ! isModuleActive && ! isLoadingModules ) {\n\t\tcontent = (\n\t\t\t<InactiveStatsPlaceholder\n\t\t\t\tclassName={ className }\n\t\t\t\tchangeStatus={ changeStatus }\n\t\t\t\tisLoading={ isChangingStatus }\n\t\t\t/>\n\t\t);\n\t} else if ( ! postsToDisplay ) {\n\t\tcontent = <LoadingPostsGrid />;\n\t} else {\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<TopPostsInspectorControls\n\t\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\ttoggleAttributes={ toggleAttributes }\n\t\t\t\t\t\tsetToggleAttributes={ setToggleAttributes }\n\t\t\t\t\t\tpostTypesData={ postTypesData }\n\t\t\t\t\t/>\n\t\t\t\t</InspectorControls>\n\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<TopPostsBlockControls attributes={ attributes } setAttributes={ setAttributes } />\n\t\t\t\t</BlockControls>\n\n\t\t\t\t<div data-item-count={ postsToDisplay.length }>\n\t\t\t\t\t<div className=\"jetpack-top-posts-wrapper\">{ postsToDisplay }</div>\n\t\t\t\t</div>\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div { ...blockProps } className={ clsx( className, `is-${ layout }-layout` ) }>\n\t\t\t{ content }\n\t\t</div>\n\t);\n}\n\nexport default TopPostsEdit;\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 custom WordPress block to implement a clickable page number sequence that enables users to browse through product review sections efficiently."
},
{
"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-numbers/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-reviews-pagination-numbers\",\n\t\"title\": \"Reviews Page Numbers\",\n\t\"category\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/product-reviews-pagination\" ],\n\t\"description\": \"Displays a list of page numbers for product reviews pagination.\",\n\t\"textdomain\": \"woocommerce\",\n\t\"usesContext\": [ \"postId\" ],\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-numbers/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport type { ElementType } from 'react';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\n\nconst PaginationItem = ( {\n\tcontent,\n\ttag: Tag = 'a',\n\textraClass = '',\n}: {\n\tcontent: string;\n\ttag?: ElementType;\n\textraClass?: string;\n} ) =>\n\tTag === 'a' ? (\n\t\t<Tag\n\t\t\tclassName={ `page-numbers ${ extraClass }` }\n\t\t\thref=\"#comments-pagination-numbers-pseudo-link\"\n\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t>\n\t\t\t{ content }\n\t\t</Tag>\n\t) : (\n\t\t<Tag className={ `page-numbers ${ extraClass }` }>{ content }</Tag>\n\t);\n\nexport default function Edit() {\n\treturn (\n\t\t<div { ...useBlockProps() }>\n\t\t\t<PaginationItem content=\"1\" />\n\t\t\t<PaginationItem content=\"2\" />\n\t\t\t<PaginationItem content=\"3\" tag=\"span\" extraClass=\"current\" />\n\t\t\t<PaginationItem content=\"4\" />\n\t\t\t<PaginationItem content=\"5\" />\n\t\t\t<PaginationItem content=\"...\" tag=\"span\" extraClass=\"dots\" />\n\t\t\t<PaginationItem content=\"8\" />\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 Embed a Google Document. that allows users to configure: url, aspect ratio, 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: projects/plugins/jetpack/extensions/blocks/google-docs-embed/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/google-docs-embed\",\n\t\"title\": \"Google Docs (Beta)\",\n\t\"description\": \"Embed a Google Document.\",\n\t\"keywords\": [ \"document\", \"gsuite\", \"doc\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"embed\",\n\t\"icon\": \"<svg viewBox='0 0 64 88' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M58,88H6c-3.3,0-6-2.7-6-6V6c0-3.3,2.7-6,6-6h36l22,22v60C64,85.3,61.3,88,58,88z' /><path fill='#FDFFFF' d='M42,0l22,22H42V0z' /><path fill='#FDFFFF' d='M50,39H14v-5h36V39z M50,46H14v5h36V46z M40,58H14v5h26V58z' /></svg>\",\n\t\"supports\": {\n\t\t\"align\": [ \"left\", \"right\", \"center\", \"wide\", \"full\" ],\n\t\t\"anchor\": true\n\t},\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"aspectRatio\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"variation\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/google-docs-embed/edit.js\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { PanelBody, SelectControl } from '@wordpress/components';\nimport { Fragment, useEffect } from '@wordpress/element';\nimport { __, _x } from '@wordpress/i18n';\nimport Embed from './embed';\nimport variations from './variations';\n\nconst docsVariation = variations?.find( v => v.name === 'jetpack/google-docs' );\nconst sheetsVariation = variations?.find( v => v.name === 'jetpack/google-sheets' );\nconst slidesVariation = variations?.find( v => v.name === 'jetpack/google-slides' );\n\nconst GOOGLE_DOCUMENT = {\n\ttype: 'document',\n\ttitle: docsVariation?.title,\n\ticon: docsVariation.icon,\n\tpatterns: [ /^(http|https):\\/\\/(docs\\.google.com)\\/document\\/d\\/([A-Za-z0-9_-]+).*?$/i ],\n};\n\nconst GOOGLE_SPREADSHEET = {\n\ttype: 'spreadsheets',\n\ttitle: sheetsVariation?.title,\n\ticon: sheetsVariation.icon,\n\tpatterns: [ /^(http|https):\\/\\/(docs\\.google.com)\\/spreadsheets\\/d\\/([A-Za-z0-9_-]+).*?$/i ],\n};\n\nconst GOOGLE_SLIDE = {\n\ttype: 'presentation',\n\ttitle: slidesVariation?.title,\n\ticon: slidesVariation.icon,\n\tpatterns: [ /^(http|https):\\/\\/(docs\\.google.com)\\/presentation\\/d\\/([A-Za-z0-9_-]+).*?$/i ],\n};\n\n/**\n * Edit component.\n * See https://wordpress.org/gutenberg/handbook/designers-developers/developers/block-api/block-edit-save/#edit\n *\n * @param {object} props - The block props.\n * @param {object} props.attributes - Block attributes.\n * @param {string} props.attributes.title - Custom title to be displayed.\n * @param {string} props.className - Class name for the block.\n * @param {Function} props.setAttributes - Sets the value for block attributes.\n * @return {Function} Render the edit screen\n */\nconst GsuiteBlockEdit = props => {\n\tconst {\n\t\tattributes: { aspectRatio },\n\t\tattributes: { variation },\n\t\tattributes: { url },\n\t\tsetAttributes,\n\t} = props;\n\n\tlet icon = '';\n\tlet title = '';\n\tlet patterns = [];\n\tlet type = '';\n\n\tuseEffect( () => {\n\t\t/**\n\t\t * Parse the URL to detect the variation type.\n\t\t *\n\t\t * @return {string} The variation.\n\t\t */\n\t\tconst detectVariation = () => {\n\t\t\tconst regex = /^(http|https):\\/\\/(docs\\.google\\.com)\\/(.*)\\/d\\//;\n\t\t\tconst matches = url.match( regex );\n\n\t\t\tswitch ( matches[ 3 ] ) {\n\t\t\t\tcase 'document':\n\t\t\t\t\treturn 'google-docs';\n\n\t\t\t\tcase 'spreadsheets':\n\t\t\t\t\treturn 'google-sheets';\n\n\t\t\t\tcase 'presentation':\n\t\t\t\t\treturn 'google-slides';\n\t\t\t}\n\n\t\t\treturn '';\n\t\t};\n\n\t\tif ( ! variation ) {\n\t\t\tsetAttributes( { variation: detectVariation() } );\n\t\t}\n\t}, [ variation, url, setAttributes ] );\n\n\tswitch ( variation.replace( 'jetpack/', '' ) ) {\n\t\tcase 'google-docs':\n\t\t\ticon = GOOGLE_DOCUMENT.icon;\n\t\t\ttitle = GOOGLE_DOCUMENT.title;\n\t\t\tpatterns = GOOGLE_DOCUMENT.patterns;\n\t\t\ttype = GOOGLE_DOCUMENT.type;\n\t\t\tbreak;\n\n\t\tcase 'google-sheets':\n\t\t\ticon = GOOGLE_SPREADSHEET.icon;\n\t\t\ttitle = GOOGLE_SPREADSHEET.title;\n\t\t\tpatterns = GOOGLE_SPREADSHEET.patterns;\n\t\t\ttype = GOOGLE_SPREADSHEET.type;\n\t\t\tbreak;\n\n\t\tcase 'google-slides':\n\t\t\ticon = GOOGLE_SLIDE.icon;\n\t\t\ttitle = GOOGLE_SLIDE.title;\n\t\t\tpatterns = GOOGLE_SLIDE.patterns;\n\t\t\ttype = GOOGLE_SLIDE.type;\n\t\t\tbreak;\n\t}\n\n\t/**\n\t * Convert GSuite URL to a preview URL.\n\t *\n\t * @return {string} The URL pattern.\n\t */\n\tconst mapGSuiteURL = () => {\n\t\t/**\n\t\t * If the block is not the expected one, return the\n\t\t * original URL as is.\n\t\t */\n\t\tif ( patterns.length === 0 || '' === type ) {\n\t\t\treturn url;\n\t\t}\n\n\t\t/**\n\t\t * Check if the URL is valid.\n\t\t *\n\t\t * If not, return the original URL as is.\n\t\t */\n\t\tconst matches = url.match( patterns[ 0 ] );\n\t\tif (\n\t\t\tnull === matches ||\n\t\t\t'undefined' === typeof matches[ 1 ] ||\n\t\t\t'undefined' === typeof matches[ 2 ] ||\n\t\t\t'undefined' === typeof matches[ 3 ]\n\t\t) {\n\t\t\treturn url;\n\t\t}\n\n\t\treturn `${ matches[ 1 ] }://${ matches[ 2 ] }/${ type }/d/${ matches[ 3 ] }/preview`;\n\t};\n\n\tconst aspectRatios = [\n\t\t// translators: default aspect ratio for the embedded Google document.\n\t\t{ label: __( 'Default', 'jetpack' ), value: '' },\n\t\t// translators: aspect ratio for the embedded Google document.\n\t\t{ label: __( '100% - Show the whole document', 'jetpack' ), value: 'ar-100' },\n\t\t// translators: aspect ratio for the embedded Google document.\n\t\t{ label: __( '50% - Show half of the document', 'jetpack' ), value: 'ar-50' },\n\t];\n\n\treturn (\n\t\t<>\n\t\t\t<Fragment>\n\t\t\t\t<Embed\n\t\t\t\t\ticon={ icon.src }\n\t\t\t\t\tinstructions={ [\n\t\t\t\t\t\t__( 'Copy and paste your document link below.', 'jetpack' ),\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'If your document is private, only readers logged into a Google account with shared access to the document may view it.',\n\t\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t\t),\n\t\t\t\t\t].join( ' ' ) }\n\t\t\t\t\tlabel={ title }\n\t\t\t\t\tpatterns={ patterns }\n\t\t\t\t\tplaceholder={ _x( 'Enter the link here…', 'Embed block placeholder', 'jetpack' ) }\n\t\t\t\t\tmapUrl={ mapGSuiteURL }\n\t\t\t\t\tmismatchErrorMessage={ __(\n\t\t\t\t\t\t'The document couldn’t be embedded. To embed a document, use the link in your browser address bar when editing the document.',\n\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t) }\n\t\t\t\t\tcheckGoogleDocVisibility={ true }\n\t\t\t\t\t{ ...props }\n\t\t\t\t/>\n\t\t\t</Fragment>\n\t\t\t<Fragment>\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<PanelBody>\n\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Select a different aspect-ratio to show more (or less) of your embedded document.',\n\t\t\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t<SelectControl\n\t\t\t\t\t\t\tlabel={ __( 'Aspect Ratio', 'jetpack' ) }\n\t\t\t\t\t\t\tvalue={ aspectRatio }\n\t\t\t\t\t\t\toptions={ aspectRatios }\n\t\t\t\t\t\t\tonChange={ value => setAttributes( { aspectRatio: value } ) }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t</InspectorControls>\n\t\t\t</Fragment>\n\t\t</>\n\t);\n};\nexport default GsuiteBlockEdit;\n\n\n// File: projects/plugins/jetpack/extensions/blocks/google-docs-embed/save.js\nconst Save = props => {\n\tconst { attributes } = props;\n\n\treturn (\n\t\t<figure>\n\t\t\t<div className=\"embed__wrapper\">\n\t\t\t\t{ `\\n${ attributes.url }\\n` /* URL on its own line as in core embeds. */ }\n\t\t\t</div>\n\t\t</figure>\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": "Create a woocommerce-product-elements block with customizable product id, text align, width, 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/atomic/blocks/product-elements/button/block.json\n{\n\t\"name\": \"woocommerce/product-button\",\n\t\"title\": \"Add to Cart Button\",\n\t\"description\": \"Display a call to action button which either adds the product to the cart, or links to the product page.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"usesContext\": [\n\t\t\"query\",\n\t\t\"queryId\",\n\t\t\"postId\",\n\t\t\"collection\",\n\t\t\"woocommerce/isDescendantOfAddToCartWithOptions\"\n\t],\n\t\"textdomain\": \"woocommerce\",\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\"textAlign\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"width\": {\n\t\t\t\"type\": \"number\"\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\"isDescendentOfQueryLoop\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\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\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"interactivity\": true,\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\"__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\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\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"email\": true,\n\t\t\"__experimentalSelector\": \".wp-block-button.wc-block-components-product-button .wc-block-components-product-button__button\"\n\t},\n\t\"ancestor\": [\n\t\t\"woocommerce/all-products\",\n\t\t\"woocommerce/single-product\",\n\t\t\"core/post-template\",\n\t\t\"woocommerce/product-template\"\n\t],\n\t\"styles\": [\n\t\t{\n\t\t\t\"name\": \"fill\",\n\t\t\t\"label\": \"Fill\",\n\t\t\t\"isDefault\": true\n\t\t},\n\t\t{\n\t\t\t\"name\": \"outline\",\n\t\t\t\"label\": \"Outline\"\n\t\t}\n\t],\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"viewScriptModule\": \"woocommerce/product-button\",\n\t\"style\": \"file:../woocommerce/product-button-style.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport {\n\tDisabled,\n\tButton,\n\tButtonGroup,\n\tPanelBody,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tAlignmentToolbar,\n\tBlockControls,\n\tuseBlockProps,\n\tInspectorControls,\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';\nimport { useProduct } from '@woocommerce/entities';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport { BlockAttributes } from './types';\n\nfunction WidthPanel( {\n\tselectedWidth,\n\tsetAttributes,\n}: {\n\tselectedWidth: number | undefined;\n\tsetAttributes: ( attributes: BlockAttributes ) => void;\n} ) {\n\tfunction handleChange( newWidth: number ) {\n\t\t// Check if we are toggling the width off\n\t\tconst width = selectedWidth === newWidth ? undefined : newWidth;\n\n\t\t// Update attributes.\n\t\tsetAttributes( { width } );\n\t}\n\n\treturn (\n\t\t<PanelBody title={ __( 'Width settings', 'woocommerce' ) }>\n\t\t\t<ButtonGroup aria-label={ __( 'Button width', 'woocommerce' ) }>\n\t\t\t\t{ [ 25, 50, 75, 100 ].map( ( widthValue ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tkey={ widthValue }\n\t\t\t\t\t\t\tisSmall\n\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\twidthValue === selectedWidth\n\t\t\t\t\t\t\t\t\t? 'primary'\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonClick={ () => handleChange( widthValue ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ widthValue }%\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</ButtonGroup>\n\t\t</PanelBody>\n\t);\n}\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n\tcontext,\n}: BlockEditProps< BlockAttributes > & {\n\tcontext?: Context | undefined;\n} ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst { product } = useProduct( context?.postId );\n\tconst isDescendentOfQueryLoop = Number.isFinite( context?.queryId );\n\tconst { width } = attributes;\n\n\tuseEffect(\n\t\t() => setAttributes( { isDescendentOfQueryLoop } ),\n\t\t[ setAttributes, isDescendentOfQueryLoop ]\n\t);\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<InspectorControls>\n\t\t\t\t<WidthPanel\n\t\t\t\t\tselectedWidth={ width }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Disabled>\n\t\t\t\t\t<Block\n\t\t\t\t\t\t{ ...{ ...attributes, ...context } }\n\t\t\t\t\t\tproduct={ {\n\t\t\t\t\t\t\t...product,\n\t\t\t\t\t\t\tbutton_text: product?.button_text || '',\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisAdmin={ true }\n\t\t\t\t\t\tblockClientId={ blockProps?.id }\n\t\t\t\t\t\tclassName={ clsx( attributes.className, {\n\t\t\t\t\t\t\t[ `has-custom-width wp-block-button__width-${ width }` ]:\n\t\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t/>\n\t\t\t\t</Disabled>\n\t\t\t</div>\n\t\t</>\n\t);\n};\n\nexport default Edit;\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport { BlockAttributes } from './types';\n\ntype Props = {\n\tattributes: BlockAttributes;\n};\n\nconst Save = ( { attributes, innerBlocks }: Props ): JSX.Element | null => {\n\tif (\n\t\tattributes.isDescendentOfQueryLoop ||\n\t\tattributes.isDescendentOfSingleProductBlock ||\n\t\t! innerBlocks ||\n\t\tinnerBlocks?.length === 0\n\t) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div\n\t\t\t{ ...useBlockProps.save( {\n\t\t\t\tclassName: clsx( 'is-loading', attributes.className, {\n\t\t\t\t\t[ `has-custom-width wp-block-button__width-${ attributes.width }` ]:\n\t\t\t\t\t\tattributes.width,\n\t\t\t\t} ),\n\t\t\t} ) }\n\t\t/>\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": "Implement a Gutenberg block for Displays a list of page numbers for comments pagination."
},
{
"role": "assistant",
"content": "// File: packages/block-library/src/comments-pagination-numbers/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/comments-pagination-numbers\",\n\t\"title\": \"Comments Page Numbers\",\n\t\"category\": \"theme\",\n\t\"parent\": [ \"core/comments-pagination\" ],\n\t\"description\": \"Displays a list of page numbers for comments pagination.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"postId\" ],\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\t\"spacing\": {\n\t\t\t\"margin\": true,\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}\n\t}\n}\n\n\n// File: packages/block-library/src/comments-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 WordPress block specifically for displaying cart tax details, enabling customization of class names and lock settings for enhanced flexibility."
},
{
"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-taxes/block.json\n{\n\t\"name\": \"woocommerce/checkout-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/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-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 woocommerce block with customizable lock"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-billing-address-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-billing-address-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Billing Address\",\n\t\"description\": \"Collect your customer's billing address.\",\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-billing-address-block/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { useCheckoutAddress } from '@woocommerce/base-context/hooks';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport type { BlockAttributes } from '@wordpress/blocks';\n/**\n * Internal dependencies\n */\nimport {\n\tFormStepBlock,\n\tAdditionalFields,\n\tAdditionalFieldsContent,\n} from '../../form-step';\nimport Block from './block';\nimport {\n\tgetBillingAddresssBlockTitle,\n\tgetBillingAddresssBlockDescription,\n} from './utils';\nimport { AddressFieldControls } from '../../address-field-controls';\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: BlockAttributes ) => void;\n} ): JSX.Element | null => {\n\tconst { showBillingFields, forcedBillingAddress, useBillingAsShipping } =\n\t\tuseCheckoutAddress();\n\n\tif ( ! showBillingFields && ! useBillingAsShipping ) {\n\t\treturn null;\n\t}\n\tattributes.title = getBillingAddresssBlockTitle(\n\t\tattributes.title,\n\t\tforcedBillingAddress\n\t);\n\tattributes.description = getBillingAddresssBlockDescription(\n\t\tattributes.description,\n\t\tforcedBillingAddress\n\t);\n\n\treturn (\n\t\t<FormStepBlock\n\t\t\tsetAttributes={ setAttributes }\n\t\t\tattributes={ attributes }\n\t\t\tclassName={ clsx(\n\t\t\t\t'wc-block-checkout__billing-fields',\n\t\t\t\tattributes?.className\n\t\t\t) }\n\t\t>\n\t\t\t<AddressFieldControls />\n\t\t\t<Block />\n\t\t\t<AdditionalFields block={ innerBlockAreas.BILLING_ADDRESS } />\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": "Build a Gutenberg block that Column containing the checkout totals. with these attributes: class name, checkbox, text"
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-totals-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-totals-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Checkout Totals\",\n\t\"description\": \"Column containing the checkout 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\"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},\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-totals-block/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\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 './style.scss';\nimport {\n\tuseForcedLayout,\n\tgetAllowedBlocks,\n} from '../../../cart-checkout-shared';\n\nexport const Edit = ( {\n\tclientId,\n\tattributes,\n}: {\n\tclientId: string;\n\tattributes: {\n\t\tclassName?: string;\n\t};\n} ): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( 'wc-block-checkout__sidebar', attributes?.className ),\n\t} );\n\tconst allowedBlocks = getAllowedBlocks( innerBlockAreas.CHECKOUT_TOTALS );\n\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/checkout-order-summary-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\ttemplateLock={ false }\n\t\t\t\ttemplate={ defaultTemplate }\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": "Construct a WordPress block for widgets that allows extensive personalization through an adjustable label, display option, placeholder field, and a total of seven configurable 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: packages/block-library/src/search/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/search\",\n\t\"title\": \"Search\",\n\t\"category\": \"widgets\",\n\t\"description\": \"Help visitors find your content.\",\n\t\"keywords\": [ \"find\" ],\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\"showLabel\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"placeholder\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"width\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"widthUnit\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"buttonText\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"buttonPosition\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"button-outside\"\n\t\t},\n\t\t\"buttonUseIcon\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"query\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {}\n\t\t},\n\t\t\"isSearchFieldHidden\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"left\", \"center\", \"right\" ],\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"__experimentalSkipSerialization\": 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\"interactivity\": true,\n\t\t\"typography\": {\n\t\t\t\"__experimentalSkipSerialization\": true,\n\t\t\t\"__experimentalSelector\": \".wp-block-search__label, .wp-block-search__input, .wp-block-search__button\",\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\"__experimentalSkipSerialization\": 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},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"html\": false\n\t},\n\t\"editorStyle\": \"wp-block-search-editor\",\n\t\"style\": \"wp-block-search\"\n}\n\n\n// File: packages/block-library/src/search/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { search 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 metadata from './block.json';\nimport edit from './edit';\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: { buttonText: __( 'Search' ), label: __( 'Search' ) },\n\t\tviewportWidth: 400,\n\t},\n\tvariations,\n\tedit,\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\tshownByDefault: true,\n\t\t},\n\t\t{\n\t\t\tid: 'buttonText',\n\t\t\tlabel: __( 'Button text' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t\t{\n\t\t\tid: 'placeholder',\n\t\t\tlabel: __( 'Placeholder' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'label' ],\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 new Gutenberg block component designed to function as a standalone list element, equipped with configurable placeholder and content properties."
},
{
"role": "assistant",
"content": "// 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": "Build a Gutenberg block that Let shoppers filter products by choosing stock status. with these attributes: show counts, display style, is preview, hide empty"
},
{
"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/status-filter/block.json\n{\n\t\"name\": \"woocommerce/product-filter-status\",\n\t\"title\": \"Status Filter\",\n\t\"description\": \"Let shoppers filter products by choosing stock status.\",\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\"html\": false,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"text\": 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\"__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\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": 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\": true,\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\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},\n\t\"attributes\": {\n\t\t\"showCounts\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"displayStyle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"woocommerce/product-filter-checkbox-list\"\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\"hideEmpty\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"usesContext\": [ \"query\", \"filterParams\" ],\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"isPreview\": true\n\t\t}\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/status-filter/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tuseBlockProps,\n\tBlockContextProvider,\n\tuseInnerBlocksProps,\n} from '@wordpress/block-editor';\nimport { useCollectionData } from '@woocommerce/base-context/hooks';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { getSetting } from '@woocommerce/settings';\n\n/**\n * Internal dependencies\n */\nimport { InitialDisabled } from '../../components/initial-disabled';\nimport { Inspector } from './inspector';\nimport type { EditProps } from './types';\n\nconst Edit = ( props: EditProps ) => {\n\tconst { showCounts, hideEmpty } = props.attributes;\n\tconst { children, ...innerBlocksProps } = useInnerBlocksProps(\n\t\tuseBlockProps(),\n\t\t{\n\t\t\ttemplate: [\n\t\t\t\t[\n\t\t\t\t\t'core/heading',\n\t\t\t\t\t{\n\t\t\t\t\t\tlevel: 3,\n\t\t\t\t\t\tcontent: __( 'Status', 'woocommerce' ),\n\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\tspacing: {\n\t\t\t\t\t\t\t\tmargin: {\n\t\t\t\t\t\t\t\t\tbottom: '0.625rem',\n\t\t\t\t\t\t\t\t\ttop: '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},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\t[ 'woocommerce/product-filter-checkbox-list' ],\n\t\t\t],\n\t\t}\n\t);\n\n\tconst stockStatusOptions: Record< string, string > = getSetting(\n\t\t'stockStatusOptions',\n\t\t{}\n\t);\n\n\tconst { data: filteredCounts, isLoading } = useCollectionData( {\n\t\tqueryStock: true,\n\t\tqueryState: {},\n\t\tisEditor: true,\n\t} );\n\n\tconst items = useMemo( () => {\n\t\treturn Object.entries( stockStatusOptions )\n\t\t\t.map( ( [ key, value ], index ) => {\n\t\t\t\tconst count =\n\t\t\t\t\tfilteredCounts?.stock_status_counts?.find(\n\t\t\t\t\t\t( item ) => item.status === key\n\t\t\t\t\t)?.count ?? 0;\n\n\t\t\t\treturn {\n\t\t\t\t\tlabel: value,\n\t\t\t\t\tariaLabel: value,\n\t\t\t\t\tvalue: key,\n\t\t\t\t\tselected: index === 0,\n\t\t\t\t\tcount,\n\t\t\t\t\ttype: 'status',\n\t\t\t\t};\n\t\t\t} )\n\t\t\t.filter( ( item ) => ! hideEmpty || item.count > 0 );\n\t}, [ stockStatusOptions, filteredCounts, hideEmpty ] );\n\n\treturn (\n\t\t<div { ...innerBlocksProps }>\n\t\t\t<Inspector { ...props } />\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,\n\t\t\t\t\t\t\tisLoading,\n\t\t\t\t\t\t\tshowCounts,\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/status-filter/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": "Construct a dedicated WooCommerce block that renders cart taxes with configurable options for class attributes and locking mechanisms to improve user experience."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-taxes/block.json\n{\n\t\"name\": \"woocommerce/checkout-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/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-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": "Craft a versatile Gutenberg block for rating various items, incorporating rating value, maximum rating, color selection, and three 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: projects/plugins/jetpack/extensions/blocks/rating-star/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/rating-star\",\n\t\"title\": \"Star Rating\",\n\t\"description\": \"Rate movies, books, songs, recipes — anything you can put a number on.\",\n\t\"keywords\": [ \"star\", \"rating\", \"review\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"widgets\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M22 9.24l-7.19-.62L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21 12 17.27 18.18 21l-1.63-7.03L22 9.24zM12 15.4V6.1l1.71 4.04 4.38.38-3.32 2.88 1 4.28L12 15.4z'/></svg>\",\n\t\"supports\": {\n\t\t\"html\": false\n\t},\n\t\"styles\": [\n\t\t{\n\t\t\t\"name\": \"filled\",\n\t\t\t\"label\": \"Filled\",\n\t\t\t\"isDefault\": true\n\t\t},\n\t\t{\n\t\t\t\"name\": \"outlined\",\n\t\t\t\"label\": \"Outlined\"\n\t\t}\n\t],\n\t\"attributes\": {\n\t\t\"rating\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 1\n\t\t},\n\t\t\"maxRating\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 5\n\t\t},\n\t\t\"color\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"ratingStyle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"star\"\n\t\t},\n\t\t\"className\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"left\"\n\t\t}\n\t},\n\t\"example\": {}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/rating-star/edit.js\nimport {\n\tAlignmentToolbar,\n\tBlockControls,\n\tInspectorControls,\n\tPanelColorSettings,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { PanelBody, RangeControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\nexport const Rating = ( { id, setRating, children } ) => {\n\tconst setNewRating = newRating => () => setRating( newRating );\n\tconst maybeSetNewRating =\n\t\tnewRating =>\n\t\t( { code } ) =>\n\t\t\tcode === 'Enter' ? setRating( newRating ) : null;\n\n\treturn (\n\t\t<span\n\t\t\tclassName=\"jetpack-ratings-button\"\n\t\t\ttabIndex={ 0 }\n\t\t\trole=\"button\"\n\t\t\tonKeyDown={ maybeSetNewRating( id ) }\n\t\t\tonClick={ setNewRating( id ) }\n\t\t>\n\t\t\t{ children }\n\t\t</span>\n\t);\n};\n\nexport default Symbol =>\n\tfunction ( { setAttributes, attributes: { align, color, rating, maxRating } } ) {\n\t\tconst blockProps = useBlockProps();\n\n\t\tconst setNewMaxRating = newMaxRating => setAttributes( { maxRating: newMaxRating } );\n\t\tconst setNewColor = newColor => setAttributes( { color: newColor } );\n\t\tconst setNewRating = newRating => {\n\t\t\tif ( newRating === rating ) {\n\t\t\t\t// Same number clicked twice.\n\t\t\t\t// Check if a half rating.\n\t\t\t\tif ( Math.ceil( rating ) === rating ) {\n\t\t\t\t\t// Whole number.\n\t\t\t\t\tnewRating = newRating - 0.5;\n\t\t\t\t}\n\t\t\t} else if ( rating === 0.5 && newRating === 1 ) {\n\t\t\t\t// Clicking the 0.5 star updates to 0 stars.\n\t\t\t\tnewRating = 0;\n\t\t\t}\n\n\t\t\tsetAttributes( { rating: newRating } );\n\t\t};\n\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<AlignmentToolbar\n\t\t\t\t\t\tvalue={ align }\n\t\t\t\t\t\tonChange={ nextAlign => setAttributes( { align: nextAlign } ) }\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t\t<div style={ { textAlign: align } }>\n\t\t\t\t\t{ Array.from( Array( Math.ceil( maxRating ) ), ( _, i ) => i + 1 ).map( position => (\n\t\t\t\t\t\t<Rating key={ position } id={ position } setRating={ setNewRating }>\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t<Symbol\n\t\t\t\t\t\t\t\t\tclassName={ rating >= position - 0.5 ? null : 'is-rating-unfilled' }\n\t\t\t\t\t\t\t\t\tcolor={ color }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t<Symbol\n\t\t\t\t\t\t\t\t\tclassName={ rating >= position ? null : 'is-rating-unfilled' }\n\t\t\t\t\t\t\t\t\tcolor={ color }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</Rating>\n\t\t\t\t\t) ) }\n\t\t\t\t</div>\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<PanelBody title={ __( 'Settings', 'jetpack' ) }>\n\t\t\t\t\t\t<RangeControl\n\t\t\t\t\t\t\tlabel={ __( 'Highest rating', 'jetpack' ) }\n\t\t\t\t\t\t\tvalue={ maxRating }\n\t\t\t\t\t\t\tonChange={ setNewMaxRating }\n\t\t\t\t\t\t\tmin={ 2 }\n\t\t\t\t\t\t\tmax={ 10 }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t\t<PanelColorSettings\n\t\t\t\t\t\ttitle={ __( 'Color', 'jetpack' ) }\n\t\t\t\t\t\tinitialOpen\n\t\t\t\t\t\tcolorSettings={ [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: color,\n\t\t\t\t\t\t\t\tonChange: setNewColor,\n\t\t\t\t\t\t\t\tlabel: __( 'Color', 'jetpack' ),\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</InspectorControls>\n\t\t\t</div>\n\t\t);\n\t};\n\n\n// File: projects/plugins/jetpack/extensions/blocks/rating-star/save.js\nimport { useBlockProps } from '@wordpress/block-editor';\n\n// This is a dynamic block, meaning that its content is created on the server.\n// This function is only to provide a fallback in case the block is deactivated\n// or there is any problem with the render_callback in the server.\n//\n// Note that, unlike the normal ratings block, here we render as many symbols\n// as the rating, not as the maxRating. This is for consistency: some symbols (star)\n// have filled and stroke UTF-8 equivalents but other symbols don't (dollar, chilli).\n// We can't provide the full styled experience using UTF-8, so we optimize\n// for consistency.\nexport default fallbackSymbol =>\n\tfunction ( { attributes: { align, rating, color } } ) {\n\t\tconst blockProps = useBlockProps.save();\n\n\t\treturn (\n\t\t\t<figure { ...blockProps } style={ { textAlign: align } }>\n\t\t\t\t{ Array.from( Array( Math.ceil( rating ) ), ( _, i ) => i + 1 ).map( position => (\n\t\t\t\t\t<span key={ position } style={ { color } }>\n\t\t\t\t\t\t{ fallbackSymbol }\n\t\t\t\t\t</span>\n\t\t\t\t) ) }\n\t\t\t</figure>\n\t\t);\n\t};\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 WordPress block that enables selecting and displaying taxonomy terms through flexible query parameters and design settings, supporting term selection and tag naming."
},
{
"role": "assistant",
"content": "// File: packages/block-library/src/terms-query/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/terms-query\",\n\t\"title\": \"Terms Query\",\n\t\"category\": \"theme\",\n\t\"description\": \"An advanced block that allows displaying taxonomy terms based on different query parameters and visual configurations.\",\n\t\"keywords\": [ \"terms\", \"taxonomy\", \"categories\", \"tags\", \"list\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"termQuery\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"perPage\": 10,\n\t\t\t\t\"taxonomy\": \"category\",\n\t\t\t\t\"order\": \"asc\",\n\t\t\t\t\"orderBy\": \"name\",\n\t\t\t\t\"include\": [],\n\t\t\t\t\"hideEmpty\": true,\n\t\t\t\t\"showNested\": false,\n\t\t\t\t\"inherit\": false\n\t\t\t}\n\t\t},\n\t\t\"tagName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"div\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"templateSlug\" ],\n\t\"providesContext\": {\n\t\t\"termQuery\": \"termQuery\"\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"layout\": true,\n\t\t\"interactivity\": true\n\t}\n}\n\n\n// File: packages/block-library/src/terms-query/index.js\n/**\n * WordPress dependencies\n */\nimport { loop 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';\nimport variations from './variations';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n\texample: {},\n\tvariations,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/terms-query/save.js\n/**\n * WordPress dependencies\n */\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { 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 show weight, show dimensions, show 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/product-specifications/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-specifications\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Product Specifications\",\n\t\"description\": \"Display product weight, dimensions, and attributes.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"attributes\", \"weight\", \"dimensions\", \"additional information\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"ancestor\": [\n\t\t\"woocommerce/single-product\",\n\t\t\"woocommerce/product-template\",\n\t\t\"core/post-template\"\n\t],\n\t\"attributes\": {\n\t\t\"showWeight\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showDimensions\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showAttributes\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\" ],\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\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true\n\t\t}\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-specifications/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\nimport { useQueryLoopProductContextValidation } from '@woocommerce/base-hooks';\nimport { useSelect } from '@wordpress/data';\nimport { optionsStore, Product, productsStore } from '@woocommerce/data';\nimport { PanelBody, ToggleControl } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { ProductSpecificationsEditProps } from './types';\n\nconst getFormattedDimensions = (\n\tdimensions: Product[ 'dimensions' ],\n\tdimensionUnit: string\n) => {\n\tif ( ! dimensions ) return '';\n\n\tconst dimensionKeys = [\n\t\t'length',\n\t\t'width',\n\t\t'height',\n\t] as ( keyof Product[ 'dimensions' ] )[];\n\n\tconst validDimensions = dimensionKeys\n\t\t.map( ( key ) => dimensions[ key ] )\n\t\t.filter(\n\t\t\t( value ): value is string =>\n\t\t\t\ttypeof value === 'string' && value.length > 0\n\t\t);\n\n\tif ( validDimensions.length === 0 ) return '';\n\n\treturn `${ validDimensions.join( ' × ' ) } ${ dimensionUnit }`;\n};\n\nconst EMPTY_PRODUCT_RESULT = {\n\tproduct: null,\n\tisLoadingProduct: false,\n};\n\nconst Edit = ( {\n\tcontext: { postId, postType },\n\tclientId,\n\tattributes,\n\tsetAttributes,\n}: ProductSpecificationsEditProps ) => {\n\tconst { showWeight, showDimensions, showAttributes } = attributes;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wp-block-table',\n\t} );\n\tconst isSpecificProductContext = !! ( postId && postType === 'product' );\n\n\tconst { dimensionUnit, weightUnit, isLoadingUnits } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getOption } = select( optionsStore );\n\t\t\treturn {\n\t\t\t\tdimensionUnit: getOption(\n\t\t\t\t\t'woocommerce_dimension_unit'\n\t\t\t\t) as string,\n\t\t\t\tweightUnit: getOption( 'woocommerce_weight_unit' ) as string,\n\t\t\t\tisLoadingUnits:\n\t\t\t\t\t! select( optionsStore ).hasFinishedResolution(\n\t\t\t\t\t\t'getOption',\n\t\t\t\t\t\t[ 'woocommerce_dimension_unit' ]\n\t\t\t\t\t) ||\n\t\t\t\t\t! select( optionsStore ).hasFinishedResolution(\n\t\t\t\t\t\t'getOption',\n\t\t\t\t\t\t[ 'woocommerce_weight_unit' ]\n\t\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { product, isLoadingProduct } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! postId ) return EMPTY_PRODUCT_RESULT;\n\t\t\tconst { getProduct } = select( productsStore );\n\t\t\treturn {\n\t\t\t\tproduct: getProduct( Number( postId ) ),\n\t\t\t\tisLoadingProduct: ! select(\n\t\t\t\t\tproductsStore\n\t\t\t\t).hasFinishedResolution( 'getProduct', [ Number( postId ) ] ),\n\t\t\t};\n\t\t},\n\t\t[ postId ]\n\t);\n\n\t/**\n\t * Validate Query Loop block context\n\t */\n\tconst { hasInvalidContext, warningElement } =\n\t\tuseQueryLoopProductContextValidation( {\n\t\t\tclientId,\n\t\t\tpostType,\n\t\t\tblockName: __( 'Product Specifications', 'woocommerce' ),\n\t\t} );\n\tif ( hasInvalidContext ) {\n\t\treturn warningElement;\n\t}\n\n\t/**\n\t * Display loading state\n\t */\n\tif ( isLoadingUnits || ( isLoadingProduct && isSpecificProductContext ) ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<span className=\"wc-product-specifications__loading\">\n\t\t\t\t\t{ __( 'Loading…', 'woocommerce' ) }\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t);\n\t}\n\n\t/**\n\t * Display no product found message\n\t */\n\tif ( postId && ! product ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<p>{ __( 'No product found', 'woocommerce' ) }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst productData: Record< string, { label: string; value: string } > = {};\n\n\tif ( showWeight ) {\n\t\tproductData.weight = {\n\t\t\tlabel: __( 'Weight', 'woocommerce' ),\n\t\t\tvalue: '',\n\t\t};\n\n\t\tif ( isSpecificProductContext ) {\n\t\t\tproductData.weight.value = product?.weight\n\t\t\t\t? `${ product.weight } ${ weightUnit }`\n\t\t\t\t: '';\n\t\t} else {\n\t\t\tproductData.weight.value = `10 ${ weightUnit }`;\n\t\t}\n\t}\n\n\tif ( showDimensions ) {\n\t\tproductData.dimensions = {\n\t\t\tlabel: __( 'Dimensions', 'woocommerce' ),\n\t\t\tvalue: '',\n\t\t};\n\n\t\tif ( isSpecificProductContext ) {\n\t\t\tproductData.dimensions.value = product?.dimensions\n\t\t\t\t? getFormattedDimensions( product.dimensions, dimensionUnit )\n\t\t\t\t: '';\n\t\t} else {\n\t\t\tproductData.dimensions.value = `10 × 10 × 10 ${ dimensionUnit }`;\n\t\t}\n\t}\n\n\tif ( showAttributes ) {\n\t\tif ( isSpecificProductContext ) {\n\t\t\tif ( product?.attributes ) {\n\t\t\t\tproduct.attributes.forEach( ( attribute ) => {\n\t\t\t\t\tproductData[ attribute.name.toLowerCase() ] = {\n\t\t\t\t\t\tlabel: attribute.name,\n\t\t\t\t\t\tvalue: attribute.options.join( ', ' ),\n\t\t\t\t\t};\n\t\t\t\t} );\n\t\t\t}\n\t\t} else {\n\t\t\tproductData.test_attribute = {\n\t\t\t\tlabel: __( 'Test Attribute', 'woocommerce' ),\n\t\t\t\tvalue: __( 'First, Second, Third', 'woocommerce' ),\n\t\t\t};\n\t\t}\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Display Settings', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show Weight', 'woocommerce' ) }\n\t\t\t\t\t\tchecked={ showWeight }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( { showWeight: ! showWeight } )\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\tlabel={ __( 'Show Dimensions', 'woocommerce' ) }\n\t\t\t\t\t\tchecked={ showDimensions }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowDimensions: ! showDimensions,\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\tlabel={ __( 'Show Attributes', 'woocommerce' ) }\n\t\t\t\t\t\tchecked={ showAttributes }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowAttributes: ! showAttributes,\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<figure { ...blockProps }>\n\t\t\t\t<table>\n\t\t\t\t\t<thead className=\"screen-reader-text\">\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>{ __( 'Attributes', 'woocommerce' ) }</th>\n\t\t\t\t\t\t\t<th>{ __( 'Value', 'woocommerce' ) }</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody>\n\t\t\t\t\t\t{ Object.entries( productData ).map(\n\t\t\t\t\t\t\t( [ key, data ] ) =>\n\t\t\t\t\t\t\t\tdata.value && (\n\t\t\t\t\t\t\t\t\t<tr\n\t\t\t\t\t\t\t\t\t\tkey={ key }\n\t\t\t\t\t\t\t\t\t\tclassName={ `wp-block-product-specifications-item wc-block-product-specifications-item-${ key }` }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<th\n\t\t\t\t\t\t\t\t\t\t\tscope=\"row\"\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"wp-block-product-specifications-item__label\"\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ data.label }\n\t\t\t\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t\t\t\t\t<td className=\"wp-block-product-specifications-item__value\">\n\t\t\t\t\t\t\t\t\t\t\t{ data.value }\n\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) }\n\t\t\t\t\t</tbody>\n\t\t\t\t</table>\n\t\t\t</figure>\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": "Develop a Gutenberg block mechanism to dynamically showcase a sale indicator when a product is discounted, with configurable attributes tracking product identification and block/template hierarchical relationships."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/block.json\n{\n\t\"name\": \"woocommerce/product-sale-badge\",\n\t\"title\": \"On-Sale Badge\",\n\t\"description\": \"Displays an on-sale badge if the product is on-sale.\",\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\"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\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"html\": false,\n\t\t\"align\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"background\": true,\n\t\t\t\"link\": false,\n\t\t\t\"__experimentalSkipSerialization\": 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\"__experimentalSkipSerialization\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": 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\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"email\": true,\n\t\t\"__experimentalSelector\": \".wc-block-components-product-sale-badge\"\n\t},\n\t\"ancestor\": [\n\t\t\"woocommerce/single-product\",\n\t\t\"woocommerce/product-template\",\n\t\t\"core/post-template\",\n\t\t\"woocommerce/product-gallery\"\n\t],\n\t\"usesContext\": [ \"query\", \"queryId\", \"postId\" ],\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"example\": {},\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/sale-badge/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport type { BlockAttributes } from './types';\nimport { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';\n\nconst Edit = ( {\n\tattributes,\n\tcontext,\n}: BlockEditProps< BlockAttributes > & { context: Context } ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\n\t// Remove the `style` prop from the block props to avoid passing it to the wrapper div.\n\tconst { style, ...wrapperProps } = blockProps;\n\tconst { isDescendentOfSingleProductTemplate } =\n\t\tuseIsDescendentOfSingleProductTemplate();\n\n\tconst blockAttrs = {\n\t\t...attributes,\n\t\t...context,\n\t};\n\n\treturn (\n\t\t<div { ...wrapperProps }>\n\t\t\t<Block\n\t\t\t\t{ ...blockAttrs }\n\t\t\t\tisDescendentOfSingleProductTemplate={\n\t\t\t\t\tisDescendentOfSingleProductTemplate\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 WordPress block that allows for configurable URL insertion and dynamic growth 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: projects/plugins/jetpack/extensions/blocks/nextdoor/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/nextdoor\",\n\t\"title\": \"Nextdoor\",\n\t\"description\": \"Embed a Nextdoor post for your neighbors on your blog.\",\n\t\"keywords\": [ \"neighbor\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg height='24' width='24' viewBox='0 0 130 130' xmlns='http://www.w3.org/2000/svg'><g><path d='M64.25 3.531c-31.144.337-57.596 24.22-60.469 55.907-3.064 33.799 21.857 63.685 55.657 66.75 33.799 3.064 63.685-21.857 66.75-55.657 3.064-33.8-21.857-63.686-55.657-66.75a62.075 62.075 0 00-6.281-.25zm3.938 34.907C82.468 38.438 93.5 48.58 93.5 61.5v27c0 .685-.565 1.25-1.25 1.25H80.906a1.267 1.267 0 01-1.25-1.25V63.375c0-5.58-4.309-11.938-11.469-11.938-7.47 0-11.468 6.358-11.468 11.938V88.5c0 .685-.565 1.25-1.25 1.25H44.125c-.68 0-1.219-.57-1.219-1.25V64.156c0-.74-.529-1.364-1.25-1.531-13.13-2.93-15.115-10.285-15.375-21.125-.005-.332.142-.67.375-.906.233-.237.543-.375.875-.375l11.688.062c.66.01 1.187.529 1.218 1.188.13 4.44.438 9.406 4.438 9.406.83 0 1.443-1.179 1.813-1.719 4.41-6.48 12.28-10.718 21.5-10.718z'/></g></svg>\",\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"alignWide\": true,\n\t\t\"html\": false\n\t},\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/nextdoor/edit.js\nimport { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { getBlockDefaultClassName } from '@wordpress/blocks';\nimport { SandBox, Button, Placeholder, withNotices } from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __, _x } from '@wordpress/i18n';\nimport './editor.scss';\nimport { isEqual } from 'lodash';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport metadata from './block.json';\nimport NextdoorControls from './controls';\nimport { parseUrl } from './utils';\n\nconst icon = getBlockIconComponent( metadata );\n\nexport function NextdoorEdit( {\n\tattributes,\n\tclientId,\n\tname,\n\tnoticeOperations,\n\tnoticeUI,\n\tsetAttributes,\n} ) {\n\tconst blockProps = useBlockProps();\n\tconst defaultClassName = getBlockDefaultClassName( name );\n\tconst validatedAttributes = getValidatedAttributes( metadata.attributes, attributes );\n\n\tif ( ! isEqual( validatedAttributes, attributes ) ) {\n\t\tsetAttributes( validatedAttributes );\n\t}\n\n\tconst { url } = validatedAttributes;\n\tconst [ iframeUrl, setIframeUrl ] = useState( url ? parseUrl( url ) : null );\n\n\tconst [ nextdoorShareUrl, setNextdoorShareUrl ] = useState( iframeUrl );\n\n\tconst setErrorNotice = () => {\n\t\tnoticeOperations.removeAllNotices();\n\t\tnoticeOperations.createErrorNotice(\n\t\t\t__(\n\t\t\t\t\"Your Nextdoor post couldn't be embedded. Please double check the URL or code.\",\n\t\t\t\t'jetpack'\n\t\t\t)\n\t\t);\n\t};\n\n\tconst onFormSubmit = event => {\n\t\tif ( ! event ) {\n\t\t\tsetIframeUrl( null );\n\t\t\tsetErrorNotice();\n\t\t\treturn;\n\t\t}\n\t\tevent.preventDefault();\n\n\t\tif ( ! nextdoorShareUrl ) {\n\t\t\tsetIframeUrl( null );\n\t\t\tsetErrorNotice();\n\t\t\treturn;\n\t\t}\n\n\t\tconst embedUrl = parseUrl( nextdoorShareUrl );\n\n\t\tif ( ! embedUrl ) {\n\t\t\tsetIframeUrl( null );\n\t\t\tsetErrorNotice();\n\t\t\treturn;\n\t\t}\n\n\t\tsetIframeUrl( embedUrl );\n\t\tsetAttributes( { url: embedUrl } );\n\t};\n\n\tconst blockPlaceholder = (\n\t\t<Placeholder\n\t\t\tlabel={ __( 'Nextdoor', 'jetpack' ) }\n\t\t\tinstructions={ __( 'Enter the URL of your Nextdoor post to share below.', 'jetpack' ) }\n\t\t\ticon={ icon }\n\t\t\tnotices={ noticeUI }\n\t\t>\n\t\t\t<form onSubmit={ onFormSubmit }>\n\t\t\t\t<input\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\tid=\"nextdoorShareUrl\"\n\t\t\t\t\tonChange={ event => setNextdoorShareUrl( event.target.value ) }\n\t\t\t\t\tplaceholder={ __( 'Nextdoor post URL', 'jetpack' ) }\n\t\t\t\t\tvalue={ nextdoorShareUrl || '' }\n\t\t\t\t\tclassName=\"components-placeholder__input\"\n\t\t\t\t/>\n\t\t\t\t<div>\n\t\t\t\t\t<Button variant=\"secondary\" type=\"submit\">\n\t\t\t\t\t\t{ _x( 'Embed', 'button label', 'jetpack' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</div>\n\t\t\t</form>\n\t\t</Placeholder>\n\t);\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<NextdoorControls\n\t\t\t\t{ ...{ defaultClassName, nextdoorShareUrl, onFormSubmit, setNextdoorShareUrl } }\n\t\t\t/>\n\t\t\t{ iframeUrl ? (\n\t\t\t\t<BlockPreview\n\t\t\t\t\tdefaultClassName={ defaultClassName }\n\t\t\t\t\tiframeUrl={ iframeUrl }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t/>\n\t\t\t) : (\n\t\t\t\tblockPlaceholder\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nconst BlockPreview = ( { defaultClassName, iframeUrl, clientId } ) => {\n\tconst html = `\n\t\t<script>\n\t\t\twindow.addEventListener( 'message', function ( event ) {\n\t\t\t\tif ( ! event.origin.startsWith( 'https://nextdoor' ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tvar iframe = document.getElementById( 'nextdoor-embed-${ clientId }' );\n\t\t\t\tif ( event.source !== iframe.contentWindow ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tiframe.setAttribute( 'height', event.data.height );\n\t\t\t\tvar clientBoundingRect = document.body.getBoundingClientRect();\n\t\t\t\twindow.parent.postMessage( { action: 'resize', width: clientBoundingRect.width, height: clientBoundingRect.height }, '*' );\n\t\t\t} );\n\t\t</script>\n\t\t<iframe id=\"nextdoor-embed-${ clientId }\" width=\"100%\" height=\"200\" frameBorder=\"0\" src=\"${ iframeUrl }\" title=\"${ __(\n\t\t\t'Nextdoor',\n\t\t\t'jetpack'\n\t\t) }\" />\n\t\t`;\n\n\treturn (\n\t\t<>\n\t\t\t<div className={ `${ defaultClassName }-overlay` }></div>\n\t\t\t<SandBox html={ html } />\n\t\t</>\n\t);\n};\n\nexport default withNotices( NextdoorEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/nextdoor/save.js\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save() {\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": "Design a WooCommerce block featuring flexible class name customization and the ability to lock its configuration."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/block.json\n{\n\t\"name\": \"woocommerce/checkout-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/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-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": "Develop a flexible WooCommerce block that allows administrators to modify key attributes such as locking options, cart page selection, cart return link display, and other configurable elements."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-actions-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Actions\",\n\t\"description\": \"Allow customers to place 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\t\"move\": true\n\t\t\t}\n\t\t},\n\t\t\"cartPageId\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"showReturnToCart\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"priceSeparator\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"·\"\n\t\t}\n\t},\n\t\"parent\": [ \"woocommerce/checkout-fields-block\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport PageSelector from '@woocommerce/editor-components/page-selector';\nimport { PanelBody, ToggleControl, TextControl } from '@wordpress/components';\nimport { CHECKOUT_PAGE_ID } from '@woocommerce/block-settings';\nimport {\n\tPlaceOrderButton,\n\tReturnToCartButton,\n} from '@woocommerce/base-components/cart-checkout';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport { BlockAttributes } from './block';\nimport { defaultReturnToCartButtonLabel } from './constants';\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: BlockAttributes;\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst {\n\t\tcartPageId = 0,\n\t\tshowReturnToCart = false,\n\t\tplaceOrderButtonLabel,\n\t\treturnToCartButtonLabel,\n\t} = attributes;\n\tconst { current: savedCartPageId } = useRef( cartPageId );\n\tconst currentPostId = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! savedCartPageId ) {\n\t\t\t\tconst store = select( 'core/editor' );\n\t\t\t\treturn store.getCurrentPostId();\n\t\t\t}\n\t\t\treturn savedCartPageId;\n\t\t},\n\t\t[ savedCartPageId ]\n\t);\n\n\tconst showPrice = blockProps.className.includes( 'is-style-with-price' );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Options', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t'Show a \"Return to Cart\" link',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Recommended to enable only if there is no Cart link in the header.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ showReturnToCart }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowReturnToCart: ! showReturnToCart,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\n\t\t\t\t\t{ showPrice && (\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __( 'Price separator', 'woocommerce' ) }\n\t\t\t\t\t\t\tid=\"price-separator\"\n\t\t\t\t\t\t\tvalue={ attributes.priceSeparator }\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\tpriceSeparator: 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) }\n\t\t\t\t</PanelBody>\n\n\t\t\t\t{ showReturnToCart &&\n\t\t\t\t\t! (\n\t\t\t\t\t\tcurrentPostId === CHECKOUT_PAGE_ID &&\n\t\t\t\t\t\tsavedCartPageId === 0\n\t\t\t\t\t) && (\n\t\t\t\t\t\t<PageSelector\n\t\t\t\t\t\t\tpageId={ cartPageId }\n\t\t\t\t\t\t\tsetPageId={ ( id: number ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { cartPageId: id } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlabels={ {\n\t\t\t\t\t\t\t\ttitle: __(\n\t\t\t\t\t\t\t\t\t'Return to Cart button',\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\tdefault: __(\n\t\t\t\t\t\t\t\t\t'WooCommerce Cart Page',\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} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t</InspectorControls>\n\t\t\t<div className=\"wc-block-checkout__actions\">\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( 'wc-block-checkout__actions_row', {\n\t\t\t\t\t\t'wc-block-checkout__actions_row--justify-flex-end':\n\t\t\t\t\t\t\t! showReturnToCart,\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t{ showReturnToCart && (\n\t\t\t\t\t\t<ReturnToCartButton element=\"span\">\n\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\tmultiline={ false }\n\t\t\t\t\t\t\t\tallowedFormats={ [] }\n\t\t\t\t\t\t\t\tvalue={ returnToCartButtonLabel }\n\t\t\t\t\t\t\t\tplaceholder={ defaultReturnToCartButtonLabel }\n\t\t\t\t\t\t\t\tonChange={ ( content ) => {\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\treturnToCartButtonLabel: content,\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</ReturnToCartButton>\n\t\t\t\t\t) }\n\t\t\t\t\t<PlaceOrderButton\n\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\tmultiline={ false }\n\t\t\t\t\t\t\t\tallowedFormats={ [] }\n\t\t\t\t\t\t\t\tvalue={ placeOrderButtonLabel }\n\t\t\t\t\t\t\t\tonChange={ ( content ) => {\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tplaceOrderButtonLabel: content,\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}\n\t\t\t\t\t\tfullWidth={ ! showReturnToCart }\n\t\t\t\t\t\tshowPrice={ showPrice }\n\t\t\t\t\t\tpriceSeparator={ attributes.priceSeparator }\n\t\t\t\t\t/>\n\t\t\t\t</div>\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": "Develop a custom Gutenberg block that Sell products and subscriptions."
},
{
"role": "assistant",
"content": "// File: projects/plugins/jetpack/extensions/blocks/payment-buttons/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/payment-buttons\",\n\t\"title\": \"Payment Buttons\",\n\t\"description\": \"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\"earn\",\n\t\t\"monetize\",\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\"__experimentalExposeControlsToChildren\": true,\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"spacing\": {\n\t\t\t\"blockGap\": true,\n\t\t\t\"margin\": [ \"vertical\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"blockGap\": 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\"__experimentalFontFamily\": 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},\n\t\"attributes\": {}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/payment-buttons/edit.js\nimport { BlockControls, useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\nimport { __ } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport ConnectBanner from '../../shared/components/connect-banner';\nimport StripeConnectToolbarButton from '../../shared/components/stripe-connect-toolbar-button';\nimport { StripeNudge } from '../../shared/components/stripe-nudge';\nimport useIsUserConnected from '../../shared/use-is-user-connected';\nimport { store as membershipProductsStore } from '../../store/membership-products';\n\nconst ALLOWED_BLOCKS = [ 'jetpack/recurring-payments' ];\n\nfunction PaymentButtonsEdit( { clientId, attributes } ) {\n\tconst { layout, fontSize } = attributes;\n\tconst { connectUrl, isApiConnected } = useSelect( select => {\n\t\tconst { getConnectUrl, isApiStateConnected } = select( membershipProductsStore );\n\t\treturn {\n\t\t\tconnectUrl: getConnectUrl(),\n\t\t\tisApiConnected: isApiStateConnected(),\n\t\t};\n\t} );\n\tconst isUserConnected = useIsUserConnected();\n\n\tconst paymentButtonBlocks = useSelect(\n\t\tselect =>\n\t\t\tselect( 'core/block-editor' )\n\t\t\t\t.getBlock( clientId )\n\t\t\t\t.innerBlocks.filter( block => block.name === 'jetpack/recurring-payments' ),\n\t\t[ clientId ]\n\t);\n\n\tuseEffect( () => {\n\t\taddFilter(\n\t\t\t'jetpack.recurringPayments.editorSettings',\n\t\t\t'jetpack/payment-buttons-hide-nudges-from-inner-blocks',\n\t\t\t( editorSettings, paymentButtonClientId ) => {\n\t\t\t\tif (\n\t\t\t\t\tpaymentButtonBlocks.some(\n\t\t\t\t\t\tpaymentButtonBlock => paymentButtonBlock.clientId === paymentButtonClientId\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...editorSettings,\n\t\t\t\t\t\t/*\n\t\t\t\t\t\t * This block already displays Stripe and plan upgrades nudges, so we hide the ones\n\t\t\t\t\t\t * displayed in the inner blocks.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tshowStripeNudge: false,\n\t\t\t\t\t\tshowUpgradeNudge: false,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn editorSettings;\n\t\t\t}\n\t\t);\n\t}, [ paymentButtonBlocks ] );\n\n\tconst showStripeConnectAction = ! isApiConnected && !! connectUrl;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( {\n\t\t\t'has-custom-font-size': !! fontSize || attributes?.style?.typography?.fontSize,\n\t\t} ),\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\tallowedBlocks: ALLOWED_BLOCKS,\n\t\torientation: 'horizontal',\n\t\ttemplate: [ [ 'jetpack/recurring-payments' ] ],\n\t\ttemplateInsertUpdatesSelection: true,\n\t\tlayout,\n\t} );\n\n\t// The ID needs to be just on the outermost wrapper - the toolbar and wpcom upgrade nudge\n\t// will then be positioned in relation to this.\n\tdelete innerBlocksProps.id;\n\tdelete innerBlocksProps[ 'data-block' ];\n\n\tif ( ! isUserConnected ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<ConnectBanner\n\t\t\t\t\tblock=\"Payment Buttons\"\n\t\t\t\t\texplanation={ __(\n\t\t\t\t\t\t'Connect your WordPress.com account to enable payment buttons on your site.',\n\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ showStripeConnectAction && (\n\t\t\t\t<BlockControls group=\"block\">\n\t\t\t\t\t<StripeConnectToolbarButton\n\t\t\t\t\t\tblockName=\"jetpack/payment-buttons\"\n\t\t\t\t\t\tconnectUrl={ connectUrl }\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t) }\n\t\t\t{ showStripeConnectAction && <StripeNudge blockName=\"payment-buttons\" /> }\n\t\t\t<div { ...innerBlocksProps } />\n\t\t</div>\n\t);\n}\n\nexport default PaymentButtonsEdit;\n\n\n// File: projects/plugins/jetpack/extensions/blocks/payment-buttons/save.js\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\nexport default function save( { attributes } ) {\n\tconst className = clsx( {\n\t\t'has-custom-font-size': !! attributes?.fontSize || attributes?.style?.typography?.fontSize,\n\t} );\n\tconst blockProps = useBlockProps.save( { className: className } );\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 block for Display code snippets that respect your spacing and tabs. that allows users to configure: content"
},
{
"role": "assistant",
"content": "// File: packages/block-library/src/code/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/code\",\n\t\"title\": \"Code\",\n\t\"category\": \"text\",\n\t\"description\": \"Display code snippets that respect your spacing and tabs.\",\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\": \"code\",\n\t\t\t\"__unstablePreserveWhiteSpace\": true,\n\t\t\t\"role\": \"content\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\" ],\n\t\t\"anchor\": 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\"spacing\": {\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\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\"__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\"width\": true,\n\t\t\t\t\"color\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": 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}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-code\"\n}\n\n\n// File: packages/block-library/src/code/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { code 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: Preserve \\n markers for line breaks\n\t\t\tcontent: __(\n\t\t\t\t'// A “block” is the abstract term used\\n// to describe units of markup that\\n// when composed together, form the\\n// content or layout of a page.\\nregisterBlockType( name, settings );'\n\t\t\t),\n\t\t\t/* eslint-enable @wordpress/i18n-no-collapsible-whitespace */\n\t\t},\n\t},\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\tcontent: attributes.content + '\\n\\n' + attributesToMerge.content,\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: 'content',\n\t\t\tlabel: __( 'Code' ),\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/code/save.js\n/**\n * WordPress dependencies\n */\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { escape } from './utils';\n\nexport default function save( { attributes } ) {\n\treturn (\n\t\t<pre { ...useBlockProps.save() }>\n\t\t\t<RichText.Content\n\t\t\t\ttagName=\"code\"\n\t\t\t\t// To do: `escape` encodes characters in shortcodes and URLs to\n\t\t\t\t// prevent embedding in PHP. Ideally checks for the code block,\n\t\t\t\t// or pre/code tags, should be made on the PHP side?\n\t\t\t\tvalue={ escape(\n\t\t\t\t\ttypeof attributes.content === 'string'\n\t\t\t\t\t\t? attributes.content\n\t\t\t\t\t\t: attributes.content.toHTMLString( {\n\t\t\t\t\t\t\t\tpreserveWhiteSpace: true,\n\t\t\t\t\t\t } )\n\t\t\t\t) }\n\t\t\t/>\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": "Create a WooCommerce-focused block that provides intuitive page display settings, empowering users to customize their content presentation within the WordPress 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: plugins/woocommerce/client/blocks/assets/js/blocks/page-content-wrapper/block.json\n{\n\t\"name\": \"woocommerce/page-content-wrapper\",\n\t\"title\": \"WooCommerce Page\",\n\t\"description\": \"Displays WooCommerce page content.\",\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\"inserter\": false\n\t},\n\t\"attributes\": {\n\t\t\"page\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"postId\": \"postId\",\n\t\t\"postType\": \"postType\"\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/page-content-wrapper/index.tsx\n/**\n * External dependencies\n */\nimport {\n\tregisterBlockType,\n\tInnerBlockTemplate,\n\tBlockAttributes,\n} from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\nimport { page } from '@wordpress/icons';\nimport { CHECKOUT_PAGE_ID, CART_PAGE_ID } from '@woocommerce/block-settings';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport './editor.scss';\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: BlockAttributes;\n\tsetAttributes: ( attrs: BlockAttributes ) => void;\n} ) => {\n\tconst TEMPLATE: InnerBlockTemplate[] = [\n\t\t[ 'core/post-title', { align: 'wide', level: 1 } ],\n\t\t[ 'core/post-content', { align: 'wide' } ],\n\t];\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wp-block-woocommerce-page-content-wrapper',\n\t} );\n\n\tuseEffect( () => {\n\t\tif ( ! attributes.postId && attributes.page ) {\n\t\t\tlet postId = 0;\n\n\t\t\tif ( attributes.page === 'checkout' ) {\n\t\t\t\tpostId = CHECKOUT_PAGE_ID;\n\t\t\t}\n\n\t\t\tif ( attributes.page === 'cart' ) {\n\t\t\t\tpostId = CART_PAGE_ID;\n\t\t\t}\n\n\t\t\tif ( postId ) {\n\t\t\t\tsetAttributes( { postId, postType: 'page' } );\n\t\t\t}\n\t\t}\n\t}, [ attributes, setAttributes ] );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks template={ TEMPLATE } />\n\t\t</div>\n\t);\n};\n\nregisterBlockType( metadata, {\n\ticon: {\n\t\tsrc: page,\n\t},\n\tedit: Edit,\n\tsave: () => <InnerBlocks.Content />,\n\tvariations: [\n\t\t{\n\t\t\tname: 'checkout-page',\n\t\t\ttitle: __( 'Checkout Page', 'woocommerce' ),\n\t\t\tattributes: {\n\t\t\t\tpage: 'checkout',\n\t\t\t},\n\t\t\tisActive: ( blockAttributes, variationAttributes ) =>\n\t\t\t\tblockAttributes.page === variationAttributes.page,\n\t\t},\n\t\t{\n\t\t\tname: 'cart-page',\n\t\t\ttitle: __( 'Cart Page', 'woocommerce' ),\n\t\t\tattributes: {\n\t\t\t\tpage: 'cart',\n\t\t\t},\n\t\t\tisActive: ( blockAttributes, variationAttributes ) =>\n\t\t\t\tblockAttributes.page === variationAttributes.page,\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 WordPress block that enables view frequency-based visibility controls, allowing customization of visibility criteria and threshold limits for page access."
},
{
"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/repeat-visitor/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/repeat-visitor\",\n\t\"title\": \"Repeat Visitor\",\n\t\"description\": \"Control block visibility based on how often a visitor has viewed the page.\",\n\t\"keywords\": [ \"return\", \"visitors\", \"visibility\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"widgets\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false\n\t},\n\t\"attributes\": {\n\t\t\"criteria\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"after-visits\"\n\t\t},\n\t\t\"threshold\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"criteria\": \"after-visits\",\n\t\t\t\"threshold\": 3\n\t\t},\n\t\t\"innerBlocks\": [\n\t\t\t{\n\t\t\t\t\"name\": \"core/paragraph\",\n\t\t\t\t\"attributes\": \"This block will only appear to a visitor who visited the page three or more times.\"\n\t\t\t}\n\t\t]\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/repeat-visitor/constants.js\nexport const CRITERIA_AFTER = 'after-visits';\nexport const CRITERIA_BEFORE = 'before-visits';\nexport const DEFAULT_THRESHOLD = 3;\nexport const COOKIE_NAME = 'jp-visit-counter';\nexport const MAX_COOKIE_AGE = 6 * 30 * 24 * 60 * 60; // 6 months\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 designed to showcase product ratings, enabling customization of product identification, query loop relationship, text alignment, and two 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: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.json\n{\n\t\"name\": \"woocommerce/product-rating\",\n\t\"icon\": \"info\",\n\t\"title\": \"Product Rating\",\n\t\"description\": \"Display the average rating 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\"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\"supports\": {\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\": 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\": [\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\": [ \"query\", \"queryId\", \"postId\" ],\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/rating/index.ts\n/**\n * External dependencies\n */\nimport type { BlockConfiguration } from '@wordpress/blocks';\nimport { registerProductBlockType } from '@woocommerce/atomic-utils';\n\n/**\n * Internal dependencies\n */\nimport save from '../save';\nimport edit from './edit';\nimport { BLOCK_ICON as icon } from './constants';\nimport metadata from './block.json';\n\nconst blockConfig: BlockConfiguration = {\n\t...metadata,\n\ticon: { src: icon },\n\tedit,\n\tsave,\n};\n\nregisterProductBlockType( blockConfig, {\n\tisAvailableOnPostEditor: true,\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 additional checkout fields from the 'contact' and 'order' locations. 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/additional-fields-wrapper/block.json\n{\n\t\"name\": \"woocommerce/order-confirmation-additional-fields-wrapper\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Additional Fields\",\n\t\"description\": \"Display additional checkout fields from the 'contact' and 'order' locations.\",\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/additional-fields-wrapper/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport {\n\tORDER_FORM_FIELDS,\n\tCONTACT_FORM_FIELDS,\n} from '@woocommerce/block-settings';\n\n/**\n * Internal dependencies\n */\nimport './style.scss';\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\t\tclassName: 'wc-block-order-confirmation-additional-fields-wrapper',\n\t} );\n\n\tconst additionalFields = {\n\t\t...ORDER_FORM_FIELDS,\n\t\t...CONTACT_FORM_FIELDS,\n\t};\n\n\tif ( Object.entries( additionalFields ).length === 0 ) {\n\t\treturn null;\n\t}\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-additional-fields',\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 block for Displays the next posts page link. that allows users to configure: label"
},
{
"role": "assistant",
"content": "// File: packages/block-library/src/query-pagination-next/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/query-pagination-next\",\n\t\"title\": \"Next Page\",\n\t\"category\": \"theme\",\n\t\"parent\": [ \"core/query-pagination\" ],\n\t\"description\": \"Displays the next posts 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\": [\n\t\t\"queryId\",\n\t\t\"query\",\n\t\t\"paginationArrow\",\n\t\t\"showLabel\",\n\t\t\"enhancedPagination\"\n\t],\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/query-pagination-next/index.js\n/**\n * WordPress dependencies\n */\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};\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 Gutenberg block designed to render the principal product image with comprehensive attribute options, including toggles for link display, sale badge presentation, alignment, and several supplementary configuration choices."
},
{
"role": "assistant",
"content": "// 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": "Construct a WooCommerce block that supports a configurable CSS class identifier and implements locking functionality."
},
{
"role": "assistant",
"content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/block.json\n{\n\t\"name\": \"woocommerce/checkout-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/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-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": "Design a custom Gutenberg block that serves as a fallback display for scenarios where no search or query results are available."
},
{
"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-no-results/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/query-no-results\",\n\t\"title\": \"No Results\",\n\t\"category\": \"theme\",\n\t\"description\": \"Contains the block elements used to render content when no query results are found.\",\n\t\"ancestor\": [ \"core/query\" ],\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"queryId\", \"query\" ],\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},\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/query-no-results/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { loop 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\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/paragraph',\n\t\t\t\tattributes: {\n\t\t\t\t\tcontent: __( 'No posts were found.' ),\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/query-no-results/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 WordPress block to Block: a8c/starscape"
},
{
"role": "assistant",
"content": "// File: blocks/starscape/src/index.js\n/**\n * WordPress dependencies\n */\nimport { registerBlockType } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport StarsIcon from './icon';\nimport attributes from './attributes';\nimport edit from './edit';\nimport save from './save';\nimport deprecated from './deprecated';\n\nexport function registerBlock() {\n\tregisterBlockType( 'a8c/starscape', {\n\t\tapiVersion: 3,\n\t\ttitle: __( 'Starscape', 'starscape' ),\n\t\tdescription: __( 'Create content with stars in motion.', 'starscape' ),\n\t\ticon: <StarsIcon />,\n\t\tcategory: 'widgets',\n\t\tsupports: {\n\t\t\tclassName: true,\n\t\t\talign: [ 'wide', 'full' ],\n\t\t\tcolor: {\n\t\t\t\theading: true,\n\t\t\t\ttext: true,\n\t\t\t\tlink: true,\n\t\t\t\tbackground: false,\n\t\t\t\tgradients: false,\n\t\t\t},\n\t\t\thtml: false,\n\t\t\tlayout: {\n\t\t\t\tallowJustification: false,\n\t\t\t},\n\t\t\tspacing: {\n\t\t\t\tpadding: true,\n\t\t\t\tmargin: [ 'top', 'bottom' ],\n\t\t\t\tblockGap: true,\n\t\t\t\t__experimentalDefaultControls: {\n\t\t\t\t\tpadding: true,\n\t\t\t\t\tblockGap: true,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tattributes,\n\t\tedit,\n\t\tsave,\n\t\tdeprecated,\n\t} );\n}\n\n\n// File: blocks/starscape/src/save.js\n/**\n * WordPress dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Starscape from './starscape';\nimport { genStars, genAnimations } from './utils';\n\nfunction StarscapeSave( { attributes } ) {\n\tconst {\n\t\tbackground,\n\t\tcolor,\n\t\tintensity,\n\t\tdensity,\n\t\tspeed,\n\t\tminHeight,\n\t\tareaWidth,\n\t\tareaHeight,\n\t\ttagName,\n\t} = attributes;\n\n\tconst starStyles = genStars( { color, density, areaWidth, areaHeight } );\n\tconst animationStyles = genAnimations( { speed } );\n\n\tconst blockProps = useBlockProps.save( {\n\t\tstyle: { background, minHeight, overflow: 'hidden' },\n\t} );\n\n\tconst innerBlocksProps = useInnerBlocksProps.save( {\n\t\tclassName: 'wp-block-a8c-starscape__inner',\n\t} );\n\n\treturn (\n\t\t<Starscape\n\t\t\tas={ tagName }\n\t\t\tstarStyles={ starStyles }\n\t\t\tanimationStyles={ animationStyles }\n\t\t\tintensity={ intensity }\n\t\t\t{ ...blockProps }\n\t\t>\n\t\t\t<div { ...innerBlocksProps } />\n\t\t</Starscape>\n\t);\n}\n\nexport default StarscapeSave;\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 previous 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-previous/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-reviews-pagination-previous\",\n\t\"title\": \"Reviews Previous Page\",\n\t\"category\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/product-reviews-pagination\" ],\n\t\"description\": \"Displays the previous 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-previous/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-previous-pseudo-link\"\n\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t\t{ ...useBlockProps() }\n\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-previous-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\t<PlainText\n\t\t\t\t__experimentalVersion={ 2 }\n\t\t\t\ttagName=\"span\"\n\t\t\t\taria-label={ __( 'Older reviews page link', 'woocommerce' ) }\n\t\t\t\tplaceholder={ __( 'Older 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</a>\n\t);\n}\n"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.