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": "Create a woocommerce block with customizable align, class 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: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/status/block.json\n{\n\t\"name\": \"woocommerce/order-confirmation-status\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Order Status\",\n\t\"description\": \"Display a \\\"thank you\\\" message, or a sentence regarding the current order status.\",\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\"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},\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/status/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport './style.scss';\n\nconst Edit = (): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wc-block-order-confirmation-status',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<h1>{ __( 'Order received', 'woocommerce' ) }</h1>\n\t\t\t<p>\n\t\t\t\t{ __(\n\t\t\t\t\t'Thank you. Your order has been received.',\n\t\t\t\t\t'woocommerce'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t</div>\n\t);\n};\n\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 taxonomy, show counts, display style, and 3 more options" }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/taxonomy-filter/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"name\": \"woocommerce/product-filter-taxonomy\",\n\t\"title\": \"Taxonomy Filter\",\n\t\"description\": \"Enable customers to filter the product collection by selecting one or more taxonomy terms, such as categories, brands, or tags.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"ancestor\": [ \"woocommerce/product-filters\" ],\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"text\": false\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": false\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"blockGap\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false,\n\t\t\t\t\"blockGap\": false\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": false,\n\t\t\t\t\"radius\": false,\n\t\t\t\t\"style\": false,\n\t\t\t\t\"width\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"usesContext\": [ \"query\", \"filterParams\" ],\n\t\"attributes\": {\n\t\t\"taxonomy\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"product_cat\"\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\"displayStyle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"woocommerce/product-filter-checkbox-list\"\n\t\t},\n\t\t\"isPreview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"sortOrder\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"count-desc\"\n\t\t},\n\t\t\"hideEmpty\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"isPreview\": true\n\t\t}\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/taxonomy-filter/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tBlockContextProvider,\n} from '@wordpress/block-editor';\nimport { withSpokenMessages } from '@wordpress/components';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useCollectionData } from '@woocommerce/base-context/hooks';\nimport { objectHasProp } from '@woocommerce/types';\n\n/**\n * Internal dependencies\n */\nimport { TaxonomyFilterInspectorControls } from './inspector';\nimport { termOptionsPreview } from './constants';\nimport { EditProps } from './types';\nimport { getAllowedBlocks } from '../../utils/get-allowed-blocks';\nimport { EXCLUDED_BLOCKS } from '../../constants';\nimport type { FilterOptionItem } from '../../types';\nimport { InitialDisabled } from '../../components/initial-disabled';\nimport { Notice } from '../../components/notice';\nimport { getTaxonomyLabel } from './utils';\nimport { sortFilterOptions } from '../../utils/sort-filter-options';\n\n// Create hierarchical structure: parents followed by their children\nfunction createHierarchicalList(\n\tterms: FilterOptionItem[],\n\tsortOrder: string\n) {\n\tconst children = new Map();\n\n\t// First: categorize terms\n\tterms.forEach( ( term ) => {\n\t\tif ( ! children.has( term.parent ) ) {\n\t\t\tchildren.set( term.parent, [] );\n\t\t}\n\t\tchildren.get( term.parent ).push( term );\n\t} );\n\n\t// Next: sort them\n\tchildren.keys().forEach( ( key ) => {\n\t\tchildren.set(\n\t\t\tkey,\n\t\t\tsortFilterOptions( children.get( key ), sortOrder )\n\t\t);\n\t} );\n\n\t// Last: build hierarchical list\n\tconst result: FilterOptionItem[] = [];\n\tfunction addTermsRecursively(\n\t\ttermList: FilterOptionItem[],\n\t\tdepth = 0,\n\t\tvisited = new Set< number >()\n\t) {\n\t\tif ( depth > 10 ) {\n\t\t\treturn;\n\t\t}\n\t\ttermList.forEach( ( term ) => {\n\t\t\tif ( ! term.id || visited.has( term.id ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tvisited.add( term.id );\n\t\t\tresult.push( { ...term, depth } );\n\t\t\tconst termChildren = children.get( term.id ) || [];\n\t\t\tif ( termChildren.length > 0 ) {\n\t\t\t\taddTermsRecursively( termChildren, depth + 1, visited );\n\t\t\t}\n\t\t} );\n\t}\n\n\taddTermsRecursively( children.get( 0 ) );\n\treturn result;\n}\n\nconst Edit = ( props: EditProps ) => {\n\tconst { attributes: blockAttributes } = props;\n\n\tconst {\n\t\ttaxonomy,\n\t\tisPreview,\n\t\tdisplayStyle,\n\t\tshowCounts,\n\t\tsortOrder,\n\t\thideEmpty,\n\t} = blockAttributes;\n\n\tconst [ termOptions, setTermOptions ] = useState< FilterOptionItem[] >(\n\t\tisPreview\n\t\t\t? sortFilterOptions( [ ...termOptionsPreview ], sortOrder )\n\t\t\t: []\n\t);\n\tconst [ isOptionsLoading, setIsOptionsLoading ] = useState< boolean >(\n\t\t! isPreview\n\t);\n\n\t// Fetch taxonomy terms using WordPress core data\n\tconst { taxonomyTerms, isTermsLoading } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( isPreview || ! taxonomy ) {\n\t\t\t\treturn { taxonomyTerms: [], isTermsLoading: false };\n\t\t\t}\n\n\t\t\tconst { getEntityRecords, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\n\t\t\tconst selectArgs = {\n\t\t\t\tper_page: 15,\n\t\t\t\thide_empty: hideEmpty,\n\t\t\t\torderby: 'name',\n\t\t\t\torder: 'asc',\n\t\t\t};\n\t\t\treturn {\n\t\t\t\ttaxonomyTerms:\n\t\t\t\t\tgetEntityRecords( 'taxonomy', taxonomy, selectArgs ) || [],\n\t\t\t\tisTermsLoading: ! hasFinishedResolution( 'getEntityRecords', [\n\t\t\t\t\t'taxonomy',\n\t\t\t\t\ttaxonomy,\n\t\t\t\t\tselectArgs,\n\t\t\t\t] ),\n\t\t\t};\n\t\t},\n\t\t[ taxonomy, hideEmpty, isPreview ]\n\t);\n\n\t// Fetch taxonomy counts using the updated useCollectionData hook\n\tconst { data: filteredCounts, isLoading: isFilterCountsLoading } =\n\t\tuseCollectionData( {\n\t\t\tqueryTaxonomy: isPreview ? undefined : taxonomy,\n\t\t\tqueryState: {},\n\t\t\tisEditor: true,\n\t\t} );\n\n\tuseEffect( () => {\n\t\tif ( isPreview ) {\n\t\t\t// In preview mode, use the preview data directly\n\t\t\tsetTermOptions(\n\t\t\t\tsortFilterOptions( [ ...termOptionsPreview ], sortOrder )\n\t\t\t);\n\t\t\tsetIsOptionsLoading( false );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isTermsLoading || isFilterCountsLoading ) {\n\t\t\tsetIsOptionsLoading( true );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! taxonomyTerms.length ) {\n\t\t\tsetTermOptions( [] );\n\t\t\tsetIsOptionsLoading( false );\n\t\t\treturn;\n\t\t}\n\n\t\t// Get taxonomy counts from the API response\n\t\tconst taxonomyCounts =\n\t\t\tobjectHasProp( filteredCounts, 'taxonomy_counts' ) &&\n\t\t\tArray.isArray( filteredCounts.taxonomy_counts )\n\t\t\t\t? filteredCounts.taxonomy_counts\n\t\t\t\t: [];\n\n\t\t// Process the terms\n\t\tconst processedTerms = taxonomyTerms.reduce(\n\t\t\t( acc: FilterOptionItem[], term ) => {\n\t\t\t\tconst count =\n\t\t\t\t\ttaxonomyCounts.find( ( item ) => item.term === term.id )\n\t\t\t\t\t\t?.count || 0;\n\n\t\t\t\t// If hideEmpty is true and count is 0, exclude this term\n\t\t\t\tif ( hideEmpty && count === 0 ) {\n\t\t\t\t\treturn acc;\n\t\t\t\t}\n\n\t\t\t\tacc.push( {\n\t\t\t\t\tlabel: term.name,\n\t\t\t\t\tvalue: term.slug,\n\t\t\t\t\tselected: false,\n\t\t\t\t\tcount,\n\t\t\t\t\tid: term.id,\n\t\t\t\t\tparent: term.parent || 0,\n\t\t\t\t} );\n\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t[]\n\t\t);\n\n\t\t// Create hierarchical structure then apply sorting\n\t\tconst hierarchicalTerms = createHierarchicalList(\n\t\t\tprocessedTerms,\n\t\t\tsortOrder\n\t\t);\n\t\tsetTermOptions( hierarchicalTerms );\n\t\tsetIsOptionsLoading( false );\n\t}, [\n\t\ttaxonomy,\n\t\ttaxonomyTerms,\n\t\tfilteredCounts,\n\t\tsortOrder,\n\t\thideEmpty,\n\t\tisPreview,\n\t\tisTermsLoading,\n\t\tisFilterCountsLoading,\n\t] );\n\n\tconst { children, ...innerBlocksProps } = useInnerBlocksProps(\n\t\tuseBlockProps(),\n\t\t{\n\t\t\tallowedBlocks: getAllowedBlocks( EXCLUDED_BLOCKS ),\n\t\t\ttemplate: [\n\t\t\t\t[\n\t\t\t\t\t'core/heading',\n\t\t\t\t\t{\n\t\t\t\t\t\tlevel: 3,\n\t\t\t\t\t\tcontent: getTaxonomyLabel( taxonomy ),\n\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\tspacing: {\n\t\t\t\t\t\t\t\tmargin: {\n\t\t\t\t\t\t\t\t\tbottom: '0.625rem',\n\t\t\t\t\t\t\t\t\ttop: '0',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\t[ displayStyle ],\n\t\t\t],\n\t\t}\n\t);\n\n\tconst isLoading = isPreview\n\t\t? false\n\t\t: isTermsLoading || isFilterCountsLoading || isOptionsLoading;\n\n\tif ( ! taxonomy )\n\t\treturn (\n\t\t\t<div { ...innerBlocksProps }>\n\t\t\t\t<TaxonomyFilterInspectorControls { ...props } />\n\t\t\t\t<Notice>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Please select a taxonomy to use this filter!',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t</Notice>\n\t\t\t</div>\n\t\t);\n\n\tif ( ! isLoading && ! isPreview && taxonomyTerms.length === 0 )\n\t\treturn (\n\t\t\t<div { ...innerBlocksProps }>\n\t\t\t\t<TaxonomyFilterInspectorControls { ...props } />\n\t\t\t\t<Notice>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t// translators: %s: Taxonomy label.\n\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t'There are no products associated with %s.',\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\tgetTaxonomyLabel( taxonomy )\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t</Notice>\n\t\t\t</div>\n\t\t);\n\n\treturn (\n\t\t<div { ...innerBlocksProps }>\n\t\t\t<TaxonomyFilterInspectorControls { ...props } />\n\t\t\t<InitialDisabled>\n\t\t\t\t<BlockContextProvider\n\t\t\t\t\tvalue={ {\n\t\t\t\t\t\tfilterData: {\n\t\t\t\t\t\t\titems:\n\t\t\t\t\t\t\t\ttermOptions.length === 0 && isPreview\n\t\t\t\t\t\t\t\t\t? termOptionsPreview\n\t\t\t\t\t\t\t\t\t: termOptions,\n\t\t\t\t\t\t\tisLoading,\n\t\t\t\t\t\t\tshowCounts,\n\t\t\t\t\t\t},\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ children }\n\t\t\t\t</BlockContextProvider>\n\t\t\t</InitialDisabled>\n\t\t</div>\n\t);\n};\n\nexport default withSpokenMessages( Edit );\n" } ]
[ { "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 grow block with customizable email placeholder, consent text, interests, and 6 more options" }, { "role": "assistant", "content": "// File: projects/plugins/jetpack/extensions/blocks/mailchimp/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/mailchimp\",\n\t\"title\": \"Mailchimp\",\n\t\"description\": \"Allow readers to join a Mailchimp audience.\",\n\t\"keywords\": [ \"email\", \"subscription\", \"newsletter\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='m16.88,11.25c.17-.02.34-.02.49,0,.09-.2.1-.55.02-.93-.12-.57-.28-.91-.61-.86-.33.05-.34.46-.22,1.03.07.32.19.59.32.76'/><path d='m14.03,11.7c.24.1.38.17.44.11.04-.04.03-.11-.03-.2-.12-.19-.36-.38-.61-.49-.52-.22-1.14-.15-1.62.19-.16.12-.31.28-.29.37,0,.03.03.06.09.06.13.01.59-.22,1.11-.25.37-.02.68.09.92.2'/><path d='m13.56,11.97c-.31.05-.48.15-.59.25-.09.08-.15.17-.15.23,0,.03.01.05.02.06.01.01.03.02.05.02.07,0,.23-.06.23-.06.43-.15.71-.13.99-.1.16.02.23.03.26-.03.01-.02.02-.05,0-.1-.07-.12-.38-.32-.81-.26'/><path d='m15.92,12.97c.21.1.44.06.52-.09s-.03-.36-.24-.46c-.21-.1-.44-.06-.52.09-.08.15.03.36.24.46'/><path d='m17.26,11.79c-.17,0-.31.18-.32.42s.13.42.3.43.31-.18.32-.42c0-.23-.13-.42-.3-.43'/><path d='m5.83,16c-.04-.05-.11-.04-.18-.02-.05.01-.1.02-.16.02-.13,0-.23-.06-.29-.15-.08-.12-.07-.3.01-.5l.04-.09c.14-.31.36-.82.11-1.31-.19-.37-.51-.6-.89-.64-.36-.05-.74.09-.98.35-.38.42-.44.98-.36,1.18.03.07.07.09.1.1.06,0,.16-.04.22-.2l.02-.05c.03-.08.08-.24.16-.37.1-.15.25-.26.43-.29.18-.04.37,0,.52.1.26.17.37.5.25.8-.06.16-.15.46-.13.72.04.51.35.71.63.73.27.01.46-.14.51-.25.03-.07,0-.11-.01-.12'/><path d='m8.42,6.69c.89-1.03,1.98-1.92,2.96-2.42.03-.02.07.02.05.05-.08.14-.23.44-.28.67,0,.04.03.06.06.04.61-.42,1.67-.86,2.6-.92.04,0,.06.05.03.07-.14.11-.3.26-.41.41-.02.03,0,.06.03.06.65,0,1.57.23,2.17.57.04.02.01.1-.03.09-.91-.21-2.4-.37-3.94.01-1.38.34-2.43.86-3.2,1.41-.04.03-.09-.02-.05-.06h0Zm4.43,9.95h0s0,0,0,0h0Zm3.67.43s.04-.04.04-.07c0-.04-.04-.06-.07-.06,0,0-1.9.28-3.69-.38.2-.63.71-.41,1.5-.34,1.41.08,2.68-.12,3.62-.39.81-.23,1.88-.69,2.71-1.35.28.61.38,1.29.38,1.29,0,0,.22-.04.4.07.17.11.3.32.21.89-.17,1.05-.62,1.91-1.38,2.7-.46.49-1.02.92-1.65,1.24-.34.18-.7.33-1.08.46-2.84.93-5.75-.09-6.69-2.28-.07-.16-.14-.34-.19-.52-.4-1.44-.06-3.17,1-4.27h0c.07-.07.13-.15.13-.25,0-.09-.05-.18-.1-.24-.37-.54-1.66-1.45-1.4-3.23.19-1.27,1.3-2.17,2.34-2.12l.26.02c.45.03.84.08,1.21.1.62.03,1.18-.06,1.84-.61.22-.19.4-.35.7-.4.03,0,.11-.03.27-.03.16,0,.31.05.45.14.53.35.6,1.21.63,1.83.02.36.06,1.22.07,1.47.03.57.18.65.48.75.17.06.33.1.56.16.7.2,1.12.4,1.38.65.16.16.23.33.25.49.08.6-.47,1.35-1.93,2.03-1.59.74-3.53.93-4.87.78l-.47-.05c-1.07-.14-1.68,1.24-1.04,2.18.41.61,1.54,1.01,2.67,1.01,2.58,0,4.57-1.1,5.31-2.06l.06-.08c.04-.05,0-.08-.04-.05-.6.41-3.28,2.05-6.15,1.56,0,0-.35-.06-.67-.18-.25-.1-.78-.34-.85-.88,2.31.72,3.77.04,3.77.04h0ZM3.8,11.57c-.8.16-1.51.61-1.95,1.24-.26-.22-.74-.63-.83-.8-.69-1.31.76-3.87,1.77-5.32C5.3,3.13,9.21.43,11.02.92c.29.08,1.27,1.21,1.27,1.21,0,0-1.81,1.01-3.49,2.41-2.26,1.74-3.97,4.28-5,7.03h0Zm1.35,6.03c-.12.02-.25.03-.37.03-1.21-.03-2.52-1.12-2.65-2.42-.14-1.43.59-2.53,1.88-2.79.15-.03.34-.05.54-.04.72.04,1.79.6,2.04,2.17.22,1.4-.13,2.82-1.44,3.04h0Zm16.4-2.53s-.08-.28-.17-.58c-.09-.3-.19-.51-.19-.51.37-.56.38-1.06.33-1.34-.05-.35-.2-.65-.49-.96-.29-.31-.89-.62-1.74-.86l-.44-.12s-.02-1.04-.04-1.48c-.01-.32-.04-.82-.2-1.31-.18-.66-.5-1.24-.9-1.61,1.1-1.14,1.79-2.4,1.79-3.48,0-2.08-2.56-2.71-5.7-1.4l-.67.28s-1.2-1.18-1.22-1.2C8.33-2.63-2.89,9.84.7,12.86l.78.66c-.2.53-.28,1.13-.22,1.78.08.83.51,1.63,1.21,2.25.66.59,1.53.96,2.37.96,1.4,3.21,4.58,5.19,8.32,5.3,4.01.12,7.37-1.76,8.78-5.14.09-.24.48-1.31.48-2.25s-.54-1.34-.88-1.34'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"color\": {\n\t\t\t\"gradients\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"emailPlaceholder\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"consentText\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"interests\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t},\n\t\t\"processingLabel\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"signupFieldTag\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"signupFieldValue\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"successLabel\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"errorLabel\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"preview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"preview\": true\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\": \"button\",\n\t\t\t\t\t\"text\": \"Join my Mailchimp audience\",\n\t\t\t\t\t\"uniqueId\": \"mailchimp-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/mailchimp/edit.js\nimport {\n\tisCurrentUserConnected,\n\tgetBlockIconComponent,\n} from '@automattic/jetpack-shared-extension-utils';\nimport apiFetch from '@wordpress/api-fetch';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { withNotices } from '@wordpress/components';\nimport { useCallback, useEffect, useState } from '@wordpress/element';\nimport { addQueryArgs } from '@wordpress/url';\nimport metadata from './block.json';\nimport Body from './body';\nimport { API_STATE_CONNECTED, API_STATE_NOTCONNECTED, API_STATE_LOADING } from './constants';\nimport { MailChimpInspectorControls } from './controls';\nimport Loader from './loader';\nimport { UserConnectedPlaceholder, UserNotConnectedPlaceholder } from './placeholders';\n\nconst icon = getBlockIconComponent( metadata );\n\nexport const MailchimpSubscribeEdit = ( {\n\tattributes,\n\tsetAttributes,\n\tnotices,\n\tnoticeUI,\n\tnoticeOperations,\n} ) => {\n\tconst blockProps = useBlockProps();\n\n\tconst [ audition, setAudition ] = useState( null );\n\tconst [ connected, setConnected ] = useState( API_STATE_LOADING );\n\tconst [ connectURL, setConnectURL ] = useState( null );\n\tconst [ currentUserConnected, setCurrentUserconnected ] = useState( null );\n\n\tconst apiCall = useCallback( () => {\n\t\tconst isUserConnected = isCurrentUserConnected();\n\n\t\tif ( isUserConnected ) {\n\t\t\tapiFetch( { path: '/wpcom/v2/mailchimp', method: 'GET' } ).then(\n\t\t\t\t( { connect_url: url, code } ) => {\n\t\t\t\t\tsetConnectURL( url );\n\t\t\t\t\tsetConnected( code === 'connected' ? API_STATE_CONNECTED : API_STATE_NOTCONNECTED );\n\t\t\t\t\tsetCurrentUserconnected( isUserConnected );\n\t\t\t\t},\n\t\t\t\t( { message } ) => {\n\t\t\t\t\tsetConnectURL( null );\n\t\t\t\t\tsetConnected( API_STATE_NOTCONNECTED );\n\t\t\t\t\tsetCurrentUserconnected( isUserConnected );\n\n\t\t\t\t\tnoticeOperations.removeAllNotices();\n\t\t\t\t\tnoticeOperations.createErrorNotice( message );\n\t\t\t\t}\n\t\t\t);\n\t\t} else {\n\t\t\tapiFetch( {\n\t\t\t\tpath: addQueryArgs( '/jetpack/v4/connection/url', {\n\t\t\t\t\tfrom: 'jetpack-block-editor',\n\t\t\t\t\tredirect: window.location.href,\n\t\t\t\t} ),\n\t\t\t} ).then( url => {\n\t\t\t\tsetConnectURL( url );\n\t\t\t\tsetConnected( API_STATE_NOTCONNECTED );\n\t\t\t\tsetCurrentUserconnected( isUserConnected );\n\t\t\t} );\n\t\t}\n\t}, [ setConnectURL, setConnected, setCurrentUserconnected, noticeOperations ] );\n\n\tuseEffect( () => {\n\t\tapiCall();\n\t}, [ apiCall ] );\n\n\tlet content;\n\n\tif ( attributes.preview ) {\n\t\tcontent = (\n\t\t\t<Body attributes={ attributes } setAttributes={ setAttributes } audition={ audition } />\n\t\t);\n\t} else if ( connected === API_STATE_LOADING ) {\n\t\tcontent = <Loader icon={ icon } notices={ notices } />;\n\t} else if ( connected === API_STATE_NOTCONNECTED ) {\n\t\tif ( currentUserConnected ) {\n\t\t\tcontent = (\n\t\t\t\t<UserConnectedPlaceholder\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tnotices={ notices }\n\t\t\t\t\tconnectURL={ connectURL }\n\t\t\t\t\tapiCall={ apiCall }\n\t\t\t\t/>\n\t\t\t);\n\t\t} else {\n\t\t\tcontent = (\n\t\t\t\t<UserNotConnectedPlaceholder icon={ icon } notices={ notices } connectURL={ connectURL } />\n\t\t\t);\n\t\t}\n\t} else if ( connected === API_STATE_CONNECTED ) {\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t<MailChimpInspectorControls\n\t\t\t\t\tconnectURL={ connectURL }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tsetAudition={ setAudition }\n\t\t\t\t/>\n\t\t\t\t<Body attributes={ attributes } setAttributes={ setAttributes } audition={ audition } />\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ noticeUI }\n\t\t\t{ content }\n\t\t</div>\n\t);\n};\n\nexport default withNotices( MailchimpSubscribeEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/mailchimp/save.js\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nexport default () => {\n\tconst blockProps = useBlockProps.save();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Craft a Gutenberg block for blog post newsletter subscription, incorporating customizable features like placeholder text, subscriber count display, social follower integration, and 26 additional configuration options." }, { "role": "assistant", "content": "// File: projects/plugins/jetpack/extensions/blocks/subscriptions/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/subscriptions\",\n\t\"title\": \"Subscribe\",\n\t\"description\": \"Subscribe to this blog's posts as a newsletter.\",\n\t\"keywords\": [ \"newsletter\", \"email\", \"follow\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='m19.02,5H4.98c-1.09,0-1.98.89-1.98,1.98v10.04c0,1.09.89,1.98,1.98,1.98h14.04c1.09,0,1.98-.89,1.98-1.98V6.98c0-1.09-.89-1.98-1.98-1.98Zm.48,11.92c0,.32-.26.58-.58.58H5.08c-.32,0-.58-.26-.58-.58V7.08c0-.32.26-.58.58-.58h13.84c.32,0,.58.26.58.58v9.84Z'/><path d='m4.38,17.69l5.71-4.79s.96,1,1.91.99,1.91-.99,1.91-.99l5.59,4.79v-2.03l-4.41-3.73,4.41-3.72v-1.91l-7.14,5.76c-.24.19-.59.19-.83,0l-7.14-5.88v1.98l4.3,3.67-4.3,3.78v2.08Z'/></svg>\",\n\t\"supports\": {\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"align\": [ \"wide\", \"full\" ]\n\t},\n\t\"styles\": [\n\t\t{\n\t\t\t\"name\": \"split\",\n\t\t\t\"label\": \"Split\",\n\t\t\t\"isDefault\": true\n\t\t},\n\t\t{\n\t\t\t\"name\": \"compact\",\n\t\t\t\"label\": \"Compact\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"button\",\n\t\t\t\"label\": \"Button only\"\n\t\t}\n\t],\n\t\"attributes\": {\n\t\t\"subscribePlaceholder\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"showSubscribersTotal\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"includeSocialFollowers\": {\n\t\t\t\"type\": \"boolean\"\n\t\t},\n\t\t\"buttonOnNewLine\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"buttonWidth\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"submitButtonText\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"emailFieldBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customEmailFieldBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"emailFieldGradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customEmailFieldGradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"buttonBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customButtonBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"buttonGradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customButtonGradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"textColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customTextColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"fontSize\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customFontSize\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"borderRadius\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"borderWeight\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"borderColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customBorderColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"padding\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"successMessage\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"Success! An email was just sent to confirm your subscription. Please find the email now and click 'Confirm' to start subscribing.\"\n\t\t},\n\t\t\"appSource\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"className\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"preselectNewsletterCategories\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"selectedNewsletterCategoryIds\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t}\n\t},\n\t\"example\": {}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/subscriptions/edit.js\nimport { ThemeProvider } from '@automattic/jetpack-components';\nimport { formatNumberCompact } from '@automattic/number-formatters';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tRichText,\n\twithColors,\n\twithFontSizes,\n\tuseBlockProps,\n\t__experimentalUseGradient as useGradient, // eslint-disable-line @wordpress/no-unsafe-wp-apis\n} from '@wordpress/block-editor';\nimport {\n\tTextControl,\n\twithFallbackStyles,\n\tToolbarGroup,\n\tToolbarButton,\n} from '@wordpress/components';\nimport { compose, usePrevious } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\nimport { _n, sprintf, _x, __ } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport { isEqual } from 'lodash';\nimport { getActiveStyleName } from '../../shared/block-styles';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport { getPaidPlanLink } from '../../shared/memberships/utils';\nimport './view.scss';\nimport './editor.scss';\nimport { store as membershipProductsStore } from '../../store/membership-products';\nimport metadata from './block.json';\nimport {\n\tDEFAULT_BORDER_RADIUS_VALUE,\n\tDEFAULT_BORDER_WEIGHT_VALUE,\n\tDEFAULT_PADDING_VALUE,\n\tDEFAULT_SPACING_VALUE,\n\tDEFAULT_FONTSIZE_VALUE,\n\tDEFAULT_SUBSCRIBE_PLACEHOLDER,\n\tDEFAULT_SUBMIT_BUTTON_LABEL,\n\tDEFAULT_SUCCESS_MESSAGE,\n} from './constants';\nimport SubscriptionControls from './controls';\n\nconst { getComputedStyle } = window;\nconst isGradientAvailable = !! useGradient;\nconst useGradientIfAvailable = isGradientAvailable ? useGradient : () => ( {} );\n\nconst applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {\n\tconst { buttonBackgroundColor, textColor } = ownProps;\n\tconst buttonBackgroundColorValue = buttonBackgroundColor && buttonBackgroundColor.color;\n\tconst textColorValue = textColor && textColor.color;\n\n\tconst buttonNode = node.querySelector( '.wp-block-jetpack-subscriptions__button' );\n\n\treturn {\n\t\tfallbackButtonBackgroundColor:\n\t\t\tbuttonBackgroundColorValue || ! node\n\t\t\t\t? undefined\n\t\t\t\t: buttonNode && getComputedStyle( buttonNode ).backgroundColor,\n\t\tfallbackTextColor:\n\t\t\ttextColorValue || ! node ? undefined : buttonNode && getComputedStyle( buttonNode ).color,\n\t};\n} );\n\nexport function SubscriptionEdit( props ) {\n\tconst {\n\t\tattributes,\n\t\tsetAttributes,\n\t\temailFieldBackgroundColor,\n\t\tbuttonBackgroundColor,\n\t\tsetButtonBackgroundColor,\n\t\tfallbackButtonBackgroundColor,\n\t\ttextColor,\n\t\tfallbackTextColor,\n\t\tsetTextColor,\n\t\tborderColor,\n\t\tsetBorderColor,\n\t\tfontSize,\n\t} = props;\n\tconst hasTierPlans = useSelect(\n\t\tselect => !! select( 'jetpack/membership-products' )?.getNewsletterTierProducts()?.length,\n\t\t[]\n\t);\n\tconst blockProps = useBlockProps();\n\tconst validatedAttributes = getValidatedAttributes( metadata.attributes, attributes );\n\tif ( ! isEqual( validatedAttributes, attributes ) ) {\n\t\tsetAttributes( validatedAttributes );\n\t}\n\n\tconst {\n\t\tborderRadius,\n\t\tborderWeight,\n\t\tbuttonWidth,\n\t\tclassName,\n\t\tincludeSocialFollowers,\n\t\tpadding,\n\t\tpreselectNewsletterCategories,\n\t\tselectedNewsletterCategoryIds,\n\t\tspacing,\n\t\tsubmitButtonText = DEFAULT_SUBMIT_BUTTON_LABEL,\n\t\tsubscribePlaceholder = DEFAULT_SUBSCRIBE_PLACEHOLDER,\n\t\tshowSubscribersTotal,\n\t\tbuttonOnNewLine,\n\t\tsuccessMessage = DEFAULT_SUCCESS_MESSAGE,\n\t} = validatedAttributes;\n\n\tconst activeStyleName = getActiveStyleName( metadata.styles, className );\n\n\tconst { subscriberCount, subscriberCountString } = useSelect( select => {\n\t\tconst { totalSubscribers, socialFollowers } =\n\t\t\tselect( membershipProductsStore ).getSubscriberCounts();\n\t\tlet count = totalSubscribers;\n\t\tif ( includeSocialFollowers ) {\n\t\t\tcount += socialFollowers;\n\t\t}\n\n\t\treturn {\n\t\t\tsubscriberCount: count,\n\t\t\tsubscriberCountString: sprintf(\n\t\t\t\t/* translators: %s: the number of subscribers. */\n\t\t\t\t_n( 'Join %s other subscriber', 'Join %s other subscribers', count, 'jetpack' ),\n\t\t\t\tformatNumberCompact( count, { numberFormatOptions: { maximumFractionDigits: 1 } } )\n\t\t\t),\n\t\t};\n\t} );\n\n\tconst { availableNewsletterCategories, areNewsletterCategoriesEnabled } = useSelect( select => {\n\t\tconst store = select( membershipProductsStore );\n\n\t\treturn {\n\t\t\tavailableNewsletterCategories: store.getNewsletterCategories(),\n\t\t\tareNewsletterCategoriesEnabled: store.getNewsletterCategoriesEnabled(),\n\t\t};\n\t} );\n\n\tconst emailFieldGradient = useGradientIfAvailable( {\n\t\tgradientAttribute: 'emailFieldGradient',\n\t\tcustomGradientAttribute: 'customEmailFieldGradient',\n\t} );\n\tconst buttonGradient = useGradientIfAvailable( {\n\t\tgradientAttribute: 'buttonGradient',\n\t\tcustomGradientAttribute: 'customButtonGradient',\n\t} );\n\n\tconst sharedClasses = {\n\t\t'no-border-radius': borderRadius === 0,\n\t\t[ fontSize.class ]: fontSize.class,\n\t\t'has-text-color': textColor.color,\n\t\t[ textColor.class ]: textColor.class,\n\t};\n\n\tconst emailFieldClasses = {\n\t\t...sharedClasses,\n\t\t'has-background': emailFieldBackgroundColor.color || emailFieldGradient.gradientValue,\n\t\t[ emailFieldBackgroundColor.class ]:\n\t\t\t! emailFieldGradient.gradientValue && emailFieldBackgroundColor.class,\n\t\t[ emailFieldGradient.gradientClass ]: emailFieldGradient.gradientClass,\n\t};\n\n\tconst buttonClasses = {\n\t\t...sharedClasses,\n\t\t'has-background': buttonBackgroundColor.color || buttonGradient.gradientValue,\n\t\t[ buttonBackgroundColor.class ]: ! buttonGradient.gradientValue && buttonBackgroundColor.class,\n\t\t[ buttonGradient.gradientClass ]: buttonGradient.gradientClass,\n\t};\n\n\tconst getPaddingStyleValue = paddingValue => {\n\t\tconst value = paddingValue ? paddingValue : DEFAULT_PADDING_VALUE;\n\n\t\treturn (\n\t\t\tvalue +\n\t\t\t'px ' +\n\t\t\tMath.round( value * 1.5 ) +\n\t\t\t'px ' +\n\t\t\tvalue +\n\t\t\t'px ' +\n\t\t\tMath.round( value * 1.5 ) +\n\t\t\t'px'\n\t\t);\n\t};\n\n\tconst getSpacingStyleValue = spacingValue => {\n\t\treturn spacingValue ? spacingValue : DEFAULT_SPACING_VALUE;\n\t};\n\n\tconst sharedStyles = {\n\t\tcolor: textColor.color,\n\t\tborderColor: borderColor.color,\n\t\tborderRadius: borderRadius ? borderRadius + 'px' : DEFAULT_BORDER_RADIUS_VALUE + 'px',\n\t\tborderWidth: borderWeight ? borderWeight + 'px' : DEFAULT_BORDER_WEIGHT_VALUE + 'px',\n\t\tfontSize: fontSize.size ? fontSize.size : DEFAULT_FONTSIZE_VALUE,\n\t\tpadding: getPaddingStyleValue( padding ),\n\t};\n\n\tconst cssVars = {\n\t\t'--subscribe-block-border-radius': borderRadius\n\t\t\t? borderRadius + 'px'\n\t\t\t: DEFAULT_BORDER_RADIUS_VALUE + 'px',\n\t};\n\n\tconst emailFieldStyles = {\n\t\t...sharedStyles,\n\t\t...( ! emailFieldBackgroundColor.color && emailFieldGradient.gradientValue\n\t\t\t? { background: emailFieldGradient.gradientValue }\n\t\t\t: { backgroundColor: emailFieldBackgroundColor.color } ),\n\t};\n\n\tconst buttonStyles = {\n\t\t...sharedStyles,\n\t\t...( ! buttonBackgroundColor.color && buttonGradient.gradientValue\n\t\t\t? { background: buttonGradient.gradientValue }\n\t\t\t: { backgroundColor: buttonBackgroundColor.color } ),\n\t\twidth: buttonWidth?.length ? buttonWidth : 'auto',\n\t};\n\n\tif ( activeStyleName !== 'button' ) {\n\t\tif ( buttonOnNewLine ) {\n\t\t\tbuttonStyles.marginTop = getSpacingStyleValue( spacing ) + 'px';\n\t\t} else {\n\t\t\tbuttonStyles.marginLeft = getSpacingStyleValue( spacing ) + 'px';\n\t\t}\n\t}\n\n\tconst previousButtonBackgroundColor = usePrevious( buttonBackgroundColor );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\tpreviousButtonBackgroundColor?.color !== borderColor?.color ||\n\t\t\tborderColor?.color === buttonBackgroundColor?.color\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tsetBorderColor( buttonBackgroundColor.color );\n\t}, [ buttonBackgroundColor, previousButtonBackgroundColor, borderColor, setBorderColor ] );\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\tclassName={ clsx(\n\t\t\t\tblockProps.className,\n\t\t\t\t'wp-block-jetpack-subscriptions__container',\n\t\t\t\t'wp-block-jetpack-subscriptions__supports-newline',\n\t\t\t\tbuttonOnNewLine ? 'wp-block-jetpack-subscriptions__use-newline' : undefined,\n\t\t\t\tshowSubscribersTotal ? 'wp-block-jetpack-subscriptions__show-subs' : undefined\n\t\t\t) }\n\t\t>\n\t\t\t<InspectorControls>\n\t\t\t\t<SubscriptionControls\n\t\t\t\t\tareNewsletterCategoriesEnabled={ areNewsletterCategoriesEnabled }\n\t\t\t\t\tavailableNewsletterCategories={ availableNewsletterCategories }\n\t\t\t\t\tbuttonBackgroundColor={ buttonBackgroundColor }\n\t\t\t\t\tborderColor={ borderColor }\n\t\t\t\t\tbuttonGradient={ buttonGradient }\n\t\t\t\t\tborderRadius={ borderRadius }\n\t\t\t\t\tborderWeight={ borderWeight }\n\t\t\t\t\tbuttonOnNewLine={ buttonOnNewLine }\n\t\t\t\t\temailFieldBackgroundColor={ emailFieldBackgroundColor }\n\t\t\t\t\tfallbackButtonBackgroundColor={ fallbackButtonBackgroundColor }\n\t\t\t\t\tfallbackTextColor={ fallbackTextColor }\n\t\t\t\t\tfontSize={ fontSize }\n\t\t\t\t\tincludeSocialFollowers={ includeSocialFollowers }\n\t\t\t\t\tisGradientAvailable={ isGradientAvailable }\n\t\t\t\t\tpadding={ padding }\n\t\t\t\t\tpreselectNewsletterCategories={ preselectNewsletterCategories }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tsetBorderColor={ setBorderColor }\n\t\t\t\t\tsetButtonBackgroundColor={ setButtonBackgroundColor }\n\t\t\t\t\tsetTextColor={ setTextColor }\n\t\t\t\t\tshowSubscribersTotal={ showSubscribersTotal }\n\t\t\t\t\tspacing={ spacing }\n\t\t\t\t\tsubscriberCount={ subscriberCount }\n\t\t\t\t\ttextColor={ textColor }\n\t\t\t\t\tbuttonWidth={ buttonWidth }\n\t\t\t\t\tselectedNewsletterCategoryIds={ selectedNewsletterCategoryIds }\n\t\t\t\t\tsubscribePlaceholder={ subscribePlaceholder }\n\t\t\t\t\tsubmitButtonText={ submitButtonText }\n\t\t\t\t\tsuccessMessage={ successMessage }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t<ToolbarButton href={ getPaidPlanLink( hasTierPlans ) } target=\"_blank\">\n\t\t\t\t\t\t{ hasTierPlans\n\t\t\t\t\t\t\t? _x( 'Manage plans', 'unused context to distinguish translations', 'jetpack' )\n\t\t\t\t\t\t\t: __( 'Set up a paid plan', 'jetpack' ) }\n\t\t\t\t\t</ToolbarButton>\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t<div style={ cssVars }>\n\t\t\t\t<div className=\"wp-block-jetpack-subscriptions__container is-not-subscriber\">\n\t\t\t\t\t<div className=\"wp-block-jetpack-subscriptions__form\" role=\"form\">\n\t\t\t\t\t\t<div className=\"wp-block-jetpack-subscriptions__form-elements\">\n\t\t\t\t\t\t\t{ activeStyleName !== 'button' && (\n\t\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t\tplaceholder={ subscribePlaceholder }\n\t\t\t\t\t\t\t\t\tdisabled={ true }\n\t\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t\temailFieldClasses,\n\t\t\t\t\t\t\t\t\t\t'wp-block-jetpack-subscriptions__textfield'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\tstyle={ emailFieldStyles }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\tbuttonClasses,\n\t\t\t\t\t\t\t\t\t'wp-block-jetpack-subscriptions__button',\n\t\t\t\t\t\t\t\t\t'wp-block-button__link'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tonChange={ value => setAttributes( { submitButtonText: value } ) }\n\t\t\t\t\t\t\t\tstyle={ buttonStyles }\n\t\t\t\t\t\t\t\tvalue={ submitButtonText }\n\t\t\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\t\t\tallowedFormats={ [ 'core/bold', 'core/italic', 'core/strikethrough' ] }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t{ showSubscribersTotal && (\n\t\t\t\t\t<div className=\"wp-block-jetpack-subscriptions__subscount\">{ subscriberCountString }</div>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nconst withThemeProvider = WrappedComponent => props => (\n\t<ThemeProvider>\n\t\t<WrappedComponent { ...props } />\n\t</ThemeProvider>\n);\n\nexport default compose( [\n\twithColors(\n\t\t{ emailFieldBackgroundColor: 'backgroundColor' },\n\t\t{ buttonBackgroundColor: 'backgroundColor' },\n\t\t{ textColor: 'color' },\n\t\t'borderColor'\n\t),\n\twithFontSizes( 'fontSize' ),\n\tapplyFallbackStyles,\n\twithThemeProvider,\n] )( SubscriptionEdit );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Displays the date on which the review was posted. with these attributes: format, is link" }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-date/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-review-date\",\n\t\"title\": \"Review Date\",\n\t\"category\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/product-reviews\" ],\n\t\"description\": \"Displays the date on which the review was posted.\",\n\t\"textdomain\": \"woocommerce\",\n\t\"attributes\": {\n\t\t\"format\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"isLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"usesContext\": [ \"commentId\" ],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-date/edit.tsx\n/**\n * External dependencies\n */\nimport { useEntityProp } from '@wordpress/core-data';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport {\n\tdateI18n,\n\thumanTimeDiff,\n\tgetSettings as getDateSettings,\n} from '@wordpress/date';\nimport { PanelBody, ToggleControl } from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport {\n\tInspectorControls,\n\tuseBlockProps,\n\t// @ts-expect-error - Experimental component\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalDateFormatPicker as DateFormatPicker,\n} from '@wordpress/block-editor';\n\nexport default function Edit( {\n\tattributes: { format, isLink },\n\tcontext: { commentId },\n\tsetAttributes,\n}: BlockEditProps< {\n\tformat: string;\n\tisLink: boolean;\n} > & {\n\tcontext: { commentId: number };\n} ) {\n\tconst blockProps = useBlockProps();\n\n\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t// @ts-expect-error - the type of useEntityProp is not correct\n\tlet [ date ] = useEntityProp( 'root', 'comment', 'date', commentId );\n\tconst [ siteFormat = getDateSettings().formats.date ] = useEntityProp(\n\t\t'root',\n\t\t'site',\n\t\t'date_format'\n\t);\n\n\tif ( ! commentId || ! date ) {\n\t\tdate = _x( 'Review Date', 'block title', 'woocommerce' );\n\t}\n\n\tlet reviewDate =\n\t\tdate instanceof Date ? (\n\t\t\t<time dateTime={ dateI18n( 'c', date, true ) }>\n\t\t\t\t{ format === 'human-diff'\n\t\t\t\t\t? humanTimeDiff( date, new Date() )\n\t\t\t\t\t: dateI18n( format || siteFormat, date, true ) }\n\t\t\t</time>\n\t\t) : (\n\t\t\t<time>{ date }</time>\n\t\t);\n\n\tif ( isLink ) {\n\t\treviewDate = (\n\t\t\t<a\n\t\t\t\thref=\"#review-date-pseudo-link\"\n\t\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t\t>\n\t\t\t\t{ reviewDate }\n\t\t\t</a>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Settings', 'woocommerce' ) }>\n\t\t\t\t\t<DateFormatPicker\n\t\t\t\t\t\tformat={ format }\n\t\t\t\t\t\tdefaultFormat={ siteFormat }\n\t\t\t\t\t\tonChange={ ( nextFormat: string ) =>\n\t\t\t\t\t\t\tsetAttributes( { format: nextFormat } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Link to review', 'woocommerce' ) }\n\t\t\t\t\t\tonChange={ () => setAttributes( { isLink: ! isLink } ) }\n\t\t\t\t\t\tchecked={ isLink }\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>{ reviewDate }</div>\n\t\t</>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a Gutenberg block utilizing AI technology to convert voice input directly into a publishable post, incorporating a content attribute for seamless text generation." }, { "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/voice-to-content/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/voice-to-content\",\n\t\"title\": \"Voice to content\",\n\t\"description\": \"Transform your spoken words into a post ready to publish with AI.\",\n\t\"keywords\": [ \"AI\", \"GPT\", \"AL\", \"Magic\", \"help\", \"assistant\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"media\",\n\t\"icon\": \"<svg viewBox='0 0 20 20' width='20' height='20' xmlns='http://www.w3.org/2000/svg'><path d='M12 9V3c0-1.1-.89-2-2-2-1.12 0-2 .94-2 2v6c0 1.1.9 2 2 2 1.13 0 2-.94 2-2zm4 0c0 2.97-2.16 5.43-5 5.91V17h2c.56 0 1 .45 1 1s-.44 1-1 1H7c-.55 0-1-.45-1-1s.45-1 1-1h2v-2.09C6.17 14.43 4 11.97 4 9c0-.55.45-1 1-1 .56 0 1 .45 1 1 0 2.21 1.8 4 4 4 2.21 0 4-1.79 4-4 0-.55.45-1 1-1 .56 0 1 .45 1 1z'/></svg>\",\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"multiple\": true,\n\t\t\"reusable\": false\n\t},\n\t\"attributes\": {\n\t\t\"content\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/voice-to-content/edit.tsx\nimport {\n\tuseMediaRecording,\n\tuseAudioValidation,\n\tTRANSCRIPTION_POST_PROCESSING_ACTION_SIMPLE_DRAFT,\n} from '@automattic/jetpack-ai-client';\nimport { ThemeProvider } from '@automattic/jetpack-components';\nimport { useAnalytics } from '@automattic/jetpack-shared-extension-utils';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { type BlockInstance } from '@wordpress/blocks';\nimport { Button, Modal, Icon } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useCallback, useEffect, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { external } from '@wordpress/icons';\nimport ActionButtons from './components/action-buttons';\nimport AudioStatusPanel from './components/audio-status-panel';\nimport useTranscriptionCreator from './hooks/use-transcription-creator';\nimport useTranscriptionInserter from './hooks/use-transcription-inserter';\nimport type {\n\tRecordingState,\n\tTranscriptionState,\n\tValidatedAudioInformation,\n} from '@automattic/jetpack-ai-client';\n\n/**\n * Helper to determine the state of the transcription.\n *\n * @param {boolean} isCreatingTranscription - The transcription creation state\n * @param {boolean} isValidatingAudio - The audio validation state\n * @param {RecordingState} recordingState - The recording state\n * @return {TranscriptionState} - The transcription state\n */\nconst transcriptionStateHelper = (\n\tisCreatingTranscription: boolean,\n\tisValidatingAudio: boolean,\n\trecordingState: RecordingState\n): TranscriptionState => {\n\tif ( isValidatingAudio ) {\n\t\treturn 'validating';\n\t}\n\n\tif ( isCreatingTranscription ) {\n\t\treturn 'processing';\n\t}\n\n\treturn recordingState;\n};\n\nexport default function VoiceToContentEdit( { clientId } ) {\n\tconst [ audio, setAudio ] = useState< Blob >( null );\n\n\tconst { removeBlock } = useDispatch( blockEditorStore );\n\t// TODO: The second `deps` argument shouldn't be needed, but it's added to make the type checker happy.\n\t// This can be removed when the core data types are updated to fix the issue.\n\tconst { getBlocks } = useSelect( blockEditorStore, [] ) as {\n\t\tgetBlocks: () => BlockInstance[];\n\t};\n\n\tconst destroyBlock = useCallback( () => {\n\t\t// Remove the block from the editor\n\t\tsetTimeout( () => {\n\t\t\tremoveBlock( clientId );\n\t\t}, 100 );\n\t}, [ removeBlock, clientId ] );\n\n\t// Track the usage of the feature\n\tconst { tracks } = useAnalytics();\n\n\tconst { isValidatingAudio, validateAudio } = useAudioValidation();\n\n\tconst { upsertTranscription } = useTranscriptionInserter();\n\tconst { isCreatingTranscription, createTranscription, cancelTranscription } =\n\t\tuseTranscriptionCreator( {\n\t\t\tonReady: ( content: string ) => {\n\t\t\t\t// When transcription is ready, insert it into the editor\n\t\t\t\tupsertTranscription( content );\n\n\t\t\t\t// Then check if there is a single empty paragraph block before the transcription and remove it\n\t\t\t\t// This is to ensure the P2 title is correct as it's based on the first block\n\t\t\t\tconst blocks = getBlocks();\n\t\t\t\t// One block is the voice-to-content block itself, so we check the first two blocks\n\t\t\t\tfor ( let i = 0; i < 2; i++ ) {\n\t\t\t\t\tif ( blocks[ i ].name === 'core/paragraph' && blocks[ i ].attributes?.content === '' ) {\n\t\t\t\t\t\tremoveBlock( String( blocks[ i ].clientId ) );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\thandleClose();\n\t\t\t},\n\t\t\tonUpdate: ( content: string ) => {\n\t\t\t\t// When transcription is updated, insert it into the editor\n\t\t\t\tupsertTranscription( content );\n\t\t\t},\n\t\t\tonError: ( error: string ) => {\n\t\t\t\t// When transcription fails, show an error message\n\t\t\t\tonError( error );\n\t\t\t},\n\t\t} );\n\n\tconst handleClose = () => {\n\t\tcancelTranscription();\n\t\tdestroyBlock();\n\t};\n\n\tconst { state, controls, error, onError, duration, analyser } = useMediaRecording( {\n\t\tonDone: lastBlob => {\n\t\t\t// When recording is done, set the audio to be transcribed\n\t\t\tonAudioHandler( lastBlob );\n\t\t},\n\t} );\n\n\tconst onAudioHandler = useCallback(\n\t\t( audioFile: Blob ) => {\n\t\t\tif ( audioFile ) {\n\t\t\t\tsetAudio( audioFile );\n\t\t\t}\n\t\t},\n\t\t[ setAudio ]\n\t);\n\n\t/**\n\t * When the audio changes, create the transcription. In the future,\n\t * we can trigger this action (and others) from a button in the UI.\n\t */\n\tuseEffect( () => {\n\t\tif ( audio ) {\n\t\t\tvalidateAudio(\n\t\t\t\taudio,\n\t\t\t\t( audioInfo: ValidatedAudioInformation ) => {\n\t\t\t\t\t// Track the transcription event\n\t\t\t\t\ttracks.recordEvent( 'jetpack_ai_voice_to_content_transcription_started', {\n\t\t\t\t\t\tpost_processing_action: TRANSCRIPTION_POST_PROCESSING_ACTION_SIMPLE_DRAFT,\n\t\t\t\t\t\ttype: audioInfo.isFile ? 'upload' : 'record',\n\t\t\t\t\t\taudio_duration: audioInfo.duration,\n\t\t\t\t\t\taudio_file_size: audioInfo.size,\n\t\t\t\t\t} );\n\n\t\t\t\t\tcreateTranscription( audio, TRANSCRIPTION_POST_PROCESSING_ACTION_SIMPLE_DRAFT );\n\t\t\t\t},\n\t\t\t\tonError\n\t\t\t);\n\t\t}\n\t}, [ audio, tracks, validateAudio, createTranscription, onError ] );\n\n\t// Destructure controls\n\tconst {\n\t\tstart: controlStart,\n\t\tpause: controlPause,\n\t\tresume: controlResume,\n\t\tstop: controlStop,\n\t\treset: controlReset,\n\t} = controls;\n\n\tconst onUploadHandler = useCallback(\n\t\tevent => {\n\t\t\tif ( event.currentTarget.files.length > 0 ) {\n\t\t\t\tconst file = event.currentTarget.files[ 0 ];\n\t\t\t\tonAudioHandler( file );\n\t\t\t}\n\t\t},\n\t\t[ onAudioHandler ]\n\t);\n\n\tconst onCancelHandler = useCallback( () => {\n\t\tcancelTranscription();\n\t\tcontrolReset();\n\t}, [ cancelTranscription, controlReset ] );\n\n\tconst onRecordHandler = useCallback( () => {\n\t\tcontrolStart( 1000 ); // Stream audio on 1 second intervals\n\t}, [ controlStart ] );\n\n\tconst onPauseHandler = useCallback( () => {\n\t\tcontrolPause();\n\t}, [ controlPause ] );\n\n\tconst onResumeHandler = useCallback( () => {\n\t\tcontrolResume();\n\t}, [ controlResume ] );\n\n\tconst onDoneHandler = useCallback( () => {\n\t\tcontrolStop();\n\t}, [ controlStop ] );\n\n\t// To avoid a wrong TS warning\n\tconst iconProps = { className: 'icon' };\n\n\tconst transcriptionState = transcriptionStateHelper(\n\t\tisCreatingTranscription,\n\t\tisValidatingAudio,\n\t\tstate\n\t);\n\n\treturn (\n\t\t<Modal\n\t\t\tonRequestClose={ handleClose }\n\t\t\ttitle={ __( 'Jetpack AI Voice to content', 'jetpack' ) }\n\t\t\tclassName=\"jetpack-ai-voice-to-content__modal\"\n\t\t\tshouldCloseOnEsc={ false }\n\t\t\tshouldCloseOnClickOutside={ false }\n\t\t>\n\t\t\t<ThemeProvider>\n\t\t\t\t<div className=\"jetpack-ai-voice-to-content__wrapper\">\n\t\t\t\t\t<div className=\"jetpack-ai-voice-to-content__body\">\n\t\t\t\t\t\t<span className=\"jetpack-ai-voice-to-content__description\">\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Transform your spoken words into a post ready to publish with AI.',\n\t\t\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<div className=\"jetpack-ai-voice-to-content__contextual-row\">\n\t\t\t\t\t\t\t<AudioStatusPanel\n\t\t\t\t\t\t\t\tstate={ transcriptionState }\n\t\t\t\t\t\t\t\terror={ error }\n\t\t\t\t\t\t\t\tduration={ duration }\n\t\t\t\t\t\t\t\tanalyser={ analyser }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<ActionButtons\n\t\t\t\t\t\t\tstate={ transcriptionState }\n\t\t\t\t\t\t\tonUpload={ onUploadHandler }\n\t\t\t\t\t\t\tonCancel={ onCancelHandler }\n\t\t\t\t\t\t\tonRecord={ onRecordHandler }\n\t\t\t\t\t\t\tonPause={ onPauseHandler }\n\t\t\t\t\t\t\tonResume={ onResumeHandler }\n\t\t\t\t\t\t\tonDone={ onDoneHandler }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div className=\"jetpack-ai-voice-to-content__footer\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\t\tclassName=\"jetpack-ai-voice-to-content__feedback-button\"\n\t\t\t\t\t\t\thref=\"https://a8c.slack.com/archives/C054LN8RNVA\" // Jetpack AI Slack channel\n\t\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<span>{ __( 'Provide feedback', 'jetpack' ) }</span>\n\t\t\t\t\t\t\t<Icon icon={ external } { ...iconProps } />\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</ThemeProvider>\n\t\t</Modal>\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 ingredients, steps" }, { "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/recipe/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/recipe\",\n\t\"title\": \"Recipe (Beta)\",\n\t\"description\": \"Add images, ingredients and cooking steps to display an easy to read recipe.\",\n\t\"keywords\": [],\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='M21,5c-1.11-0.35-2.33-0.5-3.5-0.5c-1.95,0-4.05,0.4-5.5,1.5c-1.45-1.1-3.55-1.5-5.5-1.5S2.45,4.9,1,6v14.65 c0,0.25,0.25,0.5,0.5,0.5c0.1,0,0.15-0.05,0.25-0.05C3.1,20.45,5.05,20,6.5,20c1.95,0,4.05,0.4,5.5,1.5c1.35-0.85,3.8-1.5,5.5-1.5 c1.65,0,3.35,0.3,4.75,1.05c0.1,0.05,0.15,0.05,0.25,0.05c0.25,0,0.5-0.25,0.5-0.5V6C22.4,5.55,21.75,5.25,21,5z M21,18.5 c-1.1-0.35-2.3-0.5-3.5-0.5c-1.7,0-4.15,0.65-5.5,1.5V8c1.35-0.85,3.8-1.5,5.5-1.5c1.2,0,2.4,0.15,3.5,0.5V18.5z' /><path d='M17.5,10.5c0.88,0,1.73,0.09,2.5,0.26V9.24C19.21,9.09,18.36,9,17.5,9c-1.7,0-3.24,0.29-4.5,0.83v1.66 C14.13,10.85,15.7,10.5,17.5,10.5z' /><path d='M13,12.49v1.66c1.13-0.64,2.7-0.99,4.5-0.99c0.88,0,1.73,0.09,2.5,0.26V11.9c-0.79-0.15-1.64-0.24-2.5-0.24 C15.8,11.66,14.26,11.96,13,12.49z' /><path d='M17.5,14.33c-1.7,0-3.24,0.29-4.5,0.83v1.66c1.13-0.64,2.7-0.99,4.5-0.99c0.88,0,1.73,0.09,2.5,0.26v-1.52 C19.21,14.41,18.36,14.33,17.5,14.33z' /></svg>\",\n\t\"supports\": {\n\t\t\"align\": [ \"full\", \"wide\" ],\n\t\t\"alignWide\": true,\n\t\t\"anchor\": false,\n\t\t\"customClassName\": true,\n\t\t\"className\": true,\n\t\t\"html\": false,\n\t\t\"multiple\": true,\n\t\t\"reusable\": true\n\t},\n\t\"attributes\": {\n\t\t\"ingredients\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t},\n\t\t\"steps\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/recipe/edit.js\n/**\n * External dependencies\n */\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\n\nfunction RecipeEdit( { className } ) {\n\tconst RECIPE_TEMPLATE = [\n\t\t[ 'jetpack/recipe-hero' ],\n\t\t[\n\t\t\t'core/heading',\n\t\t\t{\n\t\t\t\tlevel: 2,\n\t\t\t\tplaceholder: __( 'Recipe Title', 'jetpack' ),\n\t\t\t\tclassName: 'wp-block-jetpack-recipe-title',\n\t\t\t},\n\t\t],\n\t\t[\n\t\t\t'core/separator',\n\t\t\t{\n\t\t\t\tcolor: '--wp--custom--color--foreground',\n\t\t\t\tclassName: 'is-style-wide',\n\t\t\t\tstyle: 'wide',\n\t\t\t},\n\t\t],\n\t\t[\n\t\t\t'core/paragraph',\n\t\t\t{\n\t\t\t\tplaceholder: __( 'Recipe Description', 'jetpack' ),\n\t\t\t\tclassName: 'wp-block-jetpack-recipe-description',\n\t\t\t},\n\t\t],\n\t\t[ 'jetpack/recipe-details', {} ],\n\t\t[\n\t\t\t'core/columns',\n\t\t\t{},\n\t\t\t[\n\t\t\t\t[\n\t\t\t\t\t'core/column',\n\t\t\t\t\t{\n\t\t\t\t\t\twidth: '33.33%',\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t'core/heading',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlevel: 3,\n\t\t\t\t\t\t\t\t// translators: Ingredients heading for a recipe block.\n\t\t\t\t\t\t\t\tcontent: __( 'Ingredients', 'jetpack' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\t[ 'jetpack/recipe-ingredients-list' ],\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t\t[\n\t\t\t\t\t'core/column',\n\t\t\t\t\t{\n\t\t\t\t\t\twidth: '66.66%',\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t'core/heading',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlevel: 3,\n\t\t\t\t\t\t\t\t// translators: Instructions heading for a recipe block.\n\t\t\t\t\t\t\t\tcontent: __( 'Instructions', 'jetpack' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\t[ 'jetpack/recipe-steps' ],\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t],\n\t\t],\n\t];\n\n\treturn (\n\t\t<>\n\t\t\t<div { ...useBlockProps( { className } ) }>\n\t\t\t\t<InnerBlocks template={ RECIPE_TEMPLATE } />\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default RecipeEdit;\n\n\n// File: projects/plugins/jetpack/extensions/blocks/recipe/save.js\n/**\n * External dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nconst RecipeSave = ( { className } ) => {\n\treturn (\n\t\t<div className={ className }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n\nexport default RecipeSave;\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 Summarize your post with a list of headings. Add HTML anchors to Heading blocks to link them here. with these attributes: headings, only include current page, max level, ordered" }, { "role": "assistant", "content": "// File: packages/block-library/src/table-of-contents/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"__experimental\": true,\n\t\"name\": \"core/table-of-contents\",\n\t\"title\": \"Table of Contents\",\n\t\"category\": \"design\",\n\t\"description\": \"Summarize your post with a list of headings. Add HTML anchors to Heading blocks to link them here.\",\n\t\"keywords\": [ \"document outline\", \"summary\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"headings\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"object\"\n\t\t\t},\n\t\t\t\"default\": []\n\t\t},\n\t\t\"onlyIncludeCurrentPage\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"maxLevel\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"ordered\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"ariaLabel\": true,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true,\n\t\t\t\"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\"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-table-of-contents\"\n}\n\n\n// File: packages/block-library/src/table-of-contents/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { tableOfContents 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;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n\texample: {\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/heading',\n\t\t\t\tattributes: {\n\t\t\t\t\tlevel: 2,\n\t\t\t\t\tcontent: __( 'Heading' ),\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/heading',\n\t\t\t\tattributes: {\n\t\t\t\t\tlevel: 3,\n\t\t\t\t\tcontent: __( 'Subheading' ),\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/heading',\n\t\t\t\tattributes: {\n\t\t\t\t\tlevel: 2,\n\t\t\t\t\tcontent: __( 'Heading' ),\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/heading',\n\t\t\t\tattributes: {\n\t\t\t\t\tlevel: 3,\n\t\t\t\t\tcontent: __( 'Subheading' ),\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tattributes: {\n\t\t\theadings: [\n\t\t\t\t{\n\t\t\t\t\tcontent: __( 'Heading' ),\n\t\t\t\t\tlevel: 2,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcontent: __( 'Subheading' ),\n\t\t\t\t\tlevel: 3,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcontent: __( 'Heading' ),\n\t\t\t\t\tlevel: 2,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcontent: __( 'Subheading' ),\n\t\t\t\t\tlevel: 3,\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/table-of-contents/save.js\n/**\n * WordPress dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport TableOfContentsList from './list';\nimport { linearToNestedHeadingList } from './utils';\n\nexport default function save( {\n\tattributes: { headings = [], ordered = true },\n} ) {\n\tif ( headings.length === 0 ) {\n\t\treturn null;\n\t}\n\tconst ListTag = ordered ? 'ol' : 'ul';\n\treturn (\n\t\t<nav { ...useBlockProps.save() }>\n\t\t\t<ListTag>\n\t\t\t\t<TableOfContentsList\n\t\t\t\t\tnestedHeadingList={ linearToNestedHeadingList( headings ) }\n\t\t\t\t\tordered={ ordered }\n\t\t\t\t/>\n\t\t\t</ListTag>\n\t\t</nav>\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 Gutenberg block for Display the Large Image of a product." }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-gallery-large-image\",\n\t\"title\": \"Large Image\",\n\t\"description\": \"Display the Large Image of a product.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"usesContext\": [ \"postId\", \"hoverZoom\", \"fullScreenOnClick\" ],\n\t\"supports\": {\n\t\t\"interactivity\": true\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/product-gallery\" ],\n\t\"viewScriptModule\": \"woocommerce/product-gallery-large-image\",\n\t\"editorStyle\": \"file:../woocommerce/product-gallery-large-image-editor.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport const Edit = () => {\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{\n\t\t\tclassName: 'wc-block-product-gallery-large-image__inner-blocks',\n\t\t},\n\t\t{\n\t\t\ttemplateInsertUpdatesSelection: true,\n\t\t}\n\t);\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName:\n\t\t\t'wc-block-product-gallery-large-image wc-block-editor-product-gallery-large-image',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<div { ...innerBlocksProps } />\n\t\t</div>\n\t);\n};\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/inner-blocks/product-gallery-large-image/save.tsx\n/**\n * External dependencies\n */\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\n\nexport const Save = () => {\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: 'wc-block-product-gallery-large-image__inner-blocks',\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 text block with customizable content, text align" }, { "role": "assistant", "content": "// File: packages/block-library/src/verse/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/verse\",\n\t\"title\": \"Verse\",\n\t\"category\": \"text\",\n\t\"description\": \"Insert poetry. Use special spacing formats. Or quote song lyrics.\",\n\t\"keywords\": [ \"poetry\", \"poem\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"content\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"pre\",\n\t\t\t\"__unstablePreserveWhiteSpace\": true,\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": 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\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"dimensions\": {\n\t\t\t\"minHeight\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"minHeight\": false\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalWritingMode\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"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\"__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\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-verse\",\n\t\"editorStyle\": \"wp-block-verse-editor\"\n}\n\n\n// File: packages/block-library/src/verse/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { verse as icon } from '@wordpress/icons';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\t/* eslint-disable @wordpress/i18n-no-collapsible-whitespace */\n\t\t\t// translators: Sample content for the Verse block. Can be replaced with a more locale-adequate work.\n\t\t\tcontent: __(\n\t\t\t\t'WHAT was he doing, the great god Pan,\\n\tDown in the reeds by the river?\\nSpreading ruin and scattering ban,\\nSplashing and paddling with hoofs of a goat,\\nAnd breaking the golden lilies afloat\\n With the dragon-fly on the river.'\n\t\t\t),\n\t\t\t/* eslint-enable @wordpress/i18n-no-collapsible-whitespace */\n\t\t},\n\t},\n\ttransforms,\n\tdeprecated,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\tcontent: attributes.content + '\\n\\n' + attributesToMerge.content,\n\t\t};\n\t},\n\tedit,\n\tsave,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'content',\n\t\t\tlabel: __( 'Content' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'content' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/verse/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { textAlign, content } = attributes;\n\n\tconst className = clsx( {\n\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t} );\n\n\treturn (\n\t\t<pre { ...useBlockProps.save( { className } ) }>\n\t\t\t<RichText.Content value={ content } />\n\t\t</pre>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a Gutenberg block representing an Accordion Panel, ensuring it supports configurable attributes including block restrictions, template controls, initial expansion, and selection mechanism." }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/inner-blocks/accordion-panel/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/accordion-panel\",\n\t\"title\": \"Accordion Panel\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"Accordion Panel\",\n\t\"example\": {},\n\t\"__experimental\": true,\n\t\"parent\": [ \"woocommerce/accordion-item\" ],\n\t\"supports\": {\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"gradient\": true\n\t\t},\n\t\t\"border\": true,\n\t\t\"interactivity\": true,\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"blockGap\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true,\n\t\t\t\t\"blockGap\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"shadow\": true,\n\t\t\"layout\": true\n\t},\n\t\"attributes\": {\n\t\t\"allowedBlocks\": {\n\t\t\t\"type\": \"array\"\n\t\t},\n\t\t\"templateLock\": {\n\t\t\t\"type\": [ \"string\", \"boolean\" ],\n\t\t\t\"enum\": [ \"all\", \"insert\", \"contentOnly\", false ],\n\t\t\t\"default\": false\n\t\t},\n\t\t\"openByDefault\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isSelected\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/inner-blocks/accordion-panel/index.js\n/**\n * External dependencies\n */\nimport { SVG, Path } from '@wordpress/components';\nimport { registerBlockType } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport edit from './edit';\nimport save from './save';\nimport metadata from './block.json';\n\nconst icon = (\n\t<SVG\n\t\twidth=\"24\"\n\t\theight=\"24\"\n\t\tviewBox=\"0 0 24 24\"\n\t\tfill=\"none\"\n\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t>\n\t\t<Path\n\t\t\tfillRule=\"evenodd\"\n\t\t\tclipRule=\"evenodd\"\n\t\t\td=\"M8.10417 6.00024H6.5C5.39543 6.00024 4.5 6.89567 4.5 8.00024V10.3336H6V8.00024C6 7.7241 6.22386 7.50024 6.5 7.50024H8.10417V6.00024ZM4.5 13.6669V16.0002C4.5 17.1048 5.39543 18.0002 6.5 18.0002H8.10417V16.5002H6.5C6.22386 16.5002 6 16.2764 6 16.0002V13.6669H4.5ZM10.3958 6.00024V7.50024H13.6042V6.00024H10.3958ZM15.8958 6.00024V7.50024H17.5C17.7761 7.50024 18 7.7241 18 8.00024V10.3336H19.5V8.00024C19.5 6.89567 18.6046 6.00024 17.5 6.00024H15.8958ZM19.5 13.6669H18V16.0002C18 16.2764 17.7761 16.5002 17.5 16.5002H15.8958V18.0002H17.5C18.6046 18.0002 19.5 17.1048 19.5 16.0002V13.6669ZM13.6042 18.0002V16.5002H10.3958V18.0002H13.6042Z\"\n\t\t\tfill=\"currentColor\"\n\t\t/>\n\t</SVG>\n);\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\tapiVersion: 3,\n\ticon,\n\texample: {},\n\tedit,\n\tsave,\n};\n\nregisterBlockType( metadata, settings );\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/inner-blocks/accordion-panel/save.js\n/**\n * External dependencies\n */\nimport {\n\tInnerBlocks,\n\tuseBlockProps,\n\t__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,\n\t__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,\n\t__experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles,\n\t__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,\n} from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\nexport default function save( { attributes } ) {\n\tconst blockProps = useBlockProps.save();\n\tconst borderProps = getBorderClassesAndStyles( attributes );\n\tconst colorProps = getColorClassesAndStyles( attributes );\n\tconst spacingProps = getSpacingClassesAndStyles( attributes );\n\tconst shadowProps = getShadowClassesAndStyles( attributes );\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\tclassName={ clsx(\n\t\t\t\tblockProps.className,\n\t\t\t\tcolorProps.className,\n\t\t\t\tborderProps.className,\n\t\t\t\t{\n\t\t\t\t\t[ `has-custom-font-size` ]: blockProps?.style?.fontSize,\n\t\t\t\t}\n\t\t\t) }\n\t\t\tstyle={ {\n\t\t\t\t...borderProps.style,\n\t\t\t\t...colorProps.style,\n\t\t\t\t...shadowProps.style,\n\t\t\t} }\n\t\t>\n\t\t\t<div\n\t\t\t\tclassName=\"accordion-content__wrapper\"\n\t\t\t\tstyle={ {\n\t\t\t\t\t...spacingProps.style,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<InnerBlocks.Content />\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a Gutenberg block to display the cart subtotal, incorporating a class name and lock attribute for customization and control." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-subtotal/block.json\n{\n\t\"name\": \"woocommerce/checkout-order-summary-subtotal-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Subtotal\",\n\t\"description\": \"Shows the cart subtotal row.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/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-subtotal/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\n\nexport const Edit = ( {\n\tattributes,\n}: {\n\tattributes: {\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst { className } = attributes;\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Block className={ className } />\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a WordPress block that visually presents the currently applied filter selections." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/active-filters/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"name\": \"woocommerce/product-filter-active\",\n\t\"title\": \"Active Filters\",\n\t\"description\": \"Display the currently active filters.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"ancestor\": [ \"woocommerce/product-filters\" ],\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": false,\n\t\t\t\t\"radius\": false,\n\t\t\t\t\"style\": false,\n\t\t\t\t\"width\": false\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"blockGap\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false,\n\t\t\t\t\"blockGap\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"usesContext\": [ \"activeFilters\" ],\n\t\"viewScriptModule\": \"woocommerce/product-filter-active\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/active-filters/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tBlockContextProvider,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { InitialDisabled } from '../../components/initial-disabled';\nimport { EXCLUDED_BLOCKS } from '../../constants';\nimport { getAllowedBlocks } from '../../utils/get-allowed-blocks';\nimport { filtersPreview } from './constants';\n\nconst Edit = () => {\n\tconst { children, ...innerBlocksProps } = useInnerBlocksProps(\n\t\tuseBlockProps(),\n\t\t{\n\t\t\tallowedBlocks: getAllowedBlocks( EXCLUDED_BLOCKS ),\n\t\t\ttemplate: [\n\t\t\t\t[ 'woocommerce/product-filter-removable-chips' ],\n\t\t\t\t[ 'woocommerce/product-filter-clear-button' ],\n\t\t\t],\n\t\t}\n\t);\n\n\treturn (\n\t\t<div { ...innerBlocksProps }>\n\t\t\t<InitialDisabled>\n\t\t\t\t<BlockContextProvider\n\t\t\t\t\tvalue={ {\n\t\t\t\t\t\tfilterData: {\n\t\t\t\t\t\t\titems: filtersPreview,\n\t\t\t\t\t\t},\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ children }\n\t\t\t\t</BlockContextProvider>\n\t\t\t</InitialDisabled>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/active-filters/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nconst Save = () => {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\treturn <div { ...innerBlocksProps } />;\n};\n\nexport default Save;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Craft a WordPress block enabling product grid price range filtering with customizable options including class configuration, input field display, inline input mode, and two additional settings." }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/price-filter/block.json\n{\n\t\"name\": \"woocommerce/price-filter\",\n\t\"title\": \"Filter by Price Controls\",\n\t\"description\": \"Enable customers to filter the product grid by choosing a price range.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": false\n\t\t},\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": false\n\t\t},\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"showInputFields\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"inlineInput\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"showFilterButton\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"headingLevel\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/price-filter/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { getAdminLink } from '@woocommerce/settings';\nimport { blocksConfig } from '@woocommerce/block-settings';\nimport BlockTitle from '@woocommerce/editor-components/block-title';\nimport { Icon, currencyDollar, external } from '@wordpress/icons';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport {\n\tPlaceholder,\n\tDisabled,\n\tPanelBody,\n\tToggleControl,\n\tButton,\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport './editor.scss';\nimport type { Attributes } from './types';\nimport { UpgradeNotice } from '../filter-wrapper/upgrade';\n\nexport default function ( {\n\tattributes,\n\tsetAttributes,\n\tclientId,\n}: BlockEditProps< Attributes > ) {\n\tconst {\n\t\theading,\n\t\theadingLevel,\n\t\tshowInputFields,\n\t\tinlineInput,\n\t\tshowFilterButton,\n\t} = attributes;\n\n\tconst blockProps = useBlockProps();\n\n\tconst getInspectorControls = () => {\n\t\treturn (\n\t\t\t<InspectorControls key=\"inspector\">\n\t\t\t\t<PanelBody>\n\t\t\t\t\t<UpgradeNotice clientId={ clientId } />\n\t\t\t\t</PanelBody>\n\t\t\t\t<PanelBody title={ __( 'Settings', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\tlabel={ __( 'Price Range Selector', 'woocommerce' ) }\n\t\t\t\t\t\tisBlock\n\t\t\t\t\t\tvalue={ showInputFields ? 'editable' : 'text' }\n\t\t\t\t\t\tonChange={ ( value: string ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowInputFields: value === 'editable',\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclassName=\"wc-block-price-filter__price-range-toggle\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"editable\"\n\t\t\t\t\t\t\tlabel={ __( 'Editable', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"text\"\n\t\t\t\t\t\t\tlabel={ __( 'Text', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t{ showInputFields && (\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __( 'Inline input fields', 'woocommerce' ) }\n\t\t\t\t\t\t\tchecked={ inlineInput }\n\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tinlineInput: ! inlineInput,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Show input fields inline with the slider.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t\"Show 'Apply filters' button\",\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Products will update when the button is clicked.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ showFilterButton }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowFilterButton: ! showFilterButton,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t);\n\t};\n\n\tconst noProductsPlaceholder = () => (\n\t\t<Placeholder\n\t\t\tclassName=\"wc-block-price-slider\"\n\t\t\ticon={ <Icon icon={ currencyDollar } /> }\n\t\t\tlabel={ __( 'Filter by Price', 'woocommerce' ) }\n\t\t\tinstructions={ __(\n\t\t\t\t'Display a slider to filter products in your store by price.',\n\t\t\t\t'woocommerce'\n\t\t\t) }\n\t\t>\n\t\t\t<p>\n\t\t\t\t{ __(\n\t\t\t\t\t'To filter your products by price you first need to assign prices to your products.',\n\t\t\t\t\t'woocommerce'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t\t<Button\n\t\t\t\tclassName=\"wc-block-price-slider__add-product-button\"\n\t\t\t\tvariant=\"secondary\"\n\t\t\t\thref={ getAdminLink( 'post-new.php?post_type=product' ) }\n\t\t\t\ttarget=\"_top\"\n\t\t\t>\n\t\t\t\t{ __( 'Add new product', 'woocommerce' ) + ' ' }\n\t\t\t\t<Icon icon={ external } />\n\t\t\t</Button>\n\t\t\t<Button\n\t\t\t\tclassName=\"wc-block-price-slider__read_more_button\"\n\t\t\t\tvariant=\"tertiary\"\n\t\t\t\thref=\"https://woocommerce.com/document/managing-products/\"\n\t\t\t\ttarget=\"_blank\"\n\t\t\t>\n\t\t\t\t{ __( 'Learn more', 'woocommerce' ) }\n\t\t\t</Button>\n\t\t</Placeholder>\n\t);\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ blocksConfig.productCount === 0 ? (\n\t\t\t\tnoProductsPlaceholder()\n\t\t\t) : (\n\t\t\t\t<>\n\t\t\t\t\t{ getInspectorControls() }\n\t\t\t\t\t{ heading && (\n\t\t\t\t\t\t<BlockTitle\n\t\t\t\t\t\t\tclassName=\"wc-block-price-filter__title\"\n\t\t\t\t\t\t\theadingLevel={ headingLevel }\n\t\t\t\t\t\t\theading={ heading }\n\t\t\t\t\t\t\tonChange={ ( value: string ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { heading: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t<Disabled>\n\t\t\t\t\t\t<Block attributes={ attributes } isEditor={ true } />\n\t\t\t\t\t</Disabled>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a tailored WordPress block using the Gutenberg editor, focusing on the unique attributes of the a8c/event block type." }, { "role": "assistant", "content": "// File: blocks/event/src/index.js\n/**\n * External dependencies\n */\n\n/**\n * WordPress dependencies\n */\nimport { registerBlockType } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { Icon } from './icons';\nimport Edit from './edit';\nimport Save from './save';\n\nexport function registerBlock() {\n\tregisterBlockType( 'a8c/event', {\n\t\ttitle: __( 'Event', 'event' ),\n\t\tdescription: __( 'Show the time and location of an event.', 'event' ),\n\t\ticon: <Icon />,\n\t\tcategory: 'widgets',\n\t\tsupports: {\n\t\t\talign: [ 'center', 'wide' ],\n\t\t},\n\t\texample: {\n\t\t\tattributes: {\n\t\t\t\teventTitle: 'Digging for Treasure',\n\t\t\t\teventLocation: 'Treasure Island',\n\t\t\t\teventStart: '1783-11-14T12:00:00',\n\t\t\t\teventImageId: 1,\n\t\t\t\teventImageURL:\n\t\t\t\t\t'https://upload.wikimedia.org/wikipedia/commons/thumb/0/03/TI-treasure.jpg/366px-TI-treasure.jpg',\n\t\t\t\teventImageAlt: 'Treasure',\n\t\t\t\tfocalPoint: {\n\t\t\t\t\tx: '0.30',\n\t\t\t\t\ty: '0.40',\n\t\t\t\t},\n\t\t\t\tcustomBackgroundColor: '#d4c5af',\n\t\t\t\talign: 'wide',\n\t\t\t},\n\t\t},\n\t\tattributes: {\n\t\t\teventTitle: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\teventLocation: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\teventStart: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\teventImageId: {\n\t\t\t\ttype: 'number',\n\t\t\t},\n\t\t\teventImageURL: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\teventImageAlt: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\tfocalPoint: {\n\t\t\t\ttype: 'object',\n\t\t\t},\n\t\t\tbackgroundColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tcustomBackgroundColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\ttextColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tcustomTextColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t},\n\t\tedit: Edit,\n\t\tsave: Save,\n\t} );\n}\n\n\n// File: blocks/event/src/save.js\n/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tInnerBlocks,\n\tRichText,\n\tgetColorClassName,\n} from '@wordpress/block-editor';\nimport { getSettings, dateI18n } from '@wordpress/date';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport DateSelect from './date-select';\n\nconst Save = ( { attributes } ) => {\n\tconst settings = getSettings();\n\n\tconst classNames = [\n\t\tgetColorClassName( 'color', attributes.textColor ),\n\t\tgetColorClassName( 'background-color', attributes.backgroundColor ),\n\t];\n\tconst style = {\n\t\tcolor: attributes.customTextColor,\n\t\tbackgroundColor: attributes.customBackgroundColor,\n\t};\n\tconst imgStyle = {\n\t\tbackgroundImage:\n\t\t\tattributes.eventImageURL && `url(${ attributes.eventImageURL })`,\n\t\tbackgroundPosition:\n\t\t\tattributes.focalPoint &&\n\t\t\t`${ attributes.focalPoint.x * 100 }% ${ attributes.focalPoint.y *\n\t\t\t\t100 }%`,\n\t\tbackgroundSize: 'cover',\n\t};\n\n\treturn (\n\t\t<div\n\t\t\tclassName={ classnames( 'wp-block-a8c-event', classNames ) }\n\t\t\tstyle={ style }\n\t\t>\n\t\t\t<div className=\"event__details\">\n\t\t\t\t{ attributes.eventStart && (\n\t\t\t\t\t<div className=\"event__datebox\">\n\t\t\t\t\t\t<span>{ dateI18n( 'M', attributes.eventStart ) }</span>\n\t\t\t\t\t\t<span>{ dateI18n( 'j', attributes.eventStart ) }</span>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<RichText.Content\n\t\t\t\t\ttagName=\"h3\"\n\t\t\t\t\tclassName=\"event__title\"\n\t\t\t\t\tvalue={ attributes.eventTitle }\n\t\t\t\t/>\n\t\t\t\t{ attributes.eventStart && (\n\t\t\t\t\t<div className=\"event__time\">\n\t\t\t\t\t\t<span className=\"event__label\">\n\t\t\t\t\t\t\t{ __( 'When:', 'event' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<DateSelect.Content\n\t\t\t\t\t\t\tclassName=\"event__date-select\"\n\t\t\t\t\t\t\tdateFormat={ settings.formats.datetimeAbbreviated }\n\t\t\t\t\t\t\tvalue={ attributes.eventStart }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t{ attributes.eventLocation && (\n\t\t\t\t\t<div className=\"event__location\">\n\t\t\t\t\t\t<span className=\"event__label\">\n\t\t\t\t\t\t\t{ __( 'Where:', 'event' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<RichText.Content value={ attributes.eventLocation } />\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<div className=\"event__description\">\n\t\t\t\t\t<InnerBlocks.Content className=\"event__description\" />\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t\t{ attributes.eventImageURL && (\n\t\t\t\t<div\n\t\t\t\t\trole=\"img\"\n\t\t\t\t\taria-label={ attributes.eventImageAlt }\n\t\t\t\t\tclassName=\"event__image event__image--save\"\n\t\t\t\t\tstyle={ imgStyle }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n};\n\nexport default Save;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Restrict access to your content for paying subscribers. that allows users to configure: selected plan ids, is preview, is premium content child" }, { "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/premium-content/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"premium-content/container\",\n\t\"title\": \"Paid Content\",\n\t\"description\": \"Restrict access to your content for paying subscribers.\",\n\t\"keywords\": [\n\t\t\"buy\",\n\t\t\"credit card\",\n\t\t\"debit card\",\n\t\t\"monetize\",\n\t\t\"earn\",\n\t\t\"exclusive\",\n\t\t\"gated\",\n\t\t\"gofundme\",\n\t\t\"memberships\",\n\t\t\"money\",\n\t\t\"newsletter\",\n\t\t\"paid\",\n\t\t\"patreon\",\n\t\t\"pay\",\n\t\t\"payments\",\n\t\t\"paywall\",\n\t\t\"premium content\",\n\t\t\"purchase\",\n\t\t\"recurring\",\n\t\t\"repeat\",\n\t\t\"signin\",\n\t\t\"stripe\",\n\t\t\"subscribe\",\n\t\t\"subscriptions\",\n\t\t\"support\",\n\t\t\"sponsor\",\n\t\t\"square\",\n\t\t\"toast\",\n\t\t\"venmo\",\n\t\t\"stripe\",\n\t\t\"substack\"\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='m12.74,14.43l-4.1-1.26-.13.71-.42,6.87c-.03.49.52.81.93.54l3.72-2.48,4,2.51c.42.26.96-.07.92-.56l-.64-6.87v-.71l-4.28,1.26Z'/><path d='m12.74,15.14c-3.55,0-6.44-2.89-6.44-6.44s2.89-6.44,6.44-6.44,6.44,2.89,6.44,6.44-2.89,6.44-6.44,6.44Zm0-11.89c-3,0-5.44,2.44-5.44,5.44s2.44,5.44,5.44,5.44,5.44-2.44,5.44-5.44-2.44-5.44-5.44-5.44Z'/><path d='M11.95 11.08 9.36 8.48 10.06 7.77 11.95 9.66 15.42 6.19 16.13 6.9 11.95 11.08z'/></svg>\",\n\t\"supports\": {\n\t\t\"html\": false\n\t},\n\t\"providesContext\": {\n\t\t\"premium-content/planIds\": \"selectedPlanIds\",\n\t\t\"premium-content/isPreview\": \"isPreview\",\n\t\t\"isPremiumContentChild\": \"isPremiumContentChild\"\n\t},\n\t\"attributes\": {\n\t\t\"selectedPlanIds\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\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\"isPremiumContentChild\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"isPreview\": true\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/premium-content/edit.js\nimport { store as blockEditorStore, useBlockProps } from '@wordpress/block-editor';\nimport { Disabled, Placeholder, Spinner } from '@wordpress/components';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { select, useSelect } from '@wordpress/data';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport ConnectBanner from '../../shared/components/connect-banner';\nimport ProductManagementControls from '../../shared/components/product-management-controls';\nimport { PRODUCT_TYPE_SUBSCRIPTION } from '../../shared/components/product-management-controls/constants';\nimport { StripeNudge } from '../../shared/components/stripe-nudge';\nimport useIsUserConnected from '../../shared/use-is-user-connected';\nimport { store as membershipProductsStore } from '../../store/membership-products';\nimport Blocks from './_inc/blocks';\nimport Context from './_inc/context';\nimport './editor.scss';\nimport ViewSelector from './_inc/view-selector';\n/**\n * Tab definitions\n *\n * If changing or adding tabs, the _TAB constants below might need changing too.\n *\n * @typedef { import('./tabs').Tab } Tab\n * @type { Tab[] }\n */\nconst tabs = [\n\t{\n\t\tid: 'premium',\n\t\tlabel: <span>{ __( 'Subscriber View', 'jetpack' ) }</span>,\n\t\tclassName: 'wp-premium-content-subscriber-view',\n\t},\n\t{\n\t\tid: 'wall',\n\t\tlabel: <span>{ __( 'Guest View', 'jetpack' ) }</span>,\n\t\tclassName: 'wp-premium-content-logged-out-view',\n\t},\n];\n\nconst CONTENT_TAB = 0;\nconst WALL_TAB = 1;\nconst BLOCK_NAME = 'premium-content';\n/**\n *\n * @typedef { import('react').MutableRefObject<?object> } ContainerRef\n */\n\n/**\n * Block edit function\n *\n * @typedef { import('./').Attributes } Attributes\n * @typedef {object} OwnProps\n * @property { boolean } isSelected\n * @property { string } className\n * @property { string } clientId\n * @property { Attributes } attributes\n * @property {(attributes: Object<Attributes>) => void} setAttributes\n * @typedef { OwnProps } Props\n * @param { Props } props\n */\n\nfunction Edit( { clientId, isSelected, attributes, setAttributes } ) {\n\tconst { isPreview, selectedPlanIds } = attributes;\n\n\tconst [ selectedTab, selectTab ] = useState( tabs[ WALL_TAB ] );\n\tconst blockProps = useBlockProps();\n\tconst isUserConnected = useIsUserConnected();\n\n\tconst setSelectedProductIds = productIds => setAttributes( { selectedPlanIds: productIds } );\n\n\tconst { isApiLoading, selectedBlock } = useSelect( selector => ( {\n\t\tselectedBlock: selector( blockEditorStore ).getSelectedBlock(),\n\t\tisApiLoading: selector( membershipProductsStore ).isApiStateLoading(),\n\t} ) );\n\n\tuseEffect( () => {\n\t\tif ( isSelected ) {\n\t\t\treturn; // If this block is selected then leave the focused tab as it was.\n\t\t}\n\n\t\tif ( ! selectedBlock ) {\n\t\t\treturn; // Sometimes there isn't a block selected, e.g. on page load.\n\t\t}\n\n\t\tconst editorStore = select( blockEditorStore );\n\n\t\t// Confirm that the selected block is a descendant of this one.\n\t\tif ( ! editorStore.getBlockParents( selectedBlock.clientId ).includes( clientId ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\t'premium-content/logged-out-view' === selectedBlock.name ||\n\t\t\teditorStore.getBlockParentsByBlockName(\n\t\t\t\tselectedBlock.clientId,\n\t\t\t\t'premium-content/logged-out-view'\n\t\t\t).length\n\t\t) {\n\t\t\tselectTab( tabs[ WALL_TAB ] );\n\t\t} else {\n\t\t\tselectTab( tabs[ CONTENT_TAB ] );\n\t\t}\n\t}, [ clientId, isSelected, selectedBlock ] );\n\n\tconst isSmallViewport = useViewportMatch( 'medium', '<' );\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=\"Paid Content\"\n\t\t\t\t\texplanation={ __(\n\t\t\t\t\t\t'Connect your WordPress.com account to enable paid content.',\n\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ ! isPreview && (\n\t\t\t\t<>\n\t\t\t\t\t{ isApiLoading && (\n\t\t\t\t\t\t<Placeholder\n\t\t\t\t\t\t\ticon=\"lock\"\n\t\t\t\t\t\t\tlabel={ __( 'Paid Content', 'jetpack' ) }\n\t\t\t\t\t\t\tinstructions={ __( 'Loading data…', 'jetpack' ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t\t</Placeholder>\n\t\t\t\t\t) }\n\t\t\t\t\t<ProductManagementControls\n\t\t\t\t\t\tblockName={ BLOCK_NAME }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tproductType={ PRODUCT_TYPE_SUBSCRIPTION }\n\t\t\t\t\t\tselectedProductIds={ selectedPlanIds }\n\t\t\t\t\t\tsetSelectedProductIds={ setSelectedProductIds }\n\t\t\t\t\t/>\n\t\t\t\t\t<ViewSelector\n\t\t\t\t\t\toptions={ tabs }\n\t\t\t\t\t\tselectedOption={ selectedTab }\n\t\t\t\t\t\tselectAction={ selectTab }\n\t\t\t\t\t\tcontractViewport={ isSmallViewport }\n\t\t\t\t\t\tlabel={ __( 'Change view', 'jetpack' ) }\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ ! isApiLoading && (\n\t\t\t\t<>\n\t\t\t\t\t<StripeNudge blockName={ BLOCK_NAME } />\n\t\t\t\t\t<Context.Provider value={ { selectedTab } }>\n\t\t\t\t\t\t<Blocks />\n\t\t\t\t\t</Context.Provider>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nexport default function MaybeDisabledEdit( props ) {\n\t// The block transformations menu renders a block preview popover using real blocks\n\t// for transformation. The block previews do not play nicely with useEffect and\n\t// updating content after a resolved API call. To disarm the block preview, we can\n\t// check to see if the block is being rendered within a Disabled context, and set\n\t// the isPreview flag accordingly.\n\treturn (\n\t\t<Disabled.Consumer>\n\t\t\t{ isDisabled => {\n\t\t\t\treturn (\n\t\t\t\t\t<Edit\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\tattributes={ {\n\t\t\t\t\t\t\t...props.attributes,\n\t\t\t\t\t\t\tisPreview: isDisabled || props.attributes?.isPreview,\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</Disabled.Consumer>\n\t);\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/premium-content/save.js\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\nexport default function Save() {\n\tconst blockProps = useBlockProps.save();\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\tclassName={ clsx( blockProps.className, 'wp-block-premium-content-container' ) }\n\t\t>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a block feature for displaying curated site recommendations that lets users personalize presentation through avatar display, description visibility, link opening preferences, and two extra configuration choices." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/blogroll/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/blogroll\",\n\t\"title\": \"Blogroll\",\n\t\"description\": \"Share the sites you follow with your users.\",\n\t\"keywords\": [],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg width='24' height='24' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path d='M4.08691 16.2412H20.0869V14.7412H4.08691V16.2412Z'></path><path d='M4.08691 20.2412H13.0869V18.7412H4.08691V20.2412Z'></path><path fill-rule='evenodd' clip-rule='evenodd' d='M4.08691 8.17871C4.08691 6.00409 5.84979 4.24121 8.02441 4.24121C10.199 4.24121 11.9619 6.00409 11.9619 8.17871C11.9619 10.3533 10.199 12.1162 8.02441 12.1162C5.84979 12.1162 4.08691 10.3533 4.08691 8.17871ZM5.10729 6.71621C5.51231 5.90991 6.2418 5.29471 7.12439 5.04194C6.91534 5.28455 6.73551 5.57108 6.58869 5.88606C6.46938 6.14205 6.36999 6.42056 6.29338 6.71621H5.10729ZM4.85759 7.39121C4.79508 7.64341 4.76191 7.90719 4.76191 8.17871C4.76191 8.45024 4.79508 8.71401 4.85759 8.96621H6.16284C6.12938 8.71126 6.11192 8.44782 6.11192 8.1787C6.11192 7.90956 6.12938 7.64614 6.16284 7.39121H4.85759ZM6.84439 7.39121C6.80693 7.64285 6.78692 7.90651 6.78692 8.1787C6.78692 8.45091 6.80694 8.71459 6.84439 8.96621H9.20444C9.2419 8.71458 9.26192 8.45091 9.26192 8.17873C9.26192 7.90653 9.2419 7.64285 9.20444 7.39121H6.84439ZM9.88599 7.39121C9.91945 7.64615 9.93692 7.90958 9.93692 8.17873C9.93692 8.44786 9.91945 8.71128 9.88599 8.96621H11.1912C11.2537 8.71401 11.2869 8.45024 11.2869 8.17871C11.2869 7.90719 11.2537 7.64341 11.1912 7.39121H9.88599ZM10.9415 6.71621H9.75544C9.67883 6.42057 9.57945 6.14207 9.46014 5.88609C9.31332 5.5711 9.13347 5.28455 8.92441 5.04193C9.80702 5.29469 10.5365 5.9099 10.9415 6.71621ZM9.05465 6.71621H6.99417C7.05245 6.52254 7.12177 6.34014 7.2005 6.17123C7.42342 5.69296 7.71302 5.34019 8.02439 5.13337C8.33578 5.34019 8.6254 5.69297 8.84833 6.17126C8.92706 6.34016 8.99637 6.52255 9.05465 6.71621ZM5.10729 9.64121H6.29339C6.37419 9.95305 6.48034 10.2458 6.6085 10.5132C6.75142 10.8114 6.92452 11.0835 7.12445 11.3155C6.24183 11.0627 5.51232 10.4475 5.10729 9.64121ZM9.05466 9.64121H6.99418C7.05655 9.84847 7.13156 10.0428 7.21721 10.2215C7.43825 10.6827 7.72115 11.0226 8.02446 11.224C8.33582 11.0172 8.62541 10.6645 8.84833 10.1862C8.92706 10.0173 8.99638 9.83488 9.05466 9.64121ZM9.46014 10.4714C9.57945 10.2154 9.67884 9.93686 9.75545 9.64121H10.9415C10.5365 10.4475 9.80703 11.0627 8.92444 11.3155C9.13349 11.0729 9.31332 10.7863 9.46014 10.4714Z'></path></svg>\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"alignWide\": true,\n\t\t\"anchor\": false,\n\t\t\"customClassName\": true,\n\t\t\"className\": true,\n\t\t\"html\": false,\n\t\t\"multiple\": true,\n\t\t\"reusable\": true,\n\t\t\"color\": {\n\t\t\t\"link\": true,\n\t\t\t\"gradients\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"show_avatar\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"show_description\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"open_links_new_window\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"ignore_user_blogs\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"load_placeholders\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"showAvatar\": \"show_avatar\",\n\t\t\"showDescription\": \"show_description\",\n\t\t\"openLinksNewWindow\": \"open_links_new_window\"\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/blogroll/edit.js\nimport { InspectorControls, useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { createBlock } from '@wordpress/blocks';\nimport { PanelBody, ToggleControl, FlexBlock, Spinner, Notice } from '@wordpress/components';\nimport { dispatch } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport ConnectBanner from '../../shared/components/connect-banner';\nimport useIsUserConnected from '../../shared/use-is-user-connected';\nimport BlogrollAppender from './components/blogroll-appender';\nimport useRecommendations from './use-recommendations';\nimport { useSiteRecommendationSync } from './use-site-recommendations';\nimport useSubscriptions from './use-subscriptions';\nimport { createBlockFromRecommendation } from './utils';\nimport './editor.scss';\n\nexport function BlogRollEdit( { className, attributes, setAttributes, clientId } ) {\n\tconst {\n\t\tshow_avatar,\n\t\tshow_description,\n\t\topen_links_new_window,\n\t\tignore_user_blogs,\n\t\tload_placeholders,\n\t} = attributes;\n\n\tconst isUserConnected = useIsUserConnected();\n\n\tconst {\n\t\tisLoading: isLoadingRecommendations,\n\t\trecommendations,\n\t\terrorMessage: recommendationsErrorMessage,\n\t} = useRecommendations( load_placeholders );\n\tconst {\n\t\tisLoading: isLoadingSubscriptions,\n\t\tsubscriptions,\n\t\terrorMessage: subscriptionsErrorMessage,\n\t} = useSubscriptions( {\n\t\tignore_user_blogs,\n\t} );\n\tuseSiteRecommendationSync( { clientId } );\n\tconst { replaceInnerBlocks } = dispatch( 'core/block-editor' );\n\n\tuseEffect( () => {\n\t\tif ( load_placeholders && recommendations.length ) {\n\t\t\tsetAttributes( { load_placeholders: false } );\n\n\t\t\tconst blocks = [\n\t\t\t\tcreateBlock( 'core/heading', { content: __( 'Blogroll', 'jetpack' ), level: 3 } ),\n\t\t\t\t...recommendations.map( createBlockFromRecommendation ),\n\t\t\t];\n\t\t\treplaceInnerBlocks( clientId, blocks );\n\t\t}\n\t}, [ recommendations, load_placeholders, setAttributes, clientId, replaceInnerBlocks ] );\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( className, {\n\t\t\t'hide-avatar': ! show_avatar,\n\t\t\t'hide-description': ! show_description,\n\t\t} ),\n\t} );\n\n\tif ( ! isUserConnected ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<ConnectBanner\n\t\t\t\t\tblock=\"Blogroll\"\n\t\t\t\t\texplanation={ __(\n\t\t\t\t\t\t'Connect your WordPress.com account to use the Blogroll block.',\n\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t}\n\n\tconst errorMessage = recommendationsErrorMessage || subscriptionsErrorMessage;\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks\n\t\t\t\ttemplate={ [ [ 'core/heading', { content: __( 'Blogroll', 'jetpack' ), level: 3 } ] ] }\n\t\t\t\tallowedBlocks={ [ 'jetpack/blogroll-item' ] }\n\t\t\t\trenderAppender={ () =>\n\t\t\t\t\t! isLoadingRecommendations && (\n\t\t\t\t\t\t<BlogrollAppender\n\t\t\t\t\t\t\tisLoading={ isLoadingSubscriptions }\n\t\t\t\t\t\t\tsubscriptions={ subscriptions }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t/>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t/>\n\n\t\t\t{ errorMessage && (\n\t\t\t\t<Notice status=\"error\" isDismissible={ false }>\n\t\t\t\t\t<p>{ errorMessage }</p>\n\t\t\t\t</Notice>\n\t\t\t) }\n\n\t\t\t{ load_placeholders && isLoadingRecommendations && (\n\t\t\t\t<FlexBlock style={ { padding: '30px', textAlign: 'center' } }>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</FlexBlock>\n\t\t\t) }\n\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Settings', 'jetpack' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show avatar', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ !! show_avatar }\n\t\t\t\t\t\tonChange={ () => setAttributes( { show_avatar: ! show_avatar } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show description', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ !! show_description }\n\t\t\t\t\t\tonChange={ () => setAttributes( { show_description: ! show_description } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Open links in a new window', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ !! open_links_new_window }\n\t\t\t\t\t\tonChange={ () => setAttributes( { open_links_new_window: ! open_links_new_window } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Hide my own sites', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ !! ignore_user_blogs }\n\t\t\t\t\t\tonChange={ () => setAttributes( { ignore_user_blogs: ! ignore_user_blogs } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t</div>\n\t);\n}\n\nexport default BlogRollEdit;\n\n\n// File: projects/plugins/jetpack/extensions/blocks/blogroll/save.js\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\nexport function BlogRollSave( { attributes: { show_avatar, show_description }, className } ) {\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: clsx( className, {\n\t\t\t'hide-avatar': ! show_avatar,\n\t\t\t'hide-description': ! show_description,\n\t\t} ),\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n}\n\nexport default BlogRollSave;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Show all product categories as a list or dropdown. with these attributes: align, has count, has image, 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/product-categories/block.json\n{\n\t\"name\": \"woocommerce/product-categories\",\n\t\"title\": \"Product Categories List\",\n\t\"category\": \"woocommerce\",\n\t\"description\": \"Show all product categories as a list or dropdown.\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"background\": false,\n\t\t\t\"link\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"align\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"hasCount\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"hasImage\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"hasEmpty\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isDropdown\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isHierarchical\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showChildrenOnly\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"hasCount\": true,\n\t\t\t\"hasImage\": 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-categories/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport './editor.scss';\nimport type { ProductCategoriesBlockProps } from './types';\n\nexport default function ProductCategoriesEdit(\n\tprops: ProductCategoriesBlockProps\n): JSX.Element {\n\tconst blockProps = useBlockProps();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Block { ...props } />\n\t\t</div>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Display a grid of your newest products. that allows users to configure: columns, rows, align buttons, and 7 more options" }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-new/block.json\n{\n\t\"name\": \"woocommerce/product-new\",\n\t\"title\": \"Newest Products\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"Display a grid of your newest 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\": \"date\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-new/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { ProductNewestBlock } from './block';\nimport { ProductNewestBlockProps } from './types';\n\nexport const Edit = (\n\tprops: unknown & ProductNewestBlockProps\n): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<ProductNewestBlock { ...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 widgets block with customizable comments to show, display avatar, display date, display content" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/latest-comments/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/latest-comments\",\n\t\"title\": \"Latest Comments\",\n\t\"category\": \"widgets\",\n\t\"description\": \"Display a list of your most recent comments.\",\n\t\"keywords\": [ \"recent comments\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"commentsToShow\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 5,\n\t\t\t\"minimum\": 1,\n\t\t\t\"maximum\": 100\n\t\t},\n\t\t\"displayAvatar\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"displayDate\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"displayContent\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"excerpt\",\n\t\t\t\"enum\": [ \"none\", \"excerpt\", \"full\" ]\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": 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},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-latest-comments-editor\",\n\t\"style\": \"wp-block-latest-comments\"\n}\n\n\n// File: packages/block-library/src/latest-comments/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 deprecated from './deprecated';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {},\n\tedit,\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 personalized Gutenberg block specifically designed with the identifier a8c/event, implementing custom functionality and design." }, { "role": "assistant", "content": "// File: blocks/event/src/index.js\n/**\n * External dependencies\n */\n\n/**\n * WordPress dependencies\n */\nimport { registerBlockType } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { Icon } from './icons';\nimport Edit from './edit';\nimport Save from './save';\n\nexport function registerBlock() {\n\tregisterBlockType( 'a8c/event', {\n\t\ttitle: __( 'Event', 'event' ),\n\t\tdescription: __( 'Show the time and location of an event.', 'event' ),\n\t\ticon: <Icon />,\n\t\tcategory: 'widgets',\n\t\tsupports: {\n\t\t\talign: [ 'center', 'wide' ],\n\t\t},\n\t\texample: {\n\t\t\tattributes: {\n\t\t\t\teventTitle: 'Digging for Treasure',\n\t\t\t\teventLocation: 'Treasure Island',\n\t\t\t\teventStart: '1783-11-14T12:00:00',\n\t\t\t\teventImageId: 1,\n\t\t\t\teventImageURL:\n\t\t\t\t\t'https://upload.wikimedia.org/wikipedia/commons/thumb/0/03/TI-treasure.jpg/366px-TI-treasure.jpg',\n\t\t\t\teventImageAlt: 'Treasure',\n\t\t\t\tfocalPoint: {\n\t\t\t\t\tx: '0.30',\n\t\t\t\t\ty: '0.40',\n\t\t\t\t},\n\t\t\t\tcustomBackgroundColor: '#d4c5af',\n\t\t\t\talign: 'wide',\n\t\t\t},\n\t\t},\n\t\tattributes: {\n\t\t\teventTitle: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\teventLocation: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\teventStart: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\teventImageId: {\n\t\t\t\ttype: 'number',\n\t\t\t},\n\t\t\teventImageURL: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\teventImageAlt: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\tfocalPoint: {\n\t\t\t\ttype: 'object',\n\t\t\t},\n\t\t\tbackgroundColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tcustomBackgroundColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\ttextColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tcustomTextColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t},\n\t\tedit: Edit,\n\t\tsave: Save,\n\t} );\n}\n\n\n// File: blocks/event/src/save.js\n/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tInnerBlocks,\n\tRichText,\n\tgetColorClassName,\n} from '@wordpress/block-editor';\nimport { getSettings, dateI18n } from '@wordpress/date';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport DateSelect from './date-select';\n\nconst Save = ( { attributes } ) => {\n\tconst settings = getSettings();\n\n\tconst classNames = [\n\t\tgetColorClassName( 'color', attributes.textColor ),\n\t\tgetColorClassName( 'background-color', attributes.backgroundColor ),\n\t];\n\tconst style = {\n\t\tcolor: attributes.customTextColor,\n\t\tbackgroundColor: attributes.customBackgroundColor,\n\t};\n\tconst imgStyle = {\n\t\tbackgroundImage:\n\t\t\tattributes.eventImageURL && `url(${ attributes.eventImageURL })`,\n\t\tbackgroundPosition:\n\t\t\tattributes.focalPoint &&\n\t\t\t`${ attributes.focalPoint.x * 100 }% ${ attributes.focalPoint.y *\n\t\t\t\t100 }%`,\n\t\tbackgroundSize: 'cover',\n\t};\n\n\treturn (\n\t\t<div\n\t\t\tclassName={ classnames( 'wp-block-a8c-event', classNames ) }\n\t\t\tstyle={ style }\n\t\t>\n\t\t\t<div className=\"event__details\">\n\t\t\t\t{ attributes.eventStart && (\n\t\t\t\t\t<div className=\"event__datebox\">\n\t\t\t\t\t\t<span>{ dateI18n( 'M', attributes.eventStart ) }</span>\n\t\t\t\t\t\t<span>{ dateI18n( 'j', attributes.eventStart ) }</span>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<RichText.Content\n\t\t\t\t\ttagName=\"h3\"\n\t\t\t\t\tclassName=\"event__title\"\n\t\t\t\t\tvalue={ attributes.eventTitle }\n\t\t\t\t/>\n\t\t\t\t{ attributes.eventStart && (\n\t\t\t\t\t<div className=\"event__time\">\n\t\t\t\t\t\t<span className=\"event__label\">\n\t\t\t\t\t\t\t{ __( 'When:', 'event' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<DateSelect.Content\n\t\t\t\t\t\t\tclassName=\"event__date-select\"\n\t\t\t\t\t\t\tdateFormat={ settings.formats.datetimeAbbreviated }\n\t\t\t\t\t\t\tvalue={ attributes.eventStart }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t{ attributes.eventLocation && (\n\t\t\t\t\t<div className=\"event__location\">\n\t\t\t\t\t\t<span className=\"event__label\">\n\t\t\t\t\t\t\t{ __( 'Where:', 'event' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<RichText.Content value={ attributes.eventLocation } />\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<div className=\"event__description\">\n\t\t\t\t\t<InnerBlocks.Content className=\"event__description\" />\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t\t{ attributes.eventImageURL && (\n\t\t\t\t<div\n\t\t\t\t\trole=\"img\"\n\t\t\t\t\taria-label={ attributes.eventImageAlt }\n\t\t\t\t\tclassName=\"event__image event__image--save\"\n\t\t\t\t\tstyle={ imgStyle }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n};\n\nexport default Save;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Design a flexible WooCommerce block with comprehensive styling options, allowing users to modify attributes such as alternative text, content positioning, opacity levels, and 12 more advanced customization settings." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/featured-product/block.json\n{\n\t\"name\": \"woocommerce/featured-product\",\n\t\"title\": \"Featured Product\",\n\t\"description\": \"Highlight a product or variation.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"ariaLabel\": true,\n\t\t\"html\": false,\n\t\t\"filter\": {\n\t\t\t\"duotone\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true\n\t\t\t},\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"width\": true\n\t\t\t},\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"multiple\": true\n\t},\n\t\"attributes\": {\n\t\t\"alt\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"contentAlign\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"center\"\n\t\t},\n\t\t\"dimRatio\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 50\n\t\t},\n\t\t\"focalPoint\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"x\": 0.5,\n\t\t\t\t\"y\": 0.5\n\t\t\t}\n\t\t},\n\t\t\"imageFit\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"none\"\n\t\t},\n\t\t\"hasParallax\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isRepeated\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"mediaId\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"mediaSrc\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"minHeight\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 500\n\t\t},\n\t\t\"linkText\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"Shop now\"\n\t\t},\n\t\t\"overlayColor\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"#000000\"\n\t\t},\n\t\t\"overlayGradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"productId\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"previewProduct\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": null\n\t\t}\n\t},\n\t\"selectors\": {\n\t\t\"filter\": {\n\t\t\t\"duotone\": \".wp-block-woocommerce-featured-product .wc-block-featured-product__background-image\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/featured-product/index.tsx\n/**\n * External dependencies\n */\nimport { Icon, starEmpty } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport './style.scss';\nimport './editor.scss';\nimport Block from './block';\nimport { register } from '../register';\nimport { example } from './example';\nimport deprecated from './deprecated';\nimport metadata from './block.json';\n\nregister( Block, example, metadata, {\n\tdeprecated,\n\ticon: {\n\t\tsrc: (\n\t\t\t<Icon\n\t\t\t\ticon={ starEmpty }\n\t\t\t\tclassName=\"wc-block-editor-components-block-icon\"\n\t\t\t/>\n\t\t),\n\t},\n} );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Implement a Gutenberg block for Contains the block elements used to display product reviews, like the title, author, date, rating 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/blocks/product-reviews/inner-blocks/review-template/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-review-template\",\n\t\"title\": \"Reviews Template\",\n\t\"category\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/product-reviews\" ],\n\t\"description\": \"Contains the block elements used to display product reviews, like the title, author, date, rating and more.\",\n\t\"textdomain\": \"woocommerce\",\n\t\"usesContext\": [ \"postId\", \"postType\" ],\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"html\": false,\n\t\t\"reusable\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-template/edit.tsx\n/**\n * External dependencies\n */\nimport { useState, memo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { BlockInstance, BlockEditProps } from '@wordpress/blocks';\nimport { Spinner } from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t// @ts-ignore No types for this exist yet.\n\tBlockContextProvider,\n\tuseBlockProps,\n\t// @ts-expect-error no exported member.\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n\t// @ts-expect-error no exported member.\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalUseBlockPreview as useBlockPreview,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { useCommentQueryArgs, useCommentList } from './hooks';\n\ninterface Comment {\n\tcommentId: number;\n}\n\ninterface ReviewTemplateInnerBlocksProps {\n\tcomment: Comment;\n\tactiveCommentId: number;\n\tsetActiveCommentId: ( id: number ) => void;\n\tfirstCommentId: number;\n\tblocks: BlockInstance[];\n}\n\ninterface ReviewTemplatePreviewProps {\n\tblocks: BlockInstance[];\n\tcommentId: number;\n\tsetActiveCommentId: ( id: number ) => void;\n\tisHidden: boolean;\n}\n\ntype ReviewTemplateAttributes = {\n\tpostId?: number;\n};\n\nconst TEMPLATE = [\n\t[ 'core/avatar' ],\n\t[ 'woocommerce/product-review-author-name' ],\n\t[ 'woocommerce/product-review-date' ],\n\t[ 'woocommerce/product-review-content' ],\n];\n\ninterface ReviewSettings {\n\tperPage: number;\n\tpageComments: boolean;\n}\n\nconst getCommentsPlaceholder = ( {\n\tperPage,\n\tpageComments,\n}: ReviewSettings ) => {\n\tconst numberOfComments = pageComments ? Math.min( perPage, 3 ) : 3;\n\n\treturn Array.from( { length: numberOfComments }, ( _, i ) => ( {\n\t\tcommentId: -( i + 1 ),\n\t} ) );\n};\n\nconst ReviewTemplatePreview = ( {\n\tblocks,\n\tcommentId,\n\tsetActiveCommentId,\n\tisHidden,\n}: ReviewTemplatePreviewProps ) => {\n\tconst blockPreviewProps = useBlockPreview( {\n\t\tblocks,\n\t} );\n\n\tconst handleOnClick = () => {\n\t\tsetActiveCommentId( commentId );\n\t};\n\n\tconst style = {\n\t\tdisplay: isHidden ? 'none' : undefined,\n\t};\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockPreviewProps }\n\t\t\ttabIndex={ 0 }\n\t\t\trole=\"button\"\n\t\t\tstyle={ style }\n\t\t\tonClick={ handleOnClick }\n\t\t\tonKeyDown={ handleOnClick }\n\t\t/>\n\t);\n};\n\nconst MemoizedReviewTemplatePreview = memo( ReviewTemplatePreview );\n\nconst ReviewTemplateInnerBlocks = memo( function ReviewTemplateInnerBlocks( {\n\tcomment,\n\tactiveCommentId,\n\tsetActiveCommentId,\n\tfirstCommentId,\n\tblocks,\n}: ReviewTemplateInnerBlocksProps ) {\n\tconst { children, ...innerBlocksProps } = useInnerBlocksProps(\n\t\t{},\n\t\t{ template: TEMPLATE }\n\t);\n\n\treturn (\n\t\t<li { ...innerBlocksProps }>\n\t\t\t{ comment.commentId === ( activeCommentId || firstCommentId )\n\t\t\t\t? children\n\t\t\t\t: null }\n\n\t\t\t<MemoizedReviewTemplatePreview\n\t\t\t\tblocks={ blocks }\n\t\t\t\tcommentId={ comment.commentId }\n\t\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\t\tisHidden={\n\t\t\t\t\tcomment.commentId === ( activeCommentId || firstCommentId )\n\t\t\t\t}\n\t\t\t/>\n\t\t</li>\n\t);\n} );\n\nexport default function ReviewTemplateEdit( {\n\tclientId,\n\tcontext: { postId },\n}: BlockEditProps< ReviewTemplateAttributes > & {\n\tcontext: { postId: number };\n} ) {\n\tconst blockProps = useBlockProps();\n\n\tconst [ activeCommentId, setActiveCommentId ] = useState< number >( 0 );\n\tconst { commentOrder, commentsPerPage, pageComments } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSettings } = select( blockEditorStore ) as unknown as {\n\t\t\t\tgetSettings(): {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\t\t\t\t\t__experimentalDiscussionSettings: {\n\t\t\t\t\t\tcommentOrder: string;\n\t\t\t\t\t\tcommentsPerPage: number;\n\t\t\t\t\t\tpageComments: boolean;\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t};\n\t\t\treturn getSettings().__experimentalDiscussionSettings;\n\t\t},\n\t\t[]\n\t);\n\n\tconst commentQuery = useCommentQueryArgs( {\n\t\tpostId: postId ?? 0,\n\t} );\n\n\tconst { topLevelComments, blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\tconst { getBlocks } = select( blockEditorStore ) as unknown as {\n\t\t\t\tgetBlocks( clientId: string ): BlockInstance[];\n\t\t\t};\n\t\t\treturn {\n\t\t\t\ttopLevelComments: commentQuery\n\t\t\t\t\t? getEntityRecords( 'root', 'comment', commentQuery )\n\t\t\t\t\t: null,\n\t\t\t\tblocks: getBlocks( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId, commentQuery ]\n\t);\n\n\tlet commentTree = useCommentList(\n\t\t// Reverse the order of top comments if needed.\n\t\tcommentOrder === 'desc' && topLevelComments\n\t\t\t? [\n\t\t\t\t\t...( topLevelComments as Array< {\n\t\t\t\t\t\tid: number;\n\t\t\t\t\t} > ),\n\t\t\t ].reverse()\n\t\t\t: ( topLevelComments as Array< {\n\t\t\t\t\tid: number;\n\t\t\t } > )\n\t);\n\n\tif ( ! topLevelComments ) {\n\t\treturn (\n\t\t\t<p { ...blockProps }>\n\t\t\t\t<Spinner />\n\t\t\t</p>\n\t\t);\n\t}\n\n\tif ( ! postId ) {\n\t\tcommentTree = getCommentsPlaceholder( {\n\t\t\tperPage: commentsPerPage,\n\t\t\tpageComments,\n\t\t} );\n\t}\n\n\tif ( ! commentTree.length ) {\n\t\treturn (\n\t\t\t<p { ...blockProps }>\n\t\t\t\t{ __( 'No results found.', 'woocommerce' ) }\n\t\t\t</p>\n\t\t);\n\t}\n\n\treturn (\n\t\t<ol { ...blockProps }>\n\t\t\t{ commentTree &&\n\t\t\t\tcommentTree.map(\n\t\t\t\t\t(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommentId,\n\t\t\t\t\t\t}: {\n\t\t\t\t\t\t\tcommentId: number;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tindex: number\n\t\t\t\t\t) => (\n\t\t\t\t\t\t<BlockContextProvider\n\t\t\t\t\t\t\tkey={ commentId || index }\n\t\t\t\t\t\t\tvalue={ {\n\t\t\t\t\t\t\t\tcommentId: commentId < 0 ? null : commentId,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ReviewTemplateInnerBlocks\n\t\t\t\t\t\t\t\tcomment={ { commentId } }\n\t\t\t\t\t\t\t\tactiveCommentId={ activeCommentId }\n\t\t\t\t\t\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\t\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\t\t\t\tfirstCommentId={ commentTree[ 0 ]?.commentId }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</BlockContextProvider>\n\t\t\t\t\t)\n\t\t\t\t) }\n\t\t</ol>\n\t);\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-template/save.tsx\n/**\n * External dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function ReviewTemplateSave() {\n\treturn <InnerBlocks.Content />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a WordPress extension allowing seamless product variation browsing and selection, with integrated cart functionality for immediate purchase." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/block.json\n{\n\t\"name\": \"woocommerce/add-to-cart-with-options-variation-selector\",\n\t\"title\": \"Variation Selector (Beta)\",\n\t\"description\": \"Display any product variations available to select from and add to cart.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"usesContext\": [ \"postId\" ],\n\t\"ancestor\": [ \"woocommerce/add-to-cart-with-options\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"supports\": {\n\t\t\"interactivity\": true\n\t},\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"viewScriptModule\": \"woocommerce/add-to-cart-with-options-variation-selector\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\nimport { BlockEditProps } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { ATTRIBUTE_ITEM_TEMPLATE } from './attribute/constants';\n\ninterface Attributes {\n\tclassName?: string;\n}\n\nexport default function AddToCartWithOptionsVariationSelectorEdit(\n\tprops: BlockEditProps< Attributes >\n) {\n\tconst { className } = props.attributes;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName,\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: ATTRIBUTE_ITEM_TEMPLATE,\n\t\ttemplateLock: 'all',\n\t} );\n\n\treturn <div { ...innerBlocksProps } />;\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport default function AddToCartWithOptionsVariationSelectorSave() {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( {\n\t\t...blockProps,\n\t\trole: 'list',\n\t} );\n\treturn <div { ...innerBlocksProps } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Implement a Gutenberg block for Display a group of products that can be added to the cart." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/block.json\n{\n\t\"name\": \"woocommerce/add-to-cart-with-options-grouped-product-selector\",\n\t\"title\": \"Grouped Product Selector (Beta)\",\n\t\"description\": \"Display a group of products that can be added to the cart.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"usesContext\": [ \"postId\" ],\n\t\"ancestor\": [ \"woocommerce/add-to-cart-with-options\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"supports\": {\n\t\t\"interactivity\": true\n\t},\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"viewScriptModule\": \"woocommerce/add-to-cart-with-options-grouped-product-selector\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\nimport { type BlockEditProps } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { GROUPED_PRODUCT_ITEM_TEMPLATE } from './product-item/constants';\n\ninterface Attributes {\n\tclassName?: string;\n}\n\nexport default function AddToCartWithOptionsGroupedProductSelectorEdit(\n\tprops: BlockEditProps< Attributes >\n) {\n\tconst { className } = props.attributes;\n\tconst blockProps = useBlockProps( {\n\t\tclassName,\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: GROUPED_PRODUCT_ITEM_TEMPLATE,\n\t\ttemplateLock: 'all',\n\t} );\n\n\treturn <div { ...innerBlocksProps } />;\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport default function AddToCartWithOptionsGroupedProductSelectorSave() {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( {\n\t\t...blockProps,\n\t\trole: 'list',\n\t} );\n\treturn <div { ...innerBlocksProps } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Engineer a versatile block mechanism for rendering post comments that provides flexible configuration options for tag naming and legacy 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/comments/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/comments\",\n\t\"title\": \"Comments\",\n\t\"category\": \"theme\",\n\t\"description\": \"An advanced block that allows displaying post comments using different visual configurations.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"tagName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"div\"\n\t\t},\n\t\t\"legacy\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"heading\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-comments-editor\",\n\t\"usesContext\": [ \"postId\", \"postType\" ]\n}\n\n\n// File: packages/block-library/src/comments/index.js\n/**\n * WordPress dependencies\n */\nimport { postComments as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport save from './save';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {},\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/comments/save.js\n/**\n * WordPress dependencies\n */\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes: { tagName: Tag, legacy } } ) {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\n\t// The legacy version is dynamic (i.e. PHP rendered) and doesn't allow inner\n\t// blocks, so nothing is saved in that case.\n\treturn legacy ? null : <Tag { ...innerBlocksProps } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Implement a Gutenberg block for Block: a8c/bauhaus-centenary" }, { "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: blocks/bauhaus-centenary/src/index.js\n/**\n * WordPress dependencies\n */\nimport { registerBlockType } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport Edit from './edit';\nimport Save from './save';\nimport { BauhausIcon } from './icon';\n\nexport const registerBlock = () => {\n\tregisterBlockType( 'a8c/bauhaus-centenary', {\n\t\ttitle: 'Bauhaus Centenary',\n\t\tdescription: __( 'Celebrate the centenary of the design school', 'bauhaus-centenary' ),\n\t\ticon: BauhausIcon,\n\t\tcategory: 'widgets',\n\t\tsupports: {\n\t\t\talign: true,\n\t\t},\n\t\tattributes: {\n\t\t\talign: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: 'center',\n\t\t\t},\n\t\t\tcaption: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\theight: {\n\t\t\t\ttype: 'integer',\n\t\t\t\tdefault: 128,\n\t\t\t},\n\t\t\tcategory: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tbackgroundColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tcustomBackgroundColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tfill1Color: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tfill2Color: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tfill3Color: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tyear: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '1919',\n\t\t\t},\n\t\t},\n\t\tedit: ( props ) => <Edit { ...props } />,\n\t\tsave: ( props ) => <Save { ...props } />,\n\t} );\n};\n\n\n// File: blocks/bauhaus-centenary/src/save.js\n/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { RichText, getColorClassName } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport categories from './categories';\n\nconst Save = ( { attributes, className } ) => {\n\tconst Category = categories[ attributes.category ];\n\n\tconst style = {\n\t\tbackgroundColor: attributes.customBackgroundColor,\n\t};\n\n\tconst classNames = classnames(\n\t\tclassName,\n\t\t{ [ `align${ attributes.align }` ]: attributes.align },\n\t\tgetColorClassName( 'background-color', attributes.backgroundColor ),\n\t);\n\n\treturn (\n\t\t<figure className={ classNames } style={ style }>\n\t\t\t<Category.Content attributes={ attributes } />\n\t\t\t{ ! RichText.isEmpty( attributes.caption ) && <RichText.Content tagName=\"figcaption\" value={ attributes.caption } /> }\n\t\t</figure>\n\t);\n};\n\nexport default Save;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a WordPress block to Add a way of selecting a child product within the Grouped Product block. Depending on the type of product and its properties, this might be a button, a checkbox, or a link." }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item-selector/block.json\n{\n\t\"name\": \"woocommerce/add-to-cart-with-options-grouped-product-item-selector\",\n\t\"title\": \"Grouped Product: Item Selector (Beta)\",\n\t\"description\": \"Add a way of selecting a child product within the Grouped Product block. Depending on the type of product and its properties, this might be a button, a checkbox, or a link.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"usesContext\": [ \"postId\" ],\n\t\"ancestor\": [ \"woocommerce/add-to-cart-with-options-grouped-product-item\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"supports\": {\n\t\t\"inserter\": false,\n\t\t\"interactivity\": true\n\t},\n\t\"style\": \"file:../woocommerce/add-to-cart-with-options-grouped-product-item-selector-style.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item-selector/edit.tsx\n/**\n * External dependencies\n */\nimport { useProductDataContext } from '@woocommerce/shared-context';\nimport { Disabled, Spinner } from '@wordpress/components';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\nimport { isProductResponseItem } from '@woocommerce/entities';\n\n/**\n * Internal dependencies\n */\nimport QuantityStepper from '../../components/quantity-stepper';\n\nconst CTA = () => {\n\tconst { isLoading, product } = useProductDataContext();\n\n\tif ( isLoading || ! isProductResponseItem( product ) ) {\n\t\treturn <Spinner />;\n\t}\n\n\tconst {\n\t\tpermalink,\n\t\tadd_to_cart: productCartDetails,\n\t\thas_options: hasOptions,\n\t\tis_purchasable: isPurchasable,\n\t\tis_in_stock: isInStock,\n\t\tsold_individually: soldIndividually,\n\t} = product;\n\n\tif ( ! hasOptions && isPurchasable && isInStock ) {\n\t\tif ( soldIndividually ) {\n\t\t\treturn (\n\t\t\t\t<input\n\t\t\t\t\ttype=\"checkbox\"\n\t\t\t\t\tvalue=\"1\"\n\t\t\t\t\tclassName=\"wc-grouped-product-add-to-cart-checkbox\"\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\t\treturn <QuantityStepper />;\n\t}\n\n\treturn (\n\t\t<a\n\t\t\taria-label={ productCartDetails?.description || '' }\n\t\t\tclassName=\"button wp-element-button add_to_cart_button wc-block-components-product-button__button\"\n\t\t\thref={ permalink }\n\t\t>\n\t\t\t{ productCartDetails?.text || __( 'Add to Cart', 'woocommerce' ) }\n\t\t</a>\n\t);\n};\n\nexport default function ProductItemCTAEdit() {\n\tconst blockProps = useBlockProps( {\n\t\tclassName:\n\t\t\t'wc-block-add-to-cart-with-options-grouped-product-item-selector',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Disabled>\n\t\t\t\t<CTA />\n\t\t\t</Disabled>\n\t\t</div>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Craft a rating display block that provides flexibility in setting product details, including its ID, query loop hierarchy, text positioning, and two supplementary user-defined options." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.json\n{\n\t\"name\": \"woocommerce/product-rating\",\n\t\"icon\": \"info\",\n\t\"title\": \"Product Rating\",\n\t\"description\": \"Display the average rating of a product.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"attributes\": {\n\t\t\"productId\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"isDescendentOfQueryLoop\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"isDescendentOfSingleProductBlock\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isDescendentOfSingleProductTemplate\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": false,\n\t\t\t\"link\": false,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"__experimentalSelector\": \".wc-block-components-product-rating\"\n\t},\n\t\"ancestor\": [\n\t\t\"woocommerce/all-products\",\n\t\t\"woocommerce/single-product\",\n\t\t\"woocommerce/product-template\",\n\t\t\"core/post-template\"\n\t],\n\t\"usesContext\": [ \"query\", \"queryId\", \"postId\" ],\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/index.ts\n/**\n * External dependencies\n */\nimport type { BlockConfiguration } from '@wordpress/blocks';\nimport { registerProductBlockType } from '@woocommerce/atomic-utils';\n\n/**\n * Internal dependencies\n */\nimport save from '../save';\nimport edit from './edit';\nimport { BLOCK_ICON as icon } from './constants';\nimport metadata from './block.json';\n\nconst blockConfig: BlockConfiguration = {\n\t...metadata,\n\ticon: { src: icon },\n\tedit,\n\tsave,\n};\n\nregisterProductBlockType( blockConfig, {\n\tisAvailableOnPostEditor: true,\n} );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Craft a custom Gutenberg block designed to showcase post or page URLs, incorporating configurable attributes for content display and link targeting behavior." }, { "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/read-more/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/read-more\",\n\t\"title\": \"Read More\",\n\t\"category\": \"theme\",\n\t\"description\": \"Displays the link of a post, page, or any other content-type.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"content\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"_self\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\" ],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"text\": 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\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true,\n\t\t\t\t\"textDecoration\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\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\"style\": \"wp-block-read-more\"\n}\n\n\n// File: packages/block-library/src/read-more/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { link as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\texample: {\n\t\tattributes: {\n\t\t\tcontent: __( 'Read more' ),\n\t\t},\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Display a grid of your top rated products. that allows users to configure: 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-top-rated/block.json\n{\n\t\"name\": \"woocommerce/product-top-rated\",\n\t\"title\": \"Top Rated Products\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"Display a grid of your top rated 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\": \"rating\"\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-top-rated/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { ProductTopRatedBlock } 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<ProductTopRatedBlock { ...props } />\n\t\t</div>\n\t);\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a WooCommerce block featuring configurable locking functionality that allows users to customize access and security settings." }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/proceed-to-checkout-block/block.json\n{\n\t\"name\": \"woocommerce/proceed-to-checkout-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Proceed to Checkout\",\n\t\"description\": \"Allow customers proceed to Checkout.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/cart-totals-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/proceed-to-checkout-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport EditableButton from '@woocommerce/editor-components/editable-button';\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport PageSelector from '@woocommerce/editor-components/page-selector';\nimport { CART_PAGE_ID } from '@woocommerce/block-settings';\n\n/**\n * Internal dependencies\n */\nimport { defaultButtonLabel } from './constants';\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: {\n\t\tcheckoutPageId: number;\n\t\tclassName: string;\n\t\tbuttonLabel: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst { checkoutPageId = 0, buttonLabel } = attributes;\n\tconst { current: savedCheckoutPageId } = useRef( checkoutPageId );\n\n\tconst currentPostId = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! savedCheckoutPageId ) {\n\t\t\t\tconst store = select( 'core/editor' );\n\t\t\t\treturn store.getCurrentPostId();\n\t\t\t}\n\t\t\treturn savedCheckoutPageId;\n\t\t},\n\t\t[ savedCheckoutPageId ]\n\t);\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls>\n\t\t\t\t{ ! (\n\t\t\t\t\tcurrentPostId === CART_PAGE_ID && savedCheckoutPageId === 0\n\t\t\t\t) && (\n\t\t\t\t\t<PageSelector\n\t\t\t\t\t\tpageId={ checkoutPageId }\n\t\t\t\t\t\tsetPageId={ ( id: number ) =>\n\t\t\t\t\t\t\tsetAttributes( { checkoutPageId: id } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlabels={ {\n\t\t\t\t\t\t\ttitle: __(\n\t\t\t\t\t\t\t\t'Proceed to Checkout button',\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\tdefault: __(\n\t\t\t\t\t\t\t\t'WooCommerce Checkout Page',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</InspectorControls>\n\t\t\t<EditableButton\n\t\t\t\tclassName=\"wc-block-cart__submit-button\"\n\t\t\t\tvalue={ buttonLabel }\n\t\t\t\tplaceholder={ defaultButtonLabel }\n\t\t\t\tonChange={ ( content ) => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\tbuttonLabel: content,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Craft a custom Gutenberg block for an Accordion Panel, incorporating attributes like allowed block types, template locking, default open state, and selection status." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/inner-blocks/accordion-panel/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/accordion-panel\",\n\t\"title\": \"Accordion Panel\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"Accordion Panel\",\n\t\"example\": {},\n\t\"__experimental\": true,\n\t\"parent\": [ \"woocommerce/accordion-item\" ],\n\t\"supports\": {\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"gradient\": true\n\t\t},\n\t\t\"border\": true,\n\t\t\"interactivity\": true,\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"blockGap\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true,\n\t\t\t\t\"blockGap\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"shadow\": true,\n\t\t\"layout\": true\n\t},\n\t\"attributes\": {\n\t\t\"allowedBlocks\": {\n\t\t\t\"type\": \"array\"\n\t\t},\n\t\t\"templateLock\": {\n\t\t\t\"type\": [ \"string\", \"boolean\" ],\n\t\t\t\"enum\": [ \"all\", \"insert\", \"contentOnly\", false ],\n\t\t\t\"default\": false\n\t\t},\n\t\t\"openByDefault\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isSelected\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/inner-blocks/accordion-panel/index.js\n/**\n * External dependencies\n */\nimport { SVG, Path } from '@wordpress/components';\nimport { registerBlockType } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport edit from './edit';\nimport save from './save';\nimport metadata from './block.json';\n\nconst icon = (\n\t<SVG\n\t\twidth=\"24\"\n\t\theight=\"24\"\n\t\tviewBox=\"0 0 24 24\"\n\t\tfill=\"none\"\n\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t>\n\t\t<Path\n\t\t\tfillRule=\"evenodd\"\n\t\t\tclipRule=\"evenodd\"\n\t\t\td=\"M8.10417 6.00024H6.5C5.39543 6.00024 4.5 6.89567 4.5 8.00024V10.3336H6V8.00024C6 7.7241 6.22386 7.50024 6.5 7.50024H8.10417V6.00024ZM4.5 13.6669V16.0002C4.5 17.1048 5.39543 18.0002 6.5 18.0002H8.10417V16.5002H6.5C6.22386 16.5002 6 16.2764 6 16.0002V13.6669H4.5ZM10.3958 6.00024V7.50024H13.6042V6.00024H10.3958ZM15.8958 6.00024V7.50024H17.5C17.7761 7.50024 18 7.7241 18 8.00024V10.3336H19.5V8.00024C19.5 6.89567 18.6046 6.00024 17.5 6.00024H15.8958ZM19.5 13.6669H18V16.0002C18 16.2764 17.7761 16.5002 17.5 16.5002H15.8958V18.0002H17.5C18.6046 18.0002 19.5 17.1048 19.5 16.0002V13.6669ZM13.6042 18.0002V16.5002H10.3958V18.0002H13.6042Z\"\n\t\t\tfill=\"currentColor\"\n\t\t/>\n\t</SVG>\n);\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\tapiVersion: 3,\n\ticon,\n\texample: {},\n\tedit,\n\tsave,\n};\n\nregisterBlockType( metadata, settings );\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/inner-blocks/accordion-panel/save.js\n/**\n * External dependencies\n */\nimport {\n\tInnerBlocks,\n\tuseBlockProps,\n\t__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,\n\t__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,\n\t__experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles,\n\t__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,\n} from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\nexport default function save( { attributes } ) {\n\tconst blockProps = useBlockProps.save();\n\tconst borderProps = getBorderClassesAndStyles( attributes );\n\tconst colorProps = getColorClassesAndStyles( attributes );\n\tconst spacingProps = getSpacingClassesAndStyles( attributes );\n\tconst shadowProps = getShadowClassesAndStyles( attributes );\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\tclassName={ clsx(\n\t\t\t\tblockProps.className,\n\t\t\t\tcolorProps.className,\n\t\t\t\tborderProps.className,\n\t\t\t\t{\n\t\t\t\t\t[ `has-custom-font-size` ]: blockProps?.style?.fontSize,\n\t\t\t\t}\n\t\t\t) }\n\t\t\tstyle={ {\n\t\t\t\t...borderProps.style,\n\t\t\t\t...colorProps.style,\n\t\t\t\t...shadowProps.style,\n\t\t\t} }\n\t\t>\n\t\t\t<div\n\t\t\t\tclassName=\"accordion-content__wrapper\"\n\t\t\t\tstyle={ {\n\t\t\t\t\t...spacingProps.style,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<InnerBlocks.Content />\n\t\t\t</div>\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 widget block enabling custom parent page identification with inherent nesting capabilities." }, { "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/page-list/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/page-list\",\n\t\"title\": \"Page List\",\n\t\"category\": \"widgets\",\n\t\"allowedBlocks\": [ \"core/page-list-item\" ],\n\t\"description\": \"Display a list of all pages.\",\n\t\"keywords\": [ \"menu\", \"navigation\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"parentPageID\": {\n\t\t\t\"type\": \"integer\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"isNested\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"usesContext\": [\n\t\t\"textColor\",\n\t\t\"customTextColor\",\n\t\t\"backgroundColor\",\n\t\t\"customBackgroundColor\",\n\t\t\"overlayTextColor\",\n\t\t\"customOverlayTextColor\",\n\t\t\"overlayBackgroundColor\",\n\t\t\"customOverlayBackgroundColor\",\n\t\t\"fontSize\",\n\t\t\"customFontSize\",\n\t\t\"showSubmenuIcon\",\n\t\t\"style\",\n\t\t\"openSubmenusOnClick\"\n\t],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true,\n\t\t\t\"link\": true,\n\t\t\t\"gradients\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": false,\n\t\t\t\t\"margin\": false\n\t\t\t}\n\t\t},\n\t\t\"contentRole\": true\n\t},\n\t\"editorStyle\": \"wp-block-page-list-editor\",\n\t\"style\": \"wp-block-page-list\"\n}\n\n\n// File: packages/block-library/src/page-list/index.js\n/**\n * WordPress dependencies\n */\nimport { pages } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit.js';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon: pages,\n\texample: {},\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Display a link to the cart. that allows users to configure: is preview, cart icon, 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: plugins/woocommerce/client/blocks/assets/js/blocks/cart-link/block.json\n{\n\t\"name\": \"woocommerce/cart-link\",\n\t\"title\": \"Cart Link\",\n\t\"icon\": \"cart\",\n\t\"description\": \"Display a link to the cart.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"text\": false,\n\t\t\t\"link\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"isPreview\": true,\n\t\t\t\"cartIcon\": \"cart\",\n\t\t\t\"content\": \"Cart\"\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"isPreview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"cartIcon\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"cart\"\n\t\t},\n\t\t\"content\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": null\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/cart-link/edit.tsx\n/* eslint-disable @wordpress/no-unsafe-wp-apis */\n/**\n * External dependencies\n */\nimport {\n\tInspectorControls,\n\tuseBlockProps,\n\tPlainText,\n} from '@wordpress/block-editor';\nimport { cartOutline, bag, bagAlt } from '@woocommerce/icons';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tIcon,\n\tPanelBody,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport './style.scss';\nimport './editor.scss';\nimport QuantityBadge from '../mini-cart/quantity-badge';\n\nexport interface Attributes {\n\tcartIcon: 'cart' | 'bag' | 'bag-alt';\n\tcontent: string;\n}\n\ninterface Props {\n\tattributes: Attributes;\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n}\n\nconst Edit = ( { attributes, setAttributes }: Props ): JSX.Element => {\n\tconst { cartIcon, content } = attributes;\n\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<ToggleGroupControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"wc-block-editor-mini-cart__cart-icon-toggle\"\n\t\t\t\t\t\tisBlock\n\t\t\t\t\t\tlabel={ __( 'Cart Icon', 'woocommerce' ) }\n\t\t\t\t\t\tvalue={ cartIcon }\n\t\t\t\t\t\tonChange={ ( value: 'cart' | 'bag' | 'bag-alt' ) => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tcartIcon: value,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue={ 'cart' }\n\t\t\t\t\t\t\tlabel={ <Icon size={ 32 } icon={ cartOutline } /> }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue={ 'bag' }\n\t\t\t\t\t\t\tlabel={ <Icon size={ 32 } icon={ bag } /> }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue={ 'bag-alt' }\n\t\t\t\t\t\t\tlabel={ <Icon size={ 32 } icon={ bagAlt } /> }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<a\n\t\t\t\tclassName=\"wc-block-cart-link\"\n\t\t\t\thref={ '#cart-pseudo-link' }\n\t\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t\t>\n\t\t\t\t<QuantityBadge\n\t\t\t\t\ticon={ cartIcon }\n\t\t\t\t\tproductCountVisibility={ 'never' }\n\t\t\t\t/>\n\t\t\t\t<PlainText\n\t\t\t\t\tclassName=\"wc-block-cart-link__text\"\n\t\t\t\t\tvalue={\n\t\t\t\t\t\tcontent !== null ? content : __( 'Cart', 'woocommerce' )\n\t\t\t\t\t}\n\t\t\t\t\t__experimentalVersion={ 2 }\n\t\t\t\t\tonChange={ ( value: string ) =>\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tcontent: value,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t\tstyle={ { backgroundColor: 'transparent', resize: 'none' } }\n\t\t\t\t/>\n\t\t\t</a>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for A form. that allows users to configure: submission method, method, action, email" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/form/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"__experimental\": true,\n\t\"name\": \"core/form\",\n\t\"title\": \"Form\",\n\t\"category\": \"common\",\n\t\"allowedBlocks\": [\n\t\t\"core/paragraph\",\n\t\t\"core/heading\",\n\t\t\"core/form-input\",\n\t\t\"core/form-submit-button\",\n\t\t\"core/form-submission-notification\",\n\t\t\"core/group\",\n\t\t\"core/columns\"\n\t],\n\t\"description\": \"A form.\",\n\t\"keywords\": [ \"container\", \"wrapper\", \"row\", \"section\" ],\n\t\"textdomain\": \"default\",\n\t\"icon\": \"feedback\",\n\t\"attributes\": {\n\t\t\"submissionMethod\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"email\"\n\t\t},\n\t\t\"method\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"post\"\n\t\t},\n\t\t\"action\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"email\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"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\"__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}\n}\n\n\n// File: packages/block-library/src/form/index.js\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 variations from './variations';\nimport deprecated from './deprecated';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\tedit,\n\tsave,\n\tdeprecated,\n\tvariations,\n\texample: {},\n};\n\nexport const init = () => {\n\t// Prevent adding forms inside forms.\n\tconst DISALLOWED_PARENTS = [ 'core/form' ];\n\taddFilter(\n\t\t'blockEditor.__unstableCanInsertBlockType',\n\t\t'core/block-library/preventInsertingFormIntoAnotherForm',\n\t\t(\n\t\t\tcanInsert,\n\t\t\tblockType,\n\t\t\trootClientId,\n\t\t\t{ getBlock, getBlockParentsByBlockName }\n\t\t) => {\n\t\t\tif ( blockType.name !== 'core/form' ) {\n\t\t\t\treturn canInsert;\n\t\t\t}\n\n\t\t\tfor ( const disallowedParentType of DISALLOWED_PARENTS ) {\n\t\t\t\tconst hasDisallowedParent =\n\t\t\t\t\tgetBlock( rootClientId )?.name === disallowedParentType ||\n\t\t\t\t\tgetBlockParentsByBlockName(\n\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\tdisallowedParentType\n\t\t\t\t\t).length;\n\t\t\t\tif ( hasDisallowedParent ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t);\n\n\treturn initBlock( { name, metadata, settings } );\n};\n\n\n// File: packages/block-library/src/form/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst blockProps = useBlockProps.save();\n\tconst { submissionMethod } = attributes;\n\n\treturn (\n\t\t<form\n\t\t\t{ ...blockProps }\n\t\t\tencType={ submissionMethod === 'email' ? 'text/plain' : null }\n\t\t>\n\t\t\t<InnerBlocks.Content />\n\t\t</form>\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 Gutenberg block for Block: a8c/book" }, { "role": "assistant", "content": "// File: blocks/book/src/index.js\n/**\n * WordPress dependencies\n */\nimport { registerBlockType } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * External dependencies\n */\nimport { BookIcon } from './icon';\n\n/**\n * Internal dependencies\n */\nimport Edit from './edit';\nimport save from './save';\n\n/**\n * Every block starts by registering a new block type definition.\n *\n * @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block\n */\nexport function registerBlock() {\n\tregisterBlockType( 'a8c/book', {\n\t\tattributes: {\n\t\t\tauthor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\theight: {\n\t\t\t\ttype: 'number',\n\t\t\t},\n\t\t\timageId: {\n\t\t\t\ttype: 'number',\n\t\t\t},\n\t\t\timageUrl: {\n\t\t\t\ttype: 'string',\n\t\t\t\tsource: 'attribute',\n\t\t\t\tselector: 'img',\n\t\t\t\tattribute: 'src',\n\t\t\t},\n\t\t\tpublisher: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tpublicationDate: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tsummary: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\ttitle: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\twidth: {\n\t\t\t\ttype: 'number',\n\t\t\t},\n\t\t},\n\n\t\ttitle: __( 'Book', 'a8c' ),\n\t\tdescription: __(\n\t\t\t'Show a book with cover and metadata such as author and publisher.',\n\t\t\t'a8c'\n\t\t),\n\n\t\tcategory: 'widgets',\n\t\ticon: BookIcon,\n\n\t\tsupports: {\n\t\t\t// Removes support for an HTML mode.\n\t\t\thtml: false,\n\t\t\talign: [ 'left', 'center', 'right' ],\n\t\t\tlightBlockWrapper: true,\n\t\t},\n\n\t\tedit: Edit,\n\t\tsave,\n\t} );\n}\n\n\n// File: blocks/book/src/save.js\nimport { RichText } from '@wordpress/block-editor';\n/**\n * Retrieves the translation of text.\n *\n * @see https://developer.wordpress.org/block-editor/packages/packages-i18n/\n */\nimport { __ } from '@wordpress/i18n';\n\nimport classnames from 'classnames';\nimport prefixClasses from './prefixClasses';\n\n/**\n * The save function defines the way in which the different attributes should\n * be combined into the final markup, which is then serialized by the block\n * editor into `post_content`.\n *\n * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save\n *\n * @return {WPElement} Element to render.\n */\nexport default function save( { className, attributes } ) {\n\tconst {\n\t\tauthor,\n\t\timageId,\n\t\timageUrl,\n\t\tpublicationDate,\n\t\tpublisher,\n\t\ttitle,\n\t\twidth,\n\t} = attributes;\n\tconst hasMedia = !! imageId;\n\n\tconst classes = classnames( 'wp-block-a8c-book', className );\n\n\treturn (\n\t\t<div className={ classes }>\n\t\t\t{ hasMedia && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ prefixClasses( '__cover' ) }\n\t\t\t\t\tstyle={ { width } }\n\t\t\t\t>\n\t\t\t\t\t<img src={ imageUrl } alt={ imageId } />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<div className={ prefixClasses( '__meta' ) } style={ { width } }>\n\t\t\t\t{ title && (\n\t\t\t\t\t<RichText.Content\n\t\t\t\t\t\ttagName=\"p\"\n\t\t\t\t\t\tclassName={ prefixClasses( '__title' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ author && (\n\t\t\t\t\t<RichText.Content\n\t\t\t\t\t\ttagName=\"p\"\n\t\t\t\t\t\tclassName={ prefixClasses( '__author' ) }\n\t\t\t\t\t\tvalue={ author }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ publisher && (\n\t\t\t\t\t<RichText.Content\n\t\t\t\t\t\ttagName=\"p\"\n\t\t\t\t\t\tclassName={ prefixClasses( '__publisher' ) }\n\t\t\t\t\t\tvalue={ publisher }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ publicationDate && (\n\t\t\t\t\t<RichText.Content\n\t\t\t\t\t\ttagName=\"p\"\n\t\t\t\t\t\tclassName={ prefixClasses( '__publicationDate' ) }\n\t\t\t\t\t\tvalue={ publicationDate }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\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 text block module enabling users to modify ordering, values, type, and three extra options through intuitive configuration controls." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/list/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/list\",\n\t\"title\": \"List\",\n\t\"category\": \"text\",\n\t\"allowedBlocks\": [ \"core/list-item\" ],\n\t\"description\": \"An organized collection of items displayed in a specific order.\",\n\t\"keywords\": [ \"bullet list\", \"ordered list\", \"numbered list\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"ordered\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false,\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"values\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"html\",\n\t\t\t\"selector\": \"ol,ul\",\n\t\t\t\"multiline\": \"li\",\n\t\t\t\"default\": \"\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"type\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"start\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"reversed\": {\n\t\t\t\"type\": \"boolean\"\n\t\t},\n\t\t\"placeholder\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\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\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\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\"__unstablePasteTextInline\": true,\n\t\t\"__experimentalOnMerge\": true,\n\t\t\"__experimentalSlashInserter\": true,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"selectors\": {\n\t\t\"border\": \".wp-block-list:not(.wp-block-list .wp-block-list)\"\n\t},\n\t\"editorStyle\": \"wp-block-list-editor\",\n\t\"style\": \"wp-block-list\"\n}\n\n\n// File: packages/block-library/src/list/index.js\n/**\n * WordPress dependencies\n */\nimport { list as icon } from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\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\nconst settings = {\n\ticon,\n\texample: {\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/list-item',\n\t\t\t\tattributes: { content: __( 'Alice.' ) },\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/list-item',\n\t\t\t\tattributes: { content: __( 'The White Rabbit.' ) },\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/list-item',\n\t\t\t\tattributes: { content: __( 'The Cheshire Cat.' ) },\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/list-item',\n\t\t\t\tattributes: { content: __( 'The Mad Hatter.' ) },\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/list-item',\n\t\t\t\tattributes: { content: __( 'The Queen of Hearts.' ) },\n\t\t\t},\n\t\t],\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport { settings };\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/list/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { ordered, type, reversed, start } = attributes;\n\tconst TagName = ordered ? 'ol' : 'ul';\n\treturn (\n\t\t<TagName\n\t\t\t{ ...useBlockProps.save( {\n\t\t\t\treversed,\n\t\t\t\tstart,\n\t\t\t\tstyle: {\n\t\t\t\t\tlistStyleType:\n\t\t\t\t\t\tordered && type !== 'decimal' ? type : undefined,\n\t\t\t\t},\n\t\t\t} ) }\n\t\t>\n\t\t\t<InnerBlocks.Content />\n\t\t</TagName>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Design a WordPress block enabling in-store navigation and page hierarchy tracking, with customizable text alignment, font scaling, and content positioning options for enhanced user orientation." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: 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": "Build a WordPress block to Let your visitors send you messages with the tap of a button." }, { "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/send-a-message/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/send-a-message\",\n\t\"title\": \"Send A Message\",\n\t\"description\": \"Let your visitors send you messages with the tap of a button.\",\n\t\"keywords\": [ \"whatsapp\", \"messenger\", \"contact\", \"support\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M21 6h-2v9H6v2c0 .55.45 1 1 1h11l4 4V7c0-.55-.45-1-1-1zm-4 6V3c0-.55-.45-1-1-1H3c-.55 0-1 .45-1 1v14l4-4h10c.55 0 1-.45 1-1z'/></svg>\",\n\t\"supports\": {\n\t\t\"html\": false\n\t},\n\t\"attributes\": {},\n\t\"example\": {}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/send-a-message/edit.js\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nexport default function SendAMessageEdit() {\n\tconst blockProps = useBlockProps();\n\t// Default template is single WhatsApp block until we offer\n\t// more services\n\tconst DEFAULT_TEMPLATE = [ [ 'jetpack/whatsapp-button', {} ] ];\n\tconst ALLOWED_BLOCKS = [ 'jetpack/whatsapp-button' ];\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks template={ DEFAULT_TEMPLATE } allowedBlocks={ ALLOWED_BLOCKS } />\n\t\t</div>\n\t);\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/send-a-message/save.js\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nexport default () => {\n\tconst blockProps = useBlockProps.save();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Display the order details section. that allows users to configure: 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/totals-wrapper/block.json\n{\n\t\"name\": \"woocommerce/order-confirmation-totals-wrapper\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Order Totals Section\",\n\t\"description\": \"Display the order details 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/totals-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-totals',\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 post's comments form. with these attributes: text align" }, { "role": "assistant", "content": "// File: packages/block-library/src/post-comments-form/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-comments-form\",\n\t\"title\": \"Comments Form\",\n\t\"category\": \"theme\",\n\t\"description\": \"Display a post's comments form.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\" ],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"heading\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-post-comments-form-editor\",\n\t\"style\": [\n\t\t\"wp-block-post-comments-form\",\n\t\t\"wp-block-buttons\",\n\t\t\"wp-block-button\"\n\t],\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"textAlign\": \"center\"\n\t\t}\n\t}\n}\n\n\n// File: packages/block-library/src/post-comments-form/index.js\n/**\n * WordPress dependencies\n */\nimport { postCommentsForm 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 WordPress block that renders a taxonomy term name with customizable text alignment, heading level, and optional linking functionality." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/term-name/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/term-name\",\n\t\"title\": \"Term Name\",\n\t\"category\": \"theme\",\n\t\"description\": \"Displays the name of a taxonomy term.\",\n\t\"keywords\": [ \"term title\" ],\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"termId\", \"taxonomy\" ],\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"level\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"isLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"levelOptions\": {\n\t\t\t\"type\": \"array\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"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\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"style\": \"wp-block-term-name\"\n}\n\n\n// File: packages/block-library/src/term-name/index.js\n/**\n * WordPress dependencies\n */\nimport { termName as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {},\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a WordPress block displaying post terms with customizable alignment, separator, and additional configurable parameters for flexible term presentation." }, { "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 block for Create a break between ideas or sections with a horizontal separator. that allows users to configure: opacity, 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/separator/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/separator\",\n\t\"title\": \"Separator\",\n\t\"category\": \"design\",\n\t\"description\": \"Create a break between ideas or sections with a horizontal separator.\",\n\t\"keywords\": [ \"horizontal-line\", \"hr\", \"divider\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"opacity\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"alpha-channel\"\n\t\t},\n\t\t\"tagName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [ \"hr\", \"div\" ],\n\t\t\t\"default\": \"hr\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"align\": [ \"center\", \"wide\", \"full\" ],\n\t\t\"color\": {\n\t\t\t\"enableContrastChecker\": false,\n\t\t\t\"__experimentalSkipSerialization\": true,\n\t\t\t\"gradients\": true,\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\"margin\": [ \"top\", \"bottom\" ]\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"styles\": [\n\t\t{ \"name\": \"default\", \"label\": \"Default\", \"isDefault\": true },\n\t\t{ \"name\": \"wide\", \"label\": \"Wide Line\" },\n\t\t{ \"name\": \"dots\", \"label\": \"Dots\" }\n\t],\n\t\"editorStyle\": \"wp-block-separator-editor\",\n\t\"style\": \"wp-block-separator\"\n}\n\n\n// File: packages/block-library/src/separator/index.js\n/**\n * WordPress dependencies\n */\nimport { separator 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';\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\tcustomColor: '#065174',\n\t\t\tclassName: 'is-style-wide',\n\t\t},\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/separator/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tgetColorClassName,\n\tuseBlockProps,\n\t__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,\n} from '@wordpress/block-editor';\n\nexport default function separatorSave( { attributes } ) {\n\tconst { backgroundColor, style, opacity, tagName: Tag } = attributes;\n\tconst customColor = style?.color?.background;\n\tconst colorProps = getColorClassesAndStyles( attributes );\n\t// The hr support changing color using border-color, since border-color\n\t// is not yet supported in the color palette, we use background-color.\n\n\t// The dots styles uses text for the dots, to change those dots color is\n\t// using color, not backgroundColor.\n\tconst colorClass = getColorClassName( 'color', backgroundColor );\n\n\tconst className = clsx(\n\t\t{\n\t\t\t'has-text-color': backgroundColor || customColor,\n\t\t\t[ colorClass ]: colorClass,\n\t\t\t'has-css-opacity': opacity === 'css',\n\t\t\t'has-alpha-channel-opacity': opacity === 'alpha-channel',\n\t\t},\n\t\tcolorProps.className\n\t);\n\n\tconst styles = {\n\t\tbackgroundColor: colorProps?.style?.backgroundColor,\n\t\tcolor: colorClass ? undefined : customColor,\n\t};\n\treturn <Tag { ...useBlockProps.save( { className, style: styles } ) } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a woocommerce block with customizable lock" }, { "role": "assistant", "content": "<|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-pickup-options-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-pickup-options-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Pickup Method\",\n\t\"description\": \"Shows local pickup locations.\",\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-pickup-options-block/edit.tsx\n/* eslint-disable @wordpress/no-unsafe-wp-apis */\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport { useSelect } from '@wordpress/data';\nimport { checkoutStore as checkoutStoreDescriptor } from '@woocommerce/block-data';\nimport { LOCAL_PICKUP_ENABLED } from '@woocommerce/block-settings';\nimport { Disabled } from '@wordpress/components';\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 | null => {\n\tconst { prefersCollection } = useSelect( ( select ) => {\n\t\tconst checkoutStore = select( checkoutStoreDescriptor );\n\t\treturn {\n\t\t\tprefersCollection: checkoutStore.prefersCollection(),\n\t\t};\n\t} );\n\tconst { className } = attributes;\n\n\tif ( ! prefersCollection || ! LOCAL_PICKUP_ENABLED ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<FormStepBlock\n\t\t\tattributes={ attributes }\n\t\t\tsetAttributes={ setAttributes }\n\t\t\tclassName={ clsx(\n\t\t\t\t'wc-block-checkout__shipping-method',\n\t\t\t\tclassName\n\t\t\t) }\n\t\t>\n\t\t\t<Disabled>\n\t\t\t\t<Block />\n\t\t\t</Disabled>\n\t\t\t<AdditionalFields block={ innerBlockAreas.PICKUP_LOCATION } />\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": "Develop a block for Block that displays the checkout button when the Mini-Cart has products. that allows users to configure: lock, checkout button label" }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-checkout-button-block/block.json\n{\n\t\"name\": \"woocommerce/mini-cart-checkout-button-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Mini-Cart Proceed to Checkout Button\",\n\t\"description\": \"Block that displays the checkout button when the Mini-Cart has products.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": true,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": false,\n\t\t\t\t\"move\": false\n\t\t\t}\n\t\t},\n\t\t\"checkoutButtonLabel\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"styles\": [\n\t\t{\n\t\t\t\"name\": \"fill\",\n\t\t\t\"label\": \"Fill\",\n\t\t\t\"isDefault\": true\n\t\t},\n\t\t{\n\t\t\t\"name\": \"outline\",\n\t\t\t\"label\": \"Outline\"\n\t\t}\n\t],\n\t\"parent\": [ \"woocommerce/mini-cart-footer-block\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-checkout-button-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport EditableButton from '@woocommerce/editor-components/editable-button';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport { defaultCheckoutButtonLabel } from './constants';\nimport { getVariant } from '../utils';\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: {\n\t\tcheckoutButtonLabel: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( 'wc-block-mini-cart__footer-checkout' ),\n\t} );\n\tconst { checkoutButtonLabel } = attributes;\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<EditableButton\n\t\t\t\tvariant={ getVariant( blockProps.className, 'contained' ) }\n\t\t\t\tvalue={ checkoutButtonLabel }\n\t\t\t\tplaceholder={ defaultCheckoutButtonLabel }\n\t\t\t\tonChange={ ( content ) => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\tcheckoutButtonLabel: content,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\tstyle={ blockProps.style }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() }></div>;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Craft a custom WordPress block that introduces adjustable white space between elements, featuring configurable height and width attributes for precise spacing management." }, { "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/spacer/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/spacer\",\n\t\"title\": \"Spacer\",\n\t\"category\": \"design\",\n\t\"description\": \"Add white space between blocks and customize its height.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"height\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"100px\"\n\t\t},\n\t\t\"width\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"orientation\" ],\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-spacer-editor\",\n\t\"style\": \"wp-block-spacer\"\n}\n\n\n// File: packages/block-library/src/spacer/index.js\n/**\n * WordPress dependencies\n */\nimport { resizeCornerNE 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 transforms from './transforms';\nimport save from './save';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\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/spacer/save.js\n/**\n * WordPress dependencies\n */\nimport { useBlockProps, getSpacingPresetCssVar } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { height, width, style } = attributes;\n\tconst { layout: { selfStretch } = {} } = style || {};\n\t// If selfStretch is set to 'fill' or 'fit', don't set default height.\n\tconst finalHeight =\n\t\tselfStretch === 'fill' || selfStretch === 'fit' ? undefined : height;\n\treturn (\n\t\t<div\n\t\t\t{ ...useBlockProps.save( {\n\t\t\t\tstyle: {\n\t\t\t\t\theight: getSpacingPresetCssVar( finalHeight ),\n\t\t\t\t\twidth: getSpacingPresetCssVar( width ),\n\t\t\t\t},\n\t\t\t\t'aria-hidden': true,\n\t\t\t} ) }\n\t\t/>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Describe in a few words what this site is about. This is important for search results, sharing on social media, and gives overall clarity to visitors. with these attributes: text align, level, level options" }, { "role": "assistant", "content": "// File: packages/block-library/src/site-tagline/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/site-tagline\",\n\t\"title\": \"Site Tagline\",\n\t\"category\": \"theme\",\n\t\"description\": \"Describe in a few words what this site is about. This is important for search results, sharing on social media, and gives overall clarity to visitors.\",\n\t\"keywords\": [ \"description\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\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\": 0\n\t\t},\n\t\t\"levelOptions\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": [ 0, 1, 2, 3, 4, 5, 6 ]\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"viewportWidth\": 350,\n\t\t\"attributes\": {\n\t\t\t\"textAlign\": \"center\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"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\"contentRole\": true,\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\"__experimentalTextTransform\": 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\"__experimentalWritingMode\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-site-tagline-editor\",\n\t\"style\": \"wp-block-site-tagline\"\n}\n\n\n// File: packages/block-library/src/site-tagline/index.js\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport icon from './icon';\nimport deprecated from './deprecated';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\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": "Create a Gutenberg block for Displays the description of the product." }, { "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-description/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-description\",\n\t\"title\": \"Product Description\",\n\t\"description\": \"Displays the description of the product.\",\n\t\"category\": \"woocommerce\",\n\t\"textdomain\": \"woocommerce\",\n\t\"usesContext\": [ \"postId\", \"postType\", \"queryId\" ],\n\t\"ancestor\": [\n\t\t\"woocommerce/single-product\",\n\t\t\"woocommerce/product-template\",\n\t\t\"core/post-template\"\n\t],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\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\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-description/edit.tsx\n/**\n * External dependencies\n */\nimport { useQueryLoopProductContextValidation } from '@woocommerce/base-hooks';\nimport {\n\tRecursionProvider,\n\tuseBlockProps,\n\tuseHasRecursion,\n\tWarning,\n} from '@wordpress/block-editor';\nimport { useEntityProp } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { ProductDescriptionEditProps } from './types';\n\nfunction Placeholder( { layoutClassNames } ) {\n\tconst blockProps = useBlockProps( { className: layoutClassNames } );\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<p>\n\t\t\t\t{ __(\n\t\t\t\t\t'This block displays the product description. When viewing a product page, the description content will automatically appear here.',\n\t\t\t\t\t'woocommerce'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t</div>\n\t);\n}\n\nfunction Content( props ) {\n\tconst { context: { postType, postId } = {}, layoutClassNames } = props;\n\n\tconst [ , , content ] = useEntityProp(\n\t\t'postType',\n\t\tpostType,\n\t\t'content',\n\t\tpostId\n\t);\n\tconst blockProps = useBlockProps( { className: layoutClassNames } );\n\n\treturn content?.protected ? (\n\t\t<div { ...blockProps }>\n\t\t\t<Warning>\n\t\t\t\t{ __( 'This content is password protected.', 'woocommerce' ) }\n\t\t\t</Warning>\n\t\t</div>\n\t) : (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\tdangerouslySetInnerHTML={ { __html: content?.rendered } }\n\t\t></div>\n\t);\n}\n\nfunction RecursionError() {\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Warning>\n\t\t\t\t{ __(\n\t\t\t\t\t'Block cannot be rendered inside itself.',\n\t\t\t\t\t'woocommerce'\n\t\t\t\t) }\n\t\t\t</Warning>\n\t\t</div>\n\t);\n}\n\nexport default function ProductDescriptionEdit( {\n\tcontext,\n\t__unstableLayoutClassNames: layoutClassNames,\n\t__unstableParentLayout: parentLayout,\n\tclientId,\n}: ProductDescriptionEditProps ) {\n\tconst { postId: contextPostId, postType: contextPostType } = context;\n\tconst hasAlreadyRendered = useHasRecursion( contextPostId );\n\tconst { hasInvalidContext, warningElement } =\n\t\tuseQueryLoopProductContextValidation( {\n\t\t\tclientId,\n\t\t\tpostType: contextPostType,\n\t\t\tblockName: __( 'Product Description', 'woocommerce' ),\n\t\t} );\n\tif ( hasInvalidContext ) {\n\t\treturn warningElement;\n\t}\n\n\tif ( contextPostId && contextPostType && hasAlreadyRendered ) {\n\t\treturn <RecursionError />;\n\t}\n\n\treturn (\n\t\t<RecursionProvider uniqueId={ contextPostId }>\n\t\t\t{ contextPostId && contextPostType ? (\n\t\t\t\t<Content\n\t\t\t\t\tcontext={ context }\n\t\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\t\tlayoutClassNames={ layoutClassNames }\n\t\t\t\t/>\n\t\t\t) : (\n\t\t\t\t<Placeholder layoutClassNames={ layoutClassNames } />\n\t\t\t) }\n\t\t</RecursionProvider>\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 custom WordPress block featuring flexible label modification capabilities for enhanced design control." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/home-link/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/home-link\",\n\t\"category\": \"design\",\n\t\"parent\": [ \"core/navigation\" ],\n\t\"title\": \"Home Link\",\n\t\"description\": \"Create a link that always points to the homepage of the site. Usually not necessary if there is already a site title link present in the header.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"label\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t}\n\t},\n\t\"usesContext\": [\n\t\t\"textColor\",\n\t\t\"customTextColor\",\n\t\t\"backgroundColor\",\n\t\t\"customBackgroundColor\",\n\t\t\"fontSize\",\n\t\t\"customFontSize\",\n\t\t\"style\"\n\t],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-home-link-editor\",\n\t\"style\": \"wp-block-home-link\"\n}\n\n\n// File: packages/block-library/src/home-link/index.js\n/**\n * WordPress dependencies\n */\nimport { _x } from '@wordpress/i18n';\nimport { home } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon: home,\n\n\tedit,\n\n\tsave,\n\n\texample: {\n\t\tattributes: {\n\t\t\tlabel: _x( 'Home Link', 'block example' ),\n\t\t},\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/home-link/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function save() {\n\treturn <InnerBlocks.Content />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that This block is deprecated. Please use the Columns block instead. with these attributes: content, columns, width" }, { "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/text-columns/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/text-columns\",\n\t\"title\": \"Text Columns (deprecated)\",\n\t\"icon\": \"columns\",\n\t\"category\": \"design\",\n\t\"description\": \"This block is deprecated. Please use the Columns block instead.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"content\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"source\": \"query\",\n\t\t\t\"selector\": \"p\",\n\t\t\t\"query\": {\n\t\t\t\t\"children\": {\n\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\"source\": \"html\"\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"default\": [ {}, {} ]\n\t\t},\n\t\t\"columns\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 2\n\t\t},\n\t\t\"width\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"inserter\": false,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-text-columns-editor\",\n\t\"style\": \"wp-block-text-columns\"\n}\n\n\n// File: packages/block-library/src/text-columns/index.js\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\ttransforms,\n\tgetEditWrapperProps( attributes ) {\n\t\tconst { width } = attributes;\n\t\tif ( 'wide' === width || 'full' === width ) {\n\t\t\treturn { 'data-align': width };\n\t\t}\n\t},\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/text-columns/save.js\n/**\n * WordPress dependencies\n */\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { width, content, columns } = attributes;\n\treturn (\n\t\t<div\n\t\t\t{ ...useBlockProps.save( {\n\t\t\t\tclassName: `align${ width } columns-${ columns }`,\n\t\t\t} ) }\n\t\t>\n\t\t\t{ Array.from( { length: columns } ).map( ( _, index ) => (\n\t\t\t\t<div className=\"wp-block-column\" key={ `column-${ index }` }>\n\t\t\t\t\t<RichText.Content\n\t\t\t\t\t\ttagName=\"p\"\n\t\t\t\t\t\tvalue={ content?.[ index ]?.children }\n\t\t\t\t\t/>\n\t\t\t\t</div>\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": "Develop a widget block featuring customizable icon styling with multiple configuration settings, including 9 total color and design 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/social-links/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/social-links\",\n\t\"title\": \"Social Icons\",\n\t\"category\": \"widgets\",\n\t\"allowedBlocks\": [ \"core/social-link\" ],\n\t\"description\": \"Display icons linking to your social profiles or sites.\",\n\t\"keywords\": [ \"links\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"iconColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customIconColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"iconColorValue\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"iconBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customIconBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"iconBackgroundColorValue\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"openInNewTab\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"showLabels\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"size\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"openInNewTab\": \"openInNewTab\",\n\t\t\"showLabels\": \"showLabels\",\n\t\t\"iconColor\": \"iconColor\",\n\t\t\"iconColorValue\": \"iconColorValue\",\n\t\t\"iconBackgroundColor\": \"iconBackgroundColor\",\n\t\t\"iconBackgroundColorValue\": \"iconBackgroundColorValue\"\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"left\", \"center\", \"right\" ],\n\t\t\"anchor\": true,\n\t\t\"html\": false,\n\t\t\"__experimentalExposeControlsToChildren\": true,\n\t\t\"layout\": {\n\t\t\t\"allowSwitching\": false,\n\t\t\t\"allowInheriting\": false,\n\t\t\t\"allowVerticalAlignment\": false,\n\t\t\t\"default\": {\n\t\t\t\t\"type\": \"flex\"\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"enableContrastChecker\": false,\n\t\t\t\"background\": true,\n\t\t\t\"gradients\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": false\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"blockGap\": [ \"horizontal\", \"vertical\" ],\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"units\": [ \"px\", \"em\", \"rem\", \"vh\", \"vw\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"blockGap\": true,\n\t\t\t\t\"margin\": true,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\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\t\"contentRole\": true\n\t},\n\t\"styles\": [\n\t\t{ \"name\": \"default\", \"label\": \"Default\", \"isDefault\": true },\n\t\t{ \"name\": \"logos-only\", \"label\": \"Logos Only\" },\n\t\t{ \"name\": \"pill-shape\", \"label\": \"Pill Shape\" }\n\t],\n\t\"editorStyle\": \"wp-block-social-links-editor\",\n\t\"style\": \"wp-block-social-links\"\n}\n\n\n// File: packages/block-library/src/social-links/index.js\n/**\n * WordPress dependencies\n */\nimport { share as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\texample: {\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/social-link',\n\t\t\t\tattributes: {\n\t\t\t\t\tservice: 'wordpress',\n\t\t\t\t\turl: 'https://wordpress.org',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/social-link',\n\t\t\t\tattributes: {\n\t\t\t\t\tservice: 'facebook',\n\t\t\t\t\turl: 'https://www.facebook.com/WordPress/',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/social-link',\n\t\t\t\tattributes: {\n\t\t\t\t\tservice: 'twitter',\n\t\t\t\t\turl: 'https://twitter.com/WordPress',\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n\ticon,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/social-links/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( props ) {\n\tconst {\n\t\tattributes: {\n\t\t\ticonBackgroundColorValue,\n\t\t\ticonColorValue,\n\t\t\tshowLabels,\n\t\t\tsize,\n\t\t},\n\t} = props;\n\n\tconst className = clsx( size, {\n\t\t'has-visible-labels': showLabels,\n\t\t'has-icon-color': iconColorValue,\n\t\t'has-icon-background-color': iconBackgroundColorValue,\n\t} );\n\tconst blockProps = useBlockProps.save( { className } );\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\n\treturn <ul { ...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 Search for and insert an animated image. with these attributes: align, caption, giphy url, 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: projects/plugins/jetpack/extensions/blocks/gif/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/gif\",\n\t\"title\": \"GIF\",\n\t\"description\": \"Search for and insert an animated image.\",\n\t\"keywords\": [ \"animated\", \"giphy\", \"image\" ],\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 fill='none' d='M0 0h24v24H0V0z'/><path d='M18 13v7H4V6h5.02c.05-.71.22-1.38.48-2H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2v-5l-2-2zm-1.5 5h-11l2.75-3.53 1.96 2.36 2.75-3.54L16.5 18zm2.8-9.11c.44-.7.7-1.51.7-2.39C20 4.01 17.99 2 15.5 2S11 4.01 11 6.5s2.01 4.5 4.49 4.5c.88 0 1.7-.26 2.39-.7L21 13.42 22.42 12 19.3 8.89zM15.5 9C14.12 9 13 7.88 13 6.5S14.12 4 15.5 4 18 5.12 18 6.5 16.88 9 15.5 9z'/></svg>\",\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"align\": true\n\t},\n\t\"attributes\": {\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"center\"\n\t\t},\n\t\t\"caption\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"giphyUrl\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"searchText\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"paddingTop\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"56.2%\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"align\": \"center\",\n\t\t\t\"giphyUrl\": \"https://giphy.com/embed/fxKWgoOG9hzPPkE1oc\",\n\t\t\t\"paddingTop\": \"100%\",\n\t\t\t\"searchText\": \"WordPress\"\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/gif/edit.js\nimport { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils';\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\nimport { Placeholder } from '@wordpress/components';\nimport { createRef, useState, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport metadata from './block.json';\nimport SearchForm from './components/search-form';\nimport Controls from './controls';\nimport useFetchGiphyData from './hooks/use-fetch-giphy-data';\nimport { getUrl, getSelectedGiphyAttributes } from './utils';\n\nconst icon = getBlockIconComponent( metadata );\n\nfunction GifEdit( { attributes, setAttributes, isSelected } ) {\n\tconst { align, caption, giphyUrl, searchText, paddingTop } = attributes;\n\tconst [ captionFocus, setCaptionFocus ] = useState( false );\n\tconst searchFormInputRef = createRef();\n\tconst { isFetching, giphyData, fetchGiphyData } = useFetchGiphyData();\n\tconst blockProps = useBlockProps();\n\n\tconst setSearchInputFocus = () => {\n\t\tsearchFormInputRef.current.focus();\n\t\tsetCaptionFocus( false );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! giphyUrl && giphyData && giphyData[ 0 ] ) {\n\t\t\tsetAttributes( getSelectedGiphyAttributes( giphyData[ 0 ] ) );\n\t\t}\n\t}, [ giphyUrl, giphyData, setAttributes ] );\n\n\tconst onSubmit = async event => {\n\t\tevent.preventDefault();\n\n\t\tif ( ! attributes.searchText || isFetching ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst url = await getUrl( attributes.searchText );\n\n\t\tif ( url ) {\n\t\t\tfetchGiphyData( url );\n\t\t}\n\t};\n\n\tconst onChange = event => setAttributes( { searchText: event.target.value } );\n\tconst onSelectThumbnail = thumbnail => setAttributes( getSelectedGiphyAttributes( thumbnail ) );\n\n\treturn (\n\t\t<div { ...blockProps } className={ clsx( blockProps.className, `align${ align }` ) }>\n\t\t\t<Controls />\n\t\t\t{ ! giphyUrl ? (\n\t\t\t\t<Placeholder\n\t\t\t\t\tclassName=\"wp-block-jetpack-gif_placeholder\"\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tlabel={ metadata.title }\n\t\t\t\t\tinstructions={ __( 'Search for a term or paste a Giphy URL', 'jetpack' ) }\n\t\t\t\t>\n\t\t\t\t\t<SearchForm\n\t\t\t\t\t\tonSubmit={ onSubmit }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tvalue={ searchText }\n\t\t\t\t\t\tref={ searchFormInputRef }\n\t\t\t\t\t/>\n\t\t\t\t</Placeholder>\n\t\t\t) : (\n\t\t\t\t<figure>\n\t\t\t\t\t{ isSelected && (\n\t\t\t\t\t\t<SearchForm\n\t\t\t\t\t\t\tonSubmit={ onSubmit }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\tvalue={ searchText }\n\t\t\t\t\t\t\tref={ searchFormInputRef }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ isSelected && giphyData && giphyData.length > 1 && (\n\t\t\t\t\t\t<div className=\"wp-block-jetpack-gif_thumbnails-container\">\n\t\t\t\t\t\t\t{ giphyData.map( thumbnail => {\n\t\t\t\t\t\t\t\tconst thumbnailStyle = {\n\t\t\t\t\t\t\t\t\tbackgroundImage: `url(${ thumbnail.images.downsized_still.url })`,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tclassName=\"wp-block-jetpack-gif_thumbnail-container\"\n\t\t\t\t\t\t\t\t\t\tkey={ thumbnail.id }\n\t\t\t\t\t\t\t\t\t\tonClick={ e => {\n\t\t\t\t\t\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\t\t\t\t\t\tonSelectThumbnail( thumbnail );\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\tstyle={ thumbnailStyle }\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</div>\n\t\t\t\t\t) }\n\t\t\t\t\t<div className=\"wp-block-jetpack-gif-wrapper\" style={ { paddingTop } }>\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName=\"wp-block-jetpack-gif_cover\"\n\t\t\t\t\t\t\tonClick={ setSearchInputFocus }\n\t\t\t\t\t\t\tonKeyDown={ setSearchInputFocus }\n\t\t\t\t\t\t\trole=\"button\"\n\t\t\t\t\t\t\ttabIndex=\"0\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<iframe src={ giphyUrl } title={ searchText } />\n\t\t\t\t\t</div>\n\t\t\t\t\t{ ( ! RichText.isEmpty( caption ) || isSelected ) && !! giphyUrl && (\n\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\tclassName=\"wp-block-jetpack-gif-caption gallery-caption\"\n\t\t\t\t\t\t\tinlineToolbar\n\t\t\t\t\t\t\tisSelected={ captionFocus }\n\t\t\t\t\t\t\tonFocus={ () => setCaptionFocus( false ) }\n\t\t\t\t\t\t\tonChange={ value => setAttributes( { caption: value } ) }\n\t\t\t\t\t\t\tplaceholder={ __( 'Write caption…', 'jetpack' ) }\n\t\t\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\t\t\tvalue={ caption }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</figure>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nexport default GifEdit;\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 featuring an appointment scheduling calendar, incorporating customizable attributes like background color, event type visibility, primary color, and three additional configuration options." }, { "role": "assistant", "content": "// File: projects/plugins/jetpack/extensions/blocks/calendly/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/calendly\",\n\t\"title\": \"Calendly\",\n\t\"description\": \"Embed a calendar for customers to schedule appointments.\",\n\t\"keywords\": [ \"calendar\", \"schedule\", \"appointments\", \"events\", \"dates\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg viewBox='0 0 23 24' width='23' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M19,1h-2.3v0c0-0.6-0.4-1-1-1c-0.6,0-1,0.4-1,1v0H8.6v0c0-0.6-0.4-1-1-1c-0.6,0-1,0.4-1,1v0H4C1.8,1,0,2.8,0,5 v15c0,2.2,1.8,4,4,4h15c2.2,0,4-1.8,4-4V5C23,2.8,21.2,1,19,1z M21,20c0,1.1-0.9,2-2,2H4c-1.1,0-2-0.9-2-2V5c0-1.1,0.9-2,2-2h2.6 v0.8c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1V3h6.1v0.8c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1V3H19c1.1,0,2,0.9,2,2V20z M13.9,14.8l1.4,1.4 c-0.9,0.9-2.1,1.3-3.5,1.3c-2.4,0-4.5-2.1-4.5-4.7s2.1-4.7,4.5-4.7c1.4,0,2.5,0.4,3.4,1.1L14,10.9c-0.5-0.4-1.2-0.6-2.1-0.6 c-1.2,0-2.5,1.1-2.5,2.7c0,1.6,1.3,2.7,2.5,2.7C12.7,15.5,13.4,15.3,13.9,14.8z'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"alignWide\": false,\n\t\t\"html\": false\n\t},\n\t\"attributes\": {\n\t\t\"backgroundColor\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"ffffff\"\n\t\t},\n\t\t\"hideEventTypeDetails\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"primaryColor\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"00A2FF\"\n\t\t},\n\t\t\"textColor\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"4D5055\"\n\t\t},\n\t\t\"style\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"inline\",\n\t\t\t\"enum\": [ \"inline\", \"link\" ]\n\t\t},\n\t\t\"url\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"hideEventTypeDetails\": false,\n\t\t\t\"style\": \"inline\",\n\t\t\t\"url\": \"https://calendly.com/wpcom/jetpack-block-example\"\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\": \"Schedule time with me\",\n\t\t\t\t\t\"uniqueId\": \"calendly-widget-id\",\n\t\t\t\t\t\"url\": \"https://calendly.com/wpcom/jetpack-block-example\"\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/calendly/edit.js\nimport { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils';\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\nimport { getBlockDefaultClassName } from '@wordpress/blocks';\nimport { Button, ExternalLink, Placeholder, Spinner, withNotices } from '@wordpress/components';\nimport { select, dispatch } from '@wordpress/data';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __, _x } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport { isEqual } from 'lodash';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport testEmbedUrl from '../../shared/test-embed-url';\nimport metadata from './block.json';\nimport { CALENDLY_EXAMPLE_URL } from './constants';\nimport CalendlyControls from './controls';\nimport { getAttributesFromEmbedCode } from './utils';\n\nimport './editor.scss';\nimport './view.scss';\n\nconst innerButtonBlock = {\n\tname: 'jetpack/button',\n\tattributes: {\n\t\telement: 'a',\n\t\ttext: __( 'Schedule time with me', 'jetpack' ),\n\t\tuniqueId: 'calendly-widget-id',\n\t\turl: CALENDLY_EXAMPLE_URL,\n\t},\n};\nconst icon = getBlockIconComponent( metadata );\n\nexport function CalendlyEdit( props ) {\n\tconst { attributes, clientId, name, noticeOperations, noticeUI, setAttributes } = props;\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 { backgroundColor, hideEventTypeDetails, primaryColor, textColor, style, url } =\n\t\tvalidatedAttributes;\n\tconst [ embedCode, setEmbedCode ] = useState( url );\n\tconst [ isEditingUrl, setIsEditingUrl ] = useState( false );\n\tconst [ isResolvingUrl, setIsResolvingUrl ] = useState( false );\n\tconst [ embedButtonAttributes, setEmbedButtonAttributes ] = useState( {} );\n\tconst blockProps = useBlockProps();\n\n\tconst setErrorNotice = () => {\n\t\tnoticeOperations.removeAllNotices();\n\t\tnoticeOperations.createErrorNotice(\n\t\t\t__( \"Your calendar couldn't be embedded. Please double check your URL or code.\", 'jetpack' )\n\t\t);\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! url || CALENDLY_EXAMPLE_URL === url || 'link' === style ) {\n\t\t\treturn;\n\t\t}\n\t\ttestEmbedUrl( url, setIsResolvingUrl ).catch( () => {\n\t\t\tsetAttributes( { url: undefined } );\n\t\t\tsetErrorNotice();\n\t\t} );\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [] );\n\n\tconst parseEmbedCode = event => {\n\t\tif ( ! event ) {\n\t\t\tsetErrorNotice();\n\t\t\treturn;\n\t\t}\n\n\t\tevent.preventDefault();\n\n\t\tconst newAttributes = getAttributesFromEmbedCode( embedCode );\n\t\tif ( ! newAttributes ) {\n\t\t\tsetErrorNotice();\n\t\t\treturn;\n\t\t}\n\n\t\tif ( newAttributes.buttonAttributes && 'link' === newAttributes.style ) {\n\t\t\tconst innerButtons = select( 'core/editor' ).getBlocksByClientId( clientId );\n\n\t\t\tif ( innerButtons.length ) {\n\t\t\t\tinnerButtons[ 0 ].innerBlocks.forEach( block => {\n\t\t\t\t\tdispatch( 'core/editor' ).updateBlockAttributes(\n\t\t\t\t\t\tblock.clientId,\n\t\t\t\t\t\tnewAttributes.buttonAttributes\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t}\n\t\t\tsetEmbedButtonAttributes( newAttributes.buttonAttributes );\n\t\t}\n\n\t\ttestEmbedUrl( newAttributes.url, setIsResolvingUrl )\n\t\t\t.then( () => {\n\t\t\t\tconst newValidatedAttributes = getValidatedAttributes( metadata.attributes, newAttributes );\n\t\t\t\tsetAttributes( newValidatedAttributes );\n\t\t\t\tsetIsEditingUrl( false );\n\t\t\t\tnoticeOperations.removeAllNotices();\n\t\t\t} )\n\t\t\t.catch( () => {\n\t\t\t\tsetAttributes( { url: undefined } );\n\t\t\t\tsetErrorNotice();\n\t\t\t} );\n\t};\n\n\tconst blockEmbedding = (\n\t\t<div className=\"wp-block-embed is-loading\">\n\t\t\t<Spinner />\n\t\t\t<p>{ __( 'Embedding…', 'jetpack' ) }</p>\n\t\t</div>\n\t);\n\n\tconst blockPlaceholder = (\n\t\t<Placeholder\n\t\t\tlabel={ __( 'Calendly', 'jetpack' ) }\n\t\t\tinstructions={ __( 'Enter your Calendly web address or embed code below.', 'jetpack' ) }\n\t\t\ticon={ icon }\n\t\t\tnotices={ noticeUI }\n\t\t>\n\t\t\t<form onSubmit={ parseEmbedCode }>\n\t\t\t\t<input\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\tid=\"embedCode\"\n\t\t\t\t\tonChange={ event => setEmbedCode( event.target.value ) }\n\t\t\t\t\tplaceholder={ __( 'Calendly web address or embed code…', 'jetpack' ) }\n\t\t\t\t\tvalue={ embedCode || '' }\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\t<div className={ `${ defaultClassName }-learn-more` }>\n\t\t\t\t<ExternalLink href=\"https://help.calendly.com/hc/en-us/articles/223147027-Embed-options-overview\">\n\t\t\t\t\t{ __( 'Need help finding your embed code?', 'jetpack' ) }\n\t\t\t\t</ExternalLink>\n\t\t\t</div>\n\t\t</Placeholder>\n\t);\n\n\tconst iframeSrc = () => {\n\t\tconst query = new URLSearchParams( {\n\t\t\tembed_domain: 'wordpress.com',\n\t\t\tembed_type: 'Inline',\n\t\t\thide_event_type_details: hideEventTypeDetails ? 1 : 0,\n\t\t\tbackground_color: backgroundColor,\n\t\t\tprimary_color: primaryColor,\n\t\t\ttext_color: textColor,\n\t\t} );\n\t\treturn `${ url }?${ query }`;\n\t};\n\n\tconst inlinePreview = (\n\t\t<>\n\t\t\t<div className={ `${ defaultClassName }-overlay` }></div>\n\t\t\t<iframe\n\t\t\t\tsrc={ iframeSrc() }\n\t\t\t\twidth=\"100%\"\n\t\t\t\theight=\"100%\"\n\t\t\t\tframeBorder=\"0\"\n\t\t\t\tdata-origwidth=\"100%\"\n\t\t\t\tdata-origheight=\"100%\"\n\t\t\t\ttitle=\"Calendly\"\n\t\t\t></iframe>\n\t\t</>\n\t);\n\n\tconst buttonPreview = (\n\t\t<InnerBlocks\n\t\t\ttemplate={ [\n\t\t\t\t[\n\t\t\t\t\tinnerButtonBlock.name,\n\t\t\t\t\t{\n\t\t\t\t\t\t...innerButtonBlock.attributes,\n\t\t\t\t\t\t...embedButtonAttributes,\n\t\t\t\t\t\tpassthroughAttributes: { url: 'url' },\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t] }\n\t\t\ttemplateLock=\"all\"\n\t\t/>\n\t);\n\n\tconst blockPreview = previewStyle => {\n\t\tif ( previewStyle === 'inline' ) {\n\t\t\treturn inlinePreview;\n\t\t}\n\n\t\treturn buttonPreview;\n\t};\n\n\tif ( isResolvingUrl ) {\n\t\treturn blockEmbedding;\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[ `calendly-style-${ style }` ]: url && ! isEditingUrl,\n\t\t\t} ) }\n\t\t>\n\t\t\t<CalendlyControls\n\t\t\t\t{ ...{\n\t\t\t\t\t...props,\n\t\t\t\t\tdefaultClassName,\n\t\t\t\t\tembedCode,\n\t\t\t\t\tisEditingUrl,\n\t\t\t\t\tparseEmbedCode,\n\t\t\t\t\tsetEmbedCode,\n\t\t\t\t\tsetIsEditingUrl,\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t{ url && ! isEditingUrl ? blockPreview( style ) : blockPlaceholder }\n\t\t</div>\n\t);\n}\n\nexport default withNotices( CalendlyEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/calendly/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 WordPress block displaying financial breakdown details, enabling users to customize the class name and locking preferences." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-totals/block.json\n{\n\t\"name\": \"woocommerce/checkout-order-summary-totals-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Totals\",\n\t\"description\": \"Shows the subtotal, fees, discounts, shipping and taxes.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-order-summary-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-totals/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport type { TemplateArray } from '@wordpress/blocks';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseForcedLayout,\n\tgetAllowedBlocks,\n} from '../../../cart-checkout-shared';\n\nexport const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst allowedBlocks = getAllowedBlocks(\n\t\tinnerBlockAreas.CHECKOUT_ORDER_SUMMARY_TOTALS\n\t);\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/checkout-order-summary-subtotal-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-order-summary-fee-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-order-summary-discount-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-order-summary-shipping-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-order-summary-taxes-block', {}, [] ],\n\t] as TemplateArray;\n\n\tuseForcedLayout( {\n\t\tclientId,\n\t\tregisteredBlocks: allowedBlocks,\n\t\tdefaultTemplate,\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks\n\t\t\t\tallowedBlocks={ allowedBlocks }\n\t\t\t\ttemplate={ defaultTemplate }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a versatile text block component that allows dynamic configuration of ordering, value settings, type selection, and three additional customization parameters." }, { "role": "assistant", "content": "// File: packages/block-library/src/list/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/list\",\n\t\"title\": \"List\",\n\t\"category\": \"text\",\n\t\"allowedBlocks\": [ \"core/list-item\" ],\n\t\"description\": \"An organized collection of items displayed in a specific order.\",\n\t\"keywords\": [ \"bullet list\", \"ordered list\", \"numbered list\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"ordered\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false,\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"values\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"html\",\n\t\t\t\"selector\": \"ol,ul\",\n\t\t\t\"multiline\": \"li\",\n\t\t\t\"default\": \"\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"type\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"start\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"reversed\": {\n\t\t\t\"type\": \"boolean\"\n\t\t},\n\t\t\"placeholder\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\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\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\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\"__unstablePasteTextInline\": true,\n\t\t\"__experimentalOnMerge\": true,\n\t\t\"__experimentalSlashInserter\": true,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"selectors\": {\n\t\t\"border\": \".wp-block-list:not(.wp-block-list .wp-block-list)\"\n\t},\n\t\"editorStyle\": \"wp-block-list-editor\",\n\t\"style\": \"wp-block-list\"\n}\n\n\n// File: packages/block-library/src/list/index.js\n/**\n * WordPress dependencies\n */\nimport { list as icon } from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\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\nconst settings = {\n\ticon,\n\texample: {\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/list-item',\n\t\t\t\tattributes: { content: __( 'Alice.' ) },\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/list-item',\n\t\t\t\tattributes: { content: __( 'The White Rabbit.' ) },\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/list-item',\n\t\t\t\tattributes: { content: __( 'The Cheshire Cat.' ) },\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/list-item',\n\t\t\t\tattributes: { content: __( 'The Mad Hatter.' ) },\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/list-item',\n\t\t\t\tattributes: { content: __( 'The Queen of Hearts.' ) },\n\t\t\t},\n\t\t],\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport { settings };\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/list/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { ordered, type, reversed, start } = attributes;\n\tconst TagName = ordered ? 'ol' : 'ul';\n\treturn (\n\t\t<TagName\n\t\t\t{ ...useBlockProps.save( {\n\t\t\t\treversed,\n\t\t\t\tstart,\n\t\t\t\tstyle: {\n\t\t\t\t\tlistStyleType:\n\t\t\t\t\t\tordered && type !== 'decimal' ? type : undefined,\n\t\t\t\t},\n\t\t\t} ) }\n\t\t>\n\t\t\t<InnerBlocks.Content />\n\t\t</TagName>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Display an image to represent this site. Update this block and the changes apply everywhere. that allows users to configure: width, is link, link target, should sync icon" }, { "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/site-logo/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/site-logo\",\n\t\"title\": \"Site Logo\",\n\t\"category\": \"theme\",\n\t\"description\": \"Display an image to represent this site. Update this block and the changes apply everywhere.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"width\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"isLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true,\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"_self\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"shouldSyncIcon\": {\n\t\t\t\"type\": \"boolean\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"viewportWidth\": 500,\n\t\t\"attributes\": {\n\t\t\t\"width\": 350,\n\t\t\t\"className\": \"block-editor-block-types-list__site-logo-example\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"align\": true,\n\t\t\"alignWide\": false,\n\t\t\"color\": {\n\t\t\t\"text\": false,\n\t\t\t\"background\": false\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\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"filter\": {\n\t\t\t\"duotone\": true\n\t\t}\n\t},\n\t\"styles\": [\n\t\t{\n\t\t\t\"name\": \"default\",\n\t\t\t\"label\": \"Default\",\n\t\t\t\"isDefault\": true\n\t\t},\n\t\t{ \"name\": \"rounded\", \"label\": \"Rounded\" }\n\t],\n\t\"selectors\": {\n\t\t\"filter\": {\n\t\t\t\"duotone\": \".wp-block-site-logo img, .wp-block-site-logo .components-placeholder__illustration, .wp-block-site-logo .components-placeholder::before\"\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-site-logo-editor\",\n\t\"style\": \"wp-block-site-logo\"\n}\n\n\n// File: packages/block-library/src/site-logo/index.js\n/**\n * WordPress dependencies\n */\nimport { siteLogo as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport transforms from './transforms';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\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 Gutenberg block that Enable customers to filter the product grid by rating. with these attributes: class name, show counts, display style, 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: plugins/woocommerce/client/blocks/assets/js/blocks/rating-filter/block.json\n{\n\t\"name\": \"woocommerce/rating-filter\",\n\t\"title\": \"Filter by Rating Controls\",\n\t\"description\": \"Enable customers to filter the product grid by rating.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": false\n\t\t},\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": true,\n\t\t\t\"button\": true\n\t\t},\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"showCounts\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"displayStyle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"list\"\n\t\t},\n\t\t\"showFilterButton\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"selectType\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"multiple\"\n\t\t},\n\t\t\"isPreview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\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/rating-filter/edit.tsx\n/**\n * External dependencies\n */\nimport { __, _x } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport {\n\tDisabled,\n\tNotice,\n\tPanelBody,\n\tToggleControl,\n\twithSpokenMessages,\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport type { Attributes } from './types';\nimport './editor.scss';\nimport { UpgradeNotice } from '../filter-wrapper/upgrade';\n\nconst noRatingsNotice = (\n\t<Notice status=\"warning\" isDismissible={ false }>\n\t\t<p>\n\t\t\t{ __(\n\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'woocommerce'\n\t\t\t) }\n\t\t</p>\n\t</Notice>\n);\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n\tclientId,\n}: BlockEditProps< Attributes > ) => {\n\tconst {\n\t\tclassName,\n\t\tdisplayStyle,\n\t\tshowCounts,\n\t\tshowFilterButton,\n\t\tselectType,\n\t} = attributes;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( 'wc-block-rating-filter', className ),\n\t} );\n\n\tconst getInspectorControls = () => {\n\t\treturn (\n\t\t\t<InspectorControls key=\"inspector\">\n\t\t\t\t<PanelBody>\n\t\t\t\t\t<UpgradeNotice clientId={ clientId } />\n\t\t\t\t</PanelBody>\n\t\t\t\t<PanelBody title={ __( 'Display Settings', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Display product count', 'woocommerce' ) }\n\t\t\t\t\t\tchecked={ showCounts }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowCounts: ! showCounts,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t'Allow selecting multiple options?',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tisBlock\n\t\t\t\t\t\tvalue={ selectType || 'multiple' }\n\t\t\t\t\t\tonChange={ ( value: string ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tselectType: value,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclassName=\"wc-block-attribute-filter__multiple-toggle\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"multiple\"\n\t\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t\t'Multiple',\n\t\t\t\t\t\t\t\t'Number of filters',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"single\"\n\t\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t\t'Single',\n\t\t\t\t\t\t\t\t'Number of filters',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\tlabel={ __( 'Display Style', 'woocommerce' ) }\n\t\t\t\t\t\tisBlock\n\t\t\t\t\t\tvalue={ displayStyle }\n\t\t\t\t\t\tonChange={ ( value: string ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tdisplayStyle: value,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclassName=\"wc-block-attribute-filter__display-toggle\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"list\"\n\t\t\t\t\t\t\tlabel={ __( 'List', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"dropdown\"\n\t\t\t\t\t\t\tlabel={ __( 'Dropdown', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t\"Show 'Apply filters' button\",\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Products will update when the button is clicked.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ showFilterButton }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowFilterButton: value,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t);\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t{ getInspectorControls() }\n\t\t\t{\n\t\t\t\t<div { ...blockProps }>\n\t\t\t\t\t<Disabled>\n\t\t\t\t\t\t<Block\n\t\t\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\t\t\tisEditor={ true }\n\t\t\t\t\t\t\tnoRatingsNotice={ noRatingsNotice }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</Disabled>\n\t\t\t\t</div>\n\t\t\t}\n\t\t</>\n\t);\n};\n\nexport default withSpokenMessages( Edit );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Display filter options as chips. with these attributes: chip text, custom chip text, chip background, and 9 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/chips/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"name\": \"woocommerce/product-filter-chips\",\n\t\"title\": \"Chips\",\n\t\"description\": \"Display filter options as chips.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"ancestor\": [\n\t\t\"woocommerce/product-filter-attribute\",\n\t\t\"woocommerce/product-filter-taxonomy\",\n\t\t\"woocommerce/product-filter-status\"\n\t],\n\t\"supports\": {\n\t\t\"interactivity\": true\n\t},\n\t\"usesContext\": [ \"filterData\" ],\n\t\"attributes\": {\n\t\t\"chipText\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customChipText\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"chipBackground\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customChipBackground\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"chipBorder\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customChipBorder\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"selectedChipText\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customSelectedChipText\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"selectedChipBackground\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customSelectedChipBackground\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"selectedChipBorder\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customSelectedChipBorder\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"viewScriptModule\": \"woocommerce/product-filter-chips\",\n\t\"style\": \"file:../woocommerce/product-filter-chips-style.css\",\n\t\"editorStyle\": \"file:../woocommerce/product-filter-chips-editor.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/chips/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport clsx from 'clsx';\nimport { decodeHtmlEntities } from '@woocommerce/utils';\nimport {\n\tInspectorControls,\n\tuseBlockProps,\n\twithColors,\n\t// @ts-expect-error - no types.\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalColorGradientSettingsDropdown as ColorGradientSettingsDropdown,\n\t// @ts-expect-error - no types.\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalUseMultipleOriginColorsAndGradients as useMultipleOriginColorsAndGradients,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { EditProps } from './types';\nimport './editor.scss';\nimport { getColorClasses, getColorVars } from './utils';\n\nconst Edit = ( props: EditProps ): JSX.Element => {\n\tconst colorGradientSettings = useMultipleOriginColorsAndGradients();\n\tconst {\n\t\tcontext,\n\t\tclientId,\n\t\tattributes,\n\t\tsetAttributes,\n\t\tchipText,\n\t\tsetChipText,\n\t\tchipBackground,\n\t\tsetChipBackground,\n\t\tchipBorder,\n\t\tsetChipBorder,\n\t\tselectedChipText,\n\t\tsetSelectedChipText,\n\t\tselectedChipBackground,\n\t\tsetSelectedChipBackground,\n\t\tselectedChipBorder,\n\t\tsetSelectedChipBorder,\n\t} = props;\n\tconst {\n\t\tcustomChipText,\n\t\tcustomChipBackground,\n\t\tcustomChipBorder,\n\t\tcustomSelectedChipText,\n\t\tcustomSelectedChipBackground,\n\t\tcustomSelectedChipBorder,\n\t} = attributes;\n\tconst { filterData } = context;\n\tconst { isLoading, items, showCounts } = filterData;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( 'wc-block-product-filter-chips', {\n\t\t\t'is-loading': isLoading,\n\t\t\t...getColorClasses( attributes ),\n\t\t} ),\n\t\tstyle: getColorVars( attributes ),\n\t} );\n\n\tconst loadingState = useMemo( () => {\n\t\treturn [ ...Array( 10 ) ].map( ( _, i ) => (\n\t\t\t<div\n\t\t\t\tclassName=\"wc-block-product-filter-chips__item\"\n\t\t\t\tkey={ i }\n\t\t\t\tstyle={ {\n\t\t\t\t\t/* stylelint-disable */\n\t\t\t\t\twidth: Math.floor( Math.random() * ( 100 - 25 ) ) + '%',\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t&nbsp;\n\t\t\t</div>\n\t\t) );\n\t}, [] );\n\n\tif ( ! items ) {\n\t\treturn <></>;\n\t}\n\n\tconst threshold = 15;\n\tconst isLongList = items.length > threshold;\n\n\treturn (\n\t\t<>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<div className=\"wc-block-product-filter-chips__items\">\n\t\t\t\t\t{ isLoading && loadingState }\n\t\t\t\t\t{ ! isLoading &&\n\t\t\t\t\t\t( isLongList\n\t\t\t\t\t\t\t? items.slice( 0, threshold )\n\t\t\t\t\t\t\t: items\n\t\t\t\t\t\t).map( ( item, index ) => (\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\t\t\tclassName=\"wc-block-product-filter-chips__item\"\n\t\t\t\t\t\t\t\taria-checked={ !! item.selected }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<span className=\"wc-block-product-filter-chips__label\">\n\t\t\t\t\t\t\t\t\t<span className=\"wc-block-product-filter-chips__text\">\n\t\t\t\t\t\t\t\t\t\t{ typeof item.label === 'string'\n\t\t\t\t\t\t\t\t\t\t\t? decodeHtmlEntities( item.label )\n\t\t\t\t\t\t\t\t\t\t\t: item.label }\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t{ showCounts && (\n\t\t\t\t\t\t\t\t\t\t<span className=\"wc-block-product-filter-chips__count\">\n\t\t\t\t\t\t\t\t\t\t\t{ ` (${ item.count })` }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) ) }\n\t\t\t\t</div>\n\t\t\t\t{ ! isLoading && isLongList && (\n\t\t\t\t\t<button className=\"wc-block-product-filter-chips__show-more\">\n\t\t\t\t\t\t{ __( 'Show more…', 'woocommerce' ) }\n\t\t\t\t\t</button>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t<InspectorControls group=\"color\">\n\t\t\t\t{ colorGradientSettings.hasColorsOrGradients && (\n\t\t\t\t\t<ColorGradientSettingsDropdown\n\t\t\t\t\t\t__experimentalIsRenderedInSidebar\n\t\t\t\t\t\tsettings={ [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __(\n\t\t\t\t\t\t\t\t\t'Unselected Chip Text',\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\tcolorValue: chipText.color || customChipText,\n\t\t\t\t\t\t\t\tonColorChange: ( colorValue: string ) => {\n\t\t\t\t\t\t\t\t\tsetChipText( colorValue );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tcustomChipText: colorValue,\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\tresetAllFilter: () => {\n\t\t\t\t\t\t\t\t\tsetChipText( '' );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tcustomChipText: '',\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\t{\n\t\t\t\t\t\t\t\tlabel: __(\n\t\t\t\t\t\t\t\t\t'Unselected Chip Border',\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\tcolorValue:\n\t\t\t\t\t\t\t\t\tchipBorder.color || customChipBorder,\n\t\t\t\t\t\t\t\tonColorChange: ( colorValue: string ) => {\n\t\t\t\t\t\t\t\t\tsetChipBorder( colorValue );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tcustomChipBorder: colorValue,\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\tresetAllFilter: () => {\n\t\t\t\t\t\t\t\t\tsetChipBorder( '' );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tcustomChipBorder: '',\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\t{\n\t\t\t\t\t\t\t\tlabel: __(\n\t\t\t\t\t\t\t\t\t'Unselected Chip Background',\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\tcolorValue:\n\t\t\t\t\t\t\t\t\tchipBackground.color ||\n\t\t\t\t\t\t\t\t\tcustomChipBackground,\n\t\t\t\t\t\t\t\tonColorChange: ( colorValue: string ) => {\n\t\t\t\t\t\t\t\t\tsetChipBackground( colorValue );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tcustomChipBackground: colorValue,\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\tresetAllFilter: () => {\n\t\t\t\t\t\t\t\t\tsetChipBackground( '' );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tcustomChipBackground: '',\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\t{\n\t\t\t\t\t\t\t\tlabel: __(\n\t\t\t\t\t\t\t\t\t'Selected Chip Text',\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\tcolorValue:\n\t\t\t\t\t\t\t\t\tselectedChipText.color ||\n\t\t\t\t\t\t\t\t\tcustomSelectedChipText,\n\t\t\t\t\t\t\t\tonColorChange: ( colorValue: string ) => {\n\t\t\t\t\t\t\t\t\tsetSelectedChipText( colorValue );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tcustomSelectedChipText: colorValue,\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\tresetAllFilter: () => {\n\t\t\t\t\t\t\t\t\tsetSelectedChipText( '' );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tcustomSelectedChipText: '',\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\t{\n\t\t\t\t\t\t\t\tlabel: __(\n\t\t\t\t\t\t\t\t\t'Selected Chip Border',\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\tcolorValue:\n\t\t\t\t\t\t\t\t\tselectedChipBorder.color ||\n\t\t\t\t\t\t\t\t\tcustomSelectedChipBorder,\n\t\t\t\t\t\t\t\tonColorChange: ( colorValue: string ) => {\n\t\t\t\t\t\t\t\t\tsetSelectedChipBorder( colorValue );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tcustomSelectedChipBorder: colorValue,\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\tresetAllFilter: () => {\n\t\t\t\t\t\t\t\t\tsetSelectedChipBorder( '' );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tcustomSelectedChipBorder: '',\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\t{\n\t\t\t\t\t\t\t\tlabel: __(\n\t\t\t\t\t\t\t\t\t'Selected Chip Background',\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\tcolorValue:\n\t\t\t\t\t\t\t\t\tselectedChipBackground.color ||\n\t\t\t\t\t\t\t\t\tcustomSelectedChipBackground,\n\t\t\t\t\t\t\t\tonColorChange: ( colorValue: string ) => {\n\t\t\t\t\t\t\t\t\tsetSelectedChipBackground( colorValue );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tcustomSelectedChipBackground:\n\t\t\t\t\t\t\t\t\t\t\tcolorValue,\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\tresetAllFilter: () => {\n\t\t\t\t\t\t\t\t\tsetSelectedChipBackground( '' );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tcustomSelectedChipBackground: '',\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\tpanelId={ clientId }\n\t\t\t\t\t\t{ ...colorGradientSettings }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</InspectorControls>\n\t\t</>\n\t);\n};\n\nexport default withColors( {\n\tchipText: 'chip-text',\n\tchipBorder: 'chip-border',\n\tchipBackground: 'chip-background',\n\tselectedChipText: 'selected-chip-text',\n\tselectedChipBorder: 'selected-chip-border',\n\tselectedChipBackground: 'selected-chip-background',\n} )( Edit );\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/chips/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport { BlockAttributes } from './types';\nimport { getColorClasses, getColorVars } from './utils';\n\nconst Save = ( { attributes }: { attributes: BlockAttributes } ) => {\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: clsx(\n\t\t\t'wc-block-product-filter-chips',\n\t\t\tattributes.className,\n\t\t\tgetColorClasses( attributes )\n\t\t),\n\t\tstyle: {\n\t\t\t...getColorVars( attributes ),\n\t\t},\n\t} );\n\n\treturn <div { ...blockProps } />;\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 Gutenberg block for Let shoppers filter products by choosing a price range." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/price-filter/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"name\": \"woocommerce/product-filter-price\",\n\t\"title\": \"Price Filter\",\n\t\"description\": \"Let shoppers filter products by choosing a price range.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"ancestor\": [ \"woocommerce/product-filters\" ],\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"html\": false\n\t},\n\t\"usesContext\": [ \"query\", \"filterParams\" ],\n\t\"viewScriptModule\": \"woocommerce/product-filter-price\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/price-filter/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tBlockContextProvider,\n\tuseBlockProps,\n\tInnerBlocks,\n} from '@wordpress/block-editor';\nimport { useCollectionData } from '@woocommerce/base-context/hooks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { getAllowedBlocks } from '../../utils/get-allowed-blocks';\nimport { getPriceFilterData } from './utils';\nimport { InitialDisabled } from '../../components/initial-disabled';\n\nconst Edit = () => {\n\tconst blockProps = useBlockProps();\n\n\tconst { data, isLoading } = useCollectionData( {\n\t\tqueryPrices: true,\n\t\tqueryState: {},\n\t\tisEditor: true,\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InitialDisabled>\n\t\t\t\t<BlockContextProvider\n\t\t\t\t\tvalue={ {\n\t\t\t\t\t\tfilterData: {\n\t\t\t\t\t\t\tprice: getPriceFilterData( data ),\n\t\t\t\t\t\t\tisLoading,\n\t\t\t\t\t\t},\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<InnerBlocks\n\t\t\t\t\t\tallowedBlocks={ getAllowedBlocks() }\n\t\t\t\t\t\ttemplate={ [\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t'core/heading',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlevel: 3,\n\t\t\t\t\t\t\t\t\tcontent: __( 'Price', 'woocommerce' ),\n\t\t\t\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\t\t\t\tspacing: {\n\t\t\t\t\t\t\t\t\t\t\tmargin: {\n\t\t\t\t\t\t\t\t\t\t\t\tbottom: '0.625rem',\n\t\t\t\t\t\t\t\t\t\t\t\ttop: '0',\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\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\t[ 'woocommerce/product-filter-price-slider', {} ],\n\t\t\t\t\t\t] }\n\t\t\t\t\t/>\n\t\t\t\t</BlockContextProvider>\n\t\t\t</InitialDisabled>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/price-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": "Craft a customizable Gutenberg block for image insertion, incorporating blob, url, alt, and an extensive set of 14 additional configurable attributes to enhance visual communication." }, { "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/image/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/image\",\n\t\"title\": \"Image\",\n\t\"category\": \"media\",\n\t\"usesContext\": [\n\t\t\"allowResize\",\n\t\t\"imageCrop\",\n\t\t\"fixedHeight\",\n\t\t\"postId\",\n\t\t\"postType\",\n\t\t\"queryId\"\n\t],\n\t\"description\": \"Insert an image to make a visual statement.\",\n\t\"keywords\": [ \"img\", \"photo\", \"picture\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"blob\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"local\"\n\t\t},\n\t\t\"url\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"img\",\n\t\t\t\"attribute\": \"src\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"alt\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"img\",\n\t\t\t\"attribute\": \"alt\",\n\t\t\t\"default\": \"\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"caption\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"figcaption\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"lightbox\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"enabled\": {\n\t\t\t\t\"type\": \"boolean\"\n\t\t\t}\n\t\t},\n\t\t\"title\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"img\",\n\t\t\t\"attribute\": \"title\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"href\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"figure > a\",\n\t\t\t\"attribute\": \"href\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"rel\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"figure > a\",\n\t\t\t\"attribute\": \"rel\"\n\t\t},\n\t\t\"linkClass\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"figure > a\",\n\t\t\t\"attribute\": \"class\"\n\t\t},\n\t\t\"id\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"width\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"height\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"aspectRatio\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"scale\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"sizeSlug\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"linkDestination\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"figure > a\",\n\t\t\t\"attribute\": \"target\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"align\": [ \"left\", \"center\", \"right\", \"wide\", \"full\" ],\n\t\t\"anchor\": true,\n\t\t\"color\": {\n\t\t\t\"text\": false,\n\t\t\t\"background\": false\n\t\t},\n\t\t\"filter\": {\n\t\t\t\"duotone\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": 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\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"shadow\": {\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t}\n\t},\n\t\"selectors\": {\n\t\t\"border\": \".wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder\",\n\t\t\"shadow\": \".wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder\",\n\t\t\"filter\": {\n\t\t\t\"duotone\": \".wp-block-image img, .wp-block-image .components-placeholder\"\n\t\t}\n\t},\n\t\"styles\": [\n\t\t{\n\t\t\t\"name\": \"default\",\n\t\t\t\"label\": \"Default\",\n\t\t\t\"isDefault\": true\n\t\t},\n\t\t{ \"name\": \"rounded\", \"label\": \"Rounded\" }\n\t],\n\t\"editorStyle\": \"wp-block-image-editor\",\n\t\"style\": \"wp-block-image\"\n}\n\n\n// File: packages/block-library/src/image/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { image as icon } from '@wordpress/icons';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tsizeSlug: 'large',\n\t\t\turl: 'https://s.w.org/images/core/5.3/MtBlanc1.jpg',\n\t\t\t// translators: Caption accompanying an image of the Mont Blanc, which serves as an example for the Image block.\n\t\t\tcaption: __( 'Mont Blanc appears—still, snowy, and serene.' ),\n\t\t},\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst customName = attributes?.metadata?.name;\n\n\t\tif ( context === 'list-view' && customName ) {\n\t\t\treturn customName;\n\t\t}\n\n\t\tif ( context === 'accessibility' ) {\n\t\t\tconst { caption, alt, url } = attributes;\n\n\t\t\tif ( ! url ) {\n\t\t\t\treturn __( 'Empty' );\n\t\t\t}\n\n\t\t\tif ( ! alt ) {\n\t\t\t\treturn caption || '';\n\t\t\t}\n\n\t\t\t// This is intended to be read by a screen reader.\n\t\t\t// A period simply means a pause, no need to translate it.\n\t\t\treturn alt + ( caption ? '. ' + caption : '' );\n\t\t}\n\t},\n\tgetEditWrapperProps( attributes ) {\n\t\treturn {\n\t\t\t'data-align': attributes.align,\n\t\t};\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'image',\n\t\t\tlabel: __( 'Image' ),\n\t\t\ttype: 'media',\n\t\t\tmapping: {\n\t\t\t\tid: 'id',\n\t\t\t\turl: 'url',\n\t\t\t\tcaption: 'caption',\n\t\t\t\talt: 'alt',\n\t\t\t},\n\t\t\targs: {\n\t\t\t\tallowedTypes: [ 'image' ],\n\t\t\t\tmultiple: false,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: 'link',\n\t\t\tlabel: __( 'Link' ),\n\t\t\ttype: 'link',\n\t\t\tmapping: {\n\t\t\t\turl: 'href',\n\t\t\t\trel: 'rel',\n\t\t\t\tlinkTarget: 'linkTarget',\n\t\t\t\tdestination: 'linkDestination',\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: 'caption',\n\t\t\tlabel: __( 'Caption' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t\t{\n\t\t\tid: 'alt',\n\t\t\tlabel: __( 'Alt text' ),\n\t\t\ttype: 'text',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'image' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/image/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tRichText,\n\tuseBlockProps,\n\t__experimentalGetElementClassName,\n\t__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,\n\t__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,\n} from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst {\n\t\turl,\n\t\talt,\n\t\tcaption,\n\t\talign,\n\t\thref,\n\t\trel,\n\t\tlinkClass,\n\t\twidth,\n\t\theight,\n\t\taspectRatio,\n\t\tscale,\n\t\tid,\n\t\tlinkTarget,\n\t\tsizeSlug,\n\t\ttitle,\n\t\tmetadata: { bindings = {} } = {},\n\t} = attributes;\n\n\tconst newRel = ! rel ? undefined : rel;\n\tconst borderProps = getBorderClassesAndStyles( attributes );\n\tconst shadowProps = getShadowClassesAndStyles( attributes );\n\n\tconst classes = clsx( {\n\t\t// All other align classes are handled by block supports.\n\t\t// `{ align: 'none' }` is unique to transforms for the image block.\n\t\talignnone: 'none' === align,\n\t\t[ `size-${ sizeSlug }` ]: sizeSlug,\n\t\t'is-resized': width || height,\n\t\t'has-custom-border':\n\t\t\t!! borderProps.className ||\n\t\t\t( borderProps.style &&\n\t\t\t\tObject.keys( borderProps.style ).length > 0 ),\n\t} );\n\n\tconst imageClasses = clsx( borderProps.className, {\n\t\t[ `wp-image-${ id }` ]: !! id,\n\t} );\n\n\tconst image = (\n\t\t<img\n\t\t\tsrc={ url }\n\t\t\talt={ alt }\n\t\t\tclassName={ imageClasses || undefined }\n\t\t\tstyle={ {\n\t\t\t\t...borderProps.style,\n\t\t\t\t...shadowProps.style,\n\t\t\t\taspectRatio,\n\t\t\t\tobjectFit: scale,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t} }\n\t\t\ttitle={ title }\n\t\t/>\n\t);\n\n\tconst displayCaption =\n\t\t! RichText.isEmpty( caption ) ||\n\t\tbindings.caption ||\n\t\tbindings?.__default?.source === 'core/pattern-overrides';\n\n\tconst figure = (\n\t\t<>\n\t\t\t{ href ? (\n\t\t\t\t<a\n\t\t\t\t\tclassName={ linkClass }\n\t\t\t\t\thref={ href }\n\t\t\t\t\ttarget={ linkTarget }\n\t\t\t\t\trel={ newRel }\n\t\t\t\t>\n\t\t\t\t\t{ image }\n\t\t\t\t</a>\n\t\t\t) : (\n\t\t\t\timage\n\t\t\t) }\n\t\t\t{ displayCaption && (\n\t\t\t\t<RichText.Content\n\t\t\t\t\tclassName={ __experimentalGetElementClassName( 'caption' ) }\n\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\tvalue={ caption }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n\n\treturn (\n\t\t<figure { ...useBlockProps.save( { className: classes } ) }>\n\t\t\t{ figure }\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": "Develop a custom Gutenberg block that Block: a8c/model-viewer" }, { "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: blocks/model-viewer/src/index.js\n/**\n * WordPress dependencies\n */\nimport { registerBlockType } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { icon } from './icon';\nimport Edit from './edit';\nimport Save from './save';\n\nexport const registerBlock = () => {\n\tregisterBlockType( 'a8c/model-viewer', {\n\t\ttitle: '3D Model',\n\t\tdescription: __(\n\t\t\t'Show 3D models in an interactive viewer. Add files in .gltf or .glb formats.'\n\t\t),\n\t\tcategory: 'widgets',\n\t\ticon,\n\t\tattributes: {\n\t\t\tid: {\n\t\t\t\ttype: 'number',\n\t\t\t},\n\t\t\tsrc: {\n\t\t\t\ttype: 'string',\n\t\t\t\tsource: 'attribute',\n\t\t\t\tselector: 'model-viewer',\n\t\t\t\tattribute: 'src',\n\t\t\t},\n\t\t\talt: {\n\t\t\t\ttype: 'string',\n\t\t\t\tsource: 'attribute',\n\t\t\t\tselector: 'model-viewer',\n\t\t\t\tattribute: 'alt',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\tautoRotate: {\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: false,\n\t\t\t},\n\t\t\twidth: {\n\t\t\t\ttype: 'number',\n\t\t\t},\n\t\t\twidthUnit: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\theight: {\n\t\t\t\ttype: 'number',\n\t\t\t},\n\t\t\theightUnit: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tcameraOrbit: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tfieldOfView: {\n\t\t\t\ttype: 'number',\n\t\t\t},\n\t\t},\n\t\tsupports: {\n\t\t\talign: true,\n\t\t},\n\t\tedit: ( props ) => <Edit { ...props } />,\n\t\tsave: ( props ) => <Save { ...props } />,\n\t} );\n};\n\n\n// File: blocks/model-viewer/src/save.js\nimport { __ } from '@wordpress/i18n';\nimport { useBlockProps } from '@wordpress/block-editor';\n\nimport { DEFAULT_HEIGHT, DEFAULT_WIDTH } from './utils.js';\n\nexport default function save( { attributes } ) {\n\tconst {\n\t\tsrc,\n\t\talt,\n\t\twidth,\n\t\theight,\n\t\twidthUnit,\n\t\theightUnit,\n\t\tcameraOrbit,\n\t\tfieldOfView,\n\t\tautoRotate,\n\t} = attributes;\n\n\t// React stringifies custom properties, so use object destructuring to disable auto-rotate.\n\t// See https://github.com/facebook/react/issues/9230\n\t// Gutenberg won't save the value when true is a boolean.\n\tconst autoRotateAttr = autoRotate ? { 'auto-rotate': 'true' } : {};\n\n\treturn (\n\t\t<figure { ...useBlockProps.save() }>\n\t\t\t<model-viewer\n\t\t\t\tclass=\"wp-block-a8c-model-viewer__component\"\n\t\t\t\tstyle={ {\n\t\t\t\t\theight:\n\t\t\t\t\t\theight && heightUnit\n\t\t\t\t\t\t\t? `${ height }${ heightUnit }`\n\t\t\t\t\t\t\t: DEFAULT_HEIGHT,\n\t\t\t\t\twidth:\n\t\t\t\t\t\twidth && widthUnit\n\t\t\t\t\t\t\t? `${ width }${ widthUnit }`\n\t\t\t\t\t\t\t: DEFAULT_WIDTH,\n\t\t\t\t} }\n\t\t\t\talt={ alt }\n\t\t\t\tsrc={ src }\n\t\t\t\tar=\"true\"\n\t\t\t\tcamera-orbit={ cameraOrbit }\n\t\t\t\tfield-of-view={ fieldOfView }\n\t\t\t\tar-modes=\"webxr scene-viewer quick-look\"\n\t\t\t\tseamless-poster=\"true\"\n\t\t\t\tshadow-intensity=\"1\"\n\t\t\t\tcamera-controls=\"true\"\n\t\t\t\tenable-pan=\"true\"\n\t\t\t\t{ ...autoRotateAttr }\n\t\t\t></model-viewer>\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": "Craft an Accordion header block in WordPress with customizable settings including default state, title, heading hierarchy, and four additional configuration parameters." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/inner-blocks/accordion-header/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/accordion-header\",\n\t\"title\": \"Accordion Header\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"Accordion header.\",\n\t\"example\": {},\n\t\"__experimental\": true,\n\t\"parent\": [ \"woocommerce/accordion-item\" ],\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"gradient\": true\n\t\t},\n\t\t\"align\": false,\n\t\t\"border\": true,\n\t\t\"interactivity\": true,\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true,\n\t\t\t\t\"margin\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"textAlign\": true,\n\t\t\t\"fontSize\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true,\n\t\t\t\t\"fontFamily\": true\n\t\t\t}\n\t\t},\n\t\t\"shadow\": true,\n\t\t\"layout\": true\n\t},\n\t\"attributes\": {\n\t\t\"openByDefault\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"title\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"span\"\n\t\t},\n\t\t\"level\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t},\n\t\t\"levelOptions\": {\n\t\t\t\"type\": \"array\"\n\t\t},\n\t\t\"textAlignment\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"left\"\n\t\t},\n\t\t\"icon\": {\n\t\t\t\"type\": [ \"string\", \"boolean\" ],\n\t\t\t\"enum\": [\n\t\t\t\t\"plus\",\n\t\t\t\t\"chevron\",\n\t\t\t\t\"chevronRight\",\n\t\t\t\t\"caret\",\n\t\t\t\t\"circlePlus\",\n\t\t\t\tfalse\n\t\t\t],\n\t\t\t\"default\": \"plus\"\n\t\t},\n\t\t\"iconPosition\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [ \"left\", \"right\" ],\n\t\t\t\"default\": \"right\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/inner-blocks/accordion-header/index.js\n/**\n * External dependencies\n */\nimport { SVG, Path } from '@wordpress/components';\nimport { registerBlockType } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport edit from './edit';\nimport save from './save';\nimport metadata from './block.json';\n\nconst icon = (\n\t<SVG\n\t\twidth=\"24\"\n\t\theight=\"24\"\n\t\tviewBox=\"0 0 24 24\"\n\t\tfill=\"none\"\n\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t>\n\t\t<Path\n\t\t\tfillRule=\"evenodd\"\n\t\t\tclipRule=\"evenodd\"\n\t\t\td=\"M19.5 12.75L9.5 12.75L9.5 11.25L19.5 11.25L19.5 12.75Z\"\n\t\t\tfill=\"currentColor\"\n\t\t/>\n\t\t<Path d=\"M4.5 9.5L8.5 12L4.5 14.5L4.5 9.5Z\" fill=\"currentColor\" />\n\t</SVG>\n);\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\tapiVersion: 3,\n\ticon,\n\texample: {},\n\tedit,\n\tsave,\n};\n\nregisterBlockType( metadata, settings );\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/inner-blocks/accordion-header/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport {\n\tuseBlockProps,\n\t__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,\n\t__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,\n\t__experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles,\n\t__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,\n\tRichText,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport {\n\tcaret,\n\tchevron,\n\tchevronRight,\n\tcirclePlus,\n\tplus,\n} from '../accordion-item/icons';\n\nconst ICONS = {\n\tplus,\n\tcirclePlus,\n\tchevron,\n\tchevronRight,\n\tcaret,\n};\n\nexport default function save( { attributes } ) {\n\tconst { level, title, iconPosition, textAlign, icon } = attributes;\n\tconst TagName = 'h' + level;\n\n\tconst blockProps = useBlockProps.save();\n\tconst borderProps = getBorderClassesAndStyles( attributes );\n\tconst colorProps = getColorClassesAndStyles( attributes );\n\tconst spacingProps = getSpacingClassesAndStyles( attributes );\n\tconst shadowProps = getShadowClassesAndStyles( attributes );\n\n\tconst Icon = ICONS[ icon ];\n\n\treturn (\n\t\t<TagName\n\t\t\t{ ...blockProps }\n\t\t\tclassName={ clsx(\n\t\t\t\tblockProps.className,\n\t\t\t\tcolorProps.className,\n\t\t\t\tborderProps.className,\n\t\t\t\t'accordion-item__heading',\n\t\t\t\t{\n\t\t\t\t\t[ `has-custom-font-size` ]: blockProps?.style?.fontSize,\n\t\t\t\t\t[ `icon-position-left` ]: iconPosition === 'left',\n\t\t\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t\t\t}\n\t\t\t) }\n\t\t\tstyle={ {\n\t\t\t\t...borderProps.style,\n\t\t\t\t...colorProps.style,\n\t\t\t\t...shadowProps.style,\n\t\t\t} }\n\t\t>\n\t\t\t<button\n\t\t\t\tclassName={ clsx( 'accordion-item__toggle' ) }\n\t\t\t\tstyle={ {\n\t\t\t\t\t...spacingProps.style,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<RichText.Content tagName=\"span\" value={ title } />\n\t\t\t\t<span\n\t\t\t\t\tclassName={ clsx( `accordion-item__toggle-icon`, {\n\t\t\t\t\t\t[ `has-icon-${ icon }` ]: icon,\n\t\t\t\t\t} ) }\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t// TO-DO: make this configurable\n\t\t\t\t\t\twidth: `1.2em`,\n\t\t\t\t\t\theight: `1.2em`,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ icon && <Icon width=\"1.2em\" height=\"1.2em\" /> }\n\t\t\t\t</span>\n\t\t\t</button>\n\t\t</TagName>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Craft a Gutenberg block designed to showcase comment content, incorporating text alignment as a key attribute for customization." }, { "role": "assistant", "content": "// File: packages/block-library/src/comment-content/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/comment-content\",\n\t\"title\": \"Comment Content\",\n\t\"category\": \"theme\",\n\t\"ancestor\": [ \"core/comment-template\" ],\n\t\"description\": \"Displays the contents of a comment.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"commentId\" ],\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": [ \"horizontal\", \"vertical\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true\n\t\t\t}\n\t\t},\n\t\t\"html\": false\n\t},\n\t\"style\": \"wp-block-comment-content\"\n}\n\n\n// File: packages/block-library/src/comment-content/index.js\n/**\n * WordPress dependencies\n */\nimport { commentContent as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\texample: {},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Craft a WordPress block enabling product grid display with customizable attribute filtering, supporting comprehensive configuration of selection criteria and layout parameters." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/products-by-attribute/block.json\n{\n\t\"name\": \"woocommerce/products-by-attribute\",\n\t\"title\": \"Products by Attribute\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"Display a grid of products with selected attributes.\",\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\"attributes\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t},\n\t\t\"attrOperator\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [ \"all\", \"any\" ],\n\t\t\t\"default\": \"any\"\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\"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\"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\"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\"isPreview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"stockStatus\": {\n\t\t\t\"type\": \"array\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/products-by-attribute/edit.tsx\n/**\n * External dependencies\n */\nimport { BlockControls, useBlockProps } from '@wordpress/block-editor';\nimport {\n\tDisabled,\n\tToolbarGroup,\n\twithSpokenMessages,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\nimport { Props } from './types';\nimport { ProductsByAttributeInspectorControls } from './inspector-controls';\nimport { ProductsByAttributeEditMode } from './edit-mode';\nimport { ProductsByAttributeBlock } from './block';\n\nexport const EditBlock = ( props: Props ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\n\tconst {\n\t\tattributes: { attributes },\n\t} = props;\n\n\tconst [ isEditing, setIsEditing ] = useState( ! attributes.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 attribute',\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<ProductsByAttributeInspectorControls { ...props } />\n\t\t\t{ isEditing ? (\n\t\t\t\t<ProductsByAttributeEditMode\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<ProductsByAttributeBlock { ...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": "Develop a dynamic Gutenberg block that conditionally renders block components based on cart product presence, utilizing a lock mechanism to manage content display." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/filled-cart-block/block.json\n{\n\t\"name\": \"woocommerce/filled-cart-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Filled Cart\",\n\t\"description\": \"Contains blocks that are displayed when the cart contains products.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": [\n\t\t\t\"wide\"\n\t\t],\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/cart\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/filled-cart-block/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport { SidebarLayout } from '@woocommerce/base-components/sidebar-layout';\nimport type { TemplateArray } from '@wordpress/blocks';\nimport { useEditorContext } from '@woocommerce/base-context';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseForcedLayout,\n\tgetAllowedBlocks,\n} from '../../../cart-checkout-shared';\nimport './editor.scss';\nimport { useCartBlockContext } from '../../context';\n\nexport const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst { currentView } = useEditorContext();\n\tconst { hasDarkControls } = useCartBlockContext();\n\tconst allowedBlocks = getAllowedBlocks( innerBlockAreas.FILLED_CART );\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/cart-items-block', {}, [] ],\n\t\t[ 'woocommerce/cart-totals-block', {}, [] ],\n\t] as TemplateArray;\n\n\tuseForcedLayout( {\n\t\tclientId,\n\t\tregisteredBlocks: allowedBlocks,\n\t\tdefaultTemplate,\n\t} );\n\treturn (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\thidden={ currentView !== 'woocommerce/filled-cart-block' }\n\t\t>\n\t\t\t<SidebarLayout\n\t\t\t\tclassName={ clsx( 'wc-block-cart', {\n\t\t\t\t\t'has-dark-controls': hasDarkControls,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<InnerBlocks\n\t\t\t\t\tallowedBlocks={ allowedBlocks }\n\t\t\t\t\ttemplate={ defaultTemplate }\n\t\t\t\t\ttemplateLock=\"insert\"\n\t\t\t\t/>\n\t\t\t</SidebarLayout>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a Gutenberg block that renders the cart fee row, implementing specified attributes including class name and locking mechanism." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-fee/block.json\n{\n\t\"name\": \"woocommerce/cart-order-summary-fee-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Fees\",\n\t\"description\": \"Shows the cart fee row.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/cart-order-summary-totals-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-fee/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\n\nexport const Edit = ( {\n\tattributes,\n}: {\n\tattributes: {\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst { className } = attributes;\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Block className={ className } />\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a Gutenberg block designed for appointment scheduling, enabling users to personalize the calendar interface through background color, event detail display, primary color, and three supplementary customization settings." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/calendly/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/calendly\",\n\t\"title\": \"Calendly\",\n\t\"description\": \"Embed a calendar for customers to schedule appointments.\",\n\t\"keywords\": [ \"calendar\", \"schedule\", \"appointments\", \"events\", \"dates\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg viewBox='0 0 23 24' width='23' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M19,1h-2.3v0c0-0.6-0.4-1-1-1c-0.6,0-1,0.4-1,1v0H8.6v0c0-0.6-0.4-1-1-1c-0.6,0-1,0.4-1,1v0H4C1.8,1,0,2.8,0,5 v15c0,2.2,1.8,4,4,4h15c2.2,0,4-1.8,4-4V5C23,2.8,21.2,1,19,1z M21,20c0,1.1-0.9,2-2,2H4c-1.1,0-2-0.9-2-2V5c0-1.1,0.9-2,2-2h2.6 v0.8c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1V3h6.1v0.8c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1V3H19c1.1,0,2,0.9,2,2V20z M13.9,14.8l1.4,1.4 c-0.9,0.9-2.1,1.3-3.5,1.3c-2.4,0-4.5-2.1-4.5-4.7s2.1-4.7,4.5-4.7c1.4,0,2.5,0.4,3.4,1.1L14,10.9c-0.5-0.4-1.2-0.6-2.1-0.6 c-1.2,0-2.5,1.1-2.5,2.7c0,1.6,1.3,2.7,2.5,2.7C12.7,15.5,13.4,15.3,13.9,14.8z'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"alignWide\": false,\n\t\t\"html\": false\n\t},\n\t\"attributes\": {\n\t\t\"backgroundColor\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"ffffff\"\n\t\t},\n\t\t\"hideEventTypeDetails\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"primaryColor\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"00A2FF\"\n\t\t},\n\t\t\"textColor\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"4D5055\"\n\t\t},\n\t\t\"style\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"inline\",\n\t\t\t\"enum\": [ \"inline\", \"link\" ]\n\t\t},\n\t\t\"url\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"hideEventTypeDetails\": false,\n\t\t\t\"style\": \"inline\",\n\t\t\t\"url\": \"https://calendly.com/wpcom/jetpack-block-example\"\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\": \"Schedule time with me\",\n\t\t\t\t\t\"uniqueId\": \"calendly-widget-id\",\n\t\t\t\t\t\"url\": \"https://calendly.com/wpcom/jetpack-block-example\"\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/calendly/edit.js\nimport { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils';\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\nimport { getBlockDefaultClassName } from '@wordpress/blocks';\nimport { Button, ExternalLink, Placeholder, Spinner, withNotices } from '@wordpress/components';\nimport { select, dispatch } from '@wordpress/data';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __, _x } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport { isEqual } from 'lodash';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport testEmbedUrl from '../../shared/test-embed-url';\nimport metadata from './block.json';\nimport { CALENDLY_EXAMPLE_URL } from './constants';\nimport CalendlyControls from './controls';\nimport { getAttributesFromEmbedCode } from './utils';\n\nimport './editor.scss';\nimport './view.scss';\n\nconst innerButtonBlock = {\n\tname: 'jetpack/button',\n\tattributes: {\n\t\telement: 'a',\n\t\ttext: __( 'Schedule time with me', 'jetpack' ),\n\t\tuniqueId: 'calendly-widget-id',\n\t\turl: CALENDLY_EXAMPLE_URL,\n\t},\n};\nconst icon = getBlockIconComponent( metadata );\n\nexport function CalendlyEdit( props ) {\n\tconst { attributes, clientId, name, noticeOperations, noticeUI, setAttributes } = props;\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 { backgroundColor, hideEventTypeDetails, primaryColor, textColor, style, url } =\n\t\tvalidatedAttributes;\n\tconst [ embedCode, setEmbedCode ] = useState( url );\n\tconst [ isEditingUrl, setIsEditingUrl ] = useState( false );\n\tconst [ isResolvingUrl, setIsResolvingUrl ] = useState( false );\n\tconst [ embedButtonAttributes, setEmbedButtonAttributes ] = useState( {} );\n\tconst blockProps = useBlockProps();\n\n\tconst setErrorNotice = () => {\n\t\tnoticeOperations.removeAllNotices();\n\t\tnoticeOperations.createErrorNotice(\n\t\t\t__( \"Your calendar couldn't be embedded. Please double check your URL or code.\", 'jetpack' )\n\t\t);\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! url || CALENDLY_EXAMPLE_URL === url || 'link' === style ) {\n\t\t\treturn;\n\t\t}\n\t\ttestEmbedUrl( url, setIsResolvingUrl ).catch( () => {\n\t\t\tsetAttributes( { url: undefined } );\n\t\t\tsetErrorNotice();\n\t\t} );\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [] );\n\n\tconst parseEmbedCode = event => {\n\t\tif ( ! event ) {\n\t\t\tsetErrorNotice();\n\t\t\treturn;\n\t\t}\n\n\t\tevent.preventDefault();\n\n\t\tconst newAttributes = getAttributesFromEmbedCode( embedCode );\n\t\tif ( ! newAttributes ) {\n\t\t\tsetErrorNotice();\n\t\t\treturn;\n\t\t}\n\n\t\tif ( newAttributes.buttonAttributes && 'link' === newAttributes.style ) {\n\t\t\tconst innerButtons = select( 'core/editor' ).getBlocksByClientId( clientId );\n\n\t\t\tif ( innerButtons.length ) {\n\t\t\t\tinnerButtons[ 0 ].innerBlocks.forEach( block => {\n\t\t\t\t\tdispatch( 'core/editor' ).updateBlockAttributes(\n\t\t\t\t\t\tblock.clientId,\n\t\t\t\t\t\tnewAttributes.buttonAttributes\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t}\n\t\t\tsetEmbedButtonAttributes( newAttributes.buttonAttributes );\n\t\t}\n\n\t\ttestEmbedUrl( newAttributes.url, setIsResolvingUrl )\n\t\t\t.then( () => {\n\t\t\t\tconst newValidatedAttributes = getValidatedAttributes( metadata.attributes, newAttributes );\n\t\t\t\tsetAttributes( newValidatedAttributes );\n\t\t\t\tsetIsEditingUrl( false );\n\t\t\t\tnoticeOperations.removeAllNotices();\n\t\t\t} )\n\t\t\t.catch( () => {\n\t\t\t\tsetAttributes( { url: undefined } );\n\t\t\t\tsetErrorNotice();\n\t\t\t} );\n\t};\n\n\tconst blockEmbedding = (\n\t\t<div className=\"wp-block-embed is-loading\">\n\t\t\t<Spinner />\n\t\t\t<p>{ __( 'Embedding…', 'jetpack' ) }</p>\n\t\t</div>\n\t);\n\n\tconst blockPlaceholder = (\n\t\t<Placeholder\n\t\t\tlabel={ __( 'Calendly', 'jetpack' ) }\n\t\t\tinstructions={ __( 'Enter your Calendly web address or embed code below.', 'jetpack' ) }\n\t\t\ticon={ icon }\n\t\t\tnotices={ noticeUI }\n\t\t>\n\t\t\t<form onSubmit={ parseEmbedCode }>\n\t\t\t\t<input\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\tid=\"embedCode\"\n\t\t\t\t\tonChange={ event => setEmbedCode( event.target.value ) }\n\t\t\t\t\tplaceholder={ __( 'Calendly web address or embed code…', 'jetpack' ) }\n\t\t\t\t\tvalue={ embedCode || '' }\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\t<div className={ `${ defaultClassName }-learn-more` }>\n\t\t\t\t<ExternalLink href=\"https://help.calendly.com/hc/en-us/articles/223147027-Embed-options-overview\">\n\t\t\t\t\t{ __( 'Need help finding your embed code?', 'jetpack' ) }\n\t\t\t\t</ExternalLink>\n\t\t\t</div>\n\t\t</Placeholder>\n\t);\n\n\tconst iframeSrc = () => {\n\t\tconst query = new URLSearchParams( {\n\t\t\tembed_domain: 'wordpress.com',\n\t\t\tembed_type: 'Inline',\n\t\t\thide_event_type_details: hideEventTypeDetails ? 1 : 0,\n\t\t\tbackground_color: backgroundColor,\n\t\t\tprimary_color: primaryColor,\n\t\t\ttext_color: textColor,\n\t\t} );\n\t\treturn `${ url }?${ query }`;\n\t};\n\n\tconst inlinePreview = (\n\t\t<>\n\t\t\t<div className={ `${ defaultClassName }-overlay` }></div>\n\t\t\t<iframe\n\t\t\t\tsrc={ iframeSrc() }\n\t\t\t\twidth=\"100%\"\n\t\t\t\theight=\"100%\"\n\t\t\t\tframeBorder=\"0\"\n\t\t\t\tdata-origwidth=\"100%\"\n\t\t\t\tdata-origheight=\"100%\"\n\t\t\t\ttitle=\"Calendly\"\n\t\t\t></iframe>\n\t\t</>\n\t);\n\n\tconst buttonPreview = (\n\t\t<InnerBlocks\n\t\t\ttemplate={ [\n\t\t\t\t[\n\t\t\t\t\tinnerButtonBlock.name,\n\t\t\t\t\t{\n\t\t\t\t\t\t...innerButtonBlock.attributes,\n\t\t\t\t\t\t...embedButtonAttributes,\n\t\t\t\t\t\tpassthroughAttributes: { url: 'url' },\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t] }\n\t\t\ttemplateLock=\"all\"\n\t\t/>\n\t);\n\n\tconst blockPreview = previewStyle => {\n\t\tif ( previewStyle === 'inline' ) {\n\t\t\treturn inlinePreview;\n\t\t}\n\n\t\treturn buttonPreview;\n\t};\n\n\tif ( isResolvingUrl ) {\n\t\treturn blockEmbedding;\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[ `calendly-style-${ style }` ]: url && ! isEditingUrl,\n\t\t\t} ) }\n\t\t>\n\t\t\t<CalendlyControls\n\t\t\t\t{ ...{\n\t\t\t\t\t...props,\n\t\t\t\t\tdefaultClassName,\n\t\t\t\t\tembedCode,\n\t\t\t\t\tisEditingUrl,\n\t\t\t\t\tparseEmbedCode,\n\t\t\t\t\tsetEmbedCode,\n\t\t\t\t\tsetIsEditingUrl,\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t{ url && ! isEditingUrl ? blockPreview( style ) : blockPlaceholder }\n\t\t</div>\n\t);\n}\n\nexport default withNotices( CalendlyEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/calendly/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 custom WordPress block that empowers users to input and showcase their company's opening hours across different days of the week." }, { "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/business-hours/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/business-hours\",\n\t\"title\": \"Business Hours\",\n\t\"description\": \"Display opening hours for your business.\",\n\t\"keywords\": [ \"opening hours\", \"closing time\", \"schedule\", \"working day\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm.5-13H11v6l5.25 3.15.75-1.23-4.5-2.67z'/></svg>\",\n\t\"supports\": {\n\t\t\"html\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"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\"days\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": [\n\t\t\t\t{\n\t\t\t\t\t\"name\": \"Sun\",\n\t\t\t\t\t\"hours\": []\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"name\": \"Mon\",\n\t\t\t\t\t\"hours\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"opening\": \"09:00\",\n\t\t\t\t\t\t\t\"closing\": \"17:00\"\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\t\"name\": \"Tue\",\n\t\t\t\t\t\"hours\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"opening\": \"09:00\",\n\t\t\t\t\t\t\t\"closing\": \"17:00\"\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\t\"name\": \"Wed\",\n\t\t\t\t\t\"hours\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"opening\": \"09:00\",\n\t\t\t\t\t\t\t\"closing\": \"17:00\"\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\t\"name\": \"Thu\",\n\t\t\t\t\t\"hours\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"opening\": \"09:00\",\n\t\t\t\t\t\t\t\"closing\": \"17:00\"\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\t\"name\": \"Fri\",\n\t\t\t\t\t\"hours\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"opening\": \"09:00\",\n\t\t\t\t\t\t\t\"closing\": \"17:00\"\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\t\"name\": \"Sat\",\n\t\t\t\t\t\"hours\": []\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"days\": [\n\t\t\t\t{\n\t\t\t\t\t\"name\": \"Sun\",\n\t\t\t\t\t\"hours\": []\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"name\": \"Mon\",\n\t\t\t\t\t\"hours\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"opening\": \"09:00\",\n\t\t\t\t\t\t\t\"closing\": \"17:00\"\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\t\"name\": \"Tue\",\n\t\t\t\t\t\"hours\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"opening\": \"09:00\",\n\t\t\t\t\t\t\t\"closing\": \"17:00\"\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\t\"name\": \"Wed\",\n\t\t\t\t\t\"hours\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"opening\": \"09:00\",\n\t\t\t\t\t\t\t\"closing\": \"17:00\"\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\t\"name\": \"Thu\",\n\t\t\t\t\t\"hours\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"opening\": \"09:00\",\n\t\t\t\t\t\t\t\"closing\": \"17:00\"\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\t\"name\": \"Fri\",\n\t\t\t\t\t\"hours\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"opening\": \"09:00\",\n\t\t\t\t\t\t\t\"closing\": \"17:00\"\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\t\"name\": \"Sat\",\n\t\t\t\t\t\"hours\": []\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/business-hours/edit.js\nimport { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils';\nimport apiFetch from '@wordpress/api-fetch';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { Placeholder } from '@wordpress/components';\nimport { getSettings } from '@wordpress/date';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport metadata from './block.json';\nimport DayEdit from './components/day-edit';\nimport DayPreview from './components/day-preview';\n\nconst icon = getBlockIconComponent( metadata );\n\nexport const defaultLocalization = {\n\tdays: {\n\t\tSun: __( 'Sunday', 'jetpack' ),\n\t\tMon: __( 'Monday', 'jetpack' ),\n\t\tTue: __( 'Tuesday', 'jetpack' ),\n\t\tWed: __( 'Wednesday', 'jetpack' ),\n\t\tThu: __( 'Thursday', 'jetpack' ),\n\t\tFri: __( 'Friday', 'jetpack' ),\n\t\tSat: __( 'Saturday', 'jetpack' ),\n\t},\n\tstartOfWeek: 0,\n};\n\nconst BusinessHours = props => {\n\tconst { attributes, isSelected } = props;\n\tconst blockProps = useBlockProps();\n\tconst [ localization, setLocalization ] = useState( defaultLocalization );\n\tconst [ hasFetched, setHasFetched ] = useState( false );\n\n\tconst { days } = attributes;\n\tconst { startOfWeek } = localization;\n\tconst localizedWeek = days.concat( days.slice( 0, startOfWeek ) ).slice( startOfWeek );\n\n\tuseEffect( () => {\n\t\tapiFetch( { path: '/wpcom/v2/business-hours/localized-week' } ).then(\n\t\t\tdata => {\n\t\t\t\tsetLocalization( data );\n\t\t\t\tsetHasFetched( true );\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tsetLocalization( defaultLocalization );\n\t\t\t\tsetHasFetched( true );\n\t\t\t}\n\t\t);\n\t}, [] );\n\n\tlet content;\n\n\tif ( ! hasFetched ) {\n\t\tcontent = <Placeholder icon={ icon } label={ __( 'Loading business hours', 'jetpack' ) } />;\n\t} else if ( ! isSelected ) {\n\t\tconst settings = getSettings();\n\t\tconst {\n\t\t\tformats: { time },\n\t\t} = settings;\n\n\t\tcontent = (\n\t\t\t<dl className=\"jetpack-business-hours\">\n\t\t\t\t{ localizedWeek.map( ( day, key ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<DayPreview key={ key } day={ day } localization={ localization } timeFormat={ time } />\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</dl>\n\t\t);\n\t} else {\n\t\tcontent = (\n\t\t\t<div className=\"is-edit\">\n\t\t\t\t{ localizedWeek.map( ( day, key ) => {\n\t\t\t\t\treturn <DayEdit key={ key } day={ day } localization={ localization } { ...props } />;\n\t\t\t\t} ) }\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn <div { ...blockProps }>{ content }</div>;\n};\n\nexport default BusinessHours;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Implement a Gutenberg block for Block: a8c/waves" }, { "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: blocks/waves/src/index.js\n/**\n * WordPress dependencies\n */\nimport { registerBlockType } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport WavesIcon from './icon';\nimport Edit from './edit';\nimport Save from './save';\n\nexport const registerBlock = () => {\n\tregisterBlockType( 'a8c/waves', {\n\t\ttitle: __( 'Waves', 'waves' ),\n\t\tdescription: __( 'Create content with waves in motion.', 'waves' ),\n\t\ticon: <WavesIcon />,\n\t\tcategory: 'widgets',\n\t\tsupports: {\n\t\t\talign: true,\n\t\t\thtml: false,\n\t\t},\n\t\tattributes: {\n\t\t\tcomplexity: {\n\t\t\t\ttype: 'integer',\n\t\t\t\tdefault: 2,\n\t\t\t},\n\t\t\tmouseSpeed: {\n\t\t\t\ttype: 'integer',\n\t\t\t\tdefault: 20,\n\t\t\t},\n\t\t\tfluidSpeed: {\n\t\t\t\ttype: 'integer',\n\t\t\t\tdefault: 20,\n\t\t\t},\n\t\t\tcolor1: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tcolor2: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tcolor3: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tcolor4: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tminHeight: {\n\t\t\t\ttype: 'number',\n\t\t\t},\n\t\t\tminHeightUnit: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tpreviewImage: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t},\n\t\tedit: Edit,\n\t\tsave: Save,\n\t} );\n};\n\n\n// File: blocks/waves/src/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nconst Save = ( { attributes } ) => {\n\tconst minHeightWithUnit = attributes.minHeightUnit\n\t\t? `${ attributes.minHeight }${ attributes.minHeightUnit }`\n\t\t: attributes.minHeight;\n\tconst style = {\n\t\tminHeight: minHeightWithUnit || undefined,\n\t\tbackgroundImage: `url( \"${ attributes.previewImage }\" )`,\n\t};\n\treturn (\n\t\t<div style={ style }>\n\t\t\t<canvas\n\t\t\t\tdata-complexity={ attributes.complexity }\n\t\t\t\tdata-mouse-speed={ attributes.mouseSpeed }\n\t\t\t\tdata-fluid-speed={ attributes.fluidSpeed }\n\t\t\t\tdata-color1={ attributes.color1 }\n\t\t\t\tdata-color2={ attributes.color2 }\n\t\t\t\tdata-color3={ attributes.color3 }\n\t\t\t\tdata-color4={ attributes.color4 }\n\t\t\t/>\n\t\t\t<div className=\"wp-block-a8c-waves__inner-container\">\n\t\t\t\t<InnerBlocks.Content />\n\t\t\t</div>\n\t\t</div>\n\t);\n};\n\nexport default Save;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a design block with customizable label, type, description, and 7 more options" }, { "role": "assistant", "content": "// File: packages/block-library/src/navigation-submenu/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/navigation-submenu\",\n\t\"title\": \"Submenu\",\n\t\"category\": \"design\",\n\t\"parent\": [ \"core/navigation\" ],\n\t\"description\": \"Add a submenu to your navigation.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"label\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"type\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"description\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"rel\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"id\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"opensInNewTab\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"url\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"title\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"kind\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"isTopLevelItem\": {\n\t\t\t\"type\": \"boolean\"\n\t\t}\n\t},\n\t\"usesContext\": [\n\t\t\"textColor\",\n\t\t\"customTextColor\",\n\t\t\"backgroundColor\",\n\t\t\"customBackgroundColor\",\n\t\t\"overlayTextColor\",\n\t\t\"customOverlayTextColor\",\n\t\t\"overlayBackgroundColor\",\n\t\t\"customOverlayBackgroundColor\",\n\t\t\"fontSize\",\n\t\t\"customFontSize\",\n\t\t\"showSubmenuIcon\",\n\t\t\"maxNestingLevel\",\n\t\t\"openSubmenusOnClick\",\n\t\t\"style\"\n\t],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-navigation-submenu-editor\",\n\t\"style\": \"wp-block-navigation-submenu\"\n}\n\n\n// File: packages/block-library/src/navigation-submenu/index.js\n/**\n * WordPress dependencies\n */\nimport { page, addSubmenu } from '@wordpress/icons';\nimport { _x, __ } from '@wordpress/i18n';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon: ( { context } ) => {\n\t\tif ( context === 'list-view' ) {\n\t\t\treturn page;\n\t\t}\n\t\treturn addSubmenu;\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst { label } = attributes;\n\n\t\tconst customName = attributes?.metadata?.name;\n\n\t\t// In the list view, use the block's menu label as the label.\n\t\t// If the menu label is empty, fall back to the default label.\n\t\tif ( context === 'list-view' && ( customName || label ) ) {\n\t\t\treturn attributes?.metadata?.name || label;\n\t\t}\n\n\t\treturn label;\n\t},\n\tedit,\n\texample: {\n\t\tattributes: {\n\t\t\tlabel: _x( 'About', 'Example link text for Navigation Submenu' ),\n\t\t\ttype: 'page',\n\t\t},\n\t},\n\tsave,\n\ttransforms,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'label',\n\t\t\tlabel: __( 'Label' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t\t{\n\t\t\tid: 'link',\n\t\t\tlabel: __( 'Link' ),\n\t\t\ttype: 'link',\n\t\t\tmapping: {\n\t\t\t\thref: 'url',\n\t\t\t\trel: 'rel',\n\t\t\t\t// TODO - opens in new tab? id?\n\t\t\t},\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'label' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/navigation-submenu/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function save() {\n\treturn <InnerBlocks.Content />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Display products from your store in a grid layout. that allows users to configure: columns, rows, align buttons, 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/products/all-products/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"textdomain\": \"woocommerce\",\n\t\"name\": \"woocommerce/all-products\",\n\t\"title\": \"All Products\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"Display products from your store in a grid layout.\",\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\"multiple\": false,\n\t\t\"inserter\": false\n\t},\n\t\"attributes\": {\n\t\t\"columns\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"rows\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"alignButtons\": {\n\t\t\t\"type\": \"boolean\"\n\t\t},\n\t\t\"contentVisibility\": {\n\t\t\t\"type\": \"object\"\n\t\t},\n\t\t\"orderby\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"layoutConfig\": {\n\t\t\t\"type\": \"array\"\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}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/products/all-products/index.js\n/**\n * External dependencies\n */\nimport { registerBlockType } from '@wordpress/blocks';\nimport { Icon, grid } from '@wordpress/icons';\nimport '@woocommerce/atomic-blocks';\n\n/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport save from './save';\nimport defaults from './defaults';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nconst settings = {\n\ticon: {\n\t\tsrc: (\n\t\t\t<Icon\n\t\t\t\ticon={ grid }\n\t\t\t\tclassName=\"wc-block-editor-components-block-icon\"\n\t\t\t/>\n\t\t),\n\t},\n\tedit,\n\t// Save the props to post content.\n\tsave,\n\tdeprecated,\n\tdefaults,\n};\n\nregisterBlockType( name, settings );\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/products/all-products/save.js\n/**\n * External dependencies\n */\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { getBlockClassName } from '../utils.js';\n\nexport default function save( { attributes } ) {\n\tconst dataAttributes = {};\n\tObject.keys( attributes )\n\t\t.sort()\n\t\t.forEach( ( key ) => {\n\t\t\tdataAttributes[ key ] = attributes[ key ];\n\t\t} );\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: getBlockClassName( 'wc-block-all-products', attributes ),\n\t\t'data-attributes': JSON.stringify( dataAttributes ),\n\t} );\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": "Build a Gutenberg block that Edit the different global regions of your site, like the header, footer, sidebar, or create your own. with these attributes: slug, theme, tag name, area" }, { "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/template-part/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/template-part\",\n\t\"title\": \"Template Part\",\n\t\"category\": \"theme\",\n\t\"description\": \"Edit the different global regions of your site, like the header, footer, sidebar, or create your own.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"slug\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"theme\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"tagName\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"area\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"html\": false,\n\t\t\"reusable\": false,\n\t\t\"renaming\": false,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-template-part-editor\"\n}\n\n\n// File: packages/block-library/src/template-part/index.js\n/**\n * External dependencies\n */\nimport { capitalCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { select } from '@wordpress/data';\nimport { symbolFilled } from '@wordpress/icons';\nimport { addFilter } from '@wordpress/hooks';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport { enhanceTemplatePartVariations } from './variations';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon: symbolFilled,\n\t__experimentalLabel: ( { slug, theme } ) => {\n\t\t// Attempt to find entity title if block is a template part.\n\t\t// Require slug to request, otherwise entity is uncreated and will throw 404.\n\t\tif ( ! slug ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { getCurrentTheme, getEditedEntityRecord } =\n\t\t\tselect( coreDataStore );\n\t\tconst entity = getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\t'wp_template_part',\n\t\t\t( theme || getCurrentTheme()?.stylesheet ) + '//' + slug\n\t\t);\n\t\tif ( ! entity ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn (\n\t\t\tdecodeEntities( entity.title ) || capitalCase( entity.slug || '' )\n\t\t);\n\t},\n\tedit,\n};\n\nexport const init = () => {\n\taddFilter(\n\t\t'blocks.registerBlockType',\n\t\t'core/template-part',\n\t\tenhanceTemplatePartVariations\n\t);\n\n\t// Prevent adding template parts inside post templates.\n\tconst DISALLOWED_PARENTS = [ 'core/post-template', 'core/post-content' ];\n\taddFilter(\n\t\t'blockEditor.__unstableCanInsertBlockType',\n\t\t'core/block-library/removeTemplatePartsFromPostTemplates',\n\t\t(\n\t\t\tcanInsert,\n\t\t\tblockType,\n\t\t\trootClientId,\n\t\t\t{ getBlock, getBlockParentsByBlockName }\n\t\t) => {\n\t\t\tif ( blockType.name !== 'core/template-part' ) {\n\t\t\t\treturn canInsert;\n\t\t\t}\n\n\t\t\tfor ( const disallowedParentType of DISALLOWED_PARENTS ) {\n\t\t\t\tconst hasDisallowedParent =\n\t\t\t\t\tgetBlock( rootClientId )?.name === disallowedParentType ||\n\t\t\t\t\tgetBlockParentsByBlockName(\n\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\tdisallowedParentType\n\t\t\t\t\t).length;\n\t\t\t\tif ( hasDisallowedParent ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t}\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": "Craft a Gutenberg block designed for order submission, incorporating a checkout form that enables customer transactions, with configurable settings for preview mode, alignment, and form step visibility." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/block.json\n{\n\t\"name\": \"woocommerce/checkout\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Checkout\",\n\t\"description\": \"Display a checkout form so your customers can submit orders.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [\n\t\t\"WooCommerce\"\n\t],\n\t\"supports\": {\n\t\t\"align\": [\n\t\t\t\"wide\"\n\t\t],\n\t\t\"html\": false,\n\t\t\"multiple\": false\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"isPreview\": true\n\t\t},\n\t\t\"viewportWidth\": 800\n\t},\n\t\"attributes\": {\n\t\t\"isPreview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false,\n\t\t\t\"save\": false\n\t\t},\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"wide\"\n\t\t},\n\t\t\"showFormStepNumbers\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport {\n\tInnerBlocks,\n\tuseBlockProps,\n\tInspectorControls,\n} from '@wordpress/block-editor';\nimport { SidebarLayout } from '@woocommerce/base-components/sidebar-layout';\nimport { CheckoutProvider, EditorProvider } from '@woocommerce/base-context';\nimport {\n\tpreviewCart,\n\tpreviewSavedPaymentMethods,\n} from '@woocommerce/resource-previews';\nimport { SlotFillProvider } from '@woocommerce/blocks-checkout';\nimport type { TemplateArray } from '@wordpress/blocks';\nimport { useEffect, useRef } from '@wordpress/element';\nimport { getQueryArg } from '@wordpress/url';\nimport { dispatch, select as selectData, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { defaultFields as defaultFieldsSetting } from '@woocommerce/settings';\n\n/**\n * Internal dependencies\n */\nimport './inner-blocks';\nimport './styles/editor.scss';\nimport {\n\taddClassToBody,\n\tBlockSettings,\n\tuseBlockPropsWithLocking,\n} from '../cart-checkout-shared';\nimport '../cart-checkout-shared/sidebar-notices';\nimport { CheckoutBlockContext } from './context';\nimport type { Attributes } from './types';\n\n// This is adds a class to body to signal if the selected block is locked\naddClassToBody();\n\n// Array of allowed block names.\nconst ALLOWED_BLOCKS: string[] = [\n\t'woocommerce/checkout-fields-block',\n\t'woocommerce/checkout-totals-block',\n];\n\nexport const Edit = ( {\n\tclientId,\n\tattributes,\n\tsetAttributes,\n}: {\n\tclientId: string;\n\tattributes: Attributes;\n\tsetAttributes: ( attributes: Record< string, unknown > ) => undefined;\n} ): JSX.Element => {\n\tconst {\n\t\tshowOrderNotes,\n\t\tshowPolicyLinks,\n\t\tshowReturnToCart,\n\t\tshowRateAfterTaxName,\n\t\tcartPageId,\n\t\tisPreview = false,\n\t\tshowFormStepNumbers = false,\n\t\thasDarkControls = false,\n\t} = attributes;\n\n\tconst fieldSettings = useSelect( ( select ) => {\n\t\treturn select(\n\t\t\tcoreStore as unknown as string\n\t\t\t// @ts-expect-error getEditedEntityRecord is not typed in @wordpress/core-data yet.\n\t\t).getEditedEntityRecord( 'root', 'site' ) as Record< string, string >;\n\t}, [] );\n\n\tconst fieldsWithDefaults = {\n\t\tphone: 'optional',\n\t\tcompany: 'hidden',\n\t\taddress_2: 'optional',\n\t} as const;\n\n\tconst defaultFields = {\n\t\t...defaultFieldsSetting,\n\t\t...Object.fromEntries(\n\t\t\tObject.entries( fieldsWithDefaults ).map(\n\t\t\t\t( [ field, defaultValue ] ) => {\n\t\t\t\t\tconst value =\n\t\t\t\t\t\tfieldSettings[\n\t\t\t\t\t\t\t`woocommerce_checkout_${ field }_field`\n\t\t\t\t\t\t] || defaultValue;\n\t\t\t\t\treturn [\n\t\t\t\t\t\tfield,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...defaultFieldsSetting[\n\t\t\t\t\t\t\t\tfield as keyof typeof defaultFieldsSetting\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\trequired: value === 'required',\n\t\t\t\t\t\t\thidden: value === 'hidden',\n\t\t\t\t\t\t},\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t)\n\t\t),\n\t};\n\n\t// This focuses on the block when a certain query param is found. This is used on the link from the task list.\n\tconst focus = useRef( getQueryArg( window.location.href, 'focus' ) );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\tfocus.current === 'checkout' &&\n\t\t\t! selectData( 'core/block-editor' ).hasSelectedBlock()\n\t\t) {\n\t\t\tdispatch( 'core/block-editor' ).selectBlock( clientId );\n\t\t\tdispatch( 'core/interface' ).enableComplementaryArea(\n\t\t\t\t'core/edit-site',\n\t\t\t\t'edit-site/block-inspector'\n\t\t\t);\n\t\t}\n\t}, [ clientId ] );\n\n\tconst defaultTemplate = [\n\t\t[ 'woocommerce/checkout-totals-block', {}, [] ],\n\t\t[ 'woocommerce/checkout-fields-block', {}, [] ],\n\t] as TemplateArray;\n\n\tconst blockProps = useBlockPropsWithLocking();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls>\n\t\t\t\t<BlockSettings\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<EditorProvider\n\t\t\t\tisPreview={ !! isPreview }\n\t\t\t\tpreviewData={ {\n\t\t\t\t\tpreviewCart,\n\t\t\t\t\tpreviewSavedPaymentMethods,\n\t\t\t\t\tdefaultFields,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<SlotFillProvider>\n\t\t\t\t\t<CheckoutProvider>\n\t\t\t\t\t\t<SidebarLayout\n\t\t\t\t\t\t\tclassName={ clsx( 'wc-block-checkout', {\n\t\t\t\t\t\t\t\t'has-dark-controls': hasDarkControls,\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<CheckoutBlockContext.Provider\n\t\t\t\t\t\t\t\tvalue={ {\n\t\t\t\t\t\t\t\t\tshowOrderNotes,\n\t\t\t\t\t\t\t\t\tshowPolicyLinks,\n\t\t\t\t\t\t\t\t\tshowReturnToCart,\n\t\t\t\t\t\t\t\t\tcartPageId,\n\t\t\t\t\t\t\t\t\tshowRateAfterTaxName,\n\t\t\t\t\t\t\t\t\tshowFormStepNumbers,\n\t\t\t\t\t\t\t\t\tdefaultFields,\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<InnerBlocks\n\t\t\t\t\t\t\t\t\tallowedBlocks={ ALLOWED_BLOCKS }\n\t\t\t\t\t\t\t\t\ttemplate={ defaultTemplate }\n\t\t\t\t\t\t\t\t\ttemplateLock=\"insert\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</CheckoutBlockContext.Provider>\n\t\t\t\t\t\t</SidebarLayout>\n\t\t\t\t\t</CheckoutProvider>\n\t\t\t\t</SlotFillProvider>\n\t\t\t</EditorProvider>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div\n\t\t\t{ ...useBlockProps.save( {\n\t\t\t\tclassName: 'wc-block-checkout is-loading',\n\t\t\t} ) }\n\t\t>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Let shoppers know when products are out of stock or on backorder. This block is hidden when products are in stock. that allows users to configure: is descendant of all products" }, { "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/stock-indicator/block.json\n{\n\t\"name\": \"woocommerce/product-stock-indicator\",\n\t\"icon\": \"info\",\n\t\"title\": \"Product Stock Indicator\",\n\t\"description\": \"Let shoppers know when products are out of stock or on backorder. This block is hidden when products are in stock.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"attributes\": {\n\t\t\"isDescendantOfAllProducts\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"interactivity\": true,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t}\n\t},\n\t\"ancestor\": [\n\t\t\"woocommerce/all-products\",\n\t\t\"woocommerce/single-product\",\n\t\t\"woocommerce/product-template\",\n\t\t\"core/post-template\"\n\t],\n\t\"usesContext\": [ \"query\", \"queryId\", \"postId\" ],\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/stock-indicator/index.ts\n/**\n * External dependencies\n */\nimport { registerProductBlockType } from '@woocommerce/atomic-utils';\nimport type { BlockConfiguration } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport edit from './edit';\nimport metadata from './block.json';\nimport { BLOCK_ICON as icon } from './constants';\n\nconst blockConfig: BlockConfiguration = {\n\t...metadata,\n\ticon: { src: icon },\n\tedit,\n\tsave: () => null,\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": "Design a theme block with comprehensive text settings, allowing users to modify alignment, type, label, and four more configurable options for enhanced customization." }, { "role": "assistant", "content": "// File: packages/block-library/src/post-navigation-link/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-navigation-link\",\n\t\"title\": \"Post Navigation Link\",\n\t\"category\": \"theme\",\n\t\"description\": \"Displays the next or previous post link that is adjacent to the current post.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"type\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"next\"\n\t\t},\n\t\t\"label\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"showTitle\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"linkLabel\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"arrow\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"none\"\n\t\t},\n\t\t\"taxonomy\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postType\" ],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"link\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalWritingMode\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-post-navigation-link\"\n}\n\n\n// File: packages/block-library/src/post-navigation-link/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport variations from './variations';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\tedit,\n\tvariations,\n\texample: {\n\t\tattributes: {\n\t\t\tlabel: __( 'Next post' ),\n\t\t\tarrow: 'arrow',\n\t\t},\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Display an icon linking to a social profile or site. that allows users to configure: url, service, label, rel" }, { "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/social-link/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/social-link\",\n\t\"title\": \"Social Icon\",\n\t\"category\": \"widgets\",\n\t\"parent\": [ \"core/social-links\" ],\n\t\"description\": \"Display an icon linking to a social profile or site.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"service\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"label\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"rel\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"usesContext\": [\n\t\t\"openInNewTab\",\n\t\t\"showLabels\",\n\t\t\"iconColor\",\n\t\t\"iconColorValue\",\n\t\t\"iconBackgroundColor\",\n\t\t\"iconBackgroundColorValue\"\n\t],\n\t\"supports\": {\n\t\t\"reusable\": 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-social-link-editor\"\n}\n\n\n// File: packages/block-library/src/social-link/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { share as icon } from '@wordpress/icons';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport edit from './edit';\nimport metadata from './block.json';\nimport variations from './variations';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tvariations,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'link',\n\t\t\tlabel: __( 'Link' ),\n\t\t\ttype: 'link',\n\t\t\tmapping: {\n\t\t\t\thref: 'url',\n\t\t\t\trel: 'rel',\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: 'label',\n\t\t\tlabel: __( 'Label' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'link' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a flexible media block offering dynamic customization options and seamless media file integration 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: projects/plugins/jetpack/extensions/blocks/story/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/story\",\n\t\"title\": \"Story\",\n\t\"description\": \"Add an interactive story.\",\n\t\"keywords\": [ \"story\", \"image\", \"video\", \"gallery\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"media\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><g><path d='M17 5a2 2 0 0 1 2 2v13a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2h9z' /><path d='M13 4H5a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2z' /><path d='M7 16h8a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z' /></g></svg>\",\n\t\"supports\": {\n\t\t\"html\": false\n\t},\n\t\"attributes\": {\n\t\t\"settings\": {\n\t\t\t\"type\": \"object\"\n\t\t},\n\t\t\"mediaFiles\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"mediaFiles\": [\n\t\t\t\t{\n\t\t\t\t\t\"alt\": \"\",\n\t\t\t\t\t\"caption\": \"\",\n\t\t\t\t\t\"mime\": \"image/jpg\",\n\t\t\t\t\t\"type\": \"image\",\n\t\t\t\t\t\"id\": 22,\n\t\t\t\t\t\"url\": \"./storyExample1.png\"\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/story/edit.js\nimport { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils';\nimport { isBlobURL } from '@wordpress/blob';\nimport { MediaPlaceholder, useBlockProps } from '@wordpress/block-editor';\nimport { withNotices } from '@wordpress/components';\nimport { useDispatch } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport metadata from './block.json';\nimport Controls from './controls';\nimport StoryPlayer from './player';\n\nimport './editor.scss';\n\nconst ALLOWED_MEDIA_TYPES = [ 'image', 'video' ];\nconst ALLOWED_MEDIA_PROPS = [\n\t'alt',\n\t'title',\n\t'id',\n\t'link',\n\t'type',\n\t'mime',\n\t'caption',\n\t'width',\n\t'height',\n];\nconst icon = getBlockIconComponent( metadata );\n\nexport const pickRelevantMediaFiles = media => {\n\tconst mediaProps = Object.fromEntries(\n\t\tObject.entries( media ).filter( ( [ k ] ) => ALLOWED_MEDIA_PROPS.includes( k ) )\n\t);\n\tmediaProps.url =\n\t\tmedia?.media_details?.original?.url ||\n\t\tmedia?.media_details?.videopress?.original ||\n\t\tmedia?.media_details?.sizes?.large?.source_url ||\n\t\tmedia?.sizes?.large?.url ||\n\t\tmedia.url;\n\tmediaProps.type = media.media_type || media.type;\n\tmediaProps.mime = media.mime_type || media.mime;\n\tmediaProps.title = mediaProps.title?.rendered || mediaProps.title;\n\tmediaProps.width = mediaProps.width || media.media_details?.width;\n\tmediaProps.height = mediaProps.height || media.media_details?.height;\n\treturn mediaProps;\n};\n\nexport default withNotices( function StoryEdit( {\n\tattributes,\n\tisSelected,\n\tnoticeOperations,\n\tnoticeUI,\n\tsetAttributes,\n} ) {\n\tconst { mediaFiles } = attributes;\n\tconst { lockPostSaving, unlockPostSaving } = useDispatch( 'core/editor' );\n\tconst blockProps = useBlockProps();\n\tconst lockName = 'storyBlockLock';\n\n\tconst onSelectMedia = newMediaFiles => {\n\t\tconst allMedia = newMediaFiles\n\t\t\t.map( newMedia => {\n\t\t\t\t// MediaPlaceholder passes only the media ids as value to MediaUpload, so we're only getting those back\n\t\t\t\tif ( ! isNaN( newMedia ) ) {\n\t\t\t\t\tconst existingMedia = mediaFiles.find( mediaFile => mediaFile.id === newMedia );\n\t\t\t\t\treturn existingMedia || { id: newMedia };\n\t\t\t\t}\n\t\t\t\treturn newMedia;\n\t\t\t} )\n\t\t\t.map( pickRelevantMediaFiles );\n\t\tconst uploadedMedias = allMedia.filter( media => ! isBlobURL( media.url ) );\n\t\t// prevent saving blob urls in mediaFiles block attribute\n\t\tif ( allMedia.length !== uploadedMedias.length ) {\n\t\t\tlockPostSaving( lockName );\n\t\t} else {\n\t\t\tunlockPostSaving( lockName );\n\t\t}\n\t\tsetAttributes( {\n\t\t\tmediaFiles: allMedia,\n\t\t} );\n\t};\n\n\tconst controls = (\n\t\t<Controls\n\t\t\tallowedMediaTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\tattributes={ attributes }\n\t\t\tonSelectMedia={ onSelectMedia }\n\t\t/>\n\t);\n\n\tconst hasImages = !! mediaFiles.length;\n\n\tconst mediaPlaceholder = (\n\t\t<MediaPlaceholder\n\t\t\taddToGallery={ hasImages }\n\t\t\tisAppender={ hasImages }\n\t\t\tclassName={ blockProps.className }\n\t\t\tdisableMediaButtons={ hasImages && ! isSelected }\n\t\t\ticon={ ! hasImages && icon }\n\t\t\tlabels={ {\n\t\t\t\ttitle: ! hasImages && __( 'Story', 'jetpack' ),\n\t\t\t\tinstructions:\n\t\t\t\t\t! hasImages &&\n\t\t\t\t\t__(\n\t\t\t\t\t\t'Drag images and videos, upload new ones, or select files from your library.',\n\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t),\n\t\t\t} }\n\t\t\tonSelect={ onSelectMedia }\n\t\t\taccept={ ALLOWED_MEDIA_TYPES.map( type => type + '/*' ).join( ',' ) }\n\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\tmultiple=\"add\"\n\t\t\tvalue={ mediaFiles }\n\t\t\tnotices={ hasImages ? undefined : noticeUI }\n\t\t\tonError={ noticeOperations.createErrorNotice }\n\t\t/>\n\t);\n\n\tlet content;\n\n\tif ( ! hasImages ) {\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t{ controls }\n\t\t\t\t{ mediaPlaceholder }\n\t\t\t</>\n\t\t);\n\t} else {\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t{ controls }\n\t\t\t\t{ noticeUI }\n\t\t\t\t<StoryPlayer\n\t\t\t\t\tslides={ mediaFiles }\n\t\t\t\t\tdisabled={ ! isSelected }\n\t\t\t\t\tshowSlideCount={ isSelected }\n\t\t\t\t\tshadowDOM={ {\n\t\t\t\t\t\tenabled: false,\n\t\t\t\t\t} }\n\t\t\t\t\tplayInFullscreen={ false }\n\t\t\t\t\ttapToPlayPause={ false }\n\t\t\t\t\tplayOnNextSlide={ false }\n\t\t\t\t/>\n\t\t\t\t{ isSelected && mediaPlaceholder }\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\tclassName={ clsx( 'wp-block-jetpack-story', 'wp-story', blockProps.className ) }\n\t\t>\n\t\t\t{ content }\n\t\t</div>\n\t);\n} );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/story/save.js\nimport { useBlockProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\nexport default () => {\n\tconst blockProps = useBlockProps.save();\n\n\treturn <div { ...blockProps } className={ clsx( 'wp-story', blockProps.className ) }></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 WordPress block for showcasing product pricing that enables customization of product identification, query loop hierarchy, text alignment, and two additional configurable parameters." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/block.json\n{\n\t\"name\": \"woocommerce/product-price\",\n\t\"title\": \"Product Price\",\n\t\"description\": \"Display the price of a product.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"attributes\": {\n\t\t\"productId\": { \"type\": \"number\", \"default\": 0 },\n\t\t\"isDescendentOfQueryLoop\": { \"type\": \"boolean\", \"default\": false },\n\t\t\"textAlign\": { \"type\": \"string\", \"default\": \"\" },\n\t\t\"isDescendentOfSingleProductTemplate\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isDescendentOfSingleProductBlock\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"usesContext\": [ \"query\", \"queryId\", \"postId\" ],\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"interactivity\": true,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true,\n\t\t\t\"link\": false\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalLetterSpacing\": true\n\t\t},\n\t\t\"__experimentalSelector\": \".wp-block-woocommerce-product-price .wc-block-components-product-price\",\n\t\t\"email\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t}\n\t},\n\t\"ancestor\": [\n\t\t\"woocommerce/all-products\",\n\t\t\"woocommerce/featured-product\",\n\t\t\"woocommerce/single-product\",\n\t\t\"woocommerce/product-template\",\n\t\t\"core/post-template\"\n\t],\n\t\"viewScriptModule\": \"product-price\",\n\t\"style\": \"file:../product-price.css\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tAlignmentToolbar,\n\tBlockControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { useEffect } from '@wordpress/element';\nimport type { BlockAlignment } from '@wordpress/blocks';\nimport { isExperimentalWcRestApiV4Enabled } from '@woocommerce/block-settings';\nimport { useProduct } from '@woocommerce/entities';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';\n\ntype UnsupportedAligments = 'wide' | 'full';\ntype AllowedAlignments = Exclude< BlockAlignment, UnsupportedAligments >;\n\ninterface BlockAttributes {\n\ttextAlign?: AllowedAlignments;\n}\n\ninterface Attributes {\n\ttextAlign: 'left' | 'center' | 'right';\n\tisDescendentOfSingleProduct: boolean;\n\tisDescendentOfSingleProductBlock: boolean;\n\tproductId: number;\n}\n\ninterface Context {\n\tqueryId: number;\n}\n\ninterface Props {\n\tattributes: Attributes;\n\tsetAttributes: (\n\t\tattributes: Partial< BlockAttributes > & Record< string, unknown >\n\t) => void;\n\tcontext: Context;\n}\n\nconst PriceEdit = ( {\n\tattributes,\n\tsetAttributes,\n\tcontext,\n}: Props ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst blockAttrs = {\n\t\t...attributes,\n\t\t...context,\n\t};\n\tconst isDescendentOfQueryLoop = Number.isFinite( context.queryId );\n\n\tlet { isDescendentOfSingleProductTemplate } =\n\t\tuseIsDescendentOfSingleProductTemplate();\n\n\tif ( isDescendentOfQueryLoop ) {\n\t\tisDescendentOfSingleProductTemplate = false;\n\t}\n\n\tuseEffect(\n\t\t() =>\n\t\t\tsetAttributes( {\n\t\t\t\tisDescendentOfQueryLoop,\n\t\t\t\tisDescendentOfSingleProductTemplate,\n\t\t\t} ),\n\t\t[\n\t\t\tisDescendentOfQueryLoop,\n\t\t\tisDescendentOfSingleProductTemplate,\n\t\t\tsetAttributes,\n\t\t]\n\t);\n\n\tconst isExperimentalWcRestApiEnabled = isExperimentalWcRestApiV4Enabled();\n\n\tconst { product } = useProduct( context.postId );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<AlignmentToolbar\n\t\t\t\t\tvalue={ attributes.textAlign }\n\t\t\t\t\tonChange={ ( textAlign: AllowedAlignments ) => {\n\t\t\t\t\t\tsetAttributes( { textAlign } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{\n\t\t\t\t\t// If experimental WC API is not available we must fallback to \"old\" way of fetching product data.\n\t\t\t\t\t// Once it's available everywhere we can remove this fallback.\n\t\t\t\t\tisExperimentalWcRestApiEnabled ? (\n\t\t\t\t\t\t<Block\n\t\t\t\t\t\t\t{ ...blockAttrs }\n\t\t\t\t\t\t\tisAdmin={ true }\n\t\t\t\t\t\t\tproduct={ product }\n\t\t\t\t\t\t\tisExperimentalWcRestApiV4Enabled={\n\t\t\t\t\t\t\t\tisExperimentalWcRestApiEnabled\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<Block\n\t\t\t\t\t\t\t{ ...blockAttrs }\n\t\t\t\t\t\t\tproduct={ undefined }\n\t\t\t\t\t\t\tisAdmin={ false }\n\t\t\t\t\t\t\tisExperimentalWcRestApiV4Enabled={ false }\n\t\t\t\t\t\t/>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t</div>\n\t\t</>\n\t);\n};\n\nexport default PriceEdit;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a WordPress block utilizing Gutenberg that renders the Mini-Cart block's title while implementing the designated lock configuration." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-title-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": "Develop a block for Display a post's featured image. that allows users to configure: is link, aspect ratio, width, and 11 more options" }, { "role": "assistant", "content": "// File: packages/block-library/src/post-featured-image/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-featured-image\",\n\t\"title\": \"Featured Image\",\n\t\"category\": \"theme\",\n\t\"description\": \"Display a post's featured image.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"isLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false,\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"aspectRatio\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"width\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"height\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"scale\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"cover\"\n\t\t},\n\t\t\"sizeSlug\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"rel\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"attribute\": \"rel\",\n\t\t\t\"default\": \"\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"_self\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"overlayColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customOverlayColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"dimRatio\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"gradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customGradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"useFirstImageFromPost\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\", \"queryId\" ],\n\t\"example\": {\n\t\t\"viewportWidth\": 350\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"left\", \"right\", \"center\", \"wide\", \"full\" ],\n\t\t\"color\": {\n\t\t\t\"text\": false,\n\t\t\t\"background\": false\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalSkipSerialization\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"filter\": {\n\t\t\t\"duotone\": true\n\t\t},\n\t\t\"shadow\": {\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"html\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"selectors\": {\n\t\t\"border\": \".wp-block-post-featured-image img, .wp-block-post-featured-image .block-editor-media-placeholder, .wp-block-post-featured-image .wp-block-post-featured-image__overlay\",\n\t\t\"shadow\": \".wp-block-post-featured-image img, .wp-block-post-featured-image .components-placeholder\",\n\t\t\"filter\": {\n\t\t\t\"duotone\": \".wp-block-post-featured-image img, .wp-block-post-featured-image .wp-block-post-featured-image__placeholder, .wp-block-post-featured-image .components-placeholder__illustration, .wp-block-post-featured-image .components-placeholder::before\"\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-post-featured-image-editor\",\n\t\"style\": \"wp-block-post-featured-image\"\n}\n\n\n// File: packages/block-library/src/post-featured-image/index.js\n/**\n * WordPress dependencies\n */\nimport { postFeaturedImage 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 an image or video with a text overlay. that allows users to configure: url, use featured image, id, and 19 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/cover/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/cover\",\n\t\"title\": \"Cover\",\n\t\"category\": \"media\",\n\t\"description\": \"Add an image or video with a text overlay.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"useFeaturedImage\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"id\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"alt\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"hasParallax\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isRepeated\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"dimRatio\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 100\n\t\t},\n\t\t\"overlayColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customOverlayColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"isUserOverlayColor\": {\n\t\t\t\"type\": \"boolean\"\n\t\t},\n\t\t\"backgroundType\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"image\"\n\t\t},\n\t\t\"focalPoint\": {\n\t\t\t\"type\": \"object\"\n\t\t},\n\t\t\"minHeight\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"minHeightUnit\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"gradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customGradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"contentPosition\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"isDark\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"templateLock\": {\n\t\t\t\"type\": [ \"string\", \"boolean\" ],\n\t\t\t\"enum\": [ \"all\", \"insert\", \"contentOnly\", false ]\n\t\t},\n\t\t\"tagName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"div\"\n\t\t},\n\t\t\"sizeSlug\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"poster\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"video\",\n\t\t\t\"attribute\": \"poster\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\" ],\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"align\": true,\n\t\t\"html\": false,\n\t\t\"shadow\": true,\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"blockGap\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true,\n\t\t\t\t\"blockGap\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"heading\": true,\n\t\t\t\"text\": true,\n\t\t\t\"background\": false,\n\t\t\t\"__experimentalSkipSerialization\": [ \"gradients\" ],\n\t\t\t\"enableContrastChecker\": false\n\t\t},\n\t\t\"dimensions\": {\n\t\t\t\"aspectRatio\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"layout\": {\n\t\t\t\"allowJustification\": false\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"filter\": {\n\t\t\t\"duotone\": true\n\t\t},\n\t\t\"allowedBlocks\": true\n\t},\n\t\"selectors\": {\n\t\t\"filter\": {\n\t\t\t\"duotone\": \".wp-block-cover > .wp-block-cover__image-background, .wp-block-cover > .wp-block-cover__video-background\"\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-cover-editor\",\n\t\"style\": \"wp-block-cover\"\n}\n\n\n// File: packages/block-library/src/cover/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { cover as icon } from '@wordpress/icons';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport variations from './variations';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tcustomOverlayColor: '#065174',\n\t\t\tdimRatio: 40,\n\t\t\turl: 'https://s.w.org/images/core/5.3/Windbuchencom.jpg',\n\t\t\tstyle: {\n\t\t\t\ttypography: {\n\t\t\t\t\tfontSize: 48,\n\t\t\t\t},\n\t\t\t\tcolor: {\n\t\t\t\t\ttext: 'white',\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/paragraph',\n\t\t\t\tattributes: {\n\t\t\t\t\tcontent: `<strong>${ __( 'Snow Patrol' ) }</strong>`,\n\t\t\t\t\talign: 'center',\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n\ttransforms,\n\tsave,\n\tedit,\n\tdeprecated,\n\tvariations,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'background',\n\t\t\tlabel: __( 'Background' ),\n\t\t\ttype: 'media',\n\t\t\tmapping: {\n\t\t\t\ttype: 'backgroundType',\n\t\t\t\tid: 'id',\n\t\t\t\turl: 'url',\n\t\t\t\talt: 'alt',\n\t\t\t\tfeaturedImage: 'useFeaturedImage',\n\t\t\t},\n\t\t\targs: {\n\t\t\t\t// TODO - How to support custom gradient?\n\t\t\t\t// Build it into Media, or use a custom control?\n\t\t\t\tallowedTypes: [ 'image', 'video' ],\n\t\t\t\tmultiple: false,\n\t\t\t},\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'background' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/cover/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseInnerBlocksProps,\n\tgetColorClassName,\n\t__experimentalGetGradientClass,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport {\n\tIMAGE_BACKGROUND_TYPE,\n\tVIDEO_BACKGROUND_TYPE,\n\tEMBED_VIDEO_BACKGROUND_TYPE,\n\tdimRatioToClass,\n\tisContentPositionCenter,\n\tgetPositionClassName,\n\tmediaPosition,\n} from './shared';\n\nexport default function save( { attributes } ) {\n\tconst {\n\t\tbackgroundType,\n\t\tgradient,\n\t\tcontentPosition,\n\t\tcustomGradient,\n\t\tcustomOverlayColor,\n\t\tdimRatio,\n\t\tfocalPoint,\n\t\tuseFeaturedImage,\n\t\thasParallax,\n\t\tisDark,\n\t\tisRepeated,\n\t\toverlayColor,\n\t\turl,\n\t\talt,\n\t\tid,\n\t\tminHeight: minHeightProp,\n\t\tminHeightUnit,\n\t\ttagName: Tag,\n\t\tsizeSlug,\n\t\tposter,\n\t} = attributes;\n\tconst overlayColorClass = getColorClassName(\n\t\t'background-color',\n\t\toverlayColor\n\t);\n\tconst gradientClass = __experimentalGetGradientClass( gradient );\n\tconst minHeight =\n\t\tminHeightProp && minHeightUnit\n\t\t\t? `${ minHeightProp }${ minHeightUnit }`\n\t\t\t: minHeightProp;\n\n\tconst isImageBackground = IMAGE_BACKGROUND_TYPE === backgroundType;\n\tconst isVideoBackground = VIDEO_BACKGROUND_TYPE === backgroundType;\n\tconst isEmbedVideoBackground =\n\t\tEMBED_VIDEO_BACKGROUND_TYPE === backgroundType;\n\n\tconst isImgElement = ! ( hasParallax || isRepeated );\n\n\tconst style = {\n\t\tminHeight: minHeight || undefined,\n\t};\n\n\tconst bgStyle = {\n\t\tbackgroundColor: ! overlayColorClass ? customOverlayColor : undefined,\n\t\tbackground: customGradient ? customGradient : undefined,\n\t};\n\n\tconst objectPosition =\n\t\t// prettier-ignore\n\t\tfocalPoint && isImgElement\n\t\t\t ? mediaPosition(focalPoint)\n\t\t\t : undefined;\n\n\tconst backgroundImage = url ? `url(${ url })` : undefined;\n\n\tconst backgroundPosition = mediaPosition( focalPoint );\n\n\tconst classes = clsx(\n\t\t{\n\t\t\t'is-light': ! isDark,\n\t\t\t'has-parallax': hasParallax,\n\t\t\t'is-repeated': isRepeated,\n\t\t\t'has-custom-content-position':\n\t\t\t\t! isContentPositionCenter( contentPosition ),\n\t\t},\n\t\tgetPositionClassName( contentPosition )\n\t);\n\n\tconst imgClasses = clsx(\n\t\t'wp-block-cover__image-background',\n\t\tid ? `wp-image-${ id }` : null,\n\t\t{\n\t\t\t[ `size-${ sizeSlug }` ]: sizeSlug,\n\t\t\t'has-parallax': hasParallax,\n\t\t\t'is-repeated': isRepeated,\n\t\t}\n\t);\n\n\tconst gradientValue = gradient || customGradient;\n\n\treturn (\n\t\t<Tag { ...useBlockProps.save( { className: classes, style } ) }>\n\t\t\t{ ! useFeaturedImage &&\n\t\t\t\tisImageBackground &&\n\t\t\t\turl &&\n\t\t\t\t( isImgElement ? (\n\t\t\t\t\t<img\n\t\t\t\t\t\tclassName={ imgClasses }\n\t\t\t\t\t\talt={ alt }\n\t\t\t\t\t\tsrc={ url }\n\t\t\t\t\t\tstyle={ { objectPosition } }\n\t\t\t\t\t\tdata-object-fit=\"cover\"\n\t\t\t\t\t\tdata-object-position={ objectPosition }\n\t\t\t\t\t/>\n\t\t\t\t) : (\n\t\t\t\t\t<div\n\t\t\t\t\t\trole={ alt ? 'img' : undefined }\n\t\t\t\t\t\taria-label={ alt ? alt : undefined }\n\t\t\t\t\t\tclassName={ imgClasses }\n\t\t\t\t\t\tstyle={ { backgroundPosition, backgroundImage } }\n\t\t\t\t\t/>\n\t\t\t\t) ) }\n\t\t\t{ isVideoBackground && url && (\n\t\t\t\t<video\n\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t'wp-block-cover__video-background',\n\t\t\t\t\t\t'intrinsic-ignore'\n\t\t\t\t\t) }\n\t\t\t\t\tautoPlay\n\t\t\t\t\tmuted\n\t\t\t\t\tloop\n\t\t\t\t\tplaysInline\n\t\t\t\t\tsrc={ url }\n\t\t\t\t\tposter={ poster }\n\t\t\t\t\tstyle={ { objectPosition } }\n\t\t\t\t\tdata-object-fit=\"cover\"\n\t\t\t\t\tdata-object-position={ objectPosition }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ isEmbedVideoBackground && url && (\n\t\t\t\t<figure\n\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t'wp-block-cover__video-background',\n\t\t\t\t\t\t'wp-block-cover__embed-background',\n\t\t\t\t\t\t'wp-block-embed'\n\t\t\t\t\t) }\n\t\t\t\t>\n\t\t\t\t\t<div className=\"wp-block-embed__wrapper\">{ url }</div>\n\t\t\t\t</figure>\n\t\t\t) }\n\n\t\t\t{ /* The `wp-block-cover__background` needs to be immediately before\n\t\t\tthe `wp-block-cover__inner-container`, so the exclusion CSS selector\n\t\t\t`.wp-block-cover__background + .wp-block-cover__inner-container`\n\t\t\tworks properly. If it needs to be changed in the future, the\n\t\t\tselector for the backward compatibility for v14 deprecation also\n\t\t\tneeds change. */ }\n\t\t\t<span\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'wp-block-cover__background',\n\t\t\t\t\toverlayColorClass,\n\t\t\t\t\tdimRatioToClass( dimRatio ),\n\t\t\t\t\t{\n\t\t\t\t\t\t'has-background-dim': dimRatio !== undefined,\n\t\t\t\t\t\t// For backwards compatibility. Former versions of the Cover Block applied\n\t\t\t\t\t\t// `.wp-block-cover__gradient-background` in the presence of\n\t\t\t\t\t\t// media, a gradient and a dim.\n\t\t\t\t\t\t'wp-block-cover__gradient-background':\n\t\t\t\t\t\t\turl && gradientValue && dimRatio !== 0,\n\t\t\t\t\t\t'has-background-gradient': gradientValue,\n\t\t\t\t\t\t[ gradientClass ]: gradientClass,\n\t\t\t\t\t}\n\t\t\t\t) }\n\t\t\t\tstyle={ bgStyle }\n\t\t\t/>\n\n\t\t\t<div\n\t\t\t\t{ ...useInnerBlocksProps.save( {\n\t\t\t\t\tclassName: 'wp-block-cover__inner-container',\n\t\t\t\t} ) }\n\t\t\t/>\n\t\t</Tag>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a WordPress theme block that allows flexible comment identification through user-configurable settings." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/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 Visually highlight a product category and encourage prompt action. with these attributes: alt, content align, dim ratio, and 12 more options" }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/featured-category/block.json\n{\n\t\"name\": \"woocommerce/featured-category\",\n\t\"title\": \"Featured Category\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"Visually highlight a product category and encourage prompt action.\",\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"ariaLabel\": true,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": true\n\t\t},\n\t\t\"html\": false,\n\t\t\"filter\": {\n\t\t\t\"duotone\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true\n\t\t\t},\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"width\": true\n\t\t\t},\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"alt\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"contentAlign\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"center\"\n\t\t},\n\t\t\"dimRatio\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 50\n\t\t},\n\t\t\"focalPoint\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"x\": 0.5,\n\t\t\t\t\"y\": 0.5\n\t\t\t}\n\t\t},\n\t\t\"imageFit\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"none\"\n\t\t},\n\t\t\"hasParallax\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isRepeated\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"mediaId\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"mediaSrc\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"minHeight\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 500\n\t\t},\n\t\t\"linkText\": {\n\t\t\t\"default\": \"Shop now\",\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"categoryId\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"overlayColor\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"#000000\"\n\t\t},\n\t\t\"overlayGradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"previewCategory\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": null\n\t\t}\n\t},\n\t\"selectors\": {\n\t\t\"filter\": {\n\t\t\t\"duotone\": \".wp-block-woocommerce-featured-category .wc-block-featured-category__background-image\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"usesContext\": [ \"termId\", \"termTaxonomy\" ],\n\t\"providesContext\": {\n\t\t\"termId\": \"categoryId\",\n\t\t\"termTaxonomy\": \"termTaxonomy\"\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/featured-category/index.tsx\n/**\n * External dependencies\n */\nimport { folderStarred } from '@woocommerce/icons';\nimport { Icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport './style.scss';\nimport './editor.scss';\nimport Block from './block';\nimport metadata from './block.json';\nimport { register } from '../register';\nimport { example } from './example';\nimport deprecated from './deprecated';\n\nregister( Block, example, metadata, {\n\tdeprecated,\n\ticon: {\n\t\tsrc: (\n\t\t\t<Icon\n\t\t\t\ticon={ folderStarred }\n\t\t\t\tclassName=\"wc-block-editor-components-block-icon\"\n\t\t\t/>\n\t\t),\n\t},\n} );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a WooCommerce block featuring adjustable locking functionality that enables dynamic configuration of access controls." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-methods-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-shipping-methods-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Shipping Options\",\n\t\"description\": \"Display shipping options and rates for your store.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-fields-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-methods-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 { shipping } from '@wordpress/icons';\nimport { ADMIN_URL, getSetting } from '@woocommerce/settings';\nimport ExternalLinkCard from '@woocommerce/editor-components/external-link-card';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport { useCheckoutAddress } from '@woocommerce/base-context/hooks';\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 ConfigurePlaceholder from '../../configure-placeholder';\nimport Block from './block';\nimport './editor.scss';\n\ntype shippingAdminLink = {\n\tid: number;\n\ttitle: string;\n\tdescription: string;\n};\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 | null => {\n\tconst globalShippingMethods = getSetting(\n\t\t'globalShippingMethods'\n\t) as shippingAdminLink[];\n\tconst activeShippingZones = getSetting(\n\t\t'activeShippingZones'\n\t) as shippingAdminLink[];\n\n\tconst { showShippingMethods } = useCheckoutAddress();\n\n\tif ( ! showShippingMethods ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<FormStepBlock\n\t\t\tattributes={ attributes }\n\t\t\tsetAttributes={ setAttributes }\n\t\t\tclassName={ clsx(\n\t\t\t\t'wc-block-checkout__shipping-option',\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={ __( 'Shipping Calculations', 'woocommerce' ) }\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'Options that control shipping 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=shipping&section=options` }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Manage shipping options', 'woocommerce' ) }\n\t\t\t\t\t</ExternalLink>{ ' ' }\n\t\t\t\t</PanelBody>\n\t\t\t\t{ globalShippingMethods.length > 0 && (\n\t\t\t\t\t<PanelBody title={ __( 'Methods', 'woocommerce' ) }>\n\t\t\t\t\t\t<p className=\"wc-block-checkout__controls-text\">\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'The following shipping integrations are active on your store.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t{ globalShippingMethods.map( ( method ) => {\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<ExternalLinkCard\n\t\t\t\t\t\t\t\t\tkey={ method.id }\n\t\t\t\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping&section=${ method.id }` }\n\t\t\t\t\t\t\t\t\ttitle={ method.title }\n\t\t\t\t\t\t\t\t\tdescription={ method.description }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping` }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Manage shipping methods', 'woocommerce' ) }\n\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t) }\n\t\t\t\t{ activeShippingZones.length && (\n\t\t\t\t\t<PanelBody title={ __( 'Shipping Zones', 'woocommerce' ) }>\n\t\t\t\t\t\t<p className=\"wc-block-checkout__controls-text\">\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Shipping Zones can be made managed in your store settings.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t{ activeShippingZones.map( ( zone ) => {\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<ExternalLinkCard\n\t\t\t\t\t\t\t\t\tkey={ zone.id }\n\t\t\t\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping&zone_id=${ zone.id }` }\n\t\t\t\t\t\t\t\t\ttitle={ zone.title }\n\t\t\t\t\t\t\t\t\tdescription={ zone.description }\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) }\n\t\t\t</InspectorControls>\n\t\t\t<Noninteractive>\n\t\t\t\t<Block\n\t\t\t\t\tnoShippingPlaceholder={\n\t\t\t\t\t\t<ConfigurePlaceholder\n\t\t\t\t\t\t\ticon={ shipping }\n\t\t\t\t\t\t\tlabel={ __( 'Shipping options', 'woocommerce' ) }\n\t\t\t\t\t\t\tdescription={ __(\n\t\t\t\t\t\t\t\t'Your store does not have any Shipping Options configured. Once you have added your Shipping Options they will appear here.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tbuttonLabel={ __(\n\t\t\t\t\t\t\t\t'Configure Shipping Options',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tbuttonHref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping` }\n\t\t\t\t\t\t/>\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</Noninteractive>\n\t\t\t<AdditionalFields block={ innerBlockAreas.SHIPPING_METHODS } />\n\t\t</FormStepBlock>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<AdditionalFieldsContent />\n\t\t</div>\n\t);\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a woocommerce block with customizable lock" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-products-table-block/block.json\n{\n\t\"name\": \"woocommerce/mini-cart-products-table-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Mini-Cart Products Table\",\n\t\"description\": \"Block that displays the products table 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\"interactivity\": true\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [ \"woocommerce/mini-cart-items-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-products-table-block/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 = (): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Noninteractive>\n\t\t\t\t<Block className=\"is-mobile\" />\n\t\t\t</Noninteractive>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() }></div>;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a woocommerce block with customizable display style, icon style, icon class" }, { "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/customer-account/block.json\n{\n\t\"name\": \"woocommerce/customer-account\",\n\t\"title\": \"Customer account\",\n\t\"description\": \"A block that allows your customers to log in and out of their accounts in your store.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\", \"My Account\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"align\": true,\n\t\t\"color\": {\n\t\t\t\"text\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"__experimentalFontFamily\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"displayStyle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"icon_and_text\"\n\t\t},\n\t\t\"iconStyle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"default\"\n\t\t},\n\t\t\"iconClass\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"icon\"\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/customer-account/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { Disabled } from '@wordpress/components';\nimport type { BlockEditProps } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport { Attributes } from './types';\nimport { BlockSettings } from './sidebar-settings';\nimport './editor.scss';\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: BlockEditProps< Attributes > ) => {\n\tconst { className } = attributes;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( 'wc-block-editor-customer-account', className ),\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<BlockSettings\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<Disabled>\n\t\t\t\t\t<Block attributes={ attributes } />\n\t\t\t\t</Disabled>\n\t\t\t</div>\n\t\t</>\n\t);\n};\n\nexport default Edit;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a WordPress block enabling simple text enhancement with configurable options for adding headings, lists, and hyperlinks to plain content." }, { "role": "assistant", "content": "// File: projects/plugins/jetpack/extensions/blocks/markdown/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/markdown\",\n\t\"title\": \"Markdown\",\n\t\"description\": \"Add headings, lists, or links to plain text with ease.\",\n\t\"keywords\": [ \"formatting\", \"syntax\", \"markup\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"text\",\n\t\"icon\": \"<svg viewBox='0 0 208 128' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><rect width='198' height='118' x='5' y='5' ry='10' stroke='currentColor' strokeWidth='10' fill='none' /><path d='M30 98v-68h20l20 25 20-25h20v68h-20v-39l-20 25-20-25v39zM155 98l-30-33h20v-35h20v35h20z' />\",\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true,\n\t\t\t\t\"margin\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"attributes\": { \"source\": { \"type\": \"string\" } },\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"source\": \"## ## Try Markdown\\n\\nMarkdown is a text formatting syntax that is converted into HTML. You can _emphasize_ text or **make it strong** with just a few characters.\"\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/markdown/edit.js\nimport { BlockControls, PlainText, useBlockProps } from '@wordpress/block-editor';\nimport { compose } from '@wordpress/compose';\nimport { withDispatch, withSelect } from '@wordpress/data';\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport ToolbarButton from './controls';\nimport MarkdownRenderer from './renderer';\n\n/**\n * Module variables\n */\nconst PANEL_EDITOR = 'editor';\nconst PANEL_PREVIEW = 'preview';\n\nconst MarkdownEdit = ( { attributes, setAttributes, isSelected, removeBlock } ) => {\n\tconst { source } = attributes;\n\tconst isEmpty = ! source || source.trim() === '';\n\n\tconst blockProps = useBlockProps();\n\tconst { className } = blockProps;\n\tconst [ activePanel, setActivePanel ] = useState( PANEL_EDITOR );\n\tconst input = useRef( null );\n\n\tconst onChange = s => setAttributes( { source: s } );\n\tconst onKeyDown = e => {\n\t\t// Remove the block if source is empty and we're pressing the Backspace key\n\t\tif ( e.keyCode === 8 && source === '' ) {\n\t\t\tremoveBlock();\n\t\t\te.preventDefault();\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( isSelected ) {\n\t\t\tif ( activePanel === PANEL_EDITOR ) {\n\t\t\t\tinput?.current.focus();\n\t\t\t}\n\t\t} else if ( activePanel === PANEL_PREVIEW ) {\n\t\t\tsetActivePanel( PANEL_EDITOR );\n\t\t}\n\t}, [ isSelected, activePanel, setActivePanel ] );\n\n\tlet content;\n\n\tif ( ! isSelected && isEmpty ) {\n\t\tcontent = (\n\t\t\t<p className={ `${ className }__placeholder` }>\n\t\t\t\t{ __( 'Write your _Markdown_ **here**…', 'jetpack' ) }\n\t\t\t</p>\n\t\t);\n\t} else {\n\t\tcontent = (\n\t\t\t<div className={ className }>\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<div className=\"components-toolbar\">\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tclassName={ className }\n\t\t\t\t\t\t\tlabel={ __( 'Markdown', 'jetpack' ) }\n\t\t\t\t\t\t\tisPressed={ activePanel === PANEL_EDITOR }\n\t\t\t\t\t\t\tonClick={ () => setActivePanel( PANEL_EDITOR ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tclassName={ className }\n\t\t\t\t\t\t\tlabel={ __( 'Preview', 'jetpack' ) }\n\t\t\t\t\t\t\tisPressed={ activePanel === PANEL_PREVIEW }\n\t\t\t\t\t\t\tonClick={ () => setActivePanel( PANEL_PREVIEW ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</BlockControls>\n\n\t\t\t\t{ activePanel === PANEL_PREVIEW || ! isSelected ? (\n\t\t\t\t\t<MarkdownRenderer className={ `${ className }__preview` } source={ source } />\n\t\t\t\t) : (\n\t\t\t\t\t<PlainText\n\t\t\t\t\t\tclassName={ `${ className }__editor` }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\taria-label={ __( 'Markdown', 'jetpack' ) }\n\t\t\t\t\t\tref={ input }\n\t\t\t\t\t\tvalue={ source }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn <div { ...blockProps }>{ content }</div>;\n};\n\nexport default compose( [\n\twithSelect( select => ( {\n\t\tcurrentBlockId: select( 'core/block-editor' ).getSelectedBlockClientId(),\n\t} ) ),\n\twithDispatch( ( dispatch, { currentBlockId } ) => ( {\n\t\tremoveBlock: () => dispatch( 'core/block-editor' ).removeBlocks( currentBlockId ),\n\t} ) ),\n] )( MarkdownEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/markdown/save.js\nimport { useBlockProps } from '@wordpress/block-editor';\nimport MarkdownRenderer from './renderer';\n\nexport default ( { attributes } ) => {\n\tconst blockProps = useBlockProps.save();\n\n\treturn (\n\t\t<MarkdownRenderer { ...blockProps } source={ attributes.source } attributes={ attributes } />\n\t);\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a theme block with customizable text align, more text, show more on new line, excerpt length" }, { "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-excerpt/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-excerpt\",\n\t\"title\": \"Excerpt\",\n\t\"category\": \"theme\",\n\t\"description\": \"Display the excerpt.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"moreText\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"showMoreOnNewLine\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"excerptLength\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 55\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\", \"queryId\" ],\n\t\"example\": {\n\t\t\"viewportWidth\": 350\n\t},\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-post-excerpt-editor\",\n\t\"style\": \"wp-block-post-excerpt\"\n}\n\n\n// File: packages/block-library/src/post-excerpt/index.js\n/**\n * WordPress dependencies\n */\nimport { postExcerpt as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport transforms from './transforms';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\ttransforms,\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": "Build a Gutenberg block that Displays the link to the current post comments. with these attributes: text align" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/post-comments-link/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-comments-link\",\n\t\"title\": \"Comments Link\",\n\t\"category\": \"theme\",\n\t\"description\": \"Displays the link to the current post comments.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"postType\", \"postId\" ],\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\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\"link\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\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-comments-link\"\n}\n\n\n// File: packages/block-library/src/post-comments-link/index.js\n/**\n * WordPress dependencies\n */\nimport { postCommentsCount as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport transforms from './transforms';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\tedit,\n\ticon,\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 Gutenberg block that Elevate your content creation with our AI-powered Gutenberg Block, offering seamless customization and generation. Bear in mind that, as an evolving tool, occasional imprecision may occur. with these attributes: content, original content, prompt type, and 5 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/ai-assistant/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/ai-assistant\",\n\t\"title\": \"AI Assistant\",\n\t\"description\": \"Elevate your content creation with our AI-powered Gutenberg Block, offering seamless customization and generation. Bear in mind that, as an evolving tool, occasional imprecision may occur.\",\n\t\"keywords\": [ \"AI\", \"GPT\", \"AL\", \"Magic\", \"help\", \"assistant\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"text\",\n\t\"icon\": \"<svg viewBox='0 0 32 32' width='32' height='32' xmlns='http://www.w3.org/2000/svg'><path d='M9.33301 5.33325L10.4644 8.20188L13.333 9.33325L10.4644 10.4646L9.33301 13.3333L8.20164 10.4646L5.33301 9.33325L8.20164 8.20188L9.33301 5.33325Z'/><path d='M21.3333 5.33333L22.8418 9.15817L26.6667 10.6667L22.8418 12.1752L21.3333 16L19.8248 12.1752L16 10.6667L19.8248 9.15817L21.3333 5.33333Z'/><path d='M14.6667 13.3333L16.5523 18.1144L21.3333 20L16.5523 21.8856L14.6667 26.6667L12.781 21.8856L8 20L12.781 18.1144L14.6667 13.3333Z'/></svg>\",\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"multiple\": true,\n\t\t\"reusable\": false\n\t},\n\t\"attributes\": {\n\t\t\"content\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\n\t\t\"originalContent\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\n\t\t\"promptType\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\n\t\t\"originalMessages\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t},\n\n\t\t\"messages\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t},\n\n\t\t\"userPrompt\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\n\t\t\"requestingState\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"init\"\n\t\t},\n\n\t\t\"preTransformAction\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": null\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"content\": \"With **Jetpack AI Assistant**, you can provide a prompt, and it will generate high-quality blog posts, informative pages, well-organized lists, and thorough tables that meet your specific requirements.\\n\\nTo start using the **Jetpack AI Assistant**, type `/AI` in the block editor.\"\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/ai-assistant/edit.js\n/**\n * External dependencies\n */\nimport {\n\tBlockAIControl,\n\tUpgradeMessage,\n\trenderHTMLFromMarkdown,\n\tPROMPT_TYPE_GENERATE_TITLE,\n\tmapActionToHumanText,\n\tQuotaExceededMessage,\n\tFairUsageNotice,\n\tuseAICheckout,\n\tuseAiFeature,\n} from '@automattic/jetpack-ai-client';\nimport {\n\tuseAnalytics,\n\tPLAN_TYPE_FREE,\n\tPLAN_TYPE_UNLIMITED,\n\tusePlanType,\n\tisUserConnected,\n} from '@automattic/jetpack-shared-extension-utils';\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport { rawHandler } from '@wordpress/blocks';\nimport {\n\tNotice,\n\tPanelBody,\n\tPanelRow,\n\tKeyboardShortcuts,\n\tExternalLink,\n} from '@wordpress/components';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { RawHTML, useState, useCallback, useEffect, useRef } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport clsx from 'clsx';\n/**\n * Internal dependencies\n */\nimport UsagePanel from '../../plugins/ai-assistant-plugin/components/usage-panel';\nimport { USAGE_PANEL_PLACEMENT_BLOCK_SETTINGS_SIDEBAR } from '../../plugins/ai-assistant-plugin/components/usage-panel/types';\nimport ConnectBanner from '../../shared/components/connect-banner';\nimport FeedbackControl from './components/feedback-control';\nimport ToolbarControls from './components/toolbar-controls';\nimport useAIAssistant from './hooks/use-ai-assistant';\nimport useAiProductPage from './hooks/use-ai-product-page';\nimport { getStoreBlockId } from './hooks/use-transform-to-assistant';\nimport './editor.scss';\n\nconst isInBlockEditor = window?.Jetpack_Editor_Initial_State?.screenBase === 'post';\n\nexport default function AIAssistantEdit( { attributes, setAttributes, clientId, isSelected } ) {\n\tconst [ errorDismissed, setErrorDismissed ] = useState( null );\n\tconst { tracks } = useAnalytics();\n\n\tconst { getBlock } = useSelect( 'core/block-editor' );\n\n\tconst aiControlRef = useRef( null );\n\tconst blockRef = useRef( null );\n\n\tconst { replaceBlocks, removeBlock } = useDispatch( 'core/block-editor' );\n\tconst { editPost } = useDispatch( 'core/editor' );\n\n\tconst [ lastAction, setLastAction ] = useState(\n\t\tmapActionToHumanText( attributes.preTransformAction )\n\t);\n\n\tconst {\n\t\tisOverLimit,\n\t\trequireUpgrade,\n\t\tincreaseRequestsCount,\n\t\trequestsCount,\n\t\trequestsLimit,\n\t\tcurrentTier,\n\t\tloading: loadingAiFeature,\n\t\ttierPlansEnabled,\n\t} = useAiFeature();\n\tconst requestsRemaining = Math.max( requestsLimit - requestsCount, 0 );\n\n\tconst { autosaveAndRedirect } = useAICheckout();\n\tconst planType = usePlanType( currentTier );\n\n\tconst focusOnPrompt = () => {\n\t\t/*\n\t\t * Increase the AI Suggestion counter.\n\t\t * @todo: move this at store level.\n\t\t */\n\t\t// Small delay to avoid focus crash\n\t\tsetTimeout( () => {\n\t\t\taiControlRef.current?.focus?.();\n\t\t}, 100 );\n\t};\n\n\tconst focusOnBlock = () => {\n\t\t// Small delay to avoid focus crash\n\t\tsetTimeout( () => {\n\t\t\tblockRef.current?.focus?.();\n\t\t}, 100 );\n\t};\n\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\n\tconst contentRef = useRef( null );\n\n\tconst {\n\t\tgetSuggestionFromOpenAI,\n\t\tstopSuggestion,\n\t\tshowRetry,\n\t\tcontentBefore,\n\t\tpostTitle,\n\t\tretryRequest,\n\t\twholeContent,\n\t\trequestingState,\n\t\terror,\n\t} = useAIAssistant( {\n\t\tonSuggestionDone: useCallback(\n\t\t\tskipRequestCount => {\n\t\t\t\tfocusOnPrompt();\n\t\t\t\tif ( ! skipRequestCount ) {\n\t\t\t\t\tincreaseRequestsCount();\n\t\t\t\t}\n\t\t\t},\n\t\t\t[ increaseRequestsCount ]\n\t\t),\n\t\tonUnclearPrompt: useCallback( () => {\n\t\t\tfocusOnBlock();\n\t\t\tincreaseRequestsCount();\n\t\t}, [ increaseRequestsCount ] ),\n\t\tonModeration: focusOnPrompt,\n\t\tattributes,\n\t\tclientId,\n\t\tcontent: attributes.content,\n\t\ttracks,\n\t\tuserPrompt: attributes.userPrompt,\n\t\trequireUpgrade,\n\t\tinitialRequestingState: attributes.requestingState,\n\t\tcontentRef,\n\t\tblockRef,\n\t} );\n\n\tconst isWaitingResponse = requestingState === 'requesting';\n\tconst isLoadingCompletion = [ 'requesting', 'suggesting' ].includes( requestingState );\n\n\tconst connected = isUserConnected();\n\n\tconst { productPageUrl } = useAiProductPage();\n\n\t/*\n\t * Auto request the prompt if we detect\n\t * it was previously defined in the local storage.\n\t */\n\tconst storeBlockId = getStoreBlockId( clientId );\n\tuseEffect( () => {\n\t\tif ( ! storeBlockId ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Get the parsed data from the local storage.\n\t\tconst data = JSON.parse( localStorage.getItem( storeBlockId ) );\n\t\tif ( ! data ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { type, options } = data;\n\n\t\t// Clean up the local storage asap.\n\t\tlocalStorage.removeItem( storeBlockId );\n\n\t\tgetSuggestionFromOpenAI( type, options );\n\t}, [ storeBlockId, getSuggestionFromOpenAI ] );\n\n\tuseEffect( () => {\n\t\tif ( error ) {\n\t\t\tsetErrorDismissed( false );\n\t\t}\n\t}, [ error ] );\n\n\tuseEffect( () => {\n\t\t// we don't want to store \"half way\" states\n\t\tif ( ! [ 'init', 'done' ].includes( requestingState ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetAttributes( { requestingState } );\n\t}, [ requestingState, setAttributes ] );\n\n\t// Content is loaded\n\tconst contentIsLoaded = !! attributes.content;\n\n\tconst getLastEditableElement = newContentBlocks => {\n\t\tlet lastEditableElement = null;\n\n\t\tnewContentBlocks.forEach( block => {\n\t\t\tconst element = document.querySelector( `.wp-block[data-block=\"${ block.clientId }\"]` );\n\t\t\tif ( ! element ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( element.contentEditable === 'true' ) {\n\t\t\t\tlastEditableElement = element;\n\t\t\t}\n\n\t\t\tconst editableChildren = element.querySelectorAll( `[contenteditable=true]` );\n\t\t\tlastEditableElement = editableChildren.length\n\t\t\t\t? editableChildren[ editableChildren.length - 1 ]\n\t\t\t\t: lastEditableElement;\n\t\t} );\n\n\t\treturn lastEditableElement;\n\t};\n\n\tconst isGeneratingTitle = attributes.promptType === PROMPT_TYPE_GENERATE_TITLE;\n\n\tconst acceptContentLabel = __( 'Accept', 'jetpack' );\n\tconst acceptTitleLabel = __( 'Accept title', 'jetpack' );\n\tconst acceptLabel = isGeneratingTitle ? acceptTitleLabel : acceptContentLabel;\n\n\tconst moveCaretToEnd = element => {\n\t\tconst selection = element.ownerDocument.getSelection();\n\t\tselection.selectAllChildren( element );\n\t\tselection.collapseToEnd();\n\t\telement.focus();\n\t};\n\n\tconst handleGetSuggestion = ( ...args ) => {\n\t\tgetSuggestionFromOpenAI( ...args );\n\t\tfocusOnBlock();\n\t};\n\n\tconst handleChange = value => {\n\t\tsetErrorDismissed( true );\n\t\tsetAttributes( { userPrompt: value } );\n\t};\n\n\tconst handleSend = () => {\n\t\tsetLastAction( attributes.userPrompt );\n\t\thandleGetSuggestion( 'userPrompt' );\n\t\ttracks.recordEvent( 'jetpack_ai_assistant_block_generate', { feature: 'ai-assistant' } );\n\t};\n\n\tconst handleAccept = () => {\n\t\tif ( isGeneratingTitle ) {\n\t\t\thandleAcceptTitle();\n\t\t} else {\n\t\t\thandleAcceptContent();\n\t\t}\n\t};\n\n\tconst replaceContent = async () => {\n\t\tlet newGeneratedBlocks = [];\n\n\t\tlet HTML = renderHTMLFromMarkdown( { content: attributes.content || '' } );\n\n\t\tconst seemsToIncludeTitle =\n\t\t\tHTML?.split( '\\n' ).length > 1 && HTML?.split( '\\n' )?.[ 0 ]?.match( /^<h1>.*<\\/h1>$/ );\n\n\t\tif ( seemsToIncludeTitle && ! postTitle ) {\n\t\t\t// split HTML on new line characters\n\t\t\tconst htmlLines = HTML.split( '\\n' );\n\t\t\t// take the first line as title\n\t\t\tconst title = htmlLines.shift();\n\t\t\t// rejoin the rest of the lines on HTML\n\t\t\tHTML = htmlLines.join( '\\n' );\n\t\t\t// set the title as post title\n\t\t\teditPost( { title: title.replace( /<[^>]*>/g, '' ) } );\n\t\t}\n\t\tnewGeneratedBlocks = rawHandler( { HTML: HTML } );\n\n\t\t// Replace the block with the new generated blocks\n\t\tawait replaceBlocks( clientId, newGeneratedBlocks );\n\n\t\t// Move the caret to the end of the last editable element\n\t\tconst lastEditableElement = getLastEditableElement( newGeneratedBlocks );\n\t\tif ( lastEditableElement ) {\n\t\t\tmoveCaretToEnd( lastEditableElement );\n\t\t}\n\t};\n\n\tconst handleAcceptContent = () => {\n\t\treplaceContent();\n\t\ttracks.recordEvent( 'jetpack_ai_assistant_block_accept', { feature: 'ai-assistant' } );\n\t};\n\n\tconst handleAcceptTitle = () => {\n\t\tif ( isInBlockEditor ) {\n\t\t\teditPost( { title: attributes.content ? attributes.content.trim() : '' } );\n\t\t\tremoveBlock( clientId );\n\t\t\ttracks.recordEvent( 'jetpack_ai_assistant_block_accept', { feature: 'ai-assistant' } );\n\t\t} else {\n\t\t\thandleAcceptContent();\n\t\t}\n\t};\n\n\tconst handleDiscard = () => {\n\t\tconst isDismiss = attributes?.content === getBlock( clientId ).attributes?.content;\n\t\tsetAttributes( {\n\t\t\tcontent: attributes?.originalContent,\n\t\t\tpromptType: undefined,\n\t\t\tmessages: attributes?.originalMessages,\n\t\t} );\n\t\treplaceContent();\n\t\tif ( isDismiss ) {\n\t\t\ttracks.recordEvent( 'jetpack_ai_assistant_block_dismiss' );\n\t\t} else {\n\t\t\ttracks.recordEvent( 'jetpack_ai_assistant_block_discard', { feature: 'ai-assistant' } );\n\t\t}\n\t};\n\n\tconst handleStopSuggestion = () => {\n\t\tstopSuggestion();\n\t\tfocusOnPrompt();\n\t\ttracks.recordEvent( 'jetpack_ai_assistant_block_stop', { feature: 'ai-assistant' } );\n\t};\n\n\tconst handleGetSuggestionFromToolbar = ( type, options ) => {\n\t\tconst humanText = mapActionToHumanText( type, options );\n\t\tsetLastAction( humanText );\n\t\tgetSuggestionFromOpenAI( type, options );\n\t};\n\n\tconst blockProps = useBlockProps( {\n\t\tref: blockRef,\n\t\tclassName: clsx( { 'is-waiting-response': isWaitingResponse } ),\n\t} );\n\n\tconst promptPlaceholder = __( 'Ask Jetpack AI…', 'jetpack' );\n\tconst promptPlaceholderWithSamples = __( 'Write about… Make a table for…', 'jetpack' );\n\n\tconst banner = (\n\t\t<>\n\t\t\t{ isOverLimit && isSelected && <QuotaExceededMessage placement=\"ai-assistant-block\" /> }\n\t\t\t{ ! connected && <ConnectBanner block=\"AI Assistant\" /> }\n\t\t</>\n\t);\n\n\tconst errorNotice = (\n\t\t<>\n\t\t\t{ error?.message && ! errorDismissed && error?.code !== 'error_quota_exceeded' && (\n\t\t\t\t<Notice\n\t\t\t\t\tstatus={ error.status }\n\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\tclassName=\"jetpack-ai-assistant__error\"\n\t\t\t\t>\n\t\t\t\t\t{ error.message }\n\t\t\t\t</Notice>\n\t\t\t) }\n\t\t</>\n\t);\n\n\tconst fairUsageNotice =\n\t\tisOverLimit && planType === PLAN_TYPE_UNLIMITED ? <FairUsageNotice variant=\"muted\" /> : null;\n\n\tconst trackUpgradeClick = useCallback(\n\t\tevent => {\n\t\t\tevent.preventDefault();\n\t\t\ttracks.recordEvent( 'jetpack_ai_upgrade_button', {\n\t\t\t\tcurrent_tier_slug: currentTier?.slug,\n\t\t\t\trequests_count: requestsCount,\n\t\t\t\tplacement: 'jetpack_ai_assistant_block',\n\t\t\t} );\n\t\t\tautosaveAndRedirect( event );\n\t\t},\n\t\t[ tracks, currentTier, requestsCount, autosaveAndRedirect ]\n\t);\n\n\treturn (\n\t\t<KeyboardShortcuts\n\t\t\tbindGlobal\n\t\t\tshortcuts={ {\n\t\t\t\tesc: () => {\n\t\t\t\t\tif ( [ 'requesting', 'suggesting' ].includes( requestingState ) ) {\n\t\t\t\t\t\thandleStopSuggestion();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t} }\n\t\t>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ contentIsLoaded && (\n\t\t\t\t\t<div ref={ contentRef } className=\"jetpack-ai-assistant__content\">\n\t\t\t\t\t\t<RawHTML>{ renderHTMLFromMarkdown( { content: attributes.content || '' } ) }</RawHTML>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t{ fairUsageNotice && (\n\t\t\t\t\t\t<div className=\"block-editor-block-card\" style={ { paddingTop: 0 } }>\n\t\t\t\t\t\t\t<span className=\"block-editor-block-icon\"></span>\n\t\t\t\t\t\t\t{ fairUsageNotice }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t\t{ /* Mock BlockCard component styles to keep alignment */ }\n\t\t\t\t\t<div className=\"block-editor-block-card\" style={ { paddingTop: 0 } }>\n\t\t\t\t\t\t<span className=\"block-editor-block-icon\"></span>\n\t\t\t\t\t\t<ExternalLink href={ productPageUrl }>\n\t\t\t\t\t\t\t{ __( 'Discover all features', 'jetpack' ) }\n\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t</div>\n\t\t\t\t\t{ ( planType === PLAN_TYPE_FREE ||\n\t\t\t\t\t\t( tierPlansEnabled && planType !== PLAN_TYPE_UNLIMITED ) ) && (\n\t\t\t\t\t\t<PanelBody initialOpen={ true }>\n\t\t\t\t\t\t\t<PanelRow>\n\t\t\t\t\t\t\t\t<UsagePanel placement={ USAGE_PANEL_PLACEMENT_BLOCK_SETTINGS_SIDEBAR } />\n\t\t\t\t\t\t\t</PanelRow>\n\t\t\t\t\t\t</PanelBody>\n\t\t\t\t\t) }\n\t\t\t\t\t<PanelBody initialOpen={ true }>\n\t\t\t\t\t\t<PanelRow>\n\t\t\t\t\t\t\t<FeedbackControl />\n\t\t\t\t\t\t</PanelRow>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t</InspectorControls>\n\n\t\t\t\t{ ! isLoadingCompletion && connected && ! requireUpgrade && (\n\t\t\t\t\t<ToolbarControls\n\t\t\t\t\t\tisWaitingState={ isLoadingCompletion }\n\t\t\t\t\t\tcontentIsLoaded={ contentIsLoaded }\n\t\t\t\t\t\tgetSuggestionFromOpenAI={ handleGetSuggestionFromToolbar }\n\t\t\t\t\t\tretryRequest={ retryRequest }\n\t\t\t\t\t\thandleAcceptContent={ handleAcceptContent }\n\t\t\t\t\t\thandleAcceptTitle={ handleAcceptTitle }\n\t\t\t\t\t\thandleTryAgain={ null }\n\t\t\t\t\t\tshowRetry={ showRetry }\n\t\t\t\t\t\tcontentBefore={ contentBefore }\n\t\t\t\t\t\thasPostTitle={ !! postTitle?.length }\n\t\t\t\t\t\twholeContent={ wholeContent }\n\t\t\t\t\t\tpromptType={ attributes.promptType }\n\t\t\t\t\t\tsetUserPrompt={ prompt => {\n\t\t\t\t\t\t\tif ( ! aiControlRef?.current ) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst userPromptInput = aiControlRef.current;\n\n\t\t\t\t\t\t\t// Focus the text area\n\t\t\t\t\t\t\tuserPromptInput.focus();\n\n\t\t\t\t\t\t\tsetAttributes( { userPrompt: prompt } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\trecordEvent={ tracks.recordEvent }\n\t\t\t\t\t\tisGeneratingTitle={ isGeneratingTitle }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t<BlockAIControl\n\t\t\t\t\tref={ aiControlRef }\n\t\t\t\t\tdisabled={ requireUpgrade || ! connected }\n\t\t\t\t\tvalue={ attributes.userPrompt }\n\t\t\t\t\tplaceholder={ attributes?.content ? promptPlaceholder : promptPlaceholderWithSamples }\n\t\t\t\t\tonChange={ handleChange }\n\t\t\t\t\tonSend={ handleSend }\n\t\t\t\t\tonStop={ handleStopSuggestion }\n\t\t\t\t\tonAccept={ handleAccept }\n\t\t\t\t\tonDiscard={ handleDiscard }\n\t\t\t\t\tstate={ requestingState }\n\t\t\t\t\tisTransparent={ requireUpgrade || ! connected }\n\t\t\t\t\tshowButtonLabels={ ! isMobileViewport }\n\t\t\t\t\tshowAccept={ requestingState !== 'init' && contentIsLoaded && ! isLoadingCompletion }\n\t\t\t\t\tacceptLabel={ acceptLabel }\n\t\t\t\t\tshowGuideLine={ contentIsLoaded }\n\t\t\t\t\tshowRemove={ attributes?.content?.length > 0 }\n\t\t\t\t\tbanner={ banner }\n\t\t\t\t\terror={ errorNotice }\n\t\t\t\t\tcustomFooter={\n\t\t\t\t\t\t// Only show the upgrade message on each 5th request or if it's the first request - and only if the user is on the free plan\n\t\t\t\t\t\t( requestsRemaining % 5 === 0 || requestsCount === 1 ) &&\n\t\t\t\t\t\t! loadingAiFeature && // Don't show the upgrade message while the feature is loading\n\t\t\t\t\t\tplanType === PLAN_TYPE_FREE ? (\n\t\t\t\t\t\t\t<UpgradeMessage\n\t\t\t\t\t\t\t\trequestsRemaining={ requestsRemaining }\n\t\t\t\t\t\t\t\tonUpgradeClick={ trackUpgradeClick }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) : null\n\t\t\t\t\t}\n\t\t\t\t\tlastAction={ lastAction }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</KeyboardShortcuts>\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 Provide a notification message after the form has been submitted. with these attributes: type" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/form-submission-notification/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"__experimental\": true,\n\t\"name\": \"core/form-submission-notification\",\n\t\"title\": \"Form Submission Notification\",\n\t\"category\": \"common\",\n\t\"ancestor\": [ \"core/form\" ],\n\t\"description\": \"Provide a notification message after the form has been submitted.\",\n\t\"keywords\": [ \"form\", \"feedback\", \"notification\", \"message\" ],\n\t\"textdomain\": \"default\",\n\t\"icon\": \"feedback\",\n\t\"attributes\": {\n\t\t\"type\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"success\"\n\t\t}\n\t}\n}\n\n\n// File: packages/block-library/src/form-submission-notification/index.js\n/**\n * WordPress dependencies\n */\nimport { group 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 variations from './variations';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n\tvariations,\n\texample: {},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/form-submission-notification/save.js\n/**\n * WordPress dependencies\n */\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\n\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\nexport default function save( { attributes } ) {\n\tconst { type } = attributes;\n\n\treturn (\n\t\t<div\n\t\t\t{ ...useInnerBlocksProps.save(\n\t\t\t\tuseBlockProps.save( {\n\t\t\t\t\tclassName: clsx( 'wp-block-form-submission-notification', {\n\t\t\t\t\t\t[ `form-notification-type-${ type }` ]: type,\n\t\t\t\t\t} ),\n\t\t\t\t} )\n\t\t\t) }\n\t\t/>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Block containing current line items in Cart. that allows users to configure: lock" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-line-items-block/block.json\n{\n\t\"name\": \"woocommerce/cart-line-items-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Cart Line Items\",\n\t\"description\": \"Block containing current line items in Cart.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\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-items-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-line-items-block/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: { className: string };\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 WordPress block to Display the product title as a label or paragraph." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item-label/block.json\n{\n\t\"name\": \"woocommerce/add-to-cart-with-options-grouped-product-item-label\",\n\t\"title\": \"Grouped Product: Item Label (Beta)\",\n\t\"description\": \"Display the product title as a label or paragraph.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"ancestor\": [ \"woocommerce/add-to-cart-with-options-grouped-product-item\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"supports\": {\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true,\n\t\t\t\"gradients\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"html\": false,\n\t\t\"layout\": {\n\t\t\t\"selfStretch\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"blockGap\": true\n\t\t},\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\"textAlign\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true,\n\t\t\t\t\"fontWeight\": true,\n\t\t\t\t\"fontStyle\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\" ]\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item-label/index.tsx\n/**\n * External dependencies\n */\nimport { registerBlockType } from '@wordpress/blocks';\nimport { heading } from '@wordpress/icons';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport type { BlockConfiguration } from '@wordpress/blocks';\nimport { useProductDataContext } from '@woocommerce/shared-context';\nimport { Spinner } from '@wordpress/components';\nimport { isProductResponseItem } from '@woocommerce/entities';\n\n/**\n * Internal dependencies\n */\nimport metadata from './block.json';\n\nregisterBlockType( metadata.name, {\n\t...metadata,\n\tedit: function Edit() {\n\t\tconst blockProps = useBlockProps();\n\t\tconst { isLoading, product } = useProductDataContext();\n\n\t\tif ( isLoading || ! isProductResponseItem( product ) ) {\n\t\t\treturn <Spinner />;\n\t\t}\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<div className=\"wp-block-woocommerce-add-to-cart-with-options-grouped-product-item-label\">\n\t\t\t\t\t{ product.name }\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t},\n\ticon: heading,\n\tsave: () => null,\n} as unknown as BlockConfiguration );\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 template for displaying individual child products as list items within the Grouped Product Selector interface." }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item/block.json\n{\n\t\"name\": \"woocommerce/add-to-cart-with-options-grouped-product-item\",\n\t\"title\": \"Grouped Product: Template (Beta)\",\n\t\"description\": \"A list item template that represents a child product within the Grouped Product Selector block.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"usesContext\": [ \"postId\" ],\n\t\"ancestor\": [\n\t\t\"woocommerce/add-to-cart-with-options-grouped-product-selector\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"supports\": {\n\t\t\"inserter\": false,\n\t\t\"interactivity\": true\n\t},\n\t\"style\": \"file:../woocommerce/add-to-cart-with-options-grouped-product-item-style.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item/edit.tsx\n/**\n * External dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n\t__experimentalUseBlockPreview as useBlockPreview,\n\tBlockContextProvider,\n} from '@wordpress/block-editor';\nimport { BlockInstance, type BlockEditProps } from '@wordpress/blocks';\nimport { withProduct } from '@woocommerce/block-hocs';\nimport {\n\tInnerBlockLayoutContextProvider,\n\tProductDataContextProvider,\n\tuseProductDataContext,\n} from '@woocommerce/shared-context';\nimport { resolveSelect, useSelect } from '@wordpress/data';\nimport type { ProductResponseItem } from '@woocommerce/types';\nimport { productsStore } from '@woocommerce/data';\nimport { isProductResponseItem } from '@woocommerce/entities';\nimport { Spinner } from '@wordpress/components';\nimport { previewProductResponseItems } from '@woocommerce/resource-previews';\n\ninterface Attributes {\n\tclassName?: string;\n}\n\ntype ProductItemWithContextProps = {\n\tattributes: { productId: number };\n\tisLoading?: boolean;\n\tproduct?: ProductResponseItem | null;\n\tblocks: BlockInstance[];\n\tisSelected: boolean;\n\tonSelect(): void;\n};\n\ntype ProductItemProps = {\n\tproduct: ProductResponseItem | null;\n\tblocks: BlockInstance[];\n\tisLoading: boolean;\n\tisSelected: boolean;\n\tonSelect(): void;\n};\n\nconst ProductItem = ( {\n\tproduct,\n\tblocks,\n\tisLoading,\n\tisSelected,\n\tonSelect,\n}: ProductItemProps ) => {\n\tconst blockPreviewProps = useBlockPreview( {\n\t\tblocks,\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{ role: 'listitem' },\n\t\t{ templateLock: 'insert' }\n\t);\n\n\treturn (\n\t\t<ProductDataContextProvider product={ product } isLoading={ isLoading }>\n\t\t\t{ isSelected ? (\n\t\t\t\t<div { ...innerBlocksProps } />\n\t\t\t) : (\n\t\t\t\t<div role=\"listitem\">\n\t\t\t\t\t<div\n\t\t\t\t\t\t{ ...blockPreviewProps }\n\t\t\t\t\t\trole=\"button\"\n\t\t\t\t\t\ttabIndex={ 0 }\n\t\t\t\t\t\tonClick={ onSelect }\n\t\t\t\t\t\tonKeyDown={ ( e ) => {\n\t\t\t\t\t\t\tif ( e.key === 'Enter' || e.key === ' ' ) {\n\t\t\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\t\t\tonSelect();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</ProductDataContextProvider>\n\t);\n};\n\nconst ProductItemWithContext = withProduct(\n\t( {\n\t\tattributes,\n\t\tisLoading = true,\n\t\tproduct = null,\n\t\tblocks,\n\t\tisSelected,\n\t\tonSelect,\n\t}: ProductItemWithContextProps ) => {\n\t\treturn (\n\t\t\t<BlockContextProvider\n\t\t\t\tvalue={ { postId: attributes.productId, postType: 'product' } }\n\t\t\t>\n\t\t\t\t<ProductItem\n\t\t\t\t\tproduct={ product }\n\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\tisLoading={ isLoading }\n\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t/>\n\t\t\t</BlockContextProvider>\n\t\t);\n\t}\n);\n\nexport default function ProductItemTemplateEdit(\n\tprops: BlockEditProps< Attributes >\n) {\n\tconst { clientId } = props;\n\tconst { className } = props.attributes;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName,\n\t} );\n\n\tconst { product, isLoading } = useProductDataContext();\n\tconst [ isLoadingProducts, setIsLoadingProducts ] = useState( true );\n\tconst [ products, setProducts ] = useState< ProductResponseItem[] | null >(\n\t\tnull\n\t);\n\tconst productsLength = products?.length || 0;\n\n\tuseEffect( () => {\n\t\tconst fetchChildProducts = async ( groupedProductIds: number[] ) => {\n\t\t\tif ( ! groupedProductIds || groupedProductIds.length === 0 ) {\n\t\t\t\tsetIsLoadingProducts( false );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tresolveSelect( productsStore )\n\t\t\t\t.getProducts( {\n\t\t\t\t\tinclude: groupedProductIds,\n\t\t\t\t\tper_page: groupedProductIds.length,\n\t\t\t\t\t_fields: [ 'id' ],\n\t\t\t\t} )\n\t\t\t\t.then( ( fetchedProducts ) => {\n\t\t\t\t\tsetProducts( fetchedProducts );\n\t\t\t\t\tsetIsLoadingProducts( false );\n\t\t\t\t} );\n\t\t};\n\n\t\tif ( ! isLoading && product && productsLength === 0 ) {\n\t\t\tif ( isProductResponseItem( product ) ) {\n\t\t\t\tfetchChildProducts( product.grouped_products );\n\t\t\t} else {\n\t\t\t\t// If not editing a specific product, we are editing a template.\n\t\t\t\t// Fetch an existing grouped product so template can be edited.\n\t\t\t\tresolveSelect( productsStore )\n\t\t\t\t\t.getProducts( { type: 'grouped', per_page: 1 } )\n\t\t\t\t\t.then( ( groupedProduct ) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tgroupedProduct.length > 0 &&\n\t\t\t\t\t\t\tgroupedProduct[ 0 ]?.grouped_products?.length > 0\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tfetchChildProducts(\n\t\t\t\t\t\t\t\tgroupedProduct[ 0 ].grouped_products\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// If there are no grouped products, query for any three other products.\n\t\t\t\t\t\t\tresolveSelect( productsStore )\n\t\t\t\t\t\t\t\t.getProducts( {\n\t\t\t\t\t\t\t\t\tper_page: 3,\n\t\t\t\t\t\t\t\t\t_fields: [ 'id' ],\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t.then( ( fetchedProducts ) => {\n\t\t\t\t\t\t\t\t\tif ( fetchedProducts.length > 0 ) {\n\t\t\t\t\t\t\t\t\t\tsetProducts( fetchedProducts );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tsetIsLoadingProducts( false );\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t}, [ isLoading, product, productsLength ] );\n\n\tconst { blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlocks } = select( blockEditorStore );\n\t\t\treturn { blocks: getBlocks( clientId ) };\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst [ selectedProductItem, setSelectedProductItem ] =\n\t\tuseState< number >();\n\n\tif ( isLoading || isLoadingProducts ) {\n\t\treturn <Spinner />;\n\t}\n\n\tconst productList = products\n\t\t? products?.map( ( productItem ) => (\n\t\t\t\t<ProductItemWithContext\n\t\t\t\t\tkey={ productItem.id }\n\t\t\t\t\tattributes={ {\n\t\t\t\t\t\tproductId: productItem.id,\n\t\t\t\t\t} }\n\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\tisSelected={\n\t\t\t\t\t\t( selectedProductItem ?? products[ 0 ]?.id ) ===\n\t\t\t\t\t\tproductItem.id\n\t\t\t\t\t}\n\t\t\t\t\tonSelect={ () => setSelectedProductItem( productItem.id ) }\n\t\t\t\t/>\n\t\t ) )\n\t\t: previewProductResponseItems?.map( ( productItem ) => (\n\t\t\t\t<ProductItem\n\t\t\t\t\tkey={ productItem.id }\n\t\t\t\t\tproduct={ productItem }\n\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\tisLoading={ false }\n\t\t\t\t\tisSelected={\n\t\t\t\t\t\t( selectedProductItem ??\n\t\t\t\t\t\t\tpreviewProductResponseItems[ 0 ]?.id ) ===\n\t\t\t\t\t\tproductItem.id\n\t\t\t\t\t}\n\t\t\t\t\tonSelect={ () => setSelectedProductItem( productItem.id ) }\n\t\t\t\t/>\n\t\t ) );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlockLayoutContextProvider parentName=\"woocommerce/add-to-cart-with-options-grouped-product-item\">\n\t\t\t\t<div role=\"list\">{ productList }</div>\n\t\t\t</InnerBlockLayoutContextProvider>\n\t\t</div>\n\t);\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport default function ProductItemTemplateSave() {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( {\n\t\t...blockProps,\n\t\trole: 'listitem',\n\t} );\n\treturn <div { ...innerBlocksProps } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a embed block with customizable align, points, address, 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: projects/plugins/jetpack/extensions/blocks/map/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/map\",\n\t\"title\": \"Map\",\n\t\"description\": \"Add an interactive map showing one or more locations.\",\n\t\"keywords\": [ \"maps\", \"location\", \"navigation\" ],\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='M20.5 3l-.16.03L15 5.1 9 3 3.36 4.9c-.21.07-.36.25-.36.48V20.5c0 .28.22.5.5.5l.16-.03L9 18.9l6 2.1 5.64-1.9c.21-.07.36-.25.36-.48V3.5c0-.28-.22-.5-.5-.5zM10 5.47l4 1.4v11.66l-4-1.4V5.47zm-5 .99l3-1.01v11.7l-3 1.16V6.46zm14 11.08l-3 1.01V6.86l3-1.16v11.84z' /></svg>\",\n\t\"supports\": { \"defaultStylePicker\": false, \"html\": false },\n\t\"attributes\": {\n\t\t\"align\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"points\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t},\n\t\t\"address\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"mapDetails\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"zoom\": {\n\t\t\t\"type\": \"integer\",\n\t\t\t\"default\": 13\n\t\t},\n\t\t\"mapCenter\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"longitude\": -122.41941550000001,\n\t\t\t\t\"latitude\": 37.7749295\n\t\t\t}\n\t\t},\n\t\t\"markerColor\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"red\"\n\t\t},\n\t\t\"scrollToZoom\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"mapHeight\": {\n\t\t\t\"type\": \"integer\"\n\t\t},\n\t\t\"showFullscreenButton\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"example\": {}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/map/edit.js\nimport { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils';\nimport apiFetch from '@wordpress/api-fetch';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport {\n\tButton,\n\tExternalLink,\n\tPlaceholder,\n\tSpinner,\n\twithNotices,\n\tResizableBox,\n} from '@wordpress/components';\nimport { compose } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { getActiveStyleName } from '../../shared/block-styles';\nimport AddPoint from './add-point';\nimport metadata from './block.json';\nimport Map from './component';\nimport Controls from './controls';\nimport { getCoordinates } from './get-coordinates.js';\nimport previewPlaceholder from './map-preview.jpg';\nimport styles from './styles';\nimport getMapProvider from './utils/get-map-provider';\n\nconst icon = getBlockIconComponent( metadata );\n\nconst API_STATE_LOADING = 0;\nconst API_STATE_FAILURE = 1;\nconst API_STATE_SUCCESS = 2;\n\n// The minimum height that the map can be set to.\nconst MIN_HEIGHT = 400;\n\n// Options for the map <ResizableBox> wrapper.\nconst RESIZABLE_BOX_ENABLE_OPTION = {\n\ttop: false,\n\tright: false,\n\tbottom: true,\n\tleft: false,\n\ttopRight: false,\n\tbottomRight: false,\n\tbottomLeft: false,\n\ttopLeft: false,\n};\n\nconst MapEdit = ( {\n\tsetAttributes,\n\tattributes,\n\tnoticeUI,\n\tnotices,\n\tisSelected,\n\tnoticeOperations,\n} ) => {\n\tconst {\n\t\taddress,\n\t\tmapDetails,\n\t\tpoints,\n\t\tzoom,\n\t\tmapCenter,\n\t\tmarkerColor,\n\t\tmapHeight,\n\t\tshowFullscreenButton,\n\t} = attributes;\n\n\tconst { toggleSelection } = useDispatch( 'core/block-editor' );\n\n\tconst { isPreviewMode } = useSelect( select => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst settings = getSettings();\n\t\treturn {\n\t\t\tisPreviewMode: settings.isPreviewMode,\n\t\t};\n\t}, [] );\n\n\tconst [ addPointVisibility, setAddPointVisibility ] = useState( false );\n\tconst [ apiState, setApiState ] = useState( API_STATE_LOADING );\n\tconst [ apiKey, setApiKey ] = useState( null );\n\tconst [ apiKeyControl, setApiKeyControl ] = useState( null );\n\tconst [ apiKeySource, setApiKeySource ] = useState( null );\n\tconst [ apiRequestOutstanding, setApiRequestOutstanding ] = useState( null );\n\tconst mapRef = useRef( null );\n\tconst blockProps = useBlockProps();\n\tconst { className } = blockProps;\n\n\tconst mapStyle = getActiveStyleName( styles, className );\n\tconst mapProvider = getMapProvider( { mapStyle } );\n\n\tconst geoCodeAddress = () => {\n\t\tif ( ! address || ! apiKey || mapProvider === 'mapkit' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tgetCoordinates( address, apiKey )\n\t\t\t.then( result => {\n\t\t\t\tif ( ! result.features?.length ) {\n\t\t\t\t\tonError(\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Could not find the coordinates of the provided address. Displaying default location. Feel free to add the location manually.',\n\t\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tconst feature = result.features[ 0 ];\n\t\t\t\t\tconst newPoint = [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttitle: feature.text,\n\t\t\t\t\t\t\tplaceTitle: feature.text,\n\t\t\t\t\t\t\tcaption: feature.place_name,\n\t\t\t\t\t\t\tid: feature.id,\n\t\t\t\t\t\t\tcoordinates: {\n\t\t\t\t\t\t\t\tlatitude: feature.center[ 1 ],\n\t\t\t\t\t\t\t\tlongitude: feature.center[ 0 ],\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\tsetAttributes( { points: newPoint } );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( error => onError( null, error.message ) );\n\t};\n\n\tconst apiCall = ( serviceApiKey = null, method = 'GET' ) => {\n\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\tconst path = '/wpcom/v2/service-api-keys/mapbox';\n\t\t\tconst fetch = serviceApiKey\n\t\t\t\t? { path, method, data: { service_api_key: serviceApiKey } }\n\t\t\t\t: { path, method };\n\n\t\t\tsetApiRequestOutstanding( true );\n\n\t\t\tapiFetch( fetch ).then(\n\t\t\t\t( { service_api_key: key, service_api_key_source: source } ) => {\n\t\t\t\t\tnoticeOperations.removeAllNotices();\n\n\t\t\t\t\tsetApiState( key ? API_STATE_SUCCESS : API_STATE_FAILURE );\n\t\t\t\t\tsetApiKey( key );\n\t\t\t\t\tsetApiKeyControl( 'wpcom' === source ? '' : key );\n\t\t\t\t\tsetApiKeySource( source );\n\t\t\t\t\tsetApiRequestOutstanding( false );\n\n\t\t\t\t\tresolve();\n\t\t\t\t},\n\t\t\t\t( { message } ) => {\n\t\t\t\t\tonError( null, message );\n\n\t\t\t\t\tsetApiState( API_STATE_FAILURE );\n\t\t\t\t\tsetApiRequestOutstanding( false );\n\n\t\t\t\t\treject();\n\t\t\t\t}\n\t\t\t);\n\t\t} );\n\t};\n\n\tconst addPoint = point => {\n\t\tif ( points.some( existingPoint => existingPoint.id === point.id ) ) {\n\t\t\treturn;\n\t\t}\n\t\tconst newPoints = points.slice( 0 );\n\t\tnewPoints.push( point );\n\t\tsetAttributes( { points: newPoints } );\n\t\tsetAddPointVisibility( false );\n\t};\n\n\tconst updateAPIKey = () => {\n\t\tnoticeOperations.removeAllNotices();\n\n\t\tif ( apiKeyControl ) {\n\t\t\tapiCall( apiKeyControl, 'POST' );\n\t\t}\n\t};\n\n\tconst removeAPIKey = () => apiCall( null, 'DELETE' );\n\n\tconst onError = ( code, message ) => {\n\t\tnoticeOperations.removeAllNotices();\n\t\tnoticeOperations.createErrorNotice( message );\n\t};\n\n\t/**\n\t * Event handler for the ResizableBox component. Updates both the height attribute,\n\t * and the map component's height in the DOM.\n\t *\n\t * @param {Event} event - The event object.\n\t * @param {string} direction - A string representing which resize handler was used.\n\t * @param {HTMLElement} elt - A ref to the ResizeableBox's container element.\n\t * @param {object} delta - Information about how far the element was resized.\n\t */\n\tconst onMapResize = ( event, direction, elt, delta ) => {\n\t\ttoggleSelection( true );\n\t\tconst ref = mapRef?.current?.mapRef ?? mapRef;\n\n\t\tif ( ref ) {\n\t\t\tconst height = parseInt( ref.current.offsetHeight + delta.height, 10 );\n\n\t\t\tsetAttributes( {\n\t\t\t\tmapHeight: height,\n\t\t\t} );\n\n\t\t\tif ( ref.current.sizeMap ) {\n\t\t\t\tsetTimeout( ref.current.sizeMap, 0 );\n\t\t\t}\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( mapProvider === 'mapbox' ) {\n\t\t\tapiCall().then( geoCodeAddress );\n\t\t} else {\n\t\t\tsetApiState( API_STATE_SUCCESS );\n\t\t}\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [] );\n\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\tuseEffect( geoCodeAddress, [ address ] );\n\n\tuseEffect( () => {\n\t\t// Fetch API key when switching from mapkit to mapbox\n\t\tif ( className && ! apiKey ) {\n\t\t\tsetApiState( API_STATE_LOADING );\n\t\t\tapiCall();\n\t\t}\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [ className ] );\n\n\tlet content;\n\n\tif ( isPreviewMode ) {\n\t\tconst mapStyleObject = styles.find( styleObject => styleObject.name === mapStyle );\n\n\t\tcontent = (\n\t\t\t<div>\n\t\t\t\t<img\n\t\t\t\t\talt={ __( 'Map Preview', 'jetpack' ) }\n\t\t\t\t\tsrc={ mapStyleObject ? mapStyleObject.preview : previewPlaceholder }\n\t\t\t\t\tstyle={ { width: '100%', height: mapHeight || '400px', objectFit: 'cover' } }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t} else if ( apiState === API_STATE_LOADING ) {\n\t\tcontent = (\n\t\t\t<Placeholder icon={ icon }>\n\t\t\t\t<Spinner />\n\t\t\t</Placeholder>\n\t\t);\n\t} else if ( apiState === API_STATE_FAILURE ) {\n\t\tcontent = (\n\t\t\t<Placeholder icon={ icon } label={ __( 'Map', 'jetpack' ) } notices={ notices }>\n\t\t\t\t<>\n\t\t\t\t\t<p className=\"components-placeholder__instructions\">\n\t\t\t\t\t\t{ __( 'To use the map block, you need an Access Token.', 'jetpack' ) }\n\t\t\t\t\t\t<br />\n\t\t\t\t\t\t<ExternalLink href=\"https://www.mapbox.com\">\n\t\t\t\t\t\t\t{ __( 'Create an account or log in to Mapbox.', 'jetpack' ) }\n\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t\t<br />\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Locate and copy the default access token. Then, paste it into the field below.',\n\t\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\n\t\t\t\t\t<form>\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\tclassName=\"components-placeholder__input\"\n\t\t\t\t\t\t\tdisabled={ apiRequestOutstanding }\n\t\t\t\t\t\t\tplaceholder={ __( 'Paste Token Here', 'jetpack' ) }\n\t\t\t\t\t\t\tvalue={ apiKeyControl }\n\t\t\t\t\t\t\tonChange={ event => setApiKeyControl( event.target.value ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\tdisabled={ apiRequestOutstanding || ! apiKeyControl || apiKeyControl.length < 1 }\n\t\t\t\t\t\t\tonClick={ updateAPIKey }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Set Token', 'jetpack' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</form>\n\t\t\t\t</>\n\t\t\t</Placeholder>\n\t\t);\n\t} else if ( apiState === API_STATE_SUCCESS ) {\n\t\tconst onKeyChange = value => setApiKeyControl( value );\n\n\t\t// Only scroll to zoom when the block is selected, and there's 1 or less points.\n\t\tconst allowScrollToZoom = isSelected && points.length <= 1;\n\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<Controls\n\t\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\tapiKey={ apiKey }\n\t\t\t\t\t\tapiKeySource={ apiKeySource }\n\t\t\t\t\t\tapiKeyControl={ apiKeyControl }\n\t\t\t\t\t\tonKeyChange={ onKeyChange }\n\t\t\t\t\t\tsetPointVisibility={ () => setAddPointVisibility( true ) }\n\t\t\t\t\t\tcontext=\"toolbar\"\n\t\t\t\t\t\tmapRef={ mapRef }\n\t\t\t\t\t\tmapProvider={ mapProvider }\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<Controls\n\t\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\tapiKey={ apiKey }\n\t\t\t\t\t\tapiKeySource={ apiKeySource }\n\t\t\t\t\t\tapiKeyControl={ apiKeyControl }\n\t\t\t\t\t\tonKeyChange={ onKeyChange }\n\t\t\t\t\t\tmapRef={ mapRef }\n\t\t\t\t\t\tminHeight={ MIN_HEIGHT }\n\t\t\t\t\t\tremoveAPIKey={ removeAPIKey }\n\t\t\t\t\t\tupdateAPIKey={ updateAPIKey }\n\t\t\t\t\t\tmapProvider={ mapProvider }\n\t\t\t\t\t/>\n\t\t\t\t</InspectorControls>\n\n\t\t\t\t<ResizableBox\n\t\t\t\t\tsize={ {\n\t\t\t\t\t\theight: mapHeight || 'auto',\n\t\t\t\t\t\twidth: '100%',\n\t\t\t\t\t} }\n\t\t\t\t\tgrid={ [ 10, 10 ] }\n\t\t\t\t\tshowHandle={ isSelected }\n\t\t\t\t\tminHeight={ MIN_HEIGHT }\n\t\t\t\t\tenable={ RESIZABLE_BOX_ENABLE_OPTION }\n\t\t\t\t\tonResizeStart={ () => toggleSelection( false ) }\n\t\t\t\t\tonResizeStop={ onMapResize }\n\t\t\t\t>\n\t\t\t\t\t<div className=\"wp-block-jetpack-map__map_wrapper\">\n\t\t\t\t\t\t<Map\n\t\t\t\t\t\t\tref={ mapRef }\n\t\t\t\t\t\t\taddress={ address }\n\t\t\t\t\t\t\tscrollToZoom={ allowScrollToZoom }\n\t\t\t\t\t\t\tshowFullscreenButton={ showFullscreenButton }\n\t\t\t\t\t\t\tmapStyle={ mapStyle || 'default' }\n\t\t\t\t\t\t\tmapDetails={ mapDetails }\n\t\t\t\t\t\t\tmapHeight={ mapHeight }\n\t\t\t\t\t\t\tpoints={ points }\n\t\t\t\t\t\t\tzoom={ zoom }\n\t\t\t\t\t\t\tmapCenter={ mapCenter }\n\t\t\t\t\t\t\tmarkerColor={ markerColor }\n\t\t\t\t\t\t\tonSetZoom={ value => {\n\t\t\t\t\t\t\t\tsetAttributes( { zoom: value } );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tadmin={ true }\n\t\t\t\t\t\t\tapiKey={ apiKey }\n\t\t\t\t\t\t\tonSetPoints={ value => setAttributes( { points: value } ) }\n\t\t\t\t\t\t\tonSetMapCenter={ value => setAttributes( { mapCenter: value } ) }\n\t\t\t\t\t\t\tonMapLoaded={ () => setAddPointVisibility( ! points.length ) }\n\t\t\t\t\t\t\tonMarkerClick={ () => setAddPointVisibility( false ) }\n\t\t\t\t\t\t\tonError={ onError }\n\t\t\t\t\t\t\tmapProvider={ mapProvider }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ isSelected && addPointVisibility && (\n\t\t\t\t\t\t\t\t<AddPoint\n\t\t\t\t\t\t\t\t\tonAddPoint={ addPoint }\n\t\t\t\t\t\t\t\t\tonClose={ () => setAddPointVisibility( false ) }\n\t\t\t\t\t\t\t\t\tapiKey={ apiKey }\n\t\t\t\t\t\t\t\t\tonError={ onError }\n\t\t\t\t\t\t\t\t\ttagName=\"AddPoint\"\n\t\t\t\t\t\t\t\t\tmapProvider={ mapProvider }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</Map>\n\t\t\t\t\t</div>\n\t\t\t\t</ResizableBox>\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ noticeUI }\n\t\t\t{ content }\n\t\t</div>\n\t);\n};\n\nexport default compose( withNotices )( MapEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/map/save.js\nimport { useBlockProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\nimport { getActiveStyleName } from '../../shared/block-styles';\nimport styles from './styles';\n\nconst MapSave = ( { attributes } ) => {\n\tconst {\n\t\talign,\n\t\tmapDetails,\n\t\tpoints,\n\t\tzoom,\n\t\tmapCenter,\n\t\tmarkerColor,\n\t\tscrollToZoom,\n\t\tmapHeight,\n\t\tshowFullscreenButton,\n\t} = attributes;\n\tconst blockProps = useBlockProps.save();\n\tconst { className } = blockProps;\n\n\tconst mapStyle = getActiveStyleName( styles, className );\n\tconst pointsList = points.map( ( point, index ) => {\n\t\tconst { longitude, latitude } = point.coordinates;\n\t\tconst url = 'https://www.google.com/maps/search/?api=1&query=' + latitude + ',' + longitude;\n\t\treturn (\n\t\t\t<li key={ index }>\n\t\t\t\t<a href={ url }>{ point.title }</a>\n\t\t\t</li>\n\t\t);\n\t} );\n\n\t// All camelCase attribute names converted to snake_case data attributes\n\treturn (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\tclassName={ clsx( className, align ? `align${ align }` : null ) }\n\t\t\tdata-map-style={ mapStyle }\n\t\t\tdata-map-details={ mapDetails }\n\t\t\tdata-points={ JSON.stringify( points ) }\n\t\t\tdata-zoom={ zoom }\n\t\t\tdata-map-center={ JSON.stringify( mapCenter ) }\n\t\t\tdata-marker-color={ markerColor }\n\t\t\tdata-scroll-to-zoom={ scrollToZoom || null }\n\t\t\tdata-map-height={ mapHeight || null }\n\t\t\tdata-show-fullscreen-button={ showFullscreenButton || null }\n\t\t>\n\t\t\t{ points.length > 0 && <ul>{ pointsList }</ul> }\n\t\t</div>\n\t);\n};\n\nexport default MapSave;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Enable customers to filter the product grid by stock status. with these attributes: class name, heading level, show counts, 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/stock-filter/block.json\n{\n\t\"name\": \"woocommerce/stock-filter\",\n\t\"title\": \"Filter by Stock Controls\",\n\t\"description\": \"Enable customers to filter the product grid by stock status.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": false\n\t\t},\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": true,\n\t\t\t\"button\": true\n\t\t},\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"headingLevel\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\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\"showFilterButton\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"displayStyle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"list\"\n\t\t},\n\t\t\"selectType\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"multiple\"\n\t\t},\n\t\t\"isPreview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\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/stock-filter/edit.tsx\n/**\n * External dependencies\n */\nimport { __, _x } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport BlockTitle from '@woocommerce/editor-components/block-title';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport {\n\tDisabled,\n\tPanelBody,\n\tToggleControl,\n\twithSpokenMessages,\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport './editor.scss';\nimport { Attributes } from './types';\nimport { UpgradeNotice } from '../filter-wrapper/upgrade';\n\nconst Edit = ( {\n\tclientId,\n\tattributes,\n\tsetAttributes,\n}: BlockEditProps< Attributes > ) => {\n\tconst {\n\t\tclassName,\n\t\theading,\n\t\theadingLevel,\n\t\tshowCounts,\n\t\tshowFilterButton,\n\t\tselectType,\n\t\tdisplayStyle,\n\t} = attributes;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( 'wc-block-stock-filter', className ),\n\t} );\n\n\tconst getInspectorControls = () => {\n\t\treturn (\n\t\t\t<InspectorControls key=\"inspector\">\n\t\t\t\t<PanelBody>\n\t\t\t\t\t<UpgradeNotice clientId={ clientId } />\n\t\t\t\t</PanelBody>\n\t\t\t\t<PanelBody title={ __( 'Display Settings', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Display product count', 'woocommerce' ) }\n\t\t\t\t\t\tchecked={ showCounts }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowCounts: ! showCounts,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t'Allow selecting multiple options?',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tisBlock\n\t\t\t\t\t\tvalue={ selectType || 'multiple' }\n\t\t\t\t\t\tonChange={ ( value: string ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tselectType: value,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclassName=\"wc-block-attribute-filter__multiple-toggle\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"multiple\"\n\t\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t\t'Multiple',\n\t\t\t\t\t\t\t\t'Number of filters',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"single\"\n\t\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t\t'Single',\n\t\t\t\t\t\t\t\t'Number of filters',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\tlabel={ __( 'Display Style', 'woocommerce' ) }\n\t\t\t\t\t\tisBlock\n\t\t\t\t\t\tvalue={ displayStyle }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tdisplayStyle: value,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclassName=\"wc-block-attribute-filter__display-toggle\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"list\"\n\t\t\t\t\t\t\tlabel={ __( 'List', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"dropdown\"\n\t\t\t\t\t\t\tlabel={ __( 'Dropdown', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t\"Show 'Apply filters' button\",\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Products will update when the button is clicked.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ showFilterButton }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowFilterButton: value,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t);\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t{ getInspectorControls() }\n\t\t\t{\n\t\t\t\t<div { ...blockProps }>\n\t\t\t\t\t{ heading && (\n\t\t\t\t\t\t<BlockTitle\n\t\t\t\t\t\t\tclassName=\"wc-block-stock-filter__title\"\n\t\t\t\t\t\t\theadingLevel={ headingLevel }\n\t\t\t\t\t\t\theading={ heading }\n\t\t\t\t\t\t\tonChange={ ( value: string ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { heading: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t<Disabled>\n\t\t\t\t\t\t<Block attributes={ attributes } isEditor={ true } />\n\t\t\t\t\t</Disabled>\n\t\t\t\t</div>\n\t\t\t}\n\t\t</>\n\t);\n};\n\nexport default withSpokenMessages( Edit );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a Gutenberg block designed to transform spoken language into a publication-ready post through AI-driven content conversion, featuring a dedicated content attribute." }, { "role": "assistant", "content": "// File: projects/plugins/jetpack/extensions/blocks/voice-to-content/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/voice-to-content\",\n\t\"title\": \"Voice to content\",\n\t\"description\": \"Transform your spoken words into a post ready to publish with AI.\",\n\t\"keywords\": [ \"AI\", \"GPT\", \"AL\", \"Magic\", \"help\", \"assistant\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"media\",\n\t\"icon\": \"<svg viewBox='0 0 20 20' width='20' height='20' xmlns='http://www.w3.org/2000/svg'><path d='M12 9V3c0-1.1-.89-2-2-2-1.12 0-2 .94-2 2v6c0 1.1.9 2 2 2 1.13 0 2-.94 2-2zm4 0c0 2.97-2.16 5.43-5 5.91V17h2c.56 0 1 .45 1 1s-.44 1-1 1H7c-.55 0-1-.45-1-1s.45-1 1-1h2v-2.09C6.17 14.43 4 11.97 4 9c0-.55.45-1 1-1 .56 0 1 .45 1 1 0 2.21 1.8 4 4 4 2.21 0 4-1.79 4-4 0-.55.45-1 1-1 .56 0 1 .45 1 1z'/></svg>\",\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"multiple\": true,\n\t\t\"reusable\": false\n\t},\n\t\"attributes\": {\n\t\t\"content\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/voice-to-content/edit.tsx\nimport {\n\tuseMediaRecording,\n\tuseAudioValidation,\n\tTRANSCRIPTION_POST_PROCESSING_ACTION_SIMPLE_DRAFT,\n} from '@automattic/jetpack-ai-client';\nimport { ThemeProvider } from '@automattic/jetpack-components';\nimport { useAnalytics } from '@automattic/jetpack-shared-extension-utils';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { type BlockInstance } from '@wordpress/blocks';\nimport { Button, Modal, Icon } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useCallback, useEffect, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { external } from '@wordpress/icons';\nimport ActionButtons from './components/action-buttons';\nimport AudioStatusPanel from './components/audio-status-panel';\nimport useTranscriptionCreator from './hooks/use-transcription-creator';\nimport useTranscriptionInserter from './hooks/use-transcription-inserter';\nimport type {\n\tRecordingState,\n\tTranscriptionState,\n\tValidatedAudioInformation,\n} from '@automattic/jetpack-ai-client';\n\n/**\n * Helper to determine the state of the transcription.\n *\n * @param {boolean} isCreatingTranscription - The transcription creation state\n * @param {boolean} isValidatingAudio - The audio validation state\n * @param {RecordingState} recordingState - The recording state\n * @return {TranscriptionState} - The transcription state\n */\nconst transcriptionStateHelper = (\n\tisCreatingTranscription: boolean,\n\tisValidatingAudio: boolean,\n\trecordingState: RecordingState\n): TranscriptionState => {\n\tif ( isValidatingAudio ) {\n\t\treturn 'validating';\n\t}\n\n\tif ( isCreatingTranscription ) {\n\t\treturn 'processing';\n\t}\n\n\treturn recordingState;\n};\n\nexport default function VoiceToContentEdit( { clientId } ) {\n\tconst [ audio, setAudio ] = useState< Blob >( null );\n\n\tconst { removeBlock } = useDispatch( blockEditorStore );\n\t// TODO: The second `deps` argument shouldn't be needed, but it's added to make the type checker happy.\n\t// This can be removed when the core data types are updated to fix the issue.\n\tconst { getBlocks } = useSelect( blockEditorStore, [] ) as {\n\t\tgetBlocks: () => BlockInstance[];\n\t};\n\n\tconst destroyBlock = useCallback( () => {\n\t\t// Remove the block from the editor\n\t\tsetTimeout( () => {\n\t\t\tremoveBlock( clientId );\n\t\t}, 100 );\n\t}, [ removeBlock, clientId ] );\n\n\t// Track the usage of the feature\n\tconst { tracks } = useAnalytics();\n\n\tconst { isValidatingAudio, validateAudio } = useAudioValidation();\n\n\tconst { upsertTranscription } = useTranscriptionInserter();\n\tconst { isCreatingTranscription, createTranscription, cancelTranscription } =\n\t\tuseTranscriptionCreator( {\n\t\t\tonReady: ( content: string ) => {\n\t\t\t\t// When transcription is ready, insert it into the editor\n\t\t\t\tupsertTranscription( content );\n\n\t\t\t\t// Then check if there is a single empty paragraph block before the transcription and remove it\n\t\t\t\t// This is to ensure the P2 title is correct as it's based on the first block\n\t\t\t\tconst blocks = getBlocks();\n\t\t\t\t// One block is the voice-to-content block itself, so we check the first two blocks\n\t\t\t\tfor ( let i = 0; i < 2; i++ ) {\n\t\t\t\t\tif ( blocks[ i ].name === 'core/paragraph' && blocks[ i ].attributes?.content === '' ) {\n\t\t\t\t\t\tremoveBlock( String( blocks[ i ].clientId ) );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\thandleClose();\n\t\t\t},\n\t\t\tonUpdate: ( content: string ) => {\n\t\t\t\t// When transcription is updated, insert it into the editor\n\t\t\t\tupsertTranscription( content );\n\t\t\t},\n\t\t\tonError: ( error: string ) => {\n\t\t\t\t// When transcription fails, show an error message\n\t\t\t\tonError( error );\n\t\t\t},\n\t\t} );\n\n\tconst handleClose = () => {\n\t\tcancelTranscription();\n\t\tdestroyBlock();\n\t};\n\n\tconst { state, controls, error, onError, duration, analyser } = useMediaRecording( {\n\t\tonDone: lastBlob => {\n\t\t\t// When recording is done, set the audio to be transcribed\n\t\t\tonAudioHandler( lastBlob );\n\t\t},\n\t} );\n\n\tconst onAudioHandler = useCallback(\n\t\t( audioFile: Blob ) => {\n\t\t\tif ( audioFile ) {\n\t\t\t\tsetAudio( audioFile );\n\t\t\t}\n\t\t},\n\t\t[ setAudio ]\n\t);\n\n\t/**\n\t * When the audio changes, create the transcription. In the future,\n\t * we can trigger this action (and others) from a button in the UI.\n\t */\n\tuseEffect( () => {\n\t\tif ( audio ) {\n\t\t\tvalidateAudio(\n\t\t\t\taudio,\n\t\t\t\t( audioInfo: ValidatedAudioInformation ) => {\n\t\t\t\t\t// Track the transcription event\n\t\t\t\t\ttracks.recordEvent( 'jetpack_ai_voice_to_content_transcription_started', {\n\t\t\t\t\t\tpost_processing_action: TRANSCRIPTION_POST_PROCESSING_ACTION_SIMPLE_DRAFT,\n\t\t\t\t\t\ttype: audioInfo.isFile ? 'upload' : 'record',\n\t\t\t\t\t\taudio_duration: audioInfo.duration,\n\t\t\t\t\t\taudio_file_size: audioInfo.size,\n\t\t\t\t\t} );\n\n\t\t\t\t\tcreateTranscription( audio, TRANSCRIPTION_POST_PROCESSING_ACTION_SIMPLE_DRAFT );\n\t\t\t\t},\n\t\t\t\tonError\n\t\t\t);\n\t\t}\n\t}, [ audio, tracks, validateAudio, createTranscription, onError ] );\n\n\t// Destructure controls\n\tconst {\n\t\tstart: controlStart,\n\t\tpause: controlPause,\n\t\tresume: controlResume,\n\t\tstop: controlStop,\n\t\treset: controlReset,\n\t} = controls;\n\n\tconst onUploadHandler = useCallback(\n\t\tevent => {\n\t\t\tif ( event.currentTarget.files.length > 0 ) {\n\t\t\t\tconst file = event.currentTarget.files[ 0 ];\n\t\t\t\tonAudioHandler( file );\n\t\t\t}\n\t\t},\n\t\t[ onAudioHandler ]\n\t);\n\n\tconst onCancelHandler = useCallback( () => {\n\t\tcancelTranscription();\n\t\tcontrolReset();\n\t}, [ cancelTranscription, controlReset ] );\n\n\tconst onRecordHandler = useCallback( () => {\n\t\tcontrolStart( 1000 ); // Stream audio on 1 second intervals\n\t}, [ controlStart ] );\n\n\tconst onPauseHandler = useCallback( () => {\n\t\tcontrolPause();\n\t}, [ controlPause ] );\n\n\tconst onResumeHandler = useCallback( () => {\n\t\tcontrolResume();\n\t}, [ controlResume ] );\n\n\tconst onDoneHandler = useCallback( () => {\n\t\tcontrolStop();\n\t}, [ controlStop ] );\n\n\t// To avoid a wrong TS warning\n\tconst iconProps = { className: 'icon' };\n\n\tconst transcriptionState = transcriptionStateHelper(\n\t\tisCreatingTranscription,\n\t\tisValidatingAudio,\n\t\tstate\n\t);\n\n\treturn (\n\t\t<Modal\n\t\t\tonRequestClose={ handleClose }\n\t\t\ttitle={ __( 'Jetpack AI Voice to content', 'jetpack' ) }\n\t\t\tclassName=\"jetpack-ai-voice-to-content__modal\"\n\t\t\tshouldCloseOnEsc={ false }\n\t\t\tshouldCloseOnClickOutside={ false }\n\t\t>\n\t\t\t<ThemeProvider>\n\t\t\t\t<div className=\"jetpack-ai-voice-to-content__wrapper\">\n\t\t\t\t\t<div className=\"jetpack-ai-voice-to-content__body\">\n\t\t\t\t\t\t<span className=\"jetpack-ai-voice-to-content__description\">\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Transform your spoken words into a post ready to publish with AI.',\n\t\t\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<div className=\"jetpack-ai-voice-to-content__contextual-row\">\n\t\t\t\t\t\t\t<AudioStatusPanel\n\t\t\t\t\t\t\t\tstate={ transcriptionState }\n\t\t\t\t\t\t\t\terror={ error }\n\t\t\t\t\t\t\t\tduration={ duration }\n\t\t\t\t\t\t\t\tanalyser={ analyser }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<ActionButtons\n\t\t\t\t\t\t\tstate={ transcriptionState }\n\t\t\t\t\t\t\tonUpload={ onUploadHandler }\n\t\t\t\t\t\t\tonCancel={ onCancelHandler }\n\t\t\t\t\t\t\tonRecord={ onRecordHandler }\n\t\t\t\t\t\t\tonPause={ onPauseHandler }\n\t\t\t\t\t\t\tonResume={ onResumeHandler }\n\t\t\t\t\t\t\tonDone={ onDoneHandler }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div className=\"jetpack-ai-voice-to-content__footer\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\t\tclassName=\"jetpack-ai-voice-to-content__feedback-button\"\n\t\t\t\t\t\t\thref=\"https://a8c.slack.com/archives/C054LN8RNVA\" // Jetpack AI Slack channel\n\t\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<span>{ __( 'Provide feedback', 'jetpack' ) }</span>\n\t\t\t\t\t\t\t<Icon icon={ external } { ...iconProps } />\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</ThemeProvider>\n\t\t</Modal>\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 summary on the order confirmation page. with these attributes: align, class 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: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/summary/block.json\n{\n\t\"name\": \"woocommerce/order-confirmation-summary\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Order Summary\",\n\t\"description\": \"Display the order summary on the order confirmation page.\",\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\"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\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"width\": true,\n\t\t\t\t\"color\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"wide\"\n\t\t},\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/summary/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { Disabled } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { formatPrice } from '@woocommerce/price-format';\nimport { date } from '@wordpress/date';\nimport { getSetting } from '@woocommerce/settings';\n\n/**\n * Internal dependencies\n */\nimport './style.scss';\n\nconst Edit = (): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wc-block-order-confirmation-summary',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Disabled>\n\t\t\t\t<ul className=\"wc-block-order-confirmation-summary-list\">\n\t\t\t\t\t<li className=\"wc-block-order-confirmation-summary-list-item\">\n\t\t\t\t\t\t<span className=\"wc-block-order-confirmation-summary-list-item__key\">\n\t\t\t\t\t\t\t{ __( 'Order number:', 'woocommerce' ) }\n\t\t\t\t\t\t</span>{ ' ' }\n\t\t\t\t\t\t<span className=\"wc-block-order-confirmation-summary-list-item__value\">\n\t\t\t\t\t\t\t123\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</li>\n\t\t\t\t\t<li className=\"wc-block-order-confirmation-summary-list-item\">\n\t\t\t\t\t\t<span className=\"wc-block-order-confirmation-summary-list-item__key\">\n\t\t\t\t\t\t\t{ __( 'Date:', 'woocommerce' ) }\n\t\t\t\t\t\t</span>{ ' ' }\n\t\t\t\t\t\t<span className=\"wc-block-order-confirmation-summary-list-item__value\">\n\t\t\t\t\t\t\t{ date(\n\t\t\t\t\t\t\t\tgetSetting( 'dateFormat' ),\n\t\t\t\t\t\t\t\tnew Date(),\n\t\t\t\t\t\t\t\tundefined\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</li>\n\t\t\t\t\t<li className=\"wc-block-order-confirmation-summary-list-item\">\n\t\t\t\t\t\t<span className=\"wc-block-order-confirmation-summary-list-item__key\">\n\t\t\t\t\t\t\t{ __( 'Total:', 'woocommerce' ) }\n\t\t\t\t\t\t</span>{ ' ' }\n\t\t\t\t\t\t<span className=\"wc-block-order-confirmation-summary-list-item__value\">\n\t\t\t\t\t\t\t{ formatPrice( 4000 ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</li>\n\t\t\t\t\t<li className=\"wc-block-order-confirmation-summary-list-item\">\n\t\t\t\t\t\t<span className=\"wc-block-order-confirmation-summary-list-item__key\">\n\t\t\t\t\t\t\t{ __( 'Email:', 'woocommerce' ) }\n\t\t\t\t\t\t</span>{ ' ' }\n\t\t\t\t\t\t<span className=\"wc-block-order-confirmation-summary-list-item__value\">\n\t\t\t\t\t\t\ttest@test.com\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</li>\n\t\t\t\t\t<li className=\"wc-block-order-confirmation-summary-list-item\">\n\t\t\t\t\t\t<span className=\"wc-block-order-confirmation-summary-list-item__key\">\n\t\t\t\t\t\t\t{ __( 'Payment method:', 'woocommerce' ) }\n\t\t\t\t\t\t</span>{ ' ' }\n\t\t\t\t\t\t<span className=\"wc-block-order-confirmation-summary-list-item__value\">\n\t\t\t\t\t\t\t{ __( 'Credit Card', 'woocommerce' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</li>\n\t\t\t\t</ul>\n\t\t\t</Disabled>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n" } ]