import { registerBlockType } from '@wordpress/blocks'; import { TextControl, TextareaControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { SVG, Rect, Path } from '@wordpress/primitives'; import clsx from 'clsx'; import * as createIssueUrl from 'new-github-issue-url'; import './editor.scss'; const icon = ( ); const Shell = ( { as: El = 'div', className, title, subtitle, body, ...elementProps } ) => { return (
{ title }
{ subtitle }
{ body &&
{ body }
} ); }; const Edit = ( { onChangeTitle, onChangeUserOrOrg, onChangeRepoName, onChangeBody, title, userOrOrg, repo, body, } ) => ( } subtitle={ <>  /  } body={ } /> ); const View = ( { title, userOrOrg, repo, ...rest } ) => ( ); const Invalid = () => ( ); registerBlockType( 'a8c/github-issue-template', { title: __( 'Github Issue Template', 'a8c' ), icon, category: 'layout', attributes: { userOrOrg: { type: 'string', }, repo: { type: 'string', }, title: { type: 'string', }, body: { type: 'string', }, }, edit: ( { setAttributes, attributes, attributes: { userOrOrg, repo }, isSelected } ) => { const handlers = { onChangeUserOrOrg( newUserOrOrg ) { setAttributes( { userOrOrg: newUserOrOrg } ); }, onChangeRepoName( newRepo ) { setAttributes( { repo: newRepo } ); }, onChangeTitle( newTitle ) { setAttributes( { title: newTitle } ); }, onChangeBody( newBody ) { setAttributes( { body: newBody } ); }, }; const isValid = Boolean( userOrOrg && repo ); const { body, ...viewAttributes } = attributes; if ( isSelected ) { return ; } return isValid ? : ; }, save: ( { attributes: { userOrOrg, repo, title, body } } ) => { const isValid = Boolean( userOrOrg && repo ); if ( isValid ) { const url = createIssueUrl( { title, repo, user: userOrOrg, body, } ); const viewAttributes = { title, userOrOrg, repo }; return ; } }, } );