/** * Internal dependencies */ import type { PreviewLanguage } from '../../../../types'; const HTML_CODE = `

Hello World

WordPress

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

[gallery ids="1,2,3" columns="3" size="medium"] [caption id="attachment_1" align="aligncenter"]WordPress.org[/caption]
`; const PHP_CODE = ` 'post', 'posts_per_page' => $count, 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => array( $category ), ), ), ) ); if ( ! $query->have_posts() ) { return; } ?> { const list = document.querySelector( '.latest-posts' ); try { const posts = await fetchPosts( { perPage: 5, categories: [ 1, 2 ] } ); list.innerHTML = posts .map( ( { link, title } ) => \`
  • \${ title.rendered }
  • \` ) .join( '' ); } catch ( error ) { console.error( error ); } } ); `; const CSS_CODE = `:root { --primary-color: #3858e9; --spacing: clamp(1rem, calc(0.5rem + 2vw), 2rem); } .wp-block-group { padding: var(--spacing); background: linear-gradient(135deg, rgba(56, 88, 233, 0.1), rgb(255 255 255 / 80%)); } .latest-posts li:not(:last-child) { margin-bottom: calc(var(--spacing) / 2); } .latest-posts a[target="_blank"]::after { content: "↗"; } @media screen and (max-width: 782px) { .wp-block-columns { flex-direction: column; } } @keyframes fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } } `; const SAMPLE_CODE: Record< PreviewLanguage, string > = { html: HTML_CODE, php: PHP_CODE, javascript: JAVASCRIPT_CODE, css: CSS_CODE, }; // Sample code based on indent type and tab size settings. export function getSampleCode(): Record< PreviewLanguage, string > { const { insertSpaces, tabSize } = window.chbeObj.editorSettings; if ( ! insertSpaces || ! tabSize ) { return SAMPLE_CODE; } return Object.fromEntries( Object.entries( SAMPLE_CODE ).map( ( [ language, code ] ) => [ language, code.replace( /\t/gm, ' '.repeat( tabSize ) ), ] ) ) as Record< PreviewLanguage, string >; }