22 * External dependencies
33 */
44import { __ } from '@wordpress/i18n' ;
5- import { createBlock } from '@wordpress/blocks' ;
5+ import { createBlock , BlockInstance } from '@wordpress/blocks' ;
66import {
77 BlockControls ,
88 InnerBlocks ,
@@ -20,7 +20,6 @@ import {
2020} from '@wordpress/components' ;
2121import { Component } from '@wordpress/element' ;
2222import { compose } from '@wordpress/compose' ;
23- import PropTypes from 'prop-types' ;
2423import { Icon , grid } from '@wordpress/icons' ;
2524import GridLayoutControl from '@woocommerce/editor-components/grid-layout-control' ;
2625import {
@@ -48,46 +47,58 @@ import { getSharedContentControls, getSharedListControls } from '../edit';
4847import Block from './block' ;
4948import './editor.scss' ;
5049
50+ type EditorAttributes = {
51+ columns : number ;
52+ rows : number ;
53+ alignButtons : boolean ;
54+ contentVisibility : object ;
55+ orderby : string ;
56+ layoutConfig : Array < number > ;
57+ isPreview : boolean ;
58+ } ;
59+
60+ interface EditorProps {
61+ block : BlockInstance ;
62+ attributes : EditorAttributes ;
63+ debouncedSpeak : ( label : string ) => void ;
64+ setAttributes : ( attributes : Record < string , unknown > ) => void ;
65+ replaceInnerBlocks : (
66+ rootClientId : string ,
67+ blocks : BlockInstance [ ] ,
68+ updateSelection ?: boolean
69+ ) => void ;
70+ }
71+
72+ interface EditorState {
73+ isEditing : boolean ;
74+ innerBlocks : BlockInstance [ ] ;
75+ }
76+
5177/**
5278 * Component to handle edit mode of "All Products".
5379 */
54- class Editor extends Component {
55- static propTypes = {
56- /**
57- * The attributes for this block.
58- */
59- attributes : PropTypes . object . isRequired ,
60- /**
61- * A callback to update attributes.
62- */
63- setAttributes : PropTypes . func . isRequired ,
64- /**
65- * From withSpokenMessages.
66- */
67- debouncedSpeak : PropTypes . func . isRequired ,
68- } ;
69-
80+ class Editor extends Component < EditorProps , EditorState > {
7081 state = {
7182 isEditing : false ,
7283 innerBlocks : [ ] ,
7384 } ;
7485
7586 blockMap = getBlockMap ( 'woocommerce/all-products' ) ;
7687
77- componentDidMount = ( ) => {
88+ componentDidMount = ( ) : void => {
7889 const { block } = this . props ;
7990 this . setState ( { innerBlocks : block . innerBlocks } ) ;
8091 } ;
8192
82- getTitle = ( ) => {
93+ getTitle = ( ) : string => {
8394 return __ ( 'All Products' , 'woo-gutenberg-products-block' ) ;
8495 } ;
8596
86- getIcon = ( ) => {
97+ getIcon = ( ) : JSX . Element => {
8798 return < Icon icon = { grid } /> ;
8899 } ;
89100
90- togglePreview = ( ) => {
101+ togglePreview = ( ) : void => {
91102 const { debouncedSpeak } = this . props ;
92103
93104 this . setState ( { isEditing : ! this . state . isEditing } ) ;
@@ -102,7 +113,7 @@ class Editor extends Component {
102113 }
103114 } ;
104115
105- getInspectorControls = ( ) => {
116+ getInspectorControls = ( ) : JSX . Element => {
106117 const { attributes, setAttributes } = this . props ;
107118 const { columns, rows, alignButtons } = attributes ;
108119
@@ -139,7 +150,7 @@ class Editor extends Component {
139150 ) ;
140151 } ;
141152
142- getBlockControls = ( ) => {
153+ getBlockControls = ( ) : JSX . Element => {
143154 const { isEditing } = this . state ;
144155
145156 return (
@@ -180,7 +191,7 @@ class Editor extends Component {
180191
181192 const onReset = ( ) => {
182193 const { block, replaceInnerBlocks } = this . props ;
183- const newBlocks = [ ] ;
194+ const newBlocks : BlockInstance [ ] = [ ] ;
184195 DEFAULT_PRODUCT_LIST_LAYOUT . map ( ( [ name , attributes ] ) => {
185196 newBlocks . push ( createBlock ( name , attributes ) ) ;
186197 return true ;
@@ -193,6 +204,7 @@ class Editor extends Component {
193204 template : this . props . attributes . layoutConfig ,
194205 templateLock : false ,
195206 allowedBlocks : Object . keys ( this . blockMap ) ,
207+ renderAppender : true ,
196208 } ;
197209
198210 if ( this . props . attributes . layoutConfig . length !== 0 ) {
@@ -222,6 +234,7 @@ class Editor extends Component {
222234 < ProductDataContextProvider
223235 product = { previewProducts [ 0 ] }
224236 >
237+ { /* @ts -expect-error: `InnerBlocks` is a component that is typed in WordPress core*/ }
225238 < InnerBlocks { ...InnerBlockProps } />
226239 </ ProductDataContextProvider >
227240 </ li >
@@ -276,6 +289,7 @@ class Editor extends Component {
276289
277290 return (
278291 < Disabled >
292+ { /* @ts -expect-error: `Block` is a component that is typed in WordPress core*/ }
279293 < Block attributes = { attributes } />
280294 </ Disabled >
281295 ) ;
0 commit comments