Dataset Viewer
Auto-converted to Parquet Duplicate
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&nbsp;\n\t\t\t\t\t\t\t\t<strong className=\"product-quantity\">\n\t\t\t\t\t\t\t\t\t&times;&nbsp;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&nbsp;\n\t\t\t\t\t\t\t\t<strong className=\"product-quantity\">\n\t\t\t\t\t\t\t\t\t&times;&nbsp;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" } ]
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
11